react-semaphor 0.1.567 → 0.1.569

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 (128) hide show
  1. package/README.md +0 -7
  2. package/dist/analytics-protocol/index.js +434 -454
  3. package/dist/assistant-context/index.js +1 -1
  4. package/dist/brand-studio/index.js +10 -12
  5. package/dist/briefings/index.js +4 -4
  6. package/dist/chunks/{_commonjsHelpers-DimLPMtv.js → _commonjsHelpers-Bid1ZNYj.js} +271 -222
  7. package/dist/chunks/{assistant-chat-D-IuHHwh.js → assistant-chat-Dzf2Mbph.js} +107 -109
  8. package/dist/chunks/{bookmark-impact-B0estCHn.js → bookmark-impact-Czg6FGt5.js} +2 -2
  9. package/dist/chunks/{bookmark-state-Du3s13_V.js → bookmark-state-CflS88gq.js} +251 -250
  10. package/dist/chunks/{card-filter-builder-DbSmzvem.js → card-filter-builder-BS982X7x.js} +1001 -1000
  11. package/dist/chunks/{code-editor-DJNOsgJH.js → code-editor-BsxHzm9u.js} +43 -45
  12. package/dist/chunks/{comparison-window-caption-CMLb3mut.js → comparison-window-caption-lLTgzOkM.js} +252 -253
  13. package/dist/chunks/{dashboard-f8J9DHh5.js → dashboard-BiYSbxZv.js} +1 -1
  14. package/dist/chunks/{dashboard-briefing-launcher-DunvZYsU.js → dashboard-briefing-launcher-Bdj7luOr.js} +119 -120
  15. package/dist/chunks/{dashboard-controls-B09cN2Dz.js → dashboard-controls-TViDsnb8.js} +17 -19
  16. package/dist/chunks/dashboard-json-Dg9dQd9U.js +66 -0
  17. package/dist/chunks/{dates-BsJcyoC_.js → dates-BsPrWZIP.js} +8 -8
  18. package/dist/chunks/{edit-dashboard-visual-Cwzbpty8.js → edit-dashboard-visual-C6hoIeEJ.js} +20 -21
  19. package/dist/chunks/{filter-reach-copy-P-kDwUpY.js → filter-reach-copy-hcQ4os0u.js} +862 -852
  20. package/dist/chunks/filter-value-text-CVxEEDVl.js +146 -0
  21. package/dist/chunks/{index-BcXw0CpM.js → index-G4q89J6O.js} +74 -76
  22. package/dist/chunks/{layout-grid-0hIlqEtk.js → layout-grid-BIcoFfdS.js} +1 -1
  23. package/dist/chunks/{list-filter-DkgoCeBm.js → list-filter-C6tYkHyv.js} +1 -1
  24. package/dist/chunks/matrix-analytical-definition-dkS8szLM.js +1253 -0
  25. package/dist/chunks/matrix-member-presentation-DRa-9e6Q.js +169 -0
  26. package/dist/chunks/{matrix-operation-contract-Eb6elidS.js → matrix-operation-contract-DCVinw1o.js} +122 -122
  27. package/dist/chunks/{metric-comparison-ChXUFaZu.js → metric-comparison-n9NsIa-2.js} +175 -128
  28. package/dist/chunks/{palette-4vf2BEEg.js → palette-NjHOE_6B.js} +1 -1
  29. package/dist/chunks/pivot-result-contract-expectations-DkmueDTW.js +55 -0
  30. package/dist/chunks/{pivot-result-identity-BlbLrqaC.js → pivot-result-identity-B89X5xjb.js} +1 -1
  31. package/dist/chunks/raw-temporal-value-DdT0s47W.js +159 -0
  32. package/dist/chunks/{report-preferences-dialog-CbgmdWeZ.js → report-preferences-dialog-Xc8_GFju.js} +26 -28
  33. package/dist/chunks/{report-runtime-context-DnA_PiKo.js → report-runtime-context-BhPzLTbS.js} +1 -1
  34. package/dist/chunks/{resolve-dashboard-input-context-DPKSF3qj.js → resolve-dashboard-input-context-KqvcLcTM.js} +5956 -5880
  35. package/dist/chunks/{save-D6pHmSSP.js → save-C6VmEJTA.js} +1 -1
  36. package/dist/chunks/{saved-dashboard-context-CNudmm9U.js → saved-dashboard-context-BeXXyoD4.js} +6 -6
  37. package/dist/chunks/{semaphor-ready-indicator-CQd-PCCZ.js → semaphor-ready-indicator-BNkaANsG.js} +31011 -30850
  38. package/dist/chunks/{shelf-drop-preview-context-CWS3e20y.js → shelf-drop-preview-context-C_issPBA.js} +18 -20
  39. package/dist/chunks/{stored-dashboard-CrQFT27O.js → stored-dashboard-B6_StAty.js} +232 -234
  40. package/dist/chunks/{table-export-sheet--DUKWk6o.js → table-export-sheet-BWP2joD1.js} +1 -1
  41. package/dist/chunks/{temporal-input-presentation--2r9BLr0.js → temporal-input-presentation-scSWQXAB.js} +4 -4
  42. package/dist/chunks/{token-types-C8JymO8s.js → token-types-iKMplaBL.js} +1 -1
  43. package/dist/chunks/{upload-Cf3wXZT8.js → upload-BRW4Mwrd.js} +1 -1
  44. package/dist/chunks/validators-B8fpdinG.js +3651 -0
  45. package/dist/chunks/{variable-draft-BDxlD0dM.js → variable-draft-BQ3OMjvy.js} +4 -4
  46. package/dist/dashboard/index.js +2 -2
  47. package/dist/dashboard-authoring/index.js +1778 -1741
  48. package/dist/format-utils/index.js +230 -231
  49. package/dist/index.js +236 -237
  50. package/dist/report-runtime-context/index.js +1 -1
  51. package/dist/style.css +1 -1
  52. package/dist/surfboard/index.js +2 -2
  53. package/dist/types/components/surfboard/filter/types.d.ts +5 -4
  54. package/dist/types/components/ui-custom/date-range-presets.d.ts +1 -17
  55. package/dist/types/index.js +9 -9
  56. package/dist/types/lib/document/document-edits.d.ts +8 -3
  57. package/dist/types/lib/document/document-text-style.d.ts +54 -0
  58. package/dist/types/lib/hooks/use-date-filter.d.ts +3 -3
  59. package/dist/types/lib/matrix-table/matrix-card-adapter.d.ts +1 -1
  60. package/dist/types/lib/types/explorer-types.d.ts +2 -2
  61. package/dist/types/lib/types/index.d.ts +1 -1
  62. package/dist/types/lib/utils/card-definition.d.ts +7 -7
  63. package/dist/types/shared/analytics-protocol/agent-time-window.d.ts +84 -0
  64. package/dist/types/shared/analytics-protocol/applied-constraints.d.ts +2 -2
  65. package/dist/types/shared/analytics-protocol/contracts.d.ts +8 -17
  66. package/dist/types/shared/analytics-protocol/fixtures.d.ts +3 -2
  67. package/dist/types/shared/analytics-protocol/index.d.ts +2 -4
  68. package/dist/types/shared/analytics-protocol/matrix-definition-contract.d.ts +4 -4
  69. package/dist/types/shared/analytics-protocol/relative-date/describe.d.ts +18 -0
  70. package/dist/types/shared/analytics-protocol/relative-date/index.d.ts +7 -0
  71. package/dist/types/shared/analytics-protocol/relative-date/limits.d.ts +3 -0
  72. package/dist/types/shared/analytics-protocol/relative-date/presets.d.ts +11 -0
  73. package/dist/types/shared/analytics-protocol/relative-date/resolve.d.ts +49 -0
  74. package/dist/types/shared/analytics-protocol/relative-date/schemas.d.ts +76 -0
  75. package/dist/types/shared/analytics-protocol/relative-date/traits.d.ts +51 -0
  76. package/dist/types/shared/analytics-protocol/relative-date/window.d.ts +111 -0
  77. package/dist/types/shared/analytics-protocol/selection-contract.d.ts +1 -1
  78. package/dist/types/shared/assistant-protocol/context.d.ts +12 -12
  79. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +0 -2
  80. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +176 -1756
  81. package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +8 -4
  82. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +74 -74
  83. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +20 -20
  84. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +8 -2
  85. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +10 -2
  86. package/dist/types/shared/format-utils/filter-detail.d.ts +2 -8
  87. package/dist/types/shared/format-utils/filter-line.d.ts +2 -2
  88. package/dist/types/shared/format-utils/matrix-continuation.d.ts +3 -3
  89. package/dist/types/shared/temporal/index.d.ts +0 -2
  90. package/dist/types/shared/temporal/temporal-parity-fixtures.d.ts +2 -2
  91. package/package.json +2 -24
  92. package/DATA_APP_SDK.md +0 -339
  93. package/dist/chunks/dashboard-json-BNNCaKEc.js +0 -68
  94. package/dist/chunks/filter-value-text-7zhmth1S.js +0 -163
  95. package/dist/chunks/index-CuHybtft.js +0 -51
  96. package/dist/chunks/matrix-analytical-definition-C9xB_T84.js +0 -717
  97. package/dist/chunks/matrix-card-BSUeSXpD.js +0 -42
  98. package/dist/chunks/matrix-member-presentation-DZNgQpUq.js +0 -105
  99. package/dist/chunks/operators-B3zZoskU.js +0 -66
  100. package/dist/chunks/pivot-result-contract-expectations-Ddh1rNz5.js +0 -56
  101. package/dist/chunks/raw-temporal-value-Bqz8wc7L.js +0 -242
  102. package/dist/chunks/selection-reducer-OaJ-N5uN.js +0 -46
  103. package/dist/chunks/source-entity-resolution-DF6GulDn.js +0 -607
  104. package/dist/chunks/validators-wtjw0aw6.js +0 -3332
  105. package/dist/data-app-sdk/index.js +0 -1412
  106. package/dist/data-app-sdk-adapters/index.js +0 -361
  107. package/dist/data-app-sdk-validation/index.js +0 -1031
  108. package/dist/types/data-app-sdk/adapters.d.ts +0 -35
  109. package/dist/types/data-app-sdk/builders.d.ts +0 -62
  110. package/dist/types/data-app-sdk/contracts.d.ts +0 -419
  111. package/dist/types/data-app-sdk/executor.d.ts +0 -5
  112. package/dist/types/data-app-sdk/field-catalog-validation.d.ts +0 -29
  113. package/dist/types/data-app-sdk/hooks.d.ts +0 -11
  114. package/dist/types/data-app-sdk/index.d.ts +0 -9
  115. package/dist/types/data-app-sdk/provider.d.ts +0 -8
  116. package/dist/types/data-app-sdk/relationship-aware-field-policy.d.ts +0 -21
  117. package/dist/types/data-app-sdk/selection.d.ts +0 -2
  118. package/dist/types/data-app-sdk/validation.d.ts +0 -58
  119. package/dist/types/data-app-sdk-adapters.d.ts +0 -2
  120. package/dist/types/data-app-sdk-validation.d.ts +0 -2
  121. package/dist/types/data-app-sdk.d.ts +0 -2
  122. package/dist/types/shared/analytics-protocol/relative-date-filter.d.ts +0 -68
  123. package/dist/types/shared/analytics-protocol/relative-date-label.d.ts +0 -20
  124. package/dist/types/shared/analytics-protocol/time-window-schema.d.ts +0 -314
  125. package/dist/types/shared/analytics-protocol/time-window.d.ts +0 -52
  126. package/dist/types/shared/temporal/relative-date.d.ts +0 -21
  127. package/dist/types/shared/temporal/time-window-periods.d.ts +0 -21
  128. package/src/data-app-sdk/README.md +0 -402
@@ -1,1412 +0,0 @@
1
- import { toSemaphorInputSnapshots as ce, toSemaphorInputBinding as le, toSemaphorSelectionSnapshots as de, toSemaphorActiveInputSnapshots as q, toSemaphorMatrixIntent as fe, toSemaphorSqlIntent as me, toSemaphorInputOptionsIntent as pe, toSemaphorRecordsIntent as ye, toSemaphorAnalysisQueryOptions as he, toSemaphorAnalysisIntent as ve, toSemaphorMetricIntent as ge, hasSemaphorInputValue as b, normalizeSemaphorInputOptions as G, toSemaphorInputSpec as Z } from "../data-app-sdk-adapters/index.js";
2
- import { j as Se } from "../chunks/index-CuHybtft.js";
3
- import { J as qe, K as x, s as Ie } from "../chunks/validators-wtjw0aw6.js";
4
- import { a as Tt, aD as Nt } from "../chunks/validators-wtjw0aw6.js";
5
- import { m as Ae, ao as we, an as be, A as F, S as W, I as ke } from "../chunks/matrix-operation-contract-Eb6elidS.js";
6
- import "../chunks/analytics-base-schemas-BaIQrEzX.js";
7
- import "zod";
8
- import { createContext as Ke, useContext as Ee, useMemo as h, useEffect as M, useState as _, useCallback as S, useRef as D } from "react";
9
- import { r as J } from "../chunks/selection-reducer-OaJ-N5uN.js";
10
- import { jsx as De } from "react/jsx-runtime";
11
- function E(e, t, r) {
12
- return {
13
- ...r,
14
- name: e,
15
- role: t
16
- };
17
- }
18
- function bt(e) {
19
- return e;
20
- }
21
- function kt(e) {
22
- return e;
23
- }
24
- const Kt = {
25
- source: {
26
- semantic(e) {
27
- return {
28
- ...e,
29
- kind: "semantic"
30
- };
31
- },
32
- sql(e) {
33
- return {
34
- ...e,
35
- kind: "sql"
36
- };
37
- }
38
- },
39
- field: {
40
- measure(e, t = {}) {
41
- return E(e, "measure", t);
42
- },
43
- dimension(e, t = {}) {
44
- return E(e, "dimension", t);
45
- },
46
- date(e, t = {}) {
47
- return E(e, "date", t);
48
- },
49
- id(e, t = {}) {
50
- return E(e, "id", t);
51
- }
52
- },
53
- filter(e) {
54
- return {
55
- ...e,
56
- kind: "filter"
57
- };
58
- },
59
- selection(e) {
60
- return {
61
- ...e,
62
- kind: "selection"
63
- };
64
- },
65
- bindInput(e, t) {
66
- return {
67
- toAnalyticsInput() {
68
- const [r] = ce([e]), n = le({
69
- ...t,
70
- inputId: t.inputId || r.inputId
71
- });
72
- return {
73
- ...r,
74
- inputId: n.inputId,
75
- ...n.kind ? { kind: n.kind } : {},
76
- ...n.controlRole ? { controlRole: n.controlRole } : {},
77
- ...n.operator ? { operator: n.operator } : {},
78
- ...n.field ? { field: n.field } : {},
79
- ...n.relationshipHint ? { relationshipHint: n.relationshipHint } : {}
80
- };
81
- }
82
- };
83
- },
84
- control(e) {
85
- return {
86
- ...e,
87
- kind: "control"
88
- };
89
- },
90
- sqlParam(e) {
91
- return {
92
- ...e,
93
- kind: "control",
94
- role: "sqlParam"
95
- };
96
- },
97
- derivedField(e) {
98
- return {
99
- ...e,
100
- kind: "derived_field",
101
- expressionLanguage: e.expressionLanguage || "semaphor_sql_template"
102
- };
103
- },
104
- metric(e) {
105
- return {
106
- ...e,
107
- queryKind: "metric"
108
- };
109
- },
110
- analysis(e) {
111
- return {
112
- ...e,
113
- queryKind: "analysis"
114
- };
115
- },
116
- records(e) {
117
- return {
118
- ...e,
119
- queryKind: "records"
120
- };
121
- },
122
- inputOptions(e) {
123
- return {
124
- ...e,
125
- queryKind: "inputOptions"
126
- };
127
- },
128
- sql(e) {
129
- return {
130
- ...e,
131
- queryKind: "sql"
132
- };
133
- },
134
- matrix(e) {
135
- return {
136
- ...e,
137
- queryKind: "matrix"
138
- };
139
- }
140
- }, Oe = [
141
- "primary",
142
- "comparisons",
143
- "contributors",
144
- "segments",
145
- "periodChanges",
146
- "records",
147
- "changes",
148
- "drivers",
149
- "absoluteDeltaDrivers",
150
- "largestNegativeChanges",
151
- "largestPositiveChanges",
152
- "largestNegativeDrivers",
153
- "largestPositiveDrivers"
154
- ], xe = [
155
- "primary",
156
- "records",
157
- "periodChanges",
158
- "changes",
159
- "comparisons",
160
- "contributors",
161
- "segments",
162
- "drivers",
163
- "absoluteDeltaDrivers",
164
- "largestNegativeChanges",
165
- "largestPositiveChanges",
166
- "largestNegativeDrivers",
167
- "largestPositiveDrivers"
168
- ];
169
- function ee(e) {
170
- if (!e)
171
- return {};
172
- const t = Ne(e.executionResult), r = _e(e, t), n = Re(r), s = te(
173
- L(e.analysisWarnings),
174
- Me(r)
175
- );
176
- return {
177
- ...e,
178
- ...Object.keys(r).length ? { resultSets: r } : {},
179
- ...s.length ? { analysisWarnings: s } : {},
180
- ...n ? {
181
- columns: n.columns,
182
- records: n.records,
183
- rowCount: n.rowCount
184
- } : {}
185
- };
186
- }
187
- function _e(e, t) {
188
- const r = $e(e.resultSets);
189
- for (const s of Oe) {
190
- if (r[s])
191
- continue;
192
- const o = je(e[s]);
193
- if (!o.length)
194
- continue;
195
- const a = t.length ? t : Ve(o);
196
- r[s] = {
197
- id: s,
198
- role: s,
199
- ...P({
200
- records: o,
201
- columns: a,
202
- resultSetKey: s
203
- }),
204
- columns: a,
205
- rowCount: o.length
206
- };
207
- }
208
- const n = Te(e.executionResult);
209
- return n && n.records.length > 0 && !r.records && (r.records = n), r;
210
- }
211
- function $e(e) {
212
- return Object.fromEntries(
213
- Object.entries(e || {}).map(([t, r]) => [
214
- t,
215
- Ce(r, t)
216
- ])
217
- );
218
- }
219
- function Ce(e, t = e.id || e.role || "resultSet") {
220
- var n;
221
- const r = P({
222
- records: e.records || [],
223
- columns: e.columns || [],
224
- resultSetKey: t
225
- });
226
- return {
227
- ...e,
228
- ...r,
229
- ...e.warnings || r.warnings ? {
230
- warnings: te(
231
- L(e.warnings),
232
- r.warnings
233
- )
234
- } : {},
235
- rowCount: e.rowCount ?? ((n = e.records) == null ? void 0 : n.length) ?? 0
236
- };
237
- }
238
- function Re(e) {
239
- var t;
240
- for (const r of xe)
241
- if ((t = e[r]) != null && t.records.length)
242
- return e[r];
243
- return Object.values(e).find((r) => r.records.length) || Object.values(e)[0];
244
- }
245
- function Te(e) {
246
- const t = e == null ? void 0 : e.result;
247
- if (!(!t || t.kind !== "records" && t.kind !== "sql"))
248
- return {
249
- id: "records",
250
- role: "records",
251
- ...P({
252
- records: t.records,
253
- columns: t.columns,
254
- resultSetKey: "records"
255
- }),
256
- columns: t.columns,
257
- rowCount: t.rowCount ?? t.records.length
258
- };
259
- }
260
- function Ne(e) {
261
- const t = e == null ? void 0 : e.result;
262
- return !t || t.kind !== "records" && t.kind !== "sql" ? [] : t.columns;
263
- }
264
- function je(e) {
265
- return Array.isArray(e) ? e.filter(
266
- (t) => !!(t && typeof t == "object" && !Array.isArray(t))
267
- ) : [];
268
- }
269
- function P({
270
- records: e,
271
- columns: t,
272
- resultSetKey: r
273
- }) {
274
- if (!t.length)
275
- return { records: e };
276
- const n = [];
277
- return {
278
- records: e.map((o, a) => {
279
- const c = {};
280
- return t.forEach((u) => {
281
- if (Object.prototype.hasOwnProperty.call(o, u.key)) {
282
- c[u.key] = o[u.key];
283
- return;
284
- }
285
- n.push({
286
- code: "missing_analysis_result_key",
287
- severity: "warning",
288
- resultSetKey: r,
289
- rowIndex: a,
290
- columnKey: u.key,
291
- ...u.name ? { columnName: u.name } : {},
292
- ...u.label ? { columnLabel: u.label } : {},
293
- availableKeys: Object.keys(o),
294
- message: `Analysis result set "${r}" row ${a} is missing column key "${u.key}". Rows must expose values by column.key; labels and column names are display metadata only.`
295
- });
296
- }), c;
297
- }),
298
- ...n.length ? { warnings: n } : {}
299
- };
300
- }
301
- function Ve(e) {
302
- return Array.from(
303
- new Set(e.flatMap((r) => Object.keys(r)))
304
- ).map((r) => ({
305
- key: r,
306
- name: r,
307
- label: r
308
- }));
309
- }
310
- function Me(e) {
311
- return Object.values(e).flatMap(
312
- (t) => L(t.warnings)
313
- );
314
- }
315
- function L(e) {
316
- return Array.isArray(e) ? e.filter(Pe) : [];
317
- }
318
- function Pe(e) {
319
- return !!(e && typeof e == "object" && !Array.isArray(e));
320
- }
321
- function te(...e) {
322
- const t = /* @__PURE__ */ new Set(), r = [];
323
- for (const n of e.flatMap((s) => s || [])) {
324
- const s = Le(n);
325
- t.has(s) || (t.add(s), r.push(n));
326
- }
327
- return r;
328
- }
329
- function Le(e) {
330
- return e.code === "missing_analysis_result_key" ? [
331
- e.code,
332
- e.resultSetKey,
333
- e.rowIndex,
334
- e.columnKey
335
- ].join(":") : j(e);
336
- }
337
- function j(e) {
338
- if (!e || typeof e != "object")
339
- return JSON.stringify(e);
340
- if (Array.isArray(e))
341
- return `[${e.map((r) => j(r)).join(",")}]`;
342
- const t = e;
343
- return `{${Object.keys(t).sort().map((r) => `${JSON.stringify(r)}:${j(t[r])}`).join(",")}}`;
344
- }
345
- const C = {
346
- primaryValue: null
347
- }, R = {}, Be = { records: [] }, T = { options: [] }, ze = { records: [] }, N = {};
348
- function v(e, t) {
349
- const r = de(t);
350
- return r.length === 0 ? e : {
351
- ...e,
352
- selections: r,
353
- queryKey: JSON.stringify([e.queryKey, r])
354
- };
355
- }
356
- function Ue(e) {
357
- const t = q(e.inputs), r = he(e);
358
- try {
359
- const n = ve(e), s = A(n, "analysis");
360
- return s ? {
361
- error: s,
362
- activeInputs: t,
363
- analysisOptions: r,
364
- queryKey: f(
365
- void 0,
366
- t,
367
- s,
368
- r
369
- ),
370
- idleData: R
371
- } : {
372
- intent: n,
373
- error: null,
374
- activeInputs: t,
375
- analysisOptions: r,
376
- queryKey: f(n, t, void 0, r),
377
- idleData: R
378
- };
379
- } catch (n) {
380
- const s = I(n, "analysis");
381
- return {
382
- error: s,
383
- activeInputs: t,
384
- analysisOptions: r,
385
- queryKey: f(
386
- void 0,
387
- t,
388
- s,
389
- r
390
- ),
391
- idleData: R
392
- };
393
- }
394
- }
395
- function He(e) {
396
- const t = q(e.inputs);
397
- try {
398
- const r = ge(e), n = A(r);
399
- return n ? {
400
- error: n,
401
- activeInputs: t,
402
- queryKey: f(void 0, t, n),
403
- idleData: C
404
- } : {
405
- intent: r,
406
- error: null,
407
- activeInputs: t,
408
- queryKey: f(r, t),
409
- idleData: C
410
- };
411
- } catch (r) {
412
- const n = I(r, "metric");
413
- return {
414
- error: n,
415
- activeInputs: t,
416
- queryKey: f(void 0, t, n),
417
- idleData: C
418
- };
419
- }
420
- }
421
- function Qe(e) {
422
- const t = q(e.inputs), r = Be;
423
- try {
424
- const n = ye(e), s = A(n);
425
- return s ? {
426
- error: s,
427
- activeInputs: t,
428
- queryKey: f(void 0, t, s),
429
- idleData: r
430
- } : {
431
- intent: n,
432
- error: null,
433
- activeInputs: t,
434
- queryKey: f(n, t),
435
- idleData: r
436
- };
437
- } catch (n) {
438
- const s = I(n, "records");
439
- return {
440
- error: s,
441
- activeInputs: t,
442
- queryKey: f(void 0, t, s),
443
- idleData: r
444
- };
445
- }
446
- }
447
- function Fe(e) {
448
- const t = q(e.inputs);
449
- try {
450
- const r = pe(e), n = A(r);
451
- return n ? {
452
- error: n,
453
- activeInputs: t,
454
- queryKey: f(void 0, t, n),
455
- idleData: T
456
- } : {
457
- intent: r,
458
- error: null,
459
- activeInputs: t,
460
- queryKey: f(r, t),
461
- idleData: T
462
- };
463
- } catch (r) {
464
- const n = I(r, "inputOptions");
465
- return {
466
- error: n,
467
- activeInputs: t,
468
- queryKey: f(void 0, t, n),
469
- idleData: T
470
- };
471
- }
472
- }
473
- function We(e) {
474
- const t = q(e.inputs), r = ze;
475
- try {
476
- const n = me(e), s = A(n);
477
- return s ? {
478
- error: s,
479
- activeInputs: t,
480
- queryKey: f(void 0, t, s),
481
- idleData: r
482
- } : {
483
- intent: n,
484
- error: null,
485
- activeInputs: t,
486
- queryKey: f(n, t),
487
- idleData: r
488
- };
489
- } catch (n) {
490
- const s = I(n, "sql");
491
- return {
492
- error: s,
493
- activeInputs: t,
494
- queryKey: f(void 0, t, s),
495
- idleData: r
496
- };
497
- }
498
- }
499
- function Je(e) {
500
- const t = q(e.inputs);
501
- try {
502
- const r = fe(e), n = Ae.parse(e.matrixWindowRequest), s = A(r);
503
- return s ? {
504
- error: s,
505
- activeInputs: t,
506
- queryKey: f(void 0, t, s),
507
- idleData: N
508
- } : {
509
- intent: r,
510
- error: null,
511
- activeInputs: t,
512
- matrixWindowRequest: n,
513
- queryKey: JSON.stringify([f(r, t), n]),
514
- idleData: N
515
- };
516
- } catch (r) {
517
- const n = I(r, "matrix");
518
- return {
519
- error: n,
520
- activeInputs: t,
521
- queryKey: f(void 0, t, n),
522
- idleData: N
523
- };
524
- }
525
- }
526
- function V(e) {
527
- var o;
528
- if (Ye(e))
529
- return e;
530
- const t = e instanceof Error ? e : void 0, r = e, n = r == null ? void 0 : r.executionResult, s = $(
531
- (t == null ? void 0 : t.message) ?? String(e),
532
- {
533
- requestId: typeof (r == null ? void 0 : r.requestId) == "string" ? r.requestId : void 0,
534
- details: r == null ? void 0 : r.details,
535
- executionResult: n,
536
- validation: (r == null ? void 0 : r.validation) ?? (n == null ? void 0 : n.validation),
537
- validationIssues: (r == null ? void 0 : r.validationIssues) ?? ((o = n == null ? void 0 : n.validation) == null ? void 0 : o.errors)
538
- }
539
- );
540
- return s.name = (t == null ? void 0 : t.name) || s.name, s.stack = t == null ? void 0 : t.stack, s;
541
- }
542
- function I(e, t) {
543
- const r = V(e);
544
- if (r.executionResult || r.validation)
545
- return r;
546
- const n = {
547
- ok: !1,
548
- errors: [
549
- {
550
- code: "invalid_query_spec",
551
- message: r.message,
552
- path: "spec"
553
- }
554
- ],
555
- warnings: [],
556
- repairHints: [
557
- {
558
- code: "invalid_query_spec",
559
- message: r.message,
560
- recommendedNextStep: "Update the Data App query spec to satisfy the SDK builder contract."
561
- }
562
- ]
563
- }, s = re(
564
- void 0,
565
- t,
566
- n
567
- ), o = $(r.message, {
568
- executionResult: s,
569
- validation: n,
570
- validationIssues: n.errors
571
- });
572
- return o.stack = r.stack, o;
573
- }
574
- function $(e, t = {}) {
575
- var s, o, a;
576
- const r = new Error(e);
577
- r.name = "SemaphorDataAppQueryError", r.kind = "data_app_query_error", t.requestId && (r.requestId = t.requestId), t.details !== void 0 && (r.details = t.details), t.executionResult !== void 0 && (r.executionResult = t.executionResult), t.validation !== void 0 && (r.validation = t.validation);
578
- const n = t.validationIssues ?? ((s = t.validation) == null ? void 0 : s.errors) ?? ((a = (o = t.executionResult) == null ? void 0 : o.validation) == null ? void 0 : a.errors);
579
- return n !== void 0 && (r.validationIssues = n), r;
580
- }
581
- function Ye(e) {
582
- return e instanceof Error && e.kind === "data_app_query_error";
583
- }
584
- function A(e, t = e.kind) {
585
- const r = qe(e);
586
- if (r.ok)
587
- return null;
588
- const n = r.errors.map(
589
- (o) => o.path ? `${o.code} at ${o.path}: ${o.message}` : `${o.code}: ${o.message}`
590
- ).join("; "), s = re(
591
- e,
592
- t,
593
- r
594
- );
595
- return $(
596
- `Invalid Semaphor analytics intent. ${n}`,
597
- {
598
- executionResult: s,
599
- validation: r,
600
- validationIssues: r.errors
601
- }
602
- );
603
- }
604
- function re(e, t, r) {
605
- return {
606
- ...x(e) ? { intentId: x(e) } : {},
607
- ...e ? { intent: e } : {},
608
- status: "failed",
609
- resultShape: t,
610
- validation: r,
611
- coverage: {
612
- answeredObligations: [],
613
- missingObligations: ["query_spec_validation"],
614
- warnings: r.warnings
615
- },
616
- missingFields: r.errors.filter((n) => n.code === "missing_field").flatMap((n) => {
617
- var o;
618
- const s = n.path || ((o = n.repairHint) == null ? void 0 : o.invalidField);
619
- return s ? [s] : [];
620
- }),
621
- warnings: r.warnings.map((n) => n.message),
622
- diagnosticFeedback: {
623
- version: 1,
624
- status: "blocked",
625
- summary: "Data App query spec validation failed.",
626
- answered: [],
627
- blocked: r.errors.map((n) => {
628
- var o, a;
629
- const s = {
630
- reasonCode: "query_validation_failed",
631
- message: n.message
632
- };
633
- return n.code === "missing_field" && (s.missingFields = [
634
- n.path || ((o = n.repairHint) == null ? void 0 : o.invalidField) || n.message
635
- ]), (a = n.repairHint) != null && a.recommendedNextStep && (s.recommendedNextStep = n.repairHint.recommendedNextStep), s;
636
- })
637
- },
638
- metadata: {
639
- validationKind: "data_app_sdk_query_spec"
640
- }
641
- };
642
- }
643
- function f(e, t, r, n) {
644
- return JSON.stringify({
645
- intent: e,
646
- activeInputs: t,
647
- analysisOptions: n,
648
- error: r == null ? void 0 : r.message
649
- });
650
- }
651
- function Xe() {
652
- return {
653
- executeAnalysis: (e, t, r) => w(
654
- e,
655
- t,
656
- r ?? {}
657
- ).then(ee),
658
- executeMetric: (e, t) => w(e, t),
659
- executeRecords: (e, t) => w(e, t),
660
- executeInputOptions: (e, t) => w(e, t),
661
- executeSql: (e, t) => w(e, t),
662
- executeMatrix: async (e, t) => {
663
- var n, s;
664
- const r = await Ge(e, t);
665
- if (r.status === "failed")
666
- throw ie(
667
- ((n = r.metadata.matrixFailure) == null ? void 0 : n.message) ?? "Matrix execution failed.",
668
- { executionResult: r }
669
- );
670
- return { window: (s = r.result) == null ? void 0 : s.window, executionResult: r };
671
- }
672
- };
673
- }
674
- async function w(e, t, r) {
675
- if (!t.token)
676
- throw new Error(
677
- "SemaphorDataAppProvider needs a token to execute queries."
678
- );
679
- const n = oe(t), s = et(e, n);
680
- let o;
681
- try {
682
- o = await ne({
683
- intent: e,
684
- activeInputs: t.activeInputs,
685
- selections: t.selections,
686
- ...r ? { analysisOptions: r } : {},
687
- resultShape: e.kind,
688
- ...Ze(t) ? { debug: { responseDetail: "debug" } } : {}
689
- }, t);
690
- } catch (c) {
691
- throw new Error(
692
- `${s}: ${c instanceof Error ? c.message : String(c)}`
693
- );
694
- }
695
- const a = await se(o);
696
- if (!o.ok || a.error)
697
- throw ie(
698
- `${s}: ${a.error || `Semaphor Data App execution failed with status ${o.status}.`}`,
699
- a
700
- );
701
- return a;
702
- }
703
- function ne(e, t, r) {
704
- if (!t.token) throw new Error("SemaphorDataAppProvider needs a token to execute queries.");
705
- return fetch(oe(t), {
706
- method: "POST",
707
- signal: r,
708
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${t.token}` },
709
- body: JSON.stringify(e)
710
- });
711
- }
712
- async function Ge(e, t, r) {
713
- const n = we.parse(e), s = await ne({
714
- ...n,
715
- activeInputs: t.activeInputs,
716
- selections: t.selections,
717
- resultShape: "matrix"
718
- }, t, r), o = await se(s), a = be.safeParse(o.executionResult);
719
- if (!a.success) throw new Error(o.error || "Matrix execution returned an invalid governed result.");
720
- if (!s.ok && a.data.status !== "failed") throw new Error(o.error || `Matrix request failed (${s.status}).`);
721
- return a.data;
722
- }
723
- function ie(e, t) {
724
- var r;
725
- return $(e, {
726
- requestId: t.requestId,
727
- details: t.details,
728
- executionResult: t.executionResult,
729
- validation: (r = t.executionResult) == null ? void 0 : r.validation
730
- });
731
- }
732
- function Ze(e) {
733
- const t = e.debug;
734
- return t ? t === !0 ? !0 : t.enabled !== !1 && t.requestServerDebug !== !1 : !1;
735
- }
736
- function et(e, t) {
737
- return [
738
- `Semaphor ${e.kind} query`,
739
- x(e) ? `id=${x(e)}` : void 0,
740
- "label" in e && e.label ? `label=${e.label}` : void 0,
741
- tt(e),
742
- `endpoint=${rt(t)}`
743
- ].filter((r) => !!r).join(" ");
744
- }
745
- function tt(e) {
746
- const t = "source" in e ? e.source : void 0;
747
- if (!(!t || typeof t != "object")) {
748
- if (t.kind === "semantic")
749
- return `source=${[
750
- t.domainId,
751
- t.datasetId || t.datasetName
752
- ].filter(Boolean).join("/")}`;
753
- if (t.kind === "physical")
754
- return `source=${[
755
- t.connectionId,
756
- t.databaseName,
757
- t.schemaName,
758
- t.tableName
759
- ].filter(Boolean).join("/")}`;
760
- if (t.kind === "sql")
761
- return t.connectionId ? `source=${t.connectionId}` : void 0;
762
- }
763
- }
764
- function rt(e) {
765
- if (!e)
766
- return "/api/v1/data-app/execute";
767
- try {
768
- return new URL(e, "http://localhost").pathname;
769
- } catch {
770
- return e;
771
- }
772
- }
773
- async function se(e) {
774
- const t = await e.text().catch(() => "");
775
- if (!t.trim())
776
- return e.ok ? {
777
- error: "Semaphor Data App execution returned an empty response."
778
- } : {};
779
- try {
780
- return JSON.parse(t);
781
- } catch {
782
- return e.ok ? {
783
- error: "Semaphor Data App execution returned invalid JSON.",
784
- details: t
785
- } : {
786
- error: nt(e, t),
787
- details: t
788
- };
789
- }
790
- }
791
- function nt(e, t) {
792
- const r = e.statusText ? ` ${e.statusText}` : "", n = t.replace(/\s+/g, " ").trim();
793
- return n ? `Semaphor Data App execution failed with status ${e.status}${r}: ${n.slice(0, 240)}` : `Semaphor Data App execution failed with status ${e.status}${r}.`;
794
- }
795
- function oe(e) {
796
- const t = it(e).replace(/\/+$/, "");
797
- return t ? t.endsWith("/api") ? `${t}/v1/data-app/execute` : `${t}/api/v1/data-app/execute` : "/api/v1/data-app/execute";
798
- }
799
- function it(e) {
800
- if (e.apiBaseUrl)
801
- return e.apiBaseUrl;
802
- if (!e.token)
803
- return "";
804
- try {
805
- return Se(e.token).apiServiceUrl || "";
806
- } catch {
807
- return "";
808
- }
809
- }
810
- const ae = Ke({});
811
- function st() {
812
- if (!(typeof window > "u"))
813
- return window.__SEMAPHOR_DATA_APP_RUNTIME__;
814
- }
815
- function ot() {
816
- return Ee(ae);
817
- }
818
- function Et(e) {
819
- const [t, r] = _(e.defaultValue), n = Object.prototype.hasOwnProperty.call(e, "value"), s = n ? e.value : t, o = h(
820
- () => G(e.options),
821
- [e.options]
822
- ), a = S(
823
- (u) => {
824
- var i;
825
- const d = u;
826
- (i = e.onValueChange) == null || i.call(e, d), n || r(d);
827
- },
828
- [n, e]
829
- ), c = S(() => a(void 0), [a]);
830
- return h(() => {
831
- const u = Z(e);
832
- return {
833
- id: e.id,
834
- kind: e.kind,
835
- label: e.label,
836
- field: u.field,
837
- operator: u.operator,
838
- relationshipHint: u.relationshipHint,
839
- controlRole: e.kind === "control" ? e.role : void 0,
840
- value: s,
841
- options: o,
842
- isActive: b(s),
843
- setValue: a,
844
- clear: c,
845
- toAnalyticsInput: () => ({
846
- inputId: u.inputId,
847
- field: u.field,
848
- kind: e.kind,
849
- label: e.label,
850
- value: s,
851
- isActive: b(s),
852
- operator: u.operator,
853
- relationshipHint: u.relationshipHint,
854
- controlRole: e.kind === "control" ? e.role : void 0
855
- })
856
- };
857
- }, [c, o, a, e, s]);
858
- }
859
- function Dt(e) {
860
- const [t, r] = _(() => pt(e));
861
- return M(() => {
862
- r((n) => {
863
- let s = n;
864
- for (const o of e)
865
- !Object.prototype.hasOwnProperty.call(s, o.id) && o.defaultValue !== void 0 && (s = { ...s, [o.id]: o.defaultValue });
866
- return s;
867
- });
868
- }, [e]), h(
869
- () => e.map((n) => {
870
- const s = Object.prototype.hasOwnProperty.call(
871
- n,
872
- "value"
873
- ), o = s ? n.value : t[n.id], a = G(n.options), c = (i) => {
874
- var l;
875
- (l = n.onValueChange) == null || l.call(n, i), s || r((m) => ({
876
- ...m,
877
- [n.id]: i
878
- }));
879
- }, u = () => c(void 0), d = Z(n);
880
- return {
881
- id: n.id,
882
- kind: n.kind,
883
- label: n.label,
884
- field: d.field,
885
- operator: d.operator,
886
- relationshipHint: d.relationshipHint,
887
- controlRole: n.kind === "control" ? n.role : void 0,
888
- value: o,
889
- options: a,
890
- isActive: b(o),
891
- setValue: c,
892
- clear: u,
893
- toAnalyticsInput: () => ({
894
- inputId: d.inputId,
895
- field: d.field,
896
- kind: n.kind,
897
- label: n.label,
898
- value: o,
899
- isActive: b(o),
900
- operator: d.operator,
901
- relationshipHint: d.relationshipHint,
902
- controlRole: n.kind === "control" ? n.role : void 0
903
- })
904
- };
905
- }),
906
- [e, t]
907
- );
908
- }
909
- function Ot(e, t) {
910
- const r = (t == null ? void 0 : t.status) === "success" ? t.options : void 0, n = h(() => ut(r), [r]);
911
- M(() => {
912
- at(e.value, r) || e.clear();
913
- }, [e, n, t == null ? void 0 : t.status, r]);
914
- }
915
- function at(e, t) {
916
- if (!b(e) || t === void 0)
917
- return !0;
918
- const r = new Set(
919
- t.map((s) => Y(s.value))
920
- );
921
- return (Array.isArray(e) ? e : [e]).every(
922
- (s) => r.has(Y(s))
923
- );
924
- }
925
- function ut(e) {
926
- return JSON.stringify((e || []).map((t) => t.value));
927
- }
928
- function Y(e) {
929
- return `${typeof e}:${String(e)}`;
930
- }
931
- function xt(e, t = {}) {
932
- const r = h(
933
- () => t.inputs ? {
934
- ...e,
935
- inputs: t.inputs
936
- } : e,
937
- [t.inputs, e]
938
- ), n = h(() => (() => {
939
- switch (r.queryKind) {
940
- case "metric":
941
- return {
942
- queryKind: r.queryKind,
943
- request: v(
944
- He(r),
945
- t.selections
946
- )
947
- };
948
- case "analysis":
949
- return {
950
- queryKind: r.queryKind,
951
- request: v(
952
- Ue(r),
953
- t.selections
954
- )
955
- };
956
- case "records":
957
- return {
958
- queryKind: r.queryKind,
959
- request: v(
960
- Qe(r),
961
- t.selections
962
- )
963
- };
964
- case "inputOptions":
965
- return {
966
- queryKind: r.queryKind,
967
- request: v(
968
- Fe(r),
969
- t.selections
970
- )
971
- };
972
- case "sql":
973
- return {
974
- queryKind: r.queryKind,
975
- request: v(
976
- We(r),
977
- t.selections
978
- )
979
- };
980
- case "matrix":
981
- return {
982
- queryKind: r.queryKind,
983
- request: v(
984
- Je(r),
985
- t.selections
986
- )
987
- };
988
- default:
989
- return O(r);
990
- }
991
- })(), [r, t.selections]), s = S(
992
- (i) => {
993
- var m, p, B, z, U, k, H, K, Q;
994
- const l = n.request;
995
- if (l.intent)
996
- switch (n.queryKind) {
997
- case "metric":
998
- return (m = i.executor) == null ? void 0 : m.executeMetric(
999
- l.intent,
1000
- i
1001
- );
1002
- case "analysis":
1003
- return (B = (p = i.executor) == null ? void 0 : p.executeAnalysis) == null ? void 0 : B.call(
1004
- p,
1005
- l.intent,
1006
- i,
1007
- l.analysisOptions
1008
- );
1009
- case "records":
1010
- return (z = i.executor) == null ? void 0 : z.executeRecords(
1011
- l.intent,
1012
- i
1013
- );
1014
- case "inputOptions":
1015
- return (U = i.executor) == null ? void 0 : U.executeInputOptions(
1016
- l.intent,
1017
- i
1018
- );
1019
- case "sql":
1020
- return (H = (k = i.executor) == null ? void 0 : k.executeSql) == null ? void 0 : H.call(
1021
- k,
1022
- l.intent,
1023
- i
1024
- );
1025
- case "matrix":
1026
- if (!l.matrixWindowRequest) throw new Error("Matrix window request is required.");
1027
- return (Q = (K = i.executor) == null ? void 0 : K.executeMatrix) == null ? void 0 : Q.call(
1028
- K,
1029
- { intent: l.intent, matrixWindowRequest: l.matrixWindowRequest },
1030
- i
1031
- );
1032
- default:
1033
- return O(n);
1034
- }
1035
- },
1036
- [n]
1037
- ), o = mt(
1038
- n.request.queryKey,
1039
- s,
1040
- n.request.idleData,
1041
- n.request.activeInputs,
1042
- n.request.selections
1043
- ), a = n.request.error ? n.request.idleData : o.data, c = n.request.error ? "error" : o.status, u = !n.request.error && o.status === "loading", d = n.request.error || o.error;
1044
- switch (n.queryKind) {
1045
- case "metric": {
1046
- const i = a, l = g({
1047
- queryKind: n.queryKind,
1048
- status: c,
1049
- isLoading: u,
1050
- error: d,
1051
- payload: i,
1052
- activeInputs: n.request.activeInputs,
1053
- selections: n.request.selections,
1054
- isStale: o.isStale
1055
- });
1056
- return {
1057
- id: r.id,
1058
- intent: n.request.intent,
1059
- primaryValue: (i == null ? void 0 : i.primaryValue) ?? null,
1060
- measures: i == null ? void 0 : i.measures,
1061
- measureBindings: i == null ? void 0 : i.measureBindings,
1062
- missingMeasures: i == null ? void 0 : i.missingMeasures,
1063
- comparisonValue: i == null ? void 0 : i.comparisonValue,
1064
- comparisonKind: i == null ? void 0 : i.comparisonKind,
1065
- delta: i == null ? void 0 : i.delta,
1066
- deltaPercent: i == null ? void 0 : i.deltaPercent,
1067
- records: i == null ? void 0 : i.records,
1068
- ...l
1069
- };
1070
- }
1071
- case "analysis": {
1072
- const i = ee(a), l = g({
1073
- queryKind: n.queryKind,
1074
- status: c,
1075
- isLoading: u,
1076
- error: d,
1077
- payload: i,
1078
- activeInputs: n.request.activeInputs,
1079
- selections: n.request.selections,
1080
- isStale: o.isStale
1081
- });
1082
- return {
1083
- id: r.id,
1084
- intent: n.request.intent,
1085
- ...i || {},
1086
- ...l
1087
- };
1088
- }
1089
- case "records": {
1090
- const i = a, l = g({
1091
- queryKind: n.queryKind,
1092
- status: c,
1093
- isLoading: u,
1094
- error: d,
1095
- payload: i,
1096
- activeInputs: n.request.activeInputs,
1097
- selections: n.request.selections,
1098
- isStale: o.isStale
1099
- });
1100
- return {
1101
- id: r.id,
1102
- intent: n.request.intent,
1103
- records: (i == null ? void 0 : i.records) || [],
1104
- columns: i == null ? void 0 : i.columns,
1105
- rowCount: i == null ? void 0 : i.rowCount,
1106
- pagination: i == null ? void 0 : i.pagination,
1107
- totals: i == null ? void 0 : i.totals,
1108
- ...l
1109
- };
1110
- }
1111
- case "inputOptions": {
1112
- const i = a, l = g({
1113
- queryKind: n.queryKind,
1114
- status: c,
1115
- isLoading: u,
1116
- error: d,
1117
- payload: i,
1118
- activeInputs: n.request.activeInputs,
1119
- selections: n.request.selections,
1120
- isStale: o.isStale
1121
- });
1122
- return {
1123
- id: r.id,
1124
- intent: n.request.intent,
1125
- options: (i == null ? void 0 : i.options) || [],
1126
- dependencyOutcomes: i == null ? void 0 : i.dependencyOutcomes,
1127
- match: i == null ? void 0 : i.match,
1128
- ...l
1129
- };
1130
- }
1131
- case "sql": {
1132
- const i = a, l = g({
1133
- queryKind: n.queryKind,
1134
- status: c,
1135
- isLoading: u,
1136
- error: d,
1137
- payload: i,
1138
- activeInputs: n.request.activeInputs,
1139
- selections: n.request.selections,
1140
- isStale: o.isStale
1141
- });
1142
- return {
1143
- id: r.id,
1144
- intent: n.request.intent,
1145
- records: (i == null ? void 0 : i.records) || [],
1146
- columns: i == null ? void 0 : i.columns,
1147
- rowCount: i == null ? void 0 : i.rowCount,
1148
- pagination: i == null ? void 0 : i.pagination,
1149
- output: i == null ? void 0 : i.output,
1150
- rowLimitExceeded: i == null ? void 0 : i.rowLimitExceeded,
1151
- ...l
1152
- };
1153
- }
1154
- case "matrix": {
1155
- const i = a, l = g({
1156
- queryKind: n.queryKind,
1157
- status: c,
1158
- isLoading: u,
1159
- error: d,
1160
- payload: i,
1161
- activeInputs: n.request.activeInputs,
1162
- selections: n.request.selections,
1163
- isStale: o.isStale
1164
- });
1165
- return {
1166
- id: r.id,
1167
- intent: n.request.intent,
1168
- window: i == null ? void 0 : i.window,
1169
- ...l,
1170
- executionResult: lt(l.executionResult) ? l.executionResult : void 0
1171
- };
1172
- }
1173
- default:
1174
- return O(n);
1175
- }
1176
- }
1177
- function g(e) {
1178
- var o, a, c, u;
1179
- const t = ct(e.payload) ?? ((o = e.error) == null ? void 0 : o.executionResult), r = ((a = e.error) == null ? void 0 : a.validation) ?? (t == null ? void 0 : t.validation), n = t == null ? void 0 : t.coverage, s = t == null ? void 0 : t.diagnosticFeedback;
1180
- return {
1181
- status: e.status,
1182
- executionStatus: t == null ? void 0 : t.status,
1183
- executionResult: t,
1184
- validation: r,
1185
- coverage: n,
1186
- diagnosticFeedback: s,
1187
- isLoading: e.isLoading,
1188
- isEmpty: ft(e.queryKind, e.payload, e.status),
1189
- isPartial: dt(e.payload, t),
1190
- isFiltered: !!((c = e.activeInputs) != null && c.some(
1191
- (d) => d.kind === "filter" && d.isActive
1192
- ) || (u = e.selections) != null && u.length),
1193
- isStale: e.isStale,
1194
- isValidated: !!r,
1195
- error: e.error
1196
- };
1197
- }
1198
- function ct(e) {
1199
- const t = e;
1200
- return t == null ? void 0 : t.executionResult;
1201
- }
1202
- function lt(e) {
1203
- return (e == null ? void 0 : e.resultShape) === "matrix";
1204
- }
1205
- function dt(e, t) {
1206
- var n, s;
1207
- const r = !!(e != null && e.rowLimitExceeded);
1208
- return !!((t == null ? void 0 : t.status) === "partial" || ((n = t == null ? void 0 : t.diagnosticFeedback) == null ? void 0 : n.status) === "partial" || (t == null ? void 0 : t.status) !== "failed" && ((s = t == null ? void 0 : t.coverage) != null && s.missingObligations.length) || r);
1209
- }
1210
- function ft(e, t, r) {
1211
- var n, s, o;
1212
- if (r !== "success")
1213
- return !1;
1214
- switch (e) {
1215
- case "metric": {
1216
- const a = t;
1217
- return (a == null ? void 0 : a.primaryValue) == null && !y(a == null ? void 0 : a.records);
1218
- }
1219
- case "analysis": {
1220
- const a = t;
1221
- return a ? !a.answerSummary && !y(a.records) && !y(a.changes) && !y(a.drivers) && !y(a.largestNegativeChanges) && !y(a.largestPositiveChanges) && !y(a.largestNegativeDrivers) && !y(a.largestPositiveDrivers) && !Object.values(a.resultSets || {}).some(
1222
- (c) => y(c.records)
1223
- ) : !0;
1224
- }
1225
- case "records": {
1226
- const a = t;
1227
- return !y(a == null ? void 0 : a.records);
1228
- }
1229
- case "sql": {
1230
- const a = t;
1231
- return !y(a == null ? void 0 : a.records) && (a == null ? void 0 : a.output) === void 0;
1232
- }
1233
- case "inputOptions": {
1234
- const a = t;
1235
- return !((n = a == null ? void 0 : a.options) != null && n.length);
1236
- }
1237
- case "matrix": {
1238
- const a = t;
1239
- return !((s = a == null ? void 0 : a.window) != null && s.pages.some((c) => c.members.length > 0)) && !((o = a == null ? void 0 : a.window) != null && o.blocks.some((c) => c.cells.length > 0));
1240
- }
1241
- default:
1242
- return O(e);
1243
- }
1244
- }
1245
- function y(e) {
1246
- return Array.isArray(e) && e.length > 0;
1247
- }
1248
- function mt(e, t, r, n, s) {
1249
- const o = ot(), a = D(t), c = D(n), u = D(s), [d, i] = _({
1250
- status: "idle",
1251
- data: r,
1252
- error: null,
1253
- isStale: !1
1254
- });
1255
- return a.current = t, c.current = n, u.current = s, M(() => {
1256
- let l;
1257
- try {
1258
- l = a.current({
1259
- ...o,
1260
- activeInputs: c.current,
1261
- selections: u.current
1262
- });
1263
- } catch (p) {
1264
- i({
1265
- status: "error",
1266
- data: r,
1267
- error: V(p),
1268
- isStale: !1
1269
- });
1270
- return;
1271
- }
1272
- if (!l) {
1273
- i({ status: "idle", data: r, error: null, isStale: !1 });
1274
- return;
1275
- }
1276
- let m = !1;
1277
- return i((p) => ({
1278
- status: "loading",
1279
- data: p.data,
1280
- error: null,
1281
- isStale: p.isStale || p.status === "success"
1282
- })), l.then((p) => {
1283
- m || i({ status: "success", data: p, error: null, isStale: !1 });
1284
- }).catch((p) => {
1285
- m || i({
1286
- status: "error",
1287
- data: r,
1288
- error: V(p),
1289
- isStale: !1
1290
- });
1291
- }), () => {
1292
- m = !0;
1293
- };
1294
- }, [r, e, o]), d;
1295
- }
1296
- function pt(e) {
1297
- return Object.fromEntries(
1298
- e.filter((t) => t.defaultValue !== void 0).map((t) => [t.id, t.defaultValue])
1299
- );
1300
- }
1301
- function O(e) {
1302
- throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`);
1303
- }
1304
- function _t(e) {
1305
- const [t, r] = _(() => X(e, e.defaultTuples || [])), n = Object.prototype.hasOwnProperty.call(e, "tuples"), s = X(
1306
- e,
1307
- n ? e.tuples || [] : t
1308
- ), o = D(s);
1309
- o.current = s;
1310
- const a = S(
1311
- (d) => {
1312
- var i;
1313
- o.current = d, (i = e.onTuplesChange) == null || i.call(e, d), n || r(d);
1314
- },
1315
- [n, e]
1316
- ), c = S(
1317
- (d, i = { kind: "replace" }) => {
1318
- const l = ue(e, d), m = J(o.current, l, i, {
1319
- multipleSelection: e.multipleSelection ?? !0,
1320
- tupleKey: F
1321
- });
1322
- return (m.outcome !== "limitReached" || i.kind === "range") && a(m.tuples), m;
1323
- },
1324
- [a, e]
1325
- ), u = S(() => {
1326
- const d = o.current;
1327
- if (d.length === 0)
1328
- return;
1329
- const i = J(
1330
- d,
1331
- d[0],
1332
- { kind: "clear" },
1333
- {
1334
- multipleSelection: e.multipleSelection ?? !0,
1335
- tupleKey: F
1336
- }
1337
- );
1338
- a(i.tuples);
1339
- }, [a, e.multipleSelection]);
1340
- return h(
1341
- () => ({
1342
- id: e.id,
1343
- kind: "selection",
1344
- label: e.label,
1345
- fields: e.fields,
1346
- tuples: s,
1347
- isActive: s.length > 0,
1348
- select: c,
1349
- clear: u,
1350
- toAnalyticsSelection: () => s.length > 0 ? { id: e.id, tuples: s } : void 0
1351
- }),
1352
- [u, c, e.fields, e.id, e.label, s]
1353
- );
1354
- }
1355
- function X(e, t) {
1356
- if (e.fields.length === 0)
1357
- throw new Error(`Semaphor selection "${e.id}" requires at least one field.`);
1358
- if (t.length > W)
1359
- throw new Error(
1360
- `Semaphor selection "${e.id}" cannot contain more than ${W} tuples.`
1361
- );
1362
- if (e.multipleSelection === !1 && t.length > 1)
1363
- throw new Error(
1364
- `Semaphor selection "${e.id}" allows only one selected tuple.`
1365
- );
1366
- return t.map((r) => ue(e, r));
1367
- }
1368
- function ue(e, t) {
1369
- const r = ke.parse(t);
1370
- for (const n of r.conditions)
1371
- if (!e.fields.some(
1372
- (s) => Ie(s, n.field)
1373
- ))
1374
- throw new Error(
1375
- `Semaphor selection "${e.id}" received field "${n.field.name}" outside its declared fields.`
1376
- );
1377
- return r;
1378
- }
1379
- function $t({
1380
- token: e,
1381
- apiBaseUrl: t,
1382
- executor: r,
1383
- debug: n,
1384
- children: s
1385
- }) {
1386
- var m;
1387
- const o = st(), a = ((m = o == null ? void 0 : o.authToken) == null ? void 0 : m.accessToken) || e, c = (o == null ? void 0 : o.dataApiBaseUrl) || (o == null ? void 0 : o.apiBaseUrl) || t, u = (o == null ? void 0 : o.debug) ?? n, d = h(() => Xe(), []), i = r || d, l = h(
1388
- () => ({
1389
- token: a,
1390
- apiBaseUrl: c,
1391
- executor: i,
1392
- debug: u
1393
- }),
1394
- [c, u, i, a]
1395
- );
1396
- return /* @__PURE__ */ De(ae.Provider, { value: l, children: s });
1397
- }
1398
- export {
1399
- $t as SemaphorDataAppProvider,
1400
- Xe as createSemaphorQueryExecutor,
1401
- bt as defineSemaphorDataApp,
1402
- kt as defineSemaphorInput,
1403
- at as isSemaphorInputValueValidForOptions,
1404
- Kt as semaphor,
1405
- Tt as semaphorMetricAggregate,
1406
- Nt as semaphorMetricMeasureBindingKey,
1407
- Ot as useClearInvalidSemaphorInputValue,
1408
- Et as useSemaphorInput,
1409
- Dt as useSemaphorInputs,
1410
- xt as useSemaphorQuery,
1411
- _t as useSemaphorSelection
1412
- };