react-semaphor 0.1.326 → 0.1.328
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 +1 -1
- package/dist/brand-studio/index.cjs +5 -5
- package/dist/brand-studio/index.js +23 -24
- package/dist/chunks/_commonjsHelpers-BVfed4GL.js +28 -0
- package/dist/chunks/_commonjsHelpers-DwTZ_eVU.js +1 -0
- package/dist/chunks/{braces-DVaMJoCd.js → braces-CG8viaD2.js} +1 -1
- package/dist/chunks/{braces-dHeaioTd.js → braces-DSaa_4Oc.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-mqU_uOmY.js → calendar-preferences-dialog-DD_qAthL.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog--2jD-eKu.js → calendar-preferences-dialog-JRmNJptJ.js} +3 -3
- package/dist/chunks/{chevrons-up-down-DNQE-uEp.js → chevrons-up-down-CBa0uh0X.js} +1 -1
- package/dist/chunks/{chevrons-up-down-CLbzBHoI.js → chevrons-up-down-ChDNqVP7.js} +1 -1
- package/dist/chunks/dashboard-briefing-launcher-BKdJFwH5.js +106 -0
- package/dist/chunks/{dashboard-briefing-launcher-DsjXUPFq.js → dashboard-briefing-launcher-BfyNkd8i.js} +1106 -1108
- package/dist/chunks/{dashboard-controls-DgNkM1yT.js → dashboard-controls-0pZDLvFL.js} +218 -218
- package/dist/chunks/{dashboard-controls-XCa9PZuU.js → dashboard-controls-C0xm1QMR.js} +10 -10
- package/dist/chunks/dashboard-json-BW5OVZ6m.js +1 -0
- package/dist/chunks/{dashboard-json-DkA6Bf0Y.js → dashboard-json-DsruhRPD.js} +14 -13
- package/dist/chunks/date-formatter-B4EBSe9C.js +1 -0
- package/dist/chunks/date-formatter-CzcPZx39.js +416 -0
- package/dist/chunks/edit-dashboard-visual-DQyJ7SSv.js +178 -0
- package/dist/chunks/{edit-dashboard-visual-Q5hW5MXk.js → edit-dashboard-visual-g5SZZahJ.js} +8242 -7784
- package/dist/chunks/index-1JWDPCun.js +1935 -0
- package/dist/chunks/index-BdjXTQt4.js +1444 -0
- package/dist/chunks/{index-DwfDwtv2.js → index-BmKr-K7J.js} +117670 -113627
- package/dist/chunks/index-C1l78BIx.js +3247 -0
- package/dist/chunks/lib-Ce3zosXY.js +38 -0
- package/dist/chunks/lib-DFvr9fM4.js +5500 -0
- package/dist/chunks/{palette-DtmNws9a.js → palette-D0YmAqBS.js} +1 -1
- package/dist/chunks/{palette-DpcvHAiY.js → palette-DQgq3edH.js} +1 -1
- package/dist/chunks/{resource-management-panel-CGwWKZOP.js → resource-management-panel-CIfBh46E.js} +1 -1
- package/dist/chunks/{resource-management-panel-D2oAQkKi.js → resource-management-panel-Cj19pw9M.js} +145 -145
- package/dist/chunks/switch-BvTzw2AW.js +173 -0
- package/dist/chunks/{switch-j3AThLFk.js → switch-De31SR3q.js} +2752 -2717
- package/dist/chunks/typescript-Cmizj1hi.js +446 -0
- package/dist/chunks/typescript-H1EwZsOb.js +159820 -0
- package/dist/chunks/use-create-flow-overlay-state-BTQiKRD1.js +26 -0
- package/dist/chunks/{use-create-flow-overlay-state-CP6GDQAX.js → use-create-flow-overlay-state-IcHP0l39.js} +150 -151
- package/dist/chunks/{use-visual-utils-CSXU-96k.js → use-visual-utils-DQ5zGYD2.js} +13 -13
- package/dist/chunks/{use-visual-utils-NpOW5uZ1.js → use-visual-utils-XF-AqV8o.js} +1 -1
- package/dist/chunks/{validators-DvTxl9i0.js → validators-DDAweCzB.js} +67 -48
- 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 +907 -527
- package/dist/data-app-builder/index.cjs +1 -0
- package/dist/data-app-builder/index.js +4 -0
- package/dist/data-app-builder-browser-runtime/index.cjs +1 -0
- package/dist/data-app-builder-browser-runtime/index.js +10 -0
- package/dist/data-app-sdk/index.cjs +1 -1
- package/dist/data-app-sdk/index.js +208 -196
- 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 +14 -14
- 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 +1 -0
- package/dist/types/dashboard-authoring.d.ts +79 -2
- package/dist/types/dashboard.d.ts +17 -2
- package/dist/types/data-app-builder-browser-runtime.d.ts +185 -0
- package/dist/types/data-app-builder.d.ts +630 -0
- package/dist/types/data-app-sdk.d.ts +15 -1
- package/dist/types/format-utils.d.ts +25 -0
- package/dist/types/main.d.ts +67 -10
- package/dist/types/shared.d.ts +17 -2
- package/dist/types/surfboard.d.ts +17 -2
- package/dist/types/types.d.ts +32 -3
- package/package.json +11 -1
- package/dist/chunks/dashboard-briefing-launcher-DguNfFr8.js +0 -106
- package/dist/chunks/dashboard-json-DiBd65Xf.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-BC9eOc4U.js +0 -178
- package/dist/chunks/index-B1-46PoR.js +0 -1303
- package/dist/chunks/save-BY7WF62U.js +0 -21
- package/dist/chunks/save-Cv_XRb94.js +0 -6
- package/dist/chunks/switch-5aQ_jcLH.js +0 -168
- package/dist/chunks/use-create-flow-overlay-state-BQPXP0AM.js +0 -26
- package/dist/chunks/validators-DJUMR5An.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { H as ne, E as ie, u as b, G as H, I as ce } from "./switch-
|
|
1
|
+
import { ad as X, u as Y, ae as Z, af as ee, ag as te, ah as re, ai as se, aj as ae, p as V, ak as oe } from "./index-BmKr-K7J.js";
|
|
2
|
+
import { H as ne, E as ie, u as b, G as H, I as ce } from "./switch-De31SR3q.js";
|
|
3
3
|
import { useState as z, useEffect as de, useCallback as A } from "react";
|
|
4
4
|
function le(e) {
|
|
5
5
|
const [a, s] = z(null), [r, t] = z(null), o = X();
|
|
@@ -194,12 +194,12 @@ function be() {
|
|
|
194
194
|
setSelectedDatamodelId: g,
|
|
195
195
|
setFilterValues: P,
|
|
196
196
|
setInlineFilterValuesMap: j,
|
|
197
|
-
setApplyFilters:
|
|
198
|
-
clearEditorContext:
|
|
197
|
+
setApplyFilters: k,
|
|
198
|
+
clearEditorContext: D
|
|
199
199
|
} = ne(), {
|
|
200
200
|
setIsDashboardEditing: U,
|
|
201
|
-
setIsVisualEditing:
|
|
202
|
-
setSelectedFrameId:
|
|
201
|
+
setIsVisualEditing: L,
|
|
202
|
+
setSelectedFrameId: T,
|
|
203
203
|
clearSelectedFrameId: N,
|
|
204
204
|
setIsDashboardPanelOpen: W
|
|
205
205
|
} = ie(), E = b((c) => c.selectedSheetId), $ = b((c) => c.selectedFrameId), R = b((c) => c.dashboard), x = b((c) => c.filterValues), O = b(
|
|
@@ -209,7 +209,7 @@ function be() {
|
|
|
209
209
|
}), G = A(
|
|
210
210
|
async (c) => {
|
|
211
211
|
try {
|
|
212
|
-
o(c), N(),
|
|
212
|
+
o(c), N(), D();
|
|
213
213
|
const { data: u, fromCache: v } = await Q(
|
|
214
214
|
a.apiServiceUrl,
|
|
215
215
|
(e == null ? void 0 : e.accessToken) || "",
|
|
@@ -231,9 +231,9 @@ function be() {
|
|
|
231
231
|
setSelectedDatamodelId: g,
|
|
232
232
|
setFilterValues: P,
|
|
233
233
|
setInlineFilterValuesMap: j,
|
|
234
|
-
setApplyFilters:
|
|
234
|
+
setApplyFilters: k,
|
|
235
235
|
setIsDashboardEditing: U,
|
|
236
|
-
setIsVisualEditing:
|
|
236
|
+
setIsVisualEditing: L,
|
|
237
237
|
dashboard: R,
|
|
238
238
|
selectedSheetId: E,
|
|
239
239
|
selectedFrameId: $,
|
|
@@ -254,7 +254,7 @@ function be() {
|
|
|
254
254
|
l,
|
|
255
255
|
n,
|
|
256
256
|
U,
|
|
257
|
-
|
|
257
|
+
L,
|
|
258
258
|
i,
|
|
259
259
|
f,
|
|
260
260
|
h,
|
|
@@ -267,8 +267,8 @@ function be() {
|
|
|
267
267
|
g,
|
|
268
268
|
P,
|
|
269
269
|
j,
|
|
270
|
+
k,
|
|
270
271
|
D,
|
|
271
|
-
L,
|
|
272
272
|
N,
|
|
273
273
|
R,
|
|
274
274
|
E,
|
|
@@ -303,7 +303,7 @@ function be() {
|
|
|
303
303
|
E,
|
|
304
304
|
B,
|
|
305
305
|
"end"
|
|
306
|
-
), U(!0),
|
|
306
|
+
), U(!0), T(B.id), W(!1), { success: !0, fromCache: K };
|
|
307
307
|
} catch (d) {
|
|
308
308
|
return console.error("Error adding visual:", d), u(
|
|
309
309
|
d instanceof Error ? d.message : "Failed to add visual to dashboard"
|
|
@@ -317,7 +317,7 @@ function be() {
|
|
|
317
317
|
o,
|
|
318
318
|
E,
|
|
319
319
|
U,
|
|
320
|
-
|
|
320
|
+
T,
|
|
321
321
|
W,
|
|
322
322
|
r
|
|
323
323
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const u=require("./index-
|
|
1
|
+
"use strict";const u=require("./index-BdjXTQt4.js"),f=require("./switch-BvTzw2AW.js"),S=require("react");function K(e){const[a,s]=S.useState(null),[r,t]=S.useState(null),o=u.useEnsureReactGlobals();return S.useEffect(()=>{if(!e||e.trim()===""){s(null),t(null);return}if(!o)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const i=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const m=await import(i);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");s(()=>m.useChartStore),t(null)}catch(n){const i=n instanceof Error?n.message:"Unknown error";console.error("Failed to load remote chart store:",i),t(i),s(null)}})()},[e,o]),a}function X(e,a){if(e.length===0)return"";const s=e.find(r=>{var t,o;return((t=r.customCardPreferences)==null?void 0:t.visualType)==="multiple"||!!((o=r.customCardPreferences)!=null&&o.dataInputCardIds)});if(s)return s.id;if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const l=t.split("__")[0],n=e.find(i=>i.tabTitle===l);return n?n.id:e[0].id}return a}}return e[0].id}const A=new Set;function Y(e){return A.add(e),()=>{A.delete(e)}}function z(){A.forEach(e=>{e()})}const Z=e=>{if(!e||!("detailTableBackup"in e))return e;const{detailTableBackup:a,...s}=e;return s};async function B(e,a,s,r){if(!a||!s)throw new Error("Missing auth token or visual ID");const t=["resource-by-id","visual",s],o=r.getQueryData(t);if(o)return console.log("Using cached visual data for:",s),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",s);const l=u.ue.loading("Loading visual...",{position:"top-center"});try{const n=await fetch(`${e}/management/v1/visuals/${s}`,{headers:{Authorization:`Bearer ${a}`}});if(!n.ok)throw new Error("Failed to load visual");const i=await n.json();return r.setQueryData(t,i),u.ue.dismiss(l),{data:i,fromCache:!1}}catch(n){throw u.ue.dismiss(l),n}}function H(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function ee(e,a){var o,l;const s=(e==null?void 0:e.frameObject)??((o=e==null?void 0:e.visual)==null?void 0:o.frameObject);if(!s)return!1;const r=H(s);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const t=(l=r.cards)==null?void 0:l.find(n=>n.id===r.activeCardId);return t?(u.setupEditorWithCard({...a,frame:r,card:t,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function te(){const e=f.useEditorStore(r=>{var t;return((t=r.card.customCardPreferences)==null?void 0:t.url)||""}),a=K(e);return{getUpdatedFrame:S.useCallback(()=>{var b;z();const{frame:r,card:t,isDevMode:o,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y}=f.useEditorStore.getState(),I=t.sql,U=(b=a==null?void 0:a.getState())==null?void 0:b.settings,V=f.buildSavedEditorCard(t,{isDevMode:o,cardSql:I,isShowingVisual:l,selectedSchemaName:n,selectedDatamodelId:i,selectedDatabaseName:m,selectedTableName:p,selectedConnectionId:y,remoteChartSettings:U,stripConfig:Z}),g=r.cards.map(E=>E.id===t.id?V:E);return{...r,cards:g,activeCardId:X(g,r.activeCardId)}},[a])}}function re(){const{authToken:e,tokenProps:a}=u.useSemaphorContext(),s=u.useQueryClient(),r=u.useAddFrameWithFreshSemanticExecutionPayload(),t=u.useSelectedVisual(),{selectVisual:o}=u.useManagementActions(),{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,clearEditorContext:L}=f.useEditorActions(),{setIsDashboardEditing:v,setIsVisualEditing:T,setSelectedFrameId:j,clearSelectedFrameId:N,setIsDashboardPanelOpen:R}=f.useDashboardActions(),w=f.useDashboardStore(c=>c.selectedSheetId),W=f.useDashboardStore(c=>c.selectedFrameId),$=f.useDashboardStore(c=>c.dashboard),_=f.useDashboardStore(c=>c.filterValues),x=f.useDashboardStore(c=>c.inlineFilterValuesMap),F=u.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),Q=S.useCallback(async c=>{try{o(c),N(),L();const{data:h,fromCache:D}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s);if(!ee(h,{setFrame:l,setCard:n,setIsDevMode:i,initializeModeDrafts:m,setActiveTabCardId:p,updateDataSource:y,setQueryResultColumns:I,setSelectedConnectionId:U,setSelectedDatabaseName:V,setSelectedSchemaName:g,setSelectedTableName:b,setSelectedDatamodelId:E,setFilterValues:P,setInlineFilterValuesMap:M,setApplyFilters:k,setIsDashboardEditing:v,setIsVisualEditing:T,dashboard:$,selectedSheetId:w,selectedFrameId:W,filterValues:_,inlineFilterValuesMap:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:D}}catch(h){return console.error("Error editing visual:",h),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,l,n,v,T,i,m,p,y,I,U,V,g,b,E,P,M,k,L,N,$,w,W,_,x]),G=S.useCallback(async c=>{var D;const h=d=>(u.ue.error(d),{success:!1,error:d});try{if(o(c),!w)return h("No sheet selected. Please select a sheet first.");const{data:d,fromCache:J}=await B(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",c.id,s),O=(d==null?void 0:d.frameObject)??((D=d==null?void 0:d.visual)==null?void 0:D.frameObject);if(!O)return h("Visual has no frame data");const C=H(O);if(!(C!=null&&C.cards)||C.cards.length===0)return h("Visual frame is malformed");const q={...u.cloneLinkedFrameWithSourceMapping(C),visualId:c.id};return await r(w,q,"end"),v(!0),j(q.id),R(!1),{success:!0,fromCache:J}}catch(d){return console.error("Error adding visual:",d),h(d instanceof Error?d.message:"Failed to add visual to dashboard")}},[e==null?void 0:e.accessToken,a.apiServiceUrl,s,o,w,v,j,R,r]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:Q,handleAddLibraryVisual:G,getUpdatedFrame:te().getUpdatedFrame,refetch:F.refetch}}exports.flushPendingEditorDrafts=z;exports.registerPendingEditorDraftFlusher=Y;exports.useVisualUtils=re;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function s(e, i, n) {
|
|
2
2
|
return n ? { code: e, message: i, path: n } : { code: e, message: i };
|
|
3
3
|
}
|
|
4
|
-
function
|
|
4
|
+
function h(e) {
|
|
5
5
|
const i = /* @__PURE__ */ new Set();
|
|
6
6
|
for (const n of e) {
|
|
7
7
|
if (i.has(n))
|
|
@@ -13,10 +13,10 @@ function p(e) {
|
|
|
13
13
|
function t(e) {
|
|
14
14
|
return typeof e == "string" && e.trim().length > 0;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function m(e) {
|
|
17
17
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function _(e, i, n, c = {}) {
|
|
20
20
|
if (!e || typeof e != "object") {
|
|
21
21
|
n.push(s("missing_source", "Analytics intent needs a source.", i));
|
|
22
22
|
return;
|
|
@@ -60,13 +60,26 @@ function h(e, i, n, r = {}) {
|
|
|
60
60
|
"SQL source needs a connectionId.",
|
|
61
61
|
`${i}.connectionId`
|
|
62
62
|
)
|
|
63
|
-
),
|
|
63
|
+
), c.requireSqlText !== !1 && !t(e.sql) && n.push(s("missing_sql", "SQL source needs SQL text.", `${i}.sql`));
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
n.push(s("invalid_source_kind", "Source kind is not supported.", i));
|
|
67
67
|
}
|
|
68
|
+
function f(e, i, n, c = {}) {
|
|
69
|
+
if (!e || !m(e)) {
|
|
70
|
+
c.required && n.push(
|
|
71
|
+
s("missing_field_ref", "Field reference needs a name.", i)
|
|
72
|
+
);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
t(e.name) || n.push(
|
|
76
|
+
s("missing_field_ref", "Field reference needs a name.", `${i}.name`)
|
|
77
|
+
), e.source !== void 0 && _(e.source, `${i}.source`, n, {
|
|
78
|
+
requireSqlText: !1
|
|
79
|
+
});
|
|
80
|
+
}
|
|
68
81
|
function g(e) {
|
|
69
|
-
var
|
|
82
|
+
var c, u, d, p;
|
|
70
83
|
const i = [], n = [];
|
|
71
84
|
return !e || typeof e != "object" ? {
|
|
72
85
|
ok: !1,
|
|
@@ -85,7 +98,7 @@ function g(e) {
|
|
|
85
98
|
]
|
|
86
99
|
} : (e.version !== void 0 && e.version !== 1 && i.push(
|
|
87
100
|
s("invalid_version", "Analytics intent version must be 1.", "version")
|
|
88
|
-
),
|
|
101
|
+
), _(e.source, "source", i, {
|
|
89
102
|
requireSqlText: e.kind !== "sql" || !t(e.sql)
|
|
90
103
|
}), e.kind === "metric" ? (t(e.metric) || i.push(
|
|
91
104
|
s("missing_metric", "Metric intent needs a metric.", "metric")
|
|
@@ -95,7 +108,7 @@ function g(e) {
|
|
|
95
108
|
"Metric intent metrics must be an array of metric names.",
|
|
96
109
|
"metrics"
|
|
97
110
|
)
|
|
98
|
-
) : Array.isArray(e.metrics) && e.metrics.some((
|
|
111
|
+
) : Array.isArray(e.metrics) && e.metrics.some((r) => !t(r)) && i.push(
|
|
99
112
|
s(
|
|
100
113
|
"invalid_metric_list",
|
|
101
114
|
"Metric intent metrics must be an array of non-empty metric names.",
|
|
@@ -108,59 +121,65 @@ function g(e) {
|
|
|
108
121
|
"dimensions"
|
|
109
122
|
)
|
|
110
123
|
) : Array.isArray(e.dimensions) && e.dimensions.some(
|
|
111
|
-
(
|
|
124
|
+
(r) => !m(r) || !t(r.name)
|
|
112
125
|
) && i.push(
|
|
113
126
|
s(
|
|
114
127
|
"invalid_metric_dimensions",
|
|
115
128
|
"Metric intent dimensions must be an array of field references with names.",
|
|
116
129
|
"dimensions"
|
|
117
130
|
)
|
|
118
|
-
)
|
|
131
|
+
), e.dateField !== void 0 && f(e.dateField, "dateField", i), Array.isArray(e.dimensions) && e.dimensions.forEach((r, o) => {
|
|
132
|
+
f(r, `dimensions.${o}`, i);
|
|
133
|
+
})) : e.kind === "records" ? (!Array.isArray(e.fields) || e.fields.length === 0 ? i.push(
|
|
119
134
|
s(
|
|
120
135
|
"missing_record_fields",
|
|
121
136
|
"Records intent needs at least one field.",
|
|
122
137
|
"fields"
|
|
123
138
|
)
|
|
124
139
|
) : e.fields.some(
|
|
125
|
-
(
|
|
140
|
+
(r) => !m(r) || !t(r.name)
|
|
126
141
|
) && i.push(
|
|
127
142
|
s(
|
|
128
143
|
"invalid_record_fields",
|
|
129
144
|
"Records intent fields must be field references with names.",
|
|
130
145
|
"fields"
|
|
131
146
|
)
|
|
132
|
-
)
|
|
147
|
+
), Array.isArray(e.fields) && e.fields.forEach((r, o) => {
|
|
148
|
+
f(r, `fields.${o}`, i);
|
|
149
|
+
}), e.dateField !== void 0 && f(e.dateField, "dateField", i)) : e.kind === "inputOptions" ? ((!e.field || !t(e.field.name)) && i.push(
|
|
133
150
|
s(
|
|
134
151
|
"missing_input_options_field",
|
|
135
152
|
"Input options intent needs a field.",
|
|
136
153
|
"field"
|
|
137
154
|
)
|
|
138
|
-
) : e.kind === "sql" ? (((
|
|
155
|
+
), f(e.field, "field", i, { required: !0 })) : e.kind === "sql" ? (((c = e.source) == null ? void 0 : c.kind) !== "sql" && ((u = e.source) == null ? void 0 : u.kind) !== "physical" && i.push(
|
|
139
156
|
s(
|
|
140
157
|
"invalid_sql_source",
|
|
141
158
|
"SQL analytics intent must use a SQL or physical source.",
|
|
142
159
|
"source"
|
|
143
160
|
)
|
|
144
|
-
), t(e.sql) && ((
|
|
161
|
+
), t(e.sql) && ((d = e.source) == null ? void 0 : d.kind) === "sql" && t(e.source.sql) && y(e.sql) !== y(e.source.sql) && i.push(
|
|
145
162
|
s(
|
|
146
163
|
"conflicting_sql",
|
|
147
164
|
"SQL analytics intent cannot define different SQL text in source.sql and sql.",
|
|
148
165
|
"sql"
|
|
149
166
|
)
|
|
150
|
-
), !t(e.sql) && !(((
|
|
167
|
+
), !t(e.sql) && !(((p = e.source) == null ? void 0 : p.kind) === "sql" && t(e.source.sql)) && i.push(s("missing_sql", "SQL analytics intent needs SQL text.", "sql")), Array.isArray(e.fields) && e.fields.forEach((r, o) => {
|
|
168
|
+
f(r, `fields.${o}`, i);
|
|
169
|
+
})) : i.push(
|
|
151
170
|
s("invalid_analytics_kind", "Analytics kind is not supported.", "kind")
|
|
152
171
|
), {
|
|
153
172
|
ok: i.length === 0,
|
|
154
173
|
errors: i,
|
|
155
174
|
warnings: n,
|
|
156
|
-
repairHints:
|
|
175
|
+
repairHints: q(i)
|
|
157
176
|
});
|
|
158
177
|
}
|
|
159
|
-
function
|
|
178
|
+
function y(e) {
|
|
160
179
|
return e.replace(/\r\n/g, `
|
|
161
180
|
`).trim();
|
|
162
181
|
}
|
|
163
|
-
function
|
|
182
|
+
function q(e) {
|
|
164
183
|
return e.map((i) => {
|
|
165
184
|
switch (i.code) {
|
|
166
185
|
case "missing_source":
|
|
@@ -213,7 +232,7 @@ function v(e) {
|
|
|
213
232
|
}
|
|
214
233
|
}).filter((i) => !!i);
|
|
215
234
|
}
|
|
216
|
-
function
|
|
235
|
+
function S(e, i, n, c) {
|
|
217
236
|
if (!e || typeof e != "object") {
|
|
218
237
|
n.push(s("invalid_view", "Dashboard view must be an object.", i));
|
|
219
238
|
return;
|
|
@@ -229,7 +248,7 @@ function q(e, i, n, r) {
|
|
|
229
248
|
return;
|
|
230
249
|
}
|
|
231
250
|
if (e.presentation.kind === "text") {
|
|
232
|
-
t(e.text) ||
|
|
251
|
+
t(e.text) || c.push(
|
|
233
252
|
s(
|
|
234
253
|
"missing_text_content",
|
|
235
254
|
"Text views should include text content.",
|
|
@@ -249,20 +268,20 @@ function q(e, i, n, r) {
|
|
|
249
268
|
return;
|
|
250
269
|
}
|
|
251
270
|
const u = g(e.analytics);
|
|
252
|
-
for (const
|
|
271
|
+
for (const d of u.errors)
|
|
253
272
|
n.push(
|
|
254
|
-
s(
|
|
273
|
+
s(d.code, d.message, `${i}.analytics${d.path ? `.${d.path}` : ""}`)
|
|
255
274
|
);
|
|
256
|
-
for (const
|
|
257
|
-
|
|
275
|
+
for (const d of u.warnings)
|
|
276
|
+
c.push(
|
|
258
277
|
s(
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
`${i}.analytics${
|
|
278
|
+
d.code,
|
|
279
|
+
d.message,
|
|
280
|
+
`${i}.analytics${d.path ? `.${d.path}` : ""}`
|
|
262
281
|
)
|
|
263
282
|
);
|
|
264
283
|
}
|
|
265
|
-
function
|
|
284
|
+
function x(e) {
|
|
266
285
|
const i = [], n = [];
|
|
267
286
|
if (!e || typeof e != "object")
|
|
268
287
|
return {
|
|
@@ -276,8 +295,8 @@ function S(e) {
|
|
|
276
295
|
warnings: n
|
|
277
296
|
};
|
|
278
297
|
e.version !== 1 && i.push(s("invalid_version", "Dashboard intent version must be 1.")), e.kind !== "dashboard" && i.push(s("invalid_kind", "Experience intent kind must be dashboard.")), t(e.title) || i.push(s("missing_title", "Dashboard intent needs a title.", "title"));
|
|
279
|
-
const
|
|
280
|
-
|
|
298
|
+
const c = Array.isArray(e.inputs) ? e.inputs : [], u = h(
|
|
299
|
+
c.filter(m).map((o) => o.id).filter((o) => typeof o == "string")
|
|
281
300
|
);
|
|
282
301
|
u && i.push(
|
|
283
302
|
s(
|
|
@@ -286,38 +305,38 @@ function S(e) {
|
|
|
286
305
|
"inputs"
|
|
287
306
|
)
|
|
288
307
|
);
|
|
289
|
-
for (const [
|
|
290
|
-
const l = `inputs.${
|
|
291
|
-
if (!
|
|
308
|
+
for (const [o, a] of c.entries()) {
|
|
309
|
+
const l = `inputs.${o}`;
|
|
310
|
+
if (!m(a)) {
|
|
292
311
|
i.push(s("invalid_input", "Dashboard input must be an object.", l));
|
|
293
312
|
continue;
|
|
294
313
|
}
|
|
295
314
|
t(a.id) || i.push(s("missing_input_id", "Input needs an id.", `${l}.id`)), t(a.label) || i.push(
|
|
296
315
|
s("missing_input_label", "Input needs a label.", `${l}.label`)
|
|
297
|
-
),
|
|
316
|
+
), !a.field || !t(a.field.name) ? i.push(
|
|
298
317
|
s("missing_input_field", "Input needs a field.", `${l}.field`)
|
|
299
|
-
), a.source &&
|
|
318
|
+
) : f(a.field, `${l}.field`, i), a.source && _(a.source, `${l}.source`, i);
|
|
300
319
|
}
|
|
301
|
-
const
|
|
302
|
-
|
|
320
|
+
const d = Array.isArray(e.sections) ? e.sections : [];
|
|
321
|
+
d.length === 0 && i.push(
|
|
303
322
|
s(
|
|
304
323
|
"missing_sections",
|
|
305
324
|
"Dashboard intent needs at least one section.",
|
|
306
325
|
"sections"
|
|
307
326
|
)
|
|
308
327
|
);
|
|
309
|
-
const
|
|
310
|
-
(
|
|
311
|
-
),
|
|
312
|
-
|
|
328
|
+
const p = d.flatMap(
|
|
329
|
+
(o) => o && typeof o == "object" && Array.isArray(o.views) ? o.views.filter(m).map((a) => a.id).filter((a) => !!a) : []
|
|
330
|
+
), r = h(p);
|
|
331
|
+
r && i.push(
|
|
313
332
|
s(
|
|
314
333
|
"duplicate_view_id",
|
|
315
|
-
`Duplicate dashboard view id: ${
|
|
334
|
+
`Duplicate dashboard view id: ${r}.`,
|
|
316
335
|
"sections"
|
|
317
336
|
)
|
|
318
337
|
);
|
|
319
|
-
for (const [
|
|
320
|
-
const l = `sections.${
|
|
338
|
+
for (const [o, a] of d.entries()) {
|
|
339
|
+
const l = `sections.${o}`;
|
|
321
340
|
if (!a || typeof a != "object") {
|
|
322
341
|
i.push(
|
|
323
342
|
s("invalid_section", "Dashboard section must be an object.", l)
|
|
@@ -336,10 +355,10 @@ function S(e) {
|
|
|
336
355
|
);
|
|
337
356
|
continue;
|
|
338
357
|
}
|
|
339
|
-
for (const [
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
`${l}.views.${
|
|
358
|
+
for (const [b, v] of a.views.entries())
|
|
359
|
+
S(
|
|
360
|
+
v,
|
|
361
|
+
`${l}.views.${b}`,
|
|
343
362
|
i,
|
|
344
363
|
n
|
|
345
364
|
);
|
|
@@ -347,6 +366,6 @@ function S(e) {
|
|
|
347
366
|
return { ok: i.length === 0, errors: i, warnings: n };
|
|
348
367
|
}
|
|
349
368
|
export {
|
|
350
|
-
|
|
369
|
+
x as a,
|
|
351
370
|
g as v
|
|
352
371
|
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function s(e,i,n){return n?{code:e,message:i,path:n}:{code:e,message:i}}function h(e){const i=new Set;for(const n of e){if(i.has(n))return n;i.add(n)}return null}function t(e){return typeof e=="string"&&e.trim().length>0}function m(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function _(e,i,n,c={}){if(!e||typeof e!="object"){n.push(s("missing_source","Analytics intent needs a source.",i));return}if(e.kind==="semantic"){t(e.domainId)||n.push(s("missing_semantic_domain","Semantic source needs a domainId.",`${i}.domainId`)),t(e.datasetName)||n.push(s("missing_dataset_name","Semantic source needs a datasetName.",`${i}.datasetName`));return}if(e.kind==="physical"){t(e.connectionId)||n.push(s("missing_connection_id","Physical source needs a connectionId.",`${i}.connectionId`)),t(e.tableName)||n.push(s("missing_table_name","Physical source needs a tableName.",`${i}.tableName`));return}if(e.kind==="sql"){t(e.connectionId)||n.push(s("missing_connection_id","SQL source needs a connectionId.",`${i}.connectionId`)),c.requireSqlText!==!1&&!t(e.sql)&&n.push(s("missing_sql","SQL source needs SQL text.",`${i}.sql`));return}n.push(s("invalid_source_kind","Source kind is not supported.",i))}function f(e,i,n,c={}){if(!e||!m(e)){c.required&&n.push(s("missing_field_ref","Field reference needs a name.",i));return}t(e.name)||n.push(s("missing_field_ref","Field reference needs a name.",`${i}.name`)),e.source!==void 0&&_(e.source,`${i}.source`,n,{requireSqlText:!1})}function b(e){var c,u,d,p;const i=[],n=[];return!e||typeof e!="object"?{ok:!1,errors:[s("invalid_analytics_intent","Analytics intent must be a structured object.")],warnings:n,repairHints:[{code:"invalid_analytics_intent",recommendedNextStep:"Send one structured analytics intent object with kind, source, and required fields."}]}:(e.version!==void 0&&e.version!==1&&i.push(s("invalid_version","Analytics intent version must be 1.","version")),_(e.source,"source",i,{requireSqlText:e.kind!=="sql"||!t(e.sql)}),e.kind==="metric"?(t(e.metric)||i.push(s("missing_metric","Metric intent needs a metric.","metric")),e.metrics!==void 0&&!Array.isArray(e.metrics)?i.push(s("invalid_metric_list","Metric intent metrics must be an array of metric names.","metrics")):Array.isArray(e.metrics)&&e.metrics.some(r=>!t(r))&&i.push(s("invalid_metric_list","Metric intent metrics must be an array of non-empty metric names.","metrics")),e.dimensions!==void 0&&!Array.isArray(e.dimensions)?i.push(s("invalid_metric_dimensions","Metric intent dimensions must be an array of field references.","dimensions")):Array.isArray(e.dimensions)&&e.dimensions.some(r=>!m(r)||!t(r.name))&&i.push(s("invalid_metric_dimensions","Metric intent dimensions must be an array of field references with names.","dimensions")),e.dateField!==void 0&&f(e.dateField,"dateField",i),Array.isArray(e.dimensions)&&e.dimensions.forEach((r,o)=>{f(r,`dimensions.${o}`,i)})):e.kind==="records"?(!Array.isArray(e.fields)||e.fields.length===0?i.push(s("missing_record_fields","Records intent needs at least one field.","fields")):e.fields.some(r=>!m(r)||!t(r.name))&&i.push(s("invalid_record_fields","Records intent fields must be field references with names.","fields")),Array.isArray(e.fields)&&e.fields.forEach((r,o)=>{f(r,`fields.${o}`,i)}),e.dateField!==void 0&&f(e.dateField,"dateField",i)):e.kind==="inputOptions"?((!e.field||!t(e.field.name))&&i.push(s("missing_input_options_field","Input options intent needs a field.","field")),f(e.field,"field",i,{required:!0})):e.kind==="sql"?(((c=e.source)==null?void 0:c.kind)!=="sql"&&((u=e.source)==null?void 0:u.kind)!=="physical"&&i.push(s("invalid_sql_source","SQL analytics intent must use a SQL or physical source.","source")),t(e.sql)&&((d=e.source)==null?void 0:d.kind)==="sql"&&t(e.source.sql)&&y(e.sql)!==y(e.source.sql)&&i.push(s("conflicting_sql","SQL analytics intent cannot define different SQL text in source.sql and sql.","sql")),!t(e.sql)&&!(((p=e.source)==null?void 0:p.kind)==="sql"&&t(e.source.sql))&&i.push(s("missing_sql","SQL analytics intent needs SQL text.","sql")),Array.isArray(e.fields)&&e.fields.forEach((r,o)=>{f(r,`fields.${o}`,i)})):i.push(s("invalid_analytics_kind","Analytics kind is not supported.","kind")),{ok:i.length===0,errors:i,warnings:n,repairHints:q(i)})}function y(e){return e.replace(/\r\n/g,`
|
|
2
|
+
`).trim()}function q(e){return e.map(i=>{switch(i.code){case"missing_source":return{code:i.code,fieldRole:"source",recommendedNextStep:"Provide a semantic, physical, or SQL source before executing analytics."};case"missing_metric":return{code:i.code,fieldRole:"metric",recommendedNextStep:"Choose one exact metric from the grounded schema candidates."};case"missing_record_fields":return{code:i.code,fieldRole:"dimension",recommendedNextStep:"Provide at least one field for the records intent."};case"missing_input_options_field":return{code:i.code,fieldRole:"input",recommendedNextStep:"Provide the exact field whose option values should be listed."};case"missing_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Provide bounded read-only SQL with an explicit outer LIMIT."};case"conflicting_sql":return{code:i.code,fieldRole:"sql",recommendedNextStep:"Use one canonical SQL text location for the intent; prefer top-level sql."};case"missing_semantic_domain":case"missing_dataset_name":case"missing_connection_id":case"missing_table_name":return{code:i.code,fieldRole:"source",recommendedNextStep:"Use grounded catalog metadata to fill the missing source reference."};default:return}}).filter(i=>!!i)}function S(e,i,n,c){if(!e||typeof e!="object"){n.push(s("invalid_view","Dashboard view must be an object.",i));return}if(t(e.title)||n.push(s("missing_view_title","Dashboard view needs a title.",i)),!e.presentation||typeof e.presentation!="object"){n.push(s("missing_presentation","Dashboard view needs a presentation.",`${i}.presentation`));return}if(e.presentation.kind==="text"){t(e.text)||c.push(s("missing_text_content","Text views should include text content.",`${i}.text`));return}if(!e.analytics){n.push(s("missing_view_analytics","Non-text dashboard views need analytics intent.",`${i}.analytics`));return}const u=b(e.analytics);for(const d of u.errors)n.push(s(d.code,d.message,`${i}.analytics${d.path?`.${d.path}`:""}`));for(const d of u.warnings)c.push(s(d.code,d.message,`${i}.analytics${d.path?`.${d.path}`:""}`))}function A(e){const i=[],n=[];if(!e||typeof e!="object")return{ok:!1,errors:[s("invalid_dashboard_intent","Dashboard intent must be a structured object.")],warnings:n};e.version!==1&&i.push(s("invalid_version","Dashboard intent version must be 1.")),e.kind!=="dashboard"&&i.push(s("invalid_kind","Experience intent kind must be dashboard.")),t(e.title)||i.push(s("missing_title","Dashboard intent needs a title.","title"));const c=Array.isArray(e.inputs)?e.inputs:[],u=h(c.filter(m).map(o=>o.id).filter(o=>typeof o=="string"));u&&i.push(s("duplicate_input_id",`Duplicate input id: ${u}.`,"inputs"));for(const[o,a]of c.entries()){const l=`inputs.${o}`;if(!m(a)){i.push(s("invalid_input","Dashboard input must be an object.",l));continue}t(a.id)||i.push(s("missing_input_id","Input needs an id.",`${l}.id`)),t(a.label)||i.push(s("missing_input_label","Input needs a label.",`${l}.label`)),!a.field||!t(a.field.name)?i.push(s("missing_input_field","Input needs a field.",`${l}.field`)):f(a.field,`${l}.field`,i),a.source&&_(a.source,`${l}.source`,i)}const d=Array.isArray(e.sections)?e.sections:[];d.length===0&&i.push(s("missing_sections","Dashboard intent needs at least one section.","sections"));const p=d.flatMap(o=>o&&typeof o=="object"&&Array.isArray(o.views)?o.views.filter(m).map(a=>a.id).filter(a=>!!a):[]),r=h(p);r&&i.push(s("duplicate_view_id",`Duplicate dashboard view id: ${r}.`,"sections"));for(const[o,a]of d.entries()){const l=`sections.${o}`;if(!a||typeof a!="object"){i.push(s("invalid_section","Dashboard section must be an object.",l));continue}if(t(a.title)||i.push(s("missing_section_title","Dashboard section needs a title.",l)),!Array.isArray(a.views)||a.views.length===0){i.push(s("missing_section_views","Dashboard section needs at least one view.",`${l}.views`));continue}for(const[v,g]of a.views.entries())S(g,`${l}.views.${v}`,i,n)}return{ok:i.length===0,errors:i,warnings:n}}exports.validateSemaphorAnalyticsIntent=b;exports.validateSemaphorDashboardIntent=A;
|
package/dist/dashboard/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/index-BdjXTQt4.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
|
package/dist/dashboard/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("../chunks/validators-DJUMR5An.js"),W=["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 K(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 m=Array.isArray(a.filterInputs)?a.filterInputs:[],y=m.map(u=>u.id),g=$(y);g&&t.push(f("duplicate_input_id",`Duplicate dashboard input id: ${g}.`));const o=m.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 U(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 ne={lg:48,md:36,sm:24,xs:12,xxs:6};function re(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 ie(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 se(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 de(e,t,a,n){return a==="xxs"||a==="xs"||a==="sm"||a==="md"||t===1||t%2===1&&e===0?n:n/2}function oe(e){const{item:t,band:a,index:n,bandCount:i,breakpoint:r,columns:d}=e;return a==="kpi"?{...t,band:a,w:se(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:de(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)=>oe({item:i,band:t,index:r,bandCount:e.length,breakpoint:a,columns:n}))}function N(e){const t=ie(e);return Object.fromEntries(W.map(a=>{const n=ne[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,re(i,n)]}))}function le(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 ce(e){return!!(e&&typeof e=="object"&&!Array.isArray(e))}function ue(e){return ce(e)&&typeof e.filterId=="string"&&typeof e.operation=="string"&&Array.isArray(e.values)}function fe(e){return e.filter(t=>typeof t=="string"||typeof t=="number")}function pe(e){return e.filter(t=>t instanceof Date||typeof t=="string")}function R(e,t){if(t===void 0)return;const a=le(e.dataType),n=e.operation||"in";if(ue(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"?pe(i):fe(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 me(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 be(e){const t={};return{inputs:(e.filterInputs||[]).map((n,i)=>{const r=R(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 ge(e){var y,g;const t=K(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=Ie(e.dashboard),n=[...t.warnings],i=[],r=new Map(e.cardArtifacts.map(s=>[s.planCardId,s])),d=ye(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(C("generated_card_limit_reached",`MVP AI refinement is capped at ${S} cards.`,s.card.id));break}const m=r.get(s.card.id);if(!m){i.push(C("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:[m.card],activeCardId:m.card.id};d.frames.push(y),ve(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),Ce(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(C("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(C("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 m=0;m<s.cardIds.length;m+=1){const y=s.cardIds[m],g=P(a,y);g&&c.set(g.frame.id,m)}J(d,c);break}case"reuseCalculatedField":n.push(C("reused_calculated_field",`Calculated field "${s.fieldId}" is reused by reference.`));break;case"unsupported":i.push(C("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 Y(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 xe(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 v(e){return!!(e&&typeof e=="object")}function E(e){return v(e)&&(e.kind==="semantic"||e.kind==="physical"||e.kind==="sql")}function Q(e){return Array.isArray(e.inputs)?e.inputs.filter(t=>v(t)&&typeof t.id=="string"):[]}function Z(e){return Array.isArray(e.sections)?e.sections.filter(t=>v(t)):[]}function ee(e){return Array.isArray(e.views)?e.views.filter(t=>v(t)):[]}function Ae(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 Fe(e){return(e==null?void 0:e.source)||null}function te(e){const t=[];for(const a of Q(e))E(a.source)&&t.push(a.source);for(const a of Z(e))for(const n of ee(a)){const i=Fe(n.analytics);E(i)&&t.push(i)}return t}function De(e,t){const a=new Map;for(const i of te(e))a.set(xe(i),i);const n=[...a.values()].map(Ae).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 Se(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 Te(e){const t=Array.isArray(e.metrics)?e.metrics.filter(a=>typeof a=="string"&&a.trim().length>0):[];return Array.from(new Set([e.metric,...t].filter(a=>typeof a=="string"&&a.trim().length>0)))}function $e(e){return v(e)&&typeof e.name=="string"&&e.name.trim().length>0}function Ne(e){if(!Array.isArray(e.dimensions))return;const t=e.dimensions.filter($e).map(a=>a.name);return t.length?t:void 0}function H(e){return e==="hour"?"day":e}function Me(e){var t,a;if(e){if(e.kind==="metric")return{metric:e.metric,metrics:Te(e),dateField:(t=e.dateField)==null?void 0:t.name,timeGrain:H(e.timeGrain),dimensions:Ne(e),limit:e.limit};if(e.kind==="records")return{metrics:e.measures,dateField:(a=e.dateField)==null?void 0:a.name,timeGrain:H(e.timeGrain),dimensions:Se(e),limit:e.limit}}}function Pe(e){return e&&G.validateSemaphorAnalyticsIntent(e).ok?e:void 0}function Ve(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 Re(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 qe(e){switch(e){case"not_in":return"not in";case"contains":return"like";default:return e||"in"}}function Be(e){return v(e.field)?e.field.dataType==="datetime"?"date":e.field.dataType||"string":"string"}function Oe(e){if(!(!e||e.kind!=="physical"))return[e.databaseName,e.schemaName,e.tableName].filter(Boolean).join(".")}function Le(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(!v(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-${Y(D(e.id,e.field.name),n)}`,variableName:e.id,connectionId:d,title:e.label,column:e.field.name,dataType:Be(e),qualifiedTableName:Oe(r),sql:"",operation:qe(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:R(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 ze(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 je(e){var _,x,u;const t=[],a=G.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=Z(e),i=Q(e),r=De(e,t),d=te(e)[0],l=[],s=new Map,c=new Map,m=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}`,q=w.id||D(A,`section-${p+1}`);c.set(q,[]);for(const[B,h]of ee(w).entries()){const O=Ve(h),M=D(h.id||`${A}-${h.title||`View ${B+1}`}`,`card-${p+1}-${B+1}`);if(!O){t.push(I("unsupported_presentation",`Dashboard presentation "${((_=h.presentation)==null?void 0:_.kind)||"unknown"}" is not supported by the dashboard authoring adapter.`,`card-${M}`));continue}if(((x=h.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=Y(M,y),T=`card-${L}`;h.id&&s.set(h.id,T),(u=c.get(q))==null||u.push(T);const ae=h.analytics&&"inputs"in h.analytics?h.analytics.inputs:void 0;for(const z of ae||[]){const j=m.get(z.inputId)||[];j.push(T),m.set(z.inputId,j)}l.push({id:T,frameId:`frame-${L}`,title:h.title,description:h.description,type:O,role:Re(h),priority:o,section:A,query:Me(h.analytics),analyticsIntent:Pe(h.analytics),text:h.text}),o+=1}}const b=i.map(p=>{const w=ze({protocolScope:p.scope,inputLabel:p.label,allCardIds:l.map(A=>A.id),boundCardIds:m.get(p.id)||[],viewIdToCardId:s,sectionIdToCardIds:c,warnings:t});return w===null?null:Le(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=W;exports.DASHBOARD_AUTHORING_MAX_GENERATED_CARDS=S;exports.applyDashboardChangePlan=ke;exports.compileDashboardFromPlan=ge;exports.compileResponsiveDashboardLayouts=N;exports.dashboardPlanFromSemaphorDashboardIntent=je;exports.validateDashboardChangePlan=U;exports.validateDashboardPlan=K;
|
|
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;
|