react-semaphor 0.1.372 → 0.1.374
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 +1 -1
- package/dist/chunks/{calendar-preferences-dialog-Dn6o2r2Y.js → calendar-preferences-dialog-94DoRSW_.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-ClBAkMmF.js → calendar-preferences-dialog-DmBRXOH6.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-BO-kXtEd.js → dashboard-briefing-launcher-CAFCkwG3.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-D3Xfc_26.js → dashboard-briefing-launcher-l0ylhcAv.js} +104 -104
- package/dist/chunks/{dashboard-controls-DcXMFgGR.js → dashboard-controls-BX47yuCH.js} +1 -1
- package/dist/chunks/{dashboard-controls-B3sdy_Zx.js → dashboard-controls-DyzG0r5f.js} +167 -167
- package/dist/chunks/{dashboard-json-BWfkEy48.js → dashboard-json-B8kke4ES.js} +1 -1
- package/dist/chunks/{dashboard-json-CFURS_OR.js → dashboard-json-BlPA6wRT.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-DjdhKiP2.js → edit-dashboard-visual-CgJxTZLJ.js} +6592 -6565
- package/dist/chunks/{edit-dashboard-visual-BD2AJLiT.js → edit-dashboard-visual-DA8SaE4h.js} +37 -37
- package/dist/chunks/index-BJ971AL_.js +1361 -0
- package/dist/chunks/{index-C0Qnfr_7.js → index-BiDFY4Gr.js} +36742 -34869
- package/dist/chunks/{resource-management-panel-YvIfaphX.js → resource-management-panel-Bssc5uaX.js} +51 -51
- package/dist/chunks/{resource-management-panel-DytUMSGA.js → resource-management-panel-C14F7VSc.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-BETXykC9.js → use-create-flow-overlay-state-BGhwg121.js} +35 -35
- package/dist/chunks/{use-create-flow-overlay-state-CwIG1Ekp.js → use-create-flow-overlay-state-DAVI3fO1.js} +1 -1
- package/dist/chunks/{use-visual-utils-Bk135OgA.js → use-visual-utils-47dkDwLK.js} +12 -12
- package/dist/chunks/{use-visual-utils-BzFjIykb.js → use-visual-utils-K0yQRSI7.js} +1 -1
- package/dist/chunks/{validation-D4Zz6WPD.js → validation-1V7bWmYw.js} +1 -1
- package/dist/chunks/{validation-CQFpcSSP.js → validation-DlrTIf1N.js} +1 -1
- package/dist/chunks/{validators-CuKnUZFO.js → validators-CtNmgsvG.js} +409 -314
- package/dist/chunks/validators-jpoYhpHh.js +1 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.cjs +1 -1
- package/dist/dashboard-authoring/index.js +1 -1
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +1 -1
- package/dist/data-app-sdk/index.cjs +1 -1
- package/dist/data-app-sdk/index.js +32 -32
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +127 -126
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/analytics-protocol.d.ts +102 -11
- package/dist/types/dashboard-assistant.d.ts +117 -103
- package/dist/types/dashboard-authoring.d.ts +63 -2
- package/dist/types/dashboard.d.ts +263 -2
- package/dist/types/data-app-builder.d.ts +40 -1
- package/dist/types/data-app-sdk-validation.d.ts +94 -102
- package/dist/types/data-app-sdk.d.ts +106 -11
- package/dist/types/main.d.ts +473 -2
- package/dist/types/shared.d.ts +263 -2
- package/dist/types/surfboard.d.ts +263 -2
- package/dist/types/types.d.ts +529 -2
- package/package.json +1 -1
- package/dist/chunks/index-DlLvzmJF.js +0 -1361
- package/dist/chunks/validators-DHee9kM2.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const u=require("./index-
|
|
1
|
+
"use strict";const u=require("./index-BJ971AL_.js"),f=require("./switch-fIkmwzUt.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const x=require("./validators-DHee9kM2.js"),V=require("./catalog-field-grounding-Du6mKDcF.js"),c=require("./source-identity-C-xaeE_I.js");function S(e){var t,i;const r=G(e);return{version:1,kind:"metric",id:e.id,label:e.label,source:g(e),metrics:r,primaryMetric:L(e,r),dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,dimensions:(t=e.dimensions)==null?void 0:t.map(o=>a(o,"dimension")),comparison:le(e.comparison),orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:p(e.inputs),limit:e.limit,...(i=e.derivedFields)!=null&&i.length?{derivedFields:e.derivedFields}:{}}}function R(e){var t;return{...S(e),...e.timeWindow?{timeWindow:e.timeWindow}:{},...(t=e.filters)!=null&&t.length?{filters:e.filters}:{},...e.analysis?{analysis:e.analysis}:{}}}function W(e){return{...e.chartTitle?{chartTitle:e.chartTitle}:{},...e.chartType?{chartType:e.chartType}:{},...e.driverMode?{driverMode:e.driverMode}:{},...e.includePopulation!==void 0?{includePopulation:e.includePopulation}:{},...e.calendarContext?{calendarContext:e.calendarContext}:{}}}function L(e,r){if(!e.primaryMetric)return r[0]||{name:"",role:"measure"};const t=a(e.primaryMetric,"measure"),i=Y(t,r),o=i.length===1?i[0]:void 0;return o?C(t,o):t}function G(e){const r=[];for(const t of e.metrics.map(i=>a(i,"measure"))){if(!t.name)continue;const i=r.findIndex(o=>U(o,t));if(i===-1){r.push(t);continue}r[i]=C(r[i],t)}return r}function U(e,r){return c.semaphorFieldRefsMatch(e,r)&&h(e)===h(r)}function J(e,r){return h(r)===h(e)}function X(e,r){return r.name!==e.name||e.source&&!c.semaphorFieldRefsMatch(r,e)?!1:J(e,r)}function Y(e,r){const t=r.filter(i=>X(e,i));return e.aggregate!==void 0,t}function h(e){return(e.aggregate||"SUM").toUpperCase()}function C(e,r){if(e.aggregate&&r.aggregate&&e.aggregate!==r.aggregate)throw new Error(`Metric "${e.name}" was requested with conflicting aggregate semantics: ${e.aggregate} and ${r.aggregate}.`);return{...c.preferSemaphorFieldRefMetadata(e,r),aggregate:e.aggregate||r.aggregate}}function H(e){var t,i;if("sort"in e)throw new Error("semaphor.records supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet.");if(!de(e))throw new Error("semaphor.records needs at least one field.");const r=Z(e.fields);return{version:1,kind:"records",id:e.id,label:e.label,source:g(e),fields:r,dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,...e.timeWindow?{timeWindow:e.timeWindow}:{},...(t=e.filters)!=null&&t.length?{filters:e.filters}:{},orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:p(e.inputs),limit:e.limit,...e.pagination?{pagination:e.pagination}:{},...(i=e.derivedFields)!=null&&i.length?{derivedFields:e.derivedFields}:{}}}function Z(e){return e.map(r=>{const t=a(r);if(!t.role)throw new Error(`semaphor.records field "${t.name}" needs an explicit role.`);return t})}function T(e){var r;return{version:1,kind:"inputOptions",id:e.id,label:e.label,source:g(e),field:a(e.field,"dimension"),search:e.search,limit:e.limit,...(r=e.derivedFields)!=null&&r.length?{derivedFields:e.derivedFields}:{}}}function P(e){var r;return{version:1,kind:"sql",id:e.id,label:e.label,source:e.source,sql:e.sql,...e.defaultParameters?{defaultParameters:e.defaultParameters}:{},...e.pythonCode?{pythonCode:e.pythonCode}:{},...(r=e.fields)!=null&&r.length?{fields:e.fields.map(t=>a(t))}:{},inputs:p(e.inputs),limit:e.limit,...e.pagination?{pagination:e.pagination}:{},rationale:e.rationale}}function B(e){var r,t;return{version:1,kind:"matrix",id:e.id,label:e.label,source:g(e),rows:e.rows.map(i=>A(i,"dimension")),...e.columns?{columns:e.columns.map(i=>A(i,"dimension"))}:{},values:e.values.map(ee),...(r=e.filters)!=null&&r.length?{filters:e.filters}:{},inputs:p(e.inputs),...e.totals?{totals:e.totals}:{},...(t=e.sort)!=null&&t.length?{sort:e.sort}:{},...e.expansion?{expansion:e.expansion}:{},...e.layout?{layout:e.layout}:{},...e.displayLimits?{displayLimits:e.displayLimits}:{}}}function A(e,r){return re(e)?{...e,field:a(e.field,r)}:{field:a(e,r)}}function ee(e){return te(e)?{...e,field:a(e.field,"measure")}:{field:a(e,"measure"),aggregate:e.aggregate}}function re(e){return"field"in e}function te(e){return"field"in e}function D(e){if("toAnalyticsInput"in e){const n=e.toAnalyticsInput();return{inputId:n.inputId,kind:n.kind,...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{}}}if("id"in e){const n=k(e);return{inputId:n.inputId,kind:n.kind,...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{}}}const r="kind"in e?e.kind:void 0,t="operator"in e?O(e.operator,e.inputId):void 0,i="controlRole"in e?e.controlRole:"role"in e?e.role:void 0,o=ie(i)?i:void 0;return{inputId:e.inputId,...r?{kind:r}:{},...o?{controlRole:o}:{},...t?{operator:t}:{},...e.field?{field:e.field}:{}}}function ie(e){return e==="grain"||e==="metric"||e==="dimension"||e==="aggregation"||e==="sqlParam"}function oe(e){const r=p(e);return r.length>0?r:void 0}function z(e){return(e||[]).map(se)}function ne(e){return z(e).filter(r=>r.isActive)}function k(e){if(e.kind==="filter"){const r=O(e.operator,e.id);return{inputId:e.id,kind:e.kind,label:e.label,field:a(e.field,"dimension"),operator:r||"in"}}return{inputId:e.id,kind:e.kind,label:e.label,controlRole:e.role}}function ae(e=[]){return e.map(r=>typeof r=="object"?r:{label:String(r),value:r})}function I(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e=="string"?e.trim().length>0:!0}function se(e){if("toAnalyticsInput"in e)return e.toAnalyticsInput();if("kind"in e&&"isActive"in e)return e;if("id"in e){const r=k(e),t=Object.prototype.hasOwnProperty.call(e,"value")?e.value:e.defaultValue;return{inputId:r.inputId,kind:r.kind,label:r.label,...r.field?{field:r.field}:{},...r.operator?{operator:r.operator}:{},...r.controlRole?{controlRole:r.controlRole}:{},value:t,isActive:I(t)}}return{...e,kind:"filter",isActive:I(e.value),value:e.value}}function g(e){return e.source}function de(e){var r;return!!((r=e.fields)!=null&&r.length)}function a(e,r){return{...e,role:e.role||r}}function p(e){return(e||[]).map(D)}function le(e){if(e)return e}function O(e,r){if(e===void 0)return;const t=x.normalizeSemaphorInputOperator(e);if(!t)throw new Error(`useSemaphorInput "${r}" uses unsupported filter operator "${e}".`);return t}function j(e,r={}){const t=r.pathPrefix||"analysisOptions";if(e===void 0)return{ok:!0};if(!e||typeof e!="object"||Array.isArray(e))return u(t,"Data App analysis options must be an object.");const i=e,o={};if(i.chartTitle!==void 0){if(typeof i.chartTitle!="string")return u(`${t}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');o.chartTitle=i.chartTitle}if(i.chartType!==void 0){if(typeof i.chartType!="string")return u(`${t}.chartType`,'Data App analysis option "chartType" must be a string.');o.chartType=i.chartType}if(i.driverMode!==void 0){if(!ce(i.driverMode))return u(`${t}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');o.driverMode=i.driverMode}if(i.includePopulation!==void 0){if(typeof i.includePopulation!="boolean")return u(`${t}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');o.includePopulation=i.includePopulation}if(i.calendarContext!==void 0){const n=ye(i.calendarContext,{pathPrefix:`${t}.calendarContext`,validateTimezone:r.validateTimezone});if(!n.ok)return n;o.calendarContext=n.calendarContext}return{ok:!0,analysisOptions:o}}function ue(e){const r=e.queries.map((o,n)=>fe(o,n,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),t=r.flatMap(o=>o.diagnostics),i=r.map(o=>o.executionResult);return{ok:t.every(o=>o.severity!=="error"),diagnostics:t,queries:r,intents:r.flatMap(o=>o.intent?[o.intent]:[]),executionResults:i}}function fe(e,r,t){const i=`queries.${r}`;try{const o=pe(e),n=xe(e,o),s=x.validateSemaphorAnalyticsIntent(o),d=[...ke({querySpec:e,queryId:n,intent:o,pathPrefix:i}),...s.errors.map(m=>w(m,{queryHook:e.queryHook,queryId:n,pathPrefix:i,severity:"error",intent:o})),...s.warnings.map(m=>w(m,{queryHook:e.queryHook,queryId:n,pathPrefix:i,severity:"warning",intent:o})),...ge({querySpec:e,queryId:n,intent:o,pathPrefix:i,fieldCatalogs:t.fieldCatalogs,requireFieldCatalog:t.requireFieldCatalog}),...Se({querySpec:e,queryId:n,intent:o,pathPrefix:i,validateTimezone:t.validateTimezone})],l=Fe(s,d);return{queryHook:e.queryHook,queryId:n,intent:o,diagnostics:d,executionResult:F({intent:o,validation:l,diagnostics:d})}}catch(o){const n={severity:"error",code:"invalid_query_spec",message:o instanceof Error?o.message:String(o),path:i,queryHook:e.queryHook,queryId:N(e.spec)},s=K([n]);return{queryHook:e.queryHook,queryId:n.queryId,diagnostics:[n],executionResult:F({validation:s,diagnostics:[n]})}}}function u(e,r){return{ok:!1,issues:[{code:"invalid_analysis_option",message:r,path:e}]}}function Q(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 me(e){return e.trim().length>0&&!Number.isNaN(Date.parse(e))}function ye(e,r){var l;if(!e||typeof e!="object"||Array.isArray(e))return u(r.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const t=e,i=t.tz,o=t.weekStart,n=t.anchor,s=n&&typeof n=="object"&&!Array.isArray(n)?n.iso:void 0,d=typeof i=="string"?((l=r.validateTimezone)==null?void 0:l.call(r,i))??i:null;return d?typeof o!="number"||!Number.isInteger(o)||o<0||o>6?u(`${r.pathPrefix}.weekStart`,'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'):n!=="now"&&!(typeof s=="string"&&me(s))?u(`${r.pathPrefix}.anchor`,'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'):{ok:!0,calendarContext:{tz:d,weekStart:o,anchor:n}}:u(`${r.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.')}function pe(e){return he(e.spec)}function he(e){if(!Q(e))throw new Error("useSemaphorQuery spec must be an object.");if(e.queryKind==="metric")return S(e);if(e.queryKind==="analysis")return R(e);if(e.queryKind==="records")return H(e);if(e.queryKind==="sql")return P(e);if(e.queryKind==="matrix")return B(e);if(e.queryKind==="inputOptions")return T(e);throw new Error("useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, sql, or matrix.")}function ge(e){if(e.intent.kind==="sql")return[];if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const r=Ae(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 t=ve({...e,catalog:r}),i={...r,fields:[...r.fields,...$e(e.intent,r,e.intent.source)]};return[...t,...Ie({...e,catalog:i}),...qe({...e,catalog:i})]}function ve(e){const r=E(e.intent);if(r.length===0)return[];const t=[],i=new Set;return r.forEach((o,n)=>{const s=`${e.pathPrefix}.spec.derivedFields.${n}`,d=$(o.name);d&&(i.has(d)&&t.push({severity:"error",code:"duplicate_derived_field",message:`Derived field "${o.name}" is declared more than once.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}),i.add(d),e.catalog.fields.some(l=>$(l.name)===d)&&t.push({severity:"error",code:"derived_field_name_collision",message:`Derived field "${o.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(o.inputs||{}).forEach(([l,m])=>{const f=Me(m);if(!f)return;const v=y(f,e.intent.source);if(!c.semaphorSourcesReferToSameDataset(v,e.intent.source)){t.push({severity:"error",code:"unsupported_derived_field_source",message:`Derived field "${o.name}" input "${l}" references a different Semaphor source. App-local derived fields must use fields from the query source.`,path:`${s}.inputs.${l}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:v,field:f});return}b(e.catalog,f,e.intent.source)||t.push({severity:"error",code:"missing_field",message:`Derived field "${o.name}" input "${l}" references field "${f.name}", which is not visible on the selected Semaphor source.`,path:`${s}.inputs.${l}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:v,field:f})})}),t}function Ie(e){return be(e.intent).flatMap(({field:r,path:t})=>b(e.catalog,r,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Field "${r.name}" is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.${t}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:y(r,e.intent.source),field:r}])}function qe(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((t,i)=>{if(!t.field)return[];const o=y(t.field,e.intent.source);return c.semaphorSourcesReferToSameDataset(o,e.intent.source)?b(e.catalog,t.field,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Input "${t.inputId}" references field "${t.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${i}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:o,field:t.field}]:[{severity:"error",code:"unsupported_input_filter_composition",message:`Input "${t.inputId}" filters a different Semaphor source than the query. Cross-source Data App inputs are not supported yet.`,path:`${e.pathPrefix}.spec.inputs.${i}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:o,field:t.field}]})}function Se(e){if(e.querySpec.spec.queryKind!=="analysis")return[];const r=j(e.querySpec.spec,{pathPrefix:`${e.pathPrefix}.spec`,validateTimezone:e.validateTimezone});return r.ok?[]:r.issues.map(t=>({severity:"error",code:t.code,message:t.message,path:t.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"?[]:Q(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 be(e){return e.kind==="metric"?[...e.metrics.map((r,t)=>({field:r,path:`spec.metrics.${t}`})),...e.primaryMetric?[{field:e.primaryMetric,path:"spec.primaryMetric"}]:[],...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...(e.dimensions||[]).map((r,t)=>({field:r,path:`spec.dimensions.${t}`})),...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:e.kind==="records"?[...e.fields.map((r,t)=>({field:r,path:`spec.fields.${t}`})),...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:e.kind==="inputOptions"?[{field:e.field,path:"spec.field"}]:e.kind==="matrix"?[...e.rows.map((r,t)=>({field:r.field,path:`spec.rows.${t}.field`})),...e.rows.flatMap((r,t)=>{var i;return((i=r.sortBy)==null?void 0:i.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.rows.${t}.sortBy.by.field`}]:[]}),...(e.columns||[]).map((r,t)=>({field:r.field,path:`spec.columns.${t}.field`})),...(e.columns||[]).flatMap((r,t)=>{var i;return((i=r.sortBy)==null?void 0:i.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.columns.${t}.sortBy.by.field`}]:[]}),...e.values.map((r,t)=>({field:r.field,path:`spec.values.${t}.field`})),...(e.sort||[]).flatMap((r,t)=>r.by.kind==="field"?[{field:r.by.field,path:`spec.sort.${t}.by.field`}]:[]),...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:[]}function Ae(e,r){return e.find(t=>q(t,r))}function b(e,r,t){const i=y(r,t);if(q(e,i))return e.fields.find(o=>_e(o,r)&&q(e,y(o,e.source)))}function E(e){return!("derivedFields"in e)||!Array.isArray(e.derivedFields)?[]:e.derivedFields}function $e(e,r,t){return E(e).map(i=>({name:i.name,label:i.label,role:we(i.resultRole),dataType:i.dataType,source:r.source||t,...i.defaultAggregate?{aggregate:i.defaultAggregate}:{}}))}function we(e){return e==="measure"?"measure":e==="date"?"date":e==="id"?"id":"dimension"}function Me(e){if(!e||typeof e!="object")return;const r=e;return r.field||r.metric||r.dimension}function $(e){return V.normalizeAnalyticsCatalogName(e)}function q(e,r){return[e.source,...e.sourceAliases||[]].some(t=>c.semaphorSourcesReferToSameDataset(t,r))}function y(e,r){return e.source||r}function _e(e,r){return!!(e.name&&r.name&&e.name===r.name)}function w(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 Fe(e,r){const t=K(r);return{ok:t.ok&&e.ok,errors:_([...e.errors,...t.errors]),warnings:_([...e.warnings,...t.warnings]),repairHints:[...e.repairHints,...t.repairHints]}}function K(e){const r=e.filter(i=>i.severity==="error").map(M),t=e.filter(i=>i.severity==="warning").map(M);return{ok:r.length===0,errors:r,warnings:t,repairHints:r.map(i=>{var o,n;return{code:i.code,message:i.message,fieldRole:i.fieldRole,invalidField:(o=i.repairHint)==null?void 0:o.invalidField,recommendedNextStep:((n=i.repairHint)==null?void 0:n.recommendedNextStep)||"Update the Data App SDK query spec to use visible Semaphor source and field refs."}})}}function M(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 _(e){const r=new Set;return e.filter(t=>{const i=`${t.code}:${t.path||""}:${t.message}`;return r.has(i)?!1:(r.add(i),!0)})}function F(e){var t,i;const r=e.diagnostics.filter(o=>o.severity==="error");return{intentId:(t=e.intent)==null?void 0:t.id,status:r.length?"failed":"answered",resultShape:(i=e.intent)==null?void 0:i.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(o=>o.code==="missing_field").flatMap(o=>{var n;return(n=o.field)!=null&&n.name?[o.field.name]:[]}),warnings:e.diagnostics.filter(o=>o.severity==="warning").map(o=>o.message),metadata:{validationKind:"data_app_sdk_query_spec"}}}function xe(e,r){return r.id||N(e.spec)}function N(e){if(!e||typeof e!="object"||!("id"in e))return;const r=e.id;return typeof r=="string"&&r.trim()?r:void 0}exports.hasSemaphorInputValue=I;exports.normalizeSemaphorAnalysisQueryOptions=j;exports.normalizeSemaphorInputOptions=ae;exports.toSemaphorActiveInputSnapshots=ne;exports.toSemaphorAnalysisIntent=R;exports.toSemaphorAnalysisQueryOptions=W;exports.toSemaphorInputBinding=D;exports.toSemaphorInputBindings=oe;exports.toSemaphorInputOptionsIntent=T;exports.toSemaphorInputSnapshots=z;exports.toSemaphorInputSpec=k;exports.toSemaphorMatrixIntent=B;exports.toSemaphorMetricIntent=S;exports.toSemaphorRecordsIntent=H;exports.toSemaphorSqlIntent=P;exports.validateSemaphorDataAppQuerySpecs=ue;
|
|
1
|
+
"use strict";const x=require("./validators-jpoYhpHh.js"),V=require("./catalog-field-grounding-Du6mKDcF.js"),c=require("./source-identity-C-xaeE_I.js");function S(e){var t,i;const r=G(e);return{version:1,kind:"metric",id:e.id,label:e.label,source:g(e),metrics:r,primaryMetric:L(e,r),dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,dimensions:(t=e.dimensions)==null?void 0:t.map(o=>a(o,"dimension")),comparison:le(e.comparison),orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:p(e.inputs),limit:e.limit,...(i=e.derivedFields)!=null&&i.length?{derivedFields:e.derivedFields}:{}}}function R(e){var t;return{...S(e),...e.timeWindow?{timeWindow:e.timeWindow}:{},...(t=e.filters)!=null&&t.length?{filters:e.filters}:{},...e.analysis?{analysis:e.analysis}:{}}}function W(e){return{...e.chartTitle?{chartTitle:e.chartTitle}:{},...e.chartType?{chartType:e.chartType}:{},...e.driverMode?{driverMode:e.driverMode}:{},...e.includePopulation!==void 0?{includePopulation:e.includePopulation}:{},...e.calendarContext?{calendarContext:e.calendarContext}:{}}}function L(e,r){if(!e.primaryMetric)return r[0]||{name:"",role:"measure"};const t=a(e.primaryMetric,"measure"),i=Y(t,r),o=i.length===1?i[0]:void 0;return o?C(t,o):t}function G(e){const r=[];for(const t of e.metrics.map(i=>a(i,"measure"))){if(!t.name)continue;const i=r.findIndex(o=>U(o,t));if(i===-1){r.push(t);continue}r[i]=C(r[i],t)}return r}function U(e,r){return c.semaphorFieldRefsMatch(e,r)&&h(e)===h(r)}function J(e,r){return h(r)===h(e)}function X(e,r){return r.name!==e.name||e.source&&!c.semaphorFieldRefsMatch(r,e)?!1:J(e,r)}function Y(e,r){const t=r.filter(i=>X(e,i));return e.aggregate!==void 0,t}function h(e){return(e.aggregate||"SUM").toUpperCase()}function C(e,r){if(e.aggregate&&r.aggregate&&e.aggregate!==r.aggregate)throw new Error(`Metric "${e.name}" was requested with conflicting aggregate semantics: ${e.aggregate} and ${r.aggregate}.`);return{...c.preferSemaphorFieldRefMetadata(e,r),aggregate:e.aggregate||r.aggregate}}function H(e){var t,i;if("sort"in e)throw new Error("semaphor.records supports orderBy for a single deterministic sort. Multiple sort clauses are not supported by the analytics protocol yet.");if(!de(e))throw new Error("semaphor.records needs at least one field.");const r=Z(e.fields);return{version:1,kind:"records",id:e.id,label:e.label,source:g(e),fields:r,dateField:e.dateField?a(e.dateField,"date"):void 0,timeGrain:e.timeGrain,...e.timeWindow?{timeWindow:e.timeWindow}:{},...(t=e.filters)!=null&&t.length?{filters:e.filters}:{},orderBy:e.orderBy?{field:a(e.orderBy.field),direction:e.orderBy.direction}:void 0,inputs:p(e.inputs),limit:e.limit,...e.pagination?{pagination:e.pagination}:{},...(i=e.derivedFields)!=null&&i.length?{derivedFields:e.derivedFields}:{}}}function Z(e){return e.map(r=>{const t=a(r);if(!t.role)throw new Error(`semaphor.records field "${t.name}" needs an explicit role.`);return t})}function T(e){var r;return{version:1,kind:"inputOptions",id:e.id,label:e.label,source:g(e),field:a(e.field,"dimension"),search:e.search,limit:e.limit,...(r=e.derivedFields)!=null&&r.length?{derivedFields:e.derivedFields}:{}}}function P(e){var r;return{version:1,kind:"sql",id:e.id,label:e.label,source:e.source,sql:e.sql,...e.defaultParameters?{defaultParameters:e.defaultParameters}:{},...e.pythonCode?{pythonCode:e.pythonCode}:{},...(r=e.fields)!=null&&r.length?{fields:e.fields.map(t=>a(t))}:{},inputs:p(e.inputs),limit:e.limit,...e.pagination?{pagination:e.pagination}:{},rationale:e.rationale}}function B(e){var r,t;return{version:1,kind:"matrix",id:e.id,label:e.label,source:g(e),rows:e.rows.map(i=>A(i,"dimension")),...e.columns?{columns:e.columns.map(i=>A(i,"dimension"))}:{},values:e.values.map(ee),...(r=e.filters)!=null&&r.length?{filters:e.filters}:{},inputs:p(e.inputs),...e.totals?{totals:e.totals}:{},...(t=e.sort)!=null&&t.length?{sort:e.sort}:{},...e.expansion?{expansion:e.expansion}:{},...e.layout?{layout:e.layout}:{},...e.displayLimits?{displayLimits:e.displayLimits}:{}}}function A(e,r){return re(e)?{...e,field:a(e.field,r)}:{field:a(e,r)}}function ee(e){return te(e)?{...e,field:a(e.field,"measure")}:{field:a(e,"measure"),aggregate:e.aggregate}}function re(e){return"field"in e}function te(e){return"field"in e}function D(e){if("toAnalyticsInput"in e){const n=e.toAnalyticsInput();return{inputId:n.inputId,kind:n.kind,...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{}}}if("id"in e){const n=k(e);return{inputId:n.inputId,kind:n.kind,...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{}}}const r="kind"in e?e.kind:void 0,t="operator"in e?O(e.operator,e.inputId):void 0,i="controlRole"in e?e.controlRole:"role"in e?e.role:void 0,o=ie(i)?i:void 0;return{inputId:e.inputId,...r?{kind:r}:{},...o?{controlRole:o}:{},...t?{operator:t}:{},...e.field?{field:e.field}:{}}}function ie(e){return e==="grain"||e==="metric"||e==="dimension"||e==="aggregation"||e==="sqlParam"}function oe(e){const r=p(e);return r.length>0?r:void 0}function z(e){return(e||[]).map(se)}function ne(e){return z(e).filter(r=>r.isActive)}function k(e){if(e.kind==="filter"){const r=O(e.operator,e.id);return{inputId:e.id,kind:e.kind,label:e.label,field:a(e.field,"dimension"),operator:r||"in"}}return{inputId:e.id,kind:e.kind,label:e.label,controlRole:e.role}}function ae(e=[]){return e.map(r=>typeof r=="object"?r:{label:String(r),value:r})}function I(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e=="string"?e.trim().length>0:!0}function se(e){if("toAnalyticsInput"in e)return e.toAnalyticsInput();if("kind"in e&&"isActive"in e)return e;if("id"in e){const r=k(e),t=Object.prototype.hasOwnProperty.call(e,"value")?e.value:e.defaultValue;return{inputId:r.inputId,kind:r.kind,label:r.label,...r.field?{field:r.field}:{},...r.operator?{operator:r.operator}:{},...r.controlRole?{controlRole:r.controlRole}:{},value:t,isActive:I(t)}}return{...e,kind:"filter",isActive:I(e.value),value:e.value}}function g(e){return e.source}function de(e){var r;return!!((r=e.fields)!=null&&r.length)}function a(e,r){return{...e,role:e.role||r}}function p(e){return(e||[]).map(D)}function le(e){if(e)return e}function O(e,r){if(e===void 0)return;const t=x.normalizeSemaphorInputOperator(e);if(!t)throw new Error(`useSemaphorInput "${r}" uses unsupported filter operator "${e}".`);return t}function j(e,r={}){const t=r.pathPrefix||"analysisOptions";if(e===void 0)return{ok:!0};if(!e||typeof e!="object"||Array.isArray(e))return u(t,"Data App analysis options must be an object.");const i=e,o={};if(i.chartTitle!==void 0){if(typeof i.chartTitle!="string")return u(`${t}.chartTitle`,'Data App analysis option "chartTitle" must be a string.');o.chartTitle=i.chartTitle}if(i.chartType!==void 0){if(typeof i.chartType!="string")return u(`${t}.chartType`,'Data App analysis option "chartType" must be a string.');o.chartType=i.chartType}if(i.driverMode!==void 0){if(!ce(i.driverMode))return u(`${t}.driverMode`,'Data App analysis option "driverMode" must be absolute_delta, largest_negative, largest_positive, positive_and_negative, or all.');o.driverMode=i.driverMode}if(i.includePopulation!==void 0){if(typeof i.includePopulation!="boolean")return u(`${t}.includePopulation`,'Data App analysis option "includePopulation" must be a boolean.');o.includePopulation=i.includePopulation}if(i.calendarContext!==void 0){const n=ye(i.calendarContext,{pathPrefix:`${t}.calendarContext`,validateTimezone:r.validateTimezone});if(!n.ok)return n;o.calendarContext=n.calendarContext}return{ok:!0,analysisOptions:o}}function ue(e){const r=e.queries.map((o,n)=>fe(o,n,{fieldCatalogs:e.fieldCatalogs||[],requireFieldCatalog:!!e.requireFieldCatalog,validateTimezone:e.validateTimezone})),t=r.flatMap(o=>o.diagnostics),i=r.map(o=>o.executionResult);return{ok:t.every(o=>o.severity!=="error"),diagnostics:t,queries:r,intents:r.flatMap(o=>o.intent?[o.intent]:[]),executionResults:i}}function fe(e,r,t){const i=`queries.${r}`;try{const o=pe(e),n=xe(e,o),s=x.validateSemaphorAnalyticsIntent(o),d=[...ke({querySpec:e,queryId:n,intent:o,pathPrefix:i}),...s.errors.map(m=>w(m,{queryHook:e.queryHook,queryId:n,pathPrefix:i,severity:"error",intent:o})),...s.warnings.map(m=>w(m,{queryHook:e.queryHook,queryId:n,pathPrefix:i,severity:"warning",intent:o})),...ge({querySpec:e,queryId:n,intent:o,pathPrefix:i,fieldCatalogs:t.fieldCatalogs,requireFieldCatalog:t.requireFieldCatalog}),...Se({querySpec:e,queryId:n,intent:o,pathPrefix:i,validateTimezone:t.validateTimezone})],l=Fe(s,d);return{queryHook:e.queryHook,queryId:n,intent:o,diagnostics:d,executionResult:F({intent:o,validation:l,diagnostics:d})}}catch(o){const n={severity:"error",code:"invalid_query_spec",message:o instanceof Error?o.message:String(o),path:i,queryHook:e.queryHook,queryId:N(e.spec)},s=K([n]);return{queryHook:e.queryHook,queryId:n.queryId,diagnostics:[n],executionResult:F({validation:s,diagnostics:[n]})}}}function u(e,r){return{ok:!1,issues:[{code:"invalid_analysis_option",message:r,path:e}]}}function Q(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 me(e){return e.trim().length>0&&!Number.isNaN(Date.parse(e))}function ye(e,r){var l;if(!e||typeof e!="object"||Array.isArray(e))return u(r.pathPrefix,'Data App analysis option "calendarContext" must be an object.');const t=e,i=t.tz,o=t.weekStart,n=t.anchor,s=n&&typeof n=="object"&&!Array.isArray(n)?n.iso:void 0,d=typeof i=="string"?((l=r.validateTimezone)==null?void 0:l.call(r,i))??i:null;return d?typeof o!="number"||!Number.isInteger(o)||o<0||o>6?u(`${r.pathPrefix}.weekStart`,'Data App analysis option "calendarContext.weekStart" must be an integer from 0 to 6.'):n!=="now"&&!(typeof s=="string"&&me(s))?u(`${r.pathPrefix}.anchor`,'Data App analysis option "calendarContext.anchor" must be "now" or an object with a valid iso string.'):{ok:!0,calendarContext:{tz:d,weekStart:o,anchor:n}}:u(`${r.pathPrefix}.tz`,'Data App analysis option "calendarContext.tz" must be a valid timezone string.')}function pe(e){return he(e.spec)}function he(e){if(!Q(e))throw new Error("useSemaphorQuery spec must be an object.");if(e.queryKind==="metric")return S(e);if(e.queryKind==="analysis")return R(e);if(e.queryKind==="records")return H(e);if(e.queryKind==="sql")return P(e);if(e.queryKind==="matrix")return B(e);if(e.queryKind==="inputOptions")return T(e);throw new Error("useSemaphorQuery spec.queryKind must be metric, analysis, records, inputOptions, sql, or matrix.")}function ge(e){if(e.intent.kind==="sql")return[];if(e.fieldCatalogs.length===0&&!e.requireFieldCatalog)return[];const r=Ae(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 t=ve({...e,catalog:r}),i={...r,fields:[...r.fields,...$e(e.intent,r,e.intent.source)]};return[...t,...Ie({...e,catalog:i}),...qe({...e,catalog:i})]}function ve(e){const r=E(e.intent);if(r.length===0)return[];const t=[],i=new Set;return r.forEach((o,n)=>{const s=`${e.pathPrefix}.spec.derivedFields.${n}`,d=$(o.name);d&&(i.has(d)&&t.push({severity:"error",code:"duplicate_derived_field",message:`Derived field "${o.name}" is declared more than once.`,path:`${s}.name`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:e.intent.source}),i.add(d),e.catalog.fields.some(l=>$(l.name)===d)&&t.push({severity:"error",code:"derived_field_name_collision",message:`Derived field "${o.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(o.inputs||{}).forEach(([l,m])=>{const f=Me(m);if(!f)return;const v=y(f,e.intent.source);if(!c.semaphorSourcesReferToSameDataset(v,e.intent.source)){t.push({severity:"error",code:"unsupported_derived_field_source",message:`Derived field "${o.name}" input "${l}" references a different Semaphor source. App-local derived fields must use fields from the query source.`,path:`${s}.inputs.${l}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:v,field:f});return}b(e.catalog,f,e.intent.source)||t.push({severity:"error",code:"missing_field",message:`Derived field "${o.name}" input "${l}" references field "${f.name}", which is not visible on the selected Semaphor source.`,path:`${s}.inputs.${l}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:v,field:f})})}),t}function Ie(e){return be(e.intent).flatMap(({field:r,path:t})=>b(e.catalog,r,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Field "${r.name}" is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.${t}`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:y(r,e.intent.source),field:r}])}function qe(e){return("inputs"in e.intent?e.intent.inputs||[]:[]).flatMap((t,i)=>{if(!t.field)return[];const o=y(t.field,e.intent.source);return c.semaphorSourcesReferToSameDataset(o,e.intent.source)?b(e.catalog,t.field,e.intent.source)?[]:[{severity:"error",code:"missing_field",message:`Input "${t.inputId}" references field "${t.field.name}", which is not visible on the selected Semaphor source.`,path:`${e.pathPrefix}.spec.inputs.${i}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:o,field:t.field}]:[{severity:"error",code:"unsupported_input_filter_composition",message:`Input "${t.inputId}" filters a different Semaphor source than the query. Cross-source Data App inputs are not supported yet.`,path:`${e.pathPrefix}.spec.inputs.${i}.field`,queryHook:e.querySpec.queryHook,queryId:e.queryId,intentId:e.intent.id,source:o,field:t.field}]})}function Se(e){if(e.querySpec.spec.queryKind!=="analysis")return[];const r=j(e.querySpec.spec,{pathPrefix:`${e.pathPrefix}.spec`,validateTimezone:e.validateTimezone});return r.ok?[]:r.issues.map(t=>({severity:"error",code:t.code,message:t.message,path:t.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"?[]:Q(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 be(e){return e.kind==="metric"?[...e.metrics.map((r,t)=>({field:r,path:`spec.metrics.${t}`})),...e.primaryMetric?[{field:e.primaryMetric,path:"spec.primaryMetric"}]:[],...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...(e.dimensions||[]).map((r,t)=>({field:r,path:`spec.dimensions.${t}`})),...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:e.kind==="records"?[...e.fields.map((r,t)=>({field:r,path:`spec.fields.${t}`})),...e.dateField?[{field:e.dateField,path:"spec.dateField"}]:[],...e.orderBy?[{field:e.orderBy.field,path:"spec.orderBy.field"}]:[],...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:e.kind==="inputOptions"?[{field:e.field,path:"spec.field"}]:e.kind==="matrix"?[...e.rows.map((r,t)=>({field:r.field,path:`spec.rows.${t}.field`})),...e.rows.flatMap((r,t)=>{var i;return((i=r.sortBy)==null?void 0:i.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.rows.${t}.sortBy.by.field`}]:[]}),...(e.columns||[]).map((r,t)=>({field:r.field,path:`spec.columns.${t}.field`})),...(e.columns||[]).flatMap((r,t)=>{var i;return((i=r.sortBy)==null?void 0:i.by.kind)==="field"?[{field:r.sortBy.by.field,path:`spec.columns.${t}.sortBy.by.field`}]:[]}),...e.values.map((r,t)=>({field:r.field,path:`spec.values.${t}.field`})),...(e.sort||[]).flatMap((r,t)=>r.by.kind==="field"?[{field:r.by.field,path:`spec.sort.${t}.by.field`}]:[]),...(e.filters||[]).map((r,t)=>({field:r.field,path:`spec.filters.${t}.field`}))]:[]}function Ae(e,r){return e.find(t=>q(t,r))}function b(e,r,t){const i=y(r,t);if(q(e,i))return e.fields.find(o=>_e(o,r)&&q(e,y(o,e.source)))}function E(e){return!("derivedFields"in e)||!Array.isArray(e.derivedFields)?[]:e.derivedFields}function $e(e,r,t){return E(e).map(i=>({name:i.name,label:i.label,role:we(i.resultRole),dataType:i.dataType,source:r.source||t,...i.defaultAggregate?{aggregate:i.defaultAggregate}:{}}))}function we(e){return e==="measure"?"measure":e==="date"?"date":e==="id"?"id":"dimension"}function Me(e){if(!e||typeof e!="object")return;const r=e;return r.field||r.metric||r.dimension}function $(e){return V.normalizeAnalyticsCatalogName(e)}function q(e,r){return[e.source,...e.sourceAliases||[]].some(t=>c.semaphorSourcesReferToSameDataset(t,r))}function y(e,r){return e.source||r}function _e(e,r){return!!(e.name&&r.name&&e.name===r.name)}function w(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 Fe(e,r){const t=K(r);return{ok:t.ok&&e.ok,errors:_([...e.errors,...t.errors]),warnings:_([...e.warnings,...t.warnings]),repairHints:[...e.repairHints,...t.repairHints]}}function K(e){const r=e.filter(i=>i.severity==="error").map(M),t=e.filter(i=>i.severity==="warning").map(M);return{ok:r.length===0,errors:r,warnings:t,repairHints:r.map(i=>{var o,n;return{code:i.code,message:i.message,fieldRole:i.fieldRole,invalidField:(o=i.repairHint)==null?void 0:o.invalidField,recommendedNextStep:((n=i.repairHint)==null?void 0:n.recommendedNextStep)||"Update the Data App SDK query spec to use visible Semaphor source and field refs."}})}}function M(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 _(e){const r=new Set;return e.filter(t=>{const i=`${t.code}:${t.path||""}:${t.message}`;return r.has(i)?!1:(r.add(i),!0)})}function F(e){var t,i;const r=e.diagnostics.filter(o=>o.severity==="error");return{intentId:(t=e.intent)==null?void 0:t.id,status:r.length?"failed":"answered",resultShape:(i=e.intent)==null?void 0:i.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(o=>o.code==="missing_field").flatMap(o=>{var n;return(n=o.field)!=null&&n.name?[o.field.name]:[]}),warnings:e.diagnostics.filter(o=>o.severity==="warning").map(o=>o.message),metadata:{validationKind:"data_app_sdk_query_spec"}}}function xe(e,r){return r.id||N(e.spec)}function N(e){if(!e||typeof e!="object"||!("id"in e))return;const r=e.id;return typeof r=="string"&&r.trim()?r:void 0}exports.hasSemaphorInputValue=I;exports.normalizeSemaphorAnalysisQueryOptions=j;exports.normalizeSemaphorInputOptions=ae;exports.toSemaphorActiveInputSnapshots=ne;exports.toSemaphorAnalysisIntent=R;exports.toSemaphorAnalysisQueryOptions=W;exports.toSemaphorInputBinding=D;exports.toSemaphorInputBindings=oe;exports.toSemaphorInputOptionsIntent=T;exports.toSemaphorInputSnapshots=z;exports.toSemaphorInputSpec=k;exports.toSemaphorMatrixIntent=B;exports.toSemaphorMetricIntent=S;exports.toSemaphorRecordsIntent=H;exports.toSemaphorSqlIntent=P;exports.validateSemaphorDataAppQuerySpecs=ue;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as z, c as D } from "./validators-
|
|
1
|
+
import { n as z, c as D } from "./validators-CtNmgsvG.js";
|
|
2
2
|
import { n as O } from "./catalog-field-grounding-DoEBOXQd.js";
|
|
3
3
|
import { b as M, c as j, a as q } from "./source-identity-Dj3dryN9.js";
|
|
4
4
|
function x(e) {
|