react-semaphor 0.1.425 → 0.1.427
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/CHANGELOG.md +5 -0
- package/dist/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +42 -39
- package/dist/brand-studio/index.cjs +1 -1
- package/dist/brand-studio/index.js +1 -1
- package/dist/chunks/{calendar-preferences-dialog-DJwV0aqn.js → calendar-preferences-dialog-DE4tk3t3.js} +2 -2
- package/dist/chunks/{calendar-preferences-dialog-BLaSWhLl.js → calendar-preferences-dialog-DuGX1NPV.js} +1 -1
- package/dist/chunks/{catalog-field-grounding-DcxPLns0.js → catalog-field-grounding-AOGwWu0K.js} +2 -2
- package/dist/chunks/code-editor-BoowcKU0.js +138 -0
- package/dist/chunks/{code-editor-Bkk7s8hI.js → code-editor-CojfM3qp.js} +6564 -6293
- package/dist/chunks/{comparison-document-migration-CQJ0DZlL.js → comparison-document-migration-BJH1idOd.js} +1 -1
- package/dist/chunks/{comparison-document-migration-Db64RWYD.js → comparison-document-migration-b6c3xiWh.js} +1 -1
- package/dist/chunks/{dashboard-5agU0G_D.js → dashboard-DSxho2LN.js} +51313 -50489
- package/dist/chunks/{dashboard-briefing-launcher-qyEVfuOm.js → dashboard-briefing-launcher-BFIw5BOf.js} +4 -4
- package/dist/chunks/{dashboard-briefing-launcher-CII8-4qo.js → dashboard-briefing-launcher-CguxcHIl.js} +1 -1
- package/dist/chunks/{dashboard-controls-PJpeYZHw.js → dashboard-controls-Cl0LagTr.js} +8 -8
- package/dist/chunks/{dashboard-controls-aJY0FNPP.js → dashboard-controls-jD-HpCNK.js} +529 -524
- package/dist/chunks/dashboard-date-comparison-definition-BaYxjLi5.js +167 -0
- package/dist/chunks/dashboard-date-comparison-definition-DGZr3m-b.js +1 -0
- package/dist/chunks/{dashboard-json-DtmR5yCf.js → dashboard-json-7mpQsizF.js} +1 -1
- package/dist/chunks/{dashboard-json-CzHSP6Fa.js → dashboard-json-BovTt0uu.js} +3 -3
- package/dist/chunks/dashboard-ogxedhSY.js +1402 -0
- package/dist/chunks/edit-dashboard-visual-B7wLrHeF.js +182 -0
- package/dist/chunks/{edit-dashboard-visual-AkZzwBCV.js → edit-dashboard-visual-dlm8F_Qu.js} +4649 -4595
- package/dist/chunks/metric-comparison-BKgkMy9r.js +1 -0
- package/dist/chunks/metric-comparison-CWweq9RG.js +387 -0
- package/dist/chunks/{use-create-flow-overlay-state-ByOKVV2K.js → use-create-flow-overlay-state-BU0ROMSm.js} +2 -2
- package/dist/chunks/{use-create-flow-overlay-state-DmuReEnk.js → use-create-flow-overlay-state-kbl6avDY.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.cjs +1 -1
- package/dist/dashboard-authoring/index.js +3 -3
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +2 -2
- package/dist/data-app-sdk-validation/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +6 -6
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/analytics-protocol.d.ts +40 -2
- package/dist/types/dashboard.d.ts +25 -0
- package/dist/types/main.d.ts +54 -5
- package/dist/types/surfboard.d.ts +25 -0
- package/dist/types/types.d.ts +43 -0
- package/package.json +1 -1
- package/dist/chunks/code-editor-CkXyNgYc.js +0 -138
- package/dist/chunks/dashboard-MKIqgGDp.js +0 -1402
- package/dist/chunks/edit-dashboard-visual-Cif6uDqN.js +0 -182
- package/dist/chunks/metric-comparison-4oA4ouU9.js +0 -354
- package/dist/chunks/metric-comparison-nQKquVnx.js +0 -1
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { p as _ } from "./validators-Cz-XuORM.js";
|
|
2
|
-
const u = "higher_is_better", D = {
|
|
3
|
-
displayMode: "difference",
|
|
4
|
-
showComparison: !0,
|
|
5
|
-
indicatorStyle: "arrow_badge",
|
|
6
|
-
showColor: !0,
|
|
7
|
-
conditionalLabel: !1
|
|
8
|
-
};
|
|
9
|
-
function g(e) {
|
|
10
|
-
return _(e) !== null;
|
|
11
|
-
}
|
|
12
|
-
function N(e) {
|
|
13
|
-
var n, o, s;
|
|
14
|
-
if (((n = e.metricComparison) == null ? void 0 : n.mode) !== "off") {
|
|
15
|
-
if (((o = e.metricComparison) == null ? void 0 : o.mode) === "explicit")
|
|
16
|
-
return { source: "explicit", spec: e.metricComparison.spec };
|
|
17
|
-
if (!(e.inheritGlobalComparison === !1 || !e.isGlobalDateApplicable || ((s = e.globalSelection) == null ? void 0 : s.mode) !== "period"))
|
|
18
|
-
return { source: "inherited", spec: e.globalSelection.spec };
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function S(e) {
|
|
22
|
-
if (e.alias) return e.alias;
|
|
23
|
-
const n = e.entityName && e.entityName !== "SEMAPHOR_CALCULATED_FIELD" ? e.entityName : void 0, o = n && n !== e.name ? `${n}_` : "";
|
|
24
|
-
if (e.role !== "metric") return `${o}${e.name}`;
|
|
25
|
-
let s = e.aggregate || "metric";
|
|
26
|
-
if (e.expression) {
|
|
27
|
-
const t = e.expression.match(
|
|
28
|
-
/^(COUNT|SUM|AVG|MIN|MAX|MEDIAN|DISTINCT)\s*\(/i
|
|
29
|
-
);
|
|
30
|
-
s = t ? t[1].toLowerCase() : "expr";
|
|
31
|
-
} else
|
|
32
|
-
s = s.toLowerCase();
|
|
33
|
-
return `${o}${e.name}_${s}`;
|
|
34
|
-
}
|
|
35
|
-
function r(e, n, o) {
|
|
36
|
-
return o ? { code: e, message: n, path: o } : { code: e, message: n };
|
|
37
|
-
}
|
|
38
|
-
function p(e) {
|
|
39
|
-
return !!e && typeof e == "object" && !Array.isArray(e);
|
|
40
|
-
}
|
|
41
|
-
function l(e, n, o, s) {
|
|
42
|
-
Object.keys(e).forEach((t) => {
|
|
43
|
-
n.includes(t) || s.push(
|
|
44
|
-
r(
|
|
45
|
-
"invalid_comparison_spec",
|
|
46
|
-
`Comparison kind does not accept field "${t}".`,
|
|
47
|
-
`${o}.${t}`
|
|
48
|
-
)
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function f(e, n, o) {
|
|
53
|
-
e.alignment !== void 0 && e.alignment !== "calendar" && e.alignment !== "weekday" && o.push(
|
|
54
|
-
r(
|
|
55
|
-
"invalid_comparison_spec",
|
|
56
|
-
'Comparison alignment must be "calendar" or "weekday".',
|
|
57
|
-
`${n}.alignment`
|
|
58
|
-
)
|
|
59
|
-
), e.toDate !== void 0 && typeof e.toDate != "boolean" && o.push(
|
|
60
|
-
r(
|
|
61
|
-
"invalid_comparison_spec",
|
|
62
|
-
"Comparison toDate must be a boolean.",
|
|
63
|
-
`${n}.toDate`
|
|
64
|
-
)
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
function d(e, n, o) {
|
|
68
|
-
e !== void 0 && (typeof e != "number" || !Number.isSafeInteger(e) || e <= 0) && o.push(
|
|
69
|
-
r(
|
|
70
|
-
"invalid_comparison_spec",
|
|
71
|
-
"Comparison offset must be a positive safe integer.",
|
|
72
|
-
n
|
|
73
|
-
)
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
function b(e, n = "comparison") {
|
|
77
|
-
const o = [];
|
|
78
|
-
return p(e) ? (e.kind === "previous_period" ? (l(
|
|
79
|
-
e,
|
|
80
|
-
["kind", "offsetPeriods", "alignment", "toDate"],
|
|
81
|
-
n,
|
|
82
|
-
o
|
|
83
|
-
), d(e.offsetPeriods, `${n}.offsetPeriods`, o), f(e, n, o)) : e.kind === "previous_year" ? (l(
|
|
84
|
-
e,
|
|
85
|
-
["kind", "offsetYears", "alignment", "toDate"],
|
|
86
|
-
n,
|
|
87
|
-
o
|
|
88
|
-
), d(e.offsetYears, `${n}.offsetYears`, o), f(e, n, o)) : e.kind === "target" ? (l(e, ["kind", "targetValue"], n, o), (typeof e.targetValue != "number" || !Number.isFinite(e.targetValue)) && o.push(
|
|
89
|
-
r(
|
|
90
|
-
"invalid_comparison_spec",
|
|
91
|
-
"Target comparison requires a finite targetValue.",
|
|
92
|
-
`${n}.targetValue`
|
|
93
|
-
)
|
|
94
|
-
)) : o.push(
|
|
95
|
-
r(
|
|
96
|
-
"invalid_comparison_spec",
|
|
97
|
-
"Comparison kind must be previous_period, previous_year, or target.",
|
|
98
|
-
`${n}.kind`
|
|
99
|
-
)
|
|
100
|
-
), { ok: o.length === 0, errors: o, warnings: [] }) : {
|
|
101
|
-
ok: !1,
|
|
102
|
-
errors: [
|
|
103
|
-
r(
|
|
104
|
-
"invalid_comparison_spec",
|
|
105
|
-
"Comparison spec must be an object.",
|
|
106
|
-
n
|
|
107
|
-
)
|
|
108
|
-
],
|
|
109
|
-
warnings: []
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function y(e, n = "comparison") {
|
|
113
|
-
if (!p(e))
|
|
114
|
-
return {
|
|
115
|
-
ok: !1,
|
|
116
|
-
errors: [
|
|
117
|
-
r(
|
|
118
|
-
"invalid_comparison_config",
|
|
119
|
-
"Comparison config must be an object.",
|
|
120
|
-
n
|
|
121
|
-
)
|
|
122
|
-
],
|
|
123
|
-
warnings: []
|
|
124
|
-
};
|
|
125
|
-
const o = [];
|
|
126
|
-
return e.mode === "off" ? l(e, ["mode"], n, o) : e.mode === "explicit" ? (l(e, ["mode", "spec"], n, o), o.push(...b(e.spec, `${n}.spec`).errors)) : o.push(
|
|
127
|
-
r(
|
|
128
|
-
"invalid_comparison_config",
|
|
129
|
-
"Comparison mode must be off or explicit.",
|
|
130
|
-
`${n}.mode`
|
|
131
|
-
)
|
|
132
|
-
), { ok: o.length === 0, errors: o, warnings: [] };
|
|
133
|
-
}
|
|
134
|
-
function C(e, n = "comparisonSelection") {
|
|
135
|
-
if (!p(e))
|
|
136
|
-
return {
|
|
137
|
-
ok: !1,
|
|
138
|
-
errors: [
|
|
139
|
-
r(
|
|
140
|
-
"invalid_global_date_comparison",
|
|
141
|
-
"Global Date comparison selection must be an object.",
|
|
142
|
-
n
|
|
143
|
-
)
|
|
144
|
-
],
|
|
145
|
-
warnings: []
|
|
146
|
-
};
|
|
147
|
-
const o = [];
|
|
148
|
-
if (e.mode === "off")
|
|
149
|
-
l(e, ["mode"], n, o);
|
|
150
|
-
else if (e.mode === "period") {
|
|
151
|
-
l(e, ["mode", "spec"], n, o);
|
|
152
|
-
const s = b(e.spec, `${n}.spec`);
|
|
153
|
-
o.push(...s.errors), p(e.spec) && e.spec.kind === "target" && o.push(
|
|
154
|
-
r(
|
|
155
|
-
"invalid_global_date_comparison",
|
|
156
|
-
"Global Date comparison supports previous_period or previous_year, not target.",
|
|
157
|
-
`${n}.spec.kind`
|
|
158
|
-
)
|
|
159
|
-
);
|
|
160
|
-
} else
|
|
161
|
-
o.push(
|
|
162
|
-
r(
|
|
163
|
-
"invalid_global_date_comparison",
|
|
164
|
-
"Global Date comparison mode must be off or period.",
|
|
165
|
-
`${n}.mode`
|
|
166
|
-
)
|
|
167
|
-
);
|
|
168
|
-
return { ok: o.length === 0, errors: o, warnings: [] };
|
|
169
|
-
}
|
|
170
|
-
function I(e, n = "globalDateComparison") {
|
|
171
|
-
if (!p(e))
|
|
172
|
-
return {
|
|
173
|
-
ok: !1,
|
|
174
|
-
errors: [
|
|
175
|
-
r(
|
|
176
|
-
"invalid_global_date_comparison",
|
|
177
|
-
"Global Date comparison context must be an object.",
|
|
178
|
-
n
|
|
179
|
-
)
|
|
180
|
-
],
|
|
181
|
-
warnings: []
|
|
182
|
-
};
|
|
183
|
-
const o = [];
|
|
184
|
-
return l(
|
|
185
|
-
e,
|
|
186
|
-
["selection", "inheritGlobalComparison", "referenceTime"],
|
|
187
|
-
n,
|
|
188
|
-
o
|
|
189
|
-
), o.push(
|
|
190
|
-
...C(
|
|
191
|
-
e.selection,
|
|
192
|
-
`${n}.selection`
|
|
193
|
-
).errors
|
|
194
|
-
), e.inheritGlobalComparison !== void 0 && e.inheritGlobalComparison !== !1 && o.push(
|
|
195
|
-
r(
|
|
196
|
-
"invalid_global_date_comparison",
|
|
197
|
-
"inheritGlobalComparison may only be false when present.",
|
|
198
|
-
`${n}.inheritGlobalComparison`
|
|
199
|
-
)
|
|
200
|
-
), e.referenceTime !== void 0 && (typeof e.referenceTime != "string" || !g(e.referenceTime)) && o.push(
|
|
201
|
-
r(
|
|
202
|
-
"invalid_global_date_comparison",
|
|
203
|
-
"referenceTime must be a valid ISO date-time string when present.",
|
|
204
|
-
`${n}.referenceTime`
|
|
205
|
-
)
|
|
206
|
-
), { ok: o.length === 0, errors: o, warnings: [] };
|
|
207
|
-
}
|
|
208
|
-
function M(e, n = "comparisonPolarity") {
|
|
209
|
-
return e === "higher_is_better" || e === "lower_is_better" || e === "neutral" ? { ok: !0, errors: [], warnings: [] } : {
|
|
210
|
-
ok: !1,
|
|
211
|
-
errors: [
|
|
212
|
-
r(
|
|
213
|
-
"invalid_comparison_polarity",
|
|
214
|
-
"Comparison polarity must be higher_is_better, lower_is_better, or neutral.",
|
|
215
|
-
n
|
|
216
|
-
)
|
|
217
|
-
],
|
|
218
|
-
warnings: []
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
function T(e, n = "comparisonPresentation") {
|
|
222
|
-
if (!p(e))
|
|
223
|
-
return {
|
|
224
|
-
ok: !1,
|
|
225
|
-
errors: [
|
|
226
|
-
r(
|
|
227
|
-
"invalid_comparison_presentation",
|
|
228
|
-
"Comparison presentation must be an object.",
|
|
229
|
-
n
|
|
230
|
-
)
|
|
231
|
-
],
|
|
232
|
-
warnings: []
|
|
233
|
-
};
|
|
234
|
-
const o = [], s = [
|
|
235
|
-
"displayMode",
|
|
236
|
-
"showComparison",
|
|
237
|
-
"precision",
|
|
238
|
-
"indicatorStyle",
|
|
239
|
-
"showColor",
|
|
240
|
-
"position",
|
|
241
|
-
"conditionalLabel",
|
|
242
|
-
"labelName",
|
|
243
|
-
"conditionalLabels",
|
|
244
|
-
"colors"
|
|
245
|
-
];
|
|
246
|
-
return Object.keys(e).forEach((i) => {
|
|
247
|
-
s.includes(i) || o.push(
|
|
248
|
-
r(
|
|
249
|
-
"invalid_comparison_presentation",
|
|
250
|
-
`Comparison presentation does not accept field "${i}".`,
|
|
251
|
-
`${n}.${i}`
|
|
252
|
-
)
|
|
253
|
-
);
|
|
254
|
-
}), [
|
|
255
|
-
["displayMode", ["difference", "percent_change", "both", "ratio"]],
|
|
256
|
-
["indicatorStyle", ["arrow_badge", "arrow", "badge", "none"]],
|
|
257
|
-
["position", ["left", "right", "top"]]
|
|
258
|
-
].forEach(([i, a]) => {
|
|
259
|
-
e[i] !== void 0 && !a.includes(e[i]) && o.push(
|
|
260
|
-
r(
|
|
261
|
-
"invalid_comparison_presentation",
|
|
262
|
-
`Comparison presentation ${i} is invalid.`,
|
|
263
|
-
`${n}.${i}`
|
|
264
|
-
)
|
|
265
|
-
);
|
|
266
|
-
}), ["showComparison", "showColor", "conditionalLabel"].forEach((i) => {
|
|
267
|
-
e[i] !== void 0 && typeof e[i] != "boolean" && o.push(
|
|
268
|
-
r(
|
|
269
|
-
"invalid_comparison_presentation",
|
|
270
|
-
`Comparison presentation ${i} must be a boolean.`,
|
|
271
|
-
`${n}.${i}`
|
|
272
|
-
)
|
|
273
|
-
);
|
|
274
|
-
}), e.precision !== void 0 && (typeof e.precision != "number" || !Number.isInteger(e.precision) || e.precision < 0 || e.precision > 6) && o.push(
|
|
275
|
-
r(
|
|
276
|
-
"invalid_comparison_presentation",
|
|
277
|
-
"Comparison presentation precision must be an integer from 0 through 6.",
|
|
278
|
-
`${n}.precision`
|
|
279
|
-
)
|
|
280
|
-
), e.labelName !== void 0 && typeof e.labelName != "string" && o.push(
|
|
281
|
-
r(
|
|
282
|
-
"invalid_comparison_presentation",
|
|
283
|
-
"Comparison presentation labelName must be a string.",
|
|
284
|
-
`${n}.labelName`
|
|
285
|
-
)
|
|
286
|
-
), ["conditionalLabels", "colors"].forEach((i) => {
|
|
287
|
-
const a = e[i];
|
|
288
|
-
if (a !== void 0) {
|
|
289
|
-
if (!p(a)) {
|
|
290
|
-
o.push(
|
|
291
|
-
r(
|
|
292
|
-
"invalid_comparison_presentation",
|
|
293
|
-
`Comparison presentation ${i} must be an object.`,
|
|
294
|
-
`${n}.${i}`
|
|
295
|
-
)
|
|
296
|
-
);
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
Object.keys(a).forEach((c) => {
|
|
300
|
-
["increase", "decrease", "neutral"].includes(c) || o.push(
|
|
301
|
-
r(
|
|
302
|
-
"invalid_comparison_presentation",
|
|
303
|
-
`Comparison presentation ${i} does not accept field "${c}".`,
|
|
304
|
-
`${n}.${i}.${c}`
|
|
305
|
-
)
|
|
306
|
-
);
|
|
307
|
-
}), Object.entries(a).forEach(([c, m]) => {
|
|
308
|
-
m !== void 0 && typeof m != "string" && o.push(
|
|
309
|
-
r(
|
|
310
|
-
"invalid_comparison_presentation",
|
|
311
|
-
`Comparison presentation ${i}.${c} must be a string.`,
|
|
312
|
-
`${n}.${i}.${c}`
|
|
313
|
-
)
|
|
314
|
-
);
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}), { ok: o.length === 0, errors: o, warnings: [] };
|
|
318
|
-
}
|
|
319
|
-
function $(e) {
|
|
320
|
-
return e === null ? "unknown" : e > 0 ? "increase" : e < 0 ? "decrease" : "no_change";
|
|
321
|
-
}
|
|
322
|
-
function h(e, n) {
|
|
323
|
-
return e === "unknown" || e === "no_change" || n === "neutral" ? "neutral" : n === "higher_is_better" && e === "increase" || n === "lower_is_better" && e === "decrease" ? "favorable" : "unfavorable";
|
|
324
|
-
}
|
|
325
|
-
function A(e) {
|
|
326
|
-
const {
|
|
327
|
-
currentValue: n,
|
|
328
|
-
comparisonValue: o,
|
|
329
|
-
polarity: s = u
|
|
330
|
-
} = e, i = n !== null && o !== null ? n - o : null, a = i !== null && o !== null && o !== 0 ? i / Math.abs(o) : null, c = n !== null && o !== null && o !== 0 ? n / o : null, m = $(i);
|
|
331
|
-
return {
|
|
332
|
-
status: o === null ? "insufficient_history" : "available",
|
|
333
|
-
currentValue: n,
|
|
334
|
-
comparisonValue: o,
|
|
335
|
-
delta: i,
|
|
336
|
-
percentChange: a,
|
|
337
|
-
ratio: c,
|
|
338
|
-
direction: m,
|
|
339
|
-
sentiment: h(m, s)
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
export {
|
|
343
|
-
D as C,
|
|
344
|
-
u as D,
|
|
345
|
-
S as a,
|
|
346
|
-
I as b,
|
|
347
|
-
C as c,
|
|
348
|
-
y as d,
|
|
349
|
-
A as e,
|
|
350
|
-
M as f,
|
|
351
|
-
b as g,
|
|
352
|
-
N as r,
|
|
353
|
-
T as v
|
|
354
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const g=require("./validators-B4VMLX3_.js"),u="higher_is_better",C={displayMode:"difference",showComparison:!0,indicatorStyle:"arrow_badge",showColor:!0,conditionalLabel:!1};function $(e){return g.parseSemaphorIsoInstant(e)!==null}function h(e){var i,o,s;if(((i=e.metricComparison)==null?void 0:i.mode)!=="off"){if(((o=e.metricComparison)==null?void 0:o.mode)==="explicit")return{source:"explicit",spec:e.metricComparison.spec};if(!(e.inheritGlobalComparison===!1||!e.isGlobalDateApplicable||((s=e.globalSelection)==null?void 0:s.mode)!=="period"))return{source:"inherited",spec:e.globalSelection.spec}}}function w(e){if(e.alias)return e.alias;const i=e.entityName&&e.entityName!=="SEMAPHOR_CALCULATED_FIELD"?e.entityName:void 0,o=i&&i!==e.name?`${i}_`:"";if(e.role!=="metric")return`${o}${e.name}`;let s=e.aggregate||"metric";if(e.expression){const t=e.expression.match(/^(COUNT|SUM|AVG|MIN|MAX|MEDIAN|DISTINCT)\s*\(/i);s=t?t[1].toLowerCase():"expr"}else s=s.toLowerCase();return`${o}${e.name}_${s}`}function r(e,i,o){return o?{code:e,message:i,path:o}:{code:e,message:i}}function p(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function c(e,i,o,s){Object.keys(e).forEach(t=>{i.includes(t)||s.push(r("invalid_comparison_spec",`Comparison kind does not accept field "${t}".`,`${o}.${t}`))})}function d(e,i,o){e.alignment!==void 0&&e.alignment!=="calendar"&&e.alignment!=="weekday"&&o.push(r("invalid_comparison_spec",'Comparison alignment must be "calendar" or "weekday".',`${i}.alignment`)),e.toDate!==void 0&&typeof e.toDate!="boolean"&&o.push(r("invalid_comparison_spec","Comparison toDate must be a boolean.",`${i}.toDate`))}function _(e,i,o){e!==void 0&&(typeof e!="number"||!Number.isSafeInteger(e)||e<=0)&&o.push(r("invalid_comparison_spec","Comparison offset must be a positive safe integer.",i))}function f(e,i="comparison"){const o=[];return p(e)?(e.kind==="previous_period"?(c(e,["kind","offsetPeriods","alignment","toDate"],i,o),_(e.offsetPeriods,`${i}.offsetPeriods`,o),d(e,i,o)):e.kind==="previous_year"?(c(e,["kind","offsetYears","alignment","toDate"],i,o),_(e.offsetYears,`${i}.offsetYears`,o),d(e,i,o)):e.kind==="target"?(c(e,["kind","targetValue"],i,o),(typeof e.targetValue!="number"||!Number.isFinite(e.targetValue))&&o.push(r("invalid_comparison_spec","Target comparison requires a finite targetValue.",`${i}.targetValue`))):o.push(r("invalid_comparison_spec","Comparison kind must be previous_period, previous_year, or target.",`${i}.kind`)),{ok:o.length===0,errors:o,warnings:[]}):{ok:!1,errors:[r("invalid_comparison_spec","Comparison spec must be an object.",i)],warnings:[]}}function M(e,i="comparison"){if(!p(e))return{ok:!1,errors:[r("invalid_comparison_config","Comparison config must be an object.",i)],warnings:[]};const o=[];return e.mode==="off"?c(e,["mode"],i,o):e.mode==="explicit"?(c(e,["mode","spec"],i,o),o.push(...f(e.spec,`${i}.spec`).errors)):o.push(r("invalid_comparison_config","Comparison mode must be off or explicit.",`${i}.mode`)),{ok:o.length===0,errors:o,warnings:[]}}function b(e,i="comparisonSelection"){if(!p(e))return{ok:!1,errors:[r("invalid_global_date_comparison","Global Date comparison selection must be an object.",i)],warnings:[]};const o=[];if(e.mode==="off")c(e,["mode"],i,o);else if(e.mode==="period"){c(e,["mode","spec"],i,o);const s=f(e.spec,`${i}.spec`);o.push(...s.errors),p(e.spec)&&e.spec.kind==="target"&&o.push(r("invalid_global_date_comparison","Global Date comparison supports previous_period or previous_year, not target.",`${i}.spec.kind`))}else o.push(r("invalid_global_date_comparison","Global Date comparison mode must be off or period.",`${i}.mode`));return{ok:o.length===0,errors:o,warnings:[]}}function S(e,i="globalDateComparison"){if(!p(e))return{ok:!1,errors:[r("invalid_global_date_comparison","Global Date comparison context must be an object.",i)],warnings:[]};const o=[];return c(e,["selection","inheritGlobalComparison","referenceTime"],i,o),o.push(...b(e.selection,`${i}.selection`).errors),e.inheritGlobalComparison!==void 0&&e.inheritGlobalComparison!==!1&&o.push(r("invalid_global_date_comparison","inheritGlobalComparison may only be false when present.",`${i}.inheritGlobalComparison`)),e.referenceTime!==void 0&&(typeof e.referenceTime!="string"||!$(e.referenceTime))&&o.push(r("invalid_global_date_comparison","referenceTime must be a valid ISO date-time string when present.",`${i}.referenceTime`)),{ok:o.length===0,errors:o,warnings:[]}}function v(e,i="comparisonPolarity"){return e==="higher_is_better"||e==="lower_is_better"||e==="neutral"?{ok:!0,errors:[],warnings:[]}:{ok:!1,errors:[r("invalid_comparison_polarity","Comparison polarity must be higher_is_better, lower_is_better, or neutral.",i)],warnings:[]}}function D(e,i="comparisonPresentation"){if(!p(e))return{ok:!1,errors:[r("invalid_comparison_presentation","Comparison presentation must be an object.",i)],warnings:[]};const o=[],s=["displayMode","showComparison","precision","indicatorStyle","showColor","position","conditionalLabel","labelName","conditionalLabels","colors"];return Object.keys(e).forEach(n=>{s.includes(n)||o.push(r("invalid_comparison_presentation",`Comparison presentation does not accept field "${n}".`,`${i}.${n}`))}),[["displayMode",["difference","percent_change","both","ratio"]],["indicatorStyle",["arrow_badge","arrow","badge","none"]],["position",["left","right","top"]]].forEach(([n,a])=>{e[n]!==void 0&&!a.includes(e[n])&&o.push(r("invalid_comparison_presentation",`Comparison presentation ${n} is invalid.`,`${i}.${n}`))}),["showComparison","showColor","conditionalLabel"].forEach(n=>{e[n]!==void 0&&typeof e[n]!="boolean"&&o.push(r("invalid_comparison_presentation",`Comparison presentation ${n} must be a boolean.`,`${i}.${n}`))}),e.precision!==void 0&&(typeof e.precision!="number"||!Number.isInteger(e.precision)||e.precision<0||e.precision>6)&&o.push(r("invalid_comparison_presentation","Comparison presentation precision must be an integer from 0 through 6.",`${i}.precision`)),e.labelName!==void 0&&typeof e.labelName!="string"&&o.push(r("invalid_comparison_presentation","Comparison presentation labelName must be a string.",`${i}.labelName`)),["conditionalLabels","colors"].forEach(n=>{const a=e[n];if(a!==void 0){if(!p(a)){o.push(r("invalid_comparison_presentation",`Comparison presentation ${n} must be an object.`,`${i}.${n}`));return}Object.keys(a).forEach(l=>{["increase","decrease","neutral"].includes(l)||o.push(r("invalid_comparison_presentation",`Comparison presentation ${n} does not accept field "${l}".`,`${i}.${n}.${l}`))}),Object.entries(a).forEach(([l,m])=>{m!==void 0&&typeof m!="string"&&o.push(r("invalid_comparison_presentation",`Comparison presentation ${n}.${l} must be a string.`,`${i}.${n}.${l}`))})}}),{ok:o.length===0,errors:o,warnings:[]}}function A(e){return e===null?"unknown":e>0?"increase":e<0?"decrease":"no_change"}function N(e,i){return e==="unknown"||e==="no_change"||i==="neutral"?"neutral":i==="higher_is_better"&&e==="increase"||i==="lower_is_better"&&e==="decrease"?"favorable":"unfavorable"}function T(e){const{currentValue:i,comparisonValue:o,polarity:s=u}=e,n=i!==null&&o!==null?i-o:null,a=n!==null&&o!==null&&o!==0?n/Math.abs(o):null,l=i!==null&&o!==null&&o!==0?i/o:null,m=A(n);return{status:o===null?"insufficient_history":"available",currentValue:i,comparisonValue:o,delta:n,percentChange:a,ratio:l,direction:m,sentiment:N(m,s)}}exports.COMPARISON_PRESENTATION_DEFAULTS=C;exports.DEFAULT_METRIC_COMPARISON_POLARITY=u;exports.evaluateMetricComparison=T;exports.resolveMetricComparisonRequest=h;exports.resolveMetricResultAlias=w;exports.validateComparisonPresentationSpec=D;exports.validateGlobalDateComparisonContext=S;exports.validateGlobalDateComparisonSelection=b;exports.validateMetricComparisonConfig=M;exports.validateMetricComparisonPolarity=v;exports.validateMetricComparisonSpec=f;
|