@elementumai/edk 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist-sdk/src/catalog/org.d.ts +7 -5
- package/dist-sdk/src/catalog/org.js +14 -9
- package/dist-sdk/src/catalog/token.js +4 -0
- package/dist-sdk/src/core/types/app.d.ts +22 -0
- package/dist-sdk/src/engine/build/context.d.ts +8 -0
- package/dist-sdk/src/engine/build/source-context.d.ts +3 -4
- package/dist-sdk/src/engine/coverage-gaps.d.ts +2 -0
- package/dist-sdk/src/engine/coverage-gaps.js +3 -0
- package/dist-sdk/src/engine/ei/state.d.ts +48 -0
- package/dist-sdk/src/engine/ei/state.js +91 -0
- package/dist-sdk/src/engine/pull/authored-address.d.ts +100 -0
- package/dist-sdk/src/engine/pull/authored-address.js +360 -0
- package/dist-sdk/src/engine/pull/context.d.ts +59 -0
- package/dist-sdk/src/engine/tf/expr.d.ts +7 -0
- package/dist-sdk/src/engine/tf/expr.js +62 -18
- package/dist-sdk/src/engine/tf/index.d.ts +1 -1
- package/dist-sdk/src/engine/tf/index.js +1 -1
- package/dist-sdk/src/engine/tf/labels.d.ts +10 -2
- package/dist-sdk/src/engine/tf/labels.js +15 -2
- package/dist-sdk/src/engine/tf/parse.js +19 -6
- package/dist-sdk/src/engine/workspace/backend.d.ts +34 -0
- package/dist-sdk/src/engine/workspace/backend.js +104 -0
- package/dist-sdk/src/engine/workspace/generated-file.d.ts +3 -0
- package/dist-sdk/src/engine/workspace/generated-file.js +6 -0
- package/dist-sdk/src/engine/workspace/loader.js +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +1 -1
- package/dist-sdk/src/entities/app/build.d.ts +36 -4
- package/dist-sdk/src/entities/app/build.js +67 -4
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +12 -0
- package/dist-sdk/src/entities/app/from-tf.js +13 -9
- package/dist-sdk/src/entities/app/module.js +1 -0
- package/dist-sdk/src/entities/app/stage-keys.d.ts +82 -0
- package/dist-sdk/src/entities/app/stage-keys.js +160 -0
- package/dist-sdk/src/entities/app/to-tf.js +17 -21
- package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +9 -1
- package/dist-sdk/src/entities/approval-chain/from-tf.js +31 -3
- package/dist-sdk/src/entities/approval-chain/module.js +12 -4
- package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/approval-chain/to-tf.js +6 -1
- package/dist-sdk/src/entities/automation/build.js +13 -6
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +3 -0
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +5 -3
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +90 -17
- package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
- package/dist-sdk/src/entities/automation/from-tf.js +140 -23
- package/dist-sdk/src/entities/automation/module.js +123 -37
- package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -1
- package/dist-sdk/src/entities/automation/to-tf.js +131 -20
- package/dist-sdk/src/entities/automation/triggers.d.ts +2 -0
- package/dist-sdk/src/entities/automation/triggers.js +1 -0
- package/dist-sdk/src/entities/chart/from-tf.d.ts +6 -0
- package/dist-sdk/src/entities/chart/from-tf.js +9 -1
- package/dist-sdk/src/entities/dashboard/from-tf.js +51 -4
- package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +48 -4
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -2
- package/dist-sdk/src/entities/element/build.js +1 -1
- package/dist-sdk/src/entities/element/from-tf.d.ts +12 -6
- package/dist-sdk/src/entities/element/from-tf.js +23 -7
- package/dist-sdk/src/entities/element/module.js +3 -2
- package/dist-sdk/src/entities/element/to-tf.d.ts +3 -2
- package/dist-sdk/src/entities/element/to-tf.js +32 -25
- package/dist-sdk/src/entities/field/allow-list.d.ts +18 -0
- package/dist-sdk/src/entities/field/allow-list.js +42 -0
- package/dist-sdk/src/entities/field/build.d.ts +38 -3
- package/dist-sdk/src/entities/field/build.js +7 -2
- package/dist-sdk/src/entities/field/from-tf.js +178 -20
- package/dist-sdk/src/entities/field/module.js +2 -0
- package/dist-sdk/src/entities/field/options.d.ts +2 -0
- package/dist-sdk/src/entities/field/order.d.ts +9 -0
- package/dist-sdk/src/entities/field/order.js +33 -0
- package/dist-sdk/src/entities/field/to-tf.d.ts +6 -0
- package/dist-sdk/src/entities/field/to-tf.js +87 -0
- package/dist-sdk/src/entities/field/types.js +3 -0
- package/dist-sdk/src/entities/relationship/build.d.ts +3 -3
- package/dist-sdk/src/entities/relationship/from-tf.js +4 -2
- package/dist-sdk/src/entities/relationship/to-tf.js +3 -1
- package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +8 -3
- package/dist-sdk/src/entities/service-account/workspace-owner.js +12 -4
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +5 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +13 -0
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +7 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +1 -1
- package/dist-sdk/src/entities/skill/to-tf.js +19 -14
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.js +3 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +6 -1
- package/dist-sdk/src/entities/skill-tool/to-tf.js +6 -1
- package/dist-sdk/src/entities/task/build.js +1 -1
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +11 -0
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +13 -38
- package/dist-sdk/src/entities/view/custom-view-validate.d.ts +29 -0
- package/dist-sdk/src/entities/view/custom-view-validate.js +292 -0
- package/dist-sdk/src/entities/view/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/view/from-tf.js +40 -6
- package/dist-sdk/src/entities/view/to-tf.d.ts +6 -0
- package/dist-sdk/src/entities/view/to-tf.js +14 -6
- package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +2 -1
- package/dist-sdk/src/entities/visual-flow/from-tf.js +11 -2
- package/dist-sdk/src/entities/visual-flow/module.js +15 -5
- package/dist-sdk/src/entities/visual-flow/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/visual-flow/to-tf.js +1 -1
- package/dist-sdk/src/entities/widget/build.d.ts +8 -1
- package/dist-sdk/src/entities/widget/from-tf.js +12 -6
- package/dist-sdk/src/entities/widget/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/widget/to-tf.js +16 -0
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +8 -2
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +6 -0
- package/dist-sdk/src/graph/index.js +1 -0
- package/dist-sdk/src/graph/types.d.ts +59 -2
- package/package.json +2 -17
|
@@ -35,11 +35,12 @@ import { sdkPackageSpecifier } from "../../../internal/sdk-package.js";
|
|
|
35
35
|
import { safeIdentifier } from "../../../internal/safe-identifier.js";
|
|
36
36
|
import { isRefExpr } from "../../shared/filters/ast.js";
|
|
37
37
|
import { printFilter as printCanonicalFilter } from "../../shared/filters/print.js";
|
|
38
|
-
import { isUuid } from "../../../engine/tf/labels.js";
|
|
38
|
+
import { isUuid, sanitizeName, tfLabelToTsLabel } from "../../../engine/tf/labels.js";
|
|
39
39
|
import { UNRESOLVED_FIELD_MARKER } from "../../shared/ref.js";
|
|
40
40
|
import { UNRESOLVED_REFERENCE_MARKER } from "../filter.js";
|
|
41
41
|
import { INJECTED_TS_IGNORE, scriptFileText } from "../script-code.js";
|
|
42
42
|
import { isRequiredSecret } from "../tasks.js";
|
|
43
|
+
import { canonicalImportId } from "../../../engine/pull/authored-address.js";
|
|
43
44
|
import { unresolvedReferenceComment } from "../../../engine/pull/ref-only.js";
|
|
44
45
|
// ---------------------------------------------------------------------------
|
|
45
46
|
// Factory name mapping — decoded task `factory` → v2 factory function name.
|
|
@@ -141,14 +142,20 @@ function revisionAtLeast(a, b) {
|
|
|
141
142
|
function stateWorkflowRevision(context) {
|
|
142
143
|
if (context?.platformId === undefined || context.stateResources === undefined)
|
|
143
144
|
return undefined;
|
|
145
|
+
const want = canonicalImportId(context.platformId);
|
|
146
|
+
if (want === "")
|
|
147
|
+
return undefined;
|
|
144
148
|
for (const resource of context.stateResources) {
|
|
145
|
-
if (resource.type !== "elementum_workflow_publish")
|
|
149
|
+
if (resource.mode !== "managed" || resource.module !== undefined || resource.type !== "elementum_workflow_publish")
|
|
146
150
|
continue;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
const attrs = resource.instances?.[0]?.attributes;
|
|
152
|
+
const id = attrs?.id;
|
|
153
|
+
const revision = attrs?.workflow_revision;
|
|
154
|
+
if (typeof id !== "string" || canonicalImportId(id) !== want)
|
|
155
|
+
continue;
|
|
156
|
+
if (typeof revision !== "string" || revision === "")
|
|
157
|
+
continue;
|
|
158
|
+
return revision;
|
|
152
159
|
}
|
|
153
160
|
return undefined;
|
|
154
161
|
}
|
|
@@ -161,9 +168,17 @@ function stateWorkflowRevision(context) {
|
|
|
161
168
|
* least the baseline — the state revision, or the freshly printed live revision
|
|
162
169
|
* when state has no entry yet (adoption is about to import it). An older
|
|
163
170
|
* authored token is replaced by that baseline. Without readable state the
|
|
164
|
-
* pre-#1590 behaviour (always keep authored) is unchanged.
|
|
171
|
+
* pre-#1590 behaviour (always keep authored) is unchanged. With no existing
|
|
172
|
+
* source, a publish already bound in state keeps the state revision: the
|
|
173
|
+
* export prints `1.0.<live version>`, which Read never writes back (#1902).
|
|
165
174
|
*/
|
|
166
175
|
export function preserveAuthoredAutomationRevision(freshSource, existingSource, context) {
|
|
176
|
+
if (existingSource === undefined) {
|
|
177
|
+
const bound = stateWorkflowRevision(context);
|
|
178
|
+
if (bound === undefined || !REVISION_PROPERTY.test(freshSource))
|
|
179
|
+
return freshSource;
|
|
180
|
+
return freshSource.replace(REVISION_PROPERTY, (_line, prefix) => `${prefix}${JSON.stringify(bound)},`);
|
|
181
|
+
}
|
|
167
182
|
const authored = REVISION_PROPERTY.exec(existingSource)?.[3];
|
|
168
183
|
if (authored === undefined || authored === "")
|
|
169
184
|
return freshSource;
|
|
@@ -503,7 +518,8 @@ export function preserveAuthoredAutomationDescription(freshSource, existingSourc
|
|
|
503
518
|
}
|
|
504
519
|
/** Pull merge: preserve authored revision + description across live reprint. */
|
|
505
520
|
export function preserveAuthoredAutomationPullMeta(freshSource, existingSource, context) {
|
|
506
|
-
|
|
521
|
+
const revised = preserveAuthoredAutomationRevision(freshSource, existingSource, context);
|
|
522
|
+
return existingSource === undefined ? revised : preserveAuthoredAutomationDescription(revised, existingSource);
|
|
507
523
|
}
|
|
508
524
|
function emptyImports() {
|
|
509
525
|
return {
|
|
@@ -654,7 +670,7 @@ function printAutomation(ast, opts, externalScripts) {
|
|
|
654
670
|
}
|
|
655
671
|
body.push(` app: catalog.${appRefName},`);
|
|
656
672
|
if (ast.serviceAccountName !== undefined) {
|
|
657
|
-
body.push(` serviceAccount: serviceAccountRef({ app: catalog.${appRefName}, name: ${quote(ast.serviceAccountName)} }),`);
|
|
673
|
+
body.push(` serviceAccount: serviceAccountRef({ app: catalog.${ast.serviceAccountAppRefName ?? appRefName}, name: ${quote(ast.serviceAccountName)} }),`);
|
|
658
674
|
}
|
|
659
675
|
body.push(` status: automationStatus.${automationStatusKey(ast.status)},`);
|
|
660
676
|
body.push(` actions: actions()`);
|
|
@@ -882,6 +898,7 @@ function printTrigger(trigger, state) {
|
|
|
882
898
|
`app: ${printRef(trigger.app, state, DEFAULT_CTX)}`,
|
|
883
899
|
...(approvalChain !== undefined ? [`approvalChain: ${approvalChain}`] : []),
|
|
884
900
|
`status: ${quote(trigger.status)}`,
|
|
901
|
+
...(trigger.filter ? [`filter: ${printFilter(trigger.filter, state)}`] : []),
|
|
885
902
|
];
|
|
886
903
|
return `${approvalProcessStatusUpdated}({\n ${parts.join(",\n ")}\n })`;
|
|
887
904
|
}
|
|
@@ -1387,7 +1404,7 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
|
|
|
1387
1404
|
const parentRef = target?.refName ?? assignment?.foreignOwnerName ?? "task";
|
|
1388
1405
|
const parentName = target?.name ?? assignment?.foreignOwnerName ?? parentRef;
|
|
1389
1406
|
const fieldName = assignment?.foreignFieldName ?? fieldKey;
|
|
1390
|
-
const fieldType = assignment?.foreignFieldType ??
|
|
1407
|
+
const fieldType = assignment?.foreignFieldType ?? unconfirmedFieldType(assignment?.value);
|
|
1391
1408
|
fieldExpr = (`{ __kind: "field", refName: ${quote(fieldKey)}, name: ${quote(fieldName)}, fieldType: ${quote(fieldType)}, ` +
|
|
1392
1409
|
`parent: ${quote(parentRef)}, parentKind: "task", parentName: ${quote(parentName)} }`);
|
|
1393
1410
|
}
|
|
@@ -1395,7 +1412,7 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
|
|
|
1395
1412
|
!target.inCatalog &&
|
|
1396
1413
|
assignment?.foreignOwnerNamespace !== undefined &&
|
|
1397
1414
|
!fieldKey.startsWith(UNRESOLVED_FIELD_MARKER)) {
|
|
1398
|
-
const fieldType = assignment.foreignFieldType ??
|
|
1415
|
+
const fieldType = assignment.foreignFieldType ?? unconfirmedFieldType(assignment.value);
|
|
1399
1416
|
const parentName = assignment.foreignOwnerName ?? target.name ?? target.refName;
|
|
1400
1417
|
fieldExpr = (`{ __kind: "field", refName: ${quote(fieldKey)}, name: ${quote(assignment.foreignFieldName ?? fieldKey)}, fieldType: ${quote(fieldType)}, ` +
|
|
1401
1418
|
`parent: ${quote(target.refName)}, parentKind: ${quote(target.kind)}, parentName: ${quote(parentName)}, ` +
|
|
@@ -1416,7 +1433,10 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
|
|
|
1416
1433
|
const foreignOwner = assignment?.foreignOwnerName;
|
|
1417
1434
|
const foreignKind = assignment?.foreignEntityType;
|
|
1418
1435
|
if ((foreignKind === "app" || foreignKind === "element") && foreignOwner !== undefined && foreignOwner !== "" && !isUuid(rawKey) && assignment?.foreignFieldType !== undefined) {
|
|
1419
|
-
|
|
1436
|
+
const ownerKey = workspaceAspectRefName(state, foreignKind, foreignOwner, assignment.foreignOwnerNamespace)
|
|
1437
|
+
?? namespaceCatalogKey(assignment.foreignOwnerNamespace)
|
|
1438
|
+
?? foreignOwner;
|
|
1439
|
+
fieldExpr = `catalog.${ownerKey}.fields${safeMember(rawKey)}`;
|
|
1420
1440
|
}
|
|
1421
1441
|
else if (!isUuid(rawKey)) {
|
|
1422
1442
|
const platformFieldId = assignment?.platformFieldId;
|
|
@@ -1444,6 +1464,15 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
|
|
|
1444
1464
|
});
|
|
1445
1465
|
return `[\n${lines.join("\n")}\n${pad}]`;
|
|
1446
1466
|
}
|
|
1467
|
+
/**
|
|
1468
|
+
* The type a foreign field stub prints with when ei's data source can't
|
|
1469
|
+
* confirm it. Only a Multi-Select takes an array value, so an array (a
|
|
1470
|
+
* `jsonencode([...])` value, including the `[]` clear) prints as one;
|
|
1471
|
+
* anything else keeps the TEXT guess (#1707).
|
|
1472
|
+
*/
|
|
1473
|
+
function unconfirmedFieldType(value) {
|
|
1474
|
+
return Array.isArray(value) ? "MULTI_PICKLIST" : "TEXT";
|
|
1475
|
+
}
|
|
1447
1476
|
/**
|
|
1448
1477
|
* The task's primary target, used to resolve `values:` field keys to
|
|
1449
1478
|
* `<target>.fields.<key>` tokens (or inline field stubs for tasks).
|
|
@@ -1466,10 +1495,13 @@ function taskPrimaryTarget(args, state) {
|
|
|
1466
1495
|
}
|
|
1467
1496
|
if (v.entityType === "element") {
|
|
1468
1497
|
const foreignRefName = workspaceAspectRefName(state, "element", v.name, v.namespace);
|
|
1469
|
-
|
|
1498
|
+
const refName = foreignRefName ?? namespaceCatalogKey(v.namespace) ?? v.appHandle;
|
|
1499
|
+
return { kind: "element", refName, name: v.name, inCatalog: v.name === undefined || foreignRefName !== undefined };
|
|
1470
1500
|
}
|
|
1471
1501
|
const foreignRefName = workspaceAspectRefName(state, "app", v.name, v.namespace);
|
|
1472
|
-
const refName = foreignRefName
|
|
1502
|
+
const refName = foreignRefName
|
|
1503
|
+
?? (v.entityType === "app" ? namespaceCatalogKey(v.namespace) : undefined)
|
|
1504
|
+
?? catalogOwnerHandle(state, v.appHandle);
|
|
1473
1505
|
return { kind: "app", refName, name: v.name, inCatalog: v.entityType === undefined || v.name === undefined || foreignRefName !== undefined };
|
|
1474
1506
|
}
|
|
1475
1507
|
const aspectId = typeof v === "string"
|
|
@@ -1504,6 +1536,48 @@ function workspaceAspectRefName(state, kind, name, namespace) {
|
|
|
1504
1536
|
return (namespace !== undefined ? namespaces?.get(namespace) : undefined)
|
|
1505
1537
|
?? (name !== undefined ? names?.get(name) : undefined);
|
|
1506
1538
|
}
|
|
1539
|
+
/**
|
|
1540
|
+
* A foreign field's owner as a workspace catalog key.
|
|
1541
|
+
*
|
|
1542
|
+
* A known kind searches only that kind. An unknown kind (`ownerKindUnknown`)
|
|
1543
|
+
* is a raw field id the registry named by catalog key and did not classify.
|
|
1544
|
+
* That key is a namespace-map or name-map value, not a display name. Joining
|
|
1545
|
+
* it there first keeps an app whose display name equals the element ref from
|
|
1546
|
+
* being chosen ahead of a renamed element's namespace-map entry.
|
|
1547
|
+
*/
|
|
1548
|
+
function workspaceFieldOwnerRefName(state, foreign, appHandle) {
|
|
1549
|
+
const knownKind = foreign.entityType === "element" ? "element" : "app";
|
|
1550
|
+
if (!foreign.ownerKindUnknown) {
|
|
1551
|
+
return workspaceAspectRefName(state, knownKind, foreign.name, foreign.namespace)
|
|
1552
|
+
?? (isWorkspaceAspectRefName(state, knownKind, appHandle) ? appHandle : undefined);
|
|
1553
|
+
}
|
|
1554
|
+
const elementOwnsKey = isWorkspaceAspectRefName(state, "element", appHandle);
|
|
1555
|
+
const appOwnsKey = isWorkspaceAspectRefName(state, "app", appHandle);
|
|
1556
|
+
if (elementOwnsKey !== appOwnsKey)
|
|
1557
|
+
return appHandle;
|
|
1558
|
+
if (foreign.namespace !== undefined) {
|
|
1559
|
+
const elementRef = state.foreignElementRefNamespaces?.get(foreign.namespace);
|
|
1560
|
+
const appRef = state.foreignAppRefNamespaces?.get(foreign.namespace);
|
|
1561
|
+
if (elementRef !== undefined && appRef === undefined)
|
|
1562
|
+
return elementRef;
|
|
1563
|
+
if (appRef !== undefined && elementRef === undefined)
|
|
1564
|
+
return appRef;
|
|
1565
|
+
}
|
|
1566
|
+
for (const kind of ["app", "element"]) {
|
|
1567
|
+
const found = workspaceAspectRefName(state, kind, foreign.name, foreign.namespace)
|
|
1568
|
+
?? (isWorkspaceAspectRefName(state, kind, appHandle) ? appHandle : undefined);
|
|
1569
|
+
if (found !== undefined)
|
|
1570
|
+
return found;
|
|
1571
|
+
}
|
|
1572
|
+
return undefined;
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* An app's or element's catalog key is its sanitized namespace (its stream
|
|
1576
|
+
* label), so a foreign target that is not on disk yet still has a stable key.
|
|
1577
|
+
*/
|
|
1578
|
+
function namespaceCatalogKey(namespace) {
|
|
1579
|
+
return namespace === undefined || namespace === "" ? undefined : tfLabelToTsLabel(sanitizeName(namespace));
|
|
1580
|
+
}
|
|
1507
1581
|
/** The pulled field registry names a field's owner by its catalog key, not its platform name. */
|
|
1508
1582
|
function isWorkspaceAspectRefName(state, kind, refName) {
|
|
1509
1583
|
const namespaces = kind === "app" ? state.foreignAppRefNamespaces : state.foreignElementRefNamespaces;
|
|
@@ -1705,8 +1779,7 @@ function printRef(ref, state, refCtx) {
|
|
|
1705
1779
|
// typed token; otherwise a literal stub (field type is unconfirmed —
|
|
1706
1780
|
// ei's `elementum_field` data source doesn't expose it).
|
|
1707
1781
|
const foreignRefName = ref.foreign.entityType === "element" || ref.foreign.entityType === "app"
|
|
1708
|
-
?
|
|
1709
|
-
(isWorkspaceAspectRefName(state, ref.foreign.entityType, ref.appHandle) ? ref.appHandle : undefined)
|
|
1782
|
+
? workspaceFieldOwnerRefName(state, ref.foreign, ref.appHandle)
|
|
1710
1783
|
: ref.foreign.entityType === "task"
|
|
1711
1784
|
? state.foreignTaskRefNames?.get(ref.foreign.name)
|
|
1712
1785
|
: undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EntityTfError } from "../../engine/entity.js";
|
|
2
|
+
import { type FromTfContext } from "../../engine/pull/context.js";
|
|
2
3
|
import { type ChildResourceScope, type TfBlock, type TfDocument, type TfValue } from "../../engine/tf/index.js";
|
|
3
4
|
import type { AutomationAst } from "./deserializer/ast.js";
|
|
4
5
|
export interface AutomationFromTfResult {
|
|
@@ -13,6 +14,14 @@ export interface AutomationFromTfResult {
|
|
|
13
14
|
}[];
|
|
14
15
|
/** Non-fatal issues found while extracting (edk#785: a task anchored to the trigger because its real parent is unsupported). */
|
|
15
16
|
readonly diagnostics?: readonly string[];
|
|
17
|
+
/**
|
|
18
|
+
* The export embeds a stringified ValueReference envelope whose task,
|
|
19
|
+
* trigger, or variable is not in this automation, so source cannot
|
|
20
|
+
* reproduce it (edk#1646 / #1798). Envelopes that decode to a ctx
|
|
21
|
+
* reference don't set this: the adoption gate checks those like any
|
|
22
|
+
* other value.
|
|
23
|
+
*/
|
|
24
|
+
readonly stringifiedValueReferences?: boolean;
|
|
16
25
|
}
|
|
17
26
|
interface DecodeContext {
|
|
18
27
|
readonly appRefName: string;
|
|
@@ -68,6 +77,10 @@ interface DecodeContext {
|
|
|
68
77
|
readonly procedureKeysByDiscriminator?: ReadonlyMap<string, string>;
|
|
69
78
|
/** Group name → org.ts's `org.groups` key, for static recipients (edk#1412). See `FromTfContext.groupKeysByName`. */
|
|
70
79
|
readonly groupKeysByName?: ReadonlyMap<string, string>;
|
|
80
|
+
/** Set when this automation's export contains a stringified ValueReference envelope that does not resolve. */
|
|
81
|
+
readonly stringifiedValueReferences?: {
|
|
82
|
+
unresolved: boolean;
|
|
83
|
+
};
|
|
71
84
|
}
|
|
72
85
|
/**
|
|
73
86
|
* The same outputs as seen from a CALCULATION formula, which addresses a
|
|
@@ -97,8 +110,8 @@ export declare function inferredPublishOutputType(value: TfValue, ctx: DecodeCon
|
|
|
97
110
|
* conditions that make real extraction fail (zero triggers, an
|
|
98
111
|
* unrecognized task kind) so it over-collects rather than under-collects.
|
|
99
112
|
* More than one trigger throws {@link UnsupportedMultiTriggerError}. The
|
|
100
|
-
* stream extractor
|
|
101
|
-
*
|
|
113
|
+
* stream extractor soft-skips those automations (diagnostic + skipped +
|
|
114
|
+
* releaseIfManaged), so the rest of the app can still adopt (#1785).
|
|
102
115
|
* A false positive
|
|
103
116
|
* here just leaves one more resource unmanaged; a false negative would
|
|
104
117
|
* silently destroy a live automation on apply.
|
|
@@ -107,15 +120,23 @@ export declare function automationOwnedAddresses(doc: TfDocument, automationLabe
|
|
|
107
120
|
/**
|
|
108
121
|
* EDK does not author multi-trigger automations; apps should keep one
|
|
109
122
|
* trigger and call the shared logic with a run-automation action. Stream
|
|
110
|
-
* extraction
|
|
111
|
-
*
|
|
112
|
-
*
|
|
123
|
+
* extraction soft-skips every one of these (warn + skip + releaseIfManaged)
|
|
124
|
+
* so the rest of the app can still adopt (#1785). Direct `automationFromTf`
|
|
125
|
+
* still throws so callers that need a hard signal can catch it.
|
|
113
126
|
*/
|
|
114
127
|
export declare class UnsupportedMultiTriggerError extends EntityTfError {
|
|
115
128
|
readonly automationName: string;
|
|
116
129
|
readonly triggerCount: number;
|
|
117
130
|
constructor(automationName: string, triggerCount: number);
|
|
118
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* A bare service_account_id belongs to an app this export does not contain.
|
|
134
|
+
* Pull cannot print a serviceAccountRef until that app is in the workspace,
|
|
135
|
+
* and printing nothing would clear the live account.
|
|
136
|
+
*/
|
|
137
|
+
export declare class UnresolvedForeignServiceAccountError extends EntityTfError {
|
|
138
|
+
constructor(automationLabel: string);
|
|
139
|
+
}
|
|
119
140
|
/**
|
|
120
141
|
* #1320: a task reads the current item of a loop that doesn't enclose it.
|
|
121
142
|
* Pull skips the automation like any other exclusion, and additionally
|
|
@@ -154,6 +175,7 @@ export interface AutomationFromTfContext {
|
|
|
154
175
|
readonly foreignTaskRefNames?: ReadonlyMap<string, string>;
|
|
155
176
|
readonly procedureKeysByDiscriminator?: ReadonlyMap<string, string>;
|
|
156
177
|
readonly groupKeysByName?: ReadonlyMap<string, string>;
|
|
178
|
+
readonly serviceAccountsById?: FromTfContext["serviceAccountsById"];
|
|
157
179
|
}
|
|
158
180
|
export interface AutomationGraphFromTfResult {
|
|
159
181
|
readonly automation?: AutomationAst;
|
|
@@ -177,5 +199,5 @@ export declare function automationFromTf(doc: TfDocument, automationLabel: strin
|
|
|
177
199
|
}>, foreignTableRefsById?: ReadonlyMap<string, {
|
|
178
200
|
readonly tableRefName: string;
|
|
179
201
|
readonly name: string;
|
|
180
|
-
}>, picklistOptionLabelById?: ReadonlyMap<string, string>, fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>, foreignAppRefNames?: ReadonlyMap<string, string>, foreignElementRefNames?: ReadonlyMap<string, string>, procedureKeysByDiscriminator?: ReadonlyMap<string, string>, foreignTaskRefNames?: ReadonlyMap<string, string>, groupKeysByName?: ReadonlyMap<string, string
|
|
202
|
+
}>, picklistOptionLabelById?: ReadonlyMap<string, string>, fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>, foreignAppRefNames?: ReadonlyMap<string, string>, foreignElementRefNames?: ReadonlyMap<string, string>, procedureKeysByDiscriminator?: ReadonlyMap<string, string>, foreignTaskRefNames?: ReadonlyMap<string, string>, groupKeysByName?: ReadonlyMap<string, string>, serviceAccountsById?: FromTfContext["serviceAccountsById"]): AutomationFromTfResult;
|
|
181
203
|
export {};
|
|
@@ -984,9 +984,11 @@ function decodeStringifiedValueReference(value, ctx, diagnostics, where) {
|
|
|
984
984
|
found = true;
|
|
985
985
|
if (start > cursor)
|
|
986
986
|
parts.push(value.slice(cursor, start));
|
|
987
|
-
const reference = decodeFilterReferenceEnvelope(parsed, ctx);
|
|
988
|
-
if (reference === undefined ||
|
|
987
|
+
const reference = decodeFilterReferenceEnvelope(parsed, ctx, undefined, "envelope");
|
|
988
|
+
if (reference === undefined || stringifiedEnvelopeCannotMatchRead(parsed, reference, ctx, where)) {
|
|
989
989
|
unresolved = true;
|
|
990
|
+
if (ctx.stringifiedValueReferences !== undefined)
|
|
991
|
+
ctx.stringifiedValueReferences.unresolved = true;
|
|
990
992
|
parts.push({ kind: "unresolved", uuid: value.slice(start, end), hint: "value-reference (edk#1646)" });
|
|
991
993
|
}
|
|
992
994
|
else {
|
|
@@ -1033,6 +1035,69 @@ function stringifiedReferenceResolves(envelope, reference, ctx) {
|
|
|
1033
1035
|
}
|
|
1034
1036
|
return true;
|
|
1035
1037
|
}
|
|
1038
|
+
/**
|
|
1039
|
+
* A stringified envelope is safe to adopt only when a rebuilt ctx ref matches
|
|
1040
|
+
* what provider Read stores. "The task exists" is not that test: an undeclared
|
|
1041
|
+
* script output rebuilds as TEXT, and an envelope whose fieldType or multiple
|
|
1042
|
+
* is not the type build infers would plan an update after Read (#1858).
|
|
1043
|
+
*/
|
|
1044
|
+
function stringifiedEnvelopeCannotMatchRead(envelope, reference, ctx, where) {
|
|
1045
|
+
if (!stringifiedReferenceResolves(envelope, reference, ctx))
|
|
1046
|
+
return true;
|
|
1047
|
+
if (reference.kind === "taskRef" && reference.undeclaredScriptOutput === true)
|
|
1048
|
+
return true;
|
|
1049
|
+
if (typeof envelope.fieldType !== "string")
|
|
1050
|
+
return false;
|
|
1051
|
+
// record_reference / record_id Read as ASPECT_RECORD_ID. An envelope that
|
|
1052
|
+
// still says TEXT (or anything else) rebuilds as the wrong type (#1858).
|
|
1053
|
+
if ((where.endsWith("record_reference") || where.endsWith("record_id")) &&
|
|
1054
|
+
envelope.fieldType !== "ASPECT_RECORD_ID")
|
|
1055
|
+
return true;
|
|
1056
|
+
const inferred = inferredPublishOutputType(envelope, ctx);
|
|
1057
|
+
const multiple = envelope.multiple === true;
|
|
1058
|
+
return inferred.fieldType !== envelope.fieldType || inferred.multiple !== multiple;
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* An on-demand parameter exported as a trigger envelope because a record
|
|
1062
|
+
* field owns its display name. Both the quoted JSON string and the
|
|
1063
|
+
* jsonencode form decode to the declared parameter.
|
|
1064
|
+
*/
|
|
1065
|
+
function shadowedOnDemandParamFromEnvelope(value, ctx) {
|
|
1066
|
+
if (ctx.trigger.type !== "elementum_on_demand_trigger")
|
|
1067
|
+
return undefined;
|
|
1068
|
+
const raw = isTfExpr(value) && value.$expr === "jsonencode" ? value.value : value;
|
|
1069
|
+
let parsed = raw;
|
|
1070
|
+
if (typeof raw === "string") {
|
|
1071
|
+
if (!raw.startsWith("{"))
|
|
1072
|
+
return undefined;
|
|
1073
|
+
try {
|
|
1074
|
+
parsed = JSON.parse(raw);
|
|
1075
|
+
}
|
|
1076
|
+
catch {
|
|
1077
|
+
return undefined;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
if (!isObject(parsed) || !isObject(parsed.triggerReference) || typeof parsed.triggerReference.name !== "string") {
|
|
1081
|
+
return undefined;
|
|
1082
|
+
}
|
|
1083
|
+
if (isObject(parsed.taskReference) || isObject(parsed.variableReference) || isObject(parsed.forEachReference)) {
|
|
1084
|
+
return undefined;
|
|
1085
|
+
}
|
|
1086
|
+
const wireName = parsed.triggerReference.name;
|
|
1087
|
+
if (wireName.startsWith("record."))
|
|
1088
|
+
return undefined;
|
|
1089
|
+
const declared = isDeclaredOnDemandParameter(ctx.trigger, wireName)
|
|
1090
|
+
? wireName
|
|
1091
|
+
: declaredOnDemandInputForWireName(ctx.trigger, wireName);
|
|
1092
|
+
if (declared === undefined)
|
|
1093
|
+
return undefined;
|
|
1094
|
+
const parameter = Array.isArray(ctx.trigger.attrs.parameters)
|
|
1095
|
+
? ctx.trigger.attrs.parameters.find((candidate) => isObject(candidate) && candidate.name === declared)
|
|
1096
|
+
: undefined;
|
|
1097
|
+
if (!isObject(parameter) || parameter.type === "record" || parameter.type === "user")
|
|
1098
|
+
return undefined;
|
|
1099
|
+
return declared;
|
|
1100
|
+
}
|
|
1036
1101
|
/** decodeValue, upgrading a stringified ValueReference envelope (edk#1646). */
|
|
1037
1102
|
function decodeValueOrStringifiedRef(value, ctx, diagnostics, where) {
|
|
1038
1103
|
if (typeof value === "string") {
|
|
@@ -1042,6 +1107,17 @@ function decodeValueOrStringifiedRef(value, ctx, diagnostics, where) {
|
|
|
1042
1107
|
}
|
|
1043
1108
|
return decodeValue(value, ctx);
|
|
1044
1109
|
}
|
|
1110
|
+
function canonicalTriggerRecordIdSlot(value, ctx) {
|
|
1111
|
+
if ((ctx.trigger.type === "elementum_record_created_trigger" || ctx.trigger.type === "elementum_record_updated_trigger") &&
|
|
1112
|
+
isObject(value) &&
|
|
1113
|
+
value.kind === "triggerRef" &&
|
|
1114
|
+
Array.isArray(value.path) &&
|
|
1115
|
+
((value.path.length === 1 && value.path[0] === "recordId") ||
|
|
1116
|
+
(value.path.length === 2 && value.path[0] === "record" && value.path[1] === "10000001-2000-4000-a000-800000000000"))) {
|
|
1117
|
+
return { ...value, path: ["record"] };
|
|
1118
|
+
}
|
|
1119
|
+
return value;
|
|
1120
|
+
}
|
|
1045
1121
|
function triggerRefPath(path, ctx) {
|
|
1046
1122
|
const names = pathNames(path);
|
|
1047
1123
|
if (names.length !== 1)
|
|
@@ -1722,6 +1798,9 @@ function decodeValue(value, ctx) {
|
|
|
1722
1798
|
if (payloadKey !== undefined)
|
|
1723
1799
|
return { kind: "triggerRef", path: ["attachment", payloadKey] };
|
|
1724
1800
|
}
|
|
1801
|
+
const shadowedParam = shadowedOnDemandParamFromEnvelope(value, ctx);
|
|
1802
|
+
if (shadowedParam !== undefined)
|
|
1803
|
+
return { kind: "triggerRef", path: [shadowedParam] };
|
|
1725
1804
|
if (isTfExpr(value)) {
|
|
1726
1805
|
if (value.$expr === "template") {
|
|
1727
1806
|
return { kind: "template", parts: value.parts.map((part) => typeof part === "string" ? part : decodeValue(part, ctx)) };
|
|
@@ -2237,6 +2316,7 @@ function fieldRef(value, ctx) {
|
|
|
2237
2316
|
? {
|
|
2238
2317
|
foreign: {
|
|
2239
2318
|
entityType: foreign.ownerKind ?? "app",
|
|
2319
|
+
...(foreign.ownerKind === undefined ? { ownerKindUnknown: true } : {}),
|
|
2240
2320
|
name: foreign.ownerName ?? foreign.ownerRefName,
|
|
2241
2321
|
...(foreign.ownerNamespace !== undefined ? { namespace: foreign.ownerNamespace } : {}),
|
|
2242
2322
|
...(foreign.fieldName !== undefined ? { fieldName: foreign.fieldName } : {}),
|
|
@@ -2261,6 +2341,7 @@ function fieldRef(value, ctx) {
|
|
|
2261
2341
|
? {
|
|
2262
2342
|
foreign: {
|
|
2263
2343
|
entityType: foreign.ownerKind ?? "app",
|
|
2344
|
+
...(foreign.ownerKind === undefined ? { ownerKindUnknown: true } : {}),
|
|
2264
2345
|
name: foreign.ownerName ?? foreign.ownerRefName,
|
|
2265
2346
|
...(foreign.ownerNamespace !== undefined ? { namespace: foreign.ownerNamespace } : {}),
|
|
2266
2347
|
...(foreign.fieldName !== undefined ? { fieldName: foreign.fieldName } : {}),
|
|
@@ -2635,12 +2716,14 @@ function decodeFilterReferenceEnvelope(value, ctx, outputName, role) {
|
|
|
2635
2716
|
: schemaValue;
|
|
2636
2717
|
const outputTypes = outputFieldTypesFromScriptSchema(schema);
|
|
2637
2718
|
const declared = scriptOutputReferenceIsDeclared(outputTypes, taskRef.name);
|
|
2638
|
-
if (
|
|
2639
|
-
if (raw.multiple === true || raw.fieldType === "DECIMAL") {
|
|
2719
|
+
if (!declared && taskRef.name.startsWith("result.")) {
|
|
2720
|
+
if (role === "left" && (raw.multiple === true || raw.fieldType === "DECIMAL")) {
|
|
2640
2721
|
throw new EntityTfError(`execute-script reference "${taskRef.name}" is absent from its output schema and its ` +
|
|
2641
2722
|
`${raw.multiple === true ? "multiple" : "DECIMAL"} envelope cannot round-trip losslessly`);
|
|
2642
2723
|
}
|
|
2643
|
-
|
|
2724
|
+
if (role === "left" || role === "envelope" || outputName !== undefined) {
|
|
2725
|
+
return { ...decoded, undeclaredScriptOutput: true };
|
|
2726
|
+
}
|
|
2644
2727
|
}
|
|
2645
2728
|
}
|
|
2646
2729
|
return decoded;
|
|
@@ -2887,7 +2970,7 @@ function triggerFromBlock(block, ctx) {
|
|
|
2887
2970
|
// approval_chain_template_id is genuinely omittable on the platform
|
|
2888
2971
|
// (edk#712) - a null/never-set template means "any", not "unresolved".
|
|
2889
2972
|
if (block.attrs.approval_chain_template_id === undefined) {
|
|
2890
|
-
return { kind, app, status: block.attrs.status };
|
|
2973
|
+
return { kind, app, status: block.attrs.status, ...(filter ? { filter } : {}) };
|
|
2891
2974
|
}
|
|
2892
2975
|
const approvalChain = typeof block.attrs.approval_chain_template_id === "string"
|
|
2893
2976
|
? block.attrs.approval_chain_template_id
|
|
@@ -2895,7 +2978,7 @@ function triggerFromBlock(block, ctx) {
|
|
|
2895
2978
|
if (typeof approvalChain !== "string" && (!isObject(approvalChain) || approvalChain.kind !== "approvalChain")) {
|
|
2896
2979
|
throw new EntityTfError("approval trigger has an unreconstructable approval chain");
|
|
2897
2980
|
}
|
|
2898
|
-
return { kind, app, approvalChain: approvalChain, status: block.attrs.status };
|
|
2981
|
+
return { kind, app, approvalChain: approvalChain, status: block.attrs.status, ...(filter ? { filter } : {}) };
|
|
2899
2982
|
}
|
|
2900
2983
|
case "dataMine":
|
|
2901
2984
|
{
|
|
@@ -2982,6 +3065,9 @@ function taskArgs(block, factory, ctx, taskDiagnostics) {
|
|
|
2982
3065
|
? field.fieldKey
|
|
2983
3066
|
: `${UNRESOLVED_FIELD_MARKER}${field.uuid}`;
|
|
2984
3067
|
const decodedValue = decodeFieldAssignmentValue(item.value, ctx, taskDiagnostics, `${block.type}.${block.label} field ${field.kind === "field" ? field.fieldKey : field.uuid}`);
|
|
3068
|
+
const canonicalValue = factory === "createRecord" || factory === "updateField"
|
|
3069
|
+
? canonicalTriggerRecordIdSlot(decodedValue, ctx)
|
|
3070
|
+
: decodedValue;
|
|
2985
3071
|
const foreignInfo = field.kind === "field" && field.foreign !== undefined
|
|
2986
3072
|
? {
|
|
2987
3073
|
foreignFieldName: field.foreign.fieldName,
|
|
@@ -3002,12 +3088,12 @@ function taskArgs(block, factory, ctx, taskDiagnostics) {
|
|
|
3002
3088
|
values[fieldKey] = item.update_mode === "add" || foreignInfo !== undefined || platformFieldId !== undefined
|
|
3003
3089
|
? {
|
|
3004
3090
|
__fieldAssignment: true,
|
|
3005
|
-
value:
|
|
3091
|
+
value: canonicalValue,
|
|
3006
3092
|
...(item.update_mode === "add" ? { updateMode: "add" } : {}),
|
|
3007
3093
|
...(foreignInfo !== undefined ? foreignInfo : {}),
|
|
3008
3094
|
...(platformFieldId !== undefined ? { platformFieldId } : {}),
|
|
3009
3095
|
}
|
|
3010
|
-
:
|
|
3096
|
+
: canonicalValue;
|
|
3011
3097
|
}
|
|
3012
3098
|
args.values = values;
|
|
3013
3099
|
continue;
|
|
@@ -3548,9 +3634,12 @@ function taskArgs(block, factory, ctx, taskDiagnostics) {
|
|
|
3548
3634
|
continue;
|
|
3549
3635
|
}
|
|
3550
3636
|
const arg = ATTR_TO_ARG[attr] ?? attr.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
3551
|
-
|
|
3637
|
+
const decoded = (attr === "record_reference" || attr === "record_id") && (factory === "createRecord" || factory === "updateField")
|
|
3552
3638
|
? decodeValueOrStringifiedRef(value, ctx, taskDiagnostics, `${block.type}.${block.label} ${attr}`)
|
|
3553
3639
|
: decodeValue(value, ctx);
|
|
3640
|
+
args[arg] = attr === "record_reference" && factory === "updateField"
|
|
3641
|
+
? canonicalTriggerRecordIdSlot(decoded, ctx)
|
|
3642
|
+
: decoded;
|
|
3554
3643
|
}
|
|
3555
3644
|
if (["recordSearch", "createRecord", "updateField", "bulkUpdateFields"].includes(factory))
|
|
3556
3645
|
args.app ??= appRef(ctx.appRefName);
|
|
@@ -3700,8 +3789,8 @@ function taskRefKey(block, automationLabel, appTfLabel) {
|
|
|
3700
3789
|
* conditions that make real extraction fail (zero triggers, an
|
|
3701
3790
|
* unrecognized task kind) so it over-collects rather than under-collects.
|
|
3702
3791
|
* More than one trigger throws {@link UnsupportedMultiTriggerError}. The
|
|
3703
|
-
* stream extractor
|
|
3704
|
-
*
|
|
3792
|
+
* stream extractor soft-skips those automations (diagnostic + skipped +
|
|
3793
|
+
* releaseIfManaged), so the rest of the app can still adopt (#1785).
|
|
3705
3794
|
* A false positive
|
|
3706
3795
|
* here just leaves one more resource unmanaged; a false negative would
|
|
3707
3796
|
* silently destroy a live automation on apply.
|
|
@@ -3882,9 +3971,9 @@ function unresolvedAuthoringValues(doc) {
|
|
|
3882
3971
|
/**
|
|
3883
3972
|
* EDK does not author multi-trigger automations; apps should keep one
|
|
3884
3973
|
* trigger and call the shared logic with a run-automation action. Stream
|
|
3885
|
-
* extraction
|
|
3886
|
-
*
|
|
3887
|
-
*
|
|
3974
|
+
* extraction soft-skips every one of these (warn + skip + releaseIfManaged)
|
|
3975
|
+
* so the rest of the app can still adopt (#1785). Direct `automationFromTf`
|
|
3976
|
+
* still throws so callers that need a hard signal can catch it.
|
|
3888
3977
|
*/
|
|
3889
3978
|
export class UnsupportedMultiTriggerError extends EntityTfError {
|
|
3890
3979
|
automationName;
|
|
@@ -3897,6 +3986,18 @@ export class UnsupportedMultiTriggerError extends EntityTfError {
|
|
|
3897
3986
|
this.triggerCount = triggerCount;
|
|
3898
3987
|
}
|
|
3899
3988
|
}
|
|
3989
|
+
/**
|
|
3990
|
+
* A bare service_account_id belongs to an app this export does not contain.
|
|
3991
|
+
* Pull cannot print a serviceAccountRef until that app is in the workspace,
|
|
3992
|
+
* and printing nothing would clear the live account.
|
|
3993
|
+
*/
|
|
3994
|
+
export class UnresolvedForeignServiceAccountError extends EntityTfError {
|
|
3995
|
+
constructor(automationLabel) {
|
|
3996
|
+
super(`${AUTOMATION_RESOURCE_TYPE}.${automationLabel}: service_account_id names a service account outside this export ` +
|
|
3997
|
+
"that no pulled app in state owns; pull the app that owns it first");
|
|
3998
|
+
this.name = "UnresolvedForeignServiceAccountError";
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
3900
4001
|
/**
|
|
3901
4002
|
* #1320: a task reads the current item of a loop that doesn't enclose it.
|
|
3902
4003
|
* Pull skips the automation like any other exclusion, and additionally
|
|
@@ -3912,14 +4013,14 @@ export class ForEachItemOutsideLoopError extends EntityTfError {
|
|
|
3912
4013
|
}
|
|
3913
4014
|
}
|
|
3914
4015
|
/** Extract one app- or element-owned automation graph from an ei export. */
|
|
3915
|
-
function automationFromTfDocument(doc, automationLabel, appRefName, foreignFieldRefsById, foreignFieldRefsByDataAddress, foreignTableRefsById, picklistOptionLabelById, fieldNamesByOwnerRefName, foreignAppRefNames, foreignElementRefNames, procedureKeysByDiscriminator, foreignTaskRefNames, groupKeysByName) {
|
|
4016
|
+
function automationFromTfDocument(doc, automationLabel, appRefName, foreignFieldRefsById, foreignFieldRefsByDataAddress, foreignTableRefsById, picklistOptionLabelById, fieldNamesByOwnerRefName, foreignAppRefNames, foreignElementRefNames, procedureKeysByDiscriminator, foreignTaskRefNames, groupKeysByName, serviceAccountsById) {
|
|
3916
4017
|
const automation = doc.blocks.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE && block.label === automationLabel);
|
|
3917
4018
|
if (automation === undefined)
|
|
3918
4019
|
throw new EntityTfError(`automation resource "${automationLabel}" not found`);
|
|
3919
4020
|
const triggers = doc.blocks.filter((block) => block.kind === "resource" && AUTOMATION_TRIGGER_TYPE_SET.has(block.type ?? "") && references(block.attrs.automation, AUTOMATION_RESOURCE_TYPE, automationLabel));
|
|
3920
|
-
// N > 1 is a product non-support
|
|
3921
|
-
//
|
|
3922
|
-
//
|
|
4021
|
+
// N > 1 is a product non-support. Throw before later structural checks so
|
|
4022
|
+
// extractAutomations can soft-skip the whole graph (#1785) instead of
|
|
4023
|
+
// partially decoding a shape EDK cannot author.
|
|
3923
4024
|
if (triggers.length > 1) {
|
|
3924
4025
|
const name = typeof automation.attrs.name === "string" && automation.attrs.name !== "" ? automation.attrs.name : automationLabel;
|
|
3925
4026
|
throw new UnsupportedMultiTriggerError(name, triggers.length);
|
|
@@ -4096,6 +4197,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4096
4197
|
stagesByKey.set(item.key, item.name);
|
|
4097
4198
|
}
|
|
4098
4199
|
}
|
|
4200
|
+
const stringifiedValueReferences = { unresolved: false };
|
|
4099
4201
|
const ctx = {
|
|
4100
4202
|
appRefName,
|
|
4101
4203
|
appTfLabel: app.label,
|
|
@@ -4119,6 +4221,7 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4119
4221
|
...(foreignTaskRefNames !== undefined && { foreignTaskRefNames }),
|
|
4120
4222
|
...(procedureKeysByDiscriminator !== undefined && { procedureKeysByDiscriminator }),
|
|
4121
4223
|
...(groupKeysByName !== undefined && { groupKeysByName }),
|
|
4224
|
+
stringifiedValueReferences,
|
|
4122
4225
|
};
|
|
4123
4226
|
let serviceAccountName;
|
|
4124
4227
|
const serviceAccountValue = automation.attrs.service_account_id;
|
|
@@ -4139,6 +4242,18 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4139
4242
|
}
|
|
4140
4243
|
}
|
|
4141
4244
|
}
|
|
4245
|
+
let serviceAccountAppRefName;
|
|
4246
|
+
if (typeof serviceAccountValue === "string" && isUuid(serviceAccountValue) && serviceAccountsById !== undefined) {
|
|
4247
|
+
const owned = serviceAccountsById.get(serviceAccountValue);
|
|
4248
|
+
if (owned !== undefined) {
|
|
4249
|
+
serviceAccountName = owned.name;
|
|
4250
|
+
if (owned.appRefName !== appRefName)
|
|
4251
|
+
serviceAccountAppRefName = owned.appRefName;
|
|
4252
|
+
}
|
|
4253
|
+
else {
|
|
4254
|
+
throw new UnresolvedForeignServiceAccountError(automationLabel);
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4142
4257
|
const dependencyOrder = new Map();
|
|
4143
4258
|
if (publish && Array.isArray(publish.attrs.depends_on))
|
|
4144
4259
|
publish.attrs.depends_on.forEach((dep, index) => { const ref = resourceRef(dep); if (ref)
|
|
@@ -4313,7 +4428,8 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4313
4428
|
...(typeof automation.attrs.description === "string" ? { description: automation.attrs.description } : {}),
|
|
4314
4429
|
...(typeof automation.attrs.triggers_other_automations === "boolean" ? { triggersOtherAutomations: automation.attrs.triggers_other_automations } : {}),
|
|
4315
4430
|
...(serviceAccountName !== undefined ? { serviceAccountName } : {}),
|
|
4316
|
-
|
|
4431
|
+
...(serviceAccountAppRefName !== undefined ? { serviceAccountAppRefName } : {}),
|
|
4432
|
+
status: automation.attrs.status === "INACTIVE" ? "INACTIVE" : publish ? "ACTIVE" : "DRAFT",
|
|
4317
4433
|
trigger: triggerFromBlock(trigger, ctx),
|
|
4318
4434
|
tasks: topTasks,
|
|
4319
4435
|
...(outputs && outputs.length > 0 ? { outputs } : {}),
|
|
@@ -4332,9 +4448,10 @@ function automationFromTfDocument(doc, automationLabel, appRefName, foreignField
|
|
|
4332
4448
|
...taskDiagnostics.map((message) => `automation "${automationLabel}": ${message}`),
|
|
4333
4449
|
],
|
|
4334
4450
|
}),
|
|
4451
|
+
...(stringifiedValueReferences.unresolved ? { stringifiedValueReferences: true } : {}),
|
|
4335
4452
|
};
|
|
4336
4453
|
}
|
|
4337
|
-
export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth) {
|
|
4454
|
+
export function automationFromTf(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth) {
|
|
4338
4455
|
if (Array.isArray(first)) {
|
|
4339
4456
|
const ctx = second;
|
|
4340
4457
|
const automationBlock = first.find((block) => block.kind === "resource" && block.type === AUTOMATION_RESOURCE_TYPE);
|
|
@@ -4343,7 +4460,7 @@ export function automationFromTf(first, second, third, fourth, fifth, sixth, sev
|
|
|
4343
4460
|
throw new EntityTfError(`automation graph has no ${AUTOMATION_RESOURCE_TYPE} resource, so its resources (${addresses.join(", ") || "none"}) cannot be pulled`);
|
|
4344
4461
|
}
|
|
4345
4462
|
try {
|
|
4346
|
-
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);
|
|
4463
|
+
const result = automationFromTfDocument({ blocks: [...first] }, automationBlock.label, ctx.ownerHandle, ctx.foreignFieldRefsById, ctx.foreignFieldRefsByDataAddress, ctx.foreignTableRefsById, ctx.picklistOptionLabelById, ctx.fieldNamesByOwnerRefName, ctx.foreignAppRefNames, ctx.foreignElementRefNames, ctx.procedureKeysByDiscriminator, ctx.foreignTaskRefNames, ctx.groupKeysByName, ctx.serviceAccountsById);
|
|
4347
4464
|
if (result.diagnostics)
|
|
4348
4465
|
ctx.diagnostics.push(...result.diagnostics);
|
|
4349
4466
|
return { automation: result.ast };
|
|
@@ -4356,5 +4473,5 @@ export function automationFromTf(first, second, third, fourth, fifth, sixth, sev
|
|
|
4356
4473
|
return { skippedReason: message };
|
|
4357
4474
|
}
|
|
4358
4475
|
}
|
|
4359
|
-
return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth);
|
|
4476
|
+
return automationFromTfDocument(first, second, third ?? "", fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth, thirteenth, fourteenth);
|
|
4360
4477
|
}
|