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.
- package/bin/alchemy.js +3 -3
- package/bin/alchemy.js.map +1 -1
- package/bin/commands/logs.ts +1 -1
- package/bin/commands/tail.ts +1 -1
- package/lib/AWS/Lambda/Function.d.ts.map +1 -1
- package/lib/AWS/Lambda/Function.js +25 -21
- package/lib/AWS/Lambda/Function.js.map +1 -1
- package/lib/AWS/Lambda/HttpServer.d.ts.map +1 -1
- package/lib/AWS/Lambda/HttpServer.js +3 -1
- package/lib/AWS/Lambda/HttpServer.js.map +1 -1
- package/lib/Cloudflare/Container/Container.d.ts +55 -2
- package/lib/Cloudflare/Container/Container.d.ts.map +1 -1
- package/lib/Cloudflare/Container/Container.js +55 -2
- package/lib/Cloudflare/Container/Container.js.map +1 -1
- package/lib/Cloudflare/D1/D1Clone.d.ts +13 -0
- package/lib/Cloudflare/D1/D1Clone.d.ts.map +1 -0
- package/lib/Cloudflare/D1/D1Clone.js +31 -0
- package/lib/Cloudflare/D1/D1Clone.js.map +1 -0
- package/lib/Cloudflare/D1/D1Database.d.ts +150 -5
- package/lib/Cloudflare/D1/D1Database.d.ts.map +1 -1
- package/lib/Cloudflare/D1/D1Database.js +253 -0
- package/lib/Cloudflare/D1/D1Database.js.map +1 -1
- package/lib/Cloudflare/D1/D1Export.d.ts +24 -0
- package/lib/Cloudflare/D1/D1Export.d.ts.map +1 -0
- package/lib/Cloudflare/D1/D1Export.js +34 -0
- package/lib/Cloudflare/D1/D1Export.js.map +1 -0
- package/lib/Cloudflare/D1/D1Import.d.ts +21 -0
- package/lib/Cloudflare/D1/D1Import.d.ts.map +1 -0
- package/lib/Cloudflare/D1/D1Import.js +87 -0
- package/lib/Cloudflare/D1/D1Import.js.map +1 -0
- package/lib/Cloudflare/D1/D1Migrations.d.ts +16 -0
- package/lib/Cloudflare/D1/D1Migrations.d.ts.map +1 -0
- package/lib/Cloudflare/D1/D1Migrations.js +110 -0
- package/lib/Cloudflare/D1/D1Migrations.js.map +1 -0
- package/lib/Cloudflare/D1/D1SqlFile.d.ts +20 -0
- package/lib/Cloudflare/D1/D1SqlFile.d.ts.map +1 -0
- package/lib/Cloudflare/D1/D1SqlFile.js +46 -0
- package/lib/Cloudflare/D1/D1SqlFile.js.map +1 -0
- package/lib/Cloudflare/Providers.d.ts +1 -1
- package/lib/Cloudflare/Providers.d.ts.map +1 -1
- package/lib/Cloudflare/Queue/Queue.d.ts +34 -4
- package/lib/Cloudflare/Queue/Queue.d.ts.map +1 -1
- package/lib/Cloudflare/Queue/Queue.js +34 -4
- package/lib/Cloudflare/Queue/Queue.js.map +1 -1
- package/lib/Cloudflare/Queue/QueueBinding.d.ts +33 -0
- package/lib/Cloudflare/Queue/QueueBinding.d.ts.map +1 -1
- package/lib/Cloudflare/Queue/QueueBinding.js +33 -0
- package/lib/Cloudflare/Queue/QueueBinding.js.map +1 -1
- package/lib/Cloudflare/Workers/DurableObjectNamespace.d.ts +103 -6
- package/lib/Cloudflare/Workers/DurableObjectNamespace.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/DurableObjectNamespace.js +103 -6
- package/lib/Cloudflare/Workers/DurableObjectNamespace.js.map +1 -1
- package/lib/Cloudflare/Workers/Workflow.d.ts +94 -0
- package/lib/Cloudflare/Workers/Workflow.d.ts.map +1 -1
- package/lib/Cloudflare/Workers/Workflow.js +94 -0
- package/lib/Cloudflare/Workers/Workflow.js.map +1 -1
- package/lib/Platform.js +1 -1
- package/lib/Platform.js.map +1 -1
- package/package.json +1 -1
- package/src/AWS/Lambda/Function.ts +30 -24
- package/src/AWS/Lambda/HttpServer.ts +3 -1
- package/src/Cloudflare/Container/Container.ts +55 -2
- package/src/Cloudflare/D1/D1Clone.ts +42 -0
- package/src/Cloudflare/D1/D1Database.ts +386 -3
- package/src/Cloudflare/D1/D1Export.ts +66 -0
- package/src/Cloudflare/D1/D1Import.ts +156 -0
- package/src/Cloudflare/D1/D1Migrations.ts +229 -0
- package/src/Cloudflare/D1/D1SqlFile.ts +55 -0
- package/src/Cloudflare/Queue/Queue.ts +34 -4
- package/src/Cloudflare/Queue/QueueBinding.ts +33 -0
- package/src/Cloudflare/Workers/DurableObjectNamespace.ts +103 -6
- package/src/Cloudflare/Workers/Workflow.ts +94 -0
- 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>]
|