ddd-node 36.0.0 → 36.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ exports.Model = Model;
5
5
  const domain_1 = require("../domain");
6
6
  const meta_1 = require("../meta");
7
7
  exports.DEFAULT_MODEL_OPTIONS = {
8
- autoRegisterModel: true,
8
+ autoRegisterModel: true
9
9
  };
10
10
  /**
11
11
  * @Model decorator — registers a DomainModel with metadata and domain context.
@@ -18,7 +18,7 @@ const registerPropertyAccessor = (target, key, propTargetKey, propConverter) =>
18
18
  const declaredMap = (0, exports.resolveOwnPropertyAccessors)(target);
19
19
  declaredMap.set(key, {
20
20
  targetKey: propTargetKey,
21
- converter: propConverter,
21
+ converter: propConverter
22
22
  });
23
23
  };
24
24
  exports.registerPropertyAccessor = registerPropertyAccessor;
@@ -48,7 +48,7 @@ const defineStaticEntryProperty = (target, key) => {
48
48
  },
49
49
  set() {
50
50
  throw new Error("Static value is readonly");
51
- },
51
+ }
52
52
  });
53
53
  };
54
54
  exports.defineStaticEntryProperty = defineStaticEntryProperty;
@@ -32,7 +32,7 @@ class DomainModel {
32
32
  if (!propConverter)
33
33
  return value;
34
34
  return propConverter(value);
35
- },
35
+ }
36
36
  });
37
37
  }
38
38
  get modelDescriptor() {
@@ -74,7 +74,7 @@ class DomainModel {
74
74
  let result = Reflect.set(target, propKey, value);
75
75
  this.validate();
76
76
  return result;
77
- },
77
+ }
78
78
  });
79
79
  }
80
80
  this.validate();
@@ -14,6 +14,10 @@ export declare class ESAggregate<P extends Props> extends Aggregate<P> {
14
14
  private _events;
15
15
  typedConstructor(): ESAggregateClass<typeof this>;
16
16
  get version(): number;
17
+ /**
18
+ * Version after all committed (past) events have been applied, excluding new events.
19
+ */
20
+ get committedVersion(): number;
17
21
  pastEvents(): AnyEvent[];
18
22
  events(): AnyEvent[];
19
23
  hasNewEvent(): boolean;
@@ -19,7 +19,7 @@ class ESAggregate extends aggregate_1.Aggregate {
19
19
  return this.fromStream(id ?? (0, uuid_1.v4)(), []);
20
20
  }
21
21
  static fromSnapshot(snapshot, pastEvents = []) {
22
- const { metadata: { id, version }, props, } = snapshot;
22
+ const { metadata: { id, version }, props } = snapshot;
23
23
  const instance = new this(id, version, props);
24
24
  instance.replayPastEvents(pastEvents);
25
25
  return instance;
@@ -36,6 +36,12 @@ class ESAggregate extends aggregate_1.Aggregate {
36
36
  get version() {
37
37
  return this.initialVersion + this._pastEvents.length + this._events.length;
38
38
  }
39
+ /**
40
+ * Version after all committed (past) events have been applied, excluding new events.
41
+ */
42
+ get committedVersion() {
43
+ return this.initialVersion + this._pastEvents.length;
44
+ }
39
45
  pastEvents() {
40
46
  return Array.from(this._pastEvents);
41
47
  }
@@ -94,9 +100,9 @@ class ESAggregate extends aggregate_1.Aggregate {
94
100
  return {
95
101
  metadata: {
96
102
  id: this.id,
97
- version: this.version,
103
+ version: this.version
98
104
  },
99
- props: this.props(),
105
+ props: this.props()
100
106
  };
101
107
  }
102
108
  commitEvents() {
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SubscribeToEvents = exports.SubscribedEventsMetaKey = void 0;
4
- const utils_1 = require("../../utils");
4
+ const helpers_1 = require("../../helpers");
5
5
  exports.SubscribedEventsMetaKey = Symbol("SUBSCRIBED_EVENTS");
6
6
  const SubscribeToEvents = (subscribedEvents) => {
7
7
  return (target) => {
8
- Reflect.defineMetadata(exports.SubscribedEventsMetaKey, (0, utils_1.toArray)(subscribedEvents), target);
8
+ Reflect.defineMetadata(exports.SubscribedEventsMetaKey, (0, helpers_1.toArray)(subscribedEvents), target);
9
9
  };
10
10
  };
11
11
  exports.SubscribeToEvents = SubscribeToEvents;
@@ -1,7 +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
+ const helpers_1 = require("../helpers");
5
5
  class EventSubscriberRegistry {
6
6
  static instance() {
7
7
  if (!this._instance)
@@ -49,14 +49,14 @@ class EventSubscriberRegistry {
49
49
  this._globalSubscribers.delete(subscriber);
50
50
  }
51
51
  registerSubscriber(subscriber) {
52
- const subscribedEvents = (0, utils_1.toArray)(subscriber.subscribeToEvents());
52
+ const subscribedEvents = (0, helpers_1.toArray)(subscriber.subscribeToEvents());
53
53
  subscribedEvents.forEach((subscribedEvent) => {
54
54
  this._addSubscriber(subscribedEvent, subscriber);
55
55
  });
56
56
  return () => this.deregisterSubscriber(subscriber);
57
57
  }
58
58
  deregisterSubscriber(subscriber) {
59
- const subscribedEvents = (0, utils_1.toArray)(subscriber.subscribeToEvents());
59
+ const subscribedEvents = (0, helpers_1.toArray)(subscriber.subscribeToEvents());
60
60
  subscribedEvents.forEach((subscribedEvent) => {
61
61
  this._removeSubscriber(subscribedEvent, subscriber);
62
62
  });
@@ -73,7 +73,7 @@ class EventSubscriberRegistry {
73
73
  getAllSubscribersForEvent(eventType) {
74
74
  return [
75
75
  ...this.getGlobalSubscribers(),
76
- ...this.getSubscribersForEvent(eventType),
76
+ ...this.getSubscribersForEvent(eventType)
77
77
  ];
78
78
  }
79
79
  }
package/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export * from "./base";
2
2
  export * from "./types";
3
3
  export * from "./core";
4
4
  export * from "./event-handling";
5
- export * from "./utils";
6
- export * from "./common";
5
+ export * from "./utilities";
6
+ export * from "./helpers";
7
+ export * from "./repository";
package/index.js CHANGED
@@ -19,5 +19,6 @@ __exportStar(require("./base"), exports);
19
19
  __exportStar(require("./types"), exports);
20
20
  __exportStar(require("./core"), exports);
21
21
  __exportStar(require("./event-handling"), exports);
22
- __exportStar(require("./utils"), exports);
23
- __exportStar(require("./common"), exports);
22
+ __exportStar(require("./utilities"), exports);
23
+ __exportStar(require("./helpers"), exports);
24
+ __exportStar(require("./repository"), exports);
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"ddd-node","version":"36.0.0","description":"Domain Driven Design base for NodeJs","type":"commonjs","main":"index.js","types":"index.d.ts","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","tsconfig-paths":"^4.2.0","typescript":"^5.9.3"},"dependencies":{"class-transformer":"^0.5.1","is-class":"^0.0.9","lodash":"^4.17.21","reflect-metadata":"^0.1.13","ts-node":"^10.9.2","tsc-alias":"^1.8.8","type-fest":"^4.20.1","uuid":"^9.0.1"},"peerDependencies":{"class-validator":"^0.14.2"}}
1
+ {"name":"ddd-node","version":"36.0.1","description":"Domain Driven Design base for NodeJs","type":"commonjs","main":"index.js","types":"index.d.ts","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","tsconfig-paths":"^4.2.0","typescript":"^5.9.3"},"dependencies":{"class-transformer":"^0.5.1","is-class":"^0.0.9","lodash":"^4.17.21","reflect-metadata":"^0.1.13","ts-node":"^10.9.2","tsc-alias":"^1.8.8","type-fest":"^4.20.1","uuid":"^9.0.1"},"peerDependencies":{"class-validator":"^0.14.2"}}
@@ -0,0 +1 @@
1
+ export * from "./repository";
@@ -0,0 +1,17 @@
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("./repository"), exports);
@@ -0,0 +1,6 @@
1
+ import { Id } from "../core";
2
+ export interface Repository<T, ID = Id> {
3
+ get(id: ID): Promise<T | null>;
4
+ save(aggregate: T): Promise<void>;
5
+ delete(id: ID): Promise<void>;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes