@lunora/studio 1.0.0-alpha.38 → 1.0.0-alpha.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -10
- package/dist/mount.js +1 -1
- package/dist/packem_chunks/ApiTab.js +3 -3
- package/dist/packem_chunks/AuditPanel.js +3 -3
- package/dist/packem_chunks/ExportImportPanel.js +2 -2
- package/dist/packem_chunks/FileBrowser.js +2 -2
- package/dist/packem_chunks/FunctionRunner.js +1 -1
- package/dist/packem_chunks/FunctionStatsPanel.js +3 -3
- package/dist/packem_chunks/HealthPanel.js +2 -2
- package/dist/packem_chunks/InsightsPanel.js +3 -3
- package/dist/packem_chunks/LogsPanel.js +2 -2
- package/dist/packem_chunks/MailPanel.js +3 -3
- package/dist/packem_chunks/MetricsPanel.js +2 -2
- package/dist/packem_chunks/MigrationsPanel.js +3 -3
- package/dist/packem_chunks/PitrPanel.js +1 -1
- package/dist/packem_chunks/SchemaViewer.js +1 -1
- package/dist/packem_chunks/SecurityAdvisorPanel.js +2 -2
- package/dist/packem_chunks/SettingsPanel.js +2 -2
- package/dist/packem_chunks/SqlEditorPanel.js +149 -139
- package/dist/packem_chunks/TableEditor.js +3 -3
- package/dist/packem_chunks/analytics-panel.js +1 -1
- package/dist/packem_chunks/auth-config-panel.js +1 -1
- package/dist/packem_chunks/auth-sessions-panel.js +2 -2
- package/dist/packem_chunks/containers-panel.js +1 -1
- package/dist/packem_chunks/dashboards-panel.js +2 -2
- package/dist/packem_chunks/fanout-panel.js +2 -2
- package/dist/packem_chunks/flags-panel.js +2 -2
- package/dist/packem_chunks/kv-browser.js +2 -2
- package/dist/packem_chunks/log-drains-panel.js +1 -1
- package/dist/packem_chunks/organizations-panel.js +3 -3
- package/dist/packem_chunks/payments-panel.js +3 -3
- package/dist/packem_chunks/permissions-panel.js +3 -3
- package/dist/packem_chunks/queues-panel.js +242 -219
- package/dist/packem_chunks/rls-panel.js +2 -2
- package/dist/packem_chunks/schedule-panel.js +3 -3
- package/dist/packem_chunks/storage-rules-panel.js +2 -2
- package/dist/packem_chunks/subscriptions-panel.js +2 -2
- package/dist/packem_chunks/users-panel.js +3 -3
- package/dist/packem_chunks/vector-browser.js +1 -1
- package/dist/packem_chunks/workflows-panel.js +2 -2
- package/dist/packem_shared/{ApiDocsPanel-D4CJf2ad.js → ApiDocsPanel-CBma-lnp.js} +1 -1
- package/dist/packem_shared/{ApiReferencePanel-Co_wpRF2.js → ApiReferencePanel-CQM3pPN7.js} +1 -1
- package/dist/packem_shared/{CommandPalette-BUPpbpMc.js → CommandPalette-X2tkbyHk.js} +1 -1
- package/dist/packem_shared/{DataBrowser-BeVNxSVm.js → DataBrowser-D2ywrdId.js} +5 -5
- package/dist/packem_shared/{GlobalDataBrowser-ErfvIs1S.js → GlobalDataBrowser-BkTPLzAY.js} +3 -3
- package/dist/packem_shared/{HomePanel-D9MQk8I7.js → HomePanel-D1Q9LZgK.js} +3 -3
- package/dist/packem_shared/{OpenRpcReferencePanel-DLWzrIx9.js → OpenRpcReferencePanel-Dno-hfDb.js} +1 -1
- package/dist/packem_shared/{ScheduledJobs-ClaNpZsg.js → ScheduledJobs-Ctw4jYtU.js} +2 -2
- package/dist/packem_shared/{Studio-C48P1K5W.js → Studio-lJhzDAze.js} +4 -4
- package/dist/packem_shared/{StudioApp-Cqh-SYm2.js → StudioApp-DiMkupvZ.js} +3 -12
- package/dist/packem_shared/{advisor-view-D3-U4kRR.js → advisor-view-BX8OhG0w.js} +1 -1
- package/dist/packem_shared/{browser-storage-tLOxkIHd.js → browser-storage-BTrX4y3B.js} +32 -2
- package/dist/packem_shared/{data-grid-Jz8FqQ2C.js → data-grid-CdXztApG.js} +1 -1
- package/dist/packem_shared/{error-alert-BBT6D22d.js → error-alert-CXjqyGw9.js} +1 -1
- package/dist/packem_shared/{grid-features-CUr8Z1_O.js → grid-features-BF-KBDFz.js} +128 -65
- package/dist/packem_shared/{home-panel-CoGxi-oj.js → home-panel-TFcRf9Ui.js} +272 -22
- package/dist/packem_shared/{internal-DTsYVn-g.js → internal-CYcbqMjX.js} +15 -3
- package/dist/packem_shared/{reference-view-CSKyUyPl.js → reference-view-DUiJcILV.js} +1 -1
- package/dist/packem_shared/{studio-CPHA_-3I.js → studio-Dh9UlaF_.js} +3 -3
- package/dist/packem_shared/{table-list-sidebar-B5psdSV1.js → table-list-sidebar-UVIXQJdU.js} +1 -1
- package/dist/packem_shared/{use-admin-query-BHPKmPuj.js → use-admin-query-CfHYWx5n.js} +1 -1
- package/dist/packem_shared/{use-async-submit-BWMDwRa4.js → use-async-submit-DJQiPc-_.js} +2 -2
- package/dist/standalone/{chunk-ZL4E2WVF.js → chunk-23C4TCRO.js} +1 -1
- package/dist/standalone/{chunk-NV6RHG5L.js → chunk-5ZAA2PVR.js} +1 -1
- package/dist/standalone/{chunk-Q3PTSVVU.js → chunk-676HEBIR.js} +1 -1
- package/dist/standalone/{chunk-Y2ZPNDL7.js → chunk-6VO23MMW.js} +1 -1
- package/dist/standalone/{chunk-2GFAOIC3.js → chunk-7RE5UW27.js} +1 -1
- package/dist/standalone/{chunk-4FL3EDN5.js → chunk-AAVIFQ4Y.js} +1 -1
- package/dist/standalone/{chunk-SE2TQAHJ.js → chunk-AJFQ3LNM.js} +1 -1
- package/dist/standalone/chunk-AJULNB46.js +4 -0
- package/dist/standalone/{chunk-6GFEVKJP.js → chunk-BGXOXASQ.js} +1 -1
- package/dist/standalone/{chunk-3DBG4RIV.js → chunk-BKW7FFEO.js} +1 -1
- package/dist/standalone/{chunk-OES45DFG.js → chunk-BXOYVWJR.js} +1 -1
- package/dist/standalone/{chunk-OIC7EJWI.js → chunk-C7WTJLC3.js} +1 -1
- package/dist/standalone/{chunk-AJIUI7DD.js → chunk-CACB34RQ.js} +1 -1
- package/dist/standalone/{chunk-TI7SE33D.js → chunk-CICVBMEN.js} +1 -1
- package/dist/standalone/{chunk-VFJPO4UO.js → chunk-CWEAJUHW.js} +1 -1
- package/dist/standalone/{chunk-FA3CCTXK.js → chunk-DECHEGIC.js} +1 -1
- package/dist/standalone/{chunk-PVZI3CXP.js → chunk-E75ANNWX.js} +7 -7
- package/dist/standalone/{chunk-MZ756AFF.js → chunk-ERJNDIXC.js} +1 -1
- package/dist/standalone/{chunk-I3VXCZZL.js → chunk-FKACHRWO.js} +1 -1
- package/dist/standalone/{chunk-X7RPB4K4.js → chunk-FSGCANAU.js} +1 -1
- package/dist/standalone/{chunk-34OQUHSV.js → chunk-H6RKXQZU.js} +1 -1
- package/dist/standalone/chunk-HZTGDL4L.js +1 -0
- package/dist/standalone/{chunk-FCSPAJW4.js → chunk-I7ZZRM7I.js} +1 -1
- package/dist/standalone/{chunk-OLE2AYTD.js → chunk-J46WXQYL.js} +1 -1
- package/dist/standalone/{chunk-2F4VYKM6.js → chunk-JVODY4EP.js} +1 -1
- package/dist/standalone/{chunk-IU6GTBPD.js → chunk-LYB5L53X.js} +1 -1
- package/dist/standalone/chunk-MJWVMKQ4.js +6 -0
- package/dist/standalone/chunk-MT2J3H7O.js +3 -0
- package/dist/standalone/{chunk-P5JW7HKP.js → chunk-N746FOQP.js} +1 -1
- package/dist/standalone/{chunk-P3ZMBPCY.js → chunk-NC6MBMSI.js} +1 -1
- package/dist/standalone/chunk-NN27EDQB.js +1 -0
- package/dist/standalone/{chunk-AJKR6PY7.js → chunk-NY6GDADQ.js} +1 -1
- package/dist/standalone/{chunk-R5OQZYSW.js → chunk-OY3HD7BJ.js} +1 -1
- package/dist/standalone/{chunk-4JOKDSPU.js → chunk-P5HJXCZS.js} +1 -1
- package/dist/standalone/{chunk-GM4NPF3W.js → chunk-PTS5TW3J.js} +1 -1
- package/dist/standalone/{chunk-IQ466Q6W.js → chunk-QDBOPDJ7.js} +1 -1
- package/dist/standalone/{chunk-KQTCLPLO.js → chunk-QHFTGJPS.js} +1 -1
- package/dist/standalone/{chunk-N7G5I47W.js → chunk-SSI4G2MY.js} +1 -1
- package/dist/standalone/{chunk-QKQABJBE.js → chunk-TH45YG6Q.js} +1 -1
- package/dist/standalone/{chunk-WXPWVBIY.js → chunk-UGUEC6BC.js} +1 -1
- package/dist/standalone/{chunk-K3GNLVYK.js → chunk-UKDJ4H7I.js} +1 -1
- package/dist/standalone/{chunk-O3I57FXK.js → chunk-V6IWFYAQ.js} +1 -1
- package/dist/standalone/{chunk-7FF76BYY.js → chunk-V7SRH36W.js} +1 -1
- package/dist/standalone/{chunk-XFSUINL3.js → chunk-WPNXY7IS.js} +1 -1
- package/dist/standalone/{chunk-PZ7HD5T2.js → chunk-X33MSJPP.js} +1 -1
- package/dist/standalone/{chunk-LEHGGJP2.js → chunk-XRNXOIVZ.js} +1 -1
- package/dist/standalone/{chunk-TDL7NEWA.js → chunk-YBGC4PPD.js} +1 -1
- package/dist/standalone/{chunk-HLZ4YLRK.js → chunk-YNZ7ARWW.js} +1 -1
- package/dist/standalone/{chunk-XGUOXHX4.js → chunk-YTO65GHS.js} +1 -1
- package/dist/standalone/{chunk-JTTVXBLU.js → chunk-ZE6FT5Z3.js} +1 -1
- package/dist/standalone/studio.js +31 -31
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- package/dist/standalone/chunk-2SAZ5BZ5.js +0 -4
- package/dist/standalone/chunk-2SE7II7A.js +0 -1
- package/dist/standalone/chunk-3UFZCRWL.js +0 -1
- package/dist/standalone/chunk-IJPFHUJK.js +0 -2
- package/dist/standalone/chunk-ZYRGPDZB.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as ee,b as te,c as se}from"./chunk-ZYRGPDZB.js";import"./chunk-DC72CQY4.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-KEGAWN6Y.js";import{a as X}from"./chunk-XNJNSCLM.js";import{c as I}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as J}from"./chunk-BOXSWNXZ.js";import{a as U}from"./chunk-TAD43CG5.js";import{a as z,b as V,c as P,e as D}from"./chunk-SEU5V7I6.js";import"./chunk-CKSHCYGC.js";import{f as Q}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as O,e as H,f as Y,g as G,k as Z}from"./chunk-PVZI3CXP.js";import"./chunk-GMSGZDDH.js";import{a as k,e as j,f as ie,g as le,h as oe}from"./chunk-RRCPZMC2.js";var W=j(le(),1),T=j(ie(),1);var o=j(oe(),1);var de=H(J.runSql),ae=k(($,e)=>{let s=Q(),[f,t]=(0,T.useState)(void 0),[i,d]=(0,T.useState)(void 0),[l,c]=(0,T.useState)(!0),q=(0,T.useCallback)(async a=>{c(!0);try{let x=await s.query(de,{sql:$},Y(e));a.cancelled||(t(x),d(void 0))}catch(x){a.cancelled||(t(void 0),d(G(x)))}finally{a.cancelled||c(!1)}},[s,$,e]);return(0,T.useEffect)(()=>{let a={cancelled:!1};return Z(q(a)),()=>{a.cancelled=!0}},[q]),{error:i,loading:l,result:f}},"useRunSql"),re="lunora-studio-dashboards",B={shardKey:"",sql:"",title:""},ne=k($=>{let e=(0,W.c)(54),{onEdit:s,onRemove:f,widget:t}=$,i=O(),{error:d,loading:l,result:c}=ae(t.sql,t.shardKey??""),q;e[0]!==s||e[1]!==t.id?(q=k(()=>{s(t.id)},"t1"),e[0]=s,e[1]=t.id,e[2]=q):q=e[2];let a=q,x;e[3]!==f||e[4]!==t.id?(x=k(()=>{f(t.id)},"t2"),e[3]=f,e[4]=t.id,e[5]=x):x=e[5];let K=x,M=`dashboards-widget-${t.id}`,S;e[6]!==t.title?(S=(0,o.jsxDEV)(P,{className:"min-w-0 truncate",title:t.title,children:t.title},void 0,!1),e[6]=t.title,e[7]=S):S=e[7];let L;e[8]!==i?(L=i("Edit widget"),e[8]=i,e[9]=L):L=e[9];let R=`dashboards-widget-edit-${t.id}`,A;e[10]!==i?(A=i("Edit widget"),e[10]=i,e[11]=A):A=e[11];let w;e[12]===Symbol.for("react.memo_cache_sentinel")?(w=(0,o.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,o.jsxDEV)("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"},void 0,!1)},void 0,!1),e[12]=w):w=e[12];let C;e[13]!==a||e[14]!==L||e[15]!==R||e[16]!==A?(C=(0,o.jsxDEV)(I,{"aria-label":L,"data-testid":R,onClick:a,size:"icon-xs",title:A,type:"button",variant:"ghost",children:w},void 0,!1),e[13]=a,e[14]=L,e[15]=R,e[16]=A,e[17]=C):C=e[17];let b;e[18]!==i?(b=i("Remove widget"),e[18]=i,e[19]=b):b=e[19];let E=`dashboards-widget-remove-${t.id}`,m;e[20]!==i?(m=i("Remove widget"),e[20]=i,e[21]=m):m=e[21];let p;e[22]===Symbol.for("react.memo_cache_sentinel")?(p=(0,o.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,o.jsxDEV)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"},void 0,!1)},void 0,!1),e[22]=p):p=e[22];let u;e[23]!==K||e[24]!==b||e[25]!==E||e[26]!==m?(u=(0,o.jsxDEV)(I,{"aria-label":b,"data-testid":E,onClick:K,size:"icon-xs",title:m,type:"button",variant:"ghost",children:p},void 0,!1),e[23]=K,e[24]=b,e[25]=E,e[26]=m,e[27]=u):u=e[27];let h;e[28]!==u||e[29]!==C?(h=(0,o.jsxDEV)("div",{className:"flex shrink-0 items-center gap-1",children:[C,u]},void 0,!0),e[28]=u,e[29]=C,e[30]=h):h=e[30];let v;e[31]!==h||e[32]!==S?(v=(0,o.jsxDEV)(V,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[S,h]},void 0,!0),e[31]=h,e[32]=S,e[33]=v):v=e[33];let g;e[34]!==d||e[35]!==t.id?(g=d!==void 0&&(0,o.jsxDEV)(X,{className:"font-mono text-xs",testId:`dashboards-widget-error-${t.id}`,variant:"destructive",children:d},void 0,!1),e[34]=d,e[35]=t.id,e[36]=g):g=e[36];let N;e[37]!==d||e[38]!==l||e[39]!==c||e[40]!==i||e[41]!==t.id?(N=d===void 0&&l&&c===void 0&&(0,o.jsxDEV)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${t.id}`,children:i("Running\u2026")},void 0,!1),e[37]=d,e[38]=l,e[39]=c,e[40]=i,e[41]=t.id,e[42]=N):N=e[42];let r;e[43]!==d||e[44]!==c?(r=d===void 0&&c!==void 0&&(0,o.jsxDEV)(ee,{result:c},void 0,!1),e[43]=d,e[44]=c,e[45]=r):r=e[45];let n;e[46]!==g||e[47]!==N||e[48]!==r?(n=(0,o.jsxDEV)(D,{className:"min-h-32 py-2",children:[g,N,r]},void 0,!0),e[46]=g,e[47]=N,e[48]=r,e[49]=n):n=e[49];let y;return e[50]!==v||e[51]!==n||e[52]!==M?(y=(0,o.jsxDEV)(z,{"data-testid":M,children:[v,n]},void 0,!0),e[50]=v,e[51]=n,e[52]=M,e[53]=y):y=e[53],y},"WidgetCard"),ce=k($=>{let e=(0,W.c)(58),{draft:s,editing:f,onCancel:t,onChange:i,onSubmit:d}=$,l=O(),c;e[0]!==s||e[1]!==i?(c=k(_=>{i({...s,title:_.target.value})},"t1"),e[0]=s,e[1]=i,e[2]=c):c=e[2];let q=c,a;e[3]!==s||e[4]!==i?(a=k(_=>{i({...s,sql:_.target.value})},"t2"),e[3]=s,e[4]=i,e[5]=a):a=e[5];let x=a,K;e[6]!==s||e[7]!==i?(K=k(_=>{i({...s,shardKey:_.target.value})},"t3"),e[6]=s,e[7]=i,e[8]=K):K=e[8];let M=K,S;e[9]!==d?(S=k(()=>{d()},"t4"),e[9]=d,e[10]=S):S=e[10];let L=S,R;e[11]!==s.sql||e[12]!==s.title?(R=s.title.trim()!==""&&s.sql.trim()!=="",e[11]=s.sql,e[12]=s.title,e[13]=R):R=e[13];let A=R,w;e[14]!==l?(w=l("Widget title"),e[14]=l,e[15]=w):w=e[15];let C;e[16]!==l?(C=l("Widget title"),e[16]=l,e[17]=C):C=e[17];let b;e[18]!==s.title||e[19]!==q||e[20]!==w||e[21]!==C?(b=(0,o.jsxDEV)("input",{"aria-label":w,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:q,placeholder:C,type:"text",value:s.title},void 0,!1),e[18]=s.title,e[19]=q,e[20]=w,e[21]=C,e[22]=b):b=e[22];let E;e[23]!==l?(E=l("SQL query"),e[23]=l,e[24]=E):E=e[24];let m;e[25]!==s.sql||e[26]!==x||e[27]!==E?(m=(0,o.jsxDEV)("textarea",{"aria-label":E,className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:x,placeholder:"SELECT author, COUNT(*) AS messages FROM \u2026",spellCheck:!1,value:s.sql},void 0,!1),e[25]=s.sql,e[26]=x,e[27]=E,e[28]=m):m=e[28];let p;e[29]!==l?(p=l("Shard key (optional)"),e[29]=l,e[30]=p):p=e[30];let u;e[31]!==l?(u=l("Shard key (optional)"),e[31]=l,e[32]=u):u=e[32];let h;e[33]!==s.shardKey||e[34]!==M||e[35]!==p||e[36]!==u?(h=(0,o.jsxDEV)("input",{"aria-label":p,className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:M,placeholder:u,type:"text",value:s.shardKey},void 0,!1),e[33]=s.shardKey,e[34]=M,e[35]=p,e[36]=u,e[37]=h):h=e[37];let v;e[38]!==l?(v=l("Cancel"),e[38]=l,e[39]=v):v=e[39];let g;e[40]!==t||e[41]!==v?(g=(0,o.jsxDEV)(I,{"data-testid":"dashboards-form-cancel",onClick:t,size:"sm",type:"button",variant:"outline",children:v},void 0,!1),e[40]=t,e[41]=v,e[42]=g):g=e[42];let N=!A,r;e[43]!==f||e[44]!==l?(r=l(f?"Save widget":"Add widget"),e[43]=f,e[44]=l,e[45]=r):r=e[45];let n;e[46]!==L||e[47]!==N||e[48]!==r?(n=(0,o.jsxDEV)(I,{"data-testid":"dashboards-form-save",disabled:N,onClick:L,size:"sm",type:"button",children:r},void 0,!1),e[46]=L,e[47]=N,e[48]=r,e[49]=n):n=e[49];let y;e[50]!==g||e[51]!==n?(y=(0,o.jsxDEV)("div",{className:"flex items-center justify-end gap-2",children:[g,n]},void 0,!0),e[50]=g,e[51]=n,e[52]=y):y=e[52];let F;return e[53]!==m||e[54]!==h||e[55]!==y||e[56]!==b?(F=(0,o.jsxDEV)(z,{"data-testid":"dashboards-form",children:(0,o.jsxDEV)(D,{className:"flex flex-col gap-3 py-4",children:[b,m,h,y]},void 0,!0)},void 0,!1),e[53]=m,e[54]=h,e[55]=y,e[56]=b,e[57]=F):F=e[57],F},"WidgetForm"),Ce=k($=>{let e=(0,W.c)(39),{initialShardKey:s}=$,f=O(),[t,i]=te(re),[d,l]=(0,T.useState)(B),[c,q]=(0,T.useState)(null),[a,x]=(0,T.useState)(!1),K;e[0]!==s?(K=k(()=>{q(null),l({...B,shardKey:s??""}),x(!0)},"t1"),e[0]=s,e[1]=K):K=e[1];let M=K,S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=k(()=>{x(!1),q(null),l(B)},"t2"),e[2]=S):S=e[2];let L=S,R;e[3]!==t?(R=k(r=>{let n=t.find(y=>y.id===r);n!==void 0&&(q(r),l({shardKey:n.shardKey??"",sql:n.sql,title:n.title}),x(!0))},"t3"),e[3]=t,e[4]=R):R=e[4];let A=R,w;e[5]!==i?(w=k(r=>{i(n=>n.filter(y=>y.id!==r))},"t4"),e[5]=i,e[6]=w):w=e[6];let C=w,b;e[7]!==d.shardKey||e[8]!==d.sql||e[9]!==d.title||e[10]!==c||e[11]!==i?(b=k(()=>{let r=d.title.trim(),n=d.sql.trim();if(r===""||n==="")return;let y=d.shardKey.trim();i(c===null?F=>[...F,{id:se("w"),shardKey:y,sql:n,title:r}]:F=>F.map(_=>_.id===c?{..._,shardKey:y,sql:n,title:r}:_)),L()},"t5"),e[7]=d.shardKey,e[8]=d.sql,e[9]=d.title,e[10]=c,e[11]=i,e[12]=b):b=e[12];let E=b,m;e[13]!==f?(m=f("Chart widgets backed by saved read-only SQL queries."),e[13]=f,e[14]=m):m=e[14];let p;e[15]!==m?(p=(0,o.jsxDEV)("p",{className:"text-sm text-muted-foreground",children:m},void 0,!1),e[15]=m,e[16]=p):p=e[16];let u;e[17]!==a||e[18]!==M||e[19]!==f?(u=!a&&(0,o.jsxDEV)(I,{"data-testid":"dashboards-add",onClick:M,size:"sm",type:"button",children:f("Add widget")},void 0,!1),e[17]=a,e[18]=M,e[19]=f,e[20]=u):u=e[20];let h;e[21]!==p||e[22]!==u?(h=(0,o.jsxDEV)("div",{className:"flex items-center justify-between",children:[p,u]},void 0,!0),e[21]=p,e[22]=u,e[23]=h):h=e[23];let v;e[24]!==d||e[25]!==c||e[26]!==a||e[27]!==E?(v=a&&(0,o.jsxDEV)(ce,{draft:d,editing:c!==null,onCancel:L,onChange:l,onSubmit:E},void 0,!1),e[24]=d,e[25]=c,e[26]=a,e[27]=E,e[28]=v):v=e[28];let g;e[29]!==a||e[30]!==A||e[31]!==C||e[32]!==f||e[33]!==t?(g=t.length===0&&!a?(0,o.jsxDEV)(U,{description:f("Add a widget to chart a saved SQL query on this browser."),testId:"dashboards-empty",title:f("No widgets yet")},void 0,!1):(0,o.jsxDEV)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:t.map(r=>(0,o.jsxDEV)(ne,{onEdit:A,onRemove:C,widget:r},r.id,!1))},void 0,!1),e[29]=a,e[30]=A,e[31]=C,e[32]=f,e[33]=t,e[34]=g):g=e[34];let N;return e[35]!==v||e[36]!==g||e[37]!==h?(N=(0,o.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[h,v,g]},void 0,!0),e[35]=v,e[36]=g,e[37]=h,e[38]=N):N=e[38],N},"DashboardsPanel");export{Ce as default};
|
|
1
|
+
import{a as ee,b as te,d as se}from"./chunk-NN27EDQB.js";import"./chunk-DC72CQY4.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-KEGAWN6Y.js";import{a as X}from"./chunk-XNJNSCLM.js";import{c as I}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as J}from"./chunk-BOXSWNXZ.js";import{a as U}from"./chunk-TAD43CG5.js";import{a as z,b as V,c as P,e as D}from"./chunk-SEU5V7I6.js";import"./chunk-CKSHCYGC.js";import{f as Q}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as O,e as H,f as Y,g as G,k as Z}from"./chunk-E75ANNWX.js";import"./chunk-GMSGZDDH.js";import{a as k,e as j,f as ie,g as le,h as oe}from"./chunk-RRCPZMC2.js";var W=j(le(),1),T=j(ie(),1);var o=j(oe(),1);var de=H(J.runSql),ae=k(($,e)=>{let s=Q(),[f,t]=(0,T.useState)(void 0),[i,d]=(0,T.useState)(void 0),[l,c]=(0,T.useState)(!0),q=(0,T.useCallback)(async a=>{c(!0);try{let x=await s.query(de,{sql:$},Y(e));a.cancelled||(t(x),d(void 0))}catch(x){a.cancelled||(t(void 0),d(G(x)))}finally{a.cancelled||c(!1)}},[s,$,e]);return(0,T.useEffect)(()=>{let a={cancelled:!1};return Z(q(a)),()=>{a.cancelled=!0}},[q]),{error:i,loading:l,result:f}},"useRunSql"),re="lunora-studio-dashboards",B={shardKey:"",sql:"",title:""},ne=k($=>{let e=(0,W.c)(54),{onEdit:s,onRemove:f,widget:t}=$,i=O(),{error:d,loading:l,result:c}=ae(t.sql,t.shardKey??""),q;e[0]!==s||e[1]!==t.id?(q=k(()=>{s(t.id)},"t1"),e[0]=s,e[1]=t.id,e[2]=q):q=e[2];let a=q,x;e[3]!==f||e[4]!==t.id?(x=k(()=>{f(t.id)},"t2"),e[3]=f,e[4]=t.id,e[5]=x):x=e[5];let K=x,M=`dashboards-widget-${t.id}`,S;e[6]!==t.title?(S=(0,o.jsxDEV)(P,{className:"min-w-0 truncate",title:t.title,children:t.title},void 0,!1),e[6]=t.title,e[7]=S):S=e[7];let L;e[8]!==i?(L=i("Edit widget"),e[8]=i,e[9]=L):L=e[9];let R=`dashboards-widget-edit-${t.id}`,A;e[10]!==i?(A=i("Edit widget"),e[10]=i,e[11]=A):A=e[11];let w;e[12]===Symbol.for("react.memo_cache_sentinel")?(w=(0,o.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,o.jsxDEV)("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"},void 0,!1)},void 0,!1),e[12]=w):w=e[12];let C;e[13]!==a||e[14]!==L||e[15]!==R||e[16]!==A?(C=(0,o.jsxDEV)(I,{"aria-label":L,"data-testid":R,onClick:a,size:"icon-xs",title:A,type:"button",variant:"ghost",children:w},void 0,!1),e[13]=a,e[14]=L,e[15]=R,e[16]=A,e[17]=C):C=e[17];let b;e[18]!==i?(b=i("Remove widget"),e[18]=i,e[19]=b):b=e[19];let E=`dashboards-widget-remove-${t.id}`,m;e[20]!==i?(m=i("Remove widget"),e[20]=i,e[21]=m):m=e[21];let p;e[22]===Symbol.for("react.memo_cache_sentinel")?(p=(0,o.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,o.jsxDEV)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"},void 0,!1)},void 0,!1),e[22]=p):p=e[22];let u;e[23]!==K||e[24]!==b||e[25]!==E||e[26]!==m?(u=(0,o.jsxDEV)(I,{"aria-label":b,"data-testid":E,onClick:K,size:"icon-xs",title:m,type:"button",variant:"ghost",children:p},void 0,!1),e[23]=K,e[24]=b,e[25]=E,e[26]=m,e[27]=u):u=e[27];let h;e[28]!==u||e[29]!==C?(h=(0,o.jsxDEV)("div",{className:"flex shrink-0 items-center gap-1",children:[C,u]},void 0,!0),e[28]=u,e[29]=C,e[30]=h):h=e[30];let v;e[31]!==h||e[32]!==S?(v=(0,o.jsxDEV)(V,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[S,h]},void 0,!0),e[31]=h,e[32]=S,e[33]=v):v=e[33];let g;e[34]!==d||e[35]!==t.id?(g=d!==void 0&&(0,o.jsxDEV)(X,{className:"font-mono text-xs",testId:`dashboards-widget-error-${t.id}`,variant:"destructive",children:d},void 0,!1),e[34]=d,e[35]=t.id,e[36]=g):g=e[36];let N;e[37]!==d||e[38]!==l||e[39]!==c||e[40]!==i||e[41]!==t.id?(N=d===void 0&&l&&c===void 0&&(0,o.jsxDEV)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${t.id}`,children:i("Running\u2026")},void 0,!1),e[37]=d,e[38]=l,e[39]=c,e[40]=i,e[41]=t.id,e[42]=N):N=e[42];let r;e[43]!==d||e[44]!==c?(r=d===void 0&&c!==void 0&&(0,o.jsxDEV)(ee,{result:c},void 0,!1),e[43]=d,e[44]=c,e[45]=r):r=e[45];let n;e[46]!==g||e[47]!==N||e[48]!==r?(n=(0,o.jsxDEV)(D,{className:"min-h-32 py-2",children:[g,N,r]},void 0,!0),e[46]=g,e[47]=N,e[48]=r,e[49]=n):n=e[49];let y;return e[50]!==v||e[51]!==n||e[52]!==M?(y=(0,o.jsxDEV)(z,{"data-testid":M,children:[v,n]},void 0,!0),e[50]=v,e[51]=n,e[52]=M,e[53]=y):y=e[53],y},"WidgetCard"),ce=k($=>{let e=(0,W.c)(58),{draft:s,editing:f,onCancel:t,onChange:i,onSubmit:d}=$,l=O(),c;e[0]!==s||e[1]!==i?(c=k(_=>{i({...s,title:_.target.value})},"t1"),e[0]=s,e[1]=i,e[2]=c):c=e[2];let q=c,a;e[3]!==s||e[4]!==i?(a=k(_=>{i({...s,sql:_.target.value})},"t2"),e[3]=s,e[4]=i,e[5]=a):a=e[5];let x=a,K;e[6]!==s||e[7]!==i?(K=k(_=>{i({...s,shardKey:_.target.value})},"t3"),e[6]=s,e[7]=i,e[8]=K):K=e[8];let M=K,S;e[9]!==d?(S=k(()=>{d()},"t4"),e[9]=d,e[10]=S):S=e[10];let L=S,R;e[11]!==s.sql||e[12]!==s.title?(R=s.title.trim()!==""&&s.sql.trim()!=="",e[11]=s.sql,e[12]=s.title,e[13]=R):R=e[13];let A=R,w;e[14]!==l?(w=l("Widget title"),e[14]=l,e[15]=w):w=e[15];let C;e[16]!==l?(C=l("Widget title"),e[16]=l,e[17]=C):C=e[17];let b;e[18]!==s.title||e[19]!==q||e[20]!==w||e[21]!==C?(b=(0,o.jsxDEV)("input",{"aria-label":w,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:q,placeholder:C,type:"text",value:s.title},void 0,!1),e[18]=s.title,e[19]=q,e[20]=w,e[21]=C,e[22]=b):b=e[22];let E;e[23]!==l?(E=l("SQL query"),e[23]=l,e[24]=E):E=e[24];let m;e[25]!==s.sql||e[26]!==x||e[27]!==E?(m=(0,o.jsxDEV)("textarea",{"aria-label":E,className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:x,placeholder:"SELECT author, COUNT(*) AS messages FROM \u2026",spellCheck:!1,value:s.sql},void 0,!1),e[25]=s.sql,e[26]=x,e[27]=E,e[28]=m):m=e[28];let p;e[29]!==l?(p=l("Shard key (optional)"),e[29]=l,e[30]=p):p=e[30];let u;e[31]!==l?(u=l("Shard key (optional)"),e[31]=l,e[32]=u):u=e[32];let h;e[33]!==s.shardKey||e[34]!==M||e[35]!==p||e[36]!==u?(h=(0,o.jsxDEV)("input",{"aria-label":p,className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:M,placeholder:u,type:"text",value:s.shardKey},void 0,!1),e[33]=s.shardKey,e[34]=M,e[35]=p,e[36]=u,e[37]=h):h=e[37];let v;e[38]!==l?(v=l("Cancel"),e[38]=l,e[39]=v):v=e[39];let g;e[40]!==t||e[41]!==v?(g=(0,o.jsxDEV)(I,{"data-testid":"dashboards-form-cancel",onClick:t,size:"sm",type:"button",variant:"outline",children:v},void 0,!1),e[40]=t,e[41]=v,e[42]=g):g=e[42];let N=!A,r;e[43]!==f||e[44]!==l?(r=l(f?"Save widget":"Add widget"),e[43]=f,e[44]=l,e[45]=r):r=e[45];let n;e[46]!==L||e[47]!==N||e[48]!==r?(n=(0,o.jsxDEV)(I,{"data-testid":"dashboards-form-save",disabled:N,onClick:L,size:"sm",type:"button",children:r},void 0,!1),e[46]=L,e[47]=N,e[48]=r,e[49]=n):n=e[49];let y;e[50]!==g||e[51]!==n?(y=(0,o.jsxDEV)("div",{className:"flex items-center justify-end gap-2",children:[g,n]},void 0,!0),e[50]=g,e[51]=n,e[52]=y):y=e[52];let F;return e[53]!==m||e[54]!==h||e[55]!==y||e[56]!==b?(F=(0,o.jsxDEV)(z,{"data-testid":"dashboards-form",children:(0,o.jsxDEV)(D,{className:"flex flex-col gap-3 py-4",children:[b,m,h,y]},void 0,!0)},void 0,!1),e[53]=m,e[54]=h,e[55]=y,e[56]=b,e[57]=F):F=e[57],F},"WidgetForm"),Ce=k($=>{let e=(0,W.c)(39),{initialShardKey:s}=$,f=O(),[t,i]=te(re),[d,l]=(0,T.useState)(B),[c,q]=(0,T.useState)(null),[a,x]=(0,T.useState)(!1),K;e[0]!==s?(K=k(()=>{q(null),l({...B,shardKey:s??""}),x(!0)},"t1"),e[0]=s,e[1]=K):K=e[1];let M=K,S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=k(()=>{x(!1),q(null),l(B)},"t2"),e[2]=S):S=e[2];let L=S,R;e[3]!==t?(R=k(r=>{let n=t.find(y=>y.id===r);n!==void 0&&(q(r),l({shardKey:n.shardKey??"",sql:n.sql,title:n.title}),x(!0))},"t3"),e[3]=t,e[4]=R):R=e[4];let A=R,w;e[5]!==i?(w=k(r=>{i(n=>n.filter(y=>y.id!==r))},"t4"),e[5]=i,e[6]=w):w=e[6];let C=w,b;e[7]!==d.shardKey||e[8]!==d.sql||e[9]!==d.title||e[10]!==c||e[11]!==i?(b=k(()=>{let r=d.title.trim(),n=d.sql.trim();if(r===""||n==="")return;let y=d.shardKey.trim();i(c===null?F=>[...F,{id:se("w"),shardKey:y,sql:n,title:r}]:F=>F.map(_=>_.id===c?{..._,shardKey:y,sql:n,title:r}:_)),L()},"t5"),e[7]=d.shardKey,e[8]=d.sql,e[9]=d.title,e[10]=c,e[11]=i,e[12]=b):b=e[12];let E=b,m;e[13]!==f?(m=f("Chart widgets backed by saved read-only SQL queries."),e[13]=f,e[14]=m):m=e[14];let p;e[15]!==m?(p=(0,o.jsxDEV)("p",{className:"text-sm text-muted-foreground",children:m},void 0,!1),e[15]=m,e[16]=p):p=e[16];let u;e[17]!==a||e[18]!==M||e[19]!==f?(u=!a&&(0,o.jsxDEV)(I,{"data-testid":"dashboards-add",onClick:M,size:"sm",type:"button",children:f("Add widget")},void 0,!1),e[17]=a,e[18]=M,e[19]=f,e[20]=u):u=e[20];let h;e[21]!==p||e[22]!==u?(h=(0,o.jsxDEV)("div",{className:"flex items-center justify-between",children:[p,u]},void 0,!0),e[21]=p,e[22]=u,e[23]=h):h=e[23];let v;e[24]!==d||e[25]!==c||e[26]!==a||e[27]!==E?(v=a&&(0,o.jsxDEV)(ce,{draft:d,editing:c!==null,onCancel:L,onChange:l,onSubmit:E},void 0,!1),e[24]=d,e[25]=c,e[26]=a,e[27]=E,e[28]=v):v=e[28];let g;e[29]!==a||e[30]!==A||e[31]!==C||e[32]!==f||e[33]!==t?(g=t.length===0&&!a?(0,o.jsxDEV)(U,{description:f("Add a widget to chart a saved SQL query on this browser."),testId:"dashboards-empty",title:f("No widgets yet")},void 0,!1):(0,o.jsxDEV)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:t.map(r=>(0,o.jsxDEV)(ne,{onEdit:A,onRemove:C,widget:r},r.id,!1))},void 0,!1),e[29]=a,e[30]=A,e[31]=C,e[32]=f,e[33]=t,e[34]=g):g=e[34];let N;return e[35]!==v||e[36]!==g||e[37]!==h?(N=(0,o.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[h,v,g]},void 0,!0),e[35]=v,e[36]=g,e[37]=h,e[38]=N):N=e[38],N},"DashboardsPanel");export{Ce as default};
|
|
@@ -0,0 +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:`
|
|
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
|
+
`)[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
|
+
`).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{d as N,j as x}from"./chunk-
|
|
1
|
+
import{d as N,j as x}from"./chunk-E75ANNWX.js";import{a as m,e as w,g as y,h as C}from"./chunk-RRCPZMC2.js";var v=w(y(),1);var o=w(C(),1);var T=m(b=>{let e=(0,v.c)(8),{value:l}=b;if(l==null){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=(0,o.jsxDEV)("span",{className:"text-muted-foreground/50 italic",children:"NULL"},void 0,!1),e[0]=a):a=e[0],a}let t;e[1]!==l?(t=x(l),e[1]=l,e[2]=t):t=e[2];let r;e[3]!==l?(r=x(l),e[3]=l,e[4]=r):r=e[4];let s;return e[5]!==t||e[6]!==r?(s=(0,o.jsxDEV)("span",{title:t,children:r},void 0,!1),e[5]=t,e[6]=r,e[7]=s):s=e[7],s},"CellValue"),G=m(b=>{let e=(0,v.c)(22),{columns:l,rows:t}=b,r=N(),s;e[0]!==r?(s=r("Field"),e[0]=r,e[1]=s):s=e[1];let a;e[2]!==s?(a=(0,o.jsxDEV)("th",{className:"border-b border-e border-border px-3 py-1.5 text-start font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:s},void 0,!1),e[2]=s,e[3]=a):a=e[3];let i;if(e[4]!==t||e[5]!==r){let d;e[7]!==r?(d=m((u,h)=>(0,o.jsxDEV)("th",{className:"border-b border-border px-3 py-1.5 text-start font-mono text-[11px] tracking-wide uppercase tabular-nums text-muted-foreground",children:r("Row {n}",{n:h+1})},h,!1),"t42"),e[7]=r,e[8]=d):d=e[8],i=t.map(d),e[4]=t,e[5]=r,e[6]=i}else i=e[6];let n;e[9]!==a||e[10]!==i?(n=(0,o.jsxDEV)("thead",{className:"sticky top-0 z-10 bg-muted",children:(0,o.jsxDEV)("tr",{children:[a,i]},void 0,!0)},void 0,!1),e[9]=a,e[10]=i,e[11]=n):n=e[11];let f;if(e[12]!==l||e[13]!==t){let d;e[15]!==t?(d=m(u=>(0,o.jsxDEV)("tr",{className:"hover:bg-muted/40",children:[(0,o.jsxDEV)("th",{className:"border-b border-e border-border px-3 py-1.5 text-start font-mono font-medium whitespace-nowrap",scope:"row",children:u},void 0,!1),t.map((h,g)=>(0,o.jsxDEV)("td",{className:"max-w-md truncate border-b border-border px-3 py-1.5 font-mono",children:(0,o.jsxDEV)(T,{value:h[u]},void 0,!1)},g,!1))]},u,!0),"t62"),e[15]=t,e[16]=d):d=e[16],f=l.map(d),e[12]=l,e[13]=t,e[14]=f}else f=e[14];let c;e[17]!==f?(c=(0,o.jsxDEV)("tbody",{children:f},void 0,!1),e[17]=f,e[18]=c):c=e[18];let p;return e[19]!==n||e[20]!==c?(p=(0,o.jsxDEV)("div",{className:"min-h-0 flex-1 overflow-auto","data-testid":"db-transposed",children:(0,o.jsxDEV)("table",{className:"border-collapse text-xs",children:[n,c]},void 0,!0)},void 0,!1),e[19]=n,e[20]=c,e[21]=p):p=e[21],p},"TransposedTable"),L=m(({children:b,layout:e="card",testId:l})=>(0,o.jsxDEV)("div",{className:e==="fill"?"flex min-h-0 flex-1 flex-col overflow-hidden border-t border-border":"overflow-x-auto border border-border bg-card","data-testid":l,children:b},void 0,!1),"GridContainer");export{T as a,G as b,L as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as de,e as j}from"./chunk-SG3ALJJU.js";import{a as ce}from"./chunk-WXPWVBIY.js";import"./chunk-DC72CQY4.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-KEGAWN6Y.js";import{a as ie}from"./chunk-TBMYIZIO.js";import"./chunk-HV7G6DFP.js";import{a as E}from"./chunk-BOXSWNXZ.js";import{b as ne}from"./chunk-OIC7EJWI.js";import{a as S}from"./chunk-SEU5V7I6.js";import{b as A}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as ae,g as le}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as D,e as T,f as H,g as Q,k as F,n as oe}from"./chunk-PVZI3CXP.js";import"./chunk-GMSGZDDH.js";import{a as h,e as k,f as ke,g as re,h as se,j as w}from"./chunk-RRCPZMC2.js";var ve=k(re(),1);var c=k(ke(),1);var ue=k(re(),1);var W=k(se(),1);var Ae={connected:"bg-success",connecting:"bg-warning",idle:"bg-muted-foreground",offline:"bg-destructive"},fe=h(()=>{let t=(0,ue.c)(16),e=D(),a=le(),s;e:switch(a){case"connected":{let n;t[0]!==e?(n=e("Connected"),t[0]=e,t[1]=n):n=t[1],s=n;break e}case"connecting":{let n;t[2]!==e?(n=e("Connecting\u2026"),t[2]=e,t[3]=n):n=t[3],s=n;break e}case"idle":{let n;t[4]!==e?(n=e("Idle"),t[4]=e,t[5]=n):n=t[5],s=n;break e}case"offline":{let n;t[6]!==e?(n=e("Offline"),t[6]=e,t[7]=n):n=t[7],s=n;break e}default:s=a}let l=Ae[a],d;t[8]!==l?(d=w("size-2 rounded-full",l),t[8]=l,t[9]=d):d=t[9];let u;t[10]!==d?(u=(0,W.jsxDEV)("span",{"aria-hidden":"true",className:d},void 0,!1),t[10]=d,t[11]=u):u=t[11];let i;return t[12]!==a||t[13]!==u||t[14]!==s?(i=(0,W.jsxDEV)("span",{"aria-live":"polite",className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground","data-status":a,"data-testid":"dash-connection",role:"status",children:[u,s]},void 0,!0),t[12]=a,t[13]=u,t[14]=s,t[15]=i):i=t[15],i},"ConnectionBadge");var r=k(se(),1);var me={completed:0,failed:2,in_progress:1},Re=h(t=>{let e=0,a=0,s=0,l=0,d=[];for(let{metrics:u}of t){if(u===null){l+=1;continue}s+=1,e+=u.requests,a+=u.errors,d.push(...u.history??[])}return{errors:a,failed:l,history:d,reachable:s,requests:e}},"sumShardMetrics"),Me=h(t=>{let e=new Map;for(let a of t)for(let s of a){let l=e.get(s.path);if(l===void 0){e.set(s.path,{...s});continue}l.calls+=s.calls,l.errors+=s.errors,l.totalDurationMs+=s.totalDurationMs,l.scans=(l.scans??0)+(s.scans??0),l.maxDurationMs=Math.max(l.maxDurationMs,s.maxDurationMs),l.lastCalledAt=Math.max(l.lastCalledAt,s.lastCalledAt),(s.lastErrorAt??0)>(l.lastErrorAt??0)&&(l.lastErrorAt=s.lastErrorAt,l.lastErrorMessage=s.lastErrorMessage)}return[...e.values()]},"mergeFunctionStats"),_e=h(t=>{let e=new Map;for(let a of t)for(let s of a){let l=e.get(s.id);if(l===void 0){e.set(s.id,s);continue}let d=me[s.status]-me[l.status];(d>0||d===0&&(s.updatedAt??0)>(l.updatedAt??0))&&e.set(s.id,s)}return[...e.values()]},"dedupeMigrations"),Ie=T(E.getAuthMetrics),Le=T(E.getFunctionStats),Ce=T(E.getLogs),Oe=T(E.getMetrics),qe=T(E.migrationStatus),De=5,he=2e3,Fe=5,pe=.01,ge=.05,je=.1,Ue=.3,Pe=1,Ge=50,X=h((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","rateLevel"),Ve=h((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","countLevel"),Be={crit:"destructive",ok:"secondary",warn:"default"},U=h((t,e)=>e===0?"\u2014":`${(t/e*100).toFixed(1)}%`,"ratePercent"),Ke=h(t=>{let e=new Map;for(let s of t??[]){let l=e.get(s.bucketMs)??{calls:0,errors:0};l.calls+=s.calls,l.errors+=s.errors,e.set(s.bucketMs,l)}let a=[...e.entries()].toSorted((s,l)=>s[0]-l[0]);return{errors:a.map(([,s])=>s.errors),requests:a.map(([,s])=>s.calls)}},"requestErrorSeries"),$e=h(t=>{let e=0,a=0;for(let l of t)l.status==="failed"?e+=1:l.status==="in_progress"&&(a+=1);let s="ok";return e>0?s="crit":a>0&&(s="warn"),{failed:e,level:s,running:a}},"migrationSummary"),ze=h((t,e)=>t.failed>0?e("{count} failed",{count:t.failed.toString()}):t.running>0?e("{count} running",{count:t.running.toString()}):e("OK"),"migrationTileValue"),xe={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},Ne={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},He={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Qe=h(t=>t.includes("crit")?"crit":t.includes("warn")?"warn":"ok","worstLevel"),P=h(t=>{let e=(0,ve.c)(19),{chart:a,label:s,level:l,testId:d,value:u}=t,i=xe[l],n;e[0]!==i?(n=w("size-1.5 shrink-0 rounded-full",i),e[0]=i,e[1]=n):n=e[1];let p;e[2]!==n?(p=(0,r.jsxDEV)("span",{"aria-hidden":"true",className:n},void 0,!1),e[2]=n,e[3]=p):p=e[3];let g;e[4]!==s||e[5]!==p?(g=(0,r.jsxDEV)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[p,s]},void 0,!0),e[4]=s,e[5]=p,e[6]=g):g=e[6];let b=Ne[l],m;e[7]!==b?(m=w("truncate text-2xl font-semibold tabular-nums",b),e[7]=b,e[8]=m):m=e[8];let f;e[9]!==m||e[10]!==d||e[11]!==u?(f=(0,r.jsxDEV)("span",{className:m,"data-testid":d,children:u},void 0,!1),e[9]=m,e[10]=d,e[11]=u,e[12]=f):f=e[12];let v;e[13]!==a||e[14]!==f?(v=(0,r.jsxDEV)("div",{className:"flex items-center justify-between gap-3",children:[f,a]},void 0,!0),e[13]=a,e[14]=f,e[15]=v):v=e[15];let x;return e[16]!==g||e[17]!==v?(x=(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:(0,r.jsxDEV)("div",{className:"flex flex-col gap-2.5 p-4",children:[g,v]},void 0,!0)},void 0,!1),e[16]=g,e[17]=v,e[18]=x):x=e[18],x},"SloCard"),We=h(async(t,e,a)=>{let s=await Promise.all(a.map(m=>{let f=H(m);return Promise.allSettled([t.query(Oe,{},f),t.query(Le,{},f),t.query(qe,{},f)])})),l=H(e),d=typeof t.schedulerStatus=="function"?t.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[u,i,n]=await Promise.allSettled([t.query(Ce,{},l),t.query(Ie,{},l),d]),p=s.map(([m,f,v])=>({functions:f.status==="fulfilled"?f.value.functions:[],metrics:m.status==="fulfilled"?m.value:null,migrations:v.status==="fulfilled"?v.value.migrations:[]})),g=Re(p),b=s[0]?.[0];return{auth:i.status==="fulfilled"?i.value:null,entries:u.status==="fulfilled"?u.value.entries:[],functions:Me(p.map(m=>m.functions)),logsError:u.status==="rejected"?Q(u.reason):null,metricsError:g.reachable===0&&b?.status==="rejected"?Q(b.reason):null,migrations:_e(p.map(m=>m.migrations)),scheduler:n.status==="fulfilled"?n.value:null,totals:g}},"loadSloData"),ht=h(({initialShardKey:t})=>{let e=ae(),a=D(),[s,l]=(0,c.useState)([]),[d,u]=(0,c.useState)(null),[i,n]=(0,c.useState)(null),[p,g]=(0,c.useState)(null),[b,m]=(0,c.useState)([]),[f,v]=(0,c.useState)(null),[x,be]=(0,c.useState)(null),[we,Ee]=(0,c.useState)([]),[y]=(0,c.useState)(ie),R=(0,c.useRef)(!1),G=(0,c.useRef)(!0);(0,c.useEffect)(()=>(G.current=!0,()=>{G.current=!1}),[]);let M=t??"",_=(0,c.useCallback)(async()=>{if(R.current)return;R.current=!0;let o=await We(e,M,de(M,y));if(!G.current){R.current=!1;return}n(o.totals),g(o.metricsError),m(o.functions),Ee(o.migrations),l(o.entries),u(o.logsError),v(o.auth),be(o.scheduler),R.current=!1},[e,y,M]);(0,c.useEffect)(()=>{F(_())},[_]);let V=(0,c.useRef)(0),I=(0,c.useRef)(null),Se=h(()=>{let o=Date.now()-V.current;if(o>=he){V.current=Date.now(),F(_());return}I.current??=setTimeout(()=>{I.current=null,V.current=Date.now(),F(_())},he-o)},"scheduleFanOut");(0,c.useEffect)(()=>()=>{I.current!==null&&clearTimeout(I.current)},[]);let{data:J,liveError:Te}=ne(E.getMetrics,{},{live:!0,shardKey:M});(0,c.useEffect)(()=>{J!==void 0&&Se()},[J]);let B=s.filter(o=>o.level==="error"),K=B.slice(0,De),L=Ke(i?.history),Y=(0,c.useMemo)(()=>{let o=f?.history??[];return{attempts:o.map(N=>N.attempts),failures:o.map(N=>N.failures)}},[f?.history]),Z=b.filter(o=>o.calls>0).toSorted((o,N)=>N.errors/N.calls-o.errors/o.calls||N.calls-o.calls).slice(0,Fe),$=$e(we),ye=i===null||i.requests===0?0:i.errors/i.requests,z=X(ye,pe,ge),ee=f===null?"ok":X(f.failureRate,je,Ue),te=x===null?"ok":Ve(x.backlog,Pe,Ge),C=Qe([z,ee,te,$.level]),O,q;return C==="crit"?(O=a("Critical"),q=a("One or more service levels are breached.")):C==="warn"?(O=a("Degraded"),q=a("Some service levels need attention.")):(O=a("All systems healthy"),q=a("All service levels are within target.")),(0,r.jsxDEV)("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[(0,r.jsxDEV)("div",{className:"flex items-center gap-3",children:[(0,r.jsxDEV)("span",{"aria-hidden":"true",className:w("flex size-10 shrink-0 items-center justify-center rounded-full",He[C]),children:(0,r.jsxDEV)("span",{className:w("size-3 rounded-full",xe[C])},void 0,!1)},void 0,!1),(0,r.jsxDEV)("div",{className:"grid leading-tight",children:[(0,r.jsxDEV)("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:O},void 0,!1),(0,r.jsxDEV)("span",{className:"text-[13px] text-muted-foreground",children:q},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,r.jsxDEV)("div",{className:"text-end",children:[(0,r.jsxDEV)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Requests")},void 0,!1),(0,r.jsxDEV)("div",{className:"flex items-center justify-end gap-2",children:[L.requests.length>=2&&(0,r.jsxDEV)(j,{ariaLabel:a("Requests over time"),className:"h-6 w-20 text-foreground",series:L.requests,testId:"hl-spark-requests"},void 0,!1),(0,r.jsxDEV)("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(i?.requests??0).toString()},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"},void 0,!1),(0,r.jsxDEV)("div",{className:"text-end",children:[(0,r.jsxDEV)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Error rate")},void 0,!1),(0,r.jsxDEV)("div",{className:w("text-lg font-semibold tabular-nums",Ne[z]),"data-testid":"hl-error-rate",children:i===null?"\u2014":U(i.errors,i.requests)},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"},void 0,!1),(0,r.jsxDEV)("div",{className:"flex items-center gap-2",children:[(0,r.jsxDEV)(fe,{},void 0,!1),(0,r.jsxDEV)(ce,{message:Te,prefix:"hl"},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0),p!==null&&(0,r.jsxDEV)("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-sm text-destructive","data-testid":"hl-metrics-error",role:"alert",children:p},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[(0,r.jsxDEV)(P,{chart:L.errors.length>=2?(0,r.jsxDEV)(j,{ariaLabel:a("Errors over time"),className:"h-7 w-20 text-destructive",series:L.errors,testId:"hl-spark-errors"},void 0,!1):void 0,label:a("Error rate"),level:z,testId:"hl-slo-errorrate",value:i===null?"\u2014":U(i.errors,i.requests)},void 0,!1),(0,r.jsxDEV)(P,{chart:Y.failures.length>=2?(0,r.jsxDEV)(j,{ariaLabel:a("Auth failures over time"),className:"h-7 w-20 text-destructive",series:Y.failures,testId:"hl-spark-auth"},void 0,!1):void 0,label:a("Auth failures"),level:ee,testId:"hl-slo-auth",value:f===null?"\u2014":U(f.failures,f.attempts)},void 0,!1),(0,r.jsxDEV)(P,{label:a("Scheduler backlog"),level:te,testId:"hl-slo-backlog",value:x===null?"\u2014":x.backlog.toString()},void 0,!1),(0,r.jsxDEV)(P,{label:a("Migrations"),level:$.level,testId:"hl-slo-migrations",value:ze($,a)},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{className:"grid gap-3 lg:grid-cols-2",children:[(0,r.jsxDEV)(S,{className:"gap-0 py-0","data-testid":"hl-functions",children:[(0,r.jsxDEV)("header",{className:"border-b border-border px-4 py-3",children:(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Functions by error rate")},void 0,!1)},void 0,!1),Z.length===0?(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:a("No function activity yet.")},void 0,!1):(0,r.jsxDEV)("ul",{className:"divide-y divide-border",children:Z.map(o=>(0,r.jsxDEV)("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[(0,r.jsxDEV)("span",{className:"truncate font-mono text-foreground",children:o.path},void 0,!1),(0,r.jsxDEV)("span",{className:"flex shrink-0 items-center gap-2",children:[(0,r.jsxDEV)("span",{className:"tabular-nums text-muted-foreground",children:a("{count} calls",{count:o.calls.toString()})},void 0,!1),(0,r.jsxDEV)(A,{variant:Be[X(o.errors/o.calls,pe,ge)],children:U(o.errors,o.calls)},void 0,!1)]},void 0,!0)]},o.path,!0))},void 0,!1)]},void 0,!0),(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Recent errors")},void 0,!1),(0,r.jsxDEV)(A,{"data-testid":"hl-error-count",variant:B.length>0?"destructive":"outline",children:B.length},void 0,!1)]},void 0,!0),d!==null&&(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:d},void 0,!1),d===null&&K.length===0&&(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:a("No recent errors.")},void 0,!1),K.length>0&&(0,r.jsxDEV)("ul",{className:"divide-y divide-border",children:K.map((o,N)=>(0,r.jsxDEV)("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[(0,r.jsxDEV)("span",{className:"flex items-center gap-2",children:[(0,r.jsxDEV)("time",{className:"shrink-0 text-muted-foreground",children:oe(o.timestamp)},void 0,!1),o.functionPath!==void 0&&(0,r.jsxDEV)("span",{className:"truncate font-mono text-foreground",children:o.functionPath},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("span",{className:"text-destructive",children:o.message},void 0,!1)]},`${o.timestamp.toString()}-${N.toString()}`,!0))},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Shards seen")},void 0,!1),(0,r.jsxDEV)(A,{"data-testid":"hl-shard-count",variant:"outline",children:y.length},void 0,!1)]},void 0,!0),y.length>0&&(0,r.jsxDEV)("ul",{className:"flex flex-wrap gap-1.5 p-4",children:y.map(o=>(0,r.jsxDEV)("li",{"data-testid":"hl-shard",children:(0,r.jsxDEV)(A,{variant:"secondary",children:o},void 0,!1)},o,!1))},void 0,!1)]},void 0,!0)]},void 0,!0)},"HealthPanel");export{ht as HealthPanel};
|
|
1
|
+
import{b as de,e as j}from"./chunk-SG3ALJJU.js";import{a as ce}from"./chunk-UGUEC6BC.js";import"./chunk-DC72CQY4.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-KEGAWN6Y.js";import{a as ie}from"./chunk-TBMYIZIO.js";import"./chunk-HV7G6DFP.js";import{a as E}from"./chunk-BOXSWNXZ.js";import{b as ne}from"./chunk-C7WTJLC3.js";import{a as S}from"./chunk-SEU5V7I6.js";import{b as A}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as ae,g as le}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as D,e as T,f as H,g as Q,k as F,o as oe}from"./chunk-E75ANNWX.js";import"./chunk-GMSGZDDH.js";import{a as h,e as k,f as ke,g as re,h as se,j as w}from"./chunk-RRCPZMC2.js";var ve=k(re(),1);var c=k(ke(),1);var ue=k(re(),1);var W=k(se(),1);var Ae={connected:"bg-success",connecting:"bg-warning",idle:"bg-muted-foreground",offline:"bg-destructive"},fe=h(()=>{let t=(0,ue.c)(16),e=D(),a=le(),s;e:switch(a){case"connected":{let n;t[0]!==e?(n=e("Connected"),t[0]=e,t[1]=n):n=t[1],s=n;break e}case"connecting":{let n;t[2]!==e?(n=e("Connecting\u2026"),t[2]=e,t[3]=n):n=t[3],s=n;break e}case"idle":{let n;t[4]!==e?(n=e("Idle"),t[4]=e,t[5]=n):n=t[5],s=n;break e}case"offline":{let n;t[6]!==e?(n=e("Offline"),t[6]=e,t[7]=n):n=t[7],s=n;break e}default:s=a}let l=Ae[a],d;t[8]!==l?(d=w("size-2 rounded-full",l),t[8]=l,t[9]=d):d=t[9];let u;t[10]!==d?(u=(0,W.jsxDEV)("span",{"aria-hidden":"true",className:d},void 0,!1),t[10]=d,t[11]=u):u=t[11];let i;return t[12]!==a||t[13]!==u||t[14]!==s?(i=(0,W.jsxDEV)("span",{"aria-live":"polite",className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground","data-status":a,"data-testid":"dash-connection",role:"status",children:[u,s]},void 0,!0),t[12]=a,t[13]=u,t[14]=s,t[15]=i):i=t[15],i},"ConnectionBadge");var r=k(se(),1);var me={completed:0,failed:2,in_progress:1},Re=h(t=>{let e=0,a=0,s=0,l=0,d=[];for(let{metrics:u}of t){if(u===null){l+=1;continue}s+=1,e+=u.requests,a+=u.errors,d.push(...u.history??[])}return{errors:a,failed:l,history:d,reachable:s,requests:e}},"sumShardMetrics"),Me=h(t=>{let e=new Map;for(let a of t)for(let s of a){let l=e.get(s.path);if(l===void 0){e.set(s.path,{...s});continue}l.calls+=s.calls,l.errors+=s.errors,l.totalDurationMs+=s.totalDurationMs,l.scans=(l.scans??0)+(s.scans??0),l.maxDurationMs=Math.max(l.maxDurationMs,s.maxDurationMs),l.lastCalledAt=Math.max(l.lastCalledAt,s.lastCalledAt),(s.lastErrorAt??0)>(l.lastErrorAt??0)&&(l.lastErrorAt=s.lastErrorAt,l.lastErrorMessage=s.lastErrorMessage)}return[...e.values()]},"mergeFunctionStats"),_e=h(t=>{let e=new Map;for(let a of t)for(let s of a){let l=e.get(s.id);if(l===void 0){e.set(s.id,s);continue}let d=me[s.status]-me[l.status];(d>0||d===0&&(s.updatedAt??0)>(l.updatedAt??0))&&e.set(s.id,s)}return[...e.values()]},"dedupeMigrations"),Ie=T(E.getAuthMetrics),Le=T(E.getFunctionStats),Ce=T(E.getLogs),Oe=T(E.getMetrics),qe=T(E.migrationStatus),De=5,he=2e3,Fe=5,pe=.01,ge=.05,je=.1,Ue=.3,Pe=1,Ge=50,X=h((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","rateLevel"),Ve=h((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","countLevel"),Be={crit:"destructive",ok:"secondary",warn:"default"},U=h((t,e)=>e===0?"\u2014":`${(t/e*100).toFixed(1)}%`,"ratePercent"),Ke=h(t=>{let e=new Map;for(let s of t??[]){let l=e.get(s.bucketMs)??{calls:0,errors:0};l.calls+=s.calls,l.errors+=s.errors,e.set(s.bucketMs,l)}let a=[...e.entries()].toSorted((s,l)=>s[0]-l[0]);return{errors:a.map(([,s])=>s.errors),requests:a.map(([,s])=>s.calls)}},"requestErrorSeries"),$e=h(t=>{let e=0,a=0;for(let l of t)l.status==="failed"?e+=1:l.status==="in_progress"&&(a+=1);let s="ok";return e>0?s="crit":a>0&&(s="warn"),{failed:e,level:s,running:a}},"migrationSummary"),ze=h((t,e)=>t.failed>0?e("{count} failed",{count:t.failed.toString()}):t.running>0?e("{count} running",{count:t.running.toString()}):e("OK"),"migrationTileValue"),xe={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},Ne={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},He={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Qe=h(t=>t.includes("crit")?"crit":t.includes("warn")?"warn":"ok","worstLevel"),P=h(t=>{let e=(0,ve.c)(19),{chart:a,label:s,level:l,testId:d,value:u}=t,i=xe[l],n;e[0]!==i?(n=w("size-1.5 shrink-0 rounded-full",i),e[0]=i,e[1]=n):n=e[1];let p;e[2]!==n?(p=(0,r.jsxDEV)("span",{"aria-hidden":"true",className:n},void 0,!1),e[2]=n,e[3]=p):p=e[3];let g;e[4]!==s||e[5]!==p?(g=(0,r.jsxDEV)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[p,s]},void 0,!0),e[4]=s,e[5]=p,e[6]=g):g=e[6];let b=Ne[l],m;e[7]!==b?(m=w("truncate text-2xl font-semibold tabular-nums",b),e[7]=b,e[8]=m):m=e[8];let f;e[9]!==m||e[10]!==d||e[11]!==u?(f=(0,r.jsxDEV)("span",{className:m,"data-testid":d,children:u},void 0,!1),e[9]=m,e[10]=d,e[11]=u,e[12]=f):f=e[12];let v;e[13]!==a||e[14]!==f?(v=(0,r.jsxDEV)("div",{className:"flex items-center justify-between gap-3",children:[f,a]},void 0,!0),e[13]=a,e[14]=f,e[15]=v):v=e[15];let x;return e[16]!==g||e[17]!==v?(x=(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:(0,r.jsxDEV)("div",{className:"flex flex-col gap-2.5 p-4",children:[g,v]},void 0,!0)},void 0,!1),e[16]=g,e[17]=v,e[18]=x):x=e[18],x},"SloCard"),We=h(async(t,e,a)=>{let s=await Promise.all(a.map(m=>{let f=H(m);return Promise.allSettled([t.query(Oe,{},f),t.query(Le,{},f),t.query(qe,{},f)])})),l=H(e),d=typeof t.schedulerStatus=="function"?t.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[u,i,n]=await Promise.allSettled([t.query(Ce,{},l),t.query(Ie,{},l),d]),p=s.map(([m,f,v])=>({functions:f.status==="fulfilled"?f.value.functions:[],metrics:m.status==="fulfilled"?m.value:null,migrations:v.status==="fulfilled"?v.value.migrations:[]})),g=Re(p),b=s[0]?.[0];return{auth:i.status==="fulfilled"?i.value:null,entries:u.status==="fulfilled"?u.value.entries:[],functions:Me(p.map(m=>m.functions)),logsError:u.status==="rejected"?Q(u.reason):null,metricsError:g.reachable===0&&b?.status==="rejected"?Q(b.reason):null,migrations:_e(p.map(m=>m.migrations)),scheduler:n.status==="fulfilled"?n.value:null,totals:g}},"loadSloData"),ht=h(({initialShardKey:t})=>{let e=ae(),a=D(),[s,l]=(0,c.useState)([]),[d,u]=(0,c.useState)(null),[i,n]=(0,c.useState)(null),[p,g]=(0,c.useState)(null),[b,m]=(0,c.useState)([]),[f,v]=(0,c.useState)(null),[x,be]=(0,c.useState)(null),[we,Ee]=(0,c.useState)([]),[y]=(0,c.useState)(ie),R=(0,c.useRef)(!1),G=(0,c.useRef)(!0);(0,c.useEffect)(()=>(G.current=!0,()=>{G.current=!1}),[]);let M=t??"",_=(0,c.useCallback)(async()=>{if(R.current)return;R.current=!0;let o=await We(e,M,de(M,y));if(!G.current){R.current=!1;return}n(o.totals),g(o.metricsError),m(o.functions),Ee(o.migrations),l(o.entries),u(o.logsError),v(o.auth),be(o.scheduler),R.current=!1},[e,y,M]);(0,c.useEffect)(()=>{F(_())},[_]);let V=(0,c.useRef)(0),I=(0,c.useRef)(null),Se=h(()=>{let o=Date.now()-V.current;if(o>=he){V.current=Date.now(),F(_());return}I.current??=setTimeout(()=>{I.current=null,V.current=Date.now(),F(_())},he-o)},"scheduleFanOut");(0,c.useEffect)(()=>()=>{I.current!==null&&clearTimeout(I.current)},[]);let{data:J,liveError:Te}=ne(E.getMetrics,{},{live:!0,shardKey:M});(0,c.useEffect)(()=>{J!==void 0&&Se()},[J]);let B=s.filter(o=>o.level==="error"),K=B.slice(0,De),L=Ke(i?.history),Y=(0,c.useMemo)(()=>{let o=f?.history??[];return{attempts:o.map(N=>N.attempts),failures:o.map(N=>N.failures)}},[f?.history]),Z=b.filter(o=>o.calls>0).toSorted((o,N)=>N.errors/N.calls-o.errors/o.calls||N.calls-o.calls).slice(0,Fe),$=$e(we),ye=i===null||i.requests===0?0:i.errors/i.requests,z=X(ye,pe,ge),ee=f===null?"ok":X(f.failureRate,je,Ue),te=x===null?"ok":Ve(x.backlog,Pe,Ge),C=Qe([z,ee,te,$.level]),O,q;return C==="crit"?(O=a("Critical"),q=a("One or more service levels are breached.")):C==="warn"?(O=a("Degraded"),q=a("Some service levels need attention.")):(O=a("All systems healthy"),q=a("All service levels are within target.")),(0,r.jsxDEV)("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[(0,r.jsxDEV)("div",{className:"flex items-center gap-3",children:[(0,r.jsxDEV)("span",{"aria-hidden":"true",className:w("flex size-10 shrink-0 items-center justify-center rounded-full",He[C]),children:(0,r.jsxDEV)("span",{className:w("size-3 rounded-full",xe[C])},void 0,!1)},void 0,!1),(0,r.jsxDEV)("div",{className:"grid leading-tight",children:[(0,r.jsxDEV)("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:O},void 0,!1),(0,r.jsxDEV)("span",{className:"text-[13px] text-muted-foreground",children:q},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,r.jsxDEV)("div",{className:"text-end",children:[(0,r.jsxDEV)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Requests")},void 0,!1),(0,r.jsxDEV)("div",{className:"flex items-center justify-end gap-2",children:[L.requests.length>=2&&(0,r.jsxDEV)(j,{ariaLabel:a("Requests over time"),className:"h-6 w-20 text-foreground",series:L.requests,testId:"hl-spark-requests"},void 0,!1),(0,r.jsxDEV)("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(i?.requests??0).toString()},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"},void 0,!1),(0,r.jsxDEV)("div",{className:"text-end",children:[(0,r.jsxDEV)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Error rate")},void 0,!1),(0,r.jsxDEV)("div",{className:w("text-lg font-semibold tabular-nums",Ne[z]),"data-testid":"hl-error-rate",children:i===null?"\u2014":U(i.errors,i.requests)},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"},void 0,!1),(0,r.jsxDEV)("div",{className:"flex items-center gap-2",children:[(0,r.jsxDEV)(fe,{},void 0,!1),(0,r.jsxDEV)(ce,{message:Te,prefix:"hl"},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0),p!==null&&(0,r.jsxDEV)("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-sm text-destructive","data-testid":"hl-metrics-error",role:"alert",children:p},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[(0,r.jsxDEV)(P,{chart:L.errors.length>=2?(0,r.jsxDEV)(j,{ariaLabel:a("Errors over time"),className:"h-7 w-20 text-destructive",series:L.errors,testId:"hl-spark-errors"},void 0,!1):void 0,label:a("Error rate"),level:z,testId:"hl-slo-errorrate",value:i===null?"\u2014":U(i.errors,i.requests)},void 0,!1),(0,r.jsxDEV)(P,{chart:Y.failures.length>=2?(0,r.jsxDEV)(j,{ariaLabel:a("Auth failures over time"),className:"h-7 w-20 text-destructive",series:Y.failures,testId:"hl-spark-auth"},void 0,!1):void 0,label:a("Auth failures"),level:ee,testId:"hl-slo-auth",value:f===null?"\u2014":U(f.failures,f.attempts)},void 0,!1),(0,r.jsxDEV)(P,{label:a("Scheduler backlog"),level:te,testId:"hl-slo-backlog",value:x===null?"\u2014":x.backlog.toString()},void 0,!1),(0,r.jsxDEV)(P,{label:a("Migrations"),level:$.level,testId:"hl-slo-migrations",value:ze($,a)},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{className:"grid gap-3 lg:grid-cols-2",children:[(0,r.jsxDEV)(S,{className:"gap-0 py-0","data-testid":"hl-functions",children:[(0,r.jsxDEV)("header",{className:"border-b border-border px-4 py-3",children:(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Functions by error rate")},void 0,!1)},void 0,!1),Z.length===0?(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:a("No function activity yet.")},void 0,!1):(0,r.jsxDEV)("ul",{className:"divide-y divide-border",children:Z.map(o=>(0,r.jsxDEV)("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[(0,r.jsxDEV)("span",{className:"truncate font-mono text-foreground",children:o.path},void 0,!1),(0,r.jsxDEV)("span",{className:"flex shrink-0 items-center gap-2",children:[(0,r.jsxDEV)("span",{className:"tabular-nums text-muted-foreground",children:a("{count} calls",{count:o.calls.toString()})},void 0,!1),(0,r.jsxDEV)(A,{variant:Be[X(o.errors/o.calls,pe,ge)],children:U(o.errors,o.calls)},void 0,!1)]},void 0,!0)]},o.path,!0))},void 0,!1)]},void 0,!0),(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Recent errors")},void 0,!1),(0,r.jsxDEV)(A,{"data-testid":"hl-error-count",variant:B.length>0?"destructive":"outline",children:B.length},void 0,!1)]},void 0,!0),d!==null&&(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:d},void 0,!1),d===null&&K.length===0&&(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:a("No recent errors.")},void 0,!1),K.length>0&&(0,r.jsxDEV)("ul",{className:"divide-y divide-border",children:K.map((o,N)=>(0,r.jsxDEV)("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[(0,r.jsxDEV)("span",{className:"flex items-center gap-2",children:[(0,r.jsxDEV)("time",{className:"shrink-0 text-muted-foreground",children:oe(o.timestamp)},void 0,!1),o.functionPath!==void 0&&(0,r.jsxDEV)("span",{className:"truncate font-mono text-foreground",children:o.functionPath},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("span",{className:"text-destructive",children:o.message},void 0,!1)]},`${o.timestamp.toString()}-${N.toString()}`,!0))},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Shards seen")},void 0,!1),(0,r.jsxDEV)(A,{"data-testid":"hl-shard-count",variant:"outline",children:y.length},void 0,!1)]},void 0,!0),y.length>0&&(0,r.jsxDEV)("ul",{className:"flex flex-wrap gap-1.5 p-4",children:y.map(o=>(0,r.jsxDEV)("li",{"data-testid":"hl-shard",children:(0,r.jsxDEV)(A,{variant:"secondary",children:o},void 0,!1)},o,!1))},void 0,!1)]},void 0,!0)]},void 0,!0)},"HealthPanel");export{ht as HealthPanel};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as Ae}from"./chunk-VLXV72QE.js";import{a as xe}from"./chunk-JSEXCW5Q.js";import{a as X}from"./chunk-KZ6INM5M.js";import{d as we,f as Oe,g as $e,k as ae}from"./chunk-4QHKBC77.js";import{a as Ce}from"./chunk-
|
|
1
|
+
import{a as Ae}from"./chunk-VLXV72QE.js";import{a as xe}from"./chunk-JSEXCW5Q.js";import{a as X}from"./chunk-KZ6INM5M.js";import{d as we,f as Oe,g as $e,k as ae}from"./chunk-4QHKBC77.js";import{a as Ce}from"./chunk-UKDJ4H7I.js";import"./chunk-TBMYIZIO.js";import{R as ke}from"./chunk-3CJW6NWG.js";import{c as H}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as Te}from"./chunk-BOXSWNXZ.js";import{a as W}from"./chunk-TAD43CG5.js";import{b as Se}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as G}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as M,e as le,f as de,g as ce,k as Ie,m as re}from"./chunk-E75ANNWX.js";import{b as Ne}from"./chunk-GMSGZDDH.js";import{a as p,e as q,f as he,g as oe,h as ne,j as ge}from"./chunk-RRCPZMC2.js";var Ue=q(oe(),1),ye=q(he(),1);var ee=q(oe(),1);var Z=q(he(),1);var B=q(ne(),1);var Ye=le(Te.listTables),Qe=["react","client","cli"],Xe=!1,Ze={action:"action",mutation:"mutation",query:"query"},Pe=p(t=>{let e=t.indexOf(":");return e===-1?{file:"",fn:t}:{file:t.slice(0,e),fn:t.slice(e+1)}},"splitPath"),Ee=p(({file:t,fn:e,kind:o})=>`await client.${Ze[o]}(api.${t}.${e}, { /* args */ });`,"buildClientSnippet"),et=p(t=>{let e=`api.${t.file}.${t.fn}`;switch(t.kind){case"action":return Ee(t);case"mutation":return`const ${t.fn} = useMutation(${e});`;default:return`const data = useQuery(${e}, { /* args */ });`}},"buildReactSnippet"),tt=p(({file:t,fn:e})=>`lunora run ${t}:${e} --args '{ }'`,"buildCliSnippet"),st=p(t=>["// Read rows",`const rows = await ctx.db.query("${t}").collect();`,"","// Insert a row",`const id = await ctx.db.insert("${t}", { /* fields */ });`,"","// Generated types",`type Row = Doc<"${t}">;`,`type RowId = Id<"${t}">;`].join(`
|
|
2
2
|
`),"buildTableSnippet"),ot=p((t,e)=>{switch(t){case"cli":return tt(e);case"client":return Ee(e);default:return et(e)}},"snippetForTab"),_e=p(t=>{let e=(0,ee.c)(19),{code:o,label:s,testId:n}=t,r=M(),l;e[0]!==o?(l=p(()=>{re(o)},"t1"),e[0]=o,e[1]=l):l=e[1];let i=l,d;e[2]!==s?(d=(0,B.jsxDEV)("span",{className:"text-xs font-medium text-muted-foreground",children:s},void 0,!1),e[2]=s,e[3]=d):d=e[3];let c=`${n}-copy`,m;e[4]!==r?(m=r("Copy"),e[4]=r,e[5]=m):m=e[5];let a;e[6]!==i||e[7]!==c||e[8]!==m?(a=(0,B.jsxDEV)(H,{"data-testid":c,onClick:i,size:"xs",type:"button",variant:"ghost",children:m},void 0,!1),e[6]=i,e[7]=c,e[8]=m,e[9]=a):a=e[9];let u;e[10]!==d||e[11]!==a?(u=(0,B.jsxDEV)("div",{className:"flex items-center justify-between gap-2",children:[d,a]},void 0,!0),e[10]=d,e[11]=a,e[12]=u):u=e[12];let v;e[13]!==o||e[14]!==n?(v=(0,B.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":n,children:o},void 0,!1),e[13]=o,e[14]=n,e[15]=v):v=e[15];let k;return e[16]!==u||e[17]!==v?(k=(0,B.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[u,v]},void 0,!0),e[16]=u,e[17]=v,e[18]=k):k=e[18],k},"SnippetBlock"),nt=p(t=>{let e=(0,ee.c)(50),{file:o,fn:s,kind:n}=t,r=M(),[l,i]=(0,Z.useState)("react"),d,c,m;if(e[0]!==o||e[1]!==s||e[2]!==n||e[3]!==r||e[4]!==l){let T={file:o,fn:s,kind:n},I;e[8]!==r?(I=r("CLI"),e[8]=r,e[9]=I):I=e[9];let P;e[10]!==r?(P=r("Client"),e[10]=r,e[11]=P):P=e[11];let E;e[12]!==r?(E=r("React"),e[12]=r,e[13]=E):E=e[13];let j;e[14]!==I||e[15]!==P||e[16]!==E?(j={cli:I,client:P,react:E},e[14]=I,e[15]=P,e[16]=E,e[17]=j):j=e[17],m=j;let R;e[18]===Symbol.for("react.memo_cache_sentinel")?(R=p(L=>{i(L.currentTarget.dataset.tab)},"t62"),e[18]=R):R=e[18],d=R,c=ot(l,T),e[0]=o,e[1]=s,e[2]=n,e[3]=r,e[4]=l,e[5]=d,e[6]=c,e[7]=m}else d=e[5],c=e[6],m=e[7];let a=c,u=n==="action"&&l==="react"&&!Xe,v=`api.${o}.${s}`,k;e[19]!==v?(k=(0,B.jsxDEV)("h2",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"api-fn-title",children:v},void 0,!1),e[19]=v,e[20]=k):k=e[20];let O;e[21]!==n||e[22]!==r?(O=r("Call this {kind} from your app.",{kind:n}),e[21]=n,e[22]=r,e[23]=O):O=e[23];let h;e[24]!==O?(h=(0,B.jsxDEV)("p",{className:"text-xs text-muted-foreground",children:O},void 0,!1),e[24]=O,e[25]=h):h=e[25];let g;e[26]!==k||e[27]!==h?(g=(0,B.jsxDEV)("div",{children:[k,h]},void 0,!0),e[26]=k,e[27]=h,e[28]=g):g=e[28];let x;e[29]!==r?(x=r("Snippet flavour"),e[29]=r,e[30]=x):x=e[30];let b;e[31]!==d||e[32]!==l||e[33]!==m?(b=Qe.map(T=>(0,B.jsxDEV)(H,{"aria-selected":l===T,"data-tab":T,"data-testid":`api-tab-${T}`,onClick:d,role:"tab",size:"xs",type:"button",variant:l===T?"default":"outline",children:m[T]},T,!1)),e[31]=d,e[32]=l,e[33]=m,e[34]=b):b=e[34];let S;e[35]!==x||e[36]!==b?(S=(0,B.jsxDEV)("div",{"aria-label":x,className:"flex gap-1.5","data-testid":"api-tabs",role:"tablist",children:b},void 0,!1),e[35]=x,e[36]=b,e[37]=S):S=e[37];let y=m[l],$=`api-snippet-${l}`,N;e[38]!==a||e[39]!==y||e[40]!==$?(N=(0,B.jsxDEV)(_e,{code:a,label:y,testId:$},void 0,!1),e[38]=a,e[39]=y,e[40]=$,e[41]=N):N=e[41];let w;e[42]!==u||e[43]!==r?(w=u&&(0,B.jsxDEV)("p",{className:"text-xs text-muted-foreground","data-testid":"api-action-note",children:r("Actions have no React hook \u2014 call them through the client.")},void 0,!1),e[42]=u,e[43]=r,e[44]=w):w=e[44];let C;return e[45]!==N||e[46]!==w||e[47]!==g||e[48]!==S?(C=(0,B.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"api-fn-doc",children:[g,S,N,w]},void 0,!0),e[45]=N,e[46]=w,e[47]=g,e[48]=S,e[49]=C):C=e[49],C},"FunctionDoc"),rt=p(t=>{let e=(0,ee.c)(19),{name:o}=t,s=M(),n;e[0]!==o?(n=st(o),e[0]=o,e[1]=n):n=e[1];let r=n,l;e[2]!==o?(l=(0,B.jsxDEV)("h2",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"api-table-title",children:o},void 0,!1),e[2]=o,e[3]=l):l=e[3];let i;e[4]!==s?(i=s("Read and write this table through the typed data model."),e[4]=s,e[5]=i):i=e[5];let d;e[6]!==i?(d=(0,B.jsxDEV)("p",{className:"text-xs text-muted-foreground",children:i},void 0,!1),e[6]=i,e[7]=d):d=e[7];let c;e[8]!==l||e[9]!==d?(c=(0,B.jsxDEV)("div",{children:[l,d]},void 0,!0),e[8]=l,e[9]=d,e[10]=c):c=e[10];let m;e[11]!==s?(m=s("Data model"),e[11]=s,e[12]=m):m=e[12];let a;e[13]!==r||e[14]!==m?(a=(0,B.jsxDEV)(_e,{code:r,label:m,testId:"api-snippet-table"},void 0,!1),e[13]=r,e[14]=m,e[15]=a):a=e[15];let u;return e[16]!==c||e[17]!==a?(u=(0,B.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"api-table-doc",children:[c,a]},void 0,!0),e[16]=c,e[17]=a,e[18]=u):u=e[18],u},"TableDoc"),Re=p(t=>{let e=(0,ee.c)(8),{active:o,label:s,onSelect:n,testId:r,value:l}=t,i;e[0]!==n||e[1]!==l?(i=p(()=>{n(l)},"t1"),e[0]=n,e[1]=l,e[2]=i):i=e[2];let d=i,c=o?"page":void 0,m;return e[3]!==s||e[4]!==d||e[5]!==c||e[6]!==r?(m=(0,B.jsxDEV)("button",{"aria-current":c,className:"w-full truncate rounded-md px-2 py-1 text-start font-mono text-xs text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:bg-sidebar-accent aria-[current=page]:bg-sidebar-accent aria-[current=page]:font-medium aria-[current=page]:text-foreground","data-testid":r,onClick:d,type:"button",children:s},void 0,!1),e[3]=s,e[4]=d,e[5]=c,e[6]=r,e[7]=m):m=e[7],m},"RailButton"),je=p(t=>{let e=(0,ee.c)(67),{functions:o,initialShardKey:s}=t,n=M(),r=G(),[l,i]=(0,Z.useState)(null),[d,c]=(0,Z.useState)(null),m,a;e[0]!==r||e[1]!==s?(m=p(()=>{let _=!1;return r.query(Ye,{},de(s??"")).then(D=>(_||i(D),D)).catch(()=>{_||i([])}),()=>{_=!0}},"t1"),a=[r,s],e[0]=r,e[1]=s,e[2]=m,e[3]=a):(m=e[2],a=e[3]),(0,Z.useEffect)(m,a);let u;e[4]!==o?(u=o??[],e[4]=o,e[5]=u):u=e[5];let v=u,k;if(e[6]!==v){let _=new Map;for(let D of v){let{file:V,fn:U}=Pe(D.path),ie=_.get(V)??[];ie.push({fn:U,kind:D.kind,path:D.path}),_.set(V,ie)}k=[..._.entries()].map(at).toSorted(lt),e[6]=v,e[7]=k}else k=e[7];let O=k,h,g,x,b,S,y,$,N,w,C;if(e[8]!==v||e[9]!==O||e[10]!==d||e[11]!==n||e[12]!==l){let _=(l??[]).map(dt).toSorted(ct),D;e[23]===Symbol.for("react.memo_cache_sentinel")?(D=p(F=>{c({kind:"fn",path:F})},"t122"),e[23]=D):D=e[23];let V=D,U;e[24]===Symbol.for("react.memo_cache_sentinel")?(U=p(F=>{c({kind:"table",name:F})},"t132"),e[24]=U):U=e[24];let ie=U;if(g=d?.kind==="fn"?v.find(F=>F.path===d.path):void 0,h=v.length>0||_.length>0,x=g===void 0?void 0:Pe(g.path),b="grid min-h-0 gap-6 md:grid-cols-[16rem_minmax(0,1fr)]",S="lunora-api-docs",e[25]!==n?(y=n("API resources"),e[25]=n,e[26]=y):y=e[26],$="flex flex-col gap-4 overflow-y-auto",N="api-rail",e[27]!==O||e[28]!==d||e[29]!==n){let F;e[31]!==d||e[32]!==n?(F=p(ve=>(0,B.jsxDEV)("div",{className:"flex flex-col gap-1",children:[(0,B.jsxDEV)("span",{className:"px-2 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:ve.file||n("(root)")},void 0,!1),ve.items.map(se=>(0,B.jsxDEV)(Re,{active:d?.kind==="fn"&&d.path===se.path,label:se.fn,onSelect:V,testId:`api-rail-fn-${se.path}`,value:se.path},se.path,!1))]},ve.file,!0),"t142"),e[31]=d,e[32]=n,e[33]=F):F=e[33],w=O.map(F),e[27]=O,e[28]=d,e[29]=n,e[30]=w}else w=e[30];C=_.length>0&&(0,B.jsxDEV)("div",{className:"flex flex-col gap-1",children:[(0,B.jsxDEV)("span",{className:"px-2 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n("Tables")},void 0,!1),_.map(F=>(0,B.jsxDEV)(Re,{active:d?.kind==="table"&&d.name===F,label:F,onSelect:ie,testId:`api-rail-table-${F}`,value:F},F,!1))]},void 0,!0),e[8]=v,e[9]=O,e[10]=d,e[11]=n,e[12]=l,e[13]=h,e[14]=g,e[15]=x,e[16]=b,e[17]=S,e[18]=y,e[19]=$,e[20]=N,e[21]=w,e[22]=C}else h=e[13],g=e[14],x=e[15],b=e[16],S=e[17],y=e[18],$=e[19],N=e[20],w=e[21],C=e[22];let T;e[34]!==h||e[35]!==n?(T=!h&&(0,B.jsxDEV)("p",{className:"px-2 text-xs text-muted-foreground","data-testid":"api-rail-empty",children:n("No functions or tables to document yet.")},void 0,!1),e[34]=h,e[35]=n,e[36]=T):T=e[36];let I;e[37]!==T||e[38]!==y||e[39]!==$||e[40]!==N||e[41]!==w||e[42]!==C?(I=(0,B.jsxDEV)("nav",{"aria-label":y,className:$,"data-testid":N,children:[w,C,T]},void 0,!0),e[37]=T,e[38]=y,e[39]=$,e[40]=N,e[41]=w,e[42]=C,e[43]=I):I=e[43];let P;e[44]!==d||e[45]!==n?(P=d===null&&(0,B.jsxDEV)(W,{description:n("Select a function or table to see how to call it from your app."),testId:"api-empty",title:n("API usage snippets")},void 0,!1),e[44]=d,e[45]=n,e[46]=P):P=e[46];let E;e[47]!==d?.kind||e[48]!==g||e[49]!==x?(E=d?.kind==="fn"&&g!==void 0&&x!==void 0&&(0,B.jsxDEV)(nt,{file:x.file,fn:x.fn,kind:g.kind},g.path,!1),e[47]=d?.kind,e[48]=g,e[49]=x,e[50]=E):E=e[50];let j;e[51]!==d?.kind||e[52]!==g||e[53]!==n?(j=d?.kind==="fn"&&g===void 0&&(0,B.jsxDEV)(W,{testId:"api-empty",title:n("API usage snippets")},void 0,!1),e[51]=d?.kind,e[52]=g,e[53]=n,e[54]=j):j=e[54];let R;e[55]!==d?(R=d?.kind==="table"&&(0,B.jsxDEV)(rt,{name:d.name},void 0,!1),e[55]=d,e[56]=R):R=e[56];let L;e[57]!==P||e[58]!==E||e[59]!==j||e[60]!==R?(L=(0,B.jsxDEV)("div",{className:"min-w-0",children:[P,E,j,R]},void 0,!0),e[57]=P,e[58]=E,e[59]=j,e[60]=R,e[61]=L):L=e[61];let A;return e[62]!==b||e[63]!==S||e[64]!==I||e[65]!==L?(A=(0,B.jsxDEV)("div",{className:b,"data-testid":S,children:[I,L]},void 0,!0),e[62]=b,e[63]=S,e[64]=I,e[65]=L,e[66]=A):A=e[66],A},"ApiDocsPanel");function it(t,e){return t.fn.localeCompare(e.fn)}p(it,"_temp");function at(t){let[e,o]=t;return{file:e,items:o.toSorted(it)}}p(at,"_temp2");function lt(t,e){return t.file.localeCompare(e.file)}p(lt,"_temp3");function dt(t){return t.name}p(dt,"_temp4");function ct(t,e){return t.localeCompare(e)}p(ct,"_temp5");var Ve=q(oe(),1);var J=q(oe(),1),K=q(he(),1);var f=q(ne(),1);var ue=p(function(t,e,o){let s=(0,J.c)(10),n;s[0]===Symbol.for("react.memo_cache_sentinel")?(n={kind:"loading"},s[0]=n):n=s[0];let[r,l]=(0,K.useState)(n),i,d;s[1]!==o||s[2]!==e||s[3]!==t?(i=p(()=>{if(t!==void 0)return;let m=!1;return e().then(a=>(m||l(o(a)),a)).catch(a=>{m||l({kind:"error",message:ce(a)})}),()=>{m=!0}},"t1"),d=[o,e,t],s[1]=o,s[2]=e,s[3]=t,s[4]=i,s[5]=d):(i=s[4],d=s[5]),(0,K.useEffect)(i,d);let c;return s[6]!==o||s[7]!==r||s[8]!==t?(c=t===void 0?r:o(t),s[6]=o,s[7]=r,s[8]=t,s[9]=c):c=s[9],c},"useAdminSpec"),ft=p(t=>typeof t=="number"?"number":typeof t=="boolean"?"boolean":"string","scalarOf"),De=p(t=>{if(t.enum!==void 0&&t.enum.length>0)return t.enum;if(t.anyOf!==void 0&&t.anyOf.length>0&&t.anyOf.every(e=>e.const!==void 0))return t.anyOf.map(e=>e.const)},"enumValues"),pe=p(t=>t===void 0?"any":t.const!==void 0?JSON.stringify(t.const):t.enum!==void 0&&t.enum.length>0?t.enum.map(e=>JSON.stringify(e)).join(" | "):t.anyOf!==void 0&&t.anyOf.length>0?t.anyOf.map(e=>pe(e)).join(" | "):t.type==="array"?`array<${pe(t.items)}>`:t.type??"any","typeLabel"),pt=p(t=>{let e=De(t);return e!==void 0?t.type??ft(e[0]):pe(t)},"fieldTypeLabel"),ut=p(t=>{let e=De(t);return e===void 0?void 0:e.map(o=>JSON.stringify(o)).join(" | ")},"valueInText"),mt=p(t=>{let e=[];t.minimum!==void 0?e.push(`${String(t.minimum)} \u2264`):t.exclusiveMinimum!==void 0&&e.push(`${String(t.exclusiveMinimum)} <`);let o=e.length>0;e.push("value"),t.maximum!==void 0?e.push(`\u2264 ${String(t.maximum)}`):t.exclusiveMaximum!==void 0&&e.push(`< ${String(t.exclusiveMaximum)}`);let s=e.length>(o?2:1);return o||s?e.join(" "):void 0},"rangeText"),vt=p(t=>{if(t.type==="object"&&t.properties!==void 0)return t;if(t.type==="array"&&t.items?.type==="object"&&t.items.properties!==void 0)return t.items},"childObject"),te=p(t=>{if(t===void 0)return null;if(t.const!==void 0)return t.const;if(t.enum!==void 0&&t.enum.length>0)return t.enum[0];if(t.anyOf!==void 0&&t.anyOf.length>0)return te(t.anyOf[0]);switch(t.type){case"array":return[];case"boolean":return!1;case"number":return 0;case"object":{let e={};for(let[o,s]of Object.entries(t.properties??{}))e[o]=te(s);return e}case"string":return"";default:return null}},"exampleForSchema"),fe=p(t=>{let e=(0,J.c)(7),{label:o,value:s}=t,n;e[0]!==o?(n=(0,f.jsxDEV)("span",{className:"text-muted-foreground",children:o},void 0,!1),e[0]=o,e[1]=n):n=e[1];let r;e[2]!==s?(r=(0,f.jsxDEV)("span",{className:"text-foreground",children:s},void 0,!1),e[2]=s,e[3]=r):r=e[3];let l;return e[4]!==n||e[5]!==r?(l=(0,f.jsxDEV)("span",{className:"inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 font-mono text-[10px]",children:[n,r]},void 0,!0),e[4]=n,e[5]=r,e[6]=l):l=e[6],l},"Badge"),ht=p(t=>{let e=(0,J.c)(40),{name:o,required:s,schema:n}=t,r=M(),l;e[0]!==n?(l=mt(n),e[0]=n,e[1]=l):l=e[1];let i=l,d;e[2]!==n?(d=ut(n),e[2]=n,e[3]=d):d=e[3];let c=d,m=n["x-lunora-table"],a=n.format!==void 0||i!==void 0||c!==void 0||m!==void 0,u;e[4]!==n?(u=vt(n),e[4]=n,e[5]=u):u=e[5];let v=u,k=s?"*":"?",O;e[6]!==k?(O=(0,f.jsxDEV)("span",{className:"text-muted-foreground",children:k},void 0,!1),e[6]=k,e[7]=O):O=e[7];let h;e[8]!==o||e[9]!==O?(h=(0,f.jsxDEV)("span",{className:"font-mono text-foreground",children:[o,O]},void 0,!0),e[8]=o,e[9]=O,e[10]=h):h=e[10];let g;e[11]!==n?(g=pt(n),e[11]=n,e[12]=g):g=e[12];let x;e[13]!==g?(x=(0,f.jsxDEV)("span",{className:"font-mono text-muted-foreground",children:g},void 0,!1),e[13]=g,e[14]=x):x=e[14];let b;e[15]!==h||e[16]!==x?(b=(0,f.jsxDEV)("div",{className:"flex items-baseline gap-2",children:[h,x]},void 0,!0),e[15]=h,e[16]=x,e[17]=b):b=e[17];let S;e[18]!==n.description?(S=n.description!==void 0&&(0,f.jsxDEV)("p",{className:"max-w-prose text-muted-foreground",children:n.description},void 0,!1),e[18]=n.description,e[19]=S):S=e[19];let y;e[20]!==a||e[21]!==i||e[22]!==m||e[23]!==n.format||e[24]!==r||e[25]!==c?(y=a&&(0,f.jsxDEV)("div",{className:"flex flex-wrap gap-1",children:[n.format!==void 0&&(0,f.jsxDEV)(fe,{label:r("Format"),value:n.format},void 0,!1),i!==void 0&&(0,f.jsxDEV)(fe,{label:r("Range"),value:i},void 0,!1),c!==void 0&&(0,f.jsxDEV)(fe,{label:r("Value in"),value:c},void 0,!1),m!==void 0&&(0,f.jsxDEV)(fe,{label:r("relation"),value:m},void 0,!1)]},void 0,!0),e[20]=a,e[21]=i,e[22]=m,e[23]=n.format,e[24]=r,e[25]=c,e[26]=y):y=e[26];let $;e[27]!==S||e[28]!==y||e[29]!==b?($=(0,f.jsxDEV)("div",{className:"flex flex-col gap-1 py-2",children:[b,S,y]},void 0,!0),e[27]=S,e[28]=y,e[29]=b,e[30]=$):$=e[30];let N=$;if(v===void 0){let I;return e[31]!==N?(I=(0,f.jsxDEV)("div",{className:"border-b border-border/50 last:border-b-0",children:N},void 0,!1),e[31]=N,e[32]=I):I=e[32],I}let w;e[33]!==N?(w=(0,f.jsxDEV)("summary",{className:"cursor-pointer marker:text-muted-foreground",children:N},void 0,!1),e[33]=N,e[34]=w):w=e[34];let C;e[35]!==v?(C=(0,f.jsxDEV)("div",{className:"mb-2 ml-2 border-l border-border pl-3",children:(0,f.jsxDEV)(Me,{schema:v},void 0,!1)},void 0,!1),e[35]=v,e[36]=C):C=e[36];let T;return e[37]!==w||e[38]!==C?(T=(0,f.jsxDEV)("details",{className:"border-b border-border/50 last:border-b-0",children:[w,C]},void 0,!0),e[37]=w,e[38]=C,e[39]=T):T=e[39],T},"FieldRow"),Me=p(t=>{let e=(0,J.c)(7),{schema:o}=t,s;e[0]!==o.required?(s=new Set(o.required),e[0]=o.required,e[1]=s):s=e[1];let n=s,r;e[2]!==o.properties?(r=Object.entries(o.properties??{}),e[2]=o.properties,e[3]=r):r=e[3];let l=r,i;return e[4]!==n||e[5]!==l?(i=(0,f.jsxDEV)("div",{className:"flex flex-col",children:l.map(d=>{let[c,m]=d;return(0,f.jsxDEV)(ht,{name:c,required:n.has(c),schema:m},c,!1)})},void 0,!1),e[4]=n,e[5]=l,e[6]=i):i=e[6],i},"SchemaFields"),Le=p(t=>{let e=(0,J.c)(10),{schema:o,testId:s}=t;if(o?.type!=="object"||Object.keys(o.properties??{}).length===0){let l;e[0]!==o?(l=pe(o),e[0]=o,e[1]=l):l=e[1];let i;return e[2]!==l||e[3]!==s?(i=(0,f.jsxDEV)("p",{className:"font-mono text-xs text-muted-foreground","data-testid":s,children:l},void 0,!1),e[2]=l,e[3]=s,e[4]=i):i=e[4],i}let n;e[5]!==o?(n=(0,f.jsxDEV)(Me,{schema:o},void 0,!1),e[5]=o,e[6]=n):n=e[6];let r;return e[7]!==n||e[8]!==s?(r=(0,f.jsxDEV)("div",{className:"text-xs","data-testid":s,children:n},void 0,!1),e[7]=n,e[8]=s,e[9]=r):r=e[9],r},"SchemaTable"),gt=["curl","javascript","lunora"],xt={lunora:"Lunora",curl:"cURL",javascript:"JavaScript"},bt=p(t=>`api.${t.replaceAll(/[/:]/g,".")}`,"apiReferenceOf"),yt=p(t=>{let e=te(t.argsSchema)??{};return t.functionPath===void 0?e:{args:e,functionPath:t.functionPath}},"requestBody"),Nt=p((t,e,o)=>{let s=`${o}${e.httpPath}`,n=JSON.stringify(yt(e),void 0,2),r=JSON.stringify(te(e.argsSchema)??{},void 0,2);switch(t){case"curl":{let l=e.method!=="GET"&&e.method!=="HEAD",i=[`curl -X ${e.method} ${JSON.stringify(s)}`];return l&&i.push(' -H "Content-Type: application/json"',` -d '${n}'`),i.join(` \\
|
|
3
3
|
`)}case"lunora":return e.functionPath===void 0?`await fetch(${JSON.stringify(e.httpPath)}, { method: ${JSON.stringify(e.method)} });`:`import { useLunora } from "@lunora/react";
|
|
4
4
|
import { api } from "./_generated/api";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b,c as v,d as g,f as D}from"./chunk-GLUNBZRI.js";import{e as y,f as p,g as P,k as O}from"./chunk-
|
|
1
|
+
import{b,c as v,d as g,f as D}from"./chunk-GLUNBZRI.js";import{e as y,f as p,g as P,k as O}from"./chunk-E75ANNWX.js";import{a as n,e as Q,f as N,g as _}from"./chunk-RRCPZMC2.js";var E=Q(_(),1);var c=Q(N(),1);var C=n((e,r,o)=>["lunora-admin",e,r,o.trim()],"adminQueryKey"),h=1e3,S=25,q=new Map,k=n(e=>{let r=Date.now(),o=(q.get(e)??[]).filter(s=>r-s<h);o.push(r),q.set(e,o),o.length===S&&(console.error(`[lunora-studio] possible request loop: ${e} fired ${String(S)}\xD7 in <1s \u2014 a render/effect is re-issuing this read unbounded.`),console.trace("[lunora-studio] request-loop call site"))},"noteQueryFetch");function R(e,r,o={}){let{enabled:s=!0,keepPreviousData:a=!1,staleTime:i=0}=o,t=g({enabled:s,queryFn:n(()=>(k(JSON.stringify(e)),r()),"trackedQueryFunction"),placeholderData:a?b:void 0,queryKey:e,staleTime:i});return{data:t.data,error:t.error?P(t.error):t.error,errorSource:t.error??void 0,isLoading:t.isLoading,liveError:void 0,refetch:n(()=>{O(t.refetch())},"refetch")}}n(R,"useClientQuery");function K(e,r,o={}){let s=D(),a=v(),{enabled:i=!0,keepPreviousData:u=!1,live:t=!1,shardKey:l="",staleTime:I}=o,d=C(e,r,l),L=R(d,()=>s.query(y(e),r,p(l)),{enabled:i,keepPreviousData:u,staleTime:I??(t?Number.POSITIVE_INFINITY:0)}),[T,f]=(0,c.useState)(void 0),F=JSON.stringify(d);return(0,c.useEffect)(()=>{if(!(!i||!t))return f(void 0),s.subscribe(y(e),r,m=>{f(void 0),a.setQueryData(d,m)},{...p(l),onError:n(m=>{f(m.message)},"onError")})},[F,i,t]),{...L,liveError:i&&t?T:void 0}}n(K,"useAdminQuery");var M=n(()=>{let e=(0,E.c)(2),r=v(),o;return e[0]!==r?(o=n((s,a,i)=>{let u=a===void 0?["lunora-admin",s]:C(s,a,i??"");O(r.invalidateQueries({queryKey:u}))},"t0"),e[0]=r,e[1]=o):o=e[1],o},"useInvalidateAdmin");export{R as a,K as b,M as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as V}from"./chunk-XNJNSCLM.js";import{g as w,h as A,i as E}from"./chunk-
|
|
1
|
+
import{a as V}from"./chunk-XNJNSCLM.js";import{g as w,h as A,i as E}from"./chunk-E75ANNWX.js";import{a as b}from"./chunk-GMSGZDDH.js";import{a as x,e as N,g as D,h as H}from"./chunk-RRCPZMC2.js";var g=N(D(),1);var d=N(H(),1);var y=x(k=>{let e=(0,g.c)(26),{className:u,error:t,testId:h}=k,o,l,i,s,a,r,n;if(e[0]!==u||e[1]!==t||e[2]!==h){let v=A(t),p;e[10]!==t?(p=E(t),e[10]=t,e[11]=p):p=e[11],l=p,o=V,i=u,s=h,a="destructive";let m;e[12]!==t?(m=w(t),e[12]=t,e[13]=m):m=e[13],e[14]!==m?(r=(0,d.jsxDEV)("p",{className:"font-medium",children:m},void 0,!1),e[14]=m,e[15]=r):r=e[15],n=v===void 0?null:(0,d.jsxDEV)("p",{className:"mt-1 whitespace-pre-wrap text-xs opacity-90",children:b(v)},void 0,!1),e[0]=u,e[1]=t,e[2]=h,e[3]=o,e[4]=l,e[5]=i,e[6]=s,e[7]=a,e[8]=r,e[9]=n}else o=e[3],l=e[4],i=e[5],s=e[6],a=e[7],r=e[8],n=e[9];let c;e[16]!==l?(c=l===void 0?null:(0,d.jsxDEV)("a",{"aria-label":"View documentation for this error",className:"mt-1 inline-block text-xs underline",href:l,rel:"noreferrer",target:"_blank",children:"View error docs"},void 0,!1),e[16]=l,e[17]=c):c=e[17];let f;return e[18]!==o||e[19]!==i||e[20]!==s||e[21]!==a||e[22]!==r||e[23]!==n||e[24]!==c?(f=(0,d.jsxDEV)(o,{className:i,testId:s,variant:a,children:[r,n,c]},void 0,!0),e[18]=o,e[19]=i,e[20]=s,e[21]=a,e[22]=r,e[23]=n,e[24]=c,e[25]=f):f=e[25],f},"ErrorAlert");export{y as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as le}from"./chunk-WXPWVBIY.js";import{a as te}from"./chunk-AJIUI7DD.js";import"./chunk-XNJNSCLM.js";import{a as ae,b as se,c as oe,d as Q,e as $,f as z}from"./chunk-GTM65MVX.js";import{a as re}from"./chunk-VLXV72QE.js";import{a as C}from"./chunk-JSEXCW5Q.js";import{a as ee}from"./chunk-K3GNLVYK.js";import"./chunk-TBMYIZIO.js";import{R as E}from"./chunk-3CJW6NWG.js";import{c as k}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as L}from"./chunk-BOXSWNXZ.js";import{a as J}from"./chunk-TAD43CG5.js";import{b as U}from"./chunk-OIC7EJWI.js";import{a as j,b as K,c as V,d as Y,e as q}from"./chunk-SEU5V7I6.js";import{b as I}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as W}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as O,e as G,f as X,g as Z,k as D}from"./chunk-PVZI3CXP.js";import"./chunk-GMSGZDDH.js";import{a as n,e as B,f as ve,g as he,h as xe}from"./chunk-RRCPZMC2.js";var c=B(ve(),1);var ne=B(he(),1);var e=B(xe(),1);var ie=["read","insert","update","delete"],ye=n((a,t)=>({delete:a("Delete"),insert:a("Insert"),read:a("Read"),update:a("Update")})[t],"operationLabel"),ge=n(a=>{let t=new Set;for(let l of a?.advisories??[])if(l.name==="rls_uncovered_table"){let{table:r}=l.metadata;typeof r=="string"&&r!==""&&t.add(r)}return t},"uncoveredTables"),be=n((a,t,l)=>{let r=new Map,s=n(o=>{let d=r.get(o);if(d!==void 0)return d;let i={cells:{delete:{},insert:{},read:{},update:{}},maskedColumns:[],table:o,uncovered:l.has(o)};return r.set(o,i),i},"ensure");for(let o of a)s(o.table).cells[o.on]={procedure:o.procedure};for(let o of t){let d=s(o.table);d.maskedColumns.includes(o.column)||d.maskedColumns.push(o.column)}for(let o of l)s(o);return[...r.values()].toSorted((o,d)=>o.table.localeCompare(d.table))},"buildRows"),Ne=n(a=>{let t=(0,ne.c)(17),l;t[0]!==a?(l=a===void 0?{}:a,t[0]=a,t[1]=l):l=t[1];let{onProbe:r}=l,s=O(),o,d;t[2]===Symbol.for("react.memo_cache_sentinel")?(o={},d={live:!0},t[2]=o,t[3]=d):(o=t[2],d=t[3]);let i=U(L.rlsPolicies,o,d),x;t[4]===Symbol.for("react.memo_cache_sentinel")?(x={},t[4]=x):x=t[4];let p=U(L.maskPolicies,x),v;t[5]===Symbol.for("react.memo_cache_sentinel")?(v={},t[5]=v):v=t[5];let b=U(L.getAdvisories,v),N;if(t[6]!==b.data||t[7]!==p.data||t[8]!==r||t[9]!==i||t[10]!==s){let g=null;i.data!==void 0&&(g=Array.isArray(i.data.policies)?i.data.policies:[]);let _=Array.isArray(p.data?.columns)?p.data.columns:[],F=b.data??null,{error:h,errorSource:m,liveError:P}=i,A=g===null?[]:be(g,_,ge(F)),T;t[12]!==P?(T=(0,e.jsxDEV)("div",{className:"flex items-center justify-end",children:(0,e.jsxDEV)(le,{message:P,prefix:"pm"},void 0,!1)},void 0,!1),t[12]=P,t[13]=T):T=t[13];let y;t[14]!==h||t[15]!==m?(y=h!==null&&(0,e.jsxDEV)(te,{error:m,testId:"pm-error"},void 0,!1),t[14]=h,t[15]=m,t[16]=y):y=t[16],N=(0,e.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-matrix",children:[T,y,g!==null&&A.length===0?(0,e.jsxDEV)(J,{description:s("Add a `definePolicy` and wire it through `.use(rls(...))` to populate this matrix."),testId:"pm-empty",title:s("No policy")},void 0,!1):(0,e.jsxDEV)(ae,{"data-testid":"pm-table",children:[(0,e.jsxDEV)(se,{children:(0,e.jsxDEV)(Q,{children:[(0,e.jsxDEV)($,{children:s("Table")},void 0,!1),ie.map(u=>(0,e.jsxDEV)($,{children:ye(s,u)},u,!1)),(0,e.jsxDEV)($,{children:s("Masked columns")},void 0,!1)]},void 0,!0)},void 0,!1),(0,e.jsxDEV)(oe,{children:A.map(u=>(0,e.jsxDEV)(Q,{"data-testid":`pm-row-${u.table}`,children:[(0,e.jsxDEV)(z,{className:"font-mono text-xs",children:(0,e.jsxDEV)("span",{className:"flex items-center gap-1.5",children:[u.table,u.uncovered&&(0,e.jsxDEV)(I,{"data-testid":`pm-uncovered-${u.table}`,title:s("Uncovered \u2014 reachable without a policy"),variant:"destructive",children:s("Uncovered \u2014 reachable without a policy")},void 0,!1)]},void 0,!0)},void 0,!1),ie.map(w=>{let R=u.cells[w];return(0,e.jsxDEV)(z,{"data-testid":`pm-cell-${u.table}-${w}`,children:R.procedure===void 0?(0,e.jsxDEV)("span",{className:"text-xs text-muted-foreground",children:s("No policy")},void 0,!1):(0,e.jsxDEV)("span",{className:"flex flex-col gap-1",children:[(0,e.jsxDEV)(I,{variant:"secondary",children:s("Covered by {procedure}",{procedure:R.procedure})},void 0,!1),r!==void 0&&(0,e.jsxDEV)(k,{className:"h-auto justify-start p-0 text-[11px]","data-testid":`pm-probe-${u.table}-${w}`,onClick:n(()=>{r(u.table,w,R.procedure??"")},"onClick"),size:"xs",type:"button",variant:"ghost",children:s("Probe this")},void 0,!1)]},void 0,!0)},w,!1)}),(0,e.jsxDEV)(z,{children:u.maskedColumns.length===0?(0,e.jsxDEV)("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"\u2014"},void 0,!1):(0,e.jsxDEV)("span",{className:"flex flex-wrap gap-1",children:u.maskedColumns.map(ke)},void 0,!1)},void 0,!1)]},u.table,!0))},void 0,!1)]},void 0,!0)]},void 0,!0),t[6]=b.data,t[7]=p.data,t[8]=r,t[9]=i,t[10]=s,t[11]=N}else N=t[11];return N},"PermissionsMatrix");function ke(a){return(0,e.jsxDEV)(I,{variant:"outline",children:a},a,!1)}n(ke,"_temp");var Ce=G(L.runAs),we=n(()=>{let a=W();return async({args:t,functionPath:l,shardKey:r="",userId:s})=>{let o=Ce;try{return{kind:"allowed",value:await a.query(o,{args:t,functionPath:l,userId:s},X(r))}}catch(d){return{kind:"denied",message:d instanceof Error?d.message:String(d)}}}},"useRunAsProbe"),Se=n(a=>a===void 0?"undefined":JSON.stringify(a,null,2),"formatValue"),Pe=n(({functions:a,prefill:t,runAsIdentity:l=!1}={})=>{let r=W(),s=O(),o=we(),[d,i]=(0,c.useState)(null),[x,p]=(0,c.useState)(null),v=a??d??[],[b,N]=(0,c.useState)(""),[g,_]=(0,c.useState)("{}"),[F,h]=(0,c.useState)(""),[m,P]=(0,c.useState)(""),[A,T]=(0,c.useState)(!1),[y,u]=(0,c.useState)(null),[w,R]=(0,c.useState)(null),H=(0,c.useRef)(-1);(0,c.useEffect)(()=>{if(a!==void 0)return;let f=!1;return r.listFunctions().then(S=>(f||i(S),S)).catch(S=>{f||p(Z(S))}),()=>{f=!0}},[r,a]),(0,c.useEffect)(()=>{if(t===void 0||H.current===t.nonce)return;H.current=t.nonce;let f=t.functionPath;queueMicrotask(()=>{N(f),u(null)})},[t]);let M=b===""?v[0]?.path??"":b,ce=n(async()=>{if(M==="")return;let f;try{f=g.trim()===""?{}:JSON.parse(g)}catch(S){R(s("Invalid JSON args: {message}",{message:S.message})),u(null);return}R(null),T(!0);try{let S=await o({args:f,functionPath:M,shardKey:F.trim(),userId:m.trim()});u(S)}finally{T(!1)}},"run"),fe=n(()=>{D(ce())},"runOnce"),ue=n(f=>{N(f.target.value)},"onSelectChange"),me=n(f=>{_(f.target.value)},"onArgsChange"),pe=n(f=>{P(f.target.value)},"onUserIdChange");return(0,e.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-playground",children:[x!==null&&(0,e.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"pp-discover-error",role:"alert",children:x},void 0,!1),!l&&(0,e.jsxDEV)(J,{description:s("Dev only: runs the selected function as this user over the admin gate so you can test auth and RLS."),testId:"pp-gate",title:s("Set `runAsIdentity` to forge an identity and probe access.")},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-3 rounded-md border border-border p-3",children:[(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)(C,{htmlFor:"pp-function",children:s("Function")},void 0,!1),(0,e.jsxDEV)("select",{"aria-label":s("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","data-testid":"pp-function",id:"pp-function",onChange:ue,value:M,children:v.map(f=>(0,e.jsxDEV)("option",{value:f.path,children:[f.path," (",f.kind,")"]},f.path,!0))},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)(C,{htmlFor:"pp-args",children:s("Arguments")},void 0,!1),(0,e.jsxDEV)(re,{"aria-label":s("Arguments"),className:"font-mono text-xs","data-testid":"pp-args",id:"pp-args",onChange:me,value:g},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(ee,{onChange:h,testId:"pp-shard",value:F},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)(C,{htmlFor:"pp-user",children:s("Run as (userId)")},void 0,!1),(0,e.jsxDEV)(E,{"aria-label":s("Identity (userId) to run as"),className:"font-mono text-xs","data-testid":"pp-user",id:"pp-user",onChange:pe,placeholder:s("Leave empty to run as admin"),value:m},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex items-center gap-2",children:[(0,e.jsxDEV)(k,{"data-testid":"pp-run",disabled:!l||A||M==="",onClick:fe,type:"button",children:s(A?"Probing\u2026":"Run probe")},void 0,!1),m.trim()!==""&&(0,e.jsxDEV)(I,{"data-testid":"pp-as-badge",variant:"secondary",children:s("as {userId}",{userId:m.trim()})},void 0,!1)]},void 0,!0)]},void 0,!0),w!==null&&(0,e.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"pp-args-error",role:"alert",children:w},void 0,!1),y!==null&&y.kind==="allowed"&&(0,e.jsxDEV)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-allowed",children:[(0,e.jsxDEV)(I,{variant:"secondary",children:s("Allowed")},void 0,!1),(0,e.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"pp-result",children:Se(y.value)},void 0,!1)]},void 0,!0),y!==null&&y.kind==="denied"&&(0,e.jsxDEV)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-denied",children:[(0,e.jsxDEV)(I,{variant:"destructive",children:s("Denied")},void 0,!1),(0,e.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"pp-denied",role:"alert",children:y.message},void 0,!1)]},void 0,!0)]},void 0,!0)},"PermissionsPlayground"),Ae="/__lunora/policy-scaffold",Te={"already-wired":"That procedure already has an rls(...) policy wired in.","file-exists":"A policy file with that name already exists \u2014 pick another name or edit it by hand.","invalid-identifier":"Name, table, and policy-set must be plain identifiers (letters, digits, _ or $).","unknown-procedure":"No exported procedure was found at that file path.","unsupported-procedure-shape":"That procedure uses the bare query({\u2026}) form \u2014 convert it to the builder form (c.use(\u2026).query(\u2026)) before wiring RLS."},Ie=n(async a=>{let t=await fetch(Ae,{body:JSON.stringify(a),headers:{"Content-Type":"application/json"},method:"POST"}),l=await t.json();if(l.needsManualEdit===!0)return{kind:"needs-manual-edit",message:l.message??"This change must be made by hand."};if(t.ok)return{diagnostics:l.diagnostics??[],kind:"ok",label:l.fileName??l.exportName??""};let r=l.error;return{kind:"error",message:r===void 0?`policy scaffold failed (${String(t.status)})`:Te[r]??r}},"applyPolicyScaffold"),de={exportName:"",filePath:"",policyName:"",policies:"",tableName:""},Ee=n(()=>{let a=O(),[t,l]=(0,c.useState)(null),[r,s]=(0,c.useState)(!1),[o,d]=(0,c.useState)(null),[i,x]=(0,c.useState)(de),p=n(h=>{let m=h.target.name,{value:P}=h.target;x(A=>({...A,[m]:P}))},"onFieldChange"),v=n(()=>{l(null),x(de)},"reset"),b=n(async h=>{s(!0),d(null);try{let m=await Ie(h);d(m),m.kind==="ok"&&v()}catch(m){d({kind:"error",message:m instanceof Error?m.message:String(m)})}finally{s(!1)}},"submit"),N=n(()=>{D(b({kind:"scaffoldPolicy",name:i.policyName.trim(),table:i.tableName.trim()}))},"onSubmitScaffold"),g=n(()=>{D(b({exportName:i.exportName.trim(),filePath:i.filePath.trim(),kind:"wireRls",policies:i.policies.trim()}))},"onSubmitWire"),_=n(()=>{d(null),l("scaffold")},"openScaffold"),F=n(()=>{d(null),l("wire")},"openWire");return(0,e.jsxDEV)(j,{"data-testid":"policy-scaffolder",size:"sm",children:[(0,e.jsxDEV)(K,{children:[(0,e.jsxDEV)(V,{children:a("Scaffold access rules")},void 0,!1),(0,e.jsxDEV)(Y,{children:a("Writes a new deny-by-default policy file under lunora/, or wires one into a procedure, then reruns codegen. Local dev only.")},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(q,{children:[(0,e.jsxDEV)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsxDEV)(k,{"data-testid":"policy-scaffolder-new",onClick:_,size:"xs",type:"button",variant:t==="scaffold"?"default":"outline",children:a("New policy file")},void 0,!1),(0,e.jsxDEV)(k,{"data-testid":"policy-scaffolder-wire",onClick:F,size:"xs",type:"button",variant:t==="wire"?"default":"outline",children:a("Wire into a procedure")},void 0,!1)]},void 0,!0),t==="scaffold"&&(0,e.jsxDEV)("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-new-form",children:[(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-name",children:a("Policy name")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-name",id:"policy-scaffolder-name",name:"policyName",onChange:p,value:i.policyName},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-table",children:a("Table name")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-table",id:"policy-scaffolder-table",name:"tableName",onChange:p,value:i.tableName},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(k,{"data-testid":"policy-scaffolder-create",disabled:r||i.policyName.trim()===""||i.tableName.trim()==="",onClick:N,size:"xs",type:"button",children:a(r?"Creating\u2026":"Create policy file")},void 0,!1),(0,e.jsxDEV)(k,{onClick:v,size:"xs",type:"button",variant:"ghost",children:a("Cancel")},void 0,!1)]},void 0,!0),t==="wire"&&(0,e.jsxDEV)("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-wire-form",children:[(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-file",children:a("Procedure file path")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-file",id:"policy-scaffolder-file",name:"filePath",onChange:p,value:i.filePath},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-export",children:a("Exported procedure")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-export",id:"policy-scaffolder-export",name:"exportName",onChange:p,value:i.exportName},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-policies",children:a("Policy set identifier")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-policies",id:"policy-scaffolder-policies",name:"policies",onChange:p,value:i.policies},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(k,{"data-testid":"policy-scaffolder-apply",disabled:r||i.filePath.trim()===""||i.exportName.trim()===""||i.policies.trim()==="",onClick:g,size:"xs",type:"button",children:a(r?"Wiring\u2026":"Wire RLS")},void 0,!1),(0,e.jsxDEV)(k,{onClick:v,size:"xs",type:"button",variant:"ghost",children:a("Cancel")},void 0,!1)]},void 0,!0),o?.kind==="error"&&(0,e.jsxDEV)("p",{className:"mt-3 text-sm text-destructive","data-testid":"policy-scaffolder-error",role:"alert",children:o.message},void 0,!1),o?.kind==="needs-manual-edit"&&(0,e.jsxDEV)("p",{className:"mt-3 text-sm text-amber-600 dark:text-amber-500","data-testid":"policy-scaffolder-manual",role:"alert",children:a("This change must be made by hand \u2014 the scaffolder only adds new, deny-by-default rules.")},void 0,!1),o?.kind==="ok"&&(0,e.jsxDEV)("div",{className:"mt-3 flex flex-col gap-1","data-testid":"policy-scaffolder-ok",children:[(0,e.jsxDEV)("p",{className:"text-sm text-emerald-600 dark:text-emerald-500",children:a("Scaffolded {label} and reran codegen. Fill in the `when` predicates before relying on it.",{label:o.label})},void 0,!1),o.diagnostics.length>0&&(0,e.jsxDEV)("ul",{className:"flex flex-col gap-0.5","data-testid":"policy-scaffolder-diagnostics",children:o.diagnostics.map(h=>(0,e.jsxDEV)("li",{className:"font-mono text-[11px] text-destructive",children:h},h,!1))},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0)},"PolicyScaffolder"),He=n(({functions:a,runAsIdentity:t=!1,schemaEditable:l=!1}={})=>{let r=O(),[s,o]=(0,c.useState)(void 0),d=n((i,x,p)=>{p!==""&&o(v=>({functionPath:p,nonce:(v?.nonce??0)+1}))},"onProbe");return(0,e.jsxDEV)("div",{className:"flex flex-col gap-8","data-testid":"lunora-permissions",children:[(0,e.jsxDEV)("section",{className:"flex flex-col gap-3",children:[(0,e.jsxDEV)("header",{className:"border-b border-border px-4 py-3",children:(0,e.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Permissions")},void 0,!1)},void 0,!1),(0,e.jsxDEV)(Ne,{onProbe:d},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("section",{className:"flex flex-col gap-3",children:(0,e.jsxDEV)(j,{className:"gap-0 py-0",children:[(0,e.jsxDEV)("header",{className:"border-b border-border px-4 py-3",children:(0,e.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Probe")},void 0,!1)},void 0,!1),(0,e.jsxDEV)(q,{className:"px-4 py-4",children:[(0,e.jsxDEV)("p",{className:"mb-3 text-sm text-muted-foreground",children:r("Pick a function and an identity, then run it to see the access outcome.")},void 0,!1),(0,e.jsxDEV)(Pe,{functions:a,prefill:s,runAsIdentity:t},void 0,!1)]},void 0,!0)]},void 0,!0)},void 0,!1),l&&(0,e.jsxDEV)("section",{className:"flex flex-col gap-2",children:(0,e.jsxDEV)(Ee,{},void 0,!1)},void 0,!1)]},void 0,!0)},"PermissionsPanel");export{He as PermissionsPanel};
|
|
1
|
+
import{a as le}from"./chunk-UGUEC6BC.js";import{a as te}from"./chunk-CACB34RQ.js";import"./chunk-XNJNSCLM.js";import{a as ae,b as se,c as oe,d as Q,e as $,f as z}from"./chunk-GTM65MVX.js";import{a as re}from"./chunk-VLXV72QE.js";import{a as C}from"./chunk-JSEXCW5Q.js";import{a as ee}from"./chunk-UKDJ4H7I.js";import"./chunk-TBMYIZIO.js";import{R as E}from"./chunk-3CJW6NWG.js";import{c as k}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as L}from"./chunk-BOXSWNXZ.js";import{a as J}from"./chunk-TAD43CG5.js";import{b as U}from"./chunk-C7WTJLC3.js";import{a as j,b as K,c as V,d as Y,e as q}from"./chunk-SEU5V7I6.js";import{b as I}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as W}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as O,e as G,f as X,g as Z,k as D}from"./chunk-E75ANNWX.js";import"./chunk-GMSGZDDH.js";import{a as n,e as B,f as ve,g as he,h as xe}from"./chunk-RRCPZMC2.js";var c=B(ve(),1);var ne=B(he(),1);var e=B(xe(),1);var ie=["read","insert","update","delete"],ye=n((a,t)=>({delete:a("Delete"),insert:a("Insert"),read:a("Read"),update:a("Update")})[t],"operationLabel"),ge=n(a=>{let t=new Set;for(let l of a?.advisories??[])if(l.name==="rls_uncovered_table"){let{table:r}=l.metadata;typeof r=="string"&&r!==""&&t.add(r)}return t},"uncoveredTables"),be=n((a,t,l)=>{let r=new Map,s=n(o=>{let d=r.get(o);if(d!==void 0)return d;let i={cells:{delete:{},insert:{},read:{},update:{}},maskedColumns:[],table:o,uncovered:l.has(o)};return r.set(o,i),i},"ensure");for(let o of a)s(o.table).cells[o.on]={procedure:o.procedure};for(let o of t){let d=s(o.table);d.maskedColumns.includes(o.column)||d.maskedColumns.push(o.column)}for(let o of l)s(o);return[...r.values()].toSorted((o,d)=>o.table.localeCompare(d.table))},"buildRows"),Ne=n(a=>{let t=(0,ne.c)(17),l;t[0]!==a?(l=a===void 0?{}:a,t[0]=a,t[1]=l):l=t[1];let{onProbe:r}=l,s=O(),o,d;t[2]===Symbol.for("react.memo_cache_sentinel")?(o={},d={live:!0},t[2]=o,t[3]=d):(o=t[2],d=t[3]);let i=U(L.rlsPolicies,o,d),x;t[4]===Symbol.for("react.memo_cache_sentinel")?(x={},t[4]=x):x=t[4];let p=U(L.maskPolicies,x),v;t[5]===Symbol.for("react.memo_cache_sentinel")?(v={},t[5]=v):v=t[5];let b=U(L.getAdvisories,v),N;if(t[6]!==b.data||t[7]!==p.data||t[8]!==r||t[9]!==i||t[10]!==s){let g=null;i.data!==void 0&&(g=Array.isArray(i.data.policies)?i.data.policies:[]);let _=Array.isArray(p.data?.columns)?p.data.columns:[],F=b.data??null,{error:h,errorSource:m,liveError:P}=i,A=g===null?[]:be(g,_,ge(F)),T;t[12]!==P?(T=(0,e.jsxDEV)("div",{className:"flex items-center justify-end",children:(0,e.jsxDEV)(le,{message:P,prefix:"pm"},void 0,!1)},void 0,!1),t[12]=P,t[13]=T):T=t[13];let y;t[14]!==h||t[15]!==m?(y=h!==null&&(0,e.jsxDEV)(te,{error:m,testId:"pm-error"},void 0,!1),t[14]=h,t[15]=m,t[16]=y):y=t[16],N=(0,e.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-matrix",children:[T,y,g!==null&&A.length===0?(0,e.jsxDEV)(J,{description:s("Add a `definePolicy` and wire it through `.use(rls(...))` to populate this matrix."),testId:"pm-empty",title:s("No policy")},void 0,!1):(0,e.jsxDEV)(ae,{"data-testid":"pm-table",children:[(0,e.jsxDEV)(se,{children:(0,e.jsxDEV)(Q,{children:[(0,e.jsxDEV)($,{children:s("Table")},void 0,!1),ie.map(u=>(0,e.jsxDEV)($,{children:ye(s,u)},u,!1)),(0,e.jsxDEV)($,{children:s("Masked columns")},void 0,!1)]},void 0,!0)},void 0,!1),(0,e.jsxDEV)(oe,{children:A.map(u=>(0,e.jsxDEV)(Q,{"data-testid":`pm-row-${u.table}`,children:[(0,e.jsxDEV)(z,{className:"font-mono text-xs",children:(0,e.jsxDEV)("span",{className:"flex items-center gap-1.5",children:[u.table,u.uncovered&&(0,e.jsxDEV)(I,{"data-testid":`pm-uncovered-${u.table}`,title:s("Uncovered \u2014 reachable without a policy"),variant:"destructive",children:s("Uncovered \u2014 reachable without a policy")},void 0,!1)]},void 0,!0)},void 0,!1),ie.map(w=>{let R=u.cells[w];return(0,e.jsxDEV)(z,{"data-testid":`pm-cell-${u.table}-${w}`,children:R.procedure===void 0?(0,e.jsxDEV)("span",{className:"text-xs text-muted-foreground",children:s("No policy")},void 0,!1):(0,e.jsxDEV)("span",{className:"flex flex-col gap-1",children:[(0,e.jsxDEV)(I,{variant:"secondary",children:s("Covered by {procedure}",{procedure:R.procedure})},void 0,!1),r!==void 0&&(0,e.jsxDEV)(k,{className:"h-auto justify-start p-0 text-[11px]","data-testid":`pm-probe-${u.table}-${w}`,onClick:n(()=>{r(u.table,w,R.procedure??"")},"onClick"),size:"xs",type:"button",variant:"ghost",children:s("Probe this")},void 0,!1)]},void 0,!0)},w,!1)}),(0,e.jsxDEV)(z,{children:u.maskedColumns.length===0?(0,e.jsxDEV)("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"\u2014"},void 0,!1):(0,e.jsxDEV)("span",{className:"flex flex-wrap gap-1",children:u.maskedColumns.map(ke)},void 0,!1)},void 0,!1)]},u.table,!0))},void 0,!1)]},void 0,!0)]},void 0,!0),t[6]=b.data,t[7]=p.data,t[8]=r,t[9]=i,t[10]=s,t[11]=N}else N=t[11];return N},"PermissionsMatrix");function ke(a){return(0,e.jsxDEV)(I,{variant:"outline",children:a},a,!1)}n(ke,"_temp");var Ce=G(L.runAs),we=n(()=>{let a=W();return async({args:t,functionPath:l,shardKey:r="",userId:s})=>{let o=Ce;try{return{kind:"allowed",value:await a.query(o,{args:t,functionPath:l,userId:s},X(r))}}catch(d){return{kind:"denied",message:d instanceof Error?d.message:String(d)}}}},"useRunAsProbe"),Se=n(a=>a===void 0?"undefined":JSON.stringify(a,null,2),"formatValue"),Pe=n(({functions:a,prefill:t,runAsIdentity:l=!1}={})=>{let r=W(),s=O(),o=we(),[d,i]=(0,c.useState)(null),[x,p]=(0,c.useState)(null),v=a??d??[],[b,N]=(0,c.useState)(""),[g,_]=(0,c.useState)("{}"),[F,h]=(0,c.useState)(""),[m,P]=(0,c.useState)(""),[A,T]=(0,c.useState)(!1),[y,u]=(0,c.useState)(null),[w,R]=(0,c.useState)(null),H=(0,c.useRef)(-1);(0,c.useEffect)(()=>{if(a!==void 0)return;let f=!1;return r.listFunctions().then(S=>(f||i(S),S)).catch(S=>{f||p(Z(S))}),()=>{f=!0}},[r,a]),(0,c.useEffect)(()=>{if(t===void 0||H.current===t.nonce)return;H.current=t.nonce;let f=t.functionPath;queueMicrotask(()=>{N(f),u(null)})},[t]);let M=b===""?v[0]?.path??"":b,ce=n(async()=>{if(M==="")return;let f;try{f=g.trim()===""?{}:JSON.parse(g)}catch(S){R(s("Invalid JSON args: {message}",{message:S.message})),u(null);return}R(null),T(!0);try{let S=await o({args:f,functionPath:M,shardKey:F.trim(),userId:m.trim()});u(S)}finally{T(!1)}},"run"),fe=n(()=>{D(ce())},"runOnce"),ue=n(f=>{N(f.target.value)},"onSelectChange"),me=n(f=>{_(f.target.value)},"onArgsChange"),pe=n(f=>{P(f.target.value)},"onUserIdChange");return(0,e.jsxDEV)("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-playground",children:[x!==null&&(0,e.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"pp-discover-error",role:"alert",children:x},void 0,!1),!l&&(0,e.jsxDEV)(J,{description:s("Dev only: runs the selected function as this user over the admin gate so you can test auth and RLS."),testId:"pp-gate",title:s("Set `runAsIdentity` to forge an identity and probe access.")},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-3 rounded-md border border-border p-3",children:[(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)(C,{htmlFor:"pp-function",children:s("Function")},void 0,!1),(0,e.jsxDEV)("select",{"aria-label":s("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","data-testid":"pp-function",id:"pp-function",onChange:ue,value:M,children:v.map(f=>(0,e.jsxDEV)("option",{value:f.path,children:[f.path," (",f.kind,")"]},f.path,!0))},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)(C,{htmlFor:"pp-args",children:s("Arguments")},void 0,!1),(0,e.jsxDEV)(re,{"aria-label":s("Arguments"),className:"font-mono text-xs","data-testid":"pp-args",id:"pp-args",onChange:me,value:g},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(ee,{onChange:h,testId:"pp-shard",value:F},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)(C,{htmlFor:"pp-user",children:s("Run as (userId)")},void 0,!1),(0,e.jsxDEV)(E,{"aria-label":s("Identity (userId) to run as"),className:"font-mono text-xs","data-testid":"pp-user",id:"pp-user",onChange:pe,placeholder:s("Leave empty to run as admin"),value:m},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex items-center gap-2",children:[(0,e.jsxDEV)(k,{"data-testid":"pp-run",disabled:!l||A||M==="",onClick:fe,type:"button",children:s(A?"Probing\u2026":"Run probe")},void 0,!1),m.trim()!==""&&(0,e.jsxDEV)(I,{"data-testid":"pp-as-badge",variant:"secondary",children:s("as {userId}",{userId:m.trim()})},void 0,!1)]},void 0,!0)]},void 0,!0),w!==null&&(0,e.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"pp-args-error",role:"alert",children:w},void 0,!1),y!==null&&y.kind==="allowed"&&(0,e.jsxDEV)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-allowed",children:[(0,e.jsxDEV)(I,{variant:"secondary",children:s("Allowed")},void 0,!1),(0,e.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"pp-result",children:Se(y.value)},void 0,!1)]},void 0,!0),y!==null&&y.kind==="denied"&&(0,e.jsxDEV)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-denied",children:[(0,e.jsxDEV)(I,{variant:"destructive",children:s("Denied")},void 0,!1),(0,e.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"pp-denied",role:"alert",children:y.message},void 0,!1)]},void 0,!0)]},void 0,!0)},"PermissionsPlayground"),Ae="/__lunora/policy-scaffold",Te={"already-wired":"That procedure already has an rls(...) policy wired in.","file-exists":"A policy file with that name already exists \u2014 pick another name or edit it by hand.","invalid-identifier":"Name, table, and policy-set must be plain identifiers (letters, digits, _ or $).","unknown-procedure":"No exported procedure was found at that file path.","unsupported-procedure-shape":"That procedure uses the bare query({\u2026}) form \u2014 convert it to the builder form (c.use(\u2026).query(\u2026)) before wiring RLS."},Ie=n(async a=>{let t=await fetch(Ae,{body:JSON.stringify(a),headers:{"Content-Type":"application/json"},method:"POST"}),l=await t.json();if(l.needsManualEdit===!0)return{kind:"needs-manual-edit",message:l.message??"This change must be made by hand."};if(t.ok)return{diagnostics:l.diagnostics??[],kind:"ok",label:l.fileName??l.exportName??""};let r=l.error;return{kind:"error",message:r===void 0?`policy scaffold failed (${String(t.status)})`:Te[r]??r}},"applyPolicyScaffold"),de={exportName:"",filePath:"",policyName:"",policies:"",tableName:""},Ee=n(()=>{let a=O(),[t,l]=(0,c.useState)(null),[r,s]=(0,c.useState)(!1),[o,d]=(0,c.useState)(null),[i,x]=(0,c.useState)(de),p=n(h=>{let m=h.target.name,{value:P}=h.target;x(A=>({...A,[m]:P}))},"onFieldChange"),v=n(()=>{l(null),x(de)},"reset"),b=n(async h=>{s(!0),d(null);try{let m=await Ie(h);d(m),m.kind==="ok"&&v()}catch(m){d({kind:"error",message:m instanceof Error?m.message:String(m)})}finally{s(!1)}},"submit"),N=n(()=>{D(b({kind:"scaffoldPolicy",name:i.policyName.trim(),table:i.tableName.trim()}))},"onSubmitScaffold"),g=n(()=>{D(b({exportName:i.exportName.trim(),filePath:i.filePath.trim(),kind:"wireRls",policies:i.policies.trim()}))},"onSubmitWire"),_=n(()=>{d(null),l("scaffold")},"openScaffold"),F=n(()=>{d(null),l("wire")},"openWire");return(0,e.jsxDEV)(j,{"data-testid":"policy-scaffolder",size:"sm",children:[(0,e.jsxDEV)(K,{children:[(0,e.jsxDEV)(V,{children:a("Scaffold access rules")},void 0,!1),(0,e.jsxDEV)(Y,{children:a("Writes a new deny-by-default policy file under lunora/, or wires one into a procedure, then reruns codegen. Local dev only.")},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(q,{children:[(0,e.jsxDEV)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsxDEV)(k,{"data-testid":"policy-scaffolder-new",onClick:_,size:"xs",type:"button",variant:t==="scaffold"?"default":"outline",children:a("New policy file")},void 0,!1),(0,e.jsxDEV)(k,{"data-testid":"policy-scaffolder-wire",onClick:F,size:"xs",type:"button",variant:t==="wire"?"default":"outline",children:a("Wire into a procedure")},void 0,!1)]},void 0,!0),t==="scaffold"&&(0,e.jsxDEV)("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-new-form",children:[(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-name",children:a("Policy name")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-name",id:"policy-scaffolder-name",name:"policyName",onChange:p,value:i.policyName},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-table",children:a("Table name")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-table",id:"policy-scaffolder-table",name:"tableName",onChange:p,value:i.tableName},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(k,{"data-testid":"policy-scaffolder-create",disabled:r||i.policyName.trim()===""||i.tableName.trim()==="",onClick:N,size:"xs",type:"button",children:a(r?"Creating\u2026":"Create policy file")},void 0,!1),(0,e.jsxDEV)(k,{onClick:v,size:"xs",type:"button",variant:"ghost",children:a("Cancel")},void 0,!1)]},void 0,!0),t==="wire"&&(0,e.jsxDEV)("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-wire-form",children:[(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-file",children:a("Procedure file path")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-file",id:"policy-scaffolder-file",name:"filePath",onChange:p,value:i.filePath},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-export",children:a("Exported procedure")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-export",id:"policy-scaffolder-export",name:"exportName",onChange:p,value:i.exportName},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,e.jsxDEV)(C,{htmlFor:"policy-scaffolder-policies",children:a("Policy set identifier")},void 0,!1),(0,e.jsxDEV)(E,{"data-testid":"policy-scaffolder-policies",id:"policy-scaffolder-policies",name:"policies",onChange:p,value:i.policies},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(k,{"data-testid":"policy-scaffolder-apply",disabled:r||i.filePath.trim()===""||i.exportName.trim()===""||i.policies.trim()==="",onClick:g,size:"xs",type:"button",children:a(r?"Wiring\u2026":"Wire RLS")},void 0,!1),(0,e.jsxDEV)(k,{onClick:v,size:"xs",type:"button",variant:"ghost",children:a("Cancel")},void 0,!1)]},void 0,!0),o?.kind==="error"&&(0,e.jsxDEV)("p",{className:"mt-3 text-sm text-destructive","data-testid":"policy-scaffolder-error",role:"alert",children:o.message},void 0,!1),o?.kind==="needs-manual-edit"&&(0,e.jsxDEV)("p",{className:"mt-3 text-sm text-amber-600 dark:text-amber-500","data-testid":"policy-scaffolder-manual",role:"alert",children:a("This change must be made by hand \u2014 the scaffolder only adds new, deny-by-default rules.")},void 0,!1),o?.kind==="ok"&&(0,e.jsxDEV)("div",{className:"mt-3 flex flex-col gap-1","data-testid":"policy-scaffolder-ok",children:[(0,e.jsxDEV)("p",{className:"text-sm text-emerald-600 dark:text-emerald-500",children:a("Scaffolded {label} and reran codegen. Fill in the `when` predicates before relying on it.",{label:o.label})},void 0,!1),o.diagnostics.length>0&&(0,e.jsxDEV)("ul",{className:"flex flex-col gap-0.5","data-testid":"policy-scaffolder-diagnostics",children:o.diagnostics.map(h=>(0,e.jsxDEV)("li",{className:"font-mono text-[11px] text-destructive",children:h},h,!1))},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0)},"PolicyScaffolder"),He=n(({functions:a,runAsIdentity:t=!1,schemaEditable:l=!1}={})=>{let r=O(),[s,o]=(0,c.useState)(void 0),d=n((i,x,p)=>{p!==""&&o(v=>({functionPath:p,nonce:(v?.nonce??0)+1}))},"onProbe");return(0,e.jsxDEV)("div",{className:"flex flex-col gap-8","data-testid":"lunora-permissions",children:[(0,e.jsxDEV)("section",{className:"flex flex-col gap-3",children:[(0,e.jsxDEV)("header",{className:"border-b border-border px-4 py-3",children:(0,e.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Permissions")},void 0,!1)},void 0,!1),(0,e.jsxDEV)(Ne,{onProbe:d},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("section",{className:"flex flex-col gap-3",children:(0,e.jsxDEV)(j,{className:"gap-0 py-0",children:[(0,e.jsxDEV)("header",{className:"border-b border-border px-4 py-3",children:(0,e.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Probe")},void 0,!1)},void 0,!1),(0,e.jsxDEV)(q,{className:"px-4 py-4",children:[(0,e.jsxDEV)("p",{className:"mb-3 text-sm text-muted-foreground",children:r("Pick a function and an identity, then run it to see the access outcome.")},void 0,!1),(0,e.jsxDEV)(Pe,{functions:a,prefill:s,runAsIdentity:t},void 0,!1)]},void 0,!0)]},void 0,!0)},void 0,!1),l&&(0,e.jsxDEV)("section",{className:"flex flex-col gap-2",children:(0,e.jsxDEV)(Ee,{},void 0,!1)},void 0,!1)]},void 0,!0)},"PermissionsPanel");export{He as PermissionsPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as V}from"./chunk-VLXV72QE.js";import{a as g}from"./chunk-JSEXCW5Q.js";import{a as z}from"./chunk-
|
|
1
|
+
import{a as V}from"./chunk-VLXV72QE.js";import{a as g}from"./chunk-JSEXCW5Q.js";import{a as z}from"./chunk-UKDJ4H7I.js";import{b as q}from"./chunk-TBMYIZIO.js";import{R as j}from"./chunk-3CJW6NWG.js";import{c as p}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as P}from"./chunk-BOXSWNXZ.js";import{b as w}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{f as L}from"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as U,e as B,g as J,k as K,o as M}from"./chunk-E75ANNWX.js";import"./chunk-GMSGZDDH.js";import{a,e as D,f as oe,h as ne}from"./chunk-RRCPZMC2.js";var n=D(oe(),1);var t=D(ne(),1);var ie=a(r=>r.kind==="id"?r.table===void 0?"id":`id<${r.table}>`:r.kind==="array"?r.element===void 0?"array":`${r.element}[]`:r.kind,"argumentType"),de=a(r=>r===void 0||r.length===0?"()":`(${r.map(l=>`${l.name}${l.optional?"?":""}: ${ie(l)}`).join(", ")})`,"formatSignature"),le=a(r=>{switch(r){case"array":return[];case"bigint":case"number":return 0;case"boolean":return!1;case"object":case"record":return{};default:return""}},"placeholderValue"),ce=a(r=>{let l={};for(let s of r??[])s.optional||(l[s.name]=le(s.kind));return JSON.stringify(l,void 0,2)},"argumentsTemplate"),ue=B(P.runAs),fe=10,me=a(r=>r===void 0?"undefined":JSON.stringify(r,null,2),"formatResult"),Ie=a(({functions:r,runAsIdentity:l=!1}={})=>{let s=U(),c=L(),[H,X]=(0,n.useState)(null),[k,Y]=(0,n.useState)(null),x=r??H??[],[R,I]=(0,n.useState)(""),[f,b]=(0,n.useState)("{}"),[u,A]=(0,n.useState)(""),[m,G]=(0,n.useState)(""),[N,h]=(0,n.useState)("idle"),[Q,y]=(0,n.useState)(void 0),[C,S]=(0,n.useState)(null),[T,W]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(r!==void 0)return;let e=!1;return c.listFunctions().then(i=>(e||X(i),i)).catch(i=>{e||Y(J(i))}),()=>{e=!0}},[c,r]);let F=R===""?x[0]?.path??"":R,o=x.find(e=>e.path===F),Z=a(async()=>{if(!o)return;let e;try{e=f.trim()===""?{}:JSON.parse(f)}catch(d){h("error"),y(void 0),S(s("Invalid JSON args: {message}",{message:d.message}));return}let i={__lunoraRef:o.path},v=u.trim()===""?{}:{shardKey:u.trim()},$=l?m.trim():"",E=a(d=>{W(O=>[{argsText:f,at:Date.now(),id:(O[0]?.id??0)+1,kind:o.kind,path:o.path,shardKey:u,status:d},...O].slice(0,fe))},"record");h("running"),S(null);try{let d;if($==="")switch(o.kind){case"action":{d=await c.action(i,e,v);break}case"mutation":{d=await c.mutation(i,e,v);break}default:d=await c.query(i,e,v)}else d=await c.query(ue,{args:e,functionPath:o.path,userId:$},v);q(u),y(d),h("success"),E("success")}catch(d){y(void 0),S(d.message),h("error"),E("error")}},"run"),_=a(e=>{I(e.path),b(e.argsText),A(e.shardKey)},"loadRun"),ee=a(e=>{I(e.target.value)},"onSelectChange"),te=a(e=>{b(e.target.value)},"onArgsChange"),re=a(e=>{G(e.target.value)},"onRunAsChange"),se=a(()=>{K(Z())},"runOnce"),ae=a(()=>{b(ce(o?.args))},"prefillArgs");return(0,t.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-runner",children:[k!==null&&(0,t.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"function-discover-error",role:"alert",children:k},void 0,!1),(0,t.jsxDEV)("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4",children:[(0,t.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,t.jsxDEV)(g,{htmlFor:"function-select",children:s("Function")},void 0,!1),(0,t.jsxDEV)("select",{"aria-label":s("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50","data-testid":"function-select",id:"function-select",onChange:ee,value:F,children:x.map(e=>(0,t.jsxDEV)("option",{value:e.path,children:[e.path," (",e.kind,")"]},e.path,!0))},void 0,!1),o!==void 0&&(0,t.jsxDEV)("p",{className:"text-xs text-muted-foreground",children:[(0,t.jsxDEV)("span",{className:"mr-1.5 font-medium",children:s("Signature")},void 0,!1),(0,t.jsxDEV)("code",{className:"font-mono","data-testid":"function-signature",children:de(o.args)},void 0,!1)]},void 0,!0)]},void 0,!0),(0,t.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,t.jsxDEV)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxDEV)(g,{htmlFor:"args-input",children:s("Arguments")},void 0,!1),(0,t.jsxDEV)(p,{"data-testid":"prefill-button",disabled:o===void 0,onClick:ae,size:"xs",type:"button",variant:"ghost",children:s("Prefill")},void 0,!1)]},void 0,!0),(0,t.jsxDEV)(V,{"aria-label":s("Arguments"),className:"font-mono text-xs","data-testid":"args-input",id:"args-input",onChange:te,value:f},void 0,!1)]},void 0,!0),(0,t.jsxDEV)(z,{onChange:A,testId:"shard-input",value:u},void 0,!1),l&&(0,t.jsxDEV)("div",{className:"flex flex-col gap-1.5","data-testid":"run-as-field",children:[(0,t.jsxDEV)(g,{htmlFor:"run-as-input",children:s("Run as identity (userId)")},void 0,!1),(0,t.jsxDEV)(j,{"aria-label":s("Run as identity (userId)"),className:"font-mono text-xs","data-testid":"run-as-input",id:"run-as-input",onChange:re,placeholder:s("Leave empty to run as admin"),value:m},void 0,!1),(0,t.jsxDEV)("p",{className:"text-[11px] text-muted-foreground",children:s("Dev only: runs the function as this user so you can test auth and RLS. Forged over the admin gate.")},void 0,!1)]},void 0,!0),(0,t.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsxDEV)(p,{"data-testid":"run-button",disabled:N==="running"||o===void 0,onClick:se,type:"button",children:s("Run")},void 0,!1),o!==void 0&&(0,t.jsxDEV)(w,{variant:"outline",children:o.kind},void 0,!1),l&&m.trim()!==""&&(0,t.jsxDEV)(w,{"data-testid":"run-as-badge",variant:"secondary",children:s("as {userId}",{userId:m.trim()})},void 0,!1)]},void 0,!0)]},void 0,!0),N==="error"&&C!==null&&(0,t.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"error",role:"alert",children:C},void 0,!1),N==="success"&&(0,t.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"result",children:me(Q)},void 0,!1),T.length>0&&(0,t.jsxDEV)("ul",{className:"flex flex-col overflow-hidden rounded-xl border border-border","data-testid":"fn-history",children:T.map((e,i)=>(0,t.jsxDEV)("li",{className:"flex flex-wrap items-center gap-2 border-b border-border px-3 py-2 text-sm last:border-b-0","data-testid":"fn-history-row",children:[(0,t.jsxDEV)("span",{className:e.status==="success"?"text-success":"text-destructive","data-testid":`fn-history-status-${i.toString()}`,children:e.status==="success"?"\u2713":"\u2717"},void 0,!1)," ",(0,t.jsxDEV)("span",{className:"font-mono text-xs",children:[e.path," (",e.kind,")"]},void 0,!0)," ",(0,t.jsxDEV)("time",{className:"text-xs text-muted-foreground",children:M(e.at)},void 0,!1)," ",(0,t.jsxDEV)(p,{className:"ml-auto","data-testid":`fn-history-load-${i.toString()}`,onClick:a(()=>{_(e)},"onClick"),size:"xs",type:"button",variant:"ghost",children:s("Load")},void 0,!1)]},e.id,!0))},void 0,!1)]},void 0,!0)},"FunctionRunner");export{Ie as FunctionRunner};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as k,b as j}from"./chunk-KJJ3WM6H.js";import{a as D}from"./chunk-
|
|
1
|
+
import{a as k,b as j}from"./chunk-KJJ3WM6H.js";import{a as D}from"./chunk-UGUEC6BC.js";import{a as O}from"./chunk-2K47A3P6.js";import{a as V}from"./chunk-CACB34RQ.js";import"./chunk-XNJNSCLM.js";import{a as _,b as z,c as B,d as f,e as l,f as n}from"./chunk-GTM65MVX.js";import{a as M}from"./chunk-UKDJ4H7I.js";import"./chunk-TBMYIZIO.js";import{R as L}from"./chunk-3CJW6NWG.js";import"./chunk-O3NAGRTR.js";import"./chunk-HV7G6DFP.js";import{a as H}from"./chunk-BOXSWNXZ.js";import{a as I}from"./chunk-TAD43CG5.js";import{b as A}from"./chunk-C7WTJLC3.js";import{a as y,e as E}from"./chunk-SEU5V7I6.js";import{b as T}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import"./chunk-GLUNBZRI.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as C,o as R}from"./chunk-E75ANNWX.js";import"./chunk-GMSGZDDH.js";import{a as i,e as w,f as ee,h as te}from"./chunk-RRCPZMC2.js";var o=w(ee(),1);var e=w(te(),1);var K=80,ae=i(s=>{if(s===void 0)return"";let t=JSON.stringify(s);return t.length>K?`${t.slice(0,K)}\u2026`:t},"formatDetail"),re=41,F=480,U=5,oe=i((s,t)=>k(s,d=>{t(d.height>0?d:{height:F,width:d.width})}),"observeViewportRect"),Se=i(({initialShardKey:s})=>{let t=C(),[d,G]=(0,o.useState)(s??""),[m,W]=(0,o.useState)(""),q=O(d.trim(),400),{data:v,error:p,errorSource:J,isLoading:P,liveError:Q}=A(H.getAuditLog,{},{live:!0,shardKey:q}),u=(0,o.useMemo)(()=>v?.entries??[],[v]),c=(0,o.useMemo)(()=>{let r=m.trim().toLowerCase();return r===""?u:u.filter(a=>a.op.toLowerCase().includes(r)||(a.table??"").toLowerCase().includes(r)||(a.id??"").toLowerCase().includes(r))},[u,m]),g=(0,o.useRef)(null),x=j({count:c.length,estimateSize:i(()=>re,"estimateSize"),getScrollElement:i(()=>g.current,"getScrollElement"),initialRect:{height:F,width:800},observeElementRect:oe,overscan:8}),h=x.getVirtualItems(),X=x.getTotalSize(),S=h[0]?.start??0,b=X-(h.at(-1)?.end??0),Z={height:S},$={height:b},Y=i(r=>{W(r.target.value)},"onSearchChange");return(0,e.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-audit",children:[(0,e.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsxDEV)(M,{onChange:G,testId:"au-shard-input",value:d},void 0,!1),(0,e.jsxDEV)(D,{message:Q,prefix:"au"},void 0,!1),(0,e.jsxDEV)(L,{"aria-label":t("Filter audit log"),className:"h-8 w-48","data-testid":"au-search",onChange:Y,placeholder:t("filter op, table, id"),value:m},void 0,!1)]},void 0,!0),p!==null&&(0,e.jsxDEV)(V,{error:J,testId:"au-error"},void 0,!1),p===null&&!P&&c.length===0&&(0,e.jsxDEV)(I,{description:t("State-changing admin operations are recorded 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:"M8 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2h-2M9 3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1V3Zm-1 9h8m-8 4h5"},void 0,!1)},void 0,!1),testId:"au-empty",title:t("No audit entries.")},void 0,!1),c.length>0&&(0,e.jsxDEV)(y,{className:"overflow-hidden py-0",children:(0,e.jsxDEV)(E,{className:"max-h-[30rem] overflow-auto px-0",ref:g,children:(0,e.jsxDEV)(_,{"data-testid":"au-table",children:[(0,e.jsxDEV)(z,{children:(0,e.jsxDEV)(f,{children:[(0,e.jsxDEV)(l,{children:t("time")},void 0,!1),(0,e.jsxDEV)(l,{children:t("op")},void 0,!1),(0,e.jsxDEV)(l,{children:t("table")},void 0,!1),(0,e.jsxDEV)(l,{children:t("id")},void 0,!1),(0,e.jsxDEV)(l,{children:t("detail")},void 0,!1)]},void 0,!0)},void 0,!1),(0,e.jsxDEV)(B,{children:[S>0&&(0,e.jsxDEV)("tr",{"aria-hidden":"true",children:(0,e.jsxDEV)("td",{colSpan:U,style:Z},void 0,!1)},void 0,!1),h.map(r=>{let a=c[r.index],N=ae(a.detail);return(0,e.jsxDEV)(f,{"data-testid":"au-row",children:[(0,e.jsxDEV)(n,{className:"text-muted-foreground tabular-nums",children:R(a.ts,"\u2014")},void 0,!1),(0,e.jsxDEV)(n,{children:(0,e.jsxDEV)(T,{variant:"secondary",children:a.op},void 0,!1)},void 0,!1),(0,e.jsxDEV)(n,{className:"font-medium",children:a.table??(0,e.jsxDEV)("span",{className:"text-muted-foreground",children:"\u2014"},void 0,!1)},void 0,!1),(0,e.jsxDEV)(n,{className:"max-w-[20ch] truncate font-mono text-xs",children:a.id??(0,e.jsxDEV)("span",{className:"text-muted-foreground",children:"\u2014"},void 0,!1)},void 0,!1),(0,e.jsxDEV)(n,{className:"max-w-[32ch] truncate font-mono text-xs text-muted-foreground",title:N||void 0,children:N||(0,e.jsxDEV)("span",{className:"text-muted-foreground",children:"\u2014"},void 0,!1)},void 0,!1)]},a.seq,!0)}),b>0&&(0,e.jsxDEV)("tr",{"aria-hidden":"true",children:(0,e.jsxDEV)("td",{colSpan:U,style:$},void 0,!1)},void 0,!1)]},void 0,!0)]},void 0,!0)},void 0,!1)},void 0,!1)]},void 0,!0)},"AuditPanel");export{Se as AuditPanel};
|