@lunora/workflow 0.0.0 → 1.0.0-alpha.2
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 +105 -0
- package/README.md +260 -9
- package/__assets__/package-og.svg +14 -0
- package/dist/do/index.d.mts +25 -0
- package/dist/do/index.d.ts +25 -0
- package/dist/do/index.mjs +32 -0
- package/dist/index.d.mts +269 -0
- package/dist/index.d.ts +269 -0
- package/dist/index.mjs +8 -0
- package/dist/packem_shared/NonRetryableError-Dn2dTyBS.mjs +27 -0
- package/dist/packem_shared/WorkflowsRestError-b06i7K5j.mjs +118 -0
- package/dist/packem_shared/createRunStep-8jOXxP2o.mjs +54 -0
- package/dist/packem_shared/createWorkflowContext-D6thzmlF.mjs +14 -0
- package/dist/packem_shared/createWorkflowLogger-DR8P4ZoY.mjs +76 -0
- package/dist/packem_shared/createWorkflows-BoSYVIXg.mjs +23 -0
- package/dist/packem_shared/defineStep-DJQtLw7g.mjs +28 -0
- package/dist/packem_shared/defineWorkflow-DbUC-oCN.mjs +15 -0
- package/dist/packem_shared/types.d-CQO_koGe.d.mts +344 -0
- package/dist/packem_shared/types.d-CQO_koGe.d.ts +344 -0
- package/package.json +42 -15
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
+
import { W as WorkflowDefinition } from "../packem_shared/types.d-CQO_koGe.mjs";
|
|
3
|
+
import '@lunora/values';
|
|
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
|
+
*/
|
|
20
|
+
declare class LunoraWorkflow<Params = Record<string, unknown>, Output = unknown> extends WorkflowEntrypoint<Record<string, unknown>, Params> {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(context: ConstructorParameters<typeof WorkflowEntrypoint>[0], env: Record<string, unknown>, definition: WorkflowDefinition<Params, Output>, exportName?: string);
|
|
23
|
+
override run(event: Readonly<WorkflowEvent<Params>>, step: WorkflowStep): Promise<Output>;
|
|
24
|
+
}
|
|
25
|
+
export { LunoraWorkflow as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
|
|
2
|
+
import { W as WorkflowDefinition } from "../packem_shared/types.d-CQO_koGe.js";
|
|
3
|
+
import '@lunora/values';
|
|
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
|
+
*/
|
|
20
|
+
declare class LunoraWorkflow<Params = Record<string, unknown>, Output = unknown> extends WorkflowEntrypoint<Record<string, unknown>, Params> {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(context: ConstructorParameters<typeof WorkflowEntrypoint>[0], env: Record<string, unknown>, definition: WorkflowDefinition<Params, Output>, exportName?: string);
|
|
23
|
+
override run(event: Readonly<WorkflowEvent<Params>>, step: WorkflowStep): Promise<Output>;
|
|
24
|
+
}
|
|
25
|
+
export { LunoraWorkflow as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WorkflowEntrypoint } from 'cloudflare:workers';
|
|
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 };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
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 WorkflowInstanceStatus, f as WorkflowLogger, g as WorkflowEventLike, h as WorkflowStepLike, i as WorkflowRunContext, j as WorkflowRunFunction, k as WorkflowRunStepFunction } from "./packem_shared/types.d-CQO_koGe.mjs";
|
|
2
|
+
export type { A as ArgsOf, F as FunctionReference, I as InferStepArgs, R as RunFunctionOptions, l as RunStepOptions, m as StepHandler, n as StepRollbackContext, o as StepRollbackHandler, p as StepRunContext, q as WorkflowBindingLike, r as WorkflowCreateOptions, s as WorkflowHandle, t as WorkflowHandler, u as WorkflowInstanceLike, v as WorkflowRollbackContextLike, w as WorkflowRollbackHandlerLike, x as WorkflowStatusResult, y as WorkflowStepConfigLike, z as WorkflowStepContextLike, B as WorkflowStepRollbackOptionsLike } from "./packem_shared/types.d-CQO_koGe.mjs";
|
|
3
|
+
import '@lunora/values';
|
|
4
|
+
/** Wiring info for one declared workflow, emitted by codegen into the generated shard. */
|
|
5
|
+
interface WorkflowBindingSpec {
|
|
6
|
+
/** The Cloudflare `Workflow` binding name, e.g. `WORKFLOW_ORDER_PIPELINE`. */
|
|
7
|
+
binding: string;
|
|
8
|
+
/** The `lunora/workflows.ts` export name, e.g. `orderPipeline`. */
|
|
9
|
+
exportName: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
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
|
+
*/
|
|
18
|
+
declare const createWorkflowContext: (env: Record<string, unknown>, specs: ReadonlyArray<WorkflowBindingSpec>) => Workflows;
|
|
19
|
+
/**
|
|
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
|
+
*/
|
|
24
|
+
declare const createWorkflows: (options: LunoraWorkflowsOptions) => Workflows;
|
|
25
|
+
/**
|
|
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
|
+
*/
|
|
53
|
+
declare const defineStep: <A extends StepArgsValidator, Result>(name: string, config: StepConfig<A, Result>) => StepDefinition<A, Result>;
|
|
54
|
+
/** True when a value is a `defineStep` result (the runtime brand check). */
|
|
55
|
+
declare const isStepDefinition: (value: unknown) => value is StepDefinition;
|
|
56
|
+
/**
|
|
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
|
+
*/
|
|
62
|
+
declare const workflowClassName: (exportName: string) => string;
|
|
63
|
+
/**
|
|
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
|
+
*/
|
|
69
|
+
declare const workflowBindingName: (exportName: string) => string;
|
|
70
|
+
/**
|
|
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
|
+
*/
|
|
75
|
+
declare const workflowDefaultName: (exportName: string) => string;
|
|
76
|
+
/**
|
|
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
|
+
*/
|
|
98
|
+
declare const defineWorkflow: <Params = Record<string, unknown>, Output = unknown>(config: WorkflowConfig<Params, Output>) => WorkflowDefinition<Params, Output>;
|
|
99
|
+
/** True when a value is a `defineWorkflow` result (the runtime brand check). */
|
|
100
|
+
declare const isWorkflowDefinition: (value: unknown) => value is WorkflowDefinition;
|
|
101
|
+
/**
|
|
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
|
+
*/
|
|
114
|
+
declare class NonRetryableError extends Error {
|
|
115
|
+
constructor(message: string, name?: string);
|
|
116
|
+
}
|
|
117
|
+
/** True when `value` is a Lunora portable {@link NonRetryableError}. */
|
|
118
|
+
declare const isNonRetryableError: (value: unknown) => value is NonRetryableError;
|
|
119
|
+
/** Constructor shape of `cloudflare:workflows`' native `NonRetryableError`. */
|
|
120
|
+
type NativeNonRetryableErrorConstructor = new (message: string, name?: string) => Error;
|
|
121
|
+
/**
|
|
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
|
+
*/
|
|
127
|
+
declare const toNativeNonRetryableError: (error: NonRetryableError, NativeNonRetryableError: NativeNonRetryableErrorConstructor) => Error;
|
|
128
|
+
/**
|
|
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
|
+
*/
|
|
133
|
+
declare const convertNonRetryableError: (error: unknown, NativeNonRetryableError: NativeNonRetryableErrorConstructor | undefined) => never;
|
|
134
|
+
/** The lifecycle mutations the REST API exposes via `PATCH .../instances/{id}`. */
|
|
135
|
+
type WorkflowInstanceAction = "pause" | "resume" | "terminate";
|
|
136
|
+
/** Configuration for a {@link WorkflowsRestClient}. */
|
|
137
|
+
interface WorkflowsRestConfig {
|
|
138
|
+
/** Cloudflare account id that owns the workflow. */
|
|
139
|
+
accountId: string;
|
|
140
|
+
/** API token with `Workflows: Read` (and `Edit` for status mutation). A secret — never a binding. */
|
|
141
|
+
apiToken: string;
|
|
142
|
+
/** `fetch` implementation. Defaults to the global `fetch`; injected in tests so the path never touches the network. */
|
|
143
|
+
fetch?: typeof globalThis.fetch;
|
|
144
|
+
}
|
|
145
|
+
/** One row of the instance list — the summary the studio table renders. */
|
|
146
|
+
interface WorkflowInstanceSummary {
|
|
147
|
+
createdOn?: string;
|
|
148
|
+
endedOn?: string;
|
|
149
|
+
id: string;
|
|
150
|
+
startedOn?: string;
|
|
151
|
+
status: WorkflowInstanceStatus;
|
|
152
|
+
}
|
|
153
|
+
/** One durable step of an instance, normalized from the REST `steps[]` array. */
|
|
154
|
+
interface WorkflowStepDetail {
|
|
155
|
+
/** 1-based attempt count (`> 1` means the step retried). */
|
|
156
|
+
attempts?: number;
|
|
157
|
+
end?: string;
|
|
158
|
+
error?: unknown;
|
|
159
|
+
name: string;
|
|
160
|
+
output?: unknown;
|
|
161
|
+
start?: string;
|
|
162
|
+
success?: boolean;
|
|
163
|
+
/** `step` / `sleep` / `waitForEvent` / … (Cloudflare's step `type`). */
|
|
164
|
+
type?: string;
|
|
165
|
+
}
|
|
166
|
+
/** A single instance's full detail: its summary plus params/output/error and the step timeline. */
|
|
167
|
+
interface WorkflowInstanceDetail extends WorkflowInstanceSummary {
|
|
168
|
+
error?: unknown;
|
|
169
|
+
output?: unknown;
|
|
170
|
+
params?: unknown;
|
|
171
|
+
steps: WorkflowStepDetail[];
|
|
172
|
+
}
|
|
173
|
+
/** A page of instances plus the cursor info Cloudflare returns in `result_info`. */
|
|
174
|
+
interface WorkflowInstancePage {
|
|
175
|
+
instances: WorkflowInstanceSummary[];
|
|
176
|
+
page: number;
|
|
177
|
+
perPage: number;
|
|
178
|
+
totalCount?: number;
|
|
179
|
+
}
|
|
180
|
+
/** 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 Error {
|
|
182
|
+
readonly status: number;
|
|
183
|
+
constructor(status: number, body: string);
|
|
184
|
+
}
|
|
185
|
+
/** The observe client: list instances, read one instance's steps, and (with Edit scope) mutate its status. */
|
|
186
|
+
interface WorkflowsRestClient {
|
|
187
|
+
getInstance: (args: {
|
|
188
|
+
instanceId: string;
|
|
189
|
+
workflowName: string;
|
|
190
|
+
}) => Promise<WorkflowInstanceDetail>;
|
|
191
|
+
listInstances: (args: {
|
|
192
|
+
page?: number;
|
|
193
|
+
perPage?: number;
|
|
194
|
+
status?: WorkflowInstanceStatus;
|
|
195
|
+
workflowName: string;
|
|
196
|
+
}) => Promise<WorkflowInstancePage>;
|
|
197
|
+
setInstanceStatus: (args: {
|
|
198
|
+
action: WorkflowInstanceAction;
|
|
199
|
+
instanceId: string;
|
|
200
|
+
workflowName: string;
|
|
201
|
+
}) => Promise<{
|
|
202
|
+
status: WorkflowInstanceStatus;
|
|
203
|
+
}>;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
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
|
+
*/
|
|
211
|
+
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
|
+
interface RunContextOptions<Params> {
|
|
231
|
+
env: Record<string, unknown>;
|
|
232
|
+
event: WorkflowEventLike<Params>;
|
|
233
|
+
exportName: string;
|
|
234
|
+
fetchImpl?: typeof fetch;
|
|
235
|
+
/** Native `cloudflare:workflows` `NonRetryableError` — injected by `src/do`; absent in Node tests. */
|
|
236
|
+
nonRetryableErrorClass?: NativeNonRetryableErrorConstructor;
|
|
237
|
+
step: WorkflowStepLike;
|
|
238
|
+
}
|
|
239
|
+
/** Assemble the {@link WorkflowRunContext} passed to a `defineWorkflow` handler. */
|
|
240
|
+
declare const createWorkflowRunContext: <Params = Record<string, unknown>>(options: RunContextOptions<Params>) => WorkflowRunContext<Params>;
|
|
241
|
+
/**
|
|
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
|
+
*/
|
|
248
|
+
declare const validateStepArgs: (validators: StepArgsValidator, source: Record<string, unknown>) => Record<string, unknown>;
|
|
249
|
+
/** Dependencies needed to run a step: the native step API plus the workflow's env / runner / logger. */
|
|
250
|
+
interface RunStepDeps {
|
|
251
|
+
/** The Worker environment bindings, surfaced on the step context. */
|
|
252
|
+
env: Record<string, unknown>;
|
|
253
|
+
/** Structured logger surfaced on the step context. */
|
|
254
|
+
log: WorkflowLogger;
|
|
255
|
+
/** Native `cloudflare:workflows` `NonRetryableError` constructor — injected by `src/do`; absent in Node tests. */
|
|
256
|
+
nonRetryableErrorClass?: NativeNonRetryableErrorConstructor;
|
|
257
|
+
/** The Lunora function runner, surfaced on the step context. */
|
|
258
|
+
run: WorkflowRunFunction;
|
|
259
|
+
/** The native Cloudflare durable-step API. */
|
|
260
|
+
step: WorkflowStepLike;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
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
|
+
*/
|
|
268
|
+
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, createWorkflowLogger, createWorkflowRunContext, createWorkflowRunner, createWorkflows, createWorkflowsRestClient, defineStep, defineWorkflow, isNonRetryableError, isStepDefinition, isWorkflowDefinition, toNativeNonRetryableError, validateStepArgs, workflowBindingName, workflowClassName, workflowDefaultName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
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 WorkflowInstanceStatus, f as WorkflowLogger, g as WorkflowEventLike, h as WorkflowStepLike, i as WorkflowRunContext, j as WorkflowRunFunction, k as WorkflowRunStepFunction } from "./packem_shared/types.d-CQO_koGe.js";
|
|
2
|
+
export type { A as ArgsOf, F as FunctionReference, I as InferStepArgs, R as RunFunctionOptions, l as RunStepOptions, m as StepHandler, n as StepRollbackContext, o as StepRollbackHandler, p as StepRunContext, q as WorkflowBindingLike, r as WorkflowCreateOptions, s as WorkflowHandle, t as WorkflowHandler, u as WorkflowInstanceLike, v as WorkflowRollbackContextLike, w as WorkflowRollbackHandlerLike, x as WorkflowStatusResult, y as WorkflowStepConfigLike, z as WorkflowStepContextLike, B as WorkflowStepRollbackOptionsLike } from "./packem_shared/types.d-CQO_koGe.js";
|
|
3
|
+
import '@lunora/values';
|
|
4
|
+
/** Wiring info for one declared workflow, emitted by codegen into the generated shard. */
|
|
5
|
+
interface WorkflowBindingSpec {
|
|
6
|
+
/** The Cloudflare `Workflow` binding name, e.g. `WORKFLOW_ORDER_PIPELINE`. */
|
|
7
|
+
binding: string;
|
|
8
|
+
/** The `lunora/workflows.ts` export name, e.g. `orderPipeline`. */
|
|
9
|
+
exportName: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
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
|
+
*/
|
|
18
|
+
declare const createWorkflowContext: (env: Record<string, unknown>, specs: ReadonlyArray<WorkflowBindingSpec>) => Workflows;
|
|
19
|
+
/**
|
|
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
|
+
*/
|
|
24
|
+
declare const createWorkflows: (options: LunoraWorkflowsOptions) => Workflows;
|
|
25
|
+
/**
|
|
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
|
+
*/
|
|
53
|
+
declare const defineStep: <A extends StepArgsValidator, Result>(name: string, config: StepConfig<A, Result>) => StepDefinition<A, Result>;
|
|
54
|
+
/** True when a value is a `defineStep` result (the runtime brand check). */
|
|
55
|
+
declare const isStepDefinition: (value: unknown) => value is StepDefinition;
|
|
56
|
+
/**
|
|
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
|
+
*/
|
|
62
|
+
declare const workflowClassName: (exportName: string) => string;
|
|
63
|
+
/**
|
|
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
|
+
*/
|
|
69
|
+
declare const workflowBindingName: (exportName: string) => string;
|
|
70
|
+
/**
|
|
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
|
+
*/
|
|
75
|
+
declare const workflowDefaultName: (exportName: string) => string;
|
|
76
|
+
/**
|
|
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
|
+
*/
|
|
98
|
+
declare const defineWorkflow: <Params = Record<string, unknown>, Output = unknown>(config: WorkflowConfig<Params, Output>) => WorkflowDefinition<Params, Output>;
|
|
99
|
+
/** True when a value is a `defineWorkflow` result (the runtime brand check). */
|
|
100
|
+
declare const isWorkflowDefinition: (value: unknown) => value is WorkflowDefinition;
|
|
101
|
+
/**
|
|
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
|
+
*/
|
|
114
|
+
declare class NonRetryableError extends Error {
|
|
115
|
+
constructor(message: string, name?: string);
|
|
116
|
+
}
|
|
117
|
+
/** True when `value` is a Lunora portable {@link NonRetryableError}. */
|
|
118
|
+
declare const isNonRetryableError: (value: unknown) => value is NonRetryableError;
|
|
119
|
+
/** Constructor shape of `cloudflare:workflows`' native `NonRetryableError`. */
|
|
120
|
+
type NativeNonRetryableErrorConstructor = new (message: string, name?: string) => Error;
|
|
121
|
+
/**
|
|
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
|
+
*/
|
|
127
|
+
declare const toNativeNonRetryableError: (error: NonRetryableError, NativeNonRetryableError: NativeNonRetryableErrorConstructor) => Error;
|
|
128
|
+
/**
|
|
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
|
+
*/
|
|
133
|
+
declare const convertNonRetryableError: (error: unknown, NativeNonRetryableError: NativeNonRetryableErrorConstructor | undefined) => never;
|
|
134
|
+
/** The lifecycle mutations the REST API exposes via `PATCH .../instances/{id}`. */
|
|
135
|
+
type WorkflowInstanceAction = "pause" | "resume" | "terminate";
|
|
136
|
+
/** Configuration for a {@link WorkflowsRestClient}. */
|
|
137
|
+
interface WorkflowsRestConfig {
|
|
138
|
+
/** Cloudflare account id that owns the workflow. */
|
|
139
|
+
accountId: string;
|
|
140
|
+
/** API token with `Workflows: Read` (and `Edit` for status mutation). A secret — never a binding. */
|
|
141
|
+
apiToken: string;
|
|
142
|
+
/** `fetch` implementation. Defaults to the global `fetch`; injected in tests so the path never touches the network. */
|
|
143
|
+
fetch?: typeof globalThis.fetch;
|
|
144
|
+
}
|
|
145
|
+
/** One row of the instance list — the summary the studio table renders. */
|
|
146
|
+
interface WorkflowInstanceSummary {
|
|
147
|
+
createdOn?: string;
|
|
148
|
+
endedOn?: string;
|
|
149
|
+
id: string;
|
|
150
|
+
startedOn?: string;
|
|
151
|
+
status: WorkflowInstanceStatus;
|
|
152
|
+
}
|
|
153
|
+
/** One durable step of an instance, normalized from the REST `steps[]` array. */
|
|
154
|
+
interface WorkflowStepDetail {
|
|
155
|
+
/** 1-based attempt count (`> 1` means the step retried). */
|
|
156
|
+
attempts?: number;
|
|
157
|
+
end?: string;
|
|
158
|
+
error?: unknown;
|
|
159
|
+
name: string;
|
|
160
|
+
output?: unknown;
|
|
161
|
+
start?: string;
|
|
162
|
+
success?: boolean;
|
|
163
|
+
/** `step` / `sleep` / `waitForEvent` / … (Cloudflare's step `type`). */
|
|
164
|
+
type?: string;
|
|
165
|
+
}
|
|
166
|
+
/** A single instance's full detail: its summary plus params/output/error and the step timeline. */
|
|
167
|
+
interface WorkflowInstanceDetail extends WorkflowInstanceSummary {
|
|
168
|
+
error?: unknown;
|
|
169
|
+
output?: unknown;
|
|
170
|
+
params?: unknown;
|
|
171
|
+
steps: WorkflowStepDetail[];
|
|
172
|
+
}
|
|
173
|
+
/** A page of instances plus the cursor info Cloudflare returns in `result_info`. */
|
|
174
|
+
interface WorkflowInstancePage {
|
|
175
|
+
instances: WorkflowInstanceSummary[];
|
|
176
|
+
page: number;
|
|
177
|
+
perPage: number;
|
|
178
|
+
totalCount?: number;
|
|
179
|
+
}
|
|
180
|
+
/** 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 Error {
|
|
182
|
+
readonly status: number;
|
|
183
|
+
constructor(status: number, body: string);
|
|
184
|
+
}
|
|
185
|
+
/** The observe client: list instances, read one instance's steps, and (with Edit scope) mutate its status. */
|
|
186
|
+
interface WorkflowsRestClient {
|
|
187
|
+
getInstance: (args: {
|
|
188
|
+
instanceId: string;
|
|
189
|
+
workflowName: string;
|
|
190
|
+
}) => Promise<WorkflowInstanceDetail>;
|
|
191
|
+
listInstances: (args: {
|
|
192
|
+
page?: number;
|
|
193
|
+
perPage?: number;
|
|
194
|
+
status?: WorkflowInstanceStatus;
|
|
195
|
+
workflowName: string;
|
|
196
|
+
}) => Promise<WorkflowInstancePage>;
|
|
197
|
+
setInstanceStatus: (args: {
|
|
198
|
+
action: WorkflowInstanceAction;
|
|
199
|
+
instanceId: string;
|
|
200
|
+
workflowName: string;
|
|
201
|
+
}) => Promise<{
|
|
202
|
+
status: WorkflowInstanceStatus;
|
|
203
|
+
}>;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
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
|
+
*/
|
|
211
|
+
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
|
+
interface RunContextOptions<Params> {
|
|
231
|
+
env: Record<string, unknown>;
|
|
232
|
+
event: WorkflowEventLike<Params>;
|
|
233
|
+
exportName: string;
|
|
234
|
+
fetchImpl?: typeof fetch;
|
|
235
|
+
/** Native `cloudflare:workflows` `NonRetryableError` — injected by `src/do`; absent in Node tests. */
|
|
236
|
+
nonRetryableErrorClass?: NativeNonRetryableErrorConstructor;
|
|
237
|
+
step: WorkflowStepLike;
|
|
238
|
+
}
|
|
239
|
+
/** Assemble the {@link WorkflowRunContext} passed to a `defineWorkflow` handler. */
|
|
240
|
+
declare const createWorkflowRunContext: <Params = Record<string, unknown>>(options: RunContextOptions<Params>) => WorkflowRunContext<Params>;
|
|
241
|
+
/**
|
|
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
|
+
*/
|
|
248
|
+
declare const validateStepArgs: (validators: StepArgsValidator, source: Record<string, unknown>) => Record<string, unknown>;
|
|
249
|
+
/** Dependencies needed to run a step: the native step API plus the workflow's env / runner / logger. */
|
|
250
|
+
interface RunStepDeps {
|
|
251
|
+
/** The Worker environment bindings, surfaced on the step context. */
|
|
252
|
+
env: Record<string, unknown>;
|
|
253
|
+
/** Structured logger surfaced on the step context. */
|
|
254
|
+
log: WorkflowLogger;
|
|
255
|
+
/** Native `cloudflare:workflows` `NonRetryableError` constructor — injected by `src/do`; absent in Node tests. */
|
|
256
|
+
nonRetryableErrorClass?: NativeNonRetryableErrorConstructor;
|
|
257
|
+
/** The Lunora function runner, surfaced on the step context. */
|
|
258
|
+
run: WorkflowRunFunction;
|
|
259
|
+
/** The native Cloudflare durable-step API. */
|
|
260
|
+
step: WorkflowStepLike;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
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
|
+
*/
|
|
268
|
+
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, createWorkflowLogger, createWorkflowRunContext, createWorkflowRunner, createWorkflows, createWorkflowsRestClient, defineStep, defineWorkflow, isNonRetryableError, isStepDefinition, isWorkflowDefinition, toNativeNonRetryableError, validateStepArgs, workflowBindingName, workflowClassName, workflowDefaultName };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createWorkflowContext } from './packem_shared/createWorkflowContext-D6thzmlF.mjs';
|
|
2
|
+
export { default as createWorkflows } from './packem_shared/createWorkflows-BoSYVIXg.mjs';
|
|
3
|
+
export { defineStep, isStepDefinition } from './packem_shared/defineStep-DJQtLw7g.mjs';
|
|
4
|
+
export { defineWorkflow, isWorkflowDefinition, workflowBindingName, workflowClassName, workflowDefaultName } from './packem_shared/defineWorkflow-DbUC-oCN.mjs';
|
|
5
|
+
export { NonRetryableError, convertNonRetryableError, isNonRetryableError, toNativeNonRetryableError } from './packem_shared/NonRetryableError-Dn2dTyBS.mjs';
|
|
6
|
+
export { WorkflowsRestError, createWorkflowsRestClient } from './packem_shared/WorkflowsRestError-b06i7K5j.mjs';
|
|
7
|
+
export { createWorkflowLogger, createWorkflowRunContext, createWorkflowRunner } from './packem_shared/createWorkflowLogger-DR8P4ZoY.mjs';
|
|
8
|
+
export { createRunStep, validateStepArgs } from './packem_shared/createRunStep-8jOXxP2o.mjs';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const NON_RETRYABLE_BRAND = "__lunoraNonRetryable";
|
|
2
|
+
class NonRetryableError extends Error {
|
|
3
|
+
constructor(message, name = "NonRetryableError") {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = name;
|
|
6
|
+
this[NON_RETRYABLE_BRAND] = true;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const isNonRetryableError = (value) => value instanceof Error && value[NON_RETRYABLE_BRAND] === true;
|
|
10
|
+
const toNativeNonRetryableError = (error, NativeNonRetryableError) => {
|
|
11
|
+
const native = new NativeNonRetryableError(error.message, error.name);
|
|
12
|
+
if (error.stack !== void 0) {
|
|
13
|
+
native.stack = error.stack;
|
|
14
|
+
}
|
|
15
|
+
if (error.cause !== void 0 && native.cause === void 0) {
|
|
16
|
+
native.cause = error.cause;
|
|
17
|
+
}
|
|
18
|
+
return native;
|
|
19
|
+
};
|
|
20
|
+
const convertNonRetryableError = (error, NativeNonRetryableError) => {
|
|
21
|
+
if (NativeNonRetryableError !== void 0 && isNonRetryableError(error)) {
|
|
22
|
+
throw toNativeNonRetryableError(error, NativeNonRetryableError);
|
|
23
|
+
}
|
|
24
|
+
throw error;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { NonRetryableError, convertNonRetryableError, isNonRetryableError, toNativeNonRetryableError };
|