@elementumai/edk 0.9.10 → 0.9.12

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 (124) hide show
  1. package/README.md +39 -5
  2. package/dist-sdk/src/catalog/factories.d.ts +42 -14
  3. package/dist-sdk/src/catalog/factories.js +77 -14
  4. package/dist-sdk/src/catalog/from-authoring.js +4 -4
  5. package/dist-sdk/src/catalog/index.d.ts +2 -2
  6. package/dist-sdk/src/catalog/index.js +1 -1
  7. package/dist-sdk/src/catalog/org.js +3 -2
  8. package/dist-sdk/src/catalog/token.js +4 -0
  9. package/dist-sdk/src/catalog/types.d.ts +32 -5
  10. package/dist-sdk/src/catalog/types.js +1 -0
  11. package/dist-sdk/src/core/triggers/on-demand.d.ts +4 -28
  12. package/dist-sdk/src/core/triggers/on-demand.js +2 -4
  13. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  14. package/dist-sdk/src/engine/entity.d.ts +2 -0
  15. package/dist-sdk/src/engine/logging.d.ts +90 -0
  16. package/dist-sdk/src/engine/logging.js +124 -0
  17. package/dist-sdk/src/engine/progress.d.ts +119 -0
  18. package/dist-sdk/src/engine/progress.js +647 -0
  19. package/dist-sdk/src/engine/pull/result-output.d.ts +24 -0
  20. package/dist-sdk/src/engine/pull/result-output.js +48 -0
  21. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +3 -3
  22. package/dist-sdk/src/entities/access-policy/from-tf.js +27 -8
  23. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +13 -0
  24. package/dist-sdk/src/entities/access-policy/to-tf.js +34 -3
  25. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +13 -7
  26. package/dist-sdk/src/entities/agent/tools.d.ts +2 -2
  27. package/dist-sdk/src/entities/agent-tool/to-tf.js +13 -0
  28. package/dist-sdk/src/entities/app/build.d.ts +22 -2
  29. package/dist-sdk/src/entities/app/build.js +6 -0
  30. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +13 -3
  31. package/dist-sdk/src/entities/app/from-tf.js +10 -7
  32. package/dist-sdk/src/entities/app/to-tf.js +14 -14
  33. package/dist-sdk/src/entities/automation/build.d.ts +11 -16
  34. package/dist-sdk/src/entities/automation/build.js +38 -8
  35. package/dist-sdk/src/entities/automation/catalog-render.js +1 -1
  36. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +1 -2
  37. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +23 -5
  38. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +239 -34
  39. package/dist-sdk/src/entities/automation/from-tf.js +276 -19
  40. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  41. package/dist-sdk/src/entities/automation/module.js +3 -2
  42. package/dist-sdk/src/entities/automation/output-field-types.js +25 -13
  43. package/dist-sdk/src/entities/automation/script-code.d.ts +12 -4
  44. package/dist-sdk/src/entities/automation/script-code.js +659 -101
  45. package/dist-sdk/src/entities/automation/tasks.d.ts +60 -28
  46. package/dist-sdk/src/entities/automation/tasks.js +48 -15
  47. package/dist-sdk/src/entities/automation/to-tf.d.ts +8 -0
  48. package/dist-sdk/src/entities/automation/to-tf.js +514 -103
  49. package/dist-sdk/src/entities/automation/triggers.d.ts +15 -9
  50. package/dist-sdk/src/entities/automation/triggers.js +4 -2
  51. package/dist-sdk/src/entities/automation/types.js +1 -0
  52. package/dist-sdk/src/entities/chart/build.d.ts +15 -3
  53. package/dist-sdk/src/entities/chart/build.js +6 -1
  54. package/dist-sdk/src/entities/chart/from-tf.d.ts +8 -2
  55. package/dist-sdk/src/entities/chart/from-tf.js +71 -8
  56. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  57. package/dist-sdk/src/entities/chart/index.js +1 -1
  58. package/dist-sdk/src/entities/chart/printer.js +27 -7
  59. package/dist-sdk/src/entities/chart/to-tf.js +56 -2
  60. package/dist-sdk/src/entities/dashboard/from-tf.js +11 -2
  61. package/dist-sdk/src/entities/datamine/from-tf.js +11 -1
  62. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -1
  63. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +8 -0
  64. package/dist-sdk/src/entities/dynamic-layout/dialect.js +12 -0
  65. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +7 -0
  66. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +64 -10
  67. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +54 -6
  68. package/dist-sdk/src/entities/element/build.d.ts +8 -0
  69. package/dist-sdk/src/entities/element/from-tf.js +4 -3
  70. package/dist-sdk/src/entities/element/module.js +1 -0
  71. package/dist-sdk/src/entities/element/to-tf.d.ts +4 -1
  72. package/dist-sdk/src/entities/element/to-tf.js +28 -2
  73. package/dist-sdk/src/entities/field/build.d.ts +10 -1
  74. package/dist-sdk/src/entities/field/build.js +2 -1
  75. package/dist-sdk/src/entities/field/calc/index.js +7 -7
  76. package/dist-sdk/src/entities/field/calc/runtime.d.ts +19 -0
  77. package/dist-sdk/src/entities/field/calc/runtime.js +32 -0
  78. package/dist-sdk/src/entities/field/calc/types.d.ts +6 -0
  79. package/dist-sdk/src/entities/field/from-tf.d.ts +24 -0
  80. package/dist-sdk/src/entities/field/from-tf.js +73 -1
  81. package/dist-sdk/src/entities/field/metadata.d.ts +18 -0
  82. package/dist-sdk/src/entities/field/metadata.js +34 -0
  83. package/dist-sdk/src/entities/file-reader/to-tf.js +10 -2
  84. package/dist-sdk/src/entities/relationship/build.d.ts +27 -9
  85. package/dist-sdk/src/entities/relationship/column-contract.d.ts +24 -0
  86. package/dist-sdk/src/entities/relationship/column-contract.js +41 -0
  87. package/dist-sdk/src/entities/relationship/from-tf.js +33 -48
  88. package/dist-sdk/src/entities/relationship/to-tf.d.ts +1 -0
  89. package/dist-sdk/src/entities/relationship/to-tf.js +33 -2
  90. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  91. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +21 -0
  92. package/dist-sdk/src/entities/shared/context.d.ts +6 -3
  93. package/dist-sdk/src/entities/shared/context.js +19 -1
  94. package/dist-sdk/src/entities/shared/filters/index.d.ts +7 -0
  95. package/dist-sdk/src/entities/shared/filters/index.js +28 -0
  96. package/dist-sdk/src/entities/shared/filters/print.js +2 -0
  97. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +8 -1
  98. package/dist-sdk/src/entities/shared/filters/tf-codec.js +10 -6
  99. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  100. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +5 -0
  101. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +52 -27
  102. package/dist-sdk/src/entities/skill/module.js +1 -0
  103. package/dist-sdk/src/entities/skill/to-tf.d.ts +1 -1
  104. package/dist-sdk/src/entities/skill/to-tf.js +17 -0
  105. package/dist-sdk/src/entities/skill/tools.d.ts +48 -12
  106. package/dist-sdk/src/entities/skill/tools.js +12 -1
  107. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +15 -12
  108. package/dist-sdk/src/entities/skill-tool/from-tf.js +50 -46
  109. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +4 -0
  110. package/dist-sdk/src/entities/skill-tool/to-tf.js +66 -7
  111. package/dist-sdk/src/entities/table/build.js +10 -2
  112. package/dist-sdk/src/entities/table/catalog-render.js +2 -1
  113. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  114. package/dist-sdk/src/entities/view/to-tf.d.ts +7 -0
  115. package/dist-sdk/src/entities/view/to-tf.js +39 -12
  116. package/dist-sdk/src/entities/widget/build.d.ts +43 -7
  117. package/dist-sdk/src/entities/widget/from-tf.d.ts +1 -1
  118. package/dist-sdk/src/entities/widget/from-tf.js +162 -23
  119. package/dist-sdk/src/entities/widget/to-tf.d.ts +17 -0
  120. package/dist-sdk/src/entities/widget/to-tf.js +150 -6
  121. package/dist-sdk/src/graph/types.d.ts +13 -0
  122. package/package.json +1 -1
  123. package/dist-sdk/src/core/types/platform.d.ts +0 -2
  124. package/dist-sdk/src/core/types/platform.js +0 -1
@@ -8,7 +8,7 @@
8
8
  import { EntityTfError } from "../../engine/entity.js";
9
9
  import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
10
10
  import { dataRefLabel, optionalString, resourceRefLabel } from "../../engine/pull/context.js";
11
- import { bareChildResourceLabel, isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
11
+ import { bareChildResourceLabel, isTfExpr, sanitizeName, scopedLabelToBagKey, tfLabelToTsLabel, tsLabelToTfLabel } from "../../engine/tf/index.js";
12
12
  import { filterFromTf as deserializeFilterFromTf } from "../shared/filters/tf-codec.js";
13
13
  import { __pulledExpression } from "../app/deserializer/pulled-expression.js";
14
14
  import { optionsFromTf } from "./options.js";
@@ -510,3 +510,75 @@ export function fieldKeyFromTfValue(v, ownerRefName, ownerTfLabel, scope, ctx) {
510
510
  }
511
511
  return fieldKeyFromTfRef(v, ownerTfLabel, scope);
512
512
  }
513
+ /**
514
+ * Decode `data.elementum_field.<label>` to the target's public field key.
515
+ * ei labels are `elementum_element_<sanitize(displayName)>_<field>` (or
516
+ * `app_<slug>_<field>`), not the catalog bag key. Treating the whole label
517
+ * as the key rebuilds a non-existent `elementum_text_field.<owner>_<label>`.
518
+ */
519
+ export function decodeForeignDataField(dataLabel, target, ctx) {
520
+ const resolved = ctx.foreignFieldRefsByDataAddress?.get(`elementum_field.${dataLabel}`);
521
+ if (resolved !== undefined && resolved.ownerRefName === target.key) {
522
+ return {
523
+ key: resolved.fieldKey,
524
+ name: ctx.dataName("elementum_field", dataLabel) ?? resolved.fieldName ?? resolved.fieldKey,
525
+ ...(resolved.fieldType !== undefined ? { fieldType: resolved.fieldType } : {}),
526
+ };
527
+ }
528
+ const name = ctx.dataName("elementum_field", dataLabel) ?? tfLabelToTsLabel(dataLabel);
529
+ const catalogFieldKey = ctx.fieldNamesByOwnerRefName?.get(target.key)?.get(name.toLowerCase());
530
+ if (catalogFieldKey !== undefined) {
531
+ const fieldType = fieldTypeFromRegistry(ctx, target.key, catalogFieldKey);
532
+ return { key: catalogFieldKey, name, ...(fieldType !== undefined ? { fieldType } : {}) };
533
+ }
534
+ const stripped = fieldKeyFromForeignDataLabel(dataLabel, target);
535
+ if (stripped !== undefined) {
536
+ const fieldType = fieldTypeFromRegistry(ctx, target.key, stripped);
537
+ return { key: stripped, name, ...(fieldType !== undefined ? { fieldType } : {}) };
538
+ }
539
+ return { key: tfLabelToTsLabel(dataLabel), name };
540
+ }
541
+ function fieldTypeFromRegistry(ctx, ownerRefName, fieldKey) {
542
+ for (const ref of ctx.foreignFieldRefsByDataAddress?.values() ?? []) {
543
+ if (ref.ownerRefName === ownerRefName && ref.fieldKey === fieldKey && ref.fieldType !== undefined) {
544
+ return ref.fieldType;
545
+ }
546
+ }
547
+ for (const ref of ctx.foreignFieldRefsById?.values() ?? []) {
548
+ if (ref.ownerRefName === ownerRefName && ref.fieldKey === fieldKey) {
549
+ const typed = ref;
550
+ if (typed.fieldType !== undefined)
551
+ return typed.fieldType;
552
+ }
553
+ }
554
+ if (fieldKey === "id")
555
+ return "HANDLE";
556
+ if (fieldKey === "title")
557
+ return "TEXT";
558
+ return undefined;
559
+ }
560
+ /** Strip ei's owner-display prefix from a `data.elementum_field` label. */
561
+ export function fieldKeyFromForeignDataLabel(dataLabel, target) {
562
+ const kind = target.kind === "element" || target.kind === "app" ? target.kind : undefined;
563
+ const ownerType = kind === "element" ? "elementum_element" : kind === "app" ? "elementum_app" : undefined;
564
+ const slugs = [
565
+ target.name !== undefined && target.name !== "" ? sanitizeName(target.name) : undefined,
566
+ target.namespace,
567
+ tsLabelToTfLabel(target.key),
568
+ ].filter((slug) => typeof slug === "string" && slug !== "");
569
+ const prefixes = [];
570
+ for (const slug of slugs) {
571
+ if (ownerType !== undefined)
572
+ prefixes.push(`${ownerType}_${slug}_`);
573
+ if (kind !== undefined)
574
+ prefixes.push(`${kind}_${slug}_`);
575
+ prefixes.push(`${slug}_`);
576
+ }
577
+ prefixes.sort((a, b) => b.length - a.length);
578
+ for (const prefix of prefixes) {
579
+ if (dataLabel.startsWith(prefix) && dataLabel.length > prefix.length) {
580
+ return tfLabelToTsLabel(dataLabel.slice(prefix.length));
581
+ }
582
+ }
583
+ return undefined;
584
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Build-time field catalog used by automation switch filters.
3
+ *
4
+ * Apps already returned this from `appToTf`. Elements must emit the same
5
+ * map so an element-owned automation's `filter.isNull` / `isNotNull` can
6
+ * infer PICKLIST `.id` → UUID instead of falling back to TEXT.
7
+ */
8
+ import type { BuildFieldMetadata } from "../../graph/types.js";
9
+ import { type PicklistValueWire } from "./options.js";
10
+ interface FieldMetadataInner {
11
+ readonly name?: string;
12
+ readonly __refName?: string;
13
+ readonly picklistValues?: readonly PicklistValueWire[];
14
+ readonly tags?: readonly string[];
15
+ }
16
+ /** bag key → type/options metadata, keyed the same way as fieldAddresses. */
17
+ export declare function fieldMetadataFromEntries(fields: readonly Record<string, FieldMetadataInner>[] | undefined): Map<string, BuildFieldMetadata>;
18
+ export {};
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Build-time field catalog used by automation switch filters.
3
+ *
4
+ * Apps already returned this from `appToTf`. Elements must emit the same
5
+ * map so an element-owned automation's `filter.isNull` / `isNotNull` can
6
+ * infer PICKLIST `.id` → UUID instead of falling back to TEXT.
7
+ */
8
+ import { snakeSlug } from "../../engine/tf/index.js";
9
+ import { picklistLabel } from "./options.js";
10
+ import { SUB_TYPE_BY_TYPE_KEY } from "./types.js";
11
+ /** bag key → type/options metadata, keyed the same way as fieldAddresses. */
12
+ export function fieldMetadataFromEntries(fields) {
13
+ const fieldMetadata = new Map();
14
+ for (const fieldEntry of fields ?? []) {
15
+ const typeKey = Object.keys(fieldEntry)[0];
16
+ if (typeKey === undefined)
17
+ continue;
18
+ const inner = fieldEntry[typeKey];
19
+ const name = inner.name ?? "";
20
+ const fieldKey = inner.__refName ?? snakeSlug(name);
21
+ const subType = SUB_TYPE_BY_TYPE_KEY.get(typeKey);
22
+ if (fieldKey === "" || name === "" || subType === undefined)
23
+ continue;
24
+ fieldMetadata.set(fieldKey, {
25
+ name,
26
+ fieldType: subType.authoringType,
27
+ ...(inner.picklistValues !== undefined
28
+ ? { options: inner.picklistValues.map((value) => picklistLabel(value)) }
29
+ : {}),
30
+ ...(inner.tags !== undefined ? { tags: inner.tags } : {}),
31
+ });
32
+ }
33
+ return fieldMetadata;
34
+ }
@@ -21,8 +21,16 @@ function serializeStructureField(f) {
21
21
  return { date: { name: f.name, format: f.format } };
22
22
  case "datetime":
23
23
  return { datetime: { name: f.name, format: f.format } };
24
- case "object":
25
- return { object: { name: f.name, properties: f.properties.map(serializeStructureField) } };
24
+ case "object": {
25
+ // ei's own export omits `properties` entirely for an object with no
26
+ // discovered sub-fields (e.g. a nested array-of-objects item type ei
27
+ // couldn't further introspect) rather than emitting an empty array —
28
+ // always including it here planned a spurious in-place update on
29
+ // every build (live-confirmed on purchaseorder/eu-sanofi's
30
+ // "New file reader"'s `to_PurchaseOrderItem` array field).
31
+ const properties = f.properties.map(serializeStructureField);
32
+ return { object: { name: f.name, ...(properties.length > 0 ? { properties } : {}) } };
33
+ }
26
34
  case "array":
27
35
  return { array: { name: f.name, arrayType: serializeStructureField(f.itemType) } };
28
36
  }
@@ -1,16 +1,34 @@
1
- import type { AppOrElementRef, FieldRef, TableColumnRef, TableRef } from "../../catalog/index.js";
1
+ import type { AppOrElementRef, FieldRef, RecordIdentityRef, TableColumnRef, TableRef } from "../../catalog/index.js";
2
2
  import type { Filter } from "../shared/filters/types.js";
3
3
  import type { AppViewFieldRef } from "../app/build.js";
4
- export interface AppRelationshipColumn {
5
- /** Field on the owning app/element. */
4
+ export interface AppRelationshipColumn<Target extends AppOrElementRef | TableRef = AppOrElementRef | TableRef> {
5
+ /**
6
+ * Field on the owning app/element. System `"id"` is HANDLE (the record
7
+ * handle), not the record UUID. AutoRelation create rejects HANDLE joined
8
+ * to a child `relationField` or dynamic dropdown — put the relation field
9
+ * on this side, or join comparable scalars (text/handle/number/…).
10
+ */
6
11
  readonly field: AppViewFieldRef;
7
- /** Field/column on `target`. */
8
- readonly relatedField: FieldRef | TableColumnRef;
12
+ /**
13
+ * Field/column on `target`. Use title, id, or another scalar whose stored
14
+ * value equals `field`. A child `relationField` or dynamic dropdown is not
15
+ * a valid related join target against parent system `"id"`.
16
+ */
17
+ readonly relatedField: FieldRef | TableColumnRef | RecordIdentityRef<Target>;
9
18
  }
10
- /** A provider AutoRelation, keyed under the owning aspect's `relationships` bag. */
11
- export interface AppRelationship {
12
- readonly target: AppOrElementRef | TableRef;
13
- readonly columns: readonly AppRelationshipColumn[];
19
+ /**
20
+ * A parent-owned join (`elementum_relationship`) keyed under this app/element's
21
+ * `relationships` bag. `relatedRecords` widgets on this object list rows
22
+ * through these joins. Columns are equality joins of comparable stored values
23
+ * (SQL JOIN ON). Proven creates: TEXT→TEXT, and source `relationField`→related
24
+ * title or id. Do not join this object's system `"id"` (HANDLE) to a child
25
+ * `relationField` or dynamic dropdown (create fails with `Unable to validate`).
26
+ * A child `relationField` / `autoRelate` is an instance link, not a substitute
27
+ * for a join owned here, and does not populate a parent `relatedRecords` widget.
28
+ */
29
+ export interface AppRelationship<Target extends AppOrElementRef | TableRef = AppOrElementRef | TableRef> {
30
+ readonly target: Target;
31
+ readonly columns: readonly AppRelationshipColumn<Target>[];
14
32
  /** Uses the same typed filter DSL as access policies. */
15
33
  readonly filter?: Filter;
16
34
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * AutoRelation columns are equality joins of comparable stored values.
3
+ *
4
+ * System `id` is HANDLE (`EDKBUILD-17`), not the record UUID. A `relationField`
5
+ * or dynamic dropdown stores a related-record picklist reference. The platform
6
+ * rejects HANDLE → that stored value on create with `Unable to validate`.
7
+ *
8
+ * Proven create pairs:
9
+ * - TEXT → TEXT
10
+ * - source `relationField` → related title or id (HANDLE)
11
+ *
12
+ * Put the relation field on this object's `field` side. Do not use a child
13
+ * `relationField` or dynamic dropdown as `relatedField` against parent system
14
+ * `id`.
15
+ */
16
+ export declare const HANDLE_TO_RELATION_JOIN_ERROR: string;
17
+ interface FieldTypeProbe {
18
+ readonly fieldType?: string;
19
+ }
20
+ export declare function isHandleRelationshipField(field: string | FieldTypeProbe | undefined): boolean;
21
+ export declare function isRelationRelationshipField(field: FieldTypeProbe | undefined): boolean;
22
+ /** Returns the contract error when this column pair is not createable. */
23
+ export declare function autoRelationColumnError(field: string | FieldTypeProbe | undefined, relatedField: FieldTypeProbe | undefined): string | undefined;
24
+ export {};
@@ -0,0 +1,41 @@
1
+ /**
2
+ * AutoRelation columns are equality joins of comparable stored values.
3
+ *
4
+ * System `id` is HANDLE (`EDKBUILD-17`), not the record UUID. A `relationField`
5
+ * or dynamic dropdown stores a related-record picklist reference. The platform
6
+ * rejects HANDLE → that stored value on create with `Unable to validate`.
7
+ *
8
+ * Proven create pairs:
9
+ * - TEXT → TEXT
10
+ * - source `relationField` → related title or id (HANDLE)
11
+ *
12
+ * Put the relation field on this object's `field` side. Do not use a child
13
+ * `relationField` or dynamic dropdown as `relatedField` against parent system
14
+ * `id`.
15
+ */
16
+ export const HANDLE_TO_RELATION_JOIN_ERROR = 'AutoRelation cannot join system "id" (HANDLE) to a relationField or dynamic dropdown. ' +
17
+ 'The platform rejects that pair on create with "Unable to validate". ' +
18
+ "Put the relationField on this object's field side and match the related " +
19
+ "object's title or id, or join comparable scalars (text/handle/number/…). " +
20
+ "A child relationField + autoRelate is an instance link, not this parent join";
21
+ const RELATED_PICKLIST_TYPES = new Set(["RELATION", "PICKLIST", "MULTI_PICKLIST"]);
22
+ export function isHandleRelationshipField(field) {
23
+ if (field === "id")
24
+ return true;
25
+ if (typeof field === "object") {
26
+ const type = field.fieldType?.toUpperCase();
27
+ return type === "HANDLE";
28
+ }
29
+ return false;
30
+ }
31
+ export function isRelationRelationshipField(field) {
32
+ const type = field?.fieldType?.toUpperCase();
33
+ return type !== undefined && RELATED_PICKLIST_TYPES.has(type);
34
+ }
35
+ /** Returns the contract error when this column pair is not createable. */
36
+ export function autoRelationColumnError(field, relatedField) {
37
+ if (isHandleRelationshipField(field) && isRelationRelationshipField(relatedField)) {
38
+ return HANDLE_TO_RELATION_JOIN_ERROR;
39
+ }
40
+ return undefined;
41
+ }
@@ -1,8 +1,8 @@
1
1
  import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
3
  import { filterFromTf } from "../access-policy/from-tf.js";
4
- import { fieldKeyFromTfRef, fieldKeyFromTfValue } from "../field/from-tf.js";
5
- import { dataAspectDisplayName, dataAspectRefName } from "../shared/aspect-target-from-tf.js";
4
+ import { decodeForeignDataField, fieldKeyFromTfRef, fieldKeyFromTfValue } from "../field/from-tf.js";
5
+ import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
6
6
  import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
7
7
  import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
8
8
  const KNOWN_ATTRS = new Set(["object_id", "related_object_id", "columns", "filter"]);
@@ -123,19 +123,7 @@ function targetRef(value, owner, ctx) {
123
123
  const dataLabel = dataRefLabel(value, type);
124
124
  if (dataLabel !== undefined) {
125
125
  if (kind === "app" || kind === "element") {
126
- const displayName = dataAspectDisplayName(ctx, kind, dataLabel);
127
- const refName = dataAspectRefName(ctx, kind, dataLabel, displayName);
128
- const attrs = ctx.dataAttrs?.(type, dataLabel);
129
- const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
130
- return {
131
- kind,
132
- key: refName ?? tfLabelToTsLabel(dataLabel),
133
- name: displayName ?? refName ?? tfLabelToTsLabel(dataLabel),
134
- tfLabel: dataLabel,
135
- managed: false,
136
- ...(namespace !== undefined ? { namespace } : {}),
137
- ...(refName !== undefined ? { catalogRef: true } : {}),
138
- };
126
+ return { kind, tfLabel: dataLabel, managed: false, ...resolveDataAspectTarget(ctx, kind, dataLabel) };
139
127
  }
140
128
  const name = ctx.dataName(type, dataLabel) ?? tfLabelToTsLabel(dataLabel);
141
129
  return { kind, key: tfLabelToTsLabel(dataLabel), name, tfLabel: dataLabel, managed: false };
@@ -146,6 +134,18 @@ function targetRef(value, owner, ctx) {
146
134
  function relatedFieldRef(value, target, ctx) {
147
135
  if (value === undefined)
148
136
  return undefined;
137
+ if (isTfExpr(value) && value.$expr === "resource-attr" && value.path.length === 1 && value.path[0] === "id") {
138
+ const targetType = target.kind === "app"
139
+ ? "elementum_app"
140
+ : target.kind === "element"
141
+ ? "elementum_element"
142
+ : target.kind === "table"
143
+ ? "elementum_table"
144
+ : undefined;
145
+ if (value.type === RELATIONSHIP_RESOURCE_TYPE || value.type === targetType) {
146
+ return { kind: "recordIdentity", key: "id", name: "Record ID", target };
147
+ }
148
+ }
149
149
  if (isTfExpr(value) && value.$expr === "resource-attr" && value.path.length === 1 && value.path[0] === "id") {
150
150
  const subType = SUB_TYPE_BY_RESOURCE.get(value.type);
151
151
  if (subType !== undefined) {
@@ -161,40 +161,25 @@ function relatedFieldRef(value, target, ctx) {
161
161
  }
162
162
  const dataLabel = dataRefLabel(value, "elementum_field");
163
163
  if (dataLabel !== undefined) {
164
+ const decoded = decodeForeignDataField(dataLabel, {
165
+ key: target.key,
166
+ name: target.name,
167
+ namespace: target.namespace,
168
+ kind: target.kind,
169
+ }, ctx);
164
170
  const resolved = ctx.foreignFieldRefsByDataAddress?.get(`elementum_field.${dataLabel}`);
165
- if (resolved !== undefined && resolved.ownerRefName === target.key) {
166
- return {
167
- kind: target.kind === "table" ? "tableColumn" : "field",
168
- key: resolved.fieldKey,
169
- name: ctx.dataName("elementum_field", dataLabel) ?? resolved.fieldName ?? resolved.fieldKey,
170
- parent: resolved.ownerRefName,
171
- fieldType: resolved.fieldType ?? "TEXT",
172
- catalogRef: true,
173
- ...(resolved.ownerKind !== undefined ? { parentKind: resolved.ownerKind } : {}),
174
- ...(resolved.ownerName !== undefined ? { parentName: resolved.ownerName } : {}),
175
- ...(resolved.ownerNamespace !== undefined ? { parentNamespace: resolved.ownerNamespace } : {}),
176
- };
177
- }
178
- const name = ctx.dataName("elementum_field", dataLabel) ?? tfLabelToTsLabel(dataLabel);
179
- // The target may already be a full on-disk catalog rather than a ref-only
180
- // dependency from this one export stream. Resolve the exported field's
181
- // display name against that catalog before falling back to the data label;
182
- // the latter is an exporter implementation label, not a public field key.
183
- const catalogFieldKey = ctx.fieldNamesByOwnerRefName?.get(target.key)?.get(name.toLowerCase());
184
- if (catalogFieldKey !== undefined) {
185
- return {
186
- kind: target.kind === "table" ? "tableColumn" : "field",
187
- key: catalogFieldKey,
188
- name,
189
- parent: target.key,
190
- fieldType: "TEXT",
191
- catalogRef: true,
192
- ...(target.kind === "app" || target.kind === "element" ? { parentKind: target.kind } : {}),
193
- parentName: target.name,
194
- ...(target.namespace !== undefined ? { parentNamespace: target.namespace } : {}),
195
- };
196
- }
197
- return { kind: target.kind === "table" ? "tableColumn" : "field", key: tfLabelToTsLabel(dataLabel), name, parent: target.key, fieldType: "TEXT" };
171
+ const catalogHit = decoded.key !== tfLabelToTsLabel(dataLabel);
172
+ return {
173
+ kind: target.kind === "table" ? "tableColumn" : "field",
174
+ key: decoded.key,
175
+ name: decoded.name,
176
+ parent: resolved?.ownerRefName ?? target.key,
177
+ fieldType: decoded.fieldType ?? "TEXT",
178
+ ...(catalogHit ? { catalogRef: true } : {}),
179
+ ...(resolved?.ownerKind !== undefined ? { parentKind: resolved.ownerKind } : target.kind === "app" || target.kind === "element" ? { parentKind: target.kind } : {}),
180
+ ...(resolved?.ownerName !== undefined ? { parentName: resolved.ownerName } : target.name !== undefined ? { parentName: target.name } : {}),
181
+ ...(resolved?.ownerNamespace !== undefined ? { parentNamespace: resolved.ownerNamespace } : target.namespace !== undefined ? { parentNamespace: target.namespace } : {}),
182
+ };
198
183
  }
199
184
  const scope = target.kind === "element" ? "element" : "app";
200
185
  const key = fieldKeyFromTfValue(value, target.key, target.tfLabel ?? target.key, scope, ctx);
@@ -9,6 +9,7 @@ interface RefWire {
9
9
  readonly parent?: string;
10
10
  readonly fieldType?: string;
11
11
  readonly tfLabel?: string;
12
+ readonly target?: RefWire | string;
12
13
  }
13
14
  export interface RelationshipWire {
14
15
  readonly target?: RefWire;
@@ -4,6 +4,7 @@ import { filterToTf } from "../access-policy/to-tf.js";
4
4
  import { resolveForeignRef } from "../shared/foreign-ref.js";
5
5
  import { fieldRefToTfValue } from "../field/to-tf.js";
6
6
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
7
+ import { autoRelationColumnError } from "./column-contract.js";
7
8
  import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
8
9
  export function relationshipsToTf(relationships, opts) {
9
10
  const blocks = [];
@@ -17,12 +18,24 @@ export function relationshipsToTf(relationships, opts) {
17
18
  if (target === undefined)
18
19
  continue;
19
20
  const columns = [];
21
+ let droppedInvalidJoin = false;
20
22
  for (const [index, column] of (relationship.columns ?? []).entries()) {
21
- const field = resolveOwnerField(column.field, `${where}.columns[${index}].field`, opts);
22
- const relatedField = resolveRelatedField(column.relatedField, target, `${where}.columns[${index}].relatedField`, opts);
23
+ const columnWhere = `${where}.columns[${index}]`;
24
+ const contractError = autoRelationColumnError(column.field, column.relatedField);
25
+ if (contractError !== undefined) {
26
+ opts.diagnostics.push(`${columnWhere}: ${contractError}; dropped`);
27
+ droppedInvalidJoin = true;
28
+ continue;
29
+ }
30
+ const field = resolveOwnerField(column.field, `${columnWhere}.field`, opts);
31
+ const relatedField = resolveRelatedField(column.relatedField, target, `${columnWhere}.relatedField`, opts);
23
32
  if (field !== undefined && relatedField !== undefined)
24
33
  columns.push({ field_id: field, related_field_id: relatedField });
25
34
  }
35
+ if (columns.length === 0 && droppedInvalidJoin) {
36
+ opts.diagnostics.push(`${where}: no valid join columns remain; dropped`);
37
+ continue;
38
+ }
26
39
  const attrs = {
27
40
  object_id: opts.objectId,
28
41
  related_object_id: target.value,
@@ -117,6 +130,24 @@ function resolveTarget(value, where, opts) {
117
130
  };
118
131
  }
119
132
  function resolveRelatedField(value, target, where, opts) {
133
+ if (value?.__kind === "recordIdentity") {
134
+ if (value.target === undefined) {
135
+ opts.diagnostics.push(`${where}: record identity has no target; dropped`);
136
+ return undefined;
137
+ }
138
+ if (typeof value.target === "string") {
139
+ opts.diagnostics.push(`${where}: record identity target must be a typed reference, not a string; dropped`);
140
+ return undefined;
141
+ }
142
+ const identityTarget = resolveTarget(value.target, `${where}.target`, opts);
143
+ if (identityTarget === undefined)
144
+ return undefined;
145
+ if (identityTarget.kind !== target.kind || identityTarget.refName !== target.refName) {
146
+ opts.diagnostics.push(`${where}: record identity target does not match relationship target; dropped`);
147
+ return undefined;
148
+ }
149
+ return target.value;
150
+ }
120
151
  const refName = value?.refName ?? "";
121
152
  if (refName === "") {
122
153
  opts.diagnostics.push(`${where}: field has no refName; dropped`);
@@ -7,3 +7,18 @@ import type { FromTfContext } from "../../engine/pull/context.js";
7
7
  export declare function dataAspectDisplayName(ctx: FromTfContext, kind: "app" | "element", label: string): string | undefined;
8
8
  /** Resolve the stable pulled catalog key for the same foreign lookup. */
9
9
  export declare function dataAspectRefName(ctx: FromTfContext, kind: "app" | "element", label: string, displayName?: string): string | undefined;
10
+ export interface ResolvedAspectTarget {
11
+ readonly key: string;
12
+ readonly name: string;
13
+ readonly namespace?: string;
14
+ /** `key`/`name` are the target's real pulled catalog identity, not a guess. */
15
+ readonly catalogRef?: true;
16
+ }
17
+ /**
18
+ * Resolve a foreign app/element data lookup to the full identity a caller
19
+ * needs to build its own ref shape: the real display name/refName when the
20
+ * target was pulled separately, degrading to a tfLabel-derived guess (with
21
+ * the real namespace still attached) when it wasn't - never a bare guessed
22
+ * name with no namespace, which matches nothing on the platform.
23
+ */
24
+ export declare function resolveDataAspectTarget(ctx: FromTfContext, kind: "app" | "element", dataLabel: string): ResolvedAspectTarget;
@@ -1,3 +1,4 @@
1
+ import { tfLabelToTsLabel } from "../../engine/tf/index.js";
1
2
  /**
2
3
  * Resolve a foreign app/element data lookup to its display name. Ref-only
3
4
  * lookups are intentionally namespace-only, so fall back through the
@@ -37,3 +38,23 @@ export function dataAspectRefName(ctx, kind, label, displayName) {
37
38
  const byName = kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames;
38
39
  return name === undefined ? undefined : byName?.get(name);
39
40
  }
41
+ /**
42
+ * Resolve a foreign app/element data lookup to the full identity a caller
43
+ * needs to build its own ref shape: the real display name/refName when the
44
+ * target was pulled separately, degrading to a tfLabel-derived guess (with
45
+ * the real namespace still attached) when it wasn't - never a bare guessed
46
+ * name with no namespace, which matches nothing on the platform.
47
+ */
48
+ export function resolveDataAspectTarget(ctx, kind, dataLabel) {
49
+ const type = kind === "app" ? "elementum_app" : "elementum_element";
50
+ const displayName = dataAspectDisplayName(ctx, kind, dataLabel);
51
+ const refName = dataAspectRefName(ctx, kind, dataLabel, displayName);
52
+ const attrs = ctx.dataAttrs?.(type, dataLabel);
53
+ const namespace = typeof attrs?.namespace === "string" ? attrs.namespace : undefined;
54
+ return {
55
+ key: refName ?? tfLabelToTsLabel(dataLabel),
56
+ name: displayName ?? refName ?? tfLabelToTsLabel(dataLabel),
57
+ ...(namespace !== undefined ? { namespace } : {}),
58
+ ...(refName !== undefined ? { catalogRef: true } : {}),
59
+ };
60
+ }
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * This bridges compile-time type safety with runtime reference building.
10
10
  */
11
- import type { CalculationTypeOfValue, Ref, Simplify, ToRefs } from "./ref.js";
11
+ import type { CalculationTypeOfValue, Ref, Simplify } from "./ref.js";
12
12
  /**
13
13
  * Deep ref — a `Ref<T>` that also exposes `T`'s string-keyed properties as
14
14
  * nested deep refs. This is what makes `ctx.actions.x.record.id` and
@@ -75,12 +75,15 @@ export declare function createActionOutputProxy<T>(actionRefKey: string): DeepRe
75
75
  export declare function createActionsProxy<TActions extends Record<string, unknown>>(actionNames: string[]): Context<never, TActions>["actions"];
76
76
  /**
77
77
  * A forEach item that is both a Ref to the whole item and a proxy
78
- * with typed field access: item.fieldName → Ref<T[fieldName]>.
78
+ * with typed field access: item.fieldName → DeepRef<T[fieldName]>, drilling
79
+ * into nested object fields (e.g. a DropdownValue's .label) the same way
80
+ * createTriggerProxy/createActionOutputProxy do.
79
81
  */
80
- export type ForEachItem<T> = Ref<T> & ToRefs<T>;
82
+ export type ForEachItem<T> = Ref<T> & DeepRefs<T>;
81
83
  /**
82
84
  * Creates a forEach item proxy.
83
85
  * item.fieldName → Ref with { kind: "forEach", forEachActionName, name: "fieldName" }
86
+ * item.fieldName.nested → Ref with { ..., name: "fieldName.nested" }
84
87
  * Accessing the item directly (without a property) returns a Ref to the whole item.
85
88
  */
86
89
  export declare function createForEachItemProxy<T>(forEachActionName: string): ForEachItem<T>;
@@ -100,9 +100,27 @@ export function createActionsProxy(actionNames) {
100
100
  },
101
101
  });
102
102
  }
103
+ /**
104
+ * Ref to a forEach item field path; further property access extends `name`
105
+ * with dot segments, mirroring createTriggerFieldRef/createActionOutputFieldRef -
106
+ * without this recursion, a nested object field (e.g. item.flow.label) would
107
+ * return a plain, non-proxied Ref from the first hop and fail on the second.
108
+ */
109
+ function createForEachItemFieldRef(forEachActionName, path) {
110
+ const base = createRef({ kind: "forEach", forEachActionName, name: path });
111
+ return new Proxy(base, {
112
+ get(target, prop, receiver) {
113
+ if (typeof prop === "symbol" || prop === "__data" || prop === "__type" || prop === "__calculationType") {
114
+ return Reflect.get(target, prop, receiver);
115
+ }
116
+ return createForEachItemFieldRef(forEachActionName, `${path}.${String(prop)}`);
117
+ },
118
+ });
119
+ }
103
120
  /**
104
121
  * Creates a forEach item proxy.
105
122
  * item.fieldName → Ref with { kind: "forEach", forEachActionName, name: "fieldName" }
123
+ * item.fieldName.nested → Ref with { ..., name: "fieldName.nested" }
106
124
  * Accessing the item directly (without a property) returns a Ref to the whole item.
107
125
  */
108
126
  export function createForEachItemProxy(forEachActionName) {
@@ -112,7 +130,7 @@ export function createForEachItemProxy(forEachActionName) {
112
130
  if (typeof prop === "symbol" || prop === "__data" || prop === "__type" || prop === "__calculationType") {
113
131
  return target[prop];
114
132
  }
115
- return createRef({ kind: "forEach", forEachActionName, name: prop });
133
+ return createForEachItemFieldRef(forEachActionName, prop);
116
134
  },
117
135
  });
118
136
  }
@@ -11,6 +11,13 @@ export type FilterReferenceValue = FilterReference | {
11
11
  readonly __rawFilterReference: string;
12
12
  };
13
13
  export declare function fieldTypeToValueType(type: WorkflowFieldType | string | undefined): ValueType;
14
+ /**
15
+ * GraphQL `ValueType` has no PICKLIST member. A Dropdown option id is UUID;
16
+ * its display label is TEXT. USER/GROUP `.id` is UUID; `.name`/`.email` are TEXT.
17
+ * Used when a trigger-record Ref has no authored `filter.uuid()` / `filter.text()`
18
+ * wrapper — the field's WorkflowFieldType + path suffix is the authority.
19
+ */
20
+ export declare function referenceValueTypeForField(fieldType: WorkflowFieldType | string | undefined, suffix?: string): ValueType | undefined;
14
21
  declare const FILTER_REFERENCE_BRAND: unique symbol;
15
22
  export interface FilterReferenceInput {
16
23
  readonly [FILTER_REFERENCE_BRAND]: true;
@@ -18,10 +18,38 @@ export function fieldTypeToValueType(type) {
18
18
  case "ASPECT_RECORD":
19
19
  case "ASPECT_RECORD_ID":
20
20
  case "ASPECT_FIELD_ID":
21
+ case "PICKLIST_ID":
22
+ case "MULTI_PICKLIST_ID":
21
23
  return "UUID";
22
24
  default: return "TEXT";
23
25
  }
24
26
  }
27
+ /**
28
+ * GraphQL `ValueType` has no PICKLIST member. A Dropdown option id is UUID;
29
+ * its display label is TEXT. USER/GROUP `.id` is UUID; `.name`/`.email` are TEXT.
30
+ * Used when a trigger-record Ref has no authored `filter.uuid()` / `filter.text()`
31
+ * wrapper — the field's WorkflowFieldType + path suffix is the authority.
32
+ */
33
+ export function referenceValueTypeForField(fieldType, suffix = "") {
34
+ if (fieldType === undefined)
35
+ return undefined;
36
+ const normalized = suffix.toLowerCase();
37
+ if (fieldType === "PICKLIST" || fieldType === "MULTI_PICKLIST" || fieldType === "PICKLIST_ID") {
38
+ if (normalized === "label")
39
+ return "TEXT";
40
+ if (normalized === "id" || normalized === "")
41
+ return "UUID";
42
+ return undefined;
43
+ }
44
+ if (fieldType === "USER" || fieldType === "GROUP" || fieldType === "USER_GROUP" || fieldType === "USER_ID" || fieldType === "GROUP_ID") {
45
+ if (normalized === "id" || normalized === "")
46
+ return "UUID";
47
+ return "TEXT";
48
+ }
49
+ if (normalized === "" || normalized === "id")
50
+ return fieldTypeToValueType(fieldType);
51
+ return undefined;
52
+ }
25
53
  const FILTER_REFERENCE_BRAND = Symbol("FilterReferenceInput");
26
54
  function referenceInput(ref, valueType, options) {
27
55
  return { [FILTER_REFERENCE_BRAND]: true, ref, valueType, ...(options?.multiple === true && { multiple: true }) };
@@ -113,6 +113,8 @@ function printFilterValue(value, codec, call, quote) {
113
113
  case "UUID":
114
114
  helper = "uuid";
115
115
  break;
116
+ case undefined:
117
+ return `${codec.reference(value.value)}${options}`;
116
118
  default: throw new Error(`unsupported filter reference type "${value.realType}"`);
117
119
  }
118
120
  return call(helper, `${codec.reference(value.value)}${options}`);