@ferricstore/ferricstore 0.12.1 → 0.13.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.
Files changed (98) hide show
  1. package/README.md +2 -2
  2. package/dist/index.cjs +591 -133
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +61 -7
  5. package/dist/index.d.ts +61 -7
  6. package/dist/index.js +586 -129
  7. package/dist/index.js.map +1 -1
  8. package/dist/langgraph.cjs.map +1 -1
  9. package/dist/langgraph.d.cts +1 -1
  10. package/dist/langgraph.d.ts +1 -1
  11. package/dist/langgraph.js.map +1 -1
  12. package/dist/{outcomes-DmBwnq0Y.d.cts → outcomes-CcX956h4.d.cts} +20 -1
  13. package/dist/{outcomes-BbFDp3AH.d.ts → outcomes-DLJYTrX8.d.ts} +20 -1
  14. package/docs/api/assets/hierarchy.js +1 -1
  15. package/docs/api/assets/navigation.js +1 -1
  16. package/docs/api/assets/search.js +1 -1
  17. package/docs/api/classes/ConnectionClosedError.html +1 -1
  18. package/docs/api/classes/FerricStoreClient.html +68 -23
  19. package/docs/api/classes/FerricStoreError.html +1 -1
  20. package/docs/api/classes/FlowAlreadyExistsError.html +1 -1
  21. package/docs/api/classes/FlowBatchError.html +1 -1
  22. package/docs/api/classes/FlowNotFoundError.html +1 -1
  23. package/docs/api/classes/FlowQueryError.html +1 -1
  24. package/docs/api/classes/FlowWrongStateError.html +1 -1
  25. package/docs/api/classes/HTTPTransportError.html +1 -1
  26. package/docs/api/classes/InvalidCommandError.html +1 -1
  27. package/docs/api/classes/LeaseRenewalError.html +3 -3
  28. package/docs/api/classes/LockHeldError.html +1 -1
  29. package/docs/api/classes/LockNotOwnedError.html +1 -1
  30. package/docs/api/classes/OverloadedError.html +1 -1
  31. package/docs/api/classes/QueueCompletionError.html +1 -1
  32. package/docs/api/classes/RequestTimeoutError.html +1 -1
  33. package/docs/api/classes/RerouteError.html +1 -1
  34. package/docs/api/classes/StaleLeaseError.html +1 -1
  35. package/docs/api/classes/StalePolicyGenerationError.html +1 -1
  36. package/docs/api/classes/Workflow.html +19 -19
  37. package/docs/api/classes/WorkflowClient.html +4 -4
  38. package/docs/api/classes/WorkflowContext.html +74 -36
  39. package/docs/api/classes/WorkflowFlowCommands.html +26 -22
  40. package/docs/api/classes/WorkflowWorker.html +6 -6
  41. package/docs/api/functions/complete.html +1 -1
  42. package/docs/api/functions/fail.html +1 -1
  43. package/docs/api/functions/isAlreadyAppliedOutcome.html +41 -0
  44. package/docs/api/functions/isOutcome.html +1 -1
  45. package/docs/api/functions/retry.html +1 -1
  46. package/docs/api/functions/transition.html +1 -1
  47. package/docs/api/hierarchy.html +55 -47
  48. package/docs/api/index.html +2 -2
  49. package/docs/api/interfaces/AdminListOptions.html +1 -1
  50. package/docs/api/interfaces/AdvanceOptions.html +141 -0
  51. package/docs/api/interfaces/AlreadyAppliedOutcome.html +69 -0
  52. package/docs/api/interfaces/AppliedStepOutcome.html +87 -0
  53. package/docs/api/interfaces/CancelOptions.html +6 -6
  54. package/docs/api/interfaces/CompleteOptions.html +4 -4
  55. package/docs/api/interfaces/CompleteOutcome.html +13 -13
  56. package/docs/api/interfaces/CreateManyOptions.html +1 -1
  57. package/docs/api/interfaces/EffectCompensateOptions.html +1 -1
  58. package/docs/api/interfaces/EffectConfirmOptions.html +1 -1
  59. package/docs/api/interfaces/EffectFailOptions.html +1 -1
  60. package/docs/api/interfaces/EffectStatusOptions.html +1 -1
  61. package/docs/api/interfaces/FailOptions.html +4 -4
  62. package/docs/api/interfaces/FailOutcome.html +13 -13
  63. package/docs/api/interfaces/FerricStoreClientFromUrlOptions.html +1 -1
  64. package/docs/api/interfaces/FerricStoreClientOptions.html +1 -1
  65. package/docs/api/interfaces/FlowQueryCountResult.html +1 -1
  66. package/docs/api/interfaces/FlowQueryIndexBuild.html +1 -1
  67. package/docs/api/interfaces/FlowQueryIndexProgress.html +1 -1
  68. package/docs/api/interfaces/FlowQueryIndexValidation.html +1 -1
  69. package/docs/api/interfaces/FlowQueryRecordsResult.html +1 -1
  70. package/docs/api/interfaces/HistoryOptions.html +16 -16
  71. package/docs/api/interfaces/InvocationCreateOptions.html +1 -1
  72. package/docs/api/interfaces/LeaseMutationOptions.html +1 -1
  73. package/docs/api/interfaces/LimitListOptions.html +1 -1
  74. package/docs/api/interfaces/MutateOptions.html +1 -1
  75. package/docs/api/interfaces/NamedValueMutation.html +9 -9
  76. package/docs/api/interfaces/ReadOptions.html +12 -12
  77. package/docs/api/interfaces/ReclaimOptions.html +1 -1
  78. package/docs/api/interfaces/ReplayedStepResult.html +73 -0
  79. package/docs/api/interfaces/RequestContextOptions.html +1 -1
  80. package/docs/api/interfaces/RetryOptions.html +4 -4
  81. package/docs/api/interfaces/RetryOutcome.html +13 -13
  82. package/docs/api/interfaces/RunStepsItem.html +3 -3
  83. package/docs/api/interfaces/RunStepsManyOptions.html +11 -11
  84. package/docs/api/interfaces/SearchOptions.html +13 -13
  85. package/docs/api/interfaces/StepContinueOptions.html +1 -1
  86. package/docs/api/interfaces/StepOptions.html +159 -0
  87. package/docs/api/interfaces/StepResult.html +67 -0
  88. package/docs/api/interfaces/TDigestCreateOptions.html +1 -1
  89. package/docs/api/interfaces/TDigestMergeOptions.html +1 -1
  90. package/docs/api/interfaces/TransitionOptions.html +1 -1
  91. package/docs/api/interfaces/TransitionOutcome.html +14 -14
  92. package/docs/api/modules.html +6 -6
  93. package/docs/api/types/ConnectionRequestDisposition.html +1 -1
  94. package/docs/api/types/ManagementPairs.html +1 -1
  95. package/docs/api/types/Outcome.html +1 -1
  96. package/docs/api/types/SearchStateMeta.html +1 -1
  97. package/docs/api/types/WorkflowStepResult.html +38 -0
  98. package/package.json +3 -3
package/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ConnectionOptions } from 'node:tls';
2
2
  import { C as CommandArgument, a as Command } from './internal-lEEDZpPH.cjs';
3
3
  import { Buffer as Buffer$1 } from 'node:buffer';
4
- import { F as FencingToken, S as StateMeta, a as FlowRecord, C as ClaimedItem, M as MaxActiveMs, R as RateLimitResult, K as KeyInfo, b as FetchOrComputeResult, c as ChildSpec, d as FencedItem, e as CreateItem, O as Outcome } from './outcomes-DmBwnq0Y.cjs';
5
- export { f as CompleteOutcome, g as FailOutcome, h as FetchOrComputeComputeResult, i as FetchOrComputeFencedResult, j as FetchOrComputeHitResult, k as FlowMaxActiveFailure, N as NamedValueMutation, l as RetryOutcome, m as StateMetaValue, T as TransitionOutcome, n as complete, o as fail, p as isOutcome, r as retry, t as transition } from './outcomes-DmBwnq0Y.cjs';
4
+ import { F as FencingToken, S as StateMeta, a as FlowRecord, C as ClaimedItem, M as MaxActiveMs, R as RateLimitResult, K as KeyInfo, b as FetchOrComputeResult, c as ChildSpec, d as FencedItem, e as CreateItem, A as AlreadyAppliedOutcome, W as WorkflowStepResult, O as Outcome } from './outcomes-CcX956h4.cjs';
5
+ export { f as AppliedStepOutcome, g as CompleteOutcome, h as FailOutcome, i as FetchOrComputeComputeResult, j as FetchOrComputeFencedResult, k as FetchOrComputeHitResult, l as FlowMaxActiveFailure, N as NamedValueMutation, m as ReplayedStepResult, n as RetryOutcome, o as StateMetaValue, T as TransitionOutcome, p as complete, q as fail, r as isAlreadyAppliedOutcome, s as isOutcome, t as retry, u as transition } from './outcomes-CcX956h4.cjs';
6
6
 
7
7
  declare class FerricStoreError extends Error {
8
8
  readonly code: string;
@@ -1014,6 +1014,22 @@ interface StepContinueOptions extends Omit<LeaseMutationOptions, "returnRecord">
1014
1014
  /** Flow type to retain when returnJob requests a compact response. */
1015
1015
  type?: string;
1016
1016
  }
1017
+ /** Options for advancing an already-claimed Flow to its next logical state. */
1018
+ interface AdvanceOptions extends Omit<MutateOptions, "returnRecord"> {
1019
+ toState: string;
1020
+ leaseMs?: number;
1021
+ }
1022
+ /** Options for a closure whose result is journaled with its state transition. */
1023
+ interface StepOptions<TResult> extends AdvanceOptions {
1024
+ /** Stable operation identity. Keep this unchanged across retries. */
1025
+ name: string;
1026
+ run: () => TResult | PromiseLike<TResult>;
1027
+ }
1028
+ /** The renewed claim and durable result returned by a durable `step()` call. */
1029
+ interface StepResult<TResult> {
1030
+ readonly job: ClaimedItem;
1031
+ readonly result: TResult;
1032
+ }
1017
1033
  interface RunStepsItem {
1018
1034
  id: string;
1019
1035
  partitionKey?: string;
@@ -2249,7 +2265,19 @@ declare class FerricStoreClient extends FerricStoreProducerClient {
2249
2265
  }): Promise<unknown>;
2250
2266
  flowSignal(id: string, options: Parameters<FerricStoreClient["signal"]>[1]): Promise<unknown>;
2251
2267
  startAndClaim(id: string, options: StartAndClaimOptions): Promise<FlowRecord>;
2268
+ /**
2269
+ * @deprecated Low-level compatibility API. Use {@link advance} for state-only
2270
+ * continuation or {@link step} for a durable closure.
2271
+ */
2252
2272
  stepContinue(id: string, options: StepContinueOptions): Promise<FlowRecord | ClaimedItem>;
2273
+ /** Advance a claimed Flow and return its renewed claim. */
2274
+ advance(job: FlowRecord | ClaimedItem, options: AdvanceOptions): Promise<ClaimedItem>;
2275
+ /**
2276
+ * Run a closure after validating the claim, then atomically journal its
2277
+ * result and advance the Flow. A committed result is replayed without
2278
+ * invoking the closure again.
2279
+ */
2280
+ step<TResult>(job: FlowRecord | ClaimedItem, options: StepOptions<TResult>): Promise<StepResult<TResult>>;
2253
2281
  runStepsMany(items: readonly (string | RunStepsItem)[], options: RunStepsManyOptions): Promise<unknown>;
2254
2282
  transitionMany(partitionKey: string | undefined, options: {
2255
2283
  fromState: string;
@@ -2406,15 +2434,25 @@ declare class Queue {
2406
2434
  worker(options?: WorkerConfig): QueueWorker;
2407
2435
  }
2408
2436
 
2437
+ /** @internal Coordinates lease renewal around an atomic lease-rotating write. */
2438
+ interface WorkflowMutationCoordinator {
2439
+ pause(): Promise<void>;
2440
+ resume(job: ClaimedItem): void;
2441
+ }
2409
2442
  declare class WorkflowContext {
2443
+ private readonly mutationCoordinator?;
2410
2444
  readonly workflow: Workflow;
2411
2445
  readonly job: FlowRecord | ClaimedItem;
2412
- readonly stateName: string;
2413
2446
  readonly flow: WorkflowFlowCommands;
2414
- private readonly leaseJob;
2447
+ private appliedMutation;
2448
+ private currentStateName;
2449
+ private leaseJob;
2450
+ private mutationFailure?;
2451
+ private mutationPhase;
2415
2452
  private readonly valueCache;
2416
- constructor(workflow: Workflow, job: FlowRecord | ClaimedItem, stateName: string, leaseJob?: ClaimedItem);
2453
+ constructor(workflow: Workflow, job: FlowRecord | ClaimedItem, stateName: string, leaseJob?: ClaimedItem, mutationCoordinator?: WorkflowMutationCoordinator | undefined);
2417
2454
  get client(): FerricStoreClient;
2455
+ get stateName(): string;
2418
2456
  get id(): string;
2419
2457
  get type(): string;
2420
2458
  get state(): string;
@@ -2431,6 +2469,16 @@ declare class WorkflowContext {
2431
2469
  get parentFlowId(): string | undefined;
2432
2470
  get rootFlowId(): string | undefined;
2433
2471
  get correlationId(): string | undefined;
2472
+ advance(toState: string, options?: Omit<AdvanceOptions, "toState">): Promise<AlreadyAppliedOutcome>;
2473
+ step<TResult>(options: StepOptions<TResult>): Promise<WorkflowStepResult<TResult>>;
2474
+ /** @internal */
2475
+ get hasAppliedMutation(): boolean;
2476
+ /** @internal */
2477
+ get uncertainMutationFailure(): unknown;
2478
+ /** @internal */
2479
+ get hasUncertainMutation(): boolean;
2480
+ /** @internal */
2481
+ assertAppliedOutcome(outcome: AlreadyAppliedOutcome): void;
2434
2482
  value(name: string, defaultValue?: unknown, options?: {
2435
2483
  localCache?: boolean;
2436
2484
  }): Promise<unknown>;
@@ -2438,6 +2486,12 @@ declare class WorkflowContext {
2438
2486
  localCache?: boolean;
2439
2487
  }): Promise<Record<string, unknown>>;
2440
2488
  private valueMaxBytes;
2489
+ private durableClaim;
2490
+ private beforeCommit;
2491
+ private commitFailed;
2492
+ private committed;
2493
+ private replayed;
2494
+ private acceptJob;
2441
2495
  }
2442
2496
  declare class WorkflowFlowCommands {
2443
2497
  private readonly ctx;
@@ -2453,6 +2507,7 @@ declare class WorkflowFlowCommands {
2453
2507
  transition(toState: string, options?: Partial<Omit<Parameters<FerricStoreClient["transition"]>[1], "toState" | "fromState" | "leaseToken" | "fencingToken">> & {
2454
2508
  fromState?: string;
2455
2509
  }): Promise<FlowRecord | Buffer | unknown>;
2510
+ /** @deprecated Use `ctx.advance(toState)`. */
2456
2511
  stepContinue(toState: string, options?: Partial<Omit<StepContinueOptions, "toState" | "fromState" | "leaseToken" | "fencingToken">> & {
2457
2512
  fromState?: string;
2458
2513
  }): Promise<FlowRecord | ClaimedItem>;
@@ -2595,7 +2650,6 @@ declare class WorkflowWorker {
2595
2650
  private resolveStates;
2596
2651
  private claimState;
2597
2652
  private applyJob;
2598
- private applyHandlerError;
2599
2653
  }
2600
2654
 
2601
2655
  /** TypeScript SDK package version. */
@@ -2608,4 +2662,4 @@ declare const FERRICSTORE_NATIVE_PROTOCOL_VERSION = 1;
2608
2662
  /** @deprecated Use RequestDisposition; retained for source compatibility. */
2609
2663
  type ConnectionRequestDisposition = RequestDisposition;
2610
2664
 
2611
- export { type AdminListOptions, type ApprovalListOptions, type ApprovalRequestOptions, type AttributeQueryOptions, type AutoBatchOptions, type BackoffKind, type BackpressurePolicy, BitmapStore, BloomFilterStore, type BudgetCommitOptions, type BudgetReserveOptions, COMMAND_OPCODES, type CancelOptions, ChildSpec, type CircuitOpenOptions, type ClaimDueOptions, ClaimHydrationError, type ClaimHydrationItem, ClaimedItem, type Codec, type CollectionScanOptions, Command, CommandArgument, type CommandExecutor, type CompleteJobsAndClaimJobsResult, type CompleteManyOptions, type CompleteOptions, ConnectionClosedError, type ConnectionRequestDisposition, type CountMinMergeOptions, CountMinSketchStore, CreateItem, type CreateManyOptions, type CreateOptions, CuckooFilterStore, type EffectCompensateOptions, type EffectConfirmOptions, type EffectFailOptions, type EffectReserveOptions, type EffectStatusOptions, type EndpointPolicy, type ExceptionPolicy, type ExecutePipelineOptions, type ExpiryCondition, type ExtendLeaseOptions, FERRICSTORE_MINIMUM_SERVER_VERSION, FERRICSTORE_NATIVE_PROTOCOL_VERSION, FERRICSTORE_SDK_VERSION, type FailOptions, FencedItem, FencingToken, FerricStoreClient, type FerricStoreClientFromUrlOptions, type FerricStoreClientOptions, FerricStoreError, FetchOrComputeResult, type FlowAdminRecord, FlowAlreadyExistsError, type FlowBatchCompletedItem, FlowBatchError, type FlowEventProjectionField, type FlowExplainCapabilities, type FlowExplainResult, FlowNotFoundError, type FlowPolicyBackoffKind, type FlowPolicyBackoffSnapshot, type FlowPolicyOptions, type FlowPolicyRetentionSnapshot, type FlowPolicyRetrySnapshot, type FlowPolicySnapshot, type FlowPolicyStateSnapshot, FlowProjection, type FlowProjectionField, type FlowProjectionShape, type FlowQueryCountResult, FlowQueryError, type FlowQueryErrorPosition, type FlowQueryIndex, type FlowQueryIndexBuild, type FlowQueryIndexCoverage, type FlowQueryIndexField, type FlowQueryIndexFormat, type FlowQueryIndexProgress, type FlowQueryIndexRegistry, type FlowQueryIndexRetirement, type FlowQueryIndexServiceState, type FlowQueryIndexServices, type FlowQueryIndexStatistics, type FlowQueryIndexStatus, type FlowQueryIndexValidation, type FlowQueryInteger, type FlowQueryPage, type FlowQueryParameter, type FlowQueryParameters, type FlowQueryQuality, type FlowQueryRecord, type FlowQueryRecordsResult, type FlowQueryResult, type FlowQueryUsage, FlowRecord, type FlowRunProjectionField, type FlowStateMode, type FlowStatePolicy, type FlowStatePolicyLike, type FlowStatsOptions, FlowWrongStateError, type GeoAddOptions, type GeoMember, GeoStore, type GetExOptions, type GovernanceLedgerOptions, HTTPAdapter, type HTTPAdapterOptions, type HTTPCommandDisposition, HTTPTransportError, type HashScanResult, HashStore, type HistoryOptions, HyperLogLogStore, type IntegerReply, InvalidCommandError, type InvocationCreateOptions, JsonCodec, KeyInfo, KeyValueStore, type LeaseMutationOptions, LeaseRenewalError, type LimitAmountOptions, type LimitLeaseOptions, type LimitListOptions, type LimitReleaseOptions, ListStore, LockHeldError, LockNotOwnedError, MAX_FLOW_POLICY_GENERATION, type ManagementPairs, MaxActiveMs, type MutateOptions, NativeAdapter, type NativeAdapterOptions, type NativeClientOptions, type NativeProtocolEvent, Outcome, OverloadedError, type ProtocolCommand, Queue, type QueueBatchHandler, QueueClient, QueueCompletionError, type QueueHandler, type QueueJob, type QueueOptions, QueueWorker, type QueueWorkerResult, type RangeLimit, RateLimitResult, RawCodec, type ReadOptions, type ReclaimOptions, type ReconnectOptions, ReconnectingExecutor, type RequestContext, type RequestContextOptions, type RequestDisposition, RequestTimeoutError, RerouteError, type RetryOptions, type RetryPolicy, type RoutingEndpoint, type RoutingRoute, RoutingTopology, type RunStepsItem, type RunStepsManyOptions, type ScanOptions, type ScheduleCatchupPolicy, type ScheduleFireDueOptions, type ScheduleFireDueResult, type ScheduleFireOptions, type ScheduleFireResult, type ScheduleKind, type ScheduleListOptions, type ScheduleOptions, type ScheduleOverlapPolicy, type ScheduleRecord, type ScheduleState, type SearchOptions, type SearchStateMeta, type SetOptions, type SetScanResult, SetStore, type SortedSetScanResult, SortedSetStore, StaleLeaseError, StalePolicyGenerationError, type StartAndClaimOptions, StateMeta, type StateOptions, type StateRegistration, type StepContinueOptions, type StoreCommandClient, StreamStore, type TDigestCreateOptions, type TDigestMergeOptions, TDigestStore, type TopKReserveOptions, TopKStore, type TopologyNativeAdapterOptions, TopologyNativeAdapterPool, type TransitionOptions, type ValueConfig, type WorkerConfig, type WorkerProfile, type WorkerRefillStrategy, Workflow, WorkflowClient, WorkflowContext, WorkflowFlowCommands, type WorkflowHandler, type WorkflowOptions, WorkflowWorker, type WorkflowWorkerResult, type XReadStream, type ZAddMember, type ZAddOptions, classifyServerError, httpCommandDisposition, isReconnectableClosedConnectionError, mapException, projectFlowQuery };
2665
+ export { type AdminListOptions, type AdvanceOptions, AlreadyAppliedOutcome, type ApprovalListOptions, type ApprovalRequestOptions, type AttributeQueryOptions, type AutoBatchOptions, type BackoffKind, type BackpressurePolicy, BitmapStore, BloomFilterStore, type BudgetCommitOptions, type BudgetReserveOptions, COMMAND_OPCODES, type CancelOptions, ChildSpec, type CircuitOpenOptions, type ClaimDueOptions, ClaimHydrationError, type ClaimHydrationItem, ClaimedItem, type Codec, type CollectionScanOptions, Command, CommandArgument, type CommandExecutor, type CompleteJobsAndClaimJobsResult, type CompleteManyOptions, type CompleteOptions, ConnectionClosedError, type ConnectionRequestDisposition, type CountMinMergeOptions, CountMinSketchStore, CreateItem, type CreateManyOptions, type CreateOptions, CuckooFilterStore, type EffectCompensateOptions, type EffectConfirmOptions, type EffectFailOptions, type EffectReserveOptions, type EffectStatusOptions, type EndpointPolicy, type ExceptionPolicy, type ExecutePipelineOptions, type ExpiryCondition, type ExtendLeaseOptions, FERRICSTORE_MINIMUM_SERVER_VERSION, FERRICSTORE_NATIVE_PROTOCOL_VERSION, FERRICSTORE_SDK_VERSION, type FailOptions, FencedItem, FencingToken, FerricStoreClient, type FerricStoreClientFromUrlOptions, type FerricStoreClientOptions, FerricStoreError, FetchOrComputeResult, type FlowAdminRecord, FlowAlreadyExistsError, type FlowBatchCompletedItem, FlowBatchError, type FlowEventProjectionField, type FlowExplainCapabilities, type FlowExplainResult, FlowNotFoundError, type FlowPolicyBackoffKind, type FlowPolicyBackoffSnapshot, type FlowPolicyOptions, type FlowPolicyRetentionSnapshot, type FlowPolicyRetrySnapshot, type FlowPolicySnapshot, type FlowPolicyStateSnapshot, FlowProjection, type FlowProjectionField, type FlowProjectionShape, type FlowQueryCountResult, FlowQueryError, type FlowQueryErrorPosition, type FlowQueryIndex, type FlowQueryIndexBuild, type FlowQueryIndexCoverage, type FlowQueryIndexField, type FlowQueryIndexFormat, type FlowQueryIndexProgress, type FlowQueryIndexRegistry, type FlowQueryIndexRetirement, type FlowQueryIndexServiceState, type FlowQueryIndexServices, type FlowQueryIndexStatistics, type FlowQueryIndexStatus, type FlowQueryIndexValidation, type FlowQueryInteger, type FlowQueryPage, type FlowQueryParameter, type FlowQueryParameters, type FlowQueryQuality, type FlowQueryRecord, type FlowQueryRecordsResult, type FlowQueryResult, type FlowQueryUsage, FlowRecord, type FlowRunProjectionField, type FlowStateMode, type FlowStatePolicy, type FlowStatePolicyLike, type FlowStatsOptions, FlowWrongStateError, type GeoAddOptions, type GeoMember, GeoStore, type GetExOptions, type GovernanceLedgerOptions, HTTPAdapter, type HTTPAdapterOptions, type HTTPCommandDisposition, HTTPTransportError, type HashScanResult, HashStore, type HistoryOptions, HyperLogLogStore, type IntegerReply, InvalidCommandError, type InvocationCreateOptions, JsonCodec, KeyInfo, KeyValueStore, type LeaseMutationOptions, LeaseRenewalError, type LimitAmountOptions, type LimitLeaseOptions, type LimitListOptions, type LimitReleaseOptions, ListStore, LockHeldError, LockNotOwnedError, MAX_FLOW_POLICY_GENERATION, type ManagementPairs, MaxActiveMs, type MutateOptions, NativeAdapter, type NativeAdapterOptions, type NativeClientOptions, type NativeProtocolEvent, Outcome, OverloadedError, type ProtocolCommand, Queue, type QueueBatchHandler, QueueClient, QueueCompletionError, type QueueHandler, type QueueJob, type QueueOptions, QueueWorker, type QueueWorkerResult, type RangeLimit, RateLimitResult, RawCodec, type ReadOptions, type ReclaimOptions, type ReconnectOptions, ReconnectingExecutor, type RequestContext, type RequestContextOptions, type RequestDisposition, RequestTimeoutError, RerouteError, type RetryOptions, type RetryPolicy, type RoutingEndpoint, type RoutingRoute, RoutingTopology, type RunStepsItem, type RunStepsManyOptions, type ScanOptions, type ScheduleCatchupPolicy, type ScheduleFireDueOptions, type ScheduleFireDueResult, type ScheduleFireOptions, type ScheduleFireResult, type ScheduleKind, type ScheduleListOptions, type ScheduleOptions, type ScheduleOverlapPolicy, type ScheduleRecord, type ScheduleState, type SearchOptions, type SearchStateMeta, type SetOptions, type SetScanResult, SetStore, type SortedSetScanResult, SortedSetStore, StaleLeaseError, StalePolicyGenerationError, type StartAndClaimOptions, StateMeta, type StateOptions, type StateRegistration, type StepContinueOptions, type StepOptions, type StepResult, type StoreCommandClient, StreamStore, type TDigestCreateOptions, type TDigestMergeOptions, TDigestStore, type TopKReserveOptions, TopKStore, type TopologyNativeAdapterOptions, TopologyNativeAdapterPool, type TransitionOptions, type ValueConfig, type WorkerConfig, type WorkerProfile, type WorkerRefillStrategy, Workflow, WorkflowClient, WorkflowContext, WorkflowFlowCommands, type WorkflowHandler, type WorkflowOptions, WorkflowStepResult, WorkflowWorker, type WorkflowWorkerResult, type XReadStream, type ZAddMember, type ZAddOptions, classifyServerError, httpCommandDisposition, isReconnectableClosedConnectionError, mapException, projectFlowQuery };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ConnectionOptions } from 'node:tls';
2
2
  import { C as CommandArgument, a as Command } from './internal-lEEDZpPH.js';
3
3
  import { Buffer as Buffer$1 } from 'node:buffer';
4
- import { F as FencingToken, S as StateMeta, a as FlowRecord, C as ClaimedItem, M as MaxActiveMs, R as RateLimitResult, K as KeyInfo, b as FetchOrComputeResult, c as ChildSpec, d as FencedItem, e as CreateItem, O as Outcome } from './outcomes-BbFDp3AH.js';
5
- export { f as CompleteOutcome, g as FailOutcome, h as FetchOrComputeComputeResult, i as FetchOrComputeFencedResult, j as FetchOrComputeHitResult, k as FlowMaxActiveFailure, N as NamedValueMutation, l as RetryOutcome, m as StateMetaValue, T as TransitionOutcome, n as complete, o as fail, p as isOutcome, r as retry, t as transition } from './outcomes-BbFDp3AH.js';
4
+ import { F as FencingToken, S as StateMeta, a as FlowRecord, C as ClaimedItem, M as MaxActiveMs, R as RateLimitResult, K as KeyInfo, b as FetchOrComputeResult, c as ChildSpec, d as FencedItem, e as CreateItem, A as AlreadyAppliedOutcome, W as WorkflowStepResult, O as Outcome } from './outcomes-DLJYTrX8.js';
5
+ export { f as AppliedStepOutcome, g as CompleteOutcome, h as FailOutcome, i as FetchOrComputeComputeResult, j as FetchOrComputeFencedResult, k as FetchOrComputeHitResult, l as FlowMaxActiveFailure, N as NamedValueMutation, m as ReplayedStepResult, n as RetryOutcome, o as StateMetaValue, T as TransitionOutcome, p as complete, q as fail, r as isAlreadyAppliedOutcome, s as isOutcome, t as retry, u as transition } from './outcomes-DLJYTrX8.js';
6
6
 
7
7
  declare class FerricStoreError extends Error {
8
8
  readonly code: string;
@@ -1014,6 +1014,22 @@ interface StepContinueOptions extends Omit<LeaseMutationOptions, "returnRecord">
1014
1014
  /** Flow type to retain when returnJob requests a compact response. */
1015
1015
  type?: string;
1016
1016
  }
1017
+ /** Options for advancing an already-claimed Flow to its next logical state. */
1018
+ interface AdvanceOptions extends Omit<MutateOptions, "returnRecord"> {
1019
+ toState: string;
1020
+ leaseMs?: number;
1021
+ }
1022
+ /** Options for a closure whose result is journaled with its state transition. */
1023
+ interface StepOptions<TResult> extends AdvanceOptions {
1024
+ /** Stable operation identity. Keep this unchanged across retries. */
1025
+ name: string;
1026
+ run: () => TResult | PromiseLike<TResult>;
1027
+ }
1028
+ /** The renewed claim and durable result returned by a durable `step()` call. */
1029
+ interface StepResult<TResult> {
1030
+ readonly job: ClaimedItem;
1031
+ readonly result: TResult;
1032
+ }
1017
1033
  interface RunStepsItem {
1018
1034
  id: string;
1019
1035
  partitionKey?: string;
@@ -2249,7 +2265,19 @@ declare class FerricStoreClient extends FerricStoreProducerClient {
2249
2265
  }): Promise<unknown>;
2250
2266
  flowSignal(id: string, options: Parameters<FerricStoreClient["signal"]>[1]): Promise<unknown>;
2251
2267
  startAndClaim(id: string, options: StartAndClaimOptions): Promise<FlowRecord>;
2268
+ /**
2269
+ * @deprecated Low-level compatibility API. Use {@link advance} for state-only
2270
+ * continuation or {@link step} for a durable closure.
2271
+ */
2252
2272
  stepContinue(id: string, options: StepContinueOptions): Promise<FlowRecord | ClaimedItem>;
2273
+ /** Advance a claimed Flow and return its renewed claim. */
2274
+ advance(job: FlowRecord | ClaimedItem, options: AdvanceOptions): Promise<ClaimedItem>;
2275
+ /**
2276
+ * Run a closure after validating the claim, then atomically journal its
2277
+ * result and advance the Flow. A committed result is replayed without
2278
+ * invoking the closure again.
2279
+ */
2280
+ step<TResult>(job: FlowRecord | ClaimedItem, options: StepOptions<TResult>): Promise<StepResult<TResult>>;
2253
2281
  runStepsMany(items: readonly (string | RunStepsItem)[], options: RunStepsManyOptions): Promise<unknown>;
2254
2282
  transitionMany(partitionKey: string | undefined, options: {
2255
2283
  fromState: string;
@@ -2406,15 +2434,25 @@ declare class Queue {
2406
2434
  worker(options?: WorkerConfig): QueueWorker;
2407
2435
  }
2408
2436
 
2437
+ /** @internal Coordinates lease renewal around an atomic lease-rotating write. */
2438
+ interface WorkflowMutationCoordinator {
2439
+ pause(): Promise<void>;
2440
+ resume(job: ClaimedItem): void;
2441
+ }
2409
2442
  declare class WorkflowContext {
2443
+ private readonly mutationCoordinator?;
2410
2444
  readonly workflow: Workflow;
2411
2445
  readonly job: FlowRecord | ClaimedItem;
2412
- readonly stateName: string;
2413
2446
  readonly flow: WorkflowFlowCommands;
2414
- private readonly leaseJob;
2447
+ private appliedMutation;
2448
+ private currentStateName;
2449
+ private leaseJob;
2450
+ private mutationFailure?;
2451
+ private mutationPhase;
2415
2452
  private readonly valueCache;
2416
- constructor(workflow: Workflow, job: FlowRecord | ClaimedItem, stateName: string, leaseJob?: ClaimedItem);
2453
+ constructor(workflow: Workflow, job: FlowRecord | ClaimedItem, stateName: string, leaseJob?: ClaimedItem, mutationCoordinator?: WorkflowMutationCoordinator | undefined);
2417
2454
  get client(): FerricStoreClient;
2455
+ get stateName(): string;
2418
2456
  get id(): string;
2419
2457
  get type(): string;
2420
2458
  get state(): string;
@@ -2431,6 +2469,16 @@ declare class WorkflowContext {
2431
2469
  get parentFlowId(): string | undefined;
2432
2470
  get rootFlowId(): string | undefined;
2433
2471
  get correlationId(): string | undefined;
2472
+ advance(toState: string, options?: Omit<AdvanceOptions, "toState">): Promise<AlreadyAppliedOutcome>;
2473
+ step<TResult>(options: StepOptions<TResult>): Promise<WorkflowStepResult<TResult>>;
2474
+ /** @internal */
2475
+ get hasAppliedMutation(): boolean;
2476
+ /** @internal */
2477
+ get uncertainMutationFailure(): unknown;
2478
+ /** @internal */
2479
+ get hasUncertainMutation(): boolean;
2480
+ /** @internal */
2481
+ assertAppliedOutcome(outcome: AlreadyAppliedOutcome): void;
2434
2482
  value(name: string, defaultValue?: unknown, options?: {
2435
2483
  localCache?: boolean;
2436
2484
  }): Promise<unknown>;
@@ -2438,6 +2486,12 @@ declare class WorkflowContext {
2438
2486
  localCache?: boolean;
2439
2487
  }): Promise<Record<string, unknown>>;
2440
2488
  private valueMaxBytes;
2489
+ private durableClaim;
2490
+ private beforeCommit;
2491
+ private commitFailed;
2492
+ private committed;
2493
+ private replayed;
2494
+ private acceptJob;
2441
2495
  }
2442
2496
  declare class WorkflowFlowCommands {
2443
2497
  private readonly ctx;
@@ -2453,6 +2507,7 @@ declare class WorkflowFlowCommands {
2453
2507
  transition(toState: string, options?: Partial<Omit<Parameters<FerricStoreClient["transition"]>[1], "toState" | "fromState" | "leaseToken" | "fencingToken">> & {
2454
2508
  fromState?: string;
2455
2509
  }): Promise<FlowRecord | Buffer | unknown>;
2510
+ /** @deprecated Use `ctx.advance(toState)`. */
2456
2511
  stepContinue(toState: string, options?: Partial<Omit<StepContinueOptions, "toState" | "fromState" | "leaseToken" | "fencingToken">> & {
2457
2512
  fromState?: string;
2458
2513
  }): Promise<FlowRecord | ClaimedItem>;
@@ -2595,7 +2650,6 @@ declare class WorkflowWorker {
2595
2650
  private resolveStates;
2596
2651
  private claimState;
2597
2652
  private applyJob;
2598
- private applyHandlerError;
2599
2653
  }
2600
2654
 
2601
2655
  /** TypeScript SDK package version. */
@@ -2608,4 +2662,4 @@ declare const FERRICSTORE_NATIVE_PROTOCOL_VERSION = 1;
2608
2662
  /** @deprecated Use RequestDisposition; retained for source compatibility. */
2609
2663
  type ConnectionRequestDisposition = RequestDisposition;
2610
2664
 
2611
- export { type AdminListOptions, type ApprovalListOptions, type ApprovalRequestOptions, type AttributeQueryOptions, type AutoBatchOptions, type BackoffKind, type BackpressurePolicy, BitmapStore, BloomFilterStore, type BudgetCommitOptions, type BudgetReserveOptions, COMMAND_OPCODES, type CancelOptions, ChildSpec, type CircuitOpenOptions, type ClaimDueOptions, ClaimHydrationError, type ClaimHydrationItem, ClaimedItem, type Codec, type CollectionScanOptions, Command, CommandArgument, type CommandExecutor, type CompleteJobsAndClaimJobsResult, type CompleteManyOptions, type CompleteOptions, ConnectionClosedError, type ConnectionRequestDisposition, type CountMinMergeOptions, CountMinSketchStore, CreateItem, type CreateManyOptions, type CreateOptions, CuckooFilterStore, type EffectCompensateOptions, type EffectConfirmOptions, type EffectFailOptions, type EffectReserveOptions, type EffectStatusOptions, type EndpointPolicy, type ExceptionPolicy, type ExecutePipelineOptions, type ExpiryCondition, type ExtendLeaseOptions, FERRICSTORE_MINIMUM_SERVER_VERSION, FERRICSTORE_NATIVE_PROTOCOL_VERSION, FERRICSTORE_SDK_VERSION, type FailOptions, FencedItem, FencingToken, FerricStoreClient, type FerricStoreClientFromUrlOptions, type FerricStoreClientOptions, FerricStoreError, FetchOrComputeResult, type FlowAdminRecord, FlowAlreadyExistsError, type FlowBatchCompletedItem, FlowBatchError, type FlowEventProjectionField, type FlowExplainCapabilities, type FlowExplainResult, FlowNotFoundError, type FlowPolicyBackoffKind, type FlowPolicyBackoffSnapshot, type FlowPolicyOptions, type FlowPolicyRetentionSnapshot, type FlowPolicyRetrySnapshot, type FlowPolicySnapshot, type FlowPolicyStateSnapshot, FlowProjection, type FlowProjectionField, type FlowProjectionShape, type FlowQueryCountResult, FlowQueryError, type FlowQueryErrorPosition, type FlowQueryIndex, type FlowQueryIndexBuild, type FlowQueryIndexCoverage, type FlowQueryIndexField, type FlowQueryIndexFormat, type FlowQueryIndexProgress, type FlowQueryIndexRegistry, type FlowQueryIndexRetirement, type FlowQueryIndexServiceState, type FlowQueryIndexServices, type FlowQueryIndexStatistics, type FlowQueryIndexStatus, type FlowQueryIndexValidation, type FlowQueryInteger, type FlowQueryPage, type FlowQueryParameter, type FlowQueryParameters, type FlowQueryQuality, type FlowQueryRecord, type FlowQueryRecordsResult, type FlowQueryResult, type FlowQueryUsage, FlowRecord, type FlowRunProjectionField, type FlowStateMode, type FlowStatePolicy, type FlowStatePolicyLike, type FlowStatsOptions, FlowWrongStateError, type GeoAddOptions, type GeoMember, GeoStore, type GetExOptions, type GovernanceLedgerOptions, HTTPAdapter, type HTTPAdapterOptions, type HTTPCommandDisposition, HTTPTransportError, type HashScanResult, HashStore, type HistoryOptions, HyperLogLogStore, type IntegerReply, InvalidCommandError, type InvocationCreateOptions, JsonCodec, KeyInfo, KeyValueStore, type LeaseMutationOptions, LeaseRenewalError, type LimitAmountOptions, type LimitLeaseOptions, type LimitListOptions, type LimitReleaseOptions, ListStore, LockHeldError, LockNotOwnedError, MAX_FLOW_POLICY_GENERATION, type ManagementPairs, MaxActiveMs, type MutateOptions, NativeAdapter, type NativeAdapterOptions, type NativeClientOptions, type NativeProtocolEvent, Outcome, OverloadedError, type ProtocolCommand, Queue, type QueueBatchHandler, QueueClient, QueueCompletionError, type QueueHandler, type QueueJob, type QueueOptions, QueueWorker, type QueueWorkerResult, type RangeLimit, RateLimitResult, RawCodec, type ReadOptions, type ReclaimOptions, type ReconnectOptions, ReconnectingExecutor, type RequestContext, type RequestContextOptions, type RequestDisposition, RequestTimeoutError, RerouteError, type RetryOptions, type RetryPolicy, type RoutingEndpoint, type RoutingRoute, RoutingTopology, type RunStepsItem, type RunStepsManyOptions, type ScanOptions, type ScheduleCatchupPolicy, type ScheduleFireDueOptions, type ScheduleFireDueResult, type ScheduleFireOptions, type ScheduleFireResult, type ScheduleKind, type ScheduleListOptions, type ScheduleOptions, type ScheduleOverlapPolicy, type ScheduleRecord, type ScheduleState, type SearchOptions, type SearchStateMeta, type SetOptions, type SetScanResult, SetStore, type SortedSetScanResult, SortedSetStore, StaleLeaseError, StalePolicyGenerationError, type StartAndClaimOptions, StateMeta, type StateOptions, type StateRegistration, type StepContinueOptions, type StoreCommandClient, StreamStore, type TDigestCreateOptions, type TDigestMergeOptions, TDigestStore, type TopKReserveOptions, TopKStore, type TopologyNativeAdapterOptions, TopologyNativeAdapterPool, type TransitionOptions, type ValueConfig, type WorkerConfig, type WorkerProfile, type WorkerRefillStrategy, Workflow, WorkflowClient, WorkflowContext, WorkflowFlowCommands, type WorkflowHandler, type WorkflowOptions, WorkflowWorker, type WorkflowWorkerResult, type XReadStream, type ZAddMember, type ZAddOptions, classifyServerError, httpCommandDisposition, isReconnectableClosedConnectionError, mapException, projectFlowQuery };
2665
+ export { type AdminListOptions, type AdvanceOptions, AlreadyAppliedOutcome, type ApprovalListOptions, type ApprovalRequestOptions, type AttributeQueryOptions, type AutoBatchOptions, type BackoffKind, type BackpressurePolicy, BitmapStore, BloomFilterStore, type BudgetCommitOptions, type BudgetReserveOptions, COMMAND_OPCODES, type CancelOptions, ChildSpec, type CircuitOpenOptions, type ClaimDueOptions, ClaimHydrationError, type ClaimHydrationItem, ClaimedItem, type Codec, type CollectionScanOptions, Command, CommandArgument, type CommandExecutor, type CompleteJobsAndClaimJobsResult, type CompleteManyOptions, type CompleteOptions, ConnectionClosedError, type ConnectionRequestDisposition, type CountMinMergeOptions, CountMinSketchStore, CreateItem, type CreateManyOptions, type CreateOptions, CuckooFilterStore, type EffectCompensateOptions, type EffectConfirmOptions, type EffectFailOptions, type EffectReserveOptions, type EffectStatusOptions, type EndpointPolicy, type ExceptionPolicy, type ExecutePipelineOptions, type ExpiryCondition, type ExtendLeaseOptions, FERRICSTORE_MINIMUM_SERVER_VERSION, FERRICSTORE_NATIVE_PROTOCOL_VERSION, FERRICSTORE_SDK_VERSION, type FailOptions, FencedItem, FencingToken, FerricStoreClient, type FerricStoreClientFromUrlOptions, type FerricStoreClientOptions, FerricStoreError, FetchOrComputeResult, type FlowAdminRecord, FlowAlreadyExistsError, type FlowBatchCompletedItem, FlowBatchError, type FlowEventProjectionField, type FlowExplainCapabilities, type FlowExplainResult, FlowNotFoundError, type FlowPolicyBackoffKind, type FlowPolicyBackoffSnapshot, type FlowPolicyOptions, type FlowPolicyRetentionSnapshot, type FlowPolicyRetrySnapshot, type FlowPolicySnapshot, type FlowPolicyStateSnapshot, FlowProjection, type FlowProjectionField, type FlowProjectionShape, type FlowQueryCountResult, FlowQueryError, type FlowQueryErrorPosition, type FlowQueryIndex, type FlowQueryIndexBuild, type FlowQueryIndexCoverage, type FlowQueryIndexField, type FlowQueryIndexFormat, type FlowQueryIndexProgress, type FlowQueryIndexRegistry, type FlowQueryIndexRetirement, type FlowQueryIndexServiceState, type FlowQueryIndexServices, type FlowQueryIndexStatistics, type FlowQueryIndexStatus, type FlowQueryIndexValidation, type FlowQueryInteger, type FlowQueryPage, type FlowQueryParameter, type FlowQueryParameters, type FlowQueryQuality, type FlowQueryRecord, type FlowQueryRecordsResult, type FlowQueryResult, type FlowQueryUsage, FlowRecord, type FlowRunProjectionField, type FlowStateMode, type FlowStatePolicy, type FlowStatePolicyLike, type FlowStatsOptions, FlowWrongStateError, type GeoAddOptions, type GeoMember, GeoStore, type GetExOptions, type GovernanceLedgerOptions, HTTPAdapter, type HTTPAdapterOptions, type HTTPCommandDisposition, HTTPTransportError, type HashScanResult, HashStore, type HistoryOptions, HyperLogLogStore, type IntegerReply, InvalidCommandError, type InvocationCreateOptions, JsonCodec, KeyInfo, KeyValueStore, type LeaseMutationOptions, LeaseRenewalError, type LimitAmountOptions, type LimitLeaseOptions, type LimitListOptions, type LimitReleaseOptions, ListStore, LockHeldError, LockNotOwnedError, MAX_FLOW_POLICY_GENERATION, type ManagementPairs, MaxActiveMs, type MutateOptions, NativeAdapter, type NativeAdapterOptions, type NativeClientOptions, type NativeProtocolEvent, Outcome, OverloadedError, type ProtocolCommand, Queue, type QueueBatchHandler, QueueClient, QueueCompletionError, type QueueHandler, type QueueJob, type QueueOptions, QueueWorker, type QueueWorkerResult, type RangeLimit, RateLimitResult, RawCodec, type ReadOptions, type ReclaimOptions, type ReconnectOptions, ReconnectingExecutor, type RequestContext, type RequestContextOptions, type RequestDisposition, RequestTimeoutError, RerouteError, type RetryOptions, type RetryPolicy, type RoutingEndpoint, type RoutingRoute, RoutingTopology, type RunStepsItem, type RunStepsManyOptions, type ScanOptions, type ScheduleCatchupPolicy, type ScheduleFireDueOptions, type ScheduleFireDueResult, type ScheduleFireOptions, type ScheduleFireResult, type ScheduleKind, type ScheduleListOptions, type ScheduleOptions, type ScheduleOverlapPolicy, type ScheduleRecord, type ScheduleState, type SearchOptions, type SearchStateMeta, type SetOptions, type SetScanResult, SetStore, type SortedSetScanResult, SortedSetStore, StaleLeaseError, StalePolicyGenerationError, type StartAndClaimOptions, StateMeta, type StateOptions, type StateRegistration, type StepContinueOptions, type StepOptions, type StepResult, type StoreCommandClient, StreamStore, type TDigestCreateOptions, type TDigestMergeOptions, TDigestStore, type TopKReserveOptions, TopKStore, type TopologyNativeAdapterOptions, TopologyNativeAdapterPool, type TransitionOptions, type ValueConfig, type WorkerConfig, type WorkerProfile, type WorkerRefillStrategy, Workflow, WorkflowClient, WorkflowContext, WorkflowFlowCommands, type WorkflowHandler, type WorkflowOptions, WorkflowStepResult, WorkflowWorker, type WorkflowWorkerResult, type XReadStream, type ZAddMember, type ZAddOptions, classifyServerError, httpCommandDisposition, isReconnectableClosedConnectionError, mapException, projectFlowQuery };