@sanity/workflow-engine 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1943,6 +1943,17 @@ declare const AuthoringStageSchema: v.StrictObjectSchema<
1943
1943
  v.StringSchema<undefined>,
1944
1944
  undefined
1945
1945
  >;
1946
+ /**
1947
+ * When true, the caller MUST supply this entry at start (via
1948
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
1949
+ * missing required entry throws rather than silently defaulting to
1950
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
1951
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
1952
+ */
1953
+ readonly required: v.OptionalSchema<
1954
+ v.BooleanSchema<undefined>,
1955
+ undefined
1956
+ >;
1946
1957
  readonly source: v.GenericSchema<SourceInternal>;
1947
1958
  },
1948
1959
  undefined
@@ -2492,6 +2503,17 @@ declare const AuthoringStageSchema: v.StrictObjectSchema<
2492
2503
  v.StringSchema<undefined>,
2493
2504
  undefined
2494
2505
  >;
2506
+ /**
2507
+ * When true, the caller MUST supply this entry at start (via
2508
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
2509
+ * missing required entry throws rather than silently defaulting to
2510
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
2511
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
2512
+ */
2513
+ readonly required: v.OptionalSchema<
2514
+ v.BooleanSchema<undefined>,
2515
+ undefined
2516
+ >;
2495
2517
  readonly source: v.GenericSchema<SourceInternal>;
2496
2518
  },
2497
2519
  undefined
@@ -2561,6 +2583,17 @@ declare const AuthoringStateEntrySchema: v.UnionSchema<
2561
2583
  v.StringSchema<undefined>,
2562
2584
  undefined
2563
2585
  >;
2586
+ /**
2587
+ * When true, the caller MUST supply this entry at start (via
2588
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
2589
+ * missing required entry throws rather than silently defaulting to
2590
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
2591
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
2592
+ */
2593
+ readonly required: v.OptionalSchema<
2594
+ v.BooleanSchema<undefined>,
2595
+ undefined
2596
+ >;
2564
2597
  readonly source: v.GenericSchema<SourceInternal>;
2565
2598
  },
2566
2599
  undefined
@@ -3705,6 +3738,17 @@ declare const AuthoringTaskSchema: v.StrictObjectSchema<
3705
3738
  v.StringSchema<undefined>,
3706
3739
  undefined
3707
3740
  >;
3741
+ /**
3742
+ * When true, the caller MUST supply this entry at start (via
3743
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
3744
+ * missing required entry throws rather than silently defaulting to
3745
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
3746
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
3747
+ */
3748
+ readonly required: v.OptionalSchema<
3749
+ v.BooleanSchema<undefined>,
3750
+ undefined
3751
+ >;
3708
3752
  readonly source: v.GenericSchema<SourceInternal>;
3709
3753
  },
3710
3754
  undefined
@@ -4069,6 +4113,22 @@ declare const AuthoringWorkflowSchema: v.StrictObjectSchema<
4069
4113
  ]
4070
4114
  >;
4071
4115
  description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
4116
+ /**
4117
+ * Whether a human may start this workflow standalone. `'child'` marks a
4118
+ * spawn-only definition — instantiated by a parent via `task.subworkflows`,
4119
+ * never started cold from a picker. Omitted ⇒ `'workflow'` (startable).
4120
+ * Advisory: consumers filter their start pickers on it (see
4121
+ * {@link isStartableDefinition}); the engine does NOT refuse a
4122
+ * `startInstance` on a `'child'` def — load-bearing `required` state is the
4123
+ * runtime backstop.
4124
+ */
4125
+ role: v.OptionalSchema<
4126
+ v.PicklistSchema<
4127
+ readonly ["workflow", "child"],
4128
+ `Invalid option: expected one of ${string}`
4129
+ >,
4130
+ undefined
4131
+ >;
4072
4132
  /** Reference field: named for the target, holds the stage's `name`. */
4073
4133
  initialStage: v.SchemaWithPipe<
4074
4134
  readonly [
@@ -4115,6 +4175,17 @@ declare const AuthoringWorkflowSchema: v.StrictObjectSchema<
4115
4175
  v.StringSchema<undefined>,
4116
4176
  undefined
4117
4177
  >;
4178
+ /**
4179
+ * When true, the caller MUST supply this entry at start (via
4180
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
4181
+ * missing required entry throws rather than silently defaulting to
4182
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
4183
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
4184
+ */
4185
+ readonly required: v.OptionalSchema<
4186
+ v.BooleanSchema<undefined>,
4187
+ undefined
4188
+ >;
4118
4189
  readonly source: v.GenericSchema<SourceInternal>;
4119
4190
  },
4120
4191
  undefined
@@ -5443,6 +5514,17 @@ declare const AuthoringWorkflowSchema: v.StrictObjectSchema<
5443
5514
  v.StringSchema<undefined>,
5444
5515
  undefined
5445
5516
  >;
5517
+ /**
5518
+ * When true, the caller MUST supply this entry at start (via
5519
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
5520
+ * missing required entry throws rather than silently defaulting to
5521
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
5522
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
5523
+ */
5524
+ readonly required: v.OptionalSchema<
5525
+ v.BooleanSchema<undefined>,
5526
+ undefined
5527
+ >;
5446
5528
  readonly source: v.GenericSchema<SourceInternal>;
5447
5529
  },
5448
5530
  undefined
@@ -6055,6 +6137,17 @@ declare const AuthoringWorkflowSchema: v.StrictObjectSchema<
6055
6137
  v.StringSchema<undefined>,
6056
6138
  undefined
6057
6139
  >;
6140
+ /**
6141
+ * When true, the caller MUST supply this entry at start (via
6142
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
6143
+ * missing required entry throws rather than silently defaulting to
6144
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
6145
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
6146
+ */
6147
+ readonly required: v.OptionalSchema<
6148
+ v.BooleanSchema<undefined>,
6149
+ undefined
6150
+ >;
6058
6151
  readonly source: v.GenericSchema<SourceInternal>;
6059
6152
  },
6060
6153
  undefined
@@ -6426,6 +6519,7 @@ declare const AuthoringWorkflowSchema: v.StrictObjectSchema<
6426
6519
  name: string;
6427
6520
  title?: string | undefined;
6428
6521
  description?: string | undefined;
6522
+ required?: boolean | undefined;
6429
6523
  source: SourceInternal;
6430
6524
  }
6431
6525
  | {
@@ -6567,6 +6661,7 @@ declare const AuthoringWorkflowSchema: v.StrictObjectSchema<
6567
6661
  name: string;
6568
6662
  title?: string | undefined;
6569
6663
  description?: string | undefined;
6664
+ required?: boolean | undefined;
6570
6665
  source: SourceInternal;
6571
6666
  }
6572
6667
  | {
@@ -8261,6 +8356,18 @@ export declare function isDefinitionUnchanged(
8261
8356
  /** Type filter for GDR shape. */
8262
8357
  export declare function isGdr(value: unknown): value is GlobalDocumentReference;
8263
8358
 
8359
+ /**
8360
+ * Whether a human may start this definition standalone (the default). A
8361
+ * `role: 'child'` definition is spawn-only — instantiated by a parent via
8362
+ * `task.subworkflows`, so consumers exclude it from top-level start pickers.
8363
+ * Advisory: the engine does not enforce it (see the `required`-state backstop
8364
+ * for load-bearing init slots). Accepts any definition-shaped value (authored,
8365
+ * stored, deployed, or a projected list row).
8366
+ */
8367
+ export declare function isStartableDefinition(definition: {
8368
+ role?: WorkflowRole | undefined;
8369
+ }): boolean;
8370
+
8264
8371
  /**
8265
8372
  * A stage with no transitions out IS terminal — structural, not declared.
8266
8373
  * Reaching one completes the instance.
@@ -8546,6 +8653,20 @@ export declare interface ParsedGdr {
8546
8653
  */
8547
8654
  export declare function parseGdr(uri: string): ParsedGdr;
8548
8655
 
8656
+ /**
8657
+ * A stage's multi-guard deploy failed *after* at least one guard already landed.
8658
+ * Those partial locks can't be cleanly undone (guard docs have no transactional
8659
+ * deploy). Inside the engine {@link deployOrRollback} rolls the state move back
8660
+ * and escalates this to a loud {@link WorkflowStateDivergedError}; a caller that
8661
+ * invokes {@link deployStageGuards} directly (without that rollback wrapper) can
8662
+ * also see it, so it's exported to be catchable by type.
8663
+ */
8664
+ export declare class PartialGuardDeployError extends Error {
8665
+ readonly stageName: string;
8666
+ readonly deployed: number;
8667
+ constructor(args: { stageName: string; deployed: number; cause: unknown });
8668
+ }
8669
+
8549
8670
  export declare interface PendingEffect {
8550
8671
  _key: string;
8551
8672
  _type?: "pendingEffect";
@@ -8670,6 +8791,28 @@ export declare type RemediationVerb =
8670
8791
  | "set-stage"
8671
8792
  | "abort";
8672
8793
 
8794
+ /**
8795
+ * Thrown when a workflow is started (or a child spawned) without a value for
8796
+ * a state entry marked `required`. Mirrors {@link ActionParamsInvalidError}:
8797
+ * the engine has NOT created the instance — a missing load-bearing slot
8798
+ * (e.g. the subject of a review) screams here rather than silently defaulting
8799
+ * to `null`/`[]` and birthing a half-formed instance mid-process.
8800
+ */
8801
+ export declare class RequiredStateNotProvidedError extends Error {
8802
+ readonly definition?: string;
8803
+ readonly missing: {
8804
+ name: string;
8805
+ type: string;
8806
+ }[];
8807
+ constructor(args: {
8808
+ definition?: string;
8809
+ missing: {
8810
+ name: string;
8811
+ type: string;
8812
+ }[];
8813
+ });
8814
+ }
8815
+
8673
8816
  /**
8674
8817
  * Resolve the engine's `WorkflowAccess` for a client. Override wins
8675
8818
  * outright; otherwise both halves are fetched in parallel and
@@ -9028,6 +9171,14 @@ declare const StateEntrySchema: v.StrictObjectSchema<
9028
9171
  v.StringSchema<undefined>,
9029
9172
  undefined
9030
9173
  >;
9174
+ /**
9175
+ * When true, the caller MUST supply this entry at start (via
9176
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
9177
+ * missing required entry throws rather than silently defaulting to
9178
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
9179
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
9180
+ */
9181
+ readonly required: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
9031
9182
  readonly source: v.GenericSchema<SourceInternal>;
9032
9183
  },
9033
9184
  undefined
@@ -10273,6 +10424,17 @@ declare const StoredStageSchema: v.StrictObjectSchema<
10273
10424
  v.StringSchema<undefined>,
10274
10425
  undefined
10275
10426
  >;
10427
+ /**
10428
+ * When true, the caller MUST supply this entry at start (via
10429
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
10430
+ * missing required entry throws rather than silently defaulting to
10431
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
10432
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
10433
+ */
10434
+ readonly required: v.OptionalSchema<
10435
+ v.BooleanSchema<undefined>,
10436
+ undefined
10437
+ >;
10276
10438
  readonly source: v.GenericSchema<SourceInternal>;
10277
10439
  },
10278
10440
  undefined
@@ -10716,6 +10878,17 @@ declare const StoredStageSchema: v.StrictObjectSchema<
10716
10878
  v.StringSchema<undefined>,
10717
10879
  undefined
10718
10880
  >;
10881
+ /**
10882
+ * When true, the caller MUST supply this entry at start (via
10883
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
10884
+ * missing required entry throws rather than silently defaulting to
10885
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
10886
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
10887
+ */
10888
+ readonly required: v.OptionalSchema<
10889
+ v.BooleanSchema<undefined>,
10890
+ undefined
10891
+ >;
10719
10892
  readonly source: v.GenericSchema<SourceInternal>;
10720
10893
  },
10721
10894
  undefined
@@ -11470,6 +11643,17 @@ declare const StoredTaskSchema: v.StrictObjectSchema<
11470
11643
  v.StringSchema<undefined>,
11471
11644
  undefined
11472
11645
  >;
11646
+ /**
11647
+ * When true, the caller MUST supply this entry at start (via
11648
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
11649
+ * missing required entry throws rather than silently defaulting to
11650
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
11651
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
11652
+ */
11653
+ readonly required: v.OptionalSchema<
11654
+ v.BooleanSchema<undefined>,
11655
+ undefined
11656
+ >;
11473
11657
  readonly source: v.GenericSchema<SourceInternal>;
11474
11658
  },
11475
11659
  undefined
@@ -12444,6 +12628,8 @@ export declare const WORKFLOW_DEFINITION_TYPE = "sanity.workflow.definition";
12444
12628
  */
12445
12629
  export declare const WORKFLOW_INSTANCE_TYPE = "sanity.workflow.instance";
12446
12630
 
12631
+ declare const WORKFLOW_ROLES: readonly ["workflow", "child"];
12632
+
12447
12633
  /**
12448
12634
  * The engine's view of "who am I, what can I do?". `actor` is who
12449
12635
  * the engine stamps onto history / `completedBy` / `Source.actor`.
@@ -12604,6 +12790,22 @@ declare const WorkflowDefinitionSchema: v.StrictObjectSchema<
12604
12790
  ]
12605
12791
  >;
12606
12792
  description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
12793
+ /**
12794
+ * Whether a human may start this workflow standalone. `'child'` marks a
12795
+ * spawn-only definition — instantiated by a parent via `task.subworkflows`,
12796
+ * never started cold from a picker. Omitted ⇒ `'workflow'` (startable).
12797
+ * Advisory: consumers filter their start pickers on it (see
12798
+ * {@link isStartableDefinition}); the engine does NOT refuse a
12799
+ * `startInstance` on a `'child'` def — load-bearing `required` state is the
12800
+ * runtime backstop.
12801
+ */
12802
+ role: v.OptionalSchema<
12803
+ v.PicklistSchema<
12804
+ readonly ["workflow", "child"],
12805
+ `Invalid option: expected one of ${string}`
12806
+ >,
12807
+ undefined
12808
+ >;
12607
12809
  /** Reference field: named for the target, holds the stage's `name`. */
12608
12810
  initialStage: v.SchemaWithPipe<
12609
12811
  readonly [
@@ -12648,6 +12850,17 @@ declare const WorkflowDefinitionSchema: v.StrictObjectSchema<
12648
12850
  v.StringSchema<undefined>,
12649
12851
  undefined
12650
12852
  >;
12853
+ /**
12854
+ * When true, the caller MUST supply this entry at start (via
12855
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
12856
+ * missing required entry throws rather than silently defaulting to
12857
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
12858
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
12859
+ */
12860
+ readonly required: v.OptionalSchema<
12861
+ v.BooleanSchema<undefined>,
12862
+ undefined
12863
+ >;
12651
12864
  readonly source: v.GenericSchema<SourceInternal>;
12652
12865
  },
12653
12866
  undefined
@@ -13532,6 +13745,17 @@ declare const WorkflowDefinitionSchema: v.StrictObjectSchema<
13532
13745
  v.StringSchema<undefined>,
13533
13746
  undefined
13534
13747
  >;
13748
+ /**
13749
+ * When true, the caller MUST supply this entry at start (via
13750
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
13751
+ * missing required entry throws rather than silently defaulting to
13752
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
13753
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
13754
+ */
13755
+ readonly required: v.OptionalSchema<
13756
+ v.BooleanSchema<undefined>,
13757
+ undefined
13758
+ >;
13535
13759
  readonly source: v.GenericSchema<SourceInternal>;
13536
13760
  },
13537
13761
  undefined
@@ -14008,6 +14232,17 @@ declare const WorkflowDefinitionSchema: v.StrictObjectSchema<
14008
14232
  v.StringSchema<undefined>,
14009
14233
  undefined
14010
14234
  >;
14235
+ /**
14236
+ * When true, the caller MUST supply this entry at start (via
14237
+ * `initialState`) or spawn (via the parent's `subworkflows.with`). A
14238
+ * missing required entry throws rather than silently defaulting to
14239
+ * `null`/`[]` — the same fail-fast an action's `required` param gets.
14240
+ * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
14241
+ */
14242
+ readonly required: v.OptionalSchema<
14243
+ v.BooleanSchema<undefined>,
14244
+ undefined
14245
+ >;
14011
14246
  readonly source: v.GenericSchema<SourceInternal>;
14012
14247
  },
14013
14248
  undefined
@@ -14246,6 +14481,7 @@ declare const WorkflowDefinitionSchema: v.StrictObjectSchema<
14246
14481
  name: string;
14247
14482
  title?: string | undefined;
14248
14483
  description?: string | undefined;
14484
+ required?: boolean | undefined;
14249
14485
  source: SourceInternal;
14250
14486
  }[]
14251
14487
  | undefined;
@@ -14365,6 +14601,7 @@ declare const WorkflowDefinitionSchema: v.StrictObjectSchema<
14365
14601
  name: string;
14366
14602
  title?: string | undefined;
14367
14603
  description?: string | undefined;
14604
+ required?: boolean | undefined;
14368
14605
  source: SourceInternal;
14369
14606
  }[]
14370
14607
  | undefined;
@@ -14561,13 +14798,18 @@ export declare type WorkflowResource =
14561
14798
  id: string;
14562
14799
  };
14563
14800
 
14801
+ /** A definition's lifecycle role. `'child'` is spawn-only — see {@link isStartableDefinition}. */
14802
+ export declare type WorkflowRole = (typeof WORKFLOW_ROLES)[number];
14803
+
14564
14804
  /**
14565
14805
  * Thrown when a guard deploy fails *after* its state move committed and the
14566
- * engine could not restore the instance to its pre-move state either the
14567
- * rollback write itself failed, or the move created sibling docs (spawn) that a
14568
- * parent-only rollback cannot undo. The workflow's persisted state and its
14569
- * deployed guards are now divergent and need manual reconciliation; the engine
14570
- * screams rather than leaving the inconsistency silent.
14806
+ * engine could not cleanly undo the result any of: the rollback write itself
14807
+ * failed; the move created sibling docs (spawn) that a parent-only rollback
14808
+ * cannot undo; or a multi-guard deploy partially applied, so even a clean state
14809
+ * rollback leaves the earlier guards orphaned ({@link PartialGuardDeployError}).
14810
+ * The workflow's persisted state and its deployed guards are now divergent and
14811
+ * need manual reconciliation; the engine screams rather than leaving the
14812
+ * inconsistency silent.
14571
14813
  */
14572
14814
  export declare class WorkflowStateDivergedError extends Error {
14573
14815
  readonly instanceId: string;