@dudousxd/nestjs-durable-core 0.72.0 → 0.72.1
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 +135 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.js +131 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -2505,6 +2505,32 @@ declare function runInWorkflowCtx<T>(ctx: WorkflowCtx, fn: () => T): T;
|
|
|
2505
2505
|
* ambient workflow context (by design — a handler is not the workflow body).
|
|
2506
2506
|
*/
|
|
2507
2507
|
declare function currentWorkflowCtx(): WorkflowCtx | undefined;
|
|
2508
|
+
/**
|
|
2509
|
+
* The ambient STEP scope: which workflow ctx's checkpointed step body (if any) is executing on this
|
|
2510
|
+
* async path. The engine installs it around every in-body step execution (`ctx.localStep`,
|
|
2511
|
+
* `ctx.transaction`, and everything built on them) so the ctx primitives can refuse to run from
|
|
2512
|
+
* inside a step body — see {@link NestedWorkflowCallError}. `owner` is the identity of the ctx whose
|
|
2513
|
+
* step is running, so a DIFFERENT run's body executed inline from a step (e.g. a step that signals a
|
|
2514
|
+
* run which resumes on this async path) is never mistaken for a nested call.
|
|
2515
|
+
*
|
|
2516
|
+
* Shared per process under a `Symbol.for` key, for the same duplicate-copy reason as the ctx storage.
|
|
2517
|
+
*/
|
|
2518
|
+
interface StepScope {
|
|
2519
|
+
readonly owner: object;
|
|
2520
|
+
readonly step: string;
|
|
2521
|
+
}
|
|
2522
|
+
/** Run `fn` as the body of step `step` of the ctx identified by `owner`. Engine-internal. */
|
|
2523
|
+
declare function runInStepScope<T>(owner: object, step: string, fn: () => T): T;
|
|
2524
|
+
/** The step body currently executing on this async path, or `undefined` outside one. */
|
|
2525
|
+
declare function currentStepScope(): StepScope | undefined;
|
|
2526
|
+
/**
|
|
2527
|
+
* Run `fn` with NO ambient workflow ctx and no step scope — for a dispatched `@Step` handler. A
|
|
2528
|
+
* handler is not the workflow body (on a remote worker it never sees one), but an in-process
|
|
2529
|
+
* transport invokes it on the body's async path, where the parent's ctx would otherwise leak in and
|
|
2530
|
+
* turn a handler's `MyWorkflow.start()` into a journal-corrupting `ctx.startChild` of a parent that
|
|
2531
|
+
* is already suspended. Clearing it makes in-process and remote handlers behave identically.
|
|
2532
|
+
*/
|
|
2533
|
+
declare function runOutsideWorkflowCtx<T>(fn: () => T): T;
|
|
2508
2534
|
|
|
2509
2535
|
/**
|
|
2510
2536
|
* Run `fn` with `logger` as the ambient step logger. Engine-internal: wraps every execution of a
|
|
@@ -3870,7 +3896,23 @@ declare class WorkflowEngine {
|
|
|
3870
3896
|
start<TInput>(workflow: string, input: TInput, runId: string, opts?: StartOptions): Promise<RunResult>;
|
|
3871
3897
|
/** Read a run's current persisted state (or null if unknown). A thin pass-through to the store. */
|
|
3872
3898
|
getRun(runId: string): Promise<WorkflowRun | null>;
|
|
3899
|
+
/**
|
|
3900
|
+
* Re-execute a run's body (replaying its checkpoints). This is the EXPLICIT entry point: besides
|
|
3901
|
+
* driving a live run, it re-drives a `failed` run — the manual retry (prefer {@link requeue}, which
|
|
3902
|
+
* also resets the failure state so replay re-attempts the failed parts). Completed / cancelled /
|
|
3903
|
+
* dead runs are never re-executed. The engine's own implicit wake-ups (signals, step results,
|
|
3904
|
+
* timers, redelivered dispatches) go through {@link resumeImplicit}, which treats `failed` as
|
|
3905
|
+
* terminal too.
|
|
3906
|
+
*/
|
|
3873
3907
|
resume(runId: string): Promise<RunResult>;
|
|
3908
|
+
/**
|
|
3909
|
+
* {@link resume} for every IMPLICIT wake-up — a delivered signal/child completion, a late step
|
|
3910
|
+
* result, a due timer, a redelivered dispatch, a queue-slot wake. A `failed` run is terminal to
|
|
3911
|
+
* these: only an explicit retry ({@link requeue} / {@link resume}) may re-drive it. Otherwise a
|
|
3912
|
+
* stale waiter or a late result left behind by a failed run silently re-executes its body.
|
|
3913
|
+
*/
|
|
3914
|
+
private resumeImplicit;
|
|
3915
|
+
private resumeRun;
|
|
3874
3916
|
/**
|
|
3875
3917
|
* The registration for an UNREGISTERED run, INHERITED from its nearest REMOTE ancestor — or
|
|
3876
3918
|
* `undefined` if it has none (the skew-protection error case in {@link resume}). Callers check the
|
|
@@ -4883,6 +4925,26 @@ declare class NonDeterminismError extends Error {
|
|
|
4883
4925
|
readonly seq: number;
|
|
4884
4926
|
constructor(runId: string, seq: number, expected: string, recorded: string);
|
|
4885
4927
|
}
|
|
4928
|
+
/**
|
|
4929
|
+
* Thrown AT THE CALL SITE when a workflow-ctx primitive (`ctx.startChild`, `ctx.child`, `ctx.step`,
|
|
4930
|
+
* `ctx.sleep`, `ctx.sideEffect`, … — or a `MyWorkflow.start()`/`.execute()` static, which route to
|
|
4931
|
+
* them through the ambient ctx) is called from INSIDE the body of a checkpointed step
|
|
4932
|
+
* (`ctx.localStep`, `ctx.transaction`, `ctx.sideEffect`, `ctx.now`, `ctx.task`'s dispatch).
|
|
4933
|
+
*
|
|
4934
|
+
* A step body runs once and is replayed from its checkpoint WITHOUT re-running, so a primitive it
|
|
4935
|
+
* called claims a journal position on the first run that no replay ever claims again: every later
|
|
4936
|
+
* position shifts and the run dies on its next replay with a `NonDeterminismError` far from the
|
|
4937
|
+
* cause. Failing here instead names the real mistake. Move the call out of the step body (into the
|
|
4938
|
+
* workflow body), or — from a dispatched `@Step` handler — start a top-level run.
|
|
4939
|
+
*
|
|
4940
|
+
* A `FatalError` (code `nested_workflow_call`): the step is not retried, the run fails.
|
|
4941
|
+
*/
|
|
4942
|
+
declare class NestedWorkflowCallError extends FatalError {
|
|
4943
|
+
readonly runId: string;
|
|
4944
|
+
readonly primitive: string;
|
|
4945
|
+
readonly step: string;
|
|
4946
|
+
constructor(runId: string, primitive: string, step: string);
|
|
4947
|
+
}
|
|
4886
4948
|
/**
|
|
4887
4949
|
* Thrown by `ctx.all` when one or more parallel child workflows fail. Carries the per-item failures
|
|
4888
4950
|
* (input index, child run id, error message) and presents an aggregate message summarizing the count
|
|
@@ -5829,4 +5891,4 @@ declare class InMemoryTransport implements Transport, ControlPlane {
|
|
|
5829
5891
|
onControl(handler: (msg: ControlMessage) => void): void;
|
|
5830
5892
|
}
|
|
5831
5893
|
|
|
5832
|
-
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, CONTROL_FLOW_SIGNAL, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type ChildCallOptions, CodecStateStore, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NonDeterminismError, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunDetail, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, STATE_STORE, STATE_STORE_CANONICAL, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, 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, VERSION_UNDECLARED_TAG, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, announcementsOf, applyAttributeQuery, assertConcurrency, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, classifyWaiterToken, clearDurableExecutionWrappers, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentWorkflowCtx, debug, describeWorker, descriptorHash, error, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, hasDurableExecutionWrappers, heartbeatStatus, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isLegacyDescriptor, isNonEmptyRunScope, isWorkflowControlFlowSignal, log, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, parseDuration, partitionOfToken, planDispatch, prevCronFireMs, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, runDurableExecution, runInStepLogger, runInWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduledRunId, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, tenantGroup, useDurableExecution, warn, workflowName };
|
|
5894
|
+
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, CONTROL_FLOW_SIGNAL, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type ChildCallOptions, CodecStateStore, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunDetail, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, STATE_STORE, STATE_STORE_CANONICAL, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, 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 StepScope, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, announcementsOf, applyAttributeQuery, assertConcurrency, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, classifyWaiterToken, clearDurableExecutionWrappers, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, error, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, hasDurableExecutionWrappers, heartbeatStatus, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isLegacyDescriptor, isNonEmptyRunScope, isWorkflowControlFlowSignal, log, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, parseDuration, partitionOfToken, planDispatch, prevCronFireMs, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduledRunId, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, tenantGroup, useDurableExecution, warn, workflowName };
|
package/dist/index.d.ts
CHANGED
|
@@ -2505,6 +2505,32 @@ declare function runInWorkflowCtx<T>(ctx: WorkflowCtx, fn: () => T): T;
|
|
|
2505
2505
|
* ambient workflow context (by design — a handler is not the workflow body).
|
|
2506
2506
|
*/
|
|
2507
2507
|
declare function currentWorkflowCtx(): WorkflowCtx | undefined;
|
|
2508
|
+
/**
|
|
2509
|
+
* The ambient STEP scope: which workflow ctx's checkpointed step body (if any) is executing on this
|
|
2510
|
+
* async path. The engine installs it around every in-body step execution (`ctx.localStep`,
|
|
2511
|
+
* `ctx.transaction`, and everything built on them) so the ctx primitives can refuse to run from
|
|
2512
|
+
* inside a step body — see {@link NestedWorkflowCallError}. `owner` is the identity of the ctx whose
|
|
2513
|
+
* step is running, so a DIFFERENT run's body executed inline from a step (e.g. a step that signals a
|
|
2514
|
+
* run which resumes on this async path) is never mistaken for a nested call.
|
|
2515
|
+
*
|
|
2516
|
+
* Shared per process under a `Symbol.for` key, for the same duplicate-copy reason as the ctx storage.
|
|
2517
|
+
*/
|
|
2518
|
+
interface StepScope {
|
|
2519
|
+
readonly owner: object;
|
|
2520
|
+
readonly step: string;
|
|
2521
|
+
}
|
|
2522
|
+
/** Run `fn` as the body of step `step` of the ctx identified by `owner`. Engine-internal. */
|
|
2523
|
+
declare function runInStepScope<T>(owner: object, step: string, fn: () => T): T;
|
|
2524
|
+
/** The step body currently executing on this async path, or `undefined` outside one. */
|
|
2525
|
+
declare function currentStepScope(): StepScope | undefined;
|
|
2526
|
+
/**
|
|
2527
|
+
* Run `fn` with NO ambient workflow ctx and no step scope — for a dispatched `@Step` handler. A
|
|
2528
|
+
* handler is not the workflow body (on a remote worker it never sees one), but an in-process
|
|
2529
|
+
* transport invokes it on the body's async path, where the parent's ctx would otherwise leak in and
|
|
2530
|
+
* turn a handler's `MyWorkflow.start()` into a journal-corrupting `ctx.startChild` of a parent that
|
|
2531
|
+
* is already suspended. Clearing it makes in-process and remote handlers behave identically.
|
|
2532
|
+
*/
|
|
2533
|
+
declare function runOutsideWorkflowCtx<T>(fn: () => T): T;
|
|
2508
2534
|
|
|
2509
2535
|
/**
|
|
2510
2536
|
* Run `fn` with `logger` as the ambient step logger. Engine-internal: wraps every execution of a
|
|
@@ -3870,7 +3896,23 @@ declare class WorkflowEngine {
|
|
|
3870
3896
|
start<TInput>(workflow: string, input: TInput, runId: string, opts?: StartOptions): Promise<RunResult>;
|
|
3871
3897
|
/** Read a run's current persisted state (or null if unknown). A thin pass-through to the store. */
|
|
3872
3898
|
getRun(runId: string): Promise<WorkflowRun | null>;
|
|
3899
|
+
/**
|
|
3900
|
+
* Re-execute a run's body (replaying its checkpoints). This is the EXPLICIT entry point: besides
|
|
3901
|
+
* driving a live run, it re-drives a `failed` run — the manual retry (prefer {@link requeue}, which
|
|
3902
|
+
* also resets the failure state so replay re-attempts the failed parts). Completed / cancelled /
|
|
3903
|
+
* dead runs are never re-executed. The engine's own implicit wake-ups (signals, step results,
|
|
3904
|
+
* timers, redelivered dispatches) go through {@link resumeImplicit}, which treats `failed` as
|
|
3905
|
+
* terminal too.
|
|
3906
|
+
*/
|
|
3873
3907
|
resume(runId: string): Promise<RunResult>;
|
|
3908
|
+
/**
|
|
3909
|
+
* {@link resume} for every IMPLICIT wake-up — a delivered signal/child completion, a late step
|
|
3910
|
+
* result, a due timer, a redelivered dispatch, a queue-slot wake. A `failed` run is terminal to
|
|
3911
|
+
* these: only an explicit retry ({@link requeue} / {@link resume}) may re-drive it. Otherwise a
|
|
3912
|
+
* stale waiter or a late result left behind by a failed run silently re-executes its body.
|
|
3913
|
+
*/
|
|
3914
|
+
private resumeImplicit;
|
|
3915
|
+
private resumeRun;
|
|
3874
3916
|
/**
|
|
3875
3917
|
* The registration for an UNREGISTERED run, INHERITED from its nearest REMOTE ancestor — or
|
|
3876
3918
|
* `undefined` if it has none (the skew-protection error case in {@link resume}). Callers check the
|
|
@@ -4883,6 +4925,26 @@ declare class NonDeterminismError extends Error {
|
|
|
4883
4925
|
readonly seq: number;
|
|
4884
4926
|
constructor(runId: string, seq: number, expected: string, recorded: string);
|
|
4885
4927
|
}
|
|
4928
|
+
/**
|
|
4929
|
+
* Thrown AT THE CALL SITE when a workflow-ctx primitive (`ctx.startChild`, `ctx.child`, `ctx.step`,
|
|
4930
|
+
* `ctx.sleep`, `ctx.sideEffect`, … — or a `MyWorkflow.start()`/`.execute()` static, which route to
|
|
4931
|
+
* them through the ambient ctx) is called from INSIDE the body of a checkpointed step
|
|
4932
|
+
* (`ctx.localStep`, `ctx.transaction`, `ctx.sideEffect`, `ctx.now`, `ctx.task`'s dispatch).
|
|
4933
|
+
*
|
|
4934
|
+
* A step body runs once and is replayed from its checkpoint WITHOUT re-running, so a primitive it
|
|
4935
|
+
* called claims a journal position on the first run that no replay ever claims again: every later
|
|
4936
|
+
* position shifts and the run dies on its next replay with a `NonDeterminismError` far from the
|
|
4937
|
+
* cause. Failing here instead names the real mistake. Move the call out of the step body (into the
|
|
4938
|
+
* workflow body), or — from a dispatched `@Step` handler — start a top-level run.
|
|
4939
|
+
*
|
|
4940
|
+
* A `FatalError` (code `nested_workflow_call`): the step is not retried, the run fails.
|
|
4941
|
+
*/
|
|
4942
|
+
declare class NestedWorkflowCallError extends FatalError {
|
|
4943
|
+
readonly runId: string;
|
|
4944
|
+
readonly primitive: string;
|
|
4945
|
+
readonly step: string;
|
|
4946
|
+
constructor(runId: string, primitive: string, step: string);
|
|
4947
|
+
}
|
|
4886
4948
|
/**
|
|
4887
4949
|
* Thrown by `ctx.all` when one or more parallel child workflows fail. Carries the per-item failures
|
|
4888
4950
|
* (input index, child run id, error message) and presents an aggregate message summarizing the count
|
|
@@ -5829,4 +5891,4 @@ declare class InMemoryTransport implements Transport, ControlPlane {
|
|
|
5829
5891
|
onControl(handler: (msg: ControlMessage) => void): void;
|
|
5830
5892
|
}
|
|
5831
5893
|
|
|
5832
|
-
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, CONTROL_FLOW_SIGNAL, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type ChildCallOptions, CodecStateStore, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NonDeterminismError, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunDetail, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, STATE_STORE, STATE_STORE_CANONICAL, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, 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, VERSION_UNDECLARED_TAG, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, announcementsOf, applyAttributeQuery, assertConcurrency, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, classifyWaiterToken, clearDurableExecutionWrappers, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentWorkflowCtx, debug, describeWorker, descriptorHash, error, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, hasDurableExecutionWrappers, heartbeatStatus, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isLegacyDescriptor, isNonEmptyRunScope, isWorkflowControlFlowSignal, log, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, parseDuration, partitionOfToken, planDispatch, prevCronFireMs, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, runDurableExecution, runInStepLogger, runInWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduledRunId, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, tenantGroup, useDurableExecution, warn, workflowName };
|
|
5894
|
+
export { type AccumulatorHost, type Admission, type AdmissionBackend, type AdmissionItem, type AnnouncedWorkflow, type AnnouncementEvidence, type AttributeFilter, type AttributeOp, type AttributePredicateOperand, type AttributeValue, type BackoffStrategy, type BlockedDispatch, type BlockedResolution, CONTROL_FLOW_SIGNAL, CURRENT_PROTOCOL_VERSION, type CapabilityRequirement, type ChildCallOptions, CodecStateStore, type ConcurrencyConfig, ConcurrencyLimitError, type ConcurrencyQuota, ContinueAsNew, type ControlMessage, type ControlPlane, DEFAULT_CONCURRENCY_STATUSES, DEFAULT_PARTITION, DURABLE_OPTIONS, DURABLE_OPTIONS_CANONICAL, DURABLE_STEP_CONFIG, DURABLE_STEP_NAME, type Disagreement, type DispatchDiagnostics, type DispatchPlan, type DurableExecution, type DurableExecutionWrapper, type DurableTopology, type DurableWebhook, DurableWorkflow, type DynamicWorkflowCtx, ENGINE_MINTED_TAG_PREFIXES, EVENT_BUFFER_SCAN_LIMIT, EVENT_TOKEN_PREFIX, type EngineEvent, type EngineEventType, type EngineListener, Entities, type EntityConfig, type EntityHandler, type EntityHost, EventAccumulators, type EventBatchConfig, FatalError, GatherError, type GroupHealth, type Heartbeat, type HeartbeatSighting, type HeartbeatStatus, type HistoryEvent, InMemoryAdmissionBackend, InMemoryStateStore, InMemoryTransport, type InferSearchAttributes, LEGACY_V1_CAPABILITIES, LEGACY_V1_PROTOCOL, type MetricsCollector, type MetricsSnapshot, type NamedTransport, type NegotiateOptions, type NegotiationOutcome, type NegotiationReason, type NegotiationResult, NestedWorkflowCallError, NonDeterminismError, type PartitionSighting, type PayloadCodec, type QueueConfig, QueueController, RUN_VALUE_FACET_LIMIT, RUN_VALUE_FACET_SCAN, type RawWorkerDescriptor, RemoteStepError, RemoteStepTimeout, type RemoteTask, RemoteWorkflowExecutor, RemoteWorkflowTimeout, type RetentionPolicy, type RoutableDispatch, type RoutableResolution, type RoutingResolution, type RunAttributeRow, type RunDetail, type RunDispatcher, type RunFacetQuery, type RunFacetRow, RunGateway, type RunListItem, type RunQuery, type RunReply, type RunReplyResult, type RunRequest, type RunRequestKind, type RunResult, type RunSchedulesOptions, type RunScope, type RunStatus, type RunValueAxis, type RunValueFacetOptions, type RunValueFacetOrder, type RunValueFacetRow, type RunWaiting, STATE_STORE, STATE_STORE_CANONICAL, type ScalarAttributeFilter, ScheduleAlreadyExistsError, ScheduleClient, type ScheduleClientOptions, type ScheduleDescription, type ScheduleHost, type ScheduleListQuery, ScheduleNotFoundError, type ScheduleOptions, type ScheduleQuery, type ScheduleRecord, 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 StepScope, type StepUndo, type StoreTransaction, type SubProcessHandle, TERMINAL_RUN_STATUSES, TRANSPORT, TRANSPORT_CANONICAL, type TenantEvent, type Transport, type UndoOf, type UpdateResult, type UpdateValidator, VERSION_UNDECLARED_TAG, WORKFLOW_NAME_KEY, type WireDates, type WorkerAdjust, type WorkerConcurrencyStatus, type WorkerDescriptor, type WorkerHeartbeat, type WorkerLifecycle, type WorkerStatus, type WorkflowAnnouncement, WorkflowBlocked, type WorkflowClass, type WorkflowCommand, type WorkflowCtx, type WorkflowDecision, type WorkflowDirectory, WorkflowEngine, type WorkflowEngineDeps, type WorkflowExecutor, type WorkflowHandler, type WorkflowInputOf, type WorkflowOutputOf, type WorkflowRef, type WorkflowRegistration, type WorkflowRun, type WorkflowStartClient, type WorkflowStepEvent, WorkflowSuspended, type WorkflowTask, aggregateAnnouncements, announcementsOf, applyAttributeQuery, assertConcurrency, attributeColumnFor, attributeOperand, attributePredicateOperands, axisIsRunColumn, bindWorkflowClass, breakpointToken, buildWorkflowDirectory, canRoute, capableWorkers, classifyWaiterToken, clearDurableExecutionWrappers, collectMetrics, concurrencyTag, controlPlaneDescriptor, countRuns, coveredTokens, createStepLogger, currentStep, currentStepScope, currentWorkflowCtx, debug, describeWorker, descriptorHash, error, eventMatchOf, eventMatches, eventNameOf, eventPrefix, eventToken, facetOrigin, hasDurableExecutionWrappers, heartbeatStatus, indexWaitersByRun, info, isEngineMintedTag, isEventToken, isLegacyDescriptor, isNonEmptyRunScope, isWorkflowControlFlowSignal, log, matchesAttributes, mergeRunFacetRows, mergeRunValueFacetRows, missingCapabilities, negotiate, nextCronFireMs, normalizeAttributeRows, normalizeDescriptor, observedAnnouncements, parseDuration, partitionOfToken, planDispatch, prevCronFireMs, readSearchAttributes, requiredCapabilities, resolveConcurrency, resolveRouting, resolveRunWaiting, runDurableExecution, runInStepLogger, runInStepScope, runInWorkflowCtx, runOutsideWorkflowCtx, runSchedules, runStepHandler, runValueFacetsFromRuns, sanitizeQueueToken, scheduledRunId, sqlComparator, stepConfigOf, stepId, stepNameOf, sub, subEvent, subProcess, tenantGroup, useDurableExecution, warn, workflowName };
|
package/dist/index.js
CHANGED
|
@@ -172,6 +172,27 @@ function currentWorkflowCtx() {
|
|
|
172
172
|
return storage.getStore();
|
|
173
173
|
}
|
|
174
174
|
__name(currentWorkflowCtx, "currentWorkflowCtx");
|
|
175
|
+
var STEP_SCOPE_KEY = Symbol.for("nestjs-durable:ambient-step-scope");
|
|
176
|
+
var stepScopeRef = globalThis;
|
|
177
|
+
if (!stepScopeRef[STEP_SCOPE_KEY]) {
|
|
178
|
+
stepScopeRef[STEP_SCOPE_KEY] = new AsyncLocalStorage();
|
|
179
|
+
}
|
|
180
|
+
var stepScopeStorage = stepScopeRef[STEP_SCOPE_KEY];
|
|
181
|
+
function runInStepScope(owner, step, fn) {
|
|
182
|
+
return stepScopeStorage.run({
|
|
183
|
+
owner,
|
|
184
|
+
step
|
|
185
|
+
}, fn);
|
|
186
|
+
}
|
|
187
|
+
__name(runInStepScope, "runInStepScope");
|
|
188
|
+
function currentStepScope() {
|
|
189
|
+
return stepScopeStorage.getStore();
|
|
190
|
+
}
|
|
191
|
+
__name(currentStepScope, "currentStepScope");
|
|
192
|
+
function runOutsideWorkflowCtx(fn) {
|
|
193
|
+
return storage.exit(() => stepScopeStorage.exit(fn));
|
|
194
|
+
}
|
|
195
|
+
__name(runOutsideWorkflowCtx, "runOutsideWorkflowCtx");
|
|
175
196
|
|
|
176
197
|
// src/ambient-step.ts
|
|
177
198
|
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
@@ -334,6 +355,21 @@ var NonDeterminismError = class extends Error {
|
|
|
334
355
|
this.seq = seq;
|
|
335
356
|
}
|
|
336
357
|
};
|
|
358
|
+
var NestedWorkflowCallError = class extends FatalError {
|
|
359
|
+
static {
|
|
360
|
+
__name(this, "NestedWorkflowCallError");
|
|
361
|
+
}
|
|
362
|
+
runId;
|
|
363
|
+
primitive;
|
|
364
|
+
step;
|
|
365
|
+
constructor(runId, primitive, step) {
|
|
366
|
+
super(`ctx.${primitive}() was called inside the body of step "${step}" (run ${runId}). Workflow primitives (child/startChild/step/sleep/signals/sideEffect/\u2026, and MyWorkflow.start()/.execute() via the ambient ctx) must be called from the workflow body, never from inside a step body: the step's checkpoint replays without re-running it, so the nested call would shift every later journal position and corrupt the run on replay. Move the call out of the step.`, "nested_workflow_call");
|
|
367
|
+
this.name = "NestedWorkflowCallError";
|
|
368
|
+
this.runId = runId;
|
|
369
|
+
this.primitive = primitive;
|
|
370
|
+
this.step = step;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
337
373
|
var GatherError = class extends Error {
|
|
338
374
|
static {
|
|
339
375
|
__name(this, "GatherError");
|
|
@@ -690,14 +726,19 @@ async function runStepHandler(task, handler) {
|
|
|
690
726
|
} : result, "withEvents");
|
|
691
727
|
try {
|
|
692
728
|
const logger = createStepLogger(events, Date.now);
|
|
693
|
-
const output = await runDurableExecution(
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
729
|
+
const output = await runDurableExecution(
|
|
730
|
+
{
|
|
731
|
+
unit: "step",
|
|
732
|
+
runId: task.runId,
|
|
733
|
+
workflow: void 0,
|
|
734
|
+
name: task.name,
|
|
735
|
+
seq: task.seq,
|
|
736
|
+
attempt: task.attempt
|
|
737
|
+
},
|
|
738
|
+
// Outside any ambient workflow ctx: an in-process transport runs the handler on the parent
|
|
739
|
+
// body's async path, but a handler is not the body (see `runOutsideWorkflowCtx`).
|
|
740
|
+
async () => runOutsideWorkflowCtx(() => runInStepLogger(logger, () => handler(task.input, logger)))
|
|
741
|
+
);
|
|
701
742
|
return withEvents({
|
|
702
743
|
...base,
|
|
703
744
|
status: "completed",
|
|
@@ -2601,10 +2642,15 @@ var Position = class Position2 {
|
|
|
2601
2642
|
rewind() {
|
|
2602
2643
|
this.seq -= 1;
|
|
2603
2644
|
}
|
|
2645
|
+
/** The position the NEXT primitive would claim, without claiming it. */
|
|
2646
|
+
peek() {
|
|
2647
|
+
return this.seq + 1;
|
|
2648
|
+
}
|
|
2604
2649
|
};
|
|
2605
2650
|
function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttributesSchema) {
|
|
2606
2651
|
const { store, replay } = host;
|
|
2607
2652
|
const pos = new Position();
|
|
2653
|
+
const scopeOwner = {};
|
|
2608
2654
|
const readCheckpoint = /* @__PURE__ */ __name((seq) => {
|
|
2609
2655
|
const hit = replay?.get(seq);
|
|
2610
2656
|
if (hit !== void 0) return hit;
|
|
@@ -2650,7 +2696,7 @@ function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttr
|
|
|
2650
2696
|
};
|
|
2651
2697
|
const body = /* @__PURE__ */ __name(() => {
|
|
2652
2698
|
const logger = createStepLogger(events, host.clock);
|
|
2653
|
-
return runInStepLogger(logger, () => fn(logger));
|
|
2699
|
+
return runInStepScope(scopeOwner, name, () => runInStepLogger(logger, () => fn(logger)));
|
|
2654
2700
|
}, "body");
|
|
2655
2701
|
const output = host.interceptStep ? await host.interceptStep(invocation, body) : await body();
|
|
2656
2702
|
await host.completeStep({
|
|
@@ -2703,7 +2749,7 @@ function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttr
|
|
|
2703
2749
|
}
|
|
2704
2750
|
if (existing && existing.status === "completed") return existing.output;
|
|
2705
2751
|
return store.transaction(async (tx) => {
|
|
2706
|
-
const output = await fn(tx.raw);
|
|
2752
|
+
const output = await runInStepScope(scopeOwner, name, () => fn(tx.raw));
|
|
2707
2753
|
const cp = instantCheckpoint({
|
|
2708
2754
|
runId,
|
|
2709
2755
|
seq: current,
|
|
@@ -3212,30 +3258,49 @@ function createWorkflowCtx(host, runId, compensations, workflow = "", searchAttr
|
|
|
3212
3258
|
});
|
|
3213
3259
|
}
|
|
3214
3260
|
__name(step, "step");
|
|
3261
|
+
const nestedStep = /* @__PURE__ */ __name(() => {
|
|
3262
|
+
const scope = currentStepScope();
|
|
3263
|
+
return scope !== void 0 && scope.owner === scopeOwner ? scope.step : void 0;
|
|
3264
|
+
}, "nestedStep");
|
|
3265
|
+
const guard = /* @__PURE__ */ __name((primitive, fn) => (...args) => {
|
|
3266
|
+
const stepName = nestedStep();
|
|
3267
|
+
if (stepName === void 0) return fn(...args);
|
|
3268
|
+
return (async () => {
|
|
3269
|
+
if (await readCheckpoint(pos.peek())) return fn(...args);
|
|
3270
|
+
throw new NestedWorkflowCallError(runId, primitive, stepName);
|
|
3271
|
+
})();
|
|
3272
|
+
}, "guard");
|
|
3273
|
+
const guardedWebhook = /* @__PURE__ */ __name(() => {
|
|
3274
|
+
const stepName = nestedStep();
|
|
3275
|
+
if (stepName !== void 0 && !replay?.get(pos.peek())) {
|
|
3276
|
+
throw new NestedWorkflowCallError(runId, "webhook", stepName);
|
|
3277
|
+
}
|
|
3278
|
+
return webhook();
|
|
3279
|
+
}, "guardedWebhook");
|
|
3215
3280
|
return {
|
|
3216
3281
|
runId,
|
|
3217
|
-
step,
|
|
3218
|
-
localStep,
|
|
3219
|
-
upsertSearchAttributes,
|
|
3220
|
-
transaction,
|
|
3221
|
-
callEntity,
|
|
3222
|
-
signalEntity,
|
|
3223
|
-
sleep,
|
|
3224
|
-
sleepUntil,
|
|
3282
|
+
step: guard("step", step),
|
|
3283
|
+
localStep: guard("localStep", localStep),
|
|
3284
|
+
upsertSearchAttributes: guard("upsertSearchAttributes", upsertSearchAttributes),
|
|
3285
|
+
transaction: guard("transaction", transaction),
|
|
3286
|
+
callEntity: guard("callEntity", callEntity),
|
|
3287
|
+
signalEntity: guard("signalEntity", signalEntity),
|
|
3288
|
+
sleep: guard("sleep", sleep),
|
|
3289
|
+
sleepUntil: guard("sleepUntil", sleepUntil),
|
|
3225
3290
|
continueAsNew,
|
|
3226
|
-
waitForSignal,
|
|
3227
|
-
waitForEvent,
|
|
3228
|
-
task,
|
|
3229
|
-
child,
|
|
3230
|
-
all,
|
|
3231
|
-
startChild,
|
|
3232
|
-
breakpoint,
|
|
3233
|
-
webhook,
|
|
3234
|
-
setEvent,
|
|
3235
|
-
onUpdate,
|
|
3236
|
-
patched,
|
|
3237
|
-
now,
|
|
3238
|
-
sideEffect
|
|
3291
|
+
waitForSignal: guard("waitForSignal", waitForSignal),
|
|
3292
|
+
waitForEvent: guard("waitForEvent", waitForEvent),
|
|
3293
|
+
task: guard("task", task),
|
|
3294
|
+
child: guard("child", child),
|
|
3295
|
+
all: guard("all", all),
|
|
3296
|
+
startChild: guard("startChild", startChild),
|
|
3297
|
+
breakpoint: guard("breakpoint", breakpoint),
|
|
3298
|
+
webhook: guardedWebhook,
|
|
3299
|
+
setEvent: guard("setEvent", setEvent),
|
|
3300
|
+
onUpdate: guard("onUpdate", onUpdate),
|
|
3301
|
+
patched: guard("patched", patched),
|
|
3302
|
+
now: guard("now", now),
|
|
3303
|
+
sideEffect: guard("sideEffect", sideEffect)
|
|
3239
3304
|
};
|
|
3240
3305
|
}
|
|
3241
3306
|
__name(createWorkflowCtx, "createWorkflowCtx");
|
|
@@ -3837,10 +3902,30 @@ var WorkflowEngine = class {
|
|
|
3837
3902
|
getRun(runId) {
|
|
3838
3903
|
return this.store.getRun(runId);
|
|
3839
3904
|
}
|
|
3840
|
-
|
|
3905
|
+
/**
|
|
3906
|
+
* Re-execute a run's body (replaying its checkpoints). This is the EXPLICIT entry point: besides
|
|
3907
|
+
* driving a live run, it re-drives a `failed` run — the manual retry (prefer {@link requeue}, which
|
|
3908
|
+
* also resets the failure state so replay re-attempts the failed parts). Completed / cancelled /
|
|
3909
|
+
* dead runs are never re-executed. The engine's own implicit wake-ups (signals, step results,
|
|
3910
|
+
* timers, redelivered dispatches) go through {@link resumeImplicit}, which treats `failed` as
|
|
3911
|
+
* terminal too.
|
|
3912
|
+
*/
|
|
3913
|
+
resume(runId) {
|
|
3914
|
+
return this.resumeRun(runId, true);
|
|
3915
|
+
}
|
|
3916
|
+
/**
|
|
3917
|
+
* {@link resume} for every IMPLICIT wake-up — a delivered signal/child completion, a late step
|
|
3918
|
+
* result, a due timer, a redelivered dispatch, a queue-slot wake. A `failed` run is terminal to
|
|
3919
|
+
* these: only an explicit retry ({@link requeue} / {@link resume}) may re-drive it. Otherwise a
|
|
3920
|
+
* stale waiter or a late result left behind by a failed run silently re-executes its body.
|
|
3921
|
+
*/
|
|
3922
|
+
resumeImplicit(runId) {
|
|
3923
|
+
return this.resumeRun(runId, false);
|
|
3924
|
+
}
|
|
3925
|
+
async resumeRun(runId, allowFailed) {
|
|
3841
3926
|
const run = await this.store.getRun(runId);
|
|
3842
3927
|
if (!run) throw new Error(`run ${runId} not found`);
|
|
3843
|
-
if (run.status === "cancelled" || run.status === "completed" || run.status === "dead") {
|
|
3928
|
+
if (run.status === "cancelled" || run.status === "completed" || run.status === "dead" || run.status === "failed" && !allowFailed) {
|
|
3844
3929
|
return {
|
|
3845
3930
|
runId,
|
|
3846
3931
|
status: run.status,
|
|
@@ -4289,7 +4374,7 @@ var WorkflowEngine = class {
|
|
|
4289
4374
|
const nowMs = this.clock();
|
|
4290
4375
|
const acquired = await this.store.tryLockRun(runId, this.instanceId, nowMs + this.leaseMs, nowMs);
|
|
4291
4376
|
if (!acquired) return null;
|
|
4292
|
-
return this.
|
|
4377
|
+
return this.resumeImplicit(runId).catch((err) => {
|
|
4293
4378
|
if (err instanceof NamespaceMismatch) return null;
|
|
4294
4379
|
throw err;
|
|
4295
4380
|
});
|
|
@@ -4510,7 +4595,7 @@ var WorkflowEngine = class {
|
|
|
4510
4595
|
if (!acquired) continue;
|
|
4511
4596
|
try {
|
|
4512
4597
|
const settled = onLocked ? await onLocked(run) : void 0;
|
|
4513
|
-
results.push(settled ?? await this.
|
|
4598
|
+
results.push(settled ?? await this.resumeImplicit(run.id));
|
|
4514
4599
|
} catch (error2) {
|
|
4515
4600
|
console.error(`[nestjs-durable] could not resume run ${run.id} (${run.workflow}@${run.workflowVersion}); leaving it for another instance:`, error2);
|
|
4516
4601
|
}
|
|
@@ -4607,7 +4692,7 @@ var WorkflowEngine = class {
|
|
|
4607
4692
|
// for an ordinary (non-fan) signal/child await.
|
|
4608
4693
|
parallelGroup: waiter.parallelGroup
|
|
4609
4694
|
}));
|
|
4610
|
-
return this.
|
|
4695
|
+
return this.resumeImplicit(waiter.runId).catch((err) => {
|
|
4611
4696
|
if (err instanceof NamespaceMismatch) return null;
|
|
4612
4697
|
throw err;
|
|
4613
4698
|
});
|
|
@@ -4723,7 +4808,7 @@ var WorkflowEngine = class {
|
|
|
4723
4808
|
async cancel(runId, opts) {
|
|
4724
4809
|
const run = await this.store.getRun(runId);
|
|
4725
4810
|
if (!run) return null;
|
|
4726
|
-
if (
|
|
4811
|
+
if (TERMINAL_RUN_STATUSES.includes(run.status)) {
|
|
4727
4812
|
return {
|
|
4728
4813
|
runId,
|
|
4729
4814
|
status: run.status,
|
|
@@ -4752,7 +4837,7 @@ var WorkflowEngine = class {
|
|
|
4752
4837
|
}).catch(() => void 0);
|
|
4753
4838
|
}
|
|
4754
4839
|
queueMicrotask(() => {
|
|
4755
|
-
void this.
|
|
4840
|
+
void this.resumeImplicit(runId).then(() => this.notifyCancelled(runId)).catch(() => void 0);
|
|
4756
4841
|
});
|
|
4757
4842
|
await this.cancelChildren(runId, opts);
|
|
4758
4843
|
return {
|
|
@@ -5587,7 +5672,7 @@ var WorkflowEngine = class {
|
|
|
5587
5672
|
const checkpoint = await this.store.getCheckpoint(runId, cmd.seq);
|
|
5588
5673
|
if (checkpoint && checkpoint.status !== "pending") {
|
|
5589
5674
|
setTimeout(() => {
|
|
5590
|
-
void this.
|
|
5675
|
+
void this.resumeImplicit(runId).catch(() => void 0);
|
|
5591
5676
|
}, 0).unref?.();
|
|
5592
5677
|
return;
|
|
5593
5678
|
}
|
|
@@ -5929,7 +6014,7 @@ var WorkflowEngine = class {
|
|
|
5929
6014
|
kind: "signal",
|
|
5930
6015
|
output: payload
|
|
5931
6016
|
}));
|
|
5932
|
-
setTimeout(() => void this.
|
|
6017
|
+
setTimeout(() => void this.resumeImplicit(run.id).catch(() => void 0), 0);
|
|
5933
6018
|
}, "deliverBuffered");
|
|
5934
6019
|
const buffered = await this.store.takeBufferedSignal(cmd.signal);
|
|
5935
6020
|
if (buffered) {
|
|
@@ -6743,7 +6828,7 @@ var WorkflowEngine = class {
|
|
|
6743
6828
|
queueMs: startedAt.getTime() - cp.enqueuedAt.getTime(),
|
|
6744
6829
|
durationMs: finishedAt.getTime() - startedAt.getTime()
|
|
6745
6830
|
});
|
|
6746
|
-
await this.
|
|
6831
|
+
await this.resumeImplicit(result.runId).catch((err) => {
|
|
6747
6832
|
if (err instanceof NamespaceMismatch) return null;
|
|
6748
6833
|
throw err;
|
|
6749
6834
|
});
|
|
@@ -6844,7 +6929,7 @@ var WorkflowEngine = class {
|
|
|
6844
6929
|
...waiters
|
|
6845
6930
|
];
|
|
6846
6931
|
waiters.clear();
|
|
6847
|
-
for (const runId of runIds) void this.
|
|
6932
|
+
for (const runId of runIds) void this.resumeImplicit(runId).catch(() => void 0);
|
|
6848
6933
|
}
|
|
6849
6934
|
/** Release the flow-control slot a dispatched step held (if any), by its stepId. */
|
|
6850
6935
|
async releaseQueueSlot(id) {
|
|
@@ -7996,6 +8081,7 @@ export {
|
|
|
7996
8081
|
InMemoryTransport,
|
|
7997
8082
|
LEGACY_V1_CAPABILITIES,
|
|
7998
8083
|
LEGACY_V1_PROTOCOL,
|
|
8084
|
+
NestedWorkflowCallError,
|
|
7999
8085
|
NonDeterminismError,
|
|
8000
8086
|
QueueController,
|
|
8001
8087
|
RUN_VALUE_FACET_LIMIT,
|
|
@@ -8042,6 +8128,7 @@ export {
|
|
|
8042
8128
|
coveredTokens,
|
|
8043
8129
|
createStepLogger,
|
|
8044
8130
|
currentStep,
|
|
8131
|
+
currentStepScope,
|
|
8045
8132
|
currentWorkflowCtx,
|
|
8046
8133
|
debug,
|
|
8047
8134
|
describeWorker,
|
|
@@ -8083,7 +8170,9 @@ export {
|
|
|
8083
8170
|
resolveRunWaiting,
|
|
8084
8171
|
runDurableExecution,
|
|
8085
8172
|
runInStepLogger,
|
|
8173
|
+
runInStepScope,
|
|
8086
8174
|
runInWorkflowCtx,
|
|
8175
|
+
runOutsideWorkflowCtx,
|
|
8087
8176
|
runSchedules,
|
|
8088
8177
|
runStepHandler,
|
|
8089
8178
|
runValueFacetsFromRuns,
|