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,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeclastructChangeProposal = exports.DeclastructChangeProposalAction = void 0;
|
|
4
|
+
const domain_objects_1 = require("domain-objects");
|
|
5
|
+
/**
|
|
6
|
+
* an action that can be proposed
|
|
7
|
+
*/
|
|
8
|
+
var DeclastructChangeProposalAction;
|
|
9
|
+
(function (DeclastructChangeProposalAction) {
|
|
10
|
+
/**
|
|
11
|
+
* do nothing, the resource is already in the desired state
|
|
12
|
+
*/
|
|
13
|
+
DeclastructChangeProposalAction["DO_NOTHING"] = "DO_NOTHING";
|
|
14
|
+
/**
|
|
15
|
+
* create a new resource
|
|
16
|
+
*/
|
|
17
|
+
DeclastructChangeProposalAction["CREATE"] = "CREATE";
|
|
18
|
+
/**
|
|
19
|
+
* update an existing resource
|
|
20
|
+
*/
|
|
21
|
+
DeclastructChangeProposalAction["UPDATE"] = "UPDATE";
|
|
22
|
+
/**
|
|
23
|
+
* destroy an existing resource
|
|
24
|
+
*/
|
|
25
|
+
DeclastructChangeProposalAction["DESTROY"] = "DESTROY";
|
|
26
|
+
/**
|
|
27
|
+
* replace an existing resource
|
|
28
|
+
*
|
|
29
|
+
* note
|
|
30
|
+
* - this is a `delete` followed by a `create`
|
|
31
|
+
*/
|
|
32
|
+
DeclastructChangeProposalAction["REPLACE"] = "REPLACE";
|
|
33
|
+
})(DeclastructChangeProposalAction || (exports.DeclastructChangeProposalAction = DeclastructChangeProposalAction = {}));
|
|
34
|
+
class DeclastructChangeProposal extends domain_objects_1.DomainObject {
|
|
35
|
+
}
|
|
36
|
+
exports.DeclastructChangeProposal = DeclastructChangeProposal;
|
|
37
|
+
//# sourceMappingURL=DeclastructChangeProposal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeclastructChangeProposal.js","sourceRoot":"","sources":["../../src/domain/DeclastructChangeProposal.ts"],"names":[],"mappings":";;;AAAA,mDAA8C;AAI9C;;GAEG;AACH,IAAY,+BA4BX;AA5BD,WAAY,+BAA+B;IACzC;;OAEG;IACH,4DAAyB,CAAA;IAEzB;;OAEG;IACH,oDAAiB,CAAA;IAEjB;;OAEG;IACH,oDAAiB,CAAA;IAEjB;;OAEG;IACH,sDAAmB,CAAA;IAEnB;;;;;OAKG;IACH,sDAAmB,CAAA;AACrB,CAAC,EA5BW,+BAA+B,+CAA/B,+BAA+B,QA4B1C;AAqCD,MAAa,yBACX,SAAQ,6BAA0C;CACR;AAF5C,8DAE4C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LogMethods } from 'simple-leveled-log-methods';
|
|
2
|
+
import { DeclaredResource } from './DeclaredResource';
|
|
3
|
+
import { DeclastructProvider } from './DeclastructProvider';
|
|
4
|
+
/**
|
|
5
|
+
* the declastruct context defines all of the providers and resources declared by the user
|
|
6
|
+
*
|
|
7
|
+
* note:
|
|
8
|
+
* - this is the global context available to declastruct methods
|
|
9
|
+
* - this is _not_ the provider context available to provider methods
|
|
10
|
+
*/
|
|
11
|
+
export interface DeclastructContext {
|
|
12
|
+
/**
|
|
13
|
+
* the providers loaded by the user
|
|
14
|
+
*/
|
|
15
|
+
providers: DeclastructProvider<any>[];
|
|
16
|
+
/**
|
|
17
|
+
* all of the resources declared by the user
|
|
18
|
+
*/
|
|
19
|
+
resources: DeclaredResource[];
|
|
20
|
+
/**
|
|
21
|
+
* the log context to use
|
|
22
|
+
*/
|
|
23
|
+
log: LogMethods;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeclastructContext.js","sourceRoot":"","sources":["../../src/domain/DeclastructContext.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { LogMethods } from 'simple-leveled-log-methods';
|
|
2
|
+
import { DeclaredResource } from './DeclaredResource';
|
|
3
|
+
import { DeclastructProviderContext } from './DeclastructProviderContext';
|
|
4
|
+
import { DeclastructProviderResourceRemoteStateInterface } from './DeclastructProviderResourceRemoteStateInterface';
|
|
5
|
+
/**
|
|
6
|
+
* the class name of a declared resource
|
|
7
|
+
*
|
|
8
|
+
* note
|
|
9
|
+
* - it is just a string, but we distinguish it with its own type for clarity when defining other types
|
|
10
|
+
*/
|
|
11
|
+
export type DeclaredResourceClassName = string;
|
|
12
|
+
/**
|
|
13
|
+
* agent options can take any shape
|
|
14
|
+
*
|
|
15
|
+
* typically, agent options include
|
|
16
|
+
* - credentials
|
|
17
|
+
* - caching mechanisms
|
|
18
|
+
* - request throttling mechanisms
|
|
19
|
+
*/
|
|
20
|
+
export type DeclastructProviderAgentOptions = {
|
|
21
|
+
log: LogMethods;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* a provider exposes the agent, interfaces, and resource definitions required to declaratively manage resources
|
|
25
|
+
*/
|
|
26
|
+
export interface DeclastructProvider<AO extends DeclastructProviderAgentOptions> {
|
|
27
|
+
/**
|
|
28
|
+
* defines the options available to agents of this provider
|
|
29
|
+
*
|
|
30
|
+
* relevance
|
|
31
|
+
* - agents act on the behalf of the user to manage their resources
|
|
32
|
+
* - typically, agent options include
|
|
33
|
+
* - credentials
|
|
34
|
+
* - caching mechanisms
|
|
35
|
+
* - request throttling mechanisms
|
|
36
|
+
*/
|
|
37
|
+
agentOptions: AO;
|
|
38
|
+
/**
|
|
39
|
+
* defines the interfaces exposed by the provider for managing the remote state of resources
|
|
40
|
+
*
|
|
41
|
+
* note
|
|
42
|
+
* - specified as a "name" to "interface" lookup table, for convenient usage
|
|
43
|
+
*/
|
|
44
|
+
interfaces: Record<DeclaredResourceClassName, DeclastructProviderResourceRemoteStateInterface<DeclaredResource, DeclastructProviderContext<AO>, keyof DeclaredResource, keyof DeclaredResource>>;
|
|
45
|
+
/**
|
|
46
|
+
* defines hooks that we should execute in conjunction with managing resources
|
|
47
|
+
*/
|
|
48
|
+
hooks: {
|
|
49
|
+
/**
|
|
50
|
+
* a hook to run before any operations for this provider
|
|
51
|
+
*/
|
|
52
|
+
beforeAll?: () => {};
|
|
53
|
+
/**
|
|
54
|
+
* a hook to run after all operations for this provider
|
|
55
|
+
*/
|
|
56
|
+
afterAll?: () => {};
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeclastructProvider.js","sourceRoot":"","sources":["../../src/domain/DeclastructProvider.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { LogMethods } from 'simple-leveled-log-methods';
|
|
2
|
+
import { DeclaredResource } from './DeclaredResource';
|
|
3
|
+
import { DeclastructProvider, DeclastructProviderAgentOptions } from './DeclastructProvider';
|
|
4
|
+
/**
|
|
5
|
+
* defines the context in which declastruct is being run, accessible a provider
|
|
6
|
+
*
|
|
7
|
+
* specifically
|
|
8
|
+
* - the options that were inititialized for the provider
|
|
9
|
+
* - the resources that were defined for the provider
|
|
10
|
+
*
|
|
11
|
+
* note
|
|
12
|
+
* - we do not expose the full declastruct context to any provider for security
|
|
13
|
+
* - i.e., ProviderA will never be able to see context related to ProviderB
|
|
14
|
+
* - otherwise, MaliciousProvider may be able to access the credentials defined for CriticalProvider, and steal them
|
|
15
|
+
* - therefore, only the information explicitly given by the user to ProviderA is accessible to ProviderA
|
|
16
|
+
*/
|
|
17
|
+
export interface DeclastructProviderContext<AO extends DeclastructProviderAgentOptions> {
|
|
18
|
+
/**
|
|
19
|
+
* the options instantiated for the provider itself
|
|
20
|
+
*/
|
|
21
|
+
provider: DeclastructProvider<AO>;
|
|
22
|
+
/**
|
|
23
|
+
* the resources for this provider that were declared in this invocation
|
|
24
|
+
*/
|
|
25
|
+
resources?: DeclaredResource[];
|
|
26
|
+
/**
|
|
27
|
+
* the log context to use
|
|
28
|
+
*/
|
|
29
|
+
log: LogMethods;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeclastructProviderContext.js","sourceRoot":"","sources":["../../src/domain/DeclastructProviderContext.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { PickOne } from 'type-fns';
|
|
2
|
+
import { DeclaredResource } from './DeclaredResource';
|
|
3
|
+
import { DeclaredResourceClassName, DeclastructProviderAgentOptions } from './DeclastructProvider';
|
|
4
|
+
import { DeclastructProviderContext } from './DeclastructProviderContext';
|
|
5
|
+
/**
|
|
6
|
+
* an interface which enables the management of the remote state of a resource
|
|
7
|
+
* - capable of crud operations on the resource
|
|
8
|
+
* - conforms to a standard shape for interoperability
|
|
9
|
+
*/
|
|
10
|
+
export interface DeclastructProviderResourceRemoteStateInterface<
|
|
11
|
+
/**
|
|
12
|
+
* the class of resource being managed by this dao
|
|
13
|
+
*/
|
|
14
|
+
R extends DeclaredResource,
|
|
15
|
+
/**
|
|
16
|
+
* the shape of options given to the agent of this resource's provider
|
|
17
|
+
*/
|
|
18
|
+
AO extends DeclastructProviderAgentOptions,
|
|
19
|
+
/**
|
|
20
|
+
* the names of the primary key attributes
|
|
21
|
+
*/
|
|
22
|
+
P extends keyof R,
|
|
23
|
+
/**
|
|
24
|
+
* the names of the unique key attributes
|
|
25
|
+
*/
|
|
26
|
+
U extends keyof R,
|
|
27
|
+
/**
|
|
28
|
+
* the shape of the resources search filter options
|
|
29
|
+
*/
|
|
30
|
+
F extends undefined | null | Record<string, any> = undefined,
|
|
31
|
+
/**
|
|
32
|
+
* the shape of the resources search sort options
|
|
33
|
+
*/
|
|
34
|
+
S extends undefined | Record<string, any | null> = undefined> {
|
|
35
|
+
/**
|
|
36
|
+
* the name of the resource this interface manages
|
|
37
|
+
*/
|
|
38
|
+
for: DeclaredResourceClassName;
|
|
39
|
+
/**
|
|
40
|
+
* a method capable of finding the state of a resource of this class, by primary-key
|
|
41
|
+
*/
|
|
42
|
+
findByPrimary: (
|
|
43
|
+
/**
|
|
44
|
+
* the primary key to lookup the resource by
|
|
45
|
+
*/
|
|
46
|
+
primary: Required<Pick<R, P>>,
|
|
47
|
+
/**
|
|
48
|
+
* the declastruct context available to interfaces of this provider
|
|
49
|
+
*/
|
|
50
|
+
context: DeclastructProviderContext<AO>) => Promise<Required<R> | null>;
|
|
51
|
+
/**
|
|
52
|
+
* a method capable of finding the state of a resource of this class, by unique-key
|
|
53
|
+
*/
|
|
54
|
+
findByUnique: (
|
|
55
|
+
/**
|
|
56
|
+
* the unique key to lookup the resource by
|
|
57
|
+
*/
|
|
58
|
+
unique: Required<Pick<R, U>>,
|
|
59
|
+
/**
|
|
60
|
+
* the declastruct context available to interfaces of this provider
|
|
61
|
+
*/
|
|
62
|
+
context: DeclastructProviderContext<AO>) => Promise<Required<R> | null>;
|
|
63
|
+
/**
|
|
64
|
+
* a method capable of finding all instances of a resource of this class, by some filtering criteria
|
|
65
|
+
*
|
|
66
|
+
* note
|
|
67
|
+
* - may not be supported if search is not possible
|
|
68
|
+
*/
|
|
69
|
+
findAll?: (
|
|
70
|
+
/**
|
|
71
|
+
* the criteria to search with
|
|
72
|
+
*/
|
|
73
|
+
criteria: {
|
|
74
|
+
/**
|
|
75
|
+
* what to filter the results to list by
|
|
76
|
+
*
|
|
77
|
+
* note
|
|
78
|
+
* - if null is supported and specified, no filter will be applied
|
|
79
|
+
*/
|
|
80
|
+
filter: F;
|
|
81
|
+
/**
|
|
82
|
+
* what to sort the results by
|
|
83
|
+
*
|
|
84
|
+
* note
|
|
85
|
+
* - this dictates the order of results
|
|
86
|
+
* - this dictates the offset key for pagination
|
|
87
|
+
*
|
|
88
|
+
* tip
|
|
89
|
+
* - if you're seeing "never" when trying to use this, please make sure you're using the instantiated type of the resource, not the generic type
|
|
90
|
+
*/
|
|
91
|
+
sort: PickOne<{
|
|
92
|
+
/**
|
|
93
|
+
* descending sort
|
|
94
|
+
*/
|
|
95
|
+
until: S;
|
|
96
|
+
/**
|
|
97
|
+
* ascending sort
|
|
98
|
+
*/
|
|
99
|
+
since: S;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* how many results to return
|
|
103
|
+
*
|
|
104
|
+
* note
|
|
105
|
+
* - combine this with the sort option to paginate results
|
|
106
|
+
*/
|
|
107
|
+
limit: number;
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* the declastruct context available to interfaces of this provider
|
|
111
|
+
*/
|
|
112
|
+
context: DeclastructProviderContext<AO>) => Promise<Required<R>[]>;
|
|
113
|
+
/**
|
|
114
|
+
* a method capable of creating a resource of this class
|
|
115
|
+
*/
|
|
116
|
+
create: (
|
|
117
|
+
/**
|
|
118
|
+
* the state we want to create the resource with
|
|
119
|
+
*/
|
|
120
|
+
resource: R,
|
|
121
|
+
/**
|
|
122
|
+
* the declastruct context available to interfaces of this provider
|
|
123
|
+
*/
|
|
124
|
+
context: DeclastructProviderContext<AO>) => Promise<Required<R>>;
|
|
125
|
+
/**
|
|
126
|
+
* a method capable of destroying a resource of this class
|
|
127
|
+
*/
|
|
128
|
+
destroy: (
|
|
129
|
+
/**
|
|
130
|
+
* the primary key of the resource we want to destroy
|
|
131
|
+
*/
|
|
132
|
+
primary: Required<Pick<R, P>>,
|
|
133
|
+
/**
|
|
134
|
+
* the declastruct context available to interfaces of this provider
|
|
135
|
+
*/
|
|
136
|
+
context: DeclastructProviderContext<AO>) => Promise<Required<R>>;
|
|
137
|
+
/**
|
|
138
|
+
* a method capable of creating a resource of this class
|
|
139
|
+
*
|
|
140
|
+
* note
|
|
141
|
+
* - may not be supported if resource is immutable
|
|
142
|
+
*/
|
|
143
|
+
update?: (
|
|
144
|
+
/**
|
|
145
|
+
* the state we want to update the resource to
|
|
146
|
+
*
|
|
147
|
+
* note
|
|
148
|
+
* - either primary or unique key must be defined
|
|
149
|
+
* - any updatable keys defined will be persisted
|
|
150
|
+
*/
|
|
151
|
+
resource: R,
|
|
152
|
+
/**
|
|
153
|
+
* the declastruct context available to interfaces of this provider
|
|
154
|
+
*/
|
|
155
|
+
context: DeclastructProviderContext<AO>) => Promise<Required<R>>;
|
|
156
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeclastructProviderResourceRemoteStateInterface.js","sourceRoot":"","sources":["../../src/domain/DeclastructProviderResourceRemoteStateInterface.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './contract/sdk';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./contract/sdk"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canUpdateResource = void 0;
|
|
4
|
+
const getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource_1 = require("../../tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource");
|
|
5
|
+
const canUpdateResource = ({ resource }, context) => {
|
|
6
|
+
// grab the interface for the resource
|
|
7
|
+
const { remoteStateInterface } = (0, getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource_1.getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource)({ resource }, context);
|
|
8
|
+
// check if it has defined the update method
|
|
9
|
+
return !!remoteStateInterface.update;
|
|
10
|
+
};
|
|
11
|
+
exports.canUpdateResource = canUpdateResource;
|
|
12
|
+
//# sourceMappingURL=canUpdateResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canUpdateResource.js","sourceRoot":"","sources":["../../../../src/logic/actions/execute/canUpdateResource.ts"],"names":[],"mappings":";;;AAGA,0LAAuL;AAEhL,MAAM,iBAAiB,GAAG,CAC/B,EAAE,QAAQ,EAAmB,EAC7B,OAA2B,EAClB,EAAE;IACX,sCAAsC;IACtC,MAAM,EAAE,oBAAoB,EAAE,GAC5B,IAAA,iJAAuE,EACrE,EAAE,QAAQ,EAAE,EACZ,OAAO,CACR,CAAC;IAEJ,4CAA4C;IAC5C,OAAO,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC;AACvC,CAAC,CAAC;AAbW,QAAA,iBAAiB,qBAa5B"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DeclastructChangeProposal } from '../../../domain/DeclastructChangeProposal';
|
|
2
|
+
import { DeclastructContext } from '../../../domain/DeclastructContext';
|
|
3
|
+
export declare const executeProposal: ({ proposal }: {
|
|
4
|
+
proposal: DeclastructChangeProposal<any>;
|
|
5
|
+
}, context: DeclastructContext) => Promise<Required<any>>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeProposal = void 0;
|
|
4
|
+
const error_fns_1 = require("@ehmpathy/error-fns");
|
|
5
|
+
const DeclastructChangeProposal_1 = require("../../../domain/DeclastructChangeProposal");
|
|
6
|
+
const getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource_1 = require("../../tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource");
|
|
7
|
+
const executeProposal = async ({ proposal }, context) => {
|
|
8
|
+
// grab the interface and context for the resource
|
|
9
|
+
const { remoteStateInterface, providerContext } = (0, getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource_1.getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource)({ resource: proposal.toDesiredState ?? proposal.fromRemoteState }, context);
|
|
10
|
+
// if the proposed action was to do nothing, just return its current state
|
|
11
|
+
if (proposal.action === DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING) {
|
|
12
|
+
// look up the resource
|
|
13
|
+
const found = await remoteStateInterface.findByUnique(proposal.toDesiredState, providerContext);
|
|
14
|
+
// sanity check that the resource does really exist
|
|
15
|
+
if (!found)
|
|
16
|
+
throw new error_fns_1.UnexpectedCodePathError('proposal was to do nothing but resource does not exist. how is that possible?', { proposal, found });
|
|
17
|
+
// return the state of the resource
|
|
18
|
+
return found;
|
|
19
|
+
}
|
|
20
|
+
// if the proposed action was to create it, create it
|
|
21
|
+
if (proposal.action === DeclastructChangeProposal_1.DeclastructChangeProposalAction.CREATE) {
|
|
22
|
+
// sanity check that the entity does not already exist
|
|
23
|
+
const found = await remoteStateInterface.findByUnique(proposal.toDesiredState, providerContext);
|
|
24
|
+
if (found) {
|
|
25
|
+
// done if already found it, we must have created it as part of another operation (or the plan was wrong)
|
|
26
|
+
// console.log(' * found this resource by unique instead of creating it');
|
|
27
|
+
return found;
|
|
28
|
+
}
|
|
29
|
+
// create it
|
|
30
|
+
await remoteStateInterface.create(proposal.toDesiredState, providerContext);
|
|
31
|
+
// prove we can find it now
|
|
32
|
+
const foundNow = await remoteStateInterface.findByUnique(proposal.toDesiredState, providerContext);
|
|
33
|
+
if (!foundNow)
|
|
34
|
+
throw new error_fns_1.UnexpectedCodePathError('could not find resource after creating it', {
|
|
35
|
+
forClassName: proposal.forResourceClassName,
|
|
36
|
+
forGrokableIdentifier: proposal.forGrokableIdentifier,
|
|
37
|
+
});
|
|
38
|
+
return foundNow;
|
|
39
|
+
}
|
|
40
|
+
// if the proposed action was to update it, update it
|
|
41
|
+
if (proposal.action === DeclastructChangeProposal_1.DeclastructChangeProposalAction.UPDATE) {
|
|
42
|
+
if (!remoteStateInterface.update)
|
|
43
|
+
throw new error_fns_1.UnexpectedCodePathError(`should not have attempted to update a resource who's remote state interface does not support updates`, { resourceClassName: proposal.forResourceClassName });
|
|
44
|
+
return await remoteStateInterface.update(proposal.toDesiredState, providerContext);
|
|
45
|
+
}
|
|
46
|
+
// otherwise, throw an error, since we couldn't handle it
|
|
47
|
+
throw new error_fns_1.UnexpectedCodePathError('unsupported proposal action', {
|
|
48
|
+
proposal,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
exports.executeProposal = executeProposal;
|
|
52
|
+
//# sourceMappingURL=executeProposal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executeProposal.js","sourceRoot":"","sources":["../../../../src/logic/actions/execute/executeProposal.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAE9D,yFAGmD;AAEnD,0LAAuL;AAEhL,MAAM,eAAe,GAAG,KAAK,EAClC,EAAE,QAAQ,EAAgD,EAC1D,OAA2B,EAC3B,EAAE;IACF,kDAAkD;IAClD,MAAM,EAAE,oBAAoB,EAAE,eAAe,EAAE,GAC7C,IAAA,iJAAuE,EACrE,EAAE,QAAQ,EAAE,QAAQ,CAAC,cAAc,IAAI,QAAQ,CAAC,eAAe,EAAE,EACjE,OAAO,CACR,CAAC;IAEJ,0EAA0E;IAC1E,IAAI,QAAQ,CAAC,MAAM,KAAK,2DAA+B,CAAC,UAAU,EAAE,CAAC;QACnE,uBAAuB;QACvB,MAAM,KAAK,GAAG,MAAM,oBAAoB,CAAC,YAAY,CACnD,QAAQ,CAAC,cAAc,EACvB,eAAe,CAChB,CAAC;QAEF,mDAAmD;QACnD,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,mCAAuB,CAC/B,+EAA+E,EAC/E,EAAE,QAAQ,EAAE,KAAK,EAAE,CACpB,CAAC;QAEJ,mCAAmC;QACnC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,qDAAqD;IACrD,IAAI,QAAQ,CAAC,MAAM,KAAK,2DAA+B,CAAC,MAAM,EAAE,CAAC;QAC/D,sDAAsD;QACtD,MAAM,KAAK,GAAG,MAAM,oBAAoB,CAAC,YAAY,CACnD,QAAQ,CAAC,cAAc,EACvB,eAAe,CAChB,CAAC;QACF,IAAI,KAAK,EAAE,CAAC;YACV,yGAAyG;YACzG,6EAA6E;YAC7E,OAAO,KAAK,CAAC;QACf,CAAC;QAED,YAAY;QACZ,MAAM,oBAAoB,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;QAE5E,2BAA2B;QAC3B,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,YAAY,CACtD,QAAQ,CAAC,cAAc,EACvB,eAAe,CAChB,CAAC;QACF,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,mCAAuB,CAC/B,2CAA2C,EAC3C;gBACE,YAAY,EAAE,QAAQ,CAAC,oBAAoB;gBAC3C,qBAAqB,EAAE,QAAQ,CAAC,qBAAqB;aACtD,CACF,CAAC;QACJ,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,qDAAqD;IACrD,IAAI,QAAQ,CAAC,MAAM,KAAK,2DAA+B,CAAC,MAAM,EAAE,CAAC;QAC/D,IAAI,CAAC,oBAAoB,CAAC,MAAM;YAC9B,MAAM,IAAI,mCAAuB,CAC/B,sGAAsG,EACtG,EAAE,iBAAiB,EAAE,QAAQ,CAAC,oBAAoB,EAAE,CACrD,CAAC;QACJ,OAAO,MAAM,oBAAoB,CAAC,MAAM,CACtC,QAAQ,CAAC,cAAc,EACvB,eAAe,CAChB,CAAC;IACJ,CAAC;IAED,yDAAyD;IACzD,MAAM,IAAI,mCAAuB,CAAC,6BAA6B,EAAE;QAC/D,QAAQ;KACT,CAAC,CAAC;AACL,CAAC,CAAC;AA/EW,QAAA,eAAe,mBA+E1B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
exports.getColoredActionToken = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const DeclastructChangeProposal_1 = require("../../../domain/DeclastructChangeProposal");
|
|
9
|
+
const getColoredActionToken = ({ action, }) => {
|
|
10
|
+
// define action color
|
|
11
|
+
const actionChalk = {
|
|
12
|
+
[DeclastructChangeProposal_1.DeclastructChangeProposalAction.CREATE]: chalk_1.default.green,
|
|
13
|
+
[DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING]: chalk_1.default.gray,
|
|
14
|
+
[DeclastructChangeProposal_1.DeclastructChangeProposalAction.UPDATE]: chalk_1.default.yellow,
|
|
15
|
+
[DeclastructChangeProposal_1.DeclastructChangeProposalAction.REPLACE]: chalk_1.default.red,
|
|
16
|
+
[DeclastructChangeProposal_1.DeclastructChangeProposalAction.DESTROY]: chalk_1.default.red,
|
|
17
|
+
}[action];
|
|
18
|
+
// return the token
|
|
19
|
+
return chalk_1.default.bold(actionChalk(`[${action}]`));
|
|
20
|
+
};
|
|
21
|
+
exports.getColoredActionToken = getColoredActionToken;
|
|
22
|
+
//# sourceMappingURL=getColoredActionToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getColoredActionToken.js","sourceRoot":"","sources":["../../../../src/logic/actions/propose/getColoredActionToken.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,yFAA4F;AAErF,MAAM,qBAAqB,GAAG,CAAC,EACpC,MAAM,GAGP,EAAE,EAAE;IACH,sBAAsB;IACtB,MAAM,WAAW,GAAG;QAClB,CAAC,2DAA+B,CAAC,MAAM,CAAC,EAAE,eAAK,CAAC,KAAK;QACrD,CAAC,2DAA+B,CAAC,UAAU,CAAC,EAAE,eAAK,CAAC,IAAI;QACxD,CAAC,2DAA+B,CAAC,MAAM,CAAC,EAAE,eAAK,CAAC,MAAM;QACtD,CAAC,2DAA+B,CAAC,OAAO,CAAC,EAAE,eAAK,CAAC,GAAG;QACpD,CAAC,2DAA+B,CAAC,OAAO,CAAC,EAAE,eAAK,CAAC,GAAG;KACrD,CAAC,MAAM,CAAC,CAAC;IAEV,mBAAmB;IACnB,OAAO,eAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC;AAChD,CAAC,CAAC;AAhBW,QAAA,qBAAqB,yBAgBhC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
exports.getColoredProposalTitle = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const domain_objects_1 = require("domain-objects");
|
|
9
|
+
const type_fns_1 = require("type-fns");
|
|
10
|
+
const getColoredActionToken_1 = require("./getColoredActionToken");
|
|
11
|
+
const getColoredProposalTitle = ({ proposal, }) => {
|
|
12
|
+
// get the action token
|
|
13
|
+
const actionToken = (0, getColoredActionToken_1.getColoredActionToken)({ action: proposal.action });
|
|
14
|
+
// define the metadata string
|
|
15
|
+
const metadata = proposal.fromRemoteState
|
|
16
|
+
? (0, domain_objects_1.getMetadataKeys)(proposal.fromRemoteState).reduce((summary, thisMetadataKey) => ({
|
|
17
|
+
...summary,
|
|
18
|
+
[thisMetadataKey]: proposal.toDesiredState[thisMetadataKey],
|
|
19
|
+
}), {})
|
|
20
|
+
: {};
|
|
21
|
+
const identifierAvailableWidth = 151 - 5 - actionToken.length - proposal.forResourceClassName.length - 15;
|
|
22
|
+
const identifierString = Object.values(metadata).filter(type_fns_1.isPresent).length
|
|
23
|
+
? JSON.stringify(metadata)
|
|
24
|
+
: proposal.forGrokableIdentifier.replace(proposal.forResourceClassName, ''); // remove the classname from the identifier because its redundant, the class name is already in the title
|
|
25
|
+
const displayableIdentifierString = chalk_1.default.grey(`(${identifierString.length > identifierAvailableWidth
|
|
26
|
+
? identifierString.slice(0, identifierAvailableWidth - 3) + '...'
|
|
27
|
+
: identifierString})`);
|
|
28
|
+
// define the header
|
|
29
|
+
const title = chalk_1.default.bold(`${actionToken} ${proposal.forResourceClassName} ${displayableIdentifierString}`);
|
|
30
|
+
// return header
|
|
31
|
+
return title;
|
|
32
|
+
};
|
|
33
|
+
exports.getColoredProposalTitle = getColoredProposalTitle;
|
|
34
|
+
//# sourceMappingURL=getColoredProposalTitle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getColoredProposalTitle.js","sourceRoot":"","sources":["../../../../src/logic/actions/propose/getColoredProposalTitle.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mDAAiD;AACjD,uCAAqC;AAGrC,mEAAgE;AAEzD,MAAM,uBAAuB,GAAG,CAAC,EACtC,QAAQ,GAGT,EAAE,EAAE;IACH,uBAAuB;IACvB,MAAM,WAAW,GAAG,IAAA,6CAAqB,EAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAEvE,6BAA6B;IAC7B,MAAM,QAAQ,GAAG,QAAQ,CAAC,eAAe;QACvC,CAAC,CAAC,IAAA,gCAAe,EAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,MAAM,CAC9C,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,CAAC,CAAC;YAC7B,GAAG,OAAO;YACV,CAAC,eAAe,CAAC,EAAE,QAAQ,CAAC,cAAc,CAAC,eAAe,CAAC;SAC5D,CAAC,EACF,EAA6C,CAC9C;QACH,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,wBAAwB,GAC5B,GAAG,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,GAAG,QAAQ,CAAC,oBAAoB,CAAC,MAAM,GAAG,EAAE,CAAC;IAC3E,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,oBAAS,CAAC,CAAC,MAAM;QACvE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;QAC1B,CAAC,CAAC,QAAQ,CAAC,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC,CAAC,yGAAyG;IACxL,MAAM,2BAA2B,GAAG,eAAK,CAAC,IAAI,CAC5C,IACE,gBAAgB,CAAC,MAAM,GAAG,wBAAwB;QAChD,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,wBAAwB,GAAG,CAAC,CAAC,GAAG,KAAK;QACjE,CAAC,CAAC,gBACN,GAAG,CACJ,CAAC;IAEF,oBAAoB;IACpB,MAAM,KAAK,GAAG,eAAK,CAAC,IAAI,CACtB,GAAG,WAAW,IAAI,QAAQ,CAAC,oBAAoB,IAAI,2BAA2B,EAAE,CACjF,CAAC;IAEF,gBAAgB;IAChB,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAtCW,QAAA,uBAAuB,2BAsClC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { VisualogicContext } from 'visualogic';
|
|
2
|
+
import { DeclaredResource } from '../../../domain/DeclaredResource';
|
|
3
|
+
import { DeclastructChangeProposal } from '../../../domain/DeclastructChangeProposal';
|
|
4
|
+
import { DeclastructContext } from '../../../domain/DeclastructContext';
|
|
5
|
+
export declare const proposeChangeForResource: <R extends DeclaredResource>({ resource: desiredState, }: {
|
|
6
|
+
resource: R;
|
|
7
|
+
}, context: DeclastructContext & VisualogicContext) => Promise<DeclastructChangeProposal<R>>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proposeChangeForResource = void 0;
|
|
4
|
+
const DeclastructChangeProposal_1 = require("../../../domain/DeclastructChangeProposal");
|
|
5
|
+
const castReferenceToGrokableString_1 = require("../../tools/compare/castReferenceToGrokableString");
|
|
6
|
+
const detectDifferenceBetweenDesiredAndRemoteStateOfResource_1 = require("../../tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource");
|
|
7
|
+
const getByReference_1 = require("../../tools/reference/getByReference");
|
|
8
|
+
const getReferenceTo_1 = require("../../tools/reference/getReferenceTo");
|
|
9
|
+
const canUpdateResource_1 = require("../execute/canUpdateResource");
|
|
10
|
+
const proposeChangeForResource = async ({ resource: desiredState, // TODO: support deleting remote state resources, based on remoteState resource as input (i.e., specify which type the resource declaration represents, right now always desiredState)
|
|
11
|
+
}, context) => {
|
|
12
|
+
// get its current remote state
|
|
13
|
+
// const stopwatchOne = startDurationStopwatch(
|
|
14
|
+
// {
|
|
15
|
+
// for: `proposeChangeForResource.getByReference.ofClass::${desiredState.constructor.name}`,
|
|
16
|
+
// log: { level: LogLevel.INFO, threshold: { milliseconds: 1 } },
|
|
17
|
+
// },
|
|
18
|
+
// context,
|
|
19
|
+
// );
|
|
20
|
+
const remoteState = await (0, getByReference_1.getByReference)({ reference: (0, getReferenceTo_1.getRef)(desiredState) }, context);
|
|
21
|
+
// stopwatchOne.stop();
|
|
22
|
+
// detect the difference
|
|
23
|
+
const diff = await (0, detectDifferenceBetweenDesiredAndRemoteStateOfResource_1.detectDifferenceBetweenDesiredAndRemoteStateOfResource)({
|
|
24
|
+
desiredState,
|
|
25
|
+
remoteState,
|
|
26
|
+
}, context);
|
|
27
|
+
// determine what we should do
|
|
28
|
+
const action = await (async () => {
|
|
29
|
+
// if remote and desired state are already the same, do nothing
|
|
30
|
+
if (desiredState === remoteState)
|
|
31
|
+
return DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING;
|
|
32
|
+
// if remote state is null, create it
|
|
33
|
+
if (remoteState === null)
|
|
34
|
+
return DeclastructChangeProposal_1.DeclastructChangeProposalAction.CREATE;
|
|
35
|
+
// if desired state is null, destroy it
|
|
36
|
+
if (desiredState === null)
|
|
37
|
+
return DeclastructChangeProposal_1.DeclastructChangeProposalAction.DESTROY;
|
|
38
|
+
// if there are no changes detected, do nothing
|
|
39
|
+
if (Object.values(diff.usable)
|
|
40
|
+
.map((changeType) => Object.values(changeType).length) // TODO: make the "usable" diff more usable, this is pretty ugly and convoluted
|
|
41
|
+
.every((numberOfChangesForType) => numberOfChangesForType === 0))
|
|
42
|
+
return DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING;
|
|
43
|
+
// if the resource supports update, update it
|
|
44
|
+
if (await (0, canUpdateResource_1.canUpdateResource)({ resource: desiredState }, context))
|
|
45
|
+
return DeclastructChangeProposal_1.DeclastructChangeProposalAction.UPDATE;
|
|
46
|
+
// otherwise, replace it
|
|
47
|
+
return DeclastructChangeProposal_1.DeclastructChangeProposalAction.REPLACE;
|
|
48
|
+
})();
|
|
49
|
+
// get the grokable identifier
|
|
50
|
+
const grokableIdentifier = await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference: (0, getReferenceTo_1.getRef)(desiredState) }, // TODO: support desiredState = null, remote state != null
|
|
51
|
+
context);
|
|
52
|
+
// return the proposed change
|
|
53
|
+
return new DeclastructChangeProposal_1.DeclastructChangeProposal({
|
|
54
|
+
forResourceClassName: desiredState.constructor.name,
|
|
55
|
+
forGrokableIdentifier: grokableIdentifier,
|
|
56
|
+
fromRemoteState: remoteState,
|
|
57
|
+
toDesiredState: desiredState,
|
|
58
|
+
difference: action === DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING
|
|
59
|
+
? null
|
|
60
|
+
: diff.displayable,
|
|
61
|
+
action,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
exports.proposeChangeForResource = proposeChangeForResource;
|
|
65
|
+
//# sourceMappingURL=proposeChangeForResource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proposeChangeForResource.js","sourceRoot":"","sources":["../../../../src/logic/actions/propose/proposeChangeForResource.ts"],"names":[],"mappings":";;;AAGA,yFAGmD;AAEnD,qGAAkG;AAClG,uJAAoJ;AACpJ,yEAAsE;AACtE,yEAA8D;AAC9D,oEAAiE;AAE1D,MAAM,wBAAwB,GAAG,KAAK,EAC3C,EACE,QAAQ,EAAE,YAAY,EAAE,sLAAsL;EAC9L,EAClB,OAA+C,EAC/C,EAAE;IACF,+BAA+B;IAC/B,+CAA+C;IAC/C,MAAM;IACN,gGAAgG;IAChG,qEAAqE;IACrE,OAAO;IACP,aAAa;IACb,KAAK;IACL,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAc,EACtC,EAAE,SAAS,EAAE,IAAA,uBAAM,EAAC,YAAY,CAAC,EAAE,EACnC,OAAO,CACR,CAAC;IACF,uBAAuB;IAEvB,wBAAwB;IACxB,MAAM,IAAI,GAAG,MAAM,IAAA,+GAAsD,EACvE;QACE,YAAY;QACZ,WAAW;KACZ,EACD,OAAO,CACR,CAAC;IAEF,8BAA8B;IAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE;QAC/B,+DAA+D;QAC/D,IAAI,YAAY,KAAK,WAAW;YAC9B,OAAO,2DAA+B,CAAC,UAAU,CAAC;QAEpD,qCAAqC;QACrC,IAAI,WAAW,KAAK,IAAI;YAAE,OAAO,2DAA+B,CAAC,MAAM,CAAC;QAExE,uCAAuC;QACvC,IAAI,YAAY,KAAK,IAAI;YAAE,OAAO,2DAA+B,CAAC,OAAO,CAAC;QAE1E,+CAA+C;QAC/C,IACE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;aACvB,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,+EAA+E;aACrI,KAAK,CAAC,CAAC,sBAAsB,EAAE,EAAE,CAAC,sBAAsB,KAAK,CAAC,CAAC;YAElE,OAAO,2DAA+B,CAAC,UAAU,CAAC;QAEpD,6CAA6C;QAC7C,IAAI,MAAM,IAAA,qCAAiB,EAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC;YAC9D,OAAO,2DAA+B,CAAC,MAAM,CAAC;QAEhD,wBAAwB;QACxB,OAAO,2DAA+B,CAAC,OAAO,CAAC;IACjD,CAAC,CAAC,EAAE,CAAC;IAEL,8BAA8B;IAC9B,MAAM,kBAAkB,GAAG,MAAM,IAAA,6DAA6B,EAC5D,EAAE,SAAS,EAAE,IAAA,uBAAM,EAAC,YAAY,CAAC,EAAE,EAAE,2DAA2D;IAChG,OAAO,CACR,CAAC;IAEF,6BAA6B;IAC7B,OAAO,IAAI,qDAAyB,CAAI;QACtC,oBAAoB,EAAE,YAAY,CAAC,WAAW,CAAC,IAAI;QACnD,qBAAqB,EAAE,kBAAkB;QACzC,eAAe,EAAE,WAAW;QAC5B,cAAc,EAAE,YAAY;QAC5B,UAAU,EACR,MAAM,KAAK,2DAA+B,CAAC,UAAU;YACnD,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,IAAI,CAAC,WAAW;QACtB,MAAM;KACP,CAAC,CAAC;AACL,CAAC,CAAC;AA3EW,QAAA,wBAAwB,4BA2EnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|