law-common 10.28.2-beta.10 → 10.28.2-beta.11

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.
@@ -36,4 +36,7 @@ export declare class EntityModelRelationHelper {
36
36
  addEntity<T extends EntityEnum | VirtualEntityEnum>(entity: EnumEntityType<T>, entityEnum: T, config?: {
37
37
  populateRelations?: boolean;
38
38
  }): void;
39
+ updateEntityModel<T extends EntityEnum | VirtualEntityEnum>(entityModel: BaseEntityModel<T>, config?: {
40
+ populateRelations?: boolean;
41
+ }): void;
39
42
  }
@@ -200,5 +200,14 @@ class EntityModelRelationHelper {
200
200
  }
201
201
  this.addEntityModel(this.fromEntityToEntityModel(entity, entityEnum), config);
202
202
  }
203
+ updateEntityModel(entityModel, config = { populateRelations: false }) {
204
+ const entityEnum = entityModel.entityName;
205
+ this.entityModelIndexMap[entityEnum] = this.entityModelIndexMap[entityEnum] || {};
206
+ // @ts-ignore
207
+ this.entityModelIndexMap[entityEnum][entityModel.id] = entityModel;
208
+ if (config.populateRelations) {
209
+ this.populateRelationsByEntityModel(entityModel);
210
+ }
211
+ }
203
212
  }
204
213
  exports.EntityModelRelationHelper = EntityModelRelationHelper;
@@ -0,0 +1,10 @@
1
+ interface ComparableObject {
2
+ [key: string]: any;
3
+ }
4
+ declare class ObjectComparator {
5
+ private incoming;
6
+ private existing;
7
+ constructor(incoming: ComparableObject, existing: ComparableObject);
8
+ compare(): ComparableObject;
9
+ private deepDiff;
10
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ class ObjectComparator {
3
+ constructor(incoming, existing) {
4
+ this.incoming = incoming;
5
+ this.existing = existing;
6
+ }
7
+ compare() {
8
+ return this.deepDiff(this.incoming, this.existing);
9
+ }
10
+ deepDiff(a, b) {
11
+ // Handle null/undefined cases
12
+ if (a == null && b == null) {
13
+ return undefined;
14
+ }
15
+ if (a == null || b == null) {
16
+ return a;
17
+ }
18
+ // Handle primitives (loose equality)
19
+ if (typeof a !== "object") {
20
+ return a == b ? undefined : a;
21
+ }
22
+ // a is object or array
23
+ if (Array.isArray(a)) {
24
+ // Handle as array
25
+ const diffArr = new Array(a.length);
26
+ let hasDiff = false;
27
+ for (let i = 0; i < a.length; i++) {
28
+ const subB = Array.isArray(b) && i < b.length ? b[i] : undefined;
29
+ const subDiff = this.deepDiff(a[i], subB);
30
+ if (subDiff !== undefined) {
31
+ diffArr[i] = subDiff;
32
+ hasDiff = true;
33
+ }
34
+ }
35
+ return hasDiff ? diffArr : undefined;
36
+ }
37
+ else {
38
+ // Handle as object
39
+ const diff = {};
40
+ let hasDiff = false;
41
+ for (const key of Object.keys(a)) {
42
+ const subDiff = this.deepDiff(a[key], b === null || b === void 0 ? void 0 : b[key]);
43
+ if (subDiff !== undefined) {
44
+ diff[key] = subDiff;
45
+ hasDiff = true;
46
+ }
47
+ }
48
+ return hasDiff ? diff : undefined;
49
+ }
50
+ }
51
+ }
52
+ // // Comprehensive Usage Examples
53
+ // // Example 1: Simple object with primitive differences
54
+ // console.log("Example 1: Simple object");
55
+ // const incoming1 = { name: "Alice", age: 30, city: "New York" };
56
+ // const existing1 = { name: "Bob", age: 30, city: "Boston" };
57
+ // const comparator1 = new ObjectComparator(incoming1, existing1);
58
+ // console.log(comparator1.compare()); // Output: { name: 'Alice', city: 'New York' }
59
+ // // Example 2: Nested objects
60
+ // console.log("Example 2: Nested objects");
61
+ // const incoming2 = {
62
+ // user: { id: 1, profile: { email: "alice@example.com", phone: "123-456" } },
63
+ // settings: { theme: "dark", notifications: true },
64
+ // };
65
+ // const existing2 = {
66
+ // user: { id: 1, profile: { email: "bob@example.com" } },
67
+ // settings: { theme: "light" },
68
+ // };
69
+ // const comparator2 = new ObjectComparator(incoming2, existing2);
70
+ // console.log(comparator2.compare());
71
+ // // Output: {
72
+ // // user: { profile: { email: 'alice@example.com', phone: '123-456' } },
73
+ // // settings: { theme: 'dark', notifications: true }
74
+ // // }
75
+ // // Example 3: Array of primitives
76
+ // console.log("Example 3: Array of primitives");
77
+ // const incoming3 = { scores: [95, 87, 100] };
78
+ // const existing3 = { scores: [80, 87, 90] };
79
+ // const comparator3 = new ObjectComparator(incoming3, existing3);
80
+ // console.log(comparator3.compare()); // Output: { scores: [95, undefined, 100] }
81
+ // // Example 4: Array of objects
82
+ // console.log("Example 4: Array of objects");
83
+ // const incoming4 = {
84
+ // items: [
85
+ // { id: 1, name: "Item A", price: 10 },
86
+ // { id: 2, name: "Item B", price: 20 },
87
+ // { id: 3, name: "Item C", price: 30 },
88
+ // ],
89
+ // };
90
+ // const existing4 = {
91
+ // items: [
92
+ // { id: 1, name: "Item A", price: 15 },
93
+ // { id: 2, name: "Item X", price: 20 },
94
+ // ],
95
+ // };
96
+ // const comparator4 = new ObjectComparator(incoming4, existing4);
97
+ // console.log(comparator4.compare());
98
+ // // Output: {
99
+ // // items: [
100
+ // // { price: 10 },
101
+ // // { name: 'Item B' },
102
+ // // { id: 3, name: 'Item C', price: 30 }
103
+ // // ]
104
+ // // }
105
+ // // Example 5: Mixed structure with missing properties and nulls
106
+ // console.log("Example 5: Mixed with nulls and missing");
107
+ // const incoming5 = {
108
+ // data: {
109
+ // value: null,
110
+ // list: [1, 2, { nested: "hello" }],
111
+ // extra: "new",
112
+ // },
113
+ // };
114
+ // const existing5 = {
115
+ // data: {
116
+ // value: 42,
117
+ // list: [1, 3],
118
+ // },
119
+ // };
120
+ // const comparator5 = new ObjectComparator(incoming5, existing5);
121
+ // console.log(comparator5.compare());
122
+ // // Output: {
123
+ // // data: {
124
+ // // value: null,
125
+ // // list: [undefined, 2, { nested: 'hello' }],
126
+ // // extra: 'new'
127
+ // // }
128
+ // // }
129
+ // // Example 6: No differences
130
+ // console.log("Example 6: No differences");
131
+ // const incoming6 = { a: 1, b: { c: [true] } };
132
+ // const existing6 = { a: 1, b: { c: [true] } };
133
+ // const comparator6 = new ObjectComparator(incoming6, existing6);
134
+ // console.log(comparator6.compare()); // Output: {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "law-common",
3
- "version": "10.28.2-beta.10",
3
+ "version": "10.28.2-beta.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [