@tsed/event-emitter 7.0.0-alpha.2 → 7.0.0-beta.11
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/{EventEmitterModule.js → cjs/EventEmitterModule.js} +32 -30
- package/lib/cjs/EventEmitterModule.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/onAny.js +0 -0
- package/lib/cjs/decorators/onAny.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/onEvent.js +0 -0
- package/lib/cjs/decorators/onEvent.js.map +1 -0
- package/lib/cjs/index.js +13 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/EventEmitterStore.js +0 -0
- package/lib/cjs/interfaces/EventEmitterStore.js.map +1 -0
- 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/{services → cjs/services}/EventEmitterFactory.js +1 -1
- package/lib/cjs/services/EventEmitterFactory.js.map +1 -0
- package/lib/esm/EventEmitterModule.js +80 -0
- package/lib/esm/EventEmitterModule.js.map +1 -0
- package/lib/esm/decorators/onAny.js +12 -0
- package/lib/esm/decorators/onAny.js.map +1 -0
- package/lib/esm/decorators/onEvent.js +12 -0
- package/lib/esm/decorators/onEvent.js.map +1 -0
- package/lib/esm/index.js +10 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/EventEmitterStore.js +2 -0
- package/lib/esm/interfaces/EventEmitterStore.js.map +1 -0
- 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/esm/services/EventEmitterFactory.js +12 -0
- package/lib/esm/services/EventEmitterFactory.js.map +1 -0
- package/lib/{EventEmitterModule.d.ts → types/EventEmitterModule.d.ts} +5 -5
- package/lib/{decorators → types/decorators}/onAny.d.ts +0 -0
- package/lib/{decorators → types/decorators}/onEvent.d.ts +0 -0
- package/lib/types/index.d.ts +9 -0
- package/lib/{interfaces → types/interfaces}/EventEmitterStore.d.ts +0 -0
- package/lib/{index.d.ts → types/interfaces/interfaces.d.ts} +0 -3
- package/lib/{services → types/services}/EventEmitterFactory.d.ts +0 -0
- package/package.json +21 -13
- package/readme.md +5 -10
- package/src/EventEmitterModule.ts +33 -28
- package/src/index.ts +7 -19
- package/src/interfaces/interfaces.ts +18 -0
- package/tsconfig.compile.esm.json +12 -0
- package/lib/EventEmitterModule.js.map +0 -1
- package/lib/decorators/index.d.ts +0 -2
- package/lib/decorators/index.js +0 -6
- package/lib/decorators/index.js.map +0 -1
- package/lib/decorators/onAny.js.map +0 -1
- package/lib/decorators/onEvent.js.map +0 -1
- package/lib/index.js +0 -7
- package/lib/index.js.map +0 -1
- package/lib/interfaces/EventEmitterStore.js.map +0 -1
- package/lib/services/EventEmitterFactory.js.map +0 -1
- 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() {
|
|
@@ -19,22 +19,6 @@ let EventEmitterModule = class EventEmitterModule {
|
|
|
19
19
|
this.logger.info("EventEmitter disabled...");
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
addEventListenerForProvider(provider) {
|
|
23
|
-
const store = provider.store.get("eventEmitter");
|
|
24
|
-
const eventListenerDefinitions = Object.entries((store === null || store === void 0 ? void 0 : store.onEvent) || {});
|
|
25
|
-
for (const [propertyKey, { event, options }] of eventListenerDefinitions) {
|
|
26
|
-
const listenerFn = provider.instance[propertyKey].bind(provider.instance);
|
|
27
|
-
this.eventEmitter.on(event, listenerFn, options);
|
|
28
|
-
}
|
|
29
|
-
const anyEventListenerDefinitions = Object.keys((store === null || store === void 0 ? void 0 : store.onAny) || {});
|
|
30
|
-
for (const propertyKey of anyEventListenerDefinitions) {
|
|
31
|
-
const listenerFn = provider.instance[propertyKey].bind(provider.instance);
|
|
32
|
-
this.eventEmitter.onAny(listenerFn);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
getProviders() {
|
|
36
|
-
return Array.from(this.injector.getProviders());
|
|
37
|
-
}
|
|
38
22
|
printEvents() {
|
|
39
23
|
const list = this.eventEmitter.eventNames().map((eventName) => {
|
|
40
24
|
const listenerCount = this.eventEmitter.listenerCount(eventName).toString();
|
|
@@ -43,39 +27,57 @@ let EventEmitterModule = class EventEmitterModule {
|
|
|
43
27
|
listenerCount
|
|
44
28
|
};
|
|
45
29
|
});
|
|
46
|
-
this.
|
|
47
|
-
const str =
|
|
30
|
+
this.logger.info("EventEmitter events mounted:");
|
|
31
|
+
const str = this.logger.drawTable(list, {
|
|
48
32
|
padding: 1,
|
|
49
33
|
header: {
|
|
50
34
|
eventName: "Event name",
|
|
51
35
|
listenerCount: "Number of listener"
|
|
52
36
|
}
|
|
53
37
|
});
|
|
54
|
-
this.
|
|
38
|
+
this.logger.info("\n" + str.trim());
|
|
39
|
+
}
|
|
40
|
+
getProviders() {
|
|
41
|
+
return Array.from(this.injector.getProviders());
|
|
42
|
+
}
|
|
43
|
+
addEventListenerForProvider(provider) {
|
|
44
|
+
const store = provider.store.get("eventEmitter");
|
|
45
|
+
const eventListenerDefinitions = Object.entries((store === null || store === void 0 ? void 0 : store.onEvent) || {});
|
|
46
|
+
for (const [propertyKey, { event, options }] of eventListenerDefinitions) {
|
|
47
|
+
const instance = this.injector.get(provider.token);
|
|
48
|
+
const listenerFn = instance[propertyKey].bind(instance);
|
|
49
|
+
this.eventEmitter.on(event, listenerFn, options);
|
|
50
|
+
}
|
|
51
|
+
const anyEventListenerDefinitions = Object.keys((store === null || store === void 0 ? void 0 : store.onAny) || {});
|
|
52
|
+
for (const propertyKey of anyEventListenerDefinitions) {
|
|
53
|
+
const instance = this.injector.get(provider.token);
|
|
54
|
+
const listenerFn = instance[propertyKey].bind(instance);
|
|
55
|
+
this.eventEmitter.onAny(listenerFn);
|
|
56
|
+
}
|
|
55
57
|
}
|
|
56
58
|
};
|
|
57
59
|
tslib_1.__decorate([
|
|
58
|
-
di_1.
|
|
59
|
-
tslib_1.__metadata("design:type",
|
|
60
|
+
(0, di_1.Constant)("eventEmitter.disableSummary", false),
|
|
61
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
62
|
+
], EventEmitterModule.prototype, "disableSummary", void 0);
|
|
63
|
+
tslib_1.__decorate([
|
|
64
|
+
(0, di_1.Inject)(),
|
|
65
|
+
tslib_1.__metadata("design:type", logger_1.Logger)
|
|
60
66
|
], EventEmitterModule.prototype, "logger", void 0);
|
|
61
67
|
tslib_1.__decorate([
|
|
62
|
-
di_1.Inject(),
|
|
68
|
+
(0, di_1.Inject)(),
|
|
63
69
|
tslib_1.__metadata("design:type", di_1.InjectorService)
|
|
64
70
|
], EventEmitterModule.prototype, "injector", void 0);
|
|
65
71
|
tslib_1.__decorate([
|
|
66
|
-
di_1.Inject(),
|
|
72
|
+
(0, di_1.Inject)(),
|
|
67
73
|
tslib_1.__metadata("design:type", EventEmitterFactory_1.EventEmitterService)
|
|
68
74
|
], EventEmitterModule.prototype, "eventEmitter", void 0);
|
|
69
75
|
tslib_1.__decorate([
|
|
70
|
-
di_1.Constant("eventEmitter.enabled", false),
|
|
76
|
+
(0, di_1.Constant)("eventEmitter.enabled", false),
|
|
71
77
|
tslib_1.__metadata("design:type", Boolean)
|
|
72
78
|
], EventEmitterModule.prototype, "loadEventEmitter", void 0);
|
|
73
|
-
tslib_1.__decorate([
|
|
74
|
-
di_1.Constant("eventEmitter.disableSummary", false),
|
|
75
|
-
tslib_1.__metadata("design:type", Boolean)
|
|
76
|
-
], EventEmitterModule.prototype, "disableSummary", void 0);
|
|
77
79
|
EventEmitterModule = tslib_1.__decorate([
|
|
78
|
-
di_1.Module()
|
|
80
|
+
(0, di_1.Module)()
|
|
79
81
|
], EventEmitterModule);
|
|
80
82
|
exports.EventEmitterModule = EventEmitterModule;
|
|
81
83
|
//# sourceMappingURL=EventEmitterModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAC5D,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC5E,OAAO;gBACL,SAAS;g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pE,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"]}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onAny.js","sourceRoot":"","sources":["../../../src/decorators/onAny.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAGjC,SAAgB,KAAK;IACnB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAsB;YAC/B,KAAK,EAAE;gBACL,CAAC,WAAW,CAAC,EAAE,EAAE;aAClB;SACF,CAAC;QAEF,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC;AAVD,sBAUC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {EventEmitterStore} from \"../interfaces/EventEmitterStore\";\n\nexport function OnAny(): MethodDecorator {\n return (target: any, propertyKey: string) => {\n const store: EventEmitterStore = {\n onAny: {\n [propertyKey]: {}\n }\n };\n\n Store.from(target).merge(\"eventEmitter\", store);\n };\n}\n"]}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onEvent.js","sourceRoot":"","sources":["../../../src/decorators/onEvent.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAIjC,SAAgB,OAAO,CAAC,KAAsB,EAAE,OAA6B;IAC3E,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAsB;YAC/B,OAAO,EAAE;gBACP,CAAC,WAAW,CAAC,EAAE,EAAC,KAAK,EAAE,OAAO,EAAC;aAChC;SACF,CAAC;QAEF,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC;AAVD,0BAUC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {event, eventNS, OnOptions} from \"eventemitter2\";\nimport {EventEmitterStore} from \"../interfaces/EventEmitterStore\";\n\nexport function OnEvent(event: event | eventNS, options?: boolean | OnOptions): MethodDecorator {\n return (target: any, propertyKey: string) => {\n const store: EventEmitterStore = {\n onEvent: {\n [propertyKey]: {event, options}\n }\n };\n\n Store.from(target).merge(\"eventEmitter\", store);\n };\n}\n"]}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
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);
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventEmitterStore.js","sourceRoot":"","sources":["../../../src/interfaces/EventEmitterStore.ts"],"names":[],"mappings":"","sourcesContent":["import {event, eventNS, OnOptions} from \"eventemitter2\";\n\nexport interface EventEmitterStore {\n onEvent?: {[propertyKey: string]: {event: event | eventNS; options?: boolean | OnOptions}};\n onAny?: {[propertyKey: string]: {}};\n}\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"]}
|
|
@@ -4,7 +4,7 @@ exports.EventEmitterService = void 0;
|
|
|
4
4
|
const di_1 = require("@tsed/di");
|
|
5
5
|
const eventemitter2_1 = require("eventemitter2");
|
|
6
6
|
exports.EventEmitterService = eventemitter2_1.EventEmitter2;
|
|
7
|
-
di_1.registerProvider({
|
|
7
|
+
(0, di_1.registerProvider)({
|
|
8
8
|
provide: eventemitter2_1.EventEmitter2,
|
|
9
9
|
deps: [di_1.Configuration],
|
|
10
10
|
useFactory(settings) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventEmitterFactory.js","sourceRoot":"","sources":["../../../src/services/EventEmitterFactory.ts"],"names":[],"mappings":";;;AAAA,iCAAyD;AACzD,iDAAgE;AAEnD,QAAA,mBAAmB,GAAG,6BAAa,CAAC;AAGjD,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,6BAAa;IACtB,IAAI,EAAE,CAAC,kBAAa,CAAC;IACrB,UAAU,CAAC,QAAuB;QAChC,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAA0C,cAAc,EAAE,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;QACrG,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,6BAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {Configuration, registerProvider} from \"@tsed/di\";\nimport {ConstructorOptions, EventEmitter2} from \"eventemitter2\";\n\nexport const EventEmitterService = EventEmitter2;\nexport type EventEmitterService = EventEmitter2;\n\nregisterProvider({\n provide: EventEmitter2,\n deps: [Configuration],\n useFactory(settings: Configuration) {\n const opts = settings.get<ConstructorOptions & {enabled: boolean}>(\"eventEmitter\", {enabled: false});\n return opts.enabled ? new EventEmitter2(opts) : {};\n }\n});\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Constant, Inject, InjectorService, Module } from "@tsed/di";
|
|
3
|
+
import { Logger } from "@tsed/logger";
|
|
4
|
+
import { EventEmitterService } from "./services/EventEmitterFactory.js";
|
|
5
|
+
let EventEmitterModule = class EventEmitterModule {
|
|
6
|
+
async $afterListen() {
|
|
7
|
+
if (this.loadEventEmitter) {
|
|
8
|
+
const providers = this.getProviders();
|
|
9
|
+
providers.forEach((provider) => this.addEventListenerForProvider(provider));
|
|
10
|
+
if (!this.disableSummary) {
|
|
11
|
+
this.printEvents();
|
|
12
|
+
}
|
|
13
|
+
this.logger.info("EventEmitter listening...");
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.logger.info("EventEmitter disabled...");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
printEvents() {
|
|
20
|
+
const list = this.eventEmitter.eventNames().map((eventName) => {
|
|
21
|
+
const listenerCount = this.eventEmitter.listenerCount(eventName).toString();
|
|
22
|
+
return {
|
|
23
|
+
eventName,
|
|
24
|
+
listenerCount
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
this.logger.info("EventEmitter events mounted:");
|
|
28
|
+
const str = this.logger.drawTable(list, {
|
|
29
|
+
padding: 1,
|
|
30
|
+
header: {
|
|
31
|
+
eventName: "Event name",
|
|
32
|
+
listenerCount: "Number of listener"
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
this.logger.info("\n" + str.trim());
|
|
36
|
+
}
|
|
37
|
+
getProviders() {
|
|
38
|
+
return Array.from(this.injector.getProviders());
|
|
39
|
+
}
|
|
40
|
+
addEventListenerForProvider(provider) {
|
|
41
|
+
const store = provider.store.get("eventEmitter");
|
|
42
|
+
const eventListenerDefinitions = Object.entries((store === null || store === void 0 ? void 0 : store.onEvent) || {});
|
|
43
|
+
for (const [propertyKey, { event, options }] of eventListenerDefinitions) {
|
|
44
|
+
const instance = this.injector.get(provider.token);
|
|
45
|
+
const listenerFn = instance[propertyKey].bind(instance);
|
|
46
|
+
this.eventEmitter.on(event, listenerFn, options);
|
|
47
|
+
}
|
|
48
|
+
const anyEventListenerDefinitions = Object.keys((store === null || store === void 0 ? void 0 : store.onAny) || {});
|
|
49
|
+
for (const propertyKey of anyEventListenerDefinitions) {
|
|
50
|
+
const instance = this.injector.get(provider.token);
|
|
51
|
+
const listenerFn = instance[propertyKey].bind(instance);
|
|
52
|
+
this.eventEmitter.onAny(listenerFn);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
__decorate([
|
|
57
|
+
Constant("eventEmitter.disableSummary", false),
|
|
58
|
+
__metadata("design:type", Boolean)
|
|
59
|
+
], EventEmitterModule.prototype, "disableSummary", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
Inject(),
|
|
62
|
+
__metadata("design:type", Logger)
|
|
63
|
+
], EventEmitterModule.prototype, "logger", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
Inject(),
|
|
66
|
+
__metadata("design:type", InjectorService)
|
|
67
|
+
], EventEmitterModule.prototype, "injector", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
Inject(),
|
|
70
|
+
__metadata("design:type", EventEmitterService)
|
|
71
|
+
], EventEmitterModule.prototype, "eventEmitter", void 0);
|
|
72
|
+
__decorate([
|
|
73
|
+
Constant("eventEmitter.enabled", false),
|
|
74
|
+
__metadata("design:type", Boolean)
|
|
75
|
+
], EventEmitterModule.prototype, "loadEventEmitter", void 0);
|
|
76
|
+
EventEmitterModule = __decorate([
|
|
77
|
+
Module()
|
|
78
|
+
], EventEmitterModule);
|
|
79
|
+
export { EventEmitterModule };
|
|
80
|
+
//# sourceMappingURL=EventEmitterModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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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BACS,MAAM;kDAAC;AAGzB;IADC,MAAM,EAAE;8BACW,eAAe;oDAAC;AAGpC;IADC,MAAM,EAAE;8BACe,mBAAmB;wDAAC;AAG5C;IADC,QAAQ,CAAC,sBAAsB,EAAE,KAAK,CAAC;;4DACN;AAdvB,kBAAkB;IAD9B,MAAM,EAAE;GACI,kBAAkB,CA2E9B;SA3EY,kBAAkB","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onAny.js","sourceRoot":"","sources":["../../../src/decorators/onAny.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAGjC,MAAM,UAAU,KAAK;IACnB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAsB;YAC/B,KAAK,EAAE;gBACL,CAAC,WAAW,CAAC,EAAE,EAAE;aAClB;SACF,CAAC;QAEF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {EventEmitterStore} from \"../interfaces/EventEmitterStore\";\n\nexport function OnAny(): MethodDecorator {\n return (target: any, propertyKey: string) => {\n const store: EventEmitterStore = {\n onAny: {\n [propertyKey]: {}\n }\n };\n\n Store.from(target).merge(\"eventEmitter\", store);\n };\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
export function OnEvent(event, options) {
|
|
3
|
+
return (target, propertyKey) => {
|
|
4
|
+
const store = {
|
|
5
|
+
onEvent: {
|
|
6
|
+
[propertyKey]: { event, options }
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
Store.from(target).merge("eventEmitter", store);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=onEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onEvent.js","sourceRoot":"","sources":["../../../src/decorators/onEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAIjC,MAAM,UAAU,OAAO,CAAC,KAAsB,EAAE,OAA6B;IAC3E,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAsB;YAC/B,OAAO,EAAE;gBACP,CAAC,WAAW,CAAC,EAAE,EAAC,KAAK,EAAE,OAAO,EAAC;aAChC;SACF,CAAC;QAEF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {event, eventNS, OnOptions} from \"eventemitter2\";\nimport {EventEmitterStore} from \"../interfaces/EventEmitterStore\";\n\nexport function OnEvent(event: event | eventNS, options?: boolean | OnOptions): MethodDecorator {\n return (target: any, propertyKey: string) => {\n const store: EventEmitterStore = {\n onEvent: {\n [propertyKey]: {event, options}\n }\n };\n\n Store.from(target).merge(\"eventEmitter\", store);\n };\n}\n"]}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":"EventEmitterStore.js","sourceRoot":"","sources":["../../../src/interfaces/EventEmitterStore.ts"],"names":[],"mappings":"","sourcesContent":["import {event, eventNS, OnOptions} from \"eventemitter2\";\n\nexport interface EventEmitterStore {\n onEvent?: {[propertyKey: string]: {event: event | eventNS; options?: boolean | OnOptions}};\n onAny?: {[propertyKey: string]: {}};\n}\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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Configuration, registerProvider } from "@tsed/di";
|
|
2
|
+
import { EventEmitter2 } from "eventemitter2";
|
|
3
|
+
export const EventEmitterService = EventEmitter2;
|
|
4
|
+
registerProvider({
|
|
5
|
+
provide: EventEmitter2,
|
|
6
|
+
deps: [Configuration],
|
|
7
|
+
useFactory(settings) {
|
|
8
|
+
const opts = settings.get("eventEmitter", { enabled: false });
|
|
9
|
+
return opts.enabled ? new EventEmitter2(opts) : {};
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=EventEmitterFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventEmitterFactory.js","sourceRoot":"","sources":["../../../src/services/EventEmitterFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AACzD,OAAO,EAAqB,aAAa,EAAC,MAAM,eAAe,CAAC;AAEhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAa,CAAC;AAGjD,gBAAgB,CAAC;IACf,OAAO,EAAE,aAAa;IACtB,IAAI,EAAE,CAAC,aAAa,CAAC;IACrB,UAAU,CAAC,QAAuB;QAChC,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAA0C,cAAc,EAAE,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;QACrG,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {Configuration, registerProvider} from \"@tsed/di\";\nimport {ConstructorOptions, EventEmitter2} from \"eventemitter2\";\n\nexport const EventEmitterService = EventEmitter2;\nexport type EventEmitterService = EventEmitter2;\n\nregisterProvider({\n provide: EventEmitter2,\n deps: [Configuration],\n useFactory(settings: Configuration) {\n const opts = settings.get<ConstructorOptions & {enabled: boolean}>(\"eventEmitter\", {enabled: false});\n return opts.enabled ? new EventEmitter2(opts) : {};\n }\n});\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
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
|
+
disableSummary: boolean;
|
|
5
6
|
protected logger: Logger;
|
|
6
7
|
protected injector: InjectorService;
|
|
7
8
|
protected eventEmitter: EventEmitterService;
|
|
8
9
|
private loadEventEmitter;
|
|
9
|
-
disableSummary: boolean;
|
|
10
10
|
$afterListen(): Promise<any>;
|
|
11
|
-
private addEventListenerForProvider;
|
|
12
|
-
protected getProviders(): Provider<any>[];
|
|
13
11
|
printEvents(): void;
|
|
12
|
+
protected getProviders(): Provider<any>[];
|
|
13
|
+
private addEventListenerForProvider;
|
|
14
14
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./EventEmitterModule";
|
|
5
|
+
export * from "./decorators/onAny";
|
|
6
|
+
export * from "./decorators/onEvent";
|
|
7
|
+
export * from "./interfaces/EventEmitterStore";
|
|
8
|
+
export * from "./interfaces/interfaces";
|
|
9
|
+
export * from "./services/EventEmitterFactory";
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/event-emitter",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-beta.11",
|
|
4
4
|
"description": "EventEmitter package for Ts.ED framework",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"source": "./src/index.ts",
|
|
6
|
+
"main": "./lib/cjs/index.js",
|
|
7
|
+
"module": "./lib/esm/index.js",
|
|
8
|
+
"typings": "./lib/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"import": "./lib/esm/index.js",
|
|
12
|
+
"require": "./lib/cjs/index.js",
|
|
13
|
+
"default": "./lib/esm/index.js"
|
|
14
|
+
},
|
|
7
15
|
"scripts": {
|
|
8
|
-
"build": "
|
|
16
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
19
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
9
20
|
"test": "cross-env NODE_ENV=test nyc mocha"
|
|
10
21
|
},
|
|
11
22
|
"dependencies": {
|
|
12
|
-
"tslib": "2.
|
|
23
|
+
"tslib": "2.3.1"
|
|
13
24
|
},
|
|
14
25
|
"private": false,
|
|
15
26
|
"devDependencies": {
|
|
16
|
-
"@tsed/common": "7.0.0-
|
|
17
|
-
"@tsed/core": "7.0.0-
|
|
18
|
-
"@tsed/di": "7.0.0-
|
|
27
|
+
"@tsed/common": "7.0.0-beta.11",
|
|
28
|
+
"@tsed/core": "7.0.0-beta.11",
|
|
29
|
+
"@tsed/di": "7.0.0-beta.11",
|
|
19
30
|
"eventemitter2": "^6.4.4"
|
|
20
31
|
},
|
|
21
32
|
"peerDependencies": {
|
|
@@ -25,10 +36,7 @@
|
|
|
25
36
|
"bugs": {
|
|
26
37
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
27
38
|
},
|
|
28
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
39
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/third-parties/event-emitter",
|
|
29
40
|
"author": "Romain Lenzotti",
|
|
30
|
-
"license": "MIT"
|
|
31
|
-
"publishConfig": {
|
|
32
|
-
"tag": "alpha"
|
|
33
|
-
}
|
|
41
|
+
"license": "MIT"
|
|
34
42
|
}
|
package/readme.md
CHANGED
|
@@ -64,14 +64,12 @@ import "@tsed/event-emitter"; // import event emitter ts.ed module
|
|
|
64
64
|
|
|
65
65
|
@Configuration({
|
|
66
66
|
eventEmitter: {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
enabled: true, // Enable events for this instance.
|
|
68
|
+
// pass any options that you would normally pass to new EventEmitter2(), e.g.
|
|
69
|
+
wildcard: true
|
|
70
70
|
}
|
|
71
71
|
})
|
|
72
|
-
export class Server {
|
|
73
|
-
|
|
74
|
-
}
|
|
72
|
+
export class Server {}
|
|
75
73
|
```
|
|
76
74
|
|
|
77
75
|
## Setup event listener
|
|
@@ -109,7 +107,6 @@ import {EventEmitterService} from "@tsed/event-emitter";
|
|
|
109
107
|
|
|
110
108
|
@Service()
|
|
111
109
|
export class OrderService {
|
|
112
|
-
|
|
113
110
|
@Inject()
|
|
114
111
|
private eventEmitter: EventEmitterService;
|
|
115
112
|
|
|
@@ -118,23 +115,21 @@ export class OrderService {
|
|
|
118
115
|
// then send an event
|
|
119
116
|
this.eventEmitter.emit("order.shipped", {orderId});
|
|
120
117
|
}
|
|
121
|
-
|
|
122
118
|
}
|
|
123
119
|
```
|
|
124
120
|
|
|
125
121
|
## Contributors
|
|
122
|
+
|
|
126
123
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
127
124
|
|
|
128
125
|
<a href="https://github.com/tsedio/tsed/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
129
126
|
|
|
130
|
-
|
|
131
127
|
## Backers
|
|
132
128
|
|
|
133
129
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
134
130
|
|
|
135
131
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
|
|
136
132
|
|
|
137
|
-
|
|
138
133
|
## Sponsors
|
|
139
134
|
|
|
140
135
|
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,14 @@
|
|
|
1
|
-
import {$log, AfterListen, Logger, OnDestroy} 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
|
+
@Constant("eventEmitter.disableSummary", false)
|
|
10
|
+
disableSummary: boolean;
|
|
11
|
+
|
|
9
12
|
@Inject()
|
|
10
13
|
protected logger: Logger;
|
|
11
14
|
|
|
@@ -18,9 +21,6 @@ export class EventEmitterModule implements AfterListen {
|
|
|
18
21
|
@Constant("eventEmitter.enabled", false)
|
|
19
22
|
private loadEventEmitter: boolean;
|
|
20
23
|
|
|
21
|
-
@Constant("eventEmitter.disableSummary", false)
|
|
22
|
-
disableSummary: boolean;
|
|
23
|
-
|
|
24
24
|
async $afterListen(): Promise<any> {
|
|
25
25
|
if (this.loadEventEmitter) {
|
|
26
26
|
const providers = this.getProviders();
|
|
@@ -34,26 +34,6 @@ export class EventEmitterModule implements AfterListen {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
private addEventListenerForProvider(provider: Provider<any>) {
|
|
38
|
-
const store = provider.store.get<EventEmitterStore | undefined>("eventEmitter");
|
|
39
|
-
|
|
40
|
-
const eventListenerDefinitions = Object.entries(store?.onEvent || {});
|
|
41
|
-
for (const [propertyKey, {event, options}] of eventListenerDefinitions) {
|
|
42
|
-
const listenerFn: ListenerFn = provider.instance[propertyKey].bind(provider.instance) as ListenerFn;
|
|
43
|
-
this.eventEmitter.on(event, listenerFn, options);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const anyEventListenerDefinitions = Object.keys(store?.onAny || {});
|
|
47
|
-
for (const propertyKey of anyEventListenerDefinitions) {
|
|
48
|
-
const listenerFn: ListenerFn = provider.instance[propertyKey].bind(provider.instance) as ListenerFn;
|
|
49
|
-
this.eventEmitter.onAny(listenerFn);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
protected getProviders(): Provider<any>[] {
|
|
54
|
-
return Array.from(this.injector.getProviders());
|
|
55
|
-
}
|
|
56
|
-
|
|
57
37
|
public printEvents() {
|
|
58
38
|
const list = this.eventEmitter.eventNames().map((eventName) => {
|
|
59
39
|
const listenerCount = this.eventEmitter.listenerCount(eventName).toString();
|
|
@@ -63,9 +43,9 @@ export class EventEmitterModule implements AfterListen {
|
|
|
63
43
|
};
|
|
64
44
|
});
|
|
65
45
|
|
|
66
|
-
this.
|
|
46
|
+
this.logger.info("EventEmitter events mounted:");
|
|
67
47
|
|
|
68
|
-
const str =
|
|
48
|
+
const str = this.logger.drawTable(list, {
|
|
69
49
|
padding: 1,
|
|
70
50
|
header: {
|
|
71
51
|
eventName: "Event name",
|
|
@@ -73,6 +53,31 @@ export class EventEmitterModule implements AfterListen {
|
|
|
73
53
|
}
|
|
74
54
|
});
|
|
75
55
|
|
|
76
|
-
this.
|
|
56
|
+
this.logger.info("\n" + str.trim());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected getProviders(): Provider<any>[] {
|
|
60
|
+
return Array.from(this.injector.getProviders());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private addEventListenerForProvider(provider: Provider<any>) {
|
|
64
|
+
const store = provider.store.get<EventEmitterStore | undefined>("eventEmitter");
|
|
65
|
+
|
|
66
|
+
const eventListenerDefinitions = Object.entries(store?.onEvent || {});
|
|
67
|
+
|
|
68
|
+
for (const [propertyKey, {event, options}] of eventListenerDefinitions) {
|
|
69
|
+
const instance = this.injector.get(provider.token);
|
|
70
|
+
|
|
71
|
+
const listenerFn: ListenerFn = instance[propertyKey].bind(instance) as ListenerFn;
|
|
72
|
+
this.eventEmitter.on(event, listenerFn, options);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const anyEventListenerDefinitions = Object.keys(store?.onAny || {});
|
|
76
|
+
for (const propertyKey of anyEventListenerDefinitions) {
|
|
77
|
+
const instance = this.injector.get(provider.token);
|
|
78
|
+
|
|
79
|
+
const listenerFn: ListenerFn = instance[propertyKey].bind(instance) as ListenerFn;
|
|
80
|
+
this.eventEmitter.onAny(listenerFn);
|
|
81
|
+
}
|
|
77
82
|
}
|
|
78
83
|
}
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.compile.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationDir": "./lib/types"
|
|
10
|
+
},
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
12
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventEmitterModule.js","sourceRoot":"","sources":["../src/EventEmitterModule.ts"],"names":[],"mappings":";;;;AAAA,yCAAkE;AAClE,iCAA6E;AAG7E,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;IAEO,2BAA2B,CAAC,QAAuB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J,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QAE1D,MAAM,GAAG,GAAG,aAAI,CAAC,SAAS,CAAC,IAAI,EAAE;YAC/B,OAAO,EAAE,CAAC;YACV,MAAM,EAAE;gBACN,SAAS,EAAE,YAAY;gBACvB,aAAa,EAAE,oBAAoB;aACpC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF,CAAA;AApEC;IADC,WAAM,EAAE;sCACS,eAAM;kDAAC;AAGzB;IADC,WAAM,EAAE;sCACW,oBAAe;oDAAC;AAGpC;IADC,WAAM,EAAE;sCACe,yCAAmB;wDAAC;AAG5C;IADC,aAAQ,CAAC,sBAAsB,EAAE,KAAK,CAAC;;4DACN;AAGlC;IADC,aAAQ,CAAC,6BAA6B,EAAE,KAAK,CAAC;;0DACvB;AAdb,kBAAkB;IAD9B,WAAM,EAAE;GACI,kBAAkB,CAsE9B;AAtEY,gDAAkB","sourcesContent":["import {$log, AfterListen, Logger, OnDestroy} from \"@tsed/common\";\nimport {Constant, Inject, InjectorService, Module, Provider} from \"@tsed/di\";\nimport {ListenerFn} from \"eventemitter2\";\nimport {EventEmitterStore} from \"./interfaces/EventEmitterStore\";\nimport {EventEmitterService} from \"./services/EventEmitterFactory\";\n\n@Module()\nexport class EventEmitterModule implements AfterListen {\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 @Constant(\"eventEmitter.disableSummary\", false)\n disableSummary: 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 private addEventListenerForProvider(provider: Provider<any>) {\n const store = provider.store.get<EventEmitterStore | undefined>(\"eventEmitter\");\n\n const eventListenerDefinitions = Object.entries(store?.onEvent || {});\n for (const [propertyKey, {event, options}] of eventListenerDefinitions) {\n const listenerFn: ListenerFn = provider.instance[propertyKey].bind(provider.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 listenerFn: ListenerFn = provider.instance[propertyKey].bind(provider.instance) as ListenerFn;\n this.eventEmitter.onAny(listenerFn);\n }\n }\n\n protected getProviders(): Provider<any>[] {\n return Array.from(this.injector.getProviders());\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.injector.logger.info(\"EventEmitter events mounted:\");\n\n const str = $log.drawTable(list, {\n padding: 1,\n header: {\n eventName: \"Event name\",\n listenerCount: \"Number of listener\"\n }\n });\n\n this.injector.logger.info(\"\\n\" + str.trim());\n }\n}\n"]}
|
package/lib/decorators/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,oDAA0B;AAC1B,kDAAwB","sourcesContent":["export * from \"./onEvent\";\nexport * from \"./onAny\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onAny.js","sourceRoot":"","sources":["../../src/decorators/onAny.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAGjC,SAAgB,KAAK;IACnB,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAsB;YAC/B,KAAK,EAAE;gBACL,CAAC,WAAW,CAAC,EAAE,EAAE;aAClB;SACF,CAAC;QAEF,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC;AAVD,sBAUC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {EventEmitterStore} from \"../interfaces/EventEmitterStore\";\n\nexport function OnAny(): MethodDecorator {\n return (target: any, propertyKey: string) => {\n const store: EventEmitterStore = {\n onAny: {\n [propertyKey]: {}\n }\n };\n\n Store.from(target).merge(\"eventEmitter\", store);\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onEvent.js","sourceRoot":"","sources":["../../src/decorators/onEvent.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAIjC,SAAgB,OAAO,CAAC,KAAsB,EAAE,OAA6B;IAC3E,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAsB;YAC/B,OAAO,EAAE;gBACP,CAAC,WAAW,CAAC,EAAE,EAAC,KAAK,EAAE,OAAO,EAAC;aAChC;SACF,CAAC;QAEF,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC;AAVD,0BAUC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {event, eventNS, OnOptions} from \"eventemitter2\";\nimport {EventEmitterStore} from \"../interfaces/EventEmitterStore\";\n\nexport function OnEvent(event: event | eventNS, options?: boolean | OnOptions): MethodDecorator {\n return (target: any, propertyKey: string) => {\n const store: EventEmitterStore = {\n onEvent: {\n [propertyKey]: {event, options}\n }\n };\n\n Store.from(target).merge(\"eventEmitter\", store);\n };\n}\n"]}
|
package/lib/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./EventEmitterModule"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./services/EventEmitterFactory"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./decorators"), exports);
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAmBA,+DAAqC;AACrC,yEAA+C;AAC/C,uDAA6B","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\nexport * from \"./EventEmitterModule\";\nexport * from \"./services/EventEmitterFactory\";\nexport * from \"./decorators\";\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventEmitterStore.js","sourceRoot":"","sources":["../../src/interfaces/EventEmitterStore.ts"],"names":[],"mappings":"","sourcesContent":["import {event, eventNS, OnOptions} from \"eventemitter2\";\n\nexport interface EventEmitterStore {\n onEvent?: {[propertyKey: string]: {event: event | eventNS; options?: boolean | OnOptions}};\n onAny?: {[propertyKey: string]: {}};\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventEmitterFactory.js","sourceRoot":"","sources":["../../src/services/EventEmitterFactory.ts"],"names":[],"mappings":";;;AAAA,iCAAyD;AACzD,iDAAgE;AAEnD,QAAA,mBAAmB,GAAG,6BAAa,CAAC;AAGjD,qBAAgB,CAAC;IACf,OAAO,EAAE,6BAAa;IACtB,IAAI,EAAE,CAAC,kBAAa,CAAC;IACrB,UAAU,CAAC,QAAuB;QAChC,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAA0C,cAAc,EAAE,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;QACrG,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,6BAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {Configuration, registerProvider} from \"@tsed/di\";\nimport {ConstructorOptions, EventEmitter2} from \"eventemitter2\";\n\nexport const EventEmitterService = EventEmitter2;\nexport type EventEmitterService = EventEmitter2;\n\nregisterProvider({\n provide: EventEmitter2,\n deps: [Configuration],\n useFactory(settings: Configuration) {\n const opts = settings.get<ConstructorOptions & {enabled: boolean}>(\"eventEmitter\", {enabled: false});\n return opts.enabled ? new EventEmitter2(opts) : {};\n }\n});\n"]}
|
package/src/decorators/index.ts
DELETED