react-semaphor 0.1.408 → 0.1.410
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 +22 -21
- package/dist/chunks/{calendar-preferences-dialog-BEJunQM-.js → calendar-preferences-dialog-B8FmFRHX.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-BDovl96B.js → calendar-preferences-dialog-ck4AU-to.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-D-G1kXb8.js → dashboard-briefing-launcher-Br_1IK1z.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-DmybDHiR.js → dashboard-briefing-launcher-Tr2SqDMK.js} +2 -2
- package/dist/chunks/{dashboard-controls-DgjlAGWu.js → dashboard-controls-B2bEv8uG.js} +3 -3
- package/dist/chunks/{dashboard-controls-DIPQW6Vj.js → dashboard-controls-B7OObDNl.js} +1 -1
- package/dist/chunks/{dashboard-json-DUmEB8x3.js → dashboard-json-DAB8WVyb.js} +1 -1
- package/dist/chunks/{dashboard-json-DvW8_MWp.js → dashboard-json-DNixjalS.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-BZnVLA4S.js → edit-dashboard-visual-DWygSAp3.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-BuwFsoeW.js → edit-dashboard-visual-Dh8Ge3-B.js} +2 -2
- package/dist/chunks/{index-DhkNgPPm.js → index-BkTLAfKy.js} +4 -4
- package/dist/chunks/{index-D7JKnhyA.js → index-CQIMj-FF.js} +2 -2
- package/dist/chunks/source-identity-BM2FvJDP.js +1 -0
- package/dist/chunks/{source-identity-y0VSSreA.js → source-identity-Cv4Nm3TM.js} +23 -15
- package/dist/chunks/{update-policy-Bv3_5LFK.js → update-policy-BnEbPhHW.js} +305 -282
- package/dist/chunks/update-policy-CWg9c08k.js +3 -0
- package/dist/chunks/{use-create-flow-overlay-state-C9QPAd9_.js → use-create-flow-overlay-state-CZA-dSns.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-B8clS9IG.js → use-create-flow-overlay-state-uujasvbD.js} +1 -1
- package/dist/chunks/{validators-DaBsAUsR.js → validators-C-_9Ew5G.js} +1 -1
- package/dist/chunks/{validators-BCQB11_y.js → validators-CB9BFarT.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 +1 -1
- package/dist/data-app-codegen/index.cjs +1 -1
- package/dist/data-app-codegen/index.js +1 -1
- package/dist/data-app-codegen-node/index.cjs +304 -105
- package/dist/data-app-codegen-node/index.js +800 -503
- package/dist/data-app-sdk/index.cjs +2 -2
- package/dist/data-app-sdk/index.js +158 -155
- package/dist/data-app-sdk-adapters/index.cjs +1 -1
- package/dist/data-app-sdk-adapters/index.js +1 -1
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/analytics-protocol.d.ts +2 -0
- package/dist/types/data-app-sdk.d.ts +3 -0
- package/package.json +1 -1
- package/dist/chunks/source-identity-uMaUe036.js +0 -1
- package/dist/chunks/update-policy-2M0canB_.js +0 -3
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("../chunks/analyze-result-contract-8nxUOWp8.js"),$=require("../chunks/update-policy-CWg9c08k.js"),ye=require("node:crypto"),Ve="src/semaphor/generated",_=`// 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
|
|
4
|
-
`};return{schemaVersion
|
|
5
|
-
`);const r=e.views.find(
|
|
6
|
-
`);const o=e.views.find(
|
|
7
|
-
`);const t=e.views.find(
|
|
8
|
-
`);const
|
|
9
|
-
`);const
|
|
10
|
-
`)
|
|
3
|
+
`;function be(e,n={}){$.assertValidCodegenSummary(e);const r=Re(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=Ce(r),t=Ne({contract:r,files:o,generatorName:n.generatorName||"react-semaphor/data-app-codegen/node",generatorVersion:n.generatorVersion||"unknown"}),a={...o,"contract.manifest.json":`${JSON.stringify(t,null,2)}
|
|
4
|
+
`};return{schemaVersion:$.GENERATED_CONTRACT_SCHEMA_VERSION,files:a,manifest:t,contentHash:String(t.generatedContentHash||""),usageExample:Ee(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 Re(e){var c,u,d,m,l,w,b,V,O,A,R,N;const n=[],r=[];for(const s of e.inputs){g(r,s.fieldRef);for(const S of s.bindings||[])g(r,S.fieldRef);g(r,(c=s.optionQuery)==null?void 0:c.valueFieldRef),g(r,(u=s.optionQuery)==null?void 0:u.labelFieldRef),g(r,(d=s.optionQuery)==null?void 0:d.filterFieldRef),j(r,(m=s.optionQuery)==null?void 0:m.spec)}for(const s of e.filterContracts){g(r,s.fieldRef),g(r,(l=s.optionQuery)==null?void 0:l.valueFieldRef),g(r,(w=s.optionQuery)==null?void 0:w.labelFieldRef),g(r,(b=s.optionQuery)==null?void 0:b.filterFieldRef),j(r,(V=s.optionQuery)==null?void 0:V.spec);for(const S of s.bindings||[])g(r,S.fieldRef)}for(const s of e.views){for(const S of s.fields||[])g(r,S);j(r,(O=s.sdkSpec)==null?void 0:O.spec),j(r,s.visualSpec)}const o=e.implementationChecklist||{};for(const s of Object.values(o.bindingsByView||{}))for(const S of Array.isArray(s)?s:[])g(r,S.fieldRef),g(r,S.optionValueField),g(r,S.optionLabelField);for(const s of o.requiredInputOptions||[])g(r,s.visibleLabelField),g(r,s.optionValueField),g(r,s.runtimeFilterField);const t=on([...e.sources.map(s=>({raw:s,key:we(s),aliases:Ie(s),name:""})),...r.map(s=>nn(s)).filter(x)]);K(t,s=>{const S=I(s.raw);return Q(s.raw.label||(S==null?void 0:S.datasetName)||(S==null?void 0:S.datasetId)||(S==null?void 0:S.name)||s.raw.kind||"source")});const a=sn(t),p=ne(r.filter(s=>s.name).map(s=>({raw:s,key:U(s),name:""})),s=>s.key);K(p,s=>Q([s.raw.sourceKey?ln(s.raw.sourceKey):"",s.raw.aggregate?s.raw.aggregate.toLowerCase():"",s.raw.name].filter(Boolean).join("_")));const f=new Map(p.map(s=>[s.key,s.name])),h=e.inputs.map(s=>({raw:s,name:Q(s.id||s.label||"input")}));K(h,s=>s.name);const y=h.filter(s=>!!s.raw.optionQuery).map(s=>({input:s,name:`${s.name}Options`,raw:s.raw.optionQuery}));K(y,s=>s.name);for(const s of y)rn(s.raw.labelFieldRef,s.raw.valueFieldRef)&&tn(s.raw.valueFieldRef)&&n.push(`Input option query ${((A=s.raw.spec)==null?void 0:A.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 i=e.views.filter(s=>{var S,B;return!!((S=s.sdkSpec)!=null&&S.builder&&((B=s.sdkSpec)!=null&&B.spec))}).map(s=>({raw:s,name:Q(s.id||s.title||"query")}));K(i,s=>s.name);const F=e.views.filter(s=>fe(s)&&!("sdkSpec"in s)).map(s=>en(s));for(const s of e.views)(!("sdkSpec"in s)||!((R=s.sdkSpec)!=null&&R.builder)||!((N=s.sdkSpec)!=null&&N.spec))&&!fe(s)&&n.push(`Skipped view ${s.id||s.title||"unknown"} because it has no sdkSpec.`);return ke({inputs:h,views:i,filterContracts:e.filterContracts}),{summary:e,title:e.title||"Semaphor Data App",sources:t,fields:p,inputs:h,optionQueries:y,views:i,presentationViews:F,filterContracts:e.filterContracts,checklist:o,sourceNameByKey:a,fieldNameByKey:f,warnings:n}}function ke({inputs:e,views:n,filterContracts:r}){const o=new Set(e.map(a=>a.raw.id).filter(Boolean)),t=new Set(n.map(a=>a.raw.id).filter(Boolean));for(const[a,p]of r.entries()){if(!o.has(p.inputId))throw new Error(`filterContracts.${a}.inputId must reference a generated input.`);const f=new Set(p.appliesToViewIds||[]),h=new Set(p.notAppliedToViewIds||[]);for(const[y,i]of(p.appliesToViewIds||[]).entries())if(!t.has(i))throw new Error(`filterContracts.${a}.appliesToViewIds.${y} must reference an executable generated view.`);for(const[y,i]of(p.notAppliedToViewIds||[]).entries())if(!t.has(i))throw new Error(`filterContracts.${a}.notAppliedToViewIds.${y} must reference an executable generated view.`);for(const[y,i]of(p.bindings||[]).entries()){if(!t.has(i.viewId))throw new Error(`filterContracts.${a}.bindings.${y}.viewId must reference an executable generated view.`);if(!f.has(i.viewId))throw new Error(`filterContracts.${a}.bindings.${y}.viewId must be included in appliesToViewIds.`);if(h.has(i.viewId))throw new Error(`filterContracts.${a}.bindings.${y}.viewId must not be listed in notAppliedToViewIds.`)}}}function Ce(e){return{"sources.ts":Ge(e),"fields.ts":_e(e),"inputs.ts":He(e),"queries.ts":qe(e),"bindings.ts":Pe(e),"accessors.ts":Ue(e),"metadata.ts":Je(e),"index.ts":ze()}}function Ne({contract:e,files:n,generatorName:r,generatorVersion:o}){return{schemaVersion:$.CONTRACT_MANIFEST_SCHEMA_VERSION,generatedContractSchemaVersion:$.GENERATED_CONTRACT_SCHEMA_VERSION,generator:{name:r,version:o},generatedContentHash:Me(n),codegenSummaryValidatorVersion:$.CODEGEN_SUMMARY_VALIDATOR_VERSION,codegenSummaryHash:Oe(e.summary),codegenSummary:e.summary}}function Me(e){const n=ye.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 Oe(e){return`sha256:${ye.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(o=>ue(o)).join(",")}]`;const n=e;return`{${Object.keys(n).sort().filter(o=>n[o]!==void 0).map(o=>`${JSON.stringify(o)}:${ue(n[o])}`).join(",")}}`}function Ee(e){const n=e.views.find(y=>G(y)&&T(y));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(y=>G(y));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(y=>X(y)&&T(y));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(y=>le(y)&&T(y));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 a=e.views.find(y=>{var i;return un((i=y.raw.sdkSpec)==null?void 0:i.builder)});if(a)return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowValuesForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const result = useSemaphorQuery(queries.${a.name}(), queryOptionsForView.${a.name}(inputHandles));`,`const rows = result.records.map((row) => rowValuesForView.${a.name}(row, result.columns));`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
|
|
9
|
+
`);const p=e.views.find(y=>xe(y));if(p)return['import { appInputSpecs, createInputHandleMap, metricValuesForView, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",`const result = useSemaphorQuery(queries.${p.name}(), queryOptionsForView.${p.name}(inputHandles));`,`const metrics = metricValuesForView.${p.name}(result);`,"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
|
|
10
|
+
`);const f=e.views[0];return['import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',"const handles = useSemaphorInputs(appInputSpecs);","const inputHandles = createInputHandleMap(handles);",f?`const result = useSemaphorQuery(queries.${f.name}(), queryOptionsForView.${f.name}(inputHandles));`:"const result = undefined;","const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"].join(`
|
|
11
|
+
`)}function X(e){var n;return q((n=e.raw.sdkSpec)==null?void 0:n.builder)==="records"}function xe(e){var n;return q((n=e.raw.sdkSpec)==null?void 0:n.builder)==="metric"}function G(e){var n,r,o;return X(e)&&((o=(r=(n=e.raw.visualSpec)==null?void 0:n.tableBehavior)==null?void 0:r.sorting)==null?void 0:o.mode)==="server"}function le(e){var n;return q((n=e.raw.sdkSpec)==null?void 0:n.builder)==="sql"}function T(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 X(e)&&(T(e)||G(e))||le(e)&&T(e)}function Ge(e){const n=e.sources.map(({name:o,raw:t})=>{const a=Te(t);return` ${o}: ${a},`}).join(`
|
|
11
12
|
`),r=e.sources.some(o=>o.raw.kind==="semantic")?`import { semaphor } from "react-semaphor/data-app-sdk";
|
|
12
13
|
|
|
13
|
-
`:"";return`${
|
|
14
|
+
`:"";return`${_}
|
|
14
15
|
${r}export const sources = {
|
|
15
16
|
${n}
|
|
16
17
|
} 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(${
|
|
18
|
+
`}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(${k(v(n))})`}return`${k(v({...e,sourceKey:void 0}))} as const`}function _e(e){const n=e.fields.map(({name:o,raw:t})=>{const a=Ke(t,e);return` ${o}: ${a},`}).join(`
|
|
18
19
|
`),r=n.includes("sources.")?`import { sources } from "./sources";
|
|
19
20
|
|
|
20
|
-
`:"";return`${
|
|
21
|
+
`:"";return`${_}
|
|
21
22
|
${r}export const fields = {
|
|
22
23
|
${n}
|
|
23
24
|
} as const;
|
|
24
|
-
`}function
|
|
25
|
-
`),r=e.inputs.map(
|
|
26
|
-
`),
|
|
27
|
-
inputs.push(semaphor.bindInput(${V}, { field: fields.${
|
|
25
|
+
`}function Ke(e,n){const r={name:e.name,label:e.label,role:e.role,dataType:e.dataType,aggregate:e.aggregate},o=an(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 a=Object.entries(v(r)).map(([p,f])=>`${JSON.stringify(p)}: ${E(f,n)}`);return t&&a.push(`"source": sources.${t}`),`{ ${a.join(", ")} }`}function He(e){const n=e.inputs.map(d=>{const m=C(d.raw.fieldRef,e),l=[`id: ${JSON.stringify(d.raw.id)}`,`label: ${JSON.stringify(d.raw.label||d.raw.id)}`,`operator: ${JSON.stringify(dn(d.raw))}`];if(m&&l.push(`field: fields.${m}`),d.raw.relationshipHint&&l.push(`relationshipHint: ${k(d.raw.relationshipHint)}`),!m)throw new Error(`Input ${d.raw.id||d.name} is missing a generated field reference.`);return` ${d.name}: semaphor.filter({ ${l.join(", ")} }),`}).join(`
|
|
26
|
+
`),r=e.inputs.map(d=>`filterSpecs.${d.name}`).join(", "),o=e.inputs.map(d=>JSON.stringify(d.raw.id)).join(", "),t=e.optionQueries.map(d=>{const m=d.input.raw,l=d.raw,w=I(l.spec)||{},{id:b,inputId:V,source:O,sourceKey:A,valueField:R,labelField:N,population:s,dependencies:S,limit:B,...re}=w,L=l.sourceKey?{sourceKey:l.sourceKey}:l.source||O||(typeof A=="string"?{sourceKey:A}:void 0),te=Se(L,e),oe=C(l.valueFieldRef,e),se=C(l.labelFieldRef,e),ae={...re,id:l.id||w.id||`${m.id}-options`,inputId:m.id,source:L,valueField:l.valueFieldRef,labelField:l.labelFieldRef,population:l.population||s,dependencies:l.dependencies||S,limit:l.limit||B||100};if(!te||!oe||!se)throw new Error(`Input option query ${l.id||`${m.id}-options`} is missing source, valueField, or labelField.`);const ie=Object.entries(v(ae)).map(([$e,Fe])=>`${JSON.stringify($e)}: ${E(Fe,e)}`);return` ${d.name}: semaphor.inputOptions({ ${ie.join(", ")} }),`}).join(`
|
|
27
|
+
`),a=e.optionQueries.map(d=>{const l=ve(e,d).map(w=>{const b=C(w.raw.fieldRef,e);if(!b)throw new Error(`Input option query ${d.raw.id||`${d.input.raw.id}-options`} references input ${w.raw.id} without a generated field reference.`);const V=`inputHandles[${JSON.stringify(w.raw.id)}]`;return` if (${V}) {
|
|
28
|
+
inputs.push(semaphor.bindInput(${V}, { field: fields.${b} }));
|
|
28
29
|
}`}).join(`
|
|
29
|
-
`);return` ${
|
|
30
|
+
`);return` ${d.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
|
|
30
31
|
const inputs: SemaphorInputReference[] = [];
|
|
31
|
-
${
|
|
32
|
+
${l}
|
|
32
33
|
return inputs;
|
|
33
34
|
},`}).join(`
|
|
34
35
|
|
|
35
|
-
`),
|
|
36
|
+
`),p=e.optionQueries.map(d=>` ${d.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
|
|
36
37
|
return {
|
|
37
|
-
inputs: inputsForInputOptionQuery.${
|
|
38
|
+
inputs: inputsForInputOptionQuery.${d.name}(inputHandles),
|
|
38
39
|
};
|
|
39
40
|
},`).join(`
|
|
40
41
|
|
|
41
|
-
`),
|
|
42
|
-
return queryOptionsForInputOptionQuery.${
|
|
43
|
-
`),
|
|
44
|
-
`);return`${
|
|
45
|
-
${
|
|
42
|
+
`),f=e.optionQueries.map(d=>` case ${JSON.stringify(d.raw.id||`${d.input.raw.id}-options`)}:
|
|
43
|
+
return queryOptionsForInputOptionQuery.${d.name}(inputHandles);`).join(`
|
|
44
|
+
`),h=e.inputs.length>0,y=e.optionQueries.length>0,i=y?"inputOptionQueryId":"_inputOptionQueryId",F=y?"inputHandles":"_inputHandles",c=["SemaphorInputHandle",y?"SemaphorInputReference":void 0,"SemaphorQueryRuntimeOptions"].filter(x).join(", "),u=[h||y?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,`import type { ${c} } from "react-semaphor/data-app-sdk";`,h||y?'import { fields } from "./fields";':void 0,y?'import { sources } from "./sources";':void 0,'import type { SemaphorGeneratedInputId, SemaphorGeneratedInputOptionQueryId } from "./metadata";'].filter(x).join(`
|
|
45
|
+
`);return`${_}
|
|
46
|
+
${u}
|
|
46
47
|
|
|
47
48
|
export const filterSpecs = {
|
|
48
49
|
${n}
|
|
@@ -62,56 +63,56 @@ ${t}
|
|
|
62
63
|
} as const;
|
|
63
64
|
|
|
64
65
|
export const inputsForInputOptionQuery = {
|
|
65
|
-
${
|
|
66
|
+
${a}
|
|
66
67
|
} as const;
|
|
67
68
|
|
|
68
69
|
export const queryOptionsForInputOptionQuery = {
|
|
69
|
-
${
|
|
70
|
+
${p}
|
|
70
71
|
} as const;
|
|
71
72
|
|
|
72
73
|
export function queryOptionsForInputOptionQueryId(
|
|
73
|
-
${
|
|
74
|
-
${
|
|
74
|
+
${i}: SemaphorGeneratedInputOptionQueryId,
|
|
75
|
+
${F}: SemaphorGeneratedInputHandleMap,
|
|
75
76
|
): SemaphorQueryRuntimeOptions {
|
|
76
|
-
switch (${
|
|
77
|
-
${
|
|
77
|
+
switch (${i}) {
|
|
78
|
+
${f}
|
|
78
79
|
}
|
|
79
|
-
throw new Error(\`Unknown generated Semaphor input option query id: \${${
|
|
80
|
+
throw new Error(\`Unknown generated Semaphor input option query id: \${${i}}\`);
|
|
80
81
|
}
|
|
81
|
-
`}function
|
|
82
|
-
recordsSortFieldsForView.${
|
|
82
|
+
`}function ve(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(a=>o.has(a.raw.id)?!1:t?t.has(a.raw.id):!!a.raw.fieldRef)}function qe(e){const n=e.views.map(u=>{var l,w,b,V,O,A;const d=q(u.raw.sdkSpec.builder),m=Be(u);if(X(u)&&Ae(u)){const R=(l=u.raw.visualSpec)==null?void 0:l.tableBehavior,N=I(m.pagination),s=T(u),S=G(u),B=((w=R==null?void 0:R.pagination)==null?void 0:w.pageSize)||z(N==null?void 0:N.pageSize)||z(m.limit)||100,re=S?Y(u,e):[],L=S?je({view:u,contract:e,sortFields:re,defaultField:(b=R==null?void 0:R.sorting)==null?void 0:b.defaultField}):void 0,te=S?(V=R==null?void 0:R.sorting)==null?void 0:V.defaultDirection:void 0,oe=Qe({viewName:u.name,supportsPagination:s,supportsSort:S}),se=S?` const orderBy = resolveRecordsOrderBy(
|
|
83
|
+
recordsSortFieldsForView.${u.name},
|
|
83
84
|
params.sort,
|
|
84
|
-
${
|
|
85
|
-
${
|
|
85
|
+
${E(L,e)},
|
|
86
|
+
${E(te,e)},
|
|
86
87
|
);
|
|
87
|
-
`:"",
|
|
88
|
-
`:"",
|
|
89
|
-
`:"";return` ${
|
|
90
|
-
params: ${
|
|
88
|
+
`:"",ae=S?` ...(orderBy ? { orderBy } : {}),
|
|
89
|
+
`:"",ie=s?` pagination: resolveServerTablePagination(params, ${JSON.stringify(B)}),
|
|
90
|
+
`:"";return` ${u.name}(
|
|
91
|
+
params: ${oe} = {},
|
|
91
92
|
) {
|
|
92
|
-
${
|
|
93
|
-
...${
|
|
94
|
-
${
|
|
95
|
-
},`}if(
|
|
93
|
+
${se} return semaphor.${d}({
|
|
94
|
+
...${E(m,e)},
|
|
95
|
+
${ae}${ie} });
|
|
96
|
+
},`}if(le(u)&&T(u)){const R=(O=u.raw.visualSpec)==null?void 0:O.tableBehavior,N=I(m.pagination),s=((A=R==null?void 0:R.pagination)==null?void 0:A.pageSize)||z(N==null?void 0:N.pageSize)||z(m.limit)||100;return` ${u.name}(
|
|
96
97
|
params: SemaphorGeneratedServerPaginationParams = {},
|
|
97
98
|
) {
|
|
98
|
-
return semaphor.${
|
|
99
|
-
...${
|
|
99
|
+
return semaphor.${d}({
|
|
100
|
+
...${E(m,e)},
|
|
100
101
|
pagination: resolveServerTablePagination(params, ${JSON.stringify(s)}),
|
|
101
102
|
});
|
|
102
|
-
},`}return` ${
|
|
103
|
-
`),r=e.views.filter(
|
|
104
|
-
`);return` ${
|
|
105
|
-
${
|
|
103
|
+
},`}return` ${u.name}: () => semaphor.${d}(${E(m,e)}),`}).join(`
|
|
104
|
+
`),r=e.views.filter(u=>G(u)).map(u=>{const m=Y(u,e).map(l=>` ${JSON.stringify(l.key)}: fields.${l.fieldName},`).join(`
|
|
105
|
+
`);return` ${u.name}: {
|
|
106
|
+
${m}
|
|
106
107
|
},`}).join(`
|
|
107
|
-
`),o=e.views.filter(
|
|
108
|
-
`);return` ${
|
|
109
|
-
${
|
|
108
|
+
`),o=e.views.filter(u=>G(u)).map(u=>{const m=Y(u,e).map(l=>` { key: ${JSON.stringify(l.key)}, label: ${JSON.stringify(l.label)}, field: fields.${l.fieldName} },`).join(`
|
|
109
|
+
`);return` ${u.name}: [
|
|
110
|
+
${m}
|
|
110
111
|
],`}).join(`
|
|
111
|
-
`),t=e.views.some(
|
|
112
|
-
`),
|
|
113
|
-
`);return`${
|
|
114
|
-
${
|
|
112
|
+
`),t=e.views.some(u=>G(u)),a=e.views.some(u=>T(u)),p=[n,r,o].join(`
|
|
113
|
+
`),f=[n?'import { semaphor } from "react-semaphor/data-app-sdk";':void 0,t?'import type { SemaphorFieldRef } from "react-semaphor/data-app-sdk";':void 0,p.includes("fields.")?'import { fields } from "./fields";':void 0,p.includes("sources.")?'import { sources } from "./sources";':void 0].filter(x).join(`
|
|
114
|
+
`);return`${_}
|
|
115
|
+
${f}
|
|
115
116
|
${t?`export type SemaphorGeneratedRecordsSortDirection = "asc" | "desc";
|
|
116
117
|
|
|
117
118
|
export type SemaphorGeneratedRecordsSort<TSortKey extends string = string> = {
|
|
@@ -122,11 +123,11 @@ export type SemaphorGeneratedRecordsSort<TSortKey extends string = string> = {
|
|
|
122
123
|
export type SemaphorGeneratedRecordsSortParams<TSortKey extends string = string> = {
|
|
123
124
|
sort?: SemaphorGeneratedRecordsSort<TSortKey> | null;
|
|
124
125
|
};
|
|
125
|
-
`:""}${
|
|
126
|
+
`:""}${a?`export type SemaphorGeneratedServerPaginationParams = {
|
|
126
127
|
page?: number;
|
|
127
128
|
pageSize?: number;
|
|
128
129
|
};
|
|
129
|
-
`:""}${t&&
|
|
130
|
+
`:""}${t&&a?`export type SemaphorGeneratedRecordsQueryParams<TSortKey extends string = string> =
|
|
130
131
|
SemaphorGeneratedServerPaginationParams &
|
|
131
132
|
SemaphorGeneratedRecordsSortParams<TSortKey>;
|
|
132
133
|
`:""}
|
|
@@ -163,7 +164,7 @@ ${t?`function resolveRecordsOrderBy<TSortKey extends string>(
|
|
|
163
164
|
};
|
|
164
165
|
}
|
|
165
166
|
`:""}
|
|
166
|
-
${
|
|
167
|
+
${a?`function resolveServerTablePagination(
|
|
167
168
|
params: SemaphorGeneratedServerPaginationParams,
|
|
168
169
|
defaultPageSize: number,
|
|
169
170
|
) {
|
|
@@ -173,29 +174,29 @@ ${i?`function resolveServerTablePagination(
|
|
|
173
174
|
};
|
|
174
175
|
}
|
|
175
176
|
`:""}
|
|
176
|
-
`}function
|
|
177
|
-
inputs.push(semaphor.bindInput(${
|
|
177
|
+
`}function Be(e){var a,p;const n=I((a=e.raw.sdkSpec)==null?void 0:a.spec)||{},{kind:r,id:o,...t}=n;return{...t,id:e.raw.id,label:((p=e.raw.visualSpec)==null?void 0:p.title)||e.raw.title||t.label}}function Y(e,n){var a,p;const r=[],o=I((a=e.raw.sdkSpec)==null?void 0:a.spec)||{};for(const f of H(o.fields))g(r,f);g(r,o.dateField),g(r,(p=I(o.orderBy))==null?void 0:p.field);for(const f of e.raw.fields||[])g(r,f);return ne(r.map(f=>{const h=C(f,n);if(!(!f.name||!h))return{key:h,fieldName:h,rawName:f.name,label:f.label||f.name}}).filter(x),f=>f.key)}function je({view:e,contract:n,sortFields:r,defaultField:o}){var h,y;const t=new Set(r.map(i=>i.key));if(o&&t.has(o))return o;const a=r.filter(i=>i.rawName===o);if(a.length===1)return a[0].key;const p=I((h=e.raw.sdkSpec)==null?void 0:h.spec),f=C((y=I(p==null?void 0:p.orderBy))==null?void 0:y.field,n);return f&&t.has(f)?f:void 0}function Qe({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 Pe(e){const n=e.views.map(i=>{const c=De(e,i.raw.id).map(u=>{const d=u.inputId,m=C(u.fieldRef,e);if(!d||!m)return"";const l=[`field: fields.${m}`];if(u.relationshipHint)l.push(`relationshipHint: ${k(u.relationshipHint)}`);else if(Array.isArray(u.relationshipsUsed)&&u.relationshipsUsed.length>0){const b=u.relationshipsUsed.map(V=>{var O;return(O=I(V))==null?void 0:O.id}).filter(V=>typeof V=="string"&&V.length>0);b.length>0&&l.push(`relationshipHint: ${k({relationshipIds:b})}`)}const w=`inputHandles[${JSON.stringify(d)}]`;return` if (${w}) {
|
|
178
|
+
inputs.push(semaphor.bindInput(${w}, { ${l.join(", ")} }));
|
|
178
179
|
}`}).filter(Boolean).join(`
|
|
179
|
-
`);return{view:
|
|
180
|
+
`);return{view:i,renderedBindings:c}}),r=n.some(i=>i.renderedBindings.length>0),o=n.map(({view:i,renderedBindings:F})=>{const c=F?"inputHandles":"_inputHandles";return` ${i.name}(${c}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
|
|
180
181
|
const inputs: SemaphorInputReference[] = [];
|
|
181
|
-
${
|
|
182
|
+
${F}
|
|
182
183
|
return inputs;
|
|
183
184
|
},`}).join(`
|
|
184
185
|
|
|
185
|
-
`),t=e.views.map(
|
|
186
|
+
`),t=e.views.map(i=>` ${i.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
|
|
186
187
|
return {
|
|
187
|
-
inputs: inputsForView.${
|
|
188
|
-
debug: queryDebugForView.${
|
|
188
|
+
inputs: inputsForView.${i.name}(inputHandles),
|
|
189
|
+
debug: queryDebugForView.${i.name},
|
|
189
190
|
};
|
|
190
191
|
},`).join(`
|
|
191
192
|
|
|
192
|
-
`),
|
|
193
|
-
return inputsForView.${
|
|
194
|
-
`),
|
|
195
|
-
return queryOptionsForView.${
|
|
196
|
-
`),
|
|
197
|
-
`);return`${
|
|
198
|
-
${
|
|
193
|
+
`),a=e.views.map(i=>` case ${JSON.stringify(i.raw.id)}:
|
|
194
|
+
return inputsForView.${i.name}(inputHandles);`).join(`
|
|
195
|
+
`),p=e.views.map(i=>` case ${JSON.stringify(i.raw.id)}:
|
|
196
|
+
return queryOptionsForView.${i.name}(inputHandles);`).join(`
|
|
197
|
+
`),f=e.views.length>0,h=f?"inputHandles":"_inputHandles",y=[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";',f?'import { queryDebugForView } from "./metadata";':void 0,'import type { SemaphorGeneratedQueryViewId } from "./metadata";'].filter(x).join(`
|
|
198
|
+
`);return`${_}
|
|
199
|
+
${y}
|
|
199
200
|
|
|
200
201
|
export const inputsForView = {
|
|
201
202
|
${o}
|
|
@@ -207,48 +208,79 @@ ${t}
|
|
|
207
208
|
|
|
208
209
|
export function inputsForViewId(
|
|
209
210
|
viewId: SemaphorGeneratedQueryViewId,
|
|
210
|
-
${
|
|
211
|
+
${h}: SemaphorGeneratedInputHandleMap,
|
|
211
212
|
): SemaphorInputReference[] {
|
|
212
213
|
switch (viewId) {
|
|
213
|
-
${
|
|
214
|
+
${a}
|
|
214
215
|
}
|
|
215
216
|
throw new Error(\`Unknown generated Semaphor view id: \${viewId}\`);
|
|
216
217
|
}
|
|
217
218
|
|
|
218
219
|
export function queryOptionsForViewId(
|
|
219
220
|
viewId: SemaphorGeneratedQueryViewId,
|
|
220
|
-
${
|
|
221
|
+
${h}: SemaphorGeneratedInputHandleMap,
|
|
221
222
|
): SemaphorQueryRuntimeOptions {
|
|
222
223
|
switch (viewId) {
|
|
223
|
-
${
|
|
224
|
+
${p}
|
|
224
225
|
}
|
|
225
226
|
throw new Error(\`Unknown generated Semaphor view id: \${viewId}\`);
|
|
226
227
|
}
|
|
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
|
|
228
|
-
`);return` ${
|
|
229
|
-
${
|
|
228
|
+
`}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 Ue(e){const n=e.views.map(c=>{const d=W(c,e).map(m=>{const l=C(m.raw,e);return l?` ${m.name}: fields.${l},`:""}).filter(Boolean).join(`
|
|
229
|
+
`);return` ${c.name}: {
|
|
230
|
+
${d}
|
|
231
|
+
},`}).join(`
|
|
232
|
+
`),r=e.views.map(c=>{const d=J(c,e).map(m=>{const l=C(m.raw,e);return l?` ${m.name}: fields.${l},`:""}).filter(Boolean).join(`
|
|
233
|
+
`);return` ${c.name}: {
|
|
234
|
+
${d}
|
|
230
235
|
},`}).join(`
|
|
231
|
-
`),
|
|
232
|
-
`)
|
|
233
|
-
|
|
236
|
+
`),o=e.views.map(c=>{const u=J(c,e),d=Ze(u),m=We(u),l=u.map(w=>{const b=Array.from(new Set(ge(w.raw).filter(V=>m.has(V))));return` ${w.name}: metricKeysForField(metricFieldsForView.${c.name}.${w.name}, { allowNameFallback: ${d.has(w.raw.name)?"false":"true"}, excludedKeys: ${k(b)} }),`}).join(`
|
|
237
|
+
`);return` ${c.name}: {
|
|
238
|
+
${l}
|
|
239
|
+
},`}).join(`
|
|
240
|
+
`),t=e.views.map(c=>{const d=J(c,e).map(m=>` ${m.name}: semaphorMetricMeasureBindingKey(metricFieldsForView.${c.name}.${m.name}),`).join(`
|
|
241
|
+
`);return` ${c.name}: {
|
|
242
|
+
${d}
|
|
243
|
+
},`}).join(`
|
|
244
|
+
`),a=e.views.map(c=>{const u=J(c,e);if(u.length===0)return` ${c.name}(): Record<keyof typeof metricFieldsForView.${c.name}, unknown> {
|
|
245
|
+
return {};
|
|
246
|
+
},`;const d=Ye(c,u),m=u.map(l=>{const w=`metricMeasureKeysForView.${c.name}.${l.name}`,b=`metricMeasureBindingKeysForView.${c.name}.${l.name}`,V=d.has(l.name)?`readMetricValueByBindingWithFallback(measures, measureBindings, ${b}, ${w}, scalarValue)`:`readMetricValueByBinding(measures, measureBindings, ${b}, ${w})`;return` ${l.name}: ${V},`}).join(`
|
|
247
|
+
`);return` ${c.name}(result: SemaphorGeneratedMetricResult): Record<keyof typeof metricFieldsForView.${c.name}, unknown> {
|
|
248
|
+
const measures = result?.measures;
|
|
249
|
+
const measureBindings = result?.measureBindings;
|
|
250
|
+
const scalarValue = result?.value;
|
|
234
251
|
return {
|
|
235
|
-
${
|
|
252
|
+
${m}
|
|
236
253
|
};
|
|
237
254
|
},`}).join(`
|
|
238
255
|
|
|
239
|
-
`),
|
|
240
|
-
`)
|
|
256
|
+
`),p=e.views.map(c=>{const u=Le(c,e);return` ${c.name}: ${k(u)},`}).join(`
|
|
257
|
+
`),f=e.views.map(c=>{const d=W(c,e).map(m=>` ${m.name}: resolveColumnKey(columns, fieldsForView.${c.name}.${m.name}),`).join(`
|
|
258
|
+
`);return` ${c.name}(columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${c.name}, string | undefined> {
|
|
241
259
|
return {
|
|
242
|
-
${
|
|
260
|
+
${d}
|
|
243
261
|
};
|
|
244
262
|
},`}).join(`
|
|
245
263
|
|
|
246
|
-
`),
|
|
247
|
-
`);return
|
|
248
|
-
|
|
264
|
+
`),h=e.views.map(c=>{const d=W(c,e).map(m=>` ${m.name}: readCell(row, columns, fieldsForView.${c.name}.${m.name}),`).join(`
|
|
265
|
+
`);return` ${c.name}(row: SemaphorGeneratedRow, columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${c.name}, unknown> {
|
|
266
|
+
return {
|
|
267
|
+
${d}
|
|
268
|
+
};
|
|
269
|
+
},`}).join(`
|
|
270
|
+
|
|
271
|
+
`),y=n.includes("fields.")||r.includes("fields."),F=[`import { ${["type SemaphorFieldRef","type SemaphorResultColumn","semaphorMetricMeasureBindingKey"].filter(x).join(", ")} } from "react-semaphor/data-app-sdk";`,y?'import { fields } from "./fields";':void 0].filter(x).join(`
|
|
272
|
+
`);return`${_}
|
|
273
|
+
${F}
|
|
249
274
|
|
|
250
275
|
export type SemaphorGeneratedRow = Record<string, unknown>;
|
|
251
276
|
export type SemaphorGeneratedColumns = readonly SemaphorResultColumn[] | null | undefined;
|
|
277
|
+
export type SemaphorGeneratedMetricMeasures = Record<string, unknown> | null | undefined;
|
|
278
|
+
export type SemaphorGeneratedMetricMeasureBindings = Record<string, string> | null | undefined;
|
|
279
|
+
export type SemaphorGeneratedMetricResult = {
|
|
280
|
+
readonly measures?: SemaphorGeneratedMetricMeasures;
|
|
281
|
+
readonly measureBindings?: SemaphorGeneratedMetricMeasureBindings;
|
|
282
|
+
readonly value?: unknown;
|
|
283
|
+
} | null | undefined;
|
|
252
284
|
export type SemaphorGeneratedTableColumn = {
|
|
253
285
|
readonly key: string;
|
|
254
286
|
readonly label: string;
|
|
@@ -261,18 +293,34 @@ export const fieldsForView = {
|
|
|
261
293
|
${n}
|
|
262
294
|
} as const;
|
|
263
295
|
|
|
264
|
-
export const
|
|
296
|
+
export const metricFieldsForView = {
|
|
265
297
|
${r}
|
|
266
298
|
} as const;
|
|
267
299
|
|
|
268
|
-
export const
|
|
300
|
+
export const metricMeasureKeysForView = {
|
|
269
301
|
${o}
|
|
270
302
|
} as const;
|
|
271
303
|
|
|
272
|
-
export const
|
|
304
|
+
export const metricMeasureBindingKeysForView = {
|
|
273
305
|
${t}
|
|
274
306
|
} as const;
|
|
275
307
|
|
|
308
|
+
export const tableColumnsForView = {
|
|
309
|
+
${p}
|
|
310
|
+
} as const;
|
|
311
|
+
|
|
312
|
+
export const columnKeysForView = {
|
|
313
|
+
${f}
|
|
314
|
+
} as const;
|
|
315
|
+
|
|
316
|
+
export const rowValuesForView = {
|
|
317
|
+
${h}
|
|
318
|
+
} as const;
|
|
319
|
+
|
|
320
|
+
export const metricValuesForView = {
|
|
321
|
+
${a}
|
|
322
|
+
} as const;
|
|
323
|
+
|
|
276
324
|
export function resolveColumnKey(
|
|
277
325
|
columns: SemaphorGeneratedColumns,
|
|
278
326
|
field: SemaphorFieldRef,
|
|
@@ -314,6 +362,157 @@ export function readStringCell(
|
|
|
314
362
|
return value === null || value === undefined ? "" : String(value);
|
|
315
363
|
}
|
|
316
364
|
|
|
365
|
+
export function readMetricValue(
|
|
366
|
+
measures: SemaphorGeneratedMetricMeasures,
|
|
367
|
+
field: SemaphorFieldRef,
|
|
368
|
+
): unknown {
|
|
369
|
+
return readMetricValueByKeys(measures, metricKeysForField(field));
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function readMetricValueByKeys(
|
|
373
|
+
measures: SemaphorGeneratedMetricMeasures,
|
|
374
|
+
keys: readonly string[],
|
|
375
|
+
): unknown {
|
|
376
|
+
if (!measures) {
|
|
377
|
+
return undefined;
|
|
378
|
+
}
|
|
379
|
+
for (const key of keys) {
|
|
380
|
+
if (Object.prototype.hasOwnProperty.call(measures, key)) {
|
|
381
|
+
return measures[key];
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return undefined;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export function readMetricValueByBinding(
|
|
388
|
+
measures: SemaphorGeneratedMetricMeasures,
|
|
389
|
+
measureBindings: SemaphorGeneratedMetricMeasureBindings,
|
|
390
|
+
bindingKey: string,
|
|
391
|
+
fallbackKeys: readonly string[],
|
|
392
|
+
): unknown {
|
|
393
|
+
const resultKey = measureBindings?.[bindingKey];
|
|
394
|
+
if (resultKey && measures && Object.prototype.hasOwnProperty.call(measures, resultKey)) {
|
|
395
|
+
return measures[resultKey];
|
|
396
|
+
}
|
|
397
|
+
return readMetricValueByKeys(measures, fallbackKeys);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export function readMetricValueByKeysWithFallback(
|
|
401
|
+
measures: SemaphorGeneratedMetricMeasures,
|
|
402
|
+
keys: readonly string[],
|
|
403
|
+
fallbackValue: unknown,
|
|
404
|
+
): unknown {
|
|
405
|
+
const value = readMetricValueByKeys(measures, keys);
|
|
406
|
+
return value === undefined ? fallbackValue : value;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function readMetricValueByBindingWithFallback(
|
|
410
|
+
measures: SemaphorGeneratedMetricMeasures,
|
|
411
|
+
measureBindings: SemaphorGeneratedMetricMeasureBindings,
|
|
412
|
+
bindingKey: string,
|
|
413
|
+
fallbackKeys: readonly string[],
|
|
414
|
+
fallbackValue: unknown,
|
|
415
|
+
): unknown {
|
|
416
|
+
const value = readMetricValueByBinding(measures, measureBindings, bindingKey, fallbackKeys);
|
|
417
|
+
return value === undefined ? fallbackValue : value;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export function readNumberMetricValue(
|
|
421
|
+
measures: SemaphorGeneratedMetricMeasures,
|
|
422
|
+
field: SemaphorFieldRef,
|
|
423
|
+
): number | null {
|
|
424
|
+
const value = readMetricValue(measures, field);
|
|
425
|
+
if (typeof value === "number") {
|
|
426
|
+
return Number.isFinite(value) ? value : null;
|
|
427
|
+
}
|
|
428
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
429
|
+
const parsed = Number(value);
|
|
430
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
431
|
+
}
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export function readStringMetricValue(
|
|
436
|
+
measures: SemaphorGeneratedMetricMeasures,
|
|
437
|
+
field: SemaphorFieldRef,
|
|
438
|
+
): string {
|
|
439
|
+
const value = readMetricValue(measures, field);
|
|
440
|
+
return value === null || value === undefined ? "" : String(value);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export function metricKeysForField(
|
|
444
|
+
field: SemaphorFieldRef,
|
|
445
|
+
options: { allowNameFallback?: boolean; excludedKeys?: readonly string[] } = {},
|
|
446
|
+
): string[] {
|
|
447
|
+
const prefixes = metricKeyPrefixesForSource(field.source);
|
|
448
|
+
const aggregate = metricAggregateForField(field);
|
|
449
|
+
const excludedKeys = new Set(options.excludedKeys || []);
|
|
450
|
+
return uniqueStrings([
|
|
451
|
+
metricQualifiedKeyForField(field),
|
|
452
|
+
...prefixes.map((prefix) => \`\${prefix}.\${field.name}\`),
|
|
453
|
+
\`\${aggregate.toLowerCase()}_\${field.name}\`,
|
|
454
|
+
\`\${aggregate}_\${field.name}\`,
|
|
455
|
+
\`\${field.name}_\${aggregate.toLowerCase()}\`,
|
|
456
|
+
\`\${field.name}_\${aggregate}\`,
|
|
457
|
+
...(options.allowNameFallback === false ? [] : [field.name]),
|
|
458
|
+
]).filter((key) => !excludedKeys.has(key));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function metricQualifiedKeyForField(field: SemaphorFieldRef): string {
|
|
462
|
+
return semaphorMetricMeasureBindingKey(field);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function metricAggregateForField(field: SemaphorFieldRef): string {
|
|
466
|
+
return stringProperty(field as Record<string, unknown>, "aggregate")?.toUpperCase() || "SUM";
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function metricKeyPrefixesForSource(
|
|
470
|
+
source: SemaphorFieldRef["source"] | undefined,
|
|
471
|
+
): string[] {
|
|
472
|
+
if (!source) {
|
|
473
|
+
return [];
|
|
474
|
+
}
|
|
475
|
+
const sourceRecord = source as Record<string, unknown>;
|
|
476
|
+
if (source.kind === "semantic") {
|
|
477
|
+
const prefixes: string[] = [];
|
|
478
|
+
const datasetName = stringProperty(sourceRecord, "datasetName");
|
|
479
|
+
const datasetId = stringProperty(sourceRecord, "datasetId");
|
|
480
|
+
if (datasetName) {
|
|
481
|
+
prefixes.push(datasetName);
|
|
482
|
+
}
|
|
483
|
+
if (datasetId) {
|
|
484
|
+
prefixes.push(datasetId);
|
|
485
|
+
}
|
|
486
|
+
return uniqueStrings(prefixes);
|
|
487
|
+
}
|
|
488
|
+
if (source.kind === "physical") {
|
|
489
|
+
const prefixes: string[] = [];
|
|
490
|
+
const databaseName = stringProperty(sourceRecord, "databaseName");
|
|
491
|
+
const schemaName = stringProperty(sourceRecord, "schemaName");
|
|
492
|
+
const tableName = stringProperty(sourceRecord, "tableName");
|
|
493
|
+
if (tableName) {
|
|
494
|
+
prefixes.push(tableName);
|
|
495
|
+
}
|
|
496
|
+
if (schemaName && tableName) {
|
|
497
|
+
prefixes.push(\`\${schemaName}.\${tableName}\`);
|
|
498
|
+
}
|
|
499
|
+
if (databaseName && schemaName && tableName) {
|
|
500
|
+
prefixes.push(\`\${databaseName}.\${schemaName}.\${tableName}\`);
|
|
501
|
+
}
|
|
502
|
+
return uniqueStrings(prefixes);
|
|
503
|
+
}
|
|
504
|
+
return [];
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function stringProperty(record: Record<string, unknown>, key: string): string | undefined {
|
|
508
|
+
const value = record[key];
|
|
509
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function uniqueStrings(values: string[]): string[] {
|
|
513
|
+
return Array.from(new Set(values.filter((value) => value.length > 0)));
|
|
514
|
+
}
|
|
515
|
+
|
|
317
516
|
function resolveColumn(
|
|
318
517
|
columns: SemaphorGeneratedColumns,
|
|
319
518
|
field: SemaphorFieldRef,
|
|
@@ -416,11 +615,11 @@ function sourcesReferToSameDataset(
|
|
|
416
615
|
}
|
|
417
616
|
return false;
|
|
418
617
|
}
|
|
419
|
-
`}function
|
|
420
|
-
export const generatedViewIds = ${
|
|
421
|
-
export const generatedQueryViewIds = ${
|
|
422
|
-
export const generatedInputIds = ${
|
|
423
|
-
export const generatedInputOptionQueryIds = ${
|
|
618
|
+
`}function Le(e,n){const r=W(e,n),o=new Map((G(e)?Y(e,n):[]).map(t=>[t.fieldName,t.key]));return r.map(t=>{const a=C(t.raw,n),p=a?o.get(a):void 0;return v({key:t.name,label:t.raw.label||t.raw.name,dataType:t.raw.dataType,sortable:!!p,sortKey:p})})}function Je(e){const n=e.checklist.filterScopeByInput||[],r=e.checklist.requiredDevtools||{},o=e.summary.views.map(i=>i.id).filter(Boolean),t=e.views.map(i=>i.raw.id).filter(Boolean),a=e.inputs.map(i=>i.raw.id).filter(Boolean),p=e.optionQueries.map(i=>i.raw.id||`${i.input.raw.id}-options`).filter(Boolean),f=Object.fromEntries(t.map(i=>[i,e.filterContracts.filter(F=>Array.isArray(F.appliesToViewIds)&&F.appliesToViewIds.includes(i)).map(F=>F.inputId)])),h=Object.fromEntries(e.views.map(i=>[i.raw.id,{title:i.raw.title,visual:i.raw.visual,visualSpec:i.raw.visualSpec,queryKind:i.raw.queryKind,sdkBuilder:i.raw.sdkBuilder}])),y=Object.fromEntries(e.views.map(i=>{var F,c,u;return[i.name,v({viewId:i.raw.id,viewTitle:((F=i.raw.visualSpec)==null?void 0:F.title)||i.raw.title,visualType:(c=i.raw.visualSpec)==null?void 0:c.visualType,title:((u=i.raw.visualSpec)==null?void 0:u.title)||i.raw.title})]}));return`${_}
|
|
619
|
+
export const generatedViewIds = ${k(o)} as const;
|
|
620
|
+
export const generatedQueryViewIds = ${k(t)} as const;
|
|
621
|
+
export const generatedInputIds = ${k(a)} as const;
|
|
622
|
+
export const generatedInputOptionQueryIds = ${k(p)} as const;
|
|
424
623
|
|
|
425
624
|
export type SemaphorGeneratedViewId = typeof generatedViewIds[number];
|
|
426
625
|
export type SemaphorGeneratedQueryViewId = typeof generatedQueryViewIds[number];
|
|
@@ -439,8 +638,8 @@ export type SemaphorGeneratedFilterContract = {
|
|
|
439
638
|
readonly [key: string]: unknown;
|
|
440
639
|
};
|
|
441
640
|
|
|
442
|
-
export const generatedInputIdsForView = ${
|
|
443
|
-
export const generatedFilterContracts: readonly SemaphorGeneratedFilterContract[] = ${
|
|
641
|
+
export const generatedInputIdsForView = ${k(f)} as const;
|
|
642
|
+
export const generatedFilterContracts: readonly SemaphorGeneratedFilterContract[] = ${k(e.filterContracts)} as const;
|
|
444
643
|
|
|
445
644
|
export function filterContractsForView(viewId: SemaphorGeneratedQueryViewId) {
|
|
446
645
|
return generatedFilterContracts.filter((filterContract) =>
|
|
@@ -448,10 +647,10 @@ export function filterContractsForView(viewId: SemaphorGeneratedQueryViewId) {
|
|
|
448
647
|
);
|
|
449
648
|
}
|
|
450
649
|
|
|
451
|
-
export const queryDebugForView = ${
|
|
650
|
+
export const queryDebugForView = ${k(y)} as const;
|
|
452
651
|
|
|
453
|
-
export const semaphorGeneratedContractMetadata = ${
|
|
454
|
-
`}function
|
|
652
|
+
export const semaphorGeneratedContractMetadata = ${k({schemaVersion:"semaphor-generated-data-app-contract/v1",title:e.title,requiredDevtools:r,filterContracts:e.filterContracts,filterScopeByInput:n,generatedViewIds:o,generatedQueryViewIds:t,generatedInputIds:a,generatedInputOptionQueryIds:p,generatedInputIdsForView:f,visualSpecs:h,presentationViews:e.presentationViews})} as const;
|
|
653
|
+
`}function ze(){return`${_}
|
|
455
654
|
export * from "./sources";
|
|
456
655
|
export * from "./fields";
|
|
457
656
|
export * from "./inputs";
|
|
@@ -459,4 +658,4 @@ export * from "./queries";
|
|
|
459
658
|
export * from "./bindings";
|
|
460
659
|
export * from "./accessors";
|
|
461
660
|
export * from "./metadata";
|
|
462
|
-
`}function
|
|
661
|
+
`}function j(e,n){if(!(!n||typeof n!="object")){if(Array.isArray(n)){for(const r of n)j(e,r);return}M(n)&&g(e,D(n));for(const r of Object.values(n))j(e,r)}}function W(e,n){const r=[];if(Xe(r,e.raw.sdkSpec),r.length===0)for(const t of e.raw.fields||[])g(r,t);const o=ne(r.filter(t=>t.name&&C(t,n)).map(t=>({raw:t,key:U(t),name:""})),t=>t.key);return K(o,t=>Q(t.raw.label||t.raw.name||"field")),o}function J(e,n){if(q(e.raw.sdkSpec.builder)!=="metric")return[];const r=I(e.raw.sdkSpec.spec),o=[];g(o,r==null?void 0:r.primaryMeasure);for(const a of H(r==null?void 0:r.measures))g(o,a);const t=ne(o.filter(a=>a.name&&C(a,n)).map(a=>({raw:a,key:U(a),name:""})),a=>a.key);return K(t,a=>Q(a.raw.label||a.raw.name||"metric")),t}function Ye(e,n){if(n.length===1)return new Set([n[0].name]);const r=I(e.raw.sdkSpec.spec);if(!M(r==null?void 0:r.primaryMeasure))return new Set;const o=U(D(r.primaryMeasure)),t=n.find(a=>a.key===o);return t?new Set([t.name]):new Set}function We(e){const n=new Map;for(const r of e)for(const o of new Set(ge(r.raw)))n.set(o,(n.get(o)||0)+1);return new Set(Array.from(n.entries()).filter(([,r])=>r>1).map(([r])=>r))}function ge(e){const n=(e.aggregate||"SUM").toUpperCase();return P([`${n.toLowerCase()}_${e.name}`,`${n}_${e.name}`,`${e.name}_${n.toLowerCase()}`,`${e.name}_${n}`,e.name])}function Ze(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 Xe(e,n){const r=I(n.spec);if(!r)return;const o=q(n.builder);if(o==="records"){for(const t of H(r.fields))g(e,t);return}if(o==="sql"){for(const t of H(r.fields))g(e,t);return}if(o==="analysis"||o==="metric"){g(e,r.primaryMeasure);for(const t of H(r.measures))g(e,t);for(const t of H(r.dimensions))g(e,t);g(e,r.dateField);return}if(o==="matrix"){const t=ce(r.rows),a=ce(r.columns),p=H(r.values);for(const f of t)me(e,f);for(const f of a)me(e,f);for(const f of p){const h=I(f);g(e,h==null?void 0:h.field),g(e,h==null?void 0:h.measure)}}}function ce(e){if(Array.isArray(e))return e;const n=I(e);return Array.isArray(n==null?void 0:n.levels)?n.levels:[]}function me(e,n){var r;if(M(n)){g(e,n);return}g(e,(r=I(n))==null?void 0:r.field)}function fe(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 en(e){const n=I(e)||{};return v({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 g(e,n){M(n)&&e.push(D(n))}function D(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 nn(e){if(!e.source)return;const n={...e.source,...e.sourceKey?{sourceKey:e.sourceKey}:{}},r=we(n);if(r)return{raw:n,key:r,aliases:Ie(n),name:""}}function M(e){const n=I(e);return!!(n&&typeof n.name=="string"&&(typeof n.role=="string"||typeof n.dataType=="string"||typeof n.aggregate=="string"||n.source||n.sourceKey))}function he(e){const n=I(e);return!!(n&&(typeof n.sourceKey=="string"||n.kind==="semantic"||typeof n.datasetName=="string"&&typeof n.domainId=="string"))}function E(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=>E(t,n)).join(", ")}]`;if(M(e)){const t=C(D(e),n);if(t)return`fields.${t}`}if(he(e)){const t=Se(e,n);if(t)return`sources.${t}`}const r=I(e);return r?`{ ${Object.entries(r).filter(([,t])=>t!==void 0).map(([t,a])=>`${JSON.stringify(t)}: ${E(a,n)}`).join(", ")} }`:JSON.stringify(e)}function k(e){return JSON.stringify(e,null,2)}function C(e,n){if(M(e))return n.fieldNameByKey.get(U(D(e)))}function Se(e,n){if(he(e))for(const r of ee(e)){const o=n.sourceNameByKey.get(r);if(o)return o}}function U(e){return[e.sourceKey||"",e.name||"",e.role||"",e.aggregate||""].join("|")}function rn(e,n){return!M(e)||!M(n)||e.name!==n.name?!1:de(e).some(r=>de(n).includes(r))}function tn(e){return M(e)&&e.role==="id"}function on(e){const n=[],r=new Map;for(const o of e){const t=P(o.aliases.length?o.aliases:[o.key]),a=t.map(p=>r.get(p)).find(x);if(a){a.aliases=P([...a.aliases,...t]);continue}o.aliases=t,n.push(o);for(const p of t)r.set(p,o)}return n}function sn(e){const n=new Map;for(const r of e)for(const o of P([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 P(e){return Array.from(new Set(e.filter(Boolean)))}function we(e){return ee(e)[0]||pe(e)}function ee(e){const n=I(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)),P(r)}function Ie(e){return ee(e)}function pe(e){const n=I(e);return n?typeof n.sourceKey=="string"?n.sourceKey:JSON.stringify(n):""}function an(e){return M(e)&&de(e)[0]||""}function de(e){return M(e)?P([...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 un(e){const n=q(e);return n==="records"||n==="sql"}function dn(e){const n=I(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 K(e,n){const r=new Map;for(const o of e){const t=n(o)||"item",a=r.get(t)||0;r.set(t,a+1),o.name=a===0?t:`${t}${a+1}`}}function ne(e,n){const r=new Set,o=[];for(const t of e){const a=n(t);!a||r.has(a)||(r.add(a),o.push(t))}return o}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,...o]=n,t=[r.toLowerCase(),...o.map(a=>a.charAt(0).toUpperCase()+a.slice(1).toLowerCase())].join("");return/^[A-Za-z_$]/.test(t)?t:`item${t}`}function ln(e){const n=String(e).split(":");return n[n.length-1]||String(e)}function v(e){return Object.fromEntries(Object.entries(e).filter(([,n])=>n!==void 0))}function I(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function H(e){return Array.isArray(e)?e:[]}function z(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=$.CODEGEN_SUMMARY_SCHEMA_VERSION;exports.CODEGEN_SUMMARY_VALIDATOR_VERSION=$.CODEGEN_SUMMARY_VALIDATOR_VERSION;exports.CONTRACT_MANIFEST_SCHEMA_VERSION=$.CONTRACT_MANIFEST_SCHEMA_VERSION;exports.GENERATED_CONTRACT_SCHEMA_VERSION=$.GENERATED_CONTRACT_SCHEMA_VERSION;exports.GENERATED_CONTRACT_TYPESCRIPT_FILES=$.GENERATED_CONTRACT_TYPESCRIPT_FILES;exports.REQUIRED_GENERATED_CONTRACT_FILES=$.REQUIRED_GENERATED_CONTRACT_FILES;exports.assertValidCodegenSummary=$.assertValidCodegenSummary;exports.buildSemaphorGeneratedActiveInput=$.buildSemaphorGeneratedActiveInput;exports.buildSemaphorGeneratedInputOptionIntent=$.buildSemaphorGeneratedInputOptionIntent;exports.buildSemaphorGeneratedViewExecutionRequest=$.buildSemaphorGeneratedViewExecutionRequest;exports.buildSemaphorGeneratedViewExecutionRequests=$.buildSemaphorGeneratedViewExecutionRequests;exports.evaluateSemaphorDataAppContractUpdatePolicy=$.evaluateSemaphorDataAppContractUpdatePolicy;exports.validateCodegenSummary=$.validateCodegenSummary;exports.validateSemaphorGeneratedContract=$.validateSemaphorGeneratedContract;exports.DEFAULT_GENERATED_CONTRACT_OUTPUT_DIR=Ve;exports.generateSemaphorDataAppContract=be;
|