@daiso-tech/core 0.38.0 → 0.40.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/README.md +5 -1
- package/dist/async/backof-policies/constant-backoff-policy/constant-backoff-policy.d.ts +1 -1
- package/dist/async/backof-policies/exponential-backoff-policy/exponential-backoff-policy.d.ts +2 -2
- package/dist/async/backof-policies/linear-backoff-policy/linear-backoff-policy.d.ts +1 -1
- package/dist/async/backof-policies/polynomial-backoff-policy/polynomial-backoff-policy.d.ts +2 -2
- package/dist/async/middlewares/bulkhead/bulkhead.middleware.d.ts +2 -2
- package/dist/async/middlewares/hedging/sequential-hedging.middleware.js +2 -2
- package/dist/async/middlewares/hedging/sequential-hedging.middleware.js.map +1 -1
- package/dist/async/middlewares/retry/retry.middleware.js +2 -2
- package/dist/async/middlewares/retry/retry.middleware.js.map +1 -1
- package/dist/async/middlewares/retry/retry.types.d.ts +1 -1
- package/dist/cache/contracts/cache-adapter.contract.d.ts +9 -9
- package/dist/cache/contracts/cache.contract.d.ts +7 -7
- package/dist/cache/contracts/cache.errors.d.ts +3 -26
- package/dist/cache/contracts/cache.errors.js +0 -47
- package/dist/cache/contracts/cache.errors.js.map +1 -1
- package/dist/cache/contracts/database-cache-adapter.contract.d.ts +10 -10
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.d.ts +6 -5
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js +17 -13
- package/dist/cache/implementations/adapters/kysely-cache-adapter/kysely-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.d.ts +15 -3
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js +25 -9
- package/dist/cache/implementations/adapters/mongodb-cache-adapter/mongodb-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.d.ts +9 -9
- package/dist/cache/implementations/adapters/no-op-cache-adapter/no-op-cache-adapter.js.map +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.d.ts +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/redis-cache-adapter.js +1 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js +2 -1
- package/dist/cache/implementations/adapters/redis-cache-adapter/utilities.js.map +1 -1
- package/dist/cache/implementations/derivables/cache/cache.d.ts +2 -2
- package/dist/cache/implementations/derivables/cache/cache.js +1 -1
- package/dist/cache/implementations/derivables/cache/cache.js.map +1 -1
- package/dist/collection/contracts/async-collection.contract.d.ts +0 -1
- package/dist/collection/contracts/async-collection.contract.js +3 -1
- package/dist/collection/contracts/async-collection.contract.js.map +1 -1
- package/dist/collection/contracts/collection.contract.d.ts +0 -1
- package/dist/collection/contracts/collection.contract.js +3 -1
- package/dist/collection/contracts/collection.contract.js.map +1 -1
- package/dist/collection/contracts/collection.errors.d.ts +1 -26
- package/dist/collection/contracts/collection.errors.js +0 -55
- package/dist/collection/contracts/collection.errors.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.js +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-split-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-zip-iterable.js +1 -1
- package/dist/collection/implementations/async-iterable-collection/_shared/async-zip-iterable.js.map +1 -1
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js +9 -6
- package/dist/collection/implementations/async-iterable-collection/async-iterable-collection.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/split-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/split-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/zip-iterable.js +1 -1
- package/dist/collection/implementations/iterable-collection/_shared/zip-iterable.js.map +1 -1
- package/dist/collection/implementations/iterable-collection/iterable-collection.js +9 -6
- package/dist/collection/implementations/iterable-collection/iterable-collection.js.map +1 -1
- package/dist/collection/implementations/list-collection/list-collection.js +12 -9
- package/dist/collection/implementations/list-collection/list-collection.js.map +1 -1
- package/dist/event-bus/contracts/_module-exports.d.ts +0 -1
- package/dist/event-bus/contracts/_module-exports.js +0 -1
- package/dist/event-bus/contracts/_module-exports.js.map +1 -1
- package/dist/event-bus/contracts/event-bus-adapter.contract.d.ts +3 -3
- package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts +3 -3
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.d.ts +2 -2
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js +3 -2
- package/dist/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.d.ts +2 -1
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js +26 -26
- package/dist/event-bus/implementations/derivables/event-bus/event-bus.js.map +1 -1
- package/dist/event-bus/implementations/derivables/event-bus/listener-store.d.ts +11 -4
- package/dist/event-bus/implementations/derivables/event-bus/listener-store.js +17 -12
- package/dist/event-bus/implementations/derivables/event-bus/listener-store.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js +17 -20
- package/dist/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.js.map +1 -1
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js +159 -752
- package/dist/event-bus/implementations/test-utilities/event-bus.test-suite.js.map +1 -1
- package/dist/lock/contracts/database-lock-adapter.contract.d.ts +56 -16
- package/dist/lock/contracts/lock-adapter.contract.d.ts +32 -9
- package/dist/lock/contracts/lock-adapter.contract.js +10 -1
- package/dist/lock/contracts/lock-adapter.contract.js.map +1 -1
- package/dist/lock/contracts/lock.contract.d.ts +30 -25
- package/dist/lock/contracts/lock.errors.d.ts +11 -28
- package/dist/lock/contracts/lock.errors.js +10 -74
- package/dist/lock/contracts/lock.errors.js.map +1 -1
- package/dist/lock/contracts/lock.events.d.ts +15 -3
- package/dist/lock/contracts/lock.events.js +2 -1
- package/dist/lock/contracts/lock.events.js.map +1 -1
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.d.ts +40 -10
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js +135 -37
- package/dist/lock/implementations/adapters/kysely-lock-adapter/kysely-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.d.ts +20 -7
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js +59 -35
- package/dist/lock/implementations/adapters/memory-lock-adapter/memory-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.d.ts +23 -12
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js +152 -87
- package/dist/lock/implementations/adapters/mongodb-lock-adapter/mongodb-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.d.ts +5 -5
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js +3 -2
- package/dist/lock/implementations/adapters/no-op-lock-adapter/no-op-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.d.ts +6 -6
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js +46 -24
- package/dist/lock/implementations/adapters/redis-lock-adapter/redis-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.d.ts +4 -4
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js +45 -12
- package/dist/lock/implementations/derivables/lock-provider/database-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js +7 -5
- package/dist/lock/implementations/derivables/lock-provider/is-database-lock-adapter.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.d.ts +3 -3
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js +2 -3
- package/dist/lock/implementations/derivables/lock-provider/lock-provider.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.d.ts +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js +4 -3
- package/dist/lock/implementations/derivables/lock-provider/lock-serde-transformer.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock-state.d.ts +8 -11
- package/dist/lock/implementations/derivables/lock-provider/lock-state.js +9 -26
- package/dist/lock/implementations/derivables/lock-provider/lock-state.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider/lock.d.ts +14 -16
- package/dist/lock/implementations/derivables/lock-provider/lock.js +106 -63
- package/dist/lock/implementations/derivables/lock-provider/lock.js.map +1 -1
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.d.ts +2 -2
- package/dist/lock/implementations/derivables/lock-provider-factory/lock-provider-factory.js.map +1 -1
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js +184 -166
- package/dist/lock/implementations/test-utilities/database-lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js +240 -41
- package/dist/lock/implementations/test-utilities/lock-adapter.test-suite.js.map +1 -1
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js +2704 -1514
- package/dist/lock/implementations/test-utilities/lock-provider.test-suite.js.map +1 -1
- package/dist/serde/implementations/derivables/serde.d.ts +22 -22
- package/dist/utilities/classes/kysely-table-name-transformer-plugin/kysely-table-name-transformer-plugin.js +2 -1
- package/dist/utilities/classes/kysely-table-name-transformer-plugin/kysely-table-name-transformer-plugin.js.map +1 -1
- package/dist/utilities/classes/namespace/namespace.d.ts +3 -3
- package/dist/utilities/classes/namespace/namespace.js +2 -2
- package/dist/utilities/classes/namespace/namespace.js.map +1 -1
- package/dist/utilities/classes/time-span/time-span.d.ts +10 -2
- package/dist/utilities/classes/time-span/time-span.js +10 -2
- package/dist/utilities/classes/time-span/time-span.js.map +1 -1
- package/dist/utilities/contracts/deinitizable.contract.d.ts +1 -1
- package/dist/utilities/contracts/initizable.contract.d.ts +1 -1
- package/dist/utilities/contracts/prunable.contract.d.ts +1 -1
- package/dist/utilities/errors.d.ts +8 -0
- package/dist/utilities/errors.js +11 -0
- package/dist/utilities/errors.js.map +1 -1
- package/dist/utilities/functions/_module.d.ts +1 -0
- package/dist/utilities/functions/_module.js +1 -0
- package/dist/utilities/functions/_module.js.map +1 -1
- package/dist/utilities/functions/is-class.d.ts +4 -0
- package/dist/utilities/functions/is-class.js +4 -0
- package/dist/utilities/functions/is-class.js.map +1 -1
- package/dist/utilities/functions/is-positive-nbr.d.ts +8 -0
- package/dist/utilities/functions/is-positive-nbr.js +19 -0
- package/dist/utilities/functions/is-positive-nbr.js.map +1 -0
- package/package.json +1 -1
- package/dist/event-bus/contracts/event-bus.errors.d.ts +0 -40
- package/dist/event-bus/contracts/event-bus.errors.js +0 -62
- package/dist/event-bus/contracts/event-bus.errors.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_module-exports.js","sourceRoot":"","sources":["../../../src/event-bus/contracts/_module-exports.ts"],"names":[],"mappings":"AAAA,cAAc,qDAAqD,CAAC;AACpE,cAAc,qDAAqD,CAAC;AACpE,cAAc,6CAA6C,CAAC
|
|
1
|
+
{"version":3,"file":"_module-exports.js","sourceRoot":"","sources":["../../../src/event-bus/contracts/_module-exports.ts"],"names":[],"mappings":"AAAA,cAAc,qDAAqD,CAAC;AACpE,cAAc,qDAAqD,CAAC;AACpE,cAAc,6CAA6C,CAAC"}
|
|
@@ -25,13 +25,13 @@ export type IEventBusAdapter = {
|
|
|
25
25
|
/**
|
|
26
26
|
* The `addListener` method is used for adding {@link EventListenerFn | `listener`} for certain `eventName`.
|
|
27
27
|
*/
|
|
28
|
-
addListener(eventName: string, listener: EventListenerFn<BaseEvent>):
|
|
28
|
+
addListener(eventName: string, listener: EventListenerFn<BaseEvent>): Promise<void>;
|
|
29
29
|
/**
|
|
30
30
|
* The `removeListener` method is used for removing {@link EventListenerFn | `listener`} for certain `eventName`.
|
|
31
31
|
*/
|
|
32
|
-
removeListener(eventName: string, listener: EventListenerFn<BaseEvent>):
|
|
32
|
+
removeListener(eventName: string, listener: EventListenerFn<BaseEvent>): Promise<void>;
|
|
33
33
|
/**
|
|
34
34
|
* The `dispatch` method is used for dispatching one or multiple `events`.
|
|
35
35
|
*/
|
|
36
|
-
dispatch(eventName: string, eventData: BaseEvent):
|
|
36
|
+
dispatch(eventName: string, eventData: BaseEvent): Promise<void>;
|
|
37
37
|
};
|
package/dist/event-bus/implementations/adapters/no-op-event-bus-adapter/no-op-event-bus-adapter.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { IEventBusAdapter } from "../../../../event-bus/contracts/_module-e
|
|
|
10
10
|
* @group Adapters
|
|
11
11
|
*/
|
|
12
12
|
export declare class NoOpEventBusAdapter implements IEventBusAdapter {
|
|
13
|
-
addListener(_eventName: string, _listener: EventListenerFn<BaseEvent>):
|
|
14
|
-
removeListener(_eventName: string, _listener: EventListenerFn<BaseEvent>):
|
|
15
|
-
dispatch(_eventName: string, _eventData: BaseEvent):
|
|
13
|
+
addListener(_eventName: string, _listener: EventListenerFn<BaseEvent>): Promise<void>;
|
|
14
|
+
removeListener(_eventName: string, _listener: EventListenerFn<BaseEvent>): Promise<void>;
|
|
15
|
+
dispatch(_eventName: string, _eventData: BaseEvent): Promise<void>;
|
|
16
16
|
}
|
|
@@ -15,7 +15,7 @@ export type RedisPubSubEventBusAdapterSettings = {
|
|
|
15
15
|
serde: ISerde<string>;
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
|
-
* To utilize the `RedisPubSubEventBusAdapter`, you must install the `"ioredis"` package and supply a {@link ISerde | `ISerde<string>`}, with a {@link SuperJsonSerdeAdapter | `SuperJsonSerdeAdapter `}.
|
|
18
|
+
* To utilize the `RedisPubSubEventBusAdapter`, you must install the [`"ioredis"`](https://www.npmjs.com/package/ioredis) package and supply a {@link ISerde | `ISerde<string>`}, with a {@link SuperJsonSerdeAdapter | `SuperJsonSerdeAdapter `}.
|
|
19
19
|
*
|
|
20
20
|
* IMPORT_PATH: `"@daiso-tech/core/event-bus/adapters"`
|
|
21
21
|
* @group Adapters
|
|
@@ -43,7 +43,7 @@ export declare class RedisPubSubEventBusAdapter implements IEventBusAdapter {
|
|
|
43
43
|
* });
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
constructor(
|
|
46
|
+
constructor(settings: RedisPubSubEventBusAdapterSettings);
|
|
47
47
|
private redisListener;
|
|
48
48
|
addListener(eventName: string, listener: EventListenerFn<BaseEvent>): Promise<void>;
|
|
49
49
|
removeListener(eventName: string, listener: EventListenerFn<BaseEvent>): Promise<void>;
|
|
@@ -7,7 +7,7 @@ import { RedisSerde,
|
|
|
7
7
|
SuperJsonSerdeAdapter, } from "../../../../serde/implementations/adapters/_module-exports.js";
|
|
8
8
|
import { EventEmitter } from "node:events";
|
|
9
9
|
/**
|
|
10
|
-
* To utilize the `RedisPubSubEventBusAdapter`, you must install the `"ioredis"` package and supply a {@link ISerde | `ISerde<string>`}, with a {@link SuperJsonSerdeAdapter | `SuperJsonSerdeAdapter `}.
|
|
10
|
+
* To utilize the `RedisPubSubEventBusAdapter`, you must install the [`"ioredis"`](https://www.npmjs.com/package/ioredis) package and supply a {@link ISerde | `ISerde<string>`}, with a {@link SuperJsonSerdeAdapter | `SuperJsonSerdeAdapter `}.
|
|
11
11
|
*
|
|
12
12
|
* IMPORT_PATH: `"@daiso-tech/core/event-bus/adapters"`
|
|
13
13
|
* @group Adapters
|
|
@@ -35,7 +35,8 @@ export class RedisPubSubEventBusAdapter {
|
|
|
35
35
|
* });
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
constructor(
|
|
38
|
+
constructor(settings) {
|
|
39
|
+
const { dispatcherClient, listenerClient, serde } = settings;
|
|
39
40
|
this.dispatcherClient = dispatcherClient;
|
|
40
41
|
this.listenerClient = listenerClient;
|
|
41
42
|
this.serde = new RedisSerde(serde);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-pub-sub-event-bus-adapter.js","sourceRoot":"","sources":["../../../../../src/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAe,MAAM,sCAAsC,CAAC;AACnE,OAAO,EACH,UAAU;AACV,6DAA6D;AAC7D,qBAAqB,GACxB,MAAM,qDAAqD,CAAC;AAO7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAa3C;;;;;GAKG;AACH,MAAM,OAAO,0BAA0B;IAClB,KAAK,CAAiB;IACtB,gBAAgB,CAAQ;IACxB,cAAc,CAAQ;IACtB,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;IAEnD;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,
|
|
1
|
+
{"version":3,"file":"redis-pub-sub-event-bus-adapter.js","sourceRoot":"","sources":["../../../../../src/event-bus/implementations/adapters/redis-pub-sub-event-bus-adapter/redis-pub-sub-event-bus-adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAe,MAAM,sCAAsC,CAAC;AACnE,OAAO,EACH,UAAU;AACV,6DAA6D;AAC7D,qBAAqB,GACxB,MAAM,qDAAqD,CAAC;AAO7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAa3C;;;;;GAKG;AACH,MAAM,OAAO,0BAA0B;IAClB,KAAK,CAAiB;IACtB,gBAAgB,CAAQ;IACxB,cAAc,CAAQ;IACtB,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;IAEnD;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,QAA4C;QACpD,MAAM,EAAE,gBAAg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EventMapSchema<TEventMap>;
|
|
28
28
|
/**
|
|
29
29
|
* You can enable validating events in listeners.
|
|
30
|
-
* @default
|
|
30
|
+
* @default true
|
|
31
31
|
*/
|
|
32
32
|
shouldValidateOutput?: boolean;
|
|
33
33
|
/**
|
|
@@ -94,6 +94,7 @@ export declare class EventBus<TEventMap extends BaseEventMap = BaseEventMap> imp
|
|
|
94
94
|
*/
|
|
95
95
|
constructor(settings: EventBusSettings<TEventMap>);
|
|
96
96
|
private createLazyPromise;
|
|
97
|
+
private createWrappedListener;
|
|
97
98
|
addListener<TEventName extends keyof TEventMap>(eventName: TEventName, listener: EventListener<TEventMap[TEventName]>): LazyPromise<void>;
|
|
98
99
|
removeListener<TEventName extends keyof TEventMap>(eventName: TEventName, listener: EventListener<TEventMap[TEventName]>): LazyPromise<void>;
|
|
99
100
|
listenOnce<TEventName extends keyof TEventMap>(eventName: TEventName, listener: EventListener<TEventMap[TEventName]>): LazyPromise<void>;
|
|
@@ -47,32 +47,35 @@ export class EventBus {
|
|
|
47
47
|
createLazyPromise(asyncFn) {
|
|
48
48
|
return this.lazyPromiseFactory(asyncFn);
|
|
49
49
|
}
|
|
50
|
+
createWrappedListener(eventName, listener) {
|
|
51
|
+
return async (event) => {
|
|
52
|
+
try {
|
|
53
|
+
if (this.shouldValidateOutput) {
|
|
54
|
+
await validate(this.eventMapSchema?.[eventName], event);
|
|
55
|
+
}
|
|
56
|
+
await resolveInvokable(listener)(event);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (this.__onUncaughtRejection !== undefined) {
|
|
60
|
+
this.__onUncaughtRejection(error);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error(`An error of type "${String(error)}" occured in listener with name of "${getInvokableName(listener)}" for "${String(eventName)}" event`);
|
|
64
|
+
console.log("ERROR:", error);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
50
70
|
addListener(eventName, listener) {
|
|
51
71
|
return this.createLazyPromise(async () => {
|
|
52
72
|
const key = this.namespace._getInternal().create(String(eventName));
|
|
53
|
-
const resolvedListener = this.store.getOrAdd(
|
|
54
|
-
try {
|
|
55
|
-
if (this.shouldValidateOutput) {
|
|
56
|
-
await validate(this.eventMapSchema?.[eventName], event);
|
|
57
|
-
}
|
|
58
|
-
await resolveInvokable(listener)(event);
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
if (this.__onUncaughtRejection !== undefined) {
|
|
62
|
-
this.__onUncaughtRejection(error);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
console.error(`An error of type "${String(error)}" occured in listener with name of "${getInvokableName(listener)}" for "${String(eventName)}" event`);
|
|
66
|
-
console.log("ERROR:", error);
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
73
|
+
const resolvedListener = this.store.getOrAdd(key.namespaced, listener, this.createWrappedListener(eventName, listener));
|
|
71
74
|
try {
|
|
72
75
|
await this.adapter.addListener(key.namespaced, resolvedListener);
|
|
73
76
|
}
|
|
74
77
|
catch (error) {
|
|
75
|
-
this.store.getAndRemove(
|
|
78
|
+
this.store.getAndRemove(key.namespaced, listener);
|
|
76
79
|
throw error;
|
|
77
80
|
}
|
|
78
81
|
});
|
|
@@ -80,10 +83,7 @@ export class EventBus {
|
|
|
80
83
|
removeListener(eventName, listener) {
|
|
81
84
|
return this.createLazyPromise(async () => {
|
|
82
85
|
const key = this.namespace._getInternal().create(String(eventName));
|
|
83
|
-
const resolvedListener = this.store.getAndRemove(
|
|
84
|
-
key.namespaced,
|
|
85
|
-
listener,
|
|
86
|
-
]);
|
|
86
|
+
const resolvedListener = this.store.getAndRemove(key.namespaced, listener);
|
|
87
87
|
if (resolvedListener === null) {
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
@@ -91,7 +91,7 @@ export class EventBus {
|
|
|
91
91
|
await this.adapter.removeListener(key.namespaced, resolvedListener);
|
|
92
92
|
}
|
|
93
93
|
catch (error) {
|
|
94
|
-
this.store.getOrAdd(
|
|
94
|
+
this.store.getOrAdd(key.namespaced, listener, resolvedListener);
|
|
95
95
|
throw error;
|
|
96
96
|
}
|
|
97
97
|
});
|
|
@@ -121,12 +121,12 @@ export class EventBus {
|
|
|
121
121
|
}
|
|
122
122
|
};
|
|
123
123
|
const key = this.namespace._getInternal().create(String(eventName));
|
|
124
|
-
const resolvedListener = this.store.getOrAdd(
|
|
124
|
+
const resolvedListener = this.store.getOrAdd(key.namespaced, listener, wrappedListener);
|
|
125
125
|
try {
|
|
126
126
|
await this.adapter.addListener(key.namespaced, resolvedListener);
|
|
127
127
|
}
|
|
128
128
|
catch (error) {
|
|
129
|
-
this.store.getAndRemove(
|
|
129
|
+
this.store.getAndRemove(key.namespaced, listener);
|
|
130
130
|
throw error;
|
|
131
131
|
}
|
|
132
132
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../../../../src/event-bus/implementations/derivables/event-bus/event-bus.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAQzD,OAAO,EAGN,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACH,gBAAgB,EAChB,SAAS,EACT,QAAQ,GACX,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAIN,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,oEAAoE,CAAC;AAqEnG;;;;;GAKG;AACH,MAAM,OAAO,QAAQ;IAGA,oBAAoB,CAAU;IAC9B,KAAK,GAAG,IAAI,aAAa,EAAE,CAAC;IAC5B,OAAO,CAAmB;IAC1B,kBAAkB,CAGjC;IACe,SAAS,CAAY;IACrB,cAAc,CAAwC;IAEvE;;OAEG;IACc,qBAAqB,CAA4B;IAElE;;;;;;;;;;OAUG;IACH,YAAY,QAAqC;QAC7C,MAAM,EACF,qBAAqB,EACrB,oBAAoB,GAAG,IAAI,EAC3B,cAAc,EACd,SAAS,GAAG,IAAI,SAAS,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,EAC7C,OAAO,EACP,kBAAkB,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,WAAW,CAAC,SAAS,CAAC,GACjE,GAAG,QAAQ,CAAC;QACb,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QACjD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,kBAAkB,GAAG,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;IACvD,CAAC;IAEO,iBAAiB,CACrB,
|
|
1
|
+
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../../../../../src/event-bus/implementations/derivables/event-bus/event-bus.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAQzD,OAAO,EAGN,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACH,gBAAgB,EAChB,SAAS,EACT,QAAQ,GACX,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAIN,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,oEAAoE,CAAC;AAqEnG;;;;;GAKG;AACH,MAAM,OAAO,QAAQ;IAGA,oBAAoB,CAAU;IAC9B,KAAK,GAAG,IAAI,aAAa,EAAE,CAAC;IAC5B,OAAO,CAAmB;IAC1B,kBAAkB,CAGjC;IACe,SAAS,CAAY;IACrB,cAAc,CAAwC;IAEvE;;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AM,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBACnD,CAAC,CAAC,CAAC;YACP,CAAC,CAAC;YACF,OAAO,WAAW,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CACL,SAAqB,EACrB,QAA8C;QAE9C,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,IAAI,EAAE;YACrC,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAC5C,MAAM,WAAW,GAAG,GAAG,EAAE;gBACrB,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,IAAI,EAAE;oBACrC,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBACnD,CAAC,CAAC,CAAC;YACP,CAAC,CAAC;YACF,OAAO,WAAW,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,QAAQ,CACJ,SAAqB,EACrB,KAA4B;QAE5B,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,IAAI,EAAE;YACrC,MAAM,QAAQ,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;YACxD,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CACvB,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;iBAClD,UAAU,EACf,KAAK,CACR,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -6,8 +6,15 @@ import type { EventListener, EventListenerFn } from "../../../../event-bus/contr
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
export declare class ListenerStore {
|
|
9
|
-
private readonly
|
|
10
|
-
constructor(
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
private readonly listenerMap;
|
|
10
|
+
constructor(listenerMap?: Map<string, Map<EventListener<any>, EventListenerFn<any>>>);
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the listener if it exists. If the listener doesnt exists it will be added then retrieved.
|
|
13
|
+
*/
|
|
14
|
+
getOrAdd<TInput>(eventName: string, listener: EventListener<TInput>, listenerWrapper: EventListenerFn<TInput>): EventListenerFn<TInput>;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the listener if it exists otherwise null is returned.
|
|
17
|
+
* If the listener exists it will be removed.
|
|
18
|
+
*/
|
|
19
|
+
getAndRemove<TInput>(eventName: string, listener: EventListener<TInput>): EventListenerFn<TInput> | null;
|
|
13
20
|
}
|
|
@@ -6,27 +6,32 @@ import { resolveInvokable } from "../../../../utilities/_module-exports.js";
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
export class ListenerStore {
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
this.
|
|
9
|
+
listenerMap;
|
|
10
|
+
constructor(listenerMap = new Map()) {
|
|
11
|
+
this.listenerMap = listenerMap;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the listener if it exists. If the listener doesnt exists it will be added then retrieved.
|
|
15
|
+
*/
|
|
16
|
+
getOrAdd(eventName, listener, listenerWrapper) {
|
|
17
|
+
let eventMap = this.listenerMap.get(eventName);
|
|
16
18
|
if (eventMap === undefined) {
|
|
17
19
|
eventMap = new Map();
|
|
18
|
-
this.
|
|
20
|
+
this.listenerMap.set(eventName, eventMap);
|
|
19
21
|
}
|
|
20
22
|
let listenerFn_ = eventMap.get(listener);
|
|
21
23
|
if (listenerFn_ === undefined) {
|
|
22
|
-
listenerFn_ = resolveInvokable(
|
|
24
|
+
listenerFn_ = resolveInvokable(listenerWrapper);
|
|
23
25
|
eventMap.set(listener, listenerFn_);
|
|
24
26
|
}
|
|
25
27
|
return listenerFn_;
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the listener if it exists otherwise null is returned.
|
|
31
|
+
* If the listener exists it will be removed.
|
|
32
|
+
*/
|
|
33
|
+
getAndRemove(eventName, listener) {
|
|
34
|
+
const eventMap = this.listenerMap.get(eventName);
|
|
30
35
|
if (eventMap === undefined) {
|
|
31
36
|
return null;
|
|
32
37
|
}
|
|
@@ -36,7 +41,7 @@ export class ListenerStore {
|
|
|
36
41
|
}
|
|
37
42
|
eventMap.delete(listener);
|
|
38
43
|
if (eventMap.size === 0) {
|
|
39
|
-
this.
|
|
44
|
+
this.listenerMap.delete(eventName);
|
|
40
45
|
}
|
|
41
46
|
return listenerFn;
|
|
42
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener-store.js","sourceRoot":"","sources":["../../../../../src/event-bus/implementations/derivables/event-bus/listener-store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE;;GAEG;AACH,MAAM,OAAO,aAAa;IAED;IADrB,YACqB,
|
|
1
|
+
{"version":3,"file":"listener-store.js","sourceRoot":"","sources":["../../../../../src/event-bus/implementations/derivables/event-bus/listener-store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE;;GAEG;AACH,MAAM,OAAO,aAAa;IAED;IADrB,YACqB,cAAc,IAAI,GAAG,EAGnC;QAHc,gBAAW,GAAX,WAAW,CAGzB;IACJ,CAAC;IAEJ;;OAEG;IACH,QAAQ,CACJ,SAAiB,EACjB,QAA+B,EAC/B,eAAwC;QAExC,IAAI,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC/C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACzB,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;YACrB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC5B,WAAW,GAAG,gBAAgB,CAAC,eAAe,CAAC,CAAC;YAChD,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,WAAW,CAAC;IACvB,CAAC;IAED;;;OAGG;IACH,YAAY,CACR,SAAiB,EACjB,QAA+B;QAE/B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC1B,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC;QAED,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module EventBus
|
|
3
3
|
*/
|
|
4
|
-
import { describe, } from "vitest";
|
|
4
|
+
import { describe, vi, } from "vitest";
|
|
5
5
|
import {} from "../../../utilities/_module-exports.js";
|
|
6
6
|
import { TimeSpan } from "../../../utilities/_module-exports.js";
|
|
7
7
|
import { LazyPromise } from "../../../async/_module-exports.js";
|
|
@@ -17,40 +17,37 @@ export function eventBusAdapterTestSuite(settings) {
|
|
|
17
17
|
beforeEach(async () => {
|
|
18
18
|
adapter = await createAdapter();
|
|
19
19
|
});
|
|
20
|
+
async function delay(time) {
|
|
21
|
+
await LazyPromise.delay(time);
|
|
22
|
+
}
|
|
20
23
|
const TTL = TimeSpan.fromMilliseconds(50);
|
|
21
24
|
describe("method: addListener, removeListener, dispatch", () => {
|
|
22
25
|
test("Should be null when listener added and event is not triggered", async () => {
|
|
23
|
-
|
|
24
|
-
await adapter.addListener("event",
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
expect(result).toBeNull();
|
|
26
|
+
const handlerFn = vi.fn((_event) => { });
|
|
27
|
+
await adapter.addListener("event", handlerFn);
|
|
28
|
+
expect(handlerFn).not.toHaveBeenCalled();
|
|
28
29
|
});
|
|
29
30
|
test("Should be TestEvent when listener added and event is triggered", async () => {
|
|
30
|
-
|
|
31
|
-
await adapter.addListener("event",
|
|
32
|
-
result = event;
|
|
33
|
-
});
|
|
31
|
+
const handlerFn = vi.fn((_event) => { });
|
|
32
|
+
await adapter.addListener("event", handlerFn);
|
|
34
33
|
const event = {
|
|
35
34
|
type: "event",
|
|
36
35
|
};
|
|
37
36
|
await adapter.dispatch("event", event);
|
|
38
|
-
await
|
|
39
|
-
expect(
|
|
37
|
+
await delay(TTL);
|
|
38
|
+
expect(handlerFn).toHaveBeenCalledTimes(1);
|
|
39
|
+
expect(handlerFn).toHaveBeenCalledWith(event);
|
|
40
40
|
});
|
|
41
41
|
test("Should be null when listener removed and event is triggered", async () => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
await adapter.addListener("event", listener);
|
|
47
|
-
await adapter.removeListener("event", listener);
|
|
42
|
+
const handlerFn = vi.fn((_event) => { });
|
|
43
|
+
await adapter.addListener("event", handlerFn);
|
|
44
|
+
await adapter.removeListener("event", handlerFn);
|
|
48
45
|
const event = {
|
|
49
46
|
type: "event",
|
|
50
47
|
};
|
|
51
48
|
await adapter.dispatch("event", event);
|
|
52
|
-
await
|
|
53
|
-
expect(
|
|
49
|
+
await delay(TTL);
|
|
50
|
+
expect(handlerFn).not.toHaveBeenCalled();
|
|
54
51
|
});
|
|
55
52
|
});
|
|
56
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus-adapter.test-suite.js","sourceRoot":"","sources":["../../../../src/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAKH,QAAQ,
|
|
1
|
+
{"version":3,"file":"event-bus-adapter.test-suite.js","sourceRoot":"","sources":["../../../../src/event-bus/implementations/test-utilities/event-bus-adapter.test-suite.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAKH,QAAQ,EACR,EAAE,GACL,MAAM,QAAQ,CAAC;AAKhB,OAAO,EAAmB,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAezD;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACpC,QAA0C;IAE1C,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,QAAQ,CAAC;IAE7D,IAAI,OAAyB,CAAC;IAC9B,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,GAAG,MAAM,aAAa,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,KAAK,UAAU,KAAK,CAAC,IAAc;QAC/B,MAAM,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,MAAM,GAAG,GAAG,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC1C,QAAQ,CAAC,+CAA+C,EAAE,GAAG,EAAE;QAC3D,IAAI,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;YAC7E,MAAM,SAAS,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,MAAiB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