alchemy 2.0.0-beta.21 → 2.0.0-beta.23

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 (73) hide show
  1. package/bin/alchemy.js +3 -3
  2. package/bin/alchemy.js.map +1 -1
  3. package/bin/commands/logs.ts +1 -1
  4. package/bin/commands/tail.ts +1 -1
  5. package/lib/AWS/Lambda/Function.d.ts.map +1 -1
  6. package/lib/AWS/Lambda/Function.js +25 -21
  7. package/lib/AWS/Lambda/Function.js.map +1 -1
  8. package/lib/AWS/Lambda/HttpServer.d.ts.map +1 -1
  9. package/lib/AWS/Lambda/HttpServer.js +3 -1
  10. package/lib/AWS/Lambda/HttpServer.js.map +1 -1
  11. package/lib/Cloudflare/Container/Container.d.ts +55 -2
  12. package/lib/Cloudflare/Container/Container.d.ts.map +1 -1
  13. package/lib/Cloudflare/Container/Container.js +55 -2
  14. package/lib/Cloudflare/Container/Container.js.map +1 -1
  15. package/lib/Cloudflare/D1/D1Clone.d.ts +13 -0
  16. package/lib/Cloudflare/D1/D1Clone.d.ts.map +1 -0
  17. package/lib/Cloudflare/D1/D1Clone.js +31 -0
  18. package/lib/Cloudflare/D1/D1Clone.js.map +1 -0
  19. package/lib/Cloudflare/D1/D1Database.d.ts +150 -5
  20. package/lib/Cloudflare/D1/D1Database.d.ts.map +1 -1
  21. package/lib/Cloudflare/D1/D1Database.js +253 -0
  22. package/lib/Cloudflare/D1/D1Database.js.map +1 -1
  23. package/lib/Cloudflare/D1/D1Export.d.ts +24 -0
  24. package/lib/Cloudflare/D1/D1Export.d.ts.map +1 -0
  25. package/lib/Cloudflare/D1/D1Export.js +34 -0
  26. package/lib/Cloudflare/D1/D1Export.js.map +1 -0
  27. package/lib/Cloudflare/D1/D1Import.d.ts +21 -0
  28. package/lib/Cloudflare/D1/D1Import.d.ts.map +1 -0
  29. package/lib/Cloudflare/D1/D1Import.js +87 -0
  30. package/lib/Cloudflare/D1/D1Import.js.map +1 -0
  31. package/lib/Cloudflare/D1/D1Migrations.d.ts +16 -0
  32. package/lib/Cloudflare/D1/D1Migrations.d.ts.map +1 -0
  33. package/lib/Cloudflare/D1/D1Migrations.js +110 -0
  34. package/lib/Cloudflare/D1/D1Migrations.js.map +1 -0
  35. package/lib/Cloudflare/D1/D1SqlFile.d.ts +20 -0
  36. package/lib/Cloudflare/D1/D1SqlFile.d.ts.map +1 -0
  37. package/lib/Cloudflare/D1/D1SqlFile.js +46 -0
  38. package/lib/Cloudflare/D1/D1SqlFile.js.map +1 -0
  39. package/lib/Cloudflare/Providers.d.ts +1 -1
  40. package/lib/Cloudflare/Providers.d.ts.map +1 -1
  41. package/lib/Cloudflare/Queue/Queue.d.ts +34 -4
  42. package/lib/Cloudflare/Queue/Queue.d.ts.map +1 -1
  43. package/lib/Cloudflare/Queue/Queue.js +34 -4
  44. package/lib/Cloudflare/Queue/Queue.js.map +1 -1
  45. package/lib/Cloudflare/Queue/QueueBinding.d.ts +33 -0
  46. package/lib/Cloudflare/Queue/QueueBinding.d.ts.map +1 -1
  47. package/lib/Cloudflare/Queue/QueueBinding.js +33 -0
  48. package/lib/Cloudflare/Queue/QueueBinding.js.map +1 -1
  49. package/lib/Cloudflare/Workers/DurableObjectNamespace.d.ts +103 -6
  50. package/lib/Cloudflare/Workers/DurableObjectNamespace.d.ts.map +1 -1
  51. package/lib/Cloudflare/Workers/DurableObjectNamespace.js +103 -6
  52. package/lib/Cloudflare/Workers/DurableObjectNamespace.js.map +1 -1
  53. package/lib/Cloudflare/Workers/Workflow.d.ts +94 -0
  54. package/lib/Cloudflare/Workers/Workflow.d.ts.map +1 -1
  55. package/lib/Cloudflare/Workers/Workflow.js +94 -0
  56. package/lib/Cloudflare/Workers/Workflow.js.map +1 -1
  57. package/lib/Platform.js +1 -1
  58. package/lib/Platform.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/AWS/Lambda/Function.ts +30 -24
  61. package/src/AWS/Lambda/HttpServer.ts +3 -1
  62. package/src/Cloudflare/Container/Container.ts +55 -2
  63. package/src/Cloudflare/D1/D1Clone.ts +42 -0
  64. package/src/Cloudflare/D1/D1Database.ts +386 -3
  65. package/src/Cloudflare/D1/D1Export.ts +66 -0
  66. package/src/Cloudflare/D1/D1Import.ts +156 -0
  67. package/src/Cloudflare/D1/D1Migrations.ts +229 -0
  68. package/src/Cloudflare/D1/D1SqlFile.ts +55 -0
  69. package/src/Cloudflare/Queue/Queue.ts +34 -4
  70. package/src/Cloudflare/Queue/QueueBinding.ts +33 -0
  71. package/src/Cloudflare/Workers/DurableObjectNamespace.ts +103 -6
  72. package/src/Cloudflare/Workers/Workflow.ts +94 -0
  73. package/src/Platform.ts +1 -1
@@ -248,6 +248,36 @@ export class WorkflowScope extends Context.Service<
248
248
  * yield* Cloudflare.sleep("cooldown", "30 seconds");
249
249
  * ```
250
250
  *
251
+ * @example Accessing env bindings inside a step
252
+ * `Cloudflare.WorkerEnvironment` is the same service available
253
+ * inside a Worker — it gives you typed access to env bindings (KV,
254
+ * R2, etc.) from inside a workflow body. Wrap any side-effecting
255
+ * call in `task` so the result is persisted across replays.
256
+ *
257
+ * ```typescript
258
+ * Effect.gen(function* () {
259
+ * const env = yield* Cloudflare.WorkerEnvironment;
260
+ * const event = yield* Cloudflare.WorkflowEvent;
261
+ * const { roomId, message } = event.payload as {
262
+ * roomId: string;
263
+ * message: string;
264
+ * };
265
+ *
266
+ * const stored = yield* Cloudflare.task(
267
+ * "kv-roundtrip",
268
+ * Effect.tryPromise({
269
+ * try: async () => {
270
+ * await env.KV.put(`workflow:${roomId}`, message);
271
+ * return await env.KV.get(`workflow:${roomId}`);
272
+ * },
273
+ * catch: (cause) =>
274
+ * cause instanceof Error ? cause : new Error(String(cause)),
275
+ * }).pipe(Effect.orDie),
276
+ * );
277
+ * return stored;
278
+ * });
279
+ * ```
280
+ *
251
281
  * @section Starting and Monitoring Instances
252
282
  * @example Creating an instance from a Worker
253
283
  * ```typescript
@@ -261,6 +291,70 @@ export class WorkflowScope extends Context.Service<
261
291
  * const handle = yield* workflow.get(instanceId);
262
292
  * const status = yield* handle.status();
263
293
  * ```
294
+ *
295
+ * @section Triggering from a Worker
296
+ * Wire the workflow into HTTP routes so callers can fire instances
297
+ * and poll for completion.
298
+ *
299
+ * @example Workflow start + status routes
300
+ * ```typescript
301
+ * // src/worker.ts
302
+ * const notifier = yield* MyWorkflow;
303
+ *
304
+ * return {
305
+ * fetch: Effect.gen(function* () {
306
+ * const request = yield* HttpServerRequest;
307
+ *
308
+ * if (request.url.startsWith("/workflow/start/")) {
309
+ * const id = request.url.split("/").pop()!;
310
+ * const instance = yield* notifier.create({ id });
311
+ * return HttpServerResponse.json({ instanceId: instance.id });
312
+ * }
313
+ *
314
+ * if (request.url.startsWith("/workflow/status/")) {
315
+ * const id = request.url.split("/").pop()!;
316
+ * const instance = yield* notifier.get(id);
317
+ * return HttpServerResponse.json(yield* instance.status());
318
+ * }
319
+ *
320
+ * return HttpServerResponse.text("Not Found", { status: 404 });
321
+ * }),
322
+ * };
323
+ * ```
324
+ *
325
+ * @section Testing Workflows
326
+ * Workflows run asynchronously, so tests start an instance and
327
+ * poll until it reaches a terminal status. A simple recipe with
328
+ * `alchemy/Test/Bun`:
329
+ *
330
+ * @example Polling for workflow completion
331
+ * ```typescript
332
+ * test(
333
+ * "workflow completes",
334
+ * Effect.gen(function* () {
335
+ * const { url } = yield* stack;
336
+ *
337
+ * const start = yield* HttpClient.post(`${url}/workflow/start/x`);
338
+ * const { instanceId } = (yield* start.json) as { instanceId: string };
339
+ *
340
+ * let status: { status: string } | undefined;
341
+ * const deadline = Date.now() + 60_000;
342
+ * while (Date.now() < deadline) {
343
+ * const res = yield* HttpClient.get(
344
+ * `${url}/workflow/status/${instanceId}`,
345
+ * );
346
+ * status = (yield* res.json) as { status: string };
347
+ * if (status.status === "complete" || status.status === "errored") {
348
+ * break;
349
+ * }
350
+ * yield* Effect.sleep("2 seconds");
351
+ * }
352
+ *
353
+ * expect(status?.status).toBe("complete");
354
+ * }),
355
+ * { timeout: 120_000 },
356
+ * );
357
+ * ```
264
358
  */
265
359
  export const Workflow: WorkflowClass = taggedFunction(WorkflowScope, ((
266
360
  ...args: [] | [name: string, impl: Effect.Effect<WorkflowBody>]
package/src/Platform.ts CHANGED
@@ -326,7 +326,7 @@ export const Platform = <
326
326
 
327
327
  yield* impl.pipe(
328
328
  Effect.flatMap((impl) =>
329
- impl
329
+ impl?.fetch
330
330
  ? (executionContext.serve?.(impl.fetch) ??
331
331
  Effect.die("No serve handler"))
332
332
  : Effect.void,