@sanity/workflow-engine 0.14.0 → 0.15.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/CHANGELOG.md +743 -0
- package/DATAMODEL.md +183 -0
- package/README.md +2 -2
- package/dist/_chunks-cjs/invariants.cjs +2461 -0
- package/dist/_chunks-es/invariants.js +2251 -0
- package/dist/define.cjs +673 -906
- package/dist/define.d.cts +192 -26
- package/dist/define.d.ts +192 -26
- package/dist/define.js +650 -905
- package/dist/index.cjs +9728 -5210
- package/dist/index.d.cts +2462 -323
- package/dist/index.d.ts +2462 -323
- package/dist/index.js +9358 -5273
- package/package.json +9 -5
- package/dist/_chunks-cjs/schema.cjs +0 -1289
- package/dist/_chunks-cjs/schema.cjs.map +0 -1
- package/dist/_chunks-es/schema.js +0 -1274
- package/dist/_chunks-es/schema.js.map +0 -1
- package/dist/define.cjs.map +0 -1
- package/dist/define.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -1,1274 +0,0 @@
|
|
|
1
|
-
import * as v from "valibot";
|
|
2
|
-
const KNOWN_SCHEMES = /* @__PURE__ */ new Set(["dataset", "canvas", "media-library", "dashboard"]);
|
|
3
|
-
function parseGdr(uri) {
|
|
4
|
-
const colon = uri.indexOf(":");
|
|
5
|
-
if (colon < 0)
|
|
6
|
-
throw new Error(
|
|
7
|
-
`Invalid GDR "${uri}": must be a URI of form "<scheme>:<...id-parts>". Known schemes: dataset, canvas, media-library, dashboard.`
|
|
8
|
-
);
|
|
9
|
-
const scheme = uri.slice(0, colon), rest = uri.slice(colon + 1);
|
|
10
|
-
if (!KNOWN_SCHEMES.has(scheme))
|
|
11
|
-
throw new Error(
|
|
12
|
-
`Invalid GDR "${uri}": unknown scheme "${scheme}". Known: dataset, canvas, media-library, dashboard.`
|
|
13
|
-
);
|
|
14
|
-
const parts = rest.split(":");
|
|
15
|
-
if (parts.some((part) => part.length === 0))
|
|
16
|
-
throw new Error(
|
|
17
|
-
`Invalid GDR "${uri}": id parts must be non-empty (no leading, trailing, or doubled ":").`
|
|
18
|
-
);
|
|
19
|
-
if (scheme === "dataset") {
|
|
20
|
-
if (parts.length !== 3)
|
|
21
|
-
throw new Error(
|
|
22
|
-
`Invalid GDR "${uri}": dataset scheme requires <projectId>:<dataset>:<documentId> (3 parts after scheme); got ${parts.length}.`
|
|
23
|
-
);
|
|
24
|
-
return {
|
|
25
|
-
scheme: "dataset",
|
|
26
|
-
projectId: parts[0],
|
|
27
|
-
dataset: parts[1],
|
|
28
|
-
documentId: parts[2]
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
if (parts.length !== 2)
|
|
32
|
-
throw new Error(
|
|
33
|
-
`Invalid GDR "${uri}": ${scheme} scheme requires <resourceId>:<documentId> (2 parts after scheme); got ${parts.length}.`
|
|
34
|
-
);
|
|
35
|
-
return {
|
|
36
|
-
scheme,
|
|
37
|
-
resourceId: parts[0],
|
|
38
|
-
documentId: parts[1]
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function tryParseGdr(uri) {
|
|
42
|
-
try {
|
|
43
|
-
return parseGdr(uri);
|
|
44
|
-
} catch {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function gdrUri(parts) {
|
|
49
|
-
return parts.scheme === "dataset" ? `dataset:${parts.projectId}:${parts.dataset}:${parts.documentId}` : `${parts.scheme}:${parts.resourceId}:${parts.documentId}`;
|
|
50
|
-
}
|
|
51
|
-
function extractDocumentId(gdrUriString) {
|
|
52
|
-
return parseGdr(gdrUriString).documentId;
|
|
53
|
-
}
|
|
54
|
-
const RESOURCE_ALIAS_NAME_SOURCE = "[a-z0-9][a-z0-9-]*", RESOURCE_ALIAS_NAME_RE = new RegExp(`^${RESOURCE_ALIAS_NAME_SOURCE}$`);
|
|
55
|
-
function validateResourceAliasName(name) {
|
|
56
|
-
if (!RESOURCE_ALIAS_NAME_RE.test(name))
|
|
57
|
-
throw new Error(
|
|
58
|
-
`Invalid resource alias name "${name}": expected lowercase letters, digits, and dashes (no leading dash).`
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
function toPhysicalGdr(id, home) {
|
|
62
|
-
return isGdrUri(id) ? id : gdrFromResource(home, id);
|
|
63
|
-
}
|
|
64
|
-
function refDataset({
|
|
65
|
-
projectId,
|
|
66
|
-
dataset,
|
|
67
|
-
documentId,
|
|
68
|
-
type
|
|
69
|
-
}) {
|
|
70
|
-
return { id: gdrUri({ scheme: "dataset", projectId, dataset, documentId }), type };
|
|
71
|
-
}
|
|
72
|
-
function refCanvas({
|
|
73
|
-
resourceId,
|
|
74
|
-
documentId,
|
|
75
|
-
type
|
|
76
|
-
}) {
|
|
77
|
-
return { id: gdrUri({ scheme: "canvas", resourceId, documentId }), type };
|
|
78
|
-
}
|
|
79
|
-
function refMediaLibrary({
|
|
80
|
-
resourceId,
|
|
81
|
-
documentId,
|
|
82
|
-
type
|
|
83
|
-
}) {
|
|
84
|
-
return { id: gdrUri({ scheme: "media-library", resourceId, documentId }), type };
|
|
85
|
-
}
|
|
86
|
-
function refDashboard({
|
|
87
|
-
resourceId,
|
|
88
|
-
documentId,
|
|
89
|
-
type
|
|
90
|
-
}) {
|
|
91
|
-
return { id: gdrUri({ scheme: "dashboard", resourceId, documentId }), type };
|
|
92
|
-
}
|
|
93
|
-
function datasetResourceParts(id) {
|
|
94
|
-
const dot = id.indexOf(".");
|
|
95
|
-
if (dot <= 0 || dot === id.length - 1)
|
|
96
|
-
throw new Error(`Invalid dataset resource id "${id}": expected "<projectId>.<dataset>".`);
|
|
97
|
-
return { projectId: id.slice(0, dot), dataset: id.slice(dot + 1) };
|
|
98
|
-
}
|
|
99
|
-
function gdrFromResource(res, documentId) {
|
|
100
|
-
if (res.type === "dataset") {
|
|
101
|
-
const { projectId, dataset } = datasetResourceParts(res.id);
|
|
102
|
-
return gdrUri({ scheme: "dataset", projectId, dataset, documentId });
|
|
103
|
-
}
|
|
104
|
-
return gdrUri({ scheme: res.type, resourceId: res.id, documentId });
|
|
105
|
-
}
|
|
106
|
-
function gdrResourcePrefix(res) {
|
|
107
|
-
const full = gdrFromResource(res, "x");
|
|
108
|
-
return full.slice(0, full.length - 1);
|
|
109
|
-
}
|
|
110
|
-
function resourceFromParsed(parsed) {
|
|
111
|
-
return parsed.scheme === "dataset" ? { type: "dataset", id: `${parsed.projectId}.${parsed.dataset}` } : { type: parsed.scheme, id: parsed.resourceId ?? "" };
|
|
112
|
-
}
|
|
113
|
-
function resourceFromGdrUri(uri) {
|
|
114
|
-
const parsed = tryParseGdr(uri);
|
|
115
|
-
return parsed === void 0 ? void 0 : resourceFromParsed(parsed);
|
|
116
|
-
}
|
|
117
|
-
function sameResource(a, b) {
|
|
118
|
-
return a.type === b.type && a.id === b.id;
|
|
119
|
-
}
|
|
120
|
-
function selfGdr(doc) {
|
|
121
|
-
return gdrFromResource(doc.workflowResource, doc._id);
|
|
122
|
-
}
|
|
123
|
-
function definitionDocId({
|
|
124
|
-
tag,
|
|
125
|
-
definition,
|
|
126
|
-
version
|
|
127
|
-
}) {
|
|
128
|
-
return `${tag}.${definition}.v${version}`;
|
|
129
|
-
}
|
|
130
|
-
function isGdrUri(value) {
|
|
131
|
-
return typeof value == "string" && tryParseGdr(value) !== void 0;
|
|
132
|
-
}
|
|
133
|
-
function toBareId(id) {
|
|
134
|
-
return isGdrUri(id) ? extractDocumentId(id) : id;
|
|
135
|
-
}
|
|
136
|
-
function gdrRef({
|
|
137
|
-
res,
|
|
138
|
-
documentId,
|
|
139
|
-
type
|
|
140
|
-
}) {
|
|
141
|
-
return { id: gdrFromResource(res, documentId), type };
|
|
142
|
-
}
|
|
143
|
-
function isGdr(value) {
|
|
144
|
-
return typeof value == "object" && value !== null && typeof value.id == "string" && typeof value.type == "string";
|
|
145
|
-
}
|
|
146
|
-
class WorkflowError extends Error {
|
|
147
|
-
kind;
|
|
148
|
-
// oxlint-disable-next-line max-params -- the platform `Error(message, options)` signature with the discriminant prepended
|
|
149
|
-
constructor(kind, message, options) {
|
|
150
|
-
super(message, options), this.kind = kind;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
class ContractViolationError extends WorkflowError {
|
|
154
|
-
constructor(message) {
|
|
155
|
-
super("contract-violation", message), this.name = "ContractViolationError";
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
class InstanceNotFoundError extends WorkflowError {
|
|
159
|
-
instanceId;
|
|
160
|
-
constructor(args) {
|
|
161
|
-
super(
|
|
162
|
-
"instance-not-found",
|
|
163
|
-
`Workflow instance ${args.instanceId} not found${args.detail ? ` (${args.detail})` : ""}`
|
|
164
|
-
), this.name = "InstanceNotFoundError", this.instanceId = args.instanceId;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
class DefinitionNotFoundError extends WorkflowError {
|
|
168
|
-
definition;
|
|
169
|
-
version;
|
|
170
|
-
constructor(args) {
|
|
171
|
-
super(
|
|
172
|
-
"definition-not-found",
|
|
173
|
-
args.version !== void 0 ? `Workflow definition ${args.definition} v${args.version} not deployed` : `Workflow definition ${args.definition} has no deployed versions`
|
|
174
|
-
), this.name = "DefinitionNotFoundError", this.definition = args.definition, args.version !== void 0 && (this.version = args.version);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
class DefinitionInUseError extends WorkflowError {
|
|
178
|
-
definition;
|
|
179
|
-
blockedBy;
|
|
180
|
-
constructor(args) {
|
|
181
|
-
super("definition-in-use", definitionInUseMessage(args.definition, args.blockedBy)), this.name = "DefinitionInUseError", this.definition = args.definition, this.blockedBy = args.blockedBy;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
function definitionInUseMessage(definition, blockedBy) {
|
|
185
|
-
if (blockedBy.reason === "non-terminal-instances") {
|
|
186
|
-
const head = blockedBy.instanceIds.slice(0, 3).join(", "), preview = blockedBy.instanceIds.length > 3 ? `${head}, \u2026` : head;
|
|
187
|
-
return `Cannot delete ${definition}: ${blockedBy.instanceIds.length} non-terminal instance(s) exist (${preview}). Pass cascade to abort them first \u2014 instances are aborted in place, never deleted.`;
|
|
188
|
-
}
|
|
189
|
-
const names = blockedBy.referrers.map((r) => `${r.definition} v${r.version}`).join(", ");
|
|
190
|
-
return `Cannot delete ${definition}: still spawn-referenced by deployed definition(s) ${names}. Delete or redeploy the referrer(s) first.`;
|
|
191
|
-
}
|
|
192
|
-
class EffectNotFoundError extends WorkflowError {
|
|
193
|
-
instanceId;
|
|
194
|
-
effectKey;
|
|
195
|
-
constructor(args) {
|
|
196
|
-
super(
|
|
197
|
-
"effect-not-found",
|
|
198
|
-
`Pending effect "${args.effectKey}" not found on instance ${args.instanceId}`
|
|
199
|
-
), this.name = "EffectNotFoundError", this.instanceId = args.instanceId, this.effectKey = args.effectKey;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
const TAG_RE = /^[a-z0-9][a-z0-9-]*$/;
|
|
203
|
-
function validateTag(tag) {
|
|
204
|
-
if (!TAG_RE.test(tag))
|
|
205
|
-
throw new ContractViolationError(
|
|
206
|
-
`tag: invalid tag "${tag}" \u2014 must match ${TAG_RE.source} (ASCII lowercase + digits + dashes, no leading dash, no dots)`
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
function tagScopeFilter() {
|
|
210
|
-
return "tag == $tag";
|
|
211
|
-
}
|
|
212
|
-
const NonEmptyString = v.pipe(v.string(), v.nonEmpty("must not be empty"));
|
|
213
|
-
function asPredicate(validate) {
|
|
214
|
-
return (value) => {
|
|
215
|
-
try {
|
|
216
|
-
return validate(value), !0;
|
|
217
|
-
} catch {
|
|
218
|
-
return !1;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
const isValidTag = asPredicate(validateTag), isValidAliasName = asPredicate(validateResourceAliasName), isValidDatasetId = asPredicate(datasetResourceParts), WorkflowResourceSchema = v.variant("type", [
|
|
223
|
-
v.object({
|
|
224
|
-
type: v.literal("dataset"),
|
|
225
|
-
id: v.pipe(
|
|
226
|
-
NonEmptyString,
|
|
227
|
-
v.check(isValidDatasetId, 'invalid dataset resource id \u2014 expected "<projectId>.<dataset>"')
|
|
228
|
-
)
|
|
229
|
-
}),
|
|
230
|
-
v.object({ type: v.literal("canvas"), id: NonEmptyString }),
|
|
231
|
-
v.object({ type: v.literal("media-library"), id: NonEmptyString }),
|
|
232
|
-
v.object({ type: v.literal("dashboard"), id: NonEmptyString })
|
|
233
|
-
]), ResourceBindingSchema = v.object({
|
|
234
|
-
name: v.pipe(
|
|
235
|
-
NonEmptyString,
|
|
236
|
-
v.check(
|
|
237
|
-
isValidAliasName,
|
|
238
|
-
"invalid resource handle name \u2014 lowercase letters, digits and dashes only, no leading dash"
|
|
239
|
-
)
|
|
240
|
-
),
|
|
241
|
-
resource: WorkflowResourceSchema
|
|
242
|
-
}), DefinitionSchema = v.custom(
|
|
243
|
-
(input) => typeof input == "object" && input !== null && typeof input.name == "string",
|
|
244
|
-
"expected a workflow definition (an object with a string `name`)"
|
|
245
|
-
), DeploymentSchema = v.object({
|
|
246
|
-
name: NonEmptyString,
|
|
247
|
-
tag: v.pipe(
|
|
248
|
-
v.string(),
|
|
249
|
-
v.nonEmpty(),
|
|
250
|
-
v.check(
|
|
251
|
-
isValidTag,
|
|
252
|
-
"invalid tag \u2014 lowercase letters, digits and dashes only, no leading dash, no dots"
|
|
253
|
-
)
|
|
254
|
-
),
|
|
255
|
-
workflowResource: WorkflowResourceSchema,
|
|
256
|
-
// Optional — omit for a workflow whose definitions reference no `@handle:`.
|
|
257
|
-
// No valibot default: a default makes the inferred output `resourceAliases`
|
|
258
|
-
// required (poor authoring ergonomics) and diverges input from output,
|
|
259
|
-
// which the shared `parseOrThrow` can't model. resourceAliasesToMap treats
|
|
260
|
-
// an absent map as none.
|
|
261
|
-
//
|
|
262
|
-
// Handle names must be unique: resourceAliasesToMap collapses bindings into a
|
|
263
|
-
// map, so a duplicate would silently overwrite — and the dup is gone before
|
|
264
|
-
// the engine sees it. Caught here, at the only layer that still can.
|
|
265
|
-
resourceAliases: v.optional(
|
|
266
|
-
v.pipe(
|
|
267
|
-
v.array(ResourceBindingSchema),
|
|
268
|
-
v.check(
|
|
269
|
-
(bindings) => new Set(bindings.map((binding) => binding.name)).size === bindings.length,
|
|
270
|
-
"duplicate resource handle name \u2014 each binding name must be unique within a deployment"
|
|
271
|
-
)
|
|
272
|
-
)
|
|
273
|
-
),
|
|
274
|
-
definitions: v.pipe(
|
|
275
|
-
v.array(DefinitionSchema),
|
|
276
|
-
v.minLength(1, "a deployment needs at least one definition")
|
|
277
|
-
)
|
|
278
|
-
}), WorkflowConfigSchema = v.object({
|
|
279
|
-
// Tags must be unique: a tag is the environment key the CLI selects a
|
|
280
|
-
// deployment by, so two deployments sharing one make selection ambiguous.
|
|
281
|
-
// Enforced here so the ambiguity is a config error, not a deploy-time
|
|
282
|
-
// surprise — and so consumers can treat a tag as naming one deployment.
|
|
283
|
-
deployments: v.pipe(
|
|
284
|
-
v.array(DeploymentSchema),
|
|
285
|
-
v.minLength(1, "a config needs at least one deployment"),
|
|
286
|
-
v.check(
|
|
287
|
-
(deployments) => new Set(deployments.map((deployment) => deployment.tag)).size === deployments.length,
|
|
288
|
-
"duplicate deployment tag \u2014 each deployment must use a unique tag"
|
|
289
|
-
)
|
|
290
|
-
)
|
|
291
|
-
});
|
|
292
|
-
function resourceAliasesToMap(resourceAliases) {
|
|
293
|
-
return Object.fromEntries(
|
|
294
|
-
(resourceAliases ?? []).map((binding) => [
|
|
295
|
-
binding.name,
|
|
296
|
-
binding.resource
|
|
297
|
-
])
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
function andConditions(parts) {
|
|
301
|
-
const present = parts.filter((p) => p !== void 0);
|
|
302
|
-
if (present.length !== 0)
|
|
303
|
-
return present.length === 1 ? present[0] : present.map((p) => `(${p})`).join(" && ");
|
|
304
|
-
}
|
|
305
|
-
const FIELD_READ = /^\$fields\.(\w+)(?:\.(.+))?$/, EFFECTS_READ = /^\$effects\['([^']+)'\](?:\.(.+))?$/;
|
|
306
|
-
function isGuardReadExpr(expr) {
|
|
307
|
-
return expr === "$self" || expr === "$now" || FIELD_READ.test(expr) || EFFECTS_READ.test(expr);
|
|
308
|
-
}
|
|
309
|
-
function printGuardRead(read) {
|
|
310
|
-
switch (read.type) {
|
|
311
|
-
case "self":
|
|
312
|
-
return "$self";
|
|
313
|
-
case "now":
|
|
314
|
-
return "$now";
|
|
315
|
-
case "fieldRead":
|
|
316
|
-
return read.path === void 0 ? `$fields.${read.field}` : `$fields.${read.field}.${read.path}`;
|
|
317
|
-
case "effectsRead":
|
|
318
|
-
return read.path === void 0 ? `$effects['${read.effect}']` : `$effects['${read.effect}'].${read.path}`;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
const UNIVERSAL_ROLE_ALIAS_KEY = "$all";
|
|
322
|
-
function normalizeRoleAliases(aliases) {
|
|
323
|
-
if (aliases === void 0 || !("*" in aliases)) return aliases;
|
|
324
|
-
const { ["*"]: universal, ...perRole } = aliases;
|
|
325
|
-
return { ...perRole, [UNIVERSAL_ROLE_ALIAS_KEY]: universal };
|
|
326
|
-
}
|
|
327
|
-
function expandRequiredRoles(required, aliases) {
|
|
328
|
-
if (aliases === void 0) return [...required];
|
|
329
|
-
const out = /* @__PURE__ */ new Set();
|
|
330
|
-
for (const role of required) {
|
|
331
|
-
out.add(role);
|
|
332
|
-
for (const fulfiller of aliases[role] ?? []) out.add(fulfiller);
|
|
333
|
-
}
|
|
334
|
-
for (const fulfiller of aliases[UNIVERSAL_ROLE_ALIAS_KEY] ?? []) out.add(fulfiller);
|
|
335
|
-
return [...out];
|
|
336
|
-
}
|
|
337
|
-
function actorFulfillsRole({
|
|
338
|
-
actorRoles,
|
|
339
|
-
required,
|
|
340
|
-
aliases
|
|
341
|
-
}) {
|
|
342
|
-
if (actorRoles === void 0 || actorRoles.length === 0) return !1;
|
|
343
|
-
const accepted = new Set(expandRequiredRoles([required], aliases));
|
|
344
|
-
return actorRoles.some((role) => accepted.has(role));
|
|
345
|
-
}
|
|
346
|
-
const CONDITION_VARS = [
|
|
347
|
-
{
|
|
348
|
-
name: "self",
|
|
349
|
-
binding: "always",
|
|
350
|
-
description: "GDR URI of the instance document itself \u2014 `*[_id == $self][0]` reads the instance in the snapshot."
|
|
351
|
-
},
|
|
352
|
-
{
|
|
353
|
-
name: "fields",
|
|
354
|
-
binding: "always",
|
|
355
|
-
description: "Declared field entries rendered by name (`$fields.<name>` is the value, no envelope). Stage/activity scopes overlay lexically; `doc.ref` values render the hydrated document when the snapshot holds it."
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
name: "parent",
|
|
359
|
-
binding: "always",
|
|
360
|
-
description: "The parent instance's GDR URI, `null` on a root instance."
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
name: "ancestors",
|
|
364
|
-
binding: "always",
|
|
365
|
-
description: "GDR URIs of the ancestor chain, root first."
|
|
366
|
-
},
|
|
367
|
-
{ name: "stage", binding: "always", description: "The current stage's name." },
|
|
368
|
-
{
|
|
369
|
-
name: "now",
|
|
370
|
-
binding: "always",
|
|
371
|
-
description: "The ISO clock reading shared by every condition in one evaluation pass, so they agree on the time."
|
|
372
|
-
},
|
|
373
|
-
{
|
|
374
|
-
name: "effects",
|
|
375
|
-
binding: "always",
|
|
376
|
-
description: "The `effectsContext` map: stable handler params seeded at start plus completed effects' outputs namespaced by effect name (`$effects['<effect>'].<output>`). Handler fuel \u2014 transition filters should read instance/lake state (or $effectStatus) instead."
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
name: "effectStatus",
|
|
380
|
-
binding: "always",
|
|
381
|
-
description: "Effect name \u2192 `'done'` | `'failed'` of the latest completed run queued during the current stage entry; absent until the effect drains for this entry. Re-entry-safe: runs queued under a prior entry never count, so `$effectStatus['<effect>'] == 'done'` (or `defined($effectStatus['<effect>'])` for settled-either-way) waits for the fresh run."
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
name: "activities",
|
|
385
|
-
binding: "always",
|
|
386
|
-
description: "The current stage's activity rows, statuses included."
|
|
387
|
-
},
|
|
388
|
-
{
|
|
389
|
-
name: "allActivitiesDone",
|
|
390
|
-
binding: "always",
|
|
391
|
-
description: "Every current-stage activity is `done` or `skipped` \u2014 the default transition gate."
|
|
392
|
-
},
|
|
393
|
-
{
|
|
394
|
-
name: "anyActivityFailed",
|
|
395
|
-
binding: "always",
|
|
396
|
-
description: "Some current-stage activity is `failed`."
|
|
397
|
-
},
|
|
398
|
-
{
|
|
399
|
-
name: "actor",
|
|
400
|
-
binding: "caller",
|
|
401
|
-
description: "The acting identity (id + roles); `undefined` when no caller rides the evaluation."
|
|
402
|
-
},
|
|
403
|
-
{
|
|
404
|
-
name: "assigned",
|
|
405
|
-
binding: "caller",
|
|
406
|
-
description: "Whether the caller matches the activity's assignees-kind field entry (by user id, or by a role under the definition's `roleAliases`); `false` outside an activity context."
|
|
407
|
-
},
|
|
408
|
-
{
|
|
409
|
-
name: "can",
|
|
410
|
-
binding: "caller",
|
|
411
|
-
description: "Advisory per-permission booleans computed from the caller's grants; `undefined` without grants. Bound only while an action fires, so it may appear in action filters only (deploy-enforced)."
|
|
412
|
-
},
|
|
413
|
-
{
|
|
414
|
-
name: "row",
|
|
415
|
-
binding: "spawn",
|
|
416
|
-
description: "One `subworkflows.forEach` result row, bound while its `with` map evaluates \u2014 and the row under test while a where-op `where` evaluates (per row)."
|
|
417
|
-
},
|
|
418
|
-
{
|
|
419
|
-
name: "params",
|
|
420
|
-
binding: "caller",
|
|
421
|
-
description: "The firing action's args \u2014 bound while its effect bindings and where-op `where` conditions evaluate."
|
|
422
|
-
},
|
|
423
|
-
{
|
|
424
|
-
name: "subworkflows",
|
|
425
|
-
binding: "spawn",
|
|
426
|
-
description: "The spawned child rows (status included) of the spawning activity, bound for its `completeWhen`/`failWhen` \u2014 the implicit completion gate reads it."
|
|
427
|
-
}
|
|
428
|
-
], RESERVED_CONDITION_VARS = CONDITION_VARS.map((v2) => v2.name), FILTER_SCOPE_VARS = CONDITION_VARS.filter(
|
|
429
|
-
(v2) => v2.binding === "always"
|
|
430
|
-
).map((v2) => v2.name), GUARD_PREDICATE_VARS = [
|
|
431
|
-
{
|
|
432
|
-
name: "guard",
|
|
433
|
-
description: "The guard document itself (its `metadata` carries deploy-time resolved values)."
|
|
434
|
-
},
|
|
435
|
-
{
|
|
436
|
-
name: "mutation",
|
|
437
|
-
description: "The attempted mutation \u2014 `mutation.action` is the write kind being gated."
|
|
438
|
-
}
|
|
439
|
-
], ACTOR_KINDS = ["person", "agent", "system"];
|
|
440
|
-
class FieldValueShapeError extends WorkflowError {
|
|
441
|
-
entryType;
|
|
442
|
-
entryName;
|
|
443
|
-
issues;
|
|
444
|
-
constructor(args) {
|
|
445
|
-
const issueText = args.issues.join("; ");
|
|
446
|
-
super(
|
|
447
|
-
"field-value-shape",
|
|
448
|
-
`Field entry ${args.mode} shape invalid for "${args.entryName}" (${args.entryType}): ${issueText}`
|
|
449
|
-
), this.name = "FieldValueShapeError", this.entryType = args.entryType, this.entryName = args.entryName, this.issues = args.issues;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
const GdrShape = v.looseObject({
|
|
453
|
-
id: v.pipe(
|
|
454
|
-
v.string(),
|
|
455
|
-
v.check((s) => isGdrUri(s), "must be a GDR URI")
|
|
456
|
-
),
|
|
457
|
-
type: v.pipe(v.string(), v.minLength(1))
|
|
458
|
-
}), ReleaseRefShape = v.looseObject({
|
|
459
|
-
id: v.pipe(
|
|
460
|
-
v.string(),
|
|
461
|
-
v.check((s) => isGdrUri(s), "must be a GDR URI")
|
|
462
|
-
),
|
|
463
|
-
type: v.literal("system.release"),
|
|
464
|
-
releaseName: v.pipe(v.string(), v.minLength(1))
|
|
465
|
-
}), ActorShape = v.looseObject({
|
|
466
|
-
kind: v.picklist(ACTOR_KINDS),
|
|
467
|
-
id: v.pipe(v.string(), v.minLength(1)),
|
|
468
|
-
roles: v.optional(v.array(v.string())),
|
|
469
|
-
onBehalfOf: v.optional(v.string())
|
|
470
|
-
}), AssigneeShape = v.union([
|
|
471
|
-
v.looseObject({ type: v.literal("user"), id: v.pipe(v.string(), v.minLength(1)) }),
|
|
472
|
-
v.looseObject({ type: v.literal("role"), role: v.pipe(v.string(), v.minLength(1)) })
|
|
473
|
-
]), NullableString = v.union([v.null(), v.string()]), NullableNumber = v.union([v.null(), v.number()]), NullableBoolean = v.union([v.null(), v.boolean()]), NullableDateTime = v.union([
|
|
474
|
-
v.null(),
|
|
475
|
-
v.pipe(
|
|
476
|
-
v.string(),
|
|
477
|
-
v.check((s) => !Number.isNaN(Date.parse(s)), "must be an ISO-8601 datetime string")
|
|
478
|
-
)
|
|
479
|
-
]), NullableDate = v.union([
|
|
480
|
-
v.null(),
|
|
481
|
-
v.pipe(v.string(), v.regex(/^\d{4}-\d{2}-\d{2}$/, "must be a `YYYY-MM-DD` date"))
|
|
482
|
-
]), NullableUrl = NullableString, valueSchemas = {
|
|
483
|
-
"doc.ref": v.union([v.null(), GdrShape]),
|
|
484
|
-
"doc.refs": v.array(GdrShape),
|
|
485
|
-
"release.ref": v.union([v.null(), ReleaseRefShape]),
|
|
486
|
-
query: v.any(),
|
|
487
|
-
string: NullableString,
|
|
488
|
-
text: NullableString,
|
|
489
|
-
number: NullableNumber,
|
|
490
|
-
boolean: NullableBoolean,
|
|
491
|
-
date: NullableDate,
|
|
492
|
-
datetime: NullableDateTime,
|
|
493
|
-
url: NullableUrl,
|
|
494
|
-
actor: v.union([v.null(), ActorShape]),
|
|
495
|
-
assignee: v.union([v.null(), AssigneeShape]),
|
|
496
|
-
assignees: v.array(AssigneeShape)
|
|
497
|
-
};
|
|
498
|
-
function shapeValueSchema(shape, leaf) {
|
|
499
|
-
return shape.type === "object" ? objectSchema(shape.fields ?? [], leaf) : shape.type === "array" ? v.array(objectSchema(shape.of ?? [], leaf)) : leaf[shape.type] ?? v.any();
|
|
500
|
-
}
|
|
501
|
-
function objectSchema(fields, leaf) {
|
|
502
|
-
const entries = /* @__PURE__ */ Object.create(null);
|
|
503
|
-
for (const f of fields) entries[f.name] = v.optional(shapeValueSchema(f, leaf));
|
|
504
|
-
return v.looseObject(entries);
|
|
505
|
-
}
|
|
506
|
-
function wholeValueSchema(args) {
|
|
507
|
-
const { entryType, shape, leaf } = args;
|
|
508
|
-
return entryType === "object" ? v.union([v.null(), objectSchema(shape.fields ?? [], leaf)]) : entryType === "array" ? v.array(objectSchema(shape.of ?? [], leaf)) : leaf[entryType];
|
|
509
|
-
}
|
|
510
|
-
function appendItemSchema(entryType, shape) {
|
|
511
|
-
if (entryType === "array") return objectSchema(shape.of ?? [], valueSchemas);
|
|
512
|
-
if (entryType === "doc.refs") return GdrShape;
|
|
513
|
-
if (entryType === "assignees") return AssigneeShape;
|
|
514
|
-
}
|
|
515
|
-
function checkFieldValue(args) {
|
|
516
|
-
return checkValueAgainst(args, valueSchemas);
|
|
517
|
-
}
|
|
518
|
-
function checkValueAgainst(args, leaf) {
|
|
519
|
-
const schema = wholeValueSchema({ entryType: args.entryType, shape: args, leaf });
|
|
520
|
-
if (schema === void 0) return [`unknown field entry type ${args.entryType}`];
|
|
521
|
-
const result = v.safeParse(schema, args.value);
|
|
522
|
-
return result.success ? void 0 : formatIssues(result.issues);
|
|
523
|
-
}
|
|
524
|
-
function validateFieldValue(args) {
|
|
525
|
-
const issues = checkFieldValue(args);
|
|
526
|
-
if (issues !== void 0)
|
|
527
|
-
throw new FieldValueShapeError({
|
|
528
|
-
entryType: args.entryType,
|
|
529
|
-
entryName: args.entryName,
|
|
530
|
-
issues,
|
|
531
|
-
mode: "value"
|
|
532
|
-
});
|
|
533
|
-
}
|
|
534
|
-
const BARE_ID_SOURCE = "[A-Za-z0-9_][A-Za-z0-9._-]*", BARE_ID_RE = new RegExp(`^${BARE_ID_SOURCE}$`), ALIAS_REF_RE = new RegExp(`^@${RESOURCE_ALIAS_NAME_SOURCE}:${BARE_ID_SOURCE}$`);
|
|
535
|
-
function isAuthoringRefId(id) {
|
|
536
|
-
return id.startsWith("@") ? ALIAS_REF_RE.test(id) : id.includes(":") ? isGdrUri(id) : BARE_ID_RE.test(id);
|
|
537
|
-
}
|
|
538
|
-
function isBareSeedId(id) {
|
|
539
|
-
return BARE_ID_RE.test(id);
|
|
540
|
-
}
|
|
541
|
-
const AuthoringRefId = v.pipe(
|
|
542
|
-
v.string(),
|
|
543
|
-
v.check(
|
|
544
|
-
isAuthoringRefId,
|
|
545
|
-
"must be a bare document id, a GDR URI, or a portable `@<alias>:<id>` reference"
|
|
546
|
-
)
|
|
547
|
-
), AuthoringGdrShape = v.looseObject({
|
|
548
|
-
id: AuthoringRefId,
|
|
549
|
-
type: v.pipe(v.string(), v.minLength(1))
|
|
550
|
-
}), seedValueSchemas = {
|
|
551
|
-
...valueSchemas,
|
|
552
|
-
"doc.ref": v.union([v.null(), AuthoringGdrShape]),
|
|
553
|
-
"doc.refs": v.array(AuthoringGdrShape),
|
|
554
|
-
"release.ref": v.union([
|
|
555
|
-
v.null(),
|
|
556
|
-
v.looseObject({
|
|
557
|
-
id: AuthoringRefId,
|
|
558
|
-
type: v.literal("system.release"),
|
|
559
|
-
releaseName: v.pipe(v.string(), v.minLength(1))
|
|
560
|
-
})
|
|
561
|
-
])
|
|
562
|
-
};
|
|
563
|
-
function checkLiteralSeed(args) {
|
|
564
|
-
return args.value === null ? ["a literal seed cannot be null \u2014 omit `initialValue` to start the field empty"] : checkValueAgainst(args, seedValueSchemas);
|
|
565
|
-
}
|
|
566
|
-
function validateFieldAppendItem(args) {
|
|
567
|
-
const schema = appendItemSchema(args.entryType, args);
|
|
568
|
-
if (schema === void 0)
|
|
569
|
-
throw new FieldValueShapeError({
|
|
570
|
-
entryType: args.entryType,
|
|
571
|
-
entryName: args.entryName,
|
|
572
|
-
issues: [`field entry type ${args.entryType} does not support append`],
|
|
573
|
-
mode: "item"
|
|
574
|
-
});
|
|
575
|
-
const result = v.safeParse(schema, args.item);
|
|
576
|
-
if (!result.success)
|
|
577
|
-
throw new FieldValueShapeError({
|
|
578
|
-
entryType: args.entryType,
|
|
579
|
-
entryName: args.entryName,
|
|
580
|
-
issues: formatIssues(result.issues),
|
|
581
|
-
mode: "item"
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
function formatIssues(issues) {
|
|
585
|
-
return issues.map((i) => {
|
|
586
|
-
const keys = i.path?.map((p) => p.key) ?? [];
|
|
587
|
-
return `${keys.length > 0 ? `at ${keys.join(".")}: ` : ""}${i.message}`;
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
const ACTIVITY_STATUSES = ["pending", "active", "done", "skipped", "failed"], TERMINAL_ACTIVITY_STATUSES = ["done", "skipped", "failed"];
|
|
591
|
-
function isTerminalActivityStatus(status) {
|
|
592
|
-
return TERMINAL_ACTIVITY_STATUSES.includes(status);
|
|
593
|
-
}
|
|
594
|
-
const FIELD_SCOPES = ["workflow", "stage", "activity"], DOCUMENT_VALUE_PERMISSIONS = ["create", "read", "update"], MUTATION_GUARD_ACTIONS = [
|
|
595
|
-
"create",
|
|
596
|
-
"update",
|
|
597
|
-
"delete",
|
|
598
|
-
"publish",
|
|
599
|
-
"unpublish"
|
|
600
|
-
], ACTIVITY_KINDS = ["user", "service", "script", "manual", "receive"], DRIVER_KINDS = ["person", "agent", "service", "engine"], NonEmpty = v.pipe(v.string(), v.minLength(1, "must be a non-empty string")), PositiveInt = v.pipe(v.number(), v.integer(), v.minValue(1)), GROQ_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
601
|
-
function groqIdentifier(referencedAs) {
|
|
602
|
-
return v.pipe(
|
|
603
|
-
v.string(),
|
|
604
|
-
v.regex(
|
|
605
|
-
GROQ_IDENTIFIER,
|
|
606
|
-
`must be a GROQ-safe identifier (letters, digits, underscore; not starting with a digit) because it is referenced as ${referencedAs} in GROQ conditions`
|
|
607
|
-
)
|
|
608
|
-
);
|
|
609
|
-
}
|
|
610
|
-
function picklist(options) {
|
|
611
|
-
return v.picklist(
|
|
612
|
-
options,
|
|
613
|
-
`Invalid option: expected one of ${options.map((o) => `"${o}"`).join("|")}`
|
|
614
|
-
);
|
|
615
|
-
}
|
|
616
|
-
function pinned() {
|
|
617
|
-
return (schema, ..._exact) => schema;
|
|
618
|
-
}
|
|
619
|
-
const LiteralSchema = v.strictObject({ type: v.literal("literal"), value: v.unknown() }), FieldReadSchema = v.strictObject({
|
|
620
|
-
type: v.literal("fieldRead"),
|
|
621
|
-
scope: v.optional(v.union([v.literal("workflow"), v.literal("stage")])),
|
|
622
|
-
field: NonEmpty,
|
|
623
|
-
path: v.optional(v.string())
|
|
624
|
-
}), FieldSourceSchema = v.union([
|
|
625
|
-
// The caller supplies it at start/spawn (`initialFields` / `subworkflows.with`).
|
|
626
|
-
v.strictObject({ type: v.literal("input") }),
|
|
627
|
-
// Computed once by running GROQ against the lake at materialisation.
|
|
628
|
-
v.strictObject({ type: v.literal("query"), query: NonEmpty }),
|
|
629
|
-
LiteralSchema,
|
|
630
|
-
FieldReadSchema
|
|
631
|
-
]), ValueExprSchema = v.lazy(
|
|
632
|
-
() => v.union([
|
|
633
|
-
LiteralSchema,
|
|
634
|
-
FieldReadSchema,
|
|
635
|
-
v.strictObject({ type: v.literal("param"), param: NonEmpty }),
|
|
636
|
-
v.strictObject({ type: v.literal("actor") }),
|
|
637
|
-
v.strictObject({ type: v.literal("now") }),
|
|
638
|
-
v.strictObject({ type: v.literal("self") }),
|
|
639
|
-
v.strictObject({ type: v.literal("stage") }),
|
|
640
|
-
v.strictObject({ type: v.literal("object"), fields: v.record(NonEmpty, ValueExprSchema) })
|
|
641
|
-
])
|
|
642
|
-
), StoredFieldRefSchema = v.strictObject({
|
|
643
|
-
scope: picklist(FIELD_SCOPES),
|
|
644
|
-
field: NonEmpty
|
|
645
|
-
}), AuthoringFieldRefSchema = v.strictObject({
|
|
646
|
-
scope: v.optional(picklist(FIELD_SCOPES)),
|
|
647
|
-
field: NonEmpty
|
|
648
|
-
}), HREF_SCHEMES = ["http:", "https:"];
|
|
649
|
-
function isHttpUrl(value) {
|
|
650
|
-
try {
|
|
651
|
-
return HREF_SCHEMES.includes(new URL(value).protocol);
|
|
652
|
-
} catch {
|
|
653
|
-
return !1;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
const UrlString = v.pipe(
|
|
657
|
-
v.string(),
|
|
658
|
-
v.url("must be a valid URL"),
|
|
659
|
-
v.check(isHttpUrl, "must be an http(s) URL")
|
|
660
|
-
);
|
|
661
|
-
function manualTargetSchema(ref) {
|
|
662
|
-
return v.variant("type", [
|
|
663
|
-
v.strictObject({ type: v.literal("url"), url: UrlString }),
|
|
664
|
-
v.strictObject({ type: v.literal("field"), field: ref })
|
|
665
|
-
]);
|
|
666
|
-
}
|
|
667
|
-
const StoredManualTargetSchema = manualTargetSchema(StoredFieldRefSchema), AuthoringManualTargetSchema = manualTargetSchema(v.union([NonEmpty, AuthoringFieldRefSchema])), ConditionSchema = NonEmpty;
|
|
668
|
-
function opSchemas(targetSchema) {
|
|
669
|
-
return [
|
|
670
|
-
v.strictObject({
|
|
671
|
-
type: v.literal("field.set"),
|
|
672
|
-
target: targetSchema,
|
|
673
|
-
value: ValueExprSchema
|
|
674
|
-
}),
|
|
675
|
-
v.strictObject({
|
|
676
|
-
type: v.literal("field.unset"),
|
|
677
|
-
target: targetSchema
|
|
678
|
-
}),
|
|
679
|
-
v.strictObject({
|
|
680
|
-
type: v.literal("field.append"),
|
|
681
|
-
target: targetSchema,
|
|
682
|
-
value: ValueExprSchema
|
|
683
|
-
}),
|
|
684
|
-
v.strictObject({
|
|
685
|
-
type: v.literal("field.updateWhere"),
|
|
686
|
-
target: targetSchema,
|
|
687
|
-
where: ConditionSchema,
|
|
688
|
-
value: ValueExprSchema
|
|
689
|
-
}),
|
|
690
|
-
v.strictObject({
|
|
691
|
-
type: v.literal("field.removeWhere"),
|
|
692
|
-
target: targetSchema,
|
|
693
|
-
where: ConditionSchema
|
|
694
|
-
})
|
|
695
|
-
];
|
|
696
|
-
}
|
|
697
|
-
const StoredFieldOpSchema = v.variant("type", [...opSchemas(StoredFieldRefSchema)]), StoredOpSchema = v.variant("type", [
|
|
698
|
-
...opSchemas(StoredFieldRefSchema),
|
|
699
|
-
v.strictObject({
|
|
700
|
-
type: v.literal("status.set"),
|
|
701
|
-
activity: NonEmpty,
|
|
702
|
-
status: picklist(ACTIVITY_STATUSES)
|
|
703
|
-
})
|
|
704
|
-
]), StoredTransitionOpSchema = StoredFieldOpSchema, AuditOpSchema = v.strictObject({
|
|
705
|
-
type: v.literal("audit"),
|
|
706
|
-
target: AuthoringFieldRefSchema,
|
|
707
|
-
value: ValueExprSchema,
|
|
708
|
-
stampFields: v.optional(
|
|
709
|
-
v.strictObject({
|
|
710
|
-
actor: v.optional(NonEmpty),
|
|
711
|
-
at: v.optional(NonEmpty)
|
|
712
|
-
})
|
|
713
|
-
)
|
|
714
|
-
}), AuthoringOpSchema = v.variant("type", [
|
|
715
|
-
...opSchemas(AuthoringFieldRefSchema),
|
|
716
|
-
v.strictObject({
|
|
717
|
-
type: v.literal("status.set"),
|
|
718
|
-
activity: v.optional(NonEmpty),
|
|
719
|
-
status: picklist(ACTIVITY_STATUSES)
|
|
720
|
-
}),
|
|
721
|
-
AuditOpSchema
|
|
722
|
-
]), FIELD_VALUE_KINDS = [
|
|
723
|
-
"doc.ref",
|
|
724
|
-
"doc.refs",
|
|
725
|
-
// Release reference. A workflow declares this entry to say "I target a
|
|
726
|
-
// Content Release"; the runtime fills it at start time and auto-derives
|
|
727
|
-
// the instance's read perspective from it.
|
|
728
|
-
"release.ref",
|
|
729
|
-
"string",
|
|
730
|
-
"text",
|
|
731
|
-
"number",
|
|
732
|
-
"boolean",
|
|
733
|
-
"date",
|
|
734
|
-
"datetime",
|
|
735
|
-
"url",
|
|
736
|
-
"actor",
|
|
737
|
-
// A single {@link Assignee} — the singular of `assignees`.
|
|
738
|
-
"assignee",
|
|
739
|
-
// The WHO-FOR entry: the inbox reverse-query reads it by kind, and the
|
|
740
|
-
// rendered `$assigned` gate matches the caller against it.
|
|
741
|
-
"assignees",
|
|
742
|
-
// Compositional kinds — mirror Sanity's `object.fields` / `array.of`.
|
|
743
|
-
"object",
|
|
744
|
-
"array"
|
|
745
|
-
], FieldValueKindSchema = picklist(FIELD_VALUE_KINDS), FieldKindSchema = picklist(FIELD_VALUE_KINDS), FieldEntryName = groqIdentifier("`$fields.<name>`");
|
|
746
|
-
function asShape(input) {
|
|
747
|
-
return typeof input == "object" && input !== null ? input : {};
|
|
748
|
-
}
|
|
749
|
-
function compositeShapeOk(input) {
|
|
750
|
-
const shape = asShape(input);
|
|
751
|
-
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;
|
|
752
|
-
}
|
|
753
|
-
function compositeShapeMessage(input) {
|
|
754
|
-
const shape = asShape(input);
|
|
755
|
-
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)}"`;
|
|
756
|
-
}
|
|
757
|
-
function duplicateSubfieldName(input) {
|
|
758
|
-
const shape = asShape(input);
|
|
759
|
-
let list = [];
|
|
760
|
-
Array.isArray(shape.fields) ? list = shape.fields : Array.isArray(shape.of) && (list = shape.of);
|
|
761
|
-
const seen = /* @__PURE__ */ new Set();
|
|
762
|
-
for (const item of list) {
|
|
763
|
-
const name = asShape(item).name;
|
|
764
|
-
if (typeof name == "string") {
|
|
765
|
-
if (seen.has(name)) return name;
|
|
766
|
-
seen.add(name);
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
function compositeChecked(entries) {
|
|
771
|
-
return v.pipe(
|
|
772
|
-
v.strictObject(entries),
|
|
773
|
-
v.check(
|
|
774
|
-
(input) => compositeShapeOk(input),
|
|
775
|
-
(issue) => compositeShapeMessage(issue.input)
|
|
776
|
-
),
|
|
777
|
-
v.check(
|
|
778
|
-
(input) => duplicateSubfieldName(input) === void 0,
|
|
779
|
-
(issue) => `duplicate sub-field name "${duplicateSubfieldName(issue.input)}" \u2014 sub-field names must be unique within \`fields\` / \`of\``
|
|
780
|
-
)
|
|
781
|
-
);
|
|
782
|
-
}
|
|
783
|
-
const FieldShapeSchema = v.lazy(
|
|
784
|
-
() => compositeChecked({
|
|
785
|
-
type: FieldValueKindSchema,
|
|
786
|
-
name: FieldEntryName,
|
|
787
|
-
title: v.optional(v.string()),
|
|
788
|
-
description: v.optional(v.string()),
|
|
789
|
-
fields: v.optional(v.array(FieldShapeSchema)),
|
|
790
|
-
of: v.optional(v.array(FieldShapeSchema))
|
|
791
|
-
})
|
|
792
|
-
), StoredEditableSchema = v.union([v.literal(!0), NonEmpty]), AuthoringEditableSchema = v.union([v.literal(!0), v.array(NonEmpty), NonEmpty]);
|
|
793
|
-
function fieldBase(editable) {
|
|
794
|
-
return {
|
|
795
|
-
name: FieldEntryName,
|
|
796
|
-
title: v.optional(v.string()),
|
|
797
|
-
description: v.optional(v.string()),
|
|
798
|
-
/**
|
|
799
|
-
* When true, the caller MUST supply this entry at start (via
|
|
800
|
-
* `initialFields`) or spawn (via the parent's `subworkflows.with`). A
|
|
801
|
-
* missing required entry throws rather than silently defaulting to
|
|
802
|
-
* `null`/`[]` — the same fail-fast an action's `required` param gets.
|
|
803
|
-
* Valid only on a workflow-scope `input`-sourced entry (deploy invariant).
|
|
804
|
-
*/
|
|
805
|
-
required: v.optional(v.boolean()),
|
|
806
|
-
/**
|
|
807
|
-
* How this field SEEDS its value at materialisation — see
|
|
808
|
-
* {@link FieldSourceSchema}. Optional: an absent `initialValue` is working
|
|
809
|
-
* memory (the field starts empty and an op fills it later), the common case.
|
|
810
|
-
*/
|
|
811
|
-
initialValue: v.optional(FieldSourceSchema),
|
|
812
|
-
/** Who-may-edit this field via the edit seam — see {@link StoredEditableSchema}. */
|
|
813
|
-
editable: v.optional(editable)
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
function fieldEntryFields(editable) {
|
|
817
|
-
return {
|
|
818
|
-
type: FieldKindSchema,
|
|
819
|
-
...fieldBase(editable),
|
|
820
|
-
/** Sub-field shapes for an `object` kind (see {@link compositeShapeOk}). */
|
|
821
|
-
fields: v.optional(v.array(FieldShapeSchema)),
|
|
822
|
-
/** Item sub-field shapes for an `array` kind (see {@link compositeShapeOk}). */
|
|
823
|
-
of: v.optional(v.array(FieldShapeSchema))
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
function literalSeedIssues(entry) {
|
|
827
|
-
if (entry.initialValue?.type === "literal")
|
|
828
|
-
return checkLiteralSeed({
|
|
829
|
-
entryType: entry.type,
|
|
830
|
-
value: entry.initialValue.value,
|
|
831
|
-
fields: entry.fields,
|
|
832
|
-
of: entry.of
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
function literalSeedCheck() {
|
|
836
|
-
return v.check(
|
|
837
|
-
(entry) => literalSeedIssues(entry) === void 0,
|
|
838
|
-
(issue) => `initialValue literal does not fit the declared kind: ${(literalSeedIssues(issue.input) ?? []).join("; ")}`
|
|
839
|
-
);
|
|
840
|
-
}
|
|
841
|
-
const FieldEntrySchema = pinned()(
|
|
842
|
-
v.pipe(compositeChecked(fieldEntryFields(StoredEditableSchema)), literalSeedCheck())
|
|
843
|
-
), RawAuthoringFieldEntrySchema = pinned()(
|
|
844
|
-
v.pipe(
|
|
845
|
-
compositeChecked(fieldEntryFields(AuthoringEditableSchema)),
|
|
846
|
-
literalSeedCheck()
|
|
847
|
-
)
|
|
848
|
-
), ClaimFieldSchema = pinned()(
|
|
849
|
-
v.strictObject({
|
|
850
|
-
type: v.literal("claim"),
|
|
851
|
-
name: FieldEntryName,
|
|
852
|
-
title: v.optional(v.string()),
|
|
853
|
-
description: v.optional(v.string())
|
|
854
|
-
})
|
|
855
|
-
);
|
|
856
|
-
function listSugarFields(type) {
|
|
857
|
-
return {
|
|
858
|
-
type: v.literal(type),
|
|
859
|
-
...fieldBase(AuthoringEditableSchema)
|
|
860
|
-
};
|
|
861
|
-
}
|
|
862
|
-
const TodoListFieldSchema = pinned()(v.strictObject(listSugarFields("todoList"))), NotesFieldSchema = pinned()(v.strictObject(listSugarFields("notes"))), AuthoringFieldEntrySchema = pinned()(
|
|
863
|
-
v.union([RawAuthoringFieldEntrySchema, ClaimFieldSchema, TodoListFieldSchema, NotesFieldSchema])
|
|
864
|
-
), EffectSchema = v.strictObject({
|
|
865
|
-
name: NonEmpty,
|
|
866
|
-
title: v.optional(v.string()),
|
|
867
|
-
description: v.optional(v.string()),
|
|
868
|
-
/** GROQ reads over the rendered scope, resolved to concrete JSON at queue time. */
|
|
869
|
-
bindings: v.optional(v.record(v.string(), ConditionSchema)),
|
|
870
|
-
/** Static config, passed through to the handler verbatim. */
|
|
871
|
-
input: v.optional(v.record(v.string(), v.unknown()))
|
|
872
|
-
}), ActionParamSchema = v.strictObject({
|
|
873
|
-
type: picklist([
|
|
874
|
-
"string",
|
|
875
|
-
"number",
|
|
876
|
-
"boolean",
|
|
877
|
-
"url",
|
|
878
|
-
"dateTime",
|
|
879
|
-
"actor",
|
|
880
|
-
"doc.ref",
|
|
881
|
-
"doc.refs",
|
|
882
|
-
"json"
|
|
883
|
-
]),
|
|
884
|
-
name: NonEmpty,
|
|
885
|
-
title: v.optional(v.string()),
|
|
886
|
-
description: v.optional(v.string()),
|
|
887
|
-
required: v.optional(v.boolean())
|
|
888
|
-
});
|
|
889
|
-
function actionFields(op) {
|
|
890
|
-
return {
|
|
891
|
-
name: NonEmpty,
|
|
892
|
-
title: v.optional(v.string()),
|
|
893
|
-
description: v.optional(v.string()),
|
|
894
|
-
/**
|
|
895
|
-
* The one gate mechanism: a condition over the rendered scope. Hard
|
|
896
|
-
* enforcement lives outside the engine; every engine-evaluated gate is
|
|
897
|
-
* authoring/UX.
|
|
898
|
-
*/
|
|
899
|
-
filter: v.optional(ConditionSchema),
|
|
900
|
-
params: v.optional(v.array(ActionParamSchema)),
|
|
901
|
-
ops: v.optional(v.array(op)),
|
|
902
|
-
effects: v.optional(v.array(EffectSchema))
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
const StoredActionSchema = pinned()(v.strictObject(actionFields(StoredOpSchema))), TerminalActivityStatus = picklist(TERMINAL_ACTIVITY_STATUSES), RawAuthoringActionSchema = pinned()(
|
|
906
|
-
v.strictObject({
|
|
907
|
-
...actionFields(AuthoringOpSchema),
|
|
908
|
-
roles: v.optional(v.array(NonEmpty)),
|
|
909
|
-
status: v.optional(TerminalActivityStatus)
|
|
910
|
-
})
|
|
911
|
-
), ClaimActionSchema = pinned()(
|
|
912
|
-
v.strictObject({
|
|
913
|
-
type: v.literal("claim"),
|
|
914
|
-
name: NonEmpty,
|
|
915
|
-
title: v.optional(v.string()),
|
|
916
|
-
description: v.optional(v.string()),
|
|
917
|
-
field: v.union([NonEmpty, AuthoringFieldRefSchema]),
|
|
918
|
-
roles: v.optional(v.array(NonEmpty)),
|
|
919
|
-
filter: v.optional(ConditionSchema),
|
|
920
|
-
params: v.optional(v.array(ActionParamSchema)),
|
|
921
|
-
effects: v.optional(v.array(EffectSchema))
|
|
922
|
-
})
|
|
923
|
-
), AuthoringActionSchema = pinned()(
|
|
924
|
-
v.union([RawAuthoringActionSchema, ClaimActionSchema])
|
|
925
|
-
), DefinitionRefSchema = v.strictObject({
|
|
926
|
-
name: NonEmpty,
|
|
927
|
-
version: v.optional(v.union([PositiveInt, v.literal("latest")]))
|
|
928
|
-
}), SubworkflowsSchema = v.strictObject({
|
|
929
|
-
/** GROQ producing one row per subworkflow; each row binds as `$row`. */
|
|
930
|
-
forEach: NonEmpty,
|
|
931
|
-
definition: DefinitionRefSchema,
|
|
932
|
-
/** Initial fields for each subworkflow — entry name → GROQ over `$row` + the parent scope. */
|
|
933
|
-
with: v.optional(v.record(NonEmpty, ConditionSchema)),
|
|
934
|
-
/**
|
|
935
|
-
* Extra values evaluated in the parent's rendered scope at spawn time and
|
|
936
|
-
* delivered into each subworkflow's `$effects` bag — the parent→child
|
|
937
|
-
* handoff, read exactly like an effect output.
|
|
938
|
-
*/
|
|
939
|
-
context: v.optional(v.record(NonEmpty, ConditionSchema))
|
|
940
|
-
});
|
|
941
|
-
function activityFields({ field, action, op, target }) {
|
|
942
|
-
return {
|
|
943
|
-
name: NonEmpty,
|
|
944
|
-
title: v.optional(v.string()),
|
|
945
|
-
description: v.optional(v.string()),
|
|
946
|
-
/**
|
|
947
|
-
* Advisory BPMN-aligned classification of this activity by its executor (see
|
|
948
|
-
* {@link ACTIVITY_KINDS}). Optional and derived from the activity's shape when
|
|
949
|
-
* omitted; declaring it lets deploy check the shape matches the lane.
|
|
950
|
-
* Changes no gating or resolution — a label for tooling, like `assignees`.
|
|
951
|
-
*/
|
|
952
|
-
kind: v.optional(picklist(ACTIVITY_KINDS)),
|
|
953
|
-
/** Deep-link target for a `kind: "manual"` activity (off-system work). Render-only
|
|
954
|
-
* metadata; only valid on a manual activity (deploy-checked). */
|
|
955
|
-
target: v.optional(target),
|
|
956
|
-
activation: v.optional(picklist(["auto", "manual"])),
|
|
957
|
-
filter: v.optional(ConditionSchema),
|
|
958
|
-
/**
|
|
959
|
-
* Readiness gates, by name — conditions over the rendered scope that must
|
|
960
|
-
* hold for the activity to be *executable*, orthogonal to `filter`
|
|
961
|
-
* (visibility). An unmet requirement keeps the activity visible but disables
|
|
962
|
-
* its actions with a `requirements-unmet` verdict naming the unmet keys;
|
|
963
|
-
* all must hold (any-of lives inside one condition). Advisory like every
|
|
964
|
-
* engine gate. Distinct from ACL (authorization) and guards
|
|
965
|
-
* (content-write locks).
|
|
966
|
-
*/
|
|
967
|
-
requirements: v.optional(v.record(NonEmpty, ConditionSchema)),
|
|
968
|
-
/**
|
|
969
|
-
* Auto-completion condition — evaluated at activation and on every
|
|
970
|
-
* cascade; truthy flips the activity to `done` with a system actor. On a
|
|
971
|
-
* spawning activity it typically reads `$subworkflows`.
|
|
972
|
-
*/
|
|
973
|
-
completeWhen: v.optional(ConditionSchema),
|
|
974
|
-
/**
|
|
975
|
-
* Auto-failure condition — symmetric to `completeWhen`, flips to
|
|
976
|
-
* `failed`. When both are truthy on the same evaluation, `failWhen`
|
|
977
|
-
* wins — failure is the more notable signal.
|
|
978
|
-
*/
|
|
979
|
-
failWhen: v.optional(ConditionSchema),
|
|
980
|
-
ops: v.optional(v.array(op)),
|
|
981
|
-
effects: v.optional(v.array(EffectSchema)),
|
|
982
|
-
actions: v.optional(v.array(action)),
|
|
983
|
-
subworkflows: v.optional(SubworkflowsSchema),
|
|
984
|
-
/** Activity-scoped field entries. Resolved at activity activation time. */
|
|
985
|
-
fields: v.optional(v.array(field))
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
const StoredActivitySchema = pinned()(
|
|
989
|
-
v.strictObject(
|
|
990
|
-
activityFields({
|
|
991
|
-
field: FieldEntrySchema,
|
|
992
|
-
action: StoredActionSchema,
|
|
993
|
-
op: StoredOpSchema,
|
|
994
|
-
target: StoredManualTargetSchema
|
|
995
|
-
})
|
|
996
|
-
)
|
|
997
|
-
), AuthoringActivitySchema = pinned()(
|
|
998
|
-
v.strictObject(
|
|
999
|
-
activityFields({
|
|
1000
|
-
field: AuthoringFieldEntrySchema,
|
|
1001
|
-
action: AuthoringActionSchema,
|
|
1002
|
-
op: AuthoringOpSchema,
|
|
1003
|
-
target: AuthoringManualTargetSchema
|
|
1004
|
-
})
|
|
1005
|
-
)
|
|
1006
|
-
);
|
|
1007
|
-
function transitionFields(op, filter) {
|
|
1008
|
-
return {
|
|
1009
|
-
name: NonEmpty,
|
|
1010
|
-
title: v.optional(v.string()),
|
|
1011
|
-
description: v.optional(v.string()),
|
|
1012
|
-
to: NonEmpty,
|
|
1013
|
-
filter,
|
|
1014
|
-
/** The `field.*` subset — field-write-on-move, the stage's EXIT/ARRIVAL payload. */
|
|
1015
|
-
ops: v.optional(v.array(op)),
|
|
1016
|
-
effects: v.optional(v.array(EffectSchema))
|
|
1017
|
-
};
|
|
1018
|
-
}
|
|
1019
|
-
const StoredTransitionSchema = pinned()(
|
|
1020
|
-
v.strictObject(transitionFields(StoredTransitionOpSchema, ConditionSchema))
|
|
1021
|
-
), AuthoringTransitionOpSchema = v.variant("type", [
|
|
1022
|
-
...opSchemas(AuthoringFieldRefSchema),
|
|
1023
|
-
AuditOpSchema
|
|
1024
|
-
]), AuthoringTransitionSchema = pinned()(
|
|
1025
|
-
v.strictObject(transitionFields(AuthoringTransitionOpSchema, v.optional(ConditionSchema)))
|
|
1026
|
-
), GuardActionSchema = picklist(MUTATION_GUARD_ACTIONS), GuardReadPath = v.pipe(
|
|
1027
|
-
NonEmpty,
|
|
1028
|
-
v.check(
|
|
1029
|
-
(path) => !/[\r\n\u2028\u2029]/.test(path),
|
|
1030
|
-
"a guard read path cannot contain a line break"
|
|
1031
|
-
)
|
|
1032
|
-
), GuardReadSchema = v.variant("type", [
|
|
1033
|
-
v.strictObject({ type: v.literal("self") }),
|
|
1034
|
-
v.strictObject({ type: v.literal("now") }),
|
|
1035
|
-
v.strictObject({
|
|
1036
|
-
type: v.literal("fieldRead"),
|
|
1037
|
-
field: FieldEntryName,
|
|
1038
|
-
path: v.optional(GuardReadPath)
|
|
1039
|
-
}),
|
|
1040
|
-
v.strictObject({
|
|
1041
|
-
type: v.literal("effectsRead"),
|
|
1042
|
-
// The stored spelling bracket-quotes the name (`$effects['<name>']`), so a
|
|
1043
|
-
// quote inside it would corrupt the printed read.
|
|
1044
|
-
effect: v.pipe(
|
|
1045
|
-
NonEmpty,
|
|
1046
|
-
v.check((name) => !name.includes("'"), "an effect name cannot contain `'`")
|
|
1047
|
-
),
|
|
1048
|
-
path: v.optional(GuardReadPath)
|
|
1049
|
-
})
|
|
1050
|
-
]);
|
|
1051
|
-
function guardMatchFields(read) {
|
|
1052
|
-
return {
|
|
1053
|
-
/** Subject `_type`(s); empty matches any type. */
|
|
1054
|
-
types: v.optional(v.array(NonEmpty)),
|
|
1055
|
-
/** Target docs as field reads (or the instance itself), resolved at deploy to bare ids + the resource. */
|
|
1056
|
-
idRefs: v.optional(v.array(read)),
|
|
1057
|
-
/** Glob id patterns (bare, resource-local). */
|
|
1058
|
-
idPatterns: v.optional(v.array(NonEmpty)),
|
|
1059
|
-
actions: v.pipe(
|
|
1060
|
-
v.array(GuardActionSchema),
|
|
1061
|
-
v.minLength(1, "a guard must match at least one action")
|
|
1062
|
-
)
|
|
1063
|
-
};
|
|
1064
|
-
}
|
|
1065
|
-
function guardFields(read) {
|
|
1066
|
-
return {
|
|
1067
|
-
name: NonEmpty,
|
|
1068
|
-
title: v.optional(v.string()),
|
|
1069
|
-
description: v.optional(v.string()),
|
|
1070
|
-
match: v.strictObject(guardMatchFields(read)),
|
|
1071
|
-
/**
|
|
1072
|
-
* Lake GROQ predicate — a distinct eval context reading
|
|
1073
|
-
* `document.before`/`document.after`, `mutation`, `guard`, and
|
|
1074
|
-
* `identity()`. Bare ids/fields only. Omitted or empty means
|
|
1075
|
-
* UNCONDITIONAL DENY.
|
|
1076
|
-
*/
|
|
1077
|
-
predicate: v.optional(v.string()),
|
|
1078
|
-
/**
|
|
1079
|
-
* Projected workflow fields the predicate reads as `guard.metadata.*` —
|
|
1080
|
-
* the only bridge from the lake eval context (which cannot see `$fields`)
|
|
1081
|
-
* to workflow fields. Each value is a deploy-time read — a typed
|
|
1082
|
-
* {@link GuardRead} when authoring, the printed string spelling once
|
|
1083
|
-
* stored — resolved into a bare value at deploy and re-synced by the
|
|
1084
|
-
* post-field-op guard refresh.
|
|
1085
|
-
*/
|
|
1086
|
-
metadata: v.optional(v.record(NonEmpty, read))
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
const GuardSchema = v.strictObject(guardFields(NonEmpty)), AuthoringGuardSchema = v.strictObject(guardFields(GuardReadSchema));
|
|
1090
|
-
function stageFields({
|
|
1091
|
-
field,
|
|
1092
|
-
activity,
|
|
1093
|
-
transition,
|
|
1094
|
-
guard,
|
|
1095
|
-
editable
|
|
1096
|
-
}) {
|
|
1097
|
-
return {
|
|
1098
|
-
name: NonEmpty,
|
|
1099
|
-
title: v.optional(v.string()),
|
|
1100
|
-
description: v.optional(v.string()),
|
|
1101
|
-
activities: v.optional(v.array(activity)),
|
|
1102
|
-
transitions: v.optional(v.array(transition)),
|
|
1103
|
-
/**
|
|
1104
|
-
* Lake mutation guards active while this stage holds. Each compiles to a
|
|
1105
|
-
* persisted guard document deployed on stage entry and retracted on exit.
|
|
1106
|
-
*/
|
|
1107
|
-
guards: v.optional(v.array(guard)),
|
|
1108
|
-
/** Stage-scoped field entries. Resolved at stage entry. */
|
|
1109
|
-
fields: v.optional(v.array(field)),
|
|
1110
|
-
/**
|
|
1111
|
-
* Tighten-only editability overrides for the time this stage holds, keyed
|
|
1112
|
-
* by an in-scope field name. The field's own `editable` is the ceiling; a
|
|
1113
|
-
* stage value is ANDed with it at runtime, so an override can only NARROW
|
|
1114
|
-
* (never open a field the baseline left closed). An unlisted field inherits
|
|
1115
|
-
* its baseline.
|
|
1116
|
-
*/
|
|
1117
|
-
editable: v.optional(v.record(FieldEntryName, editable))
|
|
1118
|
-
};
|
|
1119
|
-
}
|
|
1120
|
-
const StoredStageSchema = pinned()(
|
|
1121
|
-
v.strictObject(
|
|
1122
|
-
stageFields({
|
|
1123
|
-
field: FieldEntrySchema,
|
|
1124
|
-
activity: StoredActivitySchema,
|
|
1125
|
-
transition: StoredTransitionSchema,
|
|
1126
|
-
guard: GuardSchema,
|
|
1127
|
-
editable: StoredEditableSchema
|
|
1128
|
-
})
|
|
1129
|
-
)
|
|
1130
|
-
), AuthoringStageSchema = pinned()(
|
|
1131
|
-
v.strictObject(
|
|
1132
|
-
stageFields({
|
|
1133
|
-
field: AuthoringFieldEntrySchema,
|
|
1134
|
-
activity: AuthoringActivitySchema,
|
|
1135
|
-
transition: AuthoringTransitionSchema,
|
|
1136
|
-
guard: AuthoringGuardSchema,
|
|
1137
|
-
editable: AuthoringEditableSchema
|
|
1138
|
-
})
|
|
1139
|
-
)
|
|
1140
|
-
), RoleAliasesSchema = v.record(
|
|
1141
|
-
NonEmpty,
|
|
1142
|
-
v.pipe(v.array(NonEmpty), v.minLength(1, "a role alias must list at least one fulfilling role"))
|
|
1143
|
-
), WORKFLOW_LIFECYCLES = ["standalone", "child"];
|
|
1144
|
-
function workflowFields(field, stage) {
|
|
1145
|
-
return {
|
|
1146
|
-
name: NonEmpty,
|
|
1147
|
-
title: NonEmpty,
|
|
1148
|
-
description: v.optional(v.string()),
|
|
1149
|
-
/**
|
|
1150
|
-
* How instances of this workflow come to exist. `'child'` marks a
|
|
1151
|
-
* spawn-only definition — instantiated by a parent via `activity.subworkflows`,
|
|
1152
|
-
* never started cold from a picker. Omitted ⇒ `'standalone'` (startable).
|
|
1153
|
-
* Advisory: consumers filter their start pickers on it (see
|
|
1154
|
-
* {@link isStartableDefinition}); the engine does NOT refuse a
|
|
1155
|
-
* `startInstance` on a `'child'` def — load-bearing `required` field is the
|
|
1156
|
-
* runtime backstop.
|
|
1157
|
-
*/
|
|
1158
|
-
lifecycle: v.optional(picklist(WORKFLOW_LIFECYCLES)),
|
|
1159
|
-
/** Reference field: named for the target, holds the stage's `name`. */
|
|
1160
|
-
initialStage: NonEmpty,
|
|
1161
|
-
/** Workflow-scope field entries. Persist for the instance lifetime. */
|
|
1162
|
-
fields: v.optional(v.array(field)),
|
|
1163
|
-
stages: v.pipe(v.array(stage), v.minLength(1, "must declare at least one stage")),
|
|
1164
|
-
/**
|
|
1165
|
-
* Nullary named conditions — each `name: groq` entry is pre-evaluated
|
|
1166
|
-
* and bound as the boolean `$name` var, composable with native GROQ.
|
|
1167
|
-
* Redefining a built-in var is a deploy error (never silently shadow).
|
|
1168
|
-
*/
|
|
1169
|
-
predicates: v.optional(v.record(groqIdentifier("`$<name>`"), ConditionSchema)),
|
|
1170
|
-
/** Role aliasing for this definition — see {@link RoleAliasesSchema}. */
|
|
1171
|
-
roleAliases: v.optional(RoleAliasesSchema)
|
|
1172
|
-
};
|
|
1173
|
-
}
|
|
1174
|
-
pinned()(
|
|
1175
|
-
v.strictObject(workflowFields(FieldEntrySchema, StoredStageSchema))
|
|
1176
|
-
);
|
|
1177
|
-
const AuthoringWorkflowSchema = pinned()(
|
|
1178
|
-
v.strictObject(workflowFields(AuthoringFieldEntrySchema, AuthoringStageSchema))
|
|
1179
|
-
), WORKFLOW_DEFINITION_TYPE = "sanity.workflow.definition";
|
|
1180
|
-
function isStartableDefinition(definition) {
|
|
1181
|
-
return definition.lifecycle !== "child";
|
|
1182
|
-
}
|
|
1183
|
-
function formatValidationError(label, issues) {
|
|
1184
|
-
const lines = issues.map((issue) => ` - ${issue.path.length === 0 ? "(root)" : formatPath(issue.path)}: ${issue.message}`);
|
|
1185
|
-
return `${label} failed validation (${issues.length} issue${issues.length === 1 ? "" : "s"}):
|
|
1186
|
-
${lines.join(`
|
|
1187
|
-
`)}`;
|
|
1188
|
-
}
|
|
1189
|
-
function issuesFromValibot(issues) {
|
|
1190
|
-
return issues.map((issue) => ({
|
|
1191
|
-
path: issue.path ? issue.path.map((item) => item.key) : [],
|
|
1192
|
-
message: issue.message
|
|
1193
|
-
}));
|
|
1194
|
-
}
|
|
1195
|
-
function formatPath(path) {
|
|
1196
|
-
let out = "";
|
|
1197
|
-
for (const seg of path)
|
|
1198
|
-
typeof seg == "number" ? out += `[${seg}]` : out += out.length === 0 ? String(seg) : `.${String(seg)}`;
|
|
1199
|
-
return out;
|
|
1200
|
-
}
|
|
1201
|
-
export {
|
|
1202
|
-
ACTIVITY_KINDS,
|
|
1203
|
-
ACTOR_KINDS,
|
|
1204
|
-
AuthoringActionSchema,
|
|
1205
|
-
AuthoringActivitySchema,
|
|
1206
|
-
AuthoringFieldEntrySchema,
|
|
1207
|
-
AuthoringGuardSchema,
|
|
1208
|
-
AuthoringOpSchema,
|
|
1209
|
-
AuthoringStageSchema,
|
|
1210
|
-
AuthoringTransitionSchema,
|
|
1211
|
-
AuthoringWorkflowSchema,
|
|
1212
|
-
CONDITION_VARS,
|
|
1213
|
-
ContractViolationError,
|
|
1214
|
-
DOCUMENT_VALUE_PERMISSIONS,
|
|
1215
|
-
DRIVER_KINDS,
|
|
1216
|
-
DefinitionInUseError,
|
|
1217
|
-
DefinitionNotFoundError,
|
|
1218
|
-
EFFECTS_READ,
|
|
1219
|
-
EffectNotFoundError,
|
|
1220
|
-
EffectSchema,
|
|
1221
|
-
FIELD_READ,
|
|
1222
|
-
FILTER_SCOPE_VARS,
|
|
1223
|
-
FieldValueShapeError,
|
|
1224
|
-
GROQ_IDENTIFIER,
|
|
1225
|
-
GUARD_PREDICATE_VARS,
|
|
1226
|
-
InstanceNotFoundError,
|
|
1227
|
-
RESERVED_CONDITION_VARS,
|
|
1228
|
-
RESOURCE_ALIAS_NAME_SOURCE,
|
|
1229
|
-
StoredFieldOpSchema,
|
|
1230
|
-
WORKFLOW_DEFINITION_TYPE,
|
|
1231
|
-
WorkflowConfigSchema,
|
|
1232
|
-
WorkflowError,
|
|
1233
|
-
actorFulfillsRole,
|
|
1234
|
-
andConditions,
|
|
1235
|
-
checkFieldValue,
|
|
1236
|
-
datasetResourceParts,
|
|
1237
|
-
definitionDocId,
|
|
1238
|
-
expandRequiredRoles,
|
|
1239
|
-
extractDocumentId,
|
|
1240
|
-
formatIssues,
|
|
1241
|
-
formatValidationError,
|
|
1242
|
-
gdrFromResource,
|
|
1243
|
-
gdrRef,
|
|
1244
|
-
gdrResourcePrefix,
|
|
1245
|
-
gdrUri,
|
|
1246
|
-
isBareSeedId,
|
|
1247
|
-
isGdr,
|
|
1248
|
-
isGdrUri,
|
|
1249
|
-
isGuardReadExpr,
|
|
1250
|
-
isStartableDefinition,
|
|
1251
|
-
isTerminalActivityStatus,
|
|
1252
|
-
issuesFromValibot,
|
|
1253
|
-
normalizeRoleAliases,
|
|
1254
|
-
parseGdr,
|
|
1255
|
-
printGuardRead,
|
|
1256
|
-
refCanvas,
|
|
1257
|
-
refDashboard,
|
|
1258
|
-
refDataset,
|
|
1259
|
-
refMediaLibrary,
|
|
1260
|
-
resourceAliasesToMap,
|
|
1261
|
-
resourceFromGdrUri,
|
|
1262
|
-
resourceFromParsed,
|
|
1263
|
-
sameResource,
|
|
1264
|
-
selfGdr,
|
|
1265
|
-
tagScopeFilter,
|
|
1266
|
-
toBareId,
|
|
1267
|
-
toPhysicalGdr,
|
|
1268
|
-
tryParseGdr,
|
|
1269
|
-
validateFieldAppendItem,
|
|
1270
|
-
validateFieldValue,
|
|
1271
|
-
validateResourceAliasName,
|
|
1272
|
-
validateTag
|
|
1273
|
-
};
|
|
1274
|
-
//# sourceMappingURL=schema.js.map
|