ddd-node 6.1.0 → 8.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.
@@ -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;
@@ -1,12 +1,12 @@
1
1
  import { Class } from "../types/class";
2
2
  export declare class Model<Props extends object> {
3
- protected _props?: Props;
3
+ protected _props: Props;
4
4
  constructor(props?: Props);
5
- static isModel(obj: object): boolean;
6
- protected setProps(props: Props): void;
5
+ static isModel(obj: object): obj is AnyModel;
6
+ protected initializeProps(props: Props): void;
7
7
  validate(): void;
8
8
  get type(): `${string}#${string}`;
9
- props(): Props | undefined;
9
+ props(): Props;
10
10
  }
11
11
  export type AnyModel = Model<object>;
12
12
  export type PropsOf<T> = T extends Model<infer P> ? P : never;
@@ -8,12 +8,13 @@ const lodash_1 = __importDefault(require("lodash"));
8
8
  const metadata_1 = require("./metadata");
9
9
  class Model {
10
10
  constructor(props) {
11
- this._props = props;
11
+ if (props)
12
+ this.initializeProps(props);
12
13
  }
13
14
  static isModel(obj) {
14
15
  return obj instanceof Model;
15
16
  }
16
- setProps(props) {
17
+ initializeProps(props) {
17
18
  if (!this._props) {
18
19
  this._props = props;
19
20
  this.validate();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-node",
3
- "version": "6.1.0",
3
+ "version": "8.0.0",
4
4
  "description": "Domain Driven Design base for NodeJs",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {