@woltz/rich-domain 1.2.4 → 1.3.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 (94) hide show
  1. package/dist/aggregate-changes.d.ts +56 -14
  2. package/dist/aggregate-changes.d.ts.map +1 -1
  3. package/dist/aggregate-changes.js +103 -23
  4. package/dist/aggregate-changes.js.map +1 -1
  5. package/dist/base-entity.d.ts +1 -1
  6. package/dist/base-entity.d.ts.map +1 -1
  7. package/dist/base-entity.js +28 -13
  8. package/dist/base-entity.js.map +1 -1
  9. package/dist/change-tracker.d.ts +2 -1
  10. package/dist/change-tracker.d.ts.map +1 -1
  11. package/dist/change-tracker.js +61 -35
  12. package/dist/change-tracker.js.map +1 -1
  13. package/dist/criteria.d.ts +7 -15
  14. package/dist/criteria.d.ts.map +1 -1
  15. package/dist/criteria.js +105 -81
  16. package/dist/criteria.js.map +1 -1
  17. package/dist/domain-event-bus.js +4 -4
  18. package/dist/domain-event-bus.js.map +1 -1
  19. package/dist/domain-event.js +3 -0
  20. package/dist/domain-event.js.map +1 -1
  21. package/dist/entity-changes.js +1 -0
  22. package/dist/entity-changes.js.map +1 -1
  23. package/dist/entity-schema-registry.d.ts +137 -3
  24. package/dist/entity-schema-registry.d.ts.map +1 -1
  25. package/dist/entity-schema-registry.js +160 -7
  26. package/dist/entity-schema-registry.js.map +1 -1
  27. package/dist/exceptions.js +26 -1
  28. package/dist/exceptions.js.map +1 -1
  29. package/dist/id.js +2 -0
  30. package/dist/id.js.map +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/paginated-result.d.ts +4 -4
  34. package/dist/paginated-result.d.ts.map +1 -1
  35. package/dist/paginated-result.js +14 -19
  36. package/dist/paginated-result.js.map +1 -1
  37. package/dist/repository/unit-of-work.js +3 -7
  38. package/dist/repository/unit-of-work.js.map +1 -1
  39. package/dist/types/change-tracker.d.ts +30 -0
  40. package/dist/types/change-tracker.d.ts.map +1 -1
  41. package/dist/types/criteria.d.ts +1 -4
  42. package/dist/types/criteria.d.ts.map +1 -1
  43. package/dist/types/domain.d.ts +2 -1
  44. package/dist/types/domain.d.ts.map +1 -1
  45. package/dist/types/utils.d.ts +2 -2
  46. package/dist/utils/helpers.d.ts +1 -0
  47. package/dist/utils/helpers.d.ts.map +1 -1
  48. package/dist/utils/helpers.js +23 -0
  49. package/dist/utils/helpers.js.map +1 -1
  50. package/dist/validation-error.d.ts +15 -1
  51. package/dist/validation-error.d.ts.map +1 -1
  52. package/dist/validation-error.js +46 -3
  53. package/dist/validation-error.js.map +1 -1
  54. package/dist/value-object.d.ts +1 -1
  55. package/dist/value-object.d.ts.map +1 -1
  56. package/dist/value-object.js +30 -2
  57. package/dist/value-object.js.map +1 -1
  58. package/package.json +17 -3
  59. package/src/aggregate-changes.ts +133 -24
  60. package/src/base-entity.ts +22 -11
  61. package/src/change-tracker.ts +113 -54
  62. package/src/criteria.ts +151 -109
  63. package/src/entity-schema-registry.ts +256 -6
  64. package/src/index.ts +1 -1
  65. package/src/paginated-result.ts +21 -29
  66. package/src/types/change-tracker.ts +31 -0
  67. package/src/types/criteria.ts +1 -4
  68. package/src/types/domain.ts +2 -1
  69. package/src/types/utils.ts +2 -2
  70. package/src/utils/helpers.ts +28 -0
  71. package/src/validation-error.ts +54 -4
  72. package/src/value-object.ts +6 -1
  73. package/.versionrc.json +0 -21
  74. package/CHANGELOG.md +0 -163
  75. package/tests/aggregate-changes.test.ts +0 -284
  76. package/tests/criteria.test.ts +0 -716
  77. package/tests/depth/deep-tracking.test.ts +0 -554
  78. package/tests/domain-events.test.ts +0 -431
  79. package/tests/entity-equality.test.ts +0 -464
  80. package/tests/entity-schema-registry.test.ts +0 -382
  81. package/tests/entity-validation.test.ts +0 -252
  82. package/tests/history-tracker.spec.ts +0 -439
  83. package/tests/id.test.ts +0 -338
  84. package/tests/load-test/data.json +0 -347211
  85. package/tests/load-test/entities.ts +0 -97
  86. package/tests/load-test/generate-data.ts +0 -81
  87. package/tests/load-test/lead-to-domain.mapper.ts +0 -24
  88. package/tests/load-test/load.test.ts +0 -38
  89. package/tests/repository.test.ts +0 -635
  90. package/tests/to-json.test.ts +0 -99
  91. package/tests/utils.ts +0 -290
  92. package/tests/value-object-validation.test.ts +0 -219
  93. package/tests/value-objects.test.ts +0 -80
  94. package/tsconfig.json +0 -9
@@ -1,464 +0,0 @@
1
- import { Entity, Id } from "../src";
2
- import { Address, User } from "./utils";
3
-
4
- // ============================================================================
5
- // Tests
6
- // ============================================================================
7
-
8
- class Order extends Entity<{ id: Id; total: number; status: string }> {}
9
-
10
- describe("Entity Equality by ID", () => {
11
- describe("Basic Equality", () => {
12
- it("should be equal when entities have the same ID", () => {
13
- const id = Id.from("user-123");
14
- const user1 = new User({
15
- id,
16
- name: "John",
17
- email: "john@example.com",
18
- address: new Address({
19
- street: "Main St",
20
- city: "NYC",
21
- }),
22
- posts: [],
23
- tags: [],
24
- });
25
- const user2 = new User({
26
- id,
27
- name: "Jane",
28
- email: "jane@example.com",
29
- address: new Address({
30
- street: "Main St",
31
- city: "NYC",
32
- }),
33
- posts: [],
34
- tags: [],
35
- });
36
-
37
- expect(user1.equals(user2)).toBe(true);
38
- expect(user2.equals(user1)).toBe(true);
39
- });
40
-
41
- it("should be equal when comparing with same ID instance", () => {
42
- const id = Id.from("user-123");
43
- const user1 = new User({
44
- id,
45
- name: "John",
46
- email: "john@example.com",
47
- address: new Address({
48
- street: "Main St",
49
- city: "NYC",
50
- }),
51
- tags: [],
52
- posts: [],
53
- });
54
- const user2 = new User({
55
- id: Id.from("user-123"),
56
- name: "Jane",
57
- email: "jane@example.com",
58
- address: new Address({
59
- street: "Main St",
60
- city: "NYC",
61
- }),
62
- tags: [],
63
- posts: [],
64
- });
65
-
66
- expect(user1.equals(user2)).toBe(true);
67
- });
68
-
69
- it("should NOT be equal when entities have different IDs", () => {
70
- const user1 = new User({
71
- id: Id.from("user-1"),
72
- name: "John",
73
- email: "john@example.com",
74
- address: new Address({
75
- street: "Main St",
76
- city: "NYC",
77
- }),
78
- tags: [],
79
- posts: [],
80
- });
81
- const user2 = new User({
82
- id: Id.from("user-2"),
83
- name: "John",
84
- email: "john@example.com",
85
- address: new Address({
86
- street: "Main St",
87
- city: "NYC",
88
- }),
89
- tags: [],
90
- posts: [],
91
- });
92
-
93
- expect(user1.equals(user2)).toBe(false);
94
- expect(user2.equals(user1)).toBe(false);
95
- });
96
-
97
- it("should be equal to itself", () => {
98
- const user = new User({
99
- id: Id.from("user-123"),
100
- name: "John",
101
- email: "john@example.com",
102
- address: new Address({
103
- street: "Main St",
104
- city: "NYC",
105
- }),
106
- tags: [],
107
- posts: [],
108
- });
109
- expect(user.equals(user)).toBe(true);
110
- });
111
- });
112
-
113
- describe("Equality with ID objects", () => {
114
- it("should be equal when comparing with Id instance", () => {
115
- const id = Id.from("user-123");
116
- const user = new User({
117
- id,
118
- name: "John",
119
- email: "john@example.com",
120
- address: new Address({
121
- street: "Main St",
122
- city: "NYC",
123
- }),
124
- tags: [],
125
- posts: [],
126
- });
127
-
128
- expect(user.equals(id)).toBe(true);
129
- expect(user.equals(Id.from("user-123"))).toBe(true);
130
- });
131
-
132
- it("should NOT be equal when comparing with different Id", () => {
133
- const user = new User({
134
- id: Id.from("user-123"),
135
- name: "John",
136
- email: "john@example.com",
137
- address: new Address({
138
- street: "Main St",
139
- city: "NYC",
140
- }),
141
- tags: [],
142
- posts: [],
143
- });
144
-
145
- expect(user.equals(Id.from("user-456"))).toBe(false);
146
- });
147
- });
148
-
149
- describe("Equality with string IDs", () => {
150
- it("should be equal when comparing with string ID", () => {
151
- const user = new User({
152
- id: Id.from("user-123"),
153
- name: "John",
154
- email: "john@example.com",
155
- address: new Address({
156
- street: "Main St",
157
- city: "NYC",
158
- }),
159
- tags: [],
160
- posts: [],
161
- });
162
-
163
- expect(user.equals("user-123")).toBe(true);
164
- });
165
-
166
- it("should NOT be equal when comparing with different string ID", () => {
167
- const user = new User({
168
- id: Id.from("user-123"),
169
- name: "John",
170
- email: "john@example.com",
171
- address: new Address({
172
- street: "Main St",
173
- city: "NYC",
174
- }),
175
- tags: [],
176
- posts: [],
177
- });
178
-
179
- expect(user.equals("user-456")).toBe(false);
180
- });
181
- });
182
-
183
- describe("Edge Cases", () => {
184
- it("should return false when comparing with null", () => {
185
- const user = new User({
186
- id: Id.from("user-123"),
187
- name: "John",
188
- email: "john@example.com",
189
- address: new Address({
190
- street: "Main St",
191
- city: "NYC",
192
- }),
193
- tags: [],
194
- posts: [],
195
- });
196
-
197
- expect(user.equals(null as any)).toBe(false);
198
- });
199
-
200
- it("should return false when comparing with undefined", () => {
201
- const user = new User({
202
- id: Id.from("user-123"),
203
- name: "John",
204
- email: "john@example.com",
205
- address: new Address({
206
- street: "Main St",
207
- city: "NYC",
208
- }),
209
- tags: [],
210
- posts: [],
211
- });
212
-
213
- expect(user.equals(undefined as any)).toBe(false);
214
- });
215
-
216
- it("should handle auto-generated IDs", () => {
217
- const user1 = new User({
218
- name: "John",
219
- email: "john@example.com",
220
- address: new Address({
221
- street: "Main St",
222
- city: "NYC",
223
- }),
224
- tags: [],
225
- posts: [],
226
- });
227
- const user2 = new User({
228
- name: "John",
229
- email: "john@example.com",
230
- address: new Address({
231
- street: "Main St",
232
- city: "NYC",
233
- }),
234
- tags: [],
235
- posts: [],
236
- });
237
-
238
- // Different auto-generated IDs
239
- expect(user1.equals(user2)).toBe(false);
240
-
241
- // Same instance
242
- expect(user1.equals(user1)).toBe(true);
243
- });
244
- });
245
-
246
- describe("Different Entity Types", () => {
247
- it("should NOT be equal when comparing different entity types even with same ID", () => {
248
- const id = Id.from("123");
249
- const user = new User({
250
- id,
251
- name: "John",
252
- email: "john@example.com",
253
- address: new Address({
254
- street: "Main St",
255
- city: "NYC",
256
- }),
257
- tags: [],
258
- posts: [],
259
- });
260
- const order = new Order({ id, total: 100, status: "pending" });
261
-
262
- // TypeScript won't allow this directly, but at runtime they have same ID
263
- expect(user.equals(order as any)).toBe(true); // Same ID = equal in DDD
264
- });
265
- });
266
-
267
- describe("Equality remains after property changes", () => {
268
- it("should remain equal after changing properties", () => {
269
- const id = Id.from("user-123");
270
- const user1 = new User({
271
- id,
272
- name: "John",
273
- email: "john@example.com",
274
- address: new Address({
275
- street: "Main St",
276
- city: "NYC",
277
- }),
278
- tags: [],
279
- posts: [],
280
- });
281
- const user2 = new User({
282
- id,
283
- name: "Jane",
284
- email: "jane@example.com",
285
- address: new Address({
286
- street: "Main St",
287
- city: "NYC",
288
- }),
289
- tags: [],
290
- posts: [],
291
- });
292
-
293
- expect(user1.equals(user2)).toBe(true);
294
-
295
- user1.changeName("Johnny");
296
-
297
- expect(user1.equals(user2)).toBe(true);
298
- });
299
- });
300
-
301
- describe("Use in Collections", () => {
302
- it("should work with Array.find()", () => {
303
- const users = [
304
- new User({
305
- id: Id.from("1"),
306
- name: "John",
307
- email: "john@example.com",
308
- address: new Address({
309
- street: "Main St",
310
- city: "NYC",
311
- }),
312
-
313
- tags: [],
314
- posts: [],
315
- }),
316
- new User({
317
- id: Id.from("2"),
318
- name: "Jane",
319
- email: "jane@example.com",
320
- address: new Address({
321
- street: "Main St",
322
- city: "NYC",
323
- }),
324
-
325
- tags: [],
326
- posts: [],
327
- }),
328
- new User({
329
- id: Id.from("3"),
330
- name: "Bob",
331
- email: "bob@example.com",
332
- address: new Address({
333
- street: "Main St",
334
- city: "NYC",
335
- }),
336
-
337
- tags: [],
338
- posts: [],
339
- }),
340
- ];
341
-
342
- const searchId = Id.from("2");
343
- const found = users.find((user) => user.equals(searchId));
344
-
345
- expect(found).toBeDefined();
346
- expect(found?.name).toBe("Jane");
347
- });
348
-
349
- it("should work with Array.filter()", () => {
350
- const users = [
351
- new User({
352
- id: Id.from("1"),
353
- name: "John",
354
- email: "john@example.com",
355
- address: new Address({
356
- street: "Main St",
357
- city: "NYC",
358
- }),
359
-
360
- tags: [],
361
- posts: [],
362
- }),
363
- new User({
364
- id: Id.from("2"),
365
- name: "Jane",
366
- email: "jane@example.com",
367
- address: new Address({
368
- street: "Main St",
369
- city: "NYC",
370
- }),
371
-
372
- tags: [],
373
- posts: [],
374
- }),
375
- new User({
376
- id: Id.from("1"),
377
- name: "Johnny",
378
- email: "johnny@example.com",
379
- address: new Address({
380
- street: "Main St",
381
- city: "NYC",
382
- }),
383
-
384
- tags: [],
385
- posts: [],
386
- }),
387
- ];
388
-
389
- const searchId = Id.from("1");
390
- const filtered = users.filter((user) => user.equals(searchId));
391
-
392
- expect(filtered.length).toBe(2);
393
- expect(filtered[0].name).toBe("John");
394
- expect(filtered[1].name).toBe("Johnny");
395
- });
396
-
397
- it("should work for checking if entity exists in array", () => {
398
- const users = [
399
- new User({
400
- id: Id.from("1"),
401
- name: "John",
402
- email: "john@example.com",
403
- address: new Address({
404
- street: "Main St",
405
- city: "NYC",
406
- }),
407
-
408
- tags: [],
409
- posts: [],
410
- }),
411
- new User({
412
- id: Id.from("2"),
413
- name: "Jane",
414
- email: "jane@example.com",
415
- address: new Address({
416
- street: "Main St",
417
- city: "NYC",
418
- }),
419
-
420
- tags: [],
421
- posts: [],
422
- }),
423
- ];
424
-
425
- const user1 = new User({
426
- id: Id.from("1"),
427
- name: "Different Name",
428
- email: "different@example.com",
429
- address: new Address({
430
- street: "Main St",
431
- city: "NYC",
432
- }),
433
- tags: [],
434
- posts: [],
435
- });
436
- const user3 = new User({
437
- id: Id.from("3"),
438
- name: "Bob",
439
- email: "bob@example.com",
440
- address: new Address({
441
- street: "Main St",
442
- city: "NYC",
443
- }),
444
- tags: [],
445
- posts: [],
446
- });
447
-
448
- expect(users.some((u) => u.equals(user1))).toBe(true); // Exists (same ID)
449
- expect(users.some((u) => u.equals(user3))).toBe(false); // Doesn't exist
450
- });
451
- });
452
-
453
- describe("Aggregate Equality", () => {
454
- it("should work the same way for Aggregates", () => {
455
- const id = Id.from("order-123");
456
- const order1 = new Order({ id, total: 100, status: "pending" });
457
- const order2 = new Order({ id, total: 200, status: "completed" });
458
-
459
- expect(order1.equals(order2)).toBe(true);
460
- expect(order1.equals(id)).toBe(true);
461
- expect(order1.equals("order-123")).toBe(true);
462
- });
463
- });
464
- });