@dudousxd/nestjs-durable-core 0.49.4 → 0.50.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.
- package/dist/index.cjs +46 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +191 -8
- package/dist/index.d.ts +191 -8
- package/dist/index.js +45 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -161,6 +161,74 @@ declare class InMemoryAdmissionBackend implements AdmissionBackend {
|
|
|
161
161
|
release(queue: string, _slotId: string): Promise<void>;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Vendored subset of the Standard Schema spec (https://standardschema.dev) — the `~standard`
|
|
166
|
+
* property protocol implemented by zod 3.24+, valibot, arktype, and others. Vendored (rather than
|
|
167
|
+
* taken as a dependency) so core stays dependency-free at runtime: this file is types only, erased
|
|
168
|
+
* entirely by the build. Source: https://github.com/standard-schema/standard-schema (MIT, Colin
|
|
169
|
+
* McDonnell) — trimmed to the `StandardSchemaV1` shape this package actually consumes (drops the
|
|
170
|
+
* sibling `StandardTypedV1`/`StandardJSONSchemaV1` specs the upstream package also exports).
|
|
171
|
+
*
|
|
172
|
+
* Used to type `@Workflow({ searchAttributes })` (see `WorkflowMeta.searchAttributes` in
|
|
173
|
+
* `@dudousxd/nestjs-durable` and `SearchAttributesSchema`/`InferSearchAttributes` in `interfaces.ts`)
|
|
174
|
+
* so a workflow can declare its search-attribute shape with whatever schema library it already uses,
|
|
175
|
+
* without core taking a hard dependency on any of them.
|
|
176
|
+
*/
|
|
177
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
178
|
+
/** The Standard Schema properties. */
|
|
179
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
180
|
+
}
|
|
181
|
+
declare namespace StandardSchemaV1 {
|
|
182
|
+
/** The Standard Schema properties interface. */
|
|
183
|
+
interface Props<Input = unknown, Output = Input> {
|
|
184
|
+
/** The version number of the standard. */
|
|
185
|
+
readonly version: 1;
|
|
186
|
+
/** The vendor name of the schema library. */
|
|
187
|
+
readonly vendor: string;
|
|
188
|
+
/** Validates unknown input values. */
|
|
189
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
190
|
+
/** Inferred types associated with the schema. */
|
|
191
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
192
|
+
}
|
|
193
|
+
/** The result interface of the validate function. */
|
|
194
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
195
|
+
/** The result interface if validation succeeds. */
|
|
196
|
+
interface SuccessResult<Output> {
|
|
197
|
+
/** The typed output value. */
|
|
198
|
+
readonly value: Output;
|
|
199
|
+
/** A falsy value for `issues` indicates success. */
|
|
200
|
+
readonly issues?: undefined;
|
|
201
|
+
}
|
|
202
|
+
/** The result interface if validation fails. */
|
|
203
|
+
interface FailureResult {
|
|
204
|
+
/** The issues of failed validation. */
|
|
205
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
206
|
+
}
|
|
207
|
+
/** The issue interface of the failure output. */
|
|
208
|
+
interface Issue {
|
|
209
|
+
/** The error message of the issue. */
|
|
210
|
+
readonly message: string;
|
|
211
|
+
/** The path of the issue, if any. */
|
|
212
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
213
|
+
}
|
|
214
|
+
/** The path segment interface of the issue. */
|
|
215
|
+
interface PathSegment {
|
|
216
|
+
/** The key representing a path segment. */
|
|
217
|
+
readonly key: PropertyKey;
|
|
218
|
+
}
|
|
219
|
+
/** The Standard Schema types interface. */
|
|
220
|
+
interface Types<Input = unknown, Output = Input> {
|
|
221
|
+
/** The input type of the schema. */
|
|
222
|
+
readonly input: Input;
|
|
223
|
+
/** The output type of the schema. */
|
|
224
|
+
readonly output: Output;
|
|
225
|
+
}
|
|
226
|
+
/** Infers the input type of a Standard Schema. */
|
|
227
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
228
|
+
/** Infers the output type of a Standard Schema. */
|
|
229
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
230
|
+
}
|
|
231
|
+
|
|
164
232
|
/**
|
|
165
233
|
* Cross-package step-name stamp. The `@Step` decorator (`@dudousxd/nestjs-durable`) writes a
|
|
166
234
|
* method's derived routing name under this key; core's `ctx.step` reads it (via {@link stepNameOf})
|
|
@@ -337,8 +405,10 @@ interface WorkflowRun {
|
|
|
337
405
|
* store-backed gateway from the run's signal waiters (`listSignalWaiters`, ONE bulk scan), so the
|
|
338
406
|
* dashboard can NAME the wait in a list row without fetching each run's timeline. `on` is derived from
|
|
339
407
|
* the waiter token's prefix (see `classifyWaiterToken`): `wh:<runId>:<seq>` ⇒ `webhook`, `child:<id>`
|
|
340
|
-
* ⇒ `child`, `
|
|
341
|
-
*
|
|
408
|
+
* ⇒ `child`, `bp:<runId>:<seq>` ⇒ `breakpoint` (a `ctx.breakpoint` DOES register a signal waiter —
|
|
409
|
+
* same machinery, `engine.continue` resumes it — so it's classified here, not left to fall through to
|
|
410
|
+
* the generic `signal` case with the raw token as its ugly display name), `event:<name>:…` ⇒ `signal`
|
|
411
|
+
* (name decoded), anything else ⇒ `signal` (the token IS the signal name).
|
|
342
412
|
*
|
|
343
413
|
* Deliberately EVENT-only (no timer/step): `wakeAt` alone can't tell a real `ctx.sleep` from the
|
|
344
414
|
* reconcile-fallback `wakeAt` an event/step suspend now carries, and the store exposes no cheap bulk
|
|
@@ -347,8 +417,13 @@ interface WorkflowRun {
|
|
|
347
417
|
* The detail view (which has the timeline) still distinguishes sleep vs in-flight step precisely.
|
|
348
418
|
*/
|
|
349
419
|
interface RunWaiting {
|
|
350
|
-
on: 'signal' | 'webhook' | 'child';
|
|
351
|
-
/**
|
|
420
|
+
on: 'signal' | 'webhook' | 'child' | 'breakpoint';
|
|
421
|
+
/**
|
|
422
|
+
* The token/name the run is parked on — the signal name, webhook token, or awaited child id. For a
|
|
423
|
+
* breakpoint this is always the literal `'breakpoint'`: the real label (if any) lives on the pending
|
|
424
|
+
* `breakpoint`/`breakpoint:<label>` checkpoint, which the detail view's timeline already shows —
|
|
425
|
+
* naming it here would need an extra per-run checkpoint read, defeating the bulk waiter scan.
|
|
426
|
+
*/
|
|
352
427
|
name: string;
|
|
353
428
|
}
|
|
354
429
|
type StepKind = 'local' | 'remote' | 'sleep' | 'signal';
|
|
@@ -618,6 +693,38 @@ interface RetentionPolicy {
|
|
|
618
693
|
}
|
|
619
694
|
/** Typed, queryable per-run data — exact values for `eq`/`ne`, numbers/strings for range ops. */
|
|
620
695
|
type SearchAttributes = Record<string, string | number | boolean>;
|
|
696
|
+
/**
|
|
697
|
+
* A Standard Schema (https://standardschema.dev — implemented by zod 3.24+, valibot, arktype, …)
|
|
698
|
+
* whose validated OUTPUT is search-attribute-shaped: flat `string`/`number`/`boolean` values only.
|
|
699
|
+
* Declared via `@Workflow({ searchAttributes })`, this makes `ctx.upsertSearchAttributes` reject any
|
|
700
|
+
* write whose merged result doesn't conform. The `Output extends SearchAttributes` bound is enforced
|
|
701
|
+
* structurally at the declaration site — a schema whose inferred output has a nested object/array
|
|
702
|
+
* value (e.g. `z.object({ meta: z.object({ ... }) })`) fails to satisfy this type, so it's a
|
|
703
|
+
* compile-time error to declare it as a `searchAttributes` schema, not a runtime surprise.
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```ts
|
|
707
|
+
* import { z } from 'zod';
|
|
708
|
+
*
|
|
709
|
+
* const orderAttrs = z.object({
|
|
710
|
+
* tier: z.enum(['free', 'pro']),
|
|
711
|
+
* amount: z.number(),
|
|
712
|
+
* rushOrder: z.boolean().optional(),
|
|
713
|
+
* });
|
|
714
|
+
*
|
|
715
|
+
* @Workflow({ name: 'checkout', searchAttributes: orderAttrs })
|
|
716
|
+
* class CheckoutWorkflow {
|
|
717
|
+
* async run(ctx: WorkflowCtx<InferSearchAttributes<typeof orderAttrs>>, input: CheckoutInput) {
|
|
718
|
+
* await ctx.upsertSearchAttributes({ tier: input.tier, amount: input.total });
|
|
719
|
+
* }
|
|
720
|
+
* }
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
type SearchAttributesSchema<A extends SearchAttributes = SearchAttributes> = StandardSchemaV1<unknown, A>;
|
|
724
|
+
/** Infer the validated OUTPUT shape of a {@link SearchAttributesSchema} — the typed attributes a
|
|
725
|
+
* workflow declares via `@Workflow({ searchAttributes })`. Feed it straight into `WorkflowCtx<A>`:
|
|
726
|
+
* `WorkflowCtx<InferSearchAttributes<typeof mySchema>>`. */
|
|
727
|
+
type InferSearchAttributes<S extends StandardSchemaV1<unknown, SearchAttributes>> = StandardSchemaV1.InferOutput<S>;
|
|
621
728
|
type AttributeOp = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
|
|
622
729
|
/** One predicate over a run's {@link SearchAttributes}; a {@link RunQuery} ANDs them all. */
|
|
623
730
|
interface AttributeFilter {
|
|
@@ -733,6 +840,9 @@ type RunRequestKind = {
|
|
|
733
840
|
} | {
|
|
734
841
|
kind: 'redispatch';
|
|
735
842
|
runId: string;
|
|
843
|
+
} | {
|
|
844
|
+
kind: 'waitingFor';
|
|
845
|
+
runIds: string[];
|
|
736
846
|
};
|
|
737
847
|
/** The control plane's answer to a {@link RunRequest}, correlated by `requestId`. */
|
|
738
848
|
interface RunReply {
|
|
@@ -1323,8 +1433,13 @@ type UndoOf<H> = H extends (input: infer I, ...rest: never[]) => infer R ? StepU
|
|
|
1323
1433
|
/**
|
|
1324
1434
|
* The context handed to a workflow function. Every interaction with the outside world goes
|
|
1325
1435
|
* through it so the engine can checkpoint — the workflow body itself stays deterministic.
|
|
1436
|
+
*
|
|
1437
|
+
* Generic over `A`, the run's {@link SearchAttributes} shape — narrows {@link upsertSearchAttributes}
|
|
1438
|
+
* when a workflow declares a `@Workflow({ searchAttributes })` schema (pass
|
|
1439
|
+
* `WorkflowCtx<InferSearchAttributes<typeof mySchema>>` as the `run` method's ctx type). Defaults to
|
|
1440
|
+
* the untyped `SearchAttributes`, so every existing `WorkflowCtx` usage is unaffected.
|
|
1326
1441
|
*/
|
|
1327
|
-
interface WorkflowCtx {
|
|
1442
|
+
interface WorkflowCtx<A extends SearchAttributes = SearchAttributes> {
|
|
1328
1443
|
readonly runId: string;
|
|
1329
1444
|
/**
|
|
1330
1445
|
* Run a durable step — always dispatched, always engine-scheduled: the ONE step primitive (no
|
|
@@ -1531,8 +1646,16 @@ interface WorkflowCtx {
|
|
|
1531
1646
|
* write, not one per turn. Use this instead of injecting the {@link StateStore} to mutate the run
|
|
1532
1647
|
* you're executing (`@Inject(state-store)` + `store.updateRun(ctx.runId, …)` becomes
|
|
1533
1648
|
* `ctx.upsertSearchAttributes(…)`).
|
|
1649
|
+
*
|
|
1650
|
+
* When the workflow declares a `@Workflow({ searchAttributes })` schema, the MERGED result (this
|
|
1651
|
+
* run's existing `searchAttributes` shallow-merged with `attrs`) is validated against it before the
|
|
1652
|
+
* write — an invalid merge throws, naming the workflow, the offending key(s), and the schema's
|
|
1653
|
+
* issues. Validation runs once, on the same first-run-only position as the write itself (skipped
|
|
1654
|
+
* entirely on replay, so it's never a source of nondeterminism); it must be synchronous — a schema
|
|
1655
|
+
* whose `validate` returns a `Promise` throws instead of being awaited. No schema declared ⇒
|
|
1656
|
+
* unchanged, unvalidated behavior.
|
|
1534
1657
|
*/
|
|
1535
|
-
upsertSearchAttributes(attrs:
|
|
1658
|
+
upsertSearchAttributes(attrs: Partial<A>): Promise<void>;
|
|
1536
1659
|
/**
|
|
1537
1660
|
* Run a checkpointed step **in-process** — the escape hatch from the always-dispatched {@link step}
|
|
1538
1661
|
* for work that must run inline in the workflow body. Like `step`, its result is a durable checkpoint
|
|
@@ -2009,6 +2132,8 @@ declare class WorkflowEngine {
|
|
|
2009
2132
|
singleton?: SingletonConfig | undefined;
|
|
2010
2133
|
executionTimeout?: string | number | undefined;
|
|
2011
2134
|
validateInput?: ((input: unknown) => void | Promise<void>) | undefined;
|
|
2135
|
+
/** Typed/validated `searchAttributes` shape — see `RegisteredWorkflow.searchAttributesSchema`. */
|
|
2136
|
+
searchAttributesSchema?: SearchAttributesSchema | undefined;
|
|
2012
2137
|
onEvent?: string[] | undefined;
|
|
2013
2138
|
eventBatch?: EventBatchConfig | undefined;
|
|
2014
2139
|
/** Worker group to DISPATCH this workflow's turns to (uniform dispatch). Requires `executor`.
|
|
@@ -2832,7 +2957,9 @@ interface DurableTopology {
|
|
|
2832
2957
|
/** The tenant's isolation partition name; set only when `role` is 'tenant'. */
|
|
2833
2958
|
tenant?: string;
|
|
2834
2959
|
}
|
|
2835
|
-
/** A run + its timeline + child ids — the detail view.
|
|
2960
|
+
/** A run + its timeline + child ids — the detail view. Single source of truth: the dashboard server
|
|
2961
|
+
* re-exports this instead of re-declaring it, and the dashboard client derives its wire mirror from
|
|
2962
|
+
* it via {@link WireDates} instead of hand-mirroring field by field. */
|
|
2836
2963
|
interface RunDetail {
|
|
2837
2964
|
run: WorkflowRun;
|
|
2838
2965
|
/** Steps in execution order (local + remote). */
|
|
@@ -2840,6 +2967,17 @@ interface RunDetail {
|
|
|
2840
2967
|
/** Ids of runs this run spawned (parent→children tree). */
|
|
2841
2968
|
children: string[];
|
|
2842
2969
|
}
|
|
2970
|
+
/**
|
|
2971
|
+
* Maps every `Date` (and `Date | undefined`) field of `T` to its ISO-string wire form — the shape a
|
|
2972
|
+
* JSON response actually carries once dates cross the wire (`JSON.stringify` already does this
|
|
2973
|
+
* coercion; this just types it). Homomorphic: each field keeps its own optional modifier, so a
|
|
2974
|
+
* required `Date` becomes a required `string` and an optional one stays optional. Lets a consumer
|
|
2975
|
+
* derive its own wire-facing client type from a core server type (e.g. the dashboard's SPA `WorkflowRun`/
|
|
2976
|
+
* `StepCheckpoint`/`RunDetail`) instead of hand-mirroring it field by field and drifting.
|
|
2977
|
+
*/
|
|
2978
|
+
type WireDates<T> = {
|
|
2979
|
+
[K in keyof T]: T[K] extends Date ? string : T[K] extends Date | undefined ? string | undefined : T[K];
|
|
2980
|
+
};
|
|
2843
2981
|
/**
|
|
2844
2982
|
* The bounded read/control/stream surface a consumer (e.g. a controller) needs, satisfied by BOTH
|
|
2845
2983
|
* topologies: the control plane binds a store-backed impl (reuses `DashboardService`); a tenant binds
|
|
@@ -2855,6 +2993,17 @@ interface RunGateway {
|
|
|
2855
2993
|
* parked on). The store-backed gateway resolves `waiting`; a proxy relays whatever the control
|
|
2856
2994
|
* plane sent. */
|
|
2857
2995
|
listRuns(query: RunQuery): Promise<RunListItem[]>;
|
|
2996
|
+
/**
|
|
2997
|
+
* Bulk-resolve {@link RunWaiting} for an arbitrary set of run ids — for a consumer with its OWN
|
|
2998
|
+
* filtered/paginated run listing (so it isn't just `listRuns` under another name) that needs to know
|
|
2999
|
+
* which of ITS runs are parked on a breakpoint (or any other event wait) without re-deriving the bulk
|
|
3000
|
+
* waiter scan itself or reaching for raw SQL against `durable_step_checkpoints`. A `Record` (not a
|
|
3001
|
+
* `Map`) because `ProxyRunGateway` serialises the reply over the transport as plain JSON. Entries are
|
|
3002
|
+
* present ONLY for runs currently waiting — an unknown id, a non-suspended id, and a suspended id
|
|
3003
|
+
* parked on something non-event (a bare `ctx.sleep`, an in-flight step) are simply absent, same as a
|
|
3004
|
+
* `listRuns` row with no `waiting`.
|
|
3005
|
+
*/
|
|
3006
|
+
waitingFor(runIds: string[]): Promise<Record<string, RunWaiting>>;
|
|
2858
3007
|
/** Per-group worker health (queue backlog + live worker heartbeats). On the control plane this is
|
|
2859
3008
|
* every group; over a tenant proxy the operator scopes it to the tenant's own groups. */
|
|
2860
3009
|
workerHealth(): Promise<GroupHealth[]>;
|
|
@@ -2881,6 +3030,11 @@ interface RunGateway {
|
|
|
2881
3030
|
* The token prefix carries the kind — no extra store lookup and no new persisted field. Used by the
|
|
2882
3031
|
* store-backed run gateway to stamp {@link RunWaiting} onto each listed run so the dashboard can name
|
|
2883
3032
|
* the wait in a row without fetching that run's timeline.
|
|
3033
|
+
*
|
|
3034
|
+
* `ctx.breakpoint` reuses the signal-waiter machinery (`engine.continue` resumes it via `signal()`
|
|
3035
|
+
* like any other), so without this case it would fall through to the generic `signal` branch with the
|
|
3036
|
+
* raw `bp:<runId>:<seq>` token as its display name — a real bug. Named `'breakpoint'` here instead;
|
|
3037
|
+
* the token carries no separate label to recover cheaply (see {@link RunWaiting.name}).
|
|
2884
3038
|
*/
|
|
2885
3039
|
declare function classifyWaiterToken(token: string): RunWaiting;
|
|
2886
3040
|
/**
|
|
@@ -3128,6 +3282,35 @@ declare function attributeColumnFor(filter: AttributeFilter): 'numValue' | 'strV
|
|
|
3128
3282
|
/** The literal a side-table predicate compares against (booleans → `"true"`/`"false"` strings). */
|
|
3129
3283
|
declare function attributeOperand(filter: AttributeFilter): string | number;
|
|
3130
3284
|
|
|
3285
|
+
/**
|
|
3286
|
+
* Read a run's `searchAttributes` through a {@link SearchAttributesSchema}, typed to the schema's
|
|
3287
|
+
* inferred output. **Safe-parse semantics, deliberately lenient** — unlike
|
|
3288
|
+
* `ctx.upsertSearchAttributes` (which is strict: an invalid merge throws), a failed validation here
|
|
3289
|
+
* returns `{}` rather than throwing. This is intentional: `run.searchAttributes` may predate the
|
|
3290
|
+
* schema (an older deploy wrote it under a looser or absent schema, or a run started before this
|
|
3291
|
+
* workflow ever declared one), and a dashboard/read path crashing on old history is worse than it
|
|
3292
|
+
* quietly reporting no typed attributes for that run. Write-time enforcement is what keeps NEW writes
|
|
3293
|
+
* conformant; this is the read-side counterpart for consuming them.
|
|
3294
|
+
*
|
|
3295
|
+
* The schema's `validate` must be synchronous (matching the write-side constraint in
|
|
3296
|
+
* `ctx.upsertSearchAttributes`) — one returning a `Promise` throws with a clear error rather than
|
|
3297
|
+
* being silently awaited or silently treated as a failure.
|
|
3298
|
+
*
|
|
3299
|
+
* @example
|
|
3300
|
+
* ```ts
|
|
3301
|
+
* import { z } from 'zod';
|
|
3302
|
+
* import { readSearchAttributes } from '@dudousxd/nestjs-durable-core';
|
|
3303
|
+
*
|
|
3304
|
+
* const orderAttrs = z.object({ tier: z.enum(['free', 'pro']), amount: z.number() });
|
|
3305
|
+
*
|
|
3306
|
+
* const run = await store.getRun(runId);
|
|
3307
|
+
* const attrs = readSearchAttributes(orderAttrs, run ?? {}); // { tier: 'pro', amount: 42 } | {}
|
|
3308
|
+
* ```
|
|
3309
|
+
*/
|
|
3310
|
+
declare function readSearchAttributes<S extends SearchAttributesSchema>(schema: S, run: {
|
|
3311
|
+
searchAttributes?: SearchAttributes | undefined;
|
|
3312
|
+
}): InferSearchAttributes<S>;
|
|
3313
|
+
|
|
3131
3314
|
/**
|
|
3132
3315
|
* Compute the worker group a tenant's run dispatches to. Mirrors the transport's
|
|
3133
3316
|
* default-is-bare rule (see {@link TransportPool.useNamespace}'s `'default'` no-op): a
|
|
@@ -3275,4 +3458,4 @@ declare class InMemoryTransport implements Transport, ControlPlane {
|
|
|
3275
3458
|
onControl(handler: (msg: ControlMessage) => void): void;
|
|
3276
3459
|
}
|
|
3277
3460
|
|
|
3278
|
-
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AttributeFilter, type AttributeOp, type BackoffStrategy, type ChildCallOptions, CodecStateStore, ContinueAsNew, type ControlMessage, type ControlPlane, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type DurableTopology, type DurableWebhook, DurableWorkflow, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type MetricsCollector, type MetricsSnapshot, type NamedTransport, NonDeterminismError, type PayloadCodec, type QueueConfig, QueueController, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RunAttributeRow, type RunDetail, type RunDispatcher, type RunGateway, type RunListItem, type RunQuery, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunStatus, type RunWaiting, STATE_STORE, STATE_STORE_CANONICAL, type ScheduledWorkflow, type SearchAttributes, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, WORKFLOW_NAME_KEY, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerHeartbeat, type WorkerStatus, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, applyAttributeQuery, attributeColumnFor, attributeOperand, bindWorkflowClass, breakpointToken, classifyWaiterToken, collectMetrics, createStepLogger, currentWorkflowCtx, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, indexWaitersByRun, matchesAttributes, normalizeAttributeRows, parseDuration, prevCronFireMs, resolveRunWaiting, runInWorkflowCtx, runSchedules, runStepHandler, sanitizeQueueToken, scheduledRunId, sqlComparator, stepConfigOf, stepId, stepNameOf, tenantGroup, workflowName };
|
|
3461
|
+
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AttributeFilter, type AttributeOp, type BackoffStrategy, type ChildCallOptions, CodecStateStore, ContinueAsNew, type ControlMessage, type ControlPlane, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type DurableTopology, type DurableWebhook, DurableWorkflow, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, type MetricsCollector, type MetricsSnapshot, type NamedTransport, NonDeterminismError, type PayloadCodec, type QueueConfig, QueueController, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RunAttributeRow, type RunDetail, type RunDispatcher, type RunGateway, type RunListItem, type RunQuery, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunStatus, type RunWaiting, STATE_STORE, STATE_STORE_CANONICAL, type ScheduledWorkflow, type SearchAttributes, type SearchAttributesSchema, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerHeartbeat, type WorkerStatus, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, applyAttributeQuery, attributeColumnFor, attributeOperand, bindWorkflowClass, breakpointToken, classifyWaiterToken, collectMetrics, createStepLogger, currentWorkflowCtx, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, indexWaitersByRun, matchesAttributes, normalizeAttributeRows, parseDuration, prevCronFireMs, readSearchAttributes, resolveRunWaiting, runInWorkflowCtx, runSchedules, runStepHandler, sanitizeQueueToken, scheduledRunId, sqlComparator, stepConfigOf, stepId, stepNameOf, tenantGroup, workflowName };
|
package/dist/index.d.ts
CHANGED
|
@@ -161,6 +161,74 @@ declare class InMemoryAdmissionBackend implements AdmissionBackend {
|
|
|
161
161
|
release(queue: string, _slotId: string): Promise<void>;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Vendored subset of the Standard Schema spec (https://standardschema.dev) — the `~standard`
|
|
166
|
+
* property protocol implemented by zod 3.24+, valibot, arktype, and others. Vendored (rather than
|
|
167
|
+
* taken as a dependency) so core stays dependency-free at runtime: this file is types only, erased
|
|
168
|
+
* entirely by the build. Source: https://github.com/standard-schema/standard-schema (MIT, Colin
|
|
169
|
+
* McDonnell) — trimmed to the `StandardSchemaV1` shape this package actually consumes (drops the
|
|
170
|
+
* sibling `StandardTypedV1`/`StandardJSONSchemaV1` specs the upstream package also exports).
|
|
171
|
+
*
|
|
172
|
+
* Used to type `@Workflow({ searchAttributes })` (see `WorkflowMeta.searchAttributes` in
|
|
173
|
+
* `@dudousxd/nestjs-durable` and `SearchAttributesSchema`/`InferSearchAttributes` in `interfaces.ts`)
|
|
174
|
+
* so a workflow can declare its search-attribute shape with whatever schema library it already uses,
|
|
175
|
+
* without core taking a hard dependency on any of them.
|
|
176
|
+
*/
|
|
177
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
178
|
+
/** The Standard Schema properties. */
|
|
179
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
180
|
+
}
|
|
181
|
+
declare namespace StandardSchemaV1 {
|
|
182
|
+
/** The Standard Schema properties interface. */
|
|
183
|
+
interface Props<Input = unknown, Output = Input> {
|
|
184
|
+
/** The version number of the standard. */
|
|
185
|
+
readonly version: 1;
|
|
186
|
+
/** The vendor name of the schema library. */
|
|
187
|
+
readonly vendor: string;
|
|
188
|
+
/** Validates unknown input values. */
|
|
189
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
190
|
+
/** Inferred types associated with the schema. */
|
|
191
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
192
|
+
}
|
|
193
|
+
/** The result interface of the validate function. */
|
|
194
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
195
|
+
/** The result interface if validation succeeds. */
|
|
196
|
+
interface SuccessResult<Output> {
|
|
197
|
+
/** The typed output value. */
|
|
198
|
+
readonly value: Output;
|
|
199
|
+
/** A falsy value for `issues` indicates success. */
|
|
200
|
+
readonly issues?: undefined;
|
|
201
|
+
}
|
|
202
|
+
/** The result interface if validation fails. */
|
|
203
|
+
interface FailureResult {
|
|
204
|
+
/** The issues of failed validation. */
|
|
205
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
206
|
+
}
|
|
207
|
+
/** The issue interface of the failure output. */
|
|
208
|
+
interface Issue {
|
|
209
|
+
/** The error message of the issue. */
|
|
210
|
+
readonly message: string;
|
|
211
|
+
/** The path of the issue, if any. */
|
|
212
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
213
|
+
}
|
|
214
|
+
/** The path segment interface of the issue. */
|
|
215
|
+
interface PathSegment {
|
|
216
|
+
/** The key representing a path segment. */
|
|
217
|
+
readonly key: PropertyKey;
|
|
218
|
+
}
|
|
219
|
+
/** The Standard Schema types interface. */
|
|
220
|
+
interface Types<Input = unknown, Output = Input> {
|
|
221
|
+
/** The input type of the schema. */
|
|
222
|
+
readonly input: Input;
|
|
223
|
+
/** The output type of the schema. */
|
|
224
|
+
readonly output: Output;
|
|
225
|
+
}
|
|
226
|
+
/** Infers the input type of a Standard Schema. */
|
|
227
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
228
|
+
/** Infers the output type of a Standard Schema. */
|
|
229
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
230
|
+
}
|
|
231
|
+
|
|
164
232
|
/**
|
|
165
233
|
* Cross-package step-name stamp. The `@Step` decorator (`@dudousxd/nestjs-durable`) writes a
|
|
166
234
|
* method's derived routing name under this key; core's `ctx.step` reads it (via {@link stepNameOf})
|
|
@@ -337,8 +405,10 @@ interface WorkflowRun {
|
|
|
337
405
|
* store-backed gateway from the run's signal waiters (`listSignalWaiters`, ONE bulk scan), so the
|
|
338
406
|
* dashboard can NAME the wait in a list row without fetching each run's timeline. `on` is derived from
|
|
339
407
|
* the waiter token's prefix (see `classifyWaiterToken`): `wh:<runId>:<seq>` ⇒ `webhook`, `child:<id>`
|
|
340
|
-
* ⇒ `child`, `
|
|
341
|
-
*
|
|
408
|
+
* ⇒ `child`, `bp:<runId>:<seq>` ⇒ `breakpoint` (a `ctx.breakpoint` DOES register a signal waiter —
|
|
409
|
+
* same machinery, `engine.continue` resumes it — so it's classified here, not left to fall through to
|
|
410
|
+
* the generic `signal` case with the raw token as its ugly display name), `event:<name>:…` ⇒ `signal`
|
|
411
|
+
* (name decoded), anything else ⇒ `signal` (the token IS the signal name).
|
|
342
412
|
*
|
|
343
413
|
* Deliberately EVENT-only (no timer/step): `wakeAt` alone can't tell a real `ctx.sleep` from the
|
|
344
414
|
* reconcile-fallback `wakeAt` an event/step suspend now carries, and the store exposes no cheap bulk
|
|
@@ -347,8 +417,13 @@ interface WorkflowRun {
|
|
|
347
417
|
* The detail view (which has the timeline) still distinguishes sleep vs in-flight step precisely.
|
|
348
418
|
*/
|
|
349
419
|
interface RunWaiting {
|
|
350
|
-
on: 'signal' | 'webhook' | 'child';
|
|
351
|
-
/**
|
|
420
|
+
on: 'signal' | 'webhook' | 'child' | 'breakpoint';
|
|
421
|
+
/**
|
|
422
|
+
* The token/name the run is parked on — the signal name, webhook token, or awaited child id. For a
|
|
423
|
+
* breakpoint this is always the literal `'breakpoint'`: the real label (if any) lives on the pending
|
|
424
|
+
* `breakpoint`/`breakpoint:<label>` checkpoint, which the detail view's timeline already shows —
|
|
425
|
+
* naming it here would need an extra per-run checkpoint read, defeating the bulk waiter scan.
|
|
426
|
+
*/
|
|
352
427
|
name: string;
|
|
353
428
|
}
|
|
354
429
|
type StepKind = 'local' | 'remote' | 'sleep' | 'signal';
|
|
@@ -618,6 +693,38 @@ interface RetentionPolicy {
|
|
|
618
693
|
}
|
|
619
694
|
/** Typed, queryable per-run data — exact values for `eq`/`ne`, numbers/strings for range ops. */
|
|
620
695
|
type SearchAttributes = Record<string, string | number | boolean>;
|
|
696
|
+
/**
|
|
697
|
+
* A Standard Schema (https://standardschema.dev — implemented by zod 3.24+, valibot, arktype, …)
|
|
698
|
+
* whose validated OUTPUT is search-attribute-shaped: flat `string`/`number`/`boolean` values only.
|
|
699
|
+
* Declared via `@Workflow({ searchAttributes })`, this makes `ctx.upsertSearchAttributes` reject any
|
|
700
|
+
* write whose merged result doesn't conform. The `Output extends SearchAttributes` bound is enforced
|
|
701
|
+
* structurally at the declaration site — a schema whose inferred output has a nested object/array
|
|
702
|
+
* value (e.g. `z.object({ meta: z.object({ ... }) })`) fails to satisfy this type, so it's a
|
|
703
|
+
* compile-time error to declare it as a `searchAttributes` schema, not a runtime surprise.
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```ts
|
|
707
|
+
* import { z } from 'zod';
|
|
708
|
+
*
|
|
709
|
+
* const orderAttrs = z.object({
|
|
710
|
+
* tier: z.enum(['free', 'pro']),
|
|
711
|
+
* amount: z.number(),
|
|
712
|
+
* rushOrder: z.boolean().optional(),
|
|
713
|
+
* });
|
|
714
|
+
*
|
|
715
|
+
* @Workflow({ name: 'checkout', searchAttributes: orderAttrs })
|
|
716
|
+
* class CheckoutWorkflow {
|
|
717
|
+
* async run(ctx: WorkflowCtx<InferSearchAttributes<typeof orderAttrs>>, input: CheckoutInput) {
|
|
718
|
+
* await ctx.upsertSearchAttributes({ tier: input.tier, amount: input.total });
|
|
719
|
+
* }
|
|
720
|
+
* }
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
type SearchAttributesSchema<A extends SearchAttributes = SearchAttributes> = StandardSchemaV1<unknown, A>;
|
|
724
|
+
/** Infer the validated OUTPUT shape of a {@link SearchAttributesSchema} — the typed attributes a
|
|
725
|
+
* workflow declares via `@Workflow({ searchAttributes })`. Feed it straight into `WorkflowCtx<A>`:
|
|
726
|
+
* `WorkflowCtx<InferSearchAttributes<typeof mySchema>>`. */
|
|
727
|
+
type InferSearchAttributes<S extends StandardSchemaV1<unknown, SearchAttributes>> = StandardSchemaV1.InferOutput<S>;
|
|
621
728
|
type AttributeOp = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
|
|
622
729
|
/** One predicate over a run's {@link SearchAttributes}; a {@link RunQuery} ANDs them all. */
|
|
623
730
|
interface AttributeFilter {
|
|
@@ -733,6 +840,9 @@ type RunRequestKind = {
|
|
|
733
840
|
} | {
|
|
734
841
|
kind: 'redispatch';
|
|
735
842
|
runId: string;
|
|
843
|
+
} | {
|
|
844
|
+
kind: 'waitingFor';
|
|
845
|
+
runIds: string[];
|
|
736
846
|
};
|
|
737
847
|
/** The control plane's answer to a {@link RunRequest}, correlated by `requestId`. */
|
|
738
848
|
interface RunReply {
|
|
@@ -1323,8 +1433,13 @@ type UndoOf<H> = H extends (input: infer I, ...rest: never[]) => infer R ? StepU
|
|
|
1323
1433
|
/**
|
|
1324
1434
|
* The context handed to a workflow function. Every interaction with the outside world goes
|
|
1325
1435
|
* through it so the engine can checkpoint — the workflow body itself stays deterministic.
|
|
1436
|
+
*
|
|
1437
|
+
* Generic over `A`, the run's {@link SearchAttributes} shape — narrows {@link upsertSearchAttributes}
|
|
1438
|
+
* when a workflow declares a `@Workflow({ searchAttributes })` schema (pass
|
|
1439
|
+
* `WorkflowCtx<InferSearchAttributes<typeof mySchema>>` as the `run` method's ctx type). Defaults to
|
|
1440
|
+
* the untyped `SearchAttributes`, so every existing `WorkflowCtx` usage is unaffected.
|
|
1326
1441
|
*/
|
|
1327
|
-
interface WorkflowCtx {
|
|
1442
|
+
interface WorkflowCtx<A extends SearchAttributes = SearchAttributes> {
|
|
1328
1443
|
readonly runId: string;
|
|
1329
1444
|
/**
|
|
1330
1445
|
* Run a durable step — always dispatched, always engine-scheduled: the ONE step primitive (no
|
|
@@ -1531,8 +1646,16 @@ interface WorkflowCtx {
|
|
|
1531
1646
|
* write, not one per turn. Use this instead of injecting the {@link StateStore} to mutate the run
|
|
1532
1647
|
* you're executing (`@Inject(state-store)` + `store.updateRun(ctx.runId, …)` becomes
|
|
1533
1648
|
* `ctx.upsertSearchAttributes(…)`).
|
|
1649
|
+
*
|
|
1650
|
+
* When the workflow declares a `@Workflow({ searchAttributes })` schema, the MERGED result (this
|
|
1651
|
+
* run's existing `searchAttributes` shallow-merged with `attrs`) is validated against it before the
|
|
1652
|
+
* write — an invalid merge throws, naming the workflow, the offending key(s), and the schema's
|
|
1653
|
+
* issues. Validation runs once, on the same first-run-only position as the write itself (skipped
|
|
1654
|
+
* entirely on replay, so it's never a source of nondeterminism); it must be synchronous — a schema
|
|
1655
|
+
* whose `validate` returns a `Promise` throws instead of being awaited. No schema declared ⇒
|
|
1656
|
+
* unchanged, unvalidated behavior.
|
|
1534
1657
|
*/
|
|
1535
|
-
upsertSearchAttributes(attrs:
|
|
1658
|
+
upsertSearchAttributes(attrs: Partial<A>): Promise<void>;
|
|
1536
1659
|
/**
|
|
1537
1660
|
* Run a checkpointed step **in-process** — the escape hatch from the always-dispatched {@link step}
|
|
1538
1661
|
* for work that must run inline in the workflow body. Like `step`, its result is a durable checkpoint
|
|
@@ -2009,6 +2132,8 @@ declare class WorkflowEngine {
|
|
|
2009
2132
|
singleton?: SingletonConfig | undefined;
|
|
2010
2133
|
executionTimeout?: string | number | undefined;
|
|
2011
2134
|
validateInput?: ((input: unknown) => void | Promise<void>) | undefined;
|
|
2135
|
+
/** Typed/validated `searchAttributes` shape — see `RegisteredWorkflow.searchAttributesSchema`. */
|
|
2136
|
+
searchAttributesSchema?: SearchAttributesSchema | undefined;
|
|
2012
2137
|
onEvent?: string[] | undefined;
|
|
2013
2138
|
eventBatch?: EventBatchConfig | undefined;
|
|
2014
2139
|
/** Worker group to DISPATCH this workflow's turns to (uniform dispatch). Requires `executor`.
|
|
@@ -2832,7 +2957,9 @@ interface DurableTopology {
|
|
|
2832
2957
|
/** The tenant's isolation partition name; set only when `role` is 'tenant'. */
|
|
2833
2958
|
tenant?: string;
|
|
2834
2959
|
}
|
|
2835
|
-
/** A run + its timeline + child ids — the detail view.
|
|
2960
|
+
/** A run + its timeline + child ids — the detail view. Single source of truth: the dashboard server
|
|
2961
|
+
* re-exports this instead of re-declaring it, and the dashboard client derives its wire mirror from
|
|
2962
|
+
* it via {@link WireDates} instead of hand-mirroring field by field. */
|
|
2836
2963
|
interface RunDetail {
|
|
2837
2964
|
run: WorkflowRun;
|
|
2838
2965
|
/** Steps in execution order (local + remote). */
|
|
@@ -2840,6 +2967,17 @@ interface RunDetail {
|
|
|
2840
2967
|
/** Ids of runs this run spawned (parent→children tree). */
|
|
2841
2968
|
children: string[];
|
|
2842
2969
|
}
|
|
2970
|
+
/**
|
|
2971
|
+
* Maps every `Date` (and `Date | undefined`) field of `T` to its ISO-string wire form — the shape a
|
|
2972
|
+
* JSON response actually carries once dates cross the wire (`JSON.stringify` already does this
|
|
2973
|
+
* coercion; this just types it). Homomorphic: each field keeps its own optional modifier, so a
|
|
2974
|
+
* required `Date` becomes a required `string` and an optional one stays optional. Lets a consumer
|
|
2975
|
+
* derive its own wire-facing client type from a core server type (e.g. the dashboard's SPA `WorkflowRun`/
|
|
2976
|
+
* `StepCheckpoint`/`RunDetail`) instead of hand-mirroring it field by field and drifting.
|
|
2977
|
+
*/
|
|
2978
|
+
type WireDates<T> = {
|
|
2979
|
+
[K in keyof T]: T[K] extends Date ? string : T[K] extends Date | undefined ? string | undefined : T[K];
|
|
2980
|
+
};
|
|
2843
2981
|
/**
|
|
2844
2982
|
* The bounded read/control/stream surface a consumer (e.g. a controller) needs, satisfied by BOTH
|
|
2845
2983
|
* topologies: the control plane binds a store-backed impl (reuses `DashboardService`); a tenant binds
|
|
@@ -2855,6 +2993,17 @@ interface RunGateway {
|
|
|
2855
2993
|
* parked on). The store-backed gateway resolves `waiting`; a proxy relays whatever the control
|
|
2856
2994
|
* plane sent. */
|
|
2857
2995
|
listRuns(query: RunQuery): Promise<RunListItem[]>;
|
|
2996
|
+
/**
|
|
2997
|
+
* Bulk-resolve {@link RunWaiting} for an arbitrary set of run ids — for a consumer with its OWN
|
|
2998
|
+
* filtered/paginated run listing (so it isn't just `listRuns` under another name) that needs to know
|
|
2999
|
+
* which of ITS runs are parked on a breakpoint (or any other event wait) without re-deriving the bulk
|
|
3000
|
+
* waiter scan itself or reaching for raw SQL against `durable_step_checkpoints`. A `Record` (not a
|
|
3001
|
+
* `Map`) because `ProxyRunGateway` serialises the reply over the transport as plain JSON. Entries are
|
|
3002
|
+
* present ONLY for runs currently waiting — an unknown id, a non-suspended id, and a suspended id
|
|
3003
|
+
* parked on something non-event (a bare `ctx.sleep`, an in-flight step) are simply absent, same as a
|
|
3004
|
+
* `listRuns` row with no `waiting`.
|
|
3005
|
+
*/
|
|
3006
|
+
waitingFor(runIds: string[]): Promise<Record<string, RunWaiting>>;
|
|
2858
3007
|
/** Per-group worker health (queue backlog + live worker heartbeats). On the control plane this is
|
|
2859
3008
|
* every group; over a tenant proxy the operator scopes it to the tenant's own groups. */
|
|
2860
3009
|
workerHealth(): Promise<GroupHealth[]>;
|
|
@@ -2881,6 +3030,11 @@ interface RunGateway {
|
|
|
2881
3030
|
* The token prefix carries the kind — no extra store lookup and no new persisted field. Used by the
|
|
2882
3031
|
* store-backed run gateway to stamp {@link RunWaiting} onto each listed run so the dashboard can name
|
|
2883
3032
|
* the wait in a row without fetching that run's timeline.
|
|
3033
|
+
*
|
|
3034
|
+
* `ctx.breakpoint` reuses the signal-waiter machinery (`engine.continue` resumes it via `signal()`
|
|
3035
|
+
* like any other), so without this case it would fall through to the generic `signal` branch with the
|
|
3036
|
+
* raw `bp:<runId>:<seq>` token as its display name — a real bug. Named `'breakpoint'` here instead;
|
|
3037
|
+
* the token carries no separate label to recover cheaply (see {@link RunWaiting.name}).
|
|
2884
3038
|
*/
|
|
2885
3039
|
declare function classifyWaiterToken(token: string): RunWaiting;
|
|
2886
3040
|
/**
|
|
@@ -3128,6 +3282,35 @@ declare function attributeColumnFor(filter: AttributeFilter): 'numValue' | 'strV
|
|
|
3128
3282
|
/** The literal a side-table predicate compares against (booleans → `"true"`/`"false"` strings). */
|
|
3129
3283
|
declare function attributeOperand(filter: AttributeFilter): string | number;
|
|
3130
3284
|
|
|
3285
|
+
/**
|
|
3286
|
+
* Read a run's `searchAttributes` through a {@link SearchAttributesSchema}, typed to the schema's
|
|
3287
|
+
* inferred output. **Safe-parse semantics, deliberately lenient** — unlike
|
|
3288
|
+
* `ctx.upsertSearchAttributes` (which is strict: an invalid merge throws), a failed validation here
|
|
3289
|
+
* returns `{}` rather than throwing. This is intentional: `run.searchAttributes` may predate the
|
|
3290
|
+
* schema (an older deploy wrote it under a looser or absent schema, or a run started before this
|
|
3291
|
+
* workflow ever declared one), and a dashboard/read path crashing on old history is worse than it
|
|
3292
|
+
* quietly reporting no typed attributes for that run. Write-time enforcement is what keeps NEW writes
|
|
3293
|
+
* conformant; this is the read-side counterpart for consuming them.
|
|
3294
|
+
*
|
|
3295
|
+
* The schema's `validate` must be synchronous (matching the write-side constraint in
|
|
3296
|
+
* `ctx.upsertSearchAttributes`) — one returning a `Promise` throws with a clear error rather than
|
|
3297
|
+
* being silently awaited or silently treated as a failure.
|
|
3298
|
+
*
|
|
3299
|
+
* @example
|
|
3300
|
+
* ```ts
|
|
3301
|
+
* import { z } from 'zod';
|
|
3302
|
+
* import { readSearchAttributes } from '@dudousxd/nestjs-durable-core';
|
|
3303
|
+
*
|
|
3304
|
+
* const orderAttrs = z.object({ tier: z.enum(['free', 'pro']), amount: z.number() });
|
|
3305
|
+
*
|
|
3306
|
+
* const run = await store.getRun(runId);
|
|
3307
|
+
* const attrs = readSearchAttributes(orderAttrs, run ?? {}); // { tier: 'pro', amount: 42 } | {}
|
|
3308
|
+
* ```
|
|
3309
|
+
*/
|
|
3310
|
+
declare function readSearchAttributes<S extends SearchAttributesSchema>(schema: S, run: {
|
|
3311
|
+
searchAttributes?: SearchAttributes | undefined;
|
|
3312
|
+
}): InferSearchAttributes<S>;
|
|
3313
|
+
|
|
3131
3314
|
/**
|
|
3132
3315
|
* Compute the worker group a tenant's run dispatches to. Mirrors the transport's
|
|
3133
3316
|
* default-is-bare rule (see {@link TransportPool.useNamespace}'s `'default'` no-op): a
|
|
@@ -3275,4 +3458,4 @@ declare class InMemoryTransport implements Transport, ControlPlane {
|
|
|
3275
3458
|
onControl(handler: (msg: ControlMessage) => void): void;
|
|
3276
3459
|
}
|
|
3277
3460
|
|
|
3278
|
-
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AttributeFilter, type AttributeOp, type BackoffStrategy, type ChildCallOptions, CodecStateStore, ContinueAsNew, type ControlMessage, type ControlPlane, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type DurableTopology, type DurableWebhook, DurableWorkflow, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type MetricsCollector, type MetricsSnapshot, type NamedTransport, NonDeterminismError, type PayloadCodec, type QueueConfig, QueueController, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RunAttributeRow, type RunDetail, type RunDispatcher, type RunGateway, type RunListItem, type RunQuery, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunStatus, type RunWaiting, STATE_STORE, STATE_STORE_CANONICAL, type ScheduledWorkflow, type SearchAttributes, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, WORKFLOW_NAME_KEY, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerHeartbeat, type WorkerStatus, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, applyAttributeQuery, attributeColumnFor, attributeOperand, bindWorkflowClass, breakpointToken, classifyWaiterToken, collectMetrics, createStepLogger, currentWorkflowCtx, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, indexWaitersByRun, matchesAttributes, normalizeAttributeRows, parseDuration, prevCronFireMs, resolveRunWaiting, runInWorkflowCtx, runSchedules, runStepHandler, sanitizeQueueToken, scheduledRunId, sqlComparator, stepConfigOf, stepId, stepNameOf, tenantGroup, workflowName };
|
|
3461
|
+
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AttributeFilter, type AttributeOp, type BackoffStrategy, type ChildCallOptions, CodecStateStore, ContinueAsNew, type ControlMessage, type ControlPlane, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type DurableTopology, type DurableWebhook, DurableWorkflow, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, type MetricsCollector, type MetricsSnapshot, type NamedTransport, NonDeterminismError, type PayloadCodec, type QueueConfig, QueueController, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RunAttributeRow, type RunDetail, type RunDispatcher, type RunGateway, type RunListItem, type RunQuery, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunStatus, type RunWaiting, STATE_STORE, STATE_STORE_CANONICAL, type ScheduledWorkflow, type SearchAttributes, type SearchAttributesSchema, SignalTimeoutError, type SignalWaiter, type SingletonConfig, SingletonQueueFullError, StandardSchemaV1, type StartOptions, type StartRunMessage, type StateStore, type StepCheckpoint, type StepConfig, type StepDef, type StepDispatchOpts, type StepError, type StepEvent, type StepHandler, type StepInterceptor, type StepInvocation, type StepKind, type StepLogger, type StepOptions, type StepRef, type StepResult, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerHeartbeat, type WorkerStatus, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, applyAttributeQuery, attributeColumnFor, attributeOperand, bindWorkflowClass, breakpointToken, classifyWaiterToken, collectMetrics, createStepLogger, currentWorkflowCtx, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, indexWaitersByRun, matchesAttributes, normalizeAttributeRows, parseDuration, prevCronFireMs, readSearchAttributes, resolveRunWaiting, runInWorkflowCtx, runSchedules, runStepHandler, sanitizeQueueToken, scheduledRunId, sqlComparator, stepConfigOf, stepId, stepNameOf, tenantGroup, workflowName };
|