@elementumai/edk 0.13.0 → 0.13.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 (101) hide show
  1. package/README.md +6 -2
  2. package/dist-sdk/src/catalog/factories.js +8 -2
  3. package/dist-sdk/src/catalog/types.d.ts +5 -0
  4. package/dist-sdk/src/engine/coverage-gaps.d.ts +12 -0
  5. package/dist-sdk/src/engine/coverage-gaps.js +23 -0
  6. package/dist-sdk/src/engine/ei/run.d.ts +8 -0
  7. package/dist-sdk/src/engine/ei/run.js +46 -7
  8. package/dist-sdk/src/engine/progress.d.ts +1 -0
  9. package/dist-sdk/src/engine/progress.js +6 -0
  10. package/dist-sdk/src/engine/pull/context.d.ts +24 -0
  11. package/dist-sdk/src/engine/pull/result-output.d.ts +2 -0
  12. package/dist-sdk/src/engine/pull/result-output.js +1 -1
  13. package/dist-sdk/src/engine/pull/stream-root.d.ts +11 -0
  14. package/dist-sdk/src/engine/pull/stream-root.js +22 -6
  15. package/dist-sdk/src/engine/tf/escape.d.ts +8 -3
  16. package/dist-sdk/src/engine/tf/escape.js +17 -4
  17. package/dist-sdk/src/engine/workspace/authoring-layout.js +16 -2
  18. package/dist-sdk/src/entities/access-policy/from-tf.js +4 -7
  19. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -1
  20. package/dist-sdk/src/entities/agent/from-tf.d.ts +2 -0
  21. package/dist-sdk/src/entities/agent/from-tf.js +28 -1
  22. package/dist-sdk/src/entities/agent/module.js +1 -0
  23. package/dist-sdk/src/entities/agent/to-tf.d.ts +3 -1
  24. package/dist-sdk/src/entities/agent/to-tf.js +21 -3
  25. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  26. package/dist-sdk/src/entities/app/from-tf.js +6 -23
  27. package/dist-sdk/src/entities/app/index.d.ts +1 -1
  28. package/dist-sdk/src/entities/app/module.js +2 -0
  29. package/dist-sdk/src/entities/approval-chain/from-tf.js +2 -2
  30. package/dist-sdk/src/entities/automation/build.d.ts +10 -1
  31. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +1 -0
  32. package/dist-sdk/src/entities/automation/from-tf.js +72 -11
  33. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  34. package/dist-sdk/src/entities/automation/module.js +12 -0
  35. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +23 -3
  36. package/dist-sdk/src/entities/automation/system-ref-name.js +86 -4
  37. package/dist-sdk/src/entities/automation/to-tf.d.ts +5 -1
  38. package/dist-sdk/src/entities/automation/to-tf.js +312 -51
  39. package/dist-sdk/src/entities/automation/triggers.d.ts +5 -1
  40. package/dist-sdk/src/entities/automation/workflow-output.d.ts +7 -0
  41. package/dist-sdk/src/entities/automation/workflow-output.js +8 -0
  42. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +3 -1
  43. package/dist-sdk/src/entities/dashboard/from-tf.js +42 -2
  44. package/dist-sdk/src/entities/dashboard/to-tf.js +9 -1
  45. package/dist-sdk/src/entities/dashboard-widget-order/module.d.ts +10 -0
  46. package/dist-sdk/src/entities/dashboard-widget-order/module.js +25 -0
  47. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +31 -0
  48. package/dist-sdk/src/entities/dashboard-widget-order/order.js +102 -0
  49. package/dist-sdk/src/entities/dynamic-layout/lint.d.ts +7 -0
  50. package/dist-sdk/src/entities/dynamic-layout/lint.js +48 -0
  51. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +2 -0
  52. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  53. package/dist-sdk/src/entities/element/from-tf.js +5 -21
  54. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  55. package/dist-sdk/src/entities/element/module.js +2 -0
  56. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  57. package/dist-sdk/src/entities/field/from-tf.d.ts +25 -2
  58. package/dist-sdk/src/entities/field/from-tf.js +119 -14
  59. package/dist-sdk/src/entities/relationship/from-tf.js +2 -2
  60. package/dist-sdk/src/entities/role/build.d.ts +3 -4
  61. package/dist-sdk/src/entities/search-table/build.d.ts +9 -3
  62. package/dist-sdk/src/entities/search-table/build.js +4 -4
  63. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  64. package/dist-sdk/src/entities/search-table/to-tf.js +20 -2
  65. package/dist-sdk/src/entities/shared/context.d.ts +14 -1
  66. package/dist-sdk/src/entities/shared/filters/index.d.ts +24 -13
  67. package/dist-sdk/src/entities/shared/filters/index.js +12 -1
  68. package/dist-sdk/src/entities/shared/filters/print.d.ts +2 -0
  69. package/dist-sdk/src/entities/shared/filters/print.js +15 -6
  70. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +4 -0
  71. package/dist-sdk/src/entities/shared/filters/tf-codec.js +16 -0
  72. package/dist-sdk/src/entities/shared/filters/types.d.ts +4 -0
  73. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  74. package/dist-sdk/src/entities/shared/tool-field-ref.js +2 -5
  75. package/dist-sdk/src/entities/task/from-tf.js +3 -3
  76. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +3 -3
  77. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +6 -4
  78. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +4 -2
  79. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +6 -1
  80. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +14 -2
  81. package/dist-sdk/src/entities/view/custom-view-references.d.ts +33 -0
  82. package/dist-sdk/src/entities/view/custom-view-references.js +140 -0
  83. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +16 -9
  84. package/dist-sdk/src/entities/view/custom-view-validate.js +38 -18
  85. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  86. package/dist-sdk/src/entities/view/layout-lint.d.ts +26 -0
  87. package/dist-sdk/src/entities/view/layout-lint.js +50 -0
  88. package/dist-sdk/src/entities/view/to-tf.d.ts +2 -0
  89. package/dist-sdk/src/entities/view/to-tf.js +69 -47
  90. package/dist-sdk/src/entities/visual-flow/build.d.ts +8 -1
  91. package/dist-sdk/src/entities/visual-flow/from-tf.js +16 -0
  92. package/dist-sdk/src/entities/visual-flow/initiate.d.ts +12 -0
  93. package/dist-sdk/src/entities/visual-flow/initiate.js +12 -0
  94. package/dist-sdk/src/entities/visual-flow/module.js +52 -1
  95. package/dist-sdk/src/entities/visual-flow/to-tf.js +16 -2
  96. package/dist-sdk/src/entities/widget/from-tf.js +6 -6
  97. package/dist-sdk/src/graph/index.d.ts +4 -0
  98. package/dist-sdk/src/graph/index.js +1 -0
  99. package/dist-sdk/src/graph/modules.js +2 -0
  100. package/dist-sdk/src/graph/types.d.ts +36 -1
  101. package/package.json +2 -2
@@ -20,6 +20,93 @@ import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS, ELEMENT_SYSTEM_FIELD_KEYS, platformAud
20
20
  import { resolveDataAspectTarget, resolveDataTaskTarget } from "../shared/aspect-target-from-tf.js";
21
21
  const ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_AUDIT_SYSTEM_FIELD_KEYS);
22
22
  const ELEMENT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_SYSTEM_FIELD_KEYS);
23
+ /**
24
+ * System-field keys a pulled custom field of this owner scope is re-keyed off
25
+ * (#1871). Apps and standalone tasks share the app set; elements have their own.
26
+ */
27
+ function reservedFieldKeysForScope(scope) {
28
+ return scope === "element" ? ELEMENT_SYSTEM_FIELD_KEY_SET : SYSTEM_FIELD_KEY_SET;
29
+ }
30
+ const OWNER_RESOURCE_TYPE_BY_SCOPE = {
31
+ app: "elementum_app",
32
+ element: "elementum_element",
33
+ task: "elementum_task",
34
+ };
35
+ /**
36
+ * Bag keys for all of an owner's field labels, claimed in two passes (#1871
37
+ * B1): labels whose natural key isn't reserved claim it first, then labels
38
+ * whose natural key is a system key re-key to `<key>Custom`, `<key>Custom2`, …
39
+ * So a field named like a re-key (`closed_at_custom` → `closedAtCustom`) keeps
40
+ * its natural key. The result depends only on the set of labels, so the
41
+ * field extractor and every reference to one of the owner's fields agree on
42
+ * the key (edk#2933).
43
+ */
44
+ function claimFieldBagKeys(ownerTfLabel, scope, fieldLabels, diagnostics) {
45
+ const reservedKeys = reservedFieldKeysForScope(scope);
46
+ const nonReserved = [];
47
+ const reserved = [];
48
+ for (const label of fieldLabels) {
49
+ (reservedKeys.has(scopedLabelToBagKey(ownerTfLabel, label, scope)) ? reserved : nonReserved).push(label);
50
+ }
51
+ const usedKeys = new Set();
52
+ const claimed = new Map();
53
+ for (const label of [...nonReserved, ...reserved]) {
54
+ if (claimed.has(label))
55
+ continue;
56
+ claimed.set(label, bagKeyForPulledCustomField(ownerTfLabel, label, scope, reservedKeys, usedKeys, diagnostics));
57
+ }
58
+ return claimed;
59
+ }
60
+ /** Claimed field keys per extraction context, by `<scope>:<owner tfLabel>`. */
61
+ const claimedFieldKeysByCtx = new WeakMap();
62
+ function claimCacheFor(ctx) {
63
+ let byOwner = claimedFieldKeysByCtx.get(ctx);
64
+ if (byOwner === undefined) {
65
+ byOwner = new Map();
66
+ claimedFieldKeysByCtx.set(ctx, byOwner);
67
+ }
68
+ return byOwner;
69
+ }
70
+ /**
71
+ * The owner's claimed field keys in this context: the ones {@link fieldsFromTf}
72
+ * recorded, else claimed over the stream's field resources whose `object_id`
73
+ * names the owner (the same blocks fieldFromTf extracts). Undefined when the
74
+ * context can't list the stream's resources.
75
+ */
76
+ function ownerClaimedFieldKeys(ctx, ownerTfLabel, scope) {
77
+ if (ctx === undefined)
78
+ return undefined;
79
+ const cache = claimCacheFor(ctx);
80
+ const cacheKey = `${scope}:${ownerTfLabel}`;
81
+ const cached = cache.get(cacheKey);
82
+ if (cached !== undefined)
83
+ return cached;
84
+ if (ctx.resourcesOfType === undefined)
85
+ return undefined;
86
+ const ownerType = OWNER_RESOURCE_TYPE_BY_SCOPE[scope];
87
+ const labels = [];
88
+ for (const type of SUB_TYPE_BY_RESOURCE.keys()) {
89
+ for (const resource of ctx.resourcesOfType(type)) {
90
+ if (resourceRefLabel(resource.attrs["object_id"], ownerType) === ownerTfLabel)
91
+ labels.push(resource.label);
92
+ }
93
+ }
94
+ const claimed = claimFieldBagKeys(ownerTfLabel, scope, labels);
95
+ cache.set(cacheKey, claimed);
96
+ return claimed;
97
+ }
98
+ /**
99
+ * Bag key of an owner's custom field, by its Terraform label, as pull keys it
100
+ * (#1871, edk#2933). Every same-owner reference to a field (dropdown parents,
101
+ * dynamic configs, views, layouts, relationships, widgets, approval chains,
102
+ * access policies, tools) resolves through this, so a reference names the
103
+ * key the field itself was printed under. Without a context that lists the
104
+ * stream, a reserved natural falls back to `<key>Custom`.
105
+ */
106
+ export function pulledFieldBagKey(ownerTfLabel, fieldLabel, scope, ctx) {
107
+ return ownerClaimedFieldKeys(ctx, ownerTfLabel, scope)?.get(fieldLabel)
108
+ ?? bagKeyForPulledCustomField(ownerTfLabel, fieldLabel, scope, reservedFieldKeysForScope(scope));
109
+ }
23
110
  /**
24
111
  * Bag key for a pulled custom field resource. A key that matches a reserved
25
112
  * system-field key is rewritten to `<key>Custom` so pulled source builds
@@ -208,7 +295,7 @@ function selfRelatedField(v, owner, ctx) {
208
295
  const self = selfIdentity(owner, ctx);
209
296
  if (self === undefined || v === undefined)
210
297
  return undefined;
211
- const fieldKey = fieldKeyFromTfRef(v, owner.label, owner.scope ?? "app");
298
+ const fieldKey = fieldKeyFromTfRef(v, owner.label, owner.scope ?? "app", ctx);
212
299
  if (fieldKey === undefined || !isTfExpr(v) || v.$expr !== "resource-attr")
213
300
  return undefined;
214
301
  // A typed fieldRef, not catalog.<self>.fields.<key>: the app file cannot
@@ -247,12 +334,11 @@ function selfSystemField(v, owner, ctx) {
247
334
  fieldKey = stateRef.fieldKey;
248
335
  }
249
336
  else if (isTfExpr(v) && v.$expr === "local") {
250
- fieldKey = fieldKeyFromTfRef(v, owner.label, scope);
337
+ fieldKey = fieldKeyFromTfRef(v, owner.label, scope, ctx);
251
338
  }
252
339
  if (fieldKey === undefined)
253
340
  return undefined;
254
- const systemKeys = scope === "element" ? ELEMENT_SYSTEM_FIELD_KEY_SET : SYSTEM_FIELD_KEY_SET;
255
- if (!systemKeys.has(fieldKey))
341
+ if (!reservedFieldKeysForScope(scope).has(fieldKey))
256
342
  return undefined;
257
343
  // Custom fields that would collide are re-keyed to `<key>Custom` (#1871), so
258
344
  // a system-field local always names the platform field. Element audit still
@@ -384,7 +470,7 @@ function dynamicPicklistRecordFieldRef(value, owner, ctx) {
384
470
  if (owner.refName === undefined)
385
471
  throw new EntityTfError("record_field filter value requires a known owning app or element");
386
472
  const scope = owner.scope ?? "app";
387
- const fieldKey = fieldKeyFromTfRef(value, owner.label, scope) ?? fieldKeyFromTfValue(value, owner.refName, owner.label, scope, ctx);
473
+ const fieldKey = fieldKeyFromTfRef(value, owner.label, scope, ctx) ?? fieldKeyFromTfValue(value, owner.refName, owner.label, scope, ctx);
388
474
  if (fieldKey === undefined)
389
475
  throw new EntityTfError("record_field filter value field is not a field on the owning record");
390
476
  // A clone authors the record's fields under the clone's refName (edk#1481).
@@ -490,7 +576,7 @@ function dynamicConfigFromTf(value, owner, ctx, site) {
490
576
  }
491
577
  let parentFieldId;
492
578
  if (attrs["parent_field_id"] !== undefined) {
493
- parentFieldId = fieldKeyFromTfRef(attrs["parent_field_id"], owner.label, owner.scope ?? "app");
579
+ parentFieldId = fieldKeyFromTfRef(attrs["parent_field_id"], owner.label, owner.scope ?? "app", ctx);
494
580
  if (parentFieldId === undefined) {
495
581
  blockReplaceForcingDrop(ctx, site, "parent_field_id", "could not be resolved to a same-aspect field");
496
582
  }
@@ -609,7 +695,7 @@ function staticParentLinkageFromTf(value, optionsValue, owner, ctx, where) {
609
695
  const parentFieldValue = value["parent_field_id"];
610
696
  if (parentFieldValue === undefined)
611
697
  return undefined;
612
- const parentFieldKey = fieldKeyFromTfRef(parentFieldValue, owner.label, owner.scope ?? "app");
698
+ const parentFieldKey = fieldKeyFromTfRef(parentFieldValue, owner.label, owner.scope ?? "app", ctx);
613
699
  if (parentFieldKey === undefined) {
614
700
  ctx.diagnostics.push(`${where}: static_config.parent_field_id could not be resolved to a same-app field; dropped`);
615
701
  return undefined;
@@ -722,12 +808,32 @@ function dataLookupKey(type, attrs) {
722
808
  }
723
809
  return undefined;
724
810
  }
811
+ /**
812
+ * An owner's field blocks → their normalized entries, in the blocks' (live
813
+ * field) order. Keys are claimed up front over every field the owner owns
814
+ * (two passes, #1871 B1; see {@link claimFieldBagKeys}) and recorded on the
815
+ * context before any field is extracted, so a reference from one field to
816
+ * another (a dependent dropdown's parent, a dynamic config) and every later
817
+ * same-owner reference resolve to the key the field prints under. Fields
818
+ * print in the live order, not the claim order: a re-keyed field moved last
819
+ * would reorder the live fields on the next apply (edk#2920). Apps, elements
820
+ * and standalone tasks all extract fields here (edk#2933).
821
+ */
822
+ export function fieldsFromTf(fieldBlocks, owner, ctx) {
823
+ const scope = owner.scope ?? "app";
824
+ const ownedLabels = fieldBlocks.flatMap((block) => block.label !== undefined && SUB_TYPE_BY_RESOURCE.has(block.type ?? "") && resourceRefLabel(block.attrs["object_id"], owner.type) === owner.label
825
+ ? [block.label]
826
+ : []);
827
+ const claimed = claimFieldBagKeys(owner.label, scope, ownedLabels, ctx.diagnostics);
828
+ claimCacheFor(ctx).set(`${scope}:${owner.label}`, claimed);
829
+ return fieldBlocks.flatMap((block) => fieldFromTf(block, owner, ctx) ?? []);
830
+ }
725
831
  /**
726
832
  * One field block → its normalized entry; undefined = skipped with a
727
833
  * diagnostic (unknown resource type, or a field belonging to a different
728
834
  * owner — a recursive stream carries discovered aspects' fields too).
729
835
  */
730
- export function fieldFromTf(block, owner, ctx, usedKeys) {
836
+ export function fieldFromTf(block, owner, ctx) {
731
837
  const subType = SUB_TYPE_BY_RESOURCE.get(block.type ?? "");
732
838
  const fieldLabel = block.label;
733
839
  if (fieldLabel === undefined || fieldLabel === "") {
@@ -934,9 +1040,9 @@ export function fieldFromTf(block, owner, ctx, usedKeys) {
934
1040
  ctx.diagnostics.push(`${where}: unsupported include_type ${JSON.stringify(includeType)}; defaulted to AUTO`);
935
1041
  }
936
1042
  }
937
- const reservedKeys = scope === "element" ? ELEMENT_SYSTEM_FIELD_KEY_SET : SYSTEM_FIELD_KEY_SET;
1043
+ const reservedKeys = reservedFieldKeysForScope(scope);
938
1044
  const natural = scopedLabelToBagKey(owner.label, fieldLabel, scope);
939
- const key = bagKeyForPulledCustomField(owner.label, fieldLabel, scope, reservedKeys, usedKeys, ctx.diagnostics);
1045
+ const key = pulledFieldBagKey(owner.label, fieldLabel, scope, ctx);
940
1046
  return {
941
1047
  key,
942
1048
  ...(parentLinkage !== undefined && { parentLinkage }),
@@ -1066,7 +1172,7 @@ function allowListFromTf(typeKey, attrs, owner, ctx, site) {
1066
1172
  * fields, view field_ids/columns). Undefined for any other shape or an
1067
1173
  * unknown resource type.
1068
1174
  */
1069
- export function fieldKeyFromTfRef(v, ownerTfLabel, scope = "app") {
1175
+ export function fieldKeyFromTfRef(v, ownerTfLabel, scope = "app", ctx) {
1070
1176
  if (!isTfExpr(v))
1071
1177
  return undefined;
1072
1178
  if (v.$expr === "local" && ownerTfLabel !== undefined && v.path.length === 0) {
@@ -1084,8 +1190,7 @@ export function fieldKeyFromTfRef(v, ownerTfLabel, scope = "app") {
1084
1190
  const bare = ownerTfLabel !== undefined ? bareChildResourceLabel(ownerTfLabel, v.label, scope) : v.label;
1085
1191
  if (ownerTfLabel === undefined)
1086
1192
  return tfLabelToTsLabel(bare);
1087
- const reserved = scope === "element" ? ELEMENT_SYSTEM_FIELD_KEY_SET : SYSTEM_FIELD_KEY_SET;
1088
- return bagKeyForPulledCustomField(ownerTfLabel, v.label, scope, reserved);
1193
+ return pulledFieldBagKey(ownerTfLabel, v.label, scope, ctx);
1089
1194
  }
1090
1195
  /**
1091
1196
  * Resolve either a normal Terraform field reference or a raw platform field
@@ -1109,7 +1214,7 @@ export function fieldKeyFromTfValue(v, ownerRefName, ownerTfLabel, scope, ctx) {
1109
1214
  return key;
1110
1215
  }
1111
1216
  }
1112
- return fieldKeyFromTfRef(v, ownerTfLabel, scope);
1217
+ return fieldKeyFromTfRef(v, ownerTfLabel, scope, ctx);
1113
1218
  }
1114
1219
  /**
1115
1220
  * The key a view, layout or form entry prints from, when the owner also
@@ -239,7 +239,7 @@ function bareRelatedFieldRef(v, target, owner, ctx, site) {
239
239
  const targetLabel = ownTarget ? owner.label : target.managed === true ? target.tfLabel : undefined;
240
240
  if (imported !== undefined && subType !== undefined && targetLabel !== undefined && resourceRefLabel(imported.attrs["object_id"], targetResourceType(target)) === targetLabel) {
241
241
  const scope = target.kind === "element" ? "element" : "app";
242
- const key = fieldKeyFromTfRef(expr.resourceAttr(imported.type, imported.label, ["id"]), targetLabel, scope);
242
+ const key = fieldKeyFromTfRef(expr.resourceAttr(imported.type, imported.label, ["id"]), targetLabel, scope, ctx);
243
243
  if (key !== undefined) {
244
244
  return { kind: target.kind === "table" ? "tableColumn" : "field", key, name: key, parent: target.key, fieldType: subType.authoringType };
245
245
  }
@@ -285,7 +285,7 @@ function relatedFieldRef(value, target, ctx) {
285
285
  // value is already narrowed to a TfExpr above, so fieldKeyFromTfValue's
286
286
  // string-literal (state-registry) branch can never fire here - a plain
287
287
  // fieldKeyFromTfRef is what this branch actually needs.
288
- const key = fieldKeyFromTfRef(value, ownerLabel, scope);
288
+ const key = fieldKeyFromTfRef(value, ownerLabel, scope, ctx);
289
289
  if (key !== undefined)
290
290
  return { kind: target.kind === "table" ? "tableColumn" : "field", key, name: key, parent: target.key, fieldType: subType.authoringType };
291
291
  }
@@ -1,4 +1,5 @@
1
1
  import type { GroupRef } from "../../catalog/index.js";
2
+ import type { FilterUserRef } from "../shared/filters/index.js";
2
3
  import type { ServiceAccountRef } from "../service-account/ref.js";
3
4
  declare const roleAutoShareBrand: unique symbol;
4
5
  export type RoleAutoShare = string & {
@@ -45,10 +46,8 @@ export interface RolePermission {
45
46
  readonly level: RolePermissionLevel;
46
47
  readonly customPermissions?: readonly string[];
47
48
  }
48
- export interface RoleUserRef {
49
- readonly __kind: "user";
50
- readonly email: string;
51
- }
49
+ /** A user named by email. The same shape filters take as a value (#2891). */
50
+ export type RoleUserRef = FilterUserRef;
52
51
  export declare function userRef(email: string): RoleUserRef;
53
52
  export type RoleGroupRef = GroupRef;
54
53
  /** One custom app/element role. Managed Admin/Edit/View roles stay data lookups. */
@@ -34,11 +34,16 @@ type OwnerOption<Owner extends SearchTableOwner> = {
34
34
  type OwnedField<Owner extends SearchTableOwner> = Owner extends {
35
35
  readonly fields: infer Fields;
36
36
  } ? Fields extends Readonly<Record<string, FieldRef>> ? Fields[keyof Fields] : FieldRef<Owner["refName"]> : FieldRef<Owner["refName"]>;
37
- type CommonOptions<Owner extends SearchTableOwner> = EntityDeployOptions & OwnerOption<Owner> & {
38
- readonly name: string;
39
- };
37
+ type CommonOptions<Owner extends SearchTableOwner> = EntityDeployOptions & OwnerOption<Owner>;
40
38
  /** Options for an Elementum-managed element search table. */
41
39
  export type DefineSearchTableOptions<Owner extends SearchTableOwner = SearchTableOwner> = CommonOptions<Owner> & {
40
+ /**
41
+ * The table's platform name. Give every new search table one. Leave it
42
+ * unset only for an existing table the platform holds without a name
43
+ * (older tables predate the field); pull prints those without one, so
44
+ * the plan doesn't keep trying to set a name (#2937).
45
+ */
46
+ readonly name?: string;
42
47
  readonly attributeFields: readonly [OwnedField<Owner>, ...OwnedField<Owner>[]];
43
48
  readonly duration: SearchTableDuration;
44
49
  readonly targetLag: number;
@@ -49,6 +54,7 @@ export type DefineSearchTableOptions<Owner extends SearchTableOwner = SearchTabl
49
54
  };
50
55
  /** Options for linking an existing Cortex Search Service. */
51
56
  export type DefineLinkedSearchTableOptions<Owner extends SearchTableOwner = SearchTableOwner> = CommonOptions<Owner> & {
57
+ readonly name: string;
52
58
  readonly cloudLink: CloudLinkRef;
53
59
  readonly database: string;
54
60
  readonly schema: string;
@@ -54,7 +54,7 @@ function managedBody(opts) {
54
54
  }
55
55
  }
56
56
  return {
57
- name: opts.name,
57
+ ...(opts.name !== undefined ? { name: opts.name } : {}),
58
58
  attributeFieldIds: opts.attributeFields,
59
59
  duration: opts.duration,
60
60
  targetLag: opts.targetLag,
@@ -81,7 +81,7 @@ function configuredSearchTable(opts, variant, body) {
81
81
  const payload = slimTokens({ __variant: variant, ...body });
82
82
  return {
83
83
  ref(refName) {
84
- return { __kind: "searchTable", refName, name: opts.name, parent: owner.refName, __variant: variant };
84
+ return { __kind: "searchTable", refName, name: opts.name ?? refName, parent: owner.refName, __variant: variant };
85
85
  },
86
86
  def(refName) {
87
87
  return { kind: "searchTable", parent: owner.refName, refName, payload, ...(opts.enabled !== undefined ? { enabled: opts.enabled } : {}) };
@@ -90,8 +90,8 @@ function configuredSearchTable(opts, variant, body) {
90
90
  }
91
91
  /** Build an element-owned managed search table. */
92
92
  export function searchTable(opts) {
93
- if (opts.name.trim() === "")
94
- throw new EdkValidationError("searchTable requires a non-empty name.");
93
+ if (opts.name?.trim() === "")
94
+ throw new EdkValidationError("searchTable name must not be empty; omit it only for an existing unnamed table.");
95
95
  return configuredSearchTable(opts, "snowflake", managedBody(opts));
96
96
  }
97
97
  /** Link an existing Cortex Search Service to an element. */
@@ -36,7 +36,9 @@ parentScope, orgImportPath) {
36
36
  lines.push(` creationTimeout: ${quote(table.creationTimeout)},`);
37
37
  }
38
38
  else if (table.kind === "snowflake") {
39
- lines.push(` ${parentScope}: catalog${member(ownerRefName)},`, ` name: ${quote(table.name ?? table.refName)},`, ` attributeFields: [${table.attributeFieldKeys.map((key) => `catalog${member(ownerRefName)}.fields${member(key)}`).join(", ")}],`, ...(table.textIndexFieldKeys !== undefined
39
+ lines.push(` ${parentScope}: catalog${member(ownerRefName)},`,
40
+ // An unnamed platform table stays unnamed: inventing one plans `+ name` forever (#2937).
41
+ ...(table.name !== undefined ? [` name: ${quote(table.name)},`] : []), ` attributeFields: [${table.attributeFieldKeys.map((key) => `catalog${member(ownerRefName)}.fields${member(key)}`).join(", ")}],`, ...(table.textIndexFieldKeys !== undefined
40
42
  ? [` textIndexFields: [${table.textIndexFieldKeys.map((key) => `catalog${member(ownerRefName)}.fields${member(key)}`).join(", ")}],`]
41
43
  : []), ` vectorIndex: { field: catalog${member(ownerRefName)}.fields${member(table.fieldKey)}, service: ${connectorExpr(table.connectorKey)} },`, ` duration: searchTableDuration.${table.duration.toLowerCase()},`, ` targetLag: ${table.targetLag},`);
42
44
  if (table.warehouse !== undefined)
@@ -15,6 +15,18 @@ function fieldValue(token, ctx, where) {
15
15
  throw new EntityTfError(`${where}: field ${token.refName} has no Terraform resource mapping`);
16
16
  return value;
17
17
  }
18
+ /**
19
+ * The platform indexes the owner's record ID with every app or element search
20
+ * table and returns it first among the attribute fields, whether or not the
21
+ * source lists it. Build writes the same list, so a table that leaves out
22
+ * `fields.id` (or lists it later) doesn't plan a replacement on every apply,
23
+ * which `attribute_field_ids` forces on any difference (#2890).
24
+ */
25
+ function withRecordIdFirst(attributes, ownerTfLabel) {
26
+ const recordId = expr.local(`${ownerTfLabel}_id_field_id`);
27
+ const key = JSON.stringify(recordId);
28
+ return [recordId, ...attributes.filter((value) => JSON.stringify(value) !== key)];
29
+ }
18
30
  function connectorValue(token, ctx, where) {
19
31
  const key = token?.parent !== undefined ? `${token.parent}.${token.refName ?? ""}` : token?.refName ?? "";
20
32
  const resolved = ctx.orgRefs.byTsLabel(CONNECTOR_ORG_BAG, key);
@@ -82,11 +94,17 @@ export function searchTableToTf(entity, ctx) {
82
94
  throw new EntityTfError(`search table ${entity.refName}: no vector index`);
83
95
  if ((payload.vectorIndexes?.length ?? 0) > 1)
84
96
  throw new EntityTfError(`search table ${entity.refName}: Terraform supports exactly one vector index`);
97
+ const vectorField = fieldValue(index.fieldId, aspectCtx, `search table ${entity.refName}`);
98
+ if (JSON.stringify(vectorField) === JSON.stringify(expr.local(`${ctx.appTfLabel}_id_field_id`))) {
99
+ // Build always lists the record ID as an attribute (#2890), and the provider
100
+ // refuses a vector field that is also an attribute: say so here, naming it.
101
+ throw new EntityTfError(`search table ${entity.refName}: the record ID (fields.id) is always an attribute field, which the provider doesn't allow as the vector index field; index a text field`);
102
+ }
85
103
  const attrs = {
86
104
  object_id: objectId,
87
- field_id: fieldValue(index.fieldId, aspectCtx, `search table ${entity.refName}`),
105
+ field_id: vectorField,
88
106
  ai_provider_connector_id: connectorValue(index.aiProviderConnectorId, ctx, `search table ${entity.refName}`),
89
- attribute_field_ids: (payload.attributeFieldIds ?? []).map((field) => fieldValue(field, aspectCtx, `search table ${entity.refName}`)),
107
+ attribute_field_ids: withRecordIdFirst((payload.attributeFieldIds ?? []).map((field) => fieldValue(field, aspectCtx, `search table ${entity.refName}`)), ctx.appTfLabel),
90
108
  duration: payload.duration ?? "DAYS",
91
109
  target_lag: payload.targetLag ?? 1,
92
110
  };
@@ -79,7 +79,20 @@ export declare function createActionsProxy<TActions extends Record<string, unkno
79
79
  * into nested object fields (e.g. a DropdownValue's .label) the same way
80
80
  * createTriggerProxy/createActionOutputProxy do.
81
81
  */
82
- export type ForEachItem<T> = Ref<T> & DeepRefs<T>;
82
+ export type ForEachItem<T> = Ref<T> & DeepRefs<T> & {
83
+ /**
84
+ * The loop's own position, the same for every collection kind: whether
85
+ * this is the first or last item, the iteration number, and the number of
86
+ * items (the platform's "Is First Item", "Is Last Item", "Iteration" and
87
+ * "Total Size"), e.g. `filter.boolean(ctx.item.metadata.last)`.
88
+ */
89
+ readonly metadata: DeepRefs<{
90
+ readonly first: boolean;
91
+ readonly last: boolean;
92
+ readonly iteration: number;
93
+ readonly size: number;
94
+ }>;
95
+ };
83
96
  /**
84
97
  * Creates a forEach item proxy.
85
98
  * item.fieldName → Ref with { kind: "forEach", forEachActionName, name: "fieldName" }
@@ -116,25 +116,36 @@ export declare function recordField(field: FilterField, options?: {
116
116
  type: "RECORD_FIELD";
117
117
  }>;
118
118
  type AuthoredFilterValue = FilterValue<FilterField, FilterReferenceValue>;
119
- export type FilterInput = string | number | boolean | null | Ref<unknown> | FilterReferenceInput | FilterField | CurrentUserFilterValue | AuthoredFilterValue;
119
+ /** A user named by email, as `userRef("…")` returns: compares as that user's id (#2891). */
120
+ export interface FilterUserRef {
121
+ readonly __kind: "user";
122
+ readonly email: string;
123
+ }
124
+ export type FilterInput = string | number | boolean | null | Ref<unknown> | FilterReferenceInput | FilterField | CurrentUserFilterValue | FilterUserRef | AuthoredFilterValue;
125
+ /**
126
+ * What a filter that list views and access policies accept can compare with:
127
+ * `userRef` builds only in automation filters, so a comparison with it takes
128
+ * the wider overload, which views and access policies reject (as #1873).
129
+ */
130
+ export type TokenFilterInput = Exclude<FilterInput, FilterUserRef>;
120
131
  export type LeftRef = FilterField | Ref<unknown> | FilterReferenceInput | FieldLeftValue;
121
132
  type TokenLeftRef = FilterFieldToken | Ref<unknown> | FilterReferenceInput | FieldLeftValue<FilterFieldToken>;
122
133
  export declare const UNRESOLVED_REFERENCE_MARKER = "__edkUnresolvedReference::";
123
134
  export declare function refDataToFilterReference(data: import("../ref.js").RefData): FilterReference;
124
135
  export declare function toFilterValue(input: FilterInput, valueType?: ValueType): FilterValue<FilterField, FilterReferenceValue>;
125
- export declare function eq(left: TokenLeftRef, input: FilterInput, explicit?: ValueType): EqualsFilter<FilterFieldToken, FilterReferenceValue>;
136
+ export declare function eq(left: TokenLeftRef, input: TokenFilterInput, explicit?: ValueType): EqualsFilter<FilterFieldToken, FilterReferenceValue>;
126
137
  export declare function eq(left: LeftRef, input: FilterInput, explicit?: ValueType): EqualsFilter<FilterField, FilterReferenceValue>;
127
- export declare function neq(left: TokenLeftRef, input: FilterInput, explicit?: ValueType): EqualsFilter<FilterFieldToken, FilterReferenceValue>;
138
+ export declare function neq(left: TokenLeftRef, input: TokenFilterInput, explicit?: ValueType): EqualsFilter<FilterFieldToken, FilterReferenceValue>;
128
139
  export declare function neq(left: LeftRef, input: FilterInput, explicit?: ValueType): EqualsFilter<FilterField, FilterReferenceValue>;
129
- export declare function gt(left: TokenLeftRef, input: FilterInput, explicit?: ValueType): GreaterThanFilter<FilterFieldToken, FilterReferenceValue>;
140
+ export declare function gt(left: TokenLeftRef, input: TokenFilterInput, explicit?: ValueType): GreaterThanFilter<FilterFieldToken, FilterReferenceValue>;
130
141
  export declare function gt(left: LeftRef, input: FilterInput, explicit?: ValueType): GreaterThanFilter<FilterField, FilterReferenceValue>;
131
- export declare function gte(left: TokenLeftRef, input: FilterInput, explicit?: ValueType): GreaterThanEqualsFilter<FilterFieldToken, FilterReferenceValue>;
142
+ export declare function gte(left: TokenLeftRef, input: TokenFilterInput, explicit?: ValueType): GreaterThanEqualsFilter<FilterFieldToken, FilterReferenceValue>;
132
143
  export declare function gte(left: LeftRef, input: FilterInput, explicit?: ValueType): GreaterThanEqualsFilter<FilterField, FilterReferenceValue>;
133
- export declare function lt(left: TokenLeftRef, input: FilterInput, explicit?: ValueType): LessThanFilter<FilterFieldToken, FilterReferenceValue>;
144
+ export declare function lt(left: TokenLeftRef, input: TokenFilterInput, explicit?: ValueType): LessThanFilter<FilterFieldToken, FilterReferenceValue>;
134
145
  export declare function lt(left: LeftRef, input: FilterInput, explicit?: ValueType): LessThanFilter<FilterField, FilterReferenceValue>;
135
- export declare function lte(left: TokenLeftRef, input: FilterInput, explicit?: ValueType): LessThanEqualsFilter<FilterFieldToken, FilterReferenceValue>;
146
+ export declare function lte(left: TokenLeftRef, input: TokenFilterInput, explicit?: ValueType): LessThanEqualsFilter<FilterFieldToken, FilterReferenceValue>;
136
147
  export declare function lte(left: LeftRef, input: FilterInput, explicit?: ValueType): LessThanEqualsFilter<FilterField, FilterReferenceValue>;
137
- export declare function like(left: TokenLeftRef, input: FilterInput, options?: {
148
+ export declare function like(left: TokenLeftRef, input: TokenFilterInput, options?: {
138
149
  readonly not?: boolean;
139
150
  readonly caseInsensitive?: boolean;
140
151
  readonly mode?: Lowercase<LikeMode>;
@@ -152,11 +163,11 @@ export declare function isNull(left: LeftRef, options?: {
152
163
  }, explicit?: ValueType): IsNullFilter<FilterField, FilterReferenceValue>;
153
164
  export declare function isNotNull(left: TokenLeftRef, explicit?: ValueType): IsNullFilter<FilterFieldToken, FilterReferenceValue>;
154
165
  export declare function isNotNull(left: LeftRef, explicit?: ValueType): IsNullFilter<FilterField, FilterReferenceValue>;
155
- export declare function isIn(left: TokenLeftRef, input: readonly FilterInput[], explicit?: ValueType): InFilter<FilterFieldToken, FilterReferenceValue>;
166
+ export declare function isIn(left: TokenLeftRef, input: readonly TokenFilterInput[], explicit?: ValueType): InFilter<FilterFieldToken, FilterReferenceValue>;
156
167
  export declare function isIn(left: LeftRef, input: readonly FilterInput[], explicit?: ValueType): InFilter<FilterField, FilterReferenceValue>;
157
- export declare function isNotIn(left: TokenLeftRef, input: readonly FilterInput[], explicit?: ValueType): InFilter<FilterFieldToken, FilterReferenceValue>;
168
+ export declare function isNotIn(left: TokenLeftRef, input: readonly TokenFilterInput[], explicit?: ValueType): InFilter<FilterFieldToken, FilterReferenceValue>;
158
169
  export declare function isNotIn(left: LeftRef, input: readonly FilterInput[], explicit?: ValueType): InFilter<FilterField, FilterReferenceValue>;
159
- export declare function between(left: TokenLeftRef, min: FilterInput, max: FilterInput, options?: {
170
+ export declare function between(left: TokenLeftRef, min: TokenFilterInput, max: TokenFilterInput, options?: {
160
171
  readonly not?: boolean;
161
172
  }, explicit?: ValueType): BetweenFilter<FilterFieldToken, FilterReferenceValue>;
162
173
  export declare function between(left: LeftRef, min: FilterInput, max: FilterInput, options?: {
@@ -186,13 +197,13 @@ export declare function consecutiveRange(left: LeftRef, options: {
186
197
  readonly semantic?: boolean;
187
198
  readonly isoWeek?: boolean;
188
199
  }, explicit?: ValueType): ConsecutiveRangeFilter<FilterField, FilterReferenceValue>;
189
- export declare function contains(left: TokenLeftRef, input: FilterInput | readonly FilterInput[], options?: {
200
+ export declare function contains(left: TokenLeftRef, input: TokenFilterInput | readonly TokenFilterInput[], options?: {
190
201
  readonly not?: boolean;
191
202
  }, explicit?: ValueType): ContainsFilter<FilterFieldToken, FilterReferenceValue>;
192
203
  export declare function contains(left: LeftRef, input: FilterInput | readonly FilterInput[], options?: {
193
204
  readonly not?: boolean;
194
205
  }, explicit?: ValueType): ContainsFilter<FilterField, FilterReferenceValue>;
195
- export declare function overlaps(left: TokenLeftRef, input: FilterInput | readonly FilterInput[], options?: {
206
+ export declare function overlaps(left: TokenLeftRef, input: TokenFilterInput | readonly TokenFilterInput[], options?: {
196
207
  readonly not?: boolean;
197
208
  }, explicit?: ValueType): OverlapsFilter<FilterFieldToken, FilterReferenceValue>;
198
209
  export declare function overlaps(left: LeftRef, input: FilterInput | readonly FilterInput[], options?: {
@@ -153,8 +153,11 @@ function hasKind(value, kind) {
153
153
  return typeof value === "object" && value !== null && value.__kind === kind;
154
154
  }
155
155
  function isCurrentUser(value) { return hasKind(value, "currentUser"); }
156
+ function isUserRef(value) {
157
+ return hasKind(value, "user") && typeof value.email === "string";
158
+ }
156
159
  const FILTER_VALUE_TYPES = new Set([
157
- "BOOLEAN", "CURRENT_USER", "DATE", "DATETIME", "FIELD", "NULL", "NUMBER", "RECORD_FIELD", "REFERENCE", "TEXT", "UUID",
160
+ "BOOLEAN", "CURRENT_USER", "DATE", "DATETIME", "FIELD", "NULL", "NUMBER", "RECORD_FIELD", "REFERENCE", "TEXT", "USER", "UUID",
158
161
  ]);
159
162
  function isCanonicalFilterValue(value) {
160
163
  return typeof value === "object" && value !== null && typeof value.type === "string" &&
@@ -225,6 +228,14 @@ export function toFilterValue(input, valueType = "TEXT") {
225
228
  return input;
226
229
  if (isCurrentUser(input))
227
230
  return { type: "CURRENT_USER", valueType: input.valueType };
231
+ if (isUserRef(input)) {
232
+ // A user compares as an id: under a number, date or boolean comparison it
233
+ // would build a value of the wrong type with no error (#2891).
234
+ if (valueType !== "TEXT" && valueType !== "UUID") {
235
+ throw new EdkValidationError(`userRef(${JSON.stringify(input.email)}) compares as a user id; use it in a text or UUID comparison, not ${valueType}`);
236
+ }
237
+ return { type: "USER", email: input.email, valueType };
238
+ }
228
239
  if (isFilterReferenceInput(input)) {
229
240
  const value = typeof input.ref === "string" && input.ref.startsWith(UNRESOLVED_REFERENCE_MARKER)
230
241
  ? { __rawFilterReference: input.ref.slice(UNRESOLVED_REFERENCE_MARKER.length) }
@@ -6,6 +6,8 @@ export interface FilterPrintCodec<Field, ReferenceValue> {
6
6
  readonly quote?: (value: string) => string;
7
7
  readonly namespace?: string;
8
8
  readonly used?: (helper: string) => void;
9
+ /** Prints a `USER` value (`userRef("…")`); without it such a value cannot print (#2891). */
10
+ readonly user?: (email: string) => string;
9
11
  }
10
12
  /** Print every canonical filter through the same public `filter.*` authoring surface. */
11
13
  export declare function printFilter<Field, ReferenceValue>(filter: Filter<Field, ReferenceValue>, codec: FilterPrintCodec<Field, ReferenceValue>): string;
@@ -11,18 +11,22 @@ export function printFilter(filter, codec) {
11
11
  const literals = "value" in filter ? [filter.value]
12
12
  : "values" in filter ? filter.values
13
13
  : "min" in filter ? [filter.min, filter.max] : [];
14
- const uuidValues = literals.length > 0 && literals.every((literal) => literal.type === "UUID");
14
+ const uuidValues = literals.length > 0 && literals.every((literal) => literal.type === "UUID" || (literal.type === "USER" && literal.valueType === "UUID"));
15
15
  const explicitType = uuidValues ? `, ${quote("UUID")}` : "";
16
16
  const impliedLiteralType = stringLiteralTypeImpliedBy(filter, uuidValues);
17
17
  // An option selection prints as `filter.textOption(label)` whatever the
18
18
  // left side implies: a bare or wrapped TEXT literal builds as a raw word (#1733).
19
19
  const value = (input) => input.type === "TEXT" && input.option === true
20
20
  ? printFilterValue(input, codec, call, quote)
21
- : input.type === "UUID"
22
- ? uuidValues ? quote(input.value) : `{ type: "UUID", value: ${quote(input.value)} }`
23
- : (input.type === "TEXT" || input.type === "DATE" || input.type === "DATETIME") && impliedLiteralType !== undefined && input.type !== impliedLiteralType
24
- ? `{ type: ${quote(input.type)}, value: ${quote(input.value)} }`
25
- : printFilterValue(input, codec, call, quote);
21
+ // A UUID-wrapped user among other value types would rebuild as TEXT from
22
+ // a bare `userRef(...)`: name the wrapper, as a UUID literal does.
23
+ : input.type === "USER" && input.valueType === "UUID" && !uuidValues
24
+ ? `{ type: "USER", email: ${quote(input.email)}, valueType: "UUID" }`
25
+ : input.type === "UUID"
26
+ ? uuidValues ? quote(input.value) : `{ type: "UUID", value: ${quote(input.value)} }`
27
+ : (input.type === "TEXT" || input.type === "DATE" || input.type === "DATETIME") && impliedLiteralType !== undefined && input.type !== impliedLiteralType
28
+ ? `{ type: ${quote(input.type)}, value: ${quote(input.value)} }`
29
+ : printFilterValue(input, codec, call, quote);
26
30
  if ("leftValue" in filter && filter.leftValue?.type === "FIELD") {
27
31
  const operand = filter.leftValue;
28
32
  if ((operand.aspect != null && operand.aspect !== "") || (operand.treatNullAsEquals != null && operand.treatNullAsEquals !== true)) {
@@ -127,6 +131,11 @@ function printFilterValue(value, codec, call, quote) {
127
131
  return call("fieldValue", `${codec.field(value.value)}, { ${options.join(", ")} }`);
128
132
  }
129
133
  case "CURRENT_USER": return call("currentUser", quote(value.valueType ?? "ID"));
134
+ case "USER": {
135
+ if (codec.user === undefined)
136
+ throw new EntityTfError(`a user filter value (${value.email}) has no printed form here`);
137
+ return codec.user(value.email);
138
+ }
130
139
  case "REFERENCE": {
131
140
  const options = value.multiple === true ? ", { multiple: true }" : "";
132
141
  // Stored HCL real_type is uppercased as-is. DECIMAL and INTEGER are
@@ -96,6 +96,8 @@ export interface FilterToTfCodec {
96
96
  * lookup, whichever wrapper that is.
97
97
  */
98
98
  readonly literal?: (value: TfValue, field: unknown | undefined, valueType: string, isOptionLabel: boolean) => TfValue;
99
+ /** A `userRef(email)` value's user id; without it such a value cannot encode (#2891). */
100
+ readonly user?: (email: string) => TfValue;
99
101
  /**
100
102
  * The owner keeps an option label its field no longer lists as written
101
103
  * (a pulled automation, #1733), and its `literal` hook already warned.
@@ -129,6 +131,8 @@ export interface FilterFromTfCodec<Field = string, ReferenceValue = never> {
129
131
  */
130
132
  readonly referenceType?: (value: TfValue, fallback: ValueType) => ValueType;
131
133
  readonly literal?: (value: TfValue, valueType: string, field?: Field) => TfValue;
134
+ /** The email of a user lookup a TEXT or UUID value holds, or undefined when it holds none (#2891). */
135
+ readonly user?: (value: TfValue) => string | undefined;
132
136
  /** Decode a RECORD_FIELD value's source-record field reference; without it only raw platform ids decode. */
133
137
  readonly recordField?: (value: TfValue) => Field;
134
138
  /** Whether a RECORD_FIELD `object` reference names the owning app or element; without it only raw platform ids decode. */
@@ -199,6 +199,17 @@ function wireFilterValueToTf(value, field, codec, role = "value", operator) {
199
199
  }
200
200
  return { type, current_user_type: currentUserType.toLowerCase() };
201
201
  }
202
+ if (type === "user") {
203
+ if (typeof raw.email !== "string" || raw.email === "")
204
+ throw new EntityTfError("userRef filter value requires an email");
205
+ if (codec.user === undefined) {
206
+ throw new EntityTfError(`userRef(${JSON.stringify(raw.email)}) as a filter value is supported only in automation filters`);
207
+ }
208
+ const valueType = String(raw.valueType ?? "TEXT").toLowerCase();
209
+ if (valueType !== "text" && valueType !== "uuid")
210
+ throw new EntityTfError(`userRef filter value type must be TEXT or UUID, not ${valueType.toUpperCase()}`);
211
+ return { type: valueType, value: codec.user(raw.email) };
212
+ }
202
213
  if (type === "reference") {
203
214
  const reference = raw.value ?? raw.valueReference ?? raw.value_reference;
204
215
  if (reference === undefined)
@@ -564,6 +575,11 @@ export function filterFromTf(value, codec, fieldScope = "app") {
564
575
  }
565
576
  function filterValueFromTf(value, codec, fieldScope, field) {
566
577
  const type = value.type.toLowerCase();
578
+ if ((type === "text" || type === "uuid") && codec.user !== undefined && value.value !== undefined) {
579
+ const email = codec.user(value.value);
580
+ if (email !== undefined)
581
+ return { type: "USER", email, valueType: type === "uuid" ? "UUID" : "TEXT" };
582
+ }
567
583
  const literal = codec.literal?.(value.value, type, field) ?? value.value;
568
584
  if (["text", "uuid", "number", "boolean", "date", "datetime"].includes(type) && typeof literal === "object" && literal !== null) {
569
585
  throw new EntityTfError(`${type} filter literal contains an unresolved expression or object`);
@@ -69,6 +69,10 @@ export type FilterValue<FieldValue = string, ReferenceValue = FilterReference> =
69
69
  } | {
70
70
  type: "CURRENT_USER";
71
71
  valueType?: "ID" | "EMAIL" | "DOMAIN";
72
+ } | {
73
+ type: "USER";
74
+ email: string;
75
+ valueType: "TEXT" | "UUID";
72
76
  } | ({
73
77
  type: "RECORD_FIELD";
74
78
  field: FieldValue | string;
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import type { FromTfContext } from "../../engine/pull/context.js";
18
18
  import { type ChildResourceScope, type TfValue } from "../../engine/tf/index.js";
19
- export declare function resolveToolFieldKey(fieldRef: TfValue | undefined, scopeTfLabel: string, scope?: ChildResourceScope | "task", ctx?: Pick<FromTfContext, "dataAttrs" | "foreignFieldRefsByDataAddress">): string | undefined;
19
+ export declare function resolveToolFieldKey(fieldRef: TfValue | undefined, scopeTfLabel: string, scope?: ChildResourceScope | "task", ctx?: Pick<FromTfContext, "dataAttrs" | "foreignFieldRefsByDataAddress" | "resourcesOfType">): string | undefined;
20
20
  /**
21
21
  * When `fieldRef` is a field resource whose scoped label names a different
22
22
  * owner than the tool's resolved target, return that owner as