@lunora/studio 1.0.0-alpha.196 → 1.0.0-alpha.197

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/index.d.mts +1 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_chunks/TableEditor.mjs +1 -1
  5. package/dist/packem_shared/{DataBrowser-zqK4s0IE.mjs → DataBrowser-DLRa1EYq.mjs} +2 -2
  6. package/dist/standalone/{chunk-HYGZWDB7.js → chunk-27KDQM4D.js} +1 -1
  7. package/dist/standalone/{chunk-4HGB4HWB.js → chunk-2DEL2YBJ.js} +1 -1
  8. package/dist/standalone/{chunk-425GLFP3.js → chunk-2OA2FSFF.js} +1 -1
  9. package/dist/standalone/{chunk-HZ6TVAF3.js → chunk-2VRLRPX7.js} +1 -1
  10. package/dist/standalone/{chunk-PJKHJCIC.js → chunk-3ATTKBAS.js} +1 -1
  11. package/dist/standalone/{chunk-NXUZEDGK.js → chunk-4NDUMJBO.js} +1 -1
  12. package/dist/standalone/{chunk-OGJEN75K.js → chunk-55ZSYJIW.js} +1 -1
  13. package/dist/standalone/{chunk-GCQEUAKS.js → chunk-5BTKGXYJ.js} +1 -1
  14. package/dist/standalone/{chunk-TTDW3FTR.js → chunk-5P5R4K4G.js} +1 -1
  15. package/dist/standalone/{chunk-H5AIVPUF.js → chunk-5ZPM37G7.js} +1 -1
  16. package/dist/standalone/{chunk-GOJ5JCTC.js → chunk-6VSUIO3X.js} +1 -1
  17. package/dist/standalone/{chunk-DAAUTRQE.js → chunk-ACZIA4KX.js} +1 -1
  18. package/dist/standalone/chunk-B4YYP5AH.js +11 -0
  19. package/dist/standalone/{chunk-ISCGWWET.js → chunk-BKM6EMBQ.js} +1 -1
  20. package/dist/standalone/{chunk-VDKL2SKM.js → chunk-BX72LN2S.js} +1 -1
  21. package/dist/standalone/{chunk-HARUS64R.js → chunk-DUS5YSTV.js} +1 -1
  22. package/dist/standalone/{chunk-XBYHPJFP.js → chunk-DW2WPI2K.js} +1 -1
  23. package/dist/standalone/{chunk-I73WRNA2.js → chunk-EKEHGHPT.js} +1 -1
  24. package/dist/standalone/{chunk-GOITJEW6.js → chunk-EWBZPW2U.js} +1 -1
  25. package/dist/standalone/{chunk-R357HINN.js → chunk-FDY2NVBM.js} +1 -1
  26. package/dist/standalone/{chunk-HCFPWTSP.js → chunk-FHYAWPNA.js} +1 -1
  27. package/dist/standalone/{chunk-3DZ6DV43.js → chunk-FZSDIUFA.js} +1 -1
  28. package/dist/standalone/{chunk-IOEBGFXY.js → chunk-GOL6VVKZ.js} +1 -1
  29. package/dist/standalone/{chunk-5RC7EB7G.js → chunk-GYTB4A2M.js} +1 -1
  30. package/dist/standalone/{chunk-3PVQGOWU.js → chunk-HP34OREE.js} +1 -1
  31. package/dist/standalone/{chunk-VCA27V6S.js → chunk-IY3Q4FMI.js} +1 -1
  32. package/dist/standalone/{chunk-MFGX5TG2.js → chunk-LJIHGFHU.js} +1 -1
  33. package/dist/standalone/{chunk-LM4VYHLG.js → chunk-LQI765MA.js} +1 -1
  34. package/dist/standalone/{chunk-SU7LZGWQ.js → chunk-LZIKJ7N4.js} +1 -1
  35. package/dist/standalone/{chunk-IWA4HV64.js → chunk-M2EYXPDX.js} +1 -1
  36. package/dist/standalone/{chunk-MWWJJZMX.js → chunk-MB46H4XH.js} +1 -1
  37. package/dist/standalone/{chunk-EEPI7RD5.js → chunk-MSYDLNH7.js} +1 -1
  38. package/dist/standalone/{chunk-O4K2PC3A.js → chunk-OTYTU5PT.js} +1 -1
  39. package/dist/standalone/{chunk-UYS6VVJA.js → chunk-OZF6QK5O.js} +1 -1
  40. package/dist/standalone/{chunk-GM5ADIIU.js → chunk-PCHMHMHE.js} +1 -1
  41. package/dist/standalone/{chunk-S2A6CARX.js → chunk-PD7H5BKL.js} +1 -1
  42. package/dist/standalone/{chunk-X3CZFQ62.js → chunk-PLDXUMLT.js} +1 -1
  43. package/dist/standalone/{chunk-7TDTNXSJ.js → chunk-QIXW4S4K.js} +1 -1
  44. package/dist/standalone/{chunk-2LUUF5RM.js → chunk-QY54P54V.js} +1 -1
  45. package/dist/standalone/{chunk-TGEC4TTH.js → chunk-QZM4KMEX.js} +1 -1
  46. package/dist/standalone/{chunk-O47LQ7YR.js → chunk-RIJ5VJGY.js} +1 -1
  47. package/dist/standalone/{chunk-W57FGW32.js → chunk-S2DHKQCI.js} +1 -1
  48. package/dist/standalone/{chunk-ZSKVKBTI.js → chunk-SBJV3HW6.js} +1 -1
  49. package/dist/standalone/{chunk-QWLFFOVP.js → chunk-SSMXYD2M.js} +1 -1
  50. package/dist/standalone/{chunk-56BRFXVG.js → chunk-T2RLHI5N.js} +1 -1
  51. package/dist/standalone/{chunk-4YRBL2BF.js → chunk-T53H5D2A.js} +1 -1
  52. package/dist/standalone/{chunk-OEM2AQSE.js → chunk-UUCBHRSG.js} +1 -1
  53. package/dist/standalone/{chunk-KWLJEG4G.js → chunk-VIIZ5YJB.js} +1 -1
  54. package/dist/standalone/{chunk-7EDZNLVG.js → chunk-VQJD345K.js} +1 -1
  55. package/dist/standalone/{chunk-HKYYSETK.js → chunk-VUXVPYAD.js} +1 -1
  56. package/dist/standalone/{chunk-PKUEXDSC.js → chunk-W3OQPG5Z.js} +1 -1
  57. package/dist/standalone/{chunk-IUOWYLXN.js → chunk-WIJSO6ZU.js} +1 -1
  58. package/dist/standalone/{chunk-CGSVO47H.js → chunk-WYU6OKTT.js} +1 -1
  59. package/dist/standalone/{chunk-JI6MEPCE.js → chunk-XQBWIYQN.js} +1 -1
  60. package/dist/standalone/{chunk-2HTSOS6M.js → chunk-ZA5KJ2E3.js} +3 -3
  61. package/dist/standalone/{chunk-GJH2G5M2.js → chunk-ZW5AIWQO.js} +1 -1
  62. package/dist/standalone/studio.js +1 -1
  63. package/package.json +3 -3
  64. package/dist/standalone/chunk-IL4CKMJM.js +0 -11
@@ -1,4 +1,4 @@
1
- import{c as B}from"react/compiler-runtime";import{useLunora as dt}from"@lunora/react";import{useState as D,useEffect as Be,useMemo as Tt,useRef as Ge,useCallback as it}from"react";import{ShardInput as Mn}from"./ShardInput-C6mjgAh4.mjs";import{u as Xe}from"./use-admin-query-BKXiqLci.mjs";import{ADMIN_FUNCTIONS as pe}from"./ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{b as Qt}from"./browser-storage-BH1MxLZs.mjs";import{f as Ce,i as je,j as Yt,b as Ft,c as Te,d as ke,h as Ln}from"./internal-B6haJbiP.mjs";import{m as Vn,c as Xt,d as vt,G as Bn,a as jn,u as wt,b as zn,T as qn,D as Kn}from"./table-list-sidebar-DHG1UJC4.mjs";import{u as Gn}from"./use-sql-assistant-BhIMDQHV.mjs";import{d as Rt,i as Zt,e as en,a as Jn}from"./wire-codec-Bk4XZGE4.mjs";import{B as yt}from"./button-q0UYSmrn.mjs";import{I as Wn}from"./input-CXhxesPC.mjs";import{L as Mt}from"./label-DKFzyHq6.mjs";import{M as ut}from"./modal-shell-CDztwLnv.mjs";import{useT as he}from"./DEFAULT_LOCALE-A1Yg5ORA.mjs";import{jsx as d,jsxs as E,Fragment as Ze}from"react/jsx-runtime";import{ConfirmButton as Lt}from"./ConfirmButton-DU4p72Er.mjs";import{E as Hn}from"./empty-state-D7jEML_T.mjs";import{C as Et,a as De}from"./control-button-BOZ5K-FC.mjs";import{tableFeatures as Un,sortFn_text as Qn,sortFn_datetime as Yn,sortFn_basic as Xn,sortFn_alphanumeric as Zn,rowSortingFeature as eo,rowSelectionFeature as to,columnVisibilityFeature as no,columnSizingFeature as oo,columnResizingFeature as so,columnOrderingFeature as lo,createSortedRowModel as ro,useTable as ao,flexRender as io}from"@tanstack/react-table";import{useVirtualizer as co}from"@tanstack/react-virtual";import{C as $t}from"./checkbox-CnS9cyCz.mjs";import{c as ct}from"./utils-bhneXptQ.mjs";import{f as uo}from"./virtual-rect-D_j7aLxX.mjs";import{C as Ct,G as fo,T as mo}from"./data-grid-DTBAKZlm.mjs";import{DataFilters as go,toFilterClauses as Fe}from"./DataFilters-Cocu-WWE.mjs";import{G as po,C as bo}from"./grid-features-Dm80ngyR.mjs";import Vt from"./useDebounced-DVeQ5-oW.mjs";import{r as ho,l as xo}from"./shard-history-CaO3C4KQ.mjs";const vo=s=>({tables:Object.entries(s).map(([e,n])=>({fields:n.map(o=>o.name),indexes:[],name:e,relations:n.filter(o=>o.ref!==void 0).map(o=>({field:o.name,kind:"one",name:o.name,onDelete:o.onDelete,references:o.ref,table:e}))}))}),wo=s=>{const e=new Map,n=new Set;for(const o of s.tables)for(const t of o.relations){if(t.kind!=="one"||t.onDelete==="set null")continue;const c=t.references,l=`${c}\0${o.name}\0${t.field}`;if(n.has(l))continue;n.add(l);const r=e.get(c)??[];r.push({...t,table:o.name}),e.set(c,r)}return e},yo=(s,e)=>{const n=[],o=[s];for(;o.length>0;){const t=o.shift();if(t===void 0)break;e(t)&&n.push(t);for(const c of t.children)o.push(c)}return n},Bt=(s,e)=>{const n=[];for(const[o,t]of Object.entries(e))for(const c of t)c.ref===s&&n.push({column:c.name,table:o});return n.sort((o,t)=>o.table.localeCompare(t.table)||o.column.localeCompare(t.column)),n},Dt=s=>`${s.table}.${s.column}`,Co=s=>{const e=B(111),{columns:n,onApply:o,onClose:t,shardKey:c,table:l,total:r,uniqueColumns:a}=s,i=he(),[m,f]=D(n[0]??""),[p,b]=D("");let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=ee=>{f(ee.target.value)},e[0]=u):u=e[0];const g=u;let h;e[1]===Symbol.for("react.memo_cache_sentinel")?(h=ee=>{b(ee.target.value)},e[1]=h):h=e[1];const x=h;let v;e[2]!==p?(v=p.trim(),e[2]=p,e[3]=v):v=e[3];const y=v==="";let C,N;if(e[4]!==y||e[5]!==i||e[6]!==p){if(!y)try{N=Rt(JSON.parse(p))}catch(ee){C=i("Invalid JSON: {message}",{message:ee.message})}e[4]=y,e[5]=i,e[6]=p,e[7]=C,e[8]=N}else C=e[7],N=e[8];let k;e[9]!==m||e[10]!==r||e[11]!==a?(k=a.has(m)&&r>1,e[9]=m,e[10]=r,e[11]=a,e[12]=k):k=e[12];const S=k,w=m!==""&&!y&&C===void 0&&!S;let T;e[13]!==w||e[14]!==m||e[15]!==o||e[16]!==t||e[17]!==N?(T=()=>{w&&(o({[m]:N}),t())},e[13]=w,e[14]=m,e[15]=o,e[16]=t,e[17]=N,e[18]=T):T=e[18];const I=T;let R;e[19]!==i?(R=i("Set a column on matching rows"),e[19]=i,e[20]=R):R=e[20];let _;e[21]!==i?(_=i("Set a column on matching rows"),e[21]=i,e[22]=_):_=e[22];let $;e[23]!==_?($=d("h3",{className:"text-base text-foreground","data-testid":"bulk-patch-title",children:_}),e[23]=_,e[24]=$):$=e[24];let O;e[25]!==i||e[26]!==l||e[27]!==r?(O=i("Writes {total} rows of {table} through the schema-aware writer — validators and indexes apply, exactly like a mutation.",{table:l,total:r.toString()}),e[25]=i,e[26]=l,e[27]=r,e[28]=O):O=e[28];let M;e[29]!==O?(M=d("p",{className:"text-xs text-muted-foreground","data-testid":"bulk-patch-desc",children:O}),e[29]=O,e[30]=M):M=e[30];let P;e[31]!==c||e[32]!==i?(P=c===""?i("Shard: root"):i("Shard: {shardKey} — rows in other shards are not touched.",{shardKey:c}),e[31]=c,e[32]=i,e[33]=P):P=e[33];let z;e[34]!==P?(z=d("p",{className:"text-xs text-muted-foreground","data-testid":"bulk-patch-shard",children:P}),e[34]=P,e[35]=z):z=e[35];let q;e[36]!==M||e[37]!==z||e[38]!==$?(q=E("div",{className:"flex flex-col gap-0.5",children:[$,M,z]}),e[36]=M,e[37]=z,e[38]=$,e[39]=q):q=e[39];let F;e[40]!==i?(F=i("Close"),e[40]=i,e[41]=F):F=e[41];let V;e[42]!==t||e[43]!==F?(V=d(yt,{"data-testid":"bulk-patch-close",onClick:t,size:"xs",variant:"ghost",children:F}),e[42]=t,e[43]=F,e[44]=V):V=e[44];let J;e[45]!==q||e[46]!==V?(J=E("div",{className:"flex items-start justify-between",children:[q,V]}),e[45]=q,e[46]=V,e[47]=J):J=e[47];let K;e[48]!==i?(K=i("Column"),e[48]=i,e[49]=K):K=e[49];let Z;e[50]!==K?(Z=d(Mt,{htmlFor:"bulk-patch-column",children:K}),e[50]=K,e[51]=Z):Z=e[51];let Y;e[52]!==i?(Y=i("Column"),e[52]=i,e[53]=Y):Y=e[53];let Q;e[54]!==n?(Q=n.map(No),e[54]=n,e[55]=Q):Q=e[55];let ne;e[56]!==m||e[57]!==Y||e[58]!==Q?(ne=d("select",{"aria-label":Y,className:"h-8 rounded-md border border-input bg-transparent px-2 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 dark:bg-input/30","data-testid":"bulk-patch-column",id:"bulk-patch-column",onChange:g,value:m,children:Q}),e[56]=m,e[57]=Y,e[58]=Q,e[59]=ne):ne=e[59];let oe;e[60]!==i?(oe=i("Value"),e[60]=i,e[61]=oe):oe=e[61];let de;e[62]!==oe?(de=d(Mt,{htmlFor:"bulk-patch-value",children:oe}),e[62]=oe,e[63]=de):de=e[63];let ue;e[64]!==p?(ue=d(Wn,{className:"flex-1 font-mono","data-testid":"bulk-patch-value",id:"bulk-patch-value",onChange:x,placeholder:"true",value:p}),e[64]=p,e[65]=ue):ue=e[65];let me;e[66]!==Z||e[67]!==ne||e[68]!==de||e[69]!==ue?(me=E("div",{className:"flex items-center gap-2",children:[Z,ne,de,ue]}),e[66]=Z,e[67]=ne,e[68]=de,e[69]=ue,e[70]=me):me=e[70];let re;e[71]!==C?(re=C!==void 0&&d("p",{className:"text-xs text-destructive","data-testid":"bulk-patch-error",role:"alert",children:C}),e[71]=C,e[72]=re):re=e[72];let fe;e[73]!==m||e[74]!==i||e[75]!==r||e[76]!==S?(fe=S&&d("p",{className:"text-xs text-destructive","data-testid":"bulk-patch-unique",role:"alert",children:i("{column} has a unique index — the same value cannot be set on {total} rows.",{column:m,total:r.toString()})}),e[73]=m,e[74]=i,e[75]=r,e[76]=S,e[77]=fe):fe=e[77];let ae;e[78]!==y||e[79]!==i||e[80]!==S?(ae=y&&!S&&d("p",{className:"text-xs text-muted-foreground","data-testid":"bulk-patch-hint",children:i('Enter a JSON value — for example true, 0, null, or "done".')}),e[78]=y,e[79]=i,e[80]=S,e[81]=ae):ae=e[81];let X;e[82]!==w||e[83]!==m||e[84]!==p?(X=w&&d("p",{className:"font-mono text-xs text-muted-foreground","data-testid":"bulk-patch-preview",children:`${m} = ${p.trim()}`}),e[82]=w,e[83]=m,e[84]=p,e[85]=X):X=e[85];let be;e[86]!==i?(be=i("Cancel"),e[86]=i,e[87]=be):be=e[87];let te;e[88]!==t||e[89]!==be?(te=d(yt,{"data-testid":"bulk-patch-cancel",onClick:t,size:"xs",variant:"outline",children:be}),e[88]=t,e[89]=be,e[90]=te):te=e[90];const xe=!w;let ie;e[91]!==i||e[92]!==r?(ie=i("Set on {total} rows",{total:r.toString()}),e[91]=i,e[92]=r,e[93]=ie):ie=e[93];let ce;e[94]!==I||e[95]!==xe||e[96]!==ie?(ce=d(yt,{"data-testid":"bulk-patch-apply",disabled:xe,onClick:I,size:"xs",children:ie}),e[94]=I,e[95]=xe,e[96]=ie,e[97]=ce):ce=e[97];let W;e[98]!==te||e[99]!==ce?(W=E("div",{className:"flex justify-end gap-2",children:[te,ce]}),e[98]=te,e[99]=ce,e[100]=W):W=e[100];let G;return e[101]!==t||e[102]!==J||e[103]!==me||e[104]!==re||e[105]!==fe||e[106]!==ae||e[107]!==X||e[108]!==W||e[109]!==R?(G=E(ut,{label:R,onClose:t,panelTestId:"bulk-patch-panel",testId:"bulk-patch-overlay",variant:"dialog",children:[J,me,re,fe,ae,X,W]}),e[101]=t,e[102]=J,e[103]=me,e[104]=re,e[105]=fe,e[106]=ae,e[107]=X,e[108]=W,e[109]=R,e[110]=G):G=e[110],G};function No(s){return d("option",{value:s,children:s},s)}const jt=6,rt=100,So=s=>({paddingLeft:s*16}),ko=s=>{const e=B(2),{table:n}=s,o=`cascade-restrict-${n}`;let t;return e[0]!==o?(t=d("span",{className:"rounded bg-destructive/10 px-1 text-destructive","data-testid":o,children:"restrict — will block delete"}),e[0]=o,e[1]=t):t=e[1],t},To=s=>{const e=B(2),{table:n}=s,o=`cascade-cascade-${n}`;let t;return e[0]!==o?(t=d("span",{className:"rounded bg-warning/10 px-1 text-warning","data-testid":o,children:"cascade"}),e[0]=o,e[1]=t):t=e[1],t},Eo=s=>{const e=B(2),{table:n}=s,o=`cascade-undeclared-${n}`;let t;return e[0]!==o?(t=d("span",{className:"rounded bg-muted px-1 text-muted-foreground","data-testid":o,children:"references — no delete action declared"}),e[0]=o,e[1]=t):t=e[1],t},_o=s=>s.relation===void 0||s.relation.onDelete==="cascade"?d(To,{table:s.table}):s.isRestrict?d(ko,{table:s.table}):d(Eo,{table:s.table}),tn=s=>{const e=B(35),{depth:n,node:o}=s,t=`cascade-row-${o.table}`;let c;e[0]!==n?(c=So(n),e[0]=n,e[1]=c):c=e[1];let l;e[2]!==n?(l=n>0&&d("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"└"}),e[2]=n,e[3]=l):l=e[3];let r;e[4]!==o.table?(r=d("span",{className:"font-medium text-foreground",children:o.table}),e[4]=o.table,e[5]=r):r=e[5];let a;e[6]!==o.relation||e[7]!==o.table?(a=o.relation!==void 0&&E("span",{className:"text-muted-foreground","data-testid":`cascade-col-${o.table}-${o.relation.field}`,children:["via ",o.relation.field]}),e[6]=o.relation,e[7]=o.table,e[8]=a):a=e[8];let i;e[9]!==o.rowCount?(i=o.rowCount.toString(),e[9]=o.rowCount,e[10]=i):i=e[10];let m;e[11]!==i?(m=E("span",{className:"text-muted-foreground",children:["(",i," rows)"]}),e[11]=i,e[12]=m):m=e[12];let f;e[13]!==o?(f=_o(o),e[13]=o,e[14]=f):f=e[14];let p;e[15]!==o.capNote||e[16]!==o.table?(p=o.capNote!==void 0&&E("span",{className:"italic text-muted-foreground","data-testid":`cascade-cap-${o.table}`,children:["(",o.capNote,")"]}),e[15]=o.capNote,e[16]=o.table,e[17]=p):p=e[17];let b;e[18]!==t||e[19]!==c||e[20]!==l||e[21]!==r||e[22]!==a||e[23]!==m||e[24]!==f||e[25]!==p?(b=E("li",{className:"flex flex-wrap items-center gap-1.5 py-1 font-mono text-xs","data-testid":t,style:c,children:[l,r,a,m,f,p]}),e[18]=t,e[19]=c,e[20]=l,e[21]=r,e[22]=a,e[23]=m,e[24]=f,e[25]=p,e[26]=b):b=e[26];let u;if(e[27]!==n||e[28]!==o.children){let h;e[30]!==n?(h=(x,v)=>d(tn,{depth:n+1,node:x},`${x.table}-${x.relation?.field??"root"}-${v.toString()}`),e[30]=n,e[31]=h):h=e[31],u=o.children.map(h),e[27]=n,e[28]=o.children,e[29]=u}else u=e[29];let g;return e[32]!==b||e[33]!==u?(g=E(Ze,{children:[b,u]}),e[32]=b,e[33]=u,e[34]=g):g=e[34],g},Ro=s=>{const e=s._id??s.id??s.__id__??"";return typeof e=="string"?e:typeof e=="number"?e.toString():""},$o=async(s,e,n,o)=>{try{const t=await o(s,e,n),c=t.rows.flatMap(a=>Ro(a)||[]).slice(0,rt),l=t.total??0;return{capNote:l>rt?`showing first ${rt.toString()} of ${l.toString()}`:void 0,rowCount:l,rowIds:c}}catch{return{capNote:"count unavailable",rowCount:0,rowIds:[]}}},nn=async(s,e,n,o,t,c,l)=>{const{capNote:r,rowCount:a,rowIds:i}=n===void 0?{capNote:void 0,rowCount:1,rowIds:[e]}:await $o(s,n.field,e,l),m=n?.onDelete==="restrict",f=[],p=`${s}:${e}`,b=c>=jt;if(!t.has(p)&&!b){t.add(p);const g=o.get(s)??[];for(const h of g)for(const x of i.slice(0,10)){const v=await nn(h.table,x,h,o,t,c+1,l);(v.rowCount>0||c===0)&&f.push(v)}t.delete(p)}let u=r;if(b){const g=`depth capped at ${jt.toString()}`;u=r===void 0?g:`${r}; ${g}`}return{capNote:u,children:f,isRestrict:m,relation:n,rowCount:a,rowIds:i,table:s}},Do=({onClose:s,onConfirm:e,readPage:n,rowId:o,schema:t,table:c})=>{const l=he(),[r,a]=D(!0),[i,m]=D(null),[f,p]=D(null);Be(()=>{let g=!1;return Ce((async()=>{try{a(!0),p(null);const x=wo(t);if(!((x.get(c)??[]).length>0)){g||(m({capNote:void 0,children:[],isRestrict:!1,relation:void 0,rowCount:1,rowIds:[o],table:c}),a(!1));return}const y=await nn(c,o,void 0,x,new Set,0,n);g||(m(y),a(!1))}catch(x){g||(p(x.message),a(!1))}})()),()=>{g=!0}},[o,c]);const b=i!==null&&yo(i,g=>g.isRestrict).length>0,u=()=>{e(),s()};return E(ut,{label:"Cascade impact preview",onClose:s,panelTestId:"cascade-panel",testId:"cascade-overlay",variant:"dialog",children:[E("div",{className:"flex items-start justify-between",children:[E("div",{className:"flex flex-col gap-0.5",children:[d("h3",{className:"text-base text-foreground","data-testid":"cascade-title",children:l("Cascade impact")}),d("p",{className:"text-xs text-muted-foreground","data-testid":"cascade-desc",children:l("Delete preview — rows that would cascade or be blocked")})]}),d("button",{className:"text-xs text-muted-foreground hover:text-foreground","data-testid":"cascade-close",onClick:s,type:"button",children:l("Close")})]}),r&&d("p",{className:"text-xs text-muted-foreground","data-testid":"cascade-loading",children:l("Loading…")}),f!==null&&d("p",{className:"text-xs text-destructive","data-testid":"cascade-error",role:"alert",children:f}),!r&&i!==null&&d("ul",{className:"flex flex-col","data-testid":"cascade-tree",children:d(tn,{depth:0,node:i})}),!r&&i!==null&&i.children.length===0&&d("p",{className:"text-xs text-muted-foreground","data-testid":"cascade-no-impact",children:l("No related rows found.")}),b&&d("p",{className:"text-sm font-medium text-destructive","data-testid":"cascade-blocker-warning",role:"alert",children:l("Restrict relations will block this delete.")}),E("div",{className:"flex justify-end gap-2",children:[d("button",{className:"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","data-testid":"cascade-cancel",onClick:s,type:"button",children:l("Cancel")}),d("button",{className:"rounded-md bg-destructive px-3 py-1.5 text-xs font-medium text-destructive-foreground outline-none transition-colors hover:bg-destructive/90 focus-visible:bg-destructive/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"cascade-confirm",disabled:r,onClick:u,type:"button",children:l("Delete")})]})]})},Ao=(s,e,n,o,t=300)=>{if(o<=0)return{ids:new Set(s.map(f=>f.id)),leadPx:0,tailPx:0};const c=n-t,l=n+o+t,r=new Set;let a=0,i=0,m=0;for(const f of s){const p=f.getSize(),b=e.has(f.id),u=a+p>c&&a<l;b||u?r.add(f.id):a<c?i+=p:m+=p,a+=p}return{ids:r,leadPx:i,tailPx:m}},Io=(s,e)=>{const n=new Map;let o=0;for(const t of s)e.has(t.id)&&(n.set(t.id,o),o+=t.getSize());return n},Po=Un({columnOrderingFeature:lo,columnResizingFeature:so,columnSizingFeature:oo,columnVisibilityFeature:no,rowSelectionFeature:to,rowSortingFeature:eo,sortedRowModel:ro(),sortFns:{alphanumeric:Zn,basic:Xn,datetime:Yn,text:Qn}}),Oo=()=>{const s=B(12);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e={},s[0]=e):e=s[0];const[n,o]=D(e);let t;s[1]===Symbol.for("react.memo_cache_sentinel")?(t=(g,h,x)=>{o(v=>({...v,[g]:{...v[g],[h]:x}}))},s[1]=t):t=s[1];const c=t;let l;s[2]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{o({})},s[2]=l):l=s[2];const r=l;let a;s[3]===Symbol.for("react.memo_cache_sentinel")?(a=(g,h)=>{o(x=>{const v=x[g];if(v===void 0)return x;const y=Object.fromEntries(Object.entries(v).filter(C=>{const[N,k]=C;return!(N in h)||!Object.is(k,h[N])}));return Object.keys(y).length===0?Object.fromEntries(Object.entries(x).filter(C=>{const[N]=C;return N!==g})):{...x,[g]:y}})},s[3]=a):a=s[3];const i=a;let m;s[4]!==n?(m=(g,h)=>{const x=n[g];return x!==void 0&&h in x?{value:x[h]}:void 0},s[4]=n,s[5]=m):m=s[5];const f=m;let p;s[6]!==n?(p=Object.values(n).reduce(Mo,0),s[6]=n,s[7]=p):p=s[7];const b=p;let u;return s[8]!==b||s[9]!==n||s[10]!==f?(u={clear:r,count:b,drop:i,stage:c,staged:n,stagedValue:f},s[8]=b,s[9]=n,s[10]=f,s[11]=u):u=s[11],u},on=(s,e)=>{if(typeof e=="number"){const n=Number(s);return s.trim()===""||Number.isNaN(n)?s:n}if(typeof e=="boolean"){if(s==="true")return!0;if(s==="false")return!1}return s},Fo=s=>{const e=B(29),{changes:n,committing:o,onCommit:t,onDiscard:c}=s,l=he();let r;e[0]!==n.length||e[1]!==l?(r=l("{count} pending changes",{count:n.length}),e[0]=n.length,e[1]=l,e[2]=r):r=e[2];let a;e[3]!==r?(a=d("span",{className:"font-mono text-[11px] tracking-wide uppercase text-warning","data-testid":"db-staged-count",children:r}),e[3]=r,e[4]=a):a=e[4];let i;e[5]!==o||e[6]!==l?(i=l(o?"Committing…":"Commit"),e[5]=o,e[6]=l,e[7]=i):i=e[7];let m;e[8]!==o||e[9]!==t||e[10]!==i?(m=d("button",{className:"ms-auto rounded-md bg-primary px-2.5 py-1 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":"db-staged-commit",disabled:o,onClick:t,type:"button",children:i}),e[8]=o,e[9]=t,e[10]=i,e[11]=m):m=e[11];let f;e[12]!==l?(f=l("Discard"),e[12]=l,e[13]=f):f=e[13];let p;e[14]!==o||e[15]!==c||e[16]!==f?(p=d("button",{className:"rounded-md border border-border px-2.5 py-1 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":"db-staged-discard",disabled:o,onClick:c,type:"button",children:f}),e[14]=o,e[15]=c,e[16]=f,e[17]=p):p=e[17];let b;e[18]!==a||e[19]!==m||e[20]!==p?(b=E("div",{className:"flex flex-wrap items-center gap-2",children:[a,m,p]}),e[18]=a,e[19]=m,e[20]=p,e[21]=b):b=e[21];let u;e[22]!==n?(u=n.map(Lo),e[22]=n,e[23]=u):u=e[23];let g;e[24]!==u?(g=d("ul",{className:"flex flex-col gap-1","data-testid":"db-staged-list",children:u}),e[24]=u,e[25]=g):g=e[25];let h;return e[26]!==b||e[27]!==g?(h=E("div",{className:"flex flex-col gap-2 border border-warning/40 bg-warning/5 p-3","data-testid":"db-staged",children:[b,g]}),e[26]=b,e[27]=g,e[28]=h):h=e[28],h};function Mo(s,e){return s+Object.keys(e).length}function Lo(s){return E("li",{className:"flex flex-wrap items-center gap-2 font-mono text-xs",children:[E("span",{className:"text-muted-foreground",children:[s.rowId,".",s.column]}),d("span",{className:"text-destructive line-through",children:je(s.oldValue)}),d("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"→"}),d("span",{className:"text-foreground",children:je(s.newValue)})]},`${s.rowId}:${s.column}`)}const zt=400,Vo=36,Bo={flex:"1 1 0%",minHeight:0,overflow:"auto",position:"relative"},jo={width:"100%"},zo=/\n$/u,qo={alignItems:"center",display:"flex",left:0,position:"absolute",top:0,width:"100%"},Ko={display:"flex",width:"100%"},qt={flex:"0 0 8.5rem",padding:"0.375rem 0.75rem"},Go="2.5rem",sn={alignItems:"center",display:"flex",flex:"0 0 2.5rem",justifyContent:"center",left:0,padding:"0.375rem 0",position:"sticky",zIndex:2},At=s=>({flex:"0 0 auto",overflow:"hidden",padding:"0.375rem 0.75rem",position:"relative",textOverflow:"ellipsis",whiteSpace:"nowrap",width:`${s.toString()}px`}),ln=(s,e)=>({...At(s),left:`calc(${Go} + ${e.toString()}px)`,position:"sticky",zIndex:2}),Nt="rounded-md px-2 py-0.5 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50",Jo=(s,e,n)=>e.enabled&&e.columns.has(n)?void 0:s,_t="__back__:",Wo=s=>`${_t}${s.table}.${s.column}`,Ho=s=>{const e=B(3),{counts:n,rowId:o}=s;if(n===void 0){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=d("span",{className:"text-muted-foreground/50",children:"—"}),e[0]=l):l=e[0],l}const t=n[o]??0;let c;return e[1]!==t?(c=d("span",{className:"tabular-nums",children:t}),e[1]=t,e[2]=c):c=e[2],c},Ae=s=>{for(const e of["id","__id__","_id"]){const n=s[e];if(typeof n=="string"||typeof n=="number")return String(n)}return null},Uo=(s,e)=>{if(e.enumValues!==void 0&&e.enumValues.length>0)return e.enumValues.includes(s)||s===""&&e.nullable===!0?{value:s===""?null:s}:void 0;if(e.type==="boolean")return s==="true"||s==="false"?{value:s==="true"}:void 0;if(e.type==="number"){const n=Number(s);return s.trim()===""||!Number.isFinite(n)?void 0:{value:n}}return{value:s}},Qo=(s,e,n)=>{if(n!==void 0&&n.type!=="any")return Uo(s,n);const o=on(s,e);return typeof e=="number"&&typeof o!="number"?void 0:{value:o}},Yo=({anchor:s,columnIds:e,columnMeta:n,editableColumn:o,rows:t,text:c})=>{const l=c.replaceAll(`\r
1
+ import{c as B}from"react/compiler-runtime";import{useLunora as dt}from"@lunora/react";import{useState as D,useEffect as Be,useMemo as Tt,useRef as Ge,useCallback as it}from"react";import{ShardInput as Mn}from"./ShardInput-C6mjgAh4.mjs";import{u as Xe}from"./use-admin-query-BKXiqLci.mjs";import{ADMIN_FUNCTIONS as pe}from"./ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{b as Qt}from"./browser-storage-BH1MxLZs.mjs";import{f as Ce,i as je,j as Yt,b as Ft,c as Te,d as ke,h as Ln}from"./internal-B6haJbiP.mjs";import{m as Vn,c as Xt,d as vt,G as Bn,a as jn,u as wt,b as zn,T as qn,D as Kn}from"./table-list-sidebar-DHG1UJC4.mjs";import{u as Gn}from"./use-sql-assistant-BhIMDQHV.mjs";import{d as Rt,i as Zt,e as en,a as Jn}from"./wire-codec-Bk4XZGE4.mjs";import{B as yt}from"./button-q0UYSmrn.mjs";import{I as Wn}from"./input-CXhxesPC.mjs";import{L as Mt}from"./label-DKFzyHq6.mjs";import{M as ut}from"./modal-shell-CDztwLnv.mjs";import{useT as he}from"./DEFAULT_LOCALE-A1Yg5ORA.mjs";import{jsx as d,jsxs as E,Fragment as Ze}from"react/jsx-runtime";import{ConfirmButton as Lt}from"./ConfirmButton-DU4p72Er.mjs";import{E as Hn}from"./empty-state-D7jEML_T.mjs";import{C as Et,a as De}from"./control-button-BOZ5K-FC.mjs";import{tableFeatures as Un,sortFn_text as Qn,sortFn_datetime as Yn,sortFn_basic as Xn,sortFn_alphanumeric as Zn,rowSortingFeature as eo,rowSelectionFeature as to,columnVisibilityFeature as no,columnSizingFeature as oo,columnResizingFeature as so,columnOrderingFeature as lo,createSortedRowModel as ro,useTable as ao,flexRender as io}from"@tanstack/react-table";import{useVirtualizer as co}from"@tanstack/react-virtual";import{C as $t}from"./checkbox-CnS9cyCz.mjs";import{c as ct}from"./utils-bhneXptQ.mjs";import{f as uo}from"./virtual-rect-D_j7aLxX.mjs";import{C as Ct,G as fo,T as mo}from"./data-grid-DTBAKZlm.mjs";import{DataFilters as go,toFilterClauses as Fe}from"./DataFilters-Cocu-WWE.mjs";import{G as po,C as bo}from"./grid-features-Dm80ngyR.mjs";import Vt from"./useDebounced-DVeQ5-oW.mjs";import{r as ho,l as xo}from"./shard-history-CaO3C4KQ.mjs";const vo=s=>({tables:Object.entries(s).map(([e,n])=>({fields:n.map(o=>o.name),indexes:[],name:e,relations:n.filter(o=>o.ref!==void 0).map(o=>({field:o.name,kind:"one",name:o.name,onDelete:o.onDelete,references:o.ref,table:e}))}))}),wo=s=>{const e=new Map,n=new Set;for(const o of s.tables)for(const t of o.relations){if(t.kind!=="one"||t.onDelete==="set null")continue;const c=t.references,l=`${c}\0${o.name}\0${t.field}`;if(n.has(l))continue;n.add(l);const r=e.get(c)??[];r.push({...t,table:o.name}),e.set(c,r)}return e},yo=(s,e)=>{const n=[],o=[s];for(;o.length>0;){const t=o.shift();if(t===void 0)break;e(t)&&n.push(t);for(const c of t.children)o.push(c)}return n},Bt=(s,e)=>{const n=[];for(const[o,t]of Object.entries(e))for(const c of t)c.ref===s&&n.push({column:c.name,table:o});return n.sort((o,t)=>o.table.localeCompare(t.table)||o.column.localeCompare(t.column)),n},Dt=s=>`${s.table}.${s.column}`,Co=s=>{const e=B(111),{columns:n,onApply:o,onClose:t,shardKey:c,table:l,total:r,uniqueColumns:a}=s,i=he(),[m,f]=D(n[0]??""),[p,b]=D("");let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=ee=>{f(ee.target.value)},e[0]=u):u=e[0];const g=u;let h;e[1]===Symbol.for("react.memo_cache_sentinel")?(h=ee=>{b(ee.target.value)},e[1]=h):h=e[1];const x=h;let v;e[2]!==p?(v=p.trim(),e[2]=p,e[3]=v):v=e[3];const y=v==="";let C,N;if(e[4]!==y||e[5]!==i||e[6]!==p){if(!y)try{N=Rt(JSON.parse(p))}catch(ee){C=i("Invalid JSON: {message}",{message:ee.message})}e[4]=y,e[5]=i,e[6]=p,e[7]=C,e[8]=N}else C=e[7],N=e[8];let k;e[9]!==m||e[10]!==r||e[11]!==a?(k=a.has(m)&&r>1,e[9]=m,e[10]=r,e[11]=a,e[12]=k):k=e[12];const S=k,w=m!==""&&!y&&C===void 0&&!S;let T;e[13]!==w||e[14]!==m||e[15]!==o||e[16]!==t||e[17]!==N?(T=()=>{w&&(o({[m]:N}),t())},e[13]=w,e[14]=m,e[15]=o,e[16]=t,e[17]=N,e[18]=T):T=e[18];const A=T;let R;e[19]!==i?(R=i("Set a column on matching rows"),e[19]=i,e[20]=R):R=e[20];let _;e[21]!==i?(_=i("Set a column on matching rows"),e[21]=i,e[22]=_):_=e[22];let $;e[23]!==_?($=d("h3",{className:"text-base text-foreground","data-testid":"bulk-patch-title",children:_}),e[23]=_,e[24]=$):$=e[24];let O;e[25]!==i||e[26]!==l||e[27]!==r?(O=i("Writes {total} rows of {table} through the schema-aware writer — validators and indexes apply, exactly like a mutation.",{table:l,total:r.toString()}),e[25]=i,e[26]=l,e[27]=r,e[28]=O):O=e[28];let M;e[29]!==O?(M=d("p",{className:"text-xs text-muted-foreground","data-testid":"bulk-patch-desc",children:O}),e[29]=O,e[30]=M):M=e[30];let I;e[31]!==c||e[32]!==i?(I=c===""?i("Shard: root"):i("Shard: {shardKey} — rows in other shards are not touched.",{shardKey:c}),e[31]=c,e[32]=i,e[33]=I):I=e[33];let z;e[34]!==I?(z=d("p",{className:"text-xs text-muted-foreground","data-testid":"bulk-patch-shard",children:I}),e[34]=I,e[35]=z):z=e[35];let q;e[36]!==M||e[37]!==z||e[38]!==$?(q=E("div",{className:"flex flex-col gap-0.5",children:[$,M,z]}),e[36]=M,e[37]=z,e[38]=$,e[39]=q):q=e[39];let F;e[40]!==i?(F=i("Close"),e[40]=i,e[41]=F):F=e[41];let V;e[42]!==t||e[43]!==F?(V=d(yt,{"data-testid":"bulk-patch-close",onClick:t,size:"xs",variant:"ghost",children:F}),e[42]=t,e[43]=F,e[44]=V):V=e[44];let J;e[45]!==q||e[46]!==V?(J=E("div",{className:"flex items-start justify-between",children:[q,V]}),e[45]=q,e[46]=V,e[47]=J):J=e[47];let K;e[48]!==i?(K=i("Column"),e[48]=i,e[49]=K):K=e[49];let Z;e[50]!==K?(Z=d(Mt,{htmlFor:"bulk-patch-column",children:K}),e[50]=K,e[51]=Z):Z=e[51];let Y;e[52]!==i?(Y=i("Column"),e[52]=i,e[53]=Y):Y=e[53];let Q;e[54]!==n?(Q=n.map(No),e[54]=n,e[55]=Q):Q=e[55];let ne;e[56]!==m||e[57]!==Y||e[58]!==Q?(ne=d("select",{"aria-label":Y,className:"h-8 rounded-md border border-input bg-transparent px-2 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 dark:bg-input/30","data-testid":"bulk-patch-column",id:"bulk-patch-column",onChange:g,value:m,children:Q}),e[56]=m,e[57]=Y,e[58]=Q,e[59]=ne):ne=e[59];let oe;e[60]!==i?(oe=i("Value"),e[60]=i,e[61]=oe):oe=e[61];let de;e[62]!==oe?(de=d(Mt,{htmlFor:"bulk-patch-value",children:oe}),e[62]=oe,e[63]=de):de=e[63];let ue;e[64]!==p?(ue=d(Wn,{className:"flex-1 font-mono","data-testid":"bulk-patch-value",id:"bulk-patch-value",onChange:x,placeholder:"true",value:p}),e[64]=p,e[65]=ue):ue=e[65];let me;e[66]!==Z||e[67]!==ne||e[68]!==de||e[69]!==ue?(me=E("div",{className:"flex items-center gap-2",children:[Z,ne,de,ue]}),e[66]=Z,e[67]=ne,e[68]=de,e[69]=ue,e[70]=me):me=e[70];let re;e[71]!==C?(re=C!==void 0&&d("p",{className:"text-xs text-destructive","data-testid":"bulk-patch-error",role:"alert",children:C}),e[71]=C,e[72]=re):re=e[72];let fe;e[73]!==m||e[74]!==i||e[75]!==r||e[76]!==S?(fe=S&&d("p",{className:"text-xs text-destructive","data-testid":"bulk-patch-unique",role:"alert",children:i("{column} has a unique index — the same value cannot be set on {total} rows.",{column:m,total:r.toString()})}),e[73]=m,e[74]=i,e[75]=r,e[76]=S,e[77]=fe):fe=e[77];let ae;e[78]!==y||e[79]!==i||e[80]!==S?(ae=y&&!S&&d("p",{className:"text-xs text-muted-foreground","data-testid":"bulk-patch-hint",children:i('Enter a JSON value — for example true, 0, null, or "done".')}),e[78]=y,e[79]=i,e[80]=S,e[81]=ae):ae=e[81];let X;e[82]!==w||e[83]!==m||e[84]!==p?(X=w&&d("p",{className:"font-mono text-xs text-muted-foreground","data-testid":"bulk-patch-preview",children:`${m} = ${p.trim()}`}),e[82]=w,e[83]=m,e[84]=p,e[85]=X):X=e[85];let be;e[86]!==i?(be=i("Cancel"),e[86]=i,e[87]=be):be=e[87];let te;e[88]!==t||e[89]!==be?(te=d(yt,{"data-testid":"bulk-patch-cancel",onClick:t,size:"xs",variant:"outline",children:be}),e[88]=t,e[89]=be,e[90]=te):te=e[90];const xe=!w;let ie;e[91]!==i||e[92]!==r?(ie=i("Set on {total} rows",{total:r.toString()}),e[91]=i,e[92]=r,e[93]=ie):ie=e[93];let ce;e[94]!==A||e[95]!==xe||e[96]!==ie?(ce=d(yt,{"data-testid":"bulk-patch-apply",disabled:xe,onClick:A,size:"xs",children:ie}),e[94]=A,e[95]=xe,e[96]=ie,e[97]=ce):ce=e[97];let W;e[98]!==te||e[99]!==ce?(W=E("div",{className:"flex justify-end gap-2",children:[te,ce]}),e[98]=te,e[99]=ce,e[100]=W):W=e[100];let G;return e[101]!==t||e[102]!==J||e[103]!==me||e[104]!==re||e[105]!==fe||e[106]!==ae||e[107]!==X||e[108]!==W||e[109]!==R?(G=E(ut,{label:R,onClose:t,panelTestId:"bulk-patch-panel",testId:"bulk-patch-overlay",variant:"dialog",children:[J,me,re,fe,ae,X,W]}),e[101]=t,e[102]=J,e[103]=me,e[104]=re,e[105]=fe,e[106]=ae,e[107]=X,e[108]=W,e[109]=R,e[110]=G):G=e[110],G};function No(s){return d("option",{value:s,children:s},s)}const jt=6,rt=100,So=s=>({paddingLeft:s*16}),ko=s=>{const e=B(2),{table:n}=s,o=`cascade-restrict-${n}`;let t;return e[0]!==o?(t=d("span",{className:"rounded bg-destructive/10 px-1 text-destructive","data-testid":o,children:"restrict — will block delete"}),e[0]=o,e[1]=t):t=e[1],t},To=s=>{const e=B(2),{table:n}=s,o=`cascade-cascade-${n}`;let t;return e[0]!==o?(t=d("span",{className:"rounded bg-warning/10 px-1 text-warning","data-testid":o,children:"cascade"}),e[0]=o,e[1]=t):t=e[1],t},Eo=s=>{const e=B(2),{table:n}=s,o=`cascade-undeclared-${n}`;let t;return e[0]!==o?(t=d("span",{className:"rounded bg-muted px-1 text-muted-foreground","data-testid":o,children:"references — no delete action declared"}),e[0]=o,e[1]=t):t=e[1],t},_o=s=>s.relation===void 0||s.relation.onDelete==="cascade"?d(To,{table:s.table}):s.isRestrict?d(ko,{table:s.table}):d(Eo,{table:s.table}),tn=s=>{const e=B(35),{depth:n,node:o}=s,t=`cascade-row-${o.table}`;let c;e[0]!==n?(c=So(n),e[0]=n,e[1]=c):c=e[1];let l;e[2]!==n?(l=n>0&&d("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"└"}),e[2]=n,e[3]=l):l=e[3];let r;e[4]!==o.table?(r=d("span",{className:"font-medium text-foreground",children:o.table}),e[4]=o.table,e[5]=r):r=e[5];let a;e[6]!==o.relation||e[7]!==o.table?(a=o.relation!==void 0&&E("span",{className:"text-muted-foreground","data-testid":`cascade-col-${o.table}-${o.relation.field}`,children:["via ",o.relation.field]}),e[6]=o.relation,e[7]=o.table,e[8]=a):a=e[8];let i;e[9]!==o.rowCount?(i=o.rowCount.toString(),e[9]=o.rowCount,e[10]=i):i=e[10];let m;e[11]!==i?(m=E("span",{className:"text-muted-foreground",children:["(",i," rows)"]}),e[11]=i,e[12]=m):m=e[12];let f;e[13]!==o?(f=_o(o),e[13]=o,e[14]=f):f=e[14];let p;e[15]!==o.capNote||e[16]!==o.table?(p=o.capNote!==void 0&&E("span",{className:"italic text-muted-foreground","data-testid":`cascade-cap-${o.table}`,children:["(",o.capNote,")"]}),e[15]=o.capNote,e[16]=o.table,e[17]=p):p=e[17];let b;e[18]!==t||e[19]!==c||e[20]!==l||e[21]!==r||e[22]!==a||e[23]!==m||e[24]!==f||e[25]!==p?(b=E("li",{className:"flex flex-wrap items-center gap-1.5 py-1 font-mono text-xs","data-testid":t,style:c,children:[l,r,a,m,f,p]}),e[18]=t,e[19]=c,e[20]=l,e[21]=r,e[22]=a,e[23]=m,e[24]=f,e[25]=p,e[26]=b):b=e[26];let u;if(e[27]!==n||e[28]!==o.children){let h;e[30]!==n?(h=(x,v)=>d(tn,{depth:n+1,node:x},`${x.table}-${x.relation?.field??"root"}-${v.toString()}`),e[30]=n,e[31]=h):h=e[31],u=o.children.map(h),e[27]=n,e[28]=o.children,e[29]=u}else u=e[29];let g;return e[32]!==b||e[33]!==u?(g=E(Ze,{children:[b,u]}),e[32]=b,e[33]=u,e[34]=g):g=e[34],g},Ro=s=>{const e=s._id??s.id??s.__id__??"";return typeof e=="string"?e:typeof e=="number"?e.toString():""},$o=async(s,e,n,o)=>{try{const t=await o(s,e,n),c=t.rows.flatMap(a=>Ro(a)||[]).slice(0,rt),l=t.total??0;return{capNote:l>rt?`showing first ${rt.toString()} of ${l.toString()}`:void 0,rowCount:l,rowIds:c}}catch{return{capNote:"count unavailable",rowCount:0,rowIds:[]}}},nn=async(s,e,n,o,t,c,l)=>{const{capNote:r,rowCount:a,rowIds:i}=n===void 0?{capNote:void 0,rowCount:1,rowIds:[e]}:await $o(s,n.field,e,l),m=n?.onDelete==="restrict",f=[],p=`${s}:${e}`,b=c>=jt;if(!t.has(p)&&!b){t.add(p);const g=o.get(s)??[];for(const h of g)for(const x of i.slice(0,10)){const v=await nn(h.table,x,h,o,t,c+1,l);(v.rowCount>0||c===0)&&f.push(v)}t.delete(p)}let u=r;if(b){const g=`depth capped at ${jt.toString()}`;u=r===void 0?g:`${r}; ${g}`}return{capNote:u,children:f,isRestrict:m,relation:n,rowCount:a,rowIds:i,table:s}},Do=({onClose:s,onConfirm:e,readPage:n,rowId:o,schema:t,table:c})=>{const l=he(),[r,a]=D(!0),[i,m]=D(null),[f,p]=D(null);Be(()=>{let g=!1;return Ce((async()=>{try{a(!0),p(null);const x=wo(t);if(!((x.get(c)??[]).length>0)){g||(m({capNote:void 0,children:[],isRestrict:!1,relation:void 0,rowCount:1,rowIds:[o],table:c}),a(!1));return}const y=await nn(c,o,void 0,x,new Set,0,n);g||(m(y),a(!1))}catch(x){g||(p(x.message),a(!1))}})()),()=>{g=!0}},[o,c]);const b=i!==null&&yo(i,g=>g.isRestrict).length>0,u=()=>{e(),s()};return E(ut,{label:"Cascade impact preview",onClose:s,panelTestId:"cascade-panel",testId:"cascade-overlay",variant:"dialog",children:[E("div",{className:"flex items-start justify-between",children:[E("div",{className:"flex flex-col gap-0.5",children:[d("h3",{className:"text-base text-foreground","data-testid":"cascade-title",children:l("Cascade impact")}),d("p",{className:"text-xs text-muted-foreground","data-testid":"cascade-desc",children:l("Delete preview — rows that would cascade or be blocked")})]}),d("button",{className:"text-xs text-muted-foreground hover:text-foreground","data-testid":"cascade-close",onClick:s,type:"button",children:l("Close")})]}),r&&d("p",{className:"text-xs text-muted-foreground","data-testid":"cascade-loading",children:l("Loading…")}),f!==null&&d("p",{className:"text-xs text-destructive","data-testid":"cascade-error",role:"alert",children:f}),!r&&i!==null&&d("ul",{className:"flex flex-col","data-testid":"cascade-tree",children:d(tn,{depth:0,node:i})}),!r&&i!==null&&i.children.length===0&&d("p",{className:"text-xs text-muted-foreground","data-testid":"cascade-no-impact",children:l("No related rows found.")}),b&&d("p",{className:"text-sm font-medium text-destructive","data-testid":"cascade-blocker-warning",role:"alert",children:l("Restrict relations will block this delete.")}),E("div",{className:"flex justify-end gap-2",children:[d("button",{className:"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","data-testid":"cascade-cancel",onClick:s,type:"button",children:l("Cancel")}),d("button",{className:"rounded-md bg-destructive px-3 py-1.5 text-xs font-medium text-destructive-foreground outline-none transition-colors hover:bg-destructive/90 focus-visible:bg-destructive/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"cascade-confirm",disabled:r,onClick:u,type:"button",children:l("Delete")})]})]})},Po=(s,e,n,o,t=300)=>{if(o<=0)return{ids:new Set(s.map(f=>f.id)),leadPx:0,tailPx:0};const c=n-t,l=n+o+t,r=new Set;let a=0,i=0,m=0;for(const f of s){const p=f.getSize(),b=e.has(f.id),u=a+p>c&&a<l;b||u?r.add(f.id):a<c?i+=p:m+=p,a+=p}return{ids:r,leadPx:i,tailPx:m}},Ao=(s,e)=>{const n=new Map;let o=0;for(const t of s)e.has(t.id)&&(n.set(t.id,o),o+=t.getSize());return n},Io=Un({columnOrderingFeature:lo,columnResizingFeature:so,columnSizingFeature:oo,columnVisibilityFeature:no,rowSelectionFeature:to,rowSortingFeature:eo,sortedRowModel:ro(),sortFns:{alphanumeric:Zn,basic:Xn,datetime:Yn,text:Qn}}),Oo=()=>{const s=B(12);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e={},s[0]=e):e=s[0];const[n,o]=D(e);let t;s[1]===Symbol.for("react.memo_cache_sentinel")?(t=(g,h,x)=>{o(v=>({...v,[g]:{...v[g],[h]:x}}))},s[1]=t):t=s[1];const c=t;let l;s[2]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{o({})},s[2]=l):l=s[2];const r=l;let a;s[3]===Symbol.for("react.memo_cache_sentinel")?(a=(g,h)=>{o(x=>{const v=x[g];if(v===void 0)return x;const y=Object.fromEntries(Object.entries(v).filter(C=>{const[N,k]=C;return!(N in h)||!Object.is(k,h[N])}));return Object.keys(y).length===0?Object.fromEntries(Object.entries(x).filter(C=>{const[N]=C;return N!==g})):{...x,[g]:y}})},s[3]=a):a=s[3];const i=a;let m;s[4]!==n?(m=(g,h)=>{const x=n[g];return x!==void 0&&h in x?{value:x[h]}:void 0},s[4]=n,s[5]=m):m=s[5];const f=m;let p;s[6]!==n?(p=Object.values(n).reduce(Mo,0),s[6]=n,s[7]=p):p=s[7];const b=p;let u;return s[8]!==b||s[9]!==n||s[10]!==f?(u={clear:r,count:b,drop:i,stage:c,staged:n,stagedValue:f},s[8]=b,s[9]=n,s[10]=f,s[11]=u):u=s[11],u},on=(s,e)=>{if(typeof e=="number"){const n=Number(s);return s.trim()===""||Number.isNaN(n)?s:n}if(typeof e=="boolean"){if(s==="true")return!0;if(s==="false")return!1}return s},Fo=s=>{const e=B(29),{changes:n,committing:o,onCommit:t,onDiscard:c}=s,l=he();let r;e[0]!==n.length||e[1]!==l?(r=l("{count} pending changes",{count:n.length}),e[0]=n.length,e[1]=l,e[2]=r):r=e[2];let a;e[3]!==r?(a=d("span",{className:"font-mono text-[11px] tracking-wide uppercase text-warning","data-testid":"db-staged-count",children:r}),e[3]=r,e[4]=a):a=e[4];let i;e[5]!==o||e[6]!==l?(i=l(o?"Committing…":"Commit"),e[5]=o,e[6]=l,e[7]=i):i=e[7];let m;e[8]!==o||e[9]!==t||e[10]!==i?(m=d("button",{className:"ms-auto rounded-md bg-primary px-2.5 py-1 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":"db-staged-commit",disabled:o,onClick:t,type:"button",children:i}),e[8]=o,e[9]=t,e[10]=i,e[11]=m):m=e[11];let f;e[12]!==l?(f=l("Discard"),e[12]=l,e[13]=f):f=e[13];let p;e[14]!==o||e[15]!==c||e[16]!==f?(p=d("button",{className:"rounded-md border border-border px-2.5 py-1 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":"db-staged-discard",disabled:o,onClick:c,type:"button",children:f}),e[14]=o,e[15]=c,e[16]=f,e[17]=p):p=e[17];let b;e[18]!==a||e[19]!==m||e[20]!==p?(b=E("div",{className:"flex flex-wrap items-center gap-2",children:[a,m,p]}),e[18]=a,e[19]=m,e[20]=p,e[21]=b):b=e[21];let u;e[22]!==n?(u=n.map(Lo),e[22]=n,e[23]=u):u=e[23];let g;e[24]!==u?(g=d("ul",{className:"flex flex-col gap-1","data-testid":"db-staged-list",children:u}),e[24]=u,e[25]=g):g=e[25];let h;return e[26]!==b||e[27]!==g?(h=E("div",{className:"flex flex-col gap-2 border border-warning/40 bg-warning/5 p-3","data-testid":"db-staged",children:[b,g]}),e[26]=b,e[27]=g,e[28]=h):h=e[28],h};function Mo(s,e){return s+Object.keys(e).length}function Lo(s){return E("li",{className:"flex flex-wrap items-center gap-2 font-mono text-xs",children:[E("span",{className:"text-muted-foreground",children:[s.rowId,".",s.column]}),d("span",{className:"text-destructive line-through",children:je(s.oldValue)}),d("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"→"}),d("span",{className:"text-foreground",children:je(s.newValue)})]},`${s.rowId}:${s.column}`)}const zt=400,Vo=36,Bo={flex:"1 1 0%",minHeight:0,overflow:"auto",position:"relative"},jo={width:"100%"},zo=/\n$/u,qo={alignItems:"center",display:"flex",left:0,position:"absolute",top:0,width:"100%"},Ko={display:"flex",width:"100%"},qt={flex:"0 0 8.5rem",padding:"0.375rem 0.75rem"},Go="2.5rem",sn={alignItems:"center",display:"flex",flex:"0 0 2.5rem",justifyContent:"center",left:0,padding:"0.375rem 0",position:"sticky",zIndex:2},Pt=s=>({flex:"0 0 auto",overflow:"hidden",padding:"0.375rem 0.75rem",position:"relative",textOverflow:"ellipsis",whiteSpace:"nowrap",width:`${s.toString()}px`}),ln=(s,e)=>({...Pt(s),left:`calc(${Go} + ${e.toString()}px)`,position:"sticky",zIndex:2}),Nt="rounded-md px-2 py-0.5 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50",Jo=(s,e,n)=>e.enabled&&e.columns.has(n)?void 0:s,_t="__back__:",Wo=s=>`${_t}${s.table}.${s.column}`,Ho=s=>{const e=B(3),{counts:n,rowId:o}=s;if(n===void 0){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=d("span",{className:"text-muted-foreground/50",children:"—"}),e[0]=l):l=e[0],l}const t=n[o]??0;let c;return e[1]!==t?(c=d("span",{className:"tabular-nums",children:t}),e[1]=t,e[2]=c):c=e[2],c},Pe=s=>{for(const e of["id","__id__","_id"]){const n=s[e];if(typeof n=="string"||typeof n=="number")return String(n)}return null},Uo=(s,e)=>{if(e.enumValues!==void 0&&e.enumValues.length>0)return e.enumValues.includes(s)||s===""&&e.nullable===!0?{value:s===""?null:s}:void 0;if(e.type==="boolean")return s==="true"||s==="false"?{value:s==="true"}:void 0;if(e.type==="number"){const n=Number(s);return s.trim()===""||!Number.isFinite(n)?void 0:{value:n}}return{value:s}},Qo=(s,e,n)=>{if(n!==void 0&&n.type!=="any")return Uo(s,n);const o=on(s,e);return typeof e=="number"&&typeof o!="number"?void 0:{value:o}},Yo=({anchor:s,columnIds:e,columnMeta:n,editableColumn:o,rows:t,text:c})=>{const l=c.replaceAll(`\r
2
2
  `,`
3
3
  `).replace(zo,"").split(`
4
- `),r=[];let a=0;for(const[i,m]of l.entries()){const f=t[s.row+i],p=f===void 0?null:Ae(f),b=m.split(" ");if(f===void 0||p===null){a+=b.length;continue}for(const[u,g]of b.entries()){const h=e[s.col+u],x=h===void 0||!o(h)?void 0:Qo(g,f[h],n?.[h]);h===void 0||x===void 0?a+=1:r.push({column:h,rowId:p,value:x.value})}}return{edits:r,skipped:a}},rn=(s,e)=>Ae(s)??`row-${e.toString()}`,Xo=8,Zo=s=>{const e=B(17),{anchor:n,mask:o,state:t}=s,c=he();let l;e[0]!==n.left||e[1]!==n.top?(l={left:n.left,position:"fixed",top:n.top,zIndex:50},e[0]=n.left,e[1]=n.top,e[2]=l):l=e[2];const r=l;let a;if(t==="loading"){let m;e[3]!==c?(m=c("Loading…"),e[3]=c,e[4]=m):m=e[4];let f;e[5]!==m?(f=d("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:m}),e[5]=m,e[6]=f):f=e[6],a=f}else if(t.row===null){let m;e[7]!==c?(m=c("No matching row."),e[7]=c,e[8]=m):m=e[8];let f;e[9]!==m?(f=d("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:m}),e[9]=m,e[10]=f):f=e[10],a=f}else{let m;if(e[11]!==o||e[12]!==t.row){const f=Object.entries(Xt(t.row,o)).slice(0,Xo);m=d("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 px-3 py-2",children:f.map(us)}),e[11]=o,e[12]=t.row,e[13]=m}else m=e[13];a=m}let i;return e[14]!==a||e[15]!==r?(i=d("div",{className:"pointer-events-none w-72 overflow-hidden rounded-md border border-border bg-popover text-popover-foreground","data-testid":"db-ref-preview",role:"tooltip",style:r,children:a}),e[14]=a,e[15]=r,e[16]=i):i=e[16],i},es=s=>{const e=B(24),{column:n,id:o,maskViewFor:t,onNavigate:c,onPreview:l,target:r}=s,[a,i]=D(null),[m,f]=D("idle");let p;e[0]!==o||e[1]!==c||e[2]!==r?(p=()=>{c(r,o)},e[0]=o,e[1]=c,e[2]=r,e[3]=p):p=e[3];const b=p;let u;e[4]!==o||e[5]!==l||e[6]!==m||e[7]!==r?(u=S=>{const w=S.currentTarget.getBoundingClientRect();if(i({left:w.left,top:w.bottom+4}),m!=="idle")return;f("loading"),Ce((async()=>{try{f({row:await l(r,o)})}catch{f({row:null})}})())},e[4]=o,e[5]=l,e[6]=m,e[7]=r,e[8]=u):u=e[8];const g=u;let h;e[9]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{i(null)},e[9]=h):h=e[9];const x=h,v=`db-ref-${n}`,y=`Open ${r} ${o}`;let C;e[10]!==o||e[11]!==b||e[12]!==g||e[13]!==v||e[14]!==y?(C=E("button",{"data-testid":v,onBlur:x,onClick:b,onFocus:g,onMouseEnter:g,onMouseLeave:x,title:y,type:"button",children:[o," ↗"]}),e[10]=o,e[11]=b,e[12]=g,e[13]=v,e[14]=y,e[15]=C):C=e[15];let N;e[16]!==a||e[17]!==t||e[18]!==m||e[19]!==r?(N=a!==null&&m!=="idle"&&d(Zo,{anchor:a,mask:t(r,m==="loading"||m.row===null?[]:Object.keys(m.row)),state:m}),e[16]=a,e[17]=t,e[18]=m,e[19]=r,e[20]=N):N=e[20];let k;return e[21]!==C||e[22]!==N?(k=E(Ze,{children:[C,N]}),e[21]=C,e[22]=N,e[23]=k):k=e[23],k},ts=s=>s==="asc"?" ▲":s==="desc"?" ▼":"",ns="absolute end-1 top-1/2 hidden -translate-y-1/2 items-center justify-center rounded text-muted-foreground outline-none group-hover/cell:flex hover:text-foreground focus-visible:flex",Kt=s=>{const e=B(8),{column:n,onExpand:o,value:t}=s;let c;e[0]!==n||e[1]!==o||e[2]!==t?(c=()=>{o(n,t)},e[0]=n,e[1]=o,e[2]=t,e[3]=c):c=e[3];const l=c,r=`db-expand-${n}`;let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=d("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:d("path",{d:"M9 21H5a2 2 0 0 1-2-2v-4m18 0v4a2 2 0 0 1-2 2h-4M3 9V5a2 2 0 0 1 2-2h4m6 0h4a2 2 0 0 1 2 2v4"})}),e[4]=a):a=e[4];let i;return e[5]!==l||e[6]!==r?(i=d("button",{"aria-label":"Expand cell",className:ns,"data-testid":r,onClick:l,type:"button",children:a}),e[5]=l,e[6]=r,e[7]=i):i=e[7],i},os=s=>{const e=B(15),{column:n,initial:o,onCancel:t,onCommit:c,recordId:l}=s,r=Ge(null);let a,i;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{r.current?.select()},i=[],e[0]=a,e[1]=i):(a=e[0],i=e[1]),Be(a,i);let m;e[2]!==t||e[3]!==c?(m=x=>{x.key==="Enter"?(x.preventDefault(),c(x.currentTarget.value)):x.key==="Escape"&&(x.preventDefault(),t())},e[2]=t,e[3]=c,e[4]=m):m=e[4];const f=m;let p;e[5]!==c?(p=x=>{c(x.currentTarget.value)},e[5]=c,e[6]=p):p=e[6];const b=p,u=`db-cell-input-${l}-${n}`;let g;e[7]!==o?(g=je(o),e[7]=o,e[8]=g):g=e[8];let h;return e[9]!==n||e[10]!==b||e[11]!==f||e[12]!==u||e[13]!==g?(h=d("input",{"aria-label":n,className:"w-full rounded border border-ring bg-background px-1 py-0.5 font-mono text-xs outline-none","data-testid":u,defaultValue:g,onBlur:b,onKeyDown:f,ref:r}),e[9]=n,e[10]=b,e[11]=f,e[12]=u,e[13]=g,e[14]=h):h=e[14],h},ss=s=>{const e=B(70),{cell:n,edit:o,highlight:t,mask:c,refs:l}=s,r=n.column.id;let a,i,m,f;if(e[0]!==n||e[1]!==r||e[2]!==o||e[3]!==c||e[4]!==l.columns||e[5]!==l.maskViewFor||e[6]!==l.onNavigate||e[7]!==l.onPreview){f=Symbol.for("react.early_return_sentinel");e:{i=n.getValue(),a=Ae(n.row.original);const R=l.columns?.[r];if(c.enabled&&c.columns.has(r)){const _=`db-masked-${r}`,$=d(Ct,{value:Vn(i,r,c)});let O;e[12]!==_||e[13]!==$?(O=d("span",{className:"text-muted-foreground italic","data-testid":_,title:"Masked (preview)",children:$}),e[12]=_,e[13]=$,e[14]=O):O=e[14],f=O;break e}if(R!==void 0&&(typeof i=="string"||typeof i=="number")&&String(i)!==""){const _=String(i),$=`${R}:${String(i)}`;let O;e[15]!==r||e[16]!==l.maskViewFor||e[17]!==l.onNavigate||e[18]!==l.onPreview||e[19]!==_||e[20]!==$||e[21]!==R?(O=d(es,{column:r,id:_,maskViewFor:l.maskViewFor,onNavigate:l.onNavigate,onPreview:l.onPreview,target:R},$),e[15]=r,e[16]=l.maskViewFor,e[17]=l.onNavigate,e[18]=l.onPreview,e[19]=_,e[20]=$,e[21]=R,e[22]=O):O=e[22],f=O;break e}if(a===null){let _;e[23]!==i?(_=d(Ct,{value:i}),e[23]=i,e[24]=_):_=e[24];let $;e[25]!==r||e[26]!==o.onExpandCell||e[27]!==i?($=d(Kt,{column:r,onExpand:o.onExpandCell,value:i}),e[25]=r,e[26]=o.onExpandCell,e[27]=i,e[28]=$):$=e[28];let O;e[29]!==_||e[30]!==$?(O=E(Ze,{children:[_,$]}),e[29]=_,e[30]=$,e[31]=O):O=e[31],f=O;break e}m=o.stagedValue(a,r)}e[0]=n,e[1]=r,e[2]=o,e[3]=c,e[4]=l.columns,e[5]=l.maskViewFor,e[6]=l.onNavigate,e[7]=l.onPreview,e[8]=a,e[9]=i,e[10]=m,e[11]=f}else a=e[8],i=e[9],m=e[10],f=e[11];if(f!==Symbol.for("react.early_return_sentinel"))return f;const p=m,b=p===void 0?i:p.value;let u;e[32]!==r||e[33]!==o?(u=o.editable&&o.editableColumn(r),e[32]=r,e[33]=o,e[34]=u):u=e[34];const g=u;if(o.editingCell!==null&&o.editingCell.rowId===a&&o.editingCell.column===r){let R;e[35]!==r||e[36]!==o||e[37]!==a||e[38]!==i?(R=$=>{o.stage(a,r,on($,i)),o.cancelEdit()},e[35]=r,e[36]=o,e[37]=a,e[38]=i,e[39]=R):R=e[39];let _;return e[40]!==r||e[41]!==b||e[42]!==o.cancelEdit||e[43]!==a||e[44]!==R?(_=d(os,{column:r,initial:b,onCancel:o.cancelEdit,onCommit:R,recordId:a}),e[40]=r,e[41]=b,e[42]=o.cancelEdit,e[43]=a,e[44]=R,e[45]=_):_=e[45],_}let x;p!==void 0?x="rounded bg-warning/15 px-1":g&&(x="cursor-text");let v;e[46]!==g||e[47]!==r||e[48]!==o||e[49]!==a?(v=g?()=>{o.startEdit(a,r)}:void 0,e[46]=g,e[47]=r,e[48]=o,e[49]=a,e[50]=v):v=e[50];const y=v,C=x,N=`db-cell-${a}-${r}`;let k;e[51]!==r||e[52]!==t||e[53]!==c?(k=Jo(t,c,r),e[51]=r,e[52]=t,e[53]=c,e[54]=k):k=e[54];let S;e[55]!==b||e[56]!==k?(S=d(Ct,{highlight:k,value:b}),e[55]=b,e[56]=k,e[57]=S):S=e[57];let w;e[58]!==x||e[59]!==y||e[60]!==N||e[61]!==S?(w=d("span",{className:C,"data-testid":N,onDoubleClick:y,children:S}),e[58]=x,e[59]=y,e[60]=N,e[61]=S,e[62]=w):w=e[62];let T;e[63]!==r||e[64]!==b||e[65]!==o.onExpandCell?(T=d(Kt,{column:r,onExpand:o.onExpandCell,value:b}),e[63]=r,e[64]=b,e[65]=o.onExpandCell,e[66]=T):T=e[66];let I;return e[67]!==T||e[68]!==w?(I=E(Ze,{children:[w,T]}),e[67]=T,e[68]=w,e[69]=I):I=e[69],I},ls=s=>{s.preventDefault()},Gt={any:"?",array:"[]",bigint:"#",boolean:"01",bytes:"0x",id:"→",number:"#",object:"{}",storage:"◫",string:"T",union:"|"},rs=({declaredType:s,draggedRef:e,header:n,masked:o=!1,onTogglePin:t,pinnedOffset:c,table:l})=>{const r=()=>{e.current=n.column.id},a=()=>{const i=e.current,m=n.column.id;if(e.current=null,i===null||i===m)return;const f=l.atoms.columnOrder.get(),b=(f.length>0?f:l.getAllLeafColumns().map(g=>g.id)).filter(g=>g!==i),u=b.indexOf(m);b.splice(u===-1?b.length:u,0,i),l.setColumnOrder(b)};return E("th",{className:ct("group/head text-start text-xs font-medium text-muted-foreground",c!==void 0&&"border-e border-border bg-muted"),"data-testid":`db-head-${n.column.id}`,draggable:!0,onDragOver:ls,onDragStart:r,onDrop:a,style:c===void 0?At(n.getSize()):ln(n.getSize(),c),children:[E("button",{className:"inline-flex max-w-full cursor-grab items-center gap-1 truncate outline-none hover:text-foreground","data-testid":`db-sort-${n.column.id}`,onClick:n.column.getToggleSortingHandler(),type:"button",children:[io(n.column.columnDef.header,n.getContext()),ts(n.column.getIsSorted())]}),s!==void 0&&Gt[s]!==void 0&&d("span",{className:"ms-1 font-mono text-[0.625rem] text-muted-foreground/70","data-testid":`db-type-${n.column.id}`,title:s,children:Gt[s]}),o&&d("span",{className:"ms-1 inline-flex items-center rounded-sm bg-warning/15 px-1 text-[0.625rem] font-medium uppercase text-warning","data-testid":`db-mask-chip-${n.column.id}`,title:"This column is masked by a mask() policy",children:"masked"}),d("button",{"aria-label":c===void 0?`Pin ${n.column.id}`:`Unpin ${n.column.id}`,"aria-pressed":c!==void 0,className:ct("ms-1 rounded-sm px-1 text-[0.625rem] outline-none transition-opacity hover:bg-accent focus-visible:bg-accent",c===void 0?"opacity-0 group-hover/head:opacity-100 focus-visible:opacity-100":"opacity-100 text-foreground"),"data-testid":`db-pin-${n.column.id}`,onClick:()=>{t(n.column.id)},type:"button",children:"📌"}),d("span",{"aria-hidden":"true",className:"absolute inset-y-0 end-0 w-1 cursor-col-resize touch-none select-none hover:bg-ring/60 data-[resizing=true]:bg-ring","data-resizing":n.column.getIsResizing(),"data-testid":`db-resize-${n.column.id}`,onMouseDown:n.getResizeHandler(),onTouchStart:n.getResizeHandler()})]})},as=s=>{const e=B(13),{table:n}=s,o=he();let t;e[0]!==n?(t=m=>{n.toggleAllRowsSelected(m)},e[0]=n,e[1]=t):t=e[1];const c=t;let l;e[2]!==o?(l=o("Select all rows"),e[2]=o,e[3]=l):l=e[3];let r;e[4]!==n?(r=n.getIsAllRowsSelected(),e[4]=n,e[5]=r):r=e[5];let a;e[6]!==n?(a=n.getIsSomeRowsSelected()&&!n.getIsAllRowsSelected(),e[6]=n,e[7]=a):a=e[7];let i;return e[8]!==c||e[9]!==l||e[10]!==r||e[11]!==a?(i=d("th",{className:"bg-muted",style:sn,children:d($t,{"aria-label":l,checked:r,"data-testid":"db-select-all",indeterminate:a,onCheckedChange:c})}),e[8]=c,e[9]=l,e[10]=r,e[11]=a,e[12]=i):i=e[12],i},is=s=>{const e=B(17),{row:n}=s,o=he();let t;e[0]!==n.original?(t=Ae(n.original),e[0]=n.original,e[1]=t):t=e[1];const c=t;let l;e[2]!==n?(l=u=>{n.toggleSelected(u)},e[2]=n,e[3]=l):l=e[3];const r=l;let a;e[4]!==o?(a=o("Select row"),e[4]=o,e[5]=a):a=e[5];let i;e[6]!==n?(i=n.getIsSelected(),e[6]=n,e[7]=i):i=e[7];let m;e[8]!==n.index||e[9]!==n.original?(m=rn(n.original,n.index),e[8]=n.index,e[9]=n.original,e[10]=m):m=e[10];const f=`db-select-${m}`,p=c===null;let b;return e[11]!==r||e[12]!==a||e[13]!==i||e[14]!==f||e[15]!==p?(b=d("td",{className:"bg-background",style:sn,children:d($t,{"aria-label":a,checked:i,"data-testid":f,disabled:p,onCheckedChange:r})}),e[11]=r,e[12]=a,e[13]=i,e[14]=f,e[15]=p,e[16]=b):b=e[16],b},cs=s=>{const e=B(91),{columnMeta:n,edit:o,editable:t,mask:c,onDelete:l,onEdit:r,onInspect:a,highlight:i,backRelationCounts:m,onTogglePin:f,pinnedColumns:p,refs:b,tableModel:u}=s,g=he(),{attachScroll:h,scrollLeft:x,scrollToIndex:v,table:y,tableRows:C,tbodyStyle:N,viewportWidth:k,virtualRows:S}=u,w=Ge(null),[T,I]=D(null);let R;e[0]===Symbol.for("react.memo_cache_sentinel")?(R={columns:"",count:0},e[0]=R):R=e[0];const[_,$]=D(R);let O;e[1]!==y?(O=y.getVisibleLeafColumns(),e[1]=y,e[2]=O):O=e[2];const M=O.length;let P;e[3]!==T||e[4]!==M||e[5]!==o||e[6]!==y||e[7]!==C?(P=ee=>{if(!["ArrowDown","ArrowLeft","ArrowRight","ArrowUp","Enter"].includes(ee.key))return;ee.preventDefault();const H=T??{col:0,row:0};if(ee.key==="Enter"){const we=C[H.row],ye=y.getVisibleLeafColumns()[H.col];if(we!==void 0&&ye!==void 0){const U=Ae(we.original);U!==null&&o.editableColumn(ye.id)&&o.startEdit(U,ye.id)}I(H);return}let{col:ve,row:ge}=H;e:switch(ee.key){case"ArrowDown":{ge=Math.min(ge+1,C.length-1);break e}case"ArrowRight":{ve=Math.min(ve+1,M-1);break e}case"ArrowUp":{ge=Math.max(ge-1,0);break e}default:ve=Math.max(ve-1,0)}I({col:ve,row:ge})},e[3]=T,e[4]=M,e[5]=o,e[6]=y,e[7]=C,e[8]=P):P=e[8];const z=P;let q;e[9]!==T||e[10]!==n||e[11]!==o||e[12]!==y||e[13]!==C?(q=ee=>{const H=o.editable?ee.clipboardData.getData("text/plain"):"";if(H==="")return;ee.preventDefault();const ve=y.getVisibleLeafColumns().map(fs),ge=Yo({anchor:T??{col:0,row:0},columnIds:ve,columnMeta:n,editableColumn:o.editableColumn,rows:C.map(ms),text:H});for(const we of ge.edits)o.stage(we.rowId,we.column,we.value);$({columns:ve.join("\0"),count:ge.skipped})},e[9]=T,e[10]=n,e[11]=o,e[12]=y,e[13]=C,e[14]=q):q=e[14];const F=q;let V,J;e[15]!==T||e[16]!==v?(V=()=>{T!==null&&v(T.row)},J=[T,v],e[15]=T,e[16]=v,e[17]=V,e[18]=J):(V=e[17],J=e[18]),Be(V,J);let K,Z,Y,Q,ne,oe,de,ue,me,re,fe,ae,X,be,te,xe;if(e[19]!==T||e[20]!==h||e[21]!==m||e[22]!==n||e[23]!==o||e[24]!==t||e[25]!==i||e[26]!==c||e[27]!==l||e[28]!==r||e[29]!==z||e[30]!==F||e[31]!==a||e[32]!==f||e[33]!==_.columns||e[34]!==_.count||e[35]!==p||e[36]!==b||e[37]!==x||e[38]!==g||e[39]!==y||e[40]!==C||e[41]!==N||e[42]!==k||e[43]!==S){const ee=y.getVisibleLeafColumns().map(gs),H=Ao(ee,p,x,k),ve=Io(y.getVisibleLeafColumns().map(ps),p),ge=U=>{const se=C[U.index],{original:Me}=se,Ie=Ae(Me),Pe=rn(Me,U.index),We={...qo,height:`${U.size.toString()}px`,transform:`translateY(${U.start.toString()}px)`};return E("tr",{className:"border-b border-border text-xs transition-colors hover:bg-muted/50","data-testid":"db-row",style:We,children:[d(is,{row:se}),H.leadPx>0&&d("td",{"aria-hidden":"true",style:{flex:`0 0 ${H.leadPx.toString()}px`}}),se.getVisibleCells().map((Se,ze)=>{if(!H.ids.has(Se.column.id))return null;const Le=ve.get(Se.column.id),He=T!==null&&T.row===U.index&&T.col===ze?" ring-1 ring-ring ring-inset":"";return d("td",{className:ct("group/cell truncate font-mono text-muted-foreground",Le!==void 0&&"border-e border-border bg-background",He),onPointerDown:()=>{I({col:ze,row:U.index})},style:Le===void 0?At(Se.column.getSize()):ln(Se.column.getSize(),Le),children:Se.column.id.startsWith(_t)?d(Ho,{counts:m[Se.column.id.slice(_t.length)],rowId:Pe}):d(ss,{cell:Se,edit:o,highlight:i,mask:c,refs:b})},Se.id)}),H.tailPx>0&&d("td",{"aria-hidden":"true",style:{flex:`0 0 ${H.tailPx.toString()}px`}}),E("td",{className:"flex items-center gap-1",style:qt,children:[d("button",{className:Nt,"data-testid":`db-inspect-${Pe}`,onClick:()=>{a(Me)},type:"button",children:"Details"}),t&&E(Ze,{children:[d("button",{className:Nt,"data-testid":`db-edit-${Pe}`,disabled:Ie===null,onClick:()=>{r(Ie,Me)},type:"button",children:"Edit"}),d("button",{className:Nt,"data-testid":`db-delete-${Pe}`,disabled:Ie===null,onClick:()=>{l(Ie)},type:"button",children:"Delete"})]})]})]},se.id)};K=fo,ae="fill",e[60]!==_.columns||e[61]!==_.count||e[62]!==g||e[63]!==y?(X=_.count>0&&_.columns===y.getVisibleLeafColumns().map(bs).join("\0")&&d("p",{className:"border-b border-warning/40 bg-warning/5 px-3 py-1.5 text-xs text-warning","data-testid":"db-paste-skipped",children:g("{count} pasted cells were skipped",{count:_.count})}),e[60]=_.columns,e[61]=_.count,e[62]=g,e[63]=y,e[64]=X):X=e[64],ne="db-scroll",oe=z,de=F,ue=h,me="grid",re=Bo,fe=0,xe="w-full text-xs",Z="db-rows",Y=jo;let we;e[65]!==y?(we=d(as,{table:y}),e[65]=y,e[66]=we):we=e[66];let ye;e[67]===Symbol.for("react.memo_cache_sentinel")?(ye=d("th",{"aria-label":"Row actions",style:qt}),e[67]=ye):ye=e[67],Q=d("thead",{className:"bg-muted/50",children:E("tr",{className:"border-b border-border",style:Ko,children:[we,H.leadPx>0&&d("th",{"aria-hidden":"true",style:{flex:`0 0 ${H.leadPx.toString()}px`}}),y.getFlatHeaders().map(U=>H.ids.has(U.column.id)?d(rs,{declaredType:n?.[U.column.id]?.type,draggedRef:w,header:U,masked:c.columns.has(U.column.id),onTogglePin:f,pinnedOffset:ve.get(U.column.id),table:y},U.id):null),H.tailPx>0&&d("th",{"aria-hidden":"true",style:{flex:`0 0 ${H.tailPx.toString()}px`}}),ye]})}),be=N,te=S.map(U=>ge(U)),e[19]=T,e[20]=h,e[21]=m,e[22]=n,e[23]=o,e[24]=t,e[25]=i,e[26]=c,e[27]=l,e[28]=r,e[29]=z,e[30]=F,e[31]=a,e[32]=f,e[33]=_.columns,e[34]=_.count,e[35]=p,e[36]=b,e[37]=x,e[38]=g,e[39]=y,e[40]=C,e[41]=N,e[42]=k,e[43]=S,e[44]=K,e[45]=Z,e[46]=Y,e[47]=Q,e[48]=ne,e[49]=oe,e[50]=de,e[51]=ue,e[52]=me,e[53]=re,e[54]=fe,e[55]=ae,e[56]=X,e[57]=be,e[58]=te,e[59]=xe}else K=e[44],Z=e[45],Y=e[46],Q=e[47],ne=e[48],oe=e[49],de=e[50],ue=e[51],me=e[52],re=e[53],fe=e[54],ae=e[55],X=e[56],be=e[57],te=e[58],xe=e[59];let ie;e[68]!==be||e[69]!==te?(ie=d("tbody",{style:be,children:te}),e[68]=be,e[69]=te,e[70]=ie):ie=e[70];let ce;e[71]!==Z||e[72]!==Y||e[73]!==Q||e[74]!==ie||e[75]!==xe?(ce=E("table",{className:xe,"data-testid":Z,style:Y,children:[Q,ie]}),e[71]=Z,e[72]=Y,e[73]=Q,e[74]=ie,e[75]=xe,e[76]=ce):ce=e[76];let W;e[77]!==ne||e[78]!==oe||e[79]!==de||e[80]!==ue||e[81]!==me||e[82]!==re||e[83]!==fe||e[84]!==ce?(W=d("div",{"data-testid":ne,onKeyDown:oe,onPaste:de,ref:ue,role:me,style:re,tabIndex:fe,children:ce}),e[77]=ne,e[78]=oe,e[79]=de,e[80]=ue,e[81]=me,e[82]=re,e[83]=fe,e[84]=ce,e[85]=W):W=e[85];let G;return e[86]!==K||e[87]!==ae||e[88]!==X||e[89]!==W?(G=E(K,{layout:ae,children:[X,W]}),e[86]=K,e[87]=ae,e[88]=X,e[89]=W,e[90]=G):G=e[90],G},ds=(s,e,n,o=[])=>{const t=s?.columns,c=s?.rows,l=s?.refs,r=Tt(()=>{if(t===void 0)return[];const w=t.map(T=>({accessorFn:I=>I[T],header:l?.[T]===void 0?T:`${T} →`,id:T}));for(const T of o)w.push({accessorFn:()=>{},enableSorting:!1,header:`← ${T.table}`,id:Wo(T)});return w},[o,t,l]),a=Tt(()=>c??[],[c]),[i,m]=D({}),[f,p]=D({}),b=ao({columnResizeMode:"onChange",columns:r,data:a,defaultColumn:{minSize:80,size:200},enableColumnResizing:!0,enableRowSelection:w=>Ae(w.original)!==null,features:Po,getRowId:(w,T)=>Ae(w)??`row-${T.toString()}`,manualSorting:!0,onColumnVisibilityChange:p,onRowSelectionChange:m,onSortingChange:n,state:{columnVisibility:f,rowSelection:i,sorting:e}}),u=b.getRowModel().rows,g=Ge(null),h=co({count:u.length,estimateSize:()=>Vo,getScrollElement:()=>g.current,initialRect:{height:zt,width:0},observeElementRect:(w,T)=>uo(w,T,zt),overscan:8}),x=it(w=>{h.scrollToIndex(w)},[h]),[v,y]=D({left:0,width:0}),C=it(w=>{if(g.current=w,w===null)return;const T=()=>{y(R=>R.left===w.scrollLeft&&R.width===w.clientWidth?R:{left:w.scrollLeft,width:w.clientWidth})};w.addEventListener("scroll",T,{passive:!0});const I=new ResizeObserver(T);return I.observe(w),()=>{w.removeEventListener("scroll",T),I.disconnect(),g.current=null}},[]),N=h.getVirtualItems(),S={display:"block",height:`${h.getTotalSize().toString()}px`,position:"relative"};return{attachScroll:C,scrollLeft:v.left,scrollToIndex:x,table:b,tableRows:u,tbodyStyle:S,viewportWidth:v.width,virtualRows:N}};function us(s){const[e,n]=s;return E("div",{className:"contents",children:[d("dt",{className:"truncate font-mono text-[11px] text-muted-foreground",children:e}),d("dd",{className:"truncate font-mono text-[11px] text-foreground",title:je(n),children:je(n)})]},e)}function fs(s){return s.id}function ms(s){return s.original}function gs(s){return{getSize:()=>s.getSize(),id:s.id}}function ps(s){return{getSize:()=>s.getSize(),id:s.id}}function bs(s){return s.id}const hs=s=>{const e=B(22),{onCommit:n}=s,o=he(),[t,c]=D(""),l=Ge(null);let r,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{l.current?.focus()},a=[],e[0]=r,e[1]=a):(r=e[0],a=e[1]),Be(r,a);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=y=>{c(y.target.value)},e[2]=i):i=e[2];const m=i;let f;e[3]!==t||e[4]!==n?(f=()=>{const y=t.trim();y!==""&&n(y)},e[3]=t,e[4]=n,e[5]=f):f=e[5];const p=f;let b;e[6]!==o?(b=o("Query name"),e[6]=o,e[7]=b):b=e[7];let u;e[8]!==o?(u=o("Query name"),e[8]=o,e[9]=u):u=e[9];let g;e[10]!==t||e[11]!==b||e[12]!==u?(g=d("input",{"aria-label":b,className:"h-7 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"db-save-query-name",onChange:m,placeholder:u,ref:l,value:t}),e[10]=t,e[11]=b,e[12]=u,e[13]=g):g=e[13];let h;e[14]!==o?(h=o("Save"),e[14]=o,e[15]=h):h=e[15];let x;e[16]!==p||e[17]!==h?(x=d("button",{className:Et,"data-testid":"db-save-query-confirm",onClick:p,type:"button",children:h}),e[16]=p,e[17]=h,e[18]=x):x=e[18];let v;return e[19]!==g||e[20]!==x?(v=E("span",{className:"inline-flex items-center gap-1",children:[g,x]}),e[19]=g,e[20]=x,e[21]=v):v=e[21],v},xs=s=>{const e=B(27),{onApply:n,onCopyLink:o,onDelete:t,onSave:c,saved:l}=s,r=he(),[a,i]=D(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{i(!0)},e[0]=m):m=e[0];const f=m;let p;e[1]!==c?(p=S=>{c(S),i(!1)},e[1]=c,e[2]=p):p=e[2];const b=p;let u;e[3]!==n||e[4]!==l?(u=S=>{const w=l[Number(S.currentTarget.dataset.index)];w!==void 0&&n(w)},e[3]=n,e[4]=l,e[5]=u):u=e[5];const g=u;let h;e[6]!==t||e[7]!==l?(h=S=>{const w=l[Number(S.currentTarget.dataset.index)];w!==void 0&&t(w.name)},e[6]=t,e[7]=l,e[8]=h):h=e[8];const x=h;let v;e[9]!==r?(v=r("Copy link"),e[9]=r,e[10]=v):v=e[10];let y;e[11]!==o||e[12]!==v?(y=d("button",{className:Et,"data-testid":"db-copy-link",onClick:o,type:"button",children:v}),e[11]=o,e[12]=v,e[13]=y):y=e[13];let C;e[14]!==b||e[15]!==a||e[16]!==r?(C=a?d(hs,{onCommit:b}):d("button",{className:Et,"data-testid":"db-save-query",onClick:f,type:"button",children:r("Save query")}),e[14]=b,e[15]=a,e[16]=r,e[17]=C):C=e[17];let N;e[18]!==g||e[19]!==x||e[20]!==l||e[21]!==r?(N=l.length>0&&E("div",{className:"flex flex-wrap items-center gap-1","data-testid":"db-saved-queries",children:[d("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:r("Saved")}),l.map((S,w)=>E("span",{className:"inline-flex items-center overflow-hidden rounded-md border border-border",children:[d("button",{className:"px-2 py-0.5 text-xs text-foreground transition-colors hover:bg-accent","data-index":w,"data-testid":`db-saved-query-${S.name}`,onClick:g,type:"button",children:S.name}),d("button",{"aria-label":r("Delete saved query {name}",{name:S.name}),className:"border-l border-border px-1 py-0.5 text-xs text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive","data-index":w,"data-testid":`db-saved-query-delete-${S.name}`,onClick:x,type:"button",children:"✕"})]},S.name))]}),e[18]=g,e[19]=x,e[20]=l,e[21]=r,e[22]=N):N=e[22];let k;return e[23]!==y||e[24]!==C||e[25]!==N?(k=E("div",{className:"flex flex-wrap items-center gap-1.5","data-testid":"db-query-bar",children:[y,C,N]}),e[23]=y,e[24]=C,e[25]=N,e[26]=k):k=e[26],k},Je="w-full rounded-md border border-border bg-background px-2 py-1 font-mono text-xs outline-none focus-visible:border-ring",an=/(?:_creationtime|(?:^|[a-z])(?:time|at))$/iu,Jt=(s,e)=>typeof e=="boolean"?"boolean":typeof e=="number"?an.test(s)?"date":"number":e!==null&&typeof e=="object"?"json":"text",vs=(s,e,n)=>n===void 0?Jt(s,e):n.enumValues!==void 0&&n.enumValues.length>0?"enum":n.type==="boolean"?"boolean":n.type==="number"?an.test(s)?"date":"number":Jt(s,e),ws=s=>{try{const e=JSON.parse(s);return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}catch{return null}},ys=s=>{const e=new Date(s),n=o=>String(o).padStart(2,"0");return`${e.getFullYear().toString()}-${n(e.getMonth()+1)}-${n(e.getDate())}T${n(e.getHours())}:${n(e.getMinutes())}`},Ke="\0clear",Cs=s=>{const e=B(23),{column:n,nullable:o,onChange:t,value:c}=s,l=he();let r;e[0]!==n||e[1]!==t?(r=v=>{t(n,v)},e[0]=n,e[1]=t,e[2]=r):r=e[2];const a=r;let i;e[3]!==n||e[4]!==t?(i=v=>{t(n,v.target.value===Ke?null:v.target.value==="true")},e[3]=n,e[4]=t,e[5]=i):i=e[5];const m=i;if(!o&&c!==null){const v=c===!0,y=`db-field-${n}`;let C;return e[6]!==n||e[7]!==a||e[8]!==v||e[9]!==y?(C=d($t,{"aria-label":n,checked:v,"data-testid":y,onCheckedChange:a}),e[6]=n,e[7]=a,e[8]=v,e[9]=y,e[10]=C):C=e[10],C}const f=`db-field-${n}`,p=c===!0||c===!1?String(c):Ke;let b;e[11]!==l?(b=l("(none)"),e[11]=l,e[12]=b):b=e[12];let u;e[13]!==b?(u=d("option",{value:Ke,children:b}),e[13]=b,e[14]=u):u=e[14];let g,h;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=d("option",{value:"true",children:"true"}),h=d("option",{value:"false",children:"false"}),e[15]=g,e[16]=h):(g=e[15],h=e[16]);let x;return e[17]!==n||e[18]!==m||e[19]!==f||e[20]!==p||e[21]!==u?(x=E("select",{"aria-label":n,className:Je,"data-testid":f,onChange:m,value:p,children:[u,g,h]}),e[17]=n,e[18]=m,e[19]=f,e[20]=p,e[21]=u,e[22]=x):x=e[22],x},Ns=s=>{const e=B(23),{column:n,nullable:o,onChange:t,options:c,value:l}=s,r=he(),a=typeof l=="string"?l:null;let i;e[0]!==c||e[1]!==a?(i=a!==null&&!c.includes(a),e[0]=c,e[1]=a,e[2]=i):i=e[2];const m=i;let f;e[3]!==n||e[4]!==t?(f=y=>{t(n,y.target.value===Ke?null:y.target.value)},e[3]=n,e[4]=t,e[5]=f):f=e[5];const p=f,b=`db-field-${n}`,u=a??Ke;let g;e[6]!==o||e[7]!==a||e[8]!==r?(g=(o||a===null)&&d("option",{value:Ke,children:r("(none)")}),e[6]=o,e[7]=a,e[8]=r,e[9]=g):g=e[9];let h;e[10]!==a||e[11]!==m?(h=m&&d("option",{value:a,children:a}),e[10]=a,e[11]=m,e[12]=h):h=e[12];let x;e[13]!==c?(x=c.map($s),e[13]=c,e[14]=x):x=e[14];let v;return e[15]!==n||e[16]!==p||e[17]!==b||e[18]!==u||e[19]!==g||e[20]!==h||e[21]!==x?(v=E("select",{"aria-label":n,className:Je,"data-testid":b,onChange:p,value:u,children:[g,h,x]}),e[15]=n,e[16]=p,e[17]=b,e[18]=u,e[19]=g,e[20]=h,e[21]=x,e[22]=v):v=e[22],v},Ss=s=>{const e=B(8),{column:n,onChange:o,value:t}=s;let c;e[0]!==n||e[1]!==o?(c=m=>{const f=Number(m.target.value);m.target.value!==""&&!Number.isNaN(f)&&o(n,f)},e[0]=n,e[1]=o,e[2]=c):c=e[2];const l=c,r=`db-field-${n}`,a=typeof t=="number"?t:"";let i;return e[3]!==n||e[4]!==l||e[5]!==r||e[6]!==a?(i=d("input",{"aria-label":n,className:Je,"data-testid":r,onChange:l,type:"number",value:a}),e[3]=n,e[4]=l,e[5]=r,e[6]=a,e[7]=i):i=e[7],i},ks=s=>{const e=B(10),{column:n,onChange:o,value:t}=s;let c;e[0]!==n||e[1]!==o?(c=m=>{const f=new Date(m.target.value).getTime();Number.isNaN(f)||o(n,f)},e[0]=n,e[1]=o,e[2]=c):c=e[2];const l=c,r=`db-field-${n}`;let a;e[3]!==t?(a=typeof t=="number"?ys(t):"",e[3]=t,e[4]=a):a=e[4];let i;return e[5]!==n||e[6]!==l||e[7]!==r||e[8]!==a?(i=d("input",{"aria-label":n,className:Je,"data-testid":r,onChange:l,type:"datetime-local",value:a}),e[5]=n,e[6]=l,e[7]=r,e[8]=a,e[9]=i):i=e[9],i},Ts=s=>{const e=B(8),{column:n,onChange:o,value:t}=s;let c;e[0]!==n||e[1]!==o?(c=m=>{o(n,m.target.value)},e[0]=n,e[1]=o,e[2]=c):c=e[2];const l=c,r=`db-field-${n}`,a=typeof t=="string"?t:"";let i;return e[3]!==n||e[4]!==l||e[5]!==r||e[6]!==a?(i=d("input",{"aria-label":n,className:Je,"data-testid":r,onChange:l,type:"text",value:a}),e[3]=n,e[4]=l,e[5]=r,e[6]=a,e[7]=i):i=e[7],i},Es=s=>{const e=B(20),{column:n,onChange:o,value:t}=s,c=he();let l;e[0]!==t?(l=()=>JSON.stringify(t,null,2),e[0]=t,e[1]=l):l=e[1];const[r,a]=D(l),[i,m]=D(!1);let f;e[2]!==n||e[3]!==o?(f=y=>{const C=y.target.value;a(C);try{o(n,JSON.parse(C)),m(!1)}catch{m(!0)}},e[2]=n,e[3]=o,e[4]=f):f=e[4];const p=f,b=i&&"border-destructive";let u;e[5]!==b?(u=ct(Je,"min-h-16",b),e[5]=b,e[6]=u):u=e[6];const g=`db-field-${n}`;let h;e[7]!==n||e[8]!==p||e[9]!==u||e[10]!==g||e[11]!==r?(h=d("textarea",{"aria-label":n,className:u,"data-testid":g,onChange:p,value:r}),e[7]=n,e[8]=p,e[9]=u,e[10]=g,e[11]=r,e[12]=h):h=e[12];let x;e[13]!==n||e[14]!==i||e[15]!==c?(x=i&&d("span",{className:"text-xs text-destructive","data-testid":`db-field-error-${n}`,children:c("Invalid JSON")}),e[13]=n,e[14]=i,e[15]=c,e[16]=x):x=e[16];let v;return e[17]!==h||e[18]!==x?(v=E("div",{className:"flex flex-col gap-1",children:[h,x]}),e[17]=h,e[18]=x,e[19]=v):v=e[19],v},_s=s=>{const e=B(56),{column:n,meta:o,onChange:t,target:c,value:l}=s;let r;e[0]!==n||e[1]!==o||e[2]!==l?(r=vs(n,l,o),e[0]=n,e[1]=o,e[2]=l,e[3]=r):r=e[3];const a=r,i=`db-field-${n}`;let m;e[4]!==n?(m=d("span",{className:"font-mono",children:n}),e[4]=n,e[5]=m):m=e[5];let f;e[6]!==n||e[7]!==o?(f=o!==void 0&&d("span",{className:"rounded bg-muted px-1 font-mono text-[10px] tracking-wide","data-testid":`db-field-type-${n}`,children:o.type}),e[6]=n,e[7]=o,e[8]=f):f=e[8];let p;e[9]!==c?(p=c!==void 0&&E("span",{className:"rounded bg-muted px-1 font-mono text-[10px] tracking-wide uppercase",children:["→ ",c]}),e[9]=c,e[10]=p):p=e[10];let b;e[11]!==m||e[12]!==f||e[13]!==p?(b=E("span",{className:"flex items-center gap-1.5 font-medium text-muted-foreground",children:[m,f,p]}),e[11]=m,e[12]=f,e[13]=p,e[14]=b):b=e[14];let u;e[15]!==n||e[16]!==a||e[17]!==o?.nullable||e[18]!==t||e[19]!==l?(u=a==="boolean"&&d(Cs,{column:n,nullable:o?.nullable===!0,onChange:t,value:l}),e[15]=n,e[16]=a,e[17]=o?.nullable,e[18]=t,e[19]=l,e[20]=u):u=e[20];let g;e[21]!==n||e[22]!==a||e[23]!==o||e[24]!==t||e[25]!==l?(g=a==="enum"&&o?.enumValues!==void 0&&d(Ns,{column:n,nullable:o.nullable===!0,onChange:t,options:o.enumValues,value:l}),e[21]=n,e[22]=a,e[23]=o,e[24]=t,e[25]=l,e[26]=g):g=e[26];let h;e[27]!==n||e[28]!==a||e[29]!==t||e[30]!==l?(h=a==="number"&&d(Ss,{column:n,onChange:t,value:l}),e[27]=n,e[28]=a,e[29]=t,e[30]=l,e[31]=h):h=e[31];let x;e[32]!==n||e[33]!==a||e[34]!==t||e[35]!==l?(x=a==="date"&&d(ks,{column:n,onChange:t,value:l}),e[32]=n,e[33]=a,e[34]=t,e[35]=l,e[36]=x):x=e[36];let v;e[37]!==n||e[38]!==a||e[39]!==t||e[40]!==l?(v=a==="json"&&d(Es,{column:n,onChange:t,value:l}),e[37]=n,e[38]=a,e[39]=t,e[40]=l,e[41]=v):v=e[41];let y;e[42]!==n||e[43]!==a||e[44]!==t||e[45]!==l?(y=a==="text"&&d(Ts,{column:n,onChange:t,value:l}),e[42]=n,e[43]=a,e[44]=t,e[45]=l,e[46]=y):y=e[46];let C;return e[47]!==x||e[48]!==v||e[49]!==y||e[50]!==i||e[51]!==b||e[52]!==u||e[53]!==g||e[54]!==h?(C=E("label",{className:"flex flex-col gap-1 text-xs",htmlFor:i,children:[b,u,g,h,x,v,y]}),e[47]=x,e[48]=v,e[49]=y,e[50]=i,e[51]=b,e[52]=u,e[53]=g,e[54]=h,e[55]=C):C=e[55],C},Rs=s=>{const e=B(49),{columnMeta:n,documentText:o,onCancel:t,onDocumentTextChange:c,onSave:l,refs:r}=s,a=he();let i;e[0]!==o?(i=ws(o),e[0]=o,e[1]=i):i=e[1];const m=i,[f,p]=D(!1),b=!f&&m!==null;let u;e[2]!==m||e[3]!==c?(u=(V,J)=>{c(JSON.stringify({...m,[V]:J},null,2))},e[2]=m,e[3]=c,e[4]=u):u=e[4];const g=u;let h;e[5]!==c?(h=V=>{c(V.target.value)},e[5]=c,e[6]=h):h=e[6];const x=h;let v;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{p(!1)},e[7]=v):v=e[7];const y=v;let C;e[8]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{p(!0)},e[8]=C):C=e[8];const N=C,k=m===null;let S;e[9]!==a?(S=a("Form"),e[9]=a,e[10]=S):S=e[10];let w;e[11]!==b||e[12]!==k||e[13]!==S?(w=d("button",{"aria-pressed":b,className:De,"data-testid":"db-editor-form",disabled:k,onClick:y,type:"button",children:S}),e[11]=b,e[12]=k,e[13]=S,e[14]=w):w=e[14];const T=!b;let I;e[15]!==a?(I=a("JSON"),e[15]=a,e[16]=I):I=e[16];let R;e[17]!==I||e[18]!==T?(R=d("button",{"aria-pressed":T,className:De,"data-testid":"db-editor-json",onClick:N,type:"button",children:I}),e[17]=I,e[18]=T,e[19]=R):R=e[19];let _;e[20]!==R||e[21]!==w?(_=E("div",{className:"flex items-center gap-1.5",children:[w,R]}),e[20]=R,e[21]=w,e[22]=_):_=e[22];let $;e[23]!==n||e[24]!==o||e[25]!==m||e[26]!==g||e[27]!==x||e[28]!==r||e[29]!==b||e[30]!==a?($=b?d("div",{className:"flex flex-col gap-3","data-testid":"db-editor-fields",children:Object.entries(m).map(V=>{const[J,K]=V;return d(_s,{column:J,meta:n?.[J],onChange:g,target:r?.[J],value:K},J)})}):d("textarea",{"aria-label":a("Row document JSON"),className:"min-h-28 w-full rounded-md border border-border bg-background px-2 py-1.5 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"db-editor-doc",onChange:x,value:o}),e[23]=n,e[24]=o,e[25]=m,e[26]=g,e[27]=x,e[28]=r,e[29]=b,e[30]=a,e[31]=$):$=e[31];let O;e[32]!==a?(O=a("Save"),e[32]=a,e[33]=O):O=e[33];let M;e[34]!==l||e[35]!==O?(M=d("button",{className:De,"data-testid":"db-editor-save",onClick:l,type:"button",children:O}),e[34]=l,e[35]=O,e[36]=M):M=e[36];let P;e[37]!==a?(P=a("Cancel"),e[37]=a,e[38]=P):P=e[38];let z;e[39]!==t||e[40]!==P?(z=d("button",{className:De,"data-testid":"db-editor-cancel",onClick:t,type:"button",children:P}),e[39]=t,e[40]=P,e[41]=z):z=e[41];let q;e[42]!==M||e[43]!==z?(q=E("div",{className:"flex items-center gap-1.5",children:[M,z]}),e[42]=M,e[43]=z,e[44]=q):q=e[44];let F;return e[45]!==_||e[46]!==$||e[47]!==q?(F=E("div",{className:"flex flex-col gap-2 border border-border bg-card p-3","data-testid":"db-editor",children:[_,$,q]}),e[45]=_,e[46]=$,e[47]=q,e[48]=F):F=e[48],F};function $s(s){return d("option",{value:s,children:s},s)}const Ds=s=>{const e=B(71),{columns:n,editable:o,filter:t,filters:c,hasMaskedColumns:l,hasPredicate:r,liveError:a,maskOn:i,onAddRow:m,onBulkDelete:f,onBulkPatch:p,onAskAiFilter:b,onClearTable:u,onFilterChange:g,onFiltersChange:h,onGenerateRows:x,onShowJson:v,onShowTable:y,onToggleMask:C,total:N,totalKnown:k,viewMode:S}=s,w=he(),T=S==="table";let I;e[0]!==y||e[1]!==T?(I=d("button",{"aria-pressed":T,className:De,"data-testid":"db-view-table",onClick:y,type:"button",children:"Table"}),e[0]=y,e[1]=T,e[2]=I):I=e[2];const R=S==="json";let _;e[3]!==v||e[4]!==R?(_=d("button",{"aria-pressed":R,className:De,"data-testid":"db-view-json",onClick:v,type:"button",children:"JSON"}),e[3]=v,e[4]=R,e[5]=_):_=e[5];let $;e[6]!==a||e[7]!==w?($=a===void 0?w("Live — changes stream in automatically"):w("Live unavailable: {liveError}",{liveError:a}),e[6]=a,e[7]=w,e[8]=$):$=e[8];const O=`size-1.5 rounded-full ${a===void 0?"bg-success":"bg-muted-foreground/50"}`;let M;e[9]!==O?(M=d("span",{"aria-hidden":"true",className:O}),e[9]=O,e[10]=M):M=e[10];let P;e[11]!==a||e[12]!==w?(P=w(a===void 0?"Live":"Live unavailable"),e[11]=a,e[12]=w,e[13]=P):P=e[13];let z;e[14]!==$||e[15]!==M||e[16]!==P?(z=E("span",{className:"inline-flex items-center gap-1.5 px-1 text-xs font-medium text-muted-foreground","data-testid":"db-live-indicator",role:"status",title:$,children:[M,P]}),e[14]=$,e[15]=M,e[16]=P,e[17]=z):z=e[17];let q;e[18]!==l||e[19]!==i||e[20]!==C||e[21]!==w?(q=l&&d("button",{"aria-pressed":i,className:De,"data-testid":"db-mask-toggle",onClick:C,type:"button",children:w("Mask sensitive columns")}),e[18]=l,e[19]=i,e[20]=C,e[21]=w,e[22]=q):q=e[22];let F;e[23]!==o||e[24]!==m?(F=o&&d("button",{className:De,"data-testid":"db-add-row",onClick:m,type:"button",children:"Add row"}),e[23]=o,e[24]=m,e[25]=F):F=e[25];let V;e[26]!==o||e[27]!==x||e[28]!==w?(V=o&&d("button",{className:De,"data-testid":"db-generate-rows",onClick:x,type:"button",children:w("Generate rows")}),e[26]=o,e[27]=x,e[28]=w,e[29]=V):V=e[29];let J;e[30]!==o||e[31]!==r||e[32]!==f||e[33]!==w||e[34]!==N||e[35]!==k?(J=o&&N>0&&r&&d(Lt,{confirmLabel:k?w("Delete {total} matching rows and everything that cascades?",{total:N.toString()}):w("Delete all matching rows and everything that cascades?"),onConfirm:f,testId:"db-bulk-delete",children:k?w("Delete {total} matching",{total:N.toString()}):w("Delete matching")}),e[30]=o,e[31]=r,e[32]=f,e[33]=w,e[34]=N,e[35]=k,e[36]=J):J=e[36];let K;e[37]!==o||e[38]!==r||e[39]!==p||e[40]!==w||e[41]!==N||e[42]!==k?(K=o&&k&&N>0&&r&&d("button",{className:De,"data-testid":"db-bulk-patch",onClick:p,type:"button",children:w("Set column on {total} matching",{total:N.toString()})}),e[37]=o,e[38]=r,e[39]=p,e[40]=w,e[41]=N,e[42]=k,e[43]=K):K=e[43];let Z;e[44]!==o||e[45]!==r||e[46]!==u||e[47]!==w||e[48]!==N||e[49]!==k?(Z=o&&N>0&&!r&&d(Lt,{confirmLabel:k?w("Clear all {total} rows and everything that cascades?",{total:N.toString()}):w("Clear every row and everything that cascades?"),onConfirm:u,testId:"db-clear-table",children:k?w("Clear table ({total})",{total:N.toString()}):w("Clear table")}),e[44]=o,e[45]=r,e[46]=u,e[47]=w,e[48]=N,e[49]=k,e[50]=Z):Z=e[50];let Y;e[51]!==q||e[52]!==F||e[53]!==V||e[54]!==J||e[55]!==K||e[56]!==Z||e[57]!==I||e[58]!==_||e[59]!==z?(Y=E("div",{className:"flex flex-wrap items-center gap-1.5",children:[I,_,z,q,F,V,J,K,Z]}),e[51]=q,e[52]=F,e[53]=V,e[54]=J,e[55]=K,e[56]=Z,e[57]=I,e[58]=_,e[59]=z,e[60]=Y):Y=e[60];let Q;e[61]!==n||e[62]!==t||e[63]!==c||e[64]!==b||e[65]!==g||e[66]!==h?(Q=d(go,{columns:n,filters:c,onAskAi:b,onFiltersChange:h,onSearchChange:g,search:t}),e[61]=n,e[62]=t,e[63]=c,e[64]=b,e[65]=g,e[66]=h,e[67]=Q):Q=e[67];let ne;return e[68]!==Y||e[69]!==Q?(ne=E("div",{className:"flex flex-col gap-2","data-testid":"db-view-toggle",children:[Y,Q]}),e[68]=Y,e[69]=Q,e[70]=ne):ne=e[70],ne},As=s=>{const e=B(110),{assistant:n,backRelations:o,browser:t,columnMeta:c,edit:l,editable:r,onAskAiFilter:a,onInspect:i,onOpenBulkPatch:m,onOpenGenerateRows:f,onRowDelete:p,onSaveQuery:b,page:u,preferences:g,queryBar:h,references:x}=s,v=g.maskColumns.size>0,y=n.unavailable?void 0:a;let C;e[0]!==t.addRow||e[1]!==t.bulkDelete||e[2]!==t.clearTable||e[3]!==t.columns||e[4]!==t.filter||e[5]!==t.filters||e[6]!==t.hasPredicate||e[7]!==t.liveError||e[8]!==t.onFilterChange||e[9]!==t.onFiltersChange||e[10]!==t.showJson||e[11]!==t.showTable||e[12]!==t.total||e[13]!==t.totalKnown||e[14]!==t.viewMode||e[15]!==r||e[16]!==m||e[17]!==f||e[18]!==g.maskOn||e[19]!==g.onToggleMask||e[20]!==v||e[21]!==y?(C=d(Ds,{columns:t.columns,editable:r,filter:t.filter,filters:t.filters,hasMaskedColumns:v,hasPredicate:t.hasPredicate,liveError:t.liveError,maskOn:g.maskOn,onAddRow:t.addRow,onAskAiFilter:y,onBulkDelete:t.bulkDelete,onBulkPatch:m,onClearTable:t.clearTable,onFilterChange:t.onFilterChange,onFiltersChange:t.onFiltersChange,onGenerateRows:f,onShowJson:t.showJson,onShowTable:t.showTable,onToggleMask:g.onToggleMask,total:t.total,totalKnown:t.totalKnown,viewMode:t.viewMode}),e[0]=t.addRow,e[1]=t.bulkDelete,e[2]=t.clearTable,e[3]=t.columns,e[4]=t.filter,e[5]=t.filters,e[6]=t.hasPredicate,e[7]=t.liveError,e[8]=t.onFilterChange,e[9]=t.onFiltersChange,e[10]=t.showJson,e[11]=t.showTable,e[12]=t.total,e[13]=t.totalKnown,e[14]=t.viewMode,e[15]=r,e[16]=m,e[17]=f,e[18]=g.maskOn,e[19]=g.onToggleMask,e[20]=v,e[21]=y,e[22]=C):C=e[22];let N;e[23]!==b||e[24]!==h?(N=h!==void 0&&d(xs,{onApply:h.onApplyQuery,onCopyLink:h.onCopyLink,onDelete:h.onDeleteQuery,onSave:b,saved:h.saved}),e[23]=b,e[24]=h,e[25]=N):N=e[25];let k;e[26]!==o||e[27]!==t.onBulkDeleteSelected||e[28]!==t.selectedTable||e[29]!==t.table||e[30]!==t.viewMode||e[31]!==r||e[32]!==u||e[33]!==g.maskView||e[34]!==g.onToggleTranspose||e[35]!==g.transposed?(k=t.viewMode==="table"&&u.rows.length>0&&d(po,{backRelations:o.available,columns:u.columns,editable:r,enabledBackRelations:o.enabled,name:t.selectedTable??"export",onBulkDelete:t.onBulkDeleteSelected,onToggleBackRelation:o.onToggle,onToggleTranspose:g.onToggleTranspose,rows:vt(u.rows,g.maskView),sqlColumns:u.sqlColumns,table:t.table.table,transposed:g.transposed}),e[26]=o,e[27]=t.onBulkDeleteSelected,e[28]=t.selectedTable,e[29]=t.table,e[30]=t.viewMode,e[31]=r,e[32]=u,e[33]=g.maskView,e[34]=g.onToggleTranspose,e[35]=g.transposed,e[36]=k):k=e[36];let S;e[37]!==t.cancelEdit||e[38]!==t.editing||e[39]!==t.saveEdit||e[40]!==t.setEditorDocumentText||e[41]!==c||e[42]!==r||e[43]!==u?(S=r&&t.editing!==null&&d(Rs,{columnMeta:c,documentText:t.editing.docText,onCancel:t.cancelEdit,onDocumentTextChange:t.setEditorDocumentText,onSave:t.saveEdit,refs:u.refs}),e[37]=t.cancelEdit,e[38]=t.editing,e[39]=t.saveEdit,e[40]=t.setEditorDocumentText,e[41]=c,e[42]=r,e[43]=u,e[44]=S):S=e[44];let w;e[45]!==t.committing||e[46]!==t.discardStaged||e[47]!==t.onCommitStaged||e[48]!==t.stagedChanges||e[49]!==r?(w=r&&t.stagedChanges.length>0&&d(Fo,{changes:t.stagedChanges,committing:t.committing,onCommit:t.onCommitStaged,onDiscard:t.discardStaged}),e[45]=t.committing,e[46]=t.discardStaged,e[47]=t.onCommitStaged,e[48]=t.stagedChanges,e[49]=r,e[50]=w):w=e[50];let T;e[51]!==t.writeError?(T=t.writeError!==null&&d("p",{className:"text-sm text-destructive","data-testid":"db-write-error",role:"alert",children:t.writeError}),e[51]=t.writeError,e[52]=T):T=e[52];let I;e[53]!==t.writeNotice?(I=t.writeNotice!==null&&d("p",{className:"text-sm text-muted-foreground","data-testid":"db-write-notice",role:"status",children:t.writeNotice}),e[53]=t.writeNotice,e[54]=I):I=e[54];let R;e[55]!==C||e[56]!==N||e[57]!==k||e[58]!==S||e[59]!==w||e[60]!==T||e[61]!==I?(R=E("div",{className:"flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3",children:[C,N,k,S,w,T,I]}),e[55]=C,e[56]=N,e[57]=k,e[58]=S,e[59]=w,e[60]=T,e[61]=I,e[62]=R):R=e[62];let _;e[63]!==t.viewMode||e[64]!==u?(_=t.viewMode==="table"&&u.rows.length===0&&d("div",{className:"flex flex-1 items-center justify-center p-6",children:d(Hn,{description:"Rows you insert into this table will show up here.",icon:d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"M4 5h16v14H4V5Zm0 5h16M10 10v9M4 14.5h16"})}),testId:"db-empty-rows",title:"This table is empty."})}),e[63]=t.viewMode,e[64]=u,e[65]=_):_=e[65];let $;e[66]!==t.viewMode||e[67]!==u||e[68]!==g.maskView||e[69]!==g.transposed?($=t.viewMode==="table"&&u.rows.length>0&&g.transposed&&d(mo,{columns:u.columns,rows:vt(u.rows,g.maskView)}),e[66]=t.viewMode,e[67]=u,e[68]=g.maskView,e[69]=g.transposed,e[70]=$):$=e[70];let O;e[71]!==o||e[72]!==t.filter||e[73]!==t.onRowEdit||e[74]!==t.table||e[75]!==t.viewMode||e[76]!==c||e[77]!==l||e[78]!==r||e[79]!==i||e[80]!==p||e[81]!==u||e[82]!==g.maskView||e[83]!==g.onTogglePin||e[84]!==g.pinnedColumns||e[85]!==g.transposed||e[86]!==x?(O=t.viewMode==="table"&&u.rows.length>0&&!g.transposed&&d(cs,{backRelationCounts:o.counts,columnMeta:c,edit:l,editable:r,highlight:t.filter,mask:g.maskView,onDelete:p,onEdit:t.onRowEdit,onInspect:i,onTogglePin:g.onTogglePin,pinnedColumns:g.pinnedColumns,refs:x,tableModel:t.table}),e[71]=o,e[72]=t.filter,e[73]=t.onRowEdit,e[74]=t.table,e[75]=t.viewMode,e[76]=c,e[77]=l,e[78]=r,e[79]=i,e[80]=p,e[81]=u,e[82]=g.maskView,e[83]=g.onTogglePin,e[84]=g.pinnedColumns,e[85]=g.transposed,e[86]=x,e[87]=O):O=e[87];let M;e[88]!==t.viewMode||e[89]!==u||e[90]!==g.maskView?(M=t.viewMode==="json"&&d("pre",{className:"min-h-0 flex-1 overflow-auto border-t border-border bg-muted/30 p-3 text-xs","data-testid":"db-json",children:JSON.stringify(vt(u.rows,g.maskView),Yt,2)}),e[88]=t.viewMode,e[89]=u,e[90]=g.maskView,e[91]=M):M=e[91];let P;e[92]!==t.changePageSize||e[93]!==t.goNext||e[94]!==t.goPrevious||e[95]!==t.hasNext||e[96]!==t.hasPrevious||e[97]!==t.jumpToPage||e[98]!==t.pageSize||e[99]!==t.rangeEnd||e[100]!==t.rangeStart||e[101]!==t.total?(P=d("div",{className:"flex shrink-0 items-center border-t border-border px-4 py-2",children:d(Bn,{hasNext:t.hasNext,hasPrevious:t.hasPrevious,onJumpToPage:t.jumpToPage,onNext:t.goNext,onPageSizeChange:t.changePageSize,onPrevious:t.goPrevious,pageSize:t.pageSize,prefix:"db",rangeEnd:t.rangeEnd,rangeStart:t.rangeStart,total:t.total})}),e[92]=t.changePageSize,e[93]=t.goNext,e[94]=t.goPrevious,e[95]=t.hasNext,e[96]=t.hasPrevious,e[97]=t.jumpToPage,e[98]=t.pageSize,e[99]=t.rangeEnd,e[100]=t.rangeStart,e[101]=t.total,e[102]=P):P=e[102];let z;return e[103]!==R||e[104]!==_||e[105]!==$||e[106]!==O||e[107]!==M||e[108]!==P?(z=E("div",{className:"flex min-h-0 flex-1 flex-col","data-testid":"db-page",children:[R,_,$,O,M,P]}),e[103]=R,e[104]=_,e[105]=$,e[106]=O,e[107]=M,e[108]=P,e[109]=z):z=e[109],z},Is="/__lunora/seed",St=200,Ps=50,Os=(s,e)=>{const n=[];for(const o of s)o.pk!==!0&&o.ref!==void 0&&o.type==="id"&&(e[o.ref]??[]).length===0&&n.push(o.name);return n},Fs=s=>Array.isArray(s)&&s.every(e=>Zt(e)),Ms=async s=>{let e;try{e=await fetch(Is,{body:JSON.stringify(s),headers:{"Content-Type":"application/json"},method:"POST"})}catch(o){return{kind:"error",message:`seed request failed: ${Ft(o)}`}}let n;try{n=await e.json()??{}}catch{return{kind:"error",message:`seed request failed (${String(e.status)})`}}if(e.ok&&n.rows!==void 0){let o;try{o=Rt(n.rows)}catch(t){return{kind:"error",message:`seed response could not be decoded: ${Ft(t)}`}}return Fs(o)?{kind:"ok",rows:o}:{kind:"error",message:"seed response did not carry a list of row documents"}}return n.error==="fk-parents-empty"?{kind:"error",message:`no rows to reference in ${(Array.isArray(n.tables)?n.tables.filter(t=>typeof t=="string"):[]).join(", ")} — seed those tables first`}:{kind:"error",message:typeof n.error=="string"?n.error:`seed request failed (${String(e.status)})`}},Ls="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",Vs="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",Bs=({columns:s,fkPools:e,onClose:n,onInsertRows:o,table:t})=>{const c=he(),[l,r]=D(10),[a,i]=D(!1),[m,f]=D(void 0),[p,b]=D(void 0),[u,g]=D(0),h=N=>{const k=Number(N.target.value);!Number.isNaN(k)&&k>=1&&r(Math.min(k,St))},x=async()=>{f(void 0),b(void 0),g(0),i(!0);try{const N=await Ms({count:l,existingIds:e,seed:Date.now(),table:t});if(N.kind==="error"){f(N.message);return}const{rows:k}=N;if(k.length===0){f(c("No rows generated — all columns were skipped."));return}const S=await o(k);if(S.error!==void 0){f(S.error);return}b(S.inserted),g(S.conflicts)}finally{i(!1)}},v=()=>{Ce(x())},y=s.filter(N=>N.pk!==!0),C=Os(s,e);return E(ut,{label:c("Generate dummy rows"),onClose:n,panelTestId:"gen-rows-panel",testId:"gen-rows-overlay",variant:"dialog",children:[E("div",{className:"flex items-start justify-between",children:[E("div",{className:"flex flex-col gap-0.5",children:[d("h3",{className:"text-base text-foreground","data-testid":"gen-rows-title",children:c("Generate dummy rows")}),d("p",{className:"text-xs text-muted-foreground","data-testid":"gen-rows-desc",children:c("Seed {table} with Faker-generated rows. Existing rows are not affected.",{table:t})})]}),d("button",{className:"text-xs text-muted-foreground hover:text-foreground","data-testid":"gen-rows-close",onClick:n,type:"button",children:c("Close")})]}),E("div",{className:"flex items-center gap-2",children:[d("label",{className:"text-xs font-medium text-foreground",htmlFor:"gen-rows-count",children:c("Row count")}),d("input",{className:"w-20 rounded-md border border-border bg-background px-2 py-1 text-xs outline-none focus-visible:border-ring","data-testid":"gen-rows-count",id:"gen-rows-count",max:St,min:1,onChange:h,type:"number",value:l}),d("span",{className:"text-xs text-muted-foreground",children:c("(max {max})",{max:St.toString()})})]}),y.length>0&&E("div",{className:"flex flex-col gap-1",children:[d("p",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:c("Columns to seed")}),d("ul",{className:"flex flex-col gap-0.5","data-testid":"gen-rows-columns",children:y.map(N=>{const k=N.ref!==void 0&&N.type==="id",S=k&&(e[N.ref??""]??[]).length===0,w=S?"rounded bg-destructive/10 px-1 text-destructive":"rounded bg-muted px-1 text-muted-foreground",T=S?`gen-rows-fk-empty-${N.name}`:`gen-rows-fk-ok-${N.name}`,I=S?c("FK: no rows in {ref} — seed it first",{ref:N.ref??""}):c("→ {ref}",{ref:N.ref??""});return E("li",{className:"flex items-center gap-1.5 font-mono text-xs",children:[d("span",{className:"text-foreground",children:N.name}),E("span",{className:"text-muted-foreground",children:["(",N.type,")"]}),N.optional&&d("span",{className:"rounded bg-muted px-1 font-mono text-[10px] tracking-wide uppercase",children:"optional"}),k&&d("span",{className:w,"data-testid":T,children:I})]},N.name)})})]}),C.length>0&&d("p",{className:"text-xs text-destructive","data-testid":"gen-rows-blocked",role:"alert",children:c("Cannot generate rows: these columns reference tables with no rows: {cols}. Seed those tables first.",{cols:C.join(", ")})}),m!==void 0&&d("p",{className:"text-xs text-destructive","data-testid":"gen-rows-error",role:"alert",children:m}),p!==void 0&&m===void 0&&d("p",{className:"text-xs text-success","data-testid":"gen-rows-success",children:u>0?c("Inserted {inserted} of {total} rows — {conflicts} skipped as id conflicts.",{conflicts:u.toString(),inserted:p.toString(),total:(p+u).toString()}):c("Inserted {count} rows successfully.",{count:p.toString()})}),E("div",{className:"flex justify-end gap-2",children:[d("button",{className:Ls,"data-testid":"gen-rows-cancel",onClick:n,type:"button",children:c("Cancel")}),d("button",{className:Vs,"data-testid":"gen-rows-generate",disabled:a||C.length>0,onClick:v,type:"button",children:c(a?"Inserting…":"Generate & insert")})]})]})},js=Te(pe.backRelationCounts),zs=(s,e,n,o)=>{const t=B(16),c=dt();let l;t[0]===Symbol.for("react.memo_cache_sentinel")?(l={},t[0]=l):l=t[0];const[r,a]=D(l);let i;if(t[1]!==s||t[2]!==e){let x;t[4]!==s?(x=v=>s.has(Dt(v)),t[4]=s,t[5]=x):x=t[5],i=e.filter(x),t[1]=s,t[2]=e,t[3]=i}else i=t[3];const m=i;let f;t[6]!==n||t[7]!==m?(f=JSON.stringify([m,n]),t[6]=n,t[7]=m,t[8]=f):f=t[8];const p=f;let b;t[9]!==c||t[10]!==o||t[11]!==p?(b=async x=>{const[v,y]=JSON.parse(p);if(v.length===0||y.length===0){x.cancelled||a({});return}try{const C=await c.query(js,{ids:y,relations:v},ke(o));x.cancelled||a(Object.fromEntries(C.relations.map(qs)))}catch{}},t[9]=c,t[10]=o,t[11]=p,t[12]=b):b=t[12];const u=b;let g,h;return t[13]!==u?(g=()=>{const x={cancelled:!1};return Ce(u(x)),()=>{x.cancelled=!0}},h=[u],t[13]=u,t[14]=g,t[15]=h):(g=t[14],h=t[15]),Be(g,h),r};function qs(s){return[Dt(s),s.counts]}const Ks=async s=>{const{args:e,maxBatches:n,openCursor:o,query:t}=s;let c=o,l=0,r="cap-hit";for(let a=0;a<n;a+=1){const i=await t({...e,after:c});if(l+=i.count,c=i.cursor,!i.hasMore){r="completed";break}}return{cursor:r==="cap-hit"?c:void 0,outcome:r,written:l}},at=s=>{const e=s[0];return e===void 0?void 0:{column:e.id,direction:e.desc?"desc":"asc"}},cn=s=>s==null?"":typeof s=="object"?JSON.stringify(s):String(s),Wt=s=>s.map(e=>({column:e.column,...e.value===void 0?{}:{literal:[e.value]},operator:e.operator,value:e.value===void 0?"":cn(e.value)})),Ht=s=>s===void 0?[]:[{desc:s.direction==="desc",id:s.column}],Gs=s=>[s.column,s.operator,s.value],lt=(s,e,n,o)=>JSON.stringify([s??"",e??"",(n??[]).map(t=>Gs(t)),o===void 0?null:[o.column,o.direction]]),It=200,Js=20,Ws=Te(pe.readTablePage),Hs=Te(pe.facetColumn),kt=Te(pe.writeRow),Us=Te(pe.deleteRows),Qs=Te(pe.clearTable),Ys=Te(pe.patchRows),Xs={},Pt=new Set(["__doc__","__id__","_creationTime","_id","id"]),Zs=s=>{const e=s.__doc__;if(typeof e=="string"){const o=Jn(e);if(o!==void 0)return o}const n={};for(const[o,t]of Object.entries(s))Pt.has(o)||(n[o]=t);return n},el=(s,e,n)=>JSON.stringify([s.__lunoraRef,n,en(e)]),tl=({filters:s,offset:e,pageSize:n,search:o,sorting:t,table:c})=>({filters:Fe(s),limit:n,offset:e,orderBy:at(t),search:o,skipCount:!0,table:c}),nl=({filters:s,search:e,table:n})=>({filters:Fe(s),limit:1,search:e,table:n}),ol=(s,e)=>{const n=new Map;for(const t of s?.rows??[]){const c=Ae(t);c!==null&&n.set(c,t)}const o=[];for(const[t,c]of Object.entries(e))for(const[l,r]of Object.entries(c))o.push({column:l,newValue:r,oldValue:n.get(t)?.[l],rowId:t});return o},sl=s=>!Pt.has(s),ll=`Stopped after ${It.toString()} batches — rows still match. Run it again to remove the rest.`,rl=`Stopped after ${It.toString()} batches — rows still match. Run it again to set the rest.`,Ut={resumable:!1,truncated:ll,verb:"deleted"},al={resumable:!0,truncated:rl,verb:"written"},il=({initialFilters:s,initialOrderBy:e,initialSearch:n,initialShardKey:o,onSelectTable:t,onViewChange:c,pageSize:l,resolveBackRelations:r,tableParam:a})=>{const i=dt(),[m,f]=D(l),[p,b]=D(o??""),u=a===void 0||a===""?null:a,[g,h]=D(0),[x,v]=D("table"),[y,C]=D(()=>Ht(e)),[N,k]=D(n??""),[S,w]=D(()=>Wt(s??[])),{clearFacets:T,facets:I,refetchFacets:R,toggleFacet:_}=jn(),[$,O]=D(null),[M,P]=D(null),[z,q]=D(null),F=Ge(null),V=Oo(),[J,K]=D(null),[Z,Y]=D(!1),[Q,ne]=D(a),[oe,de]=D(()=>lt(o,n,s,e)),[ue,me]=D(0),[re,fe]=D(()=>lt(o,n,s,e)),ae=a!==Q,X=lt(o,n,s,e),te=ae||!ae&&X!==oe&&X!==re;if(te){ne(a),de(X),me(j=>j+1),C(Ht(e)),k(n??"");const A=Wt(s??[]);w(A),b(o??""),T(),V.clear(),K(null),h(0),P(null),q(null),F.current=null}else X!==oe&&de(X);const xe=te?n??"":N,ie=te?o??"":p,ce=`${a??""}:${ue.toString()}`,W=Vt(xe.trim(),300,ce),G=Vt(ie.trim(),400,ce),ee=lt(G,W,Fe(S),at(y));ee!==re&&fe(ee);const H=Xe(pe.listTables,Xs,{live:!0,shardKey:G}),ve=H.data??null,ge=H.error,we=tl({filters:S,offset:g,pageSize:m,search:W,sorting:y,table:u??""}),ye=nl({filters:S,search:W,table:u??""}),U=Xe(pe.readTablePage,we,{enabled:u!==null,keepPreviousData:!1,live:!0,shardKey:G}),se=U.data??null,Me=U.error,{liveError:Ie}=U,Pe=Xe(pe.readTablePage,ye,{enabled:u!==null,live:!0,shardKey:G});Be(()=>{H.data!==void 0&&ho(G)},[H.data,G]);const We=A=>{t?.(A)},Se=(A,j)=>{t?.(A,{search:j})},ze=async(A,j)=>{try{return(await i.query(Ws,{filters:[],limit:Js,offset:0,search:j,table:A},ke(G))).rows.find(_e=>Ae(_e)===j)??null}catch{return null}},Le=(A,j,Ne,_e)=>$e=>i.query(Hs,{column:$e,filters:Fe(Ne),search:_e,table:j},ke(A)),He=A=>{_(A,u===null?null:Le(G,u,S,W))},ft=(A,j)=>{const Ne={column:A,literal:[j],operator:"eq",value:cn(j)};w(_e=>[..._e.filter($e=>$e.column!==A),Ne]),h(0)},mt=wt(Le),et=wt(R),tt=wt(c);Be(()=>{u!==null&&et.current(mt.current(G,u,S,W))},[G,u,S,W]),Be(()=>{u===null||tt.current===void 0||Q!==a||oe!==X||tt.current({filters:Fe(S),orderBy:at(y),search:W,shard:G})},[u,a,Q,oe,X,S,y,W,G]);const Ue=A=>{u!==null&&h(Math.max(0,A))},nt=(A,j)=>{K({column:j,rowId:A})},gt=()=>{K(null)},pt=async()=>{if(u!==null){P(null),Y(!0);try{for(const[A,j]of Object.entries(V.staged))await i.query(kt,{doc:j,id:A,op:"patch",table:u},ke(G)),V.drop(A,j)}catch(A){P(A.message)}K(null),U.refetch(),Y(!1)}},bt=()=>{V.clear(),K(null)},ht=ol(se,V.staged),ot=async(A,j,Ne)=>{if(u===null)return;P(null);let _e;if(A!=="delete"){let $e;try{$e=Ne===void 0||Ne.trim()===""?{}:JSON.parse(Ne)}catch(Ve){P(`Invalid JSON: ${Ve.message}`);return}try{const Ve=Rt($e);if(!Zt(Ve)){P("The document must be a JSON object.");return}_e=Ve}catch(Ve){P(`Invalid document: ${Ve.message}`);return}}try{await i.query(kt,{doc:_e,id:j??void 0,op:A,table:u},ke(G)),O(null),U.refetch()}catch($e){P($e.message)}},Qe=async(A,j,Ne)=>{if(u===null)return 0;P(null),q(null);const _e=el(A,j,G),$e=F.current?.key===_e?F.current.after:void 0,Ve=Ne.resumable?$e??"":void 0;let qe=0;try{const Ye=await Ks({args:j,maxBatches:It,openCursor:Ve,query:async Fn=>{const Ot=await i.query(A,Fn,ke(G));return qe+=Ot.count,Ot}});return F.current=Ye.cursor===void 0?null:{after:Ye.cursor,key:_e},Ye.outcome==="cap-hit"&&P(Ne.truncated),q(`${qe.toString()} ${qe===1?"row":"rows"} ${Ne.verb}.`),qe}catch(Ye){return P(`${Ye.message} (at least ${qe.toString()} rows were already ${Ne.verb})`),F.current=null,qe}finally{h(0),U.refetch()}},xt=A=>{C(A),h(0)},L=Tt(()=>u===null?[]:r?.(u)??[],[r,u]),le=ds(se,y,xt,L),Ee={filters:Fe(S),orderBy:at(y),search:W,shard:p,table:u??void 0},Re=Pe.data?.total,Oe=Re!==void 0,st=Re??(se===null?0:g+se.rows.length),dn=g>0,un=W!==""||Fe(S).length>0,fn=se!==null&&(Oe?g+se.rows.length<st:se.rows.length===m),mn=se===null||se.rows.length===0?0:g+1,gn=se===null?0:g+se.rows.length,pn=()=>{H.refetch()},bn=()=>{v("table")},hn=()=>{v("json")},xn=()=>{Ce(Qe(Us,{filters:Fe(S),search:W,table:u},Ut))},vn=()=>{Ce(Qe(Qs,{table:u},Ut))},wn=A=>{Ce(Qe(Ys,{doc:A,filters:Fe(S),search:W,table:u},al))},yn=A=>{k(A.target.value),h(0)},Cn=A=>{w(A),h(0)},Nn=()=>{P(null);const A={};for(const j of se?.columns??[])Pt.has(j)||(A[j]="");O({docText:JSON.stringify(A,null,2),id:""})},Sn=A=>{O(j=>j===null?j:{docText:A,id:j.id})},kn=()=>{$!==null&&Ce(ot($.id===""?"insert":"patch",$.id===""?null:$.id,$.docText))},Tn=()=>{O(null),P(null)},En=()=>{Ue(g-m)},_n=()=>{Ue(g+m)},Rn=A=>{Ue(Math.max(0,(A-1)*m))},$n=A=>{f(A),h(0)},Dn=(A,j)=>{P(null),O({docText:JSON.stringify(en(Zs(j)),null,2),id:A})},An=A=>{Ce(ot("delete",A))},In=async A=>{if(!(u===null||A.length===0)){P(null);try{for(const j of A)await i.query(kt,{id:j,op:"delete",table:u},ke(G));U.refetch()}catch(j){P(j.message)}}},Pn=A=>{Ce(In(A))},On=()=>{Ce(pt())};return{addRow:Nn,bulkDelete:xn,bulkPatch:wn,cancelCellEdit:gt,cancelEdit:Tn,changePageSize:$n,clearTable:vn,columns:se?.columns??[],committing:Z,currentView:Ee,discardStaged:bt,editableColumn:sl,editing:$,editingCell:J,facetFilter:ft,facets:I,filter:N,filters:S,goNext:_n,goPrevious:En,hasNext:fn,hasPredicate:un,hasPrevious:dn,jumpToPage:Rn,liveError:Ie,loadTables:pn,navigateToRef:Se,onBulkDeleteSelected:Pn,onCommitStaged:On,onFilterChange:yn,onFiltersChange:Cn,onRowDelete:An,onRowEdit:Dn,page:se,previewRef:ze,pageError:Me,pageSize:m,rangeEnd:gn,rangeStart:mn,queryShardKey:G,saveEdit:kn,selectedTable:u,selectTable:We,setEditorDocumentText:Sn,setShardKey:b,shardKey:p,showJson:hn,showTable:bn,stage:V.stage,stagedChanges:ht,stagedValue:V.stagedValue,startCellEdit:nt,table:le,tables:ve,tablesError:ge,toggleFacet:He,total:st,totalKnown:Oe,viewMode:x,writeError:M,writeNotice:z}},cl="lunora-studio-pinned-columns",dl=s=>{const e=B(21),{columns:n,initialPins:o,selectedTable:t}=s;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[l,r]=Qt(cl,c),a=t??"",i=l[a];let m;e[1]!==o||e[2]!==i?(m=i===void 0?new Set((o??"").split(",").filter(ul)):new Set(i),e[1]=o,e[2]=i,e[3]=m):m=e[3];const f=m;let p;e[4]!==a||e[5]!==f||e[6]!==r?(p=T=>{r(I=>{const R=I[a]??[...f],_=R.includes(T)?R.filter($=>$!==T):[...R,T];return{...I,[a]:_}})},e[4]=a,e[5]=f,e[6]=r,e[7]=p):p=e[7];const b=p,[u,g]=D(!1);let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{g(fl)},e[8]=h):h=e[8];const x=h;let v;e[9]!==n||e[10]!==t?(v={columns:n,selectedTable:t},e[9]=n,e[10]=t,e[11]=v):v=e[11];const{maskColumns:y,maskOn:C,maskView:N,maskViewFor:k,onToggleMask:S}=zn(v);let w;return e[12]!==y||e[13]!==C||e[14]!==N||e[15]!==k||e[16]!==S||e[17]!==b||e[18]!==f||e[19]!==u?(w={maskColumns:y,maskOn:C,maskView:N,maskViewFor:k,onToggleMask:S,onTogglePin:b,onToggleTranspose:x,pinnedColumns:f,transposed:u},e[12]=y,e[13]=C,e[14]=N,e[15]=k,e[16]=S,e[17]=b,e[18]=f,e[19]=u,e[20]=w):w=e[20],w};function ul(s){return s!==""}function fl(s){return!s}const ml=Te(pe.describeTable),gl=Te(pe.readTablePage),pl=Te(pe.importShard),bl=s=>{const e=s._id??s.id??s.__id__??"";return typeof e=="string"?e:typeof e=="number"?String(e):""},hl=s=>{const e=Object.values(s.inserted).reduce((a,i)=>a+i,0),[n]=s.errors;if(n===void 0)return{conflicts:s.conflicts,error:void 0,inserted:e};const o=s.errors.length-1,t=e+s.conflicts+s.errors.length,c=o===1?"error":"errors",l=o>0?` (+${o.toString()} more ${c})`:"",r=`Inserted ${e.toString()} of ${t.toString()} rows — row ${n.line.toString()} (${n.table}): ${n.message}${l}`;return{conflicts:s.conflicts,error:r,inserted:e}},xl=s=>{const e=dt(),[n,o]=D(!1),[t,c]=D(void 0),[l,r]=D(void 0),[a,i]=D(void 0),[m,f]=D({}),[p,b]=D(!1),[u,g]=D(void 0),h=async(C,N)=>{o(!0),c(C),r(N),i(void 0),f({}),g(void 0),b(!0);try{const k=await e.query(ml,{table:C},ke(N)),{columns:S}=k;i(S);const w={},T=S.filter(I=>I.ref!==void 0&&I.type==="id"&&I.pk!==!0);for(const I of T){if(I.ref===void 0)continue;const{ref:R}=I;if(w[R]===void 0)try{const _=await e.query(gl,{filters:[],limit:Ps,offset:0,search:"",table:R},ke(N));w[R]=_.rows.flatMap($=>bl($)||[])}catch{w[R]=[]}}f(w)}catch(k){g(k.message)}b(!1)};return{closeDialog:()=>{o(!1),c(void 0),r(void 0),i(void 0),f({}),g(void 0)},columnMeta:a,error:u,fkPools:m,insertBatch:async(C,N)=>{if(t===void 0||l===void 0)return{conflicts:0,error:"No table selected.",inserted:0};try{const k=await e.query(pl,{rows:C.map(w=>({doc:w,table:t}))},ke(l)),S=hl(k);return S.error!==void 0||(N(),s()),S}catch(k){return{conflicts:0,error:k.message,inserted:0}}},loading:p,open:n,openDialog:(C,N)=>{Ce(h(C,N))},shardKey:l,table:t}},vl=()=>{const s=B(6),[e,n]=D(null);let o;s[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>{n(null)},s[0]=o):o=s[0];const t=o,[c,l]=D(null);let r;s[1]===Symbol.for("react.memo_cache_sentinel")?(r=(p,b)=>{l({column:p,value:b})},s[1]=r):r=s[1];const a=r;let i;s[2]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{l(null)},s[2]=i):i=s[2];const m=i;let f;return s[3]!==c||s[4]!==e?(f={closeExpandedCell:m,closeInspect:t,expandedCell:c,inspecting:e,onExpandCell:a,onInspect:n},s[3]=c,s[4]=e,s[5]=f):f=s[5],f},wl=/(?:_creationtime|(?:^|[a-z])(?:time|at))$/iu,yl=(s,e)=>typeof e=="number"&&wl.test(s),Cl=s=>{const e=B(36),{column:n,masked:o,onNavigate:t,target:c,value:l}=s;let r;e[0]!==t||e[1]!==c||e[2]!==l?(r=()=>{c!==void 0&&t(c,String(l))},e[0]=t,e[1]=c,e[2]=l,e[3]=r):r=e[3];const a=r;if(l==null){let f;return e[4]===Symbol.for("react.memo_cache_sentinel")?(f=d("span",{className:"italic text-muted-foreground",children:"null"}),e[4]=f):f=e[4],f}if(o){const f=`rd-masked-${n}`;let p;e[5]!==l?(p=je(l),e[5]=l,e[6]=p):p=e[6];let b;return e[7]!==f||e[8]!==p?(b=d("span",{className:"italic text-muted-foreground","data-testid":f,title:"Masked (preview)",children:p}),e[7]=f,e[8]=p,e[9]=b):b=e[9],b}if(c!==void 0&&(typeof l=="string"||typeof l=="number")&&String(l)!==""){const f=`rd-ref-${n}`,p=`Open ${c} ${String(l)}`,b=String(l);let u;return e[10]!==a||e[11]!==f||e[12]!==p||e[13]!==b?(u=E("button",{"data-testid":f,onClick:a,title:p,type:"button",children:[b," ↗"]}),e[10]=a,e[11]=f,e[12]=p,e[13]=b,e[14]=u):u=e[14],u}if(yl(n,l)){const f=`rd-ts-${n}`;let p;e[15]!==l?(p=l.toString(),e[15]=l,e[16]=p):p=e[16];let b;e[17]!==l?(b=Ln(l),e[17]=l,e[18]=b):b=e[18];let u;return e[19]!==f||e[20]!==p||e[21]!==b?(u=d("span",{"data-testid":f,title:p,children:b}),e[19]=f,e[20]=p,e[21]=b,e[22]=u):u=e[22],u}if(l instanceof ArrayBuffer||ArrayBuffer.isView(l)){const f=`rd-bytes-${n}`;let p;e[23]!==l?(p=je(l),e[23]=l,e[24]=p):p=e[24];let b;return e[25]!==f||e[26]!==p?(b=d("span",{"data-testid":f,children:p}),e[25]=f,e[26]=p,e[27]=b):b=e[27],b}if(typeof l=="object"){let f;e[28]!==l?(f=JSON.stringify(l,Yt,2),e[28]=l,e[29]=f):f=e[29];let p;return e[30]!==f?(p=d("pre",{className:"m-0 overflow-auto rounded-md bg-muted/50 p-2 text-xs",children:f}),e[30]=f,e[31]=p):p=e[31],p}let i;e[32]!==l?(i=je(l),e[32]=l,e[33]=i):i=e[33];let m;return e[34]!==i?(m=d("span",{children:i}),e[34]=i,e[35]=m):m=e[35],m},Nl=s=>{const e=B(23),{columns:n,mask:o,onClose:t,onNavigate:c,refs:l,row:r}=s;let a;e[0]!==t||e[1]!==c?(a=(g,h)=>{c(g,h),t()},e[0]=t,e[1]=c,e[2]=a):a=e[2];const i=a;let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=d("h3",{className:"m-0 text-base text-foreground",children:"Row detail"}),e[3]=m):m=e[3];let f;e[4]!==t?(f=E("div",{className:"mb-3 flex items-center justify-between",children:[m,d("button",{"data-testid":"rd-close",onClick:t,type:"button",children:"Close"})]}),e[4]=t,e[5]=f):f=e[5];let p;if(e[6]!==n||e[7]!==o||e[8]!==i||e[9]!==l||e[10]!==r){let g;e[12]!==o||e[13]!==i||e[14]!==l||e[15]!==r?(g=h=>E("div",{className:"border-t border-border py-2 first:border-t-0","data-testid":`rd-field-${h}`,children:[d("dt",{className:"mb-0.5 text-xs font-semibold text-muted-foreground",children:h}),d("dd",{className:"m-0",children:d(Cl,{column:h,masked:o.enabled&&o.columns.has(h),onNavigate:i,target:l?.[h],value:r[h]})})]},h),e[12]=o,e[13]=i,e[14]=l,e[15]=r,e[16]=g):g=e[16],p=n.map(g),e[6]=n,e[7]=o,e[8]=i,e[9]=l,e[10]=r,e[11]=p}else p=e[11];let b;e[17]!==p?(b=d("dl",{"data-testid":"rd-fields",children:p}),e[17]=p,e[18]=b):b=e[18];let u;return e[19]!==t||e[20]!==f||e[21]!==b?(u=E(ut,{label:"Row detail",onClose:t,panelTestId:"rd-panel",testId:"rd-overlay",variant:"drawer",children:[f,b]}),e[19]=t,e[20]=f,e[21]=b,e[22]=u):u=e[22],u},Sl=50,kl=s=>{const e=B(8),{active:n,onPick:o,shard:t}=s;let c;e[0]!==o||e[1]!==t?(c=()=>{o(t)},e[0]=o,e[1]=t,e[2]=c):c=e[2];const l=c,r=`w-full rounded px-2 py-0.5 text-left text-xs transition-colors hover:bg-accent ${n?"bg-accent font-medium":""}`,a=`shard-explorer-item-${t}`;let i;return e[3]!==l||e[4]!==t||e[5]!==r||e[6]!==a?(i=d("button",{className:r,"data-testid":a,onClick:l,type:"button",children:t}),e[3]=l,e[4]=t,e[5]=r,e[6]=a,e[7]=i):i=e[7],i},Tl=({onFetchTables:s,onSelect:e})=>{const n=he(),[o]=D(()=>xo()),[t,c]=D(!1),[l,r]=D(void 0),[a,i]=D(void 0),[m,f]=D(!1),[p,b]=D(void 0),u=Ge(0),g=()=>{c(v=>!v)},h=async v=>{e(v),r(v),i(void 0),b(void 0),f(!0),u.current+=1;const y=u.current;try{const C=await s(v);u.current===y&&i(C?.slice(0,Sl))}catch(C){u.current===y&&b(C.message)}u.current===y&&f(!1)},x=v=>{Ce(h(v))};return o.length===0?null:E("div",{"data-testid":"shard-explorer",children:[E("button",{"aria-controls":"shard-explorer-panel","aria-expanded":t,className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"shard-explorer-toggle",onClick:g,type:"button",children:[n("Shards seen"),d("span",{"aria-hidden":"true",className:`ml-0.5 transition-transform ${t?"rotate-180":""}`,children:"▾"})]}),t&&E("div",{className:"mt-1 flex flex-col gap-1 rounded-md border border-border bg-popover p-2","data-testid":"shard-explorer-panel",id:"shard-explorer-panel",children:[d("p",{className:"text-xs text-muted-foreground","data-testid":"shard-explorer-hint",children:n("Recently visited shards — click to switch")}),d("ul",{className:"flex flex-col gap-0.5","data-testid":"shard-explorer-list",children:o.map(v=>d("li",{children:d(kl,{active:l===v,onPick:x,shard:v})},v))}),l!==void 0&&E("div",{className:"mt-1 border-t border-border pt-1","data-testid":"shard-explorer-summary",children:[d("p",{className:"mb-1 text-xs font-medium text-foreground","data-testid":"shard-explorer-summary-title",children:n("{shard} tables",{shard:l})}),m&&d("p",{className:"text-xs text-muted-foreground","data-testid":"shard-explorer-loading",children:n("Loading…")}),p!==void 0&&d("p",{className:"text-xs text-destructive","data-testid":"shard-explorer-error",role:"alert",children:p}),!m&&p===void 0&&a?.length===0&&d("p",{className:"text-xs text-muted-foreground","data-testid":"shard-explorer-empty",children:n("No tables in this shard.")}),!m&&p===void 0&&a!==void 0&&a.length>0&&d("ul",{className:"flex flex-col gap-0.5","data-testid":"shard-explorer-tables",children:a.map(v=>E("li",{className:"flex items-center justify-between text-xs",children:[d("span",{"data-testid":`shard-explorer-table-${v.name}`,children:v.name}),d("span",{className:"text-muted-foreground","data-testid":`shard-explorer-rowcount-${v.name}`,children:v.rowCount})]},v.name))})]})]})]})},El="lunora-studio-back-relations",_l=s=>new Set((s??[]).filter(e=>e.unique===!0&&e.fields.length===1).map(e=>e.fields[0]??"")),Rl={},$l=50,Dl=[],Al=Te(pe.listTables),Il=Te(pe.readTablePage),Pl=s=>{const e=B(10),{onFetchShardTables:n,onShardChange:o,schemaSwitch:t,shardKey:c}=s;let l;e[0]!==o||e[1]!==c?(l=d(Mn,{onChange:o,testId:"db-shard-input",value:c}),e[0]=o,e[1]=c,e[2]=l):l=e[2];let r;e[3]!==n||e[4]!==o?(r=d(Tl,{onFetchTables:n,onSelect:o}),e[3]=n,e[4]=o,e[5]=r):r=e[5];let a;return e[6]!==t||e[7]!==l||e[8]!==r?(a=E("div",{className:"flex shrink-0 flex-col items-stretch gap-2 border-b border-border p-3",children:[t,l,r]}),e[6]=t,e[7]=l,e[8]=r,e[9]=a):a=e[9],a},ur=({editable:s=!1,globalTableNames:e,initialFilters:n,initialOrderBy:o,initialPins:t,initialSearch:c,initialShardKey:l,onNavigateToGlobal:r,onSelectTable:a,onViewChange:i,pageSize:m=$l,queryBar:f,schemaSwitch:p,tableParam:b})=>{const u=Xe(pe.describeTables,{},{shardKey:l??""}),g=Xe(pe.listTablesIndexes,{},{shardKey:l??""}),h=u.data?.columnsByTable??Rl,[x,v]=Qt(El,{}),y=it(L=>{const le=new Set(x[L]);return Bt(L,h).filter(Ee=>le.has(Dt(Ee)))},[x,h]),C=il({initialFilters:n,initialOrderBy:o,initialSearch:c,initialShardKey:l,onSelectTable:a,onViewChange:i,pageSize:m,resolveBackRelations:y,tableParam:b}),{cancelCellEdit:N,columns:k,currentView:S,editableColumn:w,editingCell:T,facetFilter:I,facets:R,loadTables:_,navigateToRef:$,onFiltersChange:O,page:M,pageError:P,previewRef:z,queryShardKey:q,selectedTable:F,selectTable:V,setShardKey:J,shardKey:K,stage:Z,stagedValue:Y,startCellEdit:Q,tables:ne,tablesError:oe,toggleFacet:de}=C,ue=Gn(K),me=L=>{Ce((async()=>{const Ee=await ue.suggestFilter(L,F??"");Ee!==void 0&&O(Ee.map(Re=>{const Oe=Re.value,st=typeof Oe=="string"||typeof Oe=="number"||typeof Oe=="boolean"?String(Oe):"";return{column:Re.column,operator:Re.operator,value:st}}))})())},re=F===null?[]:Bt(F,h),fe=new Set(x[F??""]),ae=[];for(const L of M?.rows??[]){const le=L._id??L.id;typeof le=="string"&&le!==""&&ae.push(le)}const X=zs(fe,re,ae,q),be=L=>{v(le=>{const Ee=F??"",Re=le[Ee]??[];return{...le,[Ee]:Re.includes(L)?Re.filter(Oe=>Oe!==L):[...Re,L]}})},te=dl({columns:k,initialPins:t,selectedTable:F}),xe=vl(),[ie,ce]=D(null),{closeExpandedCell:W,closeInspect:G,expandedCell:ee,inspecting:H,onExpandCell:ve}=xe,ge=dt(),we=Object.fromEntries((h[F??""]??[]).map(L=>[L.name,L])),ye=new Map;for(const L of h[F??""]??[])L.isStorage===!0&&ye.set(L.name,L.bucket);const U=it(async(L,le)=>ge.signedStorageUrl(L,le===void 0?{}:{bucket:le}),[ge]),se=async L=>await ge.query(Al,{},ke(L)),Me=()=>{F!==null&&V(F)},{closeDialog:Ie,columnMeta:Pe,fkPools:We,insertBatch:Se,open:ze,openDialog:Le}=xl(Me),He=()=>{F!==null&&Le(F,K)},ft=L=>Se(L,Ie),[mt,et]=D(!1),tt=()=>{et(!0)},Ue=()=>{et(!1)},nt=(L,le)=>{if(r!==void 0&&e?.has(L)===!0){r(L,le);return}$(L,le)},gt=f?.onSaveQuery,pt=L=>{gt?.(L,S)},bt={cancelEdit:N,editable:s,editableColumn:w,editingCell:T,onExpandCell:ve,stage:Z,stagedValue:Y,startEdit:Q},ht=L=>{L!==null&&ce(L)},ot=()=>{C.onRowDelete(ie)},Qe=async(L,le,Ee)=>await ge.query(Il,{filters:[{column:le,operator:"eq",value:Ee}],limit:rt,offset:0,orderBy:[],table:L},ke(q)),xt={columns:M?.refs,maskViewFor:te.maskViewFor,onNavigate:nt,onPreview:z};return E("div",{className:"flex h-full min-w-0","data-testid":"lunora-data-browser",children:[d(qn,{header:d(Pl,{onFetchShardTables:se,onShardChange:J,schemaSwitch:p,shardKey:K}),onReload:_,onSelect:V,prefix:"db",selected:F,tables:ne??Dl}),E("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[oe!==null&&d("p",{className:"shrink-0 border-b border-border px-4 py-2 text-sm text-destructive","data-testid":"db-tables-error",role:"alert",children:oe}),M===null&&P===null&&d("div",{className:"flex flex-1 items-center justify-center p-6",children:d("p",{className:"text-sm text-muted-foreground",children:"Select a table to browse its rows."})}),P!==null&&d("p",{className:"shrink-0 border-b border-border px-4 py-2 text-sm text-destructive","data-testid":"db-page-error",role:"alert",children:P}),M!==null&&d(As,{assistant:ue,backRelations:{available:re,counts:X,enabled:fe,onToggle:be},browser:C,columnMeta:we,edit:bt,editable:s,onAskAiFilter:me,onInspect:xe.onInspect,onOpenBulkPatch:tt,onOpenGenerateRows:He,onRowDelete:ht,onSaveQuery:pt,page:M,preferences:te,queryBar:f,references:xt})]}),M!==null&&d(Kn,{columns:k,facets:R,mask:te.maskView,onFacetFilter:I,onToggleFacet:de}),H!==null&&M!==null&&d(Nl,{columns:M.columns,mask:te.maskView,onClose:G,onNavigate:nt,refs:M.refs,row:Xt(H,te.maskView)}),ie!==null&&F!==null&&d(Do,{onClose:()=>{ce(null)},onConfirm:ot,readPage:Qe,rowId:ie,schema:vo(h),table:F}),ee!==null&&d(bo,{bucket:ye.get(ee.column),column:ee.column,onClose:W,resolveUrl:ye.has(ee.column)?U:void 0,value:ee.value}),mt&&F!==null&&d(Co,{columns:C.columns.filter(L=>C.editableColumn(L)),onApply:C.bulkPatch,onClose:Ue,shardKey:C.queryShardKey,table:F,total:C.total,uniqueColumns:_l(g.data?.indexesByTable[F])}),ze&&F!==null&&Pe!==void 0&&d(Bs,{columns:Pe,fkPools:We,onClose:Ie,onInsertRows:ft,table:F})]})};export{ur as DataBrowser};
4
+ `),r=[];let a=0;for(const[i,m]of l.entries()){const f=t[s.row+i],p=f===void 0?null:Pe(f),b=m.split(" ");if(f===void 0||p===null){a+=b.length;continue}for(const[u,g]of b.entries()){const h=e[s.col+u],x=h===void 0||!o(h)?void 0:Qo(g,f[h],n?.[h]);h===void 0||x===void 0?a+=1:r.push({column:h,rowId:p,value:x.value})}}return{edits:r,skipped:a}},rn=(s,e)=>Pe(s)??`row-${e.toString()}`,Xo=8,Zo=s=>{const e=B(17),{anchor:n,mask:o,state:t}=s,c=he();let l;e[0]!==n.left||e[1]!==n.top?(l={left:n.left,position:"fixed",top:n.top,zIndex:50},e[0]=n.left,e[1]=n.top,e[2]=l):l=e[2];const r=l;let a;if(t==="loading"){let m;e[3]!==c?(m=c("Loading…"),e[3]=c,e[4]=m):m=e[4];let f;e[5]!==m?(f=d("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:m}),e[5]=m,e[6]=f):f=e[6],a=f}else if(t.row===null){let m;e[7]!==c?(m=c("No matching row."),e[7]=c,e[8]=m):m=e[8];let f;e[9]!==m?(f=d("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:m}),e[9]=m,e[10]=f):f=e[10],a=f}else{let m;if(e[11]!==o||e[12]!==t.row){const f=Object.entries(Xt(t.row,o)).slice(0,Xo);m=d("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 px-3 py-2",children:f.map(us)}),e[11]=o,e[12]=t.row,e[13]=m}else m=e[13];a=m}let i;return e[14]!==a||e[15]!==r?(i=d("div",{className:"pointer-events-none w-72 overflow-hidden rounded-md border border-border bg-popover text-popover-foreground","data-testid":"db-ref-preview",role:"tooltip",style:r,children:a}),e[14]=a,e[15]=r,e[16]=i):i=e[16],i},es=s=>{const e=B(24),{column:n,id:o,maskViewFor:t,onNavigate:c,onPreview:l,target:r}=s,[a,i]=D(null),[m,f]=D("idle");let p;e[0]!==o||e[1]!==c||e[2]!==r?(p=()=>{c(r,o)},e[0]=o,e[1]=c,e[2]=r,e[3]=p):p=e[3];const b=p;let u;e[4]!==o||e[5]!==l||e[6]!==m||e[7]!==r?(u=S=>{const w=S.currentTarget.getBoundingClientRect();if(i({left:w.left,top:w.bottom+4}),m!=="idle")return;f("loading"),Ce((async()=>{try{f({row:await l(r,o)})}catch{f({row:null})}})())},e[4]=o,e[5]=l,e[6]=m,e[7]=r,e[8]=u):u=e[8];const g=u;let h;e[9]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{i(null)},e[9]=h):h=e[9];const x=h,v=`db-ref-${n}`,y=`Open ${r} ${o}`;let C;e[10]!==o||e[11]!==b||e[12]!==g||e[13]!==v||e[14]!==y?(C=E("button",{"data-testid":v,onBlur:x,onClick:b,onFocus:g,onMouseEnter:g,onMouseLeave:x,title:y,type:"button",children:[o," ↗"]}),e[10]=o,e[11]=b,e[12]=g,e[13]=v,e[14]=y,e[15]=C):C=e[15];let N;e[16]!==a||e[17]!==t||e[18]!==m||e[19]!==r?(N=a!==null&&m!=="idle"&&d(Zo,{anchor:a,mask:t(r,m==="loading"||m.row===null?[]:Object.keys(m.row)),state:m}),e[16]=a,e[17]=t,e[18]=m,e[19]=r,e[20]=N):N=e[20];let k;return e[21]!==C||e[22]!==N?(k=E(Ze,{children:[C,N]}),e[21]=C,e[22]=N,e[23]=k):k=e[23],k},ts=s=>s==="asc"?" ▲":s==="desc"?" ▼":"",ns="absolute end-1 top-1/2 hidden -translate-y-1/2 items-center justify-center rounded text-muted-foreground outline-none group-hover/cell:flex hover:text-foreground focus-visible:flex",Kt=s=>{const e=B(8),{column:n,onExpand:o,value:t}=s;let c;e[0]!==n||e[1]!==o||e[2]!==t?(c=()=>{o(n,t)},e[0]=n,e[1]=o,e[2]=t,e[3]=c):c=e[3];const l=c,r=`db-expand-${n}`;let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=d("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:d("path",{d:"M9 21H5a2 2 0 0 1-2-2v-4m18 0v4a2 2 0 0 1-2 2h-4M3 9V5a2 2 0 0 1 2-2h4m6 0h4a2 2 0 0 1 2 2v4"})}),e[4]=a):a=e[4];let i;return e[5]!==l||e[6]!==r?(i=d("button",{"aria-label":"Expand cell",className:ns,"data-testid":r,onClick:l,type:"button",children:a}),e[5]=l,e[6]=r,e[7]=i):i=e[7],i},os=s=>{const e=B(15),{column:n,initial:o,onCancel:t,onCommit:c,recordId:l}=s,r=Ge(null);let a,i;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{r.current?.select()},i=[],e[0]=a,e[1]=i):(a=e[0],i=e[1]),Be(a,i);let m;e[2]!==t||e[3]!==c?(m=x=>{x.key==="Enter"?(x.preventDefault(),c(x.currentTarget.value)):x.key==="Escape"&&(x.preventDefault(),t())},e[2]=t,e[3]=c,e[4]=m):m=e[4];const f=m;let p;e[5]!==c?(p=x=>{c(x.currentTarget.value)},e[5]=c,e[6]=p):p=e[6];const b=p,u=`db-cell-input-${l}-${n}`;let g;e[7]!==o?(g=je(o),e[7]=o,e[8]=g):g=e[8];let h;return e[9]!==n||e[10]!==b||e[11]!==f||e[12]!==u||e[13]!==g?(h=d("input",{"aria-label":n,className:"w-full rounded border border-ring bg-background px-1 py-0.5 font-mono text-xs outline-none","data-testid":u,defaultValue:g,onBlur:b,onKeyDown:f,ref:r}),e[9]=n,e[10]=b,e[11]=f,e[12]=u,e[13]=g,e[14]=h):h=e[14],h},ss=s=>{const e=B(70),{cell:n,edit:o,highlight:t,mask:c,refs:l}=s,r=n.column.id;let a,i,m,f;if(e[0]!==n||e[1]!==r||e[2]!==o||e[3]!==c||e[4]!==l.columns||e[5]!==l.maskViewFor||e[6]!==l.onNavigate||e[7]!==l.onPreview){f=Symbol.for("react.early_return_sentinel");e:{i=n.getValue(),a=Pe(n.row.original);const R=l.columns?.[r];if(c.enabled&&c.columns.has(r)){const _=`db-masked-${r}`,$=d(Ct,{value:Vn(i,r,c)});let O;e[12]!==_||e[13]!==$?(O=d("span",{className:"text-muted-foreground italic","data-testid":_,title:"Masked (preview)",children:$}),e[12]=_,e[13]=$,e[14]=O):O=e[14],f=O;break e}if(R!==void 0&&(typeof i=="string"||typeof i=="number")&&String(i)!==""){const _=String(i),$=`${R}:${String(i)}`;let O;e[15]!==r||e[16]!==l.maskViewFor||e[17]!==l.onNavigate||e[18]!==l.onPreview||e[19]!==_||e[20]!==$||e[21]!==R?(O=d(es,{column:r,id:_,maskViewFor:l.maskViewFor,onNavigate:l.onNavigate,onPreview:l.onPreview,target:R},$),e[15]=r,e[16]=l.maskViewFor,e[17]=l.onNavigate,e[18]=l.onPreview,e[19]=_,e[20]=$,e[21]=R,e[22]=O):O=e[22],f=O;break e}if(a===null){let _;e[23]!==i?(_=d(Ct,{value:i}),e[23]=i,e[24]=_):_=e[24];let $;e[25]!==r||e[26]!==o.onExpandCell||e[27]!==i?($=d(Kt,{column:r,onExpand:o.onExpandCell,value:i}),e[25]=r,e[26]=o.onExpandCell,e[27]=i,e[28]=$):$=e[28];let O;e[29]!==_||e[30]!==$?(O=E(Ze,{children:[_,$]}),e[29]=_,e[30]=$,e[31]=O):O=e[31],f=O;break e}m=o.stagedValue(a,r)}e[0]=n,e[1]=r,e[2]=o,e[3]=c,e[4]=l.columns,e[5]=l.maskViewFor,e[6]=l.onNavigate,e[7]=l.onPreview,e[8]=a,e[9]=i,e[10]=m,e[11]=f}else a=e[8],i=e[9],m=e[10],f=e[11];if(f!==Symbol.for("react.early_return_sentinel"))return f;const p=m,b=p===void 0?i:p.value;let u;e[32]!==r||e[33]!==o?(u=o.editable&&o.editableColumn(r),e[32]=r,e[33]=o,e[34]=u):u=e[34];const g=u;if(o.editingCell!==null&&o.editingCell.rowId===a&&o.editingCell.column===r){let R;e[35]!==r||e[36]!==o||e[37]!==a||e[38]!==i?(R=$=>{o.stage(a,r,on($,i)),o.cancelEdit()},e[35]=r,e[36]=o,e[37]=a,e[38]=i,e[39]=R):R=e[39];let _;return e[40]!==r||e[41]!==b||e[42]!==o.cancelEdit||e[43]!==a||e[44]!==R?(_=d(os,{column:r,initial:b,onCancel:o.cancelEdit,onCommit:R,recordId:a}),e[40]=r,e[41]=b,e[42]=o.cancelEdit,e[43]=a,e[44]=R,e[45]=_):_=e[45],_}let x;p!==void 0?x="rounded bg-warning/15 px-1":g&&(x="cursor-text");let v;e[46]!==g||e[47]!==r||e[48]!==o||e[49]!==a?(v=g?()=>{o.startEdit(a,r)}:void 0,e[46]=g,e[47]=r,e[48]=o,e[49]=a,e[50]=v):v=e[50];const y=v,C=x,N=`db-cell-${a}-${r}`;let k;e[51]!==r||e[52]!==t||e[53]!==c?(k=Jo(t,c,r),e[51]=r,e[52]=t,e[53]=c,e[54]=k):k=e[54];let S;e[55]!==b||e[56]!==k?(S=d(Ct,{highlight:k,value:b}),e[55]=b,e[56]=k,e[57]=S):S=e[57];let w;e[58]!==x||e[59]!==y||e[60]!==N||e[61]!==S?(w=d("span",{className:C,"data-testid":N,onDoubleClick:y,children:S}),e[58]=x,e[59]=y,e[60]=N,e[61]=S,e[62]=w):w=e[62];let T;e[63]!==r||e[64]!==b||e[65]!==o.onExpandCell?(T=d(Kt,{column:r,onExpand:o.onExpandCell,value:b}),e[63]=r,e[64]=b,e[65]=o.onExpandCell,e[66]=T):T=e[66];let A;return e[67]!==T||e[68]!==w?(A=E(Ze,{children:[w,T]}),e[67]=T,e[68]=w,e[69]=A):A=e[69],A},ls=s=>{s.preventDefault()},Gt={any:"?",array:"[]",bigint:"#",boolean:"01",bytes:"0x",id:"→",number:"#",object:"{}",storage:"◫",string:"T",union:"|"},rs=({declaredType:s,draggedRef:e,header:n,masked:o=!1,onTogglePin:t,pinnedOffset:c,table:l})=>{const r=()=>{e.current=n.column.id},a=()=>{const i=e.current,m=n.column.id;if(e.current=null,i===null||i===m)return;const f=l.atoms.columnOrder.get(),b=(f.length>0?f:l.getAllLeafColumns().map(g=>g.id)).filter(g=>g!==i),u=b.indexOf(m);b.splice(u===-1?b.length:u,0,i),l.setColumnOrder(b)};return E("th",{className:ct("group/head text-start text-xs font-medium text-muted-foreground",c!==void 0&&"border-e border-border bg-muted"),"data-testid":`db-head-${n.column.id}`,draggable:!0,onDragOver:ls,onDragStart:r,onDrop:a,style:c===void 0?Pt(n.getSize()):ln(n.getSize(),c),children:[E("button",{className:"inline-flex max-w-full cursor-grab items-center gap-1 truncate outline-none hover:text-foreground","data-testid":`db-sort-${n.column.id}`,onClick:n.column.getToggleSortingHandler(),type:"button",children:[io(n.column.columnDef.header,n.getContext()),ts(n.column.getIsSorted())]}),s!==void 0&&Gt[s]!==void 0&&d("span",{className:"ms-1 font-mono text-[0.625rem] text-muted-foreground/70","data-testid":`db-type-${n.column.id}`,title:s,children:Gt[s]}),o&&d("span",{className:"ms-1 inline-flex items-center rounded-sm bg-warning/15 px-1 text-[0.625rem] font-medium uppercase text-warning","data-testid":`db-mask-chip-${n.column.id}`,title:"This column is masked by a mask() policy",children:"masked"}),d("button",{"aria-label":c===void 0?`Pin ${n.column.id}`:`Unpin ${n.column.id}`,"aria-pressed":c!==void 0,className:ct("ms-1 rounded-sm px-1 text-[0.625rem] outline-none transition-opacity hover:bg-accent focus-visible:bg-accent",c===void 0?"opacity-0 group-hover/head:opacity-100 focus-visible:opacity-100":"opacity-100 text-foreground"),"data-testid":`db-pin-${n.column.id}`,onClick:()=>{t(n.column.id)},type:"button",children:"📌"}),d("span",{"aria-hidden":"true",className:"absolute inset-y-0 end-0 w-1 cursor-col-resize touch-none select-none hover:bg-ring/60 data-[resizing=true]:bg-ring","data-resizing":n.column.getIsResizing(),"data-testid":`db-resize-${n.column.id}`,onMouseDown:n.getResizeHandler(),onTouchStart:n.getResizeHandler()})]})},as=s=>{const e=B(13),{table:n}=s,o=he();let t;e[0]!==n?(t=m=>{n.toggleAllRowsSelected(m)},e[0]=n,e[1]=t):t=e[1];const c=t;let l;e[2]!==o?(l=o("Select all rows"),e[2]=o,e[3]=l):l=e[3];let r;e[4]!==n?(r=n.getIsAllRowsSelected(),e[4]=n,e[5]=r):r=e[5];let a;e[6]!==n?(a=n.getIsSomeRowsSelected()&&!n.getIsAllRowsSelected(),e[6]=n,e[7]=a):a=e[7];let i;return e[8]!==c||e[9]!==l||e[10]!==r||e[11]!==a?(i=d("th",{className:"bg-muted",style:sn,children:d($t,{"aria-label":l,checked:r,"data-testid":"db-select-all",indeterminate:a,onCheckedChange:c})}),e[8]=c,e[9]=l,e[10]=r,e[11]=a,e[12]=i):i=e[12],i},is=s=>{const e=B(17),{row:n}=s,o=he();let t;e[0]!==n.original?(t=Pe(n.original),e[0]=n.original,e[1]=t):t=e[1];const c=t;let l;e[2]!==n?(l=u=>{n.toggleSelected(u)},e[2]=n,e[3]=l):l=e[3];const r=l;let a;e[4]!==o?(a=o("Select row"),e[4]=o,e[5]=a):a=e[5];let i;e[6]!==n?(i=n.getIsSelected(),e[6]=n,e[7]=i):i=e[7];let m;e[8]!==n.index||e[9]!==n.original?(m=rn(n.original,n.index),e[8]=n.index,e[9]=n.original,e[10]=m):m=e[10];const f=`db-select-${m}`,p=c===null;let b;return e[11]!==r||e[12]!==a||e[13]!==i||e[14]!==f||e[15]!==p?(b=d("td",{className:"bg-background",style:sn,children:d($t,{"aria-label":a,checked:i,"data-testid":f,disabled:p,onCheckedChange:r})}),e[11]=r,e[12]=a,e[13]=i,e[14]=f,e[15]=p,e[16]=b):b=e[16],b},cs=s=>{const e=B(91),{columnMeta:n,edit:o,editable:t,mask:c,onDelete:l,onEdit:r,onInspect:a,highlight:i,backRelationCounts:m,onTogglePin:f,pinnedColumns:p,refs:b,tableModel:u}=s,g=he(),{attachScroll:h,scrollLeft:x,scrollToIndex:v,table:y,tableRows:C,tbodyStyle:N,viewportWidth:k,virtualRows:S}=u,w=Ge(null),[T,A]=D(null);let R;e[0]===Symbol.for("react.memo_cache_sentinel")?(R={columns:"",count:0},e[0]=R):R=e[0];const[_,$]=D(R);let O;e[1]!==y?(O=y.getVisibleLeafColumns(),e[1]=y,e[2]=O):O=e[2];const M=O.length;let I;e[3]!==T||e[4]!==M||e[5]!==o||e[6]!==y||e[7]!==C?(I=ee=>{if(!["ArrowDown","ArrowLeft","ArrowRight","ArrowUp","Enter"].includes(ee.key))return;ee.preventDefault();const H=T??{col:0,row:0};if(ee.key==="Enter"){const we=C[H.row],ye=y.getVisibleLeafColumns()[H.col];if(we!==void 0&&ye!==void 0){const U=Pe(we.original);U!==null&&o.editableColumn(ye.id)&&o.startEdit(U,ye.id)}A(H);return}let{col:ve,row:ge}=H;e:switch(ee.key){case"ArrowDown":{ge=Math.min(ge+1,C.length-1);break e}case"ArrowRight":{ve=Math.min(ve+1,M-1);break e}case"ArrowUp":{ge=Math.max(ge-1,0);break e}default:ve=Math.max(ve-1,0)}A({col:ve,row:ge})},e[3]=T,e[4]=M,e[5]=o,e[6]=y,e[7]=C,e[8]=I):I=e[8];const z=I;let q;e[9]!==T||e[10]!==n||e[11]!==o||e[12]!==y||e[13]!==C?(q=ee=>{const H=o.editable?ee.clipboardData.getData("text/plain"):"";if(H==="")return;ee.preventDefault();const ve=y.getVisibleLeafColumns().map(fs),ge=Yo({anchor:T??{col:0,row:0},columnIds:ve,columnMeta:n,editableColumn:o.editableColumn,rows:C.map(ms),text:H});for(const we of ge.edits)o.stage(we.rowId,we.column,we.value);$({columns:ve.join("\0"),count:ge.skipped})},e[9]=T,e[10]=n,e[11]=o,e[12]=y,e[13]=C,e[14]=q):q=e[14];const F=q;let V,J;e[15]!==T||e[16]!==v?(V=()=>{T!==null&&v(T.row)},J=[T,v],e[15]=T,e[16]=v,e[17]=V,e[18]=J):(V=e[17],J=e[18]),Be(V,J);let K,Z,Y,Q,ne,oe,de,ue,me,re,fe,ae,X,be,te,xe;if(e[19]!==T||e[20]!==h||e[21]!==m||e[22]!==n||e[23]!==o||e[24]!==t||e[25]!==i||e[26]!==c||e[27]!==l||e[28]!==r||e[29]!==z||e[30]!==F||e[31]!==a||e[32]!==f||e[33]!==_.columns||e[34]!==_.count||e[35]!==p||e[36]!==b||e[37]!==x||e[38]!==g||e[39]!==y||e[40]!==C||e[41]!==N||e[42]!==k||e[43]!==S){const ee=y.getVisibleLeafColumns().map(gs),H=Po(ee,p,x,k),ve=Ao(y.getVisibleLeafColumns().map(ps),p),ge=U=>{const se=C[U.index],{original:Me}=se,Ae=Pe(Me),Ie=rn(Me,U.index),We={...qo,height:`${U.size.toString()}px`,transform:`translateY(${U.start.toString()}px)`};return E("tr",{className:"border-b border-border text-xs transition-colors hover:bg-muted/50","data-testid":"db-row",style:We,children:[d(is,{row:se}),H.leadPx>0&&d("td",{"aria-hidden":"true",style:{flex:`0 0 ${H.leadPx.toString()}px`}}),se.getVisibleCells().map((Se,ze)=>{if(!H.ids.has(Se.column.id))return null;const Le=ve.get(Se.column.id),He=T!==null&&T.row===U.index&&T.col===ze?" ring-1 ring-ring ring-inset":"";return d("td",{className:ct("group/cell truncate font-mono text-muted-foreground",Le!==void 0&&"border-e border-border bg-background",He),onPointerDown:()=>{A({col:ze,row:U.index})},style:Le===void 0?Pt(Se.column.getSize()):ln(Se.column.getSize(),Le),children:Se.column.id.startsWith(_t)?d(Ho,{counts:m[Se.column.id.slice(_t.length)],rowId:Ie}):d(ss,{cell:Se,edit:o,highlight:i,mask:c,refs:b})},Se.id)}),H.tailPx>0&&d("td",{"aria-hidden":"true",style:{flex:`0 0 ${H.tailPx.toString()}px`}}),E("td",{className:"flex items-center gap-1",style:qt,children:[d("button",{className:Nt,"data-testid":`db-inspect-${Ie}`,onClick:()=>{a(Me)},type:"button",children:"Details"}),t&&E(Ze,{children:[d("button",{className:Nt,"data-testid":`db-edit-${Ie}`,disabled:Ae===null,onClick:()=>{r(Ae,Me)},type:"button",children:"Edit"}),d("button",{className:Nt,"data-testid":`db-delete-${Ie}`,disabled:Ae===null,onClick:()=>{l(Ae)},type:"button",children:"Delete"})]})]})]},se.id)};K=fo,ae="fill",e[60]!==_.columns||e[61]!==_.count||e[62]!==g||e[63]!==y?(X=_.count>0&&_.columns===y.getVisibleLeafColumns().map(bs).join("\0")&&d("p",{className:"border-b border-warning/40 bg-warning/5 px-3 py-1.5 text-xs text-warning","data-testid":"db-paste-skipped",children:g("{count} pasted cells were skipped",{count:_.count})}),e[60]=_.columns,e[61]=_.count,e[62]=g,e[63]=y,e[64]=X):X=e[64],ne="db-scroll",oe=z,de=F,ue=h,me="grid",re=Bo,fe=0,xe="w-full text-xs",Z="db-rows",Y=jo;let we;e[65]!==y?(we=d(as,{table:y}),e[65]=y,e[66]=we):we=e[66];let ye;e[67]===Symbol.for("react.memo_cache_sentinel")?(ye=d("th",{"aria-label":"Row actions",style:qt}),e[67]=ye):ye=e[67],Q=d("thead",{className:"bg-muted/50",children:E("tr",{className:"border-b border-border",style:Ko,children:[we,H.leadPx>0&&d("th",{"aria-hidden":"true",style:{flex:`0 0 ${H.leadPx.toString()}px`}}),y.getFlatHeaders().map(U=>H.ids.has(U.column.id)?d(rs,{declaredType:n?.[U.column.id]?.type,draggedRef:w,header:U,masked:c.columns.has(U.column.id),onTogglePin:f,pinnedOffset:ve.get(U.column.id),table:y},U.id):null),H.tailPx>0&&d("th",{"aria-hidden":"true",style:{flex:`0 0 ${H.tailPx.toString()}px`}}),ye]})}),be=N,te=S.map(U=>ge(U)),e[19]=T,e[20]=h,e[21]=m,e[22]=n,e[23]=o,e[24]=t,e[25]=i,e[26]=c,e[27]=l,e[28]=r,e[29]=z,e[30]=F,e[31]=a,e[32]=f,e[33]=_.columns,e[34]=_.count,e[35]=p,e[36]=b,e[37]=x,e[38]=g,e[39]=y,e[40]=C,e[41]=N,e[42]=k,e[43]=S,e[44]=K,e[45]=Z,e[46]=Y,e[47]=Q,e[48]=ne,e[49]=oe,e[50]=de,e[51]=ue,e[52]=me,e[53]=re,e[54]=fe,e[55]=ae,e[56]=X,e[57]=be,e[58]=te,e[59]=xe}else K=e[44],Z=e[45],Y=e[46],Q=e[47],ne=e[48],oe=e[49],de=e[50],ue=e[51],me=e[52],re=e[53],fe=e[54],ae=e[55],X=e[56],be=e[57],te=e[58],xe=e[59];let ie;e[68]!==be||e[69]!==te?(ie=d("tbody",{style:be,children:te}),e[68]=be,e[69]=te,e[70]=ie):ie=e[70];let ce;e[71]!==Z||e[72]!==Y||e[73]!==Q||e[74]!==ie||e[75]!==xe?(ce=E("table",{className:xe,"data-testid":Z,style:Y,children:[Q,ie]}),e[71]=Z,e[72]=Y,e[73]=Q,e[74]=ie,e[75]=xe,e[76]=ce):ce=e[76];let W;e[77]!==ne||e[78]!==oe||e[79]!==de||e[80]!==ue||e[81]!==me||e[82]!==re||e[83]!==fe||e[84]!==ce?(W=d("div",{"data-testid":ne,onKeyDown:oe,onPaste:de,ref:ue,role:me,style:re,tabIndex:fe,children:ce}),e[77]=ne,e[78]=oe,e[79]=de,e[80]=ue,e[81]=me,e[82]=re,e[83]=fe,e[84]=ce,e[85]=W):W=e[85];let G;return e[86]!==K||e[87]!==ae||e[88]!==X||e[89]!==W?(G=E(K,{layout:ae,children:[X,W]}),e[86]=K,e[87]=ae,e[88]=X,e[89]=W,e[90]=G):G=e[90],G},ds=(s,e,n,o=[])=>{const t=s?.columns,c=s?.rows,l=s?.refs,r=Tt(()=>{if(t===void 0)return[];const w=t.map(T=>({accessorFn:A=>A[T],header:l?.[T]===void 0?T:`${T} →`,id:T}));for(const T of o)w.push({accessorFn:()=>{},enableSorting:!1,header:`← ${T.table}`,id:Wo(T)});return w},[o,t,l]),a=Tt(()=>c??[],[c]),[i,m]=D({}),[f,p]=D({}),b=ao({columnResizeMode:"onChange",columns:r,data:a,defaultColumn:{minSize:80,size:200},enableColumnResizing:!0,enableRowSelection:w=>Pe(w.original)!==null,features:Io,getRowId:(w,T)=>Pe(w)??`row-${T.toString()}`,manualSorting:!0,onColumnVisibilityChange:p,onRowSelectionChange:m,onSortingChange:n,state:{columnVisibility:f,rowSelection:i,sorting:e}}),u=b.getRowModel().rows,g=Ge(null),h=co({count:u.length,estimateSize:()=>Vo,getScrollElement:()=>g.current,initialRect:{height:zt,width:0},observeElementRect:(w,T)=>uo(w,T,zt),overscan:8}),x=it(w=>{h.scrollToIndex(w)},[h]),[v,y]=D({left:0,width:0}),C=it(w=>{if(g.current=w,w===null)return;const T=()=>{y(R=>R.left===w.scrollLeft&&R.width===w.clientWidth?R:{left:w.scrollLeft,width:w.clientWidth})};w.addEventListener("scroll",T,{passive:!0});const A=new ResizeObserver(T);return A.observe(w),()=>{w.removeEventListener("scroll",T),A.disconnect(),g.current=null}},[]),N=h.getVirtualItems(),S={display:"block",height:`${h.getTotalSize().toString()}px`,position:"relative"};return{attachScroll:C,scrollLeft:v.left,scrollToIndex:x,table:b,tableRows:u,tbodyStyle:S,viewportWidth:v.width,virtualRows:N}};function us(s){const[e,n]=s;return E("div",{className:"contents",children:[d("dt",{className:"truncate font-mono text-[11px] text-muted-foreground",children:e}),d("dd",{className:"truncate font-mono text-[11px] text-foreground",title:je(n),children:je(n)})]},e)}function fs(s){return s.id}function ms(s){return s.original}function gs(s){return{getSize:()=>s.getSize(),id:s.id}}function ps(s){return{getSize:()=>s.getSize(),id:s.id}}function bs(s){return s.id}const hs=s=>{const e=B(22),{onCommit:n}=s,o=he(),[t,c]=D(""),l=Ge(null);let r,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{l.current?.focus()},a=[],e[0]=r,e[1]=a):(r=e[0],a=e[1]),Be(r,a);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=y=>{c(y.target.value)},e[2]=i):i=e[2];const m=i;let f;e[3]!==t||e[4]!==n?(f=()=>{const y=t.trim();y!==""&&n(y)},e[3]=t,e[4]=n,e[5]=f):f=e[5];const p=f;let b;e[6]!==o?(b=o("Query name"),e[6]=o,e[7]=b):b=e[7];let u;e[8]!==o?(u=o("Query name"),e[8]=o,e[9]=u):u=e[9];let g;e[10]!==t||e[11]!==b||e[12]!==u?(g=d("input",{"aria-label":b,className:"h-7 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"db-save-query-name",onChange:m,placeholder:u,ref:l,value:t}),e[10]=t,e[11]=b,e[12]=u,e[13]=g):g=e[13];let h;e[14]!==o?(h=o("Save"),e[14]=o,e[15]=h):h=e[15];let x;e[16]!==p||e[17]!==h?(x=d("button",{className:Et,"data-testid":"db-save-query-confirm",onClick:p,type:"button",children:h}),e[16]=p,e[17]=h,e[18]=x):x=e[18];let v;return e[19]!==g||e[20]!==x?(v=E("span",{className:"inline-flex items-center gap-1",children:[g,x]}),e[19]=g,e[20]=x,e[21]=v):v=e[21],v},xs=s=>{const e=B(27),{onApply:n,onCopyLink:o,onDelete:t,onSave:c,saved:l}=s,r=he(),[a,i]=D(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{i(!0)},e[0]=m):m=e[0];const f=m;let p;e[1]!==c?(p=S=>{c(S),i(!1)},e[1]=c,e[2]=p):p=e[2];const b=p;let u;e[3]!==n||e[4]!==l?(u=S=>{const w=l[Number(S.currentTarget.dataset.index)];w!==void 0&&n(w)},e[3]=n,e[4]=l,e[5]=u):u=e[5];const g=u;let h;e[6]!==t||e[7]!==l?(h=S=>{const w=l[Number(S.currentTarget.dataset.index)];w!==void 0&&t(w.name)},e[6]=t,e[7]=l,e[8]=h):h=e[8];const x=h;let v;e[9]!==r?(v=r("Copy link"),e[9]=r,e[10]=v):v=e[10];let y;e[11]!==o||e[12]!==v?(y=d("button",{className:Et,"data-testid":"db-copy-link",onClick:o,type:"button",children:v}),e[11]=o,e[12]=v,e[13]=y):y=e[13];let C;e[14]!==b||e[15]!==a||e[16]!==r?(C=a?d(hs,{onCommit:b}):d("button",{className:Et,"data-testid":"db-save-query",onClick:f,type:"button",children:r("Save query")}),e[14]=b,e[15]=a,e[16]=r,e[17]=C):C=e[17];let N;e[18]!==g||e[19]!==x||e[20]!==l||e[21]!==r?(N=l.length>0&&E("div",{className:"flex flex-wrap items-center gap-1","data-testid":"db-saved-queries",children:[d("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:r("Saved")}),l.map((S,w)=>E("span",{className:"inline-flex items-center overflow-hidden rounded-md border border-border",children:[d("button",{className:"px-2 py-0.5 text-xs text-foreground transition-colors hover:bg-accent","data-index":w,"data-testid":`db-saved-query-${S.name}`,onClick:g,type:"button",children:S.name}),d("button",{"aria-label":r("Delete saved query {name}",{name:S.name}),className:"border-l border-border px-1 py-0.5 text-xs text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive","data-index":w,"data-testid":`db-saved-query-delete-${S.name}`,onClick:x,type:"button",children:"✕"})]},S.name))]}),e[18]=g,e[19]=x,e[20]=l,e[21]=r,e[22]=N):N=e[22];let k;return e[23]!==y||e[24]!==C||e[25]!==N?(k=E("div",{className:"flex flex-wrap items-center gap-1.5","data-testid":"db-query-bar",children:[y,C,N]}),e[23]=y,e[24]=C,e[25]=N,e[26]=k):k=e[26],k},Je="w-full rounded-md border border-border bg-background px-2 py-1 font-mono text-xs outline-none focus-visible:border-ring",an=/(?:_creationtime|(?:^|[a-z])(?:time|at))$/iu,Jt=(s,e)=>typeof e=="boolean"?"boolean":typeof e=="number"?an.test(s)?"date":"number":e!==null&&typeof e=="object"?"json":"text",vs=(s,e,n)=>n===void 0?Jt(s,e):n.enumValues!==void 0&&n.enumValues.length>0?"enum":n.type==="boolean"?"boolean":n.type==="number"?an.test(s)?"date":"number":Jt(s,e),ws=s=>{try{const e=JSON.parse(s);return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}catch{return null}},ys=s=>{const e=new Date(s),n=o=>String(o).padStart(2,"0");return`${e.getFullYear().toString()}-${n(e.getMonth()+1)}-${n(e.getDate())}T${n(e.getHours())}:${n(e.getMinutes())}`},Ke="\0clear",Cs=s=>{const e=B(23),{column:n,nullable:o,onChange:t,value:c}=s,l=he();let r;e[0]!==n||e[1]!==t?(r=v=>{t(n,v)},e[0]=n,e[1]=t,e[2]=r):r=e[2];const a=r;let i;e[3]!==n||e[4]!==t?(i=v=>{t(n,v.target.value===Ke?null:v.target.value==="true")},e[3]=n,e[4]=t,e[5]=i):i=e[5];const m=i;if(!o&&c!==null){const v=c===!0,y=`db-field-${n}`;let C;return e[6]!==n||e[7]!==a||e[8]!==v||e[9]!==y?(C=d($t,{"aria-label":n,checked:v,"data-testid":y,onCheckedChange:a}),e[6]=n,e[7]=a,e[8]=v,e[9]=y,e[10]=C):C=e[10],C}const f=`db-field-${n}`,p=c===!0||c===!1?String(c):Ke;let b;e[11]!==l?(b=l("(none)"),e[11]=l,e[12]=b):b=e[12];let u;e[13]!==b?(u=d("option",{value:Ke,children:b}),e[13]=b,e[14]=u):u=e[14];let g,h;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=d("option",{value:"true",children:"true"}),h=d("option",{value:"false",children:"false"}),e[15]=g,e[16]=h):(g=e[15],h=e[16]);let x;return e[17]!==n||e[18]!==m||e[19]!==f||e[20]!==p||e[21]!==u?(x=E("select",{"aria-label":n,className:Je,"data-testid":f,onChange:m,value:p,children:[u,g,h]}),e[17]=n,e[18]=m,e[19]=f,e[20]=p,e[21]=u,e[22]=x):x=e[22],x},Ns=s=>{const e=B(23),{column:n,nullable:o,onChange:t,options:c,value:l}=s,r=he(),a=typeof l=="string"?l:null;let i;e[0]!==c||e[1]!==a?(i=a!==null&&!c.includes(a),e[0]=c,e[1]=a,e[2]=i):i=e[2];const m=i;let f;e[3]!==n||e[4]!==t?(f=y=>{t(n,y.target.value===Ke?null:y.target.value)},e[3]=n,e[4]=t,e[5]=f):f=e[5];const p=f,b=`db-field-${n}`,u=a??Ke;let g;e[6]!==o||e[7]!==a||e[8]!==r?(g=(o||a===null)&&d("option",{value:Ke,children:r("(none)")}),e[6]=o,e[7]=a,e[8]=r,e[9]=g):g=e[9];let h;e[10]!==a||e[11]!==m?(h=m&&d("option",{value:a,children:a}),e[10]=a,e[11]=m,e[12]=h):h=e[12];let x;e[13]!==c?(x=c.map($s),e[13]=c,e[14]=x):x=e[14];let v;return e[15]!==n||e[16]!==p||e[17]!==b||e[18]!==u||e[19]!==g||e[20]!==h||e[21]!==x?(v=E("select",{"aria-label":n,className:Je,"data-testid":b,onChange:p,value:u,children:[g,h,x]}),e[15]=n,e[16]=p,e[17]=b,e[18]=u,e[19]=g,e[20]=h,e[21]=x,e[22]=v):v=e[22],v},Ss=s=>{const e=B(8),{column:n,onChange:o,value:t}=s;let c;e[0]!==n||e[1]!==o?(c=m=>{const f=Number(m.target.value);m.target.value!==""&&!Number.isNaN(f)&&o(n,f)},e[0]=n,e[1]=o,e[2]=c):c=e[2];const l=c,r=`db-field-${n}`,a=typeof t=="number"?t:"";let i;return e[3]!==n||e[4]!==l||e[5]!==r||e[6]!==a?(i=d("input",{"aria-label":n,className:Je,"data-testid":r,onChange:l,type:"number",value:a}),e[3]=n,e[4]=l,e[5]=r,e[6]=a,e[7]=i):i=e[7],i},ks=s=>{const e=B(10),{column:n,onChange:o,value:t}=s;let c;e[0]!==n||e[1]!==o?(c=m=>{const f=new Date(m.target.value).getTime();Number.isNaN(f)||o(n,f)},e[0]=n,e[1]=o,e[2]=c):c=e[2];const l=c,r=`db-field-${n}`;let a;e[3]!==t?(a=typeof t=="number"?ys(t):"",e[3]=t,e[4]=a):a=e[4];let i;return e[5]!==n||e[6]!==l||e[7]!==r||e[8]!==a?(i=d("input",{"aria-label":n,className:Je,"data-testid":r,onChange:l,type:"datetime-local",value:a}),e[5]=n,e[6]=l,e[7]=r,e[8]=a,e[9]=i):i=e[9],i},Ts=s=>{const e=B(8),{column:n,onChange:o,value:t}=s;let c;e[0]!==n||e[1]!==o?(c=m=>{o(n,m.target.value)},e[0]=n,e[1]=o,e[2]=c):c=e[2];const l=c,r=`db-field-${n}`,a=typeof t=="string"?t:"";let i;return e[3]!==n||e[4]!==l||e[5]!==r||e[6]!==a?(i=d("input",{"aria-label":n,className:Je,"data-testid":r,onChange:l,type:"text",value:a}),e[3]=n,e[4]=l,e[5]=r,e[6]=a,e[7]=i):i=e[7],i},Es=s=>{const e=B(20),{column:n,onChange:o,value:t}=s,c=he();let l;e[0]!==t?(l=()=>JSON.stringify(t,null,2),e[0]=t,e[1]=l):l=e[1];const[r,a]=D(l),[i,m]=D(!1);let f;e[2]!==n||e[3]!==o?(f=y=>{const C=y.target.value;a(C);try{o(n,JSON.parse(C)),m(!1)}catch{m(!0)}},e[2]=n,e[3]=o,e[4]=f):f=e[4];const p=f,b=i&&"border-destructive";let u;e[5]!==b?(u=ct(Je,"min-h-16",b),e[5]=b,e[6]=u):u=e[6];const g=`db-field-${n}`;let h;e[7]!==n||e[8]!==p||e[9]!==u||e[10]!==g||e[11]!==r?(h=d("textarea",{"aria-label":n,className:u,"data-testid":g,onChange:p,value:r}),e[7]=n,e[8]=p,e[9]=u,e[10]=g,e[11]=r,e[12]=h):h=e[12];let x;e[13]!==n||e[14]!==i||e[15]!==c?(x=i&&d("span",{className:"text-xs text-destructive","data-testid":`db-field-error-${n}`,children:c("Invalid JSON")}),e[13]=n,e[14]=i,e[15]=c,e[16]=x):x=e[16];let v;return e[17]!==h||e[18]!==x?(v=E("div",{className:"flex flex-col gap-1",children:[h,x]}),e[17]=h,e[18]=x,e[19]=v):v=e[19],v},_s=s=>{const e=B(56),{column:n,meta:o,onChange:t,target:c,value:l}=s;let r;e[0]!==n||e[1]!==o||e[2]!==l?(r=vs(n,l,o),e[0]=n,e[1]=o,e[2]=l,e[3]=r):r=e[3];const a=r,i=`db-field-${n}`;let m;e[4]!==n?(m=d("span",{className:"font-mono",children:n}),e[4]=n,e[5]=m):m=e[5];let f;e[6]!==n||e[7]!==o?(f=o!==void 0&&d("span",{className:"rounded bg-muted px-1 font-mono text-[10px] tracking-wide","data-testid":`db-field-type-${n}`,children:o.type}),e[6]=n,e[7]=o,e[8]=f):f=e[8];let p;e[9]!==c?(p=c!==void 0&&E("span",{className:"rounded bg-muted px-1 font-mono text-[10px] tracking-wide uppercase",children:["→ ",c]}),e[9]=c,e[10]=p):p=e[10];let b;e[11]!==m||e[12]!==f||e[13]!==p?(b=E("span",{className:"flex items-center gap-1.5 font-medium text-muted-foreground",children:[m,f,p]}),e[11]=m,e[12]=f,e[13]=p,e[14]=b):b=e[14];let u;e[15]!==n||e[16]!==a||e[17]!==o?.nullable||e[18]!==t||e[19]!==l?(u=a==="boolean"&&d(Cs,{column:n,nullable:o?.nullable===!0,onChange:t,value:l}),e[15]=n,e[16]=a,e[17]=o?.nullable,e[18]=t,e[19]=l,e[20]=u):u=e[20];let g;e[21]!==n||e[22]!==a||e[23]!==o||e[24]!==t||e[25]!==l?(g=a==="enum"&&o?.enumValues!==void 0&&d(Ns,{column:n,nullable:o.nullable===!0,onChange:t,options:o.enumValues,value:l}),e[21]=n,e[22]=a,e[23]=o,e[24]=t,e[25]=l,e[26]=g):g=e[26];let h;e[27]!==n||e[28]!==a||e[29]!==t||e[30]!==l?(h=a==="number"&&d(Ss,{column:n,onChange:t,value:l}),e[27]=n,e[28]=a,e[29]=t,e[30]=l,e[31]=h):h=e[31];let x;e[32]!==n||e[33]!==a||e[34]!==t||e[35]!==l?(x=a==="date"&&d(ks,{column:n,onChange:t,value:l}),e[32]=n,e[33]=a,e[34]=t,e[35]=l,e[36]=x):x=e[36];let v;e[37]!==n||e[38]!==a||e[39]!==t||e[40]!==l?(v=a==="json"&&d(Es,{column:n,onChange:t,value:l}),e[37]=n,e[38]=a,e[39]=t,e[40]=l,e[41]=v):v=e[41];let y;e[42]!==n||e[43]!==a||e[44]!==t||e[45]!==l?(y=a==="text"&&d(Ts,{column:n,onChange:t,value:l}),e[42]=n,e[43]=a,e[44]=t,e[45]=l,e[46]=y):y=e[46];let C;return e[47]!==x||e[48]!==v||e[49]!==y||e[50]!==i||e[51]!==b||e[52]!==u||e[53]!==g||e[54]!==h?(C=E("label",{className:"flex flex-col gap-1 text-xs",htmlFor:i,children:[b,u,g,h,x,v,y]}),e[47]=x,e[48]=v,e[49]=y,e[50]=i,e[51]=b,e[52]=u,e[53]=g,e[54]=h,e[55]=C):C=e[55],C},Rs=s=>{const e=B(49),{columnMeta:n,documentText:o,onCancel:t,onDocumentTextChange:c,onSave:l,refs:r}=s,a=he();let i;e[0]!==o?(i=ws(o),e[0]=o,e[1]=i):i=e[1];const m=i,[f,p]=D(!1),b=!f&&m!==null;let u;e[2]!==m||e[3]!==c?(u=(V,J)=>{c(JSON.stringify({...m,[V]:J},null,2))},e[2]=m,e[3]=c,e[4]=u):u=e[4];const g=u;let h;e[5]!==c?(h=V=>{c(V.target.value)},e[5]=c,e[6]=h):h=e[6];const x=h;let v;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{p(!1)},e[7]=v):v=e[7];const y=v;let C;e[8]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{p(!0)},e[8]=C):C=e[8];const N=C,k=m===null;let S;e[9]!==a?(S=a("Form"),e[9]=a,e[10]=S):S=e[10];let w;e[11]!==b||e[12]!==k||e[13]!==S?(w=d("button",{"aria-pressed":b,className:De,"data-testid":"db-editor-form",disabled:k,onClick:y,type:"button",children:S}),e[11]=b,e[12]=k,e[13]=S,e[14]=w):w=e[14];const T=!b;let A;e[15]!==a?(A=a("JSON"),e[15]=a,e[16]=A):A=e[16];let R;e[17]!==A||e[18]!==T?(R=d("button",{"aria-pressed":T,className:De,"data-testid":"db-editor-json",onClick:N,type:"button",children:A}),e[17]=A,e[18]=T,e[19]=R):R=e[19];let _;e[20]!==R||e[21]!==w?(_=E("div",{className:"flex items-center gap-1.5",children:[w,R]}),e[20]=R,e[21]=w,e[22]=_):_=e[22];let $;e[23]!==n||e[24]!==o||e[25]!==m||e[26]!==g||e[27]!==x||e[28]!==r||e[29]!==b||e[30]!==a?($=b?d("div",{className:"flex flex-col gap-3","data-testid":"db-editor-fields",children:Object.entries(m).map(V=>{const[J,K]=V;return d(_s,{column:J,meta:n?.[J],onChange:g,target:r?.[J],value:K},J)})}):d("textarea",{"aria-label":a("Row document JSON"),className:"min-h-28 w-full rounded-md border border-border bg-background px-2 py-1.5 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"db-editor-doc",onChange:x,value:o}),e[23]=n,e[24]=o,e[25]=m,e[26]=g,e[27]=x,e[28]=r,e[29]=b,e[30]=a,e[31]=$):$=e[31];let O;e[32]!==a?(O=a("Save"),e[32]=a,e[33]=O):O=e[33];let M;e[34]!==l||e[35]!==O?(M=d("button",{className:De,"data-testid":"db-editor-save",onClick:l,type:"button",children:O}),e[34]=l,e[35]=O,e[36]=M):M=e[36];let I;e[37]!==a?(I=a("Cancel"),e[37]=a,e[38]=I):I=e[38];let z;e[39]!==t||e[40]!==I?(z=d("button",{className:De,"data-testid":"db-editor-cancel",onClick:t,type:"button",children:I}),e[39]=t,e[40]=I,e[41]=z):z=e[41];let q;e[42]!==M||e[43]!==z?(q=E("div",{className:"flex items-center gap-1.5",children:[M,z]}),e[42]=M,e[43]=z,e[44]=q):q=e[44];let F;return e[45]!==_||e[46]!==$||e[47]!==q?(F=E("div",{className:"flex flex-col gap-2 border border-border bg-card p-3","data-testid":"db-editor",children:[_,$,q]}),e[45]=_,e[46]=$,e[47]=q,e[48]=F):F=e[48],F};function $s(s){return d("option",{value:s,children:s},s)}const Ds=s=>{const e=B(71),{columns:n,editable:o,filter:t,filters:c,hasMaskedColumns:l,hasPredicate:r,liveError:a,maskOn:i,onAddRow:m,onBulkDelete:f,onBulkPatch:p,onAskAiFilter:b,onClearTable:u,onFilterChange:g,onFiltersChange:h,onGenerateRows:x,onShowJson:v,onShowTable:y,onToggleMask:C,total:N,totalKnown:k,viewMode:S}=s,w=he(),T=S==="table";let A;e[0]!==y||e[1]!==T?(A=d("button",{"aria-pressed":T,className:De,"data-testid":"db-view-table",onClick:y,type:"button",children:"Table"}),e[0]=y,e[1]=T,e[2]=A):A=e[2];const R=S==="json";let _;e[3]!==v||e[4]!==R?(_=d("button",{"aria-pressed":R,className:De,"data-testid":"db-view-json",onClick:v,type:"button",children:"JSON"}),e[3]=v,e[4]=R,e[5]=_):_=e[5];let $;e[6]!==a||e[7]!==w?($=a===void 0?w("Live — changes stream in automatically"):w("Live unavailable: {liveError}",{liveError:a}),e[6]=a,e[7]=w,e[8]=$):$=e[8];const O=`size-1.5 rounded-full ${a===void 0?"bg-success":"bg-muted-foreground/50"}`;let M;e[9]!==O?(M=d("span",{"aria-hidden":"true",className:O}),e[9]=O,e[10]=M):M=e[10];let I;e[11]!==a||e[12]!==w?(I=w(a===void 0?"Live":"Live unavailable"),e[11]=a,e[12]=w,e[13]=I):I=e[13];let z;e[14]!==$||e[15]!==M||e[16]!==I?(z=E("span",{className:"inline-flex items-center gap-1.5 px-1 text-xs font-medium text-muted-foreground","data-testid":"db-live-indicator",role:"status",title:$,children:[M,I]}),e[14]=$,e[15]=M,e[16]=I,e[17]=z):z=e[17];let q;e[18]!==l||e[19]!==i||e[20]!==C||e[21]!==w?(q=l&&d("button",{"aria-pressed":i,className:De,"data-testid":"db-mask-toggle",onClick:C,type:"button",children:w("Mask sensitive columns")}),e[18]=l,e[19]=i,e[20]=C,e[21]=w,e[22]=q):q=e[22];let F;e[23]!==o||e[24]!==m?(F=o&&d("button",{className:De,"data-testid":"db-add-row",onClick:m,type:"button",children:"Add row"}),e[23]=o,e[24]=m,e[25]=F):F=e[25];let V;e[26]!==o||e[27]!==x||e[28]!==w?(V=o&&d("button",{className:De,"data-testid":"db-generate-rows",onClick:x,type:"button",children:w("Generate rows")}),e[26]=o,e[27]=x,e[28]=w,e[29]=V):V=e[29];let J;e[30]!==o||e[31]!==r||e[32]!==f||e[33]!==w||e[34]!==N||e[35]!==k?(J=o&&N>0&&r&&d(Lt,{confirmLabel:k?w("Permanently delete {total} matching rows and everything that cascades?",{total:N.toString()}):w("Permanently delete all matching rows and everything that cascades?"),onConfirm:f,testId:"db-bulk-delete",children:k?w("Delete {total} matching",{total:N.toString()}):w("Delete matching")}),e[30]=o,e[31]=r,e[32]=f,e[33]=w,e[34]=N,e[35]=k,e[36]=J):J=e[36];let K;e[37]!==o||e[38]!==r||e[39]!==p||e[40]!==w||e[41]!==N||e[42]!==k?(K=o&&k&&N>0&&r&&d("button",{className:De,"data-testid":"db-bulk-patch",onClick:p,type:"button",children:w("Set column on {total} matching",{total:N.toString()})}),e[37]=o,e[38]=r,e[39]=p,e[40]=w,e[41]=N,e[42]=k,e[43]=K):K=e[43];let Z;e[44]!==o||e[45]!==r||e[46]!==u||e[47]!==w||e[48]!==N||e[49]!==k?(Z=o&&N>0&&!r&&d(Lt,{confirmLabel:k?w("Permanently clear all {total} rows and everything that cascades?",{total:N.toString()}):w("Permanently clear every row and everything that cascades?"),onConfirm:u,testId:"db-clear-table",children:k?w("Clear table ({total})",{total:N.toString()}):w("Clear table")}),e[44]=o,e[45]=r,e[46]=u,e[47]=w,e[48]=N,e[49]=k,e[50]=Z):Z=e[50];let Y;e[51]!==q||e[52]!==F||e[53]!==V||e[54]!==J||e[55]!==K||e[56]!==Z||e[57]!==A||e[58]!==_||e[59]!==z?(Y=E("div",{className:"flex flex-wrap items-center gap-1.5",children:[A,_,z,q,F,V,J,K,Z]}),e[51]=q,e[52]=F,e[53]=V,e[54]=J,e[55]=K,e[56]=Z,e[57]=A,e[58]=_,e[59]=z,e[60]=Y):Y=e[60];let Q;e[61]!==n||e[62]!==t||e[63]!==c||e[64]!==b||e[65]!==g||e[66]!==h?(Q=d(go,{columns:n,filters:c,onAskAi:b,onFiltersChange:h,onSearchChange:g,search:t}),e[61]=n,e[62]=t,e[63]=c,e[64]=b,e[65]=g,e[66]=h,e[67]=Q):Q=e[67];let ne;return e[68]!==Y||e[69]!==Q?(ne=E("div",{className:"flex flex-col gap-2","data-testid":"db-view-toggle",children:[Y,Q]}),e[68]=Y,e[69]=Q,e[70]=ne):ne=e[70],ne},Ps=s=>{const e=B(110),{assistant:n,backRelations:o,browser:t,columnMeta:c,edit:l,editable:r,onAskAiFilter:a,onInspect:i,onOpenBulkPatch:m,onOpenGenerateRows:f,onRowDelete:p,onSaveQuery:b,page:u,preferences:g,queryBar:h,references:x}=s,v=g.maskColumns.size>0,y=n.unavailable?void 0:a;let C;e[0]!==t.addRow||e[1]!==t.bulkDelete||e[2]!==t.clearTable||e[3]!==t.columns||e[4]!==t.filter||e[5]!==t.filters||e[6]!==t.hasPredicate||e[7]!==t.liveError||e[8]!==t.onFilterChange||e[9]!==t.onFiltersChange||e[10]!==t.showJson||e[11]!==t.showTable||e[12]!==t.total||e[13]!==t.totalKnown||e[14]!==t.viewMode||e[15]!==r||e[16]!==m||e[17]!==f||e[18]!==g.maskOn||e[19]!==g.onToggleMask||e[20]!==v||e[21]!==y?(C=d(Ds,{columns:t.columns,editable:r,filter:t.filter,filters:t.filters,hasMaskedColumns:v,hasPredicate:t.hasPredicate,liveError:t.liveError,maskOn:g.maskOn,onAddRow:t.addRow,onAskAiFilter:y,onBulkDelete:t.bulkDelete,onBulkPatch:m,onClearTable:t.clearTable,onFilterChange:t.onFilterChange,onFiltersChange:t.onFiltersChange,onGenerateRows:f,onShowJson:t.showJson,onShowTable:t.showTable,onToggleMask:g.onToggleMask,total:t.total,totalKnown:t.totalKnown,viewMode:t.viewMode}),e[0]=t.addRow,e[1]=t.bulkDelete,e[2]=t.clearTable,e[3]=t.columns,e[4]=t.filter,e[5]=t.filters,e[6]=t.hasPredicate,e[7]=t.liveError,e[8]=t.onFilterChange,e[9]=t.onFiltersChange,e[10]=t.showJson,e[11]=t.showTable,e[12]=t.total,e[13]=t.totalKnown,e[14]=t.viewMode,e[15]=r,e[16]=m,e[17]=f,e[18]=g.maskOn,e[19]=g.onToggleMask,e[20]=v,e[21]=y,e[22]=C):C=e[22];let N;e[23]!==b||e[24]!==h?(N=h!==void 0&&d(xs,{onApply:h.onApplyQuery,onCopyLink:h.onCopyLink,onDelete:h.onDeleteQuery,onSave:b,saved:h.saved}),e[23]=b,e[24]=h,e[25]=N):N=e[25];let k;e[26]!==o||e[27]!==t.onBulkDeleteSelected||e[28]!==t.selectedTable||e[29]!==t.table||e[30]!==t.viewMode||e[31]!==r||e[32]!==u||e[33]!==g.maskView||e[34]!==g.onToggleTranspose||e[35]!==g.transposed?(k=t.viewMode==="table"&&u.rows.length>0&&d(po,{backRelations:o.available,columns:u.columns,editable:r,enabledBackRelations:o.enabled,name:t.selectedTable??"export",onBulkDelete:t.onBulkDeleteSelected,onToggleBackRelation:o.onToggle,onToggleTranspose:g.onToggleTranspose,rows:vt(u.rows,g.maskView),sqlColumns:u.sqlColumns,table:t.table.table,transposed:g.transposed}),e[26]=o,e[27]=t.onBulkDeleteSelected,e[28]=t.selectedTable,e[29]=t.table,e[30]=t.viewMode,e[31]=r,e[32]=u,e[33]=g.maskView,e[34]=g.onToggleTranspose,e[35]=g.transposed,e[36]=k):k=e[36];let S;e[37]!==t.cancelEdit||e[38]!==t.editing||e[39]!==t.saveEdit||e[40]!==t.setEditorDocumentText||e[41]!==c||e[42]!==r||e[43]!==u?(S=r&&t.editing!==null&&d(Rs,{columnMeta:c,documentText:t.editing.docText,onCancel:t.cancelEdit,onDocumentTextChange:t.setEditorDocumentText,onSave:t.saveEdit,refs:u.refs}),e[37]=t.cancelEdit,e[38]=t.editing,e[39]=t.saveEdit,e[40]=t.setEditorDocumentText,e[41]=c,e[42]=r,e[43]=u,e[44]=S):S=e[44];let w;e[45]!==t.committing||e[46]!==t.discardStaged||e[47]!==t.onCommitStaged||e[48]!==t.stagedChanges||e[49]!==r?(w=r&&t.stagedChanges.length>0&&d(Fo,{changes:t.stagedChanges,committing:t.committing,onCommit:t.onCommitStaged,onDiscard:t.discardStaged}),e[45]=t.committing,e[46]=t.discardStaged,e[47]=t.onCommitStaged,e[48]=t.stagedChanges,e[49]=r,e[50]=w):w=e[50];let T;e[51]!==t.writeError?(T=t.writeError!==null&&d("p",{className:"text-sm text-destructive","data-testid":"db-write-error",role:"alert",children:t.writeError}),e[51]=t.writeError,e[52]=T):T=e[52];let A;e[53]!==t.writeNotice?(A=t.writeNotice!==null&&d("p",{className:"text-sm text-muted-foreground","data-testid":"db-write-notice",role:"status",children:t.writeNotice}),e[53]=t.writeNotice,e[54]=A):A=e[54];let R;e[55]!==C||e[56]!==N||e[57]!==k||e[58]!==S||e[59]!==w||e[60]!==T||e[61]!==A?(R=E("div",{className:"flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3",children:[C,N,k,S,w,T,A]}),e[55]=C,e[56]=N,e[57]=k,e[58]=S,e[59]=w,e[60]=T,e[61]=A,e[62]=R):R=e[62];let _;e[63]!==t.viewMode||e[64]!==u?(_=t.viewMode==="table"&&u.rows.length===0&&d("div",{className:"flex flex-1 items-center justify-center p-6",children:d(Hn,{description:"Rows you insert into this table will show up here.",icon:d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"M4 5h16v14H4V5Zm0 5h16M10 10v9M4 14.5h16"})}),testId:"db-empty-rows",title:"This table is empty."})}),e[63]=t.viewMode,e[64]=u,e[65]=_):_=e[65];let $;e[66]!==t.viewMode||e[67]!==u||e[68]!==g.maskView||e[69]!==g.transposed?($=t.viewMode==="table"&&u.rows.length>0&&g.transposed&&d(mo,{columns:u.columns,rows:vt(u.rows,g.maskView)}),e[66]=t.viewMode,e[67]=u,e[68]=g.maskView,e[69]=g.transposed,e[70]=$):$=e[70];let O;e[71]!==o||e[72]!==t.filter||e[73]!==t.onRowEdit||e[74]!==t.table||e[75]!==t.viewMode||e[76]!==c||e[77]!==l||e[78]!==r||e[79]!==i||e[80]!==p||e[81]!==u||e[82]!==g.maskView||e[83]!==g.onTogglePin||e[84]!==g.pinnedColumns||e[85]!==g.transposed||e[86]!==x?(O=t.viewMode==="table"&&u.rows.length>0&&!g.transposed&&d(cs,{backRelationCounts:o.counts,columnMeta:c,edit:l,editable:r,highlight:t.filter,mask:g.maskView,onDelete:p,onEdit:t.onRowEdit,onInspect:i,onTogglePin:g.onTogglePin,pinnedColumns:g.pinnedColumns,refs:x,tableModel:t.table}),e[71]=o,e[72]=t.filter,e[73]=t.onRowEdit,e[74]=t.table,e[75]=t.viewMode,e[76]=c,e[77]=l,e[78]=r,e[79]=i,e[80]=p,e[81]=u,e[82]=g.maskView,e[83]=g.onTogglePin,e[84]=g.pinnedColumns,e[85]=g.transposed,e[86]=x,e[87]=O):O=e[87];let M;e[88]!==t.viewMode||e[89]!==u||e[90]!==g.maskView?(M=t.viewMode==="json"&&d("pre",{className:"min-h-0 flex-1 overflow-auto border-t border-border bg-muted/30 p-3 text-xs","data-testid":"db-json",children:JSON.stringify(vt(u.rows,g.maskView),Yt,2)}),e[88]=t.viewMode,e[89]=u,e[90]=g.maskView,e[91]=M):M=e[91];let I;e[92]!==t.changePageSize||e[93]!==t.goNext||e[94]!==t.goPrevious||e[95]!==t.hasNext||e[96]!==t.hasPrevious||e[97]!==t.jumpToPage||e[98]!==t.pageSize||e[99]!==t.rangeEnd||e[100]!==t.rangeStart||e[101]!==t.total?(I=d("div",{className:"flex shrink-0 items-center border-t border-border px-4 py-2",children:d(Bn,{hasNext:t.hasNext,hasPrevious:t.hasPrevious,onJumpToPage:t.jumpToPage,onNext:t.goNext,onPageSizeChange:t.changePageSize,onPrevious:t.goPrevious,pageSize:t.pageSize,prefix:"db",rangeEnd:t.rangeEnd,rangeStart:t.rangeStart,total:t.total})}),e[92]=t.changePageSize,e[93]=t.goNext,e[94]=t.goPrevious,e[95]=t.hasNext,e[96]=t.hasPrevious,e[97]=t.jumpToPage,e[98]=t.pageSize,e[99]=t.rangeEnd,e[100]=t.rangeStart,e[101]=t.total,e[102]=I):I=e[102];let z;return e[103]!==R||e[104]!==_||e[105]!==$||e[106]!==O||e[107]!==M||e[108]!==I?(z=E("div",{className:"flex min-h-0 flex-1 flex-col","data-testid":"db-page",children:[R,_,$,O,M,I]}),e[103]=R,e[104]=_,e[105]=$,e[106]=O,e[107]=M,e[108]=I,e[109]=z):z=e[109],z},As="/__lunora/seed",St=200,Is=50,Os=(s,e)=>{const n=[];for(const o of s)o.pk!==!0&&o.ref!==void 0&&o.type==="id"&&(e[o.ref]??[]).length===0&&n.push(o.name);return n},Fs=s=>Array.isArray(s)&&s.every(e=>Zt(e)),Ms=async s=>{let e;try{e=await fetch(As,{body:JSON.stringify(s),headers:{"Content-Type":"application/json"},method:"POST"})}catch(o){return{kind:"error",message:`seed request failed: ${Ft(o)}`}}let n;try{n=await e.json()??{}}catch{return{kind:"error",message:`seed request failed (${String(e.status)})`}}if(e.ok&&n.rows!==void 0){let o;try{o=Rt(n.rows)}catch(t){return{kind:"error",message:`seed response could not be decoded: ${Ft(t)}`}}return Fs(o)?{kind:"ok",rows:o}:{kind:"error",message:"seed response did not carry a list of row documents"}}return n.error==="fk-parents-empty"?{kind:"error",message:`no rows to reference in ${(Array.isArray(n.tables)?n.tables.filter(t=>typeof t=="string"):[]).join(", ")} — seed those tables first`}:{kind:"error",message:typeof n.error=="string"?n.error:`seed request failed (${String(e.status)})`}},Ls="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",Vs="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",Bs=({columns:s,fkPools:e,onClose:n,onInsertRows:o,table:t})=>{const c=he(),[l,r]=D(10),[a,i]=D(!1),[m,f]=D(void 0),[p,b]=D(void 0),[u,g]=D(0),h=N=>{const k=Number(N.target.value);!Number.isNaN(k)&&k>=1&&r(Math.min(k,St))},x=async()=>{f(void 0),b(void 0),g(0),i(!0);try{const N=await Ms({count:l,existingIds:e,seed:Date.now(),table:t});if(N.kind==="error"){f(N.message);return}const{rows:k}=N;if(k.length===0){f(c("No rows generated — all columns were skipped."));return}const S=await o(k);if(S.error!==void 0){f(S.error);return}b(S.inserted),g(S.conflicts)}finally{i(!1)}},v=()=>{Ce(x())},y=s.filter(N=>N.pk!==!0),C=Os(s,e);return E(ut,{label:c("Generate dummy rows"),onClose:n,panelTestId:"gen-rows-panel",testId:"gen-rows-overlay",variant:"dialog",children:[E("div",{className:"flex items-start justify-between",children:[E("div",{className:"flex flex-col gap-0.5",children:[d("h3",{className:"text-base text-foreground","data-testid":"gen-rows-title",children:c("Generate dummy rows")}),d("p",{className:"text-xs text-muted-foreground","data-testid":"gen-rows-desc",children:c("Seed {table} with Faker-generated rows. Existing rows are not affected.",{table:t})})]}),d("button",{className:"text-xs text-muted-foreground hover:text-foreground","data-testid":"gen-rows-close",onClick:n,type:"button",children:c("Close")})]}),E("div",{className:"flex items-center gap-2",children:[d("label",{className:"text-xs font-medium text-foreground",htmlFor:"gen-rows-count",children:c("Row count")}),d("input",{className:"w-20 rounded-md border border-border bg-background px-2 py-1 text-xs outline-none focus-visible:border-ring","data-testid":"gen-rows-count",id:"gen-rows-count",max:St,min:1,onChange:h,type:"number",value:l}),d("span",{className:"text-xs text-muted-foreground",children:c("(max {max})",{max:St.toString()})})]}),y.length>0&&E("div",{className:"flex flex-col gap-1",children:[d("p",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:c("Columns to seed")}),d("ul",{className:"flex flex-col gap-0.5","data-testid":"gen-rows-columns",children:y.map(N=>{const k=N.ref!==void 0&&N.type==="id",S=k&&(e[N.ref??""]??[]).length===0,w=S?"rounded bg-destructive/10 px-1 text-destructive":"rounded bg-muted px-1 text-muted-foreground",T=S?`gen-rows-fk-empty-${N.name}`:`gen-rows-fk-ok-${N.name}`,A=S?c("FK: no rows in {ref} — seed it first",{ref:N.ref??""}):c("→ {ref}",{ref:N.ref??""});return E("li",{className:"flex items-center gap-1.5 font-mono text-xs",children:[d("span",{className:"text-foreground",children:N.name}),E("span",{className:"text-muted-foreground",children:["(",N.type,")"]}),N.optional&&d("span",{className:"rounded bg-muted px-1 font-mono text-[10px] tracking-wide uppercase",children:"optional"}),k&&d("span",{className:w,"data-testid":T,children:A})]},N.name)})})]}),C.length>0&&d("p",{className:"text-xs text-destructive","data-testid":"gen-rows-blocked",role:"alert",children:c("Cannot generate rows: these columns reference tables with no rows: {cols}. Seed those tables first.",{cols:C.join(", ")})}),m!==void 0&&d("p",{className:"text-xs text-destructive","data-testid":"gen-rows-error",role:"alert",children:m}),p!==void 0&&m===void 0&&d("p",{className:"text-xs text-success","data-testid":"gen-rows-success",children:u>0?c("Inserted {inserted} of {total} rows — {conflicts} skipped as id conflicts.",{conflicts:u.toString(),inserted:p.toString(),total:(p+u).toString()}):c("Inserted {count} rows successfully.",{count:p.toString()})}),E("div",{className:"flex justify-end gap-2",children:[d("button",{className:Ls,"data-testid":"gen-rows-cancel",onClick:n,type:"button",children:c("Cancel")}),d("button",{className:Vs,"data-testid":"gen-rows-generate",disabled:a||C.length>0,onClick:v,type:"button",children:c(a?"Inserting…":"Generate & insert")})]})]})},js=Te(pe.backRelationCounts),zs=(s,e,n,o)=>{const t=B(16),c=dt();let l;t[0]===Symbol.for("react.memo_cache_sentinel")?(l={},t[0]=l):l=t[0];const[r,a]=D(l);let i;if(t[1]!==s||t[2]!==e){let x;t[4]!==s?(x=v=>s.has(Dt(v)),t[4]=s,t[5]=x):x=t[5],i=e.filter(x),t[1]=s,t[2]=e,t[3]=i}else i=t[3];const m=i;let f;t[6]!==n||t[7]!==m?(f=JSON.stringify([m,n]),t[6]=n,t[7]=m,t[8]=f):f=t[8];const p=f;let b;t[9]!==c||t[10]!==o||t[11]!==p?(b=async x=>{const[v,y]=JSON.parse(p);if(v.length===0||y.length===0){x.cancelled||a({});return}try{const C=await c.query(js,{ids:y,relations:v},ke(o));x.cancelled||a(Object.fromEntries(C.relations.map(qs)))}catch{}},t[9]=c,t[10]=o,t[11]=p,t[12]=b):b=t[12];const u=b;let g,h;return t[13]!==u?(g=()=>{const x={cancelled:!1};return Ce(u(x)),()=>{x.cancelled=!0}},h=[u],t[13]=u,t[14]=g,t[15]=h):(g=t[14],h=t[15]),Be(g,h),r};function qs(s){return[Dt(s),s.counts]}const Ks=async s=>{const{args:e,maxBatches:n,openCursor:o,query:t}=s;let c=o,l=0,r="cap-hit";for(let a=0;a<n;a+=1){const i=await t({...e,after:c});if(l+=i.count,c=i.cursor,!i.hasMore){r="completed";break}}return{cursor:r==="cap-hit"?c:void 0,outcome:r,written:l}},at=s=>{const e=s[0];return e===void 0?void 0:{column:e.id,direction:e.desc?"desc":"asc"}},cn=s=>s==null?"":typeof s=="object"?JSON.stringify(s):String(s),Wt=s=>s.map(e=>({column:e.column,...e.value===void 0?{}:{literal:[e.value]},operator:e.operator,value:e.value===void 0?"":cn(e.value)})),Ht=s=>s===void 0?[]:[{desc:s.direction==="desc",id:s.column}],Gs=s=>[s.column,s.operator,s.value],lt=(s,e,n,o)=>JSON.stringify([s??"",e??"",(n??[]).map(t=>Gs(t)),o===void 0?null:[o.column,o.direction]]),At=200,Js=20,Ws=Te(pe.readTablePage),Hs=Te(pe.facetColumn),kt=Te(pe.writeRow),Us=Te(pe.deleteRows),Qs=Te(pe.clearTable),Ys=Te(pe.patchRows),Xs={},It=new Set(["__doc__","__id__","_creationTime","_id","id"]),Zs=s=>{const e=s.__doc__;if(typeof e=="string"){const o=Jn(e);if(o!==void 0)return o}const n={};for(const[o,t]of Object.entries(s))It.has(o)||(n[o]=t);return n},el=(s,e,n)=>JSON.stringify([s.__lunoraRef,n,en(e)]),tl=({filters:s,offset:e,pageSize:n,search:o,sorting:t,table:c})=>({filters:Fe(s),limit:n,offset:e,orderBy:at(t),search:o,skipCount:!0,table:c}),nl=({filters:s,search:e,table:n})=>({filters:Fe(s),limit:1,search:e,table:n}),ol=(s,e)=>{const n=new Map;for(const t of s?.rows??[]){const c=Pe(t);c!==null&&n.set(c,t)}const o=[];for(const[t,c]of Object.entries(e))for(const[l,r]of Object.entries(c))o.push({column:l,newValue:r,oldValue:n.get(t)?.[l],rowId:t});return o},sl=s=>!It.has(s),ll=`Stopped after ${At.toString()} batches — rows still match. Run it again to remove the rest.`,rl=`Stopped after ${At.toString()} batches — rows still match. Run it again to set the rest.`,Ut={resumable:!1,truncated:ll,verb:"deleted"},al={resumable:!0,truncated:rl,verb:"written"},il=({initialFilters:s,initialOrderBy:e,initialSearch:n,initialShardKey:o,onSelectTable:t,onViewChange:c,pageSize:l,resolveBackRelations:r,tableParam:a})=>{const i=dt(),[m,f]=D(l),[p,b]=D(o??""),u=a===void 0||a===""?null:a,[g,h]=D(0),[x,v]=D("table"),[y,C]=D(()=>Ht(e)),[N,k]=D(n??""),[S,w]=D(()=>Wt(s??[])),{clearFacets:T,facets:A,refetchFacets:R,toggleFacet:_}=jn(),[$,O]=D(null),[M,I]=D(null),[z,q]=D(null),F=Ge(null),V=Oo(),[J,K]=D(null),[Z,Y]=D(!1),[Q,ne]=D(a),[oe,de]=D(()=>lt(o,n,s,e)),[ue,me]=D(0),[re,fe]=D(()=>lt(o,n,s,e)),ae=a!==Q,X=lt(o,n,s,e),te=ae||!ae&&X!==oe&&X!==re;if(te){ne(a),de(X),me(j=>j+1),C(Ht(e)),k(n??"");const P=Wt(s??[]);w(P),b(o??""),T(),V.clear(),K(null),h(0),I(null),q(null),F.current=null}else X!==oe&&de(X);const xe=te?n??"":N,ie=te?o??"":p,ce=`${a??""}:${ue.toString()}`,W=Vt(xe.trim(),300,ce),G=Vt(ie.trim(),400,ce),ee=lt(G,W,Fe(S),at(y));ee!==re&&fe(ee);const H=Xe(pe.listTables,Xs,{live:!0,shardKey:G}),ve=H.data??null,ge=H.error,we=tl({filters:S,offset:g,pageSize:m,search:W,sorting:y,table:u??""}),ye=nl({filters:S,search:W,table:u??""}),U=Xe(pe.readTablePage,we,{enabled:u!==null,keepPreviousData:!1,live:!0,shardKey:G}),se=U.data??null,Me=U.error,{liveError:Ae}=U,Ie=Xe(pe.readTablePage,ye,{enabled:u!==null,live:!0,shardKey:G});Be(()=>{H.data!==void 0&&ho(G)},[H.data,G]);const We=P=>{t?.(P)},Se=(P,j)=>{t?.(P,{search:j})},ze=async(P,j)=>{try{return(await i.query(Ws,{filters:[],limit:Js,offset:0,search:j,table:P},ke(G))).rows.find(_e=>Pe(_e)===j)??null}catch{return null}},Le=(P,j,Ne,_e)=>$e=>i.query(Hs,{column:$e,filters:Fe(Ne),search:_e,table:j},ke(P)),He=P=>{_(P,u===null?null:Le(G,u,S,W))},ft=(P,j)=>{const Ne={column:P,literal:[j],operator:"eq",value:cn(j)};w(_e=>[..._e.filter($e=>$e.column!==P),Ne]),h(0)},mt=wt(Le),et=wt(R),tt=wt(c);Be(()=>{u!==null&&et.current(mt.current(G,u,S,W))},[G,u,S,W]),Be(()=>{u===null||tt.current===void 0||Q!==a||oe!==X||tt.current({filters:Fe(S),orderBy:at(y),search:W,shard:G})},[u,a,Q,oe,X,S,y,W,G]);const Ue=P=>{u!==null&&h(Math.max(0,P))},nt=(P,j)=>{K({column:j,rowId:P})},gt=()=>{K(null)},pt=async()=>{if(u!==null){I(null),Y(!0);try{for(const[P,j]of Object.entries(V.staged))await i.query(kt,{doc:j,id:P,op:"patch",table:u},ke(G)),V.drop(P,j)}catch(P){I(P.message)}K(null),U.refetch(),Y(!1)}},bt=()=>{V.clear(),K(null)},ht=ol(se,V.staged),ot=async(P,j,Ne)=>{if(u===null)return;I(null);let _e;if(P!=="delete"){let $e;try{$e=Ne===void 0||Ne.trim()===""?{}:JSON.parse(Ne)}catch(Ve){I(`Invalid JSON: ${Ve.message}`);return}try{const Ve=Rt($e);if(!Zt(Ve)){I("The document must be a JSON object.");return}_e=Ve}catch(Ve){I(`Invalid document: ${Ve.message}`);return}}try{await i.query(kt,{doc:_e,id:j??void 0,op:P,table:u},ke(G)),O(null),U.refetch()}catch($e){I($e.message)}},Qe=async(P,j,Ne)=>{if(u===null)return 0;I(null),q(null);const _e=el(P,j,G),$e=F.current?.key===_e?F.current.after:void 0,Ve=Ne.resumable?$e??"":void 0;let qe=0;try{const Ye=await Ks({args:j,maxBatches:At,openCursor:Ve,query:async Fn=>{const Ot=await i.query(P,Fn,ke(G));return qe+=Ot.count,Ot}});return F.current=Ye.cursor===void 0?null:{after:Ye.cursor,key:_e},Ye.outcome==="cap-hit"&&I(Ne.truncated),q(`${qe.toString()} ${qe===1?"row":"rows"} ${Ne.verb}.`),qe}catch(Ye){return I(`${Ye.message} (at least ${qe.toString()} rows were already ${Ne.verb})`),F.current=null,qe}finally{h(0),U.refetch()}},xt=P=>{C(P),h(0)},L=Tt(()=>u===null?[]:r?.(u)??[],[r,u]),le=ds(se,y,xt,L),Ee={filters:Fe(S),orderBy:at(y),search:W,shard:p,table:u??void 0},Re=Ie.data?.total,Oe=Re!==void 0,st=Re??(se===null?0:g+se.rows.length),dn=g>0,un=W!==""||Fe(S).length>0,fn=se!==null&&(Oe?g+se.rows.length<st:se.rows.length===m),mn=se===null||se.rows.length===0?0:g+1,gn=se===null?0:g+se.rows.length,pn=()=>{H.refetch()},bn=()=>{v("table")},hn=()=>{v("json")},xn=()=>{Ce(Qe(Us,{filters:Fe(S),search:W,table:u},Ut))},vn=()=>{Ce(Qe(Qs,{table:u},Ut))},wn=P=>{Ce(Qe(Ys,{doc:P,filters:Fe(S),search:W,table:u},al))},yn=P=>{k(P.target.value),h(0)},Cn=P=>{w(P),h(0)},Nn=()=>{I(null);const P={};for(const j of se?.columns??[])It.has(j)||(P[j]="");O({docText:JSON.stringify(P,null,2),id:""})},Sn=P=>{O(j=>j===null?j:{docText:P,id:j.id})},kn=()=>{$!==null&&Ce(ot($.id===""?"insert":"patch",$.id===""?null:$.id,$.docText))},Tn=()=>{O(null),I(null)},En=()=>{Ue(g-m)},_n=()=>{Ue(g+m)},Rn=P=>{Ue(Math.max(0,(P-1)*m))},$n=P=>{f(P),h(0)},Dn=(P,j)=>{I(null),O({docText:JSON.stringify(en(Zs(j)),null,2),id:P})},Pn=P=>{Ce(ot("delete",P))},An=async P=>{if(!(u===null||P.length===0)){I(null);try{for(const j of P)await i.query(kt,{id:j,op:"delete",table:u},ke(G));U.refetch()}catch(j){I(j.message)}}},In=P=>{Ce(An(P))},On=()=>{Ce(pt())};return{addRow:Nn,bulkDelete:xn,bulkPatch:wn,cancelCellEdit:gt,cancelEdit:Tn,changePageSize:$n,clearTable:vn,columns:se?.columns??[],committing:Z,currentView:Ee,discardStaged:bt,editableColumn:sl,editing:$,editingCell:J,facetFilter:ft,facets:A,filter:N,filters:S,goNext:_n,goPrevious:En,hasNext:fn,hasPredicate:un,hasPrevious:dn,jumpToPage:Rn,liveError:Ae,loadTables:pn,navigateToRef:Se,onBulkDeleteSelected:In,onCommitStaged:On,onFilterChange:yn,onFiltersChange:Cn,onRowDelete:Pn,onRowEdit:Dn,page:se,previewRef:ze,pageError:Me,pageSize:m,rangeEnd:gn,rangeStart:mn,queryShardKey:G,saveEdit:kn,selectedTable:u,selectTable:We,setEditorDocumentText:Sn,setShardKey:b,shardKey:p,showJson:hn,showTable:bn,stage:V.stage,stagedChanges:ht,stagedValue:V.stagedValue,startCellEdit:nt,table:le,tables:ve,tablesError:ge,toggleFacet:He,total:st,totalKnown:Oe,viewMode:x,writeError:M,writeNotice:z}},cl="lunora-studio-pinned-columns",dl=s=>{const e=B(21),{columns:n,initialPins:o,selectedTable:t}=s;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[l,r]=Qt(cl,c),a=t??"",i=l[a];let m;e[1]!==o||e[2]!==i?(m=i===void 0?new Set((o??"").split(",").filter(ul)):new Set(i),e[1]=o,e[2]=i,e[3]=m):m=e[3];const f=m;let p;e[4]!==a||e[5]!==f||e[6]!==r?(p=T=>{r(A=>{const R=A[a]??[...f],_=R.includes(T)?R.filter($=>$!==T):[...R,T];return{...A,[a]:_}})},e[4]=a,e[5]=f,e[6]=r,e[7]=p):p=e[7];const b=p,[u,g]=D(!1);let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{g(fl)},e[8]=h):h=e[8];const x=h;let v;e[9]!==n||e[10]!==t?(v={columns:n,selectedTable:t},e[9]=n,e[10]=t,e[11]=v):v=e[11];const{maskColumns:y,maskOn:C,maskView:N,maskViewFor:k,onToggleMask:S}=zn(v);let w;return e[12]!==y||e[13]!==C||e[14]!==N||e[15]!==k||e[16]!==S||e[17]!==b||e[18]!==f||e[19]!==u?(w={maskColumns:y,maskOn:C,maskView:N,maskViewFor:k,onToggleMask:S,onTogglePin:b,onToggleTranspose:x,pinnedColumns:f,transposed:u},e[12]=y,e[13]=C,e[14]=N,e[15]=k,e[16]=S,e[17]=b,e[18]=f,e[19]=u,e[20]=w):w=e[20],w};function ul(s){return s!==""}function fl(s){return!s}const ml=Te(pe.describeTable),gl=Te(pe.readTablePage),pl=Te(pe.importShard),bl=s=>{const e=s._id??s.id??s.__id__??"";return typeof e=="string"?e:typeof e=="number"?String(e):""},hl=s=>{const e=Object.values(s.inserted).reduce((a,i)=>a+i,0),[n]=s.errors;if(n===void 0)return{conflicts:s.conflicts,error:void 0,inserted:e};const o=s.errors.length-1,t=e+s.conflicts+s.errors.length,c=o===1?"error":"errors",l=o>0?` (+${o.toString()} more ${c})`:"",r=`Inserted ${e.toString()} of ${t.toString()} rows — row ${n.line.toString()} (${n.table}): ${n.message}${l}`;return{conflicts:s.conflicts,error:r,inserted:e}},xl=s=>{const e=dt(),[n,o]=D(!1),[t,c]=D(void 0),[l,r]=D(void 0),[a,i]=D(void 0),[m,f]=D({}),[p,b]=D(!1),[u,g]=D(void 0),h=async(C,N)=>{o(!0),c(C),r(N),i(void 0),f({}),g(void 0),b(!0);try{const k=await e.query(ml,{table:C},ke(N)),{columns:S}=k;i(S);const w={},T=S.filter(A=>A.ref!==void 0&&A.type==="id"&&A.pk!==!0);for(const A of T){if(A.ref===void 0)continue;const{ref:R}=A;if(w[R]===void 0)try{const _=await e.query(gl,{filters:[],limit:Is,offset:0,search:"",table:R},ke(N));w[R]=_.rows.flatMap($=>bl($)||[])}catch{w[R]=[]}}f(w)}catch(k){g(k.message)}b(!1)};return{closeDialog:()=>{o(!1),c(void 0),r(void 0),i(void 0),f({}),g(void 0)},columnMeta:a,error:u,fkPools:m,insertBatch:async(C,N)=>{if(t===void 0||l===void 0)return{conflicts:0,error:"No table selected.",inserted:0};try{const k=await e.query(pl,{rows:C.map(w=>({doc:w,table:t}))},ke(l)),S=hl(k);return S.error!==void 0||(N(),s()),S}catch(k){return{conflicts:0,error:k.message,inserted:0}}},loading:p,open:n,openDialog:(C,N)=>{Ce(h(C,N))},shardKey:l,table:t}},vl=()=>{const s=B(6),[e,n]=D(null);let o;s[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>{n(null)},s[0]=o):o=s[0];const t=o,[c,l]=D(null);let r;s[1]===Symbol.for("react.memo_cache_sentinel")?(r=(p,b)=>{l({column:p,value:b})},s[1]=r):r=s[1];const a=r;let i;s[2]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{l(null)},s[2]=i):i=s[2];const m=i;let f;return s[3]!==c||s[4]!==e?(f={closeExpandedCell:m,closeInspect:t,expandedCell:c,inspecting:e,onExpandCell:a,onInspect:n},s[3]=c,s[4]=e,s[5]=f):f=s[5],f},wl=/(?:_creationtime|(?:^|[a-z])(?:time|at))$/iu,yl=(s,e)=>typeof e=="number"&&wl.test(s),Cl=s=>{const e=B(36),{column:n,masked:o,onNavigate:t,target:c,value:l}=s;let r;e[0]!==t||e[1]!==c||e[2]!==l?(r=()=>{c!==void 0&&t(c,String(l))},e[0]=t,e[1]=c,e[2]=l,e[3]=r):r=e[3];const a=r;if(l==null){let f;return e[4]===Symbol.for("react.memo_cache_sentinel")?(f=d("span",{className:"italic text-muted-foreground",children:"null"}),e[4]=f):f=e[4],f}if(o){const f=`rd-masked-${n}`;let p;e[5]!==l?(p=je(l),e[5]=l,e[6]=p):p=e[6];let b;return e[7]!==f||e[8]!==p?(b=d("span",{className:"italic text-muted-foreground","data-testid":f,title:"Masked (preview)",children:p}),e[7]=f,e[8]=p,e[9]=b):b=e[9],b}if(c!==void 0&&(typeof l=="string"||typeof l=="number")&&String(l)!==""){const f=`rd-ref-${n}`,p=`Open ${c} ${String(l)}`,b=String(l);let u;return e[10]!==a||e[11]!==f||e[12]!==p||e[13]!==b?(u=E("button",{"data-testid":f,onClick:a,title:p,type:"button",children:[b," ↗"]}),e[10]=a,e[11]=f,e[12]=p,e[13]=b,e[14]=u):u=e[14],u}if(yl(n,l)){const f=`rd-ts-${n}`;let p;e[15]!==l?(p=l.toString(),e[15]=l,e[16]=p):p=e[16];let b;e[17]!==l?(b=Ln(l),e[17]=l,e[18]=b):b=e[18];let u;return e[19]!==f||e[20]!==p||e[21]!==b?(u=d("span",{"data-testid":f,title:p,children:b}),e[19]=f,e[20]=p,e[21]=b,e[22]=u):u=e[22],u}if(l instanceof ArrayBuffer||ArrayBuffer.isView(l)){const f=`rd-bytes-${n}`;let p;e[23]!==l?(p=je(l),e[23]=l,e[24]=p):p=e[24];let b;return e[25]!==f||e[26]!==p?(b=d("span",{"data-testid":f,children:p}),e[25]=f,e[26]=p,e[27]=b):b=e[27],b}if(typeof l=="object"){let f;e[28]!==l?(f=JSON.stringify(l,Yt,2),e[28]=l,e[29]=f):f=e[29];let p;return e[30]!==f?(p=d("pre",{className:"m-0 overflow-auto rounded-md bg-muted/50 p-2 text-xs",children:f}),e[30]=f,e[31]=p):p=e[31],p}let i;e[32]!==l?(i=je(l),e[32]=l,e[33]=i):i=e[33];let m;return e[34]!==i?(m=d("span",{children:i}),e[34]=i,e[35]=m):m=e[35],m},Nl=s=>{const e=B(23),{columns:n,mask:o,onClose:t,onNavigate:c,refs:l,row:r}=s;let a;e[0]!==t||e[1]!==c?(a=(g,h)=>{c(g,h),t()},e[0]=t,e[1]=c,e[2]=a):a=e[2];const i=a;let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=d("h3",{className:"m-0 text-base text-foreground",children:"Row detail"}),e[3]=m):m=e[3];let f;e[4]!==t?(f=E("div",{className:"mb-3 flex items-center justify-between",children:[m,d("button",{"data-testid":"rd-close",onClick:t,type:"button",children:"Close"})]}),e[4]=t,e[5]=f):f=e[5];let p;if(e[6]!==n||e[7]!==o||e[8]!==i||e[9]!==l||e[10]!==r){let g;e[12]!==o||e[13]!==i||e[14]!==l||e[15]!==r?(g=h=>E("div",{className:"border-t border-border py-2 first:border-t-0","data-testid":`rd-field-${h}`,children:[d("dt",{className:"mb-0.5 text-xs font-semibold text-muted-foreground",children:h}),d("dd",{className:"m-0",children:d(Cl,{column:h,masked:o.enabled&&o.columns.has(h),onNavigate:i,target:l?.[h],value:r[h]})})]},h),e[12]=o,e[13]=i,e[14]=l,e[15]=r,e[16]=g):g=e[16],p=n.map(g),e[6]=n,e[7]=o,e[8]=i,e[9]=l,e[10]=r,e[11]=p}else p=e[11];let b;e[17]!==p?(b=d("dl",{"data-testid":"rd-fields",children:p}),e[17]=p,e[18]=b):b=e[18];let u;return e[19]!==t||e[20]!==f||e[21]!==b?(u=E(ut,{label:"Row detail",onClose:t,panelTestId:"rd-panel",testId:"rd-overlay",variant:"drawer",children:[f,b]}),e[19]=t,e[20]=f,e[21]=b,e[22]=u):u=e[22],u},Sl=50,kl=s=>{const e=B(8),{active:n,onPick:o,shard:t}=s;let c;e[0]!==o||e[1]!==t?(c=()=>{o(t)},e[0]=o,e[1]=t,e[2]=c):c=e[2];const l=c,r=`w-full rounded px-2 py-0.5 text-left text-xs transition-colors hover:bg-accent ${n?"bg-accent font-medium":""}`,a=`shard-explorer-item-${t}`;let i;return e[3]!==l||e[4]!==t||e[5]!==r||e[6]!==a?(i=d("button",{className:r,"data-testid":a,onClick:l,type:"button",children:t}),e[3]=l,e[4]=t,e[5]=r,e[6]=a,e[7]=i):i=e[7],i},Tl=({onFetchTables:s,onSelect:e})=>{const n=he(),[o]=D(()=>xo()),[t,c]=D(!1),[l,r]=D(void 0),[a,i]=D(void 0),[m,f]=D(!1),[p,b]=D(void 0),u=Ge(0),g=()=>{c(v=>!v)},h=async v=>{e(v),r(v),i(void 0),b(void 0),f(!0),u.current+=1;const y=u.current;try{const C=await s(v);u.current===y&&i(C?.slice(0,Sl))}catch(C){u.current===y&&b(C.message)}u.current===y&&f(!1)},x=v=>{Ce(h(v))};return o.length===0?null:E("div",{"data-testid":"shard-explorer",children:[E("button",{"aria-controls":"shard-explorer-panel","aria-expanded":t,className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"shard-explorer-toggle",onClick:g,type:"button",children:[n("Shards seen"),d("span",{"aria-hidden":"true",className:`ml-0.5 transition-transform ${t?"rotate-180":""}`,children:"▾"})]}),t&&E("div",{className:"mt-1 flex flex-col gap-1 rounded-md border border-border bg-popover p-2","data-testid":"shard-explorer-panel",id:"shard-explorer-panel",children:[d("p",{className:"text-xs text-muted-foreground","data-testid":"shard-explorer-hint",children:n("Recently visited shards — click to switch")}),d("ul",{className:"flex flex-col gap-0.5","data-testid":"shard-explorer-list",children:o.map(v=>d("li",{children:d(kl,{active:l===v,onPick:x,shard:v})},v))}),l!==void 0&&E("div",{className:"mt-1 border-t border-border pt-1","data-testid":"shard-explorer-summary",children:[d("p",{className:"mb-1 text-xs font-medium text-foreground","data-testid":"shard-explorer-summary-title",children:n("{shard} tables",{shard:l})}),m&&d("p",{className:"text-xs text-muted-foreground","data-testid":"shard-explorer-loading",children:n("Loading…")}),p!==void 0&&d("p",{className:"text-xs text-destructive","data-testid":"shard-explorer-error",role:"alert",children:p}),!m&&p===void 0&&a?.length===0&&d("p",{className:"text-xs text-muted-foreground","data-testid":"shard-explorer-empty",children:n("No tables in this shard.")}),!m&&p===void 0&&a!==void 0&&a.length>0&&d("ul",{className:"flex flex-col gap-0.5","data-testid":"shard-explorer-tables",children:a.map(v=>E("li",{className:"flex items-center justify-between text-xs",children:[d("span",{"data-testid":`shard-explorer-table-${v.name}`,children:v.name}),d("span",{className:"text-muted-foreground","data-testid":`shard-explorer-rowcount-${v.name}`,children:v.rowCount})]},v.name))})]})]})]})},El="lunora-studio-back-relations",_l=s=>new Set((s??[]).filter(e=>e.unique===!0&&e.fields.length===1).map(e=>e.fields[0]??"")),Rl={},$l=50,Dl=[],Pl=Te(pe.listTables),Al=Te(pe.readTablePage),Il=s=>{const e=B(10),{onFetchShardTables:n,onShardChange:o,schemaSwitch:t,shardKey:c}=s;let l;e[0]!==o||e[1]!==c?(l=d(Mn,{onChange:o,testId:"db-shard-input",value:c}),e[0]=o,e[1]=c,e[2]=l):l=e[2];let r;e[3]!==n||e[4]!==o?(r=d(Tl,{onFetchTables:n,onSelect:o}),e[3]=n,e[4]=o,e[5]=r):r=e[5];let a;return e[6]!==t||e[7]!==l||e[8]!==r?(a=E("div",{className:"flex shrink-0 flex-col items-stretch gap-2 border-b border-border p-3",children:[t,l,r]}),e[6]=t,e[7]=l,e[8]=r,e[9]=a):a=e[9],a},ur=({editable:s=!1,globalTableNames:e,initialFilters:n,initialOrderBy:o,initialPins:t,initialSearch:c,initialShardKey:l,onNavigateToGlobal:r,onSelectTable:a,onViewChange:i,pageSize:m=$l,queryBar:f,schemaSwitch:p,tableParam:b})=>{const u=Xe(pe.describeTables,{},{shardKey:l??""}),g=Xe(pe.listTablesIndexes,{},{shardKey:l??""}),h=u.data?.columnsByTable??Rl,[x,v]=Qt(El,{}),y=it(L=>{const le=new Set(x[L]);return Bt(L,h).filter(Ee=>le.has(Dt(Ee)))},[x,h]),C=il({initialFilters:n,initialOrderBy:o,initialSearch:c,initialShardKey:l,onSelectTable:a,onViewChange:i,pageSize:m,resolveBackRelations:y,tableParam:b}),{cancelCellEdit:N,columns:k,currentView:S,editableColumn:w,editingCell:T,facetFilter:A,facets:R,loadTables:_,navigateToRef:$,onFiltersChange:O,page:M,pageError:I,previewRef:z,queryShardKey:q,selectedTable:F,selectTable:V,setShardKey:J,shardKey:K,stage:Z,stagedValue:Y,startCellEdit:Q,tables:ne,tablesError:oe,toggleFacet:de}=C,ue=Gn(K),me=L=>{Ce((async()=>{const Ee=await ue.suggestFilter(L,F??"");Ee!==void 0&&O(Ee.map(Re=>{const Oe=Re.value,st=typeof Oe=="string"||typeof Oe=="number"||typeof Oe=="boolean"?String(Oe):"";return{column:Re.column,operator:Re.operator,value:st}}))})())},re=F===null?[]:Bt(F,h),fe=new Set(x[F??""]),ae=[];for(const L of M?.rows??[]){const le=L._id??L.id;typeof le=="string"&&le!==""&&ae.push(le)}const X=zs(fe,re,ae,q),be=L=>{v(le=>{const Ee=F??"",Re=le[Ee]??[];return{...le,[Ee]:Re.includes(L)?Re.filter(Oe=>Oe!==L):[...Re,L]}})},te=dl({columns:k,initialPins:t,selectedTable:F}),xe=vl(),[ie,ce]=D(null),{closeExpandedCell:W,closeInspect:G,expandedCell:ee,inspecting:H,onExpandCell:ve}=xe,ge=dt(),we=Object.fromEntries((h[F??""]??[]).map(L=>[L.name,L])),ye=new Map;for(const L of h[F??""]??[])L.isStorage===!0&&ye.set(L.name,L.bucket);const U=it(async(L,le)=>ge.signedStorageUrl(L,le===void 0?{}:{bucket:le}),[ge]),se=async L=>await ge.query(Pl,{},ke(L)),Me=()=>{F!==null&&V(F)},{closeDialog:Ae,columnMeta:Ie,fkPools:We,insertBatch:Se,open:ze,openDialog:Le}=xl(Me),He=()=>{F!==null&&Le(F,K)},ft=L=>Se(L,Ae),[mt,et]=D(!1),tt=()=>{et(!0)},Ue=()=>{et(!1)},nt=(L,le)=>{if(r!==void 0&&e?.has(L)===!0){r(L,le);return}$(L,le)},gt=f?.onSaveQuery,pt=L=>{gt?.(L,S)},bt={cancelEdit:N,editable:s,editableColumn:w,editingCell:T,onExpandCell:ve,stage:Z,stagedValue:Y,startEdit:Q},ht=L=>{L!==null&&ce(L)},ot=()=>{C.onRowDelete(ie)},Qe=async(L,le,Ee)=>await ge.query(Al,{filters:[{column:le,operator:"eq",value:Ee}],limit:rt,offset:0,orderBy:[],table:L},ke(q)),xt={columns:M?.refs,maskViewFor:te.maskViewFor,onNavigate:nt,onPreview:z};return E("div",{className:"flex h-full min-w-0","data-testid":"lunora-data-browser",children:[d(qn,{header:d(Il,{onFetchShardTables:se,onShardChange:J,schemaSwitch:p,shardKey:K}),onReload:_,onSelect:V,prefix:"db",selected:F,tables:ne??Dl}),E("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[oe!==null&&d("p",{className:"shrink-0 border-b border-border px-4 py-2 text-sm text-destructive","data-testid":"db-tables-error",role:"alert",children:oe}),M===null&&I===null&&d("div",{className:"flex flex-1 items-center justify-center p-6",children:d("p",{className:"text-sm text-muted-foreground",children:"Select a table to browse its rows."})}),I!==null&&d("p",{className:"shrink-0 border-b border-border px-4 py-2 text-sm text-destructive","data-testid":"db-page-error",role:"alert",children:I}),M!==null&&d(Ps,{assistant:ue,backRelations:{available:re,counts:X,enabled:fe,onToggle:be},browser:C,columnMeta:we,edit:bt,editable:s,onAskAiFilter:me,onInspect:xe.onInspect,onOpenBulkPatch:tt,onOpenGenerateRows:He,onRowDelete:ht,onSaveQuery:pt,page:M,preferences:te,queryBar:f,references:xt})]}),M!==null&&d(Kn,{columns:k,facets:R,mask:te.maskView,onFacetFilter:A,onToggleFacet:de}),H!==null&&M!==null&&d(Nl,{columns:M.columns,mask:te.maskView,onClose:G,onNavigate:nt,refs:M.refs,row:Xt(H,te.maskView)}),ie!==null&&F!==null&&d(Do,{onClose:()=>{ce(null)},onConfirm:ot,readPage:Qe,rowId:ie,schema:vo(h),table:F}),ee!==null&&d(bo,{bucket:ye.get(ee.column),column:ee.column,onClose:W,resolveUrl:ye.has(ee.column)?U:void 0,value:ee.value}),mt&&F!==null&&d(Co,{columns:C.columns.filter(L=>C.editableColumn(L)),onApply:C.bulkPatch,onClose:Ue,shardKey:C.queryShardKey,table:F,total:C.total,uniqueColumns:_l(g.data?.indexesByTable[F])}),ze&&F!==null&&Ie!==void 0&&d(Bs,{columns:Ie,fkPools:We,onClose:Ae,onInsertRows:ft,table:F})]})};export{ur as DataBrowser};
@@ -1 +1 @@
1
- import{a as G}from"./chunk-EA2JKR5D.js";import{a as x}from"./chunk-IMOHEGMV.js";import{a as U}from"./chunk-2DX5MROH.js";import{b as M}from"./chunk-OGUKYRFM.js";import"./chunk-OKG3HWSJ.js";import{W as O}from"./chunk-PLHA3OWK.js";import"./chunk-4L4WTGN5.js";import{a as p}from"./chunk-55754F6H.js";import"./chunk-IS6LVJ6L.js";import"./chunk-AAVLPU5Q.js";import{b as w}from"./chunk-FEWMAPNI.js";import"./chunk-225VJ77I.js";import{a as E}from"./chunk-4ZEL6BYL.js";import{f as D}from"./chunk-IL4CKMJM.js";import"./chunk-FSRSK4LY.js";import"./chunk-MKL7VDTL.js";import{d as K,e as _,f as z,h as B,o as P,r as q}from"./chunk-FODLDLE2.js";import{a as s,d as J,e as ie,g as oe}from"./chunk-YKXDMIHQ.js";var i=J(ie(),1);var e=J(oe(),1);var de=s(r=>r.kind==="id"?r.table===void 0?"id":`id<${r.table}>`:r.kind==="array"?r.element===void 0?"array":`${r.element}[]`:r.kind,"oe"),le=s(r=>r===void 0||r.length===0?"()":`(${r.map(o=>`${o.name}${o.optional?"?":""}: ${de(o)}`).join(", ")})`,"ie"),ce=s(r=>{switch(r){case"array":return[];case"bigint":case"number":return 0;case"boolean":return!1;case"object":case"record":return{};default:return""}},"de"),ue=s(r=>{let o={};for(let a of r??[])a.optional||(o[a.name]=ce(a.kind));return JSON.stringify(o,void 0,2)},"le"),me=z(E.runAs),fe=10,he=s(r=>r===void 0?"undefined":JSON.stringify(r,null,2),"me"),Fe=s(({functions:r,runAsIdentity:o=!1}={})=>{let a=K(),u=D(),[H,Q]=(0,i.useState)(null),[k,V]=(0,i.useState)(null),g=r??H??[],[I,S]=(0,i.useState)(""),[m,b]=(0,i.useState)("{}"),[c,F]=(0,i.useState)(""),[f,W]=(0,i.useState)(""),[v,h]=(0,i.useState)("idle"),[X,y]=(0,i.useState)(void 0),[C,N]=(0,i.useState)(null),[$,Y]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(r!==void 0)return;let t=!1;return u.listFunctions().then(d=>(t||Q(d),d)).catch(d=>{t||V(B(d))}),()=>{t=!0}},[u,r]);let A=I===""?g[0]?.path??"":I,n=g.find(t=>t.path===A),Z=s(async()=>{if(!n)return;let t;try{t=m.trim()===""?{}:JSON.parse(m)}catch(l){h("error"),y(void 0),N(a("Invalid JSON args: {message}",{message:l.message}));return}let d={__lunoraRef:n.path},R=c.trim()===""?{}:{shardKey:c.trim()},j=o?f.trim():"",L=s(l=>{Y(T=>[{argsText:m,at:Date.now(),id:(T[0]?.id??0)+1,kind:n.kind,path:n.path,shardKey:c,status:l},...T].slice(0,fe))},"$");h("running"),N(null);try{let l=j===""?await _(u,n.kind,d,t,R):await u.query(me,{args:t,functionPath:n.path,userId:j},R);M(c),y(l),h("success"),L("success")}catch(l){y(void 0),N(l.message),h("error"),L("error")}},"J"),ee=s(t=>{S(t.path),b(t.argsText),F(t.shardKey)},"M"),te=s(t=>{S(t.target.value)},"P"),re=s(t=>{b(t.target.value)},"z"),ae=s(t=>{W(t.target.value)},"q"),se=s(()=>{P(Z())},"H"),ne=s(()=>{b(ue(n?.args))},"V");return(0,e.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-runner",children:[k!==null&&(0,e.jsx)("p",{className:"text-sm text-destructive","data-testid":"function-discover-error",role:"alert",children:k}),(0,e.jsxs)("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsx)(x,{htmlFor:"function-select",children:a("Function")}),(0,e.jsx)("select",{"aria-label":a("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:te,value:A,children:g.map(t=>(0,e.jsxs)("option",{value:t.path,children:[t.path," (",t.kind,")"]},t.path))}),n!==void 0&&(0,e.jsxs)("p",{className:"text-xs text-muted-foreground",children:[(0,e.jsx)("span",{className:"mr-1.5 font-medium",children:a("Signature")}),(0,e.jsx)("code",{className:"font-mono","data-testid":"function-signature",children:le(n.args)})]})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsx)(x,{htmlFor:"args-input",children:a("Arguments")}),(0,e.jsx)(p,{"data-testid":"prefill-button",disabled:n===void 0,onClick:ne,size:"xs",type:"button",variant:"ghost",children:a("Prefill")})]}),(0,e.jsx)(G,{"aria-label":a("Arguments"),className:"font-mono text-xs","data-testid":"args-input",id:"args-input",onChange:re,value:m})]}),(0,e.jsx)(U,{onChange:F,testId:"shard-input",value:c}),o&&(0,e.jsxs)("div",{className:"flex flex-col gap-1.5","data-testid":"run-as-field",children:[(0,e.jsx)(x,{htmlFor:"run-as-input",children:a("Run as identity (userId)")}),(0,e.jsx)(O,{"aria-label":a("Run as identity (userId)"),className:"font-mono text-xs","data-testid":"run-as-input",id:"run-as-input",onChange:ae,placeholder:a("Leave empty to run as admin"),value:f}),(0,e.jsx)("p",{className:"text-[11px] text-muted-foreground",children:a("Dev only: runs the function as this user so you can test auth and RLS. Forged over the admin gate.")})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)(p,{"data-testid":"run-button",disabled:v==="running"||n===void 0,onClick:se,type:"button",children:a("Run")}),n!==void 0&&(0,e.jsx)(w,{variant:"outline",children:n.kind}),o&&f.trim()!==""&&(0,e.jsx)(w,{"data-testid":"run-as-badge",variant:"secondary",children:a("as {userId}",{userId:f.trim()})})]})]}),v==="error"&&C!==null&&(0,e.jsx)("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}),v==="success"&&(0,e.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"result",children:he(X)}),$.length>0&&(0,e.jsx)("ul",{className:"flex flex-col overflow-hidden rounded-xl border border-border","data-testid":"fn-history",children:$.map((t,d)=>(0,e.jsxs)("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,e.jsx)("span",{className:t.status==="success"?"text-success":"text-destructive","data-testid":`fn-history-status-${d.toString()}`,children:t.status==="success"?"\u2713":"\u2717"})," ",(0,e.jsxs)("span",{className:"font-mono text-xs",children:[t.path," (",t.kind,")"]})," ",(0,e.jsx)("time",{className:"text-xs text-muted-foreground",children:q(t.at)})," ",(0,e.jsx)(p,{className:"ml-auto","data-testid":`fn-history-load-${d.toString()}`,onClick:s(()=>{ee(t)},"onClick"),size:"xs",type:"button",variant:"ghost",children:a("Load")})]},t.id))})]})},"Ae");export{Fe as FunctionRunner};
1
+ import{a as G}from"./chunk-EA2JKR5D.js";import{a as x}from"./chunk-IMOHEGMV.js";import{a as U}from"./chunk-2DX5MROH.js";import{b as M}from"./chunk-OGUKYRFM.js";import"./chunk-OKG3HWSJ.js";import{W as O}from"./chunk-PLHA3OWK.js";import"./chunk-4L4WTGN5.js";import{a as p}from"./chunk-55754F6H.js";import"./chunk-IS6LVJ6L.js";import"./chunk-AAVLPU5Q.js";import{b as w}from"./chunk-FEWMAPNI.js";import"./chunk-225VJ77I.js";import{a as E}from"./chunk-4ZEL6BYL.js";import{f as D}from"./chunk-B4YYP5AH.js";import"./chunk-FSRSK4LY.js";import"./chunk-MKL7VDTL.js";import{d as K,e as _,f as z,h as B,o as P,r as q}from"./chunk-FODLDLE2.js";import{a as s,d as J,e as ie,g as oe}from"./chunk-YKXDMIHQ.js";var i=J(ie(),1);var e=J(oe(),1);var de=s(r=>r.kind==="id"?r.table===void 0?"id":`id<${r.table}>`:r.kind==="array"?r.element===void 0?"array":`${r.element}[]`:r.kind,"oe"),le=s(r=>r===void 0||r.length===0?"()":`(${r.map(o=>`${o.name}${o.optional?"?":""}: ${de(o)}`).join(", ")})`,"ie"),ce=s(r=>{switch(r){case"array":return[];case"bigint":case"number":return 0;case"boolean":return!1;case"object":case"record":return{};default:return""}},"de"),ue=s(r=>{let o={};for(let a of r??[])a.optional||(o[a.name]=ce(a.kind));return JSON.stringify(o,void 0,2)},"le"),me=z(E.runAs),fe=10,he=s(r=>r===void 0?"undefined":JSON.stringify(r,null,2),"me"),Fe=s(({functions:r,runAsIdentity:o=!1}={})=>{let a=K(),u=D(),[H,Q]=(0,i.useState)(null),[k,V]=(0,i.useState)(null),g=r??H??[],[I,S]=(0,i.useState)(""),[m,b]=(0,i.useState)("{}"),[c,F]=(0,i.useState)(""),[f,W]=(0,i.useState)(""),[v,h]=(0,i.useState)("idle"),[X,y]=(0,i.useState)(void 0),[C,N]=(0,i.useState)(null),[$,Y]=(0,i.useState)([]);(0,i.useEffect)(()=>{if(r!==void 0)return;let t=!1;return u.listFunctions().then(d=>(t||Q(d),d)).catch(d=>{t||V(B(d))}),()=>{t=!0}},[u,r]);let A=I===""?g[0]?.path??"":I,n=g.find(t=>t.path===A),Z=s(async()=>{if(!n)return;let t;try{t=m.trim()===""?{}:JSON.parse(m)}catch(l){h("error"),y(void 0),N(a("Invalid JSON args: {message}",{message:l.message}));return}let d={__lunoraRef:n.path},R=c.trim()===""?{}:{shardKey:c.trim()},j=o?f.trim():"",L=s(l=>{Y(T=>[{argsText:m,at:Date.now(),id:(T[0]?.id??0)+1,kind:n.kind,path:n.path,shardKey:c,status:l},...T].slice(0,fe))},"$");h("running"),N(null);try{let l=j===""?await _(u,n.kind,d,t,R):await u.query(me,{args:t,functionPath:n.path,userId:j},R);M(c),y(l),h("success"),L("success")}catch(l){y(void 0),N(l.message),h("error"),L("error")}},"J"),ee=s(t=>{S(t.path),b(t.argsText),F(t.shardKey)},"M"),te=s(t=>{S(t.target.value)},"P"),re=s(t=>{b(t.target.value)},"z"),ae=s(t=>{W(t.target.value)},"q"),se=s(()=>{P(Z())},"H"),ne=s(()=>{b(ue(n?.args))},"V");return(0,e.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-runner",children:[k!==null&&(0,e.jsx)("p",{className:"text-sm text-destructive","data-testid":"function-discover-error",role:"alert",children:k}),(0,e.jsxs)("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsx)(x,{htmlFor:"function-select",children:a("Function")}),(0,e.jsx)("select",{"aria-label":a("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:te,value:A,children:g.map(t=>(0,e.jsxs)("option",{value:t.path,children:[t.path," (",t.kind,")"]},t.path))}),n!==void 0&&(0,e.jsxs)("p",{className:"text-xs text-muted-foreground",children:[(0,e.jsx)("span",{className:"mr-1.5 font-medium",children:a("Signature")}),(0,e.jsx)("code",{className:"font-mono","data-testid":"function-signature",children:le(n.args)})]})]}),(0,e.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsx)(x,{htmlFor:"args-input",children:a("Arguments")}),(0,e.jsx)(p,{"data-testid":"prefill-button",disabled:n===void 0,onClick:ne,size:"xs",type:"button",variant:"ghost",children:a("Prefill")})]}),(0,e.jsx)(G,{"aria-label":a("Arguments"),className:"font-mono text-xs","data-testid":"args-input",id:"args-input",onChange:re,value:m})]}),(0,e.jsx)(U,{onChange:F,testId:"shard-input",value:c}),o&&(0,e.jsxs)("div",{className:"flex flex-col gap-1.5","data-testid":"run-as-field",children:[(0,e.jsx)(x,{htmlFor:"run-as-input",children:a("Run as identity (userId)")}),(0,e.jsx)(O,{"aria-label":a("Run as identity (userId)"),className:"font-mono text-xs","data-testid":"run-as-input",id:"run-as-input",onChange:ae,placeholder:a("Leave empty to run as admin"),value:f}),(0,e.jsx)("p",{className:"text-[11px] text-muted-foreground",children:a("Dev only: runs the function as this user so you can test auth and RLS. Forged over the admin gate.")})]}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)(p,{"data-testid":"run-button",disabled:v==="running"||n===void 0,onClick:se,type:"button",children:a("Run")}),n!==void 0&&(0,e.jsx)(w,{variant:"outline",children:n.kind}),o&&f.trim()!==""&&(0,e.jsx)(w,{"data-testid":"run-as-badge",variant:"secondary",children:a("as {userId}",{userId:f.trim()})})]})]}),v==="error"&&C!==null&&(0,e.jsx)("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}),v==="success"&&(0,e.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"result",children:he(X)}),$.length>0&&(0,e.jsx)("ul",{className:"flex flex-col overflow-hidden rounded-xl border border-border","data-testid":"fn-history",children:$.map((t,d)=>(0,e.jsxs)("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,e.jsx)("span",{className:t.status==="success"?"text-success":"text-destructive","data-testid":`fn-history-status-${d.toString()}`,children:t.status==="success"?"\u2713":"\u2717"})," ",(0,e.jsxs)("span",{className:"font-mono text-xs",children:[t.path," (",t.kind,")"]})," ",(0,e.jsx)("time",{className:"text-xs text-muted-foreground",children:q(t.at)})," ",(0,e.jsx)(p,{className:"ml-auto","data-testid":`fn-history-load-${d.toString()}`,onClick:s(()=>{ee(t)},"onClick"),size:"xs",type:"button",variant:"ghost",children:a("Load")})]},t.id))})]})},"Ae");export{Fe as FunctionRunner};
@@ -1 +1 @@
1
- import{a as ee}from"./chunk-5WJXVZMZ.js";import{b as Z}from"./chunk-FEWMAPNI.js";import"./chunk-225VJ77I.js";import{d as se,f as X}from"./chunk-IL4CKMJM.js";import"./chunk-FSRSK4LY.js";import"./chunk-MKL7VDTL.js";import{a as re}from"./chunk-FKVZRPV5.js";import{a as O}from"./chunk-WUWBZPUK.js";import{d as le,r as ne}from"./chunk-FODLDLE2.js";import{a as k,d as ae,f as ce,g as me,i as Y}from"./chunk-YKXDMIHQ.js";var te=ae(ce(),1);var a=ae(me(),1);var pe="/_lunora/health",he="/_lunora/health/ready",ue=k((r,e)=>(r.endsWith("/")?r.slice(0,-1):r)+e,"me"),fe=k(()=>{let r=X();return async e=>{let w=e==="ready"?he:pe,t=r.getAuthToken(),y=ue(r.url,w);try{let i=await fetch(y,{headers:t===null?{}:{authorization:`Bearer ${t}`}}),p=null;try{p=await i.json()}catch{p=null}return{body:p,ok:i.ok,status:i.status}}catch(i){return{body:null,error:i instanceof Error?i.message:String(i),ok:!1,status:0}}}},"pe"),ge={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},ye=k(r=>r==="unhealthy"?"crit":r==="degraded"?"warn":"ok","fe"),ie=k(r=>{let e=(0,te.c)(13),{label:w,level:t,testId:y,value:i}=r,p=ge[t],d;e[0]!==p?(d=Y("size-1.5 shrink-0 rounded-full",p),e[0]=p,e[1]=d):d=e[1];let o;e[2]!==d?(o=(0,a.jsx)("span",{"aria-hidden":"true",className:d}),e[2]=d,e[3]=o):o=e[3];let c;e[4]!==w||e[5]!==o?(c=(0,a.jsxs)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[o,w]}),e[4]=w,e[5]=o,e[6]=c):c=e[6];let h;e[7]!==y||e[8]!==i?(h=(0,a.jsx)("span",{className:"text-lg font-semibold text-foreground","data-testid":y,children:i}),e[7]=y,e[8]=i,e[9]=h):h=e[9];let C;return e[10]!==c||e[11]!==h?(C=(0,a.jsx)(O,{className:"gap-0 py-0",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2.5 p-4",children:[c,h]})}),e[10]=c,e[11]=h,e[12]=C):C=e[12],C},"Z"),Pe=k(r=>{let e=(0,te.c)(107),{probe:w}=r,t=le(),y=X(),i=fe(),p=w??i,d;e[0]!==p?(d=k(async()=>{let[s,n]=await Promise.all([p("live"),p("ready")]);return{live:s,ready:n}},"o"),e[0]=p,e[1]=d):d=e[1];let o;e[2]!==y?(o=y.clientIdentifier(),e[2]=y,e[3]=o):o=e[3];let c;e[4]!==o?(c=["deployment-health",o],e[4]=o,e[5]=c):c=e[5];let h;e[6]!==d||e[7]!==c?(h={queryFn:d,queryKey:c},e[6]=d,e[7]=c,e[8]=h):h=e[8];let{data:C,isPending:de}=se(h),Q=C?.live??null,oe=C?.ready??null;if(de){let s;return e[9]===Symbol.for("react.memo_cache_sentinel")?(s=(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"deployment-health-loading",children:[(0,a.jsx)(ee,{className:"h-16 w-full"}),(0,a.jsx)(ee,{className:"h-40 w-full"})]}),e[9]=s):s=e[9],s}let l=Q?.body??null;if(l===null){let s=Q?.status===403,n;e[10]!==s||e[11]!==Q?.error||e[12]!==t?(n=s?t("The health endpoint is in the admin posture. Paste a valid admin token in the connect popover, or set its auth to public."):t("Couldn't reach the health endpoint: {message}",{message:Q?.error??t("no response")}),e[10]=s,e[11]=Q?.error,e[12]=t,e[13]=n):n=e[13];let m;e[14]!==t?(m=t("Health endpoint unavailable"),e[14]=t,e[15]=m):m=e[15];let f;return e[16]!==n||e[17]!==m?(f=(0,a.jsx)(re,{description:n,testId:"deployment-health-error",title:m}),e[16]=n,e[17]=m,e[18]=f):f=e[18],f}let J;e[19]!==l.status?(J=ye(l.status),e[19]=l.status,e[20]=J):J=e[20];let W=J,u;if(l.status==="unhealthy"){let s;e[21]!==t?(s=t("Unhealthy"),e[21]=t,e[22]=s):s=e[22],u=s}else if(l.status==="degraded"){let s;e[23]!==t?(s=t("Degraded"),e[23]=t,e[24]=s):s=e[24],u=s}else{let s;e[25]!==t?(s=t("Healthy"),e[25]=t,e[26]=s):s=e[26],u=s}let j=oe?.ok??!1,G=j?"ok":"crit",H,I,P,x,N,v,S,V,b,_;if(e[27]!==l.appName||e[28]!==l.appVersion||e[29]!==l.checks||e[30]!==l.timestamp||e[31]!==W||e[32]!==G||e[33]!==j||e[34]!==u||e[35]!==t){let s=[...l.checks].toSorted(xe);I="flex flex-col gap-6",P="deployment-health";let n;e[46]!==t?(n=t("Live liveness, readiness, and per-binding health from the deployment's /_lunora/health endpoint \u2014 wire an uptime monitor or a Cloudflare Health Check at it."),e[46]=t,e[47]=n):n=e[47],e[48]!==n?(x=(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:n}),e[48]=n,e[49]=x):x=e[49];let m;e[50]!==u?(m=(0,a.jsx)("span",{className:"text-sm font-semibold text-foreground","data-testid":"dh-status",children:u}),e[50]=u,e[51]=m):m=e[51];let f;e[52]!==l.appName||e[53]!==l.appVersion?(f=(0,a.jsxs)("span",{className:"font-mono text-[13px] text-muted-foreground","data-testid":"dh-app",children:[l.appName," \xB7 ",l.appVersion]}),e[52]=l.appName,e[53]=l.appVersion,e[54]=f):f=e[54];let D;e[55]!==m||e[56]!==f?(D=(0,a.jsx)("div",{className:"flex items-center gap-3",children:(0,a.jsxs)("div",{className:"grid leading-tight",children:[m,f]})}),e[55]=m,e[56]=f,e[57]=D):D=e[57];let L;e[58]!==t?(L=t("Checked"),e[58]=t,e[59]=L):L=e[59];let T;e[60]!==L?(T=(0,a.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:L}),e[60]=L,e[61]=T):T=e[61];let $;e[62]!==l.timestamp?($=ne(l.timestamp),e[62]=l.timestamp,e[63]=$):$=e[63];let q;e[64]!==$?(q=(0,a.jsx)("time",{className:"text-[13px] text-muted-foreground","data-testid":"dh-timestamp",children:$}),e[64]=$,e[65]=q):q=e[65];let B;e[66]!==T||e[67]!==q?(B=(0,a.jsxs)("div",{className:"text-end",children:[T,q]}),e[66]=T,e[67]=q,e[68]=B):B=e[68],e[69]!==D||e[70]!==B?(N=(0,a.jsx)(O,{className:"gap-0 py-0",children:(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[D,B]})}),e[69]=D,e[70]=B,e[71]=N):N=e[71];let E;e[72]!==t?(E=t("Liveness"),e[72]=t,e[73]=E):E=e[73];let R;e[74]!==W||e[75]!==u||e[76]!==E?(R=(0,a.jsx)(ie,{label:E,level:W,testId:"dh-liveness",value:u}),e[74]=W,e[75]=u,e[76]=E,e[77]=R):R=e[77];let U;e[78]!==t?(U=t("Readiness"),e[78]=t,e[79]=U):U=e[79];let A;e[80]!==j||e[81]!==t?(A=t(j?"Ready":"Not ready"),e[80]=j,e[81]=t,e[82]=A):A=e[82];let F;e[83]!==G||e[84]!==U||e[85]!==A?(F=(0,a.jsx)(ie,{label:U,level:G,testId:"dh-readiness",value:A}),e[83]=G,e[84]=U,e[85]=A,e[86]=F):F=e[86],e[87]!==R||e[88]!==F?(v=(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2","data-testid":"dh-probes",children:[R,F]}),e[87]=R,e[88]=F,e[89]=v):v=e[89],H=O,S="gap-0 py-0",V="dh-checks";let K;e[90]!==t?(K=t("Subsystem checks"),e[90]=t,e[91]=K):K=e[91],e[92]!==K?(b=(0,a.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,a.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:K})}),e[92]=K,e[93]=b):b=e[93],_=s.length===0?(0,a.jsx)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"dh-checks-empty",children:t("No checks reported.")}):(0,a.jsx)("ul",{className:"divide-y divide-border",children:s.map(g=>(0,a.jsxs)("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2.5 text-xs","data-testid":`dh-check-${g.name}`,children:[(0,a.jsxs)("span",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:Y("size-1.5 shrink-0 rounded-full",g.status==="up"?"bg-success":"bg-destructive")}),(0,a.jsx)("span",{className:"font-mono text-foreground",children:g.name}),g.critical&&(0,a.jsx)(Z,{variant:"outline",children:t("Critical")})]}),(0,a.jsxs)("span",{className:"flex shrink-0 items-center gap-2",children:[g.message!==void 0&&(0,a.jsx)("span",{className:"text-muted-foreground",children:g.message}),(0,a.jsx)(Z,{"data-testid":`dh-check-status-${g.name}`,variant:g.status==="up"?"secondary":"destructive",children:g.status==="up"?t("Up"):t("Down")})]})]},g.name))}),e[27]=l.appName,e[28]=l.appVersion,e[29]=l.checks,e[30]=l.timestamp,e[31]=W,e[32]=G,e[33]=j,e[34]=u,e[35]=t,e[36]=H,e[37]=I,e[38]=P,e[39]=x,e[40]=N,e[41]=v,e[42]=S,e[43]=V,e[44]=b,e[45]=_}else H=e[36],I=e[37],P=e[38],x=e[39],N=e[40],v=e[41],S=e[42],V=e[43],b=e[44],_=e[45];let z;e[94]!==H||e[95]!==S||e[96]!==V||e[97]!==b||e[98]!==_?(z=(0,a.jsxs)(H,{className:S,"data-testid":V,children:[b,_]}),e[94]=H,e[95]=S,e[96]=V,e[97]=b,e[98]=_,e[99]=z):z=e[99];let M;return e[100]!==I||e[101]!==P||e[102]!==x||e[103]!==N||e[104]!==v||e[105]!==z?(M=(0,a.jsxs)("div",{className:I,"data-testid":P,children:[x,N,v,z]}),e[100]=I,e[101]=P,e[102]=x,e[103]=N,e[104]=v,e[105]=z,e[106]=M):M=e[106],M},"Pe");function xe(r,e){return r.name.localeCompare(e.name)}k(xe,"he");export{Pe as DeploymentHealthPanel};
1
+ import{a as ee}from"./chunk-5WJXVZMZ.js";import{b as Z}from"./chunk-FEWMAPNI.js";import"./chunk-225VJ77I.js";import{d as se,f as X}from"./chunk-B4YYP5AH.js";import"./chunk-FSRSK4LY.js";import"./chunk-MKL7VDTL.js";import{a as re}from"./chunk-FKVZRPV5.js";import{a as O}from"./chunk-WUWBZPUK.js";import{d as le,r as ne}from"./chunk-FODLDLE2.js";import{a as k,d as ae,f as ce,g as me,i as Y}from"./chunk-YKXDMIHQ.js";var te=ae(ce(),1);var a=ae(me(),1);var pe="/_lunora/health",he="/_lunora/health/ready",ue=k((r,e)=>(r.endsWith("/")?r.slice(0,-1):r)+e,"me"),fe=k(()=>{let r=X();return async e=>{let w=e==="ready"?he:pe,t=r.getAuthToken(),y=ue(r.url,w);try{let i=await fetch(y,{headers:t===null?{}:{authorization:`Bearer ${t}`}}),p=null;try{p=await i.json()}catch{p=null}return{body:p,ok:i.ok,status:i.status}}catch(i){return{body:null,error:i instanceof Error?i.message:String(i),ok:!1,status:0}}}},"pe"),ge={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},ye=k(r=>r==="unhealthy"?"crit":r==="degraded"?"warn":"ok","fe"),ie=k(r=>{let e=(0,te.c)(13),{label:w,level:t,testId:y,value:i}=r,p=ge[t],d;e[0]!==p?(d=Y("size-1.5 shrink-0 rounded-full",p),e[0]=p,e[1]=d):d=e[1];let o;e[2]!==d?(o=(0,a.jsx)("span",{"aria-hidden":"true",className:d}),e[2]=d,e[3]=o):o=e[3];let c;e[4]!==w||e[5]!==o?(c=(0,a.jsxs)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[o,w]}),e[4]=w,e[5]=o,e[6]=c):c=e[6];let h;e[7]!==y||e[8]!==i?(h=(0,a.jsx)("span",{className:"text-lg font-semibold text-foreground","data-testid":y,children:i}),e[7]=y,e[8]=i,e[9]=h):h=e[9];let C;return e[10]!==c||e[11]!==h?(C=(0,a.jsx)(O,{className:"gap-0 py-0",children:(0,a.jsxs)("div",{className:"flex flex-col gap-2.5 p-4",children:[c,h]})}),e[10]=c,e[11]=h,e[12]=C):C=e[12],C},"Z"),Pe=k(r=>{let e=(0,te.c)(107),{probe:w}=r,t=le(),y=X(),i=fe(),p=w??i,d;e[0]!==p?(d=k(async()=>{let[s,n]=await Promise.all([p("live"),p("ready")]);return{live:s,ready:n}},"o"),e[0]=p,e[1]=d):d=e[1];let o;e[2]!==y?(o=y.clientIdentifier(),e[2]=y,e[3]=o):o=e[3];let c;e[4]!==o?(c=["deployment-health",o],e[4]=o,e[5]=c):c=e[5];let h;e[6]!==d||e[7]!==c?(h={queryFn:d,queryKey:c},e[6]=d,e[7]=c,e[8]=h):h=e[8];let{data:C,isPending:de}=se(h),Q=C?.live??null,oe=C?.ready??null;if(de){let s;return e[9]===Symbol.for("react.memo_cache_sentinel")?(s=(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"deployment-health-loading",children:[(0,a.jsx)(ee,{className:"h-16 w-full"}),(0,a.jsx)(ee,{className:"h-40 w-full"})]}),e[9]=s):s=e[9],s}let l=Q?.body??null;if(l===null){let s=Q?.status===403,n;e[10]!==s||e[11]!==Q?.error||e[12]!==t?(n=s?t("The health endpoint is in the admin posture. Paste a valid admin token in the connect popover, or set its auth to public."):t("Couldn't reach the health endpoint: {message}",{message:Q?.error??t("no response")}),e[10]=s,e[11]=Q?.error,e[12]=t,e[13]=n):n=e[13];let m;e[14]!==t?(m=t("Health endpoint unavailable"),e[14]=t,e[15]=m):m=e[15];let f;return e[16]!==n||e[17]!==m?(f=(0,a.jsx)(re,{description:n,testId:"deployment-health-error",title:m}),e[16]=n,e[17]=m,e[18]=f):f=e[18],f}let J;e[19]!==l.status?(J=ye(l.status),e[19]=l.status,e[20]=J):J=e[20];let W=J,u;if(l.status==="unhealthy"){let s;e[21]!==t?(s=t("Unhealthy"),e[21]=t,e[22]=s):s=e[22],u=s}else if(l.status==="degraded"){let s;e[23]!==t?(s=t("Degraded"),e[23]=t,e[24]=s):s=e[24],u=s}else{let s;e[25]!==t?(s=t("Healthy"),e[25]=t,e[26]=s):s=e[26],u=s}let j=oe?.ok??!1,G=j?"ok":"crit",H,I,P,x,N,v,S,V,b,_;if(e[27]!==l.appName||e[28]!==l.appVersion||e[29]!==l.checks||e[30]!==l.timestamp||e[31]!==W||e[32]!==G||e[33]!==j||e[34]!==u||e[35]!==t){let s=[...l.checks].toSorted(xe);I="flex flex-col gap-6",P="deployment-health";let n;e[46]!==t?(n=t("Live liveness, readiness, and per-binding health from the deployment's /_lunora/health endpoint \u2014 wire an uptime monitor or a Cloudflare Health Check at it."),e[46]=t,e[47]=n):n=e[47],e[48]!==n?(x=(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:n}),e[48]=n,e[49]=x):x=e[49];let m;e[50]!==u?(m=(0,a.jsx)("span",{className:"text-sm font-semibold text-foreground","data-testid":"dh-status",children:u}),e[50]=u,e[51]=m):m=e[51];let f;e[52]!==l.appName||e[53]!==l.appVersion?(f=(0,a.jsxs)("span",{className:"font-mono text-[13px] text-muted-foreground","data-testid":"dh-app",children:[l.appName," \xB7 ",l.appVersion]}),e[52]=l.appName,e[53]=l.appVersion,e[54]=f):f=e[54];let D;e[55]!==m||e[56]!==f?(D=(0,a.jsx)("div",{className:"flex items-center gap-3",children:(0,a.jsxs)("div",{className:"grid leading-tight",children:[m,f]})}),e[55]=m,e[56]=f,e[57]=D):D=e[57];let L;e[58]!==t?(L=t("Checked"),e[58]=t,e[59]=L):L=e[59];let T;e[60]!==L?(T=(0,a.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:L}),e[60]=L,e[61]=T):T=e[61];let $;e[62]!==l.timestamp?($=ne(l.timestamp),e[62]=l.timestamp,e[63]=$):$=e[63];let q;e[64]!==$?(q=(0,a.jsx)("time",{className:"text-[13px] text-muted-foreground","data-testid":"dh-timestamp",children:$}),e[64]=$,e[65]=q):q=e[65];let B;e[66]!==T||e[67]!==q?(B=(0,a.jsxs)("div",{className:"text-end",children:[T,q]}),e[66]=T,e[67]=q,e[68]=B):B=e[68],e[69]!==D||e[70]!==B?(N=(0,a.jsx)(O,{className:"gap-0 py-0",children:(0,a.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[D,B]})}),e[69]=D,e[70]=B,e[71]=N):N=e[71];let E;e[72]!==t?(E=t("Liveness"),e[72]=t,e[73]=E):E=e[73];let R;e[74]!==W||e[75]!==u||e[76]!==E?(R=(0,a.jsx)(ie,{label:E,level:W,testId:"dh-liveness",value:u}),e[74]=W,e[75]=u,e[76]=E,e[77]=R):R=e[77];let U;e[78]!==t?(U=t("Readiness"),e[78]=t,e[79]=U):U=e[79];let A;e[80]!==j||e[81]!==t?(A=t(j?"Ready":"Not ready"),e[80]=j,e[81]=t,e[82]=A):A=e[82];let F;e[83]!==G||e[84]!==U||e[85]!==A?(F=(0,a.jsx)(ie,{label:U,level:G,testId:"dh-readiness",value:A}),e[83]=G,e[84]=U,e[85]=A,e[86]=F):F=e[86],e[87]!==R||e[88]!==F?(v=(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2","data-testid":"dh-probes",children:[R,F]}),e[87]=R,e[88]=F,e[89]=v):v=e[89],H=O,S="gap-0 py-0",V="dh-checks";let K;e[90]!==t?(K=t("Subsystem checks"),e[90]=t,e[91]=K):K=e[91],e[92]!==K?(b=(0,a.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,a.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:K})}),e[92]=K,e[93]=b):b=e[93],_=s.length===0?(0,a.jsx)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"dh-checks-empty",children:t("No checks reported.")}):(0,a.jsx)("ul",{className:"divide-y divide-border",children:s.map(g=>(0,a.jsxs)("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2.5 text-xs","data-testid":`dh-check-${g.name}`,children:[(0,a.jsxs)("span",{className:"flex items-center gap-2",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:Y("size-1.5 shrink-0 rounded-full",g.status==="up"?"bg-success":"bg-destructive")}),(0,a.jsx)("span",{className:"font-mono text-foreground",children:g.name}),g.critical&&(0,a.jsx)(Z,{variant:"outline",children:t("Critical")})]}),(0,a.jsxs)("span",{className:"flex shrink-0 items-center gap-2",children:[g.message!==void 0&&(0,a.jsx)("span",{className:"text-muted-foreground",children:g.message}),(0,a.jsx)(Z,{"data-testid":`dh-check-status-${g.name}`,variant:g.status==="up"?"secondary":"destructive",children:g.status==="up"?t("Up"):t("Down")})]})]},g.name))}),e[27]=l.appName,e[28]=l.appVersion,e[29]=l.checks,e[30]=l.timestamp,e[31]=W,e[32]=G,e[33]=j,e[34]=u,e[35]=t,e[36]=H,e[37]=I,e[38]=P,e[39]=x,e[40]=N,e[41]=v,e[42]=S,e[43]=V,e[44]=b,e[45]=_}else H=e[36],I=e[37],P=e[38],x=e[39],N=e[40],v=e[41],S=e[42],V=e[43],b=e[44],_=e[45];let z;e[94]!==H||e[95]!==S||e[96]!==V||e[97]!==b||e[98]!==_?(z=(0,a.jsxs)(H,{className:S,"data-testid":V,children:[b,_]}),e[94]=H,e[95]=S,e[96]=V,e[97]=b,e[98]=_,e[99]=z):z=e[99];let M;return e[100]!==I||e[101]!==P||e[102]!==x||e[103]!==N||e[104]!==v||e[105]!==z?(M=(0,a.jsxs)("div",{className:I,"data-testid":P,children:[x,N,v,z]}),e[100]=I,e[101]=P,e[102]=x,e[103]=N,e[104]=v,e[105]=z,e[106]=M):M=e[106],M},"Pe");function xe(r,e){return r.name.localeCompare(e.name)}k(xe,"he");export{Pe as DeploymentHealthPanel};