@hg-ts/events 0.3.4 → 0.4.0
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/dist/base.event.js +1 -5
- package/dist/base.event.js.map +1 -1
- package/dist/decorators/index.d.ts +1 -1
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js +1 -4
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/listen.decorator.d.ts +1 -1
- package/dist/decorators/listen.decorator.d.ts.map +1 -1
- package/dist/decorators/listen.decorator.js +4 -11
- package/dist/decorators/listen.decorator.js.map +1 -1
- package/dist/empty.event.d.ts +1 -1
- package/dist/empty.event.d.ts.map +1 -1
- package/dist/empty.event.js +2 -6
- package/dist/empty.event.js.map +1 -1
- package/dist/event-handling/base.event-transport.d.ts +1 -1
- package/dist/event-handling/base.event-transport.d.ts.map +1 -1
- package/dist/event-handling/base.event-transport.js +1 -5
- package/dist/event-handling/base.event-transport.js.map +1 -1
- package/dist/event-handling/event-emitter.d.ts +2 -2
- package/dist/event-handling/event-emitter.d.ts.map +1 -1
- package/dist/event-handling/event-emitter.js +1 -5
- package/dist/event-handling/event-emitter.js.map +1 -1
- package/dist/event-handling/event-listener-manager.d.ts +1 -1
- package/dist/event-handling/event-listener-manager.d.ts.map +1 -1
- package/dist/event-handling/event-listener-manager.js +6 -10
- package/dist/event-handling/event-listener-manager.js.map +1 -1
- package/dist/event-handling/event-publisher.d.ts +3 -3
- package/dist/event-handling/event-publisher.d.ts.map +1 -1
- package/dist/event-handling/event-publisher.js +4 -9
- package/dist/event-handling/event-publisher.js.map +1 -1
- package/dist/event-handling/index.d.ts +4 -4
- package/dist/event-handling/index.d.ts.map +1 -1
- package/dist/event-handling/index.js +4 -7
- package/dist/event-handling/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/tests/event-listener-manager.test.d.ts.map +1 -1
- package/dist/tests/event-listener-manager.test.js +40 -43
- package/dist/tests/event-listener-manager.test.js.map +1 -1
- package/dist/tests/event-publisher.test.d.ts.map +1 -1
- package/dist/tests/event-publisher.test.js +64 -67
- package/dist/tests/event-publisher.test.js.map +1 -1
- package/package.json +6 -5
- package/tsconfig.json +1 -1
package/dist/base.event.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseEvent = void 0;
|
|
4
|
-
class BaseEvent {
|
|
1
|
+
export class BaseEvent {
|
|
5
2
|
occurredOn;
|
|
6
3
|
name;
|
|
7
4
|
body;
|
|
@@ -13,5 +10,4 @@ class BaseEvent {
|
|
|
13
10
|
this.traceId = traceId ?? null;
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
exports.BaseEvent = BaseEvent;
|
|
17
13
|
//# sourceMappingURL=base.event.js.map
|
package/dist/base.event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.event.js","sourceRoot":"","sources":["../src/base.event.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.event.js","sourceRoot":"","sources":["../src/base.event.ts"],"names":[],"mappings":"AAcA,MAAM,OAAgB,SAAS;IACd,UAAU,CAAO;IACjB,IAAI,CAAS;IACb,IAAI,CAAO;IAEX,OAAO,CAAmB;IAE1C,YAAmB,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI,IAAI,EAAE,EAAE,OAAO,EAAqB;QACrF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAE1C,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC;IAChC,CAAC;CACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './listen.decorator';
|
|
1
|
+
export * from './listen.decorator.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
package/dist/decorators/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseEvent } from '../base.event';
|
|
1
|
+
import type { BaseEvent } from '../base.event.js';
|
|
2
2
|
export type EventHandler<T extends BaseEvent = BaseEvent> = (event: T) => any;
|
|
3
3
|
export declare const Listen: <T extends BaseEvent>(eventClass: Class<T, any[]>) => (proto: Object, propertyKey: string | symbol, _descriptor: TypedPropertyDescriptor<EventHandler<T>>) => void;
|
|
4
4
|
export declare function getEventsToHandle(proto: Object, propertyKey: string | symbol): Class<BaseEvent>[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listen.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/listen.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"listen.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/listen.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC;AAE9E,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,SAAS,cAAc,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,aAC/D,MAAM,eACA,MAAM,GAAG,MAAM,eACf,uBAAuB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KACnD,IAWF,CAAC;AAEF,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,MAAM,GAC1B,KAAK,CAAC,SAAS,CAAC,EAAE,CAEpB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAEnE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtD"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Listen = void 0;
|
|
4
|
-
exports.getEventsToHandle = getEventsToHandle;
|
|
5
|
-
exports.getListenMethods = getListenMethods;
|
|
6
|
-
exports.isEventListener = isEventListener;
|
|
7
1
|
const LISTEN_META_KEY = Symbol('LISTEN_META_KEY');
|
|
8
2
|
const LISTEN_METHODS_META_KEY = Symbol('LISTEN_METHODS_META_KEY');
|
|
9
|
-
const Listen = (eventClass) => (proto, propertyKey, _descriptor) => {
|
|
3
|
+
export const Listen = (eventClass) => (proto, propertyKey, _descriptor) => {
|
|
10
4
|
const eventsToHandle = getEventsToHandle(proto, propertyKey);
|
|
11
5
|
const listenMethods = getListenMethods(proto);
|
|
12
6
|
eventsToHandle.push(eventClass);
|
|
@@ -16,14 +10,13 @@ const Listen = (eventClass) => (proto, propertyKey, _descriptor) => {
|
|
|
16
10
|
Reflect.defineMetadata(LISTEN_META_KEY, eventsToHandle, proto, propertyKey);
|
|
17
11
|
Reflect.defineMetadata(LISTEN_METHODS_META_KEY, listenMethods, proto);
|
|
18
12
|
};
|
|
19
|
-
|
|
20
|
-
function getEventsToHandle(proto, propertyKey) {
|
|
13
|
+
export function getEventsToHandle(proto, propertyKey) {
|
|
21
14
|
return Reflect.getMetadata(LISTEN_META_KEY, proto, propertyKey) ?? [];
|
|
22
15
|
}
|
|
23
|
-
function getListenMethods(proto) {
|
|
16
|
+
export function getListenMethods(proto) {
|
|
24
17
|
return Reflect.getMetadata(LISTEN_METHODS_META_KEY, proto) ?? [];
|
|
25
18
|
}
|
|
26
|
-
function isEventListener(proto) {
|
|
19
|
+
export function isEventListener(proto) {
|
|
27
20
|
return getListenMethods(proto).length > 0;
|
|
28
21
|
}
|
|
29
22
|
//# sourceMappingURL=listen.decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listen.decorator.js","sourceRoot":"","sources":["../../src/decorators/listen.decorator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"listen.decorator.js","sourceRoot":"","sources":["../../src/decorators/listen.decorator.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAClD,MAAM,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAIlE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAsB,UAA2B,EAAE,EAAE,CAAC,CAC3E,KAAa,EACb,WAA4B,EAC5B,WAAqD,EAC9C,EAAE;IACT,MAAM,cAAc,GAAG,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC7D,MAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAE9C,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAChC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAC1C,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,CAAC,cAAc,CAAC,eAAe,EAAE,cAAc,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5E,OAAO,CAAC,cAAc,CAAC,uBAAuB,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;AACvE,CAAC,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAChC,KAAa,EACb,WAA4B;IAE5B,OAAO,OAAO,CAAC,WAAW,CAAC,eAAe,EAAE,KAAK,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC7C,OAAO,OAAO,CAAC,WAAW,CAAC,uBAAuB,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAa;IAC5C,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/empty.event.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty.event.d.ts","sourceRoot":"","sources":["../src/empty.event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"empty.event.d.ts","sourceRoot":"","sources":["../src/empty.event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,qBAAa,UAAW,SAAQ,SAAS;;CAIxC"}
|
package/dist/empty.event.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.EmptyEvent = void 0;
|
|
4
|
-
const base_event_1 = require("./base.event");
|
|
5
|
-
class EmptyEvent extends base_event_1.BaseEvent {
|
|
1
|
+
import { BaseEvent } from './base.event.js';
|
|
2
|
+
export class EmptyEvent extends BaseEvent {
|
|
6
3
|
constructor() {
|
|
7
4
|
super({ body: null });
|
|
8
5
|
}
|
|
9
6
|
}
|
|
10
|
-
exports.EmptyEvent = EmptyEvent;
|
|
11
7
|
//# sourceMappingURL=empty.event.js.map
|
package/dist/empty.event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty.event.js","sourceRoot":"","sources":["../src/empty.event.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"empty.event.js","sourceRoot":"","sources":["../src/empty.event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,UAAW,SAAQ,SAAS;IACxC;QACC,KAAK,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IACvB,CAAC;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.event-transport.d.ts","sourceRoot":"","sources":["../../src/event-handling/base.event-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"base.event-transport.d.ts","sourceRoot":"","sources":["../../src/event-handling/base.event-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,8BAAsB,kBAAkB;aACvB,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CACtE"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseEventTransport = void 0;
|
|
4
|
-
class BaseEventTransport {
|
|
1
|
+
export class BaseEventTransport {
|
|
5
2
|
}
|
|
6
|
-
exports.BaseEventTransport = BaseEventTransport;
|
|
7
3
|
//# sourceMappingURL=base.event-transport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.event-transport.js","sourceRoot":"","sources":["../../src/event-handling/base.event-transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.event-transport.js","sourceRoot":"","sources":["../../src/event-handling/base.event-transport.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,kBAAkB;CAEvC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BaseEvent } from '../base.event';
|
|
2
|
-
import type { EventPublisher } from './event-publisher';
|
|
1
|
+
import type { BaseEvent } from '../base.event.js';
|
|
2
|
+
import type { EventPublisher } from './event-publisher.js';
|
|
3
3
|
export declare class EventEmitter {
|
|
4
4
|
private readonly transports;
|
|
5
5
|
constructor(eventPublisher: EventPublisher);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../../src/event-handling/event-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"event-emitter.d.ts","sourceRoot":"","sources":["../../src/event-handling/event-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,qBAAa,YAAY;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;gBAE/B,cAAc,EAAE,cAAc;IAIpC,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAGhE"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventEmitter = void 0;
|
|
4
|
-
class EventEmitter {
|
|
1
|
+
export class EventEmitter {
|
|
5
2
|
transports;
|
|
6
3
|
constructor(eventPublisher) {
|
|
7
4
|
this.transports = [eventPublisher];
|
|
@@ -10,5 +7,4 @@ class EventEmitter {
|
|
|
10
7
|
await Promise.all(this.transports.map(async (transport) => transport.publish(event)));
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
|
-
exports.EventEmitter = EventEmitter;
|
|
14
10
|
//# sourceMappingURL=event-emitter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-emitter.js","sourceRoot":"","sources":["../../src/event-handling/event-emitter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-emitter.js","sourceRoot":"","sources":["../../src/event-handling/event-emitter.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,YAAY;IACP,UAAU,CAAuB;IAElD,YAAmB,cAA8B;QAChD,IAAI,CAAC,UAAU,GAAG,CAAC,cAAc,CAAC,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,KAA8B;QAC/C,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAC,SAAS,EAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrF,CAAC;CACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import type { EventPublisher } from './event-publisher';
|
|
2
|
+
import type { EventPublisher } from './event-publisher.js';
|
|
3
3
|
export declare class EventListenerManager {
|
|
4
4
|
private readonly eventPublisher;
|
|
5
5
|
constructor(eventPublisher: EventPublisher);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-listener-manager.d.ts","sourceRoot":"","sources":["../../src/event-handling/event-listener-manager.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAS1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"event-listener-manager.d.ts","sourceRoot":"","sources":["../../src/event-handling/event-listener-manager.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAS1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,qBAAa,oBAAoB;IAChC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;gBAE7B,cAAc,EAAE,cAAc;IAI1C,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;CAkB3C"}
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
const decorators_1 = require("../decorators");
|
|
6
|
-
class EventListenerManager {
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { getEventsToHandle, getListenMethods, isEventListener, } from '../decorators/index.js';
|
|
3
|
+
export class EventListenerManager {
|
|
7
4
|
eventPublisher;
|
|
8
5
|
constructor(eventPublisher) {
|
|
9
6
|
this.eventPublisher = eventPublisher;
|
|
10
7
|
}
|
|
11
8
|
addListener(instance) {
|
|
12
9
|
const proto = Object.getPrototypeOf(instance);
|
|
13
|
-
if (!proto || !
|
|
10
|
+
if (!proto || !isEventListener(proto)) {
|
|
14
11
|
return;
|
|
15
12
|
}
|
|
16
|
-
const listenMethods =
|
|
13
|
+
const listenMethods = getListenMethods(proto);
|
|
17
14
|
const listener = instance;
|
|
18
15
|
listenMethods.forEach(methodName => {
|
|
19
16
|
const method = listener[methodName].bind(listener);
|
|
20
|
-
const eventsToHandle =
|
|
17
|
+
const eventsToHandle = getEventsToHandle(proto, methodName);
|
|
21
18
|
eventsToHandle.forEach(eventCtor => {
|
|
22
19
|
this.eventPublisher['addListener'](eventCtor, method);
|
|
23
20
|
});
|
|
24
21
|
});
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
exports.EventListenerManager = EventListenerManager;
|
|
28
24
|
//# sourceMappingURL=event-listener-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-listener-manager.js","sourceRoot":"","sources":["../../src/event-handling/event-listener-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-listener-manager.js","sourceRoot":"","sources":["../../src/event-handling/event-listener-manager.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAEN,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GACf,MAAM,wBAAwB,CAAC;AAIhC,MAAM,OAAO,oBAAoB;IACf,cAAc,CAAiB;IAEhD,YAAmB,cAA8B;QAChD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACtC,CAAC;IAEM,WAAW,CAAC,QAAiB;QACnC,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YACvC,OAAO;QACR,CAAC;QAED,MAAM,aAAa,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAiC,QAAe,CAAC;QAE/D,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAClC,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAiB,CAAC;YACnE,MAAM,cAAc,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;YAE5D,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;gBAClC,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YACvD,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BaseEvent } from '../base.event';
|
|
2
|
-
import type { EventHandler } from '../decorators';
|
|
3
|
-
import type { BaseEventTransport } from './base.event-transport';
|
|
1
|
+
import { BaseEvent } from '../base.event.js';
|
|
2
|
+
import type { EventHandler } from '../decorators/index.js';
|
|
3
|
+
import type { BaseEventTransport } from './base.event-transport.js';
|
|
4
4
|
export declare class EventPublisher implements BaseEventTransport {
|
|
5
5
|
private readonly listeners;
|
|
6
6
|
publish(event: BaseEvent | BaseEvent[]): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-publisher.d.ts","sourceRoot":"","sources":["../../src/event-handling/event-publisher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"event-publisher.d.ts","sourceRoot":"","sources":["../../src/event-handling/event-publisher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,qBAAa,cAAe,YAAW,kBAAkB;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoD;IAEjE,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;cAMnD,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3D,SAAS,CAAC,WAAW,CAAC,KAAK,SAAS,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,IAAI;IAQ5G,OAAO,CAAC,aAAa;CASrB"}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const strict_1 = tslib_1.__importDefault(require("node:assert/strict"));
|
|
6
|
-
const base_event_1 = require("../base.event");
|
|
7
|
-
class EventPublisher {
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { BaseEvent } from '../base.event.js';
|
|
3
|
+
export class EventPublisher {
|
|
8
4
|
listeners = new Map();
|
|
9
5
|
async publish(event) {
|
|
10
6
|
const events = Array.isArray(event) ? event : [event];
|
|
11
7
|
await Promise.all(events.map(async (event) => this.publishOne(event)));
|
|
12
8
|
}
|
|
13
9
|
async publishOne(event) {
|
|
14
|
-
|
|
10
|
+
assert.ok(event instanceof BaseEvent);
|
|
15
11
|
const listeners = this.findListeners(event);
|
|
16
12
|
await Promise.all(listeners.map(async (listener) => listener(event)));
|
|
17
13
|
}
|
|
@@ -29,5 +25,4 @@ class EventPublisher {
|
|
|
29
25
|
.flatMap(ctor => this.listeners.get(ctor) ?? []);
|
|
30
26
|
}
|
|
31
27
|
}
|
|
32
|
-
exports.EventPublisher = EventPublisher;
|
|
33
28
|
//# sourceMappingURL=event-publisher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-publisher.js","sourceRoot":"","sources":["../../src/event-handling/event-publisher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-publisher.js","sourceRoot":"","sources":["../../src/event-handling/event-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAI7C,MAAM,OAAO,cAAc;IACT,SAAS,GAA0C,IAAI,GAAG,EAAE,CAAC;IAEvE,KAAK,CAAC,OAAO,CAAC,KAA8B;QAClD,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAEtD,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAC,KAAK,EAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtE,CAAC;IAES,KAAK,CAAC,UAAU,CAAC,KAAgB;QAC1C,MAAM,CAAC,EAAE,CAAC,KAAK,YAAY,SAAS,CAAC,CAAC;QACtC,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAE5C,MAAM,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAC,QAAQ,EAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC;IAES,WAAW,CAA0B,SAAuB,EAAE,QAA6B;QACpG,MAAM,SAAS,GAA0B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;QAE7E,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEzB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,SAA2B,CAAC,CAAC;IAC5D,CAAC;IAEO,aAAa,CAAC,KAAgB;QACrC,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAE,CAAC,WAAW,CAAC;QAC5D,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;QAEhD,OAAO,YAAY;aACjB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,YAAY,IAAI,IAAI,SAAS,KAAK,IAAI,CAAC;aACzE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACnD,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;CACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './event-emitter';
|
|
2
|
-
export * from './event-publisher';
|
|
3
|
-
export * from './event-listener-manager';
|
|
4
|
-
export * from './base.event-transport';
|
|
1
|
+
export * from './event-emitter.js';
|
|
2
|
+
export * from './event-publisher.js';
|
|
3
|
+
export * from './event-listener-manager.js';
|
|
4
|
+
export * from './base.event-transport.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/event-handling/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/event-handling/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tslib_1.__exportStar(require("./event-publisher"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./event-listener-manager"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./base.event-transport"), exports);
|
|
1
|
+
export * from './event-emitter.js';
|
|
2
|
+
export * from './event-publisher.js';
|
|
3
|
+
export * from './event-listener-manager.js';
|
|
4
|
+
export * from './base.event-transport.js';
|
|
8
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event-handling/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event-handling/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './base.event';
|
|
2
|
-
export * from './empty.event';
|
|
3
|
-
export * from './decorators';
|
|
4
|
-
export * from './event-handling';
|
|
1
|
+
export * from './base.event.js';
|
|
2
|
+
export * from './empty.event.js';
|
|
3
|
+
export * from './decorators/index.js';
|
|
4
|
+
export * from './event-handling/index.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tslib_1.__exportStar(require("./empty.event"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./decorators"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./event-handling"), exports);
|
|
1
|
+
export * from './base.event.js';
|
|
2
|
+
export * from './empty.event.js';
|
|
3
|
+
export * from './decorators/index.js';
|
|
4
|
+
export * from './event-handling/index.js';
|
|
8
5
|
//# sourceMappingURL=index.js.map
|
package/dist/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,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-listener-manager.test.d.ts","sourceRoot":"","sources":["../../src/tests/event-listener-manager.test.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"event-listener-manager.test.d.ts","sourceRoot":"","sources":["../../src/tests/event-listener-manager.test.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,KAAK,EAEL,MAAM,cAAc,CAAC;AAWtB,qBACa,uBAAwB,SAAQ,KAAK;IACjD,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,oBAAoB,CAAuB;IAGtC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAgDnB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAIjD"}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const base_event_1 = require("../base.event");
|
|
9
|
-
const empty_event_1 = require("../empty.event");
|
|
10
|
-
let EventPublisherTestSuite = class EventPublisherTestSuite extends tests_1.Suite {
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Describe, expect, Suite, Test, } from '@hg-ts/tests';
|
|
3
|
+
import { BaseEvent } from '../base.event.js';
|
|
4
|
+
import { Listen } from '../decorators/index.js';
|
|
5
|
+
import { EmptyEvent } from '../empty.event.js';
|
|
6
|
+
import { EventListenerManager, EventPublisher, } from '../event-handling/index.js';
|
|
7
|
+
let EventPublisherTestSuite = class EventPublisherTestSuite extends Suite {
|
|
11
8
|
publisher;
|
|
12
9
|
eventListenerManager;
|
|
13
10
|
async addListener() {
|
|
14
|
-
class TestEvent extends
|
|
11
|
+
class TestEvent extends BaseEvent {
|
|
15
12
|
constructor() {
|
|
16
13
|
super({ body: {} });
|
|
17
14
|
}
|
|
@@ -21,7 +18,7 @@ let EventPublisherTestSuite = class EventPublisherTestSuite extends tests_1.Suit
|
|
|
21
18
|
class Listener {
|
|
22
19
|
called = new Map();
|
|
23
20
|
async empty(event) {
|
|
24
|
-
this.check(event,
|
|
21
|
+
this.check(event, EmptyEvent);
|
|
25
22
|
}
|
|
26
23
|
async test(event) {
|
|
27
24
|
this.check(event, TestEvent);
|
|
@@ -31,52 +28,52 @@ let EventPublisherTestSuite = class EventPublisherTestSuite extends tests_1.Suit
|
|
|
31
28
|
}
|
|
32
29
|
check(event, ctor) {
|
|
33
30
|
let count = this.called.get(ctor) ?? 0;
|
|
34
|
-
|
|
31
|
+
expect(event).toBeInstanceOf(ctor);
|
|
35
32
|
count++;
|
|
36
33
|
this.called.set(ctor, count);
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
__decorate([
|
|
37
|
+
Listen(EmptyEvent),
|
|
38
|
+
__metadata("design:type", Function),
|
|
39
|
+
__metadata("design:paramtypes", [EmptyEvent]),
|
|
40
|
+
__metadata("design:returntype", Promise)
|
|
44
41
|
], Listener.prototype, "empty", null);
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
__decorate([
|
|
43
|
+
Listen(TestEvent),
|
|
44
|
+
__metadata("design:type", Function),
|
|
45
|
+
__metadata("design:paramtypes", [TestEvent]),
|
|
46
|
+
__metadata("design:returntype", Promise)
|
|
50
47
|
], Listener.prototype, "test", null);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
__decorate([
|
|
49
|
+
Listen(ExtendedEvent),
|
|
50
|
+
__metadata("design:type", Function),
|
|
51
|
+
__metadata("design:paramtypes", [ExtendedEvent]),
|
|
52
|
+
__metadata("design:returntype", Promise)
|
|
56
53
|
], Listener.prototype, "extended", null);
|
|
57
54
|
const listener = new Listener();
|
|
58
55
|
this.eventListenerManager.addListener(listener);
|
|
59
|
-
await this.publisher.publish(new
|
|
56
|
+
await this.publisher.publish(new EmptyEvent());
|
|
60
57
|
await this.publisher.publish(new TestEvent());
|
|
61
58
|
await this.publisher.publish(new ExtendedEvent());
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
expect(listener.called.get(EmptyEvent)).toBe(1);
|
|
60
|
+
expect(listener.called.get(TestEvent)).toBe(2);
|
|
61
|
+
expect(listener.called.get(ExtendedEvent)).toBe(1);
|
|
62
|
+
expect.assertions(7);
|
|
66
63
|
}
|
|
67
64
|
async beforeEach() {
|
|
68
|
-
this.publisher = new
|
|
69
|
-
this.eventListenerManager = new
|
|
65
|
+
this.publisher = new EventPublisher();
|
|
66
|
+
this.eventListenerManager = new EventListenerManager(this.publisher);
|
|
70
67
|
}
|
|
71
68
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
69
|
+
__decorate([
|
|
70
|
+
Test(),
|
|
71
|
+
__metadata("design:type", Function),
|
|
72
|
+
__metadata("design:paramtypes", []),
|
|
73
|
+
__metadata("design:returntype", Promise)
|
|
78
74
|
], EventPublisherTestSuite.prototype, "addListener", null);
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
EventPublisherTestSuite = __decorate([
|
|
76
|
+
Describe()
|
|
81
77
|
], EventPublisherTestSuite);
|
|
78
|
+
export { EventPublisherTestSuite };
|
|
82
79
|
//# sourceMappingURL=event-listener-manager.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-listener-manager.test.js","sourceRoot":"","sources":["../../src/tests/event-listener-manager.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-listener-manager.test.js","sourceRoot":"","sources":["../../src/tests/event-listener-manager.test.ts"],"names":[],"mappings":";AACA,OAAO,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACL,IAAI,GACJ,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EACN,oBAAoB,EACpB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M,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;QAEhC,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAEhD,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC;QAC/C,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC;QAC9C,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;QAElD,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAChD,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC/C,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAEnD,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;IACe,KAAK,CAAC,UAAU;QAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC;QACtC,IAAI,CAAC,oBAAoB,GAAG,IAAI,oBAAoB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtE,CAAC;CACD,CAAA;AApDa;IADZ,IAAI,EAAE;;;;0DAgDN;AApDW,uBAAuB;IADnC,QAAQ,EAAE;GACE,uBAAuB,CAyDnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-publisher.test.d.ts","sourceRoot":"","sources":["../../src/tests/event-publisher.test.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"event-publisher.test.d.ts","sourceRoot":"","sources":["../../src/tests/event-publisher.test.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,KAAK,EAEL,MAAM,cAAc,CAAC;AAOtB,qBACa,kBAAmB,SAAQ,KAAK;IAC5C,OAAO,CAAC,SAAS,CAAiB;IAGrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAaxB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBlC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB/B,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IA2BzC,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B7B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAGjD"}
|
|
@@ -1,57 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const base_event_1 = require("../base.event");
|
|
8
|
-
const empty_event_1 = require("../empty.event");
|
|
9
|
-
let EventPublisherTest = class EventPublisherTest extends tests_1.Suite {
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Describe, expect, Suite, Test, } from '@hg-ts/tests';
|
|
3
|
+
import { BaseEvent } from '../base.event.js';
|
|
4
|
+
import { EmptyEvent } from '../empty.event.js';
|
|
5
|
+
import { EventPublisher } from '../event-handling/index.js';
|
|
6
|
+
let EventPublisherTest = class EventPublisherTest extends Suite {
|
|
10
7
|
publisher;
|
|
11
8
|
async publish() {
|
|
12
9
|
const listener = async (event) => {
|
|
13
|
-
|
|
10
|
+
expect(event).toBeInstanceOf(EmptyEvent);
|
|
14
11
|
};
|
|
15
|
-
this.publisher['addListener'](
|
|
16
|
-
await this.publisher.publish(new
|
|
17
|
-
|
|
12
|
+
this.publisher['addListener'](EmptyEvent, listener);
|
|
13
|
+
await this.publisher.publish(new EmptyEvent());
|
|
14
|
+
expect.assertions(1);
|
|
18
15
|
}
|
|
19
16
|
async multipleListeners() {
|
|
20
17
|
let callIndex = 1;
|
|
21
18
|
const listener1 = async (event) => {
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
expect(event).toBeInstanceOf(EmptyEvent);
|
|
20
|
+
expect(callIndex).toBe(1);
|
|
24
21
|
callIndex++;
|
|
25
22
|
};
|
|
26
23
|
const listener2 = async (event) => {
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
expect(event).toBeInstanceOf(EmptyEvent);
|
|
25
|
+
expect(callIndex).toBe(2);
|
|
29
26
|
callIndex++;
|
|
30
27
|
};
|
|
31
|
-
this.publisher['addListener'](
|
|
32
|
-
this.publisher['addListener'](
|
|
33
|
-
await this.publisher.publish(new
|
|
34
|
-
|
|
28
|
+
this.publisher['addListener'](EmptyEvent, listener1);
|
|
29
|
+
this.publisher['addListener'](EmptyEvent, listener2);
|
|
30
|
+
await this.publisher.publish(new EmptyEvent());
|
|
31
|
+
expect.assertions(4);
|
|
35
32
|
}
|
|
36
33
|
async multipleEvents() {
|
|
37
|
-
class TestEvent extends
|
|
34
|
+
class TestEvent extends BaseEvent {
|
|
38
35
|
constructor() {
|
|
39
36
|
super({ body: {} });
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
const listener1 = async (event) => {
|
|
43
|
-
|
|
40
|
+
expect(event).toBeInstanceOf(EmptyEvent);
|
|
44
41
|
};
|
|
45
42
|
const listener2 = async (event) => {
|
|
46
|
-
|
|
43
|
+
expect(event).toBeInstanceOf(TestEvent);
|
|
47
44
|
};
|
|
48
|
-
this.publisher['addListener'](
|
|
45
|
+
this.publisher['addListener'](EmptyEvent, listener1);
|
|
49
46
|
this.publisher['addListener'](TestEvent, listener2);
|
|
50
47
|
await this.publisher.publish(new TestEvent());
|
|
51
|
-
|
|
48
|
+
expect.assertions(1);
|
|
52
49
|
}
|
|
53
50
|
async extendingEventsInherited() {
|
|
54
|
-
class TestEvent extends
|
|
51
|
+
class TestEvent extends BaseEvent {
|
|
55
52
|
constructor() {
|
|
56
53
|
super({ body: {} });
|
|
57
54
|
}
|
|
@@ -59,22 +56,22 @@ let EventPublisherTest = class EventPublisherTest extends tests_1.Suite {
|
|
|
59
56
|
class ExtendedEvent extends TestEvent {
|
|
60
57
|
}
|
|
61
58
|
const listener1 = async (event) => {
|
|
62
|
-
|
|
59
|
+
expect(event).toBeInstanceOf(EmptyEvent);
|
|
63
60
|
};
|
|
64
61
|
const listener2 = async (event) => {
|
|
65
|
-
|
|
62
|
+
expect(event).toBeInstanceOf(TestEvent);
|
|
66
63
|
};
|
|
67
64
|
const listener3 = async (event) => {
|
|
68
|
-
|
|
65
|
+
expect(event).toBeInstanceOf(ExtendedEvent);
|
|
69
66
|
};
|
|
70
|
-
this.publisher['addListener'](
|
|
67
|
+
this.publisher['addListener'](EmptyEvent, listener1);
|
|
71
68
|
this.publisher['addListener'](TestEvent, listener2);
|
|
72
69
|
this.publisher['addListener'](ExtendedEvent, listener3);
|
|
73
70
|
await this.publisher.publish(new ExtendedEvent());
|
|
74
|
-
|
|
71
|
+
expect.assertions(2);
|
|
75
72
|
}
|
|
76
73
|
async extendingEventsParent() {
|
|
77
|
-
class TestEvent extends
|
|
74
|
+
class TestEvent extends BaseEvent {
|
|
78
75
|
constructor() {
|
|
79
76
|
super({ body: {} });
|
|
80
77
|
}
|
|
@@ -82,56 +79,56 @@ let EventPublisherTest = class EventPublisherTest extends tests_1.Suite {
|
|
|
82
79
|
class ExtendedEvent extends TestEvent {
|
|
83
80
|
}
|
|
84
81
|
const listener1 = async (event) => {
|
|
85
|
-
|
|
82
|
+
expect(event).toBeInstanceOf(EmptyEvent);
|
|
86
83
|
};
|
|
87
84
|
const listener2 = async (event) => {
|
|
88
|
-
|
|
85
|
+
expect(event).toBeInstanceOf(TestEvent);
|
|
89
86
|
};
|
|
90
87
|
const listener3 = async (event) => {
|
|
91
|
-
|
|
88
|
+
expect(event).toBeInstanceOf(ExtendedEvent);
|
|
92
89
|
};
|
|
93
|
-
this.publisher['addListener'](
|
|
90
|
+
this.publisher['addListener'](EmptyEvent, listener1);
|
|
94
91
|
this.publisher['addListener'](TestEvent, listener2);
|
|
95
92
|
this.publisher['addListener'](ExtendedEvent, listener3);
|
|
96
93
|
await this.publisher.publish(new TestEvent());
|
|
97
|
-
|
|
94
|
+
expect.assertions(1);
|
|
98
95
|
}
|
|
99
96
|
async beforeEach() {
|
|
100
|
-
this.publisher = new
|
|
97
|
+
this.publisher = new EventPublisher();
|
|
101
98
|
}
|
|
102
99
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
100
|
+
__decorate([
|
|
101
|
+
Test(),
|
|
102
|
+
__metadata("design:type", Function),
|
|
103
|
+
__metadata("design:paramtypes", []),
|
|
104
|
+
__metadata("design:returntype", Promise)
|
|
109
105
|
], EventPublisherTest.prototype, "publish", null);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
__decorate([
|
|
107
|
+
Test(),
|
|
108
|
+
__metadata("design:type", Function),
|
|
109
|
+
__metadata("design:paramtypes", []),
|
|
110
|
+
__metadata("design:returntype", Promise)
|
|
115
111
|
], EventPublisherTest.prototype, "multipleListeners", null);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
112
|
+
__decorate([
|
|
113
|
+
Test(),
|
|
114
|
+
__metadata("design:type", Function),
|
|
115
|
+
__metadata("design:paramtypes", []),
|
|
116
|
+
__metadata("design:returntype", Promise)
|
|
121
117
|
], EventPublisherTest.prototype, "multipleEvents", null);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
__decorate([
|
|
119
|
+
Test(),
|
|
120
|
+
__metadata("design:type", Function),
|
|
121
|
+
__metadata("design:paramtypes", []),
|
|
122
|
+
__metadata("design:returntype", Promise)
|
|
127
123
|
], EventPublisherTest.prototype, "extendingEventsInherited", null);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
__decorate([
|
|
125
|
+
Test(),
|
|
126
|
+
__metadata("design:type", Function),
|
|
127
|
+
__metadata("design:paramtypes", []),
|
|
128
|
+
__metadata("design:returntype", Promise)
|
|
133
129
|
], EventPublisherTest.prototype, "extendingEventsParent", null);
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
EventPublisherTest = __decorate([
|
|
131
|
+
Describe()
|
|
136
132
|
], EventPublisherTest);
|
|
133
|
+
export { EventPublisherTest };
|
|
137
134
|
//# sourceMappingURL=event-publisher.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-publisher.test.js","sourceRoot":"","sources":["../../src/tests/event-publisher.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-publisher.test.js","sourceRoot":"","sources":["../../src/tests/event-publisher.test.ts"],"names":[],"mappings":";AACA,OAAO,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACL,IAAI,GACJ,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGrD,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,KAAK;IACpC,SAAS,CAAiB;IAGrB,AAAN,KAAK,CAAC,OAAO;QACnB,MAAM,QAAQ,GAAG,KAAK,EAAC,KAAgB,EAAiB,EAAE;YACzD,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QAC1C,CAAC,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAEpD,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC;QAE/C,MAAM,CAAC,UAAU,CAAC,CA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,IAAI,EAAE;;;;2DAoBN;AAGY;IADZ,IAAI,EAAE;;;;wDAoBN;AAGY;IADZ,IAAI,EAAE;;;;kEAyBN;AAGY;IADZ,IAAI,EAAE;;;;+DAyBN;AAhHW,kBAAkB;IAD9B,QAAQ,EAAE;GACE,kBAAkB,CAqH9B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hg-ts/events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"exports": {
|
|
6
7
|
".": "./dist/index.js"
|
|
7
8
|
},
|
|
@@ -17,10 +18,10 @@
|
|
|
17
18
|
"test:dev": "HG_ENV=test vitest watch"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"@hg-ts-config/typescript": "0.
|
|
21
|
-
"@hg-ts/linter": "0.
|
|
22
|
-
"@hg-ts/tests": "0.
|
|
23
|
-
"@hg-ts/types": "0.
|
|
21
|
+
"@hg-ts-config/typescript": "0.4.0",
|
|
22
|
+
"@hg-ts/linter": "0.4.0",
|
|
23
|
+
"@hg-ts/tests": "0.4.0",
|
|
24
|
+
"@hg-ts/types": "0.4.0",
|
|
24
25
|
"@types/node": "22.19.1",
|
|
25
26
|
"@vitest/coverage-v8": "4.0.14",
|
|
26
27
|
"eslint": "9.18.0",
|
package/tsconfig.json
CHANGED