react-semaphor 0.1.365 → 0.1.367

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 (36) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +26 -24
  3. package/dist/chunks/{calendar-preferences-dialog-CgBwWqfY.js → calendar-preferences-dialog-BOFlzOJg.js} +1 -1
  4. package/dist/chunks/{dashboard-briefing-launcher-CK_6KGFV.js → dashboard-briefing-launcher-D2lBFqAd.js} +3 -3
  5. package/dist/chunks/{dashboard-controls-CsIEj0Vm.js → dashboard-controls-BIk094Ah.js} +3 -3
  6. package/dist/chunks/{dashboard-json-OhYs9GOx.js → dashboard-json-DImOf512.js} +1 -1
  7. package/dist/chunks/{edit-dashboard-visual-q_XG4oWg.js → edit-dashboard-visual-DTxkV6Fl.js} +3 -3
  8. package/dist/chunks/{index-Ds3_EAla.js → index-BVEIk-rB.js} +5 -5
  9. package/dist/chunks/{resource-management-panel-CYXyE2js.js → resource-management-panel-BOfbSf48.js} +2 -2
  10. package/dist/chunks/{source-identity-qAmkNtEK.js → source-identity-Dj3dryN9.js} +3 -3
  11. package/dist/chunks/{use-create-flow-overlay-state-CRQcqLs3.js → use-create-flow-overlay-state-B5FygfQL.js} +2 -2
  12. package/dist/chunks/{use-visual-utils-CpZplRpR.js → use-visual-utils-CszWnFBW.js} +1 -1
  13. package/dist/chunks/{validation-B4_hBuYu.js → validation-CrUjNWby.js} +115 -94
  14. package/dist/chunks/validation-DGl8wnTt.js +1 -0
  15. package/dist/chunks/validators-Dq5X4mp0.js +1 -0
  16. package/dist/chunks/{validators-BnLhuIhd.js → validators-L0xEXtjf.js} +279 -212
  17. package/dist/dashboard/index.js +1 -1
  18. package/dist/dashboard-authoring/index.cjs +3 -3
  19. package/dist/dashboard-authoring/index.js +288 -280
  20. package/dist/data-app-builder/index.js +1 -1
  21. package/dist/data-app-sdk/index.cjs +1 -1
  22. package/dist/data-app-sdk/index.js +400 -271
  23. package/dist/data-app-sdk-validation/index.cjs +1 -1
  24. package/dist/data-app-sdk-validation/index.js +3 -3
  25. package/dist/index.js +5 -5
  26. package/dist/surfboard/index.js +2 -2
  27. package/dist/types/analytics-protocol.d.ts +12 -2
  28. package/dist/types/dashboard-assistant.d.ts +3 -1
  29. package/dist/types/dashboard-authoring.d.ts +8 -2
  30. package/dist/types/data-app-builder.d.ts +3 -1
  31. package/dist/types/data-app-sdk-validation.d.ts +5 -1
  32. package/dist/types/data-app-sdk.d.ts +25 -6
  33. package/dist/types/main.d.ts +3 -1
  34. package/package.json +1 -1
  35. package/dist/chunks/validation-CsK42Vbq.js +0 -1
  36. package/dist/chunks/validators-Cu_w8ZEP.js +0 -1
@@ -1,8 +1,8 @@
1
- import { v as C } from "./validators-BnLhuIhd.js";
2
- import { s as S, c as x, b as A } from "./source-identity-qAmkNtEK.js";
1
+ import { n as C, v as x } from "./validators-L0xEXtjf.js";
2
+ import { b as S, c as F, a as A } from "./source-identity-Dj3dryN9.js";
3
3
  function b(e) {
4
4
  var r;
5
- const t = P(e);
5
+ const t = z(e);
6
6
  return {
7
7
  version: 1,
8
8
  kind: "metric",
@@ -10,7 +10,7 @@ function b(e) {
10
10
  label: e.label,
11
11
  source: p(e),
12
12
  metrics: t,
13
- primaryMetric: T(e, t),
13
+ primaryMetric: P(e, t),
14
14
  dateField: e.dateField ? a(e.dateField, "date") : void 0,
15
15
  timeGrain: e.timeGrain,
16
16
  dimensions: (r = e.dimensions) == null ? void 0 : r.map((o) => a(o, "dimension")),
@@ -23,7 +23,7 @@ function b(e) {
23
23
  limit: e.limit
24
24
  };
25
25
  }
26
- function F(e) {
26
+ function T(e) {
27
27
  var r;
28
28
  return {
29
29
  ...b(e),
@@ -32,7 +32,7 @@ function F(e) {
32
32
  ...e.analysis ? { analysis: e.analysis } : {}
33
33
  };
34
34
  }
35
- function le(e) {
35
+ function ce(e) {
36
36
  return {
37
37
  ...e.chartTitle ? { chartTitle: e.chartTitle } : {},
38
38
  ...e.chartType ? { chartType: e.chartType } : {},
@@ -41,13 +41,13 @@ function le(e) {
41
41
  ...e.calendarContext ? { calendarContext: e.calendarContext } : {}
42
42
  };
43
43
  }
44
- function T(e, t) {
44
+ function P(e, t) {
45
45
  if (!e.primaryMetric)
46
46
  return t[0] || { name: "", role: "measure" };
47
- const r = a(e.primaryMetric, "measure"), o = D(r, t), i = o.length === 1 ? o[0] : void 0;
48
- return i ? M(r, i) : r;
47
+ const r = a(e.primaryMetric, "measure"), o = O(r, t), i = o.length === 1 ? o[0] : void 0;
48
+ return i ? w(r, i) : r;
49
49
  }
50
- function P(e) {
50
+ function z(e) {
51
51
  const t = [];
52
52
  for (const r of e.metrics.map((o) => a(o, "measure"))) {
53
53
  if (!r.name)
@@ -59,39 +59,40 @@ function P(e) {
59
59
  t.push(r);
60
60
  continue;
61
61
  }
62
- t[o] = M(t[o], r);
62
+ t[o] = w(t[o], r);
63
63
  }
64
64
  return t;
65
65
  }
66
66
  function R(e, t) {
67
- return S(e, t) && f(e) === f(t);
68
- }
69
- function z(e, t) {
70
- return f(t) === f(e);
67
+ return S(e, t) && c(e) === c(t);
71
68
  }
72
69
  function B(e, t) {
73
- return t.name !== e.name || e.source && !S(t, e) ? !1 : z(e, t);
70
+ return c(t) === c(e);
74
71
  }
75
72
  function D(e, t) {
73
+ return t.name !== e.name || e.source && !S(t, e) ? !1 : B(e, t);
74
+ }
75
+ function O(e, t) {
76
76
  const r = t.filter(
77
- (o) => B(e, o)
77
+ (o) => D(e, o)
78
78
  );
79
79
  return e.aggregate !== void 0, r;
80
80
  }
81
- function f(e) {
81
+ function c(e) {
82
82
  return (e.aggregate || "SUM").toUpperCase();
83
83
  }
84
- function M(e, t) {
84
+ function w(e, t) {
85
85
  if (e.aggregate && t.aggregate && e.aggregate !== t.aggregate)
86
86
  throw new Error(
87
87
  `Metric "${e.name}" was requested with conflicting aggregate semantics: ${e.aggregate} and ${t.aggregate}.`
88
88
  );
89
89
  return {
90
- ...x(e, t),
90
+ ...F(e, t),
91
91
  aggregate: e.aggregate || t.aggregate
92
92
  };
93
93
  }
94
94
  function H(e) {
95
+ var r;
95
96
  if ("sort" in e)
96
97
  throw new Error(
97
98
  "useSemaphorRecords supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet."
@@ -100,7 +101,7 @@ function H(e) {
100
101
  throw new Error(
101
102
  "useSemaphorRecords needs at least one field."
102
103
  );
103
- const t = O(e.fields);
104
+ const t = j(e.fields);
104
105
  return {
105
106
  version: 1,
106
107
  kind: "records",
@@ -110,6 +111,8 @@ function H(e) {
110
111
  fields: t,
111
112
  dateField: e.dateField ? a(e.dateField, "date") : void 0,
112
113
  timeGrain: e.timeGrain,
114
+ ...e.timeWindow ? { timeWindow: e.timeWindow } : {},
115
+ ...(r = e.filters) != null && r.length ? { filters: e.filters } : {},
113
116
  orderBy: e.orderBy ? {
114
117
  field: a(e.orderBy.field),
115
118
  direction: e.orderBy.direction
@@ -118,7 +121,7 @@ function H(e) {
118
121
  limit: e.limit
119
122
  };
120
123
  }
121
- function O(e) {
124
+ function j(e) {
122
125
  return e.map((t) => {
123
126
  const r = a(t);
124
127
  if (!r.role)
@@ -128,7 +131,7 @@ function O(e) {
128
131
  return r;
129
132
  });
130
133
  }
131
- function j(e) {
134
+ function N(e) {
132
135
  return {
133
136
  version: 1,
134
137
  kind: "inputOptions",
@@ -140,7 +143,7 @@ function j(e) {
140
143
  limit: e.limit
141
144
  };
142
145
  }
143
- function N(e) {
146
+ function E(e) {
144
147
  if ("toAnalyticsInput" in e) {
145
148
  const t = e.toAnalyticsInput();
146
149
  return {
@@ -153,30 +156,34 @@ function N(e) {
153
156
  ...e.field ? { field: e.field } : {}
154
157
  };
155
158
  }
156
- function ce(e) {
159
+ function ue(e) {
157
160
  const t = g(e);
158
161
  return t.length > 0 ? t : void 0;
159
162
  }
160
163
  function q(e) {
161
164
  return (e || []).map(U);
162
165
  }
163
- function fe(e) {
166
+ function me(e) {
164
167
  return q(e).filter((t) => t.isActive);
165
168
  }
166
- function ue(e) {
167
- return e.kind === "filter" ? {
168
- inputId: e.id,
169
- kind: e.kind,
170
- label: e.label,
171
- field: a(e.field, "dimension"),
172
- operator: e.operator || "in"
173
- } : {
169
+ function he(e) {
170
+ if (e.kind === "filter") {
171
+ const t = K(e.operator, e.id);
172
+ return {
173
+ inputId: e.id,
174
+ kind: e.kind,
175
+ label: e.label,
176
+ field: a(e.field, "dimension"),
177
+ operator: t || "in"
178
+ };
179
+ }
180
+ return {
174
181
  inputId: e.id,
175
182
  kind: e.kind,
176
183
  label: e.label
177
184
  };
178
185
  }
179
- function he(e = []) {
186
+ function pe(e = []) {
180
187
  return e.map(
181
188
  (t) => typeof t == "object" ? t : {
182
189
  label: String(t),
@@ -184,14 +191,14 @@ function he(e = []) {
184
191
  }
185
192
  );
186
193
  }
187
- function E(e) {
194
+ function W(e) {
188
195
  return e == null ? !1 : Array.isArray(e) ? e.length > 0 : typeof e == "string" ? e.trim().length > 0 : !0;
189
196
  }
190
197
  function U(e) {
191
198
  return "toAnalyticsInput" in e ? e.toAnalyticsInput() : "kind" in e && "isActive" in e ? e : {
192
199
  ...e,
193
200
  kind: "filter",
194
- isActive: E(
201
+ isActive: W(
195
202
  e.value
196
203
  ),
197
204
  value: e.value
@@ -211,13 +218,23 @@ function a(e, t) {
211
218
  };
212
219
  }
213
220
  function g(e) {
214
- return (e || []).map(N);
221
+ return (e || []).map(E);
215
222
  }
216
223
  function V(e) {
217
224
  if (e)
218
225
  return e;
219
226
  }
220
- function W(e, t = {}) {
227
+ function K(e, t) {
228
+ if (e === void 0)
229
+ return;
230
+ const r = C(e);
231
+ if (!r)
232
+ throw new Error(
233
+ `useSemaphorInput "${t}" uses unsupported filter operator "${e}".`
234
+ );
235
+ return r;
236
+ }
237
+ function Q(e, t = {}) {
221
238
  const r = t.pathPrefix || "analysisOptions";
222
239
  if (e === void 0)
223
240
  return { ok: !0 };
@@ -244,7 +261,7 @@ function W(e, t = {}) {
244
261
  i.chartType = o.chartType;
245
262
  }
246
263
  if (o.driverMode !== void 0) {
247
- if (!Q(o.driverMode))
264
+ if (!L(o.driverMode))
248
265
  return s(
249
266
  `${r}.driverMode`,
250
267
  'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.'
@@ -260,7 +277,7 @@ function W(e, t = {}) {
260
277
  i.includePopulation = o.includePopulation;
261
278
  }
262
279
  if (o.calendarContext !== void 0) {
263
- const n = L(
280
+ const n = Y(
264
281
  o.calendarContext,
265
282
  {
266
283
  pathPrefix: `${r}.calendarContext`,
@@ -273,9 +290,9 @@ function W(e, t = {}) {
273
290
  }
274
291
  return { ok: !0, analysisOptions: i };
275
292
  }
276
- function me(e) {
293
+ function ge(e) {
277
294
  const t = e.hooks.map(
278
- (i, n) => K(i, n, {
295
+ (i, n) => J(i, n, {
279
296
  fieldCatalogs: e.fieldCatalogs || [],
280
297
  requireFieldCatalog: !!e.requireFieldCatalog,
281
298
  validateTimezone: e.validateTimezone
@@ -289,12 +306,12 @@ function me(e) {
289
306
  executionResults: o
290
307
  };
291
308
  }
292
- function K(e, t, r) {
309
+ function J(e, t, r) {
293
310
  const o = `hooks.${t}`;
294
311
  try {
295
- const i = X(e), n = ae(e, i), d = C(i), l = [
312
+ const i = Z(e), n = de(e, i), d = x(i), l = [
296
313
  ...d.errors.map(
297
- (h) => y(h, {
314
+ (m) => y(m, {
298
315
  hook: e.hook,
299
316
  hookId: n,
300
317
  pathPrefix: o,
@@ -303,7 +320,7 @@ function K(e, t, r) {
303
320
  })
304
321
  ),
305
322
  ...d.warnings.map(
306
- (h) => y(h, {
323
+ (m) => y(m, {
307
324
  hook: e.hook,
308
325
  hookId: n,
309
326
  pathPrefix: o,
@@ -311,7 +328,7 @@ function K(e, t, r) {
311
328
  intent: i
312
329
  })
313
330
  ),
314
- ...Y({
331
+ ...ee({
315
332
  hookSpec: e,
316
333
  hookId: n,
317
334
  intent: i,
@@ -319,14 +336,14 @@ function K(e, t, r) {
319
336
  fieldCatalogs: r.fieldCatalogs,
320
337
  requireFieldCatalog: r.requireFieldCatalog
321
338
  }),
322
- ...te({
339
+ ...ie({
323
340
  hookSpec: e,
324
341
  hookId: n,
325
342
  intent: i,
326
343
  pathPrefix: o,
327
344
  validateTimezone: r.validateTimezone
328
345
  })
329
- ], c = ne(d, l);
346
+ ], f = se(d, l);
330
347
  return {
331
348
  hook: e.hook,
332
349
  hookId: n,
@@ -334,7 +351,7 @@ function K(e, t, r) {
334
351
  diagnostics: l,
335
352
  executionResult: I({
336
353
  intent: i,
337
- validation: c,
354
+ validation: f,
338
355
  diagnostics: l
339
356
  })
340
357
  };
@@ -346,7 +363,7 @@ function K(e, t, r) {
346
363
  path: o,
347
364
  hook: e.hook,
348
365
  hookId: $(e.spec)
349
- }, d = w([n]);
366
+ }, d = _([n]);
350
367
  return {
351
368
  hook: e.hook,
352
369
  hookId: n.hookId,
@@ -370,24 +387,24 @@ function s(e, t) {
370
387
  ]
371
388
  };
372
389
  }
373
- function Q(e) {
390
+ function L(e) {
374
391
  return e === "absolute_delta" || e === "largest_negative" || e === "largest_positive" || e === "positive_and_negative" || e === "all";
375
392
  }
376
- function J(e) {
393
+ function X(e) {
377
394
  return e.trim().length > 0 && !Number.isNaN(Date.parse(e));
378
395
  }
379
- function L(e, t) {
380
- var c;
396
+ function Y(e, t) {
397
+ var f;
381
398
  if (!e || typeof e != "object" || Array.isArray(e))
382
399
  return s(
383
400
  t.pathPrefix,
384
401
  'Data App analysis option "calendarContext" must be an object.'
385
402
  );
386
- const r = e, o = r.tz, i = r.weekStart, n = r.anchor, d = n && typeof n == "object" && !Array.isArray(n) ? n.iso : void 0, l = typeof o == "string" ? ((c = t.validateTimezone) == null ? void 0 : c.call(t, o)) ?? o : null;
403
+ const r = e, o = r.tz, i = r.weekStart, n = r.anchor, d = n && typeof n == "object" && !Array.isArray(n) ? n.iso : void 0, l = typeof o == "string" ? ((f = t.validateTimezone) == null ? void 0 : f.call(t, o)) ?? o : null;
387
404
  return l ? typeof i != "number" || !Number.isInteger(i) || i < 0 || i > 6 ? s(
388
405
  `${t.pathPrefix}.weekStart`,
389
406
  'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'
390
- ) : n !== "now" && !(typeof d == "string" && J(d)) ? s(
407
+ ) : n !== "now" && !(typeof d == "string" && X(d)) ? s(
391
408
  `${t.pathPrefix}.anchor`,
392
409
  'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'
393
410
  ) : {
@@ -402,19 +419,19 @@ function L(e, t) {
402
419
  'Data App analysis option "calendarContext.tz" must be a valid timezone string.'
403
420
  );
404
421
  }
405
- function X(e) {
406
- return e.hook === "useSemaphorMetric" ? b(e.spec) : e.hook === "useSemaphorAnalysis" ? F(e.spec) : e.hook === "useSemaphorRecords" ? H(e.spec) : j(e.spec);
422
+ function Z(e) {
423
+ return e.hook === "useSemaphorMetric" ? b(e.spec) : e.hook === "useSemaphorAnalysis" ? T(e.spec) : e.hook === "useSemaphorRecords" ? H(e.spec) : N(e.spec);
407
424
  }
408
- function Y(e) {
425
+ function ee(e) {
409
426
  if (e.fieldCatalogs.length === 0 && !e.requireFieldCatalog)
410
427
  return [];
411
- const t = ie(e.fieldCatalogs, e.intent.source);
428
+ const t = ne(e.fieldCatalogs, e.intent.source);
412
429
  return t ? [
413
- ...Z({
430
+ ...te({
414
431
  ...e,
415
432
  catalog: t
416
433
  }),
417
- ...ee({
434
+ ...re({
418
435
  ...e,
419
436
  catalog: t
420
437
  })
@@ -431,8 +448,8 @@ function Y(e) {
431
448
  }
432
449
  ];
433
450
  }
434
- function Z(e) {
435
- return re(e.intent).flatMap(({ field: t, path: r }) => _(e.catalog, t, e.intent.source) ? [] : [
451
+ function te(e) {
452
+ return oe(e.intent).flatMap(({ field: t, path: r }) => M(e.catalog, t, e.intent.source) ? [] : [
436
453
  {
437
454
  severity: "error",
438
455
  code: "missing_field",
@@ -446,12 +463,12 @@ function Z(e) {
446
463
  }
447
464
  ]);
448
465
  }
449
- function ee(e) {
466
+ function re(e) {
450
467
  return ("inputs" in e.intent ? e.intent.inputs || [] : []).flatMap((r, o) => {
451
468
  if (!r.field)
452
469
  return [];
453
470
  const i = u(r.field, e.intent.source);
454
- return A(i, e.intent.source) ? _(e.catalog, r.field, e.intent.source) ? [] : [
471
+ return A(i, e.intent.source) ? M(e.catalog, r.field, e.intent.source) ? [] : [
455
472
  {
456
473
  severity: "error",
457
474
  code: "missing_field",
@@ -478,10 +495,10 @@ function ee(e) {
478
495
  ];
479
496
  });
480
497
  }
481
- function te(e) {
498
+ function ie(e) {
482
499
  if (e.hookSpec.hook !== "useSemaphorAnalysis")
483
500
  return [];
484
- const t = W(e.hookSpec.spec, {
501
+ const t = Q(e.hookSpec.spec, {
485
502
  pathPrefix: `${e.pathPrefix}.spec`,
486
503
  validateTimezone: e.validateTimezone
487
504
  });
@@ -496,7 +513,7 @@ function te(e) {
496
513
  source: e.intent.source
497
514
  }));
498
515
  }
499
- function re(e) {
516
+ function oe(e) {
500
517
  return e.kind === "metric" ? [
501
518
  ...e.metrics.map((t, r) => ({
502
519
  field: t,
@@ -519,23 +536,27 @@ function re(e) {
519
536
  path: `spec.fields.${r}`
520
537
  })),
521
538
  ...e.dateField ? [{ field: e.dateField, path: "spec.dateField" }] : [],
522
- ...e.orderBy ? [{ field: e.orderBy.field, path: "spec.orderBy.field" }] : []
539
+ ...e.orderBy ? [{ field: e.orderBy.field, path: "spec.orderBy.field" }] : [],
540
+ ...(e.filters || []).map((t, r) => ({
541
+ field: t.field,
542
+ path: `spec.filters.${r}.field`
543
+ }))
523
544
  ] : e.kind === "inputOptions" ? [{ field: e.field, path: "spec.field" }] : [];
524
545
  }
525
- function ie(e, t) {
526
- return e.find((r) => m(r, t));
546
+ function ne(e, t) {
547
+ return e.find((r) => h(r, t));
527
548
  }
528
- function _(e, t, r) {
549
+ function M(e, t, r) {
529
550
  const o = u(t, r);
530
- if (m(e, o))
551
+ if (h(e, o))
531
552
  return e.fields.find(
532
- (i) => oe(i, t) && m(
553
+ (i) => ae(i, t) && h(
533
554
  e,
534
555
  u(i, e.source)
535
556
  )
536
557
  );
537
558
  }
538
- function m(e, t) {
559
+ function h(e, t) {
539
560
  return [e.source, ...e.sourceAliases || []].some(
540
561
  (r) => A(r, t)
541
562
  );
@@ -543,7 +564,7 @@ function m(e, t) {
543
564
  function u(e, t) {
544
565
  return e.source || t;
545
566
  }
546
- function oe(e, t) {
567
+ function ae(e, t) {
547
568
  return !!(e.name && t.name && e.name === t.name);
548
569
  }
549
570
  function y(e, t) {
@@ -558,8 +579,8 @@ function y(e, t) {
558
579
  source: t.intent.source
559
580
  };
560
581
  }
561
- function ne(e, t) {
562
- const r = w(t);
582
+ function se(e, t) {
583
+ const r = _(t);
563
584
  return {
564
585
  ok: r.ok && e.ok,
565
586
  errors: k([
@@ -576,7 +597,7 @@ function ne(e, t) {
576
597
  ]
577
598
  };
578
599
  }
579
- function w(e) {
600
+ function _(e) {
580
601
  const t = e.filter((o) => o.severity === "error").map(v), r = e.filter((o) => o.severity === "warning").map(v);
581
602
  return {
582
603
  ok: t.length === 0,
@@ -641,7 +662,7 @@ function I(e) {
641
662
  }
642
663
  };
643
664
  }
644
- function ae(e, t) {
665
+ function de(e, t) {
645
666
  return t.id || $(e.spec);
646
667
  }
647
668
  function $(e) {
@@ -651,18 +672,18 @@ function $(e) {
651
672
  return typeof t == "string" && t.trim() ? t : void 0;
652
673
  }
653
674
  export {
654
- le as a,
655
- F as b,
675
+ ce as a,
676
+ T as b,
656
677
  b as c,
657
678
  H as d,
658
- j as e,
659
- ue as f,
660
- N as g,
661
- E as h,
662
- ce as i,
679
+ N as e,
680
+ he as f,
681
+ E as g,
682
+ W as h,
683
+ ue as i,
663
684
  q as j,
664
- W as k,
665
- he as n,
666
- fe as t,
667
- me as v
685
+ Q as k,
686
+ pe as n,
687
+ me as t,
688
+ ge as v
668
689
  };
@@ -0,0 +1 @@
1
+ "use strict";const M=require("./validators-Dq5X4mp0.js"),c=require("./source-identity-C-xaeE_I.js");function g(e){var r;const t=O(e);return{version:1,kind:"metric",id:e.id,label:e.label,source:y(e),metrics:t,primaryMetric:D(e,t),dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,dimensions:(r=e.dimensions)==null?void 0:r.map(o=>a(o,"dimension")),comparison:J(e.comparison),orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:v(e.inputs),limit:e.limit}}function w(e){var r;return{...g(e),...e.timeWindow?{timeWindow:e.timeWindow}:{},...(r=e.filters)!=null&&r.length?{filters:e.filters}:{},...e.analysis?{analysis:e.analysis}:{}}}function B(e){return{...e.chartTitle?{chartTitle:e.chartTitle}:{},...e.chartType?{chartType:e.chartType}:{},...e.driverMode?{driverMode:e.driverMode}:{},...e.includePopulation!==void 0?{includePopulation:e.includePopulation}:{},...e.calendarContext?{calendarContext:e.calendarContext}:{}}}function D(e,t){if(!e.primaryMetric)return t[0]||{name:"",role:"measure"};const r=a(e.primaryMetric,"measure"),o=N(r,t),i=o.length===1?o[0]:void 0;return i?b(r,i):r}function O(e){const t=[];for(const r of e.metrics.map(o=>a(o,"measure"))){if(!r.name)continue;const o=t.findIndex(i=>H(i,r));if(o===-1){t.push(r);continue}t[o]=b(t[o],r)}return t}function H(e,t){return c.semaphorFieldRefsMatch(e,t)&&u(e)===u(t)}function j(e,t){return u(t)===u(e)}function q(e,t){return t.name!==e.name||e.source&&!c.semaphorFieldRefsMatch(t,e)?!1:j(e,t)}function N(e,t){const r=t.filter(o=>q(e,o));return e.aggregate!==void 0,r}function u(e){return(e.aggregate||"SUM").toUpperCase()}function b(e,t){if(e.aggregate&&t.aggregate&&e.aggregate!==t.aggregate)throw new Error(`Metric "${e.name}" was requested with conflicting aggregate semantics: ${e.aggregate} and ${t.aggregate}.`);return{...c.preferSemaphorFieldRefMetadata(e,t),aggregate:e.aggregate||t.aggregate}}function _(e){var r;if("sort"in e)throw new Error("useSemaphorRecords supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet.");if(!K(e))throw new Error("useSemaphorRecords needs at least one field.");const t=E(e.fields);return{version:1,kind:"records",id:e.id,label:e.label,source:y(e),fields:t,dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,...e.timeWindow?{timeWindow:e.timeWindow}:{},...(r=e.filters)!=null&&r.length?{filters:e.filters}:{},orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:v(e.inputs),limit:e.limit}}function E(e){return e.map(t=>{const r=a(t);if(!r.role)throw new Error(`useSemaphorRecords field "${r.name}" needs an explicit role.`);return r})}function $(e){return{version:1,kind:"inputOptions",id:e.id,label:e.label,source:y(e),field:a(e.field,"dimension"),search:e.search,limit:e.limit}}function C(e){if("toAnalyticsInput"in e){const t=e.toAnalyticsInput();return{inputId:t.inputId,...t.field?{field:t.field}:{}}}return{inputId:e.inputId,...e.field?{field:e.field}:{}}}function W(e){const t=v(e);return t.length>0?t:void 0}function F(e){return(e||[]).map(Q)}function U(e){return F(e).filter(t=>t.isActive)}function V(e){if(e.kind==="filter"){const t=L(e.operator,e.id);return{inputId:e.id,kind:e.kind,label:e.label,field:a(e.field,"dimension"),operator:t||"in"}}return{inputId:e.id,kind:e.kind,label:e.label}}function G(e=[]){return e.map(t=>typeof t=="object"?t:{label:String(t),value:t})}function T(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e=="string"?e.trim().length>0:!0}function Q(e){return"toAnalyticsInput"in e?e.toAnalyticsInput():"kind"in e&&"isActive"in e?e:{...e,kind:"filter",isActive:T(e.value),value:e.value}}function y(e){return e.source}function K(e){var t;return!!((t=e.fields)!=null&&t.length)}function a(e,t){return{...e,role:e.role||t}}function v(e){return(e||[]).map(C)}function J(e){if(e)return e}function L(e,t){if(e===void 0)return;const r=M.normalizeSemaphorInputOperator(e);if(!r)throw new Error(`useSemaphorInput "${t}" uses unsupported filter operator "${e}".`);return r}function x(e,t={}){const r=t.pathPrefix||"analysisOptions";if(e===void 0)return{ok:!0};if(!e||typeof e!="object"||Array.isArray(e))return s(r,"Data App analysis options must be an object.");const o=e,i={};if(o.chartTitle!==void 0){if(typeof o.chartTitle!="string")return s(`${r}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');i.chartTitle=o.chartTitle}if(o.chartType!==void 0){if(typeof o.chartType!="string")return s(`${r}.chartType`,'Data App analysis option "chartType" must be a string.');i.chartType=o.chartType}if(o.driverMode!==void 0){if(!Z(o.driverMode))return s(`${r}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');i.driverMode=o.driverMode}if(o.includePopulation!==void 0){if(typeof o.includePopulation!="boolean")return s(`${r}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');i.includePopulation=o.includePopulation}if(o.calendarContext!==void 0){const n=te(o.calendarContext,{pathPrefix:`${r}.calendarContext`,validateTimezone:t.validateTimezone});if(!n.ok)return n;i.calendarContext=n.calendarContext}return{ok:!0,analysisOptions:i}}function X(e){const t=e.hooks.map((i,n)=>Y(i,n,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),r=t.flatMap(i=>i.diagnostics),o=t.map(i=>i.executionResult);return{ok:r.every(i=>i.severity!=="error"),diagnostics:r,hooks:t,intents:t.flatMap(i=>i.intent?[i.intent]:[]),executionResults:o}}function Y(e,t,r){const o=`hooks.${t}`;try{const i=re(e),n=fe(e,i),d=M.validateSemaphorAnalyticsIntent(i),l=[...d.errors.map(m=>I(m,{hook:e.hook,hookId:n,pathPrefix:o,severity:"error",intent:i})),...d.warnings.map(m=>I(m,{hook:e.hook,hookId:n,pathPrefix:o,severity:"warning",intent:i})),...ie({hookSpec:e,hookId:n,intent:i,pathPrefix:o,fieldCatalogs:r.fieldCatalogs,requireFieldCatalog:r.requireFieldCatalog}),...ae({hookSpec:e,hookId:n,intent:i,pathPrefix:o,validateTimezone:r.validateTimezone})],f=ce(d,l);return{hook:e.hook,hookId:n,intent:i,diagnostics:l,executionResult:A({intent:i,validation:f,diagnostics:l})}}catch(i){const n={severity:"error",code:"invalid_hook_spec",message:i instanceof Error?i.message:String(i),path:o,hook:e.hook,hookId:P(e.spec)},d=z([n]);return{hook:e.hook,hookId:n.hookId,diagnostics:[n],executionResult:A({validation:d,diagnostics:[n]})}}}function s(e,t){return{ok:!1,issues:[{code:"invalid_analysis_option",message:t,path:e}]}}function Z(e){return e==="absolute_delta"||e==="largest_negative"||e==="largest_positive"||e==="positive_and_negative"||e==="all"}function ee(e){return e.trim().length>0&&!Number.isNaN(Date.parse(e))}function te(e,t){var f;if(!e||typeof e!="object"||Array.isArray(e))return s(t.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const r=e,o=r.tz,i=r.weekStart,n=r.anchor,d=n&&typeof n=="object"&&!Array.isArray(n)?n.iso:void 0,l=typeof o=="string"?((f=t.validateTimezone)==null?void 0:f.call(t,o))??o:null;return l?typeof i!="number"||!Number.isInteger(i)||i<0||i>6?s(`${t.pathPrefix}.weekStart`,'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'):n!=="now"&&!(typeof d=="string"&&ee(d))?s(`${t.pathPrefix}.anchor`,'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'):{ok:!0,calendarContext:{tz:l,weekStart:i,anchor:n}}:s(`${t.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.')}function re(e){return e.hook==="useSemaphorMetric"?g(e.spec):e.hook==="useSemaphorAnalysis"?w(e.spec):e.hook==="useSemaphorRecords"?_(e.spec):$(e.spec)}function ie(e){if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const t=de(e.fieldCatalogs,e.intent.source);return t?[...oe({...e,catalog:t}),...ne({...e,catalog:t})]:[{severity:"error",code:"invalid_source_ref",message:`Source ref for ${e.hookSpec.hook} does not match a visible Semaphor source.`,path:`${e.pathPrefix}.spec.source`,hook:e.hookSpec.hook,hookId:e.hookId,intentId:e.intent.id,source:e.intent.source}]}function oe(e){return se(e.intent).flatMap(({field:t,path:r})=>R(e.catalog,t,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Field "${t.name}" is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.${r}`,hook:e.hookSpec.hook,hookId:e.hookId,intentId:e.intent.id,source:h(t,e.intent.source),field:t}])}function ne(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((r,o)=>{if(!r.field)return[];const i=h(r.field,e.intent.source);return c.semaphorSourcesReferToSameDataset(i,e.intent.source)?R(e.catalog,r.field,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Input "${r.inputId}" references field "${r.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${o}.field`,hook:e.hookSpec.hook,hookId:e.hookId,intentId:e.intent.id,source:i,field:r.field}]:[{severity:"error",code:"unsupported_input_filter_composition",message:`Input "${r.inputId}" filters a different Semaphor source than the query. Cross-source Data App inputs are not supported yet.`,path:`${e.pathPrefix}.spec.inputs.${o}.field`,hook:e.hookSpec.hook,hookId:e.hookId,intentId:e.intent.id,source:i,field:r.field}]})}function ae(e){if(e.hookSpec.hook!=="useSemaphorAnalysis")return[];const t=x(e.hookSpec.spec,{pathPrefix:`${e.pathPrefix}.spec`,validateTimezone:e.validateTimezone});return t.ok?[]:t.issues.map(r=>({severity:"error",code:r.code,message:r.message,path:r.path,hook:e.hookSpec.hook,hookId:e.hookId,intentId:e.intent.id,source:e.intent.source}))}function se(e){return e.kind==="metric"?[...e.metrics.map((t,r)=>({field:t,path:`spec.metrics.${r}`})),...e.primaryMetric?[{field:e.primaryMetric,path:"spec.primaryMetric"}]:[],...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...(e.dimensions||[]).map((t,r)=>({field:t,path:`spec.dimensions.${r}`})),...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((t,r)=>({field:t.field,path:`spec.filters.${r}.field`}))]:e.kind==="records"?[...e.fields.map((t,r)=>({field:t,path:`spec.fields.${r}`})),...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((t,r)=>({field:t.field,path:`spec.filters.${r}.field`}))]:e.kind==="inputOptions"?[{field:e.field,path:"spec.field"}]:[]}function de(e,t){return e.find(r=>p(r,t))}function R(e,t,r){const o=h(t,r);if(p(e,o))return e.fields.find(i=>le(i,t)&&p(e,h(i,e.source)))}function p(e,t){return[e.source,...e.sourceAliases||[]].some(r=>c.semaphorSourcesReferToSameDataset(r,t))}function h(e,t){return e.source||t}function le(e,t){return!!(e.name&&t.name&&e.name===t.name)}function I(e,t){return{severity:t.severity,code:e.code||"invalid_analytics_intent",message:e.message,path:e.path?`${t.pathPrefix}.spec.${e.path}`:t.pathPrefix,hook:t.hook,hookId:t.hookId,intentId:t.intent.id,source:t.intent.source}}function ce(e,t){const r=z(t);return{ok:r.ok&&e.ok,errors:S([...e.errors,...r.errors]),warnings:S([...e.warnings,...r.warnings]),repairHints:[...e.repairHints,...r.repairHints]}}function z(e){const t=e.filter(o=>o.severity==="error").map(k),r=e.filter(o=>o.severity==="warning").map(k);return{ok:t.length===0,errors:t,warnings:r,repairHints:t.map(o=>{var i,n;return{code:o.code,message:o.message,fieldRole:o.fieldRole,invalidField:(i=o.repairHint)==null?void 0:i.invalidField,recommendedNextStep:((n=o.repairHint)==null?void 0:n.recommendedNextStep)||"Update the Data App SDK hook spec to use visible Semaphor source and field refs."}})}}function k(e){var t;return{code:e.code,message:e.message,path:e.path,fieldRole:e.code==="invalid_source_ref"?"source":void 0,repairHint:{code:e.code,message:e.message,invalidField:(t=e.field)==null?void 0:t.name,fieldRole:e.code==="invalid_source_ref"?"source":void 0,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 hooks.":"Update the hook spec to use a visible Semaphor source and field ref."}}}function S(e){const t=new Set;return e.filter(r=>{const o=`${r.code}:${r.path||""}:${r.message}`;return t.has(o)?!1:(t.add(o),!0)})}function A(e){var r,o;const t=e.diagnostics.filter(i=>i.severity==="error");return{intentId:(r=e.intent)==null?void 0:r.id,status:t.length?"failed":"answered",resultShape:(o=e.intent)==null?void 0:o.kind,intent:e.intent,validation:e.validation,coverage:{answeredObligations:t.length?[]:["hook_spec_validation"],missingObligations:t.length?["hook_spec_validation"]:[],warnings:e.validation.warnings},missingFields:t.filter(i=>i.code==="missing_field").flatMap(i=>{var n;return(n=i.field)!=null&&n.name?[i.field.name]:[]}),warnings:e.diagnostics.filter(i=>i.severity==="warning").map(i=>i.message),metadata:{validationKind:"data_app_sdk_hook_spec"}}}function fe(e,t){return t.id||P(e.spec)}function P(e){if(!e||typeof e!="object"||!("id"in e))return;const t=e.id;return typeof t=="string"&&t.trim()?t:void 0}exports.hasSemaphorInputValue=T;exports.normalizeSemaphorAnalysisQueryOptions=x;exports.normalizeSemaphorInputOptions=G;exports.toSemaphorActiveInputSnapshots=U;exports.toSemaphorAnalysisIntent=w;exports.toSemaphorAnalysisQueryOptions=B;exports.toSemaphorInputBinding=C;exports.toSemaphorInputBindings=W;exports.toSemaphorInputOptionsIntent=$;exports.toSemaphorInputSnapshots=F;exports.toSemaphorInputSpec=V;exports.toSemaphorMetricIntent=g;exports.toSemaphorRecordsIntent=_;exports.validateSemaphorDataAppHookSpecs=X;
@@ -0,0 +1 @@
1
+ "use strict";const O=require("./source-identity-C-xaeE_I.js");function q(e){const i=N(e);return B(i)?i:void 0}function N(e){if(typeof e!="string"||e.trim().length===0)return;const i=e.trim().toLowerCase().replace(/_/g," ");switch(i){case"eq":case"equals":case"=":return"=";case"neq":case"not equals":case"not equal":case"!=":return"!=";case"in":return"in";case"not in":return"not_in";case"contains":case"like":return"contains";case"not contains":case"not like":return"not_contains";case"between":return"between";case"not between":return"not_between";case">":case">=":case"<":case"<=":return i;case"is null":return"is_null";case"is not null":return"is_not_null";default:return j(e)?e:void 0}}function B(e){return e==="="||e==="!="||e==="in"||e==="not_in"||e==="contains"||e==="not_contains"||e==="between"||e==="not_between"||e===">"||e===">="||e==="<"||e==="<="}function j(e){return B(e)||e==="not_contains"||e==="is_null"||e==="is_not_null"}function t(e,i,n){return n?{code:e,message:i,path:n}:{code:e,message:i}}function C(e){for(let i=0;i<e.length;i+=1){const n=e[i];if(e.some((o,a)=>a!==i&&R(o,n)))return!1}return!0}function F(e,i){return O.semaphorFieldRefsMatch(e,i)}function R(e,i){return F(e,i)&&y(e)===y(i)}function E(e){return`Metric intent has duplicate metric "${e.name}" with the same aggregate (${y(e)}). Use different aggregates to request both, or remove one entry.`}function U(e,i){return w(e,i).length===1}function P(e,i){return w(e,i).length===1}function w(e,i){return i.filter(o=>G(e,o))}function G(e,i){return L(e,i)?e.source?F(i,e):!0:!1}function L(e,i){return!(i.name!==e.name||e.role!==void 0&&i.role!==void 0&&i.role!==e.role||H(e,i)&&y(i)!==y(e))}function H(e,i){return e.role==="measure"||i.role==="measure"||e.aggregate!==void 0||i.aggregate!==void 0}function y(e){return(e.aggregate||"SUM").toUpperCase()}const V=/^(\d{4})-(\d{2})-(\d{2})$/,Q=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})$/;function v(e){if(typeof e!="string")return null;const i=e.trim(),n=V.exec(i);if(n){const[,g,S,I]=n;return $(g,S,I)?new Date(Date.UTC(Number(g),Number(S)-1,Number(I))):null}const o=Q.exec(i);if(!o)return null;const[,a,r,s,m,c,l="00",,f]=o;if(!$(a,r,s)||!_(m,0,23)||!_(c,0,59)||!_(l,0,59)||!z(f))return null;const h=new Date(i);return Number.isFinite(h.getTime())?h:null}function $(e,i,n){const o=Number(e),a=Number(i),r=Number(n);if(!Number.isInteger(o)||!Number.isInteger(a)||!Number.isInteger(r)||a<1||a>12)return!1;const s=new Date(Date.UTC(o,a-1,r));return s.getUTCFullYear()===o&&s.getUTCMonth()===a-1&&s.getUTCDate()===r}function _(e,i,n){const o=Number(e);return Number.isInteger(o)&&o>=i&&o<=n}function z(e){if(e==="Z")return!0;const i=/^([+-])(\d{2}):(\d{2})$/.exec(e);return!!(i&&_(i[2],0,23)&&_(i[3],0,59))}function d(e){return typeof e=="string"&&e.trim().length>0}function u(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function M(e){const i=new Set;for(const n of e){if(i.has(n))return n;i.add(n)}return null}const X=new Set(["SUM","COUNT","AVG","MIN","MAX","MEDIAN","DISTINCT"]);function x(e,i,n){if(!e||typeof e!="object"){n.push(t("missing_source","Analytics intent needs a source.",i));return}if(e.kind==="semantic"){d(e.domainId)||n.push(t("missing_semantic_domain","Semantic source needs a domainId.",`${i}.domainId`)),d(e.datasetName)||n.push(t("missing_dataset_name","Semantic source needs a datasetName.",`${i}.datasetName`));return}if(e.kind==="physical"){d(e.connectionId)||n.push(t("missing_connection_id","Physical source needs a connectionId.",`${i}.connectionId`)),d(e.tableName)||n.push(t("missing_table_name","Physical source needs a tableName.",`${i}.tableName`));return}if(e.kind==="sql"){d(e.connectionId)||n.push(t("missing_connection_id","SQL source needs a connectionId.",`${i}.connectionId`));return}n.push(t("invalid_source_kind","Source kind is not supported.",i))}function p(e,i,n,o={}){if(!e||!u(e)){o.required&&n.push(t("missing_field_ref","Field reference needs a name.",i));return}d(e.name)||n.push(t("missing_field_ref","Field reference needs a name.",`${i}.name`)),e.source!==void 0&&x(e.source,`${i}.source`,n),Y(e.aggregate,`${i}.aggregate`,n)}function Y(e,i,n){e!==void 0&&(typeof e!="string"||!X.has(e))&&n.push(t("invalid_aggregate","Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",i))}function Z(e,i){if(e.analysis===void 0)return;if(!u(e.analysis)){i.push(t("invalid_metric_analysis","Metric analysis must be a structured object.","analysis"));return}if(e.analysis.kind!=="period_change"){i.push(t("invalid_metric_analysis","Metric analysis kind is not supported.","analysis.kind"));return}e.dateField||i.push(t("missing_analysis_date_field","Period-change analysis needs a dateField.","dateField")),e.timeGrain||i.push(t("missing_analysis_time_grain","Period-change analysis needs a timeGrain.","timeGrain")),e.analysis.orderBy!==void 0&&e.analysis.orderBy!=="absolute_change"&&e.analysis.orderBy!=="positive_change"&&e.analysis.orderBy!=="negative_change"&&e.analysis.orderBy!=="period"&&i.push(t("invalid_metric_analysis","Period-change analysis orderBy must be absolute_change, positive_change, negative_change, or period.","analysis.orderBy"));const{timeWindow:n}=e.analysis;n!==void 0&&b(n,"analysis.timeWindow",i)}function b(e,i,n){if(!u(e)){n.push(t("invalid_time_window","Time window must be a structured object.",i));return}if(e.kind!==void 0&&e.kind!=="relative"&&e.kind!=="absolute"&&n.push(t("invalid_time_window","Time window kind must be relative or absolute.",`${i}.kind`)),e.kind==="absolute"){if(d(e.start)||n.push(t("invalid_time_window","Absolute time window start must be a non-empty ISO date or timestamp string.",`${i}.start`)),d(e.end)||n.push(t("invalid_time_window","Absolute time window end must be a non-empty ISO date or timestamp string.",`${i}.end`)),d(e.start)&&d(e.end)){const o=v(e.start),a=v(e.end);o||n.push(t("invalid_time_window","Absolute time window start must be a valid ISO date or timestamp.",`${i}.start`)),a||n.push(t("invalid_time_window","Absolute time window end must be a valid ISO date or timestamp.",`${i}.end`)),o&&a&&o.getTime()>a.getTime()&&n.push(t("invalid_time_window","Absolute time window start must be before or equal to end.",i))}return}e.unit!=="second"&&e.unit!=="minute"&&e.unit!=="hour"&&e.unit!=="day"&&e.unit!=="week"&&e.unit!=="month"&&e.unit!=="quarter"&&e.unit!=="year"&&n.push(t("invalid_time_window","Time window unit must be second, minute, hour, day, week, month, quarter, or year.",`${i}.unit`)),(typeof e.value!="number"||!Number.isFinite(e.value)||e.value<=0)&&n.push(t("invalid_time_window","Time window value must be a positive number.",`${i}.value`)),e.anchor!==void 0&&e.anchor!=="now"&&e.anchor!=="latest_available"&&n.push(t("invalid_time_window","Time window anchor must be now or latest_available.",`${i}.anchor`)),e.completeness!==void 0&&e.completeness!=="include_partial"&&e.completeness!=="complete_periods"&&n.push(t("invalid_time_window","Time window completeness must be include_partial or complete_periods.",`${i}.completeness`))}function k(e,i,n){if(e!==void 0){if(!Array.isArray(e)){n.push(t("invalid_analytics_filters","Analytics filters must be an array.",i));return}e.forEach((o,a)=>{var c;const r=`${i}.${a}`;if(!u(o)){n.push(t("invalid_analytics_filter","Analytics filter must be a structured object.",r));return}const s=o;p(s.field,`${r}.field`,n,{required:!0}),s.scope!==void 0&&s.scope!=="row"&&s.scope!=="aggregate"&&n.push(t("invalid_analytics_filter_scope","Analytics filter scope must be row or aggregate.",`${r}.scope`)),s.scope==="aggregate"&&((c=s.field)==null?void 0:c.role)!==void 0&&s.field.role!=="measure"&&n.push(t("invalid_analytics_filter_scope","Aggregate-scope analytics filters must target a measure field.",`${r}.scope`));const m=s.operator==="is_null"||s.operator==="is_not_null";if(s.operator!==void 0&&s.operator!=="="&&s.operator!=="!="&&s.operator!=="in"&&s.operator!=="not_in"&&s.operator!=="contains"&&s.operator!=="not_contains"&&s.operator!=="between"&&s.operator!=="not_between"&&s.operator!==">"&&s.operator!==">="&&s.operator!=="<"&&s.operator!=="<="&&s.operator!=="is_null"&&s.operator!=="is_not_null"&&n.push(t("invalid_analytics_filter_operator","Analytics filter operator is not supported.",`${r}.operator`)),s.values===void 0&&!m&&n.push(t("missing_analytics_filter_value","Analytics filter needs values unless it is a null check.",r)),m&&s.values!==void 0){n.push(t("invalid_analytics_filter_values","Null-check analytics filters must not include values.",`${r}.values`));return}if(s.values!==void 0&&!Array.isArray(s.values)){n.push(t("invalid_analytics_filter_values","Analytics filter values must be an array when provided.",`${r}.values`));return}if(s.values!==void 0){const l=s.values.length;if(s.operator==="between"||s.operator==="not_between"){l!==2&&n.push(t("invalid_analytics_filter_values","Between analytics filters must include exactly two values.",`${r}.values`));return}(s.operator==="contains"||s.operator==="not_contains"||s.operator==="="||s.operator==="!="||s.operator===">"||s.operator===">="||s.operator==="<"||s.operator==="<="||s.operator===void 0)&&l!==1&&n.push(t("invalid_analytics_filter_values","Scalar analytics filters must include exactly one value. Use in/not_in for multiple values.",`${r}.values`))}})}}function A(e){var o;const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[t("invalid_analytics_intent","Analytics intent must be a structured object.")],warnings:n,repairHints:[{code:"invalid_analytics_intent",recommendedNextStep:"Send one structured analytics intent object with kind, source, and required fields."}]};if(e.version!==void 0&&e.version!==1&&i.push(t("invalid_version","Analytics intent version must be 1.","version")),x(e.source,"source",i),e.kind==="metric"){const a=Array.isArray(e.metrics)?e.metrics.filter(r=>u(r)&&d(r.name)):[];if(!Array.isArray(e.metrics)||e.metrics.length===0?i.push(t("missing_metric","Metric intent needs at least one metric.","metrics")):e.metrics.some(r=>!u(r)||!d(r.name))&&i.push(t("invalid_metric_list","Metric intent metrics must be an array of field references with names.","metrics")),a.forEach((r,s)=>{p(r,`metrics.${s}`,i,{required:!0})}),a.length>0&&!C(a)){const r=a.find((s,m)=>a.some((c,l)=>l!==m&&R(c,s)));r&&i.push(t("duplicate_metric",E(r),"metrics"))}if(u(e.primaryMetric)&&d(e.primaryMetric.name)&&w(e.primaryMetric,a).length>1&&i.push(t("ambiguous_primary_metric","Metric intent primaryMetric must identify exactly one selected metric.","primaryMetric")),e.primaryMetric!==void 0&&(p(e.primaryMetric,"primaryMetric",i,{required:!0}),u(e.primaryMetric)&&d(e.primaryMetric.name)&&a.length>0&&!U(e.primaryMetric,a)&&i.push(t("invalid_primary_metric","Metric intent primaryMetric must match one metric field reference.","primaryMetric"))),e.dimensions!==void 0&&!Array.isArray(e.dimensions)?i.push(t("invalid_metric_dimensions","Metric intent dimensions must be an array of field references.","dimensions")):Array.isArray(e.dimensions)&&e.dimensions.some(r=>!u(r)||!d(r.name))&&i.push(t("invalid_metric_dimensions","Metric intent dimensions must be an array of field references with names.","dimensions")),e.dateField!==void 0&&p(e.dateField,"dateField",i),e.timeWindow!==void 0&&(b(e.timeWindow,"timeWindow",i),e.dateField||i.push(t("missing_time_window_date_field","Metric timeWindow needs a dateField.","dateField"))),k(e.filters,"filters",i),Array.isArray(e.dimensions)&&e.dimensions.forEach((r,s)=>{p(r,`dimensions.${s}`,i)}),e.orderBy!==void 0){if(!u(e.orderBy))i.push(t("invalid_metric_order_by","Metric intent orderBy must be a structured object.","orderBy"));else if(p(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(t("invalid_metric_order_direction","Metric intent orderBy direction must be asc or desc.","orderBy.direction")),u(e.orderBy.field)&&d(e.orderBy.field.name)){const r=[...a,...e.timeGrain&&e.dateField&&u(e.dateField)?[e.dateField]:[],...Array.isArray(e.dimensions)?e.dimensions.filter(s=>u(s)&&d(s.name)):[]];r.length>0&&!P(e.orderBy.field,r)&&i.push(t("invalid_metric_order_by","Metric intent orderBy.field must match one selected metric, grouped dateField, or dimension.","orderBy.field"))}}Z(e,i)}else e.kind==="records"?(!Array.isArray(e.fields)||e.fields.length===0?i.push(t("missing_record_fields","Records intent needs at least one field.","fields")):e.fields.some(a=>!u(a)||!d(a.name))&&i.push(t("invalid_record_fields","Records intent fields must be field references with names.","fields")),Array.isArray(e.fields)&&e.fields.forEach((a,r)=>{p(a,`fields.${r}`,i)}),e.dateField!==void 0&&p(e.dateField,"dateField",i),e.timeWindow!==void 0&&(b(e.timeWindow,"timeWindow",i),e.dateField||i.push(t("missing_time_window_date_field","Records timeWindow needs a dateField.","dateField"))),k(e.filters,"filters",i),Array.isArray(e.filters)&&e.filters.forEach((a,r)=>{u(a)&&a.scope==="aggregate"&&i.push(t("unsupported_record_filter_scope","Records intents support row-scope filters only. Use a metric intent for aggregate-scope filters.",`filters.${r}.scope`))}),e.orderBy!==void 0&&(u(e.orderBy)?(p(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(t("invalid_record_order_direction","Records intent orderBy direction must be asc or desc.","orderBy.direction"))):i.push(t("invalid_record_order_by","Records intent orderBy must be a structured object.","orderBy")))):e.kind==="inputOptions"?((!e.field||!d(e.field.name))&&i.push(t("missing_input_options_field","Input options intent needs a field.","field")),p(e.field,"field",i,{required:!0})):e.kind==="sql"?(((o=e.source)==null?void 0:o.kind)!=="sql"&&i.push(t("invalid_sql_source","SQL analytics intent must use a SQL execution source.","source")),d(e.sql)||i.push(t("missing_sql","SQL analytics intent needs SQL text.","sql")),Array.isArray(e.fields)&&e.fields.forEach((a,r)=>{p(a,`fields.${r}`,i)})):i.push(t("invalid_analytics_kind","Analytics kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:n,repairHints:K(i)}}function T(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[t("invalid_operation_intent","Operation intent must be a structured object.")],warnings:n,repairHints:[{code:"invalid_operation_intent",recommendedNextStep:"Send one typed operation intent with version, kind, and required operation fields."}]};if(e.version!==1&&i.push(t("invalid_version","Operation intent version must be 1.","version")),e.kind==="answer_obligations")!Array.isArray(e.obligations)||e.obligations.length===0?i.push(t("missing_obligations","Answer-obligations operation intent needs at least one obligation.","obligations")):e.obligations.forEach((o,a)=>{d(o.id)||i.push(t("missing_obligation_id","Each analytics obligation needs an id.",`obligations.${a}.id`)),d(o.prompt)||i.push(t("missing_obligation_prompt","Each analytics obligation needs a prompt.",`obligations.${a}.prompt`))});else if(e.kind==="dashboard_change"||e.kind==="data_app_change"){if(d(e.instruction)||i.push(t("missing_instruction","Change operation intent needs an instruction.","instruction")),e.analyticsIntent){const o=A(e.analyticsIntent);i.push(...o.errors),n.push(...o.warnings)}}else i.push(t("invalid_operation_kind","Operation intent kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:n,repairHints:D(i)}}function J(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[t("invalid_recovery_plan","Analytics recovery plan must be a structured object.")],warnings:n,repairHints:[{code:"invalid_recovery_plan",recommendedNextStep:"Return a typed recovery plan with operationIntent and plannedToolCalls."}]};e.version!==1&&i.push(t("invalid_version","Recovery plan version must be 1.","version")),e.kind!=="analytics_recovery_plan"&&i.push(t("invalid_recovery_plan_kind","Recovery plan kind must be analytics_recovery_plan.","kind"));const o=T(e.operationIntent);return i.push(...o.errors),n.push(...o.warnings),Array.isArray(e.plannedToolCalls)||i.push(t("invalid_planned_tool_calls","Recovery plan plannedToolCalls must be an array.","plannedToolCalls")),{ok:i.length===0,errors:i,warnings:n,repairHints:D(i)}}function D(e){return e.map(i=>({code:i.code,recommendedNextStep:i.code==="missing_obligations"?"Normalize the user request into one or more typed analytics obligations before recovery planning.":"Correct the operation/recovery contract shape before planning execution."}))}function K(e){return e.map(i=>{switch(i.code){case"missing_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Provide a semantic, physical, or SQL source before executing analytics."};case"missing_metric":return{code:i.code,fieldRole:"metric",recommendedNextStep:"Choose one exact metric from the grounded schema candidates."};case"missing_record_fields":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide at least one field for the records intent."};case"missing_input_options_field":return{code:i.code,fieldRole:"input",recommendedNextStep:"Provide the exact field whose option values should be listed."};case"missing_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Provide bounded read-only SQL with an explicit outer LIMIT."};case"conflicting_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Use one canonical SQL text location for the intent; prefer top-level sql."};case"missing_semantic_domain":case"missing_dataset_name":case"missing_connection_id":case"missing_table_name":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use grounded catalog metadata to fill the missing source reference."};default:return}}).filter(i=>!!i)}function W(e,i,n,o){if(!e||typeof e!="object"){n.push(t("invalid_view","Dashboard view must be an object.",i));return}if(d(e.title)||n.push(t("missing_view_title","Dashboard view needs a title.",i)),!e.presentation||typeof e.presentation!="object"){n.push(t("missing_presentation","Dashboard view needs a presentation.",`${i}.presentation`));return}if(e.presentation.kind==="text"){d(e.text)||o.push(t("missing_text_content","Text views should include text content.",`${i}.text`));return}if(!e.analytics){n.push(t("missing_view_analytics","Non-text dashboard views need analytics intent.",`${i}.analytics`));return}const a=A(e.analytics);for(const r of a.errors)n.push(t(r.code,r.message,`${i}.analytics${r.path?`.${r.path}`:""}`));for(const r of a.warnings)o.push(t(r.code,r.message,`${i}.analytics${r.path?`.${r.path}`:""}`))}function ee(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[t("invalid_dashboard_intent","Dashboard intent must be a structured object.")],warnings:n};e.version!==1&&i.push(t("invalid_version","Dashboard intent version must be 1.")),e.kind!=="dashboard"&&i.push(t("invalid_kind","Experience intent kind must be dashboard.")),d(e.title)||i.push(t("missing_title","Dashboard intent needs a title.","title"));const o=Array.isArray(e.inputs)?e.inputs:[],a=M(o.filter(u).map(c=>c.id).filter(c=>typeof c=="string"));a&&i.push(t("duplicate_input_id",`Duplicate input id: ${a}.`,"inputs"));for(const[c,l]of o.entries()){const f=`inputs.${c}`;if(!u(l)){i.push(t("invalid_input","Dashboard input must be an object.",f));continue}d(l.id)||i.push(t("missing_input_id","Input needs an id.",`${f}.id`)),d(l.label)||i.push(t("missing_input_label","Input needs a label.",`${f}.label`)),!l.field||!d(l.field.name)?i.push(t("missing_input_field","Input needs a field.",`${f}.field`)):p(l.field,`${f}.field`,i)}const r=Array.isArray(e.sections)?e.sections:[];r.length===0&&i.push(t("missing_sections","Dashboard intent needs at least one section.","sections"));const s=r.flatMap(c=>c&&typeof c=="object"&&Array.isArray(c.views)?c.views.filter(u).map(l=>l.id).filter(l=>!!l):[]),m=M(s);m&&i.push(t("duplicate_view_id",`Duplicate dashboard view id: ${m}.`,"sections"));for(const[c,l]of r.entries()){const f=`sections.${c}`;if(!l||typeof l!="object"){i.push(t("invalid_section","Dashboard section must be an object.",f));continue}if(d(l.title)||i.push(t("missing_section_title","Dashboard section needs a title.",f)),!Array.isArray(l.views)||l.views.length===0){i.push(t("missing_section_views","Dashboard section needs at least one view.",`${f}.views`));continue}for(const[h,g]of l.views.entries())W(g,`${f}.views.${h}`,i,n)}return{ok:i.length===0,errors:i,warnings:n}}exports.normalizeSemaphorAnalyticsFilterOperator=N;exports.normalizeSemaphorInputOperator=q;exports.parseSemaphorIsoTimeWindowBoundary=v;exports.validateSemaphorAnalyticsIntent=A;exports.validateSemaphorAnalyticsRecoveryPlan=J;exports.validateSemaphorDashboardIntent=ee;exports.validateSemaphorOperationIntent=T;