@elementumai/edk 0.9.6 → 0.9.7

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.
Files changed (97) hide show
  1. package/README.md +31 -1
  2. package/dist-sdk/src/catalog/factories.d.ts +12 -3
  3. package/dist-sdk/src/catalog/factories.js +9 -6
  4. package/dist-sdk/src/catalog/org.js +26 -13
  5. package/dist-sdk/src/catalog/types.d.ts +22 -1
  6. package/dist-sdk/src/core/index.d.ts +1 -1
  7. package/dist-sdk/src/core/system-fields.d.ts +4 -0
  8. package/dist-sdk/src/core/system-fields.js +15 -0
  9. package/dist-sdk/src/core/types/app.d.ts +14 -9
  10. package/dist-sdk/src/core/types/platform.d.ts +1 -1
  11. package/dist-sdk/src/engine/build/context.d.ts +4 -0
  12. package/dist-sdk/src/engine/pull/context.d.ts +9 -0
  13. package/dist-sdk/src/engine/pull/ref-only.d.ts +14 -0
  14. package/dist-sdk/src/engine/pull/ref-only.js +35 -2
  15. package/dist-sdk/src/entities/access-policy/from-tf.js +14 -2
  16. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +6 -0
  17. package/dist-sdk/src/entities/access-policy/to-tf.js +4 -1
  18. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +18 -1
  19. package/dist-sdk/src/entities/agent/module.js +1 -0
  20. package/dist-sdk/src/entities/agent/to-tf.d.ts +1 -0
  21. package/dist-sdk/src/entities/agent/to-tf.js +1 -0
  22. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +9 -0
  23. package/dist-sdk/src/entities/agent-tool/from-tf.js +10 -2
  24. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -0
  25. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -3
  26. package/dist-sdk/src/entities/app/build.d.ts +42 -22
  27. package/dist-sdk/src/entities/app/build.js +12 -5
  28. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +10 -0
  29. package/dist-sdk/src/entities/app/from-tf.js +71 -8
  30. package/dist-sdk/src/entities/app/index.d.ts +3 -2
  31. package/dist-sdk/src/entities/app/index.js +2 -1
  32. package/dist-sdk/src/entities/app/to-tf.js +16 -0
  33. package/dist-sdk/src/entities/automation/build.d.ts +31 -19
  34. package/dist-sdk/src/entities/automation/build.js +85 -7
  35. package/dist-sdk/src/entities/automation/catalog-render.js +5 -2
  36. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +5 -3
  37. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +26 -12
  38. package/dist-sdk/src/entities/automation/from-tf.js +364 -31
  39. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  40. package/dist-sdk/src/entities/automation/module.js +2 -2
  41. package/dist-sdk/src/entities/automation/operators.d.ts +2 -2
  42. package/dist-sdk/src/entities/automation/operators.js +1 -0
  43. package/dist-sdk/src/entities/automation/output-field-types.d.ts +17 -0
  44. package/dist-sdk/src/entities/automation/output-field-types.js +45 -0
  45. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +8 -0
  46. package/dist-sdk/src/entities/automation/output-key-wire-name.js +16 -0
  47. package/dist-sdk/src/entities/automation/script-code.js +153 -25
  48. package/dist-sdk/src/entities/automation/tasks.d.ts +100 -37
  49. package/dist-sdk/src/entities/automation/tasks.js +44 -43
  50. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -1
  51. package/dist-sdk/src/entities/automation/to-tf.js +454 -58
  52. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +78 -0
  53. package/dist-sdk/src/entities/automation/value-ref-tf.js +193 -0
  54. package/dist-sdk/src/entities/element/build.js +1 -0
  55. package/dist-sdk/src/entities/element/index.d.ts +2 -1
  56. package/dist-sdk/src/entities/element/index.js +2 -1
  57. package/dist-sdk/src/entities/field/build.d.ts +94 -3
  58. package/dist-sdk/src/entities/field/build.js +82 -3
  59. package/dist-sdk/src/entities/field/from-tf.js +92 -1
  60. package/dist-sdk/src/entities/field/locals.js +6 -7
  61. package/dist-sdk/src/entities/field/options.d.ts +2 -0
  62. package/dist-sdk/src/entities/field/options.js +12 -2
  63. package/dist-sdk/src/entities/field/record-shape.d.ts +12 -15
  64. package/dist-sdk/src/entities/field/to-tf.d.ts +12 -2
  65. package/dist-sdk/src/entities/field/to-tf.js +172 -51
  66. package/dist-sdk/src/entities/field/types.js +2 -0
  67. package/dist-sdk/src/entities/record-create-form/to-tf.js +5 -8
  68. package/dist-sdk/src/entities/relationship/from-tf.js +91 -9
  69. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +9 -0
  70. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +39 -0
  71. package/dist-sdk/src/entities/shared/filters/ast.d.ts +18 -1
  72. package/dist-sdk/src/entities/shared/filters/ast.js +1 -0
  73. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +6 -1
  74. package/dist-sdk/src/entities/shared/filters/tf-codec.js +6 -4
  75. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +5 -3
  76. package/dist-sdk/src/entities/shared/tool-field-ref.js +11 -16
  77. package/dist-sdk/src/entities/shared/types/common.d.ts +7 -5
  78. package/dist-sdk/src/entities/shared/types/platform.d.ts +15 -2
  79. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +1 -1
  80. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +44 -15
  81. package/dist-sdk/src/entities/skill/from-tf.js +11 -1
  82. package/dist-sdk/src/entities/skill/input-coverage.d.ts +68 -0
  83. package/dist-sdk/src/entities/skill/input-coverage.js +184 -0
  84. package/dist-sdk/src/entities/skill/module.js +2 -0
  85. package/dist-sdk/src/entities/skill/to-tf.d.ts +3 -0
  86. package/dist-sdk/src/entities/skill/to-tf.js +7 -2
  87. package/dist-sdk/src/entities/skill/tools.d.ts +10 -1
  88. package/dist-sdk/src/entities/skill/tools.js +0 -5
  89. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +19 -0
  90. package/dist-sdk/src/entities/skill-tool/from-tf.js +40 -11
  91. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +4 -2
  92. package/dist-sdk/src/entities/skill-tool/to-tf.js +24 -16
  93. package/dist-sdk/src/entities/table/to-tf.js +18 -1
  94. package/dist-sdk/src/entities/view/to-tf.js +8 -3
  95. package/dist-sdk/src/entities/visual-flow/from-tf.js +6 -2
  96. package/dist-sdk/src/graph/types.d.ts +3 -0
  97. package/package.json +2 -1
@@ -101,7 +101,20 @@ function dynamicPicklistFilterFieldRef(value, ctx) {
101
101
  if (typeof resolved === "string")
102
102
  return { kind: "unresolved", uuid: resolved, hint: "field" };
103
103
  if (resolved !== undefined) {
104
- return { kind: "field", appHandle: resolved.ownerRefName, fieldKey: resolved.fieldKey };
104
+ return {
105
+ kind: "field",
106
+ appHandle: resolved.ownerRefName,
107
+ fieldKey: resolved.fieldKey,
108
+ ...(resolved.ownerKind !== undefined && resolved.ownerName !== undefined ? {
109
+ foreign: {
110
+ entityType: resolved.ownerKind,
111
+ name: resolved.ownerName,
112
+ ...(resolved.ownerNamespace !== undefined ? { namespace: resolved.ownerNamespace } : {}),
113
+ ...(resolved.fieldName !== undefined ? { fieldName: resolved.fieldName } : {}),
114
+ ...(resolved.fieldType !== undefined ? { fieldType: resolved.fieldType } : {}),
115
+ },
116
+ } : {}),
117
+ };
105
118
  }
106
119
  throw new EntityTfError("dynamic picklist filter field reference cannot be reconstructed");
107
120
  }
@@ -165,11 +178,38 @@ function dynamicConfigFromTf(value, owner, ctx, where) {
165
178
  ctx.diagnostics.push(`${where}: dynamic_config.sort is not a jsonencode(...) object; dropped`);
166
179
  }
167
180
  }
181
+ let parentMappings;
182
+ if (attrs["parent_mappings"] !== undefined) {
183
+ const rawMappings = attrs["parent_mappings"];
184
+ if (!Array.isArray(rawMappings)) {
185
+ ctx.diagnostics.push(`${where}: dynamic_config.parent_mappings is not a list; dropped`);
186
+ }
187
+ else {
188
+ parentMappings = [];
189
+ for (const rawMapping of rawMappings) {
190
+ if (typeof rawMapping !== "object" || rawMapping === null || Array.isArray(rawMapping) || isTfExpr(rawMapping)) {
191
+ ctx.diagnostics.push(`${where}: dynamic_config parent mapping has an unexpected shape; dropped`);
192
+ continue;
193
+ }
194
+ const mapping = rawMapping;
195
+ const parentAspectFieldId = resolveRelatedId(mapping["parent_aspect_field_id"], ctx);
196
+ const relatedAspectFieldId = resolveRelatedId(mapping["related_aspect_field_id"], ctx);
197
+ if (parentAspectFieldId === undefined || relatedAspectFieldId === undefined) {
198
+ ctx.diagnostics.push(`${where}: dynamic_config parent mapping field IDs could not be reconstructed; dropped`);
199
+ continue;
200
+ }
201
+ parentMappings.push({ parentAspectFieldId, relatedAspectFieldId });
202
+ }
203
+ if (parentMappings.length === 0)
204
+ parentMappings = undefined;
205
+ }
206
+ }
168
207
  return {
169
208
  dynamic: {
170
209
  relatedAspectId,
171
210
  relatedLabelFieldId,
172
211
  ...(parentFieldId !== undefined && { parentFieldId }),
212
+ ...(parentMappings !== undefined && { parentMappings }),
173
213
  ...(autoRelate !== undefined && { autoRelate }),
174
214
  ...(valuesRenderType !== undefined && { valuesRenderType }),
175
215
  ...(filter !== undefined && { filter }),
@@ -177,6 +217,53 @@ function dynamicConfigFromTf(value, owner, ctx, where) {
177
217
  },
178
218
  };
179
219
  }
220
+ function staticParentLinkageFromTf(value, optionsValue, owner, ctx, where) {
221
+ if (value === undefined)
222
+ return undefined;
223
+ if (typeof value !== "object" || value === null || isTfExpr(value) || Array.isArray(value)) {
224
+ ctx.diagnostics.push(`${where}: static_config has an unexpected shape; dropped`);
225
+ return undefined;
226
+ }
227
+ const parentFieldValue = value["parent_field_id"];
228
+ if (parentFieldValue === undefined)
229
+ return undefined;
230
+ const parentFieldKey = fieldKeyFromTfRef(parentFieldValue, owner.label, owner.scope ?? "app");
231
+ if (parentFieldKey === undefined) {
232
+ ctx.diagnostics.push(`${where}: static_config.parent_field_id could not be resolved to a same-app field; dropped`);
233
+ return undefined;
234
+ }
235
+ const optionParentLabels = new Map();
236
+ if (Array.isArray(optionsValue)) {
237
+ for (const rawOption of optionsValue) {
238
+ if (typeof rawOption !== "object" || rawOption === null || Array.isArray(rawOption) || isTfExpr(rawOption))
239
+ continue;
240
+ const option = rawOption;
241
+ const label = typeof option["label"] === "string" ? option["label"] : undefined;
242
+ const parentValues = option["parent_value_ids"];
243
+ if (label === undefined || !Array.isArray(parentValues))
244
+ continue;
245
+ const labels = [];
246
+ for (const parentValue of parentValues) {
247
+ if (isTfExpr(parentValue) &&
248
+ parentValue.$expr === "local" &&
249
+ parentValue.path.length === 1 &&
250
+ typeof parentValue.path[0] === "object" &&
251
+ "index" in parentValue.path[0]) {
252
+ labels.push(parentValue.path[0].index);
253
+ }
254
+ else {
255
+ ctx.diagnostics.push(`${where}: option "${label}" has an unresolvable parent_value_ids entry; dropped`);
256
+ }
257
+ }
258
+ if (labels.length > 0)
259
+ optionParentLabels.set(label, labels);
260
+ }
261
+ }
262
+ return {
263
+ parentFieldKey,
264
+ ...(optionParentLabels.size > 0 && { optionParentLabels }),
265
+ };
266
+ }
180
267
  /**
181
268
  * One field block → its normalized entry; undefined = skipped with a
182
269
  * diagnostic (unknown resource type, or a field belonging to a different
@@ -221,6 +308,9 @@ export function fieldFromTf(block, owner, ctx) {
221
308
  ? optionsFromTf(attrs["options"], `${where} options`, ctx)
222
309
  : undefined;
223
310
  const config = subType.hasOptions === true ? dynamicConfigFromTf(attrs["dynamic_config"], owner, ctx, where) : undefined;
311
+ const parentLinkage = subType.hasOptions === true && attrs["dynamic_config"] === undefined
312
+ ? staticParentLinkageFromTf(attrs["static_config"], attrs["options"], owner, ctx, where)
313
+ : undefined;
224
314
  let decimalPlaces;
225
315
  if (subType.typeKey === "decimal" && attrs["decimal_places"] !== undefined) {
226
316
  if (typeof attrs["decimal_places"] === "number")
@@ -352,6 +442,7 @@ export function fieldFromTf(block, owner, ctx) {
352
442
  }
353
443
  return {
354
444
  key: scopedLabelToBagKey(owner.label, fieldLabel, scope),
445
+ ...(parentLinkage !== undefined && { parentLinkage }),
355
446
  ...(isCalculationResultType(calculationType) && { calculationType }),
356
447
  ...(calculationInclude !== undefined && { calculationInclude }),
357
448
  field: {
@@ -4,13 +4,12 @@
4
4
  * resource (bare field label — ei does not namespace-prefix these).
5
5
  */
6
6
  import { expr } from "../../engine/tf/index.js";
7
- // Dropdown ONLY, deliberately: ei's GenerateLocals has a multiselect branch,
8
- // but it matches import blocks against "elementum_multi_select_field" — the
9
- // real resource type is elementum_multiselect_field, so that branch never
10
- // fires and real exports carry option-lookup locals for dropdowns only. The
11
- // dialect is ei's actual output, not its intent (integration-harness build-vs-export
12
- // finding, 2026-07-23).
13
- const OPTION_LOOKUP_FIELD_RESOURCE_TYPES = new Set(["elementum_dropdown_field"]);
7
+ // Both product selection fields need label-to-id lookups: dependent static
8
+ // options can use either a Dropdown or Multi-Select as their parent.
9
+ const OPTION_LOOKUP_FIELD_RESOURCE_TYPES = new Set([
10
+ "elementum_dropdown_field",
11
+ "elementum_multiselect_field",
12
+ ]);
14
13
  /**
15
14
  * Append one app's field-level lookup locals, keyed by the emitted field
16
15
  * addresses. Skips any dropdown field whose values come from `dynamic_config`
@@ -13,6 +13,8 @@ export interface PicklistValueWire {
13
13
  readonly value?: string;
14
14
  readonly tags?: readonly string[];
15
15
  readonly color?: string;
16
+ readonly icon?: string;
17
+ readonly active?: boolean;
16
18
  readonly relatedParentValues?: unknown;
17
19
  }
18
20
  export declare function picklistLabel(pv: PicklistValueWire): string;
@@ -39,11 +39,13 @@ export function optionsFromTf(v, where, ctx) {
39
39
  continue;
40
40
  }
41
41
  for (const key of Object.keys(rec)) {
42
- if (key !== "label" && key !== "tags" && key !== "color") {
42
+ if (key !== "label" && key !== "tags" && key !== "color" && key !== "icon" && key !== "active" && key !== "parent_value_ids") {
43
43
  ctx.diagnostics.push(`${where}: option "${optLabel}" has an unhandled property "${key}"; dropped`);
44
44
  }
45
45
  }
46
46
  const color = typeof rec["color"] === "string" && rec["color"] !== "" ? rec["color"] : undefined;
47
+ const icon = typeof rec["icon"] === "string" && rec["icon"] !== "" ? rec["icon"] : undefined;
48
+ const active = typeof rec["active"] === "boolean" ? rec["active"] : undefined;
47
49
  const tags = [];
48
50
  const rawTags = rec["tags"];
49
51
  if (Array.isArray(rawTags)) {
@@ -59,7 +61,13 @@ export function optionsFromTf(v, where, ctx) {
59
61
  else if (rawTags !== undefined) {
60
62
  ctx.diagnostics.push(`${where}: option "${optLabel}" tags is not a list; dropped`);
61
63
  }
62
- parsed.push({ label: optLabel, ...(color !== undefined && { color }), tags });
64
+ parsed.push({
65
+ label: optLabel,
66
+ ...(color !== undefined && { color }),
67
+ ...(icon !== undefined && { icon }),
68
+ ...(active !== undefined && { active }),
69
+ tags,
70
+ });
63
71
  }
64
72
  if (parsed.length === 0)
65
73
  return undefined;
@@ -69,6 +77,8 @@ export function optionsFromTf(v, where, ctx) {
69
77
  id: "",
70
78
  label: item.label,
71
79
  ...(item.color !== undefined && { color: item.color }),
80
+ ...(item.icon !== undefined && { icon: item.icon }),
81
+ ...(item.active !== undefined && { active: item.active }),
72
82
  ...(item.tags.length > 0 && { tags: item.tags }),
73
83
  };
74
84
  }
@@ -8,7 +8,8 @@
8
8
  * …). A few carry richer sub-properties that the platform resolves at
9
9
  * runtime, so their record value is an object instead — `DeepRef` then
10
10
  * exposes those sub-properties for drilling, e.g.
11
- * `ctx.trigger.record.severity.label` or `ctx.trigger.record.owner.email`.
11
+ * `ctx.trigger.record.severity.label`, `ctx.trigger.record.owner.email`,
12
+ * or `ctx.trigger.record.parentTicket.recordId` (dynamic Dropdown).
12
13
  * Object shapes come from `entities/shared/types/platform.ts` so a
13
14
  * `User`/`Attachment`/… means the same thing everywhere in the SDK.
14
15
  *
@@ -17,11 +18,17 @@
17
18
  */
18
19
  import type { FieldRef } from "../../catalog/types.js";
19
20
  import type { CalculationTypedValue } from "../shared/ref.js";
20
- import type { Attachment, Group, PicklistValue, RichText, User } from "../shared/types/platform.js";
21
+ import type { Attachment, DropdownValue, DynamicDropdownValue, Group, RecordId, RichText, User } from "../shared/types/platform.js";
22
+ export type { RecordId } from "../shared/types/platform.js";
21
23
  /** Map a platform field type literal to the TS type exposed on a record field. */
22
24
  type CalculationTypeForField<FieldType extends string> = FieldType extends "NUMBER" ? "number" : FieldType extends "DECIMAL" ? "decimal" : FieldType extends "BOOLEAN" ? "bool" : FieldType extends "DATE" ? "date" : FieldType extends "DATETIME" ? "datetime" : FieldType extends "PICKLIST" | "PICKLIST_ID" ? "picklist" : FieldType extends "MULTI_PICKLIST" | "MULTI_PICKLIST_ID" ? "multiPicklist" : FieldType extends "ATTACHMENT" | "ATTACHMENT_ID" | "FILE" ? "attachment" : FieldType extends "USER" | "USER_ID" ? "user" : FieldType extends "GROUP" | "GROUP_ID" ? "group" : FieldType extends "JSON" | "OBJECT" ? "json" : FieldType extends "HTML" ? "html" : FieldType extends "HANDLE" ? "handle" : FieldType extends "RICH_TEXT" ? "text" : "text";
23
- type RawFieldValueType<FieldType extends string> = FieldType extends "NUMBER" | "DECIMAL" ? number : FieldType extends "BOOLEAN" ? boolean : FieldType extends "JSON" | "OBJECT" ? unknown : FieldType extends "PICKLIST" | "PICKLIST_ID" ? PicklistValue : FieldType extends "MULTI_PICKLIST" | "MULTI_PICKLIST_ID" ? readonly PicklistValue[] : FieldType extends "ATTACHMENT" | "ATTACHMENT_ID" | "FILE" ? Attachment : FieldType extends "RICH_TEXT" ? RichText : FieldType extends "USER" | "USER_ID" ? User : FieldType extends "GROUP" | "GROUP_ID" ? Group : string;
24
- export type FieldValueType<FieldType extends string> = CalculationTypedValue<RawFieldValueType<FieldType>, CalculationTypeForField<FieldType>>;
25
+ type RawFieldValueType<FieldType extends string> = FieldType extends "NUMBER" | "DECIMAL" ? number : FieldType extends "BOOLEAN" ? boolean : FieldType extends "JSON" | "OBJECT" ? unknown : FieldType extends "PICKLIST" | "PICKLIST_ID" ? DropdownValue : FieldType extends "MULTI_PICKLIST" | "MULTI_PICKLIST_ID" ? readonly DropdownValue[] : FieldType extends "ATTACHMENT" | "ATTACHMENT_ID" | "FILE" ? Attachment : FieldType extends "RICH_TEXT" ? RichText : FieldType extends "USER" | "USER_ID" ? User : FieldType extends "GROUP" | "GROUP_ID" ? Group : string;
26
+ type CalculatedFieldValueType<FieldType extends string> = CalculationTypedValue<RawFieldValueType<FieldType>, CalculationTypeForField<FieldType>>;
27
+ export type FieldValueType<Field extends string | FieldRef> = Field extends FieldRef<string, string, infer FieldType> ? FieldType extends "PICKLIST" | "PICKLIST_ID" ? Field extends {
28
+ readonly dynamicSource: unknown;
29
+ } ? DynamicDropdownValue : DropdownValue : FieldType extends "MULTI_PICKLIST" | "MULTI_PICKLIST_ID" ? readonly (Field extends {
30
+ readonly dynamicSource: unknown;
31
+ } ? DynamicDropdownValue : DropdownValue)[] : CalculatedFieldValueType<FieldType> : Field extends string ? CalculatedFieldValueType<Field> : never;
25
32
  /**
26
33
  * Extract the `fields` bag off an app/element-like ref, e.g. `typeof catalog.myApp`.
27
34
  * `undefined` when the ref carries no `fields` bag (a hand-built `AppOrElementRef`
@@ -30,15 +37,6 @@ export type FieldValueType<FieldType extends string> = CalculationTypedValue<Raw
30
37
  export type AppFieldsOf<A> = A extends {
31
38
  readonly fields: infer F extends Record<string, FieldRef>;
32
39
  } ? F : undefined;
33
- declare const recordIdBrand: unique symbol;
34
- /**
35
- * Platform record identity (wire type ASPECT_RECORD_ID). Distinct from a
36
- * record's TEXT `id` handle so `Ref<RecordId>` cannot be satisfied by
37
- * `ctx.trigger.record.id` (`refs["ID"]`).
38
- */
39
- export type RecordId = string & {
40
- readonly [recordIdBrand]: "recordId";
41
- };
42
40
  /**
43
41
  * The typed record shape for an app/element ref. When `A` carries a concrete
44
42
  * `fields` bag (a real catalog app), this is a closed, per-field-typed object —
@@ -66,6 +64,5 @@ export type RecordShape<A> = {
66
64
  readonly id: string;
67
65
  readonly recordId: RecordId;
68
66
  } & (AppFieldsOf<A> extends Record<string, FieldRef> ? {
69
- readonly [K in keyof AppFieldsOf<A>]: FieldValueType<AppFieldsOf<A>[K]["fieldType"]>;
67
+ readonly [K in keyof AppFieldsOf<A>]: FieldValueType<AppFieldsOf<A>[K]>;
70
68
  } : {});
71
- export {};
@@ -26,6 +26,8 @@ interface FieldTokenWire {
26
26
  readonly name?: string;
27
27
  readonly parent?: string;
28
28
  readonly parentNamespace?: string;
29
+ readonly parentKind?: "app" | "element";
30
+ readonly parentName?: string;
29
31
  readonly fieldType?: string;
30
32
  }
31
33
  /**
@@ -53,6 +55,10 @@ interface DynamicPicklistConfigWire {
53
55
  readonly relatedAspectId?: AspectTokenWire | string;
54
56
  readonly relatedLabelFieldId?: FieldTokenWire | string;
55
57
  readonly parentFieldId?: FieldTokenWire | string;
58
+ readonly parentMappings?: readonly {
59
+ readonly parentAspectFieldId?: FieldTokenWire | string;
60
+ readonly relatedAspectFieldId?: FieldTokenWire | string;
61
+ }[];
56
62
  readonly autoRelate?: boolean;
57
63
  readonly valuesRenderType?: string;
58
64
  readonly filter?: unknown;
@@ -60,10 +66,14 @@ interface DynamicPicklistConfigWire {
60
66
  readonly orders: readonly DynamicPicklistSortOrderWire[];
61
67
  } | Record<string, unknown>;
62
68
  }
63
- /** Slim `AppPicklistConfig` shape — only `dynamic` round-trips through the terraform path (see fieldToTf's config handling). */
69
+ interface StaticPicklistConfigWire {
70
+ readonly parentFieldId?: FieldTokenWire | string;
71
+ readonly filter?: unknown;
72
+ readonly sort?: Record<string, unknown>;
73
+ }
64
74
  interface FieldConfigWire {
65
75
  readonly dynamic?: DynamicPicklistConfigWire;
66
- readonly static?: unknown;
76
+ readonly static?: StaticPicklistConfigWire;
67
77
  }
68
78
  /** The authored field shape (post-`slimTokens` compose body). Deliberately loose — degrade, don't assert. */
69
79
  export interface FieldInnerWire {
@@ -22,18 +22,6 @@ function asOrgFieldRef(v) {
22
22
  return undefined;
23
23
  return v;
24
24
  }
25
- /**
26
- * True when `sort` is the one known `{ orders: [{ field, ... }] }` shape —
27
- * a single `orders` key whose value is an array of objects each carrying a
28
- * `field`. Anything else (including an empty/absent `orders`) is opaque data
29
- * and passes through unresolved, same as before #484.
30
- */
31
- function isDynamicPicklistOrdersSort(sort) {
32
- const keys = Object.keys(sort);
33
- const orders = sort.orders;
34
- return keys.length === 1 && keys[0] === "orders" && Array.isArray(orders) &&
35
- orders.length > 0 && orders.every((o) => typeof o === "object" && o !== null && "field" in o);
36
- }
37
25
  /**
38
26
  * Project the subset of the public numeric-format contract that the field
39
27
  * resources own today. Unsupported properties are diagnosed individually so
@@ -121,12 +109,12 @@ function resolveRelatedObject(token, opts, where) {
121
109
  opts.orgRefs.foreignElement(tfLabel, name, token.namespace);
122
110
  if (token.namespace === undefined)
123
111
  opts.diagnostics.push(`${where}: foreign element ${JSON.stringify(name)} has no namespace; using less-stable name lookup`);
124
- return { value: expr.dataAttr("elementum_element", tfLabel, ["id"]), refName, kind };
112
+ return { value: expr.dataAttr("elementum_element", tfLabel, ["id"]), refName, kind, foreignTfLabel: tfLabel };
125
113
  }
126
114
  opts.orgRefs.foreignApp(tfLabel, name, token.namespace);
127
115
  if (token.namespace === undefined)
128
116
  opts.diagnostics.push(`${where}: foreign app ${JSON.stringify(name)} has no namespace; using less-stable name lookup`);
129
- return { value: expr.dataAttr("elementum_app", tfLabel, ["id"]), refName, kind };
117
+ return { value: expr.dataAttr("elementum_app", tfLabel, ["id"]), refName, kind, foreignTfLabel: tfLabel };
130
118
  }
131
119
  /**
132
120
  * A field token naming a field on an already-resolved target aspect →
@@ -184,8 +172,16 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
184
172
  return undefined;
185
173
  }
186
174
  const name = token.name ?? refName;
187
- const parentLabel = token.parent !== undefined ? tsLabelToTfLabel(token.parent) : "related";
188
- const tfLabel = object.kind !== undefined ? `${object.kind}_${parentLabel}_${tsLabelToTfLabel(refName)}` : `${parentLabel}_${tsLabelToTfLabel(refName)}`;
175
+ // Match ei export and every other object-scoped field lookup: the label is
176
+ // based on the provider root type + the ACTUAL root lookup label + field
177
+ // display name. Re-deriving it from the public refName produces a second,
178
+ // semantically identical data block when (for example) a relationship and
179
+ // a dynamic Dropdown both reference the same foreign field.
180
+ const ownerType = object.kind === "element" ? "elementum_element" : object.kind === "app" ? "elementum_app" : undefined;
181
+ const parentLabel = object.foreignTfLabel ?? (token.parent !== undefined ? tsLabelToTfLabel(token.parent) : "related");
182
+ const tfLabel = ownerType === undefined
183
+ ? sanitizeName(`${parentLabel}_${name}`)
184
+ : sanitizeName(`${ownerType}_${parentLabel}_${name}`);
189
185
  opts.orgRefs.foreignField("elementum_field", tfLabel, object.value, name);
190
186
  return expr.dataAttr("elementum_field", tfLabel, ["id"]);
191
187
  }
@@ -214,8 +210,8 @@ function stageOrgRefs(real) {
214
210
  byName: (bag, name) => real.byName(bag, name),
215
211
  foreignSkill: (tfLabel, name, appId) => pending.push(() => real.foreignSkill(tfLabel, name, appId)),
216
212
  rawLookup: (type, tfLabel, value, extraAttrs) => pending.push(() => real.rawLookup(type, tfLabel, value, extraAttrs)),
217
- foreignApp: (tfLabel, name) => pending.push(() => real.foreignApp(tfLabel, name)),
218
- foreignElement: (tfLabel, name) => pending.push(() => real.foreignElement(tfLabel, name)),
213
+ foreignApp: (tfLabel, name, namespace) => pending.push(() => real.foreignApp(tfLabel, name, namespace)),
214
+ foreignElement: (tfLabel, name, namespace) => pending.push(() => real.foreignElement(tfLabel, name, namespace)),
219
215
  foreignField: (type, tfLabel, objectId, name) => pending.push(() => real.foreignField(type, tfLabel, objectId, name)),
220
216
  };
221
217
  return { orgRefs, commit: () => { for (const apply of pending)
@@ -263,6 +259,24 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where) {
263
259
  return undefined;
264
260
  attrs["parent_field_id"] = parentFieldId;
265
261
  }
262
+ if (cfg.parentMappings !== undefined) {
263
+ const mappings = [];
264
+ for (const mapping of cfg.parentMappings) {
265
+ if (mapping.parentAspectFieldId === undefined || mapping.relatedAspectFieldId === undefined) {
266
+ opts.diagnostics.push(`${where}: dynamic parent mapping requires parentAspectFieldId and relatedAspectFieldId; dropped`);
267
+ return undefined;
268
+ }
269
+ const parentMappingObject = resolveDynamicMappingFieldOwner(mapping.parentAspectFieldId, opts, where);
270
+ if (parentMappingObject === undefined)
271
+ return undefined;
272
+ const parentAspectFieldId = resolveFieldOnObject(mapping.parentAspectFieldId, parentMappingObject, opts, where, "parentMappings.parentAspectFieldId");
273
+ const relatedAspectFieldId = resolveFieldOnObject(mapping.relatedAspectFieldId, resolvedObject, opts, where, "parentMappings.relatedAspectFieldId");
274
+ if (parentAspectFieldId === undefined || relatedAspectFieldId === undefined)
275
+ return undefined;
276
+ mappings.push({ parent_aspect_field_id: parentAspectFieldId, related_aspect_field_id: relatedAspectFieldId });
277
+ }
278
+ attrs["parent_mappings"] = mappings;
279
+ }
266
280
  if (cfg.autoRelate !== undefined)
267
281
  attrs["auto_relate"] = cfg.autoRelate;
268
282
  if (cfg.valuesRenderType !== undefined)
@@ -296,32 +310,85 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where) {
296
310
  }
297
311
  }
298
312
  if (cfg.sort !== undefined) {
299
- if (isDynamicPicklistOrdersSort(cfg.sort)) {
300
- const orders = [];
301
- for (const order of cfg.sort.orders) {
302
- const { field, ...rest } = order;
303
- if (field === undefined) {
304
- opts.diagnostics.push(`${where}: sort order has no field; dropped`);
305
- return undefined;
306
- }
307
- const fieldValue = resolveFieldOnObject(field, resolvedObject, opts_, where, "sort field");
308
- if (fieldValue === undefined)
309
- return undefined;
310
- // The platform always echoes `aggregation` back on Read (defaulting
311
- // to null when unset) — send it explicitly so a plan that omitted
312
- // it doesn't mismatch that Read on apply's post-apply consistency
313
- // check (issue #484, round two: the field-id fix alone still left
314
- // planned `{direction,field}` vs. read-back `{aggregation,direction,field}`).
315
- const aggregation = "aggregation" in rest ? rest["aggregation"] : null;
316
- orders.push({ ...rest, aggregation: aggregation, field: fieldValue });
317
- }
318
- attrs["sort"] = expr.jsonencode({ orders });
313
+ const sort = resolveDynamicPicklistSort(cfg.sort, resolvedObject, opts, where);
314
+ if (sort === undefined)
315
+ return undefined;
316
+ attrs["sort"] = expr.jsonencode(sort);
317
+ }
318
+ staged?.commit();
319
+ return attrs;
320
+ }
321
+ /** Resolve the aspect that owns a dynamic parent's source-field mapping. */
322
+ function resolveDynamicMappingFieldOwner(token, opts, where) {
323
+ if (typeof token === "string")
324
+ return { value: "" };
325
+ if (token.parent === opts.appRefName) {
326
+ return {
327
+ value: opts.objectId,
328
+ refName: opts.appRefName,
329
+ kind: opts.scope ?? "app",
330
+ target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
331
+ };
332
+ }
333
+ if (token.parent === undefined || token.parentKind === undefined) {
334
+ opts.diagnostics.push(`${where}: parentSourceField must identify its owning app or element; dropped`);
335
+ return undefined;
336
+ }
337
+ return resolveRelatedObject({
338
+ __kind: token.parentKind,
339
+ refName: token.parent,
340
+ name: token.parentName ?? token.parent,
341
+ }, opts, where);
342
+ }
343
+ function resolveDynamicPicklistSort(sort, relatedObject, opts, where) {
344
+ const orders = sort["orders"];
345
+ if (!Array.isArray(orders))
346
+ return sort;
347
+ const resolved = [];
348
+ for (const order of orders) {
349
+ if (typeof order !== "object" || order === null || Array.isArray(order)) {
350
+ opts.diagnostics.push(`${where}: sort order has an unexpected shape; dropped`);
351
+ return undefined;
319
352
  }
320
- else {
321
- attrs["sort"] = expr.jsonencode(cfg.sort);
353
+ const record = order;
354
+ const fieldToken = record["field"];
355
+ if (fieldToken === undefined) {
356
+ opts.diagnostics.push(`${where}: sort order requires a field; dropped`);
357
+ return undefined;
322
358
  }
359
+ const field = resolveFieldOnObject(fieldToken, relatedObject, opts, where, "sort field");
360
+ if (field === undefined)
361
+ return undefined;
362
+ resolved.push({
363
+ ...Object.fromEntries(Object.entries(record).filter(([key]) => key !== "field")),
364
+ aggregation: (record["aggregation"] ?? null),
365
+ field,
366
+ });
367
+ }
368
+ return { ...sort, orders: resolved };
369
+ }
370
+ function buildStaticPicklistConfigAttr(cfg, opts, where) {
371
+ const attrs = {};
372
+ const owner = {
373
+ value: opts.objectId,
374
+ refName: opts.appRefName,
375
+ kind: opts.scope ?? "app",
376
+ target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
377
+ };
378
+ if (cfg.parentFieldId !== undefined) {
379
+ const parentFieldId = resolveFieldOnObject(cfg.parentFieldId, owner, opts, where, "parentFieldId");
380
+ if (parentFieldId === undefined)
381
+ return undefined;
382
+ attrs["parent_field_id"] = parentFieldId;
383
+ }
384
+ if (cfg.filter !== undefined) {
385
+ opts.diagnostics.push(`${where}: static dropdown filters are not product-authorable; dropped`);
386
+ return undefined;
387
+ }
388
+ if (cfg.sort !== undefined) {
389
+ opts.diagnostics.push(`${where}: static dropdown sort is not product-authorable; dropped`);
390
+ return undefined;
323
391
  }
324
- staged?.commit();
325
392
  return attrs;
326
393
  }
327
394
  /** One custom field → its resource block; undefined = degraded (diagnostic already pushed). */
@@ -333,14 +400,17 @@ export function fieldToTf(typeKey, inner, opts) {
333
400
  diagnostics.push(`field "${name}": field type key "${typeKey}" has no terraform field resource mapping; dropped`);
334
401
  return undefined;
335
402
  }
336
- if (inner.config !== undefined && (subType.hasOptions !== true || inner.config.dynamic === undefined)) {
337
- // Only `hasOptions` fields with a `dynamic` config are supported. That
338
- // excludes non-picklist fields, `config.static`, and any other
339
- // unmodeled config shape (e.g. an `api`/`stage` variant) — all three
340
- // must degrade here, not fall through as if config were absent.
341
- diagnostics.push(`field "${name}": ${subType.hasOptions === true ? "static/dependent" : "dependent/dynamic"} picklist config is not supported by the terraform provider yet; dropped`);
403
+ if (inner.config !== undefined && subType.hasOptions !== true) {
404
+ diagnostics.push(`field "${name}": dependent/dynamic dropdown config is only valid on Dropdown and Multi-Select fields; dropped`);
342
405
  return undefined;
343
406
  }
407
+ if (inner.config !== undefined) {
408
+ const variants = Number(inner.config.dynamic !== undefined) + Number(inner.config.static !== undefined);
409
+ if (variants !== 1) {
410
+ diagnostics.push(`field "${name}": dropdown config requires exactly one of static or dynamic; dropped`);
411
+ return undefined;
412
+ }
413
+ }
344
414
  if (subType.hasOptions === true && inner.config?.dynamic !== undefined && inner.picklistValues !== undefined && inner.picklistValues.length > 0) {
345
415
  diagnostics.push(`field "${name}": config.dynamic and options are mutually exclusive; dropped`);
346
416
  return undefined;
@@ -476,12 +546,63 @@ export function fieldToTf(typeKey, inner, opts) {
476
546
  return undefined;
477
547
  attrs["dynamic_config"] = dynamicConfig;
478
548
  }
549
+ if (subType.hasOptions === true && inner.config?.static !== undefined) {
550
+ const staticConfig = buildStaticPicklistConfigAttr(inner.config.static, opts, `field "${name}"`);
551
+ if (staticConfig === undefined)
552
+ return undefined;
553
+ if (Object.keys(staticConfig).length > 0)
554
+ attrs["static_config"] = staticConfig;
555
+ }
479
556
  if (subType.hasOptions === true && inner.picklistValues !== undefined) {
480
- if (inner.picklistValues.some((pv) => pv.relatedParentValues !== undefined)) {
481
- diagnostics.push(`field "${name}": dependent option links (parentValues) are not supported by the terraform provider yet; dropped`);
482
- }
483
557
  if (inner.picklistValues.length > 0) {
484
- attrs["options"] = inner.picklistValues.map((pv) => ({ label: picklistLabel(pv) }));
558
+ attrs["options"] = inner.picklistValues.map((pv) => {
559
+ const option = { label: picklistLabel(pv) };
560
+ if (pv.color !== undefined)
561
+ option["color"] = pv.color;
562
+ if (pv.icon !== undefined)
563
+ option["icon"] = pv.icon;
564
+ if (pv.active !== undefined)
565
+ option["active"] = pv.active;
566
+ if (pv.tags !== undefined && pv.tags.length > 0)
567
+ option["tags"] = [...pv.tags];
568
+ if (pv.relatedParentValues !== undefined) {
569
+ if (!Array.isArray(pv.relatedParentValues)) {
570
+ diagnostics.push(`field "${name}": option "${picklistLabel(pv)}" parent values are not a list; dropped`);
571
+ }
572
+ else {
573
+ const parentValueIds = [];
574
+ for (const value of pv.relatedParentValues) {
575
+ if (typeof value === "string") {
576
+ parentValueIds.push(value);
577
+ continue;
578
+ }
579
+ if (typeof value !== "object" || value === null || value.__kind !== "dropdownValue") {
580
+ diagnostics.push(`field "${name}": option "${picklistLabel(pv)}" has an invalid parent value reference; dropped`);
581
+ continue;
582
+ }
583
+ const ref = value;
584
+ if (ref.field === undefined || typeof ref.label !== "string") {
585
+ diagnostics.push(`field "${name}": option "${picklistLabel(pv)}" has an incomplete parent value reference; dropped`);
586
+ continue;
587
+ }
588
+ if (ref.field.parent !== undefined && ref.field.parent !== opts.appRefName) {
589
+ diagnostics.push(`field "${name}": static parent values must belong to the same app/element; dropped`);
590
+ continue;
591
+ }
592
+ const parentType = SUB_TYPE_BY_AUTHORING_TYPE.get(ref.field.fieldType ?? "");
593
+ if (parentType?.hasOptions !== true || ref.field.refName === undefined) {
594
+ diagnostics.push(`field "${name}": parent value reference must target a Dropdown or Multi-Select field; dropped`);
595
+ continue;
596
+ }
597
+ const parentTfLabel = scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(ref.field.refName), opts.scope ?? "app");
598
+ parentValueIds.push(expr.local(`${parentTfLabel}_options_by_label`, [{ index: ref.label }]));
599
+ }
600
+ if (parentValueIds.length > 0)
601
+ option["parent_value_ids"] = parentValueIds;
602
+ }
603
+ }
604
+ return option;
605
+ });
485
606
  }
486
607
  }
487
608
  const block = { kind: "resource", type: subType.resourceType, label: tfLabel, attrs };
@@ -66,6 +66,7 @@ export const KNOWN_FIELD_ATTRS = new Set([
66
66
  "related_label_field_id",
67
67
  "auto_relate",
68
68
  "dynamic_config",
69
+ "static_config",
69
70
  "decimal_places",
70
71
  "currency",
71
72
  "percentage",
@@ -74,4 +75,5 @@ export const KNOWN_FIELD_ATTRS = new Set([
74
75
  "calculation_type",
75
76
  "include_type",
76
77
  "picklist_field_id",
78
+ "media_types",
77
79
  ]);
@@ -3,11 +3,6 @@ import { fieldRefToTfValue } from "../field/to-tf.js";
3
3
  import { SUB_TYPE_BY_AUTHORING_TYPE } from "../field/types.js";
4
4
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
5
5
  import { RECORD_CREATE_FORM_RESOURCE_TYPE } from "./module.js";
6
- // The platform export uses Int32 max for its terminal "Other fields"
7
- // position, but a newly created form canonicalizes that value to the actual
8
- // zero-based list position. Sending the sentinel back verbatim therefore
9
- // makes Terraform see an inconsistent post-create value.
10
- const PLATFORM_TERMINAL_DISPLAY_ORDER = 2147483647;
11
6
  /** Typed authoring form -> the provider's immutable sections resource. */
12
7
  export function recordCreateFormToTf(form, opts) {
13
8
  if (form === undefined)
@@ -15,9 +10,11 @@ export function recordCreateFormToTf(form, opts) {
15
10
  const sections = [];
16
11
  for (const [index, section] of (form.sections ?? []).entries()) {
17
12
  const where = `recordCreateForm.sections[${index}]`;
18
- const displayOrder = section.displayOrder === PLATFORM_TERMINAL_DISPLAY_ORDER
19
- ? index
20
- : section.displayOrder ?? index;
13
+ // Emit the authored displayOrder verbatim — including the platform's
14
+ // Int32-max "Other fields" sentinel (2147483647). Rewriting the sentinel
15
+ // to the list index planned a RequiresReplace against adopted Sanofi
16
+ // forms whose state still carries the export value.
17
+ const displayOrder = section.displayOrder ?? index;
21
18
  const attrs = {
22
19
  name: section.name ?? "",
23
20
  field_ids: resolveFields(section.fields ?? [], where, opts),