react-semaphor 0.1.375 → 0.1.377

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +47 -43
  3. package/dist/brand-studio/index.cjs +4 -9
  4. package/dist/brand-studio/index.js +98 -108
  5. package/dist/chunks/{braces-C3-w6xDL.js → braces-C2uBgj3t.js} +1 -1
  6. package/dist/chunks/{braces-C8QqW4wu.js → braces-CkXyWzRh.js} +1 -1
  7. package/dist/chunks/{calendar-preferences-dialog-DXgi7q5u.js → calendar-preferences-dialog-C55VOTIy.js} +6 -5
  8. package/dist/chunks/calendar-preferences-dialog-DAukJOaP.js +1 -0
  9. package/dist/chunks/catalog-field-grounding-BGW0hnB9.js +1 -0
  10. package/dist/chunks/catalog-field-grounding-DHXEI7cW.js +199 -0
  11. package/dist/chunks/{chevrons-up-down-DSvLu4Ye.js → chevrons-up-down-BnzChFLU.js} +1 -1
  12. package/dist/chunks/{chevrons-up-down-CnCSGY02.js → chevrons-up-down-W0nzHzx0.js} +1 -1
  13. package/dist/chunks/{dashboard-briefing-launcher-Jwbmrcl_.js → dashboard-briefing-launcher-CUyeiL_T.js} +3141 -2372
  14. package/dist/chunks/dashboard-briefing-launcher-DMKfG_z3.js +111 -0
  15. package/dist/chunks/dashboard-controls-B4hxFc3Q.js +2279 -0
  16. package/dist/chunks/dashboard-controls-D4vI0wvU.js +52 -0
  17. package/dist/chunks/dashboard-json-DQnm6daE.js +1 -0
  18. package/dist/chunks/{dashboard-json-Cl1O3uh0.js → dashboard-json-pl1_mFqJ.js} +14 -13
  19. package/dist/chunks/{edit-dashboard-visual-B_0sbc43.js → edit-dashboard-visual-CF4aSsav.js} +4729 -4645
  20. package/dist/chunks/edit-dashboard-visual-CjTXY51a.js +178 -0
  21. package/dist/chunks/{index-BIks0ktd.js → index-B2kPleRS.js} +186 -181
  22. package/dist/chunks/{index-BSkBy5cH.js → index-Bn866BBY.js} +22824 -22664
  23. package/dist/chunks/layout-grid-BFmJ7vmH.js +16 -0
  24. package/dist/chunks/layout-grid-CTOW9oTg.js +6 -0
  25. package/dist/chunks/{palette-DUGktM-M.js → palette-DrhPeer-.js} +1 -1
  26. package/dist/chunks/{palette-D-f4-82S.js → palette-OFaniMPn.js} +1 -1
  27. package/dist/chunks/{save-D3YYinDz.js → save-BxWBiQv1.js} +1 -1
  28. package/dist/chunks/{save-kkBEBeLg.js → save-Dh6gSC4x.js} +1 -1
  29. package/dist/chunks/{switch-Dkx2qEOr.js → switch-C-fGjxjY.js} +2002 -1983
  30. package/dist/chunks/switch-D5xopzFD.js +168 -0
  31. package/dist/chunks/use-create-flow-overlay-state-Dg2ffpCE.js +21 -0
  32. package/dist/chunks/use-create-flow-overlay-state-DrKP0jWE.js +1968 -0
  33. package/dist/chunks/{validation-1V7bWmYw.js → validation-BHFaWDU-.js} +1 -1
  34. package/dist/chunks/{validation-DlrTIf1N.js → validation-bMedDBOo.js} +1 -1
  35. package/dist/dashboard/index.cjs +1 -1
  36. package/dist/dashboard/index.js +1 -1
  37. package/dist/dashboard-authoring/index.cjs +1 -1
  38. package/dist/dashboard-authoring/index.js +1 -1
  39. package/dist/data-app-builder/index.cjs +18 -13
  40. package/dist/data-app-builder/index.js +141 -131
  41. package/dist/data-app-sdk/index.cjs +1 -1
  42. package/dist/data-app-sdk/index.js +22 -21
  43. package/dist/data-app-sdk-validation/index.cjs +1 -1
  44. package/dist/data-app-sdk-validation/index.js +2 -2
  45. package/dist/index.cjs +1 -1
  46. package/dist/index.js +151 -151
  47. package/dist/style.css +1 -1
  48. package/dist/surfboard/index.cjs +1 -1
  49. package/dist/surfboard/index.js +2 -2
  50. package/dist/types/analytics-protocol.d.ts +84 -0
  51. package/dist/types/main.d.ts +8 -12
  52. package/package.json +1 -1
  53. package/dist/chunks/calendar-preferences-dialog-CsRzDpDs.js +0 -1
  54. package/dist/chunks/catalog-field-grounding-DoEBOXQd.js +0 -100
  55. package/dist/chunks/catalog-field-grounding-Du6mKDcF.js +0 -1
  56. package/dist/chunks/dashboard-briefing-launcher-C-G6vQTL.js +0 -106
  57. package/dist/chunks/dashboard-controls-DzGGNQxv.js +0 -2269
  58. package/dist/chunks/dashboard-controls-p7VKzWSb.js +0 -57
  59. package/dist/chunks/dashboard-json-CvPhMpbM.js +0 -1
  60. package/dist/chunks/edit-dashboard-visual-CSrdS10O.js +0 -178
  61. package/dist/chunks/resource-management-panel-IHbUOh2g.js +0 -6
  62. package/dist/chunks/resource-management-panel-tFjbtgPw.js +0 -1018
  63. package/dist/chunks/switch-fIkmwzUt.js +0 -168
  64. package/dist/chunks/use-create-flow-overlay-state-D-yGZTR3.js +0 -1647
  65. package/dist/chunks/use-create-flow-overlay-state-DbaUD5xc.js +0 -26
  66. package/dist/chunks/use-visual-utils-B5hwU_av.js +0 -1
  67. package/dist/chunks/use-visual-utils-Dj82r7DA.js +0 -340
@@ -1 +1 @@
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
+ "use strict";const x=require("./validators-jpoYhpHh.js"),V=require("./catalog-field-grounding-BGW0hnB9.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,5 +1,5 @@
1
1
  import { n as z, c as D } from "./validators-CtNmgsvG.js";
2
- import { n as O } from "./catalog-field-grounding-DoEBOXQd.js";
2
+ import { n as O } from "./catalog-field-grounding-DHXEI7cW.js";
3
3
  import { b as M, c as j, a as q } from "./source-identity-Dj3dryN9.js";
4
4
  function x(e) {
5
5
  var t, i;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-BIks0ktd.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-B2kPleRS.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as o } from "../chunks/index-BSkBy5cH.js";
1
+ import { D as o } from "../chunks/index-Bn866BBY.js";
2
2
  import { C as s, E as C } from "../chunks/common-types-4bjoIgvm.js";
3
3
  export {
4
4
  s as CONTROL_CARD_DEFAULT_VALUE,
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../chunks/contracts-CtB2VONT.js"),N=require("../chunks/source-identity-C-xaeE_I.js"),z=require("../chunks/validators-jpoYhpHh.js"),De=require("../chunks/catalog-field-grounding-Du6mKDcF.js");function _(e){return e&&typeof e=="object"?e:null}function D(e){return typeof e=="string"?e:null}function oe(e){var t,r,n;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((r=_(e))==null?void 0:r.kind)==="physical"||((n=_(e))==null?void 0:n.kind)==="sql")}function M(e){return oe(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function ve(e){return N.semaphorSourceIdentityKey(e)}function K(e,t){return N.semaphorSourcesReferToSameDataset(e,t)}function se(e,t){return N.preferSemaphorSourceMetadata(e,t)}function R(e){const t=[];for(const r of e){const n=t.findIndex(o=>K(o,r));n===-1?t.push(r):t[n]=se(t[n],r)}return t}function Ce(e){return R(e)[0]}function G(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!N.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function W(e){return M(e)?e:void 0}function ae(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(r=>(r==null?void 0:r.kind)==="semantic"&&N.semaphorSourcesReferToSameDataset(e,r)&&!!r.connectionId)}function S(e,t){const r=W(e==null?void 0:e.source);return r?G(r,t):void 0}function de({explicitSource:e,field:t,defaultSource:r,fallbackSources:n}){const o=[r,...n||[]],a=W(e),i=a?G(a,ae(a,o)):void 0;if(i)return i;if(e!==void 0)return;const d=S(t,r),s=d?G(d,ae(d,o)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return W(r)}function ke(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const r=S(e),n=S(t);return!r||!n?!0:K(r,n)}function C(e){var t;return D((t=_(e))==null?void 0:t.kind)}function ce(e){var t,r;return C(e)!=="semantic"?null:((r=D((t=_(e))==null?void 0:t.domainId))==null?void 0:r.trim())||null}function xe(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetName)}function Te(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetId)}function Fe(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.connectionId)}function Re(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.tableName)}function Ne(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.databaseName)||""}function Me(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.schemaName)||""}function le(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function ue({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const r=e.map(ce),n=new Set(r.filter(Boolean));return r.some(o=>!o)||n.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function E(e,t){if(!t)return!1;if(t.kind==="semantic"){const r=Te(e);return ce(e)===t.domainId?r&&t.datasetId?r===t.datasetId:xe(e)===t.datasetName:!1}return t.kind==="physical"?Fe(e)===t.connectionId&&Re(e)===t.tableName&&Ne(e)===(t.databaseName||"")&&Me(e)===(t.schemaName||""):!1}function $e(e,t){return e.find(r=>E(r,t))}function p(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function B(e){const t=new Set;for(const r of e){if(t.has(r))return r;t.add(r)}return null}function fe({card:e,datasets:t,errors:r}){if(e.type==="text")return;const n=le(e);if(!n){if(t.length<=1)return;r.push(p("missing_card_analytics_source","Multi-dataset dashboard cards must include analytics intent with a source so the materializer can choose the correct dataset.",e.id));return}t.some(o=>E(o,n))||r.push(p("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function P(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function H(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function ie(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Oe(e){var r;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...P([...H(e.metrics),e.primaryMetric,e.dateField,...H(e.dimensions),...ie(e.filters).map(n=>n.field)])):e.kind==="records"?t.push(...P([...H(e.fields),e.dateField,(r=e.orderBy)==null?void 0:r.field,...ie(e.filters).map(n=>n.field)])):e.kind==="inputOptions"?t.push(...P([e.field])):e.kind==="sql"&&t.push(...P(e.fields||[])),t}function pe({card:e,datasets:t,errors:r}){if(e.type!=="text"){for(const n of Oe(e.analyticsIntent))if(n&&!t.some(o=>E(o,n))){r.push(p("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function he({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const r=z.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!r.ok)for(const n of r.errors)t.push(p(n.code,n.path?`${n.path}: ${n.message}`:n.message,e.id))}function me({datasets:e,errors:t,requireAtLeastOne:r}){const n=ue({datasets:e,requireAtLeastOne:r});if(!n.ok){if(n.issue==="invalid_dataset_count"){t.push(p("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(p("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function ge(e){var f,g;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard plan version must be 1.")),(f=r.title)!=null&&f.trim()||t.push(p("missing_title","Dashboard plan needs a title."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.sheets)?r.sheets:[];me({datasets:o,errors:t,requireAtLeastOne:!0}),a.length!==1&&t.push(p("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const i=a[0];i&&i.kind!=="dashboard"&&t.push(p("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(i==null?void 0:i.cards)||[];d.length>v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS&&t.push(p("too_many_cards",`Generated dashboards can contain at most ${v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`));const s=B(d.map(l=>l.id));s&&t.push(p("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=B(d.map(l=>l.frameId));u&&t.push(p("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(g=l.title)!=null&&g.trim()||t.push(p("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&n.push(p("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),fe({card:l,datasets:o,errors:t}),he({card:l,errors:t}),pe({card:l,datasets:o,errors:t});const h=Array.isArray(r.filterInputs)?r.filterInputs:[],I=h.map(l=>l.id),A=B(I);A&&t.push(p("duplicate_input_id",`Duplicate dashboard input id: ${A}.`));const w=h.map(l=>l.variableName).filter(Boolean)||[],y=B(w);y&&t.push(p("duplicate_input_variable",`Duplicate dashboard input variable name: ${y}.`));const c=Array.isArray(r.calculatedFields)?r.calculatedFields:[];for(const l of c)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:n}}function be(e){var i;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard change plan version must be 1.")),(i=r.dashboardId)!=null&&i.trim()||t.push(p("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.operations)?r.operations:[];me({datasets:o,errors:t,requireAtLeastOne:!1});for(const d of a){if(d.kind==="unsupported"){n.push(p("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(fe({card:d.card,datasets:o,errors:t}),he({card:d.card,errors:t}),pe({card:d.card,datasets:o,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${d.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:n}}const Be={lg:48,md:36,sm:24,xs:12,xxs:6};function Pe(e,t){let r=0,n=0,o=0;return e.map(a=>{const i=Math.min(a.w,t);r>0&&r+i>t&&(r=0,n+=o,o=0);const d={i:a.frameId,x:r,y:n,w:i,h:a.h,minW:Math.min(a.minW,t),minH:a.minH,static:!1};return r+=i,o=Math.max(o,a.h),d})}function ze(e){const t=[...e].sort((s,u)=>s.priority-u.priority),r=t.filter(s=>s.role==="kpi"),n=t.filter(s=>s.role==="chart"),o=t.filter(s=>s.role==="table"),a=t.filter(s=>s.role==="text"),i=a.slice(0,1),d=a.slice(i.length);return{kpis:r,introText:i,charts:n,tables:o,supportingText:d}}function Ee(e,t,r){return t==="xxs"||t==="xs"?r:t==="sm"?Math.min(12,r):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function qe(e,t,r,n){return r==="xxs"||r==="xs"||r==="sm"||r==="md"||t===1||t%2===1&&e===0?n:n/2}function Ve(e){const{item:t,band:r,index:n,bandCount:o,breakpoint:a,columns:i}=e;return r==="kpi"?{...t,band:r,w:Ee(o,a,i),h:15,minW:Math.min(6,i),minH:12}:r==="table"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?34:38,minW:Math.min(12,i),minH:18}:r==="introText"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:r==="supportingText"?{...t,band:r,w:a==="lg"?i/2:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:{...t,band:r,w:qe(n,o,a,i),h:a==="xxs"||a==="xs"?28:30,minW:Math.min(12,i),minH:16}}function T(e,t,r,n){return e.map((o,a)=>Ve({item:o,band:t,index:a,bandCount:e.length,breakpoint:r,columns:n}))}function q(e){const t=ze(e);return Object.fromEntries(v.DASHBOARD_AUTHORING_BREAKPOINTS.map(r=>{const n=Be[r],o=[...T(t.introText,"introText",r,n),...T(t.kpis,"kpi",r,n),...T(t.charts,"chart",r,n),...T(t.tables,"table",r,n),...T(t.supportingText,"supportingText",r,n)];return[r,Pe(o,n)]}))}function He(e){const t=De.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function Le(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function je(e){return Le(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function Ge(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function We(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function X(e,t){if(t===void 0)return;const r=He(e.dataType),n=e.operation||"in";if(je(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:r,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(n==="is null"||n==="is not null")return{filterId:e.id,name:e.column,operation:n,valueType:r,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const o=Array.isArray(t)?t:[t],a=r==="date"?We(o):Ge(o);if(a.length!==0&&!((n==="between"||n==="not between")&&a.length<2))return{filterId:e.id,name:e.column,operation:n,valueType:r,values:a,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function Ie(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ue(e,t,r){const n=(t||[]).filter(o=>o.scope==="card"&&o.targetCardId===r).map(o=>o.field).filter(Boolean);return n.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...n]}}function U(e,t){return Array.from(new Set((e||[]).map(r=>t.get(r)).filter(r=>!!r)))}function Ke(e,t){if((e==null?void 0:e.kind)!=="cards")return e;const r=U(e.cardIds,t);return r.length>0?{...e,cardIds:r}:null}function Xe(e,t){return!e.applyToCardIds&&!e.excludeCardIds?e:{...e,...e.applyToCardIds?{applyToCardIds:U(e.applyToCardIds,t)}:{},...e.excludeCardIds?{excludeCardIds:U(e.excludeCardIds,t)}:{}}}function Je(e,t){const r={},n=[];return{inputs:(e.filterInputs||[]).flatMap((a,i)=>{const d=Ke(a.scope,t);if(d===null)return n.push(Ie("filter_input_scope_empty",`Filter input "${a.label}" was skipped because all scoped cards were skipped during query validation.`)),[];const s=X(a.filter,a.defaultValue);return s&&(r.shared??(r.shared={}),r.shared[a.id]={status:"set",value:{kind:"filter",filterValue:s}}),[{id:a.id,kind:"filter",label:a.label,variableName:a.variableName,scope:d||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:i},exports:["label","value","start","end","range"],filter:Xe(a.filter,t)}]}),warnings:n,defaultInputValues:r.shared&&Object.keys(r.shared).length>0?r:void 0}}function Qe(e){var w,y;const t=ge(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../chunks/contracts-CtB2VONT.js"),N=require("../chunks/source-identity-C-xaeE_I.js"),z=require("../chunks/validators-jpoYhpHh.js"),De=require("../chunks/catalog-field-grounding-BGW0hnB9.js");function _(e){return e&&typeof e=="object"?e:null}function D(e){return typeof e=="string"?e:null}function oe(e){var t,r,n;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((r=_(e))==null?void 0:r.kind)==="physical"||((n=_(e))==null?void 0:n.kind)==="sql")}function M(e){return oe(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function ve(e){return N.semaphorSourceIdentityKey(e)}function K(e,t){return N.semaphorSourcesReferToSameDataset(e,t)}function se(e,t){return N.preferSemaphorSourceMetadata(e,t)}function R(e){const t=[];for(const r of e){const n=t.findIndex(o=>K(o,r));n===-1?t.push(r):t[n]=se(t[n],r)}return t}function Ce(e){return R(e)[0]}function G(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!N.semaphorSourcesReferToSameDataset(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function W(e){return M(e)?e:void 0}function ae(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(r=>(r==null?void 0:r.kind)==="semantic"&&N.semaphorSourcesReferToSameDataset(e,r)&&!!r.connectionId)}function S(e,t){const r=W(e==null?void 0:e.source);return r?G(r,t):void 0}function de({explicitSource:e,field:t,defaultSource:r,fallbackSources:n}){const o=[r,...n||[]],a=W(e),i=a?G(a,ae(a,o)):void 0;if(i)return i;if(e!==void 0)return;const d=S(t,r),s=d?G(d,ae(d,o)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return W(r)}function ke(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const r=S(e),n=S(t);return!r||!n?!0:K(r,n)}function C(e){var t;return D((t=_(e))==null?void 0:t.kind)}function ce(e){var t,r;return C(e)!=="semantic"?null:((r=D((t=_(e))==null?void 0:t.domainId))==null?void 0:r.trim())||null}function xe(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetName)}function Te(e){var t;return C(e)!=="semantic"?null:D((t=_(e))==null?void 0:t.datasetId)}function Fe(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.connectionId)}function Re(e){var t;return C(e)!=="physical"?null:D((t=_(e))==null?void 0:t.tableName)}function Ne(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.databaseName)||""}function Me(e){var t;return C(e)!=="physical"?"":D((t=_(e))==null?void 0:t.schemaName)||""}function le(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function ue({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const r=e.map(ce),n=new Set(r.filter(Boolean));return r.some(o=>!o)||n.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function E(e,t){if(!t)return!1;if(t.kind==="semantic"){const r=Te(e);return ce(e)===t.domainId?r&&t.datasetId?r===t.datasetId:xe(e)===t.datasetName:!1}return t.kind==="physical"?Fe(e)===t.connectionId&&Re(e)===t.tableName&&Ne(e)===(t.databaseName||"")&&Me(e)===(t.schemaName||""):!1}function $e(e,t){return e.find(r=>E(r,t))}function p(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function B(e){const t=new Set;for(const r of e){if(t.has(r))return r;t.add(r)}return null}function fe({card:e,datasets:t,errors:r}){if(e.type==="text")return;const n=le(e);if(!n){if(t.length<=1)return;r.push(p("missing_card_analytics_source","Multi-dataset dashboard cards must include analytics intent with a source so the materializer can choose the correct dataset.",e.id));return}t.some(o=>E(o,n))||r.push(p("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function P(e){return e.map(t=>t==null?void 0:t.source).filter(t=>!!t)}function H(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function ie(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object")):[]}function Oe(e){var r;if(!e)return[];const t=[e.source];return e.kind==="metric"?t.push(...P([...H(e.metrics),e.primaryMetric,e.dateField,...H(e.dimensions),...ie(e.filters).map(n=>n.field)])):e.kind==="records"?t.push(...P([...H(e.fields),e.dateField,(r=e.orderBy)==null?void 0:r.field,...ie(e.filters).map(n=>n.field)])):e.kind==="inputOptions"?t.push(...P([e.field])):e.kind==="sql"&&t.push(...P(e.fields||[])),t}function pe({card:e,datasets:t,errors:r}){if(e.type!=="text"){for(const n of Oe(e.analyticsIntent))if(n&&!t.some(o=>E(o,n))){r.push(p("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function he({card:e,errors:t}){if(e.type==="text"||!e.analyticsIntent)return;const r=z.validateSemaphorAnalyticsIntent(e.analyticsIntent);if(!r.ok)for(const n of r.errors)t.push(p(n.code,n.path?`${n.path}: ${n.message}`:n.message,e.id))}function me({datasets:e,errors:t,requireAtLeastOne:r}){const n=ue({datasets:e,requireAtLeastOne:r});if(!n.ok){if(n.issue==="invalid_dataset_count"){t.push(p("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(p("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function ge(e){var f,g;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard plan version must be 1.")),(f=r.title)!=null&&f.trim()||t.push(p("missing_title","Dashboard plan needs a title."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.sheets)?r.sheets:[];me({datasets:o,errors:t,requireAtLeastOne:!0}),a.length!==1&&t.push(p("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const i=a[0];i&&i.kind!=="dashboard"&&t.push(p("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(i==null?void 0:i.cards)||[];d.length>v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS&&t.push(p("too_many_cards",`Generated dashboards can contain at most ${v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`));const s=B(d.map(l=>l.id));s&&t.push(p("duplicate_card_id",`Duplicate generated card id: ${s}.`));const u=B(d.map(l=>l.frameId));u&&t.push(p("duplicate_frame_id",`Duplicate generated frame id: ${u}.`));for(const l of d)(g=l.title)!=null&&g.trim()||t.push(p("missing_card_title","Card title is required.",l.id)),l.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.id)),l.type!=="text"&&!l.analyticsIntent&&n.push(p("missing_analytics_intent","Non-text card has no analytics intent and may be skipped by the app layer.",l.id)),fe({card:l,datasets:o,errors:t}),he({card:l,errors:t}),pe({card:l,datasets:o,errors:t});const h=Array.isArray(r.filterInputs)?r.filterInputs:[],I=h.map(l=>l.id),A=B(I);A&&t.push(p("duplicate_input_id",`Duplicate dashboard input id: ${A}.`));const w=h.map(l=>l.variableName).filter(Boolean)||[],y=B(w);y&&t.push(p("duplicate_input_variable",`Duplicate dashboard input variable name: ${y}.`));const c=Array.isArray(r.calculatedFields)?r.calculatedFields:[];for(const l of c)l.scope==="domain"&&l.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:n}}function be(e){var i;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[p("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const r=e,n=[...r.warnings||[]];r.version!==1&&t.push(p("invalid_version","Dashboard change plan version must be 1.")),(i=r.dashboardId)!=null&&i.trim()||t.push(p("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const o=Array.isArray(r.datasets)?r.datasets:[],a=Array.isArray(r.operations)?r.operations:[];me({datasets:o,errors:t,requireAtLeastOne:!1});for(const d of a){if(d.kind==="unsupported"){n.push(p("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(p("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(fe({card:d.card,datasets:o,errors:t}),he({card:d.card,errors:t}),pe({card:d.card,datasets:o,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(p("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${d.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:n}}const Be={lg:48,md:36,sm:24,xs:12,xxs:6};function Pe(e,t){let r=0,n=0,o=0;return e.map(a=>{const i=Math.min(a.w,t);r>0&&r+i>t&&(r=0,n+=o,o=0);const d={i:a.frameId,x:r,y:n,w:i,h:a.h,minW:Math.min(a.minW,t),minH:a.minH,static:!1};return r+=i,o=Math.max(o,a.h),d})}function ze(e){const t=[...e].sort((s,u)=>s.priority-u.priority),r=t.filter(s=>s.role==="kpi"),n=t.filter(s=>s.role==="chart"),o=t.filter(s=>s.role==="table"),a=t.filter(s=>s.role==="text"),i=a.slice(0,1),d=a.slice(i.length);return{kpis:r,introText:i,charts:n,tables:o,supportingText:d}}function Ee(e,t,r){return t==="xxs"||t==="xs"?r:t==="sm"?Math.min(12,r):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function qe(e,t,r,n){return r==="xxs"||r==="xs"||r==="sm"||r==="md"||t===1||t%2===1&&e===0?n:n/2}function Ve(e){const{item:t,band:r,index:n,bandCount:o,breakpoint:a,columns:i}=e;return r==="kpi"?{...t,band:r,w:Ee(o,a,i),h:15,minW:Math.min(6,i),minH:12}:r==="table"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?34:38,minW:Math.min(12,i),minH:18}:r==="introText"?{...t,band:r,w:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:r==="supportingText"?{...t,band:r,w:a==="lg"?i/2:i,h:a==="xxs"||a==="xs"?12:10,minW:Math.min(12,i),minH:8}:{...t,band:r,w:qe(n,o,a,i),h:a==="xxs"||a==="xs"?28:30,minW:Math.min(12,i),minH:16}}function T(e,t,r,n){return e.map((o,a)=>Ve({item:o,band:t,index:a,bandCount:e.length,breakpoint:r,columns:n}))}function q(e){const t=ze(e);return Object.fromEntries(v.DASHBOARD_AUTHORING_BREAKPOINTS.map(r=>{const n=Be[r],o=[...T(t.introText,"introText",r,n),...T(t.kpis,"kpi",r,n),...T(t.charts,"chart",r,n),...T(t.tables,"table",r,n),...T(t.supportingText,"supportingText",r,n)];return[r,Pe(o,n)]}))}function He(e){const t=De.normalizeAnalyticsCatalogDataType(e);return t==="datetime"?"date":t==="unknown"?"string":t}function Le(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function je(e){return Le(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function Ge(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function We(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function X(e,t){if(t===void 0)return;const r=He(e.dataType),n=e.operation||"in";if(je(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:r,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(n==="is null"||n==="is not null")return{filterId:e.id,name:e.column,operation:n,valueType:r,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const o=Array.isArray(t)?t:[t],a=r==="date"?We(o):Ge(o);if(a.length!==0&&!((n==="between"||n==="not between")&&a.length<2))return{filterId:e.id,name:e.column,operation:n,valueType:r,values:a,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function Ie(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ue(e,t,r){const n=(t||[]).filter(o=>o.scope==="card"&&o.targetCardId===r).map(o=>o.field).filter(Boolean);return n.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...n]}}function U(e,t){return Array.from(new Set((e||[]).map(r=>t.get(r)).filter(r=>!!r)))}function Ke(e,t){if((e==null?void 0:e.kind)!=="cards")return e;const r=U(e.cardIds,t);return r.length>0?{...e,cardIds:r}:null}function Xe(e,t){return!e.applyToCardIds&&!e.excludeCardIds?e:{...e,...e.applyToCardIds?{applyToCardIds:U(e.applyToCardIds,t)}:{},...e.excludeCardIds?{excludeCardIds:U(e.excludeCardIds,t)}:{}}}function Je(e,t){const r={},n=[];return{inputs:(e.filterInputs||[]).flatMap((a,i)=>{const d=Ke(a.scope,t);if(d===null)return n.push(Ie("filter_input_scope_empty",`Filter input "${a.label}" was skipped because all scoped cards were skipped during query validation.`)),[];const s=X(a.filter,a.defaultValue);return s&&(r.shared??(r.shared={}),r.shared[a.id]={status:"set",value:{kind:"filter",filterValue:s}}),[{id:a.id,kind:"filter",label:a.label,variableName:a.variableName,scope:d||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:i},exports:["label","value","start","end","range"],filter:Xe(a.filter,t)}]}),warnings:n,defaultInputValues:r.shared&&Object.keys(r.shared).length>0?r:void 0}}function Qe(e){var w,y;const t=ge(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
2
2
  `)||"Dashboard plan is invalid.");const r=e.plan.sheets[0],n=[...t.warnings],o=[],a=new Map(e.cardArtifacts.map(c=>[c.planCardId,c])),i=new Map(e.cardArtifacts.map(c=>[c.planCardId,c.card.id])),d=[];for(const c of r.cards){const f=a.get(c.id);if(!f){const l=Ie("missing_card_artifact",`Card "${c.title}" was skipped because no generated artifact was supplied.`,c.id);o.push(l);continue}n.push(...f.warnings||[]);const g=Ue(f.card,e.plan.calculatedFields,c.id);d.push({id:c.frameId,cards:[g],activeCardId:g.id})}if(d.length===0)throw new Error("Dashboard plan did not produce any persistable cards.");const{inputs:s,defaultInputValues:u,warnings:h}=Je(e.plan,i);n.push(...h);const I=q(r.cards.filter(c=>d.some(f=>f.id===c.frameId)).map(c=>({frameId:c.frameId,priority:c.priority,role:c.role})));return{dashboard:{id:e.dashboardId,title:e.plan.title,description:e.plan.description||"",sheets:[{id:r.id,kind:"dashboard",title:r.title,description:r.description,frames:d,layouts:I,calculatedFields:(w=e.plan.calculatedFields)==null?void 0:w.filter(c=>c.scope==="sheet"&&c.field).map(c=>c.field)}],calculatedFields:(y=e.plan.calculatedFields)==null?void 0:y.filter(c=>c.scope==="dashboard"&&c.field).map(c=>c.field),inputs:s,...u?{defaultInputValues:u}:{}},warnings:n,skippedOperations:o}}function k(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function Ye(e){return JSON.parse(JSON.stringify(e))}function Ze(e){var t;return(t=e.sheets)==null?void 0:t.find(r=>(r.kind||"dashboard")==="dashboard")}function L(e,t){var r;for(const n of e.sheets||[])for(const o of n.frames||[]){const a=(r=o.cards)==null?void 0:r.find(i=>i.id===t);if(a)return{sheet:n,frame:o,card:a}}return null}function ye(e){var r,n;const t=(n=(r=e.cards)==null?void 0:r[0])==null?void 0:n.type;return t==="kpi"?"kpi":t==="table"||t==="detailTable"||t==="pivotTable"?"table":t==="text"?"text":"chart"}function et(e){var t;return new Map((((t=e.layouts)==null?void 0:t.lg)||[]).map((r,n)=>[r.i,n]))}function _e(e,t=new Map){const r=et(e),n=Math.max(r.size,t.size),o=(e.frames||[]).map((a,i)=>({frameId:a.id,role:ye(a),priority:t.get(a.id)??r.get(a.id)??n+i}));e.layouts=q(o)}function tt(e){return Object.values(e.layouts||{}).some(t=>t.length>0)}function rt(e,t){if(!tt(e)){_e(e);return}const r=q([{frameId:t.id,role:ye(t),priority:0}]);e.layouts??(e.layouts={});for(const[n,o]of Object.entries(r)){const a=e.layouts[n]||[];if(a.some(s=>s.i===t.id))continue;const i=o[0];if(!i)continue;const d=a.reduce((s,u)=>Math.max(s,u.y+u.h),0);e.layouts[n]=[...a,{...i,y:d}]}}function nt(e,t){var n;const r=X(t.filter,t.defaultValue);r&&(e.defaultInputValues??(e.defaultInputValues={}),(n=e.defaultInputValues).shared??(n.shared={}),e.defaultInputValues.shared[t.id]={status:"set",value:{kind:"filter",filterValue:r}})}function at(e){var d;const t=be(e.changePlan);if(!t.ok)throw new Error(t.errors.map(s=>s.message).join(`
3
3
  `)||"Dashboard change plan is invalid.");const r=Ye(e.dashboard),n=[...t.warnings],o=[],a=new Map(e.cardArtifacts.map(s=>[s.planCardId,s])),i=Ze(r);if(!i)throw new Error("Dashboard has no editable dashboard sheet.");i.frames??(i.frames=[]);for(const s of e.changePlan.operations)switch(s.kind){case"addCard":{if((i.frames||[]).reduce((A,w)=>{var y;return A+(((y=w.cards)==null?void 0:y.length)||0)},0)>=v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS){o.push(k("generated_card_limit_reached",`AI refinement is capped at ${v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS} cards.`,s.card.id));break}const h=a.get(s.card.id);if(!h){o.push(k("missing_card_artifact",`Card "${s.card.title}" was skipped because no generated artifact was supplied.`,s.card.id));break}const I={id:s.card.frameId,cards:[h.card],activeCardId:h.card.id};i.frames.push(I),rt(i,I);break}case"addFilterInput":{r.inputs??(r.inputs=[]);const u={id:s.input.id,kind:"filter",label:s.input.label,variableName:s.input.variableName,scope:s.input.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:r.inputs.length},exports:["label","value","start","end","range"],filter:s.input.filter};r.inputs.push(u),nt(r,s.input);break}case"addCalculatedField":{if(s.field.scope==="dashboard"&&s.field.field)r.calculatedFields??(r.calculatedFields=[]),r.calculatedFields.push(s.field.field);else if(s.field.scope==="sheet"&&s.field.field)i.calculatedFields??(i.calculatedFields=[]),i.calculatedFields.push(s.field.field);else if(s.field.scope==="card"&&s.field.field){const u=s.field.targetCardId?L(r,s.field.targetCardId):null;u?((d=u.card).calculatedFields??(d.calculatedFields=[]),u.card.calculatedFields.push(s.field.field)):o.push(k("missing_calculated_field_target",`Calculated field "${s.field.name}" needs a valid target card.`))}break}case"renameCard":{const u=L(r,s.cardId);if(!u){o.push(k("card_not_found",`Card "${s.cardId}" could not be renamed because it was not found.`,s.cardId));break}u.card.title=s.title,s.description!==void 0&&(u.card.description=s.description);break}case"reorderCards":{const u=new Map;for(let h=0;h<s.cardIds.length;h+=1){const I=s.cardIds[h],A=L(r,I);A&&u.set(A.frame.id,h)}_e(i,u);break}case"reuseCalculatedField":n.push(k("reused_calculated_field",`Calculated field "${s.fieldId}" is reused by reference.`));break;case"unsupported":o.push(k("unsupported_operation",s.reason||s.requestedAction));break}return{dashboard:r,warnings:n,skippedOperations:o}}function b(e,t,r){return r?{code:e,message:t,cardId:r}:{code:e,message:t}}function F(e,t){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||t}function Se(e,t){if(!t.has(e))return t.add(e),e;let r=2,n=`${e}-${r}`;for(;t.has(n);)r+=1,n=`${e}-${r}`;return t.add(n),n}function $(e){return!!(e&&typeof e=="object")}function Ae(e){return Array.isArray(e.inputs)?e.inputs.filter(t=>$(t)&&typeof t.id=="string"):[]}function J(e){return Array.isArray(e.sections)?e.sections.filter(t=>$(t)):[]}function Q(e){return Array.isArray(e.views)?e.views.filter(t=>$(t)):[]}function x(e){if(!Array.isArray(e))return[];const t=[];for(const r of e){const n=S(r);n&&t.push(n)}return t}function it(e){var n,o;if(!e)return[];const t=[];if(M(e.source)&&t.push(e.source),e.kind==="metric"){t.push(...x(e.metrics));const a=S(e.dateField);a&&t.push(a),t.push(...x(e.dimensions)),t.push(...x((n=e.filters)==null?void 0:n.map(i=>i.field)))}else if(e.kind==="records"){const a=S(e.dateField);a&&t.push(a),t.push(...x(e.fields)),t.push(...x((o=e.filters)==null?void 0:o.map(i=>i.field)))}else if(e.kind==="inputOptions"){const a=S(e.field);a&&t.push(a)}else e.kind==="sql"&&t.push(...x(e.fields));const r="inputs"in e&&Array.isArray(e.inputs)?e.inputs:[];for(const a of r){const i=S(a.field);i&&t.push(i)}return t}function ot(e){const t=[];for(const r of Ae(e)){const n=S(r.field);n&&t.push(n)}for(const r of J(e))for(const n of Q(r))t.push(...it(n.analytics));return t}function st(e){var r;const t=[];for(const n of J(e))for(const o of Q(n))M((r=o.analytics)==null?void 0:r.source)&&t.push(o.analytics.source);return t}function dt(e,t){const r=R(e).filter(M);if(r.length===0)return t.push(b("missing_materializable_dataset","No semantic or physical source could be converted into the current dashboard authoring dataset reference.")),[];const n=r.every(a=>a.kind==="semantic"),o=Array.from(new Set(r.filter(a=>a.kind==="semantic").map(a=>a.domainId)));return r.length>1&&(!n||o.length!==1)?(t.push(b("multiple_datasets_out_of_scope","The dashboard authoring compiler supports multiple datasets only within one semantic domain; using the first source and deferring the rest.")),[r[0]]):r}function ct(e,t){const r=J(e),n=Ae(e),o=R(ot(e)),a=R(st(e));return{sections:r,inputs:n,sources:o,primarySources:a,defaultSource:a.length===1?a[0]:void 0,datasets:dt(o,t)}}function lt(e){return e&&z.validateSemaphorAnalyticsIntent(e).ok?e:void 0}function ut(e){var t;switch((t=e.presentation)==null?void 0:t.kind){case"kpi":return"kpi";case"lineChart":return"line";case"barChart":return"bar";case"areaChart":return"area";case"table":return"table";case"text":return"text";default:return null}}function ft(e){var t,r,n;return((t=e.presentation)==null?void 0:t.kind)==="kpi"?"kpi":((r=e.presentation)==null?void 0:r.kind)==="table"?"table":((n=e.presentation)==null?void 0:n.kind)==="text"?"text":"chart"}function pt(e){const t=z.normalizeSemaphorInputOperator(e);switch(t){case"not_in":return"not in";case"not_between":return"not between";case"contains":return"like";case"not_contains":return"not like";default:return t||"in"}}function ht(e){return $(e.field)?e.field.dataType==="datetime"?"date":e.field.dataType||"string":"string"}function mt(e){if(!(!e||e.kind!=="physical"))return[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")}function gt(e,t,r,n,o,a){if(e.kind!=="filter")return a.push(b("control_inputs_deferred",`Control input "${e.label}" is represented in the protocol but not yet materialized by the dashboard authoring adapter.`)),null;if(!$(e.field)||typeof e.field.name!="string")return a.push(b("filter_requires_field",`Filter "${e.label||e.id}" needs a field before the dashboard compiler can materialize it.`)),null;const i=de({explicitSource:void 0,field:e.field,defaultSource:t,fallbackSources:r}),d=(i==null?void 0:i.kind)==="semantic"||(i==null?void 0:i.kind)==="physical"?i.connectionId:void 0;if(!d)return a.push(b("filter_requires_connection_id",`Filter "${e.label}" needs a source connectionId before the dashboard compiler can materialize it.`)),null;const h={id:`filter-${Se(F(e.id,e.field.name),o)}`,variableName:e.id,connectionId:d,title:e.label,column:e.field.name,dataType:ht(e),qualifiedTableName:mt(i),sql:"",operation:pt(e.operator),type:e.multi===!1?"single":"multiple",location:"dashboard",displayMode:"toolbar",fieldMeta:(i==null?void 0:i.kind)==="semantic"?{name:e.field.name,qualifiedFieldName:e.field.name,dataType:e.field.dataType,role:e.field.role==="measure"?"metric":"groupby"}:void 0,semanticContext:(i==null?void 0:i.kind)==="semantic"?{semanticDomainId:i.domainId,connectionId:i.connectionId}:void 0};return{id:e.id,label:e.label,variableName:e.id,scope:n,filter:h,defaultValue:X(h,e.defaultValue)}}function j(e){const t=[],r=[];for(const n of e.viewIds){const o=e.viewIdToCardId.get(n);o?t.push(o):r.push(n)}return r.length>0&&e.warnings.push(b("input_scope_view_not_found",`Filter "${e.inputLabel}" referenced unknown view ids: ${r.join(", ")}.`)),Array.from(new Set(t))}function bt(e){var n,o;if(!e.protocolScope){const a=Array.from(new Set(e.boundCardIds));return a.length>0&&a.length<e.allCardIds.length?{kind:"cards",cardIds:a}:void 0}if(e.protocolScope.level==="dashboard"){if(!((n=e.protocolScope.excludeViewIds)!=null&&n.length))return;const a=new Set(j({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:e.allCardIds.filter(i=>!a.has(i))}}if(e.protocolScope.level==="view"){const a=j({inputLabel:e.inputLabel,viewIds:e.protocolScope.viewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings});return a.length===0?(e.warnings.push(b("input_scope_has_no_materialized_cards",`Filter "${e.inputLabel}" was deferred because its view scope does not match any materialized cards.`)),null):{kind:"cards",cardIds:a}}const t=e.sectionIdToCardIds.get(e.protocolScope.sectionId)||[];if(t.length===0)return e.warnings.push(b("input_scope_section_not_found",`Filter "${e.inputLabel}" was deferred because section "${e.protocolScope.sectionId}" does not match any materialized cards.`)),null;if(!((o=e.protocolScope.excludeViewIds)!=null&&o.length))return{kind:"cards",cardIds:t};const r=new Set(j({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:t.filter(a=>!r.has(a))}}function It(e){var w,y,c;const t=[],r=z.validateSemaphorDashboardIntent(e);for(const f of r.warnings)t.push(b(f.code,f.message));for(const f of r.errors)t.push(b(f.code,f.message));const n=ct(e,t),o=[],a=new Map,i=new Map,d=new Map,s=new Set,u=new Set;let h=0;for(const[f,g]of n.sections.entries()){const l=typeof g.title=="string"?g.title:`Section ${f+1}`,Y=g.id||F(l,`section-${f+1}`);i.set(Y,[]);for(const[Z,m]of Q(g).entries()){const ee=ut(m),V=F(m.id||`${l}-${m.title||`View ${Z+1}`}`,`card-${f+1}-${Z+1}`);if(!ee){t.push(b("unsupported_presentation",`Dashboard presentation "${((w=m.presentation)==null?void 0:w.kind)||"unknown"}" is not supported by the dashboard authoring adapter.`,`card-${V}`));continue}if(((y=m.analytics)==null?void 0:y.kind)==="sql"){t.push(b("sql_intent_deferred","SQL analytics intent is valid protocol, but the current dashboard authoring adapter only materializes semantic and physical config-card intents.",`card-${V}`));continue}const te=Se(V,s),O=`card-${te}`;m.id&&a.set(m.id,O),(c=i.get(Y))==null||c.push(O);const we=m.analytics&&"inputs"in m.analytics?m.analytics.inputs:void 0;for(const re of we||[]){const ne=d.get(re.inputId)||[];ne.push(O),d.set(re.inputId,ne)}o.push({id:O,frameId:`frame-${te}`,title:m.title,description:m.description,type:ee,role:ft(m),priority:h,section:l,analyticsIntent:lt(m.analytics),text:m.text}),h+=1}}const I=n.inputs.map(f=>{const g=bt({protocolScope:f.scope,inputLabel:f.label,allCardIds:o.map(l=>l.id),boundCardIds:d.get(f.id)||[],viewIdToCardId:a,sectionIdToCardIds:i,warnings:t});return g===null?null:gt(f,n.defaultSource,n.sources,g,u,t)}).filter(f=>!!f);return{plan:{version:1,id:`plan-${F(e.title,"dashboard")}`,title:e.title,description:e.description,datasets:n.datasets,sheets:[{id:`sheet-${F(e.title,"dashboard")}`,title:e.title,description:e.description,kind:"dashboard",cards:o}],filterInputs:I.length?I:void 0,warnings:t.length?t:void 0,unresolvedRequests:r.ok?void 0:r.errors.map(f=>f.message)},warnings:t}}exports.DASHBOARD_AUTHORING_BREAKPOINTS=v.DASHBOARD_AUTHORING_BREAKPOINTS;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=v.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS;exports.applyDashboardChangePlan=at;exports.compileDashboardFromPlan=Qe;exports.compileResponsiveDashboardLayouts=q;exports.dashboardAuthoringDatasetMatchesSource=E;exports.dashboardAuthoringFieldsReferToSameTarget=ke;exports.dashboardAuthoringSourceFromField=S;exports.dashboardAuthoringSourceKey=ve;exports.dashboardAuthoringSourcesReferToSameDataset=K;exports.dashboardPlanFromSemaphorDashboardIntent=It;exports.findDashboardAuthoringDatasetForSource=$e;exports.getDashboardAuthoringCardSource=le;exports.isMaterializableDashboardAuthoringSource=M;exports.isSemaphorSourceRef=oe;exports.mergeDashboardAuthoringSources=R;exports.preferDashboardAuthoringSourceMetadata=se;exports.preferredDashboardAuthoringSource=Ce;exports.resolveDashboardAuthoringSource=de;exports.validateDashboardAuthoringDatasetScope=ue;exports.validateDashboardChangePlan=be;exports.validateDashboardPlan=ge;
@@ -1,7 +1,7 @@
1
1
  import { D as B, a as be } from "../chunks/contracts-CoCOpd_i.js";
2
2
  import { s as Ie, a as E, p as ye } from "../chunks/source-identity-Dj3dryN9.js";
3
3
  import { c as ae, f as _e, n as we } from "../chunks/validators-CtNmgsvG.js";
4
- import { b as ve } from "../chunks/catalog-field-grounding-DoEBOXQd.js";
4
+ import { c as ve } from "../chunks/catalog-field-grounding-DHXEI7cW.js";
5
5
  function _(e) {
6
6
  return e && typeof e == "object" ? e : null;
7
7
  }