ddd-node 14.0.1 → 15.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.
@@ -1,9 +1,8 @@
1
1
  import { SnowflakeOpts } from "nodejs-snowflake";
2
2
  import { IIdService } from "../interface";
3
- export declare class SnowflakeIdService implements IIdService<string> {
3
+ export declare class SnowflakeIdService implements IIdService {
4
4
  private _snowflake;
5
5
  constructor(options?: SnowflakeOpts);
6
6
  validateValue(value: string): void;
7
7
  generateValue(): string;
8
- compareValue(v1: string, v2: string): boolean;
9
8
  }
@@ -7,7 +7,4 @@ export class SnowflakeIdService {
7
7
  generateValue() {
8
8
  return this._snowflake.getUniqueID().toString(16);
9
9
  }
10
- compareValue(v1, v2) {
11
- return v1 === v2;
12
- }
13
10
  }
@@ -1,6 +1,5 @@
1
1
  import { IIdService } from "../interface";
2
- export declare class Uuid4Service implements IIdService<string> {
2
+ export declare class Uuid4Service implements IIdService {
3
3
  validateValue(value: string): void;
4
4
  generateValue(): string;
5
- compareValue(v1: string, v2: string): boolean;
6
5
  }
@@ -11,7 +11,4 @@ export class Uuid4Service {
11
11
  generateValue() {
12
12
  return v4();
13
13
  }
14
- compareValue(v1, v2) {
15
- return v1 === v2;
16
- }
17
14
  }
@@ -1,8 +1,6 @@
1
- import { IId, IIdService } from "./interface";
2
- export declare class Id<T = any> implements IId<T> {
3
- private _service;
1
+ export declare class Id {
4
2
  private _value;
5
- constructor(service: IIdService<T>, idOrValue?: Id<T> | T);
6
- get value(): T;
7
- equals(id: Id<T>): boolean;
3
+ constructor(idOrValue: Id | string);
4
+ get value(): string;
5
+ equals(id: Id): boolean;
8
6
  }
@@ -1,20 +1,11 @@
1
1
  export class Id {
2
- constructor(service, idOrValue) {
3
- this._service = service;
4
- if (idOrValue) {
5
- if (idOrValue instanceof Id)
6
- this._value = idOrValue.value;
7
- else
8
- this._value = idOrValue;
9
- }
10
- else
11
- this._value = this._service.generateValue();
12
- this._service.validateValue(this._value);
2
+ constructor(idOrValue) {
3
+ this._value = idOrValue instanceof Id ? idOrValue.value : idOrValue;
13
4
  }
14
5
  get value() {
15
6
  return this._value;
16
7
  }
17
8
  equals(id) {
18
- return this._service.compareValue(id._value, this._value);
9
+ return id._value === this._value;
19
10
  }
20
11
  }
@@ -1,10 +1,4 @@
1
- export interface IId<T = any> {
2
- value: T;
3
- equals(id: IId<T>): boolean;
4
- }
5
- export type IdValueOf<T extends IId> = T extends IId<infer V> ? V : never;
6
- export interface IIdService<T = any> {
7
- validateValue(value: T): void;
8
- generateValue(): T;
9
- compareValue(v1: T, v2: T): boolean;
1
+ export interface IIdService {
2
+ validateValue(value: string): void;
3
+ generateValue(): string;
10
4
  }
@@ -19,7 +19,7 @@ export declare class EventBase<P extends Props> extends MessageBase<P> {
19
19
  static newEvent<T extends AnyEvent>(this: EventClassWithTypedConstructor<T>, source: EventSource, props: PropsOf<T>, context?: MessageContext, timestamp?: number): T;
20
20
  getSource(): Readonly<{
21
21
  aggregate: string;
22
- id: Id<any>;
22
+ id: Id;
23
23
  version: number;
24
24
  }>;
25
25
  getEventType(): string;
@@ -3,10 +3,9 @@ import { ModelBase, Props } from "./model";
3
3
  export declare class ModelWithId<P extends Props> extends ModelBase<P> {
4
4
  protected readonly _id: Id;
5
5
  constructor(id: Id);
6
- static idService(): import("../id").IIdService<any>;
7
- static id<T = any>(id?: Id<T> | T): Id<any>;
8
- id(): Id<any>;
6
+ static idService(): import("../id").IIdService;
7
+ static id(id?: Id | string): Id;
8
+ id(): Id;
9
9
  hasId(id: Id): boolean;
10
- rawId(): any;
11
10
  }
12
11
  export type AnyModelWithId = ModelWithId<Props>;
@@ -11,7 +11,7 @@ export class ModelWithId extends ModelBase {
11
11
  }
12
12
  static id(id) {
13
13
  const idService = this.idService();
14
- return new Id(idService, id);
14
+ return new Id(id ?? idService.generateValue());
15
15
  }
16
16
  id() {
17
17
  return this._id;
@@ -19,7 +19,4 @@ export class ModelWithId extends ModelBase {
19
19
  hasId(id) {
20
20
  return this._id.equals(id);
21
21
  }
22
- rawId() {
23
- return this._id.value;
24
- }
25
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-node",
3
- "version": "14.0.1",
3
+ "version": "15.0.0",
4
4
  "type": "module",
5
5
  "description": "Domain Driven Design base for NodeJs",
6
6
  "main": "dist/index.js",