@elementumai/edk 0.10.1 → 0.10.2

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 (29) hide show
  1. package/dist-sdk/src/entities/app/module.js +2 -1
  2. package/dist-sdk/src/entities/app/to-tf.js +4 -0
  3. package/dist-sdk/src/entities/automation/build.d.ts +2 -0
  4. package/dist-sdk/src/entities/automation/build.js +13 -12
  5. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +39 -16
  6. package/dist-sdk/src/entities/automation/from-tf.js +32 -4
  7. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +21 -0
  8. package/dist-sdk/src/entities/automation/output-key-wire-name.js +38 -0
  9. package/dist-sdk/src/entities/automation/to-tf.js +60 -13
  10. package/dist-sdk/src/entities/element/module.js +2 -1
  11. package/dist-sdk/src/entities/element/to-tf.js +4 -0
  12. package/dist-sdk/src/entities/field/from-tf.js +75 -57
  13. package/dist-sdk/src/entities/field/module.d.ts +6 -0
  14. package/dist-sdk/src/entities/field/module.js +22 -2
  15. package/dist-sdk/src/entities/field/order.d.ts +16 -0
  16. package/dist-sdk/src/entities/field/order.js +41 -0
  17. package/dist-sdk/src/entities/field/types.d.ts +5 -0
  18. package/dist-sdk/src/entities/field/types.js +5 -0
  19. package/dist-sdk/src/entities/task/module.js +2 -1
  20. package/dist-sdk/src/entities/task/to-tf.js +4 -0
  21. package/dist-sdk/src/entities/view/module.js +4 -1
  22. package/dist-sdk/src/entities/view/to-tf.js +11 -3
  23. package/dist-sdk/src/entities/view/types.d.ts +6 -0
  24. package/dist-sdk/src/entities/view/types.js +6 -0
  25. package/dist-sdk/src/graph/index.d.ts +3 -2
  26. package/dist-sdk/src/graph/index.js +3 -0
  27. package/dist-sdk/src/graph/modules.js +2 -1
  28. package/dist-sdk/src/graph/types.d.ts +13 -1
  29. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  /** The app entity's graph module + resource-type constant (see src/graph/). */
2
+ import { inManagedFieldOrder } from "../field/order.js";
2
3
  import { NO_CATALOG, } from "../../graph/types.js";
3
4
  import { appendFieldLocals } from "../field/locals.js";
4
5
  import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, LAYOUT_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE } from "../view/types.js";
@@ -12,7 +13,7 @@ function extractAppStreamRoot(stream, ctx) {
12
13
  throw new Error(`expected exactly one ${APP_RESOURCE_TYPE} resource in the export stream, found ${appBlocks.length}` +
13
14
  (appBlocks.length > 1 ? " — was this exported with --recursive?" : ""));
14
15
  }
15
- const fieldBlocks = stream.byKind.get("field") ?? [];
16
+ const fieldBlocks = inManagedFieldOrder(stream.byKind.get("field") ?? [], stream.byKind.get("managed-field-order") ?? []);
16
17
  const viewBlocks = stream.byKind.get("view") ?? [];
17
18
  const layoutBlocks = viewBlocks.filter((b) => b.type === LAYOUT_RESOURCE_TYPE);
18
19
  const listViewBlocks = viewBlocks.filter((b) => b.type === LIST_VIEW_RESOURCE_TYPE);
@@ -14,6 +14,7 @@
14
14
  * Unsupported authoring shapes degrade through `diagnostics` — reported,
15
15
  * never silent, never thrown (plan §4.3).
16
16
  */
17
+ import { managedFieldOrderToTf } from "../field/order.js";
17
18
  import { typedCoverageGap } from "../../engine/coverage-gaps.js";
18
19
  import { autoShareToTf } from "./auto-share.js";
19
20
  import { workspaceAspectKey } from "../../engine/build/context.js";
@@ -241,6 +242,9 @@ export function appToTf(entity, ctx) {
241
242
  blocks.push(field.block);
242
243
  fieldAddresses.set(field.bagKey, field.address);
243
244
  }
245
+ const fieldOrder = managedFieldOrderToTf(ctx.appTfLabel, "app", objectId, fieldAddresses);
246
+ if (fieldOrder !== undefined)
247
+ blocks.push(fieldOrder);
244
248
  if (Object.keys(systemFieldConfig).length > 0) {
245
249
  appAttrs["system_field_config"] = systemFieldConfig;
246
250
  }
@@ -234,6 +234,8 @@ interface ActionMethods<TTrigger, TActions extends Record<string, unknown>, TVar
234
234
  }, displayName?: string, hclParent?: "trigger" | string): WithAction<TMode, TItem, TTrigger, TActions, TVars, TName, {
235
235
  result: R;
236
236
  textResult: string;
237
+ stringArrayResult: readonly string[];
238
+ numberArrayResult: readonly number[];
237
239
  }>;
238
240
  /**
239
241
  * Fluent setVariable: one variable, named the same as its action — read
@@ -229,8 +229,12 @@ function assertKnownSearchOutput(taskKey, wireNames, name, taskRefKey) {
229
229
  const outputs = Object.keys(wireNames).join(", ");
230
230
  throw new EntityTfError(`${taskKey}${taskRefKey === undefined ? "" : ` task "${taskRefKey}"`} has no output "${name}"; its outputs are ${outputs}.`);
231
231
  }
232
- /** Canonical service_tasks names. They are not authoring accessors. */
233
- const EXECUTE_SCRIPT_CANONICAL_OUTPUT_NAMES = new Set(["stringArrayResult", "numberArrayResult"]);
232
+ /**
233
+ * Contract outputs that are not schema properties under `result`.
234
+ * `stringArrayResult` / `numberArrayResult` are real reads (a filter's
235
+ * `task.<id>.stringArrayResult`), not a missing `.result.` hop (#1656).
236
+ */
237
+ const EXECUTE_SCRIPT_CONTRACT_OUTPUT_NAMES = new Set(["stringArrayResult", "numberArrayResult"]);
234
238
  /**
235
239
  * Top-level property names on a wire `output_schema` object. `undefined` means
236
240
  * the script declared no schema, so a `result.<prop>` cannot be checked.
@@ -261,15 +265,12 @@ function declaredScriptResultProperties(schema) {
261
265
  * `ctx.actions.<script>.<name>` would compile to a `refs["<name>"]` key the
262
266
  * platform never sets, so apply fails with "Invalid index". When the script
263
267
  * declares an output schema, `result.<prop>` is checked against that schema
264
- * too. Authoring names are `result`, `textResult`, and `result.<prop>`.
265
- * `Text Result` is the refs-map key `textResult` rewrites to, not a name
266
- * someone authors. The canonical publish path also accepts the service_tasks
267
- * contract names.
268
+ * too. Authoring names are `result`, `textResult`, `stringArrayResult`,
269
+ * `numberArrayResult`, and `result.<prop>`. `Text Result` / `Result` /
270
+ * `Text List Result` are refs-map keys, not names someone authors (#1656).
268
271
  */
269
- function assertKnownScriptOutput(name, taskRefKey, schema, canonical, checkDeclaredResult) {
270
- if (name === "result" || name === "textResult")
271
- return;
272
- if (canonical && EXECUTE_SCRIPT_CANONICAL_OUTPUT_NAMES.has(name))
272
+ function assertKnownScriptOutput(name, taskRefKey, schema, checkDeclaredResult) {
273
+ if (name === "result" || name === "textResult" || EXECUTE_SCRIPT_CONTRACT_OUTPUT_NAMES.has(name))
273
274
  return;
274
275
  if (name.startsWith("result.")) {
275
276
  // Filter `{type:"TASK"}` shapes are not refs-map reads. A switch left_value
@@ -335,7 +336,7 @@ function rewriteForwardTaskRefName(taskKey, name, taskRefKey, schema, checkDecla
335
336
  return USER_SEARCH_REF_WIRE_NAMES[name] ?? name;
336
337
  }
337
338
  if (taskKey === "executeScript") {
338
- assertKnownScriptOutput(name, taskRefKey, schema, false, checkDeclaredScriptResult);
339
+ assertKnownScriptOutput(name, taskRefKey, schema, checkDeclaredScriptResult);
339
340
  if (name === "textResult")
340
341
  return "Text Result";
341
342
  }
@@ -380,7 +381,7 @@ export function rewriteCanonicalOutputRefName(taskKey, name, taskRefKey, schema)
380
381
  throw findRelatedRecordsTotalCountError(taskRefKey);
381
382
  }
382
383
  if (taskKey === "executeScript")
383
- assertKnownScriptOutput(name, taskRefKey, schema, true, true);
384
+ assertKnownScriptOutput(name, taskRefKey, schema, true);
384
385
  if (taskKey === "api" && name.startsWith("file.")) {
385
386
  // apiRequest's file SUB-refs (.file.content / .contentType / .name) have no
386
387
  // canonical service_tasks output name of their own — they resolve by the
@@ -1419,9 +1419,19 @@ function printFieldAssignments(values, target, state, indent, refCtx) {
1419
1419
  fieldExpr = `catalog.${foreignOwner}.fields${safeMember(rawKey)}`;
1420
1420
  }
1421
1421
  else if (!isUuid(rawKey)) {
1422
- // A bag key with no known owner and type is not a TEXT field. Inventing
1423
- // one makes the next build address elementum_text_field.
1424
- fieldExpr = `/* unresolved field ${quote(rawKey)} */ null`;
1422
+ const platformFieldId = assignment?.platformFieldId;
1423
+ if (platformFieldId !== undefined && isUuid(platformFieldId)) {
1424
+ // The key was rewritten from a platform id whose owner is not in
1425
+ // this workspace. Keep that id. A null field fails to load, and a
1426
+ // guessed TEXT stub builds elementum_text_field.
1427
+ state.imports.usesUnsafePlatformId = true;
1428
+ fieldExpr = `unsafePlatformId(${quote(platformFieldId)})`;
1429
+ }
1430
+ else {
1431
+ // A bag key with no known owner and type is not a TEXT field. Inventing
1432
+ // one makes the next build address elementum_text_field.
1433
+ fieldExpr = `/* unresolved field ${quote(rawKey)} */ null`;
1434
+ }
1425
1435
  }
1426
1436
  else {
1427
1437
  state.imports.usesUnsafePlatformId = true;
@@ -1455,10 +1465,10 @@ function taskPrimaryTarget(args, state) {
1455
1465
  return { kind: "task", refName, name: v.name ?? refName, inCatalog: foreignRefName !== undefined };
1456
1466
  }
1457
1467
  if (v.entityType === "element") {
1458
- const foreignRefName = v.name !== undefined ? state.foreignElementRefNames?.get(v.name) : undefined;
1468
+ const foreignRefName = workspaceAspectRefName(state, "element", v.name, v.namespace);
1459
1469
  return { kind: "element", refName: foreignRefName ?? v.appHandle, name: v.name, inCatalog: v.name === undefined || foreignRefName !== undefined };
1460
1470
  }
1461
- const foreignRefName = v.name !== undefined ? state.foreignAppRefNames?.get(v.name) : undefined;
1471
+ const foreignRefName = workspaceAspectRefName(state, "app", v.name, v.namespace);
1462
1472
  const refName = foreignRefName ?? catalogOwnerHandle(state, v.appHandle);
1463
1473
  return { kind: "app", refName, name: v.name, inCatalog: v.entityType === undefined || v.name === undefined || foreignRefName !== undefined };
1464
1474
  }
@@ -1483,6 +1493,23 @@ function taskPrimaryTarget(args, state) {
1483
1493
  }
1484
1494
  return undefined;
1485
1495
  }
1496
+ /**
1497
+ * The workspace catalog key for a foreign app/element ref: by namespace, then
1498
+ * display name. A namespace-only data block's ref carries the namespace as
1499
+ * its name, so the name map alone misses it.
1500
+ */
1501
+ function workspaceAspectRefName(state, kind, name, namespace) {
1502
+ const namespaces = kind === "app" ? state.foreignAppRefNamespaces : state.foreignElementRefNamespaces;
1503
+ const names = kind === "app" ? state.foreignAppRefNames : state.foreignElementRefNames;
1504
+ return (namespace !== undefined ? namespaces?.get(namespace) : undefined)
1505
+ ?? (name !== undefined ? names?.get(name) : undefined);
1506
+ }
1507
+ /** The pulled field registry names a field's owner by its catalog key, not its platform name. */
1508
+ function isWorkspaceAspectRefName(state, kind, refName) {
1509
+ const namespaces = kind === "app" ? state.foreignAppRefNamespaces : state.foreignElementRefNamespaces;
1510
+ const names = kind === "app" ? state.foreignAppRefNames : state.foreignElementRefNames;
1511
+ return [...(namespaces?.values() ?? []), ...(names?.values() ?? [])].includes(refName);
1512
+ }
1486
1513
  // ---------------------------------------------------------------------------
1487
1514
  // Argument value printer — dispatches on runtime shape
1488
1515
  // ---------------------------------------------------------------------------
@@ -1677,14 +1704,12 @@ function printRef(ref, state, refCtx) {
1677
1704
  // pulled into this workspace (board issue #40, app-only) resolves to a
1678
1705
  // typed token; otherwise a literal stub (field type is unconfirmed —
1679
1706
  // ei's `elementum_field` data source doesn't expose it).
1680
- const namespace = ref.foreign.namespace;
1681
- const foreignRefName = ref.foreign.entityType === "element"
1682
- ? (namespace !== undefined ? state.foreignElementRefNamespaces?.get(namespace) : undefined) ?? state.foreignElementRefNames?.get(ref.foreign.name)
1707
+ const foreignRefName = ref.foreign.entityType === "element" || ref.foreign.entityType === "app"
1708
+ ? workspaceAspectRefName(state, ref.foreign.entityType, ref.foreign.name, ref.foreign.namespace) ??
1709
+ (isWorkspaceAspectRefName(state, ref.foreign.entityType, ref.appHandle) ? ref.appHandle : undefined)
1683
1710
  : ref.foreign.entityType === "task"
1684
1711
  ? state.foreignTaskRefNames?.get(ref.foreign.name)
1685
- : ref.foreign.entityType === "app"
1686
- ? (namespace !== undefined ? state.foreignAppRefNamespaces?.get(namespace) : undefined) ?? state.foreignAppRefNames?.get(ref.foreign.name)
1687
- : undefined;
1712
+ : undefined;
1688
1713
  if (ref.foreign.entityType === "task") {
1689
1714
  const parentRef = foreignRefName ?? ref.appHandle;
1690
1715
  const fieldType = ref.foreign.fieldType ?? "TEXT";
@@ -1716,13 +1741,11 @@ function printRef(ref, state, refCtx) {
1716
1741
  if (ref.entityType === undefined || ref.name === undefined) {
1717
1742
  return `catalog.${catalogOwnerHandle(state, ref.appHandle)}`;
1718
1743
  }
1719
- const foreignRefName = ref.entityType === "element"
1720
- ? state.foreignElementRefNames?.get(ref.name)
1744
+ const foreignRefName = ref.entityType === "element" || ref.entityType === "app"
1745
+ ? workspaceAspectRefName(state, ref.entityType, ref.name, ref.namespace)
1721
1746
  : ref.entityType === "task"
1722
1747
  ? state.foreignTaskRefNames?.get(ref.name)
1723
- : ref.entityType === "app"
1724
- ? state.foreignAppRefNames?.get(ref.name)
1725
- : undefined;
1748
+ : undefined;
1726
1749
  if (foreignRefName !== undefined)
1727
1750
  return `catalog.${foreignRefName}`;
1728
1751
  const namespace = ref.namespace !== undefined ? `, namespace: ${quote(ref.namespace)}` : "";
@@ -4,7 +4,7 @@ import { normalizeOnDemandParamKey } from "../../../pull/util.js";
4
4
  import { EntityTfError } from "../../engine/entity.js";
5
5
  import { dataRefLabel } from "../../engine/pull/context.js";
6
6
  import { procedureDiscriminator } from "../../engine/pull/procedure-refs.js";
7
- import { appResourceLabelPrefix, childPartFromScopedLabel, elementResourceLabelPrefix, isTfExpr, isTfLabel, ownerFromScopedChildLabel, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
7
+ import { appResourceLabelPrefix, childPartFromScopedLabel, elementResourceLabelPrefix, isTfExpr, isTfLabel, isUuid, ownerFromScopedChildLabel, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
8
8
  import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
9
9
  import { IMPLEMENTED_FILE_READER_RESOURCE_TYPES } from "../file-reader/types.js";
10
10
  import { connectorIdentityFromTf } from "../shared/connector-from-tf.js";
@@ -14,7 +14,7 @@ import { filterFromTf as deserializeFilterFromTf } from "../shared/filters/tf-co
14
14
  import { TABLE_RESOURCE_TYPE } from "../table/module.js";
15
15
  import { SEARCH_TABLE_RESOURCE_TYPES } from "../search-table/types.js";
16
16
  import { outputFieldTypesFromScriptSchema, repeatedScriptOutputNames, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
17
- import { apiTaskRefAuthoringPath, matchesOutputWireKey, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
17
+ import { apiTaskRefAuthoringPath, executeScriptAuthoringPath, matchesOutputWireKey, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
18
18
  import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
19
19
  import { systemRefNameRoundTrips } from "./system-ref-name.js";
20
20
  import { taskTfLabel } from "./task-label.js";
@@ -597,7 +597,13 @@ const TASK_OUTPUT_LABEL_TO_TS = {
597
597
  elementum_record_search_task: { "First found record": ["record"] },
598
598
  elementum_create_record_task: { "Created record": ["record"] },
599
599
  elementum_update_field_task: { "Updated record": ["record"] },
600
- elementum_execute_script_task: { "Text Result": ["textResult"] },
600
+ elementum_execute_script_task: {
601
+ // Display keys. Canonical `result` / `stringArrayResult` are not refs keys;
602
+ // `Result` is the whole JSON envelope, not a property named Result (#1656).
603
+ Result: ["result"],
604
+ "Text Result": ["textResult"],
605
+ "Text List Result": ["stringArrayResult"],
606
+ },
601
607
  elementum_user_search_task: {
602
608
  "Users Size": ["count"],
603
609
  "User's Id": ["user", "id"],
@@ -1304,6 +1310,14 @@ function decodeTaskReferenceFromString(taskIdOrKey, pathSegments, ctx) {
1304
1310
  return { kind: "taskRef", task: refKey, path: apiPath };
1305
1311
  }
1306
1312
  }
1313
+ // Exact contract names only. `result.passed` is two segments and stays a
1314
+ // property; `Result` is the whole JSON envelope (#1656).
1315
+ if (block?.type === "elementum_execute_script_task" && pathSegments.length === 1) {
1316
+ const scriptPath = executeScriptAuthoringPath(pathSegments[0]);
1317
+ if (scriptPath !== undefined) {
1318
+ return { kind: "taskRef", task: refKey, path: [...scriptPath] };
1319
+ }
1320
+ }
1307
1321
  const keyPath = pathSegments.map((segment) => WIRE_REF_SEGMENT_TO_TS[segment] ?? segment);
1308
1322
  const taskKind = block?.type !== undefined ? TASK_FACTORIES[block.type] : undefined;
1309
1323
  const wireOutputKey = taskKind !== undefined ? OUTPUT_KEY_WIRE_NAME[taskKind] : undefined;
@@ -2503,6 +2517,11 @@ function decodeCalculationTaskMustache(taskId, wireName, ctx) {
2503
2517
  return { kind: "taskRef", task: refKey, path: apiPath };
2504
2518
  }
2505
2519
  }
2520
+ if (taskBlock?.type === "elementum_execute_script_task") {
2521
+ const scriptPath = executeScriptAuthoringPath(wireName);
2522
+ if (scriptPath !== undefined)
2523
+ return { kind: "taskRef", task: refKey, path: [...scriptPath] };
2524
+ }
2506
2525
  const keyPath = wireName.split(".");
2507
2526
  const taskKind = taskBlock?.type !== undefined ? TASK_FACTORIES[taskBlock.type] : undefined;
2508
2527
  const wireOutputKey = taskKind !== undefined ? OUTPUT_KEY_WIRE_NAME[taskKind] : undefined;
@@ -2972,12 +2991,21 @@ function taskArgs(block, factory, ctx, taskDiagnostics) {
2972
2991
  ...(field.foreign.fieldType !== undefined ? { foreignFieldType: field.foreign.fieldType } : {}),
2973
2992
  }
2974
2993
  : undefined;
2975
- values[fieldKey] = item.update_mode === "add" || foreignInfo !== undefined
2994
+ // State can rename a foreign system-field id (Title) to its key
2995
+ // without a field type. The target aspect may still be outside this
2996
+ // workspace, and a bare key then prints as null and the file will
2997
+ // not load. Keep the platform id so the printer can emit
2998
+ // unsafePlatformId, which is what an element-only pull already does.
2999
+ const platformFieldId = typeof item.field_id === "string" && isUuid(item.field_id) && field.kind === "field" && field.fieldKey !== item.field_id
3000
+ ? item.field_id
3001
+ : undefined;
3002
+ values[fieldKey] = item.update_mode === "add" || foreignInfo !== undefined || platformFieldId !== undefined
2976
3003
  ? {
2977
3004
  __fieldAssignment: true,
2978
3005
  value: decodedValue,
2979
3006
  ...(item.update_mode === "add" ? { updateMode: "add" } : {}),
2980
3007
  ...(foreignInfo !== undefined ? foreignInfo : {}),
3008
+ ...(platformFieldId !== undefined ? { platformFieldId } : {}),
2981
3009
  }
2982
3010
  : decodedValue;
2983
3011
  }
@@ -62,3 +62,24 @@ export declare const API_TASK_REF_AUTHORING_NAMES: Readonly<Record<string, strin
62
62
  * callers can fall back to the generic segment mapping.
63
63
  */
64
64
  export declare function apiTaskRefAuthoringPath(wireSegment: string): string[] | undefined;
65
+ /**
66
+ * executeScript contract outputs whose authoring name is not the refs-map key.
67
+ *
68
+ * Live provider state (UA Activity) keys the whole JSON result as `Result`
69
+ * and the text-list contract output as `Text List Result`. The canonical
70
+ * taskReference names — and the accessors EDK authors — stay `result` and
71
+ * `stringArrayResult`. Property refs stay `result.<prop>` on both sides, so
72
+ * this table is exact keys only: `result.passed` must not become `Result.passed`.
73
+ * `numberArrayResult` is already the refs key. A variable named `Result` is a
74
+ * different resource and must not use this table.
75
+ */
76
+ export declare const EXECUTE_SCRIPT_REFS_INDEX: Readonly<Record<string, string>>;
77
+ /** Inverse of {@link EXECUTE_SCRIPT_REFS_INDEX}, plus the canonical names themselves. */
78
+ export declare const EXECUTE_SCRIPT_REF_AUTHORING_PATH: Readonly<Record<string, readonly string[]>>;
79
+ /** refs-map key for one executeScript contract output, or undefined when `name` is not one. */
80
+ export declare function executeScriptRefsIndex(name: string): string | undefined;
81
+ /**
82
+ * Authoring path for an executeScript refs key or canonical output name.
83
+ * Undefined for `result.<prop>` and for any other task's output.
84
+ */
85
+ export declare function executeScriptAuthoringPath(name: string): readonly string[] | undefined;
@@ -84,3 +84,41 @@ export function apiTaskRefAuthoringPath(wireSegment) {
84
84
  const authoring = API_TASK_REF_AUTHORING_NAMES[wireSegment];
85
85
  return authoring !== undefined ? authoring.split(".") : undefined;
86
86
  }
87
+ /**
88
+ * executeScript contract outputs whose authoring name is not the refs-map key.
89
+ *
90
+ * Live provider state (UA Activity) keys the whole JSON result as `Result`
91
+ * and the text-list contract output as `Text List Result`. The canonical
92
+ * taskReference names — and the accessors EDK authors — stay `result` and
93
+ * `stringArrayResult`. Property refs stay `result.<prop>` on both sides, so
94
+ * this table is exact keys only: `result.passed` must not become `Result.passed`.
95
+ * `numberArrayResult` is already the refs key. A variable named `Result` is a
96
+ * different resource and must not use this table.
97
+ */
98
+ export const EXECUTE_SCRIPT_REFS_INDEX = {
99
+ result: "Result",
100
+ textResult: "Text Result",
101
+ stringArrayResult: "Text List Result",
102
+ numberArrayResult: "numberArrayResult",
103
+ };
104
+ /** Inverse of {@link EXECUTE_SCRIPT_REFS_INDEX}, plus the canonical names themselves. */
105
+ export const EXECUTE_SCRIPT_REF_AUTHORING_PATH = {
106
+ Result: ["result"],
107
+ result: ["result"],
108
+ "Text Result": ["textResult"],
109
+ textResult: ["textResult"],
110
+ "Text List Result": ["stringArrayResult"],
111
+ stringArrayResult: ["stringArrayResult"],
112
+ numberArrayResult: ["numberArrayResult"],
113
+ };
114
+ /** refs-map key for one executeScript contract output, or undefined when `name` is not one. */
115
+ export function executeScriptRefsIndex(name) {
116
+ return EXECUTE_SCRIPT_REFS_INDEX[name];
117
+ }
118
+ /**
119
+ * Authoring path for an executeScript refs key or canonical output name.
120
+ * Undefined for `result.<prop>` and for any other task's output.
121
+ */
122
+ export function executeScriptAuthoringPath(name) {
123
+ return EXECUTE_SCRIPT_REF_AUTHORING_PATH[name];
124
+ }
@@ -11,7 +11,7 @@ import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
11
11
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
12
12
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
13
13
  import { referenceValueTypeForField } from "../shared/filters/index.js";
14
- import { API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
14
+ import { API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES, executeScriptRefsIndex, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
15
15
  import { outputFieldTypesFromScriptSchema, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
16
16
  import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
17
17
  import { CONNECTOR_ORG_BAG } from "../org/connector.js";
@@ -501,6 +501,19 @@ function registerForeignFieldLookup(value, ctx, dataBlocks) {
501
501
  registerForeignOptionsByLabelLocal(fieldLabel, ctx);
502
502
  return fieldLabel;
503
503
  }
504
+ /**
505
+ * A bare platform-id target whose every input names a raw parameter id is a
506
+ * static run: pull prints a static export with an undiscovered target
507
+ * (`target_automation_id` + `input_mappings[].parameter_id`) as
508
+ * `automation: "<uuid>"` + `inputs[].name: "<uuid>"`. Dynamic mappings name
509
+ * the target's inputs, never a parameter id.
510
+ */
511
+ function bareStaticRunTarget(config) {
512
+ return typeof config.targetAutomationId === "string" &&
513
+ Array.isArray(config.inputMappings) &&
514
+ config.inputMappings.length > 0 &&
515
+ config.inputMappings.every((mapping) => isObject(mapping) && typeof mapping.name === "string" && isUuid(mapping.name));
516
+ }
504
517
  /**
505
518
  * Resolve an automation token as a managed definition (same stream root or a
506
519
  * sibling root in this build) or as a ref-only `data.elementum_automation`
@@ -1663,6 +1676,13 @@ function taskOutputWireRefKey(targetType, name, taskRefKey, refs) {
1663
1676
  (name === "records" || name === "All matching table rows")) {
1664
1677
  return "All matching table rows";
1665
1678
  }
1679
+ // refs index only. Envelopes and calc mustaches keep the canonical name
1680
+ // (`result`, `stringArrayResult`); the provider refs map does not (#1656).
1681
+ if (targetType === "elementum_execute_script_task") {
1682
+ const scriptIndex = executeScriptRefsIndex(name);
1683
+ if (scriptIndex !== undefined)
1684
+ return scriptIndex;
1685
+ }
1666
1686
  return taskWireRefName(name, taskRefKey, refs);
1667
1687
  }
1668
1688
  /** The platform's own on-demand "Triggered By" refs (live refs-map keys). */
@@ -2315,7 +2335,7 @@ function valueToTf(value, refs) {
2315
2335
  ? refs.owner
2316
2336
  : recordOwnerContext(refs.owner, sourceApp, taskTargetKind(source, refs), sourceApp === refs.owner.appRefName
2317
2337
  ? refs.owner.fieldNames
2318
- : fieldNamesForAppRefName(refs.fieldNamesByAppRefName, sourceApp) ?? refs.owner.fieldNames), refs.recordItemForEachRefKeys.has(value.forEachReference.forEachTaskRefKey));
2338
+ : fieldNamesForAppRefName(refs.fieldNamesByAppRefName, sourceApp)), refs.recordItemForEachRefKeys.has(value.forEachReference.forEachTaskRefKey));
2319
2339
  return expr.resourceAttr(target.type, target.label, ["inner", "refs", { index }]);
2320
2340
  }
2321
2341
  if (isObject(value.templateReference))
@@ -2422,6 +2442,7 @@ function canonicalSingleOutputName(resourceType, wireName) {
2422
2442
  return undefined;
2423
2443
  return OUTPUT_KEY_CANONICAL[taskKey];
2424
2444
  }
2445
+ const TRIGGER_REFERENCE_NAME_PATTERN = /^[a-z][A-Za-z0-9]*(?:\.[a-z][A-Za-z0-9]*)*$/;
2425
2446
  function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2426
2447
  // Raw pass-through for a filter left side the pull-time deserializer
2427
2448
  // couldn't decode to a typed ref (filter.ts's leftDescriptor, matching the
@@ -2546,6 +2567,13 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2546
2567
  }
2547
2568
  return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["filter_refs", { index: triggerRefKey }]);
2548
2569
  }
2570
+ // `refs` is keyed by display label. A camelCase path with no display
2571
+ // mapping is the platform's own reference name (`approver.id`, which
2572
+ // `refs` labels "Final Approval By's id"); the short form is how
2573
+ // export and provider Read spell it.
2574
+ if (triggerRefKey === value.name && TRIGGER_REFERENCE_NAME_PATTERN.test(value.name)) {
2575
+ return `trigger.${value.name}`;
2576
+ }
2549
2577
  return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index: triggerRefKey }]);
2550
2578
  }
2551
2579
  case "TASK": {
@@ -2625,17 +2653,24 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2625
2653
  },
2626
2654
  });
2627
2655
  }
2628
- // A text comparison of a boolean, integer, or script-number output
2629
- // stores a TEXT envelope, while `refs` carries the declared type.
2630
- // A script `number` output is declared DECIMAL; NUMBER is the integer
2631
- // projection. Id-typed outputs keep their own type.
2656
+ // Provider Read types a left-value envelope by the comparison's
2657
+ // `real_type` when that differs from the output's declared type: a
2658
+ // text check of a BOOLEAN, NUMBER, or DECIMAL output (#1442), and a
2659
+ // text or uuid check of an ASPECT_RECORD_ID record id (#1569).
2660
+ // `multiple` follows the declaration so an array output is not
2661
+ // flattened. A NUMBER comparison of a DECIMAL script output is the
2662
+ // next branch (#1618).
2632
2663
  const envelopeName = TASK_OUTPUT_REFERENCE_NAMES[task.type]?.[wireName] ?? wireName;
2633
2664
  const executor = RESOURCE_TYPE_TO_EXECUTOR[task.type];
2634
2665
  const declared = task.outputFieldTypes?.get(wireName) ??
2635
2666
  (executor === undefined ? undefined : TASK_OUTPUT_CONTRACTS[executor]?.[envelopeName]);
2636
- if (realType?.toUpperCase() === "TEXT" && (declared?.fieldType === "BOOLEAN" || declared?.fieldType === "NUMBER" || declared?.fieldType === "DECIMAL")) {
2667
+ const compared = realType?.toUpperCase();
2668
+ if (compared !== undefined &&
2669
+ declared !== undefined &&
2670
+ declared.fieldType !== compared &&
2671
+ !(compared === "NUMBER" && declared.fieldType === "DECIMAL")) {
2637
2672
  return expr.jsonencode({
2638
- fieldType: "TEXT",
2673
+ fieldType: compared,
2639
2674
  multiple: declared.multiple,
2640
2675
  taskReference: {
2641
2676
  name: envelopeName,
@@ -2702,7 +2737,10 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
2702
2737
  },
2703
2738
  });
2704
2739
  }
2705
- return expr.resourceAttr(task.type, task.label, ["refs", { index: wireName }]);
2740
+ const refsIndex = task.type === TASK_RESOURCES.executeScript
2741
+ ? executeScriptRefsIndex(wireName) ?? wireName
2742
+ : wireName;
2743
+ return expr.resourceAttr(task.type, task.label, ["refs", { index: refsIndex }]);
2706
2744
  }
2707
2745
  const recordFieldName = foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs);
2708
2746
  // The short form addresses user-search outputs by path, and an AI task's
@@ -2931,10 +2969,10 @@ function filterToTf(value, refs) {
2931
2969
  }
2932
2970
  /**
2933
2971
  * System fields a record-updated trigger cannot meaningfully watch: these never
2934
- * change after create, or change on every update. Closed At and Closed By change
2935
- * once, on close, and the platform stores them in changed_fields.
2972
+ * change after create, or change on every update. The platform stores ID,
2973
+ * Closed At and Closed By in changed_fields, so they round-trip.
2936
2974
  */
2937
- const UNWATCHABLE_SYSTEM_FIELD_KEYS = new Set(["id", "createdAt", "createdBy", "updatedAt", "updatedBy"]);
2975
+ const UNWATCHABLE_SYSTEM_FIELD_KEYS = new Set(["createdAt", "createdBy", "updatedAt", "updatedBy"]);
2938
2976
  function isRunAutomationValueReference(raw) {
2939
2977
  if (!isObject(raw))
2940
2978
  return false;
@@ -3019,6 +3057,15 @@ function configAttrs(kind, config, refs) {
3019
3057
  if (!Array.isArray(raw))
3020
3058
  throw new EntityTfError("runAutomation inputMappings must be an array");
3021
3059
  const target = token(config.targetAutomationId);
3060
+ if (bareStaticRunTarget(config)) {
3061
+ attrs.input_mappings = raw.map((mapping) => {
3062
+ if (!isObject(mapping) || typeof mapping.name !== "string" || mapping.value === undefined) {
3063
+ throw new EntityTfError("runAutomation input mapping requires name and value");
3064
+ }
3065
+ return { parameter_id: mapping.name, value: valueToTf(mapping.value, refs) };
3066
+ });
3067
+ continue;
3068
+ }
3022
3069
  if (target?.__kind !== "automation") {
3023
3070
  attrs.dynamic_input_mappings = raw.map((mapping) => {
3024
3071
  if (!isObject(mapping) || typeof mapping.name !== "string" || mapping.value === undefined) {
@@ -3085,7 +3132,7 @@ function configAttrs(kind, config, refs) {
3085
3132
  continue;
3086
3133
  }
3087
3134
  if (typeof raw === "string" && raw !== "") {
3088
- attrs[Array.isArray(config.inputMappings) && config.inputMappings.length > 0
3135
+ attrs[Array.isArray(config.inputMappings) && config.inputMappings.length > 0 && !bareStaticRunTarget(config)
3089
3136
  ? "target_automation_ref"
3090
3137
  : "target_automation_id"] = raw;
3091
3138
  refs.owner.diagnostics?.push(`runAutomation: target automation ${JSON.stringify(raw)} is unresolved; emitted as bare id`);
@@ -3,6 +3,7 @@
3
3
  * Offline extract/build and live `edk pull element` (via `ei elements export
4
4
  * --directory` with fields/imports/adoption flags).
5
5
  */
6
+ import { inManagedFieldOrder } from "../field/order.js";
6
7
  import { NO_CATALOG, } from "../../graph/types.js";
7
8
  import { appendFieldLocals } from "../field/locals.js";
8
9
  import { CALENDAR_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, LAYOUT_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE } from "../view/types.js";
@@ -16,7 +17,7 @@ function extractElementStreamRoot(stream, ctx) {
16
17
  throw new Error(`expected exactly one ${ELEMENT_RESOURCE_TYPE} resource in the export stream, found ${elementBlocks.length}` +
17
18
  (elementBlocks.length > 1 ? " — was this exported with --recursive?" : ""));
18
19
  }
19
- const fieldBlocks = stream.byKind.get("field") ?? [];
20
+ const fieldBlocks = inManagedFieldOrder(stream.byKind.get("field") ?? [], stream.byKind.get("managed-field-order") ?? []);
20
21
  const viewBlocks = stream.byKind.get("view") ?? [];
21
22
  const layoutBlocks = viewBlocks.filter((b) => b.type === LAYOUT_RESOURCE_TYPE);
22
23
  const listViewBlocks = viewBlocks.filter((b) => b.type === LIST_VIEW_RESOURCE_TYPE);
@@ -3,6 +3,7 @@
3
3
  * field resources in ei's dialect. No status_options/stages (apps always
4
4
  * emit those; element captures do not).
5
5
  */
6
+ import { managedFieldOrderToTf } from "../field/order.js";
6
7
  import { autoShareToTf } from "../app/auto-share.js";
7
8
  import { EntityTfError } from "../../engine/entity.js";
8
9
  import { expr, snakeSlug } from "../../engine/tf/index.js";
@@ -191,6 +192,9 @@ export function elementToTf(entity, ctx) {
191
192
  blocks.push(field.block);
192
193
  fieldAddresses.set(field.bagKey, field.address);
193
194
  }
195
+ const fieldOrder = managedFieldOrderToTf(ctx.appTfLabel, "element", objectId, fieldAddresses);
196
+ if (fieldOrder !== undefined)
197
+ blocks.push(fieldOrder);
194
198
  blocks.push(...dashboardsToTf(payload.dashboards, {
195
199
  ownerTfLabel: ctx.appTfLabel,
196
200
  scope: "element",
@@ -16,6 +16,7 @@ import { optionsFromTf } from "./options.js";
16
16
  import { isCalculationResultType } from "./calculation-types.js";
17
17
  import { KNOWN_FIELD_ATTRS, SUB_TYPE_BY_RESOURCE } from "./types.js";
18
18
  import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
19
+ import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
19
20
  const ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_AUDIT_SYSTEM_FIELD_KEYS);
20
21
  /**
21
22
  * A related_object_id/related_label_field_id value → its raw platform id, if
@@ -35,23 +36,10 @@ function resolveRelatedId(v, ctx) {
35
36
  return undefined;
36
37
  }
37
38
  /**
38
- * `related_object_id` specifically (not `related_label_field_id`, which
39
- * names a field and has no equivalent name-based recovery) gets one more
40
- * fallback beyond `resolveRelatedId`: a `data.elementum_app.<label>` /
41
- * `data.elementum_element.<label>` foreign lookup carries no raw id, but the
42
- * data block's own `name = "..."` filter attribute (read via `ctx.dataName`)
43
- * IS the target's real display name - the same name `readAppNameMap`/
44
- * `readElementNameMap` index every already-pulled app/element by. When that
45
- * name matches one already in this workspace, resolve straight to a typed
46
- * `AppOrElementRef` instead of giving up - the reference then survives a
47
- * build exactly like a hand-authored `catalog.<ref>` would (see
48
- * agent-tool/from-tf.ts's `NormalizedToolTarget` for the same foreign-name
49
- * convention on tool targets). No match (the target isn't pulled into this
50
- * workspace yet, or `ctx` wasn't wired with the name maps) records the name
51
- * on `ctx.unresolvedForeignRefs` (when the caller wired it up) so
52
- * `--with-dependencies` can chase it down and pulls it as a workspace app/
53
- * element the same way it already does for agent-tool/automation targets —
54
- * then stays unresolvable this pull, same as before.
39
+ * `related_object_id` gets one more fallback beyond `resolveRelatedId`: a
40
+ * `data.elementum_app.<label>` / `data.elementum_element.<label>` foreign
41
+ * lookup carries no raw id, but its `namespace`/`name` filter attributes ARE
42
+ * the target's portable identity (see {@link dataAspectRef}).
55
43
  */
56
44
  function resolveRelatedObject(v, ctx, namespaceFallback = false) {
57
45
  const raw = resolveRelatedId(v, ctx);
@@ -59,41 +47,20 @@ function resolveRelatedObject(v, ctx, namespaceFallback = false) {
59
47
  return raw;
60
48
  if (v === undefined || !isTfExpr(v) || v.$expr !== "data-attr")
61
49
  return undefined;
62
- if (v.type === "elementum_app") {
63
- const attrs = ctx.dataAttrs?.("elementum_app", v.label);
64
- const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
65
- const name = ctx.dataName("elementum_app", v.label) ?? (typeof attrs?.name === "string" ? attrs.name : undefined);
66
- const refName = namespace !== undefined ? ctx.foreignAppRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignAppRefNames?.get(name) : undefined;
67
- if (refName !== undefined)
68
- return { __kind: "app", refName, name: name ?? refName, ...(namespace !== undefined ? { namespace } : {}) };
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)
76
- return undefined;
77
- const derived = tfLabelToTsLabel(sanitizeName(namespace));
78
- return { __kind: "app", refName: derived, name: name ?? derived, namespace };
79
- }
80
- if (v.type === "elementum_element") {
81
- const attrs = ctx.dataAttrs?.("elementum_element", v.label);
82
- const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
83
- const name = ctx.dataName("elementum_element", v.label) ?? (typeof attrs?.name === "string" ? attrs.name : undefined);
84
- const refName = namespace !== undefined ? ctx.foreignElementRefNamespaces?.get(namespace) : name !== undefined ? ctx.foreignElementRefNames?.get(name) : undefined;
85
- if (refName !== undefined)
86
- return { __kind: "element", refName, name: name ?? refName, ...(namespace !== undefined ? { namespace } : {}) };
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)
50
+ if (v.type === "elementum_app" || v.type === "elementum_element") {
51
+ const kind = v.type === "elementum_app" ? "app" : "element";
52
+ const resolved = dataAspectRef(kind, v.label, ctx);
53
+ if (resolved === undefined)
94
54
  return undefined;
95
- const derived = tfLabelToTsLabel(sanitizeName(namespace));
96
- return { __kind: "element", refName: derived, name: name ?? derived, namespace };
55
+ // In the workspace, or a dynamic Dropdown (`namespaceFallback` is the
56
+ // related_aspect_id caller): author the portable ref. That is #1440's
57
+ // namespace-derived dynamic_config and #1569's unpulled source.
58
+ if (resolved.inWorkspace || namespaceFallback)
59
+ return resolved.ref;
60
+ // #1484: an unpulled relation target stays unresolved so the pull
61
+ // refuses it. dataAspectRef already recorded the name for
62
+ // --with-dependencies.
63
+ return undefined;
97
64
  }
98
65
  if (v.type === "elementum_task") {
99
66
  const attrs = ctx.dataAttrs?.("elementum_task", v.label);
@@ -105,6 +72,34 @@ function resolveRelatedObject(v, ctx, namespaceFallback = false) {
105
72
  }
106
73
  return undefined;
107
74
  }
75
+ /**
76
+ * A `data.elementum_app|element.<label>` lookup → the aspect it names, the
77
+ * same identity views, widgets and relationships resolve: the workspace
78
+ * catalog when that app/element is pulled here, else a foreign ref build
79
+ * looks up again by the same namespace (or name) - the way automations
80
+ * author a foreign found record. A foreign one is also recorded on
81
+ * `ctx.unresolvedForeignRefs` so `pull app --with-dependencies` pulls it.
82
+ * Undefined when the export gave the lookup neither a namespace nor a name.
83
+ */
84
+ function dataAspectRef(kind, label, ctx) {
85
+ const type = kind === "app" ? "elementum_app" : "elementum_element";
86
+ const attrs = ctx.dataAttrs?.(type, label);
87
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
88
+ const name = ctx.dataName(type, label) ?? (typeof attrs?.name === "string" ? attrs.name : undefined);
89
+ if (namespace === undefined && name === undefined)
90
+ return undefined;
91
+ const target = resolveDataAspectTarget(ctx, kind, label);
92
+ const byNamespace = kind === "app" ? ctx.foreignAppRefNamespaces : ctx.foreignElementRefNamespaces;
93
+ const byName = kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames;
94
+ const inWorkspace = (namespace !== undefined && byNamespace?.get(namespace) === target.key) ||
95
+ (name !== undefined && byName?.get(name) === target.key);
96
+ if (!inWorkspace && name !== undefined)
97
+ (kind === "app" ? ctx.unresolvedForeignRefs?.apps : ctx.unresolvedForeignRefs?.elements)?.add(name);
98
+ return {
99
+ ref: { __kind: kind, refName: target.key, name: target.name, ...(namespace !== undefined ? { namespace } : {}) },
100
+ inWorkspace,
101
+ };
102
+ }
108
103
  /**
109
104
  * The identity a self-sourced dynamic Dropdown authors for its own owner:
110
105
  * the clone's `ctx.selfAspectRef`, else (pull, edk#1493) the owner itself,
@@ -202,6 +197,27 @@ function resolveRelatedField(v, ctx) {
202
197
  ...(fieldName !== undefined ? { fieldName } : {}),
203
198
  };
204
199
  }
200
+ const appLabel = dataRefLabel(objectId, "elementum_app");
201
+ const elementLabel = dataRefLabel(objectId, "elementum_element");
202
+ const ownerKind = appLabel !== undefined ? "app" : elementLabel !== undefined ? "element" : undefined;
203
+ const ownerLabel = appLabel ?? elementLabel;
204
+ const owner = ownerKind === undefined || ownerLabel === undefined ? undefined : dataAspectRef(ownerKind, ownerLabel, ctx);
205
+ if (ownerKind !== undefined && owner !== undefined && typeof attrs?.name === "string") {
206
+ const { refName, name, namespace } = owner.ref;
207
+ const field = decodeForeignDataField(v.label, { key: refName, name, ...(namespace !== undefined ? { namespace } : {}), kind: ownerKind }, ctx);
208
+ if (owner.inWorkspace)
209
+ return { ownerRefName: refName, fieldKey: field.key, fieldName: field.name };
210
+ return {
211
+ ownerRefName: refName,
212
+ ownerKind,
213
+ ownerName: name,
214
+ ...(namespace !== undefined ? { ownerNamespace: namespace } : {}),
215
+ fieldKey: field.key,
216
+ fieldName: field.name,
217
+ ...(field.fieldType !== undefined ? { fieldType: field.fieldType } : {}),
218
+ outsideWorkspace: true,
219
+ };
220
+ }
205
221
  }
206
222
  return undefined;
207
223
  }
@@ -278,16 +294,18 @@ function blockReplaceForcingDrop(ctx, site, attr, reason) {
278
294
  */
279
295
  function blockDynamicConfigDrop(ctx, site, reason, labelOnly = false) {
280
296
  // 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.
297
+ // resolved, so pulling it (again) cannot help: the export names the label
298
+ // field in a form pull cannot decode. `pull element` has no
299
+ // --with-dependencies, so the remedy names the pull itself.
283
300
  reportAuthoringBlocker(ctx, {
284
301
  address: site.address,
285
302
  description: `${site.where}: ${reason}. Dropping dynamic_config would author an empty static Dropdown, ` +
286
303
  "which plan rejects and which would replace the live dynamic options.",
287
304
  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.",
305
+ ? "The source app/element resolves, but the export's label field reference can't be decoded, so pulling the source won't help. " +
306
+ "Hand-author the Dropdown's dynamic config (source and label field) in the owning app/element file."
307
+ : "Make the Dropdown's source app/element and label field resolvable (pull the source into this workspace with " +
308
+ "`elementum pull app`/`pull element` first), then retry.",
291
309
  });
292
310
  }
293
311
  /**
@@ -301,7 +319,7 @@ function blockUnclearableParentMappings(ctx, site) {
301
319
  address: site.address,
302
320
  description: `${site.where}: dynamic_config parent mapping field IDs could not be reconstructed. The platform keeps parent mappings ` +
303
321
  `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.",
322
+ remedy: "Pull the apps/elements that own the mapped parent/source fields into this workspace (`elementum pull app`/`pull element`), or change the Dropdown's parent mappings in the Elementum UI, then pull again.",
305
323
  });
306
324
  }
307
325
  /**
@@ -2,3 +2,9 @@
2
2
  import { type EntityKindModule } from "../../graph/types.js";
3
3
  export declare const FIELD_DATA_RESOURCE_TYPE = "elementum_field";
4
4
  export declare const fieldModule: EntityKindModule;
5
+ /**
6
+ * `elementum_managed_field_order` orders an owner's custom fields. Build emits
7
+ * it from the authored `fields` key order; pull prints fields in its order.
8
+ * Like the managed view order, its import/state id is the owner's id.
9
+ */
10
+ export declare const managedFieldOrderModule: EntityKindModule;
@@ -1,7 +1,7 @@
1
1
  /** The field entity's registry entry (see src/graph/). */
2
2
  import { asNamedRef, namedFactoryEntry } from "../../catalog/render-helpers.js";
3
- import { NO_LIFECYCLE } from "../../graph/types.js";
4
- import { FIELD_SUB_TYPES } from "./types.js";
3
+ import { NO_CANVAS, NO_CATALOG, NO_DATA, NO_LIFECYCLE } from "../../graph/types.js";
4
+ import { FIELD_SUB_TYPES, MANAGED_FIELD_ORDER_RESOURCE_TYPE } from "./types.js";
5
5
  export const FIELD_DATA_RESOURCE_TYPE = "elementum_field";
6
6
  export const fieldModule = {
7
7
  kind: "field",
@@ -71,3 +71,23 @@ export const fieldModule = {
71
71
  refFromAuthoring: () => undefined,
72
72
  },
73
73
  };
74
+ /**
75
+ * `elementum_managed_field_order` orders an owner's custom fields. Build emits
76
+ * it from the authored `fields` key order; pull prints fields in its order.
77
+ * Like the managed view order, its import/state id is the owner's id.
78
+ */
79
+ export const managedFieldOrderModule = {
80
+ kind: "managed-field-order",
81
+ stream: { role: "streamMember" },
82
+ authoring: { unit: "inline", bag: "fields" },
83
+ parents: [
84
+ { parent: "app", child: "managed-field-order" },
85
+ { parent: "element", child: "managed-field-order" },
86
+ { parent: "task", child: "managed-field-order" },
87
+ ],
88
+ resource: { shape: "single", resourceType: MANAGED_FIELD_ORDER_RESOURCE_TYPE, adoptable: true },
89
+ data: NO_DATA,
90
+ lifecycle: NO_LIFECYCLE,
91
+ canvas: NO_CANVAS,
92
+ catalog: NO_CATALOG,
93
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The custom fields' order (#1670): `elementum_managed_field_order` lists an
3
+ * owner's field resources in authored `fields` key order. The platform's own
4
+ * order is whatever order the field creates finished in, so without it the
5
+ * default column order and every pull's field order drift between applies.
6
+ */
7
+ import { type TfBlock, type TfExpr } from "../../engine/tf/index.js";
8
+ import { type FieldOwnerScope } from "../../engine/tf/labels.js";
9
+ /** The owner's field order block, or undefined when it has no field resource. `fieldAddresses` iterates in authored order. */
10
+ export declare function managedFieldOrderToTf(ownerTfLabel: string, scope: FieldOwnerScope, objectId: TfExpr, fieldAddresses: ReadonlyMap<string, string>): TfBlock | undefined;
11
+ /**
12
+ * `fieldBlocks` in the order the owner's field order lists them, so pull prints
13
+ * fields in the platform's order instead of the parser's type-and-label order.
14
+ * Fields it doesn't list keep their relative order after the listed ones.
15
+ */
16
+ export declare function inManagedFieldOrder(fieldBlocks: readonly TfBlock[], orderBlocks: readonly TfBlock[]): readonly TfBlock[];
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The custom fields' order (#1670): `elementum_managed_field_order` lists an
3
+ * owner's field resources in authored `fields` key order. The platform's own
4
+ * order is whatever order the field creates finished in, so without it the
5
+ * default column order and every pull's field order drift between applies.
6
+ */
7
+ import { expr, isTfExpr } from "../../engine/tf/index.js";
8
+ import { scopedResourceLabel } from "../../engine/tf/labels.js";
9
+ import { MANAGED_FIELD_ORDER_RESOURCE_TYPE } from "./types.js";
10
+ /** The owner's field order block, or undefined when it has no field resource. `fieldAddresses` iterates in authored order. */
11
+ export function managedFieldOrderToTf(ownerTfLabel, scope, objectId, fieldAddresses) {
12
+ if (fieldAddresses.size === 0)
13
+ return undefined;
14
+ const fieldIds = [...fieldAddresses.values()].map((address) => {
15
+ const dot = address.indexOf(".");
16
+ return expr.resourceAttr(address.slice(0, dot), address.slice(dot + 1), ["id"]);
17
+ });
18
+ return {
19
+ kind: "resource",
20
+ type: MANAGED_FIELD_ORDER_RESOURCE_TYPE,
21
+ label: scopedResourceLabel(ownerTfLabel, "field_order", scope),
22
+ attrs: { object_id: objectId, field_ids: fieldIds },
23
+ };
24
+ }
25
+ /**
26
+ * `fieldBlocks` in the order the owner's field order lists them, so pull prints
27
+ * fields in the platform's order instead of the parser's type-and-label order.
28
+ * Fields it doesn't list keep their relative order after the listed ones.
29
+ */
30
+ export function inManagedFieldOrder(fieldBlocks, orderBlocks) {
31
+ const fieldIds = orderBlocks[0]?.attrs["field_ids"];
32
+ if (!Array.isArray(fieldIds))
33
+ return fieldBlocks;
34
+ const position = new Map();
35
+ for (const [index, value] of fieldIds.entries()) {
36
+ if (isTfExpr(value) && value.$expr === "resource-attr")
37
+ position.set(`${value.type}.${value.label}`, index);
38
+ }
39
+ const at = (block) => position.get(`${block.type}.${block.label}`) ?? Number.MAX_SAFE_INTEGER;
40
+ return [...fieldBlocks].sort((a, b) => at(a) - at(b));
41
+ }
@@ -53,3 +53,8 @@ export declare const FIELD_RESOURCE_TYPES: readonly string[];
53
53
  export declare const KNOWN_FIELD_ATTRS: ReadonlySet<string>;
54
54
  /** Provider resource type a field constructor builds, or undefined for unmodeled constructors. */
55
55
  export declare function fieldResourceTypeForCtor(ctor: string): string | undefined;
56
+ /**
57
+ * The order of an app's, element's or task's custom fields: the default column
58
+ * order of its record tables (#1670). One per owner, keyed by the owner's id.
59
+ */
60
+ export declare const MANAGED_FIELD_ORDER_RESOURCE_TYPE = "elementum_managed_field_order";
@@ -104,3 +104,8 @@ export function fieldResourceTypeForCtor(ctor) {
104
104
  const typeKey = FIELD_CTOR_TYPE_KEYS[ctor];
105
105
  return typeKey === undefined ? undefined : FIELD_SUB_TYPES.find((t) => t.typeKey === typeKey)?.resourceType;
106
106
  }
107
+ /**
108
+ * The order of an app's, element's or task's custom fields: the default column
109
+ * order of its record tables (#1670). One per owner, keyed by the owner's id.
110
+ */
111
+ export const MANAGED_FIELD_ORDER_RESOURCE_TYPE = "elementum_managed_field_order";
@@ -1,9 +1,10 @@
1
+ import { inManagedFieldOrder } from "../field/order.js";
1
2
  import { NO_CATALOG } from "../../graph/types.js";
2
3
  import { taskFromTf } from "./from-tf.js";
3
4
  import { taskToTf } from "./to-tf.js";
4
5
  export const TASK_RESOURCE_TYPE = "elementum_task";
5
6
  function extract(stream, ctx) { const blocks = stream.byKind.get("task") ?? []; if (blocks.length !== 1)
6
- throw new Error(`expected exactly one ${TASK_RESOURCE_TYPE}, found ${blocks.length}`); return { instance: taskFromTf(blocks[0], ctx, stream.byKind.get("field") ?? []) }; }
7
+ throw new Error(`expected exactly one ${TASK_RESOURCE_TYPE}, found ${blocks.length}`); return { instance: taskFromTf(blocks[0], ctx, inManagedFieldOrder(stream.byKind.get("field") ?? [], stream.byKind.get("managed-field-order") ?? [])) }; }
7
8
  export const taskModule = {
8
9
  kind: "task", stream: { role: "streamRoot", exportVerb: "tasks" }, authoring: { unit: "ownFile", bag: "tasks" }, parents: [{ parent: "org", child: "task" }],
9
10
  resource: { shape: "single", resourceType: TASK_RESOURCE_TYPE, adoptable: true }, data: { participates: true, lookupAttr: "name", referencedByBuild: true, referenceLookups: [{ strategy: "rootNamespace", compatibilityFallback: "name" }] },
@@ -1,3 +1,4 @@
1
+ import { managedFieldOrderToTf } from "../field/order.js";
1
2
  import { authoredFieldKeysFromPayload, claimFieldDisplayName, fieldToTf } from "../field/to-tf.js";
2
3
  import { EntityTfError } from "../../engine/entity.js";
3
4
  import { expr } from "../../engine/tf/index.js";
@@ -73,5 +74,8 @@ export function taskToTf(entity, ctx) {
73
74
  blocks.push(field.block);
74
75
  fieldAddresses.set(field.bagKey, field.address);
75
76
  }
77
+ const fieldOrder = managedFieldOrderToTf(p.namespace, "task", objectId, fieldAddresses);
78
+ if (fieldOrder !== undefined)
79
+ blocks.push(fieldOrder);
76
80
  return { blocks, fieldAddresses };
77
81
  }
@@ -1,7 +1,7 @@
1
1
  /** The view entity's registry entries (see src/graph/). */
2
2
  import { asNamedRef, namedFactoryEntry } from "../../catalog/render-helpers.js";
3
3
  import { NO_CANVAS, NO_CATALOG, NO_DATA, NO_LIFECYCLE, } from "../../graph/types.js";
4
- import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, LAYOUT_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE, MANAGED_VIEW_ORDER_RESOURCE_TYPE, VIEW_DATA_RESOURCE_TYPE, } from "./types.js";
4
+ import { AGENT_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, LAYOUT_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE, MANAGED_VIEW_ORDER_RESOURCE_TYPE, PLATFORM_DEFAULT_LIST_VIEW_NAME, VIEW_DATA_RESOURCE_TYPE, } from "./types.js";
5
5
  /**
6
6
  * Layouts + list views are stream members folded into the app authoring file
7
7
  * (inline), extracted by `appFromTf` — not own-file kinds.
@@ -77,6 +77,9 @@ export const managedViewOrderModule = {
77
77
  shape: "single",
78
78
  resourceType: MANAGED_VIEW_ORDER_RESOURCE_TYPE,
79
79
  adoptable: true,
80
+ // The provider leaves the platform's default "List" view out of an order
81
+ // whose state doesn't list it (#1598); the export always lists it (#1658).
82
+ stateScopedPlatformEntries: [{ attribute: "view_ids", name: PLATFORM_DEFAULT_LIST_VIEW_NAME }],
80
83
  },
81
84
  data: NO_DATA,
82
85
  lifecycle: NO_LIFECYCLE,
@@ -17,7 +17,7 @@ import { filterToTf, principalListToTf } from "../access-policy/to-tf.js";
17
17
  import { SUB_TYPE_BY_AUTHORING_TYPE } from "../field/types.js";
18
18
  import { DASHBOARD_RESOURCE_TYPE } from "../dashboard/module.js";
19
19
  import { WIDGET_RESOURCE_TYPE } from "../widget/module.js";
20
- import { AGENT_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, GROUP_SECTION_WIRE_TYPE, LAYOUT_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, MANAGED_VIEW_ORDER_RESOURCE_TYPE, SECTION_TYPE_TO_WIRE, SYSTEM_FIELD_ID_ATTR_BY_KEY, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
20
+ import { AGENT_VIEW_RESOURCE_TYPE, CUSTOM_VIEW_RESOURCE_TYPE, CALENDAR_VIEW_RESOURCE_TYPE, DASHBOARD_VIEW_RESOURCE_TYPE, GROUP_SECTION_WIRE_TYPE, LAYOUT_RESOURCE_TYPE, LIST_VIEW_RESOURCE_TYPE, KANBAN_VIEW_RESOURCE_TYPE, MANAGED_VIEW_ORDER_RESOURCE_TYPE, PLATFORM_DEFAULT_LIST_VIEW_NAME, SECTION_TYPE_TO_WIRE, SYSTEM_FIELD_ID_ATTR_BY_KEY, UPDATE_SECTION_WIRE_TYPE, } from "./types.js";
21
21
  function appendViewSharingAttrs(attrs, view, where, ctx) {
22
22
  const userIds = principalListToTf(view.userIds, "elementum_user", `${where}.userIds`, ctx);
23
23
  const groupIds = principalListToTf(view.groupIds, "elementum_group", `${where}.groupIds`, ctx);
@@ -301,14 +301,22 @@ export function viewToTf(layouts, listViews, calendarViews, kanbanViews, dashboa
301
301
  }
302
302
  // Every declared list view must appear even if viewOrder omitted it —
303
303
  // otherwise the omitted view has no ordering entry and the platform
304
- // may reject or silently exclude it from the managed order.
304
+ // may reject or silently exclude it from the managed order. The exception
305
+ // is the platform's default "List" view: the platform keeps it in the order
306
+ // itself, and the provider leaves it out of an order that doesn't list it
307
+ // (#1598), so appending it would plan a change after every pull (#1658).
308
+ const viewNames = new Map([listViews, calendarViews, kanbanViews, dashboardViews, agentViews, customViews]
309
+ .flatMap((bag) => Object.entries(bag ?? {}).map(([key, view]) => [key, view.name])));
305
310
  for (const [key, address] of viewAddressByKey) {
306
311
  if (placed.has(key))
307
312
  continue;
313
+ if (viewOrder !== undefined && viewNames.get(key) === PLATFORM_DEFAULT_LIST_VIEW_NAME)
314
+ continue;
308
315
  diagnostics.push(`view "${key}" is not listed in viewOrder; appended`);
309
316
  viewIds.push(expr.resourceAttr(address.type, address.label, ["id"]));
310
317
  }
311
- if (viewIds.length > 0) {
318
+ // An explicitly empty viewOrder keeps an empty order (#1658).
319
+ if (viewIds.length > 0 || viewOrder !== undefined) {
312
320
  blocks.push({
313
321
  kind: "resource",
314
322
  type: MANAGED_VIEW_ORDER_RESOURCE_TYPE,
@@ -18,6 +18,12 @@ export declare const CALENDAR_VIEW_RESOURCE_TYPE = "elementum_calendar_view";
18
18
  export declare const KANBAN_VIEW_RESOURCE_TYPE = "elementum_kanban_view";
19
19
  export declare const DASHBOARD_VIEW_RESOURCE_TYPE = "elementum_dashboard_view";
20
20
  export declare const MANAGED_VIEW_ORDER_RESOURCE_TYPE = "elementum_managed_view_order";
21
+ /**
22
+ * The name the platform gives the list view it creates on every app, element
23
+ * and task. Like the provider (`platformDefaultListViewName`), EDK recognises
24
+ * that view only by this name; the platform has no other marker for it.
25
+ */
26
+ export declare const PLATFORM_DEFAULT_LIST_VIEW_NAME = "List";
21
27
  /** Looks up a managed view by owner and name (a portal menu's view outside the workspace). */
22
28
  export declare const VIEW_DATA_RESOURCE_TYPE = "elementum_view";
23
29
  /**
@@ -20,6 +20,12 @@ export const CALENDAR_VIEW_RESOURCE_TYPE = "elementum_calendar_view";
20
20
  export const KANBAN_VIEW_RESOURCE_TYPE = "elementum_kanban_view";
21
21
  export const DASHBOARD_VIEW_RESOURCE_TYPE = "elementum_dashboard_view";
22
22
  export const MANAGED_VIEW_ORDER_RESOURCE_TYPE = "elementum_managed_view_order";
23
+ /**
24
+ * The name the platform gives the list view it creates on every app, element
25
+ * and task. Like the provider (`platformDefaultListViewName`), EDK recognises
26
+ * that view only by this name; the platform has no other marker for it.
27
+ */
28
+ export const PLATFORM_DEFAULT_LIST_VIEW_NAME = "List";
23
29
  /** Looks up a managed view by owner and name (a portal menu's view outside the workspace). */
24
30
  export const VIEW_DATA_RESOURCE_TYPE = "elementum_view";
25
31
  /**
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Public graph barrel: KIND_MODULES + derived views for pull/build/canvas.
3
3
  */
4
- import { type CatalogRenderArgs, type CatalogRenderResult, type EntityKindModule, type KindId, type ParentEdge, matchType } from "./types.js";
5
- export type { AdoptionAddressAlias, AuthoringFacet, CanvasComponentId, CanvasFacet, CanvasView, CatalogAuthoringArgs, CatalogFacet, CatalogRenderArgs, CatalogRenderResult, CatalogRoot, DataFacet, DataFacetCatalogKind, EntityKindId, EntityKindModule, KindId, LifecycleFacet, OrgIdentityBag, ParentEdge, ParentageFacet, ResourceFacet, StreamFacet, StreamMatch, StreamPartition, StreamRootExtractResult, ToTfResult, } from "./types.js";
4
+ import { type CatalogRenderArgs, type CatalogRenderResult, type EntityKindModule, type KindId, type ParentEdge, type StateScopedPlatformEntry, matchType } from "./types.js";
5
+ export type { AdoptionAddressAlias, AuthoringFacet, CanvasComponentId, CanvasFacet, CanvasView, CatalogAuthoringArgs, CatalogFacet, CatalogRenderArgs, CatalogRenderResult, CatalogRoot, DataFacet, DataFacetCatalogKind, EntityKindId, EntityKindModule, KindId, LifecycleFacet, OrgIdentityBag, ParentEdge, ParentageFacet, ResourceFacet, StateScopedPlatformEntry, StreamFacet, StreamMatch, StreamPartition, StreamRootExtractResult, ToTfResult, } from "./types.js";
6
6
  export type { ReferenceLookupStrategy } from "./types.js";
7
7
  export { NO_CANVAS, NO_CATALOG, NO_DATA, NO_LIFECYCLE, defaultMatchResourceType, implementedResourceTypes, isResourceAdoptable, isTfLive, knownResourceTypes, matchType, singleResourceType, } from "./types.js";
8
8
  export { KIND_MODULES } from "./modules.js";
@@ -134,6 +134,7 @@ export declare const UNREADABLE_ATTRIBUTES_BY_RESOURCE_TYPE: ReadonlyMap<string,
134
134
  * single-resource kind declares them. A re-pull keeps only the keys in state.
135
135
  */
136
136
  export declare const STATE_SCOPED_MAP_ATTRIBUTES_BY_RESOURCE_TYPE: ReadonlyMap<string, readonly string[]>;
137
+ export declare const STATE_SCOPED_PLATFORM_ENTRIES_BY_RESOURCE_TYPE: ReadonlyMap<string, readonly StateScopedPlatformEntry[]>;
137
138
  /** Entity-declared value equivalences used to compare builder and exporter HCL. */
138
139
  export declare const BUILD_VS_EXPORT_NORMALIZATIONS: {
139
140
  readonly omittedAttributeDefaults: {
@@ -127,6 +127,9 @@ export const UNREADABLE_ATTRIBUTES_BY_RESOURCE_TYPE = new Map(KIND_MODULES.flatM
127
127
  export const STATE_SCOPED_MAP_ATTRIBUTES_BY_RESOURCE_TYPE = new Map(KIND_MODULES.flatMap((m) => m.resource.shape === "single" && m.resource.stateScopedMapAttributes !== undefined
128
128
  ? [[m.resource.resourceType, m.resource.stateScopedMapAttributes]]
129
129
  : []));
130
+ export const STATE_SCOPED_PLATFORM_ENTRIES_BY_RESOURCE_TYPE = new Map(KIND_MODULES.flatMap((m) => m.resource.shape === "single" && m.resource.stateScopedPlatformEntries !== undefined
131
+ ? [[m.resource.resourceType, m.resource.stateScopedPlatformEntries]]
132
+ : []));
130
133
  /** Entity-declared value equivalences used to compare builder and exporter HCL. */
131
134
  export const BUILD_VS_EXPORT_NORMALIZATIONS = {
132
135
  omittedAttributeDefaults: KIND_MODULES.flatMap((module) => (module.roundtrip?.omittedAttributeDefaults ?? []).flatMap((equivalence) => implementedResourceTypes(module.resource).map((blockType) => ({ blockType, ...equivalence })))),
@@ -17,7 +17,7 @@ import { dashboardModule } from "../entities/dashboard/module.js";
17
17
  import { dashboardWidgetModule } from "../entities/dashboard-widget/module.js";
18
18
  import { datamineModule } from "../entities/datamine/module.js";
19
19
  import { dataLookupModules } from "../entities/data-lookup/module.js";
20
- import { fieldModule } from "../entities/field/module.js";
20
+ import { fieldModule, managedFieldOrderModule } from "../entities/field/module.js";
21
21
  import { fileReaderModule } from "../entities/file-reader/module.js";
22
22
  import { visualFlowModule } from "../entities/visual-flow/module.js";
23
23
  import { aiProviderModules, categoryModule, cloudLinkModule, connectorModule, emailAliasModule, groupModule, phoneProviderModule, roleModule, userModule, } from "../entities/org/index.js";
@@ -52,6 +52,7 @@ export const KIND_MODULES = [
52
52
  visualFlowModule,
53
53
  viewModule,
54
54
  managedViewOrderModule,
55
+ managedFieldOrderModule,
55
56
  recordCreateFormModule,
56
57
  dynamicLayoutModule,
57
58
  dashboardModule,
@@ -10,7 +10,7 @@ import type { DeployableEntity } from "../engine/entity.js";
10
10
  import type { FromTfContext } from "../engine/pull/context.js";
11
11
  import type { ChildResourceScope, TfBlock, TfValue } from "../engine/tf/index.js";
12
12
  import type { ValidationFailure } from "../engine/validation.js";
13
- export type KindId = "org" | "app" | "element" | "field" | "access-policy" | "agent" | "agent-evaluation" | "chart" | "agent-tool" | "agent-a2a-skill" | "automation" | "approval-chain" | "file-reader" | "visual-flow" | "skill" | "skill-tool" | "view" | "managed-view-order" | "record-create-form" | "dynamic-layout" | "dashboard" | "dashboard-widget" | "datamine" | "automation-value-references" | "organization" | "permission-template" | "service-account" | "stored-function" | "vault-entry" | "task" | "portal" | "widget" | "relationship" | "search-table" | "table" | "cloud-link" | "email-alias" | "category" | "connector" | "ai-provider-anthropic" | "ai-provider-bedrock" | "ai-provider-custom" | "ai-provider-deepgram" | "ai-provider-elevenlab" | "ai-provider-gemini" | "ai-provider-openai" | "ai-provider-snowflake" | "ai-provider-xai" | "ai-provider-managed" | "group" | "phone-provider" | "phone-service" | "role" | "user";
13
+ export type KindId = "org" | "app" | "element" | "field" | "access-policy" | "agent" | "agent-evaluation" | "chart" | "agent-tool" | "agent-a2a-skill" | "automation" | "approval-chain" | "file-reader" | "visual-flow" | "skill" | "skill-tool" | "view" | "managed-view-order" | "managed-field-order" | "record-create-form" | "dynamic-layout" | "dashboard" | "dashboard-widget" | "datamine" | "automation-value-references" | "organization" | "permission-template" | "service-account" | "stored-function" | "vault-entry" | "task" | "portal" | "widget" | "relationship" | "search-table" | "table" | "cloud-link" | "email-alias" | "category" | "connector" | "ai-provider-anthropic" | "ai-provider-bedrock" | "ai-provider-custom" | "ai-provider-deepgram" | "ai-provider-elevenlab" | "ai-provider-gemini" | "ai-provider-openai" | "ai-provider-snowflake" | "ai-provider-xai" | "ai-provider-managed" | "group" | "phone-provider" | "phone-service" | "role" | "user";
14
14
  /** @deprecated Use {@link KindId}. */
15
15
  export type EntityKindId = KindId;
16
16
  export type StreamFacet = {
@@ -43,6 +43,11 @@ export interface ParentEdge {
43
43
  }
44
44
  /** Parentage facet: who may own whom (multi-parent OK). */
45
45
  export type ParentageFacet = readonly ParentEdge[];
46
+ /** A reference list attribute and the name of the platform-created resource state decides on. */
47
+ export interface StateScopedPlatformEntry {
48
+ readonly attribute: string;
49
+ readonly name: string;
50
+ }
46
51
  export interface SubTypeRow {
47
52
  readonly key: string;
48
53
  readonly resourceType: string;
@@ -88,6 +93,13 @@ export type ResourceFacet = {
88
93
  * keys state holds (see `alignExportWithState`).
89
94
  */
90
95
  readonly stateScopedMapAttributes?: readonly string[];
96
+ /**
97
+ * Reference lists where the provider keeps an entry pointing at a
98
+ * platform-created resource (recognised by its `name`) only when state
99
+ * already holds that entry. The export always lists it; a re-pull drops
100
+ * it unless state holds its id (see `alignExportWithState`).
101
+ */
102
+ readonly stateScopedPlatformEntries?: readonly StateScopedPlatformEntry[];
91
103
  } | {
92
104
  readonly shape: "subTypes";
93
105
  readonly rows: readonly SubTypeRow[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementumai/edk",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Elementum Development Kit — statically typed SDK for building Elementum apps, automations, and agents",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",