@scarn/sdk 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/automations/define-automation.d.ts +20 -0
  2. package/dist/automations/index.d.ts +8 -0
  3. package/dist/automations/index.js +21 -0
  4. package/dist/automations/targets.d.ts +36 -0
  5. package/dist/automations/types.d.ts +116 -0
  6. package/dist/{chunk-nb0nkt71.js → chunk-01nfqm18.js} +1 -0
  7. package/dist/chunk-0vzq22dj.js +73 -0
  8. package/dist/chunk-11hbmexe.js +250 -0
  9. package/dist/{chunk-2fn95pdd.js → chunk-3gy0cb5f.js} +5 -1
  10. package/dist/{chunk-qrasq5xe.js → chunk-43y7tfn4.js} +33 -414
  11. package/dist/chunk-61jf8b6s.js +53 -0
  12. package/dist/chunk-76d1bwwz.js +119 -0
  13. package/dist/chunk-8z1wa3kd.js +109 -0
  14. package/dist/{chunk-p7yrcmqm.js → chunk-cnxaagfj.js} +2 -52
  15. package/dist/{chunk-cdanncng.js → chunk-ejzfdm1z.js} +21 -5
  16. package/dist/{chunk-gds7w7zh.js → chunk-fgfhvsee.js} +1 -4
  17. package/dist/{chunk-x9788y82.js → chunk-fyfvp6jx.js} +30 -13
  18. package/dist/{chunk-mz53r914.js → chunk-jj9pezwb.js} +22 -119
  19. package/dist/{chunk-8pyhrdgy.js → chunk-wnfj3wyx.js} +55 -11
  20. package/dist/chunk-x0hjhqrf.js +416 -0
  21. package/dist/chunk-y11p1q7r.js +159 -0
  22. package/dist/client.js +4 -2
  23. package/dist/contracts/automation-document/index.d.ts +5 -0
  24. package/dist/contracts/automation-document/index.js +34 -0
  25. package/dist/contracts/automation-document/schema.d.ts +363 -0
  26. package/dist/contracts/pipeline-document/built-ins.d.ts +1 -1
  27. package/dist/contracts/pipeline-document/index.js +9 -7
  28. package/dist/contracts/pipeline-document/schema.d.ts +3 -3
  29. package/dist/contracts/work-item-changes.d.ts +6 -0
  30. package/dist/contracts/work-item-changes.js +1 -0
  31. package/dist/defaults/index.js +2 -2
  32. package/dist/definitions/automations/automations-client.d.ts +178 -0
  33. package/dist/definitions/automations/index.d.ts +1 -0
  34. package/dist/definitions/automations/index.js +12 -0
  35. package/dist/definitions/pipelines/index.d.ts +0 -1
  36. package/dist/definitions/pipelines/index.js +4 -12
  37. package/dist/definitions/pipelines/work-item-fields.d.ts +11 -22
  38. package/dist/definitions/steps/define-code-step.d.ts +3 -1
  39. package/dist/definitions/steps/define-step.d.ts +13 -0
  40. package/dist/definitions/steps/index.js +9 -6
  41. package/dist/definitions/steps/repo.d.ts +11 -3
  42. package/dist/definitions/steps/runtime.d.ts +11 -12
  43. package/dist/definitions/steps/step-definitions-client.d.ts +12 -0
  44. package/dist/definitions/steps/step-features.d.ts +2 -2
  45. package/dist/definitions/steps/step-handle.d.ts +6 -1
  46. package/dist/definitions/validation/index.js +2 -2
  47. package/dist/generated/index.d.ts +2 -2
  48. package/dist/generated/sdk.gen.d.ts +37 -5
  49. package/dist/generated/types.gen.d.ts +2756 -1875
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.js +40 -30
  52. package/dist/pipelines/define-pipeline.d.ts +7 -7
  53. package/dist/pipelines/handles.d.ts +0 -5
  54. package/dist/pipelines/index.js +7 -4
  55. package/dist/pipelines/types.d.ts +13 -1
  56. package/dist/push/collect-definitions.d.ts +3 -8
  57. package/dist/push/collect-pipeline-documents.d.ts +13 -3
  58. package/dist/push/index.d.ts +2 -2
  59. package/dist/push/index.js +87 -124
  60. package/dist/push/push-from-directory.d.ts +10 -6
  61. package/dist/repo-config.d.ts +14 -4
  62. package/dist/repo-config.js +5 -1
  63. package/dist/task-plane-client.d.ts +40 -0
  64. package/package.json +13 -1
  65. package/dist/chunk-ra53p0v8.js +0 -256
  66. package/dist/definitions/pipelines/define-default-pipeline-assignment.d.ts +0 -263
@@ -1,440 +1,54 @@
1
1
  // @bun
2
2
  import {
3
- jsonPointer
4
- } from "./chunk-p7yrcmqm.js";
3
+ ComputedData,
4
+ ConditionData,
5
+ argEntries,
6
+ attempt,
7
+ compileArg,
8
+ compileCondition,
9
+ conditionData,
10
+ issue,
11
+ mapSource,
12
+ newState,
13
+ place,
14
+ refData,
15
+ requireRef,
16
+ rootPlaceholder,
17
+ unusedReads,
18
+ useRef,
19
+ withOwners,
20
+ withTracker
21
+ } from "./chunk-x0hjhqrf.js";
22
+ import {
23
+ bareStepHandle,
24
+ waitHandle
25
+ } from "./chunk-jj9pezwb.js";
5
26
  import {
6
27
  AuthoringError,
7
28
  PipelineBuildError,
8
- bareStepHandle,
9
29
  captureSite,
10
30
  chainOf,
11
31
  eachOf,
12
32
  nodeOf,
13
33
  pendingChains,
34
+ pipelineOn,
14
35
  registerEach,
15
36
  registerNode,
16
37
  registerTarget,
17
38
  requireNode,
18
- targetOf,
19
- waitHandle
20
- } from "./chunk-mz53r914.js";
39
+ targetOf
40
+ } from "./chunk-y11p1q7r.js";
21
41
  import {
22
42
  CONVERSATION_RESULT_SCHEMA,
23
43
  ERROR_SCHEMA,
24
44
  REPLY_INPUT_SCHEMA,
25
45
  REPLY_RESULT_SCHEMA,
26
46
  decisionResultSchema
27
- } from "./chunk-nb0nkt71.js";
47
+ } from "./chunk-01nfqm18.js";
28
48
  import {
29
49
  toJSONSchema
30
50
  } from "./chunk-skzxcba3.js";
31
51
 
32
- // src/pipelines/refs.ts
33
- var REF = Symbol("scarn.ref");
34
- var active = null;
35
- var currentOwners = [];
36
- function withOwners(owners, run) {
37
- const previous = currentOwners;
38
- currentOwners = owners;
39
- try {
40
- return run();
41
- } finally {
42
- currentOwners = previous;
43
- }
44
- }
45
- function withTracker(tracker, run) {
46
- const previous = active;
47
- active = tracker;
48
- try {
49
- return run();
50
- } finally {
51
- active = previous;
52
- }
53
- }
54
- function setTrackerPointer(pointer) {
55
- if (active !== null) {
56
- active.pointer = pointer;
57
- }
58
- }
59
- var COERCION_HINT = "a placeholder stands for a value that only exists when the pipeline runs, so it can't be compared, converted or used in JS logic. Use a condition helper such as equal(...) or greaterThan(...), in a .next(...) route's when to branch";
60
- function coercionError(path) {
61
- throw new AuthoringError(`"${path === "" ? "element" : path}" was coerced to a primitive: ${COERCION_HINT}`);
62
- }
63
- function propertySchema(schema, key) {
64
- if (key === "length") {
65
- return { type: "integer" };
66
- }
67
- if (typeof schema !== "object") {
68
- return;
69
- }
70
- if (/^\d+$/.test(key) && schema.items !== undefined) {
71
- return schema.items;
72
- }
73
- return schema.properties?.[key];
74
- }
75
- function spreadKeys(data) {
76
- const schema = data.schema;
77
- if (typeof schema !== "object" || schema.properties === undefined || schema.type !== undefined && schema.type !== "object") {
78
- throw new AuthoringError(`can't spread "${data.path}": its JSON Schema doesn't declare its properties, so the args it expands to aren't known. Pass each arg explicitly`);
79
- }
80
- return Object.keys(schema.properties);
81
- }
82
- function joinPath(path, key) {
83
- return path === "" ? key : `${path}.${key}`;
84
- }
85
- function makePlaceholder(data) {
86
- const children = new Map;
87
- const child = (key) => {
88
- const cached = children.get(key);
89
- if (cached !== undefined) {
90
- return cached;
91
- }
92
- const created = createChild(key);
93
- children.set(key, created);
94
- return created;
95
- };
96
- const spreadChild = (key) => makePlaceholder({
97
- ...data,
98
- path: joinPath(data.path, key),
99
- schema: propertySchema(data.schema, key),
100
- record: data.record
101
- });
102
- const createChild = (key) => {
103
- const record = active === null ? null : {
104
- path: joinPath(data.path, key),
105
- site: captureSite(),
106
- pointer: active.pointer,
107
- parent: data.record,
108
- used: false,
109
- hasChildren: false
110
- };
111
- if (record !== null) {
112
- active?.records.push(record);
113
- if (data.record !== null) {
114
- data.record.hasChildren = true;
115
- }
116
- }
117
- return makePlaceholder({
118
- path: joinPath(data.path, key),
119
- scope: data.scope,
120
- schema: propertySchema(data.schema, key),
121
- field: data.field,
122
- record,
123
- owner: data.owner,
124
- reach: data.reach
125
- });
126
- };
127
- let spreading;
128
- return new Proxy(Object.create(null), {
129
- get(_target, key) {
130
- if (typeof key === "string" && key === spreading) {
131
- spreading = undefined;
132
- return spreadChild(key);
133
- }
134
- if (key === REF) {
135
- return data;
136
- }
137
- if (key === Symbol.toPrimitive || key === "valueOf" || key === "toString" || key === "toJSON") {
138
- return () => coercionError(data.path);
139
- }
140
- if (typeof key === "symbol" || key === "then") {
141
- return;
142
- }
143
- return child(key);
144
- },
145
- has(_target, key) {
146
- return key === REF;
147
- },
148
- ownKeys() {
149
- return spreadKeys(data);
150
- },
151
- getOwnPropertyDescriptor(_target, key) {
152
- if (typeof key !== "string") {
153
- return;
154
- }
155
- spreading = key;
156
- return {
157
- configurable: true,
158
- enumerable: true,
159
- writable: false,
160
- value: spreadChild(key)
161
- };
162
- },
163
- set() {
164
- throw new AuthoringError(`can't assign to "${data.path}"`);
165
- }
166
- });
167
- }
168
- function rootPlaceholder(path, schema, options = {}) {
169
- const record = active === null ? null : {
170
- path,
171
- site: captureSite(),
172
- pointer: active.pointer,
173
- parent: null,
174
- used: false,
175
- hasChildren: false
176
- };
177
- if (record !== null) {
178
- active?.records.push(record);
179
- }
180
- return makePlaceholder({
181
- path,
182
- scope: options.scope ?? "document",
183
- schema,
184
- field: options.field,
185
- record,
186
- owner: options.owner ?? null,
187
- reach: options.reach
188
- });
189
- }
190
- function refData(value) {
191
- if ((typeof value === "object" || typeof value === "function") && value !== null && REF in value) {
192
- return value[REF];
193
- }
194
- return;
195
- }
196
- function markUsed(data) {
197
- for (let record = data.record;record !== null; record = record.parent) {
198
- record.used = true;
199
- }
200
- }
201
- function useRef(data) {
202
- markUsed(data);
203
- if (data.field !== undefined) {
204
- active?.fields.push(data.field);
205
- }
206
- if (data.reach !== undefined && active !== null) {
207
- active.reaches.push({
208
- node: data.reach,
209
- pointer: active.pointer,
210
- site: data.record?.site ?? null
211
- });
212
- }
213
- if (data.owner !== null && !currentOwners.includes(data.owner)) {
214
- throw new AuthoringError(`"${data.path}" comes from another callback's r: "result", "input" and "error" mean this node's own values in each callback. Use r.node(handle) to reach back to another node`, data.record?.site ?? null);
215
- }
216
- return data.path;
217
- }
218
- function unusedReads(tracker) {
219
- return tracker.records.filter((record) => !record.used && !record.hasChildren);
220
- }
221
-
222
- // src/pipelines/condition-data.ts
223
- class ConditionData {
224
- node;
225
- site;
226
- constructor(node, site = captureSite()) {
227
- this.node = node;
228
- this.site = site;
229
- }
230
- }
231
-
232
- class ComputedData {
233
- node;
234
- site;
235
- constructor(node, site = captureSite()) {
236
- this.node = node;
237
- this.site = site;
238
- }
239
- }
240
- function conditionData(value) {
241
- if (value instanceof ConditionData) {
242
- return value;
243
- }
244
- throw new AuthoringError(`${typeof value === "boolean" ? "a JS boolean" : "this value"} is not a condition: build conditions with the helpers (equal, greaterThan, all, ...), not JS operators`);
245
- }
246
- function requireRef(value, what) {
247
- const data = refData(value);
248
- if (data === undefined) {
249
- throw new AuthoringError(`${what} must be a reference (r.result..., r.input..., ...)`);
250
- }
251
- return data;
252
- }
253
- function refPath(ref, scope, side) {
254
- if (side === "right" && ref.scope === "element") {
255
- throw new AuthoringError(`"${ref.path}" is relative to a list element and can only be the left side of a condition inside some / every / none / count`, ref.record?.site ?? null);
256
- }
257
- if (side === "left" && ref.scope !== scope) {
258
- throw new AuthoringError(scope === "element" ? `"${ref.path}" is a full reference, but inside some / every / none / count the left side must come from the element parameter` : `"${ref.path}" is relative to a list element and can only be used inside that list's callback`, ref.record?.site ?? null);
259
- }
260
- return useRef(ref);
261
- }
262
- function leftPath(ref, scope) {
263
- const path = refPath(ref, scope, "left");
264
- if (path === "") {
265
- throw new AuthoringError("a condition on the whole element isn't supported; compare one of its fields", ref.record?.site ?? null);
266
- }
267
- return path;
268
- }
269
- function compileComputed(computed, scope) {
270
- if ("refs" in computed) {
271
- const source = computed.refs.map((ref) => leftPath(ref, scope));
272
- return computed.weights === undefined ? { source } : { source, weights: computed.weights };
273
- }
274
- const path = leftPath(computed.list, scope);
275
- if (computed.field !== undefined) {
276
- return { source: { path, field: leftPath(computed.field, "element") } };
277
- }
278
- if (computed.where !== undefined) {
279
- return {
280
- source: { path, where: compileCondition(computed.where, "element") }
281
- };
282
- }
283
- return { source: { path } };
284
- }
285
- function compileRight(right) {
286
- switch (right.kind) {
287
- case "none":
288
- return {};
289
- case "value":
290
- return { value: right.value };
291
- case "ref":
292
- return { ref: refPath(right.ref, "document", "right") };
293
- }
294
- }
295
- function compileCondition(data, scope = "document") {
296
- const node = data.node;
297
- switch (node.kind) {
298
- case "all":
299
- case "any":
300
- return {
301
- [node.kind]: node.items.map((item) => compileCondition(item, scope))
302
- };
303
- case "not":
304
- return { not: compileCondition(node.item, scope) };
305
- case "list":
306
- return {
307
- path: leftPath(node.list, scope),
308
- op: node.op,
309
- where: compileCondition(node.where, "element")
310
- };
311
- case "compare": {
312
- if (node.left.kind === "ref") {
313
- return {
314
- path: leftPath(node.left.ref, scope),
315
- op: node.op,
316
- ...compileRight(node.right)
317
- };
318
- }
319
- const { source, weights } = compileComputed(node.left.computed, scope);
320
- return {
321
- [node.left.computed.fn]: source,
322
- ...weights === undefined ? {} : { weights },
323
- op: node.op,
324
- ...compileRight(node.right)
325
- };
326
- }
327
- }
328
- }
329
-
330
- // src/pipelines/compile-args.ts
331
- function literal(value, path) {
332
- if (refData(value) !== undefined) {
333
- throw new AuthoringError(`"${path}" is a literal containing a reference; an arg is either a reference or a plain JSON value. Pass the reference as its own arg, or a reference to the whole object`);
334
- }
335
- if (value === null || typeof value === "string" || typeof value === "boolean") {
336
- return value;
337
- }
338
- if (typeof value === "number") {
339
- if (!Number.isFinite(value)) {
340
- throw new AuthoringError(`"${path}" is ${String(value)}, which isn't JSON`);
341
- }
342
- return value;
343
- }
344
- if (Array.isArray(value)) {
345
- return value.map((item, index) => literal(item, `${path}.${String(index)}`));
346
- }
347
- if (typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
348
- const out = {};
349
- for (const [key, item] of Object.entries(value)) {
350
- if (item !== undefined) {
351
- out[key] = literal(item, `${path}.${key}`);
352
- }
353
- }
354
- return out;
355
- }
356
- throw new AuthoringError(`"${path}" is a ${typeof value}, which isn't a JSON value`);
357
- }
358
- function refArg(name, data) {
359
- if (data.scope === "element") {
360
- throw new AuthoringError(`"${name}" is a list element from some / every / none / count; those exist only inside the condition`, data.record?.site ?? null);
361
- }
362
- return useRef(data);
363
- }
364
- function compileArg(name, value) {
365
- const data = refData(value);
366
- if (data !== undefined) {
367
- return refArg(name, data);
368
- }
369
- if (Array.isArray(value) && value.some((item) => refData(item) !== undefined)) {
370
- return {
371
- list: value.map((item, index) => {
372
- const path = `${name}.${String(index)}`;
373
- const element = refData(item);
374
- return element === undefined ? { value: literal(item, path) } : refArg(path, element);
375
- })
376
- };
377
- }
378
- return { value: literal(value, name) };
379
- }
380
- function argEntries(args) {
381
- return Object.entries(args).filter(([, value]) => value !== undefined);
382
- }
383
-
384
- // src/pipelines/compile-state.ts
385
- function newState() {
386
- return {
387
- nodes: new Map,
388
- issues: [],
389
- sourceMap: {},
390
- tracker: { records: [], fields: [], reaches: [], pointer: "" },
391
- usedChains: new Set
392
- };
393
- }
394
- function issue(state, site, pointer, message) {
395
- state.issues.push({ site, pointer: jsonPointer(pointer), message });
396
- }
397
- function mapSource(state, pointer, site) {
398
- const key = jsonPointer(pointer);
399
- if (site !== null && state.sourceMap[key] === undefined) {
400
- state.sourceMap[key] = site;
401
- }
402
- }
403
- function attempt(state, pointer, site, run) {
404
- const previous = state.tracker.pointer;
405
- setTrackerPointer(jsonPointer(pointer));
406
- try {
407
- return run();
408
- } catch (error) {
409
- if (error instanceof AuthoringError) {
410
- issue(state, error.site ?? site, pointer, error.message);
411
- } else {
412
- issue(state, site, pointer, error instanceof Error ? error.message : String(error));
413
- }
414
- return;
415
- } finally {
416
- setTrackerPointer(previous);
417
- }
418
- }
419
- function place(state, def, site, pointer) {
420
- const existing = state.nodes.get(def.id);
421
- if (existing === undefined) {
422
- const placed = {
423
- def,
424
- chain: undefined,
425
- json: {}
426
- };
427
- state.nodes.set(def.id, placed);
428
- mapSource(state, ["nodes", def.id], def.site);
429
- return placed;
430
- }
431
- if (existing.def !== def) {
432
- issue(state, site, pointer, `two different handles use the node id "${def.id}"; give one a different id (step.as("...") for steps)`);
433
- return;
434
- }
435
- return existing;
436
- }
437
-
438
52
  // src/pipelines/context.ts
439
53
  function schemaOf(node, source) {
440
54
  if (node.kind === "step") {
@@ -831,7 +445,7 @@ function compile(config, site) {
831
445
  start,
832
446
  nodes
833
447
  };
834
- return {
448
+ const definition = {
835
449
  _tag: "pipeline_document",
836
450
  key: config.key,
837
451
  document,
@@ -842,6 +456,11 @@ function compile(config, site) {
842
456
  steps: stepCatalog(state),
843
457
  warnings
844
458
  };
459
+ Object.defineProperty(definition, "on", {
460
+ value: pipelineOn(config.key),
461
+ enumerable: false
462
+ });
463
+ return definition;
845
464
  }
846
465
  function definePipeline(config) {
847
466
  return compile(config, captureSite());
@@ -0,0 +1,53 @@
1
+ // @bun
2
+ // src/contracts/pipeline-document/json.ts
3
+ function isJsonObject(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ function escapePointerSegment(segment) {
7
+ return String(segment).replaceAll("~", "~0").replaceAll("/", "~1");
8
+ }
9
+ function jsonPointer(segments) {
10
+ return segments.map((segment) => `/${escapePointerSegment(segment)}`).join("");
11
+ }
12
+ function deepEqual(left, right) {
13
+ if (left === right) {
14
+ return true;
15
+ }
16
+ if (Array.isArray(left)) {
17
+ return Array.isArray(right) && left.length === right.length && left.every((item, index) => deepEqual(item, right[index]));
18
+ }
19
+ if (isJsonObject(left) && isJsonObject(right)) {
20
+ const leftKeys = Object.keys(left);
21
+ const rightKeys = Object.keys(right);
22
+ return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(right, key) && deepEqual(left[key], right[key]));
23
+ }
24
+ return false;
25
+ }
26
+ // src/contracts/pipeline-document/routes.ts
27
+ function routeEntries(next) {
28
+ if (next === undefined) {
29
+ return [];
30
+ }
31
+ const entries = next.routes.map((route, index) => ({
32
+ kind: "route",
33
+ index,
34
+ route,
35
+ pointer: ["routes", index]
36
+ }));
37
+ if (next.otherwise !== undefined) {
38
+ entries.push({
39
+ kind: "otherwise",
40
+ index: 0,
41
+ route: next.otherwise,
42
+ pointer: ["otherwise"]
43
+ });
44
+ }
45
+ return entries;
46
+ }
47
+ function routeAt(next, kind, index) {
48
+ if (next === undefined) {
49
+ return;
50
+ }
51
+ return kind === "otherwise" ? next.otherwise : next.routes[index];
52
+ }
53
+ export { isJsonObject, jsonPointer, deepEqual, routeEntries, routeAt };
@@ -0,0 +1,119 @@
1
+ // @bun
2
+ import {
3
+ MATCH_MODES,
4
+ argValueSchema,
5
+ conditionSchema
6
+ } from "./chunk-cnxaagfj.js";
7
+ import {
8
+ exports_external
9
+ } from "./chunk-skzxcba3.js";
10
+
11
+ // src/contracts/automation-document/schema.ts
12
+ var AUTOMATION_SCOPES = ["workItem", "project"];
13
+ var WORK_ITEM_AUTOMATION_EVENTS = [
14
+ "self.attached",
15
+ "child.created",
16
+ "child.ready",
17
+ "child.closed"
18
+ ];
19
+ var PROJECT_AUTOMATION_EVENTS = [
20
+ "workItem.created",
21
+ "workItem.ready",
22
+ "workItem.label.added"
23
+ ];
24
+ var AUTOMATION_EVENTS = [
25
+ ...WORK_ITEM_AUTOMATION_EVENTS,
26
+ ...PROJECT_AUTOMATION_EVENTS
27
+ ];
28
+ var AUTOMATION_SUBJECTS = ["workItem", "child"];
29
+ function scopeOfEvent(event) {
30
+ return WORK_ITEM_AUTOMATION_EVENTS.includes(event) ? "workItem" : "project";
31
+ }
32
+ function eventHasChild(event) {
33
+ return event.startsWith("child.");
34
+ }
35
+ var keySchema = exports_external.string().min(1);
36
+ var subjectSchema = exports_external.enum(AUTOMATION_SUBJECTS);
37
+ var stepTargetShape = {
38
+ kind: exports_external.literal("step"),
39
+ to: keySchema,
40
+ args: exports_external.record(exports_external.string().min(1), argValueSchema).optional(),
41
+ on: subjectSchema
42
+ };
43
+ var pipelineTargetShape = {
44
+ kind: exports_external.literal("pipeline"),
45
+ to: keySchema,
46
+ on: subjectSchema
47
+ };
48
+ var attachTargetShape = {
49
+ kind: exports_external.literal("attach"),
50
+ automation: keySchema
51
+ };
52
+ var skipTargetShape = { kind: exports_external.literal("skip") };
53
+ var automationTargetSchema = exports_external.discriminatedUnion("kind", [
54
+ exports_external.strictObject(stepTargetShape),
55
+ exports_external.strictObject(pipelineTargetShape),
56
+ exports_external.strictObject(attachTargetShape),
57
+ exports_external.strictObject(skipTargetShape)
58
+ ]);
59
+ var when = { when: conditionSchema.optional() };
60
+ var automationRouteSchema = exports_external.discriminatedUnion("kind", [
61
+ exports_external.strictObject({ ...when, ...stepTargetShape }),
62
+ exports_external.strictObject({ ...when, ...pipelineTargetShape }),
63
+ exports_external.strictObject({ ...when, ...attachTargetShape }),
64
+ exports_external.strictObject({ ...when, ...skipTargetShape })
65
+ ]);
66
+ var automationNextSchema = exports_external.strictObject({
67
+ match: exports_external.enum(MATCH_MODES).optional(),
68
+ routes: exports_external.array(automationRouteSchema).min(1),
69
+ otherwise: automationTargetSchema.optional()
70
+ });
71
+ var automationRuleSchema = exports_external.strictObject({
72
+ event: exports_external.enum(AUTOMATION_EVENTS),
73
+ next: automationNextSchema
74
+ });
75
+ function targetsOf(rule) {
76
+ return [
77
+ ...rule.next.routes,
78
+ ...rule.next.otherwise === undefined ? [] : [rule.next.otherwise]
79
+ ];
80
+ }
81
+ var automationDocumentSchema = exports_external.strictObject({
82
+ $schema: exports_external.string().optional(),
83
+ kind: exports_external.literal("automation"),
84
+ schemaVersion: exports_external.literal(1),
85
+ key: keySchema,
86
+ title: exports_external.string().optional(),
87
+ scope: exports_external.enum(AUTOMATION_SCOPES),
88
+ rules: exports_external.array(automationRuleSchema)
89
+ }).superRefine((document, ctx) => {
90
+ document.rules.forEach((rule, index) => {
91
+ if (scopeOfEvent(rule.event) !== document.scope) {
92
+ ctx.addIssue({
93
+ code: "custom",
94
+ message: `"${rule.event}" isn't an event of a ${document.scope === "workItem" ? "work-item" : "project"} automation`,
95
+ path: ["rules", index, "event"]
96
+ });
97
+ }
98
+ for (const target of targetsOf(rule)) {
99
+ if (target.kind === "attach" && document.scope !== "project") {
100
+ ctx.addIssue({
101
+ code: "custom",
102
+ message: "Only a project automation can attach automations",
103
+ path: ["rules", index, "next"]
104
+ });
105
+ }
106
+ if ((target.kind === "step" || target.kind === "pipeline") && target.on === "child" && !eventHasChild(rule.event)) {
107
+ ctx.addIssue({
108
+ code: "custom",
109
+ message: `"${rule.event}" has no child work item, so a target can't be "on": "child"`,
110
+ path: ["rules", index, "next"]
111
+ });
112
+ }
113
+ }
114
+ });
115
+ });
116
+ function automationDocumentJsonSchema() {
117
+ return exports_external.toJSONSchema(automationDocumentSchema, { io: "input" });
118
+ }
119
+ export { AUTOMATION_SCOPES, WORK_ITEM_AUTOMATION_EVENTS, PROJECT_AUTOMATION_EVENTS, AUTOMATION_EVENTS, AUTOMATION_SUBJECTS, scopeOfEvent, eventHasChild, automationTargetSchema, automationRouteSchema, automationNextSchema, automationRuleSchema, automationDocumentSchema, automationDocumentJsonSchema };