react-semaphor 0.1.360 → 0.1.361

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.
@@ -1,5 +1,5 @@
1
1
  import { v as x } from "./validators-BnLhuIhd.js";
2
- import { s as S, c as F, b as A } from "./source-identity-qAmkNtEK.js";
2
+ import { s as A, c as F, b } from "./source-identity-qAmkNtEK.js";
3
3
  function M(e) {
4
4
  var r;
5
5
  const t = R(e);
@@ -8,7 +8,7 @@ function M(e) {
8
8
  kind: "metric",
9
9
  id: e.id,
10
10
  label: e.label,
11
- source: h(e),
11
+ source: p(e),
12
12
  metrics: t,
13
13
  primaryMetric: P(e, t),
14
14
  dateField: e.dateField ? a(e.dateField, "date") : void 0,
@@ -19,7 +19,7 @@ function M(e) {
19
19
  field: a(e.orderBy.field),
20
20
  direction: e.orderBy.direction
21
21
  } : void 0,
22
- inputs: p(e.inputs),
22
+ inputs: g(e.inputs),
23
23
  limit: e.limit
24
24
  };
25
25
  }
@@ -32,7 +32,7 @@ function T(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 } : {},
@@ -45,7 +45,7 @@ function P(e, t) {
45
45
  if (!e.primaryMetric)
46
46
  return t[0] || { name: "", role: "measure" };
47
47
  const r = a(e.primaryMetric, "measure"), i = H(r, t), o = i.length === 1 ? i[0] : void 0;
48
- return o ? b(r, o) : r;
48
+ return o ? _(r, o) : r;
49
49
  }
50
50
  function R(e) {
51
51
  const t = [];
@@ -59,18 +59,18 @@ function R(e) {
59
59
  t.push(r);
60
60
  continue;
61
61
  }
62
- t[i] = b(t[i], r);
62
+ t[i] = _(t[i], r);
63
63
  }
64
64
  return t;
65
65
  }
66
66
  function z(e, t) {
67
- return S(e, t) && c(e) === c(t);
67
+ return A(e, t) && f(e) === f(t);
68
68
  }
69
69
  function B(e, t) {
70
- return c(t) === c(e);
70
+ return f(t) === f(e);
71
71
  }
72
72
  function D(e, t) {
73
- return t.name !== e.name || e.source && !S(t, e) ? !1 : B(e, t);
73
+ return t.name !== e.name || e.source && !A(t, e) ? !1 : B(e, t);
74
74
  }
75
75
  function H(e, t) {
76
76
  const r = t.filter(
@@ -78,10 +78,10 @@ function H(e, t) {
78
78
  );
79
79
  return e.aggregate !== void 0, r;
80
80
  }
81
- function c(e) {
81
+ function f(e) {
82
82
  return (e.aggregate || "SUM").toUpperCase();
83
83
  }
84
- function b(e, t) {
84
+ function _(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}.`
@@ -91,7 +91,7 @@ function b(e, t) {
91
91
  aggregate: e.aggregate || t.aggregate
92
92
  };
93
93
  }
94
- function O(e) {
94
+ function N(e) {
95
95
  if ("sort" in e)
96
96
  throw new Error(
97
97
  "useSemaphorRecords supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet."
@@ -100,13 +100,13 @@ function O(e) {
100
100
  throw new Error(
101
101
  "useSemaphorRecords needs at least one field."
102
102
  );
103
- const t = j(e.fields);
103
+ const t = O(e.fields);
104
104
  return {
105
105
  version: 1,
106
106
  kind: "records",
107
107
  id: e.id,
108
108
  label: e.label,
109
- source: h(e),
109
+ source: p(e),
110
110
  fields: t,
111
111
  dateField: e.dateField ? a(e.dateField, "date") : void 0,
112
112
  timeGrain: e.timeGrain,
@@ -114,11 +114,11 @@ function O(e) {
114
114
  field: a(e.orderBy.field),
115
115
  direction: e.orderBy.direction
116
116
  } : void 0,
117
- inputs: p(e.inputs),
117
+ inputs: g(e.inputs),
118
118
  limit: e.limit
119
119
  };
120
120
  }
121
- function j(e) {
121
+ function O(e) {
122
122
  return e.map((t) => {
123
123
  const r = a(t);
124
124
  if (!r.role)
@@ -128,13 +128,13 @@ function j(e) {
128
128
  return r;
129
129
  });
130
130
  }
131
- function N(e) {
131
+ function j(e) {
132
132
  return {
133
133
  version: 1,
134
134
  kind: "inputOptions",
135
135
  id: e.id,
136
136
  label: e.label,
137
- source: h(e),
137
+ source: p(e),
138
138
  field: a(e.field, "dimension"),
139
139
  search: e.search,
140
140
  limit: e.limit
@@ -153,17 +153,17 @@ function q(e) {
153
153
  ...e.field ? { field: e.field } : {}
154
154
  };
155
155
  }
156
- function ce(e) {
157
- const t = p(e);
156
+ function fe(e) {
157
+ const t = g(e);
158
158
  return t.length > 0 ? t : void 0;
159
159
  }
160
160
  function E(e) {
161
161
  return (e || []).map(G);
162
162
  }
163
- function fe(e) {
163
+ function ue(e) {
164
164
  return E(e).filter((t) => t.isActive);
165
165
  }
166
- function ue(e) {
166
+ function me(e) {
167
167
  return e.kind === "filter" ? {
168
168
  inputId: e.id,
169
169
  kind: e.kind,
@@ -176,7 +176,7 @@ function ue(e) {
176
176
  label: e.label
177
177
  };
178
178
  }
179
- function me(e = []) {
179
+ function he(e = []) {
180
180
  return e.map(
181
181
  (t) => typeof t == "object" ? t : {
182
182
  label: String(t),
@@ -197,7 +197,7 @@ function G(e) {
197
197
  value: e.value
198
198
  };
199
199
  }
200
- function h(e) {
200
+ function p(e) {
201
201
  return e.source;
202
202
  }
203
203
  function V(e) {
@@ -210,7 +210,7 @@ function a(e, t) {
210
210
  role: e.role || t
211
211
  };
212
212
  }
213
- function p(e) {
213
+ function g(e) {
214
214
  return (e || []).map(q);
215
215
  }
216
216
  function W(e) {
@@ -260,7 +260,7 @@ function K(e, t = {}) {
260
260
  o.includePopulation = i.includePopulation;
261
261
  }
262
262
  if (i.calendarContext !== void 0) {
263
- const n = J(
263
+ const n = X(
264
264
  i.calendarContext,
265
265
  {
266
266
  pathPrefix: `${r}.calendarContext`,
@@ -273,7 +273,7 @@ function K(e, t = {}) {
273
273
  }
274
274
  return { ok: !0, analysisOptions: o };
275
275
  }
276
- function he(e) {
276
+ function pe(e) {
277
277
  const t = e.hooks.map(
278
278
  (o, n) => Q(o, n, {
279
279
  fieldCatalogs: e.fieldCatalogs || [],
@@ -292,9 +292,9 @@ function he(e) {
292
292
  function Q(e, t, r) {
293
293
  const i = `hooks.${t}`;
294
294
  try {
295
- const o = X(e), n = ae(e, o), d = x(o), l = [
295
+ const o = Y(e), n = se(e, o), d = x(o), l = [
296
296
  ...d.errors.map(
297
- (u) => y(u, {
297
+ (m) => v(m, {
298
298
  hook: e.hook,
299
299
  hookId: n,
300
300
  pathPrefix: i,
@@ -303,7 +303,7 @@ function Q(e, t, r) {
303
303
  })
304
304
  ),
305
305
  ...d.warnings.map(
306
- (u) => y(u, {
306
+ (m) => v(m, {
307
307
  hook: e.hook,
308
308
  hookId: n,
309
309
  pathPrefix: i,
@@ -311,7 +311,7 @@ function Q(e, t, r) {
311
311
  intent: o
312
312
  })
313
313
  ),
314
- ...Y({
314
+ ...Z({
315
315
  hookSpec: e,
316
316
  hookId: n,
317
317
  intent: o,
@@ -319,22 +319,22 @@ function Q(e, t, r) {
319
319
  fieldCatalogs: r.fieldCatalogs,
320
320
  requireFieldCatalog: r.requireFieldCatalog
321
321
  }),
322
- ...te({
322
+ ...re({
323
323
  hookSpec: e,
324
324
  hookId: n,
325
325
  intent: o,
326
326
  pathPrefix: i,
327
327
  validateTimezone: r.validateTimezone
328
328
  })
329
- ], $ = ne(d, l);
329
+ ], c = ae(d, l);
330
330
  return {
331
331
  hook: e.hook,
332
332
  hookId: n,
333
333
  intent: o,
334
334
  diagnostics: l,
335
- executionResult: I({
335
+ executionResult: S({
336
336
  intent: o,
337
- validation: $,
337
+ validation: c,
338
338
  diagnostics: l
339
339
  })
340
340
  };
@@ -345,13 +345,13 @@ function Q(e, t, r) {
345
345
  message: o instanceof Error ? o.message : String(o),
346
346
  path: i,
347
347
  hook: e.hook,
348
- hookId: C(e.spec)
349
- }, d = w([n]);
348
+ hookId: $(e.spec)
349
+ }, d = C([n]);
350
350
  return {
351
351
  hook: e.hook,
352
352
  hookId: n.hookId,
353
353
  diagnostics: [n],
354
- executionResult: I({
354
+ executionResult: S({
355
355
  validation: d,
356
356
  diagnostics: [n]
357
357
  })
@@ -373,24 +373,27 @@ function s(e, t) {
373
373
  function L(e) {
374
374
  return e === "absolute_delta" || e === "largest_negative" || e === "largest_positive" || e === "positive_and_negative" || e === "all";
375
375
  }
376
- function J(e, t) {
377
- var l;
376
+ function J(e) {
377
+ return e.trim().length > 0 && !Number.isNaN(Date.parse(e));
378
+ }
379
+ function X(e, t) {
380
+ var c;
378
381
  if (!e || typeof e != "object" || Array.isArray(e))
379
382
  return s(
380
383
  t.pathPrefix,
381
384
  'Data App analysis option "calendarContext" must be an object.'
382
385
  );
383
- const r = e, i = r.tz, o = r.weekStart, n = r.anchor, d = typeof i == "string" ? ((l = t.validateTimezone) == null ? void 0 : l.call(t, i)) ?? i : null;
384
- return d ? typeof o != "number" || !Number.isInteger(o) || o < 0 || o > 6 ? s(
386
+ const r = e, i = r.tz, o = r.weekStart, n = r.anchor, d = n && typeof n == "object" && !Array.isArray(n) ? n.iso : void 0, l = typeof i == "string" ? ((c = t.validateTimezone) == null ? void 0 : c.call(t, i)) ?? i : null;
387
+ return l ? typeof o != "number" || !Number.isInteger(o) || o < 0 || o > 6 ? s(
385
388
  `${t.pathPrefix}.weekStart`,
386
389
  'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'
387
- ) : n !== "now" && !(n && typeof n == "object" && !Array.isArray(n) && typeof n.iso == "string") ? s(
390
+ ) : n !== "now" && !(typeof d == "string" && J(d)) ? s(
388
391
  `${t.pathPrefix}.anchor`,
389
- 'Data App analysis option "calendarContext.anchor" must be "now" or an object with an iso string.'
392
+ 'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'
390
393
  ) : {
391
394
  ok: !0,
392
395
  calendarContext: {
393
- tz: d,
396
+ tz: l,
394
397
  weekStart: o,
395
398
  anchor: n
396
399
  }
@@ -399,19 +402,19 @@ function J(e, t) {
399
402
  'Data App analysis option "calendarContext.tz" must be a valid timezone string.'
400
403
  );
401
404
  }
402
- function X(e) {
403
- return e.hook === "useSemaphorMetric" ? M(e.spec) : e.hook === "useSemaphorAnalysis" ? T(e.spec) : e.hook === "useSemaphorRecords" ? O(e.spec) : N(e.spec);
404
- }
405
405
  function Y(e) {
406
+ return e.hook === "useSemaphorMetric" ? M(e.spec) : e.hook === "useSemaphorAnalysis" ? T(e.spec) : e.hook === "useSemaphorRecords" ? N(e.spec) : j(e.spec);
407
+ }
408
+ function Z(e) {
406
409
  if (e.fieldCatalogs.length === 0 && !e.requireFieldCatalog)
407
410
  return [];
408
- const t = ie(e.fieldCatalogs, e.intent.source);
411
+ const t = oe(e.fieldCatalogs, e.intent.source);
409
412
  return t ? [
410
- ...Z({
413
+ ...ee({
411
414
  ...e,
412
415
  catalog: t
413
416
  }),
414
- ...ee({
417
+ ...te({
415
418
  ...e,
416
419
  catalog: t
417
420
  })
@@ -428,8 +431,8 @@ function Y(e) {
428
431
  }
429
432
  ];
430
433
  }
431
- function Z(e) {
432
- return re(e.intent).flatMap(({ field: t, path: r }) => _(e.catalog, t, e.intent.source) ? [] : [
434
+ function ee(e) {
435
+ return ie(e.intent).flatMap(({ field: t, path: r }) => w(e.catalog, t, e.intent.source) ? [] : [
433
436
  {
434
437
  severity: "error",
435
438
  code: "missing_field",
@@ -438,17 +441,17 @@ function Z(e) {
438
441
  hook: e.hookSpec.hook,
439
442
  hookId: e.hookId,
440
443
  intentId: e.intent.id,
441
- source: f(t, e.intent.source),
444
+ source: u(t, e.intent.source),
442
445
  field: t
443
446
  }
444
447
  ]);
445
448
  }
446
- function ee(e) {
449
+ function te(e) {
447
450
  return ("inputs" in e.intent ? e.intent.inputs || [] : []).flatMap((r, i) => {
448
451
  if (!r.field)
449
452
  return [];
450
- const o = f(r.field, e.intent.source);
451
- return A(o, e.intent.source) ? _(e.catalog, r.field, e.intent.source) ? [] : [
453
+ const o = u(r.field, e.intent.source);
454
+ return b(o, e.intent.source) ? w(e.catalog, r.field, e.intent.source) ? [] : [
452
455
  {
453
456
  severity: "error",
454
457
  code: "missing_field",
@@ -475,7 +478,7 @@ function ee(e) {
475
478
  ];
476
479
  });
477
480
  }
478
- function te(e) {
481
+ function re(e) {
479
482
  if (e.hookSpec.hook !== "useSemaphorAnalysis")
480
483
  return [];
481
484
  const t = K(e.hookSpec.spec, {
@@ -493,7 +496,7 @@ function te(e) {
493
496
  source: e.intent.source
494
497
  }));
495
498
  }
496
- function re(e) {
499
+ function ie(e) {
497
500
  return e.kind === "metric" ? [
498
501
  ...e.metrics.map((t, r) => ({
499
502
  field: t,
@@ -519,35 +522,35 @@ function re(e) {
519
522
  ...e.orderBy ? [{ field: e.orderBy.field, path: "spec.orderBy.field" }] : []
520
523
  ] : e.kind === "inputOptions" ? [{ field: e.field, path: "spec.field" }] : [];
521
524
  }
522
- function ie(e, t) {
523
- return e.find((r) => m(r, t));
525
+ function oe(e, t) {
526
+ return e.find((r) => h(r, t));
524
527
  }
525
- function _(e, t, r) {
526
- const i = f(t, r);
527
- if (m(e, i))
528
+ function w(e, t, r) {
529
+ const i = u(t, r);
530
+ if (h(e, i))
528
531
  return e.fields.find(
529
- (o) => oe(o, t) && m(
532
+ (o) => ne(o, t) && h(
530
533
  e,
531
- f(o, e.source)
534
+ u(o, e.source)
532
535
  )
533
536
  );
534
537
  }
535
- function m(e, t) {
538
+ function h(e, t) {
536
539
  return [e.source, ...e.sourceAliases || []].some(
537
- (r) => A(r, t)
540
+ (r) => b(r, t)
538
541
  );
539
542
  }
540
- function f(e, t) {
543
+ function u(e, t) {
541
544
  return e.source || t;
542
545
  }
543
- function oe(e, t) {
544
- const r = g(e.name), i = g(t.name);
546
+ function ne(e, t) {
547
+ const r = y(e.name), i = y(t.name);
545
548
  return !!(r && i && r === i);
546
549
  }
547
- function g(e) {
550
+ function y(e) {
548
551
  return (e || "").trim().toLowerCase();
549
552
  }
550
- function y(e, t) {
553
+ function v(e, t) {
551
554
  return {
552
555
  severity: t.severity,
553
556
  code: e.code || "invalid_analytics_intent",
@@ -559,15 +562,15 @@ function y(e, t) {
559
562
  source: t.intent.source
560
563
  };
561
564
  }
562
- function ne(e, t) {
563
- const r = w(t);
565
+ function ae(e, t) {
566
+ const r = C(t);
564
567
  return {
565
568
  ok: r.ok && e.ok,
566
- errors: k([
569
+ errors: I([
567
570
  ...e.errors,
568
571
  ...r.errors
569
572
  ]),
570
- warnings: k([
573
+ warnings: I([
571
574
  ...e.warnings,
572
575
  ...r.warnings
573
576
  ]),
@@ -577,8 +580,8 @@ function ne(e, t) {
577
580
  ]
578
581
  };
579
582
  }
580
- function w(e) {
581
- const t = e.filter((i) => i.severity === "error").map(v), r = e.filter((i) => i.severity === "warning").map(v);
583
+ function C(e) {
584
+ const t = e.filter((i) => i.severity === "error").map(k), r = e.filter((i) => i.severity === "warning").map(k);
582
585
  return {
583
586
  ok: t.length === 0,
584
587
  errors: t,
@@ -595,7 +598,7 @@ function w(e) {
595
598
  })
596
599
  };
597
600
  }
598
- function v(e) {
601
+ function k(e) {
599
602
  var t;
600
603
  return {
601
604
  code: e.code,
@@ -611,14 +614,14 @@ function v(e) {
611
614
  }
612
615
  };
613
616
  }
614
- function k(e) {
617
+ function I(e) {
615
618
  const t = /* @__PURE__ */ new Set();
616
619
  return e.filter((r) => {
617
620
  const i = `${r.code}:${r.path || ""}:${r.message}`;
618
621
  return t.has(i) ? !1 : (t.add(i), !0);
619
622
  });
620
623
  }
621
- function I(e) {
624
+ function S(e) {
622
625
  var r, i;
623
626
  const t = e.diagnostics.filter((o) => o.severity === "error");
624
627
  return {
@@ -642,28 +645,28 @@ function I(e) {
642
645
  }
643
646
  };
644
647
  }
645
- function ae(e, t) {
646
- return t.id || C(e.spec);
648
+ function se(e, t) {
649
+ return t.id || $(e.spec);
647
650
  }
648
- function C(e) {
651
+ function $(e) {
649
652
  if (!e || typeof e != "object" || !("id" in e))
650
653
  return;
651
654
  const t = e.id;
652
655
  return typeof t == "string" && t.trim() ? t : void 0;
653
656
  }
654
657
  export {
655
- le as a,
658
+ ce as a,
656
659
  T as b,
657
660
  M as c,
658
- O as d,
659
- N as e,
660
- ue as f,
661
+ N as d,
662
+ j as e,
663
+ me as f,
661
664
  q as g,
662
665
  U as h,
663
- ce as i,
666
+ fe as i,
664
667
  E as j,
665
668
  K as k,
666
- me as n,
667
- fe as t,
668
- he as v
669
+ he as n,
670
+ ue as t,
671
+ pe as v
669
672
  };
@@ -0,0 +1 @@
1
+ "use strict";const B=require("./validators-Cu_w8ZEP.js"),c=require("./source-identity-C-xaeE_I.js");function g(e){var r;const t=H(e);return{version:1,kind:"metric",id:e.id,label:e.label,source:y(e),metrics:t,primaryMetric:O(e,t),dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,dimensions:(r=e.dimensions)==null?void 0:r.map(i=>a(i,"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 b(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 D(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 O(e,t){if(!e.primaryMetric)return t[0]||{name:"",role:"measure"};const r=a(e.primaryMetric,"measure"),i=E(r,t),o=i.length===1?i[0]:void 0;return o?_(r,o):r}function H(e){const t=[];for(const r of e.metrics.map(i=>a(i,"measure"))){if(!r.name)continue;const i=t.findIndex(o=>N(o,r));if(i===-1){t.push(r);continue}t[i]=_(t[i],r)}return t}function N(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 E(e,t){const r=t.filter(i=>q(e,i));return e.aggregate!==void 0,r}function u(e){return(e.aggregate||"SUM").toUpperCase()}function _(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 w(e){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(!L(e))throw new Error("useSemaphorRecords needs at least one field.");const t=U(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,orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:v(e.inputs),limit:e.limit}}function U(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 C(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 $(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 V(e){const t=v(e);return t.length>0?t:void 0}function F(e){return(e||[]).map(K)}function G(e){return F(e).filter(t=>t.isActive)}function Q(e){return e.kind==="filter"?{inputId:e.id,kind:e.kind,label:e.label,field:a(e.field,"dimension"),operator:e.operator||"in"}:{inputId:e.id,kind:e.kind,label:e.label}}function W(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 K(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 L(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($)}function J(e){if(e)return e}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 i=e,o={};if(i.chartTitle!==void 0){if(typeof i.chartTitle!="string")return s(`${r}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');o.chartTitle=i.chartTitle}if(i.chartType!==void 0){if(typeof i.chartType!="string")return s(`${r}.chartType`,'Data App analysis option "chartType" must be a string.');o.chartType=i.chartType}if(i.driverMode!==void 0){if(!Z(i.driverMode))return s(`${r}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');o.driverMode=i.driverMode}if(i.includePopulation!==void 0){if(typeof i.includePopulation!="boolean")return s(`${r}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');o.includePopulation=i.includePopulation}if(i.calendarContext!==void 0){const n=te(i.calendarContext,{pathPrefix:`${r}.calendarContext`,validateTimezone:t.validateTimezone});if(!n.ok)return n;o.calendarContext=n.calendarContext}return{ok:!0,analysisOptions:o}}function X(e){const t=e.hooks.map((o,n)=>Y(o,n,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),r=t.flatMap(o=>o.diagnostics),i=t.map(o=>o.executionResult);return{ok:r.every(o=>o.severity!=="error"),diagnostics:r,hooks:t,intents:t.flatMap(o=>o.intent?[o.intent]:[]),executionResults:i}}function Y(e,t,r){const i=`hooks.${t}`;try{const o=re(e),n=fe(e,o),d=B.validateSemaphorAnalyticsIntent(o),l=[...d.errors.map(m=>I(m,{hook:e.hook,hookId:n,pathPrefix:i,severity:"error",intent:o})),...d.warnings.map(m=>I(m,{hook:e.hook,hookId:n,pathPrefix:i,severity:"warning",intent:o})),...ie({hookSpec:e,hookId:n,intent:o,pathPrefix:i,fieldCatalogs:r.fieldCatalogs,requireFieldCatalog:r.requireFieldCatalog}),...ae({hookSpec:e,hookId:n,intent:o,pathPrefix:i,validateTimezone:r.validateTimezone})],f=ce(d,l);return{hook:e.hook,hookId:n,intent:o,diagnostics:l,executionResult:M({intent:o,validation:f,diagnostics:l})}}catch(o){const n={severity:"error",code:"invalid_hook_spec",message:o instanceof Error?o.message:String(o),path:i,hook:e.hook,hookId:z(e.spec)},d=P([n]);return{hook:e.hook,hookId:n.hookId,diagnostics:[n],executionResult:M({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,i=r.tz,o=r.weekStart,n=r.anchor,d=n&&typeof n=="object"&&!Array.isArray(n)?n.iso:void 0,l=typeof i=="string"?((f=t.validateTimezone)==null?void 0:f.call(t,i))??i:null;return l?typeof o!="number"||!Number.isInteger(o)||o<0||o>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:o,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"?b(e.spec):e.hook==="useSemaphorRecords"?w(e.spec):C(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,i)=>{if(!r.field)return[];const o=h(r.field,e.intent.source);return c.semaphorSourcesReferToSameDataset(o,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.${i}.field`,hook:e.hookSpec.hook,hookId:e.hookId,intentId:e.intent.id,source:o,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.${i}.field`,hook:e.hookSpec.hook,hookId:e.hookId,intentId:e.intent.id,source:o,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.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 i=h(t,r);if(p(e,i))return e.fields.find(o=>le(o,t)&&p(e,h(o,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){const r=k(e.name),i=k(t.name);return!!(r&&i&&r===i)}function k(e){return(e||"").trim().toLowerCase()}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=P(t);return{ok:r.ok&&e.ok,errors:A([...e.errors,...r.errors]),warnings:A([...e.warnings,...r.warnings]),repairHints:[...e.repairHints,...r.repairHints]}}function P(e){const t=e.filter(i=>i.severity==="error").map(S),r=e.filter(i=>i.severity==="warning").map(S);return{ok:t.length===0,errors:t,warnings:r,repairHints:t.map(i=>{var o,n;return{code:i.code,message:i.message,fieldRole:i.fieldRole,invalidField:(o=i.repairHint)==null?void 0:o.invalidField,recommendedNextStep:((n=i.repairHint)==null?void 0:n.recommendedNextStep)||"Update the Data App SDK hook spec to use visible Semaphor source and field refs."}})}}function S(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 A(e){const t=new Set;return e.filter(r=>{const i=`${r.code}:${r.path||""}:${r.message}`;return t.has(i)?!1:(t.add(i),!0)})}function M(e){var r,i;const t=e.diagnostics.filter(o=>o.severity==="error");return{intentId:(r=e.intent)==null?void 0:r.id,status:t.length?"failed":"answered",resultShape:(i=e.intent)==null?void 0:i.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(o=>o.code==="missing_field").flatMap(o=>{var n;return(n=o.field)!=null&&n.name?[o.field.name]:[]}),warnings:e.diagnostics.filter(o=>o.severity==="warning").map(o=>o.message),metadata:{validationKind:"data_app_sdk_hook_spec"}}}function fe(e,t){return t.id||z(e.spec)}function z(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=W;exports.toSemaphorActiveInputSnapshots=G;exports.toSemaphorAnalysisIntent=b;exports.toSemaphorAnalysisQueryOptions=D;exports.toSemaphorInputBinding=$;exports.toSemaphorInputBindings=V;exports.toSemaphorInputOptionsIntent=C;exports.toSemaphorInputSnapshots=F;exports.toSemaphorInputSpec=Q;exports.toSemaphorMetricIntent=g;exports.toSemaphorRecordsIntent=w;exports.validateSemaphorDataAppHookSpecs=X;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../chunks/validation-C_WDLZdp.js"),O=require("../chunks/index-BxM99sFL.js"),u=require("react"),E=require("react/jsx-runtime"),g=require("../chunks/validators-Cu_w8ZEP.js");function R(){return{executeAnalysis:(t,e,n)=>y(t,e,n??{}),executeMetric:(t,e)=>y(t,e),executeRecords:(t,e)=>y(t,e),executeInputOptions:(t,e)=>y(t,e)}}async function y(t,e,n){if(!e.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const o=await fetch(T(e),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},body:JSON.stringify({intent:t,activeInputs:e.activeInputs,...n?{analysisOptions:n}:{},resultShape:t.kind})}),r=await b(o);if(!o.ok||r.error)throw new Error(r.error||`Semaphor Data App execution failed with status ${o.status}.`);return r}async function b(t){const e=await t.text().catch(()=>"");if(!e.trim())return t.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(e)}catch{return t.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:e}:{error:M(t,e),details:e}}}function M(t,e){const n=t.statusText?` ${t.statusText}`:"",o=e.replace(/\s+/g," ").trim();return o?`Semaphor Data App execution failed with status ${t.status}${n}: ${o.slice(0,240)}`:`Semaphor Data App execution failed with status ${t.status}${n}.`}function T(t){const e=C(t).replace(/\/+$/,"");return e?e.endsWith("/api")?`${e}/v1/data-app/execute`:`${e}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function C(t){if(t.apiBaseUrl)return t.apiBaseUrl;if(!t.token)return"";try{return O.jwtDecode(t.token).apiServiceUrl||""}catch{return""}}const x=u.createContext({});function k(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function q(){return u.useContext(x)}function K({token:t,apiBaseUrl:e,executor:n,children:o}){var l;const r=k(),s=((l=r==null?void 0:r.authToken)==null?void 0:l.accessToken)||t,i=(r==null?void 0:r.dataApiBaseUrl)||(r==null?void 0:r.apiBaseUrl)||e,m=u.useMemo(()=>R(),[]),c=n||m,d=u.useMemo(()=>({token:s,apiBaseUrl:i,executor:c}),[i,c,s]);return E.jsx(x.Provider,{value:d,children:o})}const f={value:null},A={},$={records:[]},D={options:[]};function _(t){const e=a.toSemaphorActiveInputSnapshots(t.inputs),n=a.toSemaphorAnalysisQueryOptions(t);try{const o=a.toSemaphorAnalysisIntent(t),r=v(o);return r?{error:r,activeInputs:e,analysisOptions:n,queryKey:p(void 0,e,r,n),idleData:A}:{intent:o,error:null,activeInputs:e,analysisOptions:n,queryKey:p(o,e,void 0,n),idleData:A}}catch(o){const r=S(o);return{error:r,activeInputs:e,analysisOptions:n,queryKey:p(void 0,e,r,n),idleData:A}}}function P(t){const e=a.toSemaphorActiveInputSnapshots(t.inputs);try{const n=a.toSemaphorMetricIntent(t),o=v(n);return o?{error:o,activeInputs:e,queryKey:p(void 0,e,o),idleData:f}:{intent:n,error:null,activeInputs:e,queryKey:p(n,e),idleData:f}}catch(n){const o=S(n);return{error:o,activeInputs:e,queryKey:p(void 0,e,o),idleData:f}}}function V(t){const e=a.toSemaphorActiveInputSnapshots(t.inputs),n=$;try{const o=a.toSemaphorRecordsIntent(t),r=v(o);return r?{error:r,activeInputs:e,queryKey:p(void 0,e,r),idleData:n}:{intent:o,error:null,activeInputs:e,queryKey:p(o,e),idleData:n}}catch(o){const r=S(o);return{error:r,activeInputs:e,queryKey:p(void 0,e,r),idleData:n}}}function w(t){try{const e=a.toSemaphorInputOptionsIntent(t),n=v(e);return n?{error:n,queryKey:p(void 0,void 0,n),idleData:D}:{intent:e,error:null,queryKey:p(e),idleData:D}}catch(e){const n=S(e);return{error:n,queryKey:p(void 0,void 0,n),idleData:D}}}function S(t){return t instanceof Error?t:new Error(String(t))}function v(t){const e=g.validateSemaphorAnalyticsIntent(t);if(e.ok)return null;const n=e.errors.map(o=>o.path?`${o.code} at ${o.path}: ${o.message}`:`${o.code}: ${o.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${n}`)}function p(t,e,n,o){return JSON.stringify({intent:t,activeInputs:e,analysisOptions:o,error:n==null?void 0:n.message})}function B(t){const[e,n]=u.useState(t.defaultValue),o=Object.prototype.hasOwnProperty.call(t,"value"),r=o?t.value:e,s=u.useMemo(()=>a.normalizeSemaphorInputOptions(t.options),[t.options]),i=u.useCallback(c=>{var l;const d=c;(l=t.onValueChange)==null||l.call(t,d),o||n(d)},[o,t]),m=u.useCallback(()=>i(void 0),[i]);return u.useMemo(()=>{const c=a.toSemaphorInputSpec(t);return{id:t.id,kind:t.kind,label:t.label,field:c.field,operator:c.operator,controlRole:t.kind==="control"?t.role:void 0,value:r,options:s,isActive:a.hasSemaphorInputValue(r),setValue:i,clear:m,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:t.kind,label:t.label,value:r,isActive:a.hasSemaphorInputValue(r),operator:c.operator,controlRole:t.kind==="control"?t.role:void 0})}},[m,s,i,t,r])}function Q(t){const e=u.useMemo(()=>_(t),[t]),n=u.useCallback(s=>{var i;return e.intent?(i=s.executor)==null?void 0:i.executeAnalysis(e.intent,s,e.analysisOptions):void 0},[e.analysisOptions,e.intent]),o=I(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,...r||{},status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function U(t){const e=u.useMemo(()=>P(t),[t]),n=u.useCallback(s=>{var i;return e.intent?(i=s.executor)==null?void 0:i.executeMetric(e.intent,s):void 0},[e.intent]),o=I(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,value:(r==null?void 0:r.value)??null,metrics:r==null?void 0:r.metrics,comparisonValue:r==null?void 0:r.comparisonValue,delta:r==null?void 0:r.delta,deltaPercent:r==null?void 0:r.deltaPercent,records:r==null?void 0:r.records,executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function z(t){const e=u.useMemo(()=>V(t),[t]),n=u.useCallback(s=>{var i;return e.intent?(i=s.executor)==null?void 0:i.executeRecords(e.intent,s):void 0},[e.intent]),o=I(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,records:(r==null?void 0:r.records)||[],columns:r==null?void 0:r.columns,rowCount:r==null?void 0:r.rowCount,executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function L(t){const e=u.useMemo(()=>w(t),[t]),n=u.useCallback(s=>{var i;return e.intent?(i=s.executor)==null?void 0:i.executeInputOptions(e.intent,s):void 0},[e.intent]),o=I(e.queryKey,n,e.idleData),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,options:(r==null?void 0:r.options)||[],executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function I(t,e,n,o){const r=q(),s=u.useRef(e),i=u.useRef(o),[m,c]=u.useState({status:"idle",data:n,error:null});return s.current=e,i.current=o,u.useEffect(()=>{let d;try{d=s.current({...r,activeInputs:i.current})}catch(h){c({status:"error",data:n,error:S(h)});return}if(!d){c({status:"idle",data:n,error:null});return}let l=!1;return c(h=>({status:"loading",data:h.data,error:null})),d.then(h=>{l||c({status:"success",data:h,error:null})}).catch(h=>{l||c({status:"error",data:n,error:S(h)})}),()=>{l=!0}},[n,t,r]),m}exports.hasSemaphorInputValue=a.hasSemaphorInputValue;exports.normalizeSemaphorAnalysisQueryOptions=a.normalizeSemaphorAnalysisQueryOptions;exports.normalizeSemaphorInputOptions=a.normalizeSemaphorInputOptions;exports.toSemaphorActiveInputSnapshots=a.toSemaphorActiveInputSnapshots;exports.toSemaphorAnalysisIntent=a.toSemaphorAnalysisIntent;exports.toSemaphorAnalysisQueryOptions=a.toSemaphorAnalysisQueryOptions;exports.toSemaphorInputBinding=a.toSemaphorInputBinding;exports.toSemaphorInputBindings=a.toSemaphorInputBindings;exports.toSemaphorInputOptionsIntent=a.toSemaphorInputOptionsIntent;exports.toSemaphorInputSnapshots=a.toSemaphorInputSnapshots;exports.toSemaphorInputSpec=a.toSemaphorInputSpec;exports.toSemaphorMetricIntent=a.toSemaphorMetricIntent;exports.toSemaphorRecordsIntent=a.toSemaphorRecordsIntent;exports.validateSemaphorDataAppHookSpecs=a.validateSemaphorDataAppHookSpecs;exports.SemaphorDataAppContext=x;exports.SemaphorDataAppProvider=K;exports.createSemaphorQueryExecutor=R;exports.readWindowRuntime=k;exports.useSemaphorAnalysis=Q;exports.useSemaphorDataAppRuntime=q;exports.useSemaphorInput=B;exports.useSemaphorInputOptions=L;exports.useSemaphorMetric=U;exports.useSemaphorRecords=z;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../chunks/validation-bKtG7HIt.js"),O=require("../chunks/index-BxM99sFL.js"),u=require("react"),E=require("react/jsx-runtime"),g=require("../chunks/validators-Cu_w8ZEP.js");function R(){return{executeAnalysis:(t,e,n)=>y(t,e,n??{}),executeMetric:(t,e)=>y(t,e),executeRecords:(t,e)=>y(t,e),executeInputOptions:(t,e)=>y(t,e)}}async function y(t,e,n){if(!e.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const o=await fetch(T(e),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.token}`},body:JSON.stringify({intent:t,activeInputs:e.activeInputs,...n?{analysisOptions:n}:{},resultShape:t.kind})}),r=await b(o);if(!o.ok||r.error)throw new Error(r.error||`Semaphor Data App execution failed with status ${o.status}.`);return r}async function b(t){const e=await t.text().catch(()=>"");if(!e.trim())return t.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(e)}catch{return t.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:e}:{error:M(t,e),details:e}}}function M(t,e){const n=t.statusText?` ${t.statusText}`:"",o=e.replace(/\s+/g," ").trim();return o?`Semaphor Data App execution failed with status ${t.status}${n}: ${o.slice(0,240)}`:`Semaphor Data App execution failed with status ${t.status}${n}.`}function T(t){const e=C(t).replace(/\/+$/,"");return e?e.endsWith("/api")?`${e}/v1/data-app/execute`:`${e}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function C(t){if(t.apiBaseUrl)return t.apiBaseUrl;if(!t.token)return"";try{return O.jwtDecode(t.token).apiServiceUrl||""}catch{return""}}const x=u.createContext({});function k(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function q(){return u.useContext(x)}function K({token:t,apiBaseUrl:e,executor:n,children:o}){var l;const r=k(),s=((l=r==null?void 0:r.authToken)==null?void 0:l.accessToken)||t,i=(r==null?void 0:r.dataApiBaseUrl)||(r==null?void 0:r.apiBaseUrl)||e,m=u.useMemo(()=>R(),[]),c=n||m,d=u.useMemo(()=>({token:s,apiBaseUrl:i,executor:c}),[i,c,s]);return E.jsx(x.Provider,{value:d,children:o})}const f={value:null},A={},$={records:[]},D={options:[]};function _(t){const e=a.toSemaphorActiveInputSnapshots(t.inputs),n=a.toSemaphorAnalysisQueryOptions(t);try{const o=a.toSemaphorAnalysisIntent(t),r=v(o);return r?{error:r,activeInputs:e,analysisOptions:n,queryKey:p(void 0,e,r,n),idleData:A}:{intent:o,error:null,activeInputs:e,analysisOptions:n,queryKey:p(o,e,void 0,n),idleData:A}}catch(o){const r=S(o);return{error:r,activeInputs:e,analysisOptions:n,queryKey:p(void 0,e,r,n),idleData:A}}}function P(t){const e=a.toSemaphorActiveInputSnapshots(t.inputs);try{const n=a.toSemaphorMetricIntent(t),o=v(n);return o?{error:o,activeInputs:e,queryKey:p(void 0,e,o),idleData:f}:{intent:n,error:null,activeInputs:e,queryKey:p(n,e),idleData:f}}catch(n){const o=S(n);return{error:o,activeInputs:e,queryKey:p(void 0,e,o),idleData:f}}}function V(t){const e=a.toSemaphorActiveInputSnapshots(t.inputs),n=$;try{const o=a.toSemaphorRecordsIntent(t),r=v(o);return r?{error:r,activeInputs:e,queryKey:p(void 0,e,r),idleData:n}:{intent:o,error:null,activeInputs:e,queryKey:p(o,e),idleData:n}}catch(o){const r=S(o);return{error:r,activeInputs:e,queryKey:p(void 0,e,r),idleData:n}}}function w(t){try{const e=a.toSemaphorInputOptionsIntent(t),n=v(e);return n?{error:n,queryKey:p(void 0,void 0,n),idleData:D}:{intent:e,error:null,queryKey:p(e),idleData:D}}catch(e){const n=S(e);return{error:n,queryKey:p(void 0,void 0,n),idleData:D}}}function S(t){return t instanceof Error?t:new Error(String(t))}function v(t){const e=g.validateSemaphorAnalyticsIntent(t);if(e.ok)return null;const n=e.errors.map(o=>o.path?`${o.code} at ${o.path}: ${o.message}`:`${o.code}: ${o.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${n}`)}function p(t,e,n,o){return JSON.stringify({intent:t,activeInputs:e,analysisOptions:o,error:n==null?void 0:n.message})}function B(t){const[e,n]=u.useState(t.defaultValue),o=Object.prototype.hasOwnProperty.call(t,"value"),r=o?t.value:e,s=u.useMemo(()=>a.normalizeSemaphorInputOptions(t.options),[t.options]),i=u.useCallback(c=>{var l;const d=c;(l=t.onValueChange)==null||l.call(t,d),o||n(d)},[o,t]),m=u.useCallback(()=>i(void 0),[i]);return u.useMemo(()=>{const c=a.toSemaphorInputSpec(t);return{id:t.id,kind:t.kind,label:t.label,field:c.field,operator:c.operator,controlRole:t.kind==="control"?t.role:void 0,value:r,options:s,isActive:a.hasSemaphorInputValue(r),setValue:i,clear:m,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:t.kind,label:t.label,value:r,isActive:a.hasSemaphorInputValue(r),operator:c.operator,controlRole:t.kind==="control"?t.role:void 0})}},[m,s,i,t,r])}function Q(t){const e=u.useMemo(()=>_(t),[t]),n=u.useCallback(s=>{var i;return e.intent?(i=s.executor)==null?void 0:i.executeAnalysis(e.intent,s,e.analysisOptions):void 0},[e.analysisOptions,e.intent]),o=I(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,...r||{},status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function U(t){const e=u.useMemo(()=>P(t),[t]),n=u.useCallback(s=>{var i;return e.intent?(i=s.executor)==null?void 0:i.executeMetric(e.intent,s):void 0},[e.intent]),o=I(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,value:(r==null?void 0:r.value)??null,metrics:r==null?void 0:r.metrics,comparisonValue:r==null?void 0:r.comparisonValue,delta:r==null?void 0:r.delta,deltaPercent:r==null?void 0:r.deltaPercent,records:r==null?void 0:r.records,executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function z(t){const e=u.useMemo(()=>V(t),[t]),n=u.useCallback(s=>{var i;return e.intent?(i=s.executor)==null?void 0:i.executeRecords(e.intent,s):void 0},[e.intent]),o=I(e.queryKey,n,e.idleData,e.activeInputs),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,records:(r==null?void 0:r.records)||[],columns:r==null?void 0:r.columns,rowCount:r==null?void 0:r.rowCount,executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function L(t){const e=u.useMemo(()=>w(t),[t]),n=u.useCallback(s=>{var i;return e.intent?(i=s.executor)==null?void 0:i.executeInputOptions(e.intent,s):void 0},[e.intent]),o=I(e.queryKey,n,e.idleData),r=e.error?e.idleData:o.data;return{id:t.id,intent:e.intent,options:(r==null?void 0:r.options)||[],executionResult:r==null?void 0:r.executionResult,status:e.error?"error":o.status,isLoading:!e.error&&o.status==="loading",error:e.error||o.error}}function I(t,e,n,o){const r=q(),s=u.useRef(e),i=u.useRef(o),[m,c]=u.useState({status:"idle",data:n,error:null});return s.current=e,i.current=o,u.useEffect(()=>{let d;try{d=s.current({...r,activeInputs:i.current})}catch(h){c({status:"error",data:n,error:S(h)});return}if(!d){c({status:"idle",data:n,error:null});return}let l=!1;return c(h=>({status:"loading",data:h.data,error:null})),d.then(h=>{l||c({status:"success",data:h,error:null})}).catch(h=>{l||c({status:"error",data:n,error:S(h)})}),()=>{l=!0}},[n,t,r]),m}exports.hasSemaphorInputValue=a.hasSemaphorInputValue;exports.normalizeSemaphorAnalysisQueryOptions=a.normalizeSemaphorAnalysisQueryOptions;exports.normalizeSemaphorInputOptions=a.normalizeSemaphorInputOptions;exports.toSemaphorActiveInputSnapshots=a.toSemaphorActiveInputSnapshots;exports.toSemaphorAnalysisIntent=a.toSemaphorAnalysisIntent;exports.toSemaphorAnalysisQueryOptions=a.toSemaphorAnalysisQueryOptions;exports.toSemaphorInputBinding=a.toSemaphorInputBinding;exports.toSemaphorInputBindings=a.toSemaphorInputBindings;exports.toSemaphorInputOptionsIntent=a.toSemaphorInputOptionsIntent;exports.toSemaphorInputSnapshots=a.toSemaphorInputSnapshots;exports.toSemaphorInputSpec=a.toSemaphorInputSpec;exports.toSemaphorMetricIntent=a.toSemaphorMetricIntent;exports.toSemaphorRecordsIntent=a.toSemaphorRecordsIntent;exports.validateSemaphorDataAppHookSpecs=a.validateSemaphorDataAppHookSpecs;exports.SemaphorDataAppContext=x;exports.SemaphorDataAppProvider=K;exports.createSemaphorQueryExecutor=R;exports.readWindowRuntime=k;exports.useSemaphorAnalysis=Q;exports.useSemaphorDataAppRuntime=q;exports.useSemaphorInput=B;exports.useSemaphorInputOptions=L;exports.useSemaphorMetric=U;exports.useSemaphorRecords=z;
@@ -1,5 +1,5 @@
1
- import { t as x, a as g, b as O, c as K, d as T, e as $, n as _, f as b, h as E } from "../chunks/validation-McK0uXpV.js";
2
- import { k as dt, g as pt, i as yt, j as ft, v as mt } from "../chunks/validation-McK0uXpV.js";
1
+ import { t as x, a as g, b as O, c as K, d as T, e as $, n as _, f as b, h as E } from "../chunks/validation-3nSax_Vs.js";
2
+ import { k as dt, g as pt, i as yt, j as ft, v as mt } from "../chunks/validation-3nSax_Vs.js";
3
3
  import { j as P } from "../chunks/index-CuHybtft.js";
4
4
  import { createContext as U, useContext as w, useMemo as d, useState as k, useCallback as f, useRef as q, useEffect as C } from "react";
5
5
  import { jsx as B } from "react/jsx-runtime";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../chunks/validators-Cu_w8ZEP.js");require("../chunks/source-identity-C-xaeE_I.js");const e=require("../chunks/validation-C_WDLZdp.js");exports.normalizeSemaphorAnalysisQueryOptions=e.normalizeSemaphorAnalysisQueryOptions;exports.validateSemaphorDataAppHookSpecs=e.validateSemaphorDataAppHookSpecs;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../chunks/validators-Cu_w8ZEP.js");require("../chunks/source-identity-C-xaeE_I.js");const e=require("../chunks/validation-bKtG7HIt.js");exports.normalizeSemaphorAnalysisQueryOptions=e.normalizeSemaphorAnalysisQueryOptions;exports.validateSemaphorDataAppHookSpecs=e.validateSemaphorDataAppHookSpecs;
@@ -1,6 +1,6 @@
1
1
  import "../chunks/validators-BnLhuIhd.js";
2
2
  import "../chunks/source-identity-qAmkNtEK.js";
3
- import { k as e, v as i } from "../chunks/validation-McK0uXpV.js";
3
+ import { k as e, v as i } from "../chunks/validation-3nSax_Vs.js";
4
4
  export {
5
5
  e as normalizeSemaphorAnalysisQueryOptions,
6
6
  i as validateSemaphorDataAppHookSpecs
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.1.360",
8
+ "version": "0.1.361",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",
@@ -1 +0,0 @@
1
- "use strict";const B=require("./validators-Cu_w8ZEP.js"),c=require("./source-identity-C-xaeE_I.js");function p(e){var r;const t=H(e);return{version:1,kind:"metric",id:e.id,label:e.label,source:g(e),metrics:t,primaryMetric:O(e,t),dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,dimensions:(r=e.dimensions)==null?void 0:r.map(i=>a(i,"dimension")),comparison:J(e.comparison),orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:y(e.inputs),limit:e.limit}}function M(e){var r;return{...p(e),...e.timeWindow?{timeWindow:e.timeWindow}:{},...(r=e.filters)!=null&&r.length?{filters:e.filters}:{},...e.analysis?{analysis:e.analysis}:{}}}function D(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 O(e,t){if(!e.primaryMetric)return t[0]||{name:"",role:"measure"};const r=a(e.primaryMetric,"measure"),i=E(r,t),o=i.length===1?i[0]:void 0;return o?b(r,o):r}function H(e){const t=[];for(const r of e.metrics.map(i=>a(i,"measure"))){if(!r.name)continue;const i=t.findIndex(o=>j(o,r));if(i===-1){t.push(r);continue}t[i]=b(t[i],r)}return t}function j(e,t){return c.semaphorFieldRefsMatch(e,t)&&f(e)===f(t)}function q(e,t){return f(t)===f(e)}function N(e,t){return t.name!==e.name||e.source&&!c.semaphorFieldRefsMatch(t,e)?!1:q(e,t)}function E(e,t){const r=t.filter(i=>N(e,i));return e.aggregate!==void 0,r}function f(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){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(!L(e))throw new Error("useSemaphorRecords needs at least one field.");const t=U(e.fields);return{version:1,kind:"records",id:e.id,label:e.label,source:g(e),fields:t,dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:y(e.inputs),limit:e.limit}}function U(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 w(e){return{version:1,kind:"inputOptions",id:e.id,label:e.label,source:g(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 G(e){const t=y(e);return t.length>0?t:void 0}function $(e){return(e||[]).map(K)}function Q(e){return $(e).filter(t=>t.isActive)}function V(e){return e.kind==="filter"?{inputId:e.id,kind:e.kind,label:e.label,field:a(e.field,"dimension"),operator:e.operator||"in"}:{inputId:e.id,kind:e.kind,label:e.label}}function W(e=[]){return e.map(t=>typeof t=="object"?t:{label:String(t),value:t})}function F(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e=="string"?e.trim().length>0:!0}function K(e){return"toAnalyticsInput"in e?e.toAnalyticsInput():"kind"in e&&"isActive"in e?e:{...e,kind:"filter",isActive:F(e.value),value:e.value}}function g(e){return e.source}function L(e){var t;return!!((t=e.fields)!=null&&t.length)}function a(e,t){return{...e,role:e.role||t}}function y(e){return(e||[]).map(C)}function J(e){if(e)return e}function T(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 i=e,o={};if(i.chartTitle!==void 0){if(typeof i.chartTitle!="string")return s(`${r}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');o.chartTitle=i.chartTitle}if(i.chartType!==void 0){if(typeof i.chartType!="string")return s(`${r}.chartType`,'Data App analysis option "chartType" must be a string.');o.chartType=i.chartType}if(i.driverMode!==void 0){if(!Z(i.driverMode))return s(`${r}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');o.driverMode=i.driverMode}if(i.includePopulation!==void 0){if(typeof i.includePopulation!="boolean")return s(`${r}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');o.includePopulation=i.includePopulation}if(i.calendarContext!==void 0){const n=ee(i.calendarContext,{pathPrefix:`${r}.calendarContext`,validateTimezone:t.validateTimezone});if(!n.ok)return n;o.calendarContext=n.calendarContext}return{ok:!0,analysisOptions:o}}function X(e){const t=e.hooks.map((o,n)=>Y(o,n,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),r=t.flatMap(o=>o.diagnostics),i=t.map(o=>o.executionResult);return{ok:r.every(o=>o.severity!=="error"),diagnostics:r,hooks:t,intents:t.flatMap(o=>o.intent?[o.intent]:[]),executionResults:i}}function Y(e,t,r){const i=`hooks.${t}`;try{const o=te(e),n=ce(e,o),d=B.validateSemaphorAnalyticsIntent(o),l=[...d.errors.map(h=>k(h,{hook:e.hook,hookId:n,pathPrefix:i,severity:"error",intent:o})),...d.warnings.map(h=>k(h,{hook:e.hook,hookId:n,pathPrefix:i,severity:"warning",intent:o})),...re({hookSpec:e,hookId:n,intent:o,pathPrefix:i,fieldCatalogs:r.fieldCatalogs,requireFieldCatalog:r.requireFieldCatalog}),...ne({hookSpec:e,hookId:n,intent:o,pathPrefix:i,validateTimezone:r.validateTimezone})],z=le(d,l);return{hook:e.hook,hookId:n,intent:o,diagnostics:l,executionResult:A({intent:o,validation:z,diagnostics:l})}}catch(o){const n={severity:"error",code:"invalid_hook_spec",message:o instanceof Error?o.message:String(o),path:i,hook:e.hook,hookId:P(e.spec)},d=R([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,t){var l;if(!e||typeof e!="object"||Array.isArray(e))return s(t.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const r=e,i=r.tz,o=r.weekStart,n=r.anchor,d=typeof i=="string"?((l=t.validateTimezone)==null?void 0:l.call(t,i))??i:null;return d?typeof o!="number"||!Number.isInteger(o)||o<0||o>6?s(`${t.pathPrefix}.weekStart`,'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'):n!=="now"&&!(n&&typeof n=="object"&&!Array.isArray(n)&&typeof n.iso=="string")?s(`${t.pathPrefix}.anchor`,'Data App analysis option "calendarContext.anchor" must be "now" or an object with an iso string.'):{ok:!0,calendarContext:{tz:d,weekStart:o,anchor:n}}:s(`${t.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.')}function te(e){return e.hook==="useSemaphorMetric"?p(e.spec):e.hook==="useSemaphorAnalysis"?M(e.spec):e.hook==="useSemaphorRecords"?_(e.spec):w(e.spec)}function re(e){if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const t=se(e.fieldCatalogs,e.intent.source);return t?[...ie({...e,catalog:t}),...oe({...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 ie(e){return ae(e.intent).flatMap(({field:t,path:r})=>x(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:u(t,e.intent.source),field:t}])}function oe(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((r,i)=>{if(!r.field)return[];const o=u(r.field,e.intent.source);return c.semaphorSourcesReferToSameDataset(o,e.intent.source)?x(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.${i}.field`,hook:e.hookSpec.hook,hookId:e.hookId,intentId:e.intent.id,source:o,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.${i}.field`,hook:e.hookSpec.hook,hookId:e.hookId,intentId:e.intent.id,source:o,field:r.field}]})}function ne(e){if(e.hookSpec.hook!=="useSemaphorAnalysis")return[];const t=T(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 ae(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.kind==="inputOptions"?[{field:e.field,path:"spec.field"}]:[]}function se(e,t){return e.find(r=>m(r,t))}function x(e,t,r){const i=u(t,r);if(m(e,i))return e.fields.find(o=>de(o,t)&&m(e,u(o,e.source)))}function m(e,t){return[e.source,...e.sourceAliases||[]].some(r=>c.semaphorSourcesReferToSameDataset(r,t))}function u(e,t){return e.source||t}function de(e,t){const r=v(e.name),i=v(t.name);return!!(r&&i&&r===i)}function v(e){return(e||"").trim().toLowerCase()}function k(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 le(e,t){const r=R(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 R(e){const t=e.filter(i=>i.severity==="error").map(I),r=e.filter(i=>i.severity==="warning").map(I);return{ok:t.length===0,errors:t,warnings:r,repairHints:t.map(i=>{var o,n;return{code:i.code,message:i.message,fieldRole:i.fieldRole,invalidField:(o=i.repairHint)==null?void 0:o.invalidField,recommendedNextStep:((n=i.repairHint)==null?void 0:n.recommendedNextStep)||"Update the Data App SDK hook spec to use visible Semaphor source and field refs."}})}}function I(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 i=`${r.code}:${r.path||""}:${r.message}`;return t.has(i)?!1:(t.add(i),!0)})}function A(e){var r,i;const t=e.diagnostics.filter(o=>o.severity==="error");return{intentId:(r=e.intent)==null?void 0:r.id,status:t.length?"failed":"answered",resultShape:(i=e.intent)==null?void 0:i.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(o=>o.code==="missing_field").flatMap(o=>{var n;return(n=o.field)!=null&&n.name?[o.field.name]:[]}),warnings:e.diagnostics.filter(o=>o.severity==="warning").map(o=>o.message),metadata:{validationKind:"data_app_sdk_hook_spec"}}}function ce(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=F;exports.normalizeSemaphorAnalysisQueryOptions=T;exports.normalizeSemaphorInputOptions=W;exports.toSemaphorActiveInputSnapshots=Q;exports.toSemaphorAnalysisIntent=M;exports.toSemaphorAnalysisQueryOptions=D;exports.toSemaphorInputBinding=C;exports.toSemaphorInputBindings=G;exports.toSemaphorInputOptionsIntent=w;exports.toSemaphorInputSnapshots=$;exports.toSemaphorInputSpec=V;exports.toSemaphorMetricIntent=p;exports.toSemaphorRecordsIntent=_;exports.validateSemaphorDataAppHookSpecs=X;