react-semaphor 0.1.568 → 0.1.570

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 (191) hide show
  1. package/README.md +0 -7
  2. package/dist/analytics-protocol/index.js +434 -454
  3. package/dist/appearance/index.js +6 -3
  4. package/dist/appearance-runtime/index.js +1 -1
  5. package/dist/assistant-context/index.js +1 -1
  6. package/dist/brand-studio/index.js +572 -436
  7. package/dist/briefings/index.js +4 -4
  8. package/dist/chunks/appearance-context-BwBp25ZG.js +162 -0
  9. package/dist/chunks/appearance-runtime-provider-BRHYELkC.js +80 -0
  10. package/dist/chunks/assistant-chat-B-Ddyy8b.js +5940 -0
  11. package/dist/chunks/{bookmark-impact-CJ-65omV.js → bookmark-impact-DCYD-6Fr.js} +2 -2
  12. package/dist/chunks/{bookmark-state-Du3s13_V.js → bookmark-state-CflS88gq.js} +251 -250
  13. package/dist/chunks/brand-B4BdpAB_.js +54 -0
  14. package/dist/chunks/{card-filter-builder-BBuB99GZ.js → card-filter-builder-0VvKmRst.js} +992 -991
  15. package/dist/chunks/{comparison-window-caption-CMLb3mut.js → comparison-window-caption-PtcDWvkN.js} +252 -253
  16. package/dist/chunks/{dashboard-YnWZC4dK.js → dashboard-DxGIr1vZ.js} +1 -1
  17. package/dist/chunks/{dashboard-briefing-launcher-BF89TU2h.js → dashboard-briefing-launcher-B-quOOOQ.js} +253 -253
  18. package/dist/chunks/{dashboard-controls-atHc1EjP.js → dashboard-controls-Caodx80b.js} +288 -285
  19. package/dist/chunks/dashboard-json-Ct-AGDHF.js +66 -0
  20. package/dist/chunks/{dates-CKO05ino.js → dates-B9mL8BHE.js} +16 -15
  21. package/dist/chunks/edit-Bpdh_P_a.js +226 -0
  22. package/dist/chunks/{edit-dashboard-visual-DdmTfn-J.js → edit-dashboard-visual-DeDTuYB5.js} +2257 -2270
  23. package/dist/chunks/{filter-reach-copy-jZGzK_IH.js → filter-reach-copy-BSY33ro5.js} +1440 -1301
  24. package/dist/chunks/filter-value-text-DvvSNlho.js +146 -0
  25. package/dist/chunks/index-BVKzKl5d.js +90 -0
  26. package/dist/chunks/{index-RNaTnE3m.js → index-CV_Kzou0.js} +233 -223
  27. package/dist/chunks/{index-CPNZW0mu.js → index-y3HUzRNk.js} +76 -77
  28. package/dist/chunks/{layout-grid-0hIlqEtk.js → layout-grid-8rR-LPTk.js} +1 -1
  29. package/dist/chunks/{list-filter-DkgoCeBm.js → list-filter-C1-uTgjR.js} +1 -1
  30. package/dist/chunks/matrix-analytical-definition-dkS8szLM.js +1253 -0
  31. package/dist/chunks/matrix-member-presentation-DRa-9e6Q.js +169 -0
  32. package/dist/chunks/{matrix-operation-contract-Eb6elidS.js → matrix-operation-contract-DCVinw1o.js} +122 -122
  33. package/dist/chunks/{metric-comparison-ChXUFaZu.js → metric-comparison-n9NsIa-2.js} +175 -128
  34. package/dist/chunks/paintbrush-aR17Z3C9.js +27 -0
  35. package/dist/chunks/{palette-4vf2BEEg.js → palette-a5FCZKFI.js} +1 -1
  36. package/dist/chunks/{_commonjsHelpers-DimLPMtv.js → pickers-DkqmtnTL.js} +352 -290
  37. package/dist/chunks/pivot-result-contract-expectations-C-HnUKYe.js +55 -0
  38. package/dist/chunks/{pivot-result-identity-BlbLrqaC.js → pivot-result-identity-B89X5xjb.js} +1 -1
  39. package/dist/chunks/raw-temporal-value-DdT0s47W.js +159 -0
  40. package/dist/chunks/{report-preferences-dialog-Mbd-I0wV.js → report-preferences-dialog-Yvhv3WX2.js} +95 -97
  41. package/dist/chunks/{report-runtime-context-DnA_PiKo.js → report-runtime-context-BhPzLTbS.js} +1 -1
  42. package/dist/chunks/{resolve-dashboard-input-context-Du0fjN3h.js → resolve-dashboard-input-context-Lkbwycwe.js} +5491 -5683
  43. package/dist/chunks/resolver-DG_tfEpt.js +156 -0
  44. package/dist/chunks/{save-D6pHmSSP.js → save-D985VvYp.js} +1 -1
  45. package/dist/chunks/{saved-dashboard-context-y8N6RvjS.js → saved-dashboard-context-DC_TEd6y.js} +6 -6
  46. package/dist/chunks/schema-C9NPiIru.js +2568 -0
  47. package/dist/chunks/{semaphor-ready-indicator-BSEdUq40.js → semaphor-ready-indicator-ByFvqHEO.js} +35916 -36001
  48. package/dist/chunks/{shelf-drop-preview-context-D7QqPl36.js → shelf-drop-preview-context-CjoVaK6J.js} +64 -66
  49. package/dist/chunks/{stored-dashboard-d3xQYxBD.js → stored-dashboard-C0hekXiI.js} +332 -333
  50. package/dist/chunks/{code-editor-DJNOsgJH.js → style-sheet-parts-C7qGZuH1.js} +2402 -2040
  51. package/dist/chunks/{table-export-sheet--DUKWk6o.js → table-export-sheet-CP8zSOhj.js} +1 -1
  52. package/dist/chunks/{temporal-input-presentation--2r9BLr0.js → temporal-input-presentation-CqbJjIuu.js} +18 -18
  53. package/dist/chunks/{token-types-C8JymO8s.js → token-types-iKMplaBL.js} +1 -1
  54. package/dist/chunks/{upload-Cf3wXZT8.js → upload-CiGNKJ_0.js} +1 -1
  55. package/dist/chunks/validators-B8fpdinG.js +3651 -0
  56. package/dist/chunks/{variable-draft-DOX03R4A.js → variable-draft-9-huI1h4.js} +4 -4
  57. package/dist/dashboard/index.js +2 -2
  58. package/dist/dashboard-authoring/index.js +1888 -1826
  59. package/dist/format-utils/index.js +230 -231
  60. package/dist/index.js +349 -353
  61. package/dist/layouts/index.js +1 -1
  62. package/dist/report-runtime-context/index.js +1 -1
  63. package/dist/style.css +1 -1
  64. package/dist/surfboard/index.js +2 -2
  65. package/dist/types/appearance/index.d.ts +1 -0
  66. package/dist/types/brand-studio/brand-studio-draft.d.ts +7 -0
  67. package/dist/types/brand-studio/index.d.ts +1 -1
  68. package/dist/types/components/briefings/briefing-author/run-model.d.ts +1 -2
  69. package/dist/types/components/providers/appearance-runtime-provider.d.ts +4 -1
  70. package/dist/types/components/sharing-and-management/hooks/use-resource-management.d.ts +0 -2
  71. package/dist/types/components/sharing-and-management/utils/types.d.ts +0 -72
  72. package/dist/types/components/surfboard/filter/types.d.ts +5 -4
  73. package/dist/types/components/ui-custom/date-range-presets.d.ts +1 -17
  74. package/dist/types/components/visual/data-table/hooks/use-data-table-logic.d.ts +0 -1
  75. package/dist/types/components/visual/data-table/types/data-table.d.ts +0 -9
  76. package/dist/types/components/visual/data-table/utils/pagination-utils.d.ts +0 -19
  77. package/dist/types/components/visual/shared/utils/table-column-order.d.ts +0 -1
  78. package/dist/types/index.js +9 -9
  79. package/dist/types/lib/appearance/aliases.d.ts +42 -0
  80. package/dist/types/lib/appearance/compiler.d.ts +6 -0
  81. package/dist/types/lib/appearance/defaults.d.ts +6 -0
  82. package/dist/types/lib/appearance/index.d.ts +2 -0
  83. package/dist/types/lib/appearance/normalize-organization.d.ts +17 -0
  84. package/dist/types/lib/appearance/resolver.d.ts +2 -2
  85. package/dist/types/lib/appearance/types.d.ts +38 -1
  86. package/dist/types/lib/charts/types.d.ts +6 -2
  87. package/dist/types/lib/dashboard/semantic-dataset-references.d.ts +0 -1
  88. package/dist/types/lib/dashboard-inputs/dashboard-input-values.d.ts +0 -2
  89. package/dist/types/lib/dashboard-variables/types.d.ts +1 -6
  90. package/dist/types/lib/download-pdf.d.ts +0 -1
  91. package/dist/types/lib/hooks/use-dashboard.d.ts +3 -4
  92. package/dist/types/lib/hooks/use-date-filter.d.ts +3 -3
  93. package/dist/types/lib/matrix-table/matrix-card-adapter.d.ts +1 -1
  94. package/dist/types/lib/stores/dashboard-store.d.ts +15 -6
  95. package/dist/types/lib/stores/editor-store.d.ts +0 -1
  96. package/dist/types/lib/stores/table-actions.d.ts +0 -1
  97. package/dist/types/lib/table-formatting/table-formatting-css.d.ts +0 -5
  98. package/dist/types/lib/types/common-types.d.ts +3 -2
  99. package/dist/types/lib/types/explorer-types.d.ts +2 -2
  100. package/dist/types/lib/types/index.d.ts +1 -1
  101. package/dist/types/lib/types/summary-types.d.ts +0 -5
  102. package/dist/types/lib/utils/card-definition.d.ts +7 -7
  103. package/dist/types/shared/analytics-protocol/agent-time-window.d.ts +84 -0
  104. package/dist/types/shared/analytics-protocol/analytics-base-schemas.d.ts +4 -4
  105. package/dist/types/shared/analytics-protocol/applied-constraints.d.ts +2 -2
  106. package/dist/types/shared/analytics-protocol/contracts.d.ts +8 -17
  107. package/dist/types/shared/analytics-protocol/execution-input-schemas.d.ts +10 -10
  108. package/dist/types/shared/analytics-protocol/fixtures.d.ts +3 -2
  109. package/dist/types/shared/analytics-protocol/index.d.ts +2 -4
  110. package/dist/types/shared/analytics-protocol/matrix-definition-contract.d.ts +72 -72
  111. package/dist/types/shared/analytics-protocol/relative-date/describe.d.ts +18 -0
  112. package/dist/types/shared/analytics-protocol/relative-date/index.d.ts +7 -0
  113. package/dist/types/shared/analytics-protocol/relative-date/limits.d.ts +3 -0
  114. package/dist/types/shared/analytics-protocol/relative-date/presets.d.ts +11 -0
  115. package/dist/types/shared/analytics-protocol/relative-date/resolve.d.ts +49 -0
  116. package/dist/types/shared/analytics-protocol/relative-date/schemas.d.ts +76 -0
  117. package/dist/types/shared/analytics-protocol/relative-date/traits.d.ts +51 -0
  118. package/dist/types/shared/analytics-protocol/relative-date/window.d.ts +111 -0
  119. package/dist/types/shared/analytics-protocol/selection-contract.d.ts +1 -1
  120. package/dist/types/shared/assistant-protocol/context.d.ts +30 -30
  121. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +0 -2
  122. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +344 -1772
  123. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +4 -1
  124. package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +8 -4
  125. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +9 -0
  126. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +104 -104
  127. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +20 -20
  128. package/dist/types/shared/dashboard-authoring/dashboard-style/bounds.d.ts +17 -0
  129. package/dist/types/shared/dashboard-authoring/dashboard-style/brand.d.ts +20 -0
  130. package/dist/types/shared/dashboard-authoring/dashboard-style/edit-words.d.ts +7 -0
  131. package/dist/types/shared/dashboard-authoring/dashboard-style/edit.d.ts +19 -0
  132. package/dist/types/shared/dashboard-authoring/dashboard-style/index.d.ts +15 -0
  133. package/dist/types/shared/dashboard-authoring/dashboard-style/layers.d.ts +19 -0
  134. package/dist/types/shared/dashboard-authoring/dashboard-style/legacy.d.ts +21 -0
  135. package/dist/types/shared/dashboard-authoring/dashboard-style/parse.d.ts +18 -0
  136. package/dist/types/shared/dashboard-authoring/dashboard-style/pickers.d.ts +12 -0
  137. package/dist/types/shared/dashboard-authoring/dashboard-style/types.d.ts +122 -0
  138. package/dist/types/shared/dashboard-authoring/dashboard-style/view.d.ts +10 -0
  139. package/dist/types/shared/dashboard-authoring/index.d.ts +1 -0
  140. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +11 -0
  141. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +23 -0
  142. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +10 -2
  143. package/dist/types/shared/format-utils/filter-detail.d.ts +2 -8
  144. package/dist/types/shared/format-utils/filter-line.d.ts +2 -2
  145. package/dist/types/shared/format-utils/matrix-continuation.d.ts +10 -10
  146. package/dist/types/shared/temporal/index.d.ts +0 -2
  147. package/dist/types/shared/temporal/temporal-parity-fixtures.d.ts +2 -2
  148. package/package.json +7 -26
  149. package/DATA_APP_SDK.md +0 -339
  150. package/dist/chunks/appearance-context-DEYtWinQ.js +0 -126
  151. package/dist/chunks/appearance-runtime-provider-B-M8gwlZ.js +0 -81
  152. package/dist/chunks/assistant-chat-BN5I8KuN.js +0 -8849
  153. package/dist/chunks/color-CJvdlFM_.js +0 -2162
  154. package/dist/chunks/dashboard-json-Cxp3inxd.js +0 -68
  155. package/dist/chunks/filter-value-text-7zhmth1S.js +0 -163
  156. package/dist/chunks/index-CLIro-EG.js +0 -425
  157. package/dist/chunks/index-CuHybtft.js +0 -51
  158. package/dist/chunks/matrix-analytical-definition-C9xB_T84.js +0 -717
  159. package/dist/chunks/matrix-card-BSUeSXpD.js +0 -42
  160. package/dist/chunks/matrix-member-presentation-DZNgQpUq.js +0 -105
  161. package/dist/chunks/operators-B3zZoskU.js +0 -66
  162. package/dist/chunks/pivot-result-contract-expectations-Ddh1rNz5.js +0 -56
  163. package/dist/chunks/raw-temporal-value-Bqz8wc7L.js +0 -242
  164. package/dist/chunks/selection-reducer-OaJ-N5uN.js +0 -46
  165. package/dist/chunks/source-entity-resolution-DF6GulDn.js +0 -607
  166. package/dist/chunks/validators-wtjw0aw6.js +0 -3332
  167. package/dist/data-app-sdk/index.js +0 -1412
  168. package/dist/data-app-sdk-adapters/index.js +0 -361
  169. package/dist/data-app-sdk-validation/index.js +0 -1031
  170. package/dist/types/components/sharing-and-management/utils/group-types.d.ts +0 -105
  171. package/dist/types/data-app-sdk/adapters.d.ts +0 -35
  172. package/dist/types/data-app-sdk/builders.d.ts +0 -62
  173. package/dist/types/data-app-sdk/contracts.d.ts +0 -419
  174. package/dist/types/data-app-sdk/executor.d.ts +0 -5
  175. package/dist/types/data-app-sdk/field-catalog-validation.d.ts +0 -29
  176. package/dist/types/data-app-sdk/hooks.d.ts +0 -11
  177. package/dist/types/data-app-sdk/index.d.ts +0 -9
  178. package/dist/types/data-app-sdk/provider.d.ts +0 -8
  179. package/dist/types/data-app-sdk/relationship-aware-field-policy.d.ts +0 -21
  180. package/dist/types/data-app-sdk/selection.d.ts +0 -2
  181. package/dist/types/data-app-sdk/validation.d.ts +0 -58
  182. package/dist/types/data-app-sdk-adapters.d.ts +0 -2
  183. package/dist/types/data-app-sdk-validation.d.ts +0 -2
  184. package/dist/types/data-app-sdk.d.ts +0 -2
  185. package/dist/types/shared/analytics-protocol/relative-date-filter.d.ts +0 -68
  186. package/dist/types/shared/analytics-protocol/relative-date-label.d.ts +0 -20
  187. package/dist/types/shared/analytics-protocol/time-window-schema.d.ts +0 -314
  188. package/dist/types/shared/analytics-protocol/time-window.d.ts +0 -52
  189. package/dist/types/shared/temporal/relative-date.d.ts +0 -21
  190. package/dist/types/shared/temporal/time-window-periods.d.ts +0 -21
  191. package/src/data-app-sdk/README.md +0 -402
@@ -0,0 +1,1253 @@
1
+ import { am as N, ao as Q, ag as X, ae as p, an as _e, af as ie, at as De, ah as Ae, a5 as K, I as ae, o as Ee } from "./validators-B8fpdinG.js";
2
+ import { r as qe } from "./metric-comparison-n9NsIa-2.js";
3
+ import { d as Be, w as _, b as Z } from "./raw-temporal-value-DdT0s47W.js";
4
+ const Y = 864e5, ee = {
5
+ second: 1e3,
6
+ minute: 6e4,
7
+ hour: 36e5
8
+ };
9
+ function G(e, t) {
10
+ return {
11
+ ...Z(e, t),
12
+ millisecond: (e.getTime() % 1e3 + 1e3) % 1e3
13
+ };
14
+ }
15
+ function E(e, t) {
16
+ return Be(e, t);
17
+ }
18
+ function O(e) {
19
+ const t = new Date(e);
20
+ return {
21
+ year: t.getUTCFullYear(),
22
+ month: t.getUTCMonth() + 1,
23
+ day: t.getUTCDate(),
24
+ hour: t.getUTCHours(),
25
+ minute: t.getUTCMinutes(),
26
+ second: t.getUTCSeconds(),
27
+ millisecond: t.getUTCMilliseconds()
28
+ };
29
+ }
30
+ function le(e, t) {
31
+ const n = /* @__PURE__ */ new Date(0);
32
+ return n.setUTCFullYear(e, t, 0), n.getUTCDate();
33
+ }
34
+ function L(e, t) {
35
+ const n = e.year * 12 + (e.month - 1) + t, i = Math.floor(n / 12), a = n - i * 12 + 1;
36
+ return { ...e, year: i, month: a, day: Math.min(e.day, le(i, a)) };
37
+ }
38
+ function q(e, t, n) {
39
+ if (t === 0) return e;
40
+ switch (n) {
41
+ case "second":
42
+ case "minute":
43
+ case "hour":
44
+ return O(
45
+ _(e) + t * ee[n]
46
+ );
47
+ case "day":
48
+ return O(_(e) + t * Y);
49
+ case "week":
50
+ return O(_(e) + t * 7 * Y);
51
+ case "month":
52
+ return L(e, t);
53
+ case "quarter":
54
+ return L(e, t * 3);
55
+ case "year":
56
+ return L(e, t * 12);
57
+ }
58
+ }
59
+ function xe(e) {
60
+ return new Date(
61
+ _({ ...e, hour: 0, minute: 0, second: 0 })
62
+ ).getUTCDay();
63
+ }
64
+ function oe(e) {
65
+ var n;
66
+ const t = (n = e.fiscalCalendar) == null ? void 0 : n.yearStartMonth;
67
+ return t && t >= 1 && t <= 12 ? t : 1;
68
+ }
69
+ function Fe(e, t, n) {
70
+ const i = { ...e, hour: 0, minute: 0, second: 0, millisecond: 0 };
71
+ switch (t) {
72
+ case "day":
73
+ return i;
74
+ case "week":
75
+ return q(
76
+ i,
77
+ -((xe(e) - n.weekStart + 7) % 7),
78
+ "day"
79
+ );
80
+ case "month":
81
+ return { ...i, day: 1 };
82
+ case "quarter": {
83
+ const a = (e.month - oe(n) + 12) % 12;
84
+ return L({ ...i, day: 1 }, -(a % 3));
85
+ }
86
+ case "year": {
87
+ const a = oe(n);
88
+ return {
89
+ ...i,
90
+ year: e.month >= a ? e.year : e.year - 1,
91
+ month: a,
92
+ day: 1
93
+ };
94
+ }
95
+ }
96
+ }
97
+ function B(e, t, n, i = 0) {
98
+ const a = ee[t];
99
+ if (a !== void 0) {
100
+ const o = G(e, n.tz), d = o.millisecond + (t === "second" ? 0 : o.second * 1e3) + (t === "hour" ? o.minute * 6e4 : 0), c = e.getTime() - d + i * a;
101
+ return { start: new Date(c), endExclusive: new Date(c + a) };
102
+ }
103
+ const s = t, r = q(
104
+ Fe(G(e, n.tz), s, n),
105
+ i,
106
+ t
107
+ );
108
+ return {
109
+ start: E(r, n.tz),
110
+ endExclusive: E(q(r, 1, t), n.tz)
111
+ };
112
+ }
113
+ function V(e, t, n) {
114
+ return B(e, t, n).start;
115
+ }
116
+ function D(e, t, n) {
117
+ return new Date(B(e, t, n).endExclusive.getTime() - 1);
118
+ }
119
+ function ue(e, t, n, i) {
120
+ return t === 0 ? e : E(
121
+ q(G(e, i.tz), t, n),
122
+ i.tz
123
+ );
124
+ }
125
+ function yt(e, t, n) {
126
+ const i = (a) => {
127
+ const { year: s, month: r, day: o } = Z(a, n);
128
+ return _({ year: s, month: r, day: o, hour: 0, minute: 0, second: 0 });
129
+ };
130
+ return Math.round((i(t) - i(e)) / Y);
131
+ }
132
+ const He = /^(\d{4})-(\d{2})-(\d{2})$/;
133
+ function bt(e, t) {
134
+ const { year: n, month: i, day: a } = Z(e, t);
135
+ return `${String(n).padStart(4, "0")}-${String(i).padStart(2, "0")}-${String(a).padStart(2, "0")}`;
136
+ }
137
+ function fe(e) {
138
+ const t = He.exec(e);
139
+ if (!t) return null;
140
+ const n = Number(t[1]), i = Number(t[2]), a = Number(t[3]);
141
+ return i < 1 || i > 12 || a < 1 || a > le(n, i) ? null : { year: n, month: i, day: a };
142
+ }
143
+ function gt(e, t) {
144
+ const n = fe(e);
145
+ if (!n) return null;
146
+ const i = { ...n, hour: 0, minute: 0, second: 0, millisecond: 0 };
147
+ return {
148
+ start: E(i, t),
149
+ endExclusive: E(q(i, 1, "day"), t)
150
+ };
151
+ }
152
+ class re extends Error {
153
+ constructor(t) {
154
+ super(t), this.name = "RelativeDateUsageError";
155
+ }
156
+ }
157
+ function Pe(e, t, n = {}) {
158
+ const i = n.spansBack ?? 0;
159
+ if (i !== 0) return Le(e, t, i);
160
+ const { calendar: a, now: s } = t;
161
+ switch (e.kind) {
162
+ case "periods": {
163
+ const r = me(e, t);
164
+ return {
165
+ start: B(r, e.unit, a, e.from).start,
166
+ end: e.toDate ? r : ye(r, e.unit, a, e.to)
167
+ };
168
+ }
169
+ case "rolling": {
170
+ const r = e.anchor === "latest_data" ? t.latestData ?? s : s, o = ee[e.unit];
171
+ return {
172
+ start: o === void 0 ? ue(r, -e.n, e.unit, a) : new Date(r.getTime() - e.n * o),
173
+ end: r
174
+ };
175
+ }
176
+ case "monthDay": {
177
+ const r = e.day === "first" ? V(s, "month", a) : D(s, "month", a);
178
+ return { start: V(r, "day", a), end: D(r, "day", a) };
179
+ }
180
+ }
181
+ }
182
+ function me(e, t) {
183
+ const { anchor: n } = e;
184
+ return n === "latest_data" ? t.latestData ?? t.now : n === "now" ? t.now : new Date(V(t.now, n.lastComplete, t.calendar).getTime() - 1);
185
+ }
186
+ function ye(e, t, n, i) {
187
+ return new Date(B(e, t, n, i).endExclusive.getTime() - 1);
188
+ }
189
+ function Le(e, t, n) {
190
+ if (!Number.isInteger(n) || n < 0)
191
+ throw new re(`spansBack must be a whole number of spans, got ${n}.`);
192
+ if (e.kind !== "periods" || typeof e.anchor != "object")
193
+ throw new re("spansBack applies only to a window anchored at the end of the last complete period.");
194
+ const { calendar: i } = t, { unit: a } = e, s = Pe(e, t), r = -n * (e.to - e.from + 1), o = B(s.start, a, i, r).start;
195
+ if (D(s.end, a, i).getTime() === s.end.getTime())
196
+ return { start: o, end: ye(s.end, a, i, r) };
197
+ const d = ue(me(e, t), r, a, i), c = Math.min(
198
+ D(d, e.anchor.lastComplete, i).getTime(),
199
+ D(d, a, i).getTime()
200
+ );
201
+ return { start: o, end: new Date(c) };
202
+ }
203
+ function be(e) {
204
+ return e.prefixLevels.length === 1 && e.prefixLevels[0] === "table" ? ["table"] : Array.from(
205
+ /* @__PURE__ */ new Set([
206
+ "database",
207
+ ...e.prefixLevels
208
+ ])
209
+ );
210
+ }
211
+ function ht(e) {
212
+ const t = e.source.connectionType ? N(e.source.connectionType) : void 0, n = e.source.dialect ? Q(e.source.dialect) : void 0, i = e.source.dialect && e.source.dialect !== "unknown" ? N(e.source.dialect) : void 0;
213
+ if (!e.capabilities && e.source.connectionType && e.source.dialect && e.source.dialect !== "unknown" && (!t || n === "unknown" || t.dialect !== n))
214
+ return { kind: "incompatible_capabilities" };
215
+ const a = e.capabilities || t || i;
216
+ if (!a) return { kind: "incompatible_capabilities" };
217
+ const s = be(a), r = {
218
+ ...s.includes("database") && e.source.databaseName ? { databaseName: e.source.databaseName } : {},
219
+ ...s.includes("schema") && e.source.schemaName ? { schemaName: e.source.schemaName } : {},
220
+ ...e.source.tableName ? { tableName: e.source.tableName } : {}
221
+ }, o = s.filter((d) => d === "database" ? !r.databaseName : d === "schema" ? !r.schemaName : !r.tableName);
222
+ return o.length > 0 ? { kind: "missing_coordinates", missing: o } : {
223
+ kind: "resolved",
224
+ coordinates: r
225
+ };
226
+ }
227
+ function f(e) {
228
+ return typeof e == "string" && e.trim() ? e.trim() : void 0;
229
+ }
230
+ function x(e) {
231
+ return e && typeof e == "object" && !Array.isArray(e) ? e : void 0;
232
+ }
233
+ function ge(e) {
234
+ const t = x(e);
235
+ return !t || !f(t.name) || t.type === "model" ? !1 : t.type === "dataset" ? t.datasetType === "physical" : !0;
236
+ }
237
+ function H(e) {
238
+ const t = x(e);
239
+ if (!t) return {};
240
+ const n = f(t.table) || f(t.name);
241
+ return {
242
+ ...f(t.database) ? { databaseName: f(t.database) } : {},
243
+ ...f(t.schema) ? { schemaName: f(t.schema) } : {},
244
+ ...n ? { tableName: n } : {}
245
+ };
246
+ }
247
+ function Me(e) {
248
+ if (Oe(e)) return { kind: "malformed" };
249
+ const t = e.entities.filter(ge), n = ze(e), i = je({
250
+ entities: t,
251
+ connectionType: e.connectionType,
252
+ dialect: e.dialect,
253
+ capabilities: e.capabilities
254
+ });
255
+ if (!i) return { kind: "incompatible_capabilities" };
256
+ const { capabilities: a } = i, s = $e({
257
+ hints: e.qualifiedHints || [],
258
+ coordinateHint: e.coordinateHint,
259
+ capabilityAuthority: i
260
+ });
261
+ if (s.kind !== "valid")
262
+ return { kind: s.kind };
263
+ const r = s.coordinates, o = r ? t.filter(
264
+ (c) => X({
265
+ left: he(
266
+ H(c),
267
+ a
268
+ ),
269
+ right: r,
270
+ capabilities: a
271
+ })
272
+ ) : t;
273
+ if (r && o.length === 0)
274
+ return {
275
+ kind: "not_found",
276
+ basis: "qualified",
277
+ coordinates: r,
278
+ capabilityAuthority: i
279
+ };
280
+ if (r && o.length === 1) {
281
+ const c = o[0], l = $(
282
+ i,
283
+ c
284
+ );
285
+ return {
286
+ kind: "resolved",
287
+ basis: "qualified",
288
+ entity: c,
289
+ coordinates: Qe(
290
+ H(c),
291
+ r,
292
+ l
293
+ ),
294
+ capabilityAuthority: l
295
+ };
296
+ }
297
+ const d = pe([
298
+ ...e.bareHints || [],
299
+ ...s.bareHints,
300
+ r == null ? void 0 : r.tableName
301
+ ]);
302
+ if (d.size > 0) {
303
+ const c = o.filter((l) => {
304
+ const m = We(l);
305
+ return Array.from(d).some((b) => m.has(b));
306
+ });
307
+ if (c.length === 1) {
308
+ const l = c[0], m = $(
309
+ i,
310
+ l
311
+ );
312
+ return {
313
+ kind: "resolved",
314
+ basis: "bare",
315
+ entity: l,
316
+ coordinates: M(
317
+ H(l),
318
+ m
319
+ ),
320
+ capabilityAuthority: m
321
+ };
322
+ }
323
+ return c.length > 1 ? { kind: "ambiguous", basis: "bare" } : { kind: "not_found", basis: "bare", capabilityAuthority: i };
324
+ }
325
+ if (r)
326
+ return { kind: "ambiguous", basis: "qualified" };
327
+ if (n)
328
+ return {
329
+ kind: "not_found",
330
+ basis: n,
331
+ capabilityAuthority: i
332
+ };
333
+ if (t.length === 1) {
334
+ const c = t[0], l = $(
335
+ i,
336
+ c
337
+ );
338
+ return {
339
+ kind: "resolved",
340
+ basis: "unqualified",
341
+ entity: c,
342
+ coordinates: M(
343
+ H(c),
344
+ l
345
+ ),
346
+ capabilityAuthority: l
347
+ };
348
+ }
349
+ return { kind: "unqualified" };
350
+ }
351
+ function ze(e) {
352
+ const t = (e.qualifiedHints || []).map(f).filter((i) => !!i);
353
+ return Object.values(e.coordinateHint || {}).some(
354
+ (i) => !!f(i)
355
+ ) || t.some((i) => i.includes(".")) ? "qualified" : [...t, ...e.bareHints || []].some(
356
+ (i) => !!f(i)
357
+ ) ? "bare" : void 0;
358
+ }
359
+ function A(e) {
360
+ return `${e.dialect}:${e.prefixLevels.join(".")}`;
361
+ }
362
+ function P(e) {
363
+ return {
364
+ dialect: e.dialect,
365
+ prefixLevels: [...e.prefixLevels]
366
+ };
367
+ }
368
+ function je(e) {
369
+ var k;
370
+ const t = f(e.connectionType), n = f(e.dialect), i = e.capabilities ? P(e.capabilities) : void 0, a = t ? N(t) : void 0, s = n ? Q(n) : void 0, r = n && n !== "unknown" ? N(n) : void 0;
371
+ if (t && !a || n && n !== "unknown" && s === "unknown" || i && a && A(i) !== A(a))
372
+ return;
373
+ const o = i || (a ? P(a) : r ? P(r) : void 0);
374
+ if (o)
375
+ return s && s !== "unknown" && o.dialect !== s ? void 0 : {
376
+ capabilities: o,
377
+ ...t ? { connectionType: t } : {},
378
+ dialect: o.dialect,
379
+ evidence: "explicit"
380
+ };
381
+ const d = e.entities.map((y) => {
382
+ const C = x(y), h = f(C == null ? void 0 : C.connectionType), I = f(C == null ? void 0 : C.dialect), T = h ? N(h) : void 0, F = I ? Q(I) : void 0, j = I && I !== "unknown" ? N(I) : void 0;
383
+ if (h && !T || I && I !== "unknown" && F === "unknown" || I && I !== "unknown" && !T && !j || T && F && F !== "unknown" && T.dialect !== F)
384
+ return;
385
+ const ne = T || j, w = ne ? P(ne) : we(C);
386
+ return w ? {
387
+ capabilities: w,
388
+ connectionType: h,
389
+ capabilityIdentity: h ? _e(h) : void 0,
390
+ inferred: !T && !j,
391
+ signature: A(w)
392
+ } : void 0;
393
+ });
394
+ if (d.some((y) => !y)) return;
395
+ const c = d.filter(
396
+ (y) => !!y
397
+ );
398
+ if (new Set(c.map((y) => y.signature)).size > 1)
399
+ return;
400
+ const l = (k = c[0]) == null ? void 0 : k.capabilities;
401
+ if (!l || s && s !== "unknown" && l.dialect !== s)
402
+ return;
403
+ const m = new Set(
404
+ c.map((y) => y.capabilityIdentity).filter((y) => !!y)
405
+ ), b = c.every(
406
+ (y) => y.connectionType && y.capabilityIdentity
407
+ );
408
+ return {
409
+ capabilities: l,
410
+ ...b && m.size === 1 ? { connectionType: c[0].connectionType } : {},
411
+ dialect: l.dialect,
412
+ evidence: c.every((y) => y.inferred) ? "coordinates" : "entity"
413
+ };
414
+ }
415
+ function we(e) {
416
+ const t = !!f(e == null ? void 0 : e.database), n = !!f(e == null ? void 0 : e.schema);
417
+ if (!(t && n)) {
418
+ if (n)
419
+ return { dialect: "unknown", prefixLevels: ["schema", "table"] };
420
+ if (t)
421
+ return { dialect: "unknown", prefixLevels: ["database", "table"] };
422
+ }
423
+ }
424
+ function $(e, t) {
425
+ var a;
426
+ if (e.evidence !== "entity") return e;
427
+ const n = f((a = x(t)) == null ? void 0 : a.connectionType), i = n ? N(n) : void 0;
428
+ return i && A(i) === A(e.capabilities) ? { ...e, connectionType: n } : e;
429
+ }
430
+ function Oe(e) {
431
+ return (e.qualifiedHints || []).some(
432
+ (n) => {
433
+ const i = f(n);
434
+ return !!(i && i.includes(".") && !p(i));
435
+ }
436
+ ) ? !0 : Object.values(e.coordinateHint || {}).some((n) => {
437
+ const i = f(n);
438
+ return !!(i && !p(i));
439
+ });
440
+ }
441
+ function $e(e) {
442
+ const { capabilities: t } = e.capabilityAuthority, n = [], i = [];
443
+ for (const m of e.hints) {
444
+ const b = f(m);
445
+ if (!b) continue;
446
+ if (!b.includes(".")) {
447
+ i.push(b);
448
+ continue;
449
+ }
450
+ const k = p(b);
451
+ if (!k) return { kind: "malformed" };
452
+ n.push(k);
453
+ }
454
+ const a = Re(e.coordinateHint);
455
+ if (a.kind === "malformed") return a;
456
+ const s = Array.from(new Set(n)).map(
457
+ (m) => ie({
458
+ qualifiedName: m,
459
+ capabilities: t
460
+ })
461
+ );
462
+ if (!Ue(s, t))
463
+ return { kind: "conflicting" };
464
+ const r = [...new Set(n)].sort(
465
+ (m, b) => b.split(".").length - m.split(".").length
466
+ )[0], o = r ? ie({
467
+ qualifiedName: r,
468
+ capabilities: t
469
+ }) : void 0, d = he(
470
+ a.coordinates,
471
+ t
472
+ ), c = M(
473
+ a.coordinates,
474
+ e.capabilityAuthority
475
+ ), l = !!(d.tableName && (d.databaseName || d.schemaName));
476
+ return o && l && !X({
477
+ left: o,
478
+ right: d,
479
+ capabilities: t
480
+ }) ? { kind: "conflicting" } : {
481
+ kind: "valid",
482
+ coordinates: o ? {
483
+ ...c,
484
+ ...o
485
+ } : l ? c : void 0,
486
+ bareHints: [
487
+ ...i,
488
+ ...!l && d.tableName ? [d.tableName] : []
489
+ ]
490
+ };
491
+ }
492
+ function Re(e) {
493
+ const t = {};
494
+ for (const [n, i] of Object.entries(e || {})) {
495
+ const a = f(i);
496
+ if (!a) continue;
497
+ const s = p(a);
498
+ if (!s) return { kind: "malformed" };
499
+ t[n] = s;
500
+ }
501
+ return { kind: "valid", coordinates: t };
502
+ }
503
+ function he(e, t) {
504
+ return {
505
+ ...t.prefixLevels.includes("database") && e.databaseName ? { databaseName: e.databaseName } : {},
506
+ ...t.prefixLevels.includes("schema") && e.schemaName ? { schemaName: e.schemaName } : {},
507
+ ...e.tableName ? { tableName: e.tableName } : {}
508
+ };
509
+ }
510
+ function Ue(e, t) {
511
+ return e.every(
512
+ (n, i) => e.slice(i + 1).every(
513
+ (a) => X({
514
+ left: n,
515
+ right: a,
516
+ capabilities: t
517
+ })
518
+ )
519
+ );
520
+ }
521
+ function pe(e) {
522
+ return new Set(
523
+ e.map(f).map(p).filter((t) => !!t)
524
+ );
525
+ }
526
+ function We(e) {
527
+ const t = x(e);
528
+ return t ? pe([
529
+ f(t.name),
530
+ f(t.table),
531
+ f(t.id)
532
+ ]) : /* @__PURE__ */ new Set();
533
+ }
534
+ function Qe(e, t, n) {
535
+ return M(
536
+ {
537
+ ...e,
538
+ ...t
539
+ },
540
+ n
541
+ );
542
+ }
543
+ function M(e, t) {
544
+ const n = t.evidence === "coordinates" ? t.capabilities.prefixLevels : be(t.capabilities);
545
+ return {
546
+ ...n.includes("database") && e.databaseName ? { databaseName: e.databaseName } : {},
547
+ ...n.includes("schema") && e.schemaName ? { schemaName: e.schemaName } : {},
548
+ ...e.tableName ? { tableName: e.tableName } : {}
549
+ };
550
+ }
551
+ function u(e) {
552
+ return typeof e == "string" && e.trim() ? e.trim() : void 0;
553
+ }
554
+ function S(e) {
555
+ return e && typeof e == "object" && !Array.isArray(e) ? e : void 0;
556
+ }
557
+ function Ke(e) {
558
+ const t = S(e);
559
+ return !!(t && t.type === "dataset" && u(t.name));
560
+ }
561
+ function ve(e) {
562
+ const t = S(e);
563
+ return !!(t && t.type === "dataset" && t.datasetType !== "physical" && u(t.name));
564
+ }
565
+ function se(e) {
566
+ const t = /* @__PURE__ */ new Set();
567
+ for (const n of e) {
568
+ const i = u(n);
569
+ if (!i) continue;
570
+ const a = p(i);
571
+ if (!a) continue;
572
+ const s = a.toLowerCase();
573
+ t.add(s);
574
+ const r = s.split("."), o = r[r.length - 1];
575
+ o && t.add(o);
576
+ }
577
+ return t;
578
+ }
579
+ function ce(e) {
580
+ var n;
581
+ const t = u(e);
582
+ return t ? (n = p(t)) == null ? void 0 : n.toLowerCase() : void 0;
583
+ }
584
+ function R(e, t) {
585
+ const n = S(t), i = u(n == null ? void 0 : n.domainId) || u(e.semanticDomainId), a = u(n == null ? void 0 : n.name);
586
+ if (!i || !a) return;
587
+ const s = (n == null ? void 0 : n.datasetType) === "physical" ? void 0 : De(n || {}), r = u(n == null ? void 0 : n.connectionId) || u(e.connectionId);
588
+ return {
589
+ kind: "semantic",
590
+ domainId: i,
591
+ datasetName: a,
592
+ ...s ? { datasetId: s } : {},
593
+ ...r ? { connectionId: r } : {}
594
+ };
595
+ }
596
+ function Ye(e, t = {}) {
597
+ const n = u(e.fieldEntityType);
598
+ if (n && n !== "dataset")
599
+ return { kind: "unqualified" };
600
+ const i = e.entities.filter(
601
+ (r) => t.includePhysicalDatasets ? Ke(r) : ve(r)
602
+ ), a = u(e.entityId);
603
+ if (a) {
604
+ const r = ce(a), o = i.filter((d) => {
605
+ const c = S(d);
606
+ return !!(r && ce(c == null ? void 0 : c.id) === r);
607
+ });
608
+ if (o.length > 1) return { kind: "ambiguous", basis: "bare" };
609
+ if (o.length === 1) {
610
+ const d = R(e, o[0]);
611
+ return d ? {
612
+ kind: "resolved",
613
+ basis: "bare",
614
+ entity: o[0],
615
+ source: d,
616
+ matchedById: !0
617
+ } : { kind: "not_found", basis: "bare" };
618
+ }
619
+ }
620
+ const s = se([
621
+ e.entityName,
622
+ ...e.qualifiedHints || [],
623
+ ...e.bareHints || []
624
+ ]);
625
+ if (s.size > 0) {
626
+ const r = i.filter((o) => {
627
+ const d = S(o);
628
+ return [...se([d == null ? void 0 : d.id, d == null ? void 0 : d.name])].some((l) => s.has(l));
629
+ });
630
+ if (r.length > 1) return { kind: "ambiguous", basis: "bare" };
631
+ if (r.length === 1) {
632
+ const o = R(e, r[0]);
633
+ return o ? {
634
+ kind: "resolved",
635
+ basis: "bare",
636
+ entity: r[0],
637
+ source: o,
638
+ matchedById: !1
639
+ } : { kind: "not_found", basis: "bare" };
640
+ }
641
+ return { kind: "not_found", basis: "bare" };
642
+ }
643
+ if (i.length === 1) {
644
+ const r = R(e, i[0]);
645
+ return r ? {
646
+ kind: "resolved",
647
+ basis: "unqualified",
648
+ entity: i[0],
649
+ source: r,
650
+ matchedById: !1
651
+ } : { kind: "unqualified" };
652
+ }
653
+ return { kind: "unqualified" };
654
+ }
655
+ function U(e) {
656
+ const t = e.resolution.kind === "resolved" ? S(e.resolution.entity) : void 0, n = u(e.connectionId) || u(t == null ? void 0 : t.connectionId), { connectionType: i, dialect: a } = e.resolution.capabilityAuthority, s = N(a), r = !!(s && s.dialect === e.resolution.capabilityAuthority.capabilities.dialect && s.prefixLevels.join(".") === e.resolution.capabilityAuthority.capabilities.prefixLevels.join(
657
+ "."
658
+ )), o = e.resolution.coordinates;
659
+ if (!(!n || !(o != null && o.tableName)))
660
+ return {
661
+ kind: "physical",
662
+ connectionId: n,
663
+ ...i ? { connectionType: i } : {},
664
+ ...!i && r ? { dialect: a } : {},
665
+ tableName: o.tableName,
666
+ ...o.databaseName ? { databaseName: o.databaseName } : {},
667
+ ...o.schemaName ? { schemaName: o.schemaName } : {}
668
+ };
669
+ }
670
+ function Ge(e) {
671
+ const t = S(e.entity), n = p(u(t == null ? void 0 : t.table));
672
+ if (!n) return !1;
673
+ const i = p(
674
+ u(t == null ? void 0 : t.database)
675
+ ), a = p(
676
+ u(t == null ? void 0 : t.schema)
677
+ );
678
+ return e.coordinates.tableName ? Ae({
679
+ requested: e.coordinates,
680
+ allowed: {
681
+ ...i ? { databaseName: i } : {},
682
+ ...a ? { schemaName: a } : {},
683
+ tableName: n
684
+ },
685
+ capabilities: e.capabilityAuthority.capabilities
686
+ }) : !1;
687
+ }
688
+ function Ve(e) {
689
+ var a, s, r;
690
+ if (u(e.connectionType) || u(e.dialect) || e.capabilities || u(e.semanticDomainId) || u(e.fieldEntityType) === "dataset" || u((a = e.fallbackCoordinateHint) == null ? void 0 : a.databaseName) || u((s = e.fallbackCoordinateHint) == null ? void 0 : s.schemaName))
691
+ return;
692
+ const t = [
693
+ u((r = e.fallbackCoordinateHint) == null ? void 0 : r.tableName),
694
+ ...(e.qualifiedHints || []).map(u),
695
+ ...(e.bareHints || []).map(u),
696
+ u(e.entityName),
697
+ ...u(e.fieldEntityType) === "table" ? [u(e.entityId)] : []
698
+ ].filter((o) => !!o);
699
+ if (!t.length || t.some((o) => o.includes(".")))
700
+ return;
701
+ const n = t.map(p);
702
+ return n.some((o) => !o) ? void 0 : new Set(n.map((o) => o.toLowerCase())).size === 1 ? n[0] : void 0;
703
+ }
704
+ function pt(e) {
705
+ const t = e.entities.filter(
706
+ ge
707
+ ), n = e.entities.filter(
708
+ ve
709
+ ), i = t.length > 0 || n.length > 0, a = Ye(e), s = e.qualifiedHints || [], r = s.some(
710
+ (c) => {
711
+ var l;
712
+ return (l = u(c)) == null ? void 0 : l.includes(".");
713
+ }
714
+ ), o = Me({
715
+ entities: t,
716
+ connectionType: u(e.connectionType),
717
+ dialect: e.dialect,
718
+ capabilities: e.capabilities,
719
+ qualifiedHints: s,
720
+ bareHints: [e.entityName, e.entityId, ...e.bareHints || []],
721
+ ...!r && e.fallbackCoordinateHint ? { coordinateHint: e.fallbackCoordinateHint } : {}
722
+ });
723
+ if (o.kind === "malformed" || o.kind === "conflicting" || o.kind === "incompatible_capabilities" && r || o.kind === "ambiguous" && o.basis === "qualified")
724
+ return o;
725
+ if (o.kind === "resolved" && o.basis === "qualified") {
726
+ const c = U({
727
+ resolution: o,
728
+ connectionId: e.connectionId
729
+ });
730
+ return c ? {
731
+ kind: "resolved",
732
+ basis: o.basis,
733
+ source: c,
734
+ entity: o.entity
735
+ } : { kind: "missing_connection" };
736
+ }
737
+ if (o.kind === "not_found" && o.basis === "qualified" && o.coordinates) {
738
+ if (a.kind === "resolved" && a.matchedById && Ge({
739
+ entity: a.entity,
740
+ coordinates: o.coordinates,
741
+ capabilityAuthority: o.capabilityAuthority
742
+ }))
743
+ return {
744
+ kind: "resolved",
745
+ basis: a.basis,
746
+ source: a.source,
747
+ entity: a.entity
748
+ };
749
+ const c = U({
750
+ resolution: o,
751
+ connectionId: e.connectionId
752
+ });
753
+ return c ? i ? { kind: "candidate", basis: "qualified", source: c } : { kind: "resolved", basis: "qualified", source: c } : { kind: "missing_connection" };
754
+ }
755
+ if (a.kind === "resolved")
756
+ return o.kind === "resolved" && o.basis === "bare" && !a.matchedById ? { kind: "ambiguous", basis: "bare" } : {
757
+ kind: "resolved",
758
+ basis: a.basis,
759
+ source: a.source,
760
+ entity: a.entity
761
+ };
762
+ if (a.kind === "ambiguous") return a;
763
+ if (o.kind === "resolved") {
764
+ const c = U({
765
+ resolution: o,
766
+ connectionId: e.connectionId
767
+ });
768
+ return c ? {
769
+ kind: "resolved",
770
+ basis: o.basis,
771
+ source: c,
772
+ entity: o.entity
773
+ } : { kind: "missing_connection" };
774
+ }
775
+ const d = u(e.entityName) || u(e.entityId);
776
+ if (!i && !r && u(e.semanticDomainId) && (!u(e.fieldEntityType) || u(e.fieldEntityType) === "dataset") && d)
777
+ return {
778
+ kind: "resolved",
779
+ basis: "historical",
780
+ source: {
781
+ kind: "semantic",
782
+ domainId: u(e.semanticDomainId),
783
+ datasetName: d,
784
+ ...u(e.connectionId) ? { connectionId: u(e.connectionId) } : {}
785
+ }
786
+ };
787
+ if (o.kind === "incompatible_capabilities") {
788
+ const c = i ? void 0 : Ve(e), l = u(e.connectionId);
789
+ return c && l ? {
790
+ kind: "resolved",
791
+ basis: "historical",
792
+ source: { kind: "physical", connectionId: l, tableName: c }
793
+ } : o;
794
+ }
795
+ return o.kind === "ambiguous" ? o : o.kind === "not_found" ? {
796
+ kind: "not_found",
797
+ basis: o.basis
798
+ } : { kind: "unqualified" };
799
+ }
800
+ function Je(e, t) {
801
+ return qe({ ...e, role: t });
802
+ }
803
+ function vt(e, t) {
804
+ if (t.id) {
805
+ const n = [];
806
+ e.forEach(
807
+ ({ fields: a }, s) => a.forEach((r, o) => {
808
+ r.id === t.id && n.push({ group: s, index: o });
809
+ })
810
+ );
811
+ const i = t.alias ? n.find(
812
+ ({ group: a, index: s }) => Je(e[a].fields[s], e[a].role) === t.alias
813
+ ) : void 0;
814
+ if (i) return i;
815
+ if (n.length === 1) return n[0];
816
+ }
817
+ for (let n = 0; n < e.length; n += 1) {
818
+ const i = e[n].fields.findIndex(
819
+ (a) => a.name === t.name && a.entityName === t.entityName && (a.alias === t.alias || !t.alias)
820
+ );
821
+ if (i !== -1) return { group: n, index: i };
822
+ }
823
+ }
824
+ function ke(e, t) {
825
+ const n = e.split(".").map((o) => o.trim()), i = t.split(".").map((o) => o.trim());
826
+ if (n.length === 0 || i.length === 0 || n.some((o) => !o) || i.some((o) => !o))
827
+ return !1;
828
+ const [a, s] = n.length <= i.length ? [n, i] : [i, n], r = s.length - a.length;
829
+ return a.every((o, d) => o === s[d + r]);
830
+ }
831
+ function Xe(e, t) {
832
+ const n = e.split("."), i = t.split("."), a = n.pop(), s = i.pop();
833
+ return !!(a && a === s && n.length > 0 && i.length > 0 && ke(
834
+ n.join("."),
835
+ i.join(".")
836
+ ));
837
+ }
838
+ function Ze(e) {
839
+ const t = e.map((i) => i.trim()).filter(Boolean);
840
+ if (t.every(
841
+ (i, a) => t.slice(a + 1).every(
842
+ (s) => ke(i, s)
843
+ )
844
+ ))
845
+ return [...t].sort(
846
+ (i, a) => a.split(".").length - i.split(".").length
847
+ )[0];
848
+ }
849
+ function v(e) {
850
+ return typeof e == "object" && e !== null && !Array.isArray(e);
851
+ }
852
+ function de(e) {
853
+ if (typeof e != "string") return "";
854
+ const t = e.split(".").map((n) => n.trim());
855
+ return t.length > 1 && t.every(Boolean) ? t.join(".") : "";
856
+ }
857
+ function J(e) {
858
+ if (typeof e != "string") return "";
859
+ const t = e.split(".").map((n) => n.trim());
860
+ return t.length > 0 && t.every(Boolean) ? t.join(".") : "";
861
+ }
862
+ function g(e) {
863
+ return typeof e == "string" ? e.trim() : "";
864
+ }
865
+ function et(e, t) {
866
+ return e.every(
867
+ (n, i) => e.slice(i + 1).every((a) => t(n, a))
868
+ );
869
+ }
870
+ function tt(e, t) {
871
+ const n = g(e.id), i = g(e.name), a = g(t.entityId), s = g(t.entityName);
872
+ return !i || !a && !s ? !1 : (!a || a === n || a === i) && (!s || s === i);
873
+ }
874
+ function nt(e) {
875
+ const t = v(e.semanticContext) ? e.semanticContext : void 0, n = v(e.fieldMeta) ? e.fieldMeta : void 0, i = g(t == null ? void 0 : t.semanticDomainId), a = Array.isArray(t == null ? void 0 : t.selectedEntities) ? t.selectedEntities.filter(
876
+ (h) => v(h) && h.type === "dataset"
877
+ ) : [];
878
+ if (!!!(i || a.length > 0 || (n == null ? void 0 : n.entityType) === "dataset")) return;
879
+ if (!i)
880
+ return { status: "unresolved", reason: "incomplete_source_identity" };
881
+ const r = g(n == null ? void 0 : n.entityId), o = g(n == null ? void 0 : n.entityName), d = !!(r || o), c = d ? a.filter(
882
+ (h) => tt(h, {
883
+ entityId: r,
884
+ entityName: o
885
+ })
886
+ ) : a;
887
+ if (c.length > 1)
888
+ return { status: "unresolved", reason: "incomplete_source_identity" };
889
+ if (d && a.length > 0 && c.length === 0)
890
+ return { status: "unresolved", reason: "divergent_source_identity" };
891
+ const l = c[0], m = g(l == null ? void 0 : l.domainId), b = g(l == null ? void 0 : l.id), k = g(l == null ? void 0 : l.name);
892
+ if (m && m !== i)
893
+ return { status: "unresolved", reason: "divergent_source_identity" };
894
+ const y = b, C = k || o;
895
+ return C ? {
896
+ status: "resolved",
897
+ source: {
898
+ kind: "semantic",
899
+ domainId: i,
900
+ datasetName: C,
901
+ ...y ? { datasetId: y } : {}
902
+ }
903
+ } : { status: "unresolved", reason: "incomplete_source_identity" };
904
+ }
905
+ function it(e, t) {
906
+ const n = g(e.connectionId), i = v(e.semanticContext) ? e.semanticContext : void 0, a = g(i == null ? void 0 : i.connectionId);
907
+ if (n && a && n !== a)
908
+ return { status: "unresolved", reason: "divergent_source_identity" };
909
+ const s = n || a, r = v(e.fieldMeta) ? e.fieldMeta : void 0, o = t.split(".").slice(0, -1).join("."), d = J(e.qualifiedTableName), c = J(
910
+ r == null ? void 0 : r.qualifiedEntityName
911
+ ), l = [
912
+ d,
913
+ c,
914
+ o
915
+ ].filter(Boolean), m = Ze(l);
916
+ return !m && l.length > 0 ? { status: "unresolved", reason: "divergent_source_identity" } : !s || !m ? { status: "unresolved", reason: "incomplete_source_identity" } : {
917
+ status: "resolved",
918
+ source: { kind: "physical", connectionId: s, tableName: m }
919
+ };
920
+ }
921
+ function at(e, t) {
922
+ const n = v(e.fieldMeta) ? e.fieldMeta : void 0, i = typeof (n == null ? void 0 : n.qualifiedFieldName) == "string" ? n.qualifiedFieldName.trim() : "", a = de(
923
+ n == null ? void 0 : n.qualifiedFieldName
924
+ ), s = typeof e.column == "string" ? e.column.trim() : "", r = de(s), o = typeof e.qualifiedTableName == "string" ? e.qualifiedTableName.trim() : "", d = J(
925
+ e.qualifiedTableName
926
+ );
927
+ if (i && !a || t && o && !d || s.includes(".") && !r)
928
+ return { status: "unresolved", reason: "incomplete_field_identity" };
929
+ const c = r.split("."), l = r ? c[c.length - 1] : s, m = t && d && l ? `${d}.${l}` : "", b = [
930
+ a,
931
+ r,
932
+ m
933
+ ].filter(Boolean);
934
+ if (!et(
935
+ b,
936
+ Xe
937
+ ))
938
+ return { status: "unresolved", reason: "divergent_field_identity" };
939
+ const k = r || a || m;
940
+ return k ? { status: "resolved", qualifiedFieldName: k } : { status: "unresolved", reason: "incomplete_field_identity" };
941
+ }
942
+ function ot(e) {
943
+ if (!v(e))
944
+ return { status: "ineligible", reason: "invalid_input" };
945
+ if (e.kind === "global-date")
946
+ return { status: "eligible", kind: "global_date" };
947
+ const t = K(e.dataType);
948
+ if (t !== "date" && t !== "datetime")
949
+ return { status: "ineligible", reason: "non_date_filter" };
950
+ const n = v(e.fieldMeta) ? e.fieldMeta : void 0, i = K(
951
+ n == null ? void 0 : n.dataType
952
+ );
953
+ if ((n == null ? void 0 : n.dataType) !== void 0 && i !== "date" && i !== "datetime")
954
+ return { status: "ineligible", reason: "non_date_filter" };
955
+ if (e.customFilterPreferences)
956
+ return { status: "ineligible", reason: "custom_filter" };
957
+ if (e.targetColumns !== void 0 && (!Array.isArray(e.targetColumns) || e.targetColumns.length > 0))
958
+ return { status: "ineligible", reason: "multi_target_filter" };
959
+ const a = nt(e), s = at(e, a === void 0);
960
+ if (s.status === "unresolved")
961
+ return { status: "ineligible", reason: s.reason };
962
+ const r = a || it(e, s.qualifiedFieldName);
963
+ return r.status === "resolved" ? {
964
+ status: "eligible",
965
+ kind: "field_date",
966
+ qualifiedFieldName: s.qualifiedFieldName,
967
+ source: r.source
968
+ } : { status: "ineligible", reason: r.reason };
969
+ }
970
+ function rt(e) {
971
+ if (!v(e) || e.kind !== "filter" || !v(e.filter))
972
+ return { status: "ineligible", reason: "invalid_input" };
973
+ const t = ot(
974
+ e.filter
975
+ );
976
+ return t.status === "ineligible" ? t : t.kind === "field_date" && v(e.compatibility) && e.compatibility.source === "cardInlineFilter" ? { status: "ineligible", reason: "card_inline_filter" } : t;
977
+ }
978
+ function kt(e) {
979
+ return rt(e).status === "eligible";
980
+ }
981
+ function Ct(e) {
982
+ return `compat-filter:${e}`;
983
+ }
984
+ function It(e) {
985
+ return `compat-control:${e}`;
986
+ }
987
+ function Nt(e, t) {
988
+ return `compat-inline-filter:${e}:${t}`;
989
+ }
990
+ function St(e, t) {
991
+ return `compat-card-control:${e}:${t}`;
992
+ }
993
+ function Ce(e, t) {
994
+ if (e) return e;
995
+ const n = t === void 0 ? "unknown" : K(t);
996
+ return n === "number" || n === "unknown" ? "SUM" : "COUNT";
997
+ }
998
+ function st(e) {
999
+ const t = e.aggregate === Ce(e.semanticAggregate, e.dataType);
1000
+ return {
1001
+ effectiveAggregate: e.aggregate,
1002
+ aggregateSource: t ? e.semanticAggregate ? "semantic_model" : "default_sum" : "caller_override"
1003
+ };
1004
+ }
1005
+ function ct(e, t, n) {
1006
+ const i = e.effectiveAggregate !== void 0 || e.aggregateSource !== void 0;
1007
+ return {
1008
+ aggregate: t,
1009
+ aggregateOrigin: n,
1010
+ ...i ? st({ aggregate: t, semanticAggregate: e.semanticAggregate, dataType: e.dataType }) : {}
1011
+ };
1012
+ }
1013
+ function Tt(e, t, n) {
1014
+ return { ...e, ...ct(e, t, n) };
1015
+ }
1016
+ function _t(e) {
1017
+ return e.aggregate ?? e.effectiveAggregate;
1018
+ }
1019
+ function Dt(e) {
1020
+ if (!e.aggregate) return !1;
1021
+ if (e.aggregateOrigin === "explicit" || e.aggregateSource === "caller_override") return !0;
1022
+ if (e.aggregateSource) {
1023
+ const t = e.aggregateSource === "default_sum" ? Ce(void 0, e.dataType) : e.semanticAggregate ?? e.effectiveAggregate;
1024
+ return t !== void 0 && e.aggregate !== t;
1025
+ }
1026
+ return e.aggregateOrigin !== "default";
1027
+ }
1028
+ const At = ["label", "labelOrigin", "derivedLabel"];
1029
+ function Et(e) {
1030
+ return { label: e, labelOrigin: "override", derivedLabel: void 0 };
1031
+ }
1032
+ function qt(e, t) {
1033
+ const { derivedLabel: n, ...i } = e;
1034
+ return { ...i, label: t, labelOrigin: "override" };
1035
+ }
1036
+ function Bt(e, t) {
1037
+ return e.labelOrigin === "override" ? {} : { label: t, labelOrigin: "semantic" };
1038
+ }
1039
+ function xt(e) {
1040
+ if (e.groupedDate !== void 0) return { target: e.groupedDate, direction: "asc" };
1041
+ if (!(!e.grouped || e.measures.length === 0))
1042
+ return { target: e.primaryMeasure ?? e.measures[0], direction: "desc" };
1043
+ }
1044
+ const Ft = /* @__PURE__ */ new Set([
1045
+ "contains",
1046
+ "startsWith",
1047
+ "endsWith",
1048
+ "like",
1049
+ "not like"
1050
+ ]);
1051
+ function Ie(e) {
1052
+ return e.includes("%") || e.includes("_");
1053
+ }
1054
+ function dt(e, t) {
1055
+ switch (e) {
1056
+ case "contains":
1057
+ return { pattern: `%${t}%`, negate: !1 };
1058
+ case "startsWith":
1059
+ return { pattern: `${t}%`, negate: !1 };
1060
+ case "endsWith":
1061
+ return { pattern: `%${t}`, negate: !1 };
1062
+ case "like":
1063
+ return { pattern: t, negate: !1 };
1064
+ case "not like":
1065
+ return { pattern: t, negate: !0 };
1066
+ }
1067
+ }
1068
+ function lt(e) {
1069
+ return Ie(e) ? e : `%${e}%`;
1070
+ }
1071
+ function Ht(e, t) {
1072
+ const { pattern: n, negate: i } = dt(e, t), a = n.length > 2 && n.startsWith("%") && n.endsWith("%") ? n.slice(1, -1) : void 0, s = a !== void 0 && !Ie(a) ? a : n;
1073
+ if (lt(s) === n)
1074
+ return { operator: i ? "not_contains" : "contains", value: s };
1075
+ }
1076
+ function Pt(e) {
1077
+ const { operation: t, values: n, temporalPrecision: i } = e;
1078
+ if (t !== "=" && t !== "!=" || i === "minute")
1079
+ return null;
1080
+ const a = Array.isArray(n) ? n : [n];
1081
+ if (a.length !== 1 || typeof a[0] != "string") return null;
1082
+ const s = a[0].trim();
1083
+ return fe(s) ? { operation: t, day: s } : null;
1084
+ }
1085
+ function Ne(e) {
1086
+ const { label: t, ...n } = e;
1087
+ return {
1088
+ dataset: Ee(n),
1089
+ ...e.kind === "physical" ? { dialect: e.dialect, connectionType: e.connectionType } : {}
1090
+ };
1091
+ }
1092
+ function Se(e) {
1093
+ const { label: t, source: n, ...i } = e;
1094
+ return { ...i, source: n && Ne(n) };
1095
+ }
1096
+ function te(e) {
1097
+ const {
1098
+ label: t,
1099
+ format: n,
1100
+ description: i,
1101
+ tags: a,
1102
+ inputs: s,
1103
+ ...r
1104
+ } = e;
1105
+ return {
1106
+ ...r,
1107
+ inputs: Object.fromEntries(
1108
+ Object.entries(s).map(([o, d]) => [
1109
+ o,
1110
+ { ...d, field: Se(d.field) }
1111
+ ])
1112
+ )
1113
+ };
1114
+ }
1115
+ function W(e) {
1116
+ const { derivedField: t, ...n } = e;
1117
+ return {
1118
+ ...Se(n),
1119
+ derivedField: t && te(t)
1120
+ };
1121
+ }
1122
+ function z(e) {
1123
+ const {
1124
+ label: t,
1125
+ format: n,
1126
+ description: i,
1127
+ semanticTemporalPresentation: a,
1128
+ derivedField: s,
1129
+ calculatedFormula: r,
1130
+ ...o
1131
+ } = e;
1132
+ return {
1133
+ ...o,
1134
+ semanticTemporalPresentation: a && {
1135
+ granularity: a.granularity
1136
+ },
1137
+ derivedField: s && te(s),
1138
+ calculatedFormula: r && {
1139
+ ...r,
1140
+ inputFields: r.inputFields.map(z)
1141
+ }
1142
+ };
1143
+ }
1144
+ function Te(e) {
1145
+ return {
1146
+ ...e,
1147
+ conditions: e.conditions.map(
1148
+ ({ label: t, field: n, ...i }) => ({
1149
+ ...i,
1150
+ field: z(n)
1151
+ })
1152
+ ),
1153
+ groups: e.groups.map(Te)
1154
+ };
1155
+ }
1156
+ function Lt(e) {
1157
+ return {
1158
+ ...e,
1159
+ source: Ne(e.source),
1160
+ rows: e.rows.map((t) => ({
1161
+ ...t,
1162
+ field: W(t.field)
1163
+ })),
1164
+ columns: e.columns.map((t) => ({
1165
+ ...t,
1166
+ field: W(t.field)
1167
+ })),
1168
+ measures: e.measures.map(
1169
+ (t) => t.kind === "aggregate" ? { ...t, field: W(t.field) } : {
1170
+ ...t,
1171
+ definition: te(t.definition)
1172
+ }
1173
+ ),
1174
+ filters: e.filters && Te(e.filters),
1175
+ joinPlan: e.joinPlan && {
1176
+ ...e.joinPlan,
1177
+ // relationshipName participates in governed relationship resolution.
1178
+ joins: e.joinPlan.joins.map((t) => ({
1179
+ ...t,
1180
+ joinKeyGroups: t.joinKeyGroups.map((n) => ({
1181
+ ...n,
1182
+ keys: n.keys.map((i) => ({
1183
+ ...i,
1184
+ source: z(i.source),
1185
+ target: z(i.target)
1186
+ }))
1187
+ }))
1188
+ }))
1189
+ },
1190
+ // Sort scopes are keyed overrides, unlike ordered axes/calculation inputs.
1191
+ sorts: [...e.sorts].sort((t, n) => {
1192
+ const i = ae(t), a = ae(n);
1193
+ return i < a ? -1 : i > a ? 1 : 0;
1194
+ })
1195
+ };
1196
+ }
1197
+ export {
1198
+ te as $,
1199
+ At as A,
1200
+ Et as B,
1201
+ qt as C,
1202
+ xt as D,
1203
+ Ie as E,
1204
+ dt as F,
1205
+ lt as G,
1206
+ Ht as H,
1207
+ ee as I,
1208
+ G as J,
1209
+ E as K,
1210
+ le as L,
1211
+ q as M,
1212
+ xe as N,
1213
+ B as O,
1214
+ V as P,
1215
+ D as Q,
1216
+ re as R,
1217
+ Ft as S,
1218
+ ue as T,
1219
+ yt as U,
1220
+ bt as V,
1221
+ fe as W,
1222
+ gt as X,
1223
+ Pt as Y,
1224
+ ke as Z,
1225
+ Ze as _,
1226
+ Lt as a,
1227
+ Xe as a0,
1228
+ be as b,
1229
+ Me as c,
1230
+ ve as d,
1231
+ Ye as e,
1232
+ pt as f,
1233
+ Bt as g,
1234
+ vt as h,
1235
+ ge as i,
1236
+ tt as j,
1237
+ ot as k,
1238
+ rt as l,
1239
+ ct as m,
1240
+ kt as n,
1241
+ Ct as o,
1242
+ It as p,
1243
+ Nt as q,
1244
+ ht as r,
1245
+ Je as s,
1246
+ St as t,
1247
+ Pe as u,
1248
+ Ce as v,
1249
+ st as w,
1250
+ Tt as x,
1251
+ _t as y,
1252
+ Dt as z
1253
+ };