react-semaphor 0.1.360 → 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-McK0uXpV.js → validation-B4_hBuYu.js} +153 -154
- 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-C_WDLZdp.js +0 -1
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { v as
|
|
2
|
-
import { s as S, c 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",
|
|
9
9
|
id: e.id,
|
|
10
10
|
label: e.label,
|
|
11
|
-
source:
|
|
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
|
|
21
21
|
} : void 0,
|
|
22
|
-
inputs:
|
|
22
|
+
inputs: g(e.inputs),
|
|
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 } : {}
|
|
@@ -41,72 +41,72 @@ function le(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 && !S(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
|
-
function
|
|
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
|
);
|
|
103
|
-
const t =
|
|
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:
|
|
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:
|
|
117
|
+
inputs: g(e.inputs),
|
|
118
118
|
limit: e.limit
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function O(e) {
|
|
122
122
|
return e.map((t) => {
|
|
123
123
|
const r = a(t);
|
|
124
124
|
if (!r.role)
|
|
@@ -128,19 +128,19 @@ function j(e) {
|
|
|
128
128
|
return r;
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
function
|
|
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:
|
|
137
|
+
source: p(e),
|
|
138
138
|
field: a(e.field, "dimension"),
|
|
139
139
|
search: e.search,
|
|
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 {
|
|
@@ -154,14 +154,14 @@ function q(e) {
|
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
function ce(e) {
|
|
157
|
-
const t =
|
|
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
163
|
function fe(e) {
|
|
164
|
-
return
|
|
164
|
+
return q(e).filter((t) => t.isActive);
|
|
165
165
|
}
|
|
166
166
|
function ue(e) {
|
|
167
167
|
return e.kind === "filter" ? {
|
|
@@ -176,7 +176,7 @@ function ue(e) {
|
|
|
176
176
|
label: e.label
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
|
-
function
|
|
179
|
+
function he(e = []) {
|
|
180
180
|
return e.map(
|
|
181
181
|
(t) => typeof t == "object" ? t : {
|
|
182
182
|
label: String(t),
|
|
@@ -184,23 +184,23 @@ function me(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
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
|
-
function
|
|
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
|
}
|
|
@@ -210,14 +210,14 @@ function a(e, t) {
|
|
|
210
210
|
role: e.role || t
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
|
-
function
|
|
214
|
-
return (e || []).map(
|
|
213
|
+
function g(e) {
|
|
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,83 +269,83 @@ 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
|
-
],
|
|
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
335
|
executionResult: I({
|
|
336
|
-
intent:
|
|
337
|
-
validation:
|
|
336
|
+
intent: i,
|
|
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
|
-
hookId:
|
|
348
|
+
hookId: $(e.spec)
|
|
349
349
|
}, d = w([n]);
|
|
350
350
|
return {
|
|
351
351
|
hook: e.hook,
|
|
@@ -370,28 +370,31 @@ 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
|
-
function J(e
|
|
377
|
-
|
|
376
|
+
function J(e) {
|
|
377
|
+
return e.trim().length > 0 && !Number.isNaN(Date.parse(e));
|
|
378
|
+
}
|
|
379
|
+
function L(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,
|
|
384
|
-
return
|
|
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(
|
|
385
388
|
`${t.pathPrefix}.weekStart`,
|
|
386
389
|
'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'
|
|
387
|
-
) : n !== "now" && !(
|
|
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
|
|
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:
|
|
394
|
-
weekStart:
|
|
396
|
+
tz: l,
|
|
397
|
+
weekStart: i,
|
|
395
398
|
anchor: n
|
|
396
399
|
}
|
|
397
400
|
} : s(
|
|
@@ -400,7 +403,7 @@ function J(e, t) {
|
|
|
400
403
|
);
|
|
401
404
|
}
|
|
402
405
|
function X(e) {
|
|
403
|
-
return e.hook === "useSemaphorMetric" ?
|
|
406
|
+
return e.hook === "useSemaphorMetric" ? b(e.spec) : e.hook === "useSemaphorAnalysis" ? F(e.spec) : e.hook === "useSemaphorRecords" ? H(e.spec) : j(e.spec);
|
|
404
407
|
}
|
|
405
408
|
function Y(e) {
|
|
406
409
|
if (e.fieldCatalogs.length === 0 && !e.requireFieldCatalog)
|
|
@@ -438,26 +441,26 @@ function Z(e) {
|
|
|
438
441
|
hook: e.hookSpec.hook,
|
|
439
442
|
hookId: e.hookId,
|
|
440
443
|
intentId: e.intent.id,
|
|
441
|
-
source:
|
|
444
|
+
source: u(t, e.intent.source),
|
|
442
445
|
field: t
|
|
443
446
|
}
|
|
444
447
|
]);
|
|
445
448
|
}
|
|
446
449
|
function ee(e) {
|
|
447
|
-
return ("inputs" in e.intent ? e.intent.inputs || [] : []).flatMap((r,
|
|
450
|
+
return ("inputs" in e.intent ? e.intent.inputs || [] : []).flatMap((r, o) => {
|
|
448
451
|
if (!r.field)
|
|
449
452
|
return [];
|
|
450
|
-
const
|
|
451
|
-
return A(
|
|
453
|
+
const i = u(r.field, e.intent.source);
|
|
454
|
+
return A(i, e.intent.source) ? _(e.catalog, r.field, e.intent.source) ? [] : [
|
|
452
455
|
{
|
|
453
456
|
severity: "error",
|
|
454
457
|
code: "missing_field",
|
|
455
458
|
message: `Input "${r.inputId}" references field "${r.field.name}", which is not visible on the selected Semaphor source.`,
|
|
456
|
-
path: `${e.pathPrefix}.spec.inputs.${
|
|
459
|
+
path: `${e.pathPrefix}.spec.inputs.${o}.field`,
|
|
457
460
|
hook: e.hookSpec.hook,
|
|
458
461
|
hookId: e.hookId,
|
|
459
462
|
intentId: e.intent.id,
|
|
460
|
-
source:
|
|
463
|
+
source: i,
|
|
461
464
|
field: r.field
|
|
462
465
|
}
|
|
463
466
|
] : [
|
|
@@ -465,11 +468,11 @@ function ee(e) {
|
|
|
465
468
|
severity: "error",
|
|
466
469
|
code: "unsupported_input_filter_composition",
|
|
467
470
|
message: `Input "${r.inputId}" filters a different Semaphor source than the query. Cross-source Data App inputs are not supported yet.`,
|
|
468
|
-
path: `${e.pathPrefix}.spec.inputs.${
|
|
471
|
+
path: `${e.pathPrefix}.spec.inputs.${o}.field`,
|
|
469
472
|
hook: e.hookSpec.hook,
|
|
470
473
|
hookId: e.hookId,
|
|
471
474
|
intentId: e.intent.id,
|
|
472
|
-
source:
|
|
475
|
+
source: i,
|
|
473
476
|
field: r.field
|
|
474
477
|
}
|
|
475
478
|
];
|
|
@@ -478,7 +481,7 @@ function ee(e) {
|
|
|
478
481
|
function te(e) {
|
|
479
482
|
if (e.hookSpec.hook !== "useSemaphorAnalysis")
|
|
480
483
|
return [];
|
|
481
|
-
const t =
|
|
484
|
+
const t = W(e.hookSpec.spec, {
|
|
482
485
|
pathPrefix: `${e.pathPrefix}.spec`,
|
|
483
486
|
validateTimezone: e.validateTimezone
|
|
484
487
|
});
|
|
@@ -523,12 +526,12 @@ function ie(e, t) {
|
|
|
523
526
|
return e.find((r) => m(r, t));
|
|
524
527
|
}
|
|
525
528
|
function _(e, t, r) {
|
|
526
|
-
const
|
|
527
|
-
if (m(e,
|
|
529
|
+
const o = u(t, r);
|
|
530
|
+
if (m(e, o))
|
|
528
531
|
return e.fields.find(
|
|
529
|
-
(
|
|
532
|
+
(i) => oe(i, t) && m(
|
|
530
533
|
e,
|
|
531
|
-
|
|
534
|
+
u(i, e.source)
|
|
532
535
|
)
|
|
533
536
|
);
|
|
534
537
|
}
|
|
@@ -537,15 +540,11 @@ function m(e, t) {
|
|
|
537
540
|
(r) => A(r, t)
|
|
538
541
|
);
|
|
539
542
|
}
|
|
540
|
-
function
|
|
543
|
+
function u(e, t) {
|
|
541
544
|
return e.source || t;
|
|
542
545
|
}
|
|
543
546
|
function oe(e, t) {
|
|
544
|
-
|
|
545
|
-
return !!(r && i && r === i);
|
|
546
|
-
}
|
|
547
|
-
function g(e) {
|
|
548
|
-
return (e || "").trim().toLowerCase();
|
|
547
|
+
return !!(e.name && t.name && e.name === t.name);
|
|
549
548
|
}
|
|
550
549
|
function y(e, t) {
|
|
551
550
|
return {
|
|
@@ -578,19 +577,19 @@ function ne(e, t) {
|
|
|
578
577
|
};
|
|
579
578
|
}
|
|
580
579
|
function w(e) {
|
|
581
|
-
const t = e.filter((
|
|
580
|
+
const t = e.filter((o) => o.severity === "error").map(v), r = e.filter((o) => o.severity === "warning").map(v);
|
|
582
581
|
return {
|
|
583
582
|
ok: t.length === 0,
|
|
584
583
|
errors: t,
|
|
585
584
|
warnings: r,
|
|
586
|
-
repairHints: t.map((
|
|
587
|
-
var
|
|
585
|
+
repairHints: t.map((o) => {
|
|
586
|
+
var i, n;
|
|
588
587
|
return {
|
|
589
|
-
code:
|
|
590
|
-
message:
|
|
591
|
-
fieldRole:
|
|
592
|
-
invalidField: (
|
|
593
|
-
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."
|
|
594
593
|
};
|
|
595
594
|
})
|
|
596
595
|
};
|
|
@@ -614,17 +613,17 @@ function v(e) {
|
|
|
614
613
|
function k(e) {
|
|
615
614
|
const t = /* @__PURE__ */ new Set();
|
|
616
615
|
return e.filter((r) => {
|
|
617
|
-
const
|
|
618
|
-
return t.has(
|
|
616
|
+
const o = `${r.code}:${r.path || ""}:${r.message}`;
|
|
617
|
+
return t.has(o) ? !1 : (t.add(o), !0);
|
|
619
618
|
});
|
|
620
619
|
}
|
|
621
620
|
function I(e) {
|
|
622
|
-
var r,
|
|
623
|
-
const t = e.diagnostics.filter((
|
|
621
|
+
var r, o;
|
|
622
|
+
const t = e.diagnostics.filter((i) => i.severity === "error");
|
|
624
623
|
return {
|
|
625
624
|
intentId: (r = e.intent) == null ? void 0 : r.id,
|
|
626
625
|
status: t.length ? "failed" : "answered",
|
|
627
|
-
resultShape: (
|
|
626
|
+
resultShape: (o = e.intent) == null ? void 0 : o.kind,
|
|
628
627
|
intent: e.intent,
|
|
629
628
|
validation: e.validation,
|
|
630
629
|
coverage: {
|
|
@@ -632,20 +631,20 @@ function I(e) {
|
|
|
632
631
|
missingObligations: t.length ? ["hook_spec_validation"] : [],
|
|
633
632
|
warnings: e.validation.warnings
|
|
634
633
|
},
|
|
635
|
-
missingFields: t.filter((
|
|
634
|
+
missingFields: t.filter((i) => i.code === "missing_field").flatMap((i) => {
|
|
636
635
|
var n;
|
|
637
|
-
return (n =
|
|
636
|
+
return (n = i.field) != null && n.name ? [i.field.name] : [];
|
|
638
637
|
}),
|
|
639
|
-
warnings: e.diagnostics.filter((
|
|
638
|
+
warnings: e.diagnostics.filter((i) => i.severity === "warning").map((i) => i.message),
|
|
640
639
|
metadata: {
|
|
641
640
|
validationKind: "data_app_sdk_hook_spec"
|
|
642
641
|
}
|
|
643
642
|
};
|
|
644
643
|
}
|
|
645
644
|
function ae(e, t) {
|
|
646
|
-
return t.id ||
|
|
645
|
+
return t.id || $(e.spec);
|
|
647
646
|
}
|
|
648
|
-
function
|
|
647
|
+
function $(e) {
|
|
649
648
|
if (!e || typeof e != "object" || !("id" in e))
|
|
650
649
|
return;
|
|
651
650
|
const t = e.id;
|
|
@@ -653,17 +652,17 @@ function C(e) {
|
|
|
653
652
|
}
|
|
654
653
|
export {
|
|
655
654
|
le as a,
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
655
|
+
F as b,
|
|
656
|
+
b as c,
|
|
657
|
+
H as d,
|
|
658
|
+
j as e,
|
|
660
659
|
ue as f,
|
|
661
|
-
|
|
662
|
-
|
|
660
|
+
N as g,
|
|
661
|
+
E as h,
|
|
663
662
|
ce as i,
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
663
|
+
q as j,
|
|
664
|
+
W as k,
|
|
665
|
+
he as n,
|
|
667
666
|
fe as t,
|
|
668
|
-
|
|
667
|
+
me as v
|
|
669
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 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;
|