react-semaphor 0.1.541 → 0.1.543

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.
Files changed (109) hide show
  1. package/dist/analytics-protocol/index.js +75 -75
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/brand-studio/index.js +3 -3
  4. package/dist/briefings/index.js +51 -49
  5. package/dist/chunks/apply-dashboard-operations-CG9S7MGt.js +2260 -0
  6. package/dist/chunks/{assistant-chat-D1fDZD6O.js → assistant-chat-BFMRUYoB.js} +12 -12
  7. package/dist/chunks/bookmark-state-CXw7lZ50.js +118 -0
  8. package/dist/chunks/{calendar-day-equality-Bpl15IBo.js → calendar-day-equality-BmJAWduY.js} +180 -207
  9. package/dist/chunks/comparison-window-caption-Bv18samq.js +1618 -0
  10. package/dist/chunks/custom-visual-inputs-DUtpYZOk.js +323 -0
  11. package/dist/chunks/{dashboard-B6IrON_Q.js → dashboard-B9mKTJoy.js} +1 -1
  12. package/dist/chunks/{dashboard-briefing-launcher-DwjFpewq.js → dashboard-briefing-launcher-Bdmry_oG.js} +18 -18
  13. package/dist/chunks/{dashboard-controls-C_BI28ME.js → dashboard-controls-UGpjOM2k.js} +69 -70
  14. package/dist/chunks/{dashboard-filter-value-compatibility-D95O4nd7.js → dashboard-filter-value-compatibility-CwQ_iSNb.js} +2 -2
  15. package/dist/chunks/{dashboard-json-DDY15Trn.js → dashboard-json-DG8dz0eX.js} +4 -4
  16. package/dist/chunks/{document-dashboard-inputs-DP_Op5mu.js → document-dashboard-inputs-OwqCbrVp.js} +2382 -4975
  17. package/dist/chunks/document-sheet-utils-BTb3VZxV.js +3619 -0
  18. package/dist/chunks/{edit-dashboard-visual-CH2dzWW-.js → edit-dashboard-visual-CDpA4y5e.js} +728 -728
  19. package/dist/chunks/{filter-value-text-BhWugPWE.js → filter-value-text-CYsVYPuD.js} +18 -19
  20. package/dist/chunks/{index-DaQlghLY.js → index-l5LclZvs.js} +824 -1351
  21. package/dist/chunks/{matrix-analytical-definition-bcprSe4u.js → matrix-analytical-definition-C7Gb0e12.js} +1 -1
  22. package/dist/chunks/{matrix-card-CJn1hB5V.js → matrix-card-DjwWcCo8.js} +2 -2
  23. package/dist/chunks/{matrix-formatter-DQ8avoIQ.js → matrix-formatter-BnsTX90d.js} +430 -417
  24. package/dist/chunks/{matrix-member-presentation-BNPSDKBG.js → matrix-member-presentation-CQGdVks6.js} +1 -1
  25. package/dist/chunks/{matrix-operation-contract-B8PBF1Gd.js → matrix-operation-contract-8OIO4gob.js} +65 -65
  26. package/dist/chunks/metric-comparison-DEwi9uc2.js +498 -0
  27. package/dist/chunks/numeric-presentation-F_-H6VAw.js +5227 -0
  28. package/dist/chunks/{pivot-header-presentation-MkcKnjn3.js → pivot-header-presentation-DHcx1XGQ.js} +1 -1
  29. package/dist/chunks/{pivot-result-identity-D6hhcRXi.js → pivot-result-identity-DJhXXcns.js} +1 -1
  30. package/dist/chunks/pivot-result-lifecycle-DupbRk-R.js +1155 -0
  31. package/dist/chunks/raw-temporal-presentation-D-azM_98.js +585 -0
  32. package/dist/chunks/{report-preferences-dialog-DpNkFfQO.js → report-preferences-dialog-CPwRwEJx.js} +75 -75
  33. package/dist/chunks/{report-runtime-context-B984Nq1E.js → report-runtime-context-Dq8XyODK.js} +1 -1
  34. package/dist/chunks/{saved-dashboard-context-CJ2WpoMF.js → saved-dashboard-context-BKvMfRfC.js} +233 -206
  35. package/dist/chunks/{selection-reducer-vKIb_jS6.js → selection-reducer-Dj_8xD69.js} +1 -1
  36. package/dist/chunks/{semaphor-ready-indicator-KT598QJq.js → semaphor-ready-indicator-CN2AHm2x.js} +37489 -39476
  37. package/dist/chunks/{shelf-drop-preview-context-BxV3Fl8h.js → shelf-drop-preview-context-BGl_rxcW.js} +6 -6
  38. package/dist/chunks/sort-target-MT1WK1vX.js +29 -0
  39. package/dist/chunks/{source-entity-resolution-CVA1a85c.js → source-entity-resolution-BYn9giz3.js} +1 -1
  40. package/dist/chunks/{switch-DWEWiv1J.js → switch-C3jLxlG0.js} +2 -2
  41. package/dist/chunks/table-export-sheet-BDRXLLdq.js +949 -0
  42. package/dist/chunks/table-settings-CLZocegs.js +501 -0
  43. package/dist/chunks/temporal-bucket-D7NBrrtL.js +2071 -0
  44. package/dist/chunks/{token-types-bxUxXDX2.js → token-types-DBbZVQsm.js} +1 -1
  45. package/dist/chunks/{use-create-flow-overlay-state-DdD12SMY.js → use-create-flow-overlay-state-BnclfB2k.js} +151 -151
  46. package/dist/chunks/{validators-Ej1DdCXa.js → validators-DMHTpf7a.js} +73 -73
  47. package/dist/dashboard/index.js +2 -2
  48. package/dist/dashboard-authoring/index.js +462 -457
  49. package/dist/data-app-sdk/index.js +5 -5
  50. package/dist/data-app-sdk-adapters/index.js +2 -2
  51. package/dist/data-app-sdk-validation/index.js +9 -9
  52. package/dist/format-utils/index.js +346 -241
  53. package/dist/index.js +174 -175
  54. package/dist/report-runtime-context/index.js +1 -1
  55. package/dist/surfboard/index.js +2 -2
  56. package/dist/types/briefings/attachment-outcomes.d.ts +1 -1
  57. package/dist/types/briefings/attachments.d.ts +17 -1
  58. package/dist/types/briefings/index.d.ts +5 -3
  59. package/dist/types/index.js +48 -48
  60. package/dist/types/lib/api/exports-api.d.ts +11 -65
  61. package/dist/types/lib/dashboard-inputs/control-contract-overrides.d.ts +17 -0
  62. package/dist/types/lib/dashboard-viewer/export-table-view.d.ts +2 -0
  63. package/dist/types/lib/hooks/use-dashboard.d.ts +3 -6
  64. package/dist/types/lib/matrix-table/matrix-delivery-policy.d.ts +8 -2
  65. package/dist/types/lib/matrix-table/matrix-delivery.d.ts +8 -6
  66. package/dist/types/lib/query-context/build-dashboard-card-query-contract.d.ts +50 -0
  67. package/dist/types/lib/types/explorer-types.d.ts +6 -0
  68. package/dist/types/shared/analytics-protocol/matrix-definition-contract.d.ts +3 -3
  69. package/dist/types/shared/assistant-context/index.d.ts +1 -1
  70. package/dist/types/shared/assistant-context/saved-dashboard-context.d.ts +23 -6
  71. package/dist/types/shared/dashboard-authoring/card-export-request.d.ts +173 -0
  72. package/dist/types/shared/dashboard-authoring/index.d.ts +1 -0
  73. package/dist/types/shared/dashboard-authoring/matrix-delivery.d.ts +4 -3
  74. package/dist/types/shared/format-utils/exporters/export-cells.d.ts +90 -0
  75. package/dist/types/shared/format-utils/exporters/export-file-format.d.ts +44 -0
  76. package/dist/types/shared/format-utils/exporters/index.d.ts +6 -0
  77. package/dist/types/shared/format-utils/exporters/xlsx-file.d.ts +90 -0
  78. package/dist/types/shared/format-utils/formatters/date-formatter.d.ts +8 -12
  79. package/dist/types/shared/format-utils/formatters/index.d.ts +1 -1
  80. package/dist/types/shared/format-utils/formatters/matrix-formatter.d.ts +2 -0
  81. package/dist/types/shared/format-utils/index.d.ts +2 -0
  82. package/dist/types/shared/format-utils/matrix-continuation.d.ts +55 -9
  83. package/dist/types/shared/format-utils/matrix-export-presentation.d.ts +21 -1
  84. package/dist/types/shared/format-utils/matrix-export-xlsx.d.ts +27 -0
  85. package/dist/types/shared/format-utils/presentation-execution.d.ts +27 -2
  86. package/dist/types/shared/format-utils/raw-temporal.d.ts +8 -0
  87. package/dist/types/shared/format-utils/table-export/index.d.ts +8 -0
  88. package/dist/types/shared/format-utils/table-export/prepare-table-export.d.ts +50 -0
  89. package/dist/types/shared/format-utils/table-export/table-export-formatting.d.ts +47 -0
  90. package/dist/types/shared/format-utils/table-export/table-export-raw-temporal.d.ts +40 -0
  91. package/dist/types/shared/format-utils/table-export/table-export-result.d.ts +31 -0
  92. package/dist/types/shared/format-utils/table-export/table-export-sheet.d.ts +38 -0
  93. package/dist/types/shared/format-utils/temporal-bucket.d.ts +9 -0
  94. package/package.json +2 -1
  95. package/dist/chunks/aggregate-table-row-presentation-B_vQjYR3.js +0 -996
  96. package/dist/chunks/apply-dashboard-operations-C-iahGka.js +0 -402
  97. package/dist/chunks/bookmark-state-k7y5SNGf.js +0 -331
  98. package/dist/chunks/calculated-field-identity-DcBS2NPP.js +0 -2161
  99. package/dist/chunks/canonical-result-keys-CEQefvdO.js +0 -33
  100. package/dist/chunks/common-types-CUf03Htv.js +0 -288
  101. package/dist/chunks/csv-utils-GUfKyT1J.js +0 -56
  102. package/dist/chunks/custom-visual-inputs-BrUOIwln.js +0 -3288
  103. package/dist/chunks/document-sheet-utils-C1eEldxs.js +0 -1076
  104. package/dist/chunks/matrix-definition-DQDI2okF.js +0 -206
  105. package/dist/chunks/metric-comparison-CojWeLqx.js +0 -392
  106. package/dist/chunks/pivot-result-lifecycle-8qCDmpKc.js +0 -804
  107. package/dist/chunks/raw-temporal-D61lr48Y.js +0 -1464
  108. package/dist/chunks/temporal-bucket-D8JF7zKz.js +0 -575
  109. package/dist/chunks/temporal-bucket-contract-DaOajRC7.js +0 -108
@@ -0,0 +1,1155 @@
1
+ var V = Object.defineProperty;
2
+ var X = (e, t, o) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
+ var p = (e, t, o) => X(e, typeof t != "symbol" ? t + "" : t, o);
4
+ import { N as z, O as q, P as y, q as Z, H as G, E as J, i as H } from "./temporal-bucket-D7NBrrtL.js";
5
+ import { z as d } from "zod";
6
+ import { aG as W, r as Q, a7 as ee, o as b, t as te } from "./validators-DMHTpf7a.js";
7
+ import { b as oe } from "./report-runtime-context-Dq8XyODK.js";
8
+ import { S as re } from "./analytics-base-schemas-BFAoRlkU.js";
9
+ import "./matrix-operation-contract-8OIO4gob.js";
10
+ import { r as ne, i as se } from "./metric-comparison-DEwi9uc2.js";
11
+ import { d as ie, P as ae } from "./pivot-result-identity-DJhXXcns.js";
12
+ function wt(e, t) {
13
+ const r = me(e);
14
+ let n;
15
+ if (r.date) {
16
+ const l = fe(r.date, 2);
17
+ n = ue(l.restDateString, l.year);
18
+ }
19
+ if (!n || isNaN(n.getTime()))
20
+ return /* @__PURE__ */ new Date(NaN);
21
+ const s = n.getTime();
22
+ let i = 0, a;
23
+ if (r.time && (i = pe(r.time), isNaN(i)))
24
+ return /* @__PURE__ */ new Date(NaN);
25
+ if (r.timezone) {
26
+ if (a = ye(r.timezone), isNaN(a))
27
+ return /* @__PURE__ */ new Date(NaN);
28
+ } else {
29
+ const l = new Date(s + i), m = /* @__PURE__ */ new Date(0);
30
+ return m.setFullYear(
31
+ l.getUTCFullYear(),
32
+ l.getUTCMonth(),
33
+ l.getUTCDate()
34
+ ), m.setHours(
35
+ l.getUTCHours(),
36
+ l.getUTCMinutes(),
37
+ l.getUTCSeconds(),
38
+ l.getUTCMilliseconds()
39
+ ), m;
40
+ }
41
+ return new Date(s + i + a);
42
+ }
43
+ const x = {
44
+ dateTimeDelimiter: /[T ]/,
45
+ timeZoneDelimiter: /[Z ]/i,
46
+ timezone: /([Z+-].*)$/
47
+ }, ce = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/, le = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/, de = /^([+-])(\d{2})(?::?(\d{2}))?$/;
48
+ function me(e) {
49
+ const t = {}, o = e.split(x.dateTimeDelimiter);
50
+ let r;
51
+ if (o.length > 2)
52
+ return t;
53
+ if (/:/.test(o[0]) ? r = o[0] : (t.date = o[0], r = o[1], x.timeZoneDelimiter.test(t.date) && (t.date = e.split(x.timeZoneDelimiter)[0], r = e.substr(
54
+ t.date.length,
55
+ e.length
56
+ ))), r) {
57
+ const n = x.timezone.exec(r);
58
+ n ? (t.time = r.replace(n[1], ""), t.timezone = n[1]) : t.time = r;
59
+ }
60
+ return t;
61
+ }
62
+ function fe(e, t) {
63
+ const o = new RegExp(
64
+ "^(?:(\\d{4}|[+-]\\d{" + (4 + t) + "})|(\\d{2}|[+-]\\d{" + (2 + t) + "})$)"
65
+ ), r = e.match(o);
66
+ if (!r) return { year: NaN, restDateString: "" };
67
+ const n = r[1] ? parseInt(r[1]) : null, s = r[2] ? parseInt(r[2]) : null;
68
+ return {
69
+ year: s === null ? n : s * 100,
70
+ restDateString: e.slice((r[1] || r[2]).length)
71
+ };
72
+ }
73
+ function ue(e, t) {
74
+ if (t === null) return /* @__PURE__ */ new Date(NaN);
75
+ const o = e.match(ce);
76
+ if (!o) return /* @__PURE__ */ new Date(NaN);
77
+ const r = !!o[4], n = v(o[1]), s = v(o[2]) - 1, i = v(o[3]), a = v(o[4]), l = v(o[5]) - 1;
78
+ if (r)
79
+ return be(t, a, l) ? he(t, a, l) : /* @__PURE__ */ new Date(NaN);
80
+ {
81
+ const m = /* @__PURE__ */ new Date(0);
82
+ return !ge(t, s, i) || !ve(t, n) ? /* @__PURE__ */ new Date(NaN) : (m.setUTCFullYear(t, s, Math.max(n, i)), m);
83
+ }
84
+ }
85
+ function v(e) {
86
+ return e ? parseInt(e) : 1;
87
+ }
88
+ function pe(e) {
89
+ const t = e.match(le);
90
+ if (!t) return NaN;
91
+ const o = _(t[1]), r = _(t[2]), n = _(t[3]);
92
+ return xe(o, r, n) ? o * z + r * q + n * 1e3 : NaN;
93
+ }
94
+ function _(e) {
95
+ return e && parseFloat(e.replace(",", ".")) || 0;
96
+ }
97
+ function ye(e) {
98
+ if (e === "Z") return 0;
99
+ const t = e.match(de);
100
+ if (!t) return 0;
101
+ const o = t[1] === "+" ? -1 : 1, r = parseInt(t[2]), n = t[3] && parseInt(t[3]) || 0;
102
+ return Ee(r, n) ? o * (r * z + n * q) : NaN;
103
+ }
104
+ function he(e, t, o) {
105
+ const r = /* @__PURE__ */ new Date(0);
106
+ r.setUTCFullYear(e, 0, 4);
107
+ const n = r.getUTCDay() || 7, s = (t - 1) * 7 + o + 1 - n;
108
+ return r.setUTCDate(r.getUTCDate() + s), r;
109
+ }
110
+ const we = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
111
+ function B(e) {
112
+ return e % 400 === 0 || e % 4 === 0 && e % 100 !== 0;
113
+ }
114
+ function ge(e, t, o) {
115
+ return t >= 0 && t <= 11 && o >= 1 && o <= (we[t] || (B(e) ? 29 : 28));
116
+ }
117
+ function ve(e, t) {
118
+ return t >= 1 && t <= (B(e) ? 366 : 365);
119
+ }
120
+ function be(e, t, o) {
121
+ return t >= 1 && t <= 53 && o >= 0 && o <= 6;
122
+ }
123
+ function xe(e, t, o) {
124
+ return e === 24 ? t === 0 && o === 0 : o >= 0 && o < 60 && t >= 0 && t < 60 && e >= 0 && e < 25;
125
+ }
126
+ function Ee(e, t) {
127
+ return t >= 0 && t <= 59;
128
+ }
129
+ const Ie = ["utf-8-bom", "utf-8"], Ce = "utf-8-bom", Re = [",", ";", " "], Se = `\r
130
+ `, Te = "text/csv; charset=utf-8";
131
+ function gt(e) {
132
+ return e == null || typeof e == "string" || typeof e == "number" ? e : typeof e == "object" ? JSON.stringify(e) : String(e);
133
+ }
134
+ const ke = "\uFEFF";
135
+ function K(e) {
136
+ return Ie.find((t) => t === e);
137
+ }
138
+ function vt(e) {
139
+ return Re.find((t) => t === e);
140
+ }
141
+ function bt(e) {
142
+ return K(e.requested) ?? K(e.dashboardDefault) ?? Ce;
143
+ }
144
+ function Ae(e) {
145
+ return e === "utf-8-bom" ? ke : "";
146
+ }
147
+ function xt(e) {
148
+ const t = e.trimStart().charAt(0);
149
+ return ["=", "+", "-", "@"].includes(t) || [" ", "\r", `
150
+ `].includes(e.charAt(0)) ? `'${e}` : e;
151
+ }
152
+ function _e(e, t = ",") {
153
+ if (e == null)
154
+ return "";
155
+ const o = String(e);
156
+ return o.includes(t) || o.includes('"') || o.includes(`
157
+ `) || o.includes("\r") ? `"${o.replace(/"/g, '""')}"` : o;
158
+ }
159
+ function L(e, t) {
160
+ return e.map((o) => _e(o, t)).join(t) + Se;
161
+ }
162
+ function $e(e, t) {
163
+ return e.map((o) => L(o, t)).join("");
164
+ }
165
+ function Et(e) {
166
+ return Ae(e.encoding) + (e.header ? L(e.header, e.delimiter) : "") + $e(e.rows, e.delimiter);
167
+ }
168
+ const T = ["csv", "xlsx"], Fe = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", F = {
169
+ csv: Object.freeze({
170
+ format: "csv",
171
+ extension: "csv",
172
+ contentType: Te,
173
+ partExtension: "csv",
174
+ partContentType: "text/csv",
175
+ compactedFileName: "export.csv.gz",
176
+ storedEncoding: "gzip",
177
+ storedValue: "CSV",
178
+ label: "CSV"
179
+ }),
180
+ xlsx: Object.freeze({
181
+ format: "xlsx",
182
+ extension: "xlsx",
183
+ contentType: Fe,
184
+ partExtension: "xml",
185
+ partContentType: "application/xml",
186
+ compactedFileName: "export.xlsx",
187
+ storedEncoding: "identity",
188
+ storedValue: "XLSX",
189
+ label: "Excel"
190
+ })
191
+ };
192
+ function It(e) {
193
+ return T.find((t) => t === e);
194
+ }
195
+ function Y(e) {
196
+ return { ...F[e] };
197
+ }
198
+ function Ct(e) {
199
+ return e === "XLSX" ? "xlsx" : "csv";
200
+ }
201
+ function j(e) {
202
+ return e.split(";")[0].trim().toLowerCase();
203
+ }
204
+ function Rt(e) {
205
+ if (!e) return;
206
+ const t = j(e);
207
+ return T.find(
208
+ (o) => j(F[o].contentType) === t
209
+ );
210
+ }
211
+ function St(e) {
212
+ var r;
213
+ const t = (((r = e.title) == null ? void 0 : r.trim()) || "export").replace(/[^a-z0-9]+/gi, "_").replace(/^_+|_+$/g, "") || "export", o = (e.at ?? /* @__PURE__ */ new Date()).toISOString().replace(/\.\d{3}Z$/, "Z").replace(/:/g, "-");
214
+ return `${t}-${o}.${F[e.format].extension}`;
215
+ }
216
+ const Me = 5 * 1024 * 1024, Tt = 64 * 1024 * 1024, C = d.number().int().positive().max(Number.MAX_SAFE_INTEGER), I = d.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER), R = I.refine((e) => e > 0), Ke = (e) => !!e && e !== "." && e !== ".." && !e.includes("/") && !e.includes("\\");
217
+ function w(e, t) {
218
+ const o = t.split("/");
219
+ if (o.length !== 5 || o[0] !== "exports" || o[1] !== e || o[2] !== "attempts" || !o.every(Ke))
220
+ throw new Error("Invalid Matrix export artifact namespace.");
221
+ return { attemptId: o[3], filename: o[4] };
222
+ }
223
+ function kt(e, t, o) {
224
+ const r = `exports/${e}/attempts/${t}/${o}`;
225
+ return w(e, r), r;
226
+ }
227
+ const At = d.object({
228
+ acquisition: d.literal("continuation"),
229
+ jobId: d.string().min(1),
230
+ sequence: R,
231
+ deadlineAt: C
232
+ }), je = [
233
+ "application/json",
234
+ ...T.map((e) => Y(e).partContentType)
235
+ ], Ne = d.object({
236
+ key: d.string(),
237
+ content: d.string(),
238
+ contentType: d.enum(je),
239
+ encoding: d.literal("gzip-base64").optional()
240
+ // Transport-only compression: JSON (layout, sheet layout) and Excel rows. CSV travels as it always has.
241
+ }).refine((e) => !e.encoding || e.contentType === "application/json" || e.contentType === Y("xlsx").partContentType, "Unsupported Matrix artifact encoding."), De = d.discriminatedUnion("kind", [
242
+ d.object({ kind: d.literal("work"), sequence: R, checkpointKey: d.string(), objects: d.array(Ne).min(2).max(4), deadlineAt: C }),
243
+ d.object({ kind: d.literal("committed"), sequence: R, done: d.boolean(), deadlineAt: C })
244
+ ]);
245
+ function Oe(e) {
246
+ const t = JSON.stringify(e);
247
+ if (t === void 0 || new TextEncoder().encode(t).byteLength > Me)
248
+ throw new RangeError("Matrix export batch exceeds its transport byte limit.");
249
+ }
250
+ function _t(e, t) {
251
+ const o = De.parse(e);
252
+ if (Oe(e), o.deadlineAt !== t.deadlineAt) throw new Error("Matrix deadline does not match the job.");
253
+ if (o.sequence !== t.sequence + (o.kind === "committed" ? 1 : 0))
254
+ throw new Error("Invalid Matrix batch sequence.");
255
+ if (o.kind === "work") {
256
+ w(t.jobId, o.checkpointKey);
257
+ for (const r of o.objects)
258
+ w(t.jobId, r.key);
259
+ }
260
+ return o;
261
+ }
262
+ const Ue = d.object({
263
+ acquisition: d.literal("continuation"),
264
+ deadlineAt: C,
265
+ chunks: d.array(d.object({ chunkNumber: R, dataKey: d.string() })).min(1),
266
+ totalRows: I,
267
+ totalBytes: I,
268
+ fileKey: d.string().min(1).optional(),
269
+ fileSize: I.optional(),
270
+ /** The file the job writes; absent means CSV (manifests from before Excel). */
271
+ format: d.enum(T).optional(),
272
+ /** Excel only: the sheet layout the layout batch stored, which compaction wraps the rows in. */
273
+ sheetKey: d.string().min(1).optional()
274
+ }).refine((e) => e.fileKey === void 0 == (e.fileSize === void 0), "Incomplete published Matrix artifact.").refine((e) => e.format === "xlsx" == (e.sheetKey !== void 0), "An Excel Matrix manifest names its sheet layout, and only it does.");
275
+ function $t(e, t, o) {
276
+ const r = Ue.parse(e);
277
+ if (r.deadlineAt !== o) throw new Error("Matrix deadline does not match the job.");
278
+ return r.chunks.forEach((n, s) => {
279
+ if (n.chunkNumber !== s + 1) throw new Error("Invalid committed Matrix chunk order.");
280
+ w(t, n.dataKey);
281
+ }), r.fileKey !== void 0 && w(t, r.fileKey), r.sheetKey !== void 0 && w(t, r.sheetKey), r;
282
+ }
283
+ function Ft(e, t) {
284
+ return t.levelLabels[e.id] ?? e.field.label ?? e.field.name;
285
+ }
286
+ function Mt(e, t) {
287
+ return t.measureLabels[e.id] ?? (e.kind === "aggregate" ? e.field.label ?? e.field.name : e.definition.label);
288
+ }
289
+ function Kt(e) {
290
+ return te.parse(Pe(e));
291
+ }
292
+ function Pe(e) {
293
+ const t = W.parse(e), o = (r) => ({
294
+ grand: { visible: !0, position: "after" },
295
+ levels: Object.fromEntries(
296
+ r.map((n) => [
297
+ n.id,
298
+ { visible: !0, position: "before" }
299
+ ])
300
+ )
301
+ });
302
+ return Q.parse({
303
+ version: 1,
304
+ spec: t,
305
+ presentation: {
306
+ layout: { kind: "compact" },
307
+ absence: { emptyText: "—", nullText: "" },
308
+ levelLabels: {},
309
+ measureLabels: {},
310
+ levelFormats: {},
311
+ measureFormats: {},
312
+ totals: { rows: o(t.rows), columns: o(t.columns) }
313
+ },
314
+ defaultView: {
315
+ rows: { depth: 0, overrides: [] },
316
+ columns: { depth: t.columns.length > 1 ? 1 : 0, overrides: [] }
317
+ }
318
+ });
319
+ }
320
+ function ze(e, t) {
321
+ const o = new Map(e.map((r) => [b(r), r]));
322
+ for (const r of t ?? []) o.set(b(r), r);
323
+ return [...o.values()];
324
+ }
325
+ function jt(e) {
326
+ const { spec: t, presentation: o, defaults: r, session: n } = ee.parse(e), s = new Map(
327
+ ze(t.sorts, n == null ? void 0 : n.sorts).map((a) => [b(a), a])
328
+ );
329
+ for (const a of ["rows", "columns"])
330
+ for (const l of t[a]) {
331
+ const m = {
332
+ axis: a,
333
+ levelId: l.id,
334
+ scope: { kind: "level" },
335
+ target: { kind: "member" },
336
+ direction: "asc",
337
+ nulls: "last"
338
+ };
339
+ s.has(b(m)) || s.set(b(m), m);
340
+ }
341
+ const i = (a, l) => ({
342
+ depth: Math.min(a.depth, Math.max(0, l - 1)),
343
+ // Leaf toggles are valid but have no effect. Collapsed ancestors retain dormant overrides.
344
+ overrides: a.overrides.filter(
345
+ (m) => m.path.length < l
346
+ )
347
+ });
348
+ return {
349
+ spec: { ...t, sorts: [...s.values()] },
350
+ presentation: o,
351
+ view: {
352
+ rows: i((n == null ? void 0 : n.rows) ?? r.rows, t.rows.length),
353
+ columns: i(
354
+ (n == null ? void 0 : n.columns) ?? r.columns,
355
+ t.columns.length
356
+ ),
357
+ sorts: (n == null ? void 0 : n.sorts) ?? []
358
+ }
359
+ };
360
+ }
361
+ class N extends Error {
362
+ constructor(o) {
363
+ super(
364
+ `invalid_presentation_execution_snapshot: ${o} Resave this report before running it again.`
365
+ );
366
+ p(this, "code", "invalid_presentation_execution_snapshot");
367
+ p(this, "deliveryBlocking", !0);
368
+ this.name = "PresentationExecutionSnapshotError";
369
+ }
370
+ }
371
+ class Nt extends Error {
372
+ constructor(o) {
373
+ super(
374
+ `missing_resolved_raw_temporal_format: Column "${o}" has no captured presentation. Resave this report before running it again.`
375
+ );
376
+ p(this, "code", "missing_resolved_raw_temporal_format");
377
+ p(this, "deliveryBlocking", !0);
378
+ this.name = "MissingResolvedRawTemporalFormatError";
379
+ }
380
+ }
381
+ function h(e, t, o) {
382
+ const r = new Set(t), n = Object.keys(e).find((s) => !r.has(s));
383
+ if (n)
384
+ throw new Error(`${o} contains unknown property "${n}"`);
385
+ }
386
+ function qe(e, t = "scope") {
387
+ if (!y(e))
388
+ throw new Error(`${t} must be an object`);
389
+ h(
390
+ e,
391
+ ["dashboardId", "cardId", "attachmentIndex"],
392
+ t
393
+ );
394
+ const o = typeof e.dashboardId == "string" ? e.dashboardId.trim() : "";
395
+ if (!o)
396
+ throw new Error(`${t}.dashboardId is required`);
397
+ const r = typeof e.cardId == "string" ? e.cardId.trim() : void 0;
398
+ if (e.cardId !== void 0 && !r)
399
+ throw new Error(`${t}.cardId must be a non-empty string`);
400
+ const n = e.attachmentIndex;
401
+ if (n !== void 0 && (typeof n != "number" || !Number.isInteger(n) || n < 0))
402
+ throw new Error(
403
+ `${t}.attachmentIndex must be a non-negative integer`
404
+ );
405
+ return {
406
+ dashboardId: o,
407
+ ...r ? { cardId: r } : {},
408
+ ...typeof n == "number" ? { attachmentIndex: n } : {}
409
+ };
410
+ }
411
+ function g(e, t, o, r) {
412
+ if (e.kind !== t) return;
413
+ h(e, ["kind", o], r);
414
+ const n = e[o];
415
+ if (typeof n != "string" || !n.trim())
416
+ throw new Error(`${r}.${o} is required`);
417
+ return n;
418
+ }
419
+ function $(e, t) {
420
+ if (!y(e))
421
+ throw new Error(`${t} must be an object`);
422
+ const o = g(e, "metric", "metricId", t);
423
+ if (o) return { kind: "metric", metricId: o };
424
+ const r = g(e, "column", "columnKey", t);
425
+ if (r) return { kind: "column", columnKey: r };
426
+ const n = g(
427
+ e,
428
+ "matrix_measure",
429
+ "measureId",
430
+ t
431
+ );
432
+ if (n) return { kind: "matrix_measure", measureId: n };
433
+ throw new Error(`${t} is not a valid numeric presentation target`);
434
+ }
435
+ const Be = [
436
+ "type",
437
+ "inputUnit",
438
+ "outputStyle",
439
+ "largestUnit",
440
+ "smallestUnit",
441
+ "maxUnits",
442
+ "prefix",
443
+ "suffix",
444
+ "negativeStyle"
445
+ ];
446
+ function Le(e) {
447
+ return e === "millisecond" || e === "second" || e === "minute" || e === "hour" || e === "day";
448
+ }
449
+ const Ye = ["type", "locale", "pattern", "timezone", "sourceTimezone"];
450
+ function Ve(e, t) {
451
+ if (h(e, Ye, t), typeof e.locale != "string" || !e.locale.trim())
452
+ throw new Error(`${t}.locale must be a non-empty string`);
453
+ for (const o of ["pattern", "timezone", "sourceTimezone"])
454
+ if (e[o] !== void 0 && typeof e[o] != "string")
455
+ throw new Error(`${t}.${o} must be a string`);
456
+ return {
457
+ type: "date",
458
+ locale: e.locale,
459
+ ...typeof e.pattern == "string" ? { pattern: e.pattern } : {},
460
+ ...typeof e.timezone == "string" ? { timezone: e.timezone } : {},
461
+ ...typeof e.sourceTimezone == "string" ? { sourceTimezone: e.sourceTimezone } : {}
462
+ };
463
+ }
464
+ function Xe(e, t) {
465
+ h(e, Be, t);
466
+ for (const s of ["inputUnit", "largestUnit", "smallestUnit"])
467
+ if (e[s] !== void 0 && !Le(e[s]))
468
+ throw new Error(`${t}.${s} must be a duration unit`);
469
+ const o = e.outputStyle;
470
+ if (o !== void 0 && o !== "compact" && o !== "digital" && o !== "long")
471
+ throw new Error(`${t}.outputStyle must be compact, digital, or long`);
472
+ const r = e.maxUnits;
473
+ if (r !== void 0 && (typeof r != "number" || !Number.isInteger(r) || r < 0 || r > 10))
474
+ throw new Error(`${t}.maxUnits must be an integer from 0 to 10`);
475
+ for (const s of ["prefix", "suffix"])
476
+ if (e[s] !== void 0 && typeof e[s] != "string")
477
+ throw new Error(`${t}.${s} must be a string`);
478
+ const n = e.negativeStyle;
479
+ if (n !== void 0 && n !== "minus" && n !== "parentheses")
480
+ throw new Error(`${t}.negativeStyle must be minus or parentheses`);
481
+ return {
482
+ type: "duration",
483
+ ...e.inputUnit !== void 0 ? { inputUnit: e.inputUnit } : {},
484
+ ...o !== void 0 ? { outputStyle: o } : {},
485
+ ...e.largestUnit !== void 0 ? { largestUnit: e.largestUnit } : {},
486
+ ...e.smallestUnit !== void 0 ? { smallestUnit: e.smallestUnit } : {},
487
+ ...r !== void 0 ? { maxUnits: r } : {},
488
+ ...e.prefix !== void 0 ? { prefix: e.prefix } : {},
489
+ ...e.suffix !== void 0 ? { suffix: e.suffix } : {},
490
+ ...n !== void 0 ? { negativeStyle: n } : {}
491
+ };
492
+ }
493
+ function Ze(e, t) {
494
+ if (!y(e))
495
+ throw new Error(`${t} must be an object`);
496
+ if (e.kind === "field") {
497
+ h(e, ["kind", "fieldId", "role"], t);
498
+ const n = typeof e.fieldId == "string" ? e.fieldId.trim() : "";
499
+ if (!n)
500
+ throw new Error(`${t}.fieldId is required`);
501
+ const s = e.role;
502
+ if (s !== void 0 && s !== "groupby" && s !== "pivotby")
503
+ throw new Error(`${t}.role must be groupby or pivotby`);
504
+ return {
505
+ kind: "field",
506
+ fieldId: n,
507
+ ...s ? { role: s } : {}
508
+ };
509
+ }
510
+ const o = g(e, "column", "columnKey", t);
511
+ if (o) return { kind: "column", columnKey: o };
512
+ const r = g(
513
+ e,
514
+ "matrix_axis",
515
+ "axisInstanceId",
516
+ t
517
+ );
518
+ if (r) return { kind: "matrix_axis", axisInstanceId: r };
519
+ throw new Error(`${t} is not a valid temporal bucket presentation target`);
520
+ }
521
+ function Ge(e, t) {
522
+ if (!y(e))
523
+ throw new Error(`${t} must be an object`);
524
+ const o = g(e, "column", "columnKey", t);
525
+ if (!o)
526
+ throw new Error(`${t} must identify a column`);
527
+ return { kind: "column", columnKey: o };
528
+ }
529
+ function Je(e) {
530
+ return [
531
+ e.dashboardId,
532
+ e.cardId ?? null,
533
+ e.attachmentIndex ?? null
534
+ ];
535
+ }
536
+ function S(e) {
537
+ switch (e.kind) {
538
+ case "metric":
539
+ return [e.kind, e.metricId];
540
+ case "column":
541
+ return [e.kind, e.columnKey];
542
+ case "matrix_measure":
543
+ return [e.kind, e.measureId];
544
+ case "field":
545
+ return [e.kind, e.fieldId, e.role ?? ""];
546
+ case "matrix_axis":
547
+ return [e.kind, e.axisInstanceId];
548
+ }
549
+ }
550
+ function k(e, t) {
551
+ return e.dashboardId === t.dashboardId && e.cardId === t.cardId && e.attachmentIndex === t.attachmentIndex;
552
+ }
553
+ function A(e, t) {
554
+ const o = S(e), r = S(t);
555
+ return o.length === r.length && o.every((n, s) => n === r[s]);
556
+ }
557
+ function He(e) {
558
+ if (!Array.isArray(e))
559
+ throw new Error("resolvedFormats must be an array");
560
+ const t = /* @__PURE__ */ new Set();
561
+ return e.map((o, r) => {
562
+ var l, m;
563
+ const n = `resolvedFormats.${r}`;
564
+ if (!y(o))
565
+ throw new Error(`${n} must be an object`);
566
+ h(o, ["scope", "target", "format"], n);
567
+ const s = qe(o.scope, `${n}.scope`);
568
+ if (!y(o.format))
569
+ throw new Error(`${n}.format must be an object`);
570
+ let i;
571
+ switch (o.format.type) {
572
+ case "temporal_bucket": {
573
+ const f = J(o.format);
574
+ if (!f.ok)
575
+ throw new Error(
576
+ `${n}.format is invalid: ${((l = f.issues[0]) == null ? void 0 : l.message) ?? "invalid value"}`
577
+ );
578
+ i = {
579
+ scope: s,
580
+ target: Ze(o.target, `${n}.target`),
581
+ format: f.value
582
+ };
583
+ break;
584
+ }
585
+ case "raw_temporal":
586
+ i = {
587
+ scope: s,
588
+ target: Ge(o.target, `${n}.target`),
589
+ format: G(o.format)
590
+ };
591
+ break;
592
+ case "number":
593
+ case "currency":
594
+ case "percent":
595
+ case "scientific": {
596
+ const f = Z(o.format);
597
+ if (!f.ok)
598
+ throw new Error(
599
+ `${n}.format is invalid: ${((m = f.issues[0]) == null ? void 0 : m.message) ?? "invalid value"}`
600
+ );
601
+ i = {
602
+ scope: s,
603
+ target: $(o.target, `${n}.target`),
604
+ format: f.value
605
+ };
606
+ break;
607
+ }
608
+ case "date": {
609
+ const f = $(o.target, `${n}.target`);
610
+ if (f.kind !== "column")
611
+ throw new Error(`${n}.target must identify a column for a date format`);
612
+ i = {
613
+ scope: s,
614
+ target: f,
615
+ format: Ve(o.format, `${n}.format`)
616
+ };
617
+ break;
618
+ }
619
+ case "duration":
620
+ i = {
621
+ scope: s,
622
+ target: $(o.target, `${n}.target`),
623
+ format: Xe(
624
+ o.format,
625
+ `${n}.format`
626
+ )
627
+ };
628
+ break;
629
+ default:
630
+ throw new Error(`${n}.format.type is unsupported`);
631
+ }
632
+ const a = JSON.stringify([
633
+ ...Je(i.scope),
634
+ ...S(i.target)
635
+ ]);
636
+ if (t.has(a))
637
+ throw new Error(
638
+ `${n} duplicates a scoped presentation target`
639
+ );
640
+ return t.add(a), i;
641
+ });
642
+ }
643
+ function We(e) {
644
+ try {
645
+ if (!y(e))
646
+ throw new Error("presentation execution snapshot must be an object");
647
+ if (h(
648
+ e,
649
+ ["version", "reportContext", "resolvedFormats"],
650
+ "presentation execution snapshot"
651
+ ), e.version !== 1)
652
+ throw new Error("presentation execution snapshot version must be 1");
653
+ const t = oe(e.reportContext);
654
+ if (!t.ok) {
655
+ const o = t.issues[0];
656
+ throw new Error(
657
+ `presentation execution snapshot reportContext is invalid: ${o != null && o.path && o.path !== "$" ? `${o.path}: ` : ""}${(o == null ? void 0 : o.message) ?? "invalid value"}`
658
+ );
659
+ }
660
+ return {
661
+ version: 1,
662
+ reportContext: t.value,
663
+ resolvedFormats: He(e.resolvedFormats)
664
+ };
665
+ } catch (t) {
666
+ throw t instanceof N ? t : new N(
667
+ t instanceof Error ? t.message : "Snapshot is invalid."
668
+ );
669
+ }
670
+ }
671
+ function Dt(e) {
672
+ return We({
673
+ version: 1,
674
+ reportContext: e.reportContext,
675
+ resolvedFormats: [...e.resolvedFormats]
676
+ });
677
+ }
678
+ function Ot(e) {
679
+ const t = Qe(e);
680
+ return H(t) ? t : void 0;
681
+ }
682
+ function Qe(e) {
683
+ const t = e.snapshot.resolvedFormats.find(
684
+ (o) => o.format.type !== "temporal_bucket" && o.format.type !== "raw_temporal" && o.format.type !== "date" && k(o.scope, e.scope) && A(o.target, e.target)
685
+ );
686
+ return t == null ? void 0 : t.format;
687
+ }
688
+ function Ut(e) {
689
+ const t = e.snapshot.resolvedFormats.find(
690
+ (o) => o.format.type === "date" && k(o.scope, e.scope) && A(o.target, e.target)
691
+ );
692
+ return t == null ? void 0 : t.format;
693
+ }
694
+ function Pt(e) {
695
+ const t = e.snapshot.resolvedFormats.find(
696
+ (o) => o.format.type === "raw_temporal" && k(o.scope, e.scope) && A(o.target, e.target)
697
+ );
698
+ return t == null ? void 0 : t.format;
699
+ }
700
+ function zt(e) {
701
+ const t = e.snapshot.resolvedFormats.find(
702
+ (o) => o.format.type === "temporal_bucket" && k(o.scope, e.scope) && A(o.target, e.target)
703
+ );
704
+ return t == null ? void 0 : t.format;
705
+ }
706
+ function qt(e) {
707
+ var n;
708
+ const t = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
709
+ if (e.snapshot.resolvedFormats.forEach((s, i) => {
710
+ if (s.scope.attachmentIndex !== void 0)
711
+ throw new Error(
712
+ `resolvedFormats.${i}.scope.attachmentIndex is not valid for a card export`
713
+ );
714
+ if (s.scope.dashboardId !== e.expectedScope.dashboardId || s.scope.cardId !== e.expectedScope.cardId)
715
+ throw new Error(
716
+ `resolvedFormats.${i}.scope must match the executing dashboard/card`
717
+ );
718
+ if (s.target.kind === "field" && s.format.type === "temporal_bucket") {
719
+ const a = JSON.stringify(S(s.target));
720
+ if (o.has(a))
721
+ throw new Error(
722
+ `resolvedFormats.${i} duplicates export field "${s.target.fieldId}"`
723
+ );
724
+ o.add(a);
725
+ return;
726
+ }
727
+ if (s.target.kind !== "column")
728
+ throw new Error(
729
+ `resolvedFormats.${i}.target must identify an export column or temporal pivot field`
730
+ );
731
+ if (t.has(s.target.columnKey))
732
+ throw new Error(
733
+ `resolvedFormats.${i} duplicates export column "${s.target.columnKey}"`
734
+ );
735
+ t.add(s.target.columnKey);
736
+ }), !e.useFormattedValues) return;
737
+ if (!((n = e.visibleColumns) != null && n.length))
738
+ throw new Error("visibleColumns must identify every formatted export column");
739
+ const r = e.visibleColumns.find(
740
+ (s) => !t.has(s)
741
+ );
742
+ if (r)
743
+ throw new Error(
744
+ `resolvedFormats is missing visible export column "${r}"`
745
+ );
746
+ }
747
+ function E(e) {
748
+ return Array.from(
749
+ new Set(
750
+ (e ?? []).flatMap(
751
+ (t) => typeof t.id == "string" && t.id ? [t.id] : []
752
+ )
753
+ )
754
+ );
755
+ }
756
+ function et(e) {
757
+ const t = /* @__PURE__ */ new Map();
758
+ return e.forEach((o) => {
759
+ o.id && t.set(o.id, (t.get(o.id) ?? 0) + 1);
760
+ }), e.flatMap(
761
+ (o) => o.id && (t.get(o.id) ?? 0) > 1 ? [ne(o)] : []
762
+ );
763
+ }
764
+ function Bt(e) {
765
+ const t = e.metricFields ?? [], o = E(t);
766
+ return {
767
+ expectedRoleFieldIds: {
768
+ groupby: E(e.groupByFields),
769
+ metric: o.length > 0 ? o : [re],
770
+ pivotby: E(e.pivotByFields),
771
+ detail: E(e.detailFields)
772
+ },
773
+ expectedMetricAliases: et(t)
774
+ };
775
+ }
776
+ class c extends Error {
777
+ constructor(o, r) {
778
+ super(`invalid_pivot_result_lifecycle: ${o}`);
779
+ p(this, "code", "invalid_pivot_result_lifecycle");
780
+ p(this, "deliveryBlocking", !0);
781
+ this.cause = r, this.name = "PivotResultLifecycleError";
782
+ }
783
+ }
784
+ function tt(e) {
785
+ if (!Array.isArray(e) || e.some(
786
+ (o) => !o || typeof o != "object" || Array.isArray(o) || typeof o.key != "string" || !o.key || typeof o.name != "string" || typeof o.label != "string"
787
+ ))
788
+ throw new c(
789
+ "Canonical pivot columns must be an array of keyed, named result descriptors."
790
+ );
791
+ const t = e;
792
+ if (new Set(t.map((o) => o.key)).size !== t.length)
793
+ throw new c(
794
+ "Canonical pivot column keys must be unique."
795
+ );
796
+ for (const o of t) {
797
+ const r = se(o, {
798
+ metadataRequired: !1
799
+ });
800
+ if (!r.ok)
801
+ throw new c(
802
+ `Canonical pivot column "${o.key}" has invalid temporal metadata: ${r.error.message}`
803
+ );
804
+ }
805
+ return t;
806
+ }
807
+ function D(e) {
808
+ if (!e || typeof e != "object" || Array.isArray(e) || e.version !== 1 || e.source !== "explorer" || !e.byRole || typeof e.byRole != "object" || Array.isArray(e.byRole))
809
+ throw new c(
810
+ "A loaded canonical pivot result requires its role-scoped column key map."
811
+ );
812
+ const t = e, o = /* @__PURE__ */ new Set(["groupby", "metric", "pivotby", "detail"]);
813
+ for (const [r, n] of Object.entries(t.byRole)) {
814
+ if (!o.has(r) || !n || typeof n != "object" || Array.isArray(n))
815
+ throw new c(
816
+ `Canonical pivot role map contains invalid "${r}" bindings.`
817
+ );
818
+ for (const [s, i] of Object.entries(n))
819
+ if (!s || !i || typeof i != "object" || Array.isArray(i) || i.role !== r || typeof i.rawKey != "string" || !i.rawKey || i.outputKey !== void 0 && (typeof i.outputKey != "string" || !i.outputKey))
820
+ throw new c(
821
+ `Canonical pivot role map contains an invalid "${r}:${s}" binding.`
822
+ );
823
+ }
824
+ if (t.byMetricAlias !== void 0) {
825
+ if (!t.byMetricAlias || typeof t.byMetricAlias != "object" || Array.isArray(t.byMetricAlias))
826
+ throw new c(
827
+ "Canonical pivot metric-alias bindings must be an object."
828
+ );
829
+ for (const [r, n] of Object.entries(
830
+ t.byMetricAlias
831
+ ))
832
+ if (!r || !n || typeof n != "object" || Array.isArray(n) || n.role !== "metric" || typeof n.rawKey != "string" || !n.rawKey || n.outputKey !== void 0 && (typeof n.outputKey != "string" || !n.outputKey))
833
+ throw new c(
834
+ `Canonical pivot metric-alias map contains an invalid "${r}" binding.`
835
+ );
836
+ }
837
+ return t;
838
+ }
839
+ function ot(e) {
840
+ if (e === void 0) return {};
841
+ if (!e || typeof e != "object" || Array.isArray(e))
842
+ throw new c(
843
+ "Canonical pivot column metadata must be an object."
844
+ );
845
+ for (const [t, o] of Object.entries(e)) {
846
+ if (!t || !o || typeof o != "object" || Array.isArray(o))
847
+ throw new c(
848
+ `Canonical pivot column metadata contains an invalid "${t}" classification.`
849
+ );
850
+ const { isSubtotal: r, subtotalScope: n } = o;
851
+ if (r !== void 0 && typeof r != "boolean" || n !== void 0 && n !== "base" && n !== "pivot-value" && n !== "grand-total" || r === !0 && n !== "pivot-value" && n !== "grand-total" || (n === "pivot-value" || n === "grand-total") && r !== !0 || n === "base" && r === !0)
852
+ throw new c(
853
+ `Canonical pivot column metadata contains an incoherent "${t}" subtotal classification.`
854
+ );
855
+ }
856
+ return e;
857
+ }
858
+ function O(e, t) {
859
+ if (!Array.isArray(e) || e.some((o) => typeof o != "string" || !o) || new Set(e).size !== e.length)
860
+ throw new c(
861
+ `Canonical pivot contract ${t} must be an array of unique field identities.`
862
+ );
863
+ return e;
864
+ }
865
+ function rt(e, t) {
866
+ if (!e || typeof e != "object" || Array.isArray(e) || e.version !== 1)
867
+ throw new c(
868
+ "A canonical pivot result requires its versioned result contract."
869
+ );
870
+ const o = e, r = o.expectedRoleFieldIds;
871
+ if (!r || typeof r != "object" || Array.isArray(r))
872
+ throw new c(
873
+ "Canonical pivot contract role identities must be an object."
874
+ );
875
+ const s = Object.fromEntries(
876
+ [
877
+ "groupby",
878
+ "metric",
879
+ "pivotby",
880
+ "detail"
881
+ ].map((u) => [
882
+ u,
883
+ O(
884
+ r[u],
885
+ `expectedRoleFieldIds.${u}`
886
+ )
887
+ ])
888
+ ), i = O(
889
+ o.expectedMetricAliases,
890
+ "expectedMetricAliases"
891
+ ), a = o.columnKinds;
892
+ if (!a || typeof a != "object" || Array.isArray(a))
893
+ throw new c(
894
+ "Canonical pivot contract column kinds must be an object."
895
+ );
896
+ const l = /* @__PURE__ */ new Set([
897
+ "row",
898
+ "pivot_metric",
899
+ "value"
900
+ ]), m = t.map((u) => u.key), f = Object.keys(a);
901
+ if (f.length !== m.length || f.some(
902
+ (u) => !m.includes(u) || !l.has(
903
+ a[u]
904
+ )
905
+ ))
906
+ throw new c(
907
+ "Canonical pivot contract must classify every authoritative result column exactly once."
908
+ );
909
+ const M = ot(
910
+ o.columnClassifications
911
+ );
912
+ if (Object.keys(M).some(
913
+ (u) => !m.includes(u)
914
+ ))
915
+ throw new c(
916
+ "Canonical pivot contract contains a classification for an unknown result column."
917
+ );
918
+ return {
919
+ version: 1,
920
+ expectedRoleFieldIds: s,
921
+ expectedMetricAliases: i,
922
+ columnKinds: a,
923
+ columnClassifications: M
924
+ };
925
+ }
926
+ function U(e, t) {
927
+ const o = [
928
+ "groupby",
929
+ "metric",
930
+ "pivotby",
931
+ "detail"
932
+ ];
933
+ for (const s of o) {
934
+ const i = new Set(t.expectedRoleFieldIds[s] ?? []), a = Object.keys(e.byRole[s] ?? {});
935
+ if (a.length !== i.size || a.some((l) => !i.has(l)))
936
+ throw new c(
937
+ `The role-scoped ${s} bindings do not match the authored result fields.`
938
+ );
939
+ }
940
+ const r = new Set(t.expectedMetricAliases), n = Object.keys(e.byMetricAlias ?? {});
941
+ if (n.length !== r.size || n.some((s) => !r.has(s)))
942
+ throw new c(
943
+ "The metric-alias bindings do not match the authored metric instances."
944
+ );
945
+ }
946
+ function nt(e) {
947
+ if (!Array.isArray(e) || e.some(
948
+ (t) => !t || typeof t != "object" || Array.isArray(t)
949
+ ))
950
+ throw new c(
951
+ "Canonical pivot records must be an array of row objects."
952
+ );
953
+ return e;
954
+ }
955
+ function st(e, t) {
956
+ e.forEach((o, r) => {
957
+ t.forEach((n) => {
958
+ if (!Object.prototype.hasOwnProperty.call(o, n.key) || o[n.key] === void 0)
959
+ throw new c(
960
+ `Canonical pivot column "${n.key}" is absent from row ${r}.`
961
+ );
962
+ });
963
+ });
964
+ }
965
+ function it(e, t, o) {
966
+ const r = new Set(t.map((n) => n.key));
967
+ ["groupby", "detail"].forEach((n) => {
968
+ Object.entries(e.byRole[n] ?? {}).forEach(
969
+ ([s, i]) => {
970
+ const a = i.outputKey || i.rawKey;
971
+ if (!r.has(a) || o.columnKinds[a] !== "row")
972
+ throw new c(
973
+ `The role-scoped ${n} binding for "${s}" does not name an authoritative result column.`
974
+ );
975
+ }
976
+ );
977
+ });
978
+ }
979
+ function P(e, t) {
980
+ t.forEach((o) => {
981
+ const r = e.columnKinds[o.key];
982
+ if (r === "pivot_metric" && o.pivotIdentity === void 0)
983
+ throw new c(
984
+ `Physical pivot result column "${o.key}" is missing its identity.`
985
+ );
986
+ if (r !== "pivot_metric" && o.pivotIdentity !== void 0)
987
+ throw new c(
988
+ `Canonical pivot result column "${o.key}" carries pivot identity outside the physical pivot projection.`
989
+ );
990
+ });
991
+ }
992
+ function at(e) {
993
+ const t = nt(e.records), o = tt(e.columns), r = rt(
994
+ e.pivotResultContract,
995
+ o
996
+ ), n = r.expectedRoleFieldIds.pivotby ?? [];
997
+ if (e.pivotResultState === "loaded_empty") {
998
+ if (t.length !== 0)
999
+ throw new c(
1000
+ "A loaded_empty pivot result cannot carry records."
1001
+ );
1002
+ if (o.some(
1003
+ (l) => r.columnKinds[l.key] === "pivot_metric"
1004
+ ))
1005
+ throw new c(
1006
+ "A loaded_empty pivot result cannot carry physical pivot columns."
1007
+ );
1008
+ P(r, o);
1009
+ const a = D(e.columnKeyMap);
1010
+ return U(a, r), {
1011
+ pivotResultState: "loaded_empty",
1012
+ records: [],
1013
+ columns: o,
1014
+ columnKeyMap: a,
1015
+ pivotResultContract: r
1016
+ };
1017
+ }
1018
+ if (e.pivotResultState !== "loaded_valid")
1019
+ throw new c(
1020
+ "A canonical pivot result must declare loaded_empty or loaded_valid."
1021
+ );
1022
+ if (t.length === 0)
1023
+ throw new c(
1024
+ "A loaded_valid pivot result must carry at least one record."
1025
+ );
1026
+ const s = D(e.columnKeyMap);
1027
+ U(s, r), it(s, o, r), P(r, o);
1028
+ const i = o.filter(
1029
+ (a) => r.columnKinds[a.key] === "pivot_metric"
1030
+ );
1031
+ if (n.length > 0 && i.length === 0)
1032
+ throw new c(
1033
+ "A loaded_valid pivot result is missing its physical pivot columns."
1034
+ );
1035
+ try {
1036
+ ie(i, {
1037
+ expectedPivotFieldIds: n,
1038
+ columnClassifications: r.columnClassifications
1039
+ });
1040
+ } catch (a) {
1041
+ throw a instanceof ae ? new c(a.message, a) : a;
1042
+ }
1043
+ return st(t, o), {
1044
+ pivotResultState: "loaded_valid",
1045
+ records: t,
1046
+ columns: o,
1047
+ columnKeyMap: s,
1048
+ pivotResultContract: r
1049
+ };
1050
+ }
1051
+ function Lt(e) {
1052
+ const t = /* @__PURE__ */ new Set();
1053
+ ["groupby", "detail"].forEach((s) => {
1054
+ Object.values(e.columnKeyMap.byRole[s] ?? {}).forEach((i) => {
1055
+ t.add(i.outputKey || i.rawKey);
1056
+ });
1057
+ });
1058
+ const o = new Set(e.physicalPivotColumnKeys), r = new Set(
1059
+ e.columns.map((s) => s.key)
1060
+ ), n = {
1061
+ version: 1,
1062
+ expectedRoleFieldIds: {
1063
+ groupby: Array.from(
1064
+ new Set(e.expectedRoleFieldIds.groupby ?? [])
1065
+ ),
1066
+ metric: Array.from(
1067
+ new Set(e.expectedRoleFieldIds.metric ?? [])
1068
+ ),
1069
+ pivotby: Array.from(
1070
+ new Set(e.expectedRoleFieldIds.pivotby ?? [])
1071
+ ),
1072
+ detail: Array.from(
1073
+ new Set(e.expectedRoleFieldIds.detail ?? [])
1074
+ )
1075
+ },
1076
+ expectedMetricAliases: [...e.expectedMetricAliases ?? []],
1077
+ columnKinds: Object.fromEntries(
1078
+ e.columns.map((s) => [
1079
+ s.key,
1080
+ t.has(s.key) ? "row" : o.has(s.key) ? "pivot_metric" : "value"
1081
+ ])
1082
+ ),
1083
+ columnClassifications: Object.fromEntries(
1084
+ Object.entries(e.columnMetadata ?? {}).filter(
1085
+ ([s]) => r.has(s)
1086
+ )
1087
+ )
1088
+ };
1089
+ return at({
1090
+ pivotResultState: e.records.length === 0 ? "loaded_empty" : "loaded_valid",
1091
+ pivotResultContract: n,
1092
+ records: e.records,
1093
+ columns: e.columns,
1094
+ columnKeyMap: e.columnKeyMap
1095
+ });
1096
+ }
1097
+ export {
1098
+ Pe as $,
1099
+ De as A,
1100
+ Oe as B,
1101
+ Ie as C,
1102
+ Ce as D,
1103
+ T as E,
1104
+ _t as F,
1105
+ Ue as G,
1106
+ $t as H,
1107
+ qe as I,
1108
+ He as J,
1109
+ We as K,
1110
+ Dt as L,
1111
+ Nt as M,
1112
+ Ot as N,
1113
+ Ut as O,
1114
+ N as P,
1115
+ zt as Q,
1116
+ qt as R,
1117
+ et as S,
1118
+ Bt as T,
1119
+ c as U,
1120
+ at as V,
1121
+ Lt as W,
1122
+ Fe as X,
1123
+ Ft as Y,
1124
+ Mt as Z,
1125
+ Kt as _,
1126
+ Qe as a,
1127
+ ze as a0,
1128
+ jt as a1,
1129
+ wt as a2,
1130
+ Re as b,
1131
+ L as c,
1132
+ Se as d,
1133
+ Te as e,
1134
+ Pt as f,
1135
+ vt as g,
1136
+ Ae as h,
1137
+ _e as i,
1138
+ xt as j,
1139
+ $e as k,
1140
+ Et as l,
1141
+ It as m,
1142
+ Y as n,
1143
+ Ct as o,
1144
+ K as p,
1145
+ Rt as q,
1146
+ bt as r,
1147
+ St as s,
1148
+ gt as t,
1149
+ Me as u,
1150
+ Tt as v,
1151
+ C as w,
1152
+ w as x,
1153
+ kt as y,
1154
+ At as z
1155
+ };