@elementumai/edk 0.8.0-preview.11 → 0.8.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 +378 -324
- package/dist-sdk/src/catalog/ai-provider-models.d.ts +30 -0
- package/dist-sdk/src/catalog/ai-provider-models.js +63 -0
- package/dist-sdk/src/catalog/factories.d.ts +56 -3
- package/dist-sdk/src/catalog/factories.js +65 -2
- package/dist-sdk/src/catalog/from-authoring.js +6 -1
- package/dist-sdk/src/catalog/index.d.ts +3 -2
- package/dist-sdk/src/catalog/index.js +3 -2
- package/dist-sdk/src/catalog/org.d.ts +1 -1
- package/dist-sdk/src/catalog/org.js +83 -6
- package/dist-sdk/src/catalog/render.d.ts +13 -1
- package/dist-sdk/src/catalog/render.js +21 -4
- package/dist-sdk/src/catalog/token.js +14 -0
- package/dist-sdk/src/catalog/types.d.ts +60 -3
- package/dist-sdk/src/catalog/types.js +3 -0
- package/dist-sdk/src/core/system-fields.d.ts +2 -0
- package/dist-sdk/src/core/system-fields.js +2 -0
- package/dist-sdk/src/core/types/ai-provider.d.ts +10 -23
- package/dist-sdk/src/core/types/ai-provider.js +1 -25
- package/dist-sdk/src/core/types/app.d.ts +20 -1
- package/dist-sdk/src/engine/build/context.d.ts +18 -0
- package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
- package/dist-sdk/src/engine/build/source-context.js +23 -0
- package/dist-sdk/src/engine/pull/context.d.ts +15 -0
- package/dist-sdk/src/engine/pull/org.d.ts +10 -0
- package/dist-sdk/src/engine/pull/org.js +34 -4
- 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 +45 -0
- package/dist-sdk/src/engine/tf/labels.js +71 -0
- package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
- package/dist-sdk/src/entities/access-policy/build.js +7 -0
- package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
- package/dist-sdk/src/entities/access-policy/filter.js +83 -0
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +48 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +189 -0
- package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
- package/dist-sdk/src/entities/access-policy/module.js +17 -0
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +36 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +149 -0
- package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
- package/dist-sdk/src/entities/access-policy/types.js +10 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +38 -3
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +199 -32
- package/dist-sdk/src/entities/agent/from-tf.d.ts +18 -3
- package/dist-sdk/src/entities/agent/from-tf.js +135 -15
- package/dist-sdk/src/entities/agent/index.d.ts +1 -1
- package/dist-sdk/src/entities/agent/module.js +8 -2
- package/dist-sdk/src/entities/agent/to-tf.js +62 -10
- package/dist-sdk/src/entities/agent/tools.d.ts +88 -9
- package/dist-sdk/src/entities/agent/tools.js +46 -7
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +51 -4
- package/dist-sdk/src/entities/agent-tool/from-tf.js +131 -35
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +4 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +103 -17
- package/dist-sdk/src/entities/agent-tool/types.d.ts +5 -4
- package/dist-sdk/src/entities/agent-tool/types.js +38 -6
- package/dist-sdk/src/entities/app/build.d.ts +63 -13
- package/dist-sdk/src/entities/app/build.js +48 -1
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +3 -0
- package/dist-sdk/src/entities/app/from-tf.d.ts +1 -1
- package/dist-sdk/src/entities/app/from-tf.js +32 -15
- package/dist-sdk/src/entities/app/index.d.ts +4 -1
- package/dist-sdk/src/entities/app/index.js +2 -1
- package/dist-sdk/src/entities/app/module.js +9 -2
- package/dist-sdk/src/entities/app/to-tf.d.ts +5 -0
- package/dist-sdk/src/entities/app/to-tf.js +33 -4
- package/dist-sdk/src/entities/automation/build.d.ts +57 -13
- package/dist-sdk/src/entities/automation/build.js +48 -36
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +25 -8
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +16 -1
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +179 -43
- package/dist-sdk/src/entities/automation/filter.d.ts +15 -3
- package/dist-sdk/src/entities/automation/filter.js +12 -2
- package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -27
- package/dist-sdk/src/entities/automation/from-tf.js +1229 -223
- package/dist-sdk/src/entities/automation/index.d.ts +4 -0
- package/dist-sdk/src/entities/automation/index.js +4 -0
- package/dist-sdk/src/entities/automation/module.js +29 -32
- package/dist-sdk/src/entities/automation/operators.d.ts +29 -2
- package/dist-sdk/src/entities/automation/operators.js +27 -1
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +10 -21
- package/dist-sdk/src/entities/automation/script-code.js +272 -5
- package/dist-sdk/src/entities/automation/tasks.d.ts +125 -19
- package/dist-sdk/src/entities/automation/tasks.js +83 -15
- package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -29
- package/dist-sdk/src/entities/automation/to-tf.js +1134 -231
- package/dist-sdk/src/entities/automation/triggers.d.ts +9 -1
- package/dist-sdk/src/entities/automation/types.d.ts +29 -4
- package/dist-sdk/src/entities/automation/types.js +76 -46
- package/dist-sdk/src/entities/element/build.d.ts +23 -10
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/from-tf.d.ts +1 -1
- package/dist-sdk/src/entities/element/from-tf.js +18 -3
- package/dist-sdk/src/entities/element/index.d.ts +4 -1
- package/dist-sdk/src/entities/element/index.js +2 -1
- package/dist-sdk/src/entities/element/module.js +3 -1
- package/dist-sdk/src/entities/element/to-tf.js +21 -3
- package/dist-sdk/src/entities/field/build.d.ts +56 -13
- package/dist-sdk/src/entities/field/build.js +10 -0
- package/dist-sdk/src/entities/field/calc/runtime.js +4 -0
- package/dist-sdk/src/entities/field/from-tf.d.ts +5 -3
- package/dist-sdk/src/entities/field/from-tf.js +118 -7
- package/dist-sdk/src/entities/field/module.js +3 -2
- package/dist-sdk/src/entities/field/to-tf.d.ts +27 -9
- package/dist-sdk/src/entities/field/to-tf.js +62 -17
- package/dist-sdk/src/entities/field/types.d.ts +26 -0
- package/dist-sdk/src/entities/field/types.js +34 -12
- package/dist-sdk/src/entities/file-reader/build.d.ts +108 -50
- package/dist-sdk/src/entities/file-reader/build.js +23 -23
- package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
- package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
- package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
- package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
- package/dist-sdk/src/entities/file-reader/index.d.ts +8 -3
- package/dist-sdk/src/entities/file-reader/index.js +7 -2
- package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
- package/dist-sdk/src/entities/file-reader/module.js +115 -0
- package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
- package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
- package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
- package/dist-sdk/src/entities/file-reader/types.js +30 -0
- package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
- package/dist-sdk/src/entities/org/ai-provider.js +46 -0
- package/dist-sdk/src/entities/org/connector.d.ts +8 -1
- package/dist-sdk/src/entities/org/connector.js +12 -14
- package/dist-sdk/src/entities/org/group.js +10 -1
- package/dist-sdk/src/entities/org/index.d.ts +1 -0
- package/dist-sdk/src/entities/org/index.js +1 -0
- package/dist-sdk/src/entities/org/user.js +10 -1
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +44 -9
- package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
- package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
- package/dist-sdk/src/entities/shared/tool-field-ref.js +31 -0
- package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -1
- package/dist-sdk/src/entities/shared/types/field-types.js +9 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +19 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +36 -8
- package/dist-sdk/src/entities/skill/from-tf.js +4 -3
- package/dist-sdk/src/entities/skill/index.d.ts +1 -1
- package/dist-sdk/src/entities/skill/module.js +6 -1
- package/dist-sdk/src/entities/skill/to-tf.js +3 -2
- package/dist-sdk/src/entities/skill/tools.d.ts +25 -3
- package/dist-sdk/src/entities/skill/tools.js +17 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +15 -2
- package/dist-sdk/src/entities/skill-tool/from-tf.js +32 -11
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.js +32 -9
- package/dist-sdk/src/entities/view/from-tf.d.ts +6 -2
- package/dist-sdk/src/entities/view/from-tf.js +11 -9
- package/dist-sdk/src/entities/view/to-tf.d.ts +9 -7
- package/dist-sdk/src/entities/view/to-tf.js +33 -18
- package/dist-sdk/src/entities/view/types.d.ts +1 -1
- package/dist-sdk/src/entities/view/types.js +1 -1
- package/dist-sdk/src/graph/deferred-catalog-render.d.ts +0 -5
- package/dist-sdk/src/graph/deferred-catalog-render.js +1 -20
- package/dist-sdk/src/graph/index.d.ts +8 -0
- package/dist-sdk/src/graph/index.js +13 -9
- package/dist-sdk/src/graph/modules.js +6 -1
- package/dist-sdk/src/graph/types.d.ts +77 -3
- package/package.json +42 -14
- package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +0 -76
- package/dist-sdk/src/entities/automation/value-ref-tf.js +0 -190
|
@@ -6,10 +6,27 @@
|
|
|
6
6
|
* import blocks and stay data-side.
|
|
7
7
|
*/
|
|
8
8
|
import { EntityTfError } from "../../engine/entity.js";
|
|
9
|
-
import { optionalString, resourceRefLabel } from "../../engine/pull/context.js";
|
|
10
|
-
import { isTfExpr, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
9
|
+
import { dataRefLabel, optionalString, resourceRefLabel } from "../../engine/pull/context.js";
|
|
10
|
+
import { bareChildResourceLabel, isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
11
11
|
import { optionsFromTf } from "./options.js";
|
|
12
12
|
import { KNOWN_FIELD_ATTRS, SUB_TYPE_BY_RESOURCE } from "./types.js";
|
|
13
|
+
/**
|
|
14
|
+
* A related_object_id/related_label_field_id value → its raw platform id, if
|
|
15
|
+
* recoverable: a literal string as-is, or a `<type>.<label>.id` resource
|
|
16
|
+
* reference resolved through this stream's own import blocks (the same
|
|
17
|
+
* lookup adoption uses - `ctx.importId` is keyed by every resource address
|
|
18
|
+
* the stream imports, not just this field's). `data-attr` foreign lookups
|
|
19
|
+
* and `local` computed attributes carry no import block for their target
|
|
20
|
+
* and stay unresolvable.
|
|
21
|
+
*/
|
|
22
|
+
function resolveRelatedId(v, ctx) {
|
|
23
|
+
if (typeof v === "string")
|
|
24
|
+
return v;
|
|
25
|
+
if (v !== undefined && isTfExpr(v) && v.$expr === "resource-attr" && v.path.length === 1 && v.path[0] === "id") {
|
|
26
|
+
return ctx.importId(`${v.type}.${v.label}`);
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
13
30
|
/**
|
|
14
31
|
* One field block → its normalized entry; undefined = skipped with a
|
|
15
32
|
* diagnostic (unknown resource type, or a field belonging to a different
|
|
@@ -25,6 +42,18 @@ export function fieldFromTf(block, owner, ctx) {
|
|
|
25
42
|
if (fieldLabel === undefined || fieldLabel === "") {
|
|
26
43
|
throw new EntityTfError(`${block.type} block is missing its label`);
|
|
27
44
|
}
|
|
45
|
+
if (subType.implemented !== true) {
|
|
46
|
+
// Declared but not yet round-tripped - see FIELD_SUB_TYPES for the
|
|
47
|
+
// current list of not-yet-implemented sub-types, if any.
|
|
48
|
+
// Reported to `skipped`, not just a diagnostic: this address still has a
|
|
49
|
+
// real import block in the stream and would otherwise get swept into
|
|
50
|
+
// adoption's targeted plan as a side effect of something else's
|
|
51
|
+
// reference to it (e.g. a layout's field_ids), even though nothing in
|
|
52
|
+
// authored source can ever reproduce it.
|
|
53
|
+
ctx.skipped.push(`${block.type}.${fieldLabel}`);
|
|
54
|
+
ctx.diagnostics.push(`${block.type}.${fieldLabel}: ${subType.typeKey} fields are not yet supported; skipped`);
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
28
57
|
const attrs = block.attrs;
|
|
29
58
|
const fieldName = optionalString(attrs, "name", `field "${fieldLabel}"`, ctx) ?? "";
|
|
30
59
|
const where = `field "${fieldName}" (${block.type}.${fieldLabel})`;
|
|
@@ -39,8 +68,80 @@ export function fieldFromTf(block, owner, ctx) {
|
|
|
39
68
|
return undefined;
|
|
40
69
|
}
|
|
41
70
|
const options = subType.hasOptions === true ? optionsFromTf(attrs["options"], `${where} options`, ctx) : undefined;
|
|
71
|
+
let decimalPlaces;
|
|
72
|
+
if (subType.typeKey === "decimal" && attrs["decimal_places"] !== undefined) {
|
|
73
|
+
if (typeof attrs["decimal_places"] === "number")
|
|
74
|
+
decimalPlaces = attrs["decimal_places"];
|
|
75
|
+
else
|
|
76
|
+
ctx.diagnostics.push(`${where}: decimal_places is not a number; dropped`);
|
|
77
|
+
}
|
|
78
|
+
// related_object_id/related_label_field_id are raw platform ids on the
|
|
79
|
+
// wire when ei's beautifier finds nothing to resolve them against - a
|
|
80
|
+
// non-recursive export never discovers the related aspect's own identity,
|
|
81
|
+
// so this is the common case (confirmed live) and they stay literal
|
|
82
|
+
// strings. But whenever the beautifier CAN resolve one, it prefers a
|
|
83
|
+
// readable terraform reference over the raw id: a self-relation prints
|
|
84
|
+
// `related_object_id = elementum_app.<self>.id`, a relation into a
|
|
85
|
+
// resource this same stream also imports (e.g. a field on a recursively
|
|
86
|
+
// discovered dependency) prints `<type>.<label>.id` the same way. Both are
|
|
87
|
+
// `resource-attr` expressions whose target carries its own import block in
|
|
88
|
+
// this stream, so the raw id IS recoverable - via the same `ctx.importId`
|
|
89
|
+
// lookup adoption itself uses, keyed by the referenced resource's address,
|
|
90
|
+
// not this field's own. What's NOT recoverable: a `data-attr` foreign
|
|
91
|
+
// lookup (`data.elementum_element.<label>.id` - data blocks are never
|
|
92
|
+
// imported) or a `local` computed attribute (`local.<app>_id_field_id` -
|
|
93
|
+
// an app/element's system field ids are read-only outputs of that
|
|
94
|
+
// resource, never their own resource address). Both properties are
|
|
95
|
+
// required by RelationFieldOptions, so printing relationField(...) with
|
|
96
|
+
// either missing would be invalid TypeScript (item 117) - skip the whole
|
|
97
|
+
// field when either side can't be resolved, same convention as an
|
|
98
|
+
// unimplemented sub-type.
|
|
99
|
+
let relatedAspectId;
|
|
100
|
+
let relatedLabelFieldId;
|
|
101
|
+
let autoRelate;
|
|
102
|
+
if (subType.hasRelation === true) {
|
|
103
|
+
relatedAspectId = resolveRelatedId(attrs["related_object_id"], ctx);
|
|
104
|
+
relatedLabelFieldId = resolveRelatedId(attrs["related_label_field_id"], ctx);
|
|
105
|
+
if (typeof attrs["auto_relate"] === "boolean")
|
|
106
|
+
autoRelate = attrs["auto_relate"];
|
|
107
|
+
if (relatedAspectId === undefined || relatedLabelFieldId === undefined) {
|
|
108
|
+
const missing = [
|
|
109
|
+
relatedAspectId === undefined && "related_object_id",
|
|
110
|
+
relatedLabelFieldId === undefined && "related_label_field_id",
|
|
111
|
+
].filter((v) => v !== false);
|
|
112
|
+
ctx.diagnostics.push(`${where}: ${missing.join(" and ")} does not resolve to a raw platform id - a RELATION field needs both to reconstruct relatedAspectId/relatedLabelFieldId; field skipped`);
|
|
113
|
+
ctx.skipped.push(`${block.type}.${fieldLabel}`);
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const fieldRole = attrs["field_role"];
|
|
118
|
+
const tags = Array.isArray(fieldRole) && fieldRole.every((t) => typeof t === "string")
|
|
119
|
+
? fieldRole
|
|
120
|
+
: undefined;
|
|
121
|
+
// A group/user field's default_value is a `data.elementum_group|user.<label>.id`
|
|
122
|
+
// EXPRESSION on the wire (the platform has no stable raw id to hand
|
|
123
|
+
// authored source, and the field is Optional-without-Computed — omitting
|
|
124
|
+
// it entirely would plan a destroy of the live default on every build).
|
|
125
|
+
// Round-trip the data block's own captured label + lookup value verbatim
|
|
126
|
+
// (see OrgFieldRefValue/fieldToTf's `rawLookup`) rather than resolving
|
|
127
|
+
// through the org.ts catalog: this is a pulled reference, not a
|
|
128
|
+
// hand-authored one, so there's no "does it still exist in the org"
|
|
129
|
+
// check to make.
|
|
130
|
+
let orgFieldRefDefault;
|
|
131
|
+
const orgRefDataType = subType.typeKey === "group" ? "elementum_group" : subType.typeKey === "user" ? "elementum_user" : undefined;
|
|
132
|
+
if (orgRefDataType !== undefined && isTfExpr(attrs["default_value"])) {
|
|
133
|
+
const label = dataRefLabel(attrs["default_value"], orgRefDataType);
|
|
134
|
+
const value = label !== undefined ? ctx.dataName(orgRefDataType, label) : undefined;
|
|
135
|
+
if (label !== undefined && value !== undefined) {
|
|
136
|
+
orgFieldRefDefault = { __kind: "orgFieldRef", dataType: orgRefDataType, label, value };
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
ctx.diagnostics.push(`${where}: default_value references an unresolvable ${orgRefDataType} data lookup; dropped`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const scope = owner.scope ?? "app";
|
|
42
143
|
return {
|
|
43
|
-
key:
|
|
144
|
+
key: scopedLabelToBagKey(owner.label, fieldLabel, scope),
|
|
44
145
|
field: {
|
|
45
146
|
id: ctx.importId(`${block.type}.${fieldLabel}`) ?? "",
|
|
46
147
|
name: fieldName,
|
|
@@ -54,9 +155,16 @@ export function fieldFromTf(block, owner, ctx) {
|
|
|
54
155
|
...(attrs["lock_on_create"] === true && { lockOnCreate: true }),
|
|
55
156
|
...(typeof attrs["description"] === "string" && { description: attrs["description"] }),
|
|
56
157
|
...(typeof attrs["column_name"] === "string" && { columnName: attrs["column_name"] }),
|
|
57
|
-
...(
|
|
58
|
-
|
|
158
|
+
...(orgFieldRefDefault !== undefined
|
|
159
|
+
? { defaultValue: orgFieldRefDefault }
|
|
160
|
+
: attrs["default_value"] !== undefined &&
|
|
161
|
+
!isTfExpr(attrs["default_value"]) && { defaultValue: attrs["default_value"] }),
|
|
59
162
|
...(options !== undefined && { options }),
|
|
163
|
+
...(tags !== undefined && tags.length > 0 && { tags }),
|
|
164
|
+
...(relatedAspectId !== undefined && { relatedAspectId }),
|
|
165
|
+
...(relatedLabelFieldId !== undefined && { relatedLabelFieldId }),
|
|
166
|
+
...(autoRelate !== undefined && { autoRelate }),
|
|
167
|
+
...(decimalPlaces !== undefined && { decimalPlaces }),
|
|
60
168
|
},
|
|
61
169
|
};
|
|
62
170
|
}
|
|
@@ -66,8 +174,11 @@ export function fieldFromTf(block, owner, ctx) {
|
|
|
66
174
|
* fields, view field_ids/columns). Undefined for any other shape or an
|
|
67
175
|
* unknown resource type.
|
|
68
176
|
*/
|
|
69
|
-
export function fieldKeyFromTfRef(v) {
|
|
177
|
+
export function fieldKeyFromTfRef(v, ownerTfLabel, scope = "app") {
|
|
70
178
|
if (!isTfExpr(v) || v.$expr !== "resource-attr" || v.path.length !== 1 || v.path[0] !== "id")
|
|
71
179
|
return undefined;
|
|
72
|
-
|
|
180
|
+
if (!SUB_TYPE_BY_RESOURCE.has(v.type))
|
|
181
|
+
return undefined;
|
|
182
|
+
const bare = ownerTfLabel !== undefined ? bareChildResourceLabel(ownerTfLabel, v.label, scope) : v.label;
|
|
183
|
+
return ownerTfLabel !== undefined ? scopedLabelToBagKey(ownerTfLabel, v.label, scope) : tfLabelToTsLabel(bare);
|
|
73
184
|
}
|
|
@@ -12,11 +12,10 @@ export const fieldModule = {
|
|
|
12
12
|
],
|
|
13
13
|
resource: {
|
|
14
14
|
shape: "subTypes",
|
|
15
|
-
// All field rows round-trip today — no implemented? flag on FieldSubType.
|
|
16
15
|
rows: FIELD_SUB_TYPES.map((t) => ({
|
|
17
16
|
key: t.typeKey,
|
|
18
17
|
resourceType: t.resourceType,
|
|
19
|
-
implemented: true,
|
|
18
|
+
implemented: t.implemented === true,
|
|
20
19
|
})),
|
|
21
20
|
},
|
|
22
21
|
data: NO_DATA,
|
|
@@ -35,6 +34,8 @@ export const fieldModule = {
|
|
|
35
34
|
const parts = [`fieldType: ${JSON.stringify(field.fieldType)}`];
|
|
36
35
|
if (field.tags !== undefined)
|
|
37
36
|
parts.push(`tags: ${JSON.stringify(field.tags)}`);
|
|
37
|
+
if (field.options !== undefined)
|
|
38
|
+
parts.push(`options: ${JSON.stringify(field.options)}`);
|
|
38
39
|
return parts;
|
|
39
40
|
}),
|
|
40
41
|
stubRef: (refName, parent) => ({
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* never silent, never thrown (plan §4.3). The one hard error is a
|
|
10
10
|
* non-canonical bag key: it has no well-defined terraform address.
|
|
11
11
|
*/
|
|
12
|
-
import
|
|
12
|
+
import type { OrgRefLookup } from "../../engine/build/context.js";
|
|
13
|
+
import { type ChildResourceScope, type TfBlock, type TfExpr, type TfValue } from "../../engine/tf/index.js";
|
|
13
14
|
import { type PicklistValueWire } from "./options.js";
|
|
14
15
|
/** The authored field shape (post-`slimTokens` compose body). Deliberately loose — degrade, don't assert. */
|
|
15
16
|
export interface FieldInnerWire {
|
|
@@ -27,12 +28,24 @@ export interface FieldInnerWire {
|
|
|
27
28
|
readonly config?: unknown;
|
|
28
29
|
readonly format?: unknown;
|
|
29
30
|
readonly calculation?: unknown;
|
|
31
|
+
/** "relation" fields only — raw platform ids, not catalog tokens (see RelationAppField). */
|
|
32
|
+
readonly relatedAspectId?: string;
|
|
33
|
+
readonly relatedLabelFieldId?: string;
|
|
34
|
+
readonly autoRelate?: boolean;
|
|
35
|
+
/** "decimal" fields only. */
|
|
36
|
+
readonly decimalPlaces?: number;
|
|
30
37
|
}
|
|
31
38
|
export interface FieldToTfOptions {
|
|
39
|
+
/** The owning stream root's terraform label (namespace). */
|
|
40
|
+
readonly ownerTfLabel: string;
|
|
41
|
+
/** App children use `apps_<ns>_`; element children use `<ns>_`. */
|
|
42
|
+
readonly scope?: ChildResourceScope;
|
|
32
43
|
/** The owner's id reference, e.g. `elementum_app.<ns>.id` — computed by the owner's to-tf. */
|
|
33
44
|
readonly objectId: TfValue;
|
|
34
45
|
/** Degradations land here — reported by the caller, never silent. */
|
|
35
46
|
readonly diagnostics: string[];
|
|
47
|
+
/** Needed to re-emit a group/user field's `default_value` as a `data.elementum_group|user` lookup (see `OrgFieldRefValue`). */
|
|
48
|
+
readonly orgRefs?: OrgRefLookup;
|
|
36
49
|
}
|
|
37
50
|
export interface FieldToTfResult {
|
|
38
51
|
readonly block: TfBlock;
|
|
@@ -44,12 +57,17 @@ export interface FieldToTfResult {
|
|
|
44
57
|
/** One custom field → its resource block; undefined = degraded (diagnostic already pushed). */
|
|
45
58
|
export declare function fieldToTf(typeKey: string, inner: FieldInnerWire, opts: FieldToTfOptions): FieldToTfResult | undefined;
|
|
46
59
|
/**
|
|
47
|
-
* A
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
60
|
+
* A field reference `{fieldType, refName}` (the shape a `FieldRef` token
|
|
61
|
+
* slims to) → its terraform expression — shared by anything that NAMES a
|
|
62
|
+
* field by typed ref rather than owning it directly (skill-tool fields,
|
|
63
|
+
* view layout/list-view field refs). A CUSTOM field resolves to
|
|
64
|
+
* `<resourceType>.<tfLabel>.id`; a SYSTEM field (title/status/closedBy/…)
|
|
65
|
+
* has no `elementum_<type>_field` resource of its own, only a computed
|
|
66
|
+
* `local.<app>_<key>_field_id` alias — checked first, since a system
|
|
67
|
+
* field's fieldType (e.g. "USER" for closedBy) can coincidentally match a
|
|
68
|
+
* real custom-field resource type. Undefined when the authoring type has no
|
|
69
|
+
* terraform mapping or the bag key isn't canonical; callers own the
|
|
70
|
+
* diagnostic wording since the two failure cases usually read differently
|
|
71
|
+
* at each call site.
|
|
54
72
|
*/
|
|
55
|
-
export declare function fieldRefToTfValue(fieldType: string, refName: string): TfExpr | undefined;
|
|
73
|
+
export declare function fieldRefToTfValue(fieldType: string, refName: string, ownerTfLabel: string, scope?: ChildResourceScope): TfExpr | undefined;
|
|
@@ -10,12 +10,19 @@
|
|
|
10
10
|
* non-canonical bag key: it has no well-defined terraform address.
|
|
11
11
|
*/
|
|
12
12
|
import { EntityTfError } from "../../engine/entity.js";
|
|
13
|
-
import { expr, isCanonicalTsLabel, snakeSlug, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
13
|
+
import { expr, isCanonicalTsLabel, scopedResourceLabel, snakeSlug, tsLabelToTfLabel } from "../../engine/tf/index.js";
|
|
14
|
+
import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
|
|
14
15
|
import { picklistLabel } from "./options.js";
|
|
15
16
|
import { SUB_TYPE_BY_AUTHORING_TYPE, SUB_TYPE_BY_TYPE_KEY } from "./types.js";
|
|
17
|
+
/** `unknown` → the tagged org-field-ref shape, or undefined for anything else. */
|
|
18
|
+
function asOrgFieldRef(v) {
|
|
19
|
+
if (typeof v !== "object" || v === null || v.__kind !== "orgFieldRef")
|
|
20
|
+
return undefined;
|
|
21
|
+
return v;
|
|
22
|
+
}
|
|
16
23
|
/** One custom field → its resource block; undefined = degraded (diagnostic already pushed). */
|
|
17
24
|
export function fieldToTf(typeKey, inner, opts) {
|
|
18
|
-
const { objectId, diagnostics } = opts;
|
|
25
|
+
const { ownerTfLabel, scope = "app", objectId, diagnostics } = opts;
|
|
19
26
|
const name = inner.name ?? "";
|
|
20
27
|
if (typeKey === "calculated" || inner.calculation !== undefined) {
|
|
21
28
|
diagnostics.push(`field "${name}": calculated fields are not supported on the terraform path yet; dropped`);
|
|
@@ -40,7 +47,7 @@ export function fieldToTf(typeKey, inner, opts) {
|
|
|
40
47
|
if (!isCanonicalTsLabel(bagKey)) {
|
|
41
48
|
throw new EntityTfError(`field bag key "${bagKey}" is not a canonical tsLabel (see src/engine/tf/labels.ts) — rename the key in fields: {}`);
|
|
42
49
|
}
|
|
43
|
-
const tfLabel = tsLabelToTfLabel(bagKey);
|
|
50
|
+
const tfLabel = scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(bagKey), scope);
|
|
44
51
|
const attrs = {
|
|
45
52
|
object_id: objectId,
|
|
46
53
|
name,
|
|
@@ -58,13 +65,41 @@ export function fieldToTf(typeKey, inner, opts) {
|
|
|
58
65
|
if (inner.columnName !== undefined)
|
|
59
66
|
attrs["column_name"] = inner.columnName;
|
|
60
67
|
if (inner.defaultValue !== undefined) {
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
|
|
68
|
+
const orgRef = asOrgFieldRef(inner.defaultValue);
|
|
69
|
+
if (orgRef !== undefined) {
|
|
70
|
+
if (opts.orgRefs === undefined) {
|
|
71
|
+
diagnostics.push(`field "${name}": default value references a ${orgRef.dataType} lookup but no org context is available; dropped`);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
opts.orgRefs.rawLookup(orgRef.dataType, orgRef.label, orgRef.value);
|
|
75
|
+
attrs["default_value"] = expr.dataAttr(orgRef.dataType, orgRef.label, ["id"]);
|
|
76
|
+
}
|
|
64
77
|
}
|
|
65
78
|
else {
|
|
66
|
-
|
|
79
|
+
const rendered = scalarOrUndefined(inner.defaultValue);
|
|
80
|
+
if (rendered === undefined) {
|
|
81
|
+
diagnostics.push(`field "${name}": default value has an unsupported (non-scalar) shape; dropped`);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
attrs["default_value"] = rendered;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (inner.tags !== undefined && inner.tags.length > 0) {
|
|
89
|
+
attrs["field_role"] = [...inner.tags];
|
|
90
|
+
}
|
|
91
|
+
if (typeKey === "decimal" && inner.decimalPlaces !== undefined) {
|
|
92
|
+
attrs["decimal_places"] = inner.decimalPlaces;
|
|
93
|
+
}
|
|
94
|
+
if (subType.hasRelation === true) {
|
|
95
|
+
if (inner.relatedAspectId === undefined || inner.relatedLabelFieldId === undefined) {
|
|
96
|
+
diagnostics.push(`field "${name}": relation fields require relatedAspectId and relatedLabelFieldId; dropped`);
|
|
97
|
+
return undefined;
|
|
67
98
|
}
|
|
99
|
+
attrs["related_object_id"] = inner.relatedAspectId;
|
|
100
|
+
attrs["related_label_field_id"] = inner.relatedLabelFieldId;
|
|
101
|
+
if (inner.autoRelate !== undefined)
|
|
102
|
+
attrs["auto_relate"] = inner.autoRelate;
|
|
68
103
|
}
|
|
69
104
|
if (subType.hasOptions === true && inner.picklistValues !== undefined) {
|
|
70
105
|
if (inner.picklistValues.some((pv) => pv.relatedParentValues !== undefined)) {
|
|
@@ -81,17 +116,27 @@ function scalarOrUndefined(v) {
|
|
|
81
116
|
return typeof v === "string" || typeof v === "number" || typeof v === "boolean" ? v : undefined;
|
|
82
117
|
}
|
|
83
118
|
/**
|
|
84
|
-
* A
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
119
|
+
* A field reference `{fieldType, refName}` (the shape a `FieldRef` token
|
|
120
|
+
* slims to) → its terraform expression — shared by anything that NAMES a
|
|
121
|
+
* field by typed ref rather than owning it directly (skill-tool fields,
|
|
122
|
+
* view layout/list-view field refs). A CUSTOM field resolves to
|
|
123
|
+
* `<resourceType>.<tfLabel>.id`; a SYSTEM field (title/status/closedBy/…)
|
|
124
|
+
* has no `elementum_<type>_field` resource of its own, only a computed
|
|
125
|
+
* `local.<app>_<key>_field_id` alias — checked first, since a system
|
|
126
|
+
* field's fieldType (e.g. "USER" for closedBy) can coincidentally match a
|
|
127
|
+
* real custom-field resource type. Undefined when the authoring type has no
|
|
128
|
+
* terraform mapping or the bag key isn't canonical; callers own the
|
|
129
|
+
* diagnostic wording since the two failure cases usually read differently
|
|
130
|
+
* at each call site.
|
|
91
131
|
*/
|
|
92
|
-
export function fieldRefToTfValue(fieldType, refName) {
|
|
132
|
+
export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app") {
|
|
133
|
+
if (!isCanonicalTsLabel(refName))
|
|
134
|
+
return undefined;
|
|
135
|
+
if (SYSTEM_FIELD_KEY_SET.has(refName)) {
|
|
136
|
+
return expr.local(`${ownerTfLabel}_${tsLabelToTfLabel(refName)}_field_id`);
|
|
137
|
+
}
|
|
93
138
|
const subType = SUB_TYPE_BY_AUTHORING_TYPE.get(fieldType);
|
|
94
|
-
if (subType === undefined
|
|
139
|
+
if (subType === undefined)
|
|
95
140
|
return undefined;
|
|
96
|
-
return expr.resourceAttr(subType.resourceType, tsLabelToTfLabel(refName), ["id"]);
|
|
141
|
+
return expr.resourceAttr(subType.resourceType, scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(refName), scope), ["id"]);
|
|
97
142
|
}
|
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
* A sub-type that grows real per-kind logic graduates to its own file under
|
|
7
7
|
* this directory (the automation task/ pattern).
|
|
8
8
|
*/
|
|
9
|
+
/**
|
|
10
|
+
* A group/user field's `defaultValue`, when the wire value is a
|
|
11
|
+
* `data.elementum_group|user.<label>.id` EXPRESSION rather than a plain
|
|
12
|
+
* scalar — round-tripped as this tagged shape (see `field/from-tf.ts`) so
|
|
13
|
+
* `fieldToTf` can re-emit the exact same data lookup instead of either
|
|
14
|
+
* dropping the value (a live destroy on every build, since the attribute is
|
|
15
|
+
* Optional-without-Computed) or fabricating an unresolvable raw id.
|
|
16
|
+
*/
|
|
17
|
+
export interface OrgFieldRefValue {
|
|
18
|
+
readonly __kind: "orgFieldRef";
|
|
19
|
+
readonly dataType: "elementum_group" | "elementum_user";
|
|
20
|
+
/** The data block's own label, captured verbatim — reproduced byte-for-byte, never re-derived. */
|
|
21
|
+
readonly label: string;
|
|
22
|
+
/** The data block's lookup-attr value ("name" for a group, "email" for a user). */
|
|
23
|
+
readonly value: string;
|
|
24
|
+
}
|
|
9
25
|
/** One field sub-type: the authoring variant key ↔ resource type ↔ normalized type triple. */
|
|
10
26
|
export interface FieldSubType {
|
|
11
27
|
/** `AspectFieldInput` variant key — the key under `fields: {}` entries ("html"). */
|
|
@@ -16,6 +32,16 @@ export interface FieldSubType {
|
|
|
16
32
|
readonly authoringType: string;
|
|
17
33
|
/** Carries an `options` attribute (the picklist kinds). */
|
|
18
34
|
readonly hasOptions?: true;
|
|
35
|
+
/** Carries `related_object_id`/`related_label_field_id`/`auto_relate` instead of the generic default_value/options handling (the "relation" sub-type only). */
|
|
36
|
+
readonly hasRelation?: true;
|
|
37
|
+
/**
|
|
38
|
+
* Round-trips through fieldFromTf/fieldToTf today. Declared-but-absent
|
|
39
|
+
* (undefined) sub-types are recognized (so fieldFromTf doesn't report
|
|
40
|
+
* "unknown resource" for them) but extraction reports them `skipped`
|
|
41
|
+
* rather than attempting the generic field shape - same convention as
|
|
42
|
+
* file-reader's/automation's per-sub-type `implemented` flags.
|
|
43
|
+
*/
|
|
44
|
+
readonly implemented?: true;
|
|
19
45
|
}
|
|
20
46
|
export declare const FIELD_SUB_TYPES: readonly FieldSubType[];
|
|
21
47
|
export declare const SUB_TYPE_BY_TYPE_KEY: ReadonlyMap<string, FieldSubType>;
|
|
@@ -7,23 +7,40 @@
|
|
|
7
7
|
* this directory (the automation task/ pattern).
|
|
8
8
|
*/
|
|
9
9
|
export const FIELD_SUB_TYPES = [
|
|
10
|
-
{ typeKey: "text", resourceType: "elementum_text_field", authoringType: "TEXT" },
|
|
11
|
-
{ typeKey: "html", resourceType: "elementum_longtext_field", authoringType: "HTML" },
|
|
12
|
-
{ typeKey: "number", resourceType: "elementum_number_field", authoringType: "NUMBER" },
|
|
13
|
-
{ typeKey: "decimal", resourceType: "elementum_decimal_field", authoringType: "DECIMAL" },
|
|
14
|
-
{ typeKey: "bool", resourceType: "elementum_boolean_field", authoringType: "BOOLEAN" },
|
|
15
|
-
{ typeKey: "date", resourceType: "elementum_date_field", authoringType: "DATE" },
|
|
16
|
-
{ typeKey: "dateTime", resourceType: "elementum_datetime_field", authoringType: "DATETIME" },
|
|
17
|
-
{ typeKey: "user", resourceType: "elementum_user_field", authoringType: "USER" },
|
|
18
|
-
{ typeKey: "group", resourceType: "elementum_group_field", authoringType: "GROUP" },
|
|
19
|
-
{ typeKey: "attachment", resourceType: "elementum_attachment_field", authoringType: "ATTACHMENT" },
|
|
20
|
-
{ typeKey: "json", resourceType: "elementum_json_field", authoringType: "JSON" },
|
|
21
|
-
{
|
|
10
|
+
{ typeKey: "text", resourceType: "elementum_text_field", authoringType: "TEXT", implemented: true },
|
|
11
|
+
{ typeKey: "html", resourceType: "elementum_longtext_field", authoringType: "HTML", implemented: true },
|
|
12
|
+
{ typeKey: "number", resourceType: "elementum_number_field", authoringType: "NUMBER", implemented: true },
|
|
13
|
+
{ typeKey: "decimal", resourceType: "elementum_decimal_field", authoringType: "DECIMAL", implemented: true },
|
|
14
|
+
{ typeKey: "bool", resourceType: "elementum_boolean_field", authoringType: "BOOLEAN", implemented: true },
|
|
15
|
+
{ typeKey: "date", resourceType: "elementum_date_field", authoringType: "DATE", implemented: true },
|
|
16
|
+
{ typeKey: "dateTime", resourceType: "elementum_datetime_field", authoringType: "DATETIME", implemented: true },
|
|
17
|
+
{ typeKey: "user", resourceType: "elementum_user_field", authoringType: "USER", implemented: true },
|
|
18
|
+
{ typeKey: "group", resourceType: "elementum_group_field", authoringType: "GROUP", implemented: true },
|
|
19
|
+
{ typeKey: "attachment", resourceType: "elementum_attachment_field", authoringType: "ATTACHMENT", implemented: true },
|
|
20
|
+
{ typeKey: "json", resourceType: "elementum_json_field", authoringType: "JSON", implemented: true },
|
|
21
|
+
{
|
|
22
|
+
typeKey: "picklist",
|
|
23
|
+
resourceType: "elementum_dropdown_field",
|
|
24
|
+
authoringType: "PICKLIST",
|
|
25
|
+
hasOptions: true,
|
|
26
|
+
implemented: true,
|
|
27
|
+
},
|
|
22
28
|
{
|
|
23
29
|
typeKey: "multiPicklist",
|
|
24
30
|
resourceType: "elementum_multiselect_field",
|
|
25
31
|
authoringType: "MULTI_PICKLIST",
|
|
26
32
|
hasOptions: true,
|
|
33
|
+
implemented: true,
|
|
34
|
+
},
|
|
35
|
+
// related_object_id/related_label_field_id/auto_relate are handled
|
|
36
|
+
// specially in fieldFromTf/fieldToTf (see hasRelation below), not via the
|
|
37
|
+
// generic default_value/options handling other sub-types share.
|
|
38
|
+
{
|
|
39
|
+
typeKey: "relation",
|
|
40
|
+
resourceType: "elementum_relation_field",
|
|
41
|
+
authoringType: "RELATION",
|
|
42
|
+
hasRelation: true,
|
|
43
|
+
implemented: true,
|
|
27
44
|
},
|
|
28
45
|
];
|
|
29
46
|
export const SUB_TYPE_BY_TYPE_KEY = new Map(FIELD_SUB_TYPES.map((t) => [t.typeKey, t]));
|
|
@@ -43,4 +60,9 @@ export const KNOWN_FIELD_ATTRS = new Set([
|
|
|
43
60
|
"column_name",
|
|
44
61
|
"default_value",
|
|
45
62
|
"options",
|
|
63
|
+
"field_role",
|
|
64
|
+
"related_object_id",
|
|
65
|
+
"related_label_field_id",
|
|
66
|
+
"auto_relate",
|
|
67
|
+
"decimal_places",
|
|
46
68
|
]);
|