@woltz/rich-domain 1.2.4 → 1.3.0
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/dist/aggregate-changes.d.ts +56 -14
- package/dist/aggregate-changes.d.ts.map +1 -1
- package/dist/aggregate-changes.js +102 -22
- package/dist/aggregate-changes.js.map +1 -1
- package/dist/base-entity.d.ts +1 -1
- package/dist/base-entity.d.ts.map +1 -1
- package/dist/base-entity.js +11 -8
- package/dist/base-entity.js.map +1 -1
- package/dist/change-tracker.d.ts +1 -0
- package/dist/change-tracker.d.ts.map +1 -1
- package/dist/change-tracker.js +41 -27
- package/dist/change-tracker.js.map +1 -1
- package/dist/criteria.d.ts +7 -15
- package/dist/criteria.d.ts.map +1 -1
- package/dist/criteria.js +99 -76
- package/dist/criteria.js.map +1 -1
- package/dist/entity-schema-registry.d.ts +133 -3
- package/dist/entity-schema-registry.d.ts.map +1 -1
- package/dist/entity-schema-registry.js +155 -4
- package/dist/entity-schema-registry.js.map +1 -1
- package/dist/paginated-result.d.ts +4 -4
- package/dist/paginated-result.d.ts.map +1 -1
- package/dist/paginated-result.js +6 -20
- package/dist/paginated-result.js.map +1 -1
- package/dist/types/change-tracker.d.ts +30 -0
- package/dist/types/change-tracker.d.ts.map +1 -1
- package/dist/types/criteria.d.ts +1 -4
- package/dist/types/criteria.d.ts.map +1 -1
- package/dist/types/domain.d.ts +2 -0
- package/dist/types/domain.d.ts.map +1 -1
- package/dist/types/utils.d.ts +2 -2
- package/dist/utils/helpers.d.ts +1 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +23 -0
- package/dist/utils/helpers.js.map +1 -1
- package/dist/value-object.d.ts +1 -1
- package/dist/value-object.js +1 -1
- package/package.json +17 -3
- package/src/aggregate-changes.ts +133 -24
- package/src/base-entity.ts +13 -8
- package/src/change-tracker.ts +107 -38
- package/src/criteria.ts +151 -109
- package/src/entity-schema-registry.ts +253 -6
- package/src/paginated-result.ts +10 -30
- package/src/types/change-tracker.ts +31 -0
- package/src/types/criteria.ts +1 -4
- package/src/types/domain.ts +2 -0
- package/src/types/utils.ts +2 -2
- package/src/utils/helpers.ts +28 -0
- package/src/value-object.ts +1 -1
- package/.versionrc.json +0 -21
- package/CHANGELOG.md +0 -163
- package/tests/aggregate-changes.test.ts +0 -284
- package/tests/criteria.test.ts +0 -716
- package/tests/depth/deep-tracking.test.ts +0 -554
- package/tests/domain-events.test.ts +0 -431
- package/tests/entity-equality.test.ts +0 -464
- package/tests/entity-schema-registry.test.ts +0 -382
- package/tests/entity-validation.test.ts +0 -252
- package/tests/history-tracker.spec.ts +0 -439
- package/tests/id.test.ts +0 -338
- package/tests/load-test/data.json +0 -347211
- package/tests/load-test/entities.ts +0 -97
- package/tests/load-test/generate-data.ts +0 -81
- package/tests/load-test/lead-to-domain.mapper.ts +0 -24
- package/tests/load-test/load.test.ts +0 -38
- package/tests/repository.test.ts +0 -635
- package/tests/to-json.test.ts +0 -99
- package/tests/utils.ts +0 -290
- package/tests/value-object-validation.test.ts +0 -219
- package/tests/value-objects.test.ts +0 -80
- package/tsconfig.json +0 -9
package/CHANGELOG.md
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### [1.2.4](https://github.com/tarcisioandrade/rich-domain/compare/v1.2.2...v1.2.4) (2025-11-30)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
* critic bug ([474a8d9](https://github.com/tarcisioandrade/rich-domain/commit/474a8d90fc9fb2810dc37018c86dce234d2ac08f))
|
|
11
|
-
* improve deep cloning logic in BaseEntity to handle structuredClone fallback ([78f8fbf](https://github.com/tarcisioandrade/rich-domain/commit/78f8fbf5846650a7e3783aa55023d94db65572f6))
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
### Tests
|
|
15
|
-
|
|
16
|
-
* add comprehensive deep tracking tests for nested entity structures ([66b0c33](https://github.com/tarcisioandrade/rich-domain/commit/66b0c3399e825b24925a7ae3056e57a18ec6d93c))
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
### Refactoring
|
|
20
|
-
|
|
21
|
-
* change visibility of prisma client in PrismaRepository constructor ([1cf83ed](https://github.com/tarcisioandrade/rich-domain/commit/1cf83ed97585fddd6a25125cedc1bcf72b289713))
|
|
22
|
-
|
|
23
|
-
### [1.2.3](https://github.com/tarcisioandrade/rich-domain/compare/v1.2.2...v1.2.3) (2025-11-30)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
### Bug Fixes
|
|
27
|
-
|
|
28
|
-
* critic bug ([474a8d9](https://github.com/tarcisioandrade/rich-domain/commit/474a8d90fc9fb2810dc37018c86dce234d2ac08f))
|
|
29
|
-
* improve deep cloning logic in BaseEntity to handle structuredClone fallback ([78f8fbf](https://github.com/tarcisioandrade/rich-domain/commit/78f8fbf5846650a7e3783aa55023d94db65572f6))
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
### Tests
|
|
33
|
-
|
|
34
|
-
* add comprehensive deep tracking tests for nested entity structures ([66b0c33](https://github.com/tarcisioandrade/rich-domain/commit/66b0c3399e825b24925a7ae3056e57a18ec6d93c))
|
|
35
|
-
|
|
36
|
-
### [1.2.2](https://github.com/tarcisioandrade/rich-domain/compare/v0.3.0...v1.2.2) (2025-11-30)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
### Features
|
|
40
|
-
|
|
41
|
-
* filter component with criteria ([a6e5a66](https://github.com/tarcisioandrade/rich-domain/commit/a6e5a664e7b175f8156832b2d42821f73efec522))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
### Bug Fixes
|
|
45
|
-
|
|
46
|
-
* incorrect verification in criteria operator validation ([8b4da16](https://github.com/tarcisioandrade/rich-domain/commit/8b4da16ded67a55afe64adbe60d52359cd168a17))
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Chores
|
|
50
|
-
|
|
51
|
-
* update dependencies and refactor mappers to use PrismaToPersistence ([5281716](https://github.com/tarcisioandrade/rich-domain/commit/52817161667ce473ffe2f7991d55c03190d097c0))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
### Refactoring
|
|
55
|
-
|
|
56
|
-
* enhance criteria validation by adding field value sanitization ([9991a6b](https://github.com/tarcisioandrade/rich-domain/commit/9991a6b54dbfa8b5d2505ed17897b76f6b794a33))
|
|
57
|
-
* improve filter component logic and UI interactions for adding filters ([3dd8d9f](https://github.com/tarcisioandrade/rich-domain/commit/3dd8d9fb8934ca15357ad62485f74c541c01a680))
|
|
58
|
-
* migrate filter types to filter-utils for improved organization and clarity ([eeb2af4](https://github.com/tarcisioandrade/rich-domain/commit/eeb2af4f563ff7f8dc3eb1836b22392bc229f3af))
|
|
59
|
-
* update FilterDateValue component to handle string dates and improve date handling logic ([6cb0b42](https://github.com/tarcisioandrade/rich-domain/commit/6cb0b4245ce9394389ee208c16035bc49e4aa912))
|
|
60
|
-
|
|
61
|
-
### [1.2.1](https://github.com/tarcisioandrade/rich-domain/compare/v1.2.0...v1.2.1) (2025-11-29)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
### Features
|
|
65
|
-
|
|
66
|
-
* implement custom UUID generation in crypto module ([4fc732a](https://github.com/tarcisioandrade/rich-domain/commit/4fc732a00237a9d63e320555acf4a8a14c941f13))
|
|
67
|
-
* introduce TypedOrder and enhance Criteria to support nested object field paths ([9857624](https://github.com/tarcisioandrade/rich-domain/commit/9857624608eda1320ec813b165e9183f1e28a0d1))
|
|
68
|
-
* new history-tracker structure ([aaea6d4](https://github.com/tarcisioandrade/rich-domain/commit/aaea6d4c8aed575f50917cba41936d1b1560ed3d))
|
|
69
|
-
* update Id constructor to handle optional isNew parameter ([0aae58b](https://github.com/tarcisioandrade/rich-domain/commit/0aae58b02da69e0cb7421663335ac305ade5afa7))
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
### Bug Fixes
|
|
73
|
-
|
|
74
|
-
* aggregate-changes type inference ([aa62138](https://github.com/tarcisioandrade/rich-domain/commit/aa62138b31cdedb63c0e1be8a19271f4ada2e71c))
|
|
75
|
-
* history tracker not tracking when nested created ([2900e20](https://github.com/tarcisioandrade/rich-domain/commit/2900e20c18da7aa0ee960c9e5d0f5e2524e3d6f3))
|
|
76
|
-
* uow in persistence fastify example ([fcef611](https://github.com/tarcisioandrade/rich-domain/commit/fcef61103f160c0b1adbee9cbce821ce047189eb))
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
### Refactoring
|
|
80
|
-
|
|
81
|
-
* change prisma example to new architecture ([92dc179](https://github.com/tarcisioandrade/rich-domain/commit/92dc1798ee5a64439d6633ab5b0cc77b42265ed6))
|
|
82
|
-
* improve deepClone method for better object handling and error management ([52ae893](https://github.com/tarcisioandrade/rich-domain/commit/52ae8930d112ba018f7944f69837edea82d45309))
|
|
83
|
-
* prisma example unit of work with async local storage ([ca6fc16](https://github.com/tarcisioandrade/rich-domain/commit/ca6fc1663ca251dac020939080b126f3984b0eae))
|
|
84
|
-
* remove unnosed code from ancient architecture ([19a41b1](https://github.com/tarcisioandrade/rich-domain/commit/19a41b121b4adaaea5525da20b068f43cc674db8))
|
|
85
|
-
* update repository methods to use 'save' consistently across use cases ([aab323b](https://github.com/tarcisioandrade/rich-domain/commit/aab323be2fff86246dc0c1a14cb7ba56bf11efa7))
|
|
86
|
-
* update repository methods to use 'save' instead of 'create' and 'update' ([6766970](https://github.com/tarcisioandrade/rich-domain/commit/6766970019781215019b492963e020ef4babcd89))
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
### Tests
|
|
90
|
-
|
|
91
|
-
* add load test ([9bd07fb](https://github.com/tarcisioandrade/rich-domain/commit/9bd07fb019e2cc0eef3f0573af8f4dad1d8b385f))
|
|
92
|
-
* new history-tracker structure ([d31ad0b](https://github.com/tarcisioandrade/rich-domain/commit/d31ad0b109bfa5e5ff62743d70dd51bb64107f10))
|
|
93
|
-
|
|
94
|
-
## [1.2.0](https://github.com/tarcisioandrade/rich-domain/compare/v1.1.0...v1.2.0) (2025-11-23)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
### Features
|
|
98
|
-
|
|
99
|
-
* add getFilterByField and getSortByField methods to useCriteria hook ([8db041a](https://github.com/tarcisioandrade/rich-domain/commit/8db041a8fbe359ec6fe3ff70e22ac87a6c221686))
|
|
100
|
-
* add options parameter to addFilter method for enhanced filtering capabilities ([c43c164](https://github.com/tarcisioandrade/rich-domain/commit/c43c164f56831b9f0b06f2e5981ba3f540cf3378))
|
|
101
|
-
* add quantifier support to Criteria class for enhanced filtering options ([322adf3](https://github.com/tarcisioandrade/rich-domain/commit/322adf36dfedcdc21ae6fc85c3577e1fb2835019))
|
|
102
|
-
* criteria adapter implementation ([f387f0b](https://github.com/tarcisioandrade/rich-domain/commit/f387f0bcd601a69da74d5fff33b9d9872e049179))
|
|
103
|
-
* enhance criteria operators with new types and validation functions ([8d30c14](https://github.com/tarcisioandrade/rich-domain/commit/8d30c1448e3d25c790d667b43d17546a441e710d))
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
### Bug Fixes
|
|
107
|
-
|
|
108
|
-
* FieldPath infer type to array methods ([844a56e](https://github.com/tarcisioandrade/rich-domain/commit/844a56ef2cdc65fac0cb228c6936808a92ffa440))
|
|
109
|
-
* search filter not reset page ([c8c9d8b](https://github.com/tarcisioandrade/rich-domain/commit/c8c9d8b1fecc1ce8c568f43710c8748ad9ad1f1e))
|
|
110
|
-
* types in react-with-react-query ([6eeeb74](https://github.com/tarcisioandrade/rich-domain/commit/6eeeb74715bef50d3c5dec8dcc3e37484e0f511b))
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
### Chores
|
|
114
|
-
|
|
115
|
-
* add TypeScript check script and enhance ([9f6347c](https://github.com/tarcisioandrade/rich-domain/commit/9f6347c4707adebb9e03bcdc952791a9c3279038))
|
|
116
|
-
* enhance useCriteria hook and update TypeScript types for better type safety ([2bbc699](https://github.com/tarcisioandrade/rich-domain/commit/2bbc699aab415a52502ad50e7fbf67bcd52ae222))
|
|
117
|
-
* refactor frontend example to integrate useCriteria hook ([48dccc7](https://github.com/tarcisioandrade/rich-domain/commit/48dccc7df870024f280902c22c77dcf531702781))
|
|
118
|
-
* update ESLint configurations to include tsconfigRootDir ([b019884](https://github.com/tarcisioandrade/rich-domain/commit/b01988496b91c6c9d3e6d3d89597cf9f23e54729))
|
|
119
|
-
* update rich domain version in examples app ([4be8a1b](https://github.com/tarcisioandrade/rich-domain/commit/4be8a1bdd4473d8274c0ec8bec1d4ec1d70109ea))
|
|
120
|
-
* update target paths in registry.json and use-criteria.json for improved file structure ([d2f9348](https://github.com/tarcisioandrade/rich-domain/commit/d2f93486158e465d8878d92f1d80e259cc62f701))
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
### Refactoring
|
|
124
|
-
|
|
125
|
-
* criteria adapter in fastify-with-prisma example ([8adef1e](https://github.com/tarcisioandrade/rich-domain/commit/8adef1e0c62ab94bd3665f91ca6ea29d568ea24f))
|
|
126
|
-
|
|
127
|
-
## [1.1.0](https://github.com/tarcisioandrade/rich-domain/compare/v1.0.0...v1.1.0) (2025-11-22)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
### Features
|
|
131
|
-
|
|
132
|
-
* add examples in monorepo ([2cba30e](https://github.com/tarcisioandrade/rich-domain/commit/2cba30e318be2575b007c8b4f9a00e35561eec5e))
|
|
133
|
-
* add react-with-react-query example ([439589e](https://github.com/tarcisioandrade/rich-domain/commit/439589e1abbc47b1b03efab3b9dde53fe8d6253c))
|
|
134
|
-
* domain execeptions ([e206274](https://github.com/tarcisioandrade/rich-domain/commit/e206274d8a93c09cc91b2c0514be62cb986caaa3))
|
|
135
|
-
* implement useCriteria hook ([c00441a](https://github.com/tarcisioandrade/rich-domain/commit/c00441a105391fd06ef39b8c7e3aa0907c3ff508))
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
### Bug Fixes
|
|
139
|
-
|
|
140
|
-
* infinite loop when multiples order are add ([2c13dc4](https://github.com/tarcisioandrade/rich-domain/commit/2c13dc472d009bf328ad45222ea1c921f588ff9a))
|
|
141
|
-
* search not working in fromArray PaginatedResult method ([b79b2aa](https://github.com/tarcisioandrade/rich-domain/commit/b79b2aa2aa17e8b98bf2c2fcb4823452db99dcc1))
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
### Refactoring
|
|
145
|
-
|
|
146
|
-
* clean exports ([3f8e16a](https://github.com/tarcisioandrade/rich-domain/commit/3f8e16a2103514ef7a2a928dff20f674d1e39506))
|
|
147
|
-
* migrate eslint configuration to ES module syntax ([3ea4366](https://github.com/tarcisioandrade/rich-domain/commit/3ea43667b0857b7ae2afcbad858c16384035dc50))
|
|
148
|
-
* monorepo implementation ([e0b1e68](https://github.com/tarcisioandrade/rich-domain/commit/e0b1e683d5ee95b54b79510d43dd957af49c65e2))
|
|
149
|
-
* remove defaultValues from value objects ([0523479](https://github.com/tarcisioandrade/rich-domain/commit/0523479c6f272d7ea5d678638fa666e3fde71c7a))
|
|
150
|
-
* streamline domain event imports and consolidate IDomainEvent interface ([573c689](https://github.com/tarcisioandrade/rich-domain/commit/573c689a762baecd9fb8791e66300f663d7a58c1))
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
### Chores
|
|
154
|
-
|
|
155
|
-
* add postinstall script to generate Prisma client ([ffbe310](https://github.com/tarcisioandrade/rich-domain/commit/ffbe310db4ff9e6918d4e55096b8939c1f8f4543))
|
|
156
|
-
* enhance linting setup for react-rich-domain and update package.json ([ac2803b](https://github.com/tarcisioandrade/rich-domain/commit/ac2803bac0d907c0513d249fc5e14390418c7530))
|
|
157
|
-
* modify check script to target specific workspace ([d39d6d8](https://github.com/tarcisioandrade/rich-domain/commit/d39d6d8ef3a04d17207a3a0e795027040b3cf707))
|
|
158
|
-
* update clean script to remove node_modules in backend and rich-domain packages ([2a10cab](https://github.com/tarcisioandrade/rich-domain/commit/2a10cab193ba00e504a9a301cc00cda4b68b8573))
|
|
159
|
-
* update module entry points in package.json for react-rich-domain ([03be9ac](https://github.com/tarcisioandrade/rich-domain/commit/03be9aced05160c97eb74f771b770283c07e046b))
|
|
160
|
-
* update package configuration and add new dependencies ([4135393](https://github.com/tarcisioandrade/rich-domain/commit/4135393ae78b1b8e6b0c9306f0ac0872971ddb3f))
|
|
161
|
-
* update package.json scripts to target specific workspace ([8f46868](https://github.com/tarcisioandrade/rich-domain/commit/8f468688017f49cae58dff5d1a9818fe64b38017))
|
|
162
|
-
* update package.json with homepage and repository detail ([bfb387c](https://github.com/tarcisioandrade/rich-domain/commit/bfb387cb2076989a808f25be09337a24ed3a8ff6))
|
|
163
|
-
* update test script to target specific workspace ([6783208](https://github.com/tarcisioandrade/rich-domain/commit/678320803828a43ef588c366e59bf62c2851c126))
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// Tests: AggregateChanges
|
|
3
|
-
// ============================================================================
|
|
4
|
-
|
|
5
|
-
import { AggregateChanges } from "../src/aggregate-changes";
|
|
6
|
-
|
|
7
|
-
describe("AggregateChanges", () => {
|
|
8
|
-
let changes: AggregateChanges;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
changes = new AggregateChanges();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("isEmpty / hasChanges", () => {
|
|
15
|
-
it("should be empty initially", () => {
|
|
16
|
-
expect(changes.isEmpty()).toBe(true);
|
|
17
|
-
expect(changes.hasChanges()).toBe(false);
|
|
18
|
-
expect(changes.count).toBe(0);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should not be empty after adding operation", () => {
|
|
22
|
-
changes.addCreate("User", { id: "1", name: "Test" }, 0);
|
|
23
|
-
expect(changes.isEmpty()).toBe(false);
|
|
24
|
-
expect(changes.hasChanges()).toBe(true);
|
|
25
|
-
expect(changes.count).toBe(1);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe("addCreate", () => {
|
|
30
|
-
it("should add create operation", () => {
|
|
31
|
-
const data = { id: "1", name: "Test User" };
|
|
32
|
-
changes.addCreate("User", data, 0);
|
|
33
|
-
|
|
34
|
-
expect(changes.hasCreates()).toBe(true);
|
|
35
|
-
expect(changes.creates()).toHaveLength(1);
|
|
36
|
-
expect(changes.creates()[0]).toMatchObject({
|
|
37
|
-
type: "create",
|
|
38
|
-
entity: "User",
|
|
39
|
-
data,
|
|
40
|
-
depth: 0,
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should add create with parent info", () => {
|
|
45
|
-
const data = { id: "post-1", title: "Test Post" };
|
|
46
|
-
changes.addCreate("Post", data, 1, "user-1", "User");
|
|
47
|
-
|
|
48
|
-
const create = changes.creates()[0];
|
|
49
|
-
expect(create.parentId).toBe("user-1");
|
|
50
|
-
expect(create.parentEntity).toBe("User");
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe("addUpdate", () => {
|
|
55
|
-
it("should add update operation", () => {
|
|
56
|
-
const data = { id: "1", name: "Updated" };
|
|
57
|
-
const changedFields = { name: "Updated" };
|
|
58
|
-
changes.addUpdate("User", "1", data, changedFields, 0);
|
|
59
|
-
|
|
60
|
-
expect(changes.hasUpdates()).toBe(true);
|
|
61
|
-
expect(changes.updates()).toHaveLength(1);
|
|
62
|
-
expect(changes.updates()[0]).toMatchObject({
|
|
63
|
-
type: "update",
|
|
64
|
-
entity: "User",
|
|
65
|
-
id: "1",
|
|
66
|
-
changedFields,
|
|
67
|
-
depth: 0,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("addDelete", () => {
|
|
73
|
-
it("should add delete operation", () => {
|
|
74
|
-
const data = { id: "1", name: "To Delete" };
|
|
75
|
-
changes.addDelete("User", "1", data, 0);
|
|
76
|
-
|
|
77
|
-
expect(changes.hasDeletes()).toBe(true);
|
|
78
|
-
expect(changes.deletes()).toHaveLength(1);
|
|
79
|
-
expect(changes.deletes()[0]).toMatchObject({
|
|
80
|
-
type: "delete",
|
|
81
|
-
entity: "User",
|
|
82
|
-
id: "1",
|
|
83
|
-
depth: 0,
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe("ordering", () => {
|
|
89
|
-
beforeEach(() => {
|
|
90
|
-
// Add operations in random order
|
|
91
|
-
changes.addCreate("Comment", { id: "c1" }, 2);
|
|
92
|
-
changes.addDelete("Like", "l1", { id: "l1" }, 3);
|
|
93
|
-
changes.addCreate("User", { id: "u1" }, 0);
|
|
94
|
-
changes.addDelete("Comment", "c2", { id: "c2" }, 2);
|
|
95
|
-
changes.addCreate("Post", { id: "p1" }, 1);
|
|
96
|
-
changes.addDelete("Post", "p2", { id: "p2" }, 1);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should order creates by depth ASC (root → leaf)", () => {
|
|
100
|
-
const creates = changes.creates();
|
|
101
|
-
expect(creates[0].entity).toBe("User"); // depth 0
|
|
102
|
-
expect(creates[1].entity).toBe("Post"); // depth 1
|
|
103
|
-
expect(creates[2].entity).toBe("Comment"); // depth 2
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("should order deletes by depth DESC (leaf → root)", () => {
|
|
107
|
-
const deletes = changes.deletes();
|
|
108
|
-
expect(deletes[0].entity).toBe("Like"); // depth 3
|
|
109
|
-
expect(deletes[1].entity).toBe("Comment"); // depth 2
|
|
110
|
-
expect(deletes[2].entity).toBe("Post"); // depth 1
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe("operations iterator", () => {
|
|
115
|
-
it("should yield operations in correct order: deletes, creates, updates", () => {
|
|
116
|
-
changes.addCreate("Post", { id: "p1" }, 1);
|
|
117
|
-
changes.addUpdate("User", "u1", { id: "u1" }, { name: "New" }, 0);
|
|
118
|
-
changes.addDelete("Comment", "c1", { id: "c1" }, 2);
|
|
119
|
-
|
|
120
|
-
const ops = [...changes.operations()];
|
|
121
|
-
|
|
122
|
-
expect(ops[0].type).toBe("delete"); // deletes first
|
|
123
|
-
expect(ops[1].type).toBe("create"); // creates second
|
|
124
|
-
expect(ops[2].type).toBe("update"); // updates last
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
describe("toBatchOperations", () => {
|
|
129
|
-
beforeEach(() => {
|
|
130
|
-
// Creates
|
|
131
|
-
changes.addCreate("User", { id: "u1" }, 0);
|
|
132
|
-
changes.addCreate("Post", { id: "p1" }, 1, "u1", "User");
|
|
133
|
-
changes.addCreate("Post", { id: "p2" }, 1, "u1", "User");
|
|
134
|
-
changes.addCreate("Comment", { id: "c1" }, 2, "p1", "Post");
|
|
135
|
-
|
|
136
|
-
// Updates
|
|
137
|
-
changes.addUpdate("User", "u2", { id: "u2" }, { name: "Updated" }, 0);
|
|
138
|
-
changes.addUpdate("Post", "p3", { id: "p3" }, { title: "New Title" }, 1);
|
|
139
|
-
|
|
140
|
-
// Deletes
|
|
141
|
-
changes.addDelete("Comment", "c2", { id: "c2" }, 2);
|
|
142
|
-
changes.addDelete("Comment", "c3", { id: "c3" }, 2);
|
|
143
|
-
changes.addDelete("Post", "p4", { id: "p4" }, 1);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("should group deletes by entity and order by depth DESC", () => {
|
|
147
|
-
const batch = changes.toBatchOperations();
|
|
148
|
-
|
|
149
|
-
expect(batch.deletes).toHaveLength(2); // Comment and Post
|
|
150
|
-
|
|
151
|
-
// Comments should come first (depth 2)
|
|
152
|
-
expect(batch.deletes[0].entity).toBe("Comment");
|
|
153
|
-
expect(batch.deletes[0].ids).toEqual(["c2", "c3"]);
|
|
154
|
-
|
|
155
|
-
// Posts second (depth 1)
|
|
156
|
-
expect(batch.deletes[1].entity).toBe("Post");
|
|
157
|
-
expect(batch.deletes[1].ids).toEqual(["p4"]);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it("should group creates by entity and order by depth ASC", () => {
|
|
161
|
-
const batch = changes.toBatchOperations();
|
|
162
|
-
|
|
163
|
-
expect(batch.creates).toHaveLength(3); // User, Post, Comment
|
|
164
|
-
|
|
165
|
-
// User first (depth 0)
|
|
166
|
-
expect(batch.creates[0].entity).toBe("User");
|
|
167
|
-
expect(batch.creates[0].items).toHaveLength(1);
|
|
168
|
-
|
|
169
|
-
// Post second (depth 1)
|
|
170
|
-
expect(batch.creates[1].entity).toBe("Post");
|
|
171
|
-
expect(batch.creates[1].items).toHaveLength(2);
|
|
172
|
-
|
|
173
|
-
// Comment last (depth 2)
|
|
174
|
-
expect(batch.creates[2].entity).toBe("Comment");
|
|
175
|
-
expect(batch.creates[2].items).toHaveLength(1);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("should group updates by entity", () => {
|
|
179
|
-
const batch = changes.toBatchOperations();
|
|
180
|
-
|
|
181
|
-
expect(batch.updates).toHaveLength(2); // User and Post
|
|
182
|
-
|
|
183
|
-
const userUpdates = batch.updates.find((u) => u.entity === "User");
|
|
184
|
-
expect(userUpdates?.items).toHaveLength(1);
|
|
185
|
-
expect(userUpdates?.items[0].id).toBe("u2");
|
|
186
|
-
|
|
187
|
-
const postUpdates = batch.updates.find((u) => u.entity === "Post");
|
|
188
|
-
expect(postUpdates?.items).toHaveLength(1);
|
|
189
|
-
expect(postUpdates?.items[0].id).toBe("p3");
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("should include parentId in create items", () => {
|
|
193
|
-
const batch = changes.toBatchOperations();
|
|
194
|
-
|
|
195
|
-
const postCreates = batch.creates.find((c) => c.entity === "Post");
|
|
196
|
-
expect(postCreates?.items[0].parentId).toBe("u1");
|
|
197
|
-
expect(postCreates?.items[1].parentId).toBe("u1");
|
|
198
|
-
|
|
199
|
-
const commentCreates = batch.creates.find((c) => c.entity === "Comment");
|
|
200
|
-
expect(commentCreates?.items[0].parentId).toBe("p1");
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
describe("for (filter by entity)", () => {
|
|
205
|
-
beforeEach(() => {
|
|
206
|
-
changes.addCreate("Post", { id: "p1", title: "Post 1" }, 1);
|
|
207
|
-
changes.addCreate("Post", { id: "p2", title: "Post 2" }, 1);
|
|
208
|
-
changes.addUpdate("Post", "p3", { id: "p3" }, { title: "Updated" }, 1);
|
|
209
|
-
changes.addDelete("Post", "p4", { id: "p4" }, 1);
|
|
210
|
-
changes.addCreate("Comment", { id: "c1" }, 2);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it("should filter creates by entity", () => {
|
|
214
|
-
const postChanges = changes.for("Post");
|
|
215
|
-
expect(postChanges.creates).toHaveLength(2);
|
|
216
|
-
expect(postChanges.creates[0].id).toBe("p1");
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("should filter updates by entity", () => {
|
|
220
|
-
const postChanges = changes.for("Post");
|
|
221
|
-
expect(postChanges.updates).toHaveLength(1);
|
|
222
|
-
expect(postChanges.updates[0].entity.id).toBe("p3");
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it("should filter deletes by entity", () => {
|
|
226
|
-
const postChanges = changes.for("Post");
|
|
227
|
-
expect(postChanges.deletes).toHaveLength(1);
|
|
228
|
-
expect(postChanges.deletes[0].id).toBe("p4");
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("should return empty for non-existent entity", () => {
|
|
232
|
-
const userChanges = changes.for("User");
|
|
233
|
-
expect(userChanges.isEmpty()).toBe(true);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it("should have helper methods", () => {
|
|
237
|
-
const postChanges = changes.for("Post");
|
|
238
|
-
expect(postChanges.hasCreates()).toBe(true);
|
|
239
|
-
expect(postChanges.hasUpdates()).toBe(true);
|
|
240
|
-
expect(postChanges.hasDeletes()).toBe(true);
|
|
241
|
-
expect(postChanges.hasChanges()).toBe(true);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
describe("getAffectedEntities", () => {
|
|
246
|
-
it("should return list of unique entities", () => {
|
|
247
|
-
changes.addCreate("User", { id: "u1" }, 0);
|
|
248
|
-
changes.addCreate("Post", { id: "p1" }, 1);
|
|
249
|
-
changes.addUpdate("Post", "p2", { id: "p2" }, {}, 1);
|
|
250
|
-
changes.addDelete("Comment", "c1", { id: "c1" }, 2);
|
|
251
|
-
|
|
252
|
-
const entities = changes.getAffectedEntities();
|
|
253
|
-
|
|
254
|
-
expect(entities).toContain("User");
|
|
255
|
-
expect(entities).toContain("Post");
|
|
256
|
-
expect(entities).toContain("Comment");
|
|
257
|
-
expect(entities).toHaveLength(3);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
describe("clone", () => {
|
|
262
|
-
it("should create independent copy", () => {
|
|
263
|
-
changes.addCreate("User", { id: "u1" }, 0);
|
|
264
|
-
|
|
265
|
-
const cloned = changes.clone();
|
|
266
|
-
cloned.addCreate("Post", { id: "p1" }, 1);
|
|
267
|
-
|
|
268
|
-
expect(changes.count).toBe(1);
|
|
269
|
-
expect(cloned.count).toBe(2);
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
describe("clear", () => {
|
|
274
|
-
it("should remove all operations", () => {
|
|
275
|
-
changes.addCreate("User", { id: "u1" }, 0);
|
|
276
|
-
changes.addUpdate("Post", "p1", { id: "p1" }, {}, 1);
|
|
277
|
-
|
|
278
|
-
changes.clear();
|
|
279
|
-
|
|
280
|
-
expect(changes.isEmpty()).toBe(true);
|
|
281
|
-
expect(changes.count).toBe(0);
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
});
|