react-semaphor 0.1.537 → 0.1.539

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 (174) hide show
  1. package/dist/analytics-protocol/index.js +352 -341
  2. package/dist/assistant-context/index.js +10 -0
  3. package/dist/assistant-protocol/index.js +104 -0
  4. package/dist/brand-studio/index.js +35 -31
  5. package/dist/briefings/index.js +46 -45
  6. package/dist/chunks/_commonjsHelpers-BkfeUUK-.js +28 -0
  7. package/dist/chunks/add-to-dashboard-CxtTfISD.js +56 -0
  8. package/dist/chunks/aggregate-table-row-presentation-BjK9YfMI.js +979 -0
  9. package/dist/chunks/analytics-base-schemas-BFAoRlkU.js +472 -0
  10. package/dist/chunks/apply-dashboard-operations-C-iahGka.js +402 -0
  11. package/dist/chunks/assistant-chat-DgiSuFT4.js +8083 -0
  12. package/dist/chunks/availability-Bp5Gfu1I.js +44 -0
  13. package/dist/chunks/{bookmark-state-B-I9BDD0.js → bookmark-state-k7y5SNGf.js} +9 -9
  14. package/dist/chunks/{braces-8TRlDwDw.js → braces-o9UiRQes.js} +1 -1
  15. package/dist/chunks/calculated-field-identity-DcBS2NPP.js +2161 -0
  16. package/dist/chunks/calendar-day-equality-Bpl15IBo.js +487 -0
  17. package/dist/chunks/class-utils-Df1OVOT1.js +2315 -0
  18. package/dist/chunks/{field-dependencies-CpRUwr9J.js → common-types-CUf03Htv.js} +65 -58
  19. package/dist/chunks/context-HD9usB1P.js +349 -0
  20. package/dist/chunks/conversation-sQiWYUOb.js +16 -0
  21. package/dist/chunks/csv-utils-GUfKyT1J.js +56 -0
  22. package/dist/chunks/custom-visual-inputs-BrUOIwln.js +3288 -0
  23. package/dist/chunks/{dashboard-briefing-launcher-A2uVpHCp.js → dashboard-briefing-launcher-Bl3gCeBR.js} +580 -556
  24. package/dist/chunks/{dashboard-controls-DxTuVis_.js → dashboard-controls-0EX0HiJt.js} +683 -686
  25. package/dist/chunks/{common-types-g7yS12Cg.js → dashboard-filter-value-compatibility-D95O4nd7.js} +18 -24
  26. package/dist/chunks/dashboard-json-6X_2BDiL.js +69 -0
  27. package/dist/chunks/{dashboard-BPJo-Fnd.js → dashboard-y5BwcvzT.js} +1 -1
  28. package/dist/chunks/document-dashboard-inputs-BrYYlRVo.js +10678 -0
  29. package/dist/chunks/document-sheet-utils-C1eEldxs.js +1076 -0
  30. package/dist/chunks/{edit-dashboard-visual-ByV0OwSp.js → edit-dashboard-visual-Bzchfgga.js} +4744 -4746
  31. package/dist/chunks/editor-draft-sync-BN5qYHPF.js +15 -0
  32. package/dist/chunks/filter-value-text-BhWugPWE.js +163 -0
  33. package/dist/chunks/index-CqMiAkay.js +3164 -0
  34. package/dist/chunks/index-CuHybtft.js +51 -0
  35. package/dist/chunks/layout-grid-Bgzth8vd.js +16 -0
  36. package/dist/chunks/{matrix-analytical-definition-CgBTD6H8.js → matrix-analytical-definition-bcprSe4u.js} +1 -1
  37. package/dist/chunks/{matrix-card-CAdizkUl.js → matrix-card-CJn1hB5V.js} +13 -12
  38. package/dist/chunks/matrix-definition-DQDI2okF.js +206 -0
  39. package/dist/chunks/{matrix-formatter-DJCk8Znf.js → matrix-formatter-DQ8avoIQ.js} +648 -457
  40. package/dist/chunks/matrix-member-presentation-BNPSDKBG.js +105 -0
  41. package/dist/chunks/{matrix-operation-contract-BKupLHXL.js → matrix-operation-contract-B8PBF1Gd.js} +134 -133
  42. package/dist/chunks/{metric-comparison-BKHyvnAy.js → metric-comparison-CojWeLqx.js} +1 -1
  43. package/dist/chunks/{palette-Cp1hqZtm.js → palette-D10o_yYX.js} +1 -1
  44. package/dist/chunks/pivot-header-presentation-MkcKnjn3.js +42 -0
  45. package/dist/chunks/{pivot-result-identity-Bs4tLtLo.js → pivot-result-identity-D6hhcRXi.js} +1 -1
  46. package/dist/chunks/pivot-result-lifecycle-8qCDmpKc.js +804 -0
  47. package/dist/chunks/raw-temporal-D61lr48Y.js +1464 -0
  48. package/dist/chunks/{raw-temporal-contract-mLFS-9wk.js → raw-temporal-contract-C51YG48G.js} +1 -1
  49. package/dist/chunks/report-preferences-dialog-CWhSbc5_.js +1808 -0
  50. package/dist/chunks/{report-runtime-context-CG_I0PPW.js → report-runtime-context-B984Nq1E.js} +8 -7
  51. package/dist/chunks/save-CfJpQQ68.js +21 -0
  52. package/dist/chunks/saved-dashboard-context-Dqve2jlB.js +566 -0
  53. package/dist/chunks/{selection-reducer-CiDEtmAq.js → selection-reducer-vKIb_jS6.js} +2 -2
  54. package/dist/chunks/{semaphor-ready-indicator-CHu1L-lo.js → semaphor-ready-indicator-ldcwmLoY.js} +65803 -62954
  55. package/dist/chunks/{shelf-drop-preview-context-i-H6DFyU.js → shelf-drop-preview-context-BWxunXTq.js} +199 -196
  56. package/dist/chunks/{source-entity-resolution-C-oNyYMp.js → source-entity-resolution-CVA1a85c.js} +8 -8
  57. package/dist/chunks/switch-CvItuC1Q.js +8199 -0
  58. package/dist/chunks/{temporal-bucket-DlFuhCnT.js → temporal-bucket-D8JF7zKz.js} +86 -71
  59. package/dist/chunks/{temporal-bucket-contract-D2OuaVZ7.js → temporal-bucket-contract-DaOajRC7.js} +1 -1
  60. package/dist/chunks/{token-types-DtSJOUjh.js → token-types-bxUxXDX2.js} +1 -1
  61. package/dist/chunks/{upload-CAIpsti1.js → upload-BFX7apKV.js} +1 -1
  62. package/dist/chunks/{use-create-flow-overlay-state-Bj63WwHc.js → use-create-flow-overlay-state-RHgzVfcz.js} +331 -339
  63. package/dist/chunks/{validators-DMSH81OM.js → validators-Ej1DdCXa.js} +1050 -1510
  64. package/dist/chunks/visual-choice-JiJ-_3bi.js +204 -0
  65. package/dist/chunks/x-4f5U2XwU.js +100 -0
  66. package/dist/chunks/{zoned-wall-clock-1qlWCE20.js → zoned-wall-clock-MulfA26h.js} +2 -2
  67. package/dist/dashboard/index.js +2 -2
  68. package/dist/dashboard-authoring/index.js +823 -661
  69. package/dist/data-app-sdk/index.js +32 -30
  70. package/dist/data-app-sdk-adapters/index.js +23 -22
  71. package/dist/data-app-sdk-validation/index.js +23 -22
  72. package/dist/format-utils/index.js +173 -168
  73. package/dist/index.js +267 -258
  74. package/dist/layouts/index.js +236 -24
  75. package/dist/report-runtime-context/index.js +2 -2
  76. package/dist/style.css +1 -1
  77. package/dist/surfboard/index.js +2 -2
  78. package/dist/types/assistant-context.d.ts +2 -0
  79. package/dist/types/assistant-protocol.d.ts +2 -0
  80. package/dist/types/components/assistant/assistant-entry-points.d.ts +18 -0
  81. package/dist/types/components/assistant/assistant-provider.d.ts +19 -0
  82. package/dist/types/components/assistant/assistant-store.d.ts +52 -0
  83. package/dist/types/components/assistant/use-assistant.d.ts +38 -0
  84. package/dist/types/components/index.d.ts +5 -1
  85. package/dist/types/components/surfboard/filter/types.d.ts +5 -2
  86. package/dist/types/index.js +50 -51
  87. package/dist/types/lib/api/invalidate-token.d.ts +7 -0
  88. package/dist/types/lib/charts/cartesian-fields.d.ts +64 -0
  89. package/dist/types/lib/charts/types.d.ts +7 -0
  90. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-storage-transition.d.ts +14 -2
  91. package/dist/types/lib/dashboard-inputs/dashboard-input-target-context.d.ts +5 -6
  92. package/dist/types/lib/dashboard-inputs/dashboard-input-values.d.ts +8 -3
  93. package/dist/types/lib/dashboard-inputs/resolve-dashboard-input-context.d.ts +11 -6
  94. package/dist/types/lib/dashboard-pagination/dashboard-card-pagination.d.ts +7 -0
  95. package/dist/types/lib/dashboard-viewer/compatibility-input-storage.d.ts +79 -0
  96. package/dist/types/lib/dashboard-viewer/viewer-state.d.ts +3 -2
  97. package/dist/types/lib/document/document-table-data-policy.d.ts +15 -0
  98. package/dist/types/lib/filter-values/filter-mode.d.ts +22 -0
  99. package/dist/types/lib/hooks/use-calendar-context.d.ts +5 -0
  100. package/dist/types/lib/hooks/use-filter-option-browse.d.ts +5 -0
  101. package/dist/types/lib/hooks/use-text-filter.d.ts +9 -0
  102. package/dist/types/lib/print/print-inputs.d.ts +4 -2
  103. package/dist/types/lib/query-context/build-card-query-context.d.ts +12 -4
  104. package/dist/types/lib/query-context/build-dashboard-execution-snapshot.d.ts +93 -0
  105. package/dist/types/lib/query-context/card-server-request.d.ts +72 -0
  106. package/dist/types/lib/query-context/compile-dashboard-card-filters.d.ts +7 -0
  107. package/dist/types/lib/query-context/describe-card-execution-snapshot.d.ts +56 -0
  108. package/dist/types/lib/query-context/document-section-card-query.d.ts +45 -0
  109. package/dist/types/lib/query-context/resolve-runtime-card-filters.d.ts +17 -2
  110. package/dist/types/lib/stores/dashboard-store.d.ts +34 -11
  111. package/dist/types/lib/stores/editor-store.d.ts +4 -2
  112. package/dist/types/lib/types/token-types.d.ts +11 -0
  113. package/dist/types/lib/utils/card-type-change.d.ts +30 -0
  114. package/dist/types/lib/utils/comparison-window-caption.d.ts +12 -0
  115. package/dist/types/lib/utils/filter-default-value-utils.d.ts +13 -2
  116. package/dist/types/shared/analytics-protocol/applied-constraints.d.ts +74 -0
  117. package/dist/types/shared/analytics-protocol/contracts.d.ts +3 -0
  118. package/dist/types/shared/analytics-protocol/filter-field-ownership.d.ts +43 -0
  119. package/dist/types/shared/analytics-protocol/index.d.ts +3 -0
  120. package/dist/types/shared/analytics-protocol/matrix-window-contract.d.ts +1 -1
  121. package/dist/types/shared/analytics-protocol/visual-choice.d.ts +75 -0
  122. package/dist/types/shared/assistant-context/index.d.ts +9 -0
  123. package/dist/types/shared/assistant-context/project-context.d.ts +55 -0
  124. package/dist/types/shared/assistant-context/saved-dashboard-context.d.ts +130 -0
  125. package/dist/types/shared/assistant-protocol/add-to-dashboard.d.ts +17 -0
  126. package/dist/types/shared/assistant-protocol/artifact.d.ts +63 -0
  127. package/dist/types/shared/assistant-protocol/availability.d.ts +39 -0
  128. package/dist/types/shared/assistant-protocol/context.d.ts +952 -0
  129. package/dist/types/shared/assistant-protocol/conversation.d.ts +38 -0
  130. package/dist/types/shared/assistant-protocol/index.d.ts +16 -0
  131. package/dist/types/shared/assistant-protocol/limits.d.ts +53 -0
  132. package/dist/types/shared/assistant-protocol/parts.d.ts +140 -0
  133. package/dist/types/shared/assistant-protocol/request.d.ts +77 -0
  134. package/dist/types/shared/assistant-protocol/sources.d.ts +27 -0
  135. package/dist/types/shared/assistant-protocol/token-config.d.ts +32 -0
  136. package/dist/types/shared/assistant-protocol/transcript.d.ts +40 -0
  137. package/dist/types/shared/dashboard-authoring/card-query-request.d.ts +112 -0
  138. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +1794 -0
  139. package/dist/types/shared/dashboard-authoring/index.d.ts +5 -0
  140. package/dist/types/shared/dashboard-authoring/new-card.d.ts +10 -0
  141. package/dist/types/shared/dashboard-authoring/operations/apply-dashboard-operations.d.ts +40 -0
  142. package/dist/types/shared/dashboard-authoring/resolved-primary-date-field-validation.d.ts +16 -0
  143. package/dist/types/shared/format-utils/filter-detail.d.ts +70 -0
  144. package/dist/types/shared/format-utils/filter-value-text.d.ts +15 -0
  145. package/dist/types/shared/format-utils/index.d.ts +3 -0
  146. package/dist/types/shared/format-utils/raw-temporal.d.ts +7 -0
  147. package/dist/types/shared/format-utils/temporal-bucket.d.ts +7 -0
  148. package/dist/types/shared/layouts/frame-layouts.d.ts +23 -0
  149. package/dist/types/shared/layouts/index.d.ts +1 -0
  150. package/package.json +12 -2
  151. package/dist/chunks/calculated-field-identity-BptYhyOP.js +0 -1326
  152. package/dist/chunks/calendar-day-equality-BRjN1S9h.js +0 -383
  153. package/dist/chunks/card-config-utils-BOM1dxCk.js +0 -1150
  154. package/dist/chunks/constants-DNWVy8Y3.js +0 -9
  155. package/dist/chunks/dashboard-json-B1dEQu98.js +0 -65
  156. package/dist/chunks/field-aggregations-CoLzYHeL.js +0 -1229
  157. package/dist/chunks/index-DTcTAGGM.js +0 -4101
  158. package/dist/chunks/matrix-continuation-C4sRcjZU.js +0 -72
  159. package/dist/chunks/matrix-control-sources-DTqcA2_L.js +0 -636
  160. package/dist/chunks/matrix-definition-D9iShKZI.js +0 -87
  161. package/dist/chunks/matrix-member-presentation-Ct8GuxHt.js +0 -209
  162. package/dist/chunks/numeric-presentation-CWu3gunq.js +0 -537
  163. package/dist/chunks/pivot-header-presentation-CHs2GFrM.js +0 -753
  164. package/dist/chunks/pivot-result-lifecycle-DQz_gjGu.js +0 -789
  165. package/dist/chunks/raw-temporal-iMXRK-Qz.js +0 -930
  166. package/dist/chunks/report-preferences-dialog-DXPjteCU.js +0 -1623
  167. package/dist/chunks/save-kO6cIaob.js +0 -34
  168. package/dist/chunks/semantic-format-DiqYeKwU.js +0 -192
  169. package/dist/chunks/switch-DO8a0EfJ.js +0 -25004
  170. package/dist/chunks/temporal-input-presentation-BD7YNUzu.js +0 -195
  171. package/dist/chunks/x-CXDkqdur.js +0 -149
  172. package/dist/types/lib/class-utils.d.ts +0 -2
  173. package/dist/types/lib/document/document-input-runtime.d.ts +0 -26
  174. package/dist/types/lib/utils.d.ts +0 -51
@@ -0,0 +1,1076 @@
1
+ var ce = Object.defineProperty;
2
+ var le = (e, t, n) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var U = (e, t, n) => le(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { B as N, l as B, E as M, ad as ue, I as q, a2 as fe, U as me, V as pe, am as H, u as te, aa as ge } from "./validators-Ej1DdCXa.js";
5
+ import "./matrix-operation-contract-B8PBF1Gd.js";
6
+ import "./analytics-base-schemas-BFAoRlkU.js";
7
+ import { ZodError as he } from "zod";
8
+ import { o as be, b as ye, l as Ie, R as ne, U as ie, y as ve, X as _e, V as W, W as De, E as Fe, C as Te, Q as $e, O as ke } from "./calculated-field-identity-DcBS2NPP.js";
9
+ import { C as P } from "./common-types-CUf03Htv.js";
10
+ import { a as oe } from "./matrix-card-CJn1hB5V.js";
11
+ const J = /\[\[\s*param\.([A-Za-z0-9_.-]+)\s*\]\]/g, K = /\bparam\s*\(\s*(['"])([^'"]+)\1/g;
12
+ function Se(e) {
13
+ const t = [];
14
+ let n = 0;
15
+ for (; n < e.length; ) {
16
+ const o = e.indexOf("{{", n), i = e.indexOf("{%", n);
17
+ let r = -1, a = "";
18
+ if (o === -1 ? (r = i, a = "%}") : i === -1 || o < i ? (r = o, a = "}}") : (r = i, a = "%}"), r === -1)
19
+ break;
20
+ const s = e.indexOf(a, r + 2);
21
+ if (s === -1) {
22
+ n = r + 2;
23
+ continue;
24
+ }
25
+ t.push(e.slice(r + 2, s)), n = s + 2;
26
+ }
27
+ return t;
28
+ }
29
+ function re(e) {
30
+ var o, i;
31
+ if (!e)
32
+ return [];
33
+ const t = /* @__PURE__ */ new Set();
34
+ let n;
35
+ for (J.lastIndex = 0; (n = J.exec(e)) !== null; ) {
36
+ const r = (o = n[1]) == null ? void 0 : o.trim();
37
+ r && t.add(r);
38
+ }
39
+ for (const r of Se(e))
40
+ for (K.lastIndex = 0; (n = K.exec(r)) !== null; ) {
41
+ const a = (i = n[2]) == null ? void 0 : i.trim();
42
+ a && t.add(a);
43
+ }
44
+ return Array.from(t);
45
+ }
46
+ function at(e) {
47
+ const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
48
+ for (const o of e.controlBindings || [])
49
+ t.add(o.controlId), o.target === "sql_param" && n.set(o.paramId, o.controlId);
50
+ for (const o of re(e.sql))
51
+ t.add(n.get(o) ?? o);
52
+ return Array.from(t);
53
+ }
54
+ function st(e) {
55
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
56
+ for (const o of e.controlBindings || [])
57
+ o.target === "sql_param" && n.set(o.paramId, o.controlId);
58
+ for (const o of re(e.sql))
59
+ t.set(o, {
60
+ paramId: o,
61
+ controlId: n.get(o) ?? o
62
+ });
63
+ return Array.from(t.values());
64
+ }
65
+ function R(e) {
66
+ return (e == null ? void 0 : e.trim()) || void 0;
67
+ }
68
+ function X(e) {
69
+ return e.split(".").at(-1) || e;
70
+ }
71
+ function Q(e, t) {
72
+ var p, d;
73
+ const n = R(t);
74
+ if (!n) return;
75
+ const o = X(n), i = R((p = e.fieldMeta) == null ? void 0 : p.name);
76
+ if (i && i !== n && i !== o)
77
+ return;
78
+ const r = R(
79
+ (d = e.fieldMeta) == null ? void 0 : d.qualifiedFieldName
80
+ );
81
+ if (r && X(r) !== o)
82
+ return;
83
+ const a = n.includes(".") ? n : void 0, s = r != null && r.includes(".") ? r : void 0;
84
+ if (!(a && s && a !== s))
85
+ return {
86
+ leafName: o,
87
+ ...a || s ? {
88
+ qualifiedFieldName: a || s
89
+ } : {}
90
+ };
91
+ }
92
+ function Y(e, t) {
93
+ return Q(e, t) || Q({}, t);
94
+ }
95
+ function Z({
96
+ source: e,
97
+ sourceFieldName: t,
98
+ target: n,
99
+ targetFieldName: o
100
+ }) {
101
+ const i = Y(
102
+ e,
103
+ t
104
+ ), r = Y(
105
+ n,
106
+ o
107
+ );
108
+ return !i || !r || i.leafName !== r.leafName ? !1 : r.qualifiedFieldName ? i.qualifiedFieldName === r.qualifiedFieldName : !0;
109
+ }
110
+ function E(e, t) {
111
+ var i, r;
112
+ const n = xe(e);
113
+ if (n) return n;
114
+ const o = (r = (i = e == null ? void 0 : e.fieldMeta) == null ? void 0 : i.nativeDataType) == null ? void 0 : r.trim();
115
+ if (z(e == null ? void 0 : e.fieldMeta, t) && o && o !== "date" && o !== "datetime")
116
+ return o;
117
+ }
118
+ function xe(e) {
119
+ var n;
120
+ const t = (n = e == null ? void 0 : e.nativeDataType) == null ? void 0 : n.trim();
121
+ return t && t !== "date" && t !== "datetime" ? t : void 0;
122
+ }
123
+ function z(e, t) {
124
+ var a, s;
125
+ const n = t.trim();
126
+ if (!n) return !1;
127
+ const o = n.split(".").at(-1), i = (a = e == null ? void 0 : e.qualifiedFieldName) == null ? void 0 : a.trim();
128
+ if (i && !(i === n || !i.includes(".") && i === o))
129
+ return !1;
130
+ const r = (s = e == null ? void 0 : e.name) == null ? void 0 : s.trim();
131
+ return r && r !== n && r !== o ? !1 : !!(i || r);
132
+ }
133
+ function Ne({
134
+ fieldName: e,
135
+ definition: t,
136
+ value: n
137
+ }) {
138
+ if ((t == null ? void 0 : t.column) === e) {
139
+ const o = E(t, e);
140
+ if (o)
141
+ return o;
142
+ }
143
+ return (n == null ? void 0 : n.name) === e ? E(n, e) : void 0;
144
+ }
145
+ function Me({
146
+ definition: e,
147
+ value: t,
148
+ sourceValue: n = t
149
+ }) {
150
+ const o = e && Z({
151
+ source: e,
152
+ sourceFieldName: e.column,
153
+ target: t,
154
+ targetFieldName: t.name
155
+ }) ? e : void 0, i = n && Z({
156
+ source: n,
157
+ sourceFieldName: n.name,
158
+ target: t,
159
+ targetFieldName: t.name
160
+ }) ? n : void 0, r = (o ? E(o, o.column) : void 0) || (i ? E(i, i.name) : void 0);
161
+ return ae({
162
+ carrier: t,
163
+ nativeDataType: r,
164
+ projectNestedNativeDataType: z(
165
+ t.fieldMeta,
166
+ t.name
167
+ )
168
+ });
169
+ }
170
+ function dt({
171
+ filterDefinitions: e,
172
+ filterValues: t
173
+ }) {
174
+ if (!(e != null && e.length) || !t.length)
175
+ return t;
176
+ const n = new Map(
177
+ e.map((r) => [r.id, r])
178
+ );
179
+ let o = !1;
180
+ const i = t.map((r) => {
181
+ if (typeof r.name != "string" || !r.name.trim())
182
+ return r;
183
+ const a = n.get(r.filterId);
184
+ if (!a)
185
+ return r;
186
+ const s = Me({
187
+ definition: a,
188
+ value: r
189
+ });
190
+ return o || (o = s !== r), s;
191
+ });
192
+ return o ? i : t;
193
+ }
194
+ function ct(e) {
195
+ const t = Ne({
196
+ fieldName: e.column,
197
+ definition: e
198
+ });
199
+ return ae({
200
+ carrier: e,
201
+ nativeDataType: t,
202
+ projectNestedNativeDataType: z(
203
+ e.fieldMeta,
204
+ e.column
205
+ )
206
+ });
207
+ }
208
+ function ae({
209
+ carrier: e,
210
+ nativeDataType: t,
211
+ projectNestedNativeDataType: n
212
+ }) {
213
+ var d;
214
+ const o = (d = e.fieldMeta) == null ? void 0 : d.nativeDataType;
215
+ if (t) {
216
+ if (e.nativeDataType === t && (!e.fieldMeta || (n ? o === t : !o)))
217
+ return e;
218
+ const { nativeDataType: x, ...f } = e.fieldMeta || {};
219
+ return {
220
+ ...e,
221
+ nativeDataType: t,
222
+ ...e.fieldMeta ? {
223
+ fieldMeta: n ? {
224
+ ...e.fieldMeta,
225
+ nativeDataType: t
226
+ } : f
227
+ } : {}
228
+ };
229
+ }
230
+ if (e.nativeDataType === void 0 && o === void 0)
231
+ return e;
232
+ const {
233
+ nativeDataType: i,
234
+ fieldMeta: r,
235
+ ...a
236
+ } = e, { nativeDataType: s, ...p } = r || {};
237
+ return {
238
+ ...a,
239
+ ...r ? { fieldMeta: p } : {}
240
+ };
241
+ }
242
+ function ee(e) {
243
+ const t = /* @__PURE__ */ new Set();
244
+ for (const n of [e.name, e.sourceField]) {
245
+ if (!n) continue;
246
+ const o = N(n);
247
+ if (!o) continue;
248
+ t.add(o);
249
+ const i = o.split("."), r = i[i.length - 1];
250
+ r && t.add(r);
251
+ }
252
+ return t;
253
+ }
254
+ function se(e, t) {
255
+ const n = B(e), o = B(t);
256
+ return n === "unknown" || o === "unknown" ? !1 : (n === "date" || n === "datetime") && (o === "date" || o === "datetime") ? !0 : n === o;
257
+ }
258
+ function Ce(e, t) {
259
+ return M(e.field.source, t.field.source) && N(e.field.name) === N(t.field.name) && N(e.field.sourceField || e.field.name) === N(t.field.sourceField || t.field.name);
260
+ }
261
+ function Ae(e, t) {
262
+ if (e.kind !== "field") return !1;
263
+ const n = ee(t), o = ee(e.field);
264
+ return se(t.dataType, e.field.dataType) && [...o].some((i) => n.has(i));
265
+ }
266
+ function lt(e) {
267
+ const t = e.candidates.filter(
268
+ (n) => Ae(
269
+ n,
270
+ e.logicalValueField
271
+ )
272
+ );
273
+ return t.length === 1 ? { status: "matched", target: t[0] } : t.length > 1 ? { status: "ambiguous" } : { status: "notApplicable" };
274
+ }
275
+ function ut(e) {
276
+ const t = [];
277
+ for (const n of e.acceptedTargets)
278
+ !se(
279
+ e.logicalValueField.dataType,
280
+ n.field.dataType
281
+ ) || t.some(
282
+ (o) => Ce(o, n)
283
+ ) || t.push(n);
284
+ return t.length === 1 ? { status: "matched", target: t[0] } : t.length > 1 ? { status: "ambiguous" } : { status: "notApplicable" };
285
+ }
286
+ function we(e) {
287
+ return (e.field.sourceField || e.field.name).trim() || void 0;
288
+ }
289
+ function ft(e) {
290
+ if (e.inventory.kind !== "sql" || e.target.kind !== "field")
291
+ return { status: "ineligible" };
292
+ const t = be(
293
+ e.inventory,
294
+ e.target.field.source
295
+ ), n = we(e.target);
296
+ if (!t || !n) return { status: "ineligible" };
297
+ if (t.executionTable) {
298
+ const a = [
299
+ t.executionTable.databaseName,
300
+ t.executionTable.schemaName,
301
+ t.executionTable.tableName,
302
+ n
303
+ ].filter(Boolean).join(".");
304
+ return {
305
+ status: "eligible",
306
+ source: t.source,
307
+ executionIdentifier: a
308
+ };
309
+ }
310
+ if (e.inventory.pinnedCatalogSources.length !== 1)
311
+ return { status: "ineligible" };
312
+ const o = N(n), i = (e.candidateTargets || []).filter(
313
+ (a) => N(
314
+ a.field.sourceField || a.field.name
315
+ ) === o
316
+ ), r = [];
317
+ for (const a of i)
318
+ r.some(
319
+ (s) => M(s, a.field.source)
320
+ ) || r.push(a.field.source);
321
+ return r.length > 1 ? { status: "ineligible" } : {
322
+ status: "eligible",
323
+ source: t.source,
324
+ executionIdentifier: n
325
+ };
326
+ }
327
+ const Oe = Object.freeze({ mode: "all_applicable" });
328
+ function Ee(e) {
329
+ if (e === void 0)
330
+ return { ok: !0, dependencies: { ...Oe } };
331
+ const t = ue(e, "dashboard");
332
+ if (!t.ok)
333
+ return {
334
+ ok: !1,
335
+ error: "Invalid dashboard option dependency policy.",
336
+ issues: t.errors.map((o) => o.message)
337
+ };
338
+ const n = e;
339
+ switch (n.mode) {
340
+ case "independent":
341
+ return { ok: !0, dependencies: { mode: "independent" } };
342
+ case "explicit":
343
+ return {
344
+ ok: !0,
345
+ dependencies: {
346
+ mode: "explicit",
347
+ includeInputIds: [...n.includeInputIds || []]
348
+ }
349
+ };
350
+ case "all_applicable":
351
+ return {
352
+ ok: !0,
353
+ dependencies: {
354
+ mode: "all_applicable",
355
+ ...n.excludeInputIds ? { excludeInputIds: [...n.excludeInputIds] } : {}
356
+ }
357
+ };
358
+ default:
359
+ return {
360
+ ok: !1,
361
+ error: "Invalid dashboard option dependency policy.",
362
+ issues: ["Dashboard option dependencies must declare a mode."]
363
+ };
364
+ }
365
+ }
366
+ function Re(e) {
367
+ if (e === void 0) return { ok: !0, population: void 0 };
368
+ const t = { ok: !1, error: "Invalid option population." };
369
+ if (!e || typeof e != "object" || Array.isArray(e)) return t;
370
+ const n = e;
371
+ if (n.kind === "option_source")
372
+ return { ok: !0, population: { kind: "option_source" } };
373
+ if (n.kind !== "related_population") return t;
374
+ const o = n.baseSource;
375
+ if (!o || o.kind !== "semantic" || !q(o))
376
+ return t;
377
+ const i = n.relationshipHint;
378
+ return i !== void 0 && (!i || typeof i != "object" || i.relationshipIds !== void 0 && (!Array.isArray(i.relationshipIds) || i.relationshipIds.some(
379
+ (r) => typeof r != "string" || !r.trim()
380
+ ))) ? t : {
381
+ ok: !0,
382
+ population: {
383
+ kind: "related_population",
384
+ baseSource: o,
385
+ ...i ? { relationshipHint: i } : {}
386
+ }
387
+ };
388
+ }
389
+ function mt(e) {
390
+ const { dependencies: t } = e, n = /* @__PURE__ */ new Set([
391
+ e.targetInputId,
392
+ ...t.excludeInputIds || []
393
+ ]);
394
+ return t.mode === "independent" ? [] : t.mode === "explicit" ? (t.includeInputIds || []).filter(
395
+ (o) => !n.has(o)
396
+ ) : e.peerInputIds.filter((o) => !n.has(o));
397
+ }
398
+ function pt(e, t, n) {
399
+ if (t === n) return e;
400
+ let o = !1;
401
+ const i = (a) => a != null && a.includes(t) ? (o = !0, Array.from(
402
+ new Set(a.map((s) => s === t ? n : s))
403
+ )) : a, r = e.map((a) => {
404
+ const s = a.optionDependencies;
405
+ if (!s) return a;
406
+ const p = i(s.includeInputIds), d = i(s.excludeInputIds);
407
+ return p === s.includeInputIds && d === s.excludeInputIds ? a : {
408
+ ...a,
409
+ optionDependencies: {
410
+ ...s,
411
+ ...p ? { includeInputIds: p } : {},
412
+ ...d ? { excludeInputIds: d } : {}
413
+ }
414
+ };
415
+ });
416
+ return o ? r : e;
417
+ }
418
+ function gt(e, t) {
419
+ const n = Be(
420
+ e.dependencies,
421
+ t
422
+ );
423
+ return n === e.dependencies ? e : { ...e, dependencies: n };
424
+ }
425
+ function Be(e, t) {
426
+ if (!(t != null && t.length) || e.mode !== "explicit")
427
+ return e;
428
+ const n = new Set(e.includeInputIds || []), o = Array.from(new Set(t)).filter(
429
+ (i) => n.has(i)
430
+ );
431
+ return o.length ? { ...e, omitInputIds: o } : e;
432
+ }
433
+ class Pe extends Error {
434
+ constructor(n) {
435
+ super(n.map((o) => o.message).join(" "));
436
+ U(this, "issues");
437
+ this.name = "DashboardFilterMappingContractError", this.issues = n;
438
+ }
439
+ }
440
+ const qe = {
441
+ string: !0,
442
+ number: !0,
443
+ boolean: !0,
444
+ date: !0,
445
+ datetime: !0
446
+ };
447
+ function I(e) {
448
+ return typeof e == "string" && e.trim().length > 0;
449
+ }
450
+ function b(e) {
451
+ return !!e && typeof e == "object" && !Array.isArray(e);
452
+ }
453
+ function O(e) {
454
+ return Array.isArray(e) && e.every((t) => typeof t == "string");
455
+ }
456
+ function ze(e) {
457
+ if (!b(e)) return !1;
458
+ switch (e.kind) {
459
+ case "allSheets":
460
+ return e.sheetKinds === void 0 || O(e.sheetKinds) && e.sheetKinds.every(
461
+ (t) => t === "dashboard" || t === "document"
462
+ );
463
+ case "sheets":
464
+ return O(e.sheetIds);
465
+ case "cards":
466
+ return O(e.cardIds);
467
+ case "documentSections":
468
+ return I(e.sheetId) && O(e.sectionIds);
469
+ default:
470
+ return !1;
471
+ }
472
+ }
473
+ function Le(e) {
474
+ return e === "shared" || e === "perSheet" || e === "perCard" || e === "perDocumentSection";
475
+ }
476
+ function je(e) {
477
+ return b(e) ? I(e.id) && I(e.column) && I(e.dataType) : !1;
478
+ }
479
+ function Ge(e, t, n, o) {
480
+ var s;
481
+ if (!b(t)) {
482
+ o.push({
483
+ code: "invalid_option_source",
484
+ path: n,
485
+ message: `${n} must be a semantic or physical option source.`,
486
+ inputId: e
487
+ });
488
+ return;
489
+ }
490
+ const i = t.source, r = [
491
+ ["labelField", t.labelField],
492
+ ["valueField", t.valueField],
493
+ ["searchField", t.searchField]
494
+ ];
495
+ if (!b(i) || i.kind !== "semantic" && i.kind !== "physical" || !q(i) || !b(t.labelField) || !b(t.valueField) || t.searchField !== void 0 && !b(t.searchField) || t.disambiguationFields !== void 0 && (!Array.isArray(t.disambiguationFields) || !t.disambiguationFields.every(b))) {
496
+ o.push({
497
+ code: "invalid_option_source",
498
+ path: n,
499
+ message: `${n} must contain a valid semantic or physical source and field references.`,
500
+ inputId: e
501
+ });
502
+ return;
503
+ }
504
+ for (const [p, d] of r)
505
+ d !== void 0 && b(d) && (!I(d.name) || d.source !== void 0 && !M(
506
+ d.source,
507
+ i
508
+ )) && o.push({
509
+ code: "invalid_option_source",
510
+ path: `${n}.${p}`,
511
+ message: `${n}.${p} must be a named field belonging to the declared option source.`,
512
+ inputId: e
513
+ });
514
+ for (const [p, d] of ((s = t.disambiguationFields) == null ? void 0 : s.entries()) || [])
515
+ (!b(d) || !I(d.name) || d.source !== void 0 && !M(
516
+ d.source,
517
+ i
518
+ )) && o.push({
519
+ code: "invalid_option_source",
520
+ path: `${n}.disambiguationFields[${p}]`,
521
+ message: `${n}.disambiguationFields[${p}] must be a named field belonging to the declared option source.`,
522
+ inputId: e
523
+ });
524
+ const a = t.valueField;
525
+ ["string", "number", "boolean", "date", "datetime"].includes(
526
+ String(a.dataType)
527
+ ) || o.push({
528
+ code: "invalid_option_source",
529
+ path: `${n}.valueField.dataType`,
530
+ message: `${n}.valueField.dataType must be a known option-value datatype.`,
531
+ inputId: e
532
+ });
533
+ }
534
+ function Ve(e, t, n) {
535
+ var o;
536
+ if (e.optionDependencies !== void 0) {
537
+ const i = Ee(e.optionDependencies);
538
+ i.ok ? b(e.optionDependencies) && e.optionDependencies.omitInputIds !== void 0 && n.push({
539
+ code: "invalid_option_dependencies",
540
+ path: `${t}.optionDependencies.omitInputIds`,
541
+ message: `${t}.optionDependencies cannot persist a browse override (omitInputIds).`,
542
+ inputId: e.id
543
+ }) : n.push({
544
+ code: "invalid_option_dependencies",
545
+ path: `${t}.optionDependencies`,
546
+ message: `${t}.optionDependencies ${i.issues.join("; ") || i.error}`,
547
+ inputId: e.id
548
+ });
549
+ }
550
+ if (e.optionPopulation !== void 0) {
551
+ const i = Re(e.optionPopulation);
552
+ i.ok ? ((o = i.population) == null ? void 0 : o.kind) === "related_population" && !Ue(e.optionSource) && n.push({
553
+ code: "invalid_option_population",
554
+ path: `${t}.optionPopulation`,
555
+ message: `${t}.optionPopulation related_population requires an authored semantic optionSource.`,
556
+ inputId: e.id
557
+ }) : n.push({
558
+ code: "invalid_option_population",
559
+ path: `${t}.optionPopulation`,
560
+ message: `${t}.optionPopulation must be option_source or a related_population with a complete semantic baseSource.`,
561
+ inputId: e.id
562
+ });
563
+ }
564
+ }
565
+ function Ue(e) {
566
+ return b(e) && b(e.source) && e.source.kind === "semantic";
567
+ }
568
+ function He(e, t, n, o, i, r) {
569
+ var d;
570
+ if (I(t.bindingId) || i.push({
571
+ code: "invalid_binding_id",
572
+ path: `${n}.bindingId`,
573
+ message: `${n}.bindingId must be an opaque non-empty id.`,
574
+ inputId: e,
575
+ cardId: t.cardId
576
+ }), ((d = t.target) == null ? void 0 : d.kind) !== "field") {
577
+ i.push({
578
+ code: "unsupported_target",
579
+ path: `${n}.target`,
580
+ message: `${n}.target must be one direct field target.`,
581
+ inputId: e,
582
+ cardId: t.cardId,
583
+ bindingId: t.bindingId
584
+ });
585
+ return;
586
+ }
587
+ const a = t.target.field;
588
+ if (!I(a == null ? void 0 : a.name) || !a.source || a.source.kind !== "semantic" && a.source.kind !== "physical" || !q(a.source)) {
589
+ i.push({
590
+ code: "invalid_target_field",
591
+ path: `${n}.target.field`,
592
+ message: `${n}.target.field must have a name and a source-qualified semantic or physical identity.`,
593
+ inputId: e,
594
+ cardId: t.cardId,
595
+ bindingId: t.bindingId
596
+ });
597
+ return;
598
+ }
599
+ if (Object.prototype.hasOwnProperty.call(
600
+ qe,
601
+ a.dataType
602
+ ) || i.push({
603
+ code: "unknown_target_data_type",
604
+ path: `${n}.target.field.dataType`,
605
+ message: `${n}.target.field.dataType must be known.`,
606
+ inputId: e,
607
+ cardId: t.cardId,
608
+ bindingId: t.bindingId
609
+ }), a.sourceField !== void 0 && !I(a.sourceField) && i.push({
610
+ code: "invalid_target_field",
611
+ path: `${n}.target.field.sourceField`,
612
+ message: `${n}.target.field.sourceField must be a non-empty catalog-grounded column when provided.`,
613
+ inputId: e,
614
+ cardId: t.cardId,
615
+ bindingId: t.bindingId
616
+ }), !r) return;
617
+ const s = o.get(t.cardId);
618
+ if (!s) {
619
+ i.push({
620
+ code: "unknown_card",
621
+ path: `${n}.cardId`,
622
+ message: `${n}.cardId '${t.cardId}' does not exist.`,
623
+ inputId: e,
624
+ cardId: t.cardId,
625
+ bindingId: t.bindingId
626
+ });
627
+ return;
628
+ }
629
+ const p = ye(s);
630
+ (p.kind === "unconfigured" || !Ie(p, a.source)) && i.push({
631
+ code: "unavailable_card_source",
632
+ path: `${n}.target.field.source`,
633
+ message: `${n}.target field source is not declared by card '${s.id}'.`,
634
+ inputId: e,
635
+ cardId: s.id,
636
+ bindingId: t.bindingId
637
+ });
638
+ }
639
+ function We(e, t, n, o, i, r) {
640
+ if (t === void 0) return;
641
+ if (!b(t) || t.kind !== "cardMappings" || !Array.isArray(t.cards)) {
642
+ i.push({
643
+ code: "invalid_application",
644
+ path: n,
645
+ message: `${n} must be a cardMappings application with a cards array.`,
646
+ inputId: e
647
+ });
648
+ return;
649
+ }
650
+ const a = /* @__PURE__ */ new Set();
651
+ t.cards.forEach((s, p) => {
652
+ const d = `${n}.cards[${p}]`;
653
+ if (!I(s == null ? void 0 : s.cardId)) {
654
+ i.push({
655
+ code: "unknown_card",
656
+ path: `${d}.cardId`,
657
+ message: `${d}.cardId is required.`,
658
+ inputId: e
659
+ });
660
+ return;
661
+ }
662
+ if (a.has(s.cardId)) {
663
+ i.push({
664
+ code: "duplicate_card_application",
665
+ path: `${d}.cardId`,
666
+ message: `${n} contains more than one entry for card '${s.cardId}'.`,
667
+ inputId: e,
668
+ cardId: s.cardId
669
+ });
670
+ return;
671
+ }
672
+ if (a.add(s.cardId), r && !o.has(s.cardId)) {
673
+ i.push({
674
+ code: "unknown_card",
675
+ path: `${d}.cardId`,
676
+ message: `${d}.cardId '${s.cardId}' does not exist.`,
677
+ inputId: e,
678
+ cardId: s.cardId
679
+ });
680
+ return;
681
+ }
682
+ s.kind === "bound" ? He(
683
+ e,
684
+ s,
685
+ d,
686
+ o,
687
+ i,
688
+ r
689
+ ) : s.kind !== "excluded" && i.push({
690
+ code: "invalid_application",
691
+ path: d,
692
+ message: `${d}.kind must be 'bound' or 'excluded'.`,
693
+ inputId: e,
694
+ cardId: s.cardId
695
+ });
696
+ });
697
+ }
698
+ function Je({
699
+ inputs: e,
700
+ dashboardFilters: t,
701
+ cards: n = [],
702
+ validateCardTargets: o = !1
703
+ }) {
704
+ const i = [], r = new Map(
705
+ (t || []).map((d) => [d.id, d])
706
+ ), a = new Map(
707
+ o ? n.map((d) => [d.id, d]) : []
708
+ ), s = [], p = /* @__PURE__ */ new Map();
709
+ return e != null && !Array.isArray(e) ? (i.push({
710
+ code: "invalid_input",
711
+ path: "dashboard.inputs",
712
+ message: "dashboard.inputs must be an array when present."
713
+ }), { ok: !1, inputs: s, issues: i }) : ((Array.isArray(e) ? e : []).forEach((d, x) => {
714
+ const f = `dashboard.inputs[${x}]`;
715
+ if (!b(d) || d.kind !== "filter" && d.kind !== "control" || !I(d.id) || !I(d.label) || !I(d.variableName) || !ze(d.scope) || !Le(d.runtimeScope)) {
716
+ i.push({
717
+ code: "invalid_input",
718
+ path: f,
719
+ message: `${f} must be a complete filter or control Dashboard Input envelope.`,
720
+ inputId: b(d) && typeof d.id == "string" ? d.id : void 0
721
+ });
722
+ return;
723
+ }
724
+ if (d.kind === "control" && !b(d.control)) {
725
+ i.push({
726
+ code: "invalid_input",
727
+ path: `${f}.control`,
728
+ message: `${f}.control must be a control definition.`,
729
+ inputId: d.id
730
+ });
731
+ return;
732
+ }
733
+ const l = d;
734
+ if (l.kind === "control") {
735
+ s.push(l);
736
+ return;
737
+ }
738
+ const v = l.filter, F = l.filterReference, c = v !== void 0, m = !!F;
739
+ if (c && m) {
740
+ i.push({
741
+ code: "both_filter_definitions",
742
+ path: f,
743
+ message: `${f} must contain either filter or filterReference, not both.`,
744
+ inputId: l.id
745
+ });
746
+ return;
747
+ }
748
+ if (!c && !m) {
749
+ i.push({
750
+ code: "missing_filter_definition",
751
+ path: f,
752
+ message: `${f} must contain filter or filterReference.`,
753
+ inputId: l.id
754
+ });
755
+ return;
756
+ }
757
+ if (c && !je(v)) {
758
+ i.push({
759
+ code: "invalid_input",
760
+ path: `${f}.filter`,
761
+ message: `${f}.filter must be a complete dashboard filter definition.`,
762
+ inputId: l.id
763
+ });
764
+ return;
765
+ }
766
+ let u, h;
767
+ if (c)
768
+ u = v, h = "embedded";
769
+ else {
770
+ if ((F == null ? void 0 : F.kind) !== "dashboardFilter") {
771
+ i.push({
772
+ code: "invalid_filter_reference",
773
+ path: `${f}.filterReference.kind`,
774
+ message: `${f}.filterReference.kind must be 'dashboardFilter'.`,
775
+ inputId: l.id
776
+ });
777
+ return;
778
+ }
779
+ const k = typeof (F == null ? void 0 : F.filterId) == "string" ? F.filterId : void 0;
780
+ if (u = k ? r.get(k) : void 0, h = "dashboardFilter", !u) {
781
+ i.push({
782
+ code: "orphaned_filter_reference",
783
+ path: `${f}.filterReference.filterId`,
784
+ message: `${f}.filterReference cannot resolve dashboard filter '${k || ""}'.`,
785
+ inputId: l.id
786
+ });
787
+ return;
788
+ }
789
+ if (u.kind === "global-date") {
790
+ i.push({
791
+ code: "global_date_reference",
792
+ path: `${f}.filterReference`,
793
+ message: `${f}.filterReference cannot reference the Global Date filter.`,
794
+ inputId: l.id
795
+ });
796
+ return;
797
+ }
798
+ const S = p.get(u.id);
799
+ if (S) {
800
+ i.push({
801
+ code: "duplicate_filter_reference",
802
+ path: `${f}.filterReference.filterId`,
803
+ message: `${f}.filterReference duplicates dashboard filter '${u.id}' already owned by Dashboard Input '${S}'.`,
804
+ inputId: l.id
805
+ });
806
+ return;
807
+ }
808
+ p.set(u.id, l.id);
809
+ }
810
+ if (!u) return;
811
+ if (l.forceSelection !== void 0 && typeof l.forceSelection != "boolean" && i.push({
812
+ code: "invalid_input",
813
+ path: `${f}.forceSelection`,
814
+ message: `${f}.forceSelection must be a boolean.`,
815
+ inputId: l.id
816
+ }), l.optionSource !== void 0 && Ge(
817
+ l.id,
818
+ l.optionSource,
819
+ `${f}.optionSource`,
820
+ i
821
+ ), Ve(l, f, i), l.application && u.kind === "global-date") {
822
+ i.push({
823
+ code: "global_date_reference",
824
+ path: `${f}.application`,
825
+ message: `${f}.application cannot map the Global Date filter.`,
826
+ inputId: l.id
827
+ });
828
+ return;
829
+ }
830
+ l.application && l.scope.kind !== "allSheets" && l.scope.kind !== "sheets" && i.push({
831
+ code: "unsupported_mapped_scope",
832
+ path: `${f}.scope`,
833
+ message: `${f}.scope must be allSheets or sheets when cardMappings are present.`,
834
+ inputId: l.id
835
+ }), We(
836
+ l.id,
837
+ l.application,
838
+ `${f}.application`,
839
+ a,
840
+ i,
841
+ o
842
+ );
843
+ const {
844
+ filter: $,
845
+ filterReference: L,
846
+ // A reference-backed authored input must shadow the generated
847
+ // dashboard-filter compatibility input. Older writers may have copied
848
+ // the compatibility marker onto the reference; never preserve it.
849
+ compatibility: C,
850
+ ...w
851
+ } = l;
852
+ s.push({
853
+ ...w,
854
+ filter: u,
855
+ ...c && C ? { compatibility: C } : {},
856
+ ...l.optionSource ? {
857
+ optionSource: l.optionSource
858
+ } : {},
859
+ ...l.optionDependencies ? { optionDependencies: l.optionDependencies } : {},
860
+ ...l.optionPopulation ? { optionPopulation: l.optionPopulation } : {},
861
+ definitionOrigin: h
862
+ });
863
+ }), i.length ? { ok: !1, inputs: s, issues: i } : { ok: !0, inputs: s });
864
+ }
865
+ function ht(e) {
866
+ const t = Je(e);
867
+ if (!t.ok) throw new Pe(t.issues);
868
+ return t.inputs;
869
+ }
870
+ function bt(e = () => globalThis.crypto.randomUUID()) {
871
+ return e();
872
+ }
873
+ function Ke(e, t) {
874
+ return e.name === t.name && e.qualifiedEntityName === t.qualifiedEntityName;
875
+ }
876
+ function yt(e, t, n) {
877
+ var i, r;
878
+ if (n.sortPolicy === "dropUnrelatedSorts") {
879
+ const a = new Set(
880
+ (e.metricColumns || []).map((s) => s.id)
881
+ );
882
+ return {
883
+ ...e,
884
+ groupByColumns: [t],
885
+ sortByColumns: (e.sortByColumns || []).filter(
886
+ (s) => s.id === t.id || a.has(s.id)
887
+ )
888
+ };
889
+ }
890
+ const o = (i = e.groupByColumns) == null ? void 0 : i[0];
891
+ return {
892
+ ...e,
893
+ groupByColumns: [t],
894
+ sortByColumns: (r = e.sortByColumns) == null ? void 0 : r.map(
895
+ (a) => o && Ke(a, o) ? {
896
+ ...t,
897
+ role: "sortby",
898
+ direction: a.direction
899
+ } : a
900
+ )
901
+ };
902
+ }
903
+ const Xe = /* @__PURE__ */ new Set([
904
+ "day",
905
+ "week",
906
+ "month",
907
+ "quarter",
908
+ "year",
909
+ "hour",
910
+ "minute",
911
+ "second"
912
+ ]);
913
+ function It(e) {
914
+ let t = e.spec;
915
+ const n = ne(
916
+ e.controlDefinitions || [],
917
+ e.cardControlDefinitions || []
918
+ ), o = (e.controlBindings || []).filter(
919
+ (c) => c.target !== "sql_param"
920
+ ), i = o.filter(
921
+ (c) => c.target === "config_metric_selector" || c.target === "config_field_selector"
922
+ ), r = o.filter(
923
+ (c) => c.target === "config_grain" || c.target === "config_aggregation"
924
+ ), a = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map();
925
+ let p;
926
+ const d = () => {
927
+ if (p) return p;
928
+ const c = e.catalog, m = /* @__PURE__ */ new Map();
929
+ for (const u of c) {
930
+ const h = m.get(u.id) ?? [];
931
+ m.set(u.id, [...h, u]);
932
+ }
933
+ return p = { refs: c, byId: m }, p;
934
+ }, x = (c, m) => {
935
+ throw new $e(c, {
936
+ code: ke,
937
+ ...m ? { controlId: m } : {}
938
+ });
939
+ }, f = (c, m) => {
940
+ var h;
941
+ if (c.derivedField) return c.derivedField.dataType;
942
+ const u = d().refs.filter(($) => $.field.name === c.name && M($.field.source ?? e.spec.source, c.source ?? e.spec.source));
943
+ return u.length > 1 ? x("The selected field is ambiguous in the authorized Matrix field catalog.", m) : B(((h = u[0]) == null ? void 0 : h.field.dataType) ?? c.dataType);
944
+ }, l = (c, m) => ve(c, m.target, (u) => f(u, m.controlId)), v = fe.safeParse(t);
945
+ if (!v.success) return x(v.error.message);
946
+ t = v.data;
947
+ const F = [...i, ...r].map((c) => {
948
+ const m = ie({ binding: c, definitions: n, controlValues: e.controlValues }), u = !c.matrixTargetId && m !== void 0 && m !== P ? l(v.data, c) : [];
949
+ return {
950
+ binding: c,
951
+ selectedValue: m,
952
+ targetId: c.matrixTargetId ?? (u.length === 1 ? u[0].id : void 0)
953
+ };
954
+ });
955
+ for (const { binding: c, targetId: m, selectedValue: u } of F) {
956
+ if (u === void 0 || u === P)
957
+ continue;
958
+ const h = (g) => x(g, c.controlId), $ = c.target === "config_metric_selector" || c.target === "config_aggregation", L = l(t, c);
959
+ (!m || !L.some((g) => g.id === m)) && h("Choose a valid Matrix level or measure target for this control.");
960
+ const C = `${c.target}:${m}`;
961
+ a.has(C) && h("Multiple controls cannot replace the same Matrix target."), a.add(C);
962
+ const w = (g) => {
963
+ const y = (d().byId.get(g.id) ?? []).filter((D) => !g.source || M(g.source, D.field.source ?? e.spec.source));
964
+ if (y.length !== 1) return h(y.length ? "The selected field is ambiguous in the authorized Matrix field catalog." : "The selected field is not in the authorized Matrix field catalog.");
965
+ const T = pe.safeParse(y[0].field);
966
+ return T.success ? T.data : h(T.error.message);
967
+ }, k = c.target === "config_metric_selector" || c.target === "config_field_selector" ? c.mapping[u] : void 0, S = k && typeof k == "object" && "kind" in k && k.kind === "matrix_instance" ? k.id : void 0;
968
+ if ($) {
969
+ s.set(m, c.controlId);
970
+ const g = S === void 0 ? void 0 : v.data.measures.find(
971
+ (_) => _.id === S && _.kind === "aggregate"
972
+ );
973
+ S !== void 0 && !g && h("The selected Matrix aggregate measure is no longer available.");
974
+ const y = c.target === "config_metric_selector" && !g ? _e({ binding: c, selectedValue: u }) : void 0, T = ((g == null ? void 0 : g.kind) === "aggregate" ? g.aggregate : y == null ? void 0 : y.aggregate) ?? (c.target === "config_aggregation" ? W({ binding: c, selectedValue: u }) : void 0), D = T === void 0 ? void 0 : me.safeParse(T);
975
+ D && !D.success && h("This aggregation is not supported by Matrix."), t = {
976
+ ...t,
977
+ measures: t.measures.map(
978
+ (_) => _.id !== m || _.kind !== "aggregate" ? _ : {
979
+ ..._,
980
+ ...y ? { field: w(y) } : {},
981
+ ...(g == null ? void 0 : g.kind) === "aggregate" ? { field: g.field } : {},
982
+ aggregate: D != null && D.success ? D.data : _.aggregate
983
+ }
984
+ )
985
+ };
986
+ } else {
987
+ const g = S === void 0 ? void 0 : [...v.data.rows, ...v.data.columns].find(
988
+ (_) => _.id === S
989
+ );
990
+ S !== void 0 && !g && h("The selected Matrix level is no longer available.");
991
+ const y = c.target === "config_field_selector" && !g ? De({ binding: c, selectedValue: u }) : void 0, T = c.target === "config_grain" ? W({ binding: c, selectedValue: u }) : g ? g.grain : y == null ? void 0 : y.granularity;
992
+ T !== void 0 && !Xe.has(T) && h("This time grain is not supported by Matrix.");
993
+ const D = (_) => _.map((A) => {
994
+ if (A.id !== m) return A;
995
+ const j = (g == null ? void 0 : g.field) ?? (y ? w(y) : A.field), G = f(j, c.controlId), V = T ?? (y && H(G) ? A.grain : void 0);
996
+ return V && !H(G) && h("A time grain requires a temporal Matrix level."), { ...A, field: j, grain: V };
997
+ });
998
+ t = {
999
+ ...t,
1000
+ rows: D(t.rows),
1001
+ columns: D(t.columns)
1002
+ };
1003
+ }
1004
+ }
1005
+ for (const [c, m] of Array.from(s)) {
1006
+ const u = t.measures.find(($) => $.id === c);
1007
+ if (!u || u.kind !== "aggregate") continue;
1008
+ const h = f(u.field, m);
1009
+ Fe(h).some(($) => $.value === u.aggregate) || x(`Aggregation '${u.aggregate}' is not eligible for this Matrix field datatype.`, m);
1010
+ }
1011
+ try {
1012
+ return Te(v.data, t);
1013
+ } catch (c) {
1014
+ if (c instanceof he) return x(c.message);
1015
+ throw c;
1016
+ }
1017
+ }
1018
+ function de(e, t) {
1019
+ const n = [], o = (i) => {
1020
+ if (i.source) {
1021
+ const r = ge.safeParse(i.source);
1022
+ if (r.success) n.push(r.data);
1023
+ else if (t) throw r.error;
1024
+ }
1025
+ i.derivedField && Object.values(i.derivedField.inputs).forEach((r) => o(r.field));
1026
+ };
1027
+ for (const i of e) {
1028
+ if (i.target !== "config_field_selector" && i.target !== "config_metric_selector") continue;
1029
+ const r = t == null ? void 0 : t.get(i), a = t ? r && r !== P ? [i.mapping[r]] : [] : Object.values(i.mapping);
1030
+ for (const s of a)
1031
+ s && "role" in s && o(s);
1032
+ }
1033
+ return n;
1034
+ }
1035
+ function vt(e, t = [], n = []) {
1036
+ return te([...oe(e), ...de(t), ...n]);
1037
+ }
1038
+ function _t(e, t = {}) {
1039
+ const n = t.controlBindings ?? [], o = ne(t.controlDefinitions ?? [], t.cardControlDefinitions ?? []), i = new Map(n.filter((r) => r.target === "config_field_selector" || r.target === "config_metric_selector").map((r) => [r, ie({ binding: r, definitions: o, controlValues: t.controlValues })]));
1040
+ return te([...oe(e), ...de(n, i)]);
1041
+ }
1042
+ function Qe(e) {
1043
+ return (e == null ? void 0 : e.kind) === "document";
1044
+ }
1045
+ function Dt(e) {
1046
+ return (e || []).filter((t) => !Qe(t));
1047
+ }
1048
+ export {
1049
+ Pe as D,
1050
+ vt as a,
1051
+ _t as b,
1052
+ ut as c,
1053
+ Ae as d,
1054
+ st as e,
1055
+ ft as f,
1056
+ ht as g,
1057
+ bt as h,
1058
+ yt as i,
1059
+ It as j,
1060
+ Oe as k,
1061
+ Ee as l,
1062
+ Me as m,
1063
+ Je as n,
1064
+ Re as o,
1065
+ pt as p,
1066
+ Be as q,
1067
+ lt as r,
1068
+ mt as s,
1069
+ Qe as t,
1070
+ ct as u,
1071
+ dt as v,
1072
+ gt as w,
1073
+ at as x,
1074
+ Dt as y,
1075
+ re as z
1076
+ };