@sanity/workflow-engine 0.11.0 → 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.
@@ -21,6 +21,12 @@ function andConditions(parts) {
21
21
  if (present.length !== 0)
22
22
  return present.length === 1 ? present[0] : present.map((p) => `(${p})`).join(" && ");
23
23
  }
24
+ const UNIVERSAL_ROLE_ALIAS_KEY = "$all";
25
+ function normalizeRoleAliases(aliases) {
26
+ if (aliases === void 0 || !("*" in aliases)) return aliases;
27
+ const { ["*"]: universal, ...perRole } = aliases;
28
+ return { ...perRole, [UNIVERSAL_ROLE_ALIAS_KEY]: universal };
29
+ }
24
30
  function expandRequiredRoles(required, aliases) {
25
31
  if (aliases === void 0) return [...required];
26
32
  const out = /* @__PURE__ */ new Set();
@@ -28,25 +34,29 @@ function expandRequiredRoles(required, aliases) {
28
34
  out.add(role);
29
35
  for (const fulfiller of aliases[role] ?? []) out.add(fulfiller);
30
36
  }
31
- for (const fulfiller of aliases["*"] ?? []) out.add(fulfiller);
37
+ for (const fulfiller of aliases[UNIVERSAL_ROLE_ALIAS_KEY] ?? []) out.add(fulfiller);
32
38
  return [...out];
33
39
  }
34
- function actorFulfillsRole(actorRoles, required, aliases) {
40
+ function actorFulfillsRole({
41
+ actorRoles,
42
+ required,
43
+ aliases
44
+ }) {
35
45
  if (actorRoles === void 0 || actorRoles.length === 0) return !1;
36
46
  const accepted = new Set(expandRequiredRoles([required], aliases));
37
47
  return actorRoles.some((role) => accepted.has(role));
38
48
  }
39
- const TASK_STATUSES = ["pending", "active", "done", "skipped", "failed"], TERMINAL_TASK_STATUSES = ["done", "skipped", "failed"];
40
- function isTerminalTaskStatus(status) {
41
- return TERMINAL_TASK_STATUSES.includes(status);
49
+ const ACTIVITY_STATUSES = ["pending", "active", "done", "skipped", "failed"], TERMINAL_ACTIVITY_STATUSES = ["done", "skipped", "failed"];
50
+ function isTerminalActivityStatus(status) {
51
+ return TERMINAL_ACTIVITY_STATUSES.includes(status);
42
52
  }
43
- const FIELD_SCOPES = ["workflow", "stage", "task"], DOCUMENT_VALUE_PERMISSIONS = ["create", "read", "update"], MUTATION_GUARD_ACTIONS = [
53
+ const FIELD_SCOPES = ["workflow", "stage", "activity"], DOCUMENT_VALUE_PERMISSIONS = ["create", "read", "update"], MUTATION_GUARD_ACTIONS = [
44
54
  "create",
45
55
  "update",
46
56
  "delete",
47
57
  "publish",
48
58
  "unpublish"
49
- ], TASK_KINDS = ["user", "service", "script", "manual", "receive"], DRIVER_KINDS = ["person", "agent", "service", "engine"], NonEmpty = v__namespace.pipe(v__namespace.string(), v__namespace.minLength(1, "must be a non-empty string")), PositiveInt = v__namespace.pipe(v__namespace.number(), v__namespace.integer(), v__namespace.minValue(1)), GROQ_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
59
+ ], ACTIVITY_KINDS = ["user", "service", "script", "manual", "receive"], DRIVER_KINDS = ["person", "agent", "service", "engine"], NonEmpty = v__namespace.pipe(v__namespace.string(), v__namespace.minLength(1, "must be a non-empty string")), PositiveInt = v__namespace.pipe(v__namespace.number(), v__namespace.integer(), v__namespace.minValue(1)), GROQ_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
50
60
  function groqIdentifier(referencedAs) {
51
61
  return v__namespace.pipe(
52
62
  v__namespace.string(),
@@ -62,32 +72,31 @@ function picklist(options) {
62
72
  `Invalid option: expected one of ${options.map((o) => `"${o}"`).join("|")}`
63
73
  );
64
74
  }
65
- const SourceSchema = v__namespace.lazy(
75
+ function pinned() {
76
+ return (schema, ..._exact) => schema;
77
+ }
78
+ const LiteralSchema = v__namespace.strictObject({ type: v__namespace.literal("literal"), value: v__namespace.unknown() }), FieldReadSchema = v__namespace.strictObject({
79
+ type: v__namespace.literal("fieldRead"),
80
+ scope: v__namespace.optional(v__namespace.union([v__namespace.literal("workflow"), v__namespace.literal("stage")])),
81
+ field: NonEmpty,
82
+ path: v__namespace.optional(v__namespace.string())
83
+ }), FieldSourceSchema = v__namespace.union([
84
+ // The caller supplies it at start/spawn (`initialFields` / `subworkflows.with`).
85
+ v__namespace.strictObject({ type: v__namespace.literal("input") }),
86
+ // Computed once by running GROQ against the lake at materialisation.
87
+ v__namespace.strictObject({ type: v__namespace.literal("query"), query: NonEmpty }),
88
+ LiteralSchema,
89
+ FieldReadSchema
90
+ ]), ValueExprSchema = v__namespace.lazy(
66
91
  () => v__namespace.union([
67
- // Field-entry origins: who fills the entry, and when.
68
- v__namespace.strictObject({ type: v__namespace.literal("init") }),
69
- v__namespace.strictObject({ type: v__namespace.literal("write") }),
70
- v__namespace.strictObject({
71
- type: v__namespace.literal("query"),
72
- query: NonEmpty
73
- }),
74
- // Value sources: resolved to concrete JSON when an op or seed applies.
75
- v__namespace.strictObject({ type: v__namespace.literal("literal"), value: v__namespace.unknown() }),
92
+ LiteralSchema,
93
+ FieldReadSchema,
76
94
  v__namespace.strictObject({ type: v__namespace.literal("param"), param: NonEmpty }),
77
95
  v__namespace.strictObject({ type: v__namespace.literal("actor") }),
78
96
  v__namespace.strictObject({ type: v__namespace.literal("now") }),
79
97
  v__namespace.strictObject({ type: v__namespace.literal("self") }),
80
98
  v__namespace.strictObject({ type: v__namespace.literal("stage") }),
81
- v__namespace.strictObject({
82
- type: v__namespace.literal("fieldRead"),
83
- scope: v__namespace.optional(v__namespace.union([v__namespace.literal("workflow"), v__namespace.literal("stage")])),
84
- field: NonEmpty,
85
- path: v__namespace.optional(v__namespace.string())
86
- }),
87
- v__namespace.strictObject({
88
- type: v__namespace.literal("object"),
89
- fields: v__namespace.record(NonEmpty, SourceSchema)
90
- })
99
+ v__namespace.strictObject({ type: v__namespace.literal("object"), fields: v__namespace.record(NonEmpty, ValueExprSchema) })
91
100
  ])
92
101
  ), StoredFieldRefSchema = v__namespace.strictObject({
93
102
  scope: picklist(FIELD_SCOPES),
@@ -119,7 +128,7 @@ const StoredManualTargetSchema = manualTargetSchema(StoredFieldRefSchema), Autho
119
128
  v__namespace.strictObject({
120
129
  type: v__namespace.literal("field"),
121
130
  field: NonEmpty,
122
- equals: SourceSchema
131
+ equals: ValueExprSchema
123
132
  }),
124
133
  v__namespace.strictObject({ type: v__namespace.literal("all"), of: v__namespace.array(OpPredicateSchema) }),
125
134
  v__namespace.strictObject({ type: v__namespace.literal("any"), of: v__namespace.array(OpPredicateSchema) })
@@ -130,7 +139,7 @@ function opSchemas(targetSchema) {
130
139
  v__namespace.strictObject({
131
140
  type: v__namespace.literal("field.set"),
132
141
  target: targetSchema,
133
- value: SourceSchema
142
+ value: ValueExprSchema
134
143
  }),
135
144
  v__namespace.strictObject({
136
145
  type: v__namespace.literal("field.unset"),
@@ -139,13 +148,13 @@ function opSchemas(targetSchema) {
139
148
  v__namespace.strictObject({
140
149
  type: v__namespace.literal("field.append"),
141
150
  target: targetSchema,
142
- value: SourceSchema
151
+ value: ValueExprSchema
143
152
  }),
144
153
  v__namespace.strictObject({
145
154
  type: v__namespace.literal("field.updateWhere"),
146
155
  target: targetSchema,
147
156
  where: OpPredicateSchema,
148
- value: SourceSchema
157
+ value: ValueExprSchema
149
158
  }),
150
159
  v__namespace.strictObject({
151
160
  type: v__namespace.literal("field.removeWhere"),
@@ -154,17 +163,17 @@ function opSchemas(targetSchema) {
154
163
  })
155
164
  ];
156
165
  }
157
- const StoredOpSchema = v__namespace.variant("type", [
166
+ const StoredFieldOpSchema = v__namespace.variant("type", [...opSchemas(StoredFieldRefSchema)]), StoredOpSchema = v__namespace.variant("type", [
158
167
  ...opSchemas(StoredFieldRefSchema),
159
168
  v__namespace.strictObject({
160
169
  type: v__namespace.literal("status.set"),
161
- task: NonEmpty,
162
- status: picklist(TASK_STATUSES)
170
+ activity: NonEmpty,
171
+ status: picklist(ACTIVITY_STATUSES)
163
172
  })
164
- ]), StoredTransitionOpSchema = v__namespace.variant("type", [...opSchemas(StoredFieldRefSchema)]), AuditOpSchema = v__namespace.strictObject({
173
+ ]), StoredTransitionOpSchema = StoredFieldOpSchema, AuditOpSchema = v__namespace.strictObject({
165
174
  type: v__namespace.literal("audit"),
166
175
  target: AuthoringFieldRefSchema,
167
- value: SourceSchema,
176
+ value: ValueExprSchema,
168
177
  stampFields: v__namespace.optional(
169
178
  v__namespace.strictObject({
170
179
  actor: v__namespace.optional(NonEmpty),
@@ -175,33 +184,83 @@ const StoredOpSchema = v__namespace.variant("type", [
175
184
  ...opSchemas(AuthoringFieldRefSchema),
176
185
  v__namespace.strictObject({
177
186
  type: v__namespace.literal("status.set"),
178
- task: v__namespace.optional(NonEmpty),
179
- status: picklist(TASK_STATUSES)
187
+ activity: v__namespace.optional(NonEmpty),
188
+ status: picklist(ACTIVITY_STATUSES)
180
189
  }),
181
190
  AuditOpSchema
182
- ]), FieldKindSchema = picklist([
191
+ ]), FIELD_VALUE_KINDS = [
183
192
  "doc.ref",
184
193
  "doc.refs",
185
194
  // Release reference. A workflow declares this entry to say "I target a
186
195
  // Content Release"; the runtime fills it at start time and auto-derives
187
196
  // the instance's read perspective from it.
188
197
  "release.ref",
189
- "query",
190
- "value.string",
191
- "value.url",
192
- "value.number",
193
- "value.boolean",
194
- "value.dateTime",
195
- "value.actor",
196
- "checklist",
197
- "notes",
198
+ "string",
199
+ "text",
200
+ "number",
201
+ "boolean",
202
+ "date",
203
+ "datetime",
204
+ "url",
205
+ "actor",
206
+ // A single {@link Assignee} — the singular of `assignees`.
207
+ "assignee",
198
208
  // The WHO-FOR entry: the inbox reverse-query reads it by kind, and the
199
209
  // rendered `$assigned` gate matches the caller against it.
200
- "assignees"
201
- ]), FieldEntryName = groqIdentifier("`$fields.<name>`"), StoredEditableSchema = v__namespace.union([v__namespace.literal(!0), NonEmpty]), AuthoringEditableSchema = v__namespace.union([v__namespace.literal(!0), v__namespace.array(NonEmpty), NonEmpty]);
202
- function fieldEntryFields(editable) {
210
+ "assignees",
211
+ // Compositional kinds mirror Sanity's `object.fields` / `array.of`.
212
+ "object",
213
+ "array"
214
+ ], FieldValueKindSchema = picklist(FIELD_VALUE_KINDS), FieldKindSchema = picklist(FIELD_VALUE_KINDS), FieldEntryName = groqIdentifier("`$fields.<name>`");
215
+ function asShape(input) {
216
+ return typeof input == "object" && input !== null ? input : {};
217
+ }
218
+ function compositeShapeOk(input) {
219
+ const shape = asShape(input);
220
+ return shape.type === "object" ? Array.isArray(shape.fields) && shape.fields.length > 0 && shape.of === void 0 : shape.type === "array" ? Array.isArray(shape.of) && shape.of.length > 0 && shape.fields === void 0 : shape.fields === void 0 && shape.of === void 0;
221
+ }
222
+ function compositeShapeMessage(input) {
223
+ const shape = asShape(input);
224
+ return shape.type === "object" ? shape.of !== void 0 ? "an `object` kind declares its sub-fields with `fields`, not `of`" : "an `object` kind needs a non-empty `fields` list of sub-field shapes" : shape.type === "array" ? shape.fields !== void 0 ? "an `array` kind declares its item shape with `of`, not `fields`" : "an `array` kind needs a non-empty `of` list of sub-field shapes" : `\`fields\` / \`of\` are only valid on the \`object\` / \`array\` kinds, not "${String(shape.type)}"`;
225
+ }
226
+ function duplicateSubfieldName(input) {
227
+ const shape = asShape(input);
228
+ let list = [];
229
+ Array.isArray(shape.fields) ? list = shape.fields : Array.isArray(shape.of) && (list = shape.of);
230
+ const seen = /* @__PURE__ */ new Set();
231
+ for (const item of list) {
232
+ const name = asShape(item).name;
233
+ if (typeof name == "string") {
234
+ if (seen.has(name)) return name;
235
+ seen.add(name);
236
+ }
237
+ }
238
+ }
239
+ function compositeChecked(entries) {
240
+ return v__namespace.pipe(
241
+ v__namespace.strictObject(entries),
242
+ v__namespace.check(
243
+ (input) => compositeShapeOk(input),
244
+ (issue) => compositeShapeMessage(issue.input)
245
+ ),
246
+ v__namespace.check(
247
+ (input) => duplicateSubfieldName(input) === void 0,
248
+ (issue) => `duplicate sub-field name "${duplicateSubfieldName(issue.input)}" \u2014 sub-field names must be unique within \`fields\` / \`of\``
249
+ )
250
+ );
251
+ }
252
+ const FieldShapeSchema = v__namespace.lazy(
253
+ () => compositeChecked({
254
+ type: FieldValueKindSchema,
255
+ name: FieldEntryName,
256
+ title: v__namespace.optional(v__namespace.string()),
257
+ description: v__namespace.optional(v__namespace.string()),
258
+ fields: v__namespace.optional(v__namespace.array(FieldShapeSchema)),
259
+ of: v__namespace.optional(v__namespace.array(FieldShapeSchema))
260
+ })
261
+ ), StoredEditableSchema = v__namespace.union([v__namespace.literal(!0), NonEmpty]), AuthoringEditableSchema = v__namespace.union([v__namespace.literal(!0), v__namespace.array(NonEmpty), NonEmpty]);
262
+ function slotFields(editable) {
203
263
  return {
204
- type: FieldKindSchema,
205
264
  name: FieldEntryName,
206
265
  title: v__namespace.optional(v__namespace.string()),
207
266
  description: v__namespace.optional(v__namespace.string()),
@@ -210,20 +269,50 @@ function fieldEntryFields(editable) {
210
269
  * `initialFields`) or spawn (via the parent's `subworkflows.with`). A
211
270
  * missing required entry throws rather than silently defaulting to
212
271
  * `null`/`[]` — the same fail-fast an action's `required` param gets.
213
- * Valid only on a workflow-scope `init`-sourced entry (deploy invariant).
272
+ * Valid only on a workflow-scope `input`-sourced entry (deploy invariant).
214
273
  */
215
274
  required: v__namespace.optional(v__namespace.boolean()),
216
- source: SourceSchema,
275
+ /**
276
+ * How this field SEEDS its value at materialisation — see
277
+ * {@link FieldSourceSchema}. Optional: an absent `initialValue` is working
278
+ * memory (the slot starts empty and an op fills it later), the common case.
279
+ */
280
+ initialValue: v__namespace.optional(FieldSourceSchema),
217
281
  /** Who-may-edit this slot via the edit seam — see {@link StoredEditableSchema}. */
218
282
  editable: v__namespace.optional(editable)
219
283
  };
220
284
  }
221
- const FieldEntrySchema = v__namespace.strictObject(fieldEntryFields(StoredEditableSchema)), RawAuthoringFieldEntrySchema = v__namespace.strictObject(fieldEntryFields(AuthoringEditableSchema)), ClaimFieldSchema = v__namespace.strictObject({
222
- type: v__namespace.literal("claim"),
223
- name: FieldEntryName,
224
- title: v__namespace.optional(v__namespace.string()),
225
- description: v__namespace.optional(v__namespace.string())
226
- }), AuthoringFieldEntrySchema = v__namespace.union([RawAuthoringFieldEntrySchema, ClaimFieldSchema]), ConditionSchema = NonEmpty, EffectSchema = v__namespace.strictObject({
285
+ function fieldEntryFields(editable) {
286
+ return {
287
+ type: FieldKindSchema,
288
+ ...slotFields(editable),
289
+ /** Sub-field shapes for an `object` kind (see {@link compositeShapeOk}). */
290
+ fields: v__namespace.optional(v__namespace.array(FieldShapeSchema)),
291
+ /** Item sub-field shapes for an `array` kind (see {@link compositeShapeOk}). */
292
+ of: v__namespace.optional(v__namespace.array(FieldShapeSchema))
293
+ };
294
+ }
295
+ const FieldEntrySchema = pinned()(
296
+ compositeChecked(fieldEntryFields(StoredEditableSchema))
297
+ ), RawAuthoringFieldEntrySchema = pinned()(
298
+ compositeChecked(fieldEntryFields(AuthoringEditableSchema))
299
+ ), ClaimFieldSchema = pinned()(
300
+ v__namespace.strictObject({
301
+ type: v__namespace.literal("claim"),
302
+ name: FieldEntryName,
303
+ title: v__namespace.optional(v__namespace.string()),
304
+ description: v__namespace.optional(v__namespace.string())
305
+ })
306
+ );
307
+ function listSugarFields(type) {
308
+ return {
309
+ type: v__namespace.literal(type),
310
+ ...slotFields(AuthoringEditableSchema)
311
+ };
312
+ }
313
+ const TodoListFieldSchema = pinned()(v__namespace.strictObject(listSugarFields("todoList"))), NotesFieldSchema = pinned()(v__namespace.strictObject(listSugarFields("notes"))), AuthoringFieldEntrySchema = pinned()(
314
+ v__namespace.union([RawAuthoringFieldEntrySchema, ClaimFieldSchema, TodoListFieldSchema, NotesFieldSchema])
315
+ ), ConditionSchema = NonEmpty, EffectSchema = v__namespace.strictObject({
227
316
  name: NonEmpty,
228
317
  title: v__namespace.optional(v__namespace.string()),
229
318
  description: v__namespace.optional(v__namespace.string()),
@@ -264,21 +353,27 @@ function actionFields(op) {
264
353
  effects: v__namespace.optional(v__namespace.array(EffectSchema))
265
354
  };
266
355
  }
267
- const StoredActionSchema = v__namespace.strictObject(actionFields(StoredOpSchema)), TerminalTaskStatus = picklist(TERMINAL_TASK_STATUSES), RawAuthoringActionSchema = v__namespace.strictObject({
268
- ...actionFields(AuthoringOpSchema),
269
- roles: v__namespace.optional(v__namespace.array(NonEmpty)),
270
- status: v__namespace.optional(TerminalTaskStatus)
271
- }), ClaimActionSchema = v__namespace.strictObject({
272
- type: v__namespace.literal("claim"),
273
- name: NonEmpty,
274
- title: v__namespace.optional(v__namespace.string()),
275
- description: v__namespace.optional(v__namespace.string()),
276
- field: v__namespace.union([NonEmpty, AuthoringFieldRefSchema]),
277
- roles: v__namespace.optional(v__namespace.array(NonEmpty)),
278
- filter: v__namespace.optional(ConditionSchema),
279
- params: v__namespace.optional(v__namespace.array(ActionParamSchema)),
280
- effects: v__namespace.optional(v__namespace.array(EffectSchema))
281
- }), AuthoringActionSchema = v__namespace.union([RawAuthoringActionSchema, ClaimActionSchema]), DefinitionRefSchema = v__namespace.strictObject({
356
+ const StoredActionSchema = pinned()(v__namespace.strictObject(actionFields(StoredOpSchema))), TerminalActivityStatus = picklist(TERMINAL_ACTIVITY_STATUSES), RawAuthoringActionSchema = pinned()(
357
+ v__namespace.strictObject({
358
+ ...actionFields(AuthoringOpSchema),
359
+ roles: v__namespace.optional(v__namespace.array(NonEmpty)),
360
+ status: v__namespace.optional(TerminalActivityStatus)
361
+ })
362
+ ), ClaimActionSchema = pinned()(
363
+ v__namespace.strictObject({
364
+ type: v__namespace.literal("claim"),
365
+ name: NonEmpty,
366
+ title: v__namespace.optional(v__namespace.string()),
367
+ description: v__namespace.optional(v__namespace.string()),
368
+ field: v__namespace.union([NonEmpty, AuthoringFieldRefSchema]),
369
+ roles: v__namespace.optional(v__namespace.array(NonEmpty)),
370
+ filter: v__namespace.optional(ConditionSchema),
371
+ params: v__namespace.optional(v__namespace.array(ActionParamSchema)),
372
+ effects: v__namespace.optional(v__namespace.array(EffectSchema))
373
+ })
374
+ ), AuthoringActionSchema = pinned()(
375
+ v__namespace.union([RawAuthoringActionSchema, ClaimActionSchema])
376
+ ), DefinitionRefSchema = v__namespace.strictObject({
282
377
  name: NonEmpty,
283
378
  version: v__namespace.optional(v__namespace.union([PositiveInt, v__namespace.literal("latest")]))
284
379
  }), SubworkflowsSchema = v__namespace.strictObject({
@@ -294,27 +389,27 @@ const StoredActionSchema = v__namespace.strictObject(actionFields(StoredOpSchema
294
389
  */
295
390
  context: v__namespace.optional(v__namespace.record(NonEmpty, ConditionSchema))
296
391
  });
297
- function taskFields(field, action, op, target) {
392
+ function activityFields({ field, action, op, target }) {
298
393
  return {
299
394
  name: NonEmpty,
300
395
  title: v__namespace.optional(v__namespace.string()),
301
396
  description: v__namespace.optional(v__namespace.string()),
302
397
  /**
303
- * Advisory BPMN-aligned classification of this task by its executor (see
304
- * {@link TASK_KINDS}). Optional and derived from the task's shape when
398
+ * Advisory BPMN-aligned classification of this activity by its executor (see
399
+ * {@link ACTIVITY_KINDS}). Optional and derived from the activity's shape when
305
400
  * omitted; declaring it lets deploy check the shape matches the lane.
306
401
  * Changes no gating or resolution — a label for tooling, like `assignees`.
307
402
  */
308
- kind: v__namespace.optional(picklist(TASK_KINDS)),
309
- /** Deep-link target for a `kind: "manual"` task (off-system work). Render-only
310
- * metadata; only valid on a manual task (deploy-checked). */
403
+ kind: v__namespace.optional(picklist(ACTIVITY_KINDS)),
404
+ /** Deep-link target for a `kind: "manual"` activity (off-system work). Render-only
405
+ * metadata; only valid on a manual activity (deploy-checked). */
311
406
  target: v__namespace.optional(target),
312
407
  activation: v__namespace.optional(picklist(["auto", "manual"])),
313
408
  filter: v__namespace.optional(ConditionSchema),
314
409
  /**
315
410
  * Readiness gates, by name — conditions over the rendered scope that must
316
- * hold for the task to be *executable*, orthogonal to `filter`
317
- * (visibility). An unmet requirement keeps the task visible but disables
411
+ * hold for the activity to be *executable*, orthogonal to `filter`
412
+ * (visibility). An unmet requirement keeps the activity visible but disables
318
413
  * its actions with a `requirements-unmet` verdict naming the unmet keys;
319
414
  * all must hold (any-of lives inside one condition). Advisory like every
320
415
  * engine gate — the lake still enforces. Distinct from ACL (authorization)
@@ -323,8 +418,8 @@ function taskFields(field, action, op, target) {
323
418
  requirements: v__namespace.optional(v__namespace.record(NonEmpty, ConditionSchema)),
324
419
  /**
325
420
  * Auto-completion condition — evaluated at activation and on every
326
- * cascade; truthy flips the task to `done` with a system actor. On a
327
- * spawning task it typically reads `$subworkflows`.
421
+ * cascade; truthy flips the activity to `done` with a system actor. On a
422
+ * spawning activity it typically reads `$subworkflows`.
328
423
  */
329
424
  completeWhen: v__namespace.optional(ConditionSchema),
330
425
  /**
@@ -337,18 +432,27 @@ function taskFields(field, action, op, target) {
337
432
  effects: v__namespace.optional(v__namespace.array(EffectSchema)),
338
433
  actions: v__namespace.optional(v__namespace.array(action)),
339
434
  subworkflows: v__namespace.optional(SubworkflowsSchema),
340
- /** Task-scoped field entries. Resolved at task activation time. */
435
+ /** Activity-scoped field entries. Resolved at activity activation time. */
341
436
  fields: v__namespace.optional(v__namespace.array(field))
342
437
  };
343
438
  }
344
- const StoredTaskSchema = v__namespace.strictObject(
345
- taskFields(FieldEntrySchema, StoredActionSchema, StoredOpSchema, StoredManualTargetSchema)
346
- ), AuthoringTaskSchema = v__namespace.strictObject(
347
- taskFields(
348
- AuthoringFieldEntrySchema,
349
- AuthoringActionSchema,
350
- AuthoringOpSchema,
351
- AuthoringManualTargetSchema
439
+ const StoredActivitySchema = pinned()(
440
+ v__namespace.strictObject(
441
+ activityFields({
442
+ field: FieldEntrySchema,
443
+ action: StoredActionSchema,
444
+ op: StoredOpSchema,
445
+ target: StoredManualTargetSchema
446
+ })
447
+ )
448
+ ), AuthoringActivitySchema = pinned()(
449
+ v__namespace.strictObject(
450
+ activityFields({
451
+ field: AuthoringFieldEntrySchema,
452
+ action: AuthoringActionSchema,
453
+ op: AuthoringOpSchema,
454
+ target: AuthoringManualTargetSchema
455
+ })
352
456
  )
353
457
  );
354
458
  function transitionFields(op, filter) {
@@ -363,13 +467,13 @@ function transitionFields(op, filter) {
363
467
  effects: v__namespace.optional(v__namespace.array(EffectSchema))
364
468
  };
365
469
  }
366
- const StoredTransitionSchema = v__namespace.strictObject(
367
- transitionFields(StoredTransitionOpSchema, ConditionSchema)
470
+ const StoredTransitionSchema = pinned()(
471
+ v__namespace.strictObject(transitionFields(StoredTransitionOpSchema, ConditionSchema))
368
472
  ), AuthoringTransitionOpSchema = v__namespace.variant("type", [
369
473
  ...opSchemas(AuthoringFieldRefSchema),
370
474
  AuditOpSchema
371
- ]), AuthoringTransitionSchema = v__namespace.strictObject(
372
- transitionFields(AuthoringTransitionOpSchema, v__namespace.optional(ConditionSchema))
475
+ ]), AuthoringTransitionSchema = pinned()(
476
+ v__namespace.strictObject(transitionFields(AuthoringTransitionOpSchema, v__namespace.optional(ConditionSchema)))
373
477
  ), GuardActionSchema = picklist(MUTATION_GUARD_ACTIONS), GuardMatchSchema = v__namespace.strictObject({
374
478
  /** Subject `_type`(s); empty matches any type. */
375
479
  types: v__namespace.optional(v__namespace.array(NonEmpty)),
@@ -403,12 +507,17 @@ const StoredTransitionSchema = v__namespace.strictObject(
403
507
  */
404
508
  metadata: v__namespace.optional(v__namespace.record(NonEmpty, NonEmpty))
405
509
  });
406
- function stageFields(field, task, transition, editable) {
510
+ function stageFields({
511
+ field,
512
+ activity,
513
+ transition,
514
+ editable
515
+ }) {
407
516
  return {
408
517
  name: NonEmpty,
409
518
  title: v__namespace.optional(v__namespace.string()),
410
519
  description: v__namespace.optional(v__namespace.string()),
411
- tasks: v__namespace.optional(v__namespace.array(task)),
520
+ activities: v__namespace.optional(v__namespace.array(activity)),
412
521
  transitions: v__namespace.optional(v__namespace.array(transition)),
413
522
  /**
414
523
  * Lake mutation guards active while this stage holds. Each compiles to a
@@ -427,14 +536,23 @@ function stageFields(field, task, transition, editable) {
427
536
  editable: v__namespace.optional(v__namespace.record(FieldEntryName, editable))
428
537
  };
429
538
  }
430
- const StoredStageSchema = v__namespace.strictObject(
431
- stageFields(FieldEntrySchema, StoredTaskSchema, StoredTransitionSchema, StoredEditableSchema)
432
- ), AuthoringStageSchema = v__namespace.strictObject(
433
- stageFields(
434
- AuthoringFieldEntrySchema,
435
- AuthoringTaskSchema,
436
- AuthoringTransitionSchema,
437
- AuthoringEditableSchema
539
+ const StoredStageSchema = pinned()(
540
+ v__namespace.strictObject(
541
+ stageFields({
542
+ field: FieldEntrySchema,
543
+ activity: StoredActivitySchema,
544
+ transition: StoredTransitionSchema,
545
+ editable: StoredEditableSchema
546
+ })
547
+ )
548
+ ), AuthoringStageSchema = pinned()(
549
+ v__namespace.strictObject(
550
+ stageFields({
551
+ field: AuthoringFieldEntrySchema,
552
+ activity: AuthoringActivitySchema,
553
+ transition: AuthoringTransitionSchema,
554
+ editable: AuthoringEditableSchema
555
+ })
438
556
  )
439
557
  ), RoleAliasesSchema = v__namespace.record(
440
558
  NonEmpty,
@@ -443,12 +561,11 @@ const StoredStageSchema = v__namespace.strictObject(
443
561
  function workflowFields(field, stage) {
444
562
  return {
445
563
  name: NonEmpty,
446
- version: PositiveInt,
447
564
  title: NonEmpty,
448
565
  description: v__namespace.optional(v__namespace.string()),
449
566
  /**
450
567
  * Whether a human may start this workflow standalone. `'child'` marks a
451
- * spawn-only definition — instantiated by a parent via `task.subworkflows`,
568
+ * spawn-only definition — instantiated by a parent via `activity.subworkflows`,
452
569
  * never started cold from a picker. Omitted ⇒ `'workflow'` (startable).
453
570
  * Advisory: consumers filter their start pickers on it (see
454
571
  * {@link isStartableDefinition}); the engine does NOT refuse a
@@ -471,9 +588,11 @@ function workflowFields(field, stage) {
471
588
  roleAliases: v__namespace.optional(RoleAliasesSchema)
472
589
  };
473
590
  }
474
- v__namespace.strictObject(workflowFields(FieldEntrySchema, StoredStageSchema));
475
- const AuthoringWorkflowSchema = v__namespace.strictObject(
476
- workflowFields(AuthoringFieldEntrySchema, AuthoringStageSchema)
591
+ pinned()(
592
+ v__namespace.strictObject(workflowFields(FieldEntrySchema, StoredStageSchema))
593
+ );
594
+ const AuthoringWorkflowSchema = pinned()(
595
+ v__namespace.strictObject(workflowFields(AuthoringFieldEntrySchema, AuthoringStageSchema))
477
596
  ), WORKFLOW_DEFINITION_TYPE = "sanity.workflow.definition";
478
597
  function isStartableDefinition(definition) {
479
598
  return definition.role !== "child";
@@ -496,11 +615,12 @@ function formatPath(path) {
496
615
  typeof seg == "number" ? out += `[${seg}]` : out += out.length === 0 ? String(seg) : `.${String(seg)}`;
497
616
  return out;
498
617
  }
618
+ exports.ACTIVITY_KINDS = ACTIVITY_KINDS;
499
619
  exports.AuthoringActionSchema = AuthoringActionSchema;
620
+ exports.AuthoringActivitySchema = AuthoringActivitySchema;
500
621
  exports.AuthoringFieldEntrySchema = AuthoringFieldEntrySchema;
501
622
  exports.AuthoringOpSchema = AuthoringOpSchema;
502
623
  exports.AuthoringStageSchema = AuthoringStageSchema;
503
- exports.AuthoringTaskSchema = AuthoringTaskSchema;
504
624
  exports.AuthoringTransitionSchema = AuthoringTransitionSchema;
505
625
  exports.AuthoringWorkflowSchema = AuthoringWorkflowSchema;
506
626
  exports.DOCUMENT_VALUE_PERMISSIONS = DOCUMENT_VALUE_PERMISSIONS;
@@ -508,13 +628,14 @@ exports.DRIVER_KINDS = DRIVER_KINDS;
508
628
  exports.EffectSchema = EffectSchema;
509
629
  exports.GROQ_IDENTIFIER = GROQ_IDENTIFIER;
510
630
  exports.GuardSchema = GuardSchema;
511
- exports.TASK_KINDS = TASK_KINDS;
631
+ exports.StoredFieldOpSchema = StoredFieldOpSchema;
512
632
  exports.WORKFLOW_DEFINITION_TYPE = WORKFLOW_DEFINITION_TYPE;
513
633
  exports.actorFulfillsRole = actorFulfillsRole;
514
634
  exports.andConditions = andConditions;
515
635
  exports.expandRequiredRoles = expandRequiredRoles;
516
636
  exports.formatValidationError = formatValidationError;
517
637
  exports.isStartableDefinition = isStartableDefinition;
518
- exports.isTerminalTaskStatus = isTerminalTaskStatus;
638
+ exports.isTerminalActivityStatus = isTerminalActivityStatus;
519
639
  exports.issuesFromValibot = issuesFromValibot;
640
+ exports.normalizeRoleAliases = normalizeRoleAliases;
520
641
  //# sourceMappingURL=schema.cjs.map