declastruct 1.3.0 → 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 (57) hide show
  1. package/dist/domain.objects/ContextDeclastruct.d.ts +1 -1
  2. package/dist/domain.objects/DeclastructChange.d.ts +1 -1
  3. package/dist/domain.objects/DeclastructChange.js.map +1 -1
  4. package/dist/domain.objects/DeclastructDao.d.ts +2 -2
  5. package/dist/domain.objects/DeclastructPlan.d.ts +2 -2
  6. package/dist/domain.objects/DeclastructProvider.d.ts +1 -1
  7. package/dist/domain.operations/plan/computeChange.js +2 -28
  8. package/dist/domain.operations/plan/computeChange.js.map +1 -1
  9. package/dist/domain.operations/plan/getDisplayableDiff.d.ts +10 -0
  10. package/dist/domain.operations/plan/getDisplayableDiff.js +40 -0
  11. package/dist/domain.operations/plan/getDisplayableDiff.js.map +1 -0
  12. package/dist/infra/asIsoTimestamp.d.ts +1 -1
  13. package/license.md +21 -0
  14. package/package.json +19 -9
  15. package/readme.md +52 -32
  16. package/dist/.test/assets/providers/demo.provider.d.ts +0 -32
  17. package/dist/.test/assets/providers/demo.provider.js +0 -101
  18. package/dist/.test/assets/providers/demo.provider.js.map +0 -1
  19. package/dist/contract/cli/apply.integration.test.d.ts +0 -1
  20. package/dist/contract/cli/apply.integration.test.js +0 -215
  21. package/dist/contract/cli/apply.integration.test.js.map +0 -1
  22. package/dist/contract/cli/plan.integration.test.d.ts +0 -1
  23. package/dist/contract/cli/plan.integration.test.js +0 -142
  24. package/dist/contract/cli/plan.integration.test.js.map +0 -1
  25. package/dist/domain.objects/ContextDeclastruct.test.d.ts +0 -1
  26. package/dist/domain.objects/ContextDeclastruct.test.js +0 -41
  27. package/dist/domain.objects/ContextDeclastruct.test.js.map +0 -1
  28. package/dist/domain.objects/DeclastructChange.test.d.ts +0 -1
  29. package/dist/domain.objects/DeclastructChange.test.js +0 -59
  30. package/dist/domain.objects/DeclastructChange.test.js.map +0 -1
  31. package/dist/domain.objects/DeclastructDao.test.d.ts +0 -1
  32. package/dist/domain.objects/DeclastructDao.test.js +0 -78
  33. package/dist/domain.objects/DeclastructDao.test.js.map +0 -1
  34. package/dist/domain.objects/DeclastructPlan.test.d.ts +0 -1
  35. package/dist/domain.objects/DeclastructPlan.test.js +0 -31
  36. package/dist/domain.objects/DeclastructPlan.test.js.map +0 -1
  37. package/dist/domain.objects/DeclastructProvider.test.d.ts +0 -1
  38. package/dist/domain.objects/DeclastructProvider.test.js +0 -80
  39. package/dist/domain.objects/DeclastructProvider.test.js.map +0 -1
  40. package/dist/domain.objects/IsoTimestamp.test.d.ts +0 -1
  41. package/dist/domain.objects/IsoTimestamp.test.js +0 -10
  42. package/dist/domain.objects/IsoTimestamp.test.js.map +0 -1
  43. package/dist/domain.operations/apply/applyChange.test.d.ts +0 -1
  44. package/dist/domain.operations/apply/applyChange.test.js +0 -241
  45. package/dist/domain.operations/apply/applyChange.test.js.map +0 -1
  46. package/dist/domain.operations/apply/applyChanges.integration.test.d.ts +0 -1
  47. package/dist/domain.operations/apply/applyChanges.integration.test.js +0 -291
  48. package/dist/domain.operations/apply/applyChanges.integration.test.js.map +0 -1
  49. package/dist/domain.operations/plan/computeChange.test.d.ts +0 -1
  50. package/dist/domain.operations/plan/computeChange.test.js +0 -153
  51. package/dist/domain.operations/plan/computeChange.test.js.map +0 -1
  52. package/dist/domain.operations/plan/getDaoByResource.test.d.ts +0 -1
  53. package/dist/domain.operations/plan/getDaoByResource.test.js +0 -101
  54. package/dist/domain.operations/plan/getDaoByResource.test.js.map +0 -1
  55. package/dist/domain.operations/plan/planChanges.integration.test.d.ts +0 -1
  56. package/dist/domain.operations/plan/planChanges.integration.test.js +0 -200
  57. package/dist/domain.operations/plan/planChanges.integration.test.js.map +0 -1
@@ -1 +0,0 @@
1
- export {};
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const domain_objects_1 = require("domain-objects");
4
- const DeclastructProvider_1 = require("./DeclastructProvider");
5
- describe('DeclastructProvider', () => {
6
- it('should build a provider with all required properties', () => {
7
- const provider = new DeclastructProvider_1.DeclastructProvider({
8
- name: 'test-provider',
9
- daos: {},
10
- context: {},
11
- hooks: {
12
- beforeAll: async () => { },
13
- afterAll: async () => { },
14
- },
15
- });
16
- expect(provider.name).toBe('test-provider');
17
- expect(provider.daos).toEqual({});
18
- expect(provider.context).toEqual({});
19
- expect(provider.hooks.beforeAll).toBeDefined();
20
- expect(provider.hooks.afterAll).toBeDefined();
21
- });
22
- it('should work without explicit type arguments', () => {
23
- // type verification - default type parameters should work
24
- const provider = new DeclastructProvider_1.DeclastructProvider({
25
- name: 'default-provider',
26
- daos: {},
27
- context: {},
28
- hooks: {
29
- beforeAll: async () => { },
30
- afterAll: async () => { },
31
- },
32
- });
33
- expect(provider).toBeDefined();
34
- });
35
- describe('resource with optional primary key', () => {
36
- class DemoResourceWithOptionalPrimary extends domain_objects_1.DomainEntity {
37
- }
38
- DemoResourceWithOptionalPrimary.primary = ['uuid'];
39
- DemoResourceWithOptionalPrimary.unique = ['name'];
40
- it('should work with daos that have optional primary keys and byPrimary defined', () => {
41
- // define a dao for the resource with optional primary key
42
- const demoDao = {
43
- get: {
44
- byUnique: async () => null,
45
- byPrimary: async (input) => {
46
- // input.uuid should be string (not string | undefined)
47
- const uuid = input.uuid;
48
- expect(uuid).toBeDefined();
49
- return null;
50
- },
51
- byRef: async () => null,
52
- },
53
- set: {
54
- finsert: async (r) => r,
55
- },
56
- };
57
- // build provider with the dao
58
- const provider = new DeclastructProvider_1.DeclastructProvider({
59
- name: 'optional-primary-key-provider',
60
- daos: {
61
- DemoResourceWithOptionalPrimary: demoDao,
62
- },
63
- context: {},
64
- hooks: {
65
- beforeAll: async () => { },
66
- afterAll: async () => { },
67
- },
68
- });
69
- // verify provider structure
70
- expect(provider.name).toBe('optional-primary-key-provider');
71
- expect(provider.daos.DemoResourceWithOptionalPrimary).toBeDefined();
72
- // access dao to verify structure
73
- const dao = provider.daos.DemoResourceWithOptionalPrimary;
74
- expect(dao?.get.byPrimary).toBeDefined();
75
- expect(dao?.get.byUnique).toBeDefined();
76
- expect(dao?.set.finsert).toBeDefined();
77
- });
78
- });
79
- });
80
- //# sourceMappingURL=DeclastructProvider.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeclastructProvider.test.js","sourceRoot":"","sources":["../../src/domain.objects/DeclastructProvider.test.ts"],"names":[],"mappings":";;AAAA,mDAA8C;AAG9C,+DAA4D;AAE5D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,QAAQ,GAAG,IAAI,yCAAmB,CAAC;YACvC,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,EAAE;YACX,KAAK,EAAE;gBACL,SAAS,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;gBACzB,QAAQ,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;aACzB;SACF,CAAC,CAAC;QAEH,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5C,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAClC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACrC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QAC/C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,0DAA0D;QAC1D,MAAM,QAAQ,GAAG,IAAI,yCAAmB,CAAC;YACvC,IAAI,EAAE,kBAAkB;YACxB,IAAI,EA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,CAAC,CAAC;YAEH,4BAA4B;YAC5B,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;YAC5D,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC,WAAW,EAAE,CAAC;YAEpE,iCAAiC;YACjC,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,+BAA+B,CAAC;YAC1D,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;YACzC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YACxC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- describe('IsoTimestamp', () => {
4
- it('should be a string type', () => {
5
- // type verification
6
- const timestamp = '2025-11-22T10:30:00.000Z';
7
- expect(typeof timestamp).toBe('string');
8
- });
9
- });
10
- //# sourceMappingURL=IsoTimestamp.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IsoTimestamp.test.js","sourceRoot":"","sources":["../../src/domain.objects/IsoTimestamp.test.ts"],"names":[],"mappings":";;AAEA,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;QACjC,oBAAoB;QACpB,MAAM,SAAS,GAAiB,0BAA0B,CAAC;QAC3D,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,241 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const domain_objects_1 = require("domain-objects");
4
- const helpful_errors_1 = require("helpful-errors");
5
- const DeclastructChange_1 = require("../../domain.objects/DeclastructChange");
6
- const DeclastructProvider_1 = require("../../domain.objects/DeclastructProvider");
7
- const applyChange_1 = require("./applyChange");
8
- describe('applyChange', () => {
9
- class DemoResource extends domain_objects_1.DomainEntity {
10
- }
11
- DemoResource.unique = ['id'];
12
- it('should return immediately for KEEP action without calling DAO', async () => {
13
- const resource = new DemoResource({ id: 'keep-1', name: 'Keep Me' });
14
- const change = new DeclastructChange_1.DeclastructChange({
15
- forResource: {
16
- class: DemoResource.name,
17
- slug: 'keep-1',
18
- },
19
- action: DeclastructChange_1.DeclastructChangeAction.KEEP,
20
- state: {
21
- desired: resource,
22
- remote: resource,
23
- difference: null,
24
- },
25
- });
26
- const result = await (0, applyChange_1.applyChange)({
27
- resource,
28
- change,
29
- providers: [],
30
- });
31
- expect(result).toBe(change);
32
- });
33
- it('should call finsert for CREATE action', async () => {
34
- const resource = new DemoResource({ id: 'create-1', name: 'Create Me' });
35
- const finsertSpy = jest.fn().mockResolvedValue(resource);
36
- const dao = {
37
- get: {
38
- byUnique: async () => null,
39
- byRef: async () => null,
40
- },
41
- set: {
42
- finsert: finsertSpy,
43
- },
44
- };
45
- const provider = new DeclastructProvider_1.DeclastructProvider({
46
- name: 'test-provider',
47
- daos: { DemoResource: dao },
48
- context: {},
49
- hooks: {
50
- beforeAll: async () => { },
51
- afterAll: async () => { },
52
- },
53
- });
54
- const change = new DeclastructChange_1.DeclastructChange({
55
- forResource: {
56
- class: DemoResource.name,
57
- slug: 'create-1',
58
- },
59
- action: DeclastructChange_1.DeclastructChangeAction.CREATE,
60
- state: {
61
- desired: resource,
62
- remote: null,
63
- difference: 'some diff',
64
- },
65
- });
66
- await (0, applyChange_1.applyChange)({
67
- resource,
68
- change,
69
- providers: [provider],
70
- });
71
- expect(finsertSpy).toHaveBeenCalledWith(resource, {});
72
- });
73
- it('should call upsert for UPDATE action', async () => {
74
- const remote = new DemoResource({ id: 'update-1', name: 'Old Name' });
75
- const desired = new DemoResource({ id: 'update-1', name: 'New Name' });
76
- const upsertSpy = jest.fn().mockResolvedValue(desired);
77
- const dao = {
78
- get: {
79
- byUnique: async () => null,
80
- byRef: async () => null,
81
- },
82
- set: {
83
- finsert: async (input) => input,
84
- upsert: upsertSpy,
85
- },
86
- };
87
- const provider = new DeclastructProvider_1.DeclastructProvider({
88
- name: 'test-provider',
89
- daos: { DemoResource: dao },
90
- context: {},
91
- hooks: {
92
- beforeAll: async () => { },
93
- afterAll: async () => { },
94
- },
95
- });
96
- const change = new DeclastructChange_1.DeclastructChange({
97
- forResource: {
98
- class: DemoResource.name,
99
- slug: 'update-1',
100
- },
101
- action: DeclastructChange_1.DeclastructChangeAction.UPDATE,
102
- state: {
103
- desired,
104
- remote,
105
- difference: 'some diff',
106
- },
107
- });
108
- await (0, applyChange_1.applyChange)({
109
- resource: desired,
110
- change,
111
- providers: [provider],
112
- });
113
- expect(upsertSpy).toHaveBeenCalledWith(desired, {});
114
- });
115
- it('should throw when UPDATE action but DAO does not support upsert', async () => {
116
- const remote = new DemoResource({ id: 'update-1', name: 'Old Name' });
117
- const desired = new DemoResource({ id: 'update-1', name: 'New Name' });
118
- const dao = {
119
- get: {
120
- byUnique: async () => null,
121
- byRef: async () => null,
122
- },
123
- set: {
124
- finsert: async (input) => input,
125
- },
126
- };
127
- const provider = new DeclastructProvider_1.DeclastructProvider({
128
- name: 'test-provider',
129
- daos: { DemoResource: dao },
130
- context: {},
131
- hooks: {
132
- beforeAll: async () => { },
133
- afterAll: async () => { },
134
- },
135
- });
136
- const change = new DeclastructChange_1.DeclastructChange({
137
- forResource: {
138
- class: DemoResource.name,
139
- slug: 'update-1',
140
- },
141
- action: DeclastructChange_1.DeclastructChangeAction.UPDATE,
142
- state: {
143
- desired,
144
- remote,
145
- difference: 'some diff',
146
- },
147
- });
148
- const error = await (0, helpful_errors_1.getError)(() => (0, applyChange_1.applyChange)({
149
- resource: desired,
150
- change,
151
- providers: [provider],
152
- }));
153
- expect(error.message).toContain('DAO does not support updates');
154
- });
155
- it('should call delete for DESTROY action', async () => {
156
- const resource = new DemoResource({ id: 'destroy-1', name: 'Delete Me' });
157
- const deleteSpy = jest.fn().mockResolvedValue(undefined);
158
- const dao = {
159
- get: {
160
- byUnique: async () => null,
161
- byRef: async () => null,
162
- },
163
- set: {
164
- finsert: async (input) => input,
165
- delete: deleteSpy,
166
- },
167
- };
168
- const provider = new DeclastructProvider_1.DeclastructProvider({
169
- name: 'test-provider',
170
- daos: { DemoResource: dao },
171
- context: {},
172
- hooks: {
173
- beforeAll: async () => { },
174
- afterAll: async () => { },
175
- },
176
- });
177
- const change = new DeclastructChange_1.DeclastructChange({
178
- forResource: {
179
- class: DemoResource.name,
180
- slug: 'destroy-1',
181
- },
182
- action: DeclastructChange_1.DeclastructChangeAction.DESTROY,
183
- state: {
184
- desired: null,
185
- remote: resource,
186
- difference: 'some diff',
187
- },
188
- });
189
- await (0, applyChange_1.applyChange)({
190
- resource,
191
- change,
192
- providers: [provider],
193
- });
194
- expect(deleteSpy).toHaveBeenCalledWith(resource, {});
195
- });
196
- it('should call delete then finsert for REPLACE action', async () => {
197
- const remote = new DemoResource({ id: 'replace-1', name: 'Old' });
198
- const desired = new DemoResource({ id: 'replace-2', name: 'New' });
199
- const deleteSpy = jest.fn().mockResolvedValue(undefined);
200
- const finsertSpy = jest.fn().mockResolvedValue(desired);
201
- const dao = {
202
- get: {
203
- byUnique: async () => null,
204
- byRef: async () => null,
205
- },
206
- set: {
207
- finsert: finsertSpy,
208
- delete: deleteSpy,
209
- },
210
- };
211
- const provider = new DeclastructProvider_1.DeclastructProvider({
212
- name: 'test-provider',
213
- daos: { DemoResource: dao },
214
- context: {},
215
- hooks: {
216
- beforeAll: async () => { },
217
- afterAll: async () => { },
218
- },
219
- });
220
- const change = new DeclastructChange_1.DeclastructChange({
221
- forResource: {
222
- class: DemoResource.name,
223
- slug: 'replace-1',
224
- },
225
- action: DeclastructChange_1.DeclastructChangeAction.REPLACE,
226
- state: {
227
- desired,
228
- remote,
229
- difference: 'some diff',
230
- },
231
- });
232
- await (0, applyChange_1.applyChange)({
233
- resource: desired,
234
- change,
235
- providers: [provider],
236
- });
237
- expect(deleteSpy).toHaveBeenCalledWith(remote, {});
238
- expect(finsertSpy).toHaveBeenCalledWith(desired, {});
239
- });
240
- });
241
- //# sourceMappingURL=applyChange.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"applyChange.test.js","sourceRoot":"","sources":["../../../src/domain.operations/apply/applyChange.test.ts"],"names":[],"mappings":";;AAAA,mDAA8C;AAC9C,mDAA0C;AAE1C,8EAGgD;AAEhD,kFAA+E;AAC/E,+CAA4C;AAE5C,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAM3B,MAAM,YACJ,SAAQ,6BAA0B;;IAGpB,mBAAM,GAAG,CAAC,IAAI,CAAU,CAAC;IAGzC,EAAE,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;QAC7E,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QAErE,MAAM,MAAM,GAAG,IAAI,qCAAiB,CAAC;YACnC,WAAW,EAAE;gBACX,KAAK,EAAE,YAAY,CAAC,IAAI;gBACxB,IAAI,EAAE,QAAQ;aACf;YACD,MAAM,EAAE,2CAAuB,CAAC,IAAI;YACpC,KAAK,EAAE;gBACL,OAAO,EAAE,QAAQ;gBACjB,MAAM,EAAE,QAAQ;gBAChB,UAAU,EAAE,IAAI;aACjB;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAM,IAAA,yBAAW,EAAC;YAC/B,QAAQ;YACR,MAAM;YACN,SAAS,EAAE,EAAE;SACd,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,C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AAS,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;gBACzB,QAAQ,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;aACzB;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,IAAI,qCAAiB,CAAC;YACnC,WAAW,EAAE;gBACX,KAAK,EAAE,YAAY,CAAC,IAAI;gBACxB,IAAI,EAAE,WAAW;aAClB;YACD,MAAM,EAAE,2CAAuB,CAAC,OAAO;YACvC,KAAK,EAAE;gBACL,OAAO;gBACP,MAAM;gBACN,UAAU,EAAE,WAAW;aACxB;SACF,CAAC,CAAC;QAEH,MAAM,IAAA,yBAAW,EAAC;YAChB,QAAQ,EAAE,OAAO;YACjB,MAAM;YACN,SAAS,EAAE,CAAC,QAAQ,CAAC;SACtB,CAAC,CAAC;QAEH,MAAM,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACnD,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,291 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const bottleneck_1 = __importDefault(require("bottleneck"));
7
- const fs_1 = require("fs");
8
- const promises_1 = require("fs/promises");
9
- const path_1 = require("path");
10
- const demo_provider_1 = require("../../.test/assets/providers/demo.provider");
11
- const DeclastructChange_1 = require("../../domain.objects/DeclastructChange");
12
- const planChanges_1 = require("../plan/planChanges");
13
- const applyChanges_1 = require("./applyChanges");
14
- describe('applyChanges', () => {
15
- const wishFilePath = (0, path_1.resolve)(process.cwd(), 'src/.test/assets/wish.fixture.ts');
16
- beforeAll(async () => {
17
- // initialize provider (creates temp directory)
18
- await demo_provider_1.demoProvider.hooks.beforeAll();
19
- });
20
- const createContext = () => ({
21
- bottleneck: new bottleneck_1.default({ maxConcurrent: 1 }),
22
- log: {
23
- info: jest.fn(),
24
- error: jest.fn(),
25
- warn: jest.fn(),
26
- debug: jest.fn(),
27
- },
28
- });
29
- it('should apply CREATE changes and verify files created on disk', async () => {
30
- // define desired resources with automatic unique IDs
31
- const resources = [
32
- (0, demo_provider_1.genSampleDemoResource)({ name: 'First Test' }),
33
- (0, demo_provider_1.genSampleDemoResource)({ name: 'Second Test' }),
34
- ];
35
- // plan changes
36
- const plan = await (0, planChanges_1.planChanges)({
37
- resources,
38
- providers: [demo_provider_1.demoProvider],
39
- wishFilePath,
40
- }, createContext());
41
- // verify plan has CREATE actions
42
- expect(plan.changes.every((c) => c.action === DeclastructChange_1.DeclastructChangeAction.CREATE)).toBe(true);
43
- // apply changes
44
- const result = await (0, applyChanges_1.applyChanges)({
45
- plan,
46
- resources,
47
- providers: [demo_provider_1.demoProvider],
48
- }, createContext());
49
- // verify changes were applied
50
- expect(result.appliedChanges.length).toBe(2);
51
- result.appliedChanges.forEach((change) => {
52
- expect(change.action).toBe(DeclastructChange_1.DeclastructChangeAction.CREATE);
53
- });
54
- // verify files exist on disk
55
- const file1Path = (0, path_1.resolve)(process.cwd(), `.test/demo/provider/.temp/${resources[0].exid}.json`);
56
- const file2Path = (0, path_1.resolve)(process.cwd(), `.test/demo/provider/.temp/${resources[1].exid}.json`);
57
- expect((0, fs_1.existsSync)(file1Path)).toBe(true);
58
- expect((0, fs_1.existsSync)(file2Path)).toBe(true);
59
- // verify file contents
60
- const file1Json = await (0, promises_1.readFile)(file1Path, 'utf-8');
61
- const file1Data = JSON.parse(file1Json);
62
- expect(file1Data.exid).toBe(resources[0].exid);
63
- expect(file1Data.name).toBe('First Test');
64
- const file2Json = await (0, promises_1.readFile)(file2Path, 'utf-8');
65
- const file2Data = JSON.parse(file2Json);
66
- expect(file2Data.exid).toBe(resources[1].exid);
67
- expect(file2Data.name).toBe('Second Test');
68
- });
69
- it('should apply UPDATE changes and verify files modified on disk', async () => {
70
- // create initial resource
71
- const initialResource = (0, demo_provider_1.genSampleDemoResource)({ name: 'Old Name' });
72
- // create initial remote state
73
- const dao = demo_provider_1.demoProvider.daos.DemoResource;
74
- await dao.set.finsert(initialResource, {});
75
- // define desired resource with updated name (same exid)
76
- const resources = [initialResource.clone({ name: 'New Name' })];
77
- // plan changes
78
- const plan = await (0, planChanges_1.planChanges)({
79
- resources,
80
- providers: [demo_provider_1.demoProvider],
81
- wishFilePath,
82
- }, createContext());
83
- // verify plan has UPDATE action
84
- expect(plan.changes.length).toBe(1);
85
- expect(plan.changes[0].action).toBe(DeclastructChange_1.DeclastructChangeAction.UPDATE);
86
- // apply changes
87
- const result = await (0, applyChanges_1.applyChanges)({
88
- plan,
89
- resources,
90
- providers: [demo_provider_1.demoProvider],
91
- }, createContext());
92
- // verify update was applied
93
- expect(result.appliedChanges.length).toBe(1);
94
- expect(result.appliedChanges[0].action).toBe(DeclastructChange_1.DeclastructChangeAction.UPDATE);
95
- // verify file was updated on disk
96
- const filePath = (0, path_1.resolve)(process.cwd(), `.test/demo/provider/.temp/${initialResource.exid}.json`);
97
- const fileJson = await (0, promises_1.readFile)(filePath, 'utf-8');
98
- const fileData = JSON.parse(fileJson);
99
- expect(fileData.name).toBe('New Name');
100
- });
101
- it('should skip KEEP changes without making modifications', async () => {
102
- // create resource
103
- const resource = (0, demo_provider_1.genSampleDemoResource)({ name: 'Unchanged' });
104
- // create remote state
105
- const dao = demo_provider_1.demoProvider.daos.DemoResource;
106
- await dao.set.finsert(resource, {});
107
- // define same resource (no changes)
108
- const resources = [resource];
109
- // plan changes
110
- const plan = await (0, planChanges_1.planChanges)({
111
- resources,
112
- providers: [demo_provider_1.demoProvider],
113
- wishFilePath,
114
- }, createContext());
115
- // verify plan has KEEP action
116
- expect(plan.changes.length).toBe(1);
117
- expect(plan.changes[0].action).toBe(DeclastructChange_1.DeclastructChangeAction.KEEP);
118
- // apply changes
119
- const context = createContext();
120
- const result = await (0, applyChanges_1.applyChanges)({
121
- plan,
122
- resources,
123
- providers: [demo_provider_1.demoProvider],
124
- }, context);
125
- // verify KEEP was not included in applied changes
126
- expect(result.appliedChanges.length).toBe(0);
127
- // verify log was emitted for KEEP
128
- expect(context.log.info).toHaveBeenCalledWith(expect.stringContaining('[KEEP]'), {});
129
- // verify file still exists with same content
130
- const filePath = (0, path_1.resolve)(process.cwd(), `.test/demo/provider/.temp/${resource.exid}.json`);
131
- const fileJson = await (0, promises_1.readFile)(filePath, 'utf-8');
132
- const fileData = JSON.parse(fileJson);
133
- expect(fileData.name).toBe('Unchanged');
134
- });
135
- it('should emit real-time logs as changes are applied', async () => {
136
- // define resources
137
- const resources = [
138
- (0, demo_provider_1.genSampleDemoResource)({ name: 'First Test' }),
139
- (0, demo_provider_1.genSampleDemoResource)({ name: 'Second Test' }),
140
- ];
141
- // plan changes
142
- const plan = await (0, planChanges_1.planChanges)({
143
- resources,
144
- providers: [demo_provider_1.demoProvider],
145
- wishFilePath,
146
- }, createContext());
147
- // apply with spy on log
148
- const context = createContext();
149
- await (0, applyChanges_1.applyChanges)({
150
- plan,
151
- resources,
152
- providers: [demo_provider_1.demoProvider],
153
- }, context);
154
- // verify logs were emitted (logs include the full slug with hash)
155
- expect(context.log.info).toHaveBeenCalledWith(expect.stringContaining(`[CREATE] DemoResource.`), {});
156
- expect(context.log.info).toHaveBeenCalled();
157
- });
158
- it('should handle mixed CREATE, UPDATE, and KEEP actions in single apply', async () => {
159
- // create initial resources for remote state
160
- const resource1 = (0, demo_provider_1.genSampleDemoResource)({ name: 'Unchanged' });
161
- const resource2 = (0, demo_provider_1.genSampleDemoResource)({ name: 'Old Name' });
162
- // create remote state for some resources
163
- const dao = demo_provider_1.demoProvider.daos.DemoResource;
164
- await dao.set.finsert(resource1, {});
165
- await dao.set.finsert(resource2, {});
166
- // define desired resources
167
- const resources = [
168
- resource1, // KEEP (unchanged)
169
- resource2.clone({ name: 'New Name' }), // UPDATE
170
- (0, demo_provider_1.genSampleDemoResource)({ name: 'Brand New' }), // CREATE
171
- ];
172
- // plan changes
173
- const plan = await (0, planChanges_1.planChanges)({
174
- resources,
175
- providers: [demo_provider_1.demoProvider],
176
- wishFilePath,
177
- }, createContext());
178
- // verify mixed actions in plan
179
- expect(plan.changes.length).toBe(3);
180
- // apply changes
181
- const result = await (0, applyChanges_1.applyChanges)({
182
- plan,
183
- resources,
184
- providers: [demo_provider_1.demoProvider],
185
- }, createContext());
186
- // verify only CREATE and UPDATE were applied (not KEEP)
187
- expect(result.appliedChanges.length).toBe(2);
188
- const appliedActions = result.appliedChanges.map((c) => c.action);
189
- expect(appliedActions).toContain(DeclastructChange_1.DeclastructChangeAction.UPDATE);
190
- expect(appliedActions).toContain(DeclastructChange_1.DeclastructChangeAction.CREATE);
191
- // verify all files exist with correct content
192
- const file1Path = (0, path_1.resolve)(process.cwd(), `.test/demo/provider/.temp/${resources[0].exid}.json`);
193
- const file2Path = (0, path_1.resolve)(process.cwd(), `.test/demo/provider/.temp/${resources[1].exid}.json`);
194
- const file3Path = (0, path_1.resolve)(process.cwd(), `.test/demo/provider/.temp/${resources[2].exid}.json`);
195
- expect((0, fs_1.existsSync)(file1Path)).toBe(true);
196
- expect((0, fs_1.existsSync)(file2Path)).toBe(true);
197
- expect((0, fs_1.existsSync)(file3Path)).toBe(true);
198
- const file2Json = await (0, promises_1.readFile)(file2Path, 'utf-8');
199
- const file2Data = JSON.parse(file2Json);
200
- expect(file2Data.name).toBe('New Name');
201
- });
202
- it('should detect and reject stale plans', async () => {
203
- // define initial resource
204
- const initialResources = [(0, demo_provider_1.genSampleDemoResource)({ name: 'Original Name' })];
205
- // plan changes
206
- const plan = await (0, planChanges_1.planChanges)({
207
- resources: initialResources,
208
- providers: [demo_provider_1.demoProvider],
209
- wishFilePath,
210
- }, createContext());
211
- // apply the plan (creates the resource)
212
- await (0, applyChanges_1.applyChanges)({
213
- plan,
214
- resources: initialResources,
215
- providers: [demo_provider_1.demoProvider],
216
- }, createContext());
217
- // externally modify the resource
218
- const dao = demo_provider_1.demoProvider.daos.DemoResource;
219
- await dao.set.upsert(initialResources[0].clone({ name: 'Externally Modified' }), {});
220
- // try to reapply the stale plan
221
- await expect((0, applyChanges_1.applyChanges)({
222
- plan, // stale plan still shows "Original Name"
223
- resources: initialResources,
224
- providers: [demo_provider_1.demoProvider],
225
- }, createContext())).rejects.toThrow();
226
- });
227
- it('should be idempotent - reapplying same plan is safe', async () => {
228
- // define resource
229
- const resources = [(0, demo_provider_1.genSampleDemoResource)({ name: 'Test Resource' })];
230
- // plan changes
231
- const plan = await (0, planChanges_1.planChanges)({
232
- resources,
233
- providers: [demo_provider_1.demoProvider],
234
- wishFilePath,
235
- }, createContext());
236
- // apply first time
237
- const result1 = await (0, applyChanges_1.applyChanges)({
238
- plan,
239
- resources,
240
- providers: [demo_provider_1.demoProvider],
241
- }, createContext());
242
- expect(result1.appliedChanges.length).toBe(1);
243
- expect(result1.appliedChanges[0].action).toBe(DeclastructChange_1.DeclastructChangeAction.CREATE);
244
- // replan with same resources
245
- const plan2 = await (0, planChanges_1.planChanges)({
246
- resources,
247
- providers: [demo_provider_1.demoProvider],
248
- wishFilePath,
249
- }, createContext());
250
- // apply second time
251
- const result2 = await (0, applyChanges_1.applyChanges)({
252
- plan: plan2,
253
- resources,
254
- providers: [demo_provider_1.demoProvider],
255
- }, createContext());
256
- // verify second apply was KEEP (no changes)
257
- expect(result2.appliedChanges.length).toBe(0);
258
- expect(plan2.changes[0].action).toBe(DeclastructChange_1.DeclastructChangeAction.KEEP);
259
- // verify file exists with correct content
260
- const filePath = (0, path_1.resolve)(process.cwd(), `.test/demo/provider/.temp/${resources[0].exid}.json`);
261
- const fileJson = await (0, promises_1.readFile)(filePath, 'utf-8');
262
- const fileData = JSON.parse(fileJson);
263
- expect(fileData.name).toBe('Test Resource');
264
- });
265
- it('should validate plan before applying to ensure it is still valid', async () => {
266
- // define resource
267
- const resources = [(0, demo_provider_1.genSampleDemoResource)({ name: 'Test Resource' })];
268
- // plan changes
269
- const originalPlan = await (0, planChanges_1.planChanges)({
270
- resources,
271
- providers: [demo_provider_1.demoProvider],
272
- wishFilePath,
273
- }, createContext());
274
- // apply the plan (creates the resource)
275
- await (0, applyChanges_1.applyChanges)({
276
- plan: originalPlan,
277
- resources,
278
- providers: [demo_provider_1.demoProvider],
279
- }, createContext());
280
- // externally modify the remote resource to make original plan stale
281
- const dao = demo_provider_1.demoProvider.daos.DemoResource;
282
- await dao.set.upsert(resources[0].clone({ name: 'Externally Modified' }), {});
283
- // try to apply the stale plan again
284
- await expect((0, applyChanges_1.applyChanges)({
285
- plan: originalPlan, // stale - remote state changed
286
- resources,
287
- providers: [demo_provider_1.demoProvider],
288
- }, createContext())).rejects.toThrow('plan is stale');
289
- });
290
- });
291
- //# sourceMappingURL=applyChanges.integration.test.js.map