ddd-node 7.0.0 → 8.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.
@@ -20,8 +20,8 @@ export declare class Aggregate<Props extends object> extends AggregateBase<Props
20
20
  static newAggregate<T extends AnyAggregate>(this: AggregateClassWithTypedConstructor<T>, props: PropsOf<T>, id?: Id): T;
21
21
  get version(): number;
22
22
  get events(): AnyEvent[];
23
- recordEvent<E extends AnyEvent>(event: E): void;
24
- recordEvent<E extends AnyEvent>(eventClass: EventClass<E>, props: PropsOf<E>): void;
23
+ protected recordEvent<E extends AnyEvent>(event: E): void;
24
+ protected recordEvent<E extends AnyEvent>(eventClass: EventClass<E>, props: PropsOf<E>): void;
25
25
  clearEvents(): void;
26
26
  }
27
27
  export interface SnapshotMetadata extends AggregateBaseMetadata {
@@ -27,7 +27,7 @@ class Aggregate extends AggregateBase {
27
27
  }
28
28
  static newAggregate(props, id) {
29
29
  return new this({
30
- id: id !== null && id !== void 0 ? id : id_1.Id.unique(),
30
+ id: id !== null && id !== void 0 ? id : id_1.Uuid4.new(),
31
31
  version: 0,
32
32
  }, props);
33
33
  }
@@ -61,7 +61,7 @@ class AggregateES extends AggregateBase {
61
61
  }
62
62
  static newStream(id) {
63
63
  return new this({
64
- id: id !== null && id !== void 0 ? id : id_1.Id.unique(),
64
+ id: id !== null && id !== void 0 ? id : id_1.Uuid4.new(),
65
65
  version: 0,
66
66
  });
67
67
  }
@@ -9,7 +9,7 @@ class Command extends message_1.Message {
9
9
  }
10
10
  static newCommand(props, context) {
11
11
  return new this({
12
- id: id_1.Id.unique(),
12
+ id: id_1.Uuid4.new(),
13
13
  timestamp: Date.now(),
14
14
  context,
15
15
  }, props);
@@ -10,7 +10,7 @@ class Entity extends model_1.Model {
10
10
  }
11
11
  static newEntity(props) {
12
12
  return new this({
13
- id: id_1.Id.unique(),
13
+ id: id_1.Uuid4.new(),
14
14
  }, props);
15
15
  }
16
16
  get id() {
@@ -10,7 +10,7 @@ class Event extends message_1.Message {
10
10
  }
11
11
  static newEvent(source, props, context) {
12
12
  return new this({
13
- id: id_1.Id.unique(),
13
+ id: id_1.Uuid4.new(),
14
14
  timestamp: Date.now(),
15
15
  source,
16
16
  context,
package/dist/core/id.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  export declare class Id {
2
2
  private _value;
3
- private constructor();
4
- static unique(): Id;
5
- static from(value: string): Id;
3
+ constructor(value: string);
6
4
  get value(): string;
7
5
  equals(id: Id): boolean;
8
6
  }
7
+ export declare class Uuid4 extends Id {
8
+ private constructor();
9
+ static new(): Uuid4;
10
+ static from(value: string): Uuid4;
11
+ static validate(value: string): boolean;
12
+ }
package/dist/core/id.js CHANGED
@@ -1,21 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Id = void 0;
3
+ exports.Uuid4 = exports.Id = void 0;
4
4
  const uuid_1 = require("uuid");
5
5
  class Id {
6
6
  constructor(value) {
7
7
  this._value = value;
8
8
  }
9
- static unique() {
10
- const value = (0, uuid_1.v4)();
11
- return new Id(value);
12
- }
13
- static from(value) {
14
- const isUUID4 = (0, uuid_1.validate)(value) && (0, uuid_1.version)(value) === 4;
15
- if (!isUUID4)
16
- throw new Error("Invalid uuid version 4 value");
17
- return new Id(value);
18
- }
19
9
  get value() {
20
10
  return this._value;
21
11
  }
@@ -24,3 +14,22 @@ class Id {
24
14
  }
25
15
  }
26
16
  exports.Id = Id;
17
+ class Uuid4 extends Id {
18
+ constructor(value) {
19
+ super(value);
20
+ }
21
+ static new() {
22
+ const newValue = (0, uuid_1.v4)();
23
+ return this.from(newValue);
24
+ }
25
+ static from(value) {
26
+ this.validate(value);
27
+ return new Uuid4(value);
28
+ }
29
+ static validate(value) {
30
+ const isUuid = (0, uuid_1.validate)(value);
31
+ const isV4 = (0, uuid_1.version)(value) === 4;
32
+ return isUuid && isV4;
33
+ }
34
+ }
35
+ exports.Uuid4 = Uuid4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-node",
3
- "version": "7.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "Domain Driven Design base for NodeJs",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {