@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
package/tests/id.test.ts DELETED
@@ -1,338 +0,0 @@
1
- import { Id } from "../src";
2
- import { Address, Post, User } from "./utils";
3
-
4
- // ============================================================================
5
- // Id Class Tests
6
- // ============================================================================
7
-
8
- describe("Id Class", () => {
9
- describe("Construction", () => {
10
- it("should generate UUID when no value provided", () => {
11
- const id = new Id();
12
-
13
- expect(id.value).toBeDefined();
14
- expect(typeof id.value).toBe("string");
15
- expect(id.value.length).toBeGreaterThan(0);
16
- // UUID v4 format check
17
- expect(id.value).toMatch(
18
- /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i
19
- );
20
- });
21
-
22
- it("should mark as new when no value provided", () => {
23
- const id = new Id();
24
-
25
- expect(id.isNew()).toBe(true);
26
- });
27
-
28
- it("should use provided value", () => {
29
- const existingId = "550e8400-e29b-41d4-a716-446655440000";
30
- const id = new Id(existingId);
31
-
32
- expect(id.value).toBe(existingId);
33
- });
34
-
35
- it("should mark as NOT new when value provided", () => {
36
- const id = new Id("existing-id");
37
-
38
- expect(id.isNew()).toBe(false);
39
- });
40
-
41
- it("should generate unique IDs", () => {
42
- const id1 = new Id();
43
- const id2 = new Id();
44
- const id3 = new Id();
45
-
46
- expect(id1.value).not.toBe(id2.value);
47
- expect(id2.value).not.toBe(id3.value);
48
- expect(id1.value).not.toBe(id3.value);
49
- });
50
- });
51
-
52
- describe("Static Methods", () => {
53
- it("should create new Id with Id.create()", () => {
54
- const id = Id.create();
55
-
56
- expect(id.isNew()).toBe(true);
57
- expect(id.value).toBeDefined();
58
- });
59
-
60
- it("should create existing Id with Id.from()", () => {
61
- const id = Id.from("existing-id");
62
-
63
- expect(id.isNew()).toBe(false);
64
- expect(id.value).toBe("existing-id");
65
- });
66
- });
67
-
68
- describe("String Conversion", () => {
69
- it("should convert to string with toString()", () => {
70
- const id = new Id("test-id");
71
-
72
- expect(id.toString()).toBe("test-id");
73
- expect(String(id)).toBe("test-id");
74
- });
75
-
76
- it("should convert to JSON", () => {
77
- const id = new Id("test-id");
78
-
79
- expect(id.toJSON()).toBe("test-id");
80
- expect(JSON.stringify(id)).toBe('"test-id"');
81
- });
82
- });
83
-
84
- describe("Equality", () => {
85
- it("should compare with another Id", () => {
86
- const id1 = new Id("same-id");
87
- const id2 = new Id("same-id");
88
- const id3 = new Id("different-id");
89
-
90
- expect(id1.equals(id2)).toBe(true);
91
- expect(id1.equals(id3)).toBe(false);
92
- });
93
-
94
- it("should compare with string", () => {
95
- const id = new Id("test-id");
96
-
97
- expect(id.equals("test-id")).toBe(true);
98
- expect(id.equals("other-id")).toBe(false);
99
- });
100
- });
101
- });
102
-
103
- // ============================================================================
104
- // Entity with Id Tests
105
- // ============================================================================
106
-
107
- describe("Entity with Id Class", () => {
108
- describe("New Entity", () => {
109
- it("should be new when Id is auto-generated", () => {
110
- const post = new Post({
111
- id: new Id(), // No value = new
112
- title: "New Post",
113
- content: "Content",
114
- comments: [],
115
- published: false,
116
- });
117
-
118
- expect(post.isNew()).toBe(true);
119
- expect(post.id.isNew()).toBe(true);
120
- });
121
-
122
- it("should auto-generate unique IDs", () => {
123
- const post1 = new Post({
124
- id: new Id(),
125
- title: "Post 1",
126
- comments: [],
127
- published: false,
128
- content: "Content",
129
- });
130
-
131
- const post2 = new Post({
132
- id: new Id(),
133
- title: "Post 2",
134
- comments: [],
135
- published: false,
136
- content: "Content",
137
- });
138
-
139
- expect(post1.id.value).not.toBe(post2.id.value);
140
- expect(post1.isNew()).toBe(true);
141
- expect(post2.isNew()).toBe(true);
142
- });
143
-
144
- it("should work with Id.create()", () => {
145
- const post = new Post({
146
- id: Id.create(),
147
- title: "New Post",
148
- content: "Content",
149
- comments: [],
150
- published: false,
151
- });
152
-
153
- expect(post.isNew()).toBe(true);
154
- });
155
- });
156
-
157
- describe("Existing Entity", () => {
158
- it("should NOT be new when Id value is provided", () => {
159
- const post = new Post({
160
- id: new Id("existing-post-id"), // Value provided = not new
161
- title: "Existing Post",
162
- content: "Content",
163
- comments: [],
164
- published: false,
165
- });
166
-
167
- expect(post.isNew()).toBe(false);
168
- expect(post.id.isNew()).toBe(false);
169
- });
170
-
171
- it("should work with Id.from()", () => {
172
- const post = new Post({
173
- id: Id.from("existing-post-id"),
174
- title: "Existing Post",
175
- content: "Content",
176
- comments: [],
177
- published: false,
178
- });
179
-
180
- expect(post.isNew()).toBe(false);
181
- });
182
- });
183
-
184
- describe("toJson()", () => {
185
- it("should serialize Id to string", () => {
186
- const post = new Post({
187
- id: new Id("post-123"),
188
- title: "Test Post",
189
- comments: [],
190
- published: false,
191
- content: "Content",
192
- });
193
-
194
- const json = post.toJson();
195
-
196
- expect(json.id).toBe("post-123");
197
- expect(typeof json.id).toBe("string");
198
- });
199
- });
200
-
201
- describe("Id Comparison in Arrays", () => {
202
- it("should detect changes in arrays using Id", () => {
203
- const user = new User({
204
- id: new Id("user-1"),
205
- name: "John",
206
- email: "john@example.com",
207
- posts: [],
208
- address: new Address({
209
- street: "Main St",
210
- city: "NYC",
211
- }),
212
- tags: [],
213
- });
214
-
215
- user.addManyPosts([
216
- new Post({
217
- id: new Id(),
218
- title: "Post 1",
219
- content: "Content 1",
220
- comments: [],
221
- published: false,
222
- }),
223
- new Post({
224
- id: new Id(),
225
- title: "Post 2",
226
- content: "Content 2",
227
- comments: [],
228
- published: false,
229
- }),
230
- ]);
231
-
232
- const changes = user.getTypedChanges();
233
-
234
- console.dir(changes.creates(), { depth: null });
235
-
236
- expect(changes.creates().length).toBe(2);
237
- });
238
-
239
- it("should track deletes correctly with Id", () => {
240
- const postId = new Id("post-to-delete");
241
-
242
- const user = new User({
243
- id: new Id("user-1"),
244
- name: "John",
245
- email: "john@example.com",
246
- posts: [
247
- new Post({
248
- id: postId,
249
- title: "Post 1",
250
- content: "Content 1",
251
- comments: [],
252
- published: false,
253
- }),
254
- ],
255
- address: new Address({
256
- street: "Main St",
257
- city: "NYC",
258
- }),
259
- tags: [],
260
- });
261
-
262
- user.removePost(postId);
263
-
264
- const changes = user.getTypedChanges();
265
-
266
- expect(changes.deletes()).toHaveLength(1);
267
- expect(changes.creates()).toHaveLength(0);
268
- expect(changes.deletes()[0].id).toBe(postId.value);
269
- });
270
- });
271
- });
272
-
273
- // ============================================================================
274
- // Aggregate with Id Tests
275
- // ============================================================================
276
-
277
- describe("Aggregate with Id Class", () => {
278
- it("should be new when Id is auto-generated", () => {
279
- const user = new User({
280
- id: new Id(),
281
- name: "John",
282
- email: "john@example.com",
283
- posts: [],
284
- address: new Address({
285
- street: "Main St",
286
- city: "NYC",
287
- }),
288
- tags: [],
289
- });
290
-
291
- expect(user.isNew()).toBe(true);
292
- });
293
-
294
- it("should NOT be new when Id value is provided", () => {
295
- const user = new User({
296
- id: new Id("existing-user"),
297
- name: "John",
298
- email: "john@example.com",
299
- posts: [],
300
- address: new Address({
301
- street: "Main St",
302
- city: "NYC",
303
- }),
304
- tags: [],
305
- });
306
-
307
- expect(user.isNew()).toBe(false);
308
- });
309
-
310
- it("should serialize Id in nested entities", () => {
311
- const user = new User({
312
- id: new Id("user-1"),
313
- name: "John",
314
- email: "john@example.com",
315
- posts: [
316
- new Post({
317
- id: new Id("post-1"),
318
- title: "Post 1",
319
- comments: [],
320
- content: "Content",
321
- published: false,
322
- }),
323
- ],
324
- tags: [],
325
- address: new Address({
326
- street: "Main St",
327
- city: "NYC",
328
- }),
329
- });
330
-
331
- const json = user.toJson();
332
-
333
- expect(json.id).toBe("user-1");
334
- expect(json.posts[0].id).toBe("post-1");
335
- expect(typeof json.id).toBe("string");
336
- expect(typeof json.posts[0].id).toBe("string");
337
- });
338
- });