@midwayjs/event-emitter 4.0.0-alpha.1

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/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # midwayjs etcd module
2
+
3
+ [![Package Quality](http://npm.packagequality.com/shield/midway-core.svg)](http://packagequality.com/#?package=midway-core)
4
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/midwayjs/midway/pulls)
5
+
6
+ this is a sub package for midway.
7
+
8
+ Document: [https://midwayjs.org](https://midwayjs.org)
9
+
10
+ ## License
11
+
12
+ [MIT]((https://github.com/midwayjs/midway/blob/master/LICENSE))
@@ -0,0 +1,4 @@
1
+ export declare class EventEmitterConfiguration {
2
+ onReady(container: any): Promise<void>;
3
+ }
4
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.EventEmitterConfiguration = void 0;
10
+ const core_1 = require("@midwayjs/core");
11
+ let EventEmitterConfiguration = class EventEmitterConfiguration {
12
+ async onReady(container) {
13
+ }
14
+ };
15
+ exports.EventEmitterConfiguration = EventEmitterConfiguration;
16
+ exports.EventEmitterConfiguration = EventEmitterConfiguration = __decorate([
17
+ (0, core_1.Configuration)({
18
+ namespace: 'eventEmitter',
19
+ importConfigs: [
20
+ {
21
+ default: {
22
+ eventEmitter: {
23
+ defaultMaxListeners: 10,
24
+ },
25
+ },
26
+ },
27
+ ],
28
+ })
29
+ ], EventEmitterConfiguration);
30
+ //# sourceMappingURL=configuration.js.map
@@ -0,0 +1,2 @@
1
+ export declare const EVENT_KEY = "eventEmitter:on_event";
2
+ //# sourceMappingURL=const.d.ts.map
package/dist/const.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVENT_KEY = void 0;
4
+ exports.EVENT_KEY = 'eventEmitter:on_event';
5
+ //# sourceMappingURL=const.js.map
@@ -0,0 +1,3 @@
1
+ import { OnOptions, event, eventNS } from 'eventemitter2';
2
+ export declare function OnEvent(event: event | eventNS, options?: OnOptions): MethodDecorator;
3
+ //# sourceMappingURL=decorator.d.ts.map
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OnEvent = void 0;
4
+ const core_1 = require("@midwayjs/core");
5
+ const const_1 = require("./const");
6
+ function OnEvent(event, options) {
7
+ return (target, propertyKey) => {
8
+ core_1.DecoratorManager.saveModule(const_1.EVENT_KEY, target.constructor);
9
+ core_1.MetadataManager.defineMetadata(const_1.EVENT_KEY, {
10
+ event,
11
+ options,
12
+ }, target.constructor, propertyKey);
13
+ };
14
+ }
15
+ exports.OnEvent = OnEvent;
16
+ //# sourceMappingURL=decorator.js.map
@@ -0,0 +1,5 @@
1
+ export { EventEmitterConfiguration as Configuration } from './configuration';
2
+ export { EventEmitterService } from './service';
3
+ export * from './decorator';
4
+ export * from './interface';
5
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.EventEmitterService = exports.Configuration = void 0;
18
+ var configuration_1 = require("./configuration");
19
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.EventEmitterConfiguration; } });
20
+ var service_1 = require("./service");
21
+ Object.defineProperty(exports, "EventEmitterService", { enumerable: true, get: function () { return service_1.EventEmitterService; } });
22
+ __exportStar(require("./decorator"), exports);
23
+ __exportStar(require("./interface"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import { ConstructorOptions } from 'eventemitter2';
2
+ export interface EventEmitterConfigOptions extends ConstructorOptions {
3
+ }
4
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1,10 @@
1
+ import { EventEmitter2 as EventEmitter } from 'eventemitter2';
2
+ export declare class EventEmitterService implements EventEmitter {
3
+ private eventEmitter;
4
+ private config;
5
+ init(): Promise<void>;
6
+ getEventEmitter(): EventEmitter;
7
+ }
8
+ export interface EventEmitterService extends EventEmitter {
9
+ }
10
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EventEmitterService = void 0;
13
+ const eventemitter2_1 = require("eventemitter2");
14
+ const core_1 = require("@midwayjs/core");
15
+ const const_1 = require("./const");
16
+ let EventEmitterService = class EventEmitterService {
17
+ async init() {
18
+ this.eventEmitter = new eventemitter2_1.EventEmitter2(this.config);
19
+ // proxy eventEmitter public methods to this
20
+ const methods = Object.getOwnPropertyNames(eventemitter2_1.EventEmitter2.prototype);
21
+ for (const method of methods) {
22
+ if (method !== 'constructor' && typeof this.eventEmitter[method] === 'function') {
23
+ this[method] = this.eventEmitter[method].bind(this.eventEmitter);
24
+ }
25
+ }
26
+ const events = core_1.DecoratorManager.listModule(const_1.EVENT_KEY);
27
+ for (const eventModule of events) {
28
+ const props = core_1.MetadataManager.getPropertiesWithMetadata(const_1.EVENT_KEY, eventModule);
29
+ for (const prop in props) {
30
+ const { event, options } = props[prop];
31
+ this.eventEmitter.on(event, options);
32
+ }
33
+ }
34
+ }
35
+ getEventEmitter() {
36
+ return this.eventEmitter;
37
+ }
38
+ };
39
+ exports.EventEmitterService = EventEmitterService;
40
+ __decorate([
41
+ (0, core_1.Config)('eventEmitter'),
42
+ __metadata("design:type", Object)
43
+ ], EventEmitterService.prototype, "config", void 0);
44
+ __decorate([
45
+ (0, core_1.Init)(),
46
+ __metadata("design:type", Function),
47
+ __metadata("design:paramtypes", []),
48
+ __metadata("design:returntype", Promise)
49
+ ], EventEmitterService.prototype, "init", null);
50
+ exports.EventEmitterService = EventEmitterService = __decorate([
51
+ (0, core_1.Singleton)()
52
+ ], EventEmitterService);
53
+ (0, core_1.delegateTargetPrototypeMethod)(EventEmitterService, [eventemitter2_1.EventEmitter2]);
54
+ //# sourceMappingURL=service.js.map
package/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { EventEmitterConfigOptions } from './dist/index';
2
+ export * from './dist/index';
3
+
4
+ declare module '@midwayjs/core/dist/interface' {
5
+ interface MidwayConfig {
6
+ eventEmitter?: Partial<EventEmitterConfigOptions>;
7
+ }
8
+ }
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@midwayjs/event-emitter",
3
+ "description": "midway event emitter component",
4
+ "version": "4.0.0-alpha.1",
5
+ "main": "dist/index.js",
6
+ "typings": "index.d.ts",
7
+ "files": [
8
+ "dist/**/*.js",
9
+ "dist/**/*.d.ts",
10
+ "index.d.ts"
11
+ ],
12
+ "devDependencies": {
13
+ "@midwayjs/core": "workspace:^",
14
+ "@midwayjs/mock": "workspace:^"
15
+ },
16
+ "dependencies": {
17
+ "eventemitter2": "6.4.9"
18
+ },
19
+ "keywords": [
20
+ "eventemitter",
21
+ "midway"
22
+ ],
23
+ "author": "czy88840616 <czy88840616@gmail.com>",
24
+ "license": "MIT",
25
+ "scripts": {
26
+ "build": "tsc",
27
+ "test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
28
+ "cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
29
+ "ci": "npm run test",
30
+ "lint": "mwts check"
31
+ },
32
+ "engines": {
33
+ "node": ">=16"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/midwayjs/midway.git"
38
+ }
39
+ }