alchemy 0.16.10 → 0.17.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 (419) hide show
  1. package/lib/ai/astro-file.d.ts +1 -1
  2. package/lib/ai/astro-file.d.ts.map +1 -1
  3. package/lib/ai/astro-file.js +1 -1
  4. package/lib/ai/astro-file.js.map +1 -1
  5. package/lib/ai/client.js +2 -2
  6. package/lib/ai/client.js.map +1 -1
  7. package/lib/ai/css-file.d.ts +1 -1
  8. package/lib/ai/css-file.d.ts.map +1 -1
  9. package/lib/ai/css-file.js +1 -1
  10. package/lib/ai/css-file.js.map +1 -1
  11. package/lib/ai/data.d.ts +1 -1
  12. package/lib/ai/data.d.ts.map +1 -1
  13. package/lib/ai/data.js +1 -1
  14. package/lib/ai/data.js.map +1 -1
  15. package/lib/ai/html-file.d.ts +1 -1
  16. package/lib/ai/html-file.d.ts.map +1 -1
  17. package/lib/ai/html-file.js +1 -1
  18. package/lib/ai/html-file.js.map +1 -1
  19. package/lib/ai/json-file.d.ts +1 -1
  20. package/lib/ai/json-file.d.ts.map +1 -1
  21. package/lib/ai/json-file.js +1 -1
  22. package/lib/ai/json-file.js.map +1 -1
  23. package/lib/ai/typescript-file.d.ts +1 -1
  24. package/lib/ai/typescript-file.d.ts.map +1 -1
  25. package/lib/ai/typescript-file.js +1 -1
  26. package/lib/ai/typescript-file.js.map +1 -1
  27. package/lib/ai/vue-file.d.ts +1 -1
  28. package/lib/ai/vue-file.d.ts.map +1 -1
  29. package/lib/ai/vue-file.js +1 -1
  30. package/lib/ai/vue-file.js.map +1 -1
  31. package/lib/ai/yaml-file.d.ts +1 -1
  32. package/lib/ai/yaml-file.d.ts.map +1 -1
  33. package/lib/ai/yaml-file.js +2 -2
  34. package/lib/ai/yaml-file.js.map +1 -1
  35. package/lib/alchemy.d.ts +4 -0
  36. package/lib/alchemy.d.ts.map +1 -1
  37. package/lib/alchemy.js +14 -4
  38. package/lib/alchemy.js.map +1 -1
  39. package/lib/apply.d.ts +2 -0
  40. package/lib/apply.d.ts.map +1 -1
  41. package/lib/apply.js +17 -2
  42. package/lib/apply.js.map +1 -1
  43. package/lib/aws/bucket.d.ts +1 -1
  44. package/lib/aws/bucket.d.ts.map +1 -1
  45. package/lib/aws/bucket.js +1 -1
  46. package/lib/aws/bucket.js.map +1 -1
  47. package/lib/aws/function.d.ts +1 -1
  48. package/lib/aws/function.d.ts.map +1 -1
  49. package/lib/aws/function.js +2 -2
  50. package/lib/aws/function.js.map +1 -1
  51. package/lib/aws/oidc/oidc-provider.d.ts +1 -1
  52. package/lib/aws/oidc/oidc-provider.d.ts.map +1 -1
  53. package/lib/aws/oidc/oidc-provider.js +1 -1
  54. package/lib/aws/oidc/oidc-provider.js.map +1 -1
  55. package/lib/aws/policy-attachment.d.ts +1 -1
  56. package/lib/aws/policy-attachment.d.ts.map +1 -1
  57. package/lib/aws/policy-attachment.js +1 -1
  58. package/lib/aws/policy-attachment.js.map +1 -1
  59. package/lib/aws/policy.d.ts +1 -1
  60. package/lib/aws/policy.d.ts.map +1 -1
  61. package/lib/aws/policy.js +1 -1
  62. package/lib/aws/policy.js.map +1 -1
  63. package/lib/aws/queue.d.ts +1 -1
  64. package/lib/aws/queue.d.ts.map +1 -1
  65. package/lib/aws/queue.js +20 -25
  66. package/lib/aws/queue.js.map +1 -1
  67. package/lib/aws/role.d.ts +1 -1
  68. package/lib/aws/role.d.ts.map +1 -1
  69. package/lib/aws/role.js +1 -1
  70. package/lib/aws/role.js.map +1 -1
  71. package/lib/aws/ses.d.ts +1 -1
  72. package/lib/aws/ses.d.ts.map +1 -1
  73. package/lib/aws/ses.js +1 -1
  74. package/lib/aws/ses.js.map +1 -1
  75. package/lib/aws/table.d.ts +1 -1
  76. package/lib/aws/table.d.ts.map +1 -1
  77. package/lib/aws/table.js +1 -1
  78. package/lib/aws/table.js.map +1 -1
  79. package/lib/cloudflare/account-api-token.d.ts +1 -1
  80. package/lib/cloudflare/account-api-token.d.ts.map +1 -1
  81. package/lib/cloudflare/account-api-token.js +1 -1
  82. package/lib/cloudflare/account-api-token.js.map +1 -1
  83. package/lib/cloudflare/ai-gateway.d.ts +4 -3
  84. package/lib/cloudflare/ai-gateway.d.ts.map +1 -1
  85. package/lib/cloudflare/ai-gateway.js +13 -1
  86. package/lib/cloudflare/ai-gateway.js.map +1 -1
  87. package/lib/cloudflare/api-error.js +1 -1
  88. package/lib/cloudflare/api-error.js.map +1 -1
  89. package/lib/cloudflare/assets.js +2 -2
  90. package/lib/cloudflare/assets.js.map +1 -1
  91. package/lib/cloudflare/auth.js +1 -1
  92. package/lib/cloudflare/auth.js.map +1 -1
  93. package/lib/cloudflare/bindings.d.ts +17 -11
  94. package/lib/cloudflare/bindings.d.ts.map +1 -1
  95. package/lib/cloudflare/bindings.js +6 -0
  96. package/lib/cloudflare/bindings.js.map +1 -1
  97. package/lib/cloudflare/bound.d.ts +11 -10
  98. package/lib/cloudflare/bound.d.ts.map +1 -1
  99. package/lib/cloudflare/bucket.d.ts +6 -4
  100. package/lib/cloudflare/bucket.d.ts.map +1 -1
  101. package/lib/cloudflare/bucket.js +22 -2
  102. package/lib/cloudflare/bucket.js.map +1 -1
  103. package/lib/cloudflare/bundle/bundle-worker.d.ts +1 -0
  104. package/lib/cloudflare/bundle/bundle-worker.d.ts.map +1 -1
  105. package/lib/cloudflare/bundle/bundle-worker.js +4 -2
  106. package/lib/cloudflare/bundle/bundle-worker.js.map +1 -1
  107. package/lib/cloudflare/bundle/nodejs-compat-mode.d.ts +1 -1
  108. package/lib/cloudflare/bundle/nodejs-compat-mode.d.ts.map +1 -1
  109. package/lib/cloudflare/bundle/nodejs-compat-mode.js +2 -2
  110. package/lib/cloudflare/bundle/nodejs-compat-mode.js.map +1 -1
  111. package/lib/cloudflare/bundle/nodejs-compat.js +1 -1
  112. package/lib/cloudflare/bundle/nodejs-compat.js.map +1 -1
  113. package/lib/cloudflare/custom-domain.js +1 -1
  114. package/lib/cloudflare/custom-domain.js.map +1 -1
  115. package/lib/cloudflare/d1-database.d.ts +4 -62
  116. package/lib/cloudflare/d1-database.d.ts.map +1 -1
  117. package/lib/cloudflare/d1-database.js +27 -11
  118. package/lib/cloudflare/d1-database.js.map +1 -1
  119. package/lib/cloudflare/dns-records.d.ts +1 -1
  120. package/lib/cloudflare/dns-records.d.ts.map +1 -1
  121. package/lib/cloudflare/dns-records.js +2 -2
  122. package/lib/cloudflare/dns-records.js.map +1 -1
  123. package/lib/cloudflare/event-source.d.ts +3 -3
  124. package/lib/cloudflare/event-source.d.ts.map +1 -1
  125. package/lib/cloudflare/hyperdrive.d.ts +4 -3
  126. package/lib/cloudflare/hyperdrive.d.ts.map +1 -1
  127. package/lib/cloudflare/hyperdrive.js +9 -1
  128. package/lib/cloudflare/hyperdrive.js.map +1 -1
  129. package/lib/cloudflare/kv-namespace.d.ts +9 -5
  130. package/lib/cloudflare/kv-namespace.d.ts.map +1 -1
  131. package/lib/cloudflare/kv-namespace.js +26 -6
  132. package/lib/cloudflare/kv-namespace.js.map +1 -1
  133. package/lib/cloudflare/permission-groups.d.ts +1 -1
  134. package/lib/cloudflare/permission-groups.d.ts.map +1 -1
  135. package/lib/cloudflare/permission-groups.js +1 -1
  136. package/lib/cloudflare/permission-groups.js.map +1 -1
  137. package/lib/cloudflare/pipeline.d.ts +5 -3
  138. package/lib/cloudflare/pipeline.d.ts.map +1 -1
  139. package/lib/cloudflare/pipeline.js +16 -2
  140. package/lib/cloudflare/pipeline.js.map +1 -1
  141. package/lib/cloudflare/queue-consumer.d.ts +3 -3
  142. package/lib/cloudflare/queue-consumer.d.ts.map +1 -1
  143. package/lib/cloudflare/queue-consumer.js +1 -1
  144. package/lib/cloudflare/queue-consumer.js.map +1 -1
  145. package/lib/cloudflare/queue.d.ts +34 -22
  146. package/lib/cloudflare/queue.d.ts.map +1 -1
  147. package/lib/cloudflare/queue.js +66 -4
  148. package/lib/cloudflare/queue.js.map +1 -1
  149. package/lib/cloudflare/route.d.ts +1 -1
  150. package/lib/cloudflare/route.d.ts.map +1 -1
  151. package/lib/cloudflare/route.js +1 -1
  152. package/lib/cloudflare/route.js.map +1 -1
  153. package/lib/cloudflare/types.js +1 -1
  154. package/lib/cloudflare/types.js.map +1 -1
  155. package/lib/cloudflare/vectorize-index.d.ts +6 -4
  156. package/lib/cloudflare/vectorize-index.d.ts.map +1 -1
  157. package/lib/cloudflare/vectorize-index.js +20 -3
  158. package/lib/cloudflare/vectorize-index.js.map +1 -1
  159. package/lib/cloudflare/vectorize-metadata-index.d.ts +4 -3
  160. package/lib/cloudflare/vectorize-metadata-index.d.ts.map +1 -1
  161. package/lib/cloudflare/vectorize-metadata-index.js +5 -2
  162. package/lib/cloudflare/vectorize-metadata-index.js.map +1 -1
  163. package/lib/cloudflare/website.d.ts.map +1 -1
  164. package/lib/cloudflare/website.js +1 -0
  165. package/lib/cloudflare/website.js.map +1 -1
  166. package/lib/cloudflare/worker-assets.d.ts +32 -0
  167. package/lib/cloudflare/worker-assets.d.ts.map +1 -0
  168. package/lib/cloudflare/worker-assets.js +143 -0
  169. package/lib/cloudflare/worker-assets.js.map +1 -0
  170. package/lib/cloudflare/worker-metadata.d.ts +31 -0
  171. package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
  172. package/lib/cloudflare/worker-metadata.js +248 -0
  173. package/lib/cloudflare/worker-metadata.js.map +1 -1
  174. package/lib/cloudflare/worker-stub.d.ts +40 -0
  175. package/lib/cloudflare/worker-stub.d.ts.map +1 -0
  176. package/lib/cloudflare/worker-stub.js +86 -0
  177. package/lib/cloudflare/worker-stub.js.map +1 -0
  178. package/lib/cloudflare/worker.d.ts +57 -28
  179. package/lib/cloudflare/worker.d.ts.map +1 -1
  180. package/lib/cloudflare/worker.js +203 -479
  181. package/lib/cloudflare/worker.js.map +1 -1
  182. package/lib/cloudflare/wrangler.json.d.ts +1 -1
  183. package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
  184. package/lib/cloudflare/wrangler.json.js +5 -2
  185. package/lib/cloudflare/wrangler.json.js.map +1 -1
  186. package/lib/cloudflare/zone.d.ts +1 -1
  187. package/lib/cloudflare/zone.d.ts.map +1 -1
  188. package/lib/cloudflare/zone.js +1 -1
  189. package/lib/cloudflare/zone.js.map +1 -1
  190. package/lib/destroy.d.ts +1 -4
  191. package/lib/destroy.d.ts.map +1 -1
  192. package/lib/destroy.js +10 -21
  193. package/lib/destroy.js.map +1 -1
  194. package/lib/dns/import-dns.d.ts +1 -1
  195. package/lib/dns/import-dns.d.ts.map +1 -1
  196. package/lib/dns/import-dns.js +1 -1
  197. package/lib/dns/import-dns.js.map +1 -1
  198. package/lib/encrypt.d.ts.map +1 -1
  199. package/lib/encrypt.js +2 -1
  200. package/lib/encrypt.js.map +1 -1
  201. package/lib/env.js +14 -8
  202. package/lib/env.js.map +1 -1
  203. package/lib/esbuild/bundle.d.ts +2 -2
  204. package/lib/esbuild/bundle.d.ts.map +1 -1
  205. package/lib/esbuild/bundle.js +3 -3
  206. package/lib/esbuild/bundle.js.map +1 -1
  207. package/lib/fs/copy-file.d.ts +1 -1
  208. package/lib/fs/copy-file.d.ts.map +1 -1
  209. package/lib/fs/copy-file.js +1 -1
  210. package/lib/fs/copy-file.js.map +1 -1
  211. package/lib/github/client.js +1 -1
  212. package/lib/github/client.js.map +1 -1
  213. package/lib/github/repository-environment.d.ts +1 -1
  214. package/lib/github/repository-environment.d.ts.map +1 -1
  215. package/lib/github/repository-environment.js +2 -2
  216. package/lib/github/repository-environment.js.map +1 -1
  217. package/lib/github/secret.d.ts +1 -1
  218. package/lib/github/secret.d.ts.map +1 -1
  219. package/lib/github/secret.js +1 -1
  220. package/lib/github/secret.js.map +1 -1
  221. package/lib/internal/docs/providers.d.ts +1 -1
  222. package/lib/internal/docs/providers.d.ts.map +1 -1
  223. package/lib/internal/docs/providers.js +3 -1
  224. package/lib/internal/docs/providers.js.map +1 -1
  225. package/lib/neon/api-error.js +2 -2
  226. package/lib/neon/api-error.js.map +1 -1
  227. package/lib/os/exec.js +1 -1
  228. package/lib/os/exec.js.map +1 -1
  229. package/lib/resource.d.ts +13 -11
  230. package/lib/resource.d.ts.map +1 -1
  231. package/lib/resource.js +10 -5
  232. package/lib/resource.js.map +1 -1
  233. package/lib/runtime/bind.d.ts +25 -0
  234. package/lib/runtime/bind.d.ts.map +1 -0
  235. package/lib/runtime/bind.js +76 -0
  236. package/lib/runtime/bind.js.map +1 -0
  237. package/lib/runtime/global.d.ts +8 -0
  238. package/lib/runtime/global.d.ts.map +1 -0
  239. package/lib/runtime/global.js +3 -0
  240. package/lib/runtime/global.js.map +1 -0
  241. package/lib/runtime/plugin.d.ts +35 -0
  242. package/lib/runtime/plugin.d.ts.map +1 -0
  243. package/lib/runtime/plugin.js +133 -0
  244. package/lib/runtime/plugin.js.map +1 -0
  245. package/lib/runtime/shims.d.ts +6 -0
  246. package/lib/runtime/shims.d.ts.map +1 -0
  247. package/lib/runtime/shims.js +27 -0
  248. package/lib/runtime/shims.js.map +1 -0
  249. package/lib/runtime/state.d.ts +5 -0
  250. package/lib/runtime/state.d.ts.map +1 -0
  251. package/lib/runtime/state.js +4 -0
  252. package/lib/runtime/state.js.map +1 -0
  253. package/lib/scope.d.ts +16 -2
  254. package/lib/scope.d.ts.map +1 -1
  255. package/lib/scope.js +56 -9
  256. package/lib/scope.js.map +1 -1
  257. package/lib/secret.d.ts +7 -2
  258. package/lib/secret.d.ts.map +1 -1
  259. package/lib/secret.js +19 -4
  260. package/lib/secret.js.map +1 -1
  261. package/lib/sentry/client-key.d.ts +1 -1
  262. package/lib/sentry/client-key.d.ts.map +1 -1
  263. package/lib/sentry/client-key.js +1 -1
  264. package/lib/sentry/client-key.js.map +1 -1
  265. package/lib/sentry/project.d.ts +1 -1
  266. package/lib/sentry/project.d.ts.map +1 -1
  267. package/lib/sentry/project.js +1 -1
  268. package/lib/sentry/project.js.map +1 -1
  269. package/lib/sentry/team.d.ts +1 -1
  270. package/lib/sentry/team.d.ts.map +1 -1
  271. package/lib/sentry/team.js +1 -1
  272. package/lib/sentry/team.js.map +1 -1
  273. package/lib/serde.d.ts +26 -1
  274. package/lib/serde.d.ts.map +1 -1
  275. package/lib/serde.js +53 -8
  276. package/lib/serde.js.map +1 -1
  277. package/lib/stripe/meter.d.ts +1 -1
  278. package/lib/stripe/meter.d.ts.map +1 -1
  279. package/lib/stripe/meter.js +1 -1
  280. package/lib/stripe/meter.js.map +1 -1
  281. package/lib/stripe/price.d.ts +1 -1
  282. package/lib/stripe/price.d.ts.map +1 -1
  283. package/lib/stripe/price.js +1 -1
  284. package/lib/stripe/price.js.map +1 -1
  285. package/lib/stripe/product.d.ts +1 -1
  286. package/lib/stripe/product.d.ts.map +1 -1
  287. package/lib/stripe/product.js +1 -1
  288. package/lib/stripe/product.js.map +1 -1
  289. package/lib/stripe/webhook.d.ts +1 -1
  290. package/lib/stripe/webhook.d.ts.map +1 -1
  291. package/lib/stripe/webhook.js +1 -1
  292. package/lib/stripe/webhook.js.map +1 -1
  293. package/lib/test/bun.js +1 -1
  294. package/lib/test/bun.js.map +1 -1
  295. package/lib/test/prune.js +1 -1
  296. package/lib/test/prune.js.map +1 -1
  297. package/lib/upstash/redis.d.ts +1 -1
  298. package/lib/upstash/redis.d.ts.map +1 -1
  299. package/lib/upstash/redis.js +1 -1
  300. package/lib/upstash/redis.js.map +1 -1
  301. package/lib/util/content-type.d.ts +1 -1
  302. package/lib/util/content-type.d.ts.map +1 -1
  303. package/lib/util/content-type.js +1 -2
  304. package/lib/util/content-type.js.map +1 -1
  305. package/lib/util/retry.d.ts.map +1 -1
  306. package/lib/util/retry.js +1 -0
  307. package/lib/util/retry.js.map +1 -1
  308. package/lib/vercel/project-domain.d.ts +1 -1
  309. package/lib/vercel/project-domain.d.ts.map +1 -1
  310. package/lib/vercel/project-domain.js +1 -1
  311. package/lib/vercel/project-domain.js.map +1 -1
  312. package/lib/vercel/project.js +1 -1
  313. package/lib/vercel/project.js.map +1 -1
  314. package/lib/web/shadcn-component.d.ts +1 -1
  315. package/lib/web/shadcn-component.d.ts.map +1 -1
  316. package/lib/web/shadcn-component.js +1 -1
  317. package/lib/web/shadcn-component.js.map +1 -1
  318. package/lib/web/shadcn.d.ts +1 -1
  319. package/lib/web/shadcn.d.ts.map +1 -1
  320. package/lib/web/shadcn.js +1 -1
  321. package/lib/web/shadcn.js.map +1 -1
  322. package/lib/web/vitepress/dependencies.d.ts +1 -1
  323. package/lib/web/vitepress/dependencies.d.ts.map +1 -1
  324. package/lib/web/vitepress/dependencies.js +1 -1
  325. package/lib/web/vitepress/dependencies.js.map +1 -1
  326. package/lib/web/vitepress/vitepress.js +1 -1
  327. package/lib/web/vitepress/vitepress.js.map +1 -1
  328. package/package.json +2 -1
  329. package/src/ai/astro-file.ts +1 -1
  330. package/src/ai/client.ts +2 -2
  331. package/src/ai/css-file.ts +1 -1
  332. package/src/ai/data.ts +1 -1
  333. package/src/ai/html-file.ts +1 -1
  334. package/src/ai/json-file.ts +1 -1
  335. package/src/ai/typescript-file.ts +1 -1
  336. package/src/ai/vue-file.ts +1 -1
  337. package/src/ai/yaml-file.ts +2 -2
  338. package/src/alchemy.ts +18 -4
  339. package/src/apply.ts +27 -2
  340. package/src/aws/bucket.ts +1 -1
  341. package/src/aws/function.ts +2 -2
  342. package/src/aws/oidc/oidc-provider.ts +1 -1
  343. package/src/aws/policy-attachment.ts +1 -1
  344. package/src/aws/policy.ts +1 -1
  345. package/src/aws/queue.ts +28 -29
  346. package/src/aws/role.ts +1 -1
  347. package/src/aws/ses.ts +1 -1
  348. package/src/aws/table.ts +1 -1
  349. package/src/cloudflare/account-api-token.ts +1 -1
  350. package/src/cloudflare/ai-gateway.ts +23 -4
  351. package/src/cloudflare/api-error.ts +1 -1
  352. package/src/cloudflare/assets.ts +2 -2
  353. package/src/cloudflare/auth.ts +1 -1
  354. package/src/cloudflare/bindings.ts +33 -18
  355. package/src/cloudflare/bound.ts +18 -17
  356. package/src/cloudflare/bucket.ts +52 -24
  357. package/src/cloudflare/bundle/bundle-worker.ts +5 -2
  358. package/src/cloudflare/bundle/nodejs-compat-mode.ts +3 -3
  359. package/src/cloudflare/bundle/nodejs-compat.ts +1 -1
  360. package/src/cloudflare/custom-domain.ts +1 -1
  361. package/src/cloudflare/d1-database.ts +40 -19
  362. package/src/cloudflare/dns-records.ts +2 -2
  363. package/src/cloudflare/event-source.ts +3 -3
  364. package/src/cloudflare/hyperdrive.ts +19 -4
  365. package/src/cloudflare/kv-namespace.ts +46 -15
  366. package/src/cloudflare/permission-groups.ts +1 -1
  367. package/src/cloudflare/pipeline.ts +29 -6
  368. package/src/cloudflare/queue-consumer.ts +3 -3
  369. package/src/cloudflare/queue.ts +124 -23
  370. package/src/cloudflare/route.ts +1 -1
  371. package/src/cloudflare/types.ts +1 -1
  372. package/src/cloudflare/vectorize-index.ts +36 -8
  373. package/src/cloudflare/vectorize-metadata-index.ts +10 -4
  374. package/src/cloudflare/website.ts +4 -3
  375. package/src/cloudflare/worker-assets.ts +237 -0
  376. package/src/cloudflare/worker-metadata.ts +287 -0
  377. package/src/cloudflare/worker-stub.ts +153 -0
  378. package/src/cloudflare/worker.ts +386 -592
  379. package/src/cloudflare/wrangler.json.ts +4 -2
  380. package/src/cloudflare/zone.ts +1 -1
  381. package/src/destroy.ts +12 -23
  382. package/src/dns/import-dns.ts +1 -1
  383. package/src/encrypt.ts +2 -2
  384. package/src/env.ts +15 -8
  385. package/src/esbuild/bundle.ts +4 -3
  386. package/src/fs/copy-file.ts +1 -1
  387. package/src/github/client.ts +1 -1
  388. package/src/github/repository-environment.ts +2 -2
  389. package/src/github/secret.ts +1 -1
  390. package/src/internal/docs/providers.ts +1 -1
  391. package/src/neon/api-error.ts +2 -2
  392. package/src/os/exec.ts +1 -1
  393. package/src/resource.ts +22 -31
  394. package/src/runtime/bind.ts +95 -0
  395. package/src/runtime/global.ts +10 -0
  396. package/src/runtime/plugin.ts +162 -0
  397. package/src/runtime/shims.js +34 -0
  398. package/src/runtime/state.ts +9 -0
  399. package/src/scope.ts +72 -11
  400. package/src/secret.ts +29 -4
  401. package/src/sentry/client-key.ts +1 -1
  402. package/src/sentry/project.ts +1 -1
  403. package/src/sentry/team.ts +1 -1
  404. package/src/serde.ts +126 -10
  405. package/src/stripe/meter.ts +1 -1
  406. package/src/stripe/price.ts +1 -1
  407. package/src/stripe/product.ts +1 -1
  408. package/src/stripe/webhook.ts +1 -1
  409. package/src/test/bun.ts +1 -1
  410. package/src/test/prune.ts +1 -1
  411. package/src/upstash/redis.ts +1 -1
  412. package/src/util/content-type.ts +2 -3
  413. package/src/util/retry.ts +1 -0
  414. package/src/vercel/project-domain.ts +1 -1
  415. package/src/vercel/project.ts +1 -1
  416. package/src/web/shadcn-component.ts +1 -1
  417. package/src/web/shadcn.ts +1 -1
  418. package/src/web/vitepress/dependencies.ts +1 -1
  419. package/src/web/vitepress/vitepress.ts +1 -1
@@ -67,7 +67,7 @@ export const WranglerJson = Resource(
67
67
  "cloudflare::WranglerJson",
68
68
  async function (
69
69
  this: Context<WranglerJson>,
70
- id: string,
70
+ _id: string,
71
71
  props: WranglerJsonProps,
72
72
  ): Promise<WranglerJson> {
73
73
  // Default path is wrangler.json in current directory
@@ -409,7 +409,7 @@ function processBindings(
409
409
  // Service binding
410
410
  services.push({
411
411
  binding: bindingName,
412
- service: binding.id,
412
+ service: binding.name,
413
413
  });
414
414
  } else if (binding.type === "kv_namespace") {
415
415
  // KV Namespace binding
@@ -506,6 +506,8 @@ function processBindings(
506
506
  binding: bindingName,
507
507
  pipeline: binding.name,
508
508
  });
509
+ } else if (binding.type === "json") {
510
+ // TODO(sam): anything to do here? not sure wrangler.json supports this
509
511
  } else {
510
512
  // biome-ignore lint/correctness/noVoidTypeReturn: it returns never
511
513
  return assertNever(binding);
@@ -305,7 +305,7 @@ export const Zone = Resource(
305
305
  "cloudflare::Zone",
306
306
  async function (
307
307
  this: Context<Zone>,
308
- id: string,
308
+ _id: string,
309
309
  props: ZoneProps,
310
310
  ): Promise<Zone> {
311
311
  // Create Cloudflare API client with automatic account discovery
package/src/destroy.ts CHANGED
@@ -39,11 +39,11 @@ export async function destroy<Type extends string>(
39
39
  } satisfies DestroyOptions;
40
40
 
41
41
  // destroy all active resources
42
- await destroy.all(Array.from(scope.resources.values()), options);
42
+ await destroyAll(Array.from(scope.resources.values()), options);
43
43
 
44
44
  // then detect orphans and destroy them
45
45
  const orphans = await scope.state.all();
46
- await destroy.all(
46
+ await destroyAll(
47
47
  Object.values(orphans).map((orphan) => ({
48
48
  ...orphan.output,
49
49
  Scope: scope,
@@ -151,27 +151,16 @@ export async function destroy<Type extends string>(
151
151
  }
152
152
  }
153
153
 
154
- export namespace destroy {
155
- export async function all(resources: Resource[], options?: DestroyOptions) {
156
- if (options?.strategy !== "parallel") {
157
- const sorted = resources.sort((a, b) => b[ResourceSeq] - a[ResourceSeq]);
158
- for (const resource of sorted) {
159
- await destroy(resource, options);
160
- }
161
- } else {
162
- await Promise.all(
163
- resources.map((resource) => destroy(resource, options)),
164
- );
165
- }
166
- }
167
-
168
- export async function sequentially(
169
- ...resources: (Resource<string> | undefined | null)[]
170
- ) {
171
- for (const resource of resources) {
172
- if (resource) {
173
- await destroy(resource);
174
- }
154
+ export async function destroyAll(
155
+ resources: Resource[],
156
+ options?: DestroyOptions,
157
+ ) {
158
+ if (options?.strategy !== "parallel") {
159
+ const sorted = resources.sort((a, b) => b[ResourceSeq] - a[ResourceSeq]);
160
+ for (const resource of sorted) {
161
+ await destroy(resource, options);
175
162
  }
163
+ } else {
164
+ await Promise.all(resources.map((resource) => destroy(resource, options)));
176
165
  }
177
166
  }
@@ -133,7 +133,7 @@ export const ImportDnsRecords = Resource(
133
133
  "dns::ImportDnsRecords",
134
134
  async function (
135
135
  this: Context<ImportDnsRecords>,
136
- id: string,
136
+ _id: string,
137
137
  props: ImportDnsRecordsProps,
138
138
  ): Promise<ImportDnsRecords> {
139
139
  // For delete phase, just return destroyed state since this is a read-only resource
package/src/encrypt.ts CHANGED
@@ -1,5 +1,3 @@
1
- import sodium from "libsodium-wrappers";
2
-
3
1
  /**
4
2
  * Encrypt a value with a symmetric key using libsodium
5
3
  *
@@ -8,6 +6,7 @@ import sodium from "libsodium-wrappers";
8
6
  * @returns The base64-encoded encrypted value with nonce
9
7
  */
10
8
  export async function encrypt(value: string, key: string): Promise<string> {
9
+ const sodium = (await import("libsodium-wrappers")).default;
11
10
  // Initialize libsodium
12
11
  await sodium.ready;
13
12
 
@@ -46,6 +45,7 @@ export async function decryptWithKey(
46
45
  encryptedValue: string,
47
46
  key: string,
48
47
  ): Promise<string> {
48
+ const sodium = (await import("libsodium-wrappers")).default;
49
49
  // Initialize libsodium
50
50
  await sodium.ready;
51
51
 
package/src/env.ts CHANGED
@@ -16,16 +16,23 @@ async function _env<T = string>(
16
16
  if (value !== undefined) {
17
17
  return value;
18
18
  }
19
+ const env = await resolveEnv();
20
+ if (name in env) {
21
+ return env[name] as T;
22
+ }
23
+ throw new Error(error ?? `Environment variable ${name} is not set`);
24
+ }
25
+
26
+ async function resolveEnv(): Promise<Record<string, any>> {
19
27
  if (typeof process !== "undefined") {
20
- // we are in a node environment
21
- return process.env[name]! as T;
28
+ return process.env;
22
29
  }
23
- // we are in a browser environment
24
30
  try {
25
31
  const { env } = await import("cloudflare:workers");
26
- if (name in env) {
27
- return env[name as keyof typeof env] as T;
28
- }
29
- } catch (error) {}
30
- throw new Error(error ?? `Environment variable ${name} is not set`);
32
+ return env;
33
+ } catch (_error) {}
34
+ if (typeof import.meta !== "undefined") {
35
+ return import.meta.env;
36
+ }
37
+ throw new Error("No environment found");
31
38
  }
@@ -1,4 +1,4 @@
1
- import esbuild from "esbuild";
1
+ import type esbuild from "esbuild";
2
2
  import crypto from "node:crypto";
3
3
  import fs from "node:fs/promises";
4
4
  import path from "node:path";
@@ -122,7 +122,7 @@ export const Bundle = Resource(
122
122
  },
123
123
  async function <Props extends BundleProps>(
124
124
  this: Context<Bundle<any>>,
125
- id: string,
125
+ _id: string,
126
126
  props: Props,
127
127
  ): Promise<Bundle<Props>> {
128
128
  if (this.phase === "delete") {
@@ -193,7 +193,7 @@ export async function bundle(props: BundleProps) {
193
193
  // write:
194
194
  // props.outdir === undefined && props.outfile === undefined ? false : true,
195
195
  // write: false,
196
- entryPoints: [props.entryPoint],
196
+ entryPoints: [entryPoint],
197
197
  outdir: props.outdir ? props.outdir : props.outfile ? undefined : ".out",
198
198
  outfile: props.outfile,
199
199
  bundle: true,
@@ -208,5 +208,6 @@ export async function bundle(props: BundleProps) {
208
208
  if (process.env.DEBUG) {
209
209
  console.log(options);
210
210
  }
211
+ const esbuild = await import("esbuild");
211
212
  return await esbuild.build(options);
212
213
  }
@@ -63,7 +63,7 @@ export const CopyFile = Resource(
63
63
  "fs::CopyFile",
64
64
  async function (
65
65
  this: Context<CopyFile>,
66
- id: string,
66
+ _id: string,
67
67
  props: CopyFileProps,
68
68
  ): Promise<CopyFile> {
69
69
  const { src, dest, overwrite = true } = props;
@@ -17,7 +17,7 @@ export async function getGitHubTokenFromCLI(): Promise<string | null> {
17
17
  // Get the auth token
18
18
  const { stdout: token } = await execAsync("gh auth token");
19
19
  return token?.trim() || null;
20
- } catch (error) {
20
+ } catch (_error) {
21
21
  return null;
22
22
  }
23
23
  }
@@ -173,7 +173,7 @@ export const RepositoryEnvironment = Resource(
173
173
  "github::RepositoryEnvironment",
174
174
  async function (
175
175
  this: Context<RepositoryEnvironment>,
176
- id: string,
176
+ _id: string,
177
177
  props: RepositoryEnvironmentProps,
178
178
  ): Promise<RepositoryEnvironment> {
179
179
  // Create authenticated Octokit client
@@ -210,7 +210,7 @@ export const RepositoryEnvironment = Resource(
210
210
  }
211
211
  try {
212
212
  // Check if the environment already exists
213
- let environmentId: number | undefined = undefined; // Use undefined instead of 0
213
+ let environmentId: number | undefined; // Use undefined instead of 0
214
214
  try {
215
215
  const { data: environments } =
216
216
  await octokit.rest.repos.getAllEnvironments({
@@ -134,7 +134,7 @@ export const GitHubSecret = Resource(
134
134
  "github::Secret",
135
135
  async function (
136
136
  this: Context<GitHubSecretOutput>,
137
- id: string,
137
+ _id: string,
138
138
  props: GitHubSecretProps,
139
139
  ): Promise<GitHubSecretOutput> {
140
140
  // Create authenticated Octokit client - will automatically handle token resolution
@@ -52,7 +52,7 @@ export type Providers = {
52
52
  export async function Providers({
53
53
  srcDir,
54
54
  outDir,
55
- filter,
55
+ // filter,
56
56
  parallel = true,
57
57
  }: DocsProps): Promise<Providers> {
58
58
  outDir = typeof outDir === "string" ? outDir : outDir.path;
@@ -53,11 +53,11 @@ export async function handleApiError(
53
53
 
54
54
  try {
55
55
  errorData = await response.json();
56
- } catch (e) {
56
+ } catch (_e) {
57
57
  // If we can't parse JSON, just use the response text
58
58
  try {
59
59
  errorData = { message: await response.text() };
60
- } catch (textError) {
60
+ } catch (_textError) {
61
61
  errorData = { message: response.statusText };
62
62
  }
63
63
  }
package/src/os/exec.ts CHANGED
@@ -218,7 +218,7 @@ export const Exec = Resource(
218
218
  }
219
219
 
220
220
  // Wait for the process to complete
221
- exitCode = await new Promise<number>((resolve, reject) => {
221
+ exitCode = await new Promise<number>((resolve, _reject) => {
222
222
  childProcess.on("close", (code) => {
223
223
  resolve(code || 0);
224
224
  });
package/src/resource.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { apply } from "./apply.js";
2
2
  import type { Context } from "./context.js";
3
- import { Scope as _Scope } from "./scope.js";
3
+ import { Scope as _Scope, type Scope } from "./scope.js";
4
4
 
5
5
  export const PROVIDERS = new Map<ResourceKind, Provider<string, any>>();
6
6
 
@@ -11,6 +11,7 @@ export const ResourceFQN = Symbol.for("alchemy::ResourceFQN");
11
11
  export type ResourceKind = string;
12
12
  export const ResourceKind = Symbol.for("alchemy::ResourceKind");
13
13
  export const ResourceScope = Symbol.for("alchemy::ResourceScope");
14
+ export const InnerResourceScope = Symbol.for("alchemy::InnerResourceScope");
14
15
  export const ResourceSeq = Symbol.for("alchemy::ResourceSeq");
15
16
 
16
17
  export interface ProviderOptions {
@@ -34,35 +35,21 @@ export type Provider<
34
35
  handler: F;
35
36
  };
36
37
 
37
- export type PendingResource<
38
- Out = unknown,
39
- Kind extends ResourceKind = ResourceKind,
40
- ID extends ResourceID = ResourceID,
41
- FQN extends ResourceFQN = ResourceFQN,
42
- Scope extends _Scope = _Scope,
43
- Seq extends number = number,
44
- > = Promise<Out> & {
45
- [ResourceKind]: Kind;
46
- [ResourceID]: ID;
47
- [ResourceFQN]: FQN;
38
+ export interface PendingResource<Out = unknown> extends Promise<Out> {
39
+ [ResourceKind]: ResourceKind;
40
+ [ResourceID]: ResourceID;
41
+ [ResourceFQN]: ResourceFQN;
48
42
  [ResourceScope]: Scope;
49
- [ResourceSeq]: Seq;
50
- };
43
+ [ResourceSeq]: number;
44
+ [InnerResourceScope]: Promise<Scope>;
45
+ }
51
46
 
52
- export interface Resource<
53
- // give each name types for syntax highlighting (differentiation)
54
- Kind extends ResourceKind = ResourceKind,
55
- ID extends ResourceID = ResourceID,
56
- FQN extends ResourceFQN = ResourceFQN,
57
- Scope extends _Scope = _Scope,
58
- Seq extends number = number,
59
- > {
60
- // use capital letters to avoid collision with conventional camelCase typescript properties
47
+ export interface Resource<Kind extends ResourceKind = ResourceKind> {
61
48
  [ResourceKind]: Kind;
62
- [ResourceID]: ID;
63
- [ResourceFQN]: FQN;
49
+ [ResourceID]: ResourceID;
50
+ [ResourceFQN]: ResourceFQN;
64
51
  [ResourceScope]: Scope;
65
- [ResourceSeq]: Seq;
52
+ [ResourceSeq]: number;
66
53
  }
67
54
 
68
55
  // helper for semantic syntax highlighting (color as a type/class instead of function/value)
@@ -102,7 +89,7 @@ export function Resource<
102
89
 
103
90
  type Out = Awaited<ReturnType<F>>;
104
91
 
105
- const provider = ((
92
+ const provider = (async (
106
93
  resourceID: string,
107
94
  props: ResourceProps,
108
95
  ): Promise<Resource<string>> => {
@@ -123,21 +110,25 @@ export function Resource<
123
110
  `Resource ${resourceID} already exists in the stack and is of a different type: '${otherResource?.[ResourceKind]}' !== '${type}'`,
124
111
  );
125
112
  }
126
- // console.warn(
127
- // `Resource ${resourceID} already exists in the stack: ${scope.chain.join("/")}`,
128
- // );
129
113
  }
130
114
 
131
115
  // get a sequence number (unique within the scope) for the resource
132
116
  const seq = scope.seq();
117
+ let resolveInnerScope: ((scope: Scope) => void) | undefined;
133
118
  const meta = {
134
119
  [ResourceKind]: type,
135
120
  [ResourceID]: resourceID,
136
121
  [ResourceFQN]: scope.fqn(resourceID),
137
122
  [ResourceSeq]: seq,
138
123
  [ResourceScope]: scope,
124
+ [InnerResourceScope]: new Promise<Scope>((resolve) => {
125
+ resolveInnerScope = resolve;
126
+ }),
139
127
  } as any as PendingResource<Out>;
140
- const promise = apply(meta, props, options);
128
+ const promise = apply(meta, props, {
129
+ ...options,
130
+ resolveInnerScope,
131
+ });
141
132
  const resource = Object.assign(promise, meta);
142
133
  scope.resources.set(resourceID, resource);
143
134
  return resource;
@@ -0,0 +1,95 @@
1
+ import { isPromise } from "node:util/types";
2
+ import type { Binding as CloudflareBinding } from "../cloudflare/bindings.js";
3
+ import type { Bound as CloudflareBound } from "../cloudflare/bound.js";
4
+ import { isWorkerStub } from "../cloudflare/worker-stub.js";
5
+ import { isWorker } from "../cloudflare/worker.js";
6
+ import { env } from "../env.js";
7
+ import { ResourceFQN, ResourceScope, type Resource } from "../resource.js";
8
+ import { isRuntime } from "./global.js";
9
+
10
+ /**
11
+ * Get a Resource's Binding from the Environment.
12
+ */
13
+ export function getBinding<T extends Resource>(resource: T): Promise<Bound<T>> {
14
+ return env[getBindKey(resource)] as Promise<Bound<T>>;
15
+ }
16
+
17
+ export function tryGetBinding<T extends Resource>(
18
+ resource: T,
19
+ ): Promise<Bound<T>> | undefined {
20
+ if (isRuntime) {
21
+ return getBinding(resource);
22
+ }
23
+ return undefined;
24
+ }
25
+
26
+ /**
27
+ * Compute a unique key for where to store a Resource's Binding.
28
+ */
29
+ export function getBindKey(resource: Resource): string {
30
+ if (isWorker(resource) || isWorkerStub(resource)) {
31
+ return `worker:${resource.name}`;
32
+ }
33
+ const fqn = resource[ResourceFQN];
34
+ const scope = resource[ResourceScope];
35
+ const prefix = `${scope.appName}/${scope.stage}`;
36
+ const key = fqn.slice(prefix.length + 1).replace(/[^a-zA-Z0-9-_]/g, "_");
37
+ return key;
38
+ }
39
+
40
+ export type Bound<T> = T extends CloudflareBinding ? CloudflareBound<T> : T;
41
+
42
+ /**
43
+ * Create a lazy binding of a Resource to an environment that exposes the Resource's methods
44
+ * throw a Proxy that delays initialization of the binding until the Resource's methods are accessed.
45
+ *
46
+ * This allows us to run the same code during build time and runtime.
47
+ */
48
+ export async function bind<T extends Resource>(
49
+ resource: T | Promise<T>,
50
+ options?: {
51
+ reify?: (value: T, key: string) => Promise<Bound<T>>;
52
+ /** @default true */
53
+ bindThis?: boolean;
54
+ },
55
+ ): Promise<Bound<T>> {
56
+ if (isPromise(resource)) {
57
+ return resource.then((r) => bind(r, options)) as Promise<Bound<T>>;
58
+ }
59
+ let _runtime: [Bound<T>] | undefined;
60
+ const runtime = async (): Promise<Bound<T>> =>
61
+ (_runtime ??= [
62
+ await (options?.reify
63
+ ? options.reify(resource, getBindKey(resource))
64
+ : getBinding(resource)),
65
+ ])[0];
66
+
67
+ return new Proxy(() => {}, {
68
+ get: (target: any, prop: string) => {
69
+ if (prop in target) {
70
+ return (resource as T)[prop as keyof T];
71
+ } else if (prop === "then" || prop === "catch" || prop === "finally") {
72
+ return target[prop];
73
+ }
74
+ return async (...args: any[]) => {
75
+ const rt: Bound<T> = await runtime();
76
+ if (rt === undefined) {
77
+ throw new Error(`Resource ${resource[ResourceFQN]} is not bound`);
78
+ }
79
+ const method = rt[prop as keyof Bound<T>];
80
+ if (typeof method !== "function") {
81
+ throw new Error(
82
+ `Method ${prop} on '${resource[ResourceFQN]}' is not a function`,
83
+ );
84
+ }
85
+ if (options?.bindThis !== false) {
86
+ return method.bind(rt)(...args);
87
+ }
88
+ return method(...args);
89
+ };
90
+ },
91
+ // apply: (target, thisArg, argArray) => {
92
+ // return target(thisArg, ...argArray);
93
+ // },
94
+ }) as T & Bound<T>;
95
+ }
@@ -0,0 +1,10 @@
1
+ import type { SerializedScope } from "../serde.js";
2
+
3
+ declare global {
4
+ const __ALCHEMY_WORKER_NAME__: string;
5
+ const __ALCHEMY_RUNTIME__: true;
6
+ const __ALCHEMY_SERIALIZED_SCOPE__: SerializedScope;
7
+ }
8
+
9
+ // __ALCHEMY_SERIALIZED_SCOPE__ is injected by esbuild when bundling a Worker
10
+ export const isRuntime = typeof __ALCHEMY_RUNTIME__ !== "undefined";
@@ -0,0 +1,162 @@
1
+ import type {
2
+ CallExpression,
3
+ Declaration,
4
+ Expression,
5
+ FunctionDeclaration,
6
+ TsType,
7
+ VariableDeclaration,
8
+ } from "@swc/core";
9
+ import type { Plugin } from "esbuild";
10
+ import fs from "node:fs/promises";
11
+
12
+ /**
13
+ * Bundles a single Worker function entrypoint by:
14
+ * 1. Evaluate the script and detect which resources are included in its bundle.
15
+ * 2. Create a static map of Resource ID -> State
16
+ * 3. Apply esbuild with {@link bootstrapPlugin} to erase Resource lifecycle operations
17
+ * 4. The final bundle should then tree-shake away all infrastructure-code, leaving only runtime code.
18
+ *
19
+ * TODO(sam): should we inline the state map in the bundle or bind to a Cloudflare Worker with a blob?
20
+ * TODO(sam): what should we do with secrets? Seems like we could auto-bind them and resolve without requiring encryption logic.
21
+ *
22
+ * @param file the `.ts` file containing an `export default function`
23
+ */
24
+ export function bundleEntrypoint(_file: string) {}
25
+
26
+ /**
27
+ * This is a plugin that bootstraps Alchemy Infrastructure into Runtime by replacing Resources
28
+ * with a stub that loads from a statically bundled state.
29
+ *
30
+ * Take the following table for example:
31
+ * ```ts
32
+ * const Table = Resource(
33
+ * "dynamodb::Table",
34
+ * async function(this, id, props) {
35
+ * // lifecycle logic in here
36
+ * }
37
+ * );
38
+ * ```
39
+ *
40
+ * The plugin replaces the Resource with a stub:
41
+ * ```ts
42
+ * const Table = (id, props) => STATE.get(id)
43
+ * ```
44
+ */
45
+ export const bootstrapPlugin: Plugin = {
46
+ name: "alchemy-bootstrap",
47
+ async setup(build) {
48
+ const { parse, print } = await import("@swc/core");
49
+ const { Visitor } = await import("@swc/core/Visitor.js");
50
+
51
+ async function expr(expr: string) {
52
+ return (
53
+ (await parse(`const __temp__ = ${expr}`)).body[0] as VariableDeclaration
54
+ ).declarations[0].init!;
55
+ }
56
+ async function decl(decl: string) {
57
+ return (await parse(decl)).body[0] as Declaration;
58
+ }
59
+
60
+ const Provider = await decl("async function Resource() {}");
61
+ const Resource = await expr("(id) => STATE.get(id)");
62
+ // const alchemy = await expr("(async () => {})");
63
+
64
+ // Add a global STATE object to bundle for resource lookup
65
+ build.onLoad(
66
+ {
67
+ filter: /.*\.(ts|js)x?/,
68
+ },
69
+ async (args) => {
70
+ try {
71
+ const source = await fs.readFile(args.path, "utf-8");
72
+
73
+ function transformed(code: string) {
74
+ return {
75
+ contents: code,
76
+ loader: args.path.endsWith(".ts")
77
+ ? args.path.endsWith(".tsx")
78
+ ? "tsx"
79
+ : "ts"
80
+ : args.path.endsWith(".jsx")
81
+ ? "jsx"
82
+ : "js",
83
+ } as const;
84
+ }
85
+
86
+ // Parse the source code using SWC
87
+ const ast = await parse(source, {
88
+ syntax: "typescript",
89
+ tsx: args.path.endsWith(".tsx"),
90
+ decorators: true,
91
+ dynamicImport: true,
92
+ });
93
+
94
+ // function text({ span }: HasSpan) {
95
+ // return source.slice(
96
+ // span.start - ast.span.start,
97
+ // span.end - ast.span.start,
98
+ // );
99
+ // }
100
+
101
+ // Create visitor to transform Resource calls
102
+ class ResourceTransformer extends Visitor {
103
+ visitTsType(n: TsType): TsType {
104
+ return n;
105
+ }
106
+ visitFunctionDeclaration(decl: FunctionDeclaration): Declaration {
107
+ const param = decl.params[0];
108
+ if (
109
+ decl.identifier.value === "Resource" &&
110
+ param?.pat.type === "Identifier" &&
111
+ param.pat.value === "type" &&
112
+ decl.body
113
+ ) {
114
+ return Provider;
115
+ }
116
+ return decl;
117
+ }
118
+ visitCallExpression(expr: CallExpression): Expression {
119
+ // Check if this is a Resource call
120
+ if (
121
+ expr.callee.type === "Identifier" &&
122
+ expr.callee.value === "Resource" &&
123
+ expr.arguments.length >= 2
124
+ ) {
125
+ return Resource;
126
+ // } else if (
127
+ // expr.callee.type === "Identifier" &&
128
+ // expr.callee.value === "alchemy"
129
+ // ) {
130
+ // return alchemy;
131
+ }
132
+
133
+ return super.visitCallExpression(expr);
134
+ }
135
+ }
136
+
137
+ // Apply the transformation
138
+ const visitor = new ResourceTransformer();
139
+ const program = visitor.visitProgram(ast);
140
+
141
+ // Print the transformed AST back to code
142
+ const { code } = await print(program, {
143
+ sourceMaps: true,
144
+ minify: false,
145
+ });
146
+
147
+ return transformed(code);
148
+ } catch (error: unknown) {
149
+ console.error(`Error transforming ${args.path}:`, error);
150
+ return {
151
+ errors: [
152
+ {
153
+ text: `Failed to transform: ${error instanceof Error ? error.message : String(error)}`,
154
+ location: { file: args.path },
155
+ },
156
+ ],
157
+ };
158
+ }
159
+ },
160
+ );
161
+ },
162
+ };
@@ -0,0 +1,34 @@
1
+ import { env } from "cloudflare:workers";
2
+ import { Scope } from "../scope.js";
3
+ import { Secret } from "../secret.js";
4
+ import { deserialize } from "../serde.js";
5
+
6
+ globalThis.process.env = env;
7
+
8
+ export const __ALCHEMY_RUNTIME__ = true;
9
+
10
+ export var __ALCHEMY_SERIALIZED_SCOPE__ = JSON.parse(
11
+ env.__ALCHEMY_SERIALIZED_SCOPE__,
12
+ );
13
+
14
+ export const STATE = {
15
+ async get(id) {
16
+ const fqn = globalThis.__ALCHEMY_SCOPE__.current.fqn(id);
17
+ const state = __ALCHEMY_SERIALIZED_SCOPE__[fqn];
18
+ if (!state) {
19
+ throw new Error(
20
+ `Resource ${fqn} not found in __ALCHEMY_SERIALIZED_SCOPE__\n${JSON.stringify(__ALCHEMY_SERIALIZED_SCOPE__, null, 2)}`,
21
+ );
22
+ }
23
+ return await deserialize(Scope.current, state, {
24
+ transform: (value) => {
25
+ if (value && typeof value === "object" && value["@secret-env"]) {
26
+ return {
27
+ value: new Secret(env[value["@secret-env"]]),
28
+ };
29
+ }
30
+ },
31
+ });
32
+ },
33
+ };
34
+ // export const process = { env };