react-semaphor 0.1.423 → 0.1.425
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 +243 -91
- package/dist/appearance/index.cjs +1 -1
- package/dist/appearance/index.js +1 -1
- package/dist/brand-studio/index.cjs +2 -2
- package/dist/brand-studio/index.js +8 -8
- package/dist/chunks/{analyze-result-contract-D7pjjYPy.js → analyze-result-contract-DnfF8kBb.js} +434 -427
- package/dist/chunks/analyze-result-contract-ege_u6Nl.js +1 -0
- package/dist/chunks/{braces-8TRlDwDw.js → braces-BdbUk_r9.js} +1 -1
- package/dist/chunks/{braces-D2tStQjF.js → braces-CbO-aIwH.js} +1 -1
- package/dist/chunks/calendar-preferences-dialog-BLaSWhLl.js +1 -0
- package/dist/chunks/{calendar-preferences-dialog-t5ET6MON.js → calendar-preferences-dialog-DJwV0aqn.js} +4 -4
- package/dist/chunks/{catalog-field-grounding-CJKAqtiC.js → catalog-field-grounding-DcxPLns0.js} +10 -10
- package/dist/chunks/{switch-2bh3Hka1.js → code-editor-Bkk7s8hI.js} +7382 -6809
- package/dist/chunks/code-editor-CkXyNgYc.js +138 -0
- package/dist/chunks/{common-types-4bjoIgvm.js → common-types-ClkOI-3O.js} +4 -4
- package/dist/chunks/comparison-document-migration-CQJ0DZlL.js +414 -0
- package/dist/chunks/comparison-document-migration-Db64RWYD.js +1 -0
- package/dist/chunks/{index-yHe0SeLO.js → dashboard-5agU0G_D.js} +56752 -55440
- package/dist/chunks/dashboard-MKIqgGDp.js +1402 -0
- package/dist/chunks/{dashboard-briefing-launcher-S2akO-ub.js → dashboard-briefing-launcher-CII8-4qo.js} +11 -6
- package/dist/chunks/{dashboard-briefing-launcher-Cavd0QJb.js → dashboard-briefing-launcher-qyEVfuOm.js} +226 -209
- package/dist/chunks/dashboard-controls-PJpeYZHw.js +36 -0
- package/dist/chunks/dashboard-controls-aJY0FNPP.js +2196 -0
- package/dist/chunks/dashboard-input-contract-BFpERluO.js +18 -0
- package/dist/chunks/dashboard-input-contract-DV3cshjz.js +1 -0
- package/dist/chunks/{dashboard-json-Do2-pdPZ.js → dashboard-json-CzHSP6Fa.js} +16 -15
- package/dist/chunks/dashboard-json-DtmR5yCf.js +1 -0
- package/dist/chunks/date-formatter-BTTYdAik.js +1 -0
- package/dist/chunks/date-formatter-D-89jTjG.js +514 -0
- package/dist/chunks/{edit-dashboard-visual-Cw6bq4_w.js → edit-dashboard-visual-AkZzwBCV.js} +8892 -8996
- package/dist/chunks/edit-dashboard-visual-Cif6uDqN.js +182 -0
- package/dist/chunks/{index-CjzRe2su.js → index-CnujJ3fa.js} +3 -3
- package/dist/chunks/{index-DRlMUglg.js → index-Dpm_VET4.js} +2 -2
- package/dist/chunks/{index-CJdxSyQq.js → index-If0wlXGi.js} +308 -308
- package/dist/chunks/index-jSrCwPQz.js +31 -0
- package/dist/chunks/{x-CXDkqdur.js → index-xHCrHprY.js} +59 -59
- package/dist/chunks/{layout-grid-C0OI-MRn.js → layout-grid-B08pP7v6.js} +1 -1
- package/dist/chunks/{layout-grid-CiubineE.js → layout-grid-D5tYJg1-.js} +1 -1
- package/dist/chunks/metric-comparison-4oA4ouU9.js +354 -0
- package/dist/chunks/metric-comparison-nQKquVnx.js +1 -0
- package/dist/chunks/{palette-C4KTXOug.js → palette-C0yjT5Tv.js} +1 -1
- package/dist/chunks/{palette-Cp1hqZtm.js → palette-jqaAcwiQ.js} +1 -1
- package/dist/chunks/{save-DgMfP0j8.js → save-HCJjjzdX.js} +1 -1
- package/dist/chunks/{save-C__QggEE.js → save-Xdc4pnys.js} +1 -1
- package/dist/chunks/{search-BHsQIWBV.js → search-DHZCro8B.js} +1 -1
- package/dist/chunks/{search-DNCejM7Z.js → search-Dcud9ajy.js} +1 -1
- package/dist/chunks/{update-policy-C1pmhLz9.js → update-policy-BgONreNd.js} +1 -1
- package/dist/chunks/{update-policy-BCJc0oI5.js → update-policy-CY2k-pJP.js} +9 -9
- package/dist/chunks/{use-create-flow-overlay-state-5MDbZcs1.js → use-create-flow-overlay-state-ByOKVV2K.js} +62 -62
- package/dist/chunks/{use-create-flow-overlay-state-BNczg9Gj.js → use-create-flow-overlay-state-DmuReEnk.js} +2 -2
- package/dist/chunks/validators-B4VMLX3_.js +1 -0
- package/dist/chunks/{validators-PXkij33j.js → validators-Cz-XuORM.js} +123 -119
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +2 -2
- package/dist/dashboard-authoring/index.cjs +2 -2
- package/dist/dashboard-authoring/index.js +6 -4
- package/dist/data-app-builder/index.cjs +6 -6
- package/dist/data-app-builder/index.js +5 -5
- 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 +1 -1
- package/dist/data-app-sdk/index.js +6 -6
- package/dist/data-app-sdk-adapters/index.cjs +1 -1
- package/dist/data-app-sdk-adapters/index.js +1 -1
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +65 -68
- package/dist/format-utils/index.cjs +2 -2
- package/dist/format-utils/index.js +59 -58
- package/dist/index.cjs +1 -1
- package/dist/index.js +19 -19
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +3 -3
- package/dist/types/analytics-protocol.d.ts +299 -3
- package/dist/types/brand-studio.d.ts +2 -2
- package/dist/types/briefings.d.ts +65 -41
- package/dist/types/dashboard-assistant.d.ts +28 -7
- package/dist/types/dashboard-authoring.d.ts +123 -43
- package/dist/types/dashboard.d.ts +97 -48
- package/dist/types/data-app-builder.d.ts +2 -2
- package/dist/types/data-app-sdk.d.ts +1 -1
- package/dist/types/format-utils.d.ts +98 -10
- package/dist/types/index.js +1 -1
- package/dist/types/main.d.ts +229 -95
- package/dist/types/shared.d.ts +84 -43
- package/dist/types/surfboard.d.ts +99 -49
- package/dist/types/types.d.ts +110 -50
- package/package.json +2 -1
- package/dist/chunks/analyze-result-contract-DpDcImgk.js +0 -1
- package/dist/chunks/calendar-preferences-dialog-CTmeASaM.js +0 -1
- package/dist/chunks/contracts-CoCOpd_i.js +0 -11
- package/dist/chunks/contracts-CtB2VONT.js +0 -1
- package/dist/chunks/dashboard-controls-BJLrErjW.js +0 -2322
- package/dist/chunks/dashboard-controls-DzbP8AXA.js +0 -52
- package/dist/chunks/dashboard-json-5tWb5KD6.js +0 -1
- package/dist/chunks/date-formatter-B4EBSe9C.js +0 -1
- package/dist/chunks/date-formatter-BlhBftA9.js +0 -416
- package/dist/chunks/edit-dashboard-visual-Yh5YFgMF.js +0 -178
- package/dist/chunks/index-BPM3gDRw.js +0 -1406
- package/dist/chunks/switch-DMT7qf_R.js +0 -138
- package/dist/chunks/validators-DMlVbd1p.js +0 -1
- package/dist/chunks/x-B6ghREd2.js +0 -31
|
@@ -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/analyze-result-contract-ege_u6Nl.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 z(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(C),...(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 P(i)?{...i,field:o(i.field,t)}:{field:o(i,t)}}function C(i){return T(i)?{...i,field:o(i.field,"measure")}:{field:o(i,"measure"),aggregate:i.aggregate}}function P(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=W(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 W(i){return i==="grain"||i==="measure"||i==="dimension"||i==="aggregation"||i==="sqlParam"}function $(i){const t=l(i);return t.length>0?t:void 0}function y(i){return(i||[]).map(L)}function q(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=q;exports.toSemaphorAnalysisIntent=v;exports.toSemaphorAnalysisQueryOptions=F;exports.toSemaphorInputBinding=f;exports.toSemaphorInputBindings=$;exports.toSemaphorInputOptionsIntent=x;exports.toSemaphorInputSnapshots=y;exports.toSemaphorInputSpec=h;exports.toSemaphorMatrixIntent=z;exports.toSemaphorMetricIntent=p;exports.toSemaphorRecordsIntent=k;exports.toSemaphorSqlIntent=O;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as I } from "../chunks/operators-C8TxpM4C.js";
|
|
2
|
-
import { s as m, p as F, b as c } from "../chunks/analyze-result-contract-
|
|
2
|
+
import { s as m, p as F, b as c } from "../chunks/analyze-result-contract-DnfF8kBb.js";
|
|
3
3
|
function S(i) {
|
|
4
4
|
var n, r, a;
|
|
5
5
|
const t = M(i);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("../chunks/validators-DMlVbd1p.js"),v=require("../chunks/analyze-result-contract-DpDcImgk.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 M(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 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 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(B(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=B(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 B(e){const r=[...e.fields];return e.dateField&&!r.some(o=>T(o,e.dateField))&&r.push({...e.dateField,role:"date"}),r}function ee(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)&&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 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(!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=fe(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=pe(e),a=$e(e,i),s=E.validateSemaphorAnalyticsIntent(i),n=[...ke({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}),...Ie({querySpec:e,queryId:a,intent:i,pathPrefix:t,validateTimezone:o.validateTimezone})],d=be(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 ce(e){return e==="absolute_delta"||e==="largest_negative"||e==="largest_positive"||e==="positive_and_negative"||e==="all"}function ue(e){return e.trim().length>0&&!Number.isNaN(Date.parse(e))}function fe(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"&&ue(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 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=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=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 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 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 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 ve(e){return Fe(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 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=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 Se(e,r){return e.source.kind==="semantic"&&r.kind==="semantic"&&r.domainId===e.source.domainId}function Ie(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 ke(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 Fe(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 be(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 $e(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=w;exports.relatedProjectionFieldCandidatesForIntent=J;exports.validateSemaphorDataAppQuerySpecs=de;
|
|
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,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { s as
|
|
3
|
-
import { toSemaphorMetricIntent as
|
|
4
|
-
import { n as A,
|
|
5
|
-
function
|
|
1
|
+
import { p as O, v as K } from "../chunks/validators-Cz-XuORM.js";
|
|
2
|
+
import { s as Q, c as q } from "../chunks/analyze-result-contract-DnfF8kBb.js";
|
|
3
|
+
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 { n as A, a as G } from "../chunks/catalog-field-grounding-DcxPLns0.js";
|
|
5
|
+
function X({
|
|
6
6
|
intent: e,
|
|
7
7
|
field: r,
|
|
8
8
|
catalogField: o,
|
|
9
9
|
relativePath: t
|
|
10
10
|
}) {
|
|
11
|
-
const i =
|
|
11
|
+
const i = Z({
|
|
12
12
|
intent: e,
|
|
13
13
|
field: r,
|
|
14
14
|
relativePath: t
|
|
@@ -19,13 +19,13 @@ function G({
|
|
|
19
19
|
r,
|
|
20
20
|
i.selectedField
|
|
21
21
|
), s = H(o), n = f(a);
|
|
22
|
-
return
|
|
22
|
+
return Y(
|
|
23
23
|
s,
|
|
24
24
|
i.allowedRelatedRoles
|
|
25
25
|
) ? n === s : !1;
|
|
26
26
|
}
|
|
27
27
|
function Te(e) {
|
|
28
|
-
return e.kind === "records" ?
|
|
28
|
+
return e.kind === "records" ? te(e) : e.kind === "metric" ? ie(e) : ae(e);
|
|
29
29
|
}
|
|
30
30
|
function H(e) {
|
|
31
31
|
const r = A(e.role);
|
|
@@ -33,13 +33,13 @@ function H(e) {
|
|
|
33
33
|
return "measure";
|
|
34
34
|
if (r === "id")
|
|
35
35
|
return "id";
|
|
36
|
-
const o =
|
|
36
|
+
const o = G(e.dataType);
|
|
37
37
|
if (r === "date" || o === "date" || o === "datetime")
|
|
38
38
|
return "date";
|
|
39
39
|
if (r === "dimension")
|
|
40
40
|
return "dimension";
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function Y(e, r) {
|
|
43
43
|
return !!(e && r.includes(e));
|
|
44
44
|
}
|
|
45
45
|
function m(e, r) {
|
|
@@ -66,19 +66,19 @@ function k(e) {
|
|
|
66
66
|
...(e.columns || []).map((r) => r.field)
|
|
67
67
|
];
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function Z({
|
|
70
70
|
intent: e,
|
|
71
71
|
field: r,
|
|
72
72
|
relativePath: o
|
|
73
73
|
}) {
|
|
74
74
|
if (e.kind === "records")
|
|
75
|
-
return Z(e, r, o);
|
|
76
|
-
if (e.kind === "metric")
|
|
77
75
|
return ee(e, r, o);
|
|
78
|
-
if (e.kind === "
|
|
76
|
+
if (e.kind === "metric")
|
|
79
77
|
return re(e, r, o);
|
|
78
|
+
if (e.kind === "matrix")
|
|
79
|
+
return oe(e, r, o);
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function ee(e, r, o) {
|
|
82
82
|
if (o.startsWith("spec.fields."))
|
|
83
83
|
return { allowedRelatedRoles: ["dimension", "date", "id"] };
|
|
84
84
|
if (o === "spec.dateField" && !e.timeWindow)
|
|
@@ -94,7 +94,7 @@ function Z(e, r, o) {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function re(e, r, o) {
|
|
98
98
|
if (o.startsWith("spec.dimensions."))
|
|
99
99
|
return { allowedRelatedRoles: ["dimension"] };
|
|
100
100
|
if (o === "spec.orderBy.field") {
|
|
@@ -108,10 +108,10 @@ function ee(e, r, o) {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
function
|
|
112
|
-
if (
|
|
111
|
+
function oe(e, r, o) {
|
|
112
|
+
if (de(o))
|
|
113
113
|
return { allowedRelatedRoles: ["dimension", "date"] };
|
|
114
|
-
if (
|
|
114
|
+
if (le(o)) {
|
|
115
115
|
const t = u(
|
|
116
116
|
k(e),
|
|
117
117
|
r
|
|
@@ -122,10 +122,10 @@ function re(e, r, o) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function te(e) {
|
|
126
126
|
var t, i;
|
|
127
127
|
const r = M(e), o = (t = e.orderBy) != null && t.field ? u(r, e.orderBy.field) : void 0;
|
|
128
|
-
return
|
|
128
|
+
return b([
|
|
129
129
|
...r.map(
|
|
130
130
|
(a) => l(
|
|
131
131
|
a,
|
|
@@ -147,13 +147,13 @@ function oe(e) {
|
|
|
147
147
|
] : []
|
|
148
148
|
]);
|
|
149
149
|
}
|
|
150
|
-
function
|
|
150
|
+
function ie(e) {
|
|
151
151
|
var o, t;
|
|
152
152
|
const r = (o = e.orderBy) != null && o.field ? u(
|
|
153
153
|
e.dimensions || [],
|
|
154
154
|
e.orderBy.field
|
|
155
155
|
) : void 0;
|
|
156
|
-
return
|
|
156
|
+
return b([
|
|
157
157
|
...e.measures.map((i) => l(i, [])),
|
|
158
158
|
...e.primaryMeasure ? [l(e.primaryMeasure, [])] : [],
|
|
159
159
|
...(e.dimensions || []).map(
|
|
@@ -175,9 +175,9 @@ function te(e) {
|
|
|
175
175
|
] : []
|
|
176
176
|
]);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function ae(e) {
|
|
179
179
|
const r = [...e.rows, ...e.columns || []];
|
|
180
|
-
return
|
|
180
|
+
return b([
|
|
181
181
|
...r.map(
|
|
182
182
|
(o) => l(
|
|
183
183
|
o.field,
|
|
@@ -244,11 +244,11 @@ function l(e, r, o = {}) {
|
|
|
244
244
|
...o
|
|
245
245
|
};
|
|
246
246
|
}
|
|
247
|
-
function
|
|
247
|
+
function b(e) {
|
|
248
248
|
const r = [];
|
|
249
249
|
return e.forEach((o) => {
|
|
250
250
|
r.some(
|
|
251
|
-
(t) =>
|
|
251
|
+
(t) => se(t, o)
|
|
252
252
|
) || r.push(o);
|
|
253
253
|
}), r;
|
|
254
254
|
}
|
|
@@ -258,36 +258,36 @@ function M(e) {
|
|
|
258
258
|
(o) => j(o, e.dateField)
|
|
259
259
|
) && r.push({ ...e.dateField, role: "date" }), r;
|
|
260
260
|
}
|
|
261
|
-
function
|
|
261
|
+
function se(e, r) {
|
|
262
262
|
return B(e.field, r.field) && e.allowedRelatedRoles.join("|") === r.allowedRelatedRoles.join("|") && (e.unsupportedRelatedRoleMessage || "") === (r.unsupportedRelatedRoleMessage || "") && (e.recommendedNextStep || "") === (r.recommendedNextStep || "");
|
|
263
263
|
}
|
|
264
264
|
function j(e, r) {
|
|
265
|
-
return
|
|
265
|
+
return Q(e, r);
|
|
266
266
|
}
|
|
267
267
|
function B(e, r) {
|
|
268
|
-
return j(e, r) &&
|
|
268
|
+
return j(e, r) && ne(
|
|
269
269
|
f(e),
|
|
270
270
|
f(r)
|
|
271
271
|
);
|
|
272
272
|
}
|
|
273
|
-
function
|
|
273
|
+
function ne(e, r) {
|
|
274
274
|
return !!(e && (!r || e === r));
|
|
275
275
|
}
|
|
276
276
|
function f(e) {
|
|
277
277
|
return H(e);
|
|
278
278
|
}
|
|
279
|
-
function
|
|
279
|
+
function de(e) {
|
|
280
280
|
const r = e.split(".");
|
|
281
281
|
return r.length === 4 && r[0] === "spec" && (r[1] === "rows" || r[1] === "columns") && x(r[2]) && r[3] === "field";
|
|
282
282
|
}
|
|
283
|
-
function
|
|
283
|
+
function le(e) {
|
|
284
284
|
const r = e.split(".");
|
|
285
285
|
return r.length === 6 && r[0] === "spec" && (r[1] === "rows" || r[1] === "columns") && x(r[2]) && r[3] === "sortBy" && r[4] === "by" && r[5] === "field" || r.length === 5 && r[0] === "spec" && r[1] === "sort" && x(r[2]) && r[3] === "by" && r[4] === "field";
|
|
286
286
|
}
|
|
287
287
|
function x(e) {
|
|
288
288
|
return e === void 0 || e.trim() === "" ? !1 : Number.isInteger(Number(e)) && Number(e) >= 0;
|
|
289
289
|
}
|
|
290
|
-
function
|
|
290
|
+
function ce({
|
|
291
291
|
intent: e,
|
|
292
292
|
field: r,
|
|
293
293
|
relativePath: o,
|
|
@@ -298,7 +298,7 @@ function le({
|
|
|
298
298
|
a,
|
|
299
299
|
e.source
|
|
300
300
|
);
|
|
301
|
-
if (!s && !
|
|
301
|
+
if (!s && !fe(e.source, a))
|
|
302
302
|
return {
|
|
303
303
|
ok: !1,
|
|
304
304
|
code: "invalid_source_ref",
|
|
@@ -316,7 +316,7 @@ function le({
|
|
|
316
316
|
source: a
|
|
317
317
|
};
|
|
318
318
|
const d = v(n, r, e.source);
|
|
319
|
-
return d ? !s && !
|
|
319
|
+
return d ? !s && !ue({
|
|
320
320
|
intent: e,
|
|
321
321
|
field: r,
|
|
322
322
|
catalogField: d,
|
|
@@ -339,30 +339,30 @@ function le({
|
|
|
339
339
|
source: a
|
|
340
340
|
};
|
|
341
341
|
}
|
|
342
|
-
function
|
|
342
|
+
function ue({
|
|
343
343
|
intent: e,
|
|
344
344
|
field: r,
|
|
345
345
|
catalogField: o,
|
|
346
346
|
relativePath: t
|
|
347
347
|
}) {
|
|
348
|
-
return
|
|
348
|
+
return X({
|
|
349
349
|
intent: e,
|
|
350
350
|
field: r,
|
|
351
351
|
catalogField: o,
|
|
352
352
|
relativePath: t
|
|
353
353
|
});
|
|
354
354
|
}
|
|
355
|
-
function
|
|
355
|
+
function fe(e, r) {
|
|
356
356
|
return e.kind === "semantic" && r.kind === "semantic" && e.domainId === r.domainId;
|
|
357
357
|
}
|
|
358
358
|
function S(e, r) {
|
|
359
|
-
return e.find((o) =>
|
|
359
|
+
return e.find((o) => R(o, r));
|
|
360
360
|
}
|
|
361
361
|
function v(e, r, o) {
|
|
362
362
|
const t = h(r, o);
|
|
363
|
-
if (
|
|
363
|
+
if (R(e, t))
|
|
364
364
|
return e.fields.find(
|
|
365
|
-
(i) =>
|
|
365
|
+
(i) => pe(i, r) && R(
|
|
366
366
|
e,
|
|
367
367
|
h(i, e.source)
|
|
368
368
|
)
|
|
@@ -374,15 +374,15 @@ function $(e) {
|
|
|
374
374
|
function h(e, r) {
|
|
375
375
|
return e.source || r;
|
|
376
376
|
}
|
|
377
|
-
function
|
|
377
|
+
function R(e, r) {
|
|
378
378
|
return [e.source, ...e.sourceAliases || []].some(
|
|
379
379
|
(o) => q(o, r)
|
|
380
380
|
);
|
|
381
381
|
}
|
|
382
|
-
function
|
|
382
|
+
function pe(e, r) {
|
|
383
383
|
return !!(e.name && r.name && e.name === r.name);
|
|
384
384
|
}
|
|
385
|
-
function
|
|
385
|
+
function me(e, r = {}) {
|
|
386
386
|
const o = r.pathPrefix || "analysisOptions";
|
|
387
387
|
if (e === void 0)
|
|
388
388
|
return { ok: !0 };
|
|
@@ -409,7 +409,7 @@ function pe(e, r = {}) {
|
|
|
409
409
|
i.chartType = t.chartType;
|
|
410
410
|
}
|
|
411
411
|
if (t.driverMode !== void 0) {
|
|
412
|
-
if (!
|
|
412
|
+
if (!he(t.driverMode))
|
|
413
413
|
return c(
|
|
414
414
|
`${o}.driverMode`,
|
|
415
415
|
'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.'
|
|
@@ -440,7 +440,7 @@ function pe(e, r = {}) {
|
|
|
440
440
|
}
|
|
441
441
|
function De(e) {
|
|
442
442
|
const r = e.queries.map(
|
|
443
|
-
(i, a) =>
|
|
443
|
+
(i, a) => ye(i, a, {
|
|
444
444
|
fieldCatalogs: e.fieldCatalogs || [],
|
|
445
445
|
requireFieldCatalog: !!e.requireFieldCatalog,
|
|
446
446
|
validateTimezone: e.validateTimezone
|
|
@@ -456,10 +456,10 @@ function De(e) {
|
|
|
456
456
|
executionResults: t
|
|
457
457
|
};
|
|
458
458
|
}
|
|
459
|
-
function
|
|
459
|
+
function ye(e, r, o) {
|
|
460
460
|
const t = `queries.${r}`;
|
|
461
461
|
try {
|
|
462
|
-
const i = ve(e), a = Ae(e, i), s =
|
|
462
|
+
const i = ve(e), a = Ae(e, i), s = K(i), n = [
|
|
463
463
|
...$e({
|
|
464
464
|
querySpec: e,
|
|
465
465
|
queryId: a,
|
|
@@ -492,7 +492,7 @@ function me(e, r, o) {
|
|
|
492
492
|
fieldCatalogs: o.fieldCatalogs,
|
|
493
493
|
requireFieldCatalog: o.requireFieldCatalog
|
|
494
494
|
}),
|
|
495
|
-
...
|
|
495
|
+
...be({
|
|
496
496
|
querySpec: e,
|
|
497
497
|
queryId: a,
|
|
498
498
|
intent: i,
|
|
@@ -546,11 +546,8 @@ function c(e, r) {
|
|
|
546
546
|
function T(e) {
|
|
547
547
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
548
548
|
}
|
|
549
|
-
function ye(e) {
|
|
550
|
-
return e === "absolute_delta" || e === "largest_negative" || e === "largest_positive" || e === "positive_and_negative" || e === "all";
|
|
551
|
-
}
|
|
552
549
|
function he(e) {
|
|
553
|
-
return e
|
|
550
|
+
return e === "absolute_delta" || e === "largest_negative" || e === "largest_positive" || e === "positive_and_negative" || e === "all";
|
|
554
551
|
}
|
|
555
552
|
function ge(e, r) {
|
|
556
553
|
var d;
|
|
@@ -563,7 +560,7 @@ function ge(e, r) {
|
|
|
563
560
|
return n ? typeof i != "number" || !Number.isInteger(i) || i < 0 || i > 6 ? c(
|
|
564
561
|
`${r.pathPrefix}.weekStart`,
|
|
565
562
|
'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'
|
|
566
|
-
) : a !== "now" && !(typeof s == "string" &&
|
|
563
|
+
) : a !== "now" && !(typeof s == "string" && O(s)) ? c(
|
|
567
564
|
`${r.pathPrefix}.anchor`,
|
|
568
565
|
'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'
|
|
569
566
|
) : {
|
|
@@ -585,17 +582,17 @@ function qe(e) {
|
|
|
585
582
|
if (!T(e))
|
|
586
583
|
throw new Error("useSemaphorQuery spec must be an object.");
|
|
587
584
|
if (e.queryKind === "metric")
|
|
588
|
-
return Q(e);
|
|
589
|
-
if (e.queryKind === "analysis")
|
|
590
585
|
return E(e);
|
|
591
|
-
if (e.queryKind === "
|
|
586
|
+
if (e.queryKind === "analysis")
|
|
592
587
|
return J(e);
|
|
593
|
-
if (e.queryKind === "
|
|
588
|
+
if (e.queryKind === "records")
|
|
594
589
|
return U(e);
|
|
595
|
-
if (e.queryKind === "
|
|
590
|
+
if (e.queryKind === "sql")
|
|
596
591
|
return W(e);
|
|
597
|
-
if (e.queryKind === "
|
|
592
|
+
if (e.queryKind === "matrix")
|
|
598
593
|
return L(e);
|
|
594
|
+
if (e.queryKind === "inputOptions")
|
|
595
|
+
return V(e);
|
|
599
596
|
throw new Error(
|
|
600
597
|
"useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, sql, or matrix."
|
|
601
598
|
);
|
|
@@ -730,7 +727,7 @@ function ke(e) {
|
|
|
730
727
|
}
|
|
731
728
|
function Fe(e) {
|
|
732
729
|
return we(e.intent).flatMap(({ field: r, path: o }) => {
|
|
733
|
-
const t =
|
|
730
|
+
const t = ce({
|
|
734
731
|
intent: e.intent,
|
|
735
732
|
field: r,
|
|
736
733
|
relativePath: o,
|
|
@@ -758,7 +755,7 @@ function xe(e) {
|
|
|
758
755
|
return [];
|
|
759
756
|
const i = h(o.field, e.intent.source);
|
|
760
757
|
if (!q(i, e.intent.source)) {
|
|
761
|
-
if (
|
|
758
|
+
if (Re(e.intent, i)) {
|
|
762
759
|
const a = S(e.fieldCatalogs, i);
|
|
763
760
|
return a ? v(a, o.field, i) ? [] : [
|
|
764
761
|
{
|
|
@@ -815,13 +812,13 @@ function xe(e) {
|
|
|
815
812
|
];
|
|
816
813
|
});
|
|
817
814
|
}
|
|
818
|
-
function
|
|
815
|
+
function Re(e, r) {
|
|
819
816
|
return e.source.kind === "semantic" && r.kind === "semantic" && r.domainId === e.source.domainId;
|
|
820
817
|
}
|
|
821
|
-
function
|
|
818
|
+
function be(e) {
|
|
822
819
|
if (e.querySpec.spec.queryKind !== "analysis")
|
|
823
820
|
return [];
|
|
824
|
-
const r =
|
|
821
|
+
const r = me(
|
|
825
822
|
e.querySpec.spec,
|
|
826
823
|
{
|
|
827
824
|
pathPrefix: `${e.pathPrefix}.spec`,
|
|
@@ -1065,9 +1062,9 @@ function N(e) {
|
|
|
1065
1062
|
export {
|
|
1066
1063
|
m as fieldWithSelectedProjectionRole,
|
|
1067
1064
|
u as findMatchingRelatedProjectionField,
|
|
1068
|
-
|
|
1065
|
+
Y as isAllowedRelatedProjectionRole,
|
|
1069
1066
|
k as matrixAxisFieldsForPolicy,
|
|
1070
|
-
|
|
1067
|
+
me as normalizeSemaphorAnalysisQueryOptions,
|
|
1071
1068
|
H as normalizeSemaphorFieldRole,
|
|
1072
1069
|
Te as relatedProjectionFieldCandidatesForIntent,
|
|
1073
1070
|
De as validateSemaphorDataAppQuerySpecs
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../chunks/date-formatter-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../chunks/date-formatter-BTTYdAik.js");function H(r,e,n,t){const o=r instanceof Date?r.toISOString():String(r),u=(t==null?void 0:t.browserTimezone)||n,s=(t==null?void 0:t.isSqlCard)??!1;if(e!=null&&e.useRelativeTime)return l.formatRelativeTime(o,(e==null?void 0:e.sourceTimezone)||"auto");const i=e!=null&&e.useCustomFormat&&(e!=null&&e.customFormat)?e.customFormat:(e==null?void 0:e.format)||"MM/dd/yyyy";return l.formatDate(o,i,e!=null&&e.timezone&&(e==null?void 0:e.timezone)!=="auto"?e.timezone:s?u:n,(e==null?void 0:e.sourceTimezone)||"auto")}function h(r,e,n){if(r==null)return"";if(!n.useFormattedValues||!e)return String(r);switch(e.type){case"number":return typeof r=="number"?l.formatNumberWithColumnSettings(r,e.numberFormat,n.locale):String(r);case"date":return H(r,e.dateFormat,n.timezone,{browserTimezone:n.browserTimezone,isSqlCard:n.isSqlCard});case"progress":return typeof r=="number"?`${r}%`:String(r);case"badge":case"link":case"text":case"none":default:return String(r)}}function T(r,e){return e.visibleColumns.map(n=>{const t=r[n],o=e.columnSettings[n];return h(t,o,{useFormattedValues:e.useFormattedValues,timezone:e.timezone,locale:e.locale})})}function m(r,e=","){if(r==null)return"";const n=String(r);return n.includes(e)||n.includes('"')||n.includes(`
|
|
2
2
|
`)||n.includes("\r")?`"${n.replace(/"/g,'""')}"`:n}function f(r,e=","){return r.map(n=>m(n,e)).join(e)}function d(r,e={}){const{delimiter:n=",",lineEnding:t=`
|
|
3
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
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.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;
|
|
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;
|