declastruct 1.0.0 → 1.1.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/.test/assets/providers/demo.provider.d.ts +32 -0
- package/dist/.test/assets/providers/demo.provider.js +101 -0
- package/dist/.test/assets/providers/demo.provider.js.map +1 -0
- package/dist/contract/cli/apply.d.ts +9 -0
- package/dist/contract/cli/apply.integration.test.js +148 -0
- package/dist/contract/cli/apply.integration.test.js.map +1 -0
- package/dist/contract/cli/apply.js +90 -0
- package/dist/contract/cli/apply.js.map +1 -0
- package/dist/contract/cli/invoke.d.ts +8 -0
- package/dist/contract/cli/invoke.js +58 -0
- package/dist/contract/cli/invoke.js.map +1 -0
- package/dist/contract/cli/plan.d.ts +10 -0
- package/dist/contract/cli/plan.integration.test.js +107 -0
- package/dist/contract/cli/plan.integration.test.js.map +1 -0
- package/dist/contract/cli/plan.js +94 -0
- package/dist/contract/cli/plan.js.map +1 -0
- package/dist/contract/sdk/index.d.ts +15 -3
- package/dist/contract/sdk/index.js +31 -17
- package/dist/contract/sdk/index.js.map +1 -1
- package/dist/domain.objects/ContextDeclastruct.d.ts +15 -0
- package/dist/{domain/DeclastructContext.js → domain.objects/ContextDeclastruct.js} +1 -1
- package/dist/domain.objects/ContextDeclastruct.js.map +1 -0
- package/dist/domain.objects/ContextDeclastruct.test.js +41 -0
- package/dist/domain.objects/ContextDeclastruct.test.js.map +1 -0
- package/dist/domain.objects/DeclastructChange.d.ts +73 -0
- package/dist/domain.objects/DeclastructChange.js +35 -0
- package/dist/domain.objects/DeclastructChange.js.map +1 -0
- package/dist/domain.objects/DeclastructChange.test.js +59 -0
- package/dist/domain.objects/DeclastructChange.test.js.map +1 -0
- package/dist/domain.objects/DeclastructDao.d.ts +39 -0
- package/dist/domain.objects/DeclastructDao.js +8 -0
- package/dist/domain.objects/DeclastructDao.js.map +1 -0
- package/dist/domain.objects/DeclastructDao.test.js +42 -0
- package/dist/domain.objects/DeclastructDao.test.js.map +1 -0
- package/dist/domain.objects/DeclastructPlan.d.ts +35 -0
- package/dist/domain.objects/DeclastructPlan.js +11 -0
- package/dist/domain.objects/DeclastructPlan.js.map +1 -0
- package/dist/domain.objects/DeclastructPlan.test.js +31 -0
- package/dist/domain.objects/DeclastructPlan.test.js.map +1 -0
- package/dist/domain.objects/DeclastructProvider.d.ts +30 -0
- package/dist/domain.objects/DeclastructProvider.js +8 -0
- package/dist/domain.objects/DeclastructProvider.js.map +1 -0
- package/dist/domain.objects/DeclastructProvider.test.js +35 -0
- package/dist/domain.objects/DeclastructProvider.test.js.map +1 -0
- package/dist/domain.objects/IsoTimestamp.d.ts +6 -0
- package/dist/{domain/DeclaredResource.js → domain.objects/IsoTimestamp.js} +1 -1
- package/dist/domain.objects/IsoTimestamp.js.map +1 -0
- package/dist/domain.objects/IsoTimestamp.test.js +10 -0
- package/dist/domain.objects/IsoTimestamp.test.js.map +1 -0
- package/dist/domain.operations/apply/applyChange.d.ts +14 -0
- package/dist/domain.operations/apply/applyChange.js +64 -0
- package/dist/domain.operations/apply/applyChange.js.map +1 -0
- package/dist/domain.operations/apply/applyChange.test.d.ts +1 -0
- package/dist/domain.operations/apply/applyChange.test.js +247 -0
- package/dist/domain.operations/apply/applyChange.test.js.map +1 -0
- package/dist/domain.operations/apply/applyChanges.d.ts +18 -0
- package/dist/domain.operations/apply/applyChanges.integration.test.d.ts +1 -0
- package/dist/domain.operations/apply/applyChanges.integration.test.js +291 -0
- package/dist/domain.operations/apply/applyChanges.integration.test.js.map +1 -0
- package/dist/domain.operations/apply/applyChanges.js +53 -0
- package/dist/domain.operations/apply/applyChanges.js.map +1 -0
- package/dist/domain.operations/plan/computeChange.d.ts +11 -0
- package/dist/domain.operations/plan/computeChange.js +78 -0
- package/dist/domain.operations/plan/computeChange.js.map +1 -0
- package/dist/domain.operations/plan/computeChange.test.d.ts +1 -0
- package/dist/domain.operations/plan/computeChange.test.js +67 -0
- package/dist/domain.operations/plan/computeChange.test.js.map +1 -0
- package/dist/domain.operations/plan/extractResourcesFromPlan.d.ts +8 -0
- package/dist/domain.operations/plan/extractResourcesFromPlan.js +17 -0
- package/dist/domain.operations/plan/extractResourcesFromPlan.js.map +1 -0
- package/dist/domain.operations/plan/getDaoByResource.d.ts +12 -0
- package/dist/domain.operations/plan/getDaoByResource.js +41 -0
- package/dist/domain.operations/plan/getDaoByResource.js.map +1 -0
- package/dist/domain.operations/plan/getDaoByResource.test.d.ts +1 -0
- package/dist/domain.operations/plan/getDaoByResource.test.js +99 -0
- package/dist/domain.operations/plan/getDaoByResource.test.js.map +1 -0
- package/dist/domain.operations/plan/hashChanges.d.ts +7 -0
- package/dist/domain.operations/plan/hashChanges.js +18 -0
- package/dist/domain.operations/plan/hashChanges.js.map +1 -0
- package/dist/domain.operations/plan/planChanges.d.ts +15 -0
- package/dist/domain.operations/plan/planChanges.integration.test.d.ts +1 -0
- package/dist/domain.operations/plan/planChanges.integration.test.js +197 -0
- package/dist/domain.operations/plan/planChanges.integration.test.js.map +1 -0
- package/dist/domain.operations/plan/planChanges.js +50 -0
- package/dist/domain.operations/plan/planChanges.js.map +1 -0
- package/dist/domain.operations/plan/validate.d.ts +10 -0
- package/dist/domain.operations/plan/validate.js +21 -0
- package/dist/domain.operations/plan/validate.js.map +1 -0
- package/dist/infra/asIsoTimestamp.d.ts +6 -0
- package/dist/infra/asIsoTimestamp.js +12 -0
- package/dist/infra/asIsoTimestamp.js.map +1 -0
- package/package.json +8 -15
- package/readme.md +48 -28
- package/dist/__test_assets__/getExampleContext.d.ts +0 -33
- package/dist/__test_assets__/getExampleContext.js +0 -87
- package/dist/__test_assets__/getExampleContext.js.map +0 -1
- package/dist/contract/commands/command.apply.d.ts +0 -6
- package/dist/contract/commands/command.apply.js +0 -20
- package/dist/contract/commands/command.apply.js.map +0 -1
- package/dist/contract/commands/command.plan.d.ts +0 -6
- package/dist/contract/commands/command.plan.js +0 -20
- package/dist/contract/commands/command.plan.js.map +0 -1
- package/dist/contract/commands/utils/resolveCommandInputs.d.ts +0 -17
- package/dist/contract/commands/utils/resolveCommandInputs.js +0 -23
- package/dist/contract/commands/utils/resolveCommandInputs.js.map +0 -1
- package/dist/contract/sdk/refs.d.ts +0 -2
- package/dist/contract/sdk/refs.js +0 -19
- package/dist/contract/sdk/refs.js.map +0 -1
- package/dist/contract/sdk/sync/apply.d.ts +0 -22
- package/dist/contract/sdk/sync/apply.js +0 -29
- package/dist/contract/sdk/sync/apply.js.map +0 -1
- package/dist/contract/sdk/sync/plan.d.ts +0 -22
- package/dist/contract/sdk/sync/plan.js +0 -30
- package/dist/contract/sdk/sync/plan.js.map +0 -1
- package/dist/domain/DeclaredResource.d.ts +0 -2
- package/dist/domain/DeclaredResource.js.map +0 -1
- package/dist/domain/DeclaredResourceReference.d.ts +0 -66
- package/dist/domain/DeclaredResourceReference.js +0 -42
- package/dist/domain/DeclaredResourceReference.js.map +0 -1
- package/dist/domain/DeclastructChangeProposal.d.ts +0 -61
- package/dist/domain/DeclastructChangeProposal.js +0 -37
- package/dist/domain/DeclastructChangeProposal.js.map +0 -1
- package/dist/domain/DeclastructContext.d.ts +0 -24
- package/dist/domain/DeclastructContext.js.map +0 -1
- package/dist/domain/DeclastructProvider.d.ts +0 -58
- package/dist/domain/DeclastructProvider.js +0 -3
- package/dist/domain/DeclastructProvider.js.map +0 -1
- package/dist/domain/DeclastructProviderContext.d.ts +0 -30
- package/dist/domain/DeclastructProviderContext.js +0 -3
- package/dist/domain/DeclastructProviderContext.js.map +0 -1
- package/dist/domain/DeclastructProviderResourceRemoteStateInterface.d.ts +0 -156
- package/dist/domain/DeclastructProviderResourceRemoteStateInterface.js +0 -3
- package/dist/domain/DeclastructProviderResourceRemoteStateInterface.js.map +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/logic/actions/execute/canUpdateResource.d.ts +0 -5
- package/dist/logic/actions/execute/canUpdateResource.js +0 -12
- package/dist/logic/actions/execute/canUpdateResource.js.map +0 -1
- package/dist/logic/actions/execute/executeProposal.d.ts +0 -5
- package/dist/logic/actions/execute/executeProposal.js +0 -52
- package/dist/logic/actions/execute/executeProposal.js.map +0 -1
- package/dist/logic/actions/propose/getColoredActionToken.d.ts +0 -4
- package/dist/logic/actions/propose/getColoredActionToken.js +0 -22
- package/dist/logic/actions/propose/getColoredActionToken.js.map +0 -1
- package/dist/logic/actions/propose/getColoredProposalTitle.d.ts +0 -4
- package/dist/logic/actions/propose/getColoredProposalTitle.js +0 -34
- package/dist/logic/actions/propose/getColoredProposalTitle.js.map +0 -1
- package/dist/logic/actions/propose/proposeChangeForResource.d.ts +0 -7
- package/dist/logic/actions/propose/proposeChangeForResource.js +0 -65
- package/dist/logic/actions/propose/proposeChangeForResource.js.map +0 -1
- package/dist/logic/actions/propose/proposeChangeForResource.test.js +0 -48
- package/dist/logic/actions/propose/proposeChangeForResource.test.js.map +0 -1
- package/dist/logic/commands/command.apply.d.ts +0 -8
- package/dist/logic/commands/command.apply.js +0 -77
- package/dist/logic/commands/command.apply.js.map +0 -1
- package/dist/logic/commands/command.plan.d.ts +0 -13
- package/dist/logic/commands/command.plan.js +0 -155
- package/dist/logic/commands/command.plan.js.map +0 -1
- package/dist/logic/commands/execute.d.ts +0 -15
- package/dist/logic/commands/execute.js +0 -63
- package/dist/logic/commands/execute.js.map +0 -1
- package/dist/logic/tools/compare/castReferenceToGrokableString.d.ts +0 -16
- package/dist/logic/tools/compare/castReferenceToGrokableString.js +0 -66
- package/dist/logic/tools/compare/castReferenceToGrokableString.js.map +0 -1
- package/dist/logic/tools/compare/castReferenceToGrokableString.test.js +0 -111
- package/dist/logic/tools/compare/castReferenceToGrokableString.test.js.map +0 -1
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.d.ts +0 -11
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.js +0 -61
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.js.map +0 -1
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js +0 -31
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js.map +0 -1
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.d.ts +0 -21
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.js +0 -53
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.js.map +0 -1
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.test.js +0 -31
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.test.js.map +0 -1
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.d.ts +0 -10
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.js +0 -41
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.js.map +0 -1
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.test.js +0 -174
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.test.js.map +0 -1
- package/dist/logic/tools/context/createDeclastructContext.d.ts +0 -10
- package/dist/logic/tools/context/createDeclastructContext.js +0 -12
- package/dist/logic/tools/context/createDeclastructContext.js.map +0 -1
- package/dist/logic/tools/context/destroyDeclastructContext.d.ts +0 -4
- package/dist/logic/tools/context/destroyDeclastructContext.js +0 -10
- package/dist/logic/tools/context/destroyDeclastructContext.js.map +0 -1
- package/dist/logic/tools/provider/castProviderContextToGlobalContext.d.ts +0 -4
- package/dist/logic/tools/provider/castProviderContextToGlobalContext.js +0 -10
- package/dist/logic/tools/provider/castProviderContextToGlobalContext.js.map +0 -1
- package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.d.ts +0 -13
- package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.js +0 -29
- package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.js.map +0 -1
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.d.ts +0 -13
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.js +0 -24
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.js.map +0 -1
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.d.ts +0 -10
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.js +0 -21
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.js.map +0 -1
- package/dist/logic/tools/reference/buildPrimaryKeyTo.d.ts +0 -5
- package/dist/logic/tools/reference/buildPrimaryKeyTo.js +0 -40
- package/dist/logic/tools/reference/buildPrimaryKeyTo.js.map +0 -1
- package/dist/logic/tools/reference/buildReferenceTo.d.ts +0 -28
- package/dist/logic/tools/reference/buildReferenceTo.js +0 -92
- package/dist/logic/tools/reference/buildReferenceTo.js.map +0 -1
- package/dist/logic/tools/reference/buildReferenceTo.test.js +0 -119
- package/dist/logic/tools/reference/buildReferenceTo.test.js.map +0 -1
- package/dist/logic/tools/reference/buildUniqueKeyTo.d.ts +0 -5
- package/dist/logic/tools/reference/buildUniqueKeyTo.js +0 -40
- package/dist/logic/tools/reference/buildUniqueKeyTo.js.map +0 -1
- package/dist/logic/tools/reference/defineReferenceClassOf.d.ts +0 -5
- package/dist/logic/tools/reference/defineReferenceClassOf.js +0 -25
- package/dist/logic/tools/reference/defineReferenceClassOf.js.map +0 -1
- package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.d.ts +0 -13
- package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.js +0 -36
- package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.js.map +0 -1
- package/dist/logic/tools/reference/getByReference.d.ts +0 -15
- package/dist/logic/tools/reference/getByReference.js +0 -55
- package/dist/logic/tools/reference/getByReference.js.map +0 -1
- package/dist/logic/tools/reference/getByReference.test.js +0 -92
- package/dist/logic/tools/reference/getByReference.test.js.map +0 -1
- package/dist/logic/tools/reference/getByReferencedPrimaryKey.d.ts +0 -6
- package/dist/logic/tools/reference/getByReferencedPrimaryKey.js +0 -17
- package/dist/logic/tools/reference/getByReferencedPrimaryKey.js.map +0 -1
- package/dist/logic/tools/reference/getByReferencedUniqueKey.d.ts +0 -7
- package/dist/logic/tools/reference/getByReferencedUniqueKey.js +0 -42
- package/dist/logic/tools/reference/getByReferencedUniqueKey.js.map +0 -1
- package/dist/logic/tools/reference/getPrimaryKeyByReference.d.ts +0 -15
- package/dist/logic/tools/reference/getPrimaryKeyByReference.js +0 -36
- package/dist/logic/tools/reference/getPrimaryKeyByReference.js.map +0 -1
- package/dist/logic/tools/reference/getReferenceTo.d.ts +0 -18
- package/dist/logic/tools/reference/getReferenceTo.js +0 -55
- package/dist/logic/tools/reference/getReferenceTo.js.map +0 -1
- package/dist/logic/tools/reference/getReferenceTo.test.js +0 -95
- package/dist/logic/tools/reference/getReferenceTo.test.js.map +0 -1
- package/dist/logic/tools/reference/getUniqueKeyByReference.d.ts +0 -15
- package/dist/logic/tools/reference/getUniqueKeyByReference.js +0 -36
- package/dist/logic/tools/reference/getUniqueKeyByReference.js.map +0 -1
- package/dist/logic/tools/reference/isPrimaryKeyReference.d.ts +0 -6
- package/dist/logic/tools/reference/isPrimaryKeyReference.js +0 -7
- package/dist/logic/tools/reference/isPrimaryKeyReference.js.map +0 -1
- package/dist/logic/tools/reference/isUniqueKeyReference.d.ts +0 -6
- package/dist/logic/tools/reference/isUniqueKeyReference.js +0 -7
- package/dist/logic/tools/reference/isUniqueKeyReference.js.map +0 -1
- /package/dist/{logic/actions/propose/proposeChangeForResource.test.d.ts → contract/cli/apply.integration.test.d.ts} +0 -0
- /package/dist/{logic/tools/compare/castReferenceToGrokableString.test.d.ts → contract/cli/plan.integration.test.d.ts} +0 -0
- /package/dist/{logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.d.ts → domain.objects/ContextDeclastruct.test.d.ts} +0 -0
- /package/dist/{logic/tools/compare/resolveReferenceToCommonComparableForm.test.d.ts → domain.objects/DeclastructChange.test.d.ts} +0 -0
- /package/dist/{logic/tools/compare/resolveReferencesToCommonComparableForm.test.d.ts → domain.objects/DeclastructDao.test.d.ts} +0 -0
- /package/dist/{logic/tools/reference/buildReferenceTo.test.d.ts → domain.objects/DeclastructPlan.test.d.ts} +0 -0
- /package/dist/{logic/tools/reference/getByReference.test.d.ts → domain.objects/DeclastructProvider.test.d.ts} +0 -0
- /package/dist/{logic/tools/reference/getReferenceTo.test.d.ts → domain.objects/IsoTimestamp.test.d.ts} +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
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 DeclastructProvider_1 = require("../../domain.objects/DeclastructProvider");
|
|
6
|
+
const getDaoByResource_1 = require("./getDaoByResource");
|
|
7
|
+
describe('getDaoByResource', () => {
|
|
8
|
+
class DemoResource extends domain_objects_1.DomainEntity {
|
|
9
|
+
}
|
|
10
|
+
DemoResource.unique = ['id'];
|
|
11
|
+
it('should return DAO when exactly one provider matches', () => {
|
|
12
|
+
const demoDao = {
|
|
13
|
+
get: {
|
|
14
|
+
byUnique: async () => null,
|
|
15
|
+
byRef: async () => null,
|
|
16
|
+
},
|
|
17
|
+
set: {
|
|
18
|
+
finsert: async (input) => input,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const provider = new DeclastructProvider_1.DeclastructProvider({
|
|
22
|
+
name: 'test-provider',
|
|
23
|
+
daos: { DemoResource: demoDao },
|
|
24
|
+
context: {},
|
|
25
|
+
hooks: {
|
|
26
|
+
beforeAll: async () => { },
|
|
27
|
+
afterAll: async () => { },
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const resource = new DemoResource({ id: 'test-1', name: 'Test' });
|
|
31
|
+
const result = (0, getDaoByResource_1.getDaoByResource)({
|
|
32
|
+
resource,
|
|
33
|
+
providers: [provider],
|
|
34
|
+
});
|
|
35
|
+
expect(result).toBe(demoDao);
|
|
36
|
+
});
|
|
37
|
+
it('should throw UnexpectedCodePathError when multiple providers support same resource', () => {
|
|
38
|
+
const dao1 = {
|
|
39
|
+
get: {
|
|
40
|
+
byUnique: async () => null,
|
|
41
|
+
byRef: async () => null,
|
|
42
|
+
},
|
|
43
|
+
set: {
|
|
44
|
+
finsert: async (input) => input,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
const dao2 = {
|
|
48
|
+
get: {
|
|
49
|
+
byUnique: async () => null,
|
|
50
|
+
byRef: async () => null,
|
|
51
|
+
},
|
|
52
|
+
set: {
|
|
53
|
+
finsert: async (input) => input,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const provider1 = new DeclastructProvider_1.DeclastructProvider({
|
|
57
|
+
name: 'provider-1',
|
|
58
|
+
daos: { DemoResource: dao1 },
|
|
59
|
+
context: {},
|
|
60
|
+
hooks: {
|
|
61
|
+
beforeAll: async () => { },
|
|
62
|
+
afterAll: async () => { },
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const provider2 = new DeclastructProvider_1.DeclastructProvider({
|
|
66
|
+
name: 'provider-2',
|
|
67
|
+
daos: { DemoResource: dao2 },
|
|
68
|
+
context: {},
|
|
69
|
+
hooks: {
|
|
70
|
+
beforeAll: async () => { },
|
|
71
|
+
afterAll: async () => { },
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
const resource = new DemoResource({ id: 'test-1', name: 'Test' });
|
|
75
|
+
const error = (0, helpful_errors_1.getError)(() => (0, getDaoByResource_1.getDaoByResource)({
|
|
76
|
+
resource,
|
|
77
|
+
providers: [provider1, provider2],
|
|
78
|
+
}));
|
|
79
|
+
expect(error.message).toContain('multiple providers support same resource');
|
|
80
|
+
});
|
|
81
|
+
it('should throw UnexpectedCodePathError when no provider supports resource', () => {
|
|
82
|
+
const provider = new DeclastructProvider_1.DeclastructProvider({
|
|
83
|
+
name: 'empty-provider',
|
|
84
|
+
daos: {},
|
|
85
|
+
context: {},
|
|
86
|
+
hooks: {
|
|
87
|
+
beforeAll: async () => { },
|
|
88
|
+
afterAll: async () => { },
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const resource = new DemoResource({ id: 'test-1', name: 'Test' });
|
|
92
|
+
const error = (0, helpful_errors_1.getError)(() => (0, getDaoByResource_1.getDaoByResource)({
|
|
93
|
+
resource,
|
|
94
|
+
providers: [provider],
|
|
95
|
+
}));
|
|
96
|
+
expect(error.message).toContain('no DAO found for resource');
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=getDaoByResource.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDaoByResource.test.js","sourceRoot":"","sources":["../../../src/domain.operations/plan/getDaoByResource.test.ts"],"names":[],"mappings":";;AAAA,mDAA8C;AAC9C,mDAA0C;AAG1C,kFAA+E;AAC/E,yDAAsD;AAEtD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAMhC,MAAM,YACJ,SAAQ,6BAA0B;;IAGpB,mBAAM,GAAG,CAAC,IAAI,CAAU,CAAC;IAGzC,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,OAAO,GAA2D;YACtE,GAAG,EAAE;gBACH,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI;gBAC1B,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI;aACxB;YACD,GAAG,EAAE;gBACH,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAY;aACvC;SACF,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,yCAAmB,CAAC;YACvC,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,EAAE,YAAY,EAAE,OAAO,EAAE;YAC/B,OAAO,EAAE,EAAE;YACX,KAA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;SACtB,CAAC,CACH,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DeclastructChange } from '../../domain.objects/DeclastructChange';
|
|
2
|
+
/**
|
|
3
|
+
* .what = computes deterministic hash of changes
|
|
4
|
+
* .why = enables plan comparison and staleness detection
|
|
5
|
+
* .note = uses SHA-256 for consistency
|
|
6
|
+
*/
|
|
7
|
+
export declare const hashChanges: (changes: DeclastructChange[]) => string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashChanges = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
/**
|
|
6
|
+
* .what = computes deterministic hash of changes
|
|
7
|
+
* .why = enables plan comparison and staleness detection
|
|
8
|
+
* .note = uses SHA-256 for consistency
|
|
9
|
+
*/
|
|
10
|
+
const hashChanges = (changes) => {
|
|
11
|
+
// serialize changes to deterministic JSON
|
|
12
|
+
const serialized = JSON.stringify(changes, null, 0);
|
|
13
|
+
// compute SHA-256 hash
|
|
14
|
+
const hash = (0, crypto_1.createHash)('sha256').update(serialized).digest('hex');
|
|
15
|
+
return hash;
|
|
16
|
+
};
|
|
17
|
+
exports.hashChanges = hashChanges;
|
|
18
|
+
//# sourceMappingURL=hashChanges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashChanges.js","sourceRoot":"","sources":["../../../src/domain.operations/plan/hashChanges.ts"],"names":[],"mappings":";;;AAAA,mCAAoC;AAIpC;;;;GAIG;AACI,MAAM,WAAW,GAAG,CAAC,OAA4B,EAAU,EAAE;IAClE,0CAA0C;IAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAEpD,uBAAuB;IACvB,MAAM,IAAI,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEnE,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AARW,QAAA,WAAW,eAQtB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DomainEntity } from 'domain-objects';
|
|
2
|
+
import { ContextLogTrail } from 'simple-log-methods';
|
|
3
|
+
import { ContextDeclastruct } from '../../domain.objects/ContextDeclastruct';
|
|
4
|
+
import { DeclastructPlan } from '../../domain.objects/DeclastructPlan';
|
|
5
|
+
import { DeclastructProvider } from '../../domain.objects/DeclastructProvider';
|
|
6
|
+
/**
|
|
7
|
+
* .what = generates a plan of changes required to achieve desired state
|
|
8
|
+
* .why = enables users to review infrastructure changes before applying them
|
|
9
|
+
* .note = idempotent - calling multiple times produces the same plan
|
|
10
|
+
*/
|
|
11
|
+
export declare const planChanges: (input: {
|
|
12
|
+
resources: DomainEntity<any>[];
|
|
13
|
+
providers: DeclastructProvider<any, any>[];
|
|
14
|
+
wishFilePath: string;
|
|
15
|
+
}, context: ContextLogTrail & ContextDeclastruct) => Promise<DeclastructPlan>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
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 path_1 = require("path");
|
|
8
|
+
const demo_provider_1 = require("../../.test/assets/providers/demo.provider");
|
|
9
|
+
const DeclastructChange_1 = require("../../domain.objects/DeclastructChange");
|
|
10
|
+
const planChanges_1 = require("./planChanges");
|
|
11
|
+
describe('planChanges', () => {
|
|
12
|
+
const wishFilePath = (0, path_1.resolve)(process.cwd(), 'src/.test/assets/wish.fixture.ts');
|
|
13
|
+
beforeAll(async () => {
|
|
14
|
+
// initialize provider (creates temp directory)
|
|
15
|
+
await demo_provider_1.demoProvider.hooks.beforeAll();
|
|
16
|
+
});
|
|
17
|
+
const createContext = () => ({
|
|
18
|
+
bottleneck: new bottleneck_1.default({ maxConcurrent: 10 }),
|
|
19
|
+
log: {
|
|
20
|
+
info: jest.fn(),
|
|
21
|
+
error: jest.fn(),
|
|
22
|
+
warn: jest.fn(),
|
|
23
|
+
debug: jest.fn(),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
it('should plan CREATE actions for resources that do not exist remotely', async () => {
|
|
27
|
+
// define desired resources
|
|
28
|
+
const resources = [
|
|
29
|
+
(0, demo_provider_1.genSampleDemoResource)({ name: 'First Test' }),
|
|
30
|
+
(0, demo_provider_1.genSampleDemoResource)({ name: 'Second Test' }),
|
|
31
|
+
];
|
|
32
|
+
// plan changes
|
|
33
|
+
const plan = await (0, planChanges_1.planChanges)({
|
|
34
|
+
resources,
|
|
35
|
+
providers: [demo_provider_1.demoProvider],
|
|
36
|
+
wishFilePath,
|
|
37
|
+
}, createContext());
|
|
38
|
+
// verify plan structure
|
|
39
|
+
expect(plan.hash).toBeDefined();
|
|
40
|
+
expect(plan.createdAt).toBeDefined();
|
|
41
|
+
expect(plan.wish.uri).toBe(wishFilePath);
|
|
42
|
+
expect(plan.changes.length).toBe(2);
|
|
43
|
+
// verify all changes are CREATE
|
|
44
|
+
plan.changes.forEach((change) => {
|
|
45
|
+
expect(change.action).toBe(DeclastructChange_1.DeclastructChangeAction.CREATE);
|
|
46
|
+
expect(change.forResource.class).toBe('DemoResource');
|
|
47
|
+
expect(change.state.desired).toBeDefined();
|
|
48
|
+
expect(change.state.remote).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
// verify specific resources (slug includes full format with hash)
|
|
51
|
+
const slugs = plan.changes.map((c) => c.forResource.slug);
|
|
52
|
+
expect(slugs[0]).toContain(resources[0].exid);
|
|
53
|
+
expect(slugs[1]).toContain(resources[1].exid);
|
|
54
|
+
});
|
|
55
|
+
it('should plan KEEP actions for resources that exist unchanged remotely', async () => {
|
|
56
|
+
// define resources
|
|
57
|
+
const resources = [
|
|
58
|
+
(0, demo_provider_1.genSampleDemoResource)({ name: 'First Test' }),
|
|
59
|
+
(0, demo_provider_1.genSampleDemoResource)({ name: 'Second Test' }),
|
|
60
|
+
];
|
|
61
|
+
// create remote state
|
|
62
|
+
const dao = demo_provider_1.demoProvider.daos.DemoResource;
|
|
63
|
+
await dao.set.finsert(resources[0], {});
|
|
64
|
+
await dao.set.finsert(resources[1], {});
|
|
65
|
+
// plan changes
|
|
66
|
+
const plan = await (0, planChanges_1.planChanges)({
|
|
67
|
+
resources,
|
|
68
|
+
providers: [demo_provider_1.demoProvider],
|
|
69
|
+
wishFilePath,
|
|
70
|
+
}, createContext());
|
|
71
|
+
// verify all changes are KEEP
|
|
72
|
+
expect(plan.changes.length).toBe(2);
|
|
73
|
+
plan.changes.forEach((change) => {
|
|
74
|
+
expect(change.action).toBe(DeclastructChange_1.DeclastructChangeAction.KEEP);
|
|
75
|
+
expect(change.forResource.class).toBe('DemoResource');
|
|
76
|
+
expect(change.state.desired).toBeDefined();
|
|
77
|
+
expect(change.state.remote).toBeDefined();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
it('should plan UPDATE actions for resources that changed remotely', async () => {
|
|
81
|
+
// create remote state
|
|
82
|
+
const remoteResource = (0, demo_provider_1.genSampleDemoResource)({ name: 'Old Name' });
|
|
83
|
+
const dao = demo_provider_1.demoProvider.daos.DemoResource;
|
|
84
|
+
await dao.set.finsert(remoteResource, {});
|
|
85
|
+
// define desired resource with new name (same exid)
|
|
86
|
+
const resources = [remoteResource.clone({ name: 'New Name' })];
|
|
87
|
+
// plan changes
|
|
88
|
+
const plan = await (0, planChanges_1.planChanges)({
|
|
89
|
+
resources,
|
|
90
|
+
providers: [demo_provider_1.demoProvider],
|
|
91
|
+
wishFilePath,
|
|
92
|
+
}, createContext());
|
|
93
|
+
// verify UPDATE action
|
|
94
|
+
expect(plan.changes.length).toBe(1);
|
|
95
|
+
const change = plan.changes[0];
|
|
96
|
+
expect(change.action).toBe(DeclastructChange_1.DeclastructChangeAction.UPDATE);
|
|
97
|
+
expect(change.forResource.class).toBe('DemoResource');
|
|
98
|
+
expect(change.forResource.slug).toContain(remoteResource.exid);
|
|
99
|
+
expect(change.state.desired.name).toBe('New Name');
|
|
100
|
+
expect(change.state.remote?.name).toBe('Old Name');
|
|
101
|
+
expect(change.toString()).toBeDefined();
|
|
102
|
+
});
|
|
103
|
+
it('should plan DELETE actions for resources that exist remotely but not in desired state', async () => {
|
|
104
|
+
// create remote state
|
|
105
|
+
const resource1 = (0, demo_provider_1.genSampleDemoResource)({ name: 'To Delete' });
|
|
106
|
+
const resource2 = (0, demo_provider_1.genSampleDemoResource)({ name: 'To Keep' });
|
|
107
|
+
const dao = demo_provider_1.demoProvider.daos.DemoResource;
|
|
108
|
+
await dao.set.finsert(resource1, {});
|
|
109
|
+
await dao.set.finsert(resource2, {});
|
|
110
|
+
// define desired resources (only resource2)
|
|
111
|
+
const resources = [resource2];
|
|
112
|
+
// Note: planChanges only looks at desired resources, not remote state
|
|
113
|
+
// DELETE actions would need to be detected by comparing remote state to desired
|
|
114
|
+
// This is a design limitation - planChanges only processes desired resources
|
|
115
|
+
const plan = await (0, planChanges_1.planChanges)({
|
|
116
|
+
resources,
|
|
117
|
+
providers: [demo_provider_1.demoProvider],
|
|
118
|
+
wishFilePath,
|
|
119
|
+
}, createContext());
|
|
120
|
+
// verify only resource2 is in plan
|
|
121
|
+
expect(plan.changes.length).toBe(1);
|
|
122
|
+
expect(plan.changes[0].forResource.slug).toContain(resource2.exid);
|
|
123
|
+
expect(plan.changes[0].action).toBe(DeclastructChange_1.DeclastructChangeAction.KEEP);
|
|
124
|
+
});
|
|
125
|
+
it('should emit real-time logs as resources are planned', async () => {
|
|
126
|
+
// define resources
|
|
127
|
+
const resources = [
|
|
128
|
+
(0, demo_provider_1.genSampleDemoResource)({ name: 'First Test' }),
|
|
129
|
+
(0, demo_provider_1.genSampleDemoResource)({ name: 'Second Test' }),
|
|
130
|
+
];
|
|
131
|
+
// plan with spy on log
|
|
132
|
+
const context = createContext();
|
|
133
|
+
await (0, planChanges_1.planChanges)({
|
|
134
|
+
resources,
|
|
135
|
+
providers: [demo_provider_1.demoProvider],
|
|
136
|
+
wishFilePath,
|
|
137
|
+
}, context);
|
|
138
|
+
// verify logs were emitted (logs include the full slug with hash)
|
|
139
|
+
expect(context.log.info).toHaveBeenCalledWith(expect.stringContaining(`[CREATE] DemoResource.`), {});
|
|
140
|
+
expect(context.log.info).toHaveBeenCalled();
|
|
141
|
+
});
|
|
142
|
+
it('should handle mixed actions in single plan', async () => {
|
|
143
|
+
// create remote resources
|
|
144
|
+
const resource1 = (0, demo_provider_1.genSampleDemoResource)({ name: 'Unchanged' });
|
|
145
|
+
const resource2 = (0, demo_provider_1.genSampleDemoResource)({ name: 'Old Name' });
|
|
146
|
+
// create remote state for some resources
|
|
147
|
+
const dao = demo_provider_1.demoProvider.daos.DemoResource;
|
|
148
|
+
await dao.set.finsert(resource1, {});
|
|
149
|
+
await dao.set.finsert(resource2, {});
|
|
150
|
+
// define desired resources
|
|
151
|
+
const resources = [
|
|
152
|
+
resource1, // KEEP
|
|
153
|
+
resource2.clone({ name: 'New Name' }), // UPDATE
|
|
154
|
+
(0, demo_provider_1.genSampleDemoResource)({ name: 'Brand New' }), // CREATE
|
|
155
|
+
];
|
|
156
|
+
// plan changes
|
|
157
|
+
const plan = await (0, planChanges_1.planChanges)({
|
|
158
|
+
resources,
|
|
159
|
+
providers: [demo_provider_1.demoProvider],
|
|
160
|
+
wishFilePath,
|
|
161
|
+
}, createContext());
|
|
162
|
+
// verify mixed actions
|
|
163
|
+
expect(plan.changes.length).toBe(3);
|
|
164
|
+
// verify we have one of each action
|
|
165
|
+
const actions = plan.changes.map((c) => c.action);
|
|
166
|
+
expect(actions).toContain(DeclastructChange_1.DeclastructChangeAction.KEEP);
|
|
167
|
+
expect(actions).toContain(DeclastructChange_1.DeclastructChangeAction.UPDATE);
|
|
168
|
+
expect(actions).toContain(DeclastructChange_1.DeclastructChangeAction.CREATE);
|
|
169
|
+
// verify exids are in slugs
|
|
170
|
+
const slugString = plan.changes.map((c) => c.forResource.slug).join(',');
|
|
171
|
+
expect(slugString).toContain(resource1.exid);
|
|
172
|
+
expect(slugString).toContain(resource2.exid);
|
|
173
|
+
expect(slugString).toContain(resources[2].exid);
|
|
174
|
+
});
|
|
175
|
+
it('should produce deterministic plans for same input', async () => {
|
|
176
|
+
// define resources
|
|
177
|
+
const resources = [
|
|
178
|
+
(0, demo_provider_1.genSampleDemoResource)({ name: 'First Test' }),
|
|
179
|
+
(0, demo_provider_1.genSampleDemoResource)({ name: 'Second Test' }),
|
|
180
|
+
];
|
|
181
|
+
// plan twice
|
|
182
|
+
const plan1 = await (0, planChanges_1.planChanges)({
|
|
183
|
+
resources,
|
|
184
|
+
providers: [demo_provider_1.demoProvider],
|
|
185
|
+
wishFilePath,
|
|
186
|
+
}, createContext());
|
|
187
|
+
const plan2 = await (0, planChanges_1.planChanges)({
|
|
188
|
+
resources,
|
|
189
|
+
providers: [demo_provider_1.demoProvider],
|
|
190
|
+
wishFilePath,
|
|
191
|
+
}, createContext());
|
|
192
|
+
// verify plans have same hash (deterministic)
|
|
193
|
+
expect(plan1.hash).toBe(plan2.hash);
|
|
194
|
+
expect(plan1.changes.length).toBe(plan2.changes.length);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=planChanges.integration.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planChanges.integration.test.js","sourceRoot":"","sources":["../../../src/domain.operations/plan/planChanges.integration.test.ts"],"names":[],"mappings":";;;;;AAAA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E,SAAS;YACT,SAAS,EAAE,CAAC,4BAAY,CAAC;YACzB,YAAY;SACb,EACD,aAAa,EAAE,CAChB,CAAC;QAEF,MAAM,KAAK,GAAG,MAAM,IAAA,yBAAW,EAC7B;YACE,SAAS;YACT,SAAS,EAAE,CAAC,4BAAY,CAAC;YACzB,YAAY;SACb,EACD,aAAa,EAAE,CAChB,CAAC;QAEF,8CAA8C;QAC9C,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.planChanges = void 0;
|
|
4
|
+
const DeclastructChange_1 = require("../../domain.objects/DeclastructChange");
|
|
5
|
+
const DeclastructPlan_1 = require("../../domain.objects/DeclastructPlan");
|
|
6
|
+
const asIsoTimestamp_1 = require("../../infra/asIsoTimestamp");
|
|
7
|
+
const computeChange_1 = require("./computeChange");
|
|
8
|
+
const getDaoByResource_1 = require("./getDaoByResource");
|
|
9
|
+
const hashChanges_1 = require("./hashChanges");
|
|
10
|
+
/**
|
|
11
|
+
* .what = generates a plan of changes required to achieve desired state
|
|
12
|
+
* .why = enables users to review infrastructure changes before applying them
|
|
13
|
+
* .note = idempotent - calling multiple times produces the same plan
|
|
14
|
+
*/
|
|
15
|
+
const planChanges = async (input, context) => {
|
|
16
|
+
// extract bottleneck for planning
|
|
17
|
+
const bottleneck = 'onPlan' in context.bottleneck
|
|
18
|
+
? context.bottleneck.onPlan
|
|
19
|
+
: context.bottleneck;
|
|
20
|
+
// compute change for each resource with real-time logging
|
|
21
|
+
const changes = await Promise.all(input.resources.map((resource) => bottleneck.schedule(async () => {
|
|
22
|
+
// find DAO for this resource
|
|
23
|
+
const dao = (0, getDaoByResource_1.getDaoByResource)({
|
|
24
|
+
resource,
|
|
25
|
+
providers: input.providers,
|
|
26
|
+
});
|
|
27
|
+
// fetch current remote state
|
|
28
|
+
const remoteState = await dao.get.byUnique(resource, context);
|
|
29
|
+
// compute change
|
|
30
|
+
const change = (0, computeChange_1.computeChange)({
|
|
31
|
+
desired: resource,
|
|
32
|
+
remote: remoteState,
|
|
33
|
+
});
|
|
34
|
+
// log change as it's computed
|
|
35
|
+
const symbol = change.action === DeclastructChange_1.DeclastructChangeAction.KEEP ? '↓' : '○';
|
|
36
|
+
context.log.info(`${symbol} [${change.action}] ${change.forResource.slug}`, {});
|
|
37
|
+
return change;
|
|
38
|
+
})));
|
|
39
|
+
// return plan
|
|
40
|
+
return new DeclastructPlan_1.DeclastructPlan({
|
|
41
|
+
hash: (0, hashChanges_1.hashChanges)(changes),
|
|
42
|
+
createdAt: (0, asIsoTimestamp_1.asIsoTimestamp)(new Date()),
|
|
43
|
+
wish: {
|
|
44
|
+
uri: input.wishFilePath,
|
|
45
|
+
},
|
|
46
|
+
changes,
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
exports.planChanges = planChanges;
|
|
50
|
+
//# sourceMappingURL=planChanges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planChanges.js","sourceRoot":"","sources":["../../../src/domain.operations/plan/planChanges.ts"],"names":[],"mappings":";;;AAIA,8EAAiF;AACjF,0EAAuE;AAEvE,+DAA4D;AAC5D,mDAAgD;AAChD,yDAAsD;AACtD,+CAA4C;AAE5C;;;;GAIG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,KAIC,EACD,OAA6C,EACnB,EAAE;IAC5B,kCAAkC;IAClC,MAAM,UAAU,GACd,QAAQ,IAAI,OAAO,CAAC,UAAU;QAC5B,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,MA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|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DeclastructPlan } from '../../domain.objects/DeclastructPlan';
|
|
2
|
+
/**
|
|
3
|
+
* .what = validates that a plan hasn't become stale
|
|
4
|
+
* .why = prevents applying outdated changes to infrastructure
|
|
5
|
+
* .note = compares plan hashes to detect drift
|
|
6
|
+
*/
|
|
7
|
+
export declare const assertPlanStillValid: ({ originalPlan, currentPlan, }: {
|
|
8
|
+
originalPlan: DeclastructPlan;
|
|
9
|
+
currentPlan: DeclastructPlan;
|
|
10
|
+
}) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertPlanStillValid = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
/**
|
|
6
|
+
* .what = validates that a plan hasn't become stale
|
|
7
|
+
* .why = prevents applying outdated changes to infrastructure
|
|
8
|
+
* .note = compares plan hashes to detect drift
|
|
9
|
+
*/
|
|
10
|
+
const assertPlanStillValid = ({ originalPlan, currentPlan, }) => {
|
|
11
|
+
// reject if plan hashes differ
|
|
12
|
+
if (originalPlan.hash !== currentPlan.hash) {
|
|
13
|
+
throw new helpful_errors_1.BadRequestError('plan is stale', {
|
|
14
|
+
originalHash: originalPlan.hash,
|
|
15
|
+
currentHash: currentPlan.hash,
|
|
16
|
+
message: 'The infrastructure state has changed since this plan was created. Please review and create a new plan.',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.assertPlanStillValid = assertPlanStillValid;
|
|
21
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../src/domain.operations/plan/validate.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAIjD;;;;GAIG;AACI,MAAM,oBAAoB,GAAG,CAAC,EACnC,YAAY,EACZ,WAAW,GAIZ,EAAQ,EAAE;IACT,+BAA+B;IAC/B,IAAI,YAAY,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;QAC3C,MAAM,IAAI,gCAAe,CAAC,eAAe,EAAE;YACzC,YAAY,EAAE,YAAY,CAAC,IAAI;YAC/B,WAAW,EAAE,WAAW,CAAC,IAAI;YAC7B,OAAO,EACL,wGAAwG;SAC3G,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AAhBW,QAAA,oBAAoB,wBAgB/B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asIsoTimestamp = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* .what = converts a Date to ISO 8601 timestamp string
|
|
6
|
+
* .why = ensures consistent timestamp format across the system
|
|
7
|
+
*/
|
|
8
|
+
const asIsoTimestamp = (date) => {
|
|
9
|
+
return date.toISOString();
|
|
10
|
+
};
|
|
11
|
+
exports.asIsoTimestamp = asIsoTimestamp;
|
|
12
|
+
//# sourceMappingURL=asIsoTimestamp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asIsoTimestamp.js","sourceRoot":"","sources":["../../src/infra/asIsoTimestamp.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,IAAU,EAAgB,EAAE;IACzD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;AAC5B,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "declastruct",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "Add declarative control to any resource constructs. Declare, plan, and apply within an observable pit-of-success.",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.1.0",
|
|
6
6
|
"repository": "ehmpathy/declastruct",
|
|
7
7
|
"homepage": "https://github.com/ehmpathy/declastruct",
|
|
8
8
|
"keywords": [
|
|
@@ -49,22 +49,14 @@
|
|
|
49
49
|
"prepare:husky": "npx husky install && chmod ug+x .husky/*"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@ehmpathy/error-fns": "1.3.7",
|
|
53
|
-
"@ehmpathy/number-fns": "1.0.1",
|
|
54
52
|
"bottleneck": "2.19.5",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"flattie": "1.1.1",
|
|
59
|
-
"indent-string": "5.0.0",
|
|
53
|
+
"commander": "14.0.2",
|
|
54
|
+
"domain-objects": "0.25.7",
|
|
55
|
+
"helpful-errors": "1.4.0",
|
|
60
56
|
"jest-diff": "30.0.2",
|
|
61
|
-
"
|
|
62
|
-
"ora": "5.4.1",
|
|
63
|
-
"simple-in-memory-cache": "0.4.0",
|
|
57
|
+
"simple-log-methods": "0.6.1",
|
|
64
58
|
"type-fns": "1.19.0",
|
|
65
|
-
"uuid-fns": "1.0.
|
|
66
|
-
"visualogic": "1.3.2",
|
|
67
|
-
"with-simple-caching": "0.14.1"
|
|
59
|
+
"uuid-fns": "1.0.2"
|
|
68
60
|
},
|
|
69
61
|
"devDependencies": {
|
|
70
62
|
"@commitlint/cli": "19.3.0",
|
|
@@ -87,7 +79,8 @@
|
|
|
87
79
|
"husky": "8.0.3",
|
|
88
80
|
"jest": "29.3.1",
|
|
89
81
|
"prettier": "2.8.1",
|
|
90
|
-
"
|
|
82
|
+
"rhachet": "1.12.1",
|
|
83
|
+
"rhachet-roles-ehmpathy": "1.9.1",
|
|
91
84
|
"ts-jest": "29.1.3",
|
|
92
85
|
"ts-node": "10.9.2",
|
|
93
86
|
"typescript": "5.4.5"
|
package/readme.md
CHANGED
|
@@ -7,50 +7,70 @@ Add declarative control to any resource constructs. Declare, plan, and apply wit
|
|
|
7
7
|
|
|
8
8
|
Declare the structures you want. Plan to see the changes required. Apply to make it so 🪄
|
|
9
9
|
|
|
10
|
-
#
|
|
10
|
+
# install
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
```sh
|
|
13
|
+
npm install declastruct --save-dev
|
|
14
|
+
```
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
# use
|
|
17
|
+
|
|
18
|
+
### 1. declare ✨
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
declare the resources you wish to have and how you wish to have them
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- eliminate single-key constraint; enable usage of whichever key is accessible
|
|
22
|
+
```ts
|
|
23
|
+
import { getDeclastructAwsProvider, DeclaredAwsS3Bucket } from 'declastruct-aws';
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
// declare the providers that support your resources
|
|
26
|
+
export const getProviders = async () => [
|
|
27
|
+
await getDeclastructAwsProvider({
|
|
28
|
+
profile: process.env.AWS_PROFILE,
|
|
29
|
+
})
|
|
30
|
+
]
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
// declare the resources in the states you want them
|
|
33
|
+
export const getResources = async () => {
|
|
34
|
+
const bucket = DeclaredAwsS3Bucket.as({
|
|
35
|
+
name: 'your-s3-bucket',
|
|
36
|
+
});
|
|
37
|
+
// declare other resources you wish to have
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
return [
|
|
40
|
+
bucket,
|
|
41
|
+
// ... all the resources you wish for will go here
|
|
42
|
+
],
|
|
43
|
+
}
|
|
44
|
+
```
|
|
37
45
|
|
|
46
|
+
### 2. plan 🔮
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
plan how to achieve the wish of resources you've declared
|
|
40
49
|
|
|
41
50
|
```sh
|
|
42
|
-
|
|
51
|
+
npx declastruct plan --wish provision/resources.ts --into provision/.temp/plan.json
|
|
43
52
|
```
|
|
44
53
|
|
|
45
|
-
|
|
54
|
+
### 3. apply 🪄
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
apply the plan to fulfill the wish
|
|
48
57
|
|
|
49
|
-
|
|
58
|
+
```sh
|
|
59
|
+
npx declastruct apply --plan provision/.temp/plan.json
|
|
60
|
+
```
|
|
50
61
|
|
|
51
|
-
|
|
62
|
+
# benefits
|
|
52
63
|
|
|
64
|
+
- no dedicated state required
|
|
65
|
+
- looks at the source of truth directly
|
|
66
|
+
- leverages unique keys of resources to understand remote state automatically and eliminate the middleman
|
|
53
67
|
|
|
54
|
-
|
|
68
|
+
- no new language syntax required
|
|
69
|
+
- no awkward new-language limitations
|
|
70
|
+
- reuse your existing domain language to manage your resources
|
|
55
71
|
|
|
56
|
-
|
|
72
|
+
- pit of success adapters
|
|
73
|
+
- each repo that implements a declastruct adapter to control their remote state follows a pit of success
|
|
74
|
+
- idempotency is required on operations, to guarantee they operate safely
|
|
75
|
+
- clear declaration of unique and primary keys is required, to guarantee readability, composability, and true comparisons against reality
|
|
76
|
+
- not only can you use them via declastruct, you can leverage them directly as well
|