ddd-node 24.1.1 → 24.1.2

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.
@@ -9,6 +9,7 @@ export declare class EnumBase extends ModelBase<EnumProps> {
9
9
  static values(): EnumBase[];
10
10
  constructor(value: EnumValue);
11
11
  value: EnumValue;
12
+ valueOf(): EnumValue;
12
13
  }
13
14
  export type AnyEnum = EnumBase;
14
15
  export interface EnumClass<T extends AnyEnum = AnyEnum, Arguments extends unknown[] = any[]> extends Class<T, Arguments>, ClassStatic<typeof EnumBase> {
@@ -19,6 +19,9 @@ let EnumBase = class EnumBase extends model_1.ModelBase {
19
19
  super();
20
20
  this.initializeProps({ value });
21
21
  }
22
+ valueOf() {
23
+ return this.value;
24
+ }
22
25
  };
23
26
  exports.EnumBase = EnumBase;
24
27
  __decorate([
@@ -6,6 +6,8 @@ export declare class ValueObjectBase<P extends Props> extends ModelBase<P> {
6
6
  props(): P;
7
7
  equals<V extends AnyValueObject>(vo: V): boolean;
8
8
  with(props: Partial<P>): typeof this;
9
+ getEqualityValue(): string;
10
+ getEqualityObject(): any;
9
11
  }
10
12
  export type AnyValueObject = ValueObjectBase<Props>;
11
13
  export interface ValueObjectClass<T extends AnyValueObject = AnyValueObject> extends Class<T>, ClassStatic<typeof ValueObjectBase<PropsOf<T>>> {
@@ -11,11 +11,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
+ var ValueObjectBase_1;
14
15
  Object.defineProperty(exports, "__esModule", { value: true });
15
16
  exports.ValueObjectBase = void 0;
16
17
  const lodash_1 = __importDefault(require("lodash"));
17
18
  const model_1 = require("../../model");
18
- let ValueObjectBase = class ValueObjectBase extends model_1.ModelBase {
19
+ let ValueObjectBase = ValueObjectBase_1 = class ValueObjectBase extends model_1.ModelBase {
19
20
  constructor(props) {
20
21
  super();
21
22
  this.initializeProps(props);
@@ -25,16 +26,36 @@ let ValueObjectBase = class ValueObjectBase extends model_1.ModelBase {
25
26
  }
26
27
  equals(vo) {
27
28
  const equalsType = vo instanceof this.constructor;
28
- const equalsValue = JSON.stringify(vo.props()) === JSON.stringify(this.props());
29
+ const equalsValue = this.getEqualityValue() === vo.getEqualityValue();
29
30
  return equalsType && equalsValue;
30
31
  }
31
32
  with(props) {
32
33
  const newProps = lodash_1.default.merge(this.props(), props);
33
34
  return new this.constructor(newProps);
34
35
  }
36
+ getEqualityValue() {
37
+ return JSON.stringify(this.getEqualityObject());
38
+ }
39
+ getEqualityObject() {
40
+ const result = {};
41
+ const props = this.props();
42
+ const valueOf = (v) => v instanceof ValueObjectBase_1 ? v.getEqualityObject() : v;
43
+ for (let [key, value] of Object.entries(props)) {
44
+ if (Array.isArray(value)) {
45
+ result[key] = value.map((v) => valueOf(v));
46
+ result[key].sort((a, b) => {
47
+ const stringValueOf = (v) => JSON.stringify(v);
48
+ return stringValueOf(a).localeCompare(stringValueOf(b));
49
+ });
50
+ continue;
51
+ }
52
+ result[key] = valueOf(value);
53
+ }
54
+ return result;
55
+ }
35
56
  };
36
57
  exports.ValueObjectBase = ValueObjectBase;
37
- exports.ValueObjectBase = ValueObjectBase = __decorate([
58
+ exports.ValueObjectBase = ValueObjectBase = ValueObjectBase_1 = __decorate([
38
59
  (0, model_1.Mutable)(false),
39
60
  __metadata("design:paramtypes", [Object])
40
61
  ], ValueObjectBase);
@@ -1,4 +1,4 @@
1
- import { Class } from "type-fest";
1
+ import { AbstractClass, Class } from "type-fest";
2
2
  import { ModelId, ModelName, ModelVersion, PropsMap, PropsValidator, StaticValuesMap } from "../meta";
3
3
  import { ClassStatic } from "../../types";
4
4
  import { ModelDescriptor } from "./model-descriptor";
@@ -36,3 +36,5 @@ export type AnyModel = ModelBase<Props>;
36
36
  export type PropsOf<T extends AnyModel> = T extends ModelBase<infer P extends Props> ? P : never;
37
37
  export interface ModelClass<T extends AnyModel = AnyModel> extends Class<T>, ClassStatic<typeof ModelBase<PropsOf<T>>> {
38
38
  }
39
+ export interface AbstractModelClass<T extends AnyModel = AnyModel> extends AbstractClass<T>, ClassStatic<typeof ModelBase<PropsOf<T>>> {
40
+ }
@@ -1,2 +1,2 @@
1
- import { ModelClass } from "../core";
2
- export declare const Mutable: (mutable?: boolean) => (target: ModelClass) => void;
1
+ import { AbstractModelClass, ModelClass } from "../core";
2
+ export declare const Mutable: (mutable?: boolean) => <T extends ModelClass<import("../core").AnyModel> | AbstractModelClass<import("../core").AnyModel>>(target: T) => void;
package/dist/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"ddd-node","version":"24.1.1","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","reflect-metadata":"^0.1.13","tsc-alias":"^1.8.8","type-fest":"^4.20.1","uuid":"^9.0.1"}}
1
+ {"name":"ddd-node","version":"24.1.2","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","reflect-metadata":"^0.1.13","tsc-alias":"^1.8.8","type-fest":"^4.20.1","uuid":"^9.0.1"}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-node",
3
- "version": "24.1.1",
3
+ "version": "24.1.2",
4
4
  "description": "Domain Driven Design base for NodeJs",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",