react-semaphor 0.1.361 → 0.1.362
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.
- package/dist/chunks/{validation-3nSax_Vs.js → validation-B4_hBuYu.js} +164 -168
- package/dist/chunks/validation-CsK42Vbq.js +1 -0
- package/dist/data-app-sdk/index.cjs +1 -1
- package/dist/data-app-sdk/index.js +2 -2
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/validation-bKtG7HIt.js +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { v as
|
|
2
|
-
import { s as
|
|
3
|
-
function
|
|
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";
|
|
3
|
+
function b(e) {
|
|
4
4
|
var r;
|
|
5
|
-
const t =
|
|
5
|
+
const t = P(e);
|
|
6
6
|
return {
|
|
7
7
|
version: 1,
|
|
8
8
|
kind: "metric",
|
|
@@ -10,11 +10,11 @@ function M(e) {
|
|
|
10
10
|
label: e.label,
|
|
11
11
|
source: p(e),
|
|
12
12
|
metrics: t,
|
|
13
|
-
primaryMetric:
|
|
13
|
+
primaryMetric: T(e, t),
|
|
14
14
|
dateField: e.dateField ? a(e.dateField, "date") : void 0,
|
|
15
15
|
timeGrain: e.timeGrain,
|
|
16
|
-
dimensions: (r = e.dimensions) == null ? void 0 : r.map((
|
|
17
|
-
comparison:
|
|
16
|
+
dimensions: (r = e.dimensions) == null ? void 0 : r.map((o) => a(o, "dimension")),
|
|
17
|
+
comparison: V(e.comparison),
|
|
18
18
|
orderBy: e.orderBy ? {
|
|
19
19
|
field: a(e.orderBy.field),
|
|
20
20
|
direction: e.orderBy.direction
|
|
@@ -23,16 +23,16 @@ function M(e) {
|
|
|
23
23
|
limit: e.limit
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function F(e) {
|
|
27
27
|
var r;
|
|
28
28
|
return {
|
|
29
|
-
...
|
|
29
|
+
...b(e),
|
|
30
30
|
...e.timeWindow ? { timeWindow: e.timeWindow } : {},
|
|
31
31
|
...(r = e.filters) != null && r.length ? { filters: e.filters } : {},
|
|
32
32
|
...e.analysis ? { analysis: e.analysis } : {}
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function le(e) {
|
|
36
36
|
return {
|
|
37
37
|
...e.chartTitle ? { chartTitle: e.chartTitle } : {},
|
|
38
38
|
...e.chartType ? { chartType: e.chartType } : {},
|
|
@@ -41,62 +41,62 @@ function ce(e) {
|
|
|
41
41
|
...e.calendarContext ? { calendarContext: e.calendarContext } : {}
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function T(e, t) {
|
|
45
45
|
if (!e.primaryMetric)
|
|
46
46
|
return t[0] || { name: "", role: "measure" };
|
|
47
|
-
const r = a(e.primaryMetric, "measure"),
|
|
48
|
-
return
|
|
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;
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function P(e) {
|
|
51
51
|
const t = [];
|
|
52
|
-
for (const r of e.metrics.map((
|
|
52
|
+
for (const r of e.metrics.map((o) => a(o, "measure"))) {
|
|
53
53
|
if (!r.name)
|
|
54
54
|
continue;
|
|
55
|
-
const
|
|
56
|
-
(
|
|
55
|
+
const o = t.findIndex(
|
|
56
|
+
(i) => R(i, r)
|
|
57
57
|
);
|
|
58
|
-
if (
|
|
58
|
+
if (o === -1) {
|
|
59
59
|
t.push(r);
|
|
60
60
|
continue;
|
|
61
61
|
}
|
|
62
|
-
t[
|
|
62
|
+
t[o] = M(t[o], r);
|
|
63
63
|
}
|
|
64
64
|
return t;
|
|
65
65
|
}
|
|
66
|
+
function R(e, t) {
|
|
67
|
+
return S(e, t) && f(e) === f(t);
|
|
68
|
+
}
|
|
66
69
|
function z(e, t) {
|
|
67
|
-
return
|
|
70
|
+
return f(t) === f(e);
|
|
68
71
|
}
|
|
69
72
|
function B(e, t) {
|
|
70
|
-
return
|
|
73
|
+
return t.name !== e.name || e.source && !S(t, e) ? !1 : z(e, t);
|
|
71
74
|
}
|
|
72
75
|
function D(e, t) {
|
|
73
|
-
return t.name !== e.name || e.source && !A(t, e) ? !1 : B(e, t);
|
|
74
|
-
}
|
|
75
|
-
function H(e, t) {
|
|
76
76
|
const r = t.filter(
|
|
77
|
-
(
|
|
77
|
+
(o) => B(e, o)
|
|
78
78
|
);
|
|
79
79
|
return e.aggregate !== void 0, r;
|
|
80
80
|
}
|
|
81
81
|
function f(e) {
|
|
82
82
|
return (e.aggregate || "SUM").toUpperCase();
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function M(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
|
-
...
|
|
90
|
+
...x(e, t),
|
|
91
91
|
aggregate: e.aggregate || t.aggregate
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function H(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."
|
|
98
98
|
);
|
|
99
|
-
if (!
|
|
99
|
+
if (!G(e))
|
|
100
100
|
throw new Error(
|
|
101
101
|
"useSemaphorRecords needs at least one field."
|
|
102
102
|
);
|
|
@@ -140,7 +140,7 @@ function j(e) {
|
|
|
140
140
|
limit: e.limit
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function N(e) {
|
|
144
144
|
if ("toAnalyticsInput" in e) {
|
|
145
145
|
const t = e.toAnalyticsInput();
|
|
146
146
|
return {
|
|
@@ -153,17 +153,17 @@ function q(e) {
|
|
|
153
153
|
...e.field ? { field: e.field } : {}
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
|
-
function
|
|
156
|
+
function ce(e) {
|
|
157
157
|
const t = g(e);
|
|
158
158
|
return t.length > 0 ? t : void 0;
|
|
159
159
|
}
|
|
160
|
-
function
|
|
161
|
-
return (e || []).map(
|
|
160
|
+
function q(e) {
|
|
161
|
+
return (e || []).map(U);
|
|
162
162
|
}
|
|
163
|
-
function
|
|
164
|
-
return
|
|
163
|
+
function fe(e) {
|
|
164
|
+
return q(e).filter((t) => t.isActive);
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function ue(e) {
|
|
167
167
|
return e.kind === "filter" ? {
|
|
168
168
|
inputId: e.id,
|
|
169
169
|
kind: e.kind,
|
|
@@ -184,14 +184,14 @@ function he(e = []) {
|
|
|
184
184
|
}
|
|
185
185
|
);
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function E(e) {
|
|
188
188
|
return e == null ? !1 : Array.isArray(e) ? e.length > 0 : typeof e == "string" ? e.trim().length > 0 : !0;
|
|
189
189
|
}
|
|
190
|
-
function
|
|
190
|
+
function U(e) {
|
|
191
191
|
return "toAnalyticsInput" in e ? e.toAnalyticsInput() : "kind" in e && "isActive" in e ? e : {
|
|
192
192
|
...e,
|
|
193
193
|
kind: "filter",
|
|
194
|
-
isActive:
|
|
194
|
+
isActive: E(
|
|
195
195
|
e.value
|
|
196
196
|
),
|
|
197
197
|
value: e.value
|
|
@@ -200,7 +200,7 @@ function G(e) {
|
|
|
200
200
|
function p(e) {
|
|
201
201
|
return e.source;
|
|
202
202
|
}
|
|
203
|
-
function
|
|
203
|
+
function G(e) {
|
|
204
204
|
var t;
|
|
205
205
|
return !!((t = e.fields) != null && t.length);
|
|
206
206
|
}
|
|
@@ -211,13 +211,13 @@ function a(e, t) {
|
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
213
|
function g(e) {
|
|
214
|
-
return (e || []).map(
|
|
214
|
+
return (e || []).map(N);
|
|
215
215
|
}
|
|
216
|
-
function
|
|
216
|
+
function V(e) {
|
|
217
217
|
if (e)
|
|
218
218
|
return e;
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function W(e, t = {}) {
|
|
221
221
|
const r = t.pathPrefix || "analysisOptions";
|
|
222
222
|
if (e === void 0)
|
|
223
223
|
return { ok: !0 };
|
|
@@ -226,42 +226,42 @@ function K(e, t = {}) {
|
|
|
226
226
|
r,
|
|
227
227
|
"Data App analysis options must be an object."
|
|
228
228
|
);
|
|
229
|
-
const
|
|
230
|
-
if (
|
|
231
|
-
if (typeof
|
|
229
|
+
const o = e, i = {};
|
|
230
|
+
if (o.chartTitle !== void 0) {
|
|
231
|
+
if (typeof o.chartTitle != "string")
|
|
232
232
|
return s(
|
|
233
233
|
`${r}.chartTitle`,
|
|
234
234
|
'Data App analysis option "chartTitle" must be a string.'
|
|
235
235
|
);
|
|
236
|
-
|
|
236
|
+
i.chartTitle = o.chartTitle;
|
|
237
237
|
}
|
|
238
|
-
if (
|
|
239
|
-
if (typeof
|
|
238
|
+
if (o.chartType !== void 0) {
|
|
239
|
+
if (typeof o.chartType != "string")
|
|
240
240
|
return s(
|
|
241
241
|
`${r}.chartType`,
|
|
242
242
|
'Data App analysis option "chartType" must be a string.'
|
|
243
243
|
);
|
|
244
|
-
|
|
244
|
+
i.chartType = o.chartType;
|
|
245
245
|
}
|
|
246
|
-
if (
|
|
247
|
-
if (!
|
|
246
|
+
if (o.driverMode !== void 0) {
|
|
247
|
+
if (!Q(o.driverMode))
|
|
248
248
|
return s(
|
|
249
249
|
`${r}.driverMode`,
|
|
250
250
|
'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.'
|
|
251
251
|
);
|
|
252
|
-
|
|
252
|
+
i.driverMode = o.driverMode;
|
|
253
253
|
}
|
|
254
|
-
if (
|
|
255
|
-
if (typeof
|
|
254
|
+
if (o.includePopulation !== void 0) {
|
|
255
|
+
if (typeof o.includePopulation != "boolean")
|
|
256
256
|
return s(
|
|
257
257
|
`${r}.includePopulation`,
|
|
258
258
|
'Data App analysis option "includePopulation" must be a boolean.'
|
|
259
259
|
);
|
|
260
|
-
|
|
260
|
+
i.includePopulation = o.includePopulation;
|
|
261
261
|
}
|
|
262
|
-
if (
|
|
263
|
-
const n =
|
|
264
|
-
|
|
262
|
+
if (o.calendarContext !== void 0) {
|
|
263
|
+
const n = L(
|
|
264
|
+
o.calendarContext,
|
|
265
265
|
{
|
|
266
266
|
pathPrefix: `${r}.calendarContext`,
|
|
267
267
|
validateTimezone: t.validateTimezone
|
|
@@ -269,89 +269,89 @@ function K(e, t = {}) {
|
|
|
269
269
|
);
|
|
270
270
|
if (!n.ok)
|
|
271
271
|
return n;
|
|
272
|
-
|
|
272
|
+
i.calendarContext = n.calendarContext;
|
|
273
273
|
}
|
|
274
|
-
return { ok: !0, analysisOptions:
|
|
274
|
+
return { ok: !0, analysisOptions: i };
|
|
275
275
|
}
|
|
276
|
-
function
|
|
276
|
+
function me(e) {
|
|
277
277
|
const t = e.hooks.map(
|
|
278
|
-
(
|
|
278
|
+
(i, n) => K(i, n, {
|
|
279
279
|
fieldCatalogs: e.fieldCatalogs || [],
|
|
280
280
|
requireFieldCatalog: !!e.requireFieldCatalog,
|
|
281
281
|
validateTimezone: e.validateTimezone
|
|
282
282
|
})
|
|
283
|
-
), r = t.flatMap((
|
|
283
|
+
), r = t.flatMap((i) => i.diagnostics), o = t.map((i) => i.executionResult);
|
|
284
284
|
return {
|
|
285
|
-
ok: r.every((
|
|
285
|
+
ok: r.every((i) => i.severity !== "error"),
|
|
286
286
|
diagnostics: r,
|
|
287
287
|
hooks: t,
|
|
288
|
-
intents: t.flatMap((
|
|
289
|
-
executionResults:
|
|
288
|
+
intents: t.flatMap((i) => i.intent ? [i.intent] : []),
|
|
289
|
+
executionResults: o
|
|
290
290
|
};
|
|
291
291
|
}
|
|
292
|
-
function
|
|
293
|
-
const
|
|
292
|
+
function K(e, t, r) {
|
|
293
|
+
const o = `hooks.${t}`;
|
|
294
294
|
try {
|
|
295
|
-
const
|
|
295
|
+
const i = X(e), n = ae(e, i), d = C(i), l = [
|
|
296
296
|
...d.errors.map(
|
|
297
|
-
(
|
|
297
|
+
(h) => y(h, {
|
|
298
298
|
hook: e.hook,
|
|
299
299
|
hookId: n,
|
|
300
|
-
pathPrefix:
|
|
300
|
+
pathPrefix: o,
|
|
301
301
|
severity: "error",
|
|
302
|
-
intent:
|
|
302
|
+
intent: i
|
|
303
303
|
})
|
|
304
304
|
),
|
|
305
305
|
...d.warnings.map(
|
|
306
|
-
(
|
|
306
|
+
(h) => y(h, {
|
|
307
307
|
hook: e.hook,
|
|
308
308
|
hookId: n,
|
|
309
|
-
pathPrefix:
|
|
309
|
+
pathPrefix: o,
|
|
310
310
|
severity: "warning",
|
|
311
|
-
intent:
|
|
311
|
+
intent: i
|
|
312
312
|
})
|
|
313
313
|
),
|
|
314
|
-
...
|
|
314
|
+
...Y({
|
|
315
315
|
hookSpec: e,
|
|
316
316
|
hookId: n,
|
|
317
|
-
intent:
|
|
318
|
-
pathPrefix:
|
|
317
|
+
intent: i,
|
|
318
|
+
pathPrefix: o,
|
|
319
319
|
fieldCatalogs: r.fieldCatalogs,
|
|
320
320
|
requireFieldCatalog: r.requireFieldCatalog
|
|
321
321
|
}),
|
|
322
|
-
...
|
|
322
|
+
...te({
|
|
323
323
|
hookSpec: e,
|
|
324
324
|
hookId: n,
|
|
325
|
-
intent:
|
|
326
|
-
pathPrefix:
|
|
325
|
+
intent: i,
|
|
326
|
+
pathPrefix: o,
|
|
327
327
|
validateTimezone: r.validateTimezone
|
|
328
328
|
})
|
|
329
|
-
], c =
|
|
329
|
+
], c = ne(d, l);
|
|
330
330
|
return {
|
|
331
331
|
hook: e.hook,
|
|
332
332
|
hookId: n,
|
|
333
|
-
intent:
|
|
333
|
+
intent: i,
|
|
334
334
|
diagnostics: l,
|
|
335
|
-
executionResult:
|
|
336
|
-
intent:
|
|
335
|
+
executionResult: I({
|
|
336
|
+
intent: i,
|
|
337
337
|
validation: c,
|
|
338
338
|
diagnostics: l
|
|
339
339
|
})
|
|
340
340
|
};
|
|
341
|
-
} catch (
|
|
341
|
+
} catch (i) {
|
|
342
342
|
const n = {
|
|
343
343
|
severity: "error",
|
|
344
344
|
code: "invalid_hook_spec",
|
|
345
|
-
message:
|
|
346
|
-
path:
|
|
345
|
+
message: i instanceof Error ? i.message : String(i),
|
|
346
|
+
path: o,
|
|
347
347
|
hook: e.hook,
|
|
348
348
|
hookId: $(e.spec)
|
|
349
|
-
}, d =
|
|
349
|
+
}, d = w([n]);
|
|
350
350
|
return {
|
|
351
351
|
hook: e.hook,
|
|
352
352
|
hookId: n.hookId,
|
|
353
353
|
diagnostics: [n],
|
|
354
|
-
executionResult:
|
|
354
|
+
executionResult: I({
|
|
355
355
|
validation: d,
|
|
356
356
|
diagnostics: [n]
|
|
357
357
|
})
|
|
@@ -370,21 +370,21 @@ function s(e, t) {
|
|
|
370
370
|
]
|
|
371
371
|
};
|
|
372
372
|
}
|
|
373
|
-
function
|
|
373
|
+
function Q(e) {
|
|
374
374
|
return e === "absolute_delta" || e === "largest_negative" || e === "largest_positive" || e === "positive_and_negative" || e === "all";
|
|
375
375
|
}
|
|
376
376
|
function J(e) {
|
|
377
377
|
return e.trim().length > 0 && !Number.isNaN(Date.parse(e));
|
|
378
378
|
}
|
|
379
|
-
function
|
|
379
|
+
function L(e, t) {
|
|
380
380
|
var c;
|
|
381
381
|
if (!e || typeof e != "object" || Array.isArray(e))
|
|
382
382
|
return s(
|
|
383
383
|
t.pathPrefix,
|
|
384
384
|
'Data App analysis option "calendarContext" must be an object.'
|
|
385
385
|
);
|
|
386
|
-
const r = e,
|
|
387
|
-
return l ? typeof
|
|
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;
|
|
387
|
+
return l ? typeof i != "number" || !Number.isInteger(i) || i < 0 || i > 6 ? s(
|
|
388
388
|
`${t.pathPrefix}.weekStart`,
|
|
389
389
|
'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'
|
|
390
390
|
) : n !== "now" && !(typeof d == "string" && J(d)) ? s(
|
|
@@ -394,7 +394,7 @@ function X(e, t) {
|
|
|
394
394
|
ok: !0,
|
|
395
395
|
calendarContext: {
|
|
396
396
|
tz: l,
|
|
397
|
-
weekStart:
|
|
397
|
+
weekStart: i,
|
|
398
398
|
anchor: n
|
|
399
399
|
}
|
|
400
400
|
} : s(
|
|
@@ -402,19 +402,19 @@ function X(e, t) {
|
|
|
402
402
|
'Data App analysis option "calendarContext.tz" must be a valid timezone string.'
|
|
403
403
|
);
|
|
404
404
|
}
|
|
405
|
-
function
|
|
406
|
-
return e.hook === "useSemaphorMetric" ?
|
|
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);
|
|
407
407
|
}
|
|
408
|
-
function
|
|
408
|
+
function Y(e) {
|
|
409
409
|
if (e.fieldCatalogs.length === 0 && !e.requireFieldCatalog)
|
|
410
410
|
return [];
|
|
411
|
-
const t =
|
|
411
|
+
const t = ie(e.fieldCatalogs, e.intent.source);
|
|
412
412
|
return t ? [
|
|
413
|
-
...
|
|
413
|
+
...Z({
|
|
414
414
|
...e,
|
|
415
415
|
catalog: t
|
|
416
416
|
}),
|
|
417
|
-
...
|
|
417
|
+
...ee({
|
|
418
418
|
...e,
|
|
419
419
|
catalog: t
|
|
420
420
|
})
|
|
@@ -431,8 +431,8 @@ function Z(e) {
|
|
|
431
431
|
}
|
|
432
432
|
];
|
|
433
433
|
}
|
|
434
|
-
function
|
|
435
|
-
return
|
|
434
|
+
function Z(e) {
|
|
435
|
+
return re(e.intent).flatMap(({ field: t, path: r }) => _(e.catalog, t, e.intent.source) ? [] : [
|
|
436
436
|
{
|
|
437
437
|
severity: "error",
|
|
438
438
|
code: "missing_field",
|
|
@@ -446,21 +446,21 @@ function ee(e) {
|
|
|
446
446
|
}
|
|
447
447
|
]);
|
|
448
448
|
}
|
|
449
|
-
function
|
|
450
|
-
return ("inputs" in e.intent ? e.intent.inputs || [] : []).flatMap((r,
|
|
449
|
+
function ee(e) {
|
|
450
|
+
return ("inputs" in e.intent ? e.intent.inputs || [] : []).flatMap((r, o) => {
|
|
451
451
|
if (!r.field)
|
|
452
452
|
return [];
|
|
453
|
-
const
|
|
454
|
-
return
|
|
453
|
+
const i = u(r.field, e.intent.source);
|
|
454
|
+
return A(i, e.intent.source) ? _(e.catalog, r.field, e.intent.source) ? [] : [
|
|
455
455
|
{
|
|
456
456
|
severity: "error",
|
|
457
457
|
code: "missing_field",
|
|
458
458
|
message: `Input "${r.inputId}" references field "${r.field.name}", which is not visible on the selected Semaphor source.`,
|
|
459
|
-
path: `${e.pathPrefix}.spec.inputs.${
|
|
459
|
+
path: `${e.pathPrefix}.spec.inputs.${o}.field`,
|
|
460
460
|
hook: e.hookSpec.hook,
|
|
461
461
|
hookId: e.hookId,
|
|
462
462
|
intentId: e.intent.id,
|
|
463
|
-
source:
|
|
463
|
+
source: i,
|
|
464
464
|
field: r.field
|
|
465
465
|
}
|
|
466
466
|
] : [
|
|
@@ -468,20 +468,20 @@ function te(e) {
|
|
|
468
468
|
severity: "error",
|
|
469
469
|
code: "unsupported_input_filter_composition",
|
|
470
470
|
message: `Input "${r.inputId}" filters a different Semaphor source than the query. Cross-source Data App inputs are not supported yet.`,
|
|
471
|
-
path: `${e.pathPrefix}.spec.inputs.${
|
|
471
|
+
path: `${e.pathPrefix}.spec.inputs.${o}.field`,
|
|
472
472
|
hook: e.hookSpec.hook,
|
|
473
473
|
hookId: e.hookId,
|
|
474
474
|
intentId: e.intent.id,
|
|
475
|
-
source:
|
|
475
|
+
source: i,
|
|
476
476
|
field: r.field
|
|
477
477
|
}
|
|
478
478
|
];
|
|
479
479
|
});
|
|
480
480
|
}
|
|
481
|
-
function
|
|
481
|
+
function te(e) {
|
|
482
482
|
if (e.hookSpec.hook !== "useSemaphorAnalysis")
|
|
483
483
|
return [];
|
|
484
|
-
const t =
|
|
484
|
+
const t = W(e.hookSpec.spec, {
|
|
485
485
|
pathPrefix: `${e.pathPrefix}.spec`,
|
|
486
486
|
validateTimezone: e.validateTimezone
|
|
487
487
|
});
|
|
@@ -496,7 +496,7 @@ function re(e) {
|
|
|
496
496
|
source: e.intent.source
|
|
497
497
|
}));
|
|
498
498
|
}
|
|
499
|
-
function
|
|
499
|
+
function re(e) {
|
|
500
500
|
return e.kind === "metric" ? [
|
|
501
501
|
...e.metrics.map((t, r) => ({
|
|
502
502
|
field: t,
|
|
@@ -522,35 +522,31 @@ function ie(e) {
|
|
|
522
522
|
...e.orderBy ? [{ field: e.orderBy.field, path: "spec.orderBy.field" }] : []
|
|
523
523
|
] : e.kind === "inputOptions" ? [{ field: e.field, path: "spec.field" }] : [];
|
|
524
524
|
}
|
|
525
|
-
function
|
|
526
|
-
return e.find((r) =>
|
|
525
|
+
function ie(e, t) {
|
|
526
|
+
return e.find((r) => m(r, t));
|
|
527
527
|
}
|
|
528
|
-
function
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
528
|
+
function _(e, t, r) {
|
|
529
|
+
const o = u(t, r);
|
|
530
|
+
if (m(e, o))
|
|
531
531
|
return e.fields.find(
|
|
532
|
-
(
|
|
532
|
+
(i) => oe(i, t) && m(
|
|
533
533
|
e,
|
|
534
|
-
u(
|
|
534
|
+
u(i, e.source)
|
|
535
535
|
)
|
|
536
536
|
);
|
|
537
537
|
}
|
|
538
|
-
function
|
|
538
|
+
function m(e, t) {
|
|
539
539
|
return [e.source, ...e.sourceAliases || []].some(
|
|
540
|
-
(r) =>
|
|
540
|
+
(r) => A(r, t)
|
|
541
541
|
);
|
|
542
542
|
}
|
|
543
543
|
function u(e, t) {
|
|
544
544
|
return e.source || t;
|
|
545
545
|
}
|
|
546
|
-
function
|
|
547
|
-
|
|
548
|
-
return !!(r && i && r === i);
|
|
549
|
-
}
|
|
550
|
-
function y(e) {
|
|
551
|
-
return (e || "").trim().toLowerCase();
|
|
546
|
+
function oe(e, t) {
|
|
547
|
+
return !!(e.name && t.name && e.name === t.name);
|
|
552
548
|
}
|
|
553
|
-
function
|
|
549
|
+
function y(e, t) {
|
|
554
550
|
return {
|
|
555
551
|
severity: t.severity,
|
|
556
552
|
code: e.code || "invalid_analytics_intent",
|
|
@@ -562,15 +558,15 @@ function v(e, t) {
|
|
|
562
558
|
source: t.intent.source
|
|
563
559
|
};
|
|
564
560
|
}
|
|
565
|
-
function
|
|
566
|
-
const r =
|
|
561
|
+
function ne(e, t) {
|
|
562
|
+
const r = w(t);
|
|
567
563
|
return {
|
|
568
564
|
ok: r.ok && e.ok,
|
|
569
|
-
errors:
|
|
565
|
+
errors: k([
|
|
570
566
|
...e.errors,
|
|
571
567
|
...r.errors
|
|
572
568
|
]),
|
|
573
|
-
warnings:
|
|
569
|
+
warnings: k([
|
|
574
570
|
...e.warnings,
|
|
575
571
|
...r.warnings
|
|
576
572
|
]),
|
|
@@ -580,25 +576,25 @@ function ae(e, t) {
|
|
|
580
576
|
]
|
|
581
577
|
};
|
|
582
578
|
}
|
|
583
|
-
function
|
|
584
|
-
const t = e.filter((
|
|
579
|
+
function w(e) {
|
|
580
|
+
const t = e.filter((o) => o.severity === "error").map(v), r = e.filter((o) => o.severity === "warning").map(v);
|
|
585
581
|
return {
|
|
586
582
|
ok: t.length === 0,
|
|
587
583
|
errors: t,
|
|
588
584
|
warnings: r,
|
|
589
|
-
repairHints: t.map((
|
|
590
|
-
var
|
|
585
|
+
repairHints: t.map((o) => {
|
|
586
|
+
var i, n;
|
|
591
587
|
return {
|
|
592
|
-
code:
|
|
593
|
-
message:
|
|
594
|
-
fieldRole:
|
|
595
|
-
invalidField: (
|
|
596
|
-
recommendedNextStep: ((n =
|
|
588
|
+
code: o.code,
|
|
589
|
+
message: o.message,
|
|
590
|
+
fieldRole: o.fieldRole,
|
|
591
|
+
invalidField: (i = o.repairHint) == null ? void 0 : i.invalidField,
|
|
592
|
+
recommendedNextStep: ((n = o.repairHint) == null ? void 0 : n.recommendedNextStep) || "Update the Data App SDK hook spec to use visible Semaphor source and field refs."
|
|
597
593
|
};
|
|
598
594
|
})
|
|
599
595
|
};
|
|
600
596
|
}
|
|
601
|
-
function
|
|
597
|
+
function v(e) {
|
|
602
598
|
var t;
|
|
603
599
|
return {
|
|
604
600
|
code: e.code,
|
|
@@ -614,20 +610,20 @@ function k(e) {
|
|
|
614
610
|
}
|
|
615
611
|
};
|
|
616
612
|
}
|
|
617
|
-
function
|
|
613
|
+
function k(e) {
|
|
618
614
|
const t = /* @__PURE__ */ new Set();
|
|
619
615
|
return e.filter((r) => {
|
|
620
|
-
const
|
|
621
|
-
return t.has(
|
|
616
|
+
const o = `${r.code}:${r.path || ""}:${r.message}`;
|
|
617
|
+
return t.has(o) ? !1 : (t.add(o), !0);
|
|
622
618
|
});
|
|
623
619
|
}
|
|
624
|
-
function
|
|
625
|
-
var r,
|
|
626
|
-
const t = e.diagnostics.filter((
|
|
620
|
+
function I(e) {
|
|
621
|
+
var r, o;
|
|
622
|
+
const t = e.diagnostics.filter((i) => i.severity === "error");
|
|
627
623
|
return {
|
|
628
624
|
intentId: (r = e.intent) == null ? void 0 : r.id,
|
|
629
625
|
status: t.length ? "failed" : "answered",
|
|
630
|
-
resultShape: (
|
|
626
|
+
resultShape: (o = e.intent) == null ? void 0 : o.kind,
|
|
631
627
|
intent: e.intent,
|
|
632
628
|
validation: e.validation,
|
|
633
629
|
coverage: {
|
|
@@ -635,17 +631,17 @@ function S(e) {
|
|
|
635
631
|
missingObligations: t.length ? ["hook_spec_validation"] : [],
|
|
636
632
|
warnings: e.validation.warnings
|
|
637
633
|
},
|
|
638
|
-
missingFields: t.filter((
|
|
634
|
+
missingFields: t.filter((i) => i.code === "missing_field").flatMap((i) => {
|
|
639
635
|
var n;
|
|
640
|
-
return (n =
|
|
636
|
+
return (n = i.field) != null && n.name ? [i.field.name] : [];
|
|
641
637
|
}),
|
|
642
|
-
warnings: e.diagnostics.filter((
|
|
638
|
+
warnings: e.diagnostics.filter((i) => i.severity === "warning").map((i) => i.message),
|
|
643
639
|
metadata: {
|
|
644
640
|
validationKind: "data_app_sdk_hook_spec"
|
|
645
641
|
}
|
|
646
642
|
};
|
|
647
643
|
}
|
|
648
|
-
function
|
|
644
|
+
function ae(e, t) {
|
|
649
645
|
return t.id || $(e.spec);
|
|
650
646
|
}
|
|
651
647
|
function $(e) {
|
|
@@ -655,18 +651,18 @@ function $(e) {
|
|
|
655
651
|
return typeof t == "string" && t.trim() ? t : void 0;
|
|
656
652
|
}
|
|
657
653
|
export {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
654
|
+
le as a,
|
|
655
|
+
F as b,
|
|
656
|
+
b as c,
|
|
657
|
+
H as d,
|
|
662
658
|
j as e,
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
659
|
+
ue as f,
|
|
660
|
+
N as g,
|
|
661
|
+
E as h,
|
|
662
|
+
ce as i,
|
|
663
|
+
q as j,
|
|
664
|
+
W as k,
|
|
669
665
|
he as n,
|
|
670
|
-
|
|
671
|
-
|
|
666
|
+
fe as t,
|
|
667
|
+
me as v
|
|
672
668
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const z=require("./validators-Cu_w8ZEP.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 M(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){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,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 w(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 U(e){const t=v(e);return t.length>0?t:void 0}function C(e){return(e||[]).map(W)}function V(e){return C(e).filter(t=>t.isActive)}function G(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 Q(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 W(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 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($)}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 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(!Y(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=ee(o.calendarContext,{pathPrefix:`${r}.calendarContext`,validateTimezone:t.validateTimezone});if(!n.ok)return n;i.calendarContext=n.calendarContext}return{ok:!0,analysisOptions:i}}function L(e){const t=e.hooks.map((i,n)=>X(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 X(e,t,r){const o=`hooks.${t}`;try{const i=te(e),n=ce(e,i),d=z.validateSemaphorAnalyticsIntent(i),l=[...d.errors.map(m=>k(m,{hook:e.hook,hookId:n,pathPrefix:o,severity:"error",intent:i})),...d.warnings.map(m=>k(m,{hook:e.hook,hookId:n,pathPrefix:o,severity:"warning",intent:i})),...re({hookSpec:e,hookId:n,intent:i,pathPrefix:o,fieldCatalogs:r.fieldCatalogs,requireFieldCatalog:r.requireFieldCatalog}),...ne({hookSpec:e,hookId:n,intent:i,pathPrefix:o,validateTimezone:r.validateTimezone})],f=le(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=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 Y(e){return e==="absolute_delta"||e==="largest_negative"||e==="largest_positive"||e==="positive_and_negative"||e==="all"}function Z(e){return e.trim().length>0&&!Number.isNaN(Date.parse(e))}function ee(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"&&Z(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 te(e){return e.hook==="useSemaphorMetric"?g(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:h(t,e.intent.source),field:t}])}function oe(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)?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.${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 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=>p(r,t))}function x(e,t,r){const o=h(t,r);if(p(e,o))return e.fields.find(i=>de(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 de(e,t){return!!(e.name&&t.name&&e.name===t.name)}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(o=>o.severity==="error").map(I),r=e.filter(o=>o.severity==="warning").map(I);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 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 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 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=Q;exports.toSemaphorActiveInputSnapshots=V;exports.toSemaphorAnalysisIntent=M;exports.toSemaphorAnalysisQueryOptions=B;exports.toSemaphorInputBinding=$;exports.toSemaphorInputBindings=U;exports.toSemaphorInputOptionsIntent=w;exports.toSemaphorInputSnapshots=C;exports.toSemaphorInputSpec=G;exports.toSemaphorMetricIntent=g;exports.toSemaphorRecordsIntent=_;exports.validateSemaphorDataAppHookSpecs=L;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../chunks/validation-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("../chunks/validation-CsK42Vbq.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-
|
|
2
|
-
import { k as dt, g as pt, i as yt, j as ft, v as mt } from "../chunks/validation-
|
|
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-B4_hBuYu.js";
|
|
2
|
+
import { k as dt, g as pt, i as yt, j as ft, v as mt } from "../chunks/validation-B4_hBuYu.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-
|
|
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-CsK42Vbq.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-
|
|
3
|
+
import { k as e, v as i } from "../chunks/validation-B4_hBuYu.js";
|
|
4
4
|
export {
|
|
5
5
|
e as normalizeSemaphorAnalysisQueryOptions,
|
|
6
6
|
i as validateSemaphorDataAppHookSpecs
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
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;
|