@sanity/workflow-engine 0.17.0 → 0.19.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/define.cjs CHANGED
@@ -17,11 +17,16 @@ function defineWorkflow(definition) {
17
17
  }
18
18
 
19
19
  function defineWorkflowConfig(config) {
20
- return invariants.parseOrThrow({
20
+ const parsed = invariants.parseOrThrow({
21
21
  schema: invariants.WorkflowConfigSchema,
22
22
  input: config,
23
23
  label: "defineWorkflowConfig"
24
24
  });
25
+ return assertDeploymentAcknowledgements(parsed), parsed;
26
+ }
27
+
28
+ function assertDeploymentAcknowledgements(config) {
29
+ for (const [index, deployment] of config.deployments.entries()) invariants.assertReaderModelAcknowledgement(deployment.expectedMinReaderModel, `Deployment ${deployment.name || `at deployments[${index}]`}`);
25
30
  }
26
31
 
27
32
  function defineStage(stage) {
package/dist/define.d.cts CHANGED
@@ -4,10 +4,16 @@ declare type Action = ActionFields<Op, string[]> & {
4
4
  roles?: string[] | undefined;
5
5
  };
6
6
 
7
+ declare const ACTION_SEMANTICS: readonly [
8
+ "decision.accept",
9
+ "decision.decline",
10
+ ];
11
+
7
12
  /** Type-mirror of {@link actionFields}, parameterised over the op and
8
13
  * group-membership grammars. */
9
14
  declare type ActionFields<TOp, TGroup> = {
10
15
  name: string;
16
+ semantics?: ActionSemantic[] | undefined;
11
17
  title?: string | undefined;
12
18
  description?: string | undefined;
13
19
  group?: TGroup | undefined;
@@ -27,38 +33,135 @@ declare type ActionParam = v.InferOutput<typeof ActionParamSchema>;
27
33
  * effects: missing required params → ActionParamsInvalidError, action
28
34
  * does not commit. Resolved values feed `ValueExpr.param` lookups.
29
35
  */
30
- declare const ActionParamSchema: v.StrictObjectSchema<
31
- {
32
- readonly type: v.PicklistSchema<
33
- readonly [
34
- "string",
35
- "number",
36
- "boolean",
37
- "url",
38
- "dateTime",
39
- "actor",
40
- "doc.ref",
41
- "doc.refs",
42
- "json",
43
- ],
44
- `Invalid option: expected one of ${string}`
45
- >;
46
- readonly name: v.SchemaWithPipe<
47
- readonly [
48
- v.StringSchema<undefined>,
49
- v.MinLengthAction<string, 1, "must be a non-empty string">,
50
- ]
51
- >;
52
- readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
53
- readonly description: v.OptionalSchema<
54
- v.StringSchema<undefined>,
36
+ declare const ActionParamSchema: v.SchemaWithPipe<
37
+ readonly [
38
+ v.StrictObjectSchema<
39
+ {
40
+ readonly type: v.PicklistSchema<
41
+ readonly [
42
+ "string",
43
+ "number",
44
+ "boolean",
45
+ "url",
46
+ "dateTime",
47
+ "actor",
48
+ "doc.ref",
49
+ "doc.refs",
50
+ "json",
51
+ ],
52
+ `Invalid option: expected one of ${string}`
53
+ >;
54
+ readonly name: v.SchemaWithPipe<
55
+ readonly [
56
+ v.StringSchema<undefined>,
57
+ v.MinLengthAction<string, 1, "must be a non-empty string">,
58
+ ]
59
+ >;
60
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
61
+ readonly description: v.OptionalSchema<
62
+ v.StringSchema<undefined>,
63
+ undefined
64
+ >;
65
+ readonly required: v.OptionalSchema<
66
+ v.BooleanSchema<undefined>,
67
+ undefined
68
+ >;
69
+ readonly options: v.OptionalSchema<
70
+ v.GenericSchema<ChoiceOptions>,
71
+ undefined
72
+ >;
73
+ readonly validation: v.OptionalSchema<
74
+ v.GenericSchema<ScalarValidation>,
75
+ undefined
76
+ >;
77
+ },
55
78
  undefined
56
- >;
57
- readonly required: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
58
- },
59
- undefined
79
+ >,
80
+ v.CheckAction<
81
+ {
82
+ type:
83
+ | "string"
84
+ | "number"
85
+ | "boolean"
86
+ | "doc.ref"
87
+ | "doc.refs"
88
+ | "url"
89
+ | "actor"
90
+ | "dateTime"
91
+ | "json";
92
+ name: string;
93
+ title?: string | undefined;
94
+ description?: string | undefined;
95
+ required?: boolean | undefined;
96
+ options?: ChoiceOptions | undefined;
97
+ validation?: ScalarValidation | undefined;
98
+ },
99
+ (
100
+ issue: v.CheckIssue<{
101
+ type:
102
+ | "string"
103
+ | "number"
104
+ | "boolean"
105
+ | "doc.ref"
106
+ | "doc.refs"
107
+ | "url"
108
+ | "actor"
109
+ | "dateTime"
110
+ | "json";
111
+ name: string;
112
+ title?: string | undefined;
113
+ description?: string | undefined;
114
+ required?: boolean | undefined;
115
+ options?: ChoiceOptions | undefined;
116
+ validation?: ScalarValidation | undefined;
117
+ }>,
118
+ ) => string
119
+ >,
120
+ v.CheckAction<
121
+ {
122
+ type:
123
+ | "string"
124
+ | "number"
125
+ | "boolean"
126
+ | "doc.ref"
127
+ | "doc.refs"
128
+ | "url"
129
+ | "actor"
130
+ | "dateTime"
131
+ | "json";
132
+ name: string;
133
+ title?: string | undefined;
134
+ description?: string | undefined;
135
+ required?: boolean | undefined;
136
+ options?: ChoiceOptions | undefined;
137
+ validation?: ScalarValidation | undefined;
138
+ },
139
+ (
140
+ issue: v.CheckIssue<{
141
+ type:
142
+ | "string"
143
+ | "number"
144
+ | "boolean"
145
+ | "doc.ref"
146
+ | "doc.refs"
147
+ | "url"
148
+ | "actor"
149
+ | "dateTime"
150
+ | "json";
151
+ name: string;
152
+ title?: string | undefined;
153
+ description?: string | undefined;
154
+ required?: boolean | undefined;
155
+ options?: ChoiceOptions | undefined;
156
+ validation?: ScalarValidation | undefined;
157
+ }>,
158
+ ) => string
159
+ >,
160
+ ]
60
161
  >;
61
162
 
163
+ declare type ActionSemantic = (typeof ACTION_SEMANTICS)[number];
164
+
62
165
  declare type Activity = ActivityFields<
63
166
  FieldEntry,
64
167
  Action,
@@ -770,6 +873,17 @@ declare type AuthoringWorkflow = WorkflowFields<
770
873
  AuthoringStartBlock
771
874
  >;
772
875
 
876
+ declare interface ChoiceOption {
877
+ title: string;
878
+ value: ChoiceValue;
879
+ }
880
+
881
+ declare interface ChoiceOptions {
882
+ list: ChoiceOption[];
883
+ }
884
+
885
+ declare type ChoiceValue = string | number;
886
+
773
887
  /**
774
888
  * The action half of the mirrored claim pair. `field` references an
775
889
  * author-declared actor-valued entry (the pair's other half), resolved
@@ -871,6 +985,15 @@ export declare interface ConditionVar {
871
985
  */
872
986
  export declare type ConditionVarBinding = "always" | "caller" | "spawn";
873
987
 
988
+ /**
989
+ * The maximum reader floor this writer can emit. Individual documents derive
990
+ * their `minReaderModel` from the compatibility-bearing features actually
991
+ * present; a document written at {@link DATA_MODEL_VERSION} may therefore
992
+ * carry a lower floor. Raising this maximum is a declared, DATAMODEL.md-logged
993
+ * decision that requires readers-first fleet sequencing.
994
+ */
995
+ declare const DATA_MODEL_MIN_READER = 2;
996
+
874
997
  export declare function defineAction(action: AuthoringAction): AuthoringAction;
875
998
 
876
999
  export declare function defineActivity(
@@ -1028,10 +1151,12 @@ declare const EffectSchema: v.StrictObjectSchema<
1028
1151
  declare const FIELD_VALUE_KINDS: readonly [
1029
1152
  "doc.ref",
1030
1153
  "doc.refs",
1154
+ "subject",
1031
1155
  "release.ref",
1032
1156
  "string",
1033
1157
  "text",
1034
1158
  "number",
1159
+ "progress",
1035
1160
  "boolean",
1036
1161
  "date",
1037
1162
  "datetime",
@@ -1064,6 +1189,8 @@ declare type FieldEntryFields<TEditable, TGroup> = FieldBase<
1064
1189
  TGroup
1065
1190
  > & {
1066
1191
  type: FieldValueKind;
1192
+ options?: ChoiceOptions | undefined;
1193
+ validation?: ScalarValidation | undefined;
1067
1194
  types?: string[] | undefined;
1068
1195
  fields?: FieldShape[] | undefined;
1069
1196
  of?: FieldShape[] | undefined;
@@ -1081,6 +1208,8 @@ declare interface FieldShape {
1081
1208
  name: string;
1082
1209
  title?: string | undefined;
1083
1210
  description?: string | undefined;
1211
+ options?: ChoiceOptions | undefined;
1212
+ validation?: ScalarValidation | undefined;
1084
1213
  fields?: FieldShape[] | undefined;
1085
1214
  of?: FieldShape[] | undefined;
1086
1215
  }
@@ -1297,12 +1426,11 @@ declare type NotesField = FieldBase<AuthoringEditable, GroupMembership> & {
1297
1426
 
1298
1427
  declare type Op = v.InferOutput<typeof StoredOpSchema>;
1299
1428
 
1300
- /**
1301
- * Names an author's predicate may not use — engine-owned and author names
1302
- * share one namespace, so a predicate redefining a binding would silently
1303
- * shadow engine behaviour. Rejected at deploy; derived from
1304
- * {@link CONDITION_VARS}.
1305
- */
1429
+ declare type ParsedWorkflowConfig = v.InferOutput<typeof WorkflowConfigSchema>;
1430
+
1431
+ declare type ParsedWorkflowDeployment =
1432
+ ParsedWorkflowConfig["deployments"][number];
1433
+
1306
1434
  export declare const RESERVED_CONDITION_VARS: readonly string[];
1307
1435
 
1308
1436
  declare type RoleAliases = v.InferOutput<typeof RoleAliasesSchema>;
@@ -1362,6 +1490,13 @@ declare const RoleAliasesSchema: v.RecordSchema<
1362
1490
  undefined
1363
1491
  >;
1364
1492
 
1493
+ /** Inclusive scalar bounds. String/text bounds measure character length;
1494
+ * number bounds measure the numeric value. */
1495
+ declare interface ScalarValidation {
1496
+ min?: number | undefined;
1497
+ max?: number | undefined;
1498
+ }
1499
+
1365
1500
  declare type Stage = StageFields<
1366
1501
  FieldEntry,
1367
1502
  Activity,
@@ -1779,7 +1914,9 @@ declare type ValueExprInternal =
1779
1914
 
1780
1915
  declare const WORKFLOW_LIFECYCLES: readonly ["standalone", "child"];
1781
1916
 
1782
- declare type WorkflowConfig = v.InferOutput<typeof WorkflowConfigSchema>;
1917
+ declare type WorkflowConfig = Omit<ParsedWorkflowConfig, "deployments"> & {
1918
+ deployments: WorkflowDeployment[];
1919
+ };
1783
1920
 
1784
1921
  declare const WorkflowConfigSchema: v.ObjectSchema<
1785
1922
  {
@@ -1791,16 +1928,24 @@ declare const WorkflowConfigSchema: v.ObjectSchema<
1791
1928
  readonly name: v.SchemaWithPipe<
1792
1929
  readonly [
1793
1930
  v.StringSchema<undefined>,
1794
- v.NonEmptyAction<string, "must not be empty">,
1931
+ v.NonEmptyAction<string, undefined>,
1932
+ v.CheckAction<
1933
+ string,
1934
+ `invalid ${string} \u2014 ASCII lowercase + digits + dashes, no leading dash, no dots`
1935
+ >,
1795
1936
  ]
1796
1937
  >;
1938
+ readonly expectedMinReaderModel: v.OptionalSchema<
1939
+ v.CustomSchema<2, undefined>,
1940
+ undefined
1941
+ >;
1797
1942
  readonly tag: v.SchemaWithPipe<
1798
1943
  readonly [
1799
1944
  v.StringSchema<undefined>,
1800
1945
  v.NonEmptyAction<string, undefined>,
1801
1946
  v.CheckAction<
1802
1947
  string,
1803
- "invalid tag lowercase letters, digits and dashes only, no leading dash, no dots"
1948
+ `invalid ${string} \u2014 ASCII lowercase + digits + dashes, no leading dash, no dots`
1804
1949
  >,
1805
1950
  ]
1806
1951
  >;
@@ -2001,7 +2146,30 @@ declare const WorkflowConfigSchema: v.ObjectSchema<
2001
2146
  id: string;
2002
2147
  };
2003
2148
  }[],
2004
- "duplicate resource handle name — each binding name must be unique within a deployment"
2149
+ (
2150
+ issue: v.CheckIssue<
2151
+ {
2152
+ name: string;
2153
+ resource:
2154
+ | {
2155
+ type: "dataset";
2156
+ id: string;
2157
+ }
2158
+ | {
2159
+ type: "canvas";
2160
+ id: string;
2161
+ }
2162
+ | {
2163
+ type: "media-library";
2164
+ id: string;
2165
+ }
2166
+ | {
2167
+ type: "dashboard";
2168
+ id: string;
2169
+ };
2170
+ }[]
2171
+ >,
2172
+ ) => string
2005
2173
  >,
2006
2174
  ]
2007
2175
  >,
@@ -2055,6 +2223,7 @@ declare const WorkflowConfigSchema: v.ObjectSchema<
2055
2223
  v.MinLengthAction<
2056
2224
  {
2057
2225
  name: string;
2226
+ expectedMinReaderModel?: 2 | undefined;
2058
2227
  tag: string;
2059
2228
  workflowResource:
2060
2229
  | {
@@ -2115,6 +2284,7 @@ declare const WorkflowConfigSchema: v.ObjectSchema<
2115
2284
  v.CheckAction<
2116
2285
  {
2117
2286
  name: string;
2287
+ expectedMinReaderModel?: 2 | undefined;
2118
2288
  tag: string;
2119
2289
  workflowResource:
2120
2290
  | {
@@ -2169,7 +2339,187 @@ declare const WorkflowConfigSchema: v.ObjectSchema<
2169
2339
  roleAliases?: RoleAliases | undefined;
2170
2340
  }[];
2171
2341
  }[],
2172
- "duplicate deployment tag — each deployment must use a unique tag"
2342
+ (
2343
+ issue: v.CheckIssue<
2344
+ {
2345
+ name: string;
2346
+ expectedMinReaderModel?: 2 | undefined;
2347
+ tag: string;
2348
+ workflowResource:
2349
+ | {
2350
+ type: "dataset";
2351
+ id: string;
2352
+ }
2353
+ | {
2354
+ type: "canvas";
2355
+ id: string;
2356
+ }
2357
+ | {
2358
+ type: "media-library";
2359
+ id: string;
2360
+ }
2361
+ | {
2362
+ type: "dashboard";
2363
+ id: string;
2364
+ };
2365
+ resourceAliases?:
2366
+ | {
2367
+ name: string;
2368
+ resource:
2369
+ | {
2370
+ type: "dataset";
2371
+ id: string;
2372
+ }
2373
+ | {
2374
+ type: "canvas";
2375
+ id: string;
2376
+ }
2377
+ | {
2378
+ type: "media-library";
2379
+ id: string;
2380
+ }
2381
+ | {
2382
+ type: "dashboard";
2383
+ id: string;
2384
+ };
2385
+ }[]
2386
+ | undefined;
2387
+ definitions: {
2388
+ name: string;
2389
+ title: string;
2390
+ description?: string | undefined;
2391
+ groups?: Group[] | undefined;
2392
+ lifecycle?: WorkflowLifecycle | undefined;
2393
+ start?: StartBlock | undefined;
2394
+ initialStage: string;
2395
+ fields?: FieldEntry[] | undefined;
2396
+ stages: Stage[];
2397
+ predicates?: Record<string, string> | undefined;
2398
+ roleAliases?: RoleAliases | undefined;
2399
+ }[];
2400
+ }[]
2401
+ >,
2402
+ ) => string
2403
+ >,
2404
+ v.CheckAction<
2405
+ {
2406
+ name: string;
2407
+ expectedMinReaderModel?: 2 | undefined;
2408
+ tag: string;
2409
+ workflowResource:
2410
+ | {
2411
+ type: "dataset";
2412
+ id: string;
2413
+ }
2414
+ | {
2415
+ type: "canvas";
2416
+ id: string;
2417
+ }
2418
+ | {
2419
+ type: "media-library";
2420
+ id: string;
2421
+ }
2422
+ | {
2423
+ type: "dashboard";
2424
+ id: string;
2425
+ };
2426
+ resourceAliases?:
2427
+ | {
2428
+ name: string;
2429
+ resource:
2430
+ | {
2431
+ type: "dataset";
2432
+ id: string;
2433
+ }
2434
+ | {
2435
+ type: "canvas";
2436
+ id: string;
2437
+ }
2438
+ | {
2439
+ type: "media-library";
2440
+ id: string;
2441
+ }
2442
+ | {
2443
+ type: "dashboard";
2444
+ id: string;
2445
+ };
2446
+ }[]
2447
+ | undefined;
2448
+ definitions: {
2449
+ name: string;
2450
+ title: string;
2451
+ description?: string | undefined;
2452
+ groups?: Group[] | undefined;
2453
+ lifecycle?: WorkflowLifecycle | undefined;
2454
+ start?: StartBlock | undefined;
2455
+ initialStage: string;
2456
+ fields?: FieldEntry[] | undefined;
2457
+ stages: Stage[];
2458
+ predicates?: Record<string, string> | undefined;
2459
+ roleAliases?: RoleAliases | undefined;
2460
+ }[];
2461
+ }[],
2462
+ (
2463
+ issue: v.CheckIssue<
2464
+ {
2465
+ name: string;
2466
+ expectedMinReaderModel?: 2 | undefined;
2467
+ tag: string;
2468
+ workflowResource:
2469
+ | {
2470
+ type: "dataset";
2471
+ id: string;
2472
+ }
2473
+ | {
2474
+ type: "canvas";
2475
+ id: string;
2476
+ }
2477
+ | {
2478
+ type: "media-library";
2479
+ id: string;
2480
+ }
2481
+ | {
2482
+ type: "dashboard";
2483
+ id: string;
2484
+ };
2485
+ resourceAliases?:
2486
+ | {
2487
+ name: string;
2488
+ resource:
2489
+ | {
2490
+ type: "dataset";
2491
+ id: string;
2492
+ }
2493
+ | {
2494
+ type: "canvas";
2495
+ id: string;
2496
+ }
2497
+ | {
2498
+ type: "media-library";
2499
+ id: string;
2500
+ }
2501
+ | {
2502
+ type: "dashboard";
2503
+ id: string;
2504
+ };
2505
+ }[]
2506
+ | undefined;
2507
+ definitions: {
2508
+ name: string;
2509
+ title: string;
2510
+ description?: string | undefined;
2511
+ groups?: Group[] | undefined;
2512
+ lifecycle?: WorkflowLifecycle | undefined;
2513
+ start?: StartBlock | undefined;
2514
+ initialStage: string;
2515
+ fields?: FieldEntry[] | undefined;
2516
+ stages: Stage[];
2517
+ predicates?: Record<string, string> | undefined;
2518
+ roleAliases?: RoleAliases | undefined;
2519
+ }[];
2520
+ }[]
2521
+ >,
2522
+ ) => string
2173
2523
  >,
2174
2524
  ]
2175
2525
  >;
@@ -2213,6 +2563,13 @@ declare const WorkflowDefinitionSchema: v.GenericSchema<
2213
2563
  WorkflowFields<FieldEntry, Stage, StartBlock>
2214
2564
  >;
2215
2565
 
2566
+ declare type WorkflowDeployment = Omit<
2567
+ ParsedWorkflowDeployment,
2568
+ "expectedMinReaderModel"
2569
+ > & {
2570
+ expectedMinReaderModel: typeof DATA_MODEL_MIN_READER;
2571
+ };
2572
+
2216
2573
  /** Type-mirror of {@link workflowFields}, parameterised over field/stage/start. */
2217
2574
  declare type WorkflowFields<TField, TStage, TStart> = {
2218
2575
  /**