react-semaphor 0.1.381 → 0.1.383

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