Skip to content

Commit

Permalink
feat: types adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
onhate committed Dec 14, 2023
1 parent f176fd4 commit 01da4fd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nest-events",
"version": "2.0.3",
"version": "2.0.5",
"private": false,
"license": "MIT",
"repository": {
Expand All @@ -22,7 +22,7 @@
"scripts": {
"build": "tsc --project tsconfig-build.json",
"prebuild": "npx rimraf dist",
"prepublish": "npm run build",
"prepublishOnly": "npm run build",
"lint": "eslint \"{src}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
Expand Down
3 changes: 2 additions & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Inject, Optional } from '@nestjs/common';
import { ConstructorOptions, EventEmitter2 } from 'eventemitter2';

export type IEventEmitter = Pick<EventEmitter2, 'emitAsync' | 'on' | 'off'>;
export const Options = Symbol('EventBusModuleOptions');


export class DefaultEventEmitter extends EventEmitter2 implements IEventEmitter {
constructor(@Optional() @Inject('Options') options?: ConstructorOptions) {
constructor(@Optional() @Inject(Options) options?: ConstructorOptions) {
super(options);
}
}
2 changes: 1 addition & 1 deletion src/eventbus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class EventBus {
return await this.emitter().emitAsync(event, ...args);
}

public emitter(emitter: string = 'default'): IEventEmitter | undefined {
public emitter(emitter: string = 'default'): IEventEmitter {
if (this.module.getEmitters().has(emitter)) {
return this.module.getEmitters().get(emitter);
}
Expand Down
4 changes: 2 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DynamicModule, Module } from '@nestjs/common';
import { DiscoveryModule } from '@nestjs/core';
import { ConstructorOptions } from 'eventemitter2';
import { DefaultEventEmitter } from './definitions';
import { DefaultEventEmitter, Options } from './definitions';
import { EventBus } from './eventbus';
import { EventBusInitializer } from './initializer';

Expand All @@ -23,7 +23,7 @@ export class EventBusModule {
module: EventBusModule,
imports: [DiscoveryModule],
providers: [
{ provide: 'Options', useValue: options },
{ provide: Options, useValue: options },
EventBusInitializer,
EventBus,
DefaultEventEmitter
Expand Down

0 comments on commit 01da4fd

Please sign in to comment.