react-semaphor 0.1.527 → 0.1.529

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 (64) hide show
  1. package/dist/analytics-protocol/index.js +207 -196
  2. package/dist/brand-studio/index.js +3 -3
  3. package/dist/briefings/index.js +5 -5
  4. package/dist/chunks/{calculated-field-identity-DEhjPSr-.js → calculated-field-identity-Q1aCudPD.js} +4 -4
  5. package/dist/chunks/{card-config-utils-BlIbwkuD.js → card-config-utils-DqyASiD_.js} +5 -5
  6. package/dist/chunks/{dashboard-JNHR0_cZ.js → dashboard-BC-EC5M_.js} +1 -1
  7. package/dist/chunks/{dashboard-briefing-launcher-D9pFByPh.js → dashboard-briefing-launcher-CwyFda8i.js} +9 -9
  8. package/dist/chunks/{dashboard-controls-CJI5ZWMq.js → dashboard-controls-Bqg8vlyr.js} +11 -11
  9. package/dist/chunks/{dashboard-json-DLdrFry-.js → dashboard-json-DVicOlh9.js} +3 -3
  10. package/dist/chunks/{edit-dashboard-visual-D5LjWle1.js → edit-dashboard-visual-D4k246cQ.js} +1984 -1961
  11. package/dist/chunks/{editor-action-buttons-G91NQKxU.js → editor-action-buttons-DKIZkBTZ.js} +6 -6
  12. package/dist/chunks/{field-aggregations-DeVQLIsP.js → field-aggregations-BCDRRYMo.js} +6 -6
  13. package/dist/chunks/{field-dependencies-CGYic38w.js → field-dependencies-BWStuMxe.js} +1 -1
  14. package/dist/chunks/{index-BvJOYbNv.js → index-BpAM7UE0.js} +351 -360
  15. package/dist/chunks/{matrix-analytical-definition-BJyH5-99.js → matrix-analytical-definition-Q4GL16S4.js} +1 -1
  16. package/dist/chunks/{matrix-card-DY45yiUM.js → matrix-card-CkfMe-h-.js} +2 -2
  17. package/dist/chunks/{matrix-control-sources-BypfLZsK.js → matrix-control-sources-fD0Ns_9n.js} +5 -5
  18. package/dist/chunks/{matrix-definition-Cdn3LoxW.js → matrix-definition-CiGRzEzt.js} +1 -1
  19. package/dist/chunks/{matrix-formatter-BoKU3MzZ.js → matrix-formatter-DDjECnMd.js} +5 -5
  20. package/dist/chunks/{matrix-member-presentation-BBW0n1iY.js → matrix-member-presentation-Glhem6xB.js} +1 -1
  21. package/dist/chunks/matrix-operation-contract-BotZ-6zT.js +1383 -0
  22. package/dist/chunks/{metric-comparison-Crljx_XY.js → metric-comparison-QEkk6hqL.js} +1 -1
  23. package/dist/chunks/{numeric-presentation-LvnNY5Ma.js → numeric-presentation-D2I9znLM.js} +1 -1
  24. package/dist/chunks/{pivot-header-presentation-D5v8uyjj.js → pivot-header-presentation-BTOXdU6S.js} +7 -7
  25. package/dist/chunks/{pivot-result-identity-CY__BuwI.js → pivot-result-identity-BhAm8MCg.js} +1 -1
  26. package/dist/chunks/{pivot-result-lifecycle-BWrPhlGT.js → pivot-result-lifecycle-BxmATSFJ.js} +8 -8
  27. package/dist/chunks/{raw-temporal-CdnA_OXJ.js → raw-temporal-B0EuwEHr.js} +2 -2
  28. package/dist/chunks/{raw-temporal-contract-Bc9z83t-.js → raw-temporal-contract-BlyUGV3y.js} +1 -1
  29. package/dist/chunks/{relative-date-DAF9J7mt.js → relative-date-P4o6ME04.js} +1 -1
  30. package/dist/chunks/{report-preferences-dialog-D3hxu4sE.js → report-preferences-dialog-DFpOrZ02.js} +9 -9
  31. package/dist/chunks/{report-runtime-context-CtaGGlit.js → report-runtime-context-DceiWMKz.js} +1 -1
  32. package/dist/chunks/{selection-reducer-C7Um5XN-.js → selection-reducer-DQok8gsC.js} +1 -1
  33. package/dist/chunks/{semantic-format-BjBMOSoo.js → semantic-format-ByNkXJpY.js} +3 -3
  34. package/dist/chunks/{semaphor-ready-indicator-D46I_4g7.js → semaphor-ready-indicator-DBb9d0Xp.js} +9359 -9411
  35. package/dist/chunks/{slider-B6LELqx6.js → slider-BibKRCxX.js} +8 -8
  36. package/dist/chunks/{source-entity-resolution-Bde29mqE.js → source-entity-resolution-BWmw7a8P.js} +124 -132
  37. package/dist/chunks/{switch-_7uBAbYx.js → switch-Bql-RCoZ.js} +16 -18
  38. package/dist/chunks/{temporal-bucket-contract-C6lUGPS3.js → temporal-bucket-contract-CdBtoHX2.js} +1 -1
  39. package/dist/chunks/{temporal-input-presentation-DyMWCZYh.js → temporal-input-presentation-wUO681Zs.js} +1 -1
  40. package/dist/chunks/{token-types-UjyNz95-.js → token-types-Brc30mNN.js} +1 -1
  41. package/dist/chunks/{validators-CQcG0EPN.js → validators-BS521dum.js} +1 -1
  42. package/dist/dashboard/index.js +1 -1
  43. package/dist/dashboard-authoring/index.js +10 -10
  44. package/dist/data-app-sdk/index.js +5 -5
  45. package/dist/data-app-sdk-adapters/index.js +2 -2
  46. package/dist/data-app-sdk-validation/index.js +5 -5
  47. package/dist/format-utils/index.js +13 -13
  48. package/dist/index.js +17 -17
  49. package/dist/report-runtime-context/index.js +2 -2
  50. package/dist/surfboard/index.js +1 -1
  51. package/dist/types/index.js +5 -5
  52. package/dist/types/lib/types/explorer-types.d.ts +3 -1
  53. package/dist/types/lib/types/semantic-types.d.ts +4 -2
  54. package/dist/types/lib/utils/aggregate-expression-utils.d.ts +0 -4
  55. package/dist/types/lib/utils/connection-capabilities.d.ts +3 -3
  56. package/dist/types/shared/analytics-protocol/aggregate-expression.d.ts +89 -0
  57. package/dist/types/shared/analytics-protocol/analytics-refusal.d.ts +32 -0
  58. package/dist/types/shared/analytics-protocol/contracts.d.ts +38 -0
  59. package/dist/types/shared/analytics-protocol/index.d.ts +3 -0
  60. package/dist/types/shared/analytics-protocol/matrix-analytical-definition.d.ts +1 -0
  61. package/dist/types/shared/analytics-protocol/matrix-window-contract.d.ts +10 -1
  62. package/dist/types/shared/analytics-protocol/measure-aggregation-profile.d.ts +63 -0
  63. package/package.json +2 -2
  64. package/dist/chunks/matrix-operation-contract-BV02rLhu.js +0 -809
@@ -0,0 +1,1383 @@
1
+ import { z as t } from "zod";
2
+ import { a5 as k, $ as ce, aa as G, bl as ee, B as A, a6 as je, bf as K, bm as Fe, aX as Le, a0 as Ue, b0 as qe, b1 as De, b4 as Me, b5 as Be, aQ as U, aV as Z, aK as Ge, a_ as ze, a$ as le, aH as Ve, aG as We, aW as Xe, aN as $e, aO as Ke, w as ue, aS as Ze, s as He, q as de, E as Ye, A as Qe, m as Je } from "./validators-BS521dum.js";
3
+ const H = {
4
+ answerSummary: "string",
5
+ responseDetail: "responseDetail",
6
+ mode: "string",
7
+ comparisonKind: "string",
8
+ executionResult: "executionResult",
9
+ compiledQuery: "unknown",
10
+ data: "unknown",
11
+ resultSets: "record",
12
+ analysisWarnings: "unknownArray",
13
+ columns: "unknownArray",
14
+ records: "recordArray",
15
+ rowCount: "number",
16
+ rowLimitExceeded: "boolean",
17
+ output: "string",
18
+ querySpec: "unknown",
19
+ metadata: "record",
20
+ validation: "validationResult",
21
+ coverage: "coverage",
22
+ diagnosticFeedback: "diagnosticFeedback",
23
+ missingFields: "stringArray",
24
+ warnings: "unknownArray",
25
+ comparison: "unknown",
26
+ population: "population",
27
+ comparisons: "recordArray",
28
+ fieldsUsed: "compactExecutionFieldArray",
29
+ primary: "recordArray",
30
+ contributors: "recordArray",
31
+ segments: "recordArray",
32
+ periodChanges: "recordArray",
33
+ changes: "recordArray",
34
+ largestNegativeChanges: "recordArray",
35
+ largestPositiveChanges: "recordArray",
36
+ drivers: "recordArray",
37
+ absoluteDeltaDrivers: "recordArray",
38
+ largestNegativeDrivers: "recordArray",
39
+ largestPositiveDrivers: "recordArray",
40
+ periodRows: "recordArray",
41
+ sql: "unknown",
42
+ omitted: "stringArray"
43
+ }, me = [
44
+ /** The request can't run as asked (no specific validation code applies). */
45
+ "invalid_request",
46
+ /** No authored relationship connects the requested datasets. */
47
+ "missing_relationship",
48
+ /** More than one relationship path fits and none is preferred. */
49
+ "ambiguous_relationship",
50
+ /** The join would repeat measure rows (fan-out, chasm, unknown cardinality). */
51
+ "unsafe_join",
52
+ /** The request needs something this surface doesn't support yet. */
53
+ "unsupported_capability",
54
+ /** The caller lacks a capability (for example raw SQL). */
55
+ "capability_required",
56
+ "forbidden",
57
+ "not_found",
58
+ /** The warehouse or driver failed while the query ran; the message is its own. */
59
+ "execution_failed",
60
+ "timeout",
61
+ "budget_exceeded",
62
+ "cancelled"
63
+ ], et = {
64
+ invalid_request: 400,
65
+ missing_relationship: 400,
66
+ ambiguous_relationship: 400,
67
+ unsafe_join: 400,
68
+ unsupported_capability: 400,
69
+ capability_required: 403,
70
+ forbidden: 403,
71
+ not_found: 404,
72
+ execution_failed: 502,
73
+ timeout: 504,
74
+ budget_exceeded: 413,
75
+ cancelled: 499
76
+ }, tt = /* @__PURE__ */ new Set(["execution_failed", "timeout"]);
77
+ function nt(e) {
78
+ return typeof e == "string" && me.includes(e);
79
+ }
80
+ function at(e, n, a = {}) {
81
+ return {
82
+ code: e,
83
+ message: n,
84
+ ...a.details ? { details: a.details } : {},
85
+ ...a.nextStep ? { nextStep: a.nextStep } : {},
86
+ retryable: tt.has(e),
87
+ status: a.status ?? et[e]
88
+ };
89
+ }
90
+ function rn(e) {
91
+ if (!e || typeof e != "object") return;
92
+ const n = e.refusal ?? e;
93
+ if (!n || typeof n != "object") return;
94
+ const { code: a, message: r } = n;
95
+ if (!(!nt(a) || typeof r != "string"))
96
+ return n;
97
+ }
98
+ const rt = {
99
+ invalid_request: { message: "This query configuration cannot run.", nextStep: "Check the selected fields, filters and parameters." },
100
+ missing_relationship: { message: "The selected data is not connected.", nextStep: "Choose related datasets or ask the owner to add a relationship." },
101
+ ambiguous_relationship: { message: "The selected data has more than one relationship path.", nextStep: "Choose the relationship to use." },
102
+ unsafe_join: { message: "This query could count values more than once.", nextStep: "Group by shared fields or query the measures separately." },
103
+ unsupported_capability: { message: "This query needs a capability this view does not support.", nextStep: "Change the query configuration." },
104
+ capability_required: { message: "You do not have access to this capability.", nextStep: "Ask the owner for access." },
105
+ forbidden: { message: "You do not have access to this data.", nextStep: "Ask the owner for access." },
106
+ not_found: { message: "The requested data is no longer available.", nextStep: "Ask the owner to check the data source." },
107
+ execution_failed: { message: "The query could not complete.", nextStep: "Try again. If it keeps failing, contact the owner." },
108
+ timeout: { message: "The query took too long to complete.", nextStep: "Try again or narrow the query." },
109
+ budget_exceeded: { message: "The query exceeds this view’s limits.", nextStep: "Request fewer rows, columns or measures." },
110
+ cancelled: { message: "The query was cancelled.", nextStep: "Reload the view when ready." }
111
+ };
112
+ function sn(e) {
113
+ const n = rt[e.code], a = at(e.code, n.message, { nextStep: n.nextStep, status: e.status }), r = e.retryable ?? a.retryable;
114
+ return {
115
+ ...a,
116
+ retryable: r,
117
+ ...!r && a.retryable ? { nextStep: "Ask the owner to check the query." } : {}
118
+ };
119
+ }
120
+ const st = [
121
+ ...me,
122
+ "stale_cursor",
123
+ "source_truncated"
124
+ ], on = Object.freeze({
125
+ coordinates: 2e4,
126
+ responseBytes: 5 * 1024 * 1024
127
+ }), O = t.string().uuid(), y = t.string().min(1), ot = t.number().int().positive().max(Number.MAX_SAFE_INTEGER);
128
+ function f(e, n, a) {
129
+ e.addIssue({ code: "custom", path: n, message: a });
130
+ }
131
+ function v(e, n, a) {
132
+ new Set(e).size !== e.length && f(n, a, "Duplicate identity.");
133
+ }
134
+ const it = t.object({
135
+ id: y,
136
+ axis: ce,
137
+ parent: k,
138
+ position: t.union([
139
+ t.object({ kind: t.literal("first") }).strict(),
140
+ t.object({ kind: t.enum(["after", "before"]), cursor: y }).strict()
141
+ ]),
142
+ size: ot
143
+ }).strict(), te = t.object({
144
+ paths: t.array(k).readonly(),
145
+ pageIds: t.array(y).readonly()
146
+ }).strict(), ct = t.object({
147
+ id: y,
148
+ rows: te,
149
+ columns: te,
150
+ measureIds: t.array(O).min(1).readonly()
151
+ }).strict(), pe = t.object({
152
+ pages: t.array(it).readonly(),
153
+ blocks: t.array(ct).readonly()
154
+ }).strict().superRefine((e, n) => {
155
+ !e.pages.length && !e.blocks.length && f(n, [], "Request at least one page or block."), v(
156
+ [...e.pages, ...e.blocks].map((a) => a.id),
157
+ n,
158
+ []
159
+ );
160
+ for (const a of e.blocks) {
161
+ v(a.measureIds, n, ["blocks", a.id, "measureIds"]);
162
+ for (const r of ["rows", "columns"])
163
+ for (const s of a[r].pageIds)
164
+ e.pages.some(
165
+ (c) => c.id === s && c.axis === r
166
+ ) || f(
167
+ n,
168
+ ["blocks", a.id, r],
169
+ "Page reference must name a page on this axis in this operation."
170
+ );
171
+ }
172
+ }), cn = t.object({ spec: G, request: pe }).strict().superRefine(({ spec: e, request: n }, a) => {
173
+ for (const r of n.pages)
174
+ ee(
175
+ e,
176
+ r.axis,
177
+ r.parent,
178
+ a,
179
+ ["pages", r.id],
180
+ !0
181
+ ), r.parent.length >= e[r.axis].length && f(
182
+ a,
183
+ ["pages", r.id],
184
+ "Cannot request children of a leaf or empty axis."
185
+ );
186
+ for (const r of n.blocks) {
187
+ r.measureIds.some((s) => !e.measures.some((c) => c.id === s)) && f(a, ["blocks", r.id], "Unknown block measure.");
188
+ for (const s of ["rows", "columns"])
189
+ for (const c of r[s].paths)
190
+ ee(e, s, c, a, ["blocks", r.id, s]);
191
+ }
192
+ }), lt = t.object({
193
+ requestId: y,
194
+ axis: ce,
195
+ parent: k,
196
+ members: t.array(t.object({ path: k }).strict()).readonly(),
197
+ before: y.nullable(),
198
+ after: y.nullable(),
199
+ exactCount: t.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER).optional()
200
+ }).strict().superRefine((e, n) => {
201
+ e.parent.some((r) => r.member.kind === "others") && f(n, ["parent"], "Others has no children.");
202
+ const a = e.members.filter(
203
+ ({ path: r }) => {
204
+ var s;
205
+ return ((s = r[r.length - 1]) == null ? void 0 : s.member.kind) === "others";
206
+ }
207
+ );
208
+ a.length > 1 && f(n, ["members"], "A page may contain Others only once."), a.length && (e.members[e.members.length - 1] !== a[0] && f(n, ["members"], "Others must be the last page member."), e.after !== null && f(n, ["after"], "Others must end the branch.")), new Set(
209
+ e.members.map(
210
+ (r) => {
211
+ var s;
212
+ return (s = r.path[r.path.length - 1]) == null ? void 0 : s.levelId;
213
+ }
214
+ )
215
+ ).size > 1 && f(n, ["members"], "One page must contain one child level."), v(
216
+ e.members.map((r) => A(r.path)),
217
+ n,
218
+ ["members"]
219
+ );
220
+ for (const r of e.members)
221
+ (r.path.length !== e.parent.length + 1 || A(r.path.slice(0, -1)) !== A(e.parent)) && f(n, ["members"], "Page members must be immediate children.");
222
+ }), he = t.object({
223
+ rowPaths: t.array(k).readonly(),
224
+ columnPaths: t.array(k).readonly(),
225
+ measureIds: t.array(O).readonly()
226
+ }).strict();
227
+ function fe(e, n) {
228
+ const a = e.rowPaths.map(A), r = e.columnPaths.map(A);
229
+ return v(a, n, ["coverage", "rowPaths"]), v(r, n, ["coverage", "columnPaths"]), v(e.measureIds, n, ["coverage", "measureIds"]), { rows: a, columns: r };
230
+ }
231
+ const ut = t.object({
232
+ requestId: y,
233
+ coverage: he,
234
+ cells: t.array(
235
+ je.extend({ value: K }).strict()
236
+ ).readonly()
237
+ }).strict().superRefine((e, n) => {
238
+ const { rows: a, columns: r } = fe(e.coverage, n), s = new Set(a), c = new Set(r), i = new Set(e.coverage.measureIds);
239
+ v(
240
+ e.cells.map(
241
+ (l) => JSON.stringify([
242
+ A(l.rowPath),
243
+ A(l.columnPath),
244
+ l.measureId
245
+ ])
246
+ ),
247
+ n,
248
+ ["cells"]
249
+ );
250
+ for (const l of e.cells)
251
+ (!s.has(A(l.rowPath)) || !c.has(A(l.columnPath)) || !i.has(l.measureId)) && f(n, ["cells"], "Cell is outside certified coverage.");
252
+ }), q = t.number().int().nonnegative(), dt = t.object({
253
+ requestId: y,
254
+ coverage: he,
255
+ values: t.array(
256
+ t.tuple([q, q, q, K]).readonly()
257
+ ).readonly()
258
+ }).strict().superRefine((e, n) => {
259
+ fe(e.coverage, n);
260
+ const { rowPaths: a, columnPaths: r, measureIds: s } = e.coverage, c = /* @__PURE__ */ new Set();
261
+ for (const [i, l, m] of e.values) {
262
+ if (i >= a.length || l >= r.length || m >= s.length) {
263
+ f(n, ["values"], "Cell is outside certified coverage.");
264
+ continue;
265
+ }
266
+ const o = `${i},${l},${m}`;
267
+ c.has(o) && f(n, ["values"], "Duplicate identity."), c.add(o);
268
+ }
269
+ }), ne = t.object({
270
+ id: O,
271
+ column: Le,
272
+ nativeDataType: y,
273
+ semanticFormat: Fe.optional()
274
+ }).strict(), ge = t.object({
275
+ levels: t.array(ne).readonly(),
276
+ measures: t.array(ne).readonly()
277
+ }).strict(), Y = t.object({
278
+ code: t.enum(st),
279
+ message: y,
280
+ /** Technical cause for dashboard owners; never shown as the primary copy. */
281
+ detail: y.optional(),
282
+ details: t.record(t.unknown()).optional(),
283
+ nextStep: y.optional(),
284
+ status: t.number().int().optional(),
285
+ retryable: t.boolean(),
286
+ scope: t.union([
287
+ t.object({ kind: t.literal("operation") }).strict(),
288
+ t.object({ kind: t.enum(["page", "block"]), requestId: y }).strict()
289
+ ])
290
+ }).strict(), mt = t.object({
291
+ dialect: t.enum(["postgres", "clickhouse", "duckdb"]),
292
+ aggregates: t.array(Ue).readonly()
293
+ }).strict();
294
+ function ye(e) {
295
+ return t.object({
296
+ queryIdentity: y,
297
+ descriptors: ge,
298
+ capabilities: mt,
299
+ pages: t.array(lt).readonly(),
300
+ blocks: t.array(e).readonly(),
301
+ failures: t.array(Y).readonly()
302
+ }).strict().superRefine((n, a) => {
303
+ const r = new Set(
304
+ n.descriptors.levels.map((i) => i.id)
305
+ ), s = new Set(
306
+ n.descriptors.measures.map((i) => i.id)
307
+ ), c = n.pages.flatMap((i) => [
308
+ i.parent,
309
+ ...i.members.map((l) => l.path)
310
+ ]);
311
+ for (const i of n.blocks)
312
+ c.push(...i.coverage.rowPaths, ...i.coverage.columnPaths), i.coverage.measureIds.some((l) => !s.has(l)) && f(
313
+ a,
314
+ ["blocks", i.requestId],
315
+ "Coverage references an unknown measure descriptor."
316
+ );
317
+ c.some((i) => i.some((l) => !r.has(l.levelId))) && f(
318
+ a,
319
+ ["descriptors"],
320
+ "Acquired paths require level descriptors."
321
+ ), v(
322
+ [...n.descriptors.levels, ...n.descriptors.measures].map(
323
+ (i) => i.id
324
+ ),
325
+ a,
326
+ ["descriptors"]
327
+ ), v(
328
+ [...n.pages, ...n.blocks].map((i) => i.requestId),
329
+ a,
330
+ []
331
+ ), v(
332
+ n.failures.map(
333
+ (i) => i.scope.kind === "operation" ? "operation" : i.scope.requestId
334
+ ),
335
+ a,
336
+ ["failures"]
337
+ );
338
+ for (const i of n.failures)
339
+ if (i.scope.kind === "operation")
340
+ f(
341
+ a,
342
+ ["failures"],
343
+ "Operation failure cannot accompany acquired data."
344
+ );
345
+ else {
346
+ const l = i.scope.requestId;
347
+ [...n.pages, ...n.blocks].some(
348
+ (m) => m.requestId === l
349
+ ) && f(
350
+ a,
351
+ ["failures"],
352
+ "A requested unit cannot both succeed and fail."
353
+ );
354
+ }
355
+ });
356
+ }
357
+ const Se = ye(
358
+ ut
359
+ ), pt = ye(
360
+ dt
361
+ );
362
+ function be(e) {
363
+ return t.union([
364
+ t.object({
365
+ status: t.enum(["success", "partial"]),
366
+ window: e
367
+ }).strict(),
368
+ t.object({ status: t.literal("failed"), failure: Y }).strict()
369
+ ]).superRefine((n, a) => {
370
+ const r = n;
371
+ if (r.status === "failed") return;
372
+ const { window: s } = r;
373
+ !s.pages.length && !s.blocks.length && f(
374
+ a,
375
+ ["window"],
376
+ "A window outcome requires successful acquired work."
377
+ ), r.status === "success" != (s.failures.length === 0) && f(a, ["status"], "Status must match failure coverage.");
378
+ });
379
+ }
380
+ const ln = be(
381
+ Se
382
+ ), un = be(
383
+ pt
384
+ );
385
+ function ht(e) {
386
+ const { rowPaths: n, columnPaths: a, measureIds: r } = e.coverage, s = (m) => new Map(m.map((o, d) => [o, d])), c = s(n.map(A)), i = s(a.map(A)), l = s(r);
387
+ return {
388
+ requestId: e.requestId,
389
+ coverage: e.coverage,
390
+ values: e.cells.map((m) => {
391
+ const o = c.get(A(m.rowPath)), d = i.get(A(m.columnPath)), p = l.get(m.measureId);
392
+ if (o === void 0 || d === void 0 || p === void 0)
393
+ throw new Error("Cell is outside certified coverage.");
394
+ return [o, d, p, m.value];
395
+ })
396
+ };
397
+ }
398
+ function ft(e) {
399
+ const { rowPaths: n, columnPaths: a, measureIds: r } = e.coverage;
400
+ return {
401
+ requestId: e.requestId,
402
+ coverage: e.coverage,
403
+ cells: e.values.map(([s, c, i, l]) => ({
404
+ rowPath: n[s],
405
+ columnPath: a[c],
406
+ measureId: r[i],
407
+ value: l
408
+ }))
409
+ };
410
+ }
411
+ function gt(e) {
412
+ return { ...e, blocks: e.blocks.map(ht) };
413
+ }
414
+ function dn(e) {
415
+ return { ...e, blocks: e.blocks.map(ft) };
416
+ }
417
+ function mn(e) {
418
+ return e.status === "failed" ? e : { status: e.status, window: gt(e.window) };
419
+ }
420
+ const Ae = t.object({
421
+ kind: t.literal("matrix"),
422
+ window: Se
423
+ }).strict(), Ie = t.enum(["member", "subtotal", "grand_total"]), yt = t.discriminatedUnion("kind", [
424
+ t.object({ kind: t.literal("hierarchy"), label: t.string() }).strict(),
425
+ t.object({ kind: t.literal("level"), levelId: O, label: t.string() }).strict(),
426
+ t.object({
427
+ kind: t.literal("measure"),
428
+ measureId: O,
429
+ columnPath: k,
430
+ role: Ie,
431
+ label: t.string()
432
+ }).strict()
433
+ ]), St = t.object({
434
+ columns: t.array(yt).readonly(),
435
+ descriptors: ge
436
+ }).strict(), ae = t.union([
437
+ t.object({
438
+ kind: t.literal("value"),
439
+ value: K.refine(
440
+ (e) => e !== null
441
+ )
442
+ }).strict(),
443
+ t.object({ kind: t.enum(["null", "empty"]) }).strict()
444
+ ]), bt = t.discriminatedUnion("kind", [
445
+ t.object({
446
+ kind: t.literal("layout"),
447
+ rowPath: k,
448
+ role: Ie,
449
+ values: t.array(ae).readonly()
450
+ }).strict(),
451
+ t.object({
452
+ kind: t.literal("flat"),
453
+ rowPath: k,
454
+ columnPath: k,
455
+ values: t.array(ae).readonly()
456
+ }).strict()
457
+ ]), pn = t.discriminatedUnion("kind", [
458
+ t.object({
459
+ kind: t.literal("layout"),
460
+ layout: St,
461
+ next: y
462
+ }).strict(),
463
+ t.object({
464
+ kind: t.literal("rows"),
465
+ rows: t.array(bt).readonly(),
466
+ next: y.nullable()
467
+ }).strict()
468
+ ]), At = t.union([
469
+ qe,
470
+ De,
471
+ Me,
472
+ Be,
473
+ Ae
474
+ ]), It = t.object({
475
+ status: t.enum([
476
+ "not_required",
477
+ "resolved",
478
+ "missing",
479
+ "ambiguous",
480
+ "fanout_risk",
481
+ "unknown"
482
+ ]),
483
+ requiredSources: t.array(U).optional(),
484
+ relationshipsUsed: t.array(t.string()).optional(),
485
+ missingSources: t.array(t.string()).optional(),
486
+ warnings: t.array(t.string()).optional(),
487
+ message: t.string().optional(),
488
+ recommendedNextStep: t.string().optional(),
489
+ joinPlanSummary: t.object({
490
+ baseSource: U.optional(),
491
+ joinedSources: t.array(U).optional(),
492
+ joinCount: t.number().optional()
493
+ }).passthrough().optional(),
494
+ fanoutRisk: t.object({
495
+ status: t.enum(["none", "warning", "error", "unknown"]),
496
+ message: t.string().optional()
497
+ }).passthrough().optional()
498
+ }).passthrough(), re = t.enum([
499
+ "ambiguous_fields",
500
+ "empty_result",
501
+ "missing_grounded_fields",
502
+ "missing_relationship",
503
+ "no_grounded_query",
504
+ "partial_result",
505
+ "presentation_incomplete",
506
+ "query_validation_failed",
507
+ "unsafe_join"
508
+ ]), _e = t.object({
509
+ version: t.literal(1),
510
+ status: t.enum(["answered", "partial", "blocked"]),
511
+ summary: t.string(),
512
+ answered: t.array(
513
+ t.object({
514
+ slotId: t.string().optional(),
515
+ queryId: t.string().optional(),
516
+ summary: t.string(),
517
+ evidenceIds: t.array(t.string()).optional(),
518
+ fieldsUsed: t.array(Z).optional()
519
+ }).passthrough()
520
+ ),
521
+ blocked: t.array(
522
+ t.object({
523
+ slotId: t.string().optional(),
524
+ queryId: t.string().optional(),
525
+ reasonCode: re,
526
+ message: t.string(),
527
+ missingFields: t.array(t.string()).optional(),
528
+ availableFields: t.array(t.string()).optional(),
529
+ ambiguousFields: t.array(t.string()).optional(),
530
+ missingRelationships: t.array(t.string()).optional(),
531
+ evidenceIds: t.array(t.string()).optional(),
532
+ neededFromUser: t.array(t.string()).optional(),
533
+ recommendedNextStep: t.string().optional()
534
+ }).passthrough()
535
+ ),
536
+ semanticModelRecommendations: t.array(
537
+ t.object({
538
+ reasonCode: re,
539
+ message: t.string(),
540
+ recommendedNextStep: t.string().optional()
541
+ }).passthrough()
542
+ ).optional()
543
+ }).passthrough(), we = t.object({
544
+ scope: t.literal("filtered_query"),
545
+ measures: t.record(Ge)
546
+ }).passthrough(), ke = t.object({
547
+ answeredObligations: t.array(t.string()),
548
+ missingObligations: t.array(t.string()),
549
+ warnings: t.array(ze).optional()
550
+ }).passthrough(), ve = t.object({
551
+ intentId: t.string().optional(),
552
+ queryId: t.string().optional(),
553
+ status: t.enum(["answered", "partial", "failed"]),
554
+ resultShape: t.enum([
555
+ "metric",
556
+ "records",
557
+ "inputOptions",
558
+ "sql",
559
+ "matrix",
560
+ "period_change",
561
+ "analysis"
562
+ ]).optional(),
563
+ intent: t.unknown().optional(),
564
+ compiledQuery: t.unknown().optional(),
565
+ fieldsUsed: t.array(Z).optional(),
566
+ result: At.optional(),
567
+ validation: le,
568
+ coverage: ke.optional(),
569
+ missingFields: t.array(t.string()).optional(),
570
+ warnings: t.array(t.string()).optional(),
571
+ relationshipDiagnostics: It.optional(),
572
+ diagnosticFeedback: _e.optional(),
573
+ population: we.optional(),
574
+ metadata: t.record(t.string(), t.unknown()).optional()
575
+ }).passthrough(), _t = ve;
576
+ function wt(e) {
577
+ switch (e) {
578
+ case "boolean":
579
+ return t.boolean().optional();
580
+ case "compactExecutionFieldArray":
581
+ return t.array(Xe).optional();
582
+ case "coverage":
583
+ return ke.optional();
584
+ case "diagnosticFeedback":
585
+ return _e.optional();
586
+ case "executionFieldArray":
587
+ return t.array(Z).optional();
588
+ case "executionResult":
589
+ return _t.optional();
590
+ case "number":
591
+ return t.number().finite().optional();
592
+ case "population":
593
+ return we.optional();
594
+ case "record":
595
+ return We.optional();
596
+ case "recordArray":
597
+ return Ve.optional();
598
+ case "responseDetail":
599
+ return t.enum(["compact", "standard", "debug"]).optional();
600
+ case "string":
601
+ return t.string().optional();
602
+ case "stringArray":
603
+ return t.array(t.string()).optional();
604
+ case "unknown":
605
+ return t.unknown().optional();
606
+ case "unknownArray":
607
+ return t.array(t.unknown()).optional();
608
+ case "validationResult":
609
+ return le.optional();
610
+ }
611
+ }
612
+ const kt = Object.fromEntries(
613
+ Object.entries(H).map(
614
+ ([e, n]) => [e, wt(n)]
615
+ )
616
+ ), vt = t.object(kt).strict(), Tt = new Set(
617
+ Object.keys(H)
618
+ );
619
+ function hn() {
620
+ return Object.keys(
621
+ H
622
+ );
623
+ }
624
+ function Rt(e) {
625
+ return Tt.has(e);
626
+ }
627
+ function fn(e) {
628
+ if (!e || typeof e != "object" || Array.isArray(e))
629
+ throw new Error("Semaphor analyze result must be an object.");
630
+ const a = Object.keys(e).filter(
631
+ (r) => !Rt(r)
632
+ );
633
+ if (a.length)
634
+ throw new Error(
635
+ `Semaphor analyze result contains unsupported top-level field(s): ${a.join(", ")}.`
636
+ );
637
+ return vt.parse(e);
638
+ }
639
+ const Te = 100, F = "selection:";
640
+ function Re(e) {
641
+ return [
642
+ de(e.source),
643
+ Ye(e.name),
644
+ e.sourceField ?? ""
645
+ ].join("::");
646
+ }
647
+ function gn(e) {
648
+ return `${F}${e}`;
649
+ }
650
+ function Et(e) {
651
+ return e.startsWith(F) && e.length > F.length;
652
+ }
653
+ function yn(e) {
654
+ return Et(e) ? e.slice(F.length) : void 0;
655
+ }
656
+ function Ee(e) {
657
+ if (!e) return "";
658
+ const n = e.calendar.fiscalCalendar;
659
+ return JSON.stringify([
660
+ e.granularity,
661
+ e.calendar.tz,
662
+ e.calendar.weekStart,
663
+ n ? [n.kind, n.yearStartMonth] : null
664
+ ]);
665
+ }
666
+ function Ct(e) {
667
+ return JSON.stringify([
668
+ Re(e.field),
669
+ e.operator,
670
+ e.operator === "isNull" ? null : e.value,
671
+ Ee(e.temporalBucket)
672
+ ]);
673
+ }
674
+ function se(e) {
675
+ return JSON.stringify(e.conditions.map(Ct).sort());
676
+ }
677
+ function z(e) {
678
+ return JSON.stringify([
679
+ de(e.field.source),
680
+ e.field.name,
681
+ e.operator,
682
+ e.operator === "isNull" ? null : e.value,
683
+ Ee(e.temporalBucket)
684
+ ]);
685
+ }
686
+ function oe(e) {
687
+ return JSON.stringify(
688
+ e.conditions.map(z).sort()
689
+ );
690
+ }
691
+ function Sn(e) {
692
+ const n = e.map((a) => a.id);
693
+ if (new Set(n).size !== n.length)
694
+ throw new Error("Data App selections require one active selection per id.");
695
+ return e.map((a) => ({
696
+ ...a,
697
+ tuples: a.tuples.map((r) => ({
698
+ ...r,
699
+ conditions: [...r.conditions].sort(
700
+ (s, c) => D(
701
+ z(s),
702
+ z(c)
703
+ )
704
+ )
705
+ })).sort(
706
+ (r, s) => D(
707
+ oe(r),
708
+ oe(s)
709
+ )
710
+ )
711
+ })).sort((a, r) => D(a.id, r.id));
712
+ }
713
+ function D(e, n) {
714
+ return e < n ? -1 : e > n ? 1 : 0;
715
+ }
716
+ function bn(e, n) {
717
+ return se(e) === se(n);
718
+ }
719
+ const Nt = "(Blank)";
720
+ function An(e) {
721
+ return e.conditions.map((n) => n.label ? n.label : n.operator === "isNull" || n.value === null ? Nt : String(n.value)).join(" · ");
722
+ }
723
+ const Ot = t.union([
724
+ $e,
725
+ Ke
726
+ ]), xt = t.object({
727
+ name: t.string().min(1),
728
+ source: Ot,
729
+ dataType: t.enum(["string", "number", "boolean", "date", "datetime"]),
730
+ sourceField: t.string().min(1).optional()
731
+ }).strict(), Pt = t.object({
732
+ field: xt,
733
+ operator: t.enum(["=", "isNull"]),
734
+ value: t.union([t.string(), t.number().finite(), t.null()]),
735
+ label: t.string().optional(),
736
+ temporalBucket: ue.optional()
737
+ }).strict().superRefine((e, n) => {
738
+ e.operator === "isNull" != (e.value === null) && n.addIssue({
739
+ code: t.ZodIssueCode.custom,
740
+ message: "isNull carries a null value, and only isNull does.",
741
+ path: ["value"]
742
+ });
743
+ }), jt = t.object({
744
+ conditions: t.array(Pt).min(1)
745
+ }).strict().superRefine((e, n) => {
746
+ const a = e.conditions.map((r) => Re(r.field));
747
+ new Set(a).size !== a.length && n.addIssue({
748
+ code: t.ZodIssueCode.custom,
749
+ message: "A tuple holds one condition per field.",
750
+ path: ["conditions"]
751
+ });
752
+ }), In = t.object({
753
+ kind: t.literal("selection"),
754
+ sourceCardId: t.string().min(1),
755
+ tuples: t.array(jt).min(1).max(Te)
756
+ }).strict(), Ft = t.object({
757
+ field: Ze,
758
+ operator: t.enum(["=", "isNull"]),
759
+ value: t.union([t.string(), t.number().finite(), t.null()]),
760
+ temporalBucket: ue.optional()
761
+ }).strict().superRefine((e, n) => {
762
+ e.operator === "isNull" != (e.value === null) && n.addIssue({
763
+ code: t.ZodIssueCode.custom,
764
+ message: "isNull carries a null value, and only isNull does.",
765
+ path: ["value"]
766
+ });
767
+ }), Lt = t.object({
768
+ conditions: t.array(Ft).min(1)
769
+ }).strict().superRefine((e, n) => {
770
+ for (let a = 0; a < e.conditions.length; a += 1) {
771
+ const r = e.conditions[a];
772
+ e.conditions.findIndex(
773
+ (c, i) => i < a && He(c.field, r.field)
774
+ ) !== -1 && n.addIssue({
775
+ code: t.ZodIssueCode.custom,
776
+ message: "A selection tuple can contain only one condition per field.",
777
+ path: ["conditions", a, "field"]
778
+ });
779
+ }
780
+ }), _n = t.object({
781
+ id: t.string().min(1),
782
+ tuples: t.array(Lt).min(1).max(Te)
783
+ }).strict(), Ut = t.object({ key: t.string().min(1), nativeText: t.string().nullable() }).strict(), qt = t.object({
784
+ executionInstant: t.string().refine((e) => Qe(e) !== null, {
785
+ message: "executionInstant must be an ISO instant"
786
+ }),
787
+ dataAnchors: t.array(Ut).default([])
788
+ }).strict().refine(
789
+ (e) => new Set(e.dataAnchors.map((n) => n.key)).size === e.dataAnchors.length,
790
+ { message: "dataAnchors keys must be unique", path: ["dataAnchors"] }
791
+ );
792
+ function wn(e) {
793
+ if (e == null) return;
794
+ const n = qt.safeParse(e);
795
+ return n.success ? n.data : void 0;
796
+ }
797
+ const Ce = {
798
+ COUNT: "count",
799
+ COUNTIF: "count",
800
+ COUNT_IF: "count",
801
+ COUNTIFS: "count",
802
+ SUM: "sum",
803
+ SUM_IF: "sum",
804
+ SUMIF: "sum",
805
+ AVG: "avg",
806
+ AVG_IF: "avg",
807
+ AVERAGE: "avg",
808
+ MEAN: "avg",
809
+ MIN: "min",
810
+ MIN_IF: "min",
811
+ MAX: "max",
812
+ MAX_IF: "max",
813
+ MEDIAN: "median",
814
+ DISTINCT: "count_distinct",
815
+ COUNT_DISTINCT: "count_distinct",
816
+ APPROX_COUNT_DISTINCT: "count_distinct",
817
+ APPROX_DISTINCT: "count_distinct",
818
+ NDV: "count_distinct",
819
+ UNIQ: "count_distinct",
820
+ UNIQEXACT: "count_distinct",
821
+ UNIQCOMBINED: "count_distinct",
822
+ UNIQHLL12: "count_distinct",
823
+ HLL_COUNT: "count_distinct",
824
+ HLL_ESTIMATE: "count_distinct",
825
+ BOOL_AND: "repeat_safe_other",
826
+ BOOL_OR: "repeat_safe_other",
827
+ BIT_AND: "repeat_safe_other",
828
+ BIT_OR: "repeat_safe_other",
829
+ EVERY: "repeat_safe_other",
830
+ ANY_VALUE: "repeat_safe_other",
831
+ MODE: "other",
832
+ APPROX_QUANTILES: "other",
833
+ APPROX_QUANTILE: "other",
834
+ APPROX_TOP_COUNT: "other",
835
+ APPROX_TOP_SUM: "other",
836
+ STDDEV: "other",
837
+ STDDEV_POP: "other",
838
+ STDDEV_SAMP: "other",
839
+ VARIANCE: "other",
840
+ VAR_POP: "other",
841
+ VAR_SAMP: "other",
842
+ BIT_XOR: "other",
843
+ CORR: "other",
844
+ COVAR_POP: "other",
845
+ COVAR_SAMP: "other",
846
+ STRING_AGG: "other",
847
+ ARRAY_AGG: "other",
848
+ JSON_AGG: "other",
849
+ JSONB_AGG: "other",
850
+ OBJECT_AGG: "other",
851
+ MAP_AGG: "other",
852
+ LISTAGG: "other",
853
+ GROUP_CONCAT: "other",
854
+ COLLECT_LIST: "other",
855
+ COLLECT_SET: "other",
856
+ FIRST: "other",
857
+ LAST: "other"
858
+ }, Dt = /(?:_AGG$|^APPROX_[A-Z0-9_]+$|^COUNT_DISTINCT$|^HLL_(?:COUNT|ESTIMATE)$|^REGR_[A-Z_]+$)/;
859
+ function Mt(e) {
860
+ const n = e.toUpperCase();
861
+ return n in Ce || Dt.test(n);
862
+ }
863
+ function Ne(e, n = !1) {
864
+ const a = Ce[e.toUpperCase()] ?? "other";
865
+ return n ? a === "count" || a === "count_distinct" ? "count_distinct" : a === "min" || a === "max" ? a : "repeat_safe_other" : a;
866
+ }
867
+ const Bt = /* @__PURE__ */ new Set([
868
+ "NULLIF",
869
+ "COALESCE",
870
+ "IFNULL",
871
+ "ISNULL",
872
+ "ROUND",
873
+ "FLOOR",
874
+ "CEIL",
875
+ "CEILING",
876
+ "ABS",
877
+ "POWER",
878
+ "SQRT",
879
+ "CAST",
880
+ "TRY_CAST",
881
+ "SAFE_CAST"
882
+ ]), Gt = /* @__PURE__ */ new Set(["DECIMAL", "NUMERIC", "INTEGER", "INT", "BIGINT", "FLOAT", "DOUBLE", "REAL", "VARCHAR", "TEXT"]), ie = /[A-Za-z_]/, zt = /[A-Za-z0-9_]/;
883
+ function V(e, n) {
884
+ const a = e[n];
885
+ let r = n + 1;
886
+ for (; r < e.length; ) {
887
+ if (e[r] === a) {
888
+ if (e[r + 1] === a) {
889
+ r += 2;
890
+ continue;
891
+ }
892
+ return r + 1;
893
+ }
894
+ r += 1;
895
+ }
896
+ return r;
897
+ }
898
+ function P(e, n) {
899
+ let a = 0, r = n;
900
+ for (; r < e.length; ) {
901
+ const s = e[r];
902
+ if (s === "'" || s === '"') {
903
+ r = V(e, r);
904
+ continue;
905
+ }
906
+ if (s === "(" && (a += 1), s === ")" && (a -= 1, a === 0))
907
+ return r + 1;
908
+ r += 1;
909
+ }
910
+ return e.length;
911
+ }
912
+ function j(e, n) {
913
+ let a = n;
914
+ for (; a < e.length && /\s/.test(e[a]); ) a += 1;
915
+ return a;
916
+ }
917
+ function M(e, n) {
918
+ let a = n + 1;
919
+ for (; a < e.length && zt.test(e[a]); ) a += 1;
920
+ return a;
921
+ }
922
+ const Vt = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
923
+ function Wt(e) {
924
+ return Array.from(e.matchAll(Vt), (n) => n[1]);
925
+ }
926
+ function W(e, n = /* @__PURE__ */ new Set()) {
927
+ const a = [], r = [];
928
+ let s = !1, c = "", i = !0, l = 0;
929
+ for (; l < e.length; ) {
930
+ const m = e[l];
931
+ if (m === "'" || m === '"') {
932
+ const o = V(e, l);
933
+ c += "'s'", m !== "'" && (i = !1), l = o;
934
+ continue;
935
+ }
936
+ if (m === "{") {
937
+ const o = e.indexOf("}", l);
938
+ if (o > l) {
939
+ const d = e.slice(l + 1, o);
940
+ r.push(d), n.has(d) || (i = !1), c += `#${d}`, l = o + 1;
941
+ continue;
942
+ }
943
+ }
944
+ if (ie.test(m)) {
945
+ const o = M(e, l), d = e.slice(l, o), p = j(e, o);
946
+ if (e[p] === "(" && Mt(d)) {
947
+ let g = P(e, p);
948
+ const I = g - 1;
949
+ let E = g;
950
+ const T = e.slice(p + 1, g - 1);
951
+ let x = T.trim() ? 1 : 0;
952
+ for (let h = p + 1; h < E - 1; h++)
953
+ e[h] === "'" || e[h] === '"' ? h = V(e, h) - 1 : e[h] === "(" ? h = P(e, h) - 1 : e[h] === "," && x++;
954
+ const C = /^\s*DISTINCT\b/i.test(T);
955
+ W(C ? T.replace(/^\s*DISTINCT\b/i, "") : T).calls.length > 0 && (s = !0);
956
+ let b = !1, _ = !1;
957
+ for (; ; ) {
958
+ const h = j(e, g);
959
+ if (!ie.test(e[h] || "")) break;
960
+ const N = M(e, h), R = e.slice(h, N).toUpperCase(), u = j(e, N);
961
+ if (R === "WITHIN") {
962
+ const S = M(e, u), w = j(e, S);
963
+ if (e.slice(u, S).toUpperCase() === "GROUP" && e[w] === "(") {
964
+ g = P(e, w), E = g;
965
+ continue;
966
+ }
967
+ }
968
+ if ((R === "FILTER" || R === "OVER") && e[u] === "(") {
969
+ b = b || R === "OVER", _ = _ || R === "FILTER", g = P(e, u);
970
+ continue;
971
+ }
972
+ break;
973
+ }
974
+ a.push({
975
+ name: d.toUpperCase(),
976
+ kind: Ne(d, C),
977
+ distinct: C,
978
+ windowed: b,
979
+ tokens: Wt(e.slice(p, g)),
980
+ span: { start: l, end: E, argumentStart: p + 1, argumentEnd: I },
981
+ argumentCount: x,
982
+ filtered: _
983
+ }), c += `@${a.length - 1}`, l = g;
984
+ continue;
985
+ }
986
+ c += e.slice(l, o), l = o;
987
+ continue;
988
+ }
989
+ /[\s0-9.,()+*/%<>=!|&^-]/.test(m) || (i = !1), c += m, l += 1;
990
+ }
991
+ return {
992
+ calls: a,
993
+ nestedAggregate: s,
994
+ windowed: a.some((m) => m.windowed),
995
+ tokensOutsideAggregates: r,
996
+ aggregateInputsComplete: i && Xt(c, n),
997
+ skeleton: c
998
+ };
999
+ }
1000
+ function Xt(e, n) {
1001
+ var m;
1002
+ const a = [];
1003
+ let r = 0;
1004
+ for (; r < e.length; ) {
1005
+ const o = e.slice(r), d = (m = /^(\s+|@\d+|#field_\d+|(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|'s'|[A-Za-z_][A-Za-z0-9_]*|<>|!=|<=|>=|[()+*/%,<>=-])/.exec(o)) == null ? void 0 : m[0];
1006
+ if (!d) return !1;
1007
+ if (r += d.length, d.startsWith("#")) {
1008
+ if (!n.has(d.slice(1))) return !1;
1009
+ a.push("@input");
1010
+ } else d.trim() && a.push(d.toUpperCase());
1011
+ }
1012
+ let s = 0;
1013
+ const c = (o) => a[s] === o && ++s > 0, i = () => {
1014
+ if (!l()) return !1;
1015
+ for (; ["+", "-", "*", "/", "%", "<", ">", "<=", ">=", "=", "<>", "!=", "AND", "OR", "IS"].includes(a[s]); )
1016
+ if (a[s++] === "IS" && c("NOT"), !l()) return !1;
1017
+ return !0;
1018
+ }, l = () => {
1019
+ const o = a[s];
1020
+ if (!o) return !1;
1021
+ if (["+", "-", "NOT"].includes(o))
1022
+ return s++, l();
1023
+ if (c("(")) return i() && c(")");
1024
+ if (c("CASE")) {
1025
+ if (a[s] !== "WHEN" && !i()) return !1;
1026
+ let d = 0;
1027
+ for (; c("WHEN"); ) {
1028
+ if (!i() || !c("THEN") || !i()) return !1;
1029
+ d++;
1030
+ }
1031
+ return c("ELSE") && !i() ? !1 : d > 0 && c("END");
1032
+ }
1033
+ if (o.startsWith("@") || o === "'S'" || ["NULL", "TRUE", "FALSE"].includes(o) || /^[0-9.]/.test(o))
1034
+ return s++, !0;
1035
+ if (!Bt.has(o) || (s++, !c("(") || !i())) return !1;
1036
+ if (["CAST", "TRY_CAST", "SAFE_CAST"].includes(o)) {
1037
+ if (!c("AS") || !Gt.has(a[s++]) || (c("PRECISION"), c("(") && (!/^\d+$/.test(a[s++] || "") || c(",") && !/^\d+$/.test(a[s++] || "") || !c(")"))))
1038
+ return !1;
1039
+ } else
1040
+ for (; c(","); ) if (!i()) return !1;
1041
+ return c(")");
1042
+ };
1043
+ return i() && s === a.length;
1044
+ }
1045
+ function $t(e) {
1046
+ const n = [];
1047
+ let a = 0;
1048
+ for (; a < e.length; ) {
1049
+ const r = e[a];
1050
+ if (/\s/.test(r)) {
1051
+ a += 1;
1052
+ continue;
1053
+ }
1054
+ if (r === "@") {
1055
+ const s = /^@(\d+)/.exec(e.slice(a));
1056
+ n.push({ type: "unit", unit: { kind: "call", index: Number(s[1]) } }), a += s[0].length;
1057
+ continue;
1058
+ }
1059
+ if (r === "#") {
1060
+ const s = /^#([A-Za-z_][A-Za-z0-9_]*)/.exec(e.slice(a));
1061
+ if (s) {
1062
+ n.push({ type: "unit", unit: { kind: "token", token: s[1] } }), a += s[0].length;
1063
+ continue;
1064
+ }
1065
+ }
1066
+ if (/[0-9.]/.test(r)) {
1067
+ const s = /^[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?/.exec(e.slice(a));
1068
+ if (s) {
1069
+ n.push({ type: "number" }), a += s[0].length;
1070
+ continue;
1071
+ }
1072
+ }
1073
+ if (r === "+" || r === "-" || r === "*" || r === "/") {
1074
+ n.push({ type: "op", value: r }), a += 1;
1075
+ continue;
1076
+ }
1077
+ if (r === "(") {
1078
+ n.push({ type: "open" }), a += 1;
1079
+ continue;
1080
+ }
1081
+ if (r === ")") {
1082
+ n.push({ type: "close" }), a += 1;
1083
+ continue;
1084
+ }
1085
+ n.push({ type: "other" }), a += 1;
1086
+ }
1087
+ return n;
1088
+ }
1089
+ function Kt(e) {
1090
+ const n = $t(e), a = n.some((o) => o.type === "op" && o.value === "/");
1091
+ if (n.some((o) => o.type === "other"))
1092
+ return { kind: "other", hasDivision: a };
1093
+ let r = 0, s = !0;
1094
+ const c = () => {
1095
+ let o = [], d, p = !0;
1096
+ for (; ; ) {
1097
+ if (!p) {
1098
+ const I = n[r];
1099
+ if (!(I && I.type === "op" && (I.value === "+" || I.value === "-"))) break;
1100
+ r += 1;
1101
+ }
1102
+ const g = i();
1103
+ if (!g) return null;
1104
+ d === void 0 ? d = g.degree : d !== g.degree && (s = !1), o = o.concat(g.units), p = !1;
1105
+ }
1106
+ return { degree: d ?? 0, units: o };
1107
+ }, i = () => {
1108
+ let o = l();
1109
+ if (!o) return null;
1110
+ for (; ; ) {
1111
+ const d = n[r];
1112
+ if (!(d && d.type === "op" && (d.value === "*" || d.value === "/"))) break;
1113
+ r += 1;
1114
+ const p = l();
1115
+ if (!p) return null;
1116
+ d.value === "/" && p.degree > 0 && (s = !1), o.degree + p.degree > 1 && (s = !1), o = { degree: o.degree + p.degree, units: o.units.concat(p.units) };
1117
+ }
1118
+ return o;
1119
+ }, l = () => {
1120
+ var d;
1121
+ const o = n[r];
1122
+ if (!o) return null;
1123
+ if (o.type === "op" && o.value === "-")
1124
+ return r += 1, l();
1125
+ if (o.type === "unit")
1126
+ return r += 1, { degree: 1, units: [o.unit] };
1127
+ if (o.type === "number")
1128
+ return r += 1, { degree: 0, units: [] };
1129
+ if (o.type === "open") {
1130
+ r += 1;
1131
+ const p = c();
1132
+ return !p || ((d = n[r]) == null ? void 0 : d.type) !== "close" ? null : (r += 1, p);
1133
+ }
1134
+ return null;
1135
+ }, m = c();
1136
+ return !m || r !== n.length ? { kind: "other", hasDivision: a } : m.units.length === 1 && m.degree === 1 && s && !a && n.filter((d) => d.type !== "open" && d.type !== "close").length === 1 ? { kind: "single", unit: m.units[0] } : s && m.degree === 1 ? { kind: "linear", units: m.units } : { kind: "other", hasDivision: a };
1137
+ }
1138
+ const Oe = /* @__PURE__ */ new Set([
1139
+ "min",
1140
+ "max",
1141
+ "count_distinct",
1142
+ "repeat_safe_other"
1143
+ ]);
1144
+ function X(e) {
1145
+ if (!(!e || !e.trim()))
1146
+ return Ne(e);
1147
+ }
1148
+ function xe(e) {
1149
+ switch (e) {
1150
+ case "count":
1151
+ case "sum":
1152
+ return { kind: "additive" };
1153
+ case "avg":
1154
+ return { kind: "decomposable_avg" };
1155
+ case "min":
1156
+ case "max":
1157
+ return { kind: "idempotent", fn: e };
1158
+ case "count_distinct":
1159
+ return { kind: "none", reason: "distinct" };
1160
+ case "median":
1161
+ return { kind: "none", reason: "median" };
1162
+ default:
1163
+ return { kind: "none", reason: "other" };
1164
+ }
1165
+ }
1166
+ function Zt(e) {
1167
+ var n, a;
1168
+ return ((n = e.derivedField) == null ? void 0 : n.computeStage) || ((a = e.calculatedFormula) == null ? void 0 : a.computeStage);
1169
+ }
1170
+ const Q = {
1171
+ stage: "aggregate",
1172
+ calls: [],
1173
+ windowed: !1,
1174
+ repeatSafe: !1,
1175
+ reaggregation: { kind: "none", reason: "unresolved" },
1176
+ outputType: "numeric",
1177
+ identity: "unresolved",
1178
+ unresolved: !0
1179
+ }, Pe = { ...Q, stage: "row" };
1180
+ function $(e) {
1181
+ return {
1182
+ stage: "row",
1183
+ outer: e,
1184
+ calls: [{ kind: e, distinct: e === "count_distinct" }],
1185
+ windowed: !1,
1186
+ repeatSafe: Oe.has(e),
1187
+ reaggregation: xe(e),
1188
+ outputType: e === "min" || e === "max" ? "input" : "numeric",
1189
+ identity: e,
1190
+ unresolved: !1
1191
+ };
1192
+ }
1193
+ function B(e, n) {
1194
+ var r;
1195
+ const a = (r = n.derivedField) == null ? void 0 : r.aggregationBehavior;
1196
+ return !a || e.unresolved ? e : a === "additive" ? e.reaggregation.kind === "additive" ? e : { ...e, reaggregation: { kind: "additive" } } : { ...e, reaggregation: { kind: "none", reason: "declared" } };
1197
+ }
1198
+ function Ht(e, n) {
1199
+ if (!e) return Q;
1200
+ if (typeof e.expression == "string" && e.expression.trim()) {
1201
+ const r = J(e, n + 1);
1202
+ return r === "row_input" ? "raw" : r.unresolved || r.stage === "aggregate" || r.outer ? r : "raw";
1203
+ }
1204
+ const a = X(e.aggregate);
1205
+ return a ? $(a) : "raw";
1206
+ }
1207
+ const Yt = 12;
1208
+ function J(e, n) {
1209
+ var R;
1210
+ if (n > Yt) return Q;
1211
+ const a = typeof e.expression == "string" ? e.expression.trim() : "";
1212
+ if (!a)
1213
+ return B(
1214
+ $(X(e.aggregate) ?? "sum"),
1215
+ e
1216
+ );
1217
+ const r = W(a), s = ((R = e.calculatedFormula) == null ? void 0 : R.inputFields) || [], c = (u) => {
1218
+ const S = /^field_(\d+)$/.exec(u);
1219
+ return S ? s[Number(S[1])] : void 0;
1220
+ }, i = /* @__PURE__ */ new Map();
1221
+ for (const u of r.tokensOutsideAggregates)
1222
+ i.has(u) || i.set(u, Ht(c(u), n));
1223
+ const l = r.calls.some(
1224
+ (u) => u.tokens.some((S) => {
1225
+ const w = c(S);
1226
+ if (!(w != null && w.expression)) return !1;
1227
+ const L = J(w, n + 1);
1228
+ return L !== "row_input" && (L.unresolved || L.stage === "aggregate");
1229
+ })
1230
+ ), m = Array.from(i.values()).filter(
1231
+ (u) => u !== "raw"
1232
+ ), o = Array.from(i.values()).some((u) => u === "raw"), d = r.calls.length > 0 || m.length > 0 || Zt(e) === "aggregate" || !!e.isPreAggregated, p = new Set(
1233
+ [...i].filter(
1234
+ ([u, S]) => S === "raw" ? !d && !!c(u) : !S.unresolved
1235
+ ).map(([u]) => u)
1236
+ ), g = W(a, p).aggregateInputsComplete;
1237
+ if (!d) {
1238
+ if (!g) return Pe;
1239
+ const u = X(e.aggregate);
1240
+ return u ? B($(u), e) : "row_input";
1241
+ }
1242
+ const I = !g || o || r.nestedAggregate || l || m.some((u) => u.unresolved) || r.calls.length === 0 && m.length === 0, E = [
1243
+ ...r.calls.map((u) => ({ kind: u.kind, distinct: u.distinct })),
1244
+ ...m.flatMap((u) => u.calls)
1245
+ ], T = r.windowed || m.some((u) => u.windowed), x = !I && !T && E.every((u) => Oe.has(u.kind)), C = (u) => {
1246
+ if (u.kind === "call") {
1247
+ const w = r.calls[u.index];
1248
+ return w ? xe(w.kind) : { kind: "none", reason: "unresolved" };
1249
+ }
1250
+ const S = i.get(u.token);
1251
+ return S && S !== "raw" ? S.reaggregation : { kind: "none", reason: "unresolved" };
1252
+ }, b = Kt(r.skeleton);
1253
+ let _, h, N = "numeric";
1254
+ if (I)
1255
+ _ = { kind: "none", reason: "unresolved" }, h = "unresolved";
1256
+ else if (T)
1257
+ _ = { kind: "none", reason: "window" }, h = "expression";
1258
+ else if (b.kind === "single")
1259
+ if (_ = C(b.unit), b.unit.kind === "call") {
1260
+ const u = r.calls[b.unit.index];
1261
+ h = u.kind, (u.kind === "min" || u.kind === "max") && (N = "input");
1262
+ } else {
1263
+ const u = i.get(b.unit.token);
1264
+ h = u.identity, N = u.outputType;
1265
+ }
1266
+ else b.kind === "linear" ? (_ = b.units.every((S) => C(S).kind === "additive") ? { kind: "additive" } : { kind: "none", reason: "other" }, h = "linear") : (_ = { kind: "none", reason: b.hasDivision ? "ratio" : "other" }, h = b.hasDivision ? "ratio" : "expression");
1267
+ return B(
1268
+ {
1269
+ stage: "aggregate",
1270
+ calls: E,
1271
+ windowed: T,
1272
+ repeatSafe: x,
1273
+ reaggregation: _,
1274
+ outputType: N,
1275
+ identity: h,
1276
+ unresolved: I
1277
+ },
1278
+ e
1279
+ );
1280
+ }
1281
+ function kn(e) {
1282
+ const n = J(e, 0);
1283
+ return n === "row_input" ? Pe : n;
1284
+ }
1285
+ const Qt = t.object({
1286
+ intent: Je,
1287
+ matrixWindowRequest: pe
1288
+ }).strict(), Jt = t.object({
1289
+ runtimeFilters: G.innerType().shape.filters,
1290
+ runtimeSorts: G.innerType().shape.sorts.optional()
1291
+ });
1292
+ function vn(e) {
1293
+ return Jt.parse(e);
1294
+ }
1295
+ const en = {
1296
+ // A window executes a governed statement set, not one compiled query.
1297
+ compiledQuery: t.never().optional(),
1298
+ intent: Qt.shape.intent,
1299
+ resultShape: t.literal("matrix"),
1300
+ result: Ae.optional(),
1301
+ metadata: t.object({ rowLimitExceeded: t.boolean(), matrixFailure: Y.optional() }).passthrough()
1302
+ }, tn = ve.extend(en), Tn = tn.superRefine((e, n) => {
1303
+ e.status === "failed" == !!e.result && n.addIssue({ code: "custom", message: "Only answered or partial Matrix execution carries a window." }), e.result && e.status === "partial" != e.result.window.failures.length > 0 && n.addIssue({ code: "custom", message: "Matrix execution status must match acquired window failures." });
1304
+ });
1305
+ export {
1306
+ lt as $,
1307
+ bn as A,
1308
+ An as B,
1309
+ xt as C,
1310
+ Pt as D,
1311
+ jt as E,
1312
+ In as F,
1313
+ Ft as G,
1314
+ Lt as H,
1315
+ qt as I,
1316
+ wn as J,
1317
+ Mt as K,
1318
+ Ne as L,
1319
+ W as M,
1320
+ Kt as N,
1321
+ kn as O,
1322
+ me as P,
1323
+ nt as Q,
1324
+ at as R,
1325
+ H as S,
1326
+ rn as T,
1327
+ sn as U,
1328
+ st as V,
1329
+ on as W,
1330
+ it as X,
1331
+ te as Y,
1332
+ ct as Z,
1333
+ cn as _,
1334
+ _n as a,
1335
+ ut as a0,
1336
+ dt as a1,
1337
+ ne as a2,
1338
+ Y as a3,
1339
+ mt as a4,
1340
+ Se as a5,
1341
+ pt as a6,
1342
+ ln as a7,
1343
+ un as a8,
1344
+ ht as a9,
1345
+ ft as aa,
1346
+ gt as ab,
1347
+ dn as ac,
1348
+ mn as ad,
1349
+ yt as ae,
1350
+ St as af,
1351
+ ae as ag,
1352
+ bt as ah,
1353
+ pn as ai,
1354
+ Jt as aj,
1355
+ vn as ak,
1356
+ Tn as al,
1357
+ Qt as am,
1358
+ It as b,
1359
+ Sn as c,
1360
+ _e as d,
1361
+ we as e,
1362
+ ke as f,
1363
+ hn as g,
1364
+ ve as h,
1365
+ Rt as i,
1366
+ _t as j,
1367
+ kt as k,
1368
+ vt as l,
1369
+ pe as m,
1370
+ Ae as n,
1371
+ Te as o,
1372
+ fn as p,
1373
+ Re as q,
1374
+ gn as r,
1375
+ At as s,
1376
+ Et as t,
1377
+ yn as u,
1378
+ Ee as v,
1379
+ Ct as w,
1380
+ se as x,
1381
+ z as y,
1382
+ oe as z
1383
+ };