@lunora/workflow 1.0.0-alpha.2 → 1.0.0-alpha.20
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/LICENSE.md +6 -0
- package/dist/do/index.d.mts +16 -16
- package/dist/do/index.d.ts +16 -16
- package/dist/do/index.mjs +1 -32
- package/dist/index.d.mts +127 -132
- package/dist/index.d.ts +127 -132
- package/dist/index.mjs +1 -8
- package/dist/packem_shared/MAX_BRANCHES-L0FzeGTH.mjs +1 -0
- package/dist/packem_shared/NonRetryableError-CXD-mZe4.mjs +1 -0
- package/dist/packem_shared/WorkflowsRestError--PIoe9uw.mjs +1 -0
- package/dist/packem_shared/branch-marker-B2lebQA6.mjs +1 -0
- package/dist/packem_shared/createRunStep-CzGKC1eZ.mjs +1 -0
- package/dist/packem_shared/createWorkflowContext-Dw8a1U68.mjs +1 -0
- package/dist/packem_shared/createWorkflowRunContext-BNh1APpj.mjs +1 -0
- package/dist/packem_shared/createWorkflows-3djec-oS.mjs +1 -0
- package/dist/packem_shared/defineStep-rJ0XPdAx.mjs +1 -0
- package/dist/packem_shared/defineWorkflow-fBuCDkGT.mjs +1 -0
- package/dist/packem_shared/{types.d-CQO_koGe.d.mts → types.d-DZlXmeGi.d.mts} +161 -80
- package/dist/packem_shared/{types.d-CQO_koGe.d.ts → types.d-DZlXmeGi.d.ts} +161 -80
- package/package.json +4 -3
- package/dist/packem_shared/NonRetryableError-Dn2dTyBS.mjs +0 -27
- package/dist/packem_shared/WorkflowsRestError-b06i7K5j.mjs +0 -118
- package/dist/packem_shared/createRunStep-8jOXxP2o.mjs +0 -54
- package/dist/packem_shared/createWorkflowContext-D6thzmlF.mjs +0 -14
- package/dist/packem_shared/createWorkflowLogger-DR8P4ZoY.mjs +0 -76
- package/dist/packem_shared/createWorkflows-BoSYVIXg.mjs +0 -23
- package/dist/packem_shared/defineStep-DJQtLw7g.mjs +0 -28
- package/dist/packem_shared/defineWorkflow-DbUC-oCN.mjs +0 -15
package/LICENSE.md
CHANGED
|
@@ -103,3 +103,9 @@ Unless required by applicable law or agreed to in writing, software distributed
|
|
|
103
103
|
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
104
|
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
105
|
specific language governing permissions and limitations under the License.
|
|
106
|
+
|
|
107
|
+
<!-- DEPENDENCIES -->
|
|
108
|
+
<!-- /DEPENDENCIES -->
|
|
109
|
+
|
|
110
|
+
<!-- TYPE_DEPENDENCIES -->
|
|
111
|
+
<!-- /TYPE_DEPENDENCIES -->
|
package/dist/do/index.d.mts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
-
import { W as WorkflowDefinition } from "../packem_shared/types.d-
|
|
2
|
+
import { W as WorkflowDefinition } from "../packem_shared/types.d-DZlXmeGi.mjs";
|
|
3
3
|
import '@lunora/values';
|
|
4
4
|
/**
|
|
5
|
-
* Base class for the generated `WorkflowEntrypoint` classes. Applies a
|
|
6
|
-
* `defineWorkflow` definition onto Cloudflare's `WorkflowEntrypoint`: `run`
|
|
7
|
-
* assembles the Lunora context (native `step`/`event` + the `ctx.run` function
|
|
8
|
-
* dispatcher + a logger) and invokes the user's handler.
|
|
9
|
-
*
|
|
10
|
-
* Generated subclasses stay one line of behavior:
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* export class OrderPipelineWorkflow extends LunoraWorkflow {
|
|
14
|
-
* constructor(ctx: ExecutionContext, env: Record<string, unknown>) {
|
|
15
|
-
* super(ctx, env, orderPipeline, "orderPipeline");
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
5
|
+
* Base class for the generated `WorkflowEntrypoint` classes. Applies a
|
|
6
|
+
* `defineWorkflow` definition onto Cloudflare's `WorkflowEntrypoint`: `run`
|
|
7
|
+
* assembles the Lunora context (native `step`/`event` + the `ctx.run` function
|
|
8
|
+
* dispatcher + a logger) and invokes the user's handler.
|
|
9
|
+
*
|
|
10
|
+
* Generated subclasses stay one line of behavior:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* export class OrderPipelineWorkflow extends LunoraWorkflow {
|
|
14
|
+
* constructor(ctx: ExecutionContext, env: Record<string, unknown>) {
|
|
15
|
+
* super(ctx, env, orderPipeline, "orderPipeline");
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
20
|
declare class LunoraWorkflow<Params = Record<string, unknown>, Output = unknown> extends WorkflowEntrypoint<Record<string, unknown>, Params> {
|
|
21
21
|
#private;
|
|
22
22
|
constructor(context: ConstructorParameters<typeof WorkflowEntrypoint>[0], env: Record<string, unknown>, definition: WorkflowDefinition<Params, Output>, exportName?: string);
|
package/dist/do/index.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
-
import { W as WorkflowDefinition } from "../packem_shared/types.d-
|
|
2
|
+
import { W as WorkflowDefinition } from "../packem_shared/types.d-DZlXmeGi.js";
|
|
3
3
|
import '@lunora/values';
|
|
4
4
|
/**
|
|
5
|
-
* Base class for the generated `WorkflowEntrypoint` classes. Applies a
|
|
6
|
-
* `defineWorkflow` definition onto Cloudflare's `WorkflowEntrypoint`: `run`
|
|
7
|
-
* assembles the Lunora context (native `step`/`event` + the `ctx.run` function
|
|
8
|
-
* dispatcher + a logger) and invokes the user's handler.
|
|
9
|
-
*
|
|
10
|
-
* Generated subclasses stay one line of behavior:
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* export class OrderPipelineWorkflow extends LunoraWorkflow {
|
|
14
|
-
* constructor(ctx: ExecutionContext, env: Record<string, unknown>) {
|
|
15
|
-
* super(ctx, env, orderPipeline, "orderPipeline");
|
|
16
|
-
* }
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
5
|
+
* Base class for the generated `WorkflowEntrypoint` classes. Applies a
|
|
6
|
+
* `defineWorkflow` definition onto Cloudflare's `WorkflowEntrypoint`: `run`
|
|
7
|
+
* assembles the Lunora context (native `step`/`event` + the `ctx.run` function
|
|
8
|
+
* dispatcher + a logger) and invokes the user's handler.
|
|
9
|
+
*
|
|
10
|
+
* Generated subclasses stay one line of behavior:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* export class OrderPipelineWorkflow extends LunoraWorkflow {
|
|
14
|
+
* constructor(ctx: ExecutionContext, env: Record<string, unknown>) {
|
|
15
|
+
* super(ctx, env, orderPipeline, "orderPipeline");
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
20
|
declare class LunoraWorkflow<Params = Record<string, unknown>, Output = unknown> extends WorkflowEntrypoint<Record<string, unknown>, Params> {
|
|
21
21
|
#private;
|
|
22
22
|
constructor(context: ConstructorParameters<typeof WorkflowEntrypoint>[0], env: Record<string, unknown>, definition: WorkflowDefinition<Params, Output>, exportName?: string);
|
package/dist/do/index.mjs
CHANGED
|
@@ -1,32 +1 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NonRetryableError } from 'cloudflare:workflows';
|
|
3
|
-
import { convertNonRetryableError } from '../packem_shared/NonRetryableError-Dn2dTyBS.mjs';
|
|
4
|
-
import { createWorkflowRunContext } from '../packem_shared/createWorkflowLogger-DR8P4ZoY.mjs';
|
|
5
|
-
|
|
6
|
-
class LunoraWorkflow extends WorkflowEntrypoint {
|
|
7
|
-
/** The `lunora/workflows.ts` export name, for log correlation. */
|
|
8
|
-
#lunoraName;
|
|
9
|
-
/** The `defineWorkflow` result this entrypoint runs. */
|
|
10
|
-
#definition;
|
|
11
|
-
constructor(context, env, definition, exportName) {
|
|
12
|
-
super(context, env);
|
|
13
|
-
this.#definition = definition;
|
|
14
|
-
this.#lunoraName = exportName ?? "workflow";
|
|
15
|
-
}
|
|
16
|
-
async run(event, step) {
|
|
17
|
-
const context = createWorkflowRunContext({
|
|
18
|
-
env: this.env,
|
|
19
|
-
event,
|
|
20
|
-
exportName: this.#lunoraName,
|
|
21
|
-
nonRetryableErrorClass: NonRetryableError,
|
|
22
|
-
step
|
|
23
|
-
});
|
|
24
|
-
try {
|
|
25
|
-
return await this.#definition.handler(context);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
return convertNonRetryableError(error, NonRetryableError);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { LunoraWorkflow as default };
|
|
1
|
+
import{WorkflowEntrypoint as c}from"cloudflare:workers";import{NonRetryableError as i}from"cloudflare:workflows";import{convertNonRetryableError as m}from"../packem_shared/NonRetryableError-CXD-mZe4.mjs";import{extractBranchMarker as h,stripBranchMarker as f,signalBranchParentSafe as l,errorOutcome as u,okOutcome as v}from"../packem_shared/MAX_BRANCHES-L0FzeGTH.mjs";import{createWorkflowRunContext as y}from"../packem_shared/createWorkflowRunContext-BNh1APpj.mjs";class b extends c{#r;#t;constructor(t,e,a,r){super(t,e),this.#t=a,this.#r=r??"workflow"}async run(t,e){const a=e,r=h(t.payload),p=r?{...t,payload:f(t.payload)}:t,o=y({env:this.env,event:p,exportName:this.#r,nonRetryableErrorClass:i,step:a});let n;try{n=await this.#t.handler(o)}catch(s){return r&&await l({env:this.env,log:o.log,step:a},r,u(s)),m(s,i)}return r&&await l({env:this.env,log:o.log,step:a},r,v(n)),n}}export{b as default};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { a as Workflows, L as LunoraWorkflowsOptions, S as StepArgsValidator, b as StepConfig, c as StepDefinition, d as WorkflowConfig, W as WorkflowDefinition, e as
|
|
2
|
-
export type { A as ArgsOf, F as FunctionReference, I as InferStepArgs, R as RunFunctionOptions,
|
|
1
|
+
import { a as Workflows, L as LunoraWorkflowsOptions, S as StepArgsValidator, b as StepConfig, c as StepDefinition, d as WorkflowConfig, W as WorkflowDefinition, e as WorkflowBranch, f as WorkflowInstanceStatus, g as WorkflowEventLike, h as WorkflowStepLike, i as WorkflowRunContext, j as WorkflowLogger, k as WorkflowRunFunction, l as WorkflowRunStepFunction } from "./packem_shared/types.d-DZlXmeGi.mjs";
|
|
2
|
+
export type { A as ArgsOf, B as BranchCompensationParams, F as FunctionReference, I as InferStepArgs, R as RunFunctionOptions, m as RunStepOptions, n as StepHandler, o as StepRollbackContext, p as StepRollbackHandler, q as StepRunContext, r as WorkflowBindingLike, s as WorkflowBranchOutputs, t as WorkflowCreateOptions, u as WorkflowHandle, v as WorkflowHandler, w as WorkflowInstanceLike, x as WorkflowParallelFunction, y as WorkflowRollbackContextLike, z as WorkflowRollbackHandlerLike, C as WorkflowSpawnFunction, D as WorkflowSpawnOptions, E as WorkflowStatusResult, G as WorkflowStepConfigLike, H as WorkflowStepContextLike, J as WorkflowStepRollbackOptionsLike } from "./packem_shared/types.d-DZlXmeGi.mjs";
|
|
3
|
+
import { LunoraError } from '@lunora/errors';
|
|
3
4
|
import '@lunora/values';
|
|
4
5
|
/** Wiring info for one declared workflow, emitted by codegen into the generated shard. */
|
|
5
6
|
interface WorkflowBindingSpec {
|
|
@@ -9,108 +10,108 @@ interface WorkflowBindingSpec {
|
|
|
9
10
|
exportName: string;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
|
-
* Build the `ctx.workflows` handle for a request: resolve every spec's
|
|
13
|
-
* `env[binding]` into the `exportName → Workflow binding` map and wrap it in
|
|
14
|
-
* {@link createWorkflows}. A spec whose binding is absent from `env` is skipped
|
|
15
|
-
* here — the helpful "no workflow named …" error is raised lazily by
|
|
16
|
-
* `workflows.get(name)` when the missing workflow is actually used.
|
|
17
|
-
*/
|
|
13
|
+
* Build the `ctx.workflows` handle for a request: resolve every spec's
|
|
14
|
+
* `env[binding]` into the `exportName → Workflow binding` map and wrap it in
|
|
15
|
+
* {@link createWorkflows}. A spec whose binding is absent from `env` is skipped
|
|
16
|
+
* here — the helpful "no workflow named …" error is raised lazily by
|
|
17
|
+
* `workflows.get(name)` when the missing workflow is actually used.
|
|
18
|
+
*/
|
|
18
19
|
declare const createWorkflowContext: (env: Record<string, unknown>, specs: ReadonlyArray<WorkflowBindingSpec>) => Workflows;
|
|
19
20
|
/**
|
|
20
|
-
* Build the `ctx.workflows` handle from a map of `lunora/workflows.ts` export
|
|
21
|
-
* name → Cloudflare `Workflow` binding. `get(name)` resolves the typed handle;
|
|
22
|
-
* an unknown name throws with the list of declared workflows.
|
|
23
|
-
*/
|
|
21
|
+
* Build the `ctx.workflows` handle from a map of `lunora/workflows.ts` export
|
|
22
|
+
* name → Cloudflare `Workflow` binding. `get(name)` resolves the typed handle;
|
|
23
|
+
* an unknown name throws with the list of declared workflows.
|
|
24
|
+
*/
|
|
24
25
|
declare const createWorkflows: (options: LunoraWorkflowsOptions) => Workflows;
|
|
25
26
|
/**
|
|
26
|
-
* Declare a reusable durable step. Same `args` map shape a Lunora `query` /
|
|
27
|
-
* `mutation` / `action` uses, so a step reads like a function:
|
|
28
|
-
*
|
|
29
|
-
* ```ts
|
|
30
|
-
* // lunora/steps.ts
|
|
31
|
-
* import { defineStep } from "@lunora/workflow";
|
|
32
|
-
* import { v } from "@lunora/values";
|
|
33
|
-
*
|
|
34
|
-
* export const fetchImage = defineStep("fetch image", {
|
|
35
|
-
* args: { imageKey: v.string() },
|
|
36
|
-
* returns: v.object({ data: v.bytes() }),
|
|
37
|
-
* handler: async (ctx, { imageKey }) => {
|
|
38
|
-
* const object = await (ctx.env.BUCKET as R2Bucket).get(imageKey);
|
|
39
|
-
* return { data: new Uint8Array(await object!.arrayBuffer()) };
|
|
40
|
-
* },
|
|
41
|
-
* rollback: async (ctx) => {
|
|
42
|
-
* await (ctx.env.BUCKET as R2Bucket).delete(`tmp/${ctx.args.imageKey}`);
|
|
43
|
-
* },
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* Then, inside a `defineWorkflow` handler:
|
|
48
|
-
*
|
|
49
|
-
* ```ts
|
|
50
|
-
* const { data } = await ctx.runStep(fetchImage, { imageKey: ctx.params.imageKey });
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
27
|
+
* Declare a reusable durable step. Same `args` map shape a Lunora `query` /
|
|
28
|
+
* `mutation` / `action` uses, so a step reads like a function:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* // lunora/steps.ts
|
|
32
|
+
* import { defineStep } from "@lunora/workflow";
|
|
33
|
+
* import { v } from "@lunora/values";
|
|
34
|
+
*
|
|
35
|
+
* export const fetchImage = defineStep("fetch image", {
|
|
36
|
+
* args: { imageKey: v.string() },
|
|
37
|
+
* returns: v.object({ data: v.bytes() }),
|
|
38
|
+
* handler: async (ctx, { imageKey }) => {
|
|
39
|
+
* const object = await (ctx.env.BUCKET as R2Bucket).get(imageKey);
|
|
40
|
+
* return { data: new Uint8Array(await object!.arrayBuffer()) };
|
|
41
|
+
* },
|
|
42
|
+
* rollback: async (ctx) => {
|
|
43
|
+
* await (ctx.env.BUCKET as R2Bucket).delete(`tmp/${ctx.args.imageKey}`);
|
|
44
|
+
* },
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* Then, inside a `defineWorkflow` handler:
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* const { data } = await ctx.runStep(fetchImage, { imageKey: ctx.params.imageKey });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
53
54
|
declare const defineStep: <A extends StepArgsValidator, Result>(name: string, config: StepConfig<A, Result>) => StepDefinition<A, Result>;
|
|
54
55
|
/** True when a value is a `defineStep` result (the runtime brand check). */
|
|
55
56
|
declare const isStepDefinition: (value: unknown) => value is StepDefinition;
|
|
56
57
|
/**
|
|
57
|
-
* The generated `WorkflowEntrypoint` class name for a `lunora/workflows.ts`
|
|
58
|
-
* export: `orderPipeline` → `OrderPipelineWorkflow`. wrangler's
|
|
59
|
-
* `workflows[].class_name` references it, so codegen and the config layer MUST
|
|
60
|
-
* derive it identically — always via this helper.
|
|
61
|
-
*/
|
|
58
|
+
* The generated `WorkflowEntrypoint` class name for a `lunora/workflows.ts`
|
|
59
|
+
* export: `orderPipeline` → `OrderPipelineWorkflow`. wrangler's
|
|
60
|
+
* `workflows[].class_name` references it, so codegen and the config layer MUST
|
|
61
|
+
* derive it identically — always via this helper.
|
|
62
|
+
*/
|
|
62
63
|
declare const workflowClassName: (exportName: string) => string;
|
|
63
64
|
/**
|
|
64
|
-
* The wrangler binding name for a workflow export: `orderPipeline` →
|
|
65
|
-
* `WORKFLOW_ORDER_PIPELINE`, `etl` → `WORKFLOW_ETL`. The `WORKFLOW_` prefix
|
|
66
|
-
* namespaces these away from `SHARD`/`SESSION`/`SCHEDULER`/`CONTAINER_*` so a
|
|
67
|
-
* workflow export can never collide with the built-in bindings.
|
|
68
|
-
*/
|
|
65
|
+
* The wrangler binding name for a workflow export: `orderPipeline` →
|
|
66
|
+
* `WORKFLOW_ORDER_PIPELINE`, `etl` → `WORKFLOW_ETL`. The `WORKFLOW_` prefix
|
|
67
|
+
* namespaces these away from `SHARD`/`SESSION`/`SCHEDULER`/`CONTAINER_*` so a
|
|
68
|
+
* workflow export can never collide with the built-in bindings.
|
|
69
|
+
*/
|
|
69
70
|
declare const workflowBindingName: (exportName: string) => string;
|
|
70
71
|
/**
|
|
71
|
-
* The stable workflow name wrangler registers (`workflows[].name`):
|
|
72
|
-
* `orderPipeline` → `order-pipeline`. Used as the deployed workflow's
|
|
73
|
-
* identifier when no explicit `name` override is given.
|
|
74
|
-
*/
|
|
72
|
+
* The stable workflow name wrangler registers (`workflows[].name`):
|
|
73
|
+
* `orderPipeline` → `order-pipeline`. Used as the deployed workflow's
|
|
74
|
+
* identifier when no explicit `name` override is given.
|
|
75
|
+
*/
|
|
75
76
|
declare const workflowDefaultName: (exportName: string) => string;
|
|
76
77
|
/**
|
|
77
|
-
* Declare a durable workflow deployed alongside the app. Pure validation +
|
|
78
|
-
* branding: codegen discovers the export, emits the `WorkflowEntrypoint`
|
|
79
|
-
* subclass (`_generated/workflows.ts`), and wires the typed `ctx.workflows`
|
|
80
|
-
* handle; the config layer reconciles the wrangler `workflows[]` entry from the
|
|
81
|
-
* same definition.
|
|
82
|
-
*
|
|
83
|
-
* ```ts
|
|
84
|
-
* // lunora/workflows.ts
|
|
85
|
-
* import { defineWorkflow } from "@lunora/workflow";
|
|
86
|
-
* import { api } from "./_generated/api";
|
|
87
|
-
*
|
|
88
|
-
* export const orderPipeline = defineWorkflow<{ orderId: string }>({
|
|
89
|
-
* handler: async (ctx) => {
|
|
90
|
-
* const order = await ctx.step.do("load", () => ctx.run(api.orders.get, { id: ctx.params.orderId }));
|
|
91
|
-
* await ctx.step.sleep("cool-off", "1 minute");
|
|
92
|
-
* await ctx.step.do("charge", () => ctx.run(api.payments.charge, { orderId: ctx.params.orderId }));
|
|
93
|
-
* return order;
|
|
94
|
-
* },
|
|
95
|
-
* });
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
78
|
+
* Declare a durable workflow deployed alongside the app. Pure validation +
|
|
79
|
+
* branding: codegen discovers the export, emits the `WorkflowEntrypoint`
|
|
80
|
+
* subclass (`_generated/workflows.ts`), and wires the typed `ctx.workflows`
|
|
81
|
+
* handle; the config layer reconciles the wrangler `workflows[]` entry from the
|
|
82
|
+
* same definition.
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* // lunora/workflows.ts
|
|
86
|
+
* import { defineWorkflow } from "@lunora/workflow";
|
|
87
|
+
* import { api } from "./_generated/api";
|
|
88
|
+
*
|
|
89
|
+
* export const orderPipeline = defineWorkflow<{ orderId: string }>({
|
|
90
|
+
* handler: async (ctx) => {
|
|
91
|
+
* const order = await ctx.step.do("load", () => ctx.run(api.orders.get, { id: ctx.params.orderId }));
|
|
92
|
+
* await ctx.step.sleep("cool-off", "1 minute");
|
|
93
|
+
* await ctx.step.do("charge", () => ctx.run(api.payments.charge, { orderId: ctx.params.orderId }));
|
|
94
|
+
* return order;
|
|
95
|
+
* },
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
98
99
|
declare const defineWorkflow: <Params = Record<string, unknown>, Output = unknown>(config: WorkflowConfig<Params, Output>) => WorkflowDefinition<Params, Output>;
|
|
99
100
|
/** True when a value is a `defineWorkflow` result (the runtime brand check). */
|
|
100
101
|
declare const isWorkflowDefinition: (value: unknown) => value is WorkflowDefinition;
|
|
101
102
|
/**
|
|
102
|
-
* Throw from a workflow step (or handler) to fail the instance immediately
|
|
103
|
-
* **without** retrying — the portable mirror of `cloudflare:workflows`'
|
|
104
|
-
* `NonRetryableError`. Importable from Node, so workflow code stays unit-testable.
|
|
105
|
-
*
|
|
106
|
-
* ```ts
|
|
107
|
-
* import { NonRetryableError } from "@lunora/workflow";
|
|
108
|
-
*
|
|
109
|
-
* if (order.status === "cancelled") {
|
|
110
|
-
* throw new NonRetryableError("order already cancelled — no point retrying");
|
|
111
|
-
* }
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
103
|
+
* Throw from a workflow step (or handler) to fail the instance immediately
|
|
104
|
+
* **without** retrying — the portable mirror of `cloudflare:workflows`'
|
|
105
|
+
* `NonRetryableError`. Importable from Node, so workflow code stays unit-testable.
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { NonRetryableError } from "@lunora/workflow";
|
|
109
|
+
*
|
|
110
|
+
* if (order.status === "cancelled") {
|
|
111
|
+
* throw new NonRetryableError("order already cancelled — no point retrying");
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
114
115
|
declare class NonRetryableError extends Error {
|
|
115
116
|
constructor(message: string, name?: string);
|
|
116
117
|
}
|
|
@@ -119,18 +120,31 @@ declare const isNonRetryableError: (value: unknown) => value is NonRetryableErro
|
|
|
119
120
|
/** Constructor shape of `cloudflare:workflows`' native `NonRetryableError`. */
|
|
120
121
|
type NativeNonRetryableErrorConstructor = new (message: string, name?: string) => Error;
|
|
121
122
|
/**
|
|
122
|
-
* Rebuild a portable {@link NonRetryableError} as the native Cloudflare one,
|
|
123
|
-
* preserving its `name`, `message`, `cause`, and `stack`. Used at the `src/do`
|
|
124
|
-
* boundary where the native constructor is available; everywhere else the
|
|
125
|
-
* portable error is thrown unchanged (and still honored by name).
|
|
126
|
-
*/
|
|
123
|
+
* Rebuild a portable {@link NonRetryableError} as the native Cloudflare one,
|
|
124
|
+
* preserving its `name`, `message`, `cause`, and `stack`. Used at the `src/do`
|
|
125
|
+
* boundary where the native constructor is available; everywhere else the
|
|
126
|
+
* portable error is thrown unchanged (and still honored by name).
|
|
127
|
+
*/
|
|
127
128
|
declare const toNativeNonRetryableError: (error: NonRetryableError, NativeNonRetryableError: NativeNonRetryableErrorConstructor) => Error;
|
|
128
129
|
/**
|
|
129
|
-
* If `error` is a portable {@link NonRetryableError} and a native constructor is
|
|
130
|
-
* available, rethrow it as the native error; otherwise rethrow `error` as-is.
|
|
131
|
-
* Always throws — the `never` return lets callers `return convertNonRetryableError(...)`.
|
|
132
|
-
*/
|
|
130
|
+
* If `error` is a portable {@link NonRetryableError} and a native constructor is
|
|
131
|
+
* available, rethrow it as the native error; otherwise rethrow `error` as-is.
|
|
132
|
+
* Always throws — the `never` return lets callers `return convertNonRetryableError(...)`.
|
|
133
|
+
*/
|
|
133
134
|
declare const convertNonRetryableError: (error: unknown, NativeNonRetryableError: NativeNonRetryableErrorConstructor | undefined) => never;
|
|
135
|
+
/** Hard cap on branches per `ctx.parallel` call — auto-scale, never silently spawn unbounded DOs. */
|
|
136
|
+
declare const MAX_BRANCHES = 100;
|
|
137
|
+
/**
|
|
138
|
+
* Build a single fan-out branch: a declared child workflow referenced by its
|
|
139
|
+
* `lunora/workflows.ts` export name, plus the params it is created with. Pass the
|
|
140
|
+
* output type as the generic argument so `ctx.parallel(...)` infers the result
|
|
141
|
+
* tuple — e.g. `branch("imageTag", { key })` typed as `branch` of `{ tags }`.
|
|
142
|
+
*/
|
|
143
|
+
declare const branch: <Output = unknown>(workflow: string, params?: Record<string, unknown>, options?: {
|
|
144
|
+
compensateWith?: string;
|
|
145
|
+
id?: string;
|
|
146
|
+
timeout?: number | string;
|
|
147
|
+
}) => WorkflowBranch<Output>;
|
|
134
148
|
/** The lifecycle mutations the REST API exposes via `PATCH .../instances/{id}`. */
|
|
135
149
|
type WorkflowInstanceAction = "pause" | "resume" | "terminate";
|
|
136
150
|
/** Configuration for a {@link WorkflowsRestClient}. */
|
|
@@ -178,8 +192,7 @@ interface WorkflowInstancePage {
|
|
|
178
192
|
totalCount?: number;
|
|
179
193
|
}
|
|
180
194
|
/** Thrown when the REST API responds non-2xx or `success: false`; carries the status plus body for the caller to surface. */
|
|
181
|
-
declare class WorkflowsRestError extends
|
|
182
|
-
readonly status: number;
|
|
195
|
+
declare class WorkflowsRestError extends LunoraError {
|
|
183
196
|
constructor(status: number, body: string);
|
|
184
197
|
}
|
|
185
198
|
/** The observe client: list instances, read one instance's steps, and (with Edit scope) mutate its status. */
|
|
@@ -203,30 +216,12 @@ interface WorkflowsRestClient {
|
|
|
203
216
|
}>;
|
|
204
217
|
}
|
|
205
218
|
/**
|
|
206
|
-
* Build a {@link WorkflowsRestClient}. Each call hits the account-scoped REST
|
|
207
|
-
* endpoint with the bearer token, unwraps Cloudflare's
|
|
208
|
-
* `{ success, errors, result, result_info }` envelope, and normalizes the
|
|
209
|
-
* snake_case payload into the camelCase shapes the studio renders.
|
|
210
|
-
*/
|
|
219
|
+
* Build a {@link WorkflowsRestClient}. Each call hits the account-scoped REST
|
|
220
|
+
* endpoint with the bearer token, unwraps Cloudflare's
|
|
221
|
+
* `{ success, errors, result, result_info }` envelope, and normalizes the
|
|
222
|
+
* snake_case payload into the camelCase shapes the studio renders.
|
|
223
|
+
*/
|
|
211
224
|
declare const createWorkflowsRestClient: (config: WorkflowsRestConfig) => WorkflowsRestClient;
|
|
212
|
-
interface RunnerOptions {
|
|
213
|
-
/** Worker `env` — read `LUNORA_ORIGIN_URL` + `LUNORA_ADMIN_TOKEN` at call time. */
|
|
214
|
-
env: Record<string, unknown>;
|
|
215
|
-
/** Injectable fetch (tests); defaults to the global. */
|
|
216
|
-
fetchImpl?: typeof fetch;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Build a {@link WorkflowRunFunction} that invokes a Lunora function by POSTing
|
|
220
|
-
* to the Worker's `/_lunora/scheduler/dispatch` endpoint — the same path the
|
|
221
|
-
* SchedulerDO and the Queues workpool dispatch through — authenticated with the
|
|
222
|
-
* admin bearer. The parsed JSON body (the function's return value) is resolved;
|
|
223
|
-
* an empty/non-JSON body resolves to `undefined`.
|
|
224
|
-
*
|
|
225
|
-
* Wrap calls in `ctx.step.do(...)` to make them durable + memoized + retried.
|
|
226
|
-
*/
|
|
227
|
-
declare const createWorkflowRunner: (options: RunnerOptions) => WorkflowRunFunction;
|
|
228
|
-
/** Console-backed logger, prefixed with the workflow name for log correlation. */
|
|
229
|
-
declare const createWorkflowLogger: (exportName: string) => WorkflowLogger;
|
|
230
225
|
interface RunContextOptions<Params> {
|
|
231
226
|
env: Record<string, unknown>;
|
|
232
227
|
event: WorkflowEventLike<Params>;
|
|
@@ -239,12 +234,12 @@ interface RunContextOptions<Params> {
|
|
|
239
234
|
/** Assemble the {@link WorkflowRunContext} passed to a `defineWorkflow` handler. */
|
|
240
235
|
declare const createWorkflowRunContext: <Params = Record<string, unknown>>(options: RunContextOptions<Params>) => WorkflowRunContext<Params>;
|
|
241
236
|
/**
|
|
242
|
-
* Validate a step's args through its validator map, prefixing any
|
|
243
|
-
* `ValidationError` with `step args.<key>` so the failure points at the
|
|
244
|
-
* offending field. Delegates to `@lunora/values`' shared {@link parseValidatorMap}
|
|
245
|
-
* — the same parser the procedure builder and HTTP routes use — so the
|
|
246
|
-
* optional-skip and error-prefix semantics stay in lockstep across the framework.
|
|
247
|
-
*/
|
|
237
|
+
* Validate a step's args through its validator map, prefixing any
|
|
238
|
+
* `ValidationError` with `step args.<key>` so the failure points at the
|
|
239
|
+
* offending field. Delegates to `@lunora/values`' shared {@link parseValidatorMap}
|
|
240
|
+
* — the same parser the procedure builder and HTTP routes use — so the
|
|
241
|
+
* optional-skip and error-prefix semantics stay in lockstep across the framework.
|
|
242
|
+
*/
|
|
248
243
|
declare const validateStepArgs: (validators: StepArgsValidator, source: Record<string, unknown>) => Record<string, unknown>;
|
|
249
244
|
/** Dependencies needed to run a step: the native step API plus the workflow's env / runner / logger. */
|
|
250
245
|
interface RunStepDeps {
|
|
@@ -260,10 +255,10 @@ interface RunStepDeps {
|
|
|
260
255
|
step: WorkflowStepLike;
|
|
261
256
|
}
|
|
262
257
|
/**
|
|
263
|
-
* Build the `ctx.runStep` function bound to one workflow invocation. Each call
|
|
264
|
-
* runs the step through `step.do(...)`: validate args → run body → validate
|
|
265
|
-
* result (when `returns` is declared), with any portable `NonRetryableError`
|
|
266
|
-
* converted to the native one and any declared rollback forwarded to Cloudflare.
|
|
267
|
-
*/
|
|
258
|
+
* Build the `ctx.runStep` function bound to one workflow invocation. Each call
|
|
259
|
+
* runs the step through `step.do(...)`: validate args → run body → validate
|
|
260
|
+
* result (when `returns` is declared), with any portable `NonRetryableError`
|
|
261
|
+
* converted to the native one and any declared rollback forwarded to Cloudflare.
|
|
262
|
+
*/
|
|
268
263
|
declare const createRunStep: (deps: RunStepDeps) => WorkflowRunStepFunction;
|
|
269
|
-
export { type LunoraWorkflowsOptions, type NativeNonRetryableErrorConstructor, NonRetryableError, type StepArgsValidator, type StepConfig, type StepDefinition, type WorkflowBindingSpec, type WorkflowConfig, type WorkflowDefinition, type WorkflowEventLike, type WorkflowInstanceAction, type WorkflowInstanceDetail, type WorkflowInstancePage, type WorkflowInstanceStatus, type WorkflowInstanceSummary, type WorkflowLogger, type WorkflowRunContext, type WorkflowRunFunction, type WorkflowRunStepFunction, type WorkflowStepDetail, type WorkflowStepLike, type Workflows, type WorkflowsRestClient, type WorkflowsRestConfig, WorkflowsRestError, convertNonRetryableError, createRunStep, createWorkflowContext,
|
|
264
|
+
export { type LunoraWorkflowsOptions, MAX_BRANCHES, type NativeNonRetryableErrorConstructor, NonRetryableError, type StepArgsValidator, type StepConfig, type StepDefinition, type WorkflowBindingSpec, type WorkflowBranch, type WorkflowConfig, type WorkflowDefinition, type WorkflowEventLike, type WorkflowInstanceAction, type WorkflowInstanceDetail, type WorkflowInstancePage, type WorkflowInstanceStatus, type WorkflowInstanceSummary, type WorkflowLogger, type WorkflowRunContext, type WorkflowRunFunction, type WorkflowRunStepFunction, type WorkflowStepDetail, type WorkflowStepLike, type Workflows, type WorkflowsRestClient, type WorkflowsRestConfig, WorkflowsRestError, branch, convertNonRetryableError, createRunStep, createWorkflowContext, createWorkflowRunContext, createWorkflows, createWorkflowsRestClient, defineStep, defineWorkflow, isNonRetryableError, isStepDefinition, isWorkflowDefinition, toNativeNonRetryableError, validateStepArgs, workflowBindingName, workflowClassName, workflowDefaultName };
|