@ferricstore/ferricstore 0.1.5 → 0.1.6

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 (62) hide show
  1. package/README.md +20 -1
  2. package/dist/index.cjs +187 -11
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +39 -7
  5. package/dist/index.d.ts +39 -7
  6. package/dist/index.js +187 -11
  7. package/dist/index.js.map +1 -1
  8. package/docs/api/assets/hierarchy.js +1 -1
  9. package/docs/api/assets/navigation.js +1 -1
  10. package/docs/api/assets/search.js +1 -1
  11. package/docs/api/classes/FerricStoreClient.html +8 -2
  12. package/docs/api/classes/FerricStoreError.html +1 -1
  13. package/docs/api/classes/FlowAlreadyExistsError.html +1 -1
  14. package/docs/api/classes/FlowNotFoundError.html +1 -1
  15. package/docs/api/classes/FlowWrongStateError.html +1 -1
  16. package/docs/api/classes/InvalidCommandError.html +1 -1
  17. package/docs/api/classes/LockHeldError.html +1 -1
  18. package/docs/api/classes/LockNotOwnedError.html +1 -1
  19. package/docs/api/classes/OverloadedError.html +1 -1
  20. package/docs/api/classes/StaleLeaseError.html +1 -1
  21. package/docs/api/classes/Workflow.html +3 -2
  22. package/docs/api/classes/WorkflowClient.html +2 -2
  23. package/docs/api/classes/WorkflowContext.html +2 -2
  24. package/docs/api/classes/WorkflowFlowCommands.html +2 -2
  25. package/docs/api/classes/WorkflowWorker.html +2 -2
  26. package/docs/api/hierarchy.html +1 -1
  27. package/docs/api/index.html +6 -1
  28. package/docs/api/interfaces/CancelOptions.html +2 -2
  29. package/docs/api/interfaces/CompleteOptions.html +2 -2
  30. package/docs/api/interfaces/CompleteOutcome.html +1 -1
  31. package/docs/api/interfaces/CreateManyOptions.html +1 -1
  32. package/docs/api/interfaces/FailOptions.html +2 -2
  33. package/docs/api/interfaces/FailOutcome.html +1 -1
  34. package/docs/api/interfaces/FerricStoreClientFromUrlOptions.html +1 -1
  35. package/docs/api/interfaces/FerricStoreClientOptions.html +1 -1
  36. package/docs/api/interfaces/FlowPolicyOptions.html +7 -0
  37. package/docs/api/interfaces/FlowStatePolicy.html +3 -0
  38. package/docs/api/interfaces/InvocationCreateOptions.html +4 -0
  39. package/docs/api/interfaces/MutateOptions.html +2 -2
  40. package/docs/api/interfaces/NamedValueMutation.html +1 -1
  41. package/docs/api/interfaces/ReadOptions.html +2 -2
  42. package/docs/api/interfaces/ReclaimOptions.html +1 -1
  43. package/docs/api/interfaces/RequestContext.html +4 -0
  44. package/docs/api/interfaces/RequestContextOptions.html +2 -0
  45. package/docs/api/interfaces/RetryOptions.html +2 -2
  46. package/docs/api/interfaces/RetryOutcome.html +1 -1
  47. package/docs/api/interfaces/SearchOptions.html +2 -2
  48. package/docs/api/interfaces/StateOptions.html +3 -2
  49. package/docs/api/interfaces/StateRegistration.html +3 -2
  50. package/docs/api/interfaces/TDigestCreateOptions.html +1 -1
  51. package/docs/api/interfaces/TDigestMergeOptions.html +1 -1
  52. package/docs/api/interfaces/TransitionOptions.html +2 -2
  53. package/docs/api/interfaces/TransitionOutcome.html +1 -1
  54. package/docs/api/interfaces/WorkflowOptions.html +2 -2
  55. package/docs/api/interfaces/WorkflowWorkerResult.html +2 -2
  56. package/docs/api/modules.html +1 -1
  57. package/docs/api/types/FlowStateMode.html +1 -0
  58. package/docs/api/types/FlowStatePolicyLike.html +1 -0
  59. package/docs/api/types/ManagementPairs.html +1 -1
  60. package/docs/api/types/SearchStateMeta.html +1 -1
  61. package/docs/api/types/WorkflowHandler.html +1 -1
  62. package/package.json +1 -1
package/dist/index.d.cts CHANGED
@@ -871,6 +871,32 @@ interface ClaimDueOptions {
871
871
  interface ReclaimOptions extends Omit<ClaimDueOptions, "state" | "states" | "blockMs" | "reclaimExpired" | "reclaimRatio" | "includeState"> {
872
872
  state?: "running";
873
873
  }
874
+ type FlowStateMode = "fifo" | "parallel";
875
+ interface FlowStatePolicy {
876
+ mode?: FlowStateMode;
877
+ retry?: RetryPolicy;
878
+ }
879
+ type FlowStatePolicyLike = FlowStatePolicy | RetryPolicy;
880
+ interface FlowPolicyOptions {
881
+ state?: string;
882
+ mode?: FlowStateMode;
883
+ retry?: RetryPolicy;
884
+ states?: Record<string, FlowStatePolicyLike>;
885
+ retentionTtlMs?: number;
886
+ indexedStateMeta?: string;
887
+ }
888
+ interface RequestContext {
889
+ subject?: string;
890
+ tenant?: string;
891
+ scopes?: string | readonly string[];
892
+ }
893
+ interface RequestContextOptions {
894
+ requestContext?: RequestContext;
895
+ }
896
+ interface InvocationCreateOptions extends RequestContextOptions {
897
+ context?: Record<string, unknown>;
898
+ idempotencyKey?: string;
899
+ }
874
900
  interface MutateOptions {
875
901
  partitionKey?: string;
876
902
  payload?: unknown;
@@ -1063,6 +1089,14 @@ declare class FerricStoreClient {
1063
1089
  namespaceUsage(prefix: string): Promise<Record<string, unknown>>;
1064
1090
  flowQuery(attrs?: ManagementPairs): Promise<unknown[]>;
1065
1091
  flowHistory(id: string, attrs?: ManagementPairs): Promise<unknown[]>;
1092
+ invocationDefinitionPut(definition: Record<string, unknown> | string, options?: RequestContextOptions): Promise<unknown>;
1093
+ invocationDefinitionGet(name: string, options?: RequestContextOptions): Promise<unknown>;
1094
+ invocationDefinitionList(options?: RequestContextOptions): Promise<unknown[]>;
1095
+ invocationCreate(name: string, attrs: Record<string, unknown>, options?: InvocationCreateOptions): Promise<unknown>;
1096
+ invocationGet(id: string, options?: RequestContextOptions): Promise<unknown>;
1097
+ invocationPartitionList(name: string, options?: RequestContextOptions & {
1098
+ scope?: string;
1099
+ }): Promise<unknown[]>;
1066
1100
  create(id: string, options: CreateOptions): Promise<FlowRecord | Buffer | unknown>;
1067
1101
  enqueue(id: string, options: Omit<CreateOptions, "state"> & {
1068
1102
  state?: string;
@@ -1217,12 +1251,7 @@ declare class FerricStoreClient {
1217
1251
  values?: Record<string, unknown>;
1218
1252
  valueRefs?: Record<string, string>;
1219
1253
  }): Promise<unknown>;
1220
- installPolicy(type: string, options?: {
1221
- state?: string;
1222
- retry?: RetryPolicy;
1223
- retentionTtlMs?: number;
1224
- indexedStateMeta?: string;
1225
- }): Promise<unknown>;
1254
+ installPolicy(type: string, options?: FlowPolicyOptions): Promise<unknown>;
1226
1255
  policyGet(type: string, options?: {
1227
1256
  state?: string;
1228
1257
  }): Promise<Record<string, unknown>>;
@@ -1392,6 +1421,7 @@ declare class QueueWorker {
1392
1421
 
1393
1422
  type WorkflowHandler = (ctx: WorkflowContext) => Promise<Outcome | void | unknown> | Outcome | void | unknown;
1394
1423
  interface StateOptions {
1424
+ mode?: FlowStateMode;
1395
1425
  leaseMs?: number;
1396
1426
  claimPayload?: boolean;
1397
1427
  claimRecord?: boolean;
@@ -1420,6 +1450,7 @@ interface StateRegistration {
1420
1450
  exceptionPolicy: ExceptionPolicy;
1421
1451
  handler: WorkflowHandler;
1422
1452
  leaseMs: number;
1453
+ mode?: FlowStateMode;
1423
1454
  name: string;
1424
1455
  returnRecord: boolean;
1425
1456
  retryPolicy?: RetryPolicy;
@@ -1484,6 +1515,7 @@ declare class Workflow {
1484
1515
  worker(options?: WorkerConfig & {
1485
1516
  states?: string[];
1486
1517
  }): WorkflowWorker;
1518
+ installPolicy(options?: Omit<FlowPolicyOptions, "mode" | "state" | "states">): Promise<unknown>;
1487
1519
  stateNames(): string[];
1488
1520
  stateRegistration(name: string): StateRegistration | undefined;
1489
1521
  }
@@ -1560,4 +1592,4 @@ declare class WorkflowWorker {
1560
1592
  private applyHandlerError;
1561
1593
  }
1562
1594
 
1563
- export { type AutoBatchOptions, type BackoffKind, type BackpressurePolicy, BitmapStore, BloomFilterStore, COMMAND_OPCODES, type CancelOptions, type ChildSpec, type ClaimDueOptions, type ClaimedItem, type Codec, type Command, type CommandArgument, type CommandExecutor, type CompleteOptions, type CompleteOutcome, type CountMinMergeOptions, CountMinSketchStore, type CreateItem, type CreateManyOptions, type CreateOptions, CuckooFilterStore, type EndpointPolicy, type ExceptionPolicy, type ExecutePipelineOptions, type FailOptions, type FailOutcome, type FencedItem, FerricStoreClient, type FerricStoreClientFromUrlOptions, type FerricStoreClientOptions, FerricStoreError, type FetchOrComputeResult, FlowAlreadyExistsError, FlowNotFoundError, type FlowRecord, FlowWrongStateError, type GeoAddOptions, type GeoMember, GeoStore, type GetExOptions, HashStore, HyperLogLogStore, InvalidCommandError, JsonCodec, type JsonSetOptions, JsonStore, type KeyInfo, KeyValueStore, ListStore, LockHeldError, LockNotOwnedError, type ManagementPairs, type MutateOptions, type NamedValueMutation, NativeAdapter, type NativeAdapterOptions, type Outcome, OverloadedError, type ProtocolCommand, Queue, type QueueBatchHandler, QueueClient, type QueueHandler, type QueueJob, type QueueOptions, QueueWorker, type QueueWorkerResult, type RangeLimit, type RateLimitResult, RawCodec, type ReadOptions, type ReclaimOptions, type ReconnectOptions, ReconnectingExecutor, type RetryOptions, type RetryOutcome, type RetryPolicy, type RoutingEndpoint, type RoutingRoute, RoutingTopology, type ScanOptions, type SearchOptions, type SearchStateMeta, type SetOptions, SetStore, SortedSetStore, StaleLeaseError, type StateMeta, type StateMetaValue, type StateOptions, type StateRegistration, type StoreCommandClient, StreamStore, type TDigestCreateOptions, type TDigestMergeOptions, TDigestStore, type TopKReserveOptions, TopKStore, TopologyNativeAdapterPool, type TransitionOptions, type TransitionOutcome, type ValueConfig, type WorkerConfig, type WorkerProfile, Workflow, WorkflowClient, WorkflowContext, WorkflowFlowCommands, type WorkflowHandler, type WorkflowOptions, WorkflowWorker, type WorkflowWorkerResult, type XReadStream, type ZAddMember, type ZAddOptions, classifyServerError, complete, fail, isReconnectableClosedConnectionError, mapException, retry, transition };
1595
+ export { type AutoBatchOptions, type BackoffKind, type BackpressurePolicy, BitmapStore, BloomFilterStore, COMMAND_OPCODES, type CancelOptions, type ChildSpec, type ClaimDueOptions, type ClaimedItem, type Codec, type Command, type CommandArgument, type CommandExecutor, type CompleteOptions, type CompleteOutcome, type CountMinMergeOptions, CountMinSketchStore, type CreateItem, type CreateManyOptions, type CreateOptions, CuckooFilterStore, type EndpointPolicy, type ExceptionPolicy, type ExecutePipelineOptions, type FailOptions, type FailOutcome, type FencedItem, FerricStoreClient, type FerricStoreClientFromUrlOptions, type FerricStoreClientOptions, FerricStoreError, type FetchOrComputeResult, FlowAlreadyExistsError, FlowNotFoundError, type FlowPolicyOptions, type FlowRecord, type FlowStateMode, type FlowStatePolicy, type FlowStatePolicyLike, FlowWrongStateError, type GeoAddOptions, type GeoMember, GeoStore, type GetExOptions, HashStore, HyperLogLogStore, InvalidCommandError, type InvocationCreateOptions, JsonCodec, type JsonSetOptions, JsonStore, type KeyInfo, KeyValueStore, ListStore, LockHeldError, LockNotOwnedError, type ManagementPairs, type MutateOptions, type NamedValueMutation, NativeAdapter, type NativeAdapterOptions, type Outcome, OverloadedError, type ProtocolCommand, Queue, type QueueBatchHandler, QueueClient, type QueueHandler, type QueueJob, type QueueOptions, QueueWorker, type QueueWorkerResult, type RangeLimit, type RateLimitResult, RawCodec, type ReadOptions, type ReclaimOptions, type ReconnectOptions, ReconnectingExecutor, type RequestContext, type RequestContextOptions, type RetryOptions, type RetryOutcome, type RetryPolicy, type RoutingEndpoint, type RoutingRoute, RoutingTopology, type ScanOptions, type SearchOptions, type SearchStateMeta, type SetOptions, SetStore, SortedSetStore, StaleLeaseError, type StateMeta, type StateMetaValue, type StateOptions, type StateRegistration, type StoreCommandClient, StreamStore, type TDigestCreateOptions, type TDigestMergeOptions, TDigestStore, type TopKReserveOptions, TopKStore, TopologyNativeAdapterPool, type TransitionOptions, type TransitionOutcome, type ValueConfig, type WorkerConfig, type WorkerProfile, Workflow, WorkflowClient, WorkflowContext, WorkflowFlowCommands, type WorkflowHandler, type WorkflowOptions, WorkflowWorker, type WorkflowWorkerResult, type XReadStream, type ZAddMember, type ZAddOptions, classifyServerError, complete, fail, isReconnectableClosedConnectionError, mapException, retry, transition };
package/dist/index.d.ts CHANGED
@@ -871,6 +871,32 @@ interface ClaimDueOptions {
871
871
  interface ReclaimOptions extends Omit<ClaimDueOptions, "state" | "states" | "blockMs" | "reclaimExpired" | "reclaimRatio" | "includeState"> {
872
872
  state?: "running";
873
873
  }
874
+ type FlowStateMode = "fifo" | "parallel";
875
+ interface FlowStatePolicy {
876
+ mode?: FlowStateMode;
877
+ retry?: RetryPolicy;
878
+ }
879
+ type FlowStatePolicyLike = FlowStatePolicy | RetryPolicy;
880
+ interface FlowPolicyOptions {
881
+ state?: string;
882
+ mode?: FlowStateMode;
883
+ retry?: RetryPolicy;
884
+ states?: Record<string, FlowStatePolicyLike>;
885
+ retentionTtlMs?: number;
886
+ indexedStateMeta?: string;
887
+ }
888
+ interface RequestContext {
889
+ subject?: string;
890
+ tenant?: string;
891
+ scopes?: string | readonly string[];
892
+ }
893
+ interface RequestContextOptions {
894
+ requestContext?: RequestContext;
895
+ }
896
+ interface InvocationCreateOptions extends RequestContextOptions {
897
+ context?: Record<string, unknown>;
898
+ idempotencyKey?: string;
899
+ }
874
900
  interface MutateOptions {
875
901
  partitionKey?: string;
876
902
  payload?: unknown;
@@ -1063,6 +1089,14 @@ declare class FerricStoreClient {
1063
1089
  namespaceUsage(prefix: string): Promise<Record<string, unknown>>;
1064
1090
  flowQuery(attrs?: ManagementPairs): Promise<unknown[]>;
1065
1091
  flowHistory(id: string, attrs?: ManagementPairs): Promise<unknown[]>;
1092
+ invocationDefinitionPut(definition: Record<string, unknown> | string, options?: RequestContextOptions): Promise<unknown>;
1093
+ invocationDefinitionGet(name: string, options?: RequestContextOptions): Promise<unknown>;
1094
+ invocationDefinitionList(options?: RequestContextOptions): Promise<unknown[]>;
1095
+ invocationCreate(name: string, attrs: Record<string, unknown>, options?: InvocationCreateOptions): Promise<unknown>;
1096
+ invocationGet(id: string, options?: RequestContextOptions): Promise<unknown>;
1097
+ invocationPartitionList(name: string, options?: RequestContextOptions & {
1098
+ scope?: string;
1099
+ }): Promise<unknown[]>;
1066
1100
  create(id: string, options: CreateOptions): Promise<FlowRecord | Buffer | unknown>;
1067
1101
  enqueue(id: string, options: Omit<CreateOptions, "state"> & {
1068
1102
  state?: string;
@@ -1217,12 +1251,7 @@ declare class FerricStoreClient {
1217
1251
  values?: Record<string, unknown>;
1218
1252
  valueRefs?: Record<string, string>;
1219
1253
  }): Promise<unknown>;
1220
- installPolicy(type: string, options?: {
1221
- state?: string;
1222
- retry?: RetryPolicy;
1223
- retentionTtlMs?: number;
1224
- indexedStateMeta?: string;
1225
- }): Promise<unknown>;
1254
+ installPolicy(type: string, options?: FlowPolicyOptions): Promise<unknown>;
1226
1255
  policyGet(type: string, options?: {
1227
1256
  state?: string;
1228
1257
  }): Promise<Record<string, unknown>>;
@@ -1392,6 +1421,7 @@ declare class QueueWorker {
1392
1421
 
1393
1422
  type WorkflowHandler = (ctx: WorkflowContext) => Promise<Outcome | void | unknown> | Outcome | void | unknown;
1394
1423
  interface StateOptions {
1424
+ mode?: FlowStateMode;
1395
1425
  leaseMs?: number;
1396
1426
  claimPayload?: boolean;
1397
1427
  claimRecord?: boolean;
@@ -1420,6 +1450,7 @@ interface StateRegistration {
1420
1450
  exceptionPolicy: ExceptionPolicy;
1421
1451
  handler: WorkflowHandler;
1422
1452
  leaseMs: number;
1453
+ mode?: FlowStateMode;
1423
1454
  name: string;
1424
1455
  returnRecord: boolean;
1425
1456
  retryPolicy?: RetryPolicy;
@@ -1484,6 +1515,7 @@ declare class Workflow {
1484
1515
  worker(options?: WorkerConfig & {
1485
1516
  states?: string[];
1486
1517
  }): WorkflowWorker;
1518
+ installPolicy(options?: Omit<FlowPolicyOptions, "mode" | "state" | "states">): Promise<unknown>;
1487
1519
  stateNames(): string[];
1488
1520
  stateRegistration(name: string): StateRegistration | undefined;
1489
1521
  }
@@ -1560,4 +1592,4 @@ declare class WorkflowWorker {
1560
1592
  private applyHandlerError;
1561
1593
  }
1562
1594
 
1563
- export { type AutoBatchOptions, type BackoffKind, type BackpressurePolicy, BitmapStore, BloomFilterStore, COMMAND_OPCODES, type CancelOptions, type ChildSpec, type ClaimDueOptions, type ClaimedItem, type Codec, type Command, type CommandArgument, type CommandExecutor, type CompleteOptions, type CompleteOutcome, type CountMinMergeOptions, CountMinSketchStore, type CreateItem, type CreateManyOptions, type CreateOptions, CuckooFilterStore, type EndpointPolicy, type ExceptionPolicy, type ExecutePipelineOptions, type FailOptions, type FailOutcome, type FencedItem, FerricStoreClient, type FerricStoreClientFromUrlOptions, type FerricStoreClientOptions, FerricStoreError, type FetchOrComputeResult, FlowAlreadyExistsError, FlowNotFoundError, type FlowRecord, FlowWrongStateError, type GeoAddOptions, type GeoMember, GeoStore, type GetExOptions, HashStore, HyperLogLogStore, InvalidCommandError, JsonCodec, type JsonSetOptions, JsonStore, type KeyInfo, KeyValueStore, ListStore, LockHeldError, LockNotOwnedError, type ManagementPairs, type MutateOptions, type NamedValueMutation, NativeAdapter, type NativeAdapterOptions, type Outcome, OverloadedError, type ProtocolCommand, Queue, type QueueBatchHandler, QueueClient, type QueueHandler, type QueueJob, type QueueOptions, QueueWorker, type QueueWorkerResult, type RangeLimit, type RateLimitResult, RawCodec, type ReadOptions, type ReclaimOptions, type ReconnectOptions, ReconnectingExecutor, type RetryOptions, type RetryOutcome, type RetryPolicy, type RoutingEndpoint, type RoutingRoute, RoutingTopology, type ScanOptions, type SearchOptions, type SearchStateMeta, type SetOptions, SetStore, SortedSetStore, StaleLeaseError, type StateMeta, type StateMetaValue, type StateOptions, type StateRegistration, type StoreCommandClient, StreamStore, type TDigestCreateOptions, type TDigestMergeOptions, TDigestStore, type TopKReserveOptions, TopKStore, TopologyNativeAdapterPool, type TransitionOptions, type TransitionOutcome, type ValueConfig, type WorkerConfig, type WorkerProfile, Workflow, WorkflowClient, WorkflowContext, WorkflowFlowCommands, type WorkflowHandler, type WorkflowOptions, WorkflowWorker, type WorkflowWorkerResult, type XReadStream, type ZAddMember, type ZAddOptions, classifyServerError, complete, fail, isReconnectableClosedConnectionError, mapException, retry, transition };
1595
+ export { type AutoBatchOptions, type BackoffKind, type BackpressurePolicy, BitmapStore, BloomFilterStore, COMMAND_OPCODES, type CancelOptions, type ChildSpec, type ClaimDueOptions, type ClaimedItem, type Codec, type Command, type CommandArgument, type CommandExecutor, type CompleteOptions, type CompleteOutcome, type CountMinMergeOptions, CountMinSketchStore, type CreateItem, type CreateManyOptions, type CreateOptions, CuckooFilterStore, type EndpointPolicy, type ExceptionPolicy, type ExecutePipelineOptions, type FailOptions, type FailOutcome, type FencedItem, FerricStoreClient, type FerricStoreClientFromUrlOptions, type FerricStoreClientOptions, FerricStoreError, type FetchOrComputeResult, FlowAlreadyExistsError, FlowNotFoundError, type FlowPolicyOptions, type FlowRecord, type FlowStateMode, type FlowStatePolicy, type FlowStatePolicyLike, FlowWrongStateError, type GeoAddOptions, type GeoMember, GeoStore, type GetExOptions, HashStore, HyperLogLogStore, InvalidCommandError, type InvocationCreateOptions, JsonCodec, type JsonSetOptions, JsonStore, type KeyInfo, KeyValueStore, ListStore, LockHeldError, LockNotOwnedError, type ManagementPairs, type MutateOptions, type NamedValueMutation, NativeAdapter, type NativeAdapterOptions, type Outcome, OverloadedError, type ProtocolCommand, Queue, type QueueBatchHandler, QueueClient, type QueueHandler, type QueueJob, type QueueOptions, QueueWorker, type QueueWorkerResult, type RangeLimit, type RateLimitResult, RawCodec, type ReadOptions, type ReclaimOptions, type ReconnectOptions, ReconnectingExecutor, type RequestContext, type RequestContextOptions, type RetryOptions, type RetryOutcome, type RetryPolicy, type RoutingEndpoint, type RoutingRoute, RoutingTopology, type ScanOptions, type SearchOptions, type SearchStateMeta, type SetOptions, SetStore, SortedSetStore, StaleLeaseError, type StateMeta, type StateMetaValue, type StateOptions, type StateRegistration, type StoreCommandClient, StreamStore, type TDigestCreateOptions, type TDigestMergeOptions, TDigestStore, type TopKReserveOptions, TopKStore, TopologyNativeAdapterPool, type TransitionOptions, type TransitionOutcome, type ValueConfig, type WorkerConfig, type WorkerProfile, Workflow, WorkflowClient, WorkflowContext, WorkflowFlowCommands, type WorkflowHandler, type WorkflowOptions, WorkflowWorker, type WorkflowWorkerResult, type XReadStream, type ZAddMember, type ZAddOptions, classifyServerError, complete, fail, isReconnectableClosedConnectionError, mapException, retry, transition };
package/dist/index.js CHANGED
@@ -492,14 +492,64 @@ function commandExec(args) {
492
492
  if (args.length === 0) {
493
493
  throw new FerricStoreError("command requires at least one argument");
494
494
  }
495
+ const commandArgs = args.slice(1);
496
+ const payload = {
497
+ args: commandArgs,
498
+ command: asText(args[0]).toUpperCase()
499
+ };
500
+ if (commandArgs.length >= 2 && commandTokenIs(commandArgs[commandArgs.length - 2], "REQUEST_CONTEXT")) {
501
+ const requestContext = normalizeRequestContext(commandArgs[commandArgs.length - 1]);
502
+ payload.args = commandArgs.slice(0, -2);
503
+ if (requestContext != null) {
504
+ payload.request_context = requestContext;
505
+ }
506
+ }
495
507
  return {
496
508
  opcode: OPCODES.commandExec,
497
- payload: {
498
- args: args.slice(1),
499
- command: asText(args[0]).toUpperCase()
500
- }
509
+ payload
501
510
  };
502
511
  }
512
+ function normalizeRequestContext(context) {
513
+ if (!isPlainObject(context)) {
514
+ return void 0;
515
+ }
516
+ const out = {};
517
+ const subject = optionalText(context.subject);
518
+ const tenant = optionalText(context.tenant);
519
+ const scopes = normalizeRequestContextScopes(context.scopes);
520
+ if (subject != null) {
521
+ out.subject = subject;
522
+ }
523
+ if (tenant != null) {
524
+ out.tenant = tenant;
525
+ }
526
+ if (scopes.length > 0) {
527
+ out.scopes = scopes;
528
+ }
529
+ return Object.keys(out).length > 0 ? out : void 0;
530
+ }
531
+ function normalizeRequestContextScopes(scopes) {
532
+ const values = typeof scopes === "string" || Buffer2.isBuffer(scopes) || scopes instanceof Uint8Array ? asText(scopes).split(/\s+/u) : Array.isArray(scopes) ? scopes.map((scope) => optionalText(scope)).filter((scope) => scope != null) : [];
533
+ return [...new Set(values.filter((scope) => scope.length > 0))];
534
+ }
535
+ function optionalText(value) {
536
+ if (value == null || value === "") {
537
+ return void 0;
538
+ }
539
+ if (typeof value === "string" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean" || Buffer2.isBuffer(value) || value instanceof Uint8Array) {
540
+ return asText(value);
541
+ }
542
+ return void 0;
543
+ }
544
+ function commandTokenIs(value, expected) {
545
+ if (typeof value === "string") {
546
+ return value.toUpperCase() === expected;
547
+ }
548
+ if (Buffer2.isBuffer(value) || value instanceof Uint8Array) {
549
+ return asText(value).toUpperCase() === expected;
550
+ }
551
+ return false;
552
+ }
503
553
  function pipelineCommand(commands) {
504
554
  const compact = compactPipelinePayload(commands);
505
555
  if (compact != null) {
@@ -4360,6 +4410,59 @@ var FerricStoreClient = class _FerricStoreClient {
4360
4410
  );
4361
4411
  return Array.isArray(response) ? [...response] : [];
4362
4412
  }
4413
+ async invocationDefinitionPut(definition, options = {}) {
4414
+ return normalizeAdminResponse(
4415
+ await this.command(
4416
+ ...commandWithRequestContext(
4417
+ "INVOCATION.DEFINITION.PUT",
4418
+ [jsonArg(definition)],
4419
+ options.requestContext
4420
+ )
4421
+ )
4422
+ );
4423
+ }
4424
+ async invocationDefinitionGet(name, options = {}) {
4425
+ return normalizeAdminResponse(
4426
+ await this.command(
4427
+ ...commandWithRequestContext("INVOCATION.DEFINITION.GET", [name], options.requestContext)
4428
+ )
4429
+ );
4430
+ }
4431
+ async invocationDefinitionList(options = {}) {
4432
+ const response = normalizeAdminResponse(
4433
+ await this.command(
4434
+ ...commandWithRequestContext("INVOCATION.DEFINITION.LIST", [], options.requestContext)
4435
+ )
4436
+ );
4437
+ return Array.isArray(response) ? [...response] : [];
4438
+ }
4439
+ async invocationCreate(name, attrs, options = {}) {
4440
+ const envelope = { attrs };
4441
+ if (options.context != null) {
4442
+ envelope.context = options.context;
4443
+ }
4444
+ if (options.idempotencyKey != null) {
4445
+ envelope.idempotency_key = options.idempotencyKey;
4446
+ }
4447
+ return normalizeAdminResponse(
4448
+ await this.command(
4449
+ ...commandWithRequestContext("INVOCATION.CREATE", [name, jsonArg(envelope)], options.requestContext)
4450
+ )
4451
+ );
4452
+ }
4453
+ async invocationGet(id, options = {}) {
4454
+ return normalizeAdminResponse(
4455
+ await this.command(...commandWithRequestContext("INVOCATION.GET", [id], options.requestContext))
4456
+ );
4457
+ }
4458
+ async invocationPartitionList(name, options = {}) {
4459
+ const args = [name];
4460
+ append(args, "SCOPE", options.scope);
4461
+ const response = normalizeAdminResponse(
4462
+ await this.command(...commandWithRequestContext("INVOCATION.PARTITION.LIST", args, options.requestContext))
4463
+ );
4464
+ return Array.isArray(response) ? [...response] : [];
4465
+ }
4363
4466
  async create(id, options) {
4364
4467
  const currentNowMs = options.nowMs ?? nowMs();
4365
4468
  const args = [
@@ -4392,7 +4495,6 @@ var FerricStoreClient = class _FerricStoreClient {
4392
4495
  async enqueue(id, options) {
4393
4496
  return await this.create(id, {
4394
4497
  ...options,
4395
- priority: options.priority ?? 0,
4396
4498
  state: options.state ?? "queued"
4397
4499
  });
4398
4500
  }
@@ -4404,7 +4506,6 @@ var FerricStoreClient = class _FerricStoreClient {
4404
4506
  return await this.createMany(options.partitionKey, items, {
4405
4507
  ...options,
4406
4508
  independent: options.independent ?? true,
4407
- priority: options.priority ?? 0,
4408
4509
  state: options.state ?? "queued"
4409
4510
  });
4410
4511
  }
@@ -4419,7 +4520,6 @@ var FerricStoreClient = class _FerricStoreClient {
4419
4520
  const response = await this.createMany(bucket, groupItems, {
4420
4521
  ...options,
4421
4522
  independent: options.independent ?? true,
4422
- priority: options.priority ?? 0,
4423
4523
  state: options.state ?? "queued"
4424
4524
  });
4425
4525
  const expanded = expandManyResponse(response, indexedItems.length);
@@ -4572,8 +4672,7 @@ var FerricStoreClient = class _FerricStoreClient {
4572
4672
  ...options,
4573
4673
  includeState: options.includeState ?? false,
4574
4674
  jobOnly: true,
4575
- limit: options.limit ?? 100,
4576
- priority: options.priority ?? 0
4675
+ limit: options.limit ?? 100
4577
4676
  });
4578
4677
  }
4579
4678
  async reclaim(type, options) {
@@ -4924,9 +5023,14 @@ var FerricStoreClient = class _FerricStoreClient {
4924
5023
  const args = ["FLOW.POLICY.SET", type];
4925
5024
  append(args, "INDEXED_STATE_META", options.indexedStateMeta);
4926
5025
  append(args, "STATE", options.state);
5026
+ appendPolicyMode(args, options.state, options.mode);
4927
5027
  if (options.retry != null) {
4928
5028
  appendRetryPolicy(args, options.retry);
4929
5029
  }
5030
+ for (const [state, policy] of Object.entries(options.states ?? {})) {
5031
+ args.push("STATE", state);
5032
+ appendFlowStatePolicy(args, policy);
5033
+ }
4930
5034
  append(args, "RETENTION_TTL_MS", options.retentionTtlMs);
4931
5035
  return await this.command(...args);
4932
5036
  }
@@ -5306,6 +5410,16 @@ function appendSearchStateMeta(args, state, stateMeta) {
5306
5410
  function normalizeAdminResponse(value) {
5307
5411
  return normalizeRefMeta(value);
5308
5412
  }
5413
+ function jsonArg(value) {
5414
+ return typeof value === "string" ? value : JSON.stringify(value);
5415
+ }
5416
+ function commandWithRequestContext(command, args, requestContext) {
5417
+ const commandArgs = [command, ...args];
5418
+ if (requestContext != null) {
5419
+ commandArgs.push("REQUEST_CONTEXT", requestContext);
5420
+ }
5421
+ return commandArgs;
5422
+ }
5309
5423
  function infoText(value) {
5310
5424
  if (typeof value === "string" || Buffer.isBuffer(value)) {
5311
5425
  return text(value);
@@ -5337,6 +5451,19 @@ function managementPairArgs(pairs2) {
5337
5451
  }
5338
5452
  return args;
5339
5453
  }
5454
+ function appendFlowStatePolicy(args, policy) {
5455
+ if (isFlowStatePolicy(policy)) {
5456
+ appendPolicyMode(args, "state", policy.mode);
5457
+ if (policy.retry != null) {
5458
+ appendRetryPolicy(args, policy.retry);
5459
+ }
5460
+ return;
5461
+ }
5462
+ appendRetryPolicy(args, policy);
5463
+ }
5464
+ function isFlowStatePolicy(policy) {
5465
+ return typeof policy === "object" && policy != null && ("mode" in policy || "retry" in policy);
5466
+ }
5340
5467
  function ruleArgs(rules) {
5341
5468
  return typeof rules === "string" ? [rules] : [...rules];
5342
5469
  }
@@ -5429,6 +5556,24 @@ function appendRetryPolicy(args, policy) {
5429
5556
  append(args, "JITTER_PCT", policy.jitterPct);
5430
5557
  append(args, "EXHAUSTED_TO", policy.exhaustedTo);
5431
5558
  }
5559
+ function appendPolicyMode(args, state, mode) {
5560
+ if (mode == null) {
5561
+ return;
5562
+ }
5563
+ if (state == null) {
5564
+ throw new Error("policy mode requires state");
5565
+ }
5566
+ switch (mode) {
5567
+ case "fifo":
5568
+ args.push("MODE", "FIFO");
5569
+ return;
5570
+ case "parallel":
5571
+ args.push("MODE", "PARALLEL");
5572
+ return;
5573
+ default:
5574
+ throw new Error("policy mode must be 'fifo' or 'parallel'");
5575
+ }
5576
+ }
5432
5577
  function appendPayloadRead(args, payload, maxBytes) {
5433
5578
  if (payload === false) {
5434
5579
  args.push("NOPAYLOAD");
@@ -5893,6 +6038,7 @@ var Workflow = class {
5893
6038
  exceptionPolicy: normalizeExceptionPolicy(options.exceptionPolicy),
5894
6039
  handler,
5895
6040
  leaseMs: options.leaseMs ?? 3e4,
6041
+ ...options.mode == null ? {} : { mode: normalizeStateMode(options.mode) },
5896
6042
  name,
5897
6043
  returnRecord: options.returnRecord ?? false,
5898
6044
  valueMaxBytes: options.valueMaxBytes ?? this.valueConfig.valueMaxBytes,
@@ -5927,6 +6073,21 @@ var Workflow = class {
5927
6073
  worker(options = {}) {
5928
6074
  return new WorkflowWorker(this, options);
5929
6075
  }
6076
+ async installPolicy(options = {}) {
6077
+ const states = {};
6078
+ for (const registration of this.states.values()) {
6079
+ if (registration.mode != null || registration.retryPolicy != null) {
6080
+ states[registration.name] = {
6081
+ ...registration.mode == null ? {} : { mode: registration.mode },
6082
+ ...registration.retryPolicy == null ? {} : { retry: registration.retryPolicy }
6083
+ };
6084
+ }
6085
+ }
6086
+ return await this.client.installPolicy(this.type, {
6087
+ ...options,
6088
+ states
6089
+ });
6090
+ }
5930
6091
  stateNames() {
5931
6092
  return [...this.states.keys()];
5932
6093
  }
@@ -6187,13 +6348,15 @@ var WorkflowWorker = class {
6187
6348
  }
6188
6349
  async applyJob(job, registration) {
6189
6350
  const ctx = new WorkflowContext(this.workflow, job, registration.name);
6351
+ let outcome;
6190
6352
  try {
6191
6353
  const value = await registration.handler(ctx);
6192
- const outcome = isOutcome(value) ? value : complete({ result: value });
6193
- await applyOutcome(this.workflow.client, ctx, outcome, registration.returnRecord);
6354
+ outcome = isOutcome(value) ? value : complete({ result: value });
6194
6355
  } catch (error) {
6195
6356
  await this.applyHandlerError(ctx, registration, error);
6357
+ return;
6196
6358
  }
6359
+ await applyOutcome(this.workflow.client, ctx, outcome, registration.returnRecord);
6197
6360
  }
6198
6361
  async applyHandlerError(ctx, registration, error) {
6199
6362
  const policy = this.options.exceptionPolicy ?? registration.exceptionPolicy;
@@ -6224,6 +6387,7 @@ async function applyOutcome(client, ctx, outcome, returnRecord) {
6224
6387
  }
6225
6388
  }
6226
6389
  async function applyTransition(client, ctx, outcome, returnRecord) {
6390
+ validateTransitionPolicy(ctx, outcome);
6227
6391
  await client.transition(ctx.id, {
6228
6392
  dropValues: outcome.dropValues,
6229
6393
  fencingToken: ctx.fencingToken,
@@ -6241,6 +6405,12 @@ async function applyTransition(client, ctx, outcome, returnRecord) {
6241
6405
  values: outcome.values
6242
6406
  });
6243
6407
  }
6408
+ function validateTransitionPolicy(ctx, outcome) {
6409
+ const target = ctx.workflow.stateRegistration(outcome.toState);
6410
+ if (target?.mode === "fifo" && outcome.priority != null) {
6411
+ throw new Error("priority is not supported for fifo state");
6412
+ }
6413
+ }
6244
6414
  async function applyComplete(client, ctx, outcome, returnRecord) {
6245
6415
  await client.complete(ctx.id, {
6246
6416
  dropValues: outcome.dropValues,
@@ -6299,6 +6469,12 @@ function errorToPayload(error) {
6299
6469
  }
6300
6470
  return error;
6301
6471
  }
6472
+ function normalizeStateMode(mode) {
6473
+ if (mode === "fifo" || mode === "parallel") {
6474
+ return mode;
6475
+ }
6476
+ throw new Error("state mode must be 'fifo' or 'parallel'");
6477
+ }
6302
6478
  function valueRefToString(value) {
6303
6479
  if (typeof value === "string") {
6304
6480
  return value;