@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.
- package/CHANGELOG.md +33 -0
- package/dist/aggregate-changes.d.ts +164 -0
- package/dist/aggregate-changes.d.ts.map +1 -0
- package/dist/aggregate-changes.js +281 -0
- package/dist/aggregate-changes.js.map +1 -0
- package/dist/base-entity.d.ts +32 -8
- package/dist/base-entity.d.ts.map +1 -1
- package/dist/base-entity.js +117 -86
- package/dist/base-entity.js.map +1 -1
- package/dist/criteria.d.ts +3 -3
- package/dist/criteria.d.ts.map +1 -1
- package/dist/criteria.js.map +1 -1
- package/dist/crypto.d.ts +3 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +29 -0
- package/dist/crypto.js.map +1 -0
- package/dist/entity-changes.d.ts +84 -0
- package/dist/entity-changes.d.ts.map +1 -0
- package/dist/entity-changes.js +135 -0
- package/dist/entity-changes.js.map +1 -0
- package/dist/entity-schema-registry.d.ts +148 -0
- package/dist/entity-schema-registry.d.ts.map +1 -0
- package/dist/entity-schema-registry.js +219 -0
- package/dist/entity-schema-registry.js.map +1 -0
- package/dist/history-tracker.d.ts +97 -0
- package/dist/history-tracker.d.ts.map +1 -0
- package/dist/history-tracker.js +805 -0
- package/dist/history-tracker.js.map +1 -0
- package/dist/id.d.ts +11 -10
- package/dist/id.d.ts.map +1 -1
- package/dist/id.js +4 -28
- package/dist/id.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mapper.d.ts +1 -1
- package/dist/mapper.d.ts.map +1 -1
- package/dist/mapper.js.map +1 -1
- package/dist/repository/base-repository.d.ts +6 -32
- package/dist/repository/base-repository.d.ts.map +1 -1
- package/dist/repository/base-repository.js +0 -27
- package/dist/repository/base-repository.js.map +1 -1
- package/dist/repository/unit-of-work.d.ts +0 -25
- package/dist/repository/unit-of-work.d.ts.map +1 -1
- package/dist/repository/unit-of-work.js +0 -25
- package/dist/repository/unit-of-work.js.map +1 -1
- package/dist/types/change-tracker.d.ts +186 -0
- package/dist/types/change-tracker.d.ts.map +1 -0
- package/dist/types/change-tracker.js +2 -0
- package/dist/types/change-tracker.js.map +1 -0
- package/dist/types/criteria.d.ts +5 -1
- package/dist/types/criteria.d.ts.map +1 -1
- package/dist/types/history-tracker.d.ts +11 -0
- package/dist/types/history-tracker.d.ts.map +1 -1
- package/dist/types/utils.d.ts +0 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/validation-error.d.ts.map +1 -1
- package/dist/validation-error.js +0 -3
- package/dist/validation-error.js.map +1 -1
- package/dist/value-object.d.ts +57 -8
- package/dist/value-object.d.ts.map +1 -1
- package/dist/value-object.js +49 -21
- package/dist/value-object.js.map +1 -1
- package/package.json +2 -1
- package/src/aggregate-changes.ts +335 -0
- package/src/base-entity.ts +140 -100
- package/src/criteria.ts +2 -1
- package/src/crypto.ts +31 -0
- package/src/entity-changes.ts +151 -0
- package/src/entity-schema-registry.ts +275 -0
- package/src/history-tracker.ts +1114 -0
- package/src/id.ts +17 -26
- package/src/index.ts +1 -0
- package/src/mapper.ts +4 -1
- package/src/repository/base-repository.ts +6 -37
- package/src/repository/unit-of-work.ts +0 -25
- package/src/types/change-tracker.ts +221 -0
- package/src/types/criteria.ts +6 -1
- package/src/types/history-tracker.ts +13 -0
- package/src/types/utils.ts +0 -9
- package/src/validation-error.ts +0 -4
- package/src/value-object.ts +84 -23
- package/tests/aggregate-changes.test.ts +284 -0
- package/tests/criteria.test.ts +122 -161
- package/tests/entity-equality.test.ts +38 -61
- package/tests/entity-schema-registry.test.ts +382 -0
- package/tests/entity-validation.test.ts +7 -94
- package/tests/history-tracker.spec.ts +349 -617
- package/tests/id.test.ts +41 -44
- package/tests/load-test/data.json +346041 -0
- package/tests/load-test/entities.ts +97 -0
- package/tests/load-test/generate-data.ts +81 -0
- package/tests/load-test/lead-to-domain.mapper.ts +24 -0
- package/tests/load-test/load.test.ts +38 -0
- package/tests/repository.test.ts +30 -54
- package/tests/to-json.test.ts +14 -18
- package/tests/utils.ts +138 -102
- package/tests/value-objects.test.ts +57 -29
- package/dist/deep-proxy.d.ts +0 -36
- package/dist/deep-proxy.d.ts.map +0 -1
- package/dist/deep-proxy.js +0 -384
- package/dist/deep-proxy.js.map +0 -1
- package/src/deep-proxy.ts +0 -447
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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", (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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", (
|
|
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
|
-
|
|
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
|
-
|
|
259
|
+
tags: [],
|
|
256
260
|
});
|
|
257
261
|
|
|
258
|
-
user.
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
321
|
+
published: false,
|
|
324
322
|
}),
|
|
325
323
|
],
|
|
326
|
-
|
|
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
|
|