node-cqrs 0.16.4 → 0.17.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/CHANGELOG.md +45 -0
- package/README.md +2 -1
- package/dist/AbstractAggregate.js +178 -0
- package/dist/AbstractAggregate.js.map +1 -0
- package/dist/AbstractProjection.js +121 -0
- package/dist/AbstractProjection.js.map +1 -0
- package/dist/AbstractSaga.js +99 -0
- package/dist/AbstractSaga.js.map +1 -0
- package/dist/AggregateCommandHandler.js +85 -0
- package/dist/AggregateCommandHandler.js.map +1 -0
- package/dist/CommandBus.js +77 -0
- package/dist/CommandBus.js.map +1 -0
- package/dist/CqrsContainerBuilder.js +77 -0
- package/dist/CqrsContainerBuilder.js.map +1 -0
- package/dist/Event.js +43 -0
- package/dist/Event.js.map +1 -0
- package/dist/EventStore.js +229 -0
- package/dist/EventStore.js.map +1 -0
- package/dist/SagaEventHandler.js +117 -0
- package/dist/SagaEventHandler.js.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/InMemoryEventStorage.js +53 -0
- package/dist/infrastructure/InMemoryEventStorage.js.map +1 -0
- package/dist/infrastructure/InMemoryLock.js +68 -0
- package/dist/infrastructure/InMemoryLock.js.map +1 -0
- package/dist/infrastructure/InMemoryMessageBus.js +95 -0
- package/dist/infrastructure/InMemoryMessageBus.js.map +1 -0
- package/dist/infrastructure/InMemorySnapshotStorage.js +26 -0
- package/dist/infrastructure/InMemorySnapshotStorage.js.map +1 -0
- package/dist/infrastructure/InMemoryView.js +173 -0
- package/dist/infrastructure/InMemoryView.js.map +1 -0
- package/dist/infrastructure/utils/Deferred.js +38 -0
- package/dist/infrastructure/utils/Deferred.js.map +1 -0
- package/dist/infrastructure/utils/index.js +19 -0
- package/dist/infrastructure/utils/index.js.map +1 -0
- package/dist/infrastructure/utils/nextCycle.js +9 -0
- package/dist/infrastructure/utils/nextCycle.js.map +1 -0
- package/dist/interfaces.js +4 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/utils/getClassName.js +10 -0
- package/dist/utils/getClassName.js.map +1 -0
- package/dist/utils/getHandledMessageTypes.js +18 -0
- package/dist/utils/getHandledMessageTypes.js.map +1 -0
- package/dist/utils/getHandler.js +20 -0
- package/dist/utils/getHandler.js.map +1 -0
- package/dist/utils/getMessageHandlerNames.js +38 -0
- package/dist/utils/getMessageHandlerNames.js.map +1 -0
- package/dist/utils/index.js +25 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/isClass.js +8 -0
- package/dist/utils/isClass.js.map +1 -0
- package/dist/utils/setupOneTimeEmitterSubscription.js +46 -0
- package/dist/utils/setupOneTimeEmitterSubscription.js.map +1 -0
- package/dist/utils/subscribe.js +39 -0
- package/dist/utils/subscribe.js.map +1 -0
- package/dist/utils/validateHandlers.js +21 -0
- package/dist/utils/validateHandlers.js.map +1 -0
- package/package.json +23 -12
- package/src/AbstractAggregate.ts +223 -0
- package/src/AbstractProjection.ts +172 -0
- package/src/AbstractSaga.ts +118 -0
- package/src/AggregateCommandHandler.ts +129 -0
- package/src/CommandBus.ts +98 -0
- package/src/CqrsContainerBuilder.ts +120 -0
- package/src/Event.ts +43 -0
- package/src/EventStore.ts +315 -0
- package/src/SagaEventHandler.ts +161 -0
- package/src/index.ts +26 -0
- package/src/infrastructure/InMemoryEventStorage.ts +68 -0
- package/src/infrastructure/InMemoryLock.ts +73 -0
- package/src/infrastructure/InMemoryMessageBus.ts +118 -0
- package/src/infrastructure/InMemorySnapshotStorage.ts +27 -0
- package/src/infrastructure/InMemoryView.ts +221 -0
- package/src/infrastructure/utils/Deferred.ts +41 -0
- package/src/infrastructure/utils/index.ts +2 -0
- package/src/infrastructure/utils/nextCycle.ts +4 -0
- package/src/interfaces.ts +328 -0
- package/src/utils/getClassName.ts +6 -0
- package/src/utils/{getHandledMessageTypes.js → getHandledMessageTypes.ts} +4 -8
- package/src/utils/{getHandler.js → getHandler.ts} +6 -7
- package/src/utils/{getMessageHandlerNames.js → getMessageHandlerNames.ts} +2 -9
- package/src/utils/index.ts +8 -0
- package/src/utils/{isClass.js → isClass.ts} +2 -4
- package/src/utils/setupOneTimeEmitterSubscription.ts +57 -0
- package/src/{subscribe.js → utils/subscribe.ts} +21 -18
- package/src/utils/{validateHandlers.js → validateHandlers.ts} +2 -8
- package/jsconfig.json +0 -15
- package/src/AbstractAggregate.js +0 -277
- package/src/AbstractProjection.js +0 -192
- package/src/AbstractSaga.js +0 -171
- package/src/AggregateCommandHandler.js +0 -126
- package/src/CommandBus.js +0 -91
- package/src/CqrsContainerBuilder.js +0 -131
- package/src/EventStore.js +0 -457
- package/src/EventStream.js +0 -63
- package/src/SagaEventHandler.js +0 -141
- package/src/index.js +0 -21
- package/src/infrastructure/InMemoryEventStorage.js +0 -76
- package/src/infrastructure/InMemoryMessageBus.js +0 -132
- package/src/infrastructure/InMemorySnapshotStorage.js +0 -40
- package/src/infrastructure/InMemoryView.js +0 -265
- package/src/utils/getClassName.js +0 -11
- package/src/utils/index.js +0 -6
- package/src/utils/nullLogger.js +0 -8
- package/types/index.d.ts +0 -16
- package/types/interfaces/IAggregate.d.ts +0 -30
- package/types/interfaces/IAggregateSnapshotStorage.d.ts +0 -4
- package/types/interfaces/ICommandBus.d.ts +0 -6
- package/types/interfaces/ICommandHandler.d.ts +0 -3
- package/types/interfaces/IConcurrentView.d.ts +0 -22
- package/types/interfaces/IEventReceptor.d.ts +0 -3
- package/types/interfaces/IEventStorage.d.ts +0 -20
- package/types/interfaces/IEventStore.d.ts +0 -18
- package/types/interfaces/IEventStream.d.ts +0 -13
- package/types/interfaces/ILogger.d.ts +0 -3
- package/types/interfaces/IMessageBus.d.ts +0 -5
- package/types/interfaces/IObserver.d.ts +0 -11
- package/types/interfaces/IProjection.d.ts +0 -10
- package/types/interfaces/ISaga.d.ts +0 -27
- package/types/interfaces/Identifier.d.ts +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryLock = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class InMemoryLock {
|
|
6
|
+
#lockMarker;
|
|
7
|
+
#innerLock;
|
|
8
|
+
/**
|
|
9
|
+
* Indicates if lock is acquired
|
|
10
|
+
*/
|
|
11
|
+
get locked() {
|
|
12
|
+
return !!this.#lockMarker;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of InMemoryLock
|
|
16
|
+
*
|
|
17
|
+
* @param innerLock ILockable instance that can persist lock state outside of the current process
|
|
18
|
+
*/
|
|
19
|
+
constructor(innerLock) {
|
|
20
|
+
this.#innerLock = innerLock;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Acquire the lock on the current instance.
|
|
24
|
+
* Resolves when the lock is successfully acquired
|
|
25
|
+
*/
|
|
26
|
+
async lock() {
|
|
27
|
+
while (this.locked)
|
|
28
|
+
await this.once('unlocked');
|
|
29
|
+
try {
|
|
30
|
+
this.#lockMarker = new utils_1.Deferred();
|
|
31
|
+
if (this.#innerLock)
|
|
32
|
+
await this.#innerLock.lock();
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
try {
|
|
36
|
+
await this.unlock();
|
|
37
|
+
}
|
|
38
|
+
catch (unlockErr) {
|
|
39
|
+
// unlocking errors are ignored
|
|
40
|
+
}
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Release the lock acquired earlier
|
|
46
|
+
*/
|
|
47
|
+
async unlock() {
|
|
48
|
+
try {
|
|
49
|
+
if (this.#innerLock)
|
|
50
|
+
await this.#innerLock.unlock();
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
this.#lockMarker?.resolve();
|
|
54
|
+
this.#lockMarker = undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Wait until the lock is released.
|
|
59
|
+
* Resolves immediately if the lock is not acquired
|
|
60
|
+
*/
|
|
61
|
+
once(event) {
|
|
62
|
+
if (event !== 'unlocked')
|
|
63
|
+
throw new TypeError(`Unexpected event type: ${event}`);
|
|
64
|
+
return this.#lockMarker?.promise ?? Promise.resolve();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.InMemoryLock = InMemoryLock;
|
|
68
|
+
//# sourceMappingURL=InMemoryLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryLock.js","sourceRoot":"","sources":["../../src/infrastructure/InMemoryLock.ts"],"names":[],"mappings":";;;AACA,mCAAmC;AAEnC,MAAa,YAAY;IAExB,WAAW,CAA6B;IACxC,UAAU,CAAwB;IAElC;;OAEG;IACH,IAAI,MAAM;QACT,OAAO,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,YAAY,SAAqB;QAChC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACT,OAAO,IAAI,CAAC,MAAM;YACjB,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE7B,IAAI,CAAC;YACJ,IAAI,CAAC,WAAW,GAAG,IAAI,gBAAQ,EAAE,CAAC;YAClC,IAAI,IAAI,CAAC,UAAU;gBAClB,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC;QACD,OAAO,GAAQ,EAAE,CAAC;YACjB,IAAI,CAAC;gBACJ,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;YACrB,CAAC;YACD,OAAO,SAAc,EAAE,CAAC;gBACvB,+BAA+B;YAChC,CAAC;YACD,MAAM,GAAG,CAAC;QACX,CAAC;IACF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACX,IAAI,CAAC;YACJ,IAAI,IAAI,CAAC,UAAU;gBAClB,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QACjC,CAAC;gBACO,CAAC;YACR,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC;YAC5B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC9B,CAAC;IACF,CAAC;IAED;;;OAGG;IACH,IAAI,CAAC,KAAiB;QACrB,IAAI,KAAK,KAAK,UAAU;YACvB,MAAM,IAAI,SAAS,CAAC,0BAA0B,KAAK,EAAE,CAAC,CAAC;QAExD,OAAO,IAAI,CAAC,WAAW,EAAE,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IACvD,CAAC;CACD;AArED,oCAqEC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryMessageBus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Default implementation of the message bus.
|
|
6
|
+
* Keeps all subscriptions and messages in memory.
|
|
7
|
+
*/
|
|
8
|
+
class InMemoryMessageBus {
|
|
9
|
+
#handlers = new Map();
|
|
10
|
+
#name;
|
|
11
|
+
#uniqueEventHandlers;
|
|
12
|
+
#queues = new Map();
|
|
13
|
+
constructor({ name, uniqueEventHandlers = !!name } = {}) {
|
|
14
|
+
this.#name = name;
|
|
15
|
+
this.#uniqueEventHandlers = uniqueEventHandlers;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Subscribe to message type
|
|
19
|
+
*/
|
|
20
|
+
on(messageType, handler) {
|
|
21
|
+
if (typeof messageType !== 'string' || !messageType.length)
|
|
22
|
+
throw new TypeError('messageType argument must be a non-empty String');
|
|
23
|
+
if (typeof handler !== 'function')
|
|
24
|
+
throw new TypeError('handler argument must be a Function');
|
|
25
|
+
if (arguments.length !== 2)
|
|
26
|
+
throw new TypeError(`2 arguments are expected, but ${arguments.length} received`);
|
|
27
|
+
// Events published to a named queue must be consumed only once.
|
|
28
|
+
// For example, for sending a welcome email, NotificationReceptor will subscribe to "notifications:userCreated".
|
|
29
|
+
// Since we use an in-memory bus, there is no need to track message handling by multiple distributed subscribers,
|
|
30
|
+
// and we only need to make sure that no more than 1 such subscriber will be created
|
|
31
|
+
if (!this.#handlers.has(messageType))
|
|
32
|
+
this.#handlers.set(messageType, new Set());
|
|
33
|
+
else if (this.#uniqueEventHandlers)
|
|
34
|
+
throw new Error(`"${messageType}" handler is already set up on the "${this.#name}" queue`);
|
|
35
|
+
this.#handlers.get(messageType)?.add(handler);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get or create a named queue.
|
|
39
|
+
* Named queues support only one handler per event type.
|
|
40
|
+
*/
|
|
41
|
+
queue(name) {
|
|
42
|
+
let queue = this.#queues.get(name);
|
|
43
|
+
if (!queue) {
|
|
44
|
+
queue = new InMemoryMessageBus({ name, uniqueEventHandlers: true });
|
|
45
|
+
this.#queues.set(name, queue);
|
|
46
|
+
}
|
|
47
|
+
return queue;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Remove subscription
|
|
51
|
+
*/
|
|
52
|
+
off(messageType, handler) {
|
|
53
|
+
if (typeof messageType !== 'string' || !messageType.length)
|
|
54
|
+
throw new TypeError('messageType argument must be a non-empty String');
|
|
55
|
+
if (typeof handler !== 'function')
|
|
56
|
+
throw new TypeError('handler argument must be a Function');
|
|
57
|
+
if (arguments.length !== 2)
|
|
58
|
+
throw new TypeError(`2 arguments are expected, but ${arguments.length} received`);
|
|
59
|
+
if (!this.#handlers.has(messageType))
|
|
60
|
+
throw new Error(`No ${messageType} subscribers found`);
|
|
61
|
+
this.#handlers.get(messageType)?.delete(handler);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Send command to exactly 1 command handler
|
|
65
|
+
*/
|
|
66
|
+
async send(command) {
|
|
67
|
+
if (typeof command !== 'object' || !command)
|
|
68
|
+
throw new TypeError('command argument must be an Object');
|
|
69
|
+
if (typeof command.type !== 'string' || !command.type.length)
|
|
70
|
+
throw new TypeError('command.type argument must be a non-empty String');
|
|
71
|
+
const handlers = this.#handlers.get(command.type);
|
|
72
|
+
if (!handlers || !handlers.size)
|
|
73
|
+
throw new Error(`No '${command.type}' subscribers found`);
|
|
74
|
+
if (handlers.size > 1)
|
|
75
|
+
throw new Error(`More than one '${command.type}' subscriber found`);
|
|
76
|
+
const commandHandler = handlers.values().next().value;
|
|
77
|
+
return commandHandler(command);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Publish event to all subscribers (if any)
|
|
81
|
+
*/
|
|
82
|
+
async publish(event) {
|
|
83
|
+
if (typeof event !== 'object' || !event)
|
|
84
|
+
throw new TypeError('event argument must be an Object');
|
|
85
|
+
if (typeof event.type !== 'string' || !event.type.length)
|
|
86
|
+
throw new TypeError('event.type argument must be a non-empty String');
|
|
87
|
+
const handlers = [
|
|
88
|
+
...this.#handlers.get(event.type) || [],
|
|
89
|
+
...Array.from(this.#queues.values()).map(namedQueue => (e) => namedQueue.publish(e))
|
|
90
|
+
];
|
|
91
|
+
return Promise.all(handlers.map(handler => handler(event)));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.InMemoryMessageBus = InMemoryMessageBus;
|
|
95
|
+
//# sourceMappingURL=InMemoryMessageBus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryMessageBus.js","sourceRoot":"","sources":["../../src/infrastructure/InMemoryMessageBus.ts"],"names":[],"mappings":";;;AAQA;;;GAGG;AACH,MAAa,kBAAkB;IAE9B,SAAS,GAAsC,IAAI,GAAG,EAAE,CAAC;IACzD,KAAK,CAAqB;IAC1B,oBAAoB,CAAU;IAC9B,OAAO,GAAoC,IAAI,GAAG,EAAE,CAAC;IAErD,YAAY,EAAE,IAAI,EAAE,mBAAmB,GAAG,CAAC,CAAC,IAAI,KAG5C,EAAE;QACL,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,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AC,CAAC;QAErE,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;QAEtD,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,KAAa;QAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK;YACtC,MAAM,IAAI,SAAS,CAAC,kCAAkC,CAAC,CAAC;QACzD,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM;YACvD,MAAM,IAAI,SAAS,CAAC,gDAAgD,CAAC,CAAC;QAEvE,MAAM,QAAQ,GAAG;YAChB,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE;YACvC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CACrD,CAAC,CAAS,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;SACtC,CAAC;QAEF,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;CACD;AAzGD,gDAyGC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemorySnapshotStorage = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* In-memory storage for aggregate snapshots.
|
|
6
|
+
* Storage content resets on app restart
|
|
7
|
+
*/
|
|
8
|
+
class InMemorySnapshotStorage {
|
|
9
|
+
#snapshots = new Map();
|
|
10
|
+
/**
|
|
11
|
+
* Get latest aggregate snapshot
|
|
12
|
+
*/
|
|
13
|
+
async getAggregateSnapshot(aggregateId) {
|
|
14
|
+
return this.#snapshots.get(aggregateId);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Save new aggregate snapshot
|
|
18
|
+
*/
|
|
19
|
+
async saveAggregateSnapshot(snapshotEvent) {
|
|
20
|
+
if (!snapshotEvent.aggregateId)
|
|
21
|
+
throw new TypeError('event.aggregateId is required');
|
|
22
|
+
this.#snapshots.set(snapshotEvent.aggregateId, snapshotEvent);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.InMemorySnapshotStorage = InMemorySnapshotStorage;
|
|
26
|
+
//# sourceMappingURL=InMemorySnapshotStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemorySnapshotStorage.js","sourceRoot":"","sources":["../../src/infrastructure/InMemorySnapshotStorage.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,MAAa,uBAAuB;IAEnC,UAAU,GAA4B,IAAI,GAAG,EAAE,CAAC;IAEhD;;OAEG;IACH,KAAK,CAAC,oBAAoB,CAAC,WAAuB;QACjD,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,qBAAqB,CAAC,aAAqB;QAChD,IAAI,CAAC,aAAa,CAAC,WAAW;YAC7B,MAAM,IAAI,SAAS,CAAC,+BAA+B,CAAC,CAAC;QAEtD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC/D,CAAC;CACD;AApBD,0DAoBC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryView = void 0;
|
|
4
|
+
const InMemoryLock_1 = require("./InMemoryLock");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
/**
|
|
7
|
+
* Update given value with an update Cb and return updated value.
|
|
8
|
+
* Wrapper is needed for backward compatibility with update methods that were modifying the passed in objects directly
|
|
9
|
+
*/
|
|
10
|
+
function applyUpdate(view, update) {
|
|
11
|
+
const valueReturnedByUpdate = update(view);
|
|
12
|
+
return valueReturnedByUpdate === undefined ?
|
|
13
|
+
view :
|
|
14
|
+
valueReturnedByUpdate;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* In-memory Projection View, which suspends get()'s until it is ready
|
|
18
|
+
*/
|
|
19
|
+
class InMemoryView {
|
|
20
|
+
static factory() {
|
|
21
|
+
return new InMemoryView();
|
|
22
|
+
}
|
|
23
|
+
_map = new Map();
|
|
24
|
+
#lock;
|
|
25
|
+
#asyncWrites;
|
|
26
|
+
/** Whether the view is restored */
|
|
27
|
+
get ready() {
|
|
28
|
+
return !this.#lock.locked;
|
|
29
|
+
}
|
|
30
|
+
/** Number of records in the View */
|
|
31
|
+
get size() {
|
|
32
|
+
return this._map.size;
|
|
33
|
+
}
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.#asyncWrites = options?.asyncWrites ?? false;
|
|
36
|
+
this.#lock = new InMemoryLock_1.InMemoryLock();
|
|
37
|
+
// explicitly bind the `get` method to this object for easier using in Promises
|
|
38
|
+
Object.defineProperty(this, this.get.name, {
|
|
39
|
+
value: this.get.bind(this)
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** Lock the view to prevent concurrent modifications */
|
|
43
|
+
async lock() {
|
|
44
|
+
await this.#lock.lock();
|
|
45
|
+
return this.#lock.locked;
|
|
46
|
+
}
|
|
47
|
+
/** Release the lock */
|
|
48
|
+
async unlock() {
|
|
49
|
+
return this.#lock.unlock();
|
|
50
|
+
}
|
|
51
|
+
/** Create a Promise which will resolve to a first emitted event of a given type */
|
|
52
|
+
once(eventType) {
|
|
53
|
+
if (eventType !== 'ready')
|
|
54
|
+
throw new TypeError(`Unexpected event type: ${eventType}`);
|
|
55
|
+
return this.#lock.once('unlocked');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if view contains a record with a given key.
|
|
59
|
+
* This is the only synchronous method, so make sure to check the `ready` flag, if necessary
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Use `async get()` instead
|
|
62
|
+
*/
|
|
63
|
+
has(key) {
|
|
64
|
+
return this._map.has(key);
|
|
65
|
+
}
|
|
66
|
+
/** Get record with a given key; await until the view is restored */
|
|
67
|
+
async get(key, options) {
|
|
68
|
+
if (!key)
|
|
69
|
+
throw new TypeError('key argument required');
|
|
70
|
+
if (!this.ready && !options?.nowait)
|
|
71
|
+
await this.once('ready');
|
|
72
|
+
await (0, utils_1.nextCycle)();
|
|
73
|
+
return this._map.get(key);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get record with a given key synchronously
|
|
77
|
+
*/
|
|
78
|
+
getSync(key) {
|
|
79
|
+
if (!key)
|
|
80
|
+
throw new TypeError('key argument required');
|
|
81
|
+
return this._map.get(key);
|
|
82
|
+
}
|
|
83
|
+
/** Get all records matching an optional filter */
|
|
84
|
+
async getAll(filter) {
|
|
85
|
+
if (filter && typeof filter !== 'function')
|
|
86
|
+
throw new TypeError('filter argument, when defined, must be a Function');
|
|
87
|
+
if (!this.ready)
|
|
88
|
+
await this.once('ready');
|
|
89
|
+
await (0, utils_1.nextCycle)();
|
|
90
|
+
const r = [];
|
|
91
|
+
for (const entry of this._map.entries()) {
|
|
92
|
+
if (!filter || filter(entry[1], entry[0]))
|
|
93
|
+
r.push(entry);
|
|
94
|
+
}
|
|
95
|
+
return r;
|
|
96
|
+
}
|
|
97
|
+
/** Create record with a given key and value */
|
|
98
|
+
async create(key, value = {}) {
|
|
99
|
+
if (!key)
|
|
100
|
+
throw new TypeError('key argument required');
|
|
101
|
+
if (typeof value === 'function')
|
|
102
|
+
throw new TypeError('value argument must be an instance of an Object');
|
|
103
|
+
if (this.#asyncWrites)
|
|
104
|
+
await (0, utils_1.nextCycle)();
|
|
105
|
+
if (this._map.has(key))
|
|
106
|
+
throw new Error(`Key '${key}' already exists`);
|
|
107
|
+
this._map.set(key, value);
|
|
108
|
+
}
|
|
109
|
+
/** Update existing view record */
|
|
110
|
+
async update(key, update) {
|
|
111
|
+
if (!key)
|
|
112
|
+
throw new TypeError('key argument required');
|
|
113
|
+
if (typeof update !== 'function')
|
|
114
|
+
throw new TypeError('update argument must be a Function');
|
|
115
|
+
if (!this._map.has(key))
|
|
116
|
+
throw new Error(`Key '${key}' does not exist`);
|
|
117
|
+
return this._update(key, update);
|
|
118
|
+
}
|
|
119
|
+
/** Update existing view record or create new */
|
|
120
|
+
async updateEnforcingNew(key, update) {
|
|
121
|
+
if (!key)
|
|
122
|
+
throw new TypeError('key argument required');
|
|
123
|
+
if (typeof update !== 'function')
|
|
124
|
+
throw new TypeError('update argument must be a Function');
|
|
125
|
+
if (!this._map.has(key))
|
|
126
|
+
return this.create(key, applyUpdate(undefined, update));
|
|
127
|
+
return this._update(key, update);
|
|
128
|
+
}
|
|
129
|
+
/** Update all records that match filter criteria */
|
|
130
|
+
async updateAll(filter, update) {
|
|
131
|
+
if (filter && typeof filter !== 'function')
|
|
132
|
+
throw new TypeError('filter argument, when specified, must be a Function');
|
|
133
|
+
if (typeof update !== 'function')
|
|
134
|
+
throw new TypeError('update argument must be a Function');
|
|
135
|
+
for (const [key, value] of this._map) {
|
|
136
|
+
if (!filter || filter(value))
|
|
137
|
+
await this._update(key, update);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Update existing record */
|
|
141
|
+
async _update(key, update) {
|
|
142
|
+
const value = this._map.get(key);
|
|
143
|
+
const updatedValue = applyUpdate(value, update);
|
|
144
|
+
if (updatedValue === undefined)
|
|
145
|
+
return;
|
|
146
|
+
if (this.#asyncWrites)
|
|
147
|
+
await (0, utils_1.nextCycle)();
|
|
148
|
+
this._map.set(key, updatedValue);
|
|
149
|
+
}
|
|
150
|
+
/** Delete record */
|
|
151
|
+
async delete(key) {
|
|
152
|
+
if (!key)
|
|
153
|
+
throw new TypeError('key argument required');
|
|
154
|
+
if (this.#asyncWrites)
|
|
155
|
+
await (0, utils_1.nextCycle)();
|
|
156
|
+
this._map.delete(key);
|
|
157
|
+
}
|
|
158
|
+
/** Delete all records that match filter criteria */
|
|
159
|
+
async deleteAll(filter) {
|
|
160
|
+
if (filter && typeof filter !== 'function')
|
|
161
|
+
throw new TypeError('filter argument, when specified, must be a Function');
|
|
162
|
+
for (const [key, value] of this._map) {
|
|
163
|
+
if (!filter || filter(value))
|
|
164
|
+
await this.delete(key);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/** Get view summary as string */
|
|
168
|
+
toString() {
|
|
169
|
+
return `${this.size} record${this.size !== 1 ? 's' : ''}`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.InMemoryView = InMemoryView;
|
|
173
|
+
//# sourceMappingURL=InMemoryView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InMemoryView.js","sourceRoot":"","sources":["../../src/infrastructure/InMemoryView.ts"],"names":[],"mappings":";;;AAAA,iDAA8C;AAE9C,mCAAoC;AAEpC;;;GAGG;AACH,SAAS,WAAW,CAAI,IAAmB,EAAE,MAAgC;IAC5E,MAAM,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3C,OAAO,qBAAqB,KAAK,SAAS,CAAC,CAAC;QAC3C,IAAI,CAAC,CAAC;QACN,qBAAqB,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAa,YAAY;IAExB,MAAM,CAAC,OAAO;QACb,OAAQ,IAAI,YAAY,EAAuB,CAAC;IACjD,CAAC;IAES,IAAI,GAA6B,IAAI,GAAG,EAAE,CAAC;IAErD,KAAK,CAAe;IAEpB,YAAY,CAAU;IAEtB,mCAAmC;IACnC,IAAI,KAAK;QACR,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;IAC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,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC;gBAC3B,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACF,CAAC;IAED,iCAAiC;IACjC,QAAQ;QACP,OAAO,GAAG,IAAI,CAAC,IAAI,UAAU,IAAI,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC3D,CAAC;CACD;AA1MD,oCA0MC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Deferred = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Deferred promise that must be resolved from outside
|
|
6
|
+
*/
|
|
7
|
+
class Deferred {
|
|
8
|
+
promise;
|
|
9
|
+
get resolved() {
|
|
10
|
+
return this.#resolved;
|
|
11
|
+
}
|
|
12
|
+
get rejected() {
|
|
13
|
+
return this.#rejected;
|
|
14
|
+
}
|
|
15
|
+
get settled() {
|
|
16
|
+
return this.#resolved || this.#rejected;
|
|
17
|
+
}
|
|
18
|
+
#resolve;
|
|
19
|
+
#resolved = false;
|
|
20
|
+
#reject;
|
|
21
|
+
#rejected = false;
|
|
22
|
+
constructor() {
|
|
23
|
+
this.promise = new Promise((resolve, reject) => {
|
|
24
|
+
this.#resolve = resolve;
|
|
25
|
+
this.#reject = reject;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
resolve(value) {
|
|
29
|
+
this.#resolve(value);
|
|
30
|
+
this.#resolved = true;
|
|
31
|
+
}
|
|
32
|
+
reject(reason) {
|
|
33
|
+
this.#reject(reason);
|
|
34
|
+
this.#rejected = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Deferred = Deferred;
|
|
38
|
+
//# sourceMappingURL=Deferred.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Deferred.js","sourceRoot":"","sources":["../../../src/infrastructure/utils/Deferred.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,QAAQ;IAEX,OAAO,CAAiC;IAEjD,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,IAAI,QAAQ;QACX,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;IAED,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;IACzC,CAAC;IAED,QAAQ,CAAkE;IAC1E,SAAS,GAAY,KAAK,CAAC;IAC3B,OAAO,CAA0B;IACjC,SAAS,GAAY,KAAK,CAAC;IAE3B;QACC,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACvB,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,KAAsB;QAC7B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,MAAY;QAClB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC;CACD;AArCD,4BAqCC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
__exportStar(require("./Deferred"), exports);
|
|
18
|
+
__exportStar(require("./nextCycle"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/infrastructure/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nextCycle = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @returns Promise that resolves on next event loop cycle
|
|
6
|
+
*/
|
|
7
|
+
const nextCycle = () => new Promise(rs => setImmediate(rs));
|
|
8
|
+
exports.nextCycle = nextCycle;
|
|
9
|
+
//# sourceMappingURL=nextCycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextCycle.js","sourceRoot":"","sources":["../../../src/infrastructure/utils/nextCycle.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACI,MAAM,SAAS,GAAG,GAAkB,EAAE,CAAC,IAAI,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC;AAArE,QAAA,SAAS,aAA4D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;AAqHC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClassName = getClassName;
|
|
4
|
+
/**
|
|
5
|
+
* Get instance class name
|
|
6
|
+
*/
|
|
7
|
+
function getClassName(instance) {
|
|
8
|
+
return Object.getPrototypeOf(instance).constructor.name;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=getClassName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getClassName.js","sourceRoot":"","sources":["../../src/utils/getClassName.ts"],"names":[],"mappings":";;AAGA,oCAEC;AALD;;GAEG;AACH,SAAgB,YAAY,CAAC,QAAgB;IAC5C,OAAO,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHandledMessageTypes = getHandledMessageTypes;
|
|
4
|
+
const getMessageHandlerNames_1 = require("./getMessageHandlerNames");
|
|
5
|
+
/**
|
|
6
|
+
* Get a list of message types handled by observer
|
|
7
|
+
*/
|
|
8
|
+
function getHandledMessageTypes(observerInstanceOrClass) {
|
|
9
|
+
if (!observerInstanceOrClass)
|
|
10
|
+
throw new TypeError('observerInstanceOrClass argument required');
|
|
11
|
+
if (observerInstanceOrClass.handles)
|
|
12
|
+
return observerInstanceOrClass.handles;
|
|
13
|
+
const prototype = Object.getPrototypeOf(observerInstanceOrClass);
|
|
14
|
+
if (prototype && prototype.constructor && prototype.constructor.handles)
|
|
15
|
+
return prototype.constructor.handles;
|
|
16
|
+
return (0, getMessageHandlerNames_1.getMessageHandlerNames)(observerInstanceOrClass);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=getHandledMessageTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHandledMessageTypes.js","sourceRoot":"","sources":["../../src/utils/getHandledMessageTypes.ts"],"names":[],"mappings":";;AAKA,wDAcC;AAnBD,qEAAkE;AAElE;;GAEG;AACH,SAAgB,sBAAsB,CACrC,uBAAqE;IAErE,IAAI,CAAC,uBAAuB;QAC3B,MAAM,IAAI,SAAS,CAAC,2CAA2C,CAAC,CAAC;IAElE,IAAI,uBAAuB,CAAC,OAAO;QAClC,OAAO,uBAAuB,CAAC,OAAO,CAAC;IAExC,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC;IACjE,IAAI,SAAS,IAAI,SAAS,CAAC,WAAW,IAAI,SAAS,CAAC,WAAW,CAAC,OAAO;QACtE,OAAO,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC;IAEtC,OAAO,IAAA,+CAAsB,EAAC,uBAAuB,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHandler = getHandler;
|
|
4
|
+
/**
|
|
5
|
+
* Gets a handler for a specific message type, prefers a public (w\o _ prefix) method, if available
|
|
6
|
+
*/
|
|
7
|
+
function getHandler(context, messageType) {
|
|
8
|
+
if (!context || typeof context !== 'object')
|
|
9
|
+
throw new TypeError('context argument required');
|
|
10
|
+
if (typeof messageType !== 'string' || !messageType.length)
|
|
11
|
+
throw new TypeError('messageType argument must be a non-empty string');
|
|
12
|
+
if (messageType in context && typeof context[messageType] === 'function')
|
|
13
|
+
return context[messageType].bind(context);
|
|
14
|
+
const privateHandlerName = `_${messageType}`;
|
|
15
|
+
if (privateHandlerName in context && typeof context[privateHandlerName] === 'function')
|
|
16
|
+
return context[privateHandlerName].bind(context);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
;
|
|
20
|
+
//# sourceMappingURL=getHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getHandler.js","sourceRoot":"","sources":["../../src/utils/getHandler.ts"],"names":[],"mappings":";;AAKA,gCAcC;AAjBD;;GAEG;AACH,SAAgB,UAAU,CAAC,OAA+B,EAAE,WAAmB;IAC9E,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;QAC1C,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;IAClD,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,WAAW,CAAC,MAAM;QACzD,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC,CAAC;IAExE,IAAI,WAAW,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,WAAW,CAAC,KAAK,UAAU;QACvE,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE3C,MAAM,kBAAkB,GAAG,IAAI,WAAW,EAAE,CAAC;IAC7C,IAAI,kBAAkB,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,kBAAkB,CAAC,KAAK,UAAU;QACrF,OAAO,OAAO,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAElD,OAAO,IAAI,CAAC;AACb,CAAC;AAAA,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMessageHandlerNames = getMessageHandlerNames;
|
|
4
|
+
const KNOWN_METHOD_NAMES = new Set([
|
|
5
|
+
'subscribe'
|
|
6
|
+
]);
|
|
7
|
+
function getInheritedPropertyNames(prototype) {
|
|
8
|
+
const parentPrototype = prototype && Object.getPrototypeOf(prototype);
|
|
9
|
+
if (!parentPrototype)
|
|
10
|
+
return [];
|
|
11
|
+
const propDescriptors = Object.getOwnPropertyDescriptors(parentPrototype);
|
|
12
|
+
const propNames = Object.keys(propDescriptors);
|
|
13
|
+
return [
|
|
14
|
+
...propNames,
|
|
15
|
+
...getInheritedPropertyNames(parentPrototype)
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get message handler names from a command/event handler class.
|
|
20
|
+
* Assumes all private method names start from underscore ("_").
|
|
21
|
+
*/
|
|
22
|
+
function getMessageHandlerNames(observerInstanceOrClass) {
|
|
23
|
+
if (!observerInstanceOrClass)
|
|
24
|
+
throw new TypeError('observerInstanceOrClass argument required');
|
|
25
|
+
const prototype = typeof observerInstanceOrClass === 'function' ?
|
|
26
|
+
observerInstanceOrClass.prototype :
|
|
27
|
+
Object.getPrototypeOf(observerInstanceOrClass);
|
|
28
|
+
if (!prototype)
|
|
29
|
+
throw new TypeError('prototype cannot be resolved');
|
|
30
|
+
const inheritedProperties = new Set(getInheritedPropertyNames(prototype));
|
|
31
|
+
const propDescriptors = Object.getOwnPropertyDescriptors(prototype);
|
|
32
|
+
const propNames = Object.keys(propDescriptors);
|
|
33
|
+
return propNames.filter(key => !key.startsWith('_') &&
|
|
34
|
+
!inheritedProperties.has(key) &&
|
|
35
|
+
!KNOWN_METHOD_NAMES.has(key) &&
|
|
36
|
+
typeof propDescriptors[key].value === 'function');
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=getMessageHandlerNames.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMessageHandlerNames.js","sourceRoot":"","sources":["../../src/utils/getMessageHandlerNames.ts"],"names":[],"mappings":";;AAsBA,wDAqBC;AA3CD,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IAClC,WAAW;CACX,CAAC,CAAC;AAEH,SAAS,yBAAyB,CAAC,SAAiB;IACnD,MAAM,eAAe,GAAG,SAAS,IAAI,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACtE,IAAI,CAAC,eAAe;QACnB,OAAO,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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
|
+
__exportStar(require("./getClassName"), exports);
|
|
18
|
+
__exportStar(require("./getHandler"), exports);
|
|
19
|
+
__exportStar(require("./validateHandlers"), exports);
|
|
20
|
+
__exportStar(require("./getMessageHandlerNames"), exports);
|
|
21
|
+
__exportStar(require("./getHandledMessageTypes"), exports);
|
|
22
|
+
__exportStar(require("./setupOneTimeEmitterSubscription"), exports);
|
|
23
|
+
__exportStar(require("./subscribe"), exports);
|
|
24
|
+
__exportStar(require("./isClass"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,+CAA6B;AAC7B,qDAAmC;AACnC,2DAAyC;AACzC,2DAAyC;AACzC,oEAAkD;AAClD,8CAA4B;AAC5B,4CAA0B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isClass = isClass;
|
|
4
|
+
function isClass(func) {
|
|
5
|
+
return typeof func === 'function'
|
|
6
|
+
&& Function.prototype.toString.call(func).startsWith('class');
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=isClass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isClass.js","sourceRoot":"","sources":["../../src/utils/isClass.ts"],"names":[],"mappings":";;AAAA,0BAGC;AAHD,SAAgB,OAAO,CAAC,IAAc;IACrC,OAAO,OAAO,IAAI,KAAK,UAAU;WAC7B,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAChE,CAAC"}
|