@quadnix/octo 0.0.30 → 0.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 (362) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +25 -3
  3. package/dist/app.type.d.ts +143 -4
  4. package/dist/app.type.js +80 -9
  5. package/dist/app.type.js.map +1 -1
  6. package/dist/decorators/action.decorator.d.ts +10 -6
  7. package/dist/decorators/action.decorator.js +19 -6
  8. package/dist/decorators/action.decorator.js.map +1 -1
  9. package/dist/decorators/anchor.decorator.d.ts +12 -5
  10. package/dist/decorators/anchor.decorator.js +12 -5
  11. package/dist/decorators/anchor.decorator.js.map +1 -1
  12. package/dist/decorators/enable-hook.decorator.d.ts +1 -1
  13. package/dist/decorators/enable-hook.decorator.js +1 -1
  14. package/dist/decorators/factory.decorator.d.ts +18 -34
  15. package/dist/decorators/factory.decorator.js +18 -34
  16. package/dist/decorators/factory.decorator.js.map +1 -1
  17. package/dist/decorators/model.decorator.d.ts +1 -1
  18. package/dist/decorators/model.decorator.js +1 -1
  19. package/dist/decorators/module.decorator.d.ts +16 -10
  20. package/dist/decorators/module.decorator.js +16 -10
  21. package/dist/decorators/module.decorator.js.map +1 -1
  22. package/dist/decorators/on-event.decorator.d.ts +5 -0
  23. package/dist/decorators/on-event.decorator.js +5 -0
  24. package/dist/decorators/on-event.decorator.js.map +1 -1
  25. package/dist/decorators/validate.decorator.d.ts +15 -1
  26. package/dist/decorators/validate.decorator.js +15 -1
  27. package/dist/decorators/validate.decorator.js.map +1 -1
  28. package/dist/errors/container.error.d.ts +18 -0
  29. package/dist/errors/container.error.js +18 -0
  30. package/dist/errors/container.error.js.map +1 -1
  31. package/dist/errors/index.d.ts +1 -0
  32. package/dist/errors/index.js +1 -0
  33. package/dist/errors/index.js.map +1 -1
  34. package/dist/errors/module.error.d.ts +6 -0
  35. package/dist/errors/module.error.js +6 -0
  36. package/dist/errors/module.error.js.map +1 -1
  37. package/dist/errors/node.error.d.ts +56 -0
  38. package/dist/errors/node.error.js +56 -0
  39. package/dist/errors/node.error.js.map +1 -1
  40. package/dist/errors/schema.error.d.ts +6 -0
  41. package/dist/errors/schema.error.js +6 -0
  42. package/dist/errors/schema.error.js.map +1 -1
  43. package/dist/errors/terraform.error.d.ts +19 -0
  44. package/dist/errors/terraform.error.js +23 -0
  45. package/dist/errors/terraform.error.js.map +1 -0
  46. package/dist/errors/transaction.error.d.ts +61 -0
  47. package/dist/errors/transaction.error.js +61 -0
  48. package/dist/errors/transaction.error.js.map +1 -1
  49. package/dist/events/action.event.d.ts +0 -2
  50. package/dist/events/action.event.js +0 -2
  51. package/dist/events/action.event.js.map +1 -1
  52. package/dist/events/event.model.d.ts +21 -5
  53. package/dist/events/event.model.js +11 -5
  54. package/dist/events/event.model.js.map +1 -1
  55. package/dist/events/hook/commit.hook.event.d.ts +0 -6
  56. package/dist/events/hook/commit.hook.event.js +0 -6
  57. package/dist/events/hook/commit.hook.event.js.map +1 -1
  58. package/dist/events/hook/hook.event.d.ts +0 -2
  59. package/dist/events/hook/hook.event.js +0 -2
  60. package/dist/events/hook/hook.event.js.map +1 -1
  61. package/dist/events/hook/model.hook.event.d.ts +0 -6
  62. package/dist/events/hook/model.hook.event.js +0 -6
  63. package/dist/events/hook/model.hook.event.js.map +1 -1
  64. package/dist/events/hook/resource.hook.event.d.ts +0 -6
  65. package/dist/events/hook/resource.hook.event.js +0 -6
  66. package/dist/events/hook/resource.hook.event.js.map +1 -1
  67. package/dist/events/index.d.ts +3 -0
  68. package/dist/events/index.js +3 -0
  69. package/dist/events/index.js.map +1 -1
  70. package/dist/events/mode-result.event.d.ts +57 -0
  71. package/dist/events/mode-result.event.js +24 -0
  72. package/dist/events/mode-result.event.js.map +1 -0
  73. package/dist/events/mode.event.d.ts +57 -0
  74. package/dist/events/mode.event.js +32 -0
  75. package/dist/events/mode.event.js.map +1 -0
  76. package/dist/events/module.event.d.ts +0 -2
  77. package/dist/events/module.event.js +0 -2
  78. package/dist/events/module.event.js.map +1 -1
  79. package/dist/events/registration.event.d.ts +18 -14
  80. package/dist/events/registration.event.js +18 -14
  81. package/dist/events/registration.event.js.map +1 -1
  82. package/dist/events/serialization.event.d.ts +15 -12
  83. package/dist/events/serialization.event.js +15 -12
  84. package/dist/events/serialization.event.js.map +1 -1
  85. package/dist/events/terraform.event.d.ts +42 -0
  86. package/dist/events/terraform.event.js +31 -0
  87. package/dist/events/terraform.event.js.map +1 -0
  88. package/dist/events/transaction.event.d.ts +0 -37
  89. package/dist/events/transaction.event.js +0 -28
  90. package/dist/events/transaction.event.js.map +1 -1
  91. package/dist/functions/container/container.d.ts +54 -13
  92. package/dist/functions/container/container.js +63 -18
  93. package/dist/functions/container/container.js.map +1 -1
  94. package/dist/functions/container/test-container.d.ts +43 -29
  95. package/dist/functions/container/test-container.js +71 -43
  96. package/dist/functions/container/test-container.js.map +1 -1
  97. package/dist/functions/dependency/dependency.d.ts +82 -8
  98. package/dist/functions/dependency/dependency.js +80 -14
  99. package/dist/functions/dependency/dependency.js.map +1 -1
  100. package/dist/functions/diff/aggregate-resource-actions.d.ts +19 -0
  101. package/dist/functions/diff/aggregate-resource-actions.js +41 -0
  102. package/dist/functions/diff/aggregate-resource-actions.js.map +1 -0
  103. package/dist/functions/diff/diff-metadata.d.ts +21 -3
  104. package/dist/functions/diff/diff-metadata.js +18 -0
  105. package/dist/functions/diff/diff-metadata.js.map +1 -1
  106. package/dist/functions/diff/diff.d.ts +55 -1
  107. package/dist/functions/diff/diff.js +44 -3
  108. package/dist/functions/diff/diff.js.map +1 -1
  109. package/dist/functions/diff/diff.utility.d.ts +17 -2
  110. package/dist/functions/diff/diff.utility.js +53 -38
  111. package/dist/functions/diff/diff.utility.js.map +1 -1
  112. package/dist/functions/hook/commit.hook.d.ts +16 -1
  113. package/dist/functions/hook/commit.hook.js +21 -6
  114. package/dist/functions/hook/commit.hook.js.map +1 -1
  115. package/dist/functions/hook/model-action.hook.d.ts +16 -1
  116. package/dist/functions/hook/model-action.hook.js +21 -6
  117. package/dist/functions/hook/model-action.hook.js.map +1 -1
  118. package/dist/functions/hook/resource-action.hook.d.ts +16 -1
  119. package/dist/functions/hook/resource-action.hook.js +21 -6
  120. package/dist/functions/hook/resource-action.hook.js.map +1 -1
  121. package/dist/functions/node/node-action.abstract.d.ts +23 -0
  122. package/dist/functions/node/node-action.abstract.js +20 -0
  123. package/dist/functions/node/node-action.abstract.js.map +1 -1
  124. package/dist/functions/node/node.abstract.d.ts +56 -5
  125. package/dist/functions/node/node.abstract.js +85 -12
  126. package/dist/functions/node/node.abstract.js.map +1 -1
  127. package/dist/functions/node/node.interface.d.ts +1 -0
  128. package/dist/functions/schema/schema.d.ts +7 -0
  129. package/dist/functions/schema/schema.js +9 -0
  130. package/dist/functions/schema/schema.js.map +1 -1
  131. package/dist/index.d.ts +5 -1
  132. package/dist/index.js +4 -1
  133. package/dist/index.js.map +1 -1
  134. package/dist/main.d.ts +244 -14
  135. package/dist/main.js +361 -72
  136. package/dist/main.js.map +1 -1
  137. package/dist/models/account/account.model.d.ts +37 -7
  138. package/dist/models/account/account.model.js +40 -8
  139. package/dist/models/account/account.model.js.map +1 -1
  140. package/dist/models/account/account.schema.d.ts +13 -1
  141. package/dist/models/account/account.schema.js +12 -0
  142. package/dist/models/account/account.schema.js.map +1 -1
  143. package/dist/models/app/app.model.d.ts +16 -1
  144. package/dist/models/app/app.model.js +19 -4
  145. package/dist/models/app/app.model.js.map +1 -1
  146. package/dist/models/app/app.schema.d.ts +6 -0
  147. package/dist/models/app/app.schema.js +6 -0
  148. package/dist/models/app/app.schema.js.map +1 -1
  149. package/dist/models/deployment/deployment.model.d.ts +13 -1
  150. package/dist/models/deployment/deployment.model.js +16 -4
  151. package/dist/models/deployment/deployment.model.js.map +1 -1
  152. package/dist/models/deployment/deployment.schema.d.ts +2 -0
  153. package/dist/models/deployment/deployment.schema.js +2 -0
  154. package/dist/models/deployment/deployment.schema.js.map +1 -1
  155. package/dist/models/environment/environment.model.d.ts +13 -1
  156. package/dist/models/environment/environment.model.js +20 -8
  157. package/dist/models/environment/environment.model.js.map +1 -1
  158. package/dist/models/environment/environment.schema.d.ts +2 -0
  159. package/dist/models/environment/environment.schema.js +2 -0
  160. package/dist/models/environment/environment.schema.js.map +1 -1
  161. package/dist/models/execution/execution.model.d.ts +20 -2
  162. package/dist/models/execution/execution.model.js +46 -28
  163. package/dist/models/execution/execution.model.js.map +1 -1
  164. package/dist/models/execution/execution.schema.d.ts +11 -0
  165. package/dist/models/execution/execution.schema.js +11 -0
  166. package/dist/models/execution/execution.schema.js.map +1 -1
  167. package/dist/models/filesystem/filesystem.model.d.ts +27 -1
  168. package/dist/models/filesystem/filesystem.model.js +30 -4
  169. package/dist/models/filesystem/filesystem.model.js.map +1 -1
  170. package/dist/models/filesystem/filesystem.schema.d.ts +5 -0
  171. package/dist/models/filesystem/filesystem.schema.js +5 -0
  172. package/dist/models/filesystem/filesystem.schema.js.map +1 -1
  173. package/dist/models/image/image.model.d.ts +17 -4
  174. package/dist/models/image/image.model.js +20 -7
  175. package/dist/models/image/image.model.js.map +1 -1
  176. package/dist/models/image/image.schema.d.ts +8 -0
  177. package/dist/models/image/image.schema.js +8 -0
  178. package/dist/models/image/image.schema.js.map +1 -1
  179. package/dist/models/model-action.interface.d.ts +17 -4
  180. package/dist/models/model.abstract.d.ts +96 -1
  181. package/dist/models/model.abstract.js +106 -7
  182. package/dist/models/model.abstract.js.map +1 -1
  183. package/dist/models/model.interface.d.ts +3 -0
  184. package/dist/models/pipeline/pipeline.model.d.ts +13 -1
  185. package/dist/models/pipeline/pipeline.model.js +18 -6
  186. package/dist/models/pipeline/pipeline.model.js.map +1 -1
  187. package/dist/models/pipeline/pipeline.schema.d.ts +8 -0
  188. package/dist/models/pipeline/pipeline.schema.js +8 -0
  189. package/dist/models/pipeline/pipeline.schema.js.map +1 -1
  190. package/dist/models/region/region.model.d.ts +16 -1
  191. package/dist/models/region/region.model.js +19 -4
  192. package/dist/models/region/region.model.js.map +1 -1
  193. package/dist/models/region/region.schema.d.ts +6 -0
  194. package/dist/models/region/region.schema.js +6 -0
  195. package/dist/models/region/region.schema.js.map +1 -1
  196. package/dist/models/server/server.model.d.ts +13 -1
  197. package/dist/models/server/server.model.js +16 -4
  198. package/dist/models/server/server.model.js.map +1 -1
  199. package/dist/models/server/server.schema.d.ts +3 -1
  200. package/dist/models/server/server.schema.js +3 -1
  201. package/dist/models/server/server.schema.js.map +1 -1
  202. package/dist/models/service/service.model.d.ts +15 -1
  203. package/dist/models/service/service.model.js +15 -1
  204. package/dist/models/service/service.model.js.map +1 -1
  205. package/dist/models/service/service.schema.d.ts +4 -1
  206. package/dist/models/service/service.schema.js +4 -1
  207. package/dist/models/service/service.schema.js.map +1 -1
  208. package/dist/models/subnet/subnet.model.d.ts +27 -3
  209. package/dist/models/subnet/subnet.model.js +40 -16
  210. package/dist/models/subnet/subnet.model.js.map +1 -1
  211. package/dist/models/subnet/subnet.schema.d.ts +9 -0
  212. package/dist/models/subnet/subnet.schema.js +9 -0
  213. package/dist/models/subnet/subnet.schema.js.map +1 -1
  214. package/dist/modes/apply-transaction.d.ts +23 -0
  215. package/dist/modes/apply-transaction.js +25 -0
  216. package/dist/modes/apply-transaction.js.map +1 -0
  217. package/dist/modes/commit.mode.d.ts +54 -0
  218. package/dist/modes/commit.mode.js +235 -0
  219. package/dist/modes/commit.mode.js.map +1 -0
  220. package/dist/modes/generate.mode.d.ts +29 -0
  221. package/dist/modes/generate.mode.js +49 -0
  222. package/dist/modes/generate.mode.js.map +1 -0
  223. package/dist/modes/run-action.mode.d.ts +30 -0
  224. package/dist/modes/run-action.mode.js +140 -0
  225. package/dist/modes/run-action.mode.js.map +1 -0
  226. package/dist/modes/validate.mode.d.ts +162 -0
  227. package/dist/modes/validate.mode.js +480 -0
  228. package/dist/modes/validate.mode.js.map +1 -0
  229. package/dist/modules/module.abstract.d.ts +51 -0
  230. package/dist/modules/module.abstract.js +36 -0
  231. package/dist/modules/module.abstract.js.map +1 -1
  232. package/dist/modules/module.container.d.ts +36 -0
  233. package/dist/modules/module.container.js +36 -0
  234. package/dist/modules/module.container.js.map +1 -1
  235. package/dist/modules/test-module.container.d.ts +139 -25
  236. package/dist/modules/test-module.container.js +410 -178
  237. package/dist/modules/test-module.container.js.map +1 -1
  238. package/dist/overlays/anchor.abstract.d.ts +32 -1
  239. package/dist/overlays/anchor.abstract.js +42 -11
  240. package/dist/overlays/anchor.abstract.js.map +1 -1
  241. package/dist/overlays/anchor.schema.d.ts +21 -0
  242. package/dist/overlays/anchor.schema.js +21 -0
  243. package/dist/overlays/anchor.schema.js.map +1 -1
  244. package/dist/overlays/overlay-data.repository.d.ts +18 -0
  245. package/dist/overlays/overlay-data.repository.js +18 -0
  246. package/dist/overlays/overlay-data.repository.js.map +1 -1
  247. package/dist/overlays/overlay.abstract.d.ts +56 -1
  248. package/dist/overlays/overlay.abstract.js +79 -20
  249. package/dist/overlays/overlay.abstract.js.map +1 -1
  250. package/dist/overlays/overlay.schema.d.ts +20 -0
  251. package/dist/overlays/overlay.schema.js +20 -0
  252. package/dist/overlays/overlay.schema.js.map +1 -1
  253. package/dist/resources/resource-action.interface.d.ts +26 -2
  254. package/dist/resources/resource-data.repository.d.ts +63 -1
  255. package/dist/resources/resource-data.repository.js +94 -4
  256. package/dist/resources/resource-data.repository.js.map +1 -1
  257. package/dist/resources/resource.abstract.d.ts +118 -3
  258. package/dist/resources/resource.abstract.js +166 -33
  259. package/dist/resources/resource.abstract.js.map +1 -1
  260. package/dist/resources/resource.schema.d.ts +29 -1
  261. package/dist/resources/resource.schema.js +28 -0
  262. package/dist/resources/resource.schema.js.map +1 -1
  263. package/dist/resources/terraform-resource.abstract.d.ts +44 -0
  264. package/dist/resources/terraform-resource.abstract.js +45 -0
  265. package/dist/resources/terraform-resource.abstract.js.map +1 -0
  266. package/dist/services/event/event.service.d.ts +30 -3
  267. package/dist/services/event/event.service.js +58 -16
  268. package/dist/services/event/event.service.js.map +1 -1
  269. package/dist/services/input/input.service.d.ts +52 -3
  270. package/dist/services/input/input.service.js +72 -8
  271. package/dist/services/input/input.service.js.map +1 -1
  272. package/dist/services/schema-translation/schema-translation.service.d.ts +9 -0
  273. package/dist/services/schema-translation/schema-translation.service.js +9 -0
  274. package/dist/services/schema-translation/schema-translation.service.js.map +1 -1
  275. package/dist/services/serialization/model/model-serialization.service.d.ts +26 -2
  276. package/dist/services/serialization/model/model-serialization.service.js +110 -62
  277. package/dist/services/serialization/model/model-serialization.service.js.map +1 -1
  278. package/dist/services/serialization/resource/resource-serialization.service.d.ts +33 -4
  279. package/dist/services/serialization/resource/resource-serialization.service.js +64 -28
  280. package/dist/services/serialization/resource/resource-serialization.service.js.map +1 -1
  281. package/dist/services/state-management/file-app-lock.utility.d.ts +43 -0
  282. package/dist/services/state-management/file-app-lock.utility.js +124 -0
  283. package/dist/services/state-management/file-app-lock.utility.js.map +1 -0
  284. package/dist/services/state-management/local-encryption.state-provider.d.ts +53 -2
  285. package/dist/services/state-management/local-encryption.state-provider.js +75 -49
  286. package/dist/services/state-management/local-encryption.state-provider.js.map +1 -1
  287. package/dist/services/state-management/local.state-provider.d.ts +49 -2
  288. package/dist/services/state-management/local.state-provider.js +70 -49
  289. package/dist/services/state-management/local.state-provider.js.map +1 -1
  290. package/dist/services/state-management/state-management.service.d.ts +141 -6
  291. package/dist/services/state-management/state-management.service.js +149 -4
  292. package/dist/services/state-management/state-management.service.js.map +1 -1
  293. package/dist/services/state-management/state-provider.interface.d.ts +55 -1
  294. package/dist/services/state-management/terraform-state.service.d.ts +76 -0
  295. package/dist/services/state-management/terraform-state.service.js +154 -0
  296. package/dist/services/state-management/terraform-state.service.js.map +1 -0
  297. package/dist/services/state-management/test.state-provider.d.ts +38 -1
  298. package/dist/services/state-management/test.state-provider.js +52 -21
  299. package/dist/services/state-management/test.state-provider.js.map +1 -1
  300. package/dist/services/terraform/terraform.service.d.ts +426 -0
  301. package/dist/services/terraform/terraform.service.js +995 -0
  302. package/dist/services/terraform/terraform.service.js.map +1 -0
  303. package/dist/services/terraform/terraform.type.d.ts +387 -0
  304. package/dist/services/terraform/terraform.type.js +579 -0
  305. package/dist/services/terraform/terraform.type.js.map +1 -0
  306. package/dist/services/transaction/transaction.service.d.ts +86 -10
  307. package/dist/services/transaction/transaction.service.js +387 -232
  308. package/dist/services/transaction/transaction.service.js.map +1 -1
  309. package/dist/services/validation/validation.service.d.ts +13 -1
  310. package/dist/services/validation/validation.service.js +12 -0
  311. package/dist/services/validation/validation.service.js.map +1 -1
  312. package/dist/utilities/array/array.utility.d.ts +3 -0
  313. package/dist/utilities/array/array.utility.js +3 -0
  314. package/dist/utilities/array/array.utility.js.map +1 -1
  315. package/dist/utilities/file/file.utility.d.ts +15 -0
  316. package/dist/utilities/file/file.utility.js +18 -1
  317. package/dist/utilities/file/file.utility.js.map +1 -1
  318. package/dist/utilities/hcl/hcl.utility.d.ts +61 -0
  319. package/dist/utilities/hcl/hcl.utility.js +229 -0
  320. package/dist/utilities/hcl/hcl.utility.js.map +1 -0
  321. package/dist/utilities/node/node.utility.d.ts +3 -0
  322. package/dist/utilities/node/node.utility.js +3 -0
  323. package/dist/utilities/node/node.utility.js.map +1 -1
  324. package/dist/utilities/object/object.utility.d.ts +12 -0
  325. package/dist/utilities/object/object.utility.js +12 -0
  326. package/dist/utilities/object/object.utility.js.map +1 -1
  327. package/dist/utilities/project/project.utility.d.ts +28 -0
  328. package/dist/utilities/project/project.utility.js +35 -0
  329. package/dist/utilities/project/project.utility.js.map +1 -0
  330. package/dist/utilities/string/string.utility.d.ts +21 -0
  331. package/dist/utilities/string/string.utility.js +39 -0
  332. package/dist/utilities/string/string.utility.js.map +1 -0
  333. package/dist/utilities/terraform/terraform.utility.d.ts +227 -0
  334. package/dist/utilities/terraform/terraform.utility.js +434 -0
  335. package/dist/utilities/terraform/terraform.utility.js.map +1 -0
  336. package/dist/utilities/test-helpers/test-classes.d.ts +18 -31
  337. package/dist/utilities/test-helpers/test-classes.js +18 -41
  338. package/dist/utilities/test-helpers/test-classes.js.map +1 -1
  339. package/dist/utilities/test-helpers/test-models.js +12 -0
  340. package/dist/utilities/test-helpers/test-models.js.map +1 -1
  341. package/dist/utilities/test-helpers/test-modes.d.ts +315 -0
  342. package/dist/utilities/test-helpers/test-modes.js +463 -0
  343. package/dist/utilities/test-helpers/test-modes.js.map +1 -0
  344. package/dist/utilities/test-helpers/test-modules.d.ts +41 -0
  345. package/dist/utilities/test-helpers/test-modules.js +79 -0
  346. package/dist/utilities/test-helpers/test-modules.js.map +1 -0
  347. package/dist/utilities/test-helpers/test-overlays.d.ts +17 -1
  348. package/dist/utilities/test-helpers/test-overlays.js +49 -5
  349. package/dist/utilities/test-helpers/test-overlays.js.map +1 -1
  350. package/dist/utilities/test-helpers/test-resources.d.ts +19 -1
  351. package/dist/utilities/test-helpers/test-resources.js +61 -3
  352. package/dist/utilities/test-helpers/test-resources.js.map +1 -1
  353. package/dist/utilities/validation/validation.utility.d.ts +24 -0
  354. package/dist/utilities/validation/validation.utility.js +24 -0
  355. package/dist/utilities/validation/validation.utility.js.map +1 -1
  356. package/package.json +6 -5
  357. package/dist/services/capture/capture.service.d.ts +0 -19
  358. package/dist/services/capture/capture.service.js +0 -43
  359. package/dist/services/capture/capture.service.js.map +0 -1
  360. package/dist/utilities/cidr/cidr.utility.d.ts +0 -10
  361. package/dist/utilities/cidr/cidr.utility.js +0 -51
  362. package/dist/utilities/cidr/cidr.utility.js.map +0 -1
@@ -1,39 +1,174 @@
1
- import type { ModelSerializedOutput, ResourceSerializedOutput } from '../../app.type.js';
1
+ import type { ModelSerializedOutput, ResourceSerializedOutput, TerraformFolderOutput, TerraformResourceOutput } from '../../app.type.js';
2
2
  import type { IStateProvider } from './state-provider.interface.js';
3
3
  /**
4
+ * The `userData` persisted alongside the model graph in `models.json`.
5
+ */
6
+ interface ModelStateUserData {
7
+ terraformFolders?: TerraformFolderOutput[];
8
+ version?: number;
9
+ }
10
+ /**
11
+ * The `userData` persisted alongside the resource graph in `resources-actual.json` /
12
+ * `resources-old.json`.
13
+ */
14
+ interface ResourceStateUserData {
15
+ terraformFolders?: TerraformFolderOutput[];
16
+ terraformResources?: TerraformResourceOutput[];
17
+ version?: number;
18
+ }
19
+ /**
20
+ * What an external resource's action made of it, recorded the moment the action succeeded: the
21
+ * inputs it was given, the properties it was asked for, and the response it produced.
22
+ *
23
+ * It exists only between that moment and the `commit` that folds it into the resource graph, and
24
+ * while it exists it is the truth about that resource - octo state has not caught up yet.
25
+ */
26
+ interface ExternalResourceState {
27
+ inputs: Record<string, unknown>;
28
+ properties: Record<string, unknown>;
29
+ response: Record<string, string>;
30
+ }
31
+ /**
32
+ * Reads and writes Octo's state files through the configured {@link IStateProvider}.
33
+ *
34
+ * Resolve it from the {@link Container} when you need to inspect what the last run recorded.
35
+ * Octo manages its own state files, so writing through this service is rarely the right move.
36
+ *
4
37
  * @group Services/State Management
5
38
  */
6
39
  export declare class StateManagementService {
40
+ /**
41
+ * The resource graph as it stands after the last commit.
42
+ */
43
+ readonly actualResourceStateFileName: string;
44
+ /**
45
+ * The model graph as it stands after the last commit.
46
+ */
47
+ readonly modelStateFileName: string;
48
+ /**
49
+ * The resource graph as intent described it on the last commit.
50
+ */
51
+ readonly oldResourceStateFileName: string;
52
+ private readonly externalResourceStateFileNamePrefix;
7
53
  private readonly stateProvider;
54
+ /**
55
+ * @param stateProvider Where state is read from and written to.
56
+ */
8
57
  constructor(stateProvider: IStateProvider);
58
+ /**
59
+ * Clears what an external resource's action recorded.
60
+ *
61
+ * @internal
62
+ */
63
+ deleteExternalResourceState(resourceId: string): Promise<void>;
64
+ /**
65
+ * Deletes a state file. Deleting one that is not there is not an error.
66
+ */
67
+ deleteState(stateFileName: string): Promise<void>;
68
+ /**
69
+ * The id of the lock currently held, or `undefined` when the app is unlocked.
70
+ */
9
71
  getAppLock(): Promise<string | undefined>;
72
+ /**
73
+ * What an external resource's action made of it, if `commit` has not folded that into the resource
74
+ * graph yet. Undefined once it has, or before the action has ever run.
75
+ *
76
+ * @internal
77
+ */
78
+ getExternalResourceState(resourceId: string): Promise<ExternalResourceState | undefined>;
79
+ /**
80
+ * Reads the model graph. Returns an empty graph when no state exists yet.
81
+ */
10
82
  getModelState(stateFileName: string, { freeze }?: {
11
83
  freeze?: boolean;
12
84
  }): Promise<{
13
85
  data: ModelSerializedOutput;
14
- userData: object;
86
+ userData: ModelStateUserData;
15
87
  }>;
88
+ /**
89
+ * The response of one resource: what an external resource's action published and `commit` has not
90
+ * recorded yet, falling back to what the last commit recorded. Undefined when neither holds it.
91
+ *
92
+ * @internal
93
+ */
94
+ getResourceResponse(resourceId: string): Promise<Record<string, string> | undefined>;
95
+ /**
96
+ * Reads a resource graph. Returns an empty graph when no state exists yet.
97
+ */
16
98
  getResourceState(stateFileName: string, { freeze }?: {
17
99
  freeze?: boolean;
18
100
  }): Promise<{
19
101
  data: ResourceSerializedOutput;
20
- userData: object;
102
+ userData: ResourceStateUserData;
21
103
  }>;
104
+ /**
105
+ * Reads a state file as-is.
106
+ *
107
+ * @param defaultValue Returned instead of throwing when the file does not exist.
108
+ */
22
109
  getState(stateFileName: string, defaultValue?: any): Promise<Buffer>;
110
+ /**
111
+ * Whether `lockId` is the lock currently held.
112
+ *
113
+ * @throws {@link TransactionError} With the message `Invalid lock ID!` when a different lock is held.
114
+ */
23
115
  isAppLocked(lockId: string): Promise<boolean>;
116
+ /**
117
+ * The resource id of every external resource record a `commit` has not folded into the resource
118
+ * graph yet.
119
+ *
120
+ * A record is written the moment an action succeeds and cleared by the commit that records it, so
121
+ * one still here belongs to a run that did not finish.
122
+ *
123
+ * @internal
124
+ */
125
+ listExternalResourceStateIds(): Promise<string[]>;
126
+ /**
127
+ * Takes the app lock and returns its id.
128
+ *
129
+ * @throws {@link TransactionError} When a lock is held, naming the id that holds it.
130
+ */
24
131
  lockApp(): Promise<{
25
132
  lockId: string;
26
133
  }>;
27
- saveModelState(stateFileName: string, data: ModelSerializedOutput, userData: object): Promise<void>;
28
- saveResourceState(stateFileName: string, data: ResourceSerializedOutput, userData: object): Promise<void>;
134
+ /**
135
+ * Records what an external resource's action made of it. The next run reads it back rather than
136
+ * asking the resource graph, which does not learn any of this until `commit`.
137
+ *
138
+ * @internal
139
+ */
140
+ saveExternalResourceState(resourceId: string, state: ExternalResourceState): Promise<void>;
141
+ /**
142
+ * @internal
143
+ */
144
+ saveModelState(stateFileName: string, data: ModelSerializedOutput, userData: ModelStateUserData): Promise<void>;
145
+ /**
146
+ * @internal
147
+ */
148
+ saveResourceState(stateFileName: string, data: ResourceSerializedOutput, userData: ResourceStateUserData): Promise<void>;
149
+ /**
150
+ * Writes a state file as-is.
151
+ */
29
152
  saveState(stateFileName: string, data: Buffer): Promise<void>;
153
+ /**
154
+ * Releases the app lock. Unlocking an app that is not locked is not an error.
155
+ *
156
+ * @throws {@link TransactionError} With the message `Invalid lock ID!` when a different lock is held.
157
+ */
30
158
  unlockApp(lockId: string): Promise<void>;
31
- updateAppLockTransaction(lockId: string): Promise<void>;
159
+ /**
160
+ * @internal
161
+ */
162
+ private externalResourceStateFileName;
32
163
  }
33
164
  /**
34
165
  * @internal
35
166
  */
36
167
  export declare class StateManagementServiceFactory {
37
168
  private static instance;
169
+ /**
170
+ * @internal
171
+ */
38
172
  static create(stateProvider?: IStateProvider): Promise<StateManagementService>;
39
173
  }
174
+ export {};
@@ -7,15 +7,76 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { Factory } from '../../decorators/factory.decorator.js';
8
8
  import { TransactionError } from '../../errors/index.js';
9
9
  /**
10
+ * Serializes one state file.
11
+ *
12
+ * Formatted rather than written as a single line, because these files are committed: a reviewer
13
+ * reading the pull request that produced them sees which entries moved, and a merge conflict lands
14
+ * on the entries that actually collide instead of on the whole file.
15
+ */
16
+ function serializeState(data, userData) {
17
+ return Buffer.from(JSON.stringify({ data, userData }, null, 2));
18
+ }
19
+ /**
20
+ * Reads and writes Octo's state files through the configured {@link IStateProvider}.
21
+ *
22
+ * Resolve it from the {@link Container} when you need to inspect what the last run recorded.
23
+ * Octo manages its own state files, so writing through this service is rarely the right move.
24
+ *
10
25
  * @group Services/State Management
11
26
  */
12
27
  export class StateManagementService {
28
+ /**
29
+ * @param stateProvider Where state is read from and written to.
30
+ */
13
31
  constructor(stateProvider) {
32
+ /**
33
+ * The resource graph as it stands after the last commit.
34
+ */
35
+ this.actualResourceStateFileName = 'resources-actual.json';
36
+ /**
37
+ * The model graph as it stands after the last commit.
38
+ */
39
+ this.modelStateFileName = 'models.json';
40
+ /**
41
+ * The resource graph as intent described it on the last commit.
42
+ */
43
+ this.oldResourceStateFileName = 'resources-old.json';
44
+ this.externalResourceStateFileNamePrefix = 'resource-state-';
14
45
  this.stateProvider = stateProvider;
15
46
  }
47
+ /**
48
+ * Clears what an external resource's action recorded.
49
+ *
50
+ * @internal
51
+ */
52
+ async deleteExternalResourceState(resourceId) {
53
+ await this.deleteState(this.externalResourceStateFileName(resourceId));
54
+ }
55
+ /**
56
+ * Deletes a state file. Deleting one that is not there is not an error.
57
+ */
58
+ async deleteState(stateFileName) {
59
+ return this.stateProvider.deleteState(stateFileName);
60
+ }
61
+ /**
62
+ * The id of the lock currently held, or `undefined` when the app is unlocked.
63
+ */
16
64
  async getAppLock() {
17
65
  return this.stateProvider.getAppLock();
18
66
  }
67
+ /**
68
+ * What an external resource's action made of it, if `commit` has not folded that into the resource
69
+ * graph yet. Undefined once it has, or before the action has ever run.
70
+ *
71
+ * @internal
72
+ */
73
+ async getExternalResourceState(resourceId) {
74
+ const recordedState = await this.getState(this.externalResourceStateFileName(resourceId), Buffer.from(''));
75
+ return recordedState.length > 0 ? JSON.parse(recordedState.toString()) : undefined;
76
+ }
77
+ /**
78
+ * Reads the model graph. Returns an empty graph when no state exists yet.
79
+ */
19
80
  async getModelState(stateFileName, { freeze = true } = {}) {
20
81
  const defaultValue = {
21
82
  data: {
@@ -39,6 +100,30 @@ export class StateManagementService {
39
100
  }
40
101
  }
41
102
  }
103
+ /**
104
+ * The response of one resource: what an external resource's action published and `commit` has not
105
+ * recorded yet, falling back to what the last commit recorded. Undefined when neither holds it.
106
+ *
107
+ * @internal
108
+ */
109
+ async getResourceResponse(resourceId) {
110
+ const recordedState = await this.getExternalResourceState(resourceId);
111
+ if (recordedState) {
112
+ return recordedState.response;
113
+ }
114
+ const { data } = await this.getResourceState(this.actualResourceStateFileName);
115
+ const serializedResource = Object.values(data.resources).find((r) => r.resource.resourceId === resourceId);
116
+ if (!serializedResource) {
117
+ return undefined;
118
+ }
119
+ return Object.entries(serializedResource.resource.response).reduce((accumulator, [key, value]) => {
120
+ accumulator[key] = String(value);
121
+ return accumulator;
122
+ }, {});
123
+ }
124
+ /**
125
+ * Reads a resource graph. Returns an empty graph when no state exists yet.
126
+ */
42
127
  async getResourceState(stateFileName, { freeze = true } = {}) {
43
128
  const defaultValue = {
44
129
  data: {
@@ -60,6 +145,11 @@ export class StateManagementService {
60
145
  }
61
146
  }
62
147
  }
148
+ /**
149
+ * Reads a state file as-is.
150
+ *
151
+ * @param defaultValue Returned instead of throwing when the file does not exist.
152
+ */
63
153
  async getState(stateFileName, defaultValue) {
64
154
  try {
65
155
  return await this.stateProvider.getState(stateFileName);
@@ -73,32 +163,87 @@ export class StateManagementService {
73
163
  }
74
164
  }
75
165
  }
166
+ /**
167
+ * Whether `lockId` is the lock currently held.
168
+ *
169
+ * @throws {@link TransactionError} With the message `Invalid lock ID!` when a different lock is held.
170
+ */
76
171
  async isAppLocked(lockId) {
77
172
  return this.stateProvider.isAppLocked(lockId);
78
173
  }
174
+ /**
175
+ * The resource id of every external resource record a `commit` has not folded into the resource
176
+ * graph yet.
177
+ *
178
+ * A record is written the moment an action succeeds and cleared by the commit that records it, so
179
+ * one still here belongs to a run that did not finish.
180
+ *
181
+ * @internal
182
+ */
183
+ async listExternalResourceStateIds() {
184
+ const stateFileNames = await this.stateProvider.listStates(this.externalResourceStateFileNamePrefix);
185
+ return stateFileNames
186
+ .filter((stateFileName) => stateFileName.endsWith('.json'))
187
+ .map((stateFileName) => decodeURIComponent(stateFileName.slice(this.externalResourceStateFileNamePrefix.length, -'.json'.length)));
188
+ }
189
+ /**
190
+ * Takes the app lock and returns its id.
191
+ *
192
+ * @throws {@link TransactionError} When a lock is held, naming the id that holds it.
193
+ */
79
194
  async lockApp() {
80
195
  return this.stateProvider.lockApp();
81
196
  }
197
+ /**
198
+ * Records what an external resource's action made of it. The next run reads it back rather than
199
+ * asking the resource graph, which does not learn any of this until `commit`.
200
+ *
201
+ * @internal
202
+ */
203
+ async saveExternalResourceState(resourceId, state) {
204
+ await this.saveState(this.externalResourceStateFileName(resourceId), Buffer.from(JSON.stringify(state)));
205
+ }
206
+ /**
207
+ * @internal
208
+ */
82
209
  async saveModelState(stateFileName, data, userData) {
83
- await this.saveState(stateFileName, Buffer.from(JSON.stringify({ data, userData })));
210
+ await this.saveState(stateFileName, serializeState(data, userData));
84
211
  }
212
+ /**
213
+ * @internal
214
+ */
85
215
  async saveResourceState(stateFileName, data, userData) {
86
- await this.saveState(stateFileName, Buffer.from(JSON.stringify({ data, userData })));
216
+ await this.saveState(stateFileName, serializeState(data, userData));
87
217
  }
218
+ /**
219
+ * Writes a state file as-is.
220
+ */
88
221
  async saveState(stateFileName, data) {
89
222
  return this.stateProvider.saveState(stateFileName, data);
90
223
  }
224
+ /**
225
+ * Releases the app lock. Unlocking an app that is not locked is not an error.
226
+ *
227
+ * @throws {@link TransactionError} With the message `Invalid lock ID!` when a different lock is held.
228
+ */
91
229
  async unlockApp(lockId) {
92
230
  return this.stateProvider.unlockApp(lockId);
93
231
  }
94
- async updateAppLockTransaction(lockId) {
95
- return this.stateProvider.updateAppLockTransaction(lockId);
232
+ /**
233
+ * @internal
234
+ */
235
+ externalResourceStateFileName(resourceId) {
236
+ // A resource id is not a file name - it carries `/` where a resource is named after a path.
237
+ return `${this.externalResourceStateFileNamePrefix}${encodeURIComponent(resourceId)}.json`;
96
238
  }
97
239
  }
98
240
  /**
99
241
  * @internal
100
242
  */
101
243
  let StateManagementServiceFactory = class StateManagementServiceFactory {
244
+ /**
245
+ * @internal
246
+ */
102
247
  static async create(stateProvider) {
103
248
  if (!this.instance) {
104
249
  if (!stateProvider) {
@@ -1 +1 @@
1
- {"version":3,"file":"state-management.service.js","sourceRoot":"","sources":["../../../src/services/state-management/state-management.service.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAGjC,YAAY,aAA6B;QACvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,aAAqB,EACrB,EAAE,MAAM,GAAG,IAAI,KAA2B,EAAE;QAE5C,MAAM,YAAY,GAAsD;YACtE,IAAI,EAAE;gBACJ,OAAO,EAAE,EAAE;gBACX,YAAY,EAAE,EAAE;gBAChB,MAAM,EAAE,EAAE;gBACV,QAAQ,EAAE,EAAE;aACb;YACD,QAAQ,EAAE,EAAE;SACb,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YACtD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5F,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,CAAC,OAAO,KAAK,iBAAiB,EAAE,CAAC;gBACxC,OAAO,YAAY,CAAC;YAC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,IAAI,kCAAkC,CAC/F,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAsB,CAAC,aAAa,CAAC,CAAC;gBAC1D,OAAO,IAAI,CAAC,QAAQ,CAAC;YACvB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC,QAAQ,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAsB,CAAC,aAAa,CAAC,CAAC;gBAC1D,OAAO,IAAI,CAAC,QAAQ,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AAtBY,6BAA6B;IADzC,OAAO,CAAyB,sBAAsB,CAAC;GAC3C,6BAA6B,CAsBzC"}
1
+ {"version":3,"file":"state-management.service.js","sourceRoot":"","sources":["../../../src/services/state-management/state-management.service.ts"],"names":[],"mappings":";;;;;;AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAkCzD;;;;;;GAMG;AACH,SAAS,cAAc,CACrB,IAAsD,EACtD,QAAoD;IAEpD,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,sBAAsB;IAoBjC;;OAEG;IACH,YAAY,aAA6B;QAtBzC;;WAEG;QACM,gCAA2B,GAAW,uBAAuB,CAAC;QAEvE;;WAEG;QACM,uBAAkB,GAAW,aAAa,CAAC;QAEpD;;WAEG;QACM,6BAAwB,GAAW,oBAAoB,CAAC;QAEhD,wCAAmC,GAAW,iBAAiB,CAAC;QAQ/E,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACr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C,aAAa,EAAE,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAS,CAAC,MAAc;QAC5B,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACK,6BAA6B,CAAC,UAAkB;QACtD,4FAA4F;QAC5F,OAAO,GAAG,IAAI,CAAC,mCAAmC,GAAG,kBAAkB,CAAC,UAAU,CAAC,OAAO,CAAC;IAC7F,CAAC;CACF;AAED;;GAEG;AAEI,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IAGxC;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,aAA8B;QAChD,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,MAAM,IAAI,gBAAgB,CACxB,iCAAiC,sBAAsB,CAAC,IAAI,kCAAkC,CAC/F,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAsB,CAAC,aAAa,CAAC,CAAC;gBAC1D,OAAO,IAAI,CAAC,QAAQ,CAAC;YACvB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC,QAAQ,CAAC;YACvB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAsB,CAAC,aAAa,CAAC,CAAC;gBAC1D,OAAO,IAAI,CAAC,QAAQ,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AAzBY,6BAA6B;IADzC,OAAO,CAAyB,sBAAsB,CAAC;GAC3C,6BAA6B,CAyBzC"}
@@ -1,14 +1,68 @@
1
1
  /**
2
+ * Where Octo's state files live.
3
+ *
4
+ * Octo has no database - it records what it built in state files, and reads them back on the next run
5
+ * to work out the diff. A state provider is only asked to put a named blob somewhere and hand it back
6
+ * later, so implementing this interface is all it takes to keep state in S3, a database, or anywhere
7
+ * else your team already trusts.
8
+ *
9
+ * Pass one to {@link Octo.initialize}.
10
+ *
2
11
  * @group Services/State Management
12
+ *
13
+ * @see Techniques for [State Providers](/docs/techniques/state-providers).
3
14
  */
4
15
  export interface IStateProvider {
16
+ /**
17
+ * Deletes a state file. Deleting one that is not there is not an error.
18
+ */
19
+ deleteState(stateFileName: string): Promise<void>;
20
+ /**
21
+ * The id of the lock currently held, or `undefined` when the app is unlocked.
22
+ */
5
23
  getAppLock(): Promise<string | undefined>;
24
+ /**
25
+ * Reads a state file.
26
+ *
27
+ * @throws {@link TransactionError} With the message `No state found!` when the file does not exist.
28
+ * Octo treats that as a first run rather than an error.
29
+ */
6
30
  getState(stateFileName: string): Promise<Buffer>;
31
+ /**
32
+ * Whether `lockId` is the lock currently held.
33
+ *
34
+ * @throws {@link TransactionError} With the message `Invalid lock ID!` when a *different* lock is
35
+ * held, so a caller holding a stale id is told it is stale rather than told the app is free.
36
+ */
7
37
  isAppLocked(lockId: string): Promise<boolean>;
38
+ /**
39
+ * The names of the state files whose name starts with `prefix`, named as
40
+ * {@link IStateProvider.getState} would be given them.
41
+ *
42
+ * Octo reads state by name everywhere else, so this is the only way it can discover a file it was
43
+ * not told about - a record an interrupted run left behind. Returns an empty list when the store
44
+ * holds nothing matching, including when it does not exist yet.
45
+ */
46
+ listStates(prefix: string): Promise<string[]>;
47
+ /**
48
+ * Takes the app lock and returns its id, which `apply` and `commit` must then present.
49
+ *
50
+ * The lock is taken atomically, so of two callers racing for it exactly one wins.
51
+ *
52
+ * @throws {@link TransactionError} When a lock is held, naming the id that holds it.
53
+ */
8
54
  lockApp(): Promise<{
9
55
  lockId: string;
10
56
  }>;
57
+ /**
58
+ * Writes a state file, overwriting whatever was there.
59
+ */
11
60
  saveState(stateFileName: string, data: Buffer): Promise<void>;
61
+ /**
62
+ * Releases the app lock. Unlocking an app that is not locked is not an error.
63
+ *
64
+ * @throws {@link TransactionError} With the message `Invalid lock ID!` when a different lock is
65
+ * held, so one run can never release another's.
66
+ */
12
67
  unlockApp(lockId: string): Promise<void>;
13
- updateAppLockTransaction(lockId: string): Promise<void>;
14
68
  }
@@ -0,0 +1,76 @@
1
+ import { StateManagementService } from './state-management.service.js';
2
+ /**
3
+ * Moves each module folder's `terraform.tfstate` in and out of Octo's {@link IStateProvider}.
4
+ *
5
+ * Terraform's record of what exists is the one thing Octo cannot rebuild, and a local backend leaves
6
+ * it in the module folder where only the machine that ran the apply can see it. Checking it out
7
+ * before a terraform command and back in after puts it wherever Octo state already lives, so a team
8
+ * sharing Octo state shares terraform state with it.
9
+ *
10
+ * Check-in is frequent rather than atomic: it runs on every terraform command's return, success or
11
+ * failure, and on a timer through a long apply. A partial record of what exists beats none.
12
+ *
13
+ * {@link TerraformUtility} drives this around every command it runs, so nothing calls it directly.
14
+ *
15
+ * @internal
16
+ */
17
+ export declare class TerraformStateService {
18
+ private checkInQueue;
19
+ private periodicCheckIn;
20
+ private readonly stateManagementService;
21
+ /**
22
+ * @param stateManagementService Where terraform state is read from and written to.
23
+ */
24
+ constructor(stateManagementService: StateManagementService);
25
+ /**
26
+ * Writes every module folder's terraform state to the state provider.
27
+ *
28
+ * A folder holding no state file, or one recording no resources, has its state **deleted** rather
29
+ * than written - that is a module terraform has destroyed, and a file recording nothing is a file
30
+ * worth nobody's history.
31
+ *
32
+ * Check-ins are serialized, so the one on a command's return never races the one on the timer.
33
+ */
34
+ checkIn(terragruntDir: string, moduleIds: string[]): Promise<void>;
35
+ /**
36
+ * Writes the state provider's terraform state into every module folder.
37
+ *
38
+ * A module the provider holds nothing for keeps whatever its folder already has, which is what
39
+ * adopts the state of a stack that ran with a local backend until now. The check-in that follows
40
+ * hands that state to the provider, and from then on the provider is the one that answers.
41
+ */
42
+ checkOut(terragruntDir: string, moduleIds: string[]): Promise<void>;
43
+ /**
44
+ * Starts checking state in on a timer, bounding what a killed runner loses to one interval.
45
+ */
46
+ startPeriodicCheckIn(terragruntDir: string, moduleIds: string[]): void;
47
+ /**
48
+ * Stops the timer {@link TerraformStateService.startPeriodicCheckIn} started.
49
+ */
50
+ stopPeriodicCheckIn(): void;
51
+ /**
52
+ * Whether a terraform state file records nothing, which is what a destroyed module is left with.
53
+ * State that cannot be parsed is treated as holding resources, so an unreadable file is kept.
54
+ */
55
+ private holdsNoResources;
56
+ /**
57
+ * The name one module's terraform state is stored under, alongside Octo's own state files.
58
+ */
59
+ private stateFileName;
60
+ /**
61
+ * The body of a check-in, run one at a time through {@link TerraformStateService.checkIn}.
62
+ */
63
+ private writeStates;
64
+ }
65
+ /**
66
+ * @internal
67
+ */
68
+ export declare class TerraformStateServiceFactory {
69
+ /**
70
+ * Never cached: {@link Octo.initialize} builds a new {@link StateManagementService} around the
71
+ * provider it is given, and a cached instance would go on writing to the previous one.
72
+ *
73
+ * @internal
74
+ */
75
+ static create(): Promise<TerraformStateService>;
76
+ }