@elementumai/edk 0.9.20 → 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 +19 -7
- package/dist-sdk/src/catalog/factories.d.ts +10 -2
- package/dist-sdk/src/catalog/factories.js +10 -1
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +1 -1
- package/dist-sdk/src/catalog/token.js +4 -0
- package/dist-sdk/src/catalog/types.d.ts +7 -1
- package/dist-sdk/src/catalog/types.js +1 -0
- package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -2
- package/dist-sdk/src/core/triggers/on-demand.js +7 -0
- package/dist-sdk/src/core/types/app.d.ts +2 -2
- 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 +21 -1
- package/dist-sdk/src/engine/ei/run.js +89 -2
- 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/result-output.js +27 -1
- package/dist-sdk/src/engine/tf/index.d.ts +1 -1
- package/dist-sdk/src/engine/tf/index.js +1 -1
- package/dist-sdk/src/engine/tf/labels.d.ts +22 -5
- package/dist-sdk/src/engine/tf/labels.js +45 -3
- package/dist-sdk/src/engine/tf/parse.js +3 -2
- package/dist-sdk/src/engine/validation.d.ts +5 -0
- package/dist-sdk/src/engine/validation.js +12 -2
- 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/agent/deserializer/print-agent-v2.d.ts +3 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +42 -19
- 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 +14 -3
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +8 -1
- package/dist-sdk/src/entities/agent-tool/from-tf.js +11 -5
- package/dist-sdk/src/entities/agent-tool/module.js +3 -0
- 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 +17 -3
- package/dist-sdk/src/entities/app/build.js +56 -4
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +6 -1
- package/dist-sdk/src/entities/app/from-tf.js +4 -0
- package/dist-sdk/src/entities/app/index.d.ts +2 -1
- package/dist-sdk/src/entities/app/index.js +1 -8
- package/dist-sdk/src/entities/app/to-tf.d.ts +6 -0
- package/dist-sdk/src/entities/app/to-tf.js +21 -2
- package/dist-sdk/src/entities/automation/build.d.ts +10 -2
- package/dist-sdk/src/entities/automation/build.js +104 -17
- package/dist-sdk/src/entities/automation/calculation-expression.d.ts +7 -7
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +17 -4
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +156 -19
- package/dist-sdk/src/entities/automation/from-tf.d.ts +9 -2
- package/dist-sdk/src/entities/automation/from-tf.js +366 -86
- package/dist-sdk/src/entities/automation/index.d.ts +1 -1
- 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 +70 -7
- package/dist-sdk/src/entities/automation/script-code.d.ts +5 -2
- package/dist-sdk/src/entities/automation/script-code.js +23 -5
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +37 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +76 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +92 -20
- package/dist-sdk/src/entities/automation/tasks.js +48 -15
- package/dist-sdk/src/entities/automation/to-tf.d.ts +20 -3
- package/dist-sdk/src/entities/automation/to-tf.js +606 -62
- package/dist-sdk/src/entities/automation/triggers.d.ts +8 -4
- 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/data-lookup/module.js +2 -0
- 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 +3 -0
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/from-tf.js +4 -0
- package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
- package/dist-sdk/src/entities/element/to-tf.js +8 -14
- package/dist-sdk/src/entities/field/build.d.ts +3 -2
- package/dist-sdk/src/entities/field/calc.d.ts +7 -7
- package/dist-sdk/src/entities/field/from-tf.d.ts +4 -4
- package/dist-sdk/src/entities/field/from-tf.js +205 -48
- package/dist-sdk/src/entities/field/module.js +1 -0
- package/dist-sdk/src/entities/field/options.js +6 -1
- package/dist-sdk/src/entities/field/to-tf.d.ts +4 -4
- package/dist-sdk/src/entities/field/to-tf.js +7 -1
- 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/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/service-account/from-tf.js +3 -3
- 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/filters/ast.d.ts +15 -1
- package/dist-sdk/src/entities/shared/filters/ast.js +2 -0
- package/dist-sdk/src/entities/shared/filters/index.d.ts +5 -0
- package/dist-sdk/src/entities/shared/filters/index.js +5 -0
- package/dist-sdk/src/entities/shared/filters/print.js +7 -2
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +5 -0
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +42 -7
- package/dist-sdk/src/entities/shared/filters/types.d.ts +8 -3
- 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 +10 -0
- package/dist-sdk/src/entities/shared/types/field-types.js +4 -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 +12 -5
- package/dist-sdk/src/entities/skill/from-tf.js +4 -2
- package/dist-sdk/src/entities/skill/module.js +2 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.js +41 -8
- package/dist-sdk/src/entities/skill-tool/module.js +3 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +0 -6
- package/dist-sdk/src/entities/skill-tool/to-tf.js +22 -9
- 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/from-tf.js +9 -1
- package/dist-sdk/src/entities/view/to-tf.d.ts +6 -7
- package/dist-sdk/src/entities/view/to-tf.js +19 -8
- 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/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 +7 -6
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +133 -9
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +1 -0
- package/dist-sdk/src/graph/types.d.ts +29 -3
- package/package.json +7 -3
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { EntityTfError } from "../../engine/entity.js";
|
|
9
9
|
import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
|
|
10
|
-
import { dataRefLabel, optionalString, resourceRefLabel } from "../../engine/pull/context.js";
|
|
10
|
+
import { dataRefLabel, optionalString, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
|
|
11
11
|
import { bareChildResourceLabel, isTfExpr, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
12
12
|
import { filterFromTf as deserializeFilterFromTf } from "../shared/filters/tf-codec.js";
|
|
13
13
|
import { __pulledExpression } from "../app/deserializer/pulled-expression.js";
|
|
@@ -53,7 +53,7 @@ function resolveRelatedId(v, ctx) {
|
|
|
53
53
|
* element the same way it already does for agent-tool/automation targets —
|
|
54
54
|
* then stays unresolvable this pull, same as before.
|
|
55
55
|
*/
|
|
56
|
-
function resolveRelatedObject(v, ctx) {
|
|
56
|
+
function resolveRelatedObject(v, ctx, namespaceFallback = false) {
|
|
57
57
|
const raw = resolveRelatedId(v, ctx);
|
|
58
58
|
if (raw !== undefined)
|
|
59
59
|
return raw;
|
|
@@ -66,10 +66,16 @@ function resolveRelatedObject(v, ctx) {
|
|
|
66
66
|
const refName = namespace !== undefined ? ctx.foreignAppRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignAppRefNames?.get(name) : undefined;
|
|
67
67
|
if (refName !== undefined)
|
|
68
68
|
return { __kind: "app", refName, name: name ?? refName, ...(namespace !== undefined ? { namespace } : {}) };
|
|
69
|
-
if (name
|
|
69
|
+
if (name !== undefined)
|
|
70
|
+
ctx.unresolvedForeignRefs?.apps.add(name);
|
|
71
|
+
// #1440: a data lookup that carries a namespace still names the target
|
|
72
|
+
// exactly. Its stream label is the sanitized namespace, so degrade to the
|
|
73
|
+
// namespace-derived ref (as dataAspectRefName does) instead of dropping
|
|
74
|
+
// dynamic_config; --with-dependencies still records the target above.
|
|
75
|
+
if (!namespaceFallback || namespace === undefined)
|
|
70
76
|
return undefined;
|
|
71
|
-
|
|
72
|
-
return
|
|
77
|
+
const derived = tfLabelToTsLabel(sanitizeName(namespace));
|
|
78
|
+
return { __kind: "app", refName: derived, name: name ?? derived, namespace };
|
|
73
79
|
}
|
|
74
80
|
if (v.type === "elementum_element") {
|
|
75
81
|
const attrs = ctx.dataAttrs?.("elementum_element", v.label);
|
|
@@ -78,10 +84,16 @@ function resolveRelatedObject(v, ctx) {
|
|
|
78
84
|
const refName = namespace !== undefined ? ctx.foreignElementRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignElementRefNames?.get(name) : undefined;
|
|
79
85
|
if (refName !== undefined)
|
|
80
86
|
return { __kind: "element", refName, name: name ?? refName, ...(namespace !== undefined ? { namespace } : {}) };
|
|
81
|
-
if (name
|
|
87
|
+
if (name !== undefined)
|
|
88
|
+
ctx.unresolvedForeignRefs?.elements.add(name);
|
|
89
|
+
// #1440: a data lookup that carries a namespace still names the target
|
|
90
|
+
// exactly. Its stream label is the sanitized namespace, so degrade to the
|
|
91
|
+
// namespace-derived ref (as dataAspectRefName does) instead of dropping
|
|
92
|
+
// dynamic_config; --with-dependencies still records the target above.
|
|
93
|
+
if (!namespaceFallback || namespace === undefined)
|
|
82
94
|
return undefined;
|
|
83
|
-
|
|
84
|
-
return
|
|
95
|
+
const derived = tfLabelToTsLabel(sanitizeName(namespace));
|
|
96
|
+
return { __kind: "element", refName: derived, name: name ?? derived, namespace };
|
|
85
97
|
}
|
|
86
98
|
if (v.type === "elementum_task") {
|
|
87
99
|
const attrs = ctx.dataAttrs?.("elementum_task", v.label);
|
|
@@ -93,6 +105,74 @@ function resolveRelatedObject(v, ctx) {
|
|
|
93
105
|
}
|
|
94
106
|
return undefined;
|
|
95
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* The identity a self-sourced dynamic Dropdown authors for its own owner:
|
|
110
|
+
* the clone's `ctx.selfAspectRef`, else (pull, edk#1493) the owner itself,
|
|
111
|
+
* named from its own resource block. Pull used to resolve these refs through
|
|
112
|
+
* import ids and print raw `<appId>:<fieldId>` fallbacks, which drift on the
|
|
113
|
+
* next plan and count as coverage gaps.
|
|
114
|
+
*/
|
|
115
|
+
function selfIdentity(owner, ctx) {
|
|
116
|
+
if (ctx.selfAspectRef !== undefined)
|
|
117
|
+
return ctx.selfAspectRef;
|
|
118
|
+
if (owner.refName === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
const kind = owner.type === "elementum_app" ? "app" : owner.type === "elementum_element" ? "element" : owner.type === "elementum_task" ? "task" : undefined;
|
|
121
|
+
if (kind === undefined)
|
|
122
|
+
return undefined;
|
|
123
|
+
const attrs = ctx.resourceByAddress?.(`${owner.type}.${owner.label}`)?.attrs;
|
|
124
|
+
const name = typeof attrs?.["name"] === "string" ? attrs["name"] : undefined;
|
|
125
|
+
if (name === undefined)
|
|
126
|
+
return undefined;
|
|
127
|
+
const namespace = typeof attrs?.["namespace"] === "string" ? attrs["namespace"] : undefined;
|
|
128
|
+
return { __kind: kind, refName: owner.refName, name, ...(namespace !== undefined ? { namespace } : {}) };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A reference to the owner itself (`elementum_app.<owner>.id`) that no import
|
|
132
|
+
* id resolves, authored as `ctx.selfAspectRef` (clone, edk#1437).
|
|
133
|
+
*/
|
|
134
|
+
function selfRelatedObject(v, owner, ctx) {
|
|
135
|
+
const self = selfIdentity(owner, ctx);
|
|
136
|
+
if (self === undefined || v === undefined || !isTfExpr(v) || v.$expr !== "resource-attr")
|
|
137
|
+
return undefined;
|
|
138
|
+
if (v.type !== owner.type || v.label !== owner.label || v.path.join(".") !== "id")
|
|
139
|
+
return undefined;
|
|
140
|
+
return { __kind: self.__kind, refName: self.refName, name: self.name, ...(self.namespace !== undefined ? { namespace: self.namespace } : {}) };
|
|
141
|
+
}
|
|
142
|
+
/** A field of the owner that no import id resolves, as `ctx.selfAspectRef`'s catalog field (edk#1437). */
|
|
143
|
+
function selfRelatedField(v, owner, ctx) {
|
|
144
|
+
const self = selfIdentity(owner, ctx);
|
|
145
|
+
if (self === undefined || v === undefined)
|
|
146
|
+
return undefined;
|
|
147
|
+
const fieldKey = fieldKeyFromTfRef(v, owner.label, owner.scope ?? "app");
|
|
148
|
+
if (fieldKey === undefined || !isTfExpr(v) || v.$expr !== "resource-attr")
|
|
149
|
+
return undefined;
|
|
150
|
+
// A typed fieldRef, not catalog.<self>.fields.<key>: the app file cannot
|
|
151
|
+
// import its own catalog entry.
|
|
152
|
+
const fieldType = SUB_TYPE_BY_RESOURCE.get(v.type)?.authoringType;
|
|
153
|
+
// The field's real display name, from its own resource block; without it
|
|
154
|
+
// the printer falls back to the bag key ("reason" for "Reason").
|
|
155
|
+
const fieldName = ctx.resourceByAddress?.(`${v.type}.${v.label}`)?.attrs?.["name"];
|
|
156
|
+
return {
|
|
157
|
+
...(typeof fieldName === "string" ? { fieldName } : {}),
|
|
158
|
+
ownerRefName: self.refName,
|
|
159
|
+
ownerKind: self.__kind,
|
|
160
|
+
ownerName: self.name,
|
|
161
|
+
...(self.namespace !== undefined ? { ownerNamespace: self.namespace } : {}),
|
|
162
|
+
fieldKey,
|
|
163
|
+
...(fieldType !== undefined ? { fieldType } : {}),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* `resolveRelatedField`, else the owner's own field as `ctx.selfAspectRef`'s
|
|
168
|
+
* (clone of a self-sourced Dropdown, edk#1481). Used wherever a dynamic
|
|
169
|
+
* config names a field of its source, which for a self-sourced Dropdown is
|
|
170
|
+
* the owner: the label field, filter fields, sort orders and parent mappings.
|
|
171
|
+
*/
|
|
172
|
+
function resolveRelatedOrSelfField(v, owner, ctx) {
|
|
173
|
+
// Self first: in pull the owner's own fields also have import ids (edk#1493).
|
|
174
|
+
return selfRelatedField(v, owner, ctx) ?? resolveRelatedField(v, ctx);
|
|
175
|
+
}
|
|
96
176
|
function resolveRelatedField(v, ctx) {
|
|
97
177
|
const raw = resolveRelatedId(v, ctx);
|
|
98
178
|
if (raw !== undefined)
|
|
@@ -131,8 +211,8 @@ function resolveRelatedField(v, ctx) {
|
|
|
131
211
|
* ref-only dependency data address resolves to its generated catalog member;
|
|
132
212
|
* a preserved raw id remains an explicit unresolved/unsafe fallback.
|
|
133
213
|
*/
|
|
134
|
-
function dynamicPicklistFilterFieldRef(value, ctx) {
|
|
135
|
-
const resolved =
|
|
214
|
+
function dynamicPicklistFilterFieldRef(value, owner, ctx) {
|
|
215
|
+
const resolved = resolveRelatedOrSelfField(value, owner, ctx);
|
|
136
216
|
if (typeof resolved === "string")
|
|
137
217
|
return { kind: "unresolved", uuid: resolved, hint: "field" };
|
|
138
218
|
if (resolved !== undefined) {
|
|
@@ -161,40 +241,108 @@ function dynamicPicklistRecordFieldRef(value, owner, ctx) {
|
|
|
161
241
|
const fieldKey = fieldKeyFromTfRef(value, owner.label, scope) ?? fieldKeyFromTfValue(value, owner.refName, owner.label, scope, ctx);
|
|
162
242
|
if (fieldKey === undefined)
|
|
163
243
|
throw new EntityTfError("record_field filter value field is not a field on the owning record");
|
|
164
|
-
|
|
244
|
+
// A clone authors the record's fields under the clone's refName (edk#1481).
|
|
245
|
+
return { kind: "field", appHandle: ctx.selfAspectRef?.refName ?? owner.refName, fieldKey };
|
|
165
246
|
}
|
|
166
247
|
/**
|
|
167
248
|
* `dynamic_config` → `AppField.config` (picklist/multiPicklist only). Mirrors
|
|
168
249
|
* `related_object_id`/`related_label_field_id` resolution exactly (both are
|
|
169
250
|
* required by the wire schema, so either failing to resolve drops the whole
|
|
170
|
-
* config — same convention as RELATION's own required pair).
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
251
|
+
* config — same convention as RELATION's own required pair).
|
|
252
|
+
*
|
|
253
|
+
* `filter`, `sort` and `parent_field_id` are different: the provider's update
|
|
254
|
+
* mutation cannot clear them, so removing one from an existing dynamic
|
|
255
|
+
* picklist (Dropdown or multi-select) forces replacement
|
|
256
|
+
* (picklist_dynamic_config.go). A part pull cannot reconstruct is an
|
|
257
|
+
* authoring blocker ({@link blockReplaceForcingDrop}): the part is left out of
|
|
258
|
+
* the extract, and a caller that would author this field refuses rather than
|
|
259
|
+
* print source whose first plan deletes and recreates it.
|
|
260
|
+
* `auto_relate` and `values_render_type` update in place, so those still
|
|
261
|
+
* degrade with a diagnostic. `parent_mappings` updates in place too, but the
|
|
262
|
+
* platform will not clear them ({@link blockUnclearableParentMappings}).
|
|
174
263
|
*/
|
|
175
|
-
function
|
|
264
|
+
function blockReplaceForcingDrop(ctx, site, attr, reason) {
|
|
265
|
+
reportAuthoringBlocker(ctx, {
|
|
266
|
+
address: site.address,
|
|
267
|
+
description: `${site.where}: dynamic_config.${attr} ${reason}. Removing dynamic_config.${attr} forces replacement of this field ` +
|
|
268
|
+
`(the platform cannot clear it in place), so dropping it would make the next plan delete and recreate the field.`,
|
|
269
|
+
remedy: "Change the filter, sort or parent field of these fields' dynamic options in the Elementum UI to a form the EDK can represent, then pull again.",
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Without its dynamic_config a Dropdown prints as `config: { static: { values: [] } }`,
|
|
274
|
+
* which plan rejects ("options or dynamic_config is required") and which would
|
|
275
|
+
* turn a live dynamic Dropdown static if "fixed" by hand. Every pull-style
|
|
276
|
+
* caller (pull, clone, post-apply refresh) must refuse or skip rather than
|
|
277
|
+
* write it (#1405, #1406).
|
|
278
|
+
*/
|
|
279
|
+
function blockDynamicConfigDrop(ctx, site, reason, labelOnly = false) {
|
|
280
|
+
// When only the label field is unresolved the source app/element itself
|
|
281
|
+
// resolved (it is in the workspace or was just pulled), so pulling
|
|
282
|
+
// dependencies again cannot help: the label metadata simply wasn't exported.
|
|
283
|
+
reportAuthoringBlocker(ctx, {
|
|
284
|
+
address: site.address,
|
|
285
|
+
description: `${site.where}: ${reason}. Dropping dynamic_config would author an empty static Dropdown, ` +
|
|
286
|
+
"which plan rejects and which would replace the live dynamic options.",
|
|
287
|
+
remedy: labelOnly
|
|
288
|
+
? "The source app/element resolves, but its label field metadata wasn't exported, so retrying with --with-dependencies won't help. " +
|
|
289
|
+
"Hand-author the Dropdown's dynamic config (source and label field) in the app file, or see edk#1437 (clone/pull preserving dynamic Dropdown config)."
|
|
290
|
+
: "Make the Dropdown's source app/element and label field resolvable (pull them into this workspace, e.g. with --with-dependencies), then retry.",
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* `parent_mappings` can be changed in place, but the platform keeps existing
|
|
295
|
+
* mappings when the update clears them, so the provider reports
|
|
296
|
+
* "inconsistent result after apply" and the plan never converges (#1404).
|
|
297
|
+
* Dropping one in pull therefore makes source that cannot be applied: block.
|
|
298
|
+
*/
|
|
299
|
+
function blockUnclearableParentMappings(ctx, site) {
|
|
300
|
+
reportAuthoringBlocker(ctx, {
|
|
301
|
+
address: site.address,
|
|
302
|
+
description: `${site.where}: dynamic_config parent mapping field IDs could not be reconstructed. The platform keeps parent mappings ` +
|
|
303
|
+
`when an update removes them, so dropping them would make every apply fail with "inconsistent result after apply".`,
|
|
304
|
+
remedy: "Pull the apps that own the mapped parent/source fields into this workspace (e.g. with --with-dependencies), or change the Dropdown's parent mappings in the Elementum UI, then pull again.",
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* A field pull cannot extract at all. Leaving it out of the printed source
|
|
309
|
+
* would let the next plan destroy a live, possibly adopted field, so the pull
|
|
310
|
+
* refuses instead (edk#1484). The address also goes to `skipped` so a caller
|
|
311
|
+
* that does not author this field keeps it out of adoption.
|
|
312
|
+
*/
|
|
313
|
+
function blockUnextractableField(ctx, site, reason, remedy) {
|
|
314
|
+
ctx.skipped.push(site.address);
|
|
315
|
+
reportAuthoringBlocker(ctx, {
|
|
316
|
+
address: site.address,
|
|
317
|
+
description: `${site.where}: ${reason}, so pull cannot write this field and leaving it out would let the next plan destroy it.`,
|
|
318
|
+
remedy,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
const MALFORMED_FIELD_REMEDY = "The export carries a field the EDK cannot reconstruct. Update the Elementum CLI and pull again; if it persists, report the field's type to the EDK maintainers.";
|
|
322
|
+
function dynamicConfigFromTf(value, owner, ctx, site) {
|
|
323
|
+
const where = site.where;
|
|
176
324
|
if (value === undefined)
|
|
177
325
|
return undefined;
|
|
178
326
|
if (typeof value !== "object" || value === null || isTfExpr(value) || Array.isArray(value)) {
|
|
179
|
-
ctx
|
|
327
|
+
blockDynamicConfigDrop(ctx, site, "dynamic_config has an unexpected shape");
|
|
180
328
|
return undefined;
|
|
181
329
|
}
|
|
182
330
|
const attrs = value;
|
|
183
|
-
const relatedAspectId = resolveRelatedObject(attrs["related_aspect_id"], ctx);
|
|
184
|
-
const relatedLabelFieldId =
|
|
331
|
+
const relatedAspectId = selfRelatedObject(attrs["related_aspect_id"], owner, ctx) ?? resolveRelatedObject(attrs["related_aspect_id"], ctx, /* namespaceFallback (#1440) */ true);
|
|
332
|
+
const relatedLabelFieldId = resolveRelatedOrSelfField(attrs["related_label_field_id"], owner, ctx);
|
|
185
333
|
if (relatedAspectId === undefined || relatedLabelFieldId === undefined) {
|
|
186
334
|
const missing = [
|
|
187
335
|
relatedAspectId === undefined && "related_aspect_id",
|
|
188
336
|
relatedLabelFieldId === undefined && "related_label_field_id",
|
|
189
337
|
].filter((v) => v !== false);
|
|
190
|
-
ctx
|
|
338
|
+
blockDynamicConfigDrop(ctx, site, `dynamic_config.${missing.join(" and ")} does not resolve to a catalog reference or raw platform id`, relatedAspectId !== undefined);
|
|
191
339
|
return undefined;
|
|
192
340
|
}
|
|
193
341
|
let parentFieldId;
|
|
194
342
|
if (attrs["parent_field_id"] !== undefined) {
|
|
195
343
|
parentFieldId = fieldKeyFromTfRef(attrs["parent_field_id"], owner.label, owner.scope ?? "app");
|
|
196
344
|
if (parentFieldId === undefined) {
|
|
197
|
-
ctx
|
|
345
|
+
blockReplaceForcingDrop(ctx, site, "parent_field_id", "could not be resolved to a same-aspect field");
|
|
198
346
|
}
|
|
199
347
|
}
|
|
200
348
|
const autoRelate = typeof attrs["auto_relate"] === "boolean" ? attrs["auto_relate"] : undefined;
|
|
@@ -203,15 +351,16 @@ function dynamicConfigFromTf(value, owner, ctx, where) {
|
|
|
203
351
|
if (attrs["filter"] !== undefined) {
|
|
204
352
|
try {
|
|
205
353
|
filter = deserializeFilterFromTf(attrs["filter"], {
|
|
206
|
-
field: (v) => dynamicPicklistFilterFieldRef(v, ctx),
|
|
354
|
+
field: (v) => dynamicPicklistFilterFieldRef(v, owner, ctx),
|
|
207
355
|
recordField: (v) => dynamicPicklistRecordFieldRef(v, owner, ctx),
|
|
356
|
+
recordFieldOwner: (v) => resourceRefLabel(v, owner.type) === owner.label,
|
|
208
357
|
reference: () => {
|
|
209
358
|
throw new EntityTfError("dynamic picklist filter does not support value references");
|
|
210
359
|
},
|
|
211
360
|
});
|
|
212
361
|
}
|
|
213
362
|
catch (e) {
|
|
214
|
-
ctx
|
|
363
|
+
blockReplaceForcingDrop(ctx, site, "filter", e instanceof Error ? e.message : String(e));
|
|
215
364
|
}
|
|
216
365
|
}
|
|
217
366
|
let sort;
|
|
@@ -239,21 +388,19 @@ function dynamicConfigFromTf(value, owner, ctx, where) {
|
|
|
239
388
|
unresolvedField = true;
|
|
240
389
|
return rawOrder;
|
|
241
390
|
}
|
|
242
|
-
const resolved =
|
|
391
|
+
const resolved = resolveRelatedOrSelfField(field, owner, ctx);
|
|
243
392
|
if (resolved === undefined)
|
|
244
393
|
unresolvedField = true;
|
|
245
394
|
return resolved === undefined ? rawOrder : { ...order, field: resolved };
|
|
246
395
|
});
|
|
247
|
-
if (unresolvedField)
|
|
248
|
-
ctx
|
|
249
|
-
|
|
250
|
-
else {
|
|
396
|
+
if (unresolvedField)
|
|
397
|
+
blockReplaceForcingDrop(ctx, site, "sort", "has an unresolved order field");
|
|
398
|
+
else
|
|
251
399
|
sort = { ...rawSort, orders };
|
|
252
|
-
}
|
|
253
400
|
}
|
|
254
401
|
}
|
|
255
402
|
else {
|
|
256
|
-
ctx
|
|
403
|
+
blockReplaceForcingDrop(ctx, site, "sort", "is not a jsonencode(...) object");
|
|
257
404
|
}
|
|
258
405
|
}
|
|
259
406
|
let parentMappings;
|
|
@@ -270,15 +417,20 @@ function dynamicConfigFromTf(value, owner, ctx, where) {
|
|
|
270
417
|
continue;
|
|
271
418
|
}
|
|
272
419
|
const mapping = rawMapping;
|
|
273
|
-
|
|
274
|
-
|
|
420
|
+
// Mapped fields usually live on another app (the parent's and this
|
|
421
|
+
// Dropdown's sources), so resolve them like related_label_field_id:
|
|
422
|
+
// raw/imported id, else the foreign data.elementum_field identity (#1404),
|
|
423
|
+
// else (clone) the owner's own field (edk#1481).
|
|
424
|
+
const parentAspectFieldId = resolveRelatedOrSelfField(mapping["parent_aspect_field_id"], owner, ctx);
|
|
425
|
+
const relatedAspectFieldId = resolveRelatedOrSelfField(mapping["related_aspect_field_id"], owner, ctx);
|
|
275
426
|
if (parentAspectFieldId === undefined || relatedAspectFieldId === undefined) {
|
|
276
|
-
ctx
|
|
277
|
-
|
|
427
|
+
blockUnclearableParentMappings(ctx, site);
|
|
428
|
+
parentMappings = undefined;
|
|
429
|
+
break;
|
|
278
430
|
}
|
|
279
431
|
parentMappings.push({ parentAspectFieldId, relatedAspectFieldId });
|
|
280
432
|
}
|
|
281
|
-
if (parentMappings.length === 0)
|
|
433
|
+
if (parentMappings !== undefined && parentMappings.length === 0)
|
|
282
434
|
parentMappings = undefined;
|
|
283
435
|
}
|
|
284
436
|
}
|
|
@@ -349,14 +501,15 @@ function staticParentLinkageFromTf(value, optionsValue, owner, ctx, where) {
|
|
|
349
501
|
*/
|
|
350
502
|
export function fieldFromTf(block, owner, ctx) {
|
|
351
503
|
const subType = SUB_TYPE_BY_RESOURCE.get(block.type ?? "");
|
|
352
|
-
if (subType === undefined) {
|
|
353
|
-
ctx.diagnostics.push(`resource "${block.type}" is not a known field resource; skipped`);
|
|
354
|
-
return undefined;
|
|
355
|
-
}
|
|
356
504
|
const fieldLabel = block.label;
|
|
357
505
|
if (fieldLabel === undefined || fieldLabel === "") {
|
|
358
506
|
throw new EntityTfError(`${block.type} block is missing its label`);
|
|
359
507
|
}
|
|
508
|
+
if (subType === undefined) {
|
|
509
|
+
const address = `${block.type}.${fieldLabel}`;
|
|
510
|
+
blockUnextractableField(ctx, { address, where: `field (${address})` }, `resource "${block.type}" is not a known field resource`, MALFORMED_FIELD_REMEDY);
|
|
511
|
+
return undefined;
|
|
512
|
+
}
|
|
360
513
|
if (subType.implemented !== true) {
|
|
361
514
|
// Declared but not yet round-tripped - see FIELD_SUB_TYPES for the
|
|
362
515
|
// current list of not-yet-implemented sub-types, if any.
|
|
@@ -385,7 +538,7 @@ export function fieldFromTf(block, owner, ctx) {
|
|
|
385
538
|
const options = subType.hasOptions === true && attrs["dynamic_config"] === undefined
|
|
386
539
|
? optionsFromTf(attrs["options"], `${where} options`, ctx)
|
|
387
540
|
: undefined;
|
|
388
|
-
const config = subType.hasOptions === true ? dynamicConfigFromTf(attrs["dynamic_config"], owner, ctx, where) : undefined;
|
|
541
|
+
const config = subType.hasOptions === true ? dynamicConfigFromTf(attrs["dynamic_config"], owner, ctx, { address: `${block.type}.${fieldLabel}`, where }) : undefined;
|
|
389
542
|
const parentLinkage = subType.hasOptions === true && attrs["dynamic_config"] === undefined
|
|
390
543
|
? staticParentLinkageFromTf(attrs["static_config"], attrs["options"], owner, ctx, where)
|
|
391
544
|
: undefined;
|
|
@@ -442,8 +595,8 @@ export function fieldFromTf(block, owner, ctx) {
|
|
|
442
595
|
// field ids are read-only outputs of that resource, never their own
|
|
443
596
|
// resource address). Both properties are required by RelationFieldOptions,
|
|
444
597
|
// so printing relationField(...) with either missing would be invalid
|
|
445
|
-
// TypeScript (item 117)
|
|
446
|
-
//
|
|
598
|
+
// TypeScript (item 117), and leaving the field out would let the next plan
|
|
599
|
+
// destroy it - refuse the pull when either side can't be resolved (#1484).
|
|
447
600
|
let relatedObject;
|
|
448
601
|
let relatedLabelField;
|
|
449
602
|
let autoRelate;
|
|
@@ -457,8 +610,14 @@ export function fieldFromTf(block, owner, ctx) {
|
|
|
457
610
|
relatedObject === undefined && "related_object_id",
|
|
458
611
|
relatedLabelField === undefined && "related_label_field_id",
|
|
459
612
|
].filter((v) => v !== false);
|
|
460
|
-
|
|
461
|
-
|
|
613
|
+
const foreignTarget = attrs["related_object_id"];
|
|
614
|
+
const onlyForeignTargetMissing = relatedLabelField !== undefined &&
|
|
615
|
+
isTfExpr(foreignTarget) &&
|
|
616
|
+
foreignTarget.$expr === "data-attr" &&
|
|
617
|
+
(foreignTarget.type === "elementum_app" || foreignTarget.type === "elementum_element");
|
|
618
|
+
blockUnextractableField(ctx, { address: `${block.type}.${fieldLabel}`, where }, `${missing.join(" and ")} does not resolve to a raw platform id or a pulled app/element, and a RELATION field needs both relatedObject and relatedLabelField`, onlyForeignTargetMissing
|
|
619
|
+
? "Pull the related apps and elements into this workspace (retry with --with-dependencies), then pull again."
|
|
620
|
+
: "The export names these relation fields' related object or label field in a form pull cannot resolve, and --with-dependencies cannot resolve it either. Change the relation field in the Elementum UI, then pull again.");
|
|
462
621
|
return undefined;
|
|
463
622
|
}
|
|
464
623
|
}
|
|
@@ -518,14 +677,12 @@ export function fieldFromTf(block, owner, ctx) {
|
|
|
518
677
|
const scope = owner.scope ?? "app";
|
|
519
678
|
const calculation = subType.typeKey === "calculated" ? optionalString(attrs, "calculation", where, ctx) : undefined;
|
|
520
679
|
if (subType.typeKey === "calculated" && calculation === undefined) {
|
|
521
|
-
ctx
|
|
522
|
-
ctx.diagnostics.push(`${where}: calculation is required; skipped`);
|
|
680
|
+
blockUnextractableField(ctx, { address: `${block.type}.${fieldLabel}`, where }, "calculation is missing", MALFORMED_FIELD_REMEDY);
|
|
523
681
|
return undefined;
|
|
524
682
|
}
|
|
525
683
|
const calculationType = subType.typeKey === "calculated" ? attrs["calculation_type"] : undefined;
|
|
526
684
|
if (subType.typeKey === "calculated" && !isCalculationResultType(calculationType)) {
|
|
527
|
-
ctx
|
|
528
|
-
ctx.diagnostics.push(`${where}: calculation_type is missing or unsupported; skipped rather than guessing the typed result`);
|
|
685
|
+
blockUnextractableField(ctx, { address: `${block.type}.${fieldLabel}`, where }, `calculation_type is missing or unsupported (${JSON.stringify(calculationType ?? null)}), and pull will not guess the typed result`, MALFORMED_FIELD_REMEDY);
|
|
529
686
|
return undefined;
|
|
530
687
|
}
|
|
531
688
|
let calculationInclude;
|
|
@@ -73,7 +73,12 @@ export function optionsFromTf(v, where, ctx) {
|
|
|
73
73
|
return undefined;
|
|
74
74
|
const out = {};
|
|
75
75
|
for (const { key, item } of withUniqueKeys(parsed, (p) => p.label, "option")) {
|
|
76
|
-
|
|
76
|
+
// Digit-only keys are JS array indices: Object.values reorders them and
|
|
77
|
+
// pull prints the wrong option order (edk#1449). A leading underscore is
|
|
78
|
+
// outside camelCase's key space (it strips non-alphanumerics) and is not
|
|
79
|
+
// an integer index, so the prefix cannot collide with another option.
|
|
80
|
+
const bagKey = /^(0|[1-9]\d*)$/.test(key) ? `_${key}` : key;
|
|
81
|
+
out[bagKey] = {
|
|
77
82
|
id: "",
|
|
78
83
|
label: item.label,
|
|
79
84
|
...(item.color !== undefined && { color: item.color }),
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* non-canonical bag key: it has no well-defined terraform address.
|
|
11
11
|
*/
|
|
12
12
|
import { type OrgRefLookup, type WorkspaceAspect } from "../../engine/build/context.js";
|
|
13
|
-
import { type
|
|
13
|
+
import { type FieldOwnerScope, type TfBlock, type TfExpr, type TfValue } from "../../engine/tf/index.js";
|
|
14
14
|
import { type PicklistValueWire } from "./options.js";
|
|
15
15
|
/**
|
|
16
16
|
* The authored fields known to belong to an app/element. Maps produced by a
|
|
@@ -122,8 +122,8 @@ export interface FieldToTfOptions {
|
|
|
122
122
|
readonly ownerTfLabel: string;
|
|
123
123
|
/** The owning stream root's refName — needed to detect a self-targeting RELATION field. */
|
|
124
124
|
readonly appRefName: string;
|
|
125
|
-
/** App children use `apps_<ns>_
|
|
126
|
-
readonly scope?:
|
|
125
|
+
/** App children use `apps_<ns>_<ns>_`, element children `elements_<ns>_<ns>_`, task children `tasks_<ns>_<ns>_` (edk#1464). */
|
|
126
|
+
readonly scope?: FieldOwnerScope;
|
|
127
127
|
/** The owner's id reference, e.g. `elementum_app.<ns>.id` — computed by the owner's to-tf. */
|
|
128
128
|
readonly objectId: TfValue;
|
|
129
129
|
/** Degradations land here — reported by the caller, never silent. */
|
|
@@ -156,5 +156,5 @@ export interface FieldToTfResult {
|
|
|
156
156
|
*/
|
|
157
157
|
export declare function claimFieldDisplayName(seen: Map<string, string>, field: FieldToTfResult): void;
|
|
158
158
|
export declare function fieldToTf(typeKey: string, inner: FieldInnerWire, opts: FieldToTfOptions): FieldToTfResult | undefined;
|
|
159
|
-
export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?:
|
|
159
|
+
export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: FieldOwnerScope, fieldOwnership?: FieldOwnership): TfExpr | undefined;
|
|
160
160
|
export {};
|
|
@@ -194,7 +194,11 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
|
|
|
194
194
|
opts.diagnostics.push(`${where}: ${attrName} token "${refName}" belongs to "${token.parent}", not the resolved target "${object.refName}"; dropped`);
|
|
195
195
|
return undefined;
|
|
196
196
|
}
|
|
197
|
-
|
|
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) {
|
|
198
202
|
// A field belongs to an app or element; a table exposes columns, not fields.
|
|
199
203
|
// Guard rather than widen fieldRefToTfValue's scope parameter.
|
|
200
204
|
if (object.target.kind === "table") {
|
|
@@ -348,6 +352,7 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
|
|
|
348
352
|
}
|
|
349
353
|
return value;
|
|
350
354
|
},
|
|
355
|
+
recordFieldOwner: () => opts.objectId,
|
|
351
356
|
field: (token) => {
|
|
352
357
|
const value = resolveFieldOnObject(token, resolvedObject, opts_, where, "filter field");
|
|
353
358
|
if (value === undefined) {
|
|
@@ -402,6 +407,7 @@ function resolveDynamicMappingFieldOwner(token, opts, where) {
|
|
|
402
407
|
__kind: token.parentKind,
|
|
403
408
|
refName: token.parent,
|
|
404
409
|
name: token.parentName ?? token.parent,
|
|
410
|
+
...(token.parentNamespace !== undefined ? { namespace: token.parentNamespace } : {}),
|
|
405
411
|
}, opts, where);
|
|
406
412
|
}
|
|
407
413
|
function resolveDynamicPicklistSort(sort, relatedObject, opts, where) {
|
|
@@ -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
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
|
|
2
|
-
import { scopedLabelToBagKey
|
|
1
|
+
import { dataRefLabel, groupCatalogKey, resourceRefLabel } from "../../engine/pull/context.js";
|
|
2
|
+
import { scopedLabelToBagKey } from "../../engine/tf/index.js";
|
|
3
3
|
import { ROLE_RESOURCE_TYPE } from "../org/role.js";
|
|
4
4
|
const KNOWN = new Set(["id", "object_id", "name", "description", "auto_share", "user_ids", "group_ids", "service_account_ids", "permissions", "managed", "tags"]);
|
|
5
5
|
function strings(value, where, ctx) {
|
|
@@ -23,7 +23,7 @@ function principal(value, type, where, ctx) {
|
|
|
23
23
|
}
|
|
24
24
|
return { __kind: "user", email: name.trim() };
|
|
25
25
|
}
|
|
26
|
-
return { __kind: "group", refName:
|
|
26
|
+
return { __kind: "group", refName: groupCatalogKey(ctx, label, name), name };
|
|
27
27
|
}
|
|
28
28
|
ctx.diagnostics.push(`${where}: data.${type}.${label} has no lookup value; dropped`);
|
|
29
29
|
return undefined;
|
|
@@ -2,6 +2,7 @@ import type { OrgRefLookup } from "../../engine/build/context.js";
|
|
|
2
2
|
import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
|
|
3
3
|
import type { AppRole } from "./build.js";
|
|
4
4
|
import type { AppServiceAccount } from "../service-account/build.js";
|
|
5
|
+
import type { ServiceAccountOwningApp } from "../service-account/workspace-owner.js";
|
|
5
6
|
export declare function rolesToTf(roles: Readonly<Record<string, AppRole>> | undefined, opts: {
|
|
6
7
|
readonly ownerRefName: string;
|
|
7
8
|
readonly ownerTfLabel: string;
|
|
@@ -10,4 +11,5 @@ export declare function rolesToTf(roles: Readonly<Record<string, AppRole>> | und
|
|
|
10
11
|
readonly serviceAccounts?: Readonly<Record<string, AppServiceAccount>>;
|
|
11
12
|
readonly orgRefs: OrgRefLookup;
|
|
12
13
|
readonly diagnostics: string[];
|
|
14
|
+
readonly resolveServiceAccountApp?: (appRefName: string) => ServiceAccountOwningApp | undefined;
|
|
13
15
|
}): TfBlock[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expr, sanitizeName, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
2
2
|
import { ROLE_RESOURCE_TYPE } from "../org/role.js";
|
|
3
3
|
import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
|
|
4
|
+
import { serviceAccountRefToTf } from "../service-account/to-tf.js";
|
|
4
5
|
function principals(values, type, where, orgRefs, diagnostics) {
|
|
5
6
|
if (values === undefined || values.length === 0)
|
|
6
7
|
return undefined;
|
|
@@ -41,11 +42,18 @@ export function rolesToTf(roles, opts) {
|
|
|
41
42
|
attrs["group_ids"] = groups;
|
|
42
43
|
if (role.serviceAccounts !== undefined) {
|
|
43
44
|
attrs["service_account_ids"] = role.serviceAccounts.flatMap((account) => {
|
|
44
|
-
if (account.appRefName !== opts.ownerRefName) {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (opts.scope !== "app" || account.appRefName !== opts.ownerRefName) {
|
|
46
|
+
// Another app's account (or any account on an element role, which
|
|
47
|
+
// owns none): resolve it under its OWNING app (#1592).
|
|
48
|
+
const owning = opts.resolveServiceAccountApp?.(account.appRefName);
|
|
49
|
+
if (owning === undefined) {
|
|
50
|
+
opts.diagnostics.push(`roles.${key}.serviceAccounts: ${JSON.stringify(account.name)} belongs to app ${JSON.stringify(account.appRefName)}, which is not in this workspace; dropped`);
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
const value = serviceAccountRefToTf({ __kind: "serviceAccount", appRefName: account.appRefName, name: account.name }, { appRefName: account.appRefName, ...owning, orgRefs: opts.orgRefs }, `roles.${key}.serviceAccounts`, opts.diagnostics);
|
|
54
|
+
return value === undefined ? [] : [value];
|
|
47
55
|
}
|
|
48
|
-
const local = Object.entries(opts.serviceAccounts ?? {}).find(([, candidate]) => `${candidate.firstName} ${candidate.lastName}
|
|
56
|
+
const local = Object.entries(opts.serviceAccounts ?? {}).find(([, candidate]) => `${candidate.firstName} ${candidate.lastName}`.trim() === account.name);
|
|
49
57
|
if (local !== undefined)
|
|
50
58
|
return [expr.resourceAttr(SERVICE_ACCOUNT_RESOURCE_TYPE, scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(local[0]), "app"), ["id"])];
|
|
51
59
|
const label = sanitizeName(account.name);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { unsafePlatformId } from "../../core/platform-id.js";
|
|
2
|
-
import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
|
|
3
|
-
import { scopedLabelToBagKey
|
|
2
|
+
import { dataRefLabel, groupCatalogKey, resourceRefLabel } from "../../engine/pull/context.js";
|
|
3
|
+
import { scopedLabelToBagKey } from "../../engine/tf/index.js";
|
|
4
4
|
import { serviceAccountRoleRef, serviceAccountStatus, } from "./build.js";
|
|
5
5
|
import { SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE, SERVICE_ACCOUNT_RESOURCE_TYPE } from "./module.js";
|
|
6
6
|
import { serviceAccountRoleIdMismatches } from "./role-fidelity.js";
|
|
@@ -18,7 +18,7 @@ function principal(value, type, where, ctx) {
|
|
|
18
18
|
}
|
|
19
19
|
return { __kind: "user", email: name.trim() };
|
|
20
20
|
}
|
|
21
|
-
return { __kind: "group", refName:
|
|
21
|
+
return { __kind: "group", refName: groupCatalogKey(ctx, label, name), name };
|
|
22
22
|
}
|
|
23
23
|
ctx.diagnostics.push(`${where}: data.${type}.${label} has no lookup value; dropped`);
|
|
24
24
|
return undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type WorkspaceAspect } from "../../engine/build/context.js";
|
|
2
|
+
import { type TfValue } from "../../engine/tf/index.js";
|
|
3
|
+
import type { AppServiceAccount } from "./build.js";
|
|
4
|
+
/** The app that owns a service account, as a role or policy on another object resolves it. */
|
|
5
|
+
export interface ServiceAccountOwningApp {
|
|
6
|
+
readonly appTfLabel: string;
|
|
7
|
+
readonly appId: TfValue;
|
|
8
|
+
readonly serviceAccounts?: Readonly<Record<string, AppServiceAccount>>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the workspace app that owns a `serviceAccountRef` named from a
|
|
12
|
+
* different object (another app or an element), so its lookup is scoped to the
|
|
13
|
+
* OWNING app (#1592), not the object that grants it access. A managed account
|
|
14
|
+
* becomes a direct resource ref, so same-apply creation is sequenced.
|
|
15
|
+
*/
|
|
16
|
+
export declare function workspaceServiceAccountAppResolver(workspaceAspects: ReadonlyMap<string, WorkspaceAspect> | undefined): (appRefName: string) => ServiceAccountOwningApp | undefined;
|