react-semaphor 0.1.386 → 0.1.387
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/DATA_APP_SDK.md +67 -0
- package/dist/data-app-sdk/index.cjs +5 -5
- package/dist/data-app-sdk/index.js +1167 -1122
- package/dist/types/data-app-sdk.d.ts +6 -0
- package/package.json +1 -1
- package/src/data-app-sdk/README.md +67 -0
package/DATA_APP_SDK.md
CHANGED
|
@@ -8,6 +8,7 @@ these patterns over inspecting `dist/types` or SDK implementation files.
|
|
|
8
8
|
```tsx
|
|
9
9
|
import {
|
|
10
10
|
SemaphorDataAppProvider,
|
|
11
|
+
SemaphorDevtools,
|
|
11
12
|
semaphor,
|
|
12
13
|
useClearInvalidSemaphorInputValue,
|
|
13
14
|
useSemaphorInput,
|
|
@@ -23,6 +24,47 @@ import type {
|
|
|
23
24
|
} from "react-semaphor/data-app-sdk";
|
|
24
25
|
```
|
|
25
26
|
|
|
27
|
+
## Runtime Provider And DevTools
|
|
28
|
+
|
|
29
|
+
Generated local/dev apps should mount one root DevTools instance and enable the
|
|
30
|
+
debug bridge only outside production embeds.
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
const runtimeToken = import.meta.env.VITE_SEMAPHOR_PROJECT_TOKEN;
|
|
34
|
+
const enableDevtools =
|
|
35
|
+
import.meta.env.DEV ||
|
|
36
|
+
(typeof window !== "undefined" && window.location.hostname === "localhost");
|
|
37
|
+
|
|
38
|
+
export function Root() {
|
|
39
|
+
return (
|
|
40
|
+
<SemaphorDataAppProvider
|
|
41
|
+
token={runtimeToken}
|
|
42
|
+
debug={enableDevtools ? { exposeWindowBridge: true } : false}
|
|
43
|
+
>
|
|
44
|
+
<App />
|
|
45
|
+
<SemaphorDevtools
|
|
46
|
+
initialIsOpen={false}
|
|
47
|
+
buttonPosition="bottom-right"
|
|
48
|
+
panelPosition="right"
|
|
49
|
+
/>
|
|
50
|
+
</SemaphorDataAppProvider>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Add hook-level debug source hints when they are cheap and non-repetitive:
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
const result = useSemaphorQuery(revenueBySegment, {
|
|
59
|
+
debug: {
|
|
60
|
+
sourceHint: {
|
|
61
|
+
file: "src/views/RevenueBySegment.tsx",
|
|
62
|
+
component: "RevenueBySegment",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
26
68
|
## Source And Fields
|
|
27
69
|
|
|
28
70
|
```tsx
|
|
@@ -140,12 +182,37 @@ function SegmentFilter() {
|
|
|
140
182
|
});
|
|
141
183
|
|
|
142
184
|
useClearInvalidSemaphorInputValue(segmentHandle, optionsResult);
|
|
185
|
+
|
|
186
|
+
const selectedValue = Array.isArray(segmentHandle.value)
|
|
187
|
+
? String(segmentHandle.value[0] ?? "")
|
|
188
|
+
: "";
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<select
|
|
192
|
+
value={selectedValue}
|
|
193
|
+
onChange={(event) => {
|
|
194
|
+
const nextValue = event.target.value || null;
|
|
195
|
+
segmentHandle.setValue(nextValue ? [nextValue] : undefined);
|
|
196
|
+
}}
|
|
197
|
+
>
|
|
198
|
+
<option value="">All segments</option>
|
|
199
|
+
{(optionsResult.options ?? []).map((option) => (
|
|
200
|
+
<option key={String(option.value)} value={String(option.value)}>
|
|
201
|
+
{option.label ?? String(option.value)}
|
|
202
|
+
</option>
|
|
203
|
+
))}
|
|
204
|
+
</select>
|
|
205
|
+
);
|
|
143
206
|
}
|
|
144
207
|
```
|
|
145
208
|
|
|
146
209
|
Pass the full options query result to `useClearInvalidSemaphorInputValue`.
|
|
147
210
|
Do not pass only `optionsResult.options`, because idle/loading results can also
|
|
148
211
|
expose an empty options array.
|
|
212
|
+
For shadcn/Base UI style selects, type the change callback as accepting
|
|
213
|
+
`string | null` and call `handle.clear()` or `handle.setValue(undefined)` for
|
|
214
|
+
the empty state. For multi-selects and date ranges, narrow `handle.value` with
|
|
215
|
+
`Array.isArray(...)` before indexing or displaying it.
|
|
149
216
|
|
|
150
217
|
## Shared Inputs With Source-Specific Bindings
|
|
151
218
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../data-app-sdk-adapters/index.cjs"),s=require("react/jsx-runtime"),d=require("react"),re=require("../chunks/search-Dq1Mbb03.js"),Qe=require("../chunks/x-B_cx7LwM.js"),vt=require("../chunks/validators-lWo8m0Q7.js");require("../chunks/analyze-result-contract-CtXfp3nv.js");function Y(e,t,r={}){return{...r,name:e,role:t}}function xt(e){return e}function bt(e){return e}const St={source:{semantic(e){return{...e,kind:"semantic"}},sql(e){return{...e,kind:"sql"}}},field:{measure(e,t){return Y(e,"measure",t)},dimension(e,t){return Y(e,"dimension",t)},date(e,t){return Y(e,"date",t)},id(e,t){return Y(e,"id",t)}},filter(e){return{...e,kind:"filter"}},bindInput(e,t){return{toAnalyticsInput(){const[r]=S.toSemaphorInputSnapshots([e]),n=S.toSemaphorInputBinding({...t,inputId:t.inputId||r.inputId});return{...r,inputId:n.inputId,...n.kind?{kind:n.kind}:{},...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{},...n.relationshipHint?{relationshipHint:n.relationshipHint}:{}}}}},control(e){return{...e,kind:"control"}},sqlParam(e){return{...e,kind:"control",role:"sqlParam"}},derivedField(e){return{...e,kind:"derived_field",expressionLanguage:e.expressionLanguage||"semaphor_sql_template"}},metric(e){return{...e,queryKind:"metric"}},analysis(e){return{...e,queryKind:"analysis"}},records(e){return{...e,queryKind:"records"}},inputOptions(e){return{...e,queryKind:"inputOptions"}},sql(e){return{...e,queryKind:"sql"}},matrix(e){return{...e,queryKind:"matrix"}}},le=10,de=100,It=25,wt=500,Ue={enabled:!1,queries:[],getQuery:()=>{},getQueries:()=>[]},Se=d.createContext(null),Ie=d.createContext(null),we=d.createContext(void 0),$=[];function qt({debug:e,children:t}){const r=d.useMemo(()=>Sr(e),[e]),[n,i]=d.useReducer(cr,r,it),u=d.useRef(n),l=d.useId(),[p,c]=d.useState({open:!1});u.current=n,d.useEffect(()=>{i({type:"config",config:r})},[r]),d.useEffect(()=>{if(!n.enabled||!n.exposeWindowBridge||typeof window>"u")return;const x=yr(()=>u.current);return jt({ownerId:l,bridge:x}),()=>{At(l)}},[l,n.enabled,n.exposeWindowBridge]);const f=d.useMemo(()=>({state:n,dispatch:i}),[n]),h=d.useCallback(x=>{c({open:!0,focus:x})},[]),g=d.useCallback(()=>{c(x=>({...x,open:!1}))},[]),y=d.useCallback(x=>{c({open:!0,focus:x})},[]),m=d.useMemo(()=>({open:p.open,focus:p.focus,openDevtools:h,closeDevtools:g,focusTrace:y}),[g,y,h,p.focus,p.open]);return s.jsx(Se.Provider,{value:f,children:s.jsx(Ie.Provider,{value:m,children:t})})}function jt(e){const t=$.findIndex(r=>r.ownerId===e.ownerId);t>=0&&$.splice(t,1),$.push(e),Ge()}function At(e){const t=$.findIndex(r=>r.ownerId===e);t>=0&&$.splice(t,1),Ge()}function Ge(){if(typeof window>"u")return;const e=$[$.length-1];e?window.__SEMAPHOR_DEVTOOLS__=e.bridge:delete window.__SEMAPHOR_DEVTOOLS__}function Rt({id:e,title:t,children:r}){const n=d.useMemo(()=>({id:e,title:t}),[e,t]);return s.jsx(we.Provider,{value:n,children:r})}function Je({buttonPosition:e="bottom-right",initialIsOpen:t=!1,panelPosition:r="right",className:n,style:i}={}){const u=qe(),l=d.useContext(Ie),[p,c]=d.useState(""),[f,h]=d.useState(!1),g=d.useRef(null),y=d.useRef(null),m=l==null?void 0:l.openDevtools,x=l==null?void 0:l.closeDevtools,A=(l==null?void 0:l.open)===!0;d.useEffect(()=>{nt()},[]),d.useEffect(()=>{t&&u.enabled&&(m==null||m())},[t,u.enabled,m]),d.useEffect(()=>{if(!A||!x)return;const v=w=>{var R,k;const C=w.target;C instanceof Node&&((R=g.current)!=null&&R.contains(C)||(k=y.current)!=null&&k.contains(C)||x())};return document.addEventListener("pointerdown",v,!0),document.addEventListener("mousedown",v,!0),document.addEventListener("click",v,!0),()=>{document.removeEventListener("pointerdown",v,!0),document.removeEventListener("mousedown",v,!0),document.removeEventListener("click",v,!0)}},[x,A]);const o=d.useMemo(()=>_t(u.queries),[u.queries]),b=d.useMemo(()=>Ft(u.queries,p),[u.queries,p]),T=d.useMemo(()=>Nt(b),[b]),E=d.useMemo(()=>Ye(b,l==null?void 0:l.focus)||b[0],[b,l==null?void 0:l.focus]);return!u.enabled||!l?null:s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:g,type:"button","aria-label":"Open Semaphor DevTools",title:"Open Semaphor DevTools",className:n?`${O} ${n}`:O,style:{...a.launcher,...ir(e),...sr(o.severity),...i},onClick:()=>l.openDevtools(),children:[s.jsx(kt,{}),s.jsx("span",{style:a.launcherText,children:o.total}),o.issueCount>0?s.jsx("span",{style:a.launcherIssueCount,children:o.issueCount}):null]}),l.open?s.jsxs("div",{ref:y,role:"dialog","aria-label":"Semaphor DevTools","aria-modal":"false",className:O,style:{...a.panel,...or(r),...f?a.panelFullscreen:null},children:[s.jsxs("div",{style:a.panelHeader,children:[s.jsxs("div",{style:a.panelTitleBlock,children:[s.jsx("div",{style:a.panelTitle,children:"Semaphor DevTools"}),s.jsxs("div",{style:a.panelSubtitle,children:[o.total," queries · ",o.loading," loading ·"," ",o.failed," failed"]})]}),s.jsxs("div",{style:a.panelActions,children:[s.jsx("button",{type:"button","aria-label":f?"Exit fullscreen Semaphor DevTools":"Enter fullscreen Semaphor DevTools",title:f?"Exit fullscreen Semaphor DevTools":"Enter fullscreen Semaphor DevTools",style:a.iconButton,onClick:()=>h(v=>!v),children:f?s.jsx(re.Minimize2,{size:15}):s.jsx(re.Maximize2,{size:15})}),s.jsx("button",{type:"button","aria-label":"Close Semaphor DevTools",style:a.iconButton,onClick:l.closeDevtools,children:s.jsx(Qe.X,{size:15})})]})]}),s.jsxs("label",{style:a.searchBox,children:[s.jsx(re.Search,{size:14}),s.jsx("input",{"aria-label":"Search Semaphor traces",value:p,onChange:v=>c(v.currentTarget.value),placeholder:"Search traces",style:a.searchInput})]}),s.jsxs("div",{style:{...a.panelBody,...ar(r)},children:[s.jsx("div",{style:{...a.queryList,...ur()},"aria-label":"Registered queries",children:b.length?T.map(v=>s.jsxs("div",{style:a.queryGroup,children:[s.jsxs("div",{style:a.queryGroupHeader,children:[s.jsx("span",{children:v.title}),s.jsx("span",{style:a.queryGroupCount,children:v.traces.length})]}),v.traces.length?v.traces.map(w=>{var D;const C=zt(w,E),R=je(w),k=Xe(w.queryKind),I=oe(w);return s.jsxs("button",{type:"button",title:`${R} · ${k} · ${I}`,style:{...a.queryListItem,...C?a.queryListItemSelected:null},onClick:()=>l.focusTrace({traceId:w.traceId,queryId:w.queryId,viewId:w.viewId}),children:[s.jsxs("span",{style:a.queryListItemHeader,children:[s.jsx(Dt,{status:(D=w.latestAttempt)==null?void 0:D.status}),s.jsx("span",{style:a.queryListTitle,title:R,children:R}),s.jsx("span",{style:a.queryListKindChip,children:k})]}),s.jsx("span",{className:`${O}-source`,style:a.queryListSource,title:I,children:I})]},xe(w))}):s.jsx("div",{style:a.queryGroupEmpty,children:"No input traces"})]},v.title)):s.jsx("div",{style:a.emptyState,children:"No matching traces"})}),s.jsx(Tt,{trace:E})]})]}):null]})}function Et({queryId:e,viewId:t,label:r,className:n,style:i}={}){var g,y;const u=qe(),l=d.useContext(Ie),p=d.useContext(we);d.useEffect(()=>{nt()},[]);const c=t||(p==null?void 0:p.id),f=d.useMemo(()=>Wt(u.queries,{queryId:e,viewId:c}),[u.queries,e,c]);if(!u.enabled||!l||!f)return null;const h=r||`Inspect ${je(f)}`;return s.jsxs("button",{type:"button","aria-label":h,title:h,className:n?`${O} ${n}`:O,style:{...a.inspectButton,...lr((g=f.latestAttempt)==null?void 0:g.status),...i},onClick:()=>l.openDevtools({traceId:f.traceId,queryId:f.queryId,viewId:f.viewId}),children:[s.jsx(re.Eye,{size:13}),s.jsx("span",{style:a.inspectButtonText,children:((y=f.latestAttempt)==null?void 0:y.status)||"idle"})]})}function qe(){const e=d.useContext(Se);return!e||!e.state.enabled?Ue:ie(e.state)}function Ct({spec:e,queryKind:t,queryKey:r,intent:n,activeInputs:i,debug:u}){const l=d.useContext(Se),p=d.useContext(we),c=!!(l!=null&&l.state.enabled),f=l==null?void 0:l.dispatch,h=Ir(e),g=e.label,y=d.useMemo(()=>JSON.stringify(e),[e]),m=d.useMemo(()=>JSON.stringify(i||[]),[i]),x=d.useMemo(()=>JSON.stringify(n||null),[n]),A=d.useRef(e),o=d.useRef(y),b=d.useRef(n),T=d.useRef(x),E=d.useRef(i),v=d.useRef(m);o.current!==y&&(o.current=y,A.current=e),T.current!==x&&(T.current=x,b.current=n),v.current!==m&&(v.current=m,E.current=i);const w=A.current,C=b.current,R=E.current,k=d.useId(),I=d.useMemo(()=>h||`query_${lt(r)}`,[r,h]),D=(u==null?void 0:u.viewId)||(p==null?void 0:p.id),Ce=(u==null?void 0:u.title)||(p==null?void 0:p.title),gt=JSON.stringify(_e(u)||[]),ke=d.useMemo(()=>_e(u),[gt]),K=d.useMemo(()=>[D||"unscoped-view",I,k].join("::"),[I,k,D]),Te=d.useMemo(()=>({traceKey:K,spec:w,queryId:I,queryLabel:g,queryKind:t,builder:wr(t),viewId:D,viewTitle:Ce,sourceHints:ke,intent:C,activeInputs:R,clientWarnings:h?[]:["Query spec is missing an explicit id; using an opaque internal id."]}),[I,t,h,g,w,R,C,ke,K,D,Ce]);d.useEffect(()=>{if(!(!c||!f))return f({type:"register",descriptor:Te}),()=>{f({type:"unregister",traceKey:K})}},[Te,f,c,K]);const L=d.useCallback((j,_)=>{!c||!f||f({type:"event",traceKey:K,event:j,latestAttempt:_})},[f,c,K]),De=d.useCallback(()=>{L({type:"query_started",queryId:I,at:te()},{status:"loading"})},[L,I]),Oe=d.useCallback((j,_)=>{const V=Ve(j),H=Tr(j),yt=Dr(j);L({type:"query_succeeded",queryId:I,requestId:V,at:te(),rowCount:H,durationMs:_},{requestId:V,status:"success",durationMs:_,rowCount:H,columnCount:yt,executionResult:ze(j)})},[L,I]),J=d.useCallback((j,_)=>{const V=Ve(j),H=j instanceof Error?j.message:String(j);L({type:"query_failed",queryId:I,requestId:V,at:te(),errorMessage:H},{requestId:V,status:"error",durationMs:_,errorMessage:H,executionResult:ze(j)})},[L,I]),Le=d.useCallback(j=>{L({type:"query_ignored_stale",queryId:I,at:te(),reason:j})},[L,I]),Be=d.useCallback(j=>{J(j,0)},[J]),ue=c?l==null?void 0:l.state.entries[K]:void 0;return d.useMemo(()=>({enabled:c,queryId:I,trace:ue?ne(ue):void 0,start:De,success:Oe,failure:J,ignored:Le,validationFailure:Be}),[c,J,Le,I,De,Oe,ue,Be])}function kt(){return s.jsx("span",{style:a.logoMark,"aria-hidden":!0,children:s.jsxs("svg",{viewBox:"0 0 100 100",fill:"none",width:"16",height:"16",focusable:"false",children:[s.jsx("rect",{x:"20",y:"15",width:"60",height:"12",rx:"6",fill:"currentColor"}),s.jsx("rect",{x:"20",y:"35",width:"40",height:"12",rx:"6",fill:"currentColor"}),s.jsx("rect",{x:"40",y:"55",width:"40",height:"12",rx:"6",fill:"currentColor"}),s.jsx("rect",{x:"20",y:"75",width:"60",height:"12",rx:"6",fill:"currentColor"})]})})}function Tt({trace:e}){var A,o,b,T,E;if(!e)return s.jsx("div",{style:a.detailsPane,children:s.jsx("div",{style:a.emptyState,children:"No traces registered yet"})});const t=e.latestAttempt,r=t==null?void 0:t.executionResult,n=ce((A=r==null?void 0:r.validation)==null?void 0:A.warnings),i=ce((o=r==null?void 0:r.validation)==null?void 0:o.errors),u=ce((b=r==null?void 0:r.coverage)==null?void 0:b.missingObligations),l=r==null?void 0:r.compiledQuery,p=nr(r),c=((T=e.server)==null?void 0:T.compiledSql)||p.compiledSql,f=t!=null&&t.errorMessage?[t.errorMessage]:[],h=[...e.clientWarnings,...n,...i,...u],g=oe(e),y=e.viewId?`${e.viewId} - ${e.queryId}`:e.queryId,m=e.inputsApplied.length>0,x=!!(l||c);return s.jsxs("div",{style:a.detailsPane,children:[s.jsxs("div",{style:a.detailsHeader,children:[s.jsxs("div",{style:a.detailsHeaderTopRow,children:[s.jsx("span",{"aria-hidden":!0,style:{...a.detailsHeaderStatusDot,...rt(t==null?void 0:t.status)}}),s.jsx("span",{style:a.detailsTitle,children:je(e)}),s.jsx("span",{style:a.detailsKindChip,children:Xe(e.queryKind)})]}),s.jsxs("div",{style:a.detailsCaption,children:[s.jsx("span",{style:{...a.detailsCaptionItem,...a.detailsCaptionItemMono},children:y}),s.jsxs("span",{style:a.detailsCaptionItem,children:[s.jsx("span",{style:a.detailsCaptionLabel,children:"Source"}),s.jsx("span",{style:a.detailsCaptionValue,children:g})]}),s.jsxs("span",{style:a.detailsCaptionItem,children:[s.jsx("span",{style:a.detailsCaptionLabel,children:"Rows"}),s.jsx("span",{style:a.detailsCaptionValue,children:Yt(t==null?void 0:t.rowCount)})]}),s.jsxs("span",{style:a.detailsCaptionItem,children:[s.jsx("span",{style:a.detailsCaptionLabel,children:"Duration"}),s.jsx("span",{style:a.detailsCaptionValue,children:Xt(t==null?void 0:t.durationMs)})]})]})]}),f.length?s.jsx(Ke,{tone:"error",title:"Error",items:f}):null,h.length?s.jsx(Ke,{tone:"warning",title:"Warnings",items:h}):null,s.jsx(Ot,{trace:e}),s.jsx(Lt,{trace:e}),(E=e.sourceHints)!=null&&E.length?s.jsx(Bt,{hints:e.sourceHints}):null,m?s.jsx(Mt,{inputs:e.inputsApplied}):null,x?s.jsx(U,{title:"Compiled query",children:s.jsx($t,{compiledQuery:l,compiledSql:c})}):null,s.jsx(U,{title:"Lifecycle events",children:e.recentEvents.length?s.jsx("div",{style:a.eventList,children:e.recentEvents.slice(-5).map((v,w)=>s.jsxs("div",{style:a.eventRow,children:[s.jsx("span",{style:a.eventType,children:er(v)}),s.jsx("span",{style:a.eventMeta,children:tr(v)})]},`${v.type}:${v.at}:${w}`))}):s.jsx("div",{style:a.mutedText,children:"No attempts recorded"})}),s.jsx(U,{title:"Raw trace JSON",children:s.jsx("pre",{style:a.codeBlock,children:Zt(e)})})]})}function Ke({tone:e,title:t,items:r}){const n=e==="error"?a.alertCardError:a.alertCardWarning;return s.jsxs("div",{style:{...a.alertCard,...n},children:[s.jsx("div",{style:a.alertCardTitle,children:t}),r.length>1?s.jsx("ul",{style:a.alertCardList,children:r.map((i,u)=>s.jsx("li",{children:i},`${e}-${u}`))}):s.jsx("div",{children:r[0]})]})}function Dt({status:e}){return s.jsx("span",{"aria-hidden":!0,style:{...a.statusDot,...rt(e)}})}function U({title:e,children:t}){return s.jsxs("details",{style:a.disclosure,children:[s.jsx("summary",{style:a.disclosureSummary,children:e}),s.jsx("div",{style:a.disclosureBody,children:t})]})}function Ot({trace:e}){var u;const t=(u=e.projectionFieldRefs)!=null&&u.length?e.projectionFieldRefs:e.fieldRefs,r=e.inputFieldRefs||[],n=Vt(t),i=Ht(e,n,t);return s.jsxs("div",{style:a.recipe,children:[s.jsx("div",{style:a.recipeSummary,children:i.map(l=>s.jsxs("div",{style:a.recipeSummaryRow,children:[s.jsx("span",{style:a.recipeSummaryLabel,children:l.label}),s.jsx("span",{style:a.recipeSummaryValue,title:l.value,children:l.value})]},l.label))}),s.jsx(M,{title:"Measures",fields:n.measures}),s.jsx(M,{title:"Time fields",fields:n.timeFields}),s.jsx(M,{title:"Dimensions",fields:n.dimensions,emptyText:"No dimensions selected"}),s.jsx(M,{title:"Identifiers",fields:n.identifiers}),s.jsx(M,{title:"Other fields",fields:n.other}),s.jsx(M,{title:"Input bindings",fields:r})]})}function Lt({trace:e}){return!e.sourceRefs.length&&!e.fieldRefs.length?null:s.jsx(U,{title:"Sources and field refs",children:s.jsxs("div",{style:a.traceLineage,children:[s.jsx(Kt,{sources:e.sourceRefs}),s.jsx(M,{title:"All field refs",fields:e.fieldRefs,emptyText:"No field refs captured"})]})})}function Bt({hints:e}){return s.jsx(U,{title:"Source hints",children:s.jsx("div",{style:a.recipeFieldList,children:e.map((t,r)=>{const n=Jt(t),i=t.component||t.exportName||n||"Source hint",u=[t.exportName&&t.exportName!==i?t.exportName:void 0,n,t.note].filter(Boolean).join(" · ");return s.jsxs("div",{style:a.recipeFieldRow,title:u||i,children:[s.jsx("span",{style:a.recipeFieldName,children:i}),u?s.jsx("span",{style:a.recipeFieldMeta,children:u}):null]},`${i}:${n}:${r}`)})})})}function Kt({sources:e}){return s.jsxs("div",{style:a.recipeGroup,children:[s.jsxs("div",{style:a.recipeGroupHeader,children:[s.jsx("span",{style:a.recipeGroupTitle,children:"Sources"}),s.jsx("span",{style:a.recipeGroupCount,children:e.length})]}),e.length?s.jsx("div",{style:a.recipeFieldList,children:e.map((t,r)=>s.jsxs("div",{style:a.recipeFieldRow,title:W(t),children:[s.jsx("span",{style:a.recipeFieldName,children:W(t)}),s.jsx("span",{style:a.recipeFieldMeta,children:t.kind})]},`${W(t)}:${r}`))}):s.jsx("div",{style:a.recipeEmptyText,children:"No sources captured"})]})}function M({title:e,fields:t,emptyText:r}){return!t.length&&!r?null:s.jsxs("div",{style:a.recipeGroup,children:[s.jsxs("div",{style:a.recipeGroupHeader,children:[s.jsx("span",{style:a.recipeGroupTitle,children:e}),s.jsx("span",{style:a.recipeGroupCount,children:t.length})]}),t.length?s.jsx("div",{style:a.recipeFieldList,children:t.map((n,i)=>{const u=et(n),l=n.dataType&&n.dataType!=="unknown"?n.dataType:void 0,p=n.source?W(n.source):void 0,c=[u,l,p].filter(Boolean).join(" · ");return s.jsxs("div",{style:a.recipeFieldRow,title:c,children:[s.jsx("span",{style:a.recipeFieldName,children:u}),s.jsxs("span",{style:a.recipeFieldMeta,children:[l?s.jsx("span",{children:l}):null,l&&p?s.jsx("span",{style:a.recipeFieldMetaDivider,children:" · "}):null,p?s.jsx("span",{children:p}):null]})]},`${Ae(n)}:${i}`)})}):s.jsx("div",{style:a.recipeEmptyText,children:r})]})}function Mt({inputs:e}){return s.jsxs("div",{style:a.inputsAppliedBlock,children:[s.jsxs("div",{style:a.inputsAppliedHeader,children:[s.jsx("span",{style:a.inputsAppliedTitle,children:"Inputs applied"}),s.jsx("span",{style:a.inputsAppliedCount,children:e.length})]}),s.jsx("div",{style:a.inputRecipeList,children:e.map(t=>{const r=tt(t);return s.jsxs("div",{style:a.inputRecipeRow,title:r.title,children:[s.jsxs("div",{style:a.inputRecipeHeader,children:[s.jsx("span",{style:a.inputRecipeId,title:t.inputId,children:t.inputId}),r.operator?s.jsx("span",{style:a.inputOperatorBadge,children:r.operator}):null,s.jsx("span",{style:a.inputValuePreview,title:r.value,children:r.value})]}),r.binding?s.jsx("div",{style:a.inputRecipeBinding,title:r.binding,children:r.binding}):null]},t.inputId)})})]})}function $t({compiledQuery:e,compiledSql:t}){return(e==null?void 0:e.kind)==="sql"?s.jsxs("div",{style:a.compiledQuery,children:[s.jsx(P,{label:"SQL",value:e.sql}),e.pythonCode?s.jsx(P,{label:"Python",value:e.pythonCode}):null,e.parameters?s.jsx(P,{label:"Parameters",value:be(e.parameters)}):null]}):t?s.jsx(P,{label:"SQL",value:t}):s.jsx(P,{label:"Compiled query",value:be(e)})}function P({label:e,value:t}){return s.jsxs("div",{style:a.codeBlockGroup,children:[s.jsx("div",{style:a.codeBlockLabel,children:e}),s.jsx("pre",{style:a.codeBlock,children:t})]})}function _t(e){const t=e.filter(i=>{var u;return((u=i.latestAttempt)==null?void 0:u.status)==="error"}).length,r=e.filter(i=>{var u;return((u=i.latestAttempt)==null?void 0:u.status)==="loading"}).length,n=e.filter(i=>{var u,l,p,c;return i.clientWarnings.length>0||!!((c=(p=(l=(u=i.latestAttempt)==null?void 0:u.executionResult)==null?void 0:l.validation)==null?void 0:p.warnings)!=null&&c.length)}).length;return{total:e.length,failed:t,loading:r,warningCount:n,issueCount:t+n,severity:t?"error":n?"warning":"ok"}}function Ft(e,t){const r=t.trim().toLowerCase();return r?e.filter(n=>[n.queryId,n.queryLabel,n.viewId,n.builder,n.queryKind,oe(n)].filter(Boolean).join(" ").toLowerCase().includes(r)):e}function Nt(e){const t=e.filter(i=>i.queryKind==="inputOptions"),r=new Set(t.map(xe));return[{title:"Cards",traces:e.filter(i=>!r.has(xe(i)))},{title:"Inputs",traces:t}]}function Ye(e,t){if(!(!(t!=null&&t.traceId)&&!(t!=null&&t.queryId)&&!(t!=null&&t.viewId)))return t.traceId?e.find(r=>r.traceId===t.traceId):e.find(r=>!(t.queryId&&r.queryId!==t.queryId||t.viewId&&r.viewId!==t.viewId))}function Wt(e,t){if(t.queryId)return Ye(e,t);if(!t.viewId)return;const r=e.filter(n=>n.viewId===t.viewId);return r.length===1?r[0]:void 0}function zt(e,t){return!!(e&&t&&e.traceId===t.traceId)}function xe(e){return e.traceId}function Xe(e){switch(e){case"metric":return"metric";case"records":return"records";case"matrix":return"matrix";case"analysis":return"analysis";case"inputOptions":return"inputs";case"sql":return"sql";default:return ae(e)}}function je(e){return e.queryLabel||e.viewId||e.queryId}function oe(e){const t=e.sourceRefs.map(W);return t.length?t.length===1?t[0]:`${t[0]} + ${t.length-1} more`:"No source"}function Vt(e){return e.reduce((t,r)=>(r.role==="measure"?t.measures.push(r):r.role==="date"?t.timeFields.push(r):r.role==="dimension"?t.dimensions.push(r):r.role==="id"?t.identifiers.push(r):t.other.push(r),t),{measures:[],timeFields:[],dimensions:[],identifiers:[],other:[]})}function Ht(e,t,r){const n=[{label:"Operation",value:Pt(e)}],i=Qt(e,t,r);i&&n.push(i);const u=Ut(t);u&&n.push({label:"Grouped by",value:u});const l=Gt(e.inputsApplied);return l&&n.push({label:"Filtered by",value:l}),n.push({label:"Source",value:oe(e)}),n}function Pt(e){var t,r;if(e.queryKind==="records"&&((t=e.projectionFieldRefs)!=null&&t.length)&&e.projectionFieldRefs.every(n=>n.role==="measure")&&((r=e.latestAttempt)==null?void 0:r.rowCount)===1)return"KPI query";switch(e.queryKind){case"metric":return"KPI query";case"records":return"Records query";case"matrix":return"Matrix query";case"analysis":return"Analysis query";case"inputOptions":return"Input options query";case"sql":return"SQL query";default:return ae(e.queryKind)}}function Qt(e,t,r){if(e.queryKind==="records")return{label:t.measures.length?"Computes":"Selects",value:Q(r)};if(e.queryKind==="inputOptions")return{label:"Options from",value:Q(r)};if(t.measures.length)return{label:"Computes",value:Q(t.measures)};if(r.length)return{label:"Uses",value:Q(r)};if(e.queryKind==="sql")return{label:"Inspect",value:"Open compiled query for SQL or Python."}}function Ut(e){const t=[...e.dimensions,...e.timeFields];return t.length?Q(t):void 0}function Gt(e){if(e.length)return Ze(e.map(t=>{const r=tt(t);return[t.inputId,r.operator,r.value].filter(Boolean).join(" ")}))}function Q(e){return Ze(e.map(et))}function Ze(e){const t=e.filter(Boolean);return t.length===0?"-":t.length===1?t[0]:t.length===2?`${t[0]} and ${t[1]}`:`${t.slice(0,-1).join(", ")}, and ${t[t.length-1]}`}function et(e){return[e.aggregate,e.label||e.name].filter(Boolean).join(" ")}function tt(e){var l,p,c;const t=e.valuePreview||"redacted",r=((l=e.fieldRef)==null?void 0:l.label)||((p=e.fieldRef)==null?void 0:p.name),n=(c=e.fieldRef)!=null&&c.source?W(e.fieldRef.source):void 0,i=[r?`on ${r}`:void 0,n].filter(Boolean).join(" · "),u=[e.inputId,e.operator,t,i].filter(Boolean).join(" - ");return{operator:e.operator,value:t,binding:i,title:u}}function W(e){return e.kind==="semantic"?e.datasetName||e.datasetId||e.domainId:e.kind==="physical"?[e.schemaName,e.tableName].filter(Boolean).join(".")||e.tableName:e.connectionId?`SQL ${e.connectionId}`:"SQL source"}function Jt(e){if(e.file)return e.line&&e.column?`${e.file}:${e.line}:${e.column}`:e.line?`${e.file}:${e.line}`:e.file}function Yt(e){return typeof e=="number"?e.toLocaleString():"-"}function Xt(e){return typeof e=="number"?`${Math.round(e)}ms`:"-"}function Zt(e){return be(e)}function be(e){return JSON.stringify(e,null,2)??"undefined"}function er(e){switch(e.type){case"query_started":return"Started";case"query_succeeded":return"Succeeded";case"query_failed":return"Failed";case"query_ignored_stale":return"Ignored stale";case"input_changed":return"Input changed";default:return rr(e)}}function tr(e){return[e.at,"durationMs"in e&&typeof e.durationMs=="number"?`${Math.round(e.durationMs)}ms`:void 0,"rowCount"in e&&typeof e.rowCount=="number"?`${e.rowCount} rows`:void 0,"reason"in e?e.reason:void 0,"errorMessage"in e?e.errorMessage:void 0].filter(Boolean).join(" - ")}function rr(e){throw new Error(`Unsupported Semaphor trace event: ${JSON.stringify(e)}`)}function ce(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function nr(e){const t=e==null?void 0:e.metadata,r=t&&typeof t=="object"&&!Array.isArray(t)&&"dataAppDebug"in t&&t.dataAppDebug&&typeof t.dataAppDebug=="object"&&!Array.isArray(t.dataAppDebug)?t.dataAppDebug:void 0;return{compiledSql:typeof(r==null?void 0:r.compiledSql)=="string"?r.compiledSql:void 0,queryHash:typeof(r==null?void 0:r.queryHash)=="string"?r.queryHash:void 0}}function ir(e){return e==="relative"?{position:"relative",top:"auto",right:"auto",bottom:"auto",left:"auto"}:{top:e.startsWith("top")?20:"auto",right:e.endsWith("right")?20:"auto",bottom:e.startsWith("bottom")?20:"auto",left:e.endsWith("left")?20:"auto"}}function sr(e){return e==="error"?{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"}:e==="warning"?{borderColor:"var(--sd-warning-border)",background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)"}:{borderColor:"var(--sd-success-border)",background:"var(--sd-success-bg)",color:"var(--sd-success-fg)"}}function or(e){return e==="right"?{top:16,right:16,bottom:16,left:"auto",width:"min(720px, calc(100vw - 32px))",height:"auto",borderRadius:6}:{top:"auto",right:16,bottom:16,left:16,width:"auto",height:"min(420px, 45vh)",borderRadius:6}}function ar(e){return e==="right"?{gridTemplateColumns:"minmax(210px, 280px) minmax(0, 1fr)"}:{gridTemplateColumns:"minmax(260px, 340px) minmax(0, 1fr)"}}function ur(e){return{borderRight:"1px solid var(--sd-border)",borderBottom:0}}function rt(e){return e==="error"?{background:"var(--sd-error-dot)"}:e==="success"?{background:"var(--sd-success-dot)"}:e==="loading"?{background:"var(--sd-loading-dot)"}:{background:"var(--sd-idle-dot)"}}function lr(e){return e==="error"?{borderColor:"var(--sd-error-border)",color:"var(--sd-error-fg)"}:e==="success"?{borderColor:"var(--sd-success-border)",color:"var(--sd-success-fg)"}:e==="loading"?{borderColor:"var(--sd-loading-border)",color:"var(--sd-loading-fg)"}:{borderColor:"var(--sd-border)",color:"var(--sd-fg-muted)"}}const Me="semaphor-devtools-stylesheet",O="semaphor-devtools",dr=`
|
|
2
|
-
.${
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("../data-app-sdk-adapters/index.cjs"),s=require("react/jsx-runtime"),d=require("react"),ne=require("../chunks/search-Dq1Mbb03.js"),Ge=require("../chunks/x-B_cx7LwM.js"),St=require("../chunks/validators-lWo8m0Q7.js");require("../chunks/analyze-result-contract-CtXfp3nv.js");function X(e,t,r={}){return{...r,name:e,role:t}}function It(e){return e}function wt(e){return e}const qt={source:{semantic(e){return{...e,kind:"semantic"}},sql(e){return{...e,kind:"sql"}}},field:{measure(e,t){return X(e,"measure",t)},dimension(e,t){return X(e,"dimension",t)},date(e,t){return X(e,"date",t)},id(e,t){return X(e,"id",t)}},filter(e){return{...e,kind:"filter"}},bindInput(e,t){return{toAnalyticsInput(){const[r]=S.toSemaphorInputSnapshots([e]),n=S.toSemaphorInputBinding({...t,inputId:t.inputId||r.inputId});return{...r,inputId:n.inputId,...n.kind?{kind:n.kind}:{},...n.controlRole?{controlRole:n.controlRole}:{},...n.operator?{operator:n.operator}:{},...n.field?{field:n.field}:{},...n.relationshipHint?{relationshipHint:n.relationshipHint}:{}}}}},control(e){return{...e,kind:"control"}},sqlParam(e){return{...e,kind:"control",role:"sqlParam"}},derivedField(e){return{...e,kind:"derived_field",expressionLanguage:e.expressionLanguage||"semaphor_sql_template"}},metric(e){return{...e,queryKind:"metric"}},analysis(e){return{...e,queryKind:"analysis"}},records(e){return{...e,queryKind:"records"}},inputOptions(e){return{...e,queryKind:"inputOptions"}},sql(e){return{...e,queryKind:"sql"}},matrix(e){return{...e,queryKind:"matrix"}}},de=10,ce=100,jt=25,At=500,Je={enabled:!1,queries:[],getQuery:()=>{},getQueries:()=>[]},Ie=d.createContext(null),we=d.createContext(null),qe=d.createContext(void 0),$=[];function Rt({debug:e,children:t}){const r=d.useMemo(()=>Rr(e),[e]),[n,i]=d.useReducer(gr,r,at),o=d.useRef(n),l=d.useId(),[p,c]=d.useState({open:!1});o.current=n,d.useEffect(()=>{i({type:"config",config:r})},[r]),d.useEffect(()=>{if(!n.enabled||!n.exposeWindowBridge||typeof window>"u")return;const x=wr(()=>o.current);return Et({ownerId:l,bridge:x}),()=>{Tt(l)}},[l,n.enabled,n.exposeWindowBridge]);const f=d.useMemo(()=>({state:n,dispatch:i}),[n]),y=d.useCallback(x=>{c({open:!0,focus:x})},[]),h=d.useCallback(()=>{c(x=>({...x,open:!1}))},[]),g=d.useCallback(x=>{c({open:!0,focus:x})},[]),m=d.useMemo(()=>({open:p.open,focus:p.focus,openDevtools:y,closeDevtools:h,focusTrace:g}),[h,g,y,p.focus,p.open]);return s.jsx(Ie.Provider,{value:f,children:s.jsx(we.Provider,{value:m,children:t})})}function Et(e){const t=$.findIndex(r=>r.ownerId===e.ownerId);t>=0&&$.splice(t,1),$.push(e),Ye()}function Tt(e){const t=$.findIndex(r=>r.ownerId===e);t>=0&&$.splice(t,1),Ye()}function Ye(){if(typeof window>"u")return;const e=$[$.length-1];e?window.__SEMAPHOR_DEVTOOLS__=e.bridge:delete window.__SEMAPHOR_DEVTOOLS__}function Ct({id:e,title:t,children:r}){const n=d.useMemo(()=>({id:e,title:t}),[e,t]);return s.jsx(qe.Provider,{value:n,children:r})}function Xe({buttonPosition:e="bottom-right",initialIsOpen:t=!1,panelPosition:r="right",className:n,style:i}={}){const o=je(),l=d.useContext(we),[p,c]=d.useState(""),[f,y]=d.useState(!1),h=d.useRef(null),g=d.useRef(null),m=l==null?void 0:l.openDevtools,x=l==null?void 0:l.closeDevtools,A=(l==null?void 0:l.open)===!0;d.useEffect(()=>{ot()},[]),d.useEffect(()=>{t&&o.enabled&&(m==null||m())},[t,o.enabled,m]),d.useEffect(()=>{if(!A||!x)return;const v=w=>{var R,k;const C=w.target;C instanceof Node&&((R=h.current)!=null&&R.contains(C)||(k=g.current)!=null&&k.contains(C)||x())};return document.addEventListener("pointerdown",v,!0),document.addEventListener("mousedown",v,!0),document.addEventListener("click",v,!0),()=>{document.removeEventListener("pointerdown",v,!0),document.removeEventListener("mousedown",v,!0),document.removeEventListener("click",v,!0)}},[x,A]);const a=d.useMemo(()=>Wt(o.queries),[o.queries]),b=d.useMemo(()=>zt(o.queries,p),[o.queries,p]),D=d.useMemo(()=>Vt(b),[b]),E=d.useMemo(()=>Ze(b,l==null?void 0:l.focus)||b[0],[b,l==null?void 0:l.focus]);return!o.enabled||!l?null:s.jsxs(s.Fragment,{children:[s.jsxs("button",{ref:h,type:"button","aria-label":"Open Semaphor DevTools",title:"Open Semaphor DevTools",className:n?`${L} ${n}`:L,style:{...u.launcher,...dr(e),...cr(a.severity),...i},onClick:()=>l.openDevtools(),children:[s.jsx(Lt,{}),s.jsx("span",{style:u.launcherText,children:a.total}),a.issueCount>0?s.jsx("span",{style:u.launcherIssueCount,children:a.issueCount}):null]}),l.open?s.jsxs("div",{ref:g,role:"dialog","aria-label":"Semaphor DevTools","aria-modal":"false",className:L,style:{...u.panel,...pr(r),...f?u.panelFullscreen:null},children:[s.jsxs("div",{style:u.panelHeader,children:[s.jsxs("div",{style:u.panelTitleBlock,children:[s.jsx("div",{style:u.panelTitle,children:"Semaphor DevTools"}),s.jsxs("div",{style:u.panelSubtitle,children:[a.total," queries · ",a.loading," loading ·"," ",a.failed," failed"]})]}),s.jsxs("div",{style:u.panelActions,children:[s.jsx("button",{type:"button","aria-label":f?"Exit fullscreen Semaphor DevTools":"Enter fullscreen Semaphor DevTools",title:f?"Exit fullscreen Semaphor DevTools":"Enter fullscreen Semaphor DevTools",style:u.iconButton,onClick:()=>y(v=>!v),children:f?s.jsx(ne.Minimize2,{size:15}):s.jsx(ne.Maximize2,{size:15})}),s.jsx("button",{type:"button","aria-label":"Close Semaphor DevTools",style:u.iconButton,onClick:l.closeDevtools,children:s.jsx(Ge.X,{size:15})})]})]}),s.jsxs("label",{style:u.searchBox,children:[s.jsx(ne.Search,{size:14}),s.jsx("input",{"aria-label":"Search Semaphor traces",value:p,onChange:v=>c(v.currentTarget.value),placeholder:"Search traces",style:u.searchInput})]}),s.jsxs("div",{style:{...u.panelBody,...fr(r)},children:[s.jsx("div",{style:{...u.queryList,...mr()},"aria-label":"Registered queries",children:b.length?D.map(v=>s.jsxs("div",{style:u.queryGroup,children:[s.jsxs("div",{style:u.queryGroupHeader,children:[s.jsx("span",{children:v.title}),s.jsx("span",{style:u.queryGroupCount,children:v.traces.length})]}),v.traces.length?v.traces.map(w=>{var V;const C=Pt(w,E),R=Ae(w),k=tt(w),I=et(w),T=ae(w);return s.jsxs("button",{type:"button",title:`${R} · ${k} · ${T}`,style:{...u.queryListItem,...C?u.queryListItemSelected:null},onClick:()=>l.focusTrace({traceId:w.traceId,queryId:w.queryId,viewId:w.viewId}),children:[s.jsxs("span",{style:u.queryListItemHeader,children:[s.jsx(Bt,{status:(V=w.latestAttempt)==null?void 0:V.status}),s.jsx("span",{style:u.queryListTitle,title:R,children:R}),s.jsx("span",{style:u.queryListKindChip,children:k})]}),s.jsx("span",{className:`${L}-source`,style:u.queryListSource,title:`${I} · ${T}`,children:I}),s.jsx("span",{className:`${L}-source`,style:u.queryListSourceSecondary,title:T,children:T})]},be(w))}):s.jsx("div",{style:u.queryGroupEmpty,children:"No input traces"})]},v.title)):s.jsx("div",{style:u.emptyState,children:"No matching traces"})}),s.jsx(Ot,{trace:E})]})]}):null]})}function kt({queryId:e,viewId:t,label:r,className:n,style:i}={}){var h,g;const o=je(),l=d.useContext(we),p=d.useContext(qe);d.useEffect(()=>{ot()},[]);const c=t||(p==null?void 0:p.id),f=d.useMemo(()=>Ht(o.queries,{queryId:e,viewId:c}),[o.queries,e,c]);if(!o.enabled||!l||!f)return null;const y=r||`Inspect ${Ut(f,!!e)}`;return s.jsxs("button",{type:"button","aria-label":y,title:y,className:n?`${L} ${n}`:L,style:{...u.inspectButton,...yr((h=f.latestAttempt)==null?void 0:h.status),...i},onClick:()=>l.openDevtools({traceId:f.traceId,queryId:f.queryId,viewId:f.viewId}),children:[s.jsx(ne.Eye,{size:13}),s.jsx("span",{style:u.inspectButtonText,children:((g=f.latestAttempt)==null?void 0:g.status)||"idle"})]})}function je(){const e=d.useContext(Ie);return!e||!e.state.enabled?Je:se(e.state)}function Dt({spec:e,queryKind:t,queryKey:r,intent:n,activeInputs:i,debug:o}){const l=d.useContext(Ie),p=d.useContext(qe),c=!!(l!=null&&l.state.enabled),f=l==null?void 0:l.dispatch,y=Er(e),h=e.label,g=d.useMemo(()=>JSON.stringify(e),[e]),m=d.useMemo(()=>JSON.stringify(i||[]),[i]),x=d.useMemo(()=>JSON.stringify(n||null),[n]),A=d.useRef(e),a=d.useRef(g),b=d.useRef(n),D=d.useRef(x),E=d.useRef(i),v=d.useRef(m);a.current!==g&&(a.current=g,A.current=e),D.current!==x&&(D.current=x,b.current=n),v.current!==m&&(v.current=m,E.current=i);const w=A.current,C=b.current,R=E.current,k=d.useId(),I=d.useMemo(()=>y||`query_${pt(r)}`,[r,y]),T=(o==null?void 0:o.viewId)||(p==null?void 0:p.id),V=(o==null?void 0:o.viewTitle)||(o==null?void 0:o.title)||(p==null?void 0:p.title),Ce=o==null?void 0:o.visualType,ke=o==null?void 0:o.sectionTitle,xt=JSON.stringify(Fe(o)||[]),De=d.useMemo(()=>Fe(o),[xt]),K=d.useMemo(()=>[T||"unscoped-view",I,k].join("::"),[I,k,T]),Le=d.useMemo(()=>({traceKey:K,spec:w,queryId:I,queryLabel:h,queryKind:t,builder:Tr(t),viewId:T,viewTitle:V,visualType:Ce,sectionTitle:ke,sourceHints:De,intent:C,activeInputs:R,clientWarnings:y?[]:["Query spec is missing an explicit id; using an opaque internal id."]}),[I,t,y,h,w,R,C,De,ke,K,T,V,Ce]);d.useEffect(()=>{if(!(!c||!f))return f({type:"register",descriptor:Le}),()=>{f({type:"unregister",traceKey:K})}},[Le,f,c,K]);const O=d.useCallback((j,_)=>{!c||!f||f({type:"event",traceKey:K,event:j,latestAttempt:_})},[f,c,K]),Oe=d.useCallback(()=>{O({type:"query_started",queryId:I,at:re()},{status:"loading"})},[O,I]),Be=d.useCallback((j,_)=>{const H=Pe(j),P=Mr(j),bt=$r(j);O({type:"query_succeeded",queryId:I,requestId:H,at:re(),rowCount:P,durationMs:_},{requestId:H,status:"success",durationMs:_,rowCount:P,columnCount:bt,executionResult:He(j)})},[O,I]),Y=d.useCallback((j,_)=>{const H=Pe(j),P=j instanceof Error?j.message:String(j);O({type:"query_failed",queryId:I,requestId:H,at:re(),errorMessage:P},{requestId:H,status:"error",durationMs:_,errorMessage:P,executionResult:He(j)})},[O,I]),Ke=d.useCallback(j=>{O({type:"query_ignored_stale",queryId:I,at:re(),reason:j})},[O,I]),Me=d.useCallback(j=>{Y(j,0)},[Y]),le=c?l==null?void 0:l.state.entries[K]:void 0;return d.useMemo(()=>({enabled:c,queryId:I,trace:le?ie(le):void 0,start:Oe,success:Be,failure:Y,ignored:Ke,validationFailure:Me}),[c,Y,Ke,I,Oe,Be,le,Me])}function Lt(){return s.jsx("span",{style:u.logoMark,"aria-hidden":!0,children:s.jsxs("svg",{viewBox:"0 0 100 100",fill:"none",width:"16",height:"16",focusable:"false",children:[s.jsx("rect",{x:"20",y:"15",width:"60",height:"12",rx:"6",fill:"currentColor"}),s.jsx("rect",{x:"20",y:"35",width:"40",height:"12",rx:"6",fill:"currentColor"}),s.jsx("rect",{x:"40",y:"55",width:"40",height:"12",rx:"6",fill:"currentColor"}),s.jsx("rect",{x:"20",y:"75",width:"60",height:"12",rx:"6",fill:"currentColor"})]})})}function Ot({trace:e}){var A,a,b,D,E;if(!e)return s.jsx("div",{style:u.detailsPane,children:s.jsx("div",{style:u.emptyState,children:"No traces registered yet"})});const t=e.latestAttempt,r=t==null?void 0:t.executionResult,n=pe((A=r==null?void 0:r.validation)==null?void 0:A.warnings),i=pe((a=r==null?void 0:r.validation)==null?void 0:a.errors),o=pe((b=r==null?void 0:r.coverage)==null?void 0:b.missingObligations),l=r==null?void 0:r.compiledQuery,p=lr(r),c=((D=e.server)==null?void 0:D.compiledSql)||p.compiledSql,f=t!=null&&t.errorMessage?[t.errorMessage]:[],y=[...e.clientWarnings,...n,...i,...o],h=ae(e),g=et(e),m=e.inputsApplied.length>0,x=!!(l||c);return s.jsxs("div",{style:u.detailsPane,children:[s.jsxs("div",{style:u.detailsHeader,children:[s.jsxs("div",{style:u.detailsHeaderTopRow,children:[s.jsx("span",{"aria-hidden":!0,style:{...u.detailsHeaderStatusDot,...st(t==null?void 0:t.status)}}),s.jsx("span",{style:u.detailsTitle,children:Ae(e)}),s.jsx("span",{style:u.detailsKindChip,children:tt(e)})]}),s.jsxs("div",{style:u.detailsCaption,children:[s.jsxs("span",{style:u.detailsCaptionItem,children:[s.jsx("span",{style:u.detailsCaptionLabel,children:"Query"}),s.jsx("span",{style:{...u.detailsCaptionValue,...u.detailsCaptionItemMono},children:g})]}),s.jsxs("span",{style:u.detailsCaptionItem,children:[s.jsx("span",{style:u.detailsCaptionLabel,children:"Source"}),s.jsx("span",{style:u.detailsCaptionValue,children:h})]}),s.jsxs("span",{style:u.detailsCaptionItem,children:[s.jsx("span",{style:u.detailsCaptionLabel,children:"Rows"}),s.jsx("span",{style:u.detailsCaptionValue,children:nr(t==null?void 0:t.rowCount)})]}),s.jsxs("span",{style:u.detailsCaptionItem,children:[s.jsx("span",{style:u.detailsCaptionLabel,children:"Duration"}),s.jsx("span",{style:u.detailsCaptionValue,children:ir(t==null?void 0:t.durationMs)})]})]})]}),f.length?s.jsx($e,{tone:"error",title:"Error",items:f}):null,y.length?s.jsx($e,{tone:"warning",title:"Warnings",items:y}):null,s.jsx(Kt,{trace:e}),s.jsx(Mt,{trace:e}),(E=e.sourceHints)!=null&&E.length?s.jsx($t,{hints:e.sourceHints}):null,m?s.jsx(Nt,{inputs:e.inputsApplied}):null,x?s.jsx(G,{title:"Compiled query",children:s.jsx(Ft,{compiledQuery:l,compiledSql:c})}):null,s.jsx(G,{title:"Lifecycle events",children:e.recentEvents.length?s.jsx("div",{style:u.eventList,children:e.recentEvents.slice(-5).map((v,w)=>s.jsxs("div",{style:u.eventRow,children:[s.jsx("span",{style:u.eventType,children:or(v)}),s.jsx("span",{style:u.eventMeta,children:ar(v)})]},`${v.type}:${v.at}:${w}`))}):s.jsx("div",{style:u.mutedText,children:"No attempts recorded"})}),s.jsx(G,{title:"Raw trace JSON",children:s.jsx("pre",{style:u.codeBlock,children:sr(e)})})]})}function $e({tone:e,title:t,items:r}){const n=e==="error"?u.alertCardError:u.alertCardWarning;return s.jsxs("div",{style:{...u.alertCard,...n},children:[s.jsx("div",{style:u.alertCardTitle,children:t}),r.length>1?s.jsx("ul",{style:u.alertCardList,children:r.map((i,o)=>s.jsx("li",{children:i},`${e}-${o}`))}):s.jsx("div",{children:r[0]})]})}function Bt({status:e}){return s.jsx("span",{"aria-hidden":!0,style:{...u.statusDot,...st(e)}})}function G({title:e,children:t}){return s.jsxs("details",{style:u.disclosure,children:[s.jsx("summary",{style:u.disclosureSummary,children:e}),s.jsx("div",{style:u.disclosureBody,children:t})]})}function Kt({trace:e}){var o;const t=(o=e.projectionFieldRefs)!=null&&o.length?e.projectionFieldRefs:e.fieldRefs,r=e.inputFieldRefs||[],n=Jt(t),i=Yt(e,n,t);return s.jsxs("div",{style:u.recipe,children:[s.jsx("div",{style:u.recipeSummary,children:i.map(l=>s.jsxs("div",{style:u.recipeSummaryRow,children:[s.jsx("span",{style:u.recipeSummaryLabel,children:l.label}),s.jsx("span",{style:u.recipeSummaryValue,title:l.value,children:l.value})]},l.label))}),s.jsx(M,{title:"Measures",fields:n.measures}),s.jsx(M,{title:"Time fields",fields:n.timeFields}),s.jsx(M,{title:"Dimensions",fields:n.dimensions,emptyText:"No dimensions selected"}),s.jsx(M,{title:"Identifiers",fields:n.identifiers}),s.jsx(M,{title:"Other fields",fields:n.other}),s.jsx(M,{title:"Input bindings",fields:r})]})}function Mt({trace:e}){return!e.sourceRefs.length&&!e.fieldRefs.length?null:s.jsx(G,{title:"Sources and field refs",children:s.jsxs("div",{style:u.traceLineage,children:[s.jsx(_t,{sources:e.sourceRefs}),s.jsx(M,{title:"All field refs",fields:e.fieldRefs,emptyText:"No field refs captured"})]})})}function $t({hints:e}){return s.jsx(G,{title:"Source hints",children:s.jsx("div",{style:u.recipeFieldList,children:e.map((t,r)=>{const n=rr(t),i=t.component||t.exportName||n||"Source hint",o=[t.exportName&&t.exportName!==i?t.exportName:void 0,n,t.note].filter(Boolean).join(" · ");return s.jsxs("div",{style:u.recipeFieldRow,title:o||i,children:[s.jsx("span",{style:u.recipeFieldName,children:i}),o?s.jsx("span",{style:u.recipeFieldMeta,children:o}):null]},`${i}:${n}:${r}`)})})})}function _t({sources:e}){return s.jsxs("div",{style:u.recipeGroup,children:[s.jsxs("div",{style:u.recipeGroupHeader,children:[s.jsx("span",{style:u.recipeGroupTitle,children:"Sources"}),s.jsx("span",{style:u.recipeGroupCount,children:e.length})]}),e.length?s.jsx("div",{style:u.recipeFieldList,children:e.map((t,r)=>s.jsxs("div",{style:u.recipeFieldRow,title:W(t),children:[s.jsx("span",{style:u.recipeFieldName,children:W(t)}),s.jsx("span",{style:u.recipeFieldMeta,children:t.kind})]},`${W(t)}:${r}`))}):s.jsx("div",{style:u.recipeEmptyText,children:"No sources captured"})]})}function M({title:e,fields:t,emptyText:r}){return!t.length&&!r?null:s.jsxs("div",{style:u.recipeGroup,children:[s.jsxs("div",{style:u.recipeGroupHeader,children:[s.jsx("span",{style:u.recipeGroupTitle,children:e}),s.jsx("span",{style:u.recipeGroupCount,children:t.length})]}),t.length?s.jsx("div",{style:u.recipeFieldList,children:t.map((n,i)=>{const o=nt(n),l=n.dataType&&n.dataType!=="unknown"?n.dataType:void 0,p=n.source?W(n.source):void 0,c=[o,l,p].filter(Boolean).join(" · ");return s.jsxs("div",{style:u.recipeFieldRow,title:c,children:[s.jsx("span",{style:u.recipeFieldName,children:o}),s.jsxs("span",{style:u.recipeFieldMeta,children:[l?s.jsx("span",{children:l}):null,l&&p?s.jsx("span",{style:u.recipeFieldMetaDivider,children:" · "}):null,p?s.jsx("span",{children:p}):null]})]},`${Re(n)}:${i}`)})}):s.jsx("div",{style:u.recipeEmptyText,children:r})]})}function Nt({inputs:e}){return s.jsxs("div",{style:u.inputsAppliedBlock,children:[s.jsxs("div",{style:u.inputsAppliedHeader,children:[s.jsx("span",{style:u.inputsAppliedTitle,children:"Inputs applied"}),s.jsx("span",{style:u.inputsAppliedCount,children:e.length})]}),s.jsx("div",{style:u.inputRecipeList,children:e.map(t=>{const r=it(t);return s.jsxs("div",{style:u.inputRecipeRow,title:r.title,children:[s.jsxs("div",{style:u.inputRecipeHeader,children:[s.jsx("span",{style:u.inputRecipeId,title:t.inputId,children:t.inputId}),r.operator?s.jsx("span",{style:u.inputOperatorBadge,children:r.operator}):null,s.jsx("span",{style:u.inputValuePreview,title:r.value,children:r.value})]}),r.binding?s.jsx("div",{style:u.inputRecipeBinding,title:r.binding,children:r.binding}):null]},t.inputId)})})]})}function Ft({compiledQuery:e,compiledSql:t}){return(e==null?void 0:e.kind)==="sql"?s.jsxs("div",{style:u.compiledQuery,children:[s.jsx(Q,{label:"SQL",value:e.sql}),e.pythonCode?s.jsx(Q,{label:"Python",value:e.pythonCode}):null,e.parameters?s.jsx(Q,{label:"Parameters",value:Se(e.parameters)}):null]}):t?s.jsx(Q,{label:"SQL",value:t}):s.jsx(Q,{label:"Compiled query",value:Se(e)})}function Q({label:e,value:t}){return s.jsxs("div",{style:u.codeBlockGroup,children:[s.jsx("div",{style:u.codeBlockLabel,children:e}),s.jsx("pre",{style:u.codeBlock,children:t})]})}function Wt(e){const t=e.filter(i=>{var o;return((o=i.latestAttempt)==null?void 0:o.status)==="error"}).length,r=e.filter(i=>{var o;return((o=i.latestAttempt)==null?void 0:o.status)==="loading"}).length,n=e.filter(i=>{var o,l,p,c;return i.clientWarnings.length>0||!!((c=(p=(l=(o=i.latestAttempt)==null?void 0:o.executionResult)==null?void 0:l.validation)==null?void 0:p.warnings)!=null&&c.length)}).length;return{total:e.length,failed:t,loading:r,warningCount:n,issueCount:t+n,severity:t?"error":n?"warning":"ok"}}function zt(e,t){const r=t.trim().toLowerCase();return r?e.filter(n=>[n.queryId,n.queryLabel,n.viewId,n.viewTitle,n.visualType,n.sectionTitle,n.builder,n.queryKind,ae(n)].filter(Boolean).join(" ").toLowerCase().includes(r)):e}function Vt(e){const t=e.filter(i=>i.queryKind==="inputOptions"),r=new Set(t.map(be));return[{title:"Cards",traces:e.filter(i=>!r.has(be(i)))},{title:"Inputs",traces:t}]}function Ze(e,t){if(!(!(t!=null&&t.traceId)&&!(t!=null&&t.queryId)&&!(t!=null&&t.viewId)))return t.traceId?e.find(r=>r.traceId===t.traceId):e.find(r=>!(t.queryId&&r.queryId!==t.queryId||t.viewId&&r.viewId!==t.viewId))}function Ht(e,t){if(t.queryId)return Ze(e,t);if(!t.viewId)return;const r=e.filter(n=>n.viewId===t.viewId);return r.length===1?r[0]:void 0}function Pt(e,t){return!!(e&&t&&e.traceId===t.traceId)}function be(e){return e.traceId}function Qt(e){switch(e){case"metric":return"metric";case"records":return"records";case"matrix":return"matrix";case"analysis":return"analysis";case"inputOptions":return"inputs";case"sql":return"sql";default:return ue(e)}}function Ae(e){return e.viewTitle||e.queryLabel||e.viewId||e.queryId}function et(e){return e.viewTitle&&e.queryLabel&&e.queryLabel!==e.viewTitle?`${e.queryLabel} · ${e.queryId}`:e.viewTitle||e.queryLabel?e.queryId:e.viewId?`${e.viewId} · ${e.queryId}`:e.queryId}function tt(e){return Gt(e.visualType)||Qt(e.queryKind)}function Ut(e,t){return t?e.queryLabel||e.queryId:Ae(e)}function Gt(e){if(e)return e.replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function ae(e){const t=e.sourceRefs.map(W);return t.length?t.length===1?t[0]:`${t[0]} + ${t.length-1} more`:"No source"}function Jt(e){return e.reduce((t,r)=>(r.role==="measure"?t.measures.push(r):r.role==="date"?t.timeFields.push(r):r.role==="dimension"?t.dimensions.push(r):r.role==="id"?t.identifiers.push(r):t.other.push(r),t),{measures:[],timeFields:[],dimensions:[],identifiers:[],other:[]})}function Yt(e,t,r){const n=[{label:"Operation",value:Xt(e)}],i=Zt(e,t,r);i&&n.push(i);const o=er(t);o&&n.push({label:"Grouped by",value:o});const l=tr(e.inputsApplied);return l&&n.push({label:"Filtered by",value:l}),n.push({label:"Source",value:ae(e)}),n}function Xt(e){var t,r;if(e.queryKind==="records"&&((t=e.projectionFieldRefs)!=null&&t.length)&&e.projectionFieldRefs.every(n=>n.role==="measure")&&((r=e.latestAttempt)==null?void 0:r.rowCount)===1)return"KPI query";switch(e.queryKind){case"metric":return"KPI query";case"records":return"Records query";case"matrix":return"Matrix query";case"analysis":return"Analysis query";case"inputOptions":return"Input options query";case"sql":return"SQL query";default:return ue(e.queryKind)}}function Zt(e,t,r){if(e.queryKind==="records")return{label:t.measures.length?"Computes":"Selects",value:U(r)};if(e.queryKind==="inputOptions")return{label:"Options from",value:U(r)};if(t.measures.length)return{label:"Computes",value:U(t.measures)};if(r.length)return{label:"Uses",value:U(r)};if(e.queryKind==="sql")return{label:"Inspect",value:"Open compiled query for SQL or Python."}}function er(e){const t=[...e.dimensions,...e.timeFields];return t.length?U(t):void 0}function tr(e){if(e.length)return rt(e.map(t=>{const r=it(t);return[t.inputId,r.operator,r.value].filter(Boolean).join(" ")}))}function U(e){return rt(e.map(nt))}function rt(e){const t=e.filter(Boolean);return t.length===0?"-":t.length===1?t[0]:t.length===2?`${t[0]} and ${t[1]}`:`${t.slice(0,-1).join(", ")}, and ${t[t.length-1]}`}function nt(e){return[e.aggregate,e.label||e.name].filter(Boolean).join(" ")}function it(e){var l,p,c;const t=e.valuePreview||"redacted",r=((l=e.fieldRef)==null?void 0:l.label)||((p=e.fieldRef)==null?void 0:p.name),n=(c=e.fieldRef)!=null&&c.source?W(e.fieldRef.source):void 0,i=[r?`on ${r}`:void 0,n].filter(Boolean).join(" · "),o=[e.inputId,e.operator,t,i].filter(Boolean).join(" - ");return{operator:e.operator,value:t,binding:i,title:o}}function W(e){return e.kind==="semantic"?e.datasetName||e.datasetId||e.domainId:e.kind==="physical"?[e.schemaName,e.tableName].filter(Boolean).join(".")||e.tableName:e.connectionId?`SQL ${e.connectionId}`:"SQL source"}function rr(e){if(e.file)return e.line&&e.column?`${e.file}:${e.line}:${e.column}`:e.line?`${e.file}:${e.line}`:e.file}function nr(e){return typeof e=="number"?e.toLocaleString():"-"}function ir(e){return typeof e=="number"?`${Math.round(e)}ms`:"-"}function sr(e){return Se(e)}function Se(e){return JSON.stringify(e,null,2)??"undefined"}function or(e){switch(e.type){case"query_started":return"Started";case"query_succeeded":return"Succeeded";case"query_failed":return"Failed";case"query_ignored_stale":return"Ignored stale";case"input_changed":return"Input changed";default:return ur(e)}}function ar(e){return[e.at,"durationMs"in e&&typeof e.durationMs=="number"?`${Math.round(e.durationMs)}ms`:void 0,"rowCount"in e&&typeof e.rowCount=="number"?`${e.rowCount} rows`:void 0,"reason"in e?e.reason:void 0,"errorMessage"in e?e.errorMessage:void 0].filter(Boolean).join(" - ")}function ur(e){throw new Error(`Unsupported Semaphor trace event: ${JSON.stringify(e)}`)}function pe(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function lr(e){const t=e==null?void 0:e.metadata,r=t&&typeof t=="object"&&!Array.isArray(t)&&"dataAppDebug"in t&&t.dataAppDebug&&typeof t.dataAppDebug=="object"&&!Array.isArray(t.dataAppDebug)?t.dataAppDebug:void 0;return{compiledSql:typeof(r==null?void 0:r.compiledSql)=="string"?r.compiledSql:void 0,queryHash:typeof(r==null?void 0:r.queryHash)=="string"?r.queryHash:void 0}}function dr(e){return e==="relative"?{position:"relative",top:"auto",right:"auto",bottom:"auto",left:"auto"}:{top:e.startsWith("top")?20:"auto",right:e.endsWith("right")?20:"auto",bottom:e.startsWith("bottom")?20:"auto",left:e.endsWith("left")?20:"auto"}}function cr(e){return e==="error"?{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"}:e==="warning"?{borderColor:"var(--sd-warning-border)",background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)"}:{borderColor:"var(--sd-success-border)",background:"var(--sd-success-bg)",color:"var(--sd-success-fg)"}}function pr(e){return e==="right"?{top:16,right:16,bottom:16,left:"auto",width:"min(720px, calc(100vw - 32px))",height:"auto",borderRadius:6}:{top:"auto",right:16,bottom:16,left:16,width:"auto",height:"min(420px, 45vh)",borderRadius:6}}function fr(e){return e==="right"?{gridTemplateColumns:"minmax(210px, 280px) minmax(0, 1fr)"}:{gridTemplateColumns:"minmax(260px, 340px) minmax(0, 1fr)"}}function mr(e){return{borderRight:"1px solid var(--sd-border)",borderBottom:0}}function st(e){return e==="error"?{background:"var(--sd-error-dot)"}:e==="success"?{background:"var(--sd-success-dot)"}:e==="loading"?{background:"var(--sd-loading-dot)"}:{background:"var(--sd-idle-dot)"}}function yr(e){return e==="error"?{borderColor:"var(--sd-error-border)",color:"var(--sd-error-fg)"}:e==="success"?{borderColor:"var(--sd-success-border)",color:"var(--sd-success-fg)"}:e==="loading"?{borderColor:"var(--sd-loading-border)",color:"var(--sd-loading-fg)"}:{borderColor:"var(--sd-border)",color:"var(--sd-fg-muted)"}}const _e="semaphor-devtools-stylesheet",L="semaphor-devtools",hr=`
|
|
2
|
+
.${L} {
|
|
3
3
|
--sd-bg: #ffffff;
|
|
4
4
|
--sd-bg-muted: #fafafa;
|
|
5
5
|
--sd-bg-raised: #ffffff;
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
@media (prefers-color-scheme: dark) {
|
|
34
|
-
.${
|
|
34
|
+
.${L} {
|
|
35
35
|
--sd-bg: #09090b;
|
|
36
36
|
--sd-bg-muted: #18181b;
|
|
37
37
|
--sd-bg-raised: #18181b;
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
.${
|
|
61
|
+
.${L}-source {
|
|
62
62
|
display: -webkit-box;
|
|
63
63
|
-webkit-line-clamp: 2;
|
|
64
64
|
-webkit-box-orient: vertical;
|
|
65
65
|
overflow: hidden;
|
|
66
66
|
word-break: break-all;
|
|
67
67
|
}
|
|
68
|
-
`;function nt(){if(typeof document>"u"||document.getElementById(Me))return;const e=document.createElement("style");e.id=Me,e.textContent=dr,document.head.appendChild(e)}const X='ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',Z="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",pe={color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},a={launcher:{position:"fixed",bottom:20,zIndex:2147483e3,display:"inline-flex",alignItems:"center",gap:7,height:36,minWidth:36,padding:"0 10px",borderWidth:1,borderStyle:"solid",borderRadius:6,boxShadow:"var(--sd-shadow)",font:`600 12px/1.2 ${X}`,cursor:"pointer"},launcherText:{fontVariantNumeric:"tabular-nums"},launcherIssueCount:{display:"grid",minWidth:16,height:16,placeItems:"center",borderRadius:8,background:"currentColor",color:"var(--sd-bg)",fontSize:10,lineHeight:"16px"},logoMark:{display:"grid",width:18,height:18,placeItems:"center",flex:"0 0 auto",borderRadius:4,background:"var(--sd-fg)",color:"var(--sd-bg)"},panel:{position:"fixed",top:16,right:16,bottom:16,zIndex:2147483001,width:"min(720px, calc(100vw - 32px))",display:"flex",flexDirection:"column",overflow:"hidden",border:"1px solid var(--sd-border)",borderRadius:6,background:"var(--sd-bg)",color:"var(--sd-fg)",boxShadow:"var(--sd-shadow)",font:`13px/1.4 ${X}`},panelFullscreen:{top:0,right:0,bottom:0,left:0,width:"100vw",height:"100vh",borderRadius:0},panelHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--sd-border)"},panelTitleBlock:{minWidth:0},panelTitle:{fontSize:13,fontWeight:600},panelSubtitle:{marginTop:2,color:"var(--sd-fg-muted)",fontSize:11},panelActions:{display:"flex",alignItems:"center",gap:6},iconButton:{display:"grid",width:28,height:28,placeItems:"center",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,background:"var(--sd-bg)",color:"var(--sd-fg-muted)",cursor:"pointer"},searchBox:{display:"flex",alignItems:"center",gap:8,margin:10,height:28,padding:"0 8px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,color:"var(--sd-fg-muted)"},searchInput:{minWidth:0,flex:1,border:0,outline:0,background:"transparent",color:"var(--sd-fg)",font:`12px/1.4 ${X}`},panelBody:{display:"grid",gridTemplateColumns:"minmax(210px, 280px) minmax(0, 1fr)",minHeight:0,flex:1,borderTop:"1px solid var(--sd-border-soft)"},queryList:{minHeight:0,overflowY:"auto",padding:8,borderRight:"1px solid var(--sd-border)",background:"var(--sd-bg-muted)"},queryGroup:{display:"grid",gap:3,marginBottom:8},queryGroupHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 6px 3px",...pe},queryGroupCount:{color:"var(--sd-fg-subtle)",fontVariantNumeric:"tabular-nums"},queryGroupEmpty:{padding:"7px 8px",color:"var(--sd-fg-subtle)",fontSize:11},queryListItem:{display:"grid",gap:3,width:"100%",padding:"7px 8px",borderWidth:1,borderStyle:"solid",borderColor:"transparent",borderRadius:5,background:"transparent",color:"var(--sd-fg)",textAlign:"left",cursor:"pointer"},queryListItemSelected:{borderColor:"var(--sd-border-strong)",background:"var(--sd-bg-raised)"},queryListItemHeader:{display:"flex",alignItems:"center",gap:7,minWidth:0},statusDot:{width:7,height:7,flex:"0 0 auto",borderRadius:999},queryListTitle:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:"var(--sd-fg)"},queryListKindChip:{flex:"0 0 auto",color:"var(--sd-fg-subtle)",fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},queryListSource:{minWidth:0,paddingLeft:14,color:"var(--sd-fg-muted)",fontSize:11,lineHeight:1.35},detailsPane:{minHeight:0,overflowY:"auto",padding:16},detailsHeader:{display:"grid",gap:6,marginBottom:14},detailsHeaderTopRow:{display:"flex",alignItems:"center",gap:8,minWidth:0},detailsHeaderStatusDot:{width:8,height:8,flex:"0 0 auto",borderRadius:999},detailsTitle:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:14,fontWeight:700,color:"var(--sd-fg)"},detailsKindChip:{flex:"0 0 auto",padding:"2px 6px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},detailsCaption:{display:"flex",flexWrap:"wrap",alignItems:"center",columnGap:10,rowGap:2,color:"var(--sd-fg-muted)",fontSize:11},detailsCaptionItem:{display:"inline-flex",alignItems:"center",gap:4},detailsCaptionItemMono:{fontFamily:Z},detailsCaptionLabel:{color:"var(--sd-fg-subtle)"},detailsCaptionValue:{color:"var(--sd-fg)",fontVariantNumeric:"tabular-nums"},disclosure:{marginTop:16},disclosureSummary:{cursor:"pointer",...pe},disclosureBody:{marginTop:8},alertCard:{marginTop:12,padding:"8px 10px",borderWidth:1,borderStyle:"solid",borderRadius:5,fontSize:12,lineHeight:1.45},alertCardError:{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"},alertCardWarning:{borderColor:"var(--sd-warning-border)",background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)"},alertCardTitle:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em",fontSize:10,marginBottom:4},alertCardList:{margin:0,paddingLeft:16,display:"grid",gap:3},recipe:{display:"grid",gap:12},traceLineage:{display:"grid",gap:12},recipeSummary:{display:"grid",gap:4,padding:"8px 10px",border:"1px solid var(--sd-border)",borderRadius:5,background:"var(--sd-bg-muted)",color:"var(--sd-fg)",fontSize:12},recipeSummaryRow:{display:"grid",gridTemplateColumns:"76px minmax(0, 1fr)",gap:8,minWidth:0,alignItems:"baseline"},recipeSummaryLabel:{color:"var(--sd-fg-subtle)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},recipeSummaryValue:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12},recipeGroup:{display:"grid",gap:4},recipeGroupHeader:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:4,borderBottom:"1px solid var(--sd-border-soft)"},recipeGroupTitle:{color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},recipeGroupCount:{color:"var(--sd-fg-subtle)",fontSize:10,fontVariantNumeric:"tabular-nums"},recipeFieldList:{display:"grid"},recipeEmptyText:{padding:"5px 0",color:"var(--sd-fg-subtle)",fontSize:11},recipeFieldRow:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, auto)",alignItems:"center",gap:10,minHeight:26,padding:"4px 0",borderBottom:"1px solid var(--sd-border-soft)"},recipeFieldName:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,fontWeight:500},recipeFieldMeta:{minWidth:0,display:"inline-flex",alignItems:"baseline",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-subtle)",fontSize:11,textAlign:"right"},recipeFieldMetaDivider:{color:"var(--sd-fg-subtle)",margin:"0 4px"},inputsAppliedBlock:{marginTop:16,padding:"10px 12px",border:"1px solid var(--sd-border)",borderLeft:"2px solid var(--sd-fg-muted)",borderRadius:5,background:"var(--sd-bg-muted)"},inputsAppliedHeader:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,marginBottom:6},inputsAppliedTitle:{color:"var(--sd-fg)",fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.08em"},inputsAppliedCount:{color:"var(--sd-fg-subtle)",fontSize:10,fontVariantNumeric:"tabular-nums"},inputRecipeList:{display:"grid"},inputRecipeRow:{display:"grid",gap:2,minWidth:0,padding:"6px 0",borderBottom:"1px solid var(--sd-border-soft)"},inputRecipeHeader:{display:"flex",alignItems:"center",gap:8,minWidth:0},inputRecipeId:{flex:"0 0 auto",maxWidth:"40%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontFamily:Z,fontSize:11,fontWeight:600},inputOperatorBadge:{display:"inline-flex",flex:"0 0 auto",alignItems:"center",height:16,padding:"0 5px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontFamily:Z,fontSize:10,textTransform:"uppercase",letterSpacing:"0.06em"},inputValuePreview:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,textAlign:"right"},inputRecipeBinding:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-muted)",fontSize:11},eventList:{display:"grid"},eventRow:{display:"grid",gridTemplateColumns:"96px minmax(0, 1fr)",gap:10,padding:"6px 0",borderBottom:"1px solid var(--sd-border-soft)"},eventType:{color:"var(--sd-fg)",fontWeight:600,fontSize:12},eventMeta:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-muted)",fontSize:11},mutedText:{color:"var(--sd-fg-muted)",fontSize:12},compiledQuery:{display:"grid",gap:10},codeBlockGroup:{display:"grid",gap:5},codeBlockLabel:{...pe},codeBlock:{maxHeight:260,margin:0,overflow:"auto",padding:"8px 10px",border:"1px solid var(--sd-border)",borderRadius:5,background:"var(--sd-bg-muted)",color:"var(--sd-fg)",fontFamily:Z,fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap"},emptyState:{padding:10,color:"var(--sd-fg-muted)",textAlign:"center",fontSize:12},inspectButton:{display:"inline-flex",alignItems:"center",gap:5,height:24,maxWidth:"100%",padding:"0 7px",borderWidth:1,borderStyle:"solid",borderRadius:5,background:"var(--sd-bg)",font:`600 11px/1 ${X}`,cursor:"pointer"},inspectButtonText:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}};function it(e){return{...e,order:[],entries:{},sequence:0}}function cr(e,t){if(t.type==="config")return t.config.enabled?{...e,...t.config}:it(t.config);if(!e.enabled)return e;switch(t.type){case"register":return hr(pr(e,t.descriptor));case"unregister":return fr(e,t.traceKey);case"event":return mr(e,t);default:return e}}function pr(e,t){const r=e.entries[t.traceKey],n=r?e.sequence:e.sequence+1,i=Re(),u={...r||gr(t),...st(t),traceKey:t.traceKey,latestAttempt:(r==null?void 0:r.latestAttempt)||{status:"idle"},recentEvents:(r==null?void 0:r.recentEvents)||[],mounted:!0,registeredAt:(r==null?void 0:r.registeredAt)||n,lastEventAt:(r==null?void 0:r.lastEventAt)||i};return{...e,sequence:n,order:r?e.order:[...e.order,t.traceKey],entries:{...e.entries,[t.traceKey]:u}}}function fr(e,t){const r=e.entries[t];return r?{...e,entries:{...e.entries,[t]:{...r,mounted:!1}}}:e}function mr(e,t){const r=e.entries[t.traceKey];if(!r)return e;const n=Re(),i=[...r.recentEvents,t.event].slice(-e.maxEventsPerQuery);return{...e,entries:{...e.entries,[t.traceKey]:{...r,latestAttempt:t.latestAttempt?{...r.latestAttempt,...t.latestAttempt}:r.latestAttempt,recentEvents:i,lastEventAt:n}}}}function hr(e){if(e.order.length<=e.maxQueries)return e;const t=e.order.map(i=>e.entries[i]).filter(i=>!!i).sort((i,u)=>i.mounted!==u.mounted?i.mounted?1:-1:i.lastEventAt-u.lastEventAt),r=e.order.length-e.maxQueries,n=new Set(t.slice(0,r).map(i=>i.traceKey));return n.size?{...e,order:e.order.filter(i=>!n.has(i)),entries:Object.fromEntries(Object.entries(e.entries).filter(([i])=>!n.has(i)))}:e}function gr(e){const t=Re();return{...st(e),traceKey:e.traceKey,latestAttempt:{status:"idle"},recentEvents:[],mounted:!0,registeredAt:0,lastEventAt:t}}function st(e){var n;const t=Rr(e.spec),r=Er(e.spec,e.activeInputs);return{traceId:lt(e.traceKey),viewId:e.viewId,queryId:e.queryId,queryLabel:e.queryLabel||e.viewTitle,queryKind:e.queryKind,builder:e.builder,sourceRefs:Ar(e.intent),sourceHints:(n=e.sourceHints)!=null&&n.length?e.sourceHints:void 0,projectionFieldRefs:t,inputFieldRefs:r,fieldRefs:Cr(e.intent),inputsApplied:(e.activeInputs||[]).map(i=>({inputId:i.inputId,fieldRef:i.field,operator:i.operator,valuePreview:qr(i)})),recentEvents:[],clientWarnings:e.clientWarnings}}function ne(e){const{traceKey:t,mounted:r,registeredAt:n,lastEventAt:i,...u}=e;return u}function ie(e){return e.enabled?{enabled:!0,queries:e.order.map(r=>e.entries[r]).filter(r=>!!r).map(ne),getQuery:r=>{const n=Object.values(e.entries).find(i=>i.queryId===r);return n?ne(n):void 0},getQueries:r=>Object.values(e.entries).filter(n=>n.queryId===r).map(ne)}:Ue}function yr(e){return{snapshot:()=>vr(ie(e())),getQuery:t=>$e(ie(e()).getQuery(t)),getQueries:t=>ie(e()).getQueries(t).map(r=>$e(r)).filter(r=>!!r)}}function vr(e){if(!e.enabled)return e;const t=e.queries.map(ot);return{enabled:e.enabled,queries:t,getQuery:r=>t.find(n=>n.queryId===r),getQueries:r=>t.filter(n=>n.queryId===r)}}function $e(e){return e?ot(e):void 0}function ot(e){var t;return(t=e==null?void 0:e.latestAttempt)!=null&&t.executionResult?{...e,latestAttempt:{...e.latestAttempt,executionResult:xr(e.latestAttempt.executionResult)}}:e}function xr(e){const{compiledQuery:t,intent:r,result:n,...i}=e,u=br(i.metadata);return{...i,...u?{metadata:u}:{}}}function br(e){if(!e||typeof e!="object"||Array.isArray(e))return e;const t=e.dataAppDebug;if(!t||typeof t!="object"||Array.isArray(t))return e;const{compiledSql:r,...n}=t;return{...e,dataAppDebug:n}}function Sr(e){return e===void 0||e===!1?{enabled:!1,exposeWindowBridge:!1,maxEventsPerQuery:le,maxQueries:de}:e===!0?{enabled:!0,exposeWindowBridge:!1,maxEventsPerQuery:le,maxQueries:de}:{enabled:e.enabled!==!1,exposeWindowBridge:e.exposeWindowBridge===!0,maxEventsPerQuery:Ne(e.maxEventsPerQuery,le,It),maxQueries:Ne(e.maxQueries,de,wt)}}function _e(e){const r=[e==null?void 0:e.sourceHint,...(e==null?void 0:e.sourceHints)||[]].filter(n=>!!n).map(n=>({file:ee(n.file),line:Fe(n.line),column:Fe(n.column),exportName:ee(n.exportName),component:ee(n.component),note:ee(n.note)})).filter(n=>!!(n.file||n.line||n.column||n.exportName||n.component||n.note));return r.length?r:void 0}function ee(e){if(typeof e!="string")return;const t=e.trim();return t||void 0}function Fe(e){return typeof e=="number"&&Number.isInteger(e)&&e>0?e:void 0}function Ne(e,t,r){return e===void 0||!Number.isFinite(e)||!Number.isInteger(e)||e<=0?t:Math.min(e,r)}function Ir(e){return typeof e.id=="string"&&e.id.trim()?e.id:void 0}function wr(e){switch(e){case"metric":return"semaphor.metric";case"records":return"semaphor.records";case"matrix":return"semaphor.matrix";case"analysis":return"semaphor.analysis";case"inputOptions":return"semaphor.inputOptions";case"sql":return"semaphor.sql";default:return ae(e)}}function ae(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function qr(e){if(jr(e))return;const t=e.value;if(t!==void 0){if(Array.isArray(t)){const r=t.filter(n=>typeof n=="string"||typeof n=="number"||typeof n=="boolean").map(n=>String(n));if(r.length===t.length&&r.length>0){const n=r.slice(0,3).join(", "),i=r.length>3?`, +${r.length-3} more`:"";return We(`${n}${i}`)}return`${t.length} selected`}return typeof t=="number"||typeof t=="boolean"?String(t):typeof t=="string"?We(t):t&&typeof t=="object"?`object(${Object.keys(t).slice(0,5).join(",")})`:String(t)}}function We(e){return e.length>80?`${e.slice(0,77)}...`:e}function jr(e){var r;const t=[e.inputId,e.label,(r=e.field)==null?void 0:r.name].filter(Boolean).join(" ").toLowerCase();return["token","secret","password","email","phone","ssn"].some(n=>t.includes(n))}function Ar(e){const t=new Map;return se(e,r=>{kr(r)&&t.set(ut(r),r)}),[...t.values()]}function Rr(e){switch(e.queryKind){case"metric":case"analysis":return N([...e.measures||[],e.primaryMeasure,e.dateField,...e.dimensions||[]]);case"records":return N(e.fields||[]);case"inputOptions":return N([e.labelField,e.valueField,e.searchField,...e.disambiguationFields||[]]);case"sql":return N(e.fields||[]);case"matrix":return N([...(e.rows||[]).map(fe),...(e.columns||[]).map(fe),...(e.values||[]).map(fe)]);default:return ae(e)}}function Er(e,t){const r=[...(e.inputs||[]).map(at),...(t||[]).map(n=>n.field)];return N(r)}function N(e){const t=new Map;return e.forEach(r=>{r&&G(r)&&t.set(Ae(r),r)}),[...t.values()]}function at(e){if(!e||typeof e!="object")return;const t=e.toAnalyticsInput;if(typeof t=="function"){const n=t.call(e);return at(n)}const r=e.field;return G(r)?r:void 0}function fe(e){if(G(e))return e;if(!e||typeof e!="object")return;const t=e.field;return G(t)?t:void 0}function Cr(e){const t=new Map;return se(e,r=>{G(r)&&t.set(Ae(r),r)}),[...t.values()]}function se(e,t){if(!(!e||typeof e!="object")){if(t(e),Array.isArray(e)){e.forEach(r=>se(r,t));return}Object.values(e).forEach(r=>se(r,t))}}function kr(e){if(!e||typeof e!="object")return!1;const t=e;return t.kind==="semantic"?typeof t.domainId=="string"&&typeof t.datasetName=="string":t.kind==="physical"?typeof t.connectionId=="string"&&typeof t.tableName=="string":t.kind==="sql"?typeof t.connectionId=="string":!1}function G(e){if(!e||typeof e!="object")return!1;const t=e;return typeof t.name=="string"&&(t.source!==void 0||t.role!==void 0||t.dataType!==void 0||t.aggregate!==void 0)}function ut(e){return e.kind==="semantic"?[e.kind,e.domainId,e.datasetId||e.datasetName].join(":"):e.kind==="physical"?[e.kind,e.connectionId,e.databaseName,e.schemaName,e.tableName].join(":"):[e.kind,e.connectionId].join(":")}function Ae(e){return[e.name,e.role,e.aggregate,e.source?ut(e.source):""].join(":")}function Tr(e){const t=e;return typeof(t==null?void 0:t.rowCount)=="number"?t.rowCount:Array.isArray(t==null?void 0:t.records)?t.records.length:void 0}function Dr(e){const t=e;return Array.isArray(t==null?void 0:t.columns)?t.columns.length:void 0}function ze(e){const t=e;return t==null?void 0:t.executionResult}function Ve(e){const t=e;return typeof(t==null?void 0:t.requestId)=="string"?t.requestId:void 0}function lt(e){let t=2166136261;for(let r=0;r<e.length;r+=1)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function te(){return new Date().toISOString()}function Re(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const Or=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],Lr=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function dt(e){if(!e)return{};const t=_r(e.executionResult),r=Br(e,t),n=Mr(r);return{...e,...Object.keys(r).length?{resultSets:r}:{},...n?{columns:n.columns,records:n.records,rowCount:n.rowCount}:{}}}function Br(e,t){const r=Kr(e.resultSets);for(const i of Or){if(r[i]){r[i]=ct(r[i]);continue}const u=Fr(e[i]);if(!u.length)continue;const l=t.length?t:Nr(u);r[i]={records:Ee(u,l),columns:l,rowCount:u.length}}const n=$r(e.executionResult);return n&&n.records.length>0&&!r.records&&(r.records=n),r}function Kr(e){return Object.fromEntries(Object.entries(e||{}).map(([t,r])=>[t,ct(r)]))}function ct(e){var t;return{...e,records:Ee(e.records||[],e.columns||[]),rowCount:e.rowCount??((t=e.records)==null?void 0:t.length)??0}}function Mr(e){var t;for(const r of Lr)if((t=e[r])!=null&&t.records.length)return e[r];return Object.values(e).find(r=>r.records.length)||Object.values(e)[0]}function $r(e){const t=e==null?void 0:e.result;if(!(!t||t.kind!=="records"&&t.kind!=="sql"))return{records:Ee(t.records,t.columns),columns:t.columns,rowCount:t.rowCount??t.records.length}}function _r(e){const t=e==null?void 0:e.result;return!t||t.kind!=="records"&&t.kind!=="sql"?[]:t.columns}function Fr(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object"&&!Array.isArray(t))):[]}function Ee(e,t){return t.length?e.map(r=>{const n={};return t.forEach((i,u)=>{const l=Wr(r,{name:i.key,label:i.label,fallbackNames:[i.name,Object.keys(r)[u]]});l!==void 0&&(n[i.key]=l)}),Object.keys(n).length?n:r}):e}function Nr(e){return Array.from(new Set(e.flatMap(r=>Object.keys(r)))).map(r=>({key:r,name:r,label:r}))}function Wr(e,t){const r=[t.name,t.label,...t.fallbackNames||[]].filter(n=>!!n);for(const n of r)if(Object.prototype.hasOwnProperty.call(e,n))return e[n]}function pt(){return{executeAnalysis:(e,t,r)=>F(e,t,r??{}).then(dt),executeMetric:(e,t)=>F(e,t),executeRecords:(e,t)=>F(e,t),executeInputOptions:(e,t)=>F(e,t),executeSql:(e,t)=>F(e,t),executeMatrix:(e,t)=>F(e,t)}}async function F(e,t,r){if(!t.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const n=Jr(t),i=Hr(e,n);let u;try{u=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},body:JSON.stringify({intent:e,activeInputs:t.activeInputs,...r?{analysisOptions:r}:{},resultShape:e.kind,...Vr(t)?{debug:{responseDetail:"debug"}}:{}})})}catch(p){throw new Error(`${i}: ${p instanceof Error?p.message:String(p)}`)}const l=await Ur(u);if(!u.ok||l.error)throw zr(`${i}: ${l.error||`Semaphor Data App execution failed with status ${u.status}.`}`,l);return l}function zr(e,t){const r=new Error(e);return t.requestId&&(r.requestId=t.requestId),t.details!==void 0&&(r.details=t.details),t.executionResult!==void 0&&(r.executionResult=t.executionResult),r}function Vr(e){const t=e.debug;return t?t===!0?!0:t.enabled!==!1&&t.requestServerDebug!==!1:!1}function Hr(e,t){return[`Semaphor ${e.kind} query`,e.id?`id=${e.id}`:void 0,e.label?`label=${e.label}`:void 0,Pr(e),`endpoint=${Qr(t)}`].filter(r=>!!r).join(" ")}function Pr(e){const t="source"in e?e.source:void 0;if(!(!t||typeof t!="object")){if(t.kind==="semantic")return`source=${[t.domainId,t.datasetId||t.datasetName].filter(Boolean).join("/")}`;if(t.kind==="physical")return`source=${[t.connectionId,t.databaseName,t.schemaName,t.tableName].filter(Boolean).join("/")}`;if(t.kind==="sql")return t.connectionId?`source=${t.connectionId}`:void 0}}function Qr(e){if(!e)return"/api/v1/data-app/execute";try{return new URL(e,"http://localhost").pathname}catch{return e}}async function Ur(e){const t=await e.text().catch(()=>"");if(!t.trim())return e.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(t)}catch{return e.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:t}:{error:Gr(e,t),details:t}}}function Gr(e,t){const r=e.statusText?` ${e.statusText}`:"",n=t.replace(/\s+/g," ").trim();return n?`Semaphor Data App execution failed with status ${e.status}${r}: ${n.slice(0,240)}`:`Semaphor Data App execution failed with status ${e.status}${r}.`}function Jr(e){const t=Yr(e).replace(/\/+$/,"");return t?t.endsWith("/api")?`${t}/v1/data-app/execute`:`${t}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function Yr(e){if(e.apiBaseUrl)return e.apiBaseUrl;if(!e.token)return"";try{return Qe.jwtDecode(e.token).apiServiceUrl||""}catch{return""}}const ft=d.createContext({});function Xr(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function Zr(){return d.useContext(ft)}const me={value:null},he={},en={records:[]},ge={options:[]},tn={records:[]},ye={};function rn(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs),r=S.toSemaphorAnalysisQueryOptions(e);try{const n=S.toSemaphorAnalysisIntent(e),i=z(n);return i?{error:i,activeInputs:t,analysisOptions:r,queryKey:q(void 0,t,i,r),idleData:he}:{intent:n,error:null,activeInputs:t,analysisOptions:r,queryKey:q(n,t,void 0,r),idleData:he}}catch(n){const i=B(n);return{error:i,activeInputs:t,analysisOptions:r,queryKey:q(void 0,t,i,r),idleData:he}}}function nn(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs);try{const r=S.toSemaphorMetricIntent(e),n=z(r);return n?{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:me}:{intent:r,error:null,activeInputs:t,queryKey:q(r,t),idleData:me}}catch(r){const n=B(r);return{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:me}}}function sn(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs),r=en;try{const n=S.toSemaphorRecordsIntent(e),i=z(n);return i?{error:i,activeInputs:t,queryKey:q(void 0,t,i),idleData:r}:{intent:n,error:null,activeInputs:t,queryKey:q(n,t),idleData:r}}catch(n){const i=B(n);return{error:i,activeInputs:t,queryKey:q(void 0,t,i),idleData:r}}}function on(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs);try{const r=S.toSemaphorInputOptionsIntent(e),n=z(r);return n?{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ge}:{intent:r,error:null,activeInputs:t,queryKey:q(r,t),idleData:ge}}catch(r){const n=B(r);return{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ge}}}function an(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs),r=tn;try{const n=S.toSemaphorSqlIntent(e),i=z(n);return i?{error:i,activeInputs:t,queryKey:q(void 0,t,i),idleData:r}:{intent:n,error:null,activeInputs:t,queryKey:q(n,t),idleData:r}}catch(n){const i=B(n);return{error:i,activeInputs:t,queryKey:q(void 0,t,i),idleData:r}}}function un(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs);try{const r=S.toSemaphorMatrixIntent(e),n=z(r);return n?{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ye}:{intent:r,error:null,activeInputs:t,queryKey:q(r,t),idleData:ye}}catch(r){const n=B(r);return{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ye}}}function B(e){return e instanceof Error?e:new Error(String(e))}function z(e){const t=vt.validateSemaphorAnalyticsIntent(e);if(t.ok)return null;const r=t.errors.map(n=>n.path?`${n.code} at ${n.path}: ${n.message}`:`${n.code}: ${n.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${r}`)}function q(e,t,r,n){return JSON.stringify({intent:e,activeInputs:t,analysisOptions:n,error:r==null?void 0:r.message})}function ln(e){const[t,r]=d.useState(e.defaultValue),n=Object.prototype.hasOwnProperty.call(e,"value"),i=n?e.value:t,u=d.useMemo(()=>S.normalizeSemaphorInputOptions(e.options),[e.options]),l=d.useCallback(c=>{var h;const f=c;(h=e.onValueChange)==null||h.call(e,f),n||r(f)},[n,e]),p=d.useCallback(()=>l(void 0),[l]);return d.useMemo(()=>{const c=S.toSemaphorInputSpec(e);return{id:e.id,kind:e.kind,label:e.label,field:c.field,operator:c.operator,relationshipHint:c.relationshipHint,controlRole:e.kind==="control"?e.role:void 0,value:i,options:u,isActive:S.hasSemaphorInputValue(i),setValue:l,clear:p,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:e.kind,label:e.label,value:i,isActive:S.hasSemaphorInputValue(i),operator:c.operator,relationshipHint:c.relationshipHint,controlRole:e.kind==="control"?e.role:void 0})}},[p,u,l,e,i])}function dn(e){const[t,r]=d.useState(()=>hn(e));return d.useEffect(()=>{r(n=>{let i=n;for(const u of e)!Object.prototype.hasOwnProperty.call(i,u.id)&&u.defaultValue!==void 0&&(i={...i,[u.id]:u.defaultValue});return i})},[e]),d.useMemo(()=>e.map(n=>{const i=Object.prototype.hasOwnProperty.call(n,"value"),u=i?n.value:t[n.id],l=S.normalizeSemaphorInputOptions(n.options),p=h=>{var g;(g=n.onValueChange)==null||g.call(n,h),i||r(y=>({...y,[n.id]:h}))},c=()=>p(void 0),f=S.toSemaphorInputSpec(n);return{id:n.id,kind:n.kind,label:n.label,field:f.field,operator:f.operator,relationshipHint:f.relationshipHint,controlRole:n.kind==="control"?n.role:void 0,value:u,options:l,isActive:S.hasSemaphorInputValue(u),setValue:p,clear:c,toAnalyticsInput:()=>({inputId:f.inputId,field:f.field,kind:n.kind,label:n.label,value:u,isActive:S.hasSemaphorInputValue(u),operator:f.operator,relationshipHint:f.relationshipHint,controlRole:n.kind==="control"?n.role:void 0})}}),[e,t])}function cn(e,t){const r=(t==null?void 0:t.status)==="success"?t.options:void 0,n=d.useMemo(()=>pn(r),[r]);d.useEffect(()=>{mt(e.value,r)||e.clear()},[e,n,t==null?void 0:t.status,r])}function mt(e,t){if(!S.hasSemaphorInputValue(e)||t===void 0)return!0;const r=new Set(t.map(i=>He(i.value)));return(Array.isArray(e)?e:[e]).every(i=>r.has(He(i)))}function pn(e){return JSON.stringify((e||[]).map(t=>t.value))}function He(e){return`${typeof e}:${String(e)}`}function fn(e,t={}){const r=d.useMemo(()=>t.inputs?{...e,inputs:t.inputs}:e,[t.inputs,e]),n=d.useMemo(()=>{switch(r.queryKind){case"metric":return{queryKind:r.queryKind,request:nn(r)};case"analysis":return{queryKind:r.queryKind,request:rn(r)};case"records":return{queryKind:r.queryKind,request:sn(r)};case"inputOptions":return{queryKind:r.queryKind,request:on(r)};case"sql":return{queryKind:r.queryKind,request:an(r)};case"matrix":return{queryKind:r.queryKind,request:un(r)};default:return ve(r)}},[r]),i=Ct({spec:r,queryKind:n.queryKind,queryKey:n.request.queryKey,intent:n.request.intent,activeInputs:n.request.activeInputs,debug:t.debug}),u=d.useRef(null),l=d.useMemo(()=>({start:i.start,success:i.success,failure:i.failure,ignored:i.ignored}),[i.failure,i.ignored,i.start,i.success]),p=d.useCallback(o=>{var T,E,v,w,C,R,k,I,D;const b=n.request;if(b.intent)switch(n.queryKind){case"metric":return(T=o.executor)==null?void 0:T.executeMetric(b.intent,o);case"analysis":return(v=(E=o.executor)==null?void 0:E.executeAnalysis)==null?void 0:v.call(E,b.intent,o,b.analysisOptions);case"records":return(w=o.executor)==null?void 0:w.executeRecords(b.intent,o);case"inputOptions":return(C=o.executor)==null?void 0:C.executeInputOptions(b.intent,o);case"sql":return(k=(R=o.executor)==null?void 0:R.executeSql)==null?void 0:k.call(R,b.intent,o);case"matrix":return(D=(I=o.executor)==null?void 0:I.executeMatrix)==null?void 0:D.call(I,b.intent,o);default:return ve(n)}},[n]),c=mn(n.request.queryKey,p,n.request.idleData,n.request.activeInputs,l),f=i.queryId,h=i.validationFailure;d.useEffect(()=>{const o=n.request.error;if(!o){u.current=null;return}const b=`${f}:${o.message}`;u.current!==b&&(u.current=b,h(o))},[n.request.error,n.request.queryKey,f,h]);const g=n.request.error?n.request.idleData:c.data,y=n.request.error?"error":c.status,m=!n.request.error&&c.status==="loading",x=n.request.error||c.error,A=i.trace;switch(n.queryKind){case"metric":{const o=g;return{id:r.id,intent:n.request.intent,value:(o==null?void 0:o.value)??null,measures:o==null?void 0:o.measures,comparisonValue:o==null?void 0:o.comparisonValue,delta:o==null?void 0:o.delta,deltaPercent:o==null?void 0:o.deltaPercent,records:o==null?void 0:o.records,executionResult:o==null?void 0:o.executionResult,status:y,isLoading:m,error:x,trace:A}}case"analysis":{const o=dt(g);return{id:r.id,intent:n.request.intent,...o||{},status:y,isLoading:m,error:x,trace:A}}case"records":{const o=g;return{id:r.id,intent:n.request.intent,records:(o==null?void 0:o.records)||[],columns:o==null?void 0:o.columns,rowCount:o==null?void 0:o.rowCount,pagination:o==null?void 0:o.pagination,executionResult:o==null?void 0:o.executionResult,status:y,isLoading:m,error:x,trace:A}}case"inputOptions":{const o=g;return{id:r.id,intent:n.request.intent,options:(o==null?void 0:o.options)||[],executionResult:o==null?void 0:o.executionResult,status:y,isLoading:m,error:x,trace:A}}case"sql":{const o=g;return{id:r.id,intent:n.request.intent,records:(o==null?void 0:o.records)||[],columns:o==null?void 0:o.columns,rowCount:o==null?void 0:o.rowCount,pagination:o==null?void 0:o.pagination,output:o==null?void 0:o.output,rowLimitExceeded:o==null?void 0:o.rowLimitExceeded,executionResult:o==null?void 0:o.executionResult,status:y,isLoading:m,error:x,trace:A}}case"matrix":{const o=g;return{id:r.id,intent:n.request.intent,matrixResult:o==null?void 0:o.matrixResult,grid:o==null?void 0:o.grid,expansion:o==null?void 0:o.expansion,executionResult:o==null?void 0:o.executionResult,status:y,isLoading:m,error:x,trace:A}}default:return ve(n)}}function mn(e,t,r,n,i){const u=Zr(),l=d.useRef(t),p=d.useRef(n),[c,f]=d.useState({status:"idle",data:r,error:null});return l.current=t,p.current=n,d.useEffect(()=>{let h;try{h=l.current({...u,activeInputs:p.current})}catch(m){i==null||i.failure(m,0),f({status:"error",data:r,error:B(m)});return}if(!h){f({status:"idle",data:r,error:null});return}let g=!1;const y=ht();return i==null||i.start(),f(m=>({status:"loading",data:m.data,error:null})),h.then(m=>{g?i==null||i.ignored("superseded"):(i==null||i.success(m,Pe(y)),f({status:"success",data:m,error:null}))}).catch(m=>{g?i==null||i.ignored("superseded"):(i==null||i.failure(m,Pe(y)),f({status:"error",data:r,error:B(m)}))}),()=>{g=!0}},[r,e,u,i]),c}function ht(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}function Pe(e){return Math.max(0,Math.round(ht()-e))}function hn(e){return Object.fromEntries(e.filter(t=>t.defaultValue!==void 0).map(t=>[t.id,t.defaultValue]))}function ve(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function gn(e){return!e||typeof e=="boolean"||e.enabled===!1?null:e.autoRenderDevtools===!0?{}:e.autoRenderDevtools?e.autoRenderDevtools:null}function yn({token:e,apiBaseUrl:t,executor:r,debug:n,children:i}){var m;const u=Xr(),l=((m=u==null?void 0:u.authToken)==null?void 0:m.accessToken)||e,p=(u==null?void 0:u.dataApiBaseUrl)||(u==null?void 0:u.apiBaseUrl)||t,c=(u==null?void 0:u.debug)??n,f=gn(c),h=d.useMemo(()=>pt(),[]),g=r||h,y=d.useMemo(()=>({token:l,apiBaseUrl:p,executor:g,debug:c}),[p,c,g,l]);return s.jsx(qt,{debug:c,children:s.jsxs(ft.Provider,{value:y,children:[i,f?s.jsx(Je,{...f}):null]})})}exports.SemaphorDataAppProvider=yn;exports.SemaphorDevtools=Je;exports.SemaphorDevtoolsInspectButton=Et;exports.SemaphorViewBoundary=Rt;exports.createSemaphorQueryExecutor=pt;exports.defineSemaphorDataApp=xt;exports.defineSemaphorInput=bt;exports.isSemaphorInputValueValidForOptions=mt;exports.semaphor=St;exports.useClearInvalidSemaphorInputValue=cn;exports.useSemaphorDevtools=qe;exports.useSemaphorInput=ln;exports.useSemaphorInputs=dn;exports.useSemaphorQuery=fn;
|
|
68
|
+
`;function ot(){if(typeof document>"u"||document.getElementById(_e))return;const e=document.createElement("style");e.id=_e,e.textContent=hr,document.head.appendChild(e)}const Z='ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',ee="ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",fe={color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},u={launcher:{position:"fixed",bottom:20,zIndex:2147483e3,display:"inline-flex",alignItems:"center",gap:7,height:36,minWidth:36,padding:"0 10px",borderWidth:1,borderStyle:"solid",borderRadius:6,boxShadow:"var(--sd-shadow)",font:`600 12px/1.2 ${Z}`,cursor:"pointer"},launcherText:{fontVariantNumeric:"tabular-nums"},launcherIssueCount:{display:"grid",minWidth:16,height:16,placeItems:"center",borderRadius:8,background:"currentColor",color:"var(--sd-bg)",fontSize:10,lineHeight:"16px"},logoMark:{display:"grid",width:18,height:18,placeItems:"center",flex:"0 0 auto",borderRadius:4,background:"var(--sd-fg)",color:"var(--sd-bg)"},panel:{position:"fixed",top:16,right:16,bottom:16,zIndex:2147483001,width:"min(720px, calc(100vw - 32px))",display:"flex",flexDirection:"column",overflow:"hidden",border:"1px solid var(--sd-border)",borderRadius:6,background:"var(--sd-bg)",color:"var(--sd-fg)",boxShadow:"var(--sd-shadow)",font:`13px/1.4 ${Z}`},panelFullscreen:{top:0,right:0,bottom:0,left:0,width:"100vw",height:"100vh",borderRadius:0},panelHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--sd-border)"},panelTitleBlock:{minWidth:0},panelTitle:{fontSize:13,fontWeight:600},panelSubtitle:{marginTop:2,color:"var(--sd-fg-muted)",fontSize:11},panelActions:{display:"flex",alignItems:"center",gap:6},iconButton:{display:"grid",width:28,height:28,placeItems:"center",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,background:"var(--sd-bg)",color:"var(--sd-fg-muted)",cursor:"pointer"},searchBox:{display:"flex",alignItems:"center",gap:8,margin:10,height:28,padding:"0 8px",borderWidth:1,borderStyle:"solid",borderColor:"var(--sd-border)",borderRadius:5,color:"var(--sd-fg-muted)"},searchInput:{minWidth:0,flex:1,border:0,outline:0,background:"transparent",color:"var(--sd-fg)",font:`12px/1.4 ${Z}`},panelBody:{display:"grid",gridTemplateColumns:"minmax(210px, 280px) minmax(0, 1fr)",minHeight:0,flex:1,borderTop:"1px solid var(--sd-border-soft)"},queryList:{minHeight:0,overflowY:"auto",padding:8,borderRight:"1px solid var(--sd-border)",background:"var(--sd-bg-muted)"},queryGroup:{display:"grid",gap:3,marginBottom:8},queryGroupHeader:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 6px 3px",...fe},queryGroupCount:{color:"var(--sd-fg-subtle)",fontVariantNumeric:"tabular-nums"},queryGroupEmpty:{padding:"7px 8px",color:"var(--sd-fg-subtle)",fontSize:11},queryListItem:{display:"grid",gap:3,width:"100%",padding:"7px 8px",borderWidth:1,borderStyle:"solid",borderColor:"transparent",borderRadius:5,background:"transparent",color:"var(--sd-fg)",textAlign:"left",cursor:"pointer"},queryListItemSelected:{borderColor:"var(--sd-border-strong)",background:"var(--sd-bg-raised)"},queryListItemHeader:{display:"flex",alignItems:"center",gap:7,minWidth:0},statusDot:{width:7,height:7,flex:"0 0 auto",borderRadius:999},queryListTitle:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:650,color:"var(--sd-fg)"},queryListKindChip:{flex:"0 0 auto",color:"var(--sd-fg-subtle)",fontSize:9,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},queryListSource:{minWidth:0,paddingLeft:14,color:"var(--sd-fg-muted)",fontSize:11,lineHeight:1.35},queryListSourceSecondary:{minWidth:0,paddingLeft:14,color:"var(--sd-fg-subtle)",fontSize:10,lineHeight:1.3},detailsPane:{minHeight:0,overflowY:"auto",padding:16},detailsHeader:{display:"grid",gap:6,marginBottom:14},detailsHeaderTopRow:{display:"flex",alignItems:"center",gap:8,minWidth:0},detailsHeaderStatusDot:{width:8,height:8,flex:"0 0 auto",borderRadius:999},detailsTitle:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:14,fontWeight:700,color:"var(--sd-fg)"},detailsKindChip:{flex:"0 0 auto",padding:"2px 6px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},detailsCaption:{display:"flex",flexWrap:"wrap",alignItems:"center",columnGap:10,rowGap:2,color:"var(--sd-fg-muted)",fontSize:11},detailsCaptionItem:{display:"inline-flex",alignItems:"center",gap:4},detailsCaptionItemMono:{fontFamily:ee},detailsCaptionLabel:{color:"var(--sd-fg-subtle)"},detailsCaptionValue:{color:"var(--sd-fg)",fontVariantNumeric:"tabular-nums"},disclosure:{marginTop:16},disclosureSummary:{cursor:"pointer",...fe},disclosureBody:{marginTop:8},alertCard:{marginTop:12,padding:"8px 10px",borderWidth:1,borderStyle:"solid",borderRadius:5,fontSize:12,lineHeight:1.45},alertCardError:{borderColor:"var(--sd-error-border)",background:"var(--sd-error-bg)",color:"var(--sd-error-fg)"},alertCardWarning:{borderColor:"var(--sd-warning-border)",background:"var(--sd-warning-bg)",color:"var(--sd-warning-fg)"},alertCardTitle:{fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em",fontSize:10,marginBottom:4},alertCardList:{margin:0,paddingLeft:16,display:"grid",gap:3},recipe:{display:"grid",gap:12},traceLineage:{display:"grid",gap:12},recipeSummary:{display:"grid",gap:4,padding:"8px 10px",border:"1px solid var(--sd-border)",borderRadius:5,background:"var(--sd-bg-muted)",color:"var(--sd-fg)",fontSize:12},recipeSummaryRow:{display:"grid",gridTemplateColumns:"76px minmax(0, 1fr)",gap:8,minWidth:0,alignItems:"baseline"},recipeSummaryLabel:{color:"var(--sd-fg-subtle)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},recipeSummaryValue:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12},recipeGroup:{display:"grid",gap:4},recipeGroupHeader:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,paddingBottom:4,borderBottom:"1px solid var(--sd-border-soft)"},recipeGroupTitle:{color:"var(--sd-fg-muted)",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em"},recipeGroupCount:{color:"var(--sd-fg-subtle)",fontSize:10,fontVariantNumeric:"tabular-nums"},recipeFieldList:{display:"grid"},recipeEmptyText:{padding:"5px 0",color:"var(--sd-fg-subtle)",fontSize:11},recipeFieldRow:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, auto)",alignItems:"center",gap:10,minHeight:26,padding:"4px 0",borderBottom:"1px solid var(--sd-border-soft)"},recipeFieldName:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,fontWeight:500},recipeFieldMeta:{minWidth:0,display:"inline-flex",alignItems:"baseline",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-subtle)",fontSize:11,textAlign:"right"},recipeFieldMetaDivider:{color:"var(--sd-fg-subtle)",margin:"0 4px"},inputsAppliedBlock:{marginTop:16,padding:"10px 12px",border:"1px solid var(--sd-border)",borderLeft:"2px solid var(--sd-fg-muted)",borderRadius:5,background:"var(--sd-bg-muted)"},inputsAppliedHeader:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:8,marginBottom:6},inputsAppliedTitle:{color:"var(--sd-fg)",fontSize:10,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.08em"},inputsAppliedCount:{color:"var(--sd-fg-subtle)",fontSize:10,fontVariantNumeric:"tabular-nums"},inputRecipeList:{display:"grid"},inputRecipeRow:{display:"grid",gap:2,minWidth:0,padding:"6px 0",borderBottom:"1px solid var(--sd-border-soft)"},inputRecipeHeader:{display:"flex",alignItems:"center",gap:8,minWidth:0},inputRecipeId:{flex:"0 0 auto",maxWidth:"40%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontFamily:ee,fontSize:11,fontWeight:600},inputOperatorBadge:{display:"inline-flex",flex:"0 0 auto",alignItems:"center",height:16,padding:"0 5px",borderRadius:3,background:"var(--sd-bg-accent)",color:"var(--sd-fg-muted)",fontFamily:ee,fontSize:10,textTransform:"uppercase",letterSpacing:"0.06em"},inputValuePreview:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg)",fontSize:12,textAlign:"right"},inputRecipeBinding:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-muted)",fontSize:11},eventList:{display:"grid"},eventRow:{display:"grid",gridTemplateColumns:"96px minmax(0, 1fr)",gap:10,padding:"6px 0",borderBottom:"1px solid var(--sd-border-soft)"},eventType:{color:"var(--sd-fg)",fontWeight:600,fontSize:12},eventMeta:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--sd-fg-muted)",fontSize:11},mutedText:{color:"var(--sd-fg-muted)",fontSize:12},compiledQuery:{display:"grid",gap:10},codeBlockGroup:{display:"grid",gap:5},codeBlockLabel:{...fe},codeBlock:{maxHeight:260,margin:0,overflow:"auto",padding:"8px 10px",border:"1px solid var(--sd-border)",borderRadius:5,background:"var(--sd-bg-muted)",color:"var(--sd-fg)",fontFamily:ee,fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap"},emptyState:{padding:10,color:"var(--sd-fg-muted)",textAlign:"center",fontSize:12},inspectButton:{display:"inline-flex",alignItems:"center",gap:5,height:24,maxWidth:"100%",padding:"0 7px",borderWidth:1,borderStyle:"solid",borderRadius:5,background:"var(--sd-bg)",font:`600 11px/1 ${Z}`,cursor:"pointer"},inspectButtonText:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}};function at(e){return{...e,order:[],entries:{},sequence:0}}function gr(e,t){if(t.type==="config")return t.config.enabled?{...e,...t.config}:at(t.config);if(!e.enabled)return e;switch(t.type){case"register":return Sr(vr(e,t.descriptor));case"unregister":return xr(e,t.traceKey);case"event":return br(e,t);default:return e}}function vr(e,t){const r=e.entries[t.traceKey],n=r?e.sequence:e.sequence+1,i=Ee(),o={...r||Ir(t),...ut(t),traceKey:t.traceKey,latestAttempt:(r==null?void 0:r.latestAttempt)||{status:"idle"},recentEvents:(r==null?void 0:r.recentEvents)||[],mounted:!0,registeredAt:(r==null?void 0:r.registeredAt)||n,lastEventAt:(r==null?void 0:r.lastEventAt)||i};return{...e,sequence:n,order:r?e.order:[...e.order,t.traceKey],entries:{...e.entries,[t.traceKey]:o}}}function xr(e,t){const r=e.entries[t];return r?{...e,entries:{...e.entries,[t]:{...r,mounted:!1}}}:e}function br(e,t){const r=e.entries[t.traceKey];if(!r)return e;const n=Ee(),i=[...r.recentEvents,t.event].slice(-e.maxEventsPerQuery);return{...e,entries:{...e.entries,[t.traceKey]:{...r,latestAttempt:t.latestAttempt?{...r.latestAttempt,...t.latestAttempt}:r.latestAttempt,recentEvents:i,lastEventAt:n}}}}function Sr(e){if(e.order.length<=e.maxQueries)return e;const t=e.order.map(i=>e.entries[i]).filter(i=>!!i).sort((i,o)=>i.mounted!==o.mounted?i.mounted?1:-1:i.lastEventAt-o.lastEventAt),r=e.order.length-e.maxQueries,n=new Set(t.slice(0,r).map(i=>i.traceKey));return n.size?{...e,order:e.order.filter(i=>!n.has(i)),entries:Object.fromEntries(Object.entries(e.entries).filter(([i])=>!n.has(i)))}:e}function Ir(e){const t=Ee();return{...ut(e),traceKey:e.traceKey,latestAttempt:{status:"idle"},recentEvents:[],mounted:!0,registeredAt:0,lastEventAt:t}}function ut(e){var n;const t=Lr(e.spec),r=Or(e.spec,e.activeInputs);return{traceId:pt(e.traceKey),viewId:e.viewId,viewTitle:e.viewTitle,visualType:e.visualType,sectionTitle:e.sectionTitle,queryId:e.queryId,queryLabel:e.queryLabel,queryKind:e.queryKind,builder:e.builder,sourceRefs:Dr(e.intent),sourceHints:(n=e.sourceHints)!=null&&n.length?e.sourceHints:void 0,projectionFieldRefs:t,inputFieldRefs:r,fieldRefs:Br(e.intent),inputsApplied:(e.activeInputs||[]).map(i=>({inputId:i.inputId,fieldRef:i.field,operator:i.operator,valuePreview:Cr(i)})),recentEvents:[],clientWarnings:e.clientWarnings}}function ie(e){const{traceKey:t,mounted:r,registeredAt:n,lastEventAt:i,...o}=e;return o}function se(e){return e.enabled?{enabled:!0,queries:e.order.map(r=>e.entries[r]).filter(r=>!!r).map(ie),getQuery:r=>{const n=Object.values(e.entries).find(i=>i.queryId===r);return n?ie(n):void 0},getQueries:r=>Object.values(e.entries).filter(n=>n.queryId===r).map(ie)}:Je}function wr(e){return{snapshot:()=>qr(se(e())),getQuery:t=>Ne(se(e()).getQuery(t)),getQueries:t=>se(e()).getQueries(t).map(r=>Ne(r)).filter(r=>!!r)}}function qr(e){if(!e.enabled)return e;const t=e.queries.map(lt);return{enabled:e.enabled,queries:t,getQuery:r=>t.find(n=>n.queryId===r),getQueries:r=>t.filter(n=>n.queryId===r)}}function Ne(e){return e?lt(e):void 0}function lt(e){var t;return(t=e==null?void 0:e.latestAttempt)!=null&&t.executionResult?{...e,latestAttempt:{...e.latestAttempt,executionResult:jr(e.latestAttempt.executionResult)}}:e}function jr(e){const{compiledQuery:t,intent:r,result:n,...i}=e,o=Ar(i.metadata);return{...i,...o?{metadata:o}:{}}}function Ar(e){if(!e||typeof e!="object"||Array.isArray(e))return e;const t=e.dataAppDebug;if(!t||typeof t!="object"||Array.isArray(t))return e;const{compiledSql:r,...n}=t;return{...e,dataAppDebug:n}}function Rr(e){return e===void 0||e===!1?{enabled:!1,exposeWindowBridge:!1,maxEventsPerQuery:de,maxQueries:ce}:e===!0?{enabled:!0,exposeWindowBridge:!1,maxEventsPerQuery:de,maxQueries:ce}:{enabled:e.enabled!==!1,exposeWindowBridge:e.exposeWindowBridge===!0,maxEventsPerQuery:ze(e.maxEventsPerQuery,de,jt),maxQueries:ze(e.maxQueries,ce,At)}}function Fe(e){const r=[e==null?void 0:e.sourceHint,...(e==null?void 0:e.sourceHints)||[]].filter(n=>!!n).map(n=>({file:te(n.file),line:We(n.line),column:We(n.column),exportName:te(n.exportName),component:te(n.component),note:te(n.note)})).filter(n=>!!(n.file||n.line||n.column||n.exportName||n.component||n.note));return r.length?r:void 0}function te(e){if(typeof e!="string")return;const t=e.trim();return t||void 0}function We(e){return typeof e=="number"&&Number.isInteger(e)&&e>0?e:void 0}function ze(e,t,r){return e===void 0||!Number.isFinite(e)||!Number.isInteger(e)||e<=0?t:Math.min(e,r)}function Er(e){return typeof e.id=="string"&&e.id.trim()?e.id:void 0}function Tr(e){switch(e){case"metric":return"semaphor.metric";case"records":return"semaphor.records";case"matrix":return"semaphor.matrix";case"analysis":return"semaphor.analysis";case"inputOptions":return"semaphor.inputOptions";case"sql":return"semaphor.sql";default:return ue(e)}}function ue(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function Cr(e){if(kr(e))return;const t=e.value;if(t!==void 0){if(Array.isArray(t)){const r=t.filter(n=>typeof n=="string"||typeof n=="number"||typeof n=="boolean").map(n=>String(n));if(r.length===t.length&&r.length>0){const n=r.slice(0,3).join(", "),i=r.length>3?`, +${r.length-3} more`:"";return Ve(`${n}${i}`)}return`${t.length} selected`}return typeof t=="number"||typeof t=="boolean"?String(t):typeof t=="string"?Ve(t):t&&typeof t=="object"?`object(${Object.keys(t).slice(0,5).join(",")})`:String(t)}}function Ve(e){return e.length>80?`${e.slice(0,77)}...`:e}function kr(e){var r;const t=[e.inputId,e.label,(r=e.field)==null?void 0:r.name].filter(Boolean).join(" ").toLowerCase();return["token","secret","password","email","phone","ssn"].some(n=>t.includes(n))}function Dr(e){const t=new Map;return oe(e,r=>{Kr(r)&&t.set(ct(r),r)}),[...t.values()]}function Lr(e){switch(e.queryKind){case"metric":case"analysis":return F([...e.measures||[],e.primaryMeasure,e.dateField,...e.dimensions||[]]);case"records":return F(e.fields||[]);case"inputOptions":return F([e.labelField,e.valueField,e.searchField,...e.disambiguationFields||[]]);case"sql":return F(e.fields||[]);case"matrix":return F([...(e.rows||[]).map(me),...(e.columns||[]).map(me),...(e.values||[]).map(me)]);default:return ue(e)}}function Or(e,t){const r=[...(e.inputs||[]).map(dt),...(t||[]).map(n=>n.field)];return F(r)}function F(e){const t=new Map;return e.forEach(r=>{r&&J(r)&&t.set(Re(r),r)}),[...t.values()]}function dt(e){if(!e||typeof e!="object")return;const t=e.toAnalyticsInput;if(typeof t=="function"){const n=t.call(e);return dt(n)}const r=e.field;return J(r)?r:void 0}function me(e){if(J(e))return e;if(!e||typeof e!="object")return;const t=e.field;return J(t)?t:void 0}function Br(e){const t=new Map;return oe(e,r=>{J(r)&&t.set(Re(r),r)}),[...t.values()]}function oe(e,t){if(!(!e||typeof e!="object")){if(t(e),Array.isArray(e)){e.forEach(r=>oe(r,t));return}Object.values(e).forEach(r=>oe(r,t))}}function Kr(e){if(!e||typeof e!="object")return!1;const t=e;return t.kind==="semantic"?typeof t.domainId=="string"&&typeof t.datasetName=="string":t.kind==="physical"?typeof t.connectionId=="string"&&typeof t.tableName=="string":t.kind==="sql"?typeof t.connectionId=="string":!1}function J(e){if(!e||typeof e!="object")return!1;const t=e;return typeof t.name=="string"&&(t.source!==void 0||t.role!==void 0||t.dataType!==void 0||t.aggregate!==void 0)}function ct(e){return e.kind==="semantic"?[e.kind,e.domainId,e.datasetId||e.datasetName].join(":"):e.kind==="physical"?[e.kind,e.connectionId,e.databaseName,e.schemaName,e.tableName].join(":"):[e.kind,e.connectionId].join(":")}function Re(e){return[e.name,e.role,e.aggregate,e.source?ct(e.source):""].join(":")}function Mr(e){const t=e;return typeof(t==null?void 0:t.rowCount)=="number"?t.rowCount:Array.isArray(t==null?void 0:t.records)?t.records.length:void 0}function $r(e){const t=e;return Array.isArray(t==null?void 0:t.columns)?t.columns.length:void 0}function He(e){const t=e;return t==null?void 0:t.executionResult}function Pe(e){const t=e;return typeof(t==null?void 0:t.requestId)=="string"?t.requestId:void 0}function pt(e){let t=2166136261;for(let r=0;r<e.length;r+=1)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function re(){return new Date().toISOString()}function Ee(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}const _r=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],Nr=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function ft(e){if(!e)return{};const t=Hr(e.executionResult),r=Fr(e,t),n=zr(r);return{...e,...Object.keys(r).length?{resultSets:r}:{},...n?{columns:n.columns,records:n.records,rowCount:n.rowCount}:{}}}function Fr(e,t){const r=Wr(e.resultSets);for(const i of _r){if(r[i]){r[i]=mt(r[i]);continue}const o=Pr(e[i]);if(!o.length)continue;const l=t.length?t:Qr(o);r[i]={records:Te(o,l),columns:l,rowCount:o.length}}const n=Vr(e.executionResult);return n&&n.records.length>0&&!r.records&&(r.records=n),r}function Wr(e){return Object.fromEntries(Object.entries(e||{}).map(([t,r])=>[t,mt(r)]))}function mt(e){var t;return{...e,records:Te(e.records||[],e.columns||[]),rowCount:e.rowCount??((t=e.records)==null?void 0:t.length)??0}}function zr(e){var t;for(const r of Nr)if((t=e[r])!=null&&t.records.length)return e[r];return Object.values(e).find(r=>r.records.length)||Object.values(e)[0]}function Vr(e){const t=e==null?void 0:e.result;if(!(!t||t.kind!=="records"&&t.kind!=="sql"))return{records:Te(t.records,t.columns),columns:t.columns,rowCount:t.rowCount??t.records.length}}function Hr(e){const t=e==null?void 0:e.result;return!t||t.kind!=="records"&&t.kind!=="sql"?[]:t.columns}function Pr(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object"&&!Array.isArray(t))):[]}function Te(e,t){return t.length?e.map(r=>{const n={};return t.forEach((i,o)=>{const l=Ur(r,{name:i.key,label:i.label,fallbackNames:[i.name,Object.keys(r)[o]]});l!==void 0&&(n[i.key]=l)}),Object.keys(n).length?n:r}):e}function Qr(e){return Array.from(new Set(e.flatMap(r=>Object.keys(r)))).map(r=>({key:r,name:r,label:r}))}function Ur(e,t){const r=[t.name,t.label,...t.fallbackNames||[]].filter(n=>!!n);for(const n of r)if(Object.prototype.hasOwnProperty.call(e,n))return e[n]}function yt(){return{executeAnalysis:(e,t,r)=>N(e,t,r??{}).then(ft),executeMetric:(e,t)=>N(e,t),executeRecords:(e,t)=>N(e,t),executeInputOptions:(e,t)=>N(e,t),executeSql:(e,t)=>N(e,t),executeMatrix:(e,t)=>N(e,t)}}async function N(e,t,r){if(!t.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const n=rn(t),i=Yr(e,n);let o;try{o=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},body:JSON.stringify({intent:e,activeInputs:t.activeInputs,...r?{analysisOptions:r}:{},resultShape:e.kind,...Jr(t)?{debug:{responseDetail:"debug"}}:{}})})}catch(p){throw new Error(`${i}: ${p instanceof Error?p.message:String(p)}`)}const l=await en(o);if(!o.ok||l.error)throw Gr(`${i}: ${l.error||`Semaphor Data App execution failed with status ${o.status}.`}`,l);return l}function Gr(e,t){const r=new Error(e);return t.requestId&&(r.requestId=t.requestId),t.details!==void 0&&(r.details=t.details),t.executionResult!==void 0&&(r.executionResult=t.executionResult),r}function Jr(e){const t=e.debug;return t?t===!0?!0:t.enabled!==!1&&t.requestServerDebug!==!1:!1}function Yr(e,t){return[`Semaphor ${e.kind} query`,e.id?`id=${e.id}`:void 0,e.label?`label=${e.label}`:void 0,Xr(e),`endpoint=${Zr(t)}`].filter(r=>!!r).join(" ")}function Xr(e){const t="source"in e?e.source:void 0;if(!(!t||typeof t!="object")){if(t.kind==="semantic")return`source=${[t.domainId,t.datasetId||t.datasetName].filter(Boolean).join("/")}`;if(t.kind==="physical")return`source=${[t.connectionId,t.databaseName,t.schemaName,t.tableName].filter(Boolean).join("/")}`;if(t.kind==="sql")return t.connectionId?`source=${t.connectionId}`:void 0}}function Zr(e){if(!e)return"/api/v1/data-app/execute";try{return new URL(e,"http://localhost").pathname}catch{return e}}async function en(e){const t=await e.text().catch(()=>"");if(!t.trim())return e.ok?{error:"Semaphor Data App execution returned an empty response."}:{};try{return JSON.parse(t)}catch{return e.ok?{error:"Semaphor Data App execution returned invalid JSON.",details:t}:{error:tn(e,t),details:t}}}function tn(e,t){const r=e.statusText?` ${e.statusText}`:"",n=t.replace(/\s+/g," ").trim();return n?`Semaphor Data App execution failed with status ${e.status}${r}: ${n.slice(0,240)}`:`Semaphor Data App execution failed with status ${e.status}${r}.`}function rn(e){const t=nn(e).replace(/\/+$/,"");return t?t.endsWith("/api")?`${t}/v1/data-app/execute`:`${t}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function nn(e){if(e.apiBaseUrl)return e.apiBaseUrl;if(!e.token)return"";try{return Ge.jwtDecode(e.token).apiServiceUrl||""}catch{return""}}const ht=d.createContext({});function sn(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function on(){return d.useContext(ht)}const ye={value:null},he={},an={records:[]},ge={options:[]},un={records:[]},ve={};function ln(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs),r=S.toSemaphorAnalysisQueryOptions(e);try{const n=S.toSemaphorAnalysisIntent(e),i=z(n);return i?{error:i,activeInputs:t,analysisOptions:r,queryKey:q(void 0,t,i,r),idleData:he}:{intent:n,error:null,activeInputs:t,analysisOptions:r,queryKey:q(n,t,void 0,r),idleData:he}}catch(n){const i=B(n);return{error:i,activeInputs:t,analysisOptions:r,queryKey:q(void 0,t,i,r),idleData:he}}}function dn(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs);try{const r=S.toSemaphorMetricIntent(e),n=z(r);return n?{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ye}:{intent:r,error:null,activeInputs:t,queryKey:q(r,t),idleData:ye}}catch(r){const n=B(r);return{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ye}}}function cn(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs),r=an;try{const n=S.toSemaphorRecordsIntent(e),i=z(n);return i?{error:i,activeInputs:t,queryKey:q(void 0,t,i),idleData:r}:{intent:n,error:null,activeInputs:t,queryKey:q(n,t),idleData:r}}catch(n){const i=B(n);return{error:i,activeInputs:t,queryKey:q(void 0,t,i),idleData:r}}}function pn(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs);try{const r=S.toSemaphorInputOptionsIntent(e),n=z(r);return n?{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ge}:{intent:r,error:null,activeInputs:t,queryKey:q(r,t),idleData:ge}}catch(r){const n=B(r);return{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ge}}}function fn(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs),r=un;try{const n=S.toSemaphorSqlIntent(e),i=z(n);return i?{error:i,activeInputs:t,queryKey:q(void 0,t,i),idleData:r}:{intent:n,error:null,activeInputs:t,queryKey:q(n,t),idleData:r}}catch(n){const i=B(n);return{error:i,activeInputs:t,queryKey:q(void 0,t,i),idleData:r}}}function mn(e){const t=S.toSemaphorActiveInputSnapshots(e.inputs);try{const r=S.toSemaphorMatrixIntent(e),n=z(r);return n?{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ve}:{intent:r,error:null,activeInputs:t,queryKey:q(r,t),idleData:ve}}catch(r){const n=B(r);return{error:n,activeInputs:t,queryKey:q(void 0,t,n),idleData:ve}}}function B(e){return e instanceof Error?e:new Error(String(e))}function z(e){const t=St.validateSemaphorAnalyticsIntent(e);if(t.ok)return null;const r=t.errors.map(n=>n.path?`${n.code} at ${n.path}: ${n.message}`:`${n.code}: ${n.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${r}`)}function q(e,t,r,n){return JSON.stringify({intent:e,activeInputs:t,analysisOptions:n,error:r==null?void 0:r.message})}function yn(e){const[t,r]=d.useState(e.defaultValue),n=Object.prototype.hasOwnProperty.call(e,"value"),i=n?e.value:t,o=d.useMemo(()=>S.normalizeSemaphorInputOptions(e.options),[e.options]),l=d.useCallback(c=>{var y;const f=c;(y=e.onValueChange)==null||y.call(e,f),n||r(f)},[n,e]),p=d.useCallback(()=>l(void 0),[l]);return d.useMemo(()=>{const c=S.toSemaphorInputSpec(e);return{id:e.id,kind:e.kind,label:e.label,field:c.field,operator:c.operator,relationshipHint:c.relationshipHint,controlRole:e.kind==="control"?e.role:void 0,value:i,options:o,isActive:S.hasSemaphorInputValue(i),setValue:l,clear:p,toAnalyticsInput:()=>({inputId:c.inputId,field:c.field,kind:e.kind,label:e.label,value:i,isActive:S.hasSemaphorInputValue(i),operator:c.operator,relationshipHint:c.relationshipHint,controlRole:e.kind==="control"?e.role:void 0})}},[p,o,l,e,i])}function hn(e){const[t,r]=d.useState(()=>Sn(e));return d.useEffect(()=>{r(n=>{let i=n;for(const o of e)!Object.prototype.hasOwnProperty.call(i,o.id)&&o.defaultValue!==void 0&&(i={...i,[o.id]:o.defaultValue});return i})},[e]),d.useMemo(()=>e.map(n=>{const i=Object.prototype.hasOwnProperty.call(n,"value"),o=i?n.value:t[n.id],l=S.normalizeSemaphorInputOptions(n.options),p=y=>{var h;(h=n.onValueChange)==null||h.call(n,y),i||r(g=>({...g,[n.id]:y}))},c=()=>p(void 0),f=S.toSemaphorInputSpec(n);return{id:n.id,kind:n.kind,label:n.label,field:f.field,operator:f.operator,relationshipHint:f.relationshipHint,controlRole:n.kind==="control"?n.role:void 0,value:o,options:l,isActive:S.hasSemaphorInputValue(o),setValue:p,clear:c,toAnalyticsInput:()=>({inputId:f.inputId,field:f.field,kind:n.kind,label:n.label,value:o,isActive:S.hasSemaphorInputValue(o),operator:f.operator,relationshipHint:f.relationshipHint,controlRole:n.kind==="control"?n.role:void 0})}}),[e,t])}function gn(e,t){const r=(t==null?void 0:t.status)==="success"?t.options:void 0,n=d.useMemo(()=>vn(r),[r]);d.useEffect(()=>{gt(e.value,r)||e.clear()},[e,n,t==null?void 0:t.status,r])}function gt(e,t){if(!S.hasSemaphorInputValue(e)||t===void 0)return!0;const r=new Set(t.map(i=>Qe(i.value)));return(Array.isArray(e)?e:[e]).every(i=>r.has(Qe(i)))}function vn(e){return JSON.stringify((e||[]).map(t=>t.value))}function Qe(e){return`${typeof e}:${String(e)}`}function xn(e,t={}){const r=d.useMemo(()=>t.inputs?{...e,inputs:t.inputs}:e,[t.inputs,e]),n=d.useMemo(()=>{switch(r.queryKind){case"metric":return{queryKind:r.queryKind,request:dn(r)};case"analysis":return{queryKind:r.queryKind,request:ln(r)};case"records":return{queryKind:r.queryKind,request:cn(r)};case"inputOptions":return{queryKind:r.queryKind,request:pn(r)};case"sql":return{queryKind:r.queryKind,request:fn(r)};case"matrix":return{queryKind:r.queryKind,request:mn(r)};default:return xe(r)}},[r]),i=Dt({spec:r,queryKind:n.queryKind,queryKey:n.request.queryKey,intent:n.request.intent,activeInputs:n.request.activeInputs,debug:t.debug}),o=d.useRef(null),l=d.useMemo(()=>({start:i.start,success:i.success,failure:i.failure,ignored:i.ignored}),[i.failure,i.ignored,i.start,i.success]),p=d.useCallback(a=>{var D,E,v,w,C,R,k,I,T;const b=n.request;if(b.intent)switch(n.queryKind){case"metric":return(D=a.executor)==null?void 0:D.executeMetric(b.intent,a);case"analysis":return(v=(E=a.executor)==null?void 0:E.executeAnalysis)==null?void 0:v.call(E,b.intent,a,b.analysisOptions);case"records":return(w=a.executor)==null?void 0:w.executeRecords(b.intent,a);case"inputOptions":return(C=a.executor)==null?void 0:C.executeInputOptions(b.intent,a);case"sql":return(k=(R=a.executor)==null?void 0:R.executeSql)==null?void 0:k.call(R,b.intent,a);case"matrix":return(T=(I=a.executor)==null?void 0:I.executeMatrix)==null?void 0:T.call(I,b.intent,a);default:return xe(n)}},[n]),c=bn(n.request.queryKey,p,n.request.idleData,n.request.activeInputs,l),f=i.queryId,y=i.validationFailure;d.useEffect(()=>{const a=n.request.error;if(!a){o.current=null;return}const b=`${f}:${a.message}`;o.current!==b&&(o.current=b,y(a))},[n.request.error,n.request.queryKey,f,y]);const h=n.request.error?n.request.idleData:c.data,g=n.request.error?"error":c.status,m=!n.request.error&&c.status==="loading",x=n.request.error||c.error,A=i.trace;switch(n.queryKind){case"metric":{const a=h;return{id:r.id,intent:n.request.intent,value:(a==null?void 0:a.value)??null,measures:a==null?void 0:a.measures,comparisonValue:a==null?void 0:a.comparisonValue,delta:a==null?void 0:a.delta,deltaPercent:a==null?void 0:a.deltaPercent,records:a==null?void 0:a.records,executionResult:a==null?void 0:a.executionResult,status:g,isLoading:m,error:x,trace:A}}case"analysis":{const a=ft(h);return{id:r.id,intent:n.request.intent,...a||{},status:g,isLoading:m,error:x,trace:A}}case"records":{const a=h;return{id:r.id,intent:n.request.intent,records:(a==null?void 0:a.records)||[],columns:a==null?void 0:a.columns,rowCount:a==null?void 0:a.rowCount,pagination:a==null?void 0:a.pagination,executionResult:a==null?void 0:a.executionResult,status:g,isLoading:m,error:x,trace:A}}case"inputOptions":{const a=h;return{id:r.id,intent:n.request.intent,options:(a==null?void 0:a.options)||[],executionResult:a==null?void 0:a.executionResult,status:g,isLoading:m,error:x,trace:A}}case"sql":{const a=h;return{id:r.id,intent:n.request.intent,records:(a==null?void 0:a.records)||[],columns:a==null?void 0:a.columns,rowCount:a==null?void 0:a.rowCount,pagination:a==null?void 0:a.pagination,output:a==null?void 0:a.output,rowLimitExceeded:a==null?void 0:a.rowLimitExceeded,executionResult:a==null?void 0:a.executionResult,status:g,isLoading:m,error:x,trace:A}}case"matrix":{const a=h;return{id:r.id,intent:n.request.intent,matrixResult:a==null?void 0:a.matrixResult,grid:a==null?void 0:a.grid,expansion:a==null?void 0:a.expansion,executionResult:a==null?void 0:a.executionResult,status:g,isLoading:m,error:x,trace:A}}default:return xe(n)}}function bn(e,t,r,n,i){const o=on(),l=d.useRef(t),p=d.useRef(n),[c,f]=d.useState({status:"idle",data:r,error:null});return l.current=t,p.current=n,d.useEffect(()=>{let y;try{y=l.current({...o,activeInputs:p.current})}catch(m){i==null||i.failure(m,0),f({status:"error",data:r,error:B(m)});return}if(!y){f({status:"idle",data:r,error:null});return}let h=!1;const g=vt();return i==null||i.start(),f(m=>({status:"loading",data:m.data,error:null})),y.then(m=>{h?i==null||i.ignored("superseded"):(i==null||i.success(m,Ue(g)),f({status:"success",data:m,error:null}))}).catch(m=>{h?i==null||i.ignored("superseded"):(i==null||i.failure(m,Ue(g)),f({status:"error",data:r,error:B(m)}))}),()=>{h=!0}},[r,e,o,i]),c}function vt(){return typeof performance<"u"&&performance.now?performance.now():Date.now()}function Ue(e){return Math.max(0,Math.round(vt()-e))}function Sn(e){return Object.fromEntries(e.filter(t=>t.defaultValue!==void 0).map(t=>[t.id,t.defaultValue]))}function xe(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function In(e){return!e||typeof e=="boolean"||e.enabled===!1?null:e.autoRenderDevtools===!0?{}:e.autoRenderDevtools?e.autoRenderDevtools:null}function wn({token:e,apiBaseUrl:t,executor:r,debug:n,children:i}){var m;const o=sn(),l=((m=o==null?void 0:o.authToken)==null?void 0:m.accessToken)||e,p=(o==null?void 0:o.dataApiBaseUrl)||(o==null?void 0:o.apiBaseUrl)||t,c=(o==null?void 0:o.debug)??n,f=In(c),y=d.useMemo(()=>yt(),[]),h=r||y,g=d.useMemo(()=>({token:l,apiBaseUrl:p,executor:h,debug:c}),[p,c,h,l]);return s.jsx(Rt,{debug:c,children:s.jsxs(ht.Provider,{value:g,children:[i,f?s.jsx(Xe,{...f}):null]})})}exports.SemaphorDataAppProvider=wn;exports.SemaphorDevtools=Xe;exports.SemaphorDevtoolsInspectButton=kt;exports.SemaphorViewBoundary=Ct;exports.createSemaphorQueryExecutor=yt;exports.defineSemaphorDataApp=It;exports.defineSemaphorInput=wt;exports.isSemaphorInputValueValidForOptions=gt;exports.semaphor=qt;exports.useClearInvalidSemaphorInputValue=gn;exports.useSemaphorDevtools=je;exports.useSemaphorInput=yn;exports.useSemaphorInputs=hn;exports.useSemaphorQuery=xn;
|