react-semaphor 0.1.428 → 0.1.429
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.
- package/dist/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +72 -71
- package/dist/brand-studio/index.cjs +1 -1
- package/dist/brand-studio/index.js +5 -4
- package/dist/briefings/index.cjs +1 -1
- package/dist/briefings/index.js +1031 -622
- package/dist/chunks/analyze-result-contract-BswhsmWT.js +1 -0
- package/dist/chunks/{analyze-result-contract-DnfF8kBb.js → analyze-result-contract-CfOBEwaC.js} +681 -759
- package/dist/chunks/{code-editor-CojfM3qp.js → code-editor-C65eEYyU.js} +2980 -2960
- package/dist/chunks/code-editor-DOh3aYEh.js +138 -0
- package/dist/chunks/{comparison-document-migration-b6c3xiWh.js → comparison-document-migration-DbU_BTxR.js} +1 -1
- package/dist/chunks/{comparison-document-migration-BJH1idOd.js → comparison-document-migration-Dj6xZMCb.js} +2 -2
- package/dist/chunks/csv-utils-Co0WxHke.js +4 -0
- package/dist/chunks/csv-utils-suxSkJGj.js +376 -0
- package/dist/chunks/dashboard-CQfAvRYI.js +1401 -0
- package/dist/chunks/{dashboard-509sbC4_.js → dashboard-agBXhvKo.js} +47563 -44929
- package/dist/chunks/{dashboard-briefing-launcher-B-ZTWJwo.js → dashboard-briefing-launcher-CkH_pthg.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-DIdYHNTq.js → dashboard-briefing-launcher-gBNNKqoH.js} +100 -99
- package/dist/chunks/{dashboard-controls-CWprw-Pb.js → dashboard-controls-CAZnIGfT.js} +2 -2
- package/dist/chunks/{dashboard-controls-CbRzWo1N.js → dashboard-controls-CoIxUTvH.js} +114 -113
- package/dist/chunks/{dashboard-json-jO4GQfZk.js → dashboard-json-BMcPjL8-.js} +18 -17
- package/dist/chunks/dashboard-json-D4hFrMkX.js +1 -0
- package/dist/chunks/{edit-dashboard-visual-KgQTjqWp.js → edit-dashboard-visual-Bc8qNfSr.js} +8721 -8481
- package/dist/chunks/edit-dashboard-visual-onhUUXlw.js +182 -0
- package/dist/chunks/{metric-comparison-CWweq9RG.js → metric-comparison-CPoDx56y.js} +1 -1
- package/dist/chunks/{metric-comparison-BKgkMy9r.js → metric-comparison-DVy3fll_.js} +1 -1
- package/dist/chunks/numeric-presentation-CGTcqocU.js +517 -0
- package/dist/chunks/numeric-presentation-Dlb-Dk4c.js +1 -0
- package/dist/chunks/report-preferences-dialog-CPptr_V9.js +690 -0
- package/dist/chunks/report-preferences-dialog-DV_5aHrS.js +1 -0
- package/dist/chunks/source-identity-5OPV4gvg.js +92 -0
- package/dist/chunks/source-identity-Cbo2LOHQ.js +1 -0
- package/dist/chunks/{update-policy-CY2k-pJP.js → update-policy-De2NswtM.js} +1 -1
- package/dist/chunks/{update-policy-BgONreNd.js → update-policy-DnF_74zC.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-BiMYdjZP.js → use-create-flow-overlay-state-Bs6gqgjo.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-CGsLzp9A.js → use-create-flow-overlay-state-CgQbCrni.js} +97 -96
- package/dist/chunks/validators-B2vUAqTf.js +1 -0
- package/dist/chunks/{validators-Cz-XuORM.js → validators-Bce_J7Vd.js} +19 -13
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.cjs +3 -3
- package/dist/dashboard-authoring/index.js +20 -19
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +50 -50
- package/dist/data-app-codegen/index.cjs +1 -1
- package/dist/data-app-codegen/index.js +2 -2
- package/dist/data-app-codegen-node/index.cjs +1 -1
- package/dist/data-app-codegen-node/index.js +3 -3
- package/dist/data-app-sdk/index.cjs +2 -2
- package/dist/data-app-sdk/index.js +27 -26
- package/dist/data-app-sdk-adapters/index.cjs +1 -1
- package/dist/data-app-sdk-adapters/index.js +25 -24
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +57 -55
- package/dist/format-utils/index.cjs +2 -5
- package/dist/format-utils/index.js +136 -161
- package/dist/index.cjs +1 -1
- package/dist/index.js +158 -155
- package/dist/report-runtime-context/index.cjs +1 -0
- package/dist/report-runtime-context/index.js +394 -0
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +7 -6
- package/dist/types/analytics-protocol.d.ts +0 -4
- package/dist/types/briefings.d.ts +216 -19
- package/dist/types/dashboard-assistant.d.ts +0 -2
- package/dist/types/dashboard-authoring.d.ts +34 -9
- package/dist/types/dashboard.d.ts +93 -9
- package/dist/types/data-app-builder.d.ts +0 -1
- package/dist/types/data-app-codegen-node.d.ts +6 -28
- package/dist/types/data-app-codegen.d.ts +6 -28
- package/dist/types/data-app-sdk-adapters.d.ts +6 -28
- package/dist/types/data-app-sdk-validation.d.ts +6 -29
- package/dist/types/data-app-sdk.d.ts +6 -31
- package/dist/types/format-utils.d.ts +128 -4
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.js +10 -13
- package/dist/types/main.d.ts +249 -89
- package/dist/types/report-runtime-context.d.ts +99 -0
- package/dist/types/shared.d.ts +34 -9
- package/dist/types/surfboard.d.ts +119 -16
- package/dist/types/types.d.ts +156 -73
- package/dist/types/value-format-preferences.d.ts +126 -0
- package/dist/value-format-preferences/index.cjs +1 -0
- package/dist/value-format-preferences/index.js +635 -0
- package/package.json +11 -1
- package/dist/chunks/analyze-result-contract-ege_u6Nl.js +0 -1
- package/dist/chunks/calendar-preferences-dialog-BF9bNAF_.js +0 -457
- package/dist/chunks/calendar-preferences-dialog-_L9eBQfj.js +0 -1
- package/dist/chunks/code-editor-BoowcKU0.js +0 -138
- package/dist/chunks/dashboard-CMDXBLnG.js +0 -1402
- package/dist/chunks/dashboard-json-BEZrxx_k.js +0 -1
- package/dist/chunks/date-formatter-BTTYdAik.js +0 -1
- package/dist/chunks/date-formatter-D-89jTjG.js +0 -514
- package/dist/chunks/edit-dashboard-visual-D3uhqgm3.js +0 -182
- package/dist/chunks/validators-B4VMLX3_.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../chunks/operators-DrTQsJXv.js"),u=require("../chunks/analyze-result-contract-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../chunks/operators-DrTQsJXv.js"),u=require("../chunks/source-identity-Cbo2LOHQ.js");require("../chunks/analyze-result-contract-BswhsmWT.js");function p(i){var n,e,a;const t=b(i);return{version:1,kind:"metric",id:i.id,label:i.label,source:s(i),measures:t,primaryMeasure:M(i,t),dateField:i.dateField?o(i.dateField,"date"):void 0,timeGrain:i.timeGrain,dimensions:(n=i.dimensions)==null?void 0:n.map(r=>o(r,"dimension")),comparison:G(i.comparison),orderBy:i.orderBy?{field:o(i.orderBy.field),direction:i.orderBy.direction}:void 0,inputs:l(i.inputs),...(e=i.filters)!=null&&e.length?{filters:i.filters}:{},...i.relationshipHint?{relationshipHint:i.relationshipHint}:{},limit:i.limit,...(a=i.derivedFields)!=null&&a.length?{derivedFields:i.derivedFields}:{}}}function v(i){return{...p(i),...i.timeWindow?{timeWindow:i.timeWindow}:{},...i.analysis?{analysis:i.analysis}:{}}}function F(i){return{...i.chartTitle?{chartTitle:i.chartTitle}:{},...i.chartType?{chartType:i.chartType}:{},...i.driverMode?{driverMode:i.driverMode}:{},...i.includePopulation!==void 0?{includePopulation:i.includePopulation}:{},...i.calendarContext?{calendarContext:i.calendarContext}:{}}}function M(i,t){if(!i.primaryMeasure)return t[0]||{name:"",role:"measure"};const n=o(i.primaryMeasure,"measure"),e=A(n,t),a=e.length===1?e[0]:void 0;return a?I(n,a):n}function b(i){const t=[];for(const n of i.measures.map(e=>o(e,"measure"))){if(!n.name)continue;const e=t.findIndex(a=>R(a,n));if(e===-1){t.push(n);continue}t[e]=I(t[e],n)}return t}function R(i,t){return u.semaphorFieldRefsMatch(i,t)&&d(i)===d(t)}function H(i,t){return d(t)===d(i)}function w(i,t){return t.name!==i.name||i.source&&!u.semaphorFieldRefsMatch(t,i)?!1:H(i,t)}function A(i,t){const n=t.filter(e=>w(i,e));return i.aggregate!==void 0,n}function d(i){return u.semaphorMetricAggregate(i)}function I(i,t){if(i.aggregate&&t.aggregate&&i.aggregate!==t.aggregate)throw new Error(`Measure "${i.name}" was requested with conflicting aggregate semantics: ${i.aggregate} and ${t.aggregate}.`);return{...u.preferSemaphorFieldRefMetadata(i,t),aggregate:i.aggregate||t.aggregate}}function k(i){var n,e;if("sort"in i)throw new Error("semaphor.records supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet.");if(!V(i))throw new Error("semaphor.records needs at least one field.");const t=B(i.fields);return{version:1,kind:"records",id:i.id,label:i.label,source:s(i),fields:t,dateField:i.dateField?o(i.dateField,"date"):void 0,timeGrain:i.timeGrain,...i.timeWindow?{timeWindow:i.timeWindow}:{},...(n=i.filters)!=null&&n.length?{filters:i.filters}:{},orderBy:i.orderBy?{field:o(i.orderBy.field),direction:i.orderBy.direction}:void 0,inputs:l(i.inputs),...i.relationshipHint?{relationshipHint:i.relationshipHint}:{},limit:i.limit,...i.pagination?{pagination:i.pagination}:{},...i.totals?{totals:{mode:"server",measures:i.totals.measures.map(a=>o(a,"measure"))}}:{},...(e=i.derivedFields)!=null&&e.length?{derivedFields:i.derivedFields}:{}}}function B(i){return i.map(t=>{const n=o(t);if(!n.role)throw new Error(`semaphor.records field "${n.name}" needs an explicit role.`);return n})}function x(i){var t,n,e;return{version:1,kind:"inputOptions",id:i.id,label:i.label,inputId:i.inputId,source:s(i),labelField:o(i.labelField,"dimension"),valueField:o(i.valueField,"dimension"),...i.searchField?{searchField:o(i.searchField,"dimension")}:{},...(t=i.disambiguationFields)!=null&&t.length?{disambiguationFields:i.disambiguationFields.map(a=>o(a,"dimension"))}:{},...i.population?{population:i.population}:{},...i.dependencies?{dependencies:i.dependencies}:{},search:i.search,limit:i.limit,...(n=i.inputs)!=null&&n.length?{inputs:i.inputs.map(a=>f(a))}:{},...(e=i.derivedFields)!=null&&e.length?{derivedFields:i.derivedFields}:{}}}function O(i){var t;return{version:1,kind:"sql",id:i.id,label:i.label,source:i.source,sql:i.sql,...i.defaultParameters?{defaultParameters:i.defaultParameters}:{},...i.pythonCode?{pythonCode:i.pythonCode}:{},...(t=i.fields)!=null&&t.length?{fields:i.fields.map(n=>o(n))}:{},inputs:l(i.inputs),limit:i.limit,...i.pagination?{pagination:i.pagination}:{},rationale:i.rationale}}function P(i){var t,n;return{version:1,kind:"matrix",id:i.id,label:i.label,source:s(i),rows:i.rows.map(e=>g(e,"dimension")),...i.columns?{columns:i.columns.map(e=>g(e,"dimension"))}:{},values:i.values.map(z),...(t=i.filters)!=null&&t.length?{filters:i.filters}:{},inputs:l(i.inputs),...i.relationshipHint?{relationshipHint:i.relationshipHint}:{},...i.totals?{totals:i.totals}:{},...(n=i.sort)!=null&&n.length?{sort:i.sort}:{},...i.expansion?{expansion:i.expansion}:{},...i.layout?{layout:i.layout}:{},...i.displayLimits?{displayLimits:i.displayLimits}:{}}}function g(i,t){return C(i)?{...i,field:o(i.field,t)}:{field:o(i,t)}}function z(i){return T(i)?{...i,field:o(i.field,"measure")}:{field:o(i,"measure"),aggregate:i.aggregate}}function C(i){return"field"in i}function T(i){return"field"in i}function f(i){if("toAnalyticsInput"in i){const r=i.toAnalyticsInput();return{inputId:r.inputId,kind:r.kind,...r.controlRole?{controlRole:r.controlRole}:{},...r.operator?{operator:r.operator}:{},...r.field?{field:r.field}:{},...r.relationshipHint?{relationshipHint:r.relationshipHint}:{}}}if("id"in i){const r=h(i);return{inputId:r.inputId,kind:r.kind,...r.controlRole?{controlRole:r.controlRole}:{},...r.operator?{operator:r.operator}:{},...r.field?{field:r.field}:{},...r.relationshipHint?{relationshipHint:r.relationshipHint}:{}}}const t="kind"in i?i.kind:void 0,n="operator"in i?S(i.operator,i.inputId):void 0,e="controlRole"in i?i.controlRole:"role"in i?i.role:void 0,a=q(e)?e:void 0;return{inputId:i.inputId,...t?{kind:t}:{},...a?{controlRole:a}:{},...n?{operator:n}:{},...i.field?{field:i.field}:{},...i.relationshipHint?{relationshipHint:i.relationshipHint}:{}}}function q(i){return i==="grain"||i==="measure"||i==="dimension"||i==="aggregation"||i==="sqlParam"}function W(i){const t=l(i);return t.length>0?t:void 0}function y(i){return(i||[]).map(L)}function $(i){return y(i).filter(t=>t.isActive)}function h(i){if(i.kind==="filter"){const t=S(i.operator,i.id);return{inputId:i.id,kind:i.kind,label:i.label,field:o(i.field,"dimension"),operator:t||"in",...i.relationshipHint?{relationshipHint:i.relationshipHint}:{}}}return{inputId:i.id,kind:i.kind,label:i.label,controlRole:i.role}}function E(i=[]){return i.map(t=>typeof t=="object"?t:{label:String(t),value:t})}function m(i){return i==null?!1:Array.isArray(i)?i.length>0:typeof i=="string"?i.trim().length>0:!0}function L(i){if("toAnalyticsInput"in i)return i.toAnalyticsInput();if("kind"in i&&"isActive"in i)return i;if("id"in i){const t=h(i),n=Object.prototype.hasOwnProperty.call(i,"value")?i.value:i.defaultValue;return{inputId:t.inputId,kind:t.kind,label:t.label,...t.field?{field:t.field}:{},...t.operator?{operator:t.operator}:{},...t.controlRole?{controlRole:t.controlRole}:{},...t.relationshipHint?{relationshipHint:t.relationshipHint}:{},value:n,isActive:m(n)}}return{...i,kind:"filter",isActive:m(i.value),value:i.value}}function s(i){return i.source}function V(i){var t;return!!((t=i.fields)!=null&&t.length)}function o(i,t){return{...i,role:i.role||t}}function l(i){return(i||[]).map(f)}function G(i){if(i)return i}function S(i,t){if(i===void 0)return;const n=c.normalizeSemaphorInputOperator(i);if(!n)throw new Error(`useSemaphorInput "${t}" uses unsupported filter operator "${i}".`);return n}exports.hasSemaphorInputValue=m;exports.normalizeSemaphorInputOptions=E;exports.toSemaphorActiveInputSnapshots=$;exports.toSemaphorAnalysisIntent=v;exports.toSemaphorAnalysisQueryOptions=F;exports.toSemaphorInputBinding=f;exports.toSemaphorInputBindings=W;exports.toSemaphorInputOptionsIntent=x;exports.toSemaphorInputSnapshots=y;exports.toSemaphorInputSpec=h;exports.toSemaphorMatrixIntent=P;exports.toSemaphorMetricIntent=p;exports.toSemaphorRecordsIntent=k;exports.toSemaphorSqlIntent=O;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { n as I } from "../chunks/operators-C8TxpM4C.js";
|
|
2
|
-
import { s as m, p as F,
|
|
3
|
-
|
|
2
|
+
import { s as m, p as F, a as c } from "../chunks/source-identity-5OPV4gvg.js";
|
|
3
|
+
import "../chunks/analyze-result-contract-CfOBEwaC.js";
|
|
4
|
+
function p(i) {
|
|
4
5
|
var n, r, a;
|
|
5
6
|
const t = M(i);
|
|
6
7
|
return {
|
|
@@ -10,7 +11,7 @@ function S(i) {
|
|
|
10
11
|
label: i.label,
|
|
11
12
|
source: u(i),
|
|
12
13
|
measures: t,
|
|
13
|
-
primaryMeasure:
|
|
14
|
+
primaryMeasure: S(i, t),
|
|
14
15
|
dateField: i.dateField ? o(i.dateField, "date") : void 0,
|
|
15
16
|
timeGrain: i.timeGrain,
|
|
16
17
|
dimensions: (n = i.dimensions) == null ? void 0 : n.map((e) => o(e, "dimension")),
|
|
@@ -26,14 +27,14 @@ function S(i) {
|
|
|
26
27
|
...(a = i.derivedFields) != null && a.length ? { derivedFields: i.derivedFields } : {}
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
|
-
function
|
|
30
|
+
function L(i) {
|
|
30
31
|
return {
|
|
31
|
-
...
|
|
32
|
+
...p(i),
|
|
32
33
|
...i.timeWindow ? { timeWindow: i.timeWindow } : {},
|
|
33
34
|
...i.analysis ? { analysis: i.analysis } : {}
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
|
-
function
|
|
37
|
+
function G(i) {
|
|
37
38
|
return {
|
|
38
39
|
...i.chartTitle ? { chartTitle: i.chartTitle } : {},
|
|
39
40
|
...i.chartType ? { chartType: i.chartType } : {},
|
|
@@ -42,7 +43,7 @@ function L(i) {
|
|
|
42
43
|
...i.calendarContext ? { calendarContext: i.calendarContext } : {}
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
|
-
function
|
|
46
|
+
function S(i, t) {
|
|
46
47
|
if (!i.primaryMeasure)
|
|
47
48
|
return t[0] || { name: "", role: "measure" };
|
|
48
49
|
const n = o(i.primaryMeasure, "measure"), r = w(n, t), a = r.length === 1 ? r[0] : void 0;
|
|
@@ -97,7 +98,7 @@ function h(i, t) {
|
|
|
97
98
|
aggregate: i.aggregate || t.aggregate
|
|
98
99
|
};
|
|
99
100
|
}
|
|
100
|
-
function
|
|
101
|
+
function V(i) {
|
|
101
102
|
var n, r;
|
|
102
103
|
if ("sort" in i)
|
|
103
104
|
throw new Error(
|
|
@@ -146,7 +147,7 @@ function k(i) {
|
|
|
146
147
|
return n;
|
|
147
148
|
});
|
|
148
149
|
}
|
|
149
|
-
function
|
|
150
|
+
function j(i) {
|
|
150
151
|
var t, n, r;
|
|
151
152
|
return {
|
|
152
153
|
version: 1,
|
|
@@ -171,7 +172,7 @@ function V(i) {
|
|
|
171
172
|
...(r = i.derivedFields) != null && r.length ? { derivedFields: i.derivedFields } : {}
|
|
172
173
|
};
|
|
173
174
|
}
|
|
174
|
-
function
|
|
175
|
+
function q(i) {
|
|
175
176
|
var t;
|
|
176
177
|
return {
|
|
177
178
|
version: 1,
|
|
@@ -189,7 +190,7 @@ function j(i) {
|
|
|
189
190
|
rationale: i.rationale
|
|
190
191
|
};
|
|
191
192
|
}
|
|
192
|
-
function
|
|
193
|
+
function Q(i) {
|
|
193
194
|
var t, n;
|
|
194
195
|
return {
|
|
195
196
|
version: 1,
|
|
@@ -273,14 +274,14 @@ function g(i) {
|
|
|
273
274
|
function C(i) {
|
|
274
275
|
return i === "grain" || i === "measure" || i === "dimension" || i === "aggregation" || i === "sqlParam";
|
|
275
276
|
}
|
|
276
|
-
function
|
|
277
|
+
function D(i) {
|
|
277
278
|
const t = l(i);
|
|
278
279
|
return t.length > 0 ? t : void 0;
|
|
279
280
|
}
|
|
280
281
|
function O(i) {
|
|
281
282
|
return (i || []).map(P);
|
|
282
283
|
}
|
|
283
|
-
function
|
|
284
|
+
function J(i) {
|
|
284
285
|
return O(i).filter((t) => t.isActive);
|
|
285
286
|
}
|
|
286
287
|
function y(i) {
|
|
@@ -302,7 +303,7 @@ function y(i) {
|
|
|
302
303
|
controlRole: i.role
|
|
303
304
|
};
|
|
304
305
|
}
|
|
305
|
-
function
|
|
306
|
+
function K(i = []) {
|
|
306
307
|
return i.map(
|
|
307
308
|
(t) => typeof t == "object" ? t : {
|
|
308
309
|
label: String(t),
|
|
@@ -373,17 +374,17 @@ function v(i, t) {
|
|
|
373
374
|
}
|
|
374
375
|
export {
|
|
375
376
|
f as hasSemaphorInputValue,
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
377
|
+
K as normalizeSemaphorInputOptions,
|
|
378
|
+
J as toSemaphorActiveInputSnapshots,
|
|
379
|
+
L as toSemaphorAnalysisIntent,
|
|
380
|
+
G as toSemaphorAnalysisQueryOptions,
|
|
380
381
|
g as toSemaphorInputBinding,
|
|
381
|
-
|
|
382
|
-
|
|
382
|
+
D as toSemaphorInputBindings,
|
|
383
|
+
j as toSemaphorInputOptionsIntent,
|
|
383
384
|
O as toSemaphorInputSnapshots,
|
|
384
385
|
y as toSemaphorInputSpec,
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
386
|
+
Q as toSemaphorMatrixIntent,
|
|
387
|
+
p as toSemaphorMetricIntent,
|
|
388
|
+
V as toSemaphorRecordsIntent,
|
|
389
|
+
q as toSemaphorSqlIntent
|
|
389
390
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("../chunks/validators-B4VMLX3_.js"),v=require("../chunks/analyze-result-contract-ege_u6Nl.js"),y=require("../data-app-sdk-adapters/index.cjs"),R=require("../chunks/catalog-field-grounding-Bnx-3tE0.js");function W({intent:e,field:r,catalogField:o,relativePath:t}){const i=U({intent:e,field:r,relativePath:t});if(!i||i.allowedRelatedRoles.length===0)return!1;const a=f(r,i.selectedField),s=w(o),n=p(a);return B(s,i.allowedRelatedRoles)?n===s:!1}function J(e){return e.kind==="records"?X(e):e.kind==="metric"?Y(e):Z(e)}function w(e){const r=R.normalizeAnalyticsCatalogName(e.role);if(r==="measure")return"measure";if(r==="id")return"id";const o=R.normalizeAnalyticsCatalogDataType(e.dataType);if(r==="date"||o==="date"||o==="datetime")return"date";if(r==="dimension")return"dimension"}function B(e,r){return!!(e&&r.includes(e))}function f(e,r){const o=p(e);if(o)return e.role===o?e:{...e,role:o};const t=r?p(r):void 0;return t?{...e,role:t}:e}function u(e,r){return e.find(o=>z(o,r))}function S(e){return[...e.rows.map(r=>r.field),...(e.columns||[]).map(r=>r.field)]}function U({intent:e,field:r,relativePath:o}){if(e.kind==="records")return L(e,r,o);if(e.kind==="metric")return V(e,r,o);if(e.kind==="matrix")return G(e,r,o)}function L(e,r,o){if(o.startsWith("spec.fields."))return{allowedRelatedRoles:["dimension","date","id"]};if(o==="spec.dateField"&&!e.timeWindow)return{allowedRelatedRoles:["date"]};if(o==="spec.orderBy.field"){const t=u(T(e),r);return{selectedField:t,allowedRelatedRoles:t?x(t):[]}}}function V(e,r,o){if(o.startsWith("spec.dimensions."))return{allowedRelatedRoles:["dimension"]};if(o==="spec.orderBy.field"){const t=u(e.dimensions||[],r);return{selectedField:t,allowedRelatedRoles:t?["dimension"]:[]}}}function G(e,r,o){if(oe(o))return{allowedRelatedRoles:["dimension","date"]};if(te(o)){const t=u(S(e),r);return{selectedField:t,allowedRelatedRoles:q(t)}}}function X(e){var t,i;const r=T(e),o=(t=e.orderBy)!=null&&t.field?u(r,e.orderBy.field):void 0;return _([...r.map(a=>l(a,x(a))),...(i=e.orderBy)!=null&&i.field?[l(f(e.orderBy.field,o),o?x(o):[],{unsupportedRelatedRoleMessage:"Joined records projections support related sort fields only when the same related field is included in spec.fields.",recommendedNextStep:"Add the related sort field to spec.fields, or keep orderBy fields on the base source."})]:[]])}function Y(e){var o,t;const r=(o=e.orderBy)!=null&&o.field?u(e.dimensions||[],e.orderBy.field):void 0;return _([...e.measures.map(i=>l(i,[])),...e.primaryMeasure?[l(e.primaryMeasure,[])]:[],...(e.dimensions||[]).map(i=>l(i,["dimension"])),...e.dateField?[l({...e.dateField,role:"date"},[])]:[],...(t=e.orderBy)!=null&&t.field?[l(f(e.orderBy.field,r),r?["dimension"]:[],{unsupportedRelatedRoleMessage:"Joined metric projections support related orderBy fields only when the same related field is declared in spec.dimensions.",recommendedNextStep:"Add the related field as a metric dimension when it should participate in the grouped result, or keep orderBy fields on the base source."})]:[]])}function Z(e){const r=[...e.rows,...e.columns||[]];return _([...r.map(o=>l(o.field,q(o.field))),...r.flatMap(o=>{var a;if(((a=o.sortBy)==null?void 0:a.by.kind)!=="field")return[];const t=o.sortBy.by.field,i=u(S(e),t);return[l(f(t,i),q(i),{unsupportedRelatedRoleMessage:"Joined matrix projections support related axis sort fields only when the same related field is used as a row/column axis.",recommendedNextStep:"Use a related field as a row or column axis, or keep axis sort fields on the base source."})]}),...e.values.map(o=>l(o.field,[],{unsupportedRelatedRoleMessage:"Joined matrix projections support related row/column dimensions or dates only. Related value fields are not supported in this phase.",recommendedNextStep:"Keep matrix values on the base source, or use governed SQL for unsupported aggregate-safe joined values."})),...(e.sort||[]).flatMap(o=>{if(o.by.kind!=="field")return[];const t=o.by.field,i=u(S(e),t);return[l(f(t,i),q(i),{unsupportedRelatedRoleMessage:"Joined matrix projections support related top-level sort fields only when the same related field is used as a row/column axis.",recommendedNextStep:"Use a related field as a row or column axis, or keep matrix sort fields on the base source."})]})])}function x(e){const r=e?p(e):void 0;return r==="dimension"?["dimension"]:r==="date"?["date"]:r==="id"?["id"]:["dimension","date","id"]}function q(e){const r=e?p(e):void 0;return r==="date"?["date"]:r==="dimension"?["dimension"]:[]}function l(e,r,o={}){return{field:f(e),allowedRelatedRoles:r,...o}}function _(e){const r=[];return e.forEach(o=>{r.some(t=>ee(t,o))||r.push(o)}),r}function T(e){const r=[...e.fields];return e.dateField&&!r.some(o=>D(o,e.dateField))&&r.push({...e.dateField,role:"date"}),r}function ee(e,r){return z(e.field,r.field)&&e.allowedRelatedRoles.join("|")===r.allowedRelatedRoles.join("|")&&(e.unsupportedRelatedRoleMessage||"")===(r.unsupportedRelatedRoleMessage||"")&&(e.recommendedNextStep||"")===(r.recommendedNextStep||"")}function D(e,r){return v.semaphorFieldRefsMatch(e,r)}function z(e,r){return D(e,r)&&re(p(e),p(r))}function re(e,r){return!!(e&&(!r||e===r))}function p(e){return w(e)}function oe(e){const r=e.split(".");return r.length===4&&r[0]==="spec"&&(r[1]==="rows"||r[1]==="columns")&&b(r[2])&&r[3]==="field"}function te(e){const r=e.split(".");return r.length===6&&r[0]==="spec"&&(r[1]==="rows"||r[1]==="columns")&&b(r[2])&&r[3]==="sortBy"&&r[4]==="by"&&r[5]==="field"||r.length===5&&r[0]==="spec"&&r[1]==="sort"&&b(r[2])&&r[3]==="by"&&r[4]==="field"}function b(e){return e===void 0||e.trim()===""?!1:Number.isInteger(Number(e))&&Number(e)>=0}function ie({intent:e,field:r,relativePath:o,baseCatalog:t,fieldCatalogs:i}){const a=g(r,e.source),s=v.semaphorSourcesReferToSameDataset(a,e.source);if(!s&&!se(e.source,a))return{ok:!1,code:"invalid_source_ref",message:`Field "${r.name}" references a related Semaphor source outside the query's semantic domain.`,pathSuffix:".source",source:a};const n=s?t:k(i,a);if(!n)return{ok:!1,code:"invalid_source_ref",message:`Field "${r.name}" references a Semaphor source that is not present in the visible field catalog.`,pathSuffix:".source",source:a};const d=I(n,r,e.source);return d?!s&&!ae({intent:e,field:r,catalogField:d,relativePath:o})?{ok:!1,code:"unsupported_joined_projection",message:`Field "${r.name}" references a related Semaphor source, but this query kind does not support joined projections for that field yet.`,pathSuffix:".source",source:a}:{ok:!0,source:a,catalogField:d,usesBaseSource:s}:{ok:!1,code:"missing_field",message:`Field "${r.name}" is not visible on the selected Semaphor source.`,source:a}}function ae({intent:e,field:r,catalogField:o,relativePath:t}){return W({intent:e,field:r,catalogField:o,relativePath:t})}function se(e,r){return e.kind==="semantic"&&r.kind==="semantic"&&e.domainId===r.domainId}function k(e,r){return e.find(o=>$(o,r))}function I(e,r,o){const t=g(r,o);if($(e,t))return e.fields.find(i=>ne(i,r)&&$(e,g(i,e.source)))}function C(e){return R.normalizeAnalyticsCatalogName(e)}function g(e,r){return e.source||r}function $(e,r){return[e.source,...e.sourceAliases||[]].some(o=>v.semaphorSourcesReferToSameDataset(o,r))}function ne(e,r){return!!(e.name&&r.name&&e.name===r.name)}function N(e,r={}){const o=r.pathPrefix||"analysisOptions";if(e===void 0)return{ok:!0};if(!e||typeof e!="object"||Array.isArray(e))return c(o,"Data App analysis options must be an object.");const t=e,i={};if(t.chartTitle!==void 0){if(typeof t.chartTitle!="string")return c(`${o}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');i.chartTitle=t.chartTitle}if(t.chartType!==void 0){if(typeof t.chartType!="string")return c(`${o}.chartType`,'Data App analysis option "chartType" must be a string.');i.chartType=t.chartType}if(t.driverMode!==void 0){if(!ce(t.driverMode))return c(`${o}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');i.driverMode=t.driverMode}if(t.includePopulation!==void 0){if(typeof t.includePopulation!="boolean")return c(`${o}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');i.includePopulation=t.includePopulation}if(t.calendarContext!==void 0){const a=ue(t.calendarContext,{pathPrefix:`${o}.calendarContext`,validateTimezone:r.validateTimezone});if(!a.ok)return a;i.calendarContext=a.calendarContext}return{ok:!0,analysisOptions:i}}function de(e){const r=e.queries.map((i,a)=>le(i,a,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),o=r.flatMap(i=>i.diagnostics),t=r.map(i=>i.executionResult);return{ok:o.every(i=>i.severity!=="error"),diagnostics:o,queries:r,intents:r.flatMap(i=>i.intent?[i.intent]:[]),executionResults:t}}function le(e,r,o){const t=`queries.${r}`;try{const i=fe(e),a=be(e,i),s=M.validateSemaphorAnalyticsIntent(i),n=[...Ie({querySpec:e,queryId:a,intent:i,pathPrefix:t}),...s.errors.map(h=>P(h,{queryHook:e.queryHook,queryId:a,pathPrefix:t,severity:"error",intent:i})),...s.warnings.map(h=>P(h,{queryHook:e.queryHook,queryId:a,pathPrefix:t,severity:"warning",intent:i})),...me({querySpec:e,queryId:a,intent:i,pathPrefix:t,fieldCatalogs:o.fieldCatalogs,requireFieldCatalog:o.requireFieldCatalog}),...Se({querySpec:e,queryId:a,intent:i,pathPrefix:t,validateTimezone:o.validateTimezone})],d=xe(s,n);return{queryHook:e.queryHook,queryId:a,intent:i,diagnostics:n,executionResult:j({intent:i,validation:d,diagnostics:n})}}catch(i){const a={severity:"error",code:"invalid_query_spec",message:i instanceof Error?i.message:String(i),path:t,queryHook:e.queryHook,queryId:E(e.spec)},s=Q([a]);return{queryHook:e.queryHook,queryId:a.queryId,diagnostics:[a],executionResult:j({validation:s,diagnostics:[a]})}}}function c(e,r){return{ok:!1,issues:[{code:"invalid_analysis_option",message:r,path:e}]}}function O(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function ce(e){return e==="absolute_delta"||e==="largest_negative"||e==="largest_positive"||e==="positive_and_negative"||e==="all"}function ue(e,r){var d;if(!e||typeof e!="object"||Array.isArray(e))return c(r.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const o=e,t=o.tz,i=o.weekStart,a=o.anchor,s=a&&typeof a=="object"&&!Array.isArray(a)?a.iso:void 0,n=typeof t=="string"?((d=r.validateTimezone)==null?void 0:d.call(r,t))??t:null;return n?typeof i!="number"||!Number.isInteger(i)||i<0||i>6?c(`${r.pathPrefix}.weekStart`,'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'):a!=="now"&&!(typeof s=="string"&&M.parseSemaphorIsoInstant(s))?c(`${r.pathPrefix}.anchor`,'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'):{ok:!0,calendarContext:{tz:n,weekStart:i,anchor:a}}:c(`${r.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.')}function fe(e){return pe(e.spec)}function pe(e){if(!O(e))throw new Error("useSemaphorQuery spec must be an object.");if(e.queryKind==="metric")return y.toSemaphorMetricIntent(e);if(e.queryKind==="analysis")return y.toSemaphorAnalysisIntent(e);if(e.queryKind==="records")return y.toSemaphorRecordsIntent(e);if(e.queryKind==="sql")return y.toSemaphorSqlIntent(e);if(e.queryKind==="matrix")return y.toSemaphorMatrixIntent(e);if(e.queryKind==="inputOptions")return y.toSemaphorInputOptionsIntent(e);throw new Error("useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, sql, or matrix.")}function me(e){if(e.intent.kind==="sql")return[];if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const r=k(e.fieldCatalogs,e.intent.source);if(!r)return[{severity:"error",code:"invalid_source_ref",message:`Source ref for ${e.querySpec.queryHook} does not match a visible Semaphor source.`,path:`${e.pathPrefix}.spec.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}];const o=he({...e,catalog:r}),t={...r,fields:[...r.fields,...Fe(e.intent,r,e.intent.source)]};return[...o,...ye({...e,fieldCatalogs:e.fieldCatalogs}),...ge({...e,catalog:t,fieldCatalogs:e.fieldCatalogs}),...ve({...e,catalog:t,fieldCatalogs:e.fieldCatalogs})]}function ye(e){var o;if(e.intent.kind!=="inputOptions"||((o=e.intent.population)==null?void 0:o.kind)!=="related_population")return[];const r=e.intent.population.baseSource;return k(e.fieldCatalogs,r)?[]:[{severity:"error",code:"invalid_source_ref",message:"Input options related population baseSource does not match a visible Semaphor source.",path:`${e.pathPrefix}.spec.population.baseSource`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:r}]}function he(e){const r=K(e.intent);if(r.length===0)return[];const o=[],t=new Set;return r.forEach((i,a)=>{const s=`${e.pathPrefix}.spec.derivedFields.${a}`,n=C(i.name);n&&(t.has(n)&&o.push({severity:"error",code:"duplicate_derived_field",message:`Derived field "${i.name}" is declared more than once.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}),t.add(n),e.catalog.fields.some(d=>C(d.name)===n)&&o.push({severity:"error",code:"derived_field_name_collision",message:`Derived field "${i.name}" conflicts with a field already visible on the selected Semaphor source.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source})),Object.entries(i.inputs||{}).forEach(([d,h])=>{const m=Re(h);if(!m)return;const F=g(m,e.intent.source);if(!v.semaphorSourcesReferToSameDataset(F,e.intent.source)){o.push({severity:"error",code:"unsupported_derived_field_source",message:`Derived field "${i.name}" input "${d}" references a different Semaphor source. App-local derived fields must use fields from the query source.`,path:`${s}.inputs.${d}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:F,field:m});return}I(e.catalog,m,e.intent.source)||o.push({severity:"error",code:"missing_field",message:`Derived field "${i.name}" input "${d}" references field "${m.name}", which is not visible on the selected Semaphor source.`,path:`${s}.inputs.${d}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:F,field:m})})}),o}function ge(e){return ke(e.intent).flatMap(({field:r,path:o})=>{const t=ie({intent:e.intent,field:r,relativePath:o,baseCatalog:e.catalog,fieldCatalogs:e.fieldCatalogs});return t.ok?[]:[{severity:"error",code:t.code,message:t.message,path:`${e.pathPrefix}.${o}${t.pathSuffix||""}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:t.source,field:r}]})}function ve(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((o,t)=>{if(!o.field)return[];const i=g(o.field,e.intent.source);if(!v.semaphorSourcesReferToSameDataset(i,e.intent.source)){if(qe(e.intent,i)){const a=k(e.fieldCatalogs,i);return a?I(a,o.field,i)?[]:[{severity:"error",code:"missing_field",message:`Input "${o.inputId}" references field "${o.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]:[{severity:"error",code:"invalid_source_ref",message:`Input "${o.inputId}" references a Semaphor source that is not present in the visible field catalog.`,path:`${e.pathPrefix}.spec.inputs.${t}.field.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]}return[{severity:"error",code:"unsupported_input_filter_composition",message:`Input "${o.inputId}" filters a different Semaphor source than the query, and no relationship-aware semantic validation path is available for this query kind.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]}return I(e.catalog,o.field,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Input "${o.inputId}" references field "${o.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]})}function qe(e,r){return e.source.kind==="semantic"&&r.kind==="semantic"&&r.domainId===e.source.domainId}function Se(e){if(e.querySpec.spec.queryKind!=="analysis")return[];const r=N(e.querySpec.spec,{pathPrefix:`${e.pathPrefix}.spec`,validateTimezone:e.validateTimezone});return r.ok?[]:r.issues.map(o=>({severity:"error",code:o.code,message:o.message,path:o.path,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}))}function Ie(e){return e.querySpec.spec.queryKind!=="sql"?[]:O(e.querySpec.spec)?Object.prototype.hasOwnProperty.call(e.querySpec.spec,"parameters")?[{severity:"error",code:"deprecated_sql_parameters",message:"semaphor.sql uses defaultParameters for static SQL param(...) fallback values. The legacy parameters field is not supported.",path:`${e.pathPrefix}.spec.parameters`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id}]:[]:[]}function ke(e){return e.kind==="metric"?[...e.measures.map((r,o)=>({field:r,path:`spec.measures.${o}`})),...e.primaryMeasure?[{field:e.primaryMeasure,path:"spec.primaryMeasure"}]:[],...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...(e.dimensions||[]).map((r,o)=>({field:r,path:`spec.dimensions.${o}`})),...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:e.kind==="records"?[...e.fields.map((r,o)=>({field:r,path:`spec.fields.${o}`})),...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:e.kind==="inputOptions"?[{field:e.labelField,path:"spec.labelField"},{field:e.valueField,path:"spec.valueField"},...e.searchField?[{field:e.searchField,path:"spec.searchField"}]:[],...(e.disambiguationFields||[]).map((r,o)=>({field:r,path:`spec.disambiguationFields.${o}`}))]:e.kind==="matrix"?[...e.rows.map((r,o)=>({field:r.field,path:`spec.rows.${o}.field`})),...e.rows.flatMap((r,o)=>{var t;return((t=r.sortBy)==null?void 0:t.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.rows.${o}.sortBy.by.field`}]:[]}),...(e.columns||[]).map((r,o)=>({field:r.field,path:`spec.columns.${o}.field`})),...(e.columns||[]).flatMap((r,o)=>{var t;return((t=r.sortBy)==null?void 0:t.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.columns.${o}.sortBy.by.field`}]:[]}),...e.values.map((r,o)=>({field:r.field,path:`spec.values.${o}.field`})),...(e.sort||[]).flatMap((r,o)=>r.by.kind==="field"?[{field:r.by.field,path:`spec.sort.${o}.by.field`}]:[]),...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:[]}function K(e){return!("derivedFields"in e)||!Array.isArray(e.derivedFields)?[]:e.derivedFields}function Fe(e,r,o){return K(e).map(t=>({name:t.name,label:t.label,role:t.resultRole,dataType:t.dataType,source:r.source||o,...t.defaultAggregate?{aggregate:t.defaultAggregate}:{}}))}function Re(e){if(!(!e||typeof e!="object"))return e.field}function P(e,r){return{severity:r.severity,code:e.code||"invalid_analytics_intent",message:e.message,path:e.path?`${r.pathPrefix}.spec.${e.path}`:r.pathPrefix,queryHook:r.queryHook,queryId:r.queryId,intentId:r.intent.id,source:r.intent.source}}function xe(e,r){const o=Q(r);return{ok:o.ok&&e.ok,errors:H([...e.errors,...o.errors]),warnings:H([...e.warnings,...o.warnings]),repairHints:[...e.repairHints,...o.repairHints]}}function Q(e){const r=e.filter(t=>t.severity==="error").map(A),o=e.filter(t=>t.severity==="warning").map(A);return{ok:r.length===0,errors:r,warnings:o,repairHints:r.map(t=>{var i,a;return{code:t.code,message:t.message,fieldRole:t.fieldRole,invalidField:(i=t.repairHint)==null?void 0:i.invalidField,recommendedNextStep:((a=t.repairHint)==null?void 0:a.recommendedNextStep)||"Update the Data App SDK query spec to use visible Semaphor source and field refs."}})}}function A(e){var r;return{code:e.code,message:e.message,path:e.path,fieldRole:e.code==="invalid_source_ref"?"source":void 0,repairHint:{code:e.code,message:e.message,invalidField:(r=e.field)==null?void 0:r.name,fieldRole:e.code==="invalid_source_ref"?"source":void 0,recommendedNextStep:e.code==="unsupported_input_filter_composition"?"Use an input field from the same Semaphor source as the query, or split the query into separate source-scoped queries.":"Update the query spec to use a visible Semaphor source and field ref."}}}function H(e){const r=new Set;return e.filter(o=>{const t=`${o.code}:${o.path||""}:${o.message}`;return r.has(t)?!1:(r.add(t),!0)})}function j(e){var o,t;const r=e.diagnostics.filter(i=>i.severity==="error");return{intentId:(o=e.intent)==null?void 0:o.id,status:r.length?"failed":"answered",resultShape:(t=e.intent)==null?void 0:t.kind,intent:e.intent,validation:e.validation,coverage:{answeredObligations:r.length?[]:["query_spec_validation"],missingObligations:r.length?["query_spec_validation"]:[],warnings:e.validation.warnings},missingFields:r.filter(i=>i.code==="missing_field").flatMap(i=>{var a;return(a=i.field)!=null&&a.name?[i.field.name]:[]}),warnings:e.diagnostics.filter(i=>i.severity==="warning").map(i=>i.message),metadata:{validationKind:"data_app_sdk_query_spec"}}}function be(e,r){return r.id||E(e.spec)}function E(e){if(!e||typeof e!="object"||!("id"in e))return;const r=e.id;return typeof r=="string"&&r.trim()?r:void 0}exports.fieldWithSelectedProjectionRole=f;exports.findMatchingRelatedProjectionField=u;exports.isAllowedRelatedProjectionRole=B;exports.matrixAxisFieldsForPolicy=S;exports.normalizeSemaphorAnalysisQueryOptions=N;exports.normalizeSemaphorFieldRole=w;exports.relatedProjectionFieldCandidatesForIntent=J;exports.validateSemaphorDataAppQuerySpecs=de;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("../chunks/validators-B2vUAqTf.js");require("../chunks/analyze-result-contract-BswhsmWT.js");const v=require("../chunks/source-identity-Cbo2LOHQ.js"),W=require("../report-runtime-context/index.cjs"),y=require("../data-app-sdk-adapters/index.cjs"),R=require("../chunks/catalog-field-grounding-Bnx-3tE0.js");function J({intent:e,field:r,catalogField:o,relativePath:t}){const i=L({intent:e,field:r,relativePath:t});if(!i||i.allowedRelatedRoles.length===0)return!1;const a=f(r,i.selectedField),s=_(o),n=p(a);return M(s,i.allowedRelatedRoles)?n===s:!1}function U(e){return e.kind==="records"?Y(e):e.kind==="metric"?Z(e):ee(e)}function _(e){const r=R.normalizeAnalyticsCatalogName(e.role);if(r==="measure")return"measure";if(r==="id")return"id";const o=R.normalizeAnalyticsCatalogDataType(e.dataType);if(r==="date"||o==="date"||o==="datetime")return"date";if(r==="dimension")return"dimension"}function M(e,r){return!!(e&&r.includes(e))}function f(e,r){const o=p(e);if(o)return e.role===o?e:{...e,role:o};const t=r?p(r):void 0;return t?{...e,role:t}:e}function u(e,r){return e.find(o=>D(o,r))}function S(e){return[...e.rows.map(r=>r.field),...(e.columns||[]).map(r=>r.field)]}function L({intent:e,field:r,relativePath:o}){if(e.kind==="records")return V(e,r,o);if(e.kind==="metric")return G(e,r,o);if(e.kind==="matrix")return X(e,r,o)}function V(e,r,o){if(o.startsWith("spec.fields."))return{allowedRelatedRoles:["dimension","date","id"]};if(o==="spec.dateField"&&!e.timeWindow)return{allowedRelatedRoles:["date"]};if(o==="spec.orderBy.field"){const t=u(B(e),r);return{selectedField:t,allowedRelatedRoles:t?x(t):[]}}}function G(e,r,o){if(o.startsWith("spec.dimensions."))return{allowedRelatedRoles:["dimension"]};if(o==="spec.orderBy.field"){const t=u(e.dimensions||[],r);return{selectedField:t,allowedRelatedRoles:t?["dimension"]:[]}}}function X(e,r,o){if(te(o))return{allowedRelatedRoles:["dimension","date"]};if(ie(o)){const t=u(S(e),r);return{selectedField:t,allowedRelatedRoles:q(t)}}}function Y(e){var t,i;const r=B(e),o=(t=e.orderBy)!=null&&t.field?u(r,e.orderBy.field):void 0;return w([...r.map(a=>l(a,x(a))),...(i=e.orderBy)!=null&&i.field?[l(f(e.orderBy.field,o),o?x(o):[],{unsupportedRelatedRoleMessage:"Joined records projections support related sort fields only when the same related field is included in spec.fields.",recommendedNextStep:"Add the related sort field to spec.fields, or keep orderBy fields on the base source."})]:[]])}function Z(e){var o,t;const r=(o=e.orderBy)!=null&&o.field?u(e.dimensions||[],e.orderBy.field):void 0;return w([...e.measures.map(i=>l(i,[])),...e.primaryMeasure?[l(e.primaryMeasure,[])]:[],...(e.dimensions||[]).map(i=>l(i,["dimension"])),...e.dateField?[l({...e.dateField,role:"date"},[])]:[],...(t=e.orderBy)!=null&&t.field?[l(f(e.orderBy.field,r),r?["dimension"]:[],{unsupportedRelatedRoleMessage:"Joined metric projections support related orderBy fields only when the same related field is declared in spec.dimensions.",recommendedNextStep:"Add the related field as a metric dimension when it should participate in the grouped result, or keep orderBy fields on the base source."})]:[]])}function ee(e){const r=[...e.rows,...e.columns||[]];return w([...r.map(o=>l(o.field,q(o.field))),...r.flatMap(o=>{var a;if(((a=o.sortBy)==null?void 0:a.by.kind)!=="field")return[];const t=o.sortBy.by.field,i=u(S(e),t);return[l(f(t,i),q(i),{unsupportedRelatedRoleMessage:"Joined matrix projections support related axis sort fields only when the same related field is used as a row/column axis.",recommendedNextStep:"Use a related field as a row or column axis, or keep axis sort fields on the base source."})]}),...e.values.map(o=>l(o.field,[],{unsupportedRelatedRoleMessage:"Joined matrix projections support related row/column dimensions or dates only. Related value fields are not supported in this phase.",recommendedNextStep:"Keep matrix values on the base source, or use governed SQL for unsupported aggregate-safe joined values."})),...(e.sort||[]).flatMap(o=>{if(o.by.kind!=="field")return[];const t=o.by.field,i=u(S(e),t);return[l(f(t,i),q(i),{unsupportedRelatedRoleMessage:"Joined matrix projections support related top-level sort fields only when the same related field is used as a row/column axis.",recommendedNextStep:"Use a related field as a row or column axis, or keep matrix sort fields on the base source."})]})])}function x(e){const r=e?p(e):void 0;return r==="dimension"?["dimension"]:r==="date"?["date"]:r==="id"?["id"]:["dimension","date","id"]}function q(e){const r=e?p(e):void 0;return r==="date"?["date"]:r==="dimension"?["dimension"]:[]}function l(e,r,o={}){return{field:f(e),allowedRelatedRoles:r,...o}}function w(e){const r=[];return e.forEach(o=>{r.some(t=>re(t,o))||r.push(o)}),r}function B(e){const r=[...e.fields];return e.dateField&&!r.some(o=>T(o,e.dateField))&&r.push({...e.dateField,role:"date"}),r}function re(e,r){return D(e.field,r.field)&&e.allowedRelatedRoles.join("|")===r.allowedRelatedRoles.join("|")&&(e.unsupportedRelatedRoleMessage||"")===(r.unsupportedRelatedRoleMessage||"")&&(e.recommendedNextStep||"")===(r.recommendedNextStep||"")}function T(e,r){return v.semaphorFieldRefsMatch(e,r)}function D(e,r){return T(e,r)&&oe(p(e),p(r))}function oe(e,r){return!!(e&&(!r||e===r))}function p(e){return _(e)}function te(e){const r=e.split(".");return r.length===4&&r[0]==="spec"&&(r[1]==="rows"||r[1]==="columns")&&$(r[2])&&r[3]==="field"}function ie(e){const r=e.split(".");return r.length===6&&r[0]==="spec"&&(r[1]==="rows"||r[1]==="columns")&&$(r[2])&&r[3]==="sortBy"&&r[4]==="by"&&r[5]==="field"||r.length===5&&r[0]==="spec"&&r[1]==="sort"&&$(r[2])&&r[3]==="by"&&r[4]==="field"}function $(e){return e===void 0||e.trim()===""?!1:Number.isInteger(Number(e))&&Number(e)>=0}function ae({intent:e,field:r,relativePath:o,baseCatalog:t,fieldCatalogs:i}){const a=g(r,e.source),s=v.semaphorSourcesReferToSameDataset(a,e.source);if(!s&&!ne(e.source,a))return{ok:!1,code:"invalid_source_ref",message:`Field "${r.name}" references a related Semaphor source outside the query's semantic domain.`,pathSuffix:".source",source:a};const n=s?t:I(i,a);if(!n)return{ok:!1,code:"invalid_source_ref",message:`Field "${r.name}" references a Semaphor source that is not present in the visible field catalog.`,pathSuffix:".source",source:a};const d=F(n,r,e.source);return d?!s&&!se({intent:e,field:r,catalogField:d,relativePath:o})?{ok:!1,code:"unsupported_joined_projection",message:`Field "${r.name}" references a related Semaphor source, but this query kind does not support joined projections for that field yet.`,pathSuffix:".source",source:a}:{ok:!0,source:a,catalogField:d,usesBaseSource:s}:{ok:!1,code:"missing_field",message:`Field "${r.name}" is not visible on the selected Semaphor source.`,source:a}}function se({intent:e,field:r,catalogField:o,relativePath:t}){return J({intent:e,field:r,catalogField:o,relativePath:t})}function ne(e,r){return e.kind==="semantic"&&r.kind==="semantic"&&e.domainId===r.domainId}function I(e,r){return e.find(o=>b(o,r))}function F(e,r,o){const t=g(r,o);if(b(e,t))return e.fields.find(i=>de(i,r)&&b(e,g(i,e.source)))}function C(e){return R.normalizeAnalyticsCatalogName(e)}function g(e,r){return e.source||r}function b(e,r){return[e.source,...e.sourceAliases||[]].some(o=>v.semaphorSourcesReferToSameDataset(o,r))}function de(e,r){return!!(e.name&&r.name&&e.name===r.name)}function z(e,r={}){const o=r.pathPrefix||"analysisOptions";if(e===void 0)return{ok:!0};if(!e||typeof e!="object"||Array.isArray(e))return c(o,"Data App analysis options must be an object.");const t=e,i={};if(t.chartTitle!==void 0){if(typeof t.chartTitle!="string")return c(`${o}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');i.chartTitle=t.chartTitle}if(t.chartType!==void 0){if(typeof t.chartType!="string")return c(`${o}.chartType`,'Data App analysis option "chartType" must be a string.');i.chartType=t.chartType}if(t.driverMode!==void 0){if(!ue(t.driverMode))return c(`${o}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');i.driverMode=t.driverMode}if(t.includePopulation!==void 0){if(typeof t.includePopulation!="boolean")return c(`${o}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');i.includePopulation=t.includePopulation}if(t.calendarContext!==void 0){const a=fe(t.calendarContext,{pathPrefix:`${o}.calendarContext`,validateTimezone:r.validateTimezone});if(!a.ok)return a;i.calendarContext=a.calendarContext}return{ok:!0,analysisOptions:i}}function le(e){const r=e.queries.map((i,a)=>ce(i,a,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),o=r.flatMap(i=>i.diagnostics),t=r.map(i=>i.executionResult);return{ok:o.every(i=>i.severity!=="error"),diagnostics:o,queries:r,intents:r.flatMap(i=>i.intent?[i.intent]:[]),executionResults:t}}function ce(e,r,o){const t=`queries.${r}`;try{const i=pe(e),a=be(e,i),s=E.validateSemaphorAnalyticsIntent(i),n=[...Ie({querySpec:e,queryId:a,intent:i,pathPrefix:t}),...s.errors.map(h=>P(h,{queryHook:e.queryHook,queryId:a,pathPrefix:t,severity:"error",intent:i})),...s.warnings.map(h=>P(h,{queryHook:e.queryHook,queryId:a,pathPrefix:t,severity:"warning",intent:i})),...ye({querySpec:e,queryId:a,intent:i,pathPrefix:t,fieldCatalogs:o.fieldCatalogs,requireFieldCatalog:o.requireFieldCatalog}),...Fe({querySpec:e,queryId:a,intent:i,pathPrefix:t,validateTimezone:o.validateTimezone})],d=$e(s,n);return{queryHook:e.queryHook,queryId:a,intent:i,diagnostics:n,executionResult:j({intent:i,validation:d,diagnostics:n})}}catch(i){const a={severity:"error",code:"invalid_query_spec",message:i instanceof Error?i.message:String(i),path:t,queryHook:e.queryHook,queryId:Q(e.spec)},s=K([a]);return{queryHook:e.queryHook,queryId:a.queryId,diagnostics:[a],executionResult:j({validation:s,diagnostics:[a]})}}}function c(e,r){return{ok:!1,issues:[{code:"invalid_analysis_option",message:r,path:e}]}}function N(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function ue(e){return e==="absolute_delta"||e==="largest_negative"||e==="largest_positive"||e==="positive_and_negative"||e==="all"}function fe(e,r){if(!e||typeof e!="object"||Array.isArray(e))return c(r.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const o=e,t=o.tz;let i=t;if(typeof t=="string"&&r.validateTimezone&&(i=r.validateTimezone(t)),i===null)return c(`${r.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.');const a=W.parseCalendarContext({...o,tz:i});if(!a.ok){const s=a.issues[0];return c(s!=null&&s.path?`${r.pathPrefix}.${s.path}`:r.pathPrefix,`Data App analysis option "calendarContext" is invalid: ${(s==null?void 0:s.message)??"invalid value"}.`)}return{ok:!0,calendarContext:a.value}}function pe(e){return me(e.spec)}function me(e){if(!N(e))throw new Error("useSemaphorQuery spec must be an object.");if(e.queryKind==="metric")return y.toSemaphorMetricIntent(e);if(e.queryKind==="analysis")return y.toSemaphorAnalysisIntent(e);if(e.queryKind==="records")return y.toSemaphorRecordsIntent(e);if(e.queryKind==="sql")return y.toSemaphorSqlIntent(e);if(e.queryKind==="matrix")return y.toSemaphorMatrixIntent(e);if(e.queryKind==="inputOptions")return y.toSemaphorInputOptionsIntent(e);throw new Error("useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, sql, or matrix.")}function ye(e){if(e.intent.kind==="sql")return[];if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const r=I(e.fieldCatalogs,e.intent.source);if(!r)return[{severity:"error",code:"invalid_source_ref",message:`Source ref for ${e.querySpec.queryHook} does not match a visible Semaphor source.`,path:`${e.pathPrefix}.spec.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}];const o=ge({...e,catalog:r}),t={...r,fields:[...r.fields,...Re(e.intent,r,e.intent.source)]};return[...o,...he({...e,fieldCatalogs:e.fieldCatalogs}),...ve({...e,catalog:t,fieldCatalogs:e.fieldCatalogs}),...qe({...e,catalog:t,fieldCatalogs:e.fieldCatalogs})]}function he(e){var o;if(e.intent.kind!=="inputOptions"||((o=e.intent.population)==null?void 0:o.kind)!=="related_population")return[];const r=e.intent.population.baseSource;return I(e.fieldCatalogs,r)?[]:[{severity:"error",code:"invalid_source_ref",message:"Input options related population baseSource does not match a visible Semaphor source.",path:`${e.pathPrefix}.spec.population.baseSource`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:r}]}function ge(e){const r=O(e.intent);if(r.length===0)return[];const o=[],t=new Set;return r.forEach((i,a)=>{const s=`${e.pathPrefix}.spec.derivedFields.${a}`,n=C(i.name);n&&(t.has(n)&&o.push({severity:"error",code:"duplicate_derived_field",message:`Derived field "${i.name}" is declared more than once.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}),t.add(n),e.catalog.fields.some(d=>C(d.name)===n)&&o.push({severity:"error",code:"derived_field_name_collision",message:`Derived field "${i.name}" conflicts with a field already visible on the selected Semaphor source.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source})),Object.entries(i.inputs||{}).forEach(([d,h])=>{const m=xe(h);if(!m)return;const k=g(m,e.intent.source);if(!v.semaphorSourcesReferToSameDataset(k,e.intent.source)){o.push({severity:"error",code:"unsupported_derived_field_source",message:`Derived field "${i.name}" input "${d}" references a different Semaphor source. App-local derived fields must use fields from the query source.`,path:`${s}.inputs.${d}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:k,field:m});return}F(e.catalog,m,e.intent.source)||o.push({severity:"error",code:"missing_field",message:`Derived field "${i.name}" input "${d}" references field "${m.name}", which is not visible on the selected Semaphor source.`,path:`${s}.inputs.${d}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:k,field:m})})}),o}function ve(e){return ke(e.intent).flatMap(({field:r,path:o})=>{const t=ae({intent:e.intent,field:r,relativePath:o,baseCatalog:e.catalog,fieldCatalogs:e.fieldCatalogs});return t.ok?[]:[{severity:"error",code:t.code,message:t.message,path:`${e.pathPrefix}.${o}${t.pathSuffix||""}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:t.source,field:r}]})}function qe(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((o,t)=>{if(!o.field)return[];const i=g(o.field,e.intent.source);if(!v.semaphorSourcesReferToSameDataset(i,e.intent.source)){if(Se(e.intent,i)){const a=I(e.fieldCatalogs,i);return a?F(a,o.field,i)?[]:[{severity:"error",code:"missing_field",message:`Input "${o.inputId}" references field "${o.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]:[{severity:"error",code:"invalid_source_ref",message:`Input "${o.inputId}" references a Semaphor source that is not present in the visible field catalog.`,path:`${e.pathPrefix}.spec.inputs.${t}.field.source`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]}return[{severity:"error",code:"unsupported_input_filter_composition",message:`Input "${o.inputId}" filters a different Semaphor source than the query, and no relationship-aware semantic validation path is available for this query kind.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]}return F(e.catalog,o.field,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Input "${o.inputId}" references field "${o.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${t}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:i,field:o.field}]})}function Se(e,r){return e.source.kind==="semantic"&&r.kind==="semantic"&&r.domainId===e.source.domainId}function Fe(e){if(e.querySpec.spec.queryKind!=="analysis")return[];const r=z(e.querySpec.spec,{pathPrefix:`${e.pathPrefix}.spec`,validateTimezone:e.validateTimezone});return r.ok?[]:r.issues.map(o=>({severity:"error",code:o.code,message:o.message,path:o.path,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}))}function Ie(e){return e.querySpec.spec.queryKind!=="sql"?[]:N(e.querySpec.spec)?Object.prototype.hasOwnProperty.call(e.querySpec.spec,"parameters")?[{severity:"error",code:"deprecated_sql_parameters",message:"semaphor.sql uses defaultParameters for static SQL param(...) fallback values. The legacy parameters field is not supported.",path:`${e.pathPrefix}.spec.parameters`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id}]:[]:[]}function ke(e){return e.kind==="metric"?[...e.measures.map((r,o)=>({field:r,path:`spec.measures.${o}`})),...e.primaryMeasure?[{field:e.primaryMeasure,path:"spec.primaryMeasure"}]:[],...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...(e.dimensions||[]).map((r,o)=>({field:r,path:`spec.dimensions.${o}`})),...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:e.kind==="records"?[...e.fields.map((r,o)=>({field:r,path:`spec.fields.${o}`})),...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:e.kind==="inputOptions"?[{field:e.labelField,path:"spec.labelField"},{field:e.valueField,path:"spec.valueField"},...e.searchField?[{field:e.searchField,path:"spec.searchField"}]:[],...(e.disambiguationFields||[]).map((r,o)=>({field:r,path:`spec.disambiguationFields.${o}`}))]:e.kind==="matrix"?[...e.rows.map((r,o)=>({field:r.field,path:`spec.rows.${o}.field`})),...e.rows.flatMap((r,o)=>{var t;return((t=r.sortBy)==null?void 0:t.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.rows.${o}.sortBy.by.field`}]:[]}),...(e.columns||[]).map((r,o)=>({field:r.field,path:`spec.columns.${o}.field`})),...(e.columns||[]).flatMap((r,o)=>{var t;return((t=r.sortBy)==null?void 0:t.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.columns.${o}.sortBy.by.field`}]:[]}),...e.values.map((r,o)=>({field:r.field,path:`spec.values.${o}.field`})),...(e.sort||[]).flatMap((r,o)=>r.by.kind==="field"?[{field:r.by.field,path:`spec.sort.${o}.by.field`}]:[]),...(e.filters||[]).map((r,o)=>({field:r.field,path:`spec.filters.${o}.field`}))]:[]}function O(e){return!("derivedFields"in e)||!Array.isArray(e.derivedFields)?[]:e.derivedFields}function Re(e,r,o){return O(e).map(t=>({name:t.name,label:t.label,role:t.resultRole,dataType:t.dataType,source:r.source||o,...t.defaultAggregate?{aggregate:t.defaultAggregate}:{}}))}function xe(e){if(!(!e||typeof e!="object"))return e.field}function P(e,r){return{severity:r.severity,code:e.code||"invalid_analytics_intent",message:e.message,path:e.path?`${r.pathPrefix}.spec.${e.path}`:r.pathPrefix,queryHook:r.queryHook,queryId:r.queryId,intentId:r.intent.id,source:r.intent.source}}function $e(e,r){const o=K(r);return{ok:o.ok&&e.ok,errors:H([...e.errors,...o.errors]),warnings:H([...e.warnings,...o.warnings]),repairHints:[...e.repairHints,...o.repairHints]}}function K(e){const r=e.filter(t=>t.severity==="error").map(A),o=e.filter(t=>t.severity==="warning").map(A);return{ok:r.length===0,errors:r,warnings:o,repairHints:r.map(t=>{var i,a;return{code:t.code,message:t.message,fieldRole:t.fieldRole,invalidField:(i=t.repairHint)==null?void 0:i.invalidField,recommendedNextStep:((a=t.repairHint)==null?void 0:a.recommendedNextStep)||"Update the Data App SDK query spec to use visible Semaphor source and field refs."}})}}function A(e){var r;return{code:e.code,message:e.message,path:e.path,fieldRole:e.code==="invalid_source_ref"?"source":void 0,repairHint:{code:e.code,message:e.message,invalidField:(r=e.field)==null?void 0:r.name,fieldRole:e.code==="invalid_source_ref"?"source":void 0,recommendedNextStep:e.code==="unsupported_input_filter_composition"?"Use an input field from the same Semaphor source as the query, or split the query into separate source-scoped queries.":"Update the query spec to use a visible Semaphor source and field ref."}}}function H(e){const r=new Set;return e.filter(o=>{const t=`${o.code}:${o.path||""}:${o.message}`;return r.has(t)?!1:(r.add(t),!0)})}function j(e){var o,t;const r=e.diagnostics.filter(i=>i.severity==="error");return{intentId:(o=e.intent)==null?void 0:o.id,status:r.length?"failed":"answered",resultShape:(t=e.intent)==null?void 0:t.kind,intent:e.intent,validation:e.validation,coverage:{answeredObligations:r.length?[]:["query_spec_validation"],missingObligations:r.length?["query_spec_validation"]:[],warnings:e.validation.warnings},missingFields:r.filter(i=>i.code==="missing_field").flatMap(i=>{var a;return(a=i.field)!=null&&a.name?[i.field.name]:[]}),warnings:e.diagnostics.filter(i=>i.severity==="warning").map(i=>i.message),metadata:{validationKind:"data_app_sdk_query_spec"}}}function be(e,r){return r.id||Q(e.spec)}function Q(e){if(!e||typeof e!="object"||!("id"in e))return;const r=e.id;return typeof r=="string"&&r.trim()?r:void 0}exports.fieldWithSelectedProjectionRole=f;exports.findMatchingRelatedProjectionField=u;exports.isAllowedRelatedProjectionRole=M;exports.matrixAxisFieldsForPolicy=S;exports.normalizeSemaphorAnalysisQueryOptions=z;exports.normalizeSemaphorFieldRole=_;exports.relatedProjectionFieldCandidatesForIntent=U;exports.validateSemaphorDataAppQuerySpecs=le;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { v as O } from "../chunks/validators-Bce_J7Vd.js";
|
|
2
|
+
import "../chunks/analyze-result-contract-CfOBEwaC.js";
|
|
3
|
+
import { s as K, b as q } from "../chunks/source-identity-5OPV4gvg.js";
|
|
4
|
+
import { parseCalendarContext as Q } from "../report-runtime-context/index.js";
|
|
3
5
|
import { toSemaphorMetricIntent as E, toSemaphorAnalysisIntent as J, toSemaphorRecordsIntent as U, toSemaphorSqlIntent as W, toSemaphorMatrixIntent as L, toSemaphorInputOptionsIntent as V } from "../data-app-sdk-adapters/index.js";
|
|
4
|
-
import { a as
|
|
6
|
+
import { a as H, n as G } from "../chunks/catalog-field-grounding-AOGwWu0K.js";
|
|
5
7
|
function X({
|
|
6
8
|
intent: e,
|
|
7
9
|
field: r,
|
|
@@ -18,17 +20,17 @@ function X({
|
|
|
18
20
|
const a = m(
|
|
19
21
|
r,
|
|
20
22
|
i.selectedField
|
|
21
|
-
), s =
|
|
23
|
+
), s = A(o), n = f(a);
|
|
22
24
|
return Y(
|
|
23
25
|
s,
|
|
24
26
|
i.allowedRelatedRoles
|
|
25
27
|
) ? n === s : !1;
|
|
26
28
|
}
|
|
27
|
-
function
|
|
29
|
+
function ze(e) {
|
|
28
30
|
return e.kind === "records" ? te(e) : e.kind === "metric" ? ie(e) : ae(e);
|
|
29
31
|
}
|
|
30
|
-
function
|
|
31
|
-
const r =
|
|
32
|
+
function A(e) {
|
|
33
|
+
const r = H(e.role);
|
|
32
34
|
if (r === "measure")
|
|
33
35
|
return "measure";
|
|
34
36
|
if (r === "id")
|
|
@@ -125,7 +127,7 @@ function oe(e, r, o) {
|
|
|
125
127
|
function te(e) {
|
|
126
128
|
var t, i;
|
|
127
129
|
const r = M(e), o = (t = e.orderBy) != null && t.field ? u(r, e.orderBy.field) : void 0;
|
|
128
|
-
return
|
|
130
|
+
return $([
|
|
129
131
|
...r.map(
|
|
130
132
|
(a) => l(
|
|
131
133
|
a,
|
|
@@ -153,7 +155,7 @@ function ie(e) {
|
|
|
153
155
|
e.dimensions || [],
|
|
154
156
|
e.orderBy.field
|
|
155
157
|
) : void 0;
|
|
156
|
-
return
|
|
158
|
+
return $([
|
|
157
159
|
...e.measures.map((i) => l(i, [])),
|
|
158
160
|
...e.primaryMeasure ? [l(e.primaryMeasure, [])] : [],
|
|
159
161
|
...(e.dimensions || []).map(
|
|
@@ -177,7 +179,7 @@ function ie(e) {
|
|
|
177
179
|
}
|
|
178
180
|
function ae(e) {
|
|
179
181
|
const r = [...e.rows, ...e.columns || []];
|
|
180
|
-
return
|
|
182
|
+
return $([
|
|
181
183
|
...r.map(
|
|
182
184
|
(o) => l(
|
|
183
185
|
o.field,
|
|
@@ -244,7 +246,7 @@ function l(e, r, o = {}) {
|
|
|
244
246
|
...o
|
|
245
247
|
};
|
|
246
248
|
}
|
|
247
|
-
function
|
|
249
|
+
function $(e) {
|
|
248
250
|
const r = [];
|
|
249
251
|
return e.forEach((o) => {
|
|
250
252
|
r.some(
|
|
@@ -262,7 +264,7 @@ function se(e, r) {
|
|
|
262
264
|
return B(e.field, r.field) && e.allowedRelatedRoles.join("|") === r.allowedRelatedRoles.join("|") && (e.unsupportedRelatedRoleMessage || "") === (r.unsupportedRelatedRoleMessage || "") && (e.recommendedNextStep || "") === (r.recommendedNextStep || "");
|
|
263
265
|
}
|
|
264
266
|
function j(e, r) {
|
|
265
|
-
return
|
|
267
|
+
return K(e, r);
|
|
266
268
|
}
|
|
267
269
|
function B(e, r) {
|
|
268
270
|
return j(e, r) && ne(
|
|
@@ -274,7 +276,7 @@ function ne(e, r) {
|
|
|
274
276
|
return !!(e && (!r || e === r));
|
|
275
277
|
}
|
|
276
278
|
function f(e) {
|
|
277
|
-
return
|
|
279
|
+
return A(e);
|
|
278
280
|
}
|
|
279
281
|
function de(e) {
|
|
280
282
|
const r = e.split(".");
|
|
@@ -368,8 +370,8 @@ function v(e, r, o) {
|
|
|
368
370
|
)
|
|
369
371
|
);
|
|
370
372
|
}
|
|
371
|
-
function
|
|
372
|
-
return
|
|
373
|
+
function b(e) {
|
|
374
|
+
return H(e);
|
|
373
375
|
}
|
|
374
376
|
function h(e, r) {
|
|
375
377
|
return e.source || r;
|
|
@@ -438,7 +440,7 @@ function me(e, r = {}) {
|
|
|
438
440
|
}
|
|
439
441
|
return { ok: !0, analysisOptions: i };
|
|
440
442
|
}
|
|
441
|
-
function
|
|
443
|
+
function Ne(e) {
|
|
442
444
|
const r = e.queries.map(
|
|
443
445
|
(i, a) => ye(i, a, {
|
|
444
446
|
fieldCatalogs: e.fieldCatalogs || [],
|
|
@@ -459,15 +461,15 @@ function De(e) {
|
|
|
459
461
|
function ye(e, r, o) {
|
|
460
462
|
const t = `queries.${r}`;
|
|
461
463
|
try {
|
|
462
|
-
const i = ve(e), a =
|
|
463
|
-
|
|
464
|
+
const i = ve(e), a = He(e, i), s = O(i), n = [
|
|
465
|
+
...be({
|
|
464
466
|
querySpec: e,
|
|
465
467
|
queryId: a,
|
|
466
468
|
intent: i,
|
|
467
469
|
pathPrefix: t
|
|
468
470
|
}),
|
|
469
471
|
...s.errors.map(
|
|
470
|
-
(y) =>
|
|
472
|
+
(y) => _(y, {
|
|
471
473
|
queryHook: e.queryHook,
|
|
472
474
|
queryId: a,
|
|
473
475
|
pathPrefix: t,
|
|
@@ -476,7 +478,7 @@ function ye(e, r, o) {
|
|
|
476
478
|
})
|
|
477
479
|
),
|
|
478
480
|
...s.warnings.map(
|
|
479
|
-
(y) =>
|
|
481
|
+
(y) => _(y, {
|
|
480
482
|
queryHook: e.queryHook,
|
|
481
483
|
queryId: a,
|
|
482
484
|
pathPrefix: t,
|
|
@@ -492,7 +494,7 @@ function ye(e, r, o) {
|
|
|
492
494
|
fieldCatalogs: o.fieldCatalogs,
|
|
493
495
|
requireFieldCatalog: o.requireFieldCatalog
|
|
494
496
|
}),
|
|
495
|
-
|
|
497
|
+
...$e({
|
|
496
498
|
querySpec: e,
|
|
497
499
|
queryId: a,
|
|
498
500
|
intent: i,
|
|
@@ -550,30 +552,30 @@ function he(e) {
|
|
|
550
552
|
return e === "absolute_delta" || e === "largest_negative" || e === "largest_positive" || e === "positive_and_negative" || e === "all";
|
|
551
553
|
}
|
|
552
554
|
function ge(e, r) {
|
|
553
|
-
var d;
|
|
554
555
|
if (!e || typeof e != "object" || Array.isArray(e))
|
|
555
556
|
return c(
|
|
556
557
|
r.pathPrefix,
|
|
557
558
|
'Data App analysis option "calendarContext" must be an object.'
|
|
558
559
|
);
|
|
559
|
-
const o = e, t = o.tz
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
560
|
+
const o = e, t = o.tz;
|
|
561
|
+
let i = t;
|
|
562
|
+
if (typeof t == "string" && r.validateTimezone && (i = r.validateTimezone(t)), i === null)
|
|
563
|
+
return c(
|
|
564
|
+
`${r.pathPrefix}.tz`,
|
|
565
|
+
'Data App analysis option "calendarContext.tz" must be a valid timezone string.'
|
|
566
|
+
);
|
|
567
|
+
const a = Q({
|
|
568
|
+
...o,
|
|
569
|
+
tz: i
|
|
570
|
+
});
|
|
571
|
+
if (!a.ok) {
|
|
572
|
+
const s = a.issues[0];
|
|
573
|
+
return c(
|
|
574
|
+
s != null && s.path ? `${r.pathPrefix}.${s.path}` : r.pathPrefix,
|
|
575
|
+
`Data App analysis option "calendarContext" is invalid: ${(s == null ? void 0 : s.message) ?? "invalid value"}.`
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
return { ok: !0, calendarContext: a.value };
|
|
577
579
|
}
|
|
578
580
|
function ve(e) {
|
|
579
581
|
return qe(e.spec);
|
|
@@ -626,7 +628,7 @@ function Se(e) {
|
|
|
626
628
|
...r,
|
|
627
629
|
fields: [
|
|
628
630
|
...r.fields,
|
|
629
|
-
...
|
|
631
|
+
...we(e.intent, r, e.intent.source)
|
|
630
632
|
]
|
|
631
633
|
};
|
|
632
634
|
return [
|
|
@@ -671,7 +673,7 @@ function ke(e) {
|
|
|
671
673
|
return [];
|
|
672
674
|
const o = [], t = /* @__PURE__ */ new Set();
|
|
673
675
|
return r.forEach((i, a) => {
|
|
674
|
-
const s = `${e.pathPrefix}.spec.derivedFields.${a}`, n =
|
|
676
|
+
const s = `${e.pathPrefix}.spec.derivedFields.${a}`, n = b(i.name);
|
|
675
677
|
n && (t.has(n) && o.push({
|
|
676
678
|
severity: "error",
|
|
677
679
|
code: "duplicate_derived_field",
|
|
@@ -682,7 +684,7 @@ function ke(e) {
|
|
|
682
684
|
intentId: e.intent.id,
|
|
683
685
|
source: e.intent.source
|
|
684
686
|
}), t.add(n), e.catalog.fields.some(
|
|
685
|
-
(d) =>
|
|
687
|
+
(d) => b(d.name) === n
|
|
686
688
|
) && o.push({
|
|
687
689
|
severity: "error",
|
|
688
690
|
code: "derived_field_name_collision",
|
|
@@ -726,7 +728,7 @@ function ke(e) {
|
|
|
726
728
|
}), o;
|
|
727
729
|
}
|
|
728
730
|
function Fe(e) {
|
|
729
|
-
return
|
|
731
|
+
return _e(e.intent).flatMap(({ field: r, path: o }) => {
|
|
730
732
|
const t = ce({
|
|
731
733
|
intent: e.intent,
|
|
732
734
|
field: r,
|
|
@@ -815,7 +817,7 @@ function xe(e) {
|
|
|
815
817
|
function Re(e, r) {
|
|
816
818
|
return e.source.kind === "semantic" && r.kind === "semantic" && r.domainId === e.source.domainId;
|
|
817
819
|
}
|
|
818
|
-
function
|
|
820
|
+
function $e(e) {
|
|
819
821
|
if (e.querySpec.spec.queryKind !== "analysis")
|
|
820
822
|
return [];
|
|
821
823
|
const r = me(
|
|
@@ -836,7 +838,7 @@ function be(e) {
|
|
|
836
838
|
source: e.intent.source
|
|
837
839
|
}));
|
|
838
840
|
}
|
|
839
|
-
function
|
|
841
|
+
function be(e) {
|
|
840
842
|
return e.querySpec.spec.queryKind !== "sql" ? [] : T(e.querySpec.spec) ? Object.prototype.hasOwnProperty.call(e.querySpec.spec, "parameters") ? [
|
|
841
843
|
{
|
|
842
844
|
severity: "error",
|
|
@@ -849,7 +851,7 @@ function $e(e) {
|
|
|
849
851
|
}
|
|
850
852
|
] : [] : [];
|
|
851
853
|
}
|
|
852
|
-
function
|
|
854
|
+
function _e(e) {
|
|
853
855
|
return e.kind === "metric" ? [
|
|
854
856
|
...e.measures.map((r, o) => ({
|
|
855
857
|
field: r,
|
|
@@ -937,7 +939,7 @@ function we(e) {
|
|
|
937
939
|
function D(e) {
|
|
938
940
|
return !("derivedFields" in e) || !Array.isArray(e.derivedFields) ? [] : e.derivedFields;
|
|
939
941
|
}
|
|
940
|
-
function
|
|
942
|
+
function we(e, r, o) {
|
|
941
943
|
return D(e).map((t) => ({
|
|
942
944
|
name: t.name,
|
|
943
945
|
label: t.label,
|
|
@@ -951,7 +953,7 @@ function Ce(e) {
|
|
|
951
953
|
if (!(!e || typeof e != "object"))
|
|
952
954
|
return e.field;
|
|
953
955
|
}
|
|
954
|
-
function
|
|
956
|
+
function _(e, r) {
|
|
955
957
|
return {
|
|
956
958
|
severity: r.severity,
|
|
957
959
|
code: e.code || "invalid_analytics_intent",
|
|
@@ -982,7 +984,7 @@ function Pe(e, r) {
|
|
|
982
984
|
};
|
|
983
985
|
}
|
|
984
986
|
function z(e) {
|
|
985
|
-
const r = e.filter((t) => t.severity === "error").map(
|
|
987
|
+
const r = e.filter((t) => t.severity === "error").map(w), o = e.filter((t) => t.severity === "warning").map(w);
|
|
986
988
|
return {
|
|
987
989
|
ok: r.length === 0,
|
|
988
990
|
errors: r,
|
|
@@ -999,7 +1001,7 @@ function z(e) {
|
|
|
999
1001
|
})
|
|
1000
1002
|
};
|
|
1001
1003
|
}
|
|
1002
|
-
function
|
|
1004
|
+
function w(e) {
|
|
1003
1005
|
var r;
|
|
1004
1006
|
return {
|
|
1005
1007
|
code: e.code,
|
|
@@ -1050,7 +1052,7 @@ function P(e) {
|
|
|
1050
1052
|
}
|
|
1051
1053
|
};
|
|
1052
1054
|
}
|
|
1053
|
-
function
|
|
1055
|
+
function He(e, r) {
|
|
1054
1056
|
return r.id || N(e.spec);
|
|
1055
1057
|
}
|
|
1056
1058
|
function N(e) {
|
|
@@ -1065,7 +1067,7 @@ export {
|
|
|
1065
1067
|
Y as isAllowedRelatedProjectionRole,
|
|
1066
1068
|
k as matrixAxisFieldsForPolicy,
|
|
1067
1069
|
me as normalizeSemaphorAnalysisQueryOptions,
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1070
|
+
A as normalizeSemaphorFieldRole,
|
|
1071
|
+
ze as relatedProjectionFieldCandidatesForIntent,
|
|
1072
|
+
Ne as validateSemaphorDataAppQuerySpecs
|
|
1071
1073
|
};
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../chunks/
|
|
2
|
-
`)
|
|
3
|
-
`}=e;return r.map(o=>f(o,n)).join(t)}function N(r,e={}){if(r.length===0)return"";const{delimiter:n=",",lineEnding:t=`
|
|
4
|
-
`,includeHeaders:o=!0,columns:u}=e,s=u||Object.keys(r[0]),i=[];o&&i.push(s);for(const c of r){const p=s.map(b=>{const a=c[b];return a==null?"":String(a)});i.push(p)}return d(i,{delimiter:n,lineEnding:t})}function y(r,e){const n=[];e.includeHeaders&&n.push(f(e.visibleColumns,e.delimiter));for(const t of r){const o=T(t,e);n.push(o.map(u=>m(u,e.delimiter)).join(e.delimiter))}return n}function v(r,e,n=`
|
|
5
|
-
`){return y(r,e).join(n)}function j(r,e,n){return r==null?"":n.useFormattedValues?typeof r=="number"&&(e==null?void 0:e.type)==="number"?l.formatNumberWithColumnSettings(r,e.numberFormat,n.locale):typeof r=="number"?r.toLocaleString(n.locale):String(r):String(r)}function V(r,e,n){var o,u;const t=[];if(r.isSubtotal&&!r.isGrandTotal){const s=e.groupByColumns.findIndex(i=>i.alias===r.subtotalLevel);e.groupByColumns.forEach((i,c)=>{var p,b,a,S;if(c===s){const A=(b=(p=e.rowAggregates)==null?void 0:p.find(E=>E.groupLevel===r.subtotalLevel))==null?void 0:b.label,L=(S=(a=r.subtotalContext)==null?void 0:a.groupByValues)==null?void 0:S[i.alias];t.push(A??`Subtotal (${L??"Total"})`)}else c<s?t.push(String(r[i.alias]??"")):t.push("")})}else if(r.isGrandTotal){const s=(u=(o=e.rowAggregates)==null?void 0:o.find(i=>i.groupLevel==="ALL"))==null?void 0:u.label;t.push(s||"Grand Total"),e.groupByColumns.slice(1).forEach(()=>t.push(""))}else e.groupByColumns.forEach(s=>{t.push(String(r[s.alias]??""))});return e.pivotSchema.filter(s=>s.isMetricColumn).forEach(s=>{const i=r[s.alias],c=n.columnSettings[s.alias];t.push(j(i,c,n))}),t}function C(r){const e=r.groupByColumns.map(t=>t.label||t.name),n=r.pivotSchema.filter(t=>t.isMetricColumn).map(t=>t.displayLabel||t.metricLabel||t.metricName||t.alias);return[...e,...n]}function D(r,e,n){const t=[];if(n.includeHeaders){const o=C(e);t.push(f(o,n.delimiter))}for(const o of r){const u=V(o,e,n);t.push(u.map(s=>m(s,n.delimiter)).join(n.delimiter))}return t}function w(r,e,n){for(const t of r){if(t.level<n){e[t.level].push(t.name);for(let o=1;o<t.colspan;o++)e[t.level].push("")}t.children?w(t.children,e,n):t.columnKey&&e[n].push(t.name)}}function z(r){const e=r.pivotByColumns.length,n=r.groupByColumns.length,t=Array.from({length:e+1},()=>[]);for(let o=0;o<e;o++)t[o].push(...Array(n).fill(""));if(t[e].push(...r.groupByColumns.map(o=>o.label||o.name)),w(r.columnHeadersTree,t,e),r.showRowTotals){for(let o=0;o<e;o++)t[o].push("");t[e].push("Total")}return t}function P(r,e,n){if(r==null)return"";if(!n.useFormattedValues)return String(r);const t=n.columnSettings[e];return typeof r=="number"&&(t==null?void 0:t.type)==="number"?l.formatNumberWithColumnSettings(r,t.numberFormat,n.locale):typeof r=="number"?r.toLocaleString(n.locale):String(r)}function R(r,e,n){const t=[];r.fieldValues.forEach((u,s)=>{r.isSubtotal&&s===0?t.push(`${u} Total`):r.isSubtotal?t.push(""):t.push(String(u??""))});let o=0;return e.columnHeaders.forEach(u=>{var c;const s=(c=r.cells[u])==null?void 0:c.value,i=P(s,u,n);t.push(i),e.showRowTotals&&typeof s=="number"&&(o+=s)}),e.showRowTotals&&t.push(o.toLocaleString(n.locale)),t}function B(r,e,n){const t=[];if(n.includeHeaders){const o=z(e);for(const u of o)t.push(f(u,n.delimiter))}for(const o of r){const u=R(o,e,n);t.push(u.map(s=>m(s,n.delimiter)).join(n.delimiter))}return t}exports.formatCurrency=l.formatCurrency;exports.formatDate=l.formatDate;exports.formatDuration=l.formatDuration;exports.formatMetricComparison=l.formatMetricComparison;exports.formatNumber=l.formatNumber;exports.formatNumberCustom=l.formatNumberCustom;exports.formatNumberWithColumnSettings=l.formatNumberWithColumnSettings;exports.formatPercent=l.formatPercent;exports.formatRelativeTime=l.formatRelativeTime;exports.formatScientific=l.formatScientific;exports.getTimezoneAbbreviation=l.getTimezoneAbbreviation;exports.getTimezoneName=l.getTimezoneName;exports.parseWithSourceTimezone=l.parseWithSourceTimezone;exports.resolveTimezone=l.resolveTimezone;exports.arrayToCSV=d;exports.arrayToCSVRow=f;exports.escapeCSVValue=m;exports.formatAggregateRow=V;exports.formatAggregateTableForCSV=D;exports.formatCellValue=h;exports.formatPivotDataRow=R;exports.formatPivotTableForCSV=B;exports.formatRowForExport=T;exports.formatTableForCSV=y;exports.generateAggregateHeaders=C;exports.generatePivotHeaders=z;exports.generateTableCSV=v;exports.objectsToCSV=N;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../chunks/numeric-presentation-Dlb-Dk4c.js"),u=require("../chunks/csv-utils-Co0WxHke.js");function z(r,e,o,t){const s=r instanceof Date?r.toISOString():String(r),i=(t==null?void 0:t.browserTimezone)||o,n=(t==null?void 0:t.isSqlCard)??!1;if(e!=null&&e.useRelativeTime)return u.formatRelativeTime(s,(e==null?void 0:e.sourceTimezone)||"auto");const a=e!=null&&e.useCustomFormat&&(e!=null&&e.customFormat)?e.customFormat:(e==null?void 0:e.format)||"MM/dd/yyyy";return u.formatDate(s,a,e!=null&&e.timezone&&(e==null?void 0:e.timezone)!=="auto"?e.timezone:n?i:o,(e==null?void 0:e.sourceTimezone)||"auto")}function b(r,e,o){if(r==null)return"";if(!o.useFormattedValues||!e)return String(r);switch(e.type){case"number":return typeof r=="number"?l.formatNumberWithColumnSettings(r,e.numberFormat,o.locale):String(r);case"date":return z(r,e.dateFormat,o.timezone,{browserTimezone:o.browserTimezone,isSqlCard:o.isSqlCard});case"progress":return typeof r=="number"?`${r}%`:String(r);case"badge":case"link":case"text":case"none":default:return String(r)}}function h(r,e){return e.visibleColumns.map(o=>{const t=r[o],s=e.columnSettings[o];return b(t,s,{useFormattedValues:e.useFormattedValues,timezone:e.timezone,locale:e.locale})})}function T(r,e){const o=[];e.includeHeaders&&o.push(u.arrayToCSVRow(e.visibleColumns,e.delimiter));for(const t of r){const s=h(t,e);o.push(s.map(i=>u.escapeCSVValue(i,e.delimiter)).join(e.delimiter))}return o}function P(r,e,o=`
|
|
2
|
+
`){return T(r,e).join(o)}function E(r,e,o){return r==null?"":o.useFormattedValues?typeof r=="number"&&(e==null?void 0:e.type)==="number"?l.formatNumberWithColumnSettings(r,e.numberFormat,o.locale):typeof r=="number"?r.toLocaleString(o.locale):String(r):String(r)}function V(r,e,o){var s,i;const t=[];if(r.isSubtotal&&!r.isGrandTotal){const n=e.groupByColumns.findIndex(a=>a.alias===r.subtotalLevel);e.groupByColumns.forEach((a,m)=>{var c,f,p,S;if(m===n){const R=(f=(c=e.rowAggregates)==null?void 0:c.find(v=>v.groupLevel===r.subtotalLevel))==null?void 0:f.label,w=(S=(p=r.subtotalContext)==null?void 0:p.groupByValues)==null?void 0:S[a.alias];t.push(R??`Subtotal (${w??"Total"})`)}else m<n?t.push(String(r[a.alias]??"")):t.push("")})}else if(r.isGrandTotal){const n=(i=(s=e.rowAggregates)==null?void 0:s.find(a=>a.groupLevel==="ALL"))==null?void 0:i.label;t.push(n||"Grand Total"),e.groupByColumns.slice(1).forEach(()=>t.push(""))}else e.groupByColumns.forEach(n=>{t.push(String(r[n.alias]??""))});return e.pivotSchema.filter(n=>n.isMetricColumn).forEach(n=>{const a=r[n.alias],m=o.columnSettings[n.alias];t.push(E(a,m,o))}),t}function C(r){const e=r.groupByColumns.map(t=>t.label||t.name),o=r.pivotSchema.filter(t=>t.isMetricColumn).map(t=>t.displayLabel||t.metricLabel||t.metricName||t.alias);return[...e,...o]}function A(r,e,o){const t=[];if(o.includeHeaders){const s=C(e);t.push(u.arrayToCSVRow(s,o.delimiter))}for(const s of r){const i=V(s,e,o);t.push(i.map(n=>u.escapeCSVValue(n,o.delimiter)).join(o.delimiter))}return t}function y(r,e,o){for(const t of r){if(t.level<o){e[t.level].push(t.name);for(let s=1;s<t.colspan;s++)e[t.level].push("")}t.children?y(t.children,e,o):t.columnKey&&e[o].push(t.name)}}function d(r){const e=r.pivotByColumns.length,o=r.groupByColumns.length,t=Array.from({length:e+1},()=>[]);for(let s=0;s<e;s++)t[s].push(...Array(o).fill(""));if(t[e].push(...r.groupByColumns.map(s=>s.label||s.name)),y(r.columnHeadersTree,t,e),r.showRowTotals){for(let s=0;s<e;s++)t[s].push("");t[e].push("Total")}return t}function L(r,e,o){if(r==null)return"";if(!o.useFormattedValues)return String(r);const t=o.columnSettings[e];return typeof r=="number"&&(t==null?void 0:t.type)==="number"?l.formatNumberWithColumnSettings(r,t.numberFormat,o.locale):typeof r=="number"?r.toLocaleString(o.locale):String(r)}function N(r,e,o){const t=[];r.fieldValues.forEach((i,n)=>{r.isSubtotal&&n===0?t.push(`${i} Total`):r.isSubtotal?t.push(""):t.push(String(i??""))});let s=0;return e.columnHeaders.forEach(i=>{var m;const n=(m=r.cells[i])==null?void 0:m.value,a=L(n,i,o);t.push(a),e.showRowTotals&&typeof n=="number"&&(s+=n)}),e.showRowTotals&&t.push(s.toLocaleString(o.locale)),t}function D(r,e,o){const t=[];if(o.includeHeaders){const s=d(e);for(const i of s)t.push(u.arrayToCSVRow(i,o.delimiter))}for(const s of r){const i=N(s,e,o);t.push(i.map(n=>u.escapeCSVValue(n,o.delimiter)).join(o.delimiter))}return t}exports.formatCurrency=l.formatCurrency;exports.formatNumber=l.formatNumber;exports.formatNumberCustom=l.formatNumberCustom;exports.formatNumberWithColumnSettings=l.formatNumberWithColumnSettings;exports.formatNumericCanonical=l.formatNumericCanonical;exports.formatPercent=l.formatPercent;exports.formatScientific=l.formatScientific;exports.parseNumericCanonicalFormat=l.parseNumericCanonicalFormat;exports.parseNumericPresentationExecutionSnapshot=l.parseNumericPresentationExecutionSnapshot;exports.parseNumericPresentationSnapshotEntries=l.parseNumericPresentationSnapshotEntries;exports.parseResolvedNumericCanonicalFormat=l.parseResolvedNumericCanonicalFormat;exports.resolveCurrencyFractionDigits=l.resolveCurrencyFractionDigits;exports.resolveNumericPresentation=l.resolveNumericPresentation;exports.validateCardExportNumericPresentationSnapshot=l.validateCardExportNumericPresentationSnapshot;exports.arrayToCSV=u.arrayToCSV;exports.arrayToCSVRow=u.arrayToCSVRow;exports.escapeCSVValue=u.escapeCSVValue;exports.formatDate=u.formatDate;exports.formatDuration=u.formatDuration;exports.formatMetricComparison=u.formatMetricComparison;exports.formatRelativeTime=u.formatRelativeTime;exports.getTimezoneAbbreviation=u.getTimezoneAbbreviation;exports.getTimezoneName=u.getTimezoneName;exports.objectsToCSV=u.objectsToCSV;exports.parseWithSourceTimezone=u.parseWithSourceTimezone;exports.resolveTimezone=u.resolveTimezone;exports.formatAggregateRow=V;exports.formatAggregateTableForCSV=A;exports.formatCellValue=b;exports.formatPivotDataRow=N;exports.formatPivotTableForCSV=D;exports.formatRowForExport=h;exports.formatTableForCSV=T;exports.generateAggregateHeaders=C;exports.generatePivotHeaders=d;exports.generateTableCSV=P;
|