@elementumai/edk 0.10.4 → 0.11.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/README.md +11 -7
- package/dist-sdk/src/catalog/token.js +2 -1
- package/dist-sdk/src/core/wire/ref-serializer.js +26 -1
- package/dist-sdk/src/engine/build/context.d.ts +4 -0
- package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
- package/dist-sdk/src/engine/coverage-gaps.js +3 -0
- package/dist-sdk/src/engine/ei/json-stream-reader.d.ts +43 -0
- package/dist-sdk/src/engine/ei/json-stream-reader.js +234 -0
- package/dist-sdk/src/engine/ei/run.d.ts +22 -0
- package/dist-sdk/src/engine/ei/run.js +99 -18
- package/dist-sdk/src/engine/ei/saved-plan.d.ts +16 -0
- package/dist-sdk/src/engine/ei/saved-plan.js +19 -0
- package/dist-sdk/src/engine/ei/state.d.ts +1 -1
- package/dist-sdk/src/engine/ei/state.js +17 -4
- package/dist-sdk/src/engine/progress.d.ts +3 -1
- package/dist-sdk/src/engine/progress.js +7 -3
- package/dist-sdk/src/engine/pull/authored-address.d.ts +15 -1
- package/dist-sdk/src/engine/pull/authored-address.js +180 -29
- package/dist-sdk/src/engine/pull/context.d.ts +37 -2
- package/dist-sdk/src/engine/pull/context.js +7 -4
- package/dist-sdk/src/engine/tf/index.d.ts +2 -2
- package/dist-sdk/src/engine/tf/index.js +2 -2
- package/dist-sdk/src/engine/tf/labels.d.ts +22 -0
- package/dist-sdk/src/engine/tf/labels.js +50 -0
- package/dist-sdk/src/engine/tf/model.d.ts +2 -0
- package/dist-sdk/src/engine/tf/model.js +26 -0
- package/dist-sdk/src/engine/validation.d.ts +2 -0
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +17 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +52 -24
- package/dist-sdk/src/entities/access-policy/member-list.d.ts +32 -0
- package/dist-sdk/src/entities/access-policy/member-list.js +57 -0
- package/dist-sdk/src/entities/access-policy/module.js +5 -0
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +4 -3
- package/dist-sdk/src/entities/access-policy/to-tf.js +21 -12
- package/dist-sdk/src/entities/agent/build.js +7 -5
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -0
- package/dist-sdk/src/entities/agent/from-tf.js +13 -3
- package/dist-sdk/src/entities/agent/to-tf.js +11 -5
- package/dist-sdk/src/entities/agent/tools.d.ts +8 -0
- package/dist-sdk/src/entities/agent/tools.js +6 -2
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +29 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.js +56 -3
- package/dist-sdk/src/entities/agent-tool/types.d.ts +12 -8
- package/dist-sdk/src/entities/agent-tool/types.js +13 -9
- package/dist-sdk/src/entities/app/build.d.ts +11 -0
- package/dist-sdk/src/entities/app/build.js +1 -0
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +5 -7
- package/dist-sdk/src/entities/app/from-tf.js +16 -10
- package/dist-sdk/src/entities/app/to-tf.js +6 -4
- package/dist-sdk/src/entities/automation/build.d.ts +2 -7
- package/dist-sdk/src/entities/automation/build.js +43 -14
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +7 -4
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +7 -11
- package/dist-sdk/src/entities/automation/from-tf.d.ts +23 -1
- package/dist-sdk/src/entities/automation/from-tf.js +456 -34
- package/dist-sdk/src/entities/automation/index.d.ts +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +22 -2
- package/dist-sdk/src/entities/automation/module.js +244 -57
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +22 -2
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +54 -3
- package/dist-sdk/src/entities/automation/run-target.d.ts +59 -0
- package/dist-sdk/src/entities/automation/run-target.js +99 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +9 -0
- package/dist-sdk/src/entities/automation/script-code.js +24 -3
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +16 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +49 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +20 -8
- package/dist-sdk/src/entities/automation/to-tf.d.ts +1 -3
- package/dist-sdk/src/entities/automation/to-tf.js +102 -40
- package/dist-sdk/src/entities/automation/triggers.d.ts +22 -3
- package/dist-sdk/src/entities/automation/triggers.js +40 -0
- package/dist-sdk/src/entities/automation/types.d.ts +21 -0
- package/dist-sdk/src/entities/automation/types.js +26 -0
- package/dist-sdk/src/entities/dashboard/from-tf.d.ts +11 -1
- package/dist-sdk/src/entities/dashboard/from-tf.js +57 -7
- package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +7 -2
- package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +65 -19
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +4 -2
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +341 -32
- package/dist-sdk/src/entities/element/build.d.ts +10 -0
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/from-tf.js +14 -9
- package/dist-sdk/src/entities/element/to-tf.js +6 -4
- package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
- package/dist-sdk/src/entities/field/from-tf.js +79 -1
- package/dist-sdk/src/entities/field/module.js +7 -0
- package/dist-sdk/src/entities/field/to-tf.d.ts +30 -1
- package/dist-sdk/src/entities/field/to-tf.js +51 -0
- package/dist-sdk/src/entities/file-reader/module.js +3 -3
- package/dist-sdk/src/entities/file-reader/to-tf.js +3 -3
- package/dist-sdk/src/entities/file-reader/types.d.ts +4 -16
- package/dist-sdk/src/entities/file-reader/types.js +7 -0
- package/dist-sdk/src/entities/org/group.d.ts +1 -0
- package/dist-sdk/src/entities/org/group.js +2 -1
- package/dist-sdk/src/entities/record-create-form/from-tf.d.ts +8 -0
- package/dist-sdk/src/entities/record-create-form/from-tf.js +10 -2
- package/dist-sdk/src/entities/record-create-form/to-tf.d.ts +2 -1
- package/dist-sdk/src/entities/record-create-form/to-tf.js +14 -2
- package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -0
- package/dist-sdk/src/entities/relationship/from-tf.js +88 -10
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +3 -2
- package/dist-sdk/src/entities/relationship/to-tf.js +79 -8
- package/dist-sdk/src/entities/role/from-tf.js +24 -7
- package/dist-sdk/src/entities/role/to-tf.js +25 -7
- package/dist-sdk/src/entities/service-account/from-tf.js +2 -1
- package/dist-sdk/src/entities/service-account/module.js +15 -0
- package/dist-sdk/src/entities/service-account/to-tf.js +12 -4
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +1 -1
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +12 -7
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -2
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +8 -1
- package/dist-sdk/src/entities/skill/from-tf.js +10 -3
- package/dist-sdk/src/entities/skill/module.js +16 -0
- package/dist-sdk/src/entities/skill/to-tf.d.ts +8 -1
- package/dist-sdk/src/entities/skill/to-tf.js +23 -14
- package/dist-sdk/src/entities/skill/tools.d.ts +8 -0
- package/dist-sdk/src/entities/skill/tools.js +6 -2
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +8 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +8 -2
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +20 -10
- package/dist-sdk/src/entities/view/from-tf.d.ts +60 -0
- package/dist-sdk/src/entities/view/from-tf.js +391 -17
- package/dist-sdk/src/entities/view/module.js +15 -0
- package/dist-sdk/src/entities/view/portable.d.ts +11 -0
- package/dist-sdk/src/entities/view/portable.js +47 -0
- package/dist-sdk/src/entities/view/to-tf.d.ts +4 -1
- package/dist-sdk/src/entities/view/to-tf.js +25 -7
- package/dist-sdk/src/entities/view/types.js +1 -1
- package/dist-sdk/src/entities/widget/build.d.ts +4 -3
- package/dist-sdk/src/entities/widget/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/widget/from-tf.js +100 -3
- package/dist-sdk/src/entities/widget/to-tf.d.ts +16 -1
- package/dist-sdk/src/entities/widget/to-tf.js +77 -14
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +27 -8
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/field-resource-types.d.ts +2 -0
- package/dist-sdk/src/graph/field-resource-types.js +11 -0
- package/dist-sdk/src/graph/index.d.ts +28 -3
- package/dist-sdk/src/graph/index.js +12 -2
- package/dist-sdk/src/graph/types.d.ts +157 -5
- package/package.json +1 -1
|
@@ -20,7 +20,7 @@ import { systemRefNameRoundTrips } from "./system-ref-name.js";
|
|
|
20
20
|
import { taskTfLabel } from "./task-label.js";
|
|
21
21
|
import { parseTriggerAttachmentPayloadRefJson, parseTriggerWholeRecordRefJson, TRIGGER_WHOLE_RECORD_REF_NAME } from "./task-output-labels.js";
|
|
22
22
|
import { workflowOutputTypeFromFieldType } from "./workflow-output.js";
|
|
23
|
-
import { ALL_AUTOMATION_TASK_TYPE_SET, AUTOMATION_BRANCH_TYPE_SET, AUTOMATION_RESOURCE_TYPE, AUTOMATION_TRIGGER_TYPE_SET, WORKFLOW_PUBLISH_RESOURCE_TYPE, } from "./types.js";
|
|
23
|
+
import { ALL_AUTOMATION_TASK_TYPE_SET, AUTOMATION_BRANCH_TYPE_SET, AUTOMATION_RESOURCE_TYPE, AUTOMATION_TRIGGER_TYPE_SET, WEBHOOK_REQUEST_REF_PATTERN, WORKFLOW_PUBLISH_RESOURCE_TYPE, } from "./types.js";
|
|
24
24
|
const TRIGGER_KINDS = {
|
|
25
25
|
elementum_record_created_trigger: "recordCreate",
|
|
26
26
|
elementum_record_updated_trigger: "recordUpdate",
|
|
@@ -35,6 +35,7 @@ const TRIGGER_KINDS = {
|
|
|
35
35
|
elementum_datamine_trigger: "dataMine",
|
|
36
36
|
elementum_survey_trigger: "surveyResponseCreate",
|
|
37
37
|
elementum_schedule_trigger: "schedule",
|
|
38
|
+
elementum_temporal_trigger: "temporal",
|
|
38
39
|
};
|
|
39
40
|
const TASK_FACTORIES = {
|
|
40
41
|
elementum_message_task: "postComment",
|
|
@@ -175,6 +176,11 @@ function scriptOutputScalarFromStringNode(definition) {
|
|
|
175
176
|
throw new EntityTfError(`unsupported execute-script output string format ${JSON.stringify(format)}; expected DATE, DATETIME, EMAIL, or UUID4`);
|
|
176
177
|
}
|
|
177
178
|
}
|
|
179
|
+
/** An api task block's `response_type`; undefined when absent (the provider default, JSON). */
|
|
180
|
+
function apiResponseTypeAttr(block) {
|
|
181
|
+
const value = block?.attrs.response_type;
|
|
182
|
+
return typeof value === "string" ? value : undefined;
|
|
183
|
+
}
|
|
178
184
|
/**
|
|
179
185
|
* Detects a switch task's default/catch-all branch and which of the two
|
|
180
186
|
* mutually-exclusive wire shapes the platform is currently using to mark it.
|
|
@@ -327,6 +333,7 @@ const TRIGGER_ATTRIBUTES = new Set([
|
|
|
327
333
|
"fire_on_recovery", "email_alias_id", "survey_template_id",
|
|
328
334
|
"frequency", "interval", "timezone", "start_at", "weekdays", "day_of_month",
|
|
329
335
|
"end_at", "ends_after_count", "interval_unit",
|
|
336
|
+
"aspect_field_id", "temporal_unit", "value",
|
|
330
337
|
]);
|
|
331
338
|
const TASK_ATTRIBUTES = new Set([
|
|
332
339
|
"parent", "name", "depends_on", "filter", "fields", "inputs", "output_schema",
|
|
@@ -644,20 +651,6 @@ function aiAgentTaskRefPath(block, name) {
|
|
|
644
651
|
.find((fieldName) => (fieldName === candidate || fieldName.toLowerCase() === candidate.toLowerCase()));
|
|
645
652
|
return schemaName === undefined ? undefined : ["result", schemaName];
|
|
646
653
|
}
|
|
647
|
-
/**
|
|
648
|
-
* A webhook trigger's `body`/`headers` refs come back as "Body (Plain
|
|
649
|
-
* Text)"/"Headers (Content-Type)" - one wire segment naming both the
|
|
650
|
-
* top-level property (always "body"/"headers", both typed
|
|
651
|
-
* `Record<string, unknown>` on WebhookTriggerOutput) and an arbitrary
|
|
652
|
-
* sub-key. Splitting it lets the sub-key print as a plain bracket access on
|
|
653
|
-
* an already string-indexable type, instead of a false top-level property
|
|
654
|
-
* like `ctx.trigger["Body (Plain Text)"]` that WebhookTriggerOutput never
|
|
655
|
-
* declares. Gated on the trigger's actual resource type, not just the
|
|
656
|
-
* string shape - a different trigger's field could otherwise coincidentally
|
|
657
|
-
* be named "Body (something)" and get misinterpreted as this webhook-only
|
|
658
|
-
* convention.
|
|
659
|
-
*/
|
|
660
|
-
const WEBHOOK_REF_PATTERN = /^(Body|Headers) \((.+)\)$/;
|
|
661
654
|
function aspectOwnerRefNameFromObjectId(objectId, appRefName, appTfLabel, dataBlocks, foreignAppRefNames, foreignElementRefNames, foreignTaskRefNames) {
|
|
662
655
|
if (!isTfExpr(objectId))
|
|
663
656
|
return undefined;
|
|
@@ -1155,7 +1148,18 @@ function triggerRefPath(path, ctx) {
|
|
|
1155
1148
|
return ["body_html"];
|
|
1156
1149
|
}
|
|
1157
1150
|
if (ctx.trigger.type === "elementum_webhook_trigger") {
|
|
1158
|
-
|
|
1151
|
+
// A webhook trigger's `body`/`headers` refs come back as "Body (Plain
|
|
1152
|
+
// Text)"/"Headers (Content-Type)" - one wire segment naming both the
|
|
1153
|
+
// top-level property (always "body"/"headers", both typed
|
|
1154
|
+
// `Record<string, unknown>` on WebhookTriggerOutput) and an arbitrary
|
|
1155
|
+
// sub-key. Splitting it lets the sub-key print as a plain bracket access on
|
|
1156
|
+
// an already string-indexable type, instead of a false top-level property
|
|
1157
|
+
// like `ctx.trigger["Body (Plain Text)"]` that WebhookTriggerOutput never
|
|
1158
|
+
// declares. Gated on the trigger's actual resource type, not just the
|
|
1159
|
+
// string shape - a different trigger's field could otherwise coincidentally
|
|
1160
|
+
// be named "Body (something)" and get misinterpreted as this webhook-only
|
|
1161
|
+
// convention.
|
|
1162
|
+
const webhookMatch = WEBHOOK_REQUEST_REF_PATTERN.exec(wireName);
|
|
1159
1163
|
if (webhookMatch)
|
|
1160
1164
|
return [webhookMatch[1].toLowerCase(), webhookMatch[2]];
|
|
1161
1165
|
}
|
|
@@ -1381,7 +1385,7 @@ function decodeTaskReferenceFromString(taskIdOrKey, pathSegments, ctx) {
|
|
|
1381
1385
|
}
|
|
1382
1386
|
}
|
|
1383
1387
|
if (block?.type === "elementum_api_task" && pathSegments.length === 1) {
|
|
1384
|
-
const apiPath = apiTaskRefAuthoringPath(pathSegments[0]);
|
|
1388
|
+
const apiPath = apiTaskRefAuthoringPath(pathSegments[0], apiResponseTypeAttr(block));
|
|
1385
1389
|
if (apiPath !== undefined) {
|
|
1386
1390
|
return { kind: "taskRef", task: refKey, path: apiPath };
|
|
1387
1391
|
}
|
|
@@ -1903,7 +1907,7 @@ function decodeValue(value, ctx) {
|
|
|
1903
1907
|
// …) that don't match the lowercase authoring property names
|
|
1904
1908
|
// (`file`, `file.contentType`) - see API_TASK_REF_AUTHORING_NAMES.
|
|
1905
1909
|
if (task.block.type === "elementum_api_task" && rawSegments.length === 1) {
|
|
1906
|
-
const apiPath = apiTaskRefAuthoringPath(rawSegments[0]);
|
|
1910
|
+
const apiPath = apiTaskRefAuthoringPath(rawSegments[0], apiResponseTypeAttr(task.block));
|
|
1907
1911
|
if (apiPath !== undefined) {
|
|
1908
1912
|
return { kind: "taskRef", task: task.refKey, path: apiPath };
|
|
1909
1913
|
}
|
|
@@ -2391,6 +2395,153 @@ const FILTER_FIELD_SCOPE_BY_FACTORY = {
|
|
|
2391
2395
|
userSearch: "user",
|
|
2392
2396
|
userGroupSearch: "userGroup",
|
|
2393
2397
|
};
|
|
2398
|
+
function collectOptionLabels(out, value) {
|
|
2399
|
+
if (!Array.isArray(value))
|
|
2400
|
+
return;
|
|
2401
|
+
for (const item of value) {
|
|
2402
|
+
if (!isObject(item) || typeof item.label !== "string" || item.label === "")
|
|
2403
|
+
continue;
|
|
2404
|
+
out.add(item.label);
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
function labelsFromOptions(value) {
|
|
2408
|
+
const labels = new Set();
|
|
2409
|
+
collectOptionLabels(labels, value);
|
|
2410
|
+
return labels.size > 0 ? labels : undefined;
|
|
2411
|
+
}
|
|
2412
|
+
/**
|
|
2413
|
+
* Option labels build can turn back into an options-by-label local for this
|
|
2414
|
+
* field id expression. A reference to another task's record is not a field
|
|
2415
|
+
* id, and a stub without options cannot be reversed (#2099).
|
|
2416
|
+
*/
|
|
2417
|
+
function optionLabelsForFieldIdExpr(value, blocks) {
|
|
2418
|
+
if (!isTfExpr(value))
|
|
2419
|
+
return undefined;
|
|
2420
|
+
if (value.$expr === "resource-attr" && value.type.endsWith("_field") && value.path[0] === "id") {
|
|
2421
|
+
const block = blocks.get(`${value.type}.${value.label}`);
|
|
2422
|
+
if (block?.type !== "elementum_dropdown_field" && block?.type !== "elementum_multiselect_field")
|
|
2423
|
+
return undefined;
|
|
2424
|
+
return labelsFromOptions(block.attrs.options);
|
|
2425
|
+
}
|
|
2426
|
+
if ((value.$expr === "resource-attr" || value.$expr === "data-attr") &&
|
|
2427
|
+
(value.type === "elementum_app" || value.type === "elementum_element") &&
|
|
2428
|
+
value.path[0] === "status_field_id") {
|
|
2429
|
+
return labelsFromOptions(blocks.get(`${value.type}.${value.label}`)?.attrs.status_options);
|
|
2430
|
+
}
|
|
2431
|
+
if (value.$expr === "local" && value.name.endsWith("_field_id")) {
|
|
2432
|
+
const ownerAndField = value.name.slice(0, -"_field_id".length);
|
|
2433
|
+
if (ownerAndField.endsWith("_status")) {
|
|
2434
|
+
const owner = ownerAndField.slice(0, -"_status".length);
|
|
2435
|
+
const block = blocks.get(`elementum_app.${owner}`) ?? blocks.get(`elementum_element.${owner}`);
|
|
2436
|
+
return labelsFromOptions(block?.attrs.status_options);
|
|
2437
|
+
}
|
|
2438
|
+
for (const block of blocks.values()) {
|
|
2439
|
+
if (block.type !== "elementum_dropdown_field" && block.type !== "elementum_multiselect_field")
|
|
2440
|
+
continue;
|
|
2441
|
+
if (block.label === ownerAndField)
|
|
2442
|
+
return labelsFromOptions(block.attrs.options);
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
return undefined;
|
|
2446
|
+
}
|
|
2447
|
+
function optionLabelsForDecodedField(field, ctx) {
|
|
2448
|
+
if (!isObject(field) || field.kind !== "field" || typeof field.fieldKey !== "string")
|
|
2449
|
+
return undefined;
|
|
2450
|
+
const ownerHandle = typeof field.appHandle === "string" ? field.appHandle : ctx.appRefName;
|
|
2451
|
+
if (field.fieldKey === "status") {
|
|
2452
|
+
const ownerBlock = ownerHandle === ctx.appRefName
|
|
2453
|
+
? ctx.resourceBlocks.get(`${ctx.ownerScope === "element" ? "elementum_element" : "elementum_app"}.${ctx.appTfLabel}`)
|
|
2454
|
+
: [...ctx.resourceBlocks.values()].find((block) => (block.type === "elementum_app" || block.type === "elementum_element") &&
|
|
2455
|
+
block.label !== undefined &&
|
|
2456
|
+
tfLabelToTsLabel(block.label) === ownerHandle);
|
|
2457
|
+
return labelsFromOptions(ownerBlock?.attrs.status_options);
|
|
2458
|
+
}
|
|
2459
|
+
const labels = new Set();
|
|
2460
|
+
for (const block of ctx.resourceBlocks.values()) {
|
|
2461
|
+
if ((block.type !== "elementum_dropdown_field" && block.type !== "elementum_multiselect_field") || block.label === undefined)
|
|
2462
|
+
continue;
|
|
2463
|
+
if (fieldBagKey(block.label, ctx) !== field.fieldKey)
|
|
2464
|
+
continue;
|
|
2465
|
+
const owned = ownerFromScopedChildLabel(block.label);
|
|
2466
|
+
const ownerTf = owned?.ownerTfLabel ?? ctx.appTfLabel;
|
|
2467
|
+
if (tfLabelToTsLabel(ownerTf) !== ownerHandle)
|
|
2468
|
+
continue;
|
|
2469
|
+
collectOptionLabels(labels, block.attrs.options);
|
|
2470
|
+
}
|
|
2471
|
+
return labels.size > 0 ? labels : undefined;
|
|
2472
|
+
}
|
|
2473
|
+
/**
|
|
2474
|
+
* A filter literal's option id, printed as the label only when the compared
|
|
2475
|
+
* field lists that label. Build then writes the options-by-label local.
|
|
2476
|
+
* Anything else stays the raw id (#2099).
|
|
2477
|
+
*/
|
|
2478
|
+
function filterOptionLabel(value, field, ctx) {
|
|
2479
|
+
if (typeof value !== "string" || !isUuid(value))
|
|
2480
|
+
return undefined;
|
|
2481
|
+
const label = ctx.picklistOptionLabelById?.get(value);
|
|
2482
|
+
if (label === undefined)
|
|
2483
|
+
return undefined;
|
|
2484
|
+
return optionLabelsForDecodedField(field, ctx)?.has(label) === true ? label : undefined;
|
|
2485
|
+
}
|
|
2486
|
+
/** Option ids `filterOptionLabel` will print as labels. The export still holds the id. */
|
|
2487
|
+
export function filterOptionIdsPrintedAsLabels(doc, optionLabelById) {
|
|
2488
|
+
const resolved = new Set();
|
|
2489
|
+
if (optionLabelById === undefined || optionLabelById.size === 0)
|
|
2490
|
+
return resolved;
|
|
2491
|
+
const blocks = new Map();
|
|
2492
|
+
for (const block of doc.blocks) {
|
|
2493
|
+
if (block.kind !== "resource" || block.type === undefined || block.label === undefined)
|
|
2494
|
+
continue;
|
|
2495
|
+
blocks.set(`${block.type}.${block.label}`, block);
|
|
2496
|
+
}
|
|
2497
|
+
const visit = (value) => {
|
|
2498
|
+
if (Array.isArray(value)) {
|
|
2499
|
+
value.forEach((item) => visit(item));
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
if (!isObject(value))
|
|
2503
|
+
return;
|
|
2504
|
+
if (typeof value.type === "string" && (value.type.toLowerCase() === "and" || value.type.toLowerCase() === "or") && Array.isArray(value.children)) {
|
|
2505
|
+
value.children.forEach((child) => visit(child));
|
|
2506
|
+
return;
|
|
2507
|
+
}
|
|
2508
|
+
const fieldId = value.field_id ?? (isObject(value.left_value) ? value.left_value.field_id : undefined);
|
|
2509
|
+
if (fieldId === undefined) {
|
|
2510
|
+
if (Array.isArray(value.children))
|
|
2511
|
+
value.children.forEach((child) => visit(child));
|
|
2512
|
+
return;
|
|
2513
|
+
}
|
|
2514
|
+
const labels = optionLabelsForFieldIdExpr(fieldId, blocks);
|
|
2515
|
+
if (labels === undefined)
|
|
2516
|
+
return;
|
|
2517
|
+
const consider = (literal) => {
|
|
2518
|
+
if (typeof literal !== "string" || !optionLabelById.has(literal))
|
|
2519
|
+
return;
|
|
2520
|
+
const label = optionLabelById.get(literal);
|
|
2521
|
+
if (label !== undefined && labels.has(label))
|
|
2522
|
+
resolved.add(literal);
|
|
2523
|
+
};
|
|
2524
|
+
if (isObject(value.value))
|
|
2525
|
+
consider(value.value.value);
|
|
2526
|
+
if (isObject(value.min))
|
|
2527
|
+
consider(value.min.value);
|
|
2528
|
+
if (isObject(value.max))
|
|
2529
|
+
consider(value.max.value);
|
|
2530
|
+
if (Array.isArray(value.values)) {
|
|
2531
|
+
for (const item of value.values) {
|
|
2532
|
+
if (isObject(item))
|
|
2533
|
+
consider(item.value);
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
};
|
|
2537
|
+
for (const block of blocks.values()) {
|
|
2538
|
+
for (const [attr, attrValue] of Object.entries(block.attrs)) {
|
|
2539
|
+
if (attr === "filter")
|
|
2540
|
+
visit(attrValue);
|
|
2541
|
+
}
|
|
2542
|
+
}
|
|
2543
|
+
return resolved;
|
|
2544
|
+
}
|
|
2394
2545
|
function picklistOptionLabel(value) {
|
|
2395
2546
|
if (value === undefined || !isTfExpr(value))
|
|
2396
2547
|
return undefined;
|
|
@@ -2593,7 +2744,7 @@ function decodeCalculationTaskMustache(taskId, wireName, ctx) {
|
|
|
2593
2744
|
}
|
|
2594
2745
|
}
|
|
2595
2746
|
if (taskBlock?.type === "elementum_api_task") {
|
|
2596
|
-
const apiPath = apiTaskRefAuthoringPath(wireName);
|
|
2747
|
+
const apiPath = apiTaskRefAuthoringPath(wireName, apiResponseTypeAttr(taskBlock));
|
|
2597
2748
|
if (apiPath !== undefined) {
|
|
2598
2749
|
return { kind: "taskRef", task: refKey, path: apiPath };
|
|
2599
2750
|
}
|
|
@@ -2782,6 +2933,7 @@ function workflowOutputTaskIdOrKey(taskId, ctx) {
|
|
|
2782
2933
|
return undefined;
|
|
2783
2934
|
}
|
|
2784
2935
|
function filterReference(value, ctx, role) {
|
|
2936
|
+
assertFilterTaskRefResolves(filterReferenceTaskId(value), ctx);
|
|
2785
2937
|
return typeof value === "string"
|
|
2786
2938
|
? decodeReferenceString(value, ctx) ?? { kind: "unresolved", uuid: value, hint: "filter-reference" }
|
|
2787
2939
|
: decodeFilterReferenceEnvelope(value, ctx, undefined, role)
|
|
@@ -2790,6 +2942,32 @@ function filterReference(value, ctx, role) {
|
|
|
2790
2942
|
?? decodeTemplateForEachRef(value, ctx)
|
|
2791
2943
|
?? decodeValue(value, ctx);
|
|
2792
2944
|
}
|
|
2945
|
+
/** The platform task id a filter reference names: `task.<id>.<name>`, or an envelope's `taskReference.taskId`. */
|
|
2946
|
+
function filterReferenceTaskId(value) {
|
|
2947
|
+
if (typeof value === "string") {
|
|
2948
|
+
const pieces = value.split(".");
|
|
2949
|
+
return pieces[0] === "task" && pieces.length > 2 ? pieces[1] : undefined;
|
|
2950
|
+
}
|
|
2951
|
+
let raw = isTfExpr(value) && value.$expr === "jsonencode" ? value.value : value;
|
|
2952
|
+
while (isObject(raw) && "value" in raw && Object.keys(raw).length === 1)
|
|
2953
|
+
raw = raw.value;
|
|
2954
|
+
if (!isObject(raw) || !isObject(raw.taskReference))
|
|
2955
|
+
return undefined;
|
|
2956
|
+
const taskId = raw.taskReference.taskId;
|
|
2957
|
+
return typeof taskId === "string" ? taskId : undefined;
|
|
2958
|
+
}
|
|
2959
|
+
/**
|
|
2960
|
+
* A filter's task reference must name one of this automation's own tasks.
|
|
2961
|
+
* Returning the raw id let source generation fail later with only the id
|
|
2962
|
+
* (#2054); say what the id is instead, and fail closed (#1974).
|
|
2963
|
+
*/
|
|
2964
|
+
function assertFilterTaskRefResolves(taskId, ctx) {
|
|
2965
|
+
if (taskId === undefined || !isUuid(taskId))
|
|
2966
|
+
return;
|
|
2967
|
+
if (resolveTaskRefKey(taskId, ctx).block !== undefined)
|
|
2968
|
+
return;
|
|
2969
|
+
throw new UnresolvedTaskFilterRefError(taskId, ctx.describeUnresolvedTask?.(taskId) ?? `is not one of this automation's tasks. ${FIX_FILTER_IN_BUILDER}`, ctx.automationId);
|
|
2970
|
+
}
|
|
2793
2971
|
function filterReferenceType(value, fallback, ctx) {
|
|
2794
2972
|
const raw = isTfExpr(value) && value.$expr === "jsonencode" ? value.value : value;
|
|
2795
2973
|
if (!isObject(raw))
|
|
@@ -2894,15 +3072,60 @@ function decodeFilter(value, ctx, fieldScope = "app") {
|
|
|
2894
3072
|
},
|
|
2895
3073
|
reference: (reference, role) => filterReference(reference, ctx, role),
|
|
2896
3074
|
referenceType: (reference, fallback) => filterReferenceType(reference, fallback, ctx),
|
|
2897
|
-
literal: (literal) => picklistOptionLabel(literal) ?? stageFilterName(literal, ctx) ?? literal,
|
|
3075
|
+
literal: (literal, _valueType, field) => picklistOptionLabel(literal) ?? stageFilterName(literal, ctx) ?? filterOptionLabel(literal, field, ctx) ?? literal,
|
|
2898
3076
|
}, fieldScope);
|
|
2899
3077
|
}
|
|
3078
|
+
/**
|
|
3079
|
+
* A datamine trigger's condition (edk#2287). Pull used to drop it, so the next
|
|
3080
|
+
* apply cleared the live condition. It now comes back as source. A condition
|
|
3081
|
+
* that can't be decoded, or that tests anything but a column of the datamine's
|
|
3082
|
+
* own table, is an error rather than a silent drop: `pull automation` stops, and
|
|
3083
|
+
* `pull app` skips the automation with a coverage warning.
|
|
3084
|
+
*/
|
|
3085
|
+
function dataMineCondition(raw, datamineTable, ctx) {
|
|
3086
|
+
const stop = (why) => {
|
|
3087
|
+
throw new EntityTfError(`datamine trigger condition ${why}; this automation was not pulled, rather than pulled without its condition, because the next apply would clear the condition on the platform ` +
|
|
3088
|
+
"(`pull automation` stops here; `pull app` skips the automation with a coverage warning). " +
|
|
3089
|
+
"Fix the trigger condition in the Elementum UI so it tests columns of the datamine's table, then pull again.");
|
|
3090
|
+
};
|
|
3091
|
+
let condition;
|
|
3092
|
+
try {
|
|
3093
|
+
condition = UnresolvedTaskFilterRefError.within("trigger", () => decodeFilter(raw, ctx));
|
|
3094
|
+
}
|
|
3095
|
+
catch (err) {
|
|
3096
|
+
if (err instanceof UnresolvedTaskFilterRefError)
|
|
3097
|
+
throw err;
|
|
3098
|
+
return stop(`can't be decoded (${err instanceof Error ? err.message : String(err)})`);
|
|
3099
|
+
}
|
|
3100
|
+
const visit = (node) => {
|
|
3101
|
+
if (!isObject(node))
|
|
3102
|
+
return;
|
|
3103
|
+
const field = node.field;
|
|
3104
|
+
if (isObject(field)) {
|
|
3105
|
+
if (field.kind === "unresolved")
|
|
3106
|
+
stop(`tests field ${JSON.stringify(field.uuid)}, which is not a column this pull can resolve`);
|
|
3107
|
+
if (field.kind !== "tableColumn")
|
|
3108
|
+
stop(`tests a ${String(field.kind)} reference, not a column of the datamine's table`);
|
|
3109
|
+
if (datamineTable !== undefined && field.tableHandle !== datamineTable) {
|
|
3110
|
+
stop(`tests column ${JSON.stringify(field.name ?? field.columnKey)} of table "${String(field.tableHandle)}", but the datamine reads table "${datamineTable}"`);
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
if (Array.isArray(node.children))
|
|
3114
|
+
node.children.forEach(visit);
|
|
3115
|
+
};
|
|
3116
|
+
visit(condition);
|
|
3117
|
+
return condition;
|
|
3118
|
+
}
|
|
2900
3119
|
function triggerFromBlock(block, ctx) {
|
|
2901
3120
|
const kind = TRIGGER_KINDS[block.type];
|
|
2902
3121
|
if (kind === undefined)
|
|
2903
3122
|
throw new EntityTfError(`unknown trigger resource type "${block.type}"`);
|
|
2904
3123
|
const app = appRef(ctx.appRefName);
|
|
2905
|
-
|
|
3124
|
+
// A datamine trigger's condition decodes in its own case, which fails
|
|
3125
|
+
// closed with a message naming the trigger (edk#2287).
|
|
3126
|
+
const filter = block.attrs.filter !== undefined && kind !== "dataMine"
|
|
3127
|
+
? UnresolvedTaskFilterRefError.within("trigger", () => decodeFilter(block.attrs.filter, ctx))
|
|
3128
|
+
: undefined;
|
|
2906
3129
|
switch (kind) {
|
|
2907
3130
|
case "onDemand": {
|
|
2908
3131
|
const parameters = block.attrs.parameters ?? [];
|
|
@@ -2987,7 +3210,10 @@ function triggerFromBlock(block, ctx) {
|
|
|
2987
3210
|
if (typeof datamine !== "string" && (!isObject(datamine) || datamine.kind !== "datamine")) {
|
|
2988
3211
|
throw new EntityTfError("datamine trigger requires a managed datamine reference or explicit platform id");
|
|
2989
3212
|
}
|
|
2990
|
-
|
|
3213
|
+
const condition = block.attrs.filter !== undefined
|
|
3214
|
+
? dataMineCondition(block.attrs.filter, typeof datamine === "string" || typeof datamine.tableHandle !== "string" ? undefined : datamine.tableHandle, ctx)
|
|
3215
|
+
: undefined;
|
|
3216
|
+
return { kind, datamine: datamine, ...(typeof block.attrs.fire_on_alert === "boolean" ? { fireOnAlert: block.attrs.fire_on_alert } : {}), ...(typeof block.attrs.fire_on_recovery === "boolean" ? { fireOnRecovery: block.attrs.fire_on_recovery } : {}), ...(condition ? { filter: condition } : {}) };
|
|
2991
3217
|
}
|
|
2992
3218
|
case "emailReceived":
|
|
2993
3219
|
if (typeof block.attrs.email_alias_id !== "string")
|
|
@@ -2997,7 +3223,7 @@ function triggerFromBlock(block, ctx) {
|
|
|
2997
3223
|
case "surveyResponseCreate":
|
|
2998
3224
|
if (typeof block.attrs.survey_template_id !== "string")
|
|
2999
3225
|
throw new EntityTfError("survey trigger requires survey_template_id");
|
|
3000
|
-
return { kind, app, survey: block.attrs.survey_template_id };
|
|
3226
|
+
return { kind, app, survey: block.attrs.survey_template_id, ...(filter ? { filter } : {}) };
|
|
3001
3227
|
case "schedule": {
|
|
3002
3228
|
if (typeof block.attrs.frequency !== "string")
|
|
3003
3229
|
throw new EntityTfError("schedule trigger requires frequency");
|
|
@@ -3034,6 +3260,24 @@ function triggerFromBlock(block, ctx) {
|
|
|
3034
3260
|
...(typeof block.attrs.day_of_month === "number" ? { dayOfMonth: block.attrs.day_of_month } : {}),
|
|
3035
3261
|
};
|
|
3036
3262
|
}
|
|
3263
|
+
case "temporal": {
|
|
3264
|
+
const unit = block.attrs.temporal_unit;
|
|
3265
|
+
if (unit !== "MINUTES" && unit !== "HOURS" && unit !== "DAYS") {
|
|
3266
|
+
throw new EntityTfError(`temporal trigger temporal_unit "${String(unit)}" is not MINUTES, HOURS or DAYS`);
|
|
3267
|
+
}
|
|
3268
|
+
if (typeof block.attrs.value !== "number")
|
|
3269
|
+
throw new EntityTfError("temporal trigger requires value");
|
|
3270
|
+
if (block.attrs.aspect_field_id === undefined)
|
|
3271
|
+
throw new EntityTfError("temporal trigger requires aspect_field_id");
|
|
3272
|
+
return {
|
|
3273
|
+
kind,
|
|
3274
|
+
app,
|
|
3275
|
+
field: fieldRef(block.attrs.aspect_field_id, ctx),
|
|
3276
|
+
temporalUnit: unit,
|
|
3277
|
+
value: block.attrs.value,
|
|
3278
|
+
...(filter ? { filter } : {}),
|
|
3279
|
+
};
|
|
3280
|
+
}
|
|
3037
3281
|
default: throw new EntityTfError(`trigger "${kind}" is outside the Terraform contract`);
|
|
3038
3282
|
}
|
|
3039
3283
|
}
|
|
@@ -3043,7 +3287,8 @@ function taskArgs(block, factory, ctx, taskDiagnostics) {
|
|
|
3043
3287
|
if (attr === "parent" || attr === "name" || attr === "depends_on")
|
|
3044
3288
|
continue;
|
|
3045
3289
|
if (attr === "filter") {
|
|
3046
|
-
|
|
3290
|
+
const where = `task ${JSON.stringify(typeof block.attrs.name === "string" ? block.attrs.name : block.label)} (${factory})`;
|
|
3291
|
+
args.filter = UnresolvedTaskFilterRefError.within(where, () => decodeFilter(value, ctx, FILTER_FIELD_SCOPE_BY_FACTORY[factory] ?? "app"));
|
|
3047
3292
|
continue;
|
|
3048
3293
|
}
|
|
3049
3294
|
if (attr === "fields" && (factory === "createRecord" || factory === "updateField" || factory === "bulkUpdateFields")) {
|
|
@@ -3298,13 +3543,18 @@ function taskArgs(block, factory, ctx, taskDiagnostics) {
|
|
|
3298
3543
|
// option requires a `FileReaderCatalogRef` object, failing tsc on the
|
|
3299
3544
|
// generated file (edk#483). Route it through the same `unresolved`
|
|
3300
3545
|
// escape hatch already used for other unreconstructable references
|
|
3301
|
-
// (`"<uuid>" as any /* TODO: ... */`) instead.
|
|
3546
|
+
// (`"<uuid>" as any /* TODO: ... */`) instead. The one exception is
|
|
3547
|
+
// another app's reader that workspace state binds to this exact id
|
|
3548
|
+
// (edk#2007).
|
|
3302
3549
|
if (attr === "file_reader_id" && factory === "documentModel") {
|
|
3303
3550
|
const decoded = decodeValue(value, ctx);
|
|
3551
|
+
const foreign = typeof value === "string" ? ctx.foreignFileReaderRefsById?.get(value) : undefined;
|
|
3304
3552
|
args.documentModel =
|
|
3305
3553
|
typeof decoded === "object" && decoded !== null && decoded.kind === "documentModel"
|
|
3306
3554
|
? decoded
|
|
3307
|
-
:
|
|
3555
|
+
: foreign !== undefined
|
|
3556
|
+
? { kind: "documentModel", appHandle: foreign.ownerRefName, documentModelKey: foreign.refName }
|
|
3557
|
+
: { kind: "unresolved", uuid: typeof value === "string" ? value : JSON.stringify(value), hint: "file reader" };
|
|
3308
3558
|
continue;
|
|
3309
3559
|
}
|
|
3310
3560
|
if (attr === "calculations" && factory === "calculation") {
|
|
@@ -3361,7 +3611,9 @@ function taskArgs(block, factory, ctx, taskDiagnostics) {
|
|
|
3361
3611
|
...(value.description_field_id !== undefined
|
|
3362
3612
|
? { descriptionField: fieldRef(value.description_field_id, ctx) }
|
|
3363
3613
|
: {}),
|
|
3364
|
-
...(value.filter !== undefined ? {
|
|
3614
|
+
...(value.filter !== undefined ? {
|
|
3615
|
+
filter: UnresolvedTaskFilterRefError.within(`task ${JSON.stringify(typeof block.attrs.name === "string" ? block.attrs.name : block.label)} (${factory}) dynamic category source`, () => decodeFilter(value.filter, ctx)),
|
|
3616
|
+
} : {}),
|
|
3365
3617
|
...(typeof value.limit === "number" ? { limit: value.limit } : {}),
|
|
3366
3618
|
};
|
|
3367
3619
|
continue;
|
|
@@ -3986,6 +4238,38 @@ export class UnsupportedMultiTriggerError extends EntityTfError {
|
|
|
3986
4238
|
this.triggerCount = triggerCount;
|
|
3987
4239
|
}
|
|
3988
4240
|
}
|
|
4241
|
+
/**
|
|
4242
|
+
* A filter names a task id that is not one of its automation's tasks (#2054).
|
|
4243
|
+
* Pull fails on it rather than skip the automation: the message says what the
|
|
4244
|
+
* id points to so it can be fixed in the platform's automation builder.
|
|
4245
|
+
*/
|
|
4246
|
+
export class UnresolvedTaskFilterRefError extends EntityTfError {
|
|
4247
|
+
taskId;
|
|
4248
|
+
target;
|
|
4249
|
+
automationId;
|
|
4250
|
+
where;
|
|
4251
|
+
constructor(taskId, target, automationId, where) {
|
|
4252
|
+
super(`${where ?? "a filter"}${automationId !== undefined ? ` in automation ${automationId}` : ""} ` +
|
|
4253
|
+
`references task ${taskId}, which ${target}.`);
|
|
4254
|
+
this.name = "UnresolvedTaskFilterRefError";
|
|
4255
|
+
this.taskId = taskId;
|
|
4256
|
+
this.target = target;
|
|
4257
|
+
this.automationId = automationId;
|
|
4258
|
+
this.where = where;
|
|
4259
|
+
}
|
|
4260
|
+
/** Run `decode`, naming `where` (the task, branch or trigger whose filter it is) on this error. */
|
|
4261
|
+
static within(where, decode) {
|
|
4262
|
+
try {
|
|
4263
|
+
return decode();
|
|
4264
|
+
}
|
|
4265
|
+
catch (err) {
|
|
4266
|
+
if (err instanceof UnresolvedTaskFilterRefError && err.where === undefined) {
|
|
4267
|
+
throw new UnresolvedTaskFilterRefError(err.taskId, err.target, err.automationId, `${where}'s filter`);
|
|
4268
|
+
}
|
|
4269
|
+
throw err;
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4272
|
+
}
|
|
3989
4273
|
/**
|
|
3990
4274
|
* A bare service_account_id belongs to an app this export does not contain.
|
|
3991
4275
|
* Pull cannot print a serviceAccountRef until that app is in the workspace,
|
|
@@ -4012,8 +4296,101 @@ export class ForEachItemOutsideLoopError extends EntityTfError {
|
|
|
4012
4296
|
this.name = "ForEachItemOutsideLoopError";
|
|
4013
4297
|
}
|
|
4014
4298
|
}
|
|
4299
|
+
const UNMANAGED_TASK_REFERENCE_TYPE = "elementum_unmanaged_task_reference";
|
|
4300
|
+
const FIX_FILTER_IN_BUILDER = "Fix the filter's reference in the platform's automation builder, then pull again";
|
|
4301
|
+
/**
|
|
4302
|
+
* What a task id that none of this automation's tasks carries points to
|
|
4303
|
+
* (#2054), worded to follow "references task <id>, which". The export is the
|
|
4304
|
+
* whole app, so the id can be another automation's task (a cloned filter that
|
|
4305
|
+
* still points at the source automation), a task of this draft that pull did
|
|
4306
|
+
* not place in the automation, a task type EDK cannot export, or nothing.
|
|
4307
|
+
*/
|
|
4308
|
+
function describeUnresolvedTask(taskId, doc, automationLabel, taskByAddress, resourceBlocks, dataBlocks, resourceImportIds) {
|
|
4309
|
+
// Task import ids are `<workflow_id>:<task_id>`.
|
|
4310
|
+
const workflowByTaskAddress = new Map();
|
|
4311
|
+
let taskAddress;
|
|
4312
|
+
for (const block of doc.blocks) {
|
|
4313
|
+
if (block.kind !== "import" || typeof block.attrs.id !== "string")
|
|
4314
|
+
continue;
|
|
4315
|
+
const target = resourceRef(block.attrs.to);
|
|
4316
|
+
if (target === undefined || !ALL_AUTOMATION_TASK_TYPE_SET.has(target.type))
|
|
4317
|
+
continue;
|
|
4318
|
+
const [workflowId, id] = block.attrs.id.split(":");
|
|
4319
|
+
const address = `${target.type}.${target.label}`;
|
|
4320
|
+
if (workflowId !== undefined && id !== undefined)
|
|
4321
|
+
workflowByTaskAddress.set(address, workflowId);
|
|
4322
|
+
if (id === taskId)
|
|
4323
|
+
taskAddress = address;
|
|
4324
|
+
}
|
|
4325
|
+
const automationByImportId = new Map();
|
|
4326
|
+
for (const [address, id] of resourceImportIds) {
|
|
4327
|
+
if (address.startsWith(`${AUTOMATION_RESOURCE_TYPE}.`))
|
|
4328
|
+
automationByImportId.set(id, address.slice(AUTOMATION_RESOURCE_TYPE.length + 1));
|
|
4329
|
+
}
|
|
4330
|
+
const describeAutomation = (label) => {
|
|
4331
|
+
const name = resourceBlocks.get(`${AUTOMATION_RESOURCE_TYPE}.${label}`)?.attrs.name;
|
|
4332
|
+
const id = resourceImportIds.get(`${AUTOMATION_RESOURCE_TYPE}.${label}`);
|
|
4333
|
+
return `automation ${JSON.stringify(typeof name === "string" && name !== "" ? name : label)}${id !== undefined ? ` (${id})` : ""}`;
|
|
4334
|
+
};
|
|
4335
|
+
// Walk parents up to a trigger (or a #785 placeholder, which names its automation).
|
|
4336
|
+
const owningAutomationLabel = (start) => {
|
|
4337
|
+
const seen = new Set();
|
|
4338
|
+
for (let cursor = start; cursor !== undefined && !seen.has(cursor);) {
|
|
4339
|
+
seen.add(cursor);
|
|
4340
|
+
const data = cursor.startsWith(`${UNMANAGED_TASK_REFERENCE_TYPE}.`) ? dataBlocks.get(cursor) : undefined;
|
|
4341
|
+
if (data !== undefined) {
|
|
4342
|
+
return typeof data.attrs.automation_id === "string" ? automationByImportId.get(data.attrs.automation_id) : undefined;
|
|
4343
|
+
}
|
|
4344
|
+
const block = resourceBlocks.get(cursor);
|
|
4345
|
+
if (block === undefined)
|
|
4346
|
+
return undefined;
|
|
4347
|
+
if (AUTOMATION_TRIGGER_TYPE_SET.has(block.type ?? "")) {
|
|
4348
|
+
const automation = resourceRef(block.attrs.automation);
|
|
4349
|
+
return automation?.type === AUTOMATION_RESOURCE_TYPE ? automation.label : undefined;
|
|
4350
|
+
}
|
|
4351
|
+
const unmanaged = unmanagedTaskRef(block.attrs.parent);
|
|
4352
|
+
const parent = resourceRef(block.attrs.parent) ?? resourceRef(block.attrs.switch_task) ?? resourceRef(block.attrs.fork_join_task);
|
|
4353
|
+
cursor = unmanaged !== undefined
|
|
4354
|
+
? `${UNMANAGED_TASK_REFERENCE_TYPE}.${unmanaged.label}`
|
|
4355
|
+
: parent !== undefined ? `${parent.type}.${parent.label}` : undefined;
|
|
4356
|
+
}
|
|
4357
|
+
return undefined;
|
|
4358
|
+
};
|
|
4359
|
+
const isDraft = !doc.blocks.some((block) => block.kind === "resource" && block.type === WORKFLOW_PUBLISH_RESOURCE_TYPE && references(block.attrs.automation, AUTOMATION_RESOURCE_TYPE, automationLabel));
|
|
4360
|
+
if (taskAddress !== undefined) {
|
|
4361
|
+
const block = resourceBlocks.get(taskAddress);
|
|
4362
|
+
const name = typeof block?.attrs.name === "string" ? ` ${JSON.stringify(block.attrs.name)}` : "";
|
|
4363
|
+
const ownWorkflows = new Set([...taskByAddress.keys()].map((address) => workflowByTaskAddress.get(address)).filter((id) => id !== undefined));
|
|
4364
|
+
const workflowId = workflowByTaskAddress.get(taskAddress);
|
|
4365
|
+
// A task the walk cannot place still shares its workflow with its automation's other tasks.
|
|
4366
|
+
const sibling = [...workflowByTaskAddress].find(([address, id]) => id === workflowId && address !== taskAddress && owningAutomationLabel(address) !== undefined);
|
|
4367
|
+
const owner = owningAutomationLabel(taskAddress) ?? (sibling !== undefined ? owningAutomationLabel(sibling[0]) : undefined);
|
|
4368
|
+
if (owner !== undefined && owner !== automationLabel) {
|
|
4369
|
+
return `is task${name} of ${describeAutomation(owner)}, not of this automation: a filter copied from another automation ` +
|
|
4370
|
+
"still points at that automation's task. In the platform's automation builder, point the filter at a task of this automation, then pull again";
|
|
4371
|
+
}
|
|
4372
|
+
// Its parents lead back to this automation (a #785 placeholder names it),
|
|
4373
|
+
// or it shares a workflow with a task pull did place: either way it is
|
|
4374
|
+
// this automation's own task that pull left out, an EDK bug.
|
|
4375
|
+
if (owner === automationLabel || (workflowId !== undefined && ownWorkflows.has(workflowId))) {
|
|
4376
|
+
return `is task${name} of this automation${isDraft ? "'s draft" : ""}, but pull did not place it in the automation ` +
|
|
4377
|
+
"(it follows a task EDK cannot export, or nothing connects it to the trigger). Report this as an EDK bug";
|
|
4378
|
+
}
|
|
4379
|
+
return `is task${name} of workflow ${workflowId ?? "(unknown)"}, which no automation in this export owns. ${FIX_FILTER_IN_BUILDER}; if the reference is right, report this as an EDK bug`;
|
|
4380
|
+
}
|
|
4381
|
+
for (const block of dataBlocks.values()) {
|
|
4382
|
+
if (block.type !== UNMANAGED_TASK_REFERENCE_TYPE || block.attrs.id !== taskId)
|
|
4383
|
+
continue;
|
|
4384
|
+
const name = typeof block.attrs.name === "string" ? ` ${JSON.stringify(block.attrs.name)}` : "";
|
|
4385
|
+
const type = typeof block.attrs.task_type === "string" && block.attrs.task_type !== "" ? block.attrs.task_type : "unknown";
|
|
4386
|
+
return `is task${name} of type ${type}, which EDK cannot export yet, so source cannot reference it. ` +
|
|
4387
|
+
"In the platform's automation builder, point the filter at another task, then pull again";
|
|
4388
|
+
}
|
|
4389
|
+
return "is not a task of this automation or of any other automation in this export: it was deleted or replaced in the draft " +
|
|
4390
|
+
`(the platform checks references only when an automation is published), or it is a task type EDK cannot export. ${FIX_FILTER_IN_BUILDER}`;
|
|
4391
|
+
}
|
|
4015
4392
|
/** Extract one app- or element-owned automation graph from an ei export. */
|
|
4016
|
-
function automationFromTfDocument(doc, automationLabel, appRefName, foreignFieldRefsById, foreignFieldRefsByDataAddress, foreignTableRefsById, picklistOptionLabelById, fieldNamesByOwnerRefName, foreignAppRefNames, foreignElementRefNames, procedureKeysByDiscriminator, foreignTaskRefNames, groupKeysByName, serviceAccountsById) {
|
|
4393
|
+
function automationFromTfDocument(doc, automationLabel, appRefName, foreignFieldRefsById, foreignFieldRefsByDataAddress, foreignTableRefsById, picklistOptionLabelById, fieldNamesByOwnerRefName, foreignAppRefNames, foreignElementRefNames, procedureKeysByDiscriminator, foreignTaskRefNames, groupKeysByName, serviceAccountsById, foreignFileReaderRefsById) {
|
|
4017
4394
|
const automation = doc.blocks.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE && block.label === automationLabel);
|
|
4018
4395
|
if (automation === undefined)
|
|
4019
4396
|
throw new EntityTfError(`automation resource "${automationLabel}" not found`);
|
|
@@ -4148,12 +4525,50 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4148
4525
|
const appTfLabel = app.label;
|
|
4149
4526
|
const dataBlocks = new Map(doc.blocks.filter((block) => block.kind === "data" && block.type && block.label).map((block) => [`${block.type}.${block.label}`, block]));
|
|
4150
4527
|
const taskByAddress = new Map(tasks.map((block) => [`${block.type}.${block.label}`, { block, refKey: taskRefKey(block, automationLabel, appTfLabel) }]));
|
|
4151
|
-
const
|
|
4528
|
+
const taskAddressAliases = [...taskByAddress.entries()].flatMap(([from, { block, refKey }]) => {
|
|
4152
4529
|
if (soleVariableName(block) === undefined)
|
|
4153
4530
|
return [];
|
|
4154
4531
|
const to = `${block.type}.${taskTfLabel(automationLabel, refKey)}`;
|
|
4155
4532
|
return to === from ? [] : [{ from, to }];
|
|
4156
4533
|
});
|
|
4534
|
+
// edk#2010: ei's branch resource label follows the branch's own live
|
|
4535
|
+
// display text, which can diverge from the canonical authored parent
|
|
4536
|
+
// label (e.g. a parent switch/forkJoin task whose refKey round-trips
|
|
4537
|
+
// through the camelCase bijection, confirmed live on Offering Versions
|
|
4538
|
+
// 7a: `..._switch_case.offeringver_7a_...` vs the rebuilt
|
|
4539
|
+
// `..._switch_case.offeringver__7a_...`). to-tf.ts rebuilds every branch
|
|
4540
|
+
// label as `${parentTfLabel}_${sanitizeName(child.label ?? child.defaultLabel ?? fallbackLabel)}`
|
|
4541
|
+
// (to-tf.ts's emitTasks, switch/forkJoin branch). `child.label` there is
|
|
4542
|
+
// `null` on a default case, so `??` always skips to the real display text
|
|
4543
|
+
// (defaultLabel, carrying the SAME raw string as a non-default `label`)
|
|
4544
|
+
// and only reaches the fixed fallback ("default"/"case") when ei wrote no
|
|
4545
|
+
// label at all - collapsing to one audited formula below:
|
|
4546
|
+
// `sanitizeName(rawLabel ?? (isDefault ? "default" : "case"))`.
|
|
4547
|
+
const branchAddressAliases = ownedBranches.flatMap((branch) => {
|
|
4548
|
+
const parentAttr = branch.type === "elementum_switch_case" ? "switch_task" : "fork_join_task";
|
|
4549
|
+
const parentRef = resourceRef(branch.attrs[parentAttr]);
|
|
4550
|
+
const parentEntry = parentRef !== undefined ? taskByAddress.get(`${parentRef.type}.${parentRef.label}`) : undefined;
|
|
4551
|
+
if (parentEntry === undefined)
|
|
4552
|
+
return []; // unresolved parent is already reported via the task walk above
|
|
4553
|
+
const parentTfLabel = taskTfLabel(automationLabel, parentEntry.refKey);
|
|
4554
|
+
// Mirrors to-tf.ts's `isDefault = wireType === "switch" && (child.isDefault === true || child.label === null)`:
|
|
4555
|
+
// a fork_join_branch is never a default; a switch_case is default exactly
|
|
4556
|
+
// when it carries one of the two live wire shapes defaultSwitchShape detects.
|
|
4557
|
+
const isDefault = branch.type === "elementum_switch_case" && defaultSwitchShape(branch) !== undefined;
|
|
4558
|
+
const rawLabel = typeof branch.attrs.label === "string" ? branch.attrs.label : undefined;
|
|
4559
|
+
const suffix = sanitizeName(rawLabel ?? (isDefault ? "default" : "case"));
|
|
4560
|
+
const from = `${branch.type}.${branch.label}`;
|
|
4561
|
+
const to = `${branch.type}.${parentTfLabel}_${suffix}`;
|
|
4562
|
+
return to === from ? [] : [{ from, to }];
|
|
4563
|
+
});
|
|
4564
|
+
// A genuine suffix collision between two siblings (to-tf.ts's usedSuffixes
|
|
4565
|
+
// guard - e.g. an unlabeled case next to one explicitly labeled "Case")
|
|
4566
|
+
// would make the authored source unbuildable either way, so there is no
|
|
4567
|
+
// single correct target to prefer; reconcileAdoptionAddressAliases
|
|
4568
|
+
// (adopt.ts) already refuses two aliases that claim the same target
|
|
4569
|
+
// address, naming both "from" addresses, so that case fails loudly here
|
|
4570
|
+
// instead of silently importing the wrong state.
|
|
4571
|
+
const adoptionAddressAliases = [...taskAddressAliases, ...branchAddressAliases];
|
|
4157
4572
|
const taskTargetOwnerRefNameByAddress = new Map();
|
|
4158
4573
|
const taskTargetOwnerKindByAddress = new Map();
|
|
4159
4574
|
for (const [address, { block }] of taskByAddress) {
|
|
@@ -4212,6 +4627,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4212
4627
|
...(foreignFieldRefsById !== undefined && { foreignFieldRefsById }),
|
|
4213
4628
|
...(foreignFieldRefsByDataAddress !== undefined && { foreignFieldRefsByDataAddress }),
|
|
4214
4629
|
...(foreignTableRefsById !== undefined && { foreignTableRefsById }),
|
|
4630
|
+
...(foreignFileReaderRefsById !== undefined && { foreignFileReaderRefsById }),
|
|
4215
4631
|
...(picklistOptionLabelById !== undefined && { picklistOptionLabelById }),
|
|
4216
4632
|
...(fieldNamesByOwnerRefName !== undefined && { fieldNamesByOwnerRefName }),
|
|
4217
4633
|
...(taskTargetOwnerRefNameByAddress.size > 0 && { taskTargetOwnerRefNameByAddress }),
|
|
@@ -4222,6 +4638,10 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4222
4638
|
...(procedureKeysByDiscriminator !== undefined && { procedureKeysByDiscriminator }),
|
|
4223
4639
|
...(groupKeysByName !== undefined && { groupKeysByName }),
|
|
4224
4640
|
stringifiedValueReferences,
|
|
4641
|
+
...(resourceImportIds.has(`${AUTOMATION_RESOURCE_TYPE}.${automationLabel}`) && {
|
|
4642
|
+
automationId: resourceImportIds.get(`${AUTOMATION_RESOURCE_TYPE}.${automationLabel}`),
|
|
4643
|
+
}),
|
|
4644
|
+
describeUnresolvedTask: (taskId) => describeUnresolvedTask(taskId, doc, automationLabel, taskByAddress, resourceBlocks, dataBlocks, resourceImportIds),
|
|
4225
4645
|
};
|
|
4226
4646
|
let serviceAccountName;
|
|
4227
4647
|
const serviceAccountValue = automation.attrs.service_account_id;
|
|
@@ -4340,7 +4760,9 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4340
4760
|
// unmarked default, so leaving this unset there keeps printed
|
|
4341
4761
|
// output terse and matches a freshly-authored default branch.
|
|
4342
4762
|
...(shape === "explicitTrueFilter" ? { defaultFilterMode: shape } : {}),
|
|
4343
|
-
...(!isDefault && branch.attrs.filter !== undefined ? {
|
|
4763
|
+
...(!isDefault && branch.attrs.filter !== undefined ? {
|
|
4764
|
+
filter: UnresolvedTaskFilterRefError.within(`task ${JSON.stringify(typeof block.attrs.name === "string" ? block.attrs.name : block.label)} (${factory}) branch ${JSON.stringify(rawLabel ?? branch.label)}`, () => decodeFilter(branch.attrs.filter, ctx)),
|
|
4765
|
+
} : {}),
|
|
4344
4766
|
tasks: buildTasks(`${branch.type}.${branch.label}`),
|
|
4345
4767
|
};
|
|
4346
4768
|
});
|
|
@@ -4451,7 +4873,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4451
4873
|
...(stringifiedValueReferences.unresolved ? { stringifiedValueReferences: true } : {}),
|
|
4452
4874
|
};
|
|
4453
4875
|
}
|
|
4454
|
-
export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth) {
|
|
4876
|
+
export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth) {
|
|
4455
4877
|
if (Array.isArray(first)) {
|
|
4456
4878
|
const ctx = second;
|
|
4457
4879
|
const automationBlock = first.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE);
|
|
@@ -4460,18 +4882,18 @@ export function automationFromTf(first, second, third, fourth, fifth, sixth, sev
|
|
|
4460
4882
|
throw new EntityTfError(`automation graph has no ${AUTOMATION_RESOURCE_TYPE} resource, so its resources (${addresses.join(", ") || "none"}) cannot be pulled`);
|
|
4461
4883
|
}
|
|
4462
4884
|
try {
|
|
4463
|
-
const result = automationFromTfDocument({ blocks: [...first] }, automationBlock.label, ctx.ownerHandle, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator, ctx.foreignTaskRefNames, ctx.groupKeysByName, ctx.serviceAccountsById);
|
|
4885
|
+
const result = automationFromTfDocument({ blocks: [...first] }, automationBlock.label, ctx.ownerHandle, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator, ctx.foreignTaskRefNames, ctx.groupKeysByName, ctx.serviceAccountsById, ctx.foreignFileReaderRefsById);
|
|
4464
4886
|
if (result.diagnostics)
|
|
4465
4887
|
ctx.diagnostics.push(...result.diagnostics);
|
|
4466
4888
|
return { automation: result.ast };
|
|
4467
4889
|
}
|
|
4468
4890
|
catch (err) {
|
|
4469
|
-
if (err instanceof UnsupportedMultiTriggerError)
|
|
4891
|
+
if (err instanceof UnsupportedMultiTriggerError || err instanceof UnresolvedTaskFilterRefError)
|
|
4470
4892
|
throw err;
|
|
4471
4893
|
const message = err instanceof Error ? err.message : String(err);
|
|
4472
4894
|
ctx.diagnostics.push(message);
|
|
4473
4895
|
return { skippedReason: message };
|
|
4474
4896
|
}
|
|
4475
4897
|
}
|
|
4476
|
-
return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth);
|
|
4898
|
+
return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth);
|
|
4477
4899
|
}
|