declastruct 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) 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 +225 -29
  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/logic/actions/execute/canUpdateResource.d.ts +0 -5
  135. package/dist/logic/actions/execute/canUpdateResource.js +0 -12
  136. package/dist/logic/actions/execute/canUpdateResource.js.map +0 -1
  137. package/dist/logic/actions/execute/executeProposal.d.ts +0 -5
  138. package/dist/logic/actions/execute/executeProposal.js +0 -52
  139. package/dist/logic/actions/execute/executeProposal.js.map +0 -1
  140. package/dist/logic/actions/propose/getColoredActionToken.d.ts +0 -4
  141. package/dist/logic/actions/propose/getColoredActionToken.js +0 -22
  142. package/dist/logic/actions/propose/getColoredActionToken.js.map +0 -1
  143. package/dist/logic/actions/propose/getColoredProposalTitle.d.ts +0 -4
  144. package/dist/logic/actions/propose/getColoredProposalTitle.js +0 -34
  145. package/dist/logic/actions/propose/getColoredProposalTitle.js.map +0 -1
  146. package/dist/logic/actions/propose/proposeChangeForResource.d.ts +0 -7
  147. package/dist/logic/actions/propose/proposeChangeForResource.js +0 -65
  148. package/dist/logic/actions/propose/proposeChangeForResource.js.map +0 -1
  149. package/dist/logic/actions/propose/proposeChangeForResource.test.js +0 -48
  150. package/dist/logic/actions/propose/proposeChangeForResource.test.js.map +0 -1
  151. package/dist/logic/commands/command.apply.d.ts +0 -8
  152. package/dist/logic/commands/command.apply.js +0 -77
  153. package/dist/logic/commands/command.apply.js.map +0 -1
  154. package/dist/logic/commands/command.plan.d.ts +0 -13
  155. package/dist/logic/commands/command.plan.js +0 -155
  156. package/dist/logic/commands/command.plan.js.map +0 -1
  157. package/dist/logic/commands/execute.d.ts +0 -15
  158. package/dist/logic/commands/execute.js +0 -63
  159. package/dist/logic/commands/execute.js.map +0 -1
  160. package/dist/logic/tools/compare/castReferenceToGrokableString.d.ts +0 -16
  161. package/dist/logic/tools/compare/castReferenceToGrokableString.js +0 -66
  162. package/dist/logic/tools/compare/castReferenceToGrokableString.js.map +0 -1
  163. package/dist/logic/tools/compare/castReferenceToGrokableString.test.js +0 -111
  164. package/dist/logic/tools/compare/castReferenceToGrokableString.test.js.map +0 -1
  165. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.d.ts +0 -11
  166. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.js +0 -61
  167. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.js.map +0 -1
  168. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js +0 -31
  169. package/dist/logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.js.map +0 -1
  170. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.d.ts +0 -21
  171. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.js +0 -53
  172. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.js.map +0 -1
  173. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.test.js +0 -31
  174. package/dist/logic/tools/compare/resolveReferenceToCommonComparableForm.test.js.map +0 -1
  175. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.d.ts +0 -10
  176. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.js +0 -41
  177. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.js.map +0 -1
  178. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.test.js +0 -174
  179. package/dist/logic/tools/compare/resolveReferencesToCommonComparableForm.test.js.map +0 -1
  180. package/dist/logic/tools/context/createDeclastructContext.d.ts +0 -10
  181. package/dist/logic/tools/context/createDeclastructContext.js +0 -12
  182. package/dist/logic/tools/context/createDeclastructContext.js.map +0 -1
  183. package/dist/logic/tools/context/destroyDeclastructContext.d.ts +0 -4
  184. package/dist/logic/tools/context/destroyDeclastructContext.js +0 -10
  185. package/dist/logic/tools/context/destroyDeclastructContext.js.map +0 -1
  186. package/dist/logic/tools/provider/castProviderContextToGlobalContext.d.ts +0 -4
  187. package/dist/logic/tools/provider/castProviderContextToGlobalContext.js +0 -10
  188. package/dist/logic/tools/provider/castProviderContextToGlobalContext.js.map +0 -1
  189. package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.d.ts +0 -13
  190. package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.js +0 -29
  191. package/dist/logic/tools/provider/getProviderContextFromGlobalContextForResourceClass.js.map +0 -1
  192. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.d.ts +0 -13
  193. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.js +0 -24
  194. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceExecutionDependenciesForResource.js.map +0 -1
  195. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.d.ts +0 -10
  196. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.js +0 -21
  197. package/dist/logic/tools/provider/getProviderResourceRemoteStateInterfaceFromContextForResourceClass.js.map +0 -1
  198. package/dist/logic/tools/reference/buildPrimaryKeyTo.d.ts +0 -5
  199. package/dist/logic/tools/reference/buildPrimaryKeyTo.js +0 -40
  200. package/dist/logic/tools/reference/buildPrimaryKeyTo.js.map +0 -1
  201. package/dist/logic/tools/reference/buildReferenceTo.d.ts +0 -28
  202. package/dist/logic/tools/reference/buildReferenceTo.js +0 -92
  203. package/dist/logic/tools/reference/buildReferenceTo.js.map +0 -1
  204. package/dist/logic/tools/reference/buildReferenceTo.test.js +0 -119
  205. package/dist/logic/tools/reference/buildReferenceTo.test.js.map +0 -1
  206. package/dist/logic/tools/reference/buildUniqueKeyTo.d.ts +0 -5
  207. package/dist/logic/tools/reference/buildUniqueKeyTo.js +0 -40
  208. package/dist/logic/tools/reference/buildUniqueKeyTo.js.map +0 -1
  209. package/dist/logic/tools/reference/defineReferenceClassOf.d.ts +0 -5
  210. package/dist/logic/tools/reference/defineReferenceClassOf.js +0 -25
  211. package/dist/logic/tools/reference/defineReferenceClassOf.js.map +0 -1
  212. package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.d.ts +0 -13
  213. package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.js +0 -36
  214. package/dist/logic/tools/reference/defineReferenceKeyConstituentsOf.js.map +0 -1
  215. package/dist/logic/tools/reference/getByReference.d.ts +0 -15
  216. package/dist/logic/tools/reference/getByReference.js +0 -55
  217. package/dist/logic/tools/reference/getByReference.js.map +0 -1
  218. package/dist/logic/tools/reference/getByReference.test.js +0 -92
  219. package/dist/logic/tools/reference/getByReference.test.js.map +0 -1
  220. package/dist/logic/tools/reference/getByReferencedPrimaryKey.d.ts +0 -6
  221. package/dist/logic/tools/reference/getByReferencedPrimaryKey.js +0 -17
  222. package/dist/logic/tools/reference/getByReferencedPrimaryKey.js.map +0 -1
  223. package/dist/logic/tools/reference/getByReferencedUniqueKey.d.ts +0 -7
  224. package/dist/logic/tools/reference/getByReferencedUniqueKey.js +0 -42
  225. package/dist/logic/tools/reference/getByReferencedUniqueKey.js.map +0 -1
  226. package/dist/logic/tools/reference/getPrimaryKeyByReference.d.ts +0 -15
  227. package/dist/logic/tools/reference/getPrimaryKeyByReference.js +0 -36
  228. package/dist/logic/tools/reference/getPrimaryKeyByReference.js.map +0 -1
  229. package/dist/logic/tools/reference/getReferenceTo.d.ts +0 -18
  230. package/dist/logic/tools/reference/getReferenceTo.js +0 -55
  231. package/dist/logic/tools/reference/getReferenceTo.js.map +0 -1
  232. package/dist/logic/tools/reference/getReferenceTo.test.js +0 -95
  233. package/dist/logic/tools/reference/getReferenceTo.test.js.map +0 -1
  234. package/dist/logic/tools/reference/getUniqueKeyByReference.d.ts +0 -15
  235. package/dist/logic/tools/reference/getUniqueKeyByReference.js +0 -36
  236. package/dist/logic/tools/reference/getUniqueKeyByReference.js.map +0 -1
  237. package/dist/logic/tools/reference/isPrimaryKeyReference.d.ts +0 -6
  238. package/dist/logic/tools/reference/isPrimaryKeyReference.js +0 -7
  239. package/dist/logic/tools/reference/isPrimaryKeyReference.js.map +0 -1
  240. package/dist/logic/tools/reference/isUniqueKeyReference.d.ts +0 -6
  241. package/dist/logic/tools/reference/isUniqueKeyReference.js +0 -7
  242. package/dist/logic/tools/reference/isUniqueKeyReference.js.map +0 -1
  243. /package/dist/{logic/actions/propose/proposeChangeForResource.test.d.ts → contract/cli/apply.integration.test.d.ts} +0 -0
  244. /package/dist/{logic/tools/compare/castReferenceToGrokableString.test.d.ts → contract/cli/plan.integration.test.d.ts} +0 -0
  245. /package/dist/{logic/tools/compare/detectDifferenceBetweenDesiredAndRemoteStateOfResource.test.d.ts → domain.objects/ContextDeclastruct.test.d.ts} +0 -0
  246. /package/dist/{logic/tools/compare/resolveReferenceToCommonComparableForm.test.d.ts → domain.objects/DeclastructChange.test.d.ts} +0 -0
  247. /package/dist/{logic/tools/compare/resolveReferencesToCommonComparableForm.test.d.ts → domain.objects/DeclastructDao.test.d.ts} +0 -0
  248. /package/dist/{logic/tools/reference/buildReferenceTo.test.d.ts → domain.objects/DeclastructPlan.test.d.ts} +0 -0
  249. /package/dist/{logic/tools/reference/getByReference.test.d.ts → domain.objects/DeclastructProvider.test.d.ts} +0 -0
  250. /package/dist/{logic/tools/reference/getReferenceTo.test.d.ts → domain.objects/IsoTimestamp.test.d.ts} +0 -0
@@ -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;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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,Q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AA+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"}
@@ -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,mD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AAC,sDAAsD;QACrH,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,2DAA+B,CAAC,OAAO,CAAC,CAAC,CAAC,qDAAqD;IACjI,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;QACxE,MAAM,QAAQ,GAAG,MAAM,IAAA,mDAAwB,EAC7C;YACE,QAAQ,EAAE,IAAI,UAAU,CAAC,EAAE,GAAG,cAAc,EAAE,CAAC;SAChD,EACD,cAAc,CACf,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,sDAAsD;QAChH,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,2DAA+B,CAAC,UAAU,CAAC,CAAC,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>;
@@ -1,77 +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.applyChanges = void 0;
7
- /* eslint-disable @typescript-eslint/no-loop-func */
8
- const number_fns_1 = require("@ehmpathy/number-fns");
9
- const chalk_1 = __importDefault(require("chalk"));
10
- const ora_1 = __importDefault(require("ora"));
11
- const DeclastructChangeProposal_1 = require("../../domain/DeclastructChangeProposal");
12
- const executeProposal_1 = require("../actions/execute/executeProposal");
13
- const getColoredProposalTitle_1 = require("../actions/propose/getColoredProposalTitle");
14
- /**
15
- * applies the planned actions required to update the remote state to match the declared state
16
- */
17
- const applyChanges = async ({ proposals, }, context) => {
18
- console.log(chalk_1.default.bold(chalk_1.default.white(`🦾 applying...`)));
19
- // apply each plan, in parallel, up to max concurrency
20
- for (const proposal of proposals) {
21
- await (async () => {
22
- // if no change, dont even mention it
23
- if (proposal.action === DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING)
24
- return;
25
- // if cant apply, notify we're skipping
26
- const canApply = [
27
- DeclastructChangeProposal_1.DeclastructChangeProposalAction.CREATE,
28
- DeclastructChangeProposal_1.DeclastructChangeProposalAction.UPDATE, // TODO: re-enable updates once we fix the permadiffs on the resources (also, add an easy way for users to say 'only create')
29
- ].includes(proposal.action);
30
- if (!canApply) {
31
- console.log(` ${chalk_1.default.bold(chalk_1.default.yellow('↓'))} ${(0, getColoredProposalTitle_1.getColoredProposalTitle)({
32
- proposal,
33
- })}`); // tslint:disable-line no-console
34
- return;
35
- }
36
- // if can apply, then try to apply
37
- const spinner = (0, ora_1.default)({
38
- text: `${(0, getColoredProposalTitle_1.getColoredProposalTitle)({
39
- proposal,
40
- })}`,
41
- indent: 2,
42
- }).start();
43
- const startTimeInMilliseconds = new Date().getTime();
44
- const getDurationInSeconds = () => {
45
- const endTimeInMilliseconds = new Date().getTime();
46
- const durationInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;
47
- const durationInSeconds = (0, number_fns_1.roundToHundredths)(durationInMilliseconds / 1e3);
48
- return durationInSeconds;
49
- };
50
- const interval = setInterval(() => {
51
- spinner.text = `${(0, getColoredProposalTitle_1.getColoredProposalTitle)({
52
- proposal,
53
- })} at ${getDurationInSeconds()} sec`;
54
- }, 1000);
55
- try {
56
- await (0, executeProposal_1.executeProposal)({ proposal }, context);
57
- await spinner.stopAndPersist({
58
- symbol: chalk_1.default.bold(chalk_1.default.green('✔')),
59
- text: `${(0, getColoredProposalTitle_1.getColoredProposalTitle)({
60
- proposal,
61
- })} ${chalk_1.default.gray(`took ${getDurationInSeconds()} sec`)}`,
62
- });
63
- }
64
- catch (error) {
65
- await spinner.stopAndPersist({
66
- symbol: chalk_1.default.bold(chalk_1.default.red('x')),
67
- });
68
- throw error;
69
- }
70
- finally {
71
- clearInterval(interval);
72
- }
73
- })();
74
- }
75
- };
76
- exports.applyChanges = applyChanges;
77
- //# sourceMappingURL=command.apply.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.apply.js","sourceRoot":"","sources":["../../../src/logic/commands/command.apply.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAoD;AACpD,qDAAyD;AACzD,kDAA0B;AAC1B,8CAAsB;AAEtB,sFAGgD;AAEhD,wEAAqE;AACrE,wFAAqF;AAErF;;GAEG;AACI,MAAM,YAAY,GAAG,KAAK,EAC/B,EACE,SAAS,GAGV,EACD,OAA2B,EACZ,EAAE;IACjB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,eAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAEvD,sDAAsD;IACtD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,CAAC,KAAK,IAAI,EAAE;YAChB,qCAAqC;YACrC,IAAI,QAAQ,CAAC,MAAM,KAAK,2DAA+B,CAAC,UAAU;gBAChE,OAAO;YAET,uCAAuC;YACvC,MAAM,QAAQ,GAAG;gBACf,2DAA+B,CAAC,MAAM;gBACtC,2DAA+B,CAAC,MAAM,EAAE,6HAA6H;aACtK,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC5B,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,OAAO,CAAC,GAAG,CACT,KAAK,eAAK,CAAC,IAAI,CAAC,eAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,IAAA,iDAAuB,EAAC;oBAC5D,QAAQ;iBACT,CAAC,EAAE,CACL,CAAC,CAAC,iCAAiC;gBACpC,OAAO;YACT,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M,EAAE,eAAK,CAAC,IAAI,CAAC,eAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;iBACnC,CAAC,CAAC;gBACH,MAAM,KAAK,CAAC;YACd,CAAC;oBAAS,CAAC;gBACT,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC;AACH,CAAC,CAAC;AAvEW,QAAA,YAAY,gBAuEvB"}
@@ -1,13 +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
- /**
6
- * shows
7
- * - the differences between the remote state and declared state
8
- * - the actions proposed to update the remote state to match the declared state // TODO
9
- */
10
- export declare const planChanges: ({ resources, inFullDetail, }: {
11
- resources: DeclaredResource[];
12
- inFullDetail: boolean;
13
- }, context: DeclastructContext & VisualogicContext) => Promise<DeclastructChangeProposal<DeclaredResource>[]>;
@@ -1,155 +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.planChanges = void 0;
7
- const number_fns_1 = require("@ehmpathy/number-fns");
8
- const bottleneck_1 = __importDefault(require("bottleneck"));
9
- const chalk_1 = __importDefault(require("chalk"));
10
- const indent_string_1 = __importDefault(require("indent-string"));
11
- const ora_1 = __importDefault(require("ora"));
12
- const type_fns_1 = require("type-fns");
13
- const DeclastructChangeProposal_1 = require("../../domain/DeclastructChangeProposal");
14
- const getColoredActionToken_1 = require("../actions/propose/getColoredActionToken");
15
- const getColoredProposalTitle_1 = require("../actions/propose/getColoredProposalTitle");
16
- const proposeChangeForResource_1 = require("../actions/propose/proposeChangeForResource");
17
- const bottleneck = new bottleneck_1.default({ maxConcurrent: 1 });
18
- const countTimesActionRequired = ({ proposals, action, }) => proposals
19
- .filter((proposal) => proposal.action === action)
20
- .reduce((summary, thisProposal) => {
21
- const currentTotal = summary.total;
22
- const currentCountPerThisResource = summary.perResource[thisProposal.forResourceClassName] ?? 0;
23
- return {
24
- total: currentTotal + 1,
25
- perResource: {
26
- ...summary.perResource,
27
- [thisProposal.forResourceClassName]: currentCountPerThisResource + 1,
28
- },
29
- };
30
- }, {
31
- total: 0,
32
- perResource: {},
33
- });
34
- /**
35
- * shows
36
- * - the differences between the remote state and declared state
37
- * - the actions proposed to update the remote state to match the declared state // TODO
38
- */
39
- const planChanges = async ({ resources, inFullDetail, }, context) => {
40
- console.log(chalk_1.default.bold(chalk_1.default.white(`🔬 planning...`)));
41
- const startTimeInMillisecondsCumulative = new Date().getTime();
42
- const proposals = await Promise.all(
43
- // TODO: dedupe ora spinner + timer between plan and apply
44
- resources.map(async (resource, index) => bottleneck.schedule(async () => {
45
- if (index > 0 && index % 100 == 0)
46
- console.log(`${chalk_1.default.bold(chalk_1.default.gray('[PLANNING]'))} at resource ${index}/${resources.length}\n`);
47
- const actionTitle = `${chalk_1.default.bold(chalk_1.default.gray('[PLANNING]'))} ${chalk_1.default.bold(resource.constructor.name)}`;
48
- let spinner = null;
49
- const startTimeInMilliseconds = new Date().getTime();
50
- const getDurationInSeconds = () => {
51
- const endTimeInMilliseconds = new Date().getTime();
52
- const durationInMilliseconds = endTimeInMilliseconds - startTimeInMilliseconds;
53
- const durationInSeconds = (0, number_fns_1.roundToHundredths)(durationInMilliseconds / 1e3);
54
- return durationInSeconds;
55
- };
56
- const interval = setInterval(() => {
57
- if (!spinner)
58
- spinner = (0, ora_1.default)({
59
- text: actionTitle,
60
- indent: 2,
61
- }).start(); // start after first interval timeout passes, so that instaplans dont noise up the output
62
- spinner.text = `${actionTitle} at ${getDurationInSeconds()} sec`;
63
- }, 100);
64
- try {
65
- const proposal = await (0, proposeChangeForResource_1.proposeChangeForResource)({ resource }, context);
66
- await spinner?.stopAndPersist({
67
- symbol: chalk_1.default.bold(chalk_1.default.green('✔')),
68
- text: `${actionTitle} ${chalk_1.default.gray(`took ${getDurationInSeconds()} sec`)}`,
69
- });
70
- return proposal;
71
- }
72
- catch (error) {
73
- await spinner?.stopAndPersist({
74
- symbol: chalk_1.default.bold(chalk_1.default.red('x')),
75
- });
76
- throw error;
77
- }
78
- finally {
79
- // console.log(`fin at ${getDurationInSeconds()} sec`);
80
- clearInterval(interval); // note: this will prevent any plans that took less than a second from appearing ever w/ spinner
81
- }
82
- })));
83
- const endTimeInMillisecondsCumulative = new Date().getTime();
84
- const durationInMillisecondsCumulative = endTimeInMillisecondsCumulative - startTimeInMillisecondsCumulative;
85
- const durationInSecondsCumulative = (0, number_fns_1.roundToHundredths)(durationInMillisecondsCumulative / 1e3);
86
- console.log(`${chalk_1.default.bold(chalk_1.default.gray('[PLANNING]'))} took ${durationInSecondsCumulative} sec total\n`);
87
- // if full detail was requested, enumerate each change
88
- let output = [];
89
- if (inFullDetail) {
90
- // filter out nochange plans
91
- const proposalsWithChange = proposals.filter((proposal) => proposal.action !== DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING);
92
- if (!proposalsWithChange.length) {
93
- console.log(`\n${chalk_1.default.bold('Everything is up to date 🎉')}. No changes proposed.`);
94
- return proposals; // exit here if no changes proposed
95
- }
96
- // define plans output
97
- output = proposalsWithChange // skip plans that have no change
98
- .map((proposal) => {
99
- // define plan header
100
- const header = ` * ${(0, getColoredProposalTitle_1.getColoredProposalTitle)({ proposal })}`;
101
- // define the diff
102
- const diff = proposal.difference
103
- ? `\n${(0, indent_string_1.default)(proposal.difference, 6)}\n`
104
- : '';
105
- // append to output
106
- return header + diff;
107
- });
108
- }
109
- // define the plans summary
110
- const stats = {
111
- [DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING]: countTimesActionRequired({
112
- proposals,
113
- action: DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING,
114
- }),
115
- [DeclastructChangeProposal_1.DeclastructChangeProposalAction.CREATE]: countTimesActionRequired({
116
- proposals,
117
- action: DeclastructChangeProposal_1.DeclastructChangeProposalAction.CREATE,
118
- }),
119
- [DeclastructChangeProposal_1.DeclastructChangeProposalAction.UPDATE]: countTimesActionRequired({
120
- proposals,
121
- action: DeclastructChangeProposal_1.DeclastructChangeProposalAction.UPDATE,
122
- }),
123
- [DeclastructChangeProposal_1.DeclastructChangeProposalAction.REPLACE]: countTimesActionRequired({
124
- proposals,
125
- action: DeclastructChangeProposal_1.DeclastructChangeProposalAction.REPLACE,
126
- }),
127
- [DeclastructChangeProposal_1.DeclastructChangeProposalAction.DESTROY]: countTimesActionRequired({
128
- proposals,
129
- action: DeclastructChangeProposal_1.DeclastructChangeProposalAction.DESTROY,
130
- }),
131
- };
132
- const statsToSummaryRows = Object.entries(stats)
133
- .filter((entry) => entry[1].total > 0)
134
- .map(([action, counts]) => [
135
- ` * ${(0, getColoredActionToken_1.getColoredActionToken)({
136
- action: action,
137
- })} ${counts.total}`,
138
- // display counts per resource for all actions except "no change"
139
- ...(action === DeclastructChangeProposal_1.DeclastructChangeProposalAction.DO_NOTHING
140
- ? []
141
- : Object.entries(counts.perResource).map(([resourceName, resourceCount]) => ` * ${resourceCount} ${resourceName}`)),
142
- ].join('\n'));
143
- const statsOutput = [
144
- inFullDetail ? chalk_1.default.bold(chalk_1.default.white('👀 summary...')) : undefined,
145
- ...statsToSummaryRows,
146
- ]
147
- .filter(type_fns_1.isPresent)
148
- .join('\n');
149
- // display the output in one statement to make it easier on testing
150
- console.log([...output, statsOutput, ''].join('\n')); // tslint:disable-line no-console
151
- // and return the proposals
152
- return proposals;
153
- };
154
- exports.planChanges = planChanges;
155
- //# sourceMappingURL=command.plan.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"command.plan.js","sourceRoot":"","sources":["../../../src/logic/commands/command.plan.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAyD;AACzD,4DAAoC;AACpC,kDAA0B;AAC1B,kEAAyC;A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ic';
2
- import { DeclaredResource } from '../../domain/DeclaredResource';
3
- import { DeclastructProvider } from '../../domain/DeclastructProvider';
4
- export declare enum DeclastructCommandOption {
5
- PLAN = "PLAN",
6
- APPLY = "APPLY"
7
- }
8
- /**
9
- * a utility for safely executing a command
10
- */
11
- export declare const executeCommand: ({ option, resources, providers, }: {
12
- option: DeclastructCommandOption;
13
- resources: DeclaredResource[];
14
- providers: DeclastructProvider<any>[];
15
- }, { log }: VisualogicContext) => Promise<void>;
@@ -1,63 +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.executeCommand = exports.DeclastructCommandOption = void 0;
7
- const error_fns_1 = require("@ehmpathy/error-fns");
8
- const chalk_1 = __importDefault(require("chalk"));
9
- const createDeclastructContext_1 = require("../tools/context/createDeclastructContext");
10
- const destroyDeclastructContext_1 = require("../tools/context/destroyDeclastructContext");
11
- const command_apply_1 = require("./command.apply");
12
- const command_plan_1 = require("./command.plan");
13
- var DeclastructCommandOption;
14
- (function (DeclastructCommandOption) {
15
- DeclastructCommandOption["PLAN"] = "PLAN";
16
- DeclastructCommandOption["APPLY"] = "APPLY";
17
- })(DeclastructCommandOption || (exports.DeclastructCommandOption = DeclastructCommandOption = {}));
18
- /**
19
- * a utility for safely executing a command
20
- */
21
- const executeCommand = async ({ option, resources, providers, }, { log }) => {
22
- // create the context
23
- console.log(`🔑 ${chalk_1.default.bold(chalk_1.default.white('initializing...'))} ${chalk_1.default.gray(`(${providers.length} providers, ${resources.length} resources)`)}`);
24
- console.log('');
25
- const context = await (0, createDeclastructContext_1.createDeclastructContext)({ providers, resources, log });
26
- // execute the command safely
27
- let hadError = false;
28
- try {
29
- // handle the plan command
30
- if (option === DeclastructCommandOption.PLAN) {
31
- await (0, command_plan_1.planChanges)({ resources, inFullDetail: true }, context);
32
- return;
33
- }
34
- // handle the apply command
35
- if (option === DeclastructCommandOption.APPLY) {
36
- const proposals = await (0, command_plan_1.planChanges)({ resources, inFullDetail: false }, context);
37
- await (0, command_apply_1.applyChanges)({ proposals }, context);
38
- return;
39
- }
40
- // throw on unexpected
41
- throw new error_fns_1.UnexpectedCodePathError('unsupported option was selected', {
42
- option,
43
- });
44
- }
45
- catch (error) {
46
- // track that there was an error
47
- hadError = true;
48
- // log the error
49
- console.error(error);
50
- // and pass it on up
51
- throw error;
52
- }
53
- finally {
54
- console.log(`🧹 cleaning up...`);
55
- await (0, destroyDeclastructContext_1.destroyDeclastructContext)({ context }); // todo: actually destroy when can destroy only the instantiated providers (not the preinstantiated ones)
56
- if (hadError)
57
- console.log(`\n🚨 experienced an error\n`);
58
- else
59
- console.log(`🎉 done!`);
60
- }
61
- };
62
- exports.executeCommand = executeCommand;
63
- //# sourceMappingURL=execute.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/logic/commands/execute.ts"],"names":[],"mappings":";;;;;;AAAA,mDAA8D;AAC9D,kDAA0B;AAK1B,wFAAqF;AACrF,0FAAuF;AACvF,mDAA+C;AAC/C,iDAA6C;AAE7C,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IAClC,yCAAa,CAAA;IACb,2CAAe,CAAA;AACjB,CAAC,EAHW,wBAAwB,wCAAxB,wBAAwB,QAGnC;AAED;;GAEG;AACI,MAAM,cAAc,GAAG,KAAK,EACjC,EACE,MAAM,EACN,SAAS,EACT,SAAS,GAKV,EACD,EAAE,GAAG,EAAqB,EACX,EAAE;IACjB,qBAAqB;IACrB,OAAO,CAAC,GAAG,CACT,MAAM,eAAK,CAAC,IAAI,CAAC,eAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,IAAI,eAAK,CAAC,IAAI,CAC5D,IAAI,SAAS,CAAC,MAAM,eAAe,SAAS,CAAC,MAAM,aAAa,CACjE,EAAE,CACJ,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,EAA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CAAC,CAAC;AA3DW,QAAA,cAAc,kBA2DzB"}
@@ -1,16 +0,0 @@
1
- import { VisualogicContext } from 'visualogic';
2
- import { DeclaredResourceReference } from '../../../domain/DeclaredResourceReference';
3
- import { DeclastructContext } from '../../../domain/DeclastructContext';
4
- /**
5
- * create a string representation of the reference which can be easily and intuitively understood
6
- *
7
- * example
8
- * - name:'default',campaign.name:'abcd',campaign.account.name:'xyz'
9
- *
10
- * relevance
11
- * - references, especially unique references, are difficult to read (lots of nesting and metadata; lots of noise)
12
- * - we need to be able to display a succinct, easy to read, high signal string for a reference to display in diffs
13
- */
14
- export declare const castReferenceToGrokableString: ({ reference, }: {
15
- reference: DeclaredResourceReference<any, any, any>;
16
- }, context: DeclastructContext & VisualogicContext) => Promise<string>;
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.castReferenceToGrokableString = void 0;
4
- const domain_objects_1 = require("domain-objects");
5
- const flattie_1 = require("flattie");
6
- const simple_in_memory_cache_1 = require("simple-in-memory-cache");
7
- const type_fns_1 = require("type-fns");
8
- const with_simple_caching_1 = require("with-simple-caching");
9
- const resolveReferenceToCommonComparableForm_1 = require("./resolveReferenceToCommonComparableForm");
10
- /**
11
- * create a string representation of the reference which can be easily and intuitively understood
12
- *
13
- * example
14
- * - name:'default',campaign.name:'abcd',campaign.account.name:'xyz'
15
- *
16
- * relevance
17
- * - references, especially unique references, are difficult to read (lots of nesting and metadata; lots of noise)
18
- * - we need to be able to display a succinct, easy to read, high signal string for a reference to display in diffs
19
- */
20
- exports.castReferenceToGrokableString = (0, with_simple_caching_1.withSimpleCaching)(async ({ reference, }, context) => {
21
- // resolve the reference to common-comparable-form, which will resolve all of references into unique keys
22
- const comparableReference = await (0, resolveReferenceToCommonComparableForm_1.resolveReferenceToCommonComparableForm)({ reference }, context);
23
- // now, flatten the reference object (i.e., `{ campaign: { account: { name: 'name' } } }` => `{ campaign.account.name: 'name' }`)
24
- const flat = (0, flattie_1.flattie)(comparableReference);
25
- // now, remove the noise from the keys
26
- const highSignalFlat = Object.fromEntries(Object.entries(flat)
27
- .map(([key, value]) => {
28
- // if the key ends with a metadata attribute, skip it
29
- if (key.includes('referenceOf'))
30
- return null;
31
- if (key.includes('identifiedBy.key'))
32
- return null;
33
- // otherwise, strip out the metadata parts in the key
34
- const highSignalKey = key.replace(/identifiedBy.value./g, '');
35
- // and return the new key value pair
36
- return [highSignalKey, value];
37
- })
38
- .filter(type_fns_1.isPresent) // skip the nulls
39
- .sort((a, b) => {
40
- // count how many layers away the value is from the root object for each of these keys
41
- const layersAwayA = a[0].split('.').length;
42
- const layersAwayB = b[0].split('.').length;
43
- // sort the keys that are "closer" to the root object first (i.e., things that describe the object directly should go before things that describe a nested reference; that way, the most specific, and least likely to repeat across different resources, attribute is first)
44
- return layersAwayA < layersAwayB ? -1 : 1;
45
- }));
46
- // now, convert that high signal flat object into a string
47
- const grokableString = [
48
- reference.referenceOf, // prefixed by what its referencing
49
- ...Object.entries(highSignalFlat).map(([key, value]) => [
50
- key,
51
- JSON.stringify(value)
52
- .replace(/'/g, "\\'")
53
- .replace(/^"/g, "'")
54
- .replace(/"$/g, "'"), // replace the surrounding `"` with `'` for better display in the console (since in console the string is typically already shown inside of `"`, so we get a lot of `\"` otherwise)
55
- ].join(':')),
56
- ].join('.');
57
- return grokableString;
58
- }, {
59
- cache: (0, simple_in_memory_cache_1.createCache)({
60
- expiration: { seconds: 300 }, // todo: set this to "infinite", since grokable references are deterministic; they never change for a given input
61
- }),
62
- serialize: {
63
- key: ({ forInput }) => (0, domain_objects_1.serialize)(forInput[0]), // omit context
64
- },
65
- });
66
- //# sourceMappingURL=castReferenceToGrokableString.js.map