# @odg/events

> Events Interface for Ioc

Latest version **1.13.1** (published 2026-09-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @odg/events
pnpm add @odg/events
yarn add @odg/events
bun add @odg/events
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.13.1 |
| Published | 2026-09-25 |
| First published | 2022-12-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Dragons Gamers |
| Maintainers | dragonsgamers |

## Links

- npm: https://www.npmjs.com/package/@odg/events
- Repository: https://github.com/ODGodinho/ODGMono
- Homepage: https://github.com/ODGodinho/ODGMono/tree/main/packages/events
- Issues: https://github.com/ODGodinho/ODGMono/issues
- npm.io page: https://npm.io/package/@odg/events

## Recent versions

- 1.13.1 (latest) — 2026-09-25
- 1.13.0 — 2026-09-25
- 1.12.9 — 2026-08-17
- 1.12.8 — 2026-08-02
- 1.12.7 — 2026-08-02
- 1.12.5 — 2026-07-31
- 1.12.4 — 2026-07-22
- 1.12.3 — 2026-07-17
- 1.12.2 — 2026-07-17
- 1.12.1 — 2026-07-10
- 1.12.0 — 2026-07-07
- 1.11.4 — 2026-07-06
- 1.11.3 — 2026-06-25
- 1.11.2 — 2026-06-20
- 1.11.1 — 2026-06-20
- … 15 more at https://npm.io/package/@odg/events/versions

## README

<h1 align="center">
    <a href="https://github.com/ODGodinho">
        <img
            src="https://raw.githubusercontent.com/ODGodinho/Stanley-TheTemplate/main/public/images/Stanley.jpg"
            alt="Stanley Imagem" width="500"
        />
    </a>
    <br />
    Stanley The Template For Typescript By Dragons Gamers
    <br />
</h1>

<h4 align="center">Template Stanley for Typescript projects and packages 📦!</h4>

<p align="center">

[![codecov](https://codecov.io/gh/ODGodinho/ODGEvents/branch/main/graph/badge.svg?token=HNBNLLPZ3J)](https://codecov.io/gh/ODGodinho/ODGEvents)
[![Stargazers](https://img.shields.io/github/stars/ODGodinho/ODGEvents?color=F430A4)](https://github.com/ODGodinho/ODGEvents/stargazers)
[![Made by ODGodinho](https://img.shields.io/badge/made%20by-ODGodinho-%2304A361)](https://www.linkedin.com/in/victor-alves-odgodinho/)
[![Forks](https://img.shields.io/github/forks/ODGodinho/ODGEvents?color=CD4D34)](https://github.com/ODGodinho/ODGEvents/network/members)
![Repository size](https://img.shields.io/github/repo-size/ODGodinho/ODGEvents)
[![GitHub last commit](https://img.shields.io/github/last-commit/ODGodinho/ODGEvents)](https://github.com/ODGodinho/ODGEvents/commits/master)
[![License](https://img.shields.io/badge/license-MIT-brightgreen)](https://opensource.org/licenses/MIT)
[![StyleCI](https://github.styleci.io/repos/581704353/shield?branch=main)](https://github.styleci.io/repos/581704353?branch=main)

</p>

# Table of Contents

- [🎇 Benefits](#-benefits)
- [📗 Libraries](#-libraries)
- [📁 Dependencies](#-dependencies)
- [⏩ Get Started](#-get-started)
  - [🔘 Use Event Interface](#-use-event-interface)
  - [📰 Usage](#-usage)
  - [🌎 Implementation](#-implementation)
  - [🌎 Ioc](#-ioc)
  - [🏓 Use Event Provider](#-use-event-provider)
    - [🚡 Enum Events Types](#-enum-events-types)
    - [🥮 Make a provider](#-make-a-provider)
    - [🦻 Use Event Listeners](#-use-event-listeners)
  - [💻 Prepare to develop](#-prepare-to-develop)
  - [📍 Start Project](#-start-project)
  - [📨 Build and Run](#-build-and-run)
  - [🧪 Teste Code](#-teste-code)

---

## 🎇 Benefits

- 🚀 Event Pattern for your project
- 🚨 Over 800 rules for pattern, possible errors and errors in Linter
- 🎇 Code quality guaranteed
- 📢 Ioc Container
- 🧪 100% Test Coverage

## 📗 Libraries

- [Node.js 16](https://nodejs.org/?n=dragonsgamers)
- [Typescript](https://www.typescriptlang.org/?n=dragonsgamers)
- [Eslint](https://eslint.org/?n=dragonsgamers)
- [ODG-Linter-JS](https://github.com/ODGodinho/ODG-Linter-Js?n=dragonsgamers)
- [EditorConfig](https://editorconfig.org/?n=dragonsgamers)
- [ReviewDog](https://github.com/reviewdog/action-eslint)

## 📁 Dependencies

- [Node.js](https://nodejs.org) 16 or later
- [Yarn](https://yarnpkg.com/) Optional/Recommended
- [ODG TsConfig](https://github.com/ODGodinho/tsconfig) Last Version

## ⏩ Get Started

---

### 🔘 Use Event Interface

Install in your project using this command

```powershell
yarn add @odg/events
```

### 📰 Usage

#### 🌎 Implementation

```typescript
interface EventType {
    "event1": number, // receive number
    "userRegister": {
        name: string,
        age: number
    } // receive object,
}

const eventBus = new EventEmitterBus<EventType>();
const callback = (eventMessage: string) => {
    console.log(eventMessage);
};

eventBus.subscribe("event1", callback); // Subscribe before dispatch
eventBus.dispatch("event1", 1); // Send 1 to event1
eventBus.dispatch("userRegister", { name: "ODGodinho", age: 18 }); // Send object to userRegister
```

#### 🌎 Ioc

```typescript
class Example {
    public constructor(
        private eventBus: EventEmitterBus<EventType>
    ) {
    }

    public example(){
        // code ...
        this.eventBus.dispatch("event1", 1);
        // code ...
    }
}
```

## 🏓 Use Event Provider

### 🚡 Enum Events Types

```typescript
enum EventName {
    Example = "Example",
}
```

```typescript
import { type EventObjectType } from "@odg/events";

import { type EventName } from "../app/Enums";

export interface EventExampleParameters {
    // anything params
}

export interface EventBaseInterface extends EventObjectType {
    [EventName.Example]: EventExampleParameters;
}

// IF the above interface does not have all existing laws in the enum it will report an error
export type EventTypes<T extends Record<EventName, unknown> = EventBaseInterface> = T;
```

### 🥮 Make a provider

```typescript
import {
    EventBusInterface,
    EventServiceProvider as EventServiceProviderBase,
    type EventListener,
} from "@odg/events";
import {
    Container,
    // inject, prefer inversify strongly typed Container
    injectable,
} from "inversify";
// if use inversify Strongly Typed Container
import { $inject } from "#app/ContainerInject";

import { type EventTypes } from "../../Interfaces/EventsInterface";
import { ContainerName, EventName } from "../Enums";
import { type HomeEventListeners } from "../Listeners/HomeEventListeners";

@injectable()
export class EventServiceProvider extends EventServiceProviderBase<EventTypes> {

    public constructor(
        @$inject(ContainerName.EventBus) public readonly bus: EventBusInterface<Events>,
    ) {
    }

    /**
     * Listeners for events in the application.
     *
     * @protected
     * @type {EventListener<EventTypes>}
     * @memberof EventServiceProvider
     */
    protected listeners: EventListener<EventTypes> = {
        [EventName.Example]: [
            {
                listener: new HomeEventListeners(), // You can use inversify
                options: {},
            },
        ],
    };

    public async boot(): Promise<void> {
        await super.boot();
    }

    public async shutdown(): Promise<void> {
        await super.shutdown();
    }

}
```

### 🦻 Use Event Listeners

```typescript
import type { EventListenerInterface } from "@odg/events";
import type { LoggerInterface } from "@odg/log";
import { injectable } from "inversify"; // if used inversify

import { type EventExampleType, type EventTypes } from "../../Interfaces/EventsInterface";
import { ContainerName, type EventName } from "../Enums"; // If use inversify
import { PageFactoryType } from "../Factory/PageFactory";
import { $inject } from "#app/ContainerInject"; // If use inversify Strongly Typed Container

@injectable()
export class HomeEventListeners implements EventListenerInterface<EventTypes, EventName.Example> {

    public constructor(
        @$inject(ContainerName.Logger) public readonly logger: LoggerInterface,
    ) {
    }

    public async handler({ page }: EventExampleType): Promise<void> {
        await this.logger.debug("HomeEventListeners is sended");
    }

}
```

### 💻 Prepare To Develop

Copy `.env.example` to `.env` and add the values according to your needs.

### 📍 Start Project

First install dependencies with the following command

```bash
bun install
# or
npm install
```

## 📨 Build and Run

To build the project, you can use the following command

> if you change files, you need to run `bun run build` and `bun run start` again

```bash
bun run build && bun run start
# or
bun run dev
```

## 🧪 Teste Code

To Test execute this command

```bash
bun run test
# or
bun run test:watch
```

---
_Source: https://npm.io/package/@odg/events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
