react-semaphor 0.1.368 → 0.1.370

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 (65) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +1 -1
  3. package/dist/brand-studio/index.cjs +5 -5
  4. package/dist/brand-studio/index.js +24 -23
  5. package/dist/chunks/{braces-Cc86y9Ov.js → braces-C3-w6xDL.js} +1 -1
  6. package/dist/chunks/{braces-CXvY9MwQ.js → braces-C8QqW4wu.js} +1 -1
  7. package/dist/chunks/{calendar-preferences-dialog-BOFlzOJg.js → calendar-preferences-dialog-6q51A6XC.js} +3 -3
  8. package/dist/chunks/{calendar-preferences-dialog-ZzwfJv2J.js → calendar-preferences-dialog-CUGzkNcE.js} +1 -1
  9. package/dist/chunks/{chevrons-up-down-CUZL1zaU.js → chevrons-up-down-CnCSGY02.js} +1 -1
  10. package/dist/chunks/{chevrons-up-down-qQMadOWA.js → chevrons-up-down-DSvLu4Ye.js} +1 -1
  11. package/dist/chunks/{dashboard-briefing-launcher-9-PCYMjR.js → dashboard-briefing-launcher-BEZnvIla.js} +1 -1
  12. package/dist/chunks/{dashboard-briefing-launcher-D2lBFqAd.js → dashboard-briefing-launcher-ptERmNJr.js} +176 -177
  13. package/dist/chunks/{dashboard-controls-D4bUHAjX.js → dashboard-controls-CGt6_hMf.js} +11 -11
  14. package/dist/chunks/{dashboard-controls-BIk094Ah.js → dashboard-controls-CqKC5oEk.js} +77 -77
  15. package/dist/chunks/{dashboard-json-DImOf512.js → dashboard-json-6SgPm_QW.js} +13 -14
  16. package/dist/chunks/dashboard-json-CYSbOdmE.js +1 -0
  17. package/dist/chunks/{edit-dashboard-visual-DTxkV6Fl.js → edit-dashboard-visual-ByQx_M2i.js} +8 -9
  18. package/dist/chunks/{edit-dashboard-visual-BHKlcqQR.js → edit-dashboard-visual-w6hKbjlw.js} +1 -1
  19. package/dist/chunks/index-BtqYNH_S.js +1361 -0
  20. package/dist/chunks/{index-BVEIk-rB.js → index-CPyEi9gS.js} +72498 -76193
  21. package/dist/chunks/{palette-DPuAc82h.js → palette-D-f4-82S.js} +1 -1
  22. package/dist/chunks/{palette-C1k347Tb.js → palette-DUGktM-M.js} +1 -1
  23. package/dist/chunks/{resource-management-panel-BeHceP2D.js → resource-management-panel-Bf8-3eUf.js} +1 -1
  24. package/dist/chunks/{resource-management-panel-BOfbSf48.js → resource-management-panel-mJ84NxzC.js} +152 -152
  25. package/dist/chunks/save-D3YYinDz.js +6 -0
  26. package/dist/chunks/save-kkBEBeLg.js +21 -0
  27. package/dist/chunks/{switch-xcWLtWs0.js → switch-Dkx2qEOr.js} +758 -776
  28. package/dist/chunks/{switch-C0S63HAv.js → switch-fIkmwzUt.js} +27 -32
  29. package/dist/chunks/{use-create-flow-overlay-state-B5FygfQL.js → use-create-flow-overlay-state-BfoXDDrd.js} +190 -189
  30. package/dist/chunks/use-create-flow-overlay-state-c6rCm36x.js +26 -0
  31. package/dist/chunks/{use-visual-utils-DxDE8S8M.js → use-visual-utils-C_c-aiqi.js} +1 -1
  32. package/dist/chunks/{use-visual-utils-CszWnFBW.js → use-visual-utils-NN0e3fBP.js} +13 -13
  33. package/dist/chunks/validation-DYL3ArlL.js +1 -0
  34. package/dist/chunks/validation-PPSpYtVf.js +900 -0
  35. package/dist/chunks/validators-CgxWT8UX.js +1 -0
  36. package/dist/chunks/validators-DBNa-eb1.js +1799 -0
  37. package/dist/dashboard/index.cjs +1 -1
  38. package/dist/dashboard/index.js +1 -1
  39. package/dist/dashboard-authoring/index.cjs +1 -1
  40. package/dist/dashboard-authoring/index.js +1 -1
  41. package/dist/data-app-builder/index.cjs +51 -1
  42. package/dist/data-app-builder/index.js +3666 -2
  43. package/dist/data-app-sdk/index.cjs +1 -1
  44. package/dist/data-app-sdk/index.js +661 -389
  45. package/dist/data-app-sdk-validation/index.cjs +1 -1
  46. package/dist/data-app-sdk-validation/index.js +4 -4
  47. package/dist/index.cjs +1 -1
  48. package/dist/index.js +14 -14
  49. package/dist/surfboard/index.cjs +1 -1
  50. package/dist/surfboard/index.js +2 -2
  51. package/dist/types/analytics-protocol.d.ts +472 -3
  52. package/dist/types/dashboard-assistant.d.ts +469 -3
  53. package/dist/types/dashboard-authoring.d.ts +170 -2
  54. package/dist/types/data-app-builder.d.ts +167 -2
  55. package/dist/types/data-app-sdk-validation.d.ts +576 -25
  56. package/dist/types/data-app-sdk.d.ts +655 -37
  57. package/dist/types/main.d.ts +167 -2
  58. package/package.json +1 -1
  59. package/dist/chunks/dashboard-json-Bo1kX6W1.js +0 -1
  60. package/dist/chunks/index-HjDeEytV.js +0 -1411
  61. package/dist/chunks/use-create-flow-overlay-state-DOXTbTcQ.js +0 -26
  62. package/dist/chunks/validation-CrUjNWby.js +0 -689
  63. package/dist/chunks/validation-DGl8wnTt.js +0 -1
  64. package/dist/chunks/validators-Dq5X4mp0.js +0 -1
  65. package/dist/chunks/validators-L0xEXtjf.js +0 -965
@@ -0,0 +1,900 @@
1
+ import { n as P, v as T } from "./validators-DBNa-eb1.js";
2
+ import { b, c as H, a as w } from "./source-identity-Dj3dryN9.js";
3
+ function A(e) {
4
+ var t;
5
+ const r = O(e);
6
+ return {
7
+ version: 1,
8
+ kind: "metric",
9
+ id: e.id,
10
+ label: e.label,
11
+ source: y(e),
12
+ metrics: r,
13
+ primaryMetric: z(e, r),
14
+ dateField: e.dateField ? a(e.dateField, "date") : void 0,
15
+ timeGrain: e.timeGrain,
16
+ dimensions: (t = e.dimensions) == null ? void 0 : t.map((i) => a(i, "dimension")),
17
+ comparison: te(e.comparison),
18
+ orderBy: e.orderBy ? {
19
+ field: a(e.orderBy.field),
20
+ direction: e.orderBy.direction
21
+ } : void 0,
22
+ inputs: u(e.inputs),
23
+ limit: e.limit
24
+ };
25
+ }
26
+ function B(e) {
27
+ var t;
28
+ return {
29
+ ...A(e),
30
+ ...e.timeWindow ? { timeWindow: e.timeWindow } : {},
31
+ ...(t = e.filters) != null && t.length ? { filters: e.filters } : {},
32
+ ...e.analysis ? { analysis: e.analysis } : {}
33
+ };
34
+ }
35
+ function Se(e) {
36
+ return {
37
+ ...e.chartTitle ? { chartTitle: e.chartTitle } : {},
38
+ ...e.chartType ? { chartType: e.chartType } : {},
39
+ ...e.driverMode ? { driverMode: e.driverMode } : {},
40
+ ...e.includePopulation !== void 0 ? { includePopulation: e.includePopulation } : {},
41
+ ...e.calendarContext ? { calendarContext: e.calendarContext } : {}
42
+ };
43
+ }
44
+ function z(e, r) {
45
+ if (!e.primaryMetric)
46
+ return r[0] || { name: "", role: "measure" };
47
+ const t = a(e.primaryMetric, "measure"), i = Q(t, r), o = i.length === 1 ? i[0] : void 0;
48
+ return o ? M(t, o) : t;
49
+ }
50
+ function O(e) {
51
+ const r = [];
52
+ for (const t of e.metrics.map(
53
+ (i) => a(i, "measure")
54
+ )) {
55
+ if (!t.name)
56
+ continue;
57
+ const i = r.findIndex(
58
+ (o) => D(o, t)
59
+ );
60
+ if (i === -1) {
61
+ r.push(t);
62
+ continue;
63
+ }
64
+ r[i] = M(
65
+ r[i],
66
+ t
67
+ );
68
+ }
69
+ return r;
70
+ }
71
+ function D(e, r) {
72
+ return b(e, r) && c(e) === c(r);
73
+ }
74
+ function j(e, r) {
75
+ return c(r) === c(e);
76
+ }
77
+ function K(e, r) {
78
+ return r.name !== e.name || e.source && !b(r, e) ? !1 : j(e, r);
79
+ }
80
+ function Q(e, r) {
81
+ const t = r.filter(
82
+ (i) => K(e, i)
83
+ );
84
+ return e.aggregate !== void 0, t;
85
+ }
86
+ function c(e) {
87
+ return (e.aggregate || "SUM").toUpperCase();
88
+ }
89
+ function M(e, r) {
90
+ if (e.aggregate && r.aggregate && e.aggregate !== r.aggregate)
91
+ throw new Error(
92
+ `Metric "${e.name}" was requested with conflicting aggregate semantics: ${e.aggregate} and ${r.aggregate}.`
93
+ );
94
+ return {
95
+ ...H(e, r),
96
+ aggregate: e.aggregate || r.aggregate
97
+ };
98
+ }
99
+ function E(e) {
100
+ var t;
101
+ if ("sort" in e)
102
+ throw new Error(
103
+ "semaphor.records supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet."
104
+ );
105
+ if (!re(e))
106
+ throw new Error("semaphor.records needs at least one field.");
107
+ const r = N(e.fields);
108
+ return {
109
+ version: 1,
110
+ kind: "records",
111
+ id: e.id,
112
+ label: e.label,
113
+ source: y(e),
114
+ fields: r,
115
+ dateField: e.dateField ? a(e.dateField, "date") : void 0,
116
+ timeGrain: e.timeGrain,
117
+ ...e.timeWindow ? { timeWindow: e.timeWindow } : {},
118
+ ...(t = e.filters) != null && t.length ? { filters: e.filters } : {},
119
+ orderBy: e.orderBy ? {
120
+ field: a(e.orderBy.field),
121
+ direction: e.orderBy.direction
122
+ } : void 0,
123
+ inputs: u(e.inputs),
124
+ limit: e.limit,
125
+ ...e.pagination ? { pagination: e.pagination } : {}
126
+ };
127
+ }
128
+ function N(e) {
129
+ return e.map((r) => {
130
+ const t = a(r);
131
+ if (!t.role)
132
+ throw new Error(
133
+ `semaphor.records field "${t.name}" needs an explicit role.`
134
+ );
135
+ return t;
136
+ });
137
+ }
138
+ function V(e) {
139
+ return {
140
+ version: 1,
141
+ kind: "inputOptions",
142
+ id: e.id,
143
+ label: e.label,
144
+ source: y(e),
145
+ field: a(e.field, "dimension"),
146
+ search: e.search,
147
+ limit: e.limit
148
+ };
149
+ }
150
+ function L(e) {
151
+ var r;
152
+ return {
153
+ version: 1,
154
+ kind: "sql",
155
+ id: e.id,
156
+ label: e.label,
157
+ source: e.source,
158
+ sql: e.sql,
159
+ ...e.defaultParameters ? { defaultParameters: e.defaultParameters } : {},
160
+ ...e.pythonCode ? { pythonCode: e.pythonCode } : {},
161
+ ...(r = e.fields) != null && r.length ? { fields: e.fields.map((t) => a(t)) } : {},
162
+ inputs: u(e.inputs),
163
+ limit: e.limit,
164
+ ...e.pagination ? { pagination: e.pagination } : {},
165
+ rationale: e.rationale
166
+ };
167
+ }
168
+ function W(e) {
169
+ var r, t;
170
+ return {
171
+ version: 1,
172
+ kind: "matrix",
173
+ id: e.id,
174
+ label: e.label,
175
+ source: y(e),
176
+ rows: e.rows.map((i) => g(i, "dimension")),
177
+ ...e.columns ? {
178
+ columns: e.columns.map(
179
+ (i) => g(i, "dimension")
180
+ )
181
+ } : {},
182
+ values: e.values.map(U),
183
+ ...(r = e.filters) != null && r.length ? { filters: e.filters } : {},
184
+ inputs: u(e.inputs),
185
+ ...e.totals ? { totals: e.totals } : {},
186
+ ...(t = e.sort) != null && t.length ? { sort: e.sort } : {},
187
+ ...e.expansion ? { expansion: e.expansion } : {},
188
+ ...e.layout ? { layout: e.layout } : {},
189
+ ...e.displayLimits ? { displayLimits: e.displayLimits } : {}
190
+ };
191
+ }
192
+ function g(e, r) {
193
+ return G(e) ? {
194
+ ...e,
195
+ field: a(e.field, r)
196
+ } : {
197
+ field: a(e, r)
198
+ };
199
+ }
200
+ function U(e) {
201
+ return J(e) ? {
202
+ ...e,
203
+ field: a(e.field, "measure")
204
+ } : {
205
+ field: a(e, "measure"),
206
+ aggregate: e.aggregate
207
+ };
208
+ }
209
+ function G(e) {
210
+ return "field" in e;
211
+ }
212
+ function J(e) {
213
+ return "field" in e;
214
+ }
215
+ function X(e) {
216
+ if ("toAnalyticsInput" in e) {
217
+ const n = e.toAnalyticsInput();
218
+ return {
219
+ inputId: n.inputId,
220
+ kind: n.kind,
221
+ ...n.controlRole ? { controlRole: n.controlRole } : {},
222
+ ...n.operator ? { operator: n.operator } : {},
223
+ ...n.field ? { field: n.field } : {}
224
+ };
225
+ }
226
+ if ("id" in e) {
227
+ const n = x(e);
228
+ return {
229
+ inputId: n.inputId,
230
+ kind: n.kind,
231
+ ...n.controlRole ? { controlRole: n.controlRole } : {},
232
+ ...n.operator ? { operator: n.operator } : {},
233
+ ...n.field ? { field: n.field } : {}
234
+ };
235
+ }
236
+ const r = "kind" in e ? e.kind : void 0, t = "operator" in e ? $(e.operator, e.inputId) : void 0, i = "controlRole" in e ? e.controlRole : "role" in e ? e.role : void 0, o = Y(i) ? i : void 0;
237
+ return {
238
+ inputId: e.inputId,
239
+ ...r ? { kind: r } : {},
240
+ ...o ? { controlRole: o } : {},
241
+ ...t ? { operator: t } : {},
242
+ ...e.field ? { field: e.field } : {}
243
+ };
244
+ }
245
+ function Y(e) {
246
+ return e === "grain" || e === "metric" || e === "dimension" || e === "aggregation" || e === "sqlParam";
247
+ }
248
+ function be(e) {
249
+ const r = u(e);
250
+ return r.length > 0 ? r : void 0;
251
+ }
252
+ function Z(e) {
253
+ return (e || []).map(ee);
254
+ }
255
+ function we(e) {
256
+ return Z(e).filter((r) => r.isActive);
257
+ }
258
+ function x(e) {
259
+ if (e.kind === "filter") {
260
+ const r = $(e.operator, e.id);
261
+ return {
262
+ inputId: e.id,
263
+ kind: e.kind,
264
+ label: e.label,
265
+ field: a(e.field, "dimension"),
266
+ operator: r || "in"
267
+ };
268
+ }
269
+ return {
270
+ inputId: e.id,
271
+ kind: e.kind,
272
+ label: e.label,
273
+ controlRole: e.role
274
+ };
275
+ }
276
+ function Ae(e = []) {
277
+ return e.map(
278
+ (r) => typeof r == "object" ? r : {
279
+ label: String(r),
280
+ value: r
281
+ }
282
+ );
283
+ }
284
+ function v(e) {
285
+ return e == null ? !1 : Array.isArray(e) ? e.length > 0 : typeof e == "string" ? e.trim().length > 0 : !0;
286
+ }
287
+ function ee(e) {
288
+ if ("toAnalyticsInput" in e)
289
+ return e.toAnalyticsInput();
290
+ if ("kind" in e && "isActive" in e)
291
+ return e;
292
+ if ("id" in e) {
293
+ const r = x(e), t = Object.prototype.hasOwnProperty.call(e, "value") ? e.value : e.defaultValue;
294
+ return {
295
+ inputId: r.inputId,
296
+ kind: r.kind,
297
+ label: r.label,
298
+ ...r.field ? { field: r.field } : {},
299
+ ...r.operator ? { operator: r.operator } : {},
300
+ ...r.controlRole ? { controlRole: r.controlRole } : {},
301
+ value: t,
302
+ isActive: v(t)
303
+ };
304
+ }
305
+ return {
306
+ ...e,
307
+ kind: "filter",
308
+ isActive: v(
309
+ e.value
310
+ ),
311
+ value: e.value
312
+ };
313
+ }
314
+ function y(e) {
315
+ return e.source;
316
+ }
317
+ function re(e) {
318
+ var r;
319
+ return !!((r = e.fields) != null && r.length);
320
+ }
321
+ function a(e, r) {
322
+ return {
323
+ ...e,
324
+ role: e.role || r
325
+ };
326
+ }
327
+ function u(e) {
328
+ return (e || []).map(X);
329
+ }
330
+ function te(e) {
331
+ if (e)
332
+ return e;
333
+ }
334
+ function $(e, r) {
335
+ if (e === void 0)
336
+ return;
337
+ const t = P(e);
338
+ if (!t)
339
+ throw new Error(
340
+ `useSemaphorInput "${r}" uses unsupported filter operator "${e}".`
341
+ );
342
+ return t;
343
+ }
344
+ function ie(e, r = {}) {
345
+ const t = r.pathPrefix || "analysisOptions";
346
+ if (e === void 0)
347
+ return { ok: !0 };
348
+ if (!e || typeof e != "object" || Array.isArray(e))
349
+ return s(
350
+ t,
351
+ "Data App analysis options must be an object."
352
+ );
353
+ const i = e, o = {};
354
+ if (i.chartTitle !== void 0) {
355
+ if (typeof i.chartTitle != "string")
356
+ return s(
357
+ `${t}.chartTitle`,
358
+ 'Data App analysis option "chartTitle" must be a string.'
359
+ );
360
+ o.chartTitle = i.chartTitle;
361
+ }
362
+ if (i.chartType !== void 0) {
363
+ if (typeof i.chartType != "string")
364
+ return s(
365
+ `${t}.chartType`,
366
+ 'Data App analysis option "chartType" must be a string.'
367
+ );
368
+ o.chartType = i.chartType;
369
+ }
370
+ if (i.driverMode !== void 0) {
371
+ if (!ne(i.driverMode))
372
+ return s(
373
+ `${t}.driverMode`,
374
+ 'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.'
375
+ );
376
+ o.driverMode = i.driverMode;
377
+ }
378
+ if (i.includePopulation !== void 0) {
379
+ if (typeof i.includePopulation != "boolean")
380
+ return s(
381
+ `${t}.includePopulation`,
382
+ 'Data App analysis option "includePopulation" must be a boolean.'
383
+ );
384
+ o.includePopulation = i.includePopulation;
385
+ }
386
+ if (i.calendarContext !== void 0) {
387
+ const n = se(
388
+ i.calendarContext,
389
+ {
390
+ pathPrefix: `${t}.calendarContext`,
391
+ validateTimezone: r.validateTimezone
392
+ }
393
+ );
394
+ if (!n.ok)
395
+ return n;
396
+ o.calendarContext = n.calendarContext;
397
+ }
398
+ return { ok: !0, analysisOptions: o };
399
+ }
400
+ function Me(e) {
401
+ const r = e.queries.map(
402
+ (o, n) => oe(o, n, {
403
+ fieldCatalogs: e.fieldCatalogs || [],
404
+ requireFieldCatalog: !!e.requireFieldCatalog,
405
+ validateTimezone: e.validateTimezone
406
+ })
407
+ ), t = r.flatMap((o) => o.diagnostics), i = r.map((o) => o.executionResult);
408
+ return {
409
+ ok: t.every((o) => o.severity !== "error"),
410
+ diagnostics: t,
411
+ queries: r,
412
+ intents: r.flatMap(
413
+ (o) => o.intent ? [o.intent] : []
414
+ ),
415
+ executionResults: i
416
+ };
417
+ }
418
+ function oe(e, r, t) {
419
+ const i = `queries.${r}`;
420
+ try {
421
+ const o = de(e), n = qe(e, o), d = T(o), l = [
422
+ ...ye({
423
+ querySpec: e,
424
+ queryId: n,
425
+ intent: o,
426
+ pathPrefix: i
427
+ }),
428
+ ...d.errors.map(
429
+ (p) => q(p, {
430
+ queryHook: e.queryHook,
431
+ queryId: n,
432
+ pathPrefix: i,
433
+ severity: "error",
434
+ intent: o
435
+ })
436
+ ),
437
+ ...d.warnings.map(
438
+ (p) => q(p, {
439
+ queryHook: e.queryHook,
440
+ queryId: n,
441
+ pathPrefix: i,
442
+ severity: "warning",
443
+ intent: o
444
+ })
445
+ ),
446
+ ...ue({
447
+ querySpec: e,
448
+ queryId: n,
449
+ intent: o,
450
+ pathPrefix: i,
451
+ fieldCatalogs: t.fieldCatalogs,
452
+ requireFieldCatalog: t.requireFieldCatalog
453
+ }),
454
+ ...me({
455
+ querySpec: e,
456
+ queryId: n,
457
+ intent: o,
458
+ pathPrefix: i,
459
+ validateTimezone: t.validateTimezone
460
+ })
461
+ ], f = ve(d, l);
462
+ return {
463
+ queryHook: e.queryHook,
464
+ queryId: n,
465
+ intent: o,
466
+ diagnostics: l,
467
+ executionResult: S({
468
+ intent: o,
469
+ validation: f,
470
+ diagnostics: l
471
+ })
472
+ };
473
+ } catch (o) {
474
+ const n = {
475
+ severity: "error",
476
+ code: "invalid_query_spec",
477
+ message: o instanceof Error ? o.message : String(o),
478
+ path: i,
479
+ queryHook: e.queryHook,
480
+ queryId: F(e.spec)
481
+ }, d = R([n]);
482
+ return {
483
+ queryHook: e.queryHook,
484
+ queryId: n.queryId,
485
+ diagnostics: [n],
486
+ executionResult: S({
487
+ validation: d,
488
+ diagnostics: [n]
489
+ })
490
+ };
491
+ }
492
+ }
493
+ function s(e, r) {
494
+ return {
495
+ ok: !1,
496
+ issues: [
497
+ {
498
+ code: "invalid_analysis_option",
499
+ message: r,
500
+ path: e
501
+ }
502
+ ]
503
+ };
504
+ }
505
+ function _(e) {
506
+ return !!(e && typeof e == "object" && !Array.isArray(e));
507
+ }
508
+ function ne(e) {
509
+ return e === "absolute_delta" || e === "largest_negative" || e === "largest_positive" || e === "positive_and_negative" || e === "all";
510
+ }
511
+ function ae(e) {
512
+ return e.trim().length > 0 && !Number.isNaN(Date.parse(e));
513
+ }
514
+ function se(e, r) {
515
+ var f;
516
+ if (!e || typeof e != "object" || Array.isArray(e))
517
+ return s(
518
+ r.pathPrefix,
519
+ 'Data App analysis option "calendarContext" must be an object.'
520
+ );
521
+ const t = e, i = t.tz, o = t.weekStart, n = t.anchor, d = n && typeof n == "object" && !Array.isArray(n) ? n.iso : void 0, l = typeof i == "string" ? ((f = r.validateTimezone) == null ? void 0 : f.call(r, i)) ?? i : null;
522
+ return l ? typeof o != "number" || !Number.isInteger(o) || o < 0 || o > 6 ? s(
523
+ `${r.pathPrefix}.weekStart`,
524
+ 'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'
525
+ ) : n !== "now" && !(typeof d == "string" && ae(d)) ? s(
526
+ `${r.pathPrefix}.anchor`,
527
+ 'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'
528
+ ) : {
529
+ ok: !0,
530
+ calendarContext: {
531
+ tz: l,
532
+ weekStart: o,
533
+ anchor: n
534
+ }
535
+ } : s(
536
+ `${r.pathPrefix}.tz`,
537
+ 'Data App analysis option "calendarContext.tz" must be a valid timezone string.'
538
+ );
539
+ }
540
+ function de(e) {
541
+ return le(e.spec);
542
+ }
543
+ function le(e) {
544
+ if (!_(e))
545
+ throw new Error("useSemaphorQuery spec must be an object.");
546
+ if (e.queryKind === "metric")
547
+ return A(e);
548
+ if (e.queryKind === "analysis")
549
+ return B(e);
550
+ if (e.queryKind === "records")
551
+ return E(e);
552
+ if (e.queryKind === "sql")
553
+ return L(e);
554
+ if (e.queryKind === "matrix")
555
+ return W(e);
556
+ if (e.queryKind === "inputOptions")
557
+ return V(e);
558
+ throw new Error(
559
+ "useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, sql, or matrix."
560
+ );
561
+ }
562
+ function ue(e) {
563
+ if (e.intent.kind === "sql")
564
+ return [];
565
+ if (e.fieldCatalogs.length === 0 && !e.requireFieldCatalog)
566
+ return [];
567
+ const r = he(
568
+ e.fieldCatalogs,
569
+ e.intent.source
570
+ );
571
+ return r ? [
572
+ ...fe({
573
+ ...e,
574
+ catalog: r
575
+ }),
576
+ ...ce({
577
+ ...e,
578
+ catalog: r
579
+ })
580
+ ] : [
581
+ {
582
+ severity: "error",
583
+ code: "invalid_source_ref",
584
+ message: `Source ref for ${e.querySpec.queryHook} does not match a visible Semaphor source.`,
585
+ path: `${e.pathPrefix}.spec.source`,
586
+ queryHook: e.querySpec.queryHook,
587
+ queryId: e.queryId,
588
+ intentId: e.intent.id,
589
+ source: e.intent.source
590
+ }
591
+ ];
592
+ }
593
+ function fe(e) {
594
+ return pe(e.intent).flatMap(({ field: r, path: t }) => C(e.catalog, r, e.intent.source) ? [] : [
595
+ {
596
+ severity: "error",
597
+ code: "missing_field",
598
+ message: `Field "${r.name}" is not visible on the selected Semaphor source.`,
599
+ path: `${e.pathPrefix}.${t}`,
600
+ queryHook: e.querySpec.queryHook,
601
+ queryId: e.queryId,
602
+ intentId: e.intent.id,
603
+ source: m(r, e.intent.source),
604
+ field: r
605
+ }
606
+ ]);
607
+ }
608
+ function ce(e) {
609
+ return ("inputs" in e.intent ? e.intent.inputs || [] : []).flatMap((t, i) => {
610
+ if (!t.field)
611
+ return [];
612
+ const o = m(t.field, e.intent.source);
613
+ return w(o, e.intent.source) ? C(e.catalog, t.field, e.intent.source) ? [] : [
614
+ {
615
+ severity: "error",
616
+ code: "missing_field",
617
+ message: `Input "${t.inputId}" references field "${t.field.name}", which is not visible on the selected Semaphor source.`,
618
+ path: `${e.pathPrefix}.spec.inputs.${i}.field`,
619
+ queryHook: e.querySpec.queryHook,
620
+ queryId: e.queryId,
621
+ intentId: e.intent.id,
622
+ source: o,
623
+ field: t.field
624
+ }
625
+ ] : [
626
+ {
627
+ severity: "error",
628
+ code: "unsupported_input_filter_composition",
629
+ message: `Input "${t.inputId}" filters a different Semaphor source than the query. Cross-source Data App inputs are not supported yet.`,
630
+ path: `${e.pathPrefix}.spec.inputs.${i}.field`,
631
+ queryHook: e.querySpec.queryHook,
632
+ queryId: e.queryId,
633
+ intentId: e.intent.id,
634
+ source: o,
635
+ field: t.field
636
+ }
637
+ ];
638
+ });
639
+ }
640
+ function me(e) {
641
+ if (e.querySpec.spec.queryKind !== "analysis")
642
+ return [];
643
+ const r = ie(
644
+ e.querySpec.spec,
645
+ {
646
+ pathPrefix: `${e.pathPrefix}.spec`,
647
+ validateTimezone: e.validateTimezone
648
+ }
649
+ );
650
+ return r.ok ? [] : r.issues.map((t) => ({
651
+ severity: "error",
652
+ code: t.code,
653
+ message: t.message,
654
+ path: t.path,
655
+ queryHook: e.querySpec.queryHook,
656
+ queryId: e.queryId,
657
+ intentId: e.intent.id,
658
+ source: e.intent.source
659
+ }));
660
+ }
661
+ function ye(e) {
662
+ return e.querySpec.spec.queryKind !== "sql" ? [] : _(e.querySpec.spec) ? Object.prototype.hasOwnProperty.call(e.querySpec.spec, "parameters") ? [
663
+ {
664
+ severity: "error",
665
+ code: "deprecated_sql_parameters",
666
+ message: "semaphor.sql uses defaultParameters for static SQL param(...) fallback values. The legacy parameters field is not supported.",
667
+ path: `${e.pathPrefix}.spec.parameters`,
668
+ queryHook: e.querySpec.queryHook,
669
+ queryId: e.queryId,
670
+ intentId: e.intent.id
671
+ }
672
+ ] : [] : [];
673
+ }
674
+ function pe(e) {
675
+ return e.kind === "metric" ? [
676
+ ...e.metrics.map((r, t) => ({
677
+ field: r,
678
+ path: `spec.metrics.${t}`
679
+ })),
680
+ ...e.primaryMetric ? [{ field: e.primaryMetric, path: "spec.primaryMetric" }] : [],
681
+ ...e.dateField ? [{ field: e.dateField, path: "spec.dateField" }] : [],
682
+ ...(e.dimensions || []).map((r, t) => ({
683
+ field: r,
684
+ path: `spec.dimensions.${t}`
685
+ })),
686
+ ...e.orderBy ? [{ field: e.orderBy.field, path: "spec.orderBy.field" }] : [],
687
+ ...(e.filters || []).map((r, t) => ({
688
+ field: r.field,
689
+ path: `spec.filters.${t}.field`
690
+ }))
691
+ ] : e.kind === "records" ? [
692
+ ...e.fields.map((r, t) => ({
693
+ field: r,
694
+ path: `spec.fields.${t}`
695
+ })),
696
+ ...e.dateField ? [{ field: e.dateField, path: "spec.dateField" }] : [],
697
+ ...e.orderBy ? [{ field: e.orderBy.field, path: "spec.orderBy.field" }] : [],
698
+ ...(e.filters || []).map((r, t) => ({
699
+ field: r.field,
700
+ path: `spec.filters.${t}.field`
701
+ }))
702
+ ] : e.kind === "inputOptions" ? [{ field: e.field, path: "spec.field" }] : e.kind === "matrix" ? [
703
+ ...e.rows.map((r, t) => ({
704
+ field: r.field,
705
+ path: `spec.rows.${t}.field`
706
+ })),
707
+ ...e.rows.flatMap(
708
+ (r, t) => {
709
+ var i;
710
+ return ((i = r.sortBy) == null ? void 0 : i.by.kind) === "field" ? [
711
+ {
712
+ field: r.sortBy.by.field,
713
+ path: `spec.rows.${t}.sortBy.by.field`
714
+ }
715
+ ] : [];
716
+ }
717
+ ),
718
+ ...(e.columns || []).map((r, t) => ({
719
+ field: r.field,
720
+ path: `spec.columns.${t}.field`
721
+ })),
722
+ ...(e.columns || []).flatMap(
723
+ (r, t) => {
724
+ var i;
725
+ return ((i = r.sortBy) == null ? void 0 : i.by.kind) === "field" ? [
726
+ {
727
+ field: r.sortBy.by.field,
728
+ path: `spec.columns.${t}.sortBy.by.field`
729
+ }
730
+ ] : [];
731
+ }
732
+ ),
733
+ ...e.values.map((r, t) => ({
734
+ field: r.field,
735
+ path: `spec.values.${t}.field`
736
+ })),
737
+ ...(e.sort || []).flatMap(
738
+ (r, t) => r.by.kind === "field" ? [
739
+ {
740
+ field: r.by.field,
741
+ path: `spec.sort.${t}.by.field`
742
+ }
743
+ ] : []
744
+ ),
745
+ ...(e.filters || []).map((r, t) => ({
746
+ field: r.field,
747
+ path: `spec.filters.${t}.field`
748
+ }))
749
+ ] : [];
750
+ }
751
+ function he(e, r) {
752
+ return e.find((t) => h(t, r));
753
+ }
754
+ function C(e, r, t) {
755
+ const i = m(r, t);
756
+ if (h(e, i))
757
+ return e.fields.find(
758
+ (o) => ge(o, r) && h(
759
+ e,
760
+ m(o, e.source)
761
+ )
762
+ );
763
+ }
764
+ function h(e, r) {
765
+ return [e.source, ...e.sourceAliases || []].some(
766
+ (t) => w(t, r)
767
+ );
768
+ }
769
+ function m(e, r) {
770
+ return e.source || r;
771
+ }
772
+ function ge(e, r) {
773
+ return !!(e.name && r.name && e.name === r.name);
774
+ }
775
+ function q(e, r) {
776
+ return {
777
+ severity: r.severity,
778
+ code: e.code || "invalid_analytics_intent",
779
+ message: e.message,
780
+ path: e.path ? `${r.pathPrefix}.spec.${e.path}` : r.pathPrefix,
781
+ queryHook: r.queryHook,
782
+ queryId: r.queryId,
783
+ intentId: r.intent.id,
784
+ source: r.intent.source
785
+ };
786
+ }
787
+ function ve(e, r) {
788
+ const t = R(r);
789
+ return {
790
+ ok: t.ok && e.ok,
791
+ errors: k([
792
+ ...e.errors,
793
+ ...t.errors
794
+ ]),
795
+ warnings: k([
796
+ ...e.warnings,
797
+ ...t.warnings
798
+ ]),
799
+ repairHints: [
800
+ ...e.repairHints,
801
+ ...t.repairHints
802
+ ]
803
+ };
804
+ }
805
+ function R(e) {
806
+ const r = e.filter((i) => i.severity === "error").map(I), t = e.filter((i) => i.severity === "warning").map(I);
807
+ return {
808
+ ok: r.length === 0,
809
+ errors: r,
810
+ warnings: t,
811
+ repairHints: r.map((i) => {
812
+ var o, n;
813
+ return {
814
+ code: i.code,
815
+ message: i.message,
816
+ fieldRole: i.fieldRole,
817
+ invalidField: (o = i.repairHint) == null ? void 0 : o.invalidField,
818
+ recommendedNextStep: ((n = i.repairHint) == null ? void 0 : n.recommendedNextStep) || "Update the Data App SDK query spec to use visible Semaphor source and field refs."
819
+ };
820
+ })
821
+ };
822
+ }
823
+ function I(e) {
824
+ var r;
825
+ return {
826
+ code: e.code,
827
+ message: e.message,
828
+ path: e.path,
829
+ fieldRole: e.code === "invalid_source_ref" ? "source" : void 0,
830
+ repairHint: {
831
+ code: e.code,
832
+ message: e.message,
833
+ invalidField: (r = e.field) == null ? void 0 : r.name,
834
+ fieldRole: e.code === "invalid_source_ref" ? "source" : void 0,
835
+ recommendedNextStep: e.code === "unsupported_input_filter_composition" ? "Use an input field from the same Semaphor source as the query, or split the query into separate source-scoped queries." : "Update the query spec to use a visible Semaphor source and field ref."
836
+ }
837
+ };
838
+ }
839
+ function k(e) {
840
+ const r = /* @__PURE__ */ new Set();
841
+ return e.filter((t) => {
842
+ const i = `${t.code}:${t.path || ""}:${t.message}`;
843
+ return r.has(i) ? !1 : (r.add(i), !0);
844
+ });
845
+ }
846
+ function S(e) {
847
+ var t, i;
848
+ const r = e.diagnostics.filter(
849
+ (o) => o.severity === "error"
850
+ );
851
+ return {
852
+ intentId: (t = e.intent) == null ? void 0 : t.id,
853
+ status: r.length ? "failed" : "answered",
854
+ resultShape: (i = e.intent) == null ? void 0 : i.kind,
855
+ intent: e.intent,
856
+ validation: e.validation,
857
+ coverage: {
858
+ answeredObligations: r.length ? [] : ["query_spec_validation"],
859
+ missingObligations: r.length ? ["query_spec_validation"] : [],
860
+ warnings: e.validation.warnings
861
+ },
862
+ missingFields: r.filter((o) => o.code === "missing_field").flatMap(
863
+ (o) => {
864
+ var n;
865
+ return (n = o.field) != null && n.name ? [o.field.name] : [];
866
+ }
867
+ ),
868
+ warnings: e.diagnostics.filter((o) => o.severity === "warning").map((o) => o.message),
869
+ metadata: {
870
+ validationKind: "data_app_sdk_query_spec"
871
+ }
872
+ };
873
+ }
874
+ function qe(e, r) {
875
+ return r.id || F(e.spec);
876
+ }
877
+ function F(e) {
878
+ if (!e || typeof e != "object" || !("id" in e))
879
+ return;
880
+ const r = e.id;
881
+ return typeof r == "string" && r.trim() ? r : void 0;
882
+ }
883
+ export {
884
+ W as a,
885
+ L as b,
886
+ V as c,
887
+ E as d,
888
+ Se as e,
889
+ B as f,
890
+ A as g,
891
+ x as h,
892
+ v as i,
893
+ X as j,
894
+ be as k,
895
+ Z as l,
896
+ ie as m,
897
+ Ae as n,
898
+ we as t,
899
+ Me as v
900
+ };