@elementumai/edk 0.11.0 → 0.13.0

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 (222) hide show
  1. package/README.md +40 -6
  2. package/dist-sdk/src/catalog/factories.d.ts +7 -1
  3. package/dist-sdk/src/catalog/factories.js +2 -0
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +1 -1
  6. package/dist-sdk/src/catalog/org.js +79 -34
  7. package/dist-sdk/src/catalog/token.js +5 -0
  8. package/dist-sdk/src/catalog/types.d.ts +7 -1
  9. package/dist-sdk/src/catalog/types.js +3 -0
  10. package/dist-sdk/src/core/system-fields.d.ts +1 -1
  11. package/dist-sdk/src/core/system-fields.js +1 -1
  12. package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -0
  13. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  14. package/dist-sdk/src/core/types/app.d.ts +6 -0
  15. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  16. package/dist-sdk/src/engine/coverage-gaps.d.ts +5 -0
  17. package/dist-sdk/src/engine/coverage-gaps.js +9 -0
  18. package/dist-sdk/src/engine/ei/run.d.ts +20 -1
  19. package/dist-sdk/src/engine/ei/run.js +102 -14
  20. package/dist-sdk/src/engine/pull/authored-address.js +42 -6
  21. package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
  22. package/dist-sdk/src/engine/pull/authored-root.js +306 -0
  23. package/dist-sdk/src/engine/pull/context.d.ts +10 -0
  24. package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
  25. package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
  26. package/dist-sdk/src/engine/pull/org.d.ts +1 -0
  27. package/dist-sdk/src/engine/pull/org.js +2 -0
  28. package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
  29. package/dist-sdk/src/engine/pull/partition.js +43 -0
  30. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
  31. package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
  32. package/dist-sdk/src/engine/pull/ref-only.d.ts +22 -0
  33. package/dist-sdk/src/engine/pull/ref-only.js +59 -1
  34. package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
  35. package/dist-sdk/src/engine/pull/source-resources.js +110 -0
  36. package/dist-sdk/src/engine/pull/stream-root.d.ts +148 -0
  37. package/dist-sdk/src/engine/pull/stream-root.js +563 -0
  38. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
  39. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
  40. package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
  41. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +9 -1
  42. package/dist-sdk/src/entities/access-policy/from-tf.js +25 -4
  43. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  44. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
  45. package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
  46. package/dist-sdk/src/entities/agent/build.d.ts +52 -1
  47. package/dist-sdk/src/entities/agent/build.js +34 -0
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -0
  49. package/dist-sdk/src/entities/agent/from-tf.d.ts +34 -1
  50. package/dist-sdk/src/entities/agent/from-tf.js +262 -2
  51. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  52. package/dist-sdk/src/entities/agent/to-tf.d.ts +8 -10
  53. package/dist-sdk/src/entities/agent/to-tf.js +158 -14
  54. package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
  55. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  56. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
  57. package/dist-sdk/src/entities/app/build.d.ts +34 -14
  58. package/dist-sdk/src/entities/app/build.js +93 -16
  59. package/dist-sdk/src/entities/app/from-tf.js +25 -11
  60. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  61. package/dist-sdk/src/entities/app/index.js +1 -0
  62. package/dist-sdk/src/entities/app/module.js +1 -0
  63. package/dist-sdk/src/entities/app/stage-keys.d.ts +20 -5
  64. package/dist-sdk/src/entities/app/stage-keys.js +43 -9
  65. package/dist-sdk/src/entities/app/to-tf.js +2 -0
  66. package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
  67. package/dist-sdk/src/entities/approval-chain/build.js +120 -8
  68. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
  69. package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
  70. package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
  71. package/dist-sdk/src/entities/approval-chain/index.js +4 -1
  72. package/dist-sdk/src/entities/approval-chain/module.js +23 -5
  73. package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
  74. package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
  75. package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
  76. package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
  77. package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
  78. package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
  79. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
  80. package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
  81. package/dist-sdk/src/entities/automation/build.d.ts +50 -24
  82. package/dist-sdk/src/entities/automation/build.js +86 -33
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +52 -8
  84. package/dist-sdk/src/entities/automation/from-tf.d.ts +38 -6
  85. package/dist-sdk/src/entities/automation/from-tf.js +855 -157
  86. package/dist-sdk/src/entities/automation/index.d.ts +2 -1
  87. package/dist-sdk/src/entities/automation/index.js +1 -0
  88. package/dist-sdk/src/entities/automation/module.d.ts +4 -3
  89. package/dist-sdk/src/entities/automation/module.js +33 -12
  90. package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
  91. package/dist-sdk/src/entities/automation/refs-read.js +48 -0
  92. package/dist-sdk/src/entities/automation/run-target.d.ts +2 -0
  93. package/dist-sdk/src/entities/automation/run-target.js +5 -0
  94. package/dist-sdk/src/entities/automation/script-code.d.ts +2 -1
  95. package/dist-sdk/src/entities/automation/script-code.js +82 -1
  96. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  97. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  98. package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
  99. package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
  100. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +12 -1
  101. package/dist-sdk/src/entities/automation/task-output-labels.js +32 -1
  102. package/dist-sdk/src/entities/automation/tasks.d.ts +76 -18
  103. package/dist-sdk/src/entities/automation/tasks.js +52 -15
  104. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -0
  105. package/dist-sdk/src/entities/automation/to-tf.js +585 -97
  106. package/dist-sdk/src/entities/automation/triggers.d.ts +48 -23
  107. package/dist-sdk/src/entities/automation/triggers.js +27 -12
  108. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
  109. package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
  110. package/dist-sdk/src/entities/chart/build.d.ts +18 -2
  111. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  112. package/dist-sdk/src/entities/chart/from-tf.js +28 -1
  113. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  114. package/dist-sdk/src/entities/chart/printer.js +5 -2
  115. package/dist-sdk/src/entities/chart/to-tf.js +38 -3
  116. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +3 -0
  117. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  118. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  119. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +45 -6
  120. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  121. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
  122. package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
  123. package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
  124. package/dist-sdk/src/entities/element/build.js +2 -1
  125. package/dist-sdk/src/entities/element/from-tf.js +15 -2
  126. package/dist-sdk/src/entities/element/module.js +3 -0
  127. package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
  128. package/dist-sdk/src/entities/element/system-fields.js +23 -0
  129. package/dist-sdk/src/entities/element/to-tf.js +2 -0
  130. package/dist-sdk/src/entities/field/build.d.ts +9 -0
  131. package/dist-sdk/src/entities/field/from-tf.d.ts +29 -1
  132. package/dist-sdk/src/entities/field/from-tf.js +99 -6
  133. package/dist-sdk/src/entities/field/module.js +12 -2
  134. package/dist-sdk/src/entities/field/to-tf.d.ts +13 -3
  135. package/dist-sdk/src/entities/field/to-tf.js +90 -46
  136. package/dist-sdk/src/entities/org/category.js +1 -0
  137. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  138. package/dist-sdk/src/entities/org/index.js +1 -0
  139. package/dist-sdk/src/entities/org/role.js +5 -0
  140. package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
  141. package/dist-sdk/src/entities/org/voice-auth.js +33 -0
  142. package/dist-sdk/src/entities/organization/build.d.ts +3 -0
  143. package/dist-sdk/src/entities/organization/build.js +2 -0
  144. package/dist-sdk/src/entities/organization/index.d.ts +1 -0
  145. package/dist-sdk/src/entities/organization/index.js +1 -0
  146. package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
  147. package/dist-sdk/src/entities/organization/to-tf.js +59 -1
  148. package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
  149. package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
  150. package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
  151. package/dist-sdk/src/entities/phone-service/build.js +1 -0
  152. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
  153. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
  154. package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
  155. package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
  156. package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
  157. package/dist-sdk/src/entities/relationship/from-tf.js +7 -2
  158. package/dist-sdk/src/entities/relationship/module.js +2 -2
  159. package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
  160. package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
  161. package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
  162. package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
  163. package/dist-sdk/src/entities/role/permission-levels.js +78 -0
  164. package/dist-sdk/src/entities/role/to-tf.js +32 -2
  165. package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
  166. package/dist-sdk/src/entities/service-account/module.js +9 -1
  167. package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
  168. package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
  169. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  170. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  171. package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
  172. package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
  173. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  174. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
  175. package/dist-sdk/src/entities/shared/filters/ast.d.ts +4 -0
  176. package/dist-sdk/src/entities/shared/filters/index.d.ts +85 -14
  177. package/dist-sdk/src/entities/shared/filters/index.js +18 -6
  178. package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
  179. package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
  180. package/dist-sdk/src/entities/shared/filters/print.js +9 -5
  181. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +12 -7
  182. package/dist-sdk/src/entities/shared/filters/tf-codec.js +9 -5
  183. package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
  184. package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
  185. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  186. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  187. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  188. package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
  189. package/dist-sdk/src/entities/skill/module.js +2 -0
  190. package/dist-sdk/src/entities/sla/build.d.ts +96 -0
  191. package/dist-sdk/src/entities/sla/build.js +124 -0
  192. package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
  193. package/dist-sdk/src/entities/sla/from-tf.js +164 -0
  194. package/dist-sdk/src/entities/sla/index.d.ts +1 -0
  195. package/dist-sdk/src/entities/sla/index.js +1 -0
  196. package/dist-sdk/src/entities/sla/module.d.ts +4 -0
  197. package/dist-sdk/src/entities/sla/module.js +73 -0
  198. package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
  199. package/dist-sdk/src/entities/sla/printer.js +84 -0
  200. package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
  201. package/dist-sdk/src/entities/sla/to-tf.js +81 -0
  202. package/dist-sdk/src/entities/table/build.d.ts +7 -2
  203. package/dist-sdk/src/entities/table/build.js +22 -1
  204. package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
  205. package/dist-sdk/src/entities/table/from-tf.js +89 -14
  206. package/dist-sdk/src/entities/table/index.d.ts +1 -1
  207. package/dist-sdk/src/entities/table/to-tf.js +41 -2
  208. package/dist-sdk/src/entities/task/from-tf.js +2 -1
  209. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  210. package/dist-sdk/src/entities/view/from-tf.d.ts +8 -4
  211. package/dist-sdk/src/entities/view/from-tf.js +10 -9
  212. package/dist-sdk/src/entities/view/module.js +5 -0
  213. package/dist-sdk/src/entities/widget/from-tf.js +15 -4
  214. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +51 -4
  215. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  216. package/dist-sdk/src/graph/index.d.ts +20 -2
  217. package/dist-sdk/src/graph/index.js +19 -0
  218. package/dist-sdk/src/graph/modules.js +11 -1
  219. package/dist-sdk/src/graph/resource-types.d.ts +47 -0
  220. package/dist-sdk/src/graph/resource-types.js +62 -0
  221. package/dist-sdk/src/graph/types.d.ts +116 -6
  222. package/package.json +6 -3
@@ -110,6 +110,10 @@ export interface FromTfContext {
110
110
  readonly fieldKey: string;
111
111
  readonly fieldName?: string;
112
112
  readonly fieldType?: string;
113
+ /** Static option labels from the ref-only catalog. Absent for a record-sourced Dropdown. */
114
+ readonly options?: readonly string[];
115
+ /** The platform Stage system field, from its canonical `STAGE` tag. */
116
+ readonly systemStage?: true;
113
117
  }>;
114
118
  /** Lower-cased field display name -> typed field key for each on-disk app/element catalog. */
115
119
  readonly fieldNamesByOwnerRefName?: ReadonlyMap<string, ReadonlyMap<string, string>>;
@@ -142,6 +146,12 @@ export interface FromTfContext {
142
146
  * stays silent. Undefined: no listed id, so only an empty id warns.
143
147
  */
144
148
  readonly omittedAutomationsById?: ReadonlyMap<string, OmittedAutomationIdentity>;
149
+ /**
150
+ * Ids of the access policies the export matched to the one the platform
151
+ * adds for an app's creator (platform-creator-policies.json, edk#2156).
152
+ * Pull notes them in source and changes nothing else.
153
+ */
154
+ readonly platformCreatorPolicyIds?: ReadonlySet<string>;
145
155
  /**
146
156
  * Foreign app/element display names this stream saw referenced (currently:
147
157
  * a RELATION field's `related_object_id` as a `data.elementum_app`/
@@ -0,0 +1,114 @@
1
+ import { type AdoptionAddressAlias } from "../../graph/index.js";
2
+ import { type ChildResourceScope } from "../tf/labels.js";
3
+ import type { TerraformStateResource } from "../ei/state.js";
4
+ import type { StreamRootExtract } from "./stream-root.js";
5
+ export interface FieldRefIdentity {
6
+ readonly ownerRefName: string;
7
+ readonly fieldKey: string;
8
+ readonly fieldName?: string;
9
+ /** The field's public authoring type (e.g. "USER", "GROUP") — see AppField's `type` discriminant. */
10
+ readonly fieldType?: string;
11
+ }
12
+ /**
13
+ * Each static Dropdown and Multi-Select field's current options, keyed by the
14
+ * field's resource label in state: option id → label (#2568). An option id is
15
+ * read as an option only of the field that lists it.
16
+ */
17
+ export type PicklistOptionsByField = Map<string, ReadonlyMap<string, string>>;
18
+ export interface PulledFieldRefsContext {
19
+ readonly fieldRefsById: Map<string, FieldRefIdentity>;
20
+ readonly picklistOptionsByField: PicklistOptionsByField;
21
+ readonly fieldNamesByOwnerRefName: Map<string, ReadonlyMap<string, string>>;
22
+ }
23
+ /**
24
+ * Minimal stream-root shape for collecting field import ids — printers cast
25
+ * NormalizedApp at the CLI boundary; engine must not import entities/.
26
+ */
27
+ export interface FieldRefOwnerRoot {
28
+ readonly refName: string;
29
+ /** Live export/tf label (app/element namespace). Import addresses use this, not tsLabelToTfLabel(authored refName). */
30
+ readonly namespace?: string;
31
+ readonly fields: readonly {
32
+ readonly key: string;
33
+ readonly field: {
34
+ readonly name?: unknown;
35
+ readonly type?: unknown;
36
+ };
37
+ }[];
38
+ }
39
+ /**
40
+ * The current options of every static Dropdown/Multi-Select field in OpenTofu
41
+ * state, by field (#2568). The platform exports scalar Dropdown assignments
42
+ * through an options-by-label expression, but exports Multi-Select assignments
43
+ * and some filter values as raw option UUIDs. State is the only authoritative
44
+ * place shared by both shapes that holds each option's id, label and field.
45
+ */
46
+ export declare function picklistOptionsByFieldFromState(resources: readonly {
47
+ readonly mode?: unknown;
48
+ readonly type?: unknown;
49
+ readonly name?: unknown;
50
+ readonly instances?: readonly {
51
+ readonly attributes?: unknown;
52
+ }[];
53
+ }[]): PicklistOptionsByField;
54
+ /** State-backed values for each static field's `<field>_options_by_label` local. */
55
+ export declare function picklistOptionLocalValuesFromState(resources: readonly {
56
+ readonly mode?: unknown;
57
+ readonly type?: unknown;
58
+ readonly name?: unknown;
59
+ readonly instances?: readonly {
60
+ readonly attributes?: unknown;
61
+ }[];
62
+ }[]): Map<string, string>;
63
+ /**
64
+ * Repair persisted field identities before extraction when state proves that
65
+ * an export label is an alias for the workspace's authored label.
66
+ *
67
+ * Some export payloads carry raw field UUIDs rather than resource references.
68
+ * Relabelling the parsed document cannot change those values, so their
69
+ * registry entries must move to the same authored bag key as well.
70
+ */
71
+ export declare function preserveAuthoredFieldRefKeys(fieldRefsById: Map<string, FieldRefIdentity>, importIds: ReadonlyMap<string, string>, aliases: readonly AdoptionAddressAlias[]): void;
72
+ /** display name (lower) → bag key, built from persisted/bootstrap field identities. */
73
+ export declare function buildFieldNamesByOwnerRefName(fieldRefsById: ReadonlyMap<string, FieldRefIdentity>): Map<string, ReadonlyMap<string, string>>;
74
+ /**
75
+ * The option ids build can name offline (#1733). `idsByLocal` maps each
76
+ * managed Dropdown, Multi-Select and app status field's
77
+ * `<label>_options_by_label` local to its label → id pairs, read from a local
78
+ * root `terraform.tfstate`. `labelById` holds every id → label that state and
79
+ * earlier pulls recorded, for fields state does not cover. Both are empty for
80
+ * an org that was never applied with local state or pulled.
81
+ */
82
+ export interface OptionIdIndex {
83
+ readonly idsByLocal: ReadonlyMap<string, ReadonlyMap<string, string>>;
84
+ readonly labelById: ReadonlyMap<string, string>;
85
+ }
86
+ export declare function readOptionIdIndex(orgRoot: string): Promise<OptionIdIndex>;
87
+ /** Authored field identities persisted by earlier pulls. Reads the manifest only. */
88
+ export declare function readManifestFieldRefs(orgRoot: string): Promise<ReadonlyMap<string, FieldRefIdentity>>;
89
+ /**
90
+ * Hydrate the in-memory registry for a pull run.
91
+ *
92
+ * `stateResources` is the pull's `readStateSnapshot` read, so a declared
93
+ * backend is seen too; without it only a local root `terraform.tfstate` is.
94
+ * The manifest key is authored and wins, except a key that is only the
95
+ * display-name slug a ref-only lookup guessed: there the managed state key
96
+ * wins (#1431), and the correction is persisted.
97
+ */
98
+ export declare function loadPulledFieldRefsContext(orgRoot: string, stateResources?: readonly TerraformStateResource[]): Promise<PulledFieldRefsContext>;
99
+ /** Back-compat alias — most callers only need the field-id map. */
100
+ export declare function loadFieldRefsRegistry(orgRoot: string): Promise<Map<string, FieldRefIdentity>>;
101
+ /** The registry file's own entries (no state-derived refs), as a pull found them before it changed any (edk#2628). */
102
+ export declare function readFieldRefsRegistryEntries(orgRoot: string): Promise<ReadonlyMap<string, FieldRefIdentity>>;
103
+ /**
104
+ * Put one root's registry entries back to `entries` (taken by {@link readFieldRefsRegistryEntries} before the
105
+ * pull), leaving every other root's entries as they are. A failed pull that restores the root's source calls
106
+ * this, so a later pull does not print refs to fields the restored source doesn't have (edk#2628).
107
+ */
108
+ export declare function restoreOwnerFieldRefs(orgRoot: string, ownerRefName: string, entries: ReadonlyMap<string, FieldRefIdentity>): Promise<void>;
109
+ /** Persist new entries — best-effort, never blocks the pull. */
110
+ export declare function mergeFieldRefsRegistry(orgRoot: string, additions: ReadonlyMap<string, FieldRefIdentity>, picklistAdditions?: ReadonlyMap<string, string>): Promise<void>;
111
+ /** Collect field-id identities from one stream-root extract's import blocks. */
112
+ export declare function collectFieldRefEntriesFromExtract(root: FieldRefOwnerRoot, extract: StreamRootExtract, scope: ChildResourceScope): Map<string, FieldRefIdentity>;
113
+ /** Merge extract-derived field ids into the pull ctx and persist for later runs. */
114
+ export declare function rememberPulledFieldIdentities(orgRoot: string, target: Map<string, FieldRefIdentity>, root: FieldRefOwnerRoot, extract: StreamRootExtract, scope: ChildResourceScope): Promise<void>;
@@ -0,0 +1,501 @@
1
+ /**
2
+ * Cross-pull registry of platform field ids → dependency catalog identities.
3
+ *
4
+ * `pull app` starts each run with empty in-memory maps unless we hydrate from
5
+ * disk: a prior `pull element tickets` writes the element and name map, but
6
+ * the field-id map was discarded when that command exited — so a later
7
+ * `pull app knowledge` still can't resolve foreign createRecord field_ids.
8
+ *
9
+ * Persist entries as they're learned during extract (`rememberPulledFieldIdentities`)
10
+ * and hydrate at the next pull's start. State fills gaps for already-adopted
11
+ * fields without forcing a re-pull. The pull orchestrators pass the resources
12
+ * of their backend-agnostic `readStateSnapshot` read; a bare local
13
+ * `terraform.tfstate` read sees nothing on a declared remote backend.
14
+ */
15
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
16
+ import { join, resolve } from "node:path";
17
+ import { randomUUID } from "node:crypto";
18
+ import { existsSync } from "node:fs";
19
+ import { SYSTEM_FIELD_KEYS } from "../../core/system-fields.js";
20
+ import { AUTHORING_TYPE_BY_RESOURCE_TYPE, ENTITY_KIND_BY_ID, STREAM_ROOT_RESOURCE_TYPES, knownResourceTypes, } from "../../graph/index.js";
21
+ import { SCOPE_OWNER_RESOURCE_TYPES } from "../../graph/resource-types.js";
22
+ import { childPartFromScopedLabel, ownerFromScopedChildLabel, sanitizeName, scopedResourceLabel, tfLabelToTsLabel, tsLabelToTfLabel, } from "../tf/labels.js";
23
+ const MANIFEST_VERSION = 2;
24
+ /** System-field bag key → stream-root attr (`title` → `title_field_id`), same bijection as view locals. */
25
+ const SYSTEM_FIELD_KEY_BY_ID_ATTR = new Map(SYSTEM_FIELD_KEYS.map((key) => [`${tsLabelToTfLabel(key)}_field_id`, key]));
26
+ function fieldResourceTypes() {
27
+ const field = ENTITY_KIND_BY_ID.get("field");
28
+ return field === undefined ? [] : knownResourceTypes(field.resource);
29
+ }
30
+ /** Option-bearing field sub-types (typeKeys from the field kind module). */
31
+ function picklistFieldResourceTypes() {
32
+ const field = ENTITY_KIND_BY_ID.get("field");
33
+ if (field?.resource.shape !== "subTypes")
34
+ return new Set();
35
+ return new Set(field.resource.rows
36
+ .filter((row) => row.key === "picklist" || row.key === "multiPicklist")
37
+ .map((row) => row.resourceType));
38
+ }
39
+ /**
40
+ * The current options of every static Dropdown/Multi-Select field in OpenTofu
41
+ * state, by field (#2568). The platform exports scalar Dropdown assignments
42
+ * through an options-by-label expression, but exports Multi-Select assignments
43
+ * and some filter values as raw option UUIDs. State is the only authoritative
44
+ * place shared by both shapes that holds each option's id, label and field.
45
+ */
46
+ export function picklistOptionsByFieldFromState(resources) {
47
+ const out = new Map();
48
+ const picklistTypes = picklistFieldResourceTypes();
49
+ for (const resource of resources) {
50
+ if (resource.mode !== undefined && resource.mode !== "managed")
51
+ continue;
52
+ if (typeof resource.type !== "string" || !picklistTypes.has(resource.type))
53
+ continue;
54
+ if (typeof resource.name !== "string" || resource.name === "")
55
+ continue;
56
+ const labelById = new Map();
57
+ for (const instance of resource.instances ?? []) {
58
+ const attrs = instance.attributes;
59
+ if (attrs === null || typeof attrs !== "object")
60
+ continue;
61
+ const options = attrs.options;
62
+ if (!Array.isArray(options))
63
+ continue;
64
+ for (const option of options) {
65
+ if (option === null || typeof option !== "object")
66
+ continue;
67
+ const id = option.id;
68
+ const label = option.label;
69
+ // Removing an option deactivates it, and the provider keeps it in
70
+ // state as `active = false`. It is not a current option (#2568).
71
+ if (option.active === false)
72
+ continue;
73
+ if (typeof id === "string" && id !== "" && typeof label === "string" && label !== "")
74
+ labelById.set(id, label);
75
+ }
76
+ }
77
+ if (labelById.size > 0)
78
+ out.set(resource.name, labelById);
79
+ }
80
+ return out;
81
+ }
82
+ /** State-backed values for each static field's `<field>_options_by_label` local. */
83
+ export function picklistOptionLocalValuesFromState(resources) {
84
+ const out = new Map();
85
+ const picklistTypes = picklistFieldResourceTypes();
86
+ for (const resource of resources) {
87
+ if (resource.mode !== "managed" ||
88
+ typeof resource.type !== "string" ||
89
+ !picklistTypes.has(resource.type) ||
90
+ typeof resource.name !== "string" ||
91
+ resource.name === "")
92
+ continue;
93
+ for (const instance of resource.instances ?? []) {
94
+ const attrs = instance.attributes;
95
+ if (attrs === null || typeof attrs !== "object")
96
+ continue;
97
+ const options = attrs.options;
98
+ if (!Array.isArray(options))
99
+ continue;
100
+ for (const option of options) {
101
+ if (option === null || typeof option !== "object")
102
+ continue;
103
+ const id = option.id;
104
+ const label = option.label;
105
+ if (typeof id === "string" && id !== "" && typeof label === "string" && label !== "") {
106
+ out.set(`${resource.name}_options_by_label[${JSON.stringify(label)}]`, id);
107
+ }
108
+ }
109
+ }
110
+ }
111
+ return out;
112
+ }
113
+ function manifestPath(orgRoot) {
114
+ return join(resolve(orgRoot), ".edk-state", "field-refs-by-id.json");
115
+ }
116
+ function importLeafId(importId) {
117
+ return importId.slice(importId.lastIndexOf(":") + 1);
118
+ }
119
+ function ownerScopeFromScopedLabel(scopedLabel) {
120
+ if (scopedLabel.startsWith("apps_")) {
121
+ const rest = scopedLabel.slice("apps_".length);
122
+ const sep = rest.indexOf("_");
123
+ if (sep === -1)
124
+ return undefined;
125
+ return { scope: "app", ownerTfLabel: rest.slice(0, sep) };
126
+ }
127
+ if (scopedLabel.startsWith("elements_")) {
128
+ const rest = scopedLabel.slice("elements_".length);
129
+ const sep = rest.indexOf("_");
130
+ if (sep === -1)
131
+ return undefined;
132
+ return { scope: "element", ownerTfLabel: rest.slice(0, sep) };
133
+ }
134
+ return undefined;
135
+ }
136
+ function fieldKeyFromScopedResourceName(scopedLabel, scope, ownerTfLabel) {
137
+ try {
138
+ const childPart = childPartFromScopedLabel(ownerTfLabel, scopedLabel, scope);
139
+ return tfLabelToTsLabel(childPart);
140
+ }
141
+ catch {
142
+ return undefined;
143
+ }
144
+ }
145
+ /**
146
+ * Repair persisted field identities before extraction when state proves that
147
+ * an export label is an alias for the workspace's authored label.
148
+ *
149
+ * Some export payloads carry raw field UUIDs rather than resource references.
150
+ * Relabelling the parsed document cannot change those values, so their
151
+ * registry entries must move to the same authored bag key as well.
152
+ */
153
+ export function preserveAuthoredFieldRefKeys(fieldRefsById, importIds, aliases) {
154
+ const fieldTypes = new Set(fieldResourceTypes());
155
+ for (const { from, to } of aliases) {
156
+ const fromDot = from.indexOf(".");
157
+ const toDot = to.indexOf(".");
158
+ if (fromDot === -1 || toDot === -1)
159
+ continue;
160
+ const type = from.slice(0, fromDot);
161
+ if (!fieldTypes.has(type) || to.slice(0, toDot) !== type)
162
+ continue;
163
+ const importedId = importIds.get(from);
164
+ if (importedId === undefined)
165
+ continue;
166
+ const canonicalId = importedId.split(/[:/]/).at(-1) ?? importedId;
167
+ const registryId = fieldRefsById.has(importedId)
168
+ ? importedId
169
+ : fieldRefsById.has(canonicalId) ? canonicalId : undefined;
170
+ if (registryId === undefined)
171
+ continue;
172
+ const label = to.slice(toDot + 1);
173
+ const owner = ownerScopeFromScopedLabel(label);
174
+ if (owner === undefined)
175
+ continue;
176
+ const fieldKey = fieldKeyFromScopedResourceName(label, owner.scope, owner.ownerTfLabel);
177
+ if (fieldKey === undefined)
178
+ continue;
179
+ fieldRefsById.set(registryId, { ...fieldRefsById.get(registryId), fieldKey });
180
+ }
181
+ }
182
+ /** display name (lower) → bag key, built from persisted/bootstrap field identities. */
183
+ export function buildFieldNamesByOwnerRefName(fieldRefsById) {
184
+ const out = new Map();
185
+ // Managed UUID entries first. A later `refOnly:` display-name guess must
186
+ // not overwrite the bag key already bound in state (#1431).
187
+ const ordered = [...fieldRefsById.entries()].sort(([left], [right]) => {
188
+ const leftRef = left.startsWith("refOnly:") ? 1 : 0;
189
+ const rightRef = right.startsWith("refOnly:") ? 1 : 0;
190
+ return leftRef - rightRef;
191
+ });
192
+ for (const [id, { ownerRefName, fieldKey, fieldName }] of ordered) {
193
+ if (fieldName === undefined || fieldName === "")
194
+ continue;
195
+ let names = out.get(ownerRefName);
196
+ if (names === undefined) {
197
+ names = new Map();
198
+ out.set(ownerRefName, names);
199
+ }
200
+ const lower = fieldName.toLowerCase();
201
+ if (id.startsWith("refOnly:") && names.has(lower))
202
+ continue;
203
+ names.set(lower, fieldKey);
204
+ }
205
+ return out;
206
+ }
207
+ function bootstrapSystemFieldRefsFromStreamRoot(out, resource, streamRootTypes) {
208
+ if (typeof resource.type !== "string" || !streamRootTypes.has(resource.type))
209
+ return;
210
+ if (typeof resource.name !== "string" || resource.name === "")
211
+ return;
212
+ const ownerRefName = tfLabelToTsLabel(resource.name);
213
+ for (const instance of resource.instances ?? []) {
214
+ const attrs = instance.attributes;
215
+ if (attrs === null || typeof attrs !== "object")
216
+ continue;
217
+ for (const [attr, fieldKey] of SYSTEM_FIELD_KEY_BY_ID_ATTR) {
218
+ const id = attrs[attr];
219
+ if (typeof id !== "string" || id === "")
220
+ continue;
221
+ out.set(id, { ownerRefName, fieldKey });
222
+ }
223
+ }
224
+ }
225
+ async function localStateResources(orgRoot) {
226
+ const statePath = join(resolve(orgRoot), "terraform.tfstate");
227
+ if (!existsSync(statePath))
228
+ return [];
229
+ try {
230
+ const raw = await readFile(statePath, "utf8");
231
+ // eslint-disable-next-line no-restricted-syntax -- local workspace state is machine-owned JSON
232
+ return JSON.parse(raw).resources ?? [];
233
+ }
234
+ catch {
235
+ return [];
236
+ }
237
+ }
238
+ function bootstrapFromState(resources) {
239
+ const fieldRefsById = new Map();
240
+ const fieldTypes = new Set(fieldResourceTypes());
241
+ const streamRootTypes = STREAM_ROOT_RESOURCE_TYPES;
242
+ for (const resource of resources) {
243
+ bootstrapSystemFieldRefsFromStreamRoot(fieldRefsById, resource, streamRootTypes);
244
+ if (typeof resource.type !== "string" || !fieldTypes.has(resource.type))
245
+ continue;
246
+ if (typeof resource.name !== "string" || resource.name === "")
247
+ continue;
248
+ const owner = ownerFromScopedChildLabel(resource.name);
249
+ if (owner === undefined)
250
+ continue;
251
+ const fieldKey = fieldKeyFromScopedResourceName(resource.name, owner.scope, owner.ownerTfLabel);
252
+ if (fieldKey === undefined)
253
+ continue;
254
+ const ownerRefName = tfLabelToTsLabel(owner.ownerTfLabel);
255
+ // Same resourceType -> authoringType lookup collectFieldRefEntriesFromExtract
256
+ // uses (via the field's own `type` attr) below, but state instances carry
257
+ // no such attribute — the resource TYPE itself is the discriminant here.
258
+ const fieldType = AUTHORING_TYPE_BY_RESOURCE_TYPE.get(resource.type);
259
+ for (const instance of resource.instances ?? []) {
260
+ const attrs = instance.attributes;
261
+ if (attrs === null || typeof attrs !== "object")
262
+ continue;
263
+ const id = attrs.id;
264
+ if (typeof id !== "string" || id === "")
265
+ continue;
266
+ const fieldName = attrs.name;
267
+ fieldRefsById.set(id, {
268
+ ownerRefName,
269
+ fieldKey,
270
+ ...(typeof fieldName === "string" && fieldName !== "" ? { fieldName } : {}),
271
+ ...(fieldType !== undefined ? { fieldType } : {}),
272
+ });
273
+ }
274
+ }
275
+ return fieldRefsById;
276
+ }
277
+ /** The key a ref-only data lookup derives from a display name ("Bid Evaluation" → bidEvaluation). */
278
+ function isDisplayNameSlug(fieldKey, fieldName) {
279
+ return fieldName !== undefined && fieldKey === tfLabelToTsLabel(sanitizeName(fieldName));
280
+ }
281
+ export async function readOptionIdIndex(orgRoot) {
282
+ const resources = await localStateResources(orgRoot);
283
+ const picklistTypes = picklistFieldResourceTypes();
284
+ const idsByLocal = new Map();
285
+ for (const resource of resources) {
286
+ if (resource.mode !== "managed" || typeof resource.type !== "string" || typeof resource.name !== "string" || resource.name === "")
287
+ continue;
288
+ const isApp = resource.type === SCOPE_OWNER_RESOURCE_TYPES.app;
289
+ if (!isApp && !picklistTypes.has(resource.type))
290
+ continue;
291
+ const local = `${resource.name}_${isApp ? "status_" : ""}options_by_label`;
292
+ const ids = new Map();
293
+ for (const instance of resource.instances ?? []) {
294
+ const attrs = instance.attributes;
295
+ const options = attrs?.[isApp ? "status_options" : "options"];
296
+ if (!Array.isArray(options))
297
+ continue;
298
+ for (const option of options) {
299
+ if (option === null || typeof option !== "object")
300
+ continue;
301
+ const { id, label } = option;
302
+ if (typeof id === "string" && id !== "" && typeof label === "string" && label !== "")
303
+ ids.set(label, id);
304
+ }
305
+ }
306
+ if (ids.size > 0)
307
+ idsByLocal.set(local, ids);
308
+ }
309
+ const labelById = (await readManifest(orgRoot)).picklistOptionLabelById;
310
+ for (const ids of idsByLocal.values()) {
311
+ for (const [label, id] of ids)
312
+ labelById.set(id, label);
313
+ }
314
+ return { idsByLocal, labelById };
315
+ }
316
+ /** Authored field identities persisted by earlier pulls. Reads the manifest only. */
317
+ export async function readManifestFieldRefs(orgRoot) {
318
+ return (await readManifest(orgRoot)).entries;
319
+ }
320
+ async function readManifest(orgRoot) {
321
+ const entries = new Map();
322
+ const picklistOptionLabelById = new Map();
323
+ try {
324
+ const raw = await readFile(manifestPath(orgRoot), "utf8");
325
+ // eslint-disable-next-line no-restricted-syntax -- local machine-owned JSON
326
+ const parsed = JSON.parse(raw);
327
+ if (parsed.entries !== null && typeof parsed.entries === "object") {
328
+ for (const [id, identity] of Object.entries(parsed.entries)) {
329
+ if (typeof identity?.ownerRefName === "string" &&
330
+ identity.ownerRefName !== "" &&
331
+ typeof identity.fieldKey === "string" &&
332
+ identity.fieldKey !== "") {
333
+ entries.set(id, {
334
+ ownerRefName: identity.ownerRefName,
335
+ fieldKey: identity.fieldKey,
336
+ ...(typeof identity.fieldName === "string" && identity.fieldName !== "" ? { fieldName: identity.fieldName } : {}),
337
+ ...(typeof identity.fieldType === "string" && identity.fieldType !== "" ? { fieldType: identity.fieldType } : {}),
338
+ });
339
+ }
340
+ }
341
+ }
342
+ if (parsed.picklistOptionLabels !== null && typeof parsed.picklistOptionLabels === "object") {
343
+ for (const [id, label] of Object.entries(parsed.picklistOptionLabels)) {
344
+ if (typeof label === "string" && label !== "")
345
+ picklistOptionLabelById.set(id, label);
346
+ }
347
+ }
348
+ }
349
+ catch {
350
+ // missing or corrupt — treat as empty
351
+ }
352
+ return { entries, picklistOptionLabelById };
353
+ }
354
+ /**
355
+ * Hydrate the in-memory registry for a pull run.
356
+ *
357
+ * `stateResources` is the pull's `readStateSnapshot` read, so a declared
358
+ * backend is seen too; without it only a local root `terraform.tfstate` is.
359
+ * The manifest key is authored and wins, except a key that is only the
360
+ * display-name slug a ref-only lookup guessed: there the managed state key
361
+ * wins (#1431), and the correction is persisted.
362
+ */
363
+ export async function loadPulledFieldRefsContext(orgRoot, stateResources) {
364
+ const resources = stateResources ?? (await localStateResources(orgRoot));
365
+ const manifest = await readManifest(orgRoot);
366
+ const corrected = new Map();
367
+ for (const [id, identity] of bootstrapFromState(resources)) {
368
+ const prior = manifest.entries.get(id);
369
+ if (prior === undefined) {
370
+ manifest.entries.set(id, identity);
371
+ continue;
372
+ }
373
+ if (prior.fieldKey === identity.fieldKey || !isDisplayNameSlug(prior.fieldKey, prior.fieldName ?? identity.fieldName))
374
+ continue;
375
+ const fixed = { ...prior, fieldKey: identity.fieldKey };
376
+ manifest.entries.set(id, fixed);
377
+ corrected.set(id, fixed);
378
+ }
379
+ await mergeFieldRefsRegistry(orgRoot, corrected);
380
+ // Options come from state only (#2568). The manifest's id → label copy has
381
+ // no owning field and is never pruned, so pull does not read it.
382
+ return {
383
+ fieldRefsById: manifest.entries,
384
+ picklistOptionsByField: picklistOptionsByFieldFromState(resources),
385
+ fieldNamesByOwnerRefName: buildFieldNamesByOwnerRefName(manifest.entries),
386
+ };
387
+ }
388
+ /** Back-compat alias — most callers only need the field-id map. */
389
+ export async function loadFieldRefsRegistry(orgRoot) {
390
+ return (await loadPulledFieldRefsContext(orgRoot)).fieldRefsById;
391
+ }
392
+ /** The registry file's own entries (no state-derived refs), as a pull found them before it changed any (edk#2628). */
393
+ export async function readFieldRefsRegistryEntries(orgRoot) {
394
+ return (await readManifest(orgRoot)).entries;
395
+ }
396
+ /**
397
+ * Put one root's registry entries back to `entries` (taken by {@link readFieldRefsRegistryEntries} before the
398
+ * pull), leaving every other root's entries as they are. A failed pull that restores the root's source calls
399
+ * this, so a later pull does not print refs to fields the restored source doesn't have (edk#2628).
400
+ */
401
+ export async function restoreOwnerFieldRefs(orgRoot, ownerRefName, entries) {
402
+ const { entries: current, picklistOptionLabelById } = await readManifest(orgRoot);
403
+ const next = Object.fromEntries([...current].filter(([, identity]) => identity.ownerRefName !== ownerRefName));
404
+ for (const [id, identity] of entries) {
405
+ if (identity.ownerRefName === ownerRefName)
406
+ next[id] = identity;
407
+ }
408
+ const picklistOptionLabels = Object.fromEntries(picklistOptionLabelById);
409
+ const manifest = {
410
+ version: MANIFEST_VERSION,
411
+ entries: next,
412
+ ...(Object.keys(picklistOptionLabels).length > 0 ? { picklistOptionLabels } : {}),
413
+ };
414
+ await mkdir(join(resolve(orgRoot), ".edk-state"), { recursive: true });
415
+ const tmpPath = `${manifestPath(orgRoot)}.tmp-${randomUUID()}`;
416
+ await writeFile(tmpPath, JSON.stringify(manifest, null, 2), "utf8");
417
+ await rename(tmpPath, manifestPath(orgRoot));
418
+ }
419
+ /** Persist new entries — best-effort, never blocks the pull. */
420
+ export async function mergeFieldRefsRegistry(orgRoot, additions, picklistAdditions = new Map()) {
421
+ if (additions.size === 0 && picklistAdditions.size === 0)
422
+ return;
423
+ const path = manifestPath(orgRoot);
424
+ const { entries: existingEntries, picklistOptionLabelById: existingPicklist } = await readManifest(orgRoot);
425
+ const entries = Object.fromEntries(existingEntries);
426
+ for (const [id, identity] of additions)
427
+ entries[id] = identity;
428
+ const picklistOptionLabels = Object.fromEntries(existingPicklist);
429
+ for (const [id, label] of picklistAdditions)
430
+ picklistOptionLabels[id] = label;
431
+ const manifest = {
432
+ version: MANIFEST_VERSION,
433
+ entries,
434
+ ...(Object.keys(picklistOptionLabels).length > 0 ? { picklistOptionLabels } : {}),
435
+ };
436
+ try {
437
+ await mkdir(join(resolve(orgRoot), ".edk-state"), { recursive: true });
438
+ const tmpPath = `${path}.tmp-${randomUUID()}`;
439
+ await writeFile(tmpPath, JSON.stringify(manifest, null, 2), "utf8");
440
+ await rename(tmpPath, path);
441
+ }
442
+ catch {
443
+ // best-effort
444
+ }
445
+ }
446
+ /** Export tf labels that may key import addresses for this root. */
447
+ function ownerTfLabelsForImportLookup(root) {
448
+ const labels = [];
449
+ const seen = new Set();
450
+ const add = (label) => {
451
+ if (label === undefined || label === "" || seen.has(label))
452
+ return;
453
+ seen.add(label);
454
+ labels.push(label);
455
+ };
456
+ // Namespace is the live export/tf label. After authored-dir rebind,
457
+ // tsLabelToTfLabel(eDKCloudBuilder) is e_d_k_cloud_builder and misses
458
+ // import keys like apps_edkcloudbuilder_edkcloudbuilder_title.
459
+ add(root.namespace);
460
+ add(tsLabelToTfLabel(root.refName));
461
+ return labels;
462
+ }
463
+ function importedFieldId(extract, ownerTfLabels, fieldKey, scope) {
464
+ const childPart = tsLabelToTfLabel(fieldKey);
465
+ const fieldTypes = fieldResourceTypes();
466
+ for (const ownerTfLabel of ownerTfLabels) {
467
+ const label = scopedResourceLabel(ownerTfLabel, childPart, scope);
468
+ const imported = fieldTypes.map((type) => extract.importIds.get(`${type}.${label}`)).find((id) => id !== undefined);
469
+ if (imported !== undefined)
470
+ return imported;
471
+ }
472
+ return undefined;
473
+ }
474
+ /** Collect field-id identities from one stream-root extract's import blocks. */
475
+ export function collectFieldRefEntriesFromExtract(root, extract, scope) {
476
+ const out = new Map();
477
+ const ownerTfLabels = ownerTfLabelsForImportLookup(root);
478
+ for (const field of root.fields) {
479
+ const imported = importedFieldId(extract, ownerTfLabels, field.key, scope);
480
+ if (imported !== undefined) {
481
+ const fieldName = "name" in field.field && typeof field.field.name === "string" ? field.field.name : undefined;
482
+ const fieldType = "type" in field.field && typeof field.field.type === "string" ? field.field.type : undefined;
483
+ out.set(importLeafId(imported), {
484
+ ownerRefName: root.refName,
485
+ fieldKey: field.key,
486
+ ...(fieldName !== undefined && fieldName !== "" ? { fieldName } : {}),
487
+ ...(fieldType !== undefined && fieldType !== "" ? { fieldType } : {}),
488
+ });
489
+ }
490
+ }
491
+ return out;
492
+ }
493
+ /** Merge extract-derived field ids into the pull ctx and persist for later runs. */
494
+ export async function rememberPulledFieldIdentities(orgRoot, target, root, extract, scope) {
495
+ const additions = new Map();
496
+ for (const [id, identity] of collectFieldRefEntriesFromExtract(root, extract, scope)) {
497
+ target.set(id, identity);
498
+ additions.set(id, identity);
499
+ }
500
+ await mergeFieldRefsRegistry(orgRoot, additions);
501
+ }
@@ -56,6 +56,7 @@ export interface OrgExtract {
56
56
  readonly aiProviders: readonly OrgIdentity[];
57
57
  readonly groups: readonly OrgIdentity[];
58
58
  readonly phoneProviders: readonly OrgIdentity[];
59
+ readonly voiceAuths: readonly OrgIdentity[];
59
60
  readonly storedFunctions?: readonly OrgStoredFunction[];
60
61
  /** Non-fatal export anomalies; callers report these and continue the pull. */
61
62
  readonly diagnostics?: readonly string[];
@@ -33,6 +33,7 @@ export function extractOrg(doc) {
33
33
  aiProviders: [],
34
34
  groups: [],
35
35
  phoneProviders: [],
36
+ voiceAuths: [],
36
37
  };
37
38
  let apps;
38
39
  let storedFunctions = [];
@@ -100,6 +101,7 @@ export function extractOrg(doc) {
100
101
  aiProviders,
101
102
  groups: withTsLabels(raw.groups),
102
103
  phoneProviders: withTsLabels(raw.phoneProviders),
104
+ voiceAuths: withTsLabels(raw.voiceAuths),
103
105
  storedFunctions,
104
106
  diagnostics,
105
107
  apps,
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generic stream partition: terraform resource blocks → buckets by entity
3
+ * kind, using the registry's TYPE_TO_KIND + matchType. Unknown types and
4
+ * known-but-unimplemented subtypes are reported, never silently dropped.
5
+ */
6
+ import { type StreamPartition } from "../../graph/index.js";
7
+ import type { TfDocument } from "../tf/index.js";
8
+ export declare function partitionStream(doc: TfDocument): StreamPartition;