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,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,KAA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AAK,CAAC,IAAI,CAAC,QAAQ,oBAAoB,EAAE,MAAM,CAAC,EAAE;iBACzD,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,MAAM,OAAO,CAAC,cAAc,CAAC;oBAC3B,MAAM,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;AACzC,8CAAsB;AACtB,uCAAqC;AAIrC,sFAGgD;AAEhD,oFAAiF;AACjF,wFAAqF;AACrF,0FAAuF;AAEvF,MAAM,UAAU,GAAG,IAAI,oBAAU,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,CAAC;AAQxD,MAAM,wBAAwB,GAAG,CAAC,EAChC,SAAS,EACT,MAAM,GAIP,EAAE,EAAE,CACH,SAAS;KACN,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC;KAChD,MAAM,CACL,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE;IACxB,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;IACnC,MAAM,2BAA2B,GAC/B,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAC9D,OAAO;QACL,KAAK,EAAE,YAAY,GAAG,CAAC;QACvB,WAAW,EAAE;YACX,GAAG,OAAO,CAAC,WAAW;YACtB,CAAC,YAAY,CAAC,oBAAoB,CAAC,EACjC,2BAA2B,GAAG,CAAC;SAClC;KACF,CAAC;AACJ,CAAC,EACD;IACE,KAAK,EAAE,CAAC;IACR,WAAW,EAAE,EAAE;CACiC,CACnD,CAAC;AAEN;;;;GAIG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,EACE,SAAS,EACT,YAAY,GAIb,EACD,OAA+C,EACS,EAAE;IAC1D,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,eAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACvD,MAAM,iCAAiC,GAAG,IAAI,IAAI,EAAE,C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C,IAAI,CAAC,CAAC,CAAC,CAAC,iCAAiC;IAEvF,2BAA2B;IAC3B,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAnKW,QAAA,WAAW,eAmKtB"}
@@ -1,15 +0,0 @@
1
- import { VisualogicContext } from 'visualogic';
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,KA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,EAAE,CAAC,CAAC,CAAC,yGAAyG;QACvJ,IAAI,QAAQ;YAAE,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;;YACpD,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;AACH,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
@@ -1 +0,0 @@
1
- {"version":3,"file":"castReferenceToGrokableString.js","sourceRoot":"","sources":["../../../../src/logic/tools/compare/castReferenceToGrokableString.ts"],"names":[],"mappings":";;;AAAA,mDAA2C;AAC3C,qCAAkC;AAClC,mEAAqD;AACrD,uCAAqC;AAErC,6DAAwD;AAIxD,qGAAkG;AAElG;;;;;;;;;GASG;AACU,QAAA,6BAA6B,GAAG,IAAA,uCAAiB,EAC5D,KAAK,EACH,EACE,SAAS,GAGV,EACD,OAA+C,EAC/C,EAAE;IACF,yGAAyG;IACzG,MAAM,mBAAmB,GAAG,MAAM,IAAA,+EAAsC,EACtE,EAAE,SAAS,EAAE,EACb,OAAO,CACR,CAAC;IAEF,iIAAiI;IACjI,MAAM,IAAI,GAAG,IAAA,iBAAO,EAAC,mBAAmB,CAAC,CAAC;IAE1C,sCAAsC;IACtC,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CACvC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;SACjB,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACpB,qDAAqD;QACrD,IAAI,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC;YAAE,OAAO,IAAI,CAAC;QAC7C,IAAI,GAAG,CAAC,QAAQ,CAAC,kBAAkB,CAAC;YAAE,OAAO,IAAI,CAAC;QAElD,qDAAqD;QACrD,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;QAE9D,oCAAoC;QACpC,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;SACD,MAAM,CAAC,oBAAS,CAAC,CAAC,iBAAiB;SACnC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,sFAAsF;QACtF,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QAC3C,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QAE3C,6QAA6Q;QAC7Q,OAAO,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC,CAAC,CACL,CAAC;IAEF,0DAA0D;IAC1D,MAAM,cAAc,GAAG;QACrB,SAAS,CAAC,WAAW,EAAE,mCAAmC;QAC1D,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACrD;YACE,GAAG;YACH,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAClB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;iBACpB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;iBACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,mLAAmL;SAC5M,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ;KACF,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,OAAO,cAAc,CAAC;AACxB,CAAC,EACD;IACE,KAAK,EAAE,IAAA,oCAAW,EAAC;QACjB,UAAU,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,iHAAiH;KAChJ,CAAC;IACF,SAAS,EAAE;QACT,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,IAAA,0BAAS,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,eAAe;KAC/D;CACF,CACF,CAAC"}
@@ -1,111 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const domain_objects_1 = require("domain-objects");
4
- const __1 = require("../../..");
5
- const getExampleContext_1 = require("../../../__test_assets__/getExampleContext");
6
- const DeclaredResourceReference_1 = require("../../../domain/DeclaredResourceReference");
7
- const castReferenceToGrokableString_1 = require("./castReferenceToGrokableString");
8
- const { exampleContext, exampleMachine, CNCMachine, exampleRegistration, CNCMachineRegistration, } = (0, getExampleContext_1.getExampleContext)();
9
- describe('castReferenceToGrokableString', () => {
10
- describe('shallow', () => {
11
- it('should be able to cast a shallow unique key reference to grokable string', async () => {
12
- const reference = (0, __1.buildRef)(CNCMachine, {
13
- serialNumber: exampleMachine.serialNumber,
14
- });
15
- const string = await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference }, exampleContext);
16
- console.log(string);
17
- expect(string).toEqual(`CNCMachine.serialNumber:'821'`);
18
- });
19
- });
20
- describe('nested', () => {
21
- class Spaceship extends domain_objects_1.DomainEntity {
22
- }
23
- Spaceship.primary = ['uuid'];
24
- Spaceship.unique = ['serialNumber'];
25
- Spaceship.updatable = ['serialNumber'];
26
- class Address extends domain_objects_1.DomainLiteral {
27
- }
28
- class Spaceport extends domain_objects_1.DomainEntity {
29
- }
30
- Spaceport.primary = ['uuid'];
31
- Spaceport.unique = ['address'];
32
- Spaceport.updatable = ['spaceships'];
33
- Spaceport.nested = {
34
- address: Address,
35
- spaceships: DeclaredResourceReference_1.DeclaredResourceReference,
36
- };
37
- class HumanAgent extends domain_objects_1.DomainEntity {
38
- }
39
- HumanAgent.primary = ['uuid'];
40
- HumanAgent.unique = ['birthCode'];
41
- class Captain extends domain_objects_1.DomainEntity {
42
- }
43
- Captain.primary = ['uuid'];
44
- Captain.unique = ['agent', 'ship'];
45
- Captain.nested = {
46
- agent: DeclaredResourceReference_1.DeclaredResourceReference,
47
- ship: DeclaredResourceReference_1.DeclaredResourceReference,
48
- };
49
- it('should be able to cast a unique key based on referenced entities to a grokable string', async () => {
50
- // instantiate them
51
- const ship = new Spaceship({
52
- serialNumber: '__SHIP_A__',
53
- fuelQuantity: 9001,
54
- passengers: 21,
55
- });
56
- const bob = new HumanAgent({
57
- birthCode: '821',
58
- name: 'Bobby Tables', // https://xkcd.com/327/
59
- });
60
- const captain = new Captain({
61
- agent: (0, __1.getRef)(bob),
62
- ship: (0, __1.getRef)(ship),
63
- });
64
- const string = await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference: (0, __1.getRef)(captain) }, exampleContext);
65
- expect(string).toEqual(`Captain.agent.birthCode:'821'.ship.serialNumber:'__SHIP_A__'`);
66
- });
67
- it('should be able to cast a unique key based on valueobject to a grokable string', async () => {
68
- // instantiate them
69
- const shipA = new Spaceship({
70
- serialNumber: '__SHIP_A__',
71
- fuelQuantity: 9001,
72
- passengers: 21,
73
- });
74
- const shipB = new Spaceship({
75
- uuid: '821',
76
- serialNumber: '__SHIP_B__',
77
- fuelQuantity: 7000,
78
- passengers: 42,
79
- });
80
- const spaceport = new Spaceport({
81
- uuid: '__SPACEPORT_UUID__',
82
- address: new Address({
83
- galaxy: 'Milky Way',
84
- solarSystem: 'Sun',
85
- planet: 'Earth',
86
- continent: 'North America',
87
- }),
88
- spaceships: [(0, __1.getRef)(shipA), (0, __1.getRef)(shipB)],
89
- });
90
- const string = await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference: (0, __1.getRef)(spaceport) }, exampleContext);
91
- expect(string).toEqual(`Spaceport.address.galaxy:'Milky Way'.address.solarSystem:'Sun'.address.planet:'Earth'.address.continent:'North America'`);
92
- });
93
- it('should be able to get a grokable string for a primary key reference to a multi-layer nested unique key resource', async () => {
94
- const primaryKeyRef = (0, __1.buildRef)(CNCMachineRegistration, {
95
- uuid: exampleRegistration.uuid,
96
- });
97
- const string = await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference: primaryKeyRef }, exampleContext);
98
- expect(string).toEqual(`CNCMachineRegistration.machine.serialNumber:'821'`);
99
- });
100
- it('should be able to get a grokable string for a unique key reference w/ a nested primary key reference', async () => {
101
- const uniqueKeyRef = (0, __1.buildRef)(CNCMachineRegistration, {
102
- machine: (0, __1.buildRef)(CNCMachine, {
103
- uuid: exampleMachine.uuid,
104
- }),
105
- });
106
- const string = await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference: uniqueKeyRef }, exampleContext);
107
- expect(string).toEqual(`CNCMachineRegistration.machine.serialNumber:'821'`);
108
- });
109
- });
110
- });
111
- //# sourceMappingURL=castReferenceToGrokableString.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"castReferenceToGrokableString.test.js","sourceRoot":"","sources":["../../../../src/logic/tools/compare/castReferenceToGrokableString.test.ts"],"names":[],"mappings":";;AAAA,mDAA6D;AAE7D,gCAA4C;AAC5C,kFAIoD;AACpD,yFAAsF;AACtF,mFAAgF;AAEhF,MAAM,EACJ,cAAc,EACd,cAAc,EACd,UAAU,EACV,mBAAmB,EACnB,sBAAsB,GACvB,GAAG,IAAA,qCAAiB,GAAE,CAAC;AAExB,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACvB,EAAE,CAAC,0EAA0E,EAAE,KAAK,IAAI,EAAE;YACxF,MAAM,SAAS,GAAwB,IAAA,YAAQ,EAAC,UAAU,EAAE;gBAC1D,YAAY,EAAE,cAAc,CAAC,YAAY;aAC1C,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAA,6DAA6B,EAChD,EAAE,SAAS,EAAE,EACb,cAAc,CACf,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpB,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QAQtB,MAAM,SAAU,SAAQ,6BAAuB;;QAC/B,iBAAO,GAAG,CAAC,MAAM,CAAU,CAAC;QAC5B,gBAAM,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1B,mBAAS,GAAG,CAAC,cAAc,CAAC,CAAC;QAc7C,MAAM,OAAQ,SAAQ,8BAAsB;SAAsB;QAMlE,MA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5B,cAAc,CACf,CAAC;YACF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CACpB,mDAAmD,CACpD,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,EAAE,CAAC,sGAAsG,EAAE,KAAK,IAAI,EAAE;YACpH,MAAM,YAAY,GAAoC,IAAA,YAAQ,EAC5D,sBAAsB,EACtB;gBACE,OAAO,EAAE,IAAA,YAAQ,EAAC,UAAU,EAAE;oBAC5B,IAAI,EAAE,cAAc,CAAC,IAAI;iBAC1B,CAAC;aACH,CACF,CAAC;YACF,MAAM,MAAM,GAAG,MAAM,IAAA,6DAA6B,EAChD,EAAE,SAAS,EAAE,YAAY,EAAE,EAC3B,cAAc,CACf,CAAC;YACF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CACpB,mDAAmD,CACpD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,11 +0,0 @@
1
- import { DetailedDiff } from 'deep-object-diff';
2
- import { DomainObject } from 'domain-objects';
3
- import { VisualogicContext } from 'visualogic';
4
- import { DeclastructContext } from '../../../domain/DeclastructContext';
5
- export declare const detectDifferenceBetweenDesiredAndRemoteStateOfResource: <T extends DomainObject<any>>({ desiredState, remoteState, }: {
6
- desiredState: T | null;
7
- remoteState: T | null;
8
- }, context: DeclastructContext & VisualogicContext) => Promise<{
9
- displayable: string;
10
- usable: DetailedDiff;
11
- }>;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.detectDifferenceBetweenDesiredAndRemoteStateOfResource = void 0;
4
- const deep_object_diff_1 = require("deep-object-diff");
5
- const domain_objects_1 = require("domain-objects");
6
- const jest_diff_1 = require("jest-diff");
7
- const DeclaredResourceReference_1 = require("../../../domain/DeclaredResourceReference");
8
- const castReferenceToGrokableString_1 = require("./castReferenceToGrokableString");
9
- /**
10
- * recursively traverse each key of the object and grokify any references found
11
- */
12
- const withReferencesGrokified = async ({ resource }, context) => {
13
- // create a clone of the resources, which we'll mutate keys on
14
- const withKeysGrokified = new resource.constructor(resource);
15
- // for each key holding a reference, replace reference with grokable string
16
- await Promise.all(Object.keys(resource).map(async (key) => {
17
- const value = resource[key];
18
- if (value instanceof DeclaredResourceReference_1.DeclaredResourceReference)
19
- withKeysGrokified[key] = await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference: value }, context);
20
- else if (Array.isArray(value))
21
- withKeysGrokified[key] = await Promise.all(value.map(async (valueItem) => value instanceof DeclaredResourceReference_1.DeclaredResourceReference
22
- ? await (0, castReferenceToGrokableString_1.castReferenceToGrokableString)({ reference: valueItem }, context)
23
- : await withReferencesGrokified({ resource: valueItem }, context)));
24
- else if (value instanceof domain_objects_1.DomainObject)
25
- withKeysGrokified[key] = await withReferencesGrokified({ resource: value }, context);
26
- }));
27
- // return the fingerprinted object
28
- return withKeysGrokified;
29
- };
30
- const detectDifferenceBetweenDesiredAndRemoteStateOfResource = async ({ desiredState, remoteState, }, context) => {
31
- // replace all nested references with reference fingerprints, for readability
32
- const diffableDesiredState = desiredState
33
- ? // remove the metadata values from the desired state for diff, since these properties dont describe the data, they are just additional data typically generated by the remote state which cant be locally declared (e.g., uuid, createdAt, etc)
34
- (0, domain_objects_1.omitMetadataValues)(await withReferencesGrokified({ resource: desiredState }, context))
35
- : null;
36
- const diffableRemoteState = remoteState
37
- ? // remove the metadata values from the remote state for diff, since these properties dont describe the data, they are just additional data typically generated by the remote state which cant be locally declared (e.g., uuid, createdAt, etc)
38
- (0, domain_objects_1.omitMetadataValues)(await withReferencesGrokified({ resource: remoteState }, context))
39
- : null;
40
- // define a displayable difference
41
- const displayableDifference = (0, jest_diff_1.diff)(diffableDesiredState ?? {}, diffableRemoteState ?? {}, {
42
- omitAnnotationLines: true,
43
- aAnnotation: 'Desired State',
44
- bAnnotation: 'Remote State',
45
- aIndicator: '+',
46
- bIndicator: '-',
47
- });
48
- // replace the "Object {}" placeholder we have to use to represent null state, if present (since jest shows "Comparing two different types of values. Expected object but received null." if we try to use null directly)
49
- const cleanedDisplayableDifference = displayableDifference
50
- ?.replace('- Object {}', '- null')
51
- .replace('+ Object {}', '+ null');
52
- // define a usable difference
53
- const usableDifference = (0, deep_object_diff_1.detailedDiff)(diffableRemoteState ?? {}, diffableDesiredState ?? {}); // TODO: improve the usable difference. use the `objectDiff` and add our own info + make a more useful type
54
- // return both
55
- return {
56
- displayable: cleanedDisplayableDifference,
57
- usable: usableDifference,
58
- };
59
- };
60
- exports.detectDifferenceBetweenDesiredAndRemoteStateOfResource = detectDifferenceBetweenDesiredAndRemoteStateOfResource;
61
- //# sourceMappingURL=detectDifferenceBetweenDesiredAndRemoteStateOfResource.js.map