@tsed/event-emitter 7.0.0-beta.1 → 7.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.js +2 -2
- package/.nycrc +1 -1
- package/lib/cjs/EventEmitterModule.js +15 -15
- package/lib/cjs/EventEmitterModule.js.map +1 -1
- package/lib/cjs/index.js +9 -3
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/interfaces.js +3 -0
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/esm/EventEmitterModule.js +5 -5
- package/lib/esm/EventEmitterModule.js.map +1 -1
- package/lib/esm/index.js +9 -3
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/types/EventEmitterModule.d.ts +2 -2
- package/lib/types/index.d.ts +7 -18
- package/lib/types/interfaces/interfaces.d.ts +17 -0
- package/package.json +13 -8
- package/readme.md +7 -11
- package/src/EventEmitterModule.ts +5 -5
- package/src/index.ts +7 -19
- package/src/interfaces/interfaces.ts +18 -0
- package/tsconfig.compile.esm.json +1 -12
- package/lib/cjs/decorators/index.js +0 -6
- package/lib/cjs/decorators/index.js.map +0 -1
- package/lib/esm/decorators/index.js +0 -3
- package/lib/esm/decorators/index.js.map +0 -1
- package/lib/types/decorators/index.d.ts +0 -2
- package/src/decorators/index.ts +0 -2
package/.mocharc.js
CHANGED
package/.nycrc
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EventEmitterModule = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@tsed/common");
|
|
6
5
|
const di_1 = require("@tsed/di");
|
|
6
|
+
const logger_1 = require("@tsed/logger");
|
|
7
7
|
const EventEmitterFactory_1 = require("./services/EventEmitterFactory");
|
|
8
8
|
let EventEmitterModule = class EventEmitterModule {
|
|
9
9
|
async $afterListen() {
|
|
@@ -27,15 +27,15 @@ let EventEmitterModule = class EventEmitterModule {
|
|
|
27
27
|
listenerCount
|
|
28
28
|
};
|
|
29
29
|
});
|
|
30
|
-
this.
|
|
31
|
-
const str =
|
|
30
|
+
this.logger.info("EventEmitter events mounted:");
|
|
31
|
+
const str = this.logger.drawTable(list, {
|
|
32
32
|
padding: 1,
|
|
33
33
|
header: {
|
|
34
34
|
eventName: "Event name",
|
|
35
35
|
listenerCount: "Number of listener"
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
this.
|
|
38
|
+
this.logger.info("\n" + str.trim());
|
|
39
39
|
}
|
|
40
40
|
getProviders() {
|
|
41
41
|
return Array.from(this.injector.getProviders());
|
|
@@ -56,27 +56,27 @@ let EventEmitterModule = class EventEmitterModule {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
tslib_1.__decorate([
|
|
60
60
|
(0, di_1.Constant)("eventEmitter.disableSummary", false),
|
|
61
|
-
|
|
61
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
62
62
|
], EventEmitterModule.prototype, "disableSummary", void 0);
|
|
63
|
-
|
|
63
|
+
tslib_1.__decorate([
|
|
64
64
|
(0, di_1.Inject)(),
|
|
65
|
-
|
|
65
|
+
tslib_1.__metadata("design:type", logger_1.Logger)
|
|
66
66
|
], EventEmitterModule.prototype, "logger", void 0);
|
|
67
|
-
|
|
67
|
+
tslib_1.__decorate([
|
|
68
68
|
(0, di_1.Inject)(),
|
|
69
|
-
|
|
69
|
+
tslib_1.__metadata("design:type", di_1.InjectorService)
|
|
70
70
|
], EventEmitterModule.prototype, "injector", void 0);
|
|
71
|
-
|
|
71
|
+
tslib_1.__decorate([
|
|
72
72
|
(0, di_1.Inject)(),
|
|
73
|
-
|
|
73
|
+
tslib_1.__metadata("design:type", EventEmitterFactory_1.EventEmitterService)
|
|
74
74
|
], EventEmitterModule.prototype, "eventEmitter", void 0);
|
|
75
|
-
|
|
75
|
+
tslib_1.__decorate([
|
|
76
76
|
(0, di_1.Constant)("eventEmitter.enabled", false),
|
|
77
|
-
|
|
77
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
78
78
|
], EventEmitterModule.prototype, "loadEventEmitter", void 0);
|
|
79
|
-
EventEmitterModule =
|
|
79
|
+
EventEmitterModule = tslib_1.__decorate([
|
|
80
80
|
(0, di_1.Module)()
|
|
81
81
|
], EventEmitterModule);
|
|
82
82
|
exports.EventEmitterModule = EventEmitterModule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventEmitterModule.js","sourceRoot":"","sources":["../../src/EventEmitterModule.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"EventEmitterModule.js","sourceRoot":"","sources":["../../src/EventEmitterModule.ts"],"names":[],"mappings":";;;;AAAA,iCAA6E;AAC7E,yCAAoC;AAGpC,wEAAmE;AAGnE,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAgB7B,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC5E,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;gBACxB,IAAI,CAAC,WAAW,EAAE,CAAC;aACpB;YACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;SAC/C;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;SAC9C;IACH,CAAC;IAEM,WAAW;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,C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AAE,UAAU,EAAE,OAAO,CAAC,CAAC;SAClD;QAED,MAAM,2BAA2B,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,KAAI,EAAE,CAAC,CAAC;QACpE,KAAK,MAAM,WAAW,IAAI,2BAA2B,EAAE;YACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAEnD,MAAM,UAAU,GAAe,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAe,CAAC;YAClF,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;SACrC;IACH,CAAC;CACF,CAAA;AAzEC;IADC,IAAA,aAAQ,EAAC,6BAA6B,EAAE,KAAK,CAAC;;0DACvB;AAGxB;IADC,IAAA,WAAM,GAAE;sCACS,eAAM;kDAAC;AAGzB;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;oDAAC;AAGpC;IADC,IAAA,WAAM,GAAE;sCACe,yCAAmB;wDAAC;AAG5C;IADC,IAAA,aAAQ,EAAC,sBAAsB,EAAE,KAAK,CAAC;;4DACN;AAdvB,kBAAkB;IAD9B,IAAA,WAAM,GAAE;GACI,kBAAkB,CA2E9B;AA3EY,gDAAkB","sourcesContent":["import {Constant, Inject, InjectorService, Module, Provider} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {ListenerFn} from \"eventemitter2\";\nimport {EventEmitterStore} from \"./interfaces/EventEmitterStore\";\nimport {EventEmitterService} from \"./services/EventEmitterFactory\";\n\n@Module()\nexport class EventEmitterModule {\n @Constant(\"eventEmitter.disableSummary\", false)\n disableSummary: boolean;\n\n @Inject()\n protected logger: Logger;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected eventEmitter: EventEmitterService;\n\n @Constant(\"eventEmitter.enabled\", false)\n private loadEventEmitter: boolean;\n\n async $afterListen(): Promise<any> {\n if (this.loadEventEmitter) {\n const providers = this.getProviders();\n providers.forEach((provider) => this.addEventListenerForProvider(provider));\n if (!this.disableSummary) {\n this.printEvents();\n }\n this.logger.info(\"EventEmitter listening...\");\n } else {\n this.logger.info(\"EventEmitter disabled...\");\n }\n }\n\n public printEvents() {\n const list = this.eventEmitter.eventNames().map((eventName) => {\n const listenerCount = this.eventEmitter.listenerCount(eventName).toString();\n return {\n eventName,\n listenerCount\n };\n });\n\n this.logger.info(\"EventEmitter events mounted:\");\n\n const str = this.logger.drawTable(list, {\n padding: 1,\n header: {\n eventName: \"Event name\",\n listenerCount: \"Number of listener\"\n }\n });\n\n this.logger.info(\"\\n\" + str.trim());\n }\n\n protected getProviders(): Provider<any>[] {\n return Array.from(this.injector.getProviders());\n }\n\n private addEventListenerForProvider(provider: Provider<any>) {\n const store = provider.store.get<EventEmitterStore | undefined>(\"eventEmitter\");\n\n const eventListenerDefinitions = Object.entries(store?.onEvent || {});\n\n for (const [propertyKey, {event, options}] of eventListenerDefinitions) {\n const instance = this.injector.get(provider.token);\n\n const listenerFn: ListenerFn = instance[propertyKey].bind(instance) as ListenerFn;\n this.eventEmitter.on(event, listenerFn, options);\n }\n\n const anyEventListenerDefinitions = Object.keys(store?.onAny || {});\n for (const propertyKey of anyEventListenerDefinitions) {\n const instance = this.injector.get(provider.token);\n\n const listenerFn: ListenerFn = instance[propertyKey].bind(instance) as ListenerFn;\n this.eventEmitter.onAny(listenerFn);\n }\n }\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
tslib_1.__exportStar(require("./EventEmitterModule"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./decorators/onAny"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./decorators/onEvent"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./interfaces/EventEmitterStore"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./services/EventEmitterFactory"), exports);
|
|
7
13
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,+DAAqC;AACrC,6DAAmC;AACnC,+DAAqC;AACrC,yEAA+C;AAC/C,kEAAwC;AACxC,yEAA+C","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./EventEmitterModule\";\nexport * from \"./decorators/onAny\";\nexport * from \"./decorators/onEvent\";\nexport * from \"./interfaces/EventEmitterStore\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./services/EventEmitterFactory\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {ConstructorOptions} from \"eventemitter2\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n eventEmitter?: {\n /**\n * Enable Event Emitter. Default `false`.\n */\n enabled?: boolean;\n /**\n * Disable event table displayed in the logger. Default `false`.\n */\n disableSummary?: boolean;\n } & ConstructorOptions;\n }\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import { $log, Logger } from "@tsed/common";
|
|
3
2
|
import { Constant, Inject, InjectorService, Module } from "@tsed/di";
|
|
4
|
-
import {
|
|
3
|
+
import { Logger } from "@tsed/logger";
|
|
4
|
+
import { EventEmitterService } from "./services/EventEmitterFactory.js";
|
|
5
5
|
let EventEmitterModule = class EventEmitterModule {
|
|
6
6
|
async $afterListen() {
|
|
7
7
|
if (this.loadEventEmitter) {
|
|
@@ -24,15 +24,15 @@ let EventEmitterModule = class EventEmitterModule {
|
|
|
24
24
|
listenerCount
|
|
25
25
|
};
|
|
26
26
|
});
|
|
27
|
-
this.
|
|
28
|
-
const str =
|
|
27
|
+
this.logger.info("EventEmitter events mounted:");
|
|
28
|
+
const str = this.logger.drawTable(list, {
|
|
29
29
|
padding: 1,
|
|
30
30
|
header: {
|
|
31
31
|
eventName: "Event name",
|
|
32
32
|
listenerCount: "Number of listener"
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
|
-
this.
|
|
35
|
+
this.logger.info("\n" + str.trim());
|
|
36
36
|
}
|
|
37
37
|
getProviders() {
|
|
38
38
|
return Array.from(this.injector.getProviders());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EventEmitterModule.js","sourceRoot":"","sources":["../../src/EventEmitterModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"EventEmitterModule.js","sourceRoot":"","sources":["../../src/EventEmitterModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAW,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAGpC,OAAO,EAAC,mBAAmB,EAAC,MAAM,gCAAgC,CAAC;AAGnE,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAgB7B,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACzB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YACtC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI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/logger\";\nimport {ListenerFn} from \"eventemitter2\";\nimport {EventEmitterStore} from \"./interfaces/EventEmitterStore\";\nimport {EventEmitterService} from \"./services/EventEmitterFactory\";\n\n@Module()\nexport class EventEmitterModule {\n @Constant(\"eventEmitter.disableSummary\", false)\n disableSummary: boolean;\n\n @Inject()\n protected logger: Logger;\n\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected eventEmitter: EventEmitterService;\n\n @Constant(\"eventEmitter.enabled\", false)\n private loadEventEmitter: boolean;\n\n async $afterListen(): Promise<any> {\n if (this.loadEventEmitter) {\n const providers = this.getProviders();\n providers.forEach((provider) => this.addEventListenerForProvider(provider));\n if (!this.disableSummary) {\n this.printEvents();\n }\n this.logger.info(\"EventEmitter listening...\");\n } else {\n this.logger.info(\"EventEmitter disabled...\");\n }\n }\n\n public printEvents() {\n const list = this.eventEmitter.eventNames().map((eventName) => {\n const listenerCount = this.eventEmitter.listenerCount(eventName).toString();\n return {\n eventName,\n listenerCount\n };\n });\n\n this.logger.info(\"EventEmitter events mounted:\");\n\n const str = this.logger.drawTable(list, {\n padding: 1,\n header: {\n eventName: \"Event name\",\n listenerCount: \"Number of listener\"\n }\n });\n\n this.logger.info(\"\\n\" + str.trim());\n }\n\n protected getProviders(): Provider<any>[] {\n return Array.from(this.injector.getProviders());\n }\n\n private addEventListenerForProvider(provider: Provider<any>) {\n const store = provider.store.get<EventEmitterStore | undefined>(\"eventEmitter\");\n\n const eventListenerDefinitions = Object.entries(store?.onEvent || {});\n\n for (const [propertyKey, {event, options}] of eventListenerDefinitions) {\n const instance = this.injector.get(provider.token);\n\n const listenerFn: ListenerFn = instance[propertyKey].bind(instance) as ListenerFn;\n this.eventEmitter.on(event, listenerFn, options);\n }\n\n const anyEventListenerDefinitions = Object.keys(store?.onAny || {});\n for (const propertyKey of anyEventListenerDefinitions) {\n const instance = this.injector.get(provider.token);\n\n const listenerFn: ListenerFn = instance[propertyKey].bind(instance) as ListenerFn;\n this.eventEmitter.onAny(listenerFn);\n }\n }\n}\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./EventEmitterModule.js";
|
|
5
|
+
export * from "./decorators/onAny.js";
|
|
6
|
+
export * from "./decorators/onEvent.js";
|
|
7
|
+
export * from "./interfaces/EventEmitterStore.js";
|
|
8
|
+
export * from "./interfaces/interfaces.js";
|
|
9
|
+
export * from "./services/EventEmitterFactory.js";
|
|
4
10
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./EventEmitterModule\";\nexport * from \"./decorators/onAny\";\nexport * from \"./decorators/onEvent\";\nexport * from \"./interfaces/EventEmitterStore\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./services/EventEmitterFactory\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import {ConstructorOptions} from \"eventemitter2\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n eventEmitter?: {\n /**\n * Enable Event Emitter. Default `false`.\n */\n enabled?: boolean;\n /**\n * Disable event table displayed in the logger. Default `false`.\n */\n disableSummary?: boolean;\n } & ConstructorOptions;\n }\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AfterListen, Logger } from "@tsed/common";
|
|
2
1
|
import { InjectorService, Provider } from "@tsed/di";
|
|
2
|
+
import { Logger } from "@tsed/logger";
|
|
3
3
|
import { EventEmitterService } from "./services/EventEmitterFactory";
|
|
4
|
-
export declare class EventEmitterModule
|
|
4
|
+
export declare class EventEmitterModule {
|
|
5
5
|
disableSummary: boolean;
|
|
6
6
|
protected logger: Logger;
|
|
7
7
|
protected injector: InjectorService;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface Configuration {
|
|
5
|
-
eventEmitter?: {
|
|
6
|
-
/**
|
|
7
|
-
* Enable Event Emitter. Default `false`.
|
|
8
|
-
*/
|
|
9
|
-
enabled?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Disable event table displayed in the logger. Default `false`.
|
|
12
|
-
*/
|
|
13
|
-
disableSummary?: boolean;
|
|
14
|
-
} & ConstructorOptions;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
18
4
|
export * from "./EventEmitterModule";
|
|
5
|
+
export * from "./decorators/onAny";
|
|
6
|
+
export * from "./decorators/onEvent";
|
|
7
|
+
export * from "./interfaces/EventEmitterStore";
|
|
8
|
+
export * from "./interfaces/interfaces";
|
|
19
9
|
export * from "./services/EventEmitterFactory";
|
|
20
|
-
export * from "./decorators";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConstructorOptions } from "eventemitter2";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace TsED {
|
|
4
|
+
interface Configuration {
|
|
5
|
+
eventEmitter?: {
|
|
6
|
+
/**
|
|
7
|
+
* Enable Event Emitter. Default `false`.
|
|
8
|
+
*/
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Disable event table displayed in the logger. Default `false`.
|
|
12
|
+
*/
|
|
13
|
+
disableSummary?: boolean;
|
|
14
|
+
} & ConstructorOptions;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/event-emitter",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.12",
|
|
4
4
|
"description": "EventEmitter package for Ts.ED framework",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
7
|
+
"module": "./lib/esm/index.js",
|
|
7
8
|
"typings": "./lib/types/index.d.ts",
|
|
8
9
|
"exports": {
|
|
9
10
|
"types": "./lib/types/index.d.ts",
|
|
@@ -12,19 +13,20 @@
|
|
|
12
13
|
"default": "./lib/esm/index.js"
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
15
|
-
"build": "yarn run build:esm && yarn run build:cjs",
|
|
16
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
16
17
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
17
18
|
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
19
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
18
20
|
"test": "cross-env NODE_ENV=test nyc mocha"
|
|
19
21
|
},
|
|
20
22
|
"dependencies": {
|
|
21
|
-
"tslib": "2.
|
|
23
|
+
"tslib": "2.3.1"
|
|
22
24
|
},
|
|
23
25
|
"private": false,
|
|
24
26
|
"devDependencies": {
|
|
25
|
-
"@tsed/common": "7.0.0-beta.
|
|
26
|
-
"@tsed/core": "7.0.0-beta.
|
|
27
|
-
"@tsed/di": "7.0.0-beta.
|
|
27
|
+
"@tsed/common": "7.0.0-beta.12",
|
|
28
|
+
"@tsed/core": "7.0.0-beta.12",
|
|
29
|
+
"@tsed/di": "7.0.0-beta.12",
|
|
28
30
|
"eventemitter2": "^6.4.4"
|
|
29
31
|
},
|
|
30
32
|
"peerDependencies": {
|
|
@@ -34,7 +36,10 @@
|
|
|
34
36
|
"bugs": {
|
|
35
37
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
36
38
|
},
|
|
37
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
39
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/third-parties/event-emitter",
|
|
38
40
|
"author": "Romain Lenzotti",
|
|
39
|
-
"license": "MIT"
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"tag": "beta"
|
|
44
|
+
}
|
|
40
45
|
}
|
package/readme.md
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
13
13
|
[](https://github.com/semantic-release/semantic-release)
|
|
14
14
|
[](https://github.com/prettier/prettier)
|
|
15
|
-
[](https://github.com/sponsors/romakita)
|
|
16
|
+
[](https://opencollective.com/tsed)
|
|
16
17
|
|
|
17
18
|
</div>
|
|
18
19
|
|
|
@@ -64,14 +65,12 @@ import "@tsed/event-emitter"; // import event emitter ts.ed module
|
|
|
64
65
|
|
|
65
66
|
@Configuration({
|
|
66
67
|
eventEmitter: {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
enabled: true, // Enable events for this instance.
|
|
69
|
+
// pass any options that you would normally pass to new EventEmitter2(), e.g.
|
|
70
|
+
wildcard: true
|
|
70
71
|
}
|
|
71
72
|
})
|
|
72
|
-
export class Server {
|
|
73
|
-
|
|
74
|
-
}
|
|
73
|
+
export class Server {}
|
|
75
74
|
```
|
|
76
75
|
|
|
77
76
|
## Setup event listener
|
|
@@ -109,7 +108,6 @@ import {EventEmitterService} from "@tsed/event-emitter";
|
|
|
109
108
|
|
|
110
109
|
@Service()
|
|
111
110
|
export class OrderService {
|
|
112
|
-
|
|
113
111
|
@Inject()
|
|
114
112
|
private eventEmitter: EventEmitterService;
|
|
115
113
|
|
|
@@ -118,23 +116,21 @@ export class OrderService {
|
|
|
118
116
|
// then send an event
|
|
119
117
|
this.eventEmitter.emit("order.shipped", {orderId});
|
|
120
118
|
}
|
|
121
|
-
|
|
122
119
|
}
|
|
123
120
|
```
|
|
124
121
|
|
|
125
122
|
## Contributors
|
|
123
|
+
|
|
126
124
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
127
125
|
|
|
128
126
|
<a href="https://github.com/tsedio/tsed/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
129
127
|
|
|
130
|
-
|
|
131
128
|
## Backers
|
|
132
129
|
|
|
133
130
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
134
131
|
|
|
135
132
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
|
|
136
133
|
|
|
137
|
-
|
|
138
134
|
## Sponsors
|
|
139
135
|
|
|
140
136
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {$log, AfterListen, Logger} from "@tsed/common";
|
|
2
1
|
import {Constant, Inject, InjectorService, Module, Provider} from "@tsed/di";
|
|
2
|
+
import {Logger} from "@tsed/logger";
|
|
3
3
|
import {ListenerFn} from "eventemitter2";
|
|
4
4
|
import {EventEmitterStore} from "./interfaces/EventEmitterStore";
|
|
5
5
|
import {EventEmitterService} from "./services/EventEmitterFactory";
|
|
6
6
|
|
|
7
7
|
@Module()
|
|
8
|
-
export class EventEmitterModule
|
|
8
|
+
export class EventEmitterModule {
|
|
9
9
|
@Constant("eventEmitter.disableSummary", false)
|
|
10
10
|
disableSummary: boolean;
|
|
11
11
|
|
|
@@ -43,9 +43,9 @@ export class EventEmitterModule implements AfterListen {
|
|
|
43
43
|
};
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
this.
|
|
46
|
+
this.logger.info("EventEmitter events mounted:");
|
|
47
47
|
|
|
48
|
-
const str =
|
|
48
|
+
const str = this.logger.drawTable(list, {
|
|
49
49
|
padding: 1,
|
|
50
50
|
header: {
|
|
51
51
|
eventName: "Event name",
|
|
@@ -53,7 +53,7 @@ export class EventEmitterModule implements AfterListen {
|
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
this.
|
|
56
|
+
this.logger.info("\n" + str.trim());
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
protected getProviders(): Provider<any>[] {
|
package/src/index.ts
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
namespace TsED {
|
|
5
|
-
interface Configuration {
|
|
6
|
-
eventEmitter?: {
|
|
7
|
-
/**
|
|
8
|
-
* Enable Event Emitter. Default `false`.
|
|
9
|
-
*/
|
|
10
|
-
enabled?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Disable event table displayed in the logger. Default `false`.
|
|
13
|
-
*/
|
|
14
|
-
disableSummary?: boolean;
|
|
15
|
-
} & ConstructorOptions;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
19
4
|
|
|
20
5
|
export * from "./EventEmitterModule";
|
|
6
|
+
export * from "./decorators/onAny";
|
|
7
|
+
export * from "./decorators/onEvent";
|
|
8
|
+
export * from "./interfaces/EventEmitterStore";
|
|
9
|
+
export * from "./interfaces/interfaces";
|
|
21
10
|
export * from "./services/EventEmitterFactory";
|
|
22
|
-
export * from "./decorators";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {ConstructorOptions} from "eventemitter2";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
namespace TsED {
|
|
5
|
+
interface Configuration {
|
|
6
|
+
eventEmitter?: {
|
|
7
|
+
/**
|
|
8
|
+
* Enable Event Emitter. Default `false`.
|
|
9
|
+
*/
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Disable event table displayed in the logger. Default `false`.
|
|
13
|
+
*/
|
|
14
|
+
disableSummary?: boolean;
|
|
15
|
+
} & ConstructorOptions;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -8,16 +8,5 @@
|
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"declarationDir": "./lib/types"
|
|
10
10
|
},
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules",
|
|
13
|
-
"test",
|
|
14
|
-
"lib",
|
|
15
|
-
"benchmark",
|
|
16
|
-
"coverage",
|
|
17
|
-
"spec",
|
|
18
|
-
"**/*.benchmark.ts",
|
|
19
|
-
"**/*.spec.ts",
|
|
20
|
-
"keys",
|
|
21
|
-
"jest.config.js"
|
|
22
|
-
]
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
23
12
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,yDAA0B;AAC1B,uDAAwB","sourcesContent":["export * from \"./onEvent\";\nexport * from \"./onAny\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC","sourcesContent":["export * from \"./onEvent\";\nexport * from \"./onAny\";\n"]}
|
package/src/decorators/index.ts
DELETED