react-semaphor 0.1.382 → 0.1.384

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.
Files changed (50) hide show
  1. package/dist/brand-studio/index.cjs +4 -4
  2. package/dist/brand-studio/index.js +27 -27
  3. package/dist/chunks/{braces-CP8BEzl3.js → braces--20GzUQh.js} +1 -1
  4. package/dist/chunks/{braces-CGi-YFZp.js → braces-C0Vh_Mft.js} +1 -1
  5. package/dist/chunks/{calendar-preferences-dialog-CV4xF2Tp.js → calendar-preferences-dialog-B-VsxhsA.js} +3 -3
  6. package/dist/chunks/calendar-preferences-dialog-DE67Z3oQ.js +1 -0
  7. package/dist/chunks/{dashboard-briefing-launcher-BT00MvGB.js → dashboard-briefing-launcher-BIj3X7b3.js} +107 -106
  8. package/dist/chunks/dashboard-briefing-launcher-Czx6BcXW.js +80 -0
  9. package/dist/chunks/dashboard-controls-BP-DcPFs.js +52 -0
  10. package/dist/chunks/{dashboard-controls-B6y7jkKO.js → dashboard-controls-BXxucM4f.js} +114 -113
  11. package/dist/chunks/dashboard-json-BNwshkK2.js +1 -0
  12. package/dist/chunks/{dashboard-json-CfIUG8k1.js → dashboard-json-C6oZuipD.js} +8 -8
  13. package/dist/chunks/edit-dashboard-visual-BAprin3J.js +178 -0
  14. package/dist/chunks/{edit-dashboard-visual-DMbf89xa.js → edit-dashboard-visual-CmfrI_L3.js} +1277 -1276
  15. package/dist/chunks/{index-CrKxP9uF.js → index-4W_ElSBJ.js} +219 -239
  16. package/dist/chunks/{index-BAsWLkZ8.js → index-icb12JV1.js} +879 -932
  17. package/dist/chunks/{layout-grid-jJQUqDN9.js → layout-grid-B7-klXiK.js} +1 -1
  18. package/dist/chunks/{layout-grid-BsKH3TgY.js → layout-grid-DV89AC9_.js} +1 -1
  19. package/dist/chunks/{palette-xU9Qt6bE.js → palette-5IwhMbSF.js} +1 -1
  20. package/dist/chunks/{palette-9zLPGlj2.js → palette-Dj-dgPYh.js} +1 -1
  21. package/dist/chunks/{save-DzciESDh.js → save-16C6YSW2.js} +1 -1
  22. package/dist/chunks/{save-8A_q6K4E.js → save-C5fwVdTF.js} +1 -1
  23. package/dist/chunks/search-0LmWwZzW.js +57 -0
  24. package/dist/chunks/search-Dq1Mbb03.js +21 -0
  25. package/dist/chunks/{switch-DArtNJZh.js → switch-DUdaHFZQ.js} +2332 -2419
  26. package/dist/chunks/{switch-k7kj6NRg.js → switch-bdJp0Bkw.js} +29 -54
  27. package/dist/chunks/use-create-flow-overlay-state-BIHKf_XK.js +21 -0
  28. package/dist/chunks/{use-create-flow-overlay-state-BdG1DiSx.js → use-create-flow-overlay-state-YvqCp6Zo.js} +74 -74
  29. package/dist/chunks/x-B_cx7LwM.js +26 -0
  30. package/dist/chunks/x-IdR_js6f.js +139 -0
  31. package/dist/dashboard/index.cjs +1 -1
  32. package/dist/dashboard/index.js +1 -1
  33. package/dist/data-app-builder/index.cjs +23 -23
  34. package/dist/data-app-builder/index.js +17 -15
  35. package/dist/data-app-sdk/index.cjs +68 -1
  36. package/dist/data-app-sdk/index.js +2876 -495
  37. package/dist/index.cjs +1 -1
  38. package/dist/index.js +14 -14
  39. package/dist/surfboard/index.cjs +1 -1
  40. package/dist/surfboard/index.js +2 -2
  41. package/dist/types/data-app-sdk.d.ts +148 -1
  42. package/package.json +1 -1
  43. package/dist/chunks/calendar-preferences-dialog-rDDobeLo.js +0 -1
  44. package/dist/chunks/dashboard-briefing-launcher-Dcbh-mjY.js +0 -80
  45. package/dist/chunks/dashboard-controls-CRqnPibB.js +0 -52
  46. package/dist/chunks/dashboard-json-DEQqRR1x.js +0 -1
  47. package/dist/chunks/edit-dashboard-visual-wDOcHak3.js +0 -178
  48. package/dist/chunks/index-BxM99sFL.js +0 -1
  49. package/dist/chunks/index-CuHybtft.js +0 -51
  50. package/dist/chunks/use-create-flow-overlay-state-ipeaE65_.js +0 -21
@@ -2,10 +2,12 @@ import { jsx as r, jsxs as c, Fragment as re } from "react/jsx-runtime";
2
2
  import * as Yn from "react";
3
3
  import { useContext as Zn, useState as x, useRef as oe, useMemo as ze, useEffect as W, useCallback as Ot } from "react";
4
4
  import * as Xn from "react-dom/client";
5
- import { ae as ea, af as ta, ag as Ir, ah as jr, ai as zr, aj as ra, ak as Wr, al as Hr, am as Jr, an as Vr, ao as _r, ap as Ur, aq as Gr, ar as na, as as aa, at as oa, au as Ht, av as on, x as Kr, aw as sa, ax as Vt, ay as _t, az as sn, aA as ia, aB as la, aC as da } from "../chunks/index-BAsWLkZ8.js";
6
- import { c as $e, B as H, P as it, b as lt, d as dt, a1 as ca, a2 as ua, a3 as pa, a4 as ha, a5 as ma, X as Je, f as me, R as fa, e as Ut } from "../chunks/switch-DArtNJZh.js";
5
+ import { ae as ea, af as ta, ag as Ir, ah as jr, ai as zr, aj as ra, ak as Wr, al as Hr, am as Jr, an as Vr, ao as _r, ap as Ur, aq as Gr, ar as na, as as aa, at as oa, au as Ht, av as on, x as Kr, aw as sa, ax as Vt, ay as _t, az as sn, aA as ia, aB as la } from "../chunks/index-icb12JV1.js";
6
+ import { B as H, P as it, a as lt, b as dt, $ as da, a0 as ca, a1 as ua, a2 as pa, a3 as ha, e as me, R as ma, d as Ut } from "../chunks/switch-DUdaHFZQ.js";
7
7
  import { loadSemaphorBrowserRuntime as ot } from "../data-app-builder-browser-runtime/index.js";
8
- import { S as ga } from "../chunks/save-DzciESDh.js";
8
+ import { c as $e, X as Je } from "../chunks/x-IdR_js6f.js";
9
+ import { S as fa } from "../chunks/save-16C6YSW2.js";
10
+ import { S as ga } from "../chunks/search-0LmWwZzW.js";
9
11
  /**
10
12
  * @license lucide-react v0.453.0 - ISC
11
13
  *
@@ -957,7 +959,7 @@ function qa({
957
959
  ] })
958
960
  ] });
959
961
  }
960
- function yo({
962
+ function ko({
961
963
  projectId: e,
962
964
  projectName: a,
963
965
  dataAppId: s,
@@ -2668,18 +2670,18 @@ function Ya({
2668
2670
  }
2669
2671
  )
2670
2672
  ] }),
2671
- /* @__PURE__ */ c(ca, { value: pt, onValueChange: mn, children: [
2673
+ /* @__PURE__ */ c(da, { value: pt, onValueChange: mn, children: [
2672
2674
  /* @__PURE__ */ r(
2673
- ua,
2675
+ ca,
2674
2676
  {
2675
2677
  "aria-label": "Generation model",
2676
2678
  title: "Model used to generate changes",
2677
2679
  className: "h-7 w-auto gap-1.5 border-0 bg-transparent px-1.5 text-[11px] text-muted-foreground shadow-none hover:text-foreground focus:ring-0",
2678
- children: /* @__PURE__ */ r(pa, { placeholder: "Model" })
2680
+ children: /* @__PURE__ */ r(ua, { placeholder: "Model" })
2679
2681
  }
2680
2682
  ),
2681
- /* @__PURE__ */ r(ha, { align: "start", children: Jt.map((t) => /* @__PURE__ */ r(
2682
- ma,
2683
+ /* @__PURE__ */ r(pa, { align: "start", children: Jt.map((t) => /* @__PURE__ */ r(
2684
+ ha,
2683
2685
  {
2684
2686
  value: t.id,
2685
2687
  className: "text-[12px]",
@@ -2888,7 +2890,7 @@ function Ya({
2888
2890
  disabled: X || ee,
2889
2891
  title: "Reset the app to a blank development template",
2890
2892
  children: [
2891
- /* @__PURE__ */ r(fa, { className: "h-3.5 w-3.5" }),
2893
+ /* @__PURE__ */ r(ma, { className: "h-3.5 w-3.5" }),
2892
2894
  "Reset app"
2893
2895
  ]
2894
2896
  }
@@ -2915,7 +2917,7 @@ function Ya({
2915
2917
  title: "Save the current local source snapshot as a Semaphor draft",
2916
2918
  onClick: () => void Er(),
2917
2919
  children: [
2918
- Ye === "saving" ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ r(ga, { className: "h-3.5 w-3.5" }),
2920
+ Ye === "saving" ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ r(fa, { className: "h-3.5 w-3.5" }),
2919
2921
  "Save draft"
2920
2922
  ]
2921
2923
  }
@@ -3151,7 +3153,7 @@ function Za({ code: e, lang: a }) {
3151
3153
  }
3152
3154
  )
3153
3155
  ] }),
3154
- /* @__PURE__ */ r("div", { className: "overflow-x-auto bg-background", children: /* @__PURE__ */ r(la, { code: e, language: a || "tsx" }) })
3156
+ /* @__PURE__ */ r("div", { className: "overflow-x-auto bg-background", children: /* @__PURE__ */ r(ia, { code: e, language: a || "tsx" }) })
3155
3157
  ] });
3156
3158
  }
3157
3159
  const Xa = /(\b[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*\.(?:tsx?|jsx?|mjs|cjs|css|scss|json|mdx?|html?|ya?ml|toml|sql|sh|py|rb|go|rs)\b)/g;
@@ -3466,7 +3468,7 @@ function lo({
3466
3468
  e.dataset.primaryDateField
3467
3469
  ] }) : null,
3468
3470
  /* @__PURE__ */ c("label", { className: "mt-3 flex h-8 items-center gap-2 rounded-[5px] border border-border bg-background px-2", children: [
3469
- /* @__PURE__ */ r(ia, { className: "h-3.5 w-3.5 text-muted-foreground" }),
3471
+ /* @__PURE__ */ r(ga, { className: "h-3.5 w-3.5 text-muted-foreground" }),
3470
3472
  /* @__PURE__ */ r(
3471
3473
  "input",
3472
3474
  {
@@ -3671,8 +3673,8 @@ function po({
3671
3673
  ] });
3672
3674
  }
3673
3675
  function ho({ state: e }) {
3674
- return e === "done" ? /* @__PURE__ */ r(Ut, { className: "h-3.5 w-3.5 text-emerald-600" }) : e === "running" ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin text-blue-600" }) : e === "blocked" ? /* @__PURE__ */ r(Je, { className: "h-3.5 w-3.5 text-destructive" }) : /* @__PURE__ */ r(da, { className: "h-2.5 w-2.5 fill-zinc-300 stroke-none" });
3676
+ return e === "done" ? /* @__PURE__ */ r(Ut, { className: "h-3.5 w-3.5 text-emerald-600" }) : e === "running" ? /* @__PURE__ */ r(me, { className: "h-3.5 w-3.5 animate-spin text-blue-600" }) : e === "blocked" ? /* @__PURE__ */ r(Je, { className: "h-3.5 w-3.5 text-destructive" }) : /* @__PURE__ */ r(la, { className: "h-2.5 w-2.5 fill-zinc-300 stroke-none" });
3675
3677
  }
3676
3678
  export {
3677
- yo as DataAppBuilder
3679
+ ko as DataAppBuilder
3678
3680
  };
@@ -1 +1,68 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../data-app-sdk-adapters/index.cjs"),N=require("../chunks/index-BxM99sFL.js"),d=require("react"),L=require("../chunks/validators-lWo8m0Q7.js");require("../chunks/analyze-result-contract-CtXfp3nv.js");const U=require("react/jsx-runtime");function k(e,t,n={}){return{...n,name:e,role:t}}function z(e){return e}function B(e){return e}const H={source:{semantic(e){return{...e,kind:"semantic"}},sql(e){return{...e,kind:"sql"}}},field:{measure(e,t){return k(e,"measure",t)},dimension(e,t){return k(e,"dimension",t)},date(e,t){return k(e,"date",t)},id(e,t){return k(e,"id",t)}},filter(e){return{...e,kind:"filter"}},bindInput(e,t){return{toAnalyticsInput(){const[n]=c.toSemaphorInputSnapshots([e]),r=c.toSemaphorInputBinding({...t,inputId:t.inputId||n.inputId});return{...n,inputId:r.inputId,...r.kind?{kind:r.kind}:{},...r.controlRole?{controlRole:r.controlRole}:{},...r.operator?{operator:r.operator}:{},...r.field?{field:r.field}:{},...r.relationshipHint?{relationshipHint:r.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"}}},Q=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"],F=["records","changes","drivers","largestNegativeChanges","largestPositiveChanges","largestNegativeDrivers","largestPositiveDrivers"];function _(e){if(!e)return{};const t=G(e.executionResult),n=J(e,t),r=W(n);return{...e,...Object.keys(n).length?{resultSets:n}:{},...r?{columns:r.columns,records:r.records,rowCount:r.rowCount}:{}}}function J(e,t){const n=Y(e.resultSets);for(const i of Q){if(n[i]){n[i]=j(n[i]);continue}const u=Z(e[i]);if(!u.length)continue;const s=t.length?t:ee(u);n[i]={records:K(u,s),columns:s,rowCount:u.length}}const r=X(e.executionResult);return r&&r.records.length>0&&!n.records&&(n.records=r),n}function Y(e){return Object.fromEntries(Object.entries(e||{}).map(([t,n])=>[t,j(n)]))}function j(e){var t;return{...e,records:K(e.records||[],e.columns||[]),rowCount:e.rowCount??((t=e.records)==null?void 0:t.length)??0}}function W(e){var t;for(const n of F)if((t=e[n])!=null&&t.records.length)return e[n];return Object.values(e).find(n=>n.records.length)||Object.values(e)[0]}function X(e){const t=e==null?void 0:e.result;if(!(!t||t.kind!=="records"&&t.kind!=="sql"))return{records:K(t.records,t.columns),columns:t.columns,rowCount:t.rowCount??t.records.length}}function G(e){const t=e==null?void 0:e.result;return!t||t.kind!=="records"&&t.kind!=="sql"?[]:t.columns}function Z(e){return Array.isArray(e)?e.filter(t=>!!(t&&typeof t=="object"&&!Array.isArray(t))):[]}function K(e,t){return t.length?e.map(n=>{const r={};return t.forEach((i,u)=>{const s=te(n,{name:i.key,label:i.label,fallbackNames:[i.name,Object.keys(n)[u]]});s!==void 0&&(r[i.key]=s)}),Object.keys(r).length?r:n}):e}function ee(e){return Array.from(new Set(e.flatMap(n=>Object.keys(n)))).map(n=>({key:n,name:n,label:n}))}function te(e,t){const n=[t.name,t.label,...t.fallbackNames||[]].filter(r=>!!r);for(const r of n)if(Object.prototype.hasOwnProperty.call(e,r))return e[r]}function P(){return{executeAnalysis:(e,t,n)=>v(e,t,n??{}).then(_),executeMetric:(e,t)=>v(e,t),executeRecords:(e,t)=>v(e,t),executeInputOptions:(e,t)=>v(e,t),executeSql:(e,t)=>v(e,t),executeMatrix:(e,t)=>v(e,t)}}async function v(e,t,n){if(!t.token)throw new Error("SemaphorDataAppProvider needs a token to execute queries.");const r=se(t),i=re(e,r);let u;try{u=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t.token}`},body:JSON.stringify({intent:e,activeInputs:t.activeInputs,...n?{analysisOptions:n}:{},resultShape:e.kind})})}catch(p){throw new Error(`${i}: ${p instanceof Error?p.message:String(p)}`)}const s=await ie(u);if(!u.ok||s.error)throw new Error(`${i}: ${s.error||`Semaphor Data App execution failed with status ${u.status}.`}`);return s}function re(e,t){return[`Semaphor ${e.kind} query`,e.id?`id=${e.id}`:void 0,e.label?`label=${e.label}`:void 0,ne(e),`endpoint=${oe(t)}`].filter(n=>!!n).join(" ")}function ne(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 oe(e){if(!e)return"/api/v1/data-app/execute";try{return new URL(e,"http://localhost").pathname}catch{return e}}async function ie(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:ue(e,t),details:t}}}function ue(e,t){const n=e.statusText?` ${e.statusText}`:"",r=t.replace(/\s+/g," ").trim();return r?`Semaphor Data App execution failed with status ${e.status}${n}: ${r.slice(0,240)}`:`Semaphor Data App execution failed with status ${e.status}${n}.`}function se(e){const t=ae(e).replace(/\/+$/,"");return t?t.endsWith("/api")?`${t}/v1/data-app/execute`:`${t}/api/v1/data-app/execute`:"/api/v1/data-app/execute"}function ae(e){if(e.apiBaseUrl)return e.apiBaseUrl;if(!e.token)return"";try{return N.jwtDecode(e.token).apiServiceUrl||""}catch{return""}}const T=d.createContext({});function ce(){if(!(typeof window>"u"))return window.__SEMAPHOR_DATA_APP_RUNTIME__}function le(){return d.useContext(T)}const g={value:null},x={},de={records:[]},E={options:[]},pe={records:[]},D={};function fe(e){const t=c.toSemaphorActiveInputSnapshots(e.inputs),n=c.toSemaphorAnalysisQueryOptions(e);try{const r=c.toSemaphorAnalysisIntent(e),i=y(r);return i?{error:i,activeInputs:t,analysisOptions:n,queryKey:m(void 0,t,i,n),idleData:x}:{intent:r,error:null,activeInputs:t,analysisOptions:n,queryKey:m(r,t,void 0,n),idleData:x}}catch(r){const i=h(r);return{error:i,activeInputs:t,analysisOptions:n,queryKey:m(void 0,t,i,n),idleData:x}}}function me(e){const t=c.toSemaphorActiveInputSnapshots(e.inputs);try{const n=c.toSemaphorMetricIntent(e),r=y(n);return r?{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:g}:{intent:n,error:null,activeInputs:t,queryKey:m(n,t),idleData:g}}catch(n){const r=h(n);return{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:g}}}function he(e){const t=c.toSemaphorActiveInputSnapshots(e.inputs),n=de;try{const r=c.toSemaphorRecordsIntent(e),i=y(r);return i?{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}:{intent:r,error:null,activeInputs:t,queryKey:m(r,t),idleData:n}}catch(r){const i=h(r);return{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}}}function ve(e){const t=c.toSemaphorActiveInputSnapshots(e.inputs);try{const n=c.toSemaphorInputOptionsIntent(e),r=y(n);return r?{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:E}:{intent:n,error:null,activeInputs:t,queryKey:m(n,t),idleData:E}}catch(n){const r=h(n);return{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:E}}}function ye(e){const t=c.toSemaphorActiveInputSnapshots(e.inputs),n=pe;try{const r=c.toSemaphorSqlIntent(e),i=y(r);return i?{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}:{intent:r,error:null,activeInputs:t,queryKey:m(r,t),idleData:n}}catch(r){const i=h(r);return{error:i,activeInputs:t,queryKey:m(void 0,t,i),idleData:n}}}function Se(e){const t=c.toSemaphorActiveInputSnapshots(e.inputs);try{const n=c.toSemaphorMatrixIntent(e),r=y(n);return r?{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:D}:{intent:n,error:null,activeInputs:t,queryKey:m(n,t),idleData:D}}catch(n){const r=h(n);return{error:r,activeInputs:t,queryKey:m(void 0,t,r),idleData:D}}}function h(e){return e instanceof Error?e:new Error(String(e))}function y(e){const t=L.validateSemaphorAnalyticsIntent(e);if(t.ok)return null;const n=t.errors.map(r=>r.path?`${r.code} at ${r.path}: ${r.message}`:`${r.code}: ${r.message}`).join("; ");return new Error(`Invalid Semaphor analytics intent. ${n}`)}function m(e,t,n,r){return JSON.stringify({intent:e,activeInputs:t,analysisOptions:r,error:n==null?void 0:n.message})}function qe(e){const[t,n]=d.useState(e.defaultValue),r=Object.prototype.hasOwnProperty.call(e,"value"),i=r?e.value:t,u=d.useMemo(()=>c.normalizeSemaphorInputOptions(e.options),[e.options]),s=d.useCallback(a=>{var o;const l=a;(o=e.onValueChange)==null||o.call(e,l),r||n(l)},[r,e]),p=d.useCallback(()=>s(void 0),[s]);return d.useMemo(()=>{const a=c.toSemaphorInputSpec(e);return{id:e.id,kind:e.kind,label:e.label,field:a.field,operator:a.operator,relationshipHint:a.relationshipHint,controlRole:e.kind==="control"?e.role:void 0,value:i,options:u,isActive:c.hasSemaphorInputValue(i),setValue:s,clear:p,toAnalyticsInput:()=>({inputId:a.inputId,field:a.field,kind:e.kind,label:e.label,value:i,isActive:c.hasSemaphorInputValue(i),operator:a.operator,relationshipHint:a.relationshipHint,controlRole:e.kind==="control"?e.role:void 0})}},[p,u,s,e,i])}function Ie(e){const[t,n]=d.useState(()=>Ee(e));return d.useEffect(()=>{n(r=>{let i=r;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(r=>{const i=Object.prototype.hasOwnProperty.call(r,"value"),u=i?r.value:t[r.id],s=c.normalizeSemaphorInputOptions(r.options),p=o=>{var f;(f=r.onValueChange)==null||f.call(r,o),i||n(S=>({...S,[r.id]:o}))},a=()=>p(void 0),l=c.toSemaphorInputSpec(r);return{id:r.id,kind:r.kind,label:r.label,field:l.field,operator:l.operator,relationshipHint:l.relationshipHint,controlRole:r.kind==="control"?r.role:void 0,value:u,options:s,isActive:c.hasSemaphorInputValue(u),setValue:p,clear:a,toAnalyticsInput:()=>({inputId:l.inputId,field:l.field,kind:r.kind,label:r.label,value:u,isActive:c.hasSemaphorInputValue(u),operator:l.operator,relationshipHint:l.relationshipHint,controlRole:r.kind==="control"?r.role:void 0})}}),[e,t])}function Ae(e,t){const n=(t==null?void 0:t.status)==="success"?t.options:void 0,r=d.useMemo(()=>ke(n),[n]);d.useEffect(()=>{M(e.value,n)||e.clear()},[e,r,t==null?void 0:t.status,n])}function M(e,t){if(!c.hasSemaphorInputValue(e)||t===void 0)return!0;const n=new Set(t.map(i=>$(i.value)));return(Array.isArray(e)?e:[e]).every(i=>n.has($(i)))}function ke(e){return JSON.stringify((e||[]).map(t=>t.value))}function $(e){return`${typeof e}:${String(e)}`}function ge(e,t={}){const n=d.useMemo(()=>t.inputs?{...e,inputs:t.inputs}:e,[t.inputs,e]),r=d.useMemo(()=>{switch(n.queryKind){case"metric":return{queryKind:n.queryKind,request:me(n)};case"analysis":return{queryKind:n.queryKind,request:fe(n)};case"records":return{queryKind:n.queryKind,request:he(n)};case"inputOptions":return{queryKind:n.queryKind,request:ve(n)};case"sql":return{queryKind:n.queryKind,request:ye(n)};case"matrix":return{queryKind:n.queryKind,request:Se(n)};default:return b(n)}},[n]),i=d.useCallback(o=>{var S,q,O,R,w,I,C,A,V;const f=r.request;if(f.intent)switch(r.queryKind){case"metric":return(S=o.executor)==null?void 0:S.executeMetric(f.intent,o);case"analysis":return(O=(q=o.executor)==null?void 0:q.executeAnalysis)==null?void 0:O.call(q,f.intent,o,f.analysisOptions);case"records":return(R=o.executor)==null?void 0:R.executeRecords(f.intent,o);case"inputOptions":return(w=o.executor)==null?void 0:w.executeInputOptions(f.intent,o);case"sql":return(C=(I=o.executor)==null?void 0:I.executeSql)==null?void 0:C.call(I,f.intent,o);case"matrix":return(V=(A=o.executor)==null?void 0:A.executeMatrix)==null?void 0:V.call(A,f.intent,o);default:return b(r)}},[r]),u=xe(r.request.queryKey,i,r.request.idleData,r.request.activeInputs),s=r.request.error?r.request.idleData:u.data,p=r.request.error?"error":u.status,a=!r.request.error&&u.status==="loading",l=r.request.error||u.error;switch(r.queryKind){case"metric":{const o=s;return{id:n.id,intent:r.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:p,isLoading:a,error:l}}case"analysis":{const o=_(s);return{id:n.id,intent:r.request.intent,...o||{},status:p,isLoading:a,error:l}}case"records":{const o=s;return{id:n.id,intent:r.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:p,isLoading:a,error:l}}case"inputOptions":{const o=s;return{id:n.id,intent:r.request.intent,options:(o==null?void 0:o.options)||[],executionResult:o==null?void 0:o.executionResult,status:p,isLoading:a,error:l}}case"sql":{const o=s;return{id:n.id,intent:r.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:p,isLoading:a,error:l}}case"matrix":{const o=s;return{id:n.id,intent:r.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:p,isLoading:a,error:l}}default:return b(r)}}function xe(e,t,n,r){const i=le(),u=d.useRef(t),s=d.useRef(r),[p,a]=d.useState({status:"idle",data:n,error:null});return u.current=t,s.current=r,d.useEffect(()=>{let l;try{l=u.current({...i,activeInputs:s.current})}catch(f){a({status:"error",data:n,error:h(f)});return}if(!l){a({status:"idle",data:n,error:null});return}let o=!1;return a(f=>({status:"loading",data:f.data,error:null})),l.then(f=>{o||a({status:"success",data:f,error:null})}).catch(f=>{o||a({status:"error",data:n,error:h(f)})}),()=>{o=!0}},[n,e,i]),p}function Ee(e){return Object.fromEntries(e.filter(t=>t.defaultValue!==void 0).map(t=>[t.id,t.defaultValue]))}function b(e){throw new Error(`Unsupported Semaphor query kind: ${JSON.stringify(e)}`)}function De({token:e,apiBaseUrl:t,executor:n,children:r}){var o;const i=ce(),u=((o=i==null?void 0:i.authToken)==null?void 0:o.accessToken)||e,s=(i==null?void 0:i.dataApiBaseUrl)||(i==null?void 0:i.apiBaseUrl)||t,p=d.useMemo(()=>P(),[]),a=n||p,l=d.useMemo(()=>({token:u,apiBaseUrl:s,executor:a}),[s,a,u]);return U.jsx(T.Provider,{value:l,children:r})}exports.SemaphorDataAppProvider=De;exports.createSemaphorQueryExecutor=P;exports.defineSemaphorDataApp=z;exports.defineSemaphorInput=B;exports.isSemaphorInputValueValidForOptions=M;exports.semaphor=H;exports.useClearInvalidSemaphorInputValue=Ae;exports.useSemaphorInput=qe;exports.useSemaphorInputs=Ie;exports.useSemaphorQuery=ge;
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
+ .${O} {
3
+ --sd-bg: #ffffff;
4
+ --sd-bg-muted: #fafafa;
5
+ --sd-bg-raised: #ffffff;
6
+ --sd-bg-accent: #f4f4f5;
7
+ --sd-fg: #18181b;
8
+ --sd-fg-muted: #71717a;
9
+ --sd-fg-subtle: #a1a1aa;
10
+ --sd-border: #e4e4e7;
11
+ --sd-border-soft: #f4f4f5;
12
+ --sd-border-strong: #d4d4d8;
13
+ --sd-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
14
+ --sd-success-bg: #f0fdf4;
15
+ --sd-success-fg: #166534;
16
+ --sd-success-border: #bbf7d0;
17
+ --sd-success-dot: #16a34a;
18
+ --sd-warning-bg: #fff7ed;
19
+ --sd-warning-fg: #9a3412;
20
+ --sd-warning-border: #fed7aa;
21
+ --sd-warning-dot: #f59e0b;
22
+ --sd-error-bg: #fef2f2;
23
+ --sd-error-fg: #991b1b;
24
+ --sd-error-border: #fecaca;
25
+ --sd-error-dot: #dc2626;
26
+ --sd-loading-bg: #eff6ff;
27
+ --sd-loading-fg: #1d4ed8;
28
+ --sd-loading-border: #bfdbfe;
29
+ --sd-loading-dot: #2563eb;
30
+ --sd-idle-dot: #94a3b8;
31
+ }
32
+
33
+ @media (prefers-color-scheme: dark) {
34
+ .${O} {
35
+ --sd-bg: #09090b;
36
+ --sd-bg-muted: #18181b;
37
+ --sd-bg-raised: #18181b;
38
+ --sd-bg-accent: #1f1f23;
39
+ --sd-fg: #fafafa;
40
+ --sd-fg-muted: #a1a1aa;
41
+ --sd-fg-subtle: #71717a;
42
+ --sd-border: #27272a;
43
+ --sd-border-soft: #1f1f23;
44
+ --sd-border-strong: #3f3f46;
45
+ --sd-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
46
+ --sd-success-bg: rgba(34, 197, 94, 0.12);
47
+ --sd-success-fg: #86efac;
48
+ --sd-success-border: rgba(34, 197, 94, 0.35);
49
+ --sd-warning-bg: rgba(249, 115, 22, 0.12);
50
+ --sd-warning-fg: #fdba74;
51
+ --sd-warning-border: rgba(249, 115, 22, 0.35);
52
+ --sd-error-bg: rgba(239, 68, 68, 0.12);
53
+ --sd-error-fg: #fca5a5;
54
+ --sd-error-border: rgba(239, 68, 68, 0.35);
55
+ --sd-loading-bg: rgba(59, 130, 246, 0.12);
56
+ --sd-loading-fg: #93c5fd;
57
+ --sd-loading-border: rgba(59, 130, 246, 0.35);
58
+ }
59
+ }
60
+
61
+ .${O}-source {
62
+ display: -webkit-box;
63
+ -webkit-line-clamp: 2;
64
+ -webkit-box-orient: vertical;
65
+ overflow: hidden;
66
+ word-break: break-all;
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;