@lunora/studio 1.0.0-alpha.392 → 1.0.0-alpha.394

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 (159) hide show
  1. package/dist/packem_chunks/SchemaViewer.mjs +1 -1
  2. package/dist/packem_chunks/architecture-panel.mjs +1 -1
  3. package/dist/packem_chunks/migrations-route.mjs +1 -1
  4. package/dist/packem_shared/diagram-export-panel-CleSOm6J.mjs +2 -0
  5. package/dist/packem_shared/{schema-diagram-Dbs7-jSJ.mjs → schema-diagram-BpIBRUm6.mjs} +1 -1
  6. package/dist/standalone/{chunk-7UPL6MQR.js → chunk-26RNXTU3.js} +1 -1
  7. package/dist/standalone/{chunk-KULAZ4W3.js → chunk-2Q4WVEPB.js} +1 -1
  8. package/dist/standalone/{chunk-7WGZSDRS.js → chunk-2ZNMZPPZ.js} +1 -1
  9. package/dist/standalone/{chunk-AZ6QNL6G.js → chunk-3BDGZAZD.js} +1 -1
  10. package/dist/standalone/{chunk-XHDCFSC6.js → chunk-3GBBYV7C.js} +1 -1
  11. package/dist/standalone/{chunk-PUTERXSU.js → chunk-4OWWWAMB.js} +1 -1
  12. package/dist/standalone/{chunk-MVWMRJD5.js → chunk-4WFEKKAZ.js} +1 -1
  13. package/dist/standalone/{chunk-AJFMXVR4.js → chunk-4Z2GLDF7.js} +1 -1
  14. package/dist/standalone/{chunk-5FFKYQHT.js → chunk-5BTQ4VV2.js} +1 -1
  15. package/dist/standalone/{chunk-ACCTEC6Y.js → chunk-5FHGTA7V.js} +1 -1
  16. package/dist/standalone/chunk-5J2UX2CO.js +1 -0
  17. package/dist/standalone/{chunk-ZIY53FID.js → chunk-5XQM44J7.js} +1 -1
  18. package/dist/standalone/{chunk-JPL3WAVW.js → chunk-5YEMXXQZ.js} +1 -1
  19. package/dist/standalone/chunk-6KIDLGYM.js +1 -0
  20. package/dist/standalone/{chunk-XKK5ABPC.js → chunk-7URG6FZD.js} +1 -1
  21. package/dist/standalone/{chunk-2XAJCKRP.js → chunk-7XZENNML.js} +1 -1
  22. package/dist/standalone/{chunk-BFEX6HDU.js → chunk-A33FOU2H.js} +1 -1
  23. package/dist/standalone/{chunk-S64V5MAT.js → chunk-A7L3PZEL.js} +1 -1
  24. package/dist/standalone/{chunk-22C2K5PS.js → chunk-ADOZBBJC.js} +1 -1
  25. package/dist/standalone/{chunk-COMBKDVY.js → chunk-AFUJCRWR.js} +1 -1
  26. package/dist/standalone/{chunk-EFEAOMEB.js → chunk-AWMHWVF7.js} +1 -1
  27. package/dist/standalone/chunk-B5YCFPYG.js +1 -0
  28. package/dist/standalone/{chunk-6YDEXJRE.js → chunk-BADHCM45.js} +1 -1
  29. package/dist/standalone/{chunk-PRVBT5AJ.js → chunk-BCT3KY76.js} +1 -1
  30. package/dist/standalone/{chunk-6WTQL4W2.js → chunk-BFV46XUH.js} +1 -1
  31. package/dist/standalone/chunk-BMGMBZAW.js +1 -0
  32. package/dist/standalone/{chunk-BKKE4QKE.js → chunk-BTHVLHPT.js} +1 -1
  33. package/dist/standalone/{chunk-RTD3B67U.js → chunk-BUYKTV27.js} +1 -1
  34. package/dist/standalone/{chunk-W7CLOQOU.js → chunk-BZP4FOID.js} +1 -1
  35. package/dist/standalone/{chunk-EXHVWM27.js → chunk-C4PC3TVC.js} +1 -1
  36. package/dist/standalone/chunk-C57KLL4U.js +1 -0
  37. package/dist/standalone/{chunk-MPGM6L64.js → chunk-CBFVQCWS.js} +1 -1
  38. package/dist/standalone/{chunk-B34JDEEO.js → chunk-D4CP2AUO.js} +1 -1
  39. package/dist/standalone/chunk-DMQVY5L7.js +1 -0
  40. package/dist/standalone/{chunk-XYWMQVZ2.js → chunk-DRSX6KR3.js} +1 -1
  41. package/dist/standalone/{chunk-RUCMNPTD.js → chunk-DUICFFES.js} +1 -1
  42. package/dist/standalone/{chunk-E3IVOZVW.js → chunk-E32WBVTB.js} +1 -1
  43. package/dist/standalone/{chunk-QIROOZNJ.js → chunk-EBGXOUAO.js} +1 -1
  44. package/dist/standalone/{chunk-QHI77TGI.js → chunk-ECXQQPVU.js} +1 -1
  45. package/dist/standalone/{chunk-725JLR43.js → chunk-EEDAK4NS.js} +1 -1
  46. package/dist/standalone/{chunk-6HZDJA4T.js → chunk-EH53XOVI.js} +1 -1
  47. package/dist/standalone/chunk-EOHXBC4U.js +1 -0
  48. package/dist/standalone/chunk-EOTHFTZG.js +1 -0
  49. package/dist/standalone/{chunk-QHVUXMRV.js → chunk-EUNTXABP.js} +1 -1
  50. package/dist/standalone/{chunk-TFH347JK.js → chunk-EYFAYJYD.js} +1 -1
  51. package/dist/standalone/{chunk-N7FOBAV3.js → chunk-F4NZZ3LK.js} +1 -1
  52. package/dist/standalone/chunk-FRKRT73U.js +1 -0
  53. package/dist/standalone/chunk-FSY7UKMG.js +1 -0
  54. package/dist/standalone/chunk-G4H5DPO6.js +33 -0
  55. package/dist/standalone/chunk-GATWEWRW.js +1 -0
  56. package/dist/standalone/{chunk-INDH6PRB.js → chunk-HCLUIJMW.js} +1 -1
  57. package/dist/standalone/{chunk-H2HGJURT.js → chunk-HE2XT2P7.js} +1 -1
  58. package/dist/standalone/{chunk-IFU5WQHZ.js → chunk-HLN47VMG.js} +1 -1
  59. package/dist/standalone/{chunk-3RCYH6UA.js → chunk-HPCOC223.js} +1 -1
  60. package/dist/standalone/chunk-HPQLTLIE.js +1 -0
  61. package/dist/standalone/chunk-HQJXQWJM.js +1 -0
  62. package/dist/standalone/{chunk-2CMHGYZ4.js → chunk-IC2PEYF7.js} +1 -1
  63. package/dist/standalone/chunk-J2SIGUHW.js +8 -0
  64. package/dist/standalone/chunk-JCJCUWVN.js +1 -0
  65. package/dist/standalone/chunk-JEJV6SVN.js +1 -0
  66. package/dist/standalone/chunk-JSVT5VBU.js +1 -0
  67. package/dist/standalone/chunk-JXW6H6LE.js +1 -0
  68. package/dist/standalone/{chunk-TJ76NZTD.js → chunk-K3HWPNON.js} +1 -1
  69. package/dist/standalone/{chunk-EYBS3Q7O.js → chunk-KEHWNM7Q.js} +1 -1
  70. package/dist/standalone/chunk-KJHVB5KM.js +1 -0
  71. package/dist/standalone/{chunk-NRWR25MB.js → chunk-KQ6YQP3Z.js} +1 -1
  72. package/dist/standalone/{chunk-NP6H72XD.js → chunk-LUHBGCMO.js} +1 -1
  73. package/dist/standalone/{chunk-UEONVTOV.js → chunk-M6WDFEUZ.js} +1 -1
  74. package/dist/standalone/{chunk-JKTAHFTK.js → chunk-MEYZIZGX.js} +1 -1
  75. package/dist/standalone/{chunk-RN32N6ZO.js → chunk-MLX6ME3Q.js} +1 -1
  76. package/dist/standalone/{chunk-QMZKJK53.js → chunk-N3MKRANL.js} +1 -1
  77. package/dist/standalone/{chunk-H6VTIXVB.js → chunk-N7TSSCGF.js} +1 -1
  78. package/dist/standalone/{chunk-RIHWRGFS.js → chunk-NFIFRB3W.js} +2 -2
  79. package/dist/standalone/{chunk-EZ5PVGPY.js → chunk-OEPNNICC.js} +1 -1
  80. package/dist/standalone/chunk-PLCYDHU3.js +7 -0
  81. package/dist/standalone/{chunk-7ELEYWJC.js → chunk-PT4GNZU7.js} +1 -1
  82. package/dist/standalone/chunk-PVQDT47U.js +1 -0
  83. package/dist/standalone/{chunk-7Z243YUE.js → chunk-PWHUPKZB.js} +1 -1
  84. package/dist/standalone/{chunk-YYJGL32M.js → chunk-QJ3M3IQW.js} +1 -1
  85. package/dist/standalone/{chunk-5D73GSOC.js → chunk-QRXJTY2S.js} +1 -1
  86. package/dist/standalone/chunk-R76ATTPC.js +1 -0
  87. package/dist/standalone/{chunk-DW5KLXPI.js → chunk-RIRXDYLA.js} +1 -1
  88. package/dist/standalone/{chunk-TJV64AXT.js → chunk-RRIRWVQY.js} +1 -1
  89. package/dist/standalone/{chunk-34USSEJN.js → chunk-S3HFNWDK.js} +1 -1
  90. package/dist/standalone/{chunk-PLDE5R5Y.js → chunk-S3WL3QZ2.js} +1 -1
  91. package/dist/standalone/{chunk-LMCBMC2V.js → chunk-SOESES7K.js} +1 -1
  92. package/dist/standalone/chunk-SQO3WGXH.js +3 -0
  93. package/dist/standalone/chunk-T6YZEXZO.js +1 -0
  94. package/dist/standalone/{chunk-HYAGF6A5.js → chunk-TAZRDWQE.js} +1 -1
  95. package/dist/standalone/{chunk-LEF32Q5K.js → chunk-TDF4VVIF.js} +1 -1
  96. package/dist/standalone/{chunk-TVJFKXX4.js → chunk-TIFTYP3Z.js} +1 -1
  97. package/dist/standalone/{chunk-TVDBLCXQ.js → chunk-TNQHMR76.js} +1 -1
  98. package/dist/standalone/{chunk-ANHHDGNL.js → chunk-U4ZQVQZA.js} +1 -1
  99. package/dist/standalone/{chunk-OOPMRFI2.js → chunk-UB6S6VYI.js} +1 -1
  100. package/dist/standalone/chunk-UG6ZNYWH.js +167 -0
  101. package/dist/standalone/{chunk-MA2KXG2L.js → chunk-UHFZV34O.js} +1 -1
  102. package/dist/standalone/{chunk-O46IV64X.js → chunk-V5ZKAZR6.js} +1 -1
  103. package/dist/standalone/chunk-VEG327ST.js +63 -0
  104. package/dist/standalone/{chunk-UDKKUJHY.js → chunk-VLQU4G6O.js} +1 -1
  105. package/dist/standalone/{chunk-4YZAJTU5.js → chunk-VND72OIC.js} +1 -1
  106. package/dist/standalone/{chunk-NPHGFVNE.js → chunk-VUMS4VIV.js} +1 -1
  107. package/dist/standalone/{chunk-N4P6WYRV.js → chunk-VUWHTKLJ.js} +1 -1
  108. package/dist/standalone/{chunk-ZHDO7DYM.js → chunk-WARWYT4K.js} +1 -1
  109. package/dist/standalone/{chunk-KMBE7RTC.js → chunk-WVAWKCNQ.js} +1 -1
  110. package/dist/standalone/{chunk-ZPQBVYNN.js → chunk-WY23EROJ.js} +1 -1
  111. package/dist/standalone/{chunk-D7UOJY4N.js → chunk-XWLURY4U.js} +1 -1
  112. package/dist/standalone/{chunk-3HVF5LKQ.js → chunk-Y4KOJPOW.js} +1 -1
  113. package/dist/standalone/chunk-YC3TUO5H.js +1 -0
  114. package/dist/standalone/{chunk-HWG2R642.js → chunk-YQEIOEEC.js} +1 -1
  115. package/dist/standalone/{chunk-O56AZXG6.js → chunk-YQI2YAD7.js} +1 -1
  116. package/dist/standalone/{chunk-FNBNPTCM.js → chunk-YREHZBTG.js} +1 -1
  117. package/dist/standalone/chunk-YWGOETFP.js +1 -0
  118. package/dist/standalone/{chunk-K2I3AGZR.js → chunk-ZARTCW6W.js} +1 -1
  119. package/dist/standalone/chunk-ZBMHFOK2.js +1 -0
  120. package/dist/standalone/{chunk-PYG3TDLZ.js → chunk-ZG6VEBVA.js} +1 -1
  121. package/dist/standalone/{chunk-EMNOVYZC.js → chunk-ZSXJJYWN.js} +1 -1
  122. package/dist/standalone/chunk-ZUFBUWT4.js +1 -0
  123. package/dist/standalone/studio.js +1 -1
  124. package/dist/styles.css +2 -2
  125. package/package.json +15 -15
  126. package/dist/packem_shared/diagram-export-panel-miFPsocM.mjs +0 -2
  127. package/dist/standalone/chunk-3YBXNEUY.js +0 -1
  128. package/dist/standalone/chunk-4SY2N2RS.js +0 -1
  129. package/dist/standalone/chunk-6IDVWVML.js +0 -1
  130. package/dist/standalone/chunk-7ML357XR.js +0 -1
  131. package/dist/standalone/chunk-ATYVKUH7.js +0 -1
  132. package/dist/standalone/chunk-CDIV23I2.js +0 -33
  133. package/dist/standalone/chunk-D63EYK5I.js +0 -8
  134. package/dist/standalone/chunk-DYPC464U.js +0 -1
  135. package/dist/standalone/chunk-FT5WEK3S.js +0 -59
  136. package/dist/standalone/chunk-GVPVWT3Q.js +0 -1
  137. package/dist/standalone/chunk-I37WFNA6.js +0 -1
  138. package/dist/standalone/chunk-IQ5CIBXJ.js +0 -1
  139. package/dist/standalone/chunk-KBPMT33Z.js +0 -1
  140. package/dist/standalone/chunk-L27FKJTG.js +0 -1
  141. package/dist/standalone/chunk-LFWS6VBU.js +0 -1
  142. package/dist/standalone/chunk-MHZNDDGI.js +0 -1
  143. package/dist/standalone/chunk-O5QATFN3.js +0 -159
  144. package/dist/standalone/chunk-OZID3UYF.js +0 -1
  145. package/dist/standalone/chunk-PDBW6GTJ.js +0 -1
  146. package/dist/standalone/chunk-QF743FSL.js +0 -1
  147. package/dist/standalone/chunk-R3RIZDUS.js +0 -1
  148. package/dist/standalone/chunk-RZJAZ5ED.js +0 -1
  149. package/dist/standalone/chunk-SCTYLLJT.js +0 -1
  150. package/dist/standalone/chunk-UNUSBFIC.js +0 -1
  151. package/dist/standalone/chunk-UW34S35F.js +0 -1
  152. package/dist/standalone/chunk-Y6OVSHPH.js +0 -1
  153. package/dist/standalone/chunk-YESGXFAR.js +0 -7
  154. package/dist/standalone/chunk-YNCZVYCO.js +0 -1
  155. package/dist/standalone/chunk-Z6PYAG36.js +0 -3
  156. package/dist/standalone/chunk-Z7ZRXPPE.js +0 -1
  157. /package/dist/standalone/{chunk-OWRWDDJT.js → chunk-HXFXD5EP.js} +0 -0
  158. /package/dist/standalone/{chunk-UQ3WOVL2.js → chunk-HXWW3XML.js} +0 -0
  159. /package/dist/standalone/{chunk-T7UKRA6J.js → chunk-QBBNGQJA.js} +0 -0
@@ -1 +1 @@
1
- import{c as we}from"react/compiler-runtime";import{ShardInput as Ze}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{S as Ke,T as Pe}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{B as Fe}from"../packem_shared/badge-r_5B4LHP.mjs";import{c as Ge,d as ze,b as Be,a as De,C as je}from"../packem_shared/card-By2O8ULa.mjs";import{E as et}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as ke}from"../packem_shared/input-CXhxesPC.mjs";import{useT as Oe}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{d as Le,g as Ae,b as $e,f as Ce}from"../packem_shared/internal-BT5tH08j.mjs";import{c as Qe}from"../packem_shared/utils-bhneXptQ.mjs";import{useState as _,useRef as Ue,useEffect as qe}from"react";import{u as tt}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{u as lt}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{ADMIN_FUNCTIONS as Me}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{r as st}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{S as at}from"../packem_shared/schema-diagram-Dbs7-jSJ.mjs";import{useNavigate as nt}from"@tanstack/react-router";import{B as ye}from"../packem_shared/button-q0UYSmrn.mjs";import{L as Ee}from"../packem_shared/label-DKFzyHq6.mjs";import{jsx as l,jsxs as p,Fragment as Ve}from"react/jsx-runtime";const ot=Le(Me.listTables),it=Le(Me.listTableIndexes),rt=Le(Me.readTablePage),dt=Le(Me.describeTables),ct={},Ye=[],mt=n=>{const e=we(74),{initialShardKey:m,initialTable:a}=n,t=lt(),[s,c]=_("graph"),{queryShardKey:d,setShardKey:r,shardKey:g}=tt(m),[o,u]=_(""),[i,v]=_(null),[f,O]=_(null);let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S={},e[0]=S):S=e[0];const[G,y]=_(S);let L;e[1]===Symbol.for("react.memo_cache_sentinel")?(L={},e[1]=L):L=e[1];const[$,z]=_(L),[T,C]=_(null);let A;e[2]===Symbol.for("react.memo_cache_sentinel")?(A={},e[2]=A):A=e[2];const[F,pe]=_(A);let te;e[3]===Symbol.for("react.memo_cache_sentinel")?(te={},e[3]=te):te=e[3];const[E,M]=_(te),[w,ge]=_(null),[B,ce]=_(null);let le;e[4]===Symbol.for("react.memo_cache_sentinel")?(le={},e[4]=le):le=e[4];const[J,Ne]=_(le),[W,me]=_(null),be=Ue(0);let D;e[5]!==t?(D=async h=>{be.current=be.current+1;const x=be.current;O(null);try{const N=await t.query(ot,{},Ae(h));if(x!==be.current)return;st(h),v(N),y({}),z({}),C(null),pe(k=>Object.fromEntries(Object.entries(k).filter(I=>{const[he]=I;return he!==h}))),M(k=>Object.fromEntries(Object.entries(k).filter(I=>{const[he]=I;return he!==h})))}catch(N){const k=N;if(x!==be.current)return;v(null),O($e(k))}},e[5]=t,e[6]=D):D=e[6];const j=D;let se;e[7]!==t?(se=async()=>{ce(null);try{ge(await t.listGlobalTables())}catch(h){const x=h;ge(null),ce($e(x))}},e[7]=t,e[8]=se):se=e[8];const ue=se;let R,ae;e[9]!==d||e[10]!==j||e[11]!==ue?(R=()=>{Ce(j(d)),Ce(ue())},ae=[j,ue,d],e[9]=d,e[10]=j,e[11]=ue,e[12]=R,e[13]=ae):(R=e[12],ae=e[13]),qe(R,ae);let K;e[14]!==t||e[15]!==G||e[16]!==T||e[17]!==d?(K=async h=>{if(T===h){C(null);return}C(h);const x=`${d}:${h}`;if(G[x]!==void 0)return;const[N,k]=await Promise.allSettled([t.query(rt,{limit:1,offset:0,table:h},Ae(d)),t.query(it,{table:h},Ae(d))]);N.status==="fulfilled"?y(I=>({...I,[x]:N.value.columns})):O($e(N.reason)),k.status==="fulfilled"&&z(I=>({...I,[x]:k.value.indexes}))},e[14]=t,e[15]=G,e[16]=T,e[17]=d,e[18]=K):K=e[18];const ne=K;let oe;e[19]!==t||e[20]!==J||e[21]!==W?(oe=async h=>{if(W===h){me(null);return}if(me(h),J[h]===void 0)try{const x=await t.readGlobalTablePage({limit:1,offset:0,table:h});Ne(N=>({...N,[h]:x.columns}))}catch(x){ce($e(x))}},e[19]=t,e[20]=J,e[21]=W,e[22]=oe):oe=e[22];const fe=oe,X=Ue(void 0);let Q,U;e[23]!==a||e[24]!==i||e[25]!==ne?(Q=()=>{a===void 0||i===null||X.current===a||i.some(h=>h.name===a)&&(X.current=a,Ce(ne(a)))},U=[a,i,ne],e[23]=a,e[24]=i,e[25]=ne,e[26]=Q,e[27]=U):(Q=e[26],U=e[27]),qe(Q,U);let ie;e[28]!==t?(ie=async(h,x,N)=>{const[k,I]=await Promise.all([Promise.allSettled([t.query(dt,{tables:[...x,...N]},Ae(h))]),Promise.all(N.map(async H=>{const Se=await Promise.allSettled([t.readGlobalTablePage({limit:1,offset:0,table:H})]),Re=Se[0].status==="fulfilled"?Se[0].value:void 0;return{columns:Re?.columns??[],refs:Re?.refs??{},table:H}}))]),he=k[0].status==="fulfilled"?k[0].value?.columnsByTable??{}:{},_e=k[0].status==="rejected",Ie=new Map(I.map(ut)),q=[...x,...N].map(H=>{const Se=he[H]??[];return[H,Se.length>0?Se:Ie.get(H)??[]]});pe(H=>({...H,[h]:Object.fromEntries(q)})),M(H=>({...H,[h]:_e}))},e[28]=t,e[29]=ie):ie=e[29];const V=ie;let re,Y;e[30]!==B||e[31]!==w||e[32]!==V||e[33]!==d||e[34]!==F||e[35]!==i||e[36]!==s?(re=()=>{s!=="graph"||i===null||w===null&&B===null||F[d]!==void 0||Ce(V(d,i.map(ft),(w??[]).map(ht)))},Y=[s,i,w,B,d,F,V],e[30]=B,e[31]=w,e[32]=V,e[33]=d,e[34]=F,e[35]=i,e[36]=s,e[37]=re,e[38]=Y):(re=e[37],Y=e[38]),qe(re,Y);const P=F[d]??ct;let Z;if(e[39]!==P||e[40]!==w||e[41]!==i){let h;e[43]!==P?(h=I=>({columns:P[I.name]??Ye,name:I.name,tier:"shard"}),e[43]=P,e[44]=h):h=e[44];const x=(i??[]).map(h);let N;e[45]!==P?(N=I=>({columns:P[I.name]??Ye,name:I.name,tier:"global"}),e[45]=P,e[46]=N):N=e[46];const k=(w??[]).map(N);Z=[...x,...k],e[39]=P,e[40]=w,e[41]=i,e[42]=Z}else Z=e[42];const b=Z;let ee;if(e[47]!==o||e[48]!==i){const h=o.trim().toLowerCase();ee=(i??[]).filter(x=>x.name.toLowerCase().includes(h)),e[47]=o,e[48]=i,e[49]=ee}else ee=e[49];const de=ee;let xe;if(e[50]!==w||e[51]!==o){const h=o.trim().toLowerCase();xe=(w??[]).filter(x=>x.name.toLowerCase().includes(h)),e[50]=w,e[51]=o,e[52]=xe}else xe=e[52];const Te=xe;let ve;return e[53]!==G||e[54]!==b||e[55]!==f||e[56]!==T||e[57]!==Te||e[58]!==de||e[59]!==J||e[60]!==B||e[61]!==W||e[62]!==w||e[63]!==$||e[64]!==j||e[65]!==r||e[66]!==E||e[67]!==g||e[68]!==o||e[69]!==i||e[70]!==ne||e[71]!==fe||e[72]!==s?(ve={columns:G,diagramTables:b,error:f,expanded:T,filteredGlobalTables:Te,filteredTables:de,globalColumns:J,globalError:B,globalExpanded:W,globalTables:w,indexes:$,refresh:j,setShardKey:r,setTableFilter:u,setView:c,shardColumnsError:E,shardKey:g,tableFilter:o,tables:i,toggle:ne,toggleGlobal:fe,view:s},e[53]=G,e[54]=b,e[55]=f,e[56]=T,e[57]=Te,e[58]=de,e[59]=J,e[60]=B,e[61]=W,e[62]=w,e[63]=$,e[64]=j,e[65]=r,e[66]=E,e[67]=g,e[68]=o,e[69]=i,e[70]=ne,e[71]=fe,e[72]=s,e[73]=ve):ve=e[73],ve};function ut(n){const{columns:e,refs:m,table:a}=n;return[a,e.map(t=>{const s=m[t];return s===void 0?{name:t,optional:!1,type:""}:{name:t,optional:!1,ref:s,type:"id"}})]}function ft(n){return n.name}function ht(n){return n.name}const pt="/__lunora/schema-edit",gt=async n=>{const e=await fetch(pt,{body:JSON.stringify(n),headers:{"Content-Type":"application/json"},method:"POST"}),m=await e.json();return m.needsMigration===!0?{kind:"needs-migration",message:m.message??"This edit needs a migration."}:e.ok&&m.tables!==void 0?{diagnostics:m.diagnostics??[],kind:"ok",tables:m.tables}:{kind:"error",message:m.error??`schema edit failed (${String(e.status)})`}},bt=n=>{const e=we(32),{hasTables:m,mode:a,onAddColumn:t,onAddIndex:s,onAddTable:c,onDestructive:d}=n,r=Oe(),g=a==="addTable"?"default":"outline";let o;e[0]!==r?(o=r("Add table"),e[0]=r,e[1]=o):o=e[1];let u;e[2]!==c||e[3]!==g||e[4]!==o?(u=l(ye,{"data-testid":"sc-editor-add-table",onClick:c,size:"xs",type:"button",variant:g,children:o}),e[2]=c,e[3]=g,e[4]=o,e[5]=u):u=e[5];const i=!m,v=a==="addColumn"?"default":"outline";let f;e[6]!==r?(f=r("Add column"),e[6]=r,e[7]=f):f=e[7];let O;e[8]!==t||e[9]!==i||e[10]!==v||e[11]!==f?(O=l(ye,{"data-testid":"sc-editor-add-column",disabled:i,onClick:t,size:"xs",type:"button",variant:v,children:f}),e[8]=t,e[9]=i,e[10]=v,e[11]=f,e[12]=O):O=e[12];const S=!m,G=a==="addIndex"?"default":"outline";let y;e[13]!==r?(y=r("Add index"),e[13]=r,e[14]=y):y=e[14];let L;e[15]!==s||e[16]!==y||e[17]!==S||e[18]!==G?(L=l(ye,{"data-testid":"sc-editor-add-index",disabled:S,onClick:s,size:"xs",type:"button",variant:G,children:y}),e[15]=s,e[16]=y,e[17]=S,e[18]=G,e[19]=L):L=e[19];const $=!m,z=a==="destructive"?"default":"ghost";let T;e[20]!==r?(T=r("Rename / drop / change type…"),e[20]=r,e[21]=T):T=e[21];let C;e[22]!==d||e[23]!==$||e[24]!==z||e[25]!==T?(C=l(ye,{"data-testid":"sc-editor-destructive",disabled:$,onClick:d,size:"xs",type:"button",variant:z,children:T}),e[22]=d,e[23]=$,e[24]=z,e[25]=T,e[26]=C):C=e[26];let A;return e[27]!==L||e[28]!==C||e[29]!==u||e[30]!==O?(A=p("div",{className:"flex flex-wrap gap-2",children:[u,O,L,C]}),e[27]=L,e[28]=C,e[29]=u,e[30]=O,e[31]=A):A=e[31],A},xt=n=>{const e=we(28),{onOpenMigrations:m,result:a}=n,t=Oe();if(a===null){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ve,{}),e[0]=o):o=e[0],o}if(a.kind==="error"){let o;return e[1]!==a.message?(o=l("p",{className:"mt-3 text-sm text-destructive","data-testid":"sc-editor-error",role:"alert",children:a.message}),e[1]=a.message,e[2]=o):o=e[2],o}if(a.kind==="needs-migration"){let o;e[3]!==a.message||e[4]!==t?(o=a.message===""?t("This edit changes stored data and must go through a migration. Review the migration before applying."):a.message,e[3]=a.message,e[4]=t,e[5]=o):o=e[5];let u;e[6]!==o?(u=l("p",{className:"text-sm text-warning",role:"alert",children:o}),e[6]=o,e[7]=u):u=e[7];let i;e[8]!==t?(i=t("Open Migrations"),e[8]=t,e[9]=i):i=e[9];let v;e[10]!==m||e[11]!==i?(v=l(ye,{className:"self-start","data-testid":"sc-editor-open-migrations",onClick:m,size:"xs",type:"button",variant:"outline",children:i}),e[10]=m,e[11]=i,e[12]=v):v=e[12];let f;return e[13]!==u||e[14]!==v?(f=p("div",{className:"mt-3 flex flex-col gap-2","data-testid":"sc-editor-needs-migration",children:[u,v]}),e[13]=u,e[14]=v,e[15]=f):f=e[15],f}if(a.diagnostics.length===0){let o;return e[16]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ve,{}),e[16]=o):o=e[16],o}let s;e[17]!==t?(s=t("Codegen reported diagnostics:"),e[17]=t,e[18]=s):s=e[18];let c;e[19]!==s?(c=l("p",{className:"text-sm text-destructive",role:"alert",children:s}),e[19]=s,e[20]=c):c=e[20];let d;e[21]!==a.diagnostics?(d=a.diagnostics.map(vt),e[21]=a.diagnostics,e[22]=d):d=e[22];let r;e[23]!==d?(r=l("ul",{className:"flex flex-col gap-0.5",children:d}),e[23]=d,e[24]=r):r=e[24];let g;return e[25]!==c||e[26]!==r?(g=p("div",{className:"mt-3 flex flex-col gap-1","data-testid":"sc-editor-diagnostics",children:[c,r]}),e[25]=c,e[26]=r,e[27]=g):g=e[27],g};function vt(n){return l("li",{className:"font-mono text-[11px] text-destructive",children:n},n)}const yt=[{label:"string",validator:"v.string()"},{label:"number",validator:"v.number()"},{label:"boolean",validator:"v.boolean()"},{label:"bigint",validator:"v.bigint()"},{label:"bytes",validator:"v.bytes()"},{label:"any",validator:"v.any()"}],Ct="v.string()",Nt=n=>n.split(",").map(e=>e.trim()).filter(e=>e!==""),Tt=n=>{const e=we(83),{onApplied:m,tableNames:a}=n,t=Oe(),s=nt(),[c,d]=_(null),[r,g]=_(!1),[o,u]=_(null),[i,v]=_(""),[f,O]=_(""),[S,G]=_(Ct),[y,L]=_(a[0]??""),[$,z]=_(""),[T,C]=_(""),[A,F]=_(!1);let pe;e[0]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>{d(null),v(""),O(""),z(""),C(""),F(!1)},e[0]=pe):pe=e[0];const te=pe;let E;e[1]!==m?(E=async q=>{g(!0),u(null);try{const H=await gt(q);u(H),H.kind==="ok"&&(m(H.tables),te())}catch(H){const Se=H;u({kind:"error",message:Se instanceof Error?Se.message:String(Se)})}g(!1)},e[1]=m,e[2]=E):E=e[2];const M=E;let w;e[3]!==M||e[4]!==i?(w=()=>{Ce(M({kind:"addTable",table:i.trim()}))},e[3]=M,e[4]=i,e[5]=w):w=e[5];const ge=w;let B;e[6]!==f||e[7]!==M||e[8]!==y||e[9]!==S?(B=()=>{Ce(M({column:f.trim(),kind:"addOptionalColumn",table:y,validator:S}))},e[6]=f,e[7]=M,e[8]=y,e[9]=S,e[10]=B):B=e[10];const ce=B;let le;e[11]!==T||e[12]!==$||e[13]!==M||e[14]!==y||e[15]!==A?(le=()=>{Ce(M({fields:Nt(T),kind:"addIndex",name:$.trim(),table:y,unique:A}))},e[11]=T,e[12]=$,e[13]=M,e[14]=y,e[15]=A,e[16]=le):le=e[16];const J=le;let Ne;e[17]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>{u(null),d("addTable")},e[17]=Ne):Ne=e[17];const W=Ne;let me;e[18]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{u(null),d("addColumn")},e[18]=me):me=e[18];const be=me;let D;e[19]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{u(null),d("addIndex")},e[19]=D):D=e[19];const j=D;let se;e[20]!==t?(se=()=>{d("destructive"),u({kind:"needs-migration",message:t("This edit changes stored data and must go through a migration. Review the migration before applying.")})},e[20]=t,e[21]=se):se=e[21];const ue=se;let R;e[22]===Symbol.for("react.memo_cache_sentinel")?(R=q=>{v(q.target.value)},e[22]=R):R=e[22];const ae=R;let K;e[23]===Symbol.for("react.memo_cache_sentinel")?(K=q=>{O(q.target.value)},e[23]=K):K=e[23];const ne=K;let oe;e[24]===Symbol.for("react.memo_cache_sentinel")?(oe=q=>{G(q.target.value)},e[24]=oe):oe=e[24];const fe=oe;let X;e[25]===Symbol.for("react.memo_cache_sentinel")?(X=q=>{L(q.target.value)},e[25]=X):X=e[25];const Q=X;let U;e[26]===Symbol.for("react.memo_cache_sentinel")?(U=q=>{z(q.target.value)},e[26]=U):U=e[26];const ie=U;let V;e[27]===Symbol.for("react.memo_cache_sentinel")?(V=q=>{C(q.target.value)},e[27]=V):V=e[27];const re=V;let Y;e[28]===Symbol.for("react.memo_cache_sentinel")?(Y=q=>{F(q.target.checked)},e[28]=Y):Y=e[28];const P=Y;let Z;e[29]!==s?(Z=()=>{Ce(s({to:"/migrations"}))},e[29]=s,e[30]=Z):Z=e[30];const b=Z;let ee;e[31]!==t?(ee=t("Edit schema"),e[31]=t,e[32]=ee):ee=e[32];let de;e[33]!==ee?(de=l(Ge,{children:ee}),e[33]=ee,e[34]=de):de=e[34];let xe;e[35]!==t?(xe=t("Adds a table, column, or index to lunora/schema.ts and reruns codegen."),e[35]=t,e[36]=xe):xe=e[36];let Te;e[37]!==xe?(Te=l(ze,{children:xe}),e[37]=xe,e[38]=Te):Te=e[38];let ve;e[39]!==de||e[40]!==Te?(ve=p(Be,{children:[de,Te]}),e[39]=de,e[40]=Te,e[41]=ve):ve=e[41];const h=a.length>0;let x;e[42]!==c||e[43]!==ue||e[44]!==h?(x=l(bt,{hasTables:h,mode:c,onAddColumn:be,onAddIndex:j,onAddTable:W,onDestructive:ue}),e[42]=c,e[43]=ue,e[44]=h,e[45]=x):x=e[45];let N;e[46]!==r||e[47]!==c||e[48]!==ge||e[49]!==t||e[50]!==i?(N=c==="addTable"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-table-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-table-name",children:t("Table name")}),l(ke,{"data-testid":"sc-editor-table-name",id:"sc-editor-table-name",onChange:ae,value:i})]}),l(ye,{"data-testid":"sc-editor-table-apply",disabled:r||i.trim()==="",onClick:ge,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[46]=r,e[47]=c,e[48]=ge,e[49]=t,e[50]=i,e[51]=N):N=e[51];let k;e[52]!==r||e[53]!==f||e[54]!==c||e[55]!==ce||e[56]!==t||e[57]!==a||e[58]!==y||e[59]!==S?(k=c==="addColumn"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-column-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-table",id:"sc-editor-column-table",onChange:Q,value:y,children:a.map(St)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-name",children:t("Column name")}),l(ke,{"data-testid":"sc-editor-column-name",id:"sc-editor-column-name",onChange:ne,value:f})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-type",children:t("Column type")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-type",id:"sc-editor-column-type",onChange:fe,value:S,children:yt.map(wt)})]}),l("span",{className:"text-[11px] text-muted-foreground",children:t("Optional")}),l(ye,{"data-testid":"sc-editor-column-apply",disabled:r||f.trim()===""||y==="",onClick:ce,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[52]=r,e[53]=f,e[54]=c,e[55]=ce,e[56]=t,e[57]=a,e[58]=y,e[59]=S,e[60]=k):k=e[60];let I;e[61]!==r||e[62]!==T||e[63]!==$||e[64]!==c||e[65]!==J||e[66]!==t||e[67]!==a||e[68]!==y||e[69]!==A?(I=c==="addIndex"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-index-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-index-table",id:"sc-editor-index-table",onChange:Q,value:y,children:a.map(_t)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-name",children:t("Index name")}),l(ke,{"data-testid":"sc-editor-index-name",id:"sc-editor-index-name",onChange:ie,value:$})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-fields",children:t("Index fields (comma-separated)")}),l(ke,{"data-testid":"sc-editor-index-fields",id:"sc-editor-index-fields",onChange:re,value:T})]}),p(Ee,{className:"flex items-center gap-1 text-xs",htmlFor:"sc-editor-index-unique",children:[l("input",{checked:A,"data-testid":"sc-editor-index-unique",id:"sc-editor-index-unique",onChange:P,type:"checkbox"}),l("span",{className:"text-muted-foreground",children:t("Unique")})]}),l(ye,{"data-testid":"sc-editor-index-apply",disabled:r||$.trim()===""||T.trim()==="",onClick:J,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[61]=r,e[62]=T,e[63]=$,e[64]=c,e[65]=J,e[66]=t,e[67]=a,e[68]=y,e[69]=A,e[70]=I):I=e[70];let he;e[71]!==b||e[72]!==o?(he=l(xt,{onOpenMigrations:b,result:o}),e[71]=b,e[72]=o,e[73]=he):he=e[73];let _e;e[74]!==x||e[75]!==N||e[76]!==k||e[77]!==I||e[78]!==he?(_e=p(De,{children:[x,N,k,I,he]}),e[74]=x,e[75]=N,e[76]=k,e[77]=I,e[78]=he,e[79]=_e):_e=e[79];let Ie;return e[80]!==ve||e[81]!==_e?(Ie=p(je,{"data-testid":"sc-editor",size:"sm",children:[ve,_e]}),e[80]=ve,e[81]=_e,e[82]=Ie):Ie=e[82],Ie};function St(n){return l("option",{value:n,children:n},n)}function wt(n){return l("option",{value:n.validator,children:n.label},n.validator)}function _t(n){return l("option",{value:n,children:n},n)}const He=[],Et=n=>{const e=we(5),{open:m}=n,a=m&&"rotate-90";let t;e[0]!==a?(t=Qe("size-3.5 shrink-0 text-muted-foreground transition-transform duration-150",a),e[0]=a,e[1]=t):t=e[1];let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=l("path",{d:"m9 6 6 6-6 6"}),e[2]=s):s=e[2];let c;return e[3]!==t?(c=l("svg",{"aria-hidden":"true",className:t,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:s}),e[3]=t,e[4]=c):c=e[4],c},Je=n=>{const e=we(20),{children:m,expanded:a,name:t,onToggle:s,rowCount:c,rowTestId:d,toggleTestId:r}=n;let g;e[0]!==a?(g=l(Et,{open:a}),e[0]=a,e[1]=g):g=e[1];let o;e[2]!==t?(o=l("span",{className:"truncate font-mono text-xs text-foreground",title:t,children:t}),e[2]=t,e[3]=o):o=e[3];let u;e[4]!==c?(u=p("span",{className:"ms-auto shrink-0 text-xs text-muted-foreground tabular-nums",children:["(",c,")"]}),e[4]=c,e[5]=u):u=e[5];let i;e[6]!==a||e[7]!==s||e[8]!==g||e[9]!==o||e[10]!==u||e[11]!==r?(i=p("button",{"aria-expanded":a,className:"flex w-full items-center gap-2 px-3 py-2 text-start transition-colors hover:bg-muted/50 aria-expanded:bg-muted/40","data-testid":r,onClick:s,type:"button",children:[g,o," ",u]}),e[6]=a,e[7]=s,e[8]=g,e[9]=o,e[10]=u,e[11]=r,e[12]=i):i=e[12];let v;e[13]!==m||e[14]!==a?(v=a&&l("div",{className:"px-3 pb-3 ps-8",children:m}),e[13]=m,e[14]=a,e[15]=v):v=e[15];let f;return e[16]!==d||e[17]!==i||e[18]!==v?(f=p("li",{className:"border-t border-border/60 first:border-t-0","data-testid":d,children:[i,v]}),e[16]=d,e[17]=i,e[18]=v,e[19]=f):f=e[19],f},We=n=>{const e=we(5),{columns:m,testId:a}=n;let t;e[0]!==m?(t=m.map(kt),e[0]=m,e[1]=t):t=e[1];let s;return e[2]!==t||e[3]!==a?(s=l("ul",{className:"flex flex-wrap gap-1.5 pt-1","data-testid":a,children:t}),e[2]=t,e[3]=a,e[4]=s):s=e[4],s},It=n=>{const e=we(10),{heading:m,indexes:a,testId:t}=n;let s;e[0]!==m?(s=l("p",{className:"mb-1.5 font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:m}),e[0]=m,e[1]=s):s=e[1];let c;e[2]!==a?(c=a.map(At),e[2]=a,e[3]=c):c=e[3];let d;e[4]!==c||e[5]!==t?(d=l("ul",{className:"flex flex-col gap-1","data-testid":t,children:c}),e[4]=c,e[5]=t,e[6]=d):d=e[6];let r;return e[7]!==s||e[8]!==d?(r=p("div",{className:"pt-3",children:[s,d]}),e[7]=s,e[8]=d,e[9]=r):r=e[9],r},Xe=n=>Qe("border-b-2 px-3 py-2 font-mono text-[11px] tracking-widest uppercase outline-none transition-colors",n?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),Qt=n=>{const e=we(85),{initialShardKey:m,initialTable:a,schemaEditable:t}=n,s=Oe();let c;e[0]!==m||e[1]!==a?(c={initialShardKey:m,initialTable:a},e[0]=m,e[1]=a,e[2]=c):c=e[2];const{columns:d,diagramTables:r,error:g,expanded:o,filteredGlobalTables:u,filteredTables:i,globalColumns:v,globalError:f,globalExpanded:O,globalTables:S,indexes:G,refresh:y,setShardKey:L,setTableFilter:$,setView:z,shardColumnsError:T,shardKey:C,tableFilter:A,tables:F,toggle:pe,toggleGlobal:te,view:E}=mt(c);let M;e[3]!==z?(M=()=>{z("list")},e[3]=z,e[4]=M):M=e[4];const w=M;let ge;e[5]!==z?(ge=()=>{z("graph")},e[5]=z,e[6]=ge):ge=e[6];const B=ge;let ce;e[7]!==$?(ce=b=>{$(b.target.value)},e[7]=$,e[8]=ce):ce=e[8];const le=ce;let J;e[9]!==y||e[10]!==C?(J=b=>{Ce(y(C))},e[9]=y,e[10]=C,e[11]=J):J=e[11];const Ne=J;let W;e[12]!==F?(W=F??[],e[12]=F,e[13]=W):W=e[13];let me;e[14]!==W?(me=W.map($t),e[14]=W,e[15]=me):me=e[15];const be=me;let D;e[16]!==L||e[17]!==C?(D=l(Ze,{onChange:L,testId:"sc-shard-input",value:C}),e[16]=L,e[17]=C,e[18]=D):D=e[18];let j;e[19]!==s?(j=s("Schema view"),e[19]=s,e[20]=j):j=e[20];const se=E==="graph",ue=E==="graph";let R;e[21]!==ue?(R=Xe(ue),e[21]=ue,e[22]=R):R=e[22];let ae;e[23]!==s?(ae=s("Graph"),e[23]=s,e[24]=ae):ae=e[24];let K;e[25]!==B||e[26]!==se||e[27]!==R||e[28]!==ae?(K=l("button",{"aria-selected":se,className:R,"data-testid":"sc-view-graph",onClick:B,role:"tab",type:"button",children:ae}),e[25]=B,e[26]=se,e[27]=R,e[28]=ae,e[29]=K):K=e[29];const ne=E==="list",oe=E==="list";let fe;e[30]!==oe?(fe=Xe(oe),e[30]=oe,e[31]=fe):fe=e[31];let X;e[32]!==s?(X=s("Table list"),e[32]=s,e[33]=X):X=e[33];let Q;e[34]!==w||e[35]!==ne||e[36]!==fe||e[37]!==X?(Q=l("button",{"aria-selected":ne,className:fe,"data-testid":"sc-view-list",onClick:w,role:"tab",type:"button",children:X}),e[34]=w,e[35]=ne,e[36]=fe,e[37]=X,e[38]=Q):Q=e[38];let U;e[39]!==K||e[40]!==Q||e[41]!==j?(U=p("div",{"aria-label":j,className:"flex items-center gap-1","data-testid":"sc-view-toggle",role:"tablist",children:[K,Q]}),e[39]=K,e[40]=Q,e[41]=j,e[42]=U):U=e[42];let ie;e[43]!==U||e[44]!==D?(ie=p("div",{className:"flex flex-wrap items-center gap-3",children:[D,U]}),e[43]=U,e[44]=D,e[45]=ie):ie=e[45];let V;e[46]!==Ne||e[47]!==t||e[48]!==be?(V=t===!0&&l(Tt,{onApplied:Ne,tableNames:be}),e[46]=Ne,e[47]=t,e[48]=be,e[49]=V):V=e[49];let re;e[50]!==le||e[51]!==s||e[52]!==A||e[53]!==E?(re=E==="list"&&l(ke,{"aria-label":s("Filter tables"),className:"h-8 max-w-xs","data-testid":"sc-filter",onChange:le,placeholder:s("Filter tables"),value:A}),e[50]=le,e[51]=s,e[52]=A,e[53]=E,e[54]=re):re=e[54];let Y;e[55]!==r||e[56]!==g||e[57]!==f||e[58]!==T||e[59]!==C||e[60]!==E?(Y=E==="graph"&&p("div",{className:"flex flex-col gap-2","data-testid":"sc-graph-view",children:[g!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:g}),f!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:f}),l(at,{columnsError:T[C]===!0,tables:r,testIdPrefix:"sc-graph"})]}),e[55]=r,e[56]=g,e[57]=f,e[58]=T,e[59]=C,e[60]=E,e[61]=Y):Y=e[61];let P;e[62]!==d||e[63]!==g||e[64]!==o||e[65]!==u||e[66]!==i||e[67]!==v||e[68]!==f||e[69]!==O||e[70]!==S||e[71]!==G||e[72]!==C||e[73]!==s||e[74]!==F||e[75]!==pe||e[76]!==te||e[77]!==E?(P=E==="list"&&p("div",{className:"flex flex-col gap-4",children:[p(je,{"data-testid":"sc-shard-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Ke,{tier:"shard"}),l(Ge,{children:s("Shard tables")}),F!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:i.length})]}),l(ze,{children:Pe.shard.hint})]}),p(De,{children:[g!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:g}),F!==null&&F.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-empty",children:s("No tables in this shard.")}),F!==null&&F.length>0&&i.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-no-match",children:s("No tables match your filter.")}),i.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-table-list",children:i.map(b=>{const ee=`${C}:${b.name}`,de=G[ee]??[];return p(Je,{expanded:o===b.name,name:b.name,onToggle:()=>{Ce(pe(b.name))},rowCount:b.rowCount,rowTestId:`sc-table-${b.name}`,toggleTestId:`sc-toggle-${b.name}`,children:[l(We,{columns:d[ee]??He,testId:`sc-columns-${b.name}`}),de.length>0&&l(It,{heading:s("Indexes"),indexes:de,testId:`sc-indexes-${b.name}`})]},b.name)})})]})]}),p(je,{"data-testid":"sc-global-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Ke,{tier:"global"}),l(Ge,{children:s("Global tables (D1)")}),S!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:u.length})]}),l(ze,{children:Pe.global.hint})]}),p(De,{children:[f!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:f}),S!==null&&S.length===0&&l(et,{description:Pe.global.hint,testId:"sc-global-empty",title:s("No global tables.")}),S!==null&&S.length>0&&u.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-global-no-match",children:s("No tables match your filter.")}),u.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-global-table-list",children:u.map(b=>l(Je,{expanded:O===b.name,name:b.name,onToggle:()=>{Ce(te(b.name))},rowCount:b.rowCount,rowTestId:`sc-global-table-${b.name}`,toggleTestId:`sc-global-toggle-${b.name}`,children:l(We,{columns:v[b.name]??He,testId:`sc-global-columns-${b.name}`})},b.name))})]})]})]}),e[62]=d,e[63]=g,e[64]=o,e[65]=u,e[66]=i,e[67]=v,e[68]=f,e[69]=O,e[70]=S,e[71]=G,e[72]=C,e[73]=s,e[74]=F,e[75]=pe,e[76]=te,e[77]=E,e[78]=P):P=e[78];let Z;return e[79]!==ie||e[80]!==V||e[81]!==re||e[82]!==Y||e[83]!==P?(Z=p("div",{className:"flex flex-col gap-4","data-testid":"lunora-schema",children:[ie,V,re,Y,P]}),e[79]=ie,e[80]=V,e[81]=re,e[82]=Y,e[83]=P,e[84]=Z):Z=e[84],Z};function kt(n){return l("li",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:n},n)}function At(n){return p("li",{className:"flex flex-wrap items-center gap-1.5 text-xs",children:[l("span",{className:"font-mono",children:n.name}),l(Fe,{variant:"outline",children:n.type}),n.unique===!0&&l(Fe,{variant:"secondary",children:"unique"}),l("span",{className:"text-muted-foreground",children:n.fields.join(", ")})]},`${n.type}:${n.name}`)}function $t(n){return n.name}export{Qt as SchemaViewer};
1
+ import{c as we}from"react/compiler-runtime";import{ShardInput as Ze}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{S as Ke,T as Pe}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{B as Fe}from"../packem_shared/badge-r_5B4LHP.mjs";import{c as Ge,d as ze,b as Be,a as De,C as je}from"../packem_shared/card-By2O8ULa.mjs";import{E as et}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as ke}from"../packem_shared/input-CXhxesPC.mjs";import{useT as Oe}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{d as Le,g as Ae,b as $e,f as Ce}from"../packem_shared/internal-BT5tH08j.mjs";import{c as Qe}from"../packem_shared/utils-bhneXptQ.mjs";import{useState as _,useRef as Ue,useEffect as qe}from"react";import{u as tt}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{u as lt}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{ADMIN_FUNCTIONS as Me}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{r as st}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{S as at}from"../packem_shared/schema-diagram-BpIBRUm6.mjs";import{useNavigate as nt}from"@tanstack/react-router";import{B as ye}from"../packem_shared/button-q0UYSmrn.mjs";import{L as Ee}from"../packem_shared/label-DKFzyHq6.mjs";import{jsx as l,jsxs as p,Fragment as Ve}from"react/jsx-runtime";const ot=Le(Me.listTables),it=Le(Me.listTableIndexes),rt=Le(Me.readTablePage),dt=Le(Me.describeTables),ct={},Ye=[],mt=n=>{const e=we(74),{initialShardKey:m,initialTable:a}=n,t=lt(),[s,c]=_("graph"),{queryShardKey:d,setShardKey:r,shardKey:g}=tt(m),[o,u]=_(""),[i,v]=_(null),[f,O]=_(null);let S;e[0]===Symbol.for("react.memo_cache_sentinel")?(S={},e[0]=S):S=e[0];const[G,y]=_(S);let L;e[1]===Symbol.for("react.memo_cache_sentinel")?(L={},e[1]=L):L=e[1];const[$,z]=_(L),[T,C]=_(null);let A;e[2]===Symbol.for("react.memo_cache_sentinel")?(A={},e[2]=A):A=e[2];const[F,pe]=_(A);let te;e[3]===Symbol.for("react.memo_cache_sentinel")?(te={},e[3]=te):te=e[3];const[E,M]=_(te),[w,ge]=_(null),[B,ce]=_(null);let le;e[4]===Symbol.for("react.memo_cache_sentinel")?(le={},e[4]=le):le=e[4];const[J,Ne]=_(le),[W,me]=_(null),be=Ue(0);let D;e[5]!==t?(D=async h=>{be.current=be.current+1;const x=be.current;O(null);try{const N=await t.query(ot,{},Ae(h));if(x!==be.current)return;st(h),v(N),y({}),z({}),C(null),pe(k=>Object.fromEntries(Object.entries(k).filter(I=>{const[he]=I;return he!==h}))),M(k=>Object.fromEntries(Object.entries(k).filter(I=>{const[he]=I;return he!==h})))}catch(N){const k=N;if(x!==be.current)return;v(null),O($e(k))}},e[5]=t,e[6]=D):D=e[6];const j=D;let se;e[7]!==t?(se=async()=>{ce(null);try{ge(await t.listGlobalTables())}catch(h){const x=h;ge(null),ce($e(x))}},e[7]=t,e[8]=se):se=e[8];const ue=se;let R,ae;e[9]!==d||e[10]!==j||e[11]!==ue?(R=()=>{Ce(j(d)),Ce(ue())},ae=[j,ue,d],e[9]=d,e[10]=j,e[11]=ue,e[12]=R,e[13]=ae):(R=e[12],ae=e[13]),qe(R,ae);let K;e[14]!==t||e[15]!==G||e[16]!==T||e[17]!==d?(K=async h=>{if(T===h){C(null);return}C(h);const x=`${d}:${h}`;if(G[x]!==void 0)return;const[N,k]=await Promise.allSettled([t.query(rt,{limit:1,offset:0,table:h},Ae(d)),t.query(it,{table:h},Ae(d))]);N.status==="fulfilled"?y(I=>({...I,[x]:N.value.columns})):O($e(N.reason)),k.status==="fulfilled"&&z(I=>({...I,[x]:k.value.indexes}))},e[14]=t,e[15]=G,e[16]=T,e[17]=d,e[18]=K):K=e[18];const ne=K;let oe;e[19]!==t||e[20]!==J||e[21]!==W?(oe=async h=>{if(W===h){me(null);return}if(me(h),J[h]===void 0)try{const x=await t.readGlobalTablePage({limit:1,offset:0,table:h});Ne(N=>({...N,[h]:x.columns}))}catch(x){ce($e(x))}},e[19]=t,e[20]=J,e[21]=W,e[22]=oe):oe=e[22];const fe=oe,X=Ue(void 0);let Q,U;e[23]!==a||e[24]!==i||e[25]!==ne?(Q=()=>{a===void 0||i===null||X.current===a||i.some(h=>h.name===a)&&(X.current=a,Ce(ne(a)))},U=[a,i,ne],e[23]=a,e[24]=i,e[25]=ne,e[26]=Q,e[27]=U):(Q=e[26],U=e[27]),qe(Q,U);let ie;e[28]!==t?(ie=async(h,x,N)=>{const[k,I]=await Promise.all([Promise.allSettled([t.query(dt,{tables:[...x,...N]},Ae(h))]),Promise.all(N.map(async H=>{const Se=await Promise.allSettled([t.readGlobalTablePage({limit:1,offset:0,table:H})]),Re=Se[0].status==="fulfilled"?Se[0].value:void 0;return{columns:Re?.columns??[],refs:Re?.refs??{},table:H}}))]),he=k[0].status==="fulfilled"?k[0].value?.columnsByTable??{}:{},_e=k[0].status==="rejected",Ie=new Map(I.map(ut)),q=[...x,...N].map(H=>{const Se=he[H]??[];return[H,Se.length>0?Se:Ie.get(H)??[]]});pe(H=>({...H,[h]:Object.fromEntries(q)})),M(H=>({...H,[h]:_e}))},e[28]=t,e[29]=ie):ie=e[29];const V=ie;let re,Y;e[30]!==B||e[31]!==w||e[32]!==V||e[33]!==d||e[34]!==F||e[35]!==i||e[36]!==s?(re=()=>{s!=="graph"||i===null||w===null&&B===null||F[d]!==void 0||Ce(V(d,i.map(ft),(w??[]).map(ht)))},Y=[s,i,w,B,d,F,V],e[30]=B,e[31]=w,e[32]=V,e[33]=d,e[34]=F,e[35]=i,e[36]=s,e[37]=re,e[38]=Y):(re=e[37],Y=e[38]),qe(re,Y);const P=F[d]??ct;let Z;if(e[39]!==P||e[40]!==w||e[41]!==i){let h;e[43]!==P?(h=I=>({columns:P[I.name]??Ye,name:I.name,tier:"shard"}),e[43]=P,e[44]=h):h=e[44];const x=(i??[]).map(h);let N;e[45]!==P?(N=I=>({columns:P[I.name]??Ye,name:I.name,tier:"global"}),e[45]=P,e[46]=N):N=e[46];const k=(w??[]).map(N);Z=[...x,...k],e[39]=P,e[40]=w,e[41]=i,e[42]=Z}else Z=e[42];const b=Z;let ee;if(e[47]!==o||e[48]!==i){const h=o.trim().toLowerCase();ee=(i??[]).filter(x=>x.name.toLowerCase().includes(h)),e[47]=o,e[48]=i,e[49]=ee}else ee=e[49];const de=ee;let xe;if(e[50]!==w||e[51]!==o){const h=o.trim().toLowerCase();xe=(w??[]).filter(x=>x.name.toLowerCase().includes(h)),e[50]=w,e[51]=o,e[52]=xe}else xe=e[52];const Te=xe;let ve;return e[53]!==G||e[54]!==b||e[55]!==f||e[56]!==T||e[57]!==Te||e[58]!==de||e[59]!==J||e[60]!==B||e[61]!==W||e[62]!==w||e[63]!==$||e[64]!==j||e[65]!==r||e[66]!==E||e[67]!==g||e[68]!==o||e[69]!==i||e[70]!==ne||e[71]!==fe||e[72]!==s?(ve={columns:G,diagramTables:b,error:f,expanded:T,filteredGlobalTables:Te,filteredTables:de,globalColumns:J,globalError:B,globalExpanded:W,globalTables:w,indexes:$,refresh:j,setShardKey:r,setTableFilter:u,setView:c,shardColumnsError:E,shardKey:g,tableFilter:o,tables:i,toggle:ne,toggleGlobal:fe,view:s},e[53]=G,e[54]=b,e[55]=f,e[56]=T,e[57]=Te,e[58]=de,e[59]=J,e[60]=B,e[61]=W,e[62]=w,e[63]=$,e[64]=j,e[65]=r,e[66]=E,e[67]=g,e[68]=o,e[69]=i,e[70]=ne,e[71]=fe,e[72]=s,e[73]=ve):ve=e[73],ve};function ut(n){const{columns:e,refs:m,table:a}=n;return[a,e.map(t=>{const s=m[t];return s===void 0?{name:t,optional:!1,type:""}:{name:t,optional:!1,ref:s,type:"id"}})]}function ft(n){return n.name}function ht(n){return n.name}const pt="/__lunora/schema-edit",gt=async n=>{const e=await fetch(pt,{body:JSON.stringify(n),headers:{"Content-Type":"application/json"},method:"POST"}),m=await e.json();return m.needsMigration===!0?{kind:"needs-migration",message:m.message??"This edit needs a migration."}:e.ok&&m.tables!==void 0?{diagnostics:m.diagnostics??[],kind:"ok",tables:m.tables}:{kind:"error",message:m.error??`schema edit failed (${String(e.status)})`}},bt=n=>{const e=we(32),{hasTables:m,mode:a,onAddColumn:t,onAddIndex:s,onAddTable:c,onDestructive:d}=n,r=Oe(),g=a==="addTable"?"default":"outline";let o;e[0]!==r?(o=r("Add table"),e[0]=r,e[1]=o):o=e[1];let u;e[2]!==c||e[3]!==g||e[4]!==o?(u=l(ye,{"data-testid":"sc-editor-add-table",onClick:c,size:"xs",type:"button",variant:g,children:o}),e[2]=c,e[3]=g,e[4]=o,e[5]=u):u=e[5];const i=!m,v=a==="addColumn"?"default":"outline";let f;e[6]!==r?(f=r("Add column"),e[6]=r,e[7]=f):f=e[7];let O;e[8]!==t||e[9]!==i||e[10]!==v||e[11]!==f?(O=l(ye,{"data-testid":"sc-editor-add-column",disabled:i,onClick:t,size:"xs",type:"button",variant:v,children:f}),e[8]=t,e[9]=i,e[10]=v,e[11]=f,e[12]=O):O=e[12];const S=!m,G=a==="addIndex"?"default":"outline";let y;e[13]!==r?(y=r("Add index"),e[13]=r,e[14]=y):y=e[14];let L;e[15]!==s||e[16]!==y||e[17]!==S||e[18]!==G?(L=l(ye,{"data-testid":"sc-editor-add-index",disabled:S,onClick:s,size:"xs",type:"button",variant:G,children:y}),e[15]=s,e[16]=y,e[17]=S,e[18]=G,e[19]=L):L=e[19];const $=!m,z=a==="destructive"?"default":"ghost";let T;e[20]!==r?(T=r("Rename / drop / change type…"),e[20]=r,e[21]=T):T=e[21];let C;e[22]!==d||e[23]!==$||e[24]!==z||e[25]!==T?(C=l(ye,{"data-testid":"sc-editor-destructive",disabled:$,onClick:d,size:"xs",type:"button",variant:z,children:T}),e[22]=d,e[23]=$,e[24]=z,e[25]=T,e[26]=C):C=e[26];let A;return e[27]!==L||e[28]!==C||e[29]!==u||e[30]!==O?(A=p("div",{className:"flex flex-wrap gap-2",children:[u,O,L,C]}),e[27]=L,e[28]=C,e[29]=u,e[30]=O,e[31]=A):A=e[31],A},xt=n=>{const e=we(28),{onOpenMigrations:m,result:a}=n,t=Oe();if(a===null){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ve,{}),e[0]=o):o=e[0],o}if(a.kind==="error"){let o;return e[1]!==a.message?(o=l("p",{className:"mt-3 text-sm text-destructive","data-testid":"sc-editor-error",role:"alert",children:a.message}),e[1]=a.message,e[2]=o):o=e[2],o}if(a.kind==="needs-migration"){let o;e[3]!==a.message||e[4]!==t?(o=a.message===""?t("This edit changes stored data and must go through a migration. Review the migration before applying."):a.message,e[3]=a.message,e[4]=t,e[5]=o):o=e[5];let u;e[6]!==o?(u=l("p",{className:"text-sm text-warning",role:"alert",children:o}),e[6]=o,e[7]=u):u=e[7];let i;e[8]!==t?(i=t("Open Migrations"),e[8]=t,e[9]=i):i=e[9];let v;e[10]!==m||e[11]!==i?(v=l(ye,{className:"self-start","data-testid":"sc-editor-open-migrations",onClick:m,size:"xs",type:"button",variant:"outline",children:i}),e[10]=m,e[11]=i,e[12]=v):v=e[12];let f;return e[13]!==u||e[14]!==v?(f=p("div",{className:"mt-3 flex flex-col gap-2","data-testid":"sc-editor-needs-migration",children:[u,v]}),e[13]=u,e[14]=v,e[15]=f):f=e[15],f}if(a.diagnostics.length===0){let o;return e[16]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ve,{}),e[16]=o):o=e[16],o}let s;e[17]!==t?(s=t("Codegen reported diagnostics:"),e[17]=t,e[18]=s):s=e[18];let c;e[19]!==s?(c=l("p",{className:"text-sm text-destructive",role:"alert",children:s}),e[19]=s,e[20]=c):c=e[20];let d;e[21]!==a.diagnostics?(d=a.diagnostics.map(vt),e[21]=a.diagnostics,e[22]=d):d=e[22];let r;e[23]!==d?(r=l("ul",{className:"flex flex-col gap-0.5",children:d}),e[23]=d,e[24]=r):r=e[24];let g;return e[25]!==c||e[26]!==r?(g=p("div",{className:"mt-3 flex flex-col gap-1","data-testid":"sc-editor-diagnostics",children:[c,r]}),e[25]=c,e[26]=r,e[27]=g):g=e[27],g};function vt(n){return l("li",{className:"font-mono text-[11px] text-destructive",children:n},n)}const yt=[{label:"string",validator:"v.string()"},{label:"number",validator:"v.number()"},{label:"boolean",validator:"v.boolean()"},{label:"bigint",validator:"v.bigint()"},{label:"bytes",validator:"v.bytes()"},{label:"any",validator:"v.any()"}],Ct="v.string()",Nt=n=>n.split(",").map(e=>e.trim()).filter(e=>e!==""),Tt=n=>{const e=we(83),{onApplied:m,tableNames:a}=n,t=Oe(),s=nt(),[c,d]=_(null),[r,g]=_(!1),[o,u]=_(null),[i,v]=_(""),[f,O]=_(""),[S,G]=_(Ct),[y,L]=_(a[0]??""),[$,z]=_(""),[T,C]=_(""),[A,F]=_(!1);let pe;e[0]===Symbol.for("react.memo_cache_sentinel")?(pe=()=>{d(null),v(""),O(""),z(""),C(""),F(!1)},e[0]=pe):pe=e[0];const te=pe;let E;e[1]!==m?(E=async q=>{g(!0),u(null);try{const H=await gt(q);u(H),H.kind==="ok"&&(m(H.tables),te())}catch(H){const Se=H;u({kind:"error",message:Se instanceof Error?Se.message:String(Se)})}g(!1)},e[1]=m,e[2]=E):E=e[2];const M=E;let w;e[3]!==M||e[4]!==i?(w=()=>{Ce(M({kind:"addTable",table:i.trim()}))},e[3]=M,e[4]=i,e[5]=w):w=e[5];const ge=w;let B;e[6]!==f||e[7]!==M||e[8]!==y||e[9]!==S?(B=()=>{Ce(M({column:f.trim(),kind:"addOptionalColumn",table:y,validator:S}))},e[6]=f,e[7]=M,e[8]=y,e[9]=S,e[10]=B):B=e[10];const ce=B;let le;e[11]!==T||e[12]!==$||e[13]!==M||e[14]!==y||e[15]!==A?(le=()=>{Ce(M({fields:Nt(T),kind:"addIndex",name:$.trim(),table:y,unique:A}))},e[11]=T,e[12]=$,e[13]=M,e[14]=y,e[15]=A,e[16]=le):le=e[16];const J=le;let Ne;e[17]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>{u(null),d("addTable")},e[17]=Ne):Ne=e[17];const W=Ne;let me;e[18]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{u(null),d("addColumn")},e[18]=me):me=e[18];const be=me;let D;e[19]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{u(null),d("addIndex")},e[19]=D):D=e[19];const j=D;let se;e[20]!==t?(se=()=>{d("destructive"),u({kind:"needs-migration",message:t("This edit changes stored data and must go through a migration. Review the migration before applying.")})},e[20]=t,e[21]=se):se=e[21];const ue=se;let R;e[22]===Symbol.for("react.memo_cache_sentinel")?(R=q=>{v(q.target.value)},e[22]=R):R=e[22];const ae=R;let K;e[23]===Symbol.for("react.memo_cache_sentinel")?(K=q=>{O(q.target.value)},e[23]=K):K=e[23];const ne=K;let oe;e[24]===Symbol.for("react.memo_cache_sentinel")?(oe=q=>{G(q.target.value)},e[24]=oe):oe=e[24];const fe=oe;let X;e[25]===Symbol.for("react.memo_cache_sentinel")?(X=q=>{L(q.target.value)},e[25]=X):X=e[25];const Q=X;let U;e[26]===Symbol.for("react.memo_cache_sentinel")?(U=q=>{z(q.target.value)},e[26]=U):U=e[26];const ie=U;let V;e[27]===Symbol.for("react.memo_cache_sentinel")?(V=q=>{C(q.target.value)},e[27]=V):V=e[27];const re=V;let Y;e[28]===Symbol.for("react.memo_cache_sentinel")?(Y=q=>{F(q.target.checked)},e[28]=Y):Y=e[28];const P=Y;let Z;e[29]!==s?(Z=()=>{Ce(s({to:"/migrations"}))},e[29]=s,e[30]=Z):Z=e[30];const b=Z;let ee;e[31]!==t?(ee=t("Edit schema"),e[31]=t,e[32]=ee):ee=e[32];let de;e[33]!==ee?(de=l(Ge,{children:ee}),e[33]=ee,e[34]=de):de=e[34];let xe;e[35]!==t?(xe=t("Adds a table, column, or index to lunora/schema.ts and reruns codegen."),e[35]=t,e[36]=xe):xe=e[36];let Te;e[37]!==xe?(Te=l(ze,{children:xe}),e[37]=xe,e[38]=Te):Te=e[38];let ve;e[39]!==de||e[40]!==Te?(ve=p(Be,{children:[de,Te]}),e[39]=de,e[40]=Te,e[41]=ve):ve=e[41];const h=a.length>0;let x;e[42]!==c||e[43]!==ue||e[44]!==h?(x=l(bt,{hasTables:h,mode:c,onAddColumn:be,onAddIndex:j,onAddTable:W,onDestructive:ue}),e[42]=c,e[43]=ue,e[44]=h,e[45]=x):x=e[45];let N;e[46]!==r||e[47]!==c||e[48]!==ge||e[49]!==t||e[50]!==i?(N=c==="addTable"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-table-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-table-name",children:t("Table name")}),l(ke,{"data-testid":"sc-editor-table-name",id:"sc-editor-table-name",onChange:ae,value:i})]}),l(ye,{"data-testid":"sc-editor-table-apply",disabled:r||i.trim()==="",onClick:ge,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[46]=r,e[47]=c,e[48]=ge,e[49]=t,e[50]=i,e[51]=N):N=e[51];let k;e[52]!==r||e[53]!==f||e[54]!==c||e[55]!==ce||e[56]!==t||e[57]!==a||e[58]!==y||e[59]!==S?(k=c==="addColumn"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-column-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-table",id:"sc-editor-column-table",onChange:Q,value:y,children:a.map(St)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-name",children:t("Column name")}),l(ke,{"data-testid":"sc-editor-column-name",id:"sc-editor-column-name",onChange:ne,value:f})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-column-type",children:t("Column type")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-type",id:"sc-editor-column-type",onChange:fe,value:S,children:yt.map(wt)})]}),l("span",{className:"text-[11px] text-muted-foreground",children:t("Optional")}),l(ye,{"data-testid":"sc-editor-column-apply",disabled:r||f.trim()===""||y==="",onClick:ce,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[52]=r,e[53]=f,e[54]=c,e[55]=ce,e[56]=t,e[57]=a,e[58]=y,e[59]=S,e[60]=k):k=e[60];let I;e[61]!==r||e[62]!==T||e[63]!==$||e[64]!==c||e[65]!==J||e[66]!==t||e[67]!==a||e[68]!==y||e[69]!==A?(I=c==="addIndex"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-index-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-index-table",id:"sc-editor-index-table",onChange:Q,value:y,children:a.map(_t)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-name",children:t("Index name")}),l(ke,{"data-testid":"sc-editor-index-name",id:"sc-editor-index-name",onChange:ie,value:$})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(Ee,{htmlFor:"sc-editor-index-fields",children:t("Index fields (comma-separated)")}),l(ke,{"data-testid":"sc-editor-index-fields",id:"sc-editor-index-fields",onChange:re,value:T})]}),p(Ee,{className:"flex items-center gap-1 text-xs",htmlFor:"sc-editor-index-unique",children:[l("input",{checked:A,"data-testid":"sc-editor-index-unique",id:"sc-editor-index-unique",onChange:P,type:"checkbox"}),l("span",{className:"text-muted-foreground",children:t("Unique")})]}),l(ye,{"data-testid":"sc-editor-index-apply",disabled:r||$.trim()===""||T.trim()==="",onClick:J,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ye,{onClick:te,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[61]=r,e[62]=T,e[63]=$,e[64]=c,e[65]=J,e[66]=t,e[67]=a,e[68]=y,e[69]=A,e[70]=I):I=e[70];let he;e[71]!==b||e[72]!==o?(he=l(xt,{onOpenMigrations:b,result:o}),e[71]=b,e[72]=o,e[73]=he):he=e[73];let _e;e[74]!==x||e[75]!==N||e[76]!==k||e[77]!==I||e[78]!==he?(_e=p(De,{children:[x,N,k,I,he]}),e[74]=x,e[75]=N,e[76]=k,e[77]=I,e[78]=he,e[79]=_e):_e=e[79];let Ie;return e[80]!==ve||e[81]!==_e?(Ie=p(je,{"data-testid":"sc-editor",size:"sm",children:[ve,_e]}),e[80]=ve,e[81]=_e,e[82]=Ie):Ie=e[82],Ie};function St(n){return l("option",{value:n,children:n},n)}function wt(n){return l("option",{value:n.validator,children:n.label},n.validator)}function _t(n){return l("option",{value:n,children:n},n)}const He=[],Et=n=>{const e=we(5),{open:m}=n,a=m&&"rotate-90";let t;e[0]!==a?(t=Qe("size-3.5 shrink-0 text-muted-foreground transition-transform duration-150",a),e[0]=a,e[1]=t):t=e[1];let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=l("path",{d:"m9 6 6 6-6 6"}),e[2]=s):s=e[2];let c;return e[3]!==t?(c=l("svg",{"aria-hidden":"true",className:t,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:s}),e[3]=t,e[4]=c):c=e[4],c},Je=n=>{const e=we(20),{children:m,expanded:a,name:t,onToggle:s,rowCount:c,rowTestId:d,toggleTestId:r}=n;let g;e[0]!==a?(g=l(Et,{open:a}),e[0]=a,e[1]=g):g=e[1];let o;e[2]!==t?(o=l("span",{className:"truncate font-mono text-xs text-foreground",title:t,children:t}),e[2]=t,e[3]=o):o=e[3];let u;e[4]!==c?(u=p("span",{className:"ms-auto shrink-0 text-xs text-muted-foreground tabular-nums",children:["(",c,")"]}),e[4]=c,e[5]=u):u=e[5];let i;e[6]!==a||e[7]!==s||e[8]!==g||e[9]!==o||e[10]!==u||e[11]!==r?(i=p("button",{"aria-expanded":a,className:"flex w-full items-center gap-2 px-3 py-2 text-start transition-colors hover:bg-muted/50 aria-expanded:bg-muted/40","data-testid":r,onClick:s,type:"button",children:[g,o," ",u]}),e[6]=a,e[7]=s,e[8]=g,e[9]=o,e[10]=u,e[11]=r,e[12]=i):i=e[12];let v;e[13]!==m||e[14]!==a?(v=a&&l("div",{className:"px-3 pb-3 ps-8",children:m}),e[13]=m,e[14]=a,e[15]=v):v=e[15];let f;return e[16]!==d||e[17]!==i||e[18]!==v?(f=p("li",{className:"border-t border-border/60 first:border-t-0","data-testid":d,children:[i,v]}),e[16]=d,e[17]=i,e[18]=v,e[19]=f):f=e[19],f},We=n=>{const e=we(5),{columns:m,testId:a}=n;let t;e[0]!==m?(t=m.map(kt),e[0]=m,e[1]=t):t=e[1];let s;return e[2]!==t||e[3]!==a?(s=l("ul",{className:"flex flex-wrap gap-1.5 pt-1","data-testid":a,children:t}),e[2]=t,e[3]=a,e[4]=s):s=e[4],s},It=n=>{const e=we(10),{heading:m,indexes:a,testId:t}=n;let s;e[0]!==m?(s=l("p",{className:"mb-1.5 font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:m}),e[0]=m,e[1]=s):s=e[1];let c;e[2]!==a?(c=a.map(At),e[2]=a,e[3]=c):c=e[3];let d;e[4]!==c||e[5]!==t?(d=l("ul",{className:"flex flex-col gap-1","data-testid":t,children:c}),e[4]=c,e[5]=t,e[6]=d):d=e[6];let r;return e[7]!==s||e[8]!==d?(r=p("div",{className:"pt-3",children:[s,d]}),e[7]=s,e[8]=d,e[9]=r):r=e[9],r},Xe=n=>Qe("border-b-2 px-3 py-2 font-mono text-[11px] tracking-widest uppercase outline-none transition-colors",n?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),Qt=n=>{const e=we(85),{initialShardKey:m,initialTable:a,schemaEditable:t}=n,s=Oe();let c;e[0]!==m||e[1]!==a?(c={initialShardKey:m,initialTable:a},e[0]=m,e[1]=a,e[2]=c):c=e[2];const{columns:d,diagramTables:r,error:g,expanded:o,filteredGlobalTables:u,filteredTables:i,globalColumns:v,globalError:f,globalExpanded:O,globalTables:S,indexes:G,refresh:y,setShardKey:L,setTableFilter:$,setView:z,shardColumnsError:T,shardKey:C,tableFilter:A,tables:F,toggle:pe,toggleGlobal:te,view:E}=mt(c);let M;e[3]!==z?(M=()=>{z("list")},e[3]=z,e[4]=M):M=e[4];const w=M;let ge;e[5]!==z?(ge=()=>{z("graph")},e[5]=z,e[6]=ge):ge=e[6];const B=ge;let ce;e[7]!==$?(ce=b=>{$(b.target.value)},e[7]=$,e[8]=ce):ce=e[8];const le=ce;let J;e[9]!==y||e[10]!==C?(J=b=>{Ce(y(C))},e[9]=y,e[10]=C,e[11]=J):J=e[11];const Ne=J;let W;e[12]!==F?(W=F??[],e[12]=F,e[13]=W):W=e[13];let me;e[14]!==W?(me=W.map($t),e[14]=W,e[15]=me):me=e[15];const be=me;let D;e[16]!==L||e[17]!==C?(D=l(Ze,{onChange:L,testId:"sc-shard-input",value:C}),e[16]=L,e[17]=C,e[18]=D):D=e[18];let j;e[19]!==s?(j=s("Schema view"),e[19]=s,e[20]=j):j=e[20];const se=E==="graph",ue=E==="graph";let R;e[21]!==ue?(R=Xe(ue),e[21]=ue,e[22]=R):R=e[22];let ae;e[23]!==s?(ae=s("Graph"),e[23]=s,e[24]=ae):ae=e[24];let K;e[25]!==B||e[26]!==se||e[27]!==R||e[28]!==ae?(K=l("button",{"aria-selected":se,className:R,"data-testid":"sc-view-graph",onClick:B,role:"tab",type:"button",children:ae}),e[25]=B,e[26]=se,e[27]=R,e[28]=ae,e[29]=K):K=e[29];const ne=E==="list",oe=E==="list";let fe;e[30]!==oe?(fe=Xe(oe),e[30]=oe,e[31]=fe):fe=e[31];let X;e[32]!==s?(X=s("Table list"),e[32]=s,e[33]=X):X=e[33];let Q;e[34]!==w||e[35]!==ne||e[36]!==fe||e[37]!==X?(Q=l("button",{"aria-selected":ne,className:fe,"data-testid":"sc-view-list",onClick:w,role:"tab",type:"button",children:X}),e[34]=w,e[35]=ne,e[36]=fe,e[37]=X,e[38]=Q):Q=e[38];let U;e[39]!==K||e[40]!==Q||e[41]!==j?(U=p("div",{"aria-label":j,className:"flex items-center gap-1","data-testid":"sc-view-toggle",role:"tablist",children:[K,Q]}),e[39]=K,e[40]=Q,e[41]=j,e[42]=U):U=e[42];let ie;e[43]!==U||e[44]!==D?(ie=p("div",{className:"flex flex-wrap items-center gap-3",children:[D,U]}),e[43]=U,e[44]=D,e[45]=ie):ie=e[45];let V;e[46]!==Ne||e[47]!==t||e[48]!==be?(V=t===!0&&l(Tt,{onApplied:Ne,tableNames:be}),e[46]=Ne,e[47]=t,e[48]=be,e[49]=V):V=e[49];let re;e[50]!==le||e[51]!==s||e[52]!==A||e[53]!==E?(re=E==="list"&&l(ke,{"aria-label":s("Filter tables"),className:"h-8 max-w-xs","data-testid":"sc-filter",onChange:le,placeholder:s("Filter tables"),value:A}),e[50]=le,e[51]=s,e[52]=A,e[53]=E,e[54]=re):re=e[54];let Y;e[55]!==r||e[56]!==g||e[57]!==f||e[58]!==T||e[59]!==C||e[60]!==E?(Y=E==="graph"&&p("div",{className:"flex flex-col gap-2","data-testid":"sc-graph-view",children:[g!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:g}),f!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:f}),l(at,{columnsError:T[C]===!0,tables:r,testIdPrefix:"sc-graph"})]}),e[55]=r,e[56]=g,e[57]=f,e[58]=T,e[59]=C,e[60]=E,e[61]=Y):Y=e[61];let P;e[62]!==d||e[63]!==g||e[64]!==o||e[65]!==u||e[66]!==i||e[67]!==v||e[68]!==f||e[69]!==O||e[70]!==S||e[71]!==G||e[72]!==C||e[73]!==s||e[74]!==F||e[75]!==pe||e[76]!==te||e[77]!==E?(P=E==="list"&&p("div",{className:"flex flex-col gap-4",children:[p(je,{"data-testid":"sc-shard-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Ke,{tier:"shard"}),l(Ge,{children:s("Shard tables")}),F!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:i.length})]}),l(ze,{children:Pe.shard.hint})]}),p(De,{children:[g!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:g}),F!==null&&F.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-empty",children:s("No tables in this shard.")}),F!==null&&F.length>0&&i.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-no-match",children:s("No tables match your filter.")}),i.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-table-list",children:i.map(b=>{const ee=`${C}:${b.name}`,de=G[ee]??[];return p(Je,{expanded:o===b.name,name:b.name,onToggle:()=>{Ce(pe(b.name))},rowCount:b.rowCount,rowTestId:`sc-table-${b.name}`,toggleTestId:`sc-toggle-${b.name}`,children:[l(We,{columns:d[ee]??He,testId:`sc-columns-${b.name}`}),de.length>0&&l(It,{heading:s("Indexes"),indexes:de,testId:`sc-indexes-${b.name}`})]},b.name)})})]})]}),p(je,{"data-testid":"sc-global-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Ke,{tier:"global"}),l(Ge,{children:s("Global tables (D1)")}),S!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:u.length})]}),l(ze,{children:Pe.global.hint})]}),p(De,{children:[f!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:f}),S!==null&&S.length===0&&l(et,{description:Pe.global.hint,testId:"sc-global-empty",title:s("No global tables.")}),S!==null&&S.length>0&&u.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-global-no-match",children:s("No tables match your filter.")}),u.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-global-table-list",children:u.map(b=>l(Je,{expanded:O===b.name,name:b.name,onToggle:()=>{Ce(te(b.name))},rowCount:b.rowCount,rowTestId:`sc-global-table-${b.name}`,toggleTestId:`sc-global-toggle-${b.name}`,children:l(We,{columns:v[b.name]??He,testId:`sc-global-columns-${b.name}`})},b.name))})]})]})]}),e[62]=d,e[63]=g,e[64]=o,e[65]=u,e[66]=i,e[67]=v,e[68]=f,e[69]=O,e[70]=S,e[71]=G,e[72]=C,e[73]=s,e[74]=F,e[75]=pe,e[76]=te,e[77]=E,e[78]=P):P=e[78];let Z;return e[79]!==ie||e[80]!==V||e[81]!==re||e[82]!==Y||e[83]!==P?(Z=p("div",{className:"flex flex-col gap-4","data-testid":"lunora-schema",children:[ie,V,re,Y,P]}),e[79]=ie,e[80]=V,e[81]=re,e[82]=Y,e[83]=P,e[84]=Z):Z=e[84],Z};function kt(n){return l("li",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:n},n)}function At(n){return p("li",{className:"flex flex-wrap items-center gap-1.5 text-xs",children:[l("span",{className:"font-mono",children:n.name}),l(Fe,{variant:"outline",children:n.type}),n.unique===!0&&l(Fe,{variant:"secondary",children:"unique"}),l("span",{className:"text-muted-foreground",children:n.fields.join(", ")})]},`${n.type}:${n.name}`)}function $t(n){return n.name}export{Qt as SchemaViewer};
@@ -1 +1 @@
1
- import{c as F}from"react/compiler-runtime";import{useNavigate as pe}from"@tanstack/react-router";import{Background as ge,Controls as be,ReactFlow as xe,Handle as le,Position as oe}from"@xyflow/react";import{useState as re,useRef as Ne}from"react";import{D as ve}from"../packem_shared/diagram-export-panel-miFPsocM.mjs";import{B as me}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as Ee,a as ke}from"../packem_shared/card-By2O8ULa.mjs";import{E as ae}from"../packem_shared/empty-state-D7jEML_T.mjs";import{S as ie}from"../packem_shared/skeleton-DX1gfixl.mjs";import{b as U,e as $,T as we,c as V,a as Se,d as Ae}from"../packem_shared/table-D0SBiDu-.mjs";import{u as _e}from"../packem_shared/use-admin-spec-Cokw73Ks.mjs";import{u as ye}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{f as Le}from"../packem_shared/internal-BT5tH08j.mjs";import{c as De}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as x,jsx as o,Fragment as Ce}from"react/jsx-runtime";const he=["call","schedule","read","write","enqueue","publish","subscribe","start","trigger","invoke"],$e=new Set(["enqueue","publish","schedule","start","subscribe","trigger"]),ce={cron:1,function:2,http:0,queue:4,service:7,table:6,topic:3,workflow:5},Ie={stroke:"var(--muted-foreground)"},Te={fill:"var(--muted-foreground)",fontSize:10},Oe={fill:"var(--background)"},W="",X=260,Be=120,de=44,ee=40,ue=12,te=16,Ge=n=>{if(typeof n!="object"||n===null)return;const e=n;return["edges","nodes","modules","unresolved"].every(a=>Array.isArray(e[a]))?e:void 0},He={cron:()=>({to:"/schedule"}),function:()=>({to:"/functions"}),http:()=>({to:"/api"}),queue:()=>({to:"/queues"}),service:()=>({to:"/functions"}),table:n=>({search:{table:n.name},to:"/data"}),topic:()=>({to:"/queues"}),workflow:()=>({to:"/workflows"})},Me=n=>He[n.kind](n),R=n=>n.module??W,Pe=(n,e,a)=>{const t=new Set;for(const r of n.nodes)(e===void 0||R(r)===e)&&t.add(r.id);if(e===void 0)return t;const l=new Set(t);for(const r of n.edges)a.has(r.kind)&&(t.has(r.from)&&l.add(r.to),t.has(r.to)&&l.add(r.from));return l},Re=(n,e,a,t)=>{const l=`lane:${n}`;return[{data:{label:e},id:l,position:{x:a*(X+Be),y:0},selectable:!1,style:{height:de+t.length*(ee+ue)+te,width:X},type:"lane"},...t.map((r,u)=>({className:"flex cursor-pointer items-center truncate rounded-md border border-border bg-card px-2 text-xs text-foreground hover:border-ring",data:{label:`${r.detail??r.kind} · ${r.name}`,link:Me(r)},extent:"parent",id:r.id,parentId:l,position:{x:te,y:de+u*(ee+ue)},style:{height:ee,width:X-te*2},type:"member"}))]},Fe=(n,e)=>{const a=Pe(n,e.lane,e.kinds),t=new Map;for(const s of n.nodes)a.has(s.id)&&t.set(R(s),[...t.get(R(s))??[],s]);const l=[...n.modules.map(s=>({label:s.installed===!0?`${s.name} · ${e.componentLabel}`:s.name,lane:s.name})),{label:e.appLaneLabel,lane:W}],r=[];let u=0;for(const{label:s,lane:f}of l){const d=(t.get(f)??[]).toSorted((c,b)=>ce[c.kind]-ce[b.kind]||c.name.localeCompare(b.name));d.length>0&&(r.push(...Re(f,s,u,d)),u+=1)}const h=[];for(const s of n.edges)e.kinds.has(s.kind)&&a.has(s.from)&&a.has(s.to)&&h.push({animated:$e.has(s.kind),id:`${s.from}|${s.kind}|${s.to}`,label:s.kind,labelBgStyle:Oe,labelStyle:Te,source:s.from,style:Ie,target:s.to,type:"smoothstep"});return{edges:h,nodes:r}},se="*",qe=n=>{const e=F(2),{data:a}=n,t=String(a.label);let l;return e[0]!==t?(l=o("div",{className:"size-full rounded-lg border border-dashed border-border bg-background/60 px-3 py-2 text-xs font-medium text-muted-foreground",children:t}),e[0]=t,e[1]=l):l=e[1],l},fe={opacity:0},je=n=>{const e=F(10),{data:a}=n,t=pe(),{label:l,link:r}=a;let u;e[0]!==r||e[1]!==t?(u=()=>{Le(t(r))},e[0]=r,e[1]=t,e[2]=u):u=e[2];const h=u;let s;e[3]===Symbol.for("react.memo_cache_sentinel")?(s=o(le,{isConnectable:!1,position:oe.Left,style:fe,type:"target"}),e[3]=s):s=e[3];let f;e[4]!==l||e[5]!==h?(f=o("button",{className:"size-full cursor-pointer truncate rounded-md text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",onClick:h,type:"button",children:l}),e[4]=l,e[5]=h,e[6]=f):f=e[6];let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d=o(le,{isConnectable:!1,position:oe.Right,style:fe,type:"source"}),e[7]=d):d=e[7];let c;return e[8]!==f?(c=x(Ce,{children:[s,f,d]}),e[8]=f,e[9]=c):c=e[9],c},Ke={lane:qe,member:je},ze=n=>{const e=Ge(n);return e===void 0?{kind:"error",message:"the response is not an architecture manifest"}:e.modules.length===0?{kind:"empty"}:{kind:"ready",spec:e}},Ye=n=>{const e=F(54),{manifest:a}=n,t=ne();let l,r,u,h,s,f,d,c,b,i;if(e[0]!==a.modules||e[1]!==a.nodes||e[2]!==t){const P=new Map;for(const g of a.nodes)g.kind==="function"&&P.set(R(g),(P.get(R(g))??0)+1);const I=g=>P.get(g)??0;s=I(W),h=Ee,i="overflow-hidden py-0",u=ke,b="px-0",r=we,d="architecture-catalog";let y;e[13]!==t?(y=t("Module"),e[13]=t,e[14]=y):y=e[14];let L;e[15]!==y?(L=o(V,{children:y}),e[15]=y,e[16]=L):L=e[16];let D;e[17]!==t?(D=t("Description"),e[17]=t,e[18]=D):D=e[18];let C;e[19]!==D?(C=o(V,{children:D}),e[19]=D,e[20]=C):C=e[20];let N;e[21]!==t?(N=t("Owned tables"),e[21]=t,e[22]=N):N=e[22];let v;e[23]!==N?(v=o(V,{children:N}),e[23]=N,e[24]=v):v=e[24];let E;e[25]!==t?(E=t("Functions"),e[25]=t,e[26]=E):E=e[26];let k;e[27]!==E?(k=o(V,{children:E}),e[27]=E,e[28]=k):k=e[28],e[29]!==v||e[30]!==k||e[31]!==L||e[32]!==C?(c=o(Se,{children:x(U,{children:[L,C,v,k]})}),e[29]=v,e[30]=k,e[31]=L,e[32]=C,e[33]=c):c=e[33],l=Ae,f=a.modules.map(g=>x(U,{"data-testid":`architecture-module-${g.name}`,children:[x($,{className:"font-mono text-xs",children:[g.name,g.installed===!0&&o(me,{className:"ml-2","data-testid":`architecture-component-${g.name}`,variant:"outline",children:t("Component")})]}),o($,{className:"text-xs text-muted-foreground",children:g.description??(g.installed===!0?t("Installed component"):"—")}),o($,{className:"font-mono text-xs text-muted-foreground",children:g.tables.length===0?"—":g.tables.join(", ")}),o($,{className:"text-xs",children:I(g.name)})]},g.name)),e[0]=a.modules,e[1]=a.nodes,e[2]=t,e[3]=l,e[4]=r,e[5]=u,e[6]=h,e[7]=s,e[8]=f,e[9]=d,e[10]=c,e[11]=b,e[12]=i}else l=e[3],r=e[4],u=e[5],h=e[6],s=e[7],f=e[8],d=e[9],c=e[10],b=e[11],i=e[12];let m;e[34]!==s||e[35]!==t?(m=s>0&&x(U,{"data-testid":"architecture-module-app",children:[o($,{className:"text-xs italic text-muted-foreground",children:t("Outside any module")}),o($,{className:"text-xs text-muted-foreground",children:"—"}),o($,{className:"text-xs text-muted-foreground",children:"—"}),o($,{className:"text-xs",children:s})]}),e[34]=s,e[35]=t,e[36]=m):m=e[36];let p;e[37]!==l||e[38]!==f||e[39]!==m?(p=x(l,{children:[f,m]}),e[37]=l,e[38]=f,e[39]=m,e[40]=p):p=e[40];let S;e[41]!==r||e[42]!==d||e[43]!==c||e[44]!==p?(S=x(r,{"data-testid":d,children:[c,p]}),e[41]=r,e[42]=d,e[43]=c,e[44]=p,e[45]=S):S=e[45];let A;e[46]!==u||e[47]!==b||e[48]!==S?(A=o(u,{className:b,children:S}),e[46]=u,e[47]=b,e[48]=S,e[49]=A):A=e[49];let _;return e[50]!==h||e[51]!==i||e[52]!==A?(_=o(h,{className:i,children:A}),e[50]=h,e[51]=i,e[52]=A,e[53]=_):_=e[53],_},Ve=n=>{const e=F(52),{manifest:a}=n,t=ne(),[l,r]=re(se),[u,h]=re(We);let s;e[0]!==a.edges?(s=w=>a.edges.some(J=>J.kind===w),e[0]=a.edges,e[1]=s):s=e[1];const f=he.filter(s);let d;e[2]!==t?(d=t("Outside any module"),e[2]=t,e[3]=d):d=e[3];const c=d;let b;e[4]!==t?(b=t("Component"),e[4]=t,e[5]=b):b=e[5];const i=b;let m;e[6]!==c||e[7]!==i||e[8]!==u||e[9]!==l||e[10]!==a?(m=Fe(a,{appLaneLabel:c,componentLabel:i,kinds:u,...l===se?{}:{lane:l}}),e[6]=c,e[7]=i,e[8]=u,e[9]=l,e[10]=a,e[11]=m):m=e[11];const{edges:p,nodes:S}=m,A=Ne(null);let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=w=>{r(w.target.value)},e[12]=_):_=e[12];const P=_;let I;e[13]===Symbol.for("react.memo_cache_sentinel")?(I=w=>{h(J=>{const Q=new Set(J);return Q.delete(w)||Q.add(w),Q})},e[13]=I):I=e[13];const y=I,L="flex flex-col gap-2",D="architecture-diagram",C="flex flex-wrap items-center gap-2";let N;e[14]!==t?(N=t("Module"),e[14]=t,e[15]=N):N=e[15];let v;e[16]!==t?(v=t("All modules"),e[16]=t,e[17]=v):v=e[17];let E;e[18]!==v?(E=o("option",{value:se,children:v}),e[18]=v,e[19]=E):E=e[19];let k;e[20]!==a.modules?(k=a.modules.map(Ze),e[20]=a.modules,e[21]=k):k=e[21];let g;e[22]!==t?(g=t("Outside any module"),e[22]=t,e[23]=g):g=e[23];let T;e[24]!==g?(T=o("option",{value:W,children:g}),e[24]=g,e[25]=T):T=e[25];let O;e[26]!==l||e[27]!==N||e[28]!==E||e[29]!==k||e[30]!==T?(O=x("select",{"aria-label":N,className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"architecture-module-filter",onChange:P,value:l,children:[E,k,T]}),e[26]=l,e[27]=N,e[28]=E,e[29]=k,e[30]=T,e[31]=O):O=e[31];let B;e[32]!==p.length||e[33]!==t?(B=t("{count} edges shown",{count:p.length}),e[32]=p.length,e[33]=t,e[34]=B):B=e[34];let G;e[35]!==B?(G=o("span",{className:"text-xs text-muted-foreground","data-testid":"architecture-edge-count",children:B}),e[35]=B,e[36]=G):G=e[36];let q;e[37]!==u?(q=w=>o("button",{"aria-pressed":u.has(w),className:De("rounded-full border border-border px-2.5 py-0.5 text-xs",u.has(w)?"bg-muted":"text-muted-foreground line-through"),"data-testid":`architecture-kind-${w}`,onClick:()=>{y(w)},type:"button",children:w},w),e[37]=u,e[38]=q):q=e[38];const Z=f.map(q);let H;e[39]!==O||e[40]!==G||e[41]!==Z?(H=x("div",{className:C,children:[O,G,Z]}),e[39]=O,e[40]=G,e[41]=Z,e[42]=H):H=e[42];let j,K,z;e[43]===Symbol.for("react.memo_cache_sentinel")?(j=o(ge,{}),K=o(be,{showInteractive:!1}),z=o(ve,{containerRef:A,filenameBase:"architecture",testIdPrefix:"architecture"}),e[43]=j,e[44]=K,e[45]=z):(j=e[43],K=e[44],z=e[45]);let M;e[46]!==p||e[47]!==S?(M=o("div",{className:"h-[600px] w-full overflow-hidden border border-border bg-muted/20","data-testid":"architecture-canvas",ref:A,children:x(xe,{edges:p,edgesFocusable:!1,fitView:!0,minZoom:.1,nodes:S,nodesConnectable:!1,nodesDraggable:!1,nodeTypes:Ke,children:[j,K,z]})}),e[46]=p,e[47]=S,e[48]=M):M=e[48];let Y;return e[49]!==H||e[50]!==M?(Y=x("section",{className:L,"data-testid":D,children:[H,M]}),e[49]=H,e[50]=M,e[51]=Y):Y=e[51],Y},mt=n=>{const e=F(28),{manifest:a}=n,t=ne(),l=ye();let r;e[0]!==l?(r=()=>l.fetchArchitecture(),e[0]=l,e[1]=r):r=e[1];const h=_e(a,r,ze);if(h.kind==="loading"){let i;return e[2]===Symbol.for("react.memo_cache_sentinel")?(i=x("div",{className:"flex flex-col gap-4","data-testid":"architecture-loading",children:[o(ie,{className:"h-8 w-48"}),o(ie,{className:"h-64 w-full"})]}),e[2]=i):i=e[2],i}if(h.kind==="error"){let i;e[3]!==h.message||e[4]!==t?(i=t("Couldn't load the architecture manifest: {message}",{message:h.message}),e[3]=h.message,e[4]=t,e[5]=i):i=e[5];let m;e[6]!==t?(m=t("Architecture unavailable"),e[6]=t,e[7]=m):m=e[7];let p;return e[8]!==i||e[9]!==m?(p=o(ae,{description:i,testId:"architecture-error",title:m}),e[8]=i,e[9]=m,e[10]=p):p=e[10],p}if(h.kind==="empty"){let i;e[11]!==t?(i=t("Add a lunora/<folder>/module.ts that default-exports defineModule(...) and run lunora codegen to map your modules here. Installed components join the map once you declare one."),e[11]=t,e[12]=i):i=e[12];let m;e[13]!==t?(m=t("No modules declared"),e[13]=t,e[14]=m):m=e[14];let p;return e[15]!==i||e[16]!==m?(p=o(ae,{description:i,testId:"architecture-empty",title:m}),e[15]=i,e[16]=m,e[17]=p):p=e[17],p}const{spec:s}=h;let f,d;e[18]!==s?(f=o(Ye,{manifest:s}),d=o(Ve,{manifest:s}),e[18]=s,e[19]=f,e[20]=d):(f=e[19],d=e[20]);let c;e[21]!==s.unresolved||e[22]!==t?(c=s.unresolved.length>0&&x("details",{className:"text-sm","data-testid":"architecture-unresolved",children:[x("summary",{className:"cursor-pointer text-muted-foreground",children:[t("{count} call sites could not be drawn",{count:s.unresolved.length})," ",o(me,{variant:"outline",children:s.unresolved.length})]}),o("ul",{className:"mt-2 flex flex-col gap-1 font-mono text-xs",children:s.unresolved.map(Je)})]}),e[21]=s.unresolved,e[22]=t,e[23]=c):c=e[23];let b;return e[24]!==f||e[25]!==d||e[26]!==c?(b=x("div",{className:"flex flex-col gap-6","data-testid":"architecture-panel",children:[f,d,c]}),e[24]=f,e[25]=d,e[26]=c,e[27]=b):b=e[27],b};function We(){return new Set(he)}function Ze(n){return o("option",{value:n.name,children:n.name},n.name)}function Je(n){return x("li",{children:[n.file,":",n.line," · ",n.kind," · ",n.reason]},`${n.file}:${String(n.line)}:${n.kind}:${n.reason}`)}export{mt as default};
1
+ import{c as F}from"react/compiler-runtime";import{useNavigate as pe}from"@tanstack/react-router";import{Background as ge,Controls as be,ReactFlow as xe,Handle as le,Position as oe}from"@xyflow/react";import{useState as re,useRef as Ne}from"react";import{D as ve}from"../packem_shared/diagram-export-panel-CleSOm6J.mjs";import{B as me}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as Ee,a as ke}from"../packem_shared/card-By2O8ULa.mjs";import{E as ae}from"../packem_shared/empty-state-D7jEML_T.mjs";import{S as ie}from"../packem_shared/skeleton-DX1gfixl.mjs";import{b as U,e as $,T as we,c as V,a as Se,d as Ae}from"../packem_shared/table-D0SBiDu-.mjs";import{u as _e}from"../packem_shared/use-admin-spec-Cokw73Ks.mjs";import{u as ye}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{f as Le}from"../packem_shared/internal-BT5tH08j.mjs";import{c as De}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as x,jsx as o,Fragment as Ce}from"react/jsx-runtime";const he=["call","schedule","read","write","enqueue","publish","subscribe","start","trigger","invoke"],$e=new Set(["enqueue","publish","schedule","start","subscribe","trigger"]),ce={cron:1,function:2,http:0,queue:4,service:7,table:6,topic:3,workflow:5},Ie={stroke:"var(--muted-foreground)"},Te={fill:"var(--muted-foreground)",fontSize:10},Oe={fill:"var(--background)"},W="",X=260,Be=120,de=44,ee=40,ue=12,te=16,Ge=n=>{if(typeof n!="object"||n===null)return;const e=n;return["edges","nodes","modules","unresolved"].every(a=>Array.isArray(e[a]))?e:void 0},He={cron:()=>({to:"/schedule"}),function:()=>({to:"/functions"}),http:()=>({to:"/api"}),queue:()=>({to:"/queues"}),service:()=>({to:"/functions"}),table:n=>({search:{table:n.name},to:"/data"}),topic:()=>({to:"/queues"}),workflow:()=>({to:"/workflows"})},Me=n=>He[n.kind](n),R=n=>n.module??W,Pe=(n,e,a)=>{const t=new Set;for(const r of n.nodes)(e===void 0||R(r)===e)&&t.add(r.id);if(e===void 0)return t;const l=new Set(t);for(const r of n.edges)a.has(r.kind)&&(t.has(r.from)&&l.add(r.to),t.has(r.to)&&l.add(r.from));return l},Re=(n,e,a,t)=>{const l=`lane:${n}`;return[{data:{label:e},id:l,position:{x:a*(X+Be),y:0},selectable:!1,style:{height:de+t.length*(ee+ue)+te,width:X},type:"lane"},...t.map((r,u)=>({className:"flex cursor-pointer items-center truncate rounded-md border border-border bg-card px-2 text-xs text-foreground hover:border-ring",data:{label:`${r.detail??r.kind} · ${r.name}`,link:Me(r)},extent:"parent",id:r.id,parentId:l,position:{x:te,y:de+u*(ee+ue)},style:{height:ee,width:X-te*2},type:"member"}))]},Fe=(n,e)=>{const a=Pe(n,e.lane,e.kinds),t=new Map;for(const s of n.nodes)a.has(s.id)&&t.set(R(s),[...t.get(R(s))??[],s]);const l=[...n.modules.map(s=>({label:s.installed===!0?`${s.name} · ${e.componentLabel}`:s.name,lane:s.name})),{label:e.appLaneLabel,lane:W}],r=[];let u=0;for(const{label:s,lane:f}of l){const d=(t.get(f)??[]).toSorted((c,b)=>ce[c.kind]-ce[b.kind]||c.name.localeCompare(b.name));d.length>0&&(r.push(...Re(f,s,u,d)),u+=1)}const h=[];for(const s of n.edges)e.kinds.has(s.kind)&&a.has(s.from)&&a.has(s.to)&&h.push({animated:$e.has(s.kind),id:`${s.from}|${s.kind}|${s.to}`,label:s.kind,labelBgStyle:Oe,labelStyle:Te,source:s.from,style:Ie,target:s.to,type:"smoothstep"});return{edges:h,nodes:r}},se="*",qe=n=>{const e=F(2),{data:a}=n,t=String(a.label);let l;return e[0]!==t?(l=o("div",{className:"size-full rounded-lg border border-dashed border-border bg-background/60 px-3 py-2 text-xs font-medium text-muted-foreground",children:t}),e[0]=t,e[1]=l):l=e[1],l},fe={opacity:0},je=n=>{const e=F(10),{data:a}=n,t=pe(),{label:l,link:r}=a;let u;e[0]!==r||e[1]!==t?(u=()=>{Le(t(r))},e[0]=r,e[1]=t,e[2]=u):u=e[2];const h=u;let s;e[3]===Symbol.for("react.memo_cache_sentinel")?(s=o(le,{isConnectable:!1,position:oe.Left,style:fe,type:"target"}),e[3]=s):s=e[3];let f;e[4]!==l||e[5]!==h?(f=o("button",{className:"size-full cursor-pointer truncate rounded-md text-left outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",onClick:h,type:"button",children:l}),e[4]=l,e[5]=h,e[6]=f):f=e[6];let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d=o(le,{isConnectable:!1,position:oe.Right,style:fe,type:"source"}),e[7]=d):d=e[7];let c;return e[8]!==f?(c=x(Ce,{children:[s,f,d]}),e[8]=f,e[9]=c):c=e[9],c},Ke={lane:qe,member:je},ze=n=>{const e=Ge(n);return e===void 0?{kind:"error",message:"the response is not an architecture manifest"}:e.modules.length===0?{kind:"empty"}:{kind:"ready",spec:e}},Ye=n=>{const e=F(54),{manifest:a}=n,t=ne();let l,r,u,h,s,f,d,c,b,i;if(e[0]!==a.modules||e[1]!==a.nodes||e[2]!==t){const P=new Map;for(const g of a.nodes)g.kind==="function"&&P.set(R(g),(P.get(R(g))??0)+1);const I=g=>P.get(g)??0;s=I(W),h=Ee,i="overflow-hidden py-0",u=ke,b="px-0",r=we,d="architecture-catalog";let y;e[13]!==t?(y=t("Module"),e[13]=t,e[14]=y):y=e[14];let L;e[15]!==y?(L=o(V,{children:y}),e[15]=y,e[16]=L):L=e[16];let D;e[17]!==t?(D=t("Description"),e[17]=t,e[18]=D):D=e[18];let C;e[19]!==D?(C=o(V,{children:D}),e[19]=D,e[20]=C):C=e[20];let N;e[21]!==t?(N=t("Owned tables"),e[21]=t,e[22]=N):N=e[22];let v;e[23]!==N?(v=o(V,{children:N}),e[23]=N,e[24]=v):v=e[24];let E;e[25]!==t?(E=t("Functions"),e[25]=t,e[26]=E):E=e[26];let k;e[27]!==E?(k=o(V,{children:E}),e[27]=E,e[28]=k):k=e[28],e[29]!==v||e[30]!==k||e[31]!==L||e[32]!==C?(c=o(Se,{children:x(U,{children:[L,C,v,k]})}),e[29]=v,e[30]=k,e[31]=L,e[32]=C,e[33]=c):c=e[33],l=Ae,f=a.modules.map(g=>x(U,{"data-testid":`architecture-module-${g.name}`,children:[x($,{className:"font-mono text-xs",children:[g.name,g.installed===!0&&o(me,{className:"ml-2","data-testid":`architecture-component-${g.name}`,variant:"outline",children:t("Component")})]}),o($,{className:"text-xs text-muted-foreground",children:g.description??(g.installed===!0?t("Installed component"):"—")}),o($,{className:"font-mono text-xs text-muted-foreground",children:g.tables.length===0?"—":g.tables.join(", ")}),o($,{className:"text-xs",children:I(g.name)})]},g.name)),e[0]=a.modules,e[1]=a.nodes,e[2]=t,e[3]=l,e[4]=r,e[5]=u,e[6]=h,e[7]=s,e[8]=f,e[9]=d,e[10]=c,e[11]=b,e[12]=i}else l=e[3],r=e[4],u=e[5],h=e[6],s=e[7],f=e[8],d=e[9],c=e[10],b=e[11],i=e[12];let m;e[34]!==s||e[35]!==t?(m=s>0&&x(U,{"data-testid":"architecture-module-app",children:[o($,{className:"text-xs italic text-muted-foreground",children:t("Outside any module")}),o($,{className:"text-xs text-muted-foreground",children:"—"}),o($,{className:"text-xs text-muted-foreground",children:"—"}),o($,{className:"text-xs",children:s})]}),e[34]=s,e[35]=t,e[36]=m):m=e[36];let p;e[37]!==l||e[38]!==f||e[39]!==m?(p=x(l,{children:[f,m]}),e[37]=l,e[38]=f,e[39]=m,e[40]=p):p=e[40];let S;e[41]!==r||e[42]!==d||e[43]!==c||e[44]!==p?(S=x(r,{"data-testid":d,children:[c,p]}),e[41]=r,e[42]=d,e[43]=c,e[44]=p,e[45]=S):S=e[45];let A;e[46]!==u||e[47]!==b||e[48]!==S?(A=o(u,{className:b,children:S}),e[46]=u,e[47]=b,e[48]=S,e[49]=A):A=e[49];let _;return e[50]!==h||e[51]!==i||e[52]!==A?(_=o(h,{className:i,children:A}),e[50]=h,e[51]=i,e[52]=A,e[53]=_):_=e[53],_},Ve=n=>{const e=F(52),{manifest:a}=n,t=ne(),[l,r]=re(se),[u,h]=re(We);let s;e[0]!==a.edges?(s=w=>a.edges.some(J=>J.kind===w),e[0]=a.edges,e[1]=s):s=e[1];const f=he.filter(s);let d;e[2]!==t?(d=t("Outside any module"),e[2]=t,e[3]=d):d=e[3];const c=d;let b;e[4]!==t?(b=t("Component"),e[4]=t,e[5]=b):b=e[5];const i=b;let m;e[6]!==c||e[7]!==i||e[8]!==u||e[9]!==l||e[10]!==a?(m=Fe(a,{appLaneLabel:c,componentLabel:i,kinds:u,...l===se?{}:{lane:l}}),e[6]=c,e[7]=i,e[8]=u,e[9]=l,e[10]=a,e[11]=m):m=e[11];const{edges:p,nodes:S}=m,A=Ne(null);let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=w=>{r(w.target.value)},e[12]=_):_=e[12];const P=_;let I;e[13]===Symbol.for("react.memo_cache_sentinel")?(I=w=>{h(J=>{const Q=new Set(J);return Q.delete(w)||Q.add(w),Q})},e[13]=I):I=e[13];const y=I,L="flex flex-col gap-2",D="architecture-diagram",C="flex flex-wrap items-center gap-2";let N;e[14]!==t?(N=t("Module"),e[14]=t,e[15]=N):N=e[15];let v;e[16]!==t?(v=t("All modules"),e[16]=t,e[17]=v):v=e[17];let E;e[18]!==v?(E=o("option",{value:se,children:v}),e[18]=v,e[19]=E):E=e[19];let k;e[20]!==a.modules?(k=a.modules.map(Ze),e[20]=a.modules,e[21]=k):k=e[21];let g;e[22]!==t?(g=t("Outside any module"),e[22]=t,e[23]=g):g=e[23];let T;e[24]!==g?(T=o("option",{value:W,children:g}),e[24]=g,e[25]=T):T=e[25];let O;e[26]!==l||e[27]!==N||e[28]!==E||e[29]!==k||e[30]!==T?(O=x("select",{"aria-label":N,className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"architecture-module-filter",onChange:P,value:l,children:[E,k,T]}),e[26]=l,e[27]=N,e[28]=E,e[29]=k,e[30]=T,e[31]=O):O=e[31];let B;e[32]!==p.length||e[33]!==t?(B=t("{count} edges shown",{count:p.length}),e[32]=p.length,e[33]=t,e[34]=B):B=e[34];let G;e[35]!==B?(G=o("span",{className:"text-xs text-muted-foreground","data-testid":"architecture-edge-count",children:B}),e[35]=B,e[36]=G):G=e[36];let q;e[37]!==u?(q=w=>o("button",{"aria-pressed":u.has(w),className:De("rounded-full border border-border px-2.5 py-0.5 text-xs",u.has(w)?"bg-muted":"text-muted-foreground line-through"),"data-testid":`architecture-kind-${w}`,onClick:()=>{y(w)},type:"button",children:w},w),e[37]=u,e[38]=q):q=e[38];const Z=f.map(q);let H;e[39]!==O||e[40]!==G||e[41]!==Z?(H=x("div",{className:C,children:[O,G,Z]}),e[39]=O,e[40]=G,e[41]=Z,e[42]=H):H=e[42];let j,K,z;e[43]===Symbol.for("react.memo_cache_sentinel")?(j=o(ge,{}),K=o(be,{showInteractive:!1}),z=o(ve,{containerRef:A,filenameBase:"architecture",testIdPrefix:"architecture"}),e[43]=j,e[44]=K,e[45]=z):(j=e[43],K=e[44],z=e[45]);let M;e[46]!==p||e[47]!==S?(M=o("div",{className:"h-[600px] w-full overflow-hidden border border-border bg-muted/20","data-testid":"architecture-canvas",ref:A,children:x(xe,{edges:p,edgesFocusable:!1,fitView:!0,minZoom:.1,nodes:S,nodesConnectable:!1,nodesDraggable:!1,nodeTypes:Ke,children:[j,K,z]})}),e[46]=p,e[47]=S,e[48]=M):M=e[48];let Y;return e[49]!==H||e[50]!==M?(Y=x("section",{className:L,"data-testid":D,children:[H,M]}),e[49]=H,e[50]=M,e[51]=Y):Y=e[51],Y},mt=n=>{const e=F(28),{manifest:a}=n,t=ne(),l=ye();let r;e[0]!==l?(r=()=>l.fetchArchitecture(),e[0]=l,e[1]=r):r=e[1];const h=_e(a,r,ze);if(h.kind==="loading"){let i;return e[2]===Symbol.for("react.memo_cache_sentinel")?(i=x("div",{className:"flex flex-col gap-4","data-testid":"architecture-loading",children:[o(ie,{className:"h-8 w-48"}),o(ie,{className:"h-64 w-full"})]}),e[2]=i):i=e[2],i}if(h.kind==="error"){let i;e[3]!==h.message||e[4]!==t?(i=t("Couldn't load the architecture manifest: {message}",{message:h.message}),e[3]=h.message,e[4]=t,e[5]=i):i=e[5];let m;e[6]!==t?(m=t("Architecture unavailable"),e[6]=t,e[7]=m):m=e[7];let p;return e[8]!==i||e[9]!==m?(p=o(ae,{description:i,testId:"architecture-error",title:m}),e[8]=i,e[9]=m,e[10]=p):p=e[10],p}if(h.kind==="empty"){let i;e[11]!==t?(i=t("Add a lunora/<folder>/module.ts that default-exports defineModule(...) and run lunora codegen to map your modules here. Installed components join the map once you declare one."),e[11]=t,e[12]=i):i=e[12];let m;e[13]!==t?(m=t("No modules declared"),e[13]=t,e[14]=m):m=e[14];let p;return e[15]!==i||e[16]!==m?(p=o(ae,{description:i,testId:"architecture-empty",title:m}),e[15]=i,e[16]=m,e[17]=p):p=e[17],p}const{spec:s}=h;let f,d;e[18]!==s?(f=o(Ye,{manifest:s}),d=o(Ve,{manifest:s}),e[18]=s,e[19]=f,e[20]=d):(f=e[19],d=e[20]);let c;e[21]!==s.unresolved||e[22]!==t?(c=s.unresolved.length>0&&x("details",{className:"text-sm","data-testid":"architecture-unresolved",children:[x("summary",{className:"cursor-pointer text-muted-foreground",children:[t("{count} call sites could not be drawn",{count:s.unresolved.length})," ",o(me,{variant:"outline",children:s.unresolved.length})]}),o("ul",{className:"mt-2 flex flex-col gap-1 font-mono text-xs",children:s.unresolved.map(Je)})]}),e[21]=s.unresolved,e[22]=t,e[23]=c):c=e[23];let b;return e[24]!==f||e[25]!==d||e[26]!==c?(b=x("div",{className:"flex flex-col gap-6","data-testid":"architecture-panel",children:[f,d,c]}),e[24]=f,e[25]=d,e[26]=c,e[27]=b):b=e[27],b};function We(){return new Set(he)}function Ze(n){return o("option",{value:n.name,children:n.name},n.name)}function Je(n){return x("li",{children:[n.file,":",n.line," · ",n.kind," · ",n.reason]},`${n.file}:${String(n.line)}:${n.kind}:${n.reason}`)}export{mt as default};
@@ -1 +1 @@
1
- import{c as I}from"react/compiler-runtime";import{useMemo as A,useState as ne}from"react";import{useT as H}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{c as q}from"../packem_shared/utils-bhneXptQ.mjs";import{MigrationsPanel as oe}from"../packem_shared/MigrationsPanel-CTd2YSSk.mjs";import{useNavigate as se,useSearch as re}from"@tanstack/react-router";import{E as ae}from"../packem_shared/error-alert-BxCd81tw.mjs";import{E as de}from"../packem_shared/empty-state-D7jEML_T.mjs";import{u as D}from"../packem_shared/use-admin-query-DMnTt_hg.mjs";import{ADMIN_FUNCTIONS as L}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{c as ce,f as le}from"../packem_shared/internal-BT5tH08j.mjs";import{S as fe}from"../packem_shared/schema-diagram-Dbs7-jSJ.mjs";import{jsx as l,jsxs as b}from"react/jsx-runtime";const J=1;function ue(t){const e={},i=Object.keys(t);i.sort();for(const n of i)e[n]=t[n];return e}const O=t=>typeof t=="object"&&t!==null,me=t=>O(t)&&O(t.fields)&&O(t.indexes)&&O(t.relations)&&typeof t.shardMode=="string",he=t=>{if(t===void 0||t.trim()==="")return{status:"absent"};let e;try{e=JSON.parse(t)}catch(n){return{error:`baseline is not valid JSON: ${n instanceof Error?n.message:String(n)}`,status:"invalid"}}if(!O(e)||e.version!==J||!O(e.tables))return{error:`baseline is malformed or written by an incompatible version (expected version ${String(J)})`,status:"invalid"};for(const[n,o]of Object.entries(e.tables))if(!me(o))return{error:`baseline table "${n}" has an invalid structure`,status:"invalid"};return{snapshot:{jurisdiction:typeof e.jurisdiction=="string"?e.jurisdiction:void 0,migrationIds:Array.isArray(e.migrationIds)?e.migrationIds:[],tables:e.tables,version:J},status:"ok"}},pe=(t,e)=>t.unique===e.unique&&t.fields.length===e.fields.length&&t.fields.every((i,n)=>i===e.fields[n]),Q=t=>t.unique!==void 0,M=({nullable:t,optional:e,refined:i,unique:n,...o})=>JSON.stringify(ue(o)),U=t=>({form:JSON.stringify([M(t),t.optional===!0,t.nullable===!0]),refined:t.refined===!0}),W=t=>t.kind==="union"&&t.members?t.members.map(e=>U(e)):[U({...t,nullable:!1,optional:!1})],ge=(t,e)=>{if(e.kind!=="union")return!1;const i=W(e);return W(t).every(n=>i.some(o=>o.form===n.form&&(n.refined||!o.refined)))},x=t=>{switch(t.kind){case"array":return`array(${t.of?x(t.of):"?"})`;case"from":return t.output===void 0?"from":`from(${t.output})`;case"id":return`id(${t.ref??"?"})`;case"literal":return`literal(${t.literal??"?"})`;case"object":return`object({ ${Object.keys(t.fields??{}).join(", ")} })`;case"record":return`record(${t.key?x(t.key):"?"}, ${t.of?x(t.of):"?"})`;case"union":return(t.members??[]).map(e=>x(e)).join(" | ");default:return t.kind}},T=(t,e,i)=>({remediation:"backfill",scope:"table",severity:"breaking",summary:i,table:t,type:e}),F=(t,e,i)=>({remediation:"none",scope:"table",severity:"safe",summary:i,table:t,type:e}),N=(t,e)=>{const i=JSON.stringify(t),n=JSON.stringify(e);return i===n?0:i<n?-1:1},S=t=>({...t,...t.kind==="from"?{output:void 0}:{},...t.fields?{fields:Object.fromEntries(Object.entries(t.fields).map(([e,i])=>[e,S(i)]))}:{},...t.key?{key:S(t.key)}:{},...t.of?{of:S(t.of)}:{},...t.members?{members:t.members.map(e=>S(e)).toSorted(N)}:{}}),B=t=>t.kind==="union"?t.members??[]:[t],ve=(t,e)=>{const i=[...t],n=[...e],o=new Set,r=new Set,s=(a,d)=>{for(const[f,m]of i.entries()){if(r.has(f))continue;const u=n.findIndex((g,p)=>!o.has(p)&&a(m,g));u!==-1&&(o.add(u),r.add(f),d&&([i[f],n[u]]=R(m,n[u])))}};return s((a,d)=>JSON.stringify(a)===JSON.stringify(d),!1),s((a,d)=>M(S(a))===M(S(d)),!0),[i,n]},R=(t,e)=>{if(t.kind==="union"||e.kind==="union"){const[o,r]=ve(B(t),B(e)),s=(a,d)=>a.kind==="union"?{...a,members:d.toSorted(N)}:d[0];return[s(t,o),s(e,r)]}if(t.kind!==e.kind)return[t,e];if(t.kind==="from")return t.output===void 0||e.output===void 0?[{...t,output:void 0},{...e,output:void 0}]:[t,e];const i={...t.fields?{fields:{...t.fields}}:{}},n={...e.fields?{fields:{...e.fields}}:{}};for(const o of["key","of"])t[o]&&e[o]&&([i[o],n[o]]=R(t[o],e[o]));for(const o of Object.keys(t.fields??{})){const r=t.fields?.[o],s=e.fields?.[o];r&&s&&i.fields&&n.fields&&([i.fields[o],n.fields[o]]=R(r,s))}return[{...t,...i},{...e,...n}]},be=(t,e,i,n,o)=>{const[r,s]=R(i,n);if(r.kind===s.kind&&(!o||M(r)===M(s)))return;if(o&&ge(r,s))return F(t,"widenedFieldShape",`field ${t}.${e} widened: ${x(r)} → ${x(s)} — every stored value stays valid`);if(r.kind!==s.kind)return T(t,"changedFieldKind",`field ${t}.${e} changed type: ${r.kind} → ${s.kind} — add a data migration to convert existing values`);const a=Object.values(s.fields??{});return o&&r.kind==="object"&&Object.keys(r.fields??{}).length===0&&a.length>0&&a.every(d=>d.optional)?F(t,"widenedFieldShape",`field ${t}.${e} now records its optional object shape — stored values stay valid`):T(t,"changedFieldShape",`field ${t}.${e} changed shape: ${x(r)} → ${x(s)} — stored values were written against the old shape; add a data migration to convert them`)},ye=(t,e,i,n,o)=>{const r=[];return i.unique!==n.unique&&r.push(n.unique===!0?{...T(t,"addedFieldConstraint",`field ${t}.${e} became unique — existing duplicates would violate it; add a data migration to de-duplicate first`),field:e,uniqueOn:[e]}:F(t,"relaxedFieldConstraint",`field ${t}.${e} is no longer unique`)),i.nullable!==n.nullable&&r.push(n.nullable===!0?F(t,"relaxedFieldConstraint",`field ${t}.${e} became nullable`):T(t,"addedFieldConstraint",`field ${t}.${e} is no longer nullable — rows holding NULL would be invalid; add a data migration to backfill them`)),o&&i.refined!==n.refined&&r.push(n.refined===!0?T(t,"addedFieldConstraint",`field ${t}.${e} gained a validation refinement — stored values were never checked against it; add a data migration if any could fail`):F(t,"relaxedFieldConstraint",`field ${t}.${e} dropped its validation refinement`)),r},ee=(t,e,i,n,o=!0)=>{const r=[],s=Q(i)&&Q(n),a=be(t,e,i,n,s);return a&&r.push(a),s&&r.push(...ye(t,e,i,n,o)),i.optional&&!n.optional?r.push({remediation:"backfill",severity:"breaking",summary:`field ${t}.${e} became required — rows missing it would be invalid; add a data migration to backfill it`,table:t,scope:"table",type:"fieldOptionalToRequired"}):!i.optional&&n.optional&&r.push({remediation:"none",scope:"table",severity:"safe",summary:`field ${t}.${e} became optional`,table:t,type:"fieldRequiredToOptional"}),r},xe=(t,e,i)=>i.optional?{remediation:"none",scope:"table",severity:"safe",summary:`added optional field ${t}.${e}`,table:t,type:"addedOptionalField"}:{remediation:"backfill",severity:"breaking",summary:`added required field ${t}.${e} — existing rows have no value; add a data migration to backfill it`,table:t,scope:"table",type:"addedRequiredField"},ke=(t,e)=>e.refinementsRecorded!==!0||t.refinementsRecorded===!0,$e=(t,e,i,n)=>{for(const[o,r]of Object.entries(i.fields)){const s=e.fields[o];s===void 0?n.push({...xe(t,o,r),field:o}):n.push(...ee(t,o,s,r,ke(e,i)).map(a=>({...a,field:o})))}for(const o of Object.keys(e.fields))i.fields[o]===void 0&&n.push({field:o,remediation:"backfill",severity:"breaking",summary:`removed field ${t}.${o} — add a data migration if stored data must be cleaned up`,table:t,scope:"table",type:"removedField"})},we=(t,e,i,n)=>{for(const[o,r]of Object.entries(i.indexes)){const s=e.indexes[o];if(s===void 0){n.push(r.unique?{remediation:"backfill",scope:"table",severity:"breaking",summary:`added unique index ${o} on ${t} — existing duplicates would violate it; add a data migration to de-duplicate first`,table:t,type:"addedIndex",uniqueOn:r.fields}:{remediation:"none",scope:"table",severity:"safe",summary:`added index ${o} on ${t}`,table:t,type:"addedIndex"});continue}pe(s,r)||n.push(r.unique?{remediation:"backfill",scope:"table",severity:"breaking",summary:`index ${o} on ${t} changed shape and is unique — existing duplicates would violate it; add a data migration to de-duplicate first`,table:t,type:"changedIndex",uniqueOn:r.fields}:{remediation:"none",scope:"table",severity:"safe",summary:`index ${o} on ${t} changed shape — a query that relied on the old index may need updating`,table:t,type:"changedIndex"})}for(const o of Object.keys(e.indexes))i.indexes[o]===void 0&&n.push({remediation:"none",severity:"safe",index:o,summary:`removed index ${o} on ${t} — a query that used \`.withIndex("${o}")\` no longer compiles`,table:t,scope:"table",type:"removedIndex"})},Oe=(t,e,i,n)=>{for(const o of Object.keys(i.relations))e.relations[o]===void 0&&n.push({remediation:"none",scope:"schema",severity:"safe",summary:`added relation ${t}.${o}`,table:t,type:"addedRelation"});for(const o of Object.keys(e.relations))i.relations[o]===void 0&&n.push({remediation:"none",scope:"schema",severity:"safe",summary:`removed relation ${t}.${o} — the stored foreign-key values stay in place, but its \`onDelete\` action no longer runs and a \`with: { ${o} }\` read no longer compiles`,table:t,type:"removedRelation",warning:!0})},P="shardBy:_unknown_",C="global",Se=(t,e)=>t===C&&e.startsWith(`${C}:`)||e===C&&t.startsWith(`${C}:`),je=(t,e,i)=>{if(e===i)return i!==P?void 0:{remediation:"rehome",scope:"table",severity:"breaking",summary:`table ${t} declares a non-literal .shardBy(...) key, so codegen cannot read which column partitions it — every such key records as "${P}" and two DIFFERENT keys would compare equal. Pass the shard key as a string literal; until then this is reported on every run, because the alternative is a silent pass on a re-home that strands every row (export/import is the only way back).`,table:t,type:"changedShardMode"};if(!Se(e,i))return{remediation:"rehome",severity:"breaking",summary:`table ${t} changed shard mode: ${e} → ${i} — its physical storage moves, and existing rows do NOT follow the schema; re-home them with an export/import round trip (https://lunora.sh/docs/concepts/sharding#migrating-a-populated-table)`,table:t,scope:"table",type:"changedShardMode",...i===P?{}:{coverage:{shardMode:i,table:t}}}},K=t=>t.memory!==void 0,Y=t=>t.after??0,_=t=>t.after===void 0?`{ field: "${t.field}" }`:`{ after: ${String(t.after)}, field: "${t.field}" }`,w=t=>t.after===void 0?`.ttl("${t.field}")`:`.ttl("${t.field}", { after: ${String(t.after)} })`,Te=(t,e,i)=>{if(e===void 0&&i===void 0)return;const n=(a,d)=>({coverage:{table:t,ttl:{...d.after===void 0?{}:{after:d.after},field:d.field}},expiry:{...d.after===void 0?{}:{after:d.after},field:d.field,...e===void 0?{}:{previous:{...e.after===void 0?{}:{after:e.after},field:e.field}}},remediation:"backfill",scope:"table",severity:"breaking",summary:a,table:t,type:"changedTtlPolicy"}),o=a=>({remediation:"none",scope:"table",severity:"safe",summary:a,table:t,type:"changedTtlPolicy",warning:!0});if(i===void 0)return o(`table ${t} dropped its TTL policy — its rows are no longer swept, so they stay until something else deletes them`);if(e===void 0)return n(`table ${t} gained a TTL policy ${w(i)} — every row already past the cutoff is deleted on the next alarm sweep; refresh or clear "${i.field}" on the rows that must survive, then declare a migration with covers: { table: "${t}", ttl: ${_(i)} }`,i);if(e.field!==i.field)return n(`table ${t} moved its TTL to a different column: ${w(e)} → ${w(i)} — rows are now expired by a column they were never written against; populate "${i.field}" on the rows that must survive, then declare a migration with covers: { table: "${t}", ttl: ${_(i)} }`,i);const r=Y(e),s=Y(i);return s<r?n(`table ${t} shortened its TTL: ${w(e)} → ${w(i)} — rows that were not expired under the old offset are deleted on the next alarm sweep; refresh "${i.field}" on the rows that must survive, then declare a migration with covers: { table: "${t}", ttl: ${_(i)} }`,i):s>r?o(`table ${t} lengthened its TTL: ${w(e)} → ${w(i)} — every row stays, and expires later than it would have`):void 0},Fe=(t,e,i)=>{const n=[];return e.memory!==i.memory&&n.push(i.memory===!0?{remediation:"rehome",scope:"table",severity:"breaking",summary:`table ${t} became a .memory() table — every row is deleted in every shard on the next Durable Object cold start, and no data migration survives that; export the rows first if they must be kept, or revert`,table:t,type:"changedMemoryMode",coverage:{memory:!0,table:t}}:{remediation:"none",scope:"table",severity:"safe",summary:`table ${t} is no longer a .memory() table — its rows now survive a cold start`,table:t,type:"changedMemoryMode"}),e.commitOrdered!==i.commitOrdered&&n.push(i.commitOrdered===!0?{remediation:"backfill",scope:"table",severity:"breaking",summary:`table ${t} became .commitOrdered() — rows written before it carry no _commitSeq, so a \`_commitSeq > cursor\` changefeed never offers them; add a data migration over the table to stamp them (the rewrite allocates a sequence)`,table:t,type:"changedCommitOrdering",identityRewrites:!0}:{remediation:"none",scope:"table",severity:"safe",summary:`table ${t} is no longer .commitOrdered() — stored rows are untouched, but new rows carry no _commitSeq, so a \`_commitSeq > cursor\` changefeed stops advancing without erroring; update the consumers`,table:t,type:"changedCommitOrdering",warning:!0}),n},qe=(t,e,i,n)=>{const o=je(t,e.shardMode,i.shardMode);if(o&&n.push(o),K(e)&&K(i)){n.push(...Fe(t,e,i));const r=Te(t,e.ttl,i.ttl);r&&n.push(r)}$e(t,e,i,n),we(t,e,i,n),Oe(t,e,i,n)},Me=(t,e)=>{const i=[],n=t?.tables??{};for(const[o,r]of Object.entries(e.tables)){const s=n[o];if(s===void 0){i.push({remediation:"none",scope:"table",severity:"safe",summary:`added table ${o}`,table:o,type:"addedTable"});continue}qe(o,s,r,i)}for(const o of Object.keys(n))e.tables[o]===void 0&&i.push({remediation:"none",scope:"table",severity:"safe",summary:`removed table ${o} — its rows are left in place in each shard's SQLite (nothing deletes them) but are unreachable through the schema; export the shard first if the data must be kept, or declare the table again to reach it`,table:o,type:"removedTable",warning:!0});if(t!==void 0&&t.jurisdiction!==e.jurisdiction){const o=t.jurisdiction??"(none)",r=e.jurisdiction??"(none)";i.push({remediation:"rehome",scope:"schema",severity:"breaking",summary:`Durable Object jurisdiction changed from ${o} to ${r} — this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (export then import to move it). Revert the change, or declare a migration with covers: { jurisdiction: "${e.jurisdiction??"none"}" } once the data is moved.`,type:"changedJurisdiction",coverage:{jurisdiction:e.jurisdiction??"none"}})}return{changes:i}},z=t=>Object.entries(t.fields).map(([e,i])=>({name:e,optional:i.optional,ref:Object.values(t.relations).find(n=>n.field===e&&n.kind==="one")?.table,type:x(i)})),X=(t,e,i)=>{const n={},o=e?.fields??{},r=i?.fields??{};for(const[s,a]of Object.entries(r)){const d=o[s];d===void 0?n[s]=e===void 0?"unchanged":"added":n[s]=ee(t,s,d,a).length===0?"unchanged":"changed"}for(const s of Object.keys(o))r[s]===void 0&&(n[s]="removed");return n},Ce=(t,e)=>{const{changes:i}=Me(t,e),n=new Set(i.filter(s=>s.scope==="table"&&s.table!==void 0).map(s=>s.table)),o=[],r=(s,a)=>s?"added":n.has(a)?"changed":"context";for(const[s,a]of Object.entries(e.tables)){const d=t?.tables[s],f=r(d===void 0,s);o.push({columns:z(a),fieldStatus:X(s,d,a),name:s,shardMode:a.shardMode,status:f})}for(const[s,a]of Object.entries(t?.tables??{}))e.tables[s]===void 0&&o.push({columns:z(a),fieldStatus:X(s,a,void 0),name:s,shardMode:a.shardMode,status:"removed"});return o.sort((s,a)=>s.name.localeCompare(a.name)),{breakingCount:i.filter(s=>s.severity==="breaking").length,changes:i,tables:o}},Z=t=>{const e=he(t);return e.status==="ok"?e.snapshot:void 0},Re={added:"ring-2 ring-emerald-500/60",changed:"ring-2 ring-amber-500/70",context:"opacity-55",removed:"opacity-70 ring-2 ring-destructive/60"},Ie=t=>t==="global"||t.startsWith("global:")?"global":"shard",Ee=t=>{const e=I(24),{appliedAt:i,hash:n,onSelect:o,selected:r,seq:s}=t,a=r?"border-s-primary bg-accent/60 text-foreground":"border-s-transparent text-muted-foreground hover:bg-accent/30 hover:text-foreground";let d;e[0]!==a?(d=q("flex w-full flex-col items-start gap-1 border-s-2 px-4 py-3 text-start outline-none transition-colors",a),e[0]=a,e[1]=d):d=e[1];const f=`sh-version-${n}`;let m;e[2]!==n||e[3]!==o?(m=()=>{o(n)},e[2]=n,e[3]=o,e[4]=m):m=e[4];let u;e[5]!==s?(u=b("span",{className:"font-mono text-[13px] tabular-nums",children:["v",s]}),e[5]=s,e[6]=u):u=e[6];let g;e[7]!==n?(g=n.slice(0,7),e[7]=n,e[8]=g):g=e[8];let p;e[9]!==g?(p=l("span",{className:"ms-auto font-mono text-[10px] tracking-wider text-muted-foreground/70 uppercase",children:g}),e[9]=g,e[10]=p):p=e[10];let h;e[11]!==u||e[12]!==p?(h=b("span",{className:"flex w-full items-baseline gap-2",children:[u,p]}),e[11]=u,e[12]=p,e[13]=h):h=e[13];let v;e[14]!==i?(v=ce(i),e[14]=i,e[15]=v):v=e[15];let y;e[16]!==v?(y=l("span",{className:"font-mono text-[10px] tracking-wide text-muted-foreground/70",children:v}),e[16]=v,e[17]=y):y=e[17];let k;return e[18]!==y||e[19]!==d||e[20]!==f||e[21]!==m||e[22]!==h?(k=l("li",{children:b("button",{className:d,"data-testid":f,onClick:m,type:"button",children:[h,y]})}),e[18]=y,e[19]=d,e[20]=f,e[21]=m,e[22]=h,e[23]=k):k=e[23],k},Ae=t=>{const e=I(26),{breaking:i,count:n,first:o}=t,r=H();if(o){let p;e[0]!==n?(p=l("span",{className:"text-3xl leading-none font-light tracking-tight tabular-nums",children:n}),e[0]=n,e[1]=p):p=e[1];let h;e[2]!==r?(h=r("tables"),e[2]=r,e[3]=h):h=e[3];let v;e[4]!==h?(v=l("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:h}),e[4]=h,e[5]=v):v=e[5];let y;return e[6]!==p||e[7]!==v?(y=b("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[p,v]}),e[6]=p,e[7]=v,e[8]=y):y=e[8],y}const s=i>0&&"text-destructive";let a;e[9]!==s?(a=q("text-3xl leading-none font-light tracking-tight tabular-nums",s),e[9]=s,e[10]=a):a=e[10];let d;e[11]!==n||e[12]!==a?(d=l("span",{className:a,children:n}),e[11]=n,e[12]=a,e[13]=d):d=e[13];let f;e[14]!==n||e[15]!==r?(f=r(n===1?"change":"changes"),e[14]=n,e[15]=r,e[16]=f):f=e[16];let m;e[17]!==f?(m=l("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:f}),e[17]=f,e[18]=m):m=e[18];let u;e[19]!==i||e[20]!==r?(u=i>0&&b("span",{className:"font-mono text-[11px] tracking-widest text-destructive uppercase",children:["· ",r("{count} breaking",{count:i})]}),e[19]=i,e[20]=r,e[21]=u):u=e[21];let g;return e[22]!==d||e[23]!==m||e[24]!==u?(g=b("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[d,m,u]}),e[22]=d,e[23]=m,e[24]=u,e[25]=g):g=e[25],g},te={addedFieldConstraint:{action:"added",kind:"constraint"},addedIndex:{action:"added",kind:"index"},addedOptionalField:{action:"added",kind:"field?"},addedRelation:{action:"added",kind:"relation"},addedRequiredField:{action:"added",kind:"field"},addedTable:{action:"added",kind:"table"},changedCommitOrdering:{action:"changed",kind:"commit ordering"},changedFieldKind:{action:"changed",kind:"field kind"},changedFieldShape:{action:"changed",kind:"field shape"},changedIndex:{action:"changed",kind:"index"},changedJurisdiction:{action:"changed",kind:"jurisdiction"},changedMemoryMode:{action:"changed",kind:"memory mode"},changedShardMode:{action:"changed",kind:"shard mode"},changedTtlPolicy:{action:"changed",kind:"TTL policy"},fieldOptionalToRequired:{action:"changed",kind:"field → required"},fieldRequiredToOptional:{action:"changed",kind:"field → optional"},relaxedFieldConstraint:{action:"removed",kind:"constraint"},removedField:{action:"removed",kind:"field"},removedIndex:{action:"removed",kind:"index"},removedRelation:{action:"removed",kind:"relation"},removedTable:{action:"removed",kind:"table"},widenedFieldShape:{action:"changed",kind:"field → wider"}},De=(t,e)=>{const i=`${te[t.type].action} ${e} `;return t.summary.startsWith(i)?t.summary.slice(i.length):t.summary},Le=t=>{const e=new Map;for(const n of t){const o=n.table??"",r=e.get(o);r===void 0?e.set(o,[n]):r.push(n)}const i=[...e].map(([n,o])=>({changes:o,table:n}));return[...i.filter(n=>n.table!==""),...i.filter(n=>n.table==="")]},Je=t=>{const e=I(2),{children:i}=t;let n;return e[0]!==i?(n=l("div",{className:"px-4 pt-4 pb-2 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:i}),e[0]=i,e[1]=n):n=e[1],n},Pe=({pane:t,shardKey:e=""})=>{const i=H(),n=se(),r=re({strict:!1}).version,s=c=>{le(n({search:{version:c},to:"/migrations"}))},a=D(L.schemaHistory,{},{shardKey:e}),d=a.data?.versions??[],f=r!==void 0&&d.some(c=>c.hash===r)?r:d[0]?.hash,m=d.findIndex(c=>c.hash===f),u=m===-1?void 0:d[m+1]?.hash,g=D(L.schemaVersion,{hash:f??""},{enabled:f!==void 0,shardKey:e}),p=D(L.schemaVersion,{hash:u??""},{enabled:u!==void 0,shardKey:e}),h=A(()=>{const c=Z(g.data?.version?.snapshotJson);if(c!==void 0)return Ce(Z(p.data?.version?.snapshotJson),c)},[g.data,p.data]),v=A(()=>(h?.tables??[]).map(c=>({columns:c.columns,name:c.name,tier:Ie(c.shardMode)})),[h]),y=A(()=>{const c={};for(const j of h?.tables??[])c[j.name]=Re[j.status];return c},[h]);if(a.error!==null)return l(ae,{error:a.errorSource,testId:"sh-error"});if(d.length===0)return l(de,{description:i("Each distinct schema shape this shard runs is recorded here, so you can see what changed and when."),testId:"sh-empty",title:i("No schema versions recorded yet.")});const k=h?.changes??[];return b("div",{className:"flex min-h-0 flex-1 gap-4","data-testid":"lunora-schema-history",children:[b("nav",{className:"flex w-56 shrink-0 flex-col overflow-hidden border-e border-border","data-testid":"sh-timeline-rail",children:[l(Je,{children:i("Schema versions")}),l("ul",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-timeline",children:d.map(c=>l(Ee,{appliedAt:c.appliedAt,hash:c.hash,onSelect:s,selected:c.hash===f,seq:c.seq},c.hash))})]}),b("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4 pe-1 pt-4",children:[l(Ae,{breaking:h?.breakingCount??0,count:u===void 0?v.length:k.length,first:u===void 0}),t==="diagram"?l("div",{className:"flex min-h-0 flex-1 flex-col",children:l(fe,{fill:!0,nodeClasses:y,tables:v,testIdPrefix:"sh"})}):l("div",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-changes",children:Le(k).map(c=>{const j=(h?.tables??[]).find($=>$.name===c.table);return b("section",{className:"mb-6",children:[b("div",{className:"flex items-baseline gap-3 border-b border-border/60 pb-1.5",children:[l("span",{className:"font-mono text-[13px] text-foreground",children:c.table===""?i("schema"):c.table}),j!==void 0&&l("span",{className:"font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums uppercase",children:i("{count} columns",{count:j.columns.length})}),c.changes.length>1&&l("span",{className:"ms-auto font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums",children:c.changes.length})]}),l("ul",{children:c.changes.map($=>{const{action:ie,kind:V}=te[$.type],E=$.severity==="breaking",G=De($,V);return b("li",{className:"flex items-baseline gap-4 border-s-2 py-1.5 ps-3 transition-colors hover:bg-accent/30",children:[l("span",{"aria-hidden":"true",className:q("-ms-3 h-3 w-0.5 shrink-0 self-center",E?"bg-destructive":"bg-transparent")}),b("span",{className:"w-44 shrink-0 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:[i(ie)," ",V]}),G!==c.table&&l("span",{className:q("min-w-0 font-mono text-[13px]",E?"text-destructive":"text-foreground"),children:G}),E&&l("span",{className:"ms-auto shrink-0 font-mono text-[10px] tracking-widest text-destructive uppercase",children:i("breaking")})]},`${$.type}-${$.summary}`)})})]},c.table)})})]})]})},_e=t=>q("-mb-px border-b-2 px-3 py-2.5 font-mono text-[11px] tracking-wider uppercase transition-colors outline-none","hover:bg-accent/40 focus-visible:bg-accent/40",t?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),et=t=>{const e=I(11),{initialShardKey:i}=t,n=H(),[o,r]=ne("diagram");let s;e[0]!==o?(s=(u,g,p,h)=>b("button",{"aria-selected":o===u,className:_e(o===u),"data-testid":p,onClick:()=>{r(u)},role:"tab",type:"button",children:[g,h!==void 0&&l("span",{className:"ms-2 tabular-nums text-muted-foreground/70",children:h})]}),e[0]=o,e[1]=s):s=e[1];const a=s;let d;e[2]!==n||e[3]!==a?(d=b("div",{className:"flex shrink-0 items-center gap-1 border-b border-border px-3","data-testid":"mg-panes",role:"tablist",children:[a("diagram",n("Diagram"),"mg-pane-diagram"),a("changes",n("Changes"),"mg-pane-changes"),a("data",n("Data migrations"),"mg-pane-data")]}),e[2]=n,e[3]=a,e[4]=d):d=e[4];let f;e[5]!==i||e[6]!==o?(f=l("div",{className:"flex min-h-0 flex-1 flex-col",children:o==="data"?l("div",{className:"min-h-0 flex-1 overflow-y-auto px-4",children:l(oe,{initialShardKey:i})}):l(Pe,{pane:o,shardKey:i})}),e[5]=i,e[6]=o,e[7]=f):f=e[7];let m;return e[8]!==d||e[9]!==f?(m=b("div",{className:"flex min-h-0 flex-1 flex-col pt-4","data-testid":"lunora-migrations-route",children:[d,f]}),e[8]=d,e[9]=f,e[10]=m):m=e[10],m};export{et as default};
1
+ import{c as I}from"react/compiler-runtime";import{useMemo as A,useState as ne}from"react";import{useT as H}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{c as q}from"../packem_shared/utils-bhneXptQ.mjs";import{MigrationsPanel as oe}from"../packem_shared/MigrationsPanel-CTd2YSSk.mjs";import{useNavigate as se,useSearch as re}from"@tanstack/react-router";import{E as ae}from"../packem_shared/error-alert-BxCd81tw.mjs";import{E as de}from"../packem_shared/empty-state-D7jEML_T.mjs";import{u as D}from"../packem_shared/use-admin-query-DMnTt_hg.mjs";import{ADMIN_FUNCTIONS as L}from"../packem_shared/ADMIN_FUNCTIONS-DAHZ35kM.mjs";import{c as ce,f as le}from"../packem_shared/internal-BT5tH08j.mjs";import{S as fe}from"../packem_shared/schema-diagram-BpIBRUm6.mjs";import{jsx as l,jsxs as b}from"react/jsx-runtime";const J=1;function ue(t){const e={},i=Object.keys(t);i.sort();for(const n of i)e[n]=t[n];return e}const O=t=>typeof t=="object"&&t!==null,me=t=>O(t)&&O(t.fields)&&O(t.indexes)&&O(t.relations)&&typeof t.shardMode=="string",he=t=>{if(t===void 0||t.trim()==="")return{status:"absent"};let e;try{e=JSON.parse(t)}catch(n){return{error:`baseline is not valid JSON: ${n instanceof Error?n.message:String(n)}`,status:"invalid"}}if(!O(e)||e.version!==J||!O(e.tables))return{error:`baseline is malformed or written by an incompatible version (expected version ${String(J)})`,status:"invalid"};for(const[n,o]of Object.entries(e.tables))if(!me(o))return{error:`baseline table "${n}" has an invalid structure`,status:"invalid"};return{snapshot:{jurisdiction:typeof e.jurisdiction=="string"?e.jurisdiction:void 0,migrationIds:Array.isArray(e.migrationIds)?e.migrationIds:[],tables:e.tables,version:J},status:"ok"}},pe=(t,e)=>t.unique===e.unique&&t.fields.length===e.fields.length&&t.fields.every((i,n)=>i===e.fields[n]),Q=t=>t.unique!==void 0,M=({nullable:t,optional:e,refined:i,unique:n,...o})=>JSON.stringify(ue(o)),U=t=>({form:JSON.stringify([M(t),t.optional===!0,t.nullable===!0]),refined:t.refined===!0}),W=t=>t.kind==="union"&&t.members?t.members.map(e=>U(e)):[U({...t,nullable:!1,optional:!1})],ge=(t,e)=>{if(e.kind!=="union")return!1;const i=W(e);return W(t).every(n=>i.some(o=>o.form===n.form&&(n.refined||!o.refined)))},x=t=>{switch(t.kind){case"array":return`array(${t.of?x(t.of):"?"})`;case"from":return t.output===void 0?"from":`from(${t.output})`;case"id":return`id(${t.ref??"?"})`;case"literal":return`literal(${t.literal??"?"})`;case"object":return`object({ ${Object.keys(t.fields??{}).join(", ")} })`;case"record":return`record(${t.key?x(t.key):"?"}, ${t.of?x(t.of):"?"})`;case"union":return(t.members??[]).map(e=>x(e)).join(" | ");default:return t.kind}},T=(t,e,i)=>({remediation:"backfill",scope:"table",severity:"breaking",summary:i,table:t,type:e}),F=(t,e,i)=>({remediation:"none",scope:"table",severity:"safe",summary:i,table:t,type:e}),N=(t,e)=>{const i=JSON.stringify(t),n=JSON.stringify(e);return i===n?0:i<n?-1:1},S=t=>({...t,...t.kind==="from"?{output:void 0}:{},...t.fields?{fields:Object.fromEntries(Object.entries(t.fields).map(([e,i])=>[e,S(i)]))}:{},...t.key?{key:S(t.key)}:{},...t.of?{of:S(t.of)}:{},...t.members?{members:t.members.map(e=>S(e)).toSorted(N)}:{}}),B=t=>t.kind==="union"?t.members??[]:[t],ve=(t,e)=>{const i=[...t],n=[...e],o=new Set,r=new Set,s=(a,d)=>{for(const[f,m]of i.entries()){if(r.has(f))continue;const u=n.findIndex((g,p)=>!o.has(p)&&a(m,g));u!==-1&&(o.add(u),r.add(f),d&&([i[f],n[u]]=R(m,n[u])))}};return s((a,d)=>JSON.stringify(a)===JSON.stringify(d),!1),s((a,d)=>M(S(a))===M(S(d)),!0),[i,n]},R=(t,e)=>{if(t.kind==="union"||e.kind==="union"){const[o,r]=ve(B(t),B(e)),s=(a,d)=>a.kind==="union"?{...a,members:d.toSorted(N)}:d[0];return[s(t,o),s(e,r)]}if(t.kind!==e.kind)return[t,e];if(t.kind==="from")return t.output===void 0||e.output===void 0?[{...t,output:void 0},{...e,output:void 0}]:[t,e];const i={...t.fields?{fields:{...t.fields}}:{}},n={...e.fields?{fields:{...e.fields}}:{}};for(const o of["key","of"])t[o]&&e[o]&&([i[o],n[o]]=R(t[o],e[o]));for(const o of Object.keys(t.fields??{})){const r=t.fields?.[o],s=e.fields?.[o];r&&s&&i.fields&&n.fields&&([i.fields[o],n.fields[o]]=R(r,s))}return[{...t,...i},{...e,...n}]},be=(t,e,i,n,o)=>{const[r,s]=R(i,n);if(r.kind===s.kind&&(!o||M(r)===M(s)))return;if(o&&ge(r,s))return F(t,"widenedFieldShape",`field ${t}.${e} widened: ${x(r)} → ${x(s)} — every stored value stays valid`);if(r.kind!==s.kind)return T(t,"changedFieldKind",`field ${t}.${e} changed type: ${r.kind} → ${s.kind} — add a data migration to convert existing values`);const a=Object.values(s.fields??{});return o&&r.kind==="object"&&Object.keys(r.fields??{}).length===0&&a.length>0&&a.every(d=>d.optional)?F(t,"widenedFieldShape",`field ${t}.${e} now records its optional object shape — stored values stay valid`):T(t,"changedFieldShape",`field ${t}.${e} changed shape: ${x(r)} → ${x(s)} — stored values were written against the old shape; add a data migration to convert them`)},ye=(t,e,i,n,o)=>{const r=[];return i.unique!==n.unique&&r.push(n.unique===!0?{...T(t,"addedFieldConstraint",`field ${t}.${e} became unique — existing duplicates would violate it; add a data migration to de-duplicate first`),field:e,uniqueOn:[e]}:F(t,"relaxedFieldConstraint",`field ${t}.${e} is no longer unique`)),i.nullable!==n.nullable&&r.push(n.nullable===!0?F(t,"relaxedFieldConstraint",`field ${t}.${e} became nullable`):T(t,"addedFieldConstraint",`field ${t}.${e} is no longer nullable — rows holding NULL would be invalid; add a data migration to backfill them`)),o&&i.refined!==n.refined&&r.push(n.refined===!0?T(t,"addedFieldConstraint",`field ${t}.${e} gained a validation refinement — stored values were never checked against it; add a data migration if any could fail`):F(t,"relaxedFieldConstraint",`field ${t}.${e} dropped its validation refinement`)),r},ee=(t,e,i,n,o=!0)=>{const r=[],s=Q(i)&&Q(n),a=be(t,e,i,n,s);return a&&r.push(a),s&&r.push(...ye(t,e,i,n,o)),i.optional&&!n.optional?r.push({remediation:"backfill",severity:"breaking",summary:`field ${t}.${e} became required — rows missing it would be invalid; add a data migration to backfill it`,table:t,scope:"table",type:"fieldOptionalToRequired"}):!i.optional&&n.optional&&r.push({remediation:"none",scope:"table",severity:"safe",summary:`field ${t}.${e} became optional`,table:t,type:"fieldRequiredToOptional"}),r},xe=(t,e,i)=>i.optional?{remediation:"none",scope:"table",severity:"safe",summary:`added optional field ${t}.${e}`,table:t,type:"addedOptionalField"}:{remediation:"backfill",severity:"breaking",summary:`added required field ${t}.${e} — existing rows have no value; add a data migration to backfill it`,table:t,scope:"table",type:"addedRequiredField"},ke=(t,e)=>e.refinementsRecorded!==!0||t.refinementsRecorded===!0,$e=(t,e,i,n)=>{for(const[o,r]of Object.entries(i.fields)){const s=e.fields[o];s===void 0?n.push({...xe(t,o,r),field:o}):n.push(...ee(t,o,s,r,ke(e,i)).map(a=>({...a,field:o})))}for(const o of Object.keys(e.fields))i.fields[o]===void 0&&n.push({field:o,remediation:"backfill",severity:"breaking",summary:`removed field ${t}.${o} — add a data migration if stored data must be cleaned up`,table:t,scope:"table",type:"removedField"})},we=(t,e,i,n)=>{for(const[o,r]of Object.entries(i.indexes)){const s=e.indexes[o];if(s===void 0){n.push(r.unique?{remediation:"backfill",scope:"table",severity:"breaking",summary:`added unique index ${o} on ${t} — existing duplicates would violate it; add a data migration to de-duplicate first`,table:t,type:"addedIndex",uniqueOn:r.fields}:{remediation:"none",scope:"table",severity:"safe",summary:`added index ${o} on ${t}`,table:t,type:"addedIndex"});continue}pe(s,r)||n.push(r.unique?{remediation:"backfill",scope:"table",severity:"breaking",summary:`index ${o} on ${t} changed shape and is unique — existing duplicates would violate it; add a data migration to de-duplicate first`,table:t,type:"changedIndex",uniqueOn:r.fields}:{remediation:"none",scope:"table",severity:"safe",summary:`index ${o} on ${t} changed shape — a query that relied on the old index may need updating`,table:t,type:"changedIndex"})}for(const o of Object.keys(e.indexes))i.indexes[o]===void 0&&n.push({remediation:"none",severity:"safe",index:o,summary:`removed index ${o} on ${t} — a query that used \`.withIndex("${o}")\` no longer compiles`,table:t,scope:"table",type:"removedIndex"})},Oe=(t,e,i,n)=>{for(const o of Object.keys(i.relations))e.relations[o]===void 0&&n.push({remediation:"none",scope:"schema",severity:"safe",summary:`added relation ${t}.${o}`,table:t,type:"addedRelation"});for(const o of Object.keys(e.relations))i.relations[o]===void 0&&n.push({remediation:"none",scope:"schema",severity:"safe",summary:`removed relation ${t}.${o} — the stored foreign-key values stay in place, but its \`onDelete\` action no longer runs and a \`with: { ${o} }\` read no longer compiles`,table:t,type:"removedRelation",warning:!0})},P="shardBy:_unknown_",C="global",Se=(t,e)=>t===C&&e.startsWith(`${C}:`)||e===C&&t.startsWith(`${C}:`),je=(t,e,i)=>{if(e===i)return i!==P?void 0:{remediation:"rehome",scope:"table",severity:"breaking",summary:`table ${t} declares a non-literal .shardBy(...) key, so codegen cannot read which column partitions it — every such key records as "${P}" and two DIFFERENT keys would compare equal. Pass the shard key as a string literal; until then this is reported on every run, because the alternative is a silent pass on a re-home that strands every row (export/import is the only way back).`,table:t,type:"changedShardMode"};if(!Se(e,i))return{remediation:"rehome",severity:"breaking",summary:`table ${t} changed shard mode: ${e} → ${i} — its physical storage moves, and existing rows do NOT follow the schema; re-home them with an export/import round trip (https://lunora.sh/docs/concepts/sharding#migrating-a-populated-table)`,table:t,scope:"table",type:"changedShardMode",...i===P?{}:{coverage:{shardMode:i,table:t}}}},K=t=>t.memory!==void 0,Y=t=>t.after??0,_=t=>t.after===void 0?`{ field: "${t.field}" }`:`{ after: ${String(t.after)}, field: "${t.field}" }`,w=t=>t.after===void 0?`.ttl("${t.field}")`:`.ttl("${t.field}", { after: ${String(t.after)} })`,Te=(t,e,i)=>{if(e===void 0&&i===void 0)return;const n=(a,d)=>({coverage:{table:t,ttl:{...d.after===void 0?{}:{after:d.after},field:d.field}},expiry:{...d.after===void 0?{}:{after:d.after},field:d.field,...e===void 0?{}:{previous:{...e.after===void 0?{}:{after:e.after},field:e.field}}},remediation:"backfill",scope:"table",severity:"breaking",summary:a,table:t,type:"changedTtlPolicy"}),o=a=>({remediation:"none",scope:"table",severity:"safe",summary:a,table:t,type:"changedTtlPolicy",warning:!0});if(i===void 0)return o(`table ${t} dropped its TTL policy — its rows are no longer swept, so they stay until something else deletes them`);if(e===void 0)return n(`table ${t} gained a TTL policy ${w(i)} — every row already past the cutoff is deleted on the next alarm sweep; refresh or clear "${i.field}" on the rows that must survive, then declare a migration with covers: { table: "${t}", ttl: ${_(i)} }`,i);if(e.field!==i.field)return n(`table ${t} moved its TTL to a different column: ${w(e)} → ${w(i)} — rows are now expired by a column they were never written against; populate "${i.field}" on the rows that must survive, then declare a migration with covers: { table: "${t}", ttl: ${_(i)} }`,i);const r=Y(e),s=Y(i);return s<r?n(`table ${t} shortened its TTL: ${w(e)} → ${w(i)} — rows that were not expired under the old offset are deleted on the next alarm sweep; refresh "${i.field}" on the rows that must survive, then declare a migration with covers: { table: "${t}", ttl: ${_(i)} }`,i):s>r?o(`table ${t} lengthened its TTL: ${w(e)} → ${w(i)} — every row stays, and expires later than it would have`):void 0},Fe=(t,e,i)=>{const n=[];return e.memory!==i.memory&&n.push(i.memory===!0?{remediation:"rehome",scope:"table",severity:"breaking",summary:`table ${t} became a .memory() table — every row is deleted in every shard on the next Durable Object cold start, and no data migration survives that; export the rows first if they must be kept, or revert`,table:t,type:"changedMemoryMode",coverage:{memory:!0,table:t}}:{remediation:"none",scope:"table",severity:"safe",summary:`table ${t} is no longer a .memory() table — its rows now survive a cold start`,table:t,type:"changedMemoryMode"}),e.commitOrdered!==i.commitOrdered&&n.push(i.commitOrdered===!0?{remediation:"backfill",scope:"table",severity:"breaking",summary:`table ${t} became .commitOrdered() — rows written before it carry no _commitSeq, so a \`_commitSeq > cursor\` changefeed never offers them; add a data migration over the table to stamp them (the rewrite allocates a sequence)`,table:t,type:"changedCommitOrdering",identityRewrites:!0}:{remediation:"none",scope:"table",severity:"safe",summary:`table ${t} is no longer .commitOrdered() — stored rows are untouched, but new rows carry no _commitSeq, so a \`_commitSeq > cursor\` changefeed stops advancing without erroring; update the consumers`,table:t,type:"changedCommitOrdering",warning:!0}),n},qe=(t,e,i,n)=>{const o=je(t,e.shardMode,i.shardMode);if(o&&n.push(o),K(e)&&K(i)){n.push(...Fe(t,e,i));const r=Te(t,e.ttl,i.ttl);r&&n.push(r)}$e(t,e,i,n),we(t,e,i,n),Oe(t,e,i,n)},Me=(t,e)=>{const i=[],n=t?.tables??{};for(const[o,r]of Object.entries(e.tables)){const s=n[o];if(s===void 0){i.push({remediation:"none",scope:"table",severity:"safe",summary:`added table ${o}`,table:o,type:"addedTable"});continue}qe(o,s,r,i)}for(const o of Object.keys(n))e.tables[o]===void 0&&i.push({remediation:"none",scope:"table",severity:"safe",summary:`removed table ${o} — its rows are left in place in each shard's SQLite (nothing deletes them) but are unreachable through the schema; export the shard first if the data must be kept, or declare the table again to reach it`,table:o,type:"removedTable",warning:!0});if(t!==void 0&&t.jurisdiction!==e.jurisdiction){const o=t.jurisdiction??"(none)",r=e.jurisdiction??"(none)";i.push({remediation:"rehome",scope:"schema",severity:"breaking",summary:`Durable Object jurisdiction changed from ${o} to ${r} — this re-homes every DO and strands all existing shard, scheduler, and session-DO data in the old region (export then import to move it). Revert the change, or declare a migration with covers: { jurisdiction: "${e.jurisdiction??"none"}" } once the data is moved.`,type:"changedJurisdiction",coverage:{jurisdiction:e.jurisdiction??"none"}})}return{changes:i}},z=t=>Object.entries(t.fields).map(([e,i])=>({name:e,optional:i.optional,ref:Object.values(t.relations).find(n=>n.field===e&&n.kind==="one")?.table,type:x(i)})),X=(t,e,i)=>{const n={},o=e?.fields??{},r=i?.fields??{};for(const[s,a]of Object.entries(r)){const d=o[s];d===void 0?n[s]=e===void 0?"unchanged":"added":n[s]=ee(t,s,d,a).length===0?"unchanged":"changed"}for(const s of Object.keys(o))r[s]===void 0&&(n[s]="removed");return n},Ce=(t,e)=>{const{changes:i}=Me(t,e),n=new Set(i.filter(s=>s.scope==="table"&&s.table!==void 0).map(s=>s.table)),o=[],r=(s,a)=>s?"added":n.has(a)?"changed":"context";for(const[s,a]of Object.entries(e.tables)){const d=t?.tables[s],f=r(d===void 0,s);o.push({columns:z(a),fieldStatus:X(s,d,a),name:s,shardMode:a.shardMode,status:f})}for(const[s,a]of Object.entries(t?.tables??{}))e.tables[s]===void 0&&o.push({columns:z(a),fieldStatus:X(s,a,void 0),name:s,shardMode:a.shardMode,status:"removed"});return o.sort((s,a)=>s.name.localeCompare(a.name)),{breakingCount:i.filter(s=>s.severity==="breaking").length,changes:i,tables:o}},Z=t=>{const e=he(t);return e.status==="ok"?e.snapshot:void 0},Re={added:"ring-2 ring-emerald-500/60",changed:"ring-2 ring-amber-500/70",context:"opacity-55",removed:"opacity-70 ring-2 ring-destructive/60"},Ie=t=>t==="global"||t.startsWith("global:")?"global":"shard",Ee=t=>{const e=I(24),{appliedAt:i,hash:n,onSelect:o,selected:r,seq:s}=t,a=r?"border-s-primary bg-accent/60 text-foreground":"border-s-transparent text-muted-foreground hover:bg-accent/30 hover:text-foreground";let d;e[0]!==a?(d=q("flex w-full flex-col items-start gap-1 border-s-2 px-4 py-3 text-start outline-none transition-colors",a),e[0]=a,e[1]=d):d=e[1];const f=`sh-version-${n}`;let m;e[2]!==n||e[3]!==o?(m=()=>{o(n)},e[2]=n,e[3]=o,e[4]=m):m=e[4];let u;e[5]!==s?(u=b("span",{className:"font-mono text-[13px] tabular-nums",children:["v",s]}),e[5]=s,e[6]=u):u=e[6];let g;e[7]!==n?(g=n.slice(0,7),e[7]=n,e[8]=g):g=e[8];let p;e[9]!==g?(p=l("span",{className:"ms-auto font-mono text-[10px] tracking-wider text-muted-foreground/70 uppercase",children:g}),e[9]=g,e[10]=p):p=e[10];let h;e[11]!==u||e[12]!==p?(h=b("span",{className:"flex w-full items-baseline gap-2",children:[u,p]}),e[11]=u,e[12]=p,e[13]=h):h=e[13];let v;e[14]!==i?(v=ce(i),e[14]=i,e[15]=v):v=e[15];let y;e[16]!==v?(y=l("span",{className:"font-mono text-[10px] tracking-wide text-muted-foreground/70",children:v}),e[16]=v,e[17]=y):y=e[17];let k;return e[18]!==y||e[19]!==d||e[20]!==f||e[21]!==m||e[22]!==h?(k=l("li",{children:b("button",{className:d,"data-testid":f,onClick:m,type:"button",children:[h,y]})}),e[18]=y,e[19]=d,e[20]=f,e[21]=m,e[22]=h,e[23]=k):k=e[23],k},Ae=t=>{const e=I(26),{breaking:i,count:n,first:o}=t,r=H();if(o){let p;e[0]!==n?(p=l("span",{className:"text-3xl leading-none font-light tracking-tight tabular-nums",children:n}),e[0]=n,e[1]=p):p=e[1];let h;e[2]!==r?(h=r("tables"),e[2]=r,e[3]=h):h=e[3];let v;e[4]!==h?(v=l("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:h}),e[4]=h,e[5]=v):v=e[5];let y;return e[6]!==p||e[7]!==v?(y=b("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[p,v]}),e[6]=p,e[7]=v,e[8]=y):y=e[8],y}const s=i>0&&"text-destructive";let a;e[9]!==s?(a=q("text-3xl leading-none font-light tracking-tight tabular-nums",s),e[9]=s,e[10]=a):a=e[10];let d;e[11]!==n||e[12]!==a?(d=l("span",{className:a,children:n}),e[11]=n,e[12]=a,e[13]=d):d=e[13];let f;e[14]!==n||e[15]!==r?(f=r(n===1?"change":"changes"),e[14]=n,e[15]=r,e[16]=f):f=e[16];let m;e[17]!==f?(m=l("span",{className:"font-mono text-[11px] tracking-widest text-muted-foreground uppercase",children:f}),e[17]=f,e[18]=m):m=e[18];let u;e[19]!==i||e[20]!==r?(u=i>0&&b("span",{className:"font-mono text-[11px] tracking-widest text-destructive uppercase",children:["· ",r("{count} breaking",{count:i})]}),e[19]=i,e[20]=r,e[21]=u):u=e[21];let g;return e[22]!==d||e[23]!==m||e[24]!==u?(g=b("div",{className:"flex items-baseline gap-3","data-testid":"sh-summary",children:[d,m,u]}),e[22]=d,e[23]=m,e[24]=u,e[25]=g):g=e[25],g},te={addedFieldConstraint:{action:"added",kind:"constraint"},addedIndex:{action:"added",kind:"index"},addedOptionalField:{action:"added",kind:"field?"},addedRelation:{action:"added",kind:"relation"},addedRequiredField:{action:"added",kind:"field"},addedTable:{action:"added",kind:"table"},changedCommitOrdering:{action:"changed",kind:"commit ordering"},changedFieldKind:{action:"changed",kind:"field kind"},changedFieldShape:{action:"changed",kind:"field shape"},changedIndex:{action:"changed",kind:"index"},changedJurisdiction:{action:"changed",kind:"jurisdiction"},changedMemoryMode:{action:"changed",kind:"memory mode"},changedShardMode:{action:"changed",kind:"shard mode"},changedTtlPolicy:{action:"changed",kind:"TTL policy"},fieldOptionalToRequired:{action:"changed",kind:"field → required"},fieldRequiredToOptional:{action:"changed",kind:"field → optional"},relaxedFieldConstraint:{action:"removed",kind:"constraint"},removedField:{action:"removed",kind:"field"},removedIndex:{action:"removed",kind:"index"},removedRelation:{action:"removed",kind:"relation"},removedTable:{action:"removed",kind:"table"},widenedFieldShape:{action:"changed",kind:"field → wider"}},De=(t,e)=>{const i=`${te[t.type].action} ${e} `;return t.summary.startsWith(i)?t.summary.slice(i.length):t.summary},Le=t=>{const e=new Map;for(const n of t){const o=n.table??"",r=e.get(o);r===void 0?e.set(o,[n]):r.push(n)}const i=[...e].map(([n,o])=>({changes:o,table:n}));return[...i.filter(n=>n.table!==""),...i.filter(n=>n.table==="")]},Je=t=>{const e=I(2),{children:i}=t;let n;return e[0]!==i?(n=l("div",{className:"px-4 pt-4 pb-2 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:i}),e[0]=i,e[1]=n):n=e[1],n},Pe=({pane:t,shardKey:e=""})=>{const i=H(),n=se(),r=re({strict:!1}).version,s=c=>{le(n({search:{version:c},to:"/migrations"}))},a=D(L.schemaHistory,{},{shardKey:e}),d=a.data?.versions??[],f=r!==void 0&&d.some(c=>c.hash===r)?r:d[0]?.hash,m=d.findIndex(c=>c.hash===f),u=m===-1?void 0:d[m+1]?.hash,g=D(L.schemaVersion,{hash:f??""},{enabled:f!==void 0,shardKey:e}),p=D(L.schemaVersion,{hash:u??""},{enabled:u!==void 0,shardKey:e}),h=A(()=>{const c=Z(g.data?.version?.snapshotJson);if(c!==void 0)return Ce(Z(p.data?.version?.snapshotJson),c)},[g.data,p.data]),v=A(()=>(h?.tables??[]).map(c=>({columns:c.columns,name:c.name,tier:Ie(c.shardMode)})),[h]),y=A(()=>{const c={};for(const j of h?.tables??[])c[j.name]=Re[j.status];return c},[h]);if(a.error!==null)return l(ae,{error:a.errorSource,testId:"sh-error"});if(d.length===0)return l(de,{description:i("Each distinct schema shape this shard runs is recorded here, so you can see what changed and when."),testId:"sh-empty",title:i("No schema versions recorded yet.")});const k=h?.changes??[];return b("div",{className:"flex min-h-0 flex-1 gap-4","data-testid":"lunora-schema-history",children:[b("nav",{className:"flex w-56 shrink-0 flex-col overflow-hidden border-e border-border","data-testid":"sh-timeline-rail",children:[l(Je,{children:i("Schema versions")}),l("ul",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-timeline",children:d.map(c=>l(Ee,{appliedAt:c.appliedAt,hash:c.hash,onSelect:s,selected:c.hash===f,seq:c.seq},c.hash))})]}),b("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4 pe-1 pt-4",children:[l(Ae,{breaking:h?.breakingCount??0,count:u===void 0?v.length:k.length,first:u===void 0}),t==="diagram"?l("div",{className:"flex min-h-0 flex-1 flex-col",children:l(fe,{fill:!0,nodeClasses:y,tables:v,testIdPrefix:"sh"})}):l("div",{className:"min-h-0 flex-1 overflow-y-auto","data-testid":"sh-changes",children:Le(k).map(c=>{const j=(h?.tables??[]).find($=>$.name===c.table);return b("section",{className:"mb-6",children:[b("div",{className:"flex items-baseline gap-3 border-b border-border/60 pb-1.5",children:[l("span",{className:"font-mono text-[13px] text-foreground",children:c.table===""?i("schema"):c.table}),j!==void 0&&l("span",{className:"font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums uppercase",children:i("{count} columns",{count:j.columns.length})}),c.changes.length>1&&l("span",{className:"ms-auto font-mono text-[10px] tracking-widest text-muted-foreground/70 tabular-nums",children:c.changes.length})]}),l("ul",{children:c.changes.map($=>{const{action:ie,kind:V}=te[$.type],E=$.severity==="breaking",G=De($,V);return b("li",{className:"flex items-baseline gap-4 border-s-2 py-1.5 ps-3 transition-colors hover:bg-accent/30",children:[l("span",{"aria-hidden":"true",className:q("-ms-3 h-3 w-0.5 shrink-0 self-center",E?"bg-destructive":"bg-transparent")}),b("span",{className:"w-44 shrink-0 font-mono text-[10px] tracking-widest text-muted-foreground/70 uppercase",children:[i(ie)," ",V]}),G!==c.table&&l("span",{className:q("min-w-0 font-mono text-[13px]",E?"text-destructive":"text-foreground"),children:G}),E&&l("span",{className:"ms-auto shrink-0 font-mono text-[10px] tracking-widest text-destructive uppercase",children:i("breaking")})]},`${$.type}-${$.summary}`)})})]},c.table)})})]})]})},_e=t=>q("-mb-px border-b-2 px-3 py-2.5 font-mono text-[11px] tracking-wider uppercase transition-colors outline-none","hover:bg-accent/40 focus-visible:bg-accent/40",t?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),et=t=>{const e=I(11),{initialShardKey:i}=t,n=H(),[o,r]=ne("diagram");let s;e[0]!==o?(s=(u,g,p,h)=>b("button",{"aria-selected":o===u,className:_e(o===u),"data-testid":p,onClick:()=>{r(u)},role:"tab",type:"button",children:[g,h!==void 0&&l("span",{className:"ms-2 tabular-nums text-muted-foreground/70",children:h})]}),e[0]=o,e[1]=s):s=e[1];const a=s;let d;e[2]!==n||e[3]!==a?(d=b("div",{className:"flex shrink-0 items-center gap-1 border-b border-border px-3","data-testid":"mg-panes",role:"tablist",children:[a("diagram",n("Diagram"),"mg-pane-diagram"),a("changes",n("Changes"),"mg-pane-changes"),a("data",n("Data migrations"),"mg-pane-data")]}),e[2]=n,e[3]=a,e[4]=d):d=e[4];let f;e[5]!==i||e[6]!==o?(f=l("div",{className:"flex min-h-0 flex-1 flex-col",children:o==="data"?l("div",{className:"min-h-0 flex-1 overflow-y-auto px-4",children:l(oe,{initialShardKey:i})}):l(Pe,{pane:o,shardKey:i})}),e[5]=i,e[6]=o,e[7]=f):f=e[7];let m;return e[8]!==d||e[9]!==f?(m=b("div",{className:"flex min-h-0 flex-1 flex-col pt-4","data-testid":"lunora-migrations-route",children:[d,f]}),e[8]=d,e[9]=f,e[10]=m):m=e[10],m};export{et as default};
@@ -0,0 +1,2 @@
1
+ 'use client';
2
+ import{Download01Icon as j}from"@hugeicons/core-free-icons";import{HugeiconsIcon as A}from"@hugeicons/react";import{getNodesBounds as R,getViewportForBounds as L,useNodes as _,useReactFlow as O,Panel as G}from"@xyflow/react";import{useState as y}from"react";import{LunoraError as x}from"@lunora/errors";import{toBlob as I,toSvg as M}from"html-to-image";import{useT as P}from"./DEFAULT_LOCALE-BQ3jRT74.mjs";import{f as T,b as U}from"./internal-BT5tH08j.mjs";import{d as C,D as F,c as H,b as f}from"./dropdown-menu-jLZenfWH.mjs";import{jsxs as u,jsx as m}from"react/jsx-runtime";const d=1920,h=1080,v=32,J=3e4;let b;const w=(e,o)=>{const t=globalThis.document.createElement("a");t.href=e,t.download=o,globalThis.document.body.append(t),t.click(),t.remove()},q=(e,o,t="schema-diagram.json")=>{const n={edges:o,exportedAt:new Date().toISOString(),nodes:e},s=JSON.stringify(n,void 0,2),i=globalThis.URL.createObjectURL(new globalThis.Blob([s],{type:"application/json"}));w(i,t),globalThis.setTimeout(()=>{globalThis.URL.revokeObjectURL(i)},0)},E=(e,o,t,n)=>{const s=R(e),{x:i,y:a,zoom:r}=L(s,o,t,.1,2,n);return{transform:[i,a,r],zoom:r}},z=async e=>{let o;const t=new Promise((n,s)=>{o=globalThis.setTimeout(()=>{s(new x("INTERNAL","PNG export timed out"))},J)});try{return await Promise.race([e,t])}finally{globalThis.clearTimeout(o)}},B=async(e,o,t="schema-diagram.png")=>{const{transform:n}=E(o,d,h,v),[s,i,a]=n;if(b!==void 0)throw new x("INTERNAL","A PNG export is still running");const r=I(e,{backgroundColor:"#ffffff",height:h,style:{transform:`translate(${s.toString()}px, ${i.toString()}px) scale(${a.toString()})`,transformOrigin:"top left",width:`${d.toString()}px`},width:d}),g=()=>{b=void 0};b=r,r.then(g).catch(g);const c=await z(r);if(c===null)throw new x("INTERNAL","html-to-image produced no blob");const p=globalThis.URL.createObjectURL(c);w(p,t),globalThis.setTimeout(()=>{globalThis.URL.revokeObjectURL(p)},0)},V=async(e,o,t="schema-diagram.svg")=>{const{transform:n}=E(o,d,h,v),[s,i,a]=n,r=await M(e,{backgroundColor:"#ffffff",height:h,style:{transform:`translate(${s.toString()}px, ${i.toString()}px) scale(${a.toString()})`,transformOrigin:"top left",width:`${d.toString()}px`},width:d});w(r,t)},nt=({containerRef:e,filenameBase:o,testIdPrefix:t})=>{const n=P(),s=_(),{getEdges:i}=O(),[a,r]=y(null),[g,c]=y(null),p=l=>{c(n("Export failed: {message}",{message:U(l)}))},S=async()=>{const l=e.current?.querySelector(".react-flow__viewport");if(l){r("png");try{await B(l,s,`${o}.png`)}finally{r(null)}}},N=async()=>{const l=e.current?.querySelector(".react-flow__viewport");if(l){r("svg");try{await V(l,s,`${o}.svg`)}finally{r(null)}}},D=()=>{r("json");try{q(s,i(),`${o}.json`)}finally{r(null)}},$=()=>{c(null),T(S(),p)},k=()=>{c(null),T(N(),p)};return u(G,{position:"top-right",children:[u(C,{children:[u(F,{className:"group/button inline-flex shrink-0 cursor-pointer items-center justify-center gap-1 rounded-md border border-border bg-background px-2 text-xs font-medium whitespace-nowrap hover:bg-muted disabled:pointer-events-none disabled:opacity-50","data-testid":`${t}-export-trigger`,disabled:a!==null,children:[m(A,{className:"size-3.5",icon:j,strokeWidth:2}),n("Export")]}),u(H,{align:"end",children:[m(f,{"data-testid":`${t}-export-png`,disabled:a!==null,onClick:$,children:n("PNG")}),m(f,{"data-testid":`${t}-export-svg`,disabled:a!==null,onClick:k,children:n("SVG")}),m(f,{"data-testid":`${t}-export-json`,disabled:a!==null,onClick:D,children:n("JSON")})]})]}),g!==null&&m("p",{className:"mt-1 max-w-64 text-right text-xs text-destructive","data-testid":`${t}-export-error`,role:"alert",children:g})]})};export{nt as D};
@@ -1,2 +1,2 @@
1
1
  'use client';
2
- import{c as y}from"react/compiler-runtime";import{Handle as L,Position as R,useNodesState as q,useEdgesState as Q,ReactFlow as Z,Background as J,Panel as k,Controls as X,MiniMap as ee,useNodesInitialized as te,useReactFlow as se}from"@xyflow/react";import{useState as D,useMemo as _,useRef as oe,useEffect as w}from"react";import{D as ae}from"./diagram-export-panel-miFPsocM.mjs";import{S as ne,T as x}from"./storage-tier-C2mKwYRj.mjs";import{B as E}from"./badge-r_5B4LHP.mjs";import{B as A}from"./button-q0UYSmrn.mjs";import{I as re}from"./input-CXhxesPC.mjs";import{useT as M}from"./DEFAULT_LOCALE-BQ3jRT74.mjs";import{f as le}from"./internal-BT5tH08j.mjs";import{c as N}from"./utils-bhneXptQ.mjs";import{jsx as c,jsxs as h}from"react/jsx-runtime";function ie(s){const e=y(10);let t,n,o;e[0]!==s?({className:t,selected:o,...n}=s,e[0]=s,e[1]=t,e[2]=n,e[3]=o):(t=e[1],n=e[2],o=e[3]);const r=o===!0?"":void 0;let a;e[4]!==t?(a=N("rounded-md border border-border bg-card text-card-foreground shadow-sm transition-colors","data-[selected]:border-ring data-[selected]:ring-[3px] data-[selected]:ring-ring/30",t),e[4]=t,e[5]=a):a=e[5];let l;return e[6]!==n||e[7]!==r||e[8]!==a?(l=c("div",{"data-slot":"base-node","data-selected":r,className:a,...n}),e[6]=n,e[7]=r,e[8]=a,e[9]=l):l=e[9],l}function ce(s){const e=y(8);let t,n;e[0]!==s?({className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let o;e[3]!==t?(o=N("flex items-center gap-2 rounded-t-md bg-muted/50 px-3 py-1.5",t),e[3]=t,e[4]=o):o=e[4];let r;return e[5]!==n||e[6]!==o?(r=c("div",{"data-slot":"base-node-header",className:o,...n}),e[5]=n,e[6]=o,e[7]=r):r=e[7],r}function de(s){const e=y(8);let t,n;e[0]!==s?({className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let o;e[3]!==t?(o=N("flex flex-col",t),e[3]=t,e[4]=o):o=e[4];let r;return e[5]!==n||e[6]!==o?(r=c("div",{"data-slot":"base-node-content",className:o,...n}),e[5]=n,e[6]=o,e[7]=r):r=e[7],r}const me=3,fe=(s,e,t)=>{const n=e?s:s.slice(0,me),o=n.map(a=>JSON.stringify(a)).join(" | "),r=s.length-n.length;return r>0?`${o} ${t("+{count} more",{count:r})}`:o},H=(s,e,t)=>{const n=s.enumValues??[],o=n.length===0?s.type:fe(n,e,t),r=s.ref===void 0?o:`${o} → ${s.ref}`;return s.optional===!0?`${r}?`:r},ue=s=>{const e=y(23),{data:t,selected:n}=s,o=M();let r;e[0]!==t.label||e[1]!==t.loadError||e[2]!==o?(r=t.loadError===!0?c("span",{className:"px-3 py-1.5 text-xs text-destructive","data-testid":`sd-node-${t.label}-error`,children:o("Columns unavailable")}):c("span",{className:"px-3 py-1.5 text-xs text-muted-foreground",children:"—"}),e[0]=t.label,e[1]=t.loadError,e[2]=o,e[3]=r):r=e[3];const a=r,l=`sd-node-${t.label}`;let d;e[4]!==t.label?(d=c("span",{className:"truncate font-mono text-xs font-semibold",title:t.label,children:t.label}),e[4]=t.label,e[5]=d):d=e[5];let m;e[6]!==t.tier?(m=c("span",{className:"ms-auto",children:c(ne,{tier:t.tier})}),e[6]=t.tier,e[7]=m):m=e[7];let i;e[8]!==d||e[9]!==m?(i=h(ce,{children:[d,m]}),e[8]=d,e[9]=m,e[10]=i):i=e[10];let f;e[11]!==t.columns||e[12]!==t.label||e[13]!==a||e[14]!==o?(f=t.columns.length===0?a:t.columns.map(p=>h("div",{className:N("relative flex items-center gap-2 border-t border-border px-3 py-1.5 text-xs first:border-t-0",p.pk===!0&&"bg-muted/30"),"data-testid":`sd-col-${t.label}-${p.name}`,children:[c(L,{className:"!h-2 !w-2 !-left-1 !border-border !bg-muted-foreground/70",id:p.name,isConnectable:!1,position:R.Left,type:"target"}),c("span",{className:"truncate font-mono",title:p.name,children:p.name}),p.pk===!0&&c(E,{className:"px-1 py-0 text-[10px] leading-tight",variant:"secondary",children:"PK"}),p.ref!==void 0&&c(E,{className:"px-1 py-0 text-[10px] leading-tight",variant:"outline",children:"FK"}),c("span",{className:"ms-auto truncate text-muted-foreground",title:H(p,!0,o),children:H(p,!1,o)}),c(L,{className:"!h-2 !w-2 !-right-1 !border-border !bg-muted-foreground/70",id:p.name,isConnectable:!1,position:R.Right,type:"source"})]},p.name)),e[11]=t.columns,e[12]=t.label,e[13]=a,e[14]=o,e[15]=f):f=e[15];let u;e[16]!==f?(u=c(de,{children:f}),e[16]=f,e[17]=u):u=e[17];let b;return e[18]!==n||e[19]!==l||e[20]!==i||e[21]!==u?(b=h(ie,{className:"w-64 overflow-hidden","data-testid":l,selected:n,children:[i,u]}),e[18]=n,e[19]=l,e[20]=i,e[21]=u,e[22]=b):b=e[22],b},F=256,z=112,O=36,v=24,pe=480,he=1.4,ge=s=>{const e=Math.max(1,Math.round(Math.sqrt(he*s/(F+z))));return Math.max(pe,s/e)},be=38,xe=28,B=s=>be+Math.max(1,s)*xe,Ne=(s,e)=>{const t=new Map;for(const a of s)t.set(a,[]);for(const a of e)a.to!==a.from&&t.has(a.from)&&t.has(a.to)&&t.get(a.from)?.push(a.to);const n=new Map,o=new Set,r=a=>{const l=n.get(a);if(l!==void 0)return l;if(o.has(a))return 0;o.add(a);let d=0;for(const m of t.get(a)??[])d=Math.max(d,r(m)+1);return o.delete(a),n.set(a,d),d};for(const a of s)r(a);return n},ye=(s,e,t)=>{const n=Ne(s,e),o=new Map;for(const m of s){const i=n.get(m)??0,f=o.get(i);f===void 0?o.set(i,[m]):f.push(m)}const r=s.reduce((m,i)=>m+B(t.get(i)??0)+O,0),a=ge(r),l=[];let d=0;for(const m of[...o.keys()].toSorted((i,f)=>i-f)){let i=0,f=v;for(const u of o.get(m)??[]){const b=B(t.get(u)??0);f>v&&f+b>a&&(i+=1,f=v),l.push({name:u,x:v+(d+i)*(F+z),y:f}),f+=b+O}d+=i+1}return l},ve={databaseSchema:ue},G={backgroundColor:x.shard.color},I={backgroundColor:x.global.color},Ee={global:!0,shard:!0},Se={},_e=s=>{const e=s.find(t=>t.pk===!0)?.name;return e!==void 0?e:s.some(t=>t.name==="_id")?"_id":s.some(t=>t.name==="id")?"id":s[0]?.name??"_id"},K=s=>s.flatMap(e=>e.columns.filter(t=>t.ref!==void 0).map(t=>({column:t.name,from:e.name,to:t.ref}))),we=(s,e,t)=>{const n=s.map(l=>l.name),o=new Map(s.map(l=>[l.name,l.columns.length])),r=ye(n,K(s),o),a=new Map(s.map(l=>[l.name,l]));return r.flatMap(({name:l,x:d,y:m})=>{const i=a.get(l);return i===void 0?[]:[{className:t[l],data:{columns:i.columns,label:l,loadError:e,tier:i.tier},id:l,position:{x:d,y:m},type:"databaseSchema"}]})},Me=s=>{const e=new Map(s.map(t=>[t.name,t.columns]));return K(s).flatMap(t=>{const n=e.get(t.to)??[],o=e.get(t.from)??[],r=_e(n);return!n.some(a=>a.name===r)||!o.some(a=>a.name===t.column)?[]:[{id:`${t.from}.${t.column}->${t.to}`,source:t.to,sourceHandle:r,target:t.from,targetHandle:t.column}]})},Ce=()=>{const s=y(15),e=M();let t;s[0]===Symbol.for("react.memo_cache_sentinel")?(t=h("span",{className:"flex items-center gap-1",children:[c("span",{"aria-hidden":"true",className:"size-1.5 rounded-full",style:G}),x.shard.label]}),s[0]=t):t=s[0];let n;s[1]===Symbol.for("react.memo_cache_sentinel")?(n=h("span",{className:"flex items-center gap-1",children:[c("span",{"aria-hidden":"true",className:"size-1.5 rounded-full",style:I}),x.global.label]}),s[1]=n):n=s[1];let o;s[2]===Symbol.for("react.memo_cache_sentinel")?(o=c(E,{className:"px-1 py-0 text-[10px] leading-tight",variant:"secondary",children:"PK"}),s[2]=o):o=s[2];let r;s[3]!==e?(r=e("Primary key"),s[3]=e,s[4]=r):r=s[4];let a;s[5]!==r?(a=h("span",{className:"flex items-center gap-1",children:[o,r]}),s[5]=r,s[6]=a):a=s[6];let l;s[7]===Symbol.for("react.memo_cache_sentinel")?(l=c(E,{className:"px-1 py-0 text-[10px] leading-tight",variant:"outline",children:"FK"}),s[7]=l):l=s[7];let d;s[8]!==e?(d=e("Foreign key"),s[8]=e,s[9]=d):d=s[9];let m;s[10]!==d?(m=h("span",{className:"flex items-center gap-1",children:[l,d]}),s[10]=d,s[11]=m):m=s[11];let i;return s[12]!==a||s[13]!==m?(i=h("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 rounded-xl border border-border bg-card/95 px-2.5 py-1.5 text-[11px] text-muted-foreground shadow-xs",children:[t,n,a,m]}),s[12]=a,s[13]=m,s[14]=i):i=s[14],i},$e=12,Te=s=>{const e=y(9),{containerRef:t,seedKey:n}=s,o=te(),{fitView:r}=se();let a;e[0]!==t||e[1]!==r||e[2]!==o?(a=()=>{if(!o)return;const d=()=>{le(r({duration:0,maxZoom:1.6,padding:.14}))};d();const m=t.current;if(m===null)return;const i=new ResizeObserver(()=>{d()});return i.observe(m),()=>{i.disconnect()}},e[0]=t,e[1]=r,e[2]=o,e[3]=a):a=e[3];let l;return e[4]!==t||e[5]!==r||e[6]!==o||e[7]!==n?(l=[t,r,o,n],e[4]=t,e[5]=r,e[6]=o,e[7]=n,e[8]=l):l=e[8],w(a,l),null},Ke=({columnsError:s,fill:e=!1,nodeClasses:t,tables:n,testIdPrefix:o})=>{const r=M(),[a,l]=D(Ee),[d,m]=D(""),i=_(()=>{const g=d.trim().toLowerCase();return n.filter(T=>a[T.tier]&&T.name.toLowerCase().includes(g))},[n,a,d]),f=_(()=>we(i,s??!1,t??Se),[i,s,t]),u=_(()=>Me(i),[i]),b=i.map(g=>g.name).join(","),[p,C,P]=q(f),[U,$,j]=Q(u),S=oe(null);w(()=>{C(f)},[f,C]),w(()=>{$(u)},[u,$]);const V=g=>{m(g.target.value)},W=()=>{l(g=>({...g,shard:!g.shard}))},Y=()=>{l(g=>({...g,global:!g.global}))};return n.length===0?c("section",{className:"flex flex-col gap-2","data-testid":`${o}-section`,children:c("p",{className:"text-sm text-muted-foreground","data-testid":`${o}-empty`,children:r("No tables to graph.")})}):c("section",{className:N("flex flex-col",e&&"min-h-0 flex-1"),"data-testid":`${o}-section`,children:c("div",{className:N("w-full overflow-hidden border border-border bg-muted/20",e?"min-h-0 flex-1":"h-[560px]"),"data-testid":`${o}-canvas`,ref:S,children:h(Z,{edges:U,elementsSelectable:!0,fitView:!0,minZoom:.2,nodes:p,nodesConnectable:!1,nodeTypes:ve,onEdgesChange:j,onNodesChange:P,children:[c(J,{}),c(k,{position:"top-left",children:h("div",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card/95 p-2 shadow-xs",children:[c(re,{"aria-label":r("Find table…"),className:"h-7 w-44 text-xs","data-testid":`${o}-find`,onChange:V,placeholder:r("Find table…"),value:d}),h("div",{"aria-label":r("Storage tiers"),className:"flex items-center gap-1.5",role:"group",children:[h(A,{"aria-pressed":a.shard,className:"gap-1.5","data-testid":`${o}-tier-shard`,onClick:W,size:"xs",type:"button",variant:a.shard?"default":"outline",children:[c("span",{"aria-hidden":"true",className:"size-1.5 rounded-full",style:G}),x.shard.label]}),h(A,{"aria-pressed":a.global,className:"gap-1.5","data-testid":`${o}-tier-global`,onClick:Y,size:"xs",type:"button",variant:a.global?"default":"outline",children:[c("span",{"aria-hidden":"true",className:"size-1.5 rounded-full",style:I}),x.global.label]})]})]})}),c(k,{position:"bottom-center",children:c(Ce,{})}),c(X,{showInteractive:!1}),i.length>$e&&c(ee,{className:"!border !border-border !bg-card",maskColor:"var(--color-muted)",nodeColor:"var(--color-muted-foreground)",nodeStrokeWidth:0,pannable:!0,zoomable:!0}),c(ae,{containerRef:S,filenameBase:`${o}-schema-diagram`,testIdPrefix:o}),c(Te,{containerRef:S,seedKey:b})]})})})};export{Ke as S};
2
+ import{c as y}from"react/compiler-runtime";import{Handle as L,Position as R,useNodesState as q,useEdgesState as Q,ReactFlow as Z,Background as J,Panel as k,Controls as X,MiniMap as ee,useNodesInitialized as te,useReactFlow as se}from"@xyflow/react";import{useState as D,useMemo as _,useRef as oe,useEffect as w}from"react";import{D as ae}from"./diagram-export-panel-CleSOm6J.mjs";import{S as ne,T as x}from"./storage-tier-C2mKwYRj.mjs";import{B as E}from"./badge-r_5B4LHP.mjs";import{B as A}from"./button-q0UYSmrn.mjs";import{I as re}from"./input-CXhxesPC.mjs";import{useT as M}from"./DEFAULT_LOCALE-BQ3jRT74.mjs";import{f as le}from"./internal-BT5tH08j.mjs";import{c as N}from"./utils-bhneXptQ.mjs";import{jsx as c,jsxs as h}from"react/jsx-runtime";function ie(s){const e=y(10);let t,n,o;e[0]!==s?({className:t,selected:o,...n}=s,e[0]=s,e[1]=t,e[2]=n,e[3]=o):(t=e[1],n=e[2],o=e[3]);const r=o===!0?"":void 0;let a;e[4]!==t?(a=N("rounded-md border border-border bg-card text-card-foreground shadow-sm transition-colors","data-[selected]:border-ring data-[selected]:ring-[3px] data-[selected]:ring-ring/30",t),e[4]=t,e[5]=a):a=e[5];let l;return e[6]!==n||e[7]!==r||e[8]!==a?(l=c("div",{"data-slot":"base-node","data-selected":r,className:a,...n}),e[6]=n,e[7]=r,e[8]=a,e[9]=l):l=e[9],l}function ce(s){const e=y(8);let t,n;e[0]!==s?({className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let o;e[3]!==t?(o=N("flex items-center gap-2 rounded-t-md bg-muted/50 px-3 py-1.5",t),e[3]=t,e[4]=o):o=e[4];let r;return e[5]!==n||e[6]!==o?(r=c("div",{"data-slot":"base-node-header",className:o,...n}),e[5]=n,e[6]=o,e[7]=r):r=e[7],r}function de(s){const e=y(8);let t,n;e[0]!==s?({className:t,...n}=s,e[0]=s,e[1]=t,e[2]=n):(t=e[1],n=e[2]);let o;e[3]!==t?(o=N("flex flex-col",t),e[3]=t,e[4]=o):o=e[4];let r;return e[5]!==n||e[6]!==o?(r=c("div",{"data-slot":"base-node-content",className:o,...n}),e[5]=n,e[6]=o,e[7]=r):r=e[7],r}const me=3,fe=(s,e,t)=>{const n=e?s:s.slice(0,me),o=n.map(a=>JSON.stringify(a)).join(" | "),r=s.length-n.length;return r>0?`${o} ${t("+{count} more",{count:r})}`:o},H=(s,e,t)=>{const n=s.enumValues??[],o=n.length===0?s.type:fe(n,e,t),r=s.ref===void 0?o:`${o} → ${s.ref}`;return s.optional===!0?`${r}?`:r},ue=s=>{const e=y(23),{data:t,selected:n}=s,o=M();let r;e[0]!==t.label||e[1]!==t.loadError||e[2]!==o?(r=t.loadError===!0?c("span",{className:"px-3 py-1.5 text-xs text-destructive","data-testid":`sd-node-${t.label}-error`,children:o("Columns unavailable")}):c("span",{className:"px-3 py-1.5 text-xs text-muted-foreground",children:"—"}),e[0]=t.label,e[1]=t.loadError,e[2]=o,e[3]=r):r=e[3];const a=r,l=`sd-node-${t.label}`;let d;e[4]!==t.label?(d=c("span",{className:"truncate font-mono text-xs font-semibold",title:t.label,children:t.label}),e[4]=t.label,e[5]=d):d=e[5];let m;e[6]!==t.tier?(m=c("span",{className:"ms-auto",children:c(ne,{tier:t.tier})}),e[6]=t.tier,e[7]=m):m=e[7];let i;e[8]!==d||e[9]!==m?(i=h(ce,{children:[d,m]}),e[8]=d,e[9]=m,e[10]=i):i=e[10];let f;e[11]!==t.columns||e[12]!==t.label||e[13]!==a||e[14]!==o?(f=t.columns.length===0?a:t.columns.map(p=>h("div",{className:N("relative flex items-center gap-2 border-t border-border px-3 py-1.5 text-xs first:border-t-0",p.pk===!0&&"bg-muted/30"),"data-testid":`sd-col-${t.label}-${p.name}`,children:[c(L,{className:"!h-2 !w-2 !-left-1 !border-border !bg-muted-foreground/70",id:p.name,isConnectable:!1,position:R.Left,type:"target"}),c("span",{className:"truncate font-mono",title:p.name,children:p.name}),p.pk===!0&&c(E,{className:"px-1 py-0 text-[10px] leading-tight",variant:"secondary",children:"PK"}),p.ref!==void 0&&c(E,{className:"px-1 py-0 text-[10px] leading-tight",variant:"outline",children:"FK"}),c("span",{className:"ms-auto truncate text-muted-foreground",title:H(p,!0,o),children:H(p,!1,o)}),c(L,{className:"!h-2 !w-2 !-right-1 !border-border !bg-muted-foreground/70",id:p.name,isConnectable:!1,position:R.Right,type:"source"})]},p.name)),e[11]=t.columns,e[12]=t.label,e[13]=a,e[14]=o,e[15]=f):f=e[15];let u;e[16]!==f?(u=c(de,{children:f}),e[16]=f,e[17]=u):u=e[17];let b;return e[18]!==n||e[19]!==l||e[20]!==i||e[21]!==u?(b=h(ie,{className:"w-64 overflow-hidden","data-testid":l,selected:n,children:[i,u]}),e[18]=n,e[19]=l,e[20]=i,e[21]=u,e[22]=b):b=e[22],b},F=256,z=112,O=36,v=24,pe=480,he=1.4,ge=s=>{const e=Math.max(1,Math.round(Math.sqrt(he*s/(F+z))));return Math.max(pe,s/e)},be=38,xe=28,B=s=>be+Math.max(1,s)*xe,Ne=(s,e)=>{const t=new Map;for(const a of s)t.set(a,[]);for(const a of e)a.to!==a.from&&t.has(a.from)&&t.has(a.to)&&t.get(a.from)?.push(a.to);const n=new Map,o=new Set,r=a=>{const l=n.get(a);if(l!==void 0)return l;if(o.has(a))return 0;o.add(a);let d=0;for(const m of t.get(a)??[])d=Math.max(d,r(m)+1);return o.delete(a),n.set(a,d),d};for(const a of s)r(a);return n},ye=(s,e,t)=>{const n=Ne(s,e),o=new Map;for(const m of s){const i=n.get(m)??0,f=o.get(i);f===void 0?o.set(i,[m]):f.push(m)}const r=s.reduce((m,i)=>m+B(t.get(i)??0)+O,0),a=ge(r),l=[];let d=0;for(const m of[...o.keys()].toSorted((i,f)=>i-f)){let i=0,f=v;for(const u of o.get(m)??[]){const b=B(t.get(u)??0);f>v&&f+b>a&&(i+=1,f=v),l.push({name:u,x:v+(d+i)*(F+z),y:f}),f+=b+O}d+=i+1}return l},ve={databaseSchema:ue},G={backgroundColor:x.shard.color},I={backgroundColor:x.global.color},Ee={global:!0,shard:!0},Se={},_e=s=>{const e=s.find(t=>t.pk===!0)?.name;return e!==void 0?e:s.some(t=>t.name==="_id")?"_id":s.some(t=>t.name==="id")?"id":s[0]?.name??"_id"},K=s=>s.flatMap(e=>e.columns.filter(t=>t.ref!==void 0).map(t=>({column:t.name,from:e.name,to:t.ref}))),we=(s,e,t)=>{const n=s.map(l=>l.name),o=new Map(s.map(l=>[l.name,l.columns.length])),r=ye(n,K(s),o),a=new Map(s.map(l=>[l.name,l]));return r.flatMap(({name:l,x:d,y:m})=>{const i=a.get(l);return i===void 0?[]:[{className:t[l],data:{columns:i.columns,label:l,loadError:e,tier:i.tier},id:l,position:{x:d,y:m},type:"databaseSchema"}]})},Me=s=>{const e=new Map(s.map(t=>[t.name,t.columns]));return K(s).flatMap(t=>{const n=e.get(t.to)??[],o=e.get(t.from)??[],r=_e(n);return!n.some(a=>a.name===r)||!o.some(a=>a.name===t.column)?[]:[{id:`${t.from}.${t.column}->${t.to}`,source:t.to,sourceHandle:r,target:t.from,targetHandle:t.column}]})},Ce=()=>{const s=y(15),e=M();let t;s[0]===Symbol.for("react.memo_cache_sentinel")?(t=h("span",{className:"flex items-center gap-1",children:[c("span",{"aria-hidden":"true",className:"size-1.5 rounded-full",style:G}),x.shard.label]}),s[0]=t):t=s[0];let n;s[1]===Symbol.for("react.memo_cache_sentinel")?(n=h("span",{className:"flex items-center gap-1",children:[c("span",{"aria-hidden":"true",className:"size-1.5 rounded-full",style:I}),x.global.label]}),s[1]=n):n=s[1];let o;s[2]===Symbol.for("react.memo_cache_sentinel")?(o=c(E,{className:"px-1 py-0 text-[10px] leading-tight",variant:"secondary",children:"PK"}),s[2]=o):o=s[2];let r;s[3]!==e?(r=e("Primary key"),s[3]=e,s[4]=r):r=s[4];let a;s[5]!==r?(a=h("span",{className:"flex items-center gap-1",children:[o,r]}),s[5]=r,s[6]=a):a=s[6];let l;s[7]===Symbol.for("react.memo_cache_sentinel")?(l=c(E,{className:"px-1 py-0 text-[10px] leading-tight",variant:"outline",children:"FK"}),s[7]=l):l=s[7];let d;s[8]!==e?(d=e("Foreign key"),s[8]=e,s[9]=d):d=s[9];let m;s[10]!==d?(m=h("span",{className:"flex items-center gap-1",children:[l,d]}),s[10]=d,s[11]=m):m=s[11];let i;return s[12]!==a||s[13]!==m?(i=h("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 rounded-xl border border-border bg-card/95 px-2.5 py-1.5 text-[11px] text-muted-foreground shadow-xs",children:[t,n,a,m]}),s[12]=a,s[13]=m,s[14]=i):i=s[14],i},$e=12,Te=s=>{const e=y(9),{containerRef:t,seedKey:n}=s,o=te(),{fitView:r}=se();let a;e[0]!==t||e[1]!==r||e[2]!==o?(a=()=>{if(!o)return;const d=()=>{le(r({duration:0,maxZoom:1.6,padding:"14%"}))};d();const m=t.current;if(m===null)return;const i=new ResizeObserver(()=>{d()});return i.observe(m),()=>{i.disconnect()}},e[0]=t,e[1]=r,e[2]=o,e[3]=a):a=e[3];let l;return e[4]!==t||e[5]!==r||e[6]!==o||e[7]!==n?(l=[t,r,o,n],e[4]=t,e[5]=r,e[6]=o,e[7]=n,e[8]=l):l=e[8],w(a,l),null},Ke=({columnsError:s,fill:e=!1,nodeClasses:t,tables:n,testIdPrefix:o})=>{const r=M(),[a,l]=D(Ee),[d,m]=D(""),i=_(()=>{const g=d.trim().toLowerCase();return n.filter(T=>a[T.tier]&&T.name.toLowerCase().includes(g))},[n,a,d]),f=_(()=>we(i,s??!1,t??Se),[i,s,t]),u=_(()=>Me(i),[i]),b=i.map(g=>g.name).join(","),[p,C,P]=q(f),[U,$,j]=Q(u),S=oe(null);w(()=>{C(f)},[f,C]),w(()=>{$(u)},[u,$]);const V=g=>{m(g.target.value)},W=()=>{l(g=>({...g,shard:!g.shard}))},Y=()=>{l(g=>({...g,global:!g.global}))};return n.length===0?c("section",{className:"flex flex-col gap-2","data-testid":`${o}-section`,children:c("p",{className:"text-sm text-muted-foreground","data-testid":`${o}-empty`,children:r("No tables to graph.")})}):c("section",{className:N("flex flex-col",e&&"min-h-0 flex-1"),"data-testid":`${o}-section`,children:c("div",{className:N("w-full overflow-hidden border border-border bg-muted/20",e?"min-h-0 flex-1":"h-[560px]"),"data-testid":`${o}-canvas`,ref:S,children:h(Z,{edges:U,elementsSelectable:!0,fitView:!0,minZoom:.2,nodes:p,nodesConnectable:!1,nodeTypes:ve,onEdgesChange:j,onNodesChange:P,children:[c(J,{}),c(k,{position:"top-left",children:h("div",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card/95 p-2 shadow-xs",children:[c(re,{"aria-label":r("Find table…"),className:"h-7 w-44 text-xs","data-testid":`${o}-find`,onChange:V,placeholder:r("Find table…"),value:d}),h("div",{"aria-label":r("Storage tiers"),className:"flex items-center gap-1.5",role:"group",children:[h(A,{"aria-pressed":a.shard,className:"gap-1.5","data-testid":`${o}-tier-shard`,onClick:W,size:"xs",type:"button",variant:a.shard?"default":"outline",children:[c("span",{"aria-hidden":"true",className:"size-1.5 rounded-full",style:G}),x.shard.label]}),h(A,{"aria-pressed":a.global,className:"gap-1.5","data-testid":`${o}-tier-global`,onClick:Y,size:"xs",type:"button",variant:a.global?"default":"outline",children:[c("span",{"aria-hidden":"true",className:"size-1.5 rounded-full",style:I}),x.global.label]})]})]})}),c(k,{position:"bottom-center",children:c(Ce,{})}),c(X,{showInteractive:!1}),i.length>$e&&c(ee,{className:"!border !border-border !bg-card",maskColor:"var(--color-muted)",nodeColor:"var(--color-muted-foreground)",nodeStrokeWidth:0,pannable:!0,zoomable:!0}),c(ae,{containerRef:S,filenameBase:`${o}-schema-diagram`,testIdPrefix:o}),c(Te,{containerRef:S,seedKey:b})]})})})};export{Ke as S};
@@ -1 +1 @@
1
- import{a as we}from"./chunk-ACCTEC6Y.js";import{a as ve}from"./chunk-UEONVTOV.js";import{i as me}from"./chunk-Z6PYAG36.js";import"./chunk-4SY2N2RS.js";import"./chunk-4AG356VE.js";import{a as q}from"./chunk-QHI77TGI.js";import"./chunk-SCTYLLJT.js";import"./chunk-OZID3UYF.js";import{a as ue}from"./chunk-O46IV64X.js";import"./chunk-L27FKJTG.js";import{a as ae,b as re,c as ne,d as L,e as h,f as p}from"./chunk-KMBE7RTC.js";import{a as X}from"./chunk-LYVYUTQY.js";import{c as Ne}from"./chunk-NP6H72XD.js";import{a as ee,e as te}from"./chunk-NPHGFVNE.js";import{n as ce}from"./chunk-YESGXFAR.js";import"./chunk-ZPQBVYNN.js";import{B as Y,h as ie,i as de,j as U,p as pe,s as z}from"./chunk-CDIV23I2.js";import"./chunk-PDBW6GTJ.js";import{a as be}from"./chunk-A6TVTNKO.js";import{a as ke,b as Se}from"./chunk-ADABTCDI.js";import{a as s,d as he}from"./chunk-5PEAXTYQ.js";var xe=he(be(),1),i=he(ke(),1);var t=he(Se(),1);var Ce=["queued","running","rollingBack","paused","waiting","complete","errored","terminated"],Oe=["pause","resume","restart","terminate"],Ie=s(l=>{let e=(0,xe.c)(7),{busy:w,id:x,onAct:N}=l,b=Y(),a;e[0]!==w||e[1]!==x||e[2]!==N||e[3]!==b?(a=Oe.map(m=>m==="restart"?(0,t.jsx)(ve,{confirmLabel:b("Restart?"),disabled:w,onConfirm:s(()=>{N(m)},"onConfirm"),testId:`workflow-instance-${m}-${x}`,children:b(m)},m):(0,t.jsx)(q,{"data-testid":`workflow-instance-${m}-${x}`,disabled:w,onClick:s(()=>{N(m)},"onClick"),size:"sm",type:"button",variant:"ghost",children:b(m)},m)),e[0]=w,e[1]=x,e[2]=N,e[3]=b,e[4]=a):a=e[4];let d;return e[5]!==a?(d=(0,t.jsx)(t.Fragment,{children:a}),e[5]=a,e[6]=d):d=e[6],d},"Ce"),$e="WORKFLOWS_NOT_CONFIGURED",We=s(l=>typeof l=="object"&&l!==null&&l.code===$e,"Oe"),Ae=s(l=>{let e=l.error??l.output;if(e===void 0)return"\u2014";try{return JSON.stringify(e,pe)}catch{return"(unserializable)"}},"Ee"),Te=s(({loadDetail:l,loadInstances:e,readOnly:w,runAction:x,workflowName:N})=>{let b=ce(),a=Y(),[d,m]=(0,i.useState)(null),[v,R]=(0,i.useState)(null),[S,B]=(0,i.useState)(""),[C,O]=(0,i.useState)(null),[F,W]=(0,i.useState)(!1),[_,j]=(0,i.useState)(null),g=(0,i.useRef)(0),y=(0,i.useRef)(0),k=(0,i.useRef)(0),A=l??(n=>b.getWorkflowInstance(n)),I=w?void 0:x??(e===void 0?n=>b.setWorkflowInstanceStatus(n):void 0),T=s(async()=>{y.current+=1;let n=y.current;O(null),W(!1);let u=S===""?void 0:S;try{if(e===void 0){let r=await b.listWorkflowInstances({name:N,status:u});if(n!==y.current)return;if(r.configured===!1){m(null),W(!0);return}m(r.instances);return}let f=await e({name:N,status:u});n===y.current&&m(f)}catch(f){if(n!==y.current)return;m(null),We(f)?W(!0):O(U(f))}},"E");(0,i.useEffect)(()=>{g.current+=1,k.current+=1,R(null),z(T())},[N,S]);let P=s(async n=>{k.current+=1;let u=k.current;O(null);try{let f=await A({id:n,name:N});u===k.current&&R(f)}catch(f){u===k.current&&O(U(f))}},"W"),E=s(()=>{k.current+=1,R(null)},"A"),J=s(async(n,u)=>{if(I===void 0)return;let f=g.current;j(n),O(null);try{await I({action:u,id:n,name:N}),f===g.current&&await T()}catch(r){O(U(r))}j(null)},"L");return(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"lunora-workflow-instances",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("h3",{className:"text-sm font-medium",children:a("Instance history")}),(0,t.jsxs)("select",{"aria-label":a("Filter by status"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"workflow-instances-filter",onChange:s(n=>{B(n.target.value)},"onChange"),value:S,children:[(0,t.jsx)("option",{value:"",children:a("All statuses")}),Ce.map(n=>(0,t.jsx)("option",{value:n,children:n},n))]})]}),C!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflow-instances-error",role:"alert",children:C}),F&&(0,t.jsx)(ue,{description:a("Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN in your .dev.vars to enable workflow instance history."),testId:"workflow-instances-unconfigured",title:a("Workflow inspection not configured")}),!F&&d!==null&&d.length===0&&(0,t.jsx)(ue,{description:a("No instances match this filter for the selected workflow."),testId:"workflow-instances-empty",title:a("No instances")}),d!==null&&d.length>0&&(0,t.jsx)(ee,{className:"overflow-hidden py-0",children:(0,t.jsx)(te,{className:"px-0",children:(0,t.jsxs)(ae,{"data-testid":"workflow-instances-table",children:[(0,t.jsx)(re,{children:(0,t.jsxs)(L,{children:[(0,t.jsx)(h,{children:a("Instance id")}),(0,t.jsx)(h,{children:a("Status")}),(0,t.jsx)(h,{children:a("Created")}),(0,t.jsx)(h,{children:a("Ended")}),(0,t.jsx)(h,{"aria-label":a("Actions")})]})}),(0,t.jsx)(ne,{children:d.map(n=>(0,t.jsxs)(L,{"data-testid":`workflow-instance-${n.id}`,children:[(0,t.jsx)(p,{className:"font-mono text-xs",children:n.id}),(0,t.jsx)(p,{className:"font-mono text-xs",children:n.status}),(0,t.jsx)(p,{className:"text-muted-foreground tabular-nums",children:n.createdOn??"\u2014"}),(0,t.jsx)(p,{className:"text-muted-foreground tabular-nums",children:n.endedOn??"\u2014"}),(0,t.jsx)(p,{className:"text-right",children:(0,t.jsxs)("div",{className:"flex justify-end gap-1.5",children:[(0,t.jsx)(q,{"data-testid":`workflow-instance-steps-${n.id}`,onClick:s(()=>{z(P(n.id))},"onClick"),size:"sm",type:"button",variant:"outline",children:a("Steps")}),I!==void 0&&(0,t.jsx)(Ie,{busy:_===n.id,id:n.id,onAct:s(u=>{z(J(n.id,u))},"onAct")},N)]})})]},n.id))})]})})}),v!==null&&(0,t.jsx)(ee,{className:"overflow-hidden py-0","data-testid":"workflow-instance-detail",children:(0,t.jsxs)(te,{className:"flex flex-col gap-2 px-4 py-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("span",{className:"font-mono text-xs",children:[a("Steps")," \xB7 ",v.id]}),(0,t.jsx)(q,{"data-testid":"workflow-instance-detail-close",onClick:E,size:"xs",type:"button",variant:"ghost",children:a("Close")})]}),v.steps.length===0?(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:a("This instance has no recorded steps yet.")}):(0,t.jsxs)(ae,{"data-testid":"workflow-instance-steps",children:[(0,t.jsx)(re,{children:(0,t.jsxs)(L,{children:[(0,t.jsx)(h,{children:a("Step")}),(0,t.jsx)(h,{children:a("Type")}),(0,t.jsx)(h,{children:a("Attempts")}),(0,t.jsx)(h,{children:a("Started")}),(0,t.jsx)(h,{children:a("Output")})]})}),(0,t.jsx)(ne,{children:v.steps.map((n,u)=>(0,t.jsxs)(L,{"data-testid":`workflow-step-${String(u)}`,children:[(0,t.jsx)(p,{className:"font-mono text-xs",children:n.name}),(0,t.jsx)(p,{className:"text-xs text-muted-foreground",children:n.type??"\u2014"}),(0,t.jsx)(p,{className:"tabular-nums",children:n.attempts??"\u2014"}),(0,t.jsx)(p,{className:"text-muted-foreground tabular-nums",children:n.start??"\u2014"}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:Ae(n)})]},`${n.name}:${String(u)}`))})]})]})})]})},"_e"),_e=ie(X.createWorkflowInstance),Ee=ie(X.getWorkflowInstanceStatus),Je=ie(X.sendWorkflowEvent),De=s(l=>{if(l.error)return`${l.error.name}: ${l.error.message}`;if(l.output===void 0)return"\u2014";try{return JSON.stringify(l.output,pe)}catch{return"(unserializable)"}},"$e"),ge=s(l=>{let e=l.trim();if(e==="")return{value:void 0};try{return{value:JSON.parse(e)}}catch{return null}},"ve"),Fe=s((l,e)=>l.some(w=>w.exportName===e)?e:l[0]?.exportName??"","Fe"),Pe=s(l=>{let e=(0,xe.c)(72),{eventTypes:w,exportName:x,onSent:N}=l,b=ce(),a=Y(),[d,m]=(0,i.useState)(""),[v,R]=(0,i.useState)(""),[S,B]=(0,i.useState)(""),[C,O]=(0,i.useState)(!1),[F,W]=(0,i.useState)(null),_;e[0]!==b||e[1]!==x||e[2]!==N||e[3]!==a||e[4]!==v?(_=s(async(D,oe)=>{try{await b.query(Je,{exportName:x,id:D,payload:oe,type:v},de(""))}catch(fe){W(U(fe));return}try{await N(x,D)}catch(fe){let ye=fe;W(`${a("Event sent, but refreshing the instance failed")}: ${U(ye)}`)}},"_"),e[0]=b,e[1]=x,e[2]=N,e[3]=a,e[4]=v,e[5]=_):_=e[5];let j=_,g;e[6]!==j||e[7]!==d||e[8]!==S||e[9]!==a?(g=s(async()=>{let D=d.trim(),oe=ge(S);if(oe===null){W(a("Payload must be valid JSON"));return}O(!0),W(null),await j(D,oe.value).finally(()=>{O(!1)})},"N"),e[6]=j,e[7]=d,e[8]=S,e[9]=a,e[10]=g):g=e[10];let y=g,k;e[11]!==a?(k=a("Send event"),e[11]=a,e[12]=k):k=e[12];let A;e[13]!==k?(A=(0,t.jsx)("h3",{className:"text-sm font-medium",children:k}),e[13]=k,e[14]=A):A=e[14];let I;e[15]!==F?(I=F!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-event-error",role:"alert",children:F}),e[15]=F,e[16]=I):I=e[16];let T;e[17]!==a?(T=a("Instance id"),e[17]=a,e[18]=T):T=e[18];let P;e[19]===Symbol.for("react.memo_cache_sentinel")?(P=s(D=>{m(D.target.value)},"O"),e[19]=P):P=e[19];let E;e[20]!==a?(E=a("Instance id"),e[20]=a,e[21]=E):E=e[21];let J;e[22]!==d||e[23]!==T||e[24]!==E?(J=(0,t.jsx)(me,{"aria-label":T,className:"max-w-48","data-testid":"workflows-event-id",onChange:P,placeholder:E,value:d}),e[22]=d,e[23]=T,e[24]=E,e[25]=J):J=e[25];let n;e[26]!==a?(n=a("Event type"),e[26]=a,e[27]=n):n=e[27];let u;e[28]===Symbol.for("react.memo_cache_sentinel")?(u=s(D=>{R(D.target.value)},"L"),e[28]=u):u=e[28];let f;e[29]!==a?(f=a("Event type"),e[29]=a,e[30]=f):f=e[30];let r;e[31]!==n||e[32]!==f||e[33]!==v?(r=(0,t.jsx)(me,{"aria-label":n,className:"max-w-48","data-testid":"workflows-event-type",list:"workflows-event-types",onChange:u,placeholder:f,value:v}),e[31]=n,e[32]=f,e[33]=v,e[34]=r):r=e[34];let c;e[35]!==w?(c=w.map(Le),e[35]=w,e[36]=c):c=e[36];let o;e[37]!==c?(o=(0,t.jsx)("datalist",{"data-testid":"workflows-event-types",id:"workflows-event-types",children:c}),e[37]=c,e[38]=o):o=e[38];let $;e[39]!==x||e[40]!==d||e[41]!==C||e[42]!==v?($=C||x===""||d.trim()===""||v.trim()==="",e[39]=x,e[40]=d,e[41]=C,e[42]=v,e[43]=$):$=e[43];let K;e[44]!==y?(K=s(()=>{z(y())},"z"),e[44]=y,e[45]=K):K=e[45];let G;e[46]!==C||e[47]!==a?(G=a(C?"Sending\u2026":"Send event"),e[46]=C,e[47]=a,e[48]=G):G=e[48];let M;e[49]!==$||e[50]!==K||e[51]!==G?(M=(0,t.jsx)(q,{"data-testid":"workflows-event-button",disabled:$,onClick:K,children:G}),e[49]=$,e[50]=K,e[51]=G,e[52]=M):M=e[52];let Z;e[53]!==r||e[54]!==o||e[55]!==M||e[56]!==J?(Z=(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[J,r,o,M]}),e[53]=r,e[54]=o,e[55]=M,e[56]=J,e[57]=Z):Z=e[57];let H;e[58]!==a?(H=a("Payload (JSON)"),e[58]=a,e[59]=H):H=e[59];let se;e[60]===Symbol.for("react.memo_cache_sentinel")?(se=s(D=>{B(D.target.value)},"Y"),e[60]=se):se=e[60];let Q;e[61]!==a?(Q=a("Payload (JSON, optional)"),e[61]=a,e[62]=Q):Q=e[62];let V;e[63]!==S||e[64]!==H||e[65]!==Q?(V=(0,t.jsx)(we,{"aria-label":H,className:"font-mono","data-testid":"workflows-event-payload",onChange:se,placeholder:Q,value:S}),e[63]=S,e[64]=H,e[65]=Q,e[66]=V):V=e[66];let le;return e[67]!==Z||e[68]!==V||e[69]!==A||e[70]!==I?(le=(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-event",children:[A,I,Z,V]}),e[67]=Z,e[68]=V,e[69]=A,e[70]=I,e[71]=le):le=e[71],le},"Pe"),Ve=s(()=>{let l=ce(),e=Y(),{data:w,error:x}=Ne(X.listWorkflows,{}),[N,b]=(0,i.useState)(""),[a,d]=(0,i.useState)(""),[m,v]=(0,i.useState)(""),[R,S]=(0,i.useState)(!1),[B,C]=(0,i.useState)(null),[O,F]=(0,i.useState)([]),[W,_]=(0,i.useState)(null),j=w!==void 0,g=Array.isArray(w?.workflows)?[...w.workflows].toSorted((r,c)=>r.exportName.localeCompare(c.exportName)):[],y=Fe(g,N),k=g.find(r=>r.exportName===y),A=s(r=>{F(c=>{let o=c.filter($=>!($.exportName===r.exportName&&$.id===r.id));return[r,...o]})},"T"),I=s(async()=>{let r=y;if(r==="")return;let c=ge(m);if(c===null){C(e("Params must be valid JSON"));return}S(!0),C(null);try{let o=a.trim(),$=await l.query(_e,{exportName:r,id:o===""?void 0:o,params:c.value},de(""));A({exportName:r,id:$.id,status:$.status}),d("")}catch(o){C(U(o))}S(!1)},"F"),T=s(()=>{z(I())},"P"),P=s(async(r,c)=>{_(c);try{let o=await l.query(Ee,{exportName:r,id:c},de(""));A({error:o.error,exportName:r,id:o.id,output:o.output,status:o.status})}catch(o){throw _(null),o}_(null)},"O"),E=s(async(r,c)=>{try{await P(r,c)}catch(o){C(U(o))}},"E"),J=s(r=>{b(r.target.value)},"W"),n=s(r=>{d(r.target.value)},"A"),u=s(r=>{v(r.target.value)},"L"),f=s(r=>{let{export:c,id:o}=r.currentTarget.dataset;c!==void 0&&o!==void 0&&z(E(c,o))},"n");return(0,t.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-workflows-panel",children:[x!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-error",role:"alert",children:x}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:e("Workflows are declared in code with defineWorkflow and run as durable Cloudflare Workflows. Start an instance and observe its status below.")}),j&&g.length===0?(0,t.jsx)(ue,{description:e("No defineWorkflow is declared in lunora/workflows.ts in this deployment. Add one to run a durable, multi-step workflow."),testId:"workflows-empty",title:e("No workflows defined")}):(0,t.jsx)(ee,{className:"overflow-hidden py-0",children:(0,t.jsx)(te,{className:"px-0",children:(0,t.jsxs)(ae,{"data-testid":"workflows-table",children:[(0,t.jsx)(re,{children:(0,t.jsxs)(L,{children:[(0,t.jsx)(h,{children:e("Export")}),(0,t.jsx)(h,{children:e("Name")}),(0,t.jsx)(h,{children:e("Class")})]})}),(0,t.jsx)(ne,{children:g.map(r=>(0,t.jsxs)(L,{"data-testid":`workflows-row-${r.exportName}`,children:[(0,t.jsx)(p,{className:"font-mono text-xs",children:r.exportName}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:r.name}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:r.className})]},r.exportName))})]})})}),g.length>0&&(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-start",children:[(0,t.jsx)("h3",{className:"text-sm font-medium",children:e("Start instance")}),B!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-start-error",role:"alert",children:B}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("select",{"aria-label":e("Workflow"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"workflows-start-select",onChange:J,value:y,children:g.map(r=>(0,t.jsx)("option",{value:r.exportName,children:r.exportName},r.exportName))}),(0,t.jsx)(me,{"aria-label":e("Instance id (optional)"),className:"max-w-48","data-testid":"workflows-start-id",onChange:n,placeholder:e("Instance id (optional)"),value:a}),(0,t.jsx)(q,{"data-testid":"workflows-start-button",disabled:R||y==="",onClick:T,children:e(R?"Starting\u2026":"Start instance")})]}),(0,t.jsx)(we,{"aria-label":e("Params (JSON)"),className:"font-mono","data-testid":"workflows-start-params",onChange:u,placeholder:e("Params (JSON, optional)"),value:m})]}),g.length>0&&(0,t.jsx)(Pe,{eventTypes:w?.eventTypes??[],exportName:y,onSent:P},y),O.length>0&&(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-instances",children:[(0,t.jsx)("h3",{className:"text-sm font-medium",children:e("Instances")}),(0,t.jsx)(ee,{className:"overflow-hidden py-0",children:(0,t.jsx)(te,{className:"px-0",children:(0,t.jsxs)(ae,{"data-testid":"workflows-instances-table",children:[(0,t.jsx)(re,{children:(0,t.jsxs)(L,{children:[(0,t.jsx)(h,{children:e("Workflow")}),(0,t.jsx)(h,{children:e("Instance id")}),(0,t.jsx)(h,{children:e("Status")}),(0,t.jsx)(h,{children:e("Output")}),(0,t.jsx)(h,{})]})}),(0,t.jsx)(ne,{children:O.map(r=>(0,t.jsxs)(L,{"data-testid":`workflows-instance-${r.id}`,children:[(0,t.jsx)(p,{className:"font-mono text-xs",children:r.exportName}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:r.id}),(0,t.jsx)(p,{className:"font-mono text-xs",children:r.status}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:De(r)}),(0,t.jsx)(p,{children:(0,t.jsx)(q,{"data-export":r.exportName,"data-id":r.id,"data-testid":`workflows-instance-refresh-${r.id}`,disabled:W===r.id,onClick:f,size:"xs",variant:"outline",children:W===r.id?e("Refreshing\u2026"):e("Refresh")})})]},`${r.exportName}:${r.id}`))})]})})})]}),k!==void 0&&(0,t.jsx)(Te,{workflowName:k.name})]})},"Ze");function Le(l){return(0,t.jsx)("option",{value:l,children:l},l)}s(Le,"De");export{Ve as default};
1
+ import{a as we}from"./chunk-5FHGTA7V.js";import{a as ve}from"./chunk-M6WDFEUZ.js";import{j as me}from"./chunk-SQO3WGXH.js";import"./chunk-R76ATTPC.js";import"./chunk-4AG356VE.js";import{a as q}from"./chunk-ECXQQPVU.js";import"./chunk-EOHXBC4U.js";import"./chunk-JEJV6SVN.js";import{a as ue}from"./chunk-V5ZKAZR6.js";import"./chunk-DMQVY5L7.js";import{a as ae,b as re,c as ne,d as L,e as h,f as p}from"./chunk-WVAWKCNQ.js";import{a as X}from"./chunk-LYVYUTQY.js";import{c as Ne}from"./chunk-LUHBGCMO.js";import{a as ee,e as te}from"./chunk-VUMS4VIV.js";import{n as ce}from"./chunk-PLCYDHU3.js";import"./chunk-WY23EROJ.js";import{B as Y,h as ie,i as de,j as U,p as pe,s as z}from"./chunk-G4H5DPO6.js";import"./chunk-JSVT5VBU.js";import{a as be}from"./chunk-A6TVTNKO.js";import{a as ke,b as Se}from"./chunk-ADABTCDI.js";import{a as s,d as he}from"./chunk-5PEAXTYQ.js";var xe=he(be(),1),i=he(ke(),1);var t=he(Se(),1);var Ce=["queued","running","rollingBack","paused","waiting","complete","errored","terminated"],Oe=["pause","resume","restart","terminate"],Ie=s(l=>{let e=(0,xe.c)(7),{busy:w,id:x,onAct:N}=l,b=Y(),a;e[0]!==w||e[1]!==x||e[2]!==N||e[3]!==b?(a=Oe.map(m=>m==="restart"?(0,t.jsx)(ve,{confirmLabel:b("Restart?"),disabled:w,onConfirm:s(()=>{N(m)},"onConfirm"),testId:`workflow-instance-${m}-${x}`,children:b(m)},m):(0,t.jsx)(q,{"data-testid":`workflow-instance-${m}-${x}`,disabled:w,onClick:s(()=>{N(m)},"onClick"),size:"sm",type:"button",variant:"ghost",children:b(m)},m)),e[0]=w,e[1]=x,e[2]=N,e[3]=b,e[4]=a):a=e[4];let d;return e[5]!==a?(d=(0,t.jsx)(t.Fragment,{children:a}),e[5]=a,e[6]=d):d=e[6],d},"Ce"),$e="WORKFLOWS_NOT_CONFIGURED",We=s(l=>typeof l=="object"&&l!==null&&l.code===$e,"Oe"),Ae=s(l=>{let e=l.error??l.output;if(e===void 0)return"\u2014";try{return JSON.stringify(e,pe)}catch{return"(unserializable)"}},"Ee"),Te=s(({loadDetail:l,loadInstances:e,readOnly:w,runAction:x,workflowName:N})=>{let b=ce(),a=Y(),[d,m]=(0,i.useState)(null),[v,R]=(0,i.useState)(null),[S,B]=(0,i.useState)(""),[C,O]=(0,i.useState)(null),[F,W]=(0,i.useState)(!1),[_,j]=(0,i.useState)(null),g=(0,i.useRef)(0),y=(0,i.useRef)(0),k=(0,i.useRef)(0),A=l??(n=>b.getWorkflowInstance(n)),I=w?void 0:x??(e===void 0?n=>b.setWorkflowInstanceStatus(n):void 0),T=s(async()=>{y.current+=1;let n=y.current;O(null),W(!1);let u=S===""?void 0:S;try{if(e===void 0){let r=await b.listWorkflowInstances({name:N,status:u});if(n!==y.current)return;if(r.configured===!1){m(null),W(!0);return}m(r.instances);return}let f=await e({name:N,status:u});n===y.current&&m(f)}catch(f){if(n!==y.current)return;m(null),We(f)?W(!0):O(U(f))}},"E");(0,i.useEffect)(()=>{g.current+=1,k.current+=1,R(null),z(T())},[N,S]);let P=s(async n=>{k.current+=1;let u=k.current;O(null);try{let f=await A({id:n,name:N});u===k.current&&R(f)}catch(f){u===k.current&&O(U(f))}},"W"),E=s(()=>{k.current+=1,R(null)},"A"),J=s(async(n,u)=>{if(I===void 0)return;let f=g.current;j(n),O(null);try{await I({action:u,id:n,name:N}),f===g.current&&await T()}catch(r){O(U(r))}j(null)},"L");return(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"lunora-workflow-instances",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("h3",{className:"text-sm font-medium",children:a("Instance history")}),(0,t.jsxs)("select",{"aria-label":a("Filter by status"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"workflow-instances-filter",onChange:s(n=>{B(n.target.value)},"onChange"),value:S,children:[(0,t.jsx)("option",{value:"",children:a("All statuses")}),Ce.map(n=>(0,t.jsx)("option",{value:n,children:n},n))]})]}),C!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflow-instances-error",role:"alert",children:C}),F&&(0,t.jsx)(ue,{description:a("Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN in your .dev.vars to enable workflow instance history."),testId:"workflow-instances-unconfigured",title:a("Workflow inspection not configured")}),!F&&d!==null&&d.length===0&&(0,t.jsx)(ue,{description:a("No instances match this filter for the selected workflow."),testId:"workflow-instances-empty",title:a("No instances")}),d!==null&&d.length>0&&(0,t.jsx)(ee,{className:"overflow-hidden py-0",children:(0,t.jsx)(te,{className:"px-0",children:(0,t.jsxs)(ae,{"data-testid":"workflow-instances-table",children:[(0,t.jsx)(re,{children:(0,t.jsxs)(L,{children:[(0,t.jsx)(h,{children:a("Instance id")}),(0,t.jsx)(h,{children:a("Status")}),(0,t.jsx)(h,{children:a("Created")}),(0,t.jsx)(h,{children:a("Ended")}),(0,t.jsx)(h,{"aria-label":a("Actions")})]})}),(0,t.jsx)(ne,{children:d.map(n=>(0,t.jsxs)(L,{"data-testid":`workflow-instance-${n.id}`,children:[(0,t.jsx)(p,{className:"font-mono text-xs",children:n.id}),(0,t.jsx)(p,{className:"font-mono text-xs",children:n.status}),(0,t.jsx)(p,{className:"text-muted-foreground tabular-nums",children:n.createdOn??"\u2014"}),(0,t.jsx)(p,{className:"text-muted-foreground tabular-nums",children:n.endedOn??"\u2014"}),(0,t.jsx)(p,{className:"text-right",children:(0,t.jsxs)("div",{className:"flex justify-end gap-1.5",children:[(0,t.jsx)(q,{"data-testid":`workflow-instance-steps-${n.id}`,onClick:s(()=>{z(P(n.id))},"onClick"),size:"sm",type:"button",variant:"outline",children:a("Steps")}),I!==void 0&&(0,t.jsx)(Ie,{busy:_===n.id,id:n.id,onAct:s(u=>{z(J(n.id,u))},"onAct")},N)]})})]},n.id))})]})})}),v!==null&&(0,t.jsx)(ee,{className:"overflow-hidden py-0","data-testid":"workflow-instance-detail",children:(0,t.jsxs)(te,{className:"flex flex-col gap-2 px-4 py-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("span",{className:"font-mono text-xs",children:[a("Steps")," \xB7 ",v.id]}),(0,t.jsx)(q,{"data-testid":"workflow-instance-detail-close",onClick:E,size:"xs",type:"button",variant:"ghost",children:a("Close")})]}),v.steps.length===0?(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:a("This instance has no recorded steps yet.")}):(0,t.jsxs)(ae,{"data-testid":"workflow-instance-steps",children:[(0,t.jsx)(re,{children:(0,t.jsxs)(L,{children:[(0,t.jsx)(h,{children:a("Step")}),(0,t.jsx)(h,{children:a("Type")}),(0,t.jsx)(h,{children:a("Attempts")}),(0,t.jsx)(h,{children:a("Started")}),(0,t.jsx)(h,{children:a("Output")})]})}),(0,t.jsx)(ne,{children:v.steps.map((n,u)=>(0,t.jsxs)(L,{"data-testid":`workflow-step-${String(u)}`,children:[(0,t.jsx)(p,{className:"font-mono text-xs",children:n.name}),(0,t.jsx)(p,{className:"text-xs text-muted-foreground",children:n.type??"\u2014"}),(0,t.jsx)(p,{className:"tabular-nums",children:n.attempts??"\u2014"}),(0,t.jsx)(p,{className:"text-muted-foreground tabular-nums",children:n.start??"\u2014"}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:Ae(n)})]},`${n.name}:${String(u)}`))})]})]})})]})},"_e"),_e=ie(X.createWorkflowInstance),Ee=ie(X.getWorkflowInstanceStatus),Je=ie(X.sendWorkflowEvent),De=s(l=>{if(l.error)return`${l.error.name}: ${l.error.message}`;if(l.output===void 0)return"\u2014";try{return JSON.stringify(l.output,pe)}catch{return"(unserializable)"}},"$e"),ge=s(l=>{let e=l.trim();if(e==="")return{value:void 0};try{return{value:JSON.parse(e)}}catch{return null}},"ve"),Fe=s((l,e)=>l.some(w=>w.exportName===e)?e:l[0]?.exportName??"","Fe"),Pe=s(l=>{let e=(0,xe.c)(72),{eventTypes:w,exportName:x,onSent:N}=l,b=ce(),a=Y(),[d,m]=(0,i.useState)(""),[v,R]=(0,i.useState)(""),[S,B]=(0,i.useState)(""),[C,O]=(0,i.useState)(!1),[F,W]=(0,i.useState)(null),_;e[0]!==b||e[1]!==x||e[2]!==N||e[3]!==a||e[4]!==v?(_=s(async(D,oe)=>{try{await b.query(Je,{exportName:x,id:D,payload:oe,type:v},de(""))}catch(fe){W(U(fe));return}try{await N(x,D)}catch(fe){let ye=fe;W(`${a("Event sent, but refreshing the instance failed")}: ${U(ye)}`)}},"_"),e[0]=b,e[1]=x,e[2]=N,e[3]=a,e[4]=v,e[5]=_):_=e[5];let j=_,g;e[6]!==j||e[7]!==d||e[8]!==S||e[9]!==a?(g=s(async()=>{let D=d.trim(),oe=ge(S);if(oe===null){W(a("Payload must be valid JSON"));return}O(!0),W(null),await j(D,oe.value).finally(()=>{O(!1)})},"N"),e[6]=j,e[7]=d,e[8]=S,e[9]=a,e[10]=g):g=e[10];let y=g,k;e[11]!==a?(k=a("Send event"),e[11]=a,e[12]=k):k=e[12];let A;e[13]!==k?(A=(0,t.jsx)("h3",{className:"text-sm font-medium",children:k}),e[13]=k,e[14]=A):A=e[14];let I;e[15]!==F?(I=F!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-event-error",role:"alert",children:F}),e[15]=F,e[16]=I):I=e[16];let T;e[17]!==a?(T=a("Instance id"),e[17]=a,e[18]=T):T=e[18];let P;e[19]===Symbol.for("react.memo_cache_sentinel")?(P=s(D=>{m(D.target.value)},"O"),e[19]=P):P=e[19];let E;e[20]!==a?(E=a("Instance id"),e[20]=a,e[21]=E):E=e[21];let J;e[22]!==d||e[23]!==T||e[24]!==E?(J=(0,t.jsx)(me,{"aria-label":T,className:"max-w-48","data-testid":"workflows-event-id",onChange:P,placeholder:E,value:d}),e[22]=d,e[23]=T,e[24]=E,e[25]=J):J=e[25];let n;e[26]!==a?(n=a("Event type"),e[26]=a,e[27]=n):n=e[27];let u;e[28]===Symbol.for("react.memo_cache_sentinel")?(u=s(D=>{R(D.target.value)},"L"),e[28]=u):u=e[28];let f;e[29]!==a?(f=a("Event type"),e[29]=a,e[30]=f):f=e[30];let r;e[31]!==n||e[32]!==f||e[33]!==v?(r=(0,t.jsx)(me,{"aria-label":n,className:"max-w-48","data-testid":"workflows-event-type",list:"workflows-event-types",onChange:u,placeholder:f,value:v}),e[31]=n,e[32]=f,e[33]=v,e[34]=r):r=e[34];let c;e[35]!==w?(c=w.map(Le),e[35]=w,e[36]=c):c=e[36];let o;e[37]!==c?(o=(0,t.jsx)("datalist",{"data-testid":"workflows-event-types",id:"workflows-event-types",children:c}),e[37]=c,e[38]=o):o=e[38];let $;e[39]!==x||e[40]!==d||e[41]!==C||e[42]!==v?($=C||x===""||d.trim()===""||v.trim()==="",e[39]=x,e[40]=d,e[41]=C,e[42]=v,e[43]=$):$=e[43];let K;e[44]!==y?(K=s(()=>{z(y())},"z"),e[44]=y,e[45]=K):K=e[45];let G;e[46]!==C||e[47]!==a?(G=a(C?"Sending\u2026":"Send event"),e[46]=C,e[47]=a,e[48]=G):G=e[48];let M;e[49]!==$||e[50]!==K||e[51]!==G?(M=(0,t.jsx)(q,{"data-testid":"workflows-event-button",disabled:$,onClick:K,children:G}),e[49]=$,e[50]=K,e[51]=G,e[52]=M):M=e[52];let Z;e[53]!==r||e[54]!==o||e[55]!==M||e[56]!==J?(Z=(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[J,r,o,M]}),e[53]=r,e[54]=o,e[55]=M,e[56]=J,e[57]=Z):Z=e[57];let H;e[58]!==a?(H=a("Payload (JSON)"),e[58]=a,e[59]=H):H=e[59];let se;e[60]===Symbol.for("react.memo_cache_sentinel")?(se=s(D=>{B(D.target.value)},"Y"),e[60]=se):se=e[60];let Q;e[61]!==a?(Q=a("Payload (JSON, optional)"),e[61]=a,e[62]=Q):Q=e[62];let V;e[63]!==S||e[64]!==H||e[65]!==Q?(V=(0,t.jsx)(we,{"aria-label":H,className:"font-mono","data-testid":"workflows-event-payload",onChange:se,placeholder:Q,value:S}),e[63]=S,e[64]=H,e[65]=Q,e[66]=V):V=e[66];let le;return e[67]!==Z||e[68]!==V||e[69]!==A||e[70]!==I?(le=(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-event",children:[A,I,Z,V]}),e[67]=Z,e[68]=V,e[69]=A,e[70]=I,e[71]=le):le=e[71],le},"Pe"),Ve=s(()=>{let l=ce(),e=Y(),{data:w,error:x}=Ne(X.listWorkflows,{}),[N,b]=(0,i.useState)(""),[a,d]=(0,i.useState)(""),[m,v]=(0,i.useState)(""),[R,S]=(0,i.useState)(!1),[B,C]=(0,i.useState)(null),[O,F]=(0,i.useState)([]),[W,_]=(0,i.useState)(null),j=w!==void 0,g=Array.isArray(w?.workflows)?[...w.workflows].toSorted((r,c)=>r.exportName.localeCompare(c.exportName)):[],y=Fe(g,N),k=g.find(r=>r.exportName===y),A=s(r=>{F(c=>{let o=c.filter($=>!($.exportName===r.exportName&&$.id===r.id));return[r,...o]})},"T"),I=s(async()=>{let r=y;if(r==="")return;let c=ge(m);if(c===null){C(e("Params must be valid JSON"));return}S(!0),C(null);try{let o=a.trim(),$=await l.query(_e,{exportName:r,id:o===""?void 0:o,params:c.value},de(""));A({exportName:r,id:$.id,status:$.status}),d("")}catch(o){C(U(o))}S(!1)},"F"),T=s(()=>{z(I())},"P"),P=s(async(r,c)=>{_(c);try{let o=await l.query(Ee,{exportName:r,id:c},de(""));A({error:o.error,exportName:r,id:o.id,output:o.output,status:o.status})}catch(o){throw _(null),o}_(null)},"O"),E=s(async(r,c)=>{try{await P(r,c)}catch(o){C(U(o))}},"E"),J=s(r=>{b(r.target.value)},"W"),n=s(r=>{d(r.target.value)},"A"),u=s(r=>{v(r.target.value)},"L"),f=s(r=>{let{export:c,id:o}=r.currentTarget.dataset;c!==void 0&&o!==void 0&&z(E(c,o))},"n");return(0,t.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-workflows-panel",children:[x!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-error",role:"alert",children:x}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:e("Workflows are declared in code with defineWorkflow and run as durable Cloudflare Workflows. Start an instance and observe its status below.")}),j&&g.length===0?(0,t.jsx)(ue,{description:e("No defineWorkflow is declared in lunora/workflows.ts in this deployment. Add one to run a durable, multi-step workflow."),testId:"workflows-empty",title:e("No workflows defined")}):(0,t.jsx)(ee,{className:"overflow-hidden py-0",children:(0,t.jsx)(te,{className:"px-0",children:(0,t.jsxs)(ae,{"data-testid":"workflows-table",children:[(0,t.jsx)(re,{children:(0,t.jsxs)(L,{children:[(0,t.jsx)(h,{children:e("Export")}),(0,t.jsx)(h,{children:e("Name")}),(0,t.jsx)(h,{children:e("Class")})]})}),(0,t.jsx)(ne,{children:g.map(r=>(0,t.jsxs)(L,{"data-testid":`workflows-row-${r.exportName}`,children:[(0,t.jsx)(p,{className:"font-mono text-xs",children:r.exportName}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:r.name}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:r.className})]},r.exportName))})]})})}),g.length>0&&(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-start",children:[(0,t.jsx)("h3",{className:"text-sm font-medium",children:e("Start instance")}),B!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"workflows-start-error",role:"alert",children:B}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("select",{"aria-label":e("Workflow"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"workflows-start-select",onChange:J,value:y,children:g.map(r=>(0,t.jsx)("option",{value:r.exportName,children:r.exportName},r.exportName))}),(0,t.jsx)(me,{"aria-label":e("Instance id (optional)"),className:"max-w-48","data-testid":"workflows-start-id",onChange:n,placeholder:e("Instance id (optional)"),value:a}),(0,t.jsx)(q,{"data-testid":"workflows-start-button",disabled:R||y==="",onClick:T,children:e(R?"Starting\u2026":"Start instance")})]}),(0,t.jsx)(we,{"aria-label":e("Params (JSON)"),className:"font-mono","data-testid":"workflows-start-params",onChange:u,placeholder:e("Params (JSON, optional)"),value:m})]}),g.length>0&&(0,t.jsx)(Pe,{eventTypes:w?.eventTypes??[],exportName:y,onSent:P},y),O.length>0&&(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"workflows-instances",children:[(0,t.jsx)("h3",{className:"text-sm font-medium",children:e("Instances")}),(0,t.jsx)(ee,{className:"overflow-hidden py-0",children:(0,t.jsx)(te,{className:"px-0",children:(0,t.jsxs)(ae,{"data-testid":"workflows-instances-table",children:[(0,t.jsx)(re,{children:(0,t.jsxs)(L,{children:[(0,t.jsx)(h,{children:e("Workflow")}),(0,t.jsx)(h,{children:e("Instance id")}),(0,t.jsx)(h,{children:e("Status")}),(0,t.jsx)(h,{children:e("Output")}),(0,t.jsx)(h,{})]})}),(0,t.jsx)(ne,{children:O.map(r=>(0,t.jsxs)(L,{"data-testid":`workflows-instance-${r.id}`,children:[(0,t.jsx)(p,{className:"font-mono text-xs",children:r.exportName}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:r.id}),(0,t.jsx)(p,{className:"font-mono text-xs",children:r.status}),(0,t.jsx)(p,{className:"font-mono text-xs text-muted-foreground",children:De(r)}),(0,t.jsx)(p,{children:(0,t.jsx)(q,{"data-export":r.exportName,"data-id":r.id,"data-testid":`workflows-instance-refresh-${r.id}`,disabled:W===r.id,onClick:f,size:"xs",variant:"outline",children:W===r.id?e("Refreshing\u2026"):e("Refresh")})})]},`${r.exportName}:${r.id}`))})]})})})]}),k!==void 0&&(0,t.jsx)(Te,{workflowName:k.name})]})},"Ze");function Le(l){return(0,t.jsx)("option",{value:l,children:l},l)}s(Le,"De");export{Ve as default};
@@ -1 +1 @@
1
- import{a as N}from"./chunk-O46IV64X.js";import{b as x}from"./chunk-OOPMRFI2.js";import"./chunk-L27FKJTG.js";import{a as y}from"./chunk-PUTERXSU.js";import"./chunk-ZIY53FID.js";import{a as w,b,c as S,d as c,e as s,f as o}from"./chunk-KMBE7RTC.js";import"./chunk-4YZAJTU5.js";import"./chunk-UDKKUJHY.js";import"./chunk-EOFWXI3T.js";import{a as u}from"./chunk-LYVYUTQY.js";import{c as p}from"./chunk-NP6H72XD.js";import{a as g,e as v}from"./chunk-NPHGFVNE.js";import"./chunk-YESGXFAR.js";import"./chunk-ZPQBVYNN.js";import{B as f}from"./chunk-CDIV23I2.js";import"./chunk-PDBW6GTJ.js";import"./chunk-A6TVTNKO.js";import{b as T}from"./chunk-ADABTCDI.js";import{a as n,d as R}from"./chunk-5PEAXTYQ.js";var e=R(T(),1);var $={active:"default",failing:"destructive",idle:"secondary"},j=n(a=>a===void 0?"\u2014":`${new Date(a).toISOString().slice(0,19).replace("T"," ")} UTC`,"I"),K=n(a=>{let t=a.runs+a.suppressed;return t===0?void 0:Math.round(a.suppressed/t*100)},"$"),F=n(({initialShardKey:a=""})=>{let t=f(),{data:l,error:E,errorSource:A,liveError:I}=p(u.listReactors,{},{live:!0,shardKey:a}),C=l!==void 0,i=Array.isArray(l?.reactors)?l.reactors:[],d;C&&i.length===0?d=(0,e.jsx)(N,{description:t("No reactor is declared in this deployment. Export an onQueryChange(select, handler) from lunora/ to run server-side logic when a query's result changes."),testId:"reactors-empty",title:t("No reactors declared")}):d=(0,e.jsx)(g,{className:"overflow-hidden py-0",children:(0,e.jsx)(v,{className:"px-0",children:(0,e.jsxs)(w,{"data-testid":"reactors-table",children:[(0,e.jsx)(b,{children:(0,e.jsxs)(c,{children:[(0,e.jsx)(s,{children:t("Reactor")}),(0,e.jsx)(s,{children:t("State")}),(0,e.jsx)(s,{children:t("Ran")}),(0,e.jsx)(s,{children:t("Suppressed")}),(0,e.jsx)(s,{children:t("Errors")}),(0,e.jsx)(s,{children:t("Watches")}),(0,e.jsx)(s,{children:t("Last dispatch")})]})}),(0,e.jsx)(S,{children:i.map(r=>{let m=K(r);return(0,e.jsxs)(c,{"data-testid":`reactors-row-${r.path}`,children:[(0,e.jsx)(o,{className:"font-mono text-xs",children:r.path}),(0,e.jsx)(o,{children:(0,e.jsx)(x,{"data-testid":`reactors-state-${r.path}`,variant:$[r.state],children:r.state})}),(0,e.jsx)(o,{className:"font-mono text-xs",children:r.runs}),(0,e.jsxs)(o,{className:"font-mono text-xs text-muted-foreground",children:[r.suppressed,m===void 0?"":` (${String(m)}%)`]}),(0,e.jsx)(o,{className:"font-mono text-xs",children:r.errors===0?(0,e.jsx)("span",{className:"text-muted-foreground",children:"0"}):(0,e.jsx)("span",{className:"text-destructive",children:r.errors})}),(0,e.jsx)(o,{className:"font-mono text-xs text-muted-foreground",children:r.tables===void 0||r.tables.length===0?"\u2014":r.tables.join(", ")}),(0,e.jsx)(o,{className:"font-mono text-xs text-muted-foreground",children:j(r.lastRanAt)})]},r.path)})})]})})});let h=i.filter(r=>r.state==="failing");return(0,e.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-reactors-panel",children:[E!==null&&(0,e.jsx)(y,{error:A,shardKey:a,testId:"reactors-error"}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground",children:t("A reactor runs after a write flush, but only when the result of the query it watches actually changed \u2014 a trigger fires on a row write, a reactor fires on a result changing. Suppressed dispatches are the ones where the read re-ran and nothing had moved.")}),h.length>0&&(0,e.jsx)("div",{className:"flex flex-col gap-2","data-testid":"reactors-failing",children:h.map(r=>(0,e.jsxs)("p",{className:"text-xs text-destructive",role:"alert",children:[(0,e.jsx)("span",{className:"font-mono",children:r.path}),": ",r.lastError??t("last dispatch failed")]},r.path))}),I!==void 0&&(0,e.jsx)("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"reactors-live-error",role:"alert",children:t("Live updates unavailable; showing the last reading.")}),d]})},"U");export{F as default};
1
+ import{a as N}from"./chunk-V5ZKAZR6.js";import{b as x}from"./chunk-UB6S6VYI.js";import"./chunk-DMQVY5L7.js";import{a as y}from"./chunk-4OWWWAMB.js";import"./chunk-5XQM44J7.js";import{a as w,b,c as S,d as c,e as s,f as o}from"./chunk-WVAWKCNQ.js";import"./chunk-VND72OIC.js";import"./chunk-VLQU4G6O.js";import"./chunk-EOFWXI3T.js";import{a as u}from"./chunk-LYVYUTQY.js";import{c as p}from"./chunk-LUHBGCMO.js";import{a as g,e as v}from"./chunk-VUMS4VIV.js";import"./chunk-PLCYDHU3.js";import"./chunk-WY23EROJ.js";import{B as f}from"./chunk-G4H5DPO6.js";import"./chunk-JSVT5VBU.js";import"./chunk-A6TVTNKO.js";import{b as T}from"./chunk-ADABTCDI.js";import{a as n,d as R}from"./chunk-5PEAXTYQ.js";var e=R(T(),1);var $={active:"default",failing:"destructive",idle:"secondary"},j=n(a=>a===void 0?"\u2014":`${new Date(a).toISOString().slice(0,19).replace("T"," ")} UTC`,"I"),K=n(a=>{let t=a.runs+a.suppressed;return t===0?void 0:Math.round(a.suppressed/t*100)},"$"),F=n(({initialShardKey:a=""})=>{let t=f(),{data:l,error:E,errorSource:A,liveError:I}=p(u.listReactors,{},{live:!0,shardKey:a}),C=l!==void 0,i=Array.isArray(l?.reactors)?l.reactors:[],d;C&&i.length===0?d=(0,e.jsx)(N,{description:t("No reactor is declared in this deployment. Export an onQueryChange(select, handler) from lunora/ to run server-side logic when a query's result changes."),testId:"reactors-empty",title:t("No reactors declared")}):d=(0,e.jsx)(g,{className:"overflow-hidden py-0",children:(0,e.jsx)(v,{className:"px-0",children:(0,e.jsxs)(w,{"data-testid":"reactors-table",children:[(0,e.jsx)(b,{children:(0,e.jsxs)(c,{children:[(0,e.jsx)(s,{children:t("Reactor")}),(0,e.jsx)(s,{children:t("State")}),(0,e.jsx)(s,{children:t("Ran")}),(0,e.jsx)(s,{children:t("Suppressed")}),(0,e.jsx)(s,{children:t("Errors")}),(0,e.jsx)(s,{children:t("Watches")}),(0,e.jsx)(s,{children:t("Last dispatch")})]})}),(0,e.jsx)(S,{children:i.map(r=>{let m=K(r);return(0,e.jsxs)(c,{"data-testid":`reactors-row-${r.path}`,children:[(0,e.jsx)(o,{className:"font-mono text-xs",children:r.path}),(0,e.jsx)(o,{children:(0,e.jsx)(x,{"data-testid":`reactors-state-${r.path}`,variant:$[r.state],children:r.state})}),(0,e.jsx)(o,{className:"font-mono text-xs",children:r.runs}),(0,e.jsxs)(o,{className:"font-mono text-xs text-muted-foreground",children:[r.suppressed,m===void 0?"":` (${String(m)}%)`]}),(0,e.jsx)(o,{className:"font-mono text-xs",children:r.errors===0?(0,e.jsx)("span",{className:"text-muted-foreground",children:"0"}):(0,e.jsx)("span",{className:"text-destructive",children:r.errors})}),(0,e.jsx)(o,{className:"font-mono text-xs text-muted-foreground",children:r.tables===void 0||r.tables.length===0?"\u2014":r.tables.join(", ")}),(0,e.jsx)(o,{className:"font-mono text-xs text-muted-foreground",children:j(r.lastRanAt)})]},r.path)})})]})})});let h=i.filter(r=>r.state==="failing");return(0,e.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-reactors-panel",children:[E!==null&&(0,e.jsx)(y,{error:A,shardKey:a,testId:"reactors-error"}),(0,e.jsx)("p",{className:"text-sm text-muted-foreground",children:t("A reactor runs after a write flush, but only when the result of the query it watches actually changed \u2014 a trigger fires on a row write, a reactor fires on a result changing. Suppressed dispatches are the ones where the read re-ran and nothing had moved.")}),h.length>0&&(0,e.jsx)("div",{className:"flex flex-col gap-2","data-testid":"reactors-failing",children:h.map(r=>(0,e.jsxs)("p",{className:"text-xs text-destructive",role:"alert",children:[(0,e.jsx)("span",{className:"font-mono",children:r.path}),": ",r.lastError??t("last dispatch failed")]},r.path))}),I!==void 0&&(0,e.jsx)("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"reactors-live-error",role:"alert",children:t("Live updates unavailable; showing the last reading.")}),d]})},"U");export{F as default};