@woltz/rich-domain 1.2.0 → 1.2.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/aggregate-changes.d.ts +164 -0
  3. package/dist/aggregate-changes.d.ts.map +1 -0
  4. package/dist/aggregate-changes.js +281 -0
  5. package/dist/aggregate-changes.js.map +1 -0
  6. package/dist/base-entity.d.ts +32 -8
  7. package/dist/base-entity.d.ts.map +1 -1
  8. package/dist/base-entity.js +117 -86
  9. package/dist/base-entity.js.map +1 -1
  10. package/dist/criteria.d.ts +3 -3
  11. package/dist/criteria.d.ts.map +1 -1
  12. package/dist/criteria.js.map +1 -1
  13. package/dist/crypto.d.ts +3 -0
  14. package/dist/crypto.d.ts.map +1 -0
  15. package/dist/crypto.js +29 -0
  16. package/dist/crypto.js.map +1 -0
  17. package/dist/entity-changes.d.ts +84 -0
  18. package/dist/entity-changes.d.ts.map +1 -0
  19. package/dist/entity-changes.js +135 -0
  20. package/dist/entity-changes.js.map +1 -0
  21. package/dist/entity-schema-registry.d.ts +148 -0
  22. package/dist/entity-schema-registry.d.ts.map +1 -0
  23. package/dist/entity-schema-registry.js +219 -0
  24. package/dist/entity-schema-registry.js.map +1 -0
  25. package/dist/history-tracker.d.ts +97 -0
  26. package/dist/history-tracker.d.ts.map +1 -0
  27. package/dist/history-tracker.js +805 -0
  28. package/dist/history-tracker.js.map +1 -0
  29. package/dist/id.d.ts +11 -10
  30. package/dist/id.d.ts.map +1 -1
  31. package/dist/id.js +4 -28
  32. package/dist/id.js.map +1 -1
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +1 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/mapper.d.ts +1 -1
  38. package/dist/mapper.d.ts.map +1 -1
  39. package/dist/mapper.js.map +1 -1
  40. package/dist/repository/base-repository.d.ts +6 -32
  41. package/dist/repository/base-repository.d.ts.map +1 -1
  42. package/dist/repository/base-repository.js +0 -27
  43. package/dist/repository/base-repository.js.map +1 -1
  44. package/dist/repository/unit-of-work.d.ts +0 -25
  45. package/dist/repository/unit-of-work.d.ts.map +1 -1
  46. package/dist/repository/unit-of-work.js +0 -25
  47. package/dist/repository/unit-of-work.js.map +1 -1
  48. package/dist/types/change-tracker.d.ts +186 -0
  49. package/dist/types/change-tracker.d.ts.map +1 -0
  50. package/dist/types/change-tracker.js +2 -0
  51. package/dist/types/change-tracker.js.map +1 -0
  52. package/dist/types/criteria.d.ts +5 -1
  53. package/dist/types/criteria.d.ts.map +1 -1
  54. package/dist/types/history-tracker.d.ts +11 -0
  55. package/dist/types/history-tracker.d.ts.map +1 -1
  56. package/dist/types/utils.d.ts +0 -1
  57. package/dist/types/utils.d.ts.map +1 -1
  58. package/dist/validation-error.d.ts.map +1 -1
  59. package/dist/validation-error.js +0 -3
  60. package/dist/validation-error.js.map +1 -1
  61. package/dist/value-object.d.ts +57 -8
  62. package/dist/value-object.d.ts.map +1 -1
  63. package/dist/value-object.js +49 -21
  64. package/dist/value-object.js.map +1 -1
  65. package/package.json +2 -1
  66. package/src/aggregate-changes.ts +335 -0
  67. package/src/base-entity.ts +140 -100
  68. package/src/criteria.ts +2 -1
  69. package/src/crypto.ts +31 -0
  70. package/src/entity-changes.ts +151 -0
  71. package/src/entity-schema-registry.ts +275 -0
  72. package/src/history-tracker.ts +1114 -0
  73. package/src/id.ts +17 -26
  74. package/src/index.ts +1 -0
  75. package/src/mapper.ts +4 -1
  76. package/src/repository/base-repository.ts +6 -37
  77. package/src/repository/unit-of-work.ts +0 -25
  78. package/src/types/change-tracker.ts +221 -0
  79. package/src/types/criteria.ts +6 -1
  80. package/src/types/history-tracker.ts +13 -0
  81. package/src/types/utils.ts +0 -9
  82. package/src/validation-error.ts +0 -4
  83. package/src/value-object.ts +84 -23
  84. package/tests/aggregate-changes.test.ts +284 -0
  85. package/tests/criteria.test.ts +122 -161
  86. package/tests/entity-equality.test.ts +38 -61
  87. package/tests/entity-schema-registry.test.ts +382 -0
  88. package/tests/entity-validation.test.ts +7 -94
  89. package/tests/history-tracker.spec.ts +349 -617
  90. package/tests/id.test.ts +41 -44
  91. package/tests/load-test/data.json +346041 -0
  92. package/tests/load-test/entities.ts +97 -0
  93. package/tests/load-test/generate-data.ts +81 -0
  94. package/tests/load-test/lead-to-domain.mapper.ts +24 -0
  95. package/tests/load-test/load.test.ts +38 -0
  96. package/tests/repository.test.ts +30 -54
  97. package/tests/to-json.test.ts +14 -18
  98. package/tests/utils.ts +138 -102
  99. package/tests/value-objects.test.ts +57 -29
  100. package/dist/deep-proxy.d.ts +0 -36
  101. package/dist/deep-proxy.d.ts.map +0 -1
  102. package/dist/deep-proxy.js +0 -384
  103. package/dist/deep-proxy.js.map +0 -1
  104. package/src/deep-proxy.ts +0 -447
  105. package/tests/entity.test.ts +0 -33
package/tests/id.test.ts CHANGED
@@ -111,7 +111,8 @@ describe("Entity with Id Class", () => {
111
111
  id: new Id(), // No value = new
112
112
  title: "New Post",
113
113
  content: "Content",
114
- likes: 0,
114
+ comments: [],
115
+ published: false,
115
116
  });
116
117
 
117
118
  expect(post.isNew()).toBe(true);
@@ -122,15 +123,17 @@ describe("Entity with Id Class", () => {
122
123
  const post1 = new Post({
123
124
  id: new Id(),
124
125
  title: "Post 1",
126
+ comments: [],
127
+ published: false,
125
128
  content: "Content",
126
- likes: 0,
127
129
  });
128
130
 
129
131
  const post2 = new Post({
130
132
  id: new Id(),
131
133
  title: "Post 2",
134
+ comments: [],
135
+ published: false,
132
136
  content: "Content",
133
- likes: 0,
134
137
  });
135
138
 
136
139
  expect(post1.id.value).not.toBe(post2.id.value);
@@ -143,7 +146,8 @@ describe("Entity with Id Class", () => {
143
146
  id: Id.create(),
144
147
  title: "New Post",
145
148
  content: "Content",
146
- likes: 0,
149
+ comments: [],
150
+ published: false,
147
151
  });
148
152
 
149
153
  expect(post.isNew()).toBe(true);
@@ -156,7 +160,8 @@ describe("Entity with Id Class", () => {
156
160
  id: new Id("existing-post-id"), // Value provided = not new
157
161
  title: "Existing Post",
158
162
  content: "Content",
159
- likes: 10,
163
+ comments: [],
164
+ published: false,
160
165
  });
161
166
 
162
167
  expect(post.isNew()).toBe(false);
@@ -168,7 +173,8 @@ describe("Entity with Id Class", () => {
168
173
  id: Id.from("existing-post-id"),
169
174
  title: "Existing Post",
170
175
  content: "Content",
171
- likes: 10,
176
+ comments: [],
177
+ published: false,
172
178
  });
173
179
 
174
180
  expect(post.isNew()).toBe(false);
@@ -180,8 +186,9 @@ describe("Entity with Id Class", () => {
180
186
  const post = new Post({
181
187
  id: new Id("post-123"),
182
188
  title: "Test Post",
189
+ comments: [],
190
+ published: false,
183
191
  content: "Content",
184
- likes: 5,
185
192
  });
186
193
 
187
194
  const json = post.toJson();
@@ -192,7 +199,7 @@ describe("Entity with Id Class", () => {
192
199
  });
193
200
 
194
201
  describe("Id Comparison in Arrays", () => {
195
- it("should detect changes in arrays using Id", (done) => {
202
+ it("should detect changes in arrays using Id", () => {
196
203
  const user = new User({
197
204
  id: new Id("user-1"),
198
205
  name: "John",
@@ -201,19 +208,8 @@ describe("Entity with Id Class", () => {
201
208
  address: new Address({
202
209
  street: "Main St",
203
210
  city: "NYC",
204
- zipCode: "10001",
205
211
  }),
206
- comments: [],
207
- });
208
-
209
- user.subscribe({
210
- posts: {
211
- onChange: ({ toCreate, toDelete }) => {
212
- expect(toCreate).toHaveLength(2);
213
- expect(toDelete).toHaveLength(0);
214
- done();
215
- },
216
- },
212
+ tags: [],
217
213
  });
218
214
 
219
215
  user.addManyPosts([
@@ -221,18 +217,26 @@ describe("Entity with Id Class", () => {
221
217
  id: new Id(),
222
218
  title: "Post 1",
223
219
  content: "Content 1",
224
- likes: 0,
220
+ comments: [],
221
+ published: false,
225
222
  }),
226
223
  new Post({
227
224
  id: new Id(),
228
225
  title: "Post 2",
229
226
  content: "Content 2",
230
- likes: 0,
227
+ comments: [],
228
+ published: false,
231
229
  }),
232
230
  ]);
231
+
232
+ const changes = user.getTypedChanges();
233
+
234
+ console.dir(changes.creates(), { depth: null });
235
+
236
+ expect(changes.creates().length).toBe(2);
233
237
  });
234
238
 
235
- it("should track deletes correctly with Id", (done) => {
239
+ it("should track deletes correctly with Id", () => {
236
240
  const postId = new Id("post-to-delete");
237
241
 
238
242
  const user = new User({
@@ -244,29 +248,24 @@ describe("Entity with Id Class", () => {
244
248
  id: postId,
245
249
  title: "Post 1",
246
250
  content: "Content 1",
247
- likes: 0,
251
+ comments: [],
252
+ published: false,
248
253
  }),
249
254
  ],
250
255
  address: new Address({
251
256
  street: "Main St",
252
257
  city: "NYC",
253
- zipCode: "10001",
254
258
  }),
255
- comments: [],
259
+ tags: [],
256
260
  });
257
261
 
258
- user.subscribe({
259
- posts: {
260
- onChange: ({ toCreate, toDelete }) => {
261
- expect(toCreate).toHaveLength(0);
262
- expect(toDelete).toHaveLength(1);
263
- expect(toDelete[0].id.value).toBe(postId.value);
264
- done();
265
- },
266
- },
267
- });
262
+ user.removePost(postId);
263
+
264
+ const changes = user.getTypedChanges();
268
265
 
269
- user.removePostById(postId.value);
266
+ expect(changes.deletes()).toHaveLength(1);
267
+ expect(changes.creates()).toHaveLength(0);
268
+ expect(changes.deletes()[0].id).toBe(postId.value);
270
269
  });
271
270
  });
272
271
  });
@@ -285,9 +284,8 @@ describe("Aggregate with Id Class", () => {
285
284
  address: new Address({
286
285
  street: "Main St",
287
286
  city: "NYC",
288
- zipCode: "10001",
289
287
  }),
290
- comments: [],
288
+ tags: [],
291
289
  });
292
290
 
293
291
  expect(user.isNew()).toBe(true);
@@ -302,9 +300,8 @@ describe("Aggregate with Id Class", () => {
302
300
  address: new Address({
303
301
  street: "Main St",
304
302
  city: "NYC",
305
- zipCode: "10001",
306
303
  }),
307
- comments: [],
304
+ tags: [],
308
305
  });
309
306
 
310
307
  expect(user.isNew()).toBe(false);
@@ -319,15 +316,15 @@ describe("Aggregate with Id Class", () => {
319
316
  new Post({
320
317
  id: new Id("post-1"),
321
318
  title: "Post 1",
319
+ comments: [],
322
320
  content: "Content",
323
- likes: 0,
321
+ published: false,
324
322
  }),
325
323
  ],
326
- comments: [],
324
+ tags: [],
327
325
  address: new Address({
328
326
  street: "Main St",
329
327
  city: "NYC",
330
- zipCode: "10001",
331
328
  }),
332
329
  });
333
330