react-semaphor 0.1.325 → 0.1.327
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 +260 -226
- package/dist/brand-studio/index.cjs +2 -2
- package/dist/brand-studio/index.js +7 -6
- package/dist/chunks/{braces-ZjRH2Kl7.js → braces-B6qRDu1H.js} +1 -1
- package/dist/chunks/{braces-C7BeIXvM.js → braces-BGWZEnQJ.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-DHhT6Sja.js → calendar-preferences-dialog-CjwbE_82.js} +6 -5
- package/dist/chunks/calendar-preferences-dialog-fkLUMJyR.js +1 -0
- package/dist/chunks/{chevrons-up-down-CA-XvN1o.js → chevrons-up-down-BpsogQvv.js} +1 -1
- package/dist/chunks/{chevrons-up-down-Cuilz9aY.js → chevrons-up-down-xG-bVFD9.js} +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-DZiFMK8I.js → dashboard-briefing-launcher-Co57xBfS.js} +2 -2
- package/dist/chunks/{dashboard-briefing-launcher-BzIxRlzW.js → dashboard-briefing-launcher-Cy1nWZRW.js} +714 -719
- package/dist/chunks/{dashboard-controls-DVwsWny9.js → dashboard-controls-BWnVEFJq.js} +10 -9
- package/dist/chunks/{dashboard-controls-BX693lE0.js → dashboard-controls-C7rOGZO-.js} +1 -1
- package/dist/chunks/{dashboard-json-D15C_I9e.js → dashboard-json-BpRNSsF3.js} +7 -6
- package/dist/chunks/dashboard-json-DBPMknGo.js +1 -0
- package/dist/chunks/date-formatter-B4EBSe9C.js +1 -0
- package/dist/chunks/date-formatter-CzcPZx39.js +416 -0
- package/dist/chunks/edit-dashboard-visual-B2vkIKEa.js +178 -0
- package/dist/chunks/{edit-dashboard-visual-wQyJEcVH.js → edit-dashboard-visual-CYf26co_.js} +8243 -7784
- package/dist/chunks/index-BD90s-wf.js +1309 -0
- package/dist/chunks/index-BxM99sFL.js +1 -0
- package/dist/chunks/index-CuHybtft.js +51 -0
- package/dist/chunks/{index-CffvIaZO.js → index-DTlbYpxd.js} +29440 -28968
- package/dist/chunks/{palette-D96DOM7E.js → palette-CSF7IVJn.js} +1 -1
- package/dist/chunks/{palette-CanPG11m.js → palette-CWgEPBoG.js} +1 -1
- package/dist/chunks/{resource-management-panel-DlnrD0y-.js → resource-management-panel-D6nbfJY3.js} +1 -1
- package/dist/chunks/{resource-management-panel-CLoO2DL3.js → resource-management-panel-D893Onv8.js} +6 -5
- package/dist/chunks/{save-CqrBQKG6.js → save-CtQbSub2.js} +1 -1
- package/dist/chunks/{save-DxkSzUTZ.js → save-DRdFKF57.js} +1 -1
- package/dist/chunks/switch-DJJJD_g1.js +168 -0
- package/dist/chunks/{switch-Deo2Ltmj.js → switch-DKf6vHfP.js} +2222 -2228
- package/dist/chunks/{use-create-flow-overlay-state-DocFanjO.js → use-create-flow-overlay-state-C4LgoK8q.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-DsPoCfMu.js → use-create-flow-overlay-state-p21zs2p6.js} +29 -28
- package/dist/chunks/{use-visual-utils-BdO22fQZ.js → use-visual-utils-BKBua6o4.js} +2 -2
- package/dist/chunks/{use-visual-utils-DSbXQQD1.js → use-visual-utils-BqWm0QeW.js} +1 -1
- package/dist/chunks/validators-DDAweCzB.js +371 -0
- package/dist/chunks/validators-odlRJblR.js +2 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.cjs +3 -3
- package/dist/dashboard-authoring/index.js +919 -507
- package/dist/data-app-sdk/index.cjs +1 -0
- package/dist/data-app-sdk/index.js +512 -0
- package/dist/format-utils/index.cjs +4 -4
- package/dist/format-utils/index.js +22 -21
- package/dist/index.cjs +1 -1
- package/dist/index.js +141 -140
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/analytics-protocol.d.ts +326 -2
- package/dist/types/dashboard-authoring.d.ts +102 -3
- package/dist/types/dashboard.d.ts +23 -3
- package/dist/types/data-app-sdk.d.ts +379 -0
- package/dist/types/format-utils.d.ts +25 -0
- package/dist/types/main.d.ts +182 -12
- package/dist/types/shared.d.ts +18 -2
- package/dist/types/surfboard.d.ts +23 -3
- package/dist/types/types.d.ts +38 -4
- package/package.json +6 -1
- package/dist/chunks/calendar-preferences-dialog-BxeROxyq.js +0 -1
- package/dist/chunks/dashboard-json-DxNEFM-p.js +0 -1
- package/dist/chunks/date-formatter-D9Bvw5Qk.js +0 -1
- package/dist/chunks/date-formatter-DyIOb6uC.js +0 -333
- package/dist/chunks/edit-dashboard-visual-90_qEgRc.js +0 -178
- package/dist/chunks/index-YTk9Hab2.js +0 -1303
- package/dist/chunks/switch-BXICAlvS.js +0 -168
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("../analytics-protocol/index.cjs"),H=["lg","md","sm","xs","xxs"],S=10;function f(e,t,a){return a?{code:e,message:t,cardId:a}:{code:e,message:t}}function $(e){const t=new Set;for(const a of e){if(t.has(a))return a;t.add(a)}return null}function W(e){var _,x;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[f("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const a=e,n=[...a.warnings||[]];a.version!==1&&t.push(f("invalid_version","Dashboard plan version must be 1.")),(_=a.title)!=null&&_.trim()||t.push(f("missing_title","Dashboard plan needs a title."));const i=Array.isArray(a.datasets)?a.datasets:[],r=Array.isArray(a.sheets)?a.sheets:[];i.length!==1&&t.push(f("invalid_dataset_count","MVP dashboard authoring requires exactly one selected dataset.")),r.length!==1&&t.push(f("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const d=r[0];d&&d.kind!=="dashboard"&&t.push(f("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const l=(d==null?void 0:d.cards)||[];l.length>S&&t.push(f("too_many_cards",`Generated dashboards can contain at most ${S} cards.`));const s=$(l.map(u=>u.id));s&&t.push(f("duplicate_card_id",`Duplicate generated card id: ${s}.`));const c=$(l.map(u=>u.frameId));c&&t.push(f("duplicate_frame_id",`Duplicate generated frame id: ${c}.`));for(const u of l)(x=u.title)!=null&&x.trim()||t.push(f("missing_card_title","Card title is required.",u.id)),u.type==="custom"&&t.push(f("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",u.id)),u.type!=="text"&&!u.query&&n.push(f("missing_query_intent","Non-text card has no query intent and may be skipped by the app layer.",u.id));const h=Array.isArray(a.filterInputs)?a.filterInputs:[],y=h.map(u=>u.id),g=$(y);g&&t.push(f("duplicate_input_id",`Duplicate dashboard input id: ${g}.`));const o=h.map(u=>u.variableName).filter(Boolean)||[],b=$(o);b&&t.push(f("duplicate_input_variable",`Duplicate dashboard input variable name: ${b}.`));const k=Array.isArray(a.calculatedFields)?a.calculatedFields:[];for(const u of k)u.scope==="domain"&&u.reuseOnly!==!0&&t.push(f("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${u.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:n}}function G(e){var d;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[f("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const a=e,n=[...a.warnings||[]];a.version!==1&&t.push(f("invalid_version","Dashboard change plan version must be 1.")),(d=a.dashboardId)!=null&&d.trim()||t.push(f("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const i=Array.isArray(a.datasets)?a.datasets:[],r=Array.isArray(a.operations)?a.operations:[];i.length>1&&t.push(f("invalid_dataset_count","MVP dashboard refinement can ground new AI operations in at most one selected dataset."));for(const l of r){if(l.kind==="unsupported"){n.push(f("unsupported_operation",l.reason||l.requestedAction));continue}l.kind==="addCard"&&l.card.type==="custom"&&t.push(f("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",l.card.id)),l.kind==="addCalculatedField"&&l.field.scope==="domain"&&l.field.reuseOnly!==!0&&t.push(f("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${l.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:n}}const ae={lg:48,md:36,sm:24,xs:12,xxs:6};function ne(e,t){let a=0,n=0,i=0;return e.map(r=>{const d=Math.min(r.w,t);a>0&&a+d>t&&(a=0,n+=i,i=0);const l={i:r.frameId,x:a,y:n,w:d,h:r.h,minW:Math.min(r.minW,t),minH:r.minH,static:!1};return a+=d,i=Math.max(i,r.h),l})}function re(e){const t=[...e].sort((s,c)=>s.priority-c.priority),a=t.filter(s=>s.role==="kpi"),n=t.filter(s=>s.role==="chart"),i=t.filter(s=>s.role==="table"),r=t.filter(s=>s.role==="text"),d=r.slice(0,1),l=r.slice(d.length);return{kpis:a,introText:d,charts:n,tables:i,supportingText:l}}function ie(e,t,a){return t==="xxs"||t==="xs"?a:t==="sm"?Math.min(12,a):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function se(e,t,a,n){return a==="xxs"||a==="xs"||a==="sm"||a==="md"||t===1||t%2===1&&e===0?n:n/2}function de(e){const{item:t,band:a,index:n,bandCount:i,breakpoint:r,columns:d}=e;return a==="kpi"?{...t,band:a,w:ie(i,r,d),h:15,minW:Math.min(6,d),minH:12}:a==="table"?{...t,band:a,w:d,h:r==="xxs"||r==="xs"?34:38,minW:Math.min(12,d),minH:18}:a==="introText"?{...t,band:a,w:d,h:r==="xxs"||r==="xs"?12:10,minW:Math.min(12,d),minH:8}:a==="supportingText"?{...t,band:a,w:r==="lg"?d/2:d,h:r==="xxs"||r==="xs"?12:10,minW:Math.min(12,d),minH:8}:{...t,band:a,w:se(n,i,r,d),h:r==="xxs"||r==="xs"?28:30,minW:Math.min(12,d),minH:16}}function F(e,t,a,n){return e.map((i,r)=>de({item:i,band:t,index:r,bandCount:e.length,breakpoint:a,columns:n}))}function N(e){const t=re(e);return Object.fromEntries(H.map(a=>{const n=ae[a],i=[...F(t.introText,"introText",a,n),...F(t.kpis,"kpi",a,n),...F(t.charts,"chart",a,n),...F(t.tables,"table",a,n),...F(t.supportingText,"supportingText",a,n)];return[a,ne(i,n)]}))}function oe(e){const t=String(e||"").trim().toLowerCase();return t.includes("date")||t.includes("time")||t.includes("timestamp")?"date":t.includes("int")||t.includes("float")||t.includes("double")||t.includes("decimal")||t.includes("numeric")||t.includes("number")||t.includes("currency")||t.includes("percent")?"number":t.includes("bool")?"boolean":"string"}function le(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function ce(e){return le(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function ue(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function fe(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function q(e,t){if(t===void 0)return;const a=oe(e.dataType),n=e.operation||"in";if(ce(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:a,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(n==="is null"||n==="is not null")return{filterId:e.id,name:e.column,operation:n,valueType:a,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const i=Array.isArray(t)?t:[t],r=a==="date"?fe(i):ue(i);if(r.length!==0&&!((n==="between"||n==="not between")&&r.length<2))return{filterId:e.id,name:e.column,operation:n,valueType:a,values:r,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function pe(e,t,a){return a?{code:e,message:t,cardId:a}:{code:e,message:t}}function he(e,t,a){const n=(t||[]).filter(i=>i.scope==="card"&&i.targetCardId===a).map(i=>i.field).filter(Boolean);return n.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...n]}}function me(e){const t={};return{inputs:(e.filterInputs||[]).map((n,i)=>{const r=q(n.filter,n.defaultValue);return r&&(t.shared??(t.shared={}),t.shared[n.id]={status:"set",value:{kind:"filter",filterValue:r}}),{id:n.id,kind:"filter",label:n.label,variableName:n.variableName,scope:n.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:i},exports:["label","value","start","end","range"],filter:n.filter}}),defaultInputValues:t.shared&&Object.keys(t.shared).length>0?t:void 0}}function be(e){var y,g;const t=W(e.plan);if(!t.ok)throw new Error(t.errors.map(o=>o.message).join(`
|
|
2
|
-
`)||"Dashboard plan is invalid.");const
|
|
3
|
-
`)||"Dashboard change plan is invalid.");const a=ge(e.dashboard),n=[...t.warnings],i=[],r=new Map(e.cardArtifacts.map(s=>[s.planCardId,s])),d=Ie(a);if(!d)throw new Error("Dashboard has no editable dashboard sheet.");d.frames??(d.frames=[]);for(const s of e.changePlan.operations)switch(s.kind){case"addCard":{if((d.frames||[]).reduce((g,o)=>{var b;return g+(((b=o.cards)==null?void 0:b.length)||0)},0)>=S){i.push(v("generated_card_limit_reached",`MVP AI refinement is capped at ${S} cards.`,s.card.id));break}const h=r.get(s.card.id);if(!h){i.push(v("missing_card_artifact",`Card "${s.card.title}" was skipped because no generated artifact was supplied.`,s.card.id));break}const y={id:s.card.frameId,cards:[h.card],activeCardId:h.card.id};d.frames.push(y),we(d,y);break}case"addFilterInput":{a.inputs??(a.inputs=[]);const c={id:s.input.id,kind:"filter",label:s.input.label,variableName:s.input.variableName,scope:s.input.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:a.inputs.length},exports:["label","value","start","end","range"],filter:s.input.filter};a.inputs.push(c),ve(a,s.input);break}case"addCalculatedField":{if(s.field.scope==="dashboard"&&s.field.field)a.calculatedFields??(a.calculatedFields=[]),a.calculatedFields.push(s.field.field);else if(s.field.scope==="sheet"&&s.field.field)d.calculatedFields??(d.calculatedFields=[]),d.calculatedFields.push(s.field.field);else if(s.field.scope==="card"&&s.field.field){const c=s.field.targetCardId?P(a,s.field.targetCardId):null;c?((l=c.card).calculatedFields??(l.calculatedFields=[]),c.card.calculatedFields.push(s.field.field)):i.push(v("missing_calculated_field_target",`Calculated field "${s.field.name}" needs a valid target card.`))}break}case"renameCard":{const c=P(a,s.cardId);if(!c){i.push(v("card_not_found",`Card "${s.cardId}" could not be renamed because it was not found.`,s.cardId));break}c.card.title=s.title,s.description!==void 0&&(c.card.description=s.description);break}case"reorderCards":{const c=new Map;for(let h=0;h<s.cardIds.length;h+=1){const y=s.cardIds[h],g=P(a,y);g&&c.set(g.frame.id,h)}U(d,c);break}case"reuseCalculatedField":n.push(v("reused_calculated_field",`Calculated field "${s.fieldId}" is reused by reference.`));break;case"unsupported":i.push(v("unsupported_operation",s.reason||s.requestedAction));break}return{dashboard:a,warnings:n,skippedOperations:i}}function I(e,t,a){return a?{code:e,message:t,cardId:a}:{code:e,message:t}}function D(e,t){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||t}function X(e,t){if(!t.has(e))return t.add(e),e;let a=2,n=`${e}-${a}`;for(;t.has(n);)a+=1,n=`${e}-${a}`;return t.add(n),n}function ke(e){return e.kind==="semantic"?["semantic",e.domainId,e.datasetId||"",e.datasetName,e.connectionId||""].join(":"):e.kind==="physical"?["physical",e.connectionId,e.databaseName||"",e.schemaName||"",e.tableName].join(":"):["sql",e.connectionId,e.sql].join(":")}function C(e){return!!(e&&typeof e=="object")}function E(e){return C(e)&&(e.kind==="semantic"||e.kind==="physical"||e.kind==="sql")}function J(e){return Array.isArray(e.inputs)?e.inputs.filter(t=>C(t)&&typeof t.id=="string"):[]}function Y(e){return Array.isArray(e.sections)?e.sections.filter(t=>C(t)):[]}function Q(e){return Array.isArray(e.views)?e.views.filter(t=>C(t)):[]}function xe(e){return e.kind==="semantic"?{kind:"semantic",domainId:e.domainId,datasetName:e.datasetName,datasetId:e.datasetId,label:e.label,connectionId:e.connectionId}:e.kind==="physical"?{kind:"physical",connectionId:e.connectionId,databaseName:e.databaseName,schemaName:e.schemaName,tableName:e.tableName,label:e.label}:null}function Ae(e){return(e==null?void 0:e.source)||null}function Z(e){const t=[];for(const a of J(e))E(a.source)&&t.push(a.source);for(const a of Y(e))for(const n of Q(a)){const i=Ae(n.analytics);E(i)&&t.push(i)}return t}function Fe(e,t){const a=new Map;for(const i of Z(e))a.set(ke(i),i);const n=[...a.values()].map(xe).filter(i=>!!i);return n.length===0?(t.push(I("missing_materializable_dataset","No semantic or physical source could be converted into the current dashboard authoring dataset reference.")),[]):(n.length>1&&t.push(I("multiple_datasets_out_of_scope","The current dashboard authoring compiler supports one selected dataset; using the first source and deferring the rest.")),[n[0]])}function De(e){return(Array.isArray(e.fields)?e.fields:[]).map(t=>t.name).filter(t=>{var a;return t!==((a=e.dateField)==null?void 0:a.name)})}function Se(e){var t,a;if(e){if(e.kind==="metric")return{metric:e.metric,dateField:(t=e.dateField)==null?void 0:t.name};if(e.kind==="records")return{metrics:e.measures,dateField:(a=e.dateField)==null?void 0:a.name,timeGrain:e.timeGrain==="hour"?"day":e.timeGrain,dimensions:De(e),limit:e.limit}}}function Te(e){var t;switch((t=e.presentation)==null?void 0:t.kind){case"kpi":return"kpi";case"lineChart":return"line";case"barChart":return"bar";case"areaChart":return"area";case"table":return"table";case"text":return"text";default:return null}}function $e(e){var t,a,n;return((t=e.presentation)==null?void 0:t.kind)==="kpi"?"kpi":((a=e.presentation)==null?void 0:a.kind)==="table"?"table":((n=e.presentation)==null?void 0:n.kind)==="text"?"text":"chart"}function Ne(e){switch(e){case"not_in":return"not in";case"contains":return"like";default:return e||"in"}}function Me(e){return C(e.field)?e.field.dataType==="datetime"?"date":e.field.dataType||"string":"string"}function Pe(e){if(!(!e||e.kind!=="physical"))return[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")}function Ve(e,t,a,n,i){if(e.kind!=="filter")return i.push(I("control_inputs_deferred",`Control input "${e.label}" is represented in the protocol but not yet materialized by the dashboard authoring adapter.`)),null;if(!C(e.field)||typeof e.field.name!="string")return i.push(I("filter_requires_field",`Filter "${e.label||e.id}" needs a field before the dashboard compiler can materialize it.`)),null;const r=e.source||t,d=(r==null?void 0:r.kind)==="semantic"||(r==null?void 0:r.kind)==="physical"||(r==null?void 0:r.kind)==="sql"?r.connectionId:void 0;if(!d)return i.push(I("filter_requires_connection_id",`Filter "${e.label}" needs a source connectionId before the dashboard compiler can materialize it.`)),null;const c={id:`filter-${X(D(e.id,e.field.name),n)}`,variableName:e.id,connectionId:d,title:e.label,column:e.field.name,dataType:Me(e),qualifiedTableName:Pe(r),sql:"",operation:Ne(e.operator),type:e.multi===!1?"single":"multiple",location:"dashboard",displayMode:"toolbar",fieldMeta:(r==null?void 0:r.kind)==="semantic"?{name:e.field.name,qualifiedFieldName:e.field.name,dataType:e.field.dataType,role:e.field.role==="measure"?"metric":"groupby"}:void 0,semanticContext:(r==null?void 0:r.kind)==="semantic"?{semanticDomainId:r.domainId,connectionId:r.connectionId}:void 0};return{id:e.id,label:e.label,variableName:e.id,scope:a,filter:c,defaultValue:q(c,e.defaultValue)}}function V(e){const t=[],a=[];for(const n of e.viewIds){const i=e.viewIdToCardId.get(n);i?t.push(i):a.push(n)}return a.length>0&&e.warnings.push(I("input_scope_view_not_found",`Filter "${e.inputLabel}" referenced unknown view ids: ${a.join(", ")}.`)),Array.from(new Set(t))}function qe(e){var n,i;if(!e.protocolScope){const r=Array.from(new Set(e.boundCardIds));return r.length>0&&r.length<e.allCardIds.length?{kind:"cards",cardIds:r}:void 0}if(e.protocolScope.level==="dashboard"){if(!((n=e.protocolScope.excludeViewIds)!=null&&n.length))return;const r=new Set(V({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:e.allCardIds.filter(d=>!r.has(d))}}if(e.protocolScope.level==="view"){const r=V({inputLabel:e.inputLabel,viewIds:e.protocolScope.viewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings});return r.length===0?(e.warnings.push(I("input_scope_has_no_materialized_cards",`Filter "${e.inputLabel}" was deferred because its view scope does not match any materialized cards.`)),null):{kind:"cards",cardIds:r}}const t=e.sectionIdToCardIds.get(e.protocolScope.sectionId)||[];if(t.length===0)return e.warnings.push(I("input_scope_section_not_found",`Filter "${e.inputLabel}" was deferred because section "${e.protocolScope.sectionId}" does not match any materialized cards.`)),null;if(!((i=e.protocolScope.excludeViewIds)!=null&&i.length))return{kind:"cards",cardIds:t};const a=new Set(V({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:t.filter(r=>!a.has(r))}}function Re(e){var _,x,u;const t=[],a=te.validateSemaphorDashboardIntent(e);for(const p of a.warnings)t.push(I(p.code,p.message));for(const p of a.errors)t.push(I(p.code,p.message));const n=Y(e),i=J(e),r=Fe(e,t),d=Z(e)[0],l=[],s=new Map,c=new Map,h=new Map,y=new Set,g=new Set;let o=0;for(const[p,w]of n.entries()){const A=typeof w.title=="string"?w.title:`Section ${p+1}`,R=w.id||D(A,`section-${p+1}`);c.set(R,[]);for(const[B,m]of Q(w).entries()){const O=Te(m),M=D(m.id||`${A}-${m.title||`View ${B+1}`}`,`card-${p+1}-${B+1}`);if(!O){t.push(I("unsupported_presentation",`Dashboard presentation "${((_=m.presentation)==null?void 0:_.kind)||"unknown"}" is not supported by the dashboard authoring adapter.`,`card-${M}`));continue}if(((x=m.analytics)==null?void 0:x.kind)==="sql"){t.push(I("sql_intent_deferred","SQL analytics intent is valid protocol, but the current dashboard authoring adapter only materializes semantic and physical config-card intents.",`card-${M}`));continue}const L=X(M,y),T=`card-${L}`;m.id&&s.set(m.id,T),(u=c.get(R))==null||u.push(T);const ee=m.analytics&&"inputs"in m.analytics?m.analytics.inputs:void 0;for(const z of ee||[]){const j=h.get(z.inputId)||[];j.push(T),h.set(z.inputId,j)}l.push({id:T,frameId:`frame-${L}`,title:m.title,description:m.description,type:O,role:$e(m),priority:o,section:A,query:Se(m.analytics),text:m.text}),o+=1}}const b=i.map(p=>{const w=qe({protocolScope:p.scope,inputLabel:p.label,allCardIds:l.map(A=>A.id),boundCardIds:h.get(p.id)||[],viewIdToCardId:s,sectionIdToCardIds:c,warnings:t});return w===null?null:Ve(p,d,w,g,t)}).filter(p=>!!p);return{plan:{version:1,id:`plan-${D(e.title,"dashboard")}`,title:e.title,description:e.description,datasets:r,sheets:[{id:`sheet-${D(e.title,"dashboard")}`,title:e.title,description:e.description,kind:"dashboard",cards:l}],filterInputs:b.length?b:void 0,warnings:t.length?t:void 0,unresolvedRequests:a.ok?void 0:a.errors.map(p=>p.message)},warnings:t}}exports.DASHBOARD_AUTHORING_BREAKPOINTS=H;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=S;exports.applyDashboardChangePlan=Ce;exports.compileDashboardFromPlan=be;exports.compileResponsiveDashboardLayouts=N;exports.dashboardPlanFromSemaphorDashboardIntent=Re;exports.validateDashboardChangePlan=G;exports.validateDashboardPlan=W;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ie=require("../chunks/validators-odlRJblR.js"),oe=["lg","md","sm","xs","xxs"],T=10;function _(e){return e&&typeof e=="object"?e:null}function S(e){return typeof e=="string"?e:null}function se(e){var t,n,a;return!!(e&&typeof e=="object")&&(((t=_(e))==null?void 0:t.kind)==="semantic"||((n=_(e))==null?void 0:n.kind)==="physical"||((a=_(e))==null?void 0:a.kind)==="sql")}function C(e){return se(e)?e.kind==="semantic"?!!(e.domainId&&e.datasetName):e.kind==="physical"?!!(e.connectionId&&e.tableName):!1:!1}function L(e){return e.kind==="semantic"?["semantic",e.domainId,e.datasetId||"",e.datasetName].join(":"):e.kind==="physical"?["physical",e.connectionId,e.databaseName||"",e.schemaName||"",e.tableName].join(":"):["sql",e.connectionId,e.sql].join(":")}function G(e,t){return e.domainId!==t.domainId?!1:e.datasetId&&t.datasetId?e.datasetId===t.datasetId:e.datasetName===t.datasetName}function W(e,t){return e.kind==="semantic"&&t.kind==="semantic"?G(e,t):L(e)===L(t)}function de(e,t){return e.kind!=="semantic"||t.kind!=="semantic"?e:{...e,datasetId:e.datasetId||t.datasetId,label:e.label||t.label,connectionId:e.connectionId||t.connectionId}}function R(e){const t=[];for(const n of e){const a=t.findIndex(i=>W(i,n));a===-1?t.push(n):t[a]=de(t[a],n)}return t}function ke(e){return R(e)[0]}function j(e,t){return e.kind!=="semantic"||e.connectionId||(t==null?void 0:t.kind)!=="semantic"||!G(e,t)||!t.connectionId?e:{...e,connectionId:t.connectionId}}function E(e){return C(e)?e:void 0}function ne(e,t){if(!(e.kind!=="semantic"||e.connectionId))return t.find(n=>(n==null?void 0:n.kind)==="semantic"&&G(e,n)&&!!n.connectionId)}function w(e,t){const n=E(e==null?void 0:e.source);return n?j(n,t):void 0}function ce({explicitSource:e,field:t,defaultSource:n,fallbackSources:a}){const i=[n,...a||[]],r=E(e),o=r?j(r,ne(r,i)):void 0;if(o)return o;if(e!==void 0)return;const d=w(t,n),s=d?j(d,ne(d,i)):void 0;if(s)return s;if((t==null?void 0:t.source)===void 0)return E(n)}function ue(e,t){if(!(e!=null&&e.name)||!(t!=null&&t.name)||e.name!==t.name)return!1;const n=w(e),a=w(t);return!n||!a?!0:W(n,a)}function D(e){var t;return S((t=_(e))==null?void 0:t.kind)}function le(e){var t,n;return D(e)!=="semantic"?null:((n=S((t=_(e))==null?void 0:t.domainId))==null?void 0:n.trim())||null}function Ce(e){var t;return D(e)!=="semantic"?null:S((t=_(e))==null?void 0:t.datasetName)}function Fe(e){var t;return D(e)!=="semantic"?null:S((t=_(e))==null?void 0:t.datasetId)}function xe(e){var t;return D(e)!=="physical"?null:S((t=_(e))==null?void 0:t.connectionId)}function Ne(e){var t;return D(e)!=="physical"?null:S((t=_(e))==null?void 0:t.tableName)}function Te(e){var t;return D(e)!=="physical"?"":S((t=_(e))==null?void 0:t.databaseName)||""}function Re(e){var t;return D(e)!=="physical"?"":S((t=_(e))==null?void 0:t.schemaName)||""}function fe(e){if(e.analyticsIntent&&typeof e.analyticsIntent=="object"&&"source"in e.analyticsIntent)return e.analyticsIntent.source}function me({datasets:e,requireAtLeastOne:t}){if(t&&e.length<1)return{ok:!1,issue:"invalid_dataset_count"};if(e.length<=1)return{ok:!0};const n=e.map(le),a=new Set(n.filter(Boolean));return n.some(i=>!i)||a.size!==1?{ok:!1,issue:"invalid_multi_dataset_scope"}:{ok:!0}}function P(e,t){if(!t)return!1;if(t.kind==="semantic"){const n=Fe(e);return le(e)===t.domainId?n&&t.datasetId?n===t.datasetId:Ce(e)===t.datasetName:!1}return t.kind==="physical"?xe(e)===t.connectionId&&Ne(e)===t.tableName&&Te(e)===(t.databaseName||"")&&Re(e)===(t.schemaName||""):!1}function $e(e,t){return e.find(n=>P(n,t))}function l(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function M(e){const t=new Set;for(const n of e){if(t.has(n))return n;t.add(n)}return null}function pe({card:e,datasets:t,errors:n}){if(e.type==="text")return;const a=fe(e);if(!a){if(t.length<=1)return;n.push(l("missing_card_analytics_source","Multi-dataset dashboard cards must include analytics intent with a source so the materializer can choose the correct dataset.",e.id));return}t.some(i=>P(i,a))||n.push(l("invalid_card_analytics_source","Dashboard cards with an explicit analytics source must use one of the selected datasets.",e.id))}function Me(e){var t;return e?[(t=e.dateFieldRef)==null?void 0:t.source,...Array.isArray(e.dimensionRefs)?e.dimensionRefs.map(n=>n.source):[]].filter(n=>!!n):[]}function he({card:e,datasets:t,errors:n}){if(e.type!=="text"){for(const a of Me(e.query))if(a&&!t.some(i=>P(i,a))){n.push(l("invalid_card_query_source","Dashboard card query field references must use one of the selected datasets.",e.id));return}}}function Pe(e,t){return e.length===t.length&&e.every((n,a)=>n===t[a])}function be({card:e,errors:t}){if(e.type==="text"||!e.query)return;const{dateField:n,dateFieldRef:a,dimensions:i,dimensionRefs:r}=e.query;if(a&&a.name!==n){t.push(l("invalid_card_query_ref","Dashboard card source-aware date field reference must match the query date field.",e.id));return}if(!Array.isArray(r))return;const o=Array.isArray(i)?i:[],d=r.map(s=>s.name);Pe(d,o)||t.push(l("invalid_card_query_ref","Dashboard card source-aware dimension references must match the query dimensions.",e.id))}function ge({datasets:e,errors:t,requireAtLeastOne:n}){const a=me({datasets:e,requireAtLeastOne:n});if(!a.ok){if(a.issue==="invalid_dataset_count"){t.push(l("invalid_dataset_count","Dashboard authoring requires at least one selected dataset."));return}t.push(l("invalid_multi_dataset_scope","Multi-dataset dashboard authoring is limited to semantic datasets from one domain."))}}function Ie(e){var m,v;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[l("invalid_plan","Dashboard plan must be a structured object.")],warnings:[]};const n=e,a=[...n.warnings||[]];n.version!==1&&t.push(l("invalid_version","Dashboard plan version must be 1.")),(m=n.title)!=null&&m.trim()||t.push(l("missing_title","Dashboard plan needs a title."));const i=Array.isArray(n.datasets)?n.datasets:[],r=Array.isArray(n.sheets)?n.sheets:[];ge({datasets:i,errors:t,requireAtLeastOne:!0}),r.length!==1&&t.push(l("invalid_sheet_count","MVP dashboard authoring creates exactly one dashboard sheet."));const o=r[0];o&&o.kind!=="dashboard"&&t.push(l("invalid_sheet_kind",'Generated sheet must use kind "dashboard".'));const d=(o==null?void 0:o.cards)||[];d.length>T&&t.push(l("too_many_cards",`Generated dashboards can contain at most ${T} cards.`));const s=M(d.map(u=>u.id));s&&t.push(l("duplicate_card_id",`Duplicate generated card id: ${s}.`));const f=M(d.map(u=>u.frameId));f&&t.push(l("duplicate_frame_id",`Duplicate generated frame id: ${f}.`));for(const u of d)(v=u.title)!=null&&v.trim()||t.push(l("missing_card_title","Card title is required.",u.id)),u.type==="custom"&&t.push(l("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",u.id)),u.type!=="text"&&!u.query&&a.push(l("missing_query_intent","Non-text card has no query intent and may be skipped by the app layer.",u.id)),pe({card:u,datasets:i,errors:t}),be({card:u,errors:t}),he({card:u,datasets:i,errors:t});const p=Array.isArray(n.filterInputs)?n.filterInputs:[],g=p.map(u=>u.id),y=M(g);y&&t.push(l("duplicate_input_id",`Duplicate dashboard input id: ${y}.`));const c=p.map(u=>u.variableName).filter(Boolean)||[],b=M(c);b&&t.push(l("duplicate_input_variable",`Duplicate dashboard input variable name: ${b}.`));const A=Array.isArray(n.calculatedFields)?n.calculatedFields:[];for(const u of A)u.scope==="domain"&&u.reuseOnly!==!0&&t.push(l("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${u.name}" is outside MVP.`));return{ok:t.length===0,errors:t,warnings:a}}function ye(e){var o;const t=[];if(!e||typeof e!="object")return{ok:!1,errors:[l("invalid_change_plan","Dashboard change plan must be a structured object.")],warnings:[]};const n=e,a=[...n.warnings||[]];n.version!==1&&t.push(l("invalid_version","Dashboard change plan version must be 1.")),(o=n.dashboardId)!=null&&o.trim()||t.push(l("missing_dashboard_id","Dashboard change plan needs a dashboard id."));const i=Array.isArray(n.datasets)?n.datasets:[],r=Array.isArray(n.operations)?n.operations:[];ge({datasets:i,errors:t,requireAtLeastOne:!1});for(const d of r){if(d.kind==="unsupported"){a.push(l("unsupported_operation",d.reason||d.requestedAction));continue}d.kind==="addCard"&&d.card.type==="custom"&&t.push(l("custom_visual_out_of_scope","Whole-dashboard authoring supports built-in visual types only.",d.card.id)),d.kind==="addCard"&&(pe({card:d.card,datasets:i,errors:t}),be({card:d.card,errors:t}),he({card:d.card,datasets:i,errors:t})),d.kind==="addCalculatedField"&&d.field.scope==="domain"&&d.field.reuseOnly!==!0&&t.push(l("domain_calculated_field_create_out_of_scope",`Creating domain calculated field "${d.field.name}" is outside MVP.`))}return{ok:t.length===0,errors:t,warnings:a}}const qe={lg:48,md:36,sm:24,xs:12,xxs:6};function Be(e,t){let n=0,a=0,i=0;return e.map(r=>{const o=Math.min(r.w,t);n>0&&n+o>t&&(n=0,a+=i,i=0);const d={i:r.frameId,x:n,y:a,w:o,h:r.h,minW:Math.min(r.minW,t),minH:r.minH,static:!1};return n+=o,i=Math.max(i,r.h),d})}function Ve(e){const t=[...e].sort((s,f)=>s.priority-f.priority),n=t.filter(s=>s.role==="kpi"),a=t.filter(s=>s.role==="chart"),i=t.filter(s=>s.role==="table"),r=t.filter(s=>s.role==="text"),o=r.slice(0,1),d=r.slice(o.length);return{kpis:n,introText:o,charts:a,tables:i,supportingText:d}}function Oe(e,t,n){return t==="xxs"||t==="xs"?n:t==="sm"?Math.min(12,n):t==="md"?e<=1||e===2?18:12:e<=1||e===2?24:e===3?16:12}function ze(e,t,n,a){return n==="xxs"||n==="xs"||n==="sm"||n==="md"||t===1||t%2===1&&e===0?a:a/2}function Le(e){const{item:t,band:n,index:a,bandCount:i,breakpoint:r,columns:o}=e;return n==="kpi"?{...t,band:n,w:Oe(i,r,o),h:15,minW:Math.min(6,o),minH:12}:n==="table"?{...t,band:n,w:o,h:r==="xxs"||r==="xs"?34:38,minW:Math.min(12,o),minH:18}:n==="introText"?{...t,band:n,w:o,h:r==="xxs"||r==="xs"?12:10,minW:Math.min(12,o),minH:8}:n==="supportingText"?{...t,band:n,w:r==="lg"?o/2:o,h:r==="xxs"||r==="xs"?12:10,minW:Math.min(12,o),minH:8}:{...t,band:n,w:ze(a,i,r,o),h:r==="xxs"||r==="xs"?28:30,minW:Math.min(12,o),minH:16}}function x(e,t,n,a){return e.map((i,r)=>Le({item:i,band:t,index:r,bandCount:e.length,breakpoint:n,columns:a}))}function q(e){const t=Ve(e);return Object.fromEntries(oe.map(n=>{const a=qe[n],i=[...x(t.introText,"introText",n,a),...x(t.kpis,"kpi",n,a),...x(t.charts,"chart",n,a),...x(t.tables,"table",n,a),...x(t.supportingText,"supportingText",n,a)];return[n,Be(i,a)]}))}function je(e){const t=String(e||"").trim().toLowerCase();return t.includes("date")||t.includes("time")||t.includes("timestamp")?"date":t.includes("int")||t.includes("float")||t.includes("double")||t.includes("decimal")||t.includes("numeric")||t.includes("number")||t.includes("currency")||t.includes("percent")?"number":t.includes("bool")?"boolean":"string"}function Ee(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function He(e){return Ee(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function Ge(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function We(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function U(e,t){if(t===void 0)return;const n=je(e.dataType),a=e.operation||"in";if(He(t))return{...t,filterId:e.id,name:t.name||e.column,valueType:n,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};if(a==="is null"||a==="is not null")return{filterId:e.id,name:e.column,operation:a,valueType:n,values:[],dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext};const i=Array.isArray(t)?t:[t],r=n==="date"?We(i):Ge(i);if(r.length!==0&&!((a==="between"||a==="not between")&&r.length<2))return{filterId:e.id,name:e.column,operation:a,valueType:n,values:r,dataType:e.dataType,fieldMeta:e.fieldMeta,semanticContext:e.semanticContext}}function Ue(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function Ke(e,t,n){const a=(t||[]).filter(i=>i.scope==="card"&&i.targetCardId===n).map(i=>i.field).filter(Boolean);return a.length===0?e:{...e,calculatedFields:[...e.calculatedFields||[],...a]}}function Qe(e){const t={};return{inputs:(e.filterInputs||[]).map((a,i)=>{const r=U(a.filter,a.defaultValue);return r&&(t.shared??(t.shared={}),t.shared[a.id]={status:"set",value:{kind:"filter",filterValue:r}}),{id:a.id,kind:"filter",label:a.label,variableName:a.variableName,scope:a.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:i},exports:["label","value","start","end","range"],filter:a.filter}}),defaultInputValues:t.shared&&Object.keys(t.shared).length>0?t:void 0}}function Xe(e){var g,y;const t=Ie(e.plan);if(!t.ok)throw new Error(t.errors.map(c=>c.message).join(`
|
|
2
|
+
`)||"Dashboard plan is invalid.");const n=e.plan.sheets[0],a=[...t.warnings],i=[],r=new Map(e.cardArtifacts.map(c=>[c.planCardId,c])),o=[];for(const c of n.cards){const b=r.get(c.id);if(!b){const m=Ue("missing_card_artifact",`Card "${c.title}" was skipped because no generated artifact was supplied.`,c.id);i.push(m);continue}a.push(...b.warnings||[]);const A=Ke(b.card,e.plan.calculatedFields,c.id);o.push({id:c.frameId,cards:[A],activeCardId:A.id})}if(o.length===0)throw new Error("Dashboard plan did not produce any persistable cards.");const{inputs:d,defaultInputValues:s}=Qe(e.plan),f=q(n.cards.filter(c=>o.some(b=>b.id===c.frameId)).map(c=>({frameId:c.frameId,priority:c.priority,role:c.role})));return{dashboard:{id:e.dashboardId,title:e.plan.title,description:e.plan.description||"",sheets:[{id:n.id,kind:"dashboard",title:n.title,description:n.description,frames:o,layouts:f,calculatedFields:(g=e.plan.calculatedFields)==null?void 0:g.filter(c=>c.scope==="sheet"&&c.field).map(c=>c.field)}],calculatedFields:(y=e.plan.calculatedFields)==null?void 0:y.filter(c=>c.scope==="dashboard"&&c.field).map(c=>c.field),inputs:d,...s?{defaultInputValues:s}:{}},warnings:a,skippedOperations:i}}function k(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function Je(e){return JSON.parse(JSON.stringify(e))}function Ye(e){var t;return(t=e.sheets)==null?void 0:t.find(n=>(n.kind||"dashboard")==="dashboard")}function V(e,t){var n;for(const a of e.sheets||[])for(const i of a.frames||[]){const r=(n=i.cards)==null?void 0:n.find(o=>o.id===t);if(r)return{sheet:a,frame:i,card:r}}return null}function _e(e){var n,a;const t=(a=(n=e.cards)==null?void 0:n[0])==null?void 0:a.type;return t==="kpi"?"kpi":t==="table"||t==="detailTable"||t==="pivotTable"?"table":t==="text"?"text":"chart"}function Ze(e){var t;return new Map((((t=e.layouts)==null?void 0:t.lg)||[]).map((n,a)=>[n.i,a]))}function ve(e,t=new Map){const n=Ze(e),a=Math.max(n.size,t.size),i=(e.frames||[]).map((r,o)=>({frameId:r.id,role:_e(r),priority:t.get(r.id)??n.get(r.id)??a+o}));e.layouts=q(i)}function et(e){return Object.values(e.layouts||{}).some(t=>t.length>0)}function tt(e,t){if(!et(e)){ve(e);return}const n=q([{frameId:t.id,role:_e(t),priority:0}]);e.layouts??(e.layouts={});for(const[a,i]of Object.entries(n)){const r=e.layouts[a]||[];if(r.some(s=>s.i===t.id))continue;const o=i[0];if(!o)continue;const d=r.reduce((s,f)=>Math.max(s,f.y+f.h),0);e.layouts[a]=[...r,{...o,y:d}]}}function nt(e,t){var a;const n=U(t.filter,t.defaultValue);n&&(e.defaultInputValues??(e.defaultInputValues={}),(a=e.defaultInputValues).shared??(a.shared={}),e.defaultInputValues.shared[t.id]={status:"set",value:{kind:"filter",filterValue:n}})}function at(e){var d;const t=ye(e.changePlan);if(!t.ok)throw new Error(t.errors.map(s=>s.message).join(`
|
|
3
|
+
`)||"Dashboard change plan is invalid.");const n=Je(e.dashboard),a=[...t.warnings],i=[],r=new Map(e.cardArtifacts.map(s=>[s.planCardId,s])),o=Ye(n);if(!o)throw new Error("Dashboard has no editable dashboard sheet.");o.frames??(o.frames=[]);for(const s of e.changePlan.operations)switch(s.kind){case"addCard":{if((o.frames||[]).reduce((y,c)=>{var b;return y+(((b=c.cards)==null?void 0:b.length)||0)},0)>=T){i.push(k("generated_card_limit_reached",`MVP AI refinement is capped at ${T} cards.`,s.card.id));break}const p=r.get(s.card.id);if(!p){i.push(k("missing_card_artifact",`Card "${s.card.title}" was skipped because no generated artifact was supplied.`,s.card.id));break}const g={id:s.card.frameId,cards:[p.card],activeCardId:p.card.id};o.frames.push(g),tt(o,g);break}case"addFilterInput":{n.inputs??(n.inputs=[]);const f={id:s.input.id,kind:"filter",label:s.input.label,variableName:s.input.variableName,scope:s.input.scope||{kind:"allSheets",sheetKinds:["dashboard"]},runtimeScope:"shared",presentation:{placement:"toolbar",order:n.inputs.length},exports:["label","value","start","end","range"],filter:s.input.filter};n.inputs.push(f),nt(n,s.input);break}case"addCalculatedField":{if(s.field.scope==="dashboard"&&s.field.field)n.calculatedFields??(n.calculatedFields=[]),n.calculatedFields.push(s.field.field);else if(s.field.scope==="sheet"&&s.field.field)o.calculatedFields??(o.calculatedFields=[]),o.calculatedFields.push(s.field.field);else if(s.field.scope==="card"&&s.field.field){const f=s.field.targetCardId?V(n,s.field.targetCardId):null;f?((d=f.card).calculatedFields??(d.calculatedFields=[]),f.card.calculatedFields.push(s.field.field)):i.push(k("missing_calculated_field_target",`Calculated field "${s.field.name}" needs a valid target card.`))}break}case"renameCard":{const f=V(n,s.cardId);if(!f){i.push(k("card_not_found",`Card "${s.cardId}" could not be renamed because it was not found.`,s.cardId));break}f.card.title=s.title,s.description!==void 0&&(f.card.description=s.description);break}case"reorderCards":{const f=new Map;for(let p=0;p<s.cardIds.length;p+=1){const g=s.cardIds[p],y=V(n,g);y&&f.set(y.frame.id,p)}ve(o,f);break}case"reuseCalculatedField":a.push(k("reused_calculated_field",`Calculated field "${s.fieldId}" is reused by reference.`));break;case"unsupported":i.push(k("unsupported_operation",s.reason||s.requestedAction));break}return{dashboard:n,warnings:a,skippedOperations:i}}function I(e,t,n){return n?{code:e,message:t,cardId:n}:{code:e,message:t}}function N(e,t){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||t}function we(e,t){if(!t.has(e))return t.add(e),e;let n=2,a=`${e}-${n}`;for(;t.has(a);)n+=1,a=`${e}-${n}`;return t.add(a),a}function F(e){return!!(e&&typeof e=="object")}function Se(e){return Array.isArray(e.inputs)?e.inputs.filter(t=>F(t)&&typeof t.id=="string"):[]}function K(e){return Array.isArray(e.sections)?e.sections.filter(t=>F(t)):[]}function Q(e){return Array.isArray(e.views)?e.views.filter(t=>F(t)):[]}function rt(e){return C(e)?e.kind==="semantic"?{kind:"semantic",domainId:e.domainId,datasetName:e.datasetName,datasetId:e.datasetId,label:e.label,connectionId:e.connectionId}:e.kind==="physical"?{kind:"physical",connectionId:e.connectionId,databaseName:e.databaseName,schemaName:e.schemaName,tableName:e.tableName,label:e.label}:null:null}function O(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const a=w(n);a&&t.push(a)}return t}function it(e){if(!e)return[];const t=[];if(C(e.source)&&t.push(e.source),e.kind==="metric"){const a=w(e.dateField);a&&t.push(a),t.push(...O(e.dimensions))}else if(e.kind==="records"){const a=w(e.dateField);a&&t.push(a),t.push(...O(e.fields))}else if(e.kind==="inputOptions"){const a=w(e.field);a&&t.push(a)}else e.kind==="sql"&&t.push(...O(e.fields));const n="inputs"in e&&Array.isArray(e.inputs)?e.inputs:[];for(const a of n){const i=w(a.field);i&&t.push(i)}return t}function ot(e){const t=[];for(const n of Se(e)){C(n.source)&&t.push(n.source);const a=w(n.field);a&&t.push(a)}for(const n of K(e))for(const a of Q(n))t.push(...it(a.analytics));return t}function st(e){var n;const t=[];for(const a of K(e))for(const i of Q(a))C((n=i.analytics)==null?void 0:n.source)&&t.push(i.analytics.source);return t}function dt(e,t){const n=R(e).map(rt).filter(r=>!!r);if(n.length===0)return t.push(I("missing_materializable_dataset","No semantic or physical source could be converted into the current dashboard authoring dataset reference.")),[];const a=n.every(r=>r.kind==="semantic"),i=Array.from(new Set(n.filter(r=>r.kind==="semantic").map(r=>r.domainId)));return n.length>1&&(!a||i.length!==1)?(t.push(I("multiple_datasets_out_of_scope","The dashboard authoring compiler supports multiple datasets only within one semantic domain; using the first source and deferring the rest.")),[n[0]]):n}function ct(e,t){const n=K(e),a=Se(e),i=R(ot(e)),r=R(st(e));return{sections:n,inputs:a,sources:i,primarySources:r,defaultSource:r.length===1?r[0]:void 0,datasets:dt(i,t)}}function ut(e){return Ae(e).map(t=>t.name).filter(Boolean)}function Ae(e){return(Array.isArray(e.fields)?e.fields:[]).filter(t=>!ue(t,e.dateField))}function lt(e){const t=Array.isArray(e.metrics)?e.metrics.filter(n=>typeof n=="string"&&n.trim().length>0):[];return Array.from(new Set([e.metric,...t].filter(n=>typeof n=="string"&&n.trim().length>0)))}function ft(e){return F(e)&&typeof e.name=="string"&&e.name.trim().length>0}function mt(e){if(!Array.isArray(e.dimensions))return;const t=e.dimensions.filter(ft).map(n=>n.name);return t.length?t:void 0}function ae(e){return e==="hour"?"day":e}function H(e,t={}){var n,a;if(e!=null&&e.name){if(((n=e.source)==null?void 0:n.kind)==="semantic")return!e.source.domainId||!e.source.datasetName?void 0:{name:e.name,source:{kind:"semantic",domainId:e.source.domainId,datasetName:e.source.datasetName,datasetId:e.source.datasetId,label:e.source.label,connectionId:e.source.connectionId}};if(((a=e.source)==null?void 0:a.kind)==="physical")return!e.source.connectionId||!e.source.tableName?void 0:{name:e.name,source:{kind:"physical",connectionId:e.source.connectionId,tableName:e.source.tableName,databaseName:e.source.databaseName,schemaName:e.source.schemaName,label:e.source.label}};if(!(e.source!==void 0||!t.includeUnsourced))return{name:e.name}}}function re(e){if(!Array.isArray(e))return;const t=e.map(n=>H(n,{includeUnsourced:!0})).filter(Boolean);if(t.length===e.length)return t.some(n=>n.source)?t:void 0}function pt(e){var t,n;if(e){if(e.kind==="metric")return{metric:e.metric,metrics:lt(e),dateField:(t=e.dateField)==null?void 0:t.name,dateFieldRef:H(e.dateField),timeGrain:ae(e.timeGrain),dimensions:mt(e),dimensionRefs:re(e.dimensions),limit:e.limit};if(e.kind==="records")return{metrics:e.measures,dateField:(n=e.dateField)==null?void 0:n.name,dateFieldRef:H(e.dateField),timeGrain:ae(e.timeGrain),dimensions:ut(e),dimensionRefs:re(Ae(e)),limit:e.limit}}}function ht(e){return e&&ie.validateSemaphorAnalyticsIntent(e).ok?e:void 0}function bt(e){var t;switch((t=e.presentation)==null?void 0:t.kind){case"kpi":return"kpi";case"lineChart":return"line";case"barChart":return"bar";case"areaChart":return"area";case"table":return"table";case"text":return"text";default:return null}}function gt(e){var t,n,a;return((t=e.presentation)==null?void 0:t.kind)==="kpi"?"kpi":((n=e.presentation)==null?void 0:n.kind)==="table"?"table":((a=e.presentation)==null?void 0:a.kind)==="text"?"text":"chart"}function It(e){switch(e){case"not_in":return"not in";case"contains":return"like";default:return e||"in"}}function yt(e){return F(e.field)?e.field.dataType==="datetime"?"date":e.field.dataType||"string":"string"}function _t(e){if(!(!e||e.kind!=="physical"))return[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")}function vt(e,t,n,a,i,r){if(e.kind!=="filter")return r.push(I("control_inputs_deferred",`Control input "${e.label}" is represented in the protocol but not yet materialized by the dashboard authoring adapter.`)),null;if(!F(e.field)||typeof e.field.name!="string")return r.push(I("filter_requires_field",`Filter "${e.label||e.id}" needs a field before the dashboard compiler can materialize it.`)),null;const o=ce({explicitSource:e.source,field:e.field,defaultSource:t,fallbackSources:n}),d=(o==null?void 0:o.kind)==="semantic"||(o==null?void 0:o.kind)==="physical"?o.connectionId:void 0;if(!d)return r.push(I("filter_requires_connection_id",`Filter "${e.label}" needs a source connectionId before the dashboard compiler can materialize it.`)),null;const p={id:`filter-${we(N(e.id,e.field.name),i)}`,variableName:e.id,connectionId:d,title:e.label,column:e.field.name,dataType:yt(e),qualifiedTableName:_t(o),sql:"",operation:It(e.operator),type:e.multi===!1?"single":"multiple",location:"dashboard",displayMode:"toolbar",fieldMeta:(o==null?void 0:o.kind)==="semantic"?{name:e.field.name,qualifiedFieldName:e.field.name,dataType:e.field.dataType,role:e.field.role==="measure"?"metric":"groupby"}:void 0,semanticContext:(o==null?void 0:o.kind)==="semantic"?{semanticDomainId:o.domainId,connectionId:o.connectionId}:void 0};return{id:e.id,label:e.label,variableName:e.id,scope:a,filter:p,defaultValue:U(p,e.defaultValue)}}function z(e){const t=[],n=[];for(const a of e.viewIds){const i=e.viewIdToCardId.get(a);i?t.push(i):n.push(a)}return n.length>0&&e.warnings.push(I("input_scope_view_not_found",`Filter "${e.inputLabel}" referenced unknown view ids: ${n.join(", ")}.`)),Array.from(new Set(t))}function wt(e){var a,i;if(!e.protocolScope){const r=Array.from(new Set(e.boundCardIds));return r.length>0&&r.length<e.allCardIds.length?{kind:"cards",cardIds:r}:void 0}if(e.protocolScope.level==="dashboard"){if(!((a=e.protocolScope.excludeViewIds)!=null&&a.length))return;const r=new Set(z({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:e.allCardIds.filter(o=>!r.has(o))}}if(e.protocolScope.level==="view"){const r=z({inputLabel:e.inputLabel,viewIds:e.protocolScope.viewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings});return r.length===0?(e.warnings.push(I("input_scope_has_no_materialized_cards",`Filter "${e.inputLabel}" was deferred because its view scope does not match any materialized cards.`)),null):{kind:"cards",cardIds:r}}const t=e.sectionIdToCardIds.get(e.protocolScope.sectionId)||[];if(t.length===0)return e.warnings.push(I("input_scope_section_not_found",`Filter "${e.inputLabel}" was deferred because section "${e.protocolScope.sectionId}" does not match any materialized cards.`)),null;if(!((i=e.protocolScope.excludeViewIds)!=null&&i.length))return{kind:"cards",cardIds:t};const n=new Set(z({inputLabel:e.inputLabel,viewIds:e.protocolScope.excludeViewIds,viewIdToCardId:e.viewIdToCardId,warnings:e.warnings}));return{kind:"cards",cardIds:t.filter(r=>!n.has(r))}}function St(e){var c,b,A;const t=[],n=ie.validateSemaphorDashboardIntent(e);for(const m of n.warnings)t.push(I(m.code,m.message));for(const m of n.errors)t.push(I(m.code,m.message));const a=ct(e,t),i=[],r=new Map,o=new Map,d=new Map,s=new Set,f=new Set;let p=0;for(const[m,v]of a.sections.entries()){const u=typeof v.title=="string"?v.title:`Section ${m+1}`,X=v.id||N(u,`section-${m+1}`);o.set(X,[]);for(const[J,h]of Q(v).entries()){const Y=bt(h),B=N(h.id||`${u}-${h.title||`View ${J+1}`}`,`card-${m+1}-${J+1}`);if(!Y){t.push(I("unsupported_presentation",`Dashboard presentation "${((c=h.presentation)==null?void 0:c.kind)||"unknown"}" is not supported by the dashboard authoring adapter.`,`card-${B}`));continue}if(((b=h.analytics)==null?void 0:b.kind)==="sql"){t.push(I("sql_intent_deferred","SQL analytics intent is valid protocol, but the current dashboard authoring adapter only materializes semantic and physical config-card intents.",`card-${B}`));continue}const Z=we(B,s),$=`card-${Z}`;h.id&&r.set(h.id,$),(A=o.get(X))==null||A.push($);const De=h.analytics&&"inputs"in h.analytics?h.analytics.inputs:void 0;for(const ee of De||[]){const te=d.get(ee.inputId)||[];te.push($),d.set(ee.inputId,te)}i.push({id:$,frameId:`frame-${Z}`,title:h.title,description:h.description,type:Y,role:gt(h),priority:p,section:u,query:pt(h.analytics),analyticsIntent:ht(h.analytics),text:h.text}),p+=1}}const g=a.inputs.map(m=>{const v=wt({protocolScope:m.scope,inputLabel:m.label,allCardIds:i.map(u=>u.id),boundCardIds:d.get(m.id)||[],viewIdToCardId:r,sectionIdToCardIds:o,warnings:t});return v===null?null:vt(m,a.defaultSource,a.sources,v,f,t)}).filter(m=>!!m);return{plan:{version:1,id:`plan-${N(e.title,"dashboard")}`,title:e.title,description:e.description,datasets:a.datasets,sheets:[{id:`sheet-${N(e.title,"dashboard")}`,title:e.title,description:e.description,kind:"dashboard",cards:i}],filterInputs:g.length?g:void 0,warnings:t.length?t:void 0,unresolvedRequests:n.ok?void 0:n.errors.map(m=>m.message)},warnings:t}}exports.DASHBOARD_AUTHORING_BREAKPOINTS=oe;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=T;exports.applyDashboardChangePlan=at;exports.compileDashboardFromPlan=Xe;exports.compileResponsiveDashboardLayouts=q;exports.dashboardAuthoringDatasetMatchesSource=P;exports.dashboardAuthoringFieldsReferToSameTarget=ue;exports.dashboardAuthoringSourceFromField=w;exports.dashboardAuthoringSourceKey=L;exports.dashboardAuthoringSourcesReferToSameDataset=W;exports.dashboardPlanFromSemaphorDashboardIntent=St;exports.findDashboardAuthoringDatasetForSource=$e;exports.getDashboardAuthoringCardSource=fe;exports.isMaterializableDashboardAuthoringSource=C;exports.isSemaphorSourceRef=se;exports.mergeDashboardAuthoringSources=R;exports.preferDashboardAuthoringSourceMetadata=de;exports.preferredDashboardAuthoringSource=ke;exports.resolveDashboardAuthoringSource=ce;exports.validateDashboardAuthoringDatasetScope=me;exports.validateDashboardChangePlan=ye;exports.validateDashboardPlan=Ie;
|