declastruct 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/dist/.test/assets/providers/demo.provider.d.ts +32 -0
  2. package/dist/.test/assets/providers/demo.provider.js +101 -0
  3. package/dist/.test/assets/providers/demo.provider.js.map +1 -0
  4. package/dist/contract/cli/apply.d.ts +9 -0
  5. package/dist/contract/cli/apply.integration.test.js +148 -0
  6. package/dist/contract/cli/apply.integration.test.js.map +1 -0
  7. package/dist/contract/cli/apply.js +90 -0
  8. package/dist/contract/cli/apply.js.map +1 -0
  9. package/dist/contract/cli/invoke.d.ts +8 -0
  10. package/dist/contract/cli/invoke.js +58 -0
  11. package/dist/contract/cli/invoke.js.map +1 -0
  12. package/dist/contract/cli/plan.d.ts +10 -0
  13. package/dist/contract/cli/plan.integration.test.js +107 -0
  14. package/dist/contract/cli/plan.integration.test.js.map +1 -0
  15. package/dist/contract/cli/plan.js +94 -0
  16. package/dist/contract/cli/plan.js.map +1 -0
  17. package/dist/contract/sdk/index.d.ts +15 -3
  18. package/dist/contract/sdk/index.js +31 -17
  19. package/dist/contract/sdk/index.js.map +1 -1
  20. package/dist/domain.objects/ContextDeclastruct.d.ts +15 -0
  21. package/dist/{domain/DeclastructContext.js → domain.objects/ContextDeclastruct.js} +1 -1
  22. package/dist/domain.objects/ContextDeclastruct.js.map +1 -0
  23. package/dist/domain.objects/ContextDeclastruct.test.js +41 -0
  24. package/dist/domain.objects/ContextDeclastruct.test.js.map +1 -0
  25. package/dist/domain.objects/DeclastructChange.d.ts +73 -0
  26. package/dist/domain.objects/DeclastructChange.js +35 -0
  27. package/dist/domain.objects/DeclastructChange.js.map +1 -0
  28. package/dist/domain.objects/DeclastructChange.test.js +59 -0
  29. package/dist/domain.objects/DeclastructChange.test.js.map +1 -0
  30. package/dist/domain.objects/DeclastructDao.d.ts +39 -0
  31. package/dist/domain.objects/DeclastructDao.js +8 -0
  32. package/dist/domain.objects/DeclastructDao.js.map +1 -0
  33. package/dist/domain.objects/DeclastructDao.test.js +42 -0
  34. package/dist/domain.objects/DeclastructDao.test.js.map +1 -0
  35. package/dist/domain.objects/DeclastructPlan.d.ts +35 -0
  36. package/dist/domain.objects/DeclastructPlan.js +11 -0
  37. package/dist/domain.objects/DeclastructPlan.js.map +1 -0
  38. package/dist/domain.objects/DeclastructPlan.test.js +31 -0
  39. package/dist/domain.objects/DeclastructPlan.test.js.map +1 -0
  40. package/dist/domain.objects/DeclastructProvider.d.ts +30 -0
  41. package/dist/domain.objects/DeclastructProvider.js +8 -0
  42. package/dist/domain.objects/DeclastructProvider.js.map +1 -0
  43. package/dist/domain.objects/DeclastructProvider.test.js +35 -0
  44. package/dist/domain.objects/DeclastructProvider.test.js.map +1 -0
  45. package/dist/domain.objects/IsoTimestamp.d.ts +6 -0
  46. package/dist/{domain/DeclaredResource.js → domain.objects/IsoTimestamp.js} +1 -1
  47. package/dist/domain.objects/IsoTimestamp.js.map +1 -0
  48. package/dist/domain.objects/IsoTimestamp.test.js +10 -0
  49. package/dist/domain.objects/IsoTimestamp.test.js.map +1 -0
  50. package/dist/domain.operations/apply/applyChange.d.ts +14 -0
  51. package/dist/domain.operations/apply/applyChange.js +64 -0
  52. package/dist/domain.operations/apply/applyChange.js.map +1 -0
  53. package/dist/domain.operations/apply/applyChange.test.d.ts +1 -0
  54. package/dist/domain.operations/apply/applyChange.test.js +247 -0
  55. package/dist/domain.operations/apply/applyChange.test.js.map +1 -0
  56. package/dist/domain.operations/apply/applyChanges.d.ts +18 -0
  57. package/dist/domain.operations/apply/applyChanges.integration.test.d.ts +1 -0
  58. package/dist/domain.operations/apply/applyChanges.integration.test.js +291 -0
  59. package/dist/domain.operations/apply/applyChanges.integration.test.js.map +1 -0
  60. package/dist/domain.operations/apply/applyChanges.js +53 -0
  61. package/dist/domain.operations/apply/applyChanges.js.map +1 -0
  62. package/dist/domain.operations/plan/computeChange.d.ts +11 -0
  63. package/dist/domain.operations/plan/computeChange.js +78 -0
  64. package/dist/domain.operations/plan/computeChange.js.map +1 -0
  65. package/dist/domain.operations/plan/computeChange.test.d.ts +1 -0
  66. package/dist/domain.operations/plan/computeChange.test.js +67 -0
  67. package/dist/domain.operations/plan/computeChange.test.js.map +1 -0
  68. package/dist/domain.operations/plan/extractResourcesFromPlan.d.ts +8 -0
  69. package/dist/domain.operations/plan/extractResourcesFromPlan.js +17 -0
  70. package/dist/domain.operations/plan/extractResourcesFromPlan.js.map +1 -0
  71. package/dist/domain.operations/plan/getDaoByResource.d.ts +12 -0
  72. package/dist/domain.operations/plan/getDaoByResource.js +41 -0
  73. package/dist/domain.operations/plan/getDaoByResource.js.map +1 -0
  74. package/dist/domain.operations/plan/getDaoByResource.test.d.ts +1 -0
  75. package/dist/domain.operations/plan/getDaoByResource.test.js +99 -0
  76. package/dist/domain.operations/plan/getDaoByResource.test.js.map +1 -0
  77. package/dist/domain.operations/plan/hashChanges.d.ts +7 -0
  78. package/dist/domain.operations/plan/hashChanges.js +18 -0
  79. package/dist/domain.operations/plan/hashChanges.js.map +1 -0
  80. package/dist/domain.operations/plan/planChanges.d.ts +15 -0
  81. package/dist/domain.operations/plan/planChanges.integration.test.d.ts +1 -0
  82. package/dist/domain.operations/plan/planChanges.integration.test.js +197 -0
  83. package/dist/domain.operations/plan/planChanges.integration.test.js.map +1 -0
  84. package/dist/domain.operations/plan/planChanges.js +50 -0
  85. package/dist/domain.operations/plan/planChanges.js.map +1 -0
  86. package/dist/domain.operations/plan/validate.d.ts +10 -0
  87. package/dist/domain.operations/plan/validate.js +21 -0
  88. package/dist/domain.operations/plan/validate.js.map +1 -0
  89. package/dist/infra/asIsoTimestamp.d.ts +6 -0
  90. package/dist/infra/asIsoTimestamp.js +12 -0
  91. package/dist/infra/asIsoTimestamp.js.map +1 -0
  92. package/package.json +8 -15
  93. package/readme.md +48 -28
  94. package/dist/__test_assets__/getExampleContext.d.ts +0 -33
  95. package/dist/__test_assets__/getExampleContext.js +0 -87
  96. package/dist/__test_assets__/getExampleContext.js.map +0 -1
  97. package/dist/contract/commands/command.apply.d.ts +0 -6
  98. package/dist/contract/commands/command.apply.js +0 -20
  99. package/dist/contract/commands/command.apply.js.map +0 -1
  100. package/dist/contract/commands/command.plan.d.ts +0 -6
  101. package/dist/contract/commands/command.plan.js +0 -20
  102. package/dist/contract/commands/command.plan.js.map +0 -1
  103. package/dist/contract/commands/utils/resolveCommandInputs.d.ts +0 -17
  104. package/dist/contract/commands/utils/resolveCommandInputs.js +0 -23
  105. package/dist/contract/commands/utils/resolveCommandInputs.js.map +0 -1
  106. package/dist/contract/sdk/refs.d.ts +0 -2
  107. package/dist/contract/sdk/refs.js +0 -19
  108. package/dist/contract/sdk/refs.js.map +0 -1
  109. package/dist/contract/sdk/sync/apply.d.ts +0 -22
  110. package/dist/contract/sdk/sync/apply.js +0 -29
  111. package/dist/contract/sdk/sync/apply.js.map +0 -1
  112. package/dist/contract/sdk/sync/plan.d.ts +0 -22
  113. package/dist/contract/sdk/sync/plan.js +0 -30
  114. package/dist/contract/sdk/sync/plan.js.map +0 -1
  115. package/dist/domain/DeclaredResource.d.ts +0 -2
  116. package/dist/domain/DeclaredResource.js.map +0 -1
  117. package/dist/domain/DeclaredResourceReference.d.ts +0 -66
  118. package/dist/domain/DeclaredResourceReference.js +0 -42
  119. package/dist/domain/DeclaredResourceReference.js.map +0 -1
  120. package/dist/domain/DeclastructChangeProposal.d.ts +0 -61
  121. package/dist/domain/DeclastructChangeProposal.js +0 -37
  122. package/dist/domain/DeclastructChangeProposal.js.map +0 -1
  123. package/dist/domain/DeclastructContext.d.ts +0 -24
  124. package/dist/domain/DeclastructContext.js.map +0 -1
  125. package/dist/domain/DeclastructProvider.d.ts +0 -58
  126. package/dist/domain/DeclastructProvider.js +0 -3
  127. package/dist/domain/DeclastructProvider.js.map +0 -1
  128. package/dist/domain/DeclastructProviderContext.d.ts +0 -30
  129. package/dist/domain/DeclastructProviderContext.js +0 -3
  130. package/dist/domain/DeclastructProviderContext.js.map +0 -1
  131. package/dist/domain/DeclastructProviderResourceRemoteStateInterface.d.ts +0 -156
  132. package/dist/domain/DeclastructProviderResourceRemoteStateInterface.js +0 -3
  133. package/dist/domain/DeclastructProviderResourceRemoteStateInterface.js.map +0 -1
  134. package/dist/index.d.ts +0 -1
  135. package/dist/index.js +0 -18
  136. package/dist/index.js.map +0 -1
  137. package/dist/logic/actions/execute/canUpdateResource.d.ts +0 -5
  138. package/dist/logic/actions/execute/canUpdateResource.js +0 -12
  139. package/dist/logic/actions/execute/canUpdateResource.js.map +0 -1
  140. package/dist/logic/actions/execute/executeProposal.d.ts +0 -5
  141. package/dist/logic/actions/execute/executeProposal.js +0 -52
  142. package/dist/logic/actions/execute/executeProposal.js.map +0 -1
  143. package/dist/logic/actions/propose/getColoredActionToken.d.ts +0 -4
  144. package/dist/logic/actions/propose/getColoredActionToken.js +0 -22
  145. package/dist/logic/actions/propose/getColoredActionToken.js.map +0 -1
  146. package/dist/logic/actions/propose/getColoredProposalTitle.d.ts +0 -4
  147. package/dist/logic/actions/propose/getColoredProposalTitle.js +0 -34
  148. package/dist/logic/actions/propose/getColoredProposalTitle.js.map +0 -1
  149. package/dist/logic/actions/propose/proposeChangeForResource.d.ts +0 -7
  150. package/dist/logic/actions/propose/proposeChangeForResource.js +0 -65
  151. package/dist/logic/actions/propose/proposeChangeForResource.js.map +0 -1
  152. package/dist/logic/actions/propose/proposeChangeForResource.test.js +0 -48
  153. package/dist/logic/actions/propose/proposeChangeForResource.test.js.map +0 -1
  154. package/dist/logic/commands/command.apply.d.ts +0 -8
  155. package/dist/logic/commands/command.apply.js +0 -77
  156. package/dist/logic/commands/command.apply.js.map +0 -1
  157. package/dist/logic/commands/command.plan.d.ts +0 -13
  158. package/dist/logic/commands/command.plan.js +0 -155
  159. package/dist/logic/commands/command.plan.js.map +0 -1
  160. package/dist/logic/commands/execute.d.ts +0 -15
  161. package/dist/logic/commands/execute.js +0 -63
  162. package/dist/logic/commands/execute.js.map +0 -1
  163. package/dist/logic/tools/compare/castReferenceToGrokableString.d.ts +0 -16
  164. package/dist/logic/tools/compare/castReferenceToGrokableString.js +0 -66
  165. package/dist/logic/tools/compare/castReferenceToGrokableString.js.map +0 -1
  166. package/dist/logic/tools/compare/castReferenceToGrokableString.test.js +0 -111
  167. package/dist/logic/tools/compare/castReferenceToGrokableString.test.js.map +0 -1
  168. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.d.ts +0 -11
  169. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.js +0 -61
  170. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.js.map +0 -1
  171. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js +0 -31
  172. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js.map +0 -1
  173. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.d.ts +0 -21
  174. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.js +0 -53
  175. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.js.map +0 -1
  176. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.test.js +0 -31
  177. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.test.js.map +0 -1
  178. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.d.ts +0 -10
  179. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.js +0 -41
  180. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.js.map +0 -1
  181. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.test.js +0 -174
  182. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.test.js.map +0 -1
  183. package/dist/logic/tools/context/createDeclastructContext.d.ts +0 -10
  184. package/dist/logic/tools/context/createDeclastructContext.js +0 -12
  185. package/dist/logic/tools/context/createDeclastructContext.js.map +0 -1
  186. package/dist/logic/tools/context/destroyDeclastructContext.d.ts +0 -4
  187. package/dist/logic/tools/context/destroyDeclastructContext.js +0 -10
  188. package/dist/logic/tools/context/destroyDeclastructContext.js.map +0 -1
  189. package/dist/logic/tools/provider/castProviderContextToGlobalContext.d.ts +0 -4
  190. package/dist/logic/tools/provider/castProviderContextToGlobalContext.js +0 -10
  191. package/dist/logic/tools/provider/castProviderContextToGlobalContext.js.map +0 -1
  192. package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.d.ts +0 -13
  193. package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.js +0 -29
  194. package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.js.map +0 -1
  195. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.d.ts +0 -13
  196. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.js +0 -24
  197. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.js.map +0 -1
  198. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.d.ts +0 -10
  199. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.js +0 -21
  200. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.js.map +0 -1
  201. package/dist/logic/tools/reference/buildPrimaryKeyTo.d.ts +0 -5
  202. package/dist/logic/tools/reference/buildPrimaryKeyTo.js +0 -40
  203. package/dist/logic/tools/reference/buildPrimaryKeyTo.js.map +0 -1
  204. package/dist/logic/tools/reference/buildReferenceTo.d.ts +0 -28
  205. package/dist/logic/tools/reference/buildReferenceTo.js +0 -92
  206. package/dist/logic/tools/reference/buildReferenceTo.js.map +0 -1
  207. package/dist/logic/tools/reference/buildReferenceTo.test.js +0 -119
  208. package/dist/logic/tools/reference/buildReferenceTo.test.js.map +0 -1
  209. package/dist/logic/tools/reference/buildUniqueKeyTo.d.ts +0 -5
  210. package/dist/logic/tools/reference/buildUniqueKeyTo.js +0 -40
  211. package/dist/logic/tools/reference/buildUniqueKeyTo.js.map +0 -1
  212. package/dist/logic/tools/reference/defineReferenceClassOf.d.ts +0 -5
  213. package/dist/logic/tools/reference/defineReferenceClassOf.js +0 -25
  214. package/dist/logic/tools/reference/defineReferenceClassOf.js.map +0 -1
  215. package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.d.ts +0 -13
  216. package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.js +0 -36
  217. package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.js.map +0 -1
  218. package/dist/logic/tools/reference/getByReference.d.ts +0 -15
  219. package/dist/logic/tools/reference/getByReference.js +0 -55
  220. package/dist/logic/tools/reference/getByReference.js.map +0 -1
  221. package/dist/logic/tools/reference/getByReference.test.js +0 -92
  222. package/dist/logic/tools/reference/getByReference.test.js.map +0 -1
  223. package/dist/logic/tools/reference/getByReferencedPrimaryKey.d.ts +0 -6
  224. package/dist/logic/tools/reference/getByReferencedPrimaryKey.js +0 -17
  225. package/dist/logic/tools/reference/getByReferencedPrimaryKey.js.map +0 -1
  226. package/dist/logic/tools/reference/getByReferencedUniqueKey.d.ts +0 -7
  227. package/dist/logic/tools/reference/getByReferencedUniqueKey.js +0 -42
  228. package/dist/logic/tools/reference/getByReferencedUniqueKey.js.map +0 -1
  229. package/dist/logic/tools/reference/getPrimaryKeyByReference.d.ts +0 -15
  230. package/dist/logic/tools/reference/getPrimaryKeyByReference.js +0 -36
  231. package/dist/logic/tools/reference/getPrimaryKeyByReference.js.map +0 -1
  232. package/dist/logic/tools/reference/getReferenceTo.d.ts +0 -18
  233. package/dist/logic/tools/reference/getReferenceTo.js +0 -55
  234. package/dist/logic/tools/reference/getReferenceTo.js.map +0 -1
  235. package/dist/logic/tools/reference/getReferenceTo.test.js +0 -95
  236. package/dist/logic/tools/reference/getReferenceTo.test.js.map +0 -1
  237. package/dist/logic/tools/reference/getUniqueKeyByReference.d.ts +0 -15
  238. package/dist/logic/tools/reference/getUniqueKeyByReference.js +0 -36
  239. package/dist/logic/tools/reference/getUniqueKeyByReference.js.map +0 -1
  240. package/dist/logic/tools/reference/isPrimaryKeyReference.d.ts +0 -6
  241. package/dist/logic/tools/reference/isPrimaryKeyReference.js +0 -7
  242. package/dist/logic/tools/reference/isPrimaryKeyReference.js.map +0 -1
  243. package/dist/logic/tools/reference/isUniqueKeyReference.d.ts +0 -6
  244. package/dist/logic/tools/reference/isUniqueKeyReference.js +0 -7
  245. package/dist/logic/tools/reference/isUniqueKeyReference.js.map +0 -1
  246. /package/dist/{logic/actions/propose/proposeChangeForResource.test.d.ts → contract/cli/apply.integration.test.d.ts} +0 -0
  247. /package/dist/{logic/tools/compare/castReferenceToGrokableString.test.d.ts → contract/cli/plan.integration.test.d.ts} +0 -0
  248. /package/dist/{logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.d.ts → domain.objects/ContextDeclastruct.test.d.ts} +0 -0
  249. /package/dist/{logic/tools/compare/resolveReferenceToCommonComparableForm.test.d.ts → domain.objects/DeclastructChange.test.d.ts} +0 -0
  250. /package/dist/{logic/tools/compare/resolveReferencesToCommonComparableForm.test.d.ts → domain.objects/DeclastructDao.test.d.ts} +0 -0
  251. /package/dist/{logic/tools/reference/buildReferenceTo.test.d.ts → domain.objects/DeclastructPlan.test.d.ts} +0 -0
  252. /package/dist/{logic/tools/reference/getByReference.test.d.ts → domain.objects/DeclastructProvider.test.d.ts} +0 -0
  253. /package/dist/{logic/tools/reference/getReferenceTo.test.d.ts → domain.objects/IsoTimestamp.test.d.ts} +0 -0
@@ -1,58 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=DeclastructProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeclastructProvider.js","sourceRoot":"","sources":["../../src/domain/DeclastructProvider.ts"],"names":[],"mappings":""}
@@ -1,30 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=DeclastructProviderContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeclastructProviderContext.js","sourceRoot":"","sources":["../../src/domain/DeclastructProviderContext.ts"],"names":[],"mappings":""}
@@ -1,156 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=DeclastructProviderResourceRemoteStateInterface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeclastructProviderResourceRemoteStateInterface.js","sourceRoot":"","sources":["../../src/domain/DeclastructProviderResourceRemoteStateInterface.ts"],"names":[],"mappings":""}
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './contract/sdk';
package/dist/index.js DELETED
@@ -1,18 +0,0 @@
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
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}
@@ -1,5 +0,0 @@
1
- import { DomainEntity } from 'domain-objects';
2
- import { DeclastructContext } from '../../../domain/DeclastructContext';
3
- export declare const canUpdateResource: <R extends DomainEntity<any>>({ resource }: {
4
- resource: R;
5
- }, context: DeclastructContext) => boolean;
@@ -1,12 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,5 +0,0 @@
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>>;
@@ -1,52 +0,0 @@
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
@@ -1 +0,0 @@
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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AC,CAAC;AA/EW,QAAA,eAAe,mBA+E1B"}
@@ -1,4 +0,0 @@
1
- import { DeclastructChangeProposalAction } from '../../../domain/DeclastructChangeProposal';
2
- export declare const getColoredActionToken: ({ action, }: {
3
- action: DeclastructChangeProposalAction;
4
- }) => string;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- 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
@@ -1 +0,0 @@
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"}
@@ -1,4 +0,0 @@
1
- import { DeclastructChangeProposal } from '../../../domain/DeclastructChangeProposal';
2
- export declare const getColoredProposalTitle: ({ proposal, }: {
3
- proposal: DeclastructChangeProposal<any>;
4
- }) => string;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- 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
@@ -1 +0,0 @@
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"}
@@ -1,7 +0,0 @@
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>>;
@@ -1,65 +0,0 @@
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
@@ -1 +0,0 @@
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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C,CAAC;AACL,CAAC,CAAC;AA3EW,QAAA,wBAAwB,4BA2EnC"}
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const uuid_fns_1 = require("uuid-fns");
4
- const getExampleContext_1 = require("../../../__test_assets__/getExampleContext");
5
- const DeclastructChangeProposal_1 = require("../../../domain/DeclastructChangeProposal");
6
- const proposeChangeForResource_1 = require("./proposeChangeForResource");
7
- const { exampleContext, exampleMachine, CNCMachine, exampleRegistration, CNCMachineRegistration, } = (0, getExampleContext_1.getExampleContext)();
8
- describe('proposeChangeForResource', () => {
9
- it('should be able to propose creating a new resource', async () => {
10
- const proposed = await (0, proposeChangeForResource_1.proposeChangeForResource)({
11
- resource: new CNCMachine({
12
- serialNumber: (0, uuid_fns_1.getUuid)(),
13
- size: 'huge',
14
- location: 'rooftop',
15
- }),
16
- }, exampleContext);
17
- expect(proposed.fromRemoteState).toEqual(null); // should have found that remote state is null for this
18
- expect(proposed.action).toEqual(DeclastructChangeProposal_1.DeclastructChangeProposalAction.CREATE); // so it should have triggered proposing creating it
19
- });
20
- it('should be able to propose updating an existing resource which has update defined on its interface', async () => {
21
- const proposed = await (0, proposeChangeForResource_1.proposeChangeForResource)({
22
- resource: new CNCMachine({
23
- ...exampleMachine,
24
- location: 'rooftop',
25
- }),
26
- }, exampleContext);
27
- expect(proposed.fromRemoteState).toEqual(exampleMachine); // should have found an existing remote state for this
28
- expect(proposed.action).toEqual(DeclastructChangeProposal_1.DeclastructChangeProposalAction.UPDATE); // so it should have triggered proposing updating it
29
- });
30
- it('should be able to propose replacing an existing resource which does not have update defined on its interface', async () => {
31
- const proposed = await (0, proposeChangeForResource_1.proposeChangeForResource)({
32
- resource: new CNCMachineRegistration({
33
- ...exampleRegistration,
34
- registeredBy: 'casey',
35
- }),
36
- }, exampleContext);
37
- expect(proposed.fromRemoteState).toEqual(exampleRegistration); // should have found an existing remote state for this
38
- expect(proposed.action).toEqual(DeclastructChangeProposal_1.DeclastructChangeProposalAction.REPLACE); // so it should have triggered proposing replacing it
39
- });
40
- it('should be able to propose no change an existing resource', async () => {
41
- const proposed = await (0, proposeChangeForResource_1.proposeChangeForResource)({
42
- resource: new CNCMachine({ ...exampleMachine }),
43
- }, exampleContext);
44
- expect(proposed.fromRemoteState).toEqual(exampleMachine); // should have found an existing remote state for this
45
- expect(proposed.action).toEqual(DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING); // so it should have triggered proposing updating it
46
- });
47
- });
48
- //# sourceMappingURL=proposeChangeForResource.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proposeChangeForResource.test.js","sourceRoot":"","sources":["../../../../src/logic/actions/propose/proposeChangeForResource.test.ts"],"names":[],"mappings":";;AAAA,uCAAmC;AAEnC,kFAA+E;AAC/E,yFAA4F;AAC5F,yEAAsE;AAEtE,MAAM,EACJ,cAAc,EACd,cAAc,EACd,UAAU,EACV,mBAAmB,EACnB,sBAAsB,GACvB,GAAG,IAAA,qCAAiB,GAAE,CAAC;AAExB,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,EAAE,CAAC,mDAAmD,EAAE,KAAK,IAAI,EAAE;QACjE,MAAM,QAAQ,GAAG,MAAM,IAAA,mDAAwB,EAC7C;YACE,QAAQ,EAAE,IAAI,UAAU,CAAC;gBACvB,YAAY,EAAE,IAAA,kBAAO,GAAE;gBACvB,IAAI,EAAE,MAAM;gBACZ,QAAQ,EAAE,SAAS;aACpB,CAAC;SACH,EACD,cAAc,CACf,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,uDAAuD;QACvG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,2DAA+B,CAAC,MAAM,CAAC,CAAC,CAAC,oDAAoD;IAC/H,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,mGAAmG,EAAE,KAAK,IAAI,EAAE;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AAC,CAAC,oDAAoD;IACnI,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,8 +0,0 @@
1
- import { DeclastructChangeProposal } from '../../domain/DeclastructChangeProposal';
2
- import { DeclastructContext } from '../../domain/DeclastructContext';
3
- /**
4
- * applies the planned actions required to update the remote state to match the declared state
5
- */
6
- export declare const applyChanges: ({ proposals, }: {
7
- proposals: DeclastructChangeProposal<any>[];
8
- }, context: DeclastructContext) => Promise<void>;