react-semaphor 0.1.568 → 0.1.569

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 (126) hide show
  1. package/README.md +0 -7
  2. package/dist/analytics-protocol/index.js +434 -454
  3. package/dist/assistant-context/index.js +1 -1
  4. package/dist/brand-studio/index.js +10 -12
  5. package/dist/briefings/index.js +4 -4
  6. package/dist/chunks/{_commonjsHelpers-DimLPMtv.js → _commonjsHelpers-Bid1ZNYj.js} +271 -222
  7. package/dist/chunks/{assistant-chat-BN5I8KuN.js → assistant-chat-Dzf2Mbph.js} +107 -109
  8. package/dist/chunks/{bookmark-impact-CJ-65omV.js → bookmark-impact-Czg6FGt5.js} +2 -2
  9. package/dist/chunks/{bookmark-state-Du3s13_V.js → bookmark-state-CflS88gq.js} +251 -250
  10. package/dist/chunks/{card-filter-builder-BBuB99GZ.js → card-filter-builder-BS982X7x.js} +986 -985
  11. package/dist/chunks/{code-editor-DJNOsgJH.js → code-editor-BsxHzm9u.js} +43 -45
  12. package/dist/chunks/{comparison-window-caption-CMLb3mut.js → comparison-window-caption-lLTgzOkM.js} +252 -253
  13. package/dist/chunks/{dashboard-YnWZC4dK.js → dashboard-BiYSbxZv.js} +1 -1
  14. package/dist/chunks/{dashboard-briefing-launcher-BF89TU2h.js → dashboard-briefing-launcher-Bdj7luOr.js} +158 -159
  15. package/dist/chunks/{dashboard-controls-atHc1EjP.js → dashboard-controls-TViDsnb8.js} +17 -19
  16. package/dist/chunks/dashboard-json-Dg9dQd9U.js +66 -0
  17. package/dist/chunks/{dates-CKO05ino.js → dates-BsPrWZIP.js} +8 -8
  18. package/dist/chunks/{edit-dashboard-visual-DdmTfn-J.js → edit-dashboard-visual-C6hoIeEJ.js} +20 -21
  19. package/dist/chunks/{filter-reach-copy-jZGzK_IH.js → filter-reach-copy-hcQ4os0u.js} +695 -699
  20. package/dist/chunks/filter-value-text-CVxEEDVl.js +146 -0
  21. package/dist/chunks/{index-CPNZW0mu.js → index-G4q89J6O.js} +74 -76
  22. package/dist/chunks/{layout-grid-0hIlqEtk.js → layout-grid-BIcoFfdS.js} +1 -1
  23. package/dist/chunks/{list-filter-DkgoCeBm.js → list-filter-C6tYkHyv.js} +1 -1
  24. package/dist/chunks/matrix-analytical-definition-dkS8szLM.js +1253 -0
  25. package/dist/chunks/matrix-member-presentation-DRa-9e6Q.js +169 -0
  26. package/dist/chunks/{matrix-operation-contract-Eb6elidS.js → matrix-operation-contract-DCVinw1o.js} +122 -122
  27. package/dist/chunks/{metric-comparison-ChXUFaZu.js → metric-comparison-n9NsIa-2.js} +175 -128
  28. package/dist/chunks/{palette-4vf2BEEg.js → palette-NjHOE_6B.js} +1 -1
  29. package/dist/chunks/pivot-result-contract-expectations-DkmueDTW.js +55 -0
  30. package/dist/chunks/{pivot-result-identity-BlbLrqaC.js → pivot-result-identity-B89X5xjb.js} +1 -1
  31. package/dist/chunks/raw-temporal-value-DdT0s47W.js +159 -0
  32. package/dist/chunks/{report-preferences-dialog-Mbd-I0wV.js → report-preferences-dialog-Xc8_GFju.js} +26 -28
  33. package/dist/chunks/{report-runtime-context-DnA_PiKo.js → report-runtime-context-BhPzLTbS.js} +1 -1
  34. package/dist/chunks/{resolve-dashboard-input-context-Du0fjN3h.js → resolve-dashboard-input-context-KqvcLcTM.js} +4784 -4764
  35. package/dist/chunks/{save-D6pHmSSP.js → save-C6VmEJTA.js} +1 -1
  36. package/dist/chunks/{saved-dashboard-context-y8N6RvjS.js → saved-dashboard-context-BeXXyoD4.js} +6 -6
  37. package/dist/chunks/{semaphor-ready-indicator-BSEdUq40.js → semaphor-ready-indicator-BNkaANsG.js} +28395 -28384
  38. package/dist/chunks/{shelf-drop-preview-context-D7QqPl36.js → shelf-drop-preview-context-C_issPBA.js} +18 -20
  39. package/dist/chunks/{stored-dashboard-d3xQYxBD.js → stored-dashboard-B6_StAty.js} +263 -265
  40. package/dist/chunks/{table-export-sheet--DUKWk6o.js → table-export-sheet-BWP2joD1.js} +1 -1
  41. package/dist/chunks/{temporal-input-presentation--2r9BLr0.js → temporal-input-presentation-scSWQXAB.js} +4 -4
  42. package/dist/chunks/{token-types-C8JymO8s.js → token-types-iKMplaBL.js} +1 -1
  43. package/dist/chunks/{upload-Cf3wXZT8.js → upload-BRW4Mwrd.js} +1 -1
  44. package/dist/chunks/validators-B8fpdinG.js +3651 -0
  45. package/dist/chunks/{variable-draft-DOX03R4A.js → variable-draft-BQ3OMjvy.js} +4 -4
  46. package/dist/dashboard/index.js +2 -2
  47. package/dist/dashboard-authoring/index.js +1527 -1517
  48. package/dist/format-utils/index.js +230 -231
  49. package/dist/index.js +236 -237
  50. package/dist/report-runtime-context/index.js +1 -1
  51. package/dist/style.css +1 -1
  52. package/dist/surfboard/index.js +2 -2
  53. package/dist/types/components/surfboard/filter/types.d.ts +5 -4
  54. package/dist/types/components/ui-custom/date-range-presets.d.ts +1 -17
  55. package/dist/types/index.js +9 -9
  56. package/dist/types/lib/hooks/use-date-filter.d.ts +3 -3
  57. package/dist/types/lib/matrix-table/matrix-card-adapter.d.ts +1 -1
  58. package/dist/types/lib/types/explorer-types.d.ts +2 -2
  59. package/dist/types/lib/types/index.d.ts +1 -1
  60. package/dist/types/lib/utils/card-definition.d.ts +7 -7
  61. package/dist/types/shared/analytics-protocol/agent-time-window.d.ts +84 -0
  62. package/dist/types/shared/analytics-protocol/applied-constraints.d.ts +2 -2
  63. package/dist/types/shared/analytics-protocol/contracts.d.ts +8 -17
  64. package/dist/types/shared/analytics-protocol/fixtures.d.ts +3 -2
  65. package/dist/types/shared/analytics-protocol/index.d.ts +2 -4
  66. package/dist/types/shared/analytics-protocol/matrix-definition-contract.d.ts +4 -4
  67. package/dist/types/shared/analytics-protocol/relative-date/describe.d.ts +18 -0
  68. package/dist/types/shared/analytics-protocol/relative-date/index.d.ts +7 -0
  69. package/dist/types/shared/analytics-protocol/relative-date/limits.d.ts +3 -0
  70. package/dist/types/shared/analytics-protocol/relative-date/presets.d.ts +11 -0
  71. package/dist/types/shared/analytics-protocol/relative-date/resolve.d.ts +49 -0
  72. package/dist/types/shared/analytics-protocol/relative-date/schemas.d.ts +76 -0
  73. package/dist/types/shared/analytics-protocol/relative-date/traits.d.ts +51 -0
  74. package/dist/types/shared/analytics-protocol/relative-date/window.d.ts +111 -0
  75. package/dist/types/shared/analytics-protocol/selection-contract.d.ts +1 -1
  76. package/dist/types/shared/assistant-protocol/context.d.ts +12 -12
  77. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +0 -2
  78. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +155 -1753
  79. package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +8 -4
  80. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +74 -74
  81. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +20 -20
  82. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +3 -0
  83. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +10 -2
  84. package/dist/types/shared/format-utils/filter-detail.d.ts +2 -8
  85. package/dist/types/shared/format-utils/filter-line.d.ts +2 -2
  86. package/dist/types/shared/format-utils/matrix-continuation.d.ts +3 -3
  87. package/dist/types/shared/temporal/index.d.ts +0 -2
  88. package/dist/types/shared/temporal/temporal-parity-fixtures.d.ts +2 -2
  89. package/package.json +2 -24
  90. package/DATA_APP_SDK.md +0 -339
  91. package/dist/chunks/dashboard-json-Cxp3inxd.js +0 -68
  92. package/dist/chunks/filter-value-text-7zhmth1S.js +0 -163
  93. package/dist/chunks/index-CuHybtft.js +0 -51
  94. package/dist/chunks/matrix-analytical-definition-C9xB_T84.js +0 -717
  95. package/dist/chunks/matrix-card-BSUeSXpD.js +0 -42
  96. package/dist/chunks/matrix-member-presentation-DZNgQpUq.js +0 -105
  97. package/dist/chunks/operators-B3zZoskU.js +0 -66
  98. package/dist/chunks/pivot-result-contract-expectations-Ddh1rNz5.js +0 -56
  99. package/dist/chunks/raw-temporal-value-Bqz8wc7L.js +0 -242
  100. package/dist/chunks/selection-reducer-OaJ-N5uN.js +0 -46
  101. package/dist/chunks/source-entity-resolution-DF6GulDn.js +0 -607
  102. package/dist/chunks/validators-wtjw0aw6.js +0 -3332
  103. package/dist/data-app-sdk/index.js +0 -1412
  104. package/dist/data-app-sdk-adapters/index.js +0 -361
  105. package/dist/data-app-sdk-validation/index.js +0 -1031
  106. package/dist/types/data-app-sdk/adapters.d.ts +0 -35
  107. package/dist/types/data-app-sdk/builders.d.ts +0 -62
  108. package/dist/types/data-app-sdk/contracts.d.ts +0 -419
  109. package/dist/types/data-app-sdk/executor.d.ts +0 -5
  110. package/dist/types/data-app-sdk/field-catalog-validation.d.ts +0 -29
  111. package/dist/types/data-app-sdk/hooks.d.ts +0 -11
  112. package/dist/types/data-app-sdk/index.d.ts +0 -9
  113. package/dist/types/data-app-sdk/provider.d.ts +0 -8
  114. package/dist/types/data-app-sdk/relationship-aware-field-policy.d.ts +0 -21
  115. package/dist/types/data-app-sdk/selection.d.ts +0 -2
  116. package/dist/types/data-app-sdk/validation.d.ts +0 -58
  117. package/dist/types/data-app-sdk-adapters.d.ts +0 -2
  118. package/dist/types/data-app-sdk-validation.d.ts +0 -2
  119. package/dist/types/data-app-sdk.d.ts +0 -2
  120. package/dist/types/shared/analytics-protocol/relative-date-filter.d.ts +0 -68
  121. package/dist/types/shared/analytics-protocol/relative-date-label.d.ts +0 -20
  122. package/dist/types/shared/analytics-protocol/time-window-schema.d.ts +0 -314
  123. package/dist/types/shared/analytics-protocol/time-window.d.ts +0 -52
  124. package/dist/types/shared/temporal/relative-date.d.ts +0 -21
  125. package/dist/types/shared/temporal/time-window-periods.d.ts +0 -21
  126. package/src/data-app-sdk/README.md +0 -402
@@ -1,3332 +0,0 @@
1
- import { M as be, y as O, x as yt, C as bt, D as vt, F as It, H as St, w as At, h as $e, j as X, k as wt, m as kt, b as xt, d as je } from "./analytics-base-schemas-BaIQrEzX.js";
2
- import { z as a } from "zod";
3
- function Ft(e) {
4
- return typeof e == "string" || typeof e == "number" && Number.isFinite(e) || typeof e == "boolean";
5
- }
6
- function Dt(e) {
7
- return !Array.isArray(e) || e.length === 0 || e.length > be || !e.every(Ft) ? {
8
- ok: !1,
9
- error: `matchValues must be 1 to ${be} string, number or boolean values.`
10
- } : { ok: !0, values: e };
11
- }
12
- const Mt = [
13
- "day",
14
- "week",
15
- "month",
16
- "quarter",
17
- "year"
18
- ], Fa = ["this", "previous"], Et = ["now", "latest_available"], Nt = [
19
- "include_partial",
20
- "complete_periods"
21
- ], Da = {
22
- second: 31536e4,
23
- minute: 5256e3,
24
- hour: 87600,
25
- day: 3650,
26
- week: 520,
27
- month: 120,
28
- quarter: 40,
29
- year: 10
30
- };
31
- function Tt(e) {
32
- return e.anchor ?? "latest_available";
33
- }
34
- function M(e) {
35
- return !!e && (e.kind === void 0 || e.kind === "relative");
36
- }
37
- function Rt(e) {
38
- return (e == null ? void 0 : e.kind) === "calendar";
39
- }
40
- function Ma(e) {
41
- return M(e) && e.anchor === "latest_available" || $t(e) ? null : M(e) && e.unit === "day" && e.completeness !== "complete_periods" ? { mode: "between", unit: "day", from: 1 - e.value, to: 0 } : jt(M(e) ? { ...e, anchor: "now" } : e);
42
- }
43
- const Ct = /* @__PURE__ */ new Set(["week", "month", "quarter", "year"]);
44
- function $t(e) {
45
- return M(e) && Ct.has(e.unit) && e.completeness !== "complete_periods";
46
- }
47
- function Ea(e) {
48
- const t = e;
49
- return t.mode === "between" ? t.unit === "day" && t.to === 0 && typeof t.from == "number" && t.from <= 0 ? { unit: "day", value: 1 - t.from } : null : t.mode === "last" && typeof t.n == "number" ? t.relativeTo === "latest_data" ? null : {
50
- unit: t.unit,
51
- value: t.n,
52
- anchor: "now",
53
- completeness: t.complete ? "complete_periods" : "include_partial"
54
- } : t.mode === "this" ? t.boundary ? null : { kind: "calendar", unit: t.unit, period: "this", ...t.toDate ? { toDate: !0 } : {} } : t.mode === "previous" ? { kind: "calendar", unit: t.unit, period: "previous" } : null;
55
- }
56
- function jt(e, t = {}) {
57
- if (Rt(e))
58
- return e.period === "previous" ? { mode: "previous", unit: e.unit } : {
59
- mode: "this",
60
- unit: e.unit,
61
- ...e.toDate ? { toDate: !0 } : {}
62
- };
63
- if (!M(e))
64
- return null;
65
- const i = Tt(e) === "latest_available" ? { relativeTo: "latest_data" } : {}, s = e.value, l = (t.completeness ?? e.completeness) === "complete_periods";
66
- switch (e.unit) {
67
- case "second":
68
- return null;
69
- case "minute":
70
- case "hour":
71
- return l ? null : { mode: "last", n: s, unit: e.unit, ...i };
72
- default:
73
- return {
74
- mode: "last",
75
- n: s,
76
- unit: e.unit,
77
- ...l ? { complete: !0 } : {},
78
- ...i
79
- };
80
- }
81
- }
82
- function o(e, t, i) {
83
- return i ? { code: e, message: t, path: i } : { code: e, message: t };
84
- }
85
- function m(e) {
86
- return typeof e == "string" && e.trim().length > 0;
87
- }
88
- function Yt(e) {
89
- const t = /* @__PURE__ */ new Set();
90
- return Ot(e, (i) => (t.add(i), `{${i}}`)), Array.from(t);
91
- }
92
- function Ot(e, t) {
93
- let i = "", s = 0, l = 0;
94
- for (; l < e.length; ) {
95
- const n = e[l];
96
- if (n === "'" || n === '"') {
97
- l = Pt(e, l);
98
- continue;
99
- }
100
- if (n === "{") {
101
- const r = e.indexOf("}", l + 1);
102
- if (r === -1) {
103
- l += 1;
104
- continue;
105
- }
106
- const d = e.slice(l + 1, r);
107
- /^[A-Za-z_][A-Za-z0-9_]*$/.test(d) && (i += e.slice(s, l) + t(d), s = r + 1), l = r + 1;
108
- continue;
109
- }
110
- l += 1;
111
- }
112
- return i + e.slice(s);
113
- }
114
- function Pt(e, t) {
115
- const i = e[t];
116
- let s = t + 1;
117
- for (; s < e.length; ) {
118
- if (e[s] === i) {
119
- if (e[s + 1] === i) {
120
- s += 2;
121
- continue;
122
- }
123
- return s + 1;
124
- }
125
- s += 1;
126
- }
127
- return e.length;
128
- }
129
- function f(e) {
130
- return !!(e && typeof e == "object" && !Array.isArray(e));
131
- }
132
- const qt = /* @__PURE__ */ new Set([
133
- "SUM",
134
- "COUNT",
135
- "AVG",
136
- "MIN",
137
- "MAX",
138
- "MEDIAN",
139
- "DISTINCT"
140
- ]);
141
- function ne(e, t, i) {
142
- if (!e || typeof e != "object") {
143
- i.push(
144
- o("missing_source", "Analytics intent needs a source.", t)
145
- );
146
- return;
147
- }
148
- if (e.kind === "semantic") {
149
- m(e.domainId) || i.push(
150
- o(
151
- "missing_semantic_domain",
152
- "Semantic source needs a domainId.",
153
- `${t}.domainId`
154
- )
155
- ), m(e.datasetName) || i.push(
156
- o(
157
- "missing_dataset_name",
158
- "Semantic source needs a datasetName.",
159
- `${t}.datasetName`
160
- )
161
- );
162
- return;
163
- }
164
- if (e.kind === "physical") {
165
- m(e.connectionId) || i.push(
166
- o(
167
- "missing_connection_id",
168
- "Physical source needs a connectionId.",
169
- `${t}.connectionId`
170
- )
171
- ), m(e.tableName) || i.push(
172
- o(
173
- "missing_table_name",
174
- "Physical source needs a tableName.",
175
- `${t}.tableName`
176
- )
177
- );
178
- return;
179
- }
180
- if (e.kind === "sql") {
181
- m(e.connectionId) || i.push(
182
- o(
183
- "missing_connection_id",
184
- "SQL source needs a connectionId.",
185
- `${t}.connectionId`
186
- )
187
- );
188
- return;
189
- }
190
- i.push(
191
- o("invalid_source_kind", "Source kind is not supported.", t)
192
- );
193
- }
194
- function y(e, t, i, s = {}) {
195
- if (!e || !f(e)) {
196
- s.required && i.push(
197
- o("missing_field_ref", "Field reference needs a name.", t)
198
- );
199
- return;
200
- }
201
- m(e.name) || i.push(
202
- o(
203
- "missing_field_ref",
204
- "Field reference needs a name.",
205
- `${t}.name`
206
- )
207
- ), e.source !== void 0 && ne(e.source, `${t}.source`, i), se(e.aggregate, `${t}.aggregate`, i);
208
- }
209
- function se(e, t, i) {
210
- e !== void 0 && (typeof e != "string" || !qt.has(e)) && i.push(
211
- o(
212
- "invalid_aggregate",
213
- "Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",
214
- t
215
- )
216
- );
217
- }
218
- const Lt = /* @__PURE__ */ new Set([
219
- "measure",
220
- "dimension",
221
- "date",
222
- "id",
223
- "unknown"
224
- ]), Bt = /* @__PURE__ */ new Set(["row", "aggregate"]), Ht = /* @__PURE__ */ new Set([
225
- "string",
226
- "number",
227
- "boolean",
228
- "date",
229
- "datetime",
230
- "unknown"
231
- ]);
232
- function Vt(e, t, i) {
233
- if (e === void 0)
234
- return;
235
- if (!f(e)) {
236
- i.push(
237
- o(
238
- "invalid_value_format",
239
- "Value format must be a structured object.",
240
- t
241
- )
242
- );
243
- return;
244
- }
245
- const s = (e.type === "temporal_bucket" ? O : yt).safeParse(e);
246
- if (s.success) return;
247
- const l = e.type === "temporal_bucket" ? "invalid_temporal_bucket_format" : "invalid_value_format";
248
- for (const n of s.error.issues)
249
- i.push(
250
- o(
251
- l,
252
- n.message,
253
- [t, ...n.path.map(String)].filter(Boolean).join(".")
254
- )
255
- );
256
- }
257
- const Ut = /* @__PURE__ */ new Set([
258
- "additive",
259
- "non_additive",
260
- "ratio_of_sums",
261
- "weighted",
262
- "pre_aggregated",
263
- "snapshot"
264
- ]), zt = /* @__PURE__ */ new Set([
265
- "default",
266
- "symmetric_aggregate",
267
- "aggregate_then_join",
268
- "weighted"
269
- ]);
270
- function Gt(e, t, i) {
271
- if (!e || !f(e)) {
272
- i.push(
273
- o(
274
- "invalid_derived_field_input",
275
- "Derived field inputs must be structured input references.",
276
- t
277
- )
278
- );
279
- return;
280
- }
281
- if (e.kind === "field") {
282
- y(e.field, `${t}.field`, i, { required: !0 }), se(e.aggregate, `${t}.aggregate`, i);
283
- return;
284
- }
285
- i.push(
286
- o(
287
- "invalid_derived_field_input",
288
- "Derived field input kind must be field.",
289
- `${t}.kind`
290
- )
291
- );
292
- }
293
- function re(e) {
294
- const t = [];
295
- if (!f(e))
296
- return t.push(
297
- o(
298
- "invalid_derived_field",
299
- "Derived field definition must be a structured object."
300
- )
301
- ), { ok: !1, errors: t, warnings: [] };
302
- if (e.kind !== "derived_field" && t.push(
303
- o(
304
- "invalid_derived_field_kind",
305
- "Derived field kind must be derived_field.",
306
- "kind"
307
- )
308
- ), m(e.name) || t.push(
309
- o(
310
- "invalid_derived_field_name",
311
- "Derived field needs a name.",
312
- "name"
313
- )
314
- ), m(e.label) || t.push(
315
- o(
316
- "invalid_derived_field_label",
317
- "Derived field needs a label.",
318
- "label"
319
- )
320
- ), Lt.has(e.resultRole) || t.push(
321
- o(
322
- "invalid_derived_field_role",
323
- "Derived field resultRole must be measure, dimension, date, id, or unknown.",
324
- "resultRole"
325
- )
326
- ), Ht.has(e.dataType) || t.push(
327
- o(
328
- "invalid_derived_field_data_type",
329
- "Derived field dataType must be string, number, boolean, date, datetime, or unknown.",
330
- "dataType"
331
- )
332
- ), Bt.has(e.computeStage) || t.push(
333
- o(
334
- "invalid_derived_field_compute_stage",
335
- "Derived field computeStage must be row or aggregate.",
336
- "computeStage"
337
- )
338
- ), e.computeStage === "aggregate" && e.resultRole !== "measure" && t.push(
339
- o(
340
- "invalid_derived_field_compute_stage",
341
- "Aggregate-stage derived fields must have resultRole measure.",
342
- "computeStage"
343
- )
344
- ), e.resultRole !== "measure" && e.defaultAggregate !== void 0 && t.push(
345
- o(
346
- "invalid_derived_field_aggregate",
347
- "Only measure derived fields may declare defaultAggregate.",
348
- "defaultAggregate"
349
- )
350
- ), e.computeStage === "row" && e.resultRole === "measure" && e.defaultAggregate === void 0 && t.push(
351
- o(
352
- "missing_derived_field_default_aggregate",
353
- "Row-stage measure derived fields must declare defaultAggregate so row results have explicit rollup semantics.",
354
- "defaultAggregate"
355
- )
356
- ), se(
357
- e.defaultAggregate,
358
- "defaultAggregate",
359
- t
360
- ), e.aggregationBehavior !== void 0 && !Ut.has(
361
- e.aggregationBehavior
362
- ) && t.push(
363
- o(
364
- "invalid_derived_field_aggregation_behavior",
365
- "Derived field aggregationBehavior is not supported.",
366
- "aggregationBehavior"
367
- )
368
- ), e.aggregationStrategy !== void 0 && !zt.has(
369
- e.aggregationStrategy
370
- ) && t.push(
371
- o(
372
- "invalid_derived_field_aggregation_strategy",
373
- "Derived field aggregationStrategy is not supported.",
374
- "aggregationStrategy"
375
- )
376
- ), m(e.expression) || t.push(
377
- o(
378
- "invalid_derived_field_expression",
379
- "Derived field needs a named-token expression.",
380
- "expression"
381
- )
382
- ), e.expressionLanguage !== void 0 && e.expressionLanguage !== "semaphor_sql_template" && t.push(
383
- o(
384
- "invalid_derived_field_expression_language",
385
- "Derived field expressionLanguage must be semaphor_sql_template.",
386
- "expressionLanguage"
387
- )
388
- ), !f(e.inputs) || Object.keys(e.inputs).length === 0 ? t.push(
389
- o(
390
- "invalid_derived_field_inputs",
391
- "Derived field needs at least one typed input.",
392
- "inputs"
393
- )
394
- ) : Object.entries(e.inputs).forEach(([s, l]) => {
395
- if (!m(s)) {
396
- t.push(
397
- o(
398
- "invalid_derived_field_input_name",
399
- "Derived field input names must be non-empty strings.",
400
- "inputs"
401
- )
402
- );
403
- return;
404
- }
405
- Gt(
406
- l,
407
- `inputs.${s}`,
408
- t
409
- );
410
- }), m(e.expression) && f(e.inputs)) {
411
- const s = Yt(
412
- e.expression
413
- ), l = new Set(s), n = Object.keys(e.inputs).filter(
414
- (r) => m(r)
415
- );
416
- s.forEach((r) => {
417
- Object.prototype.hasOwnProperty.call(e.inputs, r) || t.push(
418
- o(
419
- "invalid_derived_field_expression_token",
420
- `Derived field expression token "{${r}}" needs a matching inputs.${r} entry.`,
421
- "expression"
422
- )
423
- );
424
- }), n.forEach((r) => {
425
- l.has(r) || t.push(
426
- o(
427
- "unused_derived_field_input",
428
- `Derived field input "${r}" is not referenced by expression.`,
429
- `inputs.${r}`
430
- )
431
- );
432
- });
433
- }
434
- const i = e.format;
435
- return f(i) && i.type === "temporal_bucket" ? t.push(
436
- o(
437
- "invalid_derived_field_format",
438
- "Derived field computation metadata cannot own temporal bucket presentation; declare grain and format on the grouped field.",
439
- "format"
440
- )
441
- ) : Vt(i, "format", t), e.tags !== void 0 && (!Array.isArray(e.tags) || e.tags.some((s) => !m(s))) && t.push(
442
- o(
443
- "invalid_derived_field_tags",
444
- "Derived field tags must be non-empty strings.",
445
- "tags"
446
- )
447
- ), { ok: t.length === 0, errors: t, warnings: [] };
448
- }
449
- const D = a.string().min(1).refine((e) => e.trim().length > 0, "Must not be blank."), oe = a.union([
450
- bt.extend({ domainId: D, datasetName: D }).strict(),
451
- vt.extend({ connectionId: D, tableName: D }).strict()
452
- ]), Ye = It.extend({
453
- name: D,
454
- source: oe.optional()
455
- }).strict(), le = St.extend({
456
- format: At.optional(),
457
- inputs: a.record(
458
- a.object({
459
- kind: a.literal("field"),
460
- field: Ye,
461
- aggregate: $e.optional()
462
- }).strict()
463
- )
464
- }).strict().superRefine((e, t) => {
465
- var i;
466
- for (const s of re(e).errors)
467
- t.addIssue({
468
- code: "custom",
469
- path: ((i = s.path) == null ? void 0 : i.split(".")) ?? [],
470
- message: s.message
471
- });
472
- }), Qt = Ye.extend({
473
- derivedField: le.optional()
474
- }).strict();
475
- function de(e) {
476
- return typeof e == "string" ? e.trim().toLowerCase() : "";
477
- }
478
- function Kt(e) {
479
- return String(
480
- e.column_name || e.name || e.qualifiedFieldName || ""
481
- );
482
- }
483
- function Xt(e) {
484
- return Array.from(
485
- new Set(
486
- [e.column_name, e.name, e.qualifiedFieldName, e.alias].filter(
487
- (t) => typeof t == "string" && t.trim().length > 0
488
- ).map((t) => t.trim())
489
- )
490
- );
491
- }
492
- function ue(e) {
493
- const t = Pe(e);
494
- return t ? ei(t) ? "number" : t.includes("timestamp") || t.includes("datetime") || t.startsWith("time") ? "datetime" : t.includes("date") ? "date" : t.includes("bool") ? "boolean" : "string" : "unknown";
495
- }
496
- const U = /* @__PURE__ */ new Map([
497
- // Integer families (PostgreSQL, ClickHouse, DuckDB, MySQL).
498
- ["int", "integer"],
499
- ["uint", "integer"],
500
- ["integer", "integer"],
501
- ["uinteger", "integer"],
502
- ["bigint", "integer"],
503
- ["ubigint", "integer"],
504
- ["smallint", "integer"],
505
- ["usmallint", "integer"],
506
- ["tinyint", "integer"],
507
- ["utinyint", "integer"],
508
- ["mediumint", "integer"],
509
- ["hugeint", "integer"],
510
- ["uhugeint", "integer"],
511
- // Exact decimal families.
512
- ["numeric", "decimal"],
513
- ["decimal", "decimal"],
514
- // Binary floating point.
515
- ["float", "float"],
516
- ["double", "float"],
517
- ["real", "float"],
518
- ["bfloat16", "float"],
519
- // Numeric for grounding; storage representation not established
520
- // (`number(p, s)` with an explicit scale is resolved before this table).
521
- ["number", null],
522
- ["money", null],
523
- ["currency", null],
524
- ["percent", null]
525
- ]), Zt = ["int", "uint", "decimal", "float"];
526
- function Jt(e) {
527
- return e.length > 0 && Array.from(e).every((t) => t >= "0" && t <= "9");
528
- }
529
- function Wt(e) {
530
- var i;
531
- const t = (i = /^number\s*\(\s*\d+\s*,\s*(\d+)\s*\)$/.exec(e)) == null ? void 0 : i[1];
532
- return t === void 0 ? null : Number(t) === 0 ? "integer" : "decimal";
533
- }
534
- function Oe(e) {
535
- const t = e.split(/[\s(]/, 1)[0] || "";
536
- if (t === "number")
537
- return { numeric: !0, kind: Wt(e) };
538
- if (U.has(t))
539
- return { numeric: !0, kind: U.get(t) ?? null };
540
- const i = Zt.find(
541
- (s) => t.startsWith(s) && Jt(t.slice(s.length))
542
- );
543
- return i ? { numeric: !0, kind: U.get(i) ?? null } : { numeric: !1, kind: null };
544
- }
545
- function ei(e) {
546
- return Oe(e).numeric;
547
- }
548
- function ti(e) {
549
- return Oe(Pe(e)).kind;
550
- }
551
- function Pe(e) {
552
- let t = de(e), i = "";
553
- for (; t && t !== i; )
554
- i = t, t = ve(t, "nullable"), t = ve(t, "lowcardinality");
555
- return t;
556
- }
557
- function ve(e, t) {
558
- const i = `${t}(`;
559
- return !e.startsWith(i) || !e.endsWith(")") ? e : e.slice(i.length, -1).trim();
560
- }
561
- function ii(e) {
562
- const t = ue(e);
563
- return t === "date" || t === "datetime";
564
- }
565
- function qe(e) {
566
- return ii(e.dataType || e.data_type);
567
- }
568
- function Le(e) {
569
- const t = Be(e);
570
- return t === "id" || t === "row_id";
571
- }
572
- function Ie(e) {
573
- const t = Be(e);
574
- return Le(e) || t.endsWith("_id") || t.endsWith("_key") || t.endsWith("_number");
575
- }
576
- function Be(e) {
577
- return de(
578
- Kt(e) || e.name || e.alias
579
- ).replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
580
- }
581
- function He(e, t = {}) {
582
- const i = de(e.role);
583
- return i === "metric" || i === "measure" ? !t.excludeIdentifiers || !Ie(e) : i === "groupby" || i === "dimension" || i === "date" || i === "id" ? !1 : ue(
584
- e.dataType || e.data_type
585
- ) === "number" && (!t.excludeIdentifiers || !Ie(e));
586
- }
587
- function Na(e) {
588
- return !He(e) && !qe(e);
589
- }
590
- function Ta(e) {
591
- const t = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set();
592
- for (const l of e) {
593
- if (Le(l))
594
- continue;
595
- const n = Xt(l);
596
- if (n.length !== 0) {
597
- if (qe(l)) {
598
- n.forEach((r) => i.add(r));
599
- continue;
600
- }
601
- if (He(l, { excludeIdentifiers: !0 })) {
602
- n.forEach((r) => t.add(r));
603
- continue;
604
- }
605
- n.forEach((r) => s.add(r));
606
- }
607
- }
608
- return {
609
- validMeasureCandidates: Array.from(t).sort(),
610
- validDateCandidates: Array.from(i).sort(),
611
- validDimensionCandidates: Array.from(s).sort()
612
- };
613
- }
614
- const E = 16 * 1024;
615
- function P(e) {
616
- const t = /^([+-]?)(?:(\d+)(?:\.(\d*))?|\.(\d+))(?:[eE]([+-]?\d+))?$/.exec(e);
617
- return t ? {
618
- sign: t[1],
619
- whole: t[2] ?? "",
620
- fraction: t[3] ?? t[4],
621
- exponent: Number(t[5] ?? "0")
622
- } : null;
623
- }
624
- function Se(e) {
625
- const { sign: t, whole: i, fraction: s = "", exponent: l } = e, n = (i + s).replace(/^0+/, ""), r = n.replace(/0+$/, ""), d = l - s.length + n.length - r.length;
626
- return !Number.isSafeInteger(l) || !Number.isSafeInteger(d) ? null : r ? `${t === "-" ? "-" : ""}${r}e${d}` : "0";
627
- }
628
- function Ra(e) {
629
- const t = P(e);
630
- if (!t) return null;
631
- const i = t.sign === "+" ? e.slice(1) : e, s = Number(e);
632
- if (!Number.isFinite(s)) return i;
633
- const l = Se(t), n = P(String(s));
634
- return l !== null && n !== null && l === Se(n) ? s : i;
635
- }
636
- function Ca(e) {
637
- if (e.length > E)
638
- throw new RangeError("Exact numeric text exceeds 16 KiB.");
639
- const t = P(e);
640
- if (!t) throw new TypeError("Expected finite decimal text.");
641
- const { sign: i, whole: s, fraction: l, exponent: n } = t, r = `${i}${s || "0"}${l ? `.${l}` : ""}`;
642
- return R(`${r}e${n}`);
643
- }
644
- function R(e) {
645
- if (e.length > E)
646
- throw new RangeError("Exact numeric text exceeds 16 KiB.");
647
- const t = P(e);
648
- if (!t || t.whole === "" || t.fraction === "")
649
- throw new TypeError("Expected finite decimal text.");
650
- const { sign: i, whole: s, fraction: l = "", exponent: n } = t;
651
- if (!Number.isSafeInteger(n) || Math.abs(n) > E)
652
- throw new RangeError("Exact numeric exponent exceeds the text budget.");
653
- const r = s + l, d = s.length + n;
654
- if (Math.max(r.length, d) + Math.max(0, -d) + 3 > E)
655
- throw new RangeError("Normalized exact numeric text exceeds 16 KiB.");
656
- let p;
657
- d <= 0 ? p = `0.${"0".repeat(-d)}${r}` : d >= r.length ? p = r + "0".repeat(d - r.length) : p = `${r.slice(0, d)}.${r.slice(d)}`;
658
- const [u, g = ""] = p.split("."), _ = u.replace(/^0+(?=\d)/, ""), I = g.replace(/0+$/, ""), S = _ + (I ? `.${I}` : "");
659
- return i === "-" && S !== "0" ? `-${S}` : S;
660
- }
661
- function $a(e, t) {
662
- const i = e.startsWith("-"), s = t.startsWith("-");
663
- if (i !== s) return i ? -1 : 1;
664
- const [l, n = ""] = (i ? e.slice(1) : e).split("."), [r, d = ""] = (s ? t.slice(1) : t).split(".");
665
- let c = Math.sign(l.length - r.length);
666
- if (!c && l !== r && (c = l < r ? -1 : 1), !c) {
667
- const p = Math.max(n.length, d.length), u = n.padEnd(p, "0"), g = d.padEnd(p, "0");
668
- c = u === g ? 0 : u < g ? -1 : 1;
669
- }
670
- return c === 0 ? 0 : i ? -c : c;
671
- }
672
- function ja(e, t) {
673
- if (typeof t == "number" && !Number.isFinite(t))
674
- throw new TypeError("Numeric scale must be finite.");
675
- const i = [e, R(String(t))].map((n) => {
676
- const [r, d = ""] = n.split(".");
677
- return { coefficient: BigInt(r + d), digits: d.length };
678
- }), s = i[0].coefficient * i[1].coefficient, l = i[0].digits + i[1].digits;
679
- return R(`${s}e-${l}`);
680
- }
681
- function ai(e) {
682
- try {
683
- return R(e) === e;
684
- } catch {
685
- return !1;
686
- }
687
- }
688
- const Ve = a.object({
689
- kind: a.literal("exact_number"),
690
- type: a.enum(["integer", "decimal"]),
691
- value: a.string().max(E).refine(ai, "Expected canonical decimal text.")
692
- }).strict().superRefine((e, t) => {
693
- e.type === "integer" && e.value.includes(".") && t.addIssue({ code: "custom", path: ["value"], message: "An integer cannot have fractional digits." });
694
- }), ni = a.union([
695
- a.null(),
696
- a.string(),
697
- a.boolean(),
698
- a.number().finite(),
699
- Ve
700
- ]);
701
- function si(e, t) {
702
- return Ve.parse({ kind: "exact_number", type: t, value: R(e) });
703
- }
704
- function Ya(e) {
705
- return typeof e == "object" && e !== null && "kind" in e && e.kind === "exact_number" && "type" in e && (e.type === "integer" || e.type === "decimal") && "value" in e && typeof e.value == "string";
706
- }
707
- function Oa(e) {
708
- const t = ti(e.nativeDataType);
709
- if (!t) throw new TypeError("Numeric result type is not established.");
710
- if (e.value === null) return null;
711
- if (t === "float") {
712
- if (typeof e.value != "number" || !Number.isFinite(e.value))
713
- throw new TypeError("Expected a finite floating-point result.");
714
- return e.value;
715
- }
716
- if (e.exactText === void 0)
717
- throw new TypeError("Exact numeric sidecar is required; rounded result values cannot substitute.");
718
- return si(e.exactText, t);
719
- }
720
- const ce = a.string().uuid(), pe = a.enum(["rows", "columns"]), Pa = a.enum(["member", "subtotal", "grand_total", "others"]), ri = a.discriminatedUnion("kind", [
721
- a.object({ kind: a.literal("value"), value: ni }).strict(),
722
- a.object({ kind: a.literal("others"), rankingId: ce }).strict()
723
- ]), k = a.array(a.object({ levelId: ce, member: ri }).strict()).readonly().superRefine((e, t) => {
724
- new Set(e.map((i) => i.levelId)).size !== e.length && t.addIssue({
725
- code: "custom",
726
- path: [],
727
- message: "Duplicate identity."
728
- }), e.some(
729
- (i, s) => i.member.kind === "others" && s !== e.length - 1
730
- ) && t.addIssue({
731
- code: "custom",
732
- path: [],
733
- message: "Others is terminal."
734
- });
735
- }), qa = a.object({
736
- rowPath: k,
737
- columnPath: k,
738
- measureId: ce
739
- }).strict();
740
- function Ue(e) {
741
- return JSON.stringify(
742
- e.map(({ levelId: t, member: i }) => [
743
- t,
744
- i.kind === "others" ? ["others", i.rankingId] : typeof i.value == "object" && i.value !== null ? ["exact_number", i.value.value] : [typeof i.value, i.value]
745
- ])
746
- );
747
- }
748
- const Z = "SEMAPHOR_CALCULATED_FIELD", oi = "calculated_fields";
749
- function li(e) {
750
- return (e == null ? void 0 : e.sourceField) || (e == null ? void 0 : e.name) || "";
751
- }
752
- const di = [
753
- // Day granularity formats
754
- "MM-DD-YYYY",
755
- "YYYY-MM-DD",
756
- "MM/DD/YYYY",
757
- "DD/MM/YYYY",
758
- "MMMM DD, YYYY",
759
- "MMM DD, YYYY",
760
- "DD MMM YYYY",
761
- "YYYY-MM-DD HH:mm",
762
- "YYYY-MM-DD HH:mm:ss",
763
- "YYYY-MM-DD HH:mm Z",
764
- "YYYY-MM-DD HH:mm:ss Z",
765
- // Week granularity formats
766
- "Week of MMM DD, YYYY",
767
- "Week of MMMM DD, YYYY",
768
- "YYYY-WW",
769
- // Month granularity formats
770
- "MMM YYYY",
771
- "MMMM YYYY",
772
- "YYYY-MM",
773
- "MM/YYYY",
774
- "YYYY MMM",
775
- // Quarter granularity formats
776
- "Q1 YYYY",
777
- "YYYY Q1",
778
- "1st Quarter YYYY",
779
- "YYYY-Q1",
780
- "Quarter 1, YYYY",
781
- // Year granularity formats
782
- "YYYY",
783
- "YY",
784
- // Custom format
785
- "custom"
786
- ];
787
- function La(e) {
788
- return e.role === "metric" && "expression" in e && !!e.expression;
789
- }
790
- function Ba(e) {
791
- return !!e.expression;
792
- }
793
- function ui(e) {
794
- return !!(e && (e.calculationRepresentation || e.expression || e.derivedField || e.calculatedFieldOrigin || e.calculatedFormula || J(e)));
795
- }
796
- function ze(e) {
797
- var g, _, I;
798
- if (!e)
799
- return {
800
- representation: "physical",
801
- ownership: "local",
802
- completeness: "not-calculated",
803
- runtimeExecutable: !1,
804
- legacyManual: !1
805
- };
806
- const t = e.fieldScope === "domain" ? "domain" : "local", i = ((g = e.derivedField) == null ? void 0 : g.computeStage) || ((_ = e.calculatedFormula) == null ? void 0 : _.computeStage), s = !e.calculatedFormula || Array.isArray(e.calculatedFormula.inputFields) && e.calculatedFormula.inputFields.every((S) => {
807
- const ye = S && li(S);
808
- return typeof ye == "string" && !!ye.trim();
809
- }), l = typeof e.expression == "string" && !!e.expression.trim() && s, n = e.calculationRepresentation;
810
- if (e.derivedField || n === "typed-derived") {
811
- const S = e.derivedField !== void 0 && re(e.derivedField).ok;
812
- return {
813
- representation: "typed-derived",
814
- ownership: t,
815
- completeness: (!n || n === "typed-derived") && S && (!e.expression && !e.calculatedFormula || l) ? "complete" : "incomplete",
816
- computeStage: i,
817
- runtimeExecutable: l,
818
- legacyManual: !1
819
- };
820
- }
821
- if (!(!!n || ui(e)))
822
- return {
823
- representation: "physical",
824
- ownership: t,
825
- completeness: "not-calculated",
826
- runtimeExecutable: !1,
827
- legacyManual: !1
828
- };
829
- const d = i || (e.role === "groupby" || ((I = e.calculatedFieldOrigin) == null ? void 0 : I.role) === "groupby" ? "row" : void 0), c = t === "domain" || J(e) || e.fieldScope === "card" || e.fieldScope === "sheet" || e.fieldScope === "dashboard" ? "manual" : "inline-expression", p = n === "manual" || n === "inline-expression" ? n : c, u = (!n || n === "manual" || n === "inline-expression") && !(n === "inline-expression" && J(e));
830
- return {
831
- representation: p,
832
- ownership: t,
833
- completeness: l && u ? "complete" : "incomplete",
834
- computeStage: d,
835
- runtimeExecutable: l,
836
- legacyManual: p === "manual" && t === "local" && !d
837
- };
838
- }
839
- function Ha(e) {
840
- if (e.calculationRepresentation) return e;
841
- const { representation: t } = ze(e);
842
- return t === "physical" ? e : { ...e, calculationRepresentation: t };
843
- }
844
- function Va(e) {
845
- return ze(e).computeStage;
846
- }
847
- function Ua(e, t) {
848
- return e === "aggregate" && t === "default";
849
- }
850
- function za(e) {
851
- var i, s;
852
- const t = e;
853
- return !!(t != null && t.expression && ((s = (i = t.calculatedFormula) == null ? void 0 : i.inputFields) != null && s.length));
854
- }
855
- function Ga(e) {
856
- return !!(e && (e.entityName === Z || e.entityId === Z));
857
- }
858
- function J(e) {
859
- return e ? [e.entityName, e.entityId, e.qualifiedEntityName].some(
860
- (t) => t === Z || t === oi
861
- ) : !1;
862
- }
863
- function ci(e) {
864
- const t = Qe(e);
865
- return t.length > 0 ? t.join(".") : void 0;
866
- }
867
- function Qa(e) {
868
- const t = ci(
869
- e.qualifiedName
870
- ), i = (t == null ? void 0 : t.split(".")) || [];
871
- if (i.length === 0) return {};
872
- const s = {};
873
- let l = i.length - 1;
874
- for (let n = e.capabilities.prefixLevels.length - 1; n >= 0 && l >= 0; n -= 1, l -= 1)
875
- fi(
876
- s,
877
- e.capabilities.prefixLevels[n],
878
- i[l]
879
- );
880
- return s;
881
- }
882
- function Ka(e) {
883
- return !e.left.tableName || !e.right.tableName ? !1 : e.capabilities.prefixLevels.every((t) => {
884
- const i = x(e.left, t), s = x(e.right, t);
885
- return !i || !s || i === s;
886
- });
887
- }
888
- function Xa(e) {
889
- return e.capabilities.prefixLevels.every((t) => {
890
- const i = x(e.requested, t);
891
- return i ? x(e.allowed, t) === i : !0;
892
- });
893
- }
894
- function Ge(e, t = {}) {
895
- const i = C(e), s = {
896
- connectionId: t.connectionId,
897
- connectionType: e,
898
- path: ["database", "schema", "table"],
899
- labels: {
900
- database: "Database",
901
- schema: "Schema",
902
- table: "Table"
903
- },
904
- prefixLevels: ["database", "schema", "table"],
905
- dialect: "postgres",
906
- supportsFilterClause: !0
907
- };
908
- return i.includes("postgres") ? {
909
- ...s,
910
- prefixLevels: ["schema", "table"],
911
- dialect: "postgres"
912
- } : i.includes("mysql") ? {
913
- ...s,
914
- prefixLevels: ["database", "table"],
915
- dialect: "mysql",
916
- supportsFilterClause: !1
917
- } : i.includes("mssql") || i.includes("sqlserver") ? {
918
- ...s,
919
- dialect: "mssql",
920
- supportsFilterClause: !1
921
- } : i.includes("redshift") ? {
922
- ...s,
923
- prefixLevels: ["schema", "table"],
924
- dialect: "redshift"
925
- } : i.includes("snowflake") ? {
926
- ...s,
927
- dialect: "snowflake"
928
- } : i.includes("clickhouse") ? {
929
- connectionId: t.connectionId,
930
- connectionType: e,
931
- path: ["database", "table"],
932
- labels: {
933
- database: "Database",
934
- table: "Table"
935
- },
936
- prefixLevels: ["database", "table"],
937
- dialect: "clickhouse",
938
- supportsFilterClause: !1
939
- } : i === "s3" || i === "api" ? {
940
- connectionId: t.connectionId,
941
- connectionType: e,
942
- path: ["table"],
943
- labels: {
944
- table: i === "api" ? "API Table" : "File Table"
945
- },
946
- prefixLevels: ["table"],
947
- dialect: "duckdb",
948
- supportsFilterClause: !0
949
- } : i === "googlesheets" || i === "fileupload" ? {
950
- connectionId: t.connectionId,
951
- connectionType: e,
952
- path: ["table"],
953
- labels: {
954
- table: "Table"
955
- },
956
- prefixLevels: ["table"],
957
- dialect: "postgres",
958
- supportsFilterClause: !0
959
- } : i === "bigquery" ? {
960
- ...s,
961
- labels: {
962
- database: "Project",
963
- schema: "Dataset",
964
- table: "Table"
965
- },
966
- prefixLevels: ["schema", "table"],
967
- dialect: "bigquery",
968
- supportsFilterClause: !1
969
- } : s;
970
- }
971
- const me = [
972
- "GoogleSheets",
973
- "FileUpload",
974
- "MySQL",
975
- "MSSQL",
976
- "PostgreSQL",
977
- "BigQuery",
978
- "Redshift",
979
- "Snowflake",
980
- "S3",
981
- "clickhouse",
982
- "API",
983
- "none"
984
- ];
985
- function Za(e) {
986
- if (!e) return;
987
- const t = me.filter(
988
- (i) => i !== "none" && Ge(i).dialect === e
989
- );
990
- return t.length === 1 ? t[0] : void 0;
991
- }
992
- const pi = {
993
- postgres: "PostgreSQL",
994
- sqlserver: "MSSQL"
995
- };
996
- function Ja(e) {
997
- const t = C(e);
998
- if (t)
999
- return me.find(
1000
- (i) => C(i) === t
1001
- ) ?? pi[t];
1002
- }
1003
- function Wa(e, t = {}) {
1004
- return mi(
1005
- e
1006
- ) ? Ge(e, t) : void 0;
1007
- }
1008
- function mi(e) {
1009
- const t = C(e);
1010
- if (t.includes("postgres")) return "postgres";
1011
- if (t.includes("mysql")) return "mysql";
1012
- if (t.includes("mssql") || t.includes("sqlserver"))
1013
- return "mssql";
1014
- if (t.includes("redshift")) return "redshift";
1015
- if (t.includes("snowflake")) return "snowflake";
1016
- if (t.includes("clickhouse")) return "clickhouse";
1017
- if (t === "s3" || t === "api" || t === "googlesheets" || t === "fileupload" || t === "bigquery")
1018
- return t;
1019
- }
1020
- function en(e) {
1021
- const t = C(e);
1022
- switch (t) {
1023
- case "mysql":
1024
- case "bigquery":
1025
- case "redshift":
1026
- case "snowflake":
1027
- case "clickhouse":
1028
- case "duckdb":
1029
- case "sqlite":
1030
- return t;
1031
- case "mssql":
1032
- case "sqlserver":
1033
- return "mssql";
1034
- case "postgres":
1035
- case "postgresql":
1036
- return "postgres";
1037
- default:
1038
- return "unknown";
1039
- }
1040
- }
1041
- function tn(e) {
1042
- return e.capabilities.prefixLevels.every(
1043
- (t) => !!x(e.source, t)
1044
- );
1045
- }
1046
- function an(e) {
1047
- const t = e.quoteIdentifier ?? _i;
1048
- return e.capabilities.prefixLevels.map((i) => x(e.source, i)).filter((i) => !!i).map((i) => t(i, e.capabilities.dialect)).join(".");
1049
- }
1050
- function x(e, t) {
1051
- return t === "database" ? e.databaseName : t === "schema" ? e.schemaName : e.tableName;
1052
- }
1053
- function fi(e, t, i) {
1054
- t === "database" ? e.databaseName = i : t === "schema" ? e.schemaName = i : e.tableName = i;
1055
- }
1056
- const gi = [
1057
- ['"', '"'],
1058
- ["`", "`"],
1059
- ["[", "]"]
1060
- ];
1061
- function hi(e) {
1062
- const t = e.trim();
1063
- for (const [i, s] of gi)
1064
- if (t.length >= 2 && t.startsWith(i) && t.endsWith(s))
1065
- return t.slice(1, -1).split(s + s).join(s);
1066
- return t;
1067
- }
1068
- function Qe(e) {
1069
- const t = e == null ? void 0 : e.trim();
1070
- if (!t) return [];
1071
- const i = t.split(".").map(hi);
1072
- return i.some((s) => !s) ? [] : i;
1073
- }
1074
- function nn(e) {
1075
- const t = Qe(e ?? void 0);
1076
- return t[t.length - 1] || "";
1077
- }
1078
- function _i(e, t) {
1079
- return t === "mysql" || t === "bigquery" || t === "clickhouse" || t === "duckdb" ? `\`${e.replace(/`/g, "``")}\`` : t === "mssql" ? `[${e.replace(/]/g, "]]")}]` : `"${e.replace(/"/g, '""')}"`;
1080
- }
1081
- function C(e) {
1082
- if (typeof e != "string")
1083
- return "";
1084
- const t = [];
1085
- for (const i of e.trim().toLowerCase())
1086
- yi(i) && t.push(i);
1087
- return t.join("");
1088
- }
1089
- function yi(e) {
1090
- const t = e.charCodeAt(0);
1091
- return t >= 48 && t <= 57 || t >= 97 && t <= 122;
1092
- }
1093
- function sn(e) {
1094
- return typeof e == "object" && e !== null && e.mode === "last" && e.relativeTo === "latest_data";
1095
- }
1096
- function bi(e) {
1097
- return e === "between" || e === "not between";
1098
- }
1099
- const B = a.enum(["day", "week", "month", "quarter", "year"]), vi = a.enum(["minute", "hour"]), Ke = a.number().int().positive(), Ae = a.number().int(), Xe = a.object({
1100
- mode: a.literal("last"),
1101
- n: Ke,
1102
- unit: vi,
1103
- complete: a.literal(!1).optional(),
1104
- relativeTo: a.literal("latest_data").optional()
1105
- }), Ze = a.object({
1106
- mode: a.literal("last"),
1107
- n: Ke,
1108
- unit: B,
1109
- complete: a.boolean().optional(),
1110
- relativeTo: a.literal("latest_data").optional()
1111
- }), Je = a.object({
1112
- mode: a.literal("this"),
1113
- unit: B,
1114
- toDate: a.boolean().optional(),
1115
- boundary: a.enum(["first_day", "last_day"]).optional()
1116
- }), We = a.object({ mode: a.literal("previous"), unit: B }), et = a.object({
1117
- mode: a.literal("between"),
1118
- unit: B,
1119
- from: Ae,
1120
- to: Ae
1121
- }), W = {
1122
- check: (e) => e.boundary === void 0 || e.unit === "month",
1123
- message: 'A month boundary requires unit "month".'
1124
- }, Ii = a.union([
1125
- Xe.strict(),
1126
- Ze.strict(),
1127
- Je.strict().refine(W.check, {
1128
- message: W.message,
1129
- path: ["boundary"]
1130
- }),
1131
- We.strict(),
1132
- et.strict()
1133
- ]), Si = a.union([
1134
- Xe,
1135
- Ze,
1136
- Je.refine(W.check),
1137
- We,
1138
- et
1139
- ]);
1140
- function rn(e) {
1141
- const t = Si.safeParse(e);
1142
- return t.success ? t.data : void 0;
1143
- }
1144
- const v = a.string().min(1), we = a.enum(["groupby", "metric", "sortby", "pivotby", "detail"]), tt = a.enum([
1145
- "table",
1146
- "view",
1147
- "materialized view",
1148
- "model",
1149
- "file",
1150
- "dataset",
1151
- "url",
1152
- "upload"
1153
- ]), z = a.object({
1154
- connectionId: v,
1155
- connectionType: a.enum(me),
1156
- type: tt,
1157
- name: v,
1158
- // Grounded relationship plans retain semantic identity and display metadata.
1159
- // SQL stays server-resolved; it is not accepted inside a join entity.
1160
- alias: a.string().optional(),
1161
- id: v.optional(),
1162
- domainId: v.optional(),
1163
- datasetType: a.enum(["physical", "virtual"]).optional(),
1164
- label: a.string().optional(),
1165
- description: a.string().optional(),
1166
- dbObjectType: a.string().optional(),
1167
- database: a.string().optional(),
1168
- schema: a.string().optional(),
1169
- dialect: a.enum([
1170
- "mysql",
1171
- "postgres",
1172
- "bigquery",
1173
- "redshift",
1174
- "snowflake",
1175
- "clickhouse",
1176
- "duckdb",
1177
- "mssql"
1178
- ]).optional()
1179
- }).strict(), q = a.lazy(
1180
- () => a.object({
1181
- id: v,
1182
- name: v,
1183
- label: a.string(),
1184
- /** Set when `label` was synthesized from `name`; see `Field.derivedLabel`. */
1185
- derivedLabel: a.string().optional(),
1186
- qualifiedFieldName: v,
1187
- dataType: v,
1188
- entityId: v,
1189
- entityName: v,
1190
- entityType: tt,
1191
- alias: a.string().optional(),
1192
- sourceField: a.string().optional(),
1193
- source: oe.optional(),
1194
- nativeDataType: a.string().optional(),
1195
- description: a.string().optional(),
1196
- qualifiedEntityName: a.string().optional(),
1197
- dateFormat: a.enum(di).optional(),
1198
- customFormat: a.string().optional(),
1199
- granularity: X.optional(),
1200
- role: we.optional(),
1201
- calculationRepresentation: a.enum(["inline-expression", "manual", "typed-derived"]).optional(),
1202
- calculatedFieldOrigin: a.object({ id: v, role: we.optional() }).strict().optional(),
1203
- aggregateOrigin: a.enum(["default", "explicit"]).optional(),
1204
- labelOrigin: a.enum(["semantic", "override"]).optional(),
1205
- formatOrigin: a.enum(["semantic", "override"]).optional(),
1206
- expression: a.string().optional(),
1207
- derivedField: le.optional(),
1208
- format: O.optional(),
1209
- semanticTemporalPresentation: a.object({
1210
- granularity: X,
1211
- format: wt
1212
- }).strict().optional(),
1213
- aggregate: $e.optional(),
1214
- fieldScope: a.enum(["card", "sheet", "dashboard", "domain"]).optional(),
1215
- calculatedFormula: a.object({
1216
- operation: a.enum([
1217
- "sum",
1218
- "difference",
1219
- "product",
1220
- "ratio",
1221
- "change",
1222
- "percentage",
1223
- "scale",
1224
- "custom"
1225
- ]),
1226
- inputFields: a.array(q),
1227
- constant: a.number().finite().optional(),
1228
- computeStage: a.enum(["row", "aggregate"]).optional()
1229
- }).strict().optional()
1230
- }).strict()
1231
- ), Ai = a.union([
1232
- a.string(),
1233
- a.number().finite(),
1234
- a.boolean(),
1235
- a.date(),
1236
- a.null()
1237
- ]), wi = a.object({
1238
- id: v,
1239
- field: q,
1240
- operator: a.enum([
1241
- "=",
1242
- "!=",
1243
- ">",
1244
- ">=",
1245
- "<",
1246
- "<=",
1247
- "contains",
1248
- "startsWith",
1249
- "endsWith",
1250
- "like",
1251
- "not like",
1252
- "in",
1253
- "not in",
1254
- "between",
1255
- "not between",
1256
- "isNull",
1257
- "isNotNull"
1258
- ]),
1259
- value: a.union([Ai, a.array(a.string()), a.array(a.number().finite())]),
1260
- label: a.string().optional(),
1261
- temporalBucket: xt.optional(),
1262
- rawTemporal: kt.optional(),
1263
- relativeMeta: Ii.optional(),
1264
- latestValue: a.literal(!0).optional(),
1265
- latestValuePolicy: a.literal("snapshot").optional()
1266
- }).strict().superRefine((e, t) => {
1267
- const { operator: i, value: s } = e;
1268
- if ((i === "between" || i === "not between") && (!Array.isArray(s) || s.length !== 2) && t.addIssue({
1269
- code: "custom",
1270
- path: ["value"],
1271
- message: "Between requires two endpoints."
1272
- }), e.relativeMeta && !bi(i) && t.addIssue({
1273
- code: "custom",
1274
- path: ["relativeMeta"],
1275
- message: "A relative date requires between or not between."
1276
- }), e.latestValue) {
1277
- const n = [e.field.nativeDataType, e.field.dataType].map((r) => ue(r)).some((r) => r === "date" || r === "datetime");
1278
- (i !== "=" || !n) && t.addIssue({
1279
- code: "custom",
1280
- path: ["latestValue"],
1281
- message: "Latest value requires = on a date or timestamp field."
1282
- });
1283
- }
1284
- (i === "in" || i === "not in") && !Array.isArray(s) && t.addIssue({
1285
- code: "custom",
1286
- path: ["value"],
1287
- message: "Membership requires an array."
1288
- });
1289
- }), it = a.lazy(
1290
- () => a.object({
1291
- id: v,
1292
- logicalOperator: a.enum(["AND", "OR"]),
1293
- negate: a.boolean(),
1294
- conditions: a.array(wi),
1295
- groups: a.array(it)
1296
- }).strict()
1297
- ), ki = a.object({
1298
- baseEntity: z,
1299
- joins: a.array(
1300
- a.object({
1301
- id: v,
1302
- source: z,
1303
- target: z,
1304
- joinType: a.enum(["INNER", "LEFT", "RIGHT", "FULL"]),
1305
- sequence: a.number().int().nonnegative(),
1306
- autoResolved: a.boolean().optional(),
1307
- relationshipId: a.string().optional(),
1308
- relationshipName: a.string().optional(),
1309
- relationshipCardinality: a.enum(["one_to_one", "one_to_many", "many_to_one", "many_to_many"]).optional(),
1310
- relationshipTraversalDirection: a.enum(["forward", "reverse"]).optional(),
1311
- joinKeyGroups: a.array(
1312
- a.object({
1313
- id: v,
1314
- operator: a.enum(["AND", "OR"]),
1315
- keys: a.array(
1316
- a.object({
1317
- id: a.string().optional(),
1318
- source: q,
1319
- target: q,
1320
- operator: a.enum(["=", "!=", ">", ">=", "<", "<="])
1321
- }).strict()
1322
- ).min(1)
1323
- }).strict()
1324
- ).min(1)
1325
- }).strict()
1326
- )
1327
- }).strict(), b = a.string().uuid(), xi = a.string().min(1), Fi = a.number().int().positive().max(Number.MAX_SAFE_INTEGER), Di = a.enum([
1328
- "SUM",
1329
- "COUNT",
1330
- "DISTINCT",
1331
- "AVG",
1332
- "MIN",
1333
- "MAX",
1334
- "MEDIAN"
1335
- ]), at = Qt.omit({
1336
- aggregate: !0
1337
- }), Mi = {
1338
- id: b,
1339
- field: at,
1340
- grain: X.optional()
1341
- }, ee = a.object(Mi).strict(), Ei = a.object({
1342
- id: b,
1343
- kind: a.literal("aggregate"),
1344
- field: at,
1345
- aggregate: Di
1346
- }).strict(), Ni = a.object({
1347
- id: b,
1348
- kind: a.literal("calculated"),
1349
- definition: le
1350
- }).strict(), nt = a.discriminatedUnion("kind", [Ei, Ni]), Ti = a.discriminatedUnion("kind", [
1351
- a.object({ kind: a.literal("member") }).strict(),
1352
- a.object({
1353
- kind: a.literal("measure"),
1354
- measureId: b,
1355
- oppositePath: k
1356
- }).strict()
1357
- ]), Ri = {
1358
- axis: pe,
1359
- levelId: b,
1360
- scope: a.discriminatedUnion("kind", [
1361
- a.object({ kind: a.literal("level") }).strict(),
1362
- a.object({ kind: a.literal("branch"), parent: k }).strict()
1363
- ]),
1364
- target: Ti,
1365
- direction: a.enum(["asc", "desc"]),
1366
- nulls: a.enum(["first", "last"])
1367
- }, st = a.object(Ri).strict(), Ci = a.object({
1368
- id: b,
1369
- axis: pe,
1370
- levelId: b,
1371
- direction: a.enum(["top", "bottom"]),
1372
- count: Fi,
1373
- measureId: b,
1374
- oppositePath: k,
1375
- others: a.boolean()
1376
- }).strict(), G = a.number().finite(), $i = a.object({
1377
- id: b,
1378
- axis: pe,
1379
- levelId: b,
1380
- measureId: b,
1381
- operator: a.enum(["=", "!=", ">", ">=", "<", "<=", "between", "not between"]),
1382
- value: a.union([
1383
- G,
1384
- a.tuple([G, G]).readonly()
1385
- ])
1386
- }).strict().superRefine((e, t) => {
1387
- const i = e.operator === "between" || e.operator === "not between";
1388
- i !== Array.isArray(e.value) ? h(t, ["value"], i ? "A range condition needs a low and a high bound." : "A comparison needs one number.") : i && e.value[0] > e.value[1] && h(t, ["value"], "The low bound must not exceed the high bound.");
1389
- }), rt = a.object({
1390
- source: oe,
1391
- rows: a.array(ee).min(1).readonly(),
1392
- columns: a.array(ee).readonly(),
1393
- measures: a.array(nt).min(1).readonly(),
1394
- filters: it.optional(),
1395
- joinPlan: ki.optional(),
1396
- relationshipHint: a.object({ relationshipIds: a.array(xi).optional() }).strict().optional(),
1397
- sorts: a.array(st).readonly(),
1398
- rankings: a.array(Ci).readonly(),
1399
- measureFilters: a.array($i).readonly().optional()
1400
- }).strict();
1401
- function ot(e) {
1402
- return JSON.stringify([
1403
- e.axis,
1404
- e.levelId,
1405
- e.scope.kind,
1406
- e.scope.kind === "branch" ? Ue(e.scope.parent) : null
1407
- ]);
1408
- }
1409
- function h(e, t, i) {
1410
- e.addIssue({ code: "custom", path: t, message: i });
1411
- }
1412
- function w(e, t, i) {
1413
- new Set(e).size !== e.length && h(t, i, "Duplicate identity.");
1414
- }
1415
- function L(e, t, i, s, l, n = !1) {
1416
- i.length > e[t].length && h(s, l, "Path exceeds axis depth."), i.forEach((r, d) => {
1417
- var c;
1418
- if (r.levelId !== ((c = e[t][d]) == null ? void 0 : c.id) && h(s, [...l, d], "Path must be an ordered axis prefix."), r.member.kind === "others") {
1419
- const p = r.member.rankingId;
1420
- (n || d !== i.length - 1 || !e.rankings.some(
1421
- (u) => u.id === p && u.others && u.axis === t && u.levelId === r.levelId
1422
- )) && h(
1423
- s,
1424
- [...l, d],
1425
- "Others must terminate a path at its enabled ranking and cannot be a sort/rank target."
1426
- );
1427
- }
1428
- });
1429
- }
1430
- function lt(e, t, i, s) {
1431
- w(t.map(ot), i, s), t.forEach((l, n) => {
1432
- const r = [...s, n], d = e[l.axis].findIndex((c) => c.id === l.levelId);
1433
- if (d < 0 && h(i, r, "Sort level is not on its axis."), l.scope.kind === "branch" && (L(
1434
- e,
1435
- l.axis,
1436
- l.scope.parent,
1437
- i,
1438
- [...r, "scope", "parent"],
1439
- !0
1440
- ), l.scope.parent.length !== d && h(
1441
- i,
1442
- r,
1443
- "Branch sort must name the immediate parent of its level."
1444
- )), l.target.kind === "measure") {
1445
- const c = l.target.measureId;
1446
- e.measures.some((p) => p.id === c) || h(i, r, "Unknown sort measure."), L(
1447
- e,
1448
- l.axis === "rows" ? "columns" : "rows",
1449
- l.target.oppositePath,
1450
- i,
1451
- [...r, "target", "oppositePath"],
1452
- !0
1453
- );
1454
- }
1455
- });
1456
- }
1457
- function Y(e, t, i, s) {
1458
- e && (e.kind !== t.kind || e.kind === "semantic" && t.kind === "semantic" && e.domainId !== t.domainId || e.kind === "physical" && t.kind === "physical" && e.connectionId !== t.connectionId) && h(
1459
- i,
1460
- s,
1461
- "Field source must belong to the same semantic domain or physical connection."
1462
- );
1463
- }
1464
- function Q(e, t, i) {
1465
- (e.aggregationBehavior === "snapshot" || e.aggregationBehavior === "weighted" || e.aggregationStrategy === "weighted") && h(t, i, "This measure semantic requires a later capability.");
1466
- }
1467
- function dt(e, t) {
1468
- w(
1469
- [...e.rows, ...e.columns, ...e.measures].map((n) => n.id),
1470
- t,
1471
- []
1472
- ), w(
1473
- e.rankings.map((n) => n.id),
1474
- t,
1475
- ["rankings"]
1476
- ), w(
1477
- e.rankings.map((n) => JSON.stringify([n.axis, n.levelId])),
1478
- t,
1479
- ["rankings"]
1480
- );
1481
- for (const n of ["rows", "columns"])
1482
- e[n].forEach((r, d) => {
1483
- r.grain && r.field.dataType !== void 0 && !["date", "datetime", "unknown"].includes(r.field.dataType) && h(t, [n, d, "grain"], "Grain requires a temporal field.");
1484
- });
1485
- const i = [
1486
- ...e.rows,
1487
- ...e.columns,
1488
- ...e.measures.filter((n) => n.kind === "aggregate")
1489
- ];
1490
- for (const n of i)
1491
- if (Y(n.field.source, e.source, t, [
1492
- n.id,
1493
- "field",
1494
- "source"
1495
- ]), n.field.derivedField) {
1496
- n.field.derivedField.computeStage !== "row" && h(
1497
- t,
1498
- [n.id],
1499
- "Aggregate-stage calculations cannot be grouped or wrapped in an aggregate."
1500
- ), Q(n.field.derivedField, t, [n.id]);
1501
- for (const r of Object.values(n.field.derivedField.inputs))
1502
- Y(r.field.source, e.source, t, [n.id, "inputs"]);
1503
- }
1504
- for (const n of e.measures)
1505
- if (n.kind === "calculated") {
1506
- (n.definition.computeStage !== "aggregate" || n.definition.resultRole !== "measure") && h(
1507
- t,
1508
- [n.id],
1509
- "Calculated measures require aggregate stage and measure role."
1510
- ), Q(n.definition, t, [n.id]);
1511
- for (const r of Object.values(n.definition.inputs))
1512
- Y(r.field.source, e.source, t, [
1513
- n.id,
1514
- "inputs"
1515
- ]);
1516
- }
1517
- const s = (n) => {
1518
- const r = (d, c) => {
1519
- var p, u;
1520
- if ((d.aggregate || ((p = d.derivedField) == null ? void 0 : p.computeStage) === "aggregate") && h(t, c, "Aggregate/HAVING filters are not supported."), d.derivedField) {
1521
- Q(d.derivedField, t, c);
1522
- for (const g of Object.values(d.derivedField.inputs))
1523
- Y(g.field.source, e.source, t, c);
1524
- }
1525
- for (const g of ((u = d.calculatedFormula) == null ? void 0 : u.inputFields) ?? [])
1526
- r(g, c);
1527
- };
1528
- for (const d of n.conditions)
1529
- r(d.field, ["filters", d.id]);
1530
- n.groups.forEach(s);
1531
- };
1532
- if (e.filters && s(e.filters), e.joinPlan) {
1533
- const n = [
1534
- e.joinPlan.baseEntity,
1535
- ...e.joinPlan.joins.flatMap((r) => [r.source, r.target])
1536
- ];
1537
- (new Set(n.map((r) => r.connectionId)).size > 1 || e.source.kind === "physical" && n[0].connectionId !== e.source.connectionId) && h(t, ["joinPlan"], "Joins must stay within the source connection."), w(
1538
- e.joinPlan.joins.map((r) => r.id),
1539
- t,
1540
- ["joinPlan", "joins"]
1541
- );
1542
- }
1543
- lt(e, e.sorts, t, ["sorts"]);
1544
- const l = e.measureFilters ?? [];
1545
- w(l.map((n) => n.id), t, ["measureFilters"]), w(
1546
- l.map((n) => JSON.stringify([n.axis, n.levelId])),
1547
- t,
1548
- ["measureFilters"]
1549
- ), l.forEach((n, r) => {
1550
- (!e[n.axis].some((d) => d.id === n.levelId) || !e.measures.some((d) => d.id === n.measureId)) && h(t, ["measureFilters", r], "Unknown measure filter level or measure.");
1551
- }), e.rankings.forEach((n, r) => {
1552
- (!e[n.axis].some((d) => d.id === n.levelId) || !e.measures.some((d) => d.id === n.measureId)) && h(t, ["rankings", r], "Unknown ranking level or measure."), L(
1553
- e,
1554
- n.axis === "rows" ? "columns" : "rows",
1555
- n.oppositePath,
1556
- t,
1557
- ["rankings", r, "oppositePath"],
1558
- !0
1559
- );
1560
- });
1561
- }
1562
- const j = rt.superRefine(dt), ji = rt.extend({
1563
- rows: a.array(ee).readonly(),
1564
- measures: a.array(nt).readonly()
1565
- }), Yi = ji.superRefine(dt), Oi = j.innerType().extend({ kind: a.literal("matrix") }), Pi = Oi.superRefine(({ kind: e, ...t }, i) => {
1566
- const s = j.safeParse(t);
1567
- s.success || s.error.issues.forEach((l) => i.addIssue(l));
1568
- }), qi = "{member}", ke = a.object({
1569
- visible: a.boolean(),
1570
- position: a.enum(["before", "after"]),
1571
- /** As written; a subtotal's `{member}` becomes its member's name. */
1572
- label: a.string().optional()
1573
- }).strict(), xe = a.object({
1574
- grand: ke,
1575
- levels: a.record(b, ke).readonly(),
1576
- /**
1577
- * Skip a subtotal that only repeats one row: an expanded group with
1578
- * exactly one child shows no subtotal. Off when absent.
1579
- */
1580
- skipRedundant: a.boolean().optional()
1581
- }).strict(), Li = {
1582
- layout: a.discriminatedUnion("kind", [
1583
- a.object({ kind: a.literal("compact") }).strict(),
1584
- a.object({ kind: a.literal("tabular"), repeatLabels: a.boolean() }).strict()
1585
- ]),
1586
- absence: a.object({ emptyText: a.string(), nullText: a.string() }).strict(),
1587
- levelLabels: a.record(b, a.string()).readonly(),
1588
- measureLabels: a.record(b, a.string()).readonly(),
1589
- levelFormats: a.record(b, O).readonly(),
1590
- measureFormats: a.record(b, O).readonly(),
1591
- totals: a.object({ rows: xe, columns: xe }).strict()
1592
- }, fe = a.object(Li).strict(), Bi = a.object({
1593
- depth: a.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
1594
- overrides: a.array(
1595
- a.object({ path: k, expanded: a.boolean() }).strict()
1596
- ).readonly()
1597
- }).strict(), Fe = Bi.superRefine(
1598
- (e, t) => w(
1599
- e.overrides.map((i) => Ue(i.path)),
1600
- t,
1601
- ["overrides"]
1602
- )
1603
- ), Hi = { rows: Fe, columns: Fe }, H = a.object(Hi).strict(), Vi = H.extend({ sorts: a.array(st).readonly() }).strict(), Ui = Vi.superRefine(
1604
- (e, t) => w(e.sorts.map(ot), t, ["sorts"])
1605
- );
1606
- function V(e, t) {
1607
- var c, p;
1608
- const { spec: i, presentation: s, defaults: l, session: n } = e, r = new Set([...i.rows, ...i.columns].map((u) => u.id)), d = new Set(i.measures.map((u) => u.id));
1609
- for (const u of [
1610
- "levelLabels",
1611
- "levelFormats",
1612
- "measureLabels",
1613
- "measureFormats"
1614
- ]) {
1615
- const g = u.startsWith("level") ? r : d;
1616
- for (const _ of Object.keys(s[u]))
1617
- g.has(_) || h(
1618
- t,
1619
- ["presentation", u, _],
1620
- "Unknown presentation reference."
1621
- );
1622
- }
1623
- for (const [u, g] of Object.entries(s.measureFormats))
1624
- g.type === "temporal_bucket" && h(
1625
- t,
1626
- ["presentation", "measureFormats", u],
1627
- "Measures cannot own temporal bucket formats."
1628
- );
1629
- for (const [u, g] of Object.entries(s.levelFormats))
1630
- g.type === "temporal_bucket" && !((c = [...i.rows, ...i.columns].find((_) => _.id === u)) != null && c.grain) && h(
1631
- t,
1632
- ["presentation", "levelFormats", u],
1633
- "Temporal bucket formats require a grain."
1634
- );
1635
- for (const u of ["rows", "columns"]) {
1636
- (p = s.totals[u].grand.label) != null && p.includes(
1637
- qi
1638
- ) && h(
1639
- t,
1640
- ["presentation", "totals", u, "grand", "label"],
1641
- "The grand total has no member, so its label cannot use {member}."
1642
- );
1643
- const g = Object.keys(s.totals[u].levels);
1644
- (g.length !== i[u].length || g.some((_) => !i[u].some((I) => I.id === _))) && h(
1645
- t,
1646
- ["presentation", "totals", u],
1647
- "Subtotal map must contain exactly the current axis levels."
1648
- );
1649
- for (const _ of [l, ...n ? [n] : []])
1650
- for (const I of _[u].overrides)
1651
- L(
1652
- i,
1653
- u,
1654
- I.path,
1655
- t,
1656
- [u, "overrides"],
1657
- !0
1658
- ), I.path.length || h(
1659
- t,
1660
- [u, "overrides"],
1661
- "Use depth to expand/collapse the root."
1662
- );
1663
- }
1664
- n && lt(i, n.sorts, t, ["session", "sorts"]);
1665
- }
1666
- const zi = a.object({
1667
- spec: j,
1668
- presentation: fe,
1669
- defaults: H,
1670
- session: Ui.optional()
1671
- }).strict(), on = zi.superRefine(V), Gi = a.object({
1672
- version: a.literal(1),
1673
- spec: j,
1674
- presentation: fe,
1675
- defaultView: H
1676
- }).strict(), Qi = Gi.superRefine(
1677
- (e, t) => V({ ...e, defaults: e.defaultView }, t)
1678
- ), Ki = Qi.innerType().extend({
1679
- spec: Yi
1680
- }), ln = Ki.superRefine((e, t) => V({ ...e, defaults: e.defaultView }, t)), De = a.object({ spec: j, presentation: fe }).strict(), Xi = a.union([
1681
- De.extend({
1682
- mode: a.literal("layout"),
1683
- format: a.enum(["csv", "xlsx", "pdf"]),
1684
- expansion: a.union([
1685
- H.extend({ kind: a.literal("current") }).strict(),
1686
- a.object({ kind: a.literal("all") }).strict()
1687
- ])
1688
- }).strict(),
1689
- De.extend({ mode: a.literal("flat"), format: a.enum(["csv", "xlsx"]) }).strict()
1690
- ]), dn = Xi.superRefine(
1691
- (e, t) => V(
1692
- {
1693
- ...e,
1694
- defaults: e.mode === "layout" && e.expansion.kind === "current" ? e.expansion : {
1695
- rows: { depth: 0, overrides: [] },
1696
- columns: { depth: 0, overrides: [] }
1697
- }
1698
- },
1699
- t
1700
- )
1701
- );
1702
- function un(e) {
1703
- return e && "id" in e ? e.id : void 0;
1704
- }
1705
- const Zi = "SUM";
1706
- function A(e) {
1707
- return typeof e == "string" && e.trim().length > 0;
1708
- }
1709
- function N(e) {
1710
- return A(e) ? e.trim().toLowerCase() : "";
1711
- }
1712
- function cn(e) {
1713
- const t = A(e.id) ? e.id.trim() : void 0;
1714
- if (!t) return;
1715
- const i = N(t), s = A(e.table) ? e.table.trim() : void 0;
1716
- if (!(i === N(e.name) || s && i === N(s)))
1717
- return t;
1718
- }
1719
- function F(e) {
1720
- const t = A(e.datasetId) ? e.datasetId.trim() : void 0;
1721
- if (t)
1722
- return N(t) === N(e.datasetName) ? void 0 : t;
1723
- }
1724
- function ut(e) {
1725
- if (e.kind !== "semantic") return e;
1726
- const t = F(e), { datasetId: i, ...s } = e;
1727
- return {
1728
- ...s,
1729
- ...t ? { datasetId: t } : {}
1730
- };
1731
- }
1732
- function pn(e) {
1733
- return e ? e.kind === "semantic" ? !!(A(e.domainId) && (A(e.datasetId) || A(e.datasetName))) : e.kind === "physical" ? A(e.connectionId) && A(e.tableName) : A(e.connectionId) : !1;
1734
- }
1735
- function te(e) {
1736
- if (!e)
1737
- return "";
1738
- if (e.kind === "semantic") {
1739
- const t = F(e);
1740
- return [
1741
- e.kind,
1742
- e.domainId,
1743
- t ? `datasetId:${t}` : `datasetName:${e.datasetName}`
1744
- ].join(":");
1745
- }
1746
- return e.kind === "physical" ? [
1747
- e.kind,
1748
- e.connectionId,
1749
- e.databaseName || "",
1750
- e.schemaName || "",
1751
- e.tableName
1752
- ].join(":") : [
1753
- e.kind,
1754
- e.connectionId,
1755
- e.dialect || "",
1756
- e.label || ""
1757
- ].join(":");
1758
- }
1759
- function ge(e, t) {
1760
- if (!e || !t)
1761
- return e === t;
1762
- if (e.kind !== t.kind)
1763
- return !1;
1764
- if (e.kind === "semantic" && t.kind === "semantic") {
1765
- if (e.domainId !== t.domainId)
1766
- return !1;
1767
- const i = F(e), s = F(t);
1768
- return i && s ? i === s : e.datasetName === t.datasetName;
1769
- }
1770
- return te(e) === te(t);
1771
- }
1772
- function ct(e, t) {
1773
- return e.kind !== "semantic" || t.kind !== "semantic" ? e : ut({
1774
- ...e,
1775
- datasetName: e.datasetName || t.datasetName,
1776
- datasetId: F(e) || F(t),
1777
- label: e.label || t.label,
1778
- connectionId: e.connectionId || t.connectionId
1779
- });
1780
- }
1781
- function mn(e) {
1782
- const t = [];
1783
- for (const i of e) {
1784
- const s = ut(
1785
- i
1786
- ), l = t.findIndex(
1787
- (n) => ge(n, s)
1788
- );
1789
- if (l === -1) {
1790
- t.push(s);
1791
- continue;
1792
- }
1793
- t[l] = ct(
1794
- t[l],
1795
- s
1796
- );
1797
- }
1798
- return t;
1799
- }
1800
- function Ji(e, t) {
1801
- return e.name === t.name && ge(e.source, t.source);
1802
- }
1803
- function fn(e) {
1804
- return [
1805
- e.source ? te(e.source) : "unknown",
1806
- pt(e),
1807
- e.name
1808
- ].filter(Boolean).join(":");
1809
- }
1810
- function pt(e) {
1811
- return Wi(
1812
- e.aggregate || Zi
1813
- );
1814
- }
1815
- function Wi(e) {
1816
- return e.trim().toUpperCase();
1817
- }
1818
- function gn(e, t) {
1819
- return {
1820
- ...e,
1821
- label: e.label || t.label,
1822
- role: e.role || t.role,
1823
- dataType: e.dataType || t.dataType,
1824
- source: e.source && t.source ? ct(e.source, t.source) : e.source || t.source
1825
- };
1826
- }
1827
- function ea(e) {
1828
- for (let t = 0; t < e.length; t += 1) {
1829
- const i = e[t];
1830
- if (e.some(
1831
- (s, l) => l !== t && ft(s, i)
1832
- ))
1833
- return !1;
1834
- }
1835
- return !0;
1836
- }
1837
- function mt(e, t) {
1838
- return Ji(e, t);
1839
- }
1840
- function ft(e, t) {
1841
- return mt(e, t) && $(e) === $(t);
1842
- }
1843
- function ta(e) {
1844
- return `Metric intent has duplicate measure "${e.name}" with the same aggregate (${$(e)}). Use different aggregates to request both, or remove one entry.`;
1845
- }
1846
- function Me(e) {
1847
- return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null;
1848
- }
1849
- function ia(e, t, i) {
1850
- if (e !== void 0) {
1851
- if (!e || typeof e != "object" || Array.isArray(e)) {
1852
- i.push(
1853
- o(
1854
- "invalid_sql_default_parameters",
1855
- "SQL defaultParameters must be an object keyed by parameter name.",
1856
- t
1857
- )
1858
- );
1859
- return;
1860
- }
1861
- Object.entries(e).forEach(([s, l]) => {
1862
- if (!s.trim()) {
1863
- i.push(
1864
- o(
1865
- "invalid_sql_default_parameter_name",
1866
- "SQL defaultParameters names must be non-empty strings.",
1867
- `${t}.${s}`
1868
- )
1869
- );
1870
- return;
1871
- }
1872
- (Array.isArray(l) ? l.every(Me) : Me(l)) || i.push(
1873
- o(
1874
- "invalid_sql_default_parameter_value",
1875
- "SQL defaultParameters values must be strings, numbers, booleans, nulls, or arrays of those scalar values.",
1876
- `${t}.${s}`
1877
- )
1878
- );
1879
- });
1880
- }
1881
- }
1882
- function aa(e, t) {
1883
- return he(e, t).length === 1;
1884
- }
1885
- function na(e, t) {
1886
- return he(e, t).length === 1;
1887
- }
1888
- function he(e, t) {
1889
- return t.filter(
1890
- (s) => sa(e, s)
1891
- );
1892
- }
1893
- function sa(e, t) {
1894
- return ra(e, t) ? e.source ? mt(t, e) : !0 : !1;
1895
- }
1896
- function ra(e, t) {
1897
- return !(t.name !== e.name || e.role !== void 0 && t.role !== void 0 && t.role !== e.role || oa(e, t) && $(t) !== $(e));
1898
- }
1899
- function oa(e, t) {
1900
- return e.role === "measure" || t.role === "measure" || e.aggregate !== void 0 || t.aggregate !== void 0;
1901
- }
1902
- function $(e) {
1903
- return pt(e);
1904
- }
1905
- const la = /^(\d{4})-(\d{2})-(\d{2})$/, gt = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})$/;
1906
- function ie(e) {
1907
- if (typeof e != "string")
1908
- return null;
1909
- const t = e.trim(), i = la.exec(t);
1910
- if (i) {
1911
- const [, _, I, S] = i;
1912
- return Ee(_, I, S) ? new Date(Date.UTC(Number(_), Number(I) - 1, Number(S))) : null;
1913
- }
1914
- const s = gt.exec(t);
1915
- if (!s)
1916
- return null;
1917
- const [, l, n, r, d, c, p = "00", , u] = s;
1918
- if (!Ee(l, n, r) || !T(d, 0, 23) || !T(c, 0, 59) || !T(p, 0, 59) || !da(u))
1919
- return null;
1920
- const g = new Date(t);
1921
- return Number.isFinite(g.getTime()) ? g : null;
1922
- }
1923
- function hn(e) {
1924
- return typeof e != "string" || !gt.test(e.trim()) ? null : ie(e);
1925
- }
1926
- function Ee(e, t, i) {
1927
- const s = Number(e), l = Number(t), n = Number(i);
1928
- if (!Number.isInteger(s) || !Number.isInteger(l) || !Number.isInteger(n) || l < 1 || l > 12)
1929
- return !1;
1930
- const r = new Date(Date.UTC(s, l - 1, n));
1931
- return r.getUTCFullYear() === s && r.getUTCMonth() === l - 1 && r.getUTCDate() === n;
1932
- }
1933
- function T(e, t, i) {
1934
- const s = Number(e);
1935
- return Number.isInteger(s) && s >= t && s <= i;
1936
- }
1937
- function da(e) {
1938
- if (e === "Z")
1939
- return !0;
1940
- const t = /^([+-])(\d{2}):(\d{2})$/.exec(e);
1941
- return !!(t && T(t[2], 0, 23) && T(t[3], 0, 59));
1942
- }
1943
- function Ne(e, t, i) {
1944
- if (e !== void 0) {
1945
- if (!f(e)) {
1946
- i.push(
1947
- o(
1948
- "invalid_pagination",
1949
- "Pagination must be an object with positive integer page and pageSize.",
1950
- t
1951
- )
1952
- );
1953
- return;
1954
- }
1955
- (!Number.isInteger(e.page) || typeof e.page != "number" || e.page < 1) && i.push(
1956
- o(
1957
- "invalid_pagination_page",
1958
- "Pagination page must be a positive integer.",
1959
- `${t}.page`
1960
- )
1961
- ), (!Number.isInteger(e.pageSize) || typeof e.pageSize != "number" || e.pageSize < 1) && i.push(
1962
- o(
1963
- "invalid_pagination_page_size",
1964
- "Pagination pageSize must be a positive integer.",
1965
- `${t}.pageSize`
1966
- )
1967
- );
1968
- }
1969
- }
1970
- function Te(e) {
1971
- const t = /* @__PURE__ */ new Set();
1972
- for (const i of e) {
1973
- if (t.has(i))
1974
- return i;
1975
- t.add(i);
1976
- }
1977
- return null;
1978
- }
1979
- function ua(e, t, i) {
1980
- if (!f(e)) {
1981
- i.push(
1982
- o(
1983
- "invalid_input_binding",
1984
- "Input bindings must be structured objects.",
1985
- t
1986
- )
1987
- );
1988
- return;
1989
- }
1990
- m(e.inputId) || i.push(
1991
- o(
1992
- "invalid_input_binding",
1993
- "Input bindings need a non-empty inputId.",
1994
- `${t}.inputId`
1995
- )
1996
- ), e.kind !== void 0 && e.kind !== "filter" && e.kind !== "control" && i.push(
1997
- o(
1998
- "invalid_input_binding",
1999
- "Input binding kind must be filter or control.",
2000
- `${t}.kind`
2001
- )
2002
- ), e.field !== void 0 && y(e.field, `${t}.field`, i), e.relationshipHint !== void 0 && _e(
2003
- e.relationshipHint,
2004
- `${t}.relationshipHint`,
2005
- i
2006
- );
2007
- }
2008
- function _e(e, t, i) {
2009
- if (!f(e)) {
2010
- i.push(
2011
- o(
2012
- "invalid_relationship_hint",
2013
- "Relationship hints must be structured objects.",
2014
- t
2015
- )
2016
- );
2017
- return;
2018
- }
2019
- e.relationshipIds !== void 0 && (!Array.isArray(e.relationshipIds) || e.relationshipIds.some((s) => !m(s))) && i.push(
2020
- o(
2021
- "invalid_relationship_hint",
2022
- "Relationship hint relationshipIds must be non-empty strings.",
2023
- `${t}.relationshipIds`
2024
- )
2025
- );
2026
- }
2027
- function ca(e, t) {
2028
- var s, l;
2029
- if (((s = e.source) == null ? void 0 : s.kind) !== "semantic" && ((l = e.source) == null ? void 0 : l.kind) !== "physical" && t.push(
2030
- o(
2031
- "invalid_input_options_source",
2032
- "Input options must use a semantic or physical source.",
2033
- "source"
2034
- )
2035
- ), m(e.inputId) || t.push(
2036
- o(
2037
- "missing_input_options_input_id",
2038
- "Input options intent needs the inputId it populates.",
2039
- "inputId"
2040
- )
2041
- ), e.search !== void 0 && typeof e.search != "string" && t.push(
2042
- o(
2043
- "invalid_input_options_search",
2044
- "Input options search must be a string.",
2045
- "search"
2046
- )
2047
- ), e.matchValues !== void 0) {
2048
- const n = Dt(e.matchValues);
2049
- n.ok || t.push(
2050
- o("invalid_input_options_match_values", n.error, "matchValues")
2051
- ), typeof e.search == "string" && e.search.trim() && t.push(
2052
- o(
2053
- "invalid_input_options_match_values",
2054
- "Input options matchValues cannot be combined with search.",
2055
- "matchValues"
2056
- )
2057
- );
2058
- }
2059
- if (e.limit !== void 0 && (typeof e.limit != "number" || !Number.isFinite(e.limit) || !Number.isInteger(e.limit) || e.limit <= 0) && t.push(
2060
- o(
2061
- "invalid_input_options_limit",
2062
- "Input options limit must be a positive finite number.",
2063
- "limit"
2064
- )
2065
- ), (!e.labelField || !m(e.labelField.name)) && t.push(
2066
- o(
2067
- "missing_input_options_label_field",
2068
- "Input options intent needs a labelField.",
2069
- "labelField"
2070
- )
2071
- ), y(e.labelField, "labelField", t, {
2072
- required: !0
2073
- }), (!e.valueField || !m(e.valueField.name)) && t.push(
2074
- o(
2075
- "missing_input_options_value_field",
2076
- "Input options intent needs a valueField.",
2077
- "valueField"
2078
- )
2079
- ), y(e.valueField, "valueField", t, {
2080
- required: !0
2081
- }), e.searchField !== void 0 && y(e.searchField, "searchField", t, {
2082
- required: !0
2083
- }), e.disambiguationFields !== void 0 && (Array.isArray(e.disambiguationFields) ? e.disambiguationFields.forEach((n, r) => {
2084
- y(n, `disambiguationFields.${r}`, t, {
2085
- required: !0
2086
- });
2087
- }) : t.push(
2088
- o(
2089
- "invalid_input_options_disambiguation_fields",
2090
- "Input options disambiguationFields must be an array of field refs.",
2091
- "disambiguationFields"
2092
- )
2093
- )), [
2094
- { field: e.labelField, path: "labelField" },
2095
- { field: e.valueField, path: "valueField" },
2096
- ...e.searchField ? [{ field: e.searchField, path: "searchField" }] : [],
2097
- ...Array.isArray(e.disambiguationFields) ? e.disambiguationFields.map((n, r) => ({
2098
- field: n,
2099
- path: `disambiguationFields.${r}`
2100
- })) : []
2101
- ].forEach(({ field: n, path: r }) => {
2102
- n != null && n.source && !ge(n.source, e.source) && t.push(
2103
- o(
2104
- "input_options_field_source_mismatch",
2105
- "Input option fields must belong to the declared option source.",
2106
- `${r}.source`
2107
- )
2108
- );
2109
- }), e.dependencies !== void 0) {
2110
- const n = ma(
2111
- e.dependencies
2112
- );
2113
- t.push(...n.errors), n.ok && ga(e, t);
2114
- }
2115
- if (e.population !== void 0) {
2116
- const n = e.population;
2117
- if (!f(n))
2118
- t.push(
2119
- o(
2120
- "invalid_input_options_population",
2121
- "Input options population must be a structured object.",
2122
- "population"
2123
- )
2124
- );
2125
- else {
2126
- const r = n.kind;
2127
- r !== "option_source" && r !== "related_population" && t.push(
2128
- o(
2129
- "invalid_input_options_population",
2130
- "Input options population kind must be option_source or related_population.",
2131
- "population.kind"
2132
- )
2133
- ), r === "option_source" && n.baseSource !== void 0 && t.push(
2134
- o(
2135
- "invalid_input_options_population",
2136
- "Input options population baseSource is only valid for related_population.",
2137
- "population.baseSource"
2138
- )
2139
- ), r === "option_source" && n.relationshipHint !== void 0 && t.push(
2140
- o(
2141
- "invalid_input_options_population",
2142
- "Input options population relationshipHint is only valid for related_population.",
2143
- "population.relationshipHint"
2144
- )
2145
- ), r === "related_population" && (ne(
2146
- n.baseSource,
2147
- "population.baseSource",
2148
- t
2149
- ), n.relationshipHint !== void 0 && _e(
2150
- n.relationshipHint,
2151
- "population.relationshipHint",
2152
- t
2153
- ));
2154
- }
2155
- }
2156
- }
2157
- function pa(e, t) {
2158
- if (!(!("inputs" in e) || e.inputs === void 0)) {
2159
- if (!Array.isArray(e.inputs)) {
2160
- t.push(
2161
- o(
2162
- "invalid_input_binding",
2163
- "Analytics intent inputs must be an array of input bindings.",
2164
- "inputs"
2165
- )
2166
- );
2167
- return;
2168
- }
2169
- e.inputs.forEach(
2170
- (i, s) => ua(i, `inputs.${s}`, t)
2171
- );
2172
- }
2173
- }
2174
- function ma(e, t = "protocol") {
2175
- const i = [];
2176
- if (!f(e))
2177
- return i.push(
2178
- o(
2179
- "invalid_input_options_dependencies",
2180
- "Input options dependencies must be a structured object.",
2181
- "dependencies"
2182
- )
2183
- ), { ok: !1, errors: i, warnings: [] };
2184
- const s = e, l = s.mode;
2185
- if (l !== void 0 && l !== "independent" && l !== "explicit" && l !== "all_applicable" && i.push(
2186
- o(
2187
- "invalid_input_options_dependencies",
2188
- "Input options dependencies mode must be independent, explicit, or all_applicable.",
2189
- "dependencies.mode"
2190
- )
2191
- ), K(
2192
- s.includeInputIds,
2193
- "dependencies.includeInputIds",
2194
- i,
2195
- "Input options includeInputIds must be non-empty strings."
2196
- ), K(
2197
- s.excludeInputIds,
2198
- "dependencies.excludeInputIds",
2199
- i,
2200
- "Input options excludeInputIds must be non-empty strings."
2201
- ), l === "all_applicable" && s.includeInputIds !== void 0 && i.push(
2202
- o(
2203
- "invalid_input_options_dependencies",
2204
- "All applicable dependencies cannot specify includeInputIds.",
2205
- "dependencies.includeInputIds"
2206
- )
2207
- ), K(
2208
- s.omitInputIds,
2209
- "dependencies.omitInputIds",
2210
- i,
2211
- "Input options omitInputIds must be non-empty strings."
2212
- ), Array.isArray(s.omitInputIds)) {
2213
- const n = new Set(
2214
- Array.isArray(s.includeInputIds) ? s.includeInputIds : []
2215
- );
2216
- (l !== "explicit" || new Set(s.omitInputIds).size !== s.omitInputIds.length || s.omitInputIds.some((r) => !n.has(r))) && i.push(
2217
- o(
2218
- "invalid_input_options_dependencies",
2219
- "A browse override may only omit unique ids from an explicit includeInputIds list.",
2220
- "dependencies.omitInputIds"
2221
- )
2222
- );
2223
- }
2224
- return t === "dashboard" && fa(s, i), { ok: i.length === 0, errors: i, warnings: [] };
2225
- }
2226
- function fa(e, t) {
2227
- const { mode: i, includeInputIds: s, excludeInputIds: l } = e;
2228
- i === void 0 && t.push(
2229
- o(
2230
- "invalid_input_options_dependencies",
2231
- "Dashboard option dependencies must declare a mode.",
2232
- "dependencies.mode"
2233
- )
2234
- );
2235
- for (const [n, r] of [
2236
- ["dependencies.includeInputIds", s],
2237
- ["dependencies.excludeInputIds", l]
2238
- ])
2239
- Array.isArray(r) && new Set(r).size !== r.length && t.push(
2240
- o(
2241
- "invalid_input_options_dependencies",
2242
- "Dashboard option dependency input IDs must be unique.",
2243
- n
2244
- )
2245
- );
2246
- i === "independent" && (s !== void 0 || l !== void 0) && t.push(
2247
- o(
2248
- "invalid_input_options_dependencies",
2249
- "Independent dashboard dependencies cannot specify input IDs.",
2250
- "dependencies"
2251
- )
2252
- ), i === "explicit" && (!Array.isArray(s) || s.length === 0 || l !== void 0) && t.push(
2253
- o(
2254
- "invalid_input_options_dependencies",
2255
- "Explicit dashboard dependencies require included input IDs and cannot specify exclusions.",
2256
- "dependencies"
2257
- )
2258
- );
2259
- }
2260
- function ga(e, t) {
2261
- var l, n, r;
2262
- const i = new Set(
2263
- Array.isArray(e.inputs) ? e.inputs.map((d) => f(d) ? d.inputId : void 0).filter((d) => typeof d == "string") : []
2264
- ), s = new Set(((l = e.dependencies) == null ? void 0 : l.omitInputIds) || []);
2265
- for (const d of ((n = e.dependencies) == null ? void 0 : n.includeInputIds) || [])
2266
- !i.has(d) && !s.has(d) && t.push(
2267
- o(
2268
- "invalid_input_options_dependencies",
2269
- `Input options dependency "${d}" is not declared in inputs.`,
2270
- "dependencies.includeInputIds"
2271
- )
2272
- );
2273
- for (const d of ((r = e.dependencies) == null ? void 0 : r.excludeInputIds) || [])
2274
- d !== e.inputId && !i.has(d) && t.push(
2275
- o(
2276
- "invalid_input_options_dependencies",
2277
- `Input options dependency exclusion "${d}" is not the populated inputId and is not declared in inputs.`,
2278
- "dependencies.excludeInputIds"
2279
- )
2280
- );
2281
- }
2282
- function K(e, t, i, s) {
2283
- e !== void 0 && (!Array.isArray(e) || e.some((l) => !m(l))) && i.push(o("invalid_input_options_dependencies", s, t));
2284
- }
2285
- const ha = new Set(je);
2286
- function _a(e, t) {
2287
- if (e.analysis === void 0)
2288
- return;
2289
- if (!f(e.analysis)) {
2290
- t.push(
2291
- o(
2292
- "invalid_measure_analysis",
2293
- "Metric analysis must be a structured object.",
2294
- "analysis"
2295
- )
2296
- );
2297
- return;
2298
- }
2299
- if (e.analysis.kind !== "period_change") {
2300
- t.push(
2301
- o(
2302
- "invalid_measure_analysis",
2303
- "Metric analysis kind is not supported.",
2304
- "analysis.kind"
2305
- )
2306
- );
2307
- return;
2308
- }
2309
- e.dateField || t.push(
2310
- o(
2311
- "missing_analysis_date_field",
2312
- "Period-change analysis needs a dateField.",
2313
- "dateField"
2314
- )
2315
- ), e.timeGrain || t.push(
2316
- o(
2317
- "missing_analysis_time_grain",
2318
- "Period-change analysis needs a timeGrain.",
2319
- "timeGrain"
2320
- )
2321
- ), e.analysis.orderBy !== void 0 && e.analysis.orderBy !== "absolute_change" && e.analysis.orderBy !== "positive_change" && e.analysis.orderBy !== "negative_change" && e.analysis.orderBy !== "period" && t.push(
2322
- o(
2323
- "invalid_measure_analysis",
2324
- "Period-change analysis orderBy must be absolute_change, positive_change, negative_change, or period.",
2325
- "analysis.orderBy"
2326
- )
2327
- );
2328
- const { timeWindow: i } = e.analysis;
2329
- i !== void 0 && ae(i, "analysis.timeWindow", t);
2330
- }
2331
- const ya = new Set(
2332
- Mt
2333
- ), ba = new Set(
2334
- Et
2335
- ), va = new Set(
2336
- Nt
2337
- );
2338
- function Ia(e, t, i) {
2339
- ya.has(e.unit) || i.push(
2340
- o(
2341
- "invalid_time_window",
2342
- "Calendar time window unit must be one of: day, week, month, quarter, year.",
2343
- `${t}.unit`
2344
- )
2345
- ), e.period !== "this" && e.period !== "previous" && i.push(
2346
- o(
2347
- "invalid_time_window",
2348
- "Calendar time window period must be this or previous.",
2349
- `${t}.period`
2350
- )
2351
- ), e.toDate !== void 0 && typeof e.toDate != "boolean" ? i.push(
2352
- o(
2353
- "invalid_time_window",
2354
- "Calendar time window toDate must be a boolean.",
2355
- `${t}.toDate`
2356
- )
2357
- ) : e.toDate === !0 && e.period !== "this" && i.push(
2358
- o(
2359
- "invalid_time_window",
2360
- "Calendar time window toDate is only allowed with period this.",
2361
- `${t}.toDate`
2362
- )
2363
- );
2364
- }
2365
- function ae(e, t, i) {
2366
- if (!f(e)) {
2367
- i.push(
2368
- o(
2369
- "invalid_time_window",
2370
- "Time window must be a structured object.",
2371
- t
2372
- )
2373
- );
2374
- return;
2375
- }
2376
- if (e.kind !== void 0 && e.kind !== "relative" && e.kind !== "calendar" && e.kind !== "absolute" && i.push(
2377
- o(
2378
- "invalid_time_window",
2379
- "Time window kind must be relative, calendar or absolute.",
2380
- `${t}.kind`
2381
- )
2382
- ), e.kind === "calendar") {
2383
- Ia(e, t, i);
2384
- return;
2385
- }
2386
- if (e.kind === "absolute") {
2387
- if (m(e.start) || i.push(
2388
- o(
2389
- "invalid_time_window",
2390
- "Absolute time window start must be a non-empty ISO date or timestamp string.",
2391
- `${t}.start`
2392
- )
2393
- ), m(e.end) || i.push(
2394
- o(
2395
- "invalid_time_window",
2396
- "Absolute time window end must be a non-empty ISO date or timestamp string.",
2397
- `${t}.end`
2398
- )
2399
- ), m(e.start) && m(e.end)) {
2400
- const s = ie(e.start), l = ie(e.end);
2401
- s || i.push(
2402
- o(
2403
- "invalid_time_window",
2404
- "Absolute time window start must be a valid ISO date or timestamp.",
2405
- `${t}.start`
2406
- )
2407
- ), l || i.push(
2408
- o(
2409
- "invalid_time_window",
2410
- "Absolute time window end must be a valid ISO date or timestamp.",
2411
- `${t}.end`
2412
- )
2413
- ), s && l && s.getTime() > l.getTime() && i.push(
2414
- o(
2415
- "invalid_time_window",
2416
- "Absolute time window start must be before or equal to end.",
2417
- t
2418
- )
2419
- );
2420
- }
2421
- return;
2422
- }
2423
- (typeof e.unit != "string" || !ha.has(e.unit)) && i.push(
2424
- o(
2425
- "invalid_time_window",
2426
- `Time window unit must be one of: ${je.join(", ")}.`,
2427
- `${t}.unit`
2428
- )
2429
- ), (typeof e.value != "number" || !Number.isFinite(e.value) || e.value <= 0) && i.push(
2430
- o(
2431
- "invalid_time_window",
2432
- "Time window value must be a positive number.",
2433
- `${t}.value`
2434
- )
2435
- ), e.anchor !== void 0 && !ba.has(e.anchor) && i.push(
2436
- o(
2437
- "invalid_time_window",
2438
- "Time window anchor must be now or latest_available.",
2439
- `${t}.anchor`
2440
- )
2441
- ), e.completeness !== void 0 && !va.has(e.completeness) && i.push(
2442
- o(
2443
- "invalid_time_window",
2444
- "Time window completeness must be include_partial or complete_periods.",
2445
- `${t}.completeness`
2446
- )
2447
- );
2448
- }
2449
- function Re(e, t, i) {
2450
- if (e !== void 0) {
2451
- if (!Array.isArray(e)) {
2452
- i.push(
2453
- o(
2454
- "invalid_analytics_filters",
2455
- "Analytics filters must be an array.",
2456
- t
2457
- )
2458
- );
2459
- return;
2460
- }
2461
- e.forEach((s, l) => {
2462
- var c;
2463
- const n = `${t}.${l}`;
2464
- if (!f(s)) {
2465
- i.push(
2466
- o(
2467
- "invalid_analytics_filter",
2468
- "Analytics filter must be a structured object.",
2469
- n
2470
- )
2471
- );
2472
- return;
2473
- }
2474
- const r = s;
2475
- y(r.field, `${n}.field`, i, {
2476
- required: !0
2477
- }), r.scope !== void 0 && r.scope !== "row" && r.scope !== "aggregate" && i.push(
2478
- o(
2479
- "invalid_analytics_filter_scope",
2480
- "Analytics filter scope must be row or aggregate.",
2481
- `${n}.scope`
2482
- )
2483
- ), r.scope === "aggregate" && ((c = r.field) == null ? void 0 : c.role) !== void 0 && r.field.role !== "measure" && i.push(
2484
- o(
2485
- "invalid_analytics_filter_scope",
2486
- "Aggregate-scope analytics filters must target a measure field.",
2487
- `${n}.scope`
2488
- )
2489
- );
2490
- const d = r.operator === "is_null" || r.operator === "is_not_null";
2491
- if (r.operator !== void 0 && r.operator !== "=" && r.operator !== "!=" && r.operator !== "in" && r.operator !== "not_in" && r.operator !== "contains" && r.operator !== "not_contains" && r.operator !== "between" && r.operator !== "not_between" && r.operator !== ">" && r.operator !== ">=" && r.operator !== "<" && r.operator !== "<=" && r.operator !== "is_null" && r.operator !== "is_not_null" && i.push(
2492
- o(
2493
- "invalid_analytics_filter_operator",
2494
- "Analytics filter operator is not supported.",
2495
- `${n}.operator`
2496
- )
2497
- ), r.values === void 0 && !d && i.push(
2498
- o(
2499
- "missing_analytics_filter_value",
2500
- "Analytics filter needs values unless it is a null check.",
2501
- n
2502
- )
2503
- ), d && r.values !== void 0) {
2504
- i.push(
2505
- o(
2506
- "invalid_analytics_filter_values",
2507
- "Null-check analytics filters must not include values.",
2508
- `${n}.values`
2509
- )
2510
- );
2511
- return;
2512
- }
2513
- if (r.values !== void 0 && !Array.isArray(r.values)) {
2514
- i.push(
2515
- o(
2516
- "invalid_analytics_filter_values",
2517
- "Analytics filter values must be an array when provided.",
2518
- `${n}.values`
2519
- )
2520
- );
2521
- return;
2522
- }
2523
- if (r.values !== void 0) {
2524
- const p = r.values.length;
2525
- if (r.operator === "between" || r.operator === "not_between") {
2526
- p !== 2 && i.push(
2527
- o(
2528
- "invalid_analytics_filter_values",
2529
- "Between analytics filters must include exactly two values.",
2530
- `${n}.values`
2531
- )
2532
- );
2533
- return;
2534
- }
2535
- (r.operator === "contains" || r.operator === "not_contains" || r.operator === "=" || r.operator === "!=" || r.operator === ">" || r.operator === ">=" || r.operator === "<" || r.operator === "<=" || r.operator === void 0) && p !== 1 && i.push(
2536
- o(
2537
- "invalid_analytics_filter_values",
2538
- "Scalar analytics filters must include exactly one value. Use in/not_in for multiple values.",
2539
- `${n}.values`
2540
- )
2541
- );
2542
- }
2543
- });
2544
- }
2545
- }
2546
- function ht(e) {
2547
- var s;
2548
- const t = [], i = [];
2549
- if (!e || typeof e != "object")
2550
- return {
2551
- ok: !1,
2552
- errors: [
2553
- o(
2554
- "invalid_analytics_intent",
2555
- "Analytics intent must be a structured object."
2556
- )
2557
- ],
2558
- warnings: i,
2559
- repairHints: [
2560
- {
2561
- code: "invalid_analytics_intent",
2562
- recommendedNextStep: "Send one structured analytics intent object with kind, source, and required fields."
2563
- }
2564
- ]
2565
- };
2566
- if (e.kind === "matrix") {
2567
- const l = Pi.safeParse(e);
2568
- return l.success || t.push(...l.error.issues.map((n) => o("invalid_matrix_intent", n.message, n.path.join(".")))), { ok: t.length === 0, errors: t, warnings: i, repairHints: Ce(t) };
2569
- }
2570
- if (e.version !== void 0 && e.version !== 1 && t.push(
2571
- o(
2572
- "invalid_version",
2573
- "Analytics intent version must be 1.",
2574
- "version"
2575
- )
2576
- ), ne(e.source, "source", t), Sa(e, t), pa(e, t), "relationshipHint" in e && e.relationshipHint !== void 0 && _e(
2577
- e.relationshipHint,
2578
- "relationshipHint",
2579
- t
2580
- ), e.kind === "metric") {
2581
- const l = Array.isArray(e.measures) ? e.measures.filter(
2582
- (n) => f(n) && m(n.name)
2583
- ) : [];
2584
- if (!Array.isArray(e.measures) || e.measures.length === 0 ? t.push(
2585
- o(
2586
- "missing_measure",
2587
- "Metric intent needs at least one measure.",
2588
- "measures"
2589
- )
2590
- ) : e.measures.some(
2591
- (n) => !f(n) || !m(n.name)
2592
- ) && t.push(
2593
- o(
2594
- "invalid_measure_list",
2595
- "Metric intent measures must be an array of field references with names.",
2596
- "measures"
2597
- )
2598
- ), l.forEach((n, r) => {
2599
- y(n, `measures.${r}`, t, {
2600
- required: !0
2601
- });
2602
- }), l.length > 0 && !ea(l)) {
2603
- const n = l.find(
2604
- (r, d) => l.some(
2605
- (c, p) => p !== d && ft(c, r)
2606
- )
2607
- );
2608
- n && t.push(
2609
- o(
2610
- "duplicate_measure",
2611
- ta(n),
2612
- "measures"
2613
- )
2614
- );
2615
- }
2616
- if (f(e.primaryMeasure) && m(e.primaryMeasure.name) && he(
2617
- e.primaryMeasure,
2618
- l
2619
- ).length > 1 && t.push(
2620
- o(
2621
- "ambiguous_primary_measure",
2622
- "Metric intent primaryMeasure must identify exactly one selected measure.",
2623
- "primaryMeasure"
2624
- )
2625
- ), e.primaryMeasure !== void 0 && (y(e.primaryMeasure, "primaryMeasure", t, {
2626
- required: !0
2627
- }), f(e.primaryMeasure) && m(e.primaryMeasure.name) && l.length > 0 && !aa(
2628
- e.primaryMeasure,
2629
- l
2630
- ) && t.push(
2631
- o(
2632
- "invalid_primary_measure",
2633
- "Metric intent primaryMeasure must match one measure field reference.",
2634
- "primaryMeasure"
2635
- )
2636
- )), e.dimensions !== void 0 && !Array.isArray(e.dimensions) ? t.push(
2637
- o(
2638
- "invalid_measure_dimensions",
2639
- "Metric intent dimensions must be an array of field references.",
2640
- "dimensions"
2641
- )
2642
- ) : Array.isArray(e.dimensions) && e.dimensions.some(
2643
- (n) => !f(n) || !m(n.name)
2644
- ) && t.push(
2645
- o(
2646
- "invalid_measure_dimensions",
2647
- "Metric intent dimensions must be an array of field references with names.",
2648
- "dimensions"
2649
- )
2650
- ), e.dateField !== void 0 && y(e.dateField, "dateField", t), e.timeWindow !== void 0 && (ae(e.timeWindow, "timeWindow", t), e.dateField || t.push(
2651
- o(
2652
- "missing_time_window_date_field",
2653
- "Metric timeWindow needs a dateField.",
2654
- "dateField"
2655
- )
2656
- )), Re(e.filters, "filters", t), Array.isArray(e.dimensions) && e.dimensions.forEach((n, r) => {
2657
- y(n, `dimensions.${r}`, t);
2658
- }), e.orderBy !== void 0) {
2659
- if (!f(e.orderBy))
2660
- t.push(
2661
- o(
2662
- "invalid_measure_order_by",
2663
- "Metric intent orderBy must be a structured object.",
2664
- "orderBy"
2665
- )
2666
- );
2667
- else if (y(e.orderBy.field, "orderBy.field", t, {
2668
- required: !0
2669
- }), e.orderBy.direction !== "asc" && e.orderBy.direction !== "desc" && t.push(
2670
- o(
2671
- "invalid_measure_order_direction",
2672
- "Metric intent orderBy direction must be asc or desc.",
2673
- "orderBy.direction"
2674
- )
2675
- ), f(e.orderBy.field) && m(e.orderBy.field.name)) {
2676
- const n = [
2677
- ...l,
2678
- ...e.timeGrain && e.dateField && f(e.dateField) ? [e.dateField] : [],
2679
- ...Array.isArray(e.dimensions) ? e.dimensions.filter(
2680
- (r) => f(r) && m(r.name)
2681
- ) : []
2682
- ];
2683
- n.length > 0 && !na(
2684
- e.orderBy.field,
2685
- n
2686
- ) && t.push(
2687
- o(
2688
- "invalid_measure_order_by",
2689
- "Metric intent orderBy.field must match one selected measure, grouped dateField, or dimension.",
2690
- "orderBy.field"
2691
- )
2692
- );
2693
- }
2694
- }
2695
- _a(e, t);
2696
- } else if (e.kind === "records") {
2697
- if (!Array.isArray(e.fields) || e.fields.length === 0 ? t.push(
2698
- o(
2699
- "missing_record_fields",
2700
- "Records intent needs at least one field.",
2701
- "fields"
2702
- )
2703
- ) : e.fields.some(
2704
- (l) => !f(l) || !m(l.name)
2705
- ) && t.push(
2706
- o(
2707
- "invalid_record_fields",
2708
- "Records intent fields must be field references with names.",
2709
- "fields"
2710
- )
2711
- ), Array.isArray(e.fields) && e.fields.forEach((l, n) => {
2712
- y(l, `fields.${n}`, t);
2713
- }), e.dateField !== void 0 && y(e.dateField, "dateField", t), Ne(e.pagination, "pagination", t), e.timeWindow !== void 0 && (ae(e.timeWindow, "timeWindow", t), e.dateField || t.push(
2714
- o(
2715
- "missing_time_window_date_field",
2716
- "Records timeWindow needs a dateField.",
2717
- "dateField"
2718
- )
2719
- )), Re(e.filters, "filters", t), Array.isArray(e.filters) && e.filters.forEach((l, n) => {
2720
- f(l) && l.scope === "aggregate" && t.push(
2721
- o(
2722
- "unsupported_record_filter_scope",
2723
- "Records intents support row-scope filters only. Use a metric intent for aggregate-scope filters.",
2724
- `filters.${n}.scope`
2725
- )
2726
- );
2727
- }), e.orderBy !== void 0 && (f(e.orderBy) ? (y(e.orderBy.field, "orderBy.field", t, {
2728
- required: !0
2729
- }), e.orderBy.direction !== "asc" && e.orderBy.direction !== "desc" && t.push(
2730
- o(
2731
- "invalid_record_order_direction",
2732
- "Records intent orderBy direction must be asc or desc.",
2733
- "orderBy.direction"
2734
- )
2735
- )) : t.push(
2736
- o(
2737
- "invalid_record_order_by",
2738
- "Records intent orderBy must be a structured object.",
2739
- "orderBy"
2740
- )
2741
- )), e.totals !== void 0)
2742
- if (!f(e.totals))
2743
- t.push(
2744
- o(
2745
- "invalid_records_totals",
2746
- "Records totals must be a structured server totals request.",
2747
- "totals"
2748
- )
2749
- );
2750
- else {
2751
- e.totals.mode !== "server" && t.push(
2752
- o(
2753
- "invalid_records_totals",
2754
- "Records totals mode must be server.",
2755
- "totals.mode"
2756
- )
2757
- );
2758
- const l = e.totals.measures;
2759
- !Array.isArray(l) || l.length === 0 ? t.push(
2760
- o(
2761
- "missing_records_totals_measures",
2762
- "Records server totals need at least one measure.",
2763
- "totals.measures"
2764
- )
2765
- ) : l.forEach((n, r) => {
2766
- y(n, `totals.measures.${r}`, t, {
2767
- required: !0
2768
- }), (!f(n) || n.role !== "measure") && t.push(
2769
- o(
2770
- "invalid_records_totals_measure",
2771
- "Records server totals measures must be measure field references.",
2772
- `totals.measures.${r}.role`
2773
- )
2774
- );
2775
- });
2776
- }
2777
- } else e.kind === "inputOptions" ? ca(e, t) : e.kind === "sql" ? (((s = e.source) == null ? void 0 : s.kind) !== "sql" && t.push(
2778
- o(
2779
- "invalid_sql_source",
2780
- "SQL analytics intent must use a SQL execution source.",
2781
- "source"
2782
- )
2783
- ), m(e.sql) || t.push(
2784
- o("missing_sql", "SQL analytics intent needs SQL text.", "sql")
2785
- ), ia(
2786
- e.defaultParameters,
2787
- "defaultParameters",
2788
- t
2789
- ), Array.isArray(e.fields) && e.fields.forEach((l, n) => {
2790
- y(l, `fields.${n}`, t);
2791
- }), Ne(e.pagination, "pagination", t)) : t.push(
2792
- o(
2793
- "invalid_analytics_kind",
2794
- "Analytics kind is not supported.",
2795
- "kind"
2796
- )
2797
- );
2798
- return {
2799
- ok: t.length === 0,
2800
- errors: t,
2801
- warnings: i,
2802
- repairHints: Ce(t)
2803
- };
2804
- }
2805
- function Sa(e, t) {
2806
- if (!(!("derivedFields" in e) || e.derivedFields === void 0)) {
2807
- if (!Array.isArray(e.derivedFields)) {
2808
- t.push(
2809
- o(
2810
- "invalid_derived_fields",
2811
- "Analytics intent derivedFields must be an array of derived field definitions.",
2812
- "derivedFields"
2813
- )
2814
- );
2815
- return;
2816
- }
2817
- e.derivedFields.forEach((i, s) => {
2818
- re(
2819
- i
2820
- ).errors.forEach((n) => {
2821
- t.push({
2822
- ...n,
2823
- path: n.path ? `derivedFields.${s}.${n.path}` : `derivedFields.${s}`
2824
- });
2825
- });
2826
- });
2827
- }
2828
- }
2829
- function Aa(e) {
2830
- const t = [], i = [];
2831
- if (!e || typeof e != "object")
2832
- return {
2833
- ok: !1,
2834
- errors: [
2835
- o(
2836
- "invalid_operation_intent",
2837
- "Operation intent must be a structured object."
2838
- )
2839
- ],
2840
- warnings: i,
2841
- repairHints: [
2842
- {
2843
- code: "invalid_operation_intent",
2844
- recommendedNextStep: "Send one typed operation intent with version, kind, and required operation fields."
2845
- }
2846
- ]
2847
- };
2848
- if (e.version !== 1 && t.push(
2849
- o(
2850
- "invalid_version",
2851
- "Operation intent version must be 1.",
2852
- "version"
2853
- )
2854
- ), e.kind === "answer_obligations")
2855
- !Array.isArray(e.obligations) || e.obligations.length === 0 ? t.push(
2856
- o(
2857
- "missing_obligations",
2858
- "Answer-obligations operation intent needs at least one obligation.",
2859
- "obligations"
2860
- )
2861
- ) : e.obligations.forEach((s, l) => {
2862
- m(s.id) || t.push(
2863
- o(
2864
- "missing_obligation_id",
2865
- "Each analytics obligation needs an id.",
2866
- `obligations.${l}.id`
2867
- )
2868
- ), m(s.prompt) || t.push(
2869
- o(
2870
- "missing_obligation_prompt",
2871
- "Each analytics obligation needs a prompt.",
2872
- `obligations.${l}.prompt`
2873
- )
2874
- );
2875
- });
2876
- else if (e.kind === "dashboard_change") {
2877
- if (m(e.instruction) || t.push(
2878
- o(
2879
- "missing_instruction",
2880
- "Change operation intent needs an instruction.",
2881
- "instruction"
2882
- )
2883
- ), e.analyticsIntent) {
2884
- const s = ht(
2885
- e.analyticsIntent
2886
- );
2887
- t.push(...s.errors), i.push(...s.warnings);
2888
- }
2889
- } else
2890
- t.push(
2891
- o(
2892
- "invalid_operation_kind",
2893
- "Operation intent kind is not supported.",
2894
- "kind"
2895
- )
2896
- );
2897
- return {
2898
- ok: t.length === 0,
2899
- errors: t,
2900
- warnings: i,
2901
- repairHints: _t(t)
2902
- };
2903
- }
2904
- function _n(e) {
2905
- const t = [], i = [];
2906
- if (!e || typeof e != "object")
2907
- return {
2908
- ok: !1,
2909
- errors: [
2910
- o(
2911
- "invalid_recovery_plan",
2912
- "Analytics recovery plan must be a structured object."
2913
- )
2914
- ],
2915
- warnings: i,
2916
- repairHints: [
2917
- {
2918
- code: "invalid_recovery_plan",
2919
- recommendedNextStep: "Return a typed recovery plan with operationIntent and plannedToolCalls."
2920
- }
2921
- ]
2922
- };
2923
- e.version !== 1 && t.push(
2924
- o("invalid_version", "Recovery plan version must be 1.", "version")
2925
- ), e.kind !== "analytics_recovery_plan" && t.push(
2926
- o(
2927
- "invalid_recovery_plan_kind",
2928
- "Recovery plan kind must be analytics_recovery_plan.",
2929
- "kind"
2930
- )
2931
- );
2932
- const s = Aa(
2933
- e.operationIntent
2934
- );
2935
- return t.push(...s.errors), i.push(...s.warnings), Array.isArray(e.plannedToolCalls) || t.push(
2936
- o(
2937
- "invalid_planned_tool_calls",
2938
- "Recovery plan plannedToolCalls must be an array.",
2939
- "plannedToolCalls"
2940
- )
2941
- ), {
2942
- ok: t.length === 0,
2943
- errors: t,
2944
- warnings: i,
2945
- repairHints: _t(t)
2946
- };
2947
- }
2948
- function _t(e) {
2949
- return e.map((t) => ({
2950
- code: t.code,
2951
- recommendedNextStep: t.code === "missing_obligations" ? "Normalize the user request into one or more typed analytics obligations before recovery planning." : "Correct the operation/recovery contract shape before planning execution."
2952
- }));
2953
- }
2954
- function Ce(e) {
2955
- return e.map((t) => {
2956
- switch (t.code) {
2957
- case "invalid_matrix_intent":
2958
- return {
2959
- code: t.code,
2960
- recommendedNextStep: `Correct MatrixSpec at ${t.path || "the definition"}: ${t.message} Keep presentation and matrixWindowRequest outside the intent.`
2961
- };
2962
- case "missing_source":
2963
- return {
2964
- code: t.code,
2965
- fieldRole: "source",
2966
- recommendedNextStep: "Provide a semantic, physical, or SQL source before executing analytics."
2967
- };
2968
- case "missing_measure":
2969
- return {
2970
- code: t.code,
2971
- fieldRole: "measure",
2972
- recommendedNextStep: "Choose one exact measure from the grounded schema candidates."
2973
- };
2974
- case "missing_record_fields":
2975
- return {
2976
- code: t.code,
2977
- fieldRole: "dimension",
2978
- recommendedNextStep: "Provide at least one field for the records intent."
2979
- };
2980
- case "missing_matrix_rows":
2981
- return {
2982
- code: t.code,
2983
- fieldRole: "dimension",
2984
- recommendedNextStep: "Choose at least one row axis level for the matrix table."
2985
- };
2986
- case "missing_matrix_values":
2987
- return {
2988
- code: t.code,
2989
- fieldRole: "measure",
2990
- recommendedNextStep: "Choose at least one value field for the matrix table."
2991
- };
2992
- case "unsupported_matrix_sql_source":
2993
- return {
2994
- code: t.code,
2995
- fieldRole: "source",
2996
- recommendedNextStep: "Use a semantic or explorer-backed source for matrix tables; raw SQL matrix tables are not supported."
2997
- };
2998
- case "missing_input_options_input_id":
2999
- return {
3000
- code: t.code,
3001
- fieldRole: "input",
3002
- recommendedNextStep: "Provide the inputId that these option values populate."
3003
- };
3004
- case "missing_input_options_label_field":
3005
- return {
3006
- code: t.code,
3007
- fieldRole: "dimension",
3008
- recommendedNextStep: "Provide the human-readable field used as option labels."
3009
- };
3010
- case "missing_input_options_value_field":
3011
- return {
3012
- code: t.code,
3013
- fieldRole: "dimension",
3014
- recommendedNextStep: "Provide the stable field used as option values."
3015
- };
3016
- case "missing_sql":
3017
- return {
3018
- code: t.code,
3019
- fieldRole: "sql",
3020
- recommendedNextStep: "Provide bounded read-only SQL with an explicit outer LIMIT."
3021
- };
3022
- case "conflicting_sql":
3023
- return {
3024
- code: t.code,
3025
- fieldRole: "sql",
3026
- recommendedNextStep: "Use one canonical SQL text location for the intent; prefer top-level sql."
3027
- };
3028
- case "missing_semantic_domain":
3029
- case "missing_dataset_name":
3030
- case "missing_connection_id":
3031
- case "missing_table_name":
3032
- return {
3033
- code: t.code,
3034
- fieldRole: "source",
3035
- recommendedNextStep: "Use grounded catalog metadata to fill the missing source reference."
3036
- };
3037
- default:
3038
- return;
3039
- }
3040
- }).filter((t) => !!t);
3041
- }
3042
- function wa(e, t, i, s) {
3043
- if (!e || typeof e != "object") {
3044
- i.push(
3045
- o("invalid_view", "Dashboard view must be an object.", t)
3046
- );
3047
- return;
3048
- }
3049
- if (m(e.title) || i.push(
3050
- o("missing_view_title", "Dashboard view needs a title.", t)
3051
- ), !e.presentation || typeof e.presentation != "object") {
3052
- i.push(
3053
- o(
3054
- "missing_presentation",
3055
- "Dashboard view needs a presentation.",
3056
- `${t}.presentation`
3057
- )
3058
- );
3059
- return;
3060
- }
3061
- if (e.presentation.kind === "text") {
3062
- m(e.text) || s.push(
3063
- o(
3064
- "missing_text_content",
3065
- "Text views should include text content.",
3066
- `${t}.text`
3067
- )
3068
- );
3069
- return;
3070
- }
3071
- if (!e.analytics) {
3072
- i.push(
3073
- o(
3074
- "missing_view_analytics",
3075
- "Non-text dashboard views need analytics intent.",
3076
- `${t}.analytics`
3077
- )
3078
- );
3079
- return;
3080
- }
3081
- e.presentation.kind === "matrixTable" && e.analytics.kind !== "matrix" && i.push(
3082
- o(
3083
- "invalid_matrix_view_analytics",
3084
- "Matrix table views need matrix analytics intent.",
3085
- `${t}.analytics.kind`
3086
- )
3087
- );
3088
- const l = ht(e.analytics);
3089
- for (const n of l.errors)
3090
- i.push(
3091
- o(
3092
- n.code,
3093
- n.message,
3094
- `${t}.analytics${n.path ? `.${n.path}` : ""}`
3095
- )
3096
- );
3097
- for (const n of l.warnings)
3098
- s.push(
3099
- o(
3100
- n.code,
3101
- n.message,
3102
- `${t}.analytics${n.path ? `.${n.path}` : ""}`
3103
- )
3104
- );
3105
- }
3106
- function yn(e) {
3107
- const t = [], i = [];
3108
- if (!e || typeof e != "object")
3109
- return {
3110
- ok: !1,
3111
- errors: [
3112
- o(
3113
- "invalid_dashboard_intent",
3114
- "Dashboard intent must be a structured object."
3115
- )
3116
- ],
3117
- warnings: i
3118
- };
3119
- e.version !== 1 && t.push(
3120
- o("invalid_version", "Dashboard intent version must be 1.")
3121
- ), e.kind !== "dashboard" && t.push(
3122
- o("invalid_kind", "Experience intent kind must be dashboard.")
3123
- ), m(e.title) || t.push(
3124
- o("missing_title", "Dashboard intent needs a title.", "title")
3125
- );
3126
- const s = Array.isArray(e.inputs) ? e.inputs : [], l = Te(
3127
- s.filter(f).map((c) => c.id).filter((c) => typeof c == "string")
3128
- );
3129
- l && t.push(
3130
- o(
3131
- "duplicate_input_id",
3132
- `Duplicate input id: ${l}.`,
3133
- "inputs"
3134
- )
3135
- );
3136
- for (const [c, p] of s.entries()) {
3137
- const u = `inputs.${c}`;
3138
- if (!f(p)) {
3139
- t.push(
3140
- o("invalid_input", "Dashboard input must be an object.", u)
3141
- );
3142
- continue;
3143
- }
3144
- m(p.id) || t.push(
3145
- o("missing_input_id", "Input needs an id.", `${u}.id`)
3146
- ), m(p.label) || t.push(
3147
- o("missing_input_label", "Input needs a label.", `${u}.label`)
3148
- ), !p.field || !m(p.field.name) ? t.push(
3149
- o("missing_input_field", "Input needs a field.", `${u}.field`)
3150
- ) : y(p.field, `${u}.field`, t);
3151
- }
3152
- const n = Array.isArray(e.sections) ? e.sections : [];
3153
- n.length === 0 && t.push(
3154
- o(
3155
- "missing_sections",
3156
- "Dashboard intent needs at least one section.",
3157
- "sections"
3158
- )
3159
- );
3160
- const r = n.flatMap(
3161
- (c) => c && typeof c == "object" && Array.isArray(c.views) ? c.views.filter(f).map((p) => p.id).filter((p) => !!p) : []
3162
- ), d = Te(r);
3163
- d && t.push(
3164
- o(
3165
- "duplicate_view_id",
3166
- `Duplicate dashboard view id: ${d}.`,
3167
- "sections"
3168
- )
3169
- );
3170
- for (const [c, p] of n.entries()) {
3171
- const u = `sections.${c}`;
3172
- if (!p || typeof p != "object") {
3173
- t.push(
3174
- o(
3175
- "invalid_section",
3176
- "Dashboard section must be an object.",
3177
- u
3178
- )
3179
- );
3180
- continue;
3181
- }
3182
- if (m(p.title) || t.push(
3183
- o(
3184
- "missing_section_title",
3185
- "Dashboard section needs a title.",
3186
- u
3187
- )
3188
- ), !Array.isArray(p.views) || p.views.length === 0) {
3189
- t.push(
3190
- o(
3191
- "missing_section_views",
3192
- "Dashboard section needs at least one view.",
3193
- `${u}.views`
3194
- )
3195
- );
3196
- continue;
3197
- }
3198
- for (const [g, _] of p.views.entries())
3199
- wa(
3200
- _,
3201
- `${u}.views.${g}`,
3202
- t,
3203
- i
3204
- );
3205
- }
3206
- return { ok: t.length === 0, errors: t, warnings: i };
3207
- }
3208
- export {
3209
- $i as $,
3210
- mi as A,
3211
- Qa as B,
3212
- Z as C,
3213
- di as D,
3214
- cn as E,
3215
- Xa as F,
3216
- de as G,
3217
- ue as H,
3218
- ge as I,
3219
- ht as J,
3220
- un as K,
3221
- oi as L,
3222
- pn as M,
3223
- te as N,
3224
- it as O,
3225
- Pa as P,
3226
- pe as Q,
3227
- Di as R,
3228
- at as S,
3229
- ee as T,
3230
- nt as U,
3231
- ri as V,
3232
- k as W,
3233
- qa as X,
3234
- Ti as Y,
3235
- st as Z,
3236
- Ci as _,
3237
- pt as a,
3238
- $a as a$,
3239
- ot as a0,
3240
- j as a1,
3241
- ke as a2,
3242
- qi as a3,
3243
- fe as a4,
3244
- Fe as a5,
3245
- H as a6,
3246
- Ui as a7,
3247
- on as a8,
3248
- dn as a9,
3249
- F as aA,
3250
- ut as aB,
3251
- ct as aC,
3252
- fn as aD,
3253
- bi as aE,
3254
- Ii as aF,
3255
- Mt as aG,
3256
- Fa as aH,
3257
- Et as aI,
3258
- Nt as aJ,
3259
- Da as aK,
3260
- Tt as aL,
3261
- M as aM,
3262
- Rt as aN,
3263
- Ma as aO,
3264
- $t as aP,
3265
- Ea as aQ,
3266
- jt as aR,
3267
- Ve as aS,
3268
- ni as aT,
3269
- si as aU,
3270
- Ya as aV,
3271
- Oa as aW,
3272
- R as aX,
3273
- Ra as aY,
3274
- L as aZ,
3275
- ja as a_,
3276
- oe as aa,
3277
- Ft as ab,
3278
- Dt as ac,
3279
- ie as ad,
3280
- ma as ae,
3281
- Aa as af,
3282
- _n as ag,
3283
- yn as ah,
3284
- re as ai,
3285
- Kt as aj,
3286
- Xt as ak,
3287
- ti as al,
3288
- ii as am,
3289
- qe as an,
3290
- Le as ao,
3291
- Ie as ap,
3292
- He as aq,
3293
- Na as ar,
3294
- Ta as as,
3295
- Ge as at,
3296
- me as au,
3297
- Za as av,
3298
- Ja as aw,
3299
- tn as ax,
3300
- an as ay,
3301
- nn as az,
3302
- Ba as b,
3303
- Yi as b0,
3304
- le as b1,
3305
- Ot as b2,
3306
- we as b3,
3307
- Ca as b4,
3308
- ui as c,
3309
- ze as d,
3310
- Va as e,
3311
- Ua as f,
3312
- li as g,
3313
- za as h,
3314
- La as i,
3315
- Ga as j,
3316
- J as k,
3317
- ln as l,
3318
- Pi as m,
3319
- Ha as n,
3320
- Qi as o,
3321
- gn as p,
3322
- mn as q,
3323
- hn as r,
3324
- Ji as s,
3325
- Ue as t,
3326
- sn as u,
3327
- rn as v,
3328
- Wa as w,
3329
- en as x,
3330
- Ka as y,
3331
- ci as z
3332
- };