@elementumai/edk 0.9.19 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +159 -7
- package/dist-sdk/src/catalog/factories.d.ts +33 -2
- package/dist-sdk/src/catalog/factories.js +40 -1
- package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
- package/dist-sdk/src/catalog/from-authoring.js +34 -9
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +2 -2
- package/dist-sdk/src/catalog/render.js +6 -6
- package/dist-sdk/src/catalog/token.js +11 -0
- package/dist-sdk/src/catalog/types.d.ts +40 -1
- package/dist-sdk/src/catalog/types.js +12 -0
- package/dist-sdk/src/core/triggers/on-demand.d.ts +40 -4
- package/dist-sdk/src/core/triggers/on-demand.js +17 -2
- package/dist-sdk/src/core/types/app.d.ts +2 -2
- package/dist-sdk/src/engine/build/context.d.ts +1 -1
- package/dist-sdk/src/engine/coverage-gaps.d.ts +86 -0
- package/dist-sdk/src/engine/coverage-gaps.js +156 -0
- package/dist-sdk/src/engine/ei/run.d.ts +169 -0
- package/dist-sdk/src/engine/ei/run.js +1219 -0
- package/dist-sdk/src/engine/logging.d.ts +17 -0
- package/dist-sdk/src/engine/logging.js +18 -0
- package/dist-sdk/src/engine/pull/catalog-ref.d.ts +16 -0
- package/dist-sdk/src/engine/pull/catalog-ref.js +24 -0
- package/dist-sdk/src/engine/pull/context.d.ts +68 -6
- package/dist-sdk/src/engine/pull/context.js +40 -1
- package/dist-sdk/src/engine/pull/procedure-refs.d.ts +8 -0
- package/dist-sdk/src/engine/pull/procedure-refs.js +28 -0
- package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
- package/dist-sdk/src/engine/pull/ref-only.js +10 -7
- package/dist-sdk/src/engine/pull/result-output.d.ts +6 -0
- package/dist-sdk/src/engine/pull/result-output.js +113 -3
- package/dist-sdk/src/engine/tf/expr.js +1 -1
- package/dist-sdk/src/engine/tf/index.d.ts +2 -2
- package/dist-sdk/src/engine/tf/index.js +1 -1
- package/dist-sdk/src/engine/tf/labels.d.ts +28 -5
- package/dist-sdk/src/engine/tf/labels.js +54 -3
- package/dist-sdk/src/engine/tf/model.d.ts +22 -1
- package/dist-sdk/src/engine/tf/parse.js +93 -4
- package/dist-sdk/src/engine/tf/render.d.ts +4 -2
- package/dist-sdk/src/engine/tf/render.js +41 -7
- package/dist-sdk/src/engine/validation.d.ts +44 -0
- package/dist-sdk/src/engine/validation.js +95 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +38 -1
- package/dist-sdk/src/entities/access-policy/principal.d.ts +2 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +5 -2
- package/dist-sdk/src/entities/agent/build.d.ts +4 -16
- package/dist-sdk/src/entities/agent/build.js +40 -5
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +46 -21
- package/dist-sdk/src/entities/agent/from-tf.js +11 -3
- package/dist-sdk/src/entities/agent/module.js +2 -0
- package/dist-sdk/src/entities/agent/to-tf.js +20 -6
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +10 -1
- package/dist-sdk/src/entities/agent-tool/from-tf.js +18 -6
- package/dist-sdk/src/entities/agent-tool/module.js +3 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +27 -5
- package/dist-sdk/src/entities/app/auto-share.d.ts +38 -0
- package/dist-sdk/src/entities/app/auto-share.js +49 -0
- package/dist-sdk/src/entities/app/build.d.ts +105 -22
- package/dist-sdk/src/entities/app/build.js +107 -10
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
- package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
- package/dist-sdk/src/entities/app/from-tf.js +11 -2
- package/dist-sdk/src/entities/app/index.d.ts +7 -6
- package/dist-sdk/src/entities/app/index.js +2 -8
- package/dist-sdk/src/entities/app/module.js +5 -2
- package/dist-sdk/src/entities/app/to-tf.d.ts +6 -0
- package/dist-sdk/src/entities/app/to-tf.js +40 -13
- package/dist-sdk/src/entities/automation/build.d.ts +56 -6
- package/dist-sdk/src/entities/automation/build.js +230 -26
- package/dist-sdk/src/entities/automation/calculation-expression.d.ts +7 -7
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +41 -5
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +470 -58
- package/dist-sdk/src/entities/automation/from-tf.d.ts +37 -8
- package/dist-sdk/src/entities/automation/from-tf.js +791 -131
- package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
- package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
- package/dist-sdk/src/entities/automation/index.d.ts +2 -2
- package/dist-sdk/src/entities/automation/index.js +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +3 -0
- package/dist-sdk/src/entities/automation/module.js +107 -15
- package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
- package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +20 -0
- package/dist-sdk/src/entities/automation/script-code.js +109 -5
- package/dist-sdk/src/entities/automation/system-ref-name.js +4 -0
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +39 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +85 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +116 -22
- package/dist-sdk/src/entities/automation/tasks.js +86 -24
- package/dist-sdk/src/entities/automation/to-tf.d.ts +24 -3
- package/dist-sdk/src/entities/automation/to-tf.js +1082 -132
- package/dist-sdk/src/entities/automation/triggers.d.ts +12 -6
- package/dist-sdk/src/entities/automation/triggers.js +4 -0
- package/dist-sdk/src/entities/automation/types.d.ts +9 -0
- package/dist-sdk/src/entities/automation/types.js +19 -0
- package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +1 -1
- package/dist-sdk/src/entities/automation/value-ref-tf.js +1 -1
- package/dist-sdk/src/entities/chart/from-tf.js +9 -1
- package/dist-sdk/src/entities/chart/to-tf.js +10 -3
- package/dist-sdk/src/entities/data-lookup/module.js +2 -0
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +24 -31
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -5
- package/dist-sdk/src/entities/element/build.d.ts +28 -13
- package/dist-sdk/src/entities/element/build.js +5 -1
- package/dist-sdk/src/entities/element/from-tf.d.ts +11 -0
- package/dist-sdk/src/entities/element/from-tf.js +62 -1
- package/dist-sdk/src/entities/element/index.d.ts +5 -3
- package/dist-sdk/src/entities/element/index.js +1 -0
- package/dist-sdk/src/entities/element/module.js +9 -3
- package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
- package/dist-sdk/src/entities/element/to-tf.js +16 -16
- package/dist-sdk/src/entities/field/build.d.ts +17 -3
- package/dist-sdk/src/entities/field/build.js +3 -0
- package/dist-sdk/src/entities/field/calc.d.ts +7 -7
- package/dist-sdk/src/entities/field/from-tf.d.ts +5 -4
- package/dist-sdk/src/entities/field/from-tf.js +244 -49
- package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
- package/dist-sdk/src/entities/field/media-types.js +30 -0
- package/dist-sdk/src/entities/field/module.js +2 -0
- package/dist-sdk/src/entities/field/options.js +6 -1
- package/dist-sdk/src/entities/field/to-tf.d.ts +26 -5
- package/dist-sdk/src/entities/field/to-tf.js +137 -15
- package/dist-sdk/src/entities/field/types.d.ts +2 -0
- package/dist-sdk/src/entities/field/types.js +27 -0
- package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
- package/dist-sdk/src/entities/file-reader/module.js +1 -0
- package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
- package/dist-sdk/src/entities/file-reader/types.js +1 -1
- package/dist-sdk/src/entities/portal/build.d.ts +26 -0
- package/dist-sdk/src/entities/portal/build.js +37 -0
- package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
- package/dist-sdk/src/entities/portal/from-tf.js +75 -0
- package/dist-sdk/src/entities/portal/index.d.ts +1 -0
- package/dist-sdk/src/entities/portal/index.js +1 -0
- package/dist-sdk/src/entities/portal/module.d.ts +3 -0
- package/dist-sdk/src/entities/portal/module.js +28 -0
- package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
- package/dist-sdk/src/entities/portal/to-tf.js +73 -0
- package/dist-sdk/src/entities/portal/types.d.ts +1 -0
- package/dist-sdk/src/entities/portal/types.js +1 -0
- package/dist-sdk/src/entities/relationship/module.js +2 -0
- package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
- package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
- package/dist-sdk/src/entities/relationship/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/relationship/to-tf.js +12 -3
- package/dist-sdk/src/entities/role/from-tf.js +3 -3
- package/dist-sdk/src/entities/role/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/role/to-tf.js +12 -4
- package/dist-sdk/src/entities/search-table/module.js +1 -0
- package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
- package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
- package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
- package/dist-sdk/src/entities/service-account/from-tf.js +20 -8
- package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
- package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
- package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
- package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
- package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +16 -0
- package/dist-sdk/src/entities/service-account/workspace-owner.js +22 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +23 -1
- package/dist-sdk/src/entities/shared/filters/ast.js +2 -0
- package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
- package/dist-sdk/src/entities/shared/filters/index.js +19 -4
- package/dist-sdk/src/entities/shared/filters/print.js +24 -3
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +7 -0
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +46 -7
- package/dist-sdk/src/entities/shared/filters/types.d.ts +15 -2
- package/dist-sdk/src/entities/shared/ref.d.ts +5 -7
- package/dist-sdk/src/entities/shared/ref.js +5 -7
- package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +9 -0
- package/dist-sdk/src/entities/shared/tool-field-ref.js +35 -2
- package/dist-sdk/src/entities/shared/types/field-types.d.ts +20 -5
- package/dist-sdk/src/entities/shared/types/field-types.js +8 -0
- package/dist-sdk/src/entities/skill/access-policy.js +3 -3
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +14 -6
- package/dist-sdk/src/entities/skill/from-tf.js +70 -15
- package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
- package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
- package/dist-sdk/src/entities/skill/module.js +2 -0
- package/dist-sdk/src/entities/skill/to-tf.js +14 -4
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.js +49 -10
- package/dist-sdk/src/entities/skill-tool/module.js +3 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -8
- package/dist-sdk/src/entities/skill-tool/to-tf.js +49 -14
- package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
- package/dist-sdk/src/entities/table/catalog.js +66 -0
- package/dist-sdk/src/entities/table/module.js +2 -1
- package/dist-sdk/src/entities/table/to-tf.js +2 -2
- package/dist-sdk/src/entities/task/build.d.ts +8 -0
- package/dist-sdk/src/entities/task/build.js +10 -1
- package/dist-sdk/src/entities/task/from-tf.d.ts +4 -2
- package/dist-sdk/src/entities/task/from-tf.js +7 -2
- package/dist-sdk/src/entities/task/module.js +2 -2
- package/dist-sdk/src/entities/task/to-tf.d.ts +8 -4
- package/dist-sdk/src/entities/task/to-tf.js +28 -1
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +49 -9
- package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +71 -18
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +19 -4
- package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +82 -10
- package/dist-sdk/src/entities/view/agent-view-layout.d.ts +53 -23
- package/dist-sdk/src/entities/view/agent-view-layout.js +1 -1
- package/dist-sdk/src/entities/view/from-tf.d.ts +3 -2
- package/dist-sdk/src/entities/view/from-tf.js +133 -13
- package/dist-sdk/src/entities/view/module.js +30 -3
- package/dist-sdk/src/entities/view/to-tf.d.ts +20 -8
- package/dist-sdk/src/entities/view/to-tf.js +86 -18
- package/dist-sdk/src/entities/view/types.d.ts +4 -15
- package/dist-sdk/src/entities/view/types.js +15 -15
- package/dist-sdk/src/entities/visual-flow/build.d.ts +16 -1
- package/dist-sdk/src/entities/visual-flow/build.js +9 -0
- package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +14 -0
- package/dist-sdk/src/entities/visual-flow/from-tf.js +51 -3
- package/dist-sdk/src/entities/visual-flow/index.d.ts +1 -1
- package/dist-sdk/src/entities/visual-flow/index.js +1 -1
- package/dist-sdk/src/entities/visual-flow/printer.js +19 -0
- package/dist-sdk/src/entities/visual-flow/to-tf.js +87 -3
- package/dist-sdk/src/entities/widget/build.d.ts +16 -1
- package/dist-sdk/src/entities/widget/build.js +11 -1
- package/dist-sdk/src/entities/widget/from-tf.js +3 -3
- package/dist-sdk/src/entities/widget/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/widget/to-tf.js +41 -14
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +148 -13
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +12 -0
- package/dist-sdk/src/graph/index.js +21 -0
- package/dist-sdk/src/graph/modules.js +2 -0
- package/dist-sdk/src/graph/types.d.ts +83 -4
- package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
- package/dist-sdk/src/internal/sdk-package.js +1 -0
- package/package.json +16 -3
|
@@ -12,11 +12,32 @@
|
|
|
12
12
|
import { EntityTfError } from "../../engine/entity.js";
|
|
13
13
|
import { workspaceAspectKey } from "../../engine/build/context.js";
|
|
14
14
|
import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
15
|
-
import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
|
|
15
|
+
import { SYSTEM_FIELD_KEY_SET, systemFieldTag } from "../../core/system-fields.js";
|
|
16
|
+
import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS, ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
|
|
16
17
|
import { filterToTf as filterWireToTfCodec } from "../shared/filters/tf-codec.js";
|
|
17
18
|
import { foreignFieldDataLabel } from "../shared/foreign-ref.js";
|
|
19
|
+
import { isAttachmentMediaType } from "./media-types.js";
|
|
18
20
|
import { picklistLabel } from "./options.js";
|
|
19
21
|
import { SUB_TYPE_BY_AUTHORING_TYPE, SUB_TYPE_BY_TYPE_KEY } from "./types.js";
|
|
22
|
+
/** Reconstruct custom-field ownership from a loaded app/element payload. */
|
|
23
|
+
export function authoredFieldKeysFromPayload(payload) {
|
|
24
|
+
if (typeof payload !== "object" || payload === null)
|
|
25
|
+
return undefined;
|
|
26
|
+
const fields = payload.fields;
|
|
27
|
+
const keys = new Set();
|
|
28
|
+
for (const entry of fields ?? []) {
|
|
29
|
+
const inner = Object.values(entry)[0];
|
|
30
|
+
if (inner === undefined || systemFieldTag(inner) !== undefined)
|
|
31
|
+
continue;
|
|
32
|
+
const key = inner.__refName ?? snakeSlug(inner.name ?? "");
|
|
33
|
+
if (key !== "")
|
|
34
|
+
keys.add(key);
|
|
35
|
+
}
|
|
36
|
+
return keys;
|
|
37
|
+
}
|
|
38
|
+
function workspaceFieldOwnership(aspect) {
|
|
39
|
+
return authoredFieldKeysFromPayload(aspect.streamRootEntity?.payload);
|
|
40
|
+
}
|
|
20
41
|
/** `unknown` → the tagged org-field-ref shape, or undefined for anything else. */
|
|
21
42
|
function asOrgFieldRef(v) {
|
|
22
43
|
if (typeof v !== "object" || v === null || v.__kind !== "orgFieldRef")
|
|
@@ -89,12 +110,24 @@ function resolveRelatedObject(token, opts, where) {
|
|
|
89
110
|
const refName = token.refName ?? "";
|
|
90
111
|
const kind = token.__kind === "element" ? "element" : token.__kind === "task" ? "task" : "app";
|
|
91
112
|
if (kind === (opts.scope ?? "app") && refName === opts.appRefName) {
|
|
92
|
-
return {
|
|
113
|
+
return {
|
|
114
|
+
value: opts.objectId,
|
|
115
|
+
refName,
|
|
116
|
+
kind,
|
|
117
|
+
target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
|
|
118
|
+
fieldOwnership: opts.fieldOwnership,
|
|
119
|
+
};
|
|
93
120
|
}
|
|
94
121
|
const sibling = kind !== "task" ? opts.workspaceAspects?.get(workspaceAspectKey(kind, refName)) : undefined;
|
|
95
122
|
if (sibling !== undefined) {
|
|
96
123
|
const resourceType = kind === "element" ? "elementum_element" : "elementum_app";
|
|
97
|
-
return {
|
|
124
|
+
return {
|
|
125
|
+
value: expr.resourceAttr(resourceType, sibling.tfLabel, ["id"]),
|
|
126
|
+
refName,
|
|
127
|
+
kind,
|
|
128
|
+
target: sibling,
|
|
129
|
+
fieldOwnership: workspaceFieldOwnership(sibling),
|
|
130
|
+
};
|
|
98
131
|
}
|
|
99
132
|
const name = token.name ?? refName;
|
|
100
133
|
if (name === "") {
|
|
@@ -161,14 +194,18 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
|
|
|
161
194
|
opts.diagnostics.push(`${where}: ${attrName} token "${refName}" belongs to "${token.parent}", not the resolved target "${object.refName}"; dropped`);
|
|
162
195
|
return undefined;
|
|
163
196
|
}
|
|
164
|
-
|
|
197
|
+
// `target` is set only for the owner itself or a workspace app/element
|
|
198
|
+
// sibling (resolveRelatedObject); another task never carries one and falls
|
|
199
|
+
// through to the data lookup below. So a "task" target is always the
|
|
200
|
+
// owning task, whose fields are resources since edk#1464.
|
|
201
|
+
if (object.target !== undefined) {
|
|
165
202
|
// A field belongs to an app or element; a table exposes columns, not fields.
|
|
166
203
|
// Guard rather than widen fieldRefToTfValue's scope parameter.
|
|
167
204
|
if (object.target.kind === "table") {
|
|
168
205
|
opts.diagnostics.push(`${where}: ${attrName} token "${refName}" resolves to table "${object.target.tfLabel}" — tables expose columns, not fields; dropped`);
|
|
169
206
|
return undefined;
|
|
170
207
|
}
|
|
171
|
-
const value = fieldRefToTfValue(token.fieldType ?? "", refName, object.target.tfLabel, object.target.kind);
|
|
208
|
+
const value = fieldRefToTfValue(token.fieldType ?? "", refName, object.target.tfLabel, object.target.kind, object.fieldOwnership);
|
|
172
209
|
if (value === undefined) {
|
|
173
210
|
opts.diagnostics.push(`${where}: ${attrName} token "${refName}" has no terraform field resource mapping (fieldType ${JSON.stringify(token.fieldType ?? "")}); dropped`);
|
|
174
211
|
}
|
|
@@ -214,7 +251,7 @@ function stageOrgRefs(real) {
|
|
|
214
251
|
foreignApp: (tfLabel, name, namespace) => pending.push(() => real.foreignApp(tfLabel, name, namespace)),
|
|
215
252
|
foreignTask: (tfLabel, name, namespace) => pending.push(() => real.foreignTask(tfLabel, name, namespace)),
|
|
216
253
|
foreignElement: (tfLabel, name, namespace) => pending.push(() => real.foreignElement(tfLabel, name, namespace)),
|
|
217
|
-
foreignField: (type, tfLabel, objectId, name) => pending.push(() => real.foreignField(type, tfLabel, objectId, name)),
|
|
254
|
+
foreignField: (type, tfLabel, objectId, name, extraAttrs) => pending.push(() => real.foreignField(type, tfLabel, objectId, name, extraAttrs)),
|
|
218
255
|
};
|
|
219
256
|
return { orgRefs, commit: () => { for (const apply of pending)
|
|
220
257
|
apply(); } };
|
|
@@ -255,7 +292,13 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
|
|
|
255
292
|
// field's own app/element) — a cascading-parent trigger, not a field
|
|
256
293
|
// on relatedAspectId's target. See `AppField.parentField`'s doc
|
|
257
294
|
// comment (the sibling STATIC mechanism this mirrors).
|
|
258
|
-
const owner = {
|
|
295
|
+
const owner = {
|
|
296
|
+
value: opts.objectId,
|
|
297
|
+
refName: opts.appRefName,
|
|
298
|
+
kind: opts.scope ?? "app",
|
|
299
|
+
target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
|
|
300
|
+
fieldOwnership: opts.fieldOwnership,
|
|
301
|
+
};
|
|
259
302
|
const parentFieldId = resolveFieldOnObject(cfg.parentFieldId, owner, opts_, where, "parentFieldId");
|
|
260
303
|
if (parentFieldId === undefined)
|
|
261
304
|
return undefined;
|
|
@@ -292,7 +335,13 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
|
|
|
292
335
|
attrs["values_render_type"] = cfg.valuesRenderType;
|
|
293
336
|
if (cfg.filter !== undefined) {
|
|
294
337
|
let unresolvedField = false;
|
|
295
|
-
const owner = {
|
|
338
|
+
const owner = {
|
|
339
|
+
value: opts.objectId,
|
|
340
|
+
refName: opts.appRefName,
|
|
341
|
+
kind: opts.scope ?? "app",
|
|
342
|
+
target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
|
|
343
|
+
fieldOwnership: opts.fieldOwnership,
|
|
344
|
+
};
|
|
296
345
|
try {
|
|
297
346
|
const filterValue = filterWireToTfCodec(cfg.filter, {
|
|
298
347
|
recordField: (token) => {
|
|
@@ -303,6 +352,7 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
|
|
|
303
352
|
}
|
|
304
353
|
return value;
|
|
305
354
|
},
|
|
355
|
+
recordFieldOwner: () => opts.objectId,
|
|
306
356
|
field: (token) => {
|
|
307
357
|
const value = resolveFieldOnObject(token, resolvedObject, opts_, where, "filter field");
|
|
308
358
|
if (value === undefined) {
|
|
@@ -346,6 +396,7 @@ function resolveDynamicMappingFieldOwner(token, opts, where) {
|
|
|
346
396
|
refName: opts.appRefName,
|
|
347
397
|
kind: opts.scope ?? "app",
|
|
348
398
|
target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
|
|
399
|
+
fieldOwnership: opts.fieldOwnership,
|
|
349
400
|
};
|
|
350
401
|
}
|
|
351
402
|
if (token.parent === undefined || token.parentKind === undefined) {
|
|
@@ -356,6 +407,7 @@ function resolveDynamicMappingFieldOwner(token, opts, where) {
|
|
|
356
407
|
__kind: token.parentKind,
|
|
357
408
|
refName: token.parent,
|
|
358
409
|
name: token.parentName ?? token.parent,
|
|
410
|
+
...(token.parentNamespace !== undefined ? { namespace: token.parentNamespace } : {}),
|
|
359
411
|
}, opts, where);
|
|
360
412
|
}
|
|
361
413
|
function resolveDynamicPicklistSort(sort, relatedObject, opts, where) {
|
|
@@ -392,6 +444,7 @@ function buildStaticPicklistConfigAttr(cfg, opts, where) {
|
|
|
392
444
|
refName: opts.appRefName,
|
|
393
445
|
kind: opts.scope ?? "app",
|
|
394
446
|
target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
|
|
447
|
+
fieldOwnership: opts.fieldOwnership,
|
|
395
448
|
};
|
|
396
449
|
if (cfg.parentFieldId !== undefined) {
|
|
397
450
|
const parentFieldId = resolveFieldOnObject(cfg.parentFieldId, owner, opts, where, "parentFieldId");
|
|
@@ -410,6 +463,28 @@ function buildStaticPicklistConfigAttr(cfg, opts, where) {
|
|
|
410
463
|
return attrs;
|
|
411
464
|
}
|
|
412
465
|
/** One custom field → its resource block; undefined = degraded (diagnostic already pushed). */
|
|
466
|
+
/** Field resources whose provider schema has no `default_value`; the platform default for these is an option/record id the provider does not manage. */
|
|
467
|
+
const NO_DEFAULT_VALUE_RESOURCES = new Map([
|
|
468
|
+
["elementum_dropdown_field", "Dropdown"],
|
|
469
|
+
["elementum_multiselect_field", "Multi-select"],
|
|
470
|
+
["elementum_relation_field", "Relation"],
|
|
471
|
+
["elementum_attachment_field", "Attachment"],
|
|
472
|
+
]);
|
|
473
|
+
/**
|
|
474
|
+
* Field display names must be unique within an app or element. The platform rejects the second one only at
|
|
475
|
+
* apply ("Duplicate key found.", naming neither field) after the rest of the apply has landed, so fail the build
|
|
476
|
+
* first and name both fields.
|
|
477
|
+
*/
|
|
478
|
+
export function claimFieldDisplayName(seen, field) {
|
|
479
|
+
const name = field.block.attrs["name"];
|
|
480
|
+
if (typeof name !== "string")
|
|
481
|
+
return;
|
|
482
|
+
const prior = seen.get(name);
|
|
483
|
+
if (prior !== undefined) {
|
|
484
|
+
throw new EntityTfError(`fields.${field.bagKey} and fields.${prior} both have the display name ${JSON.stringify(name)}; field display names must be unique within an app or element`);
|
|
485
|
+
}
|
|
486
|
+
seen.set(name, field.bagKey);
|
|
487
|
+
}
|
|
413
488
|
export function fieldToTf(typeKey, inner, opts) {
|
|
414
489
|
const { ownerTfLabel, scope = "app", objectId, diagnostics } = opts;
|
|
415
490
|
const name = inner.name ?? "";
|
|
@@ -486,7 +561,7 @@ export function fieldToTf(typeKey, inner, opts) {
|
|
|
486
561
|
if (typeof include.picklist === "object" && include.picklist !== null) {
|
|
487
562
|
const field = include.picklist.picklistFieldId;
|
|
488
563
|
if (field?.refName !== undefined) {
|
|
489
|
-
const value = fieldRefToTfValue(field.fieldType ?? "PICKLIST", field.refName, ownerTfLabel, scope);
|
|
564
|
+
const value = fieldRefToTfValue(field.fieldType ?? "PICKLIST", field.refName, ownerTfLabel, scope, opts.fieldOwnership);
|
|
490
565
|
if (value !== undefined) {
|
|
491
566
|
attrs["include_type"] = "PICKLIST";
|
|
492
567
|
attrs["picklist_field_id"] = value;
|
|
@@ -509,7 +584,10 @@ export function fieldToTf(typeKey, inner, opts) {
|
|
|
509
584
|
if (subType.typeKey === "calculated" && inner.defaultValue !== undefined) {
|
|
510
585
|
diagnostics.push(`field "${name}": calculated fields do not support defaultValue; dropped`);
|
|
511
586
|
}
|
|
512
|
-
if (subType.
|
|
587
|
+
else if (NO_DEFAULT_VALUE_RESOURCES.has(subType.resourceType) && inner.defaultValue !== undefined) {
|
|
588
|
+
diagnostics.push(`field "${name}": ${NO_DEFAULT_VALUE_RESOURCES.get(subType.resourceType)} fields cannot set defaultValue; defaultValue dropped`);
|
|
589
|
+
}
|
|
590
|
+
if (subType.typeKey !== "calculated" && !NO_DEFAULT_VALUE_RESOURCES.has(subType.resourceType) && inner.defaultValue !== undefined) {
|
|
513
591
|
const orgRef = asOrgFieldRef(inner.defaultValue);
|
|
514
592
|
if (orgRef !== undefined) {
|
|
515
593
|
if (opts.orgRefs === undefined) {
|
|
@@ -533,6 +611,16 @@ export function fieldToTf(typeKey, inner, opts) {
|
|
|
533
611
|
if (inner.tags !== undefined && inner.tags.length > 0) {
|
|
534
612
|
attrs["field_role"] = [...inner.tags];
|
|
535
613
|
}
|
|
614
|
+
if (inner.mediaTypes !== undefined) {
|
|
615
|
+
if (subType.typeKey !== "attachment") {
|
|
616
|
+
diagnostics.push(`field "${name}": mediaTypes is only valid on attachment fields; dropped`);
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
const mediaTypes = attachmentMediaTypes(inner.mediaTypes, diagnostics, name);
|
|
620
|
+
if (mediaTypes !== undefined)
|
|
621
|
+
attrs["media_types"] = mediaTypes;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
536
624
|
if (typeKey === "decimal" && inner.decimalPlaces !== undefined) {
|
|
537
625
|
if (attrs["decimal_places"] !== undefined && attrs["decimal_places"] !== inner.decimalPlaces) {
|
|
538
626
|
diagnostics.push(`field "${name}": decimalPlaces conflicts with numericFormat.decimalPlaces; decimalPlaces wins`);
|
|
@@ -626,6 +714,26 @@ export function fieldToTf(typeKey, inner, opts) {
|
|
|
626
714
|
const block = { kind: "resource", type: subType.resourceType, label: tfLabel, attrs };
|
|
627
715
|
return { block, bagKey, address: `${subType.resourceType}.${tfLabel}` };
|
|
628
716
|
}
|
|
717
|
+
/**
|
|
718
|
+
* Attachment `media_types`. An unset or empty list stays omitted so a field
|
|
719
|
+
* without a restriction keeps its previous HCL. A value that is not
|
|
720
|
+
* `type/subtype` drops the attribute rather than emitting a list that
|
|
721
|
+
* matches no upload.
|
|
722
|
+
*/
|
|
723
|
+
function attachmentMediaTypes(value, diagnostics, name) {
|
|
724
|
+
if (!Array.isArray(value)) {
|
|
725
|
+
diagnostics.push(`field "${name}": mediaTypes must be a list of MIME types; dropped`);
|
|
726
|
+
return undefined;
|
|
727
|
+
}
|
|
728
|
+
const badAt = value.findIndex((entry) => !isAttachmentMediaType(entry));
|
|
729
|
+
if (badAt !== -1) {
|
|
730
|
+
diagnostics.push(`field "${name}": mediaTypes entry ${JSON.stringify(value[badAt])} is not a MIME type (expected type/subtype); dropped`);
|
|
731
|
+
return undefined;
|
|
732
|
+
}
|
|
733
|
+
if (value.length === 0)
|
|
734
|
+
return undefined;
|
|
735
|
+
return [...value];
|
|
736
|
+
}
|
|
629
737
|
function scalarOrUndefined(v) {
|
|
630
738
|
return typeof v === "string" || typeof v === "number" || typeof v === "boolean" ? v : undefined;
|
|
631
739
|
}
|
|
@@ -643,16 +751,30 @@ function scalarOrUndefined(v) {
|
|
|
643
751
|
* diagnostic wording since the two failure cases usually read differently
|
|
644
752
|
* at each call site.
|
|
645
753
|
*/
|
|
646
|
-
/**
|
|
647
|
-
|
|
648
|
-
|
|
754
|
+
/**
|
|
755
|
+
* Element system fields resolve through their `element/locals.ts` locals.
|
|
756
|
+
* Elements have no status/stage fields; the audit fields exist only on some
|
|
757
|
+
* elements, which the build checks against `systemFields.audit`. An element
|
|
758
|
+
* may author its own field under an audit key (`createdAt: dateTimeField(…)`),
|
|
759
|
+
* which shadows the audit field, so a key in `fieldAddresses` is that field.
|
|
760
|
+
*/
|
|
761
|
+
const ELEMENT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_SYSTEM_FIELD_KEYS);
|
|
762
|
+
const ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_AUDIT_SYSTEM_FIELD_KEYS);
|
|
763
|
+
export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app", fieldOwnership) {
|
|
649
764
|
if (!isCanonicalTsLabel(refName))
|
|
650
765
|
return undefined;
|
|
651
|
-
|
|
766
|
+
if (scope === "element" &&
|
|
767
|
+
ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET.has(refName) &&
|
|
768
|
+
fieldOwnership === undefined) {
|
|
769
|
+
throw new EntityTfError(`element field "${refName}" requires authored-field ownership metadata to distinguish a custom field from the platform audit field`);
|
|
770
|
+
}
|
|
771
|
+
const isSystemField = scope === "element"
|
|
772
|
+
? ELEMENT_SYSTEM_FIELD_KEY_SET.has(refName) && !(ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET.has(refName) && fieldOwnership?.has(refName) === true)
|
|
773
|
+
: SYSTEM_FIELD_KEY_SET.has(refName);
|
|
652
774
|
if (isSystemField) {
|
|
653
775
|
return expr.local(`${ownerTfLabel}_${tsLabelToTfLabel(refName)}_field_id`);
|
|
654
776
|
}
|
|
655
|
-
const knownAddress =
|
|
777
|
+
const knownAddress = fieldOwnership?.get?.(refName);
|
|
656
778
|
if (knownAddress !== undefined) {
|
|
657
779
|
const dotIndex = knownAddress.indexOf(".");
|
|
658
780
|
if (dotIndex !== -1) {
|
|
@@ -51,3 +51,5 @@ export declare const SUB_TYPE_BY_AUTHORING_TYPE: ReadonlyMap<string, FieldSubTyp
|
|
|
51
51
|
export declare const FIELD_RESOURCE_TYPES: readonly string[];
|
|
52
52
|
/** Attributes `fieldFromTf` understands — anything else is dialect growth, reported loudly. */
|
|
53
53
|
export declare const KNOWN_FIELD_ATTRS: ReadonlySet<string>;
|
|
54
|
+
/** Provider resource type a field constructor builds, or undefined for unmodeled constructors. */
|
|
55
|
+
export declare function fieldResourceTypeForCtor(ctor: string): string | undefined;
|
|
@@ -77,3 +77,30 @@ export const KNOWN_FIELD_ATTRS = new Set([
|
|
|
77
77
|
"picklist_field_id",
|
|
78
78
|
"media_types",
|
|
79
79
|
]);
|
|
80
|
+
/** Authoring constructor base name (`richText` for `richTextField`) → FIELD_SUB_TYPES typeKey. */
|
|
81
|
+
const FIELD_CTOR_TYPE_KEYS = {
|
|
82
|
+
text: "text",
|
|
83
|
+
richText: "html",
|
|
84
|
+
number: "number",
|
|
85
|
+
decimal: "decimal",
|
|
86
|
+
boolean: "bool",
|
|
87
|
+
date: "date",
|
|
88
|
+
dateTime: "dateTime",
|
|
89
|
+
user: "user",
|
|
90
|
+
group: "group",
|
|
91
|
+
attachment: "attachment",
|
|
92
|
+
json: "json",
|
|
93
|
+
dropdown: "picklist",
|
|
94
|
+
multiSelect: "multiPicklist",
|
|
95
|
+
/** @deprecated constructor; still authored in older workspaces. */
|
|
96
|
+
picklist: "picklist",
|
|
97
|
+
/** @deprecated constructor; still authored in older workspaces. */
|
|
98
|
+
multiPicklist: "multiPicklist",
|
|
99
|
+
relation: "relation",
|
|
100
|
+
calculated: "calculated",
|
|
101
|
+
};
|
|
102
|
+
/** Provider resource type a field constructor builds, or undefined for unmodeled constructors. */
|
|
103
|
+
export function fieldResourceTypeForCtor(ctor) {
|
|
104
|
+
const typeKey = FIELD_CTOR_TYPE_KEYS[ctor];
|
|
105
|
+
return typeKey === undefined ? undefined : FIELD_SUB_TYPES.find((t) => t.typeKey === typeKey)?.resourceType;
|
|
106
|
+
}
|
|
@@ -151,14 +151,22 @@ export function fileReaderFromTf(block, appTfLabel, _ctx) {
|
|
|
151
151
|
const fields = parseExcelFields(attrs.fields ?? [], where);
|
|
152
152
|
// document_content/document_name/file_type are never returned by
|
|
153
153
|
// Read() on an already-imported resource (the provider's schema docs
|
|
154
|
-
// say so),
|
|
154
|
+
// say so), and older exports emitted placeholders for them - even
|
|
155
155
|
// document_content's empty-string placeholder counts as a change on
|
|
156
|
-
// this always-forces-replacement attribute, so reproducing
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
156
|
+
// this always-forces-replacement attribute, so reproducing them plans a
|
|
157
|
+
// spurious destroy+recreate. Only a real document is extracted: one a
|
|
158
|
+
// re-pull filled from this workspace's own state
|
|
159
|
+
// (alignExportWithState), which is what the reader holds.
|
|
160
|
+
// Adoption separately strips these attributes from `.tf/in/` itself
|
|
160
161
|
// (stripUnrecoverableExcelFileReaderAttrs in engine/adopt/adopt.ts),
|
|
161
162
|
// since its gate plans against ei's raw export, not this extractor.
|
|
163
|
+
const document = typeof attrs.document_content === "string" && attrs.document_content !== ""
|
|
164
|
+
? {
|
|
165
|
+
documentContent: attrs.document_content,
|
|
166
|
+
...(typeof attrs.document_name === "string" && { documentName: attrs.document_name }),
|
|
167
|
+
...(typeof attrs.file_type === "string" && { fileType: attrs.file_type }),
|
|
168
|
+
}
|
|
169
|
+
: {};
|
|
162
170
|
return {
|
|
163
171
|
fileReader: {
|
|
164
172
|
refName,
|
|
@@ -167,6 +175,7 @@ export function fileReaderFromTf(block, appTfLabel, _ctx) {
|
|
|
167
175
|
name,
|
|
168
176
|
firstRowIsHeader: attrs.first_row_is_header,
|
|
169
177
|
fields,
|
|
178
|
+
...document,
|
|
170
179
|
},
|
|
171
180
|
},
|
|
172
181
|
};
|
|
@@ -87,6 +87,7 @@ export const fileReaderModule = {
|
|
|
87
87
|
key: t.typeKey,
|
|
88
88
|
resourceType: t.resourceType,
|
|
89
89
|
implemented: t.implemented === true,
|
|
90
|
+
...(t.unreadableAttributes !== undefined && { unreadableAttributes: t.unreadableAttributes }),
|
|
90
91
|
})),
|
|
91
92
|
},
|
|
92
93
|
data: { participates: true, resourceType: "elementum_ai_file_reader", lookupAttr: "name", referencedByBuild: false },
|
|
@@ -21,6 +21,8 @@ export interface FileReaderSubType {
|
|
|
21
21
|
readonly resourceType: string;
|
|
22
22
|
/** Round-trips on the terraform path (to-tf + from-tf + printer). */
|
|
23
23
|
readonly implemented?: true;
|
|
24
|
+
/** Attributes the platform never returns on read; a re-pull fills them from state. */
|
|
25
|
+
readonly unreadableAttributes?: readonly string[];
|
|
24
26
|
}
|
|
25
27
|
export declare const FILE_READER_SUB_TYPES: readonly FileReaderSubType[];
|
|
26
28
|
export declare const FILE_READER_SUB_TYPE_BY_TYPE_KEY: ReadonlyMap<string, FileReaderSubType>;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* provider's `values` attribute.
|
|
16
16
|
*/
|
|
17
17
|
export const FILE_READER_SUB_TYPES = [
|
|
18
|
-
{ typeKey: "excel", resourceType: "elementum_excel_file_reader", implemented: true },
|
|
18
|
+
{ typeKey: "excel", resourceType: "elementum_excel_file_reader", implemented: true, unreadableAttributes: ["document_content", "document_name", "file_type"] },
|
|
19
19
|
{ typeKey: "json", resourceType: "elementum_json_file_reader", implemented: true },
|
|
20
20
|
{ typeKey: "text", resourceType: "elementum_text_file_reader", implemented: true },
|
|
21
21
|
{ typeKey: "xml", resourceType: "elementum_xml_file_reader", implemented: true },
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ViewRef } from "../../catalog/index.js";
|
|
2
|
+
import type { DeployableEntity, EntityDeployOptions } from "../../engine/entity.js";
|
|
3
|
+
/** One portal menu entry: a managed view under its own slug. */
|
|
4
|
+
export interface PortalMenuItem {
|
|
5
|
+
readonly view: ViewRef;
|
|
6
|
+
readonly slug: string;
|
|
7
|
+
/** Menu text; the platform shows the view's name when omitted. */
|
|
8
|
+
readonly label?: string;
|
|
9
|
+
/** Opens this view when the portal opens. At most one item. */
|
|
10
|
+
readonly home?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface DefinePortalOptions extends EntityDeployOptions {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly slug: string;
|
|
15
|
+
/** Once set, the platform can change it but not clear it. */
|
|
16
|
+
readonly description?: string;
|
|
17
|
+
/** Once set, the platform can change it but not clear it. */
|
|
18
|
+
readonly icon?: string;
|
|
19
|
+
/** Once set, the platform can change it but not clear it. */
|
|
20
|
+
readonly color?: string;
|
|
21
|
+
readonly menu?: readonly PortalMenuItem[];
|
|
22
|
+
}
|
|
23
|
+
export interface PortalConfigured {
|
|
24
|
+
def(refName: string): DeployableEntity;
|
|
25
|
+
}
|
|
26
|
+
export declare function portal(opts: DefinePortalOptions): PortalConfigured;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { slimTokens } from "../../catalog/index.js";
|
|
2
|
+
// View names aren't unique, so a catalog view is identified by its owner, bag
|
|
3
|
+
// and key; only a viewRef outside the workspace falls back to its name.
|
|
4
|
+
const viewKey = (view) => view.viewType !== undefined
|
|
5
|
+
? `${view.parentKind ?? "app"}:${view.parent}:${view.viewType}:${view.refName}`
|
|
6
|
+
: `${view.parentKind ?? "app"}:${view.parentNamespace ?? view.parent}:${view.name}`;
|
|
7
|
+
export function portal(opts) {
|
|
8
|
+
const where = `portal ${JSON.stringify(opts.name)}`;
|
|
9
|
+
if (opts.name.trim() === "")
|
|
10
|
+
throw new Error("portal requires a non-empty name.");
|
|
11
|
+
if (opts.slug.trim() === "")
|
|
12
|
+
throw new Error(`${where}: slug is required.`);
|
|
13
|
+
for (const key of ["description", "icon", "color"]) {
|
|
14
|
+
if (opts[key]?.trim() === "")
|
|
15
|
+
throw new Error(`${where}: ${key} can't be empty; leave it out instead.`);
|
|
16
|
+
}
|
|
17
|
+
const menu = opts.menu ?? [];
|
|
18
|
+
const slugs = new Set();
|
|
19
|
+
const views = new Set();
|
|
20
|
+
for (const item of menu) {
|
|
21
|
+
if (item.slug.trim() === "")
|
|
22
|
+
throw new Error(`${where}: menu item for view ${JSON.stringify(item.view.name)} needs a slug.`);
|
|
23
|
+
if (item.label?.trim() === "")
|
|
24
|
+
throw new Error(`${where}: menu item ${JSON.stringify(item.slug)} has an empty label; leave it out to show the view's name.`);
|
|
25
|
+
if (slugs.has(item.slug))
|
|
26
|
+
throw new Error(`${where}: menu slug ${JSON.stringify(item.slug)} is used twice.`);
|
|
27
|
+
if (views.has(viewKey(item.view)))
|
|
28
|
+
throw new Error(`${where}: view ${JSON.stringify(item.view.name)} is in the menu twice.`);
|
|
29
|
+
slugs.add(item.slug);
|
|
30
|
+
views.add(viewKey(item.view));
|
|
31
|
+
}
|
|
32
|
+
if (menu.filter((item) => item.home === true).length > 1)
|
|
33
|
+
throw new Error(`${where}: only one menu item can be the homepage.`);
|
|
34
|
+
return { def(refName) {
|
|
35
|
+
return { kind: "portal", parent: "org", refName, payload: slimTokens(opts), ...(opts.enabled !== undefined ? { enabled: opts.enabled } : {}) };
|
|
36
|
+
} };
|
|
37
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type FromTfContext } from "../../engine/pull/context.js";
|
|
2
|
+
import { type TfBlock } from "../../engine/tf/index.js";
|
|
3
|
+
/** A view's owner as the export looks it up: an app or element by namespace, a task by name. */
|
|
4
|
+
export type PortalViewOwner = {
|
|
5
|
+
readonly kind: "app" | "element";
|
|
6
|
+
readonly namespace: string;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: "task";
|
|
9
|
+
readonly name: string;
|
|
10
|
+
};
|
|
11
|
+
export interface NormalizedPortalItem {
|
|
12
|
+
readonly owner: PortalViewOwner;
|
|
13
|
+
readonly viewName: string;
|
|
14
|
+
readonly slug: string;
|
|
15
|
+
readonly label?: string;
|
|
16
|
+
readonly home?: true;
|
|
17
|
+
}
|
|
18
|
+
export interface NormalizedPortal {
|
|
19
|
+
readonly refName: string;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly slug: string;
|
|
22
|
+
readonly description?: string;
|
|
23
|
+
readonly icon?: string;
|
|
24
|
+
readonly color?: string;
|
|
25
|
+
readonly items: readonly NormalizedPortalItem[];
|
|
26
|
+
}
|
|
27
|
+
export declare function portalFromTf(block: TfBlock, ctx: FromTfContext): NormalizedPortal;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { optionalBoolean, optionalString, plainObject } from "../../engine/pull/context.js";
|
|
2
|
+
import { isTfExpr, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
3
|
+
import { VIEW_DATA_RESOURCE_TYPE } from "../view/types.js";
|
|
4
|
+
import { PORTAL_RESOURCE_TYPE } from "./types.js";
|
|
5
|
+
function ownerOf(type, attrs) {
|
|
6
|
+
const namespace = attrs?.["namespace"];
|
|
7
|
+
const name = attrs?.["name"];
|
|
8
|
+
if (type === "elementum_app" && typeof namespace === "string")
|
|
9
|
+
return { kind: "app", namespace };
|
|
10
|
+
if (type === "elementum_element" && typeof namespace === "string")
|
|
11
|
+
return { kind: "element", namespace };
|
|
12
|
+
if (type === "elementum_task" && typeof name === "string")
|
|
13
|
+
return { kind: "task", name };
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const KNOWN = new Set(["id", "url", "name", "slug", "description", "icon", "color", "menu_item"]);
|
|
17
|
+
const KNOWN_ITEM = new Set(["view_id", "slug", "label", "home"]);
|
|
18
|
+
/** A menu view reaches the portal as `data.elementum_view.<label>.id`, whose owner is itself a lookup. */
|
|
19
|
+
function viewOf(value, where, ctx) {
|
|
20
|
+
if (value === undefined || !isTfExpr(value) || value.$expr !== "data-attr" || value.type !== VIEW_DATA_RESOURCE_TYPE) {
|
|
21
|
+
throw new Error(`${where}: view_id must reference data.${VIEW_DATA_RESOURCE_TYPE}, got ${JSON.stringify(value)}`);
|
|
22
|
+
}
|
|
23
|
+
const view = ctx.dataAttrs?.(VIEW_DATA_RESOURCE_TYPE, value.label);
|
|
24
|
+
const viewName = view?.["name"];
|
|
25
|
+
const owner = view?.["owner_id"];
|
|
26
|
+
if (typeof viewName !== "string" || owner === undefined || !isTfExpr(owner) || owner.$expr !== "data-attr") {
|
|
27
|
+
throw new Error(`${where}: data.${VIEW_DATA_RESOURCE_TYPE}.${value.label} needs a name and an owner_id lookup`);
|
|
28
|
+
}
|
|
29
|
+
const viewOwner = ownerOf(owner.type, ctx.dataAttrs?.(owner.type, owner.label));
|
|
30
|
+
if (viewOwner === undefined) {
|
|
31
|
+
throw new Error(`${where}: the owner of view ${JSON.stringify(viewName)} must be an app or element looked up by namespace, or a task looked up by name`);
|
|
32
|
+
}
|
|
33
|
+
return { owner: viewOwner, viewName };
|
|
34
|
+
}
|
|
35
|
+
export function portalFromTf(block, ctx) {
|
|
36
|
+
if (block.type !== PORTAL_RESOURCE_TYPE || !block.label)
|
|
37
|
+
throw new Error(`expected ${PORTAL_RESOURCE_TYPE}`);
|
|
38
|
+
const where = `portal ${block.label}`;
|
|
39
|
+
for (const key of Object.keys(block.attrs))
|
|
40
|
+
if (!KNOWN.has(key))
|
|
41
|
+
ctx.diagnostics.push(`${block.type}.${block.label}: unhandled attribute ${key}`);
|
|
42
|
+
const rawItems = block.attrs["menu_item"];
|
|
43
|
+
const items = (Array.isArray(rawItems) ? rawItems : []).map((raw, index) => {
|
|
44
|
+
const itemWhere = `${where} menu_item[${index}]`;
|
|
45
|
+
const item = plainObject(raw);
|
|
46
|
+
if (item === undefined)
|
|
47
|
+
throw new Error(`${itemWhere}: expected an object`);
|
|
48
|
+
for (const key of Object.keys(item))
|
|
49
|
+
if (!KNOWN_ITEM.has(key))
|
|
50
|
+
ctx.diagnostics.push(`${itemWhere}: unhandled attribute ${key}`);
|
|
51
|
+
const slug = optionalString(item, "slug", itemWhere, ctx);
|
|
52
|
+
if (slug === undefined)
|
|
53
|
+
throw new Error(`${itemWhere}: slug is required`);
|
|
54
|
+
const label = optionalString(item, "label", itemWhere, ctx);
|
|
55
|
+
return {
|
|
56
|
+
...viewOf(item["view_id"], itemWhere, ctx),
|
|
57
|
+
slug,
|
|
58
|
+
...(label !== undefined && { label }),
|
|
59
|
+
...(optionalBoolean(item, "home", itemWhere, ctx) === true && { home: true }),
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
const optional = (key) => {
|
|
63
|
+
const value = optionalString(block.attrs, key, where, ctx);
|
|
64
|
+
return value !== undefined ? { [key]: value } : {};
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
refName: tfLabelToTsLabel(block.label),
|
|
68
|
+
name: optionalString(block.attrs, "name", where, ctx) ?? "",
|
|
69
|
+
slug: optionalString(block.attrs, "slug", where, ctx) ?? "",
|
|
70
|
+
...optional("description"),
|
|
71
|
+
...optional("icon"),
|
|
72
|
+
...optional("color"),
|
|
73
|
+
items,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { portal, type DefinePortalOptions, type PortalConfigured, type PortalMenuItem } from "./build.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { portal } from "./build.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
2
|
+
import { NO_CATALOG } from "../../graph/types.js";
|
|
3
|
+
import { portalFromTf } from "./from-tf.js";
|
|
4
|
+
import { portalToTf } from "./to-tf.js";
|
|
5
|
+
import { PORTAL_RESOURCE_TYPE } from "./types.js";
|
|
6
|
+
function extract(stream, ctx) {
|
|
7
|
+
const blocks = stream.byKind.get("portal") ?? [];
|
|
8
|
+
if (blocks.length !== 1)
|
|
9
|
+
throw new Error(`expected exactly one ${PORTAL_RESOURCE_TYPE}, found ${blocks.length}`);
|
|
10
|
+
return { instance: portalFromTf(blocks[0], ctx) };
|
|
11
|
+
}
|
|
12
|
+
/** An org-level portal: `portals/<ref>/<ref>.ts`, labelled by its refName. */
|
|
13
|
+
export const portalModule = {
|
|
14
|
+
kind: "portal", stream: { role: "streamRoot", exportVerb: "portals" }, authoring: { unit: "ownFile", bag: "portals" }, parents: [{ parent: "org", child: "portal" }],
|
|
15
|
+
resource: { shape: "single", resourceType: PORTAL_RESOURCE_TYPE, adoptable: true },
|
|
16
|
+
data: { participates: false },
|
|
17
|
+
lifecycle: {
|
|
18
|
+
participates: true,
|
|
19
|
+
extractStreamRoot: extract,
|
|
20
|
+
toTf: (entity, ctx) => portalToTf(entity, {
|
|
21
|
+
tfLabel: tsLabelToTfLabel(entity.refName),
|
|
22
|
+
orgRefs: ctx.orgRefs,
|
|
23
|
+
diagnostics: ctx.diagnostics,
|
|
24
|
+
...(ctx.workspaceAspects !== undefined && { workspaceAspects: ctx.workspaceAspects }),
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
canvas: { participates: true, label: "Portals", glyph: "▦", component: "appDetail" }, catalog: NO_CATALOG,
|
|
28
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { OrgRefLookup, WorkspaceAspect } from "../../engine/build/context.js";
|
|
2
|
+
import { type DeployableEntity } from "../../engine/entity.js";
|
|
3
|
+
import { type TfBlock } from "../../engine/tf/index.js";
|
|
4
|
+
export interface PortalToTfContext {
|
|
5
|
+
readonly tfLabel: string;
|
|
6
|
+
readonly orgRefs: OrgRefLookup;
|
|
7
|
+
readonly diagnostics: string[];
|
|
8
|
+
readonly workspaceAspects?: ReadonlyMap<string, Pick<WorkspaceAspect, "tfLabel">>;
|
|
9
|
+
}
|
|
10
|
+
export declare function portalToTf(entity: DeployableEntity, ctx: PortalToTfContext): {
|
|
11
|
+
blocks: readonly TfBlock[];
|
|
12
|
+
};
|