@elementumai/edk 0.9.19 → 0.10.1
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 +159 -7
- package/dist-sdk/src/catalog/factories.d.ts +33 -2
- package/dist-sdk/src/catalog/factories.js +40 -1
- package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
- package/dist-sdk/src/catalog/from-authoring.js +34 -9
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +2 -2
- package/dist-sdk/src/catalog/render.js +6 -6
- package/dist-sdk/src/catalog/token.js +11 -0
- package/dist-sdk/src/catalog/types.d.ts +40 -1
- package/dist-sdk/src/catalog/types.js +12 -0
- package/dist-sdk/src/core/triggers/on-demand.d.ts +40 -4
- package/dist-sdk/src/core/triggers/on-demand.js +17 -2
- package/dist-sdk/src/core/types/app.d.ts +2 -2
- package/dist-sdk/src/engine/build/context.d.ts +1 -1
- package/dist-sdk/src/engine/coverage-gaps.d.ts +86 -0
- package/dist-sdk/src/engine/coverage-gaps.js +156 -0
- package/dist-sdk/src/engine/ei/run.d.ts +169 -0
- package/dist-sdk/src/engine/ei/run.js +1219 -0
- package/dist-sdk/src/engine/logging.d.ts +17 -0
- package/dist-sdk/src/engine/logging.js +18 -0
- package/dist-sdk/src/engine/pull/catalog-ref.d.ts +16 -0
- package/dist-sdk/src/engine/pull/catalog-ref.js +24 -0
- package/dist-sdk/src/engine/pull/context.d.ts +68 -6
- package/dist-sdk/src/engine/pull/context.js +40 -1
- package/dist-sdk/src/engine/pull/procedure-refs.d.ts +8 -0
- package/dist-sdk/src/engine/pull/procedure-refs.js +28 -0
- package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
- package/dist-sdk/src/engine/pull/ref-only.js +10 -7
- package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
- package/dist-sdk/src/engine/pull/result-output.js +113 -3
- package/dist-sdk/src/engine/tf/expr.js +1 -1
- package/dist-sdk/src/engine/tf/index.d.ts +2 -2
- package/dist-sdk/src/engine/tf/index.js +1 -1
- package/dist-sdk/src/engine/tf/labels.d.ts +28 -5
- package/dist-sdk/src/engine/tf/labels.js +54 -3
- package/dist-sdk/src/engine/tf/model.d.ts +22 -1
- package/dist-sdk/src/engine/tf/parse.js +93 -4
- package/dist-sdk/src/engine/tf/render.d.ts +4 -2
- package/dist-sdk/src/engine/tf/render.js +41 -7
- package/dist-sdk/src/engine/validation.d.ts +44 -0
- package/dist-sdk/src/engine/validation.js +95 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +38 -1
- package/dist-sdk/src/entities/access-policy/principal.d.ts +2 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
- package/dist-sdk/src/entities/agent/build.d.ts +4 -16
- package/dist-sdk/src/entities/agent/build.js +40 -5
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +46 -21
- package/dist-sdk/src/entities/agent/from-tf.js +11 -3
- package/dist-sdk/src/entities/agent/module.js +2 -0
- package/dist-sdk/src/entities/agent/to-tf.js +20 -6
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +10 -1
- package/dist-sdk/src/entities/agent-tool/from-tf.js +18 -6
- package/dist-sdk/src/entities/agent-tool/module.js +3 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
- package/dist-sdk/src/entities/app/auto-share.d.ts +38 -0
- package/dist-sdk/src/entities/app/auto-share.js +49 -0
- package/dist-sdk/src/entities/app/build.d.ts +105 -22
- package/dist-sdk/src/entities/app/build.js +107 -10
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
- package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
- package/dist-sdk/src/entities/app/from-tf.js +11 -2
- package/dist-sdk/src/entities/app/index.d.ts +7 -6
- package/dist-sdk/src/entities/app/index.js +2 -8
- package/dist-sdk/src/entities/app/module.js +5 -2
- package/dist-sdk/src/entities/app/to-tf.d.ts +6 -0
- package/dist-sdk/src/entities/app/to-tf.js +40 -13
- package/dist-sdk/src/entities/automation/build.d.ts +56 -6
- package/dist-sdk/src/entities/automation/build.js +230 -26
- package/dist-sdk/src/entities/automation/calculation-expression.d.ts +7 -7
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +41 -5
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +470 -58
- package/dist-sdk/src/entities/automation/from-tf.d.ts +37 -8
- package/dist-sdk/src/entities/automation/from-tf.js +791 -131
- package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
- package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
- package/dist-sdk/src/entities/automation/index.d.ts +2 -2
- package/dist-sdk/src/entities/automation/index.js +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +3 -0
- package/dist-sdk/src/entities/automation/module.js +107 -15
- package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
- package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +20 -0
- package/dist-sdk/src/entities/automation/script-code.js +109 -5
- package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +39 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +85 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +116 -22
- package/dist-sdk/src/entities/automation/tasks.js +86 -24
- package/dist-sdk/src/entities/automation/to-tf.d.ts +24 -3
- package/dist-sdk/src/entities/automation/to-tf.js +1082 -132
- package/dist-sdk/src/entities/automation/triggers.d.ts +12 -6
- package/dist-sdk/src/entities/automation/triggers.js +4 -0
- package/dist-sdk/src/entities/automation/types.d.ts +9 -0
- package/dist-sdk/src/entities/automation/types.js +19 -0
- package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +1 -1
- package/dist-sdk/src/entities/automation/value-ref-tf.js +1 -1
- package/dist-sdk/src/entities/chart/from-tf.js +9 -1
- package/dist-sdk/src/entities/chart/to-tf.js +10 -3
- package/dist-sdk/src/entities/data-lookup/module.js +2 -0
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -5
- package/dist-sdk/src/entities/element/build.d.ts +28 -13
- package/dist-sdk/src/entities/element/build.js +5 -1
- package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
- package/dist-sdk/src/entities/element/from-tf.js +62 -1
- package/dist-sdk/src/entities/element/index.d.ts +5 -3
- package/dist-sdk/src/entities/element/index.js +1 -0
- package/dist-sdk/src/entities/element/module.js +9 -3
- package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
- package/dist-sdk/src/entities/element/to-tf.js +16 -16
- package/dist-sdk/src/entities/field/build.d.ts +17 -3
- package/dist-sdk/src/entities/field/build.js +3 -0
- package/dist-sdk/src/entities/field/calc.d.ts +7 -7
- package/dist-sdk/src/entities/field/from-tf.d.ts +5 -4
- package/dist-sdk/src/entities/field/from-tf.js +244 -49
- package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
- package/dist-sdk/src/entities/field/media-types.js +30 -0
- package/dist-sdk/src/entities/field/module.js +2 -0
- package/dist-sdk/src/entities/field/options.js +6 -1
- package/dist-sdk/src/entities/field/to-tf.d.ts +26 -5
- package/dist-sdk/src/entities/field/to-tf.js +137 -15
- package/dist-sdk/src/entities/field/types.d.ts +2 -0
- package/dist-sdk/src/entities/field/types.js +27 -0
- package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
- package/dist-sdk/src/entities/file-reader/module.js +1 -0
- package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
- package/dist-sdk/src/entities/file-reader/types.js +1 -1
- package/dist-sdk/src/entities/portal/build.d.ts +26 -0
- package/dist-sdk/src/entities/portal/build.js +37 -0
- package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
- package/dist-sdk/src/entities/portal/from-tf.js +75 -0
- package/dist-sdk/src/entities/portal/index.d.ts +1 -0
- package/dist-sdk/src/entities/portal/index.js +1 -0
- package/dist-sdk/src/entities/portal/module.d.ts +3 -0
- package/dist-sdk/src/entities/portal/module.js +28 -0
- package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
- package/dist-sdk/src/entities/portal/to-tf.js +73 -0
- package/dist-sdk/src/entities/portal/types.d.ts +1 -0
- package/dist-sdk/src/entities/portal/types.js +1 -0
- package/dist-sdk/src/entities/relationship/module.js +2 -0
- package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
- package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
- package/dist-sdk/src/entities/role/from-tf.js +3 -3
- package/dist-sdk/src/entities/role/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/role/to-tf.js +12 -4
- package/dist-sdk/src/entities/search-table/module.js +1 -0
- package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
- package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
- package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
- package/dist-sdk/src/entities/service-account/from-tf.js +20 -8
- package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
- package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
- package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
- package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
- package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +16 -0
- package/dist-sdk/src/entities/service-account/workspace-owner.js +22 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +23 -1
- package/dist-sdk/src/entities/shared/filters/ast.js +2 -0
- package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
- package/dist-sdk/src/entities/shared/filters/index.js +19 -4
- package/dist-sdk/src/entities/shared/filters/print.js +24 -3
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +7 -0
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +46 -7
- package/dist-sdk/src/entities/shared/filters/types.d.ts +15 -2
- package/dist-sdk/src/entities/shared/ref.d.ts +5 -7
- package/dist-sdk/src/entities/shared/ref.js +5 -7
- package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +9 -0
- package/dist-sdk/src/entities/shared/tool-field-ref.js +35 -2
- package/dist-sdk/src/entities/shared/types/field-types.d.ts +20 -5
- package/dist-sdk/src/entities/shared/types/field-types.js +8 -0
- package/dist-sdk/src/entities/skill/access-policy.js +3 -3
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +14 -6
- package/dist-sdk/src/entities/skill/from-tf.js +70 -15
- package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
- package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
- package/dist-sdk/src/entities/skill/module.js +2 -0
- package/dist-sdk/src/entities/skill/to-tf.js +14 -4
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.js +49 -10
- package/dist-sdk/src/entities/skill-tool/module.js +3 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -8
- package/dist-sdk/src/entities/skill-tool/to-tf.js +49 -14
- package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
- package/dist-sdk/src/entities/table/catalog.js +66 -0
- package/dist-sdk/src/entities/table/module.js +2 -1
- package/dist-sdk/src/entities/table/to-tf.js +2 -2
- package/dist-sdk/src/entities/task/build.d.ts +8 -0
- package/dist-sdk/src/entities/task/build.js +10 -1
- package/dist-sdk/src/entities/task/from-tf.d.ts +4 -2
- package/dist-sdk/src/entities/task/from-tf.js +7 -2
- package/dist-sdk/src/entities/task/module.js +2 -2
- package/dist-sdk/src/entities/task/to-tf.d.ts +8 -4
- package/dist-sdk/src/entities/task/to-tf.js +28 -1
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
- package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
- package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
- package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
- package/dist-sdk/src/entities/view/from-tf.js +133 -13
- package/dist-sdk/src/entities/view/module.js +30 -3
- package/dist-sdk/src/entities/view/to-tf.d.ts +20 -8
- package/dist-sdk/src/entities/view/to-tf.js +86 -18
- package/dist-sdk/src/entities/view/types.d.ts +4 -15
- package/dist-sdk/src/entities/view/types.js +15 -15
- package/dist-sdk/src/entities/visual-flow/build.d.ts +16 -1
- package/dist-sdk/src/entities/visual-flow/build.js +9 -0
- package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +14 -0
- package/dist-sdk/src/entities/visual-flow/from-tf.js +51 -3
- package/dist-sdk/src/entities/visual-flow/index.d.ts +1 -1
- package/dist-sdk/src/entities/visual-flow/index.js +1 -1
- package/dist-sdk/src/entities/visual-flow/printer.js +19 -0
- package/dist-sdk/src/entities/visual-flow/to-tf.js +87 -3
- package/dist-sdk/src/entities/widget/build.d.ts +16 -1
- package/dist-sdk/src/entities/widget/build.js +11 -1
- package/dist-sdk/src/entities/widget/from-tf.js +3 -3
- package/dist-sdk/src/entities/widget/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/widget/to-tf.js +41 -14
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +148 -13
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +12 -0
- package/dist-sdk/src/graph/index.js +21 -0
- package/dist-sdk/src/graph/modules.js +2 -0
- package/dist-sdk/src/graph/types.d.ts +83 -4
- package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
- package/dist-sdk/src/internal/sdk-package.js +1 -0
- package/package.json +16 -3
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { USER_FIELD_KEYS, USER_GROUP_FIELD_KEYS } from "../../catalog/types.js";
|
|
2
2
|
import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEY_SET, SYSTEM_FIELD_KEYS } from "../../core/system-fields.js";
|
|
3
|
+
import { normalizeOnDemandParamKey } from "../../../pull/util.js";
|
|
3
4
|
import { EntityTfError } from "../../engine/entity.js";
|
|
5
|
+
import { dataRefLabel } from "../../engine/pull/context.js";
|
|
4
6
|
import { procedureDiscriminator } from "../../engine/pull/procedure-refs.js";
|
|
5
|
-
import { childPartFromScopedLabel, isTfExpr, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
|
|
7
|
+
import { appResourceLabelPrefix, childPartFromScopedLabel, elementResourceLabelPrefix, isTfExpr, isTfLabel, ownerFromScopedChildLabel, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
|
|
6
8
|
import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
|
|
7
9
|
import { IMPLEMENTED_FILE_READER_RESOURCE_TYPES } from "../file-reader/types.js";
|
|
8
10
|
import { connectorIdentityFromTf } from "../shared/connector-from-tf.js";
|
|
@@ -11,10 +13,12 @@ import { UNRESOLVED_FIELD_MARKER } from "../shared/ref.js";
|
|
|
11
13
|
import { filterFromTf as deserializeFilterFromTf } from "../shared/filters/tf-codec.js";
|
|
12
14
|
import { TABLE_RESOURCE_TYPE } from "../table/module.js";
|
|
13
15
|
import { SEARCH_TABLE_RESOURCE_TYPES } from "../search-table/types.js";
|
|
14
|
-
import { outputFieldTypesFromScriptSchema, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
|
|
16
|
+
import { outputFieldTypesFromScriptSchema, repeatedScriptOutputNames, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
|
|
15
17
|
import { apiTaskRefAuthoringPath, matchesOutputWireKey, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
|
|
18
|
+
import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
|
|
16
19
|
import { systemRefNameRoundTrips } from "./system-ref-name.js";
|
|
17
20
|
import { taskTfLabel } from "./task-label.js";
|
|
21
|
+
import { parseTriggerAttachmentPayloadRefJson, parseTriggerWholeRecordRefJson, TRIGGER_WHOLE_RECORD_REF_NAME } from "./task-output-labels.js";
|
|
18
22
|
import { workflowOutputTypeFromFieldType } from "./workflow-output.js";
|
|
19
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";
|
|
20
24
|
const TRIGGER_KINDS = {
|
|
@@ -35,6 +39,7 @@ const TRIGGER_KINDS = {
|
|
|
35
39
|
const TASK_FACTORIES = {
|
|
36
40
|
elementum_message_task: "postComment",
|
|
37
41
|
elementum_update_field_task: "updateField",
|
|
42
|
+
elementum_bulk_update_fields_task: "bulkUpdateFields",
|
|
38
43
|
elementum_variable_task: "setVariable",
|
|
39
44
|
elementum_update_variable_task: "setVariable",
|
|
40
45
|
elementum_create_record_task: "createRecord",
|
|
@@ -58,6 +63,7 @@ const TASK_FACTORIES = {
|
|
|
58
63
|
elementum_ai_search_table_task: "aiSearchTable",
|
|
59
64
|
elementum_ai_transform_task: "aiTransform",
|
|
60
65
|
elementum_save_attachment_task: "saveAttachment",
|
|
66
|
+
elementum_unzip_file_task: "unzip",
|
|
61
67
|
elementum_user_search_task: "userSearch",
|
|
62
68
|
elementum_user_group_search_task: "userGroupSearch",
|
|
63
69
|
elementum_calculation_task: "calculation",
|
|
@@ -123,6 +129,33 @@ const ATTR_TO_ARG = {
|
|
|
123
129
|
function isObject(value) {
|
|
124
130
|
return value !== null && typeof value === "object" && !Array.isArray(value) && !("$expr" in value);
|
|
125
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Describe a raw output-schema node for a diagnostic: its type tag, a string
|
|
134
|
+
* format, an object's nested property names, and an array's item shape
|
|
135
|
+
* (`string format "DATETIME"`, `object {step, done}`, `array of bool`).
|
|
136
|
+
*/
|
|
137
|
+
function describeScriptOutputNode(node) {
|
|
138
|
+
if (!isObject(node))
|
|
139
|
+
return "unknown";
|
|
140
|
+
const [type, definition] = Object.entries(node)[0] ?? [];
|
|
141
|
+
if (type === undefined || !isObject(definition))
|
|
142
|
+
return type ?? "unknown";
|
|
143
|
+
if (type === "string" && typeof definition.format === "string" && definition.format !== "") {
|
|
144
|
+
return `string format ${JSON.stringify(definition.format)}`;
|
|
145
|
+
}
|
|
146
|
+
if (type === "object") {
|
|
147
|
+
const names = Array.isArray(definition.properties)
|
|
148
|
+
? definition.properties.map((child) => {
|
|
149
|
+
const childDefinition = isObject(child) ? Object.values(child)[0] : undefined;
|
|
150
|
+
return isObject(childDefinition) && typeof childDefinition.name === "string" ? childDefinition.name : "?";
|
|
151
|
+
})
|
|
152
|
+
: [];
|
|
153
|
+
return `object {${names.join(", ")}}`;
|
|
154
|
+
}
|
|
155
|
+
if (type === "array")
|
|
156
|
+
return definition.item === undefined ? "array" : `array of ${describeScriptOutputNode(definition.item)}`;
|
|
157
|
+
return type;
|
|
158
|
+
}
|
|
126
159
|
/**
|
|
127
160
|
* Map a string output-schema node back to a product scalar.
|
|
128
161
|
* DATE/DATETIME/EMAIL/UUID4 become date/datetime/email/uuid4. A missing
|
|
@@ -171,6 +204,42 @@ function resourceRef(value) {
|
|
|
171
204
|
? { type: value.type, label: value.label, path: value.path }
|
|
172
205
|
: undefined;
|
|
173
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* A Run Automation input mapping names its parameter through the trigger (or
|
|
209
|
+
* data lookup) of the automation that owns it, but pulled source only keeps
|
|
210
|
+
* the parameter NAME and build resolves it on the task's target. When the
|
|
211
|
+
* exported owner is provably a different automation than the target, the
|
|
212
|
+
* mapping cannot round-trip; report it instead of re-pointing it silently.
|
|
213
|
+
* Owners that cannot be resolved inside this export are not judged.
|
|
214
|
+
*/
|
|
215
|
+
function inputMappingOwnerMismatch(block, parameter, ctx) {
|
|
216
|
+
const automationAddress = (value) => {
|
|
217
|
+
if (!isTfExpr(value))
|
|
218
|
+
return undefined;
|
|
219
|
+
const ref = value;
|
|
220
|
+
if ((ref.$expr === "resource-attr" || ref.$expr === "data-attr") && ref.type === AUTOMATION_RESOURCE_TYPE) {
|
|
221
|
+
return `${ref.$expr === "data-attr" ? "data." : ""}${ref.type}.${ref.label}`;
|
|
222
|
+
}
|
|
223
|
+
return undefined;
|
|
224
|
+
};
|
|
225
|
+
const target = automationAddress(block.attrs.target_automation_id);
|
|
226
|
+
if (target === undefined)
|
|
227
|
+
return undefined;
|
|
228
|
+
if (parameter.$expr === "data-attr") {
|
|
229
|
+
const owner = automationAddress(parameter);
|
|
230
|
+
return owner !== undefined && owner !== target ? { parameterOwner: owner, target } : undefined;
|
|
231
|
+
}
|
|
232
|
+
if (parameter.$expr !== "resource-attr")
|
|
233
|
+
return undefined;
|
|
234
|
+
const triggerAddress = `${parameter.type}.${parameter.label}`;
|
|
235
|
+
const trigger = ctx.resourceBlocks.get(triggerAddress);
|
|
236
|
+
const owningAutomation = resourceRef(trigger?.attrs.automation);
|
|
237
|
+
if (owningAutomation === undefined || owningAutomation.type !== AUTOMATION_RESOURCE_TYPE)
|
|
238
|
+
return undefined;
|
|
239
|
+
return `${owningAutomation.type}.${owningAutomation.label}` !== target
|
|
240
|
+
? { parameterOwner: triggerAddress, target }
|
|
241
|
+
: undefined;
|
|
242
|
+
}
|
|
174
243
|
function references(value, type, label) {
|
|
175
244
|
const ref = resourceRef(value);
|
|
176
245
|
return ref?.type === type && ref.label === label;
|
|
@@ -261,7 +330,7 @@ const TRIGGER_ATTRIBUTES = new Set([
|
|
|
261
330
|
]);
|
|
262
331
|
const TASK_ATTRIBUTES = new Set([
|
|
263
332
|
"parent", "name", "depends_on", "filter", "fields", "inputs", "output_schema",
|
|
264
|
-
"list", "code", "
|
|
333
|
+
"list", "code", "variables", "updates", "variable", "value",
|
|
265
334
|
"object_id", "table_id", "record_reference", "record_id", "source_record_ids",
|
|
266
335
|
"approval_process_id", "requester_reference", "approver_references", "reason", "summary",
|
|
267
336
|
"approval_reference", "status",
|
|
@@ -276,11 +345,13 @@ const TASK_ATTRIBUTES = new Set([
|
|
|
276
345
|
"output_mappings", "file_reader_id", "raw_text", "procedure_id",
|
|
277
346
|
"calculations", "categories", "limit", "sort", "tag", "tags", "context", "length",
|
|
278
347
|
"subject", "phone_service_id", "phone_number", "default_language", "first_message",
|
|
279
|
-
"synchronous", "cloudlink_id", "stored_function_id",
|
|
348
|
+
"synchronous", "cloudlink_id", "stored_function_id",
|
|
280
349
|
"relate_to_record_reference", "method", "parameters", "headers",
|
|
281
350
|
"basic_auth", "bearer_auth", "oauth", "json_body", "form_body", "custom_body", "multipart_body",
|
|
282
351
|
"query",
|
|
283
352
|
]);
|
|
353
|
+
/** A notification's description is a value reference like its title and message. */
|
|
354
|
+
const NOTIFICATION_TASK_ATTRIBUTES = new Set([...TASK_ATTRIBUTES, "description"]);
|
|
284
355
|
const BRANCH_ATTRIBUTES = new Set([
|
|
285
356
|
"switch_task", "fork_join_task", "label", "is_default", "filter",
|
|
286
357
|
"previous_case_id", "previous_branch_id",
|
|
@@ -312,6 +383,11 @@ const WIRE_REF_SEGMENT_TO_TS = {
|
|
|
312
383
|
"Message ID": "messageId",
|
|
313
384
|
"Message Metadata": "messageMetadata",
|
|
314
385
|
};
|
|
386
|
+
const ON_DEMAND_TRIGGERED_BY_FROM_WIRE = {
|
|
387
|
+
"Triggered By's Id": ["triggeredBy", "id"],
|
|
388
|
+
"Triggered By's Email": ["triggeredBy", "email"],
|
|
389
|
+
"Triggered By's Name": ["triggeredBy", "name"],
|
|
390
|
+
};
|
|
315
391
|
const FIELD_REF_SUFFIX_FROM_WIRE = [
|
|
316
392
|
[" Manager Email", ["employee", "manager", "email"]],
|
|
317
393
|
[" Manager Name", ["employee", "manager", "name"]],
|
|
@@ -402,6 +478,38 @@ function isDeclaredOnDemandParameter(trigger, wireName) {
|
|
|
402
478
|
const parameters = trigger.attrs.parameters;
|
|
403
479
|
return Array.isArray(parameters) && parameters.some((parameter) => isObject(parameter) && parameter.name === wireName);
|
|
404
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* The platform stores a reference to an on-demand input under its normalized
|
|
483
|
+
* name (`normalizeOnDemandFilterRefName`: "TICKET_ID" → "ticketId"), whatever
|
|
484
|
+
* spelling the reference was authored with. Map that wire name back to the
|
|
485
|
+
* one declared scalar input it normalizes from, so pulled source addresses
|
|
486
|
+
* the input as declared (`ctx.trigger.TICKET_ID`).
|
|
487
|
+
*/
|
|
488
|
+
function declaredOnDemandInputForWireName(trigger, wireName) {
|
|
489
|
+
if (trigger.type !== "elementum_on_demand_trigger" || !Array.isArray(trigger.attrs.parameters))
|
|
490
|
+
return undefined;
|
|
491
|
+
if (isDeclaredOnDemandParameter(trigger, wireName))
|
|
492
|
+
return undefined;
|
|
493
|
+
const matches = trigger.attrs.parameters.flatMap((parameter) => isObject(parameter) && typeof parameter.name === "string" && parameter.type !== "record" &&
|
|
494
|
+
normalizeOnDemandParamKey(parameter.name) === wireName
|
|
495
|
+
? [parameter.name]
|
|
496
|
+
: []);
|
|
497
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
498
|
+
}
|
|
499
|
+
/** The declared field type of the scalar on-demand input a trigger reference names (declared or normalized spelling). */
|
|
500
|
+
function declaredOnDemandInputFieldType(trigger, wireName) {
|
|
501
|
+
if (trigger.type !== "elementum_on_demand_trigger" || !Array.isArray(trigger.attrs.parameters))
|
|
502
|
+
return undefined;
|
|
503
|
+
const name = declaredOnDemandInputForWireName(trigger, wireName) ?? wireName;
|
|
504
|
+
const parameter = trigger.attrs.parameters.find((candidate) => isObject(candidate) && candidate.name === name);
|
|
505
|
+
if (!isObject(parameter) || typeof parameter.type !== "string" || parameter.type === "record")
|
|
506
|
+
return undefined;
|
|
507
|
+
return {
|
|
508
|
+
// Inverse of to-tf's on-demand parameter type spelling.
|
|
509
|
+
fieldType: parameter.type === "attachment" ? "ATTACHMENT_ID" : parameter.type.toUpperCase(),
|
|
510
|
+
multiple: parameter.multiple === true,
|
|
511
|
+
};
|
|
512
|
+
}
|
|
405
513
|
function onDemandRecordParameters(trigger) {
|
|
406
514
|
if (trigger.type !== "elementum_on_demand_trigger" || !Array.isArray(trigger.attrs.parameters))
|
|
407
515
|
return [];
|
|
@@ -448,7 +556,7 @@ const RECORD_SEARCH_TASK_REF_SEGMENT_TO_TS = {
|
|
|
448
556
|
* write side). Only the names that differ from their authoring path are
|
|
449
557
|
* listed; the rest already read back correctly.
|
|
450
558
|
*/
|
|
451
|
-
const RECORD_SEARCH_CALCULATION_REF_NAME_TO_TS = {
|
|
559
|
+
export const RECORD_SEARCH_CALCULATION_REF_NAME_TO_TS = {
|
|
452
560
|
count: ["totalCount"],
|
|
453
561
|
recordId: ["record", "recordId"],
|
|
454
562
|
};
|
|
@@ -456,15 +564,30 @@ const RECORD_SEARCH_CALCULATION_REF_NAME_TO_TS = {
|
|
|
456
564
|
// RECORD_SEARCH_TASK_REF_SEGMENT_TO_TS: "All Records" is a platform-fixed
|
|
457
565
|
// wire key on elementum_ai_search_table_task only. A trigger field could
|
|
458
566
|
// coincidentally share that display name and must not be rewritten here.
|
|
459
|
-
const AI_SEARCH_TABLE_TASK_REF_SEGMENT_TO_TS = {
|
|
567
|
+
export const AI_SEARCH_TABLE_TASK_REF_SEGMENT_TO_TS = {
|
|
568
|
+
// "searchTableRecords" is the CANONICAL output name a workflow output emits
|
|
569
|
+
// (edk#835 — the forward maps the `.records` accessor to it); "All Records" is
|
|
570
|
+
// the legacy display form kept for already-deployed HCL. Both decode to `.records`.
|
|
571
|
+
searchTableRecords: "records",
|
|
460
572
|
"All Records": "records",
|
|
573
|
+
searchTableRecordsText: "recordsText",
|
|
574
|
+
"All Records Text": "recordsText",
|
|
575
|
+
searchTableRecordsJson: "recordsJson",
|
|
576
|
+
"All Records JSON": "recordsJson",
|
|
577
|
+
firstFoundRecordText: "firstRecordText",
|
|
578
|
+
"First Record Text": "firstRecordText",
|
|
579
|
+
firstFoundRecordJson: "firstRecordJson",
|
|
580
|
+
"First Record JSON": "firstRecordJson",
|
|
461
581
|
};
|
|
462
582
|
// tableRecordsSearch collection output — platform wire key
|
|
463
583
|
// "All matching table rows" (not recordSearch's "All found records" or
|
|
464
584
|
// aiSearchTable's "All Records"). Leaving it unmapped prints
|
|
465
585
|
// `(ctx.actions.x as any)["All matching table rows"]`, which drops the Ref
|
|
466
586
|
// proxy at build time and omits the script/filter input entirely.
|
|
467
|
-
const TABLE_RECORDS_SEARCH_TASK_REF_SEGMENT_TO_TS = {
|
|
587
|
+
export const TABLE_RECORDS_SEARCH_TASK_REF_SEGMENT_TO_TS = {
|
|
588
|
+
// Canonical count output `count` → the `totalCount` accessor (edk#835 — same
|
|
589
|
+
// as recordSearch). "All matching table rows" is the legacy display form.
|
|
590
|
+
count: "totalCount",
|
|
468
591
|
"All matching table rows": "records",
|
|
469
592
|
};
|
|
470
593
|
// Platform-fixed output labels → authoring path, inverse of
|
|
@@ -476,6 +599,7 @@ const TASK_OUTPUT_LABEL_TO_TS = {
|
|
|
476
599
|
elementum_update_field_task: { "Updated record": ["record"] },
|
|
477
600
|
elementum_execute_script_task: { "Text Result": ["textResult"] },
|
|
478
601
|
elementum_user_search_task: {
|
|
602
|
+
"Users Size": ["count"],
|
|
479
603
|
"User's Id": ["user", "id"],
|
|
480
604
|
"User's Name": ["user", "name"],
|
|
481
605
|
"User's Email": ["user", "email"],
|
|
@@ -584,11 +708,13 @@ function aspectRefFromObjectId(objectId, ctx) {
|
|
|
584
708
|
}
|
|
585
709
|
if (typeof identity !== "string" || identity === "")
|
|
586
710
|
return undefined;
|
|
711
|
+
const namespace = lookup?.attrs.namespace;
|
|
587
712
|
return {
|
|
588
713
|
kind: "app",
|
|
589
714
|
appHandle: tfLabelToTsLabel(objectId.label),
|
|
590
715
|
entityType: objectId.type === "elementum_task" ? "task" : objectId.type === "elementum_element" ? "element" : "app",
|
|
591
716
|
name: identity,
|
|
717
|
+
...(typeof namespace === "string" && namespace !== "" ? { namespace } : {}),
|
|
592
718
|
};
|
|
593
719
|
}
|
|
594
720
|
function aspectKindFromObjectId(objectId) {
|
|
@@ -770,22 +896,144 @@ function approverReferenceFieldAuthoringType(value, ctx) {
|
|
|
770
896
|
}
|
|
771
897
|
return undefined;
|
|
772
898
|
}
|
|
773
|
-
function decodeFieldAssignmentValue(value, ctx) {
|
|
899
|
+
function decodeFieldAssignmentValue(value, ctx, diagnostics, where = "field assignment") {
|
|
774
900
|
// Multi-Select assignments are exported as jsonencode([<option UUID>, ...])
|
|
775
901
|
// rather than the options-by-label locals used for a scalar Dropdown. Walk
|
|
776
902
|
// that payload with the state-derived option registry so pulled source stays
|
|
777
903
|
// portable across organizations and fresh creates.
|
|
778
904
|
if (isTfExpr(value) && value.$expr === "jsonencode") {
|
|
779
|
-
return decodeFieldAssignmentValue(value.value, ctx);
|
|
905
|
+
return decodeFieldAssignmentValue(value.value, ctx, diagnostics, where);
|
|
780
906
|
}
|
|
781
907
|
if (Array.isArray(value)) {
|
|
782
|
-
return value.map((item) => decodeFieldAssignmentValue(item, ctx));
|
|
908
|
+
return value.map((item) => decodeFieldAssignmentValue(item, ctx, diagnostics, where));
|
|
783
909
|
}
|
|
784
910
|
if (typeof value === "string" && /^[a-f0-9-]{36}$/i.test(value)) {
|
|
785
911
|
const label = ctx.picklistOptionLabelById?.get(value);
|
|
786
912
|
if (label !== undefined)
|
|
787
913
|
return { kind: "literal", value: label };
|
|
788
914
|
}
|
|
915
|
+
return decodeValueOrStringifiedRef(value, ctx, diagnostics, where);
|
|
916
|
+
}
|
|
917
|
+
const VALUE_REFERENCE_KEYS = ["taskReference", "triggerReference", "variableReference"];
|
|
918
|
+
/**
|
|
919
|
+
* edk#1646: ei's exporter falls back to a stringified wire ValueReference
|
|
920
|
+
* envelope (`"{\"fieldType\":…,\"taskReference\":{…}}"`) when it cannot emit a
|
|
921
|
+
* `refs["…"]` expression. Left as a literal, build ships the JSON text into
|
|
922
|
+
* the field (or fails a typed field). Decode the envelope - whole-string or
|
|
923
|
+
* embedded in surrounding text - through the same path calculation formulas
|
|
924
|
+
* use. An envelope whose task / trigger / variable does not resolve in this
|
|
925
|
+
* automation stays visible as an `unresolved` value-reference with a pull
|
|
926
|
+
* diagnostic instead of a silent literal. Returns undefined for any string
|
|
927
|
+
* that carries no envelope.
|
|
928
|
+
*/
|
|
929
|
+
function decodeStringifiedValueReference(value, ctx, diagnostics, where) {
|
|
930
|
+
if (!value.includes("{") || !VALUE_REFERENCE_KEYS.some((key) => value.includes(`"${key}"`)))
|
|
931
|
+
return undefined;
|
|
932
|
+
const parts = [];
|
|
933
|
+
let cursor = 0;
|
|
934
|
+
let unresolved = false;
|
|
935
|
+
let found = false;
|
|
936
|
+
for (let start = value.indexOf("{", cursor); start >= 0; start = value.indexOf("{", cursor)) {
|
|
937
|
+
let depth = 0;
|
|
938
|
+
let inString = false;
|
|
939
|
+
let escaped = false;
|
|
940
|
+
let end = start;
|
|
941
|
+
for (; end < value.length; end += 1) {
|
|
942
|
+
const char = value[end];
|
|
943
|
+
if (inString) {
|
|
944
|
+
if (escaped)
|
|
945
|
+
escaped = false;
|
|
946
|
+
else if (char === "\\")
|
|
947
|
+
escaped = true;
|
|
948
|
+
else if (char === '"')
|
|
949
|
+
inString = false;
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
if (char === '"')
|
|
953
|
+
inString = true;
|
|
954
|
+
else if (char === "{")
|
|
955
|
+
depth += 1;
|
|
956
|
+
else if (char === "}") {
|
|
957
|
+
depth -= 1;
|
|
958
|
+
if (depth === 0) {
|
|
959
|
+
end += 1;
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (depth !== 0)
|
|
965
|
+
break;
|
|
966
|
+
let parsed;
|
|
967
|
+
try {
|
|
968
|
+
parsed = JSON.parse(value.slice(start, end));
|
|
969
|
+
}
|
|
970
|
+
catch {
|
|
971
|
+
cursor = start + 1;
|
|
972
|
+
continue;
|
|
973
|
+
}
|
|
974
|
+
if (!isObject(parsed) || !VALUE_REFERENCE_KEYS.some((key) => isObject(parsed[key]))) {
|
|
975
|
+
cursor = start + 1;
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
found = true;
|
|
979
|
+
if (start > cursor)
|
|
980
|
+
parts.push(value.slice(cursor, start));
|
|
981
|
+
const reference = decodeFilterReferenceEnvelope(parsed, ctx);
|
|
982
|
+
if (reference === undefined || !stringifiedReferenceResolves(parsed, reference, ctx)) {
|
|
983
|
+
unresolved = true;
|
|
984
|
+
parts.push({ kind: "unresolved", uuid: value.slice(start, end), hint: "value-reference (edk#1646)" });
|
|
985
|
+
}
|
|
986
|
+
else {
|
|
987
|
+
parts.push(reference);
|
|
988
|
+
}
|
|
989
|
+
cursor = end;
|
|
990
|
+
}
|
|
991
|
+
if (!found)
|
|
992
|
+
return undefined;
|
|
993
|
+
if (unresolved) {
|
|
994
|
+
diagnostics?.push(`${where}: value is a stringified platform ValueReference whose task/trigger/variable is not in this automation; ` +
|
|
995
|
+
"kept as an unresolved value-reference - rewrite it as a ctx reference before building (edk#1646)");
|
|
996
|
+
}
|
|
997
|
+
if (cursor < value.length)
|
|
998
|
+
parts.push(value.slice(cursor));
|
|
999
|
+
const merged = [];
|
|
1000
|
+
for (const part of parts) {
|
|
1001
|
+
const last = merged[merged.length - 1];
|
|
1002
|
+
if (typeof part === "string" && typeof last === "string")
|
|
1003
|
+
merged[merged.length - 1] = last + part;
|
|
1004
|
+
else
|
|
1005
|
+
merged.push(part);
|
|
1006
|
+
}
|
|
1007
|
+
// A sole unresolved envelope (or one that failed to resolve) becomes a
|
|
1008
|
+
// single unresolved value so the printer surfaces the TODO instead of a
|
|
1009
|
+
// template that still embeds the JSON text.
|
|
1010
|
+
if (unresolved && merged.length === 1 && typeof merged[0] !== "string") {
|
|
1011
|
+
return merged[0];
|
|
1012
|
+
}
|
|
1013
|
+
if (unresolved) {
|
|
1014
|
+
return { kind: "unresolved", uuid: value, hint: "value-reference (edk#1646)" };
|
|
1015
|
+
}
|
|
1016
|
+
if (merged.length === 1 && typeof merged[0] !== "string")
|
|
1017
|
+
return merged[0];
|
|
1018
|
+
return { kind: "template", parts: merged };
|
|
1019
|
+
}
|
|
1020
|
+
function stringifiedReferenceResolves(envelope, reference, ctx) {
|
|
1021
|
+
if (reference.kind === "unresolved")
|
|
1022
|
+
return false;
|
|
1023
|
+
const taskRef = envelope.taskReference;
|
|
1024
|
+
if (isObject(taskRef)) {
|
|
1025
|
+
const taskIdOrKey = workflowOutputTaskIdOrKey(taskRef.taskId, ctx);
|
|
1026
|
+
return taskIdOrKey !== undefined && resolveTaskRefKey(taskIdOrKey, ctx).block !== undefined;
|
|
1027
|
+
}
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
1030
|
+
/** decodeValue, upgrading a stringified ValueReference envelope (edk#1646). */
|
|
1031
|
+
function decodeValueOrStringifiedRef(value, ctx, diagnostics, where) {
|
|
1032
|
+
if (typeof value === "string") {
|
|
1033
|
+
const decoded = decodeStringifiedValueReference(value, ctx, diagnostics, where);
|
|
1034
|
+
if (decoded !== undefined)
|
|
1035
|
+
return decoded;
|
|
1036
|
+
}
|
|
789
1037
|
return decodeValue(value, ctx);
|
|
790
1038
|
}
|
|
791
1039
|
function triggerRefPath(path, ctx) {
|
|
@@ -833,6 +1081,11 @@ function triggerRefPath(path, ctx) {
|
|
|
833
1081
|
const recordPath = prefixedOnDemandRecordRefPath(wireName, ctx);
|
|
834
1082
|
if (recordPath !== undefined)
|
|
835
1083
|
return recordPath;
|
|
1084
|
+
const triggeredBy = ON_DEMAND_TRIGGERED_BY_FROM_WIRE[wireName];
|
|
1085
|
+
const declaresTriggeredBy = Array.isArray(ctx.trigger.attrs.parameters) &&
|
|
1086
|
+
ctx.trigger.attrs.parameters.some((parameter) => isObject(parameter) && parameter.name === "triggeredBy");
|
|
1087
|
+
if (triggeredBy !== undefined && !declaresTriggeredBy)
|
|
1088
|
+
return [...triggeredBy];
|
|
836
1089
|
}
|
|
837
1090
|
// An on-demand parameter is an explicitly declared top-level ctx.trigger
|
|
838
1091
|
// property. Check this before record-field inference: a perfectly ordinary
|
|
@@ -840,15 +1093,16 @@ function triggerRefPath(path, ctx) {
|
|
|
840
1093
|
// field display name "Facility".
|
|
841
1094
|
if (isDeclaredOnDemandParameter(ctx.trigger, wireName))
|
|
842
1095
|
return names;
|
|
843
|
-
// A trigger's own bare record reference
|
|
844
|
-
//
|
|
845
|
-
//
|
|
846
|
-
//
|
|
847
|
-
//
|
|
848
|
-
//
|
|
849
|
-
//
|
|
850
|
-
//
|
|
851
|
-
//
|
|
1096
|
+
// A trigger's own bare record reference. refs["Record"] is the record ID
|
|
1097
|
+
// (ASPECT_RECORD_ID, confirmed live via `ei refs`, see
|
|
1098
|
+
// trigger-record-id.test.ts); the whole record shares that display name and
|
|
1099
|
+
// has no refs key, so it exports as its reference JSON instead (edk#1284).
|
|
1100
|
+
// Deliberately scoped to triggerRefPath, not the shared
|
|
1101
|
+
// WIRE_REF_SEGMENT_TO_TS table: createRecord/findRelatedRecords TASKS also
|
|
1102
|
+
// expose a wire key literally named "Record" (their record-ID output), and
|
|
1103
|
+
// translating it globally intercepted that task-level case before it could
|
|
1104
|
+
// ever be checked (decodeValue's own dedicated "Record" handling for those
|
|
1105
|
+
// task types).
|
|
852
1106
|
if (wireName === "Record") {
|
|
853
1107
|
const recordParams = onDemandRecordParameters(ctx.trigger);
|
|
854
1108
|
return recordParams.length === 1
|
|
@@ -867,7 +1121,11 @@ function triggerRefPath(path, ctx) {
|
|
|
867
1121
|
return names;
|
|
868
1122
|
return recordFieldRefPath(wireName, ctx) ?? names;
|
|
869
1123
|
}
|
|
870
|
-
function
|
|
1124
|
+
function forEachItemOwnerRefName(loop, ctx) {
|
|
1125
|
+
const collection = loop === undefined ? undefined : resourceRef(loop.attrs.list);
|
|
1126
|
+
return collection === undefined ? undefined : ctx.taskTargetOwnerRefNameByAddress?.get(`${collection.type}.${collection.label}`);
|
|
1127
|
+
}
|
|
1128
|
+
function forEachItemRefPath(path, ctx, loop) {
|
|
871
1129
|
const names = pathNames(path);
|
|
872
1130
|
if (names.length !== 1)
|
|
873
1131
|
return names.flatMap((segment) => segment.split("."));
|
|
@@ -878,7 +1136,9 @@ function forEachItemRefPath(path, ctx) {
|
|
|
878
1136
|
if (wireName === "Record")
|
|
879
1137
|
return ["recordId"];
|
|
880
1138
|
const wireNameLower = wireName.toLowerCase();
|
|
881
|
-
|
|
1139
|
+
const itemOwner = forEachItemOwnerRefName(loop, ctx);
|
|
1140
|
+
const ownFields = itemOwner === undefined || itemOwner === ctx.appRefName ? ctx.fieldById.values() : [];
|
|
1141
|
+
for (const field of ownFields) {
|
|
882
1142
|
// Some provider paths already contain the stable EDK field key (for
|
|
883
1143
|
// example `for_each.<task-id>.productId`), while inner.refs uses the
|
|
884
1144
|
// display name in other workflow shapes. Accept both forms.
|
|
@@ -946,8 +1206,12 @@ function decodeTaskReferenceFromString(taskIdOrKey, pathSegments, ctx) {
|
|
|
946
1206
|
}
|
|
947
1207
|
if (block?.type === "elementum_record_search_task" && pathSegments.length >= 1) {
|
|
948
1208
|
const [head, ...tail] = pathSegments;
|
|
949
|
-
|
|
950
|
-
|
|
1209
|
+
// Canonical output names whose authoring path differs from the wire name
|
|
1210
|
+
// (count → .totalCount, recordId → .record.recordId) — the exact inverse of
|
|
1211
|
+
// rewriteCanonicalOutputRefName's forward map (edk#835).
|
|
1212
|
+
const canonicalPath = RECORD_SEARCH_CALCULATION_REF_NAME_TO_TS[head];
|
|
1213
|
+
if (canonicalPath !== undefined) {
|
|
1214
|
+
return { kind: "taskRef", task: refKey, path: [...canonicalPath, ...tail] };
|
|
951
1215
|
}
|
|
952
1216
|
const recordSearchName = RECORD_SEARCH_TASK_REF_SEGMENT_TO_TS[head];
|
|
953
1217
|
if (recordSearchName !== undefined) {
|
|
@@ -996,6 +1260,11 @@ function decodeTaskReferenceFromString(taskIdOrKey, pathSegments, ctx) {
|
|
|
996
1260
|
if (groupPath !== undefined)
|
|
997
1261
|
return { kind: "taskRef", task: refKey, path: [...groupPath] };
|
|
998
1262
|
}
|
|
1263
|
+
if (block?.type === "elementum_user_search_task" && pathSegments.length === 1) {
|
|
1264
|
+
const userPath = TASK_OUTPUT_LABEL_TO_TS.elementum_user_search_task?.[pathSegments[0]];
|
|
1265
|
+
if (userPath !== undefined)
|
|
1266
|
+
return { kind: "taskRef", task: refKey, path: [...userPath] };
|
|
1267
|
+
}
|
|
999
1268
|
// createRecord/findRelatedRecords record-id + field outputs (same as the
|
|
1000
1269
|
// refs["Title"] / refs["Record"] resource-attr path in decodeValue).
|
|
1001
1270
|
if ((block?.type === "elementum_create_record_task" || block?.type === "elementum_find_related_records_task") &&
|
|
@@ -1047,6 +1316,9 @@ function decodeReferenceString(value, ctx) {
|
|
|
1047
1316
|
const pieces = value.split(".");
|
|
1048
1317
|
if (pieces[0] === "trigger" && pieces.length > 1) {
|
|
1049
1318
|
const path = pieces.slice(1);
|
|
1319
|
+
const declaredInput = path.length === 1 ? declaredOnDemandInputForWireName(ctx.trigger, path[0]) : undefined;
|
|
1320
|
+
if (declaredInput !== undefined)
|
|
1321
|
+
return { kind: "triggerRef", path: [declaredInput] };
|
|
1050
1322
|
if (path[0] === "record" && path.length >= 2 && /^[a-f0-9-]{36}$/.test(path[1])) {
|
|
1051
1323
|
const sourceFieldId = path[1];
|
|
1052
1324
|
const field = ctx.fieldById.get(sourceFieldId);
|
|
@@ -1074,11 +1346,11 @@ function decodeReferenceString(value, ctx) {
|
|
|
1074
1346
|
return decodeTaskReferenceFromString(pieces[1], pieces.slice(2), ctx);
|
|
1075
1347
|
}
|
|
1076
1348
|
if (pieces[0] === "for_each" && pieces.length > 2) {
|
|
1077
|
-
const { refKey } = resolveTaskRefKey(pieces[1], ctx);
|
|
1349
|
+
const { refKey, block } = resolveTaskRefKey(pieces[1], ctx);
|
|
1078
1350
|
return {
|
|
1079
1351
|
kind: "forEachItemRef",
|
|
1080
1352
|
forEachTask: refKey,
|
|
1081
|
-
path: forEachItemRefPath(pieces.slice(2), ctx),
|
|
1353
|
+
path: forEachItemRefPath(pieces.slice(2), ctx, block),
|
|
1082
1354
|
};
|
|
1083
1355
|
}
|
|
1084
1356
|
if (pieces[0] === "variable" && pieces.length > 1) {
|
|
@@ -1109,18 +1381,35 @@ function decodeTemplateTriggerRecordFieldRef(value, ctx) {
|
|
|
1109
1381
|
if (!isTfExpr(value) || value.$expr !== "template")
|
|
1110
1382
|
return undefined;
|
|
1111
1383
|
const [prefix, fieldPart, suffixPart] = value.parts;
|
|
1112
|
-
if (prefix !== "
|
|
1384
|
+
if (typeof prefix !== "string" || fieldPart === undefined || typeof fieldPart === "string")
|
|
1385
|
+
return undefined;
|
|
1386
|
+
const root = prefix === "trigger.record."
|
|
1387
|
+
? "record"
|
|
1388
|
+
: onDemandRecordParameters(ctx.trigger)
|
|
1389
|
+
.map((parameter) => parameter.name)
|
|
1390
|
+
.find((name) => prefix === `trigger.${name}.`);
|
|
1391
|
+
if (root === undefined)
|
|
1113
1392
|
return undefined;
|
|
1114
1393
|
if (suffixPart !== undefined && typeof suffixPart !== "string")
|
|
1115
1394
|
return undefined;
|
|
1116
|
-
const
|
|
1395
|
+
const parameter = onDemandRecordParameters(ctx.trigger).find((candidate) => candidate.name === root);
|
|
1396
|
+
const hasTarget = parameter?.default_value !== undefined && parameter.default_value !== null;
|
|
1397
|
+
const fieldKey = hasTarget
|
|
1398
|
+
? fieldKeyOnRecordParameterTarget(fieldPart, parameter.default_value, ctx)
|
|
1399
|
+
: fieldKeyFromTriggerFieldIdExpr(fieldPart, ctx);
|
|
1400
|
+
if (fieldKey === undefined && hasTarget) {
|
|
1401
|
+
const fieldId = fieldPart.$expr === "resource-attr" ? `${fieldPart.type}.${fieldPart.label}.id`
|
|
1402
|
+
: fieldPart.$expr === "local" ? `local.${fieldPart.name}`
|
|
1403
|
+
: "field";
|
|
1404
|
+
return { kind: "unresolved", uuid: `${prefix}${fieldId}${suffixPart ?? ""}`, hint: `field of on-demand record input "${root}"` };
|
|
1405
|
+
}
|
|
1117
1406
|
if (fieldKey === undefined)
|
|
1118
1407
|
return undefined;
|
|
1119
1408
|
const suffix = suffixPart === undefined ? [] : suffixPart.replace(/^\./, "").split(".").filter((s) => s.length > 0);
|
|
1120
1409
|
if (suffix.length === 1 && suffix[0] === "10000001-2000-4000-a000-800000000000") {
|
|
1121
|
-
return { kind: "triggerRef", path: [
|
|
1410
|
+
return { kind: "triggerRef", path: [root, fieldKey, "recordId"] };
|
|
1122
1411
|
}
|
|
1123
|
-
return { kind: "triggerRef", path: [
|
|
1412
|
+
return { kind: "triggerRef", path: [root, fieldKey, ...suffix] };
|
|
1124
1413
|
}
|
|
1125
1414
|
/**
|
|
1126
1415
|
* Inverse of filterReferenceToTf's TASK case: filters render
|
|
@@ -1201,7 +1490,7 @@ function decodeTemplateForEachRef(value, ctx) {
|
|
|
1201
1490
|
return {
|
|
1202
1491
|
kind: "forEachItemRef",
|
|
1203
1492
|
forEachTask: task.refKey,
|
|
1204
|
-
path: forEachItemRefPath(nameParts, ctx),
|
|
1493
|
+
path: forEachItemRefPath(nameParts, ctx, task.block),
|
|
1205
1494
|
};
|
|
1206
1495
|
}
|
|
1207
1496
|
/**
|
|
@@ -1213,9 +1502,44 @@ function decodeTemplateForEachRef(value, ctx) {
|
|
|
1213
1502
|
* decodeValue's generic local handling, but resolves to a triggerRef bag key
|
|
1214
1503
|
* instead of a "field" RefExpr so it stays a valid filter LHS.
|
|
1215
1504
|
*/
|
|
1505
|
+
function fieldBagKey(label, ctx) {
|
|
1506
|
+
const owned = ownerFromScopedChildLabel(label);
|
|
1507
|
+
if (owned !== undefined)
|
|
1508
|
+
return scopedLabelToBagKey(owned.ownerTfLabel, label, owned.scope);
|
|
1509
|
+
return scopedLabelToBagKey(ctx.appTfLabel, label, ctx.ownerScope);
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* A field id under an on-demand record input belongs to that input's target
|
|
1513
|
+
* (its `default_value`). Another app's or element's field decodes only when its
|
|
1514
|
+
* label carries that owner's prefix; anything else stays unresolved rather
|
|
1515
|
+
* than becoming a made-up key on the parameter.
|
|
1516
|
+
*/
|
|
1517
|
+
function fieldKeyOnRecordParameterTarget(fieldPart, target, ctx) {
|
|
1518
|
+
if (!isTfExpr(target) ||
|
|
1519
|
+
(target.$expr !== "resource-attr" && target.$expr !== "data-attr") ||
|
|
1520
|
+
(target.type !== "elementum_app" && target.type !== "elementum_element") ||
|
|
1521
|
+
target.path[0] !== "id") {
|
|
1522
|
+
return undefined;
|
|
1523
|
+
}
|
|
1524
|
+
if (target.$expr === "resource-attr" && target.label === ctx.appTfLabel) {
|
|
1525
|
+
return fieldKeyFromTriggerFieldIdExpr(fieldPart, ctx);
|
|
1526
|
+
}
|
|
1527
|
+
const scope = target.type === "elementum_element" ? "element" : "app";
|
|
1528
|
+
if (fieldPart.$expr === "resource-attr" && fieldPart.type.endsWith("_field") && fieldPart.path[0] === "id") {
|
|
1529
|
+
const prefix = scope === "element" ? elementResourceLabelPrefix(target.label) : appResourceLabelPrefix(target.label);
|
|
1530
|
+
return fieldPart.label.startsWith(prefix) ? scopedLabelToBagKey(target.label, fieldPart.label, scope) : undefined;
|
|
1531
|
+
}
|
|
1532
|
+
if (fieldPart.$expr === "local") {
|
|
1533
|
+
const prefix = `${target.label}_`;
|
|
1534
|
+
if (fieldPart.name.startsWith(prefix) && fieldPart.name.endsWith("_field_id")) {
|
|
1535
|
+
return tfLabelToTsLabel(fieldPart.name.slice(prefix.length, -"_field_id".length));
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
return undefined;
|
|
1539
|
+
}
|
|
1216
1540
|
function fieldKeyFromTriggerFieldIdExpr(fieldPart, ctx) {
|
|
1217
1541
|
if (fieldPart.$expr === "resource-attr" && fieldPart.type.endsWith("_field") && fieldPart.path[0] === "id") {
|
|
1218
|
-
return
|
|
1542
|
+
return fieldBagKey(fieldPart.label, ctx);
|
|
1219
1543
|
}
|
|
1220
1544
|
if (fieldPart.$expr === "local") {
|
|
1221
1545
|
const prefix = `${ctx.appTfLabel}_`;
|
|
@@ -1313,6 +1637,22 @@ function decodeSearchTableReference(value, ctx) {
|
|
|
1313
1637
|
if (isTfExpr(value) && value.$expr === "data-attr" && value.type === "elementum_search_table") {
|
|
1314
1638
|
const lookup = ctx.dataBlocks.get(`${value.type}.${value.label}`);
|
|
1315
1639
|
const name = typeof lookup?.attrs.name === "string" ? lookup.attrs.name : undefined;
|
|
1640
|
+
const pinnedId = typeof lookup?.attrs.id === "string" && lookup.attrs.id !== "" ? lookup.attrs.id : undefined;
|
|
1641
|
+
const tableLabel = dataRefLabel(lookup?.attrs.table_id, TABLE_RESOURCE_TYPE);
|
|
1642
|
+
if (tableLabel !== undefined) {
|
|
1643
|
+
const tableName = ctx.dataBlocks.get(`${TABLE_RESOURCE_TYPE}.${tableLabel}`)?.attrs.name;
|
|
1644
|
+
const parentName = typeof tableName === "string" && tableName !== "" ? tableName : undefined;
|
|
1645
|
+
const parent = parentName !== undefined ? tfLabelToTsLabel(sanitizeName(parentName)) : tfLabelToTsLabel(tableLabel);
|
|
1646
|
+
return {
|
|
1647
|
+
kind: "searchTable",
|
|
1648
|
+
appHandle: parent,
|
|
1649
|
+
tableKey: name !== undefined ? tfLabelToTsLabel(sanitizeName(name)) : value.label,
|
|
1650
|
+
...(name !== undefined ? { name } : {}),
|
|
1651
|
+
...(parentName !== undefined ? { parentName } : {}),
|
|
1652
|
+
...(pinnedId !== undefined ? { id: pinnedId } : {}),
|
|
1653
|
+
ownerKind: "table",
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1316
1656
|
const objectId = lookup?.attrs.object_id ?? lookup?.attrs.aspect_id;
|
|
1317
1657
|
const elementHandle = objectId !== undefined
|
|
1318
1658
|
? aspectOwnerRefNameFromObjectId(objectId, ctx.appRefName, ctx.appTfLabel, ctx.dataBlocks, ctx.foreignAppRefNames, ctx.foreignElementRefNames)
|
|
@@ -1357,7 +1697,17 @@ function decodeSearchTableReference(value, ctx) {
|
|
|
1357
1697
|
}
|
|
1358
1698
|
return { kind: "unresolved", uuid: typeof value === "string" ? value : JSON.stringify(value), hint: "search table" };
|
|
1359
1699
|
}
|
|
1700
|
+
/** A `data.elementum_user` reference pulls as `userRef(email)`; a raw id stays a string, which build refuses. */
|
|
1701
|
+
function userIdDefault(value, ctx) {
|
|
1702
|
+
const decoded = decodeValue(value, ctx);
|
|
1703
|
+
return decoded?.kind === "user" ? decoded : value;
|
|
1704
|
+
}
|
|
1360
1705
|
function decodeValue(value, ctx) {
|
|
1706
|
+
if (ctx.trigger.type === "elementum_attachment_added_trigger") {
|
|
1707
|
+
const payloadKey = parseTriggerAttachmentPayloadRefJson(isTfExpr(value) && value.$expr === "jsonencode" ? JSON.stringify(value.value) : value);
|
|
1708
|
+
if (payloadKey !== undefined)
|
|
1709
|
+
return { kind: "triggerRef", path: ["attachment", payloadKey] };
|
|
1710
|
+
}
|
|
1361
1711
|
if (isTfExpr(value)) {
|
|
1362
1712
|
if (value.$expr === "template") {
|
|
1363
1713
|
return { kind: "template", parts: value.parts.map((part) => typeof part === "string" ? part : decodeValue(part, ctx)) };
|
|
@@ -1376,7 +1726,7 @@ function decodeValue(value, ctx) {
|
|
|
1376
1726
|
return {
|
|
1377
1727
|
kind: "forEachItemRef",
|
|
1378
1728
|
forEachTask: task.refKey,
|
|
1379
|
-
path: forEachItemRefPath(value.path.slice(2), ctx),
|
|
1729
|
+
path: forEachItemRefPath(value.path.slice(2), ctx, task.block),
|
|
1380
1730
|
};
|
|
1381
1731
|
}
|
|
1382
1732
|
if (task !== undefined && value.path[0] === "refs") {
|
|
@@ -1486,7 +1836,7 @@ function decodeValue(value, ctx) {
|
|
|
1486
1836
|
return {
|
|
1487
1837
|
kind: "field",
|
|
1488
1838
|
appHandle: ctx.appRefName,
|
|
1489
|
-
fieldKey:
|
|
1839
|
+
fieldKey: fieldBagKey(value.label, ctx),
|
|
1490
1840
|
};
|
|
1491
1841
|
}
|
|
1492
1842
|
if (value.type === AUTOMATION_RESOURCE_TYPE && value.path[0] === "id") {
|
|
@@ -1497,13 +1847,13 @@ function decodeValue(value, ctx) {
|
|
|
1497
1847
|
};
|
|
1498
1848
|
}
|
|
1499
1849
|
if (value.type === "elementum_agent" && value.path[0] === "id") {
|
|
1500
|
-
return { kind: "agent", appHandle: ctx.appRefName, agentKey: scopedLabelToBagKey(ctx.appTfLabel, value.label), name: value.label };
|
|
1850
|
+
return { kind: "agent", appHandle: ctx.appRefName, agentKey: scopedLabelToBagKey(ctx.appTfLabel, value.label, ctx.ownerScope), name: value.label };
|
|
1501
1851
|
}
|
|
1502
1852
|
if (value.type === "elementum_phone_service" && value.path[0] === "id") {
|
|
1503
1853
|
return {
|
|
1504
1854
|
kind: "phoneService",
|
|
1505
1855
|
appHandle: ctx.appRefName,
|
|
1506
|
-
phoneServiceKey: scopedLabelToBagKey(ctx.appTfLabel, value.label),
|
|
1856
|
+
phoneServiceKey: scopedLabelToBagKey(ctx.appTfLabel, value.label, ctx.ownerScope),
|
|
1507
1857
|
};
|
|
1508
1858
|
}
|
|
1509
1859
|
if (value.type === TABLE_RESOURCE_TYPE && value.path[0] === "id") {
|
|
@@ -1541,7 +1891,7 @@ function decodeValue(value, ctx) {
|
|
|
1541
1891
|
return {
|
|
1542
1892
|
kind: "documentModel",
|
|
1543
1893
|
appHandle: ctx.appRefName,
|
|
1544
|
-
documentModelKey: scopedLabelToBagKey(ctx.appTfLabel, value.label),
|
|
1894
|
+
documentModelKey: scopedLabelToBagKey(ctx.appTfLabel, value.label, ctx.ownerScope),
|
|
1545
1895
|
};
|
|
1546
1896
|
}
|
|
1547
1897
|
if (value.type === "elementum_approval_process" && value.path[0] === "id") {
|
|
@@ -1552,7 +1902,7 @@ function decodeValue(value, ctx) {
|
|
|
1552
1902
|
return {
|
|
1553
1903
|
kind: "approvalChain",
|
|
1554
1904
|
appHandle: ctx.appRefName,
|
|
1555
|
-
approvalChainKey: scopedLabelToBagKey(ctx.appTfLabel, value.label),
|
|
1905
|
+
approvalChainKey: scopedLabelToBagKey(ctx.appTfLabel, value.label, ctx.ownerScope),
|
|
1556
1906
|
};
|
|
1557
1907
|
}
|
|
1558
1908
|
if ((value.type === SEARCH_TABLE_RESOURCE_TYPES.snowflake ||
|
|
@@ -1603,11 +1953,13 @@ function decodeValue(value, ctx) {
|
|
|
1603
1953
|
const mappedHandle = typeof name === "string"
|
|
1604
1954
|
? (value.type === "elementum_task" ? ctx.foreignTaskRefNames : value.type === "elementum_element" ? ctx.foreignElementRefNames : ctx.foreignAppRefNames)?.get(name)
|
|
1605
1955
|
: undefined;
|
|
1956
|
+
const namespace = lookup?.attrs.namespace;
|
|
1606
1957
|
return {
|
|
1607
1958
|
kind: "app",
|
|
1608
1959
|
appHandle: mappedHandle ?? tfLabelToTsLabel(value.label),
|
|
1609
1960
|
entityType: value.type === "elementum_task" ? "task" : value.type === "elementum_element" ? "element" : "app",
|
|
1610
1961
|
...(typeof name === "string" ? { name } : {}),
|
|
1962
|
+
...(typeof namespace === "string" && namespace !== "" ? { namespace } : {}),
|
|
1611
1963
|
};
|
|
1612
1964
|
}
|
|
1613
1965
|
if (value.$expr === "data-attr" && value.type === AUTOMATION_RESOURCE_TYPE && value.path[0] === "id") {
|
|
@@ -1746,6 +2098,31 @@ function decodeValue(value, ctx) {
|
|
|
1746
2098
|
}
|
|
1747
2099
|
return { kind: "user", email };
|
|
1748
2100
|
}
|
|
2101
|
+
if (value.$expr === "data-attr" && value.type === "elementum_vault_entry" && value.path[0] === "value_reference") {
|
|
2102
|
+
const key = ctx.dataBlocks.get(`${value.type}.${value.label}`)?.attrs.key;
|
|
2103
|
+
if (typeof key !== "string" || key === "") {
|
|
2104
|
+
throw new EntityTfError(`data.elementum_vault_entry.${value.label}: key lookup is missing`);
|
|
2105
|
+
}
|
|
2106
|
+
return { kind: "secret", key };
|
|
2107
|
+
}
|
|
2108
|
+
if (value.$expr === "data-attr" && value.type === "elementum_group" && value.path[0] === "id") {
|
|
2109
|
+
// Static notification/add-watcher recipients (edk#1389). The export
|
|
2110
|
+
// labels recipient lookups by id, so the org.groups key is the one
|
|
2111
|
+
// org.ts assigned this name (edk#1412), else the name's sanitized key,
|
|
2112
|
+
// the way `pull org` derives it.
|
|
2113
|
+
const name = ctx.dataBlocks.get(`${value.type}.${value.label}`)?.attrs.name;
|
|
2114
|
+
if (typeof name !== "string" || name === "") {
|
|
2115
|
+
throw new EntityTfError(`data.elementum_group.${value.label}: name lookup is missing`);
|
|
2116
|
+
}
|
|
2117
|
+
const groupKey = ctx.groupKeysByName?.get(name) ?? tfLabelToTsLabel(sanitizeName(name));
|
|
2118
|
+
return { kind: "orgGroup", groupKey, name };
|
|
2119
|
+
}
|
|
2120
|
+
if (value.$expr === "variable") {
|
|
2121
|
+
if (value.path.length !== 0) {
|
|
2122
|
+
throw new EntityTfError(`unsupported variable reference var.${value.name}`);
|
|
2123
|
+
}
|
|
2124
|
+
return { kind: "requiredSecret", variable: value.name };
|
|
2125
|
+
}
|
|
1749
2126
|
if (value.$expr === "local") {
|
|
1750
2127
|
const stageName = stageFilterName(value, ctx);
|
|
1751
2128
|
if (stageName !== undefined)
|
|
@@ -1813,14 +2190,35 @@ function decodeCustomResponse(value, ctx) {
|
|
|
1813
2190
|
return undefined;
|
|
1814
2191
|
return { ...(success !== undefined ? { success } : {}), ...(failure !== undefined ? { failure } : {}) };
|
|
1815
2192
|
}
|
|
2193
|
+
/**
|
|
2194
|
+
* The managed bag key for a ref-only field lookup, matched on display name
|
|
2195
|
+
* and owner. Managed entries name the owner by its catalog ref or, when
|
|
2196
|
+
* bootstrapped from state, by the camelCase of its tf label (#1431).
|
|
2197
|
+
*/
|
|
2198
|
+
function managedFieldKeyForDisplayName(foreign, ctx) {
|
|
2199
|
+
if (foreign.fieldName === undefined)
|
|
2200
|
+
return undefined;
|
|
2201
|
+
const lower = foreign.fieldName.toLowerCase();
|
|
2202
|
+
const owners = new Set([foreign.ownerRefName]);
|
|
2203
|
+
if (foreign.ownerNamespace !== undefined && isTfLabel(foreign.ownerNamespace))
|
|
2204
|
+
owners.add(tfLabelToTsLabel(foreign.ownerNamespace));
|
|
2205
|
+
const keys = new Set();
|
|
2206
|
+
for (const [id, identity] of ctx.foreignFieldRefsById ?? []) {
|
|
2207
|
+
if (id.startsWith("refOnly:") || !owners.has(identity.ownerRefName) || identity.fieldName?.toLowerCase() !== lower)
|
|
2208
|
+
continue;
|
|
2209
|
+
keys.add(identity.fieldKey);
|
|
2210
|
+
}
|
|
2211
|
+
return keys.size === 1 ? keys.values().next().value : undefined;
|
|
2212
|
+
}
|
|
1816
2213
|
function fieldRef(value, ctx) {
|
|
1817
2214
|
if (isTfExpr(value) && value.$expr === "data-attr" && value.path.join(".") === "id") {
|
|
1818
2215
|
const foreign = ctx.foreignFieldRefsByDataAddress?.get(`${value.type}.${value.label}`);
|
|
1819
2216
|
if (foreign !== undefined) {
|
|
2217
|
+
const fieldKey = managedFieldKeyForDisplayName(foreign, ctx) ?? foreign.fieldKey;
|
|
1820
2218
|
return {
|
|
1821
2219
|
kind: "field",
|
|
1822
2220
|
appHandle: foreign.ownerRefName,
|
|
1823
|
-
fieldKey
|
|
2221
|
+
fieldKey,
|
|
1824
2222
|
...(foreign.ownerKind !== undefined || foreign.fieldName !== undefined || foreign.fieldType !== undefined
|
|
1825
2223
|
? {
|
|
1826
2224
|
foreign: {
|
|
@@ -1845,11 +2243,12 @@ function fieldRef(value, ctx) {
|
|
|
1845
2243
|
kind: "field",
|
|
1846
2244
|
appHandle: foreign.ownerRefName,
|
|
1847
2245
|
fieldKey: foreign.fieldKey,
|
|
1848
|
-
...(foreign.fieldName !== undefined || foreign.fieldType !== undefined
|
|
2246
|
+
...(foreign.ownerKind !== undefined || foreign.fieldName !== undefined || foreign.fieldType !== undefined
|
|
1849
2247
|
? {
|
|
1850
2248
|
foreign: {
|
|
1851
|
-
entityType: "app",
|
|
1852
|
-
name: foreign.ownerRefName,
|
|
2249
|
+
entityType: foreign.ownerKind ?? "app",
|
|
2250
|
+
name: foreign.ownerName ?? foreign.ownerRefName,
|
|
2251
|
+
...(foreign.ownerNamespace !== undefined ? { namespace: foreign.ownerNamespace } : {}),
|
|
1853
2252
|
...(foreign.fieldName !== undefined ? { fieldName: foreign.fieldName } : {}),
|
|
1854
2253
|
...(foreign.fieldType !== undefined ? { fieldType: foreign.fieldType } : {}),
|
|
1855
2254
|
},
|
|
@@ -2144,16 +2543,13 @@ function pulledRawCalculation(formula, outputType, multiple) {
|
|
|
2144
2543
|
return resultType === undefined ? undefined : { kind: "calculationRaw", text: formula, resultType };
|
|
2145
2544
|
}
|
|
2146
2545
|
function resolveVariableReference(rawId, rawName, outputName, ctx) {
|
|
2546
|
+
// One candidate per created variable (edk#1456: a task can create several).
|
|
2147
2547
|
const variableTasks = [];
|
|
2148
2548
|
for (const [, task] of ctx.taskByAddress) {
|
|
2149
2549
|
if (task.block.type === "elementum_variable_task") {
|
|
2150
|
-
const
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
const varId = typeof task.block.attrs.variable_id === "string"
|
|
2154
|
-
? task.block.attrs.variable_id
|
|
2155
|
-
: undefined;
|
|
2156
|
-
variableTasks.push({ refKey: task.refKey, varName, varId });
|
|
2550
|
+
for (const entry of variableTaskEntries(task.block)) {
|
|
2551
|
+
variableTasks.push({ refKey: task.refKey, varName: entry.name, ...(entry.id !== undefined ? { varId: entry.id } : {}) });
|
|
2552
|
+
}
|
|
2157
2553
|
}
|
|
2158
2554
|
}
|
|
2159
2555
|
if (variableTasks.length === 0)
|
|
@@ -2180,8 +2576,8 @@ function resolveVariableReference(rawId, rawName, outputName, ctx) {
|
|
|
2180
2576
|
}
|
|
2181
2577
|
}
|
|
2182
2578
|
// 4. The variable's real platform id is Computed on the provider, so the
|
|
2183
|
-
// static `variable_task` block does not carry `
|
|
2184
|
-
// in an EDK-only `
|
|
2579
|
+
// static `variable_task` block does not carry `variables[*].id`. Export puts them
|
|
2580
|
+
// in an EDK-only `edk_variable_ids_<label>` local (hydrated onto the block
|
|
2185
2581
|
// before this resolver runs). Without that, a workflow OUTPUT's
|
|
2186
2582
|
// `variableReference.name` is the synthetic "variable|<uuid>" placeholder,
|
|
2187
2583
|
// and #2/#3's name-based matches routinely
|
|
@@ -2193,6 +2589,7 @@ function resolveVariableReference(rawId, rawName, outputName, ctx) {
|
|
|
2193
2589
|
// "variable.<uuid>" is a DIFFERENT wire dialect with no such guarantee
|
|
2194
2590
|
// (board issue #171 contract: a filter referencing variable.<uuid> must
|
|
2195
2591
|
// NOT bind to a same-automation variable task).
|
|
2592
|
+
// One candidate means one variable in the whole automation.
|
|
2196
2593
|
if (rawId !== undefined && outputName !== undefined && variableTasks.length === 1) {
|
|
2197
2594
|
const only = variableTasks[0];
|
|
2198
2595
|
return { kind: "variableParamRef", varTask: only.refKey, name: only.varName };
|
|
@@ -2311,8 +2708,31 @@ function filterReferenceType(value, fallback, ctx) {
|
|
|
2311
2708
|
}
|
|
2312
2709
|
return typeof raw.fieldType === "string" ? fieldTypeToValueType(raw.fieldType) : fallback;
|
|
2313
2710
|
}
|
|
2711
|
+
/**
|
|
2712
|
+
* True when a workflow output references an execute-script output whose name
|
|
2713
|
+
* the stored schema lists more than once. Pull keeps the first entry, and
|
|
2714
|
+
* export/provider type the output from it; an older export typed it from the
|
|
2715
|
+
* LAST entry, so its envelope type is not authored intent.
|
|
2716
|
+
*/
|
|
2717
|
+
function referencesRepeatedScriptOutput(value, ctx) {
|
|
2718
|
+
const raw = isTfExpr(value) && value.$expr === "jsonencode" ? value.value : value;
|
|
2719
|
+
if (!isObject(raw) || !isObject(raw.taskReference) || typeof raw.taskReference.name !== "string")
|
|
2720
|
+
return false;
|
|
2721
|
+
const taskIdOrKey = workflowOutputTaskIdOrKey(raw.taskReference.taskId, ctx);
|
|
2722
|
+
const task = taskIdOrKey === undefined ? undefined : resolveTaskRefKey(taskIdOrKey, ctx).block;
|
|
2723
|
+
if (task?.type !== "elementum_execute_script_task")
|
|
2724
|
+
return false;
|
|
2725
|
+
const schemaValue = task.attrs.output_schema;
|
|
2726
|
+
const schema = isTfExpr(schemaValue) && schemaValue.$expr === "jsonencode"
|
|
2727
|
+
? schemaValue.value
|
|
2728
|
+
: schemaValue;
|
|
2729
|
+
return repeatedScriptOutputNames(schema).has(raw.taskReference.name);
|
|
2730
|
+
}
|
|
2314
2731
|
export function inferredPublishOutputType(value, ctx) {
|
|
2315
2732
|
const raw = isTfExpr(value) && value.$expr === "jsonencode" ? value.value : value;
|
|
2733
|
+
if (isObject(raw) && isObject(raw.triggerReference) && typeof raw.triggerReference.name === "string") {
|
|
2734
|
+
return declaredOnDemandInputFieldType(ctx.trigger, raw.triggerReference.name) ?? { fieldType: "TEXT", multiple: false };
|
|
2735
|
+
}
|
|
2316
2736
|
if (!isObject(raw) || !isObject(raw.taskReference) || typeof raw.taskReference.name !== "string") {
|
|
2317
2737
|
return { fieldType: "TEXT", multiple: false };
|
|
2318
2738
|
}
|
|
@@ -2337,6 +2757,16 @@ export function inferredPublishOutputType(value, ctx) {
|
|
|
2337
2757
|
return { fieldType: field.type.toUpperCase(), multiple: false };
|
|
2338
2758
|
}
|
|
2339
2759
|
}
|
|
2760
|
+
// Canonical reference model: a workflow OUTPUT carries the platform's canonical
|
|
2761
|
+
// output name — take fieldType + multiple from the generated service_tasks
|
|
2762
|
+
// contract (the display-name heuristics below remain for legacy deployed HCL).
|
|
2763
|
+
// See DESIGN-canonical-reference-model.md.
|
|
2764
|
+
if (task?.type !== undefined) {
|
|
2765
|
+
const executor = RESOURCE_TYPE_TO_EXECUTOR[task.type];
|
|
2766
|
+
const contract = executor !== undefined ? TASK_OUTPUT_CONTRACTS[executor]?.[raw.taskReference.name] : undefined;
|
|
2767
|
+
if (contract !== undefined)
|
|
2768
|
+
return { fieldType: contract.fieldType, multiple: contract.multiple };
|
|
2769
|
+
}
|
|
2340
2770
|
if ((task?.type === "elementum_create_record_task" || task?.type === "elementum_find_related_records_task") &&
|
|
2341
2771
|
(raw.taskReference.name === "Record" || raw.taskReference.name === "Record ID")) {
|
|
2342
2772
|
return { fieldType: "ASPECT_RECORD_ID", multiple: false };
|
|
@@ -2384,8 +2814,11 @@ function triggerFromBlock(block, ctx) {
|
|
|
2384
2814
|
// no "attachmentId" spelling at all, but the authoring alias
|
|
2385
2815
|
// (onDemand's TriggerFieldTypeAlias) does. Map back so printed
|
|
2386
2816
|
// source uses a type-checkable alias instead of a raw wire string
|
|
2387
|
-
// "attachment" that TriggerFieldTypeAlias doesn't accept.
|
|
2388
|
-
|
|
2817
|
+
// "attachment" that TriggerFieldTypeAlias doesn't accept. The
|
|
2818
|
+
// provider's "user" is USER_ID, authored as "userId".
|
|
2819
|
+
const type = parameter.type === "attachment" ? "attachmentId"
|
|
2820
|
+
: parameter.type === "user" ? "userId"
|
|
2821
|
+
: parameter.type;
|
|
2389
2822
|
const record = type === "record";
|
|
2390
2823
|
const recordApp = record
|
|
2391
2824
|
? aspectRefFromObjectId(parameter.default_value, ctx)
|
|
@@ -2399,7 +2832,9 @@ function triggerFromBlock(block, ctx) {
|
|
|
2399
2832
|
...(recordApp !== undefined ? { app: recordApp } : {}),
|
|
2400
2833
|
...(parameter.required === true ? { required: true } : {}),
|
|
2401
2834
|
...(parameter.multiple === true ? { multiple: true } : {}),
|
|
2402
|
-
...(!record && parameter.default_value !== undefined
|
|
2835
|
+
...(!record && parameter.default_value !== undefined
|
|
2836
|
+
? { defaultValue: type === "userId" ? userIdDefault(parameter.default_value, ctx) : parameter.default_value }
|
|
2837
|
+
: {}),
|
|
2403
2838
|
...(typeof parameter.description === "string" ? { description: parameter.description } : {}),
|
|
2404
2839
|
};
|
|
2405
2840
|
})
|
|
@@ -2500,7 +2935,7 @@ function triggerFromBlock(block, ctx) {
|
|
|
2500
2935
|
default: throw new EntityTfError(`trigger "${kind}" is outside the Terraform contract`);
|
|
2501
2936
|
}
|
|
2502
2937
|
}
|
|
2503
|
-
function taskArgs(block, factory, ctx,
|
|
2938
|
+
function taskArgs(block, factory, ctx, taskDiagnostics) {
|
|
2504
2939
|
const args = {};
|
|
2505
2940
|
for (const [attr, value] of Object.entries(block.attrs)) {
|
|
2506
2941
|
if (attr === "parent" || attr === "name" || attr === "depends_on")
|
|
@@ -2509,7 +2944,7 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2509
2944
|
args.filter = decodeFilter(value, ctx, FILTER_FIELD_SCOPE_BY_FACTORY[factory] ?? "app");
|
|
2510
2945
|
continue;
|
|
2511
2946
|
}
|
|
2512
|
-
if (attr === "fields" && (factory === "createRecord" || factory === "updateField")) {
|
|
2947
|
+
if (attr === "fields" && (factory === "createRecord" || factory === "updateField" || factory === "bulkUpdateFields")) {
|
|
2513
2948
|
if (!Array.isArray(value))
|
|
2514
2949
|
throw new EntityTfError(`${block.type}.${block.label}: fields must be an array`);
|
|
2515
2950
|
const values = {};
|
|
@@ -2527,12 +2962,13 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2527
2962
|
const fieldKey = field.kind === "field"
|
|
2528
2963
|
? field.fieldKey
|
|
2529
2964
|
: `${UNRESOLVED_FIELD_MARKER}${field.uuid}`;
|
|
2530
|
-
const decodedValue = decodeFieldAssignmentValue(item.value, ctx);
|
|
2965
|
+
const decodedValue = decodeFieldAssignmentValue(item.value, ctx, taskDiagnostics, `${block.type}.${block.label} field ${field.kind === "field" ? field.fieldKey : field.uuid}`);
|
|
2531
2966
|
const foreignInfo = field.kind === "field" && field.foreign !== undefined
|
|
2532
2967
|
? {
|
|
2533
2968
|
foreignFieldName: field.foreign.fieldName,
|
|
2534
2969
|
foreignEntityType: field.foreign.entityType,
|
|
2535
2970
|
foreignOwnerName: field.foreign.name,
|
|
2971
|
+
...(field.foreign.namespace !== undefined ? { foreignOwnerNamespace: field.foreign.namespace } : {}),
|
|
2536
2972
|
...(field.foreign.fieldType !== undefined ? { foreignFieldType: field.foreign.fieldType } : {}),
|
|
2537
2973
|
}
|
|
2538
2974
|
: undefined;
|
|
@@ -2573,7 +3009,7 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2573
3009
|
// throwing out of taskArgs, which would drop the WHOLE automation
|
|
2574
3010
|
// (a live-caught regression in an earlier attempt at this fix).
|
|
2575
3011
|
if (mapping.field_id === undefined) {
|
|
2576
|
-
|
|
3012
|
+
taskDiagnostics.push(`execute-script input "${item.name}" field_mappings entry ${JSON.stringify(mapping.alias)}: no field_id on the platform; dropped`);
|
|
2577
3013
|
continue;
|
|
2578
3014
|
}
|
|
2579
3015
|
// A PRESENT but unreconstructable field_id (fieldRef throws) is
|
|
@@ -2584,7 +3020,15 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2584
3020
|
fields.push({ alias: mapping.alias, field: fieldRef(mapping.field_id, ctx) });
|
|
2585
3021
|
}
|
|
2586
3022
|
if (fields.length > 0) {
|
|
2587
|
-
|
|
3023
|
+
// A record trigger's whole record exports as its reference JSON,
|
|
3024
|
+
// because refs["Record"] is the record ID (edk#1284). Field
|
|
3025
|
+
// mappings make it `ctx.trigger.record` again; build restores
|
|
3026
|
+
// the JSON (TRIGGER_WHOLE_RECORD_MARKER).
|
|
3027
|
+
const wholeRecord = parseTriggerWholeRecordRefJson(item.value);
|
|
3028
|
+
const value = wholeRecord === TRIGGER_WHOLE_RECORD_REF_NAME && ctx.trigger.type !== "elementum_on_demand_trigger"
|
|
3029
|
+
? { kind: "triggerRef", path: [TRIGGER_WHOLE_RECORD_REF_NAME] }
|
|
3030
|
+
: decodedValue;
|
|
3031
|
+
return [item.name, { __edkExecuteScriptListInput: true, value, fields }];
|
|
2588
3032
|
}
|
|
2589
3033
|
}
|
|
2590
3034
|
return [item.name, decodedValue];
|
|
@@ -2595,7 +3039,54 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2595
3039
|
const raw = isTfExpr(value) && value.$expr === "jsonencode" ? value.value : value;
|
|
2596
3040
|
const root = isObject(raw) && isObject(raw.object) ? raw.object : undefined;
|
|
2597
3041
|
const props = Array.isArray(root?.properties) ? root.properties : [];
|
|
2598
|
-
|
|
3042
|
+
// Export and import collapse an identical repeat of a property, but keep
|
|
3043
|
+
// a name listed twice with different shapes. The public `outputs`
|
|
3044
|
+
// option is keyed by name and cannot carry the repeat, so keep the
|
|
3045
|
+
// FIRST occurrence (position and type) and report the collapse: the
|
|
3046
|
+
// rebuilt schema no longer matches live. The provider refreshes
|
|
3047
|
+
// output_schema on every Read, so the next plan shows the in-place
|
|
3048
|
+
// update and applying it removes the repeat. outputFieldTypesFromScriptSchema
|
|
3049
|
+
// resolves a repeated name to the same first entry, so ref typing and
|
|
3050
|
+
// workflow-output inference agree with the pulled `outputs`.
|
|
3051
|
+
const decodeProperties = (nodes, path) => {
|
|
3052
|
+
const nested = path !== "root";
|
|
3053
|
+
// A Map, not `{}`: a platform property named `__proto__` assigned onto
|
|
3054
|
+
// a plain object hits the legacy prototype setter and is dropped (or,
|
|
3055
|
+
// object-shaped, becomes the prototype). Object.fromEntries below
|
|
3056
|
+
// defines every name, `__proto__` included, as an own key.
|
|
3057
|
+
const properties = new Map();
|
|
3058
|
+
const kept = new Map();
|
|
3059
|
+
const repeats = new Map();
|
|
3060
|
+
for (const node of nodes) {
|
|
3061
|
+
if (!isObject(node)) {
|
|
3062
|
+
throw new EntityTfError(nested ? "invalid nested script output property" : "invalid script output schema");
|
|
3063
|
+
}
|
|
3064
|
+
const [type, definition] = Object.entries(node)[0] ?? [];
|
|
3065
|
+
if (type === undefined || !isObject(definition) || typeof definition.name !== "string") {
|
|
3066
|
+
throw new EntityTfError(nested ? "nested script output property requires a name" : "invalid script output property");
|
|
3067
|
+
}
|
|
3068
|
+
const decoded = decodeNode(node, `${path}.${definition.name}`);
|
|
3069
|
+
if (properties.has(definition.name)) {
|
|
3070
|
+
const differs = JSON.stringify(decoded) !== JSON.stringify(properties.get(definition.name));
|
|
3071
|
+
repeats.set(definition.name, [...(repeats.get(definition.name) ?? []), { node, differs }]);
|
|
3072
|
+
continue;
|
|
3073
|
+
}
|
|
3074
|
+
properties.set(definition.name, decoded);
|
|
3075
|
+
kept.set(definition.name, node);
|
|
3076
|
+
}
|
|
3077
|
+
for (const [name, dropped] of repeats) {
|
|
3078
|
+
const droppedShapes = dropped.map(({ node, differs }) => `${describeScriptOutputNode(node)} (${differs ? "differs from" : "identical to"} the kept shape)`);
|
|
3079
|
+
taskDiagnostics.push(`${block.type}.${block.label}: output_schema ${path} lists duplicate property ${JSON.stringify(name)} ` +
|
|
3080
|
+
`${dropped.length + 1} times; outputs is keyed by name, so pulled source keeps only the first, ` +
|
|
3081
|
+
`${describeScriptOutputNode(kept.get(name))}, and drops the later ` +
|
|
3082
|
+
`entr${dropped.length === 1 ? "y" : "ies"} ${droppedShapes.join(", ")} - ` +
|
|
3083
|
+
`the provider reads the live schema, so the next plan updates this task's output_schema in place, ` +
|
|
3084
|
+
`and applying it removes the repeat from the automation's draft; the published workflow keeps it until ` +
|
|
3085
|
+
`the automation's revision is bumped and republished`);
|
|
3086
|
+
}
|
|
3087
|
+
return Object.fromEntries(properties);
|
|
3088
|
+
};
|
|
3089
|
+
const decodeNode = (node, path) => {
|
|
2599
3090
|
if (!isObject(node))
|
|
2600
3091
|
throw new EntityTfError("invalid script output schema node");
|
|
2601
3092
|
const [type, definition] = Object.entries(node)[0] ?? [];
|
|
@@ -2608,34 +3099,18 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2608
3099
|
: undefined;
|
|
2609
3100
|
return {
|
|
2610
3101
|
type: "array",
|
|
2611
|
-
items: decodeNode(definition.item),
|
|
3102
|
+
items: decodeNode(definition.item, `${path}[]`),
|
|
2612
3103
|
...(itemName !== undefined ? { itemName } : {}),
|
|
2613
3104
|
};
|
|
2614
3105
|
}
|
|
2615
3106
|
if (type === "object" && Array.isArray(definition.properties)) {
|
|
2616
|
-
|
|
2617
|
-
if (!isObject(child))
|
|
2618
|
-
throw new EntityTfError("invalid nested script output property");
|
|
2619
|
-
const childDefinition = Object.values(child)[0];
|
|
2620
|
-
if (!isObject(childDefinition) || typeof childDefinition.name !== "string") {
|
|
2621
|
-
throw new EntityTfError("nested script output property requires a name");
|
|
2622
|
-
}
|
|
2623
|
-
return [childDefinition.name, decodeNode(child)];
|
|
2624
|
-
}));
|
|
2625
|
-
return { type: "object", properties };
|
|
3107
|
+
return { type: "object", properties: decodeProperties(definition.properties, path) };
|
|
2626
3108
|
}
|
|
2627
3109
|
if (type === "string")
|
|
2628
3110
|
return scriptOutputScalarFromStringNode(definition);
|
|
2629
3111
|
return type === "bool" ? "boolean" : type;
|
|
2630
3112
|
};
|
|
2631
|
-
const properties =
|
|
2632
|
-
if (!isObject(property))
|
|
2633
|
-
throw new EntityTfError("invalid script output schema");
|
|
2634
|
-
const definition = Object.values(property)[0];
|
|
2635
|
-
if (!isObject(definition) || typeof definition.name !== "string")
|
|
2636
|
-
throw new EntityTfError("invalid script output property");
|
|
2637
|
-
return [definition.name, decodeNode(property)];
|
|
2638
|
-
}));
|
|
3113
|
+
const properties = decodeProperties(props, "root");
|
|
2639
3114
|
// The root object's own name is inert to the platform but real stored
|
|
2640
3115
|
// data, so carry it through rather than rebuilding a schema that
|
|
2641
3116
|
// differs from the one just read.
|
|
@@ -2662,7 +3137,14 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2662
3137
|
parameter.path[1] !== null &&
|
|
2663
3138
|
"index" in parameter.path[1] &&
|
|
2664
3139
|
typeof parameter.path[1].index === "string") {
|
|
2665
|
-
|
|
3140
|
+
const name = parameter.path[1].index;
|
|
3141
|
+
const mismatch = inputMappingOwnerMismatch(block, parameter, ctx);
|
|
3142
|
+
if (mismatch !== undefined) {
|
|
3143
|
+
taskDiagnostics.push(`${block.type}.${block.label}: input mapping ${JSON.stringify(name)} names ${mismatch.parameterOwner}'s parameter, ` +
|
|
3144
|
+
`but the task targets ${mismatch.target}; pulled source maps ${JSON.stringify(name)} by name on the target, ` +
|
|
3145
|
+
"so build will not reproduce the exported mapping");
|
|
3146
|
+
}
|
|
3147
|
+
return { name, value: decodeValue(item.value, ctx) };
|
|
2666
3148
|
}
|
|
2667
3149
|
// ei emits bare platform parameter UUIDs when the target automation's
|
|
2668
3150
|
// onDemand trigger is not in this export (foreign / undiscovered).
|
|
@@ -2680,6 +3162,17 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2680
3162
|
});
|
|
2681
3163
|
continue;
|
|
2682
3164
|
}
|
|
3165
|
+
if (attr === "output_mappings" && factory === "runAutomation") {
|
|
3166
|
+
if (!Array.isArray(value))
|
|
3167
|
+
throw new EntityTfError(`${block.type}.${block.label}: output_mappings must be an array`);
|
|
3168
|
+
args.outputs = value.map((item) => {
|
|
3169
|
+
if (!isObject(item) || typeof item.name !== "string") {
|
|
3170
|
+
throw new EntityTfError(`${block.type}.${block.label}: invalid output mapping`);
|
|
3171
|
+
}
|
|
3172
|
+
return item.name;
|
|
3173
|
+
});
|
|
3174
|
+
continue;
|
|
3175
|
+
}
|
|
2683
3176
|
// `file_reader_id` resolves to a real `documentModel` RefExpr only
|
|
2684
3177
|
// through decodeValue's resource-attr branch (an implemented reader
|
|
2685
3178
|
// type's own resource block in this export). When ei instead emits a
|
|
@@ -2813,7 +3306,7 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2813
3306
|
continue;
|
|
2814
3307
|
}
|
|
2815
3308
|
if (attr === "list" && factory === "forEach") {
|
|
2816
|
-
args.collection =
|
|
3309
|
+
args.collection = decodeValueOrStringifiedRef(value, ctx, taskDiagnostics, `${block.type}.${block.label} list`);
|
|
2817
3310
|
continue;
|
|
2818
3311
|
}
|
|
2819
3312
|
if (attr === "code" && factory === "executeScript") {
|
|
@@ -2894,7 +3387,7 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2894
3387
|
// the wire (relate_to_record_reference) - its presence alone implies
|
|
2895
3388
|
// relateToRecord: true (the provider has no separate boolean attribute).
|
|
2896
3389
|
if (attr === "relate_to_record_reference" && factory === "createRecord") {
|
|
2897
|
-
args.record =
|
|
3390
|
+
args.record = decodeValueOrStringifiedRef(value, ctx, taskDiagnostics, `${block.type}.${block.label} relate_to_record_reference`);
|
|
2898
3391
|
args.relateToRecord = true;
|
|
2899
3392
|
continue;
|
|
2900
3393
|
}
|
|
@@ -2920,11 +3413,25 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2920
3413
|
if (!isObject(value))
|
|
2921
3414
|
throw new EntityTfError(`${block.type}.${block.label}: basic_auth must be an object`);
|
|
2922
3415
|
args.basicAuth = {
|
|
2923
|
-
|
|
3416
|
+
// reference_username is a vault-bound username; it authors back as
|
|
3417
|
+
// username: secret("KEY") (edk#1283).
|
|
3418
|
+
username: decodeValue((value.reference_username ?? value.username_wo ?? value.username), ctx),
|
|
2924
3419
|
...(value.reference_password !== undefined ? { referencePassword: decodeValue(value.reference_password, ctx) } : {}),
|
|
2925
3420
|
};
|
|
2926
3421
|
continue;
|
|
2927
3422
|
}
|
|
3423
|
+
if (attr === "headers" && factory === "apiRequest" && Array.isArray(value)) {
|
|
3424
|
+
// value_wo (write-only, edk#1400) authors back as the header's value.
|
|
3425
|
+
args.headers = value.map((h) => {
|
|
3426
|
+
if (!isObject(h))
|
|
3427
|
+
throw new EntityTfError(`${block.type}.${block.label}: invalid header`);
|
|
3428
|
+
return {
|
|
3429
|
+
name: decodeValue(h.name, ctx),
|
|
3430
|
+
value: decodeValue((h.value_wo ?? h.value), ctx),
|
|
3431
|
+
};
|
|
3432
|
+
});
|
|
3433
|
+
continue;
|
|
3434
|
+
}
|
|
2928
3435
|
if (attr === "bearer_auth" && factory === "apiRequest") {
|
|
2929
3436
|
if (!isObject(value))
|
|
2930
3437
|
throw new EntityTfError(`${block.type}.${block.label}: bearer_auth must be an object`);
|
|
@@ -2947,8 +3454,14 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
2947
3454
|
args.oauth = {
|
|
2948
3455
|
requestType: value.request_type,
|
|
2949
3456
|
...(value.url !== undefined ? { url: decodeValue(value.url, ctx) } : {}),
|
|
2950
|
-
|
|
2951
|
-
|
|
3457
|
+
// reference_client_id/reference_client_secret are vault-bound and
|
|
3458
|
+
// author back as secret("KEY") (edk#1283).
|
|
3459
|
+
...(value.reference_client_id !== undefined
|
|
3460
|
+
? { clientId: decodeValue(value.reference_client_id, ctx) }
|
|
3461
|
+
: value.client_id !== undefined ? { clientId: value.client_id } : {}),
|
|
3462
|
+
...(value.reference_client_secret !== undefined
|
|
3463
|
+
? { clientSecret: decodeValue(value.reference_client_secret, ctx) }
|
|
3464
|
+
: value.client_secret !== undefined ? { clientSecret: value.client_secret } : {}),
|
|
2952
3465
|
...(headers !== undefined ? { headers } : {}),
|
|
2953
3466
|
};
|
|
2954
3467
|
continue;
|
|
@@ -3007,9 +3520,11 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
3007
3520
|
continue;
|
|
3008
3521
|
}
|
|
3009
3522
|
const arg = ATTR_TO_ARG[attr] ?? attr.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
3010
|
-
args[arg] =
|
|
3523
|
+
args[arg] = (attr === "record_reference" || attr === "record_id") && (factory === "createRecord" || factory === "updateField")
|
|
3524
|
+
? decodeValueOrStringifiedRef(value, ctx, taskDiagnostics, `${block.type}.${block.label} ${attr}`)
|
|
3525
|
+
: decodeValue(value, ctx);
|
|
3011
3526
|
}
|
|
3012
|
-
if (["recordSearch", "createRecord", "updateField"].includes(factory))
|
|
3527
|
+
if (["recordSearch", "createRecord", "updateField", "bulkUpdateFields"].includes(factory))
|
|
3013
3528
|
args.app ??= appRef(ctx.appRefName);
|
|
3014
3529
|
if (factory === "findRelatedRecords") {
|
|
3015
3530
|
args.relatedApp = args.app ?? appRef(ctx.appRefName);
|
|
@@ -3028,15 +3543,28 @@ function taskArgs(block, factory, ctx, fieldMappingDiagnostics) {
|
|
|
3028
3543
|
}
|
|
3029
3544
|
}
|
|
3030
3545
|
if (factory === "setVariable") {
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3546
|
+
// edk#1456: elementum_variable_task carries `variables` (creates) and
|
|
3547
|
+
// optionally `updates`; elementum_update_variable_task carries `updates`.
|
|
3548
|
+
// The provider's update attribute is variable_reference; the AST/authoring
|
|
3549
|
+
// key stays "variable" (SetVariableOptions.update[].variable).
|
|
3550
|
+
const create = block.type === "elementum_variable_task"
|
|
3551
|
+
? variableTaskEntries(block).map((entry) => ({
|
|
3552
|
+
name: entry.name,
|
|
3553
|
+
type: entry.type,
|
|
3554
|
+
...(entry.value !== undefined ? { value: decodeValue(entry.value, ctx) } : {}),
|
|
3555
|
+
}))
|
|
3556
|
+
: [];
|
|
3557
|
+
if (block.type === "elementum_variable_task" && create.length === 0)
|
|
3558
|
+
throw new EntityTfError("variable task is incomplete");
|
|
3559
|
+
const rawUpdates = Array.isArray(block.attrs.updates) ? block.attrs.updates : [];
|
|
3560
|
+
const update = rawUpdates.map((item) => {
|
|
3561
|
+
if (!isObject(item))
|
|
3562
|
+
throw new EntityTfError("variable task update is incomplete");
|
|
3563
|
+
return { variable: decodeValue(item.variable_reference, ctx), value: decodeValue(item.value, ctx) };
|
|
3564
|
+
});
|
|
3565
|
+
if (create.length === 0 && update.length === 0)
|
|
3566
|
+
throw new EntityTfError("update variable task is incomplete");
|
|
3567
|
+
return { ...(create.length > 0 ? { create } : {}), ...(update.length > 0 ? { update } : {}) };
|
|
3040
3568
|
}
|
|
3041
3569
|
return args;
|
|
3042
3570
|
}
|
|
@@ -3111,12 +3639,11 @@ function taskRefKey(block, automationLabel, appTfLabel) {
|
|
|
3111
3639
|
// keys them by the variable they create. Restrict this reconciliation to
|
|
3112
3640
|
// that positional export shape: named tasks such as "set_variable_task"
|
|
3113
3641
|
// remain valid action identities used by workflow outputs.
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
block.attrs.variable_name !== "" &&
|
|
3642
|
+
const soleVariable = soleVariableName(block);
|
|
3643
|
+
if (soleVariable !== undefined &&
|
|
3117
3644
|
/(?:\s|-)\d+$/.test(taskName.trim()) &&
|
|
3118
3645
|
(sanitized === tail || sanitized === `_${tail}`)) {
|
|
3119
|
-
return
|
|
3646
|
+
return soleVariable;
|
|
3120
3647
|
}
|
|
3121
3648
|
// ei sanitizes `<automation>_<task>` as ONE combined string
|
|
3122
3649
|
// (imports.go), so the digit-leading guard only ever sees the
|
|
@@ -3144,8 +3671,10 @@ function taskRefKey(block, automationLabel, appTfLabel) {
|
|
|
3144
3671
|
* driving spurious destroys). Deliberately lenient - tolerant of the exact
|
|
3145
3672
|
* conditions that make real extraction fail (zero triggers, an
|
|
3146
3673
|
* unrecognized task kind) so it over-collects rather than under-collects.
|
|
3147
|
-
* More than one trigger
|
|
3148
|
-
*
|
|
3674
|
+
* More than one trigger throws {@link UnsupportedMultiTriggerError}. The
|
|
3675
|
+
* stream extractor records that as a fatal validation, excludes these
|
|
3676
|
+
* addresses, and continues so every multi-trigger automation is reported.
|
|
3677
|
+
* A false positive
|
|
3149
3678
|
* here just leaves one more resource unmanaged; a false negative would
|
|
3150
3679
|
* silently destroy a live automation on apply.
|
|
3151
3680
|
*/
|
|
@@ -3153,7 +3682,8 @@ export function automationOwnedAddresses(doc, automationLabel) {
|
|
|
3153
3682
|
const owned = new Set([`${AUTOMATION_RESOURCE_TYPE}.${automationLabel}`]);
|
|
3154
3683
|
for (const block of doc.blocks) {
|
|
3155
3684
|
if (block.kind === "resource" && block.type !== undefined && block.label !== undefined &&
|
|
3156
|
-
references(block.attrs.automation, AUTOMATION_RESOURCE_TYPE, automationLabel)
|
|
3685
|
+
(references(block.attrs.automation, AUTOMATION_RESOURCE_TYPE, automationLabel) ||
|
|
3686
|
+
references(block.attrs.automation_id, AUTOMATION_RESOURCE_TYPE, automationLabel))) {
|
|
3157
3687
|
owned.add(`${block.type}.${block.label}`);
|
|
3158
3688
|
}
|
|
3159
3689
|
}
|
|
@@ -3175,30 +3705,128 @@ export function automationOwnedAddresses(doc, automationLabel) {
|
|
|
3175
3705
|
}
|
|
3176
3706
|
return [...owned];
|
|
3177
3707
|
}
|
|
3178
|
-
const
|
|
3179
|
-
/** Pull-only: computed
|
|
3708
|
+
const EDK_VARIABLE_IDS_LOCAL_PREFIX = "edk_variable_ids_";
|
|
3709
|
+
/** Pull-only: the computed variables[*].id cannot live on the resource config. */
|
|
3180
3710
|
function exportedVariableIdsByTaskLabel(doc) {
|
|
3181
3711
|
const ids = new Map();
|
|
3182
3712
|
for (const block of doc.blocks) {
|
|
3183
3713
|
if (block.kind !== "locals")
|
|
3184
3714
|
continue;
|
|
3185
3715
|
for (const [key, value] of Object.entries(block.attrs)) {
|
|
3186
|
-
if (key.startsWith(
|
|
3187
|
-
ids.set(key.slice(
|
|
3716
|
+
if (key.startsWith(EDK_VARIABLE_IDS_LOCAL_PREFIX) && Array.isArray(value)) {
|
|
3717
|
+
ids.set(key.slice(EDK_VARIABLE_IDS_LOCAL_PREFIX.length), value.map((id) => (typeof id === "string" ? id : "")));
|
|
3188
3718
|
}
|
|
3189
3719
|
}
|
|
3190
3720
|
}
|
|
3191
3721
|
return ids;
|
|
3192
3722
|
}
|
|
3723
|
+
/** Hydrates each exported variable id onto its `variables` entry, by position. */
|
|
3193
3724
|
function withExportedVariableId(block, ids) {
|
|
3194
|
-
if (block.type !== "elementum_variable_task" || block.label === undefined)
|
|
3195
|
-
return block;
|
|
3196
|
-
if (typeof block.attrs.variable_id === "string" && block.attrs.variable_id !== "")
|
|
3725
|
+
if (block.type !== "elementum_variable_task" || block.label === undefined || !Array.isArray(block.attrs.variables))
|
|
3197
3726
|
return block;
|
|
3198
3727
|
const exported = ids.get(block.label);
|
|
3199
3728
|
if (exported === undefined)
|
|
3200
3729
|
return block;
|
|
3201
|
-
|
|
3730
|
+
const variables = block.attrs.variables.map((entry, index) => {
|
|
3731
|
+
const id = exported[index];
|
|
3732
|
+
if (!isObject(entry))
|
|
3733
|
+
return entry;
|
|
3734
|
+
const object = entry;
|
|
3735
|
+
if (id === undefined || id === "" || (typeof object.id === "string" && object.id !== ""))
|
|
3736
|
+
return entry;
|
|
3737
|
+
return { ...object, id };
|
|
3738
|
+
});
|
|
3739
|
+
return { ...block, attrs: { ...block.attrs, variables } };
|
|
3740
|
+
}
|
|
3741
|
+
/** The created variables of an elementum_variable_task block, in order (edk#1456). */
|
|
3742
|
+
function variableTaskEntries(block) {
|
|
3743
|
+
if (block.type !== "elementum_variable_task" || !Array.isArray(block.attrs.variables))
|
|
3744
|
+
return [];
|
|
3745
|
+
return block.attrs.variables.flatMap((entry) => {
|
|
3746
|
+
if (!isObject(entry) || typeof entry.name !== "string" || typeof entry.type !== "string") {
|
|
3747
|
+
throw new EntityTfError(`${block.type}.${block.label}: variable entry is incomplete`);
|
|
3748
|
+
}
|
|
3749
|
+
return [{
|
|
3750
|
+
name: entry.name,
|
|
3751
|
+
type: entry.type,
|
|
3752
|
+
...(entry.value !== undefined && entry.value !== null ? { value: entry.value } : {}),
|
|
3753
|
+
...(typeof entry.id === "string" && entry.id !== "" ? { id: entry.id } : {}),
|
|
3754
|
+
}];
|
|
3755
|
+
});
|
|
3756
|
+
}
|
|
3757
|
+
/** The variable name of a variable task that creates exactly one variable. */
|
|
3758
|
+
function soleVariableName(block) {
|
|
3759
|
+
if (block.type !== "elementum_variable_task" || !Array.isArray(block.attrs.variables) || block.attrs.variables.length !== 1)
|
|
3760
|
+
return undefined;
|
|
3761
|
+
const entry = block.attrs.variables[0];
|
|
3762
|
+
return isObject(entry) && typeof entry.name === "string" && entry.name !== "" ? entry.name : undefined;
|
|
3763
|
+
}
|
|
3764
|
+
/**
|
|
3765
|
+
* #1320: a task may read the current item of a loop that ENCLOSES it - the
|
|
3766
|
+
* nearest as `ctx.item`, an outer one as `ctx.loops.<name>.item` - but not of
|
|
3767
|
+
* a loop that doesn't (a sibling, already finished when the task runs). The
|
|
3768
|
+
* builder never offers that reference and its validation flags it invalid, so
|
|
3769
|
+
* EDK has no public form for it. Returns the first such reader so the caller
|
|
3770
|
+
* can exclude the automation. Scoping matches print-automation's
|
|
3771
|
+
* selfTaskRefKeys: a forEach's own args (its collection) sit outside its loop;
|
|
3772
|
+
* workflow outputs sit outside every loop.
|
|
3773
|
+
*/
|
|
3774
|
+
function forEachItemRefOutsideItsLoop(topTasks, outputValues) {
|
|
3775
|
+
const loopNames = new Map();
|
|
3776
|
+
const collectLoops = (tasks) => {
|
|
3777
|
+
for (const task of tasks) {
|
|
3778
|
+
if (task.factory === "forEach")
|
|
3779
|
+
loopNames.set(task.refKey, task.displayName ?? task.refKey);
|
|
3780
|
+
for (const child of task.children ?? [])
|
|
3781
|
+
collectLoops(child.tasks);
|
|
3782
|
+
}
|
|
3783
|
+
};
|
|
3784
|
+
collectLoops(topTasks);
|
|
3785
|
+
const loopName = (refKey) => loopNames.get(refKey) ?? refKey;
|
|
3786
|
+
const outsideRef = (value, enclosing) => {
|
|
3787
|
+
if (Array.isArray(value)) {
|
|
3788
|
+
for (const item of value) {
|
|
3789
|
+
const found = outsideRef(item, enclosing);
|
|
3790
|
+
if (found !== undefined)
|
|
3791
|
+
return found;
|
|
3792
|
+
}
|
|
3793
|
+
return undefined;
|
|
3794
|
+
}
|
|
3795
|
+
if (!isObject(value))
|
|
3796
|
+
return undefined;
|
|
3797
|
+
if (value.kind === "forEachItemRef" && typeof value.forEachTask === "string" && !enclosing.includes(value.forEachTask)) {
|
|
3798
|
+
return value.forEachTask;
|
|
3799
|
+
}
|
|
3800
|
+
for (const nested of Object.values(value)) {
|
|
3801
|
+
const found = outsideRef(nested, enclosing);
|
|
3802
|
+
if (found !== undefined)
|
|
3803
|
+
return found;
|
|
3804
|
+
}
|
|
3805
|
+
return undefined;
|
|
3806
|
+
};
|
|
3807
|
+
const walk = (tasks, enclosing) => {
|
|
3808
|
+
for (const task of tasks) {
|
|
3809
|
+
const reader = `task "${task.displayName ?? task.refKey}"`;
|
|
3810
|
+
const inArgs = outsideRef(task.args, enclosing);
|
|
3811
|
+
if (inArgs !== undefined)
|
|
3812
|
+
return { reader, loop: loopName(inArgs) };
|
|
3813
|
+
const bodyScope = task.factory === "forEach" ? [...enclosing, task.refKey] : enclosing;
|
|
3814
|
+
for (const child of task.children ?? []) {
|
|
3815
|
+
const inFilter = outsideRef(child.filter, bodyScope);
|
|
3816
|
+
if (inFilter !== undefined)
|
|
3817
|
+
return { reader, loop: loopName(inFilter) };
|
|
3818
|
+
const nested = walk(child.tasks, bodyScope);
|
|
3819
|
+
if (nested !== undefined)
|
|
3820
|
+
return nested;
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
return undefined;
|
|
3824
|
+
};
|
|
3825
|
+
const inTasks = walk(topTasks, []);
|
|
3826
|
+
if (inTasks !== undefined)
|
|
3827
|
+
return inTasks;
|
|
3828
|
+
const inOutputs = outsideRef(outputValues, []);
|
|
3829
|
+
return inOutputs === undefined ? undefined : { reader: "a workflow output", loop: loopName(inOutputs) };
|
|
3202
3830
|
}
|
|
3203
3831
|
/** Bridge metadata for required values that GraphQL could not reconstruct. */
|
|
3204
3832
|
function unresolvedAuthoringValues(doc) {
|
|
@@ -3224,10 +3852,11 @@ function unresolvedAuthoringValues(doc) {
|
|
|
3224
3852
|
return values;
|
|
3225
3853
|
}
|
|
3226
3854
|
/**
|
|
3227
|
-
*
|
|
3228
|
-
*
|
|
3229
|
-
*
|
|
3230
|
-
*
|
|
3855
|
+
* EDK does not author multi-trigger automations; apps should keep one
|
|
3856
|
+
* trigger and call the shared logic with a run-automation action. Stream
|
|
3857
|
+
* extraction records every one of these and continues. Direct
|
|
3858
|
+
* `automationFromTf` still throws. Callers that turn other extract failures
|
|
3859
|
+
* into soft skips must not treat this as one of those skips.
|
|
3231
3860
|
*/
|
|
3232
3861
|
export class UnsupportedMultiTriggerError extends EntityTfError {
|
|
3233
3862
|
automationName;
|
|
@@ -3240,8 +3869,22 @@ export class UnsupportedMultiTriggerError extends EntityTfError {
|
|
|
3240
3869
|
this.triggerCount = triggerCount;
|
|
3241
3870
|
}
|
|
3242
3871
|
}
|
|
3243
|
-
/**
|
|
3244
|
-
|
|
3872
|
+
/**
|
|
3873
|
+
* #1320: a task reads the current item of a loop that doesn't enclose it.
|
|
3874
|
+
* Pull skips the automation like any other exclusion, and additionally
|
|
3875
|
+
* releases it from state if an earlier pull adopted it: no authored source can
|
|
3876
|
+
* ever manage it, so keeping it bound would make the next apply destroy it.
|
|
3877
|
+
*/
|
|
3878
|
+
export class ForEachItemOutsideLoopError extends EntityTfError {
|
|
3879
|
+
constructor(automationLabel, reader, loop) {
|
|
3880
|
+
super(`automation "${automationLabel}": ${reader} reads the current item of loop "${loop}", ` +
|
|
3881
|
+
"which does not enclose it (a sibling loop that has already finished); the platform builder never offers " +
|
|
3882
|
+
"this reference and flags it invalid, so the automation is excluded because EDK has no safe authored form for it");
|
|
3883
|
+
this.name = "ForEachItemOutsideLoopError";
|
|
3884
|
+
}
|
|
3885
|
+
}
|
|
3886
|
+
/** Extract one app- or element-owned automation graph from an ei export. */
|
|
3887
|
+
function automationFromTfDocument(doc, automationLabel, appRefName, foreignFieldRefsById, foreignFieldRefsByDataAddress, foreignTableRefsById, picklistOptionLabelById, fieldNamesByOwnerRefName, foreignAppRefNames, foreignElementRefNames, procedureKeysByDiscriminator, foreignTaskRefNames, groupKeysByName) {
|
|
3245
3888
|
const automation = doc.blocks.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE && block.label === automationLabel);
|
|
3246
3889
|
if (automation === undefined)
|
|
3247
3890
|
throw new EntityTfError(`automation resource "${automationLabel}" not found`);
|
|
@@ -3255,8 +3898,12 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3255
3898
|
}
|
|
3256
3899
|
assertAllowed(automation, new Set(["app_id", "name", "description", "status", "triggers_other_automations", "service_account_id", "depends_on"]));
|
|
3257
3900
|
const app = resourceRef(automation.attrs.app_id);
|
|
3258
|
-
if (app === undefined ||
|
|
3259
|
-
|
|
3901
|
+
if (app === undefined ||
|
|
3902
|
+
app.path[0] !== "id" ||
|
|
3903
|
+
(app.type !== "elementum_app" && app.type !== "elementum_element")) {
|
|
3904
|
+
throw new EntityTfError(`${AUTOMATION_RESOURCE_TYPE}.${automationLabel}: app_id is not an app or element reference`);
|
|
3905
|
+
}
|
|
3906
|
+
const ownerScope = app.type === "elementum_element" ? "element" : "app";
|
|
3260
3907
|
const publish = doc.blocks.find((block) => block.kind === "resource" && block.type === WORKFLOW_PUBLISH_RESOURCE_TYPE && references(block.attrs.automation, AUTOMATION_RESOURCE_TYPE, automationLabel));
|
|
3261
3908
|
const unknownDirectChild = doc.blocks.find((block) => block.kind === "resource" &&
|
|
3262
3909
|
references(block.attrs.automation, AUTOMATION_RESOURCE_TYPE, automationLabel) &&
|
|
@@ -3324,7 +3971,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3324
3971
|
throw new EntityTfError(`${unresolved.resource}.${unresolved.field}: ${unresolved.reason}; ` +
|
|
3325
3972
|
"the automation is excluded because no safe authored value or UUID fallback is available");
|
|
3326
3973
|
}
|
|
3327
|
-
tasks.forEach((block) => assertAllowed(block, TASK_ATTRIBUTES));
|
|
3974
|
+
tasks.forEach((block) => assertAllowed(block, block.type === "elementum_notification_task" ? NOTIFICATION_TASK_ATTRIBUTES : TASK_ATTRIBUTES));
|
|
3328
3975
|
ownedBranches.forEach((block) => assertAllowed(block, BRANCH_ATTRIBUTES));
|
|
3329
3976
|
const publishDependencies = Array.isArray(publish?.attrs.depends_on)
|
|
3330
3977
|
? publish.attrs.depends_on.map((value) => resourceRef(value)).filter((value) => value !== undefined)
|
|
@@ -3373,9 +4020,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3373
4020
|
const dataBlocks = new Map(doc.blocks.filter((block) => block.kind === "data" && block.type && block.label).map((block) => [`${block.type}.${block.label}`, block]));
|
|
3374
4021
|
const taskByAddress = new Map(tasks.map((block) => [`${block.type}.${block.label}`, { block, refKey: taskRefKey(block, automationLabel, appTfLabel) }]));
|
|
3375
4022
|
const adoptionAddressAliases = [...taskByAddress.entries()].flatMap(([from, { block, refKey }]) => {
|
|
3376
|
-
if (block
|
|
3377
|
-
typeof block.attrs.variable_name !== "string" ||
|
|
3378
|
-
block.attrs.variable_name === "")
|
|
4023
|
+
if (soleVariableName(block) === undefined)
|
|
3379
4024
|
return [];
|
|
3380
4025
|
const to = `${block.type}.${taskTfLabel(automationLabel, refKey)}`;
|
|
3381
4026
|
return to === from ? [] : [{ from, to }];
|
|
@@ -3406,8 +4051,11 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3406
4051
|
const block = resourceBlocks.get(address);
|
|
3407
4052
|
if (block?.type?.endsWith("_field") !== true || block.label === undefined)
|
|
3408
4053
|
continue;
|
|
4054
|
+
const ownedField = ownerFromScopedChildLabel(block.label);
|
|
3409
4055
|
fieldById.set(id, {
|
|
3410
|
-
key:
|
|
4056
|
+
key: ownedField !== undefined
|
|
4057
|
+
? scopedLabelToBagKey(ownedField.ownerTfLabel, block.label, ownedField.scope)
|
|
4058
|
+
: scopedLabelToBagKey(appTfLabel, block.label, ownerScope),
|
|
3411
4059
|
name: typeof block.attrs.name === "string" ? block.attrs.name : block.label,
|
|
3412
4060
|
resourceType: block.type,
|
|
3413
4061
|
});
|
|
@@ -3423,6 +4071,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3423
4071
|
const ctx = {
|
|
3424
4072
|
appRefName,
|
|
3425
4073
|
appTfLabel: app.label,
|
|
4074
|
+
ownerScope,
|
|
3426
4075
|
trigger,
|
|
3427
4076
|
taskByAddress,
|
|
3428
4077
|
resourceBlocks,
|
|
@@ -3441,6 +4090,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3441
4090
|
...(foreignElementRefNames !== undefined && { foreignElementRefNames }),
|
|
3442
4091
|
...(foreignTaskRefNames !== undefined && { foreignTaskRefNames }),
|
|
3443
4092
|
...(procedureKeysByDiscriminator !== undefined && { procedureKeysByDiscriminator }),
|
|
4093
|
+
...(groupKeysByName !== undefined && { groupKeysByName }),
|
|
3444
4094
|
};
|
|
3445
4095
|
let serviceAccountName;
|
|
3446
4096
|
const serviceAccountValue = automation.attrs.service_account_id;
|
|
@@ -3467,7 +4117,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3467
4117
|
dependencyOrder.set(`${ref.type}.${ref.label}`, index); });
|
|
3468
4118
|
const triggerAddress = `${trigger.type}.${trigger.label}`;
|
|
3469
4119
|
const unrebuildableTasks = [];
|
|
3470
|
-
const
|
|
4120
|
+
const taskDiagnostics = [];
|
|
3471
4121
|
// edk#821: resolve each elementum_unmanaged_task_reference this automation's
|
|
3472
4122
|
// OWN tasks actually parent onto (never the whole doc's data blocks - a
|
|
3473
4123
|
// sibling automation sharing this export can have its own, edk#785) to its
|
|
@@ -3571,7 +4221,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3571
4221
|
id: typeof block.attrs.id === "string" ? block.attrs.id : "",
|
|
3572
4222
|
taskType: typeof block.attrs.task_type === "string" ? block.attrs.task_type : "",
|
|
3573
4223
|
}
|
|
3574
|
-
: taskArgs(block, factory, ctx,
|
|
4224
|
+
: taskArgs(block, factory, ctx, taskDiagnostics);
|
|
3575
4225
|
const call = { factory, refKey, args, ...(children ? { children } : {}), ...(typeof block.attrs.name === "string" && block.attrs.name !== refKey ? { displayName: block.attrs.name } : {}), ...(hclParent !== undefined ? { hclParent } : {}) };
|
|
3576
4226
|
visiting.delete(address);
|
|
3577
4227
|
return [call, ...buildTasks(address)];
|
|
@@ -3599,6 +4249,12 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3599
4249
|
if (inferred.fieldType === fieldType && inferred.multiple === multiple) {
|
|
3600
4250
|
return { name: output.name, value };
|
|
3601
4251
|
}
|
|
4252
|
+
// A repeated script output name has one public type, its first entry's
|
|
4253
|
+
// (already reported by the duplicate diagnostic); build infers it, and
|
|
4254
|
+
// export/provider read it back the same way.
|
|
4255
|
+
if (referencesRepeatedScriptOutput(output.value, ctx)) {
|
|
4256
|
+
return { name: output.name, value };
|
|
4257
|
+
}
|
|
3602
4258
|
const explicitType = workflowOutputTypeFromFieldType(fieldType);
|
|
3603
4259
|
if (explicitType === undefined) {
|
|
3604
4260
|
outputDiagnostics.push(`automation "${automationLabel}" workflow output "${output.name}" has explicit field type ` +
|
|
@@ -3615,6 +4271,9 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3615
4271
|
}
|
|
3616
4272
|
return { name: output.name, value, explicitType, explicitMultiple: multiple };
|
|
3617
4273
|
}) : undefined;
|
|
4274
|
+
const outOfLoop = forEachItemRefOutsideItsLoop(topTasks, outputs?.map((output) => output.value) ?? []);
|
|
4275
|
+
if (outOfLoop !== undefined)
|
|
4276
|
+
throw new ForEachItemOutsideLoopError(automationLabel, outOfLoop.reader, outOfLoop.loop);
|
|
3618
4277
|
const exportedRevision = publish?.attrs.workflow_revision;
|
|
3619
4278
|
if (exportedRevision !== undefined && typeof exportedRevision !== "string") {
|
|
3620
4279
|
throw new EntityTfError(`${WORKFLOW_PUBLISH_RESOURCE_TYPE}.${automationLabel}: workflow_revision must be a string`);
|
|
@@ -3637,25 +4296,26 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
3637
4296
|
ast,
|
|
3638
4297
|
blocks: [automation, trigger, ...tasks, ...ownedBranches, ...(publish ? [publish] : [])],
|
|
3639
4298
|
adoptionAddressAliases,
|
|
3640
|
-
...((unrebuildableTasks.length > 0 || placeholderTasks.length > 0 || outputDiagnostics.length > 0 ||
|
|
4299
|
+
...((unrebuildableTasks.length > 0 || placeholderTasks.length > 0 || outputDiagnostics.length > 0 || taskDiagnostics.length > 0) && {
|
|
3641
4300
|
diagnostics: [
|
|
3642
4301
|
...unrebuildableTasks.map((address) => `automation "${automationLabel}": ${address}'s real parent is a task type EDK doesn't support yet, so its authored position couldn't be reconstructed (anchored to the trigger instead) - not rebuildable from this source until that task type is supported`),
|
|
3643
4302
|
...placeholderTasks.map(({ name, taskType }) => `automation "${automationLabel}" uses platform task type "${taskType}" ("${name}"), which EDK doesn't implement - kept as an unimplementedTask(...) placeholder; its configuration isn't authorable, but its position and downstream chain are round-trip-safe`),
|
|
3644
4303
|
...outputDiagnostics,
|
|
3645
|
-
...
|
|
4304
|
+
...taskDiagnostics.map((message) => `automation "${automationLabel}": ${message}`),
|
|
3646
4305
|
],
|
|
3647
4306
|
}),
|
|
3648
4307
|
};
|
|
3649
4308
|
}
|
|
3650
|
-
export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth) {
|
|
4309
|
+
export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth) {
|
|
3651
4310
|
if (Array.isArray(first)) {
|
|
3652
4311
|
const ctx = second;
|
|
3653
4312
|
const automationBlock = first.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE);
|
|
3654
4313
|
if (automationBlock?.label === undefined) {
|
|
3655
|
-
|
|
4314
|
+
const addresses = first.filter((block) => block.kind === "resource").map((block) => `${block.type}.${block.label}`);
|
|
4315
|
+
throw new EntityTfError(`automation graph has no ${AUTOMATION_RESOURCE_TYPE} resource, so its resources (${addresses.join(", ") || "none"}) cannot be pulled`);
|
|
3656
4316
|
}
|
|
3657
4317
|
try {
|
|
3658
|
-
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);
|
|
4318
|
+
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);
|
|
3659
4319
|
if (result.diagnostics)
|
|
3660
4320
|
ctx.diagnostics.push(...result.diagnostics);
|
|
3661
4321
|
return { automation: result.ast };
|
|
@@ -3668,5 +4328,5 @@ export function automationFromTf(first, second, third, fourth, fifth, sixth, sev
|
|
|
3668
4328
|
return { skippedReason: message };
|
|
3669
4329
|
}
|
|
3670
4330
|
}
|
|
3671
|
-
return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth);
|
|
4331
|
+
return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth);
|
|
3672
4332
|
}
|