@scarn/sdk 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/automations/define-automation.d.ts +20 -0
- package/dist/automations/index.d.ts +8 -0
- package/dist/automations/index.js +21 -0
- package/dist/automations/targets.d.ts +36 -0
- package/dist/automations/types.d.ts +116 -0
- package/dist/{chunk-nb0nkt71.js → chunk-01nfqm18.js} +1 -0
- package/dist/chunk-0vzq22dj.js +73 -0
- package/dist/chunk-11hbmexe.js +250 -0
- package/dist/{chunk-2fn95pdd.js → chunk-3gy0cb5f.js} +5 -1
- package/dist/{chunk-qrasq5xe.js → chunk-43y7tfn4.js} +33 -414
- package/dist/chunk-61jf8b6s.js +53 -0
- package/dist/chunk-76d1bwwz.js +119 -0
- package/dist/chunk-8z1wa3kd.js +109 -0
- package/dist/{chunk-p7yrcmqm.js → chunk-cnxaagfj.js} +2 -52
- package/dist/{chunk-cdanncng.js → chunk-ejzfdm1z.js} +21 -5
- package/dist/{chunk-gds7w7zh.js → chunk-fgfhvsee.js} +1 -4
- package/dist/{chunk-x9788y82.js → chunk-hyaez4ee.js} +145 -16
- package/dist/{chunk-mz53r914.js → chunk-jj9pezwb.js} +22 -119
- package/dist/{chunk-8pyhrdgy.js → chunk-wnfj3wyx.js} +55 -11
- package/dist/chunk-x0hjhqrf.js +416 -0
- package/dist/chunk-y11p1q7r.js +159 -0
- package/dist/client.js +4 -2
- package/dist/contracts/automation-document/index.d.ts +5 -0
- package/dist/contracts/automation-document/index.js +34 -0
- package/dist/contracts/automation-document/schema.d.ts +363 -0
- package/dist/contracts/pipeline-document/built-ins.d.ts +1 -1
- package/dist/contracts/pipeline-document/index.js +9 -7
- package/dist/contracts/pipeline-document/schema.d.ts +3 -3
- package/dist/contracts/work-item-changes.d.ts +6 -4
- package/dist/contracts/work-item-changes.js +2 -2
- package/dist/defaults/index.js +2 -2
- package/dist/definitions/automations/automations-client.d.ts +178 -0
- package/dist/definitions/automations/index.d.ts +1 -0
- package/dist/definitions/automations/index.js +12 -0
- package/dist/definitions/pipelines/index.d.ts +0 -1
- package/dist/definitions/pipelines/index.js +4 -12
- package/dist/definitions/pipelines/work-item-fields.d.ts +11 -22
- package/dist/definitions/steps/define-code-step.d.ts +8 -5
- package/dist/definitions/steps/define-step.d.ts +22 -11
- package/dist/definitions/steps/index.js +13 -6
- package/dist/definitions/steps/repo.d.ts +11 -3
- package/dist/definitions/steps/runtime.d.ts +11 -12
- package/dist/definitions/steps/step-definitions-client.d.ts +105 -3
- package/dist/definitions/steps/step-features.d.ts +89 -6
- package/dist/definitions/steps/step-handle.d.ts +6 -1
- package/dist/definitions/validation/index.js +2 -2
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/sdk.gen.d.ts +38 -6
- package/dist/generated/types.gen.d.ts +3026 -1889
- package/dist/index.d.ts +1 -0
- package/dist/index.js +44 -30
- package/dist/pipelines/define-pipeline.d.ts +7 -7
- package/dist/pipelines/handles.d.ts +0 -5
- package/dist/pipelines/index.js +7 -4
- package/dist/pipelines/types.d.ts +13 -1
- package/dist/push/collect-definitions.d.ts +3 -8
- package/dist/push/collect-pipeline-documents.d.ts +13 -3
- package/dist/push/index.d.ts +2 -2
- package/dist/push/index.js +87 -124
- package/dist/push/push-from-directory.d.ts +10 -6
- package/dist/repo-config.d.ts +14 -4
- package/dist/repo-config.js +5 -1
- package/dist/task-plane-client.d.ts +71 -1
- package/package.json +13 -1
- package/dist/chunk-ra53p0v8.js +0 -256
- package/dist/definitions/pipelines/define-default-pipeline-assignment.d.ts +0 -263
|
@@ -862,6 +862,12 @@ class Projects extends HeyApiClient {
|
|
|
862
862
|
listProjectWorkItemFieldOptions(options) {
|
|
863
863
|
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/work-item-field-options", ...options });
|
|
864
864
|
}
|
|
865
|
+
listProjectWorkItemLabels(options) {
|
|
866
|
+
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/work-item-labels", ...options });
|
|
867
|
+
}
|
|
868
|
+
listProjectWorkItemStatuses(options) {
|
|
869
|
+
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/work-item-statuses", ...options });
|
|
870
|
+
}
|
|
865
871
|
getProject(options) {
|
|
866
872
|
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}", ...options });
|
|
867
873
|
}
|
|
@@ -881,16 +887,6 @@ class Projects extends HeyApiClient {
|
|
|
881
887
|
listProjectMembers(options) {
|
|
882
888
|
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/members", ...options });
|
|
883
889
|
}
|
|
884
|
-
updateProjectDefaultPipelineAssignment(options) {
|
|
885
|
-
return (options.client ?? this.client).put({
|
|
886
|
-
url: "/api/projects/{projectId}/default-pipeline-assignment",
|
|
887
|
-
...options,
|
|
888
|
-
headers: {
|
|
889
|
-
"Content-Type": "application/json",
|
|
890
|
-
...options.headers
|
|
891
|
-
}
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
890
|
updateProjectMemberPermissions(options) {
|
|
895
891
|
return (options.client ?? this.client).put({ url: "/api/projects/{projectId}/members/{userId}/permissions", ...options });
|
|
896
892
|
}
|
|
@@ -1154,6 +1150,37 @@ class PipelineDefinitions extends HeyApiClient {
|
|
|
1154
1150
|
}
|
|
1155
1151
|
}
|
|
1156
1152
|
|
|
1153
|
+
class Automations extends HeyApiClient {
|
|
1154
|
+
listAutomations(options) {
|
|
1155
|
+
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/automations", ...options });
|
|
1156
|
+
}
|
|
1157
|
+
listWorkItemAutomations(options) {
|
|
1158
|
+
return (options.client ?? this.client).get({ url: "/api/work-items/{workItemId}/automations", ...options });
|
|
1159
|
+
}
|
|
1160
|
+
publishAutomation(options) {
|
|
1161
|
+
return (options.client ?? this.client).put({
|
|
1162
|
+
url: "/api/projects/{projectId}/automations/{key}",
|
|
1163
|
+
...options,
|
|
1164
|
+
headers: {
|
|
1165
|
+
"Content-Type": "application/json",
|
|
1166
|
+
...options.headers
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
enableAutomation(options) {
|
|
1171
|
+
return (options.client ?? this.client).post({ url: "/api/projects/{projectId}/automations/{key}/enable", ...options });
|
|
1172
|
+
}
|
|
1173
|
+
disableAutomation(options) {
|
|
1174
|
+
return (options.client ?? this.client).post({ url: "/api/projects/{projectId}/automations/{key}/disable", ...options });
|
|
1175
|
+
}
|
|
1176
|
+
detachWorkItemAutomation(options) {
|
|
1177
|
+
return (options.client ?? this.client).delete({ url: "/api/work-items/{workItemId}/automations/{key}", ...options });
|
|
1178
|
+
}
|
|
1179
|
+
attachWorkItemAutomation(options) {
|
|
1180
|
+
return (options.client ?? this.client).post({ url: "/api/work-items/{workItemId}/automations/{key}", ...options });
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1157
1184
|
class PipelineExecutions extends HeyApiClient {
|
|
1158
1185
|
listPipelineExecutions(options) {
|
|
1159
1186
|
return (options.client ?? this.client).get({ url: "/api/pipeline-executions", ...options });
|
|
@@ -1251,6 +1278,9 @@ class WorkItems extends HeyApiClient {
|
|
|
1251
1278
|
listWorkItemChildren(options) {
|
|
1252
1279
|
return (options.client ?? this.client).get({ url: "/api/work-items/{workItemId}/children", ...options });
|
|
1253
1280
|
}
|
|
1281
|
+
listWorkItemActivity(options) {
|
|
1282
|
+
return (options.client ?? this.client).get({ url: "/api/work-items/{workItemId}/activity", ...options });
|
|
1283
|
+
}
|
|
1254
1284
|
createWorkItem(options) {
|
|
1255
1285
|
return (options.client ?? this.client).post({
|
|
1256
1286
|
url: "/api/work-items",
|
|
@@ -1301,6 +1331,16 @@ class WorkItems extends HeyApiClient {
|
|
|
1301
1331
|
}
|
|
1302
1332
|
});
|
|
1303
1333
|
}
|
|
1334
|
+
labelWorkItem(options) {
|
|
1335
|
+
return (options.client ?? this.client).patch({
|
|
1336
|
+
url: "/api/work-items/{workItemId}/labels",
|
|
1337
|
+
...options,
|
|
1338
|
+
headers: {
|
|
1339
|
+
"Content-Type": "application/json",
|
|
1340
|
+
...options.headers
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1304
1344
|
setWorkItemParent(options) {
|
|
1305
1345
|
return (options.client ?? this.client).patch({
|
|
1306
1346
|
url: "/api/work-items/{workItemId}/parent",
|
|
@@ -1647,6 +1687,10 @@ class ScarnClient extends HeyApiClient {
|
|
|
1647
1687
|
get pipelineDefinitions() {
|
|
1648
1688
|
return this._pipelineDefinitions ??= new PipelineDefinitions({ client: this.client });
|
|
1649
1689
|
}
|
|
1690
|
+
_automations;
|
|
1691
|
+
get automations() {
|
|
1692
|
+
return this._automations ??= new Automations({ client: this.client });
|
|
1693
|
+
}
|
|
1650
1694
|
_pipelineExecutions;
|
|
1651
1695
|
get pipelineExecutions() {
|
|
1652
1696
|
return this._pipelineExecutions ??= new PipelineExecutions({ client: this.client });
|
|
@@ -1713,4 +1757,4 @@ class ScarnClient extends HeyApiClient {
|
|
|
1713
1757
|
}
|
|
1714
1758
|
}
|
|
1715
1759
|
|
|
1716
|
-
export { createClient, Api, Projects, StepDefinitions, Tasks, TaskRuns, PipelineDefinitions, PipelineExecutions, WorkItems, Conversations, WorkItemComments, WorkItemCommentDrafts, WorkItemBlocks, ProjectArtifacts, UserNotifications, Inbox, NotificationRules, ProjectIntegrations, GitHubIntegrations, ProjectInvites, Billing, Username, Secrets, ScarnClient };
|
|
1760
|
+
export { createClient, Api, Projects, StepDefinitions, Tasks, TaskRuns, PipelineDefinitions, Automations, PipelineExecutions, WorkItems, Conversations, WorkItemComments, WorkItemCommentDrafts, WorkItemBlocks, ProjectArtifacts, UserNotifications, Inbox, NotificationRules, ProjectIntegrations, GitHubIntegrations, ProjectInvites, Billing, Username, Secrets, ScarnClient };
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
jsonPointer
|
|
4
|
+
} from "./chunk-61jf8b6s.js";
|
|
5
|
+
import {
|
|
6
|
+
AuthoringError,
|
|
7
|
+
captureSite
|
|
8
|
+
} from "./chunk-y11p1q7r.js";
|
|
9
|
+
|
|
10
|
+
// src/pipelines/refs.ts
|
|
11
|
+
var REF = Symbol("scarn.ref");
|
|
12
|
+
var active = null;
|
|
13
|
+
var currentOwners = [];
|
|
14
|
+
function withOwners(owners, run) {
|
|
15
|
+
const previous = currentOwners;
|
|
16
|
+
currentOwners = owners;
|
|
17
|
+
try {
|
|
18
|
+
return run();
|
|
19
|
+
} finally {
|
|
20
|
+
currentOwners = previous;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function withTracker(tracker, run) {
|
|
24
|
+
const previous = active;
|
|
25
|
+
active = tracker;
|
|
26
|
+
try {
|
|
27
|
+
return run();
|
|
28
|
+
} finally {
|
|
29
|
+
active = previous;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function setTrackerPointer(pointer) {
|
|
33
|
+
if (active !== null) {
|
|
34
|
+
active.pointer = pointer;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
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";
|
|
38
|
+
function coercionError(path) {
|
|
39
|
+
throw new AuthoringError(`"${path === "" ? "element" : path}" was coerced to a primitive: ${COERCION_HINT}`);
|
|
40
|
+
}
|
|
41
|
+
function propertySchema(schema, key) {
|
|
42
|
+
if (key === "length") {
|
|
43
|
+
return { type: "integer" };
|
|
44
|
+
}
|
|
45
|
+
if (typeof schema !== "object") {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (/^\d+$/.test(key) && schema.items !== undefined) {
|
|
49
|
+
return schema.items;
|
|
50
|
+
}
|
|
51
|
+
return schema.properties?.[key];
|
|
52
|
+
}
|
|
53
|
+
function spreadKeys(data) {
|
|
54
|
+
const schema = data.schema;
|
|
55
|
+
if (typeof schema !== "object" || schema.properties === undefined || schema.type !== undefined && schema.type !== "object") {
|
|
56
|
+
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`);
|
|
57
|
+
}
|
|
58
|
+
return Object.keys(schema.properties);
|
|
59
|
+
}
|
|
60
|
+
function joinPath(path, key) {
|
|
61
|
+
return path === "" ? key : `${path}.${key}`;
|
|
62
|
+
}
|
|
63
|
+
function makePlaceholder(data) {
|
|
64
|
+
const children = new Map;
|
|
65
|
+
const child = (key) => {
|
|
66
|
+
const cached = children.get(key);
|
|
67
|
+
if (cached !== undefined) {
|
|
68
|
+
return cached;
|
|
69
|
+
}
|
|
70
|
+
const created = createChild(key);
|
|
71
|
+
children.set(key, created);
|
|
72
|
+
return created;
|
|
73
|
+
};
|
|
74
|
+
const spreadChild = (key) => makePlaceholder({
|
|
75
|
+
...data,
|
|
76
|
+
path: joinPath(data.path, key),
|
|
77
|
+
schema: propertySchema(data.schema, key),
|
|
78
|
+
record: data.record
|
|
79
|
+
});
|
|
80
|
+
const createChild = (key) => {
|
|
81
|
+
const record = active === null ? null : {
|
|
82
|
+
path: joinPath(data.path, key),
|
|
83
|
+
site: captureSite(),
|
|
84
|
+
pointer: active.pointer,
|
|
85
|
+
parent: data.record,
|
|
86
|
+
used: false,
|
|
87
|
+
hasChildren: false
|
|
88
|
+
};
|
|
89
|
+
if (record !== null) {
|
|
90
|
+
active?.records.push(record);
|
|
91
|
+
if (data.record !== null) {
|
|
92
|
+
data.record.hasChildren = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return makePlaceholder({
|
|
96
|
+
path: joinPath(data.path, key),
|
|
97
|
+
scope: data.scope,
|
|
98
|
+
schema: propertySchema(data.schema, key),
|
|
99
|
+
field: data.field,
|
|
100
|
+
record,
|
|
101
|
+
owner: data.owner,
|
|
102
|
+
reach: data.reach
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
let spreading;
|
|
106
|
+
return new Proxy(Object.create(null), {
|
|
107
|
+
get(_target, key) {
|
|
108
|
+
if (typeof key === "string" && key === spreading) {
|
|
109
|
+
spreading = undefined;
|
|
110
|
+
return spreadChild(key);
|
|
111
|
+
}
|
|
112
|
+
if (key === REF) {
|
|
113
|
+
return data;
|
|
114
|
+
}
|
|
115
|
+
if (key === Symbol.toPrimitive || key === "valueOf" || key === "toString" || key === "toJSON") {
|
|
116
|
+
return () => coercionError(data.path);
|
|
117
|
+
}
|
|
118
|
+
if (typeof key === "symbol" || key === "then") {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
return child(key);
|
|
122
|
+
},
|
|
123
|
+
has(_target, key) {
|
|
124
|
+
return key === REF;
|
|
125
|
+
},
|
|
126
|
+
ownKeys() {
|
|
127
|
+
return spreadKeys(data);
|
|
128
|
+
},
|
|
129
|
+
getOwnPropertyDescriptor(_target, key) {
|
|
130
|
+
if (typeof key !== "string") {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
spreading = key;
|
|
134
|
+
return {
|
|
135
|
+
configurable: true,
|
|
136
|
+
enumerable: true,
|
|
137
|
+
writable: false,
|
|
138
|
+
value: spreadChild(key)
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
set() {
|
|
142
|
+
throw new AuthoringError(`can't assign to "${data.path}"`);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function rootPlaceholder(path, schema, options = {}) {
|
|
147
|
+
const record = active === null ? null : {
|
|
148
|
+
path,
|
|
149
|
+
site: captureSite(),
|
|
150
|
+
pointer: active.pointer,
|
|
151
|
+
parent: null,
|
|
152
|
+
used: false,
|
|
153
|
+
hasChildren: false
|
|
154
|
+
};
|
|
155
|
+
if (record !== null) {
|
|
156
|
+
active?.records.push(record);
|
|
157
|
+
}
|
|
158
|
+
return makePlaceholder({
|
|
159
|
+
path,
|
|
160
|
+
scope: options.scope ?? "document",
|
|
161
|
+
schema,
|
|
162
|
+
field: options.field,
|
|
163
|
+
record,
|
|
164
|
+
owner: options.owner ?? null,
|
|
165
|
+
reach: options.reach
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function refData(value) {
|
|
169
|
+
if ((typeof value === "object" || typeof value === "function") && value !== null && REF in value) {
|
|
170
|
+
return value[REF];
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
function markUsed(data) {
|
|
175
|
+
for (let record = data.record;record !== null; record = record.parent) {
|
|
176
|
+
record.used = true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function useRef(data) {
|
|
180
|
+
markUsed(data);
|
|
181
|
+
if (data.field !== undefined) {
|
|
182
|
+
active?.fields.push(data.field);
|
|
183
|
+
}
|
|
184
|
+
if (data.reach !== undefined && active !== null) {
|
|
185
|
+
active.reaches.push({
|
|
186
|
+
node: data.reach,
|
|
187
|
+
pointer: active.pointer,
|
|
188
|
+
site: data.record?.site ?? null
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (data.owner !== null && !currentOwners.includes(data.owner)) {
|
|
192
|
+
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);
|
|
193
|
+
}
|
|
194
|
+
return data.path;
|
|
195
|
+
}
|
|
196
|
+
function unusedReads(tracker) {
|
|
197
|
+
return tracker.records.filter((record) => !record.used && !record.hasChildren);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/pipelines/condition-data.ts
|
|
201
|
+
class ConditionData {
|
|
202
|
+
node;
|
|
203
|
+
site;
|
|
204
|
+
constructor(node, site = captureSite()) {
|
|
205
|
+
this.node = node;
|
|
206
|
+
this.site = site;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
class ComputedData {
|
|
211
|
+
node;
|
|
212
|
+
site;
|
|
213
|
+
constructor(node, site = captureSite()) {
|
|
214
|
+
this.node = node;
|
|
215
|
+
this.site = site;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function conditionData(value) {
|
|
219
|
+
if (value instanceof ConditionData) {
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
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`);
|
|
223
|
+
}
|
|
224
|
+
function requireRef(value, what) {
|
|
225
|
+
const data = refData(value);
|
|
226
|
+
if (data === undefined) {
|
|
227
|
+
throw new AuthoringError(`${what} must be a reference (r.result..., r.input..., ...)`);
|
|
228
|
+
}
|
|
229
|
+
return data;
|
|
230
|
+
}
|
|
231
|
+
function refPath(ref, scope, side) {
|
|
232
|
+
if (side === "right" && ref.scope === "element") {
|
|
233
|
+
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);
|
|
234
|
+
}
|
|
235
|
+
if (side === "left" && ref.scope !== scope) {
|
|
236
|
+
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);
|
|
237
|
+
}
|
|
238
|
+
return useRef(ref);
|
|
239
|
+
}
|
|
240
|
+
function leftPath(ref, scope) {
|
|
241
|
+
const path = refPath(ref, scope, "left");
|
|
242
|
+
if (path === "") {
|
|
243
|
+
throw new AuthoringError("a condition on the whole element isn't supported; compare one of its fields", ref.record?.site ?? null);
|
|
244
|
+
}
|
|
245
|
+
return path;
|
|
246
|
+
}
|
|
247
|
+
function compileComputed(computed, scope) {
|
|
248
|
+
if ("refs" in computed) {
|
|
249
|
+
const source = computed.refs.map((ref) => leftPath(ref, scope));
|
|
250
|
+
return computed.weights === undefined ? { source } : { source, weights: computed.weights };
|
|
251
|
+
}
|
|
252
|
+
const path = leftPath(computed.list, scope);
|
|
253
|
+
if (computed.field !== undefined) {
|
|
254
|
+
return { source: { path, field: leftPath(computed.field, "element") } };
|
|
255
|
+
}
|
|
256
|
+
if (computed.where !== undefined) {
|
|
257
|
+
return {
|
|
258
|
+
source: { path, where: compileCondition(computed.where, "element") }
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return { source: { path } };
|
|
262
|
+
}
|
|
263
|
+
function compileRight(right) {
|
|
264
|
+
switch (right.kind) {
|
|
265
|
+
case "none":
|
|
266
|
+
return {};
|
|
267
|
+
case "value":
|
|
268
|
+
return { value: right.value };
|
|
269
|
+
case "ref":
|
|
270
|
+
return { ref: refPath(right.ref, "document", "right") };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function compileCondition(data, scope = "document") {
|
|
274
|
+
const node = data.node;
|
|
275
|
+
switch (node.kind) {
|
|
276
|
+
case "all":
|
|
277
|
+
case "any":
|
|
278
|
+
return {
|
|
279
|
+
[node.kind]: node.items.map((item) => compileCondition(item, scope))
|
|
280
|
+
};
|
|
281
|
+
case "not":
|
|
282
|
+
return { not: compileCondition(node.item, scope) };
|
|
283
|
+
case "list":
|
|
284
|
+
return {
|
|
285
|
+
path: leftPath(node.list, scope),
|
|
286
|
+
op: node.op,
|
|
287
|
+
where: compileCondition(node.where, "element")
|
|
288
|
+
};
|
|
289
|
+
case "compare": {
|
|
290
|
+
if (node.left.kind === "ref") {
|
|
291
|
+
return {
|
|
292
|
+
path: leftPath(node.left.ref, scope),
|
|
293
|
+
op: node.op,
|
|
294
|
+
...compileRight(node.right)
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const { source, weights } = compileComputed(node.left.computed, scope);
|
|
298
|
+
return {
|
|
299
|
+
[node.left.computed.fn]: source,
|
|
300
|
+
...weights === undefined ? {} : { weights },
|
|
301
|
+
op: node.op,
|
|
302
|
+
...compileRight(node.right)
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/pipelines/compile-args.ts
|
|
309
|
+
function literal(value, path) {
|
|
310
|
+
if (refData(value) !== undefined) {
|
|
311
|
+
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`);
|
|
312
|
+
}
|
|
313
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
314
|
+
return value;
|
|
315
|
+
}
|
|
316
|
+
if (typeof value === "number") {
|
|
317
|
+
if (!Number.isFinite(value)) {
|
|
318
|
+
throw new AuthoringError(`"${path}" is ${String(value)}, which isn't JSON`);
|
|
319
|
+
}
|
|
320
|
+
return value;
|
|
321
|
+
}
|
|
322
|
+
if (Array.isArray(value)) {
|
|
323
|
+
return value.map((item, index) => literal(item, `${path}.${String(index)}`));
|
|
324
|
+
}
|
|
325
|
+
if (typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
|
|
326
|
+
const out = {};
|
|
327
|
+
for (const [key, item] of Object.entries(value)) {
|
|
328
|
+
if (item !== undefined) {
|
|
329
|
+
out[key] = literal(item, `${path}.${key}`);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return out;
|
|
333
|
+
}
|
|
334
|
+
throw new AuthoringError(`"${path}" is a ${typeof value}, which isn't a JSON value`);
|
|
335
|
+
}
|
|
336
|
+
function refArg(name, data) {
|
|
337
|
+
if (data.scope === "element") {
|
|
338
|
+
throw new AuthoringError(`"${name}" is a list element from some / every / none / count; those exist only inside the condition`, data.record?.site ?? null);
|
|
339
|
+
}
|
|
340
|
+
return useRef(data);
|
|
341
|
+
}
|
|
342
|
+
function compileArg(name, value) {
|
|
343
|
+
const data = refData(value);
|
|
344
|
+
if (data !== undefined) {
|
|
345
|
+
return refArg(name, data);
|
|
346
|
+
}
|
|
347
|
+
if (Array.isArray(value) && value.some((item) => refData(item) !== undefined)) {
|
|
348
|
+
return {
|
|
349
|
+
list: value.map((item, index) => {
|
|
350
|
+
const path = `${name}.${String(index)}`;
|
|
351
|
+
const element = refData(item);
|
|
352
|
+
return element === undefined ? { value: literal(item, path) } : refArg(path, element);
|
|
353
|
+
})
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
return { value: literal(value, name) };
|
|
357
|
+
}
|
|
358
|
+
function argEntries(args) {
|
|
359
|
+
return Object.entries(args).filter(([, value]) => value !== undefined);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// src/pipelines/compile-state.ts
|
|
363
|
+
function newState() {
|
|
364
|
+
return {
|
|
365
|
+
nodes: new Map,
|
|
366
|
+
issues: [],
|
|
367
|
+
sourceMap: {},
|
|
368
|
+
tracker: { records: [], fields: [], reaches: [], pointer: "" },
|
|
369
|
+
usedChains: new Set
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function issue(state, site, pointer, message) {
|
|
373
|
+
state.issues.push({ site, pointer: jsonPointer(pointer), message });
|
|
374
|
+
}
|
|
375
|
+
function mapSource(state, pointer, site) {
|
|
376
|
+
const key = jsonPointer(pointer);
|
|
377
|
+
if (site !== null && state.sourceMap[key] === undefined) {
|
|
378
|
+
state.sourceMap[key] = site;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function attempt(state, pointer, site, run) {
|
|
382
|
+
const previous = state.tracker.pointer;
|
|
383
|
+
setTrackerPointer(jsonPointer(pointer));
|
|
384
|
+
try {
|
|
385
|
+
return run();
|
|
386
|
+
} catch (error) {
|
|
387
|
+
if (error instanceof AuthoringError) {
|
|
388
|
+
issue(state, error.site ?? site, pointer, error.message);
|
|
389
|
+
} else {
|
|
390
|
+
issue(state, site, pointer, error instanceof Error ? error.message : String(error));
|
|
391
|
+
}
|
|
392
|
+
return;
|
|
393
|
+
} finally {
|
|
394
|
+
setTrackerPointer(previous);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function place(state, def, site, pointer) {
|
|
398
|
+
const existing = state.nodes.get(def.id);
|
|
399
|
+
if (existing === undefined) {
|
|
400
|
+
const placed = {
|
|
401
|
+
def,
|
|
402
|
+
chain: undefined,
|
|
403
|
+
json: {}
|
|
404
|
+
};
|
|
405
|
+
state.nodes.set(def.id, placed);
|
|
406
|
+
mapSource(state, ["nodes", def.id], def.site);
|
|
407
|
+
return placed;
|
|
408
|
+
}
|
|
409
|
+
if (existing.def !== def) {
|
|
410
|
+
issue(state, site, pointer, `two different handles use the node id "${def.id}"; give one a different id (step.as("...") for steps)`);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
return existing;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export { withOwners, withTracker, rootPlaceholder, refData, useRef, unusedReads, ConditionData, ComputedData, conditionData, requireRef, compileCondition, compileArg, argEntries, newState, issue, mapSource, attempt, place };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/pipelines/source.ts
|
|
3
|
+
var FRAME = /\(?((?:file:\/\/)?[^\s()]+):(\d+):(\d+)\)?\s*$/;
|
|
4
|
+
function sdkRoot() {
|
|
5
|
+
const here = new URL(import.meta.url).pathname;
|
|
6
|
+
const parts = here.split("/");
|
|
7
|
+
return parts.slice(0, -2).join("/") + "/";
|
|
8
|
+
}
|
|
9
|
+
var SDK_ROOT = sdkRoot();
|
|
10
|
+
function toPath(file) {
|
|
11
|
+
return file.startsWith("file://") ? new URL(file).pathname : file;
|
|
12
|
+
}
|
|
13
|
+
function parseFrame(frame) {
|
|
14
|
+
const match = FRAME.exec(frame.trim());
|
|
15
|
+
if (match === null) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const [, file, line, column] = match;
|
|
19
|
+
if (file === undefined || line === undefined || column === undefined) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return { file: toPath(file), line: Number(line), column: Number(column) };
|
|
23
|
+
}
|
|
24
|
+
function captureSite(stack = new Error().stack) {
|
|
25
|
+
for (const frame of (stack ?? "").split(`
|
|
26
|
+
`).slice(1)) {
|
|
27
|
+
const site = parseFrame(frame);
|
|
28
|
+
if (site !== null && !site.file.startsWith(SDK_ROOT) && !site.file.startsWith("node:") && site.file.includes("/")) {
|
|
29
|
+
return site;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function cwd() {
|
|
35
|
+
const proc = globalThis.process;
|
|
36
|
+
return typeof proc?.cwd === "function" ? proc.cwd() : null;
|
|
37
|
+
}
|
|
38
|
+
function formatSite(site) {
|
|
39
|
+
if (site === null) {
|
|
40
|
+
return "<unknown>";
|
|
41
|
+
}
|
|
42
|
+
const base = cwd();
|
|
43
|
+
const file = base !== null && site.file.startsWith(`${base}/`) ? site.file.slice(base.length + 1) : site.file;
|
|
44
|
+
return `${file}:${String(site.line)}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/pipelines/errors.ts
|
|
48
|
+
function formatIssue(issue) {
|
|
49
|
+
return `${formatSite(issue.site)} (${issue.pointer === "" ? "/" : issue.pointer}): ${issue.message}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
class PipelineBuildError extends Error {
|
|
53
|
+
issues;
|
|
54
|
+
constructor(key, issues) {
|
|
55
|
+
super(`Pipeline "${key}" has ${String(issues.length)} build error${issues.length === 1 ? "" : "s"}:
|
|
56
|
+
${issues.map((issue) => ` ${formatIssue(issue)}`).join(`
|
|
57
|
+
`)}`);
|
|
58
|
+
this.name = "PipelineBuildError";
|
|
59
|
+
this.issues = issues;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
class AuthoringError extends Error {
|
|
64
|
+
site;
|
|
65
|
+
constructor(message, site = captureSite()) {
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = "AuthoringError";
|
|
68
|
+
this.site = site;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/automations/targets.ts
|
|
73
|
+
var SUBJECT = Symbol("scarn.automation.subject");
|
|
74
|
+
var targets = new WeakMap;
|
|
75
|
+
function registerAutomationTarget(data) {
|
|
76
|
+
const value = Object.freeze({ _tag: "automation_target", kind: data.kind });
|
|
77
|
+
targets.set(value, data);
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
function automationTargetOf(value) {
|
|
81
|
+
return (typeof value === "object" || typeof value === "function") && value !== null ? targets.get(value) : undefined;
|
|
82
|
+
}
|
|
83
|
+
function markSubject(value, subject) {
|
|
84
|
+
Object.defineProperty(value, SUBJECT, { value: subject, enumerable: false });
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
function subjectOf(value) {
|
|
88
|
+
const subject = typeof value === "object" && value !== null && SUBJECT in value ? value[SUBJECT] : undefined;
|
|
89
|
+
if (subject === undefined) {
|
|
90
|
+
throw new AuthoringError(".on(...) takes the work item to start for: r.workItem, or r.child on child.* events");
|
|
91
|
+
}
|
|
92
|
+
return subject;
|
|
93
|
+
}
|
|
94
|
+
function stepOn(target) {
|
|
95
|
+
return (subject) => registerAutomationTarget({
|
|
96
|
+
kind: "step",
|
|
97
|
+
target,
|
|
98
|
+
on: subjectOf(subject),
|
|
99
|
+
site: captureSite()
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function pipelineOn(pipeline) {
|
|
103
|
+
return (subject) => registerAutomationTarget({
|
|
104
|
+
kind: "pipeline",
|
|
105
|
+
pipeline,
|
|
106
|
+
on: subjectOf(subject),
|
|
107
|
+
site: captureSite()
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/pipelines/registry.ts
|
|
112
|
+
var nodes = new WeakMap;
|
|
113
|
+
var targets2 = new WeakMap;
|
|
114
|
+
var eaches = new WeakMap;
|
|
115
|
+
var chains = new WeakMap;
|
|
116
|
+
var pendingChains = new Set;
|
|
117
|
+
function registerNode(value, node) {
|
|
118
|
+
nodes.set(value, node);
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
function registerTarget(value, target) {
|
|
122
|
+
targets2.set(value, target);
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
function registerEach(value, each) {
|
|
126
|
+
eaches.set(value, each);
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
function registerChain(value, chain) {
|
|
130
|
+
chains.set(value, chain);
|
|
131
|
+
if (chain.next !== undefined) {
|
|
132
|
+
pendingChains.add(chain);
|
|
133
|
+
}
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
function isObject(value) {
|
|
137
|
+
return (typeof value === "object" || typeof value === "function") && value !== null;
|
|
138
|
+
}
|
|
139
|
+
function nodeOf(value) {
|
|
140
|
+
return isObject(value) ? nodes.get(value) : undefined;
|
|
141
|
+
}
|
|
142
|
+
function targetOf(value) {
|
|
143
|
+
return isObject(value) ? targets2.get(value) : undefined;
|
|
144
|
+
}
|
|
145
|
+
function eachOf(value) {
|
|
146
|
+
return isObject(value) ? eaches.get(value) : undefined;
|
|
147
|
+
}
|
|
148
|
+
function chainOf(value) {
|
|
149
|
+
return isObject(value) ? chains.get(value) : undefined;
|
|
150
|
+
}
|
|
151
|
+
function requireNode(value, what) {
|
|
152
|
+
const node = nodeOf(value);
|
|
153
|
+
if (node === undefined) {
|
|
154
|
+
throw new AuthoringError(`${what} must be a step, decision or reply handle`);
|
|
155
|
+
}
|
|
156
|
+
return node;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { captureSite, formatIssue, PipelineBuildError, AuthoringError, registerAutomationTarget, automationTargetOf, markSubject, stepOn, pipelineOn, pendingChains, registerNode, registerTarget, registerEach, registerChain, nodeOf, targetOf, eachOf, chainOf, requireNode };
|
package/dist/client.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
createScarnClient,
|
|
4
4
|
createTaskPlaneClient
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-3gy0cb5f.js";
|
|
6
6
|
import {
|
|
7
7
|
Api,
|
|
8
|
+
Automations,
|
|
8
9
|
Billing,
|
|
9
10
|
Conversations,
|
|
10
11
|
GitHubIntegrations,
|
|
@@ -27,10 +28,11 @@ import {
|
|
|
27
28
|
WorkItemCommentDrafts,
|
|
28
29
|
WorkItemComments,
|
|
29
30
|
WorkItems
|
|
30
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-wnfj3wyx.js";
|
|
31
32
|
import"./chunk-y64skrwp.js";
|
|
32
33
|
export {
|
|
33
34
|
Api,
|
|
35
|
+
Automations,
|
|
34
36
|
Billing,
|
|
35
37
|
Conversations,
|
|
36
38
|
GitHubIntegrations,
|