@lunora/studio 1.0.0-alpha.40 → 1.0.0-alpha.41

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 (51) hide show
  1. package/dist/standalone/{chunk-AAVIFQ4Y.js → chunk-25AYY4H7.js} +1 -1
  2. package/dist/standalone/{chunk-Q52CHOSY.js → chunk-2ANAF4ZM.js} +1 -1
  3. package/dist/standalone/{chunk-BKW7FFEO.js → chunk-3OIHOXVV.js} +1 -1
  4. package/dist/standalone/{chunk-AJFQ3LNM.js → chunk-447TAUFD.js} +1 -1
  5. package/dist/standalone/{chunk-SSI4G2MY.js → chunk-5C4TSNE6.js} +1 -1
  6. package/dist/standalone/{chunk-DC72CQY4.js → chunk-6HSHEMZV.js} +1 -1
  7. package/dist/standalone/{chunk-676HEBIR.js → chunk-6JIZ34MB.js} +1 -1
  8. package/dist/standalone/{chunk-YTO65GHS.js → chunk-7MVSQS7B.js} +1 -1
  9. package/dist/standalone/{chunk-P5HJXCZS.js → chunk-BX5MKYOC.js} +1 -1
  10. package/dist/standalone/{chunk-V6IWFYAQ.js → chunk-EQZQOTJY.js} +1 -1
  11. package/dist/standalone/{chunk-ZE6FT5Z3.js → chunk-GTLEWM5Y.js} +1 -1
  12. package/dist/standalone/{chunk-N746FOQP.js → chunk-GUI5GFFI.js} +1 -1
  13. package/dist/standalone/{chunk-CACB34RQ.js → chunk-HN6KJXYQ.js} +1 -1
  14. package/dist/standalone/{chunk-J46WXQYL.js → chunk-HYDJNCGW.js} +1 -1
  15. package/dist/standalone/{chunk-DECHEGIC.js → chunk-HZK5RQHG.js} +1 -1
  16. package/dist/standalone/{chunk-FSGCANAU.js → chunk-IN2SYVJB.js} +1 -1
  17. package/dist/standalone/{chunk-JVODY4EP.js → chunk-IOANPSJN.js} +1 -1
  18. package/dist/standalone/{chunk-NC6MBMSI.js → chunk-ISDZPW3V.js} +1 -1
  19. package/dist/standalone/{chunk-QDBOPDJ7.js → chunk-J73VHFCL.js} +1 -1
  20. package/dist/standalone/{chunk-GMSGZDDH.js → chunk-JHKMUTIF.js} +5 -5
  21. package/dist/standalone/{chunk-CICVBMEN.js → chunk-JPRH6DPK.js} +1 -1
  22. package/dist/standalone/{chunk-PTS5TW3J.js → chunk-KA5YB3VP.js} +1 -1
  23. package/dist/standalone/{chunk-SG3ALJJU.js → chunk-KBB75WNT.js} +1 -1
  24. package/dist/standalone/{chunk-LYB5L53X.js → chunk-KQV4NGH3.js} +1 -1
  25. package/dist/standalone/{chunk-I7ZZRM7I.js → chunk-KUH4P5F5.js} +1 -1
  26. package/dist/standalone/{chunk-5ZAA2PVR.js → chunk-KYJPPVGB.js} +1 -1
  27. package/dist/standalone/{chunk-HZTGDL4L.js → chunk-L2TJVSDQ.js} +1 -1
  28. package/dist/standalone/{chunk-ERJNDIXC.js → chunk-LBN7LPVK.js} +1 -1
  29. package/dist/standalone/{chunk-NY6GDADQ.js → chunk-MLZYX5CQ.js} +1 -1
  30. package/dist/standalone/{chunk-TH45YG6Q.js → chunk-N2X2OO4V.js} +1 -1
  31. package/dist/standalone/{chunk-BXOYVWJR.js → chunk-NGKITPQP.js} +1 -1
  32. package/dist/standalone/{chunk-YNZ7ARWW.js → chunk-OZACQNKG.js} +1 -1
  33. package/dist/standalone/{chunk-NN27EDQB.js → chunk-PNDNXS5Z.js} +1 -1
  34. package/dist/standalone/{chunk-CWEAJUHW.js → chunk-Q7DMUTUE.js} +1 -1
  35. package/dist/standalone/{chunk-C7WTJLC3.js → chunk-RHZ4M2NZ.js} +1 -1
  36. package/dist/standalone/{chunk-QHFTGJPS.js → chunk-TDZ44E5I.js} +1 -1
  37. package/dist/standalone/{chunk-X33MSJPP.js → chunk-THNBTMUF.js} +1 -1
  38. package/dist/standalone/{chunk-FKACHRWO.js → chunk-TIQISBGK.js} +1 -1
  39. package/dist/standalone/{chunk-H6RKXQZU.js → chunk-TMYVNQ66.js} +1 -1
  40. package/dist/standalone/{chunk-AJULNB46.js → chunk-UJB2LEI4.js} +1 -1
  41. package/dist/standalone/{chunk-23C4TCRO.js → chunk-W3JK4YWR.js} +1 -1
  42. package/dist/standalone/{chunk-MT2J3H7O.js → chunk-W3SHEIAL.js} +2 -2
  43. package/dist/standalone/chunk-WIHXMNUY.js +1 -0
  44. package/dist/standalone/{chunk-XRNXOIVZ.js → chunk-WLDVXVI2.js} +1 -1
  45. package/dist/standalone/{chunk-GLUNBZRI.js → chunk-XLXNLJ4N.js} +1 -1
  46. package/dist/standalone/{chunk-OY3HD7BJ.js → chunk-YJAPWSDC.js} +1 -1
  47. package/dist/standalone/{chunk-7RE5UW27.js → chunk-ZEJB6DXU.js} +1 -1
  48. package/dist/standalone/{chunk-V7SRH36W.js → chunk-ZFNBPAIZ.js} +1 -1
  49. package/dist/standalone/studio.js +1 -1
  50. package/package.json +6 -6
  51. package/dist/standalone/chunk-WPNXY7IS.js +0 -1
@@ -1,4 +1,4 @@
1
- import{a as Pe,b as re,c as ge,d as xe}from"./chunk-NN27EDQB.js";import{a as Be}from"./chunk-BGXOXASQ.js";import{a as $e}from"./chunk-MJWVMKQ4.js";import"./chunk-LNZIB2MD.js";import"./chunk-QBAT52GB.js";import"./chunk-QAFAJBAW.js";import"./chunk-AHILM3ZP.js";import"./chunk-IXDH4GL5.js";import"./chunk-KSKXW5PX.js";import"./chunk-5OIBXYZM.js";import"./chunk-L7SK4ZZD.js";import"./chunk-DC72CQY4.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-YBGC4PPD.js";import"./chunk-KEGAWN6Y.js";import{a as Re}from"./chunk-XNJNSCLM.js";import{a as Le,b as Ae,c as Oe,d as ve,e as Me,f as De}from"./chunk-GTM65MVX.js";import"./chunk-4QHKBC77.js";import{a as Ie}from"./chunk-UKDJ4H7I.js";import{b as qe}from"./chunk-TBMYIZIO.js";import"./chunk-3CJW6NWG.js";import"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as le}from"./chunk-BOXSWNXZ.js";import"./chunk-CKSHCYGC.js";import{f as he}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as G,e as ne,f as se,g as Ee,k as Q}from"./chunk-E75ANNWX.js";import"./chunk-GMSGZDDH.js";import{a as r,e as be,f as It,g as Rt,h as Lt,j as oe}from"./chunk-RRCPZMC2.js";var K=be(Rt(),1);var q=be(It(),1);var n=be(Lt(),1);var At=["ORDER BY","GROUP BY","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN","EXPLAIN QUERY PLAN","SELECT","DISTINCT","FROM","WHERE","HAVING","LIMIT","OFFSET","JOIN","ON","AND","OR","AS","ASC","DESC","WITH","UNION","EXPLAIN"],Ot=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],ae=String.fromCodePoint(0),Mt=new RegExp(`${ae}${String.raw`(\d+)`}${ae}`,"gu"),Dt=At.map(s=>({pattern:new RegExp(String.raw`\b${s.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:s})),Bt=Ot.map(s=>({pattern:new RegExp(String.raw`\s+${s.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
1
+ import{a as Pe,b as re,c as ge,d as xe}from"./chunk-PNDNXS5Z.js";import{a as Be}from"./chunk-BGXOXASQ.js";import{a as $e}from"./chunk-MJWVMKQ4.js";import"./chunk-LNZIB2MD.js";import"./chunk-QBAT52GB.js";import"./chunk-QAFAJBAW.js";import"./chunk-AHILM3ZP.js";import"./chunk-IXDH4GL5.js";import"./chunk-KSKXW5PX.js";import"./chunk-5OIBXYZM.js";import"./chunk-L7SK4ZZD.js";import"./chunk-6HSHEMZV.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-YBGC4PPD.js";import"./chunk-KEGAWN6Y.js";import{a as Re}from"./chunk-XNJNSCLM.js";import{a as Le,b as Ae,c as Oe,d as ve,e as Me,f as De}from"./chunk-GTM65MVX.js";import"./chunk-4QHKBC77.js";import{a as Ie}from"./chunk-UKDJ4H7I.js";import{b as qe}from"./chunk-TBMYIZIO.js";import"./chunk-3CJW6NWG.js";import"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as le}from"./chunk-BOXSWNXZ.js";import"./chunk-CKSHCYGC.js";import{f as he}from"./chunk-XLXNLJ4N.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as G,e as ne,f as se,g as Ee,k as Q}from"./chunk-E75ANNWX.js";import"./chunk-JHKMUTIF.js";import{a as r,e as be,f as It,g as Rt,h as Lt,j as oe}from"./chunk-RRCPZMC2.js";var K=be(Rt(),1);var q=be(It(),1);var n=be(Lt(),1);var At=["ORDER BY","GROUP BY","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN","EXPLAIN QUERY PLAN","SELECT","DISTINCT","FROM","WHERE","HAVING","LIMIT","OFFSET","JOIN","ON","AND","OR","AS","ASC","DESC","WITH","UNION","EXPLAIN"],Ot=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],ae=String.fromCodePoint(0),Mt=new RegExp(`${ae}${String.raw`(\d+)`}${ae}`,"gu"),Dt=At.map(s=>({pattern:new RegExp(String.raw`\b${s.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:s})),Bt=Ot.map(s=>({pattern:new RegExp(String.raw`\s+${s.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
2
2
  ${s}`})),$t=r(s=>{let e=[],o=s.replaceAll(/'(?:[^']|'')*'/gu,l=>(e.push(l),`${ae}${(e.length-1).toString()}${ae}`)).replaceAll(/\s+/gu," ").trim();for(let{pattern:l,replacement:a}of Dt)o=o.replaceAll(l,a);for(let{pattern:l,replacement:a}of Bt)o=o.replaceAll(l,a);return o=o.replaceAll(Mt,(l,a)=>e[Number(a)]??""),o},"formatSql"),ie=8,Pt=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],_t=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Wt=/[\w$]/,He=r(s=>s!==void 0&&Wt.test(s),"isWordChar"),Fe=r(s=>{let e=s.length;for(;e>0&&He(s[e-1]);)e-=1;return s.slice(e)},"trailingWord"),ze=r((s,e)=>{let t=e;for(;t>0&&He(s[t-1]);)t-=1;return{end:e,start:t,text:s.slice(t,e)}},"tokenAt"),_e=r((s,e)=>{let t=s.slice(0,e).trimEnd();return t.endsWith(".")||_t.has(Fe(t).toUpperCase())},"prefersColumns"),Ht=r((s,e)=>{let t=s.slice(0,e);if(!t.endsWith("."))return;let o=Fe(t.slice(0,-1));return o===""?void 0:o},"qualifierTable"),ke=r((s,e)=>s.toLowerCase().startsWith(e.toLowerCase()),"matches"),We=r((s,e,t,o)=>{let l=[];for(let a of s)if(ke(a,e)&&(l.push(o(a)),l.length>=t))break;return l},"takeMatches"),Ft=r((s,e,t)=>{let o=new Map;for(let[l,a]of Object.entries(s.columns))for(let d of a)if(ke(d,e)&&!o.has(d)&&(o.set(d,l),o.size>=t))return[...o].map(([p,c])=>({detail:c,kind:"column",label:p}));return[...o].map(([l,a])=>({detail:a,kind:"column",label:l}))},"takeColumnMatches"),zt=r((s,e,t)=>{let o=ze(s,e),l=Ht(s,o.start);if(l!==void 0){let u=t.columns[l]??t.columns[l.toLowerCase()]??[];return We(u,o.text,ie,y=>({detail:l,kind:"column",label:y}))}if(o.text===""&&!_e(s,o.start))return[];let a=We(t.tables,o.text,ie,u=>({kind:"table",label:u})),d=Ft(t,o.text,ie),p=Pt.filter(u=>o.text!==""&&ke(u,o.text)&&u.toLowerCase()!==o.text.toLowerCase()).map(u=>({kind:"keyword",label:u}));return(_e(s,o.start)?[...d,...a,...p]:[...a,...d,...p]).slice(0,ie)},"suggestionsFor"),Ut=r((s,e,t)=>{let o=ze(s,e),l=s.slice(0,o.start)+t.label+s.slice(o.end);return{caret:o.start+t.label.length,value:l}},"acceptSuggestion"),Yt=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],jt=r((s,e)=>{let t=globalThis.getComputedStyle(s),o=globalThis.document.createElement("div"),{style:l}=o;l.position="absolute",l.visibility="hidden",l.whiteSpace="pre-wrap",l.overflowWrap="break-word";for(let c of Yt)l[c]=t[c];o.textContent=s.value.slice(0,Math.max(0,e));let a=globalThis.document.createElement("span");a.textContent=s.value.slice(Math.max(0,e))||".",o.append(a),globalThis.document.body.append(o);let d=a.offsetLeft-s.scrollLeft,p=a.offsetTop-s.scrollTop;return o.remove(),{left:d,top:p}},"caretOffset"),Kt=r((s,e,t)=>{let o=(0,K.c)(13),[l,a]=(0,q.useState)(null),d;o[0]!==s||o[1]!==e?(d=r((N,x)=>{let S=zt(N,x,s);if(S.length===0){a(null);return}let h=e.current,{left:w,top:C}=h===null?{left:0,top:0}:jt(h,x);a({active:0,left:w,suggestions:S,top:C})},"t0"),o[0]=s,o[1]=e,o[2]=d):d=o[2];let p=d,c;o[3]===Symbol.for("react.memo_cache_sentinel")?(c=r(()=>{a(null)},"t1"),o[3]=c):c=o[3];let u=c,y;o[4]===Symbol.for("react.memo_cache_sentinel")?(y=r(N=>{a(x=>{if(x===null)return x;let S=x.suggestions.length,h=(x.active+N+S)%S;return{...x,active:h}})},"t2"),o[4]=y):y=o[4];let g=y,v;o[5]!==t||o[6]!==l||o[7]!==e?(v=r(()=>{let N=e.current;if(l===null||N===null)return!1;let x=l.suggestions[l.active];if(x===void 0)return!1;let S=Ut(N.value,N.selectionStart,x);return t(S.value),a(null),requestAnimationFrame(()=>{let h=e.current;h!==null&&(h.focus(),h.setSelectionRange(S.caret,S.caret))}),!0},"t3"),o[5]=t,o[6]=l,o[7]=e,o[8]=v):v=o[8];let m=v,f;return o[9]!==m||o[10]!==p||o[11]!==l?(f={close:u,commit:m,move:g,refresh:p,state:l},o[9]=m,o[10]=p,o[11]=l,o[12]=f):f=o[12],f},"useSqlAutocomplete"),Gt={column:"column",keyword:"keyword",table:"table"},Vt=20,Jt=r(s=>{let e=(0,K.c)(17),{listboxId:t,onPick:o,state:l}=s,a=G(),d;e[0]!==l?(d=l===null?void 0:{left:l.left,top:l.top+Vt},e[0]=l,e[1]=d):d=e[1];let p=d;if(l===null)return null;let c;if(e[2]!==t||e[3]!==o||e[4]!==l.active||e[5]!==l.suggestions||e[6]!==a){let y;e[8]!==t||e[9]!==o||e[10]!==l.active||e[11]!==a?(y=r((g,v)=>(0,n.jsxDEV)("li",{"aria-selected":v===l.active,className:oe("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",v===l.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${t}-opt-${v.toString()}`,onMouseDown:r(m=>{m.preventDefault(),o(v)},"onMouseDown"),role:"option",children:[(0,n.jsxDEV)("span",{className:"truncate font-mono",children:g.label},void 0,!1),g.detail!==void 0&&(0,n.jsxDEV)("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:g.detail},void 0,!1),(0,n.jsxDEV)("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:a(Gt[g.kind])},void 0,!1)]},`${g.kind}:${g.label}`,!0),"t32"),e[8]=t,e[9]=o,e[10]=l.active,e[11]=a,e[12]=y):y=e[12],c=l.suggestions.map(y),e[2]=t,e[3]=o,e[4]=l.active,e[5]=l.suggestions,e[6]=a,e[7]=c}else c=e[7];let u;return e[13]!==t||e[14]!==p||e[15]!==c?(u=(0,n.jsxDEV)("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:t,role:"listbox",style:p,children:c},void 0,!1),e[13]=t,e[14]=p,e[15]=c,e[16]=u):u=e[16],u},"AutocompletePopover"),Ue=[{label:"List tables",sql:"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"},{label:"Table row count",sql:"SELECT COUNT(*) AS rows FROM messages;"},{label:"Recent rows",sql:"SELECT id, _creationTime, __doc__ FROM messages ORDER BY _creationTime DESC LIMIT 50;"},{label:"Index list",sql:"SELECT name, tbl_name FROM sqlite_master WHERE type = 'index' ORDER BY tbl_name;"}],Qt=r(s=>{let e=(0,K.c)(29),{active:t,onDelete:o,onSelect:l,query:a}=s,d=G(),p;e[0]!==l||e[1]!==a.id?(p=r(()=>{l(a.id)},"t1"),e[0]=l,e[1]=a.id,e[2]=p):p=e[2];let c=p,u;e[3]!==o||e[4]!==a.id?(u=r(E=>{E.stopPropagation(),o(a.id)},"t2"),e[3]=o,e[4]=a.id,e[5]=u):u=e[5];let y=u,g=t?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground",v;e[6]!==g?(v=oe("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",g),e[6]=g,e[7]=v):v=e[7];let m=`sql-query-${a.id}`,f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M4 6h16M4 12h10M4 18h7"},void 0,!1)},void 0,!1),e[8]=f):f=e[8];let N;e[9]!==a.name?(N=(0,n.jsxDEV)("span",{className:"truncate",children:a.name},void 0,!1),e[9]=a.name,e[10]=N):N=e[10];let x;e[11]!==t||e[12]!==c||e[13]!==v||e[14]!==m||e[15]!==N?(x=(0,n.jsxDEV)("button",{"aria-pressed":t,className:v,"data-testid":m,onClick:c,type:"button",children:[f,N]},void 0,!0),e[11]=t,e[12]=c,e[13]=v,e[14]=m,e[15]=N,e[16]=x):x=e[16];let S;e[17]!==d?(S=d("Delete query"),e[17]=d,e[18]=S):S=e[18];let h;e[19]!==d?(h=d("Delete query"),e[19]=d,e[20]=h):h=e[20];let w;e[21]===Symbol.for("react.memo_cache_sentinel")?(w=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"},void 0,!1)},void 0,!1),e[21]=w):w=e[21];let C;e[22]!==y||e[23]!==h||e[24]!==S?(C=(0,n.jsxDEV)("button",{"aria-label":S,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:y,title:h,type:"button",children:w},void 0,!1),e[22]=y,e[23]=h,e[24]=S,e[25]=C):C=e[25];let A;return e[26]!==C||e[27]!==x?(A=(0,n.jsxDEV)("li",{className:"group/q flex items-center",children:[x,C]},void 0,!0),e[26]=C,e[27]=x,e[28]=A):A=e[28],A},"QueryRow"),Xt=r(s=>{let e=(0,K.c)(58),{activeId:t,history:o,listRef:l,onClearHistory:a,onDelete:d,onLoadHistory:p,onLoadTemplate:c,onNew:u,onSearchChange:y,onSelect:g,queries:v,search:m}=s,f=G(),N;if(e[0]!==v||e[1]!==m){let T=m.trim().toLowerCase();N=T===""?[...v]:v.filter(R=>R.name.toLowerCase().includes(T)),e[0]=v,e[1]=m,e[2]=N}else N=e[2];let x=N,S;e[3]!==f?(S=f("Search queries\u2026"),e[3]=f,e[4]=S):S=e[4];let h;e[5]!==y||e[6]!==m||e[7]!==S?(h=(0,n.jsxDEV)("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:y,placeholder:S,type:"text",value:m},void 0,!1),e[5]=y,e[6]=m,e[7]=S,e[8]=h):h=e[8];let w;e[9]!==f?(w=f("New query"),e[9]=f,e[10]=w):w=e[10];let C;e[11]!==f?(C=f("New query"),e[11]=f,e[12]=C):C=e[12];let A;e[13]===Symbol.for("react.memo_cache_sentinel")?(A=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M12 5v14M5 12h14"},void 0,!1)},void 0,!1),e[13]=A):A=e[13];let E;e[14]!==u||e[15]!==w||e[16]!==C?(E=(0,n.jsxDEV)("button",{"aria-label":w,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:u,title:C,type:"button",children:A},void 0,!1),e[14]=u,e[15]=w,e[16]=C,e[17]=E):E=e[17];let M;e[18]!==h||e[19]!==E?(M=(0,n.jsxDEV)("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[h,E]},void 0,!0),e[18]=h,e[19]=E,e[20]=M):M=e[20];let D;e[21]!==f?(D=f("Private"),e[21]=f,e[22]=D):D=e[22];let O;e[23]!==D?(O=(0,n.jsxDEV)("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D},void 0,!1),e[23]=D,e[24]=O):O=e[24];let B;e[25]!==t||e[26]!==x||e[27]!==l||e[28]!==d||e[29]!==g||e[30]!==f?(B=x.length===0?(0,n.jsxDEV)("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:f("No saved queries yet \u2014 they save to this browser as you type.")},void 0,!1):(0,n.jsxDEV)("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:l,children:x.map(T=>(0,n.jsxDEV)(Qt,{active:t===T.id,onDelete:d,onSelect:g,query:T},T.id,!1))},void 0,!1),e[25]=t,e[26]=x,e[27]=l,e[28]=d,e[29]=g,e[30]=f,e[31]=B):B=e[31];let P;e[32]!==O||e[33]!==B?(P=(0,n.jsxDEV)("div",{children:[O,B]},void 0,!0),e[32]=O,e[33]=B,e[34]=P):P=e[34];let _;e[35]!==f?(_=f("Reference"),e[35]=f,e[36]=_):_=e[36];let Y;e[37]!==_?(Y=(0,n.jsxDEV)("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:_},void 0,!1),e[37]=_,e[38]=Y):Y=e[38];let F;e[39]!==c?(F=Ue.map(T=>(0,n.jsxDEV)("li",{children:(0,n.jsxDEV)("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":T.sql,onClick:c,type:"button",children:[(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"},void 0,!1)},void 0,!1),T.label]},void 0,!0)},T.label,!1)),e[39]=c,e[40]=F):F=e[40];let $;e[41]!==F?($=(0,n.jsxDEV)("ul",{className:"flex flex-col gap-px",children:F},void 0,!1),e[41]=F,e[42]=$):$=e[42];let I;e[43]!==Y||e[44]!==$?(I=(0,n.jsxDEV)("div",{children:[Y,$]},void 0,!0),e[43]=Y,e[44]=$,e[45]=I):I=e[45];let L;e[46]!==o||e[47]!==a||e[48]!==p||e[49]!==f?(L=o.length>0&&(0,n.jsxDEV)("div",{children:[(0,n.jsxDEV)("div",{className:"flex items-center justify-between px-1 pb-1",children:[(0,n.jsxDEV)("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:f("History")},void 0,!1),(0,n.jsxDEV)("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:a,type:"button",children:f("Clear history")},void 0,!1)]},void 0,!0),(0,n.jsxDEV)("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:o.map(T=>(0,n.jsxDEV)("li",{children:(0,n.jsxDEV)("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":T.sql,"data-testid":"sql-history-item",onClick:p,title:T.sql,type:"button",children:[(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"},void 0,!1)},void 0,!1),(0,n.jsxDEV)("span",{className:"truncate font-mono",children:T.sql},void 0,!1)]},void 0,!0)},`${T.at.toString()}:${T.sql}`,!1))},void 0,!1)]},void 0,!0),e[46]=o,e[47]=a,e[48]=p,e[49]=f,e[50]=L):L=e[50];let W;e[51]!==P||e[52]!==I||e[53]!==L?(W=(0,n.jsxDEV)("div",{className:"flex flex-1 flex-col gap-4 overflow-y-auto p-2",children:[P,I,L]},void 0,!0),e[51]=P,e[52]=I,e[53]=L,e[54]=W):W=e[54];let H;return e[55]!==W||e[56]!==M?(H=(0,n.jsxDEV)("aside",{className:"flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar",children:[M,W]},void 0,!0),e[55]=W,e[56]=M,e[57]=H):H=e[57],H},"SqlQuerySidebar"),Zt=ne(le.listTables),eo=ne(le.readTablePage),to=r(s=>{let e=(0,K.c)(16),t=he(),o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=[],e[0]=o):o=e[0];let[l,a]=(0,q.useState)(o),d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={},e[1]=d):d=e[1];let[p,c]=(0,q.useState)(d),u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=new Set,e[2]=u):u=e[2];let y=(0,q.useRef)(u),g,v;e[3]!==t||e[4]!==s?(g=r(()=>{let h={cancelled:!1};return Q(r(async()=>{try{let C=await t.query(Zt,{},se(s));h.cancelled||(a(C.map(no)),c({}),y.current=new Set)}catch{h.cancelled||(a([]),c({}),y.current=new Set)}},"load")()),()=>{h.cancelled=!0}},"t3"),v=[t,s],e[3]=t,e[4]=s,e[5]=g,e[6]=v):(g=e[5],v=e[6]),(0,q.useEffect)(g,v);let m;e[7]!==t||e[8]!==s?(m=r(h=>{if(y.current.has(h))return;y.current.add(h),Q(r(async()=>{try{let C=await t.query(eo,{limit:1,offset:0,table:h},se(s));c(A=>({...A,[h]:C.columns}))}catch{y.current.delete(h)}},"fetchColumns")())},"t5"),e[7]=t,e[8]=s,e[9]=m):m=e[9];let f=m,N;e[10]!==p||e[11]!==l?(N={columns:p,tables:l},e[10]=p,e[11]=l,e[12]=N):N=e[12];let x=N,S;return e[13]!==f||e[14]!==x?(S={probe:f,schema:x},e[13]=f,e[14]=x,e[15]=S):S=e[15],S},"useSqlSchema"),ye=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,oo=r(s=>{let e=new Set;ye.lastIndex=0;let t=ye.exec(s);for(;t!==null;)e.add(t[1]??t[2]),t=ye.exec(s);return[...e]},"referencedTables");function no(s){return s.name}r(no,"_temp$2");var so="lunora-studio-sql-tabs",lo="lunora-studio-sql-active-tab",Se=12,X=r((s="",e="")=>({activeId:null,id:xe("tab"),name:e,sql:s}),"makeTab"),ro=r(()=>ge(lo,""),"usePersistedActive"),io=r(s=>{let[e,t]=re(so),[o,l]=ro(),a=(0,q.useRef)(null);e.length===0&&a.current===null&&(a.current=s()),(0,q.useEffect)(()=>{if(e.length===0&&a.current!==null){let c=a.current;t([c])}},[t,e.length]);let d=e.length===0&&a.current!==null?[a.current]:e;return{activeId:d.some(c=>c.id===o)?o:d[0]?.id??"",setActiveId:l,setTabs:t,tabs:d}},"usePersistedTabs"),Ye=r(s=>s.activeId===null&&s.sql.trim()!=="","isDirty"),ao=r((s,e)=>[...s,e].slice(-Se),"addTab"),co=r((s,e,t)=>{let o=s.findIndex(d=>d.id===e);if(o===-1)return{activeId:s[0]?.id??"",tabs:[...s]};let l=s.filter(d=>d.id!==e);if(l.length===0){let d=t();return{activeId:d.id,tabs:[d]}}return{activeId:l[Math.min(o,l.length-1)].id,tabs:l}},"closeTab"),uo=r((s,e)=>{let t=s.filter(o=>o.id===e);return t.length===0?{activeId:s[0]?.id??"",tabs:[...s]}:{activeId:e,tabs:t}},"closeOtherTabs"),fo=r((s,e,t)=>{let o=s.findIndex(a=>a.id===e);if(o===-1)return{activeId:t,tabs:[...s]};let l=s.slice(0,o+1);return{activeId:l.some(a=>a.id===t)?t:e,tabs:l}},"closeTabsToRight"),mo=r(s=>{let e=s();return{activeId:e.id,tabs:[e]}},"closeAllTabs"),po=r((s,e,t)=>{if(s==="others")return e.filter(o=>o.id!==t);if(s==="right"){let o=e.findIndex(l=>l.id===t);return o===-1?[]:e.slice(o+1)}return[...e]},"tabsClosedBy"),bo=r((s,e)=>s.trim()===""?e:(s.split(`
3
3
  `)[0]??s).slice(0,24),"derivedTabLabel"),ho=r(s=>{let e=(0,K.c)(14),{initial:t,onCancel:o,onCommit:l,placeholder:a,testId:d}=s,p=G(),c=xo,u;e[0]!==l?(u=r(N=>{l(N.currentTarget.value.trim())},"t1"),e[0]=l,e[1]=u):u=e[1];let y=u,g;e[2]!==o||e[3]!==l?(g=r(N=>{N.key==="Enter"?l(N.currentTarget.value.trim()):N.key==="Escape"&&o()},"t2"),e[2]=o,e[3]=l,e[4]=g):g=e[4];let v=g,m;e[5]!==p?(m=p("Tab title"),e[5]=p,e[6]=m):m=e[6];let f;return e[7]!==t||e[8]!==y||e[9]!==v||e[10]!==a||e[11]!==m||e[12]!==d?(f=(0,n.jsxDEV)("input",{"aria-label":m,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":d,defaultValue:t,onBlur:y,onKeyDown:v,placeholder:a,ref:c,type:"text"},void 0,!1),e[7]=t,e[8]=y,e[9]=v,e[10]=a,e[11]=m,e[12]=d,e[13]=f):f=e[13],f},"TabRenameInput"),vo=r(s=>{let e=(0,K.c)(29),{idBase:t,onDiscard:o,onKeep:l}=s,a=G(),d=`sql-tab-close-prompt-${t}`,p;e[0]!==a?(p=a("Discard?"),e[0]=a,e[1]=p):p=e[1];let c;e[2]!==p?(c=(0,n.jsxDEV)("span",{className:"text-[11px] text-muted-foreground",children:p},void 0,!1),e[2]=p,e[3]=c):c=e[3];let u;e[4]!==a?(u=a("Discard changes"),e[4]=a,e[5]=u):u=e[5];let y=`sql-tab-close-confirm-${t}`,g;e[6]!==a?(g=a("Discard changes"),e[6]=a,e[7]=g):g=e[7];let v;e[8]===Symbol.for("react.memo_cache_sentinel")?(v=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M5 13l4 4L19 7"},void 0,!1)},void 0,!1),e[8]=v):v=e[8];let m;e[9]!==o||e[10]!==u||e[11]!==y||e[12]!==g?(m=(0,n.jsxDEV)("button",{"aria-label":u,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":y,onClick:o,title:g,type:"button",children:v},void 0,!1),e[9]=o,e[10]=u,e[11]=y,e[12]=g,e[13]=m):m=e[13];let f;e[14]!==a?(f=a("Keep editing"),e[14]=a,e[15]=f):f=e[15];let N=`sql-tab-close-cancel-${t}`,x;e[16]!==a?(x=a("Keep editing"),e[16]=a,e[17]=x):x=e[17];let S;e[18]===Symbol.for("react.memo_cache_sentinel")?(S=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M6 6l12 12M18 6 6 18"},void 0,!1)},void 0,!1),e[18]=S):S=e[18];let h;e[19]!==l||e[20]!==N||e[21]!==x||e[22]!==f?(h=(0,n.jsxDEV)("button",{"aria-label":f,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":N,onClick:l,title:x,type:"button",children:S},void 0,!1),e[19]=l,e[20]=N,e[21]=x,e[22]=f,e[23]=h):h=e[23];let w;return e[24]!==d||e[25]!==h||e[26]!==c||e[27]!==m?(w=(0,n.jsxDEV)("span",{className:"flex shrink-0 items-center gap-1","data-testid":d,role:"group",children:[c,m,h]},void 0,!0),e[24]=d,e[25]=h,e[26]=c,e[27]=m,e[28]=w):w=e[28],w},"TabCloseConfirm"),go=r(s=>{let e=(0,K.c)(47),{active:t,canClose:o,onClose:l,onMenu:a,onRename:d,onSelect:p,tab:c}=s,u=G(),[y,g]=(0,q.useState)(!1),[v,m]=(0,q.useState)(!1),f;e[0]!==a||e[1]!==c.id?(f=r(z=>{a(c.id,z)},"t1"),e[0]=a,e[1]=c.id,e[2]=f):f=e[2];let N=f,x;e[3]!==p||e[4]!==c.id?(x=r(()=>{p(c.id)},"t2"),e[3]=p,e[4]=c.id,e[5]=x):x=e[5];let S=x,h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=r(()=>{g(!0)},"t3"),e[6]=h):h=e[6];let w=h,C;e[7]!==l||e[8]!==c?(C=r(z=>{z.stopPropagation(),Ye(c)?m(!0):l(c.id)},"t4"),e[7]=l,e[8]=c,e[9]=C):C=e[9];let A=C,E;e[10]!==l||e[11]!==c.id?(E=r(z=>{z.stopPropagation(),m(!1),l(c.id)},"t5"),e[10]=l,e[11]=c.id,e[12]=E):E=e[12];let M=E,D;e[13]===Symbol.for("react.memo_cache_sentinel")?(D=r(z=>{z.stopPropagation(),m(!1)},"t6"),e[13]=D):D=e[13];let O=D,B;e[14]!==d||e[15]!==c.id?(B=r(z=>{d(c.id,z),g(!1)},"t7"),e[14]=d,e[15]=c.id,e[16]=B):B=e[16];let P=B,_;e[17]===Symbol.for("react.memo_cache_sentinel")?(_=r(()=>{g(!1)},"t8"),e[17]=_):_=e[17];let Y=_,F;e[18]!==c.name?(F=c.name.trim(),e[18]=c.name,e[19]=F):F=e[19];let $=F,I;e[20]!==u||e[21]!==c.sql?(I=bo(c.sql,u("Untitled")),e[20]=u,e[21]=c.sql,e[22]=I):I=e[22];let L=I,W=t?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground",H;e[23]!==W?(H=oe("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",W),e[23]=W,e[24]=H):H=e[24];let T=`sql-tab-${c.id}`,R;e[25]!==t||e[26]!==P||e[27]!==$||e[28]!==L||e[29]!==y||e[30]!==S||e[31]!==u||e[32]!==c.id?(R=y?(0,n.jsxDEV)(ho,{initial:$,onCancel:Y,onCommit:P,placeholder:L,testId:`sql-tab-rename-${c.id}`},void 0,!1):(0,n.jsxDEV)("button",{"aria-pressed":t,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${c.id}`,onClick:S,onDoubleClick:w,title:u("Double-click to rename"),type:"button",children:$===""?L:$},void 0,!1),e[25]=t,e[26]=P,e[27]=$,e[28]=L,e[29]=y,e[30]=S,e[31]=u,e[32]=c.id,e[33]=R):R=e[33];let j;e[34]!==o||e[35]!==M||e[36]!==v||e[37]!==A||e[38]!==u||e[39]!==c.id?(j=o&&(v?(0,n.jsxDEV)(vo,{idBase:c.id,onDiscard:M,onKeep:O},void 0,!1):(0,n.jsxDEV)("button",{"aria-label":u("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${c.id}`,onClick:A,title:u("Close tab"),type:"button",children:(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M6 6l12 12M18 6 6 18"},void 0,!1)},void 0,!1)},void 0,!1)),e[34]=o,e[35]=M,e[36]=v,e[37]=A,e[38]=u,e[39]=c.id,e[40]=j):j=e[40];let J;return e[41]!==N||e[42]!==H||e[43]!==T||e[44]!==R||e[45]!==j?(J=(0,n.jsxDEV)("div",{className:H,"data-testid":T,onContextMenu:N,children:[R,j]},void 0,!0),e[41]=N,e[42]=H,e[43]=T,e[44]=R,e[45]=j,e[46]=J):J=e[46],J},"TabButton");function xo(s){s?.focus(),s?.select()}r(xo,"_temp$1");var yo=ne(le.runSql),No="lunora-studio-sql-queries",So="lunora-studio-sql-history",ko="lunora-studio-sql-split-view",Co=25,wo={minWidth:"2.75rem",paddingInline:"0.5rem"},Ne={error:null,pane:"results",result:null},To=r(s=>{let e=(0,K.c)(16),{result:t}=s;if(t.columns.length===0){let c=t.rowCount===0?"0 rows":"",u;return e[0]!==c?(u=(0,n.jsxDEV)("p",{className:"p-4 text-sm text-muted-foreground",children:c},void 0,!1),e[0]=c,e[1]=u):u=e[1],u}let o;e[2]!==t.columns?(o=t.columns.map(Eo),e[2]=t.columns,e[3]=o):o=e[3];let l;e[4]!==o?(l=(0,n.jsxDEV)(Ae,{className:"sticky top-0 z-10 bg-muted",children:(0,n.jsxDEV)(ve,{children:o},void 0,!1)},void 0,!1),e[4]=o,e[5]=l):l=e[5];let a;if(e[6]!==t.columns||e[7]!==t.rows){let c;e[9]!==t.columns?(c=r((u,y)=>(0,n.jsxDEV)(ve,{"data-testid":"sql-row",children:t.columns.map(g=>(0,n.jsxDEV)(De,{className:"max-w-md truncate font-mono text-xs",children:(0,n.jsxDEV)(Be,{value:u[g]},void 0,!1)},g,!1))},y,!1),"t42"),e[9]=t.columns,e[10]=c):c=e[10],a=t.rows.map(c),e[6]=t.columns,e[7]=t.rows,e[8]=a}else a=e[8];let d;e[11]!==a?(d=(0,n.jsxDEV)(Oe,{children:a},void 0,!1),e[11]=a,e[12]=d):d=e[12];let p;return e[13]!==l||e[14]!==d?(p=(0,n.jsxDEV)(Le,{"data-testid":"sql-rows",children:[l,d]},void 0,!0),e[13]=l,e[14]=d,e[15]=p):p=e[15],p},"SqlResultTable"),Wo=r(({initialShardKey:s})=>{let e=he(),t=G(),[o,l]=re(No),[a,d]=re(So),[p,c]=(0,q.useState)(""),u=r(()=>X(Ue[0]?.sql??""),"seedTab"),{activeId:y,setActiveId:g,setTabs:v,tabs:m}=io(u),[f,N]=(0,q.useState)({}),[x,S]=(0,q.useState)(s??""),[h,w]=(0,q.useState)(!1),[C,A]=ge(ko,!1),[E,M]=(0,q.useState)(null),[D,O]=(0,q.useState)(null),B=(0,q.useRef)(null),P=(0,q.useRef)(null),_=(0,q.useRef)(null),Y=(0,q.useId)(),{probe:F,schema:$}=to(x),I=m.find(i=>i.id===y)??m[0]??X(),L=I.sql,{activeId:W}=I,H=f[I.id]??Ne,{error:T,result:R}=H,j=H.pane,J=r(i=>{v(b=>b.map(k=>k.id===I.id?{...k,...i}:k))},"patchActiveTab"),z=r(i=>{N(b=>{let k=b[I.id]??Ne;return{...b,[I.id]:{error:i.error,pane:i.pane??k.pane,result:i.result}}})},"setActiveOutput"),Ce=r(i=>{N(b=>{let k=b[I.id]??Ne;return{...b,[I.id]:{...k,pane:i}}})},"setActivePane"),ce=r(i=>{J({sql:i}),W!==null&&l(b=>b.map(k=>k.id===W?{...k,sql:i}:k))},"setDraft"),je=Kt($,P,ce),{close:de,commit:we,move:ue,refresh:Z,state:V}=je,Ke=r(i=>{ue(i-(V?.active??0)),we()},"onPickSuggestion");(0,q.useEffect)(()=>{let i=P.current;i!==null&&i===document.activeElement&&Z(i.value,i.selectionStart)},[Z,$]);let Ge=r(i=>{d(b=>b[0]?.sql===i?b:[{at:Date.now(),sql:i},...b.filter(U=>U.sql!==i)].slice(0,Co))},"recordHistory"),fe=r(async i=>{if(L.trim()==="")return;w(!0);let b=i==="explain"?`EXPLAIN QUERY PLAN ${L}`:L;try{let k=await e.query(yo,{sql:b},se(x));z({error:null,pane:i,result:k}),qe(x),Ge(b)}catch(k){z({error:Ee(k),pane:i,result:null})}finally{w(!1)}},"run"),Ve=r(()=>{Q(fe("results"))},"onRun"),Je=r(i=>{let{selectionStart:b,value:k}=i.target;ce(k);for(let U of oo(k))F(U);Z(k,b)},"onDraftChange"),Qe=r(i=>{let b=i.currentTarget;Z(b.value,b.selectionStart)},"onEditorSelect"),Xe=r(i=>{if(V!==null){if(i.key==="ArrowDown"){i.preventDefault(),ue(1);return}if(i.key==="ArrowUp"){i.preventDefault(),ue(-1);return}if(i.key==="Escape"){i.preventDefault(),de();return}if((i.key==="Enter"||i.key==="Tab")&&!i.metaKey&&!i.ctrlKey&&we()){i.preventDefault();return}}(i.metaKey||i.ctrlKey)&&i.key==="Enter"&&(i.preventDefault(),Q(fe(j)))},"onEditorKeyDown"),Ze=r(()=>{requestAnimationFrame(()=>{de()})},"onEditorBlur"),et=r(i=>{B.current!==null&&(B.current.scrollTop=i.currentTarget.scrollTop)},"onEditorScroll"),ee=r((i,b)=>{v(k=>k.map(U=>U.id===I.id?{...U,activeId:b,sql:i}:U)),z({error:null,result:null})},"loadIntoActiveTab"),tt=r(()=>{let i={id:xe("q"),name:t("Untitled query"),sql:""};l(b=>[i,...b]),ee("",i.id)},"newQuery"),ot=r(i=>{let b=o.find(k=>k.id===i);b!==void 0&&(ee(b.sql,i),_.current?.querySelector(`[data-testid="sql-query-${i}"]`)?.scrollIntoView({block:"nearest"}))},"selectQuery"),nt=r(i=>{l(b=>b.filter(k=>k.id!==i)),v(b=>b.map(k=>k.activeId===i?{...k,activeId:null}:k))},"deleteQuery"),st=r(i=>{ee(i.currentTarget.dataset.sql??"",null)},"loadTemplate"),lt=r(i=>{ee(i.currentTarget.dataset.sql??"",null)},"loadFromHistory"),rt=r(()=>{d([])},"clearHistory"),it=r(()=>{ce($t(L))},"formatDraft"),at=r(()=>{if(m.length>=Se)return;let i=X();v(b=>ao(b,i)),g(i.id)},"addEditorTab"),te=r(i=>{M(null),O(null),v(i.tabs),g(i.activeId);let b=new Set(i.tabs.map(k=>k.id));N(k=>Object.fromEntries(Object.entries(k).filter(([U])=>b.has(U))))},"commitTabs"),ct=r(i=>{te(co(m,i,X))},"closeEditorTab"),Te=r((i,b)=>{te(i==="others"?uo(m,b):i==="right"?fo(m,b,y):mo(X))},"applyBulk"),me=r(i=>{E!==null&&(po(i,m,E.id).some(b=>Ye(b))?O(i):Te(i,E.id))},"requestBulk"),dt=r((i,b)=>{b.preventDefault(),O(null),M({id:i,x:b.clientX,y:b.clientY})},"openTabMenu"),ut=r(()=>{M(null),O(null)},"closeTabMenu"),ft=r(i=>{i.preventDefault(),M(null),O(null)},"onBackdropContextMenu"),mt=r(()=>{me("others")},"onCloseOthers"),pt=r(()=>{me("right")},"onCloseToRight"),bt=r(()=>{me("all")},"onCloseAll"),ht=r(()=>{E!==null&&D!==null&&Te(D,E.id),O(null)},"confirmBulk"),vt=r(()=>{O(null)},"cancelBulk"),gt=E===null?void 0:{left:E.x,top:E.y},xt=r(i=>{de(),g(i)},"selectTab"),yt=r((i,b)=>{v(k=>k.map(U=>U.id===i?{...U,name:b}:U))},"renameTab"),Nt=r(()=>{Ce("results")},"showResults"),St=r(()=>{Q(fe("explain"))},"showExplain"),kt=r(()=>{Ce("chart")},"showChart"),Ct=r(()=>{A(!C)},"toggleSplit"),wt=L.split(`
4
4
  `).length,Tt=r(i=>{c(i.target.value)},"onSearchChange"),pe=r(i=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${i?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,"tabClass"),Et=C?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",qt=C?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";return(0,n.jsxDEV)("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[(0,n.jsxDEV)(Xt,{activeId:W,history:a,listRef:_,onClearHistory:rt,onDelete:nt,onLoadHistory:lt,onLoadTemplate:st,onNew:tt,onSearchChange:Tt,onSelect:ot,queries:o,search:p},void 0,!1),(0,n.jsxDEV)("div",{className:"flex min-w-0 flex-1 flex-col",children:[(0,n.jsxDEV)("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[m.map(i=>(0,n.jsxDEV)(go,{active:i.id===I.id,canClose:m.length>1,onClose:ct,onMenu:dt,onRename:yt,onSelect:xt,tab:i},i.id,!1)),(0,n.jsxDEV)("button",{"aria-label":t("New tab"),className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:m.length>=Se,onClick:at,title:t("New tab"),type:"button",children:(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M12 5v14M5 12h14"},void 0,!1)},void 0,!1)},void 0,!1)]},void 0,!0),E!==null&&(0,n.jsxDEV)(n.Fragment,{children:[(0,n.jsxDEV)("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:ut,onContextMenu:ft,role:"presentation"},void 0,!1),(0,n.jsxDEV)("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:gt,children:D===null?(0,n.jsxDEV)(n.Fragment,{children:[(0,n.jsxDEV)("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:m.length<=1,onClick:mt,role:"menuitem",type:"button",children:t("Close other tabs")},void 0,!1),(0,n.jsxDEV)("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:m.findIndex(i=>i.id===E.id)>=m.length-1,onClick:pt,role:"menuitem",type:"button",children:t("Close tabs to the right")},void 0,!1),(0,n.jsxDEV)("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:bt,role:"menuitem",type:"button",children:t("Close all tabs")},void 0,!1)]},void 0,!0):(0,n.jsxDEV)("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[(0,n.jsxDEV)("p",{className:"pb-1.5 text-xs text-muted-foreground",children:t("Discard unsaved tabs?")},void 0,!1),(0,n.jsxDEV)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsxDEV)("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:ht,type:"button",children:t("Discard")},void 0,!1),(0,n.jsxDEV)("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:vt,type:"button",children:t("Cancel")},void 0,!1)]},void 0,!0)]},void 0,!0)},void 0,!1)]},void 0,!0),(0,n.jsxDEV)("div",{className:Et,children:[(0,n.jsxDEV)("div",{className:"flex min-h-0 min-w-0 flex-1",children:[(0,n.jsxDEV)("div",{"aria-hidden":"true",className:"shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",ref:B,style:wo,children:Array.from({length:wt},(i,b)=>(0,n.jsxDEV)("div",{children:b+1},b,!1))},void 0,!1),(0,n.jsxDEV)("div",{className:"relative min-w-0 flex-1",children:[(0,n.jsxDEV)("textarea",{"aria-activedescendant":V===null?void 0:`${Y}-opt-${V.active.toString()}`,"aria-autocomplete":"list","aria-controls":V===null?void 0:Y,"aria-expanded":V!==null,"aria-label":t("SQL query"),className:"size-full resize-none bg-background p-3 font-mono text-xs leading-5 outline-none","data-testid":"sql-input",onBlur:Ze,onChange:Je,onKeyDown:Xe,onScroll:et,onSelect:Qe,placeholder:"SELECT * FROM \u2026",ref:P,role:"combobox",spellCheck:!1,value:L},void 0,!1),(0,n.jsxDEV)(Jt,{listboxId:Y,onPick:Ke,state:V},void 0,!1)]},void 0,!0)]},void 0,!0),(0,n.jsxDEV)("div",{className:qt,children:[(0,n.jsxDEV)("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[(0,n.jsxDEV)("button",{className:pe(j==="results"),"data-testid":"sql-tab-results",onClick:Nt,type:"button",children:t("Results")},void 0,!1),(0,n.jsxDEV)("button",{className:pe(j==="chart"),"data-testid":"sql-tab-chart",onClick:kt,type:"button",children:t("Chart")},void 0,!1),(0,n.jsxDEV)("button",{className:pe(j==="explain"),"data-testid":"sql-tab-explain",onClick:St,type:"button",children:t("Explain")},void 0,!1),(0,n.jsxDEV)("div",{className:"ms-auto flex items-center gap-2",children:[(0,n.jsxDEV)("button",{"aria-label":t("Split editor and results"),"aria-pressed":C,className:`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${C?"bg-accent text-foreground":"text-muted-foreground"}`,"data-testid":"sql-split-toggle",onClick:Ct,title:t("Split editor and results"),type:"button",children:(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[(0,n.jsxDEV)("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"},void 0,!1),(0,n.jsxDEV)("path",{d:"M12 4v16"},void 0,!1)]},void 0,!0)},void 0,!1),R!==null&&R.columns.length>0&&(0,n.jsxDEV)($e,{columns:R.columns,name:"query-result",rows:R.rows},void 0,!1),(0,n.jsxDEV)("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:h,onClick:it,type:"button",children:t("Format")},void 0,!1),(0,n.jsxDEV)(Ie,{onChange:S,testId:"sql-shard-input",value:x},void 0,!1),(0,n.jsxDEV)("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:h,onClick:Ve,type:"button",children:[t(h?"Running\u2026":"Run"),(0,n.jsxDEV)("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"\u2318\u21B5"},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0),(0,n.jsxDEV)("div",{className:"min-h-0 flex-1 overflow-auto",children:[T!==null&&(0,n.jsxDEV)(Re,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:T},void 0,!1),T===null&&R===null&&(0,n.jsxDEV)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:t("Click Run to execute your query.")},void 0,!1),T===null&&R!==null&&(0,n.jsxDEV)("div",{"data-testid":"sql-result",children:[j==="chart"?(0,n.jsxDEV)(Pe,{result:R},void 0,!1):(0,n.jsxDEV)(To,{result:R},void 0,!1),(0,n.jsxDEV)("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:R.truncated?t("Showing the first {max} of {count} rows.",{count:R.rowCount,max:R.rows.length}):t("{count} rows",{count:R.rowCount})},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0)]},void 0,!0)]},void 0,!0)]},void 0,!0)},"SqlEditorPanel");function Eo(s){return(0,n.jsxDEV)(Me,{children:s},s,!1)}r(Eo,"_temp");export{Wo as SqlEditorPanel};
@@ -1 +1 @@
1
- import{a as $}from"./chunk-UGUEC6BC.js";import{a as W}from"./chunk-YBGC4PPD.js";import{a as _}from"./chunk-2K47A3P6.js";import{a as q}from"./chunk-CACB34RQ.js";import"./chunk-XNJNSCLM.js";import{a as G,b as P,c as V,d as b,e as i,f as o}from"./chunk-GTM65MVX.js";import{a as y}from"./chunk-JSEXCW5Q.js";import{a as U}from"./chunk-UKDJ4H7I.js";import{b as Q}from"./chunk-TBMYIZIO.js";import{R as w}from"./chunk-3CJW6NWG.js";import{c as L}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as g}from"./chunk-BOXSWNXZ.js";import{a as A}from"./chunk-TAD43CG5.js";import{b as H}from"./chunk-C7WTJLC3.js";import{a as k,e as B}from"./chunk-SEU5V7I6.js";import{b as T}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as M}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as S,e as F,f as K,g as O,k as j,o as z}from"./chunk-E75ANNWX.js";import"./chunk-GMSGZDDH.js";import{a as n,e as D,f as le,h as ce}from"./chunk-RRCPZMC2.js";var a=D(le(),1);var e=D(ce(),1);var ue=F(g.runMigration),we=n(({initialShardKey:J})=>{let X=M(),r=S(),[c,Y]=(0,a.useState)(J??""),[x,Z]=(0,a.useState)(""),[R,ee]=(0,a.useState)("up"),[f,re]=(0,a.useState)(!0),[u,N]=(0,a.useState)(!1),[d,h]=(0,a.useState)(null),[C,p]=(0,a.useState)(null),m=_(c.trim(),400),I=c.trim()===m,s=H(g.migrationStatus,{},{live:!0,shardKey:m}),l=s.data?.migrations??null,te=s.error,{errorSource:ae,liveError:ie}=s;(0,a.useEffect)(()=>{s.data!==void 0&&Q(m)},[s.data,m]);let oe=n(async()=>{let t=x.trim();if(t===""){p(r("Enter a migration id")),h(null);return}N(!0),p(null);try{let v=await X.query(ue,{direction:R,dryRun:f,id:t},K(c));h(v),s.refetch()}catch(v){h(null),p(O(v))}finally{N(!1)}},"run"),E=n(()=>{j(oe())},"runMigration"),ne=n(t=>{Z(t.target.value)},"onIdChange"),se=n(t=>{ee(t.target.value==="down"?"down":"up")},"onDirectionChange"),de=n(t=>{re(t.target.checked)},"onDryRunChange");return(0,e.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-migrations",children:[(0,e.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsxDEV)(U,{onChange:Y,testId:"mg-shard-input",value:c},void 0,!1),(0,e.jsxDEV)($,{message:ie,prefix:"mg"},void 0,!1)]},void 0,!0),te!==null&&(0,e.jsxDEV)(q,{error:ae,testId:"mg-status-error"},void 0,!1),l!==null&&l.length===0&&(0,e.jsxDEV)(A,{description:r("Data migrations you run against this shard will be tracked here."),icon:(0,e.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,e.jsxDEV)("path",{d:"M4 12a8 8 0 0 1 13.7-5.6L20 8M20 4v4h-4M20 12a8 8 0 0 1-13.7 5.6L4 16m0 4v-4h4"},void 0,!1)},void 0,!1),testId:"mg-empty",title:r("No migrations have run on this shard.")},void 0,!1),l!==null&&l.length>0&&(0,e.jsxDEV)(k,{className:"overflow-hidden py-0",children:(0,e.jsxDEV)(B,{className:"px-0",children:(0,e.jsxDEV)(G,{"data-testid":"mg-table",children:[(0,e.jsxDEV)(P,{children:(0,e.jsxDEV)(b,{children:[(0,e.jsxDEV)(i,{children:r("id")},void 0,!1),(0,e.jsxDEV)(i,{children:r("direction")},void 0,!1),(0,e.jsxDEV)(i,{children:r("status")},void 0,!1),(0,e.jsxDEV)(i,{children:r("processed")},void 0,!1),(0,e.jsxDEV)(i,{children:r("changed")},void 0,!1),(0,e.jsxDEV)(i,{children:r("updated")},void 0,!1),(0,e.jsxDEV)(i,{children:r("error")},void 0,!1)]},void 0,!0)},void 0,!1),(0,e.jsxDEV)(V,{children:l.map(t=>(0,e.jsxDEV)(b,{"data-testid":`mg-row-${t.id}`,children:[(0,e.jsxDEV)(o,{children:t.id},void 0,!1),(0,e.jsxDEV)(o,{children:t.direction},void 0,!1),(0,e.jsxDEV)(o,{children:(0,e.jsxDEV)(T,{variant:"secondary",children:t.status},void 0,!1)},void 0,!1),(0,e.jsxDEV)(o,{children:t.processed},void 0,!1),(0,e.jsxDEV)(o,{children:t.changed},void 0,!1),(0,e.jsxDEV)(o,{children:z(t.updatedAt)},void 0,!1),(0,e.jsxDEV)(o,{children:t.error??""},void 0,!1)]},t.id,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs",children:[(0,e.jsxDEV)(y,{children:r("Run migration")},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsxDEV)(w,{"aria-label":r("Migration id"),className:"w-auto","data-testid":"mg-id-input",onChange:ne,placeholder:r("migration id"),value:x},void 0,!1),(0,e.jsxDEV)("select",{"aria-label":r("Direction"),className:"flex h-9 rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","data-testid":"mg-direction",onChange:se,value:R,children:[(0,e.jsxDEV)("option",{value:"up",children:r("up")},void 0,!1),(0,e.jsxDEV)("option",{value:"down",children:r("down")},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(y,{className:"flex items-center gap-1.5",htmlFor:"mg-dry-run",children:[(0,e.jsxDEV)("input",{checked:f,className:"size-4 accent-primary","data-testid":"mg-dry-run",id:"mg-dry-run",onChange:de,type:"checkbox"},void 0,!1),r("Dry run")]},void 0,!0),f?(0,e.jsxDEV)(L,{"data-testid":"mg-run",disabled:u||!I,onClick:E,size:"sm",type:"button",children:r(u?"Running\u2026":"Run")},void 0,!1):(0,e.jsxDEV)(W,{confirmLabel:r(u?"Running\u2026":"Run migration?"),disabled:u||!I,onConfirm:E,testId:"mg-run",children:r("Run")},void 0,!1)]},void 0,!0)]},void 0,!0),C!==null&&(0,e.jsxDEV)("pre",{className:"text-sm text-destructive whitespace-pre-wrap","data-testid":"mg-run-error",role:"alert",children:C},void 0,!1),d!==null&&(0,e.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"mg-run-result",children:[d.dryRun?r("Dry run: "):"",r("{status} \u2014 processed",{status:d.status}),d.processed,r(", changed"),d.changed]},void 0,!0)]},void 0,!0)},"MigrationsPanel");export{we as MigrationsPanel};
1
+ import{a as $}from"./chunk-UGUEC6BC.js";import{a as W}from"./chunk-YBGC4PPD.js";import{a as _}from"./chunk-2K47A3P6.js";import{a as q}from"./chunk-HN6KJXYQ.js";import"./chunk-XNJNSCLM.js";import{a as G,b as P,c as V,d as b,e as i,f as o}from"./chunk-GTM65MVX.js";import{a as y}from"./chunk-JSEXCW5Q.js";import{a as U}from"./chunk-UKDJ4H7I.js";import{b as Q}from"./chunk-TBMYIZIO.js";import{R as w}from"./chunk-3CJW6NWG.js";import{c as L}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as g}from"./chunk-BOXSWNXZ.js";import{a as A}from"./chunk-TAD43CG5.js";import{b as H}from"./chunk-RHZ4M2NZ.js";import{a as k,e as B}from"./chunk-SEU5V7I6.js";import{b as T}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as M}from"./chunk-XLXNLJ4N.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as S,e as F,f as K,g as O,k as j,o as z}from"./chunk-E75ANNWX.js";import"./chunk-JHKMUTIF.js";import{a as n,e as D,f as le,h as ce}from"./chunk-RRCPZMC2.js";var a=D(le(),1);var e=D(ce(),1);var ue=F(g.runMigration),we=n(({initialShardKey:J})=>{let X=M(),r=S(),[c,Y]=(0,a.useState)(J??""),[x,Z]=(0,a.useState)(""),[R,ee]=(0,a.useState)("up"),[f,re]=(0,a.useState)(!0),[u,N]=(0,a.useState)(!1),[d,h]=(0,a.useState)(null),[C,p]=(0,a.useState)(null),m=_(c.trim(),400),I=c.trim()===m,s=H(g.migrationStatus,{},{live:!0,shardKey:m}),l=s.data?.migrations??null,te=s.error,{errorSource:ae,liveError:ie}=s;(0,a.useEffect)(()=>{s.data!==void 0&&Q(m)},[s.data,m]);let oe=n(async()=>{let t=x.trim();if(t===""){p(r("Enter a migration id")),h(null);return}N(!0),p(null);try{let v=await X.query(ue,{direction:R,dryRun:f,id:t},K(c));h(v),s.refetch()}catch(v){h(null),p(O(v))}finally{N(!1)}},"run"),E=n(()=>{j(oe())},"runMigration"),ne=n(t=>{Z(t.target.value)},"onIdChange"),se=n(t=>{ee(t.target.value==="down"?"down":"up")},"onDirectionChange"),de=n(t=>{re(t.target.checked)},"onDryRunChange");return(0,e.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-migrations",children:[(0,e.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsxDEV)(U,{onChange:Y,testId:"mg-shard-input",value:c},void 0,!1),(0,e.jsxDEV)($,{message:ie,prefix:"mg"},void 0,!1)]},void 0,!0),te!==null&&(0,e.jsxDEV)(q,{error:ae,testId:"mg-status-error"},void 0,!1),l!==null&&l.length===0&&(0,e.jsxDEV)(A,{description:r("Data migrations you run against this shard will be tracked here."),icon:(0,e.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,e.jsxDEV)("path",{d:"M4 12a8 8 0 0 1 13.7-5.6L20 8M20 4v4h-4M20 12a8 8 0 0 1-13.7 5.6L4 16m0 4v-4h4"},void 0,!1)},void 0,!1),testId:"mg-empty",title:r("No migrations have run on this shard.")},void 0,!1),l!==null&&l.length>0&&(0,e.jsxDEV)(k,{className:"overflow-hidden py-0",children:(0,e.jsxDEV)(B,{className:"px-0",children:(0,e.jsxDEV)(G,{"data-testid":"mg-table",children:[(0,e.jsxDEV)(P,{children:(0,e.jsxDEV)(b,{children:[(0,e.jsxDEV)(i,{children:r("id")},void 0,!1),(0,e.jsxDEV)(i,{children:r("direction")},void 0,!1),(0,e.jsxDEV)(i,{children:r("status")},void 0,!1),(0,e.jsxDEV)(i,{children:r("processed")},void 0,!1),(0,e.jsxDEV)(i,{children:r("changed")},void 0,!1),(0,e.jsxDEV)(i,{children:r("updated")},void 0,!1),(0,e.jsxDEV)(i,{children:r("error")},void 0,!1)]},void 0,!0)},void 0,!1),(0,e.jsxDEV)(V,{children:l.map(t=>(0,e.jsxDEV)(b,{"data-testid":`mg-row-${t.id}`,children:[(0,e.jsxDEV)(o,{children:t.id},void 0,!1),(0,e.jsxDEV)(o,{children:t.direction},void 0,!1),(0,e.jsxDEV)(o,{children:(0,e.jsxDEV)(T,{variant:"secondary",children:t.status},void 0,!1)},void 0,!1),(0,e.jsxDEV)(o,{children:t.processed},void 0,!1),(0,e.jsxDEV)(o,{children:t.changed},void 0,!1),(0,e.jsxDEV)(o,{children:z(t.updatedAt)},void 0,!1),(0,e.jsxDEV)(o,{children:t.error??""},void 0,!1)]},t.id,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs",children:[(0,e.jsxDEV)(y,{children:r("Run migration")},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsxDEV)(w,{"aria-label":r("Migration id"),className:"w-auto","data-testid":"mg-id-input",onChange:ne,placeholder:r("migration id"),value:x},void 0,!1),(0,e.jsxDEV)("select",{"aria-label":r("Direction"),className:"flex h-9 rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","data-testid":"mg-direction",onChange:se,value:R,children:[(0,e.jsxDEV)("option",{value:"up",children:r("up")},void 0,!1),(0,e.jsxDEV)("option",{value:"down",children:r("down")},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(y,{className:"flex items-center gap-1.5",htmlFor:"mg-dry-run",children:[(0,e.jsxDEV)("input",{checked:f,className:"size-4 accent-primary","data-testid":"mg-dry-run",id:"mg-dry-run",onChange:de,type:"checkbox"},void 0,!1),r("Dry run")]},void 0,!0),f?(0,e.jsxDEV)(L,{"data-testid":"mg-run",disabled:u||!I,onClick:E,size:"sm",type:"button",children:r(u?"Running\u2026":"Run")},void 0,!1):(0,e.jsxDEV)(W,{confirmLabel:r(u?"Running\u2026":"Run migration?"),disabled:u||!I,onConfirm:E,testId:"mg-run",children:r("Run")},void 0,!1)]},void 0,!0)]},void 0,!0),C!==null&&(0,e.jsxDEV)("pre",{className:"text-sm text-destructive whitespace-pre-wrap","data-testid":"mg-run-error",role:"alert",children:C},void 0,!1),d!==null&&(0,e.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"mg-run-result",children:[d.dryRun?r("Dry run: "):"",r("{status} \u2014 processed",{status:d.status}),d.processed,r(", changed"),d.changed]},void 0,!0)]},void 0,!0)},"MigrationsPanel");export{we as MigrationsPanel};