react-semaphor 0.1.398 → 0.1.400
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +2 -2
- package/dist/brand-studio/index.cjs +1 -1
- package/dist/brand-studio/index.js +2 -2
- package/dist/chunks/analyze-result-contract-BUgK3759.js +1833 -0
- package/dist/chunks/analyze-result-contract-S8u7CcPL.js +1 -0
- package/dist/chunks/{calendar-preferences-dialog-DwLeBLy2.js → calendar-preferences-dialog-Ci3rHHgA.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-49fcEPXS.js → calendar-preferences-dialog-i3-jBIYS.js} +3 -3
- package/dist/chunks/{dashboard-briefing-launcher-cgPKz1yX.js → dashboard-briefing-launcher-BpwjeJsQ.js} +4 -4
- package/dist/chunks/{dashboard-briefing-launcher-CgkSKkZR.js → dashboard-briefing-launcher-DiEpMS9E.js} +1 -1
- package/dist/chunks/{dashboard-controls-D12ZSUP_.js → dashboard-controls-BaUUrvSI.js} +1 -1
- package/dist/chunks/{dashboard-controls-VMFm3OP4.js → dashboard-controls-Bkjpgr3d.js} +5 -5
- package/dist/chunks/{dashboard-json-CvK0oI24.js → dashboard-json-CxNyExRm.js} +1 -1
- package/dist/chunks/{dashboard-json-C-GG5yC7.js → dashboard-json-DvULhhN2.js} +3 -3
- package/dist/chunks/{edit-dashboard-visual-B5KB7dx4.js → edit-dashboard-visual-DBrsgEtL.js} +4 -4
- package/dist/chunks/{edit-dashboard-visual-ql99faTz.js → edit-dashboard-visual-DJRPiKdY.js} +1 -1
- package/dist/chunks/{index-DXCBPLDu.js → index-BepF6hoa.js} +2 -2
- package/dist/chunks/{index-CQmKDEbe.js → index-Drz04wqE.js} +5 -5
- package/dist/chunks/{switch-B79Hn4Qh.js → switch-D2oOmorN.js} +1 -1
- package/dist/chunks/{switch-BXQAlSuW.js → switch-qUw8u-gU.js} +1 -1
- package/dist/chunks/update-policy-BmtOqvbf.js +3 -0
- package/dist/chunks/update-policy-KImUg4Od.js +831 -0
- package/dist/chunks/{use-create-flow-overlay-state-Bw5LRkf9.js → use-create-flow-overlay-state-CFJIHt5D.js} +3 -3
- package/dist/chunks/{use-create-flow-overlay-state-7MFN3PWX.js → use-create-flow-overlay-state-DrkYiyQz.js} +1 -1
- package/dist/chunks/{validators-4EGCWWga.js → validators-B1Mgdr3T.js} +279 -242
- package/dist/chunks/{validators-CPtkrola.js → validators-DFOX0tYY.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.cjs +1 -1
- package/dist/dashboard-authoring/index.js +2 -2
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +2 -2
- package/dist/data-app-codegen/index.cjs +1 -0
- package/dist/data-app-codegen/index.js +22 -0
- package/dist/data-app-codegen-node/index.cjs +462 -0
- package/dist/data-app-codegen-node/index.js +1424 -0
- package/dist/data-app-sdk/index.cjs +2 -2
- package/dist/data-app-sdk/index.js +3 -2
- package/dist/data-app-sdk-adapters/index.cjs +1 -1
- package/dist/data-app-sdk-adapters/index.js +20 -12
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +7 -7
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/analytics-protocol.d.ts +101 -2
- package/dist/types/dashboard-assistant.d.ts +14 -0
- package/dist/types/dashboard-authoring.d.ts +6 -0
- package/dist/types/data-app-builder.d.ts +6 -0
- package/dist/types/data-app-codegen-node.d.ts +1165 -0
- package/dist/types/data-app-codegen.d.ts +1137 -0
- package/dist/types/data-app-sdk-adapters.d.ts +7 -0
- package/dist/types/data-app-sdk-validation.d.ts +15 -0
- package/dist/types/data-app-sdk.d.ts +18 -0
- package/dist/types/main.d.ts +6 -0
- package/package.json +9 -1
- package/dist/chunks/analyze-result-contract-C9Gv2_qW.js +0 -1585
- package/dist/chunks/analyze-result-contract-Zgg-Bbpj.js +0 -1
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("../chunks/analyze-result-contract-S8u7CcPL.js"),w=require("../chunks/update-policy-BmtOqvbf.js"),fe=require("node:crypto"),$e="src/semaphor/generated",M=`// Generated by Semaphor Agent Plugin. Do not hand-edit analytics wiring here.
|
|
2
|
+
// Regenerate from the accepted semaphor_plan_data_app codegenSummary when the plan changes.
|
|
3
|
+
`;function Fe(e,n={}){w.assertValidCodegenSummary(e);const r=Ve(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 o=be(r),t=Ce({contract:r,files:o,generatorName:n.generatorName||"react-semaphor/data-app-codegen/node",generatorVersion:n.generatorVersion||"unknown"}),i={...o,"contract.manifest.json":`${JSON.stringify(t,null,2)}
|
|
4
|
+
`};return{schemaVersion:w.GENERATED_CONTRACT_SCHEMA_VERSION,files:i,manifest:t,contentHash:String(t.generatedContentHash||""),usageExample:Ne(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 Ve(e){var b,d,c,S,f,F,C,V,N,T,I,O;const n=[],r=[];for(const s of e.inputs){y(r,s.fieldRef);for(const h of s.bindings||[])y(r,h.fieldRef);y(r,(b=s.optionQuery)==null?void 0:b.valueFieldRef),y(r,(d=s.optionQuery)==null?void 0:d.labelFieldRef),y(r,(c=s.optionQuery)==null?void 0:c.filterFieldRef),Q(r,(S=s.optionQuery)==null?void 0:S.spec)}for(const s of e.filterContracts){y(r,s.fieldRef),y(r,(f=s.optionQuery)==null?void 0:f.valueFieldRef),y(r,(F=s.optionQuery)==null?void 0:F.labelFieldRef),y(r,(C=s.optionQuery)==null?void 0:C.filterFieldRef),Q(r,(V=s.optionQuery)==null?void 0:V.spec);for(const h of s.bindings||[])y(r,h.fieldRef)}for(const s of e.views){for(const h of s.fields||[])y(r,h);Q(r,(N=s.sdkSpec)==null?void 0:N.spec),Q(r,s.visualSpec)}const o=e.implementationChecklist||{};for(const s of Object.values(o.bindingsByView||{}))for(const h of Array.isArray(s)?s:[])y(r,h.fieldRef),y(r,h.optionValueField),y(r,h.optionLabelField);for(const s of o.requiredInputOptions||[])y(r,s.visibleLabelField),y(r,s.optionValueField),y(r,s.runtimeFilterField);const t=We([...e.sources.map(s=>({raw:s,key:Se(s),aliases:ge(s),name:""})),...r.map(s=>ze(s)).filter(x)]);v(t,s=>{const h=g(s.raw);return D(s.raw.label||(h==null?void 0:h.datasetName)||(h==null?void 0:h.datasetId)||(h==null?void 0:h.name)||s.raw.kind||"source")});const i=Xe(t),u=de(r.filter(s=>s.name).map(s=>({raw:s,key:ue(s),name:""})),s=>s.key);v(u,s=>D([s.raw.sourceKey?tn(s.raw.sourceKey):"",s.raw.aggregate?s.raw.aggregate.toLowerCase():"",s.raw.name].filter(Boolean).join("_")));const l=new Map(u.map(s=>[s.key,s.name])),p=e.inputs.map(s=>({raw:s,name:D(s.id||s.label||"input")}));v(p,s=>s.name);const m=p.filter(s=>!!s.raw.optionQuery).map(s=>({input:s,name:`${s.name}Options`,raw:s.raw.optionQuery}));v(m,s=>s.name);for(const s of m)Ye(s.raw.labelFieldRef,s.raw.valueFieldRef)&&Ze(s.raw.valueFieldRef)&&n.push(`Input option query ${((T=s.raw.spec)==null?void 0:T.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 a=e.views.filter(s=>{var h,q;return!!((h=s.sdkSpec)!=null&&h.builder&&((q=s.sdkSpec)!=null&&q.spec))}).map(s=>({raw:s,name:D(s.id||s.title||"query")}));v(a,s=>s.name);const $=e.views.filter(s=>me(s)&&!("sdkSpec"in s)).map(s=>Je(s));for(const s of e.views)(!("sdkSpec"in s)||!((I=s.sdkSpec)!=null&&I.builder)||!((O=s.sdkSpec)!=null&&O.spec))&&!me(s)&&n.push(`Skipped view ${s.id||s.title||"unknown"} because it has no sdkSpec.`);return Re({inputs:p,views:a,filterContracts:e.filterContracts}),{summary:e,title:e.title||"Semaphor Data App",sources:t,fields:u,inputs:p,optionQueries:m,views:a,presentationViews:$,filterContracts:e.filterContracts,checklist:o,sourceNameByKey:i,fieldNameByKey:l,warnings:n}}function Re({inputs:e,views:n,filterContracts:r}){const o=new Set(e.map(i=>i.raw.id).filter(Boolean)),t=new Set(n.map(i=>i.raw.id).filter(Boolean));for(const[i,u]of r.entries()){if(!o.has(u.inputId))throw new Error(`filterContracts.${i}.inputId must reference a generated input.`);const l=new Set(u.appliesToViewIds||[]),p=new Set(u.notAppliedToViewIds||[]);for(const[m,a]of(u.appliesToViewIds||[]).entries())if(!t.has(a))throw new Error(`filterContracts.${i}.appliesToViewIds.${m} must reference an executable generated view.`);for(const[m,a]of(u.notAppliedToViewIds||[]).entries())if(!t.has(a))throw new Error(`filterContracts.${i}.notAppliedToViewIds.${m} must reference an executable generated view.`);for(const[m,a]of(u.bindings||[]).entries()){if(!t.has(a.viewId))throw new Error(`filterContracts.${i}.bindings.${m}.viewId must reference an executable generated view.`);if(!l.has(a.viewId))throw new Error(`filterContracts.${i}.bindings.${m}.viewId must be included in appliesToViewIds.`);if(p.has(a.viewId))throw new Error(`filterContracts.${i}.bindings.${m}.viewId must not be listed in notAppliedToViewIds.`)}}}function be(e){return{"sources.ts":ke(e),"fields.ts":Ge(e),"inputs.ts":xe(e),"queries.ts":He(e),"bindings.ts":Qe(e),"accessors.ts":Ke(e),"metadata.ts":Be(e),"index.ts":Ue()}}function Ce({contract:e,files:n,generatorName:r,generatorVersion:o}){return{schemaVersion:w.CONTRACT_MANIFEST_SCHEMA_VERSION,generatedContractSchemaVersion:w.GENERATED_CONTRACT_SCHEMA_VERSION,generator:{name:r,version:o},generatedContentHash:Oe(n),codegenSummaryValidatorVersion:w.CODEGEN_SUMMARY_VALIDATOR_VERSION,codegenSummaryHash:Ee(e.summary),codegenSummary:e.summary}}function Oe(e){const n=fe.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 Ee(e){return`sha256:${fe.createHash("sha256").update(se(e)).digest("hex")}`}function se(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(o=>se(o)).join(",")}]`;const n=e;return`{${Object.keys(n).sort().filter(o=>n[o]!==void 0).map(o=>`${JSON.stringify(o)}:${se(n[o])}`).join(",")}}`}function Ne(e){const n=e.views.find(p=>G(p)&&_(p));if(n)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, recordsSortOptionsForView, rowValuesForView, 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 = result.records.map((row) => rowValuesForView.${n.name}(row, result.columns));`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
|
|
5
|
+
`);const r=e.views.find(p=>G(p));if(r)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, recordsSortOptionsForView, rowValuesForView, 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 = result.records.map((row) => rowValuesForView.${r.name}(row, result.columns));`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
|
|
6
|
+
`);const o=e.views.find(p=>Y(p)&&_(p));if(o)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowValuesForView, 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 = result.records.map((row) => rowValuesForView.${o.name}(row, result.columns));`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
|
|
7
|
+
`);const t=e.views.find(p=>ae(p)&&_(p));if(t)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowValuesForView, 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 = result.records.map((row) => rowValuesForView.${t.name}(row, result.columns));`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
|
|
8
|
+
`);const i=e.views.find(p=>{var m;return nn((m=p.raw.sdkSpec)==null?void 0:m.builder)});if(i)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowValuesForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const result = useSemaphorQuery(queries.${i.name}(), queryOptionsForView.${i.name}(inputHandles));`,`const rows = result.records.map((row) => rowValuesForView.${i.name}(row, result.columns));`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
|
|
9
|
+
`);const u=e.views[0];return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",u?`const result = useSemaphorQuery(queries.${u.name}(), queryOptionsForView.${u.name}(inputHandles));`:"const result = undefined;","const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
|
|
10
|
+
`)}function Y(e){var n;return P((n=e.raw.sdkSpec)==null?void 0:n.builder)==="records"}function G(e){var n,r,o;return Y(e)&&((o=(r=(n=e.raw.visualSpec)==null?void 0:n.tableBehavior)==null?void 0:r.sorting)==null?void 0:o.mode)==="server"}function ae(e){var n;return P((n=e.raw.sdkSpec)==null?void 0:n.builder)==="sql"}function _(e){var n,r,o;return((o=(r=(n=e.raw.visualSpec)==null?void 0:n.tableBehavior)==null?void 0:r.pagination)==null?void 0:o.mode)==="server"}function Ae(e){return Y(e)&&(_(e)||G(e))||ae(e)&&_(e)}function ke(e){const n=e.sources.map(({name:o,raw:t})=>{const i=Te(t);return` ${o}: ${i},`}).join(`
|
|
11
|
+
`),r=e.sources.some(o=>o.raw.kind==="semantic")?`import { semaphor } from "react-semaphor/data-app-sdk";
|
|
12
|
+
|
|
13
|
+
`:"";return`${M}
|
|
14
|
+
${r}export const sources = {
|
|
15
|
+
${n}
|
|
16
|
+
} as const;
|
|
17
|
+
`}function Te(e){if(e.kind==="semantic"){const n={domainId:e.domainId,datasetId:e.datasetId,datasetName:e.datasetName,label:e.label};return`semaphor.source.semantic(${R(H(n))})`}return`${R(H({...e,sourceKey:void 0}))} as const`}function Ge(e){const n=e.fields.map(({name:o,raw:t})=>{const i=_e(t,e);return` ${o}: ${i},`}).join(`
|
|
18
|
+
`),r=n.includes("sources.")?`import { sources } from "./sources";
|
|
19
|
+
|
|
20
|
+
`:"";return`${M}
|
|
21
|
+
${r}export const fields = {
|
|
22
|
+
${n}
|
|
23
|
+
} as const;
|
|
24
|
+
`}function _e(e,n){const r={name:e.name,label:e.label,role:e.role,dataType:e.dataType,aggregate:e.aggregate},o=en(e),t=o?n.sourceNameByKey.get(o):void 0;if(o&&!t)throw new Error(`Field ${e.name} references source ${o}, but that source is not renderable. Include the source in codegenSummary.sources or provide field.source.`);const i=Object.entries(H(r)).map(([u,l])=>`${JSON.stringify(u)}: ${k(l,n)}`);return t&&i.push(`"source": sources.${t}`),`{ ${i.join(", ")} }`}function xe(e){const n=e.inputs.map(c=>{const S=E(c.raw.fieldRef,e),f=[`id: ${JSON.stringify(c.raw.id)}`,`label: ${JSON.stringify(c.raw.label||c.raw.id)}`,`operator: ${JSON.stringify(rn(c.raw))}`];if(S&&f.push(`field: fields.${S}`),c.raw.relationshipHint&&f.push(`relationshipHint: ${R(c.raw.relationshipHint)}`),!S)throw new Error(`Input ${c.raw.id||c.name} is missing a generated field reference.`);return` ${c.name}: semaphor.filter({ ${f.join(", ")} }),`}).join(`
|
|
25
|
+
`),r=e.inputs.map(c=>`filterSpecs.${c.name}`).join(", "),o=e.inputs.map(c=>JSON.stringify(c.raw.id)).join(", "),t=e.optionQueries.map(c=>{const S=c.input.raw,f=c.raw,F=g(f.spec)||{},{id:C,inputId:V,source:N,sourceKey:T,valueField:I,labelField:O,population:s,dependencies:h,limit:q,...X}=F,B=f.sourceKey?{sourceKey:f.sourceKey}:f.source||N||(typeof T=="string"?{sourceKey:T}:void 0),ee=he(B,e),ne=E(f.valueFieldRef,e),re=E(f.labelFieldRef,e),te={...X,id:f.id||F.id||`${S.id}-options`,inputId:S.id,source:B,valueField:f.valueFieldRef,labelField:f.labelFieldRef,population:f.population||s,dependencies:f.dependencies||h,limit:f.limit||q||100};if(!ee||!ne||!re)throw new Error(`Input option query ${f.id||`${S.id}-options`} is missing source, valueField, or labelField.`);const oe=Object.entries(H(te)).map(([we,Ie])=>`${JSON.stringify(we)}: ${k(Ie,e)}`);return` ${c.name}: semaphor.inputOptions({ ${oe.join(", ")} }),`}).join(`
|
|
26
|
+
`),i=e.optionQueries.map(c=>{const f=Me(e,c).map(F=>{const C=E(F.raw.fieldRef,e);if(!C)throw new Error(`Input option query ${c.raw.id||`${c.input.raw.id}-options`} references input ${F.raw.id} without a generated field reference.`);const V=`inputHandles[${JSON.stringify(F.raw.id)}]`;return` if (${V}) {
|
|
27
|
+
inputs.push(semaphor.bindInput(${V}, { field: fields.${C} }));
|
|
28
|
+
}`}).join(`
|
|
29
|
+
`);return` ${c.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
|
|
30
|
+
const inputs: SemaphorInputReference[] = [];
|
|
31
|
+
${f}
|
|
32
|
+
return inputs;
|
|
33
|
+
},`}).join(`
|
|
34
|
+
|
|
35
|
+
`),u=e.optionQueries.map(c=>` ${c.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
|
|
36
|
+
return {
|
|
37
|
+
inputs: inputsForInputOptionQuery.${c.name}(inputHandles),
|
|
38
|
+
};
|
|
39
|
+
},`).join(`
|
|
40
|
+
|
|
41
|
+
`),l=e.optionQueries.map(c=>` case ${JSON.stringify(c.raw.id||`${c.input.raw.id}-options`)}:
|
|
42
|
+
return queryOptionsForInputOptionQuery.${c.name}(inputHandles);`).join(`
|
|
43
|
+
`),p=e.inputs.length>0,m=e.optionQueries.length>0,a=m?"inputOptionQueryId":"_inputOptionQueryId",$=m?"inputHandles":"_inputHandles",b=["SemaphorInputHandle",m?"SemaphorInputReference":void 0,"SemaphorQueryRuntimeOptions"].filter(x).join(", "),d=[p||m?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,`import type { ${b} } from "react-semaphor/data-app-sdk";`,p||m?'import { fields } from "./fields";':void 0,m?'import { sources } from "./sources";':void 0,'import type { SemaphorGeneratedInputId, SemaphorGeneratedInputOptionQueryId } from "./metadata";'].filter(x).join(`
|
|
44
|
+
`);return`${M}
|
|
45
|
+
${d}
|
|
46
|
+
|
|
47
|
+
export const filterSpecs = {
|
|
48
|
+
${n}
|
|
49
|
+
} as const;
|
|
50
|
+
|
|
51
|
+
export const appInputSpecs = [${r}] as const;
|
|
52
|
+
export const appInputIds = [${o}] as const;
|
|
53
|
+
|
|
54
|
+
export type SemaphorGeneratedInputHandleMap = Partial<Record<SemaphorGeneratedInputId, SemaphorInputHandle>>;
|
|
55
|
+
|
|
56
|
+
export function createInputHandleMap(handles: readonly SemaphorInputHandle[]): SemaphorGeneratedInputHandleMap {
|
|
57
|
+
return Object.fromEntries(appInputIds.map((id, index) => [id, handles[index]])) as SemaphorGeneratedInputHandleMap;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const inputOptionQueries = {
|
|
61
|
+
${t}
|
|
62
|
+
} as const;
|
|
63
|
+
|
|
64
|
+
export const inputsForInputOptionQuery = {
|
|
65
|
+
${i}
|
|
66
|
+
} as const;
|
|
67
|
+
|
|
68
|
+
export const queryOptionsForInputOptionQuery = {
|
|
69
|
+
${u}
|
|
70
|
+
} as const;
|
|
71
|
+
|
|
72
|
+
export function queryOptionsForInputOptionQueryId(
|
|
73
|
+
${a}: SemaphorGeneratedInputOptionQueryId,
|
|
74
|
+
${$}: SemaphorGeneratedInputHandleMap,
|
|
75
|
+
): SemaphorQueryRuntimeOptions {
|
|
76
|
+
switch (${a}) {
|
|
77
|
+
${l}
|
|
78
|
+
}
|
|
79
|
+
throw new Error(\`Unknown generated Semaphor input option query id: \${${a}}\`);
|
|
80
|
+
}
|
|
81
|
+
`}function Me(e,n){const r=n.raw.dependencies;if((r==null?void 0:r.mode)==="independent")return[];const o=new Set([n.input.raw.id,...(r==null?void 0:r.excludeInputIds)||[]]),t=(r==null?void 0:r.mode)==="explicit"?new Set(r.includeInputIds||[]):void 0;return e.inputs.filter(i=>o.has(i.raw.id)?!1:t?t.has(i.raw.id):!!i.raw.fieldRef)}function He(e){const n=e.views.map(d=>{var f,F,C,V,N,T;const c=P(d.raw.sdkSpec.builder),S=qe(d);if(Y(d)&&Ae(d)){const I=(f=d.raw.visualSpec)==null?void 0:f.tableBehavior,O=g(S.pagination),s=_(d),h=G(d),q=((F=I==null?void 0:I.pagination)==null?void 0:F.pageSize)||U(O==null?void 0:O.pageSize)||U(S.limit)||100,X=h?L(d,e):[],B=h?ve({view:d,contract:e,sortFields:X,defaultField:(C=I==null?void 0:I.sorting)==null?void 0:C.defaultField}):void 0,ee=h?(V=I==null?void 0:I.sorting)==null?void 0:V.defaultDirection:void 0,ne=je({viewName:d.name,supportsPagination:s,supportsSort:h}),re=h?` const orderBy = resolveRecordsOrderBy(
|
|
82
|
+
recordsSortFieldsForView.${d.name},
|
|
83
|
+
params.sort,
|
|
84
|
+
${k(B,e)},
|
|
85
|
+
${k(ee,e)},
|
|
86
|
+
);
|
|
87
|
+
`:"",te=h?` ...(orderBy ? { orderBy } : {}),
|
|
88
|
+
`:"",oe=s?` pagination: resolveServerTablePagination(params, ${JSON.stringify(q)}),
|
|
89
|
+
`:"";return` ${d.name}(
|
|
90
|
+
params: ${ne} = {},
|
|
91
|
+
) {
|
|
92
|
+
${re} return semaphor.${c}({
|
|
93
|
+
...${k(S,e)},
|
|
94
|
+
${te}${oe} });
|
|
95
|
+
},`}if(ae(d)&&_(d)){const I=(N=d.raw.visualSpec)==null?void 0:N.tableBehavior,O=g(S.pagination),s=((T=I==null?void 0:I.pagination)==null?void 0:T.pageSize)||U(O==null?void 0:O.pageSize)||U(S.limit)||100;return` ${d.name}(
|
|
96
|
+
params: SemaphorGeneratedServerPaginationParams = {},
|
|
97
|
+
) {
|
|
98
|
+
return semaphor.${c}({
|
|
99
|
+
...${k(S,e)},
|
|
100
|
+
pagination: resolveServerTablePagination(params, ${JSON.stringify(s)}),
|
|
101
|
+
});
|
|
102
|
+
},`}return` ${d.name}: () => semaphor.${c}(${k(S,e)}),`}).join(`
|
|
103
|
+
`),r=e.views.filter(d=>G(d)).map(d=>{const S=L(d,e).map(f=>` ${JSON.stringify(f.key)}: fields.${f.fieldName},`).join(`
|
|
104
|
+
`);return` ${d.name}: {
|
|
105
|
+
${S}
|
|
106
|
+
},`}).join(`
|
|
107
|
+
`),o=e.views.filter(d=>G(d)).map(d=>{const S=L(d,e).map(f=>` { key: ${JSON.stringify(f.key)}, label: ${JSON.stringify(f.label)}, field: fields.${f.fieldName} },`).join(`
|
|
108
|
+
`);return` ${d.name}: [
|
|
109
|
+
${S}
|
|
110
|
+
],`}).join(`
|
|
111
|
+
`),t=e.views.some(d=>G(d)),i=e.views.some(d=>_(d)),u=[n,r,o].join(`
|
|
112
|
+
`),l=[n?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,t?'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(`
|
|
113
|
+
`);return`${M}
|
|
114
|
+
${l}
|
|
115
|
+
${t?`export type SemaphorGeneratedRecordsSortDirection = "asc" | "desc";
|
|
116
|
+
|
|
117
|
+
export type SemaphorGeneratedRecordsSort<TSortKey extends string = string> = {
|
|
118
|
+
key: TSortKey;
|
|
119
|
+
direction: SemaphorGeneratedRecordsSortDirection;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export type SemaphorGeneratedRecordsSortParams<TSortKey extends string = string> = {
|
|
123
|
+
sort?: SemaphorGeneratedRecordsSort<TSortKey> | null;
|
|
124
|
+
};
|
|
125
|
+
`:""}${i?`export type SemaphorGeneratedServerPaginationParams = {
|
|
126
|
+
page?: number;
|
|
127
|
+
pageSize?: number;
|
|
128
|
+
};
|
|
129
|
+
`:""}${t&&i?`export type SemaphorGeneratedRecordsQueryParams<TSortKey extends string = string> =
|
|
130
|
+
SemaphorGeneratedServerPaginationParams &
|
|
131
|
+
SemaphorGeneratedRecordsSortParams<TSortKey>;
|
|
132
|
+
`:""}
|
|
133
|
+
|
|
134
|
+
export const recordsSortFieldsForView = {
|
|
135
|
+
${r}
|
|
136
|
+
} as const;
|
|
137
|
+
|
|
138
|
+
export const recordsSortOptionsForView = {
|
|
139
|
+
${o}
|
|
140
|
+
} as const;
|
|
141
|
+
|
|
142
|
+
export const queries = {
|
|
143
|
+
${n}
|
|
144
|
+
} as const;
|
|
145
|
+
|
|
146
|
+
${t?`function resolveRecordsOrderBy<TSortKey extends string>(
|
|
147
|
+
sortFields: Record<TSortKey, SemaphorFieldRef>,
|
|
148
|
+
sort: SemaphorGeneratedRecordsSort<TSortKey> | null | undefined,
|
|
149
|
+
defaultKey: TSortKey | undefined,
|
|
150
|
+
defaultDirection: SemaphorGeneratedRecordsSortDirection | undefined,
|
|
151
|
+
) {
|
|
152
|
+
const key = sort?.key ?? defaultKey;
|
|
153
|
+
if (!key) {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
const field = sortFields[key];
|
|
157
|
+
if (!field) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
field,
|
|
162
|
+
direction: sort?.direction ?? defaultDirection ?? "asc",
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
`:""}
|
|
166
|
+
${i?`function resolveServerTablePagination(
|
|
167
|
+
params: SemaphorGeneratedServerPaginationParams,
|
|
168
|
+
defaultPageSize: number,
|
|
169
|
+
) {
|
|
170
|
+
return {
|
|
171
|
+
page: params.page ?? 1,
|
|
172
|
+
pageSize: params.pageSize ?? defaultPageSize,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
`:""}
|
|
176
|
+
`}function qe(e){var i,u;const n=g((i=e.raw.sdkSpec)==null?void 0:i.spec)||{},{kind:r,id:o,...t}=n;return{...t,id:e.raw.id,label:((u=e.raw.visualSpec)==null?void 0:u.title)||e.raw.title||t.label}}function L(e,n){var i,u;const r=[],o=g((i=e.raw.sdkSpec)==null?void 0:i.spec)||{};for(const l of j(o.fields))y(r,l);y(r,o.dateField),y(r,(u=g(o.orderBy))==null?void 0:u.field);for(const l of e.raw.fields||[])y(r,l);return de(r.map(l=>{const p=E(l,n);if(!(!l.name||!p))return{key:p,fieldName:p,rawName:l.name,label:l.label||l.name}}).filter(x),l=>l.key)}function ve({view:e,contract:n,sortFields:r,defaultField:o}){var p,m;const t=new Set(r.map(a=>a.key));if(o&&t.has(o))return o;const i=r.filter(a=>a.rawName===o);if(i.length===1)return i[0].key;const u=g((p=e.raw.sdkSpec)==null?void 0:p.spec),l=E((m=g(u==null?void 0:u.orderBy))==null?void 0:m.field,n);return l&&t.has(l)?l: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 Qe(e){const n=e.views.map(a=>{const b=De(e,a.raw.id).map(d=>{const c=d.inputId,S=E(d.fieldRef,e);if(!c||!S)return"";const f=[`field: fields.${S}`];if(d.relationshipHint)f.push(`relationshipHint: ${R(d.relationshipHint)}`);else if(Array.isArray(d.relationshipsUsed)&&d.relationshipsUsed.length>0){const C=d.relationshipsUsed.map(V=>{var N;return(N=g(V))==null?void 0:N.id}).filter(V=>typeof V=="string"&&V.length>0);C.length>0&&f.push(`relationshipHint: ${R({relationshipIds:C})}`)}const F=`inputHandles[${JSON.stringify(c)}]`;return` if (${F}) {
|
|
177
|
+
inputs.push(semaphor.bindInput(${F}, { ${f.join(", ")} }));
|
|
178
|
+
}`}).filter(Boolean).join(`
|
|
179
|
+
`);return{view:a,renderedBindings:b}}),r=n.some(a=>a.renderedBindings.length>0),o=n.map(({view:a,renderedBindings:$})=>{const b=$?"inputHandles":"_inputHandles";return` ${a.name}(${b}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
|
|
180
|
+
const inputs: SemaphorInputReference[] = [];
|
|
181
|
+
${$}
|
|
182
|
+
return inputs;
|
|
183
|
+
},`}).join(`
|
|
184
|
+
|
|
185
|
+
`),t=e.views.map(a=>` ${a.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
|
|
186
|
+
return {
|
|
187
|
+
inputs: inputsForView.${a.name}(inputHandles),
|
|
188
|
+
debug: queryDebugForView.${a.name},
|
|
189
|
+
};
|
|
190
|
+
},`).join(`
|
|
191
|
+
|
|
192
|
+
`),i=e.views.map(a=>` case ${JSON.stringify(a.raw.id)}:
|
|
193
|
+
return inputsForView.${a.name}(inputHandles);`).join(`
|
|
194
|
+
`),u=e.views.map(a=>` case ${JSON.stringify(a.raw.id)}:
|
|
195
|
+
return queryOptionsForView.${a.name}(inputHandles);`).join(`
|
|
196
|
+
`),l=e.views.length>0,p=l?"inputHandles":"_inputHandles",m=[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";',l?'import { queryDebugForView } from "./metadata";':void 0,'import type { SemaphorGeneratedQueryViewId } from "./metadata";'].filter(x).join(`
|
|
197
|
+
`);return`${M}
|
|
198
|
+
${m}
|
|
199
|
+
|
|
200
|
+
export const inputsForView = {
|
|
201
|
+
${o}
|
|
202
|
+
} as const;
|
|
203
|
+
|
|
204
|
+
export const queryOptionsForView = {
|
|
205
|
+
${t}
|
|
206
|
+
} as const;
|
|
207
|
+
|
|
208
|
+
export function inputsForViewId(
|
|
209
|
+
viewId: SemaphorGeneratedQueryViewId,
|
|
210
|
+
${p}: SemaphorGeneratedInputHandleMap,
|
|
211
|
+
): SemaphorInputReference[] {
|
|
212
|
+
switch (viewId) {
|
|
213
|
+
${i}
|
|
214
|
+
}
|
|
215
|
+
throw new Error(\`Unknown generated Semaphor view id: \${viewId}\`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function queryOptionsForViewId(
|
|
219
|
+
viewId: SemaphorGeneratedQueryViewId,
|
|
220
|
+
${p}: SemaphorGeneratedInputHandleMap,
|
|
221
|
+
): SemaphorQueryRuntimeOptions {
|
|
222
|
+
switch (viewId) {
|
|
223
|
+
${u}
|
|
224
|
+
}
|
|
225
|
+
throw new Error(\`Unknown generated Semaphor view id: \${viewId}\`);
|
|
226
|
+
}
|
|
227
|
+
`}function De(e,n){return e.filterContracts.flatMap(r=>(r.bindings||[]).filter(o=>o.viewId===n).map(o=>({inputId:r.inputId,fieldRef:o.fieldRef,relationshipHint:o.relationshipHint,relationshipsUsed:o.relationshipsUsed})))}function Ke(e){const n=e.views.map(u=>{const p=J(u,e).map(m=>{const a=E(m.raw,e);return a?` ${m.name}: fields.${a},`:""}).filter(Boolean).join(`
|
|
228
|
+
`);return` ${u.name}: {
|
|
229
|
+
${p}
|
|
230
|
+
},`}).join(`
|
|
231
|
+
`),r=e.views.map(u=>{const l=Pe(u,e);return` ${u.name}: ${R(l)},`}).join(`
|
|
232
|
+
`),o=e.views.map(u=>{const p=J(u,e).map(m=>` ${m.name}: resolveColumnKey(columns, fieldsForView.${u.name}.${m.name}),`).join(`
|
|
233
|
+
`);return` ${u.name}(columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${u.name}, string | undefined> {
|
|
234
|
+
return {
|
|
235
|
+
${p}
|
|
236
|
+
};
|
|
237
|
+
},`}).join(`
|
|
238
|
+
|
|
239
|
+
`),t=e.views.map(u=>{const p=J(u,e).map(m=>` ${m.name}: readCell(row, columns, fieldsForView.${u.name}.${m.name}),`).join(`
|
|
240
|
+
`);return` ${u.name}(row: SemaphorGeneratedRow, columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${u.name}, unknown> {
|
|
241
|
+
return {
|
|
242
|
+
${p}
|
|
243
|
+
};
|
|
244
|
+
},`}).join(`
|
|
245
|
+
|
|
246
|
+
`),i=['import type { SemaphorFieldRef, SemaphorResultColumn } from "react-semaphor/data-app-sdk";',n.includes("fields.")?'import { fields } from "./fields";':void 0].filter(x).join(`
|
|
247
|
+
`);return`${M}
|
|
248
|
+
${i}
|
|
249
|
+
|
|
250
|
+
export type SemaphorGeneratedRow = Record<string, unknown>;
|
|
251
|
+
export type SemaphorGeneratedColumns = readonly SemaphorResultColumn[] | null | undefined;
|
|
252
|
+
export type SemaphorGeneratedTableColumn = {
|
|
253
|
+
readonly key: string;
|
|
254
|
+
readonly label: string;
|
|
255
|
+
readonly dataType?: string;
|
|
256
|
+
readonly sortable?: boolean;
|
|
257
|
+
readonly sortKey?: string;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export const fieldsForView = {
|
|
261
|
+
${n}
|
|
262
|
+
} as const;
|
|
263
|
+
|
|
264
|
+
export const tableColumnsForView = {
|
|
265
|
+
${r}
|
|
266
|
+
} as const;
|
|
267
|
+
|
|
268
|
+
export const columnKeysForView = {
|
|
269
|
+
${o}
|
|
270
|
+
} as const;
|
|
271
|
+
|
|
272
|
+
export const rowValuesForView = {
|
|
273
|
+
${t}
|
|
274
|
+
} as const;
|
|
275
|
+
|
|
276
|
+
export function resolveColumnKey(
|
|
277
|
+
columns: SemaphorGeneratedColumns,
|
|
278
|
+
field: SemaphorFieldRef,
|
|
279
|
+
): string | undefined {
|
|
280
|
+
return resolveColumn(columns, field)?.key;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export function readCell(
|
|
284
|
+
row: SemaphorGeneratedRow,
|
|
285
|
+
columns: SemaphorGeneratedColumns,
|
|
286
|
+
field: SemaphorFieldRef,
|
|
287
|
+
): unknown {
|
|
288
|
+
const key = resolveColumnKey(columns, field);
|
|
289
|
+
return key ? row[key] : undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function readNumberCell(
|
|
293
|
+
row: SemaphorGeneratedRow,
|
|
294
|
+
columns: SemaphorGeneratedColumns,
|
|
295
|
+
field: SemaphorFieldRef,
|
|
296
|
+
): number | null {
|
|
297
|
+
const value = readCell(row, columns, field);
|
|
298
|
+
if (typeof value === "number") {
|
|
299
|
+
return Number.isFinite(value) ? value : null;
|
|
300
|
+
}
|
|
301
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
302
|
+
const parsed = Number(value);
|
|
303
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
304
|
+
}
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function readStringCell(
|
|
309
|
+
row: SemaphorGeneratedRow,
|
|
310
|
+
columns: SemaphorGeneratedColumns,
|
|
311
|
+
field: SemaphorFieldRef,
|
|
312
|
+
): string {
|
|
313
|
+
const value = readCell(row, columns, field);
|
|
314
|
+
return value === null || value === undefined ? "" : String(value);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function resolveColumn(
|
|
318
|
+
columns: SemaphorGeneratedColumns,
|
|
319
|
+
field: SemaphorFieldRef,
|
|
320
|
+
): SemaphorResultColumn | undefined {
|
|
321
|
+
if (!columns || columns.length === 0) {
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
return (
|
|
325
|
+
findUniqueColumn(columns, (column) => column.name === field.name && columnMatchesField(column, field, true, false)) ||
|
|
326
|
+
findUniqueColumn(columns, (column) => column.name === field.name && columnMatchesField(column, field, false, false)) ||
|
|
327
|
+
findUniqueColumn(columns, (column) => columnLabelMatchesField(column, field) && columnMatchesField(column, field, true, false)) ||
|
|
328
|
+
findUniqueColumn(columns, (column) => columnLabelMatchesField(column, field) && columnMatchesField(column, field, false, false)) ||
|
|
329
|
+
findUniqueColumn(columns, (column) => column.name === field.name && columnMatchesField(column, field, true, true)) ||
|
|
330
|
+
findUniqueColumn(columns, (column) => column.name === field.name && columnMatchesField(column, field, false, true)) ||
|
|
331
|
+
findUniqueColumn(columns, (column) => columnLabelMatchesField(column, field) && columnMatchesField(column, field, true, true)) ||
|
|
332
|
+
findUniqueColumn(columns, (column) => columnLabelMatchesField(column, field) && columnMatchesField(column, field, false, true))
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function findUniqueColumn(
|
|
337
|
+
columns: readonly SemaphorResultColumn[],
|
|
338
|
+
predicate: (column: SemaphorResultColumn) => boolean,
|
|
339
|
+
): SemaphorResultColumn | undefined {
|
|
340
|
+
const matches = columns.filter(predicate);
|
|
341
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function columnLabelMatchesField(
|
|
345
|
+
column: SemaphorResultColumn,
|
|
346
|
+
field: SemaphorFieldRef,
|
|
347
|
+
): boolean {
|
|
348
|
+
return Boolean(field.label && column.label === field.label);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function columnMatchesField(
|
|
352
|
+
column: SemaphorResultColumn,
|
|
353
|
+
field: SemaphorFieldRef,
|
|
354
|
+
requireComparableSource: boolean,
|
|
355
|
+
allowImplicitAggregate: boolean,
|
|
356
|
+
): boolean {
|
|
357
|
+
if (field.aggregate && column.aggregate && normalizeAggregate(field.aggregate) !== normalizeAggregate(column.aggregate)) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
if (
|
|
361
|
+
!field.aggregate &&
|
|
362
|
+
column.aggregate &&
|
|
363
|
+
(!allowImplicitAggregate || field.role !== "measure")
|
|
364
|
+
) {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
if (requireComparableSource && !column.source) {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
return sourcesReferToSameDataset(column.source, field.source);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function normalizeAggregate(aggregate: string): string {
|
|
374
|
+
return aggregate.trim().toLowerCase();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function sourcesReferToSameDataset(
|
|
378
|
+
left: SemaphorFieldRef["source"] | undefined,
|
|
379
|
+
right: SemaphorFieldRef["source"] | undefined,
|
|
380
|
+
): boolean {
|
|
381
|
+
if (!left || !right) {
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
if (left.kind !== right.kind) {
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
if (left.kind === "physical" && right.kind === "physical") {
|
|
388
|
+
if (left.connectionId && right.connectionId && left.connectionId !== right.connectionId) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
if (left.databaseName && right.databaseName && left.databaseName !== right.databaseName) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
if (left.schemaName && right.schemaName && left.schemaName !== right.schemaName) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
if (left.tableName && right.tableName && left.tableName !== right.tableName) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
if (left.kind === "sql" && right.kind === "sql") {
|
|
403
|
+
return !left.connectionId || !right.connectionId || left.connectionId === right.connectionId;
|
|
404
|
+
}
|
|
405
|
+
if (left.kind === "semantic" && right.kind === "semantic") {
|
|
406
|
+
if (left.domainId && right.domainId && left.domainId !== right.domainId) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
if (left.datasetId && right.datasetId) {
|
|
410
|
+
return left.datasetId === right.datasetId;
|
|
411
|
+
}
|
|
412
|
+
if (left.datasetName && right.datasetName) {
|
|
413
|
+
return left.datasetName === right.datasetName;
|
|
414
|
+
}
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
`}function Pe(e,n){const r=J(e,n),o=new Map((G(e)?L(e,n):[]).map(t=>[t.fieldName,t.key]));return r.map(t=>{const i=E(t.raw,n),u=i?o.get(i):void 0;return H({key:t.name,label:t.raw.label||t.raw.name,dataType:t.raw.dataType,sortable:!!u,sortKey:u})})}function Be(e){const n=e.checklist.filterScopeByInput||[],r=e.checklist.requiredDevtools||{},o=e.summary.views.map(a=>a.id).filter(Boolean),t=e.views.map(a=>a.raw.id).filter(Boolean),i=e.inputs.map(a=>a.raw.id).filter(Boolean),u=e.optionQueries.map(a=>a.raw.id||`${a.input.raw.id}-options`).filter(Boolean),l=Object.fromEntries(t.map(a=>[a,e.filterContracts.filter($=>Array.isArray($.appliesToViewIds)&&$.appliesToViewIds.includes(a)).map($=>$.inputId)])),p=Object.fromEntries(e.views.map(a=>[a.raw.id,{title:a.raw.title,visual:a.raw.visual,visualSpec:a.raw.visualSpec,queryKind:a.raw.queryKind,sdkBuilder:a.raw.sdkBuilder}])),m=Object.fromEntries(e.views.map(a=>{var $,b,d;return[a.name,H({viewId:a.raw.id,viewTitle:(($=a.raw.visualSpec)==null?void 0:$.title)||a.raw.title,visualType:(b=a.raw.visualSpec)==null?void 0:b.visualType,title:((d=a.raw.visualSpec)==null?void 0:d.title)||a.raw.title})]}));return`${M}
|
|
420
|
+
export const generatedViewIds = ${R(o)} as const;
|
|
421
|
+
export const generatedQueryViewIds = ${R(t)} as const;
|
|
422
|
+
export const generatedInputIds = ${R(i)} as const;
|
|
423
|
+
export const generatedInputOptionQueryIds = ${R(u)} as const;
|
|
424
|
+
|
|
425
|
+
export type SemaphorGeneratedViewId = typeof generatedViewIds[number];
|
|
426
|
+
export type SemaphorGeneratedQueryViewId = typeof generatedQueryViewIds[number];
|
|
427
|
+
export type SemaphorGeneratedInputId = typeof generatedInputIds[number];
|
|
428
|
+
export type SemaphorGeneratedInputOptionQueryId = typeof generatedInputOptionQueryIds[number];
|
|
429
|
+
export type SemaphorGeneratedFilterContract = {
|
|
430
|
+
readonly inputId: string;
|
|
431
|
+
readonly appliesToViewIds: readonly SemaphorGeneratedQueryViewId[];
|
|
432
|
+
readonly notAppliedToViewIds: readonly SemaphorGeneratedQueryViewId[];
|
|
433
|
+
readonly bindings: readonly {
|
|
434
|
+
readonly viewId: SemaphorGeneratedQueryViewId;
|
|
435
|
+
readonly fieldRef: Record<string, unknown>;
|
|
436
|
+
readonly relationshipHint?: Record<string, unknown>;
|
|
437
|
+
readonly relationshipsUsed?: readonly Record<string, unknown>[];
|
|
438
|
+
}[];
|
|
439
|
+
readonly [key: string]: unknown;
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
export const generatedInputIdsForView = ${R(l)} as const;
|
|
443
|
+
export const generatedFilterContracts: readonly SemaphorGeneratedFilterContract[] = ${R(e.filterContracts)} as const;
|
|
444
|
+
|
|
445
|
+
export function filterContractsForView(viewId: SemaphorGeneratedQueryViewId) {
|
|
446
|
+
return generatedFilterContracts.filter((filterContract) =>
|
|
447
|
+
filterContract.appliesToViewIds.includes(viewId)
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export const queryDebugForView = ${R(m)} as const;
|
|
452
|
+
|
|
453
|
+
export const semaphorGeneratedContractMetadata = ${R({schemaVersion:"semaphor-generated-data-app-contract/v1",title:e.title,requiredDevtools:r,filterContracts:e.filterContracts,filterScopeByInput:n,generatedViewIds:o,generatedQueryViewIds:t,generatedInputIds:i,generatedInputOptionQueryIds:u,generatedInputIdsForView:l,visualSpecs:p,presentationViews:e.presentationViews})} as const;
|
|
454
|
+
`}function Ue(){return`${M}
|
|
455
|
+
export * from "./sources";
|
|
456
|
+
export * from "./fields";
|
|
457
|
+
export * from "./inputs";
|
|
458
|
+
export * from "./queries";
|
|
459
|
+
export * from "./bindings";
|
|
460
|
+
export * from "./accessors";
|
|
461
|
+
export * from "./metadata";
|
|
462
|
+
`}function Q(e,n){if(!(!n||typeof n!="object")){if(Array.isArray(n)){for(const r of n)Q(e,r);return}A(n)&&y(e,Z(n));for(const r of Object.values(n))Q(e,r)}}function J(e,n){const r=[];if(Le(r,e.raw.sdkSpec),r.length===0)for(const t of e.raw.fields||[])y(r,t);const o=de(r.filter(t=>t.name&&E(t,n)).map(t=>({raw:t,key:ue(t),name:""})),t=>t.key);return v(o,t=>D(t.raw.label||t.raw.name||"field")),o}function Le(e,n){const r=g(n.spec);if(!r)return;const o=P(n.builder);if(o==="records"){for(const t of j(r.fields))y(e,t);return}if(o==="sql"){for(const t of j(r.fields))y(e,t);return}if(o==="analysis"||o==="metric"){y(e,r.primaryMeasure);for(const t of j(r.measures))y(e,t);for(const t of j(r.dimensions))y(e,t);y(e,r.dateField);return}if(o==="matrix"){const t=le(r.rows),i=le(r.columns),u=j(r.values);for(const l of t)ce(e,l);for(const l of i)ce(e,l);for(const l of u){const p=g(l);y(e,p==null?void 0:p.field),y(e,p==null?void 0:p.measure)}}}function le(e){if(Array.isArray(e))return e;const n=g(e);return Array.isArray(n==null?void 0:n.levels)?n.levels:[]}function ce(e,n){var r;if(A(n)){y(e,n);return}y(e,(r=g(n))==null?void 0:r.field)}function me(e){var n,r,o,t;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"||((o=e==null?void 0:e.computation)==null?void 0:o.kind)==="unsupported"||(e==null?void 0:e.visual)==="text_block"||((t=e==null?void 0:e.visualSpec)==null?void 0:t.visualType)==="text_block"}function Je(e){const n=g(e)||{};return H({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 y(e,n){A(n)&&e.push(Z(n))}function Z(e){return{name:e.name,label:e.label,role:e.role,dataType:e.dataType,aggregate:e.aggregate,sourceKey:e.sourceKey||(e.source?pe(e.source):void 0),...e.source?{source:e.source}:{}}}function ze(e){if(!e.source)return;const n={...e.source,...e.sourceKey?{sourceKey:e.sourceKey}:{}},r=Se(n);if(r)return{raw:n,key:r,aliases:ge(n),name:""}}function A(e){const n=g(e);return!!(n&&typeof n.name=="string"&&(typeof n.role=="string"||typeof n.dataType=="string"||typeof n.aggregate=="string"||n.source||n.sourceKey))}function ye(e){const n=g(e);return!!(n&&(typeof n.sourceKey=="string"||n.kind==="semantic"||typeof n.datasetName=="string"&&typeof n.domainId=="string"))}function k(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(t=>k(t,n)).join(", ")}]`;if(A(e)){const t=E(Z(e),n);if(t)return`fields.${t}`}if(ye(e)){const t=he(e,n);if(t)return`sources.${t}`}const r=g(e);return r?`{ ${Object.entries(r).filter(([,t])=>t!==void 0).map(([t,i])=>`${JSON.stringify(t)}: ${k(i,n)}`).join(", ")} }`:JSON.stringify(e)}function R(e){return JSON.stringify(e,null,2)}function E(e,n){if(A(e))return n.fieldNameByKey.get(ue(Z(e)))}function he(e,n){if(ye(e))for(const r of W(e)){const o=n.sourceNameByKey.get(r);if(o)return o}}function ue(e){return[e.sourceKey||"",e.name||"",e.role||"",e.aggregate||""].join("|")}function Ye(e,n){return!A(e)||!A(n)||e.name!==n.name?!1:ie(e).some(r=>ie(n).includes(r))}function Ze(e){return A(e)&&e.role==="id"}function We(e){const n=[],r=new Map;for(const o of e){const t=K(o.aliases.length?o.aliases:[o.key]),i=t.map(u=>r.get(u)).find(x);if(i){i.aliases=K([...i.aliases,...t]);continue}o.aliases=t,n.push(o);for(const u of t)r.set(u,o)}return n}function Xe(e){const n=new Map;for(const r of e)for(const o of K([r.key,...r.aliases])){const t=n.get(o);if(t&&t!==r.name)throw new Error(`Source identity ${o} resolves to multiple generated sources.`);n.set(o,r.name)}return n}function K(e){return Array.from(new Set(e.filter(Boolean)))}function Se(e){return W(e)[0]||pe(e)}function W(e){const n=g(e);if(!n)return[];const r=[];if(typeof n.sourceKey=="string"&&r.push(n.sourceKey),n.kind==="semantic"||n.datasetName){const o=typeof n.domainId=="string"?n.domainId:"";o&&typeof n.datasetId=="string"&&r.push(`semantic:${o}:datasetId:${n.datasetId}`),o&&typeof n.datasetName=="string"&&r.push(`semantic:${o}:datasetName:${n.datasetName}`)}return r.length===0&&r.push(pe(e)),K(r)}function ge(e){return W(e)}function pe(e){const n=g(e);return n?typeof n.sourceKey=="string"?n.sourceKey:JSON.stringify(n):""}function en(e){return A(e)&&ie(e)[0]||""}function ie(e){return A(e)?K([...typeof e.sourceKey=="string"?[e.sourceKey]:[],...e.source?W(e.source):[]]):[]}function P(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 nn(e){const n=P(e);return n==="records"||n==="sql"}function rn(e){const n=g(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 v(e,n){const r=new Map;for(const o of e){const t=n(o)||"item",i=r.get(t)||0;r.set(t,i+1),o.name=i===0?t:`${t}${i+1}`}}function de(e,n){const r=new Set,o=[];for(const t of e){const i=n(t);!i||r.has(i)||(r.add(i),o.push(t))}return o}function D(e){const n=String(e||"").replace(/[^A-Za-z0-9]+/g," ").trim().split(/\s+/).filter(Boolean);if(n.length===0)return"item";const[r,...o]=n,t=[r.toLowerCase(),...o.map(i=>i.charAt(0).toUpperCase()+i.slice(1).toLowerCase())].join("");return/^[A-Za-z_$]/.test(t)?t:`item${t}`}function tn(e){const n=String(e).split(":");return n[n.length-1]||String(e)}function H(e){return Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}function g(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function j(e){return Array.isArray(e)?e:[]}function U(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=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=w.CODEGEN_SUMMARY_SCHEMA_VERSION;exports.CODEGEN_SUMMARY_VALIDATOR_VERSION=w.CODEGEN_SUMMARY_VALIDATOR_VERSION;exports.CONTRACT_MANIFEST_SCHEMA_VERSION=w.CONTRACT_MANIFEST_SCHEMA_VERSION;exports.GENERATED_CONTRACT_SCHEMA_VERSION=w.GENERATED_CONTRACT_SCHEMA_VERSION;exports.GENERATED_CONTRACT_TYPESCRIPT_FILES=w.GENERATED_CONTRACT_TYPESCRIPT_FILES;exports.REQUIRED_GENERATED_CONTRACT_FILES=w.REQUIRED_GENERATED_CONTRACT_FILES;exports.assertValidCodegenSummary=w.assertValidCodegenSummary;exports.buildSemaphorGeneratedActiveInput=w.buildSemaphorGeneratedActiveInput;exports.buildSemaphorGeneratedInputOptionIntent=w.buildSemaphorGeneratedInputOptionIntent;exports.buildSemaphorGeneratedViewExecutionRequest=w.buildSemaphorGeneratedViewExecutionRequest;exports.buildSemaphorGeneratedViewExecutionRequests=w.buildSemaphorGeneratedViewExecutionRequests;exports.evaluateSemaphorDataAppContractUpdatePolicy=w.evaluateSemaphorDataAppContractUpdatePolicy;exports.validateCodegenSummary=w.validateCodegenSummary;exports.validateSemaphorGeneratedContract=w.validateSemaphorGeneratedContract;exports.DEFAULT_GENERATED_CONTRACT_OUTPUT_DIR=$e;exports.generateSemaphorDataAppContract=Fe;
|