react-semaphor 0.1.369 → 0.1.371

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 (53) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +40 -38
  3. package/dist/chunks/{calendar-preferences-dialog-6q51A6XC.js → calendar-preferences-dialog-ClBAkMmF.js} +1 -1
  4. package/dist/chunks/{calendar-preferences-dialog-CUGzkNcE.js → calendar-preferences-dialog-Dn6o2r2Y.js} +1 -1
  5. package/dist/chunks/{dashboard-briefing-launcher-BEZnvIla.js → dashboard-briefing-launcher-BO-kXtEd.js} +1 -1
  6. package/dist/chunks/{dashboard-briefing-launcher-ptERmNJr.js → dashboard-briefing-launcher-D3Xfc_26.js} +3 -3
  7. package/dist/chunks/{dashboard-controls-CqKC5oEk.js → dashboard-controls-B3sdy_Zx.js} +3 -3
  8. package/dist/chunks/{dashboard-controls-CGt6_hMf.js → dashboard-controls-DcXMFgGR.js} +1 -1
  9. package/dist/chunks/{dashboard-json-6SgPm_QW.js → dashboard-json-BWfkEy48.js} +1 -1
  10. package/dist/chunks/{dashboard-json-CYSbOdmE.js → dashboard-json-CFURS_OR.js} +1 -1
  11. package/dist/chunks/{edit-dashboard-visual-w6hKbjlw.js → edit-dashboard-visual-BD2AJLiT.js} +1 -1
  12. package/dist/chunks/{edit-dashboard-visual-ByQx_M2i.js → edit-dashboard-visual-DjdhKiP2.js} +3 -3
  13. package/dist/chunks/{index-CPyEi9gS.js → index-C0Qnfr_7.js} +5 -4
  14. package/dist/chunks/{index-BtqYNH_S.js → index-DlLvzmJF.js} +2 -2
  15. package/dist/chunks/{resource-management-panel-Bf8-3eUf.js → resource-management-panel-DytUMSGA.js} +1 -1
  16. package/dist/chunks/{resource-management-panel-mJ84NxzC.js → resource-management-panel-YvIfaphX.js} +2 -2
  17. package/dist/chunks/{use-create-flow-overlay-state-BfoXDDrd.js → use-create-flow-overlay-state-BETXykC9.js} +2 -2
  18. package/dist/chunks/{use-create-flow-overlay-state-c6rCm36x.js → use-create-flow-overlay-state-CwIG1Ekp.js} +1 -1
  19. package/dist/chunks/{use-visual-utils-NN0e3fBP.js → use-visual-utils-Bk135OgA.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-C_c-aiqi.js → use-visual-utils-BzFjIykb.js} +1 -1
  21. package/dist/chunks/{validation-nOPr0mTk.js → validation-CQFpcSSP.js} +446 -246
  22. package/dist/chunks/validation-D4Zz6WPD.js +1 -0
  23. package/dist/chunks/validators-CuKnUZFO.js +2171 -0
  24. package/dist/chunks/validators-DHee9kM2.js +1 -0
  25. package/dist/dashboard/index.cjs +1 -1
  26. package/dist/dashboard/index.js +1 -1
  27. package/dist/dashboard-authoring/index.cjs +1 -1
  28. package/dist/dashboard-authoring/index.js +1 -1
  29. package/dist/data-app-builder/index.cjs +1 -1
  30. package/dist/data-app-builder/index.js +1 -1
  31. package/dist/data-app-sdk/index.cjs +1 -1
  32. package/dist/data-app-sdk/index.js +261 -183
  33. package/dist/data-app-sdk-validation/index.cjs +1 -1
  34. package/dist/data-app-sdk-validation/index.js +4 -3
  35. package/dist/index.cjs +1 -1
  36. package/dist/index.js +5 -5
  37. package/dist/surfboard/index.cjs +1 -1
  38. package/dist/surfboard/index.js +2 -2
  39. package/dist/types/analytics-protocol.d.ts +542 -2
  40. package/dist/types/dashboard-assistant.d.ts +508 -4
  41. package/dist/types/dashboard-authoring.d.ts +217 -3
  42. package/dist/types/dashboard.d.ts +67 -2
  43. package/dist/types/data-app-builder.d.ts +197 -1
  44. package/dist/types/data-app-sdk-validation.d.ts +520 -6
  45. package/dist/types/data-app-sdk.d.ts +543 -8
  46. package/dist/types/main.d.ts +215 -3
  47. package/dist/types/shared.d.ts +66 -2
  48. package/dist/types/surfboard.d.ts +67 -2
  49. package/dist/types/types.d.ts +67 -2
  50. package/package.json +1 -1
  51. package/dist/chunks/validation-Dsf7PydY.js +0 -1
  52. package/dist/chunks/validators-CVuWOHYv.js +0 -1032
  53. package/dist/chunks/validators-oc8qtP4q.js +0 -1
@@ -1,38 +1,40 @@
1
- import { n as T, v as x } from "./validators-CVuWOHYv.js";
2
- import { b as S, c as H, a as b } from "./source-identity-Dj3dryN9.js";
3
- function w(e) {
4
- var t;
5
- const r = B(e);
1
+ import { n as z, c as D } from "./validators-CuKnUZFO.js";
2
+ import { n as O } from "./catalog-field-grounding-DoEBOXQd.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);
6
7
  return {
7
8
  version: 1,
8
9
  kind: "metric",
9
10
  id: e.id,
10
11
  label: e.label,
11
- source: h(e),
12
+ source: p(e),
12
13
  metrics: r,
13
- primaryMetric: z(e, r),
14
+ primaryMetric: K(e, r),
14
15
  dateField: e.dateField ? a(e.dateField, "date") : void 0,
15
16
  timeGrain: e.timeGrain,
16
17
  dimensions: (t = e.dimensions) == null ? void 0 : t.map((o) => a(o, "dimension")),
17
- comparison: X(e.comparison),
18
+ comparison: se(e.comparison),
18
19
  orderBy: e.orderBy ? {
19
20
  field: a(e.orderBy.field),
20
21
  direction: e.orderBy.direction
21
22
  } : void 0,
22
- inputs: m(e.inputs),
23
- limit: e.limit
23
+ inputs: y(e.inputs),
24
+ limit: e.limit,
25
+ ...(i = e.derivedFields) != null && i.length ? { derivedFields: e.derivedFields } : {}
24
26
  };
25
27
  }
26
- function F(e) {
28
+ function E(e) {
27
29
  var t;
28
30
  return {
29
- ...w(e),
31
+ ...x(e),
30
32
  ...e.timeWindow ? { timeWindow: e.timeWindow } : {},
31
33
  ...(t = e.filters) != null && t.length ? { filters: e.filters } : {},
32
34
  ...e.analysis ? { analysis: e.analysis } : {}
33
35
  };
34
36
  }
35
- function ge(e) {
37
+ function Re(e) {
36
38
  return {
37
39
  ...e.chartTitle ? { chartTitle: e.chartTitle } : {},
38
40
  ...e.chartType ? { chartType: e.chartType } : {},
@@ -41,76 +43,76 @@ function ge(e) {
41
43
  ...e.calendarContext ? { calendarContext: e.calendarContext } : {}
42
44
  };
43
45
  }
44
- function z(e, r) {
46
+ function K(e, r) {
45
47
  if (!e.primaryMetric)
46
48
  return r[0] || { name: "", role: "measure" };
47
- const t = a(e.primaryMetric, "measure"), o = K(t, r), i = o.length === 1 ? o[0] : void 0;
48
- return i ? A(t, i) : t;
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;
49
51
  }
50
- function B(e) {
52
+ function Q(e) {
51
53
  const r = [];
52
54
  for (const t of e.metrics.map(
53
- (o) => a(o, "measure")
55
+ (i) => a(i, "measure")
54
56
  )) {
55
57
  if (!t.name)
56
58
  continue;
57
- const o = r.findIndex(
58
- (i) => O(i, t)
59
+ const i = r.findIndex(
60
+ (o) => N(o, t)
59
61
  );
60
- if (o === -1) {
62
+ if (i === -1) {
61
63
  r.push(t);
62
64
  continue;
63
65
  }
64
- r[o] = A(
65
- r[o],
66
+ r[i] = F(
67
+ r[i],
66
68
  t
67
69
  );
68
70
  }
69
71
  return r;
70
72
  }
71
- function O(e, r) {
72
- return S(e, r) && f(e) === f(r);
73
+ function N(e, r) {
74
+ return M(e, r) && h(e) === h(r);
73
75
  }
74
- function D(e, r) {
75
- return f(r) === f(e);
76
+ function V(e, r) {
77
+ return h(r) === h(e);
76
78
  }
77
- function j(e, r) {
78
- return r.name !== e.name || e.source && !S(r, e) ? !1 : D(e, r);
79
+ function W(e, r) {
80
+ return r.name !== e.name || e.source && !M(r, e) ? !1 : V(e, r);
79
81
  }
80
- function K(e, r) {
82
+ function L(e, r) {
81
83
  const t = r.filter(
82
- (o) => j(e, o)
84
+ (i) => W(e, i)
83
85
  );
84
86
  return e.aggregate !== void 0, t;
85
87
  }
86
- function f(e) {
88
+ function h(e) {
87
89
  return (e.aggregate || "SUM").toUpperCase();
88
90
  }
89
- function A(e, r) {
91
+ function F(e, r) {
90
92
  if (e.aggregate && r.aggregate && e.aggregate !== r.aggregate)
91
93
  throw new Error(
92
94
  `Metric "${e.name}" was requested with conflicting aggregate semantics: ${e.aggregate} and ${r.aggregate}.`
93
95
  );
94
96
  return {
95
- ...H(e, r),
97
+ ...j(e, r),
96
98
  aggregate: e.aggregate || r.aggregate
97
99
  };
98
100
  }
99
- function Q(e) {
100
- var t;
101
+ function U(e) {
102
+ var t, i;
101
103
  if ("sort" in e)
102
104
  throw new Error(
103
105
  "semaphor.records supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet."
104
106
  );
105
- if (!J(e))
107
+ if (!ae(e))
106
108
  throw new Error("semaphor.records needs at least one field.");
107
- const r = E(e.fields);
109
+ const r = G(e.fields);
108
110
  return {
109
111
  version: 1,
110
112
  kind: "records",
111
113
  id: e.id,
112
114
  label: e.label,
113
- source: h(e),
115
+ source: p(e),
114
116
  fields: r,
115
117
  dateField: e.dateField ? a(e.dateField, "date") : void 0,
116
118
  timeGrain: e.timeGrain,
@@ -120,12 +122,13 @@ function Q(e) {
120
122
  field: a(e.orderBy.field),
121
123
  direction: e.orderBy.direction
122
124
  } : void 0,
123
- inputs: m(e.inputs),
125
+ inputs: y(e.inputs),
124
126
  limit: e.limit,
125
- ...e.pagination ? { pagination: e.pagination } : {}
127
+ ...e.pagination ? { pagination: e.pagination } : {},
128
+ ...(i = e.derivedFields) != null && i.length ? { derivedFields: e.derivedFields } : {}
126
129
  };
127
130
  }
128
- function E(e) {
131
+ function G(e) {
129
132
  return e.map((r) => {
130
133
  const t = a(r);
131
134
  if (!t.role)
@@ -135,19 +138,21 @@ function E(e) {
135
138
  return t;
136
139
  });
137
140
  }
138
- function N(e) {
141
+ function J(e) {
142
+ var r;
139
143
  return {
140
144
  version: 1,
141
145
  kind: "inputOptions",
142
146
  id: e.id,
143
147
  label: e.label,
144
- source: h(e),
148
+ source: p(e),
145
149
  field: a(e.field, "dimension"),
146
150
  search: e.search,
147
- limit: e.limit
151
+ limit: e.limit,
152
+ ...(r = e.derivedFields) != null && r.length ? { derivedFields: e.derivedFields } : {}
148
153
  };
149
154
  }
150
- function W(e) {
155
+ function X(e) {
151
156
  var r;
152
157
  return {
153
158
  version: 1,
@@ -159,13 +164,60 @@ function W(e) {
159
164
  ...e.defaultParameters ? { defaultParameters: e.defaultParameters } : {},
160
165
  ...e.pythonCode ? { pythonCode: e.pythonCode } : {},
161
166
  ...(r = e.fields) != null && r.length ? { fields: e.fields.map((t) => a(t)) } : {},
162
- inputs: m(e.inputs),
167
+ inputs: y(e.inputs),
163
168
  limit: e.limit,
164
169
  ...e.pagination ? { pagination: e.pagination } : {},
165
170
  rationale: e.rationale
166
171
  };
167
172
  }
168
- function U(e) {
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) {
169
221
  if ("toAnalyticsInput" in e) {
170
222
  const n = e.toAnalyticsInput();
171
223
  return {
@@ -177,7 +229,7 @@ function U(e) {
177
229
  };
178
230
  }
179
231
  if ("id" in e) {
180
- const n = M(e);
232
+ const n = C(e);
181
233
  return {
182
234
  inputId: n.inputId,
183
235
  kind: n.kind,
@@ -186,31 +238,31 @@ function U(e) {
186
238
  ...n.field ? { field: n.field } : {}
187
239
  };
188
240
  }
189
- const r = "kind" in e ? e.kind : void 0, t = "operator" in e ? _(e.operator, e.inputId) : void 0, o = "controlRole" in e ? e.controlRole : "role" in e ? e.role : void 0, i = V(o) ? o : void 0;
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;
190
242
  return {
191
243
  inputId: e.inputId,
192
244
  ...r ? { kind: r } : {},
193
- ...i ? { controlRole: i } : {},
245
+ ...o ? { controlRole: o } : {},
194
246
  ...t ? { operator: t } : {},
195
247
  ...e.field ? { field: e.field } : {}
196
248
  };
197
249
  }
198
- function V(e) {
250
+ function ie(e) {
199
251
  return e === "grain" || e === "metric" || e === "dimension" || e === "aggregation" || e === "sqlParam";
200
252
  }
201
- function ve(e) {
202
- const r = m(e);
253
+ function He(e) {
254
+ const r = y(e);
203
255
  return r.length > 0 ? r : void 0;
204
256
  }
205
- function G(e) {
206
- return (e || []).map(L);
257
+ function oe(e) {
258
+ return (e || []).map(ne);
207
259
  }
208
- function qe(e) {
209
- return G(e).filter((r) => r.isActive);
260
+ function Te(e) {
261
+ return oe(e).filter((r) => r.isActive);
210
262
  }
211
- function M(e) {
263
+ function C(e) {
212
264
  if (e.kind === "filter") {
213
- const r = _(e.operator, e.id);
265
+ const r = R(e.operator, e.id);
214
266
  return {
215
267
  inputId: e.id,
216
268
  kind: e.kind,
@@ -226,7 +278,7 @@ function M(e) {
226
278
  controlRole: e.role
227
279
  };
228
280
  }
229
- function Ie(e = []) {
281
+ function Pe(e = []) {
230
282
  return e.map(
231
283
  (r) => typeof r == "object" ? r : {
232
284
  label: String(r),
@@ -234,16 +286,16 @@ function Ie(e = []) {
234
286
  }
235
287
  );
236
288
  }
237
- function g(e) {
289
+ function S(e) {
238
290
  return e == null ? !1 : Array.isArray(e) ? e.length > 0 : typeof e == "string" ? e.trim().length > 0 : !0;
239
291
  }
240
- function L(e) {
292
+ function ne(e) {
241
293
  if ("toAnalyticsInput" in e)
242
294
  return e.toAnalyticsInput();
243
295
  if ("kind" in e && "isActive" in e)
244
296
  return e;
245
297
  if ("id" in e) {
246
- const r = M(e), t = Object.prototype.hasOwnProperty.call(e, "value") ? e.value : e.defaultValue;
298
+ const r = C(e), t = Object.prototype.hasOwnProperty.call(e, "value") ? e.value : e.defaultValue;
247
299
  return {
248
300
  inputId: r.inputId,
249
301
  kind: r.kind,
@@ -252,22 +304,22 @@ function L(e) {
252
304
  ...r.operator ? { operator: r.operator } : {},
253
305
  ...r.controlRole ? { controlRole: r.controlRole } : {},
254
306
  value: t,
255
- isActive: g(t)
307
+ isActive: S(t)
256
308
  };
257
309
  }
258
310
  return {
259
311
  ...e,
260
312
  kind: "filter",
261
- isActive: g(
313
+ isActive: S(
262
314
  e.value
263
315
  ),
264
316
  value: e.value
265
317
  };
266
318
  }
267
- function h(e) {
319
+ function p(e) {
268
320
  return e.source;
269
321
  }
270
- function J(e) {
322
+ function ae(e) {
271
323
  var r;
272
324
  return !!((r = e.fields) != null && r.length);
273
325
  }
@@ -277,68 +329,68 @@ function a(e, r) {
277
329
  role: e.role || r
278
330
  };
279
331
  }
280
- function m(e) {
281
- return (e || []).map(U);
332
+ function y(e) {
333
+ return (e || []).map(te);
282
334
  }
283
- function X(e) {
335
+ function se(e) {
284
336
  if (e)
285
337
  return e;
286
338
  }
287
- function _(e, r) {
339
+ function R(e, r) {
288
340
  if (e === void 0)
289
341
  return;
290
- const t = T(e);
342
+ const t = z(e);
291
343
  if (!t)
292
344
  throw new Error(
293
345
  `useSemaphorInput "${r}" uses unsupported filter operator "${e}".`
294
346
  );
295
347
  return t;
296
348
  }
297
- function Y(e, r = {}) {
349
+ function de(e, r = {}) {
298
350
  const t = r.pathPrefix || "analysisOptions";
299
351
  if (e === void 0)
300
352
  return { ok: !0 };
301
353
  if (!e || typeof e != "object" || Array.isArray(e))
302
- return s(
354
+ return u(
303
355
  t,
304
356
  "Data App analysis options must be an object."
305
357
  );
306
- const o = e, i = {};
307
- if (o.chartTitle !== void 0) {
308
- if (typeof o.chartTitle != "string")
309
- return s(
358
+ const i = e, o = {};
359
+ if (i.chartTitle !== void 0) {
360
+ if (typeof i.chartTitle != "string")
361
+ return u(
310
362
  `${t}.chartTitle`,
311
363
  'Data App analysis option "chartTitle" must be a string.'
312
364
  );
313
- i.chartTitle = o.chartTitle;
365
+ o.chartTitle = i.chartTitle;
314
366
  }
315
- if (o.chartType !== void 0) {
316
- if (typeof o.chartType != "string")
317
- return s(
367
+ if (i.chartType !== void 0) {
368
+ if (typeof i.chartType != "string")
369
+ return u(
318
370
  `${t}.chartType`,
319
371
  'Data App analysis option "chartType" must be a string.'
320
372
  );
321
- i.chartType = o.chartType;
373
+ o.chartType = i.chartType;
322
374
  }
323
- if (o.driverMode !== void 0) {
324
- if (!ee(o.driverMode))
325
- return s(
375
+ if (i.driverMode !== void 0) {
376
+ if (!ue(i.driverMode))
377
+ return u(
326
378
  `${t}.driverMode`,
327
379
  'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.'
328
380
  );
329
- i.driverMode = o.driverMode;
381
+ o.driverMode = i.driverMode;
330
382
  }
331
- if (o.includePopulation !== void 0) {
332
- if (typeof o.includePopulation != "boolean")
333
- return s(
383
+ if (i.includePopulation !== void 0) {
384
+ if (typeof i.includePopulation != "boolean")
385
+ return u(
334
386
  `${t}.includePopulation`,
335
387
  'Data App analysis option "includePopulation" must be a boolean.'
336
388
  );
337
- i.includePopulation = o.includePopulation;
389
+ o.includePopulation = i.includePopulation;
338
390
  }
339
- if (o.calendarContext !== void 0) {
340
- const n = te(
341
- o.calendarContext,
391
+ if (i.calendarContext !== void 0) {
392
+ const n = ce(
393
+ i.calendarContext,
342
394
  {
343
395
  pathPrefix: `${t}.calendarContext`,
344
396
  validateTimezone: r.validateTimezone
@@ -346,104 +398,104 @@ function Y(e, r = {}) {
346
398
  );
347
399
  if (!n.ok)
348
400
  return n;
349
- i.calendarContext = n.calendarContext;
401
+ o.calendarContext = n.calendarContext;
350
402
  }
351
- return { ok: !0, analysisOptions: i };
403
+ return { ok: !0, analysisOptions: o };
352
404
  }
353
- function ke(e) {
405
+ function Be(e) {
354
406
  const r = e.queries.map(
355
- (i, n) => Z(i, n, {
407
+ (o, n) => le(o, n, {
356
408
  fieldCatalogs: e.fieldCatalogs || [],
357
409
  requireFieldCatalog: !!e.requireFieldCatalog,
358
410
  validateTimezone: e.validateTimezone
359
411
  })
360
- ), t = r.flatMap((i) => i.diagnostics), o = r.map((i) => i.executionResult);
412
+ ), t = r.flatMap((o) => o.diagnostics), i = r.map((o) => o.executionResult);
361
413
  return {
362
- ok: t.every((i) => i.severity !== "error"),
414
+ ok: t.every((o) => o.severity !== "error"),
363
415
  diagnostics: t,
364
416
  queries: r,
365
417
  intents: r.flatMap(
366
- (i) => i.intent ? [i.intent] : []
418
+ (o) => o.intent ? [o.intent] : []
367
419
  ),
368
- executionResults: o
420
+ executionResults: i
369
421
  };
370
422
  }
371
- function Z(e, r, t) {
372
- const o = `queries.${r}`;
423
+ function le(e, r, t) {
424
+ const i = `queries.${r}`;
373
425
  try {
374
- const i = ie(e), n = ye(e, i), d = x(i), l = [
375
- ...le({
426
+ const o = me(e), n = Me(e, o), s = D(o), d = [
427
+ ...Ie({
376
428
  querySpec: e,
377
429
  queryId: n,
378
- intent: i,
379
- pathPrefix: o
430
+ intent: o,
431
+ pathPrefix: i
380
432
  }),
381
- ...d.errors.map(
382
- (y) => v(y, {
433
+ ...s.errors.map(
434
+ (c) => $(c, {
383
435
  queryHook: e.queryHook,
384
436
  queryId: n,
385
- pathPrefix: o,
437
+ pathPrefix: i,
386
438
  severity: "error",
387
- intent: i
439
+ intent: o
388
440
  })
389
441
  ),
390
- ...d.warnings.map(
391
- (y) => v(y, {
442
+ ...s.warnings.map(
443
+ (c) => $(c, {
392
444
  queryHook: e.queryHook,
393
445
  queryId: n,
394
- pathPrefix: o,
446
+ pathPrefix: i,
395
447
  severity: "warning",
396
- intent: i
448
+ intent: o
397
449
  })
398
450
  ),
399
- ...ne({
451
+ ...he({
400
452
  querySpec: e,
401
453
  queryId: n,
402
- intent: i,
403
- pathPrefix: o,
454
+ intent: o,
455
+ pathPrefix: i,
404
456
  fieldCatalogs: t.fieldCatalogs,
405
457
  requireFieldCatalog: t.requireFieldCatalog
406
458
  }),
407
- ...de({
459
+ ...qe({
408
460
  querySpec: e,
409
461
  queryId: n,
410
- intent: i,
411
- pathPrefix: o,
462
+ intent: o,
463
+ pathPrefix: i,
412
464
  validateTimezone: t.validateTimezone
413
465
  })
414
- ], u = me(d, l);
466
+ ], l = _e(s, d);
415
467
  return {
416
468
  queryHook: e.queryHook,
417
469
  queryId: n,
418
- intent: i,
419
- diagnostics: l,
420
- executionResult: k({
421
- intent: i,
422
- validation: u,
423
- diagnostics: l
470
+ intent: o,
471
+ diagnostics: d,
472
+ executionResult: _({
473
+ intent: o,
474
+ validation: l,
475
+ diagnostics: d
424
476
  })
425
477
  };
426
- } catch (i) {
478
+ } catch (o) {
427
479
  const n = {
428
480
  severity: "error",
429
481
  code: "invalid_query_spec",
430
- message: i instanceof Error ? i.message : String(i),
431
- path: o,
482
+ message: o instanceof Error ? o.message : String(o),
483
+ path: i,
432
484
  queryHook: e.queryHook,
433
- queryId: P(e.spec)
434
- }, d = R([n]);
485
+ queryId: B(e.spec)
486
+ }, s = P([n]);
435
487
  return {
436
488
  queryHook: e.queryHook,
437
489
  queryId: n.queryId,
438
490
  diagnostics: [n],
439
- executionResult: k({
440
- validation: d,
491
+ executionResult: _({
492
+ validation: s,
441
493
  diagnostics: [n]
442
494
  })
443
495
  };
444
496
  }
445
497
  }
446
- function s(e, r) {
498
+ function u(e, r) {
447
499
  return {
448
500
  ok: !1,
449
501
  issues: [
@@ -455,94 +507,169 @@ function s(e, r) {
455
507
  ]
456
508
  };
457
509
  }
458
- function C(e) {
510
+ function H(e) {
459
511
  return !!(e && typeof e == "object" && !Array.isArray(e));
460
512
  }
461
- function ee(e) {
513
+ function ue(e) {
462
514
  return e === "absolute_delta" || e === "largest_negative" || e === "largest_positive" || e === "positive_and_negative" || e === "all";
463
515
  }
464
- function re(e) {
516
+ function fe(e) {
465
517
  return e.trim().length > 0 && !Number.isNaN(Date.parse(e));
466
518
  }
467
- function te(e, r) {
468
- var u;
519
+ function ce(e, r) {
520
+ var l;
469
521
  if (!e || typeof e != "object" || Array.isArray(e))
470
- return s(
522
+ return u(
471
523
  r.pathPrefix,
472
524
  'Data App analysis option "calendarContext" must be an object.'
473
525
  );
474
- const t = e, o = t.tz, i = t.weekStart, n = t.anchor, d = n && typeof n == "object" && !Array.isArray(n) ? n.iso : void 0, l = typeof o == "string" ? ((u = r.validateTimezone) == null ? void 0 : u.call(r, o)) ?? o : null;
475
- return l ? typeof i != "number" || !Number.isInteger(i) || i < 0 || i > 6 ? s(
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(
476
528
  `${r.pathPrefix}.weekStart`,
477
529
  'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'
478
- ) : n !== "now" && !(typeof d == "string" && re(d)) ? s(
530
+ ) : n !== "now" && !(typeof s == "string" && fe(s)) ? u(
479
531
  `${r.pathPrefix}.anchor`,
480
532
  'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'
481
533
  ) : {
482
534
  ok: !0,
483
535
  calendarContext: {
484
- tz: l,
485
- weekStart: i,
536
+ tz: d,
537
+ weekStart: o,
486
538
  anchor: n
487
539
  }
488
- } : s(
540
+ } : u(
489
541
  `${r.pathPrefix}.tz`,
490
542
  'Data App analysis option "calendarContext.tz" must be a valid timezone string.'
491
543
  );
492
544
  }
493
- function ie(e) {
494
- return oe(e.spec);
545
+ function me(e) {
546
+ return ye(e.spec);
495
547
  }
496
- function oe(e) {
497
- if (!C(e))
548
+ function ye(e) {
549
+ if (!H(e))
498
550
  throw new Error("useSemaphorQuery spec must be an object.");
499
551
  if (e.queryKind === "metric")
500
- return w(e);
552
+ return x(e);
501
553
  if (e.queryKind === "analysis")
502
- return F(e);
554
+ return E(e);
503
555
  if (e.queryKind === "records")
504
- return Q(e);
556
+ return U(e);
505
557
  if (e.queryKind === "sql")
506
- return W(e);
558
+ return X(e);
559
+ if (e.queryKind === "matrix")
560
+ return Y(e);
507
561
  if (e.queryKind === "inputOptions")
508
- return N(e);
562
+ return J(e);
509
563
  throw new Error(
510
- "useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, or sql."
564
+ "useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, sql, or matrix."
511
565
  );
512
566
  }
513
- function ne(e) {
567
+ function he(e) {
514
568
  if (e.intent.kind === "sql")
515
569
  return [];
516
570
  if (e.fieldCatalogs.length === 0 && !e.requireFieldCatalog)
517
571
  return [];
518
- const r = fe(
572
+ const r = Se(
519
573
  e.fieldCatalogs,
520
574
  e.intent.source
521
575
  );
522
- return r ? [
523
- ...ae({
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({
524
602
  ...e,
525
- catalog: r
603
+ catalog: i
526
604
  }),
527
- ...se({
605
+ ...ve({
528
606
  ...e,
529
- catalog: r
607
+ catalog: i
530
608
  })
531
- ] : [
532
- {
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({
533
619
  severity: "error",
534
- code: "invalid_source_ref",
535
- message: `Source ref for ${e.querySpec.queryHook} does not match a visible Semaphor source.`,
536
- path: `${e.pathPrefix}.spec.source`,
620
+ code: "duplicate_derived_field",
621
+ message: `Derived field "${o.name}" is declared more than once.`,
622
+ path: `${s}.name`,
537
623
  queryHook: e.querySpec.queryHook,
538
624
  queryId: e.queryId,
539
625
  intentId: e.intent.id,
540
626
  source: e.intent.source
541
- }
542
- ];
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;
543
670
  }
544
- function ae(e) {
545
- return ue(e.intent).flatMap(({ field: r, path: t }) => $(e.catalog, r, e.intent.source) ? [] : [
671
+ function ge(e) {
672
+ return ke(e.intent).flatMap(({ field: r, path: t }) => I(e.catalog, r, e.intent.source) ? [] : [
546
673
  {
547
674
  severity: "error",
548
675
  code: "missing_field",
@@ -551,26 +678,26 @@ function ae(e) {
551
678
  queryHook: e.querySpec.queryHook,
552
679
  queryId: e.queryId,
553
680
  intentId: e.intent.id,
554
- source: c(r, e.intent.source),
681
+ source: m(r, e.intent.source),
555
682
  field: r
556
683
  }
557
684
  ]);
558
685
  }
559
- function se(e) {
560
- return ("inputs" in e.intent ? e.intent.inputs || [] : []).flatMap((t, o) => {
686
+ function ve(e) {
687
+ return ("inputs" in e.intent ? e.intent.inputs || [] : []).flatMap((t, i) => {
561
688
  if (!t.field)
562
689
  return [];
563
- const i = c(t.field, e.intent.source);
564
- return b(i, e.intent.source) ? $(e.catalog, t.field, e.intent.source) ? [] : [
690
+ const o = m(t.field, e.intent.source);
691
+ return q(o, e.intent.source) ? I(e.catalog, t.field, e.intent.source) ? [] : [
565
692
  {
566
693
  severity: "error",
567
694
  code: "missing_field",
568
695
  message: `Input "${t.inputId}" references field "${t.field.name}", which is not visible on the selected Semaphor source.`,
569
- path: `${e.pathPrefix}.spec.inputs.${o}.field`,
696
+ path: `${e.pathPrefix}.spec.inputs.${i}.field`,
570
697
  queryHook: e.querySpec.queryHook,
571
698
  queryId: e.queryId,
572
699
  intentId: e.intent.id,
573
- source: i,
700
+ source: o,
574
701
  field: t.field
575
702
  }
576
703
  ] : [
@@ -578,20 +705,20 @@ function se(e) {
578
705
  severity: "error",
579
706
  code: "unsupported_input_filter_composition",
580
707
  message: `Input "${t.inputId}" filters a different Semaphor source than the query. Cross-source Data App inputs are not supported yet.`,
581
- path: `${e.pathPrefix}.spec.inputs.${o}.field`,
708
+ path: `${e.pathPrefix}.spec.inputs.${i}.field`,
582
709
  queryHook: e.querySpec.queryHook,
583
710
  queryId: e.queryId,
584
711
  intentId: e.intent.id,
585
- source: i,
712
+ source: o,
586
713
  field: t.field
587
714
  }
588
715
  ];
589
716
  });
590
717
  }
591
- function de(e) {
718
+ function qe(e) {
592
719
  if (e.querySpec.spec.queryKind !== "analysis")
593
720
  return [];
594
- const r = Y(
721
+ const r = de(
595
722
  e.querySpec.spec,
596
723
  {
597
724
  pathPrefix: `${e.pathPrefix}.spec`,
@@ -609,8 +736,8 @@ function de(e) {
609
736
  source: e.intent.source
610
737
  }));
611
738
  }
612
- function le(e) {
613
- return e.querySpec.spec.queryKind !== "sql" ? [] : C(e.querySpec.spec) ? Object.prototype.hasOwnProperty.call(e.querySpec.spec, "parameters") ? [
739
+ function Ie(e) {
740
+ return e.querySpec.spec.queryKind !== "sql" ? [] : H(e.querySpec.spec) ? Object.prototype.hasOwnProperty.call(e.querySpec.spec, "parameters") ? [
614
741
  {
615
742
  severity: "error",
616
743
  code: "deprecated_sql_parameters",
@@ -622,7 +749,7 @@ function le(e) {
622
749
  }
623
750
  ] : [] : [];
624
751
  }
625
- function ue(e) {
752
+ function ke(e) {
626
753
  return e.kind === "metric" ? [
627
754
  ...e.metrics.map((r, t) => ({
628
755
  field: r,
@@ -650,33 +777,105 @@ function ue(e) {
650
777
  field: r.field,
651
778
  path: `spec.filters.${t}.field`
652
779
  }))
653
- ] : e.kind === "inputOptions" ? [{ field: e.field, path: "spec.field" }] : [];
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
+ ] : [];
654
828
  }
655
- function fe(e, r) {
656
- return e.find((t) => p(t, r));
829
+ function Se(e, r) {
830
+ return e.find((t) => v(t, r));
657
831
  }
658
- function $(e, r, t) {
659
- const o = c(r, t);
660
- if (p(e, o))
832
+ function I(e, r, t) {
833
+ const i = m(r, t);
834
+ if (v(e, i))
661
835
  return e.fields.find(
662
- (i) => ce(i, r) && p(
836
+ (o) => Ae(o, r) && v(
663
837
  e,
664
- c(i, e.source)
838
+ m(o, e.source)
665
839
  )
666
840
  );
667
841
  }
668
- function p(e, r) {
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) {
669
868
  return [e.source, ...e.sourceAliases || []].some(
670
- (t) => b(t, r)
869
+ (t) => q(t, r)
671
870
  );
672
871
  }
673
- function c(e, r) {
872
+ function m(e, r) {
674
873
  return e.source || r;
675
874
  }
676
- function ce(e, r) {
875
+ function Ae(e, r) {
677
876
  return !!(e.name && r.name && e.name === r.name);
678
877
  }
679
- function v(e, r) {
878
+ function $(e, r) {
680
879
  return {
681
880
  severity: r.severity,
682
881
  code: e.code || "invalid_analytics_intent",
@@ -688,15 +887,15 @@ function v(e, r) {
688
887
  source: r.intent.source
689
888
  };
690
889
  }
691
- function me(e, r) {
692
- const t = R(r);
890
+ function _e(e, r) {
891
+ const t = P(r);
693
892
  return {
694
893
  ok: t.ok && e.ok,
695
- errors: I([
894
+ errors: A([
696
895
  ...e.errors,
697
896
  ...t.errors
698
897
  ]),
699
- warnings: I([
898
+ warnings: A([
700
899
  ...e.warnings,
701
900
  ...t.warnings
702
901
  ]),
@@ -706,25 +905,25 @@ function me(e, r) {
706
905
  ]
707
906
  };
708
907
  }
709
- function R(e) {
710
- const r = e.filter((o) => o.severity === "error").map(q), t = e.filter((o) => o.severity === "warning").map(q);
908
+ function P(e) {
909
+ const r = e.filter((i) => i.severity === "error").map(w), t = e.filter((i) => i.severity === "warning").map(w);
711
910
  return {
712
911
  ok: r.length === 0,
713
912
  errors: r,
714
913
  warnings: t,
715
- repairHints: r.map((o) => {
716
- var i, n;
914
+ repairHints: r.map((i) => {
915
+ var o, n;
717
916
  return {
718
- code: o.code,
719
- message: o.message,
720
- fieldRole: o.fieldRole,
721
- invalidField: (i = o.repairHint) == null ? void 0 : i.invalidField,
722
- recommendedNextStep: ((n = o.repairHint) == null ? void 0 : n.recommendedNextStep) || "Update the Data App SDK query spec to use visible Semaphor source and field refs."
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."
723
922
  };
724
923
  })
725
924
  };
726
925
  }
727
- function q(e) {
926
+ function w(e) {
728
927
  var r;
729
928
  return {
730
929
  code: e.code,
@@ -740,22 +939,22 @@ function q(e) {
740
939
  }
741
940
  };
742
941
  }
743
- function I(e) {
942
+ function A(e) {
744
943
  const r = /* @__PURE__ */ new Set();
745
944
  return e.filter((t) => {
746
- const o = `${t.code}:${t.path || ""}:${t.message}`;
747
- return r.has(o) ? !1 : (r.add(o), !0);
945
+ const i = `${t.code}:${t.path || ""}:${t.message}`;
946
+ return r.has(i) ? !1 : (r.add(i), !0);
748
947
  });
749
948
  }
750
- function k(e) {
751
- var t, o;
949
+ function _(e) {
950
+ var t, i;
752
951
  const r = e.diagnostics.filter(
753
- (i) => i.severity === "error"
952
+ (o) => o.severity === "error"
754
953
  );
755
954
  return {
756
955
  intentId: (t = e.intent) == null ? void 0 : t.id,
757
956
  status: r.length ? "failed" : "answered",
758
- resultShape: (o = e.intent) == null ? void 0 : o.kind,
957
+ resultShape: (i = e.intent) == null ? void 0 : i.kind,
759
958
  intent: e.intent,
760
959
  validation: e.validation,
761
960
  coverage: {
@@ -763,41 +962,42 @@ function k(e) {
763
962
  missingObligations: r.length ? ["query_spec_validation"] : [],
764
963
  warnings: e.validation.warnings
765
964
  },
766
- missingFields: r.filter((i) => i.code === "missing_field").flatMap(
767
- (i) => {
965
+ missingFields: r.filter((o) => o.code === "missing_field").flatMap(
966
+ (o) => {
768
967
  var n;
769
- return (n = i.field) != null && n.name ? [i.field.name] : [];
968
+ return (n = o.field) != null && n.name ? [o.field.name] : [];
770
969
  }
771
970
  ),
772
- warnings: e.diagnostics.filter((i) => i.severity === "warning").map((i) => i.message),
971
+ warnings: e.diagnostics.filter((o) => o.severity === "warning").map((o) => o.message),
773
972
  metadata: {
774
973
  validationKind: "data_app_sdk_query_spec"
775
974
  }
776
975
  };
777
976
  }
778
- function ye(e, r) {
779
- return r.id || P(e.spec);
977
+ function Me(e, r) {
978
+ return r.id || B(e.spec);
780
979
  }
781
- function P(e) {
980
+ function B(e) {
782
981
  if (!e || typeof e != "object" || !("id" in e))
783
982
  return;
784
983
  const r = e.id;
785
984
  return typeof r == "string" && r.trim() ? r : void 0;
786
985
  }
787
986
  export {
788
- W as a,
789
- N as b,
790
- Q as c,
791
- ge as d,
792
- F as e,
793
- w as f,
794
- M as g,
795
- g as h,
796
- U as i,
797
- ve as j,
798
- G as k,
799
- Y as l,
800
- Ie as n,
801
- qe as t,
802
- ke as v
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
803
1003
  };