@elementumai/edk 0.9.18 → 0.9.20
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 +154 -9
- package/dist-sdk/src/catalog/factories.d.ts +35 -1
- package/dist-sdk/src/catalog/factories.js +36 -0
- package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
- package/dist-sdk/src/catalog/from-authoring.js +34 -9
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +2 -2
- package/dist-sdk/src/catalog/org.d.ts +39 -1
- package/dist-sdk/src/catalog/org.js +460 -50
- package/dist-sdk/src/catalog/render.js +6 -6
- package/dist-sdk/src/catalog/token.js +7 -0
- package/dist-sdk/src/catalog/types.d.ts +44 -1
- package/dist-sdk/src/catalog/types.js +13 -0
- package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
- package/dist-sdk/src/core/triggers/on-demand.js +10 -2
- package/dist-sdk/src/engine/build/context.d.ts +1 -1
- package/dist-sdk/src/engine/ei/run.d.ts +149 -0
- package/dist-sdk/src/engine/ei/run.js +1132 -0
- package/dist-sdk/src/engine/logging.d.ts +17 -0
- package/dist-sdk/src/engine/logging.js +18 -0
- package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
- package/dist-sdk/src/engine/pull/ref-only.js +64 -27
- package/dist-sdk/src/engine/pull/result-output.d.ts +8 -0
- package/dist-sdk/src/engine/pull/result-output.js +88 -4
- package/dist-sdk/src/engine/tf/expr.js +39 -14
- package/dist-sdk/src/engine/tf/index.d.ts +3 -3
- package/dist-sdk/src/engine/tf/index.js +2 -2
- package/dist-sdk/src/engine/tf/labels.d.ts +8 -0
- package/dist-sdk/src/engine/tf/labels.js +13 -0
- package/dist-sdk/src/engine/tf/model.d.ts +22 -1
- package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
- package/dist-sdk/src/engine/tf/parse.js +197 -10
- package/dist-sdk/src/engine/tf/render.d.ts +4 -2
- package/dist-sdk/src/engine/tf/render.js +41 -7
- package/dist-sdk/src/engine/validation.d.ts +39 -0
- package/dist-sdk/src/engine/validation.js +85 -0
- package/dist-sdk/src/engine/workspace/loader.js +49 -12
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
- package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +16 -6
- package/dist-sdk/src/entities/agent/build.d.ts +4 -16
- package/dist-sdk/src/entities/agent/build.js +40 -5
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
- package/dist-sdk/src/entities/agent/to-tf.js +6 -3
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +29 -6
- package/dist-sdk/src/entities/app/build.d.ts +98 -19
- package/dist-sdk/src/entities/app/build.js +51 -19
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
- package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
- package/dist-sdk/src/entities/app/from-tf.js +11 -5
- package/dist-sdk/src/entities/app/index.d.ts +6 -5
- package/dist-sdk/src/entities/app/index.js +2 -0
- package/dist-sdk/src/entities/app/module.js +18 -2
- package/dist-sdk/src/entities/app/to-tf.js +21 -11
- package/dist-sdk/src/entities/automation/build.d.ts +49 -6
- package/dist-sdk/src/entities/automation/build.js +163 -19
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +320 -39
- package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
- package/dist-sdk/src/entities/automation/from-tf.js +563 -74
- package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
- package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
- package/dist-sdk/src/entities/automation/index.d.ts +2 -2
- package/dist-sdk/src/entities/automation/index.js +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +2 -0
- package/dist-sdk/src/entities/automation/module.js +93 -8
- package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
- package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
- package/dist-sdk/src/entities/automation/script-code.js +91 -5
- package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
- package/dist-sdk/src/entities/automation/system-ref-name.js +48 -0
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +47 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +53 -4
- package/dist-sdk/src/entities/automation/tasks.js +38 -9
- package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
- package/dist-sdk/src/entities/automation/to-tf.js +647 -167
- package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
- package/dist-sdk/src/entities/automation/triggers.js +4 -0
- package/dist-sdk/src/entities/automation/types.js +1 -0
- package/dist-sdk/src/entities/chart/from-tf.js +33 -17
- package/dist-sdk/src/entities/chart/module.js +3 -1
- package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
- package/dist-sdk/src/entities/chart/printer.js +26 -16
- package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
- package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
- package/dist-sdk/src/entities/chart/to-tf.js +21 -12
- package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
- package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
- package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
- package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +72 -30
- package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
- package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
- package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
- package/dist-sdk/src/entities/element/build.d.ts +33 -13
- package/dist-sdk/src/entities/element/build.js +5 -1
- package/dist-sdk/src/entities/element/from-tf.d.ts +12 -0
- package/dist-sdk/src/entities/element/from-tf.js +64 -3
- package/dist-sdk/src/entities/element/index.d.ts +5 -2
- package/dist-sdk/src/entities/element/index.js +2 -0
- package/dist-sdk/src/entities/element/module.js +11 -3
- package/dist-sdk/src/entities/element/to-tf.js +20 -2
- package/dist-sdk/src/entities/field/build.d.ts +14 -1
- package/dist-sdk/src/entities/field/build.js +3 -0
- package/dist-sdk/src/entities/field/from-tf.d.ts +3 -0
- package/dist-sdk/src/entities/field/from-tf.js +50 -1
- package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
- package/dist-sdk/src/entities/field/media-types.js +30 -0
- package/dist-sdk/src/entities/field/module.js +1 -0
- package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
- package/dist-sdk/src/entities/field/to-tf.js +142 -22
- package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
- package/dist-sdk/src/entities/file-reader/module.js +1 -0
- package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
- package/dist-sdk/src/entities/file-reader/types.js +1 -1
- package/dist-sdk/src/entities/portal/build.d.ts +26 -0
- package/dist-sdk/src/entities/portal/build.js +37 -0
- package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
- package/dist-sdk/src/entities/portal/from-tf.js +75 -0
- package/dist-sdk/src/entities/portal/index.d.ts +1 -0
- package/dist-sdk/src/entities/portal/index.js +1 -0
- package/dist-sdk/src/entities/portal/module.d.ts +3 -0
- package/dist-sdk/src/entities/portal/module.js +28 -0
- package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
- package/dist-sdk/src/entities/portal/to-tf.js +73 -0
- package/dist-sdk/src/entities/portal/types.d.ts +1 -0
- package/dist-sdk/src/entities/portal/types.js +1 -0
- package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
- package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
- package/dist-sdk/src/entities/relationship/module.js +2 -0
- package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
- package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +10 -0
- package/dist-sdk/src/entities/relationship/to-tf.js +31 -13
- package/dist-sdk/src/entities/search-table/module.js +1 -0
- package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
- package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
- package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
- package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
- package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
- package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
- package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
- package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -2
- package/dist-sdk/src/entities/shared/filters/index.d.ts +25 -2
- package/dist-sdk/src/entities/shared/filters/index.js +38 -5
- package/dist-sdk/src/entities/shared/filters/print.js +31 -3
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +25 -3
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +51 -15
- package/dist-sdk/src/entities/shared/filters/types.d.ts +22 -5
- package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
- package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
- package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
- package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
- package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
- package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
- package/dist-sdk/src/entities/skill/access-policy.js +101 -0
- package/dist-sdk/src/entities/skill/build.d.ts +3 -0
- package/dist-sdk/src/entities/skill/build.js +3 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +23 -1
- package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill/from-tf.js +70 -22
- package/dist-sdk/src/entities/skill/index.d.ts +2 -0
- package/dist-sdk/src/entities/skill/index.js +1 -0
- package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
- package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
- package/dist-sdk/src/entities/skill/module.js +1 -0
- package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/skill/to-tf.js +19 -6
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -6
- package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
- package/dist-sdk/src/entities/table/catalog.js +66 -0
- package/dist-sdk/src/entities/table/module.js +2 -1
- package/dist-sdk/src/entities/table/to-tf.js +5 -5
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +89 -0
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +277 -0
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +51 -0
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +360 -0
- package/dist-sdk/src/entities/view/agent-view-layout.d.ts +151 -0
- package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
- package/dist-sdk/src/entities/view/from-tf.d.ts +6 -3
- package/dist-sdk/src/entities/view/from-tf.js +161 -14
- package/dist-sdk/src/entities/view/module.js +30 -3
- package/dist-sdk/src/entities/view/to-tf.d.ts +24 -2
- package/dist-sdk/src/entities/view/to-tf.js +95 -9
- package/dist-sdk/src/entities/view/types.d.ts +4 -15
- package/dist-sdk/src/entities/view/types.js +17 -15
- package/dist-sdk/src/entities/widget/build.d.ts +16 -1
- package/dist-sdk/src/entities/widget/build.js +11 -1
- package/dist-sdk/src/entities/widget/to-tf.js +36 -10
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +38 -10
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +54 -0
- package/dist-sdk/src/graph/index.js +30 -0
- package/dist-sdk/src/graph/modules.js +2 -0
- package/dist-sdk/src/graph/types.d.ts +133 -2
- package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
- package/dist-sdk/src/internal/sdk-package.js +1 -0
- package/package.json +11 -1
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { isUnsafePlatformId } from "../../core/platform-id.js";
|
|
2
|
+
import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
|
|
3
|
+
import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
4
|
+
import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "./module.js";
|
|
5
|
+
/**
|
|
6
|
+
* Pull must not report success when a service account's generated roles
|
|
7
|
+
* disagree with the export's `role_ids`. Adoption plans the export, so a
|
|
8
|
+
* clean adopt does not prove the authored source kept every role.
|
|
9
|
+
*/
|
|
10
|
+
export const SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX = "service-account role_ids mismatch:";
|
|
11
|
+
function sourceFileOf(owner) {
|
|
12
|
+
if (owner.sourceFile !== undefined && owner.sourceFile !== "")
|
|
13
|
+
return owner.sourceFile;
|
|
14
|
+
const ref = tfLabelToTsLabel(owner.ownerTfLabel);
|
|
15
|
+
return `apps/${ref}/${ref}.ts`;
|
|
16
|
+
}
|
|
17
|
+
function describeRoleValue(item) {
|
|
18
|
+
if (typeof item === "string")
|
|
19
|
+
return item;
|
|
20
|
+
if (isTfExpr(item) && (item.$expr === "data-attr" || item.$expr === "resource-attr")) {
|
|
21
|
+
const head = item.$expr === "data-attr" ? `data.${item.type}` : item.type;
|
|
22
|
+
return `${head}.${item.label}.${item.path.join(".")}`;
|
|
23
|
+
}
|
|
24
|
+
return JSON.stringify(item);
|
|
25
|
+
}
|
|
26
|
+
function identityText(identity) {
|
|
27
|
+
if (identity === undefined)
|
|
28
|
+
return "missing";
|
|
29
|
+
if (identity.kind === "unresolved")
|
|
30
|
+
return `unresolved (${identity.detail})`;
|
|
31
|
+
return `${identity.kind}:${identity.value}`;
|
|
32
|
+
}
|
|
33
|
+
function sameIdentity(left, right) {
|
|
34
|
+
if (left.kind === "unresolved" || right.kind === "unresolved") {
|
|
35
|
+
return left.kind === "unresolved" && right.kind === "unresolved" && left.detail === right.detail;
|
|
36
|
+
}
|
|
37
|
+
return left.kind === right.kind && left.value === right.value;
|
|
38
|
+
}
|
|
39
|
+
function exportRoleIdentity(item, blocks, ctx) {
|
|
40
|
+
const resourceLabel = resourceRefLabel(item, "elementum_role");
|
|
41
|
+
if (resourceLabel !== undefined) {
|
|
42
|
+
const role = blocks.find((candidate) => candidate.type === "elementum_role" && candidate.label === resourceLabel);
|
|
43
|
+
if (typeof role?.attrs["name"] === "string" && role.attrs["name"] !== "") {
|
|
44
|
+
return { kind: "name", value: role.attrs["name"] };
|
|
45
|
+
}
|
|
46
|
+
const id = typeof role?.attrs["id"] === "string" ? role.attrs["id"] : ctx.importId(`elementum_role.${resourceLabel}`);
|
|
47
|
+
if (typeof id === "string" && id.trim() !== "")
|
|
48
|
+
return { kind: "id", value: id };
|
|
49
|
+
return { kind: "unresolved", detail: describeRoleValue(item) };
|
|
50
|
+
}
|
|
51
|
+
const dataLabel = dataRefLabel(item, "elementum_role");
|
|
52
|
+
if (dataLabel !== undefined) {
|
|
53
|
+
const name = ctx.dataName("elementum_role", dataLabel);
|
|
54
|
+
if (name !== undefined && name !== "")
|
|
55
|
+
return { kind: "name", value: name };
|
|
56
|
+
return { kind: "unresolved", detail: describeRoleValue(item) };
|
|
57
|
+
}
|
|
58
|
+
if (typeof item === "string" && item.trim() !== "")
|
|
59
|
+
return { kind: "id", value: item };
|
|
60
|
+
return { kind: "unresolved", detail: describeRoleValue(item) };
|
|
61
|
+
}
|
|
62
|
+
function sourceRoleIdentity(role) {
|
|
63
|
+
if (isUnsafePlatformId(role))
|
|
64
|
+
return { kind: "id", value: role.value };
|
|
65
|
+
return { kind: "name", value: role.name };
|
|
66
|
+
}
|
|
67
|
+
function nextStep(sourceFile, key, index) {
|
|
68
|
+
const slot = index === undefined ? `serviceAccounts.${key}.roles` : `serviceAccounts.${key}.roles[${index}]`;
|
|
69
|
+
return `edit ${slot} in ${sourceFile} (add serviceAccountRoleRef("…") or unsafePlatformId("…")) before build/apply; applying as-is changes the account's live roles`;
|
|
70
|
+
}
|
|
71
|
+
function mismatchLine(where, index, exported, generated, sourceFile, key) {
|
|
72
|
+
return `${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where}.role_ids[${index}] export ${identityText(exported)} vs generated ${identityText(generated)}; ${nextStep(sourceFile, key, index)}`;
|
|
73
|
+
}
|
|
74
|
+
function compareRoleLists(where, key, sourceFile, exported, generated, out) {
|
|
75
|
+
if (exported.length === 0 && generated.length === 0)
|
|
76
|
+
return;
|
|
77
|
+
const count = Math.max(exported.length, generated.length);
|
|
78
|
+
for (let index = 0; index < count; index += 1) {
|
|
79
|
+
const left = exported[index];
|
|
80
|
+
const right = generated[index];
|
|
81
|
+
if (left !== undefined && right !== undefined && sameIdentity(left, right))
|
|
82
|
+
continue;
|
|
83
|
+
out.push(mismatchLine(where, index, left, right, sourceFile, key));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function roleListFromRebuild(value, dataQueues, resourceRoleNames) {
|
|
87
|
+
if (value === undefined)
|
|
88
|
+
return [];
|
|
89
|
+
if (!Array.isArray(value))
|
|
90
|
+
return "not-a-list";
|
|
91
|
+
return value.map((item) => {
|
|
92
|
+
const resourceLabel = resourceRefLabel(item, "elementum_role");
|
|
93
|
+
if (resourceLabel !== undefined) {
|
|
94
|
+
const name = resourceRoleNames.get(resourceLabel);
|
|
95
|
+
if (name !== undefined && name !== "")
|
|
96
|
+
return { kind: "name", value: name };
|
|
97
|
+
return { kind: "unresolved", detail: describeRoleValue(item) };
|
|
98
|
+
}
|
|
99
|
+
const dataLabel = dataRefLabel(item, "elementum_role");
|
|
100
|
+
if (dataLabel !== undefined) {
|
|
101
|
+
const name = dataQueues.get(dataLabel)?.shift();
|
|
102
|
+
if (name !== undefined && name !== "")
|
|
103
|
+
return { kind: "name", value: name };
|
|
104
|
+
return { kind: "unresolved", detail: describeRoleValue(item) };
|
|
105
|
+
}
|
|
106
|
+
if (typeof item === "string" && item.trim() !== "")
|
|
107
|
+
return { kind: "id", value: item };
|
|
108
|
+
return { kind: "unresolved", detail: describeRoleValue(item) };
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function roleList(value, blocks, ctx) {
|
|
112
|
+
if (value === undefined)
|
|
113
|
+
return [];
|
|
114
|
+
if (!Array.isArray(value))
|
|
115
|
+
return "not-a-list";
|
|
116
|
+
return value.map((item) => exportRoleIdentity(item, blocks, ctx));
|
|
117
|
+
}
|
|
118
|
+
function describedRoleIds(value) {
|
|
119
|
+
if (value === undefined)
|
|
120
|
+
return "(none)";
|
|
121
|
+
if (!Array.isArray(value))
|
|
122
|
+
return "not a list";
|
|
123
|
+
return value.map((item) => describeRoleValue(item)).join(", ");
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Order-sensitive comparison of each owned service account's export
|
|
127
|
+
* `role_ids` with the roles written into source. Named roles compare by
|
|
128
|
+
* display name; raw ids compare by platform id. A value the printer cannot
|
|
129
|
+
* represent is a disagreement, not a quiet omission.
|
|
130
|
+
*/
|
|
131
|
+
export function serviceAccountRoleIdMismatches(blocks, accounts, owner, ctx) {
|
|
132
|
+
return compareServiceAccountRoleIds(blocks, accounts, owner, ctx);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Same order-sensitive rule, against service-account blocks rebuilt from
|
|
136
|
+
* the pulled `.ts`. A printer or to-tf that drops or reorders a raw id
|
|
137
|
+
* disagrees here even when extract mirrored the export.
|
|
138
|
+
* When `lookup` is set, rebuilt refs resolve through it. Export refs still
|
|
139
|
+
* use `ctx` and the export blocks.
|
|
140
|
+
*/
|
|
141
|
+
export function rebuiltServiceAccountRoleIdMismatches(exportBlocks, rebuiltBlocks, owner, ctx, lookup) {
|
|
142
|
+
const dataQueues = new Map();
|
|
143
|
+
if (lookup !== undefined) {
|
|
144
|
+
for (const [label, names] of lookup.dataRoleNames)
|
|
145
|
+
dataQueues.set(label, [...names]);
|
|
146
|
+
}
|
|
147
|
+
const rebuiltAccounts = rebuiltBlocks.flatMap((block) => {
|
|
148
|
+
if (block.type !== SERVICE_ACCOUNT_RESOURCE_TYPE || block.label === undefined || block.label === "")
|
|
149
|
+
return [];
|
|
150
|
+
const roles = lookup === undefined
|
|
151
|
+
? roleList(block.attrs["role_ids"], exportBlocks, ctx)
|
|
152
|
+
: roleListFromRebuild(block.attrs["role_ids"], dataQueues, lookup.resourceRoleNames);
|
|
153
|
+
return [{
|
|
154
|
+
key: scopedLabelToBagKey(owner.ownerTfLabel, block.label, "app"),
|
|
155
|
+
label: block.label,
|
|
156
|
+
roles,
|
|
157
|
+
}];
|
|
158
|
+
});
|
|
159
|
+
return compareServiceAccountRoleIds(exportBlocks, rebuiltAccounts.map((account) => ({
|
|
160
|
+
key: account.key,
|
|
161
|
+
roles: account.roles === "not-a-list" ? undefined : account.roles.map((role) => {
|
|
162
|
+
if (role.kind === "id")
|
|
163
|
+
return { __unsafe: "platformId", value: role.value };
|
|
164
|
+
if (role.kind === "name")
|
|
165
|
+
return { __kind: "serviceAccountRole", name: role.value };
|
|
166
|
+
return undefined;
|
|
167
|
+
}).filter((role) => role !== undefined),
|
|
168
|
+
})), owner, ctx, rebuiltAccounts);
|
|
169
|
+
}
|
|
170
|
+
function compareServiceAccountRoleIds(blocks, accounts, owner, ctx, rebuilt) {
|
|
171
|
+
const mismatches = [];
|
|
172
|
+
const sourceFile = sourceFileOf(owner);
|
|
173
|
+
const seen = new Set();
|
|
174
|
+
for (const block of blocks) {
|
|
175
|
+
if (block.type !== SERVICE_ACCOUNT_RESOURCE_TYPE)
|
|
176
|
+
continue;
|
|
177
|
+
if (resourceRefLabel(block.attrs["app_id"], "elementum_app") !== owner.label)
|
|
178
|
+
continue;
|
|
179
|
+
const label = block.label ?? "";
|
|
180
|
+
const where = `${SERVICE_ACCOUNT_RESOURCE_TYPE}.${label || "?"}`;
|
|
181
|
+
const exported = block.attrs["role_ids"];
|
|
182
|
+
if (label === "") {
|
|
183
|
+
if (exported !== undefined) {
|
|
184
|
+
mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where} was not written to source (role_ids: ${describedRoleIds(exported)}); ${nextStep(sourceFile, "?", undefined)}`);
|
|
185
|
+
}
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const key = scopedLabelToBagKey(owner.ownerTfLabel, label, "app");
|
|
189
|
+
seen.add(key);
|
|
190
|
+
const account = accounts.find((candidate) => candidate.key === key);
|
|
191
|
+
const rebuiltAccount = rebuilt?.find((candidate) => candidate.key === key);
|
|
192
|
+
if (!Array.isArray(exported) && exported !== undefined) {
|
|
193
|
+
mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where}.role_ids export role_ids is not a list (${describedRoleIds(exported)}); ${nextStep(sourceFile, key, undefined)}`);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const exportedRoles = exported === undefined ? [] : exported.map((item) => exportRoleIdentity(item, blocks, ctx));
|
|
197
|
+
if (rebuiltAccount !== undefined) {
|
|
198
|
+
if (rebuiltAccount.roles === "not-a-list") {
|
|
199
|
+
mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where}.role_ids rebuild role_ids is not a list; ${nextStep(sourceFile, key, undefined)}`);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
compareRoleLists(where, key, sourceFile, exportedRoles, rebuiltAccount.roles, mismatches);
|
|
203
|
+
}
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const generatedRoles = account?.roles?.map(sourceRoleIdentity) ?? [];
|
|
207
|
+
if (account === undefined && exportedRoles.length > 0) {
|
|
208
|
+
mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where} was not written to source (role_ids: ${describedRoleIds(exported)}); ${nextStep(sourceFile, key, undefined)}`);
|
|
209
|
+
}
|
|
210
|
+
compareRoleLists(where, key, sourceFile, exportedRoles, generatedRoles, mismatches);
|
|
211
|
+
}
|
|
212
|
+
if (rebuilt === undefined) {
|
|
213
|
+
for (const account of accounts) {
|
|
214
|
+
if (seen.has(account.key) || (account.roles?.length ?? 0) === 0)
|
|
215
|
+
continue;
|
|
216
|
+
mismatches.push(`${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} serviceAccounts.${account.key} has roles with no export service account; ${nextStep(sourceFile, account.key, undefined)}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return mismatches;
|
|
220
|
+
}
|
|
221
|
+
/** Authoring files named by role-mismatch lines, in first-seen order. */
|
|
222
|
+
export function serviceAccountRoleMismatchSources(lines) {
|
|
223
|
+
const files = [];
|
|
224
|
+
for (const line of lines) {
|
|
225
|
+
const match = / in (\S+\.ts) /.exec(line);
|
|
226
|
+
if (match?.[1] !== undefined && !files.includes(match[1]))
|
|
227
|
+
files.push(match[1]);
|
|
228
|
+
}
|
|
229
|
+
return files;
|
|
230
|
+
}
|
|
231
|
+
/** Single-root build-vs-export lines that are a service-account `role_ids` disagreement. */
|
|
232
|
+
export function serviceAccountRoleRoundTripMismatches(differences, sourceFile) {
|
|
233
|
+
return differences
|
|
234
|
+
.filter((line) => line.includes("resource:elementum_service_account.") && line.includes("role_ids"))
|
|
235
|
+
.map((line) => `${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${line}; edit serviceAccounts in ${sourceFile} (add serviceAccountRoleRef("…") or unsafePlatformId("…")) before build/apply; applying as-is changes the account's live roles`);
|
|
236
|
+
}
|
|
237
|
+
export function serviceAccountRoleGuardBlocksSuccess(diagnostics) {
|
|
238
|
+
return diagnostics.some((line) => line.includes(SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX));
|
|
239
|
+
}
|
|
240
|
+
/** Adoption failure fails a pull. Role-id disagreement must too, even when adoption succeeded or was skipped. */
|
|
241
|
+
export function serviceAccountPullMustFail(input) {
|
|
242
|
+
return input.adoptionFailed || serviceAccountRoleGuardBlocksSuccess(input.diagnostics);
|
|
243
|
+
}
|
|
@@ -31,3 +31,17 @@ export declare function serviceAccountsToTf(accounts: Readonly<Record<string, Ap
|
|
|
31
31
|
readonly orgRefs: OrgRefLookup;
|
|
32
32
|
readonly diagnostics: string[];
|
|
33
33
|
}): TfBlock[];
|
|
34
|
+
/**
|
|
35
|
+
* Service-account blocks for one app. `appToTf` and the pull role rebuild
|
|
36
|
+
* both call this, so the `roles` bag and the other arguments cannot drift
|
|
37
|
+
* between build and the guard.
|
|
38
|
+
*/
|
|
39
|
+
export declare function appServiceAccountBlocks(payload: {
|
|
40
|
+
readonly serviceAccounts?: Readonly<Record<string, AppServiceAccount>>;
|
|
41
|
+
readonly roles?: Readonly<Record<string, AppRole>>;
|
|
42
|
+
}, opts: {
|
|
43
|
+
readonly ownerTfLabel: string;
|
|
44
|
+
readonly appId: TfValue;
|
|
45
|
+
readonly orgRefs: OrgRefLookup;
|
|
46
|
+
readonly diagnostics: string[];
|
|
47
|
+
}): TfBlock[];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isUnsafePlatformId } from "../../core/platform-id.js";
|
|
1
2
|
import { appScopedResourceLabel, expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
2
3
|
import { SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE, SERVICE_ACCOUNT_RESOURCE_TYPE } from "./module.js";
|
|
3
4
|
/**
|
|
@@ -64,6 +65,8 @@ function principalValues(values, type, where, orgRefs, diagnostics) {
|
|
|
64
65
|
return out.length > 0 ? out : undefined;
|
|
65
66
|
}
|
|
66
67
|
function roleValue(value, roles, ownerTfLabel, appId, orgRefs) {
|
|
68
|
+
if (isUnsafePlatformId(value))
|
|
69
|
+
return value.value;
|
|
67
70
|
const local = Object.entries(roles ?? {}).find(([, role]) => role.name === value.name);
|
|
68
71
|
if (local !== undefined) {
|
|
69
72
|
return expr.resourceAttr("elementum_role", scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(local[0]), "app"), ["id"]);
|
|
@@ -108,3 +111,17 @@ export function serviceAccountsToTf(accounts, opts) {
|
|
|
108
111
|
}
|
|
109
112
|
return blocks;
|
|
110
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Service-account blocks for one app. `appToTf` and the pull role rebuild
|
|
116
|
+
* both call this, so the `roles` bag and the other arguments cannot drift
|
|
117
|
+
* between build and the guard.
|
|
118
|
+
*/
|
|
119
|
+
export function appServiceAccountBlocks(payload, opts) {
|
|
120
|
+
return serviceAccountsToTf(payload.serviceAccounts, {
|
|
121
|
+
ownerTfLabel: opts.ownerTfLabel,
|
|
122
|
+
appId: opts.appId,
|
|
123
|
+
roles: payload.roles,
|
|
124
|
+
orgRefs: opts.orgRefs,
|
|
125
|
+
diagnostics: opts.diagnostics,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
@@ -11,7 +11,7 @@ export interface ResolvedAspectTarget {
|
|
|
11
11
|
readonly key: string;
|
|
12
12
|
readonly name: string;
|
|
13
13
|
readonly namespace?: string;
|
|
14
|
-
/** `key
|
|
14
|
+
/** `key` is the target's real catalog identity: pulled, or derived from its namespace (its stream label). */
|
|
15
15
|
readonly catalogRef?: true;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
1
|
+
import { sanitizeName, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Resolve a foreign app/element data lookup to its display name. Ref-only
|
|
4
4
|
* lookups are intentionally namespace-only, so fall back through the
|
|
@@ -40,7 +40,10 @@ export function dataAspectRefName(ctx, kind, label, displayName) {
|
|
|
40
40
|
}
|
|
41
41
|
const name = displayName ?? dataAspectDisplayName(ctx, kind, label);
|
|
42
42
|
const byName = kind === "app" ? ctx.foreignAppRefNames : kind === "element" ? ctx.foreignElementRefNames : undefined;
|
|
43
|
-
|
|
43
|
+
const pulled = name === undefined ? undefined : byName?.get(name);
|
|
44
|
+
// An app's or element's stream label is its sanitized namespace (ei AppResourceName /
|
|
45
|
+
// ElementResourceName), so the namespace alone gives the real refName before the target is pulled.
|
|
46
|
+
return pulled ?? (namespace === undefined ? undefined : tfLabelToTsLabel(sanitizeName(namespace)));
|
|
44
47
|
}
|
|
45
48
|
/**
|
|
46
49
|
* Resolve a foreign app/element data lookup to the full identity a caller
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* filters, for instance, only produce `literal`, `field`, `app`, and
|
|
34
34
|
* `unresolved`).
|
|
35
35
|
*/
|
|
36
|
-
import type { UserFieldKey } from "../../../catalog/types.js";
|
|
36
|
+
import type { UserFieldKey, UserGroupFieldKey } from "../../../catalog/types.js";
|
|
37
37
|
/** Reference to an app: `<appHandle>`. */
|
|
38
38
|
export interface AppRefAst {
|
|
39
39
|
readonly kind: "app";
|
|
@@ -72,11 +72,24 @@ export interface UserFieldRefAst {
|
|
|
72
72
|
readonly kind: "userField";
|
|
73
73
|
readonly fieldKey: UserFieldKey;
|
|
74
74
|
}
|
|
75
|
+
/** Reference to a fixed platform user-group attribute. */
|
|
76
|
+
export interface UserGroupFieldRefAst {
|
|
77
|
+
readonly kind: "userGroupField";
|
|
78
|
+
readonly fieldKey: UserGroupFieldKey;
|
|
79
|
+
}
|
|
75
80
|
/** Reference to an element's search table: `<handle>.searchTables.<tableKey>`. */
|
|
76
81
|
export interface SearchTableRefAst {
|
|
77
82
|
readonly kind: "searchTable";
|
|
78
83
|
readonly appHandle: string;
|
|
79
84
|
readonly tableKey: string;
|
|
85
|
+
/** Table-owned lookup. Element-owned catalog refs leave this unset. */
|
|
86
|
+
readonly ownerKind?: "table" | "element";
|
|
87
|
+
/** Display name of the search table, when the reference is not a catalog key. */
|
|
88
|
+
readonly name?: string;
|
|
89
|
+
/** Display name of a table owner. */
|
|
90
|
+
readonly parentName?: string;
|
|
91
|
+
/** Set when the search table's name is not unique on its owner. */
|
|
92
|
+
readonly id?: string;
|
|
80
93
|
}
|
|
81
94
|
/** Reference to an app-owned phone service. */
|
|
82
95
|
export interface PhoneServiceRefAst {
|
|
@@ -246,7 +259,7 @@ export type RefExpr =
|
|
|
246
259
|
| {
|
|
247
260
|
kind: "template";
|
|
248
261
|
parts: readonly (string | RefExpr)[];
|
|
249
|
-
} | FieldRefAst | UserFieldRefAst | AppRefAst | AgentRefAst | AutomationRefAst | DocumentModelRefAst | DocumentModelFieldRefAst | ApprovalChainRefAst | DatamineRefAst | TableRefAst | TableColumnRefAst | SearchTableRefAst | ConnectorRefAst | CloudLinkRefAst | ProcedureRefAst | PhoneServiceRefAst | UserRefAst | UnresolvedRefAst
|
|
262
|
+
} | FieldRefAst | UserFieldRefAst | UserGroupFieldRefAst | AppRefAst | AgentRefAst | AutomationRefAst | DocumentModelRefAst | DocumentModelFieldRefAst | ApprovalChainRefAst | DatamineRefAst | TableRefAst | TableColumnRefAst | SearchTableRefAst | ConnectorRefAst | CloudLinkRefAst | ProcedureRefAst | PhoneServiceRefAst | UserRefAst | UnresolvedRefAst
|
|
250
263
|
/** Preserved terraform local expression for round-trip (e.g. status option ids by label). */
|
|
251
264
|
| {
|
|
252
265
|
kind: "localRef";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** Canonical Elementum filter model and authoring helpers. */
|
|
2
|
-
import type { AppOrElementRef, FieldRef, TableColumnRef, TableRef, UserFieldRef } from "../../../catalog/index.js";
|
|
2
|
+
import type { AppOrElementRef, FieldRef, TableColumnRef, TableRef, UserFieldRef, UserGroupFieldRef } from "../../../catalog/index.js";
|
|
3
3
|
import type { UnsafePlatformId } from "../../../core/platform-id.js";
|
|
4
4
|
import { type AppField, type FieldScope } from "../../../core/types/app.js";
|
|
5
5
|
import { type Ref } from "../ref.js";
|
|
6
6
|
import type { WorkflowFieldType } from "../types/field-types.js";
|
|
7
7
|
import type { AndFilter, BetweenFilter, ConsecutiveRangeFilter, ContainsFilter, CurrentRangeFilter, DateTimeUnit, EqualsFilter, FalseFilter, Filter, FilterReference, FilterValue, GreaterThanEqualsFilter, GreaterThanFilter, InFilter, IsNullFilter, LessThanEqualsFilter, LessThanFilter, LikeFilter, LikeMode, OrFilter, OverlapsFilter, TrueFilter, ValueType } from "./types.js";
|
|
8
8
|
export type { AndFilter, BetweenFilter, ConsecutiveRangeFilter, ContainsFilter, CurrentRangeFilter, DateTimeUnit, EqualsFilter, FalseFilter, FieldFilterOptions, Filter, FilterReference, FilterValue, GreaterThanEqualsFilter, GreaterThanFilter, InFilter, IsNullFilter, LessThanEqualsFilter, LessThanFilter, LikeFilter, LikeMode, OrFilter, OverlapsFilter, TrueFilter, ValueType, } from "./types.js";
|
|
9
|
-
export type FilterField = AppOrElementRef | FieldRef | UserFieldRef | TableColumnRef | TableRef | AppField<FieldScope> | UnsafePlatformId | string;
|
|
9
|
+
export type FilterField = AppOrElementRef | FieldRef | UserFieldRef | UserGroupFieldRef | TableColumnRef | TableRef | AppField<FieldScope> | UnsafePlatformId | string;
|
|
10
10
|
export type FilterReferenceValue = FilterReference | {
|
|
11
11
|
readonly __rawFilterReference: string;
|
|
12
12
|
};
|
|
@@ -23,6 +23,8 @@ export interface FilterReferenceInput {
|
|
|
23
23
|
readonly [FILTER_REFERENCE_BRAND]: true;
|
|
24
24
|
readonly ref: Ref<unknown> | string;
|
|
25
25
|
readonly valueType: ValueType;
|
|
26
|
+
/** The caller named this type. Build must not replace it with field metadata. */
|
|
27
|
+
readonly explicit: true;
|
|
26
28
|
readonly multiple?: boolean;
|
|
27
29
|
}
|
|
28
30
|
export declare function boolean(ref: Ref<unknown> | string, options?: {
|
|
@@ -44,6 +46,17 @@ export declare function uuid(ref: Ref<unknown> | string, options?: {
|
|
|
44
46
|
readonly multiple?: boolean;
|
|
45
47
|
}): FilterReferenceInput;
|
|
46
48
|
export declare function isFilterReferenceInput(value: unknown): value is FilterReferenceInput;
|
|
49
|
+
/**
|
|
50
|
+
* A picklist, status, or stage option selected by its LABEL and stored behind
|
|
51
|
+
* the platform's TEXT value wrapper, which is how many live list-view filters
|
|
52
|
+
* hold their option ids. Build resolves the label to that option's id either
|
|
53
|
+
* way, so the wrapper is the only difference: pass a plain label for a raw text
|
|
54
|
+
* comparison, `"UUID"` as the comparison's value type for the UUID wrapper, and
|
|
55
|
+
* this for the TEXT one.
|
|
56
|
+
*/
|
|
57
|
+
export declare function textOption(label: string): Extract<FilterValue<FilterField, FilterReferenceValue>, {
|
|
58
|
+
type: "TEXT";
|
|
59
|
+
}>;
|
|
47
60
|
export interface CurrentUserFilterValue {
|
|
48
61
|
readonly __kind: "currentUser";
|
|
49
62
|
readonly valueType: "ID" | "EMAIL" | "DOMAIN";
|
|
@@ -63,6 +76,16 @@ export declare function fieldValue(value: FilterField, options?: {
|
|
|
63
76
|
}): Extract<FilterValue<FilterField, FilterReferenceValue>, {
|
|
64
77
|
type: "FIELD";
|
|
65
78
|
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Compare against a field on the record being edited — a dynamic Dropdown
|
|
81
|
+
* filter such as "source Process Area equals this record's Process Area".
|
|
82
|
+
* `field` must belong to the Dropdown's own app or element.
|
|
83
|
+
*/
|
|
84
|
+
export declare function recordField(field: FilterField, options?: {
|
|
85
|
+
readonly required?: boolean;
|
|
86
|
+
}): Extract<FilterValue<FilterField, FilterReferenceValue>, {
|
|
87
|
+
type: "RECORD_FIELD";
|
|
88
|
+
}>;
|
|
66
89
|
type AuthoredFilterValue = FilterValue<FilterField, FilterReferenceValue>;
|
|
67
90
|
export type FilterInput = string | number | boolean | null | Ref<unknown> | FilterReferenceInput | FilterField | CurrentUserFilterValue | AuthoredFilterValue;
|
|
68
91
|
export type LeftRef = FilterField | Ref<unknown> | FilterReferenceInput | FieldLeftValue;
|
|
@@ -52,7 +52,7 @@ export function referenceValueTypeForField(fieldType, suffix = "") {
|
|
|
52
52
|
}
|
|
53
53
|
const FILTER_REFERENCE_BRAND = Symbol("FilterReferenceInput");
|
|
54
54
|
function referenceInput(ref, valueType, options) {
|
|
55
|
-
return { [FILTER_REFERENCE_BRAND]: true, ref, valueType, ...(options?.multiple === true && { multiple: true }) };
|
|
55
|
+
return { [FILTER_REFERENCE_BRAND]: true, ref, valueType, explicit: true, ...(options?.multiple === true && { multiple: true }) };
|
|
56
56
|
}
|
|
57
57
|
export function boolean(ref, options) {
|
|
58
58
|
return referenceInput(ref, "BOOLEAN", options);
|
|
@@ -75,6 +75,17 @@ export function uuid(ref, options) {
|
|
|
75
75
|
export function isFilterReferenceInput(value) {
|
|
76
76
|
return typeof value === "object" && value !== null && FILTER_REFERENCE_BRAND in value;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* A picklist, status, or stage option selected by its LABEL and stored behind
|
|
80
|
+
* the platform's TEXT value wrapper, which is how many live list-view filters
|
|
81
|
+
* hold their option ids. Build resolves the label to that option's id either
|
|
82
|
+
* way, so the wrapper is the only difference: pass a plain label for a raw text
|
|
83
|
+
* comparison, `"UUID"` as the comparison's value type for the UUID wrapper, and
|
|
84
|
+
* this for the TEXT one.
|
|
85
|
+
*/
|
|
86
|
+
export function textOption(label) {
|
|
87
|
+
return { type: "TEXT", value: label, option: true };
|
|
88
|
+
}
|
|
78
89
|
export function currentUser(valueType = "ID") {
|
|
79
90
|
return { __kind: "currentUser", valueType };
|
|
80
91
|
}
|
|
@@ -90,6 +101,18 @@ export function fieldValue(value, options) {
|
|
|
90
101
|
Object.defineProperty(operand, FIELD_VALUE_SOURCE, { value });
|
|
91
102
|
return operand;
|
|
92
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Compare against a field on the record being edited — a dynamic Dropdown
|
|
106
|
+
* filter such as "source Process Area equals this record's Process Area".
|
|
107
|
+
* `field` must belong to the Dropdown's own app or element.
|
|
108
|
+
*/
|
|
109
|
+
export function recordField(field, options) {
|
|
110
|
+
return {
|
|
111
|
+
type: "RECORD_FIELD",
|
|
112
|
+
field: fieldWireValue(field),
|
|
113
|
+
...(options?.required !== undefined && { required: options.required }),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
93
116
|
export const UNRESOLVED_REFERENCE_MARKER = "__edkUnresolvedReference::";
|
|
94
117
|
export function refDataToFilterReference(data) {
|
|
95
118
|
switch (data.kind) {
|
|
@@ -121,7 +144,7 @@ function isCanonicalFilterValue(value) {
|
|
|
121
144
|
FILTER_VALUE_TYPES.has(value.type);
|
|
122
145
|
}
|
|
123
146
|
function isCatalogField(value) {
|
|
124
|
-
return hasKind(value, "field") || hasKind(value, "userField") || hasKind(value, "tableColumn");
|
|
147
|
+
return hasKind(value, "field") || hasKind(value, "userField") || hasKind(value, "userGroupField") || hasKind(value, "tableColumn");
|
|
125
148
|
}
|
|
126
149
|
function isAppField(value) {
|
|
127
150
|
return typeof value === "object" && value !== null && "id" in value && "type" in value && !isCatalogField(value);
|
|
@@ -151,15 +174,25 @@ function leftType(left, fallback, explicit) {
|
|
|
151
174
|
return fallback;
|
|
152
175
|
return fieldTypeToValueType(isAppField(left) ? left.type : "fieldType" in left ? left.fieldType : undefined);
|
|
153
176
|
}
|
|
177
|
+
function referenceValue(realType, value, explicit) {
|
|
178
|
+
return {
|
|
179
|
+
type: "REFERENCE",
|
|
180
|
+
realType,
|
|
181
|
+
// A passed comparison type (`filter.eq(ref, value, "TEXT")`) is authored.
|
|
182
|
+
// An omitted type is the operator fallback, which field metadata may replace.
|
|
183
|
+
...(explicit !== undefined ? { explicit: true } : {}),
|
|
184
|
+
value,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
154
187
|
function leftDescriptor(left, fallback, explicit) {
|
|
155
188
|
if (isFieldLeftValue(left))
|
|
156
189
|
return { leftValue: left };
|
|
157
190
|
if (isFilterReferenceInput(left))
|
|
158
191
|
return { leftValue: toFilterValue(left) };
|
|
159
192
|
if (isRef(left))
|
|
160
|
-
return { leftValue:
|
|
193
|
+
return { leftValue: referenceValue(explicit ?? fallback, refDataToFilterReference(left.__data), explicit) };
|
|
161
194
|
if (typeof left === "string" && left.startsWith(UNRESOLVED_REFERENCE_MARKER)) {
|
|
162
|
-
return { leftValue:
|
|
195
|
+
return { leftValue: referenceValue(explicit ?? fallback, { __rawFilterReference: left.slice(UNRESOLVED_REFERENCE_MARKER.length) }, explicit) };
|
|
163
196
|
}
|
|
164
197
|
return { field: fieldWireValue(left) };
|
|
165
198
|
}
|
|
@@ -181,7 +214,7 @@ export function toFilterValue(input, valueType = "TEXT") {
|
|
|
181
214
|
: typeof input.ref === "string"
|
|
182
215
|
? { __rawFilterReference: input.ref }
|
|
183
216
|
: refDataToFilterReference(input.ref.__data);
|
|
184
|
-
return { type: "REFERENCE", realType: input.valueType, value, ...(input.multiple === true && { multiple: true }) };
|
|
217
|
+
return { type: "REFERENCE", realType: input.valueType, explicit: true, value, ...(input.multiple === true && { multiple: true }) };
|
|
185
218
|
}
|
|
186
219
|
if (isRef(input)) {
|
|
187
220
|
if (input.__data.kind === "static")
|
|
@@ -13,9 +13,12 @@ export function printFilter(filter, codec) {
|
|
|
13
13
|
: "min" in filter ? [filter.min, filter.max] : [];
|
|
14
14
|
const uuidValues = literals.length > 0 && literals.every((literal) => literal.type === "UUID");
|
|
15
15
|
const explicitType = uuidValues ? `, ${quote("UUID")}` : "";
|
|
16
|
+
const impliedLiteralType = stringLiteralTypeImpliedBy(filter, uuidValues);
|
|
16
17
|
const value = (input) => input.type === "UUID"
|
|
17
18
|
? uuidValues ? quote(input.value) : `{ type: "UUID", value: ${quote(input.value)} }`
|
|
18
|
-
:
|
|
19
|
+
: (input.type === "TEXT" || input.type === "DATE" || input.type === "DATETIME") && impliedLiteralType !== undefined && input.type !== impliedLiteralType
|
|
20
|
+
? `{ type: ${quote(input.type)}, value: ${quote(input.value)} }`
|
|
21
|
+
: printFilterValue(input, codec, call, quote);
|
|
19
22
|
if ("leftValue" in filter && filter.leftValue?.type === "FIELD") {
|
|
20
23
|
const operand = filter.leftValue;
|
|
21
24
|
if ((operand.aspect != null && operand.aspect !== "") || (operand.treatNullAsEquals != null && operand.treatNullAsEquals !== true)) {
|
|
@@ -76,6 +79,19 @@ export function printFilter(filter, codec) {
|
|
|
76
79
|
];
|
|
77
80
|
return options.length === 0 ? printed : call("withOptions", `${printed}, { ${options.join(", ")} }`);
|
|
78
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* The type `filter.*` gives a bare string literal when the left operand prints as a typed reference wrapper
|
|
84
|
+
* (`filter.uuid(…)`, `filter.date(…)`): the wrapper's type, narrowed to the string-valued ones, else TEXT.
|
|
85
|
+
* Undefined for every other left operand, whose literals already print as before.
|
|
86
|
+
*/
|
|
87
|
+
function stringLiteralTypeImpliedBy(filter, uuidValues) {
|
|
88
|
+
if (!("leftValue" in filter) || filter.leftValue?.type !== "REFERENCE" || filter.leftValue.realType === undefined)
|
|
89
|
+
return undefined;
|
|
90
|
+
if (uuidValues)
|
|
91
|
+
return "UUID";
|
|
92
|
+
const realType = filter.leftValue.realType;
|
|
93
|
+
return realType === "UUID" || realType === "DATE" || realType === "DATETIME" ? realType : "TEXT";
|
|
94
|
+
}
|
|
79
95
|
function printLikeOptions(filter, quote) {
|
|
80
96
|
const options = [];
|
|
81
97
|
if (filter.not === true)
|
|
@@ -88,7 +104,9 @@ function printLikeOptions(filter, quote) {
|
|
|
88
104
|
}
|
|
89
105
|
function printFilterValue(value, codec, call, quote) {
|
|
90
106
|
switch (value.type) {
|
|
91
|
-
|
|
107
|
+
// A TEXT-wrapped option label needs both facts in the printed call: a bare
|
|
108
|
+
// string is a raw word, and `"UUID"` would change the stored wrapper.
|
|
109
|
+
case "TEXT": return value.option === true ? call("textOption", quote(value.value)) : quote(value.value);
|
|
92
110
|
case "UUID":
|
|
93
111
|
case "DATE":
|
|
94
112
|
case "DATETIME": return quote(value.value);
|
|
@@ -139,6 +157,16 @@ function printFilterValue(value, codec, call, quote) {
|
|
|
139
157
|
}
|
|
140
158
|
return call(helper, `${codec.reference(value.value)}${options}`);
|
|
141
159
|
}
|
|
142
|
-
case "RECORD_FIELD":
|
|
160
|
+
case "RECORD_FIELD": {
|
|
161
|
+
if (typeof value.field === "string")
|
|
162
|
+
return `${JSON.stringify(value)} as const`;
|
|
163
|
+
const { type: _type, field, required, ...rest } = value;
|
|
164
|
+
if (Object.keys(rest).length === 0) {
|
|
165
|
+
return call("recordField", `${codec.field(field)}${required !== undefined ? `, { required: ${required} }` : ""}`);
|
|
166
|
+
}
|
|
167
|
+
const extras = Object.entries({ ...rest, ...(required !== undefined && { required }) })
|
|
168
|
+
.map(([key, item]) => `${key}: ${JSON.stringify(item)}`);
|
|
169
|
+
return `{ type: "RECORD_FIELD", field: ${codec.field(field)}, ${extras.join(", ")} } as const`;
|
|
170
|
+
}
|
|
143
171
|
}
|
|
144
172
|
}
|
|
@@ -90,18 +90,29 @@ export interface FilterToTfCodec {
|
|
|
90
90
|
* wire forms for TASK refs in each slot (#490).
|
|
91
91
|
*/
|
|
92
92
|
readonly reference: (value: unknown, role?: "left" | "value", realType?: string, operator?: TfFilterType) => TfValue;
|
|
93
|
-
|
|
93
|
+
/**
|
|
94
|
+
* `valueType` is the wrapper to store. `isOptionLabel` is the independent
|
|
95
|
+
* fact that `value` is an option LABEL to resolve back to its option-id
|
|
96
|
+
* lookup, whichever wrapper that is.
|
|
97
|
+
*/
|
|
98
|
+
readonly literal?: (value: TfValue, field: unknown | undefined, valueType: string, isOptionLabel: boolean) => TfValue;
|
|
99
|
+
/** A RECORD_FIELD value's source-record field; without it only raw platform ids encode. */
|
|
100
|
+
readonly recordField?: (value: unknown) => TfValue;
|
|
94
101
|
readonly fieldFromLeftValue?: (value: unknown) => unknown | undefined;
|
|
95
102
|
/**
|
|
96
103
|
* Override the REFERENCE `real_type` that would otherwise default to TEXT.
|
|
97
104
|
* Return a GraphQL ValueType (TEXT/UUID/NUMBER/…) or undefined to keep the
|
|
98
105
|
* authored/default value. Used when a trigger-record Ref's field metadata
|
|
99
106
|
* is a better authority than `isNull`'s TEXT operator fallback.
|
|
107
|
+
* Not called for an explicit wrapper (`filter.text()`, `filter.uuid()`, …):
|
|
108
|
+
* that authored type is kept as written.
|
|
100
109
|
*/
|
|
101
110
|
readonly referenceRealType?: (reference: unknown, role: "left" | "value", authored: string | undefined) => string | undefined;
|
|
102
111
|
}
|
|
112
|
+
/** Which schema a filter's `field_id` addresses: app/element fields, or the fixed platform user / user-group directory. */
|
|
113
|
+
export type FilterFieldScope = "app" | "user" | "userGroup";
|
|
103
114
|
export interface FilterFromTfCodec<Field = string, ReferenceValue = never> {
|
|
104
|
-
readonly field: (value: TfValue, fieldScope:
|
|
115
|
+
readonly field: (value: TfValue, fieldScope: FilterFieldScope) => Field;
|
|
105
116
|
readonly aspect?: (value: TfValue) => Field;
|
|
106
117
|
readonly reference: (value: TfValue, role: "left" | "value") => ReferenceValue;
|
|
107
118
|
/**
|
|
@@ -111,6 +122,17 @@ export interface FilterFromTfCodec<Field = string, ReferenceValue = never> {
|
|
|
111
122
|
*/
|
|
112
123
|
readonly referenceType?: (value: TfValue, fallback: ValueType) => ValueType;
|
|
113
124
|
readonly literal?: (value: TfValue, valueType: string) => TfValue;
|
|
125
|
+
/** Decode a RECORD_FIELD value's source-record field reference; without it only raw platform ids decode. */
|
|
126
|
+
readonly recordField?: (value: TfValue) => Field;
|
|
127
|
+
/**
|
|
128
|
+
* A TEXT-wrapped literal `literal` resolved from an option-id lookup is an
|
|
129
|
+
* option LABEL, not a stored word. Set this when the owner cannot rebuild a
|
|
130
|
+
* bare label into the same lookup — list views keep raw words literal, so
|
|
131
|
+
* dropping the fact there rewrites the stored wrapper type. Owners that
|
|
132
|
+
* always resolve labels (access policies) leave it off and keep printing
|
|
133
|
+
* plain labels.
|
|
134
|
+
*/
|
|
135
|
+
readonly optionLookupsAreIdentities?: boolean;
|
|
114
136
|
}
|
|
115
137
|
export type WireFilterValue = Readonly<{
|
|
116
138
|
type: string;
|
|
@@ -184,5 +206,5 @@ export declare function filterWireToTf(value: unknown): TfFilter;
|
|
|
184
206
|
/** Canonical Terraform-HCL filter -> platform wire shape for tables/datamines. */
|
|
185
207
|
export declare function filterTfToWire(value: TfValue): WireFilter;
|
|
186
208
|
/** The only Terraform-HCL filter -> strongly typed deserializer AST. */
|
|
187
|
-
export declare function filterFromTf<Field, ReferenceValue>(value: TfValue, codec: FilterFromTfCodec<Field, ReferenceValue>, fieldScope?:
|
|
209
|
+
export declare function filterFromTf<Field, ReferenceValue>(value: TfValue, codec: FilterFromTfCodec<Field, ReferenceValue>, fieldScope?: FilterFieldScope): Filter<Field, ReferenceValue>;
|
|
188
210
|
export {};
|