octaflow 0.14.0

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.
@@ -0,0 +1,137 @@
1
+ import { A as StepError, B as WorkflowDefinition, C as FlowError, D as StepCompensateHandler, E as StartOptions, F as StepId, G as WorkflowWithSteps, H as WorkflowNotFoundError, I as StepRecord, J as err, K as FlowErrorShape, L as StepRegistration, M as StepHandler, N as StepHandlerNotFoundError, O as StepCompensationContext, P as StepHandlerRegistry, R as StepStatus, S as defineWaitStep, T as RetryPolicy, U as WorkflowRecord, V as WorkflowId, W as WorkflowStatus, Y as ok, _ as buildWorkflow, a as STEP_DISPLAY_STATUS, b as defineStep, c as WORKFLOW_STATUS_SCHEMA, d as toPublicWorkflow, f as StepOutput, g as WorkflowOutput, h as TypedWorkflow, i as PublicWorkflowStep, j as StepExecutionContext, k as StepDefinition, l as toDisplayStepStatus, m as TypedStepContext, n as PUBLIC_WORKFLOW_STEP_SCHEMA, o as STEP_DISPLAY_STATUS_SCHEMA, p as TypedStep, q as Result, r as PublicWorkflow, s as StepDisplayStatus, t as PUBLIC_WORKFLOW_SCHEMA, u as toPublicStep, v as defineMapStep, w as InvalidWorkflowDefinitionError, x as defineSubWorkflowStep, y as defineSleepStep, z as WorkflowCreatedResult } from "./index-D_fOYfmf.js";
2
+ import { n as Logger, r as noopLogger, t as LogAttributes } from "./logger-BCus3AOa.js";
3
+ import { C as CreateWorkflowStep, D as ListWorkflowsFilters, E as FinishWorkflowParams, O as WorkflowStore, S as CreateWorkflowParams, T as FailStepParams, _ as StepGateDecision, a as FlowTracer, b as AddChildStep, c as RecordingTracer, d as noopObserver, f as noopTracer, g as StepGate, h as RateRule, i as FlowSpan, l as createRecordingObserver, m as InMemoryStepGateConfig, n as FlowEventType, o as RecordedSpan, p as ConcurrencyRule, r as FlowObserver, s as RecordingObserver, t as FlowEvent, u as createRecordingTracer, v as StepGateRequest, w as CreatedWorkflow, x as CompleteStepParams, y as createInMemoryStepGate } from "./observability-BsrvbhDr.js";
4
+ import { n as Dispatcher, r as EnqueueOptions, t as DispatchStepPayload } from "./dispatcher-BydjyrgU.js";
5
+ import { a as WorkflowCompletedArgs, i as BuildStepContextArgs, n as BeforeStartArgs, o as WorkflowHooks, r as BeforeStartResult, t as AfterStepArgs } from "./hooks-CDRFQZbT.js";
6
+ //#region src/core/registry.d.ts
7
+ /**
8
+ * Creates an in-memory step handler registry.
9
+ * Populate it at application startup (e.g. by registering every workflow's steps).
10
+ * Each registration carries the handler plus its optional retry/timeout policy.
11
+ */
12
+ declare function createStepHandlerRegistry<TContext = unknown>(): StepHandlerRegistry<TContext>;
13
+ //#endregion
14
+ //#region src/core/retry.d.ts
15
+ /**
16
+ * Tag an error with an explicit retryability decision, overriding both the
17
+ * step predicate and the message heuristic. Returns the same error, so it can
18
+ * wrap a throw:
19
+ *
20
+ * ```ts
21
+ * throw markRetryable(await client.readError(), true);
22
+ * ```
23
+ */
24
+ declare function markRetryable<E>(error: E, retryable?: boolean): E;
25
+ /** An error the engine will always retry (within the step's attempt budget). */
26
+ declare function retryableError(message: string, options?: ErrorOptions): Error;
27
+ /** An error the engine will never retry, whatever its message says. */
28
+ declare function nonRetryableError(message: string, options?: ErrorOptions): Error;
29
+ /**
30
+ * The explicit decision carried by an error, or `undefined` if it carries none.
31
+ * Callers deciding retryability themselves should consult this first.
32
+ *
33
+ * Follows the `cause` chain, so a marked error keeps its decision when a caller
34
+ * wraps it — `new Error('upstream failed', { cause: retryableError('busy') })`
35
+ * still reports `true`. The outermost decision wins; the walk is depth-capped and
36
+ * cycle-safe.
37
+ */
38
+ declare function explicitRetryability(error: unknown): boolean | undefined;
39
+ /**
40
+ * Default classifier for a thrown error, used when nothing more specific applies.
41
+ * Checked in order:
42
+ *
43
+ * 1. An explicit marker ({@link markRetryable}), including through `cause`.
44
+ * 2. **Structured fields** — `code` (`ECONNRESET`, `ETIMEDOUT`, …) and HTTP
45
+ * status (`status` / `statusCode` / `response.status`): 408, 425, 429, 5xx.
46
+ * 3. **The message**, matched against a small vocabulary.
47
+ *
48
+ * Steps 2–3 are a convenience, not a classifier. The message check especially will
49
+ * misjudge anything whose wording it doesn't recognise — a permanent bug reading
50
+ * `'timeout must be > 0'` looks transient. Reach for {@link retryableError} /
51
+ * {@link nonRetryableError}, `defineStep`'s `isRetryable`, or the engine's
52
+ * `defaultRetryable` when the answer matters.
53
+ */
54
+ declare function isRetryableError(error: unknown): boolean;
55
+ //#endregion
56
+ //#region src/core/engine.d.ts
57
+ interface WorkflowEngineConfig {
58
+ /** The dispatcher's per-step expiry, in seconds. Used by the stuck-step sweeper. Default 600. */
59
+ stepExpirySeconds?: number;
60
+ /** Extra grace added to the stuck threshold beyond `stepExpirySeconds`. Default 300. */
61
+ stuckStepBufferSeconds?: number;
62
+ /**
63
+ * Retryability for failures nothing authoritative classified — i.e. where the
64
+ * default classifier fell back to guessing from the error's shape and message.
65
+ * Set `false` for strict mode: never guess, and treat an unmarked failure as
66
+ * permanent. Explicitly marked errors ({@link markRetryable}) and steps with
67
+ * their own `isRetryable` are unaffected, as are engine-generated failures like
68
+ * a step timeout.
69
+ *
70
+ * Leave unset to keep the default classifier's answer.
71
+ */
72
+ defaultRetryable?: boolean;
73
+ }
74
+ interface WorkflowEngineDeps<TContext = unknown> {
75
+ store: WorkflowStore;
76
+ dispatcher: Dispatcher;
77
+ registry: StepHandlerRegistry<TContext>;
78
+ /** Partition this engine instance is bound to (e.g. a tenant id). */
79
+ partitionKey: string;
80
+ logger?: Logger;
81
+ hooks?: WorkflowHooks<TContext>;
82
+ config?: WorkflowEngineConfig;
83
+ /**
84
+ * Optional admission gate (concurrency caps / rate limiting). Consulted before each
85
+ * step runs; a denied step is deferred (re-enqueued) without consuming an attempt.
86
+ */
87
+ gate?: StepGate;
88
+ /** Run-history / metrics sink. Receives a `FlowEvent` per transition. Default: no-op. */
89
+ observer?: FlowObserver;
90
+ /** Tracer: the engine wraps each `executeStep` in a span. Default: no-op. */
91
+ tracer?: FlowTracer;
92
+ /** Clock injection point for testability. Defaults to `() => new Date()`. */
93
+ now?: () => Date;
94
+ }
95
+ declare function createWorkflowEngine<TContext = unknown>(deps: WorkflowEngineDeps<TContext>): {
96
+ validateDefinition: (definition: WorkflowDefinition) => Result<void, FlowError>;
97
+ startWorkflow: (definition: WorkflowDefinition, input: Record<string, unknown>, options?: StartOptions) => Promise<Result<WorkflowCreatedResult, FlowError>>;
98
+ start: <TInput extends Record<string, unknown>>(workflow: {
99
+ inputSchema: {
100
+ parse(v: unknown): TInput;
101
+ };
102
+ definition: WorkflowDefinition;
103
+ }, input: TInput, options?: StartOptions) => Promise<Result<WorkflowCreatedResult, FlowError>>;
104
+ executeStep: (workflowId: WorkflowId, stepId: StepId) => Promise<Result<void, FlowError>>;
105
+ resumeStep: (workflowId: WorkflowId, stepKey: string, payload?: Record<string, unknown>) => Promise<Result<void, FlowError>>;
106
+ handleStepExhausted: (workflowId: WorkflowId, stepId: StepId, errorMessage: string) => Promise<void>;
107
+ recoverStuckWorkflows: () => Promise<{
108
+ recoveredSteps: number;
109
+ recoveredWorkflows: number;
110
+ }>;
111
+ cancelWorkflow: (workflowId: WorkflowId) => Promise<Result<void, FlowError>>;
112
+ getWorkflowStatus: (workflowId: WorkflowId) => Promise<Result<WorkflowWithSteps, FlowError>>;
113
+ listWorkflows: (filters?: {
114
+ status?: WorkflowStatus;
115
+ type?: string;
116
+ entityRef?: string;
117
+ limit?: number;
118
+ }) => Promise<Result<WorkflowWithSteps[], FlowError>>;
119
+ };
120
+ type WorkflowEngine<TContext = unknown> = ReturnType<typeof createWorkflowEngine<TContext>>;
121
+ //#endregion
122
+ //#region src/core/in-memory-store.d.ts
123
+ /**
124
+ * Reference `WorkflowStore` backed by plain Maps. Intended for tests and single-
125
+ * process experimentation — NOT durable. Partition-scoped at construction to
126
+ * mirror real adapters (the partition value is recorded but isolation is trivial
127
+ * since each instance owns its own maps).
128
+ */
129
+ declare function createInMemoryWorkflowStore(partitionKey?: string): WorkflowStore & {
130
+ /** Test helper: read everything currently stored. */
131
+ _dump(): {
132
+ workflows: WorkflowRecord[];
133
+ steps: StepRecord[];
134
+ };
135
+ };
136
+ //#endregion
137
+ export { AddChildStep, AfterStepArgs, BeforeStartArgs, BeforeStartResult, BuildStepContextArgs, CompleteStepParams, ConcurrencyRule, CreateWorkflowParams, CreateWorkflowStep, CreatedWorkflow, DispatchStepPayload, Dispatcher, EnqueueOptions, FailStepParams, FinishWorkflowParams, FlowError, FlowErrorShape, FlowEvent, FlowEventType, FlowObserver, FlowSpan, FlowTracer, InMemoryStepGateConfig, InvalidWorkflowDefinitionError, ListWorkflowsFilters, LogAttributes, Logger, PUBLIC_WORKFLOW_SCHEMA, PUBLIC_WORKFLOW_STEP_SCHEMA, PublicWorkflow, PublicWorkflowStep, RateRule, RecordedSpan, RecordingObserver, RecordingTracer, Result, RetryPolicy, STEP_DISPLAY_STATUS, STEP_DISPLAY_STATUS_SCHEMA, StartOptions, StepCompensateHandler, StepCompensationContext, StepDefinition, StepDisplayStatus, StepError, StepExecutionContext, StepGate, StepGateDecision, StepGateRequest, StepHandler, StepHandlerNotFoundError, StepHandlerRegistry, StepId, StepOutput, StepRecord, StepRegistration, StepStatus, TypedStep, TypedStepContext, TypedWorkflow, WORKFLOW_STATUS_SCHEMA, WorkflowCompletedArgs, WorkflowCreatedResult, WorkflowDefinition, WorkflowEngine, WorkflowEngineConfig, WorkflowEngineDeps, WorkflowHooks, WorkflowId, WorkflowNotFoundError, WorkflowOutput, WorkflowRecord, WorkflowStatus, WorkflowStore, WorkflowWithSteps, buildWorkflow, createInMemoryStepGate, createInMemoryWorkflowStore, createRecordingObserver, createRecordingTracer, createStepHandlerRegistry, createWorkflowEngine, defineMapStep, defineSleepStep, defineStep, defineSubWorkflowStep, defineWaitStep, err, explicitRetryability, isRetryableError, markRetryable, nonRetryableError, noopLogger, noopObserver, noopTracer, ok, retryableError, toDisplayStepStatus, toPublicStep, toPublicWorkflow };