react-semaphor 0.1.420 → 0.1.422

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 (58) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +28 -27
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +2 -2
  5. package/dist/chunks/analyze-result-contract-D7pjjYPy.js +2069 -0
  6. package/dist/chunks/analyze-result-contract-DpDcImgk.js +1 -0
  7. package/dist/chunks/{calendar-preferences-dialog-f0Z7Kf-U.js → calendar-preferences-dialog-C2fBRNZh.js} +1 -1
  8. package/dist/chunks/{calendar-preferences-dialog-DIfAbE_y.js → calendar-preferences-dialog-Cbavs2EK.js} +3 -3
  9. package/dist/chunks/{dashboard-briefing-launcher-anh-Jy5v.js → dashboard-briefing-launcher-C0_ZbBK3.js} +4 -4
  10. package/dist/chunks/{dashboard-briefing-launcher-C3tNkGFG.js → dashboard-briefing-launcher-CGfEFUnX.js} +1 -1
  11. package/dist/chunks/{dashboard-controls-DQxlOxzy.js → dashboard-controls-BUuS-BGl.js} +1 -1
  12. package/dist/chunks/{dashboard-controls-8dCQaPaq.js → dashboard-controls-ae5t32xV.js} +5 -5
  13. package/dist/chunks/{dashboard-json-B309EInF.js → dashboard-json-DTL_kYhz.js} +1 -1
  14. package/dist/chunks/{dashboard-json-i7Ae9KGD.js → dashboard-json-Db3rkY_a.js} +3 -3
  15. package/dist/chunks/{edit-dashboard-visual-z3IqzYnj.js → edit-dashboard-visual-CW7mv_si.js} +7030 -6963
  16. package/dist/chunks/{edit-dashboard-visual-4HycwBHR.js → edit-dashboard-visual-Ciqdu58a.js} +38 -38
  17. package/dist/chunks/{index-yxKWKFdr.js → index-8y8XX7sX.js} +121 -121
  18. package/dist/chunks/{index-B6DLEXRX.js → index-OD6mLD7U.js} +257 -256
  19. package/dist/chunks/{switch-COWQU8aK.js → switch-CWcWwwDJ.js} +1 -1
  20. package/dist/chunks/{switch-D6Ygf3wA.js → switch-DRNqX0v0.js} +1 -1
  21. package/dist/chunks/{update-policy-BzT2k4n6.js → update-policy-BCJc0oI5.js} +211 -187
  22. package/dist/chunks/update-policy-C1pmhLz9.js +3 -0
  23. package/dist/chunks/{use-create-flow-overlay-state-DENfd7sW.js → use-create-flow-overlay-state-C0Uhmlpd.js} +1 -1
  24. package/dist/chunks/{use-create-flow-overlay-state-CX0D-6HM.js → use-create-flow-overlay-state-CkMmXhI-.js} +3 -3
  25. package/dist/chunks/validators-DMlVbd1p.js +1 -0
  26. package/dist/chunks/{validators-Cxr9qbrR.js → validators-PXkij33j.js} +93 -93
  27. package/dist/dashboard/index.cjs +1 -1
  28. package/dist/dashboard/index.js +1 -1
  29. package/dist/dashboard-authoring/index.cjs +1 -1
  30. package/dist/dashboard-authoring/index.js +14 -14
  31. package/dist/data-app-builder/index.cjs +1 -1
  32. package/dist/data-app-builder/index.js +2 -2
  33. package/dist/data-app-codegen/index.cjs +1 -1
  34. package/dist/data-app-codegen/index.js +2 -2
  35. package/dist/data-app-codegen-node/index.cjs +188 -251
  36. package/dist/data-app-codegen-node/index.js +631 -673
  37. package/dist/data-app-sdk/index.cjs +2 -2
  38. package/dist/data-app-sdk/index.js +678 -638
  39. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  40. package/dist/data-app-sdk-adapters/index.js +51 -51
  41. package/dist/data-app-sdk-validation/index.cjs +1 -1
  42. package/dist/data-app-sdk-validation/index.js +2 -2
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.js +7 -7
  45. package/dist/style.css +1 -1
  46. package/dist/surfboard/index.cjs +1 -1
  47. package/dist/surfboard/index.js +2 -2
  48. package/dist/types/analytics-protocol.d.ts +12 -9
  49. package/dist/types/dashboard-assistant.d.ts +0 -6
  50. package/dist/types/data-app-codegen-node.d.ts +12 -2
  51. package/dist/types/data-app-codegen.d.ts +12 -2
  52. package/dist/types/data-app-sdk-validation.d.ts +0 -6
  53. package/dist/types/data-app-sdk.d.ts +17 -7
  54. package/package.json +1 -1
  55. package/dist/chunks/analyze-result-contract-DdhEt99q.js +0 -2004
  56. package/dist/chunks/analyze-result-contract-DwRzl7yJ.js +0 -1
  57. package/dist/chunks/update-policy-VloD-0YM.js +0 -3
  58. package/dist/chunks/validators-BMQo93Y0.js +0 -1
@@ -1,49 +1,51 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("../chunks/analyze-result-contract-DwRzl7yJ.js"),R=require("../chunks/update-policy-VloD-0YM.js"),ge=require("node:crypto"),ke="src/semaphor/generated",K=`// Generated by Semaphor Agent Plugin. Do not hand-edit analytics wiring here.
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("../chunks/analyze-result-contract-DpDcImgk.js"),R=require("../chunks/update-policy-C1pmhLz9.js"),he=require("node:crypto"),Ce="src/semaphor/generated",H=`// Generated by Semaphor Agent Plugin. Do not hand-edit analytics wiring here.
2
2
  // Regenerate from the accepted semaphor_plan_data_app codegenSummary when the plan changes.
3
- `;function Me(e,n={}){R.assertValidCodegenSummary(e);const r=Ce(e);if(r.views.length===0&&!n.allowEmpty)throw new Error("Contract generation produced zero executable views. Stop and ask for a different domain/goal or semantic model improvement; pass --allow-empty only for an explicit model-gap report.");const t=Oe(r),o=Ee({contract:r,files:t,generatorName:n.generatorName||"react-semaphor/data-app-codegen/node",generatorVersion:n.generatorVersion||"unknown"}),a={...t,"contract.manifest.json":`${JSON.stringify(o,null,2)}
4
- `};return{schemaVersion:R.GENERATED_CONTRACT_SCHEMA_VERSION,files:a,manifest:o,contentHash:String(o.generatedContentHash||""),usageExample:Ge(r),warnings:r.warnings,stats:{inputCount:r.inputs.length,executableViewCount:r.views.length,presentationViewCount:r.presentationViews.length,queryCount:r.views.length,optionQueryCount:r.optionQueries.length}}}function Ce(e){var u,d,c,i,p,w,g,$,F,M,V,C;const n=[],r=[];for(const s of e.inputs){h(r,s.fieldRef);for(const I of s.bindings||[])h(r,I.fieldRef);h(r,(u=s.optionQuery)==null?void 0:u.valueFieldRef),h(r,(d=s.optionQuery)==null?void 0:d.labelFieldRef),h(r,(c=s.optionQuery)==null?void 0:c.filterFieldRef),Q(r,(i=s.optionQuery)==null?void 0:i.spec)}for(const s of e.filterContracts){h(r,s.fieldRef),h(r,(p=s.optionQuery)==null?void 0:p.valueFieldRef),h(r,(w=s.optionQuery)==null?void 0:w.labelFieldRef),h(r,(g=s.optionQuery)==null?void 0:g.filterFieldRef),Q(r,($=s.optionQuery)==null?void 0:$.spec);for(const I of s.bindings||[])h(r,I.fieldRef)}for(const s of e.views){for(const I of s.fields||[])h(r,I);Q(r,(F=s.sdkSpec)==null?void 0:F.spec),Q(r,s.visualSpec)}const t=e.implementationChecklist||{};for(const s of Object.values(t.bindingsByView||{}))for(const I of Array.isArray(s)?s:[])h(r,I.fieldRef),h(r,I.optionValueField),h(r,I.optionLabelField);for(const s of t.requiredInputOptions||[])h(r,s.visibleLabelField),h(r,s.optionValueField),h(r,s.runtimeFilterField);const o=dn([...e.sources.map(s=>({raw:s,key:Ie(s),aliases:Fe(s),name:""})),...r.map(s=>sn(s)).filter(G)]);H(o,s=>{const I=b(s.raw);return q(s.raw.label||(I==null?void 0:I.datasetName)||(I==null?void 0:I.datasetId)||(I==null?void 0:I.name)||s.raw.kind||"source")});const a=pn(o),l=ne(r.filter(s=>s.name).map(s=>({raw:s,key:J(s),name:""})),s=>s.key);H(l,s=>q([s.raw.sourceKey?fn(s.raw.sourceKey):"",s.raw.aggregate?s.raw.aggregate.toLowerCase():"",s.raw.name].filter(Boolean).join("_")));const y=new Map(l.map(s=>[s.key,s.name])),S=e.inputs.map(s=>({raw:s,name:q(s.id||s.label||"input")}));H(S,s=>s.name);const f=S.filter(s=>!!s.raw.optionQuery).map(s=>({input:s,name:`${s.name}Options`,raw:s.raw.optionQuery}));H(f,s=>s.name);for(const s of f)an(s.raw.labelFieldRef,s.raw.valueFieldRef)&&un(s.raw.valueFieldRef)&&n.push(`Input option query ${((M=s.raw.spec)==null?void 0:M.inputId)||s.input.raw.id||s.name} uses identifier field ${s.raw.valueFieldRef.name} as both label and value. It can execute, but the UI will show key values unless the semantic model exposes a human-readable label through a modeled relationship.`);const m=e.views.filter(s=>{var I,B;return!!((I=s.sdkSpec)!=null&&I.builder&&((B=s.sdkSpec)!=null&&B.spec))}).map(s=>({raw:s,name:q(s.id||s.title||"query")}));H(m,s=>s.name);const O=e.views.filter(s=>fe(s)&&!("sdkSpec"in s)).map(s=>on(s));for(const s of e.views)(!("sdkSpec"in s)||!((V=s.sdkSpec)!=null&&V.builder)||!((C=s.sdkSpec)!=null&&C.spec))&&!fe(s)&&n.push(`Skipped view ${s.id||s.title||"unknown"} because it has no sdkSpec.`);return Ne({inputs:S,views:m,filterContracts:e.filterContracts}),{summary:e,title:e.title||"Semaphor Data App",sources:o,fields:l,inputs:S,optionQueries:f,views:m,presentationViews:O,filterContracts:e.filterContracts,checklist:t,sourceNameByKey:a,fieldNameByKey:y,warnings:n}}function Ne({inputs:e,views:n,filterContracts:r}){const t=new Set(e.map(a=>a.raw.id).filter(Boolean)),o=new Set(n.map(a=>a.raw.id).filter(Boolean));for(const[a,l]of r.entries()){if(!t.has(l.inputId))throw new Error(`filterContracts.${a}.inputId must reference a generated input.`);const y=new Set(l.appliesToViewIds||[]),S=new Set(l.notAppliedToViewIds||[]);for(const[f,m]of(l.appliesToViewIds||[]).entries())if(!o.has(m))throw new Error(`filterContracts.${a}.appliesToViewIds.${f} must reference an executable generated view.`);for(const[f,m]of(l.notAppliedToViewIds||[]).entries())if(!o.has(m))throw new Error(`filterContracts.${a}.notAppliedToViewIds.${f} must reference an executable generated view.`);for(const[f,m]of(l.bindings||[]).entries()){if(!o.has(m.viewId))throw new Error(`filterContracts.${a}.bindings.${f}.viewId must reference an executable generated view.`);if(!y.has(m.viewId))throw new Error(`filterContracts.${a}.bindings.${f}.viewId must be included in appliesToViewIds.`);if(S.has(m.viewId))throw new Error(`filterContracts.${a}.bindings.${f}.viewId must not be listed in notAppliedToViewIds.`)}}}function Oe(e){return{"sources.ts":Ke(e),"fields.ts":ve(e),"inputs.ts":je(e),"queries.ts":Qe(e),"bindings.ts":Le(e),"accessors.ts":ze(e),"metadata.ts":We(e),"index.ts":Ze()}}function Ee({contract:e,files:n,generatorName:r,generatorVersion:t}){return{schemaVersion:R.CONTRACT_MANIFEST_SCHEMA_VERSION,generatedContractSchemaVersion:R.GENERATED_CONTRACT_SCHEMA_VERSION,generator:{name:r,version:t},generatedContentHash:xe(n),codegenSummaryValidatorVersion:R.CODEGEN_SUMMARY_VALIDATOR_VERSION,codegenSummaryHash:Ae(e.summary),codegenSummary:e.summary}}function xe(e){const n=ge.createHash("sha256");for(const r of Object.keys(e).sort())n.update(r),n.update("\0"),n.update(e[r]),n.update("\0");return`sha256:${n.digest("hex")}`}function Ae(e){return`sha256:${ge.createHash("sha256").update(ue(e)).digest("hex")}`}function ue(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>ue(t)).join(",")}]`;const n=e;return`{${Object.keys(n).sort().filter(t=>n[t]!==void 0).map(t=>`${JSON.stringify(t)}:${ue(n[t])}`).join(",")}}`}function Ge(e){const n=e.views.find(f=>T(f)&&_(f));if(n)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, recordsSortOptionsForView, rowsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const sortOption = recordsSortOptionsForView.${n.name}[0];`,'const sort = sortOption ? { key: sortOption.key, direction: "asc" as const } : undefined;',`const query = queries.${n.name}({ page, pageSize, sort });`,`const result = useSemaphorQuery(query, queryOptionsForView.${n.name}(inputHandles));`,`const rows = rowsForView.${n.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
3
+ `;function Oe(e,n={}){R.assertValidCodegenSummary(e);const r=Me(e);if(r.views.length===0&&!n.allowEmpty)throw new Error("Contract generation produced zero executable views. Stop and ask for a different domain/goal or semantic model improvement; pass --allow-empty only for an explicit model-gap report.");const t=ke(r),o=Ne({contract:r,files:t,generatorName:n.generatorName||"react-semaphor/data-app-codegen/node",generatorVersion:n.generatorVersion||"unknown"}),a={...t,"contract.manifest.json":`${JSON.stringify(o,null,2)}
4
+ `};return{schemaVersion:R.GENERATED_CONTRACT_SCHEMA_VERSION,files:a,manifest:o,contentHash:String(o.generatedContentHash||""),usageExample:Te(r),warnings:r.warnings,stats:{inputCount:r.inputs.length,executableViewCount:r.views.length,presentationViewCount:r.presentationViews.length,queryCount:r.views.length,optionQueryCount:r.optionQueries.length}}}function Me(e){var d,p,m,i,l,g,h,I,$,M,b,E;const n=[],r=[];for(const s of e.inputs){S(r,s.fieldRef);for(const V of s.bindings||[])S(r,V.fieldRef);S(r,(d=s.optionQuery)==null?void 0:d.valueFieldRef),S(r,(p=s.optionQuery)==null?void 0:p.labelFieldRef),S(r,(m=s.optionQuery)==null?void 0:m.filterFieldRef),D(r,(i=s.optionQuery)==null?void 0:i.spec)}for(const s of e.filterContracts){S(r,s.fieldRef),S(r,(l=s.optionQuery)==null?void 0:l.valueFieldRef),S(r,(g=s.optionQuery)==null?void 0:g.labelFieldRef),S(r,(h=s.optionQuery)==null?void 0:h.filterFieldRef),D(r,(I=s.optionQuery)==null?void 0:I.spec);for(const V of s.bindings||[])S(r,V.fieldRef)}for(const s of e.views){for(const V of s.fields||[])S(r,V);D(r,($=s.sdkSpec)==null?void 0:$.spec),D(r,s.visualSpec)}const t=e.implementationChecklist||{};for(const s of Object.values(t.bindingsByView||{}))for(const V of Array.isArray(s)?s:[])S(r,V.fieldRef),S(r,V.optionValueField),S(r,V.optionLabelField);for(const s of t.requiredInputOptions||[])S(r,s.visibleLabelField),S(r,s.optionValueField),S(r,s.runtimeFilterField);const o=pn([...e.sources.map(s=>({raw:s,key:Ie(s),aliases:Ve(s),name:""})),...r.map(s=>an(s)).filter(x)]);P(o,s=>{const V=F(s.raw);return j(s.raw.label||(V==null?void 0:V.datasetName)||(V==null?void 0:V.datasetId)||(V==null?void 0:V.name)||s.raw.kind||"source")});const a=ln(o),u=ne(r.filter(s=>s.name).map(s=>({raw:s,key:X(s),name:""})),s=>s.key);P(u,s=>j([s.raw.sourceKey?yn(s.raw.sourceKey):"",s.raw.aggregate?s.raw.aggregate.toLowerCase():"",s.raw.name].filter(Boolean).join("_")));const c=new Map(u.map(s=>[s.key,s.name])),w=e.inputs.map(s=>({raw:s,name:j(s.id||s.label||"input")}));P(w,s=>s.name);const f=w.filter(s=>!!s.raw.optionQuery).map(s=>({input:s,name:`${s.name}Options`,raw:s.raw.optionQuery}));P(f,s=>s.name);for(const s of f)un(s.raw.labelFieldRef,s.raw.valueFieldRef)&&dn(s.raw.valueFieldRef)&&n.push(`Input option query ${((M=s.raw.spec)==null?void 0:M.inputId)||s.input.raw.id||s.name} uses identifier field ${s.raw.valueFieldRef.name} as both label and value. It can execute, but the UI will show key values unless the semantic model exposes a human-readable label through a modeled relationship.`);const y=e.views.filter(s=>{var V,K;return!!((V=s.sdkSpec)!=null&&V.builder&&((K=s.sdkSpec)!=null&&K.spec))}).map(s=>({raw:s,name:j(s.id||s.title||"query")}));P(y,s=>s.name);const k=e.views.filter(s=>fe(s)&&!("sdkSpec"in s)).map(s=>sn(s));for(const s of e.views)(!("sdkSpec"in s)||!((b=s.sdkSpec)!=null&&b.builder)||!((E=s.sdkSpec)!=null&&E.spec))&&!fe(s)&&n.push(`Skipped view ${s.id||s.title||"unknown"} because it has no sdkSpec.`);return Ee({inputs:w,views:y,filterContracts:e.filterContracts}),{summary:e,title:e.title||"Semaphor Data App",sources:o,fields:u,inputs:w,optionQueries:f,views:y,presentationViews:k,filterContracts:e.filterContracts,checklist:t,sourceNameByKey:a,fieldNameByKey:c,warnings:n}}function Ee({inputs:e,views:n,filterContracts:r}){const t=new Set(e.map(a=>a.raw.id).filter(Boolean)),o=new Set(n.map(a=>a.raw.id).filter(Boolean));for(const[a,u]of r.entries()){if(!t.has(u.inputId))throw new Error(`filterContracts.${a}.inputId must reference a generated input.`);const c=new Set(u.appliesToViewIds||[]),w=new Set(u.notAppliedToViewIds||[]);for(const[f,y]of(u.appliesToViewIds||[]).entries())if(!o.has(y))throw new Error(`filterContracts.${a}.appliesToViewIds.${f} must reference an executable generated view.`);for(const[f,y]of(u.notAppliedToViewIds||[]).entries())if(!o.has(y))throw new Error(`filterContracts.${a}.notAppliedToViewIds.${f} must reference an executable generated view.`);for(const[f,y]of(u.bindings||[]).entries()){if(!o.has(y.viewId))throw new Error(`filterContracts.${a}.bindings.${f}.viewId must reference an executable generated view.`);if(!c.has(y.viewId))throw new Error(`filterContracts.${a}.bindings.${f}.viewId must be included in appliesToViewIds.`);if(w.has(y.viewId))throw new Error(`filterContracts.${a}.bindings.${f}.viewId must not be listed in notAppliedToViewIds.`)}}}function ke(e){return{"sources.ts":ve(e),"fields.ts":qe(e),"inputs.ts":De(e),"queries.ts":Pe(e),"bindings.ts":Le(e),"accessors.ts":Ye(e),"metadata.ts":We(e),"index.ts":Xe(),"USAGE.md":Ae(e)}}function Ne({contract:e,files:n,generatorName:r,generatorVersion:t}){return{schemaVersion:R.CONTRACT_MANIFEST_SCHEMA_VERSION,generatedContractSchemaVersion:R.GENERATED_CONTRACT_SCHEMA_VERSION,generator:{name:r,version:t},generatedContentHash:Ge(n),codegenSummaryValidatorVersion:R.CODEGEN_SUMMARY_VALIDATOR_VERSION,codegenSummaryHash:xe(e.summary),codegenSummary:e.summary}}function Ge(e){const n=he.createHash("sha256");for(const r of Object.keys(e).filter(t=>t.endsWith(".ts")).sort())n.update(r),n.update("\0"),n.update(e[r]),n.update("\0");return`sha256:${n.digest("hex")}`}function Ae(e){const n=["# Semaphor Generated Data App Contract","","Generated files in this directory are governed Semaphor analytics wiring. Do not hand-edit them.","","Use the app-facing exports from `index.ts`:","","- `queries`: generated governed query factories.","- `queryOptionsForView`: active-input wiring for each generated view.","- `rowsForView`: table/records row readers.","- `rowValuesForView`: friendly row object readers for chart/table views.","- `metricValuesForView`: friendly metric-value readers.","- `kpiPropsForView`: KPI component props derived from runtime metric results.","- `roleValuesForView`: canonical dimension/measure/date/id role readers.","- `appInputSpecs`: generated input/filter specs.","- `inputOptionQueries`: option-list query factories for generated inputs.","- `semaphorGeneratedContractMetadata`: generated view/input metadata and presentation-only views.","","Start with these exports before opening large generated internals such as `metadata.ts`.",""];return e.views.length>0&&(n.push("Generated executable views:"),e.views.forEach(r=>{n.push(`- \`${r.raw.id}\`: ${r.raw.title||r.name}`)}),n.push("")),e.inputs.length>0&&(n.push("Generated inputs:"),e.inputs.forEach(r=>{n.push(`- \`${r.raw.id}\`: ${r.raw.label||r.name}`)}),n.push("")),`${n.join(`
5
+ `)}
6
+ `}function xe(e){return`sha256:${he.createHash("sha256").update(ue(e)).digest("hex")}`}function ue(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(t=>ue(t)).join(",")}]`;const n=e;return`{${Object.keys(n).sort().filter(t=>n[t]!==void 0).map(t=>`${JSON.stringify(t)}:${ue(n[t])}`).join(",")}}`}function Te(e){const n=e.views.find(f=>T(f)&&_(f));if(n)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, recordsSortOptionsForView, rowsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const sortOption = recordsSortOptionsForView.${n.name}[0];`,'const sort = sortOption ? { key: sortOption.key, direction: "asc" as const } : undefined;',`const query = queries.${n.name}({ page, pageSize, sort });`,`const result = useSemaphorQuery(query, queryOptionsForView.${n.name}(inputHandles));`,`const rows = rowsForView.${n.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
5
7
  `);const r=e.views.find(f=>T(f));if(r)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, recordsSortOptionsForView, rowsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const sortOption = recordsSortOptionsForView.${r.name}[0];`,'const sort = sortOption ? { key: sortOption.key, direction: "asc" as const } : undefined;',`const query = queries.${r.name}({ sort });`,`const result = useSemaphorQuery(query, queryOptionsForView.${r.name}(inputHandles));`,`const rows = rowsForView.${r.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
6
- `);const t=e.views.find(f=>X(f)&&_(f));if(t)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const query = queries.${t.name}({ page, pageSize });`,`const result = useSemaphorQuery(query, queryOptionsForView.${t.name}(inputHandles));`,`const rows = rowsForView.${t.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
8
+ `);const t=e.views.find(f=>Z(f)&&_(f));if(t)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const query = queries.${t.name}({ page, pageSize });`,`const result = useSemaphorQuery(query, queryOptionsForView.${t.name}(inputHandles));`,`const rows = rowsForView.${t.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
7
9
  `);const o=e.views.find(f=>pe(f)&&_(f));if(o)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const query = queries.${o.name}({ page, pageSize });`,`const result = useSemaphorQuery(query, queryOptionsForView.${o.name}(inputHandles));`,`const rows = rowsForView.${o.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
8
- `);const a=e.views.find(f=>{var m;return cn((m=f.raw.sdkSpec)==null?void 0:m.builder)});if(a)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const result = useSemaphorQuery(queries.${a.name}(), queryOptionsForView.${a.name}(inputHandles));`,`const rows = rowsForView.${a.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
9
- `);const l=e.views.find(f=>Te(f));if(l)return['import { appInputSpecs, createInputHandleMap, metricValuesForView, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const result = useSemaphorQuery(queries.${l.name}(), queryOptionsForView.${l.name}(inputHandles));`,`const metrics = metricValuesForView.${l.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
10
- `);const y=e.views[0];return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",y?`const result = useSemaphorQuery(queries.${y.name}(), queryOptionsForView.${y.name}(inputHandles));`:"const result = undefined;","const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
11
- `)}function X(e){var n;return j((n=e.raw.sdkSpec)==null?void 0:n.builder)==="records"}function Te(e){var n;return j((n=e.raw.sdkSpec)==null?void 0:n.builder)==="metric"}function T(e){var n,r,t;return X(e)&&((t=(r=(n=e.raw.visualSpec)==null?void 0:n.tableBehavior)==null?void 0:r.sorting)==null?void 0:t.mode)==="server"}function pe(e){var n;return j((n=e.raw.sdkSpec)==null?void 0:n.builder)==="sql"}function _(e){var n,r,t;return((t=(r=(n=e.raw.visualSpec)==null?void 0:n.tableBehavior)==null?void 0:r.pagination)==null?void 0:t.mode)==="server"}function _e(e){return X(e)&&(_(e)||T(e))||pe(e)&&_(e)}function Ke(e){const n=e.sources.map(({name:t,raw:o})=>{const a=He(o);return` ${t}: ${a},`}).join(`
10
+ `);const a=e.views.find(f=>{var y;return mn((y=f.raw.sdkSpec)==null?void 0:y.builder)});if(a)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const result = useSemaphorQuery(queries.${a.name}(), queryOptionsForView.${a.name}(inputHandles));`,`const rows = rowsForView.${a.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
11
+ `);const u=e.views.find(f=>_e(f));if(u)return['import { appInputSpecs, createInputHandleMap, kpiPropsForView, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const result = useSemaphorQuery(queries.${u.name}(), queryOptionsForView.${u.name}(inputHandles));`,`const kpiProps = kpiPropsForView.${u.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
12
+ `);const c=e.views[0];return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",c?`const result = useSemaphorQuery(queries.${c.name}(), queryOptionsForView.${c.name}(inputHandles));`:"const result = undefined;","const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
13
+ `)}function Z(e){var n;return q((n=e.raw.sdkSpec)==null?void 0:n.builder)==="records"}function _e(e){var n;return q((n=e.raw.sdkSpec)==null?void 0:n.builder)==="metric"}function T(e){var n,r,t;return Z(e)&&((t=(r=(n=e.raw.visualSpec)==null?void 0:n.tableBehavior)==null?void 0:r.sorting)==null?void 0:t.mode)==="server"}function pe(e){var n;return q((n=e.raw.sdkSpec)==null?void 0:n.builder)==="sql"}function _(e){var n,r,t;return((t=(r=(n=e.raw.visualSpec)==null?void 0:n.tableBehavior)==null?void 0:r.pagination)==null?void 0:t.mode)==="server"}function He(e){return Z(e)&&(_(e)||T(e))||pe(e)&&_(e)}function ve(e){const n=e.sources.map(({name:t,raw:o})=>{const a=je(o);return` ${t}: ${a},`}).join(`
12
14
  `),r=e.sources.some(t=>t.raw.kind==="semantic")?`import { semaphor } from "react-semaphor/data-app-sdk";
13
15
 
14
- `:"";return`${K}
16
+ `:"";return`${H}
15
17
  ${r}export const sources = {
16
18
  ${n}
17
19
  } as const;
18
- `}function He(e){if(e.kind==="semantic"){const n={domainId:e.domainId,datasetId:e.datasetId,datasetName:e.datasetName,label:e.label};return`semaphor.source.semantic(${k(A(n))})`}return`${k(A({...e,sourceKey:void 0}))} as const`}function ve(e){const n=e.fields.map(({name:t,raw:o})=>{const a=qe(o,e);return` ${t}: ${a},`}).join(`
20
+ `}function je(e){if(e.kind==="semantic"){const n={domainId:e.domainId,datasetId:e.datasetId,datasetName:e.datasetName,label:e.label};return`semaphor.source.semantic(${C(A(n))})`}return`${C(A({...e,sourceKey:void 0}))} as const`}function qe(e){const n=e.fields.map(({name:t,raw:o})=>{const a=Ke(o,e);return` ${t}: ${a},`}).join(`
19
21
  `),r=n.includes("sources.")?`import { sources } from "./sources";
20
22
 
21
- `:"";return`${K}
23
+ `:"";return`${H}
22
24
  ${r}export const fields = {
23
25
  ${n}
24
26
  } as const;
25
- `}function qe(e,n){const r={name:e.name,label:e.label,role:e.role,dataType:e.dataType,aggregate:e.aggregate},t=ln(e),o=t?n.sourceNameByKey.get(t):void 0;if(t&&!o)throw new Error(`Field ${e.name} references source ${t}, but that source is not renderable. Include the source in codegenSummary.sources or provide field.source.`);const a=Object.entries(A(r)).map(([l,y])=>`${JSON.stringify(l)}: ${x(y,n)}`);return o&&a.push(`"source": sources.${o}`),`{ ${a.join(", ")} }`}function je(e){const n=e.inputs.map(c=>{const i=N(c.raw.fieldRef,e),p=[`id: ${JSON.stringify(c.raw.id)}`,`label: ${JSON.stringify(c.raw.label||c.raw.id)}`,`operator: ${JSON.stringify(mn(c.raw))}`];if(i&&p.push(`field: fields.${i}`),c.raw.relationshipHint&&p.push(`relationshipHint: ${k(c.raw.relationshipHint)}`),!i)throw new Error(`Input ${c.raw.id||c.name} is missing a generated field reference.`);return` ${c.name}: semaphor.filter({ ${p.join(", ")} }),`}).join(`
26
- `),r=e.inputs.map(c=>`filterSpecs.${c.name}`).join(", "),t=e.inputs.map(c=>JSON.stringify(c.raw.id)).join(", "),o=e.optionQueries.map(c=>{const i=c.input.raw,p=c.raw,w=b(p.spec)||{},{id:g,inputId:$,source:F,sourceKey:M,valueField:V,labelField:C,population:s,dependencies:I,limit:B,...re}=w,z=p.sourceKey?{sourceKey:p.sourceKey}:p.source||F||(typeof M=="string"?{sourceKey:M}:void 0),te=$e(z,e),oe=N(p.valueFieldRef,e),se=N(p.labelFieldRef,e),ae=he(c),ie={...re,id:p.id||w.id||`${i.id}-options`,inputId:i.id,source:z,valueField:p.valueFieldRef,labelField:p.labelFieldRef,population:p.population||s,dependencies:ae,limit:p.limit||B||100};if(!te||!oe||!se)throw new Error(`Input option query ${p.id||`${i.id}-options`} is missing source, valueField, or labelField.`);const Ve=Object.entries(A(ie)).map(([be,Re])=>`${JSON.stringify(be)}: ${x(Re,e)}`);return` ${c.name}: semaphor.inputOptions({ ${Ve.join(", ")} }),`}).join(`
27
- `),a=e.optionQueries.map(c=>{const i=Be(e,c),p=i.length>0?"inputHandles":"_inputHandles",w=i.map(g=>{const $=N(g.raw.fieldRef,e);if(!$)throw new Error(`Input option query ${c.raw.id||`${c.input.raw.id}-options`} references input ${g.raw.id} without a generated field reference.`);const F=`inputHandles[${JSON.stringify(g.raw.id)}]`;return` if (${F}) {
28
- inputs.push(semaphor.bindInput(${F}, { field: fields.${$} }));
27
+ `}function Ke(e,n){const r={name:e.name,label:e.label,role:e.role,dataType:e.dataType,aggregate:e.aggregate},t=cn(e),o=t?n.sourceNameByKey.get(t):void 0;if(t&&!o)throw new Error(`Field ${e.name} references source ${t}, but that source is not renderable. Include the source in codegenSummary.sources or provide field.source.`);const a=Object.entries(A(r)).map(([u,c])=>`${JSON.stringify(u)}: ${G(c,n)}`);return o&&a.push(`"source": sources.${o}`),`{ ${a.join(", ")} }`}function De(e){const n=e.inputs.map(m=>{const i=O(m.raw.fieldRef,e),l=[`id: ${JSON.stringify(m.raw.id)}`,`label: ${JSON.stringify(m.raw.label||m.raw.id)}`,`operator: ${JSON.stringify(fn(m.raw))}`];if(i&&l.push(`field: fields.${i}`),m.raw.relationshipHint&&l.push(`relationshipHint: ${C(m.raw.relationshipHint)}`),!i)throw new Error(`Input ${m.raw.id||m.name} is missing a generated field reference.`);return` ${m.name}: semaphor.filter({ ${l.join(", ")} }),`}).join(`
28
+ `),r=e.inputs.map(m=>`filterSpecs.${m.name}`).join(", "),t=e.inputs.map(m=>JSON.stringify(m.raw.id)).join(", "),o=e.optionQueries.map(m=>{const i=m.input.raw,l=m.raw,g=F(l.spec)||{},{id:h,inputId:I,source:$,sourceKey:M,valueField:b,labelField:E,population:s,dependencies:V,limit:K,...re}=g,J=l.sourceKey?{sourceKey:l.sourceKey}:l.source||$||(typeof M=="string"?{sourceKey:M}:void 0),te=$e(J,e),oe=O(l.valueFieldRef,e),se=O(l.labelFieldRef,e),ae=ge(m),ie={...re,id:l.id||g.id||`${i.id}-options`,inputId:i.id,source:J,valueField:l.valueFieldRef,labelField:l.labelFieldRef,population:l.population||s,dependencies:ae,limit:l.limit||K||100};if(!te||!oe||!se)throw new Error(`Input option query ${l.id||`${i.id}-options`} is missing source, valueField, or labelField.`);const Fe=Object.entries(A(ie)).map(([be,Re])=>`${JSON.stringify(be)}: ${G(Re,e)}`);return` ${m.name}: semaphor.inputOptions({ ${Fe.join(", ")} }),`}).join(`
29
+ `),a=e.optionQueries.map(m=>{const i=Be(e,m),l=i.length>0?"inputHandles":"_inputHandles",g=i.map(h=>{const I=O(h.raw.fieldRef,e);if(!I)throw new Error(`Input option query ${m.raw.id||`${m.input.raw.id}-options`} references input ${h.raw.id} without a generated field reference.`);const $=`inputHandles[${JSON.stringify(h.raw.id)}]`;return` if (${$}) {
30
+ inputs.push(semaphor.bindInput(${$}, { field: fields.${I} }));
29
31
  }`}).join(`
30
- `);return` ${c.name}(${p}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
32
+ `);return` ${m.name}(${l}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
31
33
  const inputs: SemaphorInputReference[] = [];
32
- ${w}
34
+ ${g}
33
35
  return inputs;
34
36
  },`}).join(`
35
37
 
36
- `),l=e.optionQueries.map(c=>` ${c.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
38
+ `),u=e.optionQueries.map(m=>` ${m.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
37
39
  return {
38
- inputs: inputsForInputOptionQuery.${c.name}(inputHandles),
40
+ inputs: inputsForInputOptionQuery.${m.name}(inputHandles),
39
41
  };
40
42
  },`).join(`
41
43
 
42
- `),y=e.optionQueries.map(c=>` case ${JSON.stringify(c.raw.id||`${c.input.raw.id}-options`)}:
43
- return queryOptionsForInputOptionQuery.${c.name}(inputHandles);`).join(`
44
- `),S=e.inputs.length>0,f=e.optionQueries.length>0,m=f?"inputOptionQueryId":"_inputOptionQueryId",O=f?"inputHandles":"_inputHandles",u=["SemaphorInputHandle",f?"SemaphorInputReference":void 0,"SemaphorQueryRuntimeOptions"].filter(G).join(", "),d=[S||f?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,`import type { ${u} } from "react-semaphor/data-app-sdk";`,S||f?'import { fields } from "./fields";':void 0,f?'import { sources } from "./sources";':void 0,'import type { SemaphorGeneratedInputId, SemaphorGeneratedInputOptionQueryId } from "./metadata";'].filter(G).join(`
45
- `);return`${K}
46
- ${d}
44
+ `),c=e.optionQueries.map(m=>` case ${JSON.stringify(m.raw.id||`${m.input.raw.id}-options`)}:
45
+ return queryOptionsForInputOptionQuery.${m.name}(inputHandles);`).join(`
46
+ `),w=e.inputs.length>0,f=e.optionQueries.length>0,y=f?"inputOptionQueryId":"_inputOptionQueryId",k=f?"inputHandles":"_inputHandles",d=["SemaphorInputHandle",f?"SemaphorInputReference":void 0,"SemaphorQueryRuntimeOptions"].filter(x).join(", "),p=[w||f?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,`import type { ${d} } from "react-semaphor/data-app-sdk";`,w||f?'import { fields } from "./fields";':void 0,f?'import { sources } from "./sources";':void 0,'import type { SemaphorGeneratedInputId, SemaphorGeneratedInputOptionQueryId } from "./metadata";'].filter(x).join(`
47
+ `);return`${H}
48
+ ${p}
47
49
 
48
50
  export const filterSpecs = {
49
51
  ${n}
@@ -67,52 +69,52 @@ ${a}
67
69
  } as const;
68
70
 
69
71
  export const queryOptionsForInputOptionQuery = {
70
- ${l}
72
+ ${u}
71
73
  } as const;
72
74
 
73
75
  export function queryOptionsForInputOptionQueryId(
74
- ${m}: SemaphorGeneratedInputOptionQueryId,
75
- ${O}: SemaphorGeneratedInputHandleMap,
76
+ ${y}: SemaphorGeneratedInputOptionQueryId,
77
+ ${k}: SemaphorGeneratedInputHandleMap,
76
78
  ): SemaphorQueryRuntimeOptions {
77
- switch (${m}) {
78
- ${y}
79
+ switch (${y}) {
80
+ ${c}
79
81
  }
80
- throw new Error(\`Unknown generated Semaphor input option query id: \${${m}}\`);
82
+ throw new Error(\`Unknown generated Semaphor input option query id: \${${y}}\`);
81
83
  }
82
- `}function Be(e,n){const r=he(n);if(!r||r.mode==="independent")return[];if(r.mode!=="explicit")return[];const t=new Set(r.includeInputIds||[]),o=new Set([n.input.raw.id,...r.excludeInputIds||[]]);return e.inputs.filter(a=>o.has(a.raw.id)?!1:t.has(a.raw.id))}function he(e){var n;return e.raw.dependencies||((n=e.raw.spec)==null?void 0:n.dependencies)}function Qe(e){const n=e.views.map(d=>{var p,w,g,$,F,M;const c=j(d.raw.sdkSpec.builder),i=De(d);if(X(d)&&_e(d)){const V=(p=d.raw.visualSpec)==null?void 0:p.tableBehavior,C=b(i.pagination),s=_(d),I=T(d),B=((w=V==null?void 0:V.pagination)==null?void 0:w.pageSize)||Y(C==null?void 0:C.pageSize)||Y(i.limit)||100,re=I?W(d,e):[],z=I?Pe({view:d,contract:e,sortFields:re,defaultField:(g=V==null?void 0:V.sorting)==null?void 0:g.defaultField}):void 0,te=I?($=V==null?void 0:V.sorting)==null?void 0:$.defaultDirection:void 0,oe=Ue({viewName:d.name,supportsPagination:s,supportsSort:I}),se=I?` const orderBy = resolveRecordsOrderBy(
83
- recordsSortFieldsForView.${d.name},
84
+ `}function Be(e,n){const r=ge(n);if(!r||r.mode==="independent")return[];if(r.mode!=="explicit")return[];const t=new Set(r.includeInputIds||[]),o=new Set([n.input.raw.id,...r.excludeInputIds||[]]);return e.inputs.filter(a=>o.has(a.raw.id)?!1:t.has(a.raw.id))}function ge(e){var n;return e.raw.dependencies||((n=e.raw.spec)==null?void 0:n.dependencies)}function Pe(e){const n=e.views.map(p=>{var l,g,h,I,$,M;const m=q(p.raw.sdkSpec.builder),i=Qe(p);if(Z(p)&&He(p)){const b=(l=p.raw.visualSpec)==null?void 0:l.tableBehavior,E=F(i.pagination),s=_(p),V=T(p),K=((g=b==null?void 0:b.pagination)==null?void 0:g.pageSize)||L(E==null?void 0:E.pageSize)||L(i.limit)||100,re=V?z(p,e):[],J=V?Ue({view:p,contract:e,sortFields:re,defaultField:(h=b==null?void 0:b.sorting)==null?void 0:h.defaultField}):void 0,te=V?(I=b==null?void 0:b.sorting)==null?void 0:I.defaultDirection:void 0,oe=Je({viewName:p.name,supportsPagination:s,supportsSort:V}),se=V?` const orderBy = resolveRecordsOrderBy(
85
+ recordsSortFieldsForView.${p.name},
84
86
  params.sort,
85
- ${x(z,e)},
86
- ${x(te,e)},
87
+ ${G(J,e)},
88
+ ${G(te,e)},
87
89
  );
88
- `:"",ae=I?` ...(orderBy ? { orderBy } : {}),
89
- `:"",ie=s?` pagination: resolveServerTablePagination(params, ${JSON.stringify(B)}),
90
- `:"";return` ${d.name}(
90
+ `:"",ae=V?` ...(orderBy ? { orderBy } : {}),
91
+ `:"",ie=s?` pagination: resolveServerTablePagination(params, ${JSON.stringify(K)}),
92
+ `:"";return` ${p.name}(
91
93
  params: ${oe} = {},
92
94
  ) {
93
- ${se} return semaphor.${c}({
94
- ...${x(i,e)},
95
+ ${se} return semaphor.${m}({
96
+ ...${G(i,e)},
95
97
  ${ae}${ie} });
96
- },`}if(pe(d)&&_(d)){const V=(F=d.raw.visualSpec)==null?void 0:F.tableBehavior,C=b(i.pagination),s=((M=V==null?void 0:V.pagination)==null?void 0:M.pageSize)||Y(C==null?void 0:C.pageSize)||Y(i.limit)||100;return` ${d.name}(
98
+ },`}if(pe(p)&&_(p)){const b=($=p.raw.visualSpec)==null?void 0:$.tableBehavior,E=F(i.pagination),s=((M=b==null?void 0:b.pagination)==null?void 0:M.pageSize)||L(E==null?void 0:E.pageSize)||L(i.limit)||100;return` ${p.name}(
97
99
  params: SemaphorGeneratedServerPaginationParams = {},
98
100
  ) {
99
- return semaphor.${c}({
100
- ...${x(i,e)},
101
+ return semaphor.${m}({
102
+ ...${G(i,e)},
101
103
  pagination: resolveServerTablePagination(params, ${JSON.stringify(s)}),
102
104
  });
103
- },`}return` ${d.name}: () => semaphor.${c}(${x(i,e)}),`}).join(`
104
- `),r=e.views.filter(d=>T(d)).map(d=>{const i=W(d,e).map(p=>` ${JSON.stringify(p.key)}: fields.${p.fieldName},`).join(`
105
- `);return` ${d.name}: {
105
+ },`}return` ${p.name}: () => semaphor.${m}(${G(i,e)}),`}).join(`
106
+ `),r=e.views.filter(p=>T(p)).map(p=>{const i=z(p,e).map(l=>` ${JSON.stringify(l.key)}: fields.${l.fieldName},`).join(`
107
+ `);return` ${p.name}: {
106
108
  ${i}
107
109
  },`}).join(`
108
- `),t=e.views.filter(d=>T(d)).map(d=>{const i=W(d,e).map(p=>` { key: ${JSON.stringify(p.key)}, label: ${JSON.stringify(p.label)}, field: fields.${p.fieldName} },`).join(`
109
- `);return` ${d.name}: [
110
+ `),t=e.views.filter(p=>T(p)).map(p=>{const i=z(p,e).map(l=>` { key: ${JSON.stringify(l.key)}, label: ${JSON.stringify(l.label)}, field: fields.${l.fieldName} },`).join(`
111
+ `);return` ${p.name}: [
110
112
  ${i}
111
113
  ],`}).join(`
112
- `),o=e.views.some(d=>T(d)),a=e.views.some(d=>_(d)),l=[n,r,t].join(`
113
- `),y=[n?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,o?'import type { SemaphorFieldRef } from "react-semaphor/data-app-sdk";':void 0,l.includes("fields.")?'import { fields } from "./fields";':void 0,l.includes("sources.")?'import { sources } from "./sources";':void 0].filter(G).join(`
114
- `);return`${K}
115
- ${y}
114
+ `),o=e.views.some(p=>T(p)),a=e.views.some(p=>_(p)),u=[n,r,t].join(`
115
+ `),c=[n?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,o?'import type { SemaphorFieldRef } from "react-semaphor/data-app-sdk";':void 0,u.includes("fields.")?'import { fields } from "./fields";':void 0,u.includes("sources.")?'import { sources } from "./sources";':void 0].filter(x).join(`
116
+ `);return`${H}
117
+ ${c}
116
118
  ${o?`export type SemaphorGeneratedRecordsSortDirection = "asc" | "desc";
117
119
 
118
120
  export type SemaphorGeneratedRecordsSort<TSortKey extends string = string> = {
@@ -174,28 +176,28 @@ ${a?`function resolveServerTablePagination(
174
176
  };
175
177
  }
176
178
  `:""}
177
- `}function De(e){var a,l;const n=b((a=e.raw.sdkSpec)==null?void 0:a.spec)||{},{kind:r,id:t,...o}=n;return{...o,id:e.raw.id,label:((l=e.raw.visualSpec)==null?void 0:l.title)||e.raw.title||o.label}}function W(e,n){var a,l;const r=[],t=b((a=e.raw.sdkSpec)==null?void 0:a.spec)||{};for(const y of v(t.fields))h(r,y);h(r,t.dateField),h(r,(l=b(t.orderBy))==null?void 0:l.field);for(const y of e.raw.fields||[])h(r,y);return ne(r.map(y=>{const S=N(y,n);if(!(!y.name||!S))return{key:S,fieldName:S,rawName:y.name,label:y.label||y.name}}).filter(G),y=>y.key)}function Pe({view:e,contract:n,sortFields:r,defaultField:t}){var S,f;const o=new Set(r.map(m=>m.key));if(t&&o.has(t))return t;const a=r.filter(m=>m.rawName===t);if(a.length===1)return a[0].key;const l=b((S=e.raw.sdkSpec)==null?void 0:S.spec),y=N((f=b(l==null?void 0:l.orderBy))==null?void 0:f.field,n);return y&&o.has(y)?y:void 0}function Ue({viewName:e,supportsPagination:n,supportsSort:r}){return n&&r?`SemaphorGeneratedRecordsQueryParams<Extract<keyof typeof recordsSortFieldsForView.${e}, string>>`:r?`SemaphorGeneratedRecordsSortParams<Extract<keyof typeof recordsSortFieldsForView.${e}, string>>`:"SemaphorGeneratedServerPaginationParams"}function Le(e){const n=e.views.map(m=>{const u=Je(e,m.raw.id).map(d=>{const c=d.inputId,i=N(d.fieldRef,e);if(!c||!i)return"";const p=[`field: fields.${i}`];if(d.relationshipHint)p.push(`relationshipHint: ${k(d.relationshipHint)}`);else if(Array.isArray(d.relationshipsUsed)&&d.relationshipsUsed.length>0){const g=d.relationshipsUsed.map($=>{var F;return(F=b($))==null?void 0:F.id}).filter($=>typeof $=="string"&&$.length>0);g.length>0&&p.push(`relationshipHint: ${k({relationshipIds:g})}`)}const w=`inputHandles[${JSON.stringify(c)}]`;return` if (${w}) {
178
- inputs.push(semaphor.bindInput(${w}, { ${p.join(", ")} }));
179
+ `}function Qe(e){var a,u;const n=F((a=e.raw.sdkSpec)==null?void 0:a.spec)||{},{kind:r,id:t,...o}=n;return{...o,id:e.raw.id,label:((u=e.raw.visualSpec)==null?void 0:u.title)||e.raw.title||o.label}}function z(e,n){var a,u;const r=[],t=F((a=e.raw.sdkSpec)==null?void 0:a.spec)||{};for(const c of v(t.fields))S(r,c);S(r,t.dateField),S(r,(u=F(t.orderBy))==null?void 0:u.field);for(const c of e.raw.fields||[])S(r,c);return ne(r.map(c=>{const w=O(c,n);if(!(!c.name||!w))return{key:w,fieldName:w,rawName:c.name,label:c.label||c.name}}).filter(x),c=>c.key)}function Ue({view:e,contract:n,sortFields:r,defaultField:t}){var w,f;const o=new Set(r.map(y=>y.key));if(t&&o.has(t))return t;const a=r.filter(y=>y.rawName===t);if(a.length===1)return a[0].key;const u=F((w=e.raw.sdkSpec)==null?void 0:w.spec),c=O((f=F(u==null?void 0:u.orderBy))==null?void 0:f.field,n);return c&&o.has(c)?c:void 0}function Je({viewName:e,supportsPagination:n,supportsSort:r}){return n&&r?`SemaphorGeneratedRecordsQueryParams<Extract<keyof typeof recordsSortFieldsForView.${e}, string>>`:r?`SemaphorGeneratedRecordsSortParams<Extract<keyof typeof recordsSortFieldsForView.${e}, string>>`:"SemaphorGeneratedServerPaginationParams"}function Le(e){const n=e.views.map(y=>{const d=ze(e,y.raw.id).map(p=>{const m=p.inputId,i=O(p.fieldRef,e);if(!m||!i)return"";const l=[`field: fields.${i}`];if(p.relationshipHint)l.push(`relationshipHint: ${C(p.relationshipHint)}`);else if(Array.isArray(p.relationshipsUsed)&&p.relationshipsUsed.length>0){const h=p.relationshipsUsed.map(I=>{var $;return($=F(I))==null?void 0:$.id}).filter(I=>typeof I=="string"&&I.length>0);h.length>0&&l.push(`relationshipHint: ${C({relationshipIds:h})}`)}const g=`inputHandles[${JSON.stringify(m)}]`;return` if (${g}) {
180
+ inputs.push(semaphor.bindInput(${g}, { ${l.join(", ")} }));
179
181
  }`}).filter(Boolean).join(`
180
- `);return{view:m,renderedBindings:u}}),r=n.some(m=>m.renderedBindings.length>0),t=n.map(({view:m,renderedBindings:O})=>{const u=O?"inputHandles":"_inputHandles";return` ${m.name}(${u}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
182
+ `);return{view:y,renderedBindings:d}}),r=n.some(y=>y.renderedBindings.length>0),t=n.map(({view:y,renderedBindings:k})=>{const d=k?"inputHandles":"_inputHandles";return` ${y.name}(${d}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
181
183
  const inputs: SemaphorInputReference[] = [];
182
- ${O}
184
+ ${k}
183
185
  return inputs;
184
186
  },`}).join(`
185
187
 
186
- `),o=e.views.map(m=>` ${m.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
188
+ `),o=e.views.map(y=>` ${y.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
187
189
  return {
188
- inputs: inputsForView.${m.name}(inputHandles),
189
- debug: queryDebugForView.${m.name},
190
+ inputs: inputsForView.${y.name}(inputHandles),
191
+ debug: queryDebugForView.${y.name},
190
192
  };
191
193
  },`).join(`
192
194
 
193
- `),a=e.views.map(m=>` case ${JSON.stringify(m.raw.id)}:
194
- return inputsForView.${m.name}(inputHandles);`).join(`
195
- `),l=e.views.map(m=>` case ${JSON.stringify(m.raw.id)}:
196
- return queryOptionsForView.${m.name}(inputHandles);`).join(`
197
- `),y=e.views.length>0,S=y?"inputHandles":"_inputHandles",f=[r?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,'import type { SemaphorInputReference, SemaphorQueryRuntimeOptions } from "react-semaphor/data-app-sdk";',r?'import { fields } from "./fields";':void 0,'import type { SemaphorGeneratedInputHandleMap } from "./inputs";',y?'import { queryDebugForView } from "./metadata";':void 0,'import type { SemaphorGeneratedQueryViewId } from "./metadata";'].filter(G).join(`
198
- `);return`${K}
195
+ `),a=e.views.map(y=>` case ${JSON.stringify(y.raw.id)}:
196
+ return inputsForView.${y.name}(inputHandles);`).join(`
197
+ `),u=e.views.map(y=>` case ${JSON.stringify(y.raw.id)}:
198
+ return queryOptionsForView.${y.name}(inputHandles);`).join(`
199
+ `),c=e.views.length>0,w=c?"inputHandles":"_inputHandles",f=[r?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,'import type { SemaphorInputReference, SemaphorQueryRuntimeOptions } from "react-semaphor/data-app-sdk";',r?'import { fields } from "./fields";':void 0,'import type { SemaphorGeneratedInputHandleMap } from "./inputs";',c?'import { queryDebugForView } from "./metadata";':void 0,'import type { SemaphorGeneratedQueryViewId } from "./metadata";'].filter(x).join(`
200
+ `);return`${H}
199
201
  ${f}
200
202
 
201
203
  export const inputsForView = {
@@ -208,7 +210,7 @@ ${o}
208
210
 
209
211
  export function inputsForViewId(
210
212
  viewId: SemaphorGeneratedQueryViewId,
211
- ${S}: SemaphorGeneratedInputHandleMap,
213
+ ${w}: SemaphorGeneratedInputHandleMap,
212
214
  ): SemaphorInputReference[] {
213
215
  switch (viewId) {
214
216
  ${a}
@@ -218,81 +220,103 @@ ${a}
218
220
 
219
221
  export function queryOptionsForViewId(
220
222
  viewId: SemaphorGeneratedQueryViewId,
221
- ${S}: SemaphorGeneratedInputHandleMap,
223
+ ${w}: SemaphorGeneratedInputHandleMap,
222
224
  ): SemaphorQueryRuntimeOptions {
223
225
  switch (viewId) {
224
- ${l}
226
+ ${u}
225
227
  }
226
228
  throw new Error(\`Unknown generated Semaphor view id: \${viewId}\`);
227
229
  }
228
- `}function Je(e,n){return e.filterContracts.flatMap(r=>(r.bindings||[]).filter(t=>t.viewId===n).map(t=>({inputId:r.inputId,fieldRef:t.fieldRef,relationshipHint:t.relationshipHint,relationshipsUsed:t.relationshipsUsed})))}function ze(e){const n=e.views.map(i=>{const w=U(i,e).map(g=>{const $=N(g.raw,e);return $?` ${g.name}: fields.${$},`:""}).filter(Boolean).join(`
229
- `);return` ${i.name}: {
230
- ${w}
231
- },`}).join(`
232
- `),r=e.views.map(i=>{const w=P(i,e).map(g=>{const $=N(g.raw,e);return $?` ${g.name}: fields.${$},`:""}).filter(Boolean).join(`
230
+ `}function ze(e,n){return e.filterContracts.flatMap(r=>(r.bindings||[]).filter(t=>t.viewId===n).map(t=>({inputId:r.inputId,fieldRef:t.fieldRef,relationshipHint:t.relationshipHint,relationshipsUsed:t.relationshipsUsed})))}function Ye(e){const n=e.views.map(i=>{const g=Q(i,e).map(h=>{const I=O(h.raw,e);return I?` ${h.name}: fields.${I},`:""}).filter(Boolean).join(`
233
231
  `);return` ${i.name}: {
234
- ${w}
232
+ ${g}
235
233
  },`}).join(`
236
- `),t=e.views.map(i=>{const p=P(i,e),w=rn(p),g=nn(p),$=p.map(F=>{const M=Array.from(new Set(Se(F.raw).filter(V=>g.has(V))));return` ${F.name}: metricKeysForField(metricFieldsForView.${i.name}.${F.name}, { allowNameFallback: ${w.has(F.raw.name)?"false":"true"}, excludedKeys: ${k(M)} }),`}).join(`
234
+ `),r=e.views.map(i=>{const g=B(i,e).map(h=>{const I=O(h.raw,e);return I?` ${h.name}: fields.${I},`:""}).filter(Boolean).join(`
237
235
  `);return` ${i.name}: {
238
- ${$}
236
+ ${g}
239
237
  },`}).join(`
240
- `),o=e.views.map(i=>{const w=P(i,e).map((g,$)=>` ${g.name}: ${JSON.stringify(Xe(i,g,$))},`).join(`
238
+ `),t=e.views.map(i=>{const g=B(i,e).map((h,I)=>` ${h.name}: ${JSON.stringify(en(i,h,I))},`).join(`
241
239
  `);return` ${i.name}: {
242
- ${w}
240
+ ${g}
243
241
  },`}).join(`
244
- `),a=e.views.map(i=>{const p=P(i,e);if(p.length===0)return` ${i.name}(): Record<keyof typeof metricFieldsForView.${i.name}, unknown> {
242
+ `),o=e.views.map(i=>{const l=B(i,e);if(l.length===0)return` ${i.name}(): Record<keyof typeof metricFieldsForView.${i.name}, unknown> {
245
243
  return {};
246
- },`;const w=en(i,p),g=p.map($=>{const F=`metricMeasureKeysForView.${i.name}.${$.name}`,M=`metricMeasureBindingKeysForView.${i.name}.${$.name}`,V=w.has($.name)?`readMetricValueByBindingWithFallback(measures, measureBindings, ${M}, ${F}, primaryValue)`:`readMetricValueByBinding(measures, measureBindings, ${M}, ${F})`;return` ${$.name}: ${V},`}).join(`
244
+ },`;const g=l.map(h=>{const $=`readMetricValueByBinding(measures, measureBindings, ${`metricMeasureBindingKeysForView.${i.name}.${h.name}`})`;return` ${h.name}: ${$},`}).join(`
247
245
  `);return` ${i.name}(result: SemaphorGeneratedMetricResult): Record<keyof typeof metricFieldsForView.${i.name}, unknown> {
248
246
  const measures = result?.measures;
249
247
  const measureBindings = result?.measureBindings;
250
- const primaryValue = result?.primaryValue;
251
248
  return {
252
249
  ${g}
253
250
  };
254
251
  },`}).join(`
255
252
 
256
- `),l=e.views.map(i=>{const p=P(i,e);if(p.length===0)return` ${i.name}(): Array<keyof typeof metricFieldsForView.${i.name}> {
253
+ `),a=e.views.map(i=>{const l=B(i,e);if(l.length===0)return` ${i.name}(): Array<keyof typeof metricFieldsForView.${i.name}> {
257
254
  return [];
258
- },`;const w=p.map(g=>` ...(missing.has(metricMeasureBindingKeysForView.${i.name}.${g.name}) ? [${JSON.stringify(g.name)} as keyof typeof metricFieldsForView.${i.name}] : []),`).join(`
255
+ },`;const g=l.map((h,I)=>{const $=`metricMeasureBindingKeysForView.${i.name}.${h.name}`,M=I===0?`readMetricValueByBinding(measures, measureBindings, ${$}) === undefined && !hasOwnPrimaryMetricValue(result)`:`readMetricValueByBinding(measures, measureBindings, ${$}) === undefined`;return` ...(missing.has(${$}) || (${M}) ? [${JSON.stringify(h.name)} as keyof typeof metricFieldsForView.${i.name}] : []),`}).join(`
259
256
  `);return` ${i.name}(result: SemaphorGeneratedMetricResult): Array<keyof typeof metricFieldsForView.${i.name}> {
260
257
  const missing = new Set(result?.missingMeasures || []);
258
+ const measures = result?.measures;
259
+ const measureBindings = result?.measureBindings;
261
260
  return [
262
- ${w}
261
+ ${g}
263
262
  ];
264
263
  },`}).join(`
265
264
 
266
- `),y=e.views.map(i=>{const p=Ye(i,e);return` ${i.name}: ${k(p)},`}).join(`
267
- `),S=e.views.map(i=>{const w=U(i,e).map(g=>` ${g.name}: resolveColumnKey(columns, fieldsForView.${i.name}.${g.name}),`).join(`
265
+ `),u=e.views.map(i=>{const l=B(i,e);if(l.length===0)return"";const g=l[0],h=l.map($=>`{ key: ${JSON.stringify($.name)}, label: ${JSON.stringify($.raw.label||$.raw.name)} }`).join(", "),I=l.filter($=>$.name!==g.name).map($=>` if (missing.includes(${JSON.stringify($.name)})) delete values.${$.name};`).join(`
266
+ `);return` ${i.name}(result: SemaphorGeneratedMetricResult): SemaphorGeneratedKpiProps {
267
+ const values = mapMetricDisplayValues(metricValuesForView.${i.name}(result));
268
+ const missing = missingMetricMeasuresForView.${i.name}(result).map((key) => String(key));
269
+ const primaryMissing = missing.includes(${JSON.stringify(g.name)});
270
+ const boundPrimaryValue = values.${g.name};
271
+ const primaryValue = primaryMissing || boundPrimaryValue === undefined ? result?.primaryValue : boundPrimaryValue;
272
+ if (primaryMissing) values.${g.name} = metricDisplayValue(result?.primaryValue);
273
+ ${I}
274
+ return {
275
+ result: {
276
+ ...(result || {}),
277
+ primaryValue: metricDisplayValue(result?.primaryValue),
278
+ comparisonValue: metricDisplayValue(result?.comparisonValue),
279
+ measures: values,
280
+ },
281
+ title: ${JSON.stringify(i.raw.title||i.raw.id)},
282
+ label: ${JSON.stringify(g.raw.label||g.raw.name)},
283
+ value: metricDisplayValue(primaryValue),
284
+ measures: [${h}],
285
+ missingMeasures: missing,
286
+ showComparison: Boolean(result?.comparisonKind),
287
+ };
288
+ },`}).filter(Boolean).join(`
289
+
290
+ `),c=e.views.map(i=>{const l=Ze(i,e);return` ${i.name}: ${C(l)},`}).join(`
291
+ `),w=e.views.map(i=>{const g=Q(i,e).map(h=>` ${h.name}: resolveColumnKey(columns, fieldsForView.${i.name}.${h.name}),`).join(`
268
292
  `);return` ${i.name}(columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${i.name}, string | undefined> {
269
293
  return {
270
- ${w}
294
+ ${g}
271
295
  };
272
296
  },`}).join(`
273
297
 
274
- `),f=e.views.map(i=>{const w=U(i,e).map(g=>` ${g.name}: readCell(row, columns, fieldsForView.${i.name}.${g.name}),`).join(`
298
+ `),f=e.views.map(i=>{const g=Q(i,e).map(h=>` ${h.name}: readCell(row, columns, fieldsForView.${i.name}.${h.name}),`).join(`
275
299
  `);return` ${i.name}(row: SemaphorGeneratedRow, columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${i.name}, unknown> {
276
300
  return {
277
- ${w}
301
+ ${g}
278
302
  };
279
303
  },`}).join(`
280
304
 
281
- `),m=e.views.map(i=>` ${i.name}(result: SemaphorGeneratedRecordsResult): Array<Record<keyof typeof fieldsForView.${i.name}, unknown>> {
305
+ `),y=e.views.map(i=>` ${i.name}(result: SemaphorGeneratedRecordsResult): Array<Record<keyof typeof fieldsForView.${i.name}, unknown>> {
282
306
  return (result?.records || []).map((row) => rowValuesForView.${i.name}(row, result?.columns));
283
307
  },`).join(`
284
308
 
285
- `),O=e.views.map(i=>{const p=U(i,e),w=p.filter(s=>s.raw.role==="dimension"),g=p.filter(s=>s.raw.role==="measure"),$=w[0],F=w[1],M=g[0],V=g[1],C=[$?` primaryDimension: values.${$.name},`:" primaryDimension: undefined,",F?` secondaryDimension: values.${F.name},`:" secondaryDimension: undefined,",M?` primaryMeasure: values.${M.name},`:" primaryMeasure: undefined,",V?` secondaryMeasure: values.${V.name},`:" secondaryMeasure: undefined,"].join(`
309
+ `),k=e.views.map(i=>{const l=Q(i,e),g=l.filter(s=>s.raw.role==="dimension"),h=l.filter(s=>s.raw.role==="measure"),I=g[0],$=g[1],M=h[0],b=h[1],E=[I?` primaryDimension: values.${I.name},`:" primaryDimension: undefined,",$?` secondaryDimension: values.${$.name},`:" secondaryDimension: undefined,",M?` primaryMeasure: values.${M.name},`:" primaryMeasure: undefined,",b?` secondaryMeasure: values.${b.name},`:" secondaryMeasure: undefined,"].join(`
286
310
  `);return` ${i.name}(row: SemaphorGeneratedRow, columns: SemaphorGeneratedColumns): SemaphorGeneratedRoleValues {
287
311
  const values = rowValuesForView.${i.name}(row, columns);
288
312
  return {
289
- ${C}
313
+ ${E}
290
314
  };
291
315
  },`}).join(`
292
316
 
293
- `),u=n.includes("fields.")||r.includes("fields."),c=[`import { ${["type SemaphorFieldRef","type SemaphorResultColumn","semaphorMetricMeasureBindingKey"].filter(G).join(", ")} } from "react-semaphor/data-app-sdk";`,u?'import { fields } from "./fields";':void 0].filter(G).join(`
294
- `);return`${K}
295
- ${c}
317
+ `),d=n.includes("fields.")||r.includes("fields."),m=[`import { ${["type SemaphorFieldRef","type SemaphorResultColumn"].filter(x).join(", ")} } from "react-semaphor/data-app-sdk";`,d?'import { fields } from "./fields";':void 0].filter(x).join(`
318
+ `);return`${H}
319
+ ${m}
296
320
 
297
321
  export type SemaphorGeneratedRow = Record<string, unknown>;
298
322
  export type SemaphorGeneratedColumns = readonly SemaphorResultColumn[] | null | undefined;
@@ -302,12 +326,16 @@ export type SemaphorGeneratedRecordsResult = {
302
326
  } | null | undefined;
303
327
  export type SemaphorGeneratedMetricMeasures = Record<string, unknown> | null | undefined;
304
328
  export type SemaphorGeneratedMetricMeasureBindings = Record<string, string> | null | undefined;
329
+ export type SemaphorGeneratedMetricValue = number | string | null;
305
330
  export type SemaphorGeneratedMetricResult = {
306
331
  readonly measures?: SemaphorGeneratedMetricMeasures;
307
332
  readonly measureBindings?: SemaphorGeneratedMetricMeasureBindings;
308
333
  readonly missingMeasures?: readonly string[];
309
334
  readonly primaryValue: unknown;
310
- readonly value?: unknown;
335
+ readonly comparisonKind?: string;
336
+ readonly comparisonValue?: unknown;
337
+ readonly delta?: number | null;
338
+ readonly deltaPercent?: number | null;
311
339
  } | null | undefined;
312
340
  export type SemaphorGeneratedRoleValues = {
313
341
  readonly primaryDimension: unknown;
@@ -322,6 +350,28 @@ export type SemaphorGeneratedTableColumn = {
322
350
  readonly sortable?: boolean;
323
351
  readonly sortKey?: string;
324
352
  };
353
+ export type SemaphorGeneratedKpiResult<TValues extends Record<string, SemaphorGeneratedMetricValue> = Record<string, SemaphorGeneratedMetricValue>> =
354
+ Record<string, unknown> & {
355
+ readonly primaryValue?: SemaphorGeneratedMetricValue;
356
+ readonly comparisonValue?: SemaphorGeneratedMetricValue;
357
+ readonly comparisonKind?: string;
358
+ readonly delta?: number | null;
359
+ readonly deltaPercent?: number | null;
360
+ readonly measures: TValues;
361
+ };
362
+ export type SemaphorGeneratedKpiMeasureConfig = {
363
+ key: string;
364
+ label: string;
365
+ };
366
+ export type SemaphorGeneratedKpiProps = {
367
+ readonly result: SemaphorGeneratedKpiResult;
368
+ readonly title: string;
369
+ readonly label: string;
370
+ readonly value: SemaphorGeneratedMetricValue;
371
+ readonly measures: SemaphorGeneratedKpiMeasureConfig[];
372
+ readonly missingMeasures: readonly string[];
373
+ readonly showComparison: boolean;
374
+ };
325
375
 
326
376
  export const fieldsForView = {
327
377
  ${n}
@@ -331,20 +381,16 @@ export const metricFieldsForView = {
331
381
  ${r}
332
382
  } as const;
333
383
 
334
- export const metricMeasureKeysForView = {
335
- ${t}
336
- } as const;
337
-
338
384
  export const metricMeasureBindingKeysForView = {
339
- ${o}
385
+ ${t}
340
386
  } as const;
341
387
 
342
388
  export const tableColumnsForView = {
343
- ${y}
389
+ ${c}
344
390
  } as const;
345
391
 
346
392
  export const columnKeysForView = {
347
- ${S}
393
+ ${w}
348
394
  } as const;
349
395
 
350
396
  export const rowValuesForView = {
@@ -352,19 +398,23 @@ ${f}
352
398
  } as const;
353
399
 
354
400
  export const rowsForView = {
355
- ${m}
401
+ ${y}
356
402
  } as const;
357
403
 
358
404
  export const roleValuesForView = {
359
- ${O}
405
+ ${k}
360
406
  } as const;
361
407
 
362
408
  export const metricValuesForView = {
363
- ${a}
409
+ ${o}
364
410
  } as const;
365
411
 
366
412
  export const missingMetricMeasuresForView = {
367
- ${l}
413
+ ${a}
414
+ } as const;
415
+
416
+ export const kpiPropsForView = {
417
+ ${u}
368
418
  } as const;
369
419
 
370
420
  export function resolveColumnKey(
@@ -408,155 +458,42 @@ export function readStringCell(
408
458
  return value === null || value === undefined ? "" : String(value);
409
459
  }
410
460
 
411
- export function readMetricValue(
412
- measures: SemaphorGeneratedMetricMeasures,
413
- field: SemaphorFieldRef,
414
- ): unknown {
415
- return readMetricValueByKeys(measures, metricKeysForField(field));
416
- }
417
-
418
- export function readMetricValueByKeys(
419
- measures: SemaphorGeneratedMetricMeasures,
420
- keys: readonly string[],
421
- ): unknown {
422
- if (!measures) {
423
- return undefined;
424
- }
425
- for (const key of keys) {
426
- if (Object.prototype.hasOwnProperty.call(measures, key)) {
427
- return measures[key];
428
- }
429
- }
430
- return undefined;
431
- }
432
-
433
461
  export function readMetricValueByBinding(
434
462
  measures: SemaphorGeneratedMetricMeasures,
435
463
  measureBindings: SemaphorGeneratedMetricMeasureBindings,
436
464
  bindingKey: string,
437
- fallbackKeys: readonly string[],
438
465
  ): unknown {
439
466
  const resultKey = measureBindings?.[bindingKey];
440
467
  if (resultKey && measures && Object.prototype.hasOwnProperty.call(measures, resultKey)) {
441
468
  return measures[resultKey];
442
469
  }
443
- return readMetricValueByKeys(measures, fallbackKeys);
444
- }
445
-
446
- export function readMetricValueByKeysWithFallback(
447
- measures: SemaphorGeneratedMetricMeasures,
448
- keys: readonly string[],
449
- fallbackValue: unknown,
450
- ): unknown {
451
- const value = readMetricValueByKeys(measures, keys);
452
- return value === undefined ? fallbackValue : value;
453
- }
454
-
455
- export function readMetricValueByBindingWithFallback(
456
- measures: SemaphorGeneratedMetricMeasures,
457
- measureBindings: SemaphorGeneratedMetricMeasureBindings,
458
- bindingKey: string,
459
- fallbackKeys: readonly string[],
460
- fallbackValue: unknown,
461
- ): unknown {
462
- const value = readMetricValueByBinding(measures, measureBindings, bindingKey, fallbackKeys);
463
- return value === undefined ? fallbackValue : value;
464
- }
465
-
466
- export function readNumberMetricValue(
467
- measures: SemaphorGeneratedMetricMeasures,
468
- field: SemaphorFieldRef,
469
- ): number | null {
470
- const value = readMetricValue(measures, field);
471
- if (typeof value === "number") {
472
- return Number.isFinite(value) ? value : null;
473
- }
474
- if (typeof value === "string" && value.trim().length > 0) {
475
- const parsed = Number(value);
476
- return Number.isFinite(parsed) ? parsed : null;
477
- }
478
- return null;
479
- }
480
-
481
- export function readStringMetricValue(
482
- measures: SemaphorGeneratedMetricMeasures,
483
- field: SemaphorFieldRef,
484
- ): string {
485
- const value = readMetricValue(measures, field);
486
- return value === null || value === undefined ? "" : String(value);
487
- }
488
-
489
- export function metricKeysForField(
490
- field: SemaphorFieldRef,
491
- options: { allowNameFallback?: boolean; excludedKeys?: readonly string[] } = {},
492
- ): string[] {
493
- const prefixes = metricKeyPrefixesForSource(field.source);
494
- const aggregate = metricAggregateForField(field);
495
- const excludedKeys = new Set(options.excludedKeys || []);
496
- return uniqueStrings([
497
- metricQualifiedKeyForField(field),
498
- ...prefixes.map((prefix) => \`\${prefix}.\${field.name}\`),
499
- \`\${aggregate.toLowerCase()}_\${field.name}\`,
500
- \`\${aggregate}_\${field.name}\`,
501
- \`\${field.name}_\${aggregate.toLowerCase()}\`,
502
- \`\${field.name}_\${aggregate}\`,
503
- ...(options.allowNameFallback === false ? [] : [field.name]),
504
- ]).filter((key) => !excludedKeys.has(key));
470
+ return undefined;
505
471
  }
506
472
 
507
- function metricQualifiedKeyForField(field: SemaphorFieldRef): string {
508
- return semaphorMetricMeasureBindingKey(field);
473
+ export function hasOwnPrimaryMetricValue(
474
+ result: SemaphorGeneratedMetricResult,
475
+ ): boolean {
476
+ return Boolean(result && Object.prototype.hasOwnProperty.call(result, "primaryValue"));
509
477
  }
510
478
 
511
- function metricAggregateForField(field: SemaphorFieldRef): string {
512
- return stringProperty(field as Record<string, unknown>, "aggregate")?.toUpperCase() || "SUM";
479
+ export function mapMetricDisplayValues(
480
+ values: Record<string, unknown>,
481
+ ): Record<string, SemaphorGeneratedMetricValue> {
482
+ return Object.fromEntries(
483
+ Object.entries(values)
484
+ .map(([key, value]) => [key, metricDisplayValue(value)] as const)
485
+ .filter(([key]) => values[key] !== undefined),
486
+ );
513
487
  }
514
488
 
515
- function metricKeyPrefixesForSource(
516
- source: SemaphorFieldRef["source"] | undefined,
517
- ): string[] {
518
- if (!source) {
519
- return [];
489
+ export function metricDisplayValue(value: unknown): SemaphorGeneratedMetricValue {
490
+ if (value === null || value === undefined) {
491
+ return null;
520
492
  }
521
- const sourceRecord = source as Record<string, unknown>;
522
- if (source.kind === "semantic") {
523
- const prefixes: string[] = [];
524
- const datasetName = stringProperty(sourceRecord, "datasetName");
525
- const datasetId = stringProperty(sourceRecord, "datasetId");
526
- if (datasetName) {
527
- prefixes.push(datasetName);
528
- }
529
- if (datasetId) {
530
- prefixes.push(datasetId);
531
- }
532
- return uniqueStrings(prefixes);
493
+ if (typeof value === "number" || typeof value === "string") {
494
+ return value;
533
495
  }
534
- if (source.kind === "physical") {
535
- const prefixes: string[] = [];
536
- const databaseName = stringProperty(sourceRecord, "databaseName");
537
- const schemaName = stringProperty(sourceRecord, "schemaName");
538
- const tableName = stringProperty(sourceRecord, "tableName");
539
- if (tableName) {
540
- prefixes.push(tableName);
541
- }
542
- if (schemaName && tableName) {
543
- prefixes.push(\`\${schemaName}.\${tableName}\`);
544
- }
545
- if (databaseName && schemaName && tableName) {
546
- prefixes.push(\`\${databaseName}.\${schemaName}.\${tableName}\`);
547
- }
548
- return uniqueStrings(prefixes);
549
- }
550
- return [];
551
- }
552
-
553
- function stringProperty(record: Record<string, unknown>, key: string): string | undefined {
554
- const value = record[key];
555
- return typeof value === "string" && value.length > 0 ? value : undefined;
556
- }
557
-
558
- function uniqueStrings(values: string[]): string[] {
559
- return Array.from(new Set(values.filter((value) => value.length > 0)));
496
+ return String(value);
560
497
  }
561
498
 
562
499
  function resolveColumn(
@@ -661,13 +598,13 @@ function sourcesReferToSameDataset(
661
598
  }
662
599
  return false;
663
600
  }
664
- `}function Ye(e,n){const r=U(e,n),t=new Map((T(e)?W(e,n):[]).map(o=>[o.fieldName,o.key]));return r.map(o=>{const a=N(o.raw,n),l=a?t.get(a):void 0;return A({key:o.name,label:o.raw.label||o.raw.name,dataType:o.raw.dataType,sortable:!!l,sortKey:l})})}function We(e){const n=e.checklist.filterScopeByInput||[],r=e.checklist.requiredDevtools||{},t=e.summary.views.map(u=>u.id).filter(Boolean),o=e.views.map(u=>u.raw.id).filter(Boolean),a=e.inputs.map(u=>u.raw.id).filter(Boolean),l=e.optionQueries.map(u=>u.raw.id||`${u.input.raw.id}-options`).filter(Boolean),y=Object.fromEntries(o.map(u=>[u,e.filterContracts.filter(d=>Array.isArray(d.appliesToViewIds)&&d.appliesToViewIds.includes(u)).map(d=>d.inputId)])),S=Object.fromEntries(e.views.map(u=>[u.raw.id,{title:u.raw.title,visual:u.raw.visual,visualSpec:u.raw.visualSpec,queryKind:u.raw.queryKind,sdkBuilder:u.raw.sdkBuilder}])),f=Object.fromEntries(e.views.map(u=>{var d;return[u.raw.id,A({viewId:u.raw.id,queryId:u.name,title:u.raw.title,visualType:((d=u.raw.visualSpec)==null?void 0:d.visualType)||u.raw.visual,suggestedComponentName:ye(u.raw.title||u.raw.id||u.name),marker:{attribute:"data-semaphor-view-id",value:u.raw.id}})]})),m=Object.fromEntries(e.inputs.map(u=>{var d;return[u.raw.id,A({inputId:u.raw.id,label:u.raw.label,type:u.raw.type,optionQueryId:((d=u.raw.optionQuery)==null?void 0:d.id)||(u.raw.optionQuery?`${u.raw.id}-options`:void 0),suggestedComponentName:ye(u.raw.label||u.raw.id||u.name),marker:{attribute:"data-semaphor-input-id",value:u.raw.id}})]})),O=Object.fromEntries(e.views.map(u=>{var d,c,i;return[u.name,A({viewId:u.raw.id,viewTitle:((d=u.raw.visualSpec)==null?void 0:d.title)||u.raw.title,visualType:(c=u.raw.visualSpec)==null?void 0:c.visualType,title:((i=u.raw.visualSpec)==null?void 0:i.title)||u.raw.title})]}));return`${K}
665
- export const generatedViewIds = ${k(t)} as const;
666
- export const generatedQueryViewIds = ${k(o)} as const;
667
- export const generatedInputIds = ${k(a)} as const;
668
- export const generatedInputOptionQueryIds = ${k(l)} as const;
669
- export const generatedViewAuthoring = ${k(f)} as const;
670
- export const generatedInputAuthoring = ${k(m)} as const;
601
+ `}function Ze(e,n){const r=Q(e,n),t=new Map((T(e)?z(e,n):[]).map(o=>[o.fieldName,o.key]));return r.map(o=>{const a=O(o.raw,n),u=a?t.get(a):void 0;return A({key:o.name,label:o.raw.label||o.raw.name,dataType:o.raw.dataType,sortable:!!u,sortKey:u})})}function We(e){const n=e.checklist.filterScopeByInput||[],r=e.checklist.requiredDevtools||{},t=e.summary.views.map(d=>d.id).filter(Boolean),o=e.views.map(d=>d.raw.id).filter(Boolean),a=e.inputs.map(d=>d.raw.id).filter(Boolean),u=e.optionQueries.map(d=>d.raw.id||`${d.input.raw.id}-options`).filter(Boolean),c=Object.fromEntries(o.map(d=>[d,e.filterContracts.filter(p=>Array.isArray(p.appliesToViewIds)&&p.appliesToViewIds.includes(d)).map(p=>p.inputId)])),w=Object.fromEntries(e.views.map(d=>[d.raw.id,{title:d.raw.title,visual:d.raw.visual,visualSpec:d.raw.visualSpec,queryKind:d.raw.queryKind,sdkBuilder:d.raw.sdkBuilder}])),f=Object.fromEntries(e.views.map(d=>{var p;return[d.raw.id,A({viewId:d.raw.id,queryId:d.name,title:d.raw.title,visualType:((p=d.raw.visualSpec)==null?void 0:p.visualType)||d.raw.visual,suggestedComponentName:ye(d.raw.title||d.raw.id||d.name),marker:{attribute:"data-semaphor-view-id",value:d.raw.id}})]})),y=Object.fromEntries(e.inputs.map(d=>{var p;return[d.raw.id,A({inputId:d.raw.id,label:d.raw.label,type:d.raw.type,optionQueryId:((p=d.raw.optionQuery)==null?void 0:p.id)||(d.raw.optionQuery?`${d.raw.id}-options`:void 0),suggestedComponentName:ye(d.raw.label||d.raw.id||d.name),marker:{attribute:"data-semaphor-input-id",value:d.raw.id}})]})),k=Object.fromEntries(e.views.map(d=>{var p,m,i;return[d.name,A({viewId:d.raw.id,viewTitle:((p=d.raw.visualSpec)==null?void 0:p.title)||d.raw.title,visualType:(m=d.raw.visualSpec)==null?void 0:m.visualType,title:((i=d.raw.visualSpec)==null?void 0:i.title)||d.raw.title})]}));return`${H}
602
+ export const generatedViewIds = ${C(t)} as const;
603
+ export const generatedQueryViewIds = ${C(o)} as const;
604
+ export const generatedInputIds = ${C(a)} as const;
605
+ export const generatedInputOptionQueryIds = ${C(u)} as const;
606
+ export const generatedViewAuthoring = ${C(f)} as const;
607
+ export const generatedInputAuthoring = ${C(y)} as const;
671
608
 
672
609
  export type SemaphorGeneratedViewId = typeof generatedViewIds[number];
673
610
  export type SemaphorGeneratedQueryViewId = typeof generatedQueryViewIds[number];
@@ -686,8 +623,8 @@ export type SemaphorGeneratedFilterContract = {
686
623
  readonly [key: string]: unknown;
687
624
  };
688
625
 
689
- export const generatedInputIdsForView = ${k(y)} as const;
690
- export const generatedFilterContracts: readonly SemaphorGeneratedFilterContract[] = ${k(e.filterContracts)} as const;
626
+ export const generatedInputIdsForView = ${C(c)} as const;
627
+ export const generatedFilterContracts: readonly SemaphorGeneratedFilterContract[] = ${C(e.filterContracts)} as const;
691
628
 
692
629
  export function semaphorViewMarkerProps(viewId: SemaphorGeneratedViewId) {
693
630
  return {
@@ -707,10 +644,10 @@ export function filterContractsForView(viewId: SemaphorGeneratedQueryViewId) {
707
644
  );
708
645
  }
709
646
 
710
- export const queryDebugForView = ${k(O)} as const;
647
+ export const queryDebugForView = ${C(k)} as const;
711
648
 
712
- export const semaphorGeneratedContractMetadata = ${k({schemaVersion:"semaphor-generated-data-app-contract/v1",title:e.title,requiredDevtools:r,filterContracts:e.filterContracts,filterScopeByInput:n,generatedViewIds:t,generatedQueryViewIds:o,generatedInputIds:a,generatedInputOptionQueryIds:l,generatedInputIdsForView:y,generatedViewAuthoring:f,generatedInputAuthoring:m,visualSpecs:S,presentationViews:e.presentationViews})} as const;
713
- `}function Ze(){return`${K}
649
+ export const semaphorGeneratedContractMetadata = ${C({schemaVersion:"semaphor-generated-data-app-contract/v1",title:e.title,requiredDevtools:r,filterContracts:e.filterContracts,filterScopeByInput:n,generatedViewIds:t,generatedQueryViewIds:o,generatedInputIds:a,generatedInputOptionQueryIds:u,generatedInputIdsForView:c,generatedViewAuthoring:f,generatedInputAuthoring:y,visualSpecs:w,presentationViews:e.presentationViews})} as const;
650
+ `}function Xe(){return`${H}
714
651
  export * from "./sources";
715
652
  export * from "./fields";
716
653
  export * from "./inputs";
@@ -718,4 +655,4 @@ export * from "./queries";
718
655
  export * from "./bindings";
719
656
  export * from "./accessors";
720
657
  export * from "./metadata";
721
- `}function Q(e,n){if(!(!n||typeof n!="object")){if(Array.isArray(n)){for(const r of n)Q(e,r);return}E(n)&&h(e,L(n));for(const r of Object.values(n))Q(e,r)}}function U(e,n){const r=[];if(tn(r,e.raw.sdkSpec),r.length===0)for(const o of e.raw.fields||[])h(r,o);const t=ne(r.filter(o=>o.name&&N(o,n)).map(o=>({raw:o,key:J(o),name:""})),o=>o.key);return H(t,o=>q(o.raw.label||o.raw.name||"field")),t}function P(e,n){if(j(e.raw.sdkSpec.builder)!=="metric")return[];const r=b(e.raw.sdkSpec.spec),t=[];h(t,r==null?void 0:r.primaryMeasure);for(const a of v(r==null?void 0:r.measures))h(t,a);const o=ne(t.filter(a=>a.name&&N(a,n)).map(a=>({raw:a,key:J(a),name:""})),a=>a.key);return H(o,a=>q(a.raw.label||a.raw.name||"metric")),o}function Xe(e,n,r){var o;const t=(o=e.raw.metricBindingKeys)==null?void 0:o[r];if(typeof t=="string"&&t.trim())return t;throw new Error(`views.${e.raw.id}.metricBindingKeys must include a binding key for metric field ${n.raw.name}.`)}function en(e,n){if(n.length===1)return new Set([n[0].name]);const r=b(e.raw.sdkSpec.spec);if(!E(r==null?void 0:r.primaryMeasure))return new Set;const t=J(L(r.primaryMeasure)),o=n.find(a=>a.key===t);return o?new Set([o.name]):new Set}function nn(e){const n=new Map;for(const r of e)for(const t of new Set(Se(r.raw)))n.set(t,(n.get(t)||0)+1);return new Set(Array.from(n.entries()).filter(([,r])=>r>1).map(([r])=>r))}function Se(e){const n=(e.aggregate||"SUM").toUpperCase();return D([`${n.toLowerCase()}_${e.name}`,`${n}_${e.name}`,`${e.name}_${n.toLowerCase()}`,`${e.name}_${n}`,e.name])}function rn(e){const n=new Map;for(const r of e)n.set(r.raw.name,(n.get(r.raw.name)||0)+1);return new Set(Array.from(n.entries()).filter(([,r])=>r>1).map(([r])=>r))}function tn(e,n){const r=b(n.spec);if(!r)return;const t=j(n.builder);if(t==="records"){for(const o of v(r.fields))h(e,o);return}if(t==="sql"){for(const o of v(r.fields))h(e,o);return}if(t==="analysis"||t==="metric"){h(e,r.primaryMeasure);for(const o of v(r.measures))h(e,o);for(const o of v(r.dimensions))h(e,o);h(e,r.dateField);return}if(t==="matrix"){const o=ce(r.rows),a=ce(r.columns),l=v(r.values);for(const y of o)me(e,y);for(const y of a)me(e,y);for(const y of l){const S=b(y);h(e,S==null?void 0:S.field),h(e,S==null?void 0:S.measure)}}}function ce(e){if(Array.isArray(e))return e;const n=b(e);return Array.isArray(n==null?void 0:n.levels)?n.levels:[]}function me(e,n){var r;if(E(n)){h(e,n);return}h(e,(r=b(n))==null?void 0:r.field)}function fe(e){var n,r,t,o;return((n=e==null?void 0:e.computation)==null?void 0:n.kind)==="presentation_only"||((r=e==null?void 0:e.computation)==null?void 0:r.kind)==="derived"||((t=e==null?void 0:e.computation)==null?void 0:t.kind)==="unsupported"||(e==null?void 0:e.visual)==="text_block"||((o=e==null?void 0:e.visualSpec)==null?void 0:o.visualType)==="text_block"}function on(e){const n=b(e)||{};return A({id:e.id,title:e.title,purpose:e.purpose,visual:e.visual,visualSpec:e.visualSpec,computation:e.computation,uxExpectations:e.uxExpectations,validation:e.validation,sourceViewIds:n.sourceViewIds,content:n.content,description:n.description})}function h(e,n){E(n)&&e.push(L(n))}function L(e){return{name:e.name,label:e.label,role:e.role,dataType:e.dataType,aggregate:e.aggregate,sourceKey:e.sourceKey||(e.source?le(e.source):void 0),...e.source?{source:e.source}:{}}}function sn(e){if(!e.source)return;const n={...e.source,...e.sourceKey?{sourceKey:e.sourceKey}:{}},r=Ie(n);if(r)return{raw:n,key:r,aliases:Fe(n),name:""}}function E(e){const n=b(e);return!!(n&&typeof n.name=="string"&&(typeof n.role=="string"||typeof n.dataType=="string"||typeof n.aggregate=="string"||n.source||n.sourceKey))}function we(e){const n=b(e);return!!(n&&(typeof n.sourceKey=="string"||n.kind==="semantic"||typeof n.datasetName=="string"&&typeof n.domainId=="string"))}function x(e,n){if(e===void 0)return"undefined";if(e===null||typeof e=="number"||typeof e=="boolean"||typeof e=="string")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(o=>x(o,n)).join(", ")}]`;if(E(e)){const o=N(L(e),n);if(o)return`fields.${o}`}if(we(e)){const o=$e(e,n);if(o)return`sources.${o}`}const r=b(e);return r?`{ ${Object.entries(r).filter(([,o])=>o!==void 0).map(([o,a])=>`${JSON.stringify(o)}: ${x(a,n)}`).join(", ")} }`:JSON.stringify(e)}function k(e){return JSON.stringify(e,null,2)}function N(e,n){if(E(e))return n.fieldNameByKey.get(J(L(e)))}function $e(e,n){if(we(e))for(const r of ee(e)){const t=n.sourceNameByKey.get(r);if(t)return t}}function J(e){return[e.sourceKey||"",e.name||"",e.role||"",e.aggregate||""].join("|")}function an(e,n){return!E(e)||!E(n)||e.name!==n.name?!1:de(e).some(r=>de(n).includes(r))}function un(e){return E(e)&&e.role==="id"}function dn(e){const n=[],r=new Map;for(const t of e){const o=D(t.aliases.length?t.aliases:[t.key]),a=o.map(l=>r.get(l)).find(G);if(a){a.aliases=D([...a.aliases,...o]);continue}t.aliases=o,n.push(t);for(const l of o)r.set(l,t)}return n}function pn(e){const n=new Map;for(const r of e)for(const t of D([r.key,...r.aliases])){const o=n.get(t);if(o&&o!==r.name)throw new Error(`Source identity ${t} resolves to multiple generated sources.`);n.set(t,r.name)}return n}function D(e){return Array.from(new Set(e.filter(Boolean)))}function Ie(e){return ee(e)[0]||le(e)}function ee(e){const n=b(e);if(!n)return[];const r=[];if(typeof n.sourceKey=="string"&&r.push(n.sourceKey),n.kind==="semantic"||n.datasetName){const t=typeof n.domainId=="string"?n.domainId:"";t&&typeof n.datasetId=="string"&&r.push(`semantic:${t}:datasetId:${n.datasetId}`),t&&typeof n.datasetName=="string"&&r.push(`semantic:${t}:datasetName:${n.datasetName}`)}return r.length===0&&r.push(le(e)),D(r)}function Fe(e){return ee(e)}function le(e){const n=b(e);return n?typeof n.sourceKey=="string"?n.sourceKey:JSON.stringify(n):""}function ln(e){return E(e)&&de(e)[0]||""}function de(e){return E(e)?D([...typeof e.sourceKey=="string"?[e.sourceKey]:[],...e.source?ee(e.source):[]]):[]}function j(e){const n=String(e||"").replace(/^semaphor\./,"");if(!["metric","records","analysis","matrix","sql"].includes(n))throw new Error(`Unsupported sdkSpec builder: ${e}`);return n}function cn(e){const n=j(e);return n==="records"||n==="sql"}function mn(e){const n=b(e);return typeof(n==null?void 0:n.operator)=="string"?n.operator:e.type==="date_range"?"between":e.type==="multi_select"||e.type==="select"?"in":"="}function H(e,n){const r=new Map;for(const t of e){const o=n(t)||"item",a=r.get(o)||0;r.set(o,a+1),t.name=a===0?o:`${o}${a+1}`}}function ne(e,n){const r=new Set,t=[];for(const o of e){const a=n(o);!a||r.has(a)||(r.add(a),t.push(o))}return t}function q(e){const n=String(e||"").replace(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(Boolean);if(n.length===0)return"item";const[r,...t]=n,o=[r.toLowerCase(),...t.map(a=>a.charAt(0).toUpperCase()+a.slice(1).toLowerCase())].join("");return/^[A-Za-z_$]/.test(o)?o:`item${o}`}function ye(e){const n=q(e);return n.charAt(0).toUpperCase()+n.slice(1)}function fn(e){const n=String(e).split(":");return n[n.length-1]||String(e)}function A(e){return Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}function b(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function v(e){return Array.isArray(e)?e:[]}function Y(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function G(e){return e!==void 0}exports.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_SCHEMA_VERSION=Z.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_SCHEMA_VERSION;exports.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_VALIDATOR_VERSION=Z.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_VALIDATOR_VERSION;exports.isSemaphorDataAppCodegenSummary=Z.isSemaphorDataAppCodegenSummary;exports.validateSemaphorDataAppCodegenSummary=Z.validateSemaphorDataAppCodegenSummary;exports.CODEGEN_SUMMARY_SCHEMA_VERSION=R.CODEGEN_SUMMARY_SCHEMA_VERSION;exports.CODEGEN_SUMMARY_VALIDATOR_VERSION=R.CODEGEN_SUMMARY_VALIDATOR_VERSION;exports.CONTRACT_MANIFEST_SCHEMA_VERSION=R.CONTRACT_MANIFEST_SCHEMA_VERSION;exports.GENERATED_CONTRACT_SCHEMA_VERSION=R.GENERATED_CONTRACT_SCHEMA_VERSION;exports.GENERATED_CONTRACT_TYPESCRIPT_FILES=R.GENERATED_CONTRACT_TYPESCRIPT_FILES;exports.REQUIRED_GENERATED_CONTRACT_FILES=R.REQUIRED_GENERATED_CONTRACT_FILES;exports.assertValidCodegenSummary=R.assertValidCodegenSummary;exports.buildSemaphorGeneratedActiveInput=R.buildSemaphorGeneratedActiveInput;exports.buildSemaphorGeneratedInputOptionIntent=R.buildSemaphorGeneratedInputOptionIntent;exports.buildSemaphorGeneratedViewExecutionRequest=R.buildSemaphorGeneratedViewExecutionRequest;exports.buildSemaphorGeneratedViewExecutionRequests=R.buildSemaphorGeneratedViewExecutionRequests;exports.evaluateSemaphorDataAppContractUpdatePolicy=R.evaluateSemaphorDataAppContractUpdatePolicy;exports.validateCodegenSummary=R.validateCodegenSummary;exports.validateSemaphorGeneratedContract=R.validateSemaphorGeneratedContract;exports.DEFAULT_GENERATED_CONTRACT_OUTPUT_DIR=ke;exports.generateSemaphorDataAppContract=Me;
658
+ `}function D(e,n){if(!(!n||typeof n!="object")){if(Array.isArray(n)){for(const r of n)D(e,r);return}N(n)&&S(e,W(n));for(const r of Object.values(n))D(e,r)}}function Q(e,n){const r=[];if(on(r,e.raw.sdkSpec),r.length===0)for(const o of e.raw.fields||[])S(r,o);const t=ne(r.filter(o=>o.name&&O(o,n)).map(o=>({raw:o,key:X(o),name:""})),o=>o.key);return Se(t,n,"field"),t}function B(e,n){if(q(e.raw.sdkSpec.builder)!=="metric")return[];const r=F(e.raw.sdkSpec.spec),t=[];S(t,r==null?void 0:r.primaryMeasure);for(const a of v(r==null?void 0:r.measures))S(t,a);const o=ne(t.filter(a=>a.name&&O(a,n)).map(a=>({raw:a,key:X(a),name:""})),a=>a.key);return Se(o,n,"metric"),o}function en(e,n,r){var o;const t=(o=e.raw.metricBindingKeys)==null?void 0:o[r];if(typeof t=="string"&&t.trim())return t;throw new Error(`views.${e.raw.id}.metricBindingKeys must include a binding key for metric field ${n.raw.name}.`)}function Se(e,n,r){const t=new Map,o=new Map;for(const u of e){const c=j(u.raw.name||u.raw.label||r)||r;t.set(u.key,c),o.set(c,(o.get(c)||0)+1)}const a=new Set;for(const u of e){const c=t.get(u.key)||r,w=O(u.raw,n)||c,f=o.get(c)===1?c:w;u.name=nn(f,u.key,a)}}function nn(e,n,r){const t=tn(e)?e:j(e||"field")||"field";if(!r.has(t))return r.add(t),t;const o=rn(n),a=`${t}${o}`;if(!r.has(a))return r.add(a),a;let u=2;for(;r.has(`${a}${u}`);)u+=1;const c=`${a}${u}`;return r.add(c),c}function rn(e){let n=0;for(let r=0;r<e.length;r+=1)n=n*31+e.charCodeAt(r)>>>0;return n.toString(36).slice(0,6).replace(/^[0-9]/,"x$&")}function tn(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)}function on(e,n){const r=F(n.spec);if(!r)return;const t=q(n.builder);if(t==="records"){for(const o of v(r.fields))S(e,o);return}if(t==="sql"){for(const o of v(r.fields))S(e,o);return}if(t==="analysis"||t==="metric"){S(e,r.primaryMeasure);for(const o of v(r.measures))S(e,o);for(const o of v(r.dimensions))S(e,o);S(e,r.dateField);return}if(t==="matrix"){const o=ce(r.rows),a=ce(r.columns),u=v(r.values);for(const c of o)me(e,c);for(const c of a)me(e,c);for(const c of u){const w=F(c);S(e,w==null?void 0:w.field),S(e,w==null?void 0:w.measure)}}}function ce(e){if(Array.isArray(e))return e;const n=F(e);return Array.isArray(n==null?void 0:n.levels)?n.levels:[]}function me(e,n){var r;if(N(n)){S(e,n);return}S(e,(r=F(n))==null?void 0:r.field)}function fe(e){var n,r,t,o;return((n=e==null?void 0:e.computation)==null?void 0:n.kind)==="presentation_only"||((r=e==null?void 0:e.computation)==null?void 0:r.kind)==="derived"||((t=e==null?void 0:e.computation)==null?void 0:t.kind)==="unsupported"||(e==null?void 0:e.visual)==="text_block"||((o=e==null?void 0:e.visualSpec)==null?void 0:o.visualType)==="text_block"}function sn(e){const n=F(e)||{};return A({id:e.id,title:e.title,purpose:e.purpose,visual:e.visual,visualSpec:e.visualSpec,computation:e.computation,uxExpectations:e.uxExpectations,validation:e.validation,sourceViewIds:n.sourceViewIds,content:n.content,description:n.description})}function S(e,n){N(n)&&e.push(W(n))}function W(e){return{name:e.name,label:e.label,role:e.role,dataType:e.dataType,aggregate:e.aggregate,sourceKey:e.sourceKey||(e.source?le(e.source):void 0),...e.source?{source:e.source}:{}}}function an(e){if(!e.source)return;const n={...e.source,...e.sourceKey?{sourceKey:e.sourceKey}:{}},r=Ie(n);if(r)return{raw:n,key:r,aliases:Ve(n),name:""}}function N(e){const n=F(e);return!!(n&&typeof n.name=="string"&&(typeof n.role=="string"||typeof n.dataType=="string"||typeof n.aggregate=="string"||n.source||n.sourceKey))}function we(e){const n=F(e);return!!(n&&(typeof n.sourceKey=="string"||n.kind==="semantic"||typeof n.datasetName=="string"&&typeof n.domainId=="string"))}function G(e,n){if(e===void 0)return"undefined";if(e===null||typeof e=="number"||typeof e=="boolean"||typeof e=="string")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(o=>G(o,n)).join(", ")}]`;if(N(e)){const o=O(W(e),n);if(o)return`fields.${o}`}if(we(e)){const o=$e(e,n);if(o)return`sources.${o}`}const r=F(e);return r?`{ ${Object.entries(r).filter(([,o])=>o!==void 0).map(([o,a])=>`${JSON.stringify(o)}: ${G(a,n)}`).join(", ")} }`:JSON.stringify(e)}function C(e){return JSON.stringify(e,null,2)}function O(e,n){if(N(e))return n.fieldNameByKey.get(X(W(e)))}function $e(e,n){if(we(e))for(const r of ee(e)){const t=n.sourceNameByKey.get(r);if(t)return t}}function X(e){return[e.sourceKey||"",e.name||"",e.role||"",e.aggregate||""].join("|")}function un(e,n){return!N(e)||!N(n)||e.name!==n.name?!1:de(e).some(r=>de(n).includes(r))}function dn(e){return N(e)&&e.role==="id"}function pn(e){const n=[],r=new Map;for(const t of e){const o=U(t.aliases.length?t.aliases:[t.key]),a=o.map(u=>r.get(u)).find(x);if(a){a.aliases=U([...a.aliases,...o]);continue}t.aliases=o,n.push(t);for(const u of o)r.set(u,t)}return n}function ln(e){const n=new Map;for(const r of e)for(const t of U([r.key,...r.aliases])){const o=n.get(t);if(o&&o!==r.name)throw new Error(`Source identity ${t} resolves to multiple generated sources.`);n.set(t,r.name)}return n}function U(e){return Array.from(new Set(e.filter(Boolean)))}function Ie(e){return ee(e)[0]||le(e)}function ee(e){const n=F(e);if(!n)return[];const r=[];if(typeof n.sourceKey=="string"&&r.push(n.sourceKey),n.kind==="semantic"||n.datasetName){const t=typeof n.domainId=="string"?n.domainId:"";t&&typeof n.datasetId=="string"&&r.push(`semantic:${t}:datasetId:${n.datasetId}`),t&&typeof n.datasetName=="string"&&r.push(`semantic:${t}:datasetName:${n.datasetName}`)}return r.length===0&&r.push(le(e)),U(r)}function Ve(e){return ee(e)}function le(e){const n=F(e);return n?typeof n.sourceKey=="string"?n.sourceKey:JSON.stringify(n):""}function cn(e){return N(e)&&de(e)[0]||""}function de(e){return N(e)?U([...typeof e.sourceKey=="string"?[e.sourceKey]:[],...e.source?ee(e.source):[]]):[]}function q(e){const n=String(e||"").replace(/^semaphor\./,"");if(!["metric","records","analysis","matrix","sql"].includes(n))throw new Error(`Unsupported sdkSpec builder: ${e}`);return n}function mn(e){const n=q(e);return n==="records"||n==="sql"}function fn(e){const n=F(e);return typeof(n==null?void 0:n.operator)=="string"?n.operator:e.type==="date_range"?"between":e.type==="multi_select"||e.type==="select"?"in":"="}function P(e,n){const r=new Map;for(const t of e){const o=n(t)||"item",a=r.get(o)||0;r.set(o,a+1),t.name=a===0?o:`${o}${a+1}`}}function ne(e,n){const r=new Set,t=[];for(const o of e){const a=n(o);!a||r.has(a)||(r.add(a),t.push(o))}return t}function j(e){const n=String(e||"").replace(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(Boolean);if(n.length===0)return"item";const[r,...t]=n,o=[r.toLowerCase(),...t.map(a=>a.charAt(0).toUpperCase()+a.slice(1).toLowerCase())].join("");return/^[A-Za-z_$]/.test(o)?o:`item${o}`}function ye(e){const n=j(e);return n.charAt(0).toUpperCase()+n.slice(1)}function yn(e){const n=String(e).split(":");return n[n.length-1]||String(e)}function A(e){return Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}function F(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function v(e){return Array.isArray(e)?e:[]}function L(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function x(e){return e!==void 0}exports.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_SCHEMA_VERSION=Y.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_SCHEMA_VERSION;exports.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_VALIDATOR_VERSION=Y.SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_VALIDATOR_VERSION;exports.isSemaphorDataAppCodegenSummary=Y.isSemaphorDataAppCodegenSummary;exports.validateSemaphorDataAppCodegenSummary=Y.validateSemaphorDataAppCodegenSummary;exports.CODEGEN_SUMMARY_SCHEMA_VERSION=R.CODEGEN_SUMMARY_SCHEMA_VERSION;exports.CODEGEN_SUMMARY_VALIDATOR_VERSION=R.CODEGEN_SUMMARY_VALIDATOR_VERSION;exports.CONTRACT_MANIFEST_SCHEMA_VERSION=R.CONTRACT_MANIFEST_SCHEMA_VERSION;exports.GENERATED_CONTRACT_SCHEMA_VERSION=R.GENERATED_CONTRACT_SCHEMA_VERSION;exports.GENERATED_CONTRACT_TYPESCRIPT_FILES=R.GENERATED_CONTRACT_TYPESCRIPT_FILES;exports.REQUIRED_GENERATED_CONTRACT_FILES=R.REQUIRED_GENERATED_CONTRACT_FILES;exports.assertValidCodegenSummary=R.assertValidCodegenSummary;exports.buildSemaphorGeneratedActiveInput=R.buildSemaphorGeneratedActiveInput;exports.buildSemaphorGeneratedInputOptionIntent=R.buildSemaphorGeneratedInputOptionIntent;exports.buildSemaphorGeneratedViewExecutionRequest=R.buildSemaphorGeneratedViewExecutionRequest;exports.buildSemaphorGeneratedViewExecutionRequests=R.buildSemaphorGeneratedViewExecutionRequests;exports.evaluateSemaphorDataAppContractUpdatePolicy=R.evaluateSemaphorDataAppContractUpdatePolicy;exports.validateCodegenSummary=R.validateCodegenSummary;exports.validateSemaphorGeneratedContract=R.validateSemaphorGeneratedContract;exports.DEFAULT_GENERATED_CONTRACT_OUTPUT_DIR=Ce;exports.generateSemaphorDataAppContract=Oe;