@elementumai/edk 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -6
- package/dist-sdk/src/catalog/factories.d.ts +7 -1
- package/dist-sdk/src/catalog/factories.js +2 -0
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +1 -1
- package/dist-sdk/src/catalog/org.js +79 -34
- package/dist-sdk/src/catalog/token.js +5 -0
- package/dist-sdk/src/catalog/types.d.ts +7 -1
- package/dist-sdk/src/catalog/types.js +3 -0
- package/dist-sdk/src/core/system-fields.d.ts +1 -1
- package/dist-sdk/src/core/system-fields.js +1 -1
- package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
- package/dist-sdk/src/core/triggers/on-demand.js +3 -0
- package/dist-sdk/src/core/types/app.d.ts +6 -0
- package/dist-sdk/src/engine/build/context.d.ts +3 -0
- package/dist-sdk/src/engine/coverage-gaps.d.ts +5 -0
- package/dist-sdk/src/engine/coverage-gaps.js +9 -0
- package/dist-sdk/src/engine/ei/run.d.ts +20 -1
- package/dist-sdk/src/engine/ei/run.js +102 -14
- package/dist-sdk/src/engine/pull/authored-address.js +42 -6
- package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
- package/dist-sdk/src/engine/pull/authored-root.js +306 -0
- package/dist-sdk/src/engine/pull/context.d.ts +10 -0
- package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
- package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
- package/dist-sdk/src/engine/pull/org.d.ts +1 -0
- package/dist-sdk/src/engine/pull/org.js +2 -0
- package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
- package/dist-sdk/src/engine/pull/partition.js +43 -0
- package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
- package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
- package/dist-sdk/src/engine/pull/ref-only.d.ts +22 -0
- package/dist-sdk/src/engine/pull/ref-only.js +59 -1
- package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
- package/dist-sdk/src/engine/pull/source-resources.js +110 -0
- package/dist-sdk/src/engine/pull/stream-root.d.ts +148 -0
- package/dist-sdk/src/engine/pull/stream-root.js +563 -0
- package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
- package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
- package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +9 -1
- package/dist-sdk/src/entities/access-policy/from-tf.js +25 -4
- package/dist-sdk/src/entities/access-policy/module.js +5 -0
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
- package/dist-sdk/src/entities/agent/build.d.ts +52 -1
- package/dist-sdk/src/entities/agent/build.js +34 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -0
- package/dist-sdk/src/entities/agent/from-tf.d.ts +34 -1
- package/dist-sdk/src/entities/agent/from-tf.js +262 -2
- package/dist-sdk/src/entities/agent/index.d.ts +1 -1
- package/dist-sdk/src/entities/agent/to-tf.d.ts +8 -10
- package/dist-sdk/src/entities/agent/to-tf.js +158 -14
- package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
- package/dist-sdk/src/entities/app/build.d.ts +34 -14
- package/dist-sdk/src/entities/app/build.js +93 -16
- package/dist-sdk/src/entities/app/from-tf.js +25 -11
- package/dist-sdk/src/entities/app/index.d.ts +1 -0
- package/dist-sdk/src/entities/app/index.js +1 -0
- package/dist-sdk/src/entities/app/module.js +1 -0
- package/dist-sdk/src/entities/app/stage-keys.d.ts +20 -5
- package/dist-sdk/src/entities/app/stage-keys.js +43 -9
- package/dist-sdk/src/entities/app/to-tf.js +2 -0
- package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
- package/dist-sdk/src/entities/approval-chain/build.js +120 -8
- package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
- package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
- package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
- package/dist-sdk/src/entities/approval-chain/index.js +4 -1
- package/dist-sdk/src/entities/approval-chain/module.js +23 -5
- package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
- package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
- package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
- package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
- package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
- package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
- package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
- package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
- package/dist-sdk/src/entities/automation/build.d.ts +50 -24
- package/dist-sdk/src/entities/automation/build.js +86 -33
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +52 -8
- package/dist-sdk/src/entities/automation/from-tf.d.ts +38 -6
- package/dist-sdk/src/entities/automation/from-tf.js +855 -157
- package/dist-sdk/src/entities/automation/index.d.ts +2 -1
- package/dist-sdk/src/entities/automation/index.js +1 -0
- package/dist-sdk/src/entities/automation/module.d.ts +4 -3
- package/dist-sdk/src/entities/automation/module.js +33 -12
- package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
- package/dist-sdk/src/entities/automation/refs-read.js +48 -0
- package/dist-sdk/src/entities/automation/run-target.d.ts +2 -0
- package/dist-sdk/src/entities/automation/run-target.js +5 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +2 -1
- package/dist-sdk/src/entities/automation/script-code.js +82 -1
- package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
- package/dist-sdk/src/entities/automation/script-lint.js +418 -0
- package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
- package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +12 -1
- package/dist-sdk/src/entities/automation/task-output-labels.js +32 -1
- package/dist-sdk/src/entities/automation/tasks.d.ts +76 -18
- package/dist-sdk/src/entities/automation/tasks.js +52 -15
- package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -0
- package/dist-sdk/src/entities/automation/to-tf.js +585 -97
- package/dist-sdk/src/entities/automation/triggers.d.ts +48 -23
- package/dist-sdk/src/entities/automation/triggers.js +27 -12
- package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
- package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
- package/dist-sdk/src/entities/chart/build.d.ts +18 -2
- package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
- package/dist-sdk/src/entities/chart/from-tf.js +28 -1
- package/dist-sdk/src/entities/chart/index.d.ts +1 -1
- package/dist-sdk/src/entities/chart/printer.js +5 -2
- package/dist-sdk/src/entities/chart/to-tf.js +38 -3
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +3 -0
- package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
- package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +45 -6
- package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
- package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
- package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
- package/dist-sdk/src/entities/element/build.js +2 -1
- package/dist-sdk/src/entities/element/from-tf.js +15 -2
- package/dist-sdk/src/entities/element/module.js +3 -0
- package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
- package/dist-sdk/src/entities/element/system-fields.js +23 -0
- package/dist-sdk/src/entities/element/to-tf.js +2 -0
- package/dist-sdk/src/entities/field/build.d.ts +9 -0
- package/dist-sdk/src/entities/field/from-tf.d.ts +29 -1
- package/dist-sdk/src/entities/field/from-tf.js +99 -6
- package/dist-sdk/src/entities/field/module.js +12 -2
- package/dist-sdk/src/entities/field/to-tf.d.ts +13 -3
- package/dist-sdk/src/entities/field/to-tf.js +90 -46
- package/dist-sdk/src/entities/org/category.js +1 -0
- package/dist-sdk/src/entities/org/index.d.ts +1 -0
- package/dist-sdk/src/entities/org/index.js +1 -0
- package/dist-sdk/src/entities/org/role.js +5 -0
- package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
- package/dist-sdk/src/entities/org/voice-auth.js +33 -0
- package/dist-sdk/src/entities/organization/build.d.ts +3 -0
- package/dist-sdk/src/entities/organization/build.js +2 -0
- package/dist-sdk/src/entities/organization/index.d.ts +1 -0
- package/dist-sdk/src/entities/organization/index.js +1 -0
- package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/organization/to-tf.js +59 -1
- package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
- package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
- package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
- package/dist-sdk/src/entities/phone-service/build.js +1 -0
- package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
- package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
- package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
- package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
- package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
- package/dist-sdk/src/entities/relationship/from-tf.js +7 -2
- package/dist-sdk/src/entities/relationship/module.js +2 -2
- package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
- package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
- package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
- package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
- package/dist-sdk/src/entities/role/permission-levels.js +78 -0
- package/dist-sdk/src/entities/role/to-tf.js +32 -2
- package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
- package/dist-sdk/src/entities/service-account/module.js +9 -1
- package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
- package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
- package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
- package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
- package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
- package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +4 -0
- package/dist-sdk/src/entities/shared/filters/index.d.ts +85 -14
- package/dist-sdk/src/entities/shared/filters/index.js +18 -6
- package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
- package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
- package/dist-sdk/src/entities/shared/filters/print.js +9 -5
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +12 -7
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +9 -5
- package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
- package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
- package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
- package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
- package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
- package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
- package/dist-sdk/src/entities/skill/module.js +2 -0
- package/dist-sdk/src/entities/sla/build.d.ts +96 -0
- package/dist-sdk/src/entities/sla/build.js +124 -0
- package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
- package/dist-sdk/src/entities/sla/from-tf.js +164 -0
- package/dist-sdk/src/entities/sla/index.d.ts +1 -0
- package/dist-sdk/src/entities/sla/index.js +1 -0
- package/dist-sdk/src/entities/sla/module.d.ts +4 -0
- package/dist-sdk/src/entities/sla/module.js +73 -0
- package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
- package/dist-sdk/src/entities/sla/printer.js +84 -0
- package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
- package/dist-sdk/src/entities/sla/to-tf.js +81 -0
- package/dist-sdk/src/entities/table/build.d.ts +7 -2
- package/dist-sdk/src/entities/table/build.js +22 -1
- package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
- package/dist-sdk/src/entities/table/from-tf.js +89 -14
- package/dist-sdk/src/entities/table/index.d.ts +1 -1
- package/dist-sdk/src/entities/table/to-tf.js +41 -2
- package/dist-sdk/src/entities/task/from-tf.js +2 -1
- package/dist-sdk/src/entities/task/to-tf.js +1 -0
- package/dist-sdk/src/entities/view/from-tf.d.ts +8 -4
- package/dist-sdk/src/entities/view/from-tf.js +10 -9
- package/dist-sdk/src/entities/view/module.js +5 -0
- package/dist-sdk/src/entities/widget/from-tf.js +15 -4
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +51 -4
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +20 -2
- package/dist-sdk/src/graph/index.js +19 -0
- package/dist-sdk/src/graph/modules.js +11 -1
- package/dist-sdk/src/graph/resource-types.d.ts +47 -0
- package/dist-sdk/src/graph/resource-types.js +62 -0
- package/dist-sdk/src/graph/types.d.ts +116 -6
- package/package.json +6 -3
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { isUnsafePlatformId } from "../../core/platform-id.js";
|
|
2
2
|
import { EntityTfError } from "../../engine/entity.js";
|
|
3
|
-
import {
|
|
3
|
+
import { expr, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
4
4
|
import { APP_RESOURCE_TYPE } from "../app/module.js";
|
|
5
|
+
import { ELEMENT_RESOURCE_TYPE } from "../element/module.js";
|
|
5
6
|
import { fieldRefToTfValue } from "../field/to-tf.js";
|
|
6
7
|
import { APPROVAL_PROCESS_RESOURCE_TYPE } from "./module.js";
|
|
8
|
+
import { approvalStepsToTf } from "./steps-tf.js";
|
|
7
9
|
export function approvalChainToTf(entity, ctx) {
|
|
8
10
|
if (entity.kind !== "approvalChain")
|
|
9
11
|
throw new EntityTfError(`approvalChainToTf expects approvalChain; got ${entity.kind}`);
|
|
10
12
|
const payload = entity.payload;
|
|
11
13
|
if (payload === null)
|
|
12
14
|
throw new EntityTfError(`approval chain ${entity.refName} has no payload`);
|
|
13
|
-
const
|
|
15
|
+
const scope = ctx.parentScope ?? "app";
|
|
16
|
+
if (scope === "element" && (payload.stage !== undefined || payload.stageId !== undefined)) {
|
|
17
|
+
throw new EntityTfError(`approval chain ${entity.refName}: an element-owned approval process takes no stage`);
|
|
18
|
+
}
|
|
19
|
+
const label = scopedResourceLabel(ctx.appTfLabel, tsLabelToTfLabel(entity.refName), scope);
|
|
14
20
|
const attrs = {
|
|
15
|
-
|
|
21
|
+
...(scope === "element"
|
|
22
|
+
? { element_id: expr.resourceAttr(ELEMENT_RESOURCE_TYPE, ctx.appTfLabel, ["id"]) }
|
|
23
|
+
: { app_id: expr.resourceAttr(APP_RESOURCE_TYPE, ctx.appTfLabel, ["id"]) }),
|
|
16
24
|
name: payload.name ?? "",
|
|
17
25
|
number_of_dynamic_approvers: payload.numberOfDynamicApprovers ?? 0,
|
|
18
26
|
managed_by_automation: payload.managedByAutomation ?? false,
|
|
@@ -35,12 +43,37 @@ export function approvalChainToTf(entity, ctx) {
|
|
|
35
43
|
return field.value;
|
|
36
44
|
if (field.parent !== undefined && field.parent !== "" && field.parent !== ctx.appRefName)
|
|
37
45
|
throw new EntityTfError(`approval chain ${entity.refName}: locked field belongs to ${field.parent}`);
|
|
38
|
-
const value = fieldRefToTfValue(field.fieldType ?? "", field.refName ?? "", ctx.appTfLabel);
|
|
46
|
+
const value = fieldRefToTfValue(field.fieldType ?? "", field.refName ?? "", ctx.appTfLabel, scope, ctx.fieldAddresses, field.resourceKey);
|
|
39
47
|
if (value === undefined)
|
|
40
48
|
throw new EntityTfError(`approval chain ${entity.refName}: locked field ${field.refName ?? ""} has no Terraform mapping`);
|
|
41
49
|
return value;
|
|
42
50
|
});
|
|
43
51
|
}
|
|
52
|
+
if (payload.dynamicChain === true)
|
|
53
|
+
attrs["dynamic_chain"] = true;
|
|
54
|
+
else if (payload.dynamicChain === false)
|
|
55
|
+
attrs["dynamic_chain"] = false;
|
|
56
|
+
if (payload.steps !== undefined) {
|
|
57
|
+
if (ctx.orgRefs === undefined)
|
|
58
|
+
throw new EntityTfError(`approval chain ${entity.refName}: approver steps need org lookups`);
|
|
59
|
+
attrs["approvers"] = approvalStepsToTf(payload.steps, `${APPROVAL_PROCESS_RESOURCE_TYPE}.${label}.approvers`, {
|
|
60
|
+
orgRefs: ctx.orgRefs, ownerTfLabel: ctx.appTfLabel, appRefName: ctx.appRefName, scope,
|
|
61
|
+
diagnostics: ctx.diagnostics ?? [], ...(ctx.fieldAddresses !== undefined ? { fieldAddresses: ctx.fieldAddresses } : {}),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (payload.tableFilterFieldIds !== undefined) {
|
|
65
|
+
attrs["table_filter_field_ids"] = payload.tableFilterFieldIds.map((field) => {
|
|
66
|
+
if (isUnsafePlatformId(field))
|
|
67
|
+
return field.value;
|
|
68
|
+
if (field.parent !== undefined && field.parent !== "" && field.parent !== ctx.appRefName) {
|
|
69
|
+
throw new EntityTfError(`approval chain ${entity.refName}: table filter column belongs to ${field.parent}`);
|
|
70
|
+
}
|
|
71
|
+
const value = fieldRefToTfValue(field.fieldType ?? "", field.refName ?? "", ctx.appTfLabel, scope, ctx.fieldAddresses, field.resourceKey);
|
|
72
|
+
if (value === undefined)
|
|
73
|
+
throw new EntityTfError(`approval chain ${entity.refName}: table filter column ${field.refName ?? ""} has no Terraform mapping`);
|
|
74
|
+
return value;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
44
77
|
const block = { kind: "resource", type: APPROVAL_PROCESS_RESOURCE_TYPE, label, attrs };
|
|
45
78
|
return { blocks: [block], address: `${APPROVAL_PROCESS_RESOURCE_TYPE}.${label}` };
|
|
46
79
|
}
|
|
@@ -7,7 +7,7 @@ import { type Ref, type Simplify, type ValueOrRef } from "../shared/ref.js";
|
|
|
7
7
|
import type { Filter } from "./filter.js";
|
|
8
8
|
import { type ScriptFile, type ScriptInput } from "./script-code.js";
|
|
9
9
|
import * as actionFactories from "./tasks.js";
|
|
10
|
-
import type { ScriptOutputs } from "./tasks.js";
|
|
10
|
+
import type { ExecuteScriptOutput, ScriptOutputs } from "./tasks.js";
|
|
11
11
|
import { type WorkflowOutputDeclaration } from "./workflow-output.js";
|
|
12
12
|
/** Structural empty object — neutral element for the accumulated action map. */
|
|
13
13
|
type EmptyObject = {
|
|
@@ -198,37 +198,63 @@ type WithAction<TMode extends BuilderMode, TItem, TTrigger, TActions extends Rec
|
|
|
198
198
|
*/
|
|
199
199
|
interface ActionMethods<TTrigger, TActions extends Record<string, unknown>, TVars extends Record<string, unknown> = EmptyObject, TMode extends BuilderMode = "root", TItem = never> {
|
|
200
200
|
/**
|
|
201
|
-
* `inputs` is a ctx-lambda mapping input names to
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* `tryExtractFromCurrentSource` in `script-code.ts`) rather than from the
|
|
208
|
-
* transpiled function's `toString()`, which would otherwise reformat a
|
|
209
|
-
* pulled script's exact text on every rebuild. Outside `elementum build`
|
|
210
|
-
* (e.g. constructing an automation directly in a test), the body falls
|
|
211
|
-
* back to `extractScriptBody`'s `toString()` extraction.
|
|
201
|
+
* `inputs` is a ctx-lambda mapping input names to refs/values. `code` is
|
|
202
|
+
* either an inline function (#125) or a `scriptFile(...)` reference to a
|
|
203
|
+
* plain `.js` body. Under `elementum build`, an inline body's text ships
|
|
204
|
+
* byte-exact from the automation file (see `tryExtractFromCurrentSource`);
|
|
205
|
+
* outside build it falls back to `extractScriptBody`'s `toString()`. A
|
|
206
|
+
* `scriptFile` body is the file's text, never type-stripped.
|
|
212
207
|
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
208
|
+
* Downstream `ctx.actions.<name>.result.*` typing:
|
|
209
|
+
* - inline function: from the function's return type;
|
|
210
|
+
* - `scriptFile` with a declared `outputs`: from that schema (#2125);
|
|
211
|
+
* - `scriptFile` with `outputs` omitted or `null`: `Record<string, unknown>`.
|
|
212
|
+
*
|
|
213
|
+
* For an inline function the output schema is also INFERRED from
|
|
214
|
+
* `return {...}` literals (property names statically; types from literals,
|
|
215
|
+
* default text). Pass `outputs` to override a non-text property or a return
|
|
216
|
+
* the scan can't enumerate. Pass `outputs: null` to suppress inference —
|
|
217
|
+
* the printer does this for pulled actions with no platform
|
|
218
|
+
* `output_schema`, so a rebuild doesn't invent one and drift from state.
|
|
219
|
+
* For `scriptFile`, inference from the file is not available at the type
|
|
220
|
+
* level: declare `outputs` when downstream steps need typed results.
|
|
221
|
+
*/
|
|
222
|
+
executeScript<TName extends string, I extends Record<string, ValueOrRef<unknown> | actionFactories.ExecuteScriptListInputToken>, const O extends ScriptOutputs>(name: TName, opts: {
|
|
223
|
+
readonly inputs?: (ctx: NestedActionContext<TTrigger, TActions, TVars, TItem>) => I;
|
|
224
|
+
readonly code: ScriptFile;
|
|
225
|
+
readonly outputs: O;
|
|
226
|
+
}, displayName?: string, hclParent?: "trigger" | string): WithAction<TMode, TItem, TTrigger, TActions, TVars, TName, {
|
|
227
|
+
result: ExecuteScriptOutput<O>["result"];
|
|
228
|
+
textResult: string;
|
|
229
|
+
stringArrayResult: readonly string[];
|
|
230
|
+
numberArrayResult: readonly number[];
|
|
231
|
+
}>;
|
|
232
|
+
/**
|
|
233
|
+
* `scriptFile` with `outputs` omitted, `null`, or typed `ScriptOutputs | null`
|
|
234
|
+
* (or wider): untyped result, as before #2125. A plain non-null
|
|
235
|
+
* `ScriptOutputs` variable still takes the overload above, so each result
|
|
236
|
+
* key is a union of every output value type rather than `unknown`.
|
|
221
237
|
*/
|
|
238
|
+
executeScript<TName extends string, I extends Record<string, ValueOrRef<unknown> | actionFactories.ExecuteScriptListInputToken>>(name: TName, opts: {
|
|
239
|
+
readonly inputs?: (ctx: NestedActionContext<TTrigger, TActions, TVars, TItem>) => I;
|
|
240
|
+
readonly code: ScriptFile;
|
|
241
|
+
readonly outputs?: ScriptOutputs | null;
|
|
242
|
+
}, displayName?: string, hclParent?: "trigger" | string): WithAction<TMode, TItem, TTrigger, TActions, TVars, TName, {
|
|
243
|
+
result: Record<string, unknown>;
|
|
244
|
+
textResult: string;
|
|
245
|
+
stringArrayResult: readonly string[];
|
|
246
|
+
numberArrayResult: readonly number[];
|
|
247
|
+
}>;
|
|
248
|
+
/** Inline function: result keys follow the function's return type. */
|
|
222
249
|
executeScript<TName extends string, I extends Record<string, ValueOrRef<unknown> | actionFactories.ExecuteScriptListInputToken>, R extends Record<string, unknown> = Record<string, unknown>>(name: TName, opts: {
|
|
223
250
|
readonly inputs?: (ctx: NestedActionContext<TTrigger, TActions, TVars, TItem>) => I;
|
|
224
|
-
readonly code: (
|
|
251
|
+
readonly code: (input: ScriptInput<ResolvedRefs<NoInfer<I>>>) => R;
|
|
225
252
|
/**
|
|
226
253
|
* Override the inferred output schema: property name → scalar type or a
|
|
227
254
|
* recursive `{ type: "array", items }` / `{ type: "object", properties }`
|
|
228
255
|
* descriptor; the object form may also carry `name` for the root.
|
|
229
|
-
* `null`
|
|
230
|
-
*
|
|
231
|
-
* option infers from the code body.
|
|
256
|
+
* `null` explicitly means "no schema" and suppresses inference; omitting
|
|
257
|
+
* the option infers from the code body.
|
|
232
258
|
*/
|
|
233
259
|
readonly outputs?: ScriptOutputs | null;
|
|
234
260
|
}, displayName?: string, hclParent?: "trigger" | string): WithAction<TMode, TItem, TTrigger, TActions, TVars, TName, {
|
|
@@ -32,6 +32,7 @@ import { buildContext, createForEachItemProxy } from "../shared/context.js";
|
|
|
32
32
|
import { outputFieldTypesFromScriptSchema, scriptSchemaIsSingleStringArray } from "./output-field-types.js";
|
|
33
33
|
import { isRef } from "../shared/ref.js";
|
|
34
34
|
import { apiTaskCanonicalOutputName, apiTaskJsonRefsKeys, apiTaskRefsIndex, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
|
|
35
|
+
import { memberPath, scriptActionAccess, unwrapUnsafeScriptOutput } from "./unsafe-script-output.js";
|
|
35
36
|
import { extractScriptBody, inferOutputSchema, isScriptFile, readScriptFile, toPlatformScriptBody, tryExtractFromCurrentSource } from "./script-code.js";
|
|
36
37
|
import { serializeNode } from "./serialize.js";
|
|
37
38
|
// Runtime factory imports stay below the public action-native surface. Their
|
|
@@ -284,6 +285,21 @@ function declaredScriptResultProperties(schema) {
|
|
|
284
285
|
}
|
|
285
286
|
return names;
|
|
286
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* What to read in a filter instead of `textResult`: each declared
|
|
290
|
+
* `result.<prop>`, plus `stringArrayResult` for a single text array. With no
|
|
291
|
+
* declared properties, the whole `result`, or a property once the script's
|
|
292
|
+
* outputs declare it.
|
|
293
|
+
*/
|
|
294
|
+
function scriptFilterReadHint(at, schema) {
|
|
295
|
+
const declared = declaredScriptResultProperties(schema);
|
|
296
|
+
const reads = declared === undefined ? [] : [...declared].map((p) => `${at}.result${memberPath(p)}`);
|
|
297
|
+
if (scriptSchemaIsSingleStringArray(schema))
|
|
298
|
+
reads.push(`${at}.stringArrayResult`);
|
|
299
|
+
if (reads.length > 0)
|
|
300
|
+
return `Read ${reads.join(" or ")} instead.`;
|
|
301
|
+
return `Read ${at}.result instead, or add the value to the script's outputs and read it under ${at}.result.`;
|
|
302
|
+
}
|
|
287
303
|
/**
|
|
288
304
|
* A script's declared outputs are read under `result`. A bare
|
|
289
305
|
* `ctx.actions.<script>.<name>` would compile to a `refs["<name>"]` key the
|
|
@@ -293,32 +309,47 @@ function declaredScriptResultProperties(schema) {
|
|
|
293
309
|
* `numberArrayResult`, and `result.<prop>`. `Text Result` / `Result` /
|
|
294
310
|
* `Text List Result` are refs-map keys, not names someone authors (#1656).
|
|
295
311
|
*/
|
|
296
|
-
function assertKnownScriptOutput(name, taskRefKey, schema,
|
|
312
|
+
function assertKnownScriptOutput(name, taskRefKey, schema, undeclared) {
|
|
313
|
+
const at = scriptActionAccess(taskRefKey);
|
|
314
|
+
const task = `executeScript${taskRefKey === undefined ? "" : ` task "${taskRefKey}"`}`;
|
|
315
|
+
// On a filter value, the platform refuses to publish the short
|
|
316
|
+
// `task.<id>.Text Result` reference build writes for `textResult` ("has a
|
|
317
|
+
// value reference that is no longer valid"), whether or not the script
|
|
318
|
+
// declares outputs. A switch condition's left side doesn't reach here (see
|
|
319
|
+
// rewriteTaskOutputRefs). Checked live on the EDK org (#1725, #2221).
|
|
320
|
+
if (name === "textResult" && undeclared === "unsafeOnly") {
|
|
321
|
+
throw new EntityTfError(`${task}: ${at}.textResult can't be read as a filter value; the platform rejects it when the automation is published. ` +
|
|
322
|
+
scriptFilterReadHint(at, schema));
|
|
323
|
+
}
|
|
297
324
|
if (name === "result" || name === "textResult" || EXECUTE_SCRIPT_CONTRACT_OUTPUT_NAMES.has(name))
|
|
298
325
|
return;
|
|
299
326
|
if (name.startsWith("result.")) {
|
|
300
|
-
|
|
301
|
-
// whose script does not declare the property stays a typed envelope on the
|
|
302
|
-
// task `.id` (#1151), which to-tf emits with a diagnostic.
|
|
303
|
-
if (!checkDeclaredResult)
|
|
327
|
+
if (undeclared === "allow")
|
|
304
328
|
return;
|
|
305
329
|
const declared = declaredScriptResultProperties(schema);
|
|
306
|
-
const
|
|
307
|
-
if (declared === undefined || declared.has(
|
|
330
|
+
const output = name.slice("result.".length);
|
|
331
|
+
if (declared === undefined || declared.has(output.split(".")[0] ?? ""))
|
|
308
332
|
return;
|
|
309
333
|
const listed = [...declared].join(", ");
|
|
310
|
-
|
|
311
|
-
|
|
334
|
+
const reads = [...declared].map((p) => `${at}.result${memberPath(p)}`);
|
|
335
|
+
if (scriptSchemaIsSingleStringArray(schema))
|
|
336
|
+
reads.push(`${at}.stringArrayResult`);
|
|
337
|
+
throw new EntityTfError(`${task} has no output "${name}"; declared result properties are ${listed === "" ? "(none)" : listed}.` +
|
|
338
|
+
(undeclared === "unsafeOnly"
|
|
339
|
+
? ` Read a declared output${reads.length > 0 ? ` (${reads.join(" or ")})` : ""}, add ${JSON.stringify(output)} to the script's outputs, ` +
|
|
340
|
+
`or keep a pulled reference the live schema doesn't declare with unsafeScriptOutput(${at}, ${JSON.stringify(output)}) ` +
|
|
341
|
+
`(the platform won't publish the automation while a filter reads it).`
|
|
342
|
+
: ""));
|
|
312
343
|
}
|
|
313
|
-
//
|
|
314
|
-
//
|
|
344
|
+
// A bare name is not a `result.<prop>` read (an undeclared `result.<name>` is
|
|
345
|
+
// handled above). Suggest only declared reads: an undeclared one reads
|
|
346
|
+
// nothing at runtime (#1725).
|
|
315
347
|
const declared = declaredScriptResultProperties(schema);
|
|
316
348
|
const missing = declared !== undefined && !declared.has(name.split(".")[0] ?? "");
|
|
317
|
-
const
|
|
318
|
-
const uses = missing ? [...declared].map((p) => `${at}.result.${p}`) : [`${at}.result.${name}`];
|
|
349
|
+
const uses = missing ? [...declared].map((p) => `${at}.result${memberPath(p)}`) : [`${at}.result${memberPath(name)}`];
|
|
319
350
|
if ((missing || !name.includes(".")) && scriptSchemaIsSingleStringArray(schema))
|
|
320
351
|
uses.push(`${at}.stringArrayResult`);
|
|
321
|
-
throw new EntityTfError(
|
|
352
|
+
throw new EntityTfError(`${task} has no output "${name}"; ` +
|
|
322
353
|
`script outputs are read under result` +
|
|
323
354
|
(missing ? ` and the declared result properties are ${declared.size === 0 ? "(none)" : [...declared].join(", ")}` : "") +
|
|
324
355
|
(uses.length > 0 ? `. Use ${uses.join(" or ")}.` : "."));
|
|
@@ -351,7 +382,7 @@ function assertKnownScriptOutput(name, taskRefKey, schema, checkDeclaredResult)
|
|
|
351
382
|
* - single-scalar-output tasks (see `OUTPUT_KEY_WIRE_NAME`): `output` →
|
|
352
383
|
* the platform's actual output name for that task kind.
|
|
353
384
|
*/
|
|
354
|
-
function rewriteForwardTaskRefName(taskKey, name, taskRefKey, schema,
|
|
385
|
+
function rewriteForwardTaskRefName(taskKey, name, taskRefKey, schema, undeclaredScriptResult = "reject", apiResponseType) {
|
|
355
386
|
if (taskKey === "findRelatedRecords" && FIND_RELATED_RECORDS_COUNT_REF_NAMES.has(name.split(".")[0])) {
|
|
356
387
|
throw findRelatedRecordsTotalCountError(taskRefKey);
|
|
357
388
|
}
|
|
@@ -370,7 +401,7 @@ function rewriteForwardTaskRefName(taskKey, name, taskRefKey, schema, checkDecla
|
|
|
370
401
|
return USER_SEARCH_REF_WIRE_NAMES[name] ?? name;
|
|
371
402
|
}
|
|
372
403
|
if (taskKey === "executeScript") {
|
|
373
|
-
assertKnownScriptOutput(name, taskRefKey, schema,
|
|
404
|
+
assertKnownScriptOutput(name, taskRefKey, schema, undeclaredScriptResult);
|
|
374
405
|
if (name === "textResult")
|
|
375
406
|
return "Text Result";
|
|
376
407
|
}
|
|
@@ -416,14 +447,14 @@ export function rewriteCanonicalOutputRefName(taskKey, name, taskRefKey, schema,
|
|
|
416
447
|
}
|
|
417
448
|
// Workflow outputs are jsonencode envelopes on the task id, not refs-map indexes.
|
|
418
449
|
if (taskKey === "executeScript")
|
|
419
|
-
assertKnownScriptOutput(name, taskRefKey, schema,
|
|
450
|
+
assertKnownScriptOutput(name, taskRefKey, schema, "allow");
|
|
420
451
|
if (taskKey === "api" && name.startsWith("file.")) {
|
|
421
452
|
// apiRequest's file SUB-refs (.file.content / .contentType / .name) have no
|
|
422
453
|
// canonical service_tasks output name of their own — they resolve by the
|
|
423
454
|
// provider's refs-map DISPLAY label ("Content" / "Content Type" / "Name", via
|
|
424
455
|
// API_TASK_REF_WIRE_NAMES). Keep the base display rewrite. Top-level api
|
|
425
456
|
// outputs ARE contract names and ride the envelope as identity.
|
|
426
|
-
return rewriteForwardTaskRefName(taskKey, name, taskRefKey, schema,
|
|
457
|
+
return rewriteForwardTaskRefName(taskKey, name, taskRefKey, schema, "reject", apiResponseType);
|
|
427
458
|
}
|
|
428
459
|
if (taskKey === "api")
|
|
429
460
|
return apiTaskCanonicalOutputName(apiResponseType, name) ?? apiTaskMissingOutput(taskRefKey, name, apiResponseType);
|
|
@@ -486,6 +517,15 @@ export function rewriteCanonicalOutputRefName(taskKey, name, taskRefKey, schema,
|
|
|
486
517
|
}
|
|
487
518
|
return name;
|
|
488
519
|
}
|
|
520
|
+
/** Rename a task's `.record` reference to its whole-record output, in place. */
|
|
521
|
+
function useWholeTaskRecord(value, taskKindByRefKey) {
|
|
522
|
+
const mapped = value?.taskReference;
|
|
523
|
+
if (typeof mapped?.taskRefKey !== "string" || mapped.name !== "record")
|
|
524
|
+
return;
|
|
525
|
+
const wholeRecord = WHOLE_RECORD_REF_WIRE_NAMES[taskKindByRefKey.get(mapped.taskRefKey) ?? ""];
|
|
526
|
+
if (wholeRecord !== undefined)
|
|
527
|
+
mapped.name = wholeRecord;
|
|
528
|
+
}
|
|
489
529
|
/**
|
|
490
530
|
* Walk a serialized wire node and rewrite, in place, the `name` of every task
|
|
491
531
|
* output reference whose target task needs an output-name rewrite. Two wire
|
|
@@ -503,22 +543,25 @@ function rewriteTaskOutputRefs(node, taskKindByRefKey, scriptSchemas,
|
|
|
503
543
|
// those positions.
|
|
504
544
|
canonical = false,
|
|
505
545
|
// Field assignments rebuild an undeclared result.* as the value envelope.
|
|
506
|
-
|
|
546
|
+
undeclaredScriptResult = "reject", apiResponseTypes = new Map(),
|
|
547
|
+
// The reference in a filter's `leftValue` (a switch condition's left side).
|
|
548
|
+
filterLeft = false) {
|
|
507
549
|
if (Array.isArray(node)) {
|
|
508
550
|
for (const item of node)
|
|
509
|
-
rewriteTaskOutputRefs(item, taskKindByRefKey, scriptSchemas, canonical,
|
|
551
|
+
rewriteTaskOutputRefs(item, taskKindByRefKey, scriptSchemas, canonical, undeclaredScriptResult, apiResponseTypes);
|
|
510
552
|
return;
|
|
511
553
|
}
|
|
512
554
|
if (node === null || typeof node !== "object")
|
|
513
555
|
return;
|
|
514
556
|
const rec = node;
|
|
557
|
+
// A script input reads a task's `.record` as the whole record, mapped or not.
|
|
558
|
+
const scriptInputs = rec.executeScript?.inputs;
|
|
559
|
+
if (Array.isArray(scriptInputs)) {
|
|
560
|
+
for (const input of scriptInputs)
|
|
561
|
+
useWholeTaskRecord(input?.value, taskKindByRefKey);
|
|
562
|
+
}
|
|
515
563
|
if (Array.isArray(rec.field_mappings)) {
|
|
516
|
-
|
|
517
|
-
const wholeRecord = typeof mapped?.taskRefKey === "string" && mapped.name === "record"
|
|
518
|
-
? WHOLE_RECORD_REF_WIRE_NAMES[taskKindByRefKey.get(mapped.taskRefKey) ?? ""]
|
|
519
|
-
: undefined;
|
|
520
|
-
if (wholeRecord !== undefined)
|
|
521
|
-
mapped.name = wholeRecord;
|
|
564
|
+
useWholeTaskRecord(rec.value, taskKindByRefKey);
|
|
522
565
|
// Field mappings read a trigger's whole record too, which shares its
|
|
523
566
|
// display name with the record ID (edk#1284); see TRIGGER_WHOLE_RECORD_MARKER.
|
|
524
567
|
const value = rec.value;
|
|
@@ -531,22 +574,32 @@ checkDeclaredScriptResult = true, apiResponseTypes = new Map()) {
|
|
|
531
574
|
const kind = taskKindByRefKey.get(ref.taskRefKey);
|
|
532
575
|
const schema = scriptSchemas.get(ref.taskRefKey);
|
|
533
576
|
const apiResponseType = apiResponseTypes.get(ref.taskRefKey);
|
|
577
|
+
const undeclared = canonical ? "allow" : undeclaredScriptResult;
|
|
578
|
+
const { name, unsafe } = unwrapUnsafeScriptOutput(ref.name, kind, ref.taskRefKey, declaredScriptResultProperties(schema), undeclared);
|
|
534
579
|
ref.name = canonical
|
|
535
|
-
? rewriteCanonicalOutputRefName(kind,
|
|
536
|
-
: rewriteForwardTaskRefName(kind,
|
|
580
|
+
? rewriteCanonicalOutputRefName(kind, name, ref.taskRefKey, schema, apiResponseType)
|
|
581
|
+
: rewriteForwardTaskRefName(kind, name, ref.taskRefKey, schema, unsafe ? "allow" : undeclared, apiResponseType);
|
|
537
582
|
}
|
|
538
583
|
if (rec.type === "TASK" && typeof rec.taskRefKey === "string" && typeof rec.name === "string") {
|
|
539
584
|
// Filter `{type:"TASK"}` shapes never appear in a workflow OUTPUT subtree;
|
|
540
585
|
// keep the display rewrite (#1271's filter path) regardless of `canonical`.
|
|
541
|
-
|
|
586
|
+
const kind = taskKindByRefKey.get(rec.taskRefKey);
|
|
587
|
+
const schema = scriptSchemas.get(rec.taskRefKey);
|
|
588
|
+
const { name, unsafe } = unwrapUnsafeScriptOutput(rec.name, kind, rec.taskRefKey, declaredScriptResultProperties(schema), "unsafeOnly");
|
|
589
|
+
// A left side is written as the `refs["Text Result"]` envelope, which
|
|
590
|
+
// publishes for a script with or without a schema; only the value side's
|
|
591
|
+
// short `task.<id>.Text Result` is rejected (checked live, #2221).
|
|
592
|
+
const leftTextResult = filterLeft && kind === "executeScript" && name === "textResult";
|
|
593
|
+
rec.name = rewriteForwardTaskRefName(kind, name, rec.taskRefKey, schema, unsafe || leftTextResult ? "allow" : "unsafeOnly", apiResponseTypes.get(rec.taskRefKey));
|
|
542
594
|
}
|
|
543
595
|
for (const [key, v] of Object.entries(rec)) {
|
|
544
596
|
// A calc-engine mustache subtree (`calculationReference` → templateReference)
|
|
545
597
|
// keeps the display/forward rewrite even under an output, so its decode
|
|
546
598
|
// (decodeCalculationTaskMustache) stays idempotent.
|
|
547
599
|
const childCanonical = key === "calculationReference" ? false : canonical;
|
|
548
|
-
const childCheck = key === "workflowFields" ?
|
|
549
|
-
|
|
600
|
+
const childCheck = key === "workflowFields" ? "allow" : undeclaredScriptResult;
|
|
601
|
+
const childLeft = key === "leftValue" || (filterLeft && key === "value" && rec.type === "REFERENCE");
|
|
602
|
+
rewriteTaskOutputRefs(v, taskKindByRefKey, scriptSchemas, childCanonical, childCheck, apiResponseTypes, childLeft);
|
|
550
603
|
}
|
|
551
604
|
}
|
|
552
605
|
/**
|
|
@@ -804,11 +857,11 @@ function makeActionBuilder(state, mode = "root", item, loops = {}) {
|
|
|
804
857
|
// Deep copy: the rewrites below mutate in place, and `state.outputs` is
|
|
805
858
|
// shared by every build of this definition (#1536).
|
|
806
859
|
const outputs = state.outputs?.map((o) => structuredClone(o));
|
|
807
|
-
rewriteTaskOutputRefs(tasks, taskKindByRefKey, scriptSchemas, false,
|
|
860
|
+
rewriteTaskOutputRefs(tasks, taskKindByRefKey, scriptSchemas, false, "reject", apiResponseTypes);
|
|
808
861
|
// Workflow OUTPUTS emit the platform's CANONICAL output name (edk#835);
|
|
809
862
|
// task inputs/filters above stay on the display path (#1271 owns them).
|
|
810
863
|
if (outputs)
|
|
811
|
-
rewriteTaskOutputRefs(outputs, taskKindByRefKey, scriptSchemas, /* canonical */ true,
|
|
864
|
+
rewriteTaskOutputRefs(outputs, taskKindByRefKey, scriptSchemas, /* canonical */ true, "reject", apiResponseTypes);
|
|
812
865
|
// Trigger reference names are NOT canonicalized: the authored name is
|
|
813
866
|
// the name, everywhere in EDK. (Mobius canonicalizes reference names in
|
|
814
867
|
// ITS storage — `ValueReference.ofTriggerReference` — but on the tf
|
|
@@ -34,6 +34,7 @@ import { camelCase } from "../../../../pull/util.js";
|
|
|
34
34
|
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
|
+
import { isTextOptionValue } from "../../shared/filters/index.js";
|
|
37
38
|
import { printFilter as printCanonicalFilter } from "../../shared/filters/print.js";
|
|
38
39
|
import { isUuid, sanitizeName, tfLabelToTsLabel } from "../../../engine/tf/labels.js";
|
|
39
40
|
import { UNRESOLVED_FIELD_MARKER } from "../../shared/ref.js";
|
|
@@ -534,6 +535,7 @@ function emptyImports() {
|
|
|
534
535
|
usesScriptInput: false,
|
|
535
536
|
usesRefType: false,
|
|
536
537
|
usesTableSearchTableRef: false,
|
|
538
|
+
usesGroupRef: false,
|
|
537
539
|
};
|
|
538
540
|
}
|
|
539
541
|
/** Folder (inside the automations folder) that holds printed script files. */
|
|
@@ -776,8 +778,12 @@ function renderHeader(ast, imports, _opts) {
|
|
|
776
778
|
return alias ? `${name} as ${alias}` : name;
|
|
777
779
|
});
|
|
778
780
|
lines.push(`import { ${sortedSpecifiers.join(", ")} } from "${sdkPackageSpecifier("automations")}";`);
|
|
779
|
-
|
|
780
|
-
|
|
781
|
+
const catalogNamed = [
|
|
782
|
+
...(imports.usesGroupRef ? ["groupRef"] : []),
|
|
783
|
+
...(imports.usesTableSearchTableRef ? ["tableSearchTableRef"] : []),
|
|
784
|
+
];
|
|
785
|
+
if (catalogNamed.length > 0) {
|
|
786
|
+
lines.push(`import { ${catalogNamed.join(", ")} } from "${sdkPackageSpecifier("catalog")}";`);
|
|
781
787
|
}
|
|
782
788
|
if (imports.usesSecret || imports.usesTemplate || imports.usesUnresolvedField || imports.usesUnsafePlatformId || imports.usesRefType) {
|
|
783
789
|
const coreNamed = [];
|
|
@@ -1058,7 +1064,7 @@ function formatExecuteScript(task, state, indent, refCtx = DEFAULT_CTX) {
|
|
|
1058
1064
|
}
|
|
1059
1065
|
}
|
|
1060
1066
|
if (task.args.outputs !== undefined && task.args.outputs !== null && typeof task.args.outputs === "object") {
|
|
1061
|
-
lines.push(`${configPad}outputs: ${
|
|
1067
|
+
lines.push(`${configPad}outputs: ${printOutputSchemaLiteral(task.args.outputs, indent + 1)},`);
|
|
1062
1068
|
}
|
|
1063
1069
|
else {
|
|
1064
1070
|
// No `output_schema` on the platform resource — print an explicit `null`
|
|
@@ -1592,6 +1598,11 @@ function printArgValue(name, value, state, indent, refCtx) {
|
|
|
1592
1598
|
const fn = trackFactory("requiredSecret", state);
|
|
1593
1599
|
return `${fn}(${quote(value.variable)})`;
|
|
1594
1600
|
}
|
|
1601
|
+
// A Dropdown or Multi-Select assignment's option (#1733).
|
|
1602
|
+
if (isTextOptionValue(value)) {
|
|
1603
|
+
state.imports.filterOps.add("textOption");
|
|
1604
|
+
return `filter.textOption(${quote(value.value)})`;
|
|
1605
|
+
}
|
|
1595
1606
|
if (isRefExpr(value))
|
|
1596
1607
|
return printRef(value, state, refCtx);
|
|
1597
1608
|
if (isFilter(value))
|
|
@@ -1669,23 +1680,32 @@ function printRef(ref, state, refCtx) {
|
|
|
1669
1680
|
if (state.forkJoinBranchTaskRefKeys.has(ref.task) &&
|
|
1670
1681
|
!refCtx.currentForkJoinBranchTaskRefKeys?.has(ref.task) &&
|
|
1671
1682
|
!state.topLevelTaskRefKeys.has(ref.task)) {
|
|
1672
|
-
const
|
|
1673
|
-
|
|
1683
|
+
const receiver = `(${ctxName}.actions as any /* TODO: "${ref.task}" is inside a forkJoin branch, not reachable from here */)${safeMember(ref.task)}`;
|
|
1684
|
+
// Same marker as below for an undeclared script output: build rejects
|
|
1685
|
+
// a plain `result.<name>` in a filter, cast receiver or not (#1725).
|
|
1686
|
+
if (ref.path[0] === "result" && ref.undeclaredScriptOutput === true) {
|
|
1687
|
+
return `${trackFactory("unsafeScriptOutput", state)}(${receiver}, ${quote(ref.path.slice(1).join("."))})`;
|
|
1688
|
+
}
|
|
1689
|
+
return receiver + ref.path.map(safeMember).join("");
|
|
1674
1690
|
}
|
|
1675
1691
|
// `result.<prop>` segments are output-schema property names — typed,
|
|
1676
1692
|
// legitimate — so print them with plain dot/bracket access; only record
|
|
1677
1693
|
// paths keep the unresolved-key as-any heuristic.
|
|
1678
1694
|
if (ref.path[0] === "result") {
|
|
1695
|
+
// The live automation reads a script output its schema doesn't
|
|
1696
|
+
// declare; build accepts that only through this marker (#1725).
|
|
1679
1697
|
if (ref.undeclaredScriptOutput === true) {
|
|
1680
|
-
|
|
1681
|
-
return `(${ctxName}.actions${safeMember(ref.task)}${safeMember(result)} as any /* TODO: live automation references an execute-script output absent from its output schema */)` +
|
|
1682
|
-
rest.map(safeMember).join("");
|
|
1698
|
+
return `${trackFactory("unsafeScriptOutput", state)}(${ctxName}.actions${safeMember(ref.task)}, ${quote(ref.path.slice(1).join("."))})`;
|
|
1683
1699
|
}
|
|
1684
1700
|
return `${ctxName}.actions${safeMember(ref.task)}` + ref.path.map(safeMember).join("");
|
|
1685
1701
|
}
|
|
1686
1702
|
return printPathAccess(`${ctxName}.actions${safeMember(ref.task)}`, ref.path);
|
|
1687
1703
|
}
|
|
1688
1704
|
case "triggerRef": {
|
|
1705
|
+
// The output type has no such property and no index signature (#2643).
|
|
1706
|
+
if (ref.undeclaredHead === true) {
|
|
1707
|
+
return `(${ctxName}.trigger as any /* TODO: trigger ref the trigger output doesn't declare */)${ref.path.map(safeMember).join("")}`;
|
|
1708
|
+
}
|
|
1689
1709
|
// A bare `record.<unresolved-id>` path (no trailing sub-path) — the
|
|
1690
1710
|
// exact shape `unresolvedField` round-trips through the wire. Anything
|
|
1691
1711
|
// with a trailing sub-path (e.g. `.label`) falls back to the generic
|
|
@@ -1858,6 +1878,10 @@ function printRef(ref, state, refCtx) {
|
|
|
1858
1878
|
state.imports.usesSecret = true;
|
|
1859
1879
|
return `secret(${quote(ref.key)})`;
|
|
1860
1880
|
case "orgGroup":
|
|
1881
|
+
if (ref.inOrgCatalog === false) {
|
|
1882
|
+
state.imports.usesGroupRef = true;
|
|
1883
|
+
return `groupRef({ name: ${quote(ref.name)} })`;
|
|
1884
|
+
}
|
|
1861
1885
|
state.imports.usesOrg = true;
|
|
1862
1886
|
return `org.groups${safeMember(ref.groupKey)}`;
|
|
1863
1887
|
case "documentModel":
|
|
@@ -2004,6 +2028,26 @@ function printObjectLiteral(obj, state, indent, refCtx) {
|
|
|
2004
2028
|
});
|
|
2005
2029
|
return `{\n${lines.join("\n")}\n${" ".repeat(indent - 1)}}`;
|
|
2006
2030
|
}
|
|
2031
|
+
/**
|
|
2032
|
+
* An output schema is plain data: a property named `code` or `script` is an
|
|
2033
|
+
* output's type, not a script body, so none of printArgValue's detection applies.
|
|
2034
|
+
*/
|
|
2035
|
+
function printOutputSchemaLiteral(value, indent) {
|
|
2036
|
+
const pad = " ".repeat(indent);
|
|
2037
|
+
const closePad = " ".repeat(indent - 1);
|
|
2038
|
+
if (Array.isArray(value)) {
|
|
2039
|
+
if (value.length === 0)
|
|
2040
|
+
return "[]";
|
|
2041
|
+
return `[\n${value.map((item) => `${pad}${printOutputSchemaLiteral(item, indent + 1)},`).join("\n")}\n${closePad}]`;
|
|
2042
|
+
}
|
|
2043
|
+
if (value && typeof value === "object") {
|
|
2044
|
+
const entries = Object.entries(value);
|
|
2045
|
+
if (entries.length === 0)
|
|
2046
|
+
return "{}";
|
|
2047
|
+
return `{\n${entries.map(([k, v]) => `${pad}${safeKey(k)}: ${printOutputSchemaLiteral(v, indent + 1)},`).join("\n")}\n${closePad}}`;
|
|
2048
|
+
}
|
|
2049
|
+
return literalJson(value);
|
|
2050
|
+
}
|
|
2007
2051
|
function printArrayLiteral(arr, state, indent, refCtx) {
|
|
2008
2052
|
if (arr.length === 0)
|
|
2009
2053
|
return "[]";
|