@scarn/sdk 0.8.1 → 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.
- 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-dp86pa6m.js → chunk-01nfqm18.js} +5 -1
- package/dist/chunk-0vzq22dj.js +73 -0
- package/dist/chunk-11hbmexe.js +250 -0
- package/dist/{chunk-700xe701.js → chunk-3gy0cb5f.js} +5 -1
- package/dist/{chunk-102vfpw4.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-3ctaaseb.js → chunk-fyfvp6jx.js} +48 -21
- package/dist/{chunk-mz53r914.js → chunk-jj9pezwb.js} +22 -119
- package/dist/{chunk-vfeytkqx.js → chunk-wnfj3wyx.js} +106 -33
- package/dist/chunk-x0hjhqrf.js +416 -0
- package/dist/chunk-y11p1q7r.js +159 -0
- package/dist/client.js +6 -4
- 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 +51 -0
- package/dist/contracts/work-item-changes.js +68 -0
- 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 +3 -1
- package/dist/definitions/steps/define-step.d.ts +29 -1
- package/dist/definitions/steps/index.js +12 -7
- 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 +18 -0
- package/dist/definitions/steps/step-features.d.ts +2 -2
- package/dist/definitions/steps/step-handle.d.ts +8 -1
- package/dist/definitions/validation/index.js +2 -2
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/sdk.gen.d.ts +66 -11
- package/dist/generated/types.gen.d.ts +5513 -3488
- package/dist/index.d.ts +1 -0
- package/dist/index.js +61 -49
- 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 +90 -127
- 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 +42 -0
- package/package.json +17 -1
- package/dist/chunk-zm72ksz0.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
|
}
|
|
@@ -878,15 +884,8 @@ class Projects extends HeyApiClient {
|
|
|
878
884
|
}
|
|
879
885
|
});
|
|
880
886
|
}
|
|
881
|
-
|
|
882
|
-
return (options.client ?? this.client).
|
|
883
|
-
url: "/api/projects/{projectId}/default-pipeline-assignment",
|
|
884
|
-
...options,
|
|
885
|
-
headers: {
|
|
886
|
-
"Content-Type": "application/json",
|
|
887
|
-
...options.headers
|
|
888
|
-
}
|
|
889
|
-
});
|
|
887
|
+
listProjectMembers(options) {
|
|
888
|
+
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/members", ...options });
|
|
890
889
|
}
|
|
891
890
|
updateProjectMemberPermissions(options) {
|
|
892
891
|
return (options.client ?? this.client).put({ url: "/api/projects/{projectId}/members/{userId}/permissions", ...options });
|
|
@@ -956,12 +955,18 @@ class Tasks extends HeyApiClient {
|
|
|
956
955
|
}
|
|
957
956
|
});
|
|
958
957
|
}
|
|
958
|
+
cancelTask(options) {
|
|
959
|
+
return (options.client ?? this.client).post({ url: "/api/tasks/{taskId}/cancel", ...options });
|
|
960
|
+
}
|
|
959
961
|
getTask(options) {
|
|
960
962
|
return (options.client ?? this.client).get({ url: "/api/tasks/{taskId}", ...options });
|
|
961
963
|
}
|
|
962
964
|
getTaskRuns(options) {
|
|
963
965
|
return (options.client ?? this.client).get({ url: "/api/tasks/{taskId}/runs", ...options });
|
|
964
966
|
}
|
|
967
|
+
listProjectTasks(options) {
|
|
968
|
+
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/tasks", ...options });
|
|
969
|
+
}
|
|
965
970
|
}
|
|
966
971
|
|
|
967
972
|
class TaskRuns extends HeyApiClient {
|
|
@@ -1050,6 +1055,16 @@ class TaskRuns extends HeyApiClient {
|
|
|
1050
1055
|
}
|
|
1051
1056
|
});
|
|
1052
1057
|
}
|
|
1058
|
+
readTaskRunWorkItem(options) {
|
|
1059
|
+
return (options.client ?? this.client).post({
|
|
1060
|
+
url: "/api/task-runs/{taskRunId}/work-item-reads",
|
|
1061
|
+
...options,
|
|
1062
|
+
headers: {
|
|
1063
|
+
"Content-Type": "application/json",
|
|
1064
|
+
...options.headers
|
|
1065
|
+
}
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1053
1068
|
createArtifactUploadUrl(options) {
|
|
1054
1069
|
return (options.client ?? this.client).post({
|
|
1055
1070
|
url: "/api/task-runs/{taskRunId}/artifact-upload-url",
|
|
@@ -1135,6 +1150,37 @@ class PipelineDefinitions extends HeyApiClient {
|
|
|
1135
1150
|
}
|
|
1136
1151
|
}
|
|
1137
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
|
+
|
|
1138
1184
|
class PipelineExecutions extends HeyApiClient {
|
|
1139
1185
|
listPipelineExecutions(options) {
|
|
1140
1186
|
return (options.client ?? this.client).get({ url: "/api/pipeline-executions", ...options });
|
|
@@ -1152,6 +1198,16 @@ class PipelineExecutions extends HeyApiClient {
|
|
|
1152
1198
|
rerunPipelineExecutionVisit(options) {
|
|
1153
1199
|
return (options.client ?? this.client).post({ url: "/api/pipeline-executions/{pipelineExecutionId}/visits/{visitId}/rerun", ...options });
|
|
1154
1200
|
}
|
|
1201
|
+
answerQuestion(options) {
|
|
1202
|
+
return (options.client ?? this.client).post({
|
|
1203
|
+
url: "/api/pipeline-executions/{pipelineExecutionId}/questions/{questionId}/answer",
|
|
1204
|
+
...options,
|
|
1205
|
+
headers: {
|
|
1206
|
+
"Content-Type": "application/json",
|
|
1207
|
+
...options.headers
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1155
1211
|
continueWithoutReply(options) {
|
|
1156
1212
|
return (options.client ?? this.client).post({ url: "/api/pipeline-executions/{pipelineExecutionId}/questions/{questionId}/continue", ...options });
|
|
1157
1213
|
}
|
|
@@ -1222,6 +1278,9 @@ class WorkItems extends HeyApiClient {
|
|
|
1222
1278
|
listWorkItemChildren(options) {
|
|
1223
1279
|
return (options.client ?? this.client).get({ url: "/api/work-items/{workItemId}/children", ...options });
|
|
1224
1280
|
}
|
|
1281
|
+
listWorkItemActivity(options) {
|
|
1282
|
+
return (options.client ?? this.client).get({ url: "/api/work-items/{workItemId}/activity", ...options });
|
|
1283
|
+
}
|
|
1225
1284
|
createWorkItem(options) {
|
|
1226
1285
|
return (options.client ?? this.client).post({
|
|
1227
1286
|
url: "/api/work-items",
|
|
@@ -1272,6 +1331,16 @@ class WorkItems extends HeyApiClient {
|
|
|
1272
1331
|
}
|
|
1273
1332
|
});
|
|
1274
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
|
+
}
|
|
1275
1344
|
setWorkItemParent(options) {
|
|
1276
1345
|
return (options.client ?? this.client).patch({
|
|
1277
1346
|
url: "/api/work-items/{workItemId}/parent",
|
|
@@ -1282,6 +1351,16 @@ class WorkItems extends HeyApiClient {
|
|
|
1282
1351
|
}
|
|
1283
1352
|
});
|
|
1284
1353
|
}
|
|
1354
|
+
setWorkItemState(options) {
|
|
1355
|
+
return (options.client ?? this.client).put({
|
|
1356
|
+
url: "/api/work-items/{workItemId}/state",
|
|
1357
|
+
...options,
|
|
1358
|
+
headers: {
|
|
1359
|
+
"Content-Type": "application/json",
|
|
1360
|
+
...options.headers
|
|
1361
|
+
}
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1285
1364
|
}
|
|
1286
1365
|
|
|
1287
1366
|
class Conversations extends HeyApiClient {
|
|
@@ -1430,6 +1509,15 @@ class UserNotifications extends HeyApiClient {
|
|
|
1430
1509
|
}
|
|
1431
1510
|
}
|
|
1432
1511
|
|
|
1512
|
+
class Inbox extends HeyApiClient {
|
|
1513
|
+
listProjectInboxWaits(options) {
|
|
1514
|
+
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/inbox/waits", ...options });
|
|
1515
|
+
}
|
|
1516
|
+
getProjectInboxSummary(options) {
|
|
1517
|
+
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/inbox/summary", ...options });
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1433
1521
|
class NotificationRules extends HeyApiClient {
|
|
1434
1522
|
listNotificationRules(options) {
|
|
1435
1523
|
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/notification-rules", ...options });
|
|
@@ -1446,25 +1534,6 @@ class NotificationRules extends HeyApiClient {
|
|
|
1446
1534
|
}
|
|
1447
1535
|
}
|
|
1448
1536
|
|
|
1449
|
-
class StepDefinitionTemplates extends HeyApiClient {
|
|
1450
|
-
listStepDefinitionTemplates(options) {
|
|
1451
|
-
return (options?.client ?? this.client).get({ url: "/api/step-definition-templates", ...options });
|
|
1452
|
-
}
|
|
1453
|
-
getStepDefinitionTemplate(options) {
|
|
1454
|
-
return (options.client ?? this.client).get({ url: "/api/step-definition-templates/{stepDefinitionTemplateId}", ...options });
|
|
1455
|
-
}
|
|
1456
|
-
instantiateStepDefinitionTemplate(options) {
|
|
1457
|
-
return (options.client ?? this.client).post({
|
|
1458
|
-
url: "/api/step-definition-templates/{stepDefinitionTemplateId}/instantiate",
|
|
1459
|
-
...options,
|
|
1460
|
-
headers: {
|
|
1461
|
-
"Content-Type": "application/json",
|
|
1462
|
-
...options.headers
|
|
1463
|
-
}
|
|
1464
|
-
});
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
1537
|
class ProjectIntegrations extends HeyApiClient {
|
|
1469
1538
|
listProjectIntegrations(options) {
|
|
1470
1539
|
return (options.client ?? this.client).get({ url: "/api/projects/{projectId}/integrations", ...options });
|
|
@@ -1618,6 +1687,10 @@ class ScarnClient extends HeyApiClient {
|
|
|
1618
1687
|
get pipelineDefinitions() {
|
|
1619
1688
|
return this._pipelineDefinitions ??= new PipelineDefinitions({ client: this.client });
|
|
1620
1689
|
}
|
|
1690
|
+
_automations;
|
|
1691
|
+
get automations() {
|
|
1692
|
+
return this._automations ??= new Automations({ client: this.client });
|
|
1693
|
+
}
|
|
1621
1694
|
_pipelineExecutions;
|
|
1622
1695
|
get pipelineExecutions() {
|
|
1623
1696
|
return this._pipelineExecutions ??= new PipelineExecutions({ client: this.client });
|
|
@@ -1650,14 +1723,14 @@ class ScarnClient extends HeyApiClient {
|
|
|
1650
1723
|
get userNotifications() {
|
|
1651
1724
|
return this._userNotifications ??= new UserNotifications({ client: this.client });
|
|
1652
1725
|
}
|
|
1726
|
+
_inbox;
|
|
1727
|
+
get inbox() {
|
|
1728
|
+
return this._inbox ??= new Inbox({ client: this.client });
|
|
1729
|
+
}
|
|
1653
1730
|
_notificationRules;
|
|
1654
1731
|
get notificationRules() {
|
|
1655
1732
|
return this._notificationRules ??= new NotificationRules({ client: this.client });
|
|
1656
1733
|
}
|
|
1657
|
-
_stepDefinitionTemplates;
|
|
1658
|
-
get stepDefinitionTemplates() {
|
|
1659
|
-
return this._stepDefinitionTemplates ??= new StepDefinitionTemplates({ client: this.client });
|
|
1660
|
-
}
|
|
1661
1734
|
_projectIntegrations;
|
|
1662
1735
|
get projectIntegrations() {
|
|
1663
1736
|
return this._projectIntegrations ??= new ProjectIntegrations({ client: this.client });
|
|
@@ -1684,4 +1757,4 @@ class ScarnClient extends HeyApiClient {
|
|
|
1684
1757
|
}
|
|
1685
1758
|
}
|
|
1686
1759
|
|
|
1687
|
-
export { createClient, Api, Projects, StepDefinitions, Tasks, TaskRuns, PipelineDefinitions, PipelineExecutions, WorkItems, Conversations, WorkItemComments, WorkItemCommentDrafts, WorkItemBlocks, ProjectArtifacts, UserNotifications,
|
|
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 };
|