alchemy-effect 0.2.0 → 0.3.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 (428) hide show
  1. package/bin/alchemy-effect.js +55038 -8
  2. package/bin/alchemy-effect.js.map +1 -1
  3. package/bin/alchemy-effect.ts +266 -10
  4. package/lib/$.d.ts +5 -0
  5. package/lib/$.d.ts.map +1 -0
  6. package/lib/$.js +9 -0
  7. package/lib/$.js.map +1 -0
  8. package/lib/app.d.ts +4 -17
  9. package/lib/app.d.ts.map +1 -1
  10. package/lib/app.js +0 -20
  11. package/lib/app.js.map +1 -1
  12. package/lib/apply.d.ts +14 -74
  13. package/lib/apply.d.ts.map +1 -1
  14. package/lib/apply.js +62 -57
  15. package/lib/apply.js.map +1 -1
  16. package/lib/assert-never.d.ts +12 -0
  17. package/lib/assert-never.d.ts.map +1 -0
  18. package/lib/assert-never.js +11 -0
  19. package/lib/assert-never.js.map +1 -0
  20. package/lib/aws/account.d.ts +10 -1
  21. package/lib/aws/account.d.ts.map +1 -1
  22. package/lib/aws/account.js +18 -3
  23. package/lib/aws/account.js.map +1 -1
  24. package/lib/aws/client.d.ts.map +1 -1
  25. package/lib/aws/client.js +0 -1
  26. package/lib/aws/client.js.map +1 -1
  27. package/lib/aws/config.d.ts +15 -0
  28. package/lib/aws/config.d.ts.map +1 -0
  29. package/lib/aws/config.js +1 -0
  30. package/lib/aws/config.js.map +1 -0
  31. package/lib/aws/credentials.d.ts +10 -0
  32. package/lib/aws/credentials.d.ts.map +1 -1
  33. package/lib/aws/credentials.js +73 -47
  34. package/lib/aws/credentials.js.map +1 -1
  35. package/lib/aws/dynamodb/client.d.ts +1 -1
  36. package/lib/aws/dynamodb/client.d.ts.map +1 -1
  37. package/lib/aws/dynamodb/index.d.ts +2 -1
  38. package/lib/aws/dynamodb/index.d.ts.map +1 -1
  39. package/lib/aws/dynamodb/index.js +1 -2
  40. package/lib/aws/dynamodb/index.js.map +1 -1
  41. package/lib/aws/dynamodb/secondary-index.d.ts +5 -4
  42. package/lib/aws/dynamodb/secondary-index.d.ts.map +1 -1
  43. package/lib/aws/dynamodb/table.d.ts +23 -20
  44. package/lib/aws/dynamodb/table.d.ts.map +1 -1
  45. package/lib/aws/dynamodb/table.get-item.d.ts +8 -6
  46. package/lib/aws/dynamodb/table.get-item.d.ts.map +1 -1
  47. package/lib/aws/dynamodb/table.get-item.js +4 -2
  48. package/lib/aws/dynamodb/table.get-item.js.map +1 -1
  49. package/lib/aws/dynamodb/table.js.map +1 -1
  50. package/lib/aws/dynamodb/table.provider.d.ts +3 -4
  51. package/lib/aws/dynamodb/table.provider.d.ts.map +1 -1
  52. package/lib/aws/dynamodb/table.provider.js +17 -29
  53. package/lib/aws/dynamodb/table.provider.js.map +1 -1
  54. package/lib/aws/ec2/client.d.ts +1 -1
  55. package/lib/aws/ec2/client.d.ts.map +1 -1
  56. package/lib/aws/ec2/index.d.ts +3 -0
  57. package/lib/aws/ec2/index.d.ts.map +1 -1
  58. package/lib/aws/ec2/index.js +3 -0
  59. package/lib/aws/ec2/index.js.map +1 -1
  60. package/lib/aws/ec2/subnet.d.ts +175 -0
  61. package/lib/aws/ec2/subnet.d.ts.map +1 -0
  62. package/lib/aws/ec2/subnet.js +4 -0
  63. package/lib/aws/ec2/subnet.js.map +1 -0
  64. package/lib/aws/ec2/subnet.provider.d.ts +4 -0
  65. package/lib/aws/ec2/subnet.provider.d.ts.map +1 -0
  66. package/lib/aws/ec2/subnet.provider.js +250 -0
  67. package/lib/aws/ec2/subnet.provider.js.map +1 -0
  68. package/lib/aws/ec2/vpc.d.ts +12 -8
  69. package/lib/aws/ec2/vpc.d.ts.map +1 -1
  70. package/lib/aws/ec2/vpc.js +1 -0
  71. package/lib/aws/ec2/vpc.js.map +1 -1
  72. package/lib/aws/ec2/vpc.provider.d.ts +3 -4
  73. package/lib/aws/ec2/vpc.provider.d.ts.map +1 -1
  74. package/lib/aws/ec2/vpc.provider.js +11 -26
  75. package/lib/aws/ec2/vpc.provider.js.map +1 -1
  76. package/lib/aws/index.d.ts +16 -19
  77. package/lib/aws/index.d.ts.map +1 -1
  78. package/lib/aws/index.js +7 -10
  79. package/lib/aws/index.js.map +1 -1
  80. package/lib/aws/lambda/consume.d.ts +10 -11
  81. package/lib/aws/lambda/consume.d.ts.map +1 -1
  82. package/lib/aws/lambda/consume.js +3 -3
  83. package/lib/aws/lambda/consume.js.map +1 -1
  84. package/lib/aws/lambda/function.d.ts +7 -7
  85. package/lib/aws/lambda/function.d.ts.map +1 -1
  86. package/lib/aws/lambda/function.handler.d.ts +1 -1
  87. package/lib/aws/lambda/function.handler.d.ts.map +1 -1
  88. package/lib/aws/lambda/function.handler.js.map +1 -1
  89. package/lib/aws/lambda/function.invoke.d.ts +6 -4
  90. package/lib/aws/lambda/function.invoke.d.ts.map +1 -1
  91. package/lib/aws/lambda/function.invoke.js +3 -1
  92. package/lib/aws/lambda/function.invoke.js.map +1 -1
  93. package/lib/aws/lambda/function.js +1 -1
  94. package/lib/aws/lambda/function.js.map +1 -1
  95. package/lib/aws/lambda/function.provider.d.ts +5 -4
  96. package/lib/aws/lambda/function.provider.d.ts.map +1 -1
  97. package/lib/aws/lambda/function.provider.js +16 -14
  98. package/lib/aws/lambda/function.provider.js.map +1 -1
  99. package/lib/aws/lambda/index.d.ts +1 -0
  100. package/lib/aws/lambda/index.d.ts.map +1 -1
  101. package/lib/aws/lambda/index.js +1 -0
  102. package/lib/aws/lambda/index.js.map +1 -1
  103. package/lib/aws/lambda/serve.d.ts +2 -4
  104. package/lib/aws/lambda/serve.d.ts.map +1 -1
  105. package/lib/aws/profile.d.ts +2 -2
  106. package/lib/aws/profile.d.ts.map +1 -1
  107. package/lib/aws/profile.js +1 -1
  108. package/lib/aws/profile.js.map +1 -1
  109. package/lib/aws/region.d.ts +14 -2
  110. package/lib/aws/region.d.ts.map +1 -1
  111. package/lib/aws/region.js +26 -1
  112. package/lib/aws/region.js.map +1 -1
  113. package/lib/aws/sqs/client.d.ts +1 -1
  114. package/lib/aws/sqs/client.d.ts.map +1 -1
  115. package/lib/aws/sqs/index.d.ts +1 -0
  116. package/lib/aws/sqs/index.d.ts.map +1 -1
  117. package/lib/aws/sqs/index.js +1 -0
  118. package/lib/aws/sqs/index.js.map +1 -1
  119. package/lib/aws/sqs/queue.consume.d.ts +1 -1
  120. package/lib/aws/sqs/queue.consume.d.ts.map +1 -1
  121. package/lib/aws/sqs/queue.consume.js +0 -1
  122. package/lib/aws/sqs/queue.consume.js.map +1 -1
  123. package/lib/aws/sqs/queue.d.ts +6 -4
  124. package/lib/aws/sqs/queue.d.ts.map +1 -1
  125. package/lib/aws/sqs/queue.event-source.d.ts +8 -6
  126. package/lib/aws/sqs/queue.event-source.d.ts.map +1 -1
  127. package/lib/aws/sqs/queue.event-source.js +26 -44
  128. package/lib/aws/sqs/queue.event-source.js.map +1 -1
  129. package/lib/aws/sqs/queue.js +1 -1
  130. package/lib/aws/sqs/queue.js.map +1 -1
  131. package/lib/aws/sqs/queue.provider.d.ts +4 -4
  132. package/lib/aws/sqs/queue.provider.d.ts.map +1 -1
  133. package/lib/aws/sqs/queue.provider.js +3 -3
  134. package/lib/aws/sqs/queue.provider.js.map +1 -1
  135. package/lib/aws/sqs/queue.send-message.d.ts +7 -5
  136. package/lib/aws/sqs/queue.send-message.d.ts.map +1 -1
  137. package/lib/aws/sqs/queue.send-message.js +4 -2
  138. package/lib/aws/sqs/queue.send-message.js.map +1 -1
  139. package/lib/binding.d.ts +12 -12
  140. package/lib/binding.d.ts.map +1 -1
  141. package/lib/binding.js.map +1 -1
  142. package/lib/cli/components/ApprovePlan.d.ts +2 -2
  143. package/lib/cli/components/ApprovePlan.d.ts.map +1 -1
  144. package/lib/cli/components/ApprovePlan.js.map +1 -1
  145. package/lib/cli/components/Plan.d.ts +2 -2
  146. package/lib/cli/components/Plan.d.ts.map +1 -1
  147. package/lib/cli/components/Plan.js.map +1 -1
  148. package/lib/cli/components/PlanProgress.d.ts +8 -4
  149. package/lib/cli/components/PlanProgress.d.ts.map +1 -1
  150. package/lib/cli/components/PlanProgress.js +11 -1
  151. package/lib/cli/components/PlanProgress.js.map +1 -1
  152. package/lib/cli/index.d.ts +265 -224
  153. package/lib/cli/index.d.ts.map +1 -1
  154. package/lib/cli/index.js +57 -65
  155. package/lib/cli/index.js.map +1 -1
  156. package/lib/cli/ink-service.d.ts +4 -0
  157. package/lib/cli/ink-service.d.ts.map +1 -0
  158. package/lib/cli/ink-service.js +43 -0
  159. package/lib/cli/ink-service.js.map +1 -0
  160. package/lib/cli/service.d.ts +21 -0
  161. package/lib/cli/service.d.ts.map +1 -0
  162. package/lib/cli/service.js +5 -0
  163. package/lib/cli/service.js.map +1 -0
  164. package/lib/cloudflare/account.d.ts +10 -0
  165. package/lib/cloudflare/account.d.ts.map +1 -0
  166. package/lib/cloudflare/account.js +24 -0
  167. package/lib/cloudflare/account.js.map +1 -0
  168. package/lib/cloudflare/api.d.ts +7 -7
  169. package/lib/cloudflare/api.d.ts.map +1 -1
  170. package/lib/cloudflare/api.js +18 -17
  171. package/lib/cloudflare/api.js.map +1 -1
  172. package/lib/cloudflare/config.d.ts +9 -0
  173. package/lib/cloudflare/config.d.ts.map +1 -0
  174. package/lib/cloudflare/config.js +1 -0
  175. package/lib/cloudflare/config.js.map +1 -0
  176. package/lib/cloudflare/index.d.ts +3 -1
  177. package/lib/cloudflare/index.d.ts.map +1 -1
  178. package/lib/cloudflare/index.js +3 -0
  179. package/lib/cloudflare/index.js.map +1 -1
  180. package/lib/cloudflare/kv/namespace.binding.d.ts +5 -3
  181. package/lib/cloudflare/kv/namespace.binding.d.ts.map +1 -1
  182. package/lib/cloudflare/kv/namespace.binding.js +1 -1
  183. package/lib/cloudflare/kv/namespace.binding.js.map +1 -1
  184. package/lib/cloudflare/kv/namespace.d.ts +3 -2
  185. package/lib/cloudflare/kv/namespace.d.ts.map +1 -1
  186. package/lib/cloudflare/kv/namespace.js.map +1 -1
  187. package/lib/cloudflare/kv/namespace.provider.d.ts +3 -2
  188. package/lib/cloudflare/kv/namespace.provider.d.ts.map +1 -1
  189. package/lib/cloudflare/kv/namespace.provider.js +8 -7
  190. package/lib/cloudflare/kv/namespace.provider.js.map +1 -1
  191. package/lib/cloudflare/live.d.ts +5 -5
  192. package/lib/cloudflare/live.d.ts.map +1 -1
  193. package/lib/cloudflare/live.js +5 -8
  194. package/lib/cloudflare/live.js.map +1 -1
  195. package/lib/cloudflare/r2/bucket.binding.d.ts +5 -3
  196. package/lib/cloudflare/r2/bucket.binding.d.ts.map +1 -1
  197. package/lib/cloudflare/r2/bucket.binding.js +1 -1
  198. package/lib/cloudflare/r2/bucket.binding.js.map +1 -1
  199. package/lib/cloudflare/r2/bucket.d.ts +3 -2
  200. package/lib/cloudflare/r2/bucket.d.ts.map +1 -1
  201. package/lib/cloudflare/r2/bucket.js.map +1 -1
  202. package/lib/cloudflare/r2/bucket.provider.d.ts +3 -2
  203. package/lib/cloudflare/r2/bucket.provider.d.ts.map +1 -1
  204. package/lib/cloudflare/r2/bucket.provider.js +8 -7
  205. package/lib/cloudflare/r2/bucket.provider.js.map +1 -1
  206. package/lib/cloudflare/worker/assets.fetch.d.ts +3 -2
  207. package/lib/cloudflare/worker/assets.fetch.d.ts.map +1 -1
  208. package/lib/cloudflare/worker/assets.fetch.js +2 -1
  209. package/lib/cloudflare/worker/assets.fetch.js.map +1 -1
  210. package/lib/cloudflare/worker/assets.provider.d.ts +1 -1
  211. package/lib/cloudflare/worker/assets.provider.d.ts.map +1 -1
  212. package/lib/cloudflare/worker/index.d.ts +0 -1
  213. package/lib/cloudflare/worker/index.d.ts.map +1 -1
  214. package/lib/cloudflare/worker/worker.d.ts +5 -6
  215. package/lib/cloudflare/worker/worker.d.ts.map +1 -1
  216. package/lib/cloudflare/worker/worker.handler.d.ts +1 -1
  217. package/lib/cloudflare/worker/worker.handler.d.ts.map +1 -1
  218. package/lib/cloudflare/worker/worker.handler.js.map +1 -1
  219. package/lib/cloudflare/worker/worker.js.map +1 -1
  220. package/lib/cloudflare/worker/worker.provider.d.ts +3 -2
  221. package/lib/cloudflare/worker/worker.provider.d.ts.map +1 -1
  222. package/lib/cloudflare/worker/worker.provider.js +7 -6
  223. package/lib/cloudflare/worker/worker.provider.js.map +1 -1
  224. package/lib/cloudflare/worker/worker.serve.d.ts +7 -7
  225. package/lib/cloudflare/worker/worker.serve.d.ts.map +1 -1
  226. package/lib/cloudflare/worker/worker.serve.js.map +1 -1
  227. package/lib/data.d.ts +3 -0
  228. package/lib/data.d.ts.map +1 -0
  229. package/lib/data.js +8 -0
  230. package/lib/data.js.map +1 -0
  231. package/lib/destroy.d.ts +1 -1
  232. package/lib/destroy.d.ts.map +1 -1
  233. package/lib/destroy.js +1 -4
  234. package/lib/destroy.js.map +1 -1
  235. package/lib/diff.d.ts +16 -0
  236. package/lib/diff.d.ts.map +1 -0
  237. package/lib/diff.js +9 -0
  238. package/lib/diff.js.map +1 -0
  239. package/lib/env.d.ts +5 -0
  240. package/lib/env.d.ts.map +1 -1
  241. package/lib/env.js +15 -29
  242. package/lib/env.js.map +1 -1
  243. package/lib/exports.d.ts +9 -0
  244. package/lib/exports.d.ts.map +1 -0
  245. package/lib/exports.js +13 -0
  246. package/lib/exports.js.map +1 -0
  247. package/lib/index.d.ts +10 -2
  248. package/lib/index.d.ts.map +1 -1
  249. package/lib/index.js +10 -5
  250. package/lib/index.js.map +1 -1
  251. package/lib/input.d.ts +32 -0
  252. package/lib/input.d.ts.map +1 -0
  253. package/lib/input.js +1 -0
  254. package/lib/input.js.map +1 -0
  255. package/lib/output.d.ts +143 -0
  256. package/lib/output.d.ts.map +1 -0
  257. package/lib/output.js +269 -0
  258. package/lib/output.js.map +1 -0
  259. package/lib/plan.d.ts +47 -28
  260. package/lib/plan.d.ts.map +1 -1
  261. package/lib/plan.js +257 -151
  262. package/lib/plan.js.map +1 -1
  263. package/lib/policy.d.ts +3 -4
  264. package/lib/policy.d.ts.map +1 -1
  265. package/lib/policy.js +0 -1
  266. package/lib/policy.js.map +1 -1
  267. package/lib/provider.d.ts +14 -16
  268. package/lib/provider.d.ts.map +1 -1
  269. package/lib/ref.d.ts +14 -0
  270. package/lib/ref.d.ts.map +1 -0
  271. package/lib/ref.js +21 -0
  272. package/lib/ref.js.map +1 -0
  273. package/lib/resource.d.ts +11 -6
  274. package/lib/resource.d.ts.map +1 -1
  275. package/lib/resource.js.map +1 -1
  276. package/lib/runtime.d.ts +7 -6
  277. package/lib/runtime.d.ts.map +1 -1
  278. package/lib/runtime.js.map +1 -1
  279. package/lib/service.d.ts +9 -6
  280. package/lib/service.d.ts.map +1 -1
  281. package/lib/service.js.map +1 -1
  282. package/lib/stack.d.ts +60 -0
  283. package/lib/stack.d.ts.map +1 -0
  284. package/lib/stack.js +11 -0
  285. package/lib/stack.js.map +1 -0
  286. package/lib/stage.d.ts +39 -0
  287. package/lib/stage.d.ts.map +1 -0
  288. package/lib/stage.js +32 -0
  289. package/lib/stage.js.map +1 -0
  290. package/lib/state.d.ts +51 -10
  291. package/lib/state.d.ts.map +1 -1
  292. package/lib/state.js +30 -29
  293. package/lib/state.js.map +1 -1
  294. package/lib/test.d.ts +25 -4
  295. package/lib/test.d.ts.map +1 -1
  296. package/lib/test.js +54 -14
  297. package/lib/test.js.map +1 -1
  298. package/lib/tsconfig.test.tsbuildinfo +1 -1
  299. package/lib/type.d.ts +3 -0
  300. package/lib/type.d.ts.map +1 -1
  301. package/lib/unknown.d.ts +4 -0
  302. package/lib/unknown.d.ts.map +1 -0
  303. package/lib/unknown.js +4 -0
  304. package/lib/unknown.js.map +1 -0
  305. package/lib/user.d.ts +3 -0
  306. package/lib/user.d.ts.map +1 -0
  307. package/lib/user.js +3 -0
  308. package/lib/user.js.map +1 -0
  309. package/lib/util.d.ts +6 -0
  310. package/lib/util.d.ts.map +1 -0
  311. package/lib/util.js +9 -0
  312. package/lib/util.js.map +1 -0
  313. package/package.json +18 -12
  314. package/src/$.ts +17 -0
  315. package/src/app.ts +3 -32
  316. package/src/apply.ts +429 -441
  317. package/src/assert-never.ts +18 -0
  318. package/src/aws/account.ts +23 -3
  319. package/src/aws/client.ts +0 -1
  320. package/src/aws/config.ts +16 -0
  321. package/src/aws/credentials.ts +212 -177
  322. package/src/aws/dynamodb/index.ts +3 -3
  323. package/src/aws/dynamodb/table.get-item.ts +5 -9
  324. package/src/aws/dynamodb/table.provider.ts +35 -39
  325. package/src/aws/dynamodb/table.ts +29 -84
  326. package/src/aws/ec2/index.ts +4 -0
  327. package/src/aws/ec2/subnet.provider.ts +358 -0
  328. package/src/aws/ec2/subnet.ts +213 -0
  329. package/src/aws/ec2/vpc.provider.ts +20 -36
  330. package/src/aws/ec2/vpc.ts +19 -8
  331. package/src/aws/index.ts +46 -40
  332. package/src/aws/lambda/consume.ts +8 -7
  333. package/src/aws/lambda/function.handler.ts +1 -1
  334. package/src/aws/lambda/function.invoke.ts +6 -2
  335. package/src/aws/lambda/function.provider.ts +28 -21
  336. package/src/aws/lambda/function.ts +7 -4
  337. package/src/aws/lambda/index.ts +2 -0
  338. package/src/aws/profile.ts +1 -4
  339. package/src/aws/region.ts +42 -3
  340. package/src/aws/sqs/index.ts +2 -0
  341. package/src/aws/sqs/queue.consume.ts +1 -1
  342. package/src/aws/sqs/queue.event-source.ts +29 -55
  343. package/src/aws/sqs/queue.provider.ts +11 -4
  344. package/src/aws/sqs/queue.send-message.ts +5 -8
  345. package/src/aws/sqs/queue.ts +9 -4
  346. package/src/binding.ts +19 -19
  347. package/src/cli/components/ApprovePlan.tsx +2 -2
  348. package/src/cli/components/Plan.tsx +3 -2
  349. package/src/cli/components/PlanProgress.tsx +32 -14
  350. package/src/cli/index.ts +2 -6
  351. package/src/cli/ink-service.tsx +61 -0
  352. package/src/cli/service.ts +23 -0
  353. package/src/cloudflare/account.ts +37 -0
  354. package/src/cloudflare/api.ts +33 -29
  355. package/src/cloudflare/config.ts +7 -0
  356. package/src/cloudflare/index.ts +3 -1
  357. package/src/cloudflare/kv/namespace.binding.ts +3 -1
  358. package/src/cloudflare/kv/namespace.provider.ts +9 -8
  359. package/src/cloudflare/kv/namespace.ts +3 -2
  360. package/src/cloudflare/live.ts +11 -17
  361. package/src/cloudflare/r2/bucket.binding.ts +3 -1
  362. package/src/cloudflare/r2/bucket.provider.ts +9 -8
  363. package/src/cloudflare/r2/bucket.ts +8 -2
  364. package/src/cloudflare/worker/assets.fetch.ts +3 -1
  365. package/src/cloudflare/worker/assets.provider.ts +1 -1
  366. package/src/cloudflare/worker/index.ts +0 -2
  367. package/src/cloudflare/worker/worker.handler.ts +1 -1
  368. package/src/cloudflare/worker/worker.provider.ts +16 -13
  369. package/src/cloudflare/worker/worker.serve.ts +5 -2
  370. package/src/cloudflare/worker/worker.ts +4 -3
  371. package/src/data.ts +18 -0
  372. package/src/destroy.ts +1 -5
  373. package/src/diff.ts +30 -0
  374. package/src/env.ts +20 -32
  375. package/src/exports.ts +21 -0
  376. package/src/index.ts +10 -5
  377. package/src/input.ts +81 -0
  378. package/src/output.ts +518 -0
  379. package/src/plan.ts +380 -192
  380. package/src/policy.ts +3 -5
  381. package/src/provider.ts +25 -23
  382. package/src/ref.ts +48 -0
  383. package/src/resource.ts +20 -6
  384. package/src/runtime.ts +15 -8
  385. package/src/service.ts +11 -7
  386. package/src/stack.ts +116 -0
  387. package/src/stage.ts +85 -0
  388. package/src/state.ts +138 -60
  389. package/src/test.ts +117 -16
  390. package/src/type.ts +4 -0
  391. package/src/unknown.ts +6 -0
  392. package/src/user.ts +4 -0
  393. package/src/util.ts +21 -0
  394. package/lib/approve.d.ts +0 -15
  395. package/lib/approve.d.ts.map +0 -1
  396. package/lib/approve.js +0 -7
  397. package/lib/approve.js.map +0 -1
  398. package/lib/cli/approve.d.ts +0 -4
  399. package/lib/cli/approve.d.ts.map +0 -1
  400. package/lib/cli/approve.js +0 -18
  401. package/lib/cli/approve.js.map +0 -1
  402. package/lib/cli/clack.d.ts +0 -14
  403. package/lib/cli/clack.d.ts.map +0 -1
  404. package/lib/cli/clack.js +0 -12
  405. package/lib/cli/clack.js.map +0 -1
  406. package/lib/cli/main.d.ts +0 -2
  407. package/lib/cli/main.d.ts.map +0 -1
  408. package/lib/cli/main.js +0 -1
  409. package/lib/cli/main.js.map +0 -1
  410. package/lib/cli/plan.d.ts +0 -13
  411. package/lib/cli/plan.d.ts.map +0 -1
  412. package/lib/cli/plan.js +0 -1
  413. package/lib/cli/plan.js.map +0 -1
  414. package/lib/cli/progress.d.ts +0 -7
  415. package/lib/cli/progress.d.ts.map +0 -1
  416. package/lib/cli/progress.js +0 -30
  417. package/lib/cli/progress.js.map +0 -1
  418. package/lib/cli/spinner.d.ts +0 -2
  419. package/lib/cli/spinner.d.ts.map +0 -1
  420. package/lib/cli/spinner.js +0 -13
  421. package/lib/cli/spinner.js.map +0 -1
  422. package/src/approve.ts +0 -13
  423. package/src/cli/approve.tsx +0 -30
  424. package/src/cli/clack.ts +0 -22
  425. package/src/cli/main.ts +0 -0
  426. package/src/cli/plan.ts +0 -16
  427. package/src/cli/progress.tsx +0 -46
  428. package/src/cli/spinner.ts +0 -14
package/src/apply.ts CHANGED
@@ -1,476 +1,464 @@
1
1
  import * as Context from "effect/Context";
2
2
  import * as Effect from "effect/Effect";
3
- import * as Option from "effect/Option";
4
3
  import type { Simplify } from "effect/Types";
5
- import { PlanReviewer, type PlanRejected } from "./approve.ts";
6
4
  import type { AnyBinding, BindingService } from "./binding.ts";
7
- import type { ApplyEvent, ApplyStatus } from "./event.ts";
5
+ import type { ApplyStatus } from "./event.ts";
6
+ import * as Output from "./output.ts";
8
7
  import {
9
8
  plan,
10
9
  type BindNode,
11
10
  type Create,
12
11
  type CRUD,
13
12
  type Delete,
14
- type Plan,
13
+ type DerivePlan,
14
+ type IPlan,
15
+ type Providers,
15
16
  type Update,
16
17
  } from "./plan.ts";
17
- import type { Resource } from "./resource.ts";
18
- import type { Service } from "./service.ts";
18
+ import type { Instance } from "./policy.ts";
19
+ import type { AnyResource, Resource } from "./resource.ts";
20
+ import type { AnyService } from "./service.ts";
19
21
  import { State } from "./state.ts";
20
-
21
- export interface PlanStatusSession {
22
- emit: (event: ApplyEvent) => Effect.Effect<void>;
23
- done: () => Effect.Effect<void>;
24
- }
25
-
26
- export interface ScopedPlanStatusSession extends PlanStatusSession {
27
- note: (note: string) => Effect.Effect<void>;
28
- }
29
-
30
- export class PlanStatusReporter extends Context.Tag("PlanStatusReporter")<
31
- PlanStatusReporter,
22
+ import { App } from "./app.ts";
23
+ import { asEffect } from "./util.ts";
24
+ import { type ScopedPlanStatusSession, CLI } from "./cli/service.ts";
25
+
26
+ export type ApplyEffect<
27
+ P extends IPlan,
28
+ Err = never,
29
+ Req = never,
30
+ > = Effect.Effect<
32
31
  {
33
- start(plan: Plan): Effect.Effect<PlanStatusSession, never>;
34
- }
35
- >() {}
36
-
37
- export const apply: typeof applyPlan &
38
- typeof applyResources &
39
- typeof applyResourcesPhase = (...args: any[]): any =>
40
- Effect.isEffect(args[0])
41
- ? applyPlan(args[0] as any)
42
- : args.length === 1 && "phase" in args[0]
43
- ? applyResourcesPhase(args[0])
44
- : applyResources(...args);
45
-
46
- export const applyResourcesPhase = <
47
- const Phase extends "update" | "destroy",
48
- const Resources extends (Service | Resource)[],
49
- >(props: {
50
- resources: Resources;
51
- phase: Phase;
52
- }) => applyPlan(plan(props));
53
-
54
- export const applyResources = <const Resources extends (Service | Resource)[]>(
32
+ [k in keyof AppliedPlan<P>]: AppliedPlan<P>[k];
33
+ },
34
+ Err,
35
+ Req
36
+ >;
37
+
38
+ export type AppliedPlan<P extends IPlan> = {
39
+ [id in keyof P["resources"]]: P["resources"][id] extends
40
+ | Delete<Resource>
41
+ | undefined
42
+ | never
43
+ ? never
44
+ : Simplify<P["resources"][id]["resource"]["attr"]>;
45
+ };
46
+
47
+ export const apply = <
48
+ const Resources extends (AnyService | AnyResource)[] = never,
49
+ >(
55
50
  ...resources: Resources
56
- ) =>
57
- applyPlan(
58
- plan({
59
- phase: "update",
60
- resources,
61
- }),
62
- );
63
-
64
- export const applyPlan = <P extends Plan, Err, Req>(
65
- plan: Effect.Effect<P, Err, Req>,
66
- ) =>
67
- plan.pipe(
68
- Effect.flatMap((plan) =>
69
- Effect.gen(function* () {
70
- const state = yield* State;
71
- const outputs = {} as Record<string, Effect.Effect<any, any>>;
72
- const reviewer = yield* Effect.serviceOption(PlanReviewer);
73
-
74
- if (Option.isSome(reviewer)) {
75
- yield* reviewer.value.approve(plan);
76
- }
77
-
78
- const events = yield* Effect.serviceOption(PlanStatusReporter);
79
-
80
- const session = Option.isSome(events)
81
- ? yield* events.value.start(plan)
82
- : ({
83
- emit: () => Effect.void,
84
- done: () => Effect.void,
85
- } satisfies PlanStatusSession);
86
- const { emit, done } = session;
87
-
88
- const constOrEffect = <T, Err = never, Req = never>(
89
- effect: T | Effect.Effect<T>,
90
- ): Effect.Effect<T, Err, Req> =>
91
- Effect.isEffect(effect) ? effect : Effect.succeed(effect);
92
-
93
- const resolveBindingUpstream = Effect.fn(function* ({
94
- node,
95
- resource,
96
- }: {
97
- node: BindNode;
98
- resource: Resource;
99
- }) {
100
- const binding = node.binding as AnyBinding & {
101
- // smuggled property (because it interacts poorly with inference)
102
- Tag: Context.Tag<never, BindingService>;
103
- };
104
- const provider = yield* binding.Tag;
105
-
106
- const resourceId: string = node.binding.capability.resource.id;
107
- const upstreamNode = plan.resources[resourceId];
108
- const upstreamAttr = resource
109
- ? yield* apply(upstreamNode)
110
- : yield* Effect.dieMessage(`Resource ${resourceId} not found`);
111
-
112
- return {
113
- resourceId,
114
- upstreamAttr,
115
- upstreamNode,
116
- provider,
117
- };
118
- });
119
-
120
- const attachBindings = ({
121
- resource,
122
- bindings,
123
- target,
124
- }: {
125
- resource: Resource;
126
- bindings: BindNode[];
127
- target: {
128
- id: string;
129
- props: any;
130
- attr: any;
131
- };
132
- }) =>
133
- Effect.all(
134
- bindings.map(
135
- Effect.fn(function* (node) {
136
- const { resourceId, upstreamAttr, upstreamNode, provider } =
137
- yield* resolveBindingUpstream({ node, resource });
138
-
139
- const input = {
51
+ ): ApplyEffect<
52
+ DerivePlan<Instance<Resources[number]>>,
53
+ never,
54
+ State | Providers<Instance<Resources[number]>>
55
+ // TODO(sam): don't cast to any
56
+ > => plan(...resources).pipe(Effect.flatMap(applyPlan)) as any;
57
+
58
+ export const applyPlan = <P extends IPlan>(plan: P) =>
59
+ Effect.gen(function* () {
60
+ const state = yield* State;
61
+ // TODO(sam): rename terminology to Stack
62
+ const app = yield* App;
63
+ const outputs = {} as Record<string, Effect.Effect<any, any, State>>;
64
+
65
+ const cli = yield* CLI;
66
+
67
+ const session = yield* cli.startApplySession(plan);
68
+ const { emit, done } = session;
69
+
70
+ const resolveUpstream = Effect.fn(function* (resourceId: string) {
71
+ const upstreamNode = plan.resources[resourceId];
72
+ const upstreamAttr = upstreamNode
73
+ ? yield* apply(upstreamNode)
74
+ : yield* Effect.dieMessage(`Resource ${resourceId} not found`);
75
+ return {
76
+ resourceId,
77
+ upstreamAttr,
78
+ upstreamNode,
79
+ };
80
+ });
81
+
82
+ const resolveBindingUpstream = Effect.fn(function* ({
83
+ node,
84
+ }: {
85
+ node: BindNode;
86
+ resource: Resource;
87
+ }) {
88
+ const binding = node.binding as AnyBinding & {
89
+ // smuggled property (because it interacts poorly with inference)
90
+ Tag: Context.Tag<never, BindingService>;
91
+ };
92
+ const provider = yield* binding.Tag;
93
+
94
+ const resourceId: string = node.binding.capability.resource.id;
95
+ const { upstreamAttr, upstreamNode } = yield* resolveUpstream(resourceId);
96
+
97
+ return {
98
+ resourceId,
99
+ upstreamAttr,
100
+ upstreamNode,
101
+ provider,
102
+ };
103
+ });
104
+
105
+ const attachBindings = ({
106
+ resource,
107
+ bindings,
108
+ target,
109
+ }: {
110
+ resource: Resource;
111
+ bindings: BindNode[];
112
+ target: {
113
+ id: string;
114
+ props: any;
115
+ attr: any;
116
+ };
117
+ }) =>
118
+ Effect.all(
119
+ bindings.map(
120
+ Effect.fn(function* (node) {
121
+ const { resourceId, upstreamAttr, upstreamNode, provider } =
122
+ yield* resolveBindingUpstream({ node, resource });
123
+
124
+ const input = {
125
+ source: {
126
+ id: resourceId,
127
+ attr: upstreamAttr,
128
+ props: upstreamNode.resource.props,
129
+ },
130
+ props: node.binding.props,
131
+ attr: node.attr,
132
+ target,
133
+ } as const;
134
+ if (node.action === "attach") {
135
+ return yield* asEffect(provider.attach(input));
136
+ } else if (node.action === "reattach") {
137
+ // reattach is optional, we fall back to attach if it's not available
138
+ return yield* asEffect(
139
+ (provider.reattach ? provider.reattach : provider.attach)(
140
+ input,
141
+ ),
142
+ );
143
+ } else if (node.action === "detach" && provider.detach) {
144
+ return yield* asEffect(
145
+ provider.detach({
146
+ ...input,
147
+ target,
148
+ }),
149
+ );
150
+ }
151
+ return node.attr;
152
+ }),
153
+ ),
154
+ );
155
+
156
+ const postAttachBindings = ({
157
+ bindings,
158
+ bindingOutputs,
159
+ resource,
160
+ target,
161
+ }: {
162
+ bindings: BindNode[];
163
+ bindingOutputs: any[];
164
+ resource: Resource;
165
+ target: {
166
+ id: string;
167
+ props: any;
168
+ attr: any;
169
+ };
170
+ }) =>
171
+ Effect.all(
172
+ bindings.map(
173
+ Effect.fn(function* (node, i) {
174
+ const { resourceId, upstreamAttr, upstreamNode, provider } =
175
+ yield* resolveBindingUpstream({ node, resource });
176
+
177
+ const oldBindingOutput = bindingOutputs[i];
178
+
179
+ if (
180
+ provider.postattach &&
181
+ (node.action === "attach" || node.action === "reattach")
182
+ ) {
183
+ const bindingOutput = yield* asEffect(
184
+ provider.postattach({
140
185
  source: {
141
186
  id: resourceId,
142
187
  attr: upstreamAttr,
143
188
  props: upstreamNode.resource.props,
144
189
  },
145
190
  props: node.binding.props,
146
- attr: node.attr,
191
+ attr: oldBindingOutput,
147
192
  target,
148
- } as const;
149
- if (node.action === "attach") {
150
- return yield* constOrEffect(provider.attach(input));
151
- } else if (node.action === "reattach") {
152
- // reattach is optional, we fall back to attach if it's not available
153
- return yield* constOrEffect(
154
- (provider.reattach ? provider.reattach : provider.attach)(
155
- input,
156
- ),
157
- );
158
- } else if (node.action === "detach" && provider.detach) {
159
- return yield* constOrEffect(
160
- provider.detach({
161
- ...input,
162
- target,
163
- }),
164
- );
165
- }
166
- return node.attr;
167
- }),
168
- ),
169
- );
170
-
171
- const postAttachBindings = ({
172
- bindings,
173
- bindingOutputs,
174
- resource,
175
- target,
193
+ } as const),
194
+ );
195
+ return {
196
+ ...oldBindingOutput,
197
+ ...bindingOutput,
198
+ };
199
+ }
200
+ return oldBindingOutput;
201
+ }),
202
+ ),
203
+ );
204
+
205
+ const apply: (node: CRUD) => Effect.Effect<any, never, never> = (node) =>
206
+ Effect.gen(function* () {
207
+ const saveState = <Output>({
208
+ output,
209
+ bindings = node.bindings,
210
+ news,
176
211
  }: {
177
- bindings: BindNode[];
178
- bindingOutputs: any[];
179
- resource: Resource;
180
- target: {
181
- id: string;
182
- props: any;
183
- attr: any;
184
- };
212
+ output: Output;
213
+ bindings?: BindNode[];
214
+ news: any;
185
215
  }) =>
186
- Effect.all(
187
- bindings.map(
188
- Effect.fn(function* (node, i) {
189
- const { resourceId, upstreamAttr, upstreamNode, provider } =
190
- yield* resolveBindingUpstream({ node, resource });
191
-
192
- const oldBindingOutput = bindingOutputs[i];
193
-
194
- if (
195
- provider.postattach &&
196
- (node.action === "attach" || node.action === "reattach")
197
- ) {
198
- const bindingOutput = yield* constOrEffect(
199
- provider.postattach({
200
- source: {
201
- id: resourceId,
202
- attr: upstreamAttr,
203
- props: upstreamNode.resource.props,
204
- },
205
- props: node.binding.props,
206
- attr: oldBindingOutput,
207
- target,
208
- } as const),
209
- );
210
- return {
211
- ...oldBindingOutput,
212
- ...bindingOutput,
213
- };
214
- }
215
- return oldBindingOutput;
216
- }),
217
- ),
218
- );
219
-
220
- const apply: (node: CRUD) => Effect.Effect<any, never, never> = (
221
- node,
222
- ) =>
216
+ state
217
+ .set({
218
+ stack: app.name,
219
+ stage: app.stage,
220
+ resourceId: node.resource.id,
221
+ value: {
222
+ id: node.resource.id,
223
+ type: node.resource.type,
224
+ status: node.action === "create" ? "created" : "updated",
225
+ props: news,
226
+ output,
227
+ bindings,
228
+ },
229
+ })
230
+ .pipe(Effect.map(() => output));
231
+
232
+ const id = node.resource.id;
233
+ const resource = node.resource;
234
+
235
+ const scopedSession = {
236
+ ...session,
237
+ note: (note: string) =>
238
+ session.emit({
239
+ id,
240
+ kind: "annotate",
241
+ message: note,
242
+ }),
243
+ } satisfies ScopedPlanStatusSession;
244
+
245
+ return yield* (outputs[id] ??= yield* Effect.cached(
223
246
  Effect.gen(function* () {
224
- const checkpoint = <Out, Err>(
225
- effect: Effect.Effect<Out, Err, never>,
226
- ) => effect.pipe(Effect.flatMap((output) => saveState({ output })));
227
-
228
- const saveState = <Output>({
229
- output,
230
- bindings = node.bindings,
247
+ const report = (status: ApplyStatus) =>
248
+ emit({
249
+ kind: "status-change",
250
+ id,
251
+ type: node.resource.type,
252
+ status,
253
+ });
254
+
255
+ const createOrUpdate = Effect.fn(function* ({
256
+ node,
257
+ attr,
258
+ phase,
231
259
  }: {
232
- output: Output;
233
- bindings?: BindNode[];
234
- }) =>
235
- state
236
- .set(node.resource.id, {
237
- id: node.resource.id,
238
- type: node.resource.type,
239
- status: node.action === "create" ? "created" : "updated",
240
- props: node.resource.props,
241
- output,
242
- bindings,
260
+ node: Create | Update;
261
+ attr: any;
262
+ phase: "create" | "update";
263
+ }) {
264
+ const upstream = Object.fromEntries(
265
+ yield* Effect.all(
266
+ Object.entries(Output.resolveUpstream(node.news)).map(
267
+ ([id]) =>
268
+ resolveUpstream(id).pipe(
269
+ Effect.map(({ upstreamAttr }) => [id, upstreamAttr]),
270
+ ),
271
+ ),
272
+ ),
273
+ );
274
+ const news = yield* Output.evaluate(node.news, upstream);
275
+
276
+ yield* report(phase === "create" ? "creating" : "updating");
277
+
278
+ let bindingOutputs = yield* attachBindings({
279
+ resource,
280
+ bindings: node.bindings,
281
+ target: {
282
+ id,
283
+ props: news,
284
+ attr,
285
+ },
286
+ });
287
+
288
+ const output: any = yield* (
289
+ phase === "create" ? node.provider.create : node.provider.update
290
+ )({
291
+ id,
292
+ news,
293
+ bindings: bindingOutputs,
294
+ session: scopedSession,
295
+ ...(node.action === "update"
296
+ ? {
297
+ output: node.output,
298
+ olds: node.olds,
299
+ }
300
+ : {}),
301
+ }).pipe(
302
+ // TODO(sam): partial checkpoints
303
+ // checkpoint,
304
+ Effect.tap(() =>
305
+ report(phase === "create" ? "created" : "updated"),
306
+ ),
307
+ );
308
+
309
+ bindingOutputs = yield* postAttachBindings({
310
+ resource,
311
+ bindings: node.bindings,
312
+ bindingOutputs,
313
+ target: {
314
+ id,
315
+ props: news,
316
+ attr,
317
+ },
318
+ });
319
+
320
+ yield* saveState({
321
+ news,
322
+ output,
323
+ bindings: node.bindings.map((binding, i) => ({
324
+ ...binding,
325
+ attr: bindingOutputs[i],
326
+ })),
327
+ });
328
+
329
+ return output;
330
+ });
331
+
332
+ if (node.action === "noop") {
333
+ return (yield* state.get({
334
+ stack: app.name,
335
+ stage: app.stage,
336
+ resourceId: id,
337
+ }))?.output;
338
+ } else if (node.action === "create") {
339
+ let attr: any;
340
+ if (node.provider.precreate) {
341
+ yield* Effect.logDebug("precreate", id);
342
+ // stub the resource prior to resolving upstream resources or bindings if a stub is available
343
+ attr = yield* node.provider.precreate({
344
+ id,
345
+ news: node.news,
346
+ session: scopedSession,
347
+ });
348
+ }
349
+
350
+ yield* Effect.logDebug("create", id);
351
+ return yield* createOrUpdate({
352
+ node,
353
+ attr,
354
+ phase: "create",
355
+ });
356
+ } else if (node.action === "update") {
357
+ yield* Effect.logDebug("update", id);
358
+ return yield* createOrUpdate({
359
+ node,
360
+ attr: node.attributes,
361
+ phase: "update",
362
+ });
363
+ } else if (node.action === "delete") {
364
+ yield* Effect.logDebug("delete", id);
365
+ yield* Effect.all(
366
+ node.downstream.map((dep) =>
367
+ dep in plan.resources
368
+ ? apply(plan.resources[dep] as any)
369
+ : Effect.void,
370
+ ),
371
+ );
372
+ yield* report("deleting");
373
+
374
+ return yield* node.provider
375
+ .delete({
376
+ id,
377
+ olds: node.olds,
378
+ output: node.output,
379
+ session: scopedSession,
380
+ bindings: [],
243
381
  })
244
- .pipe(Effect.map(() => output));
245
-
246
- const id = node.resource.id;
247
- const resource = node.resource;
248
-
249
- const scopedSession = {
250
- ...session,
251
- note: (note: string) =>
252
- session.emit({
382
+ .pipe(
383
+ Effect.flatMap(() =>
384
+ state.delete({
385
+ stack: app.name,
386
+ stage: app.stage,
387
+ resourceId: id,
388
+ }),
389
+ ),
390
+ Effect.tap(() => report("deleted")),
391
+ );
392
+ } else if (node.action === "replace") {
393
+ const destroy = Effect.gen(function* () {
394
+ yield* report("deleting");
395
+ return yield* node.provider.delete({
253
396
  id,
254
- kind: "annotate",
255
- message: note,
256
- }),
257
- } satisfies ScopedPlanStatusSession;
258
-
259
- return yield* (outputs[id] ??= yield* Effect.cached(
260
- Effect.gen(function* () {
261
- const report = (status: ApplyStatus) =>
262
- emit({
263
- kind: "status-change",
264
- id,
265
- type: node.resource.type,
266
- status,
267
- });
397
+ olds: node.olds,
398
+ output: node.output,
399
+ session: scopedSession,
400
+ bindings: [],
401
+ });
402
+ });
403
+ const create = Effect.gen(function* () {
404
+ yield* report("creating");
268
405
 
269
- const createOrUpdate = Effect.fn(function* ({
270
- node,
271
- attr,
272
- phase,
273
- }: {
274
- node: Create<Resource> | Update<Resource>;
275
- attr: any;
276
- phase: "create" | "update";
277
- }) {
278
- yield* report(phase === "create" ? "creating" : "updating");
279
-
280
- let bindingOutputs = yield* attachBindings({
281
- resource,
282
- bindings: node.bindings,
283
- target: {
284
- id,
285
- props: node.news,
286
- attr,
287
- },
288
- });
289
-
290
- const output: any = yield* (
291
- phase === "create"
292
- ? node.provider.create
293
- : node.provider.update
294
- )({
406
+ // TODO(sam): delete and create will conflict here, we need to extend the state store for replace
407
+ return yield* node.provider
408
+ .create({
295
409
  id,
296
410
  news: node.news,
297
- bindings: bindingOutputs,
411
+ // TODO(sam): these need to only include attach actions
412
+ bindings: yield* attachBindings({
413
+ resource,
414
+ bindings: node.bindings,
415
+ target: {
416
+ id,
417
+ // TODO(sam): resolve the news
418
+ props: node.news,
419
+ attr: node.attributes,
420
+ },
421
+ }),
298
422
  session: scopedSession,
299
- ...(node.action === "update"
300
- ? {
301
- output: node.output,
302
- olds: node.olds,
303
- }
304
- : {}),
305
- }).pipe(
306
- // TODO(sam): partial checkpoints
307
- // checkpoint,
308
- Effect.tap(() =>
309
- report(phase === "create" ? "created" : "updated"),
310
- ),
311
- );
312
-
313
- bindingOutputs = yield* postAttachBindings({
314
- resource,
315
- bindings: node.bindings,
316
- bindingOutputs,
317
- target: {
318
- id,
319
- props: node.news,
320
- attr,
321
- },
322
- });
323
-
324
- yield* saveState({
325
- output,
326
- bindings: node.bindings.map((binding, i) => ({
327
- ...binding,
328
- attr: bindingOutputs[i],
329
- })),
330
- });
331
-
332
- return output;
333
- });
334
-
335
- if (node.action === "noop") {
336
- return (yield* state.get(id))?.output;
337
- } else if (node.action === "create") {
338
- let attr: any;
339
- if (node.provider.precreate) {
340
- yield* Effect.logDebug("precreate", id);
341
- // stub the resource prior to resolving upstream resources or bindings if a stub is available
342
- attr = yield* node.provider.precreate({
343
- id,
344
- news: node.news,
345
- session: scopedSession,
346
- });
347
- }
348
-
349
- yield* Effect.logDebug("create", id);
350
- return yield* createOrUpdate({
351
- node,
352
- attr,
353
- phase: "create",
354
- });
355
- } else if (node.action === "update") {
356
- yield* Effect.logDebug("update", id);
357
- return yield* createOrUpdate({
358
- node,
359
- attr: node.attributes,
360
- phase: "update",
361
- });
362
- } else if (node.action === "delete") {
363
- yield* Effect.logDebug("delete", id);
364
- yield* Effect.all(
365
- node.downstream.map((dep) =>
366
- dep in plan.resources
367
- ? apply(
368
- plan.resources[
369
- dep
370
- ] as P["resources"][keyof P["resources"]],
371
- )
372
- : Effect.void,
423
+ })
424
+ .pipe(
425
+ Effect.tap((output) =>
426
+ saveState({ news: node.news, output }),
373
427
  ),
374
428
  );
375
- yield* report("deleting");
376
-
377
- return yield* node.provider
378
- .delete({
379
- id,
380
- olds: node.olds,
381
- output: node.output,
382
- session: scopedSession,
383
- bindings: [],
384
- })
385
- .pipe(
386
- Effect.flatMap(() => state.delete(id)),
387
- Effect.tap(() => report("deleted")),
388
- );
389
- } else if (node.action === "replace") {
390
- const destroy = Effect.gen(function* () {
391
- yield* report("deleting");
392
- return yield* node.provider.delete({
393
- id,
394
- olds: node.olds,
395
- output: node.output,
396
- session: scopedSession,
397
- bindings: [],
398
- });
399
- });
400
- const create = Effect.gen(function* () {
401
- yield* report("creating");
402
- return yield* (
403
- node.provider
404
- .create({
405
- id,
406
- news: node.news,
407
- // TODO(sam): these need to only include attach actions
408
- bindings: yield* attachBindings({
409
- resource,
410
- bindings: node.bindings,
411
- target: {
412
- id,
413
- props: node.news,
414
- attr: node.attributes,
415
- },
416
- }),
417
- session: scopedSession,
418
- })
419
- // TODO(sam): delete and create will conflict here, we need to extend the state store for replace
420
- .pipe(
421
- checkpoint,
422
- Effect.tap(() => report("created")),
423
- )
424
- );
425
- });
426
- if (!node.deleteFirst) {
427
- yield* destroy;
428
- return outputs;
429
- } else {
430
- yield* destroy;
431
- return yield* create;
432
- }
433
- }
434
- }),
435
- ));
436
- }) as Effect.Effect<any, never, never>;
437
-
438
- const nodes = [
439
- ...Object.entries(plan.resources),
440
- ...Object.entries(plan.deletions),
441
- ];
442
-
443
- const resources: any = Object.fromEntries(
444
- yield* Effect.all(
445
- nodes.map(
446
- Effect.fn(function* ([id, node]) {
447
- return [id, yield* apply(node as CRUD)];
448
- }),
449
- ),
450
- ),
451
- );
452
- yield* done();
453
- if (Object.keys(plan.resources).length === 0) {
454
- // all resources are deleted, return undefined
455
- return undefined;
456
- }
457
- return resources;
458
- }),
459
- ),
460
- ) as Effect.Effect<
461
- "update" extends P["phase"]
462
- ?
463
- | {
464
- [id in keyof P["resources"]]: P["resources"][id] extends
465
- | Delete<Resource>
466
- | undefined
467
- | never
468
- ? never
469
- : Simplify<P["resources"][id]["resource"]["attr"]>;
429
+ });
430
+ if (!node.deleteFirst) {
431
+ yield* destroy;
432
+ return outputs;
433
+ } else {
434
+ yield* destroy;
435
+ return yield* create;
436
+ }
470
437
  }
471
- // union distribution isn't happening, so we gotta add this additional void here just in case
472
- | ("destroy" extends P["phase"] ? void : never)
473
- : void,
474
- Err | PlanRejected,
475
- Req
476
- >;
438
+ }),
439
+ ));
440
+ }) as Effect.Effect<any, never, never>;
441
+
442
+ const nodes = [
443
+ ...Object.entries(plan.resources),
444
+ ...Object.entries(plan.deletions),
445
+ ];
446
+
447
+ const resources: any = Object.fromEntries(
448
+ yield* Effect.all(
449
+ nodes.map(
450
+ Effect.fn(function* ([id, node]) {
451
+ return [id, yield* apply(node as CRUD)];
452
+ }),
453
+ ),
454
+ ),
455
+ );
456
+ yield* done();
457
+ if (Object.keys(plan.resources).length === 0) {
458
+ // all resources are deleted, return undefined
459
+ return undefined;
460
+ }
461
+ return resources as {
462
+ [k in keyof AppliedPlan<P>]: AppliedPlan<P>[k];
463
+ };
464
+ });