alchemy 2.0.0-beta.44 → 2.0.0-beta.45

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 (404) hide show
  1. package/bin/exec.js +67 -8
  2. package/bin/exec.js.map +1 -1
  3. package/lib/AWS/Lambda/Function.d.ts +17 -0
  4. package/lib/AWS/Lambda/Function.d.ts.map +1 -1
  5. package/lib/AWS/Lambda/Function.js +61 -16
  6. package/lib/AWS/Lambda/Function.js.map +1 -1
  7. package/lib/AWS/Providers.d.ts +2 -1
  8. package/lib/AWS/Providers.d.ts.map +1 -1
  9. package/lib/AWS/Providers.js +3 -1
  10. package/lib/AWS/Providers.js.map +1 -1
  11. package/lib/Apply.js +17 -1
  12. package/lib/Apply.js.map +1 -1
  13. package/lib/Auth/AuthProvider.d.ts.map +1 -1
  14. package/lib/Auth/AuthProvider.js +24 -6
  15. package/lib/Auth/AuthProvider.js.map +1 -1
  16. package/lib/Auth/Credentials.d.ts.map +1 -1
  17. package/lib/Auth/Credentials.js +3 -3
  18. package/lib/Auth/Credentials.js.map +1 -1
  19. package/lib/Cli/commands/_shared.d.ts +13 -1
  20. package/lib/Cli/commands/_shared.d.ts.map +1 -1
  21. package/lib/Cli/commands/_shared.js +33 -2
  22. package/lib/Cli/commands/_shared.js.map +1 -1
  23. package/lib/Cli/commands/dev.d.ts.map +1 -1
  24. package/lib/Cli/commands/dev.js +10 -1
  25. package/lib/Cli/commands/dev.js.map +1 -1
  26. package/lib/Cli/commands/login.d.ts.map +1 -1
  27. package/lib/Cli/commands/login.js +19 -5
  28. package/lib/Cli/commands/login.js.map +1 -1
  29. package/lib/Cli/commands/profile.d.ts.map +1 -1
  30. package/lib/Cli/commands/profile.js +7 -27
  31. package/lib/Cli/commands/profile.js.map +1 -1
  32. package/lib/Cli/main.d.ts.map +1 -1
  33. package/lib/Cli/main.js +0 -2
  34. package/lib/Cli/main.js.map +1 -1
  35. package/lib/Cloudflare/AiGateway/AiGateway.d.ts +0 -2
  36. package/lib/Cloudflare/AiGateway/AiGateway.d.ts.map +1 -1
  37. package/lib/Cloudflare/AiGateway/AiGateway.js +2 -4
  38. package/lib/Cloudflare/AiGateway/AiGateway.js.map +1 -1
  39. package/lib/Cloudflare/BrowserRendering/BrowserRendering.d.ts +116 -0
  40. package/lib/Cloudflare/BrowserRendering/BrowserRendering.d.ts.map +1 -0
  41. package/lib/Cloudflare/BrowserRendering/BrowserRendering.js +92 -0
  42. package/lib/Cloudflare/BrowserRendering/BrowserRendering.js.map +1 -0
  43. package/lib/Cloudflare/BrowserRendering/BrowserRenderingBinding.d.ts +55 -0
  44. package/lib/Cloudflare/BrowserRendering/BrowserRenderingBinding.d.ts.map +1 -0
  45. package/lib/Cloudflare/BrowserRendering/BrowserRenderingBinding.js +55 -0
  46. package/lib/Cloudflare/BrowserRendering/BrowserRenderingBinding.js.map +1 -0
  47. package/lib/Cloudflare/BrowserRendering/index.d.ts +3 -0
  48. package/lib/Cloudflare/BrowserRendering/index.d.ts.map +1 -0
  49. package/lib/Cloudflare/BrowserRendering/index.js +3 -0
  50. package/lib/Cloudflare/BrowserRendering/index.js.map +1 -0
  51. package/lib/Cloudflare/Container/Container.d.ts +3 -3
  52. package/lib/Cloudflare/Container/Container.js +3 -3
  53. package/lib/Cloudflare/Container/StartContainer.d.ts.map +1 -1
  54. package/lib/Cloudflare/Container/StartContainer.js.map +1 -1
  55. package/lib/Cloudflare/D1/D1Database.d.ts +1 -0
  56. package/lib/Cloudflare/D1/D1Database.d.ts.map +1 -1
  57. package/lib/Cloudflare/D1/D1Database.js +2 -1
  58. package/lib/Cloudflare/D1/D1Database.js.map +1 -1
  59. package/lib/Cloudflare/D1/D1DatabaseBinding.js +1 -1
  60. package/lib/Cloudflare/D1/D1DatabaseBinding.js.map +1 -1
  61. package/lib/Cloudflare/Fetcher.d.ts.map +1 -1
  62. package/lib/Cloudflare/Fetcher.js +0 -2
  63. package/lib/Cloudflare/Fetcher.js.map +1 -1
  64. package/lib/Cloudflare/Hyperdrive/Hyperdrive.d.ts +1 -0
  65. package/lib/Cloudflare/Hyperdrive/Hyperdrive.d.ts.map +1 -1
  66. package/lib/Cloudflare/Hyperdrive/Hyperdrive.js +3 -0
  67. package/lib/Cloudflare/Hyperdrive/Hyperdrive.js.map +1 -1
  68. package/lib/Cloudflare/Hyperdrive/HyperdriveBinding.d.ts +3 -2
  69. package/lib/Cloudflare/Hyperdrive/HyperdriveBinding.d.ts.map +1 -1
  70. package/lib/Cloudflare/Hyperdrive/HyperdriveBinding.js +32 -33
  71. package/lib/Cloudflare/Hyperdrive/HyperdriveBinding.js.map +1 -1
  72. package/lib/Cloudflare/KV/KVNamespace.d.ts +1 -0
  73. package/lib/Cloudflare/KV/KVNamespace.d.ts.map +1 -1
  74. package/lib/Cloudflare/KV/KVNamespace.js +2 -0
  75. package/lib/Cloudflare/KV/KVNamespace.js.map +1 -1
  76. package/lib/Cloudflare/Local.js +1 -1
  77. package/lib/Cloudflare/Local.js.map +1 -1
  78. package/lib/Cloudflare/Providers.d.ts +2 -1
  79. package/lib/Cloudflare/Providers.d.ts.map +1 -1
  80. package/lib/Cloudflare/Providers.js +21 -17
  81. package/lib/Cloudflare/Providers.js.map +1 -1
  82. package/lib/Cloudflare/Queue/Queue.d.ts +1 -0
  83. package/lib/Cloudflare/Queue/Queue.d.ts.map +1 -1
  84. package/lib/Cloudflare/Queue/Queue.js +1 -0
  85. package/lib/Cloudflare/Queue/Queue.js.map +1 -1
  86. package/lib/Cloudflare/Queue/QueueConsumer.d.ts +2 -1
  87. package/lib/Cloudflare/Queue/QueueConsumer.d.ts.map +1 -1
  88. package/lib/Cloudflare/Queue/QueueConsumer.js +11 -3
  89. package/lib/Cloudflare/Queue/QueueConsumer.js.map +1 -1
  90. package/lib/Cloudflare/Queue/QueueEventSource.d.ts +30 -4
  91. package/lib/Cloudflare/Queue/QueueEventSource.d.ts.map +1 -1
  92. package/lib/Cloudflare/Queue/QueueEventSource.js +22 -1
  93. package/lib/Cloudflare/Queue/QueueEventSource.js.map +1 -1
  94. package/lib/Cloudflare/R2/R2Bucket.d.ts +1 -0
  95. package/lib/Cloudflare/R2/R2Bucket.d.ts.map +1 -1
  96. package/lib/Cloudflare/R2/R2Bucket.js +18 -0
  97. package/lib/Cloudflare/R2/R2Bucket.js.map +1 -1
  98. package/lib/Cloudflare/SecretsStore/Secret.d.ts.map +1 -1
  99. package/lib/Cloudflare/SecretsStore/Secret.js +13 -34
  100. package/lib/Cloudflare/SecretsStore/Secret.js.map +1 -1
  101. package/lib/Cloudflare/SecretsStore/SecretBinding.d.ts +3 -2
  102. package/lib/Cloudflare/SecretsStore/SecretBinding.d.ts.map +1 -1
  103. package/lib/Cloudflare/SecretsStore/SecretBinding.js +3 -2
  104. package/lib/Cloudflare/SecretsStore/SecretBinding.js.map +1 -1
  105. package/lib/Cloudflare/StateStore/Api.d.ts +5 -13
  106. package/lib/Cloudflare/StateStore/Api.d.ts.map +1 -1
  107. package/lib/Cloudflare/StateStore/Api.js +14 -8
  108. package/lib/Cloudflare/StateStore/Api.js.map +1 -1
  109. package/lib/Cloudflare/StateStore/State.d.ts.map +1 -1
  110. package/lib/Cloudflare/StateStore/State.js +45 -9
  111. package/lib/Cloudflare/StateStore/State.js.map +1 -1
  112. package/lib/Cloudflare/StateStore/Store.d.ts.map +1 -1
  113. package/lib/Cloudflare/StateStore/Store.js +5 -2
  114. package/lib/Cloudflare/StateStore/Store.js.map +1 -1
  115. package/lib/Cloudflare/VpcService/VpcService.d.ts +2 -2
  116. package/lib/Cloudflare/VpcService/VpcService.d.ts.map +1 -1
  117. package/lib/Cloudflare/Website/StaticSite.d.ts +5 -5
  118. package/lib/Cloudflare/Website/StaticSite.d.ts.map +1 -1
  119. package/lib/Cloudflare/Website/StaticSite.js +3 -0
  120. package/lib/Cloudflare/Website/StaticSite.js.map +1 -1
  121. package/lib/Cloudflare/Website/Vite.d.ts +5 -5
  122. package/lib/Cloudflare/Website/Vite.d.ts.map +1 -1
  123. package/lib/Cloudflare/Website/Vite.js.map +1 -1
  124. package/lib/Cloudflare/Workers/Assets.d.ts.map +1 -1
  125. package/lib/Cloudflare/Workers/Assets.js +1 -1
  126. package/lib/Cloudflare/Workers/Assets.js.map +1 -1
  127. package/lib/Cloudflare/Workers/DurableObjectBridge.d.ts.map +1 -1
  128. package/lib/Cloudflare/Workers/DurableObjectBridge.js +4 -2
  129. package/lib/Cloudflare/Workers/DurableObjectBridge.js.map +1 -1
  130. package/lib/Cloudflare/Workers/DurableObjectNamespace.d.ts +183 -6
  131. package/lib/Cloudflare/Workers/DurableObjectNamespace.d.ts.map +1 -1
  132. package/lib/Cloudflare/Workers/DurableObjectNamespace.js +279 -76
  133. package/lib/Cloudflare/Workers/DurableObjectNamespace.js.map +1 -1
  134. package/lib/Cloudflare/Workers/HttpServer.d.ts +6 -4
  135. package/lib/Cloudflare/Workers/HttpServer.d.ts.map +1 -1
  136. package/lib/Cloudflare/Workers/HttpServer.js +20 -15
  137. package/lib/Cloudflare/Workers/HttpServer.js.map +1 -1
  138. package/lib/Cloudflare/Workers/InferEnv.d.ts +3 -2
  139. package/lib/Cloudflare/Workers/InferEnv.d.ts.map +1 -1
  140. package/lib/Cloudflare/Workers/LocalWorkerProvider.d.ts +4 -7
  141. package/lib/Cloudflare/Workers/LocalWorkerProvider.d.ts.map +1 -1
  142. package/lib/Cloudflare/Workers/LocalWorkerProvider.js +111 -66
  143. package/lib/Cloudflare/Workers/LocalWorkerProvider.js.map +1 -1
  144. package/lib/Cloudflare/Workers/Rpc.d.ts +16 -0
  145. package/lib/Cloudflare/Workers/Rpc.d.ts.map +1 -1
  146. package/lib/Cloudflare/Workers/Rpc.js +22 -0
  147. package/lib/Cloudflare/Workers/Rpc.js.map +1 -1
  148. package/lib/Cloudflare/Workers/RpcDurableObjectNamespace.d.ts +285 -0
  149. package/lib/Cloudflare/Workers/RpcDurableObjectNamespace.d.ts.map +1 -0
  150. package/lib/Cloudflare/Workers/RpcDurableObjectNamespace.js +288 -0
  151. package/lib/Cloudflare/Workers/RpcDurableObjectNamespace.js.map +1 -0
  152. package/lib/Cloudflare/Workers/RpcWorker.d.ts +305 -0
  153. package/lib/Cloudflare/Workers/RpcWorker.d.ts.map +1 -0
  154. package/lib/Cloudflare/Workers/RpcWorker.js +350 -0
  155. package/lib/Cloudflare/Workers/RpcWorker.js.map +1 -0
  156. package/lib/Cloudflare/Workers/Vite.d.ts +1 -1
  157. package/lib/Cloudflare/Workers/Vite.d.ts.map +1 -1
  158. package/lib/Cloudflare/Workers/Vite.js +2 -1
  159. package/lib/Cloudflare/Workers/Vite.js.map +1 -1
  160. package/lib/Cloudflare/Workers/Worker.d.ts +69 -24
  161. package/lib/Cloudflare/Workers/Worker.d.ts.map +1 -1
  162. package/lib/Cloudflare/Workers/Worker.js +168 -47
  163. package/lib/Cloudflare/Workers/Worker.js.map +1 -1
  164. package/lib/Cloudflare/Workers/WorkerAsyncBindings.d.ts +1 -1
  165. package/lib/Cloudflare/Workers/WorkerAsyncBindings.d.ts.map +1 -1
  166. package/lib/Cloudflare/Workers/WorkerAsyncBindings.js +158 -97
  167. package/lib/Cloudflare/Workers/WorkerAsyncBindings.js.map +1 -1
  168. package/lib/Cloudflare/Workers/WorkerBinding.d.ts +11 -23
  169. package/lib/Cloudflare/Workers/WorkerBinding.d.ts.map +1 -1
  170. package/lib/Cloudflare/Workers/WorkerBinding.js +3 -0
  171. package/lib/Cloudflare/Workers/WorkerBinding.js.map +1 -1
  172. package/lib/Cloudflare/Workers/WorkerBridge.d.ts.map +1 -1
  173. package/lib/Cloudflare/Workers/WorkerBridge.js +5 -2
  174. package/lib/Cloudflare/Workers/WorkerBridge.js.map +1 -1
  175. package/lib/Cloudflare/Workers/WorkerBundle.d.ts.map +1 -1
  176. package/lib/Cloudflare/Workers/WorkerBundle.js +4 -1
  177. package/lib/Cloudflare/Workers/WorkerBundle.js.map +1 -1
  178. package/lib/Cloudflare/Workers/WorkerRuntimeContext.d.ts.map +1 -1
  179. package/lib/Cloudflare/Workers/WorkerRuntimeContext.js +9 -10
  180. package/lib/Cloudflare/Workers/WorkerRuntimeContext.js.map +1 -1
  181. package/lib/Cloudflare/Workers/Workflow.d.ts +5 -3
  182. package/lib/Cloudflare/Workers/Workflow.d.ts.map +1 -1
  183. package/lib/Cloudflare/Workers/Workflow.js +19 -1
  184. package/lib/Cloudflare/Workers/Workflow.js.map +1 -1
  185. package/lib/Cloudflare/Workers/index.d.ts +2 -0
  186. package/lib/Cloudflare/Workers/index.d.ts.map +1 -1
  187. package/lib/Cloudflare/Workers/index.js +2 -0
  188. package/lib/Cloudflare/Workers/index.js.map +1 -1
  189. package/lib/Cloudflare/index.d.ts +1 -0
  190. package/lib/Cloudflare/index.d.ts.map +1 -1
  191. package/lib/Cloudflare/index.js +1 -0
  192. package/lib/Cloudflare/index.js.map +1 -1
  193. package/lib/Dependencies.d.ts +10 -0
  194. package/lib/Dependencies.d.ts.map +1 -0
  195. package/lib/Dependencies.js +1 -0
  196. package/lib/Dependencies.js.map +1 -0
  197. package/lib/Deploy.d.ts +2 -1
  198. package/lib/Deploy.d.ts.map +1 -1
  199. package/lib/Deploy.js +2 -2
  200. package/lib/Deploy.js.map +1 -1
  201. package/lib/Diff.d.ts +11 -0
  202. package/lib/Diff.d.ts.map +1 -1
  203. package/lib/Diff.js +11 -0
  204. package/lib/Diff.js.map +1 -1
  205. package/lib/Input.d.ts +2 -1
  206. package/lib/Input.d.ts.map +1 -1
  207. package/lib/KeyPair.d.ts +77 -0
  208. package/lib/KeyPair.d.ts.map +1 -0
  209. package/lib/KeyPair.js +102 -0
  210. package/lib/KeyPair.js.map +1 -0
  211. package/lib/Local/RpcProvider.d.ts +3 -1
  212. package/lib/Local/RpcProvider.d.ts.map +1 -1
  213. package/lib/Local/RpcProvider.js +28 -2
  214. package/lib/Local/RpcProvider.js.map +1 -1
  215. package/lib/Local/RpcServerEnvironment.js +1 -1
  216. package/lib/Local/RpcServerEnvironment.js.map +1 -1
  217. package/lib/Neon/Project.d.ts.map +1 -1
  218. package/lib/Neon/Project.js +14 -3
  219. package/lib/Neon/Project.js.map +1 -1
  220. package/lib/Output.d.ts.map +1 -1
  221. package/lib/Output.js +9 -2
  222. package/lib/Output.js.map +1 -1
  223. package/lib/Phase.d.ts +2 -1
  224. package/lib/Phase.d.ts.map +1 -1
  225. package/lib/Phase.js +6 -1
  226. package/lib/Phase.js.map +1 -1
  227. package/lib/Plan.d.ts.map +1 -1
  228. package/lib/Plan.js +14 -3
  229. package/lib/Plan.js.map +1 -1
  230. package/lib/Platform.d.ts +8 -6
  231. package/lib/Platform.d.ts.map +1 -1
  232. package/lib/Platform.js +33 -3
  233. package/lib/Platform.js.map +1 -1
  234. package/lib/Random.d.ts.map +1 -1
  235. package/lib/Random.js +9 -14
  236. package/lib/Random.js.map +1 -1
  237. package/lib/RuntimeContext.d.ts +21 -1
  238. package/lib/RuntimeContext.d.ts.map +1 -1
  239. package/lib/RuntimeContext.js +12 -0
  240. package/lib/RuntimeContext.js.map +1 -1
  241. package/lib/Stack.d.ts +3 -3
  242. package/lib/Stack.d.ts.map +1 -1
  243. package/lib/Stack.js.map +1 -1
  244. package/lib/State/HttpStateApi.d.ts +2 -2
  245. package/lib/State/StateEncoding.d.ts +8 -0
  246. package/lib/State/StateEncoding.d.ts.map +1 -1
  247. package/lib/State/StateEncoding.js +55 -5
  248. package/lib/State/StateEncoding.js.map +1 -1
  249. package/lib/Test/Bun.d.ts.map +1 -1
  250. package/lib/Test/Bun.js +0 -2
  251. package/lib/Test/Bun.js.map +1 -1
  252. package/lib/Test/Vitest.d.ts.map +1 -1
  253. package/lib/Test/Vitest.js +0 -2
  254. package/lib/Test/Vitest.js.map +1 -1
  255. package/lib/Util/Duration.d.ts +14 -0
  256. package/lib/Util/Duration.d.ts.map +1 -0
  257. package/lib/Util/Duration.js +18 -0
  258. package/lib/Util/Duration.js.map +1 -0
  259. package/lib/Util/index.d.ts +0 -6
  260. package/lib/Util/index.d.ts.map +1 -1
  261. package/lib/Util/index.js +0 -6
  262. package/lib/Util/index.js.map +1 -1
  263. package/lib/Util/types.d.ts +3 -1
  264. package/lib/Util/types.d.ts.map +1 -1
  265. package/lib/Util/types.js +5 -1
  266. package/lib/Util/types.js.map +1 -1
  267. package/lib/index.d.ts +2 -3
  268. package/lib/index.d.ts.map +1 -1
  269. package/lib/index.js +1 -3
  270. package/lib/index.js.map +1 -1
  271. package/lib/tsconfig.test.tsbuildinfo +1 -1
  272. package/package.json +20 -19
  273. package/src/AWS/Lambda/Function.ts +87 -34
  274. package/src/AWS/Providers.ts +3 -0
  275. package/src/Apply.ts +18 -1
  276. package/src/Auth/AuthProvider.ts +25 -5
  277. package/src/Auth/Credentials.ts +8 -7
  278. package/src/Cli/commands/_shared.ts +47 -4
  279. package/src/Cli/commands/dev.ts +13 -1
  280. package/src/Cli/commands/login.ts +20 -4
  281. package/src/Cli/commands/profile.ts +24 -34
  282. package/src/Cli/main.ts +0 -3
  283. package/src/Cloudflare/AiGateway/AiGateway.ts +2 -6
  284. package/src/Cloudflare/BrowserRendering/BrowserRendering.ts +132 -0
  285. package/src/Cloudflare/BrowserRendering/BrowserRenderingBinding.ts +137 -0
  286. package/src/Cloudflare/BrowserRendering/index.ts +11 -0
  287. package/src/Cloudflare/Container/Container.ts +3 -3
  288. package/src/Cloudflare/Container/StartContainer.ts +1 -2
  289. package/src/Cloudflare/D1/D1Database.ts +4 -1
  290. package/src/Cloudflare/D1/D1DatabaseBinding.ts +1 -1
  291. package/src/Cloudflare/Fetcher.ts +0 -2
  292. package/src/Cloudflare/Hyperdrive/Hyperdrive.ts +5 -0
  293. package/src/Cloudflare/Hyperdrive/HyperdriveBinding.ts +41 -43
  294. package/src/Cloudflare/KV/KVNamespace.ts +4 -0
  295. package/src/Cloudflare/Local.ts +1 -1
  296. package/src/Cloudflare/Providers.ts +25 -16
  297. package/src/Cloudflare/Queue/Queue.ts +3 -0
  298. package/src/Cloudflare/Queue/QueueConsumer.ts +23 -8
  299. package/src/Cloudflare/Queue/QueueEventSource.ts +33 -5
  300. package/src/Cloudflare/R2/R2Bucket.ts +26 -0
  301. package/src/Cloudflare/SecretsStore/Secret.ts +14 -41
  302. package/src/Cloudflare/SecretsStore/SecretBinding.ts +11 -11
  303. package/src/Cloudflare/StateStore/Api.ts +15 -15
  304. package/src/Cloudflare/StateStore/State.ts +68 -6
  305. package/src/Cloudflare/StateStore/Store.ts +5 -2
  306. package/src/Cloudflare/VpcService/VpcService.ts +2 -2
  307. package/src/Cloudflare/Website/StaticSite.ts +8 -10
  308. package/src/Cloudflare/Website/Vite.ts +4 -7
  309. package/src/Cloudflare/Workers/Assets.ts +1 -1
  310. package/src/Cloudflare/Workers/DurableObjectBridge.ts +7 -4
  311. package/src/Cloudflare/Workers/DurableObjectNamespace.ts +380 -121
  312. package/src/Cloudflare/Workers/HttpServer.ts +31 -25
  313. package/src/Cloudflare/Workers/InferEnv.ts +15 -8
  314. package/src/Cloudflare/Workers/LocalWorkerProvider.ts +139 -78
  315. package/src/Cloudflare/Workers/Rpc.ts +50 -0
  316. package/src/Cloudflare/Workers/RpcDurableObjectNamespace.ts +502 -0
  317. package/src/Cloudflare/Workers/RpcWorker.ts +562 -0
  318. package/src/Cloudflare/Workers/Vite.ts +2 -0
  319. package/src/Cloudflare/Workers/Worker.ts +274 -93
  320. package/src/Cloudflare/Workers/WorkerAsyncBindings.ts +158 -103
  321. package/src/Cloudflare/Workers/WorkerBinding.ts +10 -0
  322. package/src/Cloudflare/Workers/WorkerBridge.ts +7 -4
  323. package/src/Cloudflare/Workers/WorkerBundle.ts +4 -1
  324. package/src/Cloudflare/Workers/WorkerRuntimeContext.ts +8 -15
  325. package/src/Cloudflare/Workers/Workflow.ts +22 -3
  326. package/src/Cloudflare/Workers/index.ts +2 -0
  327. package/src/Cloudflare/index.ts +1 -0
  328. package/src/Dependencies.ts +10 -0
  329. package/src/Deploy.ts +3 -1
  330. package/src/Diff.ts +13 -0
  331. package/src/Input.ts +2 -0
  332. package/src/KeyPair.ts +146 -0
  333. package/src/Local/RpcProvider.ts +45 -1
  334. package/src/Local/RpcServerEnvironment.ts +1 -1
  335. package/src/Neon/Project.ts +16 -3
  336. package/src/Output.ts +8 -2
  337. package/src/Phase.ts +8 -0
  338. package/src/Plan.ts +16 -3
  339. package/src/Platform.ts +74 -27
  340. package/src/Random.ts +22 -27
  341. package/src/RuntimeContext.ts +23 -1
  342. package/src/Stack.ts +3 -3
  343. package/src/State/StateEncoding.ts +58 -7
  344. package/src/Test/Bun.ts +0 -3
  345. package/src/Test/Vitest.ts +0 -3
  346. package/src/Util/Duration.ts +21 -0
  347. package/src/Util/index.ts +0 -6
  348. package/src/Util/types.ts +9 -2
  349. package/src/index.ts +2 -3
  350. package/lib/Secret.d.ts +0 -50
  351. package/lib/Secret.d.ts.map +0 -1
  352. package/lib/Secret.js +0 -23
  353. package/lib/Secret.js.map +0 -1
  354. package/lib/Trait.d.ts +0 -43
  355. package/lib/Trait.d.ts.map +0 -1
  356. package/lib/Trait.js +0 -17
  357. package/lib/Trait.js.map +0 -1
  358. package/lib/Util/LocalhostDns.d.ts +0 -23
  359. package/lib/Util/LocalhostDns.d.ts.map +0 -1
  360. package/lib/Util/LocalhostDns.js +0 -46
  361. package/lib/Util/LocalhostDns.js.map +0 -1
  362. package/lib/Util/assert-never.d.ts +0 -12
  363. package/lib/Util/assert-never.d.ts.map +0 -1
  364. package/lib/Util/assert-never.js +0 -11
  365. package/lib/Util/assert-never.js.map +0 -1
  366. package/lib/Util/class.d.ts +0 -3
  367. package/lib/Util/class.d.ts.map +0 -1
  368. package/lib/Util/class.js +0 -1
  369. package/lib/Util/class.js.map +0 -1
  370. package/lib/Util/ignore.d.ts +0 -40
  371. package/lib/Util/ignore.d.ts.map +0 -1
  372. package/lib/Util/ignore.js +0 -591
  373. package/lib/Util/ignore.js.map +0 -1
  374. package/lib/Util/instance.d.ts +0 -4
  375. package/lib/Util/instance.d.ts.map +0 -1
  376. package/lib/Util/instance.js +0 -1
  377. package/lib/Util/instance.js.map +0 -1
  378. package/lib/Util/pointer.d.ts +0 -5
  379. package/lib/Util/pointer.d.ts.map +0 -1
  380. package/lib/Util/pointer.js +0 -1
  381. package/lib/Util/pointer.js.map +0 -1
  382. package/lib/Util/schema-to-type.d.ts +0 -42
  383. package/lib/Util/schema-to-type.d.ts.map +0 -1
  384. package/lib/Util/schema-to-type.js +0 -364
  385. package/lib/Util/schema-to-type.js.map +0 -1
  386. package/lib/Util/todo.d.ts +0 -3
  387. package/lib/Util/todo.d.ts.map +0 -1
  388. package/lib/Util/todo.js +0 -3
  389. package/lib/Util/todo.js.map +0 -1
  390. package/lib/Variable.d.ts +0 -29
  391. package/lib/Variable.d.ts.map +0 -1
  392. package/lib/Variable.js +0 -9
  393. package/lib/Variable.js.map +0 -1
  394. package/src/Secret.ts +0 -87
  395. package/src/Trait.ts +0 -105
  396. package/src/Util/LocalhostDns.ts +0 -52
  397. package/src/Util/assert-never.ts +0 -18
  398. package/src/Util/class.ts +0 -7
  399. package/src/Util/ignore.ts +0 -815
  400. package/src/Util/instance.ts +0 -9
  401. package/src/Util/pointer.ts +0 -5
  402. package/src/Util/schema-to-type.ts +0 -456
  403. package/src/Util/todo.ts +0 -4
  404. package/src/Variable.ts +0 -44
@@ -0,0 +1,562 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as HttpClient from "effect/unstable/http/HttpClient";
5
+ import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
6
+ import {
7
+ type Rpc,
8
+ RpcClient,
9
+ type RpcGroup,
10
+ RpcSerialization,
11
+ } from "effect/unstable/rpc";
12
+ import type * as RpcClientError from "effect/unstable/rpc/RpcClientError";
13
+ import type { Dependencies } from "../../Dependencies.ts";
14
+ import type { HttpEffect } from "../../Http.ts";
15
+ import type { Rpc as RpcShape } from "../../Rpc.ts";
16
+ import { effectClass, taggedFunction } from "../../Util/effect.ts";
17
+ import type { Worker, WorkerProps } from "./Worker.ts";
18
+ import { Worker as WorkerCtor, WorkerEnvironment } from "./Worker.ts";
19
+
20
+ /**
21
+ * Props for {@link RpcWorker}. Same shape as {@link WorkerProps} with
22
+ * an additional `schema` field carrying the rpc group definition.
23
+ */
24
+ export type RpcWorkerProps<Rpcs extends Rpc.Any> = Omit<
25
+ WorkerProps,
26
+ "schema"
27
+ > & {
28
+ /**
29
+ * The {@link RpcGroup.RpcGroup} served on this worker's `fetch`
30
+ * handler. The same value should be importable by any consumer of
31
+ * the worker (other workers or scripts using `RpcClient.make`).
32
+ */
33
+ readonly schema: RpcGroup.RpcGroup<Rpcs>;
34
+ };
35
+
36
+ // Context tag carrying the surrounding `RpcWorker` value, so
37
+ // `yield* RpcWorker` inside the impl resolves to the worker itself
38
+ // (mirrors `yield* Worker` semantics inside `Cloudflare.Worker`).
39
+ // Documented as part of the main `RpcWorker` JSDoc below.
40
+ export class RpcWorkerScope extends Context.Service<RpcWorkerScope, Worker>()(
41
+ "Cloudflare.RpcWorker",
42
+ ) {}
43
+
44
+ // Symbol used internally to stash the rpc `RpcGroup` schema on the
45
+ // `effectClass` that `RpcWorker(...)` returns, so `RpcWorker.bind`
46
+ // can recover it when handed the class later.
47
+ const SchemaSymbol = Symbol.for("alchemy.RpcWorker.schema");
48
+
49
+ // Phantom carrier — `RpcWorker.bind` uses `Rpcs` to type the returned
50
+ // rpc client. We don't tie it to a specific `Effect.R` since the
51
+ // requirements come from the underlying `Cloudflare.Worker` factory
52
+ // and shouldn't leak into the Stack-side service signature.
53
+ //
54
+ // `Deps` mirrors `Cloudflare.Worker<Self, Bindings, Deps>` — declares
55
+ // the DOs / Workers this script publishes for cross-script binding so
56
+ // `Counter.from(WorkerA)` type-checks from another script.
57
+ export interface RpcWorkerYieldable<
58
+ Self,
59
+ Rpcs extends Rpc.Any,
60
+ Deps = never,
61
+ > extends Effect.Effect<
62
+ Worker<{}> & RpcShape<Self> & Dependencies<Deps>,
63
+ never,
64
+ any
65
+ > {
66
+ /** @internal */
67
+ readonly [SchemaSymbol]: RpcGroup.RpcGroup<Rpcs>;
68
+ }
69
+
70
+ /**
71
+ * Type of the {@link RpcWorker} constructor. Mirrors the class-form
72
+ * signature of {@link Worker} so `class X extends RpcWorker<X>()(...)`
73
+ * works identically and the resulting worker is `Rpc<Self>`-typed for
74
+ * binding consumers.
75
+ */
76
+ export interface RpcWorkerClass extends Effect.Effect<
77
+ Worker,
78
+ never,
79
+ RpcWorkerScope
80
+ > {
81
+ /**
82
+ * Class-based form: `class X extends RpcWorker<X>()(name, props, impl)`.
83
+ *
84
+ * The optional second type argument `Deps` mirrors
85
+ * `Cloudflare.Worker<Self, Bindings, Deps>` — it declares the DOs
86
+ * this Worker publishes for cross-script binding so consumers can
87
+ * write `Counter.from(WorkerA)` and have it type-check. `Rpcs` is
88
+ * always inferred from `props.schema`.
89
+ *
90
+ * Yielding the class in a Stack returns the {@link Worker} resource
91
+ * (so `worker.url`, `worker.workerName`, etc. work as usual). To get
92
+ * a typed `RpcClient` for *this* worker's rpc group from inside
93
+ * another worker's init, call {@link RpcWorker.bind}.
94
+ */
95
+ <Self, Deps = never>(): {
96
+ /**
97
+ * Modular form (no impl). Mirrors `Cloudflare.Worker<Self>()(id, props)`.
98
+ * Use `WorkerClass.make(impl)` to provide the runtime as a
99
+ * `Layer.Layer<Self>` so consumers that don't host the worker can
100
+ * import the class without pulling its runtime into their bundle.
101
+ */
102
+ <Rpcs extends Rpc.Any>(
103
+ id: string,
104
+ props: RpcWorkerProps<Rpcs>,
105
+ ): RpcWorkerYieldable<Self, Rpcs, Deps> & {
106
+ new (_: never): {};
107
+ make<InnerR = never, InitReq = never>(
108
+ impl: Effect.Effect<
109
+ Effect.Effect<HttpEffect<InnerR>, never, InnerR>,
110
+ never,
111
+ InitReq
112
+ >,
113
+ ): Layer.Layer<Self, never, Exclude<InitReq | InnerR, never>>;
114
+ };
115
+ /** Inline-impl form. */
116
+ <Rpcs extends Rpc.Any, InnerR = never, InitReq = never>(
117
+ id: string,
118
+ props: RpcWorkerProps<Rpcs>,
119
+ impl: Effect.Effect<
120
+ Effect.Effect<HttpEffect<InnerR>, never, InnerR>,
121
+ never,
122
+ InitReq
123
+ >,
124
+ ): RpcWorkerYieldable<Self, Rpcs, Deps> & {
125
+ // Phantom — `class X extends RpcWorker<X>()(...)` carries `X`
126
+ // through the result type via `Rpc<Self>` on the binding side;
127
+ // the instance shape itself is empty (no methods exposed on
128
+ // `new X(...)` — everything goes through `fetch`).
129
+ new (_: never): {};
130
+ };
131
+ };
132
+
133
+ /**
134
+ * Bind a typed Effect rpc client to a worker resource, using the
135
+ * worker's declared rpc {@link RpcGroup.RpcGroup} schema. Mirrors
136
+ * `Cloudflare.R2Bucket.bind(MyBucket)` and friends.
137
+ *
138
+ * Yield once at **init** — the result is a normal `RpcClient` you
139
+ * can call directly from any per-request handler. Internally each
140
+ * method invocation builds a fresh underlying `RpcClient` (through
141
+ * a Proxy) because Cloudflare rejects I/O objects created on a
142
+ * previous request; this is hidden from the consumer.
143
+ *
144
+ * Pair with {@link RpcWorker} on the server side; both ends share
145
+ * the same schema so values round-trip through one `Schema` codec.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * // INIT: register the binding once and get the typed client
150
+ * const tasks = yield* Cloudflare.RpcWorker.bind(TaskWorker);
151
+ *
152
+ * // PER-REQUEST: call methods directly
153
+ * proxyGetTask: ({ id }) => tasks.getTask({ id }),
154
+ * ```
155
+ */
156
+ readonly bind: <Self, Rpcs extends Rpc.Any>(
157
+ workerEff: RpcWorkerYieldable<Self, Rpcs>,
158
+ ) => Effect.Effect<
159
+ RpcClient.RpcClient<Rpcs, RpcClientError.RpcClientError> & RpcShape<Self>,
160
+ never,
161
+ Worker
162
+ >;
163
+ }
164
+
165
+ /** @internal helper — exposed as `RpcWorker.bind` below. */
166
+ const bind = <Self, Rpcs extends Rpc.Any>(
167
+ workerEff: RpcWorkerYieldable<Self, Rpcs>,
168
+ ): Effect.Effect<
169
+ RpcClient.RpcClient<Rpcs, RpcClientError.RpcClientError> & RpcShape<Self>,
170
+ never,
171
+ Worker
172
+ > =>
173
+ Effect.gen(function* () {
174
+ const schema = (workerEff as unknown as Record<symbol, unknown>)[
175
+ SchemaSymbol
176
+ ] as RpcGroup.RpcGroup<Rpcs> | undefined;
177
+ if (!schema) {
178
+ return yield* Effect.die(
179
+ new Error(
180
+ "RpcWorker.bind: passed value isn't an RpcWorker class — no schema attached.",
181
+ ),
182
+ );
183
+ }
184
+ const worker = (yield* workerEff) as Worker;
185
+ // Register the service binding on the surrounding worker at INIT.
186
+ // Mirrors `Cloudflare.bindWorker` — yielding the class is *not*
187
+ // enough; we need an explicit `self.bind\`${worker}\`(...)` so
188
+ // workerd surfaces the stub on `env` at request time.
189
+ const self = yield* WorkerCtor;
190
+ yield* self.bind`${worker}`({
191
+ bindings: [
192
+ {
193
+ type: "service",
194
+ name: worker.LogicalId,
195
+ service: worker.workerName,
196
+ },
197
+ ],
198
+ });
199
+
200
+ // Build a per-call factory that wraps the Cloudflare service-
201
+ // binding stub (Promise-based fetch) into an Effect `HttpClient`,
202
+ // then `RpcClient.make` over that transport. Each call gets its
203
+ // own `RpcClient` because Cloudflare rejects I/O objects (the
204
+ // stub.fetch body) that were created on a previous request.
205
+ const makeFreshClient = Effect.gen(function* () {
206
+ const env = yield* WorkerEnvironment;
207
+ const stub = (env as Record<string, { fetch: typeof fetch }>)[
208
+ worker.LogicalId
209
+ ];
210
+ const httpClient = HttpClient.make((req) =>
211
+ Effect.promise((signal) =>
212
+ stub.fetch(
213
+ new Request(req.url, {
214
+ method: req.method,
215
+ headers: new Headers(req.headers as any),
216
+ body: (req.body as any)?.body ?? undefined,
217
+ signal,
218
+ }),
219
+ ),
220
+ ).pipe(Effect.map((res) => HttpClientResponse.fromWeb(req, res))),
221
+ );
222
+ const protocol = RpcClient.layerProtocolHttp({
223
+ url: "http://alchemy-rpc-worker/",
224
+ }).pipe(
225
+ Layer.provide(RpcSerialization.layerNdjson),
226
+ Layer.provide(Layer.succeed(HttpClient.HttpClient, httpClient)),
227
+ );
228
+ return yield* RpcClient.make(schema).pipe(Effect.provide(protocol));
229
+ });
230
+
231
+ // Return a Proxy that LOOKS like an `RpcClient<Rpcs>` but defers
232
+ // the actual `RpcClient` construction to call time. Mirrors
233
+ // `makeRpcStub` from `./Rpc.ts`: each method invocation builds a
234
+ // fresh client, runs the call inside `Effect.scoped`, and tears
235
+ // the client's scope down with the call. From the consumer's
236
+ // perspective this is a normal `RpcClient`:
237
+ //
238
+ // const tasks = yield* Cloudflare.RpcWorker.bind(TaskWorker);
239
+ // yield* tasks.getTask({ id: "abc" });
240
+ return new Proxy(
241
+ {},
242
+ {
243
+ get: (_target, method) => {
244
+ if (typeof method !== "string") return undefined;
245
+ return (...args: unknown[]) =>
246
+ Effect.gen(function* () {
247
+ const client = yield* makeFreshClient;
248
+ const fn = (
249
+ client as unknown as Record<
250
+ string,
251
+ (...a: unknown[]) => Effect.Effect<unknown, unknown, unknown>
252
+ >
253
+ )[method];
254
+ return yield* fn(...args);
255
+ }).pipe(Effect.scoped);
256
+ },
257
+ },
258
+ ) as RpcClient.RpcClient<Rpcs, RpcClientError.RpcClientError> &
259
+ RpcShape<Self>;
260
+ });
261
+
262
+ /**
263
+ * `RpcWorker` is a thin sugar over {@link Worker} for the common case
264
+ * where a worker's entire `fetch` surface is a typed Effect `RpcGroup`.
265
+ * It takes the rpc `schema` directly in props alongside `main`, and
266
+ * accepts an init Effect that returns the already-piped
267
+ * `RpcServer.toHttpEffect(...)`-producing Effect (no `{ fetch }`
268
+ * wrapper) — the wrapper plugs it into the worker's `fetch` for you.
269
+ *
270
+ * Functionally identical to writing `Cloudflare.Worker(...)` with
271
+ * `return { fetch: RpcServer.toHttpEffect(schema).pipe(...) }`; use
272
+ * whichever style you prefer.
273
+ *
274
+ * The class form (`class X extends Cloudflare.RpcWorker<X>()(...)`)
275
+ * carries `Self` through the result type as `Rpc<Self>`, so other
276
+ * workers binding to this one see the rpc shape pinned to `Self`.
277
+ *
278
+ * @resource
279
+ *
280
+ * @section Defining the rpc group
281
+ * @example Pure schema description
282
+ * The rpc group and its schemas live outside any worker so both the
283
+ * server (`RpcWorker`) and any consumers (`RpcClient.make` /
284
+ * `RpcDurableObjectNamespace`) import the same value.
285
+ * ```typescript
286
+ * import * as Schema from "effect/Schema";
287
+ * import { Rpc, RpcGroup } from "effect/unstable/rpc";
288
+ *
289
+ * export class TaskNotFound extends Schema.TaggedClass<TaskNotFound>()(
290
+ * "TaskNotFound",
291
+ * { id: Schema.String },
292
+ * ) {}
293
+ *
294
+ * const getTask = Rpc.make("getTask", {
295
+ * payload: { id: Schema.String },
296
+ * success: Schema.String,
297
+ * error: TaskNotFound,
298
+ * });
299
+ *
300
+ * export class TaskRpcs extends RpcGroup.make(getTask) {}
301
+ * ```
302
+ *
303
+ * @section Implementing the worker
304
+ * @example Class form (recommended)
305
+ * Mirrors `Cloudflare.Worker<Self>()(...)` — `class X extends ...`
306
+ * works the same. The init Effect builds a handlers `Layer` from the
307
+ * group and returns the `RpcServer.toHttpEffect(schema)`-piped Effect
308
+ * directly.
309
+ * ```typescript
310
+ * import * as Cloudflare from "alchemy/Cloudflare";
311
+ * import * as Effect from "effect/Effect";
312
+ * import * as Layer from "effect/Layer";
313
+ * import { RpcSerialization, RpcServer } from "effect/unstable/rpc";
314
+ * import { TaskRpcs } from "./rpcs.ts";
315
+ *
316
+ * export default class Worker extends Cloudflare.RpcWorker<Worker>()(
317
+ * "Worker",
318
+ * { main: import.meta.filename, schema: TaskRpcs },
319
+ * Effect.gen(function* () {
320
+ * const handlers = TaskRpcs.toLayer({
321
+ * getTask: ({ id }) => Effect.succeed(`task-${id}`),
322
+ * });
323
+ * return RpcServer.toHttpEffect(TaskRpcs).pipe(
324
+ * Effect.provide(Layer.mergeAll(handlers, RpcSerialization.layerJson)),
325
+ * );
326
+ * }),
327
+ * ) {}
328
+ * ```
329
+ *
330
+ * @example NDJSON for streaming rpcs
331
+ * If any rpc in the group is a streaming rpc, the wire serialization
332
+ * must be `RpcSerialization.layerNdjson` — streaming rpcs need
333
+ * newline framing on the wire.
334
+ * ```typescript
335
+ * return RpcServer.toHttpEffect(ChatRpcs).pipe(
336
+ * Effect.provide(handlers),
337
+ * Effect.provide(RpcSerialization.layerNdjson),
338
+ * );
339
+ * ```
340
+ *
341
+ * @section Modular form: separate the class from its runtime
342
+ * @example Class declaration with no impl + `static make(impl)`
343
+ * The inline class form above bundles the runtime into the class
344
+ * declaration. The two-arg form `(id, props)` declares the class
345
+ * as a pure tagged identifier; provide the runtime separately via
346
+ * `WorkerClass.make(impl)` so consumers can import the class for
347
+ * binding without pulling the host's runtime into their bundle.
348
+ * ```typescript
349
+ * export class TaskWorker extends Cloudflare.RpcWorker<TaskWorker>()(
350
+ * "TaskWorker",
351
+ * { main: import.meta.filename, schema: TaskRpcs },
352
+ * ) {}
353
+ *
354
+ * // Only the host script imports this default export; consumers
355
+ * // import the class above for `RpcWorker.bind(TaskWorker)`.
356
+ * export default TaskWorker.make(
357
+ * Effect.gen(function* () {
358
+ * const handlers = TaskRpcs.toLayer({
359
+ * getTask: ({ id }) => Effect.succeed(`task-${id}`),
360
+ * });
361
+ * return RpcServer.toHttpEffect(TaskRpcs).pipe(
362
+ * Effect.provide(Layer.mergeAll(handlers, RpcSerialization.layerJson)),
363
+ * );
364
+ * }),
365
+ * );
366
+ * ```
367
+ *
368
+ * @section Hosting a Durable Object for cross-script binding
369
+ * @example `RpcWorker<Self, Deps>()` declares published DOs
370
+ * The optional second type argument `Deps` mirrors
371
+ * `Cloudflare.Worker<Self, Bindings, Deps>` — it declares the DOs
372
+ * this Worker publishes for cross-script binding. With `Counter`
373
+ * named in `Deps`, any other Worker can write
374
+ * `Counter.from(TaskWorker)` and have it type-check.
375
+ * ```typescript
376
+ * import { Counter } from "./counter.ts";
377
+ *
378
+ * export class TaskWorker extends Cloudflare.RpcWorker<TaskWorker, Counter>()(
379
+ * "TaskWorker",
380
+ * { main: import.meta.filename, schema: TaskRpcs },
381
+ * ) {}
382
+ * ```
383
+ * See {@link RpcDurableObjectNamespace} for the consumer side
384
+ * (`Counter.from(TaskWorker)`).
385
+ *
386
+ * @section Binding it from another worker
387
+ * @example `Cloudflare.RpcWorker.bind(WorkerClass)`
388
+ * Inside another worker's init, `RpcWorker.bind(WorkerClass)`
389
+ * registers the service binding on the surrounding worker and returns
390
+ * a typed `RpcClient` you can call directly from any per-request
391
+ * handler. Internally each method invocation builds a fresh underlying
392
+ * client (because Cloudflare rejects cross-request reuse of the
393
+ * stub I/O), but that's hidden behind a Proxy so the consumer sees a
394
+ * normal `RpcClient`.
395
+ * ```typescript
396
+ * import TaskWorker from "./task-worker.ts";
397
+ *
398
+ * export default class Caller extends Cloudflare.RpcWorker<Caller>()(
399
+ * "Caller",
400
+ * { main: import.meta.filename, schema: CallerRpcs },
401
+ * Effect.gen(function* () {
402
+ * // INIT: register binding, get the typed client
403
+ * const tasks = yield* Cloudflare.RpcWorker.bind(TaskWorker);
404
+ *
405
+ * const handlers = CallerRpcs.toLayer({
406
+ * // PER-REQUEST: just call methods directly
407
+ * proxyGetTask: ({ id }) => tasks.getTask({ id }),
408
+ * });
409
+ * return RpcServer.toHttpEffect(CallerRpcs).pipe(
410
+ * Effect.provide(Layer.mergeAll(handlers, RpcSerialization.layerJson)),
411
+ * );
412
+ * }),
413
+ * ) {}
414
+ * ```
415
+ *
416
+ * @section Driving it from a test
417
+ * @example `Test.make` + `RpcClient.make`
418
+ * The same `RpcGroup` drives a typed client. `Test.make` deploys the
419
+ * stack once for the file; each test yields the deploy handle for its
420
+ * URL and calls procedures directly.
421
+ * ```typescript
422
+ * import { expect } from "@effect/vitest";
423
+ * import * as Cloudflare from "alchemy/Cloudflare";
424
+ * import * as Test from "alchemy/Test/Vitest";
425
+ * import * as Effect from "effect/Effect";
426
+ * import * as Layer from "effect/Layer";
427
+ * import * as Schedule from "effect/Schedule";
428
+ * import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
429
+ * import * as RpcClient from "effect/unstable/rpc/RpcClient";
430
+ * import * as RpcSerialization from "effect/unstable/rpc/RpcSerialization";
431
+ * import Stack from "../alchemy.run.ts";
432
+ * import { TaskRpcs } from "../src/rpcs.ts";
433
+ *
434
+ * const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
435
+ * providers: Cloudflare.providers(),
436
+ * });
437
+ * const stack = beforeAll(deploy(Stack));
438
+ * afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack));
439
+ *
440
+ * const layer = (url: string) =>
441
+ * RpcClient.layerProtocolHttp({ url }).pipe(
442
+ * Layer.provide(FetchHttpClient.layer),
443
+ * Layer.provide(
444
+ * Layer.succeed(RpcSerialization.RpcSerialization, RpcSerialization.json),
445
+ * ),
446
+ * );
447
+ *
448
+ * test(
449
+ * "getTask",
450
+ * Effect.gen(function* () {
451
+ * const { url } = yield* stack;
452
+ * yield* Effect.gen(function* () {
453
+ * const client = yield* RpcClient.make(TaskRpcs);
454
+ * const result = yield* client
455
+ * .getTask({ id: "abc" })
456
+ * .pipe(Effect.retry({ schedule: Schedule.exponential("500 millis"), times: 5 }));
457
+ * expect(result).toBe("task-abc");
458
+ * }).pipe(Effect.scoped, Effect.provide(layer(url)));
459
+ * }),
460
+ * );
461
+ * ```
462
+ *
463
+ * @section Yielding the surrounding worker from inside the impl
464
+ * @example `yield* RpcWorker` inside the init effect
465
+ * Mirrors `yield* DurableObjectNamespace` — yield the tag to access
466
+ * the surrounding worker.
467
+ * ```typescript
468
+ * Effect.gen(function* () {
469
+ * const self = yield* Cloudflare.RpcWorker;
470
+ * });
471
+ * ```
472
+ */
473
+ export const RpcWorker: RpcWorkerClass = (() => {
474
+ const fn = (...args: any[]) => {
475
+ // Class-form: zero args returns the inner builder. Inner-arg arity
476
+ // distinguishes modular (`(id, props)`, no impl — `static make(impl)`
477
+ // provides the runtime) from inline-impl (`(id, props, impl)`).
478
+ if (args.length === 0) {
479
+ return (...inner: any[]) => {
480
+ if (inner.length === 2) {
481
+ const [id, props] = inner as [string, RpcWorkerProps<any>];
482
+ return buildModular(id, props);
483
+ }
484
+ const [id, props, impl] = inner as [
485
+ string,
486
+ RpcWorkerProps<any>,
487
+ Effect.Effect<Effect.Effect<HttpEffect<any>>>,
488
+ ];
489
+ return build(id, props, impl);
490
+ };
491
+ }
492
+ // Bare form: `(name, props, impl)`.
493
+ const [id, props, impl] = args as [
494
+ string,
495
+ RpcWorkerProps<any>,
496
+ Effect.Effect<Effect.Effect<HttpEffect<any>>>,
497
+ ];
498
+ return build(id, props, impl);
499
+ };
500
+
501
+ const tagged = taggedFunction(RpcWorkerScope, fn as any) as any;
502
+ tagged.bind = bind;
503
+ return tagged;
504
+ })() as any;
505
+
506
+ const wrapImpl = (impl: Effect.Effect<Effect.Effect<HttpEffect<any>>>) =>
507
+ // The user's inner Effect resolves to `HttpEffect`; the underlying
508
+ // `Cloudflare.Worker` expects `{ fetch: HttpEffect }`. Box it.
509
+ Effect.map(
510
+ impl,
511
+ (fetch) => ({ fetch }) as unknown as { fetch: HttpEffect<any> },
512
+ );
513
+
514
+ const buildModular = (id: string, props: RpcWorkerProps<any>) => {
515
+ const { schema, ...workerProps } = props;
516
+ // Delegate to `Cloudflare.Worker<Self>()(id, props)` (modular form)
517
+ // so we inherit its `static make(impl)` plumbing for free. We just
518
+ // wrap the user's HttpEffect-returning impl into the `{ fetch }`
519
+ // shape `Cloudflare.Worker` expects, and stash the rpc schema on
520
+ // the class so `RpcWorker.bind(WorkerClass)` can recover it.
521
+ const Underlying: any = (WorkerCtor as any)()(id, workerProps);
522
+ const klass = class extends effectClass(
523
+ (Underlying as { asEffect(): Effect.Effect<Worker> }).asEffect(),
524
+ ) {
525
+ static make = (
526
+ impl: Effect.Effect<Effect.Effect<HttpEffect<any>>>,
527
+ ): Layer.Layer<any, never, any> => Underlying.make(wrapImpl(impl));
528
+ } as unknown as Record<symbol | string, unknown>;
529
+ klass[SchemaSymbol] = schema;
530
+ return klass;
531
+ };
532
+
533
+ const build = (
534
+ id: string,
535
+ props: RpcWorkerProps<any>,
536
+ impl: Effect.Effect<Effect.Effect<HttpEffect<any>>>,
537
+ ) => {
538
+ const { schema, ...workerProps } = props;
539
+
540
+ // Wrap the user's HttpEffect-returning Effect into the `{ fetch }`
541
+ // shape `Cloudflare.Worker` expects.
542
+ const wrappedImpl = Effect.map(
543
+ impl,
544
+ (fetch) => ({ fetch }) as unknown as { fetch: HttpEffect<any> },
545
+ );
546
+
547
+ // Delegate registration / binding metadata to the underlying
548
+ // `Cloudflare.Worker`. The returned `effectClass`, when yielded,
549
+ // produces the standard `Worker` resource (so `worker.url`,
550
+ // `worker.workerName`, etc. all work as usual).
551
+ const underlying = (WorkerCtor as any)()(id, workerProps, wrappedImpl);
552
+
553
+ // Re-wrap as our own `effectClass` so we can stash the rpc schema
554
+ // on the class for `RpcWorker.bind` to recover later. (Re-using
555
+ // `effectClass` here means `class X extends RpcWorker<X>()(...)`
556
+ // still works.)
557
+ const klass = effectClass(
558
+ (underlying as { asEffect(): Effect.Effect<Worker> }).asEffect(),
559
+ ) as unknown as Record<symbol, unknown>;
560
+ klass[SchemaSymbol] = schema;
561
+ return klass;
562
+ };
@@ -12,6 +12,7 @@ export const viteDev = (
12
12
  rootDir: string = process.cwd(),
13
13
  env: Record<string, unknown>,
14
14
  pluginOptions: CloudflareVitePluginOptions,
15
+ serverOptions: vite.ServerOptions,
15
16
  ) =>
16
17
  Effect.acquireRelease(
17
18
  Effect.promise(async () => {
@@ -20,6 +21,7 @@ export const viteDev = (
20
21
  root: rootDir,
21
22
  define: getDefine(env),
22
23
  plugins: [cloudflare(pluginOptions)],
24
+ server: serverOptions,
23
25
  });
24
26
  await devServer.listen();
25
27
  return devServer;