ddd-node 20.0.0 → 21.0.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/core/aggregate/state-aggregate/state-aggregate.d.ts +2 -2
- package/dist/core/event-pubsub/event-subscriber-registry.js +13 -9
- package/dist/core/event-pubsub/event-subscriber.d.ts +2 -2
- package/dist/core/event-pubsub/event-subscriber.js +1 -1
- package/dist/model/core/model.d.ts +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Class } from "type-fest";
|
|
2
2
|
import { Props, PropsOf } from "../../../model";
|
|
3
3
|
import { ClassStatic } from "../../../types";
|
|
4
|
-
import { AnyEvent,
|
|
4
|
+
import { AnyEvent, EventClassWithTypedConstructor } from "../../message";
|
|
5
5
|
import { AggregateBase, AggregateMetadata } from "../aggregate-base";
|
|
6
6
|
import { IEventDispatcher } from "../event-dispatcher.interface";
|
|
7
7
|
export declare class StateAggregateBase<P extends Props> extends AggregateBase<P> {
|
|
@@ -11,7 +11,7 @@ export declare class StateAggregateBase<P extends Props> extends AggregateBase<P
|
|
|
11
11
|
version(): number;
|
|
12
12
|
events(): AnyEvent[];
|
|
13
13
|
protected recordEvent<E extends AnyEvent>(event: E): void;
|
|
14
|
-
protected recordEvent<E extends AnyEvent>(eventClass:
|
|
14
|
+
protected recordEvent<E extends AnyEvent>(eventClass: EventClassWithTypedConstructor<E>, props: PropsOf<E>): void;
|
|
15
15
|
clearEvents(): void;
|
|
16
16
|
dispatchEvents(dispatcher: IEventDispatcher): void;
|
|
17
17
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EventSubscriberRegistry = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
4
5
|
class EventSubscriberRegistry {
|
|
5
6
|
static instance() {
|
|
6
7
|
if (!this._instance)
|
|
@@ -25,29 +26,32 @@ class EventSubscriberRegistry {
|
|
|
25
26
|
this._initSubscribersForEvent(eventType);
|
|
26
27
|
return subscribers();
|
|
27
28
|
}
|
|
28
|
-
_hasSubscriber(subscriber) {
|
|
29
|
-
const subscribedEvent = subscriber.subscribeToEvent();
|
|
29
|
+
_hasSubscriber(subscribedEvent, subscriber) {
|
|
30
30
|
const subscribers = this._getSubscribersForEvent(subscribedEvent);
|
|
31
31
|
return subscribers.some((_subscriber) => _subscriber === subscriber);
|
|
32
32
|
}
|
|
33
|
-
_addSubscriber(subscriber) {
|
|
34
|
-
if (!this._hasSubscriber(subscriber)) {
|
|
35
|
-
const subscribedEvent = subscriber.subscribeToEvent();
|
|
33
|
+
_addSubscriber(subscribedEvent, subscriber) {
|
|
34
|
+
if (!this._hasSubscriber(subscribedEvent, subscriber)) {
|
|
36
35
|
const subscribers = this._getSubscribersForEvent(subscribedEvent);
|
|
37
36
|
subscribers.push(subscriber);
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
|
-
_removeSubscriber(subscriber) {
|
|
41
|
-
const subscribedEvent = subscriber.subscribeToEvent();
|
|
39
|
+
_removeSubscriber(subscribedEvent, subscriber) {
|
|
42
40
|
const subscribers = this._getSubscribersForEvent(subscribedEvent);
|
|
43
41
|
this._setSubscribersForEvent(subscribedEvent, subscribers.filter((_subscriber) => _subscriber !== subscriber));
|
|
44
42
|
}
|
|
45
43
|
registerSubscriber(subscriber) {
|
|
46
|
-
|
|
44
|
+
const subscribedEvents = (0, utils_1.toArray)(subscriber.subscribeToEvents());
|
|
45
|
+
subscribedEvents.forEach((subscribedEvent) => {
|
|
46
|
+
this._addSubscriber(subscribedEvent, subscriber);
|
|
47
|
+
});
|
|
47
48
|
return () => this.deregisterSubscriber(subscriber);
|
|
48
49
|
}
|
|
49
50
|
deregisterSubscriber(subscriber) {
|
|
50
|
-
|
|
51
|
+
const subscribedEvents = (0, utils_1.toArray)(subscriber.subscribeToEvents());
|
|
52
|
+
subscribedEvents.forEach((subscribedEvent) => {
|
|
53
|
+
this._removeSubscriber(subscribedEvent, subscriber);
|
|
54
|
+
});
|
|
51
55
|
}
|
|
52
56
|
getSubscribersForEvent(eventType) {
|
|
53
57
|
return Array.from(this._getSubscribersForEvent(eventType));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyEvent, EventClass } from "../message";
|
|
2
2
|
export interface IEventSubscriber<T extends AnyEvent = AnyEvent> {
|
|
3
|
-
|
|
3
|
+
subscribeToEvents(): EventClass<T> | EventClass<T>[];
|
|
4
4
|
handleEvent(event: T): Promise<void>;
|
|
5
5
|
}
|
|
6
6
|
export type EventSubscriberHandler<T extends AnyEvent = AnyEvent> = IEventSubscriber<T>["handleEvent"];
|
|
@@ -8,6 +8,6 @@ export declare class EventSubscriber<T extends AnyEvent = AnyEvent> implements I
|
|
|
8
8
|
private readonly subscribedEvent;
|
|
9
9
|
private readonly eventHandler;
|
|
10
10
|
constructor(subscribedEvent: EventClass<T>, eventHandler: EventSubscriberHandler<T>);
|
|
11
|
-
|
|
11
|
+
subscribeToEvents(): EventClass<T, any[]>;
|
|
12
12
|
handleEvent(event: T): Promise<void>;
|
|
13
13
|
}
|
|
@@ -28,7 +28,7 @@ export declare class ModelBase<P extends Props> {
|
|
|
28
28
|
constructor();
|
|
29
29
|
protected redefineModel(): void;
|
|
30
30
|
protected redefineProp(key: keyof this, propTargetKey: keyof P): void;
|
|
31
|
-
|
|
31
|
+
modelMetadata(): ModelMetadata<typeof this>;
|
|
32
32
|
validateProps(props: P): void;
|
|
33
33
|
validate(): void;
|
|
34
34
|
propsIsEmpty(): boolean;
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"ddd-node","version":"
|
|
1
|
+
{"name":"ddd-node","version":"21.0.0","description":"Domain Driven Design base for NodeJs","type":"commonjs","main":"index.js","types":"index.d.ts","files":["dist"],"repository":{"type":"git","url":"https://github.com/nqd881/ddd-node"},"keywords":["ddd","ddd-node","ddd-base","ddd-ts","ddd-js"],"author":"Quoc Dai","license":"ISC","devDependencies":{"@types/chai":"^4.3.16","@types/lodash":"^4.14.200","@types/mocha":"^10.0.6","@types/uuid":"^9.0.6","chai":"^5.1.1","chai-deep-match":"^1.2.1","ddd-node":"file:dist","mocha":"^10.4.0","ts-node":"^10.9.1","tsconfig-paths":"^4.2.0","typescript":"^5.2.2"},"dependencies":{"lodash":"^4.17.21","nodejs-snowflake":"^2.0.1","reflect-metadata":"^0.1.13","tsc-alias":"^1.8.8","type-fest":"^4.20.1","uuid":"^9.0.1"}}
|