declastruct 1.0.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/LICENSE +21 -0
- package/dist/__test_assets__/getExampleContext.d.ts +33 -0
- package/dist/__test_assets__/getExampleContext.js +87 -0
- package/dist/__test_assets__/getExampleContext.js.map +1 -0
- package/dist/contract/commands/command.apply.d.ts +6 -0
- package/dist/contract/commands/command.apply.js +20 -0
- package/dist/contract/commands/command.apply.js.map +1 -0
- package/dist/contract/commands/command.plan.d.ts +6 -0
- package/dist/contract/commands/command.plan.js +20 -0
- package/dist/contract/commands/command.plan.js.map +1 -0
- package/dist/contract/commands/utils/resolveCommandInputs.d.ts +17 -0
- package/dist/contract/commands/utils/resolveCommandInputs.js +23 -0
- package/dist/contract/commands/utils/resolveCommandInputs.js.map +1 -0
- package/dist/contract/sdk/index.d.ts +3 -0
- package/dist/contract/sdk/index.js +20 -0
- package/dist/contract/sdk/index.js.map +1 -0
- package/dist/contract/sdk/refs.d.ts +2 -0
- package/dist/contract/sdk/refs.js +19 -0
- package/dist/contract/sdk/refs.js.map +1 -0
- package/dist/contract/sdk/sync/apply.d.ts +22 -0
- package/dist/contract/sdk/sync/apply.js +29 -0
- package/dist/contract/sdk/sync/apply.js.map +1 -0
- package/dist/contract/sdk/sync/plan.d.ts +22 -0
- package/dist/contract/sdk/sync/plan.js +30 -0
- package/dist/contract/sdk/sync/plan.js.map +1 -0
- package/dist/domain/DeclaredResource.d.ts +2 -0
- package/dist/domain/DeclaredResource.js +3 -0
- package/dist/domain/DeclaredResource.js.map +1 -0
- package/dist/domain/DeclaredResourceReference.d.ts +66 -0
- package/dist/domain/DeclaredResourceReference.js +42 -0
- package/dist/domain/DeclaredResourceReference.js.map +1 -0
- package/dist/domain/DeclastructChangeProposal.d.ts +61 -0
- package/dist/domain/DeclastructChangeProposal.js +37 -0
- package/dist/domain/DeclastructChangeProposal.js.map +1 -0
- package/dist/domain/DeclastructContext.d.ts +24 -0
- package/dist/domain/DeclastructContext.js +3 -0
- package/dist/domain/DeclastructContext.js.map +1 -0
- package/dist/domain/DeclastructProvider.d.ts +58 -0
- package/dist/domain/DeclastructProvider.js +3 -0
- package/dist/domain/DeclastructProvider.js.map +1 -0
- package/dist/domain/DeclastructProviderContext.d.ts +30 -0
- package/dist/domain/DeclastructProviderContext.js +3 -0
- package/dist/domain/DeclastructProviderContext.js.map +1 -0
- package/dist/domain/DeclastructProviderResourceRemoteStateInterface.d.ts +156 -0
- package/dist/domain/DeclastructProviderResourceRemoteStateInterface.js +3 -0
- package/dist/domain/DeclastructProviderResourceRemoteStateInterface.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/logic/actions/execute/canUpdateResource.d.ts +5 -0
- package/dist/logic/actions/execute/canUpdateResource.js +12 -0
- package/dist/logic/actions/execute/canUpdateResource.js.map +1 -0
- package/dist/logic/actions/execute/executeProposal.d.ts +5 -0
- package/dist/logic/actions/execute/executeProposal.js +52 -0
- package/dist/logic/actions/execute/executeProposal.js.map +1 -0
- package/dist/logic/actions/propose/getColoredActionToken.d.ts +4 -0
- package/dist/logic/actions/propose/getColoredActionToken.js +22 -0
- package/dist/logic/actions/propose/getColoredActionToken.js.map +1 -0
- package/dist/logic/actions/propose/getColoredProposalTitle.d.ts +4 -0
- package/dist/logic/actions/propose/getColoredProposalTitle.js +34 -0
- package/dist/logic/actions/propose/getColoredProposalTitle.js.map +1 -0
- package/dist/logic/actions/propose/proposeChangeForResource.d.ts +7 -0
- package/dist/logic/actions/propose/proposeChangeForResource.js +65 -0
- package/dist/logic/actions/propose/proposeChangeForResource.js.map +1 -0
- package/dist/logic/actions/propose/proposeChangeForResource.test.d.ts +1 -0
- package/dist/logic/actions/propose/proposeChangeForResource.test.js +48 -0
- package/dist/logic/actions/propose/proposeChangeForResource.test.js.map +1 -0
- package/dist/logic/commands/command.apply.d.ts +8 -0
- package/dist/logic/commands/command.apply.js +77 -0
- package/dist/logic/commands/command.apply.js.map +1 -0
- package/dist/logic/commands/command.plan.d.ts +13 -0
- package/dist/logic/commands/command.plan.js +155 -0
- package/dist/logic/commands/command.plan.js.map +1 -0
- package/dist/logic/commands/execute.d.ts +15 -0
- package/dist/logic/commands/execute.js +63 -0
- package/dist/logic/commands/execute.js.map +1 -0
- package/dist/logic/tools/compare/castReferenceToGrokableString.d.ts +16 -0
- package/dist/logic/tools/compare/castReferenceToGrokableString.js +66 -0
- package/dist/logic/tools/compare/castReferenceToGrokableString.js.map +1 -0
- package/dist/logic/tools/compare/castReferenceToGrokableString.test.d.ts +1 -0
- package/dist/logic/tools/compare/castReferenceToGrokableString.test.js +111 -0
- package/dist/logic/tools/compare/castReferenceToGrokableString.test.js.map +1 -0
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.d.ts +11 -0
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.js +61 -0
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.js.map +1 -0
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.d.ts +1 -0
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js +31 -0
- package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js.map +1 -0
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.d.ts +21 -0
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.js +53 -0
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.js.map +1 -0
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.test.d.ts +1 -0
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.test.js +31 -0
- package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.test.js.map +1 -0
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.d.ts +10 -0
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.js +41 -0
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.js.map +1 -0
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.test.d.ts +1 -0
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.test.js +174 -0
- package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.test.js.map +1 -0
- package/dist/logic/tools/context/createDeclastructContext.d.ts +10 -0
- package/dist/logic/tools/context/createDeclastructContext.js +12 -0
- package/dist/logic/tools/context/createDeclastructContext.js.map +1 -0
- package/dist/logic/tools/context/destroyDeclastructContext.d.ts +4 -0
- package/dist/logic/tools/context/destroyDeclastructContext.js +10 -0
- package/dist/logic/tools/context/destroyDeclastructContext.js.map +1 -0
- package/dist/logic/tools/provider/castProviderContextToGlobalContext.d.ts +4 -0
- package/dist/logic/tools/provider/castProviderContextToGlobalContext.js +10 -0
- package/dist/logic/tools/provider/castProviderContextToGlobalContext.js.map +1 -0
- package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.d.ts +13 -0
- package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.js +29 -0
- package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.js.map +1 -0
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.d.ts +13 -0
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.js +24 -0
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.js.map +1 -0
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.d.ts +10 -0
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.js +21 -0
- package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.js.map +1 -0
- package/dist/logic/tools/reference/buildPrimaryKeyTo.d.ts +5 -0
- package/dist/logic/tools/reference/buildPrimaryKeyTo.js +40 -0
- package/dist/logic/tools/reference/buildPrimaryKeyTo.js.map +1 -0
- package/dist/logic/tools/reference/buildReferenceTo.d.ts +28 -0
- package/dist/logic/tools/reference/buildReferenceTo.js +92 -0
- package/dist/logic/tools/reference/buildReferenceTo.js.map +1 -0
- package/dist/logic/tools/reference/buildReferenceTo.test.d.ts +1 -0
- package/dist/logic/tools/reference/buildReferenceTo.test.js +119 -0
- package/dist/logic/tools/reference/buildReferenceTo.test.js.map +1 -0
- package/dist/logic/tools/reference/buildUniqueKeyTo.d.ts +5 -0
- package/dist/logic/tools/reference/buildUniqueKeyTo.js +40 -0
- package/dist/logic/tools/reference/buildUniqueKeyTo.js.map +1 -0
- package/dist/logic/tools/reference/defineReferenceClassOf.d.ts +5 -0
- package/dist/logic/tools/reference/defineReferenceClassOf.js +25 -0
- package/dist/logic/tools/reference/defineReferenceClassOf.js.map +1 -0
- package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.d.ts +13 -0
- package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.js +36 -0
- package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.js.map +1 -0
- package/dist/logic/tools/reference/getByReference.d.ts +15 -0
- package/dist/logic/tools/reference/getByReference.js +55 -0
- package/dist/logic/tools/reference/getByReference.js.map +1 -0
- package/dist/logic/tools/reference/getByReference.test.d.ts +1 -0
- package/dist/logic/tools/reference/getByReference.test.js +92 -0
- package/dist/logic/tools/reference/getByReference.test.js.map +1 -0
- package/dist/logic/tools/reference/getByReferencedPrimaryKey.d.ts +6 -0
- package/dist/logic/tools/reference/getByReferencedPrimaryKey.js +17 -0
- package/dist/logic/tools/reference/getByReferencedPrimaryKey.js.map +1 -0
- package/dist/logic/tools/reference/getByReferencedUniqueKey.d.ts +7 -0
- package/dist/logic/tools/reference/getByReferencedUniqueKey.js +42 -0
- package/dist/logic/tools/reference/getByReferencedUniqueKey.js.map +1 -0
- package/dist/logic/tools/reference/getPrimaryKeyByReference.d.ts +15 -0
- package/dist/logic/tools/reference/getPrimaryKeyByReference.js +36 -0
- package/dist/logic/tools/reference/getPrimaryKeyByReference.js.map +1 -0
- package/dist/logic/tools/reference/getReferenceTo.d.ts +18 -0
- package/dist/logic/tools/reference/getReferenceTo.js +55 -0
- package/dist/logic/tools/reference/getReferenceTo.js.map +1 -0
- package/dist/logic/tools/reference/getReferenceTo.test.d.ts +1 -0
- package/dist/logic/tools/reference/getReferenceTo.test.js +95 -0
- package/dist/logic/tools/reference/getReferenceTo.test.js.map +1 -0
- package/dist/logic/tools/reference/getUniqueKeyByReference.d.ts +15 -0
- package/dist/logic/tools/reference/getUniqueKeyByReference.js +36 -0
- package/dist/logic/tools/reference/getUniqueKeyByReference.js.map +1 -0
- package/dist/logic/tools/reference/isPrimaryKeyReference.d.ts +6 -0
- package/dist/logic/tools/reference/isPrimaryKeyReference.js +7 -0
- package/dist/logic/tools/reference/isPrimaryKeyReference.js.map +1 -0
- package/dist/logic/tools/reference/isUniqueKeyReference.d.ts +6 -0
- package/dist/logic/tools/reference/isUniqueKeyReference.js +7 -0
- package/dist/logic/tools/reference/isUniqueKeyReference.js.map +1 -0
- package/package.json +100 -0
- package/readme.md +56 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DetailedDiff } from 'deep-object-diff';
|
|
2
|
+
import { DomainObject } from 'domain-objects';
|
|
3
|
+
import { VisualogicContext } from 'visualogic';
|
|
4
|
+
import { DeclastructContext } from '../../../domain/DeclastructContext';
|
|
5
|
+
export declare const detectDifferenceBetweenDesiredAndRemoteStateOfResource: <T extends DomainObject<any>>({ desiredState, remoteState, }: {
|
|
6
|
+
desiredState: T | null;
|
|
7
|
+
remoteState: T | null;
|
|
8
|
+
}, context: DeclastructContext & VisualogicContext) => Promise<{
|
|
9
|
+
displayable: string;
|
|
10
|
+
usable: DetailedDiff;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectDifferenceBetweenDesiredAndRemoteStateOfResource = void 0;
|
|
4
|
+
const deep_object_diff_1 = require("deep-object-diff");
|
|
5
|
+
const domain_objects_1 = require("domain-objects");
|
|
6
|
+
const jest_diff_1 = require("jest-diff");
|
|
7
|
+
const DeclaredResourceReference_1 = require("../../../domain/DeclaredResourceReference");
|
|
8
|
+
const castReferenceToGrokableString_1 = require("./castReferenceToGrokableString");
|
|
9
|
+
/**
|
|
10
|
+
* recursively traverse each key of the object and grokify any references found
|
|
11
|
+
*/
|
|
12
|
+
const withReferencesGrokified = async ({ resource }, context) => {
|
|
13
|
+
// create a clone of the resources, which we'll mutate keys on
|
|
14
|
+
const withKeysGrokified = new resource.constructor(resource);
|
|
15
|
+
// for each key holding a reference, replace reference with grokable string
|
|
16
|
+
await Promise.all(Object.keys(resource).map(async (key) => {
|
|
17
|
+
const value = resource[key];
|
|
18
|
+
if (value instanceof DeclaredResourceReference_1.DeclaredResourceReference)
|
|
19
|
+
withKeysGrokified[key] = await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference: value }, context);
|
|
20
|
+
else if (Array.isArray(value))
|
|
21
|
+
withKeysGrokified[key] = await Promise.all(value.map(async (valueItem) => value instanceof DeclaredResourceReference_1.DeclaredResourceReference
|
|
22
|
+
? await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference: valueItem }, context)
|
|
23
|
+
: await withReferencesGrokified({ resource: valueItem }, context)));
|
|
24
|
+
else if (value instanceof domain_objects_1.DomainObject)
|
|
25
|
+
withKeysGrokified[key] = await withReferencesGrokified({ resource: value }, context);
|
|
26
|
+
}));
|
|
27
|
+
// return the fingerprinted object
|
|
28
|
+
return withKeysGrokified;
|
|
29
|
+
};
|
|
30
|
+
const detectDifferenceBetweenDesiredAndRemoteStateOfResource = async ({ desiredState, remoteState, }, context) => {
|
|
31
|
+
// replace all nested references with reference fingerprints, for readability
|
|
32
|
+
const diffableDesiredState = desiredState
|
|
33
|
+
? // remove the metadata values from the desired state for diff, since these properties dont describe the data, they are just additional data typically generated by the remote state which cant be locally declared (e.g., uuid, createdAt, etc)
|
|
34
|
+
(0, domain_objects_1.omitMetadataValues)(await withReferencesGrokified({ resource: desiredState }, context))
|
|
35
|
+
: null;
|
|
36
|
+
const diffableRemoteState = remoteState
|
|
37
|
+
? // remove the metadata values from the remote state for diff, since these properties dont describe the data, they are just additional data typically generated by the remote state which cant be locally declared (e.g., uuid, createdAt, etc)
|
|
38
|
+
(0, domain_objects_1.omitMetadataValues)(await withReferencesGrokified({ resource: remoteState }, context))
|
|
39
|
+
: null;
|
|
40
|
+
// define a displayable difference
|
|
41
|
+
const displayableDifference = (0, jest_diff_1.diff)(diffableDesiredState ?? {}, diffableRemoteState ?? {}, {
|
|
42
|
+
omitAnnotationLines: true,
|
|
43
|
+
aAnnotation: 'Desired State',
|
|
44
|
+
bAnnotation: 'Remote State',
|
|
45
|
+
aIndicator: '+',
|
|
46
|
+
bIndicator: '-',
|
|
47
|
+
});
|
|
48
|
+
// replace the "Object {}" placeholder we have to use to represent null state, if present (since jest shows "Comparing two different types of values. Expected object but received null." if we try to use null directly)
|
|
49
|
+
const cleanedDisplayableDifference = displayableDifference
|
|
50
|
+
?.replace('- Object {}', '- null')
|
|
51
|
+
.replace('+ Object {}', '+ null');
|
|
52
|
+
// define a usable difference
|
|
53
|
+
const usableDifference = (0, deep_object_diff_1.detailedDiff)(diffableRemoteState ?? {}, diffableDesiredState ?? {}); // TODO: improve the usable difference. use the `objectDiff` and add our own info + make a more useful type
|
|
54
|
+
// return both
|
|
55
|
+
return {
|
|
56
|
+
displayable: cleanedDisplayableDifference,
|
|
57
|
+
usable: usableDifference,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
exports.detectDifferenceBetweenDesiredAndRemoteStateOfResource = detectDifferenceBetweenDesiredAndRemoteStateOfResource;
|
|
61
|
+
//# sourceMappingURL=detectDifferenceBetweenDesiredAndRemoteStateOfResource.js.map
|
package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectDifferenceBetweenDesiredAndRemoteStateOfResource.js","sourceRoot":"","sources":["../../../../src/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.ts"],"names":[],"mappings":";;;AAAA,uDAA4E;AAC5E,mDAAkE;AAClE,yCAA6C;AAI7C,yFAAsF;AAEtF,mFAAgF;AAEhF;;GAEG;AACH,MAAM,uBAAuB,GAAG,KAAK,EACnC,EAAE,QAAQ,EAAkC,EAC5C,OAA+C,EAC/C,EAAE;IACF,8DAA8D;IAC9D,MAAM,iBAAiB,GACrB,IAAK,QAAQ,CAAC,WAAmC,CAAC,QAAQ,CAAC,CAAC;IAE9D,2EAA2E;IAC3E,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACtC,MAAM,KAAK,GAAI,QAAgB,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,KAAK,YAAY,qDAAyB;YAC5C,iBAAiB,CAAC,GAAG,CAAC,GAAG,MAAM,IAAA,6DAA6B,EAC1D,EAAE,SAAS,EAAE,KAAK,EAAE,EACpB,OAAO,CACR,CAAC;aACC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAC3B,iBAAiB,CAAC,GAAG,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CACxC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAC5B,KAAK,YAAY,qDAAyB;gBACxC,CAAC,CAAC,MAAM,IAAA,6DAA6B,EACjC,EAAE,SAAS,EAAE,SAAS,EAAE,EACxB,OAAO,CACR;gBACH,CAAC,CAAC,MAAM,uBAAuB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,OAAO,CAAC,CACpE,CACF,CAAC;aACC,IAAI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CAAC,CAAC,2GAA2G;IAE9G,cAAc;IACd,OAAO;QACL,WAAW,EAAE,4BAA4B;QACzC,MAAM,EAAE,gBAAgB;KACzB,CAAC;AACJ,CAAC,CAAC;AA1DW,QAAA,sDAAsD,0DA0DjE"}
|
package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getExampleContext_1 = require("../../../__test_assets__/getExampleContext");
|
|
4
|
+
const detectDifferenceBetweenDesiredAndRemoteStateOfResource_1 = require("./detectDifferenceBetweenDesiredAndRemoteStateOfResource");
|
|
5
|
+
const { exampleContext, exampleMachine, CNCMachine } = (0, getExampleContext_1.getExampleContext)();
|
|
6
|
+
describe('detectDifferenceBetweenDesiredAndRemoteStateOfResource', () => {
|
|
7
|
+
it('should return a helpful displayable difference and usable difference', async () => {
|
|
8
|
+
const desiredState = exampleMachine;
|
|
9
|
+
const remoteState = new CNCMachine({
|
|
10
|
+
...desiredState,
|
|
11
|
+
location: 'moon',
|
|
12
|
+
});
|
|
13
|
+
const difference = await (0, detectDifferenceBetweenDesiredAndRemoteStateOfResource_1.detectDifferenceBetweenDesiredAndRemoteStateOfResource)({
|
|
14
|
+
desiredState,
|
|
15
|
+
remoteState,
|
|
16
|
+
}, exampleContext);
|
|
17
|
+
expect(difference).toMatchSnapshot();
|
|
18
|
+
});
|
|
19
|
+
it('should show the case where we want to create a new resource well', async () => {
|
|
20
|
+
const desiredState = exampleMachine;
|
|
21
|
+
const remoteState = null;
|
|
22
|
+
const difference = await (0, detectDifferenceBetweenDesiredAndRemoteStateOfResource_1.detectDifferenceBetweenDesiredAndRemoteStateOfResource)({
|
|
23
|
+
desiredState,
|
|
24
|
+
remoteState,
|
|
25
|
+
}, exampleContext);
|
|
26
|
+
console.log(difference.displayable);
|
|
27
|
+
console.log(difference.usable);
|
|
28
|
+
expect(difference).toMatchSnapshot();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js.map
|
package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js","sourceRoot":"","sources":["../../../../src/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.ts"],"names":[],"mappings":";;AAAA,kFAA+E;AAC/E,qIAAkI;AAElI,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,IAAA,qCAAiB,GAAE,CAAC;AAE3E,QAAQ,CAAC,wDAAwD,EAAE,GAAG,EAAE;IACtE,EAAE,CAAC,sEAAsE,EAAE,KAAK,IAAI,EAAE;QACpF,MAAM,YAAY,GAAG,cAAc,CAAC;QACpC,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC;YACjC,GAAG,YAAY;YACf,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;QACH,MAAM,UAAU,GACd,MAAM,IAAA,+GAAsD,EAC1D;YACE,YAAY;YACZ,WAAW;SACZ,EACD,cAAc,CACf,CAAC;QACJ,MAAM,CAAC,UAAU,CAAC,CAAC,eAAe,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,kEAAkE,EAAE,KAAK,IAAI,EAAE;QAChF,MAAM,YAAY,GAAG,cAAc,CAAC;QACpC,MAAM,WAAW,GAAG,IAAI,CAAC;QACzB,MAAM,UAAU,GACd,MAAM,IAAA,+GAAsD,EAC1D;YACE,YAAY;YACZ,WAAW;SACZ,EACD,cAAc,CACf,CAAC;QACJ,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC/B,MAAM,CAAC,UAAU,CAAC,CAAC,eAAe,EAAE,CAAC;IACvC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { VisualogicContext } from 'visualogic';
|
|
2
|
+
import { DeclaredResourceReference } from '../../../domain/DeclaredResourceReference';
|
|
3
|
+
import { DeclastructContext } from '../../../domain/DeclastructContext';
|
|
4
|
+
/**
|
|
5
|
+
* resolves a reference to a common form, which any reference can be normalized to, in which it can be compared
|
|
6
|
+
* - references can only be compared in fully-expanded unique-key form
|
|
7
|
+
* - this function resolves all primary key references into fully-expanded unique-key form
|
|
8
|
+
*
|
|
9
|
+
* context
|
|
10
|
+
* - references to the same resource can be defined by primary-key or unique-key
|
|
11
|
+
* - there is no way to determine whether a unique-key reference and a primary-key reference are referring to the same resource
|
|
12
|
+
* - the unique-key reference is the only reference form which can be guaranteed to be resolvable
|
|
13
|
+
* - a primary-key reference can always be resolved to a unique-key reference (if a resource has a primary key assigned, then it can be looked up by primary key in the remote state)
|
|
14
|
+
* - a unique-key reference may not be resolvable into a primary-key reference (the resource may not exist yet, and so there may not exist a primary-key defined for the resource)
|
|
15
|
+
* - a unique-key may itself be composed of nested unique keys
|
|
16
|
+
* - for example, a `GoogleAdsAdGroup` is unique per `GoogleAdsCampaign` which itself is unique per `GoogleAdsAccount`
|
|
17
|
+
* - these nested references must each be resolved
|
|
18
|
+
*/
|
|
19
|
+
export declare const resolveReferenceToCommonComparableForm: <T extends DeclaredResourceReference<any, any, any>>({ reference }: {
|
|
20
|
+
reference: T;
|
|
21
|
+
}, context: DeclastructContext & VisualogicContext) => Promise<T>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveReferenceToCommonComparableForm = void 0;
|
|
4
|
+
const error_fns_1 = require("@ehmpathy/error-fns");
|
|
5
|
+
const error_fns_2 = require("@ehmpathy/error-fns");
|
|
6
|
+
const __1 = require("../../..");
|
|
7
|
+
const DeclaredResourceReference_1 = require("../../../domain/DeclaredResourceReference");
|
|
8
|
+
const getByReference_1 = require("../reference/getByReference");
|
|
9
|
+
const resolveReferencesToCommonComparableForm_1 = require("./resolveReferencesToCommonComparableForm");
|
|
10
|
+
/**
|
|
11
|
+
* resolves a reference to a common form, which any reference can be normalized to, in which it can be compared
|
|
12
|
+
* - references can only be compared in fully-expanded unique-key form
|
|
13
|
+
* - this function resolves all primary key references into fully-expanded unique-key form
|
|
14
|
+
*
|
|
15
|
+
* context
|
|
16
|
+
* - references to the same resource can be defined by primary-key or unique-key
|
|
17
|
+
* - there is no way to determine whether a unique-key reference and a primary-key reference are referring to the same resource
|
|
18
|
+
* - the unique-key reference is the only reference form which can be guaranteed to be resolvable
|
|
19
|
+
* - a primary-key reference can always be resolved to a unique-key reference (if a resource has a primary key assigned, then it can be looked up by primary key in the remote state)
|
|
20
|
+
* - a unique-key reference may not be resolvable into a primary-key reference (the resource may not exist yet, and so there may not exist a primary-key defined for the resource)
|
|
21
|
+
* - a unique-key may itself be composed of nested unique keys
|
|
22
|
+
* - for example, a `GoogleAdsAdGroup` is unique per `GoogleAdsCampaign` which itself is unique per `GoogleAdsAccount`
|
|
23
|
+
* - these nested references must each be resolved
|
|
24
|
+
*/
|
|
25
|
+
const resolveReferenceToCommonComparableForm = async ({ reference }, context) => {
|
|
26
|
+
// if this is a unique key reference, resolve any nested references and return that result
|
|
27
|
+
if (reference.identifiedBy.key === DeclaredResourceReference_1.DeclaredResourceReferenceKeyType.UNIQUE_KEY) {
|
|
28
|
+
const uniqueKeyValueWithNestedReferencesResolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({
|
|
29
|
+
in: reference.identifiedBy.value,
|
|
30
|
+
}, context);
|
|
31
|
+
return new DeclaredResourceReference_1.DeclaredResourceReference({
|
|
32
|
+
referenceOf: reference.referenceOf,
|
|
33
|
+
identifiedBy: {
|
|
34
|
+
key: reference.identifiedBy.key,
|
|
35
|
+
value: uniqueKeyValueWithNestedReferencesResolved,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// if this is a primary key reference, lookup the resource and evaluate common form from there
|
|
40
|
+
const resource = await (0, getByReference_1.getByReference)({ reference }, context);
|
|
41
|
+
if (!resource)
|
|
42
|
+
throw new error_fns_2.BadRequestError('could not find resource by primary key reference. can not resolveReferenceToCommonComparableForm', { reference });
|
|
43
|
+
const resolvedShallowReference = (0, __1.getReferenceTo)(resource); // get reference to will produce a reference that may be shallow, since it synchronously computes the deepest reference possible from the available data returned by the interface
|
|
44
|
+
if (resolvedShallowReference.identifiedBy.key !==
|
|
45
|
+
DeclaredResourceReference_1.DeclaredResourceReferenceKeyType.UNIQUE_KEY // sanity check that the resolved resource reference is defined by unique key; that's what it should normalize to since it's the most common form
|
|
46
|
+
)
|
|
47
|
+
throw new error_fns_1.UnexpectedCodePathError('should have resolved a reference by unique key from resolved resource', { resource, resolvedReference: resolvedShallowReference });
|
|
48
|
+
const resolvedReference = await (0, exports.resolveReferenceToCommonComparableForm)({ reference: resolvedShallowReference }, // now resolve the reference into the deep common form
|
|
49
|
+
context);
|
|
50
|
+
return resolvedReference;
|
|
51
|
+
};
|
|
52
|
+
exports.resolveReferenceToCommonComparableForm = resolveReferenceToCommonComparableForm;
|
|
53
|
+
//# sourceMappingURL=resolveReferenceToCommonComparableForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveReferenceToCommonComparableForm.js","sourceRoot":"","sources":["../../../../src/logic/tools/compare/resolveReferenceToCommonComparableForm.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAC9D,mDAAsD;AAGtD,gCAA0C;AAC1C,yFAGmD;AAEnD,gEAA6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CjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const __1 = require("../../..");
|
|
4
|
+
const getExampleContext_1 = require("../../../__test_assets__/getExampleContext");
|
|
5
|
+
const resolveReferenceToCommonComparableForm_1 = require("./resolveReferenceToCommonComparableForm");
|
|
6
|
+
const { exampleContext, exampleMachine, CNCMachine } = (0, getExampleContext_1.getExampleContext)();
|
|
7
|
+
describe('resolveReferenceToCommonComparableForm', () => {
|
|
8
|
+
it('should change nothing on a shallow unique key reference', async () => {
|
|
9
|
+
const original = (0, __1.buildRef)(CNCMachine, {
|
|
10
|
+
serialNumber: exampleMachine.serialNumber,
|
|
11
|
+
});
|
|
12
|
+
const resolved = await (0, resolveReferenceToCommonComparableForm_1.resolveReferenceToCommonComparableForm)({
|
|
13
|
+
reference: original,
|
|
14
|
+
}, exampleContext);
|
|
15
|
+
expect(resolved).toEqual(original);
|
|
16
|
+
});
|
|
17
|
+
it('should resolve unique key reference from primary key reference', async () => {
|
|
18
|
+
const original = (0, __1.buildRef)(CNCMachine, {
|
|
19
|
+
uuid: exampleMachine.uuid,
|
|
20
|
+
});
|
|
21
|
+
const expected = (0, __1.buildRef)(CNCMachine, {
|
|
22
|
+
serialNumber: exampleMachine.serialNumber,
|
|
23
|
+
});
|
|
24
|
+
const resolved = await (0, resolveReferenceToCommonComparableForm_1.resolveReferenceToCommonComparableForm)({
|
|
25
|
+
reference: original,
|
|
26
|
+
}, exampleContext);
|
|
27
|
+
expect(resolved).toEqual(expected);
|
|
28
|
+
});
|
|
29
|
+
it.todo('should resolve a primary key reference nested in a unique key reference to unique key form');
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=resolveReferenceToCommonComparableForm.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveReferenceToCommonComparableForm.test.js","sourceRoot":"","sources":["../../../../src/logic/tools/compare/resolveReferenceToCommonComparableForm.test.ts"],"names":[],"mappings":";;AAAA,gCAAoC;AACpC,kFAGoD;AACpD,qGAAkG;AAElG,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,IAAA,qCAAiB,GAAE,CAAC;AAE3E,QAAQ,CAAC,wCAAwC,EAAE,GAAG,EAAE;IACtD,EAAE,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;QACvE,MAAM,QAAQ,GAAwB,IAAA,YAAQ,EAAC,UAAU,EAAE;YACzD,YAAY,EAAE,cAAc,CAAC,YAAY;SAC1C,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,IAAA,+EAAsC,EAC3D;YACE,SAAS,EAAE,QAAQ;SACpB,EACD,cAAc,CACf,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;QAC9E,MAAM,QAAQ,GAAwB,IAAA,YAAQ,EAAC,UAAU,EAAE;YACzD,IAAI,EAAE,cAAc,CAAC,IAAI;SAC1B,CAAC,CAAC;QACH,MAAM,QAAQ,GAAwB,IAAA,YAAQ,EAAC,UAAU,EAAE;YACzD,YAAY,EAAE,cAAc,CAAC,YAAY;SAC1C,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,IAAA,+EAAsC,EAC3D;YACE,SAAS,EAAE,QAAQ;SACpB,EACD,cAAc,CACf,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,IAAI,CACL,4FAA4F,CAC7F,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { VisualogicContext } from 'visualogic';
|
|
2
|
+
import { DeclastructContext } from '../../../domain/DeclastructContext';
|
|
3
|
+
/**
|
|
4
|
+
* recursively resolves all references in the given object to their common-comparable-form
|
|
5
|
+
*
|
|
6
|
+
* see the docs on `resolveReferenceToCommonComparableForm` for more info
|
|
7
|
+
*/
|
|
8
|
+
export declare const resolveReferencesToCommonComparableForm: <T extends unknown>({ in: value }: {
|
|
9
|
+
in: T;
|
|
10
|
+
}, context: DeclastructContext & VisualogicContext) => Promise<T>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveReferencesToCommonComparableForm = void 0;
|
|
4
|
+
const domain_objects_1 = require("domain-objects");
|
|
5
|
+
const DeclaredResourceReference_1 = require("../../../domain/DeclaredResourceReference");
|
|
6
|
+
const resolveReferenceToCommonComparableForm_1 = require("./resolveReferenceToCommonComparableForm");
|
|
7
|
+
/**
|
|
8
|
+
* recursively resolves all references in the given object to their common-comparable-form
|
|
9
|
+
*
|
|
10
|
+
* see the docs on `resolveReferenceToCommonComparableForm` for more info
|
|
11
|
+
*/
|
|
12
|
+
const resolveReferencesToCommonComparableForm = async ({ in: value }, context) => {
|
|
13
|
+
// if this is not an object, then do nothing to it
|
|
14
|
+
if (!Array.isArray(value) && typeof value !== 'object')
|
|
15
|
+
return value; // if this value is not an array and is not an object, then it's a literal, so no more preparation required, return it itself
|
|
16
|
+
if (value === null)
|
|
17
|
+
return value; // if its null, return it too (null is typeof 'object' in js :shrug:)
|
|
18
|
+
// if its an array, then `resolve references` on each element
|
|
19
|
+
if (Array.isArray(value))
|
|
20
|
+
return (await Promise.all(value.map((el) => (0, exports.resolveReferencesToCommonComparableForm)({ in: el }, context))));
|
|
21
|
+
// if it's a reference, then resolve the reference
|
|
22
|
+
if (value instanceof DeclaredResourceReference_1.DeclaredResourceReference)
|
|
23
|
+
return await (0, resolveReferenceToCommonComparableForm_1.resolveReferenceToCommonComparableForm)({ reference: value }, context);
|
|
24
|
+
// otherwise, it's a generic object, so resolve the references on each key
|
|
25
|
+
const object = value;
|
|
26
|
+
const resolvedObject = {};
|
|
27
|
+
for (const nestedKey of Object.keys(object)) {
|
|
28
|
+
const nestedValue = object[nestedKey];
|
|
29
|
+
const resolvedValue = await (0, exports.resolveReferencesToCommonComparableForm)({ in: nestedValue }, context);
|
|
30
|
+
resolvedObject[nestedKey] = resolvedValue;
|
|
31
|
+
}
|
|
32
|
+
// if the object was a declared resource, then instantiate it with the same constructor and return that
|
|
33
|
+
if (object instanceof domain_objects_1.DomainObject) {
|
|
34
|
+
const DomainObjectConstructor = object.constructor;
|
|
35
|
+
return new DomainObjectConstructor(resolvedObject);
|
|
36
|
+
}
|
|
37
|
+
// otherwise, return the resolved object
|
|
38
|
+
return resolvedObject;
|
|
39
|
+
};
|
|
40
|
+
exports.resolveReferencesToCommonComparableForm = resolveReferencesToCommonComparableForm;
|
|
41
|
+
//# sourceMappingURL=resolveReferencesToCommonComparableForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveReferencesToCommonComparableForm.js","sourceRoot":"","sources":["../../../../src/logic/tools/compare/resolveReferencesToCommonComparableForm.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAG9C,yFAAsF;AAEtF,qGAAkG;AAElG;;;;GAIG;AACI,MAAM,uCAAuC,GAAG,KAAK,EAC1D,EAAE,EAAE,EAAE,KAAK,EAAa,EACxB,OAA+C,EACnC,EAAE;IACd,kDAAkD;IAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC,CAAC,6HAA6H;IACnM,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC,CAAC,qEAAqE;IAEvG,6DAA6D;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACtB,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CACvB,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACf,IAAA,+CAAuC,EAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAC7D,CACF,CAAM,CAAC;IAEV,kDAAkD;IAClD,IAAI,KAAK,YAAY,qDAAyB;QAC5C,OAAO,MAAM,IAAA,+EAAsC,EACjD,EAAE,SAAS,EAAE,KAAK,EAAE,EACpB,OAAO,CACR,CAAC;IAEJ,0EAA0E;IAC1E,MAAM,MAAM,GAAwB,KAAY,CAAC;IACjD,MAAM,cAAc,GAAwB,EAAE,CAAC;IAC/C,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5C,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM,aAAa,GAAG,MAAM,IAAA,+CAAuC,EACjE,EAAE,EAAE,EAAE,WAAW,EAAE,EACnB,OAAO,CACR,CAAC;QACF,cAAc,CAAC,SAAS,CAAC,GAAG,aAAa,CAAC;IAC5C,CAAC;IAED,uGAAuG;IACvG,IAAI,MAAM,YAAY,6BAAY,EAAE,CAAC;QACnC,MAAM,uBAAuB,GAAG,MAAM,CAAC,WAAkC,CAAC;QAC1E,OAAO,IAAI,uBAAuB,CAAC,cAAc,CAAM,CAAC;IAC1D,CAAC;IAED,wCAAwC;IACxC,OAAO,cAAmB,CAAC;AAC7B,CAAC,CAAC;AA3CW,QAAA,uCAAuC,2CA2ClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const domain_objects_1 = require("domain-objects");
|
|
4
|
+
const __1 = require("../../..");
|
|
5
|
+
const getExampleContext_1 = require("../../../__test_assets__/getExampleContext");
|
|
6
|
+
const DeclaredResourceReference_1 = require("../../../domain/DeclaredResourceReference");
|
|
7
|
+
const resolveReferencesToCommonComparableForm_1 = require("./resolveReferencesToCommonComparableForm");
|
|
8
|
+
const { exampleContext, exampleMachine, CNCMachine, exampleRegistration, CNCMachineRegistration, } = (0, getExampleContext_1.getExampleContext)();
|
|
9
|
+
describe('resolveReferencesToCommonComparableForm', () => {
|
|
10
|
+
describe('basic types', () => {
|
|
11
|
+
it('should resolve strings', async () => {
|
|
12
|
+
const original = 'hello!';
|
|
13
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
14
|
+
expect(resolved).toEqual(original);
|
|
15
|
+
});
|
|
16
|
+
it('should resolve numbers', async () => {
|
|
17
|
+
const original = 821;
|
|
18
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
19
|
+
expect(resolved).toEqual(original);
|
|
20
|
+
});
|
|
21
|
+
// TODO: fix this
|
|
22
|
+
it.skip('should resolve dates', async () => {
|
|
23
|
+
const original = new Date('2020-08-21 00:00:00');
|
|
24
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
25
|
+
expect(resolved).toEqual(original);
|
|
26
|
+
});
|
|
27
|
+
it('should resolve undefined', async () => {
|
|
28
|
+
const original = undefined;
|
|
29
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
30
|
+
expect(resolved).toEqual(original);
|
|
31
|
+
});
|
|
32
|
+
it('should resolve nulls', async () => {
|
|
33
|
+
const original = null;
|
|
34
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
35
|
+
expect(resolved).toEqual(original);
|
|
36
|
+
});
|
|
37
|
+
// TODO: fix this
|
|
38
|
+
it.skip('should resolve buffers', async () => {
|
|
39
|
+
const original = Buffer.from('821');
|
|
40
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
41
|
+
expect(resolved).toEqual(original);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('arrays', () => {
|
|
45
|
+
it('should be able to resolve arrays', async () => {
|
|
46
|
+
const original = ['821', 721, 'leopard', 7, 'apple', 3];
|
|
47
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
48
|
+
expect(resolved).toEqual(original);
|
|
49
|
+
});
|
|
50
|
+
it('should resolve arrays even if they have objects', async () => {
|
|
51
|
+
const original = [
|
|
52
|
+
'banana',
|
|
53
|
+
{ id: 1, value: 821, meaning: 42 },
|
|
54
|
+
821,
|
|
55
|
+
{ id: 0, value: undefined, meaning: null }, // should go first, because id is 0
|
|
56
|
+
];
|
|
57
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
58
|
+
expect(resolved).toEqual(original);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe('objects', () => {
|
|
62
|
+
it('should be able to resolve an object with all sorts of types', async () => {
|
|
63
|
+
const original = {
|
|
64
|
+
color: 'blue',
|
|
65
|
+
cost: 821,
|
|
66
|
+
orders: [
|
|
67
|
+
{ id: 1, value: 821, meaning: 42 },
|
|
68
|
+
{ id: 0, value: undefined, meaning: null },
|
|
69
|
+
],
|
|
70
|
+
application: {
|
|
71
|
+
type: 'PAINTING',
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
75
|
+
expect(resolved).toEqual(original);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('domain objects', () => {
|
|
79
|
+
class Spaceship extends domain_objects_1.DomainEntity {
|
|
80
|
+
}
|
|
81
|
+
Spaceship.primary = ['uuid'];
|
|
82
|
+
Spaceship.unique = ['serialNumber'];
|
|
83
|
+
Spaceship.updatable = ['serialNumber'];
|
|
84
|
+
class Address extends domain_objects_1.DomainLiteral {
|
|
85
|
+
}
|
|
86
|
+
class Spaceport extends domain_objects_1.DomainEntity {
|
|
87
|
+
}
|
|
88
|
+
Spaceport.primary = ['uuid'];
|
|
89
|
+
Spaceport.unique = ['uuid'];
|
|
90
|
+
Spaceport.updatable = ['spaceships'];
|
|
91
|
+
Spaceport.nested = {
|
|
92
|
+
address: Address,
|
|
93
|
+
spaceships: DeclaredResourceReference_1.DeclaredResourceReference,
|
|
94
|
+
};
|
|
95
|
+
// run the tests
|
|
96
|
+
it('should resolve a domain object with no nested references', async () => {
|
|
97
|
+
const ship = new Spaceship({
|
|
98
|
+
serialNumber: '__UUID__',
|
|
99
|
+
fuelQuantity: 9001,
|
|
100
|
+
passengers: 21,
|
|
101
|
+
});
|
|
102
|
+
const original = ship;
|
|
103
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
104
|
+
expect(resolved).toEqual(original);
|
|
105
|
+
});
|
|
106
|
+
it('should not change nested references already in common form', async () => {
|
|
107
|
+
const shipA = new Spaceship({
|
|
108
|
+
serialNumber: '__SHIP_A__',
|
|
109
|
+
fuelQuantity: 9001,
|
|
110
|
+
passengers: 21,
|
|
111
|
+
});
|
|
112
|
+
const shipB = new Spaceship({
|
|
113
|
+
uuid: '821',
|
|
114
|
+
serialNumber: '__SHIP_B__',
|
|
115
|
+
fuelQuantity: 7000,
|
|
116
|
+
passengers: 42,
|
|
117
|
+
});
|
|
118
|
+
const spaceport = new Spaceport({
|
|
119
|
+
uuid: '__SPACEPORT_UUID__',
|
|
120
|
+
address: new Address({
|
|
121
|
+
galaxy: 'Milky Way',
|
|
122
|
+
solarSystem: 'Sun',
|
|
123
|
+
planet: 'Earth',
|
|
124
|
+
continent: 'North America',
|
|
125
|
+
}),
|
|
126
|
+
spaceships: [(0, __1.getRef)(shipA), (0, __1.getRef)(shipB)],
|
|
127
|
+
});
|
|
128
|
+
const original = spaceport;
|
|
129
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
130
|
+
expect(resolved).toEqual(original);
|
|
131
|
+
});
|
|
132
|
+
it('should resolve each nested primary key reference to its common form', async () => {
|
|
133
|
+
const primaryKeyRef = (0, __1.buildRef)(CNCMachine, {
|
|
134
|
+
uuid: exampleMachine.uuid,
|
|
135
|
+
});
|
|
136
|
+
const uniqueKeyRef = (0, __1.buildRef)(CNCMachine, {
|
|
137
|
+
serialNumber: exampleMachine.serialNumber,
|
|
138
|
+
});
|
|
139
|
+
const original = {
|
|
140
|
+
machine: primaryKeyRef,
|
|
141
|
+
};
|
|
142
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
143
|
+
expect(resolved).not.toEqual(original);
|
|
144
|
+
expect(resolved).toEqual({ machine: uniqueKeyRef }); // should have taken it to common form
|
|
145
|
+
});
|
|
146
|
+
it('should resolve each nested unique key reference to its common form', async () => {
|
|
147
|
+
const uniqueKeyRef = (0, __1.buildRef)(CNCMachine, {
|
|
148
|
+
serialNumber: exampleMachine.serialNumber,
|
|
149
|
+
});
|
|
150
|
+
const original = {
|
|
151
|
+
machine: uniqueKeyRef,
|
|
152
|
+
};
|
|
153
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
154
|
+
expect(resolved).toEqual({ machine: uniqueKeyRef }); // should have taken it to common form
|
|
155
|
+
});
|
|
156
|
+
it('should resolve a primary key reference to a multi level nested unique key reference common form', async () => {
|
|
157
|
+
const primaryKeyRef = (0, __1.buildRef)(CNCMachineRegistration, {
|
|
158
|
+
uuid: exampleRegistration.uuid,
|
|
159
|
+
});
|
|
160
|
+
const uniqueKeyRef = (0, __1.buildRef)(CNCMachineRegistration, {
|
|
161
|
+
machine: (0, __1.buildRef)(CNCMachine, {
|
|
162
|
+
serialNumber: exampleMachine.serialNumber,
|
|
163
|
+
}),
|
|
164
|
+
});
|
|
165
|
+
const original = {
|
|
166
|
+
registration: primaryKeyRef,
|
|
167
|
+
};
|
|
168
|
+
const resolved = await (0, resolveReferencesToCommonComparableForm_1.resolveReferencesToCommonComparableForm)({ in: original }, exampleContext);
|
|
169
|
+
expect(resolved).not.toEqual(original);
|
|
170
|
+
expect(resolved).toEqual({ registration: uniqueKeyRef }); // should have taken it to common form});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
//# sourceMappingURL=resolveReferencesToCommonComparableForm.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveReferencesToCommonComparableForm.test.js","sourceRoot":"","sources":["../../../../src/logic/tools/compare/resolveReferencesToCommonComparableForm.test.ts"],"names":[],"mappings":";;AAAA,mDAA6D;AAE7D,gCAA4C;AAC5C,kFAIoD;AACpD,yFAAsF;AACtF,uGAAoG;AAEpG,MAAM,EACJ,cAAc,EACd,cAAc,EACd,UAAU,EACV,mBAAmB,EACnB,sBAAsB,GACvB,GAAG,IAAA,qCAAiB,GAAE,CAAC;AAExB,QAAQ,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACvD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;YACtC,MAAM,QAAQ,GAAG,QAAQ,CAAC;YAC1B,MAAM,QAAQ,GAAG,MAAM,IAAA,iFAAuC,EAC5D,EAAE,EAAE,EAAE,QAAQ,EAAE,EAChB,cAAc,CACf,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QACH,EAAE,CAAC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AAoC,IAAA,YAAQ,EAC7D,sBAAsB,EACtB;gBACE,IAAI,EAAE,mBAAmB,CAAC,IAAI;aAC/B,CACF,CAAC;YACF,MAAM,YAAY,GAAoC,IAAA,YAAQ,EAC5D,sBAAsB,EACtB;gBACE,OAAO,EAAE,IAAA,YAAQ,EAAC,UAAU,EAAE;oBAC5B,YAAY,EAAE,cAAc,CAAC,YAAY;iBAC1C,CAAC;aACH,CACF,CAAC;YACF,MAAM,QAAQ,GAAG;gBACf,YAAY,EAAE,aAAa;aAC5B,CAAC;YACF,MAAM,QAAQ,GAAG,MAAM,IAAA,iFAAuC,EAC5D,EAAE,EAAE,EAAE,QAAQ,EAAE,EAChB,cAAc,CACf,CAAC;YACF,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACvC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,yCAAyC;QACrG,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LogMethods } from 'simple-leveled-log-methods';
|
|
2
|
+
import { VisualogicContext } from 'visualogic';
|
|
3
|
+
import { DeclaredResource } from '../../../domain/DeclaredResource';
|
|
4
|
+
import { DeclastructContext } from '../../../domain/DeclastructContext';
|
|
5
|
+
import { DeclastructProvider } from '../../../domain/DeclastructProvider';
|
|
6
|
+
export declare const createDeclastructContext: ({ providers, resources, log, }: {
|
|
7
|
+
providers: DeclastructProvider<any>[];
|
|
8
|
+
resources: DeclaredResource[];
|
|
9
|
+
log: LogMethods;
|
|
10
|
+
}) => DeclastructContext & VisualogicContext;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDeclastructContext = void 0;
|
|
4
|
+
const createDeclastructContext = ({ providers, resources, log, }) => {
|
|
5
|
+
return {
|
|
6
|
+
providers,
|
|
7
|
+
resources,
|
|
8
|
+
log,
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
exports.createDeclastructContext = createDeclastructContext;
|
|
12
|
+
//# sourceMappingURL=createDeclastructContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDeclastructContext.js","sourceRoot":"","sources":["../../../../src/logic/tools/context/createDeclastructContext.ts"],"names":[],"mappings":";;;AAOO,MAAM,wBAAwB,GAAG,CAAC,EACvC,SAAS,EACT,SAAS,EACT,GAAG,GAKJ,EAA0C,EAAE;IAC3C,OAAO;QACL,SAAS;QACT,SAAS;QACT,GAAG;KACJ,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,wBAAwB,4BAcnC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.destroyDeclastructContext = void 0;
|
|
4
|
+
const destroyDeclastructContext = async ({ context, }) => {
|
|
5
|
+
// run the "afterall" of each provider
|
|
6
|
+
await Promise.all(context.providers.map((provider) => provider.hooks.afterAll ? provider.hooks.afterAll() : undefined));
|
|
7
|
+
// todo: mark the context as "destroyed" so it wont be used anymore?
|
|
8
|
+
};
|
|
9
|
+
exports.destroyDeclastructContext = destroyDeclastructContext;
|
|
10
|
+
//# sourceMappingURL=destroyDeclastructContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destroyDeclastructContext.js","sourceRoot":"","sources":["../../../../src/logic/tools/context/destroyDeclastructContext.ts"],"names":[],"mappings":";;;AAEO,MAAM,yBAAyB,GAAG,KAAK,EAAE,EAC9C,OAAO,GAGR,EAAE,EAAE;IACH,sCAAsC;IACtC,MAAM,OAAO,CAAC,GAAG,CACf,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CACjC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAChE,CACF,CAAC;IAEF,oEAAoE;AACtE,CAAC,CAAC;AAbW,QAAA,yBAAyB,6BAapC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { VisualogicContext } from 'visualogic';
|
|
2
|
+
import { DeclastructContext } from '../../../domain/DeclastructContext';
|
|
3
|
+
import { DeclastructProviderContext } from '../../../domain/DeclastructProviderContext';
|
|
4
|
+
export declare const castProviderContextToGlobalContext: (from: DeclastructProviderContext<any>) => DeclastructContext & VisualogicContext;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.castProviderContextToGlobalContext = void 0;
|
|
4
|
+
const castProviderContextToGlobalContext = (from) => ({
|
|
5
|
+
providers: [from.provider],
|
|
6
|
+
resources: from.resources ?? [],
|
|
7
|
+
log: from.log,
|
|
8
|
+
});
|
|
9
|
+
exports.castProviderContextToGlobalContext = castProviderContextToGlobalContext;
|
|
10
|
+
//# sourceMappingURL=castProviderContextToGlobalContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"castProviderContextToGlobalContext.js","sourceRoot":"","sources":["../../../../src/logic/tools/provider/castProviderContextToGlobalContext.ts"],"names":[],"mappings":";;;AAKO,MAAM,kCAAkC,GAAG,CAChD,IAAqC,EACG,EAAE,CAAC,CAAC;IAC5C,SAAS,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC1B,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,EAAE;IAC/B,GAAG,EAAE,IAAI,CAAC,GAAG;CACd,CAAC,CAAC;AANU,QAAA,kCAAkC,sCAM5C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DeclastructContext } from '../../../domain/DeclastructContext';
|
|
2
|
+
import { DeclastructProviderAgentOptions } from '../../../domain/DeclastructProvider';
|
|
3
|
+
import { DeclastructProviderContext } from '../../../domain/DeclastructProviderContext';
|
|
4
|
+
/**
|
|
5
|
+
* defines the provider specific context for resources of a specific class, from the full context
|
|
6
|
+
*
|
|
7
|
+
* relevance
|
|
8
|
+
* - we dont share the full declastruct context to providers, due to security, becuase credentials are defined in the full context
|
|
9
|
+
* - instead, we only share the the data the user explicitly defined for a particular provider (agentOptions, resources)
|
|
10
|
+
*/
|
|
11
|
+
export declare const getProviderContextFromGlobalContextForResourceClass: <AO extends DeclastructProviderAgentOptions>({ resourceClassName }: {
|
|
12
|
+
resourceClassName: string;
|
|
13
|
+
}, context: DeclastructContext) => DeclastructProviderContext<AO>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProviderContextFromGlobalContextForResourceClass = void 0;
|
|
4
|
+
const error_fns_1 = require("@ehmpathy/error-fns");
|
|
5
|
+
/**
|
|
6
|
+
* defines the provider specific context for resources of a specific class, from the full context
|
|
7
|
+
*
|
|
8
|
+
* relevance
|
|
9
|
+
* - we dont share the full declastruct context to providers, due to security, becuase credentials are defined in the full context
|
|
10
|
+
* - instead, we only share the the data the user explicitly defined for a particular provider (agentOptions, resources)
|
|
11
|
+
*/
|
|
12
|
+
const getProviderContextFromGlobalContextForResourceClass = ({ resourceClassName }, context) => {
|
|
13
|
+
// lookup the provider for this resource
|
|
14
|
+
const provider = context.providers.find((thisProvider) => resourceClassName in thisProvider.interfaces);
|
|
15
|
+
if (!provider)
|
|
16
|
+
throw new error_fns_1.UnexpectedCodePathError('could not find provider for resource', {
|
|
17
|
+
resourceClassName,
|
|
18
|
+
});
|
|
19
|
+
// find all of the resources managed by this provider
|
|
20
|
+
const resources = context.resources.filter((resource) => resource.constructor.name in provider.interfaces);
|
|
21
|
+
// return the context
|
|
22
|
+
return {
|
|
23
|
+
provider: provider,
|
|
24
|
+
resources,
|
|
25
|
+
log: context.log,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.getProviderContextFromGlobalContextForResourceClass = getProviderContextFromGlobalContextForResourceClass;
|
|
29
|
+
//# sourceMappingURL=getProviderContextFromGlobalContextForResourceClass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getProviderContextFromGlobalContextForResourceClass.js","sourceRoot":"","sources":["../../../../src/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAU9D;;;;;;GAMG;AACI,MAAM,mDAAmD,GAAG,CAGjE,EAAE,iBAAiB,EAAiC,EACpD,OAA2B,EACK,EAAE;IAClC,wCAAwC;IACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CACrC,CAAC,YAAY,EAAE,EAAE,CAAC,iBAAiB,IAAI,YAAY,CAAC,UAAU,CAC/D,CAAC;IACF,IAAI,CAAC,QAAQ;QACX,MAAM,IAAI,mCAAuB,CAAC,sCAAsC,EAAE;YACxE,iBAAiB;SAClB,CAAC,CAAC;IAEL,qDAAqD;IACrD,MAAM,SAAS,GAAuB,OAAO,CAAC,SAAS,CAAC,MAAM,CAC5D,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,QAAQ,CAAC,UAAU,CAC/D,CAAC;IAEF,qBAAqB;IACrB,OAAO;QACL,QAAQ,EAAE,QAAmC;QAC7C,SAAS;QACT,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAAC;AACJ,CAAC,CAAC;AA1BW,QAAA,mDAAmD,uDA0B9D"}
|