react-semaphor 0.1.459 → 0.1.461
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/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +32 -32
- package/dist/brand-studio/index.cjs +1 -1
- package/dist/brand-studio/index.js +4 -4
- package/dist/briefings/index.cjs +1 -1
- package/dist/briefings/index.js +4 -4
- package/dist/chunks/{analyze-result-contract-BbRJ-C06.js → analyze-result-contract-DROq4vgY.js} +1 -1
- package/dist/chunks/{analyze-result-contract-LPDNldic.cjs → analyze-result-contract-DSGoFuXQ.cjs} +1 -1
- package/dist/chunks/canonical-result-keys-CEQefvdO.js +33 -0
- package/dist/chunks/canonical-result-keys-Cb96edol.cjs +1 -0
- package/dist/chunks/{common-types-H51FLKB7.js → common-types-BHVKgxRR.js} +1 -1
- package/dist/chunks/{common-types-C57kJ59w.cjs → common-types-BcV9PD9D.cjs} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-ClCj98sq.js → dashboard-briefing-launcher-3owMxX5K.js} +60 -61
- package/dist/chunks/{dashboard-briefing-launcher-DHtEouuH.cjs → dashboard-briefing-launcher-xuGrw8H3.cjs} +2 -2
- package/dist/chunks/{dashboard-controls-B8gsKlxc.js → dashboard-controls-B4GvjGr1.js} +44 -45
- package/dist/chunks/{dashboard-controls-VRShl9J0.cjs → dashboard-controls-Bpm_xOXQ.cjs} +1 -1
- package/dist/chunks/dashboard-filter-value-compatibility-KXIyvbhc.js +677 -0
- package/dist/chunks/dashboard-filter-value-compatibility-UapptYnn.cjs +1 -0
- package/dist/chunks/dashboard-input-contract-BkRFQ7Tq.cjs +1 -0
- package/dist/chunks/{dashboard-date-comparison-definition-DC3ekV2S.js → dashboard-input-contract-D5dxTWJ5.js} +41 -25
- package/dist/chunks/{dashboard-json-i_Auue_K.js → dashboard-json-DzyxoBp-.js} +13 -14
- package/dist/chunks/dashboard-json-yLM01xK4.cjs +1 -0
- package/dist/chunks/{edit-dashboard-visual-DWWyT55u.cjs → edit-dashboard-visual-1T278Nr_.cjs} +28 -28
- package/dist/chunks/{edit-dashboard-visual-B3JF0fe4.js → edit-dashboard-visual-nwSasO_j.js} +880 -894
- package/dist/chunks/{editor-action-buttons-BTlCsP63.cjs → editor-action-buttons-CX1Pken3.cjs} +2 -2
- package/dist/chunks/{editor-action-buttons-C9x3nGnb.js → editor-action-buttons-Dqw0asfA.js} +28 -28
- package/dist/chunks/index-B1qplNxl.cjs +1392 -0
- package/dist/chunks/{index-BS2-ZZGf.js → index-DazD5k0F.js} +45362 -42931
- package/dist/chunks/{index-BIFLI8ul.js → index-De_7nrwb.js} +10 -10
- package/dist/chunks/index-DjjKJPDy.cjs +4 -0
- package/dist/chunks/{matrix-result-contract-CofATICL.js → matrix-result-contract-BTpPuHOc.js} +88 -104
- package/dist/chunks/matrix-result-contract-ZRNfeIbI.cjs +1 -0
- package/dist/chunks/{pivot-header-presentation-B9nXXKlW.cjs → pivot-header-presentation-BijPbP33.cjs} +1 -1
- package/dist/chunks/{pivot-header-presentation-D-0jvUwn.js → pivot-header-presentation-DW0gKG8g.js} +2 -2
- package/dist/chunks/{pivot-result-identity-Bb4EixVN.cjs → pivot-result-identity-DxHtiKVj.cjs} +1 -1
- package/dist/chunks/{pivot-result-identity-DU1v-5Xk.js → pivot-result-identity-Z9tN2tEV.js} +1 -1
- package/dist/chunks/{pivot-result-lifecycle-DTLRuDEW.cjs → pivot-result-lifecycle-BXzIlQVu.cjs} +1 -1
- package/dist/chunks/{pivot-result-lifecycle-CHWEGU2o.js → pivot-result-lifecycle-g2U-vzQb.js} +7 -7
- package/dist/chunks/{raw-temporal-contract-BtjH_G-d.cjs → raw-temporal-contract-DfAvqNMo.cjs} +1 -1
- package/dist/chunks/{raw-temporal-contract-CxncLze5.js → raw-temporal-contract-UtAqoOZO.js} +1 -1
- package/dist/chunks/{report-preferences-dialog-BK0yAJnQ.cjs → report-preferences-dialog-DKPyjiCt.cjs} +1 -1
- package/dist/chunks/{report-preferences-dialog-BDpkcUtz.js → report-preferences-dialog-Dv3vCCFt.js} +6 -6
- package/dist/chunks/{report-runtime-context-DqxS4wbi.cjs → report-runtime-context-C0NfLPfc.cjs} +1 -1
- package/dist/chunks/{report-runtime-context-SM6YO61_.js → report-runtime-context-CNncA3VD.js} +11 -11
- package/dist/chunks/{saved-temporal-bucket-format-CFfWXRl9.cjs → saved-temporal-bucket-format-3QKveR3v.cjs} +1 -1
- package/dist/chunks/{saved-temporal-bucket-format-SGAV0ivR.js → saved-temporal-bucket-format-Dd2eixTH.js} +11 -11
- package/dist/chunks/switch-DBZsEV0U.cjs +138 -0
- package/dist/chunks/{switch-DQR-Va05.js → switch-kPUJEC1A.js} +6615 -5219
- package/dist/chunks/{temporal-bucket-5UYEotyQ.js → temporal-bucket-C85rmFmC.js} +4 -4
- package/dist/chunks/temporal-bucket-authoring-1fZuPAVb.js +653 -0
- package/dist/chunks/temporal-bucket-authoring-BK1UhYpD.cjs +1 -0
- package/dist/chunks/{temporal-bucket-contract-D5d-xEl3.js → temporal-bucket-contract-DXXNZssK.js} +1 -1
- package/dist/chunks/{temporal-bucket-contract-D2-93DGr.cjs → temporal-bucket-contract-xFkvboaw.cjs} +1 -1
- package/dist/chunks/{temporal-bucket-DHY1y9lq.cjs → temporal-bucket-pMfghsLX.cjs} +1 -1
- package/dist/chunks/{token-types-GbxRUozo.js → token-types-BLxc7UwR.js} +1 -1
- package/dist/chunks/{token-types-D7CaaI80.cjs → token-types-BYYO109W.cjs} +1 -1
- package/dist/chunks/{update-policy-hednMF-0.js → update-policy-CB8XJIoY.js} +1 -1
- package/dist/chunks/{update-policy-BmiOd0PB.cjs → update-policy-DMjjGjQY.cjs} +1 -1
- package/dist/chunks/{validators-DEmd8Sin.js → validators-DVd8s3qY.js} +416 -350
- package/dist/chunks/validators-dJlwubP4.cjs +1 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +2 -2
- package/dist/dashboard-authoring/index.cjs +3 -3
- package/dist/dashboard-authoring/index.js +328 -311
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +2 -2
- package/dist/data-app-codegen/index.cjs +1 -1
- package/dist/data-app-codegen/index.js +2 -2
- package/dist/data-app-codegen-node/index.cjs +1 -1
- package/dist/data-app-codegen-node/index.js +3 -3
- package/dist/data-app-sdk/index.cjs +1 -1
- package/dist/data-app-sdk/index.js +55 -55
- package/dist/data-app-sdk-adapters/index.cjs +1 -1
- package/dist/data-app-sdk-adapters/index.js +61 -56
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +9 -9
- package/dist/format-utils/index.cjs +1 -1
- package/dist/format-utils/index.js +15 -15
- package/dist/index.cjs +1 -1
- package/dist/index.js +154 -155
- package/dist/report-runtime-context/index.cjs +1 -1
- package/dist/report-runtime-context/index.js +2 -2
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +3 -3
- package/dist/types/analytics-protocol.d.ts +16 -8
- package/dist/types/briefings.d.ts +95 -13
- package/dist/types/dashboard-assistant.d.ts +11 -6
- package/dist/types/dashboard-authoring.d.ts +257 -19
- package/dist/types/dashboard.d.ts +109 -14
- package/dist/types/data-app-builder.d.ts +11 -6
- package/dist/types/data-app-codegen-node.d.ts +16 -8
- package/dist/types/data-app-codegen.d.ts +16 -8
- package/dist/types/data-app-sdk-adapters.d.ts +17 -11
- package/dist/types/data-app-sdk-validation.d.ts +17 -11
- package/dist/types/data-app-sdk.d.ts +17 -11
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.js +4 -4
- package/dist/types/main.d.ts +225 -20
- package/dist/types/shared.d.ts +95 -13
- package/dist/types/surfboard.d.ts +109 -14
- package/dist/types/types.d.ts +109 -14
- package/package.json +1 -1
- package/dist/chunks/canonical-result-keys-BA0HCP4e.cjs +0 -1
- package/dist/chunks/canonical-result-keys-D6avdjpA.js +0 -467
- package/dist/chunks/dashboard-date-comparison-definition-Ces4alFm.cjs +0 -1
- package/dist/chunks/dashboard-json-BhvPMpZA.cjs +0 -1
- package/dist/chunks/index-DHF-2AqS.cjs +0 -1392
- package/dist/chunks/index-k8tEp0ys.cjs +0 -4
- package/dist/chunks/matrix-result-contract-zamd9euI.cjs +0 -1
- package/dist/chunks/switch-f3TuZNLr.cjs +0 -138
- package/dist/chunks/temporal-bucket-authoring-K1kE6R_z.js +0 -222
- package/dist/chunks/temporal-bucket-authoring-o3Emn05L.cjs +0 -1
- package/dist/chunks/validators-BDYprKI9.cjs +0 -1
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { d as c, e as f } from "./validators-DEmd8Sin.js";
|
|
2
|
-
import { f as H } from "./temporal-bucket-5UYEotyQ.js";
|
|
3
|
-
import { DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES as d } from "../value-format-preferences/index.js";
|
|
4
|
-
const l = {
|
|
5
|
-
type: "temporal_bucket",
|
|
6
|
-
presentation: { mode: "auto" }
|
|
7
|
-
}, M = {
|
|
8
|
-
value: "auto",
|
|
9
|
-
label: "Automatic",
|
|
10
|
-
format: l
|
|
11
|
-
};
|
|
12
|
-
function Y(t, e) {
|
|
13
|
-
return {
|
|
14
|
-
value: `pattern:${t}`,
|
|
15
|
-
label: e,
|
|
16
|
-
format: {
|
|
17
|
-
type: "temporal_bucket",
|
|
18
|
-
presentation: { mode: "pattern", pattern: t }
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function i(t, e) {
|
|
23
|
-
return {
|
|
24
|
-
value: `preset:${t}`,
|
|
25
|
-
label: e,
|
|
26
|
-
format: {
|
|
27
|
-
type: "temporal_bucket",
|
|
28
|
-
presentation: { mode: "preset", preset: t }
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function p(t) {
|
|
33
|
-
return {
|
|
34
|
-
...Y(t, "Custom format…"),
|
|
35
|
-
value: "custom",
|
|
36
|
-
custom: !0
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const D = {
|
|
40
|
-
second: [
|
|
41
|
-
M,
|
|
42
|
-
Y("HH:mm:ss", "14:30:45 (HH:mm:ss)"),
|
|
43
|
-
Y(
|
|
44
|
-
"YYYY-MM-DD HH:mm:ss",
|
|
45
|
-
"2024-01-15 14:30:45 (YYYY-MM-DD HH:mm:ss)"
|
|
46
|
-
),
|
|
47
|
-
p("DD/MM/YYYY HH:mm:ss")
|
|
48
|
-
],
|
|
49
|
-
minute: [
|
|
50
|
-
M,
|
|
51
|
-
Y("HH:mm", "14:30 (HH:mm)"),
|
|
52
|
-
Y("YYYY-MM-DD HH:mm", "2024-01-15 14:30 (YYYY-MM-DD HH:mm)"),
|
|
53
|
-
p("DD/MM/YYYY HH:mm")
|
|
54
|
-
],
|
|
55
|
-
hour: [
|
|
56
|
-
M,
|
|
57
|
-
Y("HH", "14 (HH)"),
|
|
58
|
-
Y("YYYY-MM-DD HH", "2024-01-15 14 (YYYY-MM-DD HH)"),
|
|
59
|
-
p("DD/MM/YYYY HH")
|
|
60
|
-
],
|
|
61
|
-
day: [
|
|
62
|
-
M,
|
|
63
|
-
Y("YYYY-MM-DD", "2024-01-15 (YYYY-MM-DD)"),
|
|
64
|
-
Y("MM/DD/YYYY", "01/15/2024 (MM/DD/YYYY)"),
|
|
65
|
-
Y("DD/MM/YYYY", "15/01/2024 (DD/MM/YYYY)"),
|
|
66
|
-
Y("MMM DD, YYYY", "Jan 15, 2024 (MMM DD, YYYY)"),
|
|
67
|
-
Y("MMMM DD, YYYY", "January 15, 2024 (MMMM DD, YYYY)"),
|
|
68
|
-
p("YYYY/MM/DD")
|
|
69
|
-
],
|
|
70
|
-
week: [
|
|
71
|
-
M,
|
|
72
|
-
i("week_of_short", "Week of Jan 15, 2024"),
|
|
73
|
-
i("week_of_long", "Week of January 15, 2024"),
|
|
74
|
-
Y("YYYY-MM-DD", "2024-01-15 (YYYY-MM-DD)"),
|
|
75
|
-
p("YYYY/MM/DD")
|
|
76
|
-
],
|
|
77
|
-
month: [
|
|
78
|
-
M,
|
|
79
|
-
Y("MMM YYYY", "Jan 2024 (MMM YYYY)"),
|
|
80
|
-
Y("MMMM YYYY", "January 2024 (MMMM YYYY)"),
|
|
81
|
-
Y("YYYY-MM", "2024-01 (YYYY-MM)"),
|
|
82
|
-
Y("MM/YYYY", "01/2024 (MM/YYYY)"),
|
|
83
|
-
Y("YYYY MMM", "2024 Jan (YYYY MMM)"),
|
|
84
|
-
p("YYYY/MM")
|
|
85
|
-
],
|
|
86
|
-
quarter: [
|
|
87
|
-
M,
|
|
88
|
-
i("quarter_short", "Q1 2024"),
|
|
89
|
-
i("quarter_long", "1st Quarter 2024")
|
|
90
|
-
],
|
|
91
|
-
year: [
|
|
92
|
-
M,
|
|
93
|
-
Y("YYYY", "2024 (YYYY)"),
|
|
94
|
-
Y("YY", "24 (YY)")
|
|
95
|
-
]
|
|
96
|
-
}, _ = {
|
|
97
|
-
second: "2026-07-31T14:05:09",
|
|
98
|
-
minute: "2026-07-31T14:05:00",
|
|
99
|
-
hour: "2026-07-31T14:00:00",
|
|
100
|
-
day: "2026-07-31",
|
|
101
|
-
week: "2026-07-27",
|
|
102
|
-
month: "2026-07-01",
|
|
103
|
-
quarter: "2026-07-01",
|
|
104
|
-
year: "2026-01-01"
|
|
105
|
-
};
|
|
106
|
-
function k(t, e, n = d) {
|
|
107
|
-
return H({
|
|
108
|
-
value: _[e],
|
|
109
|
-
metadata: {
|
|
110
|
-
kind: "temporal_bucket",
|
|
111
|
-
granularity: e,
|
|
112
|
-
calendar: {
|
|
113
|
-
tz: "UTC",
|
|
114
|
-
weekStart: 1,
|
|
115
|
-
...t.presentation.mode === "preset" && (t.presentation.preset === "fiscal_quarter_short" || t.presentation.preset === "fiscal_year") ? {
|
|
116
|
-
fiscalCalendar: {
|
|
117
|
-
kind: "month_aligned",
|
|
118
|
-
yearStartMonth: 7
|
|
119
|
-
}
|
|
120
|
-
} : {}
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
format: t.presentation.mode === "auto" ? {
|
|
124
|
-
type: "temporal_bucket",
|
|
125
|
-
locale: n.locale,
|
|
126
|
-
presentation: {
|
|
127
|
-
mode: "auto",
|
|
128
|
-
styles: {
|
|
129
|
-
dateStyle: n.dateStyle,
|
|
130
|
-
dateTime: { ...n.dateTime }
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
} : {
|
|
134
|
-
type: "temporal_bucket",
|
|
135
|
-
locale: n.locale,
|
|
136
|
-
presentation: t.presentation
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
function b(t, e, n = d) {
|
|
141
|
-
const o = D[t], r = (e == null ? void 0 : e.presentation.mode) === "preset" ? e.presentation.preset : void 0, s = r && e && c(e, t).ok && !o.some(
|
|
142
|
-
(a) => {
|
|
143
|
-
var u;
|
|
144
|
-
return ((u = a.format) == null ? void 0 : u.presentation.mode) === "preset" && a.format.presentation.preset === r;
|
|
145
|
-
}
|
|
146
|
-
) ? i(r, r) : void 0;
|
|
147
|
-
return (s ? [...o, s] : o).map((a) => {
|
|
148
|
-
if (!a.format || a.custom) return a;
|
|
149
|
-
const u = k(
|
|
150
|
-
a.format,
|
|
151
|
-
t,
|
|
152
|
-
n
|
|
153
|
-
);
|
|
154
|
-
return a.format.presentation.mode === "pattern" ? {
|
|
155
|
-
...a,
|
|
156
|
-
label: `${u} (${a.format.presentation.pattern})`
|
|
157
|
-
} : a.format.presentation.mode === "auto" ? { ...a, label: `Automatic (${u})` } : { ...a, label: u };
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
function y(t, e) {
|
|
161
|
-
const n = D[e];
|
|
162
|
-
if (t.presentation.mode === "pattern") {
|
|
163
|
-
const o = t.presentation.pattern, r = n.find(
|
|
164
|
-
(s) => {
|
|
165
|
-
var m;
|
|
166
|
-
return ((m = s.format) == null ? void 0 : m.presentation.mode) === "pattern" && s.format.presentation.pattern === o;
|
|
167
|
-
}
|
|
168
|
-
);
|
|
169
|
-
return {
|
|
170
|
-
value: (r == null ? void 0 : r.value) ?? "custom",
|
|
171
|
-
customPattern: r != null && r.custom || !r ? o : "",
|
|
172
|
-
format: t
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
if (t.presentation.mode === "preset") {
|
|
176
|
-
const o = t.presentation.preset, r = n.find(
|
|
177
|
-
(m) => {
|
|
178
|
-
var a;
|
|
179
|
-
return ((a = m.format) == null ? void 0 : a.presentation.mode) === "preset" && m.format.presentation.preset === o;
|
|
180
|
-
}
|
|
181
|
-
), s = c(
|
|
182
|
-
t,
|
|
183
|
-
e
|
|
184
|
-
).ok;
|
|
185
|
-
return r ? { value: r.value, customPattern: "", format: t } : s ? {
|
|
186
|
-
value: `preset:${o}`,
|
|
187
|
-
customPattern: "",
|
|
188
|
-
format: t
|
|
189
|
-
} : { value: "auto", customPattern: "", format: l };
|
|
190
|
-
}
|
|
191
|
-
return { value: "auto", customPattern: "", format: t };
|
|
192
|
-
}
|
|
193
|
-
function v(t, e, n = "") {
|
|
194
|
-
var m;
|
|
195
|
-
const o = D[t].find(
|
|
196
|
-
(a) => a.value === e
|
|
197
|
-
), r = e.startsWith("preset:") ? e.slice(7) : void 0, s = e === "custom" ? {
|
|
198
|
-
type: "temporal_bucket",
|
|
199
|
-
presentation: {
|
|
200
|
-
mode: "pattern",
|
|
201
|
-
pattern: n.trim() || (((m = o == null ? void 0 : o.format) == null ? void 0 : m.presentation.mode) === "pattern" ? o.format.presentation.pattern : "")
|
|
202
|
-
}
|
|
203
|
-
} : (o == null ? void 0 : o.format) ?? (r && f(r) ? {
|
|
204
|
-
type: "temporal_bucket",
|
|
205
|
-
presentation: {
|
|
206
|
-
mode: "preset",
|
|
207
|
-
preset: r
|
|
208
|
-
}
|
|
209
|
-
} : void 0);
|
|
210
|
-
return !s || !c(s, t).ok ? l : s;
|
|
211
|
-
}
|
|
212
|
-
function E(t, e) {
|
|
213
|
-
return c(t, e).ok ? t : l;
|
|
214
|
-
}
|
|
215
|
-
export {
|
|
216
|
-
l as A,
|
|
217
|
-
y as a,
|
|
218
|
-
E as b,
|
|
219
|
-
b as g,
|
|
220
|
-
k as p,
|
|
221
|
-
v as r
|
|
222
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const c=require("./validators-BDYprKI9.cjs"),T=require("./temporal-bucket-DHY1y9lq.cjs"),d=require("../value-format-preferences/index.cjs"),l={type:"temporal_bucket",presentation:{mode:"auto"}},m={value:"auto",label:"Automatic",format:l};function r(t,e){return{value:`pattern:${t}`,label:e,format:{type:"temporal_bucket",presentation:{mode:"pattern",pattern:t}}}}function M(t,e){return{value:`preset:${t}`,label:e,format:{type:"temporal_bucket",presentation:{mode:"preset",preset:t}}}}function p(t){return{...r(t,"Custom format…"),value:"custom",custom:!0}}const D={second:[m,r("HH:mm:ss","14:30:45 (HH:mm:ss)"),r("YYYY-MM-DD HH:mm:ss","2024-01-15 14:30:45 (YYYY-MM-DD HH:mm:ss)"),p("DD/MM/YYYY HH:mm:ss")],minute:[m,r("HH:mm","14:30 (HH:mm)"),r("YYYY-MM-DD HH:mm","2024-01-15 14:30 (YYYY-MM-DD HH:mm)"),p("DD/MM/YYYY HH:mm")],hour:[m,r("HH","14 (HH)"),r("YYYY-MM-DD HH","2024-01-15 14 (YYYY-MM-DD HH)"),p("DD/MM/YYYY HH")],day:[m,r("YYYY-MM-DD","2024-01-15 (YYYY-MM-DD)"),r("MM/DD/YYYY","01/15/2024 (MM/DD/YYYY)"),r("DD/MM/YYYY","15/01/2024 (DD/MM/YYYY)"),r("MMM DD, YYYY","Jan 15, 2024 (MMM DD, YYYY)"),r("MMMM DD, YYYY","January 15, 2024 (MMMM DD, YYYY)"),p("YYYY/MM/DD")],week:[m,M("week_of_short","Week of Jan 15, 2024"),M("week_of_long","Week of January 15, 2024"),r("YYYY-MM-DD","2024-01-15 (YYYY-MM-DD)"),p("YYYY/MM/DD")],month:[m,r("MMM YYYY","Jan 2024 (MMM YYYY)"),r("MMMM YYYY","January 2024 (MMMM YYYY)"),r("YYYY-MM","2024-01 (YYYY-MM)"),r("MM/YYYY","01/2024 (MM/YYYY)"),r("YYYY MMM","2024 Jan (YYYY MMM)"),p("YYYY/MM")],quarter:[m,M("quarter_short","Q1 2024"),M("quarter_long","1st Quarter 2024")],year:[m,r("YYYY","2024 (YYYY)"),r("YY","24 (YY)")]},_={second:"2026-07-31T14:05:09",minute:"2026-07-31T14:05:00",hour:"2026-07-31T14:00:00",day:"2026-07-31",week:"2026-07-27",month:"2026-07-01",quarter:"2026-07-01",year:"2026-01-01"};function k(t,e,Y=d.DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES){return T.formatTemporalBucket({value:_[e],metadata:{kind:"temporal_bucket",granularity:e,calendar:{tz:"UTC",weekStart:1,...t.presentation.mode==="preset"&&(t.presentation.preset==="fiscal_quarter_short"||t.presentation.preset==="fiscal_year")?{fiscalCalendar:{kind:"month_aligned",yearStartMonth:7}}:{}}},format:t.presentation.mode==="auto"?{type:"temporal_bucket",locale:Y.locale,presentation:{mode:"auto",styles:{dateStyle:Y.dateStyle,dateTime:{...Y.dateTime}}}}:{type:"temporal_bucket",locale:Y.locale,presentation:t.presentation}})}function A(t,e,Y=d.DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES){const n=D[t],o=(e==null?void 0:e.presentation.mode)==="preset"?e.presentation.preset:void 0,s=o&&e&&c.validateTemporalBucketFormatApplicability(e,t).ok&&!n.some(a=>{var i;return((i=a.format)==null?void 0:i.presentation.mode)==="preset"&&a.format.presentation.preset===o})?M(o,o):void 0;return(s?[...n,s]:n).map(a=>{if(!a.format||a.custom)return a;const i=k(a.format,t,Y);return a.format.presentation.mode==="pattern"?{...a,label:`${i} (${a.format.presentation.pattern})`}:a.format.presentation.mode==="auto"?{...a,label:`Automatic (${i})`}:{...a,label:i}})}function f(t,e){const Y=D[e];if(t.presentation.mode==="pattern"){const n=t.presentation.pattern,o=Y.find(s=>{var u;return((u=s.format)==null?void 0:u.presentation.mode)==="pattern"&&s.format.presentation.pattern===n});return{value:(o==null?void 0:o.value)??"custom",customPattern:o!=null&&o.custom||!o?n:"",format:t}}if(t.presentation.mode==="preset"){const n=t.presentation.preset,o=Y.find(u=>{var a;return((a=u.format)==null?void 0:a.presentation.mode)==="preset"&&u.format.presentation.preset===n}),s=c.validateTemporalBucketFormatApplicability(t,e).ok;return o?{value:o.value,customPattern:"",format:t}:s?{value:`preset:${n}`,customPattern:"",format:t}:{value:"auto",customPattern:"",format:l}}return{value:"auto",customPattern:"",format:t}}function H(t,e,Y=""){var u;const n=D[t].find(a=>a.value===e),o=e.startsWith("preset:")?e.slice(7):void 0,s=e==="custom"?{type:"temporal_bucket",presentation:{mode:"pattern",pattern:Y.trim()||(((u=n==null?void 0:n.format)==null?void 0:u.presentation.mode)==="pattern"?n.format.presentation.pattern:"")}}:(n==null?void 0:n.format)??(o&&c.isTemporalBucketPreset(o)?{type:"temporal_bucket",presentation:{mode:"preset",preset:o}}:void 0);return!s||!c.validateTemporalBucketFormatApplicability(s,t).ok?l:s}function E(t,e){return c.validateTemporalBucketFormatApplicability(t,e).ok?t:l}exports.AUTOMATIC_TEMPORAL_BUCKET_FORMAT=l;exports.getTemporalBucketAuthoringOptions=A;exports.getTemporalBucketAuthoringSelection=f;exports.previewTemporalBucketAuthoringFormat=k;exports.reconcileTemporalBucketAuthoringFormat=E;exports.resolveTemporalBucketAuthoringFormat=H;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const a=require("zod"),T=["second","minute","hour","day","week","month","quarter","year"];function ii(e){return typeof e=="string"&&T.includes(e)}const[,,...ie]=T;function ti(e){return ii(e)&&ie.includes(e)}const ai=["week_of_short","week_of_long","quarter_short","quarter_long","fiscal_quarter_short","fiscal_year"],Ji={invalidMetadata:"invalid_raw_temporal_metadata"};function ni(e){return e==="second"||e==="minute"||e==="hour"?"datetime":"date"}const et={missingMetadata:"missing_temporal_bucket_metadata",invalidMetadata:"invalid_temporal_bucket_metadata",invalidValue:"invalid_temporal_bucket_value"},it="__auto_count__";function si(e){try{return new Intl.DateTimeFormat("en-US",{timeZone:e}).format(),!0}catch{return!1}}const oi={answerSummary:"string",responseDetail:"responseDetail",mode:"string",comparisonKind:"string",executionResult:"executionResult",compiledQuery:"unknown",data:"unknown",resultSets:"record",analysisWarnings:"unknownArray",columns:"unknownArray",records:"recordArray",rowCount:"number",rowLimitExceeded:"boolean",output:"string",querySpec:"unknown",metadata:"record",validation:"validationResult",coverage:"coverage",diagnosticFeedback:"diagnosticFeedback",missingFields:"stringArray",warnings:"unknownArray",comparison:"unknown",population:"population",comparisons:"recordArray",fieldsUsed:"compactExecutionFieldArray",primary:"recordArray",contributors:"recordArray",segments:"recordArray",periodChanges:"recordArray",changes:"recordArray",largestNegativeChanges:"recordArray",largestPositiveChanges:"recordArray",drivers:"recordArray",absoluteDeltaDrivers:"recordArray",largestNegativeDrivers:"recordArray",largestPositiveDrivers:"recordArray",periodRows:"recordArray",sql:"unknown",omitted:"stringArray"},tt="SUM";function I(e){return typeof e=="string"&&e.trim().length>0}function at(e){return e?e.kind==="semantic"?!!(I(e.domainId)&&(I(e.datasetId)||I(e.datasetName))):e.kind==="physical"?I(e.connectionId)&&I(e.tableName):I(e.connectionId):!1}function U(e){return e?e.kind==="semantic"?[e.kind,e.domainId,e.datasetId?`datasetId:${e.datasetId}`:`datasetName:${e.datasetName}`].join(":"):e.kind==="physical"?[e.kind,e.connectionId,e.databaseName||"",e.schemaName||"",e.tableName].join(":"):[e.kind,e.connectionId,e.dialect||"",e.label||""].join(":"):""}function ve(e,i){return!e||!i?e===i:e.kind!==i.kind?!1:e.kind==="semantic"&&i.kind==="semantic"?e.domainId!==i.domainId?!1:e.datasetId&&i.datasetId?e.datasetId===i.datasetId:e.datasetName===i.datasetName:U(e)===U(i)}function ze(e,i){return e.kind!=="semantic"||i.kind!=="semantic"?e:{...e,datasetName:e.datasetName||i.datasetName,datasetId:e.datasetId||i.datasetId,label:e.label||i.label,connectionId:e.connectionId||i.connectionId}}function nt(e){const i=[];for(const t of e){const n=i.findIndex(s=>ve(s,t));if(n===-1){i.push(t);continue}i[n]=ze(i[n],t)}return i}function ri(e,i){return e.name===i.name&&ve(e.source,i.source)}function li(e){return[e.source?U(e.source):"unknown",te(e),e.name].filter(Boolean).join(":")}function te(e){return st(e.aggregate||tt)}function st(e){return e.trim().toUpperCase()}function ot(e,i){return{...e,label:e.label||i.label,role:e.role||i.role,dataType:e.dataType||i.dataType,source:e.source&&i.source?ze(e.source,i.source):e.source||i.source}}const Y="semaphor-data-app-codegen-summary/v1",rt="semaphor-data-app-codegen-summary-validator/v2",lt=new Set(["metric","records","matrix","analysis","sql_fallback"]),dt=new Set(["semaphor.metric","semaphor.records","semaphor.matrix","semaphor.analysis","semaphor.sql"]),ut=new Set(["SUM","COUNT","AVG","MIN","MAX","MEDIAN","DISTINCT"]),ct=new Set(["absolute_delta","largest_negative","largest_positive","positive_and_negative","all"]),di=new Set(["source","id","label","measures","primaryMeasure","dateField","timeGrain","dimensions","comparison","orderBy","filters","relationshipHint","limit","derivedFields"]),pt=new Set([...di,"analysis","timeWindow","filters","driverMode","includePopulation","calendarContext","chartTitle","chartType"]),mt=new Set(["source","id","label","fields","dateField","timeGrain","timeWindow","filters","orderBy","relationshipHint","limit","pagination","totals","derivedFields"]),ft=new Set(["source","id","label","filters","relationshipHint","rows","columns","values","totals","sort","expansion","layout","displayLimits"]),gt=new Set(["source","id","label","sql","defaultParameters","pythonCode","fields","limit","pagination","rationale"]),ht=new Set(["kpi","line_chart","bar_chart","stacked_bar_chart","pie_chart","donut_chart","area_chart","table","matrix","narrative","text_block","custom"]),yt=new Set(["missing_measure","missing_dimension","missing_date","missing_relationship","missing_semantic_role","missing_current_app_state","raw_identifier_filter_options","unsupported_change_intent","ambiguous_field_grounding","bounded_intent_unavailable","invalid_bounded_intent_output","latest_snapshot_selector_not_modeled","unsupported_grain","requires_sql_escape_hatch","unsupported_sdk_capability"]);function bt(e){return Se(e).ok}function Se(e){const i=[];if(!e||typeof e!="object")return{ok:!1,issues:["Summary must be an object."]};const t=e;return t.schemaVersion!==Y&&i.push(`schemaVersion must be ${Y}.`),(typeof t.title!="string"||!t.title.trim())&&i.push("title is required."),Array.isArray(t.sources)||i.push("sources must be an array."),Array.isArray(t.inputs)||i.push("inputs must be an array."),Array.isArray(t.views)||i.push("views must be an array."),Array.isArray(t.filterContracts)||i.push("filterContracts must be an array."),(!t.implementationChecklist||typeof t.implementationChecklist!="object")&&i.push("implementationChecklist must be an object."),t.implementationChecklist&&typeof t.implementationChecklist=="object"&&i.push(...vt(t.implementationChecklist)),Array.isArray(t.sources)&&t.sources.forEach((n,s)=>{i.push(...O(n,`sources.${s}`))}),Array.isArray(t.inputs)&&t.inputs.forEach((n,s)=>{i.push(...zt(n,`inputs.${s}`))}),Array.isArray(t.views)&&t.views.forEach((n,s)=>{i.push(...St(n,`views.${s}`))}),Array.isArray(t.filterContracts)&&t.filterContracts.forEach((n,s)=>{i.push(...Et(n,`filterContracts.${s}`))}),t.unsupportedInsights!==void 0&&(Array.isArray(t.unsupportedInsights)?t.unsupportedInsights.forEach((n,s)=>{i.push(...Wt(n,`unsupportedInsights.${s}`))}):i.push("unsupportedInsights must be an array.")),i.push(..._t(t)),{ok:i.length===0,issues:i}}function _t(e){const i=Array.isArray(e.unsupportedInsights)&&e.unsupportedInsights.some(l=>{var d;return Oe.has((d=c(l))==null?void 0:d.reason)}),t=Array.isArray(e.views)&&e.views.some(l=>{var u;const d=c((u=c(l))==null?void 0:u.computation);return(d==null?void 0:d.kind)==="unsupported"&&Oe.has(d.reason)});if(!i&&!t)return[];const n=[],s=c(e.validation);(s==null?void 0:s.status)!=="blocked"&&n.push("validation.status must be blocked when semantic model repair gaps are present.");const r=c(e.nextRequiredTool);return(r==null?void 0:r.name)!=="semaphor_propose_semantic_model_change"&&n.push("nextRequiredTool.name must be semaphor_propose_semantic_model_change when semantic model repair gaps are present."),n}const Oe=new Set(["missing_relationship","raw_identifier_filter_options"]);function O(e,i){const t=c(e);return t?t.kind==="semantic"?typeof t.domainId=="string"&&t.domainId.trim()&&typeof t.datasetName=="string"&&t.datasetName.trim()?[]:[`${i} must include sourceKey or a supported source identity.`]:typeof t.sourceKey=="string"&&t.sourceKey.trim()?[]:t.kind==="physical"&&typeof t.tableName=="string"&&t.tableName.trim()&&typeof t.connectionId=="string"&&t.connectionId.trim()?[]:t.kind==="sql"&&typeof t.connectionId=="string"&&t.connectionId.trim()?[]:[`${i} must include sourceKey or a supported source identity.`]:[`${i} must be an object.`]}function vt(e){const i=c(e);if(!i)return["implementationChecklist must be an object."];const t=[],n=["requiredDevtools","requiredInputOptions","filterScopeByInput","bindingsByView","validationCommands","browserSmokeChecks"];for(const r of n)r in i||t.push(`implementationChecklist.${r} is required.`);const s=c(i.requiredDevtools);return s?typeof s.mountRootDevtools!="boolean"&&t.push("implementationChecklist.requiredDevtools.mountRootDevtools must be a boolean."):t.push("implementationChecklist.requiredDevtools must be an object."),Array.isArray(i.requiredInputOptions)||t.push("implementationChecklist.requiredInputOptions must be an array."),Array.isArray(i.filterScopeByInput)||t.push("implementationChecklist.filterScopeByInput must be an array."),c(i.bindingsByView)||t.push("implementationChecklist.bindingsByView must be an object."),z(i.validationCommands)||t.push("implementationChecklist.validationCommands must be an array of strings."),z(i.browserSmokeChecks)||t.push("implementationChecklist.browserSmokeChecks must be an array of strings."),t}function zt(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];return(typeof t.id!="string"||!t.id.trim())&&n.push(`${i}.id is required.`),t.fieldRef&&n.push(...h(t.fieldRef,`${i}.fieldRef`)),n.push(...ci(t.optionQuery,`${i}.optionQuery`)),z(t.appliesToViewIds)||n.push(`${i}.appliesToViewIds must be an array of strings.`),t.bindings!==void 0&&!Array.isArray(t.bindings)&&n.push(`${i}.bindings must be an array.`),Array.isArray(t.bindings)&&t.bindings.forEach((s,r)=>{const l=c(s);if(!l){n.push(`${i}.bindings.${r} must be an object.`);return}z(l.appliesToViewIds)||n.push(`${i}.bindings.${r}.appliesToViewIds must be an array of strings.`),n.push(...h(l.fieldRef,`${i}.bindings.${r}.fieldRef`))}),n}function St(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];if((typeof t.id!="string"||!t.id.trim())&&n.push(`${i}.id is required.`),t.visualSpec!==void 0&&n.push(...Ht(t.visualSpec,`${i}.visualSpec`)),t.computation!==void 0&&n.push(...Xt(t.computation,`${i}.computation`)),Lt(t))return n.push(...de(t,`${i}`)),t.fields!==void 0&&(Array.isArray(t.fields)?t.fields.forEach((u,p)=>{n.push(...h(u,`${i}.fields.${p}`))}):n.push(`${i}.fields must be an array.`)),t.queryKind!==void 0&&n.push(`${i}.queryKind is not allowed for non-executable views.`),t.sdkBuilder!==void 0&&n.push(`${i}.sdkBuilder is not allowed for non-executable views.`),t.sdkSpec!==void 0&&n.push(`${i}.sdkSpec is not allowed for non-executable views.`),n;if(!Array.isArray(t.fields))return n.push(`${i}.fields must be an array.`),(t.sdkSpec!==void 0||t.sdkBuilder!==void 0)&&n.push(`${i}.fields must be an array for executable views.`),n.push(...de(t,`${i}`)),n;t.fields.forEach((u,p)=>{n.push(...h(u,`${i}.fields.${p}`))}),F(t.queryKind)||n.push(`${i}.queryKind must be a supported codegen query kind.`),t.sdkBuilder!==void 0&&!fi(t.sdkBuilder)&&n.push(`${i}.sdkBuilder must be a supported SDK builder.`),t.metricBindingKeys!==void 0&&(Array.isArray(t.metricBindingKeys)?t.metricBindingKeys.some(u=>typeof u!="string"||u.trim().length===0)&&n.push(`${i}.metricBindingKeys must be an array of strings.`):n.push(`${i}.metricBindingKeys must be an array of strings.`));const s=c(t.sdkSpec),r=(s==null?void 0:s.builder)==="semaphor.metric";r&&(!Array.isArray(t.metricBindingKeys)||t.metricBindingKeys.length===0)&&n.push(`${i}.metricBindingKeys is required for metric views.`);const l=$t(t);r&&Array.isArray(t.metricBindingKeys)&&l&&JSON.stringify(t.metricBindingKeys)!==JSON.stringify(l)&&n.push(`${i}.metricBindingKeys must match the generated metric field binding keys in order.`);const d=c(t.computation);return(d==null?void 0:d.kind)==="server_query"&&F(t.queryKind)&&F(d.queryKind)&&d.queryKind!==t.queryKind&&n.push(`${i}.computation.queryKind must match queryKind.`),n.push(...Ct({value:t.sdkSpec,path:`${i}.sdkSpec`,queryKind:typeof t.queryKind=="string"?t.queryKind:void 0,sdkBuilder:typeof t.sdkBuilder=="string"?t.sdkBuilder:void 0}),...de(t,`${i}`)),n}function $t(e){const i=c(e.sdkSpec);if((i==null?void 0:i.builder)!=="semaphor.metric")return;const t=c(i.spec);if(!t)return;const s=[t.primaryMeasure,...Array.isArray(t.measures)?t.measures:[]].map(wt).filter(r=>!!r);return Array.from(new Map(s.map(r=>[r.identity,r.bindingKey])).values())}function wt(e){const i=c(e);if(!i||typeof i.name!="string"||!i.name.trim())return;const t=kt(i);return t?{identity:JSON.stringify({source:t,name:i.name,aggregate:ui(i)}),bindingKey:At(i)}:void 0}function kt(e){if(typeof e.sourceKey=="string"&&e.sourceKey.trim())return{sourceKey:e.sourceKey};const i=c(e.source);if(i)return{kind:i.kind,domainId:i.domainId,datasetId:i.datasetId,datasetName:i.datasetName,name:i.name}}function At(e){return typeof e.sourceKey=="string"&&e.sourceKey.trim()?[e.sourceKey,ui(e),e.name].filter(Boolean).join(":"):li(e)}function ui(e){return te(e)}function de(e,i){var p;const t=c((p=c(e.visualSpec))==null?void 0:p.tableBehavior),n=c(e.sdkSpec),s=c(n==null?void 0:n.spec),r=typeof(n==null?void 0:n.builder)=="string"?n.builder:void 0,l=r==="semaphor.records"?c(s==null?void 0:s.totals):void 0,d=[];if(!t)return l&&d.push(`${i}.sdkSpec.spec.totals is only allowed when tableBehavior.totals.mode is server.`),d;const u=c(t.totals);return u?(u.mode==="server"&&(r!=="semaphor.records"&&d.push(`${i}.visualSpec.tableBehavior.totals.mode server is only supported for semaphor.records views.`),!l||l.mode!=="server"?d.push(`${i}.sdkSpec.spec.totals.mode must be server when tableBehavior.totals.mode is server.`):d.push(...It({left:u.measures,right:l.measures,leftPath:`${i}.visualSpec.tableBehavior.totals.measures`,rightPath:`${i}.sdkSpec.spec.totals.measures`}))),u.mode!=="server"&&l&&d.push(`${i}.sdkSpec.spec.totals is only allowed when tableBehavior.totals.mode is server.`),r==="semaphor.sql"&&u.mode!=="none"&&d.push(`${i}.visualSpec.tableBehavior.totals.mode must be none for semaphor.sql views.`),r==="semaphor.sql"&&c(s==null?void 0:s.totals)&&d.push(`${i}.sdkSpec.spec.totals is not supported for semaphor.sql.`),d):(l&&d.push(`${i}.sdkSpec.spec.totals is only allowed when tableBehavior.totals.mode is server.`),d)}function It({left:e,right:i,leftPath:t,rightPath:n}){if(!Array.isArray(e)||!Array.isArray(i))return[`${n} must match ${t}.`];const s=[];return e.length!==i.length?(s.push(`${n} must match ${t}.`),s):(e.forEach((r,l)=>{xt(c(r),c(i[l]))||s.push(`${n}.${l} must match ${t}.${l}.`)}),s)}function xt(e,i){return!e||!i?!1:e.name===i.name&&(e.role||"measure")===(i.role||"measure")&&Pe(e)===Pe(i)&&Rt(e,i)}function Pe(e){return typeof e.aggregate=="string"?e.aggregate.toUpperCase():"SUM"}function Rt(e,i){const t=c(e.source),n=c(i.source);if(Mt(t,n))return!1;const s=Be(e),r=Be(i);if(s.size>0||r.size>0){for(const l of s)if(r.has(l))return!0;return!1}return!t||!n||t.kind!==n.kind?!1:t.kind==="semantic"?t.domainId===n.domainId&&t.datasetName===n.datasetName&&(t.datasetId===void 0||n.datasetId===void 0||t.datasetId===n.datasetId):t.kind==="physical"?t.connectionId===n.connectionId&&t.tableName===n.tableName:t.kind==="sql"?t.connectionId===n.connectionId:!1}function Mt(e,i){if(!e||!i||e.kind!=="semantic"||i.kind!=="semantic")return!1;const t=typeof e.datasetId=="string"?e.datasetId.trim():"",n=typeof i.datasetId=="string"?i.datasetId.trim():"";return!!(t&&n&&t!==n)}function Be(e){const i=typeof e.sourceKey=="string"?e.sourceKey.trim():"";return i?new Set([i]):Tt(c(e.source))}function Tt(e){const i=new Set;if(!e)return i;const t=typeof e.sourceKey=="string"?e.sourceKey.trim():"";if(t&&i.add(t),e.kind==="semantic"){const n=typeof e.domainId=="string"?e.domainId:"",s=typeof e.datasetName=="string"?e.datasetName:"",r=typeof e.datasetId=="string"?e.datasetId:"";n&&r&&i.add(`semantic:${n}:datasetId:${r}`),n&&s&&i.add(`semantic:${n}:datasetName:${s}`)}if(e.kind==="physical"){const n=typeof e.connectionId=="string"?e.connectionId:"",s=typeof e.tableName=="string"?e.tableName:"",r=typeof e.databaseName=="string"?e.databaseName:"",l=typeof e.schemaName=="string"?e.schemaName:"";n&&s&&(i.add(["physical",n,r,l,s].join(":")),i.add(`physical:${n}:${s}`))}if(e.kind==="sql"){const n=typeof e.connectionId=="string"?e.connectionId:"",s=typeof e.dialect=="string"?e.dialect:"",r=typeof e.label=="string"?e.label:"";n&&(i.add(["sql",n,s,r].join(":")),i.add(`sql:${n}`))}return i}function Et(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];if(t.fieldRef&&n.push(...h(t.fieldRef,`${i}.fieldRef`)),(typeof t.inputId!="string"||!t.inputId.trim())&&n.push(`${i}.inputId is required.`),n.push(...ci(t.optionQuery,`${i}.optionQuery`)),z(t.appliesToViewIds)||n.push(`${i}.appliesToViewIds must be an array of strings.`),z(t.notAppliedToViewIds)||n.push(`${i}.notAppliedToViewIds must be an array of strings.`),!Array.isArray(t.bindings))n.push(`${i}.bindings must be an array.`);else{const s=z(t.appliesToViewIds)?new Set(t.appliesToViewIds):void 0,r=z(t.notAppliedToViewIds)?new Set(t.notAppliedToViewIds):void 0;t.bindings.forEach((l,d)=>{const u=c(l);if(!u){n.push(`${i}.bindings.${d} must be an object.`);return}typeof u.viewId!="string"||!u.viewId?n.push(`${i}.bindings.${d}.viewId is required.`):(s&&!s.has(u.viewId)&&n.push(`${i}.bindings.${d}.viewId must be included in appliesToViewIds.`),r!=null&&r.has(u.viewId)&&n.push(`${i}.bindings.${d}.viewId must not be listed in notAppliedToViewIds.`)),n.push(...h(u.fieldRef,`${i}.bindings.${d}.fieldRef`))})}return n}function ci(e,i){if(e===void 0)return[];const t=c(e);if(!t)return[`${i} must be an object.`];const n=[...S(t.valueFieldRef,`${i}.valueFieldRef`),...S(t.labelFieldRef,`${i}.labelFieldRef`),...S(t.filterFieldRef,`${i}.filterFieldRef`)];return t.builder!=="semaphor.inputOptions"&&n.push(`${i}.builder must be semaphor.inputOptions.`),typeof t.sourceKey!="string"&&t.source===void 0&&n.push(`${i} must include source or sourceKey.`),t.source!==void 0&&n.push(...O(t.source,`${i}.source`)),c(t.valueFieldRef)||n.push(`${i}.valueFieldRef is required.`),c(t.labelFieldRef)||n.push(`${i}.labelFieldRef is required.`),t.limit!==void 0&&(typeof t.limit!="number"||!Number.isInteger(t.limit)||t.limit<=0)&&n.push(`${i}.limit must be a positive integer.`),n}function Ct(e){var s;const i=c(e.value);if(!i)return[`${e.path} is required for executable views.`];const t=[];if(!fi(i.builder))return t.push(`${e.path}.builder must be a supported SDK builder.`),t;e.sdkBuilder&&i.builder!==e.sdkBuilder&&t.push(`${e.path}.builder must match sdkBuilder.`),e.queryKind&&F(e.queryKind)&&i.builder!==Vt(e.queryKind)&&t.push(`${e.path}.builder must match queryKind.`);const n=c(i.spec);if(!n)return t.push(`${e.path}.spec must be an object.`),t;switch(i.builder){case"semaphor.metric":t.push(...D(n,di,`${e.path}.spec`),...K(n,e.path),...ue(n.measures,`${e.path}.spec.measures`),...S(n.primaryMeasure,`${e.path}.spec.primaryMeasure`),...S(n.dateField,`${e.path}.spec.dateField`),...ce(n.dimensions,`${e.path}.spec.dimensions`),...pe(n.orderBy,`${e.path}.spec.orderBy`),...V(n.filters,`${e.path}.spec.filters`));break;case"semaphor.analysis":t.push(...D(n,pt,`${e.path}.spec`),...K(n,e.path),...ue(n.measures,`${e.path}.spec.measures`),...S(n.primaryMeasure,`${e.path}.spec.primaryMeasure`),...S(n.dateField,`${e.path}.spec.dateField`),...ce(n.dimensions,`${e.path}.spec.dimensions`),...pe(n.orderBy,`${e.path}.spec.orderBy`),...V(n.filters,`${e.path}.spec.filters`),...Dt(n,`${e.path}.spec`));break;case"semaphor.records":t.push(...D(n,mt,`${e.path}.spec`),...K(n,e.path),...ue(n.fields,`${e.path}.spec.fields`),...S(n.dateField,`${e.path}.spec.dateField`),...pe(n.orderBy,`${e.path}.spec.orderBy`),...V(n.filters,`${e.path}.spec.filters`),...Ft(n.totals,`${e.path}.spec.totals`));break;case"semaphor.matrix":t.push(...D(n,ft,`${e.path}.spec`),...Nt(n,e.path),...qt(n.rows,`${e.path}.spec.rows`),...Ot(n.columns,`${e.path}.spec.columns`),...Pt(n.values,`${e.path}.spec.values`),...Bt(n.sort,`${e.path}.spec.sort`),...V(n.filters,`${e.path}.spec.filters`),...jt(n.displayLimits,`${e.path}.spec.displayLimits`));break;case"semaphor.sql":t.push(...D(n,gt,`${e.path}.spec`),...K(n,e.path)),((s=c(n.source))==null?void 0:s.kind)!=="sql"&&t.push(`${e.path}.spec.source.kind must be sql.`),(typeof n.sql!="string"||!n.sql.trim())&&t.push(`${e.path}.spec.sql is required.`),t.push(...ce(n.fields,`${e.path}.spec.fields`));break}return t}function jt(e,i){if(e===void 0)return[];const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];n.push(...Ke(t.rows,`${i}.rows`),...Ke(t.columns,`${i}.columns`));for(const s of Object.keys(t))s==="rows"||s==="columns"||n.push(`${i}.${s} is not supported.`);return n}function Ke(e,i){if(e===void 0)return[];const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];(typeof t.limit!="number"||!Number.isInteger(t.limit)||t.limit<1)&&n.push(`${i}.limit must be a positive integer.`);for(const s of Object.keys(t))s!=="limit"&&n.push(`${i}.${s} is not supported; matrix display limits are count-only in v1.`);return n}function Dt(e,i){const t=[];if(e.driverMode!==void 0&&!ct.has(e.driverMode)&&t.push(`${i}.driverMode must be a supported analysis driver mode.`),e.includePopulation!==void 0&&typeof e.includePopulation!="boolean"&&t.push(`${i}.includePopulation must be a boolean.`),e.calendarContext!==void 0){const n=c(e.calendarContext);if(!n)t.push(`${i}.calendarContext must be an object.`);else{n.tz!==void 0&&typeof n.tz!="string"&&t.push(`${i}.calendarContext.tz must be a string.`),n.weekStart!==void 0&&(typeof n.weekStart!="number"||!Number.isInteger(n.weekStart)||n.weekStart<0||n.weekStart>6)&&t.push(`${i}.calendarContext.weekStart must be an integer between 0 and 6.`);const s=n.anchor;if(s!==void 0&&s!=="now"){const r=c(s);(!r||typeof r.iso!="string"||!r.iso.trim())&&t.push(`${i}.calendarContext.anchor must be now or { iso }.`)}}}return t}function Ft(e,i){if(e===void 0)return[];const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];return t.mode!=="server"&&n.push(`${i}.mode must be server.`),!Array.isArray(t.measures)||t.measures.length===0?n.push(`${i}.measures must include at least one measure.`):t.measures.forEach((s,r)=>{var l;n.push(...gi(s,`${i}.measures.${r}`)),((l=c(s))==null?void 0:l.role)!=="measure"&&n.push(`${i}.measures.${r}.role must be measure.`)}),n}function D(e,i,t){const n=[];return Object.keys(e).forEach(s=>{i.has(s)||n.push(`${t}.${s} is not supported for this SDK builder.`)}),n}function K(e,i){return c(e.source)?O(e.source,`${i}.spec.source`):[`${i}.spec.source must be an object.`]}function Nt(e,i){const t=c(e.source);if(!t)return[`${i}.spec.source must be an object.`];const n=O(e.source,`${i}.spec.source`);return t.kind!=="semantic"&&t.kind!=="physical"&&n.push(`${i}.spec.source.kind must be semantic or physical.`),n}function ue(e,i){const t=$e(e,i);return Array.isArray(e)&&e.forEach((n,s)=>{t.push(...h(n,`${i}.${s}`))}),t}function ce(e,i){if(e===void 0)return[];if(!Array.isArray(e))return[`${i} must be an array.`];const t=[];return e.forEach((n,s)=>{t.push(...h(n,`${i}.${s}`))}),t}function pe(e,i){if(e===void 0)return[];const t=c(e);return t?[...h(t.field,`${i}.field`),...pi(t.direction,`${i}.direction`)]:[`${i} must be an object.`]}function qt(e,i){const t=$e(e,i);return Array.isArray(e)&&e.forEach((n,s)=>{const r=c(n);if(!r){t.push(`${i}.${s} must be an object.`);return}t.push(...h(r.field,`${i}.${s}.field`))}),t}function Ot(e,i){if(e===void 0)return[];const t=[];return Array.isArray(e)?(e.forEach((n,s)=>{const r=c(n);if(!r){t.push(`${i}.${s} must be an object.`);return}t.push(...h(r.field,`${i}.${s}.field`))}),t):[`${i} must be an array.`]}function Pt(e,i){const t=$e(e,i);return Array.isArray(e)&&e.forEach((n,s)=>{const r=c(n);if(!r){t.push(`${i}.${s} must be an object.`);return}t.push(...h(r.field,`${i}.${s}.field`))}),t}function Bt(e,i){if(e===void 0)return[];if(!Array.isArray(e))return[`${i} must be an array.`];const t=[];return e.forEach((n,s)=>{const r=c(n);if(!r){t.push(`${i}.${s} must be an object.`);return}r.axis!=="row"&&r.axis!=="column"&&t.push(`${i}.${s}.axis must be row or column.`),t.push(...pi(r.direction,`${i}.${s}.direction`),...Kt(r.by,`${i}.${s}.by`))}),t}function Kt(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];switch(t.kind){case"member":return[];case"field":return h(t.field,`${i}.field`);case"value":return typeof t.valueId!="string"||!t.valueId.trim()?[`${i}.valueId is required.`]:[];default:return[`${i}.kind must be member, field, or value.`]}}function pi(e,i){return e==="asc"||e==="desc"?[]:[`${i} must be asc or desc.`]}function V(e,i){if(e===void 0)return[];if(!Array.isArray(e))return[`${i} must be an array.`];const t=[];return e.forEach((n,s)=>{const r=c(n);if(!r){t.push(`${i}.${s} must be an object.`);return}t.push(...h(r.field,`${i}.${s}.field`))}),t}function $e(e,i){return!Array.isArray(e)||e.length===0?[`${i} must be a non-empty array.`]:[]}function Vt(e){switch(e){case"metric":return"semaphor.metric";case"records":return"semaphor.records";case"matrix":return"semaphor.matrix";case"analysis":return"semaphor.analysis";case"sql_fallback":return"semaphor.sql"}}function Lt(e){const i=c(e.computation),t=c(e.visualSpec);return(i==null?void 0:i.kind)==="presentation_only"||(i==null?void 0:i.kind)==="derived"||(i==null?void 0:i.kind)==="unsupported"||e.visual==="text_block"||(t==null?void 0:t.visualType)==="text_block"}function Ht(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];return ht.has(t.visualType)||n.push(`${i}.visualType must be a supported visual type.`),t.limit!==void 0&&(typeof t.limit!="number"||!Number.isInteger(t.limit)||t.limit<=0)&&n.push(`${i}.limit must be a positive integer.`),t.tableBehavior!==void 0&&n.push(...Gt(t.tableBehavior,`${i}.tableBehavior`)),n}function Gt(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];return t.tableMode!=="bounded"&&t.tableMode!=="server_paginated"&&t.tableMode!=="server_windowed"&&n.push(`${i}.tableMode must be a supported table mode.`),n.push(...Ut(t.height,`${i}.height`),...Yt(t.pagination,`${i}.pagination`),...Qt(t.sorting,`${i}.sorting`),...Zt(t.totals,`${i}.totals`)),typeof t.serverSideRequired!="boolean"&&n.push(`${i}.serverSideRequired must be a boolean.`),n}function Ut(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];return(typeof t.maxPx!="number"||!Number.isInteger(t.maxPx)||t.maxPx<=0)&&n.push(`${i}.maxPx must be a positive integer.`),t.scroll!=="vertical"&&t.scroll!=="both"&&n.push(`${i}.scroll must be vertical or both.`),typeof t.stickyHeader!="boolean"&&n.push(`${i}.stickyHeader must be a boolean.`),n}function Yt(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];return t.mode!=="none"&&t.mode!=="server"&&t.mode!=="client_for_bounded_rows"&&n.push(`${i}.mode must be a supported pagination mode.`),t.pageSize!==void 0&&(typeof t.pageSize!="number"||!Number.isInteger(t.pageSize)||t.pageSize<=0)&&n.push(`${i}.pageSize must be a positive integer.`),t.readsFrom!==void 0&&t.readsFrom!=="result.pagination"&&n.push(`${i}.readsFrom must be result.pagination.`),n}function Qt(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];return t.mode!=="server"&&t.mode!=="client_for_bounded_rows"&&n.push(`${i}.mode must be a supported sorting mode.`),t.defaultField!==void 0&&(typeof t.defaultField!="string"||!t.defaultField.trim())&&n.push(`${i}.defaultField must be a non-empty string.`),t.defaultDirection!==void 0&&t.defaultDirection!=="asc"&&t.defaultDirection!=="desc"&&n.push(`${i}.defaultDirection must be asc or desc.`),t.resetPageOnChange!==void 0&&typeof t.resetPageOnChange!="boolean"&&n.push(`${i}.resetPageOnChange must be a boolean.`),n}function Zt(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];return t.mode!=="none"&&t.mode!=="server"&&t.mode!=="local"?(n.push(`${i}.mode must be none, server, or local.`),n):t.mode==="none"?(t.measures!==void 0&&n.push(`${i}.measures is not allowed when mode is none.`),t.label!==void 0&&n.push(`${i}.label is not allowed when mode is none.`),n):t.mode==="server"?(!Array.isArray(t.measures)||t.measures.length===0?n.push(`${i}.measures must include at least one measure when mode is server.`):t.measures.forEach((s,r)=>{var l;n.push(...gi(s,`${i}.measures.${r}`)),((l=c(s))==null?void 0:l.role)!=="measure"&&n.push(`${i}.measures.${r}.role must be measure.`)}),t.label!==void 0&&n.push(`${i}.label is not allowed when mode is server.`),n):(t.mode==="local"&&(t.label!=="Displayed rows"&&t.label!=="Current page"&&n.push(`${i}.label must be Displayed rows or Current page when mode is local.`),t.measures!==void 0&&n.push(`${i}.measures is not allowed when mode is local.`)),n)}function Xt(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];switch(t.kind){case"server_query":F(t.queryKind)||n.push(`${i}.queryKind must be a supported codegen query kind.`),t.queryOwnership!==void 0&&t.queryOwnership!=="view_owned"&&t.queryOwnership!=="shared_query"&&n.push(`${i}.queryOwnership must be view_owned or shared_query.`),t.sourceKeys!==void 0&&!z(t.sourceKeys)&&n.push(`${i}.sourceKeys must be an array of strings.`),t.fieldNames!==void 0&&!z(t.fieldNames)&&n.push(`${i}.fieldNames must be an array of strings.`);break;case"derived":(typeof t.upstreamViewId!="string"||!t.upstreamViewId.trim())&&n.push(`${i}.upstreamViewId is required.`),(typeof t.derivation!="string"||!t.derivation.trim())&&n.push(`${i}.derivation is required.`);break;case"presentation_only":break;case"unsupported":(typeof t.reason!="string"||!t.reason.trim())&&n.push(`${i}.reason is required.`),(typeof t.suggestedModelingFix!="string"||!t.suggestedModelingFix.trim())&&n.push(`${i}.suggestedModelingFix is required.`);break;default:n.push(`${i}.kind must be a supported computation kind.`)}return n}function Wt(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];for(const r of["title","requestedQuestion","suggestedModelingFix"])(typeof t[r]!="string"||!t[r].trim())&&n.push(`${i}.${r} is required.`);return yt.has(t.reason)||n.push(`${i}.reason must be a supported unsupported insight reason.`),(t.relationshipCandidate!==void 0||t.nextRepairAction!==void 0)&&t.reason!=="missing_relationship"&&n.push(`${i} relationship repair metadata is only valid for missing_relationship unsupported insights.`),t.diagnostic!==void 0&&n.push(...Jt(t.diagnostic,`${i}.diagnostic`,t.reason)),t.relationshipCandidate!==void 0&&n.push(...ia(t.relationshipCandidate,`${i}.relationshipCandidate`)),t.nextRepairAction!==void 0&&n.push(...ea(t.nextRepairAction,`${i}.nextRepairAction`)),n}function Jt(e,i,t){const n=c(e);if(!n)return[`${i} must be an object.`];const s=[],r=new Set(["kind","inputId","inputLabel","optionSource","optionField","missingEvidence"]);Object.keys(n).forEach(d=>{r.has(d)||s.push(`${i}.${d} is not supported; raw identifier diagnostics support only kind, inputId, inputLabel, optionSource, optionField, and missingEvidence.`)}),t!=="raw_identifier_filter_options"&&s.push(`${i} is only valid for raw_identifier_filter_options unsupported insights.`),n.kind!=="raw_identifier_filter_options"&&s.push(`${i}.kind must be raw_identifier_filter_options.`);for(const d of["inputId","inputLabel"])(typeof n[d]!="string"||!n[d].trim())&&s.push(`${i}.${d} must be a non-empty string.`);s.push(...ge(n.optionSource,`${i}.optionSource`)),s.push(...mi(n.optionField,`${i}.optionField`));const l=new Set(["display_field","relationship_display_path"]);return!Array.isArray(n.missingEvidence)||n.missingEvidence.length===0?s.push(`${i}.missingEvidence must be a non-empty evidence array.`):n.missingEvidence.forEach((d,u)=>{l.has(d)||s.push(`${i}.missingEvidence.${u} must be display_field or relationship_display_path.`)}),s}function ea(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[],s=new Set(["tool","reason"]);return Object.keys(t).forEach(r=>{s.has(r)||n.push(`${i}.${r} is not supported; repair actions support only tool and reason.`)}),t.tool!=="semaphor_propose_semantic_model_change"&&n.push(`${i}.tool must be semaphor_propose_semantic_model_change.`),t.reason!=="missing_relationship"&&n.push(`${i}.reason must be missing_relationship.`),n}function ia(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[],s=new Set(["source","sourceFields","target","targetFields"]);Object.keys(t).forEach(r=>{s.has(r)||n.push(`${i}.${r} is not supported; relationship candidates support only source, sourceFields, target, and targetFields.`)}),n.push(...ge(t.source,`${i}.source`)),n.push(...ge(t.target,`${i}.target`));for(const r of["sourceFields","targetFields"]){const l=t[r];if(!Array.isArray(l)||l.length===0){n.push(`${i}.${r} must be a non-empty endpoint field array.`);continue}l.forEach((d,u)=>{n.push(...mi(d,`${i}.${r}.${u}`))})}return n}function mi(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[],s=new Set(["name","label","role","dataType"]);return Object.keys(t).forEach(r=>{s.has(r)||n.push(`${i}.${r} is not supported; relationship candidate fields are scoped by their endpoint and support only name, label, role, and dataType.`)}),(typeof t.name!="string"||!t.name.trim())&&n.push(`${i}.name must be a non-empty string.`),t.role!==void 0&&(typeof t.role!="string"||!["dimension","measure","date","id","unknown"].includes(t.role))&&n.push(`${i}.role must be dimension, measure, date, id, or unknown.`),t.dataType!==void 0&&(typeof t.dataType!="string"||!["string","number","boolean","date","datetime","unknown"].includes(t.dataType))&&n.push(`${i}.dataType must be string, number, boolean, date, datetime, or unknown.`),n}function ge(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[],s=new Set(["kind","domainId","datasetName","datasetId","label","sourceKey"]);return Object.keys(t).forEach(r=>{s.has(r)||n.push(`${i}.${r} is not supported; relationship candidate sources support only semantic identity fields.`)}),t.kind!=="semantic"&&n.push(`${i} must use semantic source identity.`),(typeof t.domainId!="string"||!t.domainId.trim()||typeof t.datasetName!="string"||!t.datasetName.trim())&&n.push(`${i} must include semantic domainId and datasetName.`),n}function F(e){return lt.has(e)}function fi(e){return dt.has(e)}function S(e,i){return e===void 0?[]:h(e,i)}function h(e,i){const t=c(e);if(!t)return[`${i} must be an object.`];const n=[];return(typeof t.name!="string"||!t.name.trim())&&n.push(`${i}.name is required.`),!t.source&&typeof t.sourceKey!="string"&&n.push(`${i} must include source or sourceKey.`),t.aggregate!==void 0&&!ut.has(t.aggregate)&&n.push(`${i}.aggregate must be a supported aggregate function.`),n}function gi(e,i){const t=c(e),n=h(e,i);if(!t||typeof t.sourceKey=="string"&&t.sourceKey.trim())return n;if(t.source!==void 0){const r=O(t.source,`${i}.source`);return r.length===0||n.push(...r),n}return n.includes(`${i} must include source or sourceKey.`)||n.push(`${i} must include source or sourceKey.`),n}function c(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function z(e){return Array.isArray(e)&&e.every(i=>typeof i=="string")}const b=a.z.record(a.z.string(),a.z.unknown()),E=a.z.array(b),_=a.z.enum(["SUM","COUNT","AVG","MIN","MAX","MEDIAN","DISTINCT"]),ae=a.z.enum(["postgres","mysql","mssql","snowflake","clickhouse","bigquery","redshift","duckdb","sqlite","unknown"]),hi=a.z.enum(T),yi=a.z.enum(ie),ne=a.z.enum(["dimension","measure","date","id","unknown"]),se=a.z.enum(["string","number","boolean","date","datetime","unknown"]),G=a.z.union([a.z.number(),a.z.string(),a.z.null()]),me=a.z.enum(["millisecond","second","minute","hour","day"]),ta=a.z.enum(ai),aa=a.z.discriminatedUnion("mode",[a.z.object({mode:a.z.literal("auto")}).strict(),a.z.object({mode:a.z.literal("preset"),preset:ta}).strict(),a.z.object({mode:a.z.literal("pattern"),pattern:a.z.string().min(1)}).strict()]),Q=a.z.object({type:a.z.literal("temporal_bucket"),presentation:aa}).strict(),na=a.z.object({tz:a.z.string().min(1).refine(si,{message:"tz must be a valid IANA timezone"}),weekStart:a.z.number().int().min(0).max(6),fiscalCalendar:a.z.object({kind:a.z.literal("month_aligned"),yearStartMonth:a.z.number().int().min(1).max(12)}).strict().optional()}).strict(),Z=a.z.object({kind:a.z.literal("temporal_bucket"),granularity:hi,calendar:na}).strict(),bi=a.z.object({kind:a.z.literal("raw_temporal"),valueKind:a.z.enum(["date","wall_datetime","instant"])}).strict(),_i=a.z.union([a.z.object({type:a.z.enum(["number","currency","percent","percentage","scientific"]),locale:a.z.string().optional(),minimumFractionDigits:a.z.number().optional(),maximumFractionDigits:a.z.number().optional(),useGrouping:a.z.boolean().optional(),prefix:a.z.string().optional(),suffix:a.z.string().optional(),negativeStyle:a.z.enum(["minus","parentheses"]).optional(),compact:a.z.boolean().optional(),scale:a.z.number().optional(),currency:a.z.string().optional(),percentValueMode:a.z.enum(["fraction","whole"]).optional()}).passthrough().superRefine((e,i)=>{"locale"in e&&i.addIssue({code:a.z.ZodIssueCode.custom,path:["locale"],message:"Numeric semantic formats inherit locale from viewer preferences."})}),a.z.object({type:a.z.enum(["date","datetime"]),locale:a.z.string().optional(),pattern:a.z.string().optional(),relative:a.z.boolean().optional(),timezone:a.z.string().optional(),sourceTimezone:a.z.string().optional(),prefix:a.z.string().optional(),suffix:a.z.string().optional()}).passthrough(),a.z.object({type:a.z.literal("duration"),inputUnit:me.optional(),outputStyle:a.z.enum(["compact","digital","long"]).optional(),largestUnit:me.optional(),smallestUnit:me.optional(),maxUnits:a.z.number().optional(),prefix:a.z.string().optional(),suffix:a.z.string().optional(),negativeStyle:a.z.enum(["minus","parentheses"]).optional()}).passthrough(),a.z.object({type:a.z.literal("string"),prefix:a.z.string().optional(),suffix:a.z.string().optional()}).passthrough()]),sa=a.z.union([a.z.object({kind:a.z.literal("defaultAggregate")}).passthrough(),a.z.object({kind:a.z.literal("blank")}).passthrough(),a.z.object({kind:a.z.literal("labelOnly"),label:a.z.string().optional()}).passthrough(),a.z.object({kind:a.z.literal("customAggregate"),aggregate:_}).passthrough(),a.z.object({kind:a.z.literal("percentOfParent")}).passthrough(),a.z.object({kind:a.z.literal("percentOfGrandTotal")}).passthrough(),a.z.object({kind:a.z.literal("customExpression"),expressionId:a.z.string()}).passthrough()]);function P(e,i){return a.z.object(e).passthrough().superRefine((t,n)=>{for(const s of i)Object.prototype.hasOwnProperty.call(t,s)||n.addIssue({code:"custom",path:[s],message:`Required field "${s}" is missing.`})})}const we=a.z.object({kind:a.z.literal("semantic"),domainId:a.z.string(),datasetName:a.z.string(),datasetId:a.z.string().optional(),label:a.z.string().optional(),connectionId:a.z.string().optional()}).passthrough(),vi=a.z.object({kind:a.z.literal("physical"),connectionId:a.z.string(),connectionType:a.z.string().optional(),tableName:a.z.string(),databaseName:a.z.string().optional(),schemaName:a.z.string().optional(),label:a.z.string().optional(),dialect:ae.optional()}).passthrough(),zi=a.z.object({kind:a.z.literal("sql"),connectionId:a.z.string(),dialect:ae.optional(),label:a.z.string().optional()}).passthrough(),x=a.z.union([we,vi,zi]),w=a.z.object({name:a.z.string(),label:a.z.string().optional(),role:ne.optional(),dataType:se.optional(),source:x.optional(),aggregate:_.optional()}).passthrough(),oa=a.z.object({kind:a.z.literal("field"),field:w,aggregate:_.optional()}).passthrough(),ke=a.z.object({kind:a.z.literal("derived_field"),name:a.z.string(),label:a.z.string(),description:a.z.string().optional(),resultRole:ne,dataType:se,computeStage:a.z.enum(["row","aggregate"]),expression:a.z.string(),expressionLanguage:a.z.literal("semaphor_sql_template").optional(),inputs:a.z.record(oa),defaultAggregate:_.optional(),aggregationBehavior:a.z.enum(["additive","non_additive","ratio_of_sums","weighted","pre_aggregated","snapshot"]).optional(),aggregationStrategy:a.z.enum(["default","symmetric_aggregate","aggregate_then_join","weighted"]).optional(),format:_i.optional(),tags:a.z.array(a.z.string()).optional()}).passthrough(),oe=w.and(a.z.object({derivedField:ke.optional()}).passthrough()),ra=we,la=a.z.object({kind:a.z.literal("physical"),connectionId:a.z.string().optional(),connectionType:a.z.string().optional(),tableName:a.z.string(),databaseName:a.z.string().optional(),schemaName:a.z.string().optional(),label:a.z.string().optional(),dialect:ae.optional()}).passthrough(),da=a.z.object({kind:a.z.literal("sql"),connectionId:a.z.string().optional(),dialect:ae.optional(),label:a.z.string().optional()}).passthrough(),ua=a.z.union([ra,la,da]),ca=a.z.object({key:a.z.string().optional(),name:a.z.string(),label:a.z.string().optional(),role:ne.optional(),dataType:se.optional(),source:ua.optional(),aggregate:_.optional(),derivedField:a.z.never().optional()}).passthrough(),R=a.z.object({key:a.z.string(),name:a.z.string(),label:a.z.string(),role:ne.optional(),dataType:se.optional(),aggregate:_.optional(),source:x.optional(),derivedField:ke.optional(),temporalBucket:Z.optional(),rawTemporal:bi.optional(),pivotIdentity:a.z.object({metricId:a.z.string().min(1),metricAlias:a.z.string().min(1),members:a.z.array(a.z.object({fieldId:a.z.string().min(1),value:a.z.string().nullable(),temporalBucket:Z.optional()}).strict())}).strict().optional()}).passthrough().superRefine((e,i)=>{if(e.temporalBucket&&e.rawTemporal&&i.addIssue({code:a.z.ZodIssueCode.custom,path:["rawTemporal"],message:"A result column cannot carry both temporalBucket and rawTemporal metadata."}),e.temporalBucket){const t=ni(e.temporalBucket.granularity);e.dataType!==t&&i.addIssue({code:a.z.ZodIssueCode.custom,path:["dataType"],message:`${e.temporalBucket.granularity} temporal buckets require dataType ${t}.`})}if(e.rawTemporal){const t=e.rawTemporal.valueKind==="date"?"date":"datetime";e.dataType!==t&&i.addIssue({code:a.z.ZodIssueCode.custom,path:["dataType"],message:`${e.rawTemporal.valueKind} raw temporal values require dataType ${t}.`})}}),pa=a.z.object({records:E,columns:a.z.array(R).optional()}).passthrough(),ma=a.z.object({records:E,columns:a.z.array(R)}).passthrough(),Si=a.z.object({code:a.z.string(),message:a.z.string().optional(),invalidField:a.z.string().optional(),fieldRole:a.z.enum(["measure","date","dimension","input","source","sql"]).optional(),validMeasureCandidates:a.z.array(a.z.string()).optional(),validDateCandidates:a.z.array(a.z.string()).optional(),validDimensionCandidates:a.z.array(a.z.string()).optional(),recommendedNextStep:a.z.string()}).passthrough(),X=a.z.object({code:a.z.string(),message:a.z.string(),path:a.z.string().optional(),fieldRole:a.z.enum(["measure","date","dimension","input","source","sql"]).optional(),repairHint:Si.optional()}).passthrough(),Ae=a.z.object({ok:a.z.boolean(),errors:a.z.array(X),warnings:a.z.array(X),repairHints:a.z.array(Si)}).passthrough(),fa=a.z.object({page:a.z.number(),pageSize:a.z.number(),pageCount:a.z.number(),totalCount:a.z.number(),hasNextPage:a.z.boolean(),hasPrevPage:a.z.boolean()}).passthrough(),B={intentId:a.z.string().optional(),queryPath:a.z.enum(["query_spec","sql","sql_python"]),warnings:a.z.array(a.z.string()).optional(),rowCount:a.z.number().optional(),rowLimitExceeded:a.z.boolean().optional(),limit:a.z.number().optional(),pagination:fa.optional()},$i=a.z.object({...B,kind:a.z.literal("metric"),primaryValue:G,measures:a.z.record(G).optional(),missingMeasures:a.z.array(a.z.string()).optional(),comparison:a.z.object({kind:a.z.enum(["previous_period","previous_year","target"]),value:G.optional(),delta:a.z.union([a.z.number(),a.z.null()]).optional(),deltaPercent:a.z.union([a.z.number(),a.z.null()]).optional()}).passthrough().optional(),records:E.optional()}).passthrough(),wi=a.z.object({...B,kind:a.z.literal("records"),columns:a.z.array(R),records:E,totals:a.z.object({mode:a.z.literal("server"),scope:a.z.literal("filtered_result"),row:a.z.record(a.z.string(),a.z.unknown()),columns:a.z.array(R).optional()}).passthrough().optional()}).passthrough(),ki=a.z.object({...B,kind:a.z.literal("inputOptions"),options:a.z.array(P({label:a.z.string(),value:a.z.unknown(),count:a.z.number().optional(),disambiguation:a.z.array(a.z.string()).optional()},["value"]))}).passthrough(),Ai=a.z.object({...B,kind:a.z.literal("sql"),columns:a.z.array(R),records:E,sqlShape:a.z.object({statementType:a.z.string().optional(),explicitLimit:a.z.number().optional(),hasPythonCode:a.z.boolean().optional()}).passthrough().optional()}).passthrough(),ga=a.z.object({enabled:a.z.boolean().optional(),position:a.z.enum(["before","after"]).optional(),label:a.z.string().optional()}).passthrough(),Ve=a.z.object({id:a.z.enum(["rows","columns"]),levels:a.z.array(a.z.object({instanceId:a.z.string(),fieldKey:a.z.string(),label:a.z.string(),field:w,grain:yi.optional(),temporalBucket:Z.optional(),subtotal:ga.optional()}).passthrough()),nodeIds:a.z.array(a.z.string())}).passthrough(),M=P({instanceId:a.z.string(),fieldKey:a.z.string(),value:a.z.unknown(),label:a.z.string().optional()},["value"]),ha=a.z.union([a.z.object({kind:a.z.literal("member")}).passthrough(),a.z.object({kind:a.z.literal("field"),field:w,aggregate:_.optional()}).passthrough(),a.z.object({kind:a.z.literal("value"),valueId:a.z.string(),rowPath:a.z.array(M).optional(),columnPath:a.z.array(M).optional()}).passthrough()]),ya=a.z.enum(["present","presentNull","missing","densified"]),ba=a.z.enum(["value","rowSubtotal","columnSubtotal","subtotalIntersection","rowGrandTotal","columnGrandTotal","matrixGrandTotal"]),_a=a.z.object({instanceId:a.z.string(),fieldKey:a.z.string(),field:w,role:a.z.enum(["row","column","measure","sort","filter"]),label:a.z.string().optional()}).passthrough(),va=a.z.union([a.z.object({kind:a.z.literal("additive"),aggregate:_.optional()}).passthrough(),a.z.object({kind:a.z.literal("semiAdditive"),aggregate:_.optional(),grain:yi.optional()}).passthrough(),a.z.object({kind:a.z.literal("nonAdditive"),aggregate:_.optional()}).passthrough(),a.z.object({kind:a.z.literal("ratio"),numeratorMeasureInstanceId:a.z.string().optional(),denominatorMeasureInstanceId:a.z.string().optional()}).passthrough(),a.z.object({kind:a.z.literal("custom"),expressionId:a.z.string().optional()}).passthrough()]),za=a.z.object({instanceId:a.z.string(),fieldKey:a.z.string(),label:a.z.string(),field:w,aggregate:_.optional(),format:_i.optional(),totalBehavior:sa.optional(),semantics:va}).passthrough(),Sa=a.z.object({id:a.z.string(),measureId:a.z.string(),aggregate:_.optional(),label:a.z.string().optional(),source:a.z.enum(["measureDefault","rowSubtotal","columnSubtotal","subtotalIntersection","rowGrandTotal","columnGrandTotal","matrixGrandTotal","custom"]),scope:a.z.object({rowLevelId:a.z.string().optional(),columnLevelId:a.z.string().optional(),rowNodeId:a.z.string().optional(),columnNodeId:a.z.string().optional()}).passthrough().optional()}).passthrough(),$a=a.z.object({kind:a.z.string(),label:a.z.string().optional(),payload:a.z.record(a.z.string(),a.z.unknown()).optional()}).passthrough(),wa=P({id:a.z.string(),axis:a.z.enum(["row","column"]),path:a.z.array(M),level:a.z.number(),label:a.z.string().optional(),value:a.z.unknown(),parentId:a.z.string().optional(),hasChildren:a.z.boolean(),isExpanded:a.z.boolean().optional(),isSubtotal:a.z.boolean().optional(),isGrandTotal:a.z.boolean().optional(),subtotalFunction:_.optional(),childCount:a.z.number().optional(),actions:a.z.array($a).optional()},["value"]),ka=a.z.object({rowHeaderLevels:a.z.array(a.z.object({id:a.z.string(),label:a.z.string(),fieldInstanceId:a.z.string()}).passthrough()),columnHeaderRows:a.z.array(a.z.object({id:a.z.string(),cells:a.z.array(a.z.object({id:a.z.string(),label:a.z.string().optional(),role:a.z.enum(["rowHeader","columnHeader","measureHeader","subtotal","grandTotal"]),colSpan:a.z.number(),rowSpan:a.z.number(),columnPath:a.z.array(M),measureInstanceId:a.z.string().optional()}).passthrough())}).passthrough()),columns:a.z.array(a.z.object({id:a.z.string(),label:a.z.string().optional(),columnNodeId:a.z.string().optional(),columnPath:a.z.array(M),measureInstanceId:a.z.string(),role:a.z.enum(["value","columnSubtotal","columnGrandTotal"])}).passthrough())}).passthrough(),Aa=P({rowId:a.z.string(),columnId:a.z.string().optional(),measureId:a.z.string(),value:a.z.unknown(),presence:ya,role:ba,calculationId:a.z.string().optional()},["value"]).superRefine((e,i)=>{Object.prototype.hasOwnProperty.call(e,"formattedValue")&&i.addIssue({code:"custom",path:["formattedValue"],message:"Matrix result cells carry typed values; formattedValue is not supported."})}),Ia=a.z.object({rows:a.z.boolean().optional(),columns:a.z.boolean().optional(),grandTotal:a.z.union([a.z.boolean(),a.z.object({rows:a.z.boolean().optional(),columns:a.z.boolean().optional()}).passthrough()]).optional()}).passthrough(),xa=P({id:a.z.string(),axis:a.z.enum(["row","column"]),targetInstanceId:a.z.string().optional(),direction:a.z.enum(["asc","desc"]),nulls:a.z.enum(["warehouseDefault","first","last"]).optional(),scope:a.z.enum(["global","withinParent"]).optional(),by:ha},["by"]),Ra=a.z.object({rowOffset:a.z.number().optional(),rowLimit:a.z.number().optional(),columnOffset:a.z.number().optional(),columnLimit:a.z.number().optional(),hasMoreRows:a.z.boolean().optional(),hasMoreColumns:a.z.boolean().optional()}).passthrough(),Ma=a.z.object({axis:a.z.enum(["row","column"]),path:a.z.array(M),depth:a.z.number().optional()}).passthrough(),Ta=a.z.object({rowLazyLoading:a.z.boolean().optional(),columnLazyLoading:a.z.boolean().optional(),expandableRowNodeIds:a.z.array(a.z.string()).optional(),expandableColumnNodeIds:a.z.array(a.z.string()).optional(),nextRequests:a.z.array(Ma).optional()}).passthrough(),Ea=a.z.object({domains:a.z.record(a.z.object({min:a.z.number().optional(),max:a.z.number().optional()}).passthrough()).optional(),rules:a.z.array(a.z.record(a.z.string(),a.z.unknown())).optional()}).passthrough(),Ii=a.z.object({...B,kind:a.z.literal("matrix"),schemaVersion:a.z.literal(2),shape:a.z.enum(["hierarchical","pivot"]),capabilities:a.z.array(a.z.string()),executionMetadata:a.z.record(a.z.string(),a.z.unknown()),fieldsById:a.z.record(a.z.string(),_a),measuresById:a.z.record(a.z.string(),za),calculationsById:a.z.record(a.z.string(),Sa).optional(),axes:a.z.object({rows:Ve,columns:Ve}).passthrough(),nodesById:a.z.record(a.z.string(),wa),layout:ka,cells:a.z.array(Aa),totals:Ia,sort:a.z.array(xa),formattingContext:Ea,pageInfo:Ra.optional(),expansion:Ta.optional()}).passthrough(),xi=a.z.union([$i,wi,ki,Ai,Ii]),Ri=a.z.object({status:a.z.enum(["not_required","resolved","missing","ambiguous","fanout_risk","unknown"]),requiredSources:a.z.array(x).optional(),relationshipsUsed:a.z.array(a.z.string()).optional(),missingSources:a.z.array(a.z.string()).optional(),warnings:a.z.array(a.z.string()).optional(),message:a.z.string().optional(),recommendedNextStep:a.z.string().optional(),joinPlanSummary:a.z.object({baseSource:x.optional(),joinedSources:a.z.array(x).optional(),joinCount:a.z.number().optional()}).passthrough().optional(),fanoutRisk:a.z.object({status:a.z.enum(["none","warning","error","unknown"]),message:a.z.string().optional()}).passthrough().optional()}).passthrough(),Le=a.z.enum(["ambiguous_fields","empty_result","missing_grounded_fields","missing_relationship","no_grounded_query","partial_result","presentation_incomplete","query_validation_failed","unsafe_join"]),Ie=a.z.object({version:a.z.literal(1),status:a.z.enum(["answered","partial","blocked"]),summary:a.z.string(),answered:a.z.array(a.z.object({slotId:a.z.string().optional(),queryId:a.z.string().optional(),summary:a.z.string(),evidenceIds:a.z.array(a.z.string()).optional(),fieldsUsed:a.z.array(oe).optional()}).passthrough()),blocked:a.z.array(a.z.object({slotId:a.z.string().optional(),queryId:a.z.string().optional(),reasonCode:Le,message:a.z.string(),missingFields:a.z.array(a.z.string()).optional(),availableFields:a.z.array(a.z.string()).optional(),ambiguousFields:a.z.array(a.z.string()).optional(),missingRelationships:a.z.array(a.z.string()).optional(),evidenceIds:a.z.array(a.z.string()).optional(),neededFromUser:a.z.array(a.z.string()).optional(),recommendedNextStep:a.z.string().optional()}).passthrough()),semanticModelRecommendations:a.z.array(a.z.object({reasonCode:Le,message:a.z.string(),recommendedNextStep:a.z.string().optional()}).passthrough()).optional()}).passthrough(),xe=a.z.object({scope:a.z.literal("filtered_query"),measures:a.z.record(G)}).passthrough(),Re=a.z.object({answeredObligations:a.z.array(a.z.string()),missingObligations:a.z.array(a.z.string()),warnings:a.z.array(X).optional()}).passthrough(),Mi=a.z.object({intentId:a.z.string().optional(),queryId:a.z.string().optional(),status:a.z.enum(["answered","partial","failed"]),resultShape:a.z.enum(["metric","records","inputOptions","sql","matrix","period_change","analysis"]).optional(),intent:a.z.unknown().optional(),compiledQuery:a.z.unknown().optional(),fieldsUsed:a.z.array(oe).optional(),result:xi.optional(),validation:Ae,coverage:Re.optional(),missingFields:a.z.array(a.z.string()).optional(),warnings:a.z.array(a.z.string()).optional(),relationshipDiagnostics:Ri.optional(),diagnosticFeedback:Ie.optional(),population:xe.optional(),metadata:a.z.record(a.z.string(),a.z.unknown()).optional()}).passthrough();function Ca(e){switch(e){case"boolean":return a.z.boolean().optional();case"compactExecutionFieldArray":return a.z.array(ca).optional();case"coverage":return Re.optional();case"diagnosticFeedback":return Ie.optional();case"executionFieldArray":return a.z.array(oe).optional();case"executionResult":return Mi.optional();case"number":return a.z.number().finite().optional();case"population":return xe.optional();case"record":return b.optional();case"recordArray":return E.optional();case"responseDetail":return a.z.enum(["compact","standard","debug"]).optional();case"string":return a.z.string().optional();case"stringArray":return a.z.array(a.z.string()).optional();case"unknown":return a.z.unknown().optional();case"unknownArray":return a.z.array(a.z.unknown()).optional();case"validationResult":return Ae.optional()}}const Ti=Object.fromEntries(Object.entries(oi).map(([e,i])=>[e,Ca(i)])),ja=a.z.object(Ti).strict(),Me=a.z.object({sourceKey:a.z.string().optional(),kind:a.z.enum(["semantic","physical","sql"]).optional(),domainId:a.z.string().optional(),datasetName:a.z.string().optional(),datasetId:a.z.string().optional(),connectionId:a.z.string().optional(),tableName:a.z.string().optional(),label:a.z.string().optional()}).passthrough(),$=a.z.object({name:a.z.string(),label:a.z.string().optional(),role:a.z.enum(["dimension","measure","date","id","unknown"]).optional(),dataType:a.z.enum(["string","number","boolean","date","datetime","unknown"]).optional(),aggregate:_.optional(),sourceKey:a.z.string().optional(),source:Me.optional()}).passthrough(),Ei=a.z.object({id:a.z.string().optional(),builder:a.z.literal("semaphor.inputOptions"),source:Me.optional(),sourceKey:a.z.string().optional(),valueFieldRef:$,labelFieldRef:$,filterFieldRef:$.optional(),population:a.z.unknown().optional(),dependencies:a.z.unknown().optional(),limit:a.z.number().int().positive().optional(),spec:b.optional()}).passthrough(),Ci=a.z.object({appliesToViewIds:a.z.array(a.z.string()).optional(),viewId:a.z.string().optional(),fieldRef:$,relationshipHint:a.z.unknown().optional(),relationshipsUsed:a.z.array(b).optional()}).passthrough(),Da=a.z.object({id:a.z.string(),label:a.z.string().optional(),type:a.z.string().optional(),serverSide:a.z.boolean().optional(),fieldRef:$.optional(),optionQuery:Ei.optional(),bindings:a.z.array(Ci).optional(),appliesToViewIds:a.z.array(a.z.string()),relationshipHint:a.z.unknown().optional(),relationshipsUsed:a.z.array(b).optional()}).passthrough(),Fa=a.z.object({builder:a.z.enum(["semaphor.metric","semaphor.records","semaphor.matrix","semaphor.analysis","semaphor.sql"]),spec:b,fallbackReason:b.optional()}).passthrough(),Na=a.z.object({id:a.z.string(),title:a.z.string().optional(),purpose:a.z.string().optional(),sourcePresentation:a.z.object({sourceKeys:a.z.array(a.z.string()).optional(),sourceLabels:a.z.array(a.z.string()).optional()}).passthrough().optional(),visual:a.z.string().optional(),visualSpec:b.optional(),queryKind:a.z.enum(["metric","records","matrix","analysis","sql_fallback"]).optional(),sdkBuilder:a.z.enum(["semaphor.metric","semaphor.records","semaphor.matrix","semaphor.analysis","semaphor.sql"]).optional(),sdkSpec:Fa.optional(),fields:a.z.array($).optional(),computation:b.optional(),uxExpectations:a.z.array(a.z.string()).optional(),validation:b.optional()}).passthrough(),qa=a.z.object({inputId:a.z.string(),label:a.z.string().optional(),type:a.z.string().optional(),serverSide:a.z.boolean().optional(),fieldRef:$.optional(),optionQuery:Ei.optional(),bindings:a.z.array(Ci),appliesToViewIds:a.z.array(a.z.string()),notAppliedToViewIds:a.z.array(a.z.string())}).passthrough(),Oa=a.z.object({schemaVersion:a.z.literal(Y),title:a.z.string(),purpose:a.z.string().optional(),userGoal:a.z.string().optional(),nextStep:a.z.string().optional(),sources:a.z.array(Me),inputs:a.z.array(Da),views:a.z.array(Na),filterContracts:a.z.array(qa),implementationChecklist:a.z.object({schemaVersion:a.z.string().optional(),requiredDevtools:a.z.object({mountRootDevtools:a.z.boolean(),providerDebugBridge:a.z.string().optional(),panelPosition:a.z.string().optional(),forbidden:a.z.array(a.z.string()).optional()}).passthrough(),requiredInputOptions:a.z.array(b),filterScopeByInput:a.z.array(b),bindingsByView:a.z.record(a.z.string(),a.z.array(b)),validationCommands:a.z.array(a.z.string()),browserSmokeChecks:a.z.array(a.z.string())}).passthrough(),nextRequiredTool:a.z.object({name:a.z.string(),reason:a.z.string().optional()}).optional(),unsupportedInsights:a.z.array(a.z.object({title:a.z.string(),requestedQuestion:a.z.string(),reason:a.z.string(),suggestedModelingFix:a.z.string()}).passthrough()).optional(),assumptions:a.z.array(a.z.string()).optional(),validation:b.optional()}).passthrough().superRefine((e,i)=>{const t=Se(e);for(const n of t.issues)i.addIssue({code:a.z.ZodIssueCode.custom,message:n})});function re(e){return typeof e=="string"?e.trim().toLowerCase():""}function ji(e){return String(e.column_name||e.name||e.qualifiedFieldName||"")}function Di(e){return Array.from(new Set([e.column_name,e.name,e.qualifiedFieldName,e.alias].filter(i=>typeof i=="string"&&i.trim().length>0).map(i=>i.trim())))}function le(e){const i=Pa(e);return i?i.includes("int")||i.includes("uint")||i.includes("bigint")||i.includes("smallint")||i.includes("tinyint")||i.includes("numeric")||i.includes("decimal")||i.includes("double")||i.includes("float")||i.includes("number")||i.includes("real")||i.includes("money")||i.includes("currency")||i.includes("percent")?"number":i.includes("timestamp")||i.includes("datetime")||i.startsWith("time")?"datetime":i.includes("date")?"date":i.includes("bool")?"boolean":"string":"unknown"}function Pa(e){let i=re(e),t="";for(;i&&i!==t;)t=i,i=He(i,"nullable"),i=He(i,"lowcardinality");return i}function He(e,i){const t=`${i}(`;return!e.startsWith(t)||!e.endsWith(")")?e:e.slice(t.length,-1).trim()}function Fi(e){const i=le(e);return i==="date"||i==="datetime"}function Te(e){return Fi(e.dataType||e.data_type)}function Ee(e){const i=Ni(e);return i==="id"||i==="row_id"}function he(e){const i=Ni(e);return Ee(e)||i.endsWith("_id")||i.endsWith("_key")||i.endsWith("_number")}function Ni(e){return re(ji(e)||e.name||e.alias).replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")}function Ce(e,i={}){const t=re(e.role);return t==="metric"||t==="measure"?!i.excludeIdentifiers||!he(e):t==="groupby"||t==="dimension"||t==="date"||t==="id"?!1:le(e.dataType||e.data_type)==="number"&&(!i.excludeIdentifiers||!he(e))}function Ba(e){return!Ce(e)&&!Te(e)}function Ka(e){const i=new Set,t=new Set,n=new Set;for(const s of e){if(Ee(s))continue;const r=Di(s);if(r.length!==0){if(Te(s)){r.forEach(l=>t.add(l));continue}if(Ce(s,{excludeIdentifiers:!0})){r.forEach(l=>i.add(l));continue}r.forEach(l=>n.add(l))}}return{validMeasureCandidates:Array.from(i).sort(),validDateCandidates:Array.from(t).sort(),validDimensionCandidates:Array.from(n).sort()}}const qi=["YYYY","MMMM","MMM","YY","MM","DD","HH","mm","ss"],Va=new Set([" ","-","/",":",".",",","T"]),Oi={week_of_short:"week",week_of_long:"week",quarter_short:"quarter",quarter_long:"quarter",fiscal_quarter_short:"quarter",fiscal_year:"year"};function La(e){return typeof e=="string"&&Object.prototype.hasOwnProperty.call(Oi,e)}function Ha(e,i){return qi.find(t=>e.startsWith(t,i))}function Pi(e){var s;if(!e||e.trim()!==e)return{ok:!1,code:"invalid_temporal_bucket_pattern",message:"Temporal bucket patterns must be non-empty and trimmed."};const i=[];let t=0,n=!1;for(;t<e.length;){const r=Ha(e,t);if(r){if(n)return{ok:!1,code:"invalid_temporal_bucket_pattern",message:"Adjacent temporal bucket tokens require a separator."};i.push({kind:"token",value:r}),t+=r.length,n=!0;continue}const l=e[t];if(!Va.has(l))return{ok:!1,code:"invalid_temporal_bucket_pattern",message:`Unsupported temporal bucket pattern character "${l}".`};if(i.length===0)return{ok:!1,code:"invalid_temporal_bucket_pattern",message:"Temporal bucket patterns cannot begin with a separator."};const d=i[i.length-1];d.kind==="literal"?d.value+=l:i.push({kind:"literal",value:l}),t+=1,n=!1}return((s=i[i.length-1])==null?void 0:s.kind)!=="token"?{ok:!1,code:"invalid_temporal_bucket_pattern",message:"Temporal bucket patterns cannot end with a separator."}:{ok:!0,segments:i}}function Ga(e){return e.flatMap(i=>i.kind==="token"?[i.value]:[])}function Ge(e,i){return e.filter(t=>i.includes(t)).length===1}function L(e,i){return e.some(t=>i.includes(t))}function Ua(e){return new Set(e).size!==e.length}function Ya(e,i){if(Ua(e))return!1;const t=["YYYY","YY"],n=["MMMM","MMM","MM"],s=["HH","mm","ss"],r=Ge(e,t),l=Ge(e,n),d=e.includes("DD"),u=L(e,s);switch(i){case"second":return e.includes("HH")&&e.includes("mm")&&e.includes("ss")&&(!L(e,[...t,...n,"DD"])||r&&l&&d);case"minute":return e.includes("HH")&&e.includes("mm")&&(!L(e,[...t,...n,"DD"])||r&&l&&d);case"hour":return e.includes("HH")&&(!L(e,[...t,...n,"DD"])||r&&l&&d);case"day":case"week":return r&&l&&d&&!u;case"month":return r&&l&&!d&&!u;case"quarter":return!1;case"year":return r&&!l&&!d&&!u}}function W(e,i){if(e.presentation.mode==="auto")return{ok:!0};if(e.presentation.mode==="preset"){const n=Oi[e.presentation.preset];return n===i?{ok:!0}:{ok:!1,code:"incompatible_temporal_bucket_preset",message:`Preset ${e.presentation.preset} requires ${n} granularity.`}}const t=Pi(e.presentation.pattern);return t.ok?Ya(Ga(t.segments),i)?{ok:!0,segments:t.segments}:{ok:!1,code:"incompatible_temporal_bucket_pattern",message:`Pattern ${e.presentation.pattern} is not compatible with ${i} granularity.`}:t}function Qa(e,i){if(!(!e||!i))return W(e,i).ok?e:void 0}function o(e,i,t){return t?{code:e,message:i,path:t}:{code:e,message:i}}function Za(e){for(let i=0;i<e.length;i+=1){const t=e[i];if(e.some((n,s)=>s!==i&&Ki(n,t)))return!1}return!0}function Bi(e,i){return ri(e,i)}function Ki(e,i){return Bi(e,i)&&q(e)===q(i)}function Xa(e){return`Metric intent has duplicate measure "${e.name}" with the same aggregate (${q(e)}). Use different aggregates to request both, or remove one entry.`}function Ue(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function Wa(e,i,t){if(e!==void 0){if(!e||typeof e!="object"||Array.isArray(e)){t.push(o("invalid_sql_default_parameters","SQL defaultParameters must be an object keyed by parameter name.",i));return}Object.entries(e).forEach(([n,s])=>{if(!n.trim()){t.push(o("invalid_sql_default_parameter_name","SQL defaultParameters names must be non-empty strings.",`${i}.${n}`));return}(Array.isArray(s)?s.every(Ue):Ue(s))||t.push(o("invalid_sql_default_parameter_value","SQL defaultParameters values must be strings, numbers, booleans, nulls, or arrays of those scalar values.",`${i}.${n}`))})}}function Ja(e,i){return je(e,i).length===1}function en(e,i){return je(e,i).length===1}function je(e,i){return i.filter(n=>tn(e,n))}function tn(e,i){return an(e,i)?e.source?Bi(i,e):!0:!1}function an(e,i){return!(i.name!==e.name||e.role!==void 0&&i.role!==void 0&&i.role!==e.role||nn(e,i)&&q(i)!==q(e))}function nn(e,i){return e.role==="measure"||i.role==="measure"||e.aggregate!==void 0||i.aggregate!==void 0}function q(e){return te(e)}const sn=/^(\d{4})-(\d{2})-(\d{2})$/,Vi=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})$/;function J(e){if(typeof e!="string")return null;const i=e.trim(),t=sn.exec(i);if(t){const[,v,C,j]=t;return Ye(v,C,j)?new Date(Date.UTC(Number(v),Number(C)-1,Number(j))):null}const n=Vi.exec(i);if(!n)return null;const[,s,r,l,d,u,p="00",,y]=n;if(!Ye(s,r,l)||!N(d,0,23)||!N(u,0,59)||!N(p,0,59)||!rn(y))return null;const A=new Date(i);return Number.isFinite(A.getTime())?A:null}function on(e){return typeof e!="string"||!Vi.test(e.trim())?null:J(e)}function Ye(e,i,t){const n=Number(e),s=Number(i),r=Number(t);if(!Number.isInteger(n)||!Number.isInteger(s)||!Number.isInteger(r)||s<1||s>12)return!1;const l=new Date(Date.UTC(n,s-1,r));return l.getUTCFullYear()===n&&l.getUTCMonth()===s-1&&l.getUTCDate()===r}function N(e,i,t){const n=Number(e);return Number.isInteger(n)&&n>=i&&n<=t}function rn(e){if(e==="Z")return!0;const i=/^([+-])(\d{2}):(\d{2})$/.exec(e);return!!(i&&N(i[2],0,23)&&N(i[3],0,59))}function f(e){return typeof e=="string"&&e.trim().length>0}function ln(e){const i=new Set;let t=0;for(;t<e.length;){const n=e[t];if(n==="'"||n==='"'){t=dn(e,t);continue}if(n==="{"){const s=e.indexOf("}",t+1);if(s===-1){t+=1;continue}const r=e.slice(t+1,s);/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)&&i.add(r),t=s+1;continue}t+=1}return Array.from(i)}function dn(e,i){const t=e[i];let n=i+1;for(;n<e.length;){if(e[n]===t){if(e[n+1]===t){n+=2;continue}return n+1}n+=1}return e.length}function m(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function Qe(e,i,t){if(e!==void 0){if(!m(e)){t.push(o("invalid_pagination","Pagination must be an object with positive integer page and pageSize.",i));return}(!Number.isInteger(e.page)||typeof e.page!="number"||e.page<1)&&t.push(o("invalid_pagination_page","Pagination page must be a positive integer.",`${i}.page`)),(!Number.isInteger(e.pageSize)||typeof e.pageSize!="number"||e.pageSize<1)&&t.push(o("invalid_pagination_page_size","Pagination pageSize must be a positive integer.",`${i}.pageSize`))}}function ye(e){const i=new Set;for(const t of e){if(i.has(t))return t;i.add(t)}return null}function fe(e,i,t,n){ye(e.filter(r=>f(r)))&&n.push(o("duplicate_matrix_public_id",`Matrix ${t} ids must be unique so sort and expansion references are unambiguous.`,i))}const un=new Set(["SUM","COUNT","AVG","MIN","MAX","MEDIAN","DISTINCT"]);function De(e,i,t){if(!e||typeof e!="object"){t.push(o("missing_source","Analytics intent needs a source.",i));return}if(e.kind==="semantic"){f(e.domainId)||t.push(o("missing_semantic_domain","Semantic source needs a domainId.",`${i}.domainId`)),f(e.datasetName)||t.push(o("missing_dataset_name","Semantic source needs a datasetName.",`${i}.datasetName`));return}if(e.kind==="physical"){f(e.connectionId)||t.push(o("missing_connection_id","Physical source needs a connectionId.",`${i}.connectionId`)),f(e.tableName)||t.push(o("missing_table_name","Physical source needs a tableName.",`${i}.tableName`));return}if(e.kind==="sql"){f(e.connectionId)||t.push(o("missing_connection_id","SQL source needs a connectionId.",`${i}.connectionId`));return}t.push(o("invalid_source_kind","Source kind is not supported.",i))}function g(e,i,t,n={}){if(!e||!m(e)){n.required&&t.push(o("missing_field_ref","Field reference needs a name.",i));return}f(e.name)||t.push(o("missing_field_ref","Field reference needs a name.",`${i}.name`)),e.source!==void 0&&De(e.source,`${i}.source`,t),k(e.aggregate,`${i}.aggregate`,t)}function cn(e,i,t){if(!m(e)){t.push(o("invalid_input_binding","Input bindings must be structured objects.",i));return}f(e.inputId)||t.push(o("invalid_input_binding","Input bindings need a non-empty inputId.",`${i}.inputId`)),e.kind!==void 0&&e.kind!=="filter"&&e.kind!=="control"&&t.push(o("invalid_input_binding","Input binding kind must be filter or control.",`${i}.kind`)),e.field!==void 0&&g(e.field,`${i}.field`,t),e.relationshipHint!==void 0&&Fe(e.relationshipHint,`${i}.relationshipHint`,t)}function Fe(e,i,t){if(!m(e)){t.push(o("invalid_relationship_hint","Relationship hints must be structured objects.",i));return}e.relationshipIds!==void 0&&(!Array.isArray(e.relationshipIds)||e.relationshipIds.some(n=>!f(n)))&&t.push(o("invalid_relationship_hint","Relationship hint relationshipIds must be non-empty strings.",`${i}.relationshipIds`))}function pn(e,i){if(f(e.inputId)||i.push(o("missing_input_options_input_id","Input options intent needs the inputId it populates.","inputId")),(!e.labelField||!f(e.labelField.name))&&i.push(o("missing_input_options_label_field","Input options intent needs a labelField.","labelField")),g(e.labelField,"labelField",i,{required:!0}),(!e.valueField||!f(e.valueField.name))&&i.push(o("missing_input_options_value_field","Input options intent needs a valueField.","valueField")),g(e.valueField,"valueField",i,{required:!0}),e.searchField!==void 0&&g(e.searchField,"searchField",i,{required:!0}),e.disambiguationFields!==void 0&&(Array.isArray(e.disambiguationFields)?e.disambiguationFields.forEach((t,n)=>{g(t,`disambiguationFields.${n}`,i,{required:!0})}):i.push(o("invalid_input_options_disambiguation_fields","Input options disambiguationFields must be an array of field refs.","disambiguationFields"))),e.dependencies!==void 0){const t=e.dependencies;if(!m(t))i.push(o("invalid_input_options_dependencies","Input options dependencies must be a structured object.","dependencies"));else{const n=t.mode;n!==void 0&&n!=="independent"&&n!=="explicit"&&i.push(o("invalid_input_options_dependencies","Input options dependencies mode must be independent or explicit.","dependencies.mode")),Ze(t.includeInputIds,"dependencies.includeInputIds",i,"Input options includeInputIds must be non-empty strings."),Ze(t.excludeInputIds,"dependencies.excludeInputIds",i,"Input options excludeInputIds must be non-empty strings."),fn(e,i)}}if(e.population!==void 0){const t=e.population;if(!m(t))i.push(o("invalid_input_options_population","Input options population must be a structured object.","population"));else{const n=t.kind;n!=="option_source"&&n!=="related_population"&&i.push(o("invalid_input_options_population","Input options population kind must be option_source or related_population.","population.kind")),n==="option_source"&&t.baseSource!==void 0&&i.push(o("invalid_input_options_population","Input options population baseSource is only valid for related_population.","population.baseSource")),n==="option_source"&&t.relationshipHint!==void 0&&i.push(o("invalid_input_options_population","Input options population relationshipHint is only valid for related_population.","population.relationshipHint")),n==="related_population"&&(De(t.baseSource,"population.baseSource",i),t.relationshipHint!==void 0&&Fe(t.relationshipHint,"population.relationshipHint",i))}}}function mn(e,i){if(!(!("inputs"in e)||e.inputs===void 0)){if(!Array.isArray(e.inputs)){i.push(o("invalid_input_binding","Analytics intent inputs must be an array of input bindings.","inputs"));return}e.inputs.forEach((t,n)=>cn(t,`inputs.${n}`,i))}}function fn(e,i){var n,s;const t=new Set(Array.isArray(e.inputs)?e.inputs.map(r=>m(r)?r.inputId:void 0).filter(r=>typeof r=="string"):[]);for(const r of((n=e.dependencies)==null?void 0:n.includeInputIds)||[])t.has(r)||i.push(o("invalid_input_options_dependencies",`Input options dependency "${r}" is not declared in inputs.`,"dependencies.includeInputIds"));for(const r of((s=e.dependencies)==null?void 0:s.excludeInputIds)||[])r!==e.inputId&&!t.has(r)&&i.push(o("invalid_input_options_dependencies",`Input options dependency exclusion "${r}" is not the populated inputId and is not declared in inputs.`,"dependencies.excludeInputIds"))}function Ze(e,i,t,n){e!==void 0&&(!Array.isArray(e)||e.some(s=>!f(s)))&&t.push(o("invalid_input_options_dependencies",n,i))}function k(e,i,t){e!==void 0&&(typeof e!="string"||!un.has(e))&&t.push(o("invalid_aggregate","Field aggregate must be SUM, COUNT, AVG, MIN, MAX, MEDIAN, or DISTINCT.",i))}const gn=new Set(["measure","dimension","date","id","unknown"]),hn=new Set(["row","aggregate"]),Li=new Set(["string","number","boolean","date","datetime","unknown"]),yn=new Set(["number","currency","percent","percentage","scientific","date","datetime","duration","string","temporal_bucket"]),bn=new Set(T),_n=new Set(["millisecond","second","minute","hour","day"]),vn=new Set(["compact","digital","long"]);function Hi(e,i,t){if(e===void 0)return;if(!m(e)){t.push(o("invalid_value_format","Value format must be a structured object.",i));return}const n=e;(typeof n.type!="string"||!yn.has(n.type))&&t.push(o("invalid_value_format_type","Value format type must be number, currency, percent, percentage, scientific, date, datetime, duration, string, or temporal_bucket.",`${i}.type`)),n.type==="temporal_bucket"&&!Q.safeParse(e).success&&t.push(o("invalid_temporal_bucket_format","Temporal bucket format must contain a valid auto, preset, or pattern presentation.",i)),(n.type==="number"||n.type==="currency"||n.type==="percent"||n.type==="percentage"||n.type==="scientific")&&Object.prototype.hasOwnProperty.call(e,"locale")&&t.push(o("invalid_value_format","Numeric value formats cannot define viewer locale.",`${i}.locale`)),H(e.minimumFractionDigits,`${i}.minimumFractionDigits`,t),H(e.maximumFractionDigits,`${i}.maximumFractionDigits`,t),H(e.scale,`${i}.scale`,t),H(e.maxUnits,`${i}.maxUnits`,t),e.useGrouping!==void 0&&typeof e.useGrouping!="boolean"&&t.push(o("invalid_value_format_use_grouping","Value format useGrouping must be boolean.",`${i}.useGrouping`)),e.negativeStyle!==void 0&&e.negativeStyle!=="minus"&&e.negativeStyle!=="parentheses"&&t.push(o("invalid_value_format_negative_style","Value format negativeStyle must be minus or parentheses.",`${i}.negativeStyle`)),e.percentValueMode!==void 0&&e.percentValueMode!=="fraction"&&e.percentValueMode!=="whole"&&t.push(o("invalid_value_format_percent_mode","Value format percentValueMode must be fraction or whole.",`${i}.percentValueMode`));for(const s of["inputUnit","largestUnit","smallestUnit"]){const r=e[s];r!==void 0&&(typeof r!="string"||!_n.has(r))&&t.push(o("invalid_value_format_duration_unit","Duration format units must be millisecond, second, minute, hour, or day.",`${i}.${s}`))}e.outputStyle!==void 0&&(typeof e.outputStyle!="string"||!vn.has(e.outputStyle))&&t.push(o("invalid_value_format_duration_style","Duration format outputStyle must be compact, digital, or long.",`${i}.outputStyle`))}function Gi(e,i,t){if(m(e)&&e.type==="temporal_bucket"){t.push(o("invalid_scalar_value_format","Scalar and measure slots cannot own temporal bucket presentation; declare it with grain on a grouped field or axis.",i));return}Hi(e,i,t)}function H(e,i,t){e!==void 0&&(typeof e!="number"||!Number.isFinite(e))&&t.push(o("invalid_value_format_number","Value format numeric options must be finite numbers.",i))}const zn=new Set(["additive","non_additive","ratio_of_sums","weighted","pre_aggregated","snapshot"]),Sn=new Set(["default","symmetric_aggregate","aggregate_then_join","weighted"]);function $n(e,i,t){if(!e||!m(e)){t.push(o("invalid_derived_field_input","Derived field inputs must be structured input references.",i));return}if(e.kind==="field"){g(e.field,`${i}.field`,t,{required:!0}),k(e.aggregate,`${i}.aggregate`,t);return}t.push(o("invalid_derived_field_input","Derived field input kind must be field.",`${i}.kind`))}function Xe(e,i,t){if(!m(e)){t.push(o("invalid_result_column_ref","Result calculation references must use columnKey or field.",i));return}const n=f(e.columnKey),s=m(e.field);if(n===s){t.push(o("invalid_result_column_ref","Result calculation references must identify exactly one of columnKey or field.",i));return}s&&g(e.field,`${i}.field`,t,{required:!0})}function wn(e,i,t){if(!m(e)){t.push(o("invalid_result_calculation_output","Result calculation output must be a structured object.",i));return}f(e.key)||t.push(o("invalid_result_calculation_output","Result calculation output needs a stable key.",`${i}.key`)),e.dataType!==void 0&&(typeof e.dataType!="string"||!Li.has(e.dataType))&&t.push(o("invalid_result_calculation_output","Result calculation output dataType must be string, number, boolean, date, datetime, or unknown.",`${i}.dataType`)),Gi(e.format,`${i}.format`,t)}function kn(e,i,t){e!==void 0&&(ti(e)||t.push(o("invalid_time_grain",`Matrix time grain must be one of: ${ie.join(", ")}.`,i)))}function Ui(e,i,t,n){e!=="asc"&&e!=="desc"&&t.push(o(n,"Sort direction must be asc or desc.",i))}function Yi(e,i,t,n){e!==void 0&&e!=="warehouseDefault"&&e!=="first"&&e!=="last"&&t.push(o(n,"Null ordering must be warehouseDefault, first, or last.",i))}function Qi(e,i,t,n){e!==void 0&&e!=="global"&&e!=="withinParent"&&t.push(o(n,"Sort scope must be global or withinParent.",i))}function An(e,i,t){e.enabled!==void 0&&typeof e.enabled!="boolean"&&t.push(o("invalid_matrix_subtotal","Matrix subtotal enabled must be a boolean.",`${i}.enabled`)),e.position!==void 0&&e.position!=="before"&&e.position!=="after"&&t.push(o("invalid_matrix_subtotal","Matrix subtotal position must be before or after.",`${i}.position`)),e.label!==void 0&&typeof e.label!="string"&&t.push(o("invalid_matrix_subtotal","Matrix subtotal label must be a string.",`${i}.label`))}function In(e,i,t){if(Ui(e.direction,`${i}.direction`,t,"invalid_matrix_sort_direction"),Yi(e.nulls,`${i}.nulls`,t,"invalid_matrix_sort_nulls"),Qi(e.scope,`${i}.scope`,t,"invalid_matrix_sort_scope"),!m(e.by)){t.push(o("invalid_matrix_sort_by","Matrix sort by must be a structured object.",`${i}.by`));return}if(e.by.kind!=="member"){if(e.by.kind==="field"){g(e.by.field,`${i}.by.field`,t,{required:!0}),k(e.by.aggregate,`${i}.by.aggregate`,t);return}t.push(o("invalid_matrix_sort_by","Matrix axis sort by must be member or field.",`${i}.by.kind`))}}function We(e,i,t,n){if(!Array.isArray(e))return n.required?t.push(o("missing_matrix_rows","Matrix intent needs at least one row axis level.",i)):e!==void 0&&t.push(o("invalid_matrix_columns","Matrix columns must be an array of axis levels.",i)),[];n.required&&e.length===0&&t.push(o("missing_matrix_rows","Matrix intent needs at least one row axis level.",i));const s=[];return e.forEach((r,l)=>{var C,j;const d=`${i}.${l}`;if(!m(r)){t.push(o("invalid_matrix_axis_level","Matrix axis levels must be structured objects.",d));return}const u=r;s.push(u),u.id!==void 0&&!f(u.id)&&t.push(o("invalid_matrix_axis_level_id","Matrix axis level id must be a non-empty string.",`${d}.id`)),g(u.field,`${d}.field`,t,{required:!0}),kn(u.grain,`${d}.grain`,t);const p=le((C=u.field)==null?void 0:C.dataType),y=((j=u.field)==null?void 0:j.role)==="date"||p==="date"||p==="datetime",A=p==="string"||p==="number"||p==="boolean";y&&!u.grain&&t.push(o("missing_matrix_temporal_grain","Temporal Matrix axis levels require an explicit supported grain.",`${d}.grain`)),A&&u.grain&&t.push(o("invalid_matrix_temporal_grain","Matrix grain is valid only for temporal axis fields.",`${d}.grain`)),u.format!==void 0&&(!u.grain||!Q.safeParse(u.format).success?t.push(o("invalid_matrix_temporal_format","Matrix temporal presentation requires a valid structured format and explicit grain.",`${d}.format`)):W(u.format,u.grain).ok||t.push(o("invalid_matrix_temporal_format","Matrix temporal presentation is not applicable to the selected grain.",`${d}.format`)));const v=u.semanticTemporalPresentation;if(v!==void 0){const qe=v==null?void 0:v.format;!u.grain||(v==null?void 0:v.granularity)!==u.grain||!Q.safeParse(qe).success?t.push(o("invalid_matrix_temporal_format","Matrix semantic temporal presentation must match the selected grain.",`${d}.semanticTemporalPresentation`)):W(qe,u.grain).ok||t.push(o("invalid_matrix_temporal_format","Matrix semantic temporal presentation is not applicable to the selected grain.",`${d}.semanticTemporalPresentation.format`))}u.label!==void 0&&typeof u.label!="string"&&t.push(o("invalid_matrix_axis_label","Matrix axis level label must be a string.",`${d}.label`)),u.subtotal!==void 0&&typeof u.subtotal!="boolean"&&(m(u.subtotal)?An(u.subtotal,`${d}.subtotal`,t):t.push(o("invalid_matrix_subtotal","Matrix subtotal must be a boolean or structured options object.",`${d}.subtotal`))),u.sortBy!==void 0&&(m(u.sortBy)?In(u.sortBy,`${d}.sortBy`,t):t.push(o("invalid_matrix_sort_by","Matrix axis sortBy must be a structured object.",`${d}.sortBy`)))}),s}function xn(e,i,t){if(!m(e)){t.push(o("invalid_matrix_total_behavior","Matrix total behavior must be a structured object.",i));return}if(e.kind!=="defaultAggregate"&&e.kind!=="blank"&&e.kind!=="labelOnly"&&e.kind!=="customAggregate"&&e.kind!=="percentOfParent"&&e.kind!=="percentOfGrandTotal"&&e.kind!=="customExpression"){t.push(o("invalid_matrix_total_behavior","Matrix total behavior kind is not supported.",`${i}.kind`));return}e.kind==="customAggregate"&&(Object.prototype.hasOwnProperty.call(e,"aggregate")?k(e.aggregate,`${i}.aggregate`,t):t.push(o("invalid_matrix_total_behavior","Custom matrix total behavior needs an aggregate.",`${i}.aggregate`))),e.kind==="customExpression"&&!f(e.expressionId)&&t.push(o("invalid_matrix_total_behavior","Custom matrix total behavior needs an expressionId.",`${i}.expressionId`)),e.kind==="labelOnly"&&e.label!==void 0&&typeof e.label!="string"&&t.push(o("invalid_matrix_total_behavior","Matrix label-only total behavior label must be a string.",`${i}.label`))}function Rn(e,i,t){if(!Array.isArray(e)||e.length===0)return t.push(o("missing_matrix_values","Matrix intent needs at least one value field.",i)),[];const n=[];return e.forEach((s,r)=>{const l=`${i}.${r}`;if(!m(s)){t.push(o("invalid_matrix_value","Matrix values must be structured objects.",l));return}const d=s;n.push(d),d.id!==void 0&&!f(d.id)&&t.push(o("invalid_matrix_value_id","Matrix value id must be a non-empty string.",`${l}.id`)),g(d.field,`${l}.field`,t,{required:!0}),k(d.aggregate,`${l}.aggregate`,t),Gi(d.format,`${l}.format`,t),d.label!==void 0&&typeof d.label!="string"&&t.push(o("invalid_matrix_value_label","Matrix value label must be a string.",`${l}.label`)),d.totalBehavior!==void 0&&xn(d.totalBehavior,`${l}.totalBehavior`,t)}),n}function Mn(e,i,t){if(!m(e)){t.push(o("invalid_matrix_totals","Matrix totals must be a structured object.",i));return}for(const n of["rows","columns"]){const s=e[n];s!==void 0&&s!==!0&&s!==!1&&s!=="perLevel"&&t.push(o("invalid_matrix_totals","Matrix total axis setting must be a boolean or perLevel.",`${i}.${n}`))}if(e.grandTotal!==void 0&&typeof e.grandTotal!="boolean")if(!m(e.grandTotal))t.push(o("invalid_matrix_totals","Matrix grandTotal must be a boolean or structured object.",`${i}.grandTotal`));else for(const n of["rows","columns"]){const s=e.grandTotal[n];s!==void 0&&typeof s!="boolean"&&t.push(o("invalid_matrix_totals","Matrix grandTotal rows/columns must be booleans.",`${i}.grandTotal.${n}`))}e.rowPosition!==void 0&&e.rowPosition!=="top"&&e.rowPosition!=="bottom"&&t.push(o("invalid_matrix_totals","Matrix row total position must be top or bottom.",`${i}.rowPosition`)),e.columnPosition!==void 0&&e.columnPosition!=="left"&&e.columnPosition!=="right"&&t.push(o("invalid_matrix_totals","Matrix column total position must be left or right.",`${i}.columnPosition`))}function be(e,i,t,n){if(!Array.isArray(e)){n.push(o("invalid_matrix_path","Matrix member path must be an array of path segments.",i));return}e.forEach((s,r)=>{const l=`${i}.${r}`;if(!m(s)){n.push(o("invalid_matrix_path","Matrix path segment must be a structured object.",l));return}const d=s;if(!f(d.levelId)){n.push(o("stable_id_required","Matrix path segments must reference an explicit public axis level id.",`${l}.levelId`));return}Object.prototype.hasOwnProperty.call(s,"value")||n.push(o("invalid_matrix_path","Matrix path segments must include a value property; use explicit null for null members.",`${l}.value`)),t.has(d.levelId)||n.push(o("stable_id_required","Matrix path segment levelId must match an explicit public axis level id.",`${l}.levelId`))})}function Je(e,i,t,n){if(!m(e)){n.push(o("invalid_matrix_expansion","Matrix expansion axis options must be structured objects.",i));return}e.defaultDepth!==void 0&&(typeof e.defaultDepth!="number"||!Number.isInteger(e.defaultDepth)||e.defaultDepth<0)&&n.push(o("invalid_matrix_expansion","Matrix expansion defaultDepth must be a non-negative integer.",`${i}.defaultDepth`)),e.lazy!==void 0&&typeof e.lazy!="boolean"&&n.push(o("invalid_matrix_expansion","Matrix expansion lazy must be a boolean.",`${i}.lazy`)),e.expandedPaths!==void 0&&(Array.isArray(e.expandedPaths)?e.expandedPaths.forEach((s,r)=>{be(s,`${i}.expandedPaths.${r}`,t,n)}):n.push(o("invalid_matrix_expansion","Matrix expandedPaths must be an array of member paths.",`${i}.expandedPaths`)))}function Tn(e,i,t,n){if(e!==void 0){if(!m(e)){n.push(o("invalid_matrix_expansion","Matrix expansion must be a structured object.","expansion"));return}e.rows!==void 0&&Je(e.rows,"expansion.rows",i,n),e.columns!==void 0&&Je(e.columns,"expansion.columns",t,n)}}function En(e,i,t,n,s){if(e!==void 0){if(!Array.isArray(e)){s.push(o("invalid_matrix_sort","Matrix sort must be an array of sort rules.","sort"));return}e.forEach((r,l)=>{const d=`sort.${l}`;if(!m(r)){s.push(o("invalid_matrix_sort","Matrix sort rule must be a structured object.",d));return}const u=r;u.axis!=="row"&&u.axis!=="column"&&s.push(o("invalid_matrix_sort","Matrix sort axis must be row or column.",`${d}.axis`));const p=u.axis==="column"?t:i;if(u.targetId!==void 0&&!p.has(u.targetId)&&s.push(o("stable_id_required","Matrix sort targetId must reference an explicit public axis level id.",`${d}.targetId`)),Ui(u.direction,`${d}.direction`,s,"invalid_matrix_sort_direction"),Yi(u.nulls,`${d}.nulls`,s,"invalid_matrix_sort_nulls"),Qi(u.scope,`${d}.scope`,s,"invalid_matrix_sort_scope"),!m(u.by)){s.push(o("invalid_matrix_sort_by","Matrix sort by must be a structured object.",`${d}.by`));return}if(u.by.kind!=="member"){if(u.by.kind==="field"){g(u.by.field,`${d}.by.field`,s,{required:!0}),k(u.by.aggregate,`${d}.by.aggregate`,s);return}if(u.by.kind==="value"){(!f(u.by.valueId)||!n.has(u.by.valueId))&&s.push(o("stable_id_required","Matrix value sort must reference an explicit public value id.",`${d}.by.valueId`)),u.by.rowPath!==void 0&&be(u.by.rowPath,`${d}.by.rowPath`,i,s),u.by.columnPath!==void 0&&be(u.by.columnPath,`${d}.by.columnPath`,t,s);return}s.push(o("invalid_matrix_sort_by","Matrix sort by must be label, field, or value.",`${d}.by.kind`))}})}}function Cn(e,i){if(e!==void 0){if(!m(e)){i.push(o("invalid_matrix_layout","Matrix layout must be a structured object.","layout"));return}e.hierarchy!==void 0&&e.hierarchy!=="compact"&&e.hierarchy!=="tabular"&&e.hierarchy!=="outline"&&i.push(o("invalid_matrix_layout","Matrix hierarchy layout must be compact, tabular, or outline.","layout.hierarchy")),e.valuesPlacement!==void 0&&e.valuesPlacement!=="columns"&&e.valuesPlacement!=="rows"&&i.push(o("invalid_matrix_layout","Matrix valuesPlacement must be columns or rows.","layout.valuesPlacement")),e.stickyRowHeaders!==void 0&&typeof e.stickyRowHeaders!="boolean"&&i.push(o("invalid_matrix_layout","Matrix stickyRowHeaders must be a boolean.","layout.stickyRowHeaders")),e.stickyColumnHeaders!==void 0&&typeof e.stickyColumnHeaders!="boolean"&&i.push(o("invalid_matrix_layout","Matrix stickyColumnHeaders must be a boolean.","layout.stickyColumnHeaders"))}}function ei(e,i,t){if(!m(e)){t.push(o("invalid_matrix_display_limits","Matrix display limit must be a structured object.",i));return}(typeof e.limit!="number"||!Number.isInteger(e.limit)||e.limit<1)&&t.push(o("invalid_matrix_display_limits","Matrix display limit must be a positive integer.",`${i}.limit`));for(const n of Object.keys(e))n!=="limit"&&t.push(o("invalid_matrix_display_limits",`Matrix display limit ${n} is not supported in v1; use count-only { limit } display limits.`,`${i}.${n}`))}function jn(e,i){if(e!==void 0){if(!m(e)){i.push(o("invalid_matrix_display_limits","Matrix displayLimits must be a structured object.","displayLimits"));return}e.rows!==void 0&&ei(e.rows,"displayLimits.rows",i),e.columns!==void 0&&ei(e.columns,"displayLimits.columns",i);for(const t of Object.keys(e))t==="rows"||t==="columns"||i.push(o("invalid_matrix_display_limits",`Matrix displayLimits ${t} is not supported in v1; use rows and columns count limits only.`,`displayLimits.${t}`))}}function Dn(e,i){var u;((u=e.source)==null?void 0:u.kind)==="sql"&&i.push(o("unsupported_matrix_sql_source","Matrix analytics intent does not support raw SQL sources.","source.kind"));const t=We(e.rows,"rows",i,{required:!0}),n=We(e.columns,"columns",i,{required:!1}),s=Rn(e.values,"values",i);ee(e.filters,"filters",i),e.totals!==void 0&&Mn(e.totals,"totals",i),fe(t.map(p=>p.id),"rows","row axis level",i),fe(n.map(p=>p.id),"columns","column axis level",i),fe(s.map(p=>p.id),"values","value",i);const r=new Set(t.map(p=>p.id).filter(p=>f(p))),l=new Set(n.map(p=>p.id).filter(p=>f(p))),d=new Set(s.map(p=>p.id).filter(p=>f(p)));En(e.sort,r,l,d,i),Tn(e.expansion,r,l,i),Cn(e.layout,i),jn(e.displayLimits,i)}function Fn(e,i){if(e.analysis===void 0)return;if(!m(e.analysis)){i.push(o("invalid_measure_analysis","Metric analysis must be a structured object.","analysis"));return}if(e.analysis.kind!=="period_change"){i.push(o("invalid_measure_analysis","Metric analysis kind is not supported.","analysis.kind"));return}e.dateField||i.push(o("missing_analysis_date_field","Period-change analysis needs a dateField.","dateField")),e.timeGrain||i.push(o("missing_analysis_time_grain","Period-change analysis needs a timeGrain.","timeGrain")),e.analysis.orderBy!==void 0&&e.analysis.orderBy!=="absolute_change"&&e.analysis.orderBy!=="positive_change"&&e.analysis.orderBy!=="negative_change"&&e.analysis.orderBy!=="period"&&i.push(o("invalid_measure_analysis","Period-change analysis orderBy must be absolute_change, positive_change, negative_change, or period.","analysis.orderBy"));const{timeWindow:t}=e.analysis;t!==void 0&&_e(t,"analysis.timeWindow",i)}function _e(e,i,t){if(!m(e)){t.push(o("invalid_time_window","Time window must be a structured object.",i));return}if(e.kind!==void 0&&e.kind!=="relative"&&e.kind!=="absolute"&&t.push(o("invalid_time_window","Time window kind must be relative or absolute.",`${i}.kind`)),e.kind==="absolute"){if(f(e.start)||t.push(o("invalid_time_window","Absolute time window start must be a non-empty ISO date or timestamp string.",`${i}.start`)),f(e.end)||t.push(o("invalid_time_window","Absolute time window end must be a non-empty ISO date or timestamp string.",`${i}.end`)),f(e.start)&&f(e.end)){const n=J(e.start),s=J(e.end);n||t.push(o("invalid_time_window","Absolute time window start must be a valid ISO date or timestamp.",`${i}.start`)),s||t.push(o("invalid_time_window","Absolute time window end must be a valid ISO date or timestamp.",`${i}.end`)),n&&s&&n.getTime()>s.getTime()&&t.push(o("invalid_time_window","Absolute time window start must be before or equal to end.",i))}return}(typeof e.unit!="string"||!bn.has(e.unit))&&t.push(o("invalid_time_window",`Time window unit must be one of: ${T.join(", ")}.`,`${i}.unit`)),(typeof e.value!="number"||!Number.isFinite(e.value)||e.value<=0)&&t.push(o("invalid_time_window","Time window value must be a positive number.",`${i}.value`)),e.anchor!==void 0&&e.anchor!=="now"&&e.anchor!=="latest_available"&&t.push(o("invalid_time_window","Time window anchor must be now or latest_available.",`${i}.anchor`)),e.completeness!==void 0&&e.completeness!=="include_partial"&&e.completeness!=="complete_periods"&&t.push(o("invalid_time_window","Time window completeness must be include_partial or complete_periods.",`${i}.completeness`))}function ee(e,i,t){if(e!==void 0){if(!Array.isArray(e)){t.push(o("invalid_analytics_filters","Analytics filters must be an array.",i));return}e.forEach((n,s)=>{var u;const r=`${i}.${s}`;if(!m(n)){t.push(o("invalid_analytics_filter","Analytics filter must be a structured object.",r));return}const l=n;g(l.field,`${r}.field`,t,{required:!0}),l.scope!==void 0&&l.scope!=="row"&&l.scope!=="aggregate"&&t.push(o("invalid_analytics_filter_scope","Analytics filter scope must be row or aggregate.",`${r}.scope`)),l.scope==="aggregate"&&((u=l.field)==null?void 0:u.role)!==void 0&&l.field.role!=="measure"&&t.push(o("invalid_analytics_filter_scope","Aggregate-scope analytics filters must target a measure field.",`${r}.scope`));const d=l.operator==="is_null"||l.operator==="is_not_null";if(l.operator!==void 0&&l.operator!=="="&&l.operator!=="!="&&l.operator!=="in"&&l.operator!=="not_in"&&l.operator!=="contains"&&l.operator!=="not_contains"&&l.operator!=="between"&&l.operator!=="not_between"&&l.operator!==">"&&l.operator!==">="&&l.operator!=="<"&&l.operator!=="<="&&l.operator!=="is_null"&&l.operator!=="is_not_null"&&t.push(o("invalid_analytics_filter_operator","Analytics filter operator is not supported.",`${r}.operator`)),l.values===void 0&&!d&&t.push(o("missing_analytics_filter_value","Analytics filter needs values unless it is a null check.",r)),d&&l.values!==void 0){t.push(o("invalid_analytics_filter_values","Null-check analytics filters must not include values.",`${r}.values`));return}if(l.values!==void 0&&!Array.isArray(l.values)){t.push(o("invalid_analytics_filter_values","Analytics filter values must be an array when provided.",`${r}.values`));return}if(l.values!==void 0){const p=l.values.length;if(l.operator==="between"||l.operator==="not_between"){p!==2&&t.push(o("invalid_analytics_filter_values","Between analytics filters must include exactly two values.",`${r}.values`));return}(l.operator==="contains"||l.operator==="not_contains"||l.operator==="="||l.operator==="!="||l.operator===">"||l.operator===">="||l.operator==="<"||l.operator==="<="||l.operator===void 0)&&p!==1&&t.push(o("invalid_analytics_filter_values","Scalar analytics filters must include exactly one value. Use in/not_in for multiple values.",`${r}.values`))}})}}function Zi(e){const i=[];if(!m(e))return i.push(o("invalid_derived_field","Derived field definition must be a structured object.")),{ok:!1,errors:i,warnings:[]};if(e.kind!=="derived_field"&&i.push(o("invalid_derived_field_kind","Derived field kind must be derived_field.","kind")),f(e.name)||i.push(o("invalid_derived_field_name","Derived field needs a name.","name")),f(e.label)||i.push(o("invalid_derived_field_label","Derived field needs a label.","label")),gn.has(e.resultRole)||i.push(o("invalid_derived_field_role","Derived field resultRole must be measure, dimension, date, id, or unknown.","resultRole")),Li.has(e.dataType)||i.push(o("invalid_derived_field_data_type","Derived field dataType must be string, number, boolean, date, datetime, or unknown.","dataType")),hn.has(e.computeStage)||i.push(o("invalid_derived_field_compute_stage","Derived field computeStage must be row or aggregate.","computeStage")),e.computeStage==="aggregate"&&e.resultRole!=="measure"&&i.push(o("invalid_derived_field_compute_stage","Aggregate-stage derived fields must have resultRole measure.","computeStage")),e.resultRole!=="measure"&&e.defaultAggregate!==void 0&&i.push(o("invalid_derived_field_aggregate","Only measure derived fields may declare defaultAggregate.","defaultAggregate")),e.computeStage==="row"&&e.resultRole==="measure"&&e.defaultAggregate===void 0&&i.push(o("missing_derived_field_default_aggregate","Row-stage measure derived fields must declare defaultAggregate so row results have explicit rollup semantics.","defaultAggregate")),k(e.defaultAggregate,"defaultAggregate",i),e.aggregationBehavior!==void 0&&!zn.has(e.aggregationBehavior)&&i.push(o("invalid_derived_field_aggregation_behavior","Derived field aggregationBehavior is not supported.","aggregationBehavior")),e.aggregationStrategy!==void 0&&!Sn.has(e.aggregationStrategy)&&i.push(o("invalid_derived_field_aggregation_strategy","Derived field aggregationStrategy is not supported.","aggregationStrategy")),f(e.expression)||i.push(o("invalid_derived_field_expression","Derived field needs a named-token expression.","expression")),e.expressionLanguage!==void 0&&e.expressionLanguage!=="semaphor_sql_template"&&i.push(o("invalid_derived_field_expression_language","Derived field expressionLanguage must be semaphor_sql_template.","expressionLanguage")),!m(e.inputs)||Object.keys(e.inputs).length===0?i.push(o("invalid_derived_field_inputs","Derived field needs at least one typed input.","inputs")):Object.entries(e.inputs).forEach(([n,s])=>{if(!f(n)){i.push(o("invalid_derived_field_input_name","Derived field input names must be non-empty strings.","inputs"));return}$n(s,`inputs.${n}`,i)}),f(e.expression)&&m(e.inputs)){const n=ln(e.expression),s=new Set(n),r=Object.keys(e.inputs).filter(l=>f(l));n.forEach(l=>{Object.prototype.hasOwnProperty.call(e.inputs,l)||i.push(o("invalid_derived_field_expression_token",`Derived field expression token "{${l}}" needs a matching inputs.${l} entry.`,"expression"))}),r.forEach(l=>{s.has(l)||i.push(o("unused_derived_field_input",`Derived field input "${l}" is not referenced by expression.`,`inputs.${l}`))})}const t=e.format;return m(t)&&t.type==="temporal_bucket"?i.push(o("invalid_derived_field_format","Derived field computation metadata cannot own temporal bucket presentation; declare grain and format on the grouped field.","format")):Hi(t,"format",i),e.tags!==void 0&&(!Array.isArray(e.tags)||e.tags.some(n=>!f(n)))&&i.push(o("invalid_derived_field_tags","Derived field tags must be non-empty strings.","tags")),{ok:i.length===0,errors:i,warnings:[]}}function Nn(e){const i=[];if(!m(e))return i.push(o("invalid_result_calculation","Result calculation must be a structured object.")),{ok:!1,errors:i,warnings:[]};if(f(e.id)||i.push(o("invalid_result_calculation_id","Result calculation needs an id.","id")),f(e.label)||i.push(o("invalid_result_calculation_label","Result calculation needs a label.","label")),e.kind!=="percent_of_total"&&e.kind!=="rank"&&e.kind!=="running_total"&&e.kind!=="previous_row_delta"&&i.push(o("invalid_result_calculation_kind","Result calculation kind must be percent_of_total, rank, running_total, or previous_row_delta.","kind")),Xe(e.input,"input",i),wn(e.output,"output",i),e.kind==="percent_of_total"){const t=e.denominator;t!==void 0&&(m(t)?t.scope==="population"?(g(t.metric,"denominator.metric",i,{required:!0}),ee(t.filters,"denominator.filters",i)):t.scope!=="returned_result"&&i.push(o("invalid_result_calculation_denominator","Percent-of-total denominator scope must be returned_result or population.","denominator.scope")):i.push(o("invalid_result_calculation_denominator","Percent-of-total denominator must be a structured object.","denominator")))}return e.kind==="rank"&&e.order!==void 0&&e.order!=="asc"&&e.order!=="desc"&&i.push(o("invalid_result_calculation_order","Rank result calculation order must be asc or desc.","order")),(e.kind==="running_total"||e.kind==="previous_row_delta")&&e.orderBy!==void 0&&Xe(e.orderBy,"orderBy",i),{ok:i.length===0,errors:i,warnings:[]}}function Ne(e){var n;const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[o("invalid_analytics_intent","Analytics intent must be a structured object.")],warnings:t,repairHints:[{code:"invalid_analytics_intent",recommendedNextStep:"Send one structured analytics intent object with kind, source, and required fields."}]};if(e.version!==void 0&&e.version!==1&&i.push(o("invalid_version","Analytics intent version must be 1.","version")),De(e.source,"source",i),qn(e,i),mn(e,i),"relationshipHint"in e&&e.relationshipHint!==void 0&&Fe(e.relationshipHint,"relationshipHint",i),e.kind==="metric"){const s=Array.isArray(e.measures)?e.measures.filter(r=>m(r)&&f(r.name)):[];if(!Array.isArray(e.measures)||e.measures.length===0?i.push(o("missing_measure","Metric intent needs at least one measure.","measures")):e.measures.some(r=>!m(r)||!f(r.name))&&i.push(o("invalid_measure_list","Metric intent measures must be an array of field references with names.","measures")),s.forEach((r,l)=>{g(r,`measures.${l}`,i,{required:!0})}),s.length>0&&!Za(s)){const r=s.find((l,d)=>s.some((u,p)=>p!==d&&Ki(u,l)));r&&i.push(o("duplicate_measure",Xa(r),"measures"))}if(m(e.primaryMeasure)&&f(e.primaryMeasure.name)&&je(e.primaryMeasure,s).length>1&&i.push(o("ambiguous_primary_measure","Metric intent primaryMeasure must identify exactly one selected measure.","primaryMeasure")),e.primaryMeasure!==void 0&&(g(e.primaryMeasure,"primaryMeasure",i,{required:!0}),m(e.primaryMeasure)&&f(e.primaryMeasure.name)&&s.length>0&&!Ja(e.primaryMeasure,s)&&i.push(o("invalid_primary_measure","Metric intent primaryMeasure must match one measure field reference.","primaryMeasure"))),e.dimensions!==void 0&&!Array.isArray(e.dimensions)?i.push(o("invalid_measure_dimensions","Metric intent dimensions must be an array of field references.","dimensions")):Array.isArray(e.dimensions)&&e.dimensions.some(r=>!m(r)||!f(r.name))&&i.push(o("invalid_measure_dimensions","Metric intent dimensions must be an array of field references with names.","dimensions")),e.dateField!==void 0&&g(e.dateField,"dateField",i),e.timeWindow!==void 0&&(_e(e.timeWindow,"timeWindow",i),e.dateField||i.push(o("missing_time_window_date_field","Metric timeWindow needs a dateField.","dateField"))),ee(e.filters,"filters",i),Array.isArray(e.dimensions)&&e.dimensions.forEach((r,l)=>{g(r,`dimensions.${l}`,i)}),e.orderBy!==void 0){if(!m(e.orderBy))i.push(o("invalid_measure_order_by","Metric intent orderBy must be a structured object.","orderBy"));else if(g(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(o("invalid_measure_order_direction","Metric intent orderBy direction must be asc or desc.","orderBy.direction")),m(e.orderBy.field)&&f(e.orderBy.field.name)){const r=[...s,...e.timeGrain&&e.dateField&&m(e.dateField)?[e.dateField]:[],...Array.isArray(e.dimensions)?e.dimensions.filter(l=>m(l)&&f(l.name)):[]];r.length>0&&!en(e.orderBy.field,r)&&i.push(o("invalid_measure_order_by","Metric intent orderBy.field must match one selected measure, grouped dateField, or dimension.","orderBy.field"))}}Fn(e,i)}else if(e.kind==="records"){if(!Array.isArray(e.fields)||e.fields.length===0?i.push(o("missing_record_fields","Records intent needs at least one field.","fields")):e.fields.some(s=>!m(s)||!f(s.name))&&i.push(o("invalid_record_fields","Records intent fields must be field references with names.","fields")),Array.isArray(e.fields)&&e.fields.forEach((s,r)=>{g(s,`fields.${r}`,i)}),e.dateField!==void 0&&g(e.dateField,"dateField",i),Qe(e.pagination,"pagination",i),e.timeWindow!==void 0&&(_e(e.timeWindow,"timeWindow",i),e.dateField||i.push(o("missing_time_window_date_field","Records timeWindow needs a dateField.","dateField"))),ee(e.filters,"filters",i),Array.isArray(e.filters)&&e.filters.forEach((s,r)=>{m(s)&&s.scope==="aggregate"&&i.push(o("unsupported_record_filter_scope","Records intents support row-scope filters only. Use a metric intent for aggregate-scope filters.",`filters.${r}.scope`))}),e.orderBy!==void 0&&(m(e.orderBy)?(g(e.orderBy.field,"orderBy.field",i,{required:!0}),e.orderBy.direction!=="asc"&&e.orderBy.direction!=="desc"&&i.push(o("invalid_record_order_direction","Records intent orderBy direction must be asc or desc.","orderBy.direction"))):i.push(o("invalid_record_order_by","Records intent orderBy must be a structured object.","orderBy"))),e.totals!==void 0)if(!m(e.totals))i.push(o("invalid_records_totals","Records totals must be a structured server totals request.","totals"));else{e.totals.mode!=="server"&&i.push(o("invalid_records_totals","Records totals mode must be server.","totals.mode"));const s=e.totals.measures;!Array.isArray(s)||s.length===0?i.push(o("missing_records_totals_measures","Records server totals need at least one measure.","totals.measures")):s.forEach((r,l)=>{g(r,`totals.measures.${l}`,i,{required:!0}),(!m(r)||r.role!=="measure")&&i.push(o("invalid_records_totals_measure","Records server totals measures must be measure field references.",`totals.measures.${l}.role`))})}}else e.kind==="inputOptions"?pn(e,i):e.kind==="matrix"?Dn(e,i):e.kind==="sql"?(((n=e.source)==null?void 0:n.kind)!=="sql"&&i.push(o("invalid_sql_source","SQL analytics intent must use a SQL execution source.","source")),f(e.sql)||i.push(o("missing_sql","SQL analytics intent needs SQL text.","sql")),Wa(e.defaultParameters,"defaultParameters",i),Array.isArray(e.fields)&&e.fields.forEach((s,r)=>{g(s,`fields.${r}`,i)}),Qe(e.pagination,"pagination",i)):i.push(o("invalid_analytics_kind","Analytics kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:t,repairHints:Pn(i)}}function qn(e,i){if(!(!("derivedFields"in e)||e.derivedFields===void 0)){if(!Array.isArray(e.derivedFields)){i.push(o("invalid_derived_fields","Analytics intent derivedFields must be an array of derived field definitions.","derivedFields"));return}e.derivedFields.forEach((t,n)=>{Zi(t).errors.forEach(r=>{i.push({...r,path:r.path?`derivedFields.${n}.${r.path}`:`derivedFields.${n}`})})})}}function Xi(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[o("invalid_operation_intent","Operation intent must be a structured object.")],warnings:t,repairHints:[{code:"invalid_operation_intent",recommendedNextStep:"Send one typed operation intent with version, kind, and required operation fields."}]};if(e.version!==1&&i.push(o("invalid_version","Operation intent version must be 1.","version")),e.kind==="answer_obligations")!Array.isArray(e.obligations)||e.obligations.length===0?i.push(o("missing_obligations","Answer-obligations operation intent needs at least one obligation.","obligations")):e.obligations.forEach((n,s)=>{f(n.id)||i.push(o("missing_obligation_id","Each analytics obligation needs an id.",`obligations.${s}.id`)),f(n.prompt)||i.push(o("missing_obligation_prompt","Each analytics obligation needs a prompt.",`obligations.${s}.prompt`))});else if(e.kind==="dashboard_change"||e.kind==="data_app_change"){if(f(e.instruction)||i.push(o("missing_instruction","Change operation intent needs an instruction.","instruction")),e.analyticsIntent){const n=Ne(e.analyticsIntent);i.push(...n.errors),t.push(...n.warnings)}}else i.push(o("invalid_operation_kind","Operation intent kind is not supported.","kind"));return{ok:i.length===0,errors:i,warnings:t,repairHints:Wi(i)}}function On(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[o("invalid_recovery_plan","Analytics recovery plan must be a structured object.")],warnings:t,repairHints:[{code:"invalid_recovery_plan",recommendedNextStep:"Return a typed recovery plan with operationIntent and plannedToolCalls."}]};e.version!==1&&i.push(o("invalid_version","Recovery plan version must be 1.","version")),e.kind!=="analytics_recovery_plan"&&i.push(o("invalid_recovery_plan_kind","Recovery plan kind must be analytics_recovery_plan.","kind"));const n=Xi(e.operationIntent);return i.push(...n.errors),t.push(...n.warnings),Array.isArray(e.plannedToolCalls)||i.push(o("invalid_planned_tool_calls","Recovery plan plannedToolCalls must be an array.","plannedToolCalls")),{ok:i.length===0,errors:i,warnings:t,repairHints:Wi(i)}}function Wi(e){return e.map(i=>({code:i.code,recommendedNextStep:i.code==="missing_obligations"?"Normalize the user request into one or more typed analytics obligations before recovery planning.":"Correct the operation/recovery contract shape before planning execution."}))}function Pn(e){return e.map(i=>{switch(i.code){case"missing_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Provide a semantic, physical, or SQL source before executing analytics."};case"missing_measure":return{code:i.code,fieldRole:"measure",recommendedNextStep:"Choose one exact measure from the grounded schema candidates."};case"missing_record_fields":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide at least one field for the records intent."};case"missing_matrix_rows":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Choose at least one row axis level for the matrix table."};case"missing_matrix_values":return{code:i.code,fieldRole:"measure",recommendedNextStep:"Choose at least one value field for the matrix table."};case"unsupported_matrix_sql_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use a semantic or explorer-backed source for matrix tables; raw SQL matrix tables are not supported."};case"missing_input_options_input_id":return{code:i.code,fieldRole:"input",recommendedNextStep:"Provide the inputId that these option values populate."};case"missing_input_options_label_field":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide the human-readable field used as option labels."};case"missing_input_options_value_field":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide the stable field used as option values."};case"missing_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Provide bounded read-only SQL with an explicit outer LIMIT."};case"conflicting_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Use one canonical SQL text location for the intent; prefer top-level sql."};case"missing_semantic_domain":case"missing_dataset_name":case"missing_connection_id":case"missing_table_name":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use grounded catalog metadata to fill the missing source reference."};default:return}}).filter(i=>!!i)}function Bn(e,i,t,n){if(!e||typeof e!="object"){t.push(o("invalid_view","Dashboard view must be an object.",i));return}if(f(e.title)||t.push(o("missing_view_title","Dashboard view needs a title.",i)),!e.presentation||typeof e.presentation!="object"){t.push(o("missing_presentation","Dashboard view needs a presentation.",`${i}.presentation`));return}if(e.presentation.kind==="text"){f(e.text)||n.push(o("missing_text_content","Text views should include text content.",`${i}.text`));return}if(!e.analytics){t.push(o("missing_view_analytics","Non-text dashboard views need analytics intent.",`${i}.analytics`));return}e.presentation.kind==="matrixTable"&&e.analytics.kind!=="matrix"&&t.push(o("invalid_matrix_view_analytics","Matrix table views need matrix analytics intent.",`${i}.analytics.kind`));const s=Ne(e.analytics);for(const r of s.errors)t.push(o(r.code,r.message,`${i}.analytics${r.path?`.${r.path}`:""}`));for(const r of s.warnings)n.push(o(r.code,r.message,`${i}.analytics${r.path?`.${r.path}`:""}`))}function Kn(e){const i=[],t=[];if(!e||typeof e!="object")return{ok:!1,errors:[o("invalid_dashboard_intent","Dashboard intent must be a structured object.")],warnings:t};e.version!==1&&i.push(o("invalid_version","Dashboard intent version must be 1.")),e.kind!=="dashboard"&&i.push(o("invalid_kind","Experience intent kind must be dashboard.")),f(e.title)||i.push(o("missing_title","Dashboard intent needs a title.","title"));const n=Array.isArray(e.inputs)?e.inputs:[],s=ye(n.filter(m).map(u=>u.id).filter(u=>typeof u=="string"));s&&i.push(o("duplicate_input_id",`Duplicate input id: ${s}.`,"inputs"));for(const[u,p]of n.entries()){const y=`inputs.${u}`;if(!m(p)){i.push(o("invalid_input","Dashboard input must be an object.",y));continue}f(p.id)||i.push(o("missing_input_id","Input needs an id.",`${y}.id`)),f(p.label)||i.push(o("missing_input_label","Input needs a label.",`${y}.label`)),!p.field||!f(p.field.name)?i.push(o("missing_input_field","Input needs a field.",`${y}.field`)):g(p.field,`${y}.field`,i)}const r=Array.isArray(e.sections)?e.sections:[];r.length===0&&i.push(o("missing_sections","Dashboard intent needs at least one section.","sections"));const l=r.flatMap(u=>u&&typeof u=="object"&&Array.isArray(u.views)?u.views.filter(m).map(p=>p.id).filter(p=>!!p):[]),d=ye(l);d&&i.push(o("duplicate_view_id",`Duplicate dashboard view id: ${d}.`,"sections"));for(const[u,p]of r.entries()){const y=`sections.${u}`;if(!p||typeof p!="object"){i.push(o("invalid_section","Dashboard section must be an object.",y));continue}if(f(p.title)||i.push(o("missing_section_title","Dashboard section needs a title.",y)),!Array.isArray(p.views)||p.views.length===0){i.push(o("missing_section_views","Dashboard section needs at least one view.",`${y}.views`));continue}for(const[A,v]of p.views.entries())Bn(v,`${y}.views.${A}`,i,t)}return{ok:i.length===0,errors:i,warnings:t}}exports.RAW_TEMPORAL_CONTRACT_ERROR_CODES=Ji;exports.SEMAPHOR_ANALYZE_RESULT_FIELD_CONTRACT=oi;exports.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_SCHEMA_VERSION=Y;exports.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_VALIDATOR_VERSION=rt;exports.SEMAPHOR_GENERATED_COUNT_METRIC_ID=it;exports.SEMAPHOR_MATRIX_TIME_GRAINS=ie;exports.SEMAPHOR_TIME_GRAINS=T;exports.TEMPORAL_BUCKET_CONTRACT_ERROR_CODES=et;exports.TEMPORAL_BUCKET_PATTERN_TOKENS=qi;exports.TEMPORAL_BUCKET_PRESETS=ai;exports.buildAnalyticsCatalogFieldSummary=Ka;exports.canonicalDashboardRecordsPayloadSchema=ma;exports.dashboardRecordsPayloadSchema=pa;exports.getAnalyticsCatalogFieldCandidates=Di;exports.getAnalyticsCatalogFieldName=ji;exports.hasCompleteSemaphorSourceIdentity=at;exports.isAnalyticsCatalogDateField=Te;exports.isAnalyticsCatalogDimensionField=Ba;exports.isAnalyticsCatalogMetricField=Ce;exports.isAnalyticsDateLikeDataType=Fi;exports.isAnalyticsMetricIdentifierField=he;exports.isAnalyticsTechnicalIdentifierField=Ee;exports.isSemaphorDataAppCodegenSummary=bt;exports.isSemaphorMatrixTimeGrain=ti;exports.isSemaphorTimeGrain=ii;exports.isTemporalBucketPreset=La;exports.isValidIanaTimeZone=si;exports.mergeSemaphorSourcesByIdentity=nt;exports.normalizeAnalyticsCatalogDataType=le;exports.normalizeAnalyticsCatalogName=re;exports.parseSemaphorIsoInstant=on;exports.parseSemaphorIsoTimeWindowBoundary=J;exports.preferSemaphorFieldRefMetadata=ot;exports.preferSemaphorSourceMetadata=ze;exports.rawTemporalValueMetadataSchema=bi;exports.resolveApplicableTemporalBucketFormat=Qa;exports.semaphorAnalyticsCoverageSchema=Re;exports.semaphorAnalyticsDiagnosticFeedbackSchema=Ie;exports.semaphorAnalyticsExecutionResultSchema=Mi;exports.semaphorAnalyticsPopulationSchema=xe;exports.semaphorAnalyticsResultSchema=xi;exports.semaphorAnalyticsValidationIssueSchema=X;exports.semaphorAnalyticsValidationResultSchema=Ae;exports.semaphorAnalyzeResultSchema=ja;exports.semaphorAnalyzeResultShape=Ti;exports.semaphorDataAppCodegenSummarySchema=Oa;exports.semaphorDerivedFieldDefinitionSchema=ke;exports.semaphorExecutionFieldRefSchema=oe;exports.semaphorFieldRefSchema=w;exports.semaphorFieldRefsMatch=ri;exports.semaphorInputOptionsResultSchema=ki;exports.semaphorMatrixResultSchema=Ii;exports.semaphorMetricAggregate=te;exports.semaphorMetricMeasureBindingKey=li;exports.semaphorMetricResultSchema=$i;exports.semaphorPhysicalSourceRefSchema=vi;exports.semaphorRecordsResultSchema=wi;exports.semaphorRelationshipDiagnosticsSchema=Ri;exports.semaphorResultColumnSchema=R;exports.semaphorSemanticSourceRefSchema=we;exports.semaphorSourceIdentityKey=U;exports.semaphorSourceRefSchema=x;exports.semaphorSourcesReferToSameDataset=ve;exports.semaphorSqlResultSchema=Ai;exports.semaphorSqlSourceRefSchema=zi;exports.semaphorTimeGrainSchema=hi;exports.temporalBucketDataTypeForGrain=ni;exports.temporalBucketFormatSchema=Q;exports.temporalBucketMetadataSchema=Z;exports.tokenizeTemporalBucketPattern=Pi;exports.validateSemaphorAnalyticsIntent=Ne;exports.validateSemaphorAnalyticsRecoveryPlan=On;exports.validateSemaphorDashboardIntent=Kn;exports.validateSemaphorDataAppCodegenSummary=Se;exports.validateSemaphorDerivedFieldDefinition=Zi;exports.validateSemaphorOperationIntent=Xi;exports.validateSemaphorResultCalculation=Nn;exports.validateTemporalBucketFormatApplicability=W;
|