react-semaphor 0.1.555 → 0.1.557

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 (114) hide show
  1. package/DATA_APP_SDK.md +6 -29
  2. package/dist/analytics-protocol/index.js +20 -21
  3. package/dist/assistant-context/index.js +1 -1
  4. package/dist/assistant-protocol/index.js +5 -5
  5. package/dist/brand-studio/index.js +426 -444
  6. package/dist/briefings/index.js +56 -57
  7. package/dist/chunks/{analytics-base-schemas-BKs3flFS.js → analytics-base-schemas-BUFUoO6G.js} +2 -2
  8. package/dist/chunks/{assistant-chat-8NZP6m-u.js → assistant-chat-WMTpYirZ.js} +79 -81
  9. package/dist/chunks/{bookmark-state-BAeGKd3s.js → bookmark-state-PjQpxbG7.js} +3 -3
  10. package/dist/chunks/{braces-o9UiRQes.js → braces-BOErQVyi.js} +1 -1
  11. package/dist/chunks/comparison-window-caption-Dc7BaCMz.js +1218 -0
  12. package/dist/chunks/{context-BerEBuFR.js → context-DVy4HOU0.js} +1 -1
  13. package/dist/chunks/{custom-visual-inputs-Gw-Ggg3O.js → custom-visual-inputs-CxYI-gFa.js} +31 -33
  14. package/dist/chunks/{dashboard-Ds68ckO3.js → dashboard-4D8Vy4pL.js} +1 -1
  15. package/dist/chunks/{dashboard-briefing-launcher-DlTr-VGc.js → dashboard-briefing-launcher-C4EmOfxs.js} +149 -151
  16. package/dist/chunks/{dashboard-controls-oNXJZN6x.js → dashboard-controls-DBWykmvL.js} +171 -173
  17. package/dist/chunks/{dashboard-json-CW7Q_efH.js → dashboard-json-DiX-p0F7.js} +21 -22
  18. package/dist/chunks/{document-dashboard-inputs-C21mL3ib.js → document-dashboard-inputs-DP5hquBR.js} +32 -32
  19. package/dist/chunks/{edit-dashboard-visual-BnnT_oKR.js → edit-dashboard-visual-n1jLV_7V.js} +5842 -5955
  20. package/dist/chunks/{filter-reach-copy-DlNPHbE-.js → filter-reach-copy-BB9iakLA.js} +915 -986
  21. package/dist/chunks/{filter-value-text-DMrpj4h9.js → filter-value-text-CUBpotVN.js} +5 -5
  22. package/dist/chunks/{global-date-filter-utils-7OboTgrM.js → global-date-filter-utils-Cc5tqkoW.js} +2908 -3112
  23. package/dist/chunks/{index-B2k6KtUN.js → index-CgjhzkKM.js} +72 -80
  24. package/dist/chunks/{index-CtoK1Lgu.js → index-dIV-Gdsb.js} +159 -161
  25. package/dist/chunks/{layout-grid-Bgzth8vd.js → layout-grid-CcNklCwL.js} +1 -1
  26. package/dist/chunks/{list-filter-DsaTbM3J.js → list-filter-Ds_4UTpD.js} +1 -1
  27. package/dist/chunks/{matrix-analytical-definition-DPVGg1mU.js → matrix-analytical-definition-4GTUDheD.js} +22 -22
  28. package/dist/chunks/{matrix-card-D9bsdAye.js → matrix-card-fS_4O7zA.js} +3 -3
  29. package/dist/chunks/{matrix-member-presentation-DRWcJ8Mi.js → matrix-member-presentation-Dj7HaAHC.js} +1 -1
  30. package/dist/chunks/{matrix-operation-contract--lMaLlpV.js → matrix-operation-contract-CpgLZ7E5.js} +52 -52
  31. package/dist/chunks/{metric-comparison-CYIt2F5X.js → metric-comparison-C8LY7GG5.js} +4 -4
  32. package/dist/chunks/{model-change-B0rAK-5w.js → model-change-CJEj3ZD6.js} +1 -1
  33. package/dist/chunks/{palette-D10o_yYX.js → palette-DMkIhagj.js} +1 -1
  34. package/dist/chunks/{matrix-formatter-K2OVPJQI.js → pivot-result-contract-expectations-DMk-mKhG.js} +451 -402
  35. package/dist/chunks/pivot-result-identity-CrQ54Xbj.js +77 -0
  36. package/dist/chunks/{raw-temporal-presentation-CivONfcO.js → raw-temporal-presentation-DdEpgPRB.js} +25 -26
  37. package/dist/chunks/report-preferences-dialog-CFg5VFLk.js +2109 -0
  38. package/dist/chunks/{report-runtime-context-BaIKSaja.js → report-runtime-context-CohdtiMg.js} +2 -2
  39. package/dist/chunks/{resolve-dashboard-input-context-CIm9A8_j.js → resolve-dashboard-input-context-Djl3kCFL.js} +1396 -1550
  40. package/dist/chunks/{save-CfJpQQ68.js → save-D1EpMcwT.js} +1 -1
  41. package/dist/chunks/{saved-dashboard-context-akb9JfOL.js → saved-dashboard-context-umlQFevH.js} +9 -9
  42. package/dist/chunks/selection-reducer-_d6aKJnj.js +46 -0
  43. package/dist/chunks/{semaphor-ready-indicator-Ba7dwP5_.js → semaphor-ready-indicator-4cOp6sla.js} +54479 -63899
  44. package/dist/chunks/{shelf-drop-preview-context-5rg3pJHW.js → shelf-drop-preview-context-DAtRuvR7.js} +7 -7
  45. package/dist/chunks/{source-entity-resolution-CGymm5td.js → source-entity-resolution-DXW1HpKf.js} +1 -1
  46. package/dist/chunks/{switch-B-UTI6v-.js → switch-9CJt5EF_.js} +1431 -1342
  47. package/dist/chunks/{table-export-sheet-CgO6gaSM.js → table-export-sheet-CTCTA_bd.js} +1 -1
  48. package/dist/chunks/{table-settings-DOT_Bv1m.js → table-settings-DF1gdVQR.js} +3 -3
  49. package/dist/chunks/temporal-input-presentation-DoSniQj1.js +2939 -0
  50. package/dist/chunks/{token-types-DYECHYGH.js → token-types-DFyLflLY.js} +1 -1
  51. package/dist/chunks/{upload-BFX7apKV.js → upload-LSNKpt0w.js} +1 -1
  52. package/dist/chunks/{use-create-flow-overlay-state-BHNs0wl7.js → use-create-flow-overlay-state-esyMT9vU.js} +125 -127
  53. package/dist/chunks/{validators-ClKLGDGZ.js → validators-hmfNNQz8.js} +305 -307
  54. package/dist/chunks/zoned-wall-clock-E35Frf9v.js +191 -0
  55. package/dist/dashboard/index.js +2 -2
  56. package/dist/dashboard-authoring/index.js +168 -169
  57. package/dist/data-app-sdk/index.js +789 -4154
  58. package/dist/data-app-sdk-adapters/index.js +3 -3
  59. package/dist/data-app-sdk-validation/index.js +6 -6
  60. package/dist/format-utils/index.js +234 -253
  61. package/dist/index.js +233 -235
  62. package/dist/layouts/index.js +1 -1
  63. package/dist/pdf-export-policy/index.js +9 -11
  64. package/dist/report-runtime-context/index.js +2 -2
  65. package/dist/style.css +1 -1
  66. package/dist/surfboard/index.js +2 -2
  67. package/dist/types/brand-studio/brand-studio-draft.d.ts +0 -3
  68. package/dist/types/brand-studio/index.d.ts +1 -1
  69. package/dist/types/components/visual/data-table/types/data-table.d.ts +0 -1
  70. package/dist/types/components/visual/shared/utils/table-column-order.d.ts +0 -6
  71. package/dist/types/data-app-sdk/contracts.d.ts +0 -146
  72. package/dist/types/data-app-sdk/index.d.ts +0 -2
  73. package/dist/types/index.js +27 -28
  74. package/dist/types/lib/api/exports-api.d.ts +1 -1
  75. package/dist/types/lib/charts/table-chart-types.d.ts +1 -1
  76. package/dist/types/lib/charts/types.d.ts +2 -2
  77. package/dist/types/lib/dashboard-viewer/export-table-view.d.ts +0 -3
  78. package/dist/types/lib/document/document-edits.d.ts +1 -1
  79. package/dist/types/lib/document/document-section-kinds.d.ts +2 -4
  80. package/dist/types/lib/document/document-table-data-policy.d.ts +1 -2
  81. package/dist/types/lib/formatters/grouped-temporal-activation.d.ts +3 -3
  82. package/dist/types/lib/formatters/grouped-temporal-presentation.d.ts +0 -6
  83. package/dist/types/lib/query-context/card-server-request.d.ts +0 -1
  84. package/dist/types/lib/table-formatting/table-formatting-types.d.ts +1 -1
  85. package/dist/types/lib/types/common-types.d.ts +0 -7
  86. package/dist/types/lib/types/explorer-types.d.ts +1 -14
  87. package/dist/types/lib/utils/card-config-utils.d.ts +11 -1
  88. package/dist/types/shared/dashboard-authoring/card-export-request.d.ts +1 -2
  89. package/dist/types/shared/dashboard-authoring/filter-model/filter-definitions.d.ts +1 -7
  90. package/dist/types/shared/dashboard-authoring/legacy-table-routing.d.ts +9 -4
  91. package/dist/types/shared/format-utils/grouped-table-presentation.d.ts +0 -14
  92. package/dist/types/shared/format-utils/index.d.ts +0 -2
  93. package/dist/types/shared/format-utils/pdf-export-policy.d.ts +1 -1
  94. package/dist/types/shared/format-utils/pivot-result-contract-expectations.d.ts +2 -20
  95. package/dist/types/shared/format-utils/pivot-result-identity.d.ts +0 -20
  96. package/dist/types/shared/format-utils/table-export/prepare-table-export.d.ts +0 -1
  97. package/dist/types/shared/format-utils/table-export/table-export-result.d.ts +0 -4
  98. package/package.json +2 -4
  99. package/src/data-app-sdk/README.md +7 -31
  100. package/dist/chunks/comparison-window-caption-C2WNTlxK.js +0 -1433
  101. package/dist/chunks/pivot-header-presentation-CX4fkRuG.js +0 -42
  102. package/dist/chunks/pivot-result-identity-BHJGZwIc.js +0 -94
  103. package/dist/chunks/pivot-result-lifecycle-BygCpOhk.js +0 -1238
  104. package/dist/chunks/raw-temporal-contract-WuXA8jBP.js +0 -64
  105. package/dist/chunks/report-preferences-dialog-D_KyuEFx.js +0 -2261
  106. package/dist/chunks/selection-reducer-yw_JgICP.js +0 -111
  107. package/dist/chunks/temporal-bucket-C4rqmwaQ.js +0 -2071
  108. package/dist/chunks/x-4f5U2XwU.js +0 -100
  109. package/dist/chunks/zoned-wall-clock-MulfA26h.js +0 -129
  110. package/dist/types/components/visual/pivot-table/types.d.ts +0 -80
  111. package/dist/types/data-app-sdk/devtools/index.d.ts +0 -49
  112. package/dist/types/data-app-sdk/devtools.d.ts +0 -1
  113. package/dist/types/shared/format-utils/aggregate-table-row-presentation.d.ts +0 -85
  114. package/dist/types/shared/format-utils/pivot-result-lifecycle.d.ts +0 -55
@@ -1,1238 +0,0 @@
1
- var G = Object.defineProperty;
2
- var Q = (e, t, o) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
- var h = (e, t, o) => Q(e, typeof t != "symbol" ? t + "" : t, o);
4
- import { N as q, O as L, P as y, q as ee, H as te, E as oe, i as re, Q as K, f as ne, F as ae, r as ie, M as se, v as ce } from "./temporal-bucket-C4rqmwaQ.js";
5
- import { z as d } from "zod";
6
- import { E as B, l as Y } from "./export-file-format-C-tJsxsf.js";
7
- import { aN as le, l as de, Y as me, Q as T, o as ue } from "./validators-ClKLGDGZ.js";
8
- import { b as fe } from "./report-runtime-context-BaIKSaja.js";
9
- import { DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES as pe } from "../value-format-preferences/index.js";
10
- import { z as ye } from "./zoned-wall-clock-MulfA26h.js";
11
- import { S as he } from "./analytics-base-schemas-BKs3flFS.js";
12
- import "./matrix-operation-contract--lMaLlpV.js";
13
- import { r as we, i as ge } from "./metric-comparison-CYIt2F5X.js";
14
- import { d as ve, P as be } from "./pivot-result-identity-BHJGZwIc.js";
15
- function Ot(e, t) {
16
- const r = Ie(e);
17
- let n;
18
- if (r.date) {
19
- const c = Se(r.date, 2);
20
- n = Ee(c.restDateString, c.year);
21
- }
22
- if (!n || isNaN(n.getTime()))
23
- return /* @__PURE__ */ new Date(NaN);
24
- const a = n.getTime();
25
- let i = 0, s;
26
- if (r.time && (i = Re(r.time), isNaN(i)))
27
- return /* @__PURE__ */ new Date(NaN);
28
- if (r.timezone) {
29
- if (s = Ae(r.timezone), isNaN(s))
30
- return /* @__PURE__ */ new Date(NaN);
31
- } else {
32
- const c = new Date(a + i), m = /* @__PURE__ */ new Date(0);
33
- return m.setFullYear(
34
- c.getUTCFullYear(),
35
- c.getUTCMonth(),
36
- c.getUTCDate()
37
- ), m.setHours(
38
- c.getUTCHours(),
39
- c.getUTCMinutes(),
40
- c.getUTCSeconds(),
41
- c.getUTCMilliseconds()
42
- ), m;
43
- }
44
- return new Date(a + i + s);
45
- }
46
- const k = {
47
- dateTimeDelimiter: /[T ]/,
48
- timeZoneDelimiter: /[Z ]/i,
49
- timezone: /([Z+-].*)$/
50
- }, xe = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/, Te = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/, ke = /^([+-])(\d{2})(?::?(\d{2}))?$/;
51
- function Ie(e) {
52
- const t = {}, o = e.split(k.dateTimeDelimiter);
53
- let r;
54
- if (o.length > 2)
55
- return t;
56
- if (/:/.test(o[0]) ? r = o[0] : (t.date = o[0], r = o[1], k.timeZoneDelimiter.test(t.date) && (t.date = e.split(k.timeZoneDelimiter)[0], r = e.substr(
57
- t.date.length,
58
- e.length
59
- ))), r) {
60
- const n = k.timezone.exec(r);
61
- n ? (t.time = r.replace(n[1], ""), t.timezone = n[1]) : t.time = r;
62
- }
63
- return t;
64
- }
65
- function Se(e, t) {
66
- const o = new RegExp(
67
- "^(?:(\\d{4}|[+-]\\d{" + (4 + t) + "})|(\\d{2}|[+-]\\d{" + (2 + t) + "})$)"
68
- ), r = e.match(o);
69
- if (!r) return { year: NaN, restDateString: "" };
70
- const n = r[1] ? parseInt(r[1]) : null, a = r[2] ? parseInt(r[2]) : null;
71
- return {
72
- year: a === null ? n : a * 100,
73
- restDateString: e.slice((r[1] || r[2]).length)
74
- };
75
- }
76
- function Ee(e, t) {
77
- if (t === null) return /* @__PURE__ */ new Date(NaN);
78
- const o = e.match(xe);
79
- if (!o) return /* @__PURE__ */ new Date(NaN);
80
- const r = !!o[4], n = x(o[1]), a = x(o[2]) - 1, i = x(o[3]), s = x(o[4]), c = x(o[5]) - 1;
81
- if (r)
82
- return Fe(t, s, c) ? Ce(t, s, c) : /* @__PURE__ */ new Date(NaN);
83
- {
84
- const m = /* @__PURE__ */ new Date(0);
85
- return !$e(t, a, i) || !Me(t, n) ? /* @__PURE__ */ new Date(NaN) : (m.setUTCFullYear(t, a, Math.max(n, i)), m);
86
- }
87
- }
88
- function x(e) {
89
- return e ? parseInt(e) : 1;
90
- }
91
- function Re(e) {
92
- const t = e.match(Te);
93
- if (!t) return NaN;
94
- const o = M(t[1]), r = M(t[2]), n = M(t[3]);
95
- return De(o, r, n) ? o * q + r * L + n * 1e3 : NaN;
96
- }
97
- function M(e) {
98
- return e && parseFloat(e.replace(",", ".")) || 0;
99
- }
100
- function Ae(e) {
101
- if (e === "Z") return 0;
102
- const t = e.match(ke);
103
- if (!t) return 0;
104
- const o = t[1] === "+" ? -1 : 1, r = parseInt(t[2]), n = t[3] && parseInt(t[3]) || 0;
105
- return Ke(r, n) ? o * (r * q + n * L) : NaN;
106
- }
107
- function Ce(e, t, o) {
108
- const r = /* @__PURE__ */ new Date(0);
109
- r.setUTCFullYear(e, 0, 4);
110
- const n = r.getUTCDay() || 7, a = (t - 1) * 7 + o + 1 - n;
111
- return r.setUTCDate(r.getUTCDate() + a), r;
112
- }
113
- const _e = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
114
- function Z(e) {
115
- return e % 400 === 0 || e % 4 === 0 && e % 100 !== 0;
116
- }
117
- function $e(e, t, o) {
118
- return t >= 0 && t <= 11 && o >= 1 && o <= (_e[t] || (Z(e) ? 29 : 28));
119
- }
120
- function Me(e, t) {
121
- return t >= 1 && t <= (Z(e) ? 366 : 365);
122
- }
123
- function Fe(e, t, o) {
124
- return t >= 1 && t <= 53 && o >= 0 && o <= 6;
125
- }
126
- function De(e, t, o) {
127
- return e === 24 ? t === 0 && o === 0 : o >= 0 && o < 60 && t >= 0 && t < 60 && e >= 0 && e < 25;
128
- }
129
- function Ke(e, t) {
130
- return t >= 0 && t <= 59;
131
- }
132
- const je = 5 * 1024 * 1024, Pt = 64 * 1024 * 1024, R = d.number().int().positive().max(Number.MAX_SAFE_INTEGER), S = d.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER), A = S.refine((e) => e > 0), Ne = (e) => !!e && e !== "." && e !== ".." && !e.includes("/") && !e.includes("\\");
133
- function v(e, t) {
134
- const o = t.split("/");
135
- if (o.length !== 5 || o[0] !== "exports" || o[1] !== e || o[2] !== "attempts" || !o.every(Ne))
136
- throw new Error("Invalid Matrix export artifact namespace.");
137
- return { attemptId: o[3], filename: o[4] };
138
- }
139
- function zt(e, t, o) {
140
- const r = `exports/${e}/attempts/${t}/${o}`;
141
- return v(e, r), r;
142
- }
143
- const qt = d.object({
144
- acquisition: d.literal("continuation"),
145
- jobId: d.string().min(1),
146
- sequence: A,
147
- deadlineAt: R
148
- }), Ue = [
149
- "application/json",
150
- ...B.map((e) => Y(e).partContentType)
151
- ], Oe = d.object({
152
- key: d.string(),
153
- content: d.string(),
154
- contentType: d.enum(Ue),
155
- encoding: d.literal("gzip-base64").optional()
156
- // Transport-only compression: JSON (layout, sheet layout) and Excel rows. CSV travels as it always has.
157
- }).refine((e) => !e.encoding || e.contentType === "application/json" || e.contentType === Y("xlsx").partContentType, "Unsupported Matrix artifact encoding."), Pe = d.discriminatedUnion("kind", [
158
- d.object({ kind: d.literal("work"), sequence: A, checkpointKey: d.string(), objects: d.array(Oe).min(2).max(4), deadlineAt: R }),
159
- d.object({ kind: d.literal("committed"), sequence: A, done: d.boolean(), deadlineAt: R })
160
- ]);
161
- function ze(e) {
162
- const t = JSON.stringify(e);
163
- if (t === void 0 || new TextEncoder().encode(t).byteLength > je)
164
- throw new RangeError("Matrix export batch exceeds its transport byte limit.");
165
- }
166
- function Lt(e, t) {
167
- const o = Pe.parse(e);
168
- if (ze(e), o.deadlineAt !== t.deadlineAt) throw new Error("Matrix deadline does not match the job.");
169
- if (o.sequence !== t.sequence + (o.kind === "committed" ? 1 : 0))
170
- throw new Error("Invalid Matrix batch sequence.");
171
- if (o.kind === "work") {
172
- v(t.jobId, o.checkpointKey);
173
- for (const r of o.objects)
174
- v(t.jobId, r.key);
175
- }
176
- return o;
177
- }
178
- const qe = d.object({
179
- acquisition: d.literal("continuation"),
180
- deadlineAt: R,
181
- chunks: d.array(d.object({ chunkNumber: A, dataKey: d.string() })).min(1),
182
- totalRows: S,
183
- totalBytes: S,
184
- fileKey: d.string().min(1).optional(),
185
- fileSize: S.optional(),
186
- /** The file the job writes; absent means CSV (manifests from before Excel). */
187
- format: d.enum(B).optional(),
188
- /** Excel only: the sheet layout the layout batch stored, which compaction wraps the rows in. */
189
- sheetKey: d.string().min(1).optional()
190
- }).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.");
191
- function Bt(e, t, o) {
192
- const r = qe.parse(e);
193
- if (r.deadlineAt !== o) throw new Error("Matrix deadline does not match the job.");
194
- return r.chunks.forEach((n, a) => {
195
- if (n.chunkNumber !== a + 1) throw new Error("Invalid committed Matrix chunk order.");
196
- v(t, n.dataKey);
197
- }), r.fileKey !== void 0 && v(t, r.fileKey), r.sheetKey !== void 0 && v(t, r.sheetKey), r;
198
- }
199
- function Yt(e, t) {
200
- return t.levelLabels[e.id] ?? e.field.label ?? e.field.name;
201
- }
202
- function Zt(e, t) {
203
- return t.measureLabels[e.id] ?? (e.kind === "aggregate" ? e.field.label ?? e.field.name : e.definition.label);
204
- }
205
- function Ht(e) {
206
- return ue.parse(Le(e));
207
- }
208
- function Le(e) {
209
- const t = le.parse(e), o = (r) => ({
210
- grand: { visible: !0, position: "after" },
211
- levels: Object.fromEntries(
212
- r.map((n) => [
213
- n.id,
214
- { visible: !0, position: "before" }
215
- ])
216
- )
217
- });
218
- return de.parse({
219
- version: 1,
220
- spec: t,
221
- presentation: {
222
- layout: { kind: "compact" },
223
- absence: { emptyText: "—", nullText: "" },
224
- levelLabels: {},
225
- measureLabels: {},
226
- levelFormats: {},
227
- measureFormats: {},
228
- totals: { rows: o(t.rows), columns: o(t.columns) }
229
- },
230
- defaultView: {
231
- rows: { depth: 0, overrides: [] },
232
- columns: { depth: t.columns.length > 1 ? 1 : 0, overrides: [] }
233
- }
234
- });
235
- }
236
- function Be(e, t) {
237
- const o = new Map(e.map((r) => [T(r), r]));
238
- for (const r of t ?? []) o.set(T(r), r);
239
- return [...o.values()];
240
- }
241
- function Vt(e) {
242
- const { spec: t, presentation: o, defaults: r, session: n } = me.parse(e), a = new Map(
243
- Be(t.sorts, n == null ? void 0 : n.sorts).map((s) => [T(s), s])
244
- );
245
- for (const s of ["rows", "columns"])
246
- for (const c of t[s]) {
247
- const m = {
248
- axis: s,
249
- levelId: c.id,
250
- scope: { kind: "level" },
251
- target: { kind: "member" },
252
- direction: "asc",
253
- nulls: "last"
254
- };
255
- a.has(T(m)) || a.set(T(m), m);
256
- }
257
- const i = (s, c) => ({
258
- depth: Math.min(s.depth, Math.max(0, c - 1)),
259
- // Leaf toggles are valid but have no effect. Collapsed ancestors retain dormant overrides.
260
- overrides: s.overrides.filter(
261
- (m) => m.path.length < c
262
- )
263
- });
264
- return {
265
- spec: { ...t, sorts: [...a.values()] },
266
- presentation: o,
267
- view: {
268
- rows: i((n == null ? void 0 : n.rows) ?? r.rows, t.rows.length),
269
- columns: i(
270
- (n == null ? void 0 : n.columns) ?? r.columns,
271
- t.columns.length
272
- ),
273
- sorts: (n == null ? void 0 : n.sorts) ?? []
274
- }
275
- };
276
- }
277
- class N extends Error {
278
- constructor(o) {
279
- super(
280
- `invalid_presentation_execution_snapshot: ${o} Resave this report before running it again.`
281
- );
282
- h(this, "code", "invalid_presentation_execution_snapshot");
283
- h(this, "deliveryBlocking", !0);
284
- this.name = "PresentationExecutionSnapshotError";
285
- }
286
- }
287
- class Wt extends Error {
288
- constructor(o) {
289
- super(
290
- `missing_resolved_raw_temporal_format: Column "${o}" has no captured presentation. Resave this report before running it again.`
291
- );
292
- h(this, "code", "missing_resolved_raw_temporal_format");
293
- h(this, "deliveryBlocking", !0);
294
- this.name = "MissingResolvedRawTemporalFormatError";
295
- }
296
- }
297
- function w(e, t, o) {
298
- const r = new Set(t), n = Object.keys(e).find((a) => !r.has(a));
299
- if (n)
300
- throw new Error(`${o} contains unknown property "${n}"`);
301
- }
302
- function Ye(e, t = "scope") {
303
- if (!y(e))
304
- throw new Error(`${t} must be an object`);
305
- w(
306
- e,
307
- ["dashboardId", "cardId", "attachmentIndex"],
308
- t
309
- );
310
- const o = typeof e.dashboardId == "string" ? e.dashboardId.trim() : "";
311
- if (!o)
312
- throw new Error(`${t}.dashboardId is required`);
313
- const r = typeof e.cardId == "string" ? e.cardId.trim() : void 0;
314
- if (e.cardId !== void 0 && !r)
315
- throw new Error(`${t}.cardId must be a non-empty string`);
316
- const n = e.attachmentIndex;
317
- if (n !== void 0 && (typeof n != "number" || !Number.isInteger(n) || n < 0))
318
- throw new Error(
319
- `${t}.attachmentIndex must be a non-negative integer`
320
- );
321
- return {
322
- dashboardId: o,
323
- ...r ? { cardId: r } : {},
324
- ...typeof n == "number" ? { attachmentIndex: n } : {}
325
- };
326
- }
327
- function b(e, t, o, r) {
328
- if (e.kind !== t) return;
329
- w(e, ["kind", o], r);
330
- const n = e[o];
331
- if (typeof n != "string" || !n.trim())
332
- throw new Error(`${r}.${o} is required`);
333
- return n;
334
- }
335
- function F(e, t) {
336
- if (!y(e))
337
- throw new Error(`${t} must be an object`);
338
- const o = b(e, "metric", "metricId", t);
339
- if (o) return { kind: "metric", metricId: o };
340
- const r = b(e, "column", "columnKey", t);
341
- if (r) return { kind: "column", columnKey: r };
342
- const n = b(
343
- e,
344
- "matrix_measure",
345
- "measureId",
346
- t
347
- );
348
- if (n) return { kind: "matrix_measure", measureId: n };
349
- throw new Error(`${t} is not a valid numeric presentation target`);
350
- }
351
- const Ze = [
352
- "type",
353
- "inputUnit",
354
- "outputStyle",
355
- "largestUnit",
356
- "smallestUnit",
357
- "maxUnits",
358
- "prefix",
359
- "suffix",
360
- "negativeStyle"
361
- ];
362
- function He(e) {
363
- return e === "millisecond" || e === "second" || e === "minute" || e === "hour" || e === "day";
364
- }
365
- const Ve = ["type", "locale", "pattern", "timezone", "sourceTimezone"];
366
- function We(e, t) {
367
- if (w(e, Ve, t), typeof e.locale != "string" || !e.locale.trim())
368
- throw new Error(`${t}.locale must be a non-empty string`);
369
- for (const o of ["pattern", "timezone", "sourceTimezone"])
370
- if (e[o] !== void 0 && typeof e[o] != "string")
371
- throw new Error(`${t}.${o} must be a string`);
372
- return {
373
- type: "date",
374
- locale: e.locale,
375
- ...typeof e.pattern == "string" ? { pattern: e.pattern } : {},
376
- ...typeof e.timezone == "string" ? { timezone: e.timezone } : {},
377
- ...typeof e.sourceTimezone == "string" ? { sourceTimezone: e.sourceTimezone } : {}
378
- };
379
- }
380
- function Xe(e, t) {
381
- w(e, Ze, t);
382
- for (const a of ["inputUnit", "largestUnit", "smallestUnit"])
383
- if (e[a] !== void 0 && !He(e[a]))
384
- throw new Error(`${t}.${a} must be a duration unit`);
385
- const o = e.outputStyle;
386
- if (o !== void 0 && o !== "compact" && o !== "digital" && o !== "long")
387
- throw new Error(`${t}.outputStyle must be compact, digital, or long`);
388
- const r = e.maxUnits;
389
- if (r !== void 0 && (typeof r != "number" || !Number.isInteger(r) || r < 0 || r > 10))
390
- throw new Error(`${t}.maxUnits must be an integer from 0 to 10`);
391
- for (const a of ["prefix", "suffix"])
392
- if (e[a] !== void 0 && typeof e[a] != "string")
393
- throw new Error(`${t}.${a} must be a string`);
394
- const n = e.negativeStyle;
395
- if (n !== void 0 && n !== "minus" && n !== "parentheses")
396
- throw new Error(`${t}.negativeStyle must be minus or parentheses`);
397
- return {
398
- type: "duration",
399
- ...e.inputUnit !== void 0 ? { inputUnit: e.inputUnit } : {},
400
- ...o !== void 0 ? { outputStyle: o } : {},
401
- ...e.largestUnit !== void 0 ? { largestUnit: e.largestUnit } : {},
402
- ...e.smallestUnit !== void 0 ? { smallestUnit: e.smallestUnit } : {},
403
- ...r !== void 0 ? { maxUnits: r } : {},
404
- ...e.prefix !== void 0 ? { prefix: e.prefix } : {},
405
- ...e.suffix !== void 0 ? { suffix: e.suffix } : {},
406
- ...n !== void 0 ? { negativeStyle: n } : {}
407
- };
408
- }
409
- function Je(e, t) {
410
- if (!y(e))
411
- throw new Error(`${t} must be an object`);
412
- if (e.kind === "field") {
413
- w(e, ["kind", "fieldId", "role"], t);
414
- const n = typeof e.fieldId == "string" ? e.fieldId.trim() : "";
415
- if (!n)
416
- throw new Error(`${t}.fieldId is required`);
417
- const a = e.role;
418
- if (a !== void 0 && a !== "groupby" && a !== "pivotby")
419
- throw new Error(`${t}.role must be groupby or pivotby`);
420
- return {
421
- kind: "field",
422
- fieldId: n,
423
- ...a ? { role: a } : {}
424
- };
425
- }
426
- const o = b(e, "column", "columnKey", t);
427
- if (o) return { kind: "column", columnKey: o };
428
- const r = b(
429
- e,
430
- "matrix_axis",
431
- "axisInstanceId",
432
- t
433
- );
434
- if (r) return { kind: "matrix_axis", axisInstanceId: r };
435
- throw new Error(`${t} is not a valid temporal bucket presentation target`);
436
- }
437
- function Ge(e, t) {
438
- if (!y(e))
439
- throw new Error(`${t} must be an object`);
440
- const o = b(e, "column", "columnKey", t);
441
- if (!o)
442
- throw new Error(`${t} must identify a column`);
443
- return { kind: "column", columnKey: o };
444
- }
445
- function Qe(e) {
446
- return [
447
- e.dashboardId,
448
- e.cardId ?? null,
449
- e.attachmentIndex ?? null
450
- ];
451
- }
452
- function C(e) {
453
- switch (e.kind) {
454
- case "metric":
455
- return [e.kind, e.metricId];
456
- case "column":
457
- return [e.kind, e.columnKey];
458
- case "matrix_measure":
459
- return [e.kind, e.measureId];
460
- case "field":
461
- return [e.kind, e.fieldId, e.role ?? ""];
462
- case "matrix_axis":
463
- return [e.kind, e.axisInstanceId];
464
- }
465
- }
466
- function _(e, t) {
467
- return e.dashboardId === t.dashboardId && e.cardId === t.cardId && e.attachmentIndex === t.attachmentIndex;
468
- }
469
- function $(e, t) {
470
- const o = C(e), r = C(t);
471
- return o.length === r.length && o.every((n, a) => n === r[a]);
472
- }
473
- function et(e) {
474
- if (!Array.isArray(e))
475
- throw new Error("resolvedFormats must be an array");
476
- const t = /* @__PURE__ */ new Set();
477
- return e.map((o, r) => {
478
- var c, m;
479
- const n = `resolvedFormats.${r}`;
480
- if (!y(o))
481
- throw new Error(`${n} must be an object`);
482
- w(o, ["scope", "target", "format"], n);
483
- const a = Ye(o.scope, `${n}.scope`);
484
- if (!y(o.format))
485
- throw new Error(`${n}.format must be an object`);
486
- let i;
487
- switch (o.format.type) {
488
- case "temporal_bucket": {
489
- const u = oe(o.format);
490
- if (!u.ok)
491
- throw new Error(
492
- `${n}.format is invalid: ${((c = u.issues[0]) == null ? void 0 : c.message) ?? "invalid value"}`
493
- );
494
- i = {
495
- scope: a,
496
- target: Je(o.target, `${n}.target`),
497
- format: u.value
498
- };
499
- break;
500
- }
501
- case "raw_temporal":
502
- i = {
503
- scope: a,
504
- target: Ge(o.target, `${n}.target`),
505
- format: te(o.format)
506
- };
507
- break;
508
- case "number":
509
- case "currency":
510
- case "percent":
511
- case "scientific": {
512
- const u = ee(o.format);
513
- if (!u.ok)
514
- throw new Error(
515
- `${n}.format is invalid: ${((m = u.issues[0]) == null ? void 0 : m.message) ?? "invalid value"}`
516
- );
517
- i = {
518
- scope: a,
519
- target: F(o.target, `${n}.target`),
520
- format: u.value
521
- };
522
- break;
523
- }
524
- case "date": {
525
- const u = F(o.target, `${n}.target`);
526
- if (u.kind !== "column")
527
- throw new Error(`${n}.target must identify a column for a date format`);
528
- i = {
529
- scope: a,
530
- target: u,
531
- format: We(o.format, `${n}.format`)
532
- };
533
- break;
534
- }
535
- case "duration":
536
- i = {
537
- scope: a,
538
- target: F(o.target, `${n}.target`),
539
- format: Xe(
540
- o.format,
541
- `${n}.format`
542
- )
543
- };
544
- break;
545
- default:
546
- throw new Error(`${n}.format.type is unsupported`);
547
- }
548
- const s = JSON.stringify([
549
- ...Qe(i.scope),
550
- ...C(i.target)
551
- ]);
552
- if (t.has(s))
553
- throw new Error(
554
- `${n} duplicates a scoped presentation target`
555
- );
556
- return t.add(s), i;
557
- });
558
- }
559
- function tt(e) {
560
- try {
561
- if (!y(e))
562
- throw new Error("presentation execution snapshot must be an object");
563
- if (w(
564
- e,
565
- ["version", "reportContext", "resolvedFormats"],
566
- "presentation execution snapshot"
567
- ), e.version !== 1)
568
- throw new Error("presentation execution snapshot version must be 1");
569
- const t = fe(e.reportContext);
570
- if (!t.ok) {
571
- const o = t.issues[0];
572
- throw new Error(
573
- `presentation execution snapshot reportContext is invalid: ${o != null && o.path && o.path !== "$" ? `${o.path}: ` : ""}${(o == null ? void 0 : o.message) ?? "invalid value"}`
574
- );
575
- }
576
- return {
577
- version: 1,
578
- reportContext: t.value,
579
- resolvedFormats: et(e.resolvedFormats)
580
- };
581
- } catch (t) {
582
- throw t instanceof N ? t : new N(
583
- t instanceof Error ? t.message : "Snapshot is invalid."
584
- );
585
- }
586
- }
587
- function Xt(e) {
588
- return tt({
589
- version: 1,
590
- reportContext: e.reportContext,
591
- resolvedFormats: [...e.resolvedFormats]
592
- });
593
- }
594
- function Jt(e) {
595
- const t = ot(e);
596
- return re(t) ? t : void 0;
597
- }
598
- function ot(e) {
599
- const t = e.snapshot.resolvedFormats.find(
600
- (o) => o.format.type !== "temporal_bucket" && o.format.type !== "raw_temporal" && o.format.type !== "date" && _(o.scope, e.scope) && $(o.target, e.target)
601
- );
602
- return t == null ? void 0 : t.format;
603
- }
604
- function Gt(e) {
605
- const t = e.snapshot.resolvedFormats.find(
606
- (o) => o.format.type === "date" && _(o.scope, e.scope) && $(o.target, e.target)
607
- );
608
- return t == null ? void 0 : t.format;
609
- }
610
- function Qt(e) {
611
- const t = e.snapshot.resolvedFormats.find(
612
- (o) => o.format.type === "raw_temporal" && _(o.scope, e.scope) && $(o.target, e.target)
613
- );
614
- return t == null ? void 0 : t.format;
615
- }
616
- function eo(e) {
617
- const t = e.snapshot.resolvedFormats.find(
618
- (o) => o.format.type === "temporal_bucket" && _(o.scope, e.scope) && $(o.target, e.target)
619
- );
620
- return t == null ? void 0 : t.format;
621
- }
622
- function to(e) {
623
- var n;
624
- const t = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
625
- if (e.snapshot.resolvedFormats.forEach((a, i) => {
626
- if (a.scope.attachmentIndex !== void 0)
627
- throw new Error(
628
- `resolvedFormats.${i}.scope.attachmentIndex is not valid for a card export`
629
- );
630
- if (a.scope.dashboardId !== e.expectedScope.dashboardId || a.scope.cardId !== e.expectedScope.cardId)
631
- throw new Error(
632
- `resolvedFormats.${i}.scope must match the executing dashboard/card`
633
- );
634
- if (a.target.kind === "field" && a.format.type === "temporal_bucket") {
635
- const s = JSON.stringify(C(a.target));
636
- if (o.has(s))
637
- throw new Error(
638
- `resolvedFormats.${i} duplicates export field "${a.target.fieldId}"`
639
- );
640
- o.add(s);
641
- return;
642
- }
643
- if (a.target.kind !== "column")
644
- throw new Error(
645
- `resolvedFormats.${i}.target must identify an export column or temporal pivot field`
646
- );
647
- if (t.has(a.target.columnKey))
648
- throw new Error(
649
- `resolvedFormats.${i} duplicates export column "${a.target.columnKey}"`
650
- );
651
- t.add(a.target.columnKey);
652
- }), !e.useFormattedValues) return;
653
- if (!((n = e.visibleColumns) != null && n.length))
654
- throw new Error("visibleColumns must identify every formatted export column");
655
- const r = e.visibleColumns.find(
656
- (a) => !t.has(a)
657
- );
658
- if (r)
659
- throw new Error(
660
- `resolvedFormats is missing visible export column "${r}"`
661
- );
662
- }
663
- const rt = /* @__PURE__ */ new Set(["short", "medium", "long"]), nt = /^(\d{4})-(\d{2})-(\d{2})$/, at = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?$/, it = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/, j = " – ";
664
- function oo(e) {
665
- if (!y(e)) return;
666
- const t = Object.keys(e);
667
- if (e.mode === "period_label" && t.length === 1)
668
- return { mode: "period_label" };
669
- if (e.mode === "style" && t.length === 2 && typeof e.dateStyle == "string" && rt.has(e.dateStyle))
670
- return { mode: "style", dateStyle: e.dateStyle };
671
- if (e.mode === "pattern" && t.length === 3 && e.dialect === "semaphor_tokens" && typeof e.pattern == "string" && st(e.pattern) === null)
672
- return {
673
- mode: "pattern",
674
- dialect: "semaphor_tokens",
675
- pattern: e.pattern
676
- };
677
- }
678
- function st(e) {
679
- try {
680
- return ce({ dialect: "semaphor_tokens", pattern: e }), null;
681
- } catch (t) {
682
- return t instanceof Error ? t.message : "The pattern is invalid.";
683
- }
684
- }
685
- function ro(e) {
686
- const { value: t, part: o, presentation: r, preferences: n, calendar: a } = e;
687
- if ((r == null ? void 0 : r.mode) === "period_label" && t.periodLabel && o === "range")
688
- return { ok: !0, text: t.periodLabel };
689
- const [i, s] = t.bounds, m = s === void 0 || o === "start" ? [{ raw: i, role: "start" }] : o === "end" ? [{ raw: s, role: "end" }] : [
690
- { raw: i, role: "start" },
691
- { raw: s, role: "end" }
692
- ], u = m.map(({ raw: p }) => mt(p, a.tz));
693
- if (u.some((p) => p === null))
694
- return {
695
- ok: !1,
696
- text: m.map(({ raw: p }) => p).join(j),
697
- diagnostic: {
698
- code: "invalid_temporal_input_value",
699
- message: "A date input bound is not a date or an instant."
700
- }
701
- };
702
- const g = t.precision === "day" ? u.map(
703
- (p, J) => ft(p, m[J].role, a.tz)
704
- ) : [], f = g.length > 0 && g.every((p) => p !== null) ? g : null;
705
- return { ok: !0, text: f ? ct(f, r, n, a) : lt(
706
- u.map((p) => ut(p, a.tz)),
707
- r,
708
- n,
709
- a
710
- ) };
711
- }
712
- function ct(e, t, o, r) {
713
- const [n, a = n] = e;
714
- if ((t == null ? void 0 : t.mode) === "pattern")
715
- return W(
716
- e.map(
717
- (c) => V(D(c), "date", t.pattern, o, r)
718
- )
719
- );
720
- const i = (t == null ? void 0 : t.mode) === "style" ? t.dateStyle : o.dateStyle;
721
- if (!t || t.mode === "period_label") {
722
- const c = pt(n, a, r);
723
- if (c)
724
- return ne({
725
- value: D(n),
726
- metadata: {
727
- kind: "temporal_bucket",
728
- granularity: c,
729
- calendar: { tz: r.tz, weekStart: r.weekStart ?? 1 }
730
- },
731
- format: ae({
732
- metadata: {
733
- kind: "temporal_bucket",
734
- granularity: c,
735
- calendar: { tz: r.tz, weekStart: r.weekStart ?? 1 }
736
- },
737
- locale: o.locale,
738
- styles: { dateStyle: i, dateTime: { ...o.dateTime } }
739
- }).format
740
- });
741
- }
742
- const s = new Intl.DateTimeFormat(o.locale, {
743
- calendar: "gregory",
744
- timeZone: "UTC",
745
- dateStyle: i
746
- });
747
- return ht(n, a) ? s.format(E(n)) : H(s, E(n), E(a));
748
- }
749
- function lt(e, t, o, r) {
750
- if ((t == null ? void 0 : t.mode) === "pattern")
751
- return W(
752
- e.map(
753
- (s) => V(
754
- s.toISOString(),
755
- "instant",
756
- t.pattern,
757
- o,
758
- r
759
- )
760
- )
761
- );
762
- const n = new Intl.DateTimeFormat(o.locale, {
763
- calendar: "gregory",
764
- timeZone: r.tz,
765
- dateStyle: (t == null ? void 0 : t.mode) === "style" ? t.dateStyle : o.dateTime.dateStyle,
766
- timeStyle: o.dateTime.timeStyle
767
- }), [a, i] = e;
768
- return i && i.getTime() !== a.getTime() ? H(n, a, i) : n.format(a);
769
- }
770
- function H(e, t, o) {
771
- const r = e;
772
- return typeof r.formatRange == "function" ? r.formatRange(t, o) : `${e.format(t)}${j}${e.format(o)}`;
773
- }
774
- function V(e, t, o, r, n) {
775
- const a = ie({
776
- format: {
777
- type: "raw_temporal",
778
- presentation: { mode: "pattern", dialect: "semaphor_tokens", pattern: o }
779
- },
780
- // Temporal formatting reads no currency.
781
- preferences: {
782
- ...r,
783
- defaultCurrency: pe.defaultCurrency
784
- },
785
- calendar: { tz: n.tz }
786
- }), i = t === "date" && dt(o) ? "instant" : t;
787
- return se({
788
- value: i === t ? e : K(`${e}T00:00:00`, n.tz).toISOString(),
789
- metadata: { kind: "raw_temporal", valueKind: i },
790
- format: a
791
- }).text;
792
- }
793
- function dt(e) {
794
- return /HH|mm|ss/.test(e);
795
- }
796
- function W(e) {
797
- return e[1] === void 0 || e[0] === e[1] ? e[0] : e.join(j);
798
- }
799
- function mt(e, t) {
800
- const o = nt.exec(e);
801
- if (o) {
802
- const n = {
803
- year: Number(o[1]),
804
- month: Number(o[2]),
805
- day: Number(o[3])
806
- };
807
- return wt(n) ? { kind: "date", date: n } : null;
808
- }
809
- const r = it.test(e) ? new Date(e.replace(" ", "T")) : at.test(e) ? K(e.replace(" ", "T"), t) : null;
810
- return r && !Number.isNaN(r.getTime()) ? { kind: "instant", instant: r } : null;
811
- }
812
- function ut(e, t) {
813
- return e.kind === "instant" ? e.instant : K(`${D(e.date)}T00:00:00`, t);
814
- }
815
- function ft(e, t, o) {
816
- if (e.kind === "date") return e.date;
817
- const r = ye(e.instant, o), n = { year: r.year, month: r.month, day: r.day };
818
- if (r.hour === 0 && r.minute === 0 && r.second === 0 && e.instant.getUTCMilliseconds() === 0) return t === "start" ? n : yt(n, -1);
819
- const i = r.hour === 23 && r.minute === 59 && r.second === 59;
820
- return t === "end" && i ? n : null;
821
- }
822
- function pt(e, t, o) {
823
- return o.fiscalCalendar || e.day !== 1 || e.year !== t.year || t.day !== X(t.year, t.month) ? null : e.month === t.month ? "month" : e.month % 3 === 1 && t.month === e.month + 2 ? "quarter" : e.month === 1 && t.month === 12 ? "year" : null;
824
- }
825
- function D(e) {
826
- return `${String(e.year).padStart(4, "0")}-${String(e.month).padStart(2, "0")}-${String(e.day).padStart(2, "0")}`;
827
- }
828
- function E(e) {
829
- const t = /* @__PURE__ */ new Date(0);
830
- return t.setUTCFullYear(e.year, e.month - 1, e.day), t.setUTCHours(0, 0, 0, 0), t;
831
- }
832
- function yt(e, t) {
833
- const o = E(e);
834
- return o.setUTCDate(o.getUTCDate() + t), {
835
- year: o.getUTCFullYear(),
836
- month: o.getUTCMonth() + 1,
837
- day: o.getUTCDate()
838
- };
839
- }
840
- function ht(e, t) {
841
- return e.year === t.year && e.month === t.month && e.day === t.day;
842
- }
843
- function X(e, t) {
844
- return new Date(Date.UTC(e, t, 0)).getUTCDate();
845
- }
846
- function wt(e) {
847
- return e.year >= 1 && e.month >= 1 && e.month <= 12 && e.day >= 1 && e.day <= X(e.year, e.month);
848
- }
849
- function I(e) {
850
- return Array.from(
851
- new Set(
852
- (e ?? []).flatMap(
853
- (t) => typeof t.id == "string" && t.id ? [t.id] : []
854
- )
855
- )
856
- );
857
- }
858
- function gt(e) {
859
- const t = /* @__PURE__ */ new Map();
860
- return e.forEach((o) => {
861
- o.id && t.set(o.id, (t.get(o.id) ?? 0) + 1);
862
- }), e.flatMap(
863
- (o) => o.id && (t.get(o.id) ?? 0) > 1 ? [we(o)] : []
864
- );
865
- }
866
- function no(e) {
867
- const t = e.metricFields ?? [], o = I(t);
868
- return {
869
- expectedRoleFieldIds: {
870
- groupby: I(e.groupByFields),
871
- metric: o.length > 0 ? o : [he],
872
- pivotby: I(e.pivotByFields),
873
- detail: I(e.detailFields)
874
- },
875
- expectedMetricAliases: gt(t)
876
- };
877
- }
878
- class l extends Error {
879
- constructor(o, r) {
880
- super(`invalid_pivot_result_lifecycle: ${o}`);
881
- h(this, "code", "invalid_pivot_result_lifecycle");
882
- h(this, "deliveryBlocking", !0);
883
- this.cause = r, this.name = "PivotResultLifecycleError";
884
- }
885
- }
886
- function vt(e) {
887
- if (!Array.isArray(e) || e.some(
888
- (o) => !o || typeof o != "object" || Array.isArray(o) || typeof o.key != "string" || !o.key || typeof o.name != "string" || typeof o.label != "string"
889
- ))
890
- throw new l(
891
- "Canonical pivot columns must be an array of keyed, named result descriptors."
892
- );
893
- const t = e;
894
- if (new Set(t.map((o) => o.key)).size !== t.length)
895
- throw new l(
896
- "Canonical pivot column keys must be unique."
897
- );
898
- for (const o of t) {
899
- const r = ge(o, {
900
- metadataRequired: !1
901
- });
902
- if (!r.ok)
903
- throw new l(
904
- `Canonical pivot column "${o.key}" has invalid temporal metadata: ${r.error.message}`
905
- );
906
- }
907
- return t;
908
- }
909
- function U(e) {
910
- if (!e || typeof e != "object" || Array.isArray(e) || e.version !== 1 || e.source !== "explorer" || !e.byRole || typeof e.byRole != "object" || Array.isArray(e.byRole))
911
- throw new l(
912
- "A loaded canonical pivot result requires its role-scoped column key map."
913
- );
914
- const t = e, o = /* @__PURE__ */ new Set(["groupby", "metric", "pivotby", "detail"]);
915
- for (const [r, n] of Object.entries(t.byRole)) {
916
- if (!o.has(r) || !n || typeof n != "object" || Array.isArray(n))
917
- throw new l(
918
- `Canonical pivot role map contains invalid "${r}" bindings.`
919
- );
920
- for (const [a, i] of Object.entries(n))
921
- if (!a || !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))
922
- throw new l(
923
- `Canonical pivot role map contains an invalid "${r}:${a}" binding.`
924
- );
925
- }
926
- if (t.byMetricAlias !== void 0) {
927
- if (!t.byMetricAlias || typeof t.byMetricAlias != "object" || Array.isArray(t.byMetricAlias))
928
- throw new l(
929
- "Canonical pivot metric-alias bindings must be an object."
930
- );
931
- for (const [r, n] of Object.entries(
932
- t.byMetricAlias
933
- ))
934
- 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))
935
- throw new l(
936
- `Canonical pivot metric-alias map contains an invalid "${r}" binding.`
937
- );
938
- }
939
- return t;
940
- }
941
- function bt(e) {
942
- if (e === void 0) return {};
943
- if (!e || typeof e != "object" || Array.isArray(e))
944
- throw new l(
945
- "Canonical pivot column metadata must be an object."
946
- );
947
- for (const [t, o] of Object.entries(e)) {
948
- if (!t || !o || typeof o != "object" || Array.isArray(o))
949
- throw new l(
950
- `Canonical pivot column metadata contains an invalid "${t}" classification.`
951
- );
952
- const { isSubtotal: r, subtotalScope: n } = o;
953
- 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)
954
- throw new l(
955
- `Canonical pivot column metadata contains an incoherent "${t}" subtotal classification.`
956
- );
957
- }
958
- return e;
959
- }
960
- function O(e, t) {
961
- if (!Array.isArray(e) || e.some((o) => typeof o != "string" || !o) || new Set(e).size !== e.length)
962
- throw new l(
963
- `Canonical pivot contract ${t} must be an array of unique field identities.`
964
- );
965
- return e;
966
- }
967
- function xt(e, t) {
968
- if (!e || typeof e != "object" || Array.isArray(e) || e.version !== 1)
969
- throw new l(
970
- "A canonical pivot result requires its versioned result contract."
971
- );
972
- const o = e, r = o.expectedRoleFieldIds;
973
- if (!r || typeof r != "object" || Array.isArray(r))
974
- throw new l(
975
- "Canonical pivot contract role identities must be an object."
976
- );
977
- const a = Object.fromEntries(
978
- [
979
- "groupby",
980
- "metric",
981
- "pivotby",
982
- "detail"
983
- ].map((f) => [
984
- f,
985
- O(
986
- r[f],
987
- `expectedRoleFieldIds.${f}`
988
- )
989
- ])
990
- ), i = O(
991
- o.expectedMetricAliases,
992
- "expectedMetricAliases"
993
- ), s = o.columnKinds;
994
- if (!s || typeof s != "object" || Array.isArray(s))
995
- throw new l(
996
- "Canonical pivot contract column kinds must be an object."
997
- );
998
- const c = /* @__PURE__ */ new Set([
999
- "row",
1000
- "pivot_metric",
1001
- "value"
1002
- ]), m = t.map((f) => f.key), u = Object.keys(s);
1003
- if (u.length !== m.length || u.some(
1004
- (f) => !m.includes(f) || !c.has(
1005
- s[f]
1006
- )
1007
- ))
1008
- throw new l(
1009
- "Canonical pivot contract must classify every authoritative result column exactly once."
1010
- );
1011
- const g = bt(
1012
- o.columnClassifications
1013
- );
1014
- if (Object.keys(g).some(
1015
- (f) => !m.includes(f)
1016
- ))
1017
- throw new l(
1018
- "Canonical pivot contract contains a classification for an unknown result column."
1019
- );
1020
- return {
1021
- version: 1,
1022
- expectedRoleFieldIds: a,
1023
- expectedMetricAliases: i,
1024
- columnKinds: s,
1025
- columnClassifications: g
1026
- };
1027
- }
1028
- function P(e, t) {
1029
- const o = [
1030
- "groupby",
1031
- "metric",
1032
- "pivotby",
1033
- "detail"
1034
- ];
1035
- for (const a of o) {
1036
- const i = new Set(t.expectedRoleFieldIds[a] ?? []), s = Object.keys(e.byRole[a] ?? {});
1037
- if (s.length !== i.size || s.some((c) => !i.has(c)))
1038
- throw new l(
1039
- `The role-scoped ${a} bindings do not match the authored result fields.`
1040
- );
1041
- }
1042
- const r = new Set(t.expectedMetricAliases), n = Object.keys(e.byMetricAlias ?? {});
1043
- if (n.length !== r.size || n.some((a) => !r.has(a)))
1044
- throw new l(
1045
- "The metric-alias bindings do not match the authored metric instances."
1046
- );
1047
- }
1048
- function Tt(e) {
1049
- if (!Array.isArray(e) || e.some(
1050
- (t) => !t || typeof t != "object" || Array.isArray(t)
1051
- ))
1052
- throw new l(
1053
- "Canonical pivot records must be an array of row objects."
1054
- );
1055
- return e;
1056
- }
1057
- function kt(e, t) {
1058
- e.forEach((o, r) => {
1059
- t.forEach((n) => {
1060
- if (!Object.prototype.hasOwnProperty.call(o, n.key) || o[n.key] === void 0)
1061
- throw new l(
1062
- `Canonical pivot column "${n.key}" is absent from row ${r}.`
1063
- );
1064
- });
1065
- });
1066
- }
1067
- function It(e, t, o) {
1068
- const r = new Set(t.map((n) => n.key));
1069
- ["groupby", "detail"].forEach((n) => {
1070
- Object.entries(e.byRole[n] ?? {}).forEach(
1071
- ([a, i]) => {
1072
- const s = i.outputKey || i.rawKey;
1073
- if (!r.has(s) || o.columnKinds[s] !== "row")
1074
- throw new l(
1075
- `The role-scoped ${n} binding for "${a}" does not name an authoritative result column.`
1076
- );
1077
- }
1078
- );
1079
- });
1080
- }
1081
- function z(e, t) {
1082
- t.forEach((o) => {
1083
- const r = e.columnKinds[o.key];
1084
- if (r === "pivot_metric" && o.pivotIdentity === void 0)
1085
- throw new l(
1086
- `Physical pivot result column "${o.key}" is missing its identity.`
1087
- );
1088
- if (r !== "pivot_metric" && o.pivotIdentity !== void 0)
1089
- throw new l(
1090
- `Canonical pivot result column "${o.key}" carries pivot identity outside the physical pivot projection.`
1091
- );
1092
- });
1093
- }
1094
- function St(e) {
1095
- const t = Tt(e.records), o = vt(e.columns), r = xt(
1096
- e.pivotResultContract,
1097
- o
1098
- ), n = r.expectedRoleFieldIds.pivotby ?? [];
1099
- if (e.pivotResultState === "loaded_empty") {
1100
- if (t.length !== 0)
1101
- throw new l(
1102
- "A loaded_empty pivot result cannot carry records."
1103
- );
1104
- if (o.some(
1105
- (c) => r.columnKinds[c.key] === "pivot_metric"
1106
- ))
1107
- throw new l(
1108
- "A loaded_empty pivot result cannot carry physical pivot columns."
1109
- );
1110
- z(r, o);
1111
- const s = U(e.columnKeyMap);
1112
- return P(s, r), {
1113
- pivotResultState: "loaded_empty",
1114
- records: [],
1115
- columns: o,
1116
- columnKeyMap: s,
1117
- pivotResultContract: r
1118
- };
1119
- }
1120
- if (e.pivotResultState !== "loaded_valid")
1121
- throw new l(
1122
- "A canonical pivot result must declare loaded_empty or loaded_valid."
1123
- );
1124
- if (t.length === 0)
1125
- throw new l(
1126
- "A loaded_valid pivot result must carry at least one record."
1127
- );
1128
- const a = U(e.columnKeyMap);
1129
- P(a, r), It(a, o, r), z(r, o);
1130
- const i = o.filter(
1131
- (s) => r.columnKinds[s.key] === "pivot_metric"
1132
- );
1133
- if (n.length > 0 && i.length === 0)
1134
- throw new l(
1135
- "A loaded_valid pivot result is missing its physical pivot columns."
1136
- );
1137
- try {
1138
- ve(i, {
1139
- expectedPivotFieldIds: n,
1140
- columnClassifications: r.columnClassifications
1141
- });
1142
- } catch (s) {
1143
- throw s instanceof be ? new l(s.message, s) : s;
1144
- }
1145
- return kt(t, o), {
1146
- pivotResultState: "loaded_valid",
1147
- records: t,
1148
- columns: o,
1149
- columnKeyMap: a,
1150
- pivotResultContract: r
1151
- };
1152
- }
1153
- function ao(e) {
1154
- const t = /* @__PURE__ */ new Set();
1155
- ["groupby", "detail"].forEach((a) => {
1156
- Object.values(e.columnKeyMap.byRole[a] ?? {}).forEach((i) => {
1157
- t.add(i.outputKey || i.rawKey);
1158
- });
1159
- });
1160
- const o = new Set(e.physicalPivotColumnKeys), r = new Set(
1161
- e.columns.map((a) => a.key)
1162
- ), n = {
1163
- version: 1,
1164
- expectedRoleFieldIds: {
1165
- groupby: Array.from(
1166
- new Set(e.expectedRoleFieldIds.groupby ?? [])
1167
- ),
1168
- metric: Array.from(
1169
- new Set(e.expectedRoleFieldIds.metric ?? [])
1170
- ),
1171
- pivotby: Array.from(
1172
- new Set(e.expectedRoleFieldIds.pivotby ?? [])
1173
- ),
1174
- detail: Array.from(
1175
- new Set(e.expectedRoleFieldIds.detail ?? [])
1176
- )
1177
- },
1178
- expectedMetricAliases: [...e.expectedMetricAliases ?? []],
1179
- columnKinds: Object.fromEntries(
1180
- e.columns.map((a) => [
1181
- a.key,
1182
- t.has(a.key) ? "row" : o.has(a.key) ? "pivot_metric" : "value"
1183
- ])
1184
- ),
1185
- columnClassifications: Object.fromEntries(
1186
- Object.entries(e.columnMetadata ?? {}).filter(
1187
- ([a]) => r.has(a)
1188
- )
1189
- )
1190
- };
1191
- return St({
1192
- pivotResultState: e.records.length === 0 ? "loaded_empty" : "loaded_valid",
1193
- pivotResultContract: n,
1194
- records: e.records,
1195
- columns: e.columns,
1196
- columnKeyMap: e.columnKeyMap
1197
- });
1198
- }
1199
- export {
1200
- l as A,
1201
- St as B,
1202
- ao as C,
1203
- Yt as D,
1204
- Zt as E,
1205
- Ht as F,
1206
- Le as G,
1207
- Be as H,
1208
- Vt as I,
1209
- Ot as J,
1210
- Wt as M,
1211
- N as P,
1212
- ot as a,
1213
- je as b,
1214
- Pt as c,
1215
- zt as d,
1216
- qt as e,
1217
- Qt as f,
1218
- Pe as g,
1219
- ze as h,
1220
- Lt as i,
1221
- qe as j,
1222
- Bt as k,
1223
- Ye as l,
1224
- R as m,
1225
- et as n,
1226
- tt as o,
1227
- v as p,
1228
- Xt as q,
1229
- Jt as r,
1230
- Gt as s,
1231
- eo as t,
1232
- oo as u,
1233
- to as v,
1234
- st as w,
1235
- ro as x,
1236
- gt as y,
1237
- no as z
1238
- };