@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
@@ -0,0 +1,73 @@
1
+ import { scopedLabelToBagKey } from "../../engine/tf/index.js";
2
+ import { NO_CANVAS, NO_CATALOG, NO_DATA } from "../../graph/types.js";
3
+ import { appStageKeyByHandle, LostStageHandleError, stageHandleIndexFromTfStages } from "../app/stage-keys.js";
4
+ import { slaFromTf, UnmanagedSlaError } from "./from-tf.js";
5
+ import { printSla } from "./printer.js";
6
+ import { slaToTf } from "./to-tf.js";
7
+ export const SLA_RESOURCE_TYPE = "elementum_sla";
8
+ function extract(blocks, _stream, ctx) {
9
+ const items = [];
10
+ const skipped = [];
11
+ const releaseIfManaged = [];
12
+ const quarantineOwnFiles = [];
13
+ const diagnostics = [];
14
+ const stageHandles = stageHandleIndexFromTfStages(ctx.resourceByAddress?.(`elementum_app.${ctx.appTfLabel}`)?.attrs["stages"]);
15
+ for (const block of blocks) {
16
+ try {
17
+ items.push(slaFromTf(block, ctx.appTfLabel, stageHandles, ctx));
18
+ }
19
+ catch (error) {
20
+ // Only an SLA on a stage with no authored handle (#1136) or with no
21
+ // targets is a supported, reported gap: it stays platform-managed, its
22
+ // state is released and its authored file archived, so the next plan
23
+ // neither destroys the live clock nor creates a second one (#1858).
24
+ // Any other extract error is malformed structure and fails the pull,
25
+ // since a skipped block left in state would plan a destroy.
26
+ if (!(error instanceof LostStageHandleError) && !(error instanceof UnmanagedSlaError))
27
+ throw error;
28
+ const address = `${block.type}.${block.label ?? ""}`;
29
+ skipped.push(address);
30
+ releaseIfManaged.push(address);
31
+ if (block.label !== undefined) {
32
+ quarantineOwnFiles.push({ kind: "sla", refName: scopedLabelToBagKey(ctx.appTfLabel, block.label, "app") });
33
+ }
34
+ diagnostics.push(`${error.message}; its authored file, if any, is archived so the next plan does not create a duplicate`);
35
+ }
36
+ }
37
+ return {
38
+ items,
39
+ skipped,
40
+ ...(releaseIfManaged.length > 0 && { releaseIfManaged }),
41
+ ...(quarantineOwnFiles.length > 0 && { quarantineOwnFiles }),
42
+ diagnostics,
43
+ };
44
+ }
45
+ /** App SLA clocks (edk#600): `apps/<appRef>/slas/<slaRef>.ts`. */
46
+ export const slaModule = {
47
+ kind: "sla",
48
+ stream: { role: "streamMember" },
49
+ authoring: { unit: "ownFile", bag: "slas" },
50
+ parents: [{ parent: "app", child: "sla" }],
51
+ resource: { shape: "single", resourceType: SLA_RESOURCE_TYPE, adoptable: true },
52
+ data: NO_DATA,
53
+ lifecycle: {
54
+ participates: true,
55
+ extractOwnFile: extract,
56
+ printOwnFile: (item, opts) => {
57
+ const sla = item;
58
+ return { refName: sla.refName, source: printSla(sla, opts.appRefName) };
59
+ },
60
+ toTf: (entity, ctx) => slaToTf(entity, {
61
+ appRefName: ctx.appRefName,
62
+ appTfLabel: ctx.appTfLabel,
63
+ diagnostics: ctx.diagnostics,
64
+ ...(ctx.fieldAddresses !== undefined ? { fieldAddresses: ctx.fieldAddresses } : {}),
65
+ ...(() => {
66
+ const stageKeyByTfLabel = appStageKeyByHandle(ctx.streamRootEntity?.payload);
67
+ return stageKeyByTfLabel !== undefined ? { stageKeyByTfLabel } : {};
68
+ })(),
69
+ }),
70
+ },
71
+ canvas: NO_CANVAS,
72
+ catalog: NO_CATALOG,
73
+ };
@@ -0,0 +1,2 @@
1
+ import type { NormalizedSla } from "./from-tf.js";
2
+ export declare function printSla(sla: NormalizedSla, appRefName: string): string;
@@ -0,0 +1,84 @@
1
+ import { sdkPackageSpecifier } from "../../internal/sdk-package.js";
2
+ import { printFilter } from "../shared/filters/print.js";
3
+ import { safeIdentifier } from "../../internal/safe-identifier.js";
4
+ import { slaTimeUnit, slaWeekDay } from "./build.js";
5
+ import { scopedLabelToBagKey, tsLabelToTfLabel } from "../../engine/tf/index.js";
6
+ const safeKey = (value) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value) ? value : JSON.stringify(value);
7
+ const timeUnitKey = new Map(Object.entries(slaTimeUnit).map(([key, value]) => [value, key]));
8
+ const weekDayKey = new Map(Object.entries(slaWeekDay).map(([key, value]) => [value, key]));
9
+ const weekDayOrder = Object.values(slaWeekDay);
10
+ /**
11
+ * A value the public constants do not cover prints as an explicit TODO that
12
+ * fails to type-check, so it is never silently replaced with a guess.
13
+ */
14
+ function constant(name, keys, value) {
15
+ const key = keys.get(value);
16
+ return key !== undefined ? `${name}.${key}` : `${JSON.stringify(value)} /* TODO: unsupported ${name} value */`;
17
+ }
18
+ export function printSla(sla, appRefName) {
19
+ const identifier = safeIdentifier(sla.refName, "sla");
20
+ const approvalOwned = sla.approvalProcessTfLabel !== undefined;
21
+ const lines = [
22
+ "/**",
23
+ " * Auto-generated by EDK (v2 pull). Hand-edit freely; the generator is a",
24
+ " * one-shot starting point, not a live-binding view.",
25
+ " */",
26
+ "",
27
+ `import { sla, slaTimeUnit, slaWeekDay${sla.targets.some((target) => target.filter !== undefined) ? ", filter" : ""} } from ${JSON.stringify(sdkPackageSpecifier("app"))};`,
28
+ 'import catalog from "@catalog";',
29
+ "",
30
+ `const ${identifier} = sla({`,
31
+ ...(approvalOwned
32
+ ? [` approvalProcess: catalog.${safeKey(appRefName)}.approvalChains.${safeKey(scopedLabelToBagKey(tsLabelToTfLabel(appRefName), sla.approvalProcessTfLabel, "app"))},`]
33
+ : [` app: catalog.${safeKey(appRefName)},`]),
34
+ ` name: ${JSON.stringify(sla.name)},`,
35
+ ...(sla.description !== undefined ? [` description: ${JSON.stringify(sla.description)},`] : []),
36
+ ...(sla.active ? [] : [" active: false,"]),
37
+ ...(approvalOwned ? [] : [` stages: [${sla.stages.map((stage) => JSON.stringify(stage)).join(", ")}],`]),
38
+ ];
39
+ lines.push(" targets: [");
40
+ for (const target of sla.targets) {
41
+ const days = [...target.workingWeekDays]
42
+ .sort((a, b) => {
43
+ const ai = weekDayOrder.indexOf(a);
44
+ const bi = weekDayOrder.indexOf(b);
45
+ return (ai < 0 ? 99 : ai) - (bi < 0 ? 99 : bi) || a.localeCompare(b);
46
+ })
47
+ .map((day) => constant("slaWeekDay", weekDayKey, day));
48
+ lines.push(" {", ` name: ${JSON.stringify(target.name)},`, ` time: { amount: ${target.timePeriod}, unit: ${constant("slaTimeUnit", timeUnitKey, target.timeUnit)} },`, " workingHours: {", ` days: [${days.join(", ")}],`, ` start: ${JSON.stringify(target.workingStartTime)},`, ` end: ${JSON.stringify(target.workingEndTime)},`, ...(target.workingTimezone !== undefined ? [` timezone: ${JSON.stringify(target.workingTimezone)},`] : []), " },", ...(target.filter !== undefined ? [` filter: ${printSlaFilter(target.filter, appRefName)},`] : []), ...(target.approval !== undefined ? [printApproval(target.approval)] : []), " },");
49
+ }
50
+ lines.push(" ],");
51
+ lines.push("});", "", `export default ${identifier};`, "");
52
+ return lines.join("\n");
53
+ }
54
+ function printSlaFilterField(left, appRefName) {
55
+ if (left.kind === "field") {
56
+ if (left.appHandle === appRefName || left.foreign === undefined) {
57
+ return `catalog.${appRefName}.fields.${left.fieldKey}`;
58
+ }
59
+ return `catalog.${left.appHandle}.fields.${left.fieldKey}`;
60
+ }
61
+ if (left.kind === "unresolved") {
62
+ return `/* TODO: unresolved filter field ${JSON.stringify(left.uuid)} */ undefined as any`;
63
+ }
64
+ return `/* TODO: unexpected filter left-hand side kind ${JSON.stringify(left.kind)} */ undefined as any`;
65
+ }
66
+ function printSlaFilter(filter, appRefName) {
67
+ return printFilter(filter, {
68
+ field: (field) => printSlaFilterField(field, appRefName),
69
+ reference: (reference) => printSlaFilterField(reference, appRefName),
70
+ });
71
+ }
72
+ function printApproval(approval) {
73
+ // entityId must never reach here: from-tf leaves those SLAs unmanaged
74
+ // (raw platform ids are not typed approver/conditional refs yet).
75
+ if (approval.entityId !== undefined) {
76
+ throw new Error("sla printer: approval.entityId is a raw platform id; the SLA should have been left unmanaged");
77
+ }
78
+ const parts = [];
79
+ if (approval.entityType !== undefined)
80
+ parts.push(`entityType: ${JSON.stringify(approval.entityType)}`);
81
+ if (parts.length === 0)
82
+ return " approval: {},";
83
+ return ` approval: { ${parts.join(", ")} },`;
84
+ }
@@ -0,0 +1,12 @@
1
+ import { type DeployableEntity } from "../../engine/entity.js";
2
+ import { type TfBlock } from "../../engine/tf/index.js";
3
+ export declare function slaToTf(entity: DeployableEntity, ctx: {
4
+ readonly appRefName: string;
5
+ readonly appTfLabel: string;
6
+ readonly stageKeyByTfLabel?: ReadonlyMap<string, string>;
7
+ readonly diagnostics?: string[];
8
+ readonly fieldAddresses?: ReadonlyMap<string, string>;
9
+ }): {
10
+ readonly blocks: readonly TfBlock[];
11
+ readonly address: string;
12
+ };
@@ -0,0 +1,81 @@
1
+ import { EntityTfError } from "../../engine/entity.js";
2
+ import { filterToTf } from "../access-policy/to-tf.js";
3
+ import { appScopedResourceLabel, expr, tsLabelToTfLabel } from "../../engine/tf/index.js";
4
+ import { APP_RESOURCE_TYPE } from "../app/module.js";
5
+ import { APPROVAL_PROCESS_RESOURCE_TYPE } from "../approval-chain/module.js";
6
+ import { SLA_RESOURCE_TYPE } from "./module.js";
7
+ export function slaToTf(entity, ctx) {
8
+ if (entity.kind !== "sla")
9
+ throw new EntityTfError(`slaToTf expects kind "sla"; got "${entity.kind}"`);
10
+ const payload = entity.payload;
11
+ if (payload === null)
12
+ throw new EntityTfError(`sla "${entity.refName}" has no payload`);
13
+ const approvalOwned = payload.approvalProcess !== undefined;
14
+ if (approvalOwned) {
15
+ if (payload.approvalProcess?.parent !== ctx.appRefName) {
16
+ throw new EntityTfError(`sla "${entity.refName}" approval process is not under owning app "${ctx.appRefName}"`);
17
+ }
18
+ }
19
+ else if (payload.app?.refName !== ctx.appRefName) {
20
+ throw new EntityTfError(`sla "${entity.refName}" does not reference owning app "${ctx.appRefName}"`);
21
+ }
22
+ const label = appScopedResourceLabel(ctx.appTfLabel, tsLabelToTfLabel(entity.refName));
23
+ const attrs = {
24
+ name: payload.name ?? "",
25
+ ...(payload.description !== undefined ? { description: payload.description } : {}),
26
+ active: payload.active ?? true,
27
+ targets: (payload.targets ?? []).map((target, index) => {
28
+ const base = {
29
+ name: target.name ?? "",
30
+ time_period: target.timePeriod ?? 0,
31
+ time_unit: target.timeUnit ?? "",
32
+ working_start_time: target.workingStartTime ?? "",
33
+ working_end_time: target.workingEndTime ?? "",
34
+ ...(target.workingTimezone !== undefined ? { working_timezone: target.workingTimezone } : {}),
35
+ working_week_days: [...(target.workingWeekDays ?? [])],
36
+ };
37
+ if (target.filter !== undefined) {
38
+ base["filter"] = filterToTf(target.filter, `elementum_sla.${label}.targets[${index}].filter`, {
39
+ ownerTfLabel: ctx.appTfLabel,
40
+ appRefName: ctx.appRefName,
41
+ ownerRefName: ctx.appRefName,
42
+ scope: "app",
43
+ objectId: expr.resourceAttr(APP_RESOURCE_TYPE, ctx.appTfLabel, ["id"]),
44
+ diagnostics: ctx.diagnostics ?? [],
45
+ resolvePicklistLiterals: false,
46
+ ...(ctx.fieldAddresses !== undefined ? { fieldAddresses: ctx.fieldAddresses } : {}),
47
+ });
48
+ }
49
+ if (target.approval !== undefined) {
50
+ const approval = {};
51
+ if (target.approval.entityType !== undefined)
52
+ approval["entity_type"] = target.approval.entityType;
53
+ if (Object.keys(approval).length > 0)
54
+ base["approval"] = approval;
55
+ }
56
+ return base;
57
+ }),
58
+ };
59
+ if (approvalOwned) {
60
+ const processTfLabel = appScopedResourceLabel(ctx.appTfLabel, tsLabelToTfLabel(payload.approvalProcess.refName ?? ""));
61
+ attrs["approval_process_id"] = expr.resourceAttr(APPROVAL_PROCESS_RESOURCE_TYPE, processTfLabel, ["id"]);
62
+ }
63
+ else {
64
+ attrs["app_id"] = expr.resourceAttr(APP_RESOURCE_TYPE, ctx.appTfLabel, ["id"]);
65
+ attrs["stage_ids"] = (payload.stages ?? []).map((stage) => expr.local(`${ctx.appTfLabel}_stage_ids_by_key`, [{ index: stageIndex(entity.refName, stage, ctx.stageKeyByTfLabel) }]));
66
+ }
67
+ const block = { kind: "resource", type: SLA_RESOURCE_TYPE, label, attrs };
68
+ return { blocks: [block], address: `${SLA_RESOURCE_TYPE}.${label}` };
69
+ }
70
+ function stageIndex(refName, stage, stageKeyByTfLabel) {
71
+ const tfLabel = tsLabelToTfLabel(stage);
72
+ if (stageKeyByTfLabel === undefined)
73
+ return tfLabel;
74
+ const key = stageKeyByTfLabel.get(tfLabel);
75
+ if (key !== undefined)
76
+ return key;
77
+ if ([...stageKeyByTfLabel.values()].includes(stage))
78
+ return stage;
79
+ const known = [...new Set(stageKeyByTfLabel.keys())].sort().join(", ");
80
+ throw new EntityTfError(`sla "${refName}": stage "${stage}" is not a stage of the owning app (stages: ${known})`);
81
+ }
@@ -42,6 +42,11 @@ export declare function databricksTableMapping(opts: {
42
42
  readonly schema: string;
43
43
  readonly table: string;
44
44
  }): CloudMapping;
45
+ /** A table row window. The platform Limit scalar is `{ count, offset }`. */
46
+ export interface TableLimit {
47
+ readonly count: number;
48
+ readonly offset?: number;
49
+ }
45
50
  export declare function snowflakeTableView(opts: {
46
51
  readonly database: string;
47
52
  readonly schema: string;
@@ -68,7 +73,7 @@ export interface DefineTableV2Options<Columns extends Readonly<Record<string, Ta
68
73
  readonly color?: string;
69
74
  readonly cloudMapping?: CloudMapping;
70
75
  readonly filter?: Filter;
71
- readonly limit?: unknown;
76
+ readonly limit?: TableLimit;
72
77
  readonly orderBy?: unknown;
73
78
  }
74
79
  export interface TableAuthoringPayload {
@@ -85,7 +90,7 @@ export interface TableAuthoringPayload {
85
90
  readonly color?: string;
86
91
  readonly cloudMapping?: Record<string, unknown>;
87
92
  readonly filter?: Filter;
88
- readonly limit?: unknown;
93
+ readonly limit?: TableLimit;
89
94
  readonly orderBy?: unknown;
90
95
  }
91
96
  type TableColumnRefs<Columns extends Readonly<Record<string, TableColumn>>, Parent extends string> = {
@@ -19,6 +19,27 @@ export function bigQueryTableMapping(opts) {
19
19
  export function databricksTableMapping(opts) {
20
20
  return { cloudLink: opts.cloudLink, databricks: { databaseName: opts.database, schemaName: opts.schema, tableName: opts.table } };
21
21
  }
22
+ function nonNegativeInteger(value) {
23
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
24
+ }
25
+ /** Rejects a bare number and any shape other than `{ count, offset? }`. */
26
+ function tableLimitFromAuthoring(value, where) {
27
+ if (value === null || typeof value !== "object" || Array.isArray(value)) {
28
+ throw new EdkValidationError(`${where} must be { count, offset? } with a non-negative integer count.`);
29
+ }
30
+ const rec = value;
31
+ const extra = Object.keys(rec).filter((key) => key !== "count" && key !== "offset");
32
+ if (extra.length > 0) {
33
+ throw new EdkValidationError(`${where} only carries count and offset.`);
34
+ }
35
+ if (!nonNegativeInteger(rec.count)) {
36
+ throw new EdkValidationError(`${where}.count must be a non-negative integer.`);
37
+ }
38
+ if (rec.offset !== undefined && !nonNegativeInteger(rec.offset)) {
39
+ throw new EdkValidationError(`${where}.offset must be a non-negative integer.`);
40
+ }
41
+ return { count: rec.count, ...(rec.offset !== undefined ? { offset: rec.offset } : {}) };
42
+ }
22
43
  export function snowflakeTableView(opts) {
23
44
  return { snowflake: { databaseName: opts.database, schemaName: opts.schema, name: opts.name } };
24
45
  }
@@ -60,7 +81,7 @@ function payloadFor(opts, refName) {
60
81
  ...(joins != null && joins.length > 0 ? { joins } : {}),
61
82
  ...(opts.view !== undefined ? { views: [opts.view] } : {}),
62
83
  ...(opts.filter !== undefined ? { filter: opts.filter } : {}),
63
- ...(opts.limit !== undefined ? { limit: opts.limit } : {}),
84
+ ...(opts.limit !== undefined ? { limit: tableLimitFromAuthoring(opts.limit, "table limit") } : {}),
64
85
  ...(opts.orderBy !== undefined ? { orderBy: opts.orderBy } : {}),
65
86
  });
66
87
  }
@@ -37,7 +37,10 @@ export interface NormalizedTable {
37
37
  readonly description?: string;
38
38
  readonly icon?: string;
39
39
  readonly color?: string;
40
- readonly limit?: number;
40
+ readonly limit?: {
41
+ readonly count: number;
42
+ readonly offset?: number;
43
+ };
41
44
  readonly orderBy?: unknown;
42
45
  readonly filter?: Filter<NormalizedTableFilterField, TfValue>;
43
46
  readonly joins: readonly NormalizedJoin[];
@@ -3,7 +3,29 @@ import { isTfExpr, sanitizeName, snakeSlug, tfLabelToTsLabel, tsLabelToTfLabel }
3
3
  import { tableDataminesFromTf } from "../datamine/from-tf.js";
4
4
  import { TABLE_RESOURCE_TYPE } from "./module.js";
5
5
  import { EntityTfError } from "../../engine/entity.js";
6
+ import { catalogRefForAspectOwner } from "../shared/aspect-target-from-tf.js";
6
7
  import { filterFromTf } from "../shared/filters/tf-codec.js";
8
+ import { optionLookupDecode } from "../shared/filters/option-lookups.js";
9
+ function nonNegativeInteger(value) {
10
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
11
+ }
12
+ /** A present limit that is not {count, offset} fails the pull. Dropping it would clear the live limit on the next apply (#2679). */
13
+ function tableLimitFromAttr(value, where) {
14
+ const rec = plainObject(value);
15
+ if (rec === undefined)
16
+ throw new EntityTfError(`${where} must be { count, offset }`);
17
+ const extra = Object.keys(rec).filter((key) => key !== "count" && key !== "offset");
18
+ if (extra.length > 0)
19
+ throw new EntityTfError(`${where} only carries count and offset`);
20
+ const count = rec["count"];
21
+ const offset = rec["offset"];
22
+ if (!nonNegativeInteger(count))
23
+ throw new EntityTfError(`${where}.count must be a non-negative integer`);
24
+ if (offset !== undefined && offset !== null && !nonNegativeInteger(offset)) {
25
+ throw new EntityTfError(`${where}.offset must be a non-negative integer`);
26
+ }
27
+ return { count, ...(nonNegativeInteger(offset) ? { offset } : {}) };
28
+ }
7
29
  function str(obj, key) {
8
30
  return typeof obj[key] === "string" ? obj[key] : undefined;
9
31
  }
@@ -12,18 +34,65 @@ function stringList(value) {
12
34
  return undefined;
13
35
  return value;
14
36
  }
15
- function sourceRef(value) {
16
- for (const [kind, type] of [
17
- ["app", "elementum_app"],
18
- ["element", "elementum_element"],
19
- ["table", "elementum_table"],
20
- ]) {
21
- const label = dataRefLabel(value, type) ?? resourceRefLabel(value, type);
22
- if (label !== undefined)
23
- return { kind, refName: tfLabelToTsLabel(label) };
37
+ const SOURCE_TYPES = [
38
+ ["app", "elementum_app"],
39
+ ["element", "elementum_element"],
40
+ ["table", "elementum_table"],
41
+ ];
42
+ function ownerLabel(value) {
43
+ for (const [kind, type] of SOURCE_TYPES) {
44
+ const dataLabel = dataRefLabel(value, type);
45
+ if (dataLabel !== undefined)
46
+ return { kind, type, label: dataLabel, data: true };
47
+ const resourceLabel = resourceRefLabel(value, type);
48
+ if (resourceLabel !== undefined)
49
+ return { kind, type, label: resourceLabel, data: false };
24
50
  }
25
51
  return undefined;
26
52
  }
53
+ function stringAttr(attrs, key) {
54
+ const value = attrs?.[key];
55
+ return typeof value === "string" && value !== "" ? value : undefined;
56
+ }
57
+ /**
58
+ * Catalog key for an app or element source. The export labels the resource
59
+ * by sanitized namespace, which is not the workspace refName when the two
60
+ * differ (#2667). The field-label prefix stays the export label; only the
61
+ * catalog key is remapped.
62
+ */
63
+ function aspectOwnerRefName(ctx, owner) {
64
+ const attrs = owner.data
65
+ ? ctx.dataAttrs?.(owner.type, owner.label)
66
+ : ctx.resourceByAddress?.(`${owner.type}.${owner.label}`)?.attrs;
67
+ const namespace = stringAttr(attrs, "namespace");
68
+ const name = owner.data
69
+ ? ctx.dataName(owner.type, owner.label) ?? stringAttr(attrs, "name")
70
+ : stringAttr(attrs, "name");
71
+ return catalogRefForAspectOwner({
72
+ ...(namespace !== undefined && { namespace }),
73
+ ...(name !== undefined && { name }),
74
+ tfLabel: owner.label,
75
+ refNamesByNamespace: owner.kind === "app" ? ctx.foreignAppRefNamespaces : ctx.foreignElementRefNamespaces,
76
+ refNamesByName: owner.kind === "app" ? ctx.foreignAppRefNames : ctx.foreignElementRefNames,
77
+ }) ?? tfLabelToTsLabel(owner.label);
78
+ }
79
+ function sourceRef(value, ctx) {
80
+ const owner = ownerLabel(value);
81
+ if (owner === undefined)
82
+ return undefined;
83
+ if (owner.kind !== "app" && owner.kind !== "element") {
84
+ return { kind: "table", refName: tfLabelToTsLabel(owner.label) };
85
+ }
86
+ return {
87
+ kind: owner.kind,
88
+ refName: aspectOwnerRefName(ctx, {
89
+ kind: owner.kind,
90
+ type: owner.type,
91
+ label: owner.label,
92
+ data: owner.data,
93
+ }),
94
+ };
95
+ }
27
96
  function rawRef(value) {
28
97
  if (typeof value === "string")
29
98
  return value;
@@ -44,10 +113,14 @@ function fieldSourceRef(value, ctx) {
44
113
  if (fieldLabel === undefined)
45
114
  return undefined;
46
115
  const attrs = ctx.dataAttrs?.("elementum_field", fieldLabel);
47
- const owner = sourceRef(attrs?.["object_id"]);
116
+ const ownerValue = attrs?.["object_id"];
117
+ const owner = sourceRef(ownerValue, ctx);
48
118
  if (owner === undefined)
49
119
  return undefined;
50
- const prefix = `${owner.refName}_`;
120
+ // Column labels are prefixed with the export label (the sanitized
121
+ // namespace), not the workspace refName the catalog is keyed by.
122
+ const prefixLabel = ownerLabel(ownerValue)?.label;
123
+ const prefix = `${prefixLabel === undefined ? owner.refName : tfLabelToTsLabel(prefixLabel)}_`;
51
124
  const fieldPart = fieldLabel.startsWith(prefix) ? fieldLabel.slice(prefix.length) : fieldLabel;
52
125
  if (owner.kind === "table")
53
126
  return { kind: "tableColumn", parentRefName: owner.refName, refName: tfLabelToTsLabel(fieldPart) };
@@ -108,6 +181,8 @@ function tableFilterFromTf(value, tableTfLabel, columnKeyByName, ctx, where) {
108
181
  return filterFromTf(value, {
109
182
  field: (field) => tableFilterFieldFromTf(field, tableTfLabel, columnKeyByName, ctx, where),
110
183
  reference: () => { throw new EntityTfError("table filters do not support reference values"); },
184
+ // #2582: a stored option lookup prints as filter.textOption(label).
185
+ ...optionLookupDecode,
111
186
  });
112
187
  }
113
188
  function tableFilterFieldFromTf(value, tableTfLabel, columnKeyByName, ctx, where) {
@@ -212,7 +287,7 @@ export function tableFromTf(block, ctx, datamineBlocks = []) {
212
287
  const join = plainObject(item);
213
288
  if (join === undefined)
214
289
  return [];
215
- const joinedSource = sourceRef(join["source_id"]);
290
+ const joinedSource = sourceRef(join["source_id"], ctx);
216
291
  return [{
217
292
  type: (str(join, "type") ?? "LEFT"),
218
293
  ...(joinedSource !== undefined && { sourceRef: joinedSource }),
@@ -228,7 +303,7 @@ export function tableFromTf(block, ctx, datamineBlocks = []) {
228
303
  }];
229
304
  });
230
305
  const categoryLabel = dataRefLabel(attrs["category_id"], "elementum_category");
231
- const source = sourceRef(attrs["source_id"]);
306
+ const source = sourceRef(attrs["source_id"], ctx);
232
307
  const sourceID = typeof attrs["source_id"] === "string" ? attrs["source_id"] : undefined;
233
308
  const view = dataView(attrs);
234
309
  const datamines = tableDataminesFromTf(datamineBlocks, tableTfLabel, columnKeyByName, ctx, new Map(columns.flatMap((column) => [column.state.id, column.sourceFieldId]
@@ -246,7 +321,7 @@ export function tableFromTf(block, ctx, datamineBlocks = []) {
246
321
  ...(optionalString(attrs, "description", `table ${block.label}`, ctx) !== undefined && { description: optionalString(attrs, "description", `table ${block.label}`, ctx) }),
247
322
  ...(optionalString(attrs, "icon", `table ${block.label}`, ctx) !== undefined && { icon: optionalString(attrs, "icon", `table ${block.label}`, ctx) }),
248
323
  ...(optionalString(attrs, "color", `table ${block.label}`, ctx) !== undefined && { color: optionalString(attrs, "color", `table ${block.label}`, ctx) }),
249
- ...(typeof attrs["limit"] === "number" && { limit: attrs["limit"] }),
324
+ ...(attrs["limit"] !== undefined && attrs["limit"] !== null && { limit: tableLimitFromAttr(attrs["limit"], `elementum_table.${block.label}.limit`) }),
250
325
  ...(attrs["order_by"] !== undefined && { orderBy: orderBy(attrs["order_by"]) }),
251
326
  ...(attrs["filter"] !== undefined && {
252
327
  filter: tableFilterFromTf(attrs["filter"], tableTfLabel, columnKeyByName, ctx, `elementum_table.${tableTfLabel}.filter`),
@@ -2,7 +2,7 @@
2
2
  * v2 table authoring — `table`. Org-owned top-level entity.
3
3
  * Standalone from v1's `src/tables`.
4
4
  */
5
- export { table, bigQueryTableMapping, databricksTableMapping, snowflakeTableMapping, snowflakeTableView, tablePayloadToCreateRequest, tablePayloadToReadOnlyUpdateRequest, tablePayloadToUpdateRequest, type DefineTableV2Options, type TableAuthoringPayload, type TableConfigured, type TableView, } from "./build.js";
5
+ export { table, bigQueryTableMapping, databricksTableMapping, snowflakeTableMapping, snowflakeTableView, tablePayloadToCreateRequest, tablePayloadToReadOnlyUpdateRequest, tablePayloadToUpdateRequest, type DefineTableV2Options, type TableAuthoringPayload, type TableLimit, type TableConfigured, type TableView, } from "./build.js";
6
6
  export { type TableDatamine, type DatamineSchedule, type DatamineTimeUnit } from "../datamine/build.js";
7
7
  export { calculationColumn, bigQueryColumn, serializeTableField, snowflakeColumn, sourceColumn, tableAggregation, tableColumnTag, tableColumnType, tableExpansion, type CalculationColumnOptions, type SourceColumnOptions, type TableAggregation, type TableColumn, type TableColumnTag, type TableColumnType, type TableCalculationField, type TableCloudField, type TableField, type TableExpansion, type TableReferenceField, } from "./fields.js";
8
8
  export { serializeJoin, tableJoin, tableJoinType, type TableJoinFieldPair, type TableJoin, type TableJoinOptions, type TableJoinType, } from "./joins.js";
@@ -8,7 +8,29 @@ import { tableDataminesToTf, } from "../datamine/to-tf.js";
8
8
  import { authoredFieldKeysFromPayload, fieldRefToTfValue } from "../field/to-tf.js";
9
9
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
10
10
  import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
11
+ import { optionSelectionLiteral, optionsLocalName } from "../shared/filters/option-lookups.js";
11
12
  import { TABLE_RESOURCE_TYPE } from "./module.js";
13
+ function nonNegativeInteger(value) {
14
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
15
+ }
16
+ /**
17
+ * The platform's Limit scalar is {count, offset}; offset is written even when
18
+ * it is the default 0 so build matches what export writes (#2679).
19
+ */
20
+ function tableLimitToTf(limit, where) {
21
+ if (limit === null || typeof limit !== "object" || Array.isArray(limit)) {
22
+ throw new EntityTfError(`${where} must be { count, offset? }`);
23
+ }
24
+ const extra = Object.keys(limit).filter((key) => key !== "count" && key !== "offset");
25
+ if (extra.length > 0)
26
+ throw new EntityTfError(`${where} only carries count and offset`);
27
+ if (!nonNegativeInteger(limit.count))
28
+ throw new EntityTfError(`${where}.count must be a non-negative integer`);
29
+ if (limit.offset !== undefined && !nonNegativeInteger(limit.offset)) {
30
+ throw new EntityTfError(`${where}.offset must be a non-negative integer`);
31
+ }
32
+ return { count: limit.count, offset: limit.offset ?? 0 };
33
+ }
12
34
  function tableColumnName(column) {
13
35
  for (const kind of ["cloud", "calculation", "reference"]) {
14
36
  const value = column[kind];
@@ -108,6 +130,23 @@ function tableFilterToTf(filter, orgRefs, ownRef, ownLabel, ownColumnNames, work
108
130
  field: (field) => fieldId(field, orgRefs, ownRef, ownLabel, ownColumnNames, workspaceAspects, diagnostics),
109
131
  aspect: (aspect) => aspectId(aspect, orgRefs, workspaceAspects, diagnostics, "table filter aspect"),
110
132
  reference: () => { throw new EntityTfError("table filters do not support reference values"); },
133
+ // #2582: a Dropdown option is selected with filter.textOption(label).
134
+ literal: optionSelectionLiteral({
135
+ where: `table ${ownRef} filter`,
136
+ address: `${TABLE_RESOURCE_TYPE}.${ownLabel}`,
137
+ name: ownRef,
138
+ ownerKind: "table",
139
+ optionsLocal: (field) => {
140
+ const ref = field;
141
+ if (ref.__kind !== "field")
142
+ return undefined;
143
+ const kind = ref.parentKind ?? "app";
144
+ if (kind !== "app" && kind !== "element")
145
+ return undefined;
146
+ const local = workspaceAspects?.get(workspaceAspectKey(kind, ref.parent ?? ""));
147
+ return local === undefined ? undefined : optionsLocalName(local.tfLabel, kind, field);
148
+ },
149
+ }),
111
150
  });
112
151
  }
113
152
  export function tableToTf(entity, ctx) {
@@ -208,8 +247,8 @@ export function tableToTf(entity, ctx) {
208
247
  if (p.filter !== undefined) {
209
248
  attrs["filter"] = tableFilterToTf(p.filter, ctx.orgRefs, entity.refName, label, columnNames, ctx.workspaceAspects, ctx.diagnostics);
210
249
  }
211
- if (typeof p.limit === "number")
212
- attrs["limit"] = p.limit;
250
+ if (p.limit !== undefined)
251
+ attrs["limit"] = tableLimitToTf(p.limit, `table ${entity.refName} limit`);
213
252
  if (p.orderBy !== undefined)
214
253
  attrs["order_by"] =
215
254
  typeof p.orderBy === "string"
@@ -28,7 +28,8 @@ export function taskFromTf(block, ctx, fieldBlocks = []) {
28
28
  const statusDescription = optionalString(block.attrs, "status_field_description", `task ${block.label}`, ctx);
29
29
  const refName = tfLabelToTsLabel(block.label);
30
30
  const owner = { type: TASK_RESOURCE_TYPE, label: block.label, scope: "task", refName };
31
- const fields = fieldBlocks.flatMap((fieldBlock) => fieldFromTf(fieldBlock, owner, ctx) ?? []);
31
+ const usedFieldKeys = new Set();
32
+ const fields = fieldBlocks.flatMap((fieldBlock) => fieldFromTf(fieldBlock, owner, ctx, usedFieldKeys) ?? []);
32
33
  return { refName, name, handle, namespace,
33
34
  ...(fields.length > 0 && { fields }),
34
35
  ...(categoryLabel !== undefined && { categoryRef: tfLabelToTsLabel(categoryLabel) }),
@@ -61,6 +61,7 @@ export function taskToTf(entity, ctx) {
61
61
  const field = fieldToTf(typeKey, entry[typeKey], {
62
62
  ownerTfLabel: p.namespace,
63
63
  appRefName: entity.refName,
64
+ ownerName: p.name,
64
65
  scope: "task",
65
66
  objectId,
66
67
  diagnostics: ctx.diagnostics,
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import { type FromTfContext } from "../../engine/pull/context.js";
9
9
  import { type ChildResourceScope, type TfBlock, type TfValue } from "../../engine/tf/index.js";
10
+ import { type StageHandleIndex } from "../app/stage-keys.js";
10
11
  import { type NormalizedManagedViewSort } from "./build.js";
11
12
  import type { NormalizedAgentView, NormalizedCalendarView, NormalizedCustomView, NormalizedDashboardView, NormalizedKanbanView, NormalizedLayout, NormalizedListView } from "../app/deserializer/normalize.js";
12
13
  /** Report every attribute key not in `known` as dialect growth — shared by all four view/section passes below. */
@@ -19,10 +20,13 @@ export interface ViewOwner {
19
20
  readonly ownerTfLabel: string;
20
21
  /** App vs element scope for prefix stripping. */
21
22
  readonly scope?: ChildResourceScope;
22
- /** Stage keys declared by the owning app, used when ei exports a raw stage UUID. */
23
- readonly stageKeys?: ReadonlySet<string>;
24
- /** The owning app's stage handles → real stage keys (see `stageKeyByHandle`, #1136). */
25
- readonly stageKeyByHandle?: ReadonlyMap<string, string>;
23
+ /**
24
+ * The owning app's full stage-handle index: real stage keys (used when ei
25
+ * exports a raw stage UUID), handles → real keys (#1136) and stages whose
26
+ * only fallback handle another stage holds (#1767). One field, so a caller
27
+ * cannot pass the keys and handles without the fallback losses.
28
+ */
29
+ readonly stageHandles?: StageHandleIndex;
26
30
  /**
27
31
  * Keys of the fields pull extracted for this owner. A field reference whose
28
32
  * field is not among them keeps its platform id instead of a key that