@lunora/studio 1.0.0-alpha.217 → 1.0.0-alpha.219

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 (193) hide show
  1. package/dist/index.d.mts +2 -2
  2. package/dist/index.d.ts +2 -2
  3. package/dist/index.mjs +1 -1
  4. package/dist/mount.mjs +1 -1
  5. package/dist/packem_chunks/AdvisorHealthPanel.mjs +1 -1
  6. package/dist/packem_chunks/ApiTab.mjs +1 -1
  7. package/dist/packem_chunks/AuditPanel.mjs +1 -1
  8. package/dist/packem_chunks/DeploymentHealthPanel.mjs +1 -1
  9. package/dist/packem_chunks/ExportImportPanel.mjs +1 -1
  10. package/dist/packem_chunks/FileBrowser.mjs +1 -1
  11. package/dist/packem_chunks/FunctionRunner.mjs +1 -1
  12. package/dist/packem_chunks/FunctionStatsPanel.mjs +1 -1
  13. package/dist/packem_chunks/HealthPanel.mjs +1 -1
  14. package/dist/packem_chunks/InsightsPanel.mjs +1 -1
  15. package/dist/packem_chunks/LogsPanel.mjs +1 -1
  16. package/dist/packem_chunks/MailPanel.mjs +2 -2
  17. package/dist/packem_chunks/MetricsPanel.mjs +1 -1
  18. package/dist/packem_chunks/NotificationsPanel.mjs +1 -1
  19. package/dist/packem_chunks/PitrPanel.mjs +1 -1
  20. package/dist/packem_chunks/SchemaViewer.mjs +1 -1
  21. package/dist/packem_chunks/SecurityAdvisorPanel.mjs +1 -1
  22. package/dist/packem_chunks/SettingsPanel.mjs +1 -1
  23. package/dist/packem_chunks/SqlEditorPanel.mjs +1 -1
  24. package/dist/packem_chunks/TableEditor.mjs +1 -1
  25. package/dist/packem_chunks/agents-panel.mjs +1 -1
  26. package/dist/packem_chunks/analytics-panel.mjs +1 -1
  27. package/dist/packem_chunks/auth-audit-panel.mjs +1 -1
  28. package/dist/packem_chunks/auth-config-panel.mjs +1 -1
  29. package/dist/packem_chunks/auth-sessions-panel.mjs +1 -1
  30. package/dist/packem_chunks/containers-panel.mjs +1 -1
  31. package/dist/packem_chunks/dashboards-panel.mjs +1 -1
  32. package/dist/packem_chunks/evals-panel.mjs +1 -1
  33. package/dist/packem_chunks/fanout-panel.mjs +1 -1
  34. package/dist/packem_chunks/flags-panel.mjs +1 -1
  35. package/dist/packem_chunks/issues-panel.mjs +1 -1
  36. package/dist/packem_chunks/kv-browser.mjs +1 -1
  37. package/dist/packem_chunks/log-drains-panel.mjs +1 -1
  38. package/dist/packem_chunks/migrations-route.mjs +1 -1
  39. package/dist/packem_chunks/organizations-panel.mjs +1 -1
  40. package/dist/packem_chunks/payments-panel.mjs +1 -1
  41. package/dist/packem_chunks/permissions-panel.mjs +1 -1
  42. package/dist/packem_chunks/queues-panel.mjs +1 -1
  43. package/dist/packem_chunks/reactors-panel.mjs +1 -1
  44. package/dist/packem_chunks/rls-panel.mjs +1 -1
  45. package/dist/packem_chunks/schedule-panel.mjs +1 -1
  46. package/dist/packem_chunks/storage-rules-panel.mjs +1 -1
  47. package/dist/packem_chunks/subscriptions-panel.mjs +1 -1
  48. package/dist/packem_chunks/sync-client-panel.mjs +1 -1
  49. package/dist/packem_chunks/traces-panel.mjs +1 -1
  50. package/dist/packem_chunks/users-panel.mjs +1 -1
  51. package/dist/packem_chunks/vector-browser.mjs +1 -1
  52. package/dist/packem_chunks/workflows-panel.mjs +1 -1
  53. package/dist/packem_shared/{ApiDocsPanel-BImfQhyJ.mjs → ApiDocsPanel-DzvVLAev.mjs} +1 -1
  54. package/dist/packem_shared/{ApiReferencePanel-CigvHhCa.mjs → ApiReferencePanel--1Y4o_-l.mjs} +1 -1
  55. package/dist/packem_shared/{CommandPalette-CSdz9zax.mjs → CommandPalette-D7GxhPrH.mjs} +1 -1
  56. package/dist/packem_shared/DataBrowser-CKbaOtDh.mjs +4 -0
  57. package/dist/packem_shared/GlobalDataBrowser-DSexMt80.mjs +1 -0
  58. package/dist/packem_shared/{HomePanel-_BwLI4TQ.mjs → HomePanel-BkCmY0Hl.mjs} +1 -1
  59. package/dist/packem_shared/{MigrationsPanel-BPWzFdxC.mjs → MigrationsPanel-DLQRarWw.mjs} +1 -1
  60. package/dist/packem_shared/{OpenRpcReferencePanel-C6CM791D.mjs → OpenRpcReferencePanel-a_mbqw67.mjs} +1 -1
  61. package/dist/packem_shared/{ScheduledJobs-B4DPADwk.mjs → ScheduledJobs-DSqsMB51.mjs} +1 -1
  62. package/dist/packem_shared/Studio-BE_SzY44.mjs +1 -0
  63. package/dist/packem_shared/{StudioApp-fYFz6zZQ.mjs → StudioApp-kVjMop0V.mjs} +1 -1
  64. package/dist/packem_shared/{advisor-view-CPgOok_h.mjs → advisor-view-DtkbHW2O.mjs} +1 -1
  65. package/dist/packem_shared/aggregateMetrics-5zEJC6Ju.mjs +1 -0
  66. package/dist/packem_shared/auth-pager-DiDnXsfe.mjs +1 -0
  67. package/dist/packem_shared/{data-grid-DTBAKZlm.mjs → data-grid-BPu1a997.mjs} +1 -1
  68. package/dist/packem_shared/data-view-params-DhYmAkcj.mjs +1 -0
  69. package/dist/packem_shared/{error-alert-tf5zvSLV.mjs → error-alert-dQk3g8WI.mjs} +1 -1
  70. package/dist/packem_shared/{grid-features-Dm80ngyR.mjs → grid-features-ByxOklon.mjs} +1 -1
  71. package/dist/packem_shared/grid-pagination-DgzyzfBh.mjs +1 -0
  72. package/dist/packem_shared/home-panel-B_HN6YMA.mjs +3 -0
  73. package/dist/packem_shared/internal-CyDwqA67.mjs +2 -0
  74. package/dist/packem_shared/{log-line-BoObzuue.mjs → log-line-BHZD2Aj4.mjs} +1 -1
  75. package/dist/packem_shared/{recording-client-BXUIyBL4.mjs → recording-client-CjRFjhya.mjs} +1 -1
  76. package/dist/packem_shared/reference-view-vNXUVPlA.mjs +13 -0
  77. package/dist/packem_shared/{schema-diagram-CDj_69jF.mjs → schema-diagram-DADlbs2X.mjs} +1 -1
  78. package/dist/packem_shared/{sql-result-table-C5y0jwaK.mjs → sql-result-table-DS4o0GoC.mjs} +1 -1
  79. package/dist/packem_shared/{studio-OqNyRY1N.mjs → studio-BVQq3QLR.mjs} +1 -1
  80. package/dist/packem_shared/table-list-sidebar-D30qERKx.mjs +1 -0
  81. package/dist/packem_shared/{use-admin-query-BKXiqLci.mjs → use-admin-query-CR9mHt0P.mjs} +1 -1
  82. package/dist/packem_shared/{use-async-submit-BTr3w2-K.mjs → use-async-submit-LWIKsZ8r.mjs} +1 -1
  83. package/dist/packem_shared/{use-auth-config-CuM3eJZz.mjs → use-auth-config-HmTOvrWd.mjs} +1 -1
  84. package/dist/packem_shared/{use-open-trace-BCW0c9qq.mjs → use-open-trace-DdGxsEB9.mjs} +1 -1
  85. package/dist/packem_shared/{use-sql-assistant-BhIMDQHV.mjs → use-sql-assistant-D4XQ0v0R.mjs} +1 -1
  86. package/dist/standalone/{chunk-VPL4UEUQ.js → chunk-2ABVDLD3.js} +1 -1
  87. package/dist/standalone/{chunk-GNT6XGND.js → chunk-2HAWCLCS.js} +1 -1
  88. package/dist/standalone/chunk-2HF37UQN.js +1 -0
  89. package/dist/standalone/chunk-2JLOP2EL.js +1 -0
  90. package/dist/standalone/{chunk-DUKQRASV.js → chunk-2R6ZRXPJ.js} +1 -1
  91. package/dist/standalone/{chunk-NKPDRRNQ.js → chunk-2RMFAASK.js} +1 -1
  92. package/dist/standalone/{chunk-ZBCR4Y7H.js → chunk-3C25RFTP.js} +1 -1
  93. package/dist/standalone/chunk-3GFF4BA4.js +3 -0
  94. package/dist/standalone/{chunk-PA2VU4KN.js → chunk-3TE3V2QL.js} +1 -1
  95. package/dist/standalone/{chunk-SO2DWPC4.js → chunk-3ZMF2GJ5.js} +1 -1
  96. package/dist/standalone/chunk-4AZDQAT2.js +1 -0
  97. package/dist/standalone/chunk-4P2KFEUN.js +1 -0
  98. package/dist/standalone/chunk-5ICUJ4IA.js +15 -0
  99. package/dist/standalone/{chunk-FODLDLE2.js → chunk-6B7FVPW3.js} +5 -5
  100. package/dist/standalone/{chunk-QHRQX4KT.js → chunk-6CGJCPHC.js} +1 -1
  101. package/dist/standalone/chunk-6DAD3RFX.js +1 -0
  102. package/dist/standalone/chunk-6HDT763N.js +1 -0
  103. package/dist/standalone/{chunk-EDGO46IR.js → chunk-6P7CYZPR.js} +1 -1
  104. package/dist/standalone/{chunk-3S77QF26.js → chunk-6RNWWWLS.js} +1 -1
  105. package/dist/standalone/chunk-6WPU62WQ.js +2 -0
  106. package/dist/standalone/{chunk-JYKNN7XE.js → chunk-A2XTI2C3.js} +1 -1
  107. package/dist/standalone/{chunk-WMCC4HKS.js → chunk-AM7VTTNL.js} +1 -1
  108. package/dist/standalone/chunk-BJEJVHCO.js +9 -0
  109. package/dist/standalone/{chunk-TIUMFAN2.js → chunk-DKLSANZA.js} +1 -1
  110. package/dist/standalone/{chunk-NX2EQSOE.js → chunk-DX6246CW.js} +1 -1
  111. package/dist/standalone/{chunk-DX6FAHR2.js → chunk-DXT2DY4I.js} +1 -1
  112. package/dist/standalone/{chunk-RLVFEWIN.js → chunk-EDEQELIO.js} +1 -1
  113. package/dist/standalone/chunk-EQVY6WGK.js +1 -0
  114. package/dist/standalone/{chunk-YIK4XEVX.js → chunk-FCEQTBLC.js} +1 -1
  115. package/dist/standalone/{chunk-WD3PESCG.js → chunk-FCPY75TQ.js} +1 -1
  116. package/dist/standalone/{chunk-E7TOMONS.js → chunk-FS4GMDIW.js} +1 -1
  117. package/dist/standalone/{chunk-YDIJI7T6.js → chunk-GGAUC5ZI.js} +1 -1
  118. package/dist/standalone/{chunk-N3R2NFDS.js → chunk-GL7PC32W.js} +1 -1
  119. package/dist/standalone/{chunk-R3J3OY24.js → chunk-GYKK64E7.js} +1 -1
  120. package/dist/standalone/{chunk-JYQA5LES.js → chunk-H4OORJHB.js} +1 -1
  121. package/dist/standalone/chunk-HR7W3Z5I.js +1 -0
  122. package/dist/standalone/chunk-I3TUOZM3.js +1 -0
  123. package/dist/standalone/{chunk-OK2Q64WC.js → chunk-I4VOJYXE.js} +1 -1
  124. package/dist/standalone/{chunk-BOTGXX4H.js → chunk-IJPXZZZ5.js} +1 -1
  125. package/dist/standalone/{chunk-Y5D7BKI4.js → chunk-J345HOFQ.js} +1 -1
  126. package/dist/standalone/chunk-JNDBJAO6.js +1 -0
  127. package/dist/standalone/{chunk-LAOVV6GJ.js → chunk-JQ63BDVF.js} +1 -1
  128. package/dist/standalone/{chunk-IDVSCQJU.js → chunk-K4HVLN3Z.js} +1 -1
  129. package/dist/standalone/chunk-KFEWMJQS.js +1 -0
  130. package/dist/standalone/chunk-KGCUFNFC.js +5 -0
  131. package/dist/standalone/{chunk-4Q6ZHR7P.js → chunk-LJVH6HRQ.js} +1 -1
  132. package/dist/standalone/{chunk-GGPSI4ZR.js → chunk-MDUTVBJZ.js} +1 -1
  133. package/dist/standalone/{chunk-U745VG7H.js → chunk-MMMRSTCL.js} +1 -1
  134. package/dist/standalone/{chunk-3F35BVE4.js → chunk-PAE3ULFR.js} +1 -1
  135. package/dist/standalone/{chunk-2J44JAMR.js → chunk-PIKO7SSB.js} +1 -1
  136. package/dist/standalone/chunk-PSBP27ZK.js +1 -0
  137. package/dist/standalone/chunk-PSPSEIFN.js +1 -0
  138. package/dist/standalone/{chunk-SYJQ3QYJ.js → chunk-PUBYZCHW.js} +1 -1
  139. package/dist/standalone/{chunk-7PKIWAFQ.js → chunk-PVNT7VXC.js} +1 -1
  140. package/dist/standalone/{chunk-BDO4YYBB.js → chunk-PY5P53RV.js} +3 -3
  141. package/dist/standalone/{chunk-LBMSRD6N.js → chunk-Q2F2DRGB.js} +1 -1
  142. package/dist/standalone/chunk-QKZ2JCH3.js +1 -0
  143. package/dist/standalone/{chunk-F2FPKLFM.js → chunk-RBJMRBC3.js} +1 -1
  144. package/dist/standalone/{chunk-SGBJAOTU.js → chunk-RE4RWXYW.js} +1 -1
  145. package/dist/standalone/{chunk-XUNTO4S2.js → chunk-RVBRSHYE.js} +1 -1
  146. package/dist/standalone/{chunk-3OI7B7W6.js → chunk-SEBIGECV.js} +1 -1
  147. package/dist/standalone/{chunk-6EJUU2ZR.js → chunk-TZHEXHD4.js} +1 -1
  148. package/dist/standalone/{chunk-4FNAK556.js → chunk-UTPXXTQ6.js} +1 -1
  149. package/dist/standalone/chunk-UYKO4I36.js +1 -0
  150. package/dist/standalone/chunk-V2JKX5UU.js +14 -0
  151. package/dist/standalone/{chunk-EHTUWA7S.js → chunk-V2LIXSFE.js} +1 -1
  152. package/dist/standalone/{chunk-YHCB77HW.js → chunk-VQM2MKYO.js} +1 -1
  153. package/dist/standalone/chunk-VQTSESFP.js +1 -0
  154. package/dist/standalone/{chunk-HRHJB4QO.js → chunk-WINPNKYC.js} +1 -1
  155. package/dist/standalone/{chunk-BMDPZOBN.js → chunk-Y5PCZUGU.js} +1 -1
  156. package/dist/standalone/{chunk-A2TVIAEC.js → chunk-YBCFAAQJ.js} +1 -1
  157. package/dist/standalone/chunk-YV6JXZJO.js +1 -0
  158. package/dist/standalone/{chunk-2DX5MROH.js → chunk-ZHM5ZHPC.js} +1 -1
  159. package/dist/standalone/{chunk-PD6WIDY6.js → chunk-ZJZNCJHY.js} +1 -1
  160. package/dist/standalone/{chunk-OVBIGTEL.js → chunk-ZUGCPRKB.js} +1 -1
  161. package/dist/standalone/studio.js +1 -1
  162. package/dist/styles.css +1 -1
  163. package/package.json +6 -6
  164. package/dist/packem_shared/DataBrowser-DLRa1EYq.mjs +0 -4
  165. package/dist/packem_shared/GlobalDataBrowser-BTbqR6Wc.mjs +0 -1
  166. package/dist/packem_shared/Studio-CcWQdYrV.mjs +0 -1
  167. package/dist/packem_shared/aggregateMetrics-CY05xrYU.mjs +0 -1
  168. package/dist/packem_shared/data-view-params-qoSTqjAj.mjs +0 -1
  169. package/dist/packem_shared/home-panel-DCUKd8Uk.mjs +0 -3
  170. package/dist/packem_shared/internal-B6haJbiP.mjs +0 -2
  171. package/dist/packem_shared/reference-view-DiikOols.mjs +0 -13
  172. package/dist/packem_shared/table-list-sidebar-DHG1UJC4.mjs +0 -1
  173. package/dist/standalone/chunk-4BSUMM2O.js +0 -1
  174. package/dist/standalone/chunk-4IE4RCU2.js +0 -14
  175. package/dist/standalone/chunk-6IGGJN74.js +0 -1
  176. package/dist/standalone/chunk-75TJGBCF.js +0 -1
  177. package/dist/standalone/chunk-AFUPTCKG.js +0 -1
  178. package/dist/standalone/chunk-C3RVT4ZV.js +0 -1
  179. package/dist/standalone/chunk-EC4MB5HF.js +0 -5
  180. package/dist/standalone/chunk-ETRF5USL.js +0 -1
  181. package/dist/standalone/chunk-FR7VMBTI.js +0 -1
  182. package/dist/standalone/chunk-J54ZPBT7.js +0 -1
  183. package/dist/standalone/chunk-ORJ7WS3N.js +0 -1
  184. package/dist/standalone/chunk-RLLKECZT.js +0 -1
  185. package/dist/standalone/chunk-SI6H2NVN.js +0 -1
  186. package/dist/standalone/chunk-SUDJTC4S.js +0 -1
  187. package/dist/standalone/chunk-SYDJEFWA.js +0 -1
  188. package/dist/standalone/chunk-TFDBSYX4.js +0 -15
  189. package/dist/standalone/chunk-UEVR3CED.js +0 -2
  190. package/dist/standalone/chunk-UEZQP5EU.js +0 -9
  191. package/dist/standalone/chunk-XGJNOLY6.js +0 -1
  192. package/dist/standalone/chunk-XNHCCZZZ.js +0 -3
  193. package/dist/standalone/chunk-ZGMLIJ7Y.js +0 -1
@@ -1 +1 @@
1
- import{useLunora as Y}from"@lunora/react";import{useState as w,useEffect as Ve}from"react";import{B as M}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as R}from"../packem_shared/button-q0UYSmrn.mjs";import{C as Q,a as _}from"../packem_shared/card--2hKx4L2.mjs";import{E as Qe}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as $}from"../packem_shared/input-CXhxesPC.mjs";import{T as Ee,a as Re,b as O,c as S,d as Te,e as U}from"../packem_shared/table-D0SBiDu-.mjs";import{b as _e}from"../packem_shared/use-admin-query-BKXiqLci.mjs";import{c as Ae}from"react/compiler-runtime";import{u as Ye,D as We}from"../packem_shared/use-auth-config-CuM3eJZz.mjs";import{useAutoRefresh as Je}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.mjs";import Ke from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{h as Ie,f as q,i as Ue,b as Oe}from"../packem_shared/internal-B6haJbiP.mjs";import{jsxs as a,jsx as t,Fragment as Xe}from"react/jsx-runtime";import{C as et}from"../packem_shared/checkbox-CnS9cyCz.mjs";import{L as V}from"../packem_shared/label-DKFzyHq6.mjs";import{M as Ge}from"../packem_shared/modal-shell-CDztwLnv.mjs";import{u as tt}from"../packem_shared/use-async-submit-BTr3w2-K.mjs";We.capabilities;const st=()=>{const m=Ae(3),{config:e,ready:l}=Ye();let n;return m[0]!==e.capabilities||m[1]!==l?(n={capabilities:e.capabilities,ready:l},m[0]=e.capabilities,m[1]=l,m[2]=n):n=m[2],n},nt=(m,e)=>typeof m.acceptedAt=="number"?"spent":typeof m.expiresAt=="number"&&m.expiresAt<=e?"expired":"pending",qe=500,lt=()=>{const m=Y(),e=G(),[l,n]=w(""),[h,s]=w(null),[c,i]=w(null),[o,f]=w(!1),v=_e(["lunora-auth-sign-up-invitations",qe],()=>m.listAuthSignUpInvitations({limit:qe})),C=v.data?.rows??null,b=v.data?.total??0,A=()=>{const r=l.trim();r!==""&&(s(null),q((async()=>{try{const u=await m.createAuthSignUpInvitation({email:r}),p=typeof u.token=="string"?u.token:void 0;i(p===void 0?null:`${globalThis.location.origin}/sign-up?email=${encodeURIComponent(r)}&invite=${encodeURIComponent(p)}`),f(!1),n(""),v.refetch()}catch(u){s(u instanceof Error?u.message:String(u))}})()))},y=()=>{const r="navigator"in globalThis?globalThis.navigator.clipboard:void 0;c===null||r===void 0||q(r.writeText(c).then(()=>(f(!0),!0)))},I=r=>{s(null),q((async()=>{try{await m.revokeAuthSignUpInvitation({email:r}),v.refetch()}catch(u){s(u instanceof Error?u.message:String(u))}})())};return a("div",{className:"flex flex-col gap-4","data-testid":"sign-up-invitations",children:[a("div",{children:[t("h2",{className:"text-base font-medium",children:e("Sign-up invitations")}),t("p",{className:"text-sm text-muted-foreground",children:e("Only invited addresses can create an account. Nothing is emailed — send the invitee the one-time link yourself.")})]}),a("div",{className:"flex gap-2",children:[t($,{"aria-label":e("Email address to invite"),"data-testid":"sign-up-invitation-email",onChange:r=>{n(r.target.value)},placeholder:e("ada@example.com"),type:"email",value:l}),t(R,{"data-testid":"sign-up-invitation-submit",onClick:A,type:"button",children:e("Invite")})]}),c!==null&&t(Q,{children:a(_,{className:"flex flex-col gap-2 p-4",children:[t("p",{className:"text-sm",children:e("Send this link to the invitee. It is shown once and cannot be recovered.")}),a("div",{className:"flex gap-2",children:[t($,{"data-testid":"sign-up-invitation-link",readOnly:!0,value:c}),t(R,{"data-testid":"sign-up-invitation-copy",onClick:y,type:"button",children:e(o?"Copied":"Copy")})]})]})}),(h??v.error)!==null&&t("p",{className:"text-sm text-destructive","data-testid":"sign-up-invitations-error",role:"alert",children:h??v.error}),C!==null&&C.length===0&&t(Qe,{testId:"sign-up-invitations-empty",title:e("Nobody has been invited yet.")}),C!==null&&b>C.length&&t("p",{className:"text-sm text-muted-foreground","data-testid":"sign-up-invitations-truncated",children:e("Showing the most recent invitations. Query the signUpInvitation table directly to see the rest.")}),C!==null&&C.length>0&&t(Q,{children:t(_,{className:"p-0",children:a(Ee,{children:[t(Re,{children:a(O,{children:[t(S,{children:e("Email")}),t(S,{children:e("Status")}),t(S,{children:e("Expires")}),t(S,{children:e("Invited by")}),t(S,{})]})}),t(Te,{children:C.map(r=>{const u=nt(r,Date.now()),p=r.email??"";return a(O,{"data-testid":`sign-up-invitation-${p}`,children:[t(U,{children:p}),a(U,{"data-testid":`sign-up-invitation-status-${p}`,children:[u==="spent"&&e("Accepted"),u==="expired"&&e("Expired"),u==="pending"&&e("Pending")]}),t(U,{children:typeof r.expiresAt=="number"?Ie(r.expiresAt):"—"}),t(U,{children:r.invitedBy??"—"}),t(U,{className:"text-right",children:t(R,{onClick:()=>{I(p)},type:"button",variant:"ghost",children:e("Revoke")})})]},r.id)})})]})})})]})},at={boolean:"checkbox",date:"datetime-local",number:"number",string:"text"},it=(m,e)=>m.type==="boolean"?!0:typeof e!="string"||e.trim()===""?!1:m.type!=="number"||!Number.isNaN(Number(e.trim())),rt=(m,e)=>{if(m.type==="boolean")return e===!0?{value:!0}:m.required?{value:!1}:void 0;const l=typeof e=="string"?e.trim():"";if(l!==""){if(m.type==="number"){const n=Number(l);return Number.isNaN(n)?void 0:{value:n}}return{value:l}}},ot=m=>{const e=Ae(105),{onClose:l,onCreated:n}=m,h=Y(),s=G(),{config:c}=Ye(),{busy:i,error:o,run:f}=tt(),[v,C]=w(""),[b,A]=w(""),[y,I]=w(""),[r,u]=w("");let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p={},e[0]=p):p=e[0];const[x,d]=w(p);let F;e[1]===Symbol.for("react.memo_cache_sentinel")?(F=g=>{C(g.target.value)},e[1]=F):F=e[1];const N=F;let E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=g=>{A(g.target.value)},e[2]=E):E=e[2];const z=E;let D;e[3]===Symbol.for("react.memo_cache_sentinel")?(D=g=>{I(g.target.value)},e[3]=D):D=e[3];const $e=D;let Z;e[4]===Symbol.for("react.memo_cache_sentinel")?(Z=g=>{u(g.target.value)},e[4]=Z):Z=e[4];const Be=Z;let W;e[5]===Symbol.for("react.memo_cache_sentinel")?(W=(g,T)=>{d(H=>({...H,[g]:T}))},e[5]=W):W=e[5];const De=W;let J;e[6]!==x?(J=g=>x[g.name]??(g.type==="boolean"?!1:""),e[6]=x,e[7]=J):J=e[7];const P=J;let K;if(e[8]!==c.userFields||e[9]!==P){let g;e[11]!==P?(g=T=>!T.required||it(T,P(T)),e[11]=P,e[12]=g):g=e[12],K=c.userFields.every(g),e[8]=c.userFields,e[9]=P,e[10]=K}else K=e[10];const Fe=K;let X;e[13]!==i||e[14]!==v||e[15]!==b||e[16]!==Fe?(X=!i&&v.trim()!==""&&b.trim()!==""&&Fe,e[13]=i,e[14]=v,e[15]=b,e[16]=Fe,e[17]=X):X=e[17];const ze=X;let ee;e[18]!==c.userFields||e[19]!==P?(ee=()=>{const g={};for(const T of c.userFields){const H=rt(T,P(T));H!==void 0&&(g[T.name]=H.value)}return Object.keys(g).length===0?void 0:g},e[18]=c.userFields,e[19]=P,e[20]=ee):ee=e[20];const Se=ee;let te;e[21]!==Se||e[22]!==h||e[23]!==v||e[24]!==b||e[25]!==l||e[26]!==n||e[27]!==y||e[28]!==r||e[29]!==f?(te=()=>{f(async()=>{await h.createAuthUser({data:Se(),email:v.trim(),name:b.trim(),password:y===""?void 0:y,role:r.trim()===""?void 0:r.trim()}),n(),l()})},e[21]=Se,e[22]=h,e[23]=v,e[24]=b,e[25]=l,e[26]=n,e[27]=y,e[28]=r,e[29]=f,e[30]=te):te=e[30];const k=te;let B;e[31]!==s?(B=s("Create user"),e[31]=s,e[32]=B):B=e[32];let L;e[33]!==s?(L=s("Create user"),e[33]=s,e[34]=L):L=e[34];let j;e[35]!==L?(j=t("h2",{className:"text-sm font-semibold text-foreground",children:L}),e[35]=L,e[36]=j):j=e[36];let se;e[37]!==s?(se=s("email"),e[37]=s,e[38]=se):se=e[38];let ne;e[39]!==se?(ne=t(V,{htmlFor:"uc-email",children:se}),e[39]=se,e[40]=ne):ne=e[40];let le;e[41]!==v?(le=t($,{"data-testid":"uc-email",id:"uc-email",onChange:N,type:"email",value:v}),e[41]=v,e[42]=le):le=e[42];let ae;e[43]!==ne||e[44]!==le?(ae=a("div",{className:"flex flex-col gap-1",children:[ne,le]}),e[43]=ne,e[44]=le,e[45]=ae):ae=e[45];let ie;e[46]!==s?(ie=s("name"),e[46]=s,e[47]=ie):ie=e[47];let re;e[48]!==ie?(re=t(V,{htmlFor:"uc-name",children:ie}),e[48]=ie,e[49]=re):re=e[49];let oe;e[50]!==b?(oe=t($,{"data-testid":"uc-name",id:"uc-name",onChange:z,value:b}),e[50]=b,e[51]=oe):oe=e[51];let de;e[52]!==re||e[53]!==oe?(de=a("div",{className:"flex flex-col gap-1",children:[re,oe]}),e[52]=re,e[53]=oe,e[54]=de):de=e[54];let ce;e[55]!==s?(ce=s("Password (optional)"),e[55]=s,e[56]=ce):ce=e[56];let ue;e[57]!==ce?(ue=t(V,{htmlFor:"uc-password",children:ce}),e[57]=ce,e[58]=ue):ue=e[58];let me;e[59]!==y?(me=t($,{"data-testid":"uc-password",id:"uc-password",onChange:$e,type:"password",value:y}),e[59]=y,e[60]=me):me=e[60];let he;e[61]!==ue||e[62]!==me?(he=a("div",{className:"flex flex-col gap-1",children:[ue,me]}),e[61]=ue,e[62]=me,e[63]=he):he=e[63];let pe;e[64]!==s?(pe=s("Role (optional)"),e[64]=s,e[65]=pe):pe=e[65];let fe;e[66]!==pe?(fe=t(V,{htmlFor:"uc-role",children:pe}),e[66]=pe,e[67]=fe):fe=e[67];let ve;e[68]!==r?(ve=t($,{"data-testid":"uc-role",id:"uc-role",onChange:Be,value:r}),e[68]=r,e[69]=ve):ve=e[69];let ge;e[70]!==fe||e[71]!==ve?(ge=a("div",{className:"flex flex-col gap-1",children:[fe,ve]}),e[70]=fe,e[71]=ve,e[72]=ge):ge=e[72];let be;e[73]!==c.userFields||e[74]!==P||e[75]!==s?(be=c.userFields.length>0&&a("div",{className:"flex flex-col gap-3 border-t border-border pt-3","data-testid":"uc-plugin-fields",children:[t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s("Plugin fields")}),c.userFields.map(g=>{const T=`uc-field-${g.name}`,H=g.required?"":` (${s("optional")})`;if(g.type==="boolean"){const Me=P(g)===!0;return a("label",{className:"flex items-center gap-2",htmlFor:T,children:[t(et,{checked:Me,"data-testid":T,id:T,onCheckedChange:Ze=>{De(g.name,Ze)}}),a("span",{className:"text-sm",children:[g.name,H]})]},g.name)}const He=P(g);return a("div",{className:"flex flex-col gap-1",children:[a(V,{htmlFor:T,children:[g.name,H]}),t($,{"data-testid":T,id:T,onChange:Me=>{De(g.name,Me.target.value)},type:at[g.type],value:typeof He=="string"?He:""})]},g.name)})]}),e[73]=c.userFields,e[74]=P,e[75]=s,e[76]=be):be=e[76];let xe;e[77]!==o?(xe=o!==null&&t("p",{className:"text-sm text-destructive","data-testid":"uc-error",role:"alert",children:o}),e[77]=o,e[78]=xe):xe=e[78];let ye;e[79]!==s?(ye=s("Cancel"),e[79]=s,e[80]=ye):ye=e[80];let Ne;e[81]!==l||e[82]!==ye?(Ne=t(R,{"data-testid":"uc-cancel",onClick:l,size:"sm",type:"button",variant:"outline",children:ye}),e[81]=l,e[82]=ye,e[83]=Ne):Ne=e[83];const Le=!ze;let ke;e[84]!==i||e[85]!==s?(ke=s(i?"Creating…":"Create"),e[84]=i,e[85]=s,e[86]=ke):ke=e[86];let Ce;e[87]!==k||e[88]!==Le||e[89]!==ke?(Ce=t(R,{"data-testid":"uc-submit",disabled:Le,onClick:k,size:"sm",type:"button",children:ke}),e[87]=k,e[88]=Le,e[89]=ke,e[90]=Ce):Ce=e[90];let we;e[91]!==Ne||e[92]!==Ce?(we=a("div",{className:"flex justify-end gap-2 pt-1",children:[Ne,Ce]}),e[91]=Ne,e[92]=Ce,e[93]=we):we=e[93];let Pe;return e[94]!==l||e[95]!==B||e[96]!==j||e[97]!==ae||e[98]!==de||e[99]!==he||e[100]!==ge||e[101]!==be||e[102]!==xe||e[103]!==we?(Pe=a(Ge,{label:B,onClose:l,panelTestId:"uc-dialog",testId:"uc-overlay",variant:"dialog",children:[j,ae,de,he,ge,be,xe,we]}),e[94]=l,e[95]=B,e[96]=j,e[97]=ae,e[98]=de,e[99]=he,e[100]=ge,e[101]=be,e[102]=xe,e[103]=we,e[104]=Pe):Pe=e[104],Pe},je=m=>{const e=Ae(2),{children:l}=m;let n;return e[0]!==l?(n=t("h3",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:l}),e[0]=l,e[1]=n):n=e[1],n},dt=m=>{const e=Ae(29),{busy:l,runAction:n,userId:h,version:s}=m,c=Y(),i=G(),[o,f]=w(null),[v,C]=w(null);let b;e[0]!==c||e[1]!==h?(b=()=>{q((async()=>{C(null);try{const N=await c.listAuthSessions({limit:50,userId:h});f(N.rows)}catch(N){const E=N;f(null),C(Oe(E))}})())},e[0]=c,e[1]=h,e[2]=b):b=e[2];let A;e[3]!==c||e[4]!==h||e[5]!==s?(A=[c,h,s],e[3]=c,e[4]=h,e[5]=s,e[6]=A):A=e[6],Ve(b,A);let y;e[7]!==c||e[8]!==n?(y=N=>{n(()=>c.revokeAuthSession({sessionId:N}))},e[7]=c,e[8]=n,e[9]=y):y=e[9];const I=y;let r;e[10]!==i?(r=i("Sessions"),e[10]=i,e[11]=r):r=e[11];let u;e[12]!==r?(u=t(je,{children:r}),e[12]=r,e[13]=u):u=e[13];let p;e[14]!==v?(p=v!==null&&t("p",{className:"text-sm text-destructive","data-testid":"ud-sessions-error",role:"alert",children:v}),e[14]=v,e[15]=p):p=e[15];let x;e[16]!==o||e[17]!==i?(x=o!==null&&o.length===0&&t("p",{className:"text-sm text-muted-foreground","data-testid":"ud-sessions-empty",children:i("No active sessions.")}),e[16]=o,e[17]=i,e[18]=x):x=e[18];let d;e[19]!==l||e[20]!==I||e[21]!==o||e[22]!==i?(d=o!==null&&o.length>0&&t(Q,{className:"overflow-hidden py-0",children:t(_,{className:"px-0",children:a(Ee,{"data-testid":"ud-sessions-table",children:[t(Re,{children:a(O,{children:[t(S,{children:i("expires")}),t(S,{children:i("ip")}),t(S,{children:i("user agent")}),t(S,{"aria-label":i("Actions")})]})}),t(Te,{children:o.map(N=>a(O,{"data-testid":`ud-session-${N.id}`,children:[t(U,{className:"text-muted-foreground tabular-nums",children:Ie(N.expiresAt)}),t(U,{children:N.ipAddress??""}),t(U,{className:"max-w-40 truncate",children:N.userAgent??""}),t(U,{children:t(R,{"data-testid":`ud-revoke-${N.id}`,disabled:l,onClick:()=>{I(N.id)},size:"xs",type:"button",variant:"ghost",children:i("Revoke")})})]},N.id))})]})})}),e[19]=l,e[20]=I,e[21]=o,e[22]=i,e[23]=d):d=e[23];let F;return e[24]!==u||e[25]!==p||e[26]!==x||e[27]!==d?(F=a("div",{className:"flex flex-col gap-2","data-testid":"ud-sessions",children:[u,p,x,d]}),e[24]=u,e[25]=p,e[26]=x,e[27]=d,e[28]=F):F=e[28],F},ct=m=>{const e=Ae(30),{busy:l,runAction:n,userId:h,version:s}=m,c=Y(),i=G(),[o,f]=w(null),[v,C]=w(null);let b;e[0]!==c||e[1]!==h?(b=()=>{q((async()=>{C(null);try{f(await c.listAuthAccounts({userId:h}))}catch(N){const E=N;f(null),C(Oe(E))}})())},e[0]=c,e[1]=h,e[2]=b):b=e[2];let A;e[3]!==c||e[4]!==h||e[5]!==s?(A=[c,h,s],e[3]=c,e[4]=h,e[5]=s,e[6]=A):A=e[6],Ve(b,A);let y;e[7]!==c||e[8]!==n||e[9]!==h?(y=N=>{n(()=>c.unlinkAuthAccount({accountId:N,userId:h}))},e[7]=c,e[8]=n,e[9]=h,e[10]=y):y=e[10];const I=y;let r;e[11]!==i?(r=i("Linked accounts"),e[11]=i,e[12]=r):r=e[12];let u;e[13]!==r?(u=t(je,{children:r}),e[13]=r,e[14]=u):u=e[14];let p;e[15]!==v?(p=v!==null&&t("p",{className:"text-sm text-destructive",role:"alert",children:v}),e[15]=v,e[16]=p):p=e[16];let x;e[17]!==o||e[18]!==i?(x=o!==null&&o.length===0&&t("p",{className:"text-sm text-muted-foreground",children:i("No linked accounts.")}),e[17]=o,e[18]=i,e[19]=x):x=e[19];let d;e[20]!==o||e[21]!==l||e[22]!==I||e[23]!==i?(d=o!==null&&o.length>0&&t(Q,{className:"overflow-hidden py-0",children:t(_,{className:"px-0",children:a(Ee,{"data-testid":"ud-accounts-table",children:[t(Re,{children:a(O,{children:[t(S,{children:i("provider")}),t(S,{children:i("created")}),t(S,{"aria-label":i("Actions")})]})}),t(Te,{children:o.map(N=>{const E=Ue(N.id);return a(O,{"data-testid":`ud-account-${E}`,children:[t(U,{children:Ue(N.providerId)}),t(U,{className:"text-muted-foreground tabular-nums",children:Ie(N.createdAt)}),t(U,{children:t(R,{"data-testid":`ud-unlink-${E}`,disabled:l,onClick:()=>{I(E)},size:"xs",type:"button",variant:"ghost",children:i("Unlink")})})]},E)})})]})})}),e[20]=o,e[21]=l,e[22]=I,e[23]=i,e[24]=d):d=e[24];let F;return e[25]!==u||e[26]!==p||e[27]!==x||e[28]!==d?(F=a("div",{className:"flex flex-col gap-2","data-testid":"ud-accounts",children:[u,p,x,d]}),e[25]=u,e[26]=p,e[27]=x,e[28]=d,e[29]=F):F=e[29],F},ut=m=>{const e=Ae(40),{busy:l,capabilities:n,runAction:h,userId:s,version:c}=m,i=Y(),o=G(),[f,v]=w(null);let C;e[0]!==n.passkey||e[1]!==i||e[2]!==s?(C=()=>{n.passkey&&q((async()=>{try{v(await i.listAuthPasskeys({userId:s}))}catch{v(null)}})())},e[0]=n.passkey,e[1]=i,e[2]=s,e[3]=C):C=e[3];let b;e[4]!==n.passkey||e[5]!==i||e[6]!==s||e[7]!==c?(b=[n.passkey,i,s,c],e[4]=n.passkey,e[5]=i,e[6]=s,e[7]=c,e[8]=b):b=e[8],Ve(C,b);let A;e[9]!==i||e[10]!==h||e[11]!==s?(A=()=>{h(()=>i.disableAuthTwoFactor({userId:s}))},e[9]=i,e[10]=h,e[11]=s,e[12]=A):A=e[12];const y=A;let I;e[13]!==i||e[14]!==h?(I=E=>{h(()=>i.deleteAuthPasskey({passkeyId:E}))},e[13]=i,e[14]=h,e[15]=I):I=e[15];const r=I;let u;e[16]!==o?(u=o("Security"),e[16]=o,e[17]=u):u=e[17];let p;e[18]!==u?(p=t(je,{children:u}),e[18]=u,e[19]=p):p=e[19];let x;e[20]!==l||e[21]!==n.twoFactor||e[22]!==y||e[23]!==o?(x=n.twoFactor&&t(R,{"data-testid":"ud-disable-2fa",disabled:l,onClick:y,size:"sm",type:"button",variant:"outline",children:o("Disable two-factor")}),e[20]=l,e[21]=n.twoFactor,e[22]=y,e[23]=o,e[24]=x):x=e[24];let d;e[25]!==n.passkey||e[26]!==f||e[27]!==o?(d=n.passkey&&f!==null&&f.length===0&&t("p",{className:"text-sm text-muted-foreground",children:o("No passkeys.")}),e[25]=n.passkey,e[26]=f,e[27]=o,e[28]=d):d=e[28];let F;e[29]!==l||e[30]!==n.passkey||e[31]!==r||e[32]!==f||e[33]!==o?(F=n.passkey&&f!==null&&f.length>0&&t(Q,{className:"overflow-hidden py-0",children:t(_,{className:"px-0",children:a(Ee,{"data-testid":"ud-passkeys-table",children:[t(Re,{children:a(O,{children:[t(S,{children:o("name")}),t(S,{children:o("created")}),t(S,{"aria-label":o("Actions")})]})}),t(Te,{children:f.map(E=>{const z=Ue(E.id);return a(O,{"data-testid":`ud-passkey-${z}`,children:[t(U,{children:Ue(E.name)||z}),t(U,{className:"text-muted-foreground tabular-nums",children:Ie(E.createdAt)}),t(U,{children:t(R,{"data-testid":`ud-delete-passkey-${z}`,disabled:l,onClick:()=>{r(z)},size:"xs",type:"button",variant:"ghost",children:o("Delete")})})]},z)})})]})})}),e[29]=l,e[30]=n.passkey,e[31]=r,e[32]=f,e[33]=o,e[34]=F):F=e[34];let N;return e[35]!==p||e[36]!==x||e[37]!==d||e[38]!==F?(N=a("div",{className:"flex flex-col gap-2","data-testid":"ud-security",children:[p,x,d,F]}),e[35]=p,e[36]=x,e[37]=d,e[38]=F,e[39]=N):N=e[39],N},mt=/(?:at|expires)$/iu,ht=new Set(["banExpires","banned","banReason","email","emailVerified","id","name","role"]),pt=(m,e)=>typeof e=="number"&&mt.test(m)?Ie(e):Ue(e),ft=({capabilities:m,onChanged:e,onClose:l,user:n})=>{const h=Y(),s=G(),c=n.banned===!0,[i,o]=w(null),[f,v]=w(!1),[C,b]=w(0),[A,y]=w(typeof n.role=="string"?n.role:""),[I,r]=w(""),[u,p]=w(""),[x,d]=w(""),[F,N]=w(null),[E,z]=w(!1),D=(k,B)=>{q((async()=>{v(!0),o(null);try{const L=await k();B?.refresh!==!1&&(b(j=>j+1),e()),B?.onResult?.(L)}catch(L){o(Oe(L))}v(!1)})())},$e=k=>{y(k.target.value)},Z=k=>{r(k.target.value)},Be=k=>{p(k.target.value)},W=k=>{d(k.target.value)},De=()=>{const k=A.trim();k!==""&&D(async()=>{await h.setAuthUserRole({role:k,userId:n.id})})},J=()=>{const k=Number.parseInt(u,10),B=Number.isFinite(k)&&k>0?k*86400:void 0;D(async()=>{await h.banAuthUser({expiresInSeconds:B,reason:I.trim()===""?void 0:I.trim(),userId:n.id})})},P=()=>{D(async()=>{await h.unbanAuthUser({userId:n.id})})},K=()=>{D(async()=>{await h.setAuthUserPassword({newPassword:x,userId:n.id}),d("")})},Fe=()=>{D(()=>h.impersonateAuthUser({userId:n.id}),{onResult:k=>{N(k.token)},refresh:!1})},X=()=>{D(async()=>{await h.revokeAuthUserSessions({userId:n.id})})},ze=()=>{D(async()=>{await h.removeAuthUser({userId:n.id}),l()})},ee=()=>{z(!0)},Se=()=>{z(!1)},te=Object.entries(n).filter(([k])=>!ht.has(k));return a(Ge,{label:s("User details"),onClose:l,panelTestId:"ud-panel",testId:"ud-overlay",variant:"drawer",children:[a("div",{className:"flex items-start justify-between gap-2",children:[a("div",{className:"flex flex-col gap-1",children:[t("h2",{className:"text-sm font-semibold text-foreground",children:n.name??n.email??n.id}),t("p",{className:"font-mono text-xs text-muted-foreground",children:n.id}),a("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[typeof n.role=="string"&&n.role!==""&&t(M,{variant:"secondary",children:n.role}),c?t(M,{variant:"destructive",children:s("Banned")}):t(M,{variant:"outline",children:s("Active")}),n.emailVerified===!0?t(M,{variant:"secondary",children:s("verified")}):t(M,{variant:"outline",children:s("unverified")})]})]}),t(R,{"data-testid":"ud-close",onClick:l,size:"sm",type:"button",variant:"ghost",children:s("Close")})]}),i!==null&&t("p",{className:"text-sm text-destructive","data-testid":"ud-action-error",role:"alert",children:i}),m.admin&&a(Q,{className:"gap-0 py-0",children:[t("header",{className:"border-b border-border px-4 py-3",children:t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s("Actions")})}),a(_,{className:"flex flex-col gap-3 p-3",children:[a("div",{className:"flex items-end gap-2",children:[a("div",{className:"flex flex-1 flex-col gap-1",children:[t(V,{htmlFor:"ud-role",children:s("Role")}),t($,{"data-testid":"ud-role-input",id:"ud-role",onChange:$e,value:A})]}),t(R,{"data-testid":"ud-set-role",disabled:f||A.trim()==="",onClick:De,size:"sm",type:"button",variant:"outline",children:s("Set role")})]}),c?t(R,{"data-testid":"ud-unban",disabled:f,onClick:P,size:"sm",type:"button",variant:"outline",children:s("Unban")}):a("div",{className:"flex items-end gap-2",children:[a("div",{className:"flex flex-1 flex-col gap-1",children:[t(V,{htmlFor:"ud-ban-reason",children:s("Ban reason (optional)")}),t($,{"data-testid":"ud-ban-reason",id:"ud-ban-reason",onChange:Z,value:I})]}),a("div",{className:"flex w-24 flex-col gap-1",children:[t(V,{htmlFor:"ud-ban-days",children:s("Days")}),t($,{"data-testid":"ud-ban-days",id:"ud-ban-days",onChange:Be,type:"number",value:u})]}),t(R,{"data-testid":"ud-ban",disabled:f,onClick:J,size:"sm",type:"button",variant:"destructive",children:s("Ban user")})]}),a("div",{className:"flex items-end gap-2",children:[a("div",{className:"flex flex-1 flex-col gap-1",children:[t(V,{htmlFor:"ud-password",children:s("New password")}),t($,{"data-testid":"ud-password",id:"ud-password",onChange:W,type:"password",value:x})]}),t(R,{"data-testid":"ud-set-password",disabled:f||x==="",onClick:K,size:"sm",type:"button",variant:"outline",children:s("Set password")})]}),a("div",{className:"flex flex-wrap gap-2",children:[t(R,{"data-testid":"ud-impersonate",disabled:f,onClick:Fe,size:"sm",type:"button",variant:"outline",children:s("Impersonate")}),t(R,{"data-testid":"ud-revoke-all",disabled:f,onClick:X,size:"sm",type:"button",variant:"outline",children:s("Revoke all sessions")}),E?a(Xe,{children:[t(R,{"data-testid":"ud-delete-confirm",disabled:f,onClick:ze,size:"sm",type:"button",variant:"destructive",children:s("Confirm delete")}),t(R,{"data-testid":"ud-delete-cancel",onClick:Se,size:"sm",type:"button",variant:"ghost",children:s("Cancel")})]}):t(R,{"data-testid":"ud-delete",disabled:f,onClick:ee,size:"sm",type:"button",variant:"destructive",children:s("Delete user")})]}),F!==null&&a("div",{className:"flex flex-col gap-1","data-testid":"ud-impersonation",children:[t(V,{htmlFor:"ud-token",children:s("Impersonation token")}),t($,{"data-testid":"ud-token",id:"ud-token",readOnly:!0,value:F})]})]})]}),t(dt,{busy:f,runAction:D,userId:n.id,version:C}),m.accounts&&t(ct,{busy:f,runAction:D,userId:n.id,version:C}),(m.twoFactor||m.passkey)&&t(ut,{busy:f,capabilities:m,runAction:D,userId:n.id,version:C}),a("div",{className:"flex flex-col gap-1","data-testid":"ud-fields",children:[t("h3",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s("Fields")}),t("dl",{className:"flex flex-col",children:te.map(([k,B])=>a("div",{className:"flex flex-col border-t border-border py-1.5",children:[t("dt",{className:"text-xs font-semibold text-muted-foreground",children:k}),t("dd",{className:"m-0 font-mono text-xs break-words",children:pt(k,B)})]},k))})]})]})},vt=50,zt=({pageSize:m=vt}={})=>{const e=Y(),l=G(),[n,h]=w(""),[s,c]=w(""),i=Ke(n),[o,f]=w(null),[v,C]=w(!1),{capabilities:b}=st(),A=i.trim(),y=s.trim(),I=_e(["lunora-auth-users",A,y,m],()=>e.listAuthUsers({filterField:y===""?void 0:"role",filterValue:y===""?void 0:y,limit:m,search:A===""?void 0:A}),{keepPreviousData:!0}),r=I.data?.rows??null,u=I.error,p=()=>{I.refetch()};Je(()=>{I.refetch()},!0);const x=o===null?null:r?.find(d=>d.id===o)??null;return a("div",{className:"flex flex-col gap-4","data-testid":"lunora-users",children:[a("div",{className:"flex flex-wrap items-center gap-2",children:[t($,{"aria-label":l("Search users"),className:"w-56","data-testid":"us-search",onChange:d=>{h(d.target.value)},placeholder:l("Search by email or name…"),value:n}),t($,{"aria-label":l("Filter by role"),className:"w-40","data-testid":"us-role-filter",onChange:d=>{c(d.target.value)},placeholder:l("Filter by role"),value:s}),t(R,{"data-testid":"us-new",onClick:()=>{C(!0)},size:"sm",type:"button",children:l("New user")})]}),u!==null&&t("p",{className:"text-sm text-destructive","data-testid":"us-users-error",role:"alert",children:u}),r!==null&&r.length===0&&t(Qe,{description:l("Users who sign up to your app will appear here."),icon:t("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:t("path",{d:"M16 20v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2M9.5 10a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm11.5 10v-2a4 4 0 0 0-3-3.85"})}),testId:"us-empty",title:l("No users.")}),r!==null&&r.length>0&&t(Q,{className:"overflow-hidden py-0",children:t(_,{className:"px-0",children:a(Ee,{"data-testid":"us-table",children:[t(Re,{children:a(O,{children:[t(S,{children:l("id")}),t(S,{children:l("email")}),t(S,{children:l("name")}),t(S,{children:l("role")}),t(S,{children:l("status")}),t(S,{children:l("verified")}),t(S,{children:l("created")}),t(S,{"aria-label":l("Actions")})]})}),t(Te,{children:r.map(d=>a(O,{"data-testid":`us-row-${d.id}`,children:[t(U,{className:"font-mono text-xs",children:d.id}),t(U,{children:d.email??""}),t(U,{children:d.name??""}),t(U,{children:typeof d.role=="string"&&d.role!==""?t(M,{variant:"secondary",children:d.role}):""}),t(U,{children:d.banned===!0?t(M,{variant:"destructive",children:l("Banned")}):t(M,{variant:"success",children:l("Active")})}),t(U,{children:d.emailVerified===!0?t(M,{variant:"success",children:l("yes")}):t(M,{variant:"outline",children:l("no")})}),t(U,{className:"text-muted-foreground tabular-nums",children:Ie(d.createdAt)}),t(U,{children:t(R,{"data-testid":`us-manage-${d.id}`,onClick:()=>{f(d.id)},size:"xs",type:"button",variant:"ghost",children:l("Manage")})})]},d.id))})]})})}),x!==null&&t(ft,{capabilities:b,onChanged:p,onClose:()=>{f(null)},user:x}),v&&t(ot,{onClose:()=>{C(!1)},onCreated:p}),b.inviteOnly&&t(lt,{})]})};export{zt as UsersPanel};
1
+ import{useLunora as K}from"@lunora/react";import{useState as S,useEffect as _e}from"react";import{B as q}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as R}from"../packem_shared/button-q0UYSmrn.mjs";import{C as X,a as ee}from"../packem_shared/card--2hKx4L2.mjs";import{E as Ye}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as B}from"../packem_shared/input-CXhxesPC.mjs";import{T as Ee,a as Re,b as Q,c as U,d as Te,e as P}from"../packem_shared/table-D0SBiDu-.mjs";import{b as qe}from"../packem_shared/use-admin-query-CR9mHt0P.mjs";import{c as W}from"react/compiler-runtime";import{u as Qe,D as Ze}from"../packem_shared/use-auth-config-HmTOvrWd.mjs";import{useAutoRefresh as Je}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.mjs";import Ke from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{w as Xe,h as Fe,f as J,i as Pe,b as Me}from"../packem_shared/internal-CyDwqA67.mjs";import{A as et}from"../packem_shared/auth-pager-DiDnXsfe.mjs";import{jsxs as u,jsx as t,Fragment as tt}from"react/jsx-runtime";import{C as st}from"../packem_shared/checkbox-CnS9cyCz.mjs";import{L as V}from"../packem_shared/label-DKFzyHq6.mjs";import{M as Ge}from"../packem_shared/modal-shell-CDztwLnv.mjs";import{u as nt}from"../packem_shared/use-async-submit-LWIKsZ8r.mjs";Ze.capabilities;const lt=()=>{const h=W(3),{config:e,ready:l}=Qe();let n;return h[0]!==e.capabilities||h[1]!==l?(n={capabilities:e.capabilities,ready:l},h[0]=e.capabilities,h[1]=l,h[2]=n):n=h[2],n},at=(h,e)=>typeof h.acceptedAt=="number"?"spent":typeof h.expiresAt=="number"&&h.expiresAt<=e?"expired":"pending",He=500,it=(h,e)=>{if(!URL.canParse(h.trim()))return null;const l=new URL(h.trim());return l.searchParams.set("email",e.email),l.searchParams.set("invite",e.token),l.toString()},rt=h=>{const e=W(34),{issued:l,onSignUpPageChange:n,signUpPage:o}=h,s=G(),[f,a]=S(null);let c;e[0]!==l||e[1]!==o?(c=it(o,l),e[0]=l,e[1]=o,e[2]=c):c=e[2];const d=c;let y;e[3]!==d?(y=()=>{const T="navigator"in globalThis?globalThis.navigator.clipboard:void 0;d===null||T===void 0||J(T.writeText(d).then(()=>(a(d),!0)))},e[3]=d,e[4]=y):y=e[4];const C=y;let g;e[5]!==s?(g=s("Send this link to the invitee. It is shown once and cannot be recovered."),e[5]=s,e[6]=g):g=e[6];let w;e[7]!==g?(w=t("p",{className:"text-sm",children:g}),e[7]=g,e[8]=w):w=e[8];const k=d===null;let v;e[9]!==s?(v=s("Your app's sign-up page"),e[9]=s,e[10]=v):v=e[10];let r;e[11]!==n?(r=T=>{n(T.target.value)},e[11]=n,e[12]=r):r=e[12];let m;e[13]!==o||e[14]!==k||e[15]!==v||e[16]!==r?(m=t(B,{"aria-invalid":k,"aria-label":v,"data-testid":"sign-up-invitation-page",onChange:r,value:o}),e[13]=o,e[14]=k,e[15]=v,e[16]=r,e[17]=m):m=e[17];const b=d??"";let x;e[18]!==b?(x=t(B,{"data-testid":"sign-up-invitation-link",readOnly:!0,value:b}),e[18]=b,e[19]=x):x=e[19];let N;e[20]!==f||e[21]!==d||e[22]!==s?(N=s(f!==null&&f===d?"Copied":"Copy"),e[20]=f,e[21]=d,e[22]=s,e[23]=N):N=e[23];let p;e[24]!==C||e[25]!==N?(p=t(R,{"data-testid":"sign-up-invitation-copy",onClick:C,type:"button",children:N}),e[24]=C,e[25]=N,e[26]=p):p=e[26];let i;e[27]!==x||e[28]!==p?(i=u("div",{className:"flex gap-2",children:[x,p]}),e[27]=x,e[28]=p,e[29]=i):i=e[29];let I;return e[30]!==i||e[31]!==w||e[32]!==m?(I=t(X,{children:u(ee,{className:"flex flex-col gap-2 p-4",children:[w,m,i]})}),e[30]=i,e[31]=w,e[32]=m,e[33]=I):I=e[33],I},ot=()=>{const h=K(),e=G(),[l,n]=S(""),[o,s]=S(null),[f,a]=S(null),[c,d]=S(()=>`${Xe(h.url)}/sign-up`),y=qe(["lunora-auth-sign-up-invitations",He],()=>h.listAuthSignUpInvitations({limit:He})),C=y.data?.rows??null,g=y.data?.total??0,w=()=>{const v=l.trim();v!==""&&(s(null),J((async()=>{try{const r=await h.createAuthSignUpInvitation({email:v}),m=typeof r.token=="string"?r.token:void 0;a(m===void 0?null:{email:v,token:m}),n(""),y.refetch()}catch(r){s(r instanceof Error?r.message:String(r))}})()))},k=v=>{s(null),J((async()=>{try{await h.revokeAuthSignUpInvitation({email:v}),y.refetch()}catch(r){s(r instanceof Error?r.message:String(r))}})())};return u("div",{className:"flex flex-col gap-4","data-testid":"sign-up-invitations",children:[u("div",{children:[t("h2",{className:"text-base font-medium",children:e("Sign-up invitations")}),t("p",{className:"text-sm text-muted-foreground",children:e("Only invited addresses can create an account. Nothing is emailed — send the invitee the one-time link yourself.")})]}),u("div",{className:"flex gap-2",children:[t(B,{"aria-label":e("Email address to invite"),"data-testid":"sign-up-invitation-email",onChange:v=>{n(v.target.value)},placeholder:e("ada@example.com"),type:"email",value:l}),t(R,{"data-testid":"sign-up-invitation-submit",onClick:w,type:"button",children:e("Invite")})]}),f!==null&&t(rt,{issued:f,onSignUpPageChange:d,signUpPage:c},f.token),(o??y.error)!==null&&t("p",{className:"text-sm text-destructive","data-testid":"sign-up-invitations-error",role:"alert",children:o??y.error}),C!==null&&C.length===0&&t(Ye,{testId:"sign-up-invitations-empty",title:e("Nobody has been invited yet.")}),C!==null&&g>C.length&&t("p",{className:"text-sm text-muted-foreground","data-testid":"sign-up-invitations-truncated",children:e("Showing the most recent invitations. Query the signUpInvitation table directly to see the rest.")}),C!==null&&C.length>0&&t(X,{children:t(ee,{className:"p-0",children:u(Ee,{children:[t(Re,{children:u(Q,{children:[t(U,{children:e("Email")}),t(U,{children:e("Status")}),t(U,{children:e("Expires")}),t(U,{children:e("Invited by")}),t(U,{})]})}),t(Te,{children:C.map(v=>{const r=at(v,Date.now()),m=v.email??"";return u(Q,{"data-testid":`sign-up-invitation-${m}`,children:[t(P,{children:m}),u(P,{"data-testid":`sign-up-invitation-status-${m}`,children:[r==="spent"&&e("Accepted"),r==="expired"&&e("Expired"),r==="pending"&&e("Pending")]}),t(P,{children:typeof v.expiresAt=="number"?Fe(v.expiresAt):"—"}),t(P,{children:v.invitedBy??"—"}),t(P,{className:"text-right",children:t(R,{onClick:()=>{k(m)},type:"button",variant:"ghost",children:e("Revoke")})})]},v.id)})})]})})})]})},dt={boolean:"checkbox",date:"datetime-local",number:"number",string:"text"},ct=(h,e)=>h.type==="boolean"?!0:typeof e!="string"||e.trim()===""?!1:h.type!=="number"||!Number.isNaN(Number(e.trim())),ut=(h,e)=>{if(h.type==="boolean")return e===!0?{value:!0}:h.required?{value:!1}:void 0;const l=typeof e=="string"?e.trim():"";if(l!==""){if(h.type==="number"){const n=Number(l);return Number.isNaN(n)?void 0:{value:n}}return{value:l}}},mt=h=>{const e=W(105),{onClose:l,onCreated:n}=h,o=K(),s=G(),{config:f}=Qe(),{busy:a,error:c,run:d}=nt(),[y,C]=S(""),[g,w]=S(""),[k,v]=S(""),[r,m]=S("");let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b={},e[0]=b):b=e[0];const[x,N]=S(b);let p;e[1]===Symbol.for("react.memo_cache_sentinel")?(p=A=>{C(A.target.value)},e[1]=p):p=e[1];const i=p;let I;e[2]===Symbol.for("react.memo_cache_sentinel")?(I=A=>{w(A.target.value)},e[2]=I):I=e[2];const T=I;let L;e[3]===Symbol.for("react.memo_cache_sentinel")?(L=A=>{v(A.target.value)},e[3]=L):L=e[3];const j=L;let _;e[4]===Symbol.for("react.memo_cache_sentinel")?(_=A=>{m(A.target.value)},e[4]=_):_=e[4];const H=_;let z;e[5]===Symbol.for("react.memo_cache_sentinel")?(z=(A,D)=>{N(Z=>({...Z,[A]:D}))},e[5]=z):z=e[5];const M=z;let Y;e[6]!==x?(Y=A=>x[A.name]??(A.type==="boolean"?!1:""),e[6]=x,e[7]=Y):Y=e[7];const E=Y;let O;if(e[8]!==f.userFields||e[9]!==E){let A;e[11]!==E?(A=D=>!D.required||ct(D,E(D)),e[11]=E,e[12]=A):A=e[12],O=f.userFields.every(A),e[8]=f.userFields,e[9]=E,e[10]=O}else O=e[10];const F=O;let $;e[13]!==a||e[14]!==y||e[15]!==g||e[16]!==F?($=!a&&y.trim()!==""&&g.trim()!==""&&F,e[13]=a,e[14]=y,e[15]=g,e[16]=F,e[17]=$):$=e[17];const Ue=$;let te;e[18]!==f.userFields||e[19]!==E?(te=()=>{const A={};for(const D of f.userFields){const Z=ut(D,E(D));Z!==void 0&&(A[D.name]=Z.value)}return Object.keys(A).length===0?void 0:A},e[18]=f.userFields,e[19]=E,e[20]=te):te=e[20];const Be=te;let De;e[21]!==Be||e[22]!==o||e[23]!==y||e[24]!==g||e[25]!==l||e[26]!==n||e[27]!==k||e[28]!==r||e[29]!==d?(De=()=>{d(async()=>{await o.createAuthUser({data:Be(),email:y.trim(),name:g.trim(),password:k===""?void 0:k,role:r.trim()===""?void 0:r.trim()}),n(),l()})},e[21]=Be,e[22]=o,e[23]=y,e[24]=g,e[25]=l,e[26]=n,e[27]=k,e[28]=r,e[29]=d,e[30]=De):De=e[30];const Le=De;let se;e[31]!==s?(se=s("Create user"),e[31]=s,e[32]=se):se=e[32];let ne;e[33]!==s?(ne=s("Create user"),e[33]=s,e[34]=ne):ne=e[34];let le;e[35]!==ne?(le=t("h2",{className:"text-sm font-semibold text-foreground",children:ne}),e[35]=ne,e[36]=le):le=e[36];let ae;e[37]!==s?(ae=s("email"),e[37]=s,e[38]=ae):ae=e[38];let ie;e[39]!==ae?(ie=t(V,{htmlFor:"uc-email",children:ae}),e[39]=ae,e[40]=ie):ie=e[40];let re;e[41]!==y?(re=t(B,{"data-testid":"uc-email",id:"uc-email",onChange:i,type:"email",value:y}),e[41]=y,e[42]=re):re=e[42];let oe;e[43]!==ie||e[44]!==re?(oe=u("div",{className:"flex flex-col gap-1",children:[ie,re]}),e[43]=ie,e[44]=re,e[45]=oe):oe=e[45];let de;e[46]!==s?(de=s("name"),e[46]=s,e[47]=de):de=e[47];let ce;e[48]!==de?(ce=t(V,{htmlFor:"uc-name",children:de}),e[48]=de,e[49]=ce):ce=e[49];let ue;e[50]!==g?(ue=t(B,{"data-testid":"uc-name",id:"uc-name",onChange:T,value:g}),e[50]=g,e[51]=ue):ue=e[51];let me;e[52]!==ce||e[53]!==ue?(me=u("div",{className:"flex flex-col gap-1",children:[ce,ue]}),e[52]=ce,e[53]=ue,e[54]=me):me=e[54];let he;e[55]!==s?(he=s("Password (optional)"),e[55]=s,e[56]=he):he=e[56];let fe;e[57]!==he?(fe=t(V,{htmlFor:"uc-password",children:he}),e[57]=he,e[58]=fe):fe=e[58];let pe;e[59]!==k?(pe=t(B,{"data-testid":"uc-password",id:"uc-password",onChange:j,type:"password",value:k}),e[59]=k,e[60]=pe):pe=e[60];let ve;e[61]!==fe||e[62]!==pe?(ve=u("div",{className:"flex flex-col gap-1",children:[fe,pe]}),e[61]=fe,e[62]=pe,e[63]=ve):ve=e[63];let ge;e[64]!==s?(ge=s("Role (optional)"),e[64]=s,e[65]=ge):ge=e[65];let be;e[66]!==ge?(be=t(V,{htmlFor:"uc-role",children:ge}),e[66]=ge,e[67]=be):be=e[67];let xe;e[68]!==r?(xe=t(B,{"data-testid":"uc-role",id:"uc-role",onChange:H,value:r}),e[68]=r,e[69]=xe):xe=e[69];let ye;e[70]!==be||e[71]!==xe?(ye=u("div",{className:"flex flex-col gap-1",children:[be,xe]}),e[70]=be,e[71]=xe,e[72]=ye):ye=e[72];let Ne;e[73]!==f.userFields||e[74]!==E||e[75]!==s?(Ne=f.userFields.length>0&&u("div",{className:"flex flex-col gap-3 border-t border-border pt-3","data-testid":"uc-plugin-fields",children:[t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s("Plugin fields")}),f.userFields.map(A=>{const D=`uc-field-${A.name}`,Z=A.required?"":` (${s("optional")})`;if(A.type==="boolean"){const Oe=E(A)===!0;return u("label",{className:"flex items-center gap-2",htmlFor:D,children:[t(st,{checked:Oe,"data-testid":D,id:D,onCheckedChange:We=>{M(A.name,We)}}),u("span",{className:"text-sm",children:[A.name,Z]})]},A.name)}const je=E(A);return u("div",{className:"flex flex-col gap-1",children:[u(V,{htmlFor:D,children:[A.name,Z]}),t(B,{"data-testid":D,id:D,onChange:Oe=>{M(A.name,Oe.target.value)},type:dt[A.type],value:typeof je=="string"?je:""})]},A.name)})]}),e[73]=f.userFields,e[74]=E,e[75]=s,e[76]=Ne):Ne=e[76];let ke;e[77]!==c?(ke=c!==null&&t("p",{className:"text-sm text-destructive","data-testid":"uc-error",role:"alert",children:c}),e[77]=c,e[78]=ke):ke=e[78];let Ce;e[79]!==s?(Ce=s("Cancel"),e[79]=s,e[80]=Ce):Ce=e[80];let we;e[81]!==l||e[82]!==Ce?(we=t(R,{"data-testid":"uc-cancel",onClick:l,size:"sm",type:"button",variant:"outline",children:Ce}),e[81]=l,e[82]=Ce,e[83]=we):we=e[83];const ze=!Ue;let Ae;e[84]!==a||e[85]!==s?(Ae=s(a?"Creating…":"Create"),e[84]=a,e[85]=s,e[86]=Ae):Ae=e[86];let Ie;e[87]!==Le||e[88]!==ze||e[89]!==Ae?(Ie=t(R,{"data-testid":"uc-submit",disabled:ze,onClick:Le,size:"sm",type:"button",children:Ae}),e[87]=Le,e[88]=ze,e[89]=Ae,e[90]=Ie):Ie=e[90];let Se;e[91]!==we||e[92]!==Ie?(Se=u("div",{className:"flex justify-end gap-2 pt-1",children:[we,Ie]}),e[91]=we,e[92]=Ie,e[93]=Se):Se=e[93];let $e;return e[94]!==l||e[95]!==se||e[96]!==le||e[97]!==oe||e[98]!==me||e[99]!==ve||e[100]!==ye||e[101]!==Ne||e[102]!==ke||e[103]!==Se?($e=u(Ge,{label:se,onClose:l,panelTestId:"uc-dialog",testId:"uc-overlay",variant:"dialog",children:[le,oe,me,ve,ye,Ne,ke,Se]}),e[94]=l,e[95]=se,e[96]=le,e[97]=oe,e[98]=me,e[99]=ve,e[100]=ye,e[101]=Ne,e[102]=ke,e[103]=Se,e[104]=$e):$e=e[104],$e},Ve=h=>{const e=W(2),{children:l}=h;let n;return e[0]!==l?(n=t("h3",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:l}),e[0]=l,e[1]=n):n=e[1],n},ht=h=>{const e=W(29),{busy:l,runAction:n,userId:o,version:s}=h,f=K(),a=G(),[c,d]=S(null),[y,C]=S(null);let g;e[0]!==f||e[1]!==o?(g=()=>{J((async()=>{C(null);try{const i=await f.listAuthSessions({limit:50,userId:o});d(i.rows)}catch(i){const I=i;d(null),C(Me(I))}})())},e[0]=f,e[1]=o,e[2]=g):g=e[2];let w;e[3]!==f||e[4]!==o||e[5]!==s?(w=[f,o,s],e[3]=f,e[4]=o,e[5]=s,e[6]=w):w=e[6],_e(g,w);let k;e[7]!==f||e[8]!==n?(k=i=>{n(()=>f.revokeAuthSession({sessionId:i}))},e[7]=f,e[8]=n,e[9]=k):k=e[9];const v=k;let r;e[10]!==a?(r=a("Sessions"),e[10]=a,e[11]=r):r=e[11];let m;e[12]!==r?(m=t(Ve,{children:r}),e[12]=r,e[13]=m):m=e[13];let b;e[14]!==y?(b=y!==null&&t("p",{className:"text-sm text-destructive","data-testid":"ud-sessions-error",role:"alert",children:y}),e[14]=y,e[15]=b):b=e[15];let x;e[16]!==c||e[17]!==a?(x=c!==null&&c.length===0&&t("p",{className:"text-sm text-muted-foreground","data-testid":"ud-sessions-empty",children:a("No active sessions.")}),e[16]=c,e[17]=a,e[18]=x):x=e[18];let N;e[19]!==l||e[20]!==v||e[21]!==c||e[22]!==a?(N=c!==null&&c.length>0&&t(X,{className:"overflow-hidden py-0",children:t(ee,{className:"px-0",children:u(Ee,{"data-testid":"ud-sessions-table",children:[t(Re,{children:u(Q,{children:[t(U,{children:a("expires")}),t(U,{children:a("ip")}),t(U,{children:a("user agent")}),t(U,{"aria-label":a("Actions")})]})}),t(Te,{children:c.map(i=>u(Q,{"data-testid":`ud-session-${i.id}`,children:[t(P,{className:"text-muted-foreground tabular-nums",children:Fe(i.expiresAt)}),t(P,{children:i.ipAddress??""}),t(P,{className:"max-w-40 truncate",children:i.userAgent??""}),t(P,{children:t(R,{"data-testid":`ud-revoke-${i.id}`,disabled:l,onClick:()=>{v(i.id)},size:"xs",type:"button",variant:"ghost",children:a("Revoke")})})]},i.id))})]})})}),e[19]=l,e[20]=v,e[21]=c,e[22]=a,e[23]=N):N=e[23];let p;return e[24]!==m||e[25]!==b||e[26]!==x||e[27]!==N?(p=u("div",{className:"flex flex-col gap-2","data-testid":"ud-sessions",children:[m,b,x,N]}),e[24]=m,e[25]=b,e[26]=x,e[27]=N,e[28]=p):p=e[28],p},ft=h=>{const e=W(30),{busy:l,runAction:n,userId:o,version:s}=h,f=K(),a=G(),[c,d]=S(null),[y,C]=S(null);let g;e[0]!==f||e[1]!==o?(g=()=>{J((async()=>{C(null);try{d(await f.listAuthAccounts({userId:o}))}catch(i){const I=i;d(null),C(Me(I))}})())},e[0]=f,e[1]=o,e[2]=g):g=e[2];let w;e[3]!==f||e[4]!==o||e[5]!==s?(w=[f,o,s],e[3]=f,e[4]=o,e[5]=s,e[6]=w):w=e[6],_e(g,w);let k;e[7]!==f||e[8]!==n||e[9]!==o?(k=i=>{n(()=>f.unlinkAuthAccount({accountId:i,userId:o}))},e[7]=f,e[8]=n,e[9]=o,e[10]=k):k=e[10];const v=k;let r;e[11]!==a?(r=a("Linked accounts"),e[11]=a,e[12]=r):r=e[12];let m;e[13]!==r?(m=t(Ve,{children:r}),e[13]=r,e[14]=m):m=e[14];let b;e[15]!==y?(b=y!==null&&t("p",{className:"text-sm text-destructive",role:"alert",children:y}),e[15]=y,e[16]=b):b=e[16];let x;e[17]!==c||e[18]!==a?(x=c!==null&&c.length===0&&t("p",{className:"text-sm text-muted-foreground",children:a("No linked accounts.")}),e[17]=c,e[18]=a,e[19]=x):x=e[19];let N;e[20]!==c||e[21]!==l||e[22]!==v||e[23]!==a?(N=c!==null&&c.length>0&&t(X,{className:"overflow-hidden py-0",children:t(ee,{className:"px-0",children:u(Ee,{"data-testid":"ud-accounts-table",children:[t(Re,{children:u(Q,{children:[t(U,{children:a("provider")}),t(U,{children:a("created")}),t(U,{"aria-label":a("Actions")})]})}),t(Te,{children:c.map(i=>{const I=Pe(i.id);return u(Q,{"data-testid":`ud-account-${I}`,children:[t(P,{children:Pe(i.providerId)}),t(P,{className:"text-muted-foreground tabular-nums",children:Fe(i.createdAt)}),t(P,{children:t(R,{"data-testid":`ud-unlink-${I}`,disabled:l,onClick:()=>{v(I)},size:"xs",type:"button",variant:"ghost",children:a("Unlink")})})]},I)})})]})})}),e[20]=c,e[21]=l,e[22]=v,e[23]=a,e[24]=N):N=e[24];let p;return e[25]!==m||e[26]!==b||e[27]!==x||e[28]!==N?(p=u("div",{className:"flex flex-col gap-2","data-testid":"ud-accounts",children:[m,b,x,N]}),e[25]=m,e[26]=b,e[27]=x,e[28]=N,e[29]=p):p=e[29],p},pt=h=>{const e=W(40),{busy:l,capabilities:n,runAction:o,userId:s,version:f}=h,a=K(),c=G(),[d,y]=S(null);let C;e[0]!==n.passkey||e[1]!==a||e[2]!==s?(C=()=>{n.passkey&&J((async()=>{try{y(await a.listAuthPasskeys({userId:s}))}catch{y(null)}})())},e[0]=n.passkey,e[1]=a,e[2]=s,e[3]=C):C=e[3];let g;e[4]!==n.passkey||e[5]!==a||e[6]!==s||e[7]!==f?(g=[n.passkey,a,s,f],e[4]=n.passkey,e[5]=a,e[6]=s,e[7]=f,e[8]=g):g=e[8],_e(C,g);let w;e[9]!==a||e[10]!==o||e[11]!==s?(w=()=>{o(()=>a.disableAuthTwoFactor({userId:s}))},e[9]=a,e[10]=o,e[11]=s,e[12]=w):w=e[12];const k=w;let v;e[13]!==a||e[14]!==o?(v=I=>{o(()=>a.deleteAuthPasskey({passkeyId:I}))},e[13]=a,e[14]=o,e[15]=v):v=e[15];const r=v;let m;e[16]!==c?(m=c("Security"),e[16]=c,e[17]=m):m=e[17];let b;e[18]!==m?(b=t(Ve,{children:m}),e[18]=m,e[19]=b):b=e[19];let x;e[20]!==l||e[21]!==n.twoFactor||e[22]!==k||e[23]!==c?(x=n.twoFactor&&t(R,{"data-testid":"ud-disable-2fa",disabled:l,onClick:k,size:"sm",type:"button",variant:"outline",children:c("Disable two-factor")}),e[20]=l,e[21]=n.twoFactor,e[22]=k,e[23]=c,e[24]=x):x=e[24];let N;e[25]!==n.passkey||e[26]!==d||e[27]!==c?(N=n.passkey&&d!==null&&d.length===0&&t("p",{className:"text-sm text-muted-foreground",children:c("No passkeys.")}),e[25]=n.passkey,e[26]=d,e[27]=c,e[28]=N):N=e[28];let p;e[29]!==l||e[30]!==n.passkey||e[31]!==r||e[32]!==d||e[33]!==c?(p=n.passkey&&d!==null&&d.length>0&&t(X,{className:"overflow-hidden py-0",children:t(ee,{className:"px-0",children:u(Ee,{"data-testid":"ud-passkeys-table",children:[t(Re,{children:u(Q,{children:[t(U,{children:c("name")}),t(U,{children:c("created")}),t(U,{"aria-label":c("Actions")})]})}),t(Te,{children:d.map(I=>{const T=Pe(I.id);return u(Q,{"data-testid":`ud-passkey-${T}`,children:[t(P,{children:Pe(I.name)||T}),t(P,{className:"text-muted-foreground tabular-nums",children:Fe(I.createdAt)}),t(P,{children:t(R,{"data-testid":`ud-delete-passkey-${T}`,disabled:l,onClick:()=>{r(T)},size:"xs",type:"button",variant:"ghost",children:c("Delete")})})]},T)})})]})})}),e[29]=l,e[30]=n.passkey,e[31]=r,e[32]=d,e[33]=c,e[34]=p):p=e[34];let i;return e[35]!==b||e[36]!==x||e[37]!==N||e[38]!==p?(i=u("div",{className:"flex flex-col gap-2","data-testid":"ud-security",children:[b,x,N,p]}),e[35]=b,e[36]=x,e[37]=N,e[38]=p,e[39]=i):i=e[39],i},vt=/(?:at|expires)$/iu,gt=/^[1-9]\d*$/u,bt=new Set(["banExpires","banned","banReason","email","emailVerified","id","name","role"]),xt=h=>{const e=W(51),{busy:l,onBan:n}=h,o=G(),[s,f]=S(""),[a,c]=S(""),[d,y]=S(!1);let C;e[0]!==a?(C=gt.test(a.trim())&&Number.isSafeInteger(Number(a.trim())*86400)?Number(a.trim()):void 0,e[0]=a,e[1]=C):C=e[1];const g=C,w=d||g!==void 0;let k;e[2]!==n||e[3]!==d||e[4]!==s||e[5]!==g?(k=()=>{n({expiresInSeconds:d||g===void 0?void 0:g*86400,reason:s.trim()===""?void 0:s.trim()})},e[2]=n,e[3]=d,e[4]=s,e[5]=g,e[6]=k):k=e[6];const v=k;let r;e[7]!==o?(r=o("Ban reason (optional)"),e[7]=o,e[8]=r):r=e[8];let m;e[9]!==r?(m=t(V,{htmlFor:"ud-ban-reason",children:r}),e[9]=r,e[10]=m):m=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=$=>{f($.target.value)},e[11]=b):b=e[11];let x;e[12]!==s?(x=t(B,{"data-testid":"ud-ban-reason",id:"ud-ban-reason",onChange:b,value:s}),e[12]=s,e[13]=x):x=e[13];let N;e[14]!==m||e[15]!==x?(N=u("div",{className:"flex flex-1 flex-col gap-1",children:[m,x]}),e[14]=m,e[15]=x,e[16]=N):N=e[16];let p;e[17]!==o?(p=o("Days"),e[17]=o,e[18]=p):p=e[18];let i;e[19]!==p?(i=t(V,{htmlFor:"ud-ban-days",children:p}),e[19]=p,e[20]=i):i=e[20];let I;e[21]!==a||e[22]!==g?(I=a.trim()!==""&&g===void 0,e[21]=a,e[22]=g,e[23]=I):I=e[23];let T;e[24]===Symbol.for("react.memo_cache_sentinel")?(T=$=>{c($.target.value)},e[24]=T):T=e[24];let L;e[25]!==a||e[26]!==d||e[27]!==I?(L=t(B,{"aria-invalid":I,"data-testid":"ud-ban-days",disabled:d,id:"ud-ban-days",min:1,onChange:T,step:1,type:"number",value:a}),e[25]=a,e[26]=d,e[27]=I,e[28]=L):L=e[28];let j;e[29]!==L||e[30]!==i?(j=u("div",{className:"flex w-24 flex-col gap-1",children:[i,L]}),e[29]=L,e[30]=i,e[31]=j):j=e[31];let _;e[32]===Symbol.for("react.memo_cache_sentinel")?(_=$=>{y($.target.checked)},e[32]=_):_=e[32];let H;e[33]!==d?(H=t("input",{checked:d,className:"size-4 accent-destructive","data-testid":"ud-ban-permanent",id:"ud-ban-permanent",onChange:_,type:"checkbox"}),e[33]=d,e[34]=H):H=e[34];let z;e[35]!==o?(z=o("Permanent"),e[35]=o,e[36]=z):z=e[36];let M;e[37]!==H||e[38]!==z?(M=u(V,{className:"flex items-center gap-1.5 pb-2 text-xs font-normal",htmlFor:"ud-ban-permanent",children:[H,z]}),e[37]=H,e[38]=z,e[39]=M):M=e[39];const Y=l||!w;let E;e[40]!==o?(E=o("Ban user"),e[40]=o,e[41]=E):E=e[41];let O;e[42]!==v||e[43]!==Y||e[44]!==E?(O=t(R,{"data-testid":"ud-ban",disabled:Y,onClick:v,size:"sm",type:"button",variant:"destructive",children:E}),e[42]=v,e[43]=Y,e[44]=E,e[45]=O):O=e[45];let F;return e[46]!==j||e[47]!==M||e[48]!==O||e[49]!==N?(F=u("div",{className:"flex items-end gap-2",children:[N,j,M,O]}),e[46]=j,e[47]=M,e[48]=O,e[49]=N,e[50]=F):F=e[50],F},yt=(h,e)=>typeof e=="number"&&vt.test(h)?Fe(e):Pe(e),Nt=({capabilities:h,onChanged:e,onClose:l,user:n})=>{const o=K(),s=G(),f=n.banned===!0,[a,c]=S(null),[d,y]=S(!1),[C,g]=S(0),[w,k]=S(typeof n.role=="string"?n.role:""),[v,r]=S(""),[m,b]=S(null),[x,N]=S(!1),p=(F,$)=>{J((async()=>{y(!0),c(null);try{const Ue=await F();$?.refresh!==!1&&(g(te=>te+1),e()),$?.onResult?.(Ue)}catch(Ue){c(Me(Ue))}y(!1)})())},i=F=>{k(F.target.value)},I=F=>{r(F.target.value)},T=()=>{const F=w.trim();F!==""&&p(async()=>{await o.setAuthUserRole({role:F,userId:n.id})})},L=F=>{p(async()=>{await o.banAuthUser({...F,userId:n.id})})},j=()=>{p(async()=>{await o.unbanAuthUser({userId:n.id})})},_=()=>{p(async()=>{await o.setAuthUserPassword({newPassword:v,userId:n.id}),r("")})},H=()=>{p(()=>o.impersonateAuthUser({userId:n.id}),{onResult:F=>{b(F.token)},refresh:!1})},z=()=>{p(async()=>{await o.revokeAuthUserSessions({userId:n.id})})},M=()=>{p(async()=>{await o.removeAuthUser({userId:n.id}),l()})},Y=()=>{N(!0)},E=()=>{N(!1)},O=Object.entries(n).filter(([F])=>!bt.has(F));return u(Ge,{label:s("User details"),onClose:l,panelTestId:"ud-panel",testId:"ud-overlay",variant:"drawer",children:[u("div",{className:"flex items-start justify-between gap-2",children:[u("div",{className:"flex flex-col gap-1",children:[t("h2",{className:"text-sm font-semibold text-foreground",children:n.name??n.email??n.id}),t("p",{className:"font-mono text-xs text-muted-foreground",children:n.id}),u("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[typeof n.role=="string"&&n.role!==""&&t(q,{variant:"secondary",children:n.role}),f?t(q,{variant:"destructive",children:s("Banned")}):t(q,{variant:"outline",children:s("Active")}),n.emailVerified===!0?t(q,{variant:"secondary",children:s("verified")}):t(q,{variant:"outline",children:s("unverified")})]})]}),t(R,{"data-testid":"ud-close",onClick:l,size:"sm",type:"button",variant:"ghost",children:s("Close")})]}),a!==null&&t("p",{className:"text-sm text-destructive","data-testid":"ud-action-error",role:"alert",children:a}),h.admin&&u(X,{className:"gap-0 py-0",children:[t("header",{className:"border-b border-border px-4 py-3",children:t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s("Actions")})}),u(ee,{className:"flex flex-col gap-3 p-3",children:[u("div",{className:"flex items-end gap-2",children:[u("div",{className:"flex flex-1 flex-col gap-1",children:[t(V,{htmlFor:"ud-role",children:s("Role")}),t(B,{"data-testid":"ud-role-input",id:"ud-role",onChange:i,value:w})]}),t(R,{"data-testid":"ud-set-role",disabled:d||w.trim()==="",onClick:T,size:"sm",type:"button",variant:"outline",children:s("Set role")})]}),f?t(R,{"data-testid":"ud-unban",disabled:d,onClick:j,size:"sm",type:"button",variant:"outline",children:s("Unban")}):t(xt,{busy:d,onBan:L}),u("div",{className:"flex items-end gap-2",children:[u("div",{className:"flex flex-1 flex-col gap-1",children:[t(V,{htmlFor:"ud-password",children:s("New password")}),t(B,{"data-testid":"ud-password",id:"ud-password",onChange:I,type:"password",value:v})]}),t(R,{"data-testid":"ud-set-password",disabled:d||v==="",onClick:_,size:"sm",type:"button",variant:"outline",children:s("Set password")})]}),u("div",{className:"flex flex-wrap gap-2",children:[t(R,{"data-testid":"ud-impersonate",disabled:d,onClick:H,size:"sm",type:"button",variant:"outline",children:s("Impersonate")}),t(R,{"data-testid":"ud-revoke-all",disabled:d,onClick:z,size:"sm",type:"button",variant:"outline",children:s("Revoke all sessions")}),x?u(tt,{children:[t(R,{"data-testid":"ud-delete-confirm",disabled:d,onClick:M,size:"sm",type:"button",variant:"destructive",children:s("Confirm delete")}),t(R,{"data-testid":"ud-delete-cancel",onClick:E,size:"sm",type:"button",variant:"ghost",children:s("Cancel")})]}):t(R,{"data-testid":"ud-delete",disabled:d,onClick:Y,size:"sm",type:"button",variant:"destructive",children:s("Delete user")})]}),m!==null&&u("div",{className:"flex flex-col gap-1","data-testid":"ud-impersonation",children:[t(V,{htmlFor:"ud-token",children:s("Impersonation token")}),t(B,{"data-testid":"ud-token",id:"ud-token",readOnly:!0,value:m})]})]})]}),t(ht,{busy:d,runAction:p,userId:n.id,version:C}),h.accounts&&t(ft,{busy:d,runAction:p,userId:n.id,version:C}),(h.twoFactor||h.passkey)&&t(pt,{busy:d,capabilities:h,runAction:p,userId:n.id,version:C}),u("div",{className:"flex flex-col gap-1","data-testid":"ud-fields",children:[t("h3",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s("Fields")}),t("dl",{className:"flex flex-col",children:O.map(([F,$])=>u("div",{className:"flex flex-col border-t border-border py-1.5",children:[t("dt",{className:"text-xs font-semibold text-muted-foreground",children:F}),t("dd",{className:"m-0 font-mono text-xs break-words",children:yt(F,$)})]},F))})]})]})},kt=50,Ht=({pageSize:h=kt}={})=>{const e=K(),l=G(),[n,o]=S(""),[s,f]=S(""),[a,c]=S(0),d=Ke(n),[y,C]=S(null),[g,w]=S(!1),{capabilities:k}=lt(),v=d.trim(),r=s.trim(),m=qe(["lunora-auth-users",v,r,h,a],()=>e.listAuthUsers({filterField:r===""?void 0:"role",filterValue:r===""?void 0:r,limit:h,offset:a,search:v===""?void 0:v}).then(i=>({...i,offset:a})),{keepPreviousData:!0}),b=m.data?.rows??null,x=m.error,N=()=>{m.refetch()};Je(()=>{m.refetch()},!0);const p=y===null?null:b?.find(i=>i.id===y)??null;return u("div",{className:"flex flex-col gap-4","data-testid":"lunora-users",children:[u("div",{className:"flex flex-wrap items-center gap-2",children:[t(B,{"aria-label":l("Search users"),className:"w-56","data-testid":"us-search",onChange:i=>{o(i.target.value),c(0)},placeholder:l("Search by email or name…"),value:n}),t(B,{"aria-label":l("Filter by role"),className:"w-40","data-testid":"us-role-filter",onChange:i=>{f(i.target.value),c(0)},placeholder:l("Filter by role"),value:s}),t(R,{"data-testid":"us-new",onClick:()=>{w(!0)},size:"sm",type:"button",children:l("New user")})]}),x!==null&&t("p",{className:"text-sm text-destructive","data-testid":"us-users-error",role:"alert",children:x}),b!==null&&b.length===0&&t(Ye,{description:l("Users who sign up to your app will appear here."),icon:t("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:t("path",{d:"M16 20v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2M9.5 10a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm11.5 10v-2a4 4 0 0 0-3-3.85"})}),testId:"us-empty",title:l("No users.")}),b!==null&&b.length>0&&t(X,{className:"overflow-hidden py-0",children:t(ee,{className:"px-0",children:u(Ee,{"data-testid":"us-table",children:[t(Re,{children:u(Q,{children:[t(U,{children:l("id")}),t(U,{children:l("email")}),t(U,{children:l("name")}),t(U,{children:l("role")}),t(U,{children:l("status")}),t(U,{children:l("verified")}),t(U,{children:l("created")}),t(U,{"aria-label":l("Actions")})]})}),t(Te,{children:b.map(i=>u(Q,{"data-testid":`us-row-${i.id}`,children:[t(P,{className:"font-mono text-xs",children:i.id}),t(P,{children:i.email??""}),t(P,{children:i.name??""}),t(P,{children:typeof i.role=="string"&&i.role!==""?t(q,{variant:"secondary",children:i.role}):""}),t(P,{children:i.banned===!0?t(q,{variant:"destructive",children:l("Banned")}):t(q,{variant:"success",children:l("Active")})}),t(P,{children:i.emailVerified===!0?t(q,{variant:"success",children:l("yes")}):t(q,{variant:"outline",children:l("no")})}),t(P,{className:"text-muted-foreground tabular-nums",children:Fe(i.createdAt)}),t(P,{children:t(R,{"data-testid":`us-manage-${i.id}`,onClick:()=>{C(i.id)},size:"xs",type:"button",variant:"ghost",children:l("Manage")})})]},i.id))})]})})}),b!==null&&t(et,{count:b.length,offset:m.data?.offset??0,onOffsetChange:c,pageSize:h,prefix:"us",total:m.data?.total}),p!==null&&t(Nt,{capabilities:k,onChanged:N,onClose:()=>{C(null)},user:p}),g&&t(mt,{onClose:()=>{w(!1)},onCreated:N}),k.inviteOnly&&t(ot,{})]})};export{Ht as UsersPanel};
@@ -1 +1 @@
1
- import{c as H}from"react/compiler-runtime";import{useLunora as K}from"@lunora/react";import{useState as h,useEffect as z}from"react";import{B as O}from"../packem_shared/button-q0UYSmrn.mjs";import{C as E,a as q}from"../packem_shared/card--2hKx4L2.mjs";import{E as P}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as R}from"../packem_shared/input-CXhxesPC.mjs";import{T as B,a as j,b,c as d,d as L,e as i}from"../packem_shared/table-D0SBiDu-.mjs";import{useT as U}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{f as M,b as V,i as W}from"../packem_shared/internal-B6haJbiP.mjs";import{jsxs as n,jsx as e}from"react/jsx-runtime";const Z=10,g=x=>{const a=H(7),{label:m,value:r}=x;let l;a[0]!==m?(l=e("span",{className:"font-mono text-[11px] uppercase tracking-wide text-muted-foreground",children:m}),a[0]=m,a[1]=l):l=a[1];const f=r??"—";let s;a[2]!==f?(s=e("span",{className:"font-mono text-sm",children:f}),a[2]=f,a[3]=s):s=a[3];let u;return a[4]!==l||a[5]!==s?(u=n("div",{className:"flex flex-col gap-0.5",children:[l,s]}),a[4]=l,a[5]=s,a[6]=u):u=a[6],u},se=({loadIndexes:x,runQuery:a}={})=>{const m=K(),r=U(),[l,f]=h(null),[s,u]=h(null),[v,C]=h(null),[N,F]=h(""),[p,y]=h(null),[S,w]=h(null),[k,I]=h(!1);z(()=>{const t={cancelled:!1};return M((async()=>{try{const o=await(x??(()=>m.listVectorIndexes()))();t.cancelled||(f(o),u(null),C(T=>T??o[0]?.name??null))}catch(o){t.cancelled||(f(null),u(V(o)))}})()),()=>{t.cancelled=!0}},[m,x]);const c=l?.find(t=>t.name===v)??null,Q=t=>{C(t.currentTarget.dataset.index??null),y(null),w(null)},$=t=>{F(t.target.value)},A=async()=>{const t=N.trim();if(!(v===null||t==="")){I(!0),w(null);try{const o=await(a??(T=>m.queryVectorIndex(T)))({name:v,text:t,topK:Z});y(o)}catch(o){y(null),w(V(o))}I(!1)}},D=()=>{M(A())};return n("div",{className:"flex flex-col gap-4","data-testid":"lunora-vector-browser",children:[s!==null&&e("p",{className:"text-sm text-destructive","data-testid":"vector-error",role:"alert",children:s}),l!==null&&l.length===0&&e(P,{description:r("Indexes declared with .vectorize() or defineVectorIndex() appear here."),icon:e("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:e("path",{d:"M4 7l8-4 8 4-8 4-8-4Zm0 5 8 4 8-4M4 17l8 4 8-4"})}),testId:"vector-empty",title:r("No vector indexes.")}),l!==null&&l.length>0&&e(E,{className:"overflow-hidden py-0",children:e(q,{className:"px-0",children:n(B,{"data-testid":"vector-table",children:[e(j,{children:n(b,{children:[e(d,{children:r("name")}),e(d,{children:r("table")}),e(d,{children:r("dimensions")}),e(d,{children:r("metric")}),e(d,{children:r("vectors")})]})}),e(L,{children:l.map(t=>n(b,{className:t.name===v?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-index":t.name,"data-testid":`vector-row-${t.name}`,onClick:Q,children:[e(i,{className:"font-mono text-xs",children:t.name}),e(i,{className:"font-mono text-xs",children:t.table}),e(i,{className:"tabular-nums",children:t.dimensions??"—"}),e(i,{children:t.metric??"—"}),e(i,{className:"tabular-nums",children:t.vectorsCount??"—"})]},t.name))})]})})}),c!==null&&n("section",{className:"border border-border bg-card p-3","data-testid":"vector-detail",children:[n("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e(g,{label:r("field"),value:c.field}),e(g,{label:r("dimensions"),value:c.dimensions}),e(g,{label:r("metric"),value:c.metric}),e(g,{label:r("vectors"),value:c.vectorsCount})]}),c.metadata!==void 0&&c.metadata.length>0&&n("p",{className:"mt-3 text-xs text-muted-foreground","data-testid":"vector-metadata",children:[r("metadata"),": ",e("span",{className:"font-mono",children:c.metadata.join(", ")})]}),n("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e(R,{className:"min-w-[18rem] flex-1","data-testid":"vector-query-input",onChange:$,placeholder:r("Search by similarity…"),value:N}),e(O,{"data-testid":"vector-search",disabled:k||N.trim()==="",onClick:D,children:r(k?"Searching…":"Search")})]}),S!==null&&e("p",{className:"mt-2 text-sm text-destructive","data-testid":"vector-query-error",role:"alert",children:S}),p!==null&&p.length===0&&e("p",{className:"mt-2 text-sm text-muted-foreground","data-testid":"vector-no-matches",children:r("No matches.")}),p!==null&&p.length>0&&e(E,{className:"mt-3 overflow-hidden py-0",children:e(q,{className:"px-0",children:n(B,{"data-testid":"vector-matches",children:[e(j,{children:n(b,{children:[e(d,{children:r("id")}),e(d,{children:r("score")}),e(d,{children:r("metadata")})]})}),e(L,{children:p.map(t=>n(b,{"data-testid":`vector-match-${t.id}`,children:[e(i,{className:"font-mono text-xs",children:t.id}),e(i,{className:"tabular-nums",children:t.score.toFixed(4)}),e(i,{className:"max-w-md truncate font-mono text-xs",children:t.metadata===void 0?"—":W(t.metadata)})]},t.id))})]})})})]})]})};export{se as VectorBrowser};
1
+ import{c as H}from"react/compiler-runtime";import{useLunora as K}from"@lunora/react";import{useState as h,useEffect as z}from"react";import{B as O}from"../packem_shared/button-q0UYSmrn.mjs";import{C as E,a as q}from"../packem_shared/card--2hKx4L2.mjs";import{E as P}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as R}from"../packem_shared/input-CXhxesPC.mjs";import{T as B,a as j,b,c as d,d as L,e as i}from"../packem_shared/table-D0SBiDu-.mjs";import{useT as U}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{f as M,b as V,i as W}from"../packem_shared/internal-CyDwqA67.mjs";import{jsxs as n,jsx as e}from"react/jsx-runtime";const Z=10,g=x=>{const a=H(7),{label:m,value:r}=x;let l;a[0]!==m?(l=e("span",{className:"font-mono text-[11px] uppercase tracking-wide text-muted-foreground",children:m}),a[0]=m,a[1]=l):l=a[1];const f=r??"—";let s;a[2]!==f?(s=e("span",{className:"font-mono text-sm",children:f}),a[2]=f,a[3]=s):s=a[3];let u;return a[4]!==l||a[5]!==s?(u=n("div",{className:"flex flex-col gap-0.5",children:[l,s]}),a[4]=l,a[5]=s,a[6]=u):u=a[6],u},se=({loadIndexes:x,runQuery:a}={})=>{const m=K(),r=U(),[l,f]=h(null),[s,u]=h(null),[v,C]=h(null),[N,F]=h(""),[p,y]=h(null),[S,w]=h(null),[k,I]=h(!1);z(()=>{const t={cancelled:!1};return M((async()=>{try{const o=await(x??(()=>m.listVectorIndexes()))();t.cancelled||(f(o),u(null),C(T=>T??o[0]?.name??null))}catch(o){t.cancelled||(f(null),u(V(o)))}})()),()=>{t.cancelled=!0}},[m,x]);const c=l?.find(t=>t.name===v)??null,Q=t=>{C(t.currentTarget.dataset.index??null),y(null),w(null)},$=t=>{F(t.target.value)},A=async()=>{const t=N.trim();if(!(v===null||t==="")){I(!0),w(null);try{const o=await(a??(T=>m.queryVectorIndex(T)))({name:v,text:t,topK:Z});y(o)}catch(o){y(null),w(V(o))}I(!1)}},D=()=>{M(A())};return n("div",{className:"flex flex-col gap-4","data-testid":"lunora-vector-browser",children:[s!==null&&e("p",{className:"text-sm text-destructive","data-testid":"vector-error",role:"alert",children:s}),l!==null&&l.length===0&&e(P,{description:r("Indexes declared with .vectorize() or defineVectorIndex() appear here."),icon:e("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:e("path",{d:"M4 7l8-4 8 4-8 4-8-4Zm0 5 8 4 8-4M4 17l8 4 8-4"})}),testId:"vector-empty",title:r("No vector indexes.")}),l!==null&&l.length>0&&e(E,{className:"overflow-hidden py-0",children:e(q,{className:"px-0",children:n(B,{"data-testid":"vector-table",children:[e(j,{children:n(b,{children:[e(d,{children:r("name")}),e(d,{children:r("table")}),e(d,{children:r("dimensions")}),e(d,{children:r("metric")}),e(d,{children:r("vectors")})]})}),e(L,{children:l.map(t=>n(b,{className:t.name===v?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-index":t.name,"data-testid":`vector-row-${t.name}`,onClick:Q,children:[e(i,{className:"font-mono text-xs",children:t.name}),e(i,{className:"font-mono text-xs",children:t.table}),e(i,{className:"tabular-nums",children:t.dimensions??"—"}),e(i,{children:t.metric??"—"}),e(i,{className:"tabular-nums",children:t.vectorsCount??"—"})]},t.name))})]})})}),c!==null&&n("section",{className:"border border-border bg-card p-3","data-testid":"vector-detail",children:[n("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e(g,{label:r("field"),value:c.field}),e(g,{label:r("dimensions"),value:c.dimensions}),e(g,{label:r("metric"),value:c.metric}),e(g,{label:r("vectors"),value:c.vectorsCount})]}),c.metadata!==void 0&&c.metadata.length>0&&n("p",{className:"mt-3 text-xs text-muted-foreground","data-testid":"vector-metadata",children:[r("metadata"),": ",e("span",{className:"font-mono",children:c.metadata.join(", ")})]}),n("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e(R,{className:"min-w-[18rem] flex-1","data-testid":"vector-query-input",onChange:$,placeholder:r("Search by similarity…"),value:N}),e(O,{"data-testid":"vector-search",disabled:k||N.trim()==="",onClick:D,children:r(k?"Searching…":"Search")})]}),S!==null&&e("p",{className:"mt-2 text-sm text-destructive","data-testid":"vector-query-error",role:"alert",children:S}),p!==null&&p.length===0&&e("p",{className:"mt-2 text-sm text-muted-foreground","data-testid":"vector-no-matches",children:r("No matches.")}),p!==null&&p.length>0&&e(E,{className:"mt-3 overflow-hidden py-0",children:e(q,{className:"px-0",children:n(B,{"data-testid":"vector-matches",children:[e(j,{children:n(b,{children:[e(d,{children:r("id")}),e(d,{children:r("score")}),e(d,{children:r("metadata")})]})}),e(L,{children:p.map(t=>n(b,{"data-testid":`vector-match-${t.id}`,children:[e(i,{className:"font-mono text-xs",children:t.id}),e(i,{className:"tabular-nums",children:t.score.toFixed(4)}),e(i,{className:"max-w-md truncate font-mono text-xs",children:t.metadata===void 0?"—":W(t.metadata)})]},t.id))})]})})})]})]})};export{se as VectorBrowser};
@@ -1 +1 @@
1
- import{useLunora as X}from"@lunora/react";import{useState as m,useEffect as te}from"react";import{B as E}from"../packem_shared/button-q0UYSmrn.mjs";import{C as P,a as U}from"../packem_shared/card--2hKx4L2.mjs";import{E as H}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as re}from"../packem_shared/input-CXhxesPC.mjs";import{T as j,a as z,b as x,c as i,d as J,e as d}from"../packem_shared/table-D0SBiDu-.mjs";import{T as se}from"../packem_shared/textarea--40GKAyz.mjs";import{u as ae}from"../packem_shared/use-admin-query-BKXiqLci.mjs";import{useT as Y}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as M}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{f as W,b as A,d as V,c as Z}from"../packem_shared/internal-B6haJbiP.mjs";import{jsxs as n,jsx as e}from"react/jsx-runtime";const ne=["queued","running","paused","waiting","complete","errored","terminated"],oe=["pause","resume","terminate"],le="WORKFLOWS_NOT_CONFIGURED",ie=o=>typeof o=="object"&&o!==null&&o.code===le,de=o=>{const s=o.error??o.output;if(s===void 0)return"—";try{return JSON.stringify(s)}catch{return"(unserializable)"}},ce=({loadDetail:o,loadInstances:s,readOnly:N,runAction:R,workflowName:w})=>{const O=X(),a=Y(),[h,g]=m(null),[k,I]=m(null),[v,_]=m(""),[b,f]=m(null),[$,S]=m(!1),[F,D]=m(null),p=o??(r=>O.getWorkflowInstance(r)),C=N?void 0:R??(s===void 0?r=>O.setWorkflowInstanceStatus(r):void 0),L=async()=>{f(null),S(!1);const r=v===""?void 0:v;try{if(s===void 0){const l=await O.listWorkflowInstances({name:w,status:r});if(l.configured===!1){g(null),S(!0);return}g(l.instances);return}g(await s({name:w,status:r}))}catch(l){g(null),ie(l)?S(!0):f(A(l))}};te(()=>{I(null),W(L())},[w,v]);const K=async r=>{f(null);try{I(await p({id:r,name:w}))}catch(l){f(A(l))}},q=async(r,l)=>{if(C!==void 0){D(r),f(null);try{await C({action:l,id:r,name:w}),await L()}catch(G){f(A(G))}D(null)}};return n("div",{className:"flex flex-col gap-3","data-testid":"lunora-workflow-instances",children:[n("div",{className:"flex items-center justify-between gap-2",children:[e("h3",{className:"text-sm font-medium",children:a("Instance history")}),n("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:r=>{_(r.target.value)},value:v,children:[e("option",{value:"",children:a("All statuses")}),ne.map(r=>e("option",{value:r,children:r},r))]})]}),b!==null&&e("p",{className:"text-sm text-destructive","data-testid":"workflow-instances-error",role:"alert",children:b}),$&&e(H,{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")}),!$&&h!==null&&h.length===0&&e(H,{description:a("No instances match this filter for the selected workflow."),testId:"workflow-instances-empty",title:a("No instances")}),h!==null&&h.length>0&&e(P,{className:"overflow-hidden py-0",children:e(U,{className:"px-0",children:n(j,{"data-testid":"workflow-instances-table",children:[e(z,{children:n(x,{children:[e(i,{children:a("Instance id")}),e(i,{children:a("Status")}),e(i,{children:a("Created")}),e(i,{children:a("Ended")}),e(i,{"aria-label":a("Actions")})]})}),e(J,{children:h.map(r=>n(x,{"data-testid":`workflow-instance-${r.id}`,children:[e(d,{className:"font-mono text-xs",children:r.id}),e(d,{className:"font-mono text-xs",children:r.status}),e(d,{className:"text-muted-foreground tabular-nums",children:r.createdOn??"—"}),e(d,{className:"text-muted-foreground tabular-nums",children:r.endedOn??"—"}),e(d,{className:"text-right",children:n("div",{className:"flex justify-end gap-1.5",children:[e(E,{"data-testid":`workflow-instance-steps-${r.id}`,onClick:()=>{W(K(r.id))},size:"sm",type:"button",variant:"outline",children:a("Steps")}),C!==void 0&&oe.map(l=>e(E,{"data-testid":`workflow-instance-${l}-${r.id}`,disabled:F===r.id,onClick:()=>{W(q(r.id,l))},size:"sm",type:"button",variant:"ghost",children:a(l)},l))]})})]},r.id))})]})})}),k!==null&&e(P,{className:"overflow-hidden py-0","data-testid":"workflow-instance-detail",children:n(U,{className:"flex flex-col gap-2 px-4 py-3",children:[n("div",{className:"flex items-center justify-between",children:[n("span",{className:"font-mono text-xs",children:[a("Steps")," · ",k.id]}),e(E,{"data-testid":"workflow-instance-detail-close",onClick:()=>{I(null)},size:"xs",type:"button",variant:"ghost",children:a("Close")})]}),k.steps.length===0?e("p",{className:"text-xs text-muted-foreground",children:a("This instance has no recorded steps yet.")}):n(j,{"data-testid":"workflow-instance-steps",children:[e(z,{children:n(x,{children:[e(i,{children:a("Step")}),e(i,{children:a("Type")}),e(i,{children:a("Attempts")}),e(i,{children:a("Started")}),e(i,{children:a("Output")})]})}),e(J,{children:k.steps.map((r,l)=>n(x,{"data-testid":`workflow-step-${String(l)}`,children:[e(d,{className:"font-mono text-xs",children:r.name}),e(d,{className:"text-xs text-muted-foreground",children:r.type??"—"}),e(d,{className:"tabular-nums",children:r.attempts??"—"}),e(d,{className:"text-muted-foreground tabular-nums",children:r.start??"—"}),e(d,{className:"font-mono text-xs text-muted-foreground",children:de(r)})]},`${r.name}:${String(l)}`))})]})]})})]})},me=Z(M.createWorkflowInstance),ue=Z(M.getWorkflowInstanceStatus),fe=o=>{if(o.error)return`${o.error.name}: ${o.error.message}`;if(o.output===void 0)return"—";try{return JSON.stringify(o.output)}catch{return"(unserializable)"}},he=(o,s)=>o.some(N=>N.exportName===s)?s:o[0]?.exportName??"",Te=()=>{const o=X(),s=Y(),{data:N,error:R}=ae(M.listWorkflows,{}),[w,O]=m(""),[a,h]=m(""),[g,k]=m(""),[I,v]=m(!1),[_,b]=m(null),[f,$]=m([]),[S,F]=m(null),D=N!==void 0,p=Array.isArray(N?.workflows)?[...N.workflows].toSorted((t,u)=>t.exportName.localeCompare(u.exportName)):[],T=he(p,w),B=p.find(t=>t.exportName===T),C=t=>{$(u=>{const c=u.filter(y=>!(y.exportName===t.exportName&&y.id===t.id));return[t,...c]})},L=async()=>{const t=T;if(t==="")return;let u;const c=g.trim();if(c!=="")try{u=JSON.parse(c)}catch{b(s("Params must be valid JSON"));return}v(!0),b(null);try{const y=a.trim(),Q=await o.query(me,{exportName:t,id:y===""?void 0:y,params:u},V(""));C({exportName:t,id:Q.id,status:Q.status}),h("")}catch(y){b(A(y))}v(!1)},K=()=>{W(L())},q=async(t,u)=>{F(u);try{const c=await o.query(ue,{exportName:t,id:u},V(""));C({error:c.error,exportName:t,id:c.id,output:c.output,status:c.status})}catch(c){b(A(c))}F(null)},r=t=>{O(t.target.value)},l=t=>{h(t.target.value)},G=t=>{k(t.target.value)},ee=t=>{const{export:u,id:c}=t.currentTarget.dataset;u!==void 0&&c!==void 0&&W(q(u,c))};return n("div",{className:"flex flex-col gap-6","data-testid":"lunora-workflows-panel",children:[R!==null&&e("p",{className:"text-sm text-destructive","data-testid":"workflows-error",role:"alert",children:R}),e("p",{className:"text-sm text-muted-foreground",children:s("Workflows are declared in code with defineWorkflow and run as durable Cloudflare Workflows. Start an instance and observe its status below.")}),D&&p.length===0?e(H,{description:s("No defineWorkflow is declared in lunora/workflows.ts in this deployment. Add one to run a durable, multi-step workflow."),testId:"workflows-empty",title:s("No workflows defined")}):e(P,{className:"overflow-hidden py-0",children:e(U,{className:"px-0",children:n(j,{"data-testid":"workflows-table",children:[e(z,{children:n(x,{children:[e(i,{children:s("Export")}),e(i,{children:s("Name")}),e(i,{children:s("Class")}),e(i,{children:s("Binding")})]})}),e(J,{children:p.map(t=>n(x,{"data-testid":`workflows-row-${t.exportName}`,children:[e(d,{className:"font-mono text-xs",children:t.exportName}),e(d,{className:"font-mono text-xs text-muted-foreground",children:t.name}),e(d,{className:"font-mono text-xs text-muted-foreground",children:t.className}),e(d,{className:"font-mono text-xs text-muted-foreground",children:t.binding})]},t.exportName))})]})})}),p.length>0&&n("div",{className:"flex flex-col gap-3","data-testid":"workflows-start",children:[e("h3",{className:"text-sm font-medium",children:s("Start instance")}),_!==null&&e("p",{className:"text-sm text-destructive","data-testid":"workflows-start-error",role:"alert",children:_}),n("div",{className:"flex flex-wrap items-center gap-2",children:[e("select",{"aria-label":s("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:r,value:T,children:p.map(t=>e("option",{value:t.exportName,children:t.exportName},t.exportName))}),e(re,{"aria-label":s("Instance id (optional)"),className:"max-w-48","data-testid":"workflows-start-id",onChange:l,placeholder:s("Instance id (optional)"),value:a}),e(E,{"data-testid":"workflows-start-button",disabled:I||T==="",onClick:K,children:s(I?"Starting…":"Start instance")})]}),e(se,{"aria-label":s("Params (JSON)"),className:"font-mono","data-testid":"workflows-start-params",onChange:G,placeholder:s("Params (JSON, optional)"),value:g})]}),f.length>0&&n("div",{className:"flex flex-col gap-3","data-testid":"workflows-instances",children:[e("h3",{className:"text-sm font-medium",children:s("Instances")}),e(P,{className:"overflow-hidden py-0",children:e(U,{className:"px-0",children:n(j,{"data-testid":"workflows-instances-table",children:[e(z,{children:n(x,{children:[e(i,{children:s("Workflow")}),e(i,{children:s("Instance id")}),e(i,{children:s("Status")}),e(i,{children:s("Output")}),e(i,{})]})}),e(J,{children:f.map(t=>n(x,{"data-testid":`workflows-instance-${t.id}`,children:[e(d,{className:"font-mono text-xs",children:t.exportName}),e(d,{className:"font-mono text-xs text-muted-foreground",children:t.id}),e(d,{className:"font-mono text-xs",children:t.status}),e(d,{className:"font-mono text-xs text-muted-foreground",children:fe(t)}),e(d,{children:e(E,{"data-export":t.exportName,"data-id":t.id,"data-testid":`workflows-instance-refresh-${t.id}`,disabled:S===t.id,onClick:ee,size:"xs",variant:"outline",children:S===t.id?s("Refreshing…"):s("Refresh")})})]},`${t.exportName}:${t.id}`))})]})})})]}),B!==void 0&&e(ce,{workflowName:B.name})]})};export{Te as default};
1
+ import{useLunora as X}from"@lunora/react";import{useState as m,useEffect as re}from"react";import{B as E}from"../packem_shared/button-q0UYSmrn.mjs";import{C as P,a as j}from"../packem_shared/card--2hKx4L2.mjs";import{E as H}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as se}from"../packem_shared/input-CXhxesPC.mjs";import{T as U,a as z,b as x,c as i,d as J,e as d}from"../packem_shared/table-D0SBiDu-.mjs";import{T as ae}from"../packem_shared/textarea--40GKAyz.mjs";import{u as ne}from"../packem_shared/use-admin-query-CR9mHt0P.mjs";import{useT as Y}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as M}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{f as W,b as A,j as Z,d as V,c as ee}from"../packem_shared/internal-CyDwqA67.mjs";import{jsxs as n,jsx as e}from"react/jsx-runtime";const oe=["queued","running","paused","waiting","complete","errored","terminated"],le=["pause","resume","terminate"],ie="WORKFLOWS_NOT_CONFIGURED",de=o=>typeof o=="object"&&o!==null&&o.code===ie,ce=o=>{const s=o.error??o.output;if(s===void 0)return"—";try{return JSON.stringify(s,Z)}catch{return"(unserializable)"}},me=({loadDetail:o,loadInstances:s,readOnly:N,runAction:R,workflowName:w})=>{const O=X(),a=Y(),[h,g]=m(null),[k,I]=m(null),[v,_]=m(""),[b,f]=m(null),[$,S]=m(!1),[F,D]=m(null),p=o??(r=>O.getWorkflowInstance(r)),C=N?void 0:R??(s===void 0?r=>O.setWorkflowInstanceStatus(r):void 0),L=async()=>{f(null),S(!1);const r=v===""?void 0:v;try{if(s===void 0){const l=await O.listWorkflowInstances({name:w,status:r});if(l.configured===!1){g(null),S(!0);return}g(l.instances);return}g(await s({name:w,status:r}))}catch(l){g(null),de(l)?S(!0):f(A(l))}};re(()=>{I(null),W(L())},[w,v]);const K=async r=>{f(null);try{I(await p({id:r,name:w}))}catch(l){f(A(l))}},q=async(r,l)=>{if(C!==void 0){D(r),f(null);try{await C({action:l,id:r,name:w}),await L()}catch(G){f(A(G))}D(null)}};return n("div",{className:"flex flex-col gap-3","data-testid":"lunora-workflow-instances",children:[n("div",{className:"flex items-center justify-between gap-2",children:[e("h3",{className:"text-sm font-medium",children:a("Instance history")}),n("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:r=>{_(r.target.value)},value:v,children:[e("option",{value:"",children:a("All statuses")}),oe.map(r=>e("option",{value:r,children:r},r))]})]}),b!==null&&e("p",{className:"text-sm text-destructive","data-testid":"workflow-instances-error",role:"alert",children:b}),$&&e(H,{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")}),!$&&h!==null&&h.length===0&&e(H,{description:a("No instances match this filter for the selected workflow."),testId:"workflow-instances-empty",title:a("No instances")}),h!==null&&h.length>0&&e(P,{className:"overflow-hidden py-0",children:e(j,{className:"px-0",children:n(U,{"data-testid":"workflow-instances-table",children:[e(z,{children:n(x,{children:[e(i,{children:a("Instance id")}),e(i,{children:a("Status")}),e(i,{children:a("Created")}),e(i,{children:a("Ended")}),e(i,{"aria-label":a("Actions")})]})}),e(J,{children:h.map(r=>n(x,{"data-testid":`workflow-instance-${r.id}`,children:[e(d,{className:"font-mono text-xs",children:r.id}),e(d,{className:"font-mono text-xs",children:r.status}),e(d,{className:"text-muted-foreground tabular-nums",children:r.createdOn??"—"}),e(d,{className:"text-muted-foreground tabular-nums",children:r.endedOn??"—"}),e(d,{className:"text-right",children:n("div",{className:"flex justify-end gap-1.5",children:[e(E,{"data-testid":`workflow-instance-steps-${r.id}`,onClick:()=>{W(K(r.id))},size:"sm",type:"button",variant:"outline",children:a("Steps")}),C!==void 0&&le.map(l=>e(E,{"data-testid":`workflow-instance-${l}-${r.id}`,disabled:F===r.id,onClick:()=>{W(q(r.id,l))},size:"sm",type:"button",variant:"ghost",children:a(l)},l))]})})]},r.id))})]})})}),k!==null&&e(P,{className:"overflow-hidden py-0","data-testid":"workflow-instance-detail",children:n(j,{className:"flex flex-col gap-2 px-4 py-3",children:[n("div",{className:"flex items-center justify-between",children:[n("span",{className:"font-mono text-xs",children:[a("Steps")," · ",k.id]}),e(E,{"data-testid":"workflow-instance-detail-close",onClick:()=>{I(null)},size:"xs",type:"button",variant:"ghost",children:a("Close")})]}),k.steps.length===0?e("p",{className:"text-xs text-muted-foreground",children:a("This instance has no recorded steps yet.")}):n(U,{"data-testid":"workflow-instance-steps",children:[e(z,{children:n(x,{children:[e(i,{children:a("Step")}),e(i,{children:a("Type")}),e(i,{children:a("Attempts")}),e(i,{children:a("Started")}),e(i,{children:a("Output")})]})}),e(J,{children:k.steps.map((r,l)=>n(x,{"data-testid":`workflow-step-${String(l)}`,children:[e(d,{className:"font-mono text-xs",children:r.name}),e(d,{className:"text-xs text-muted-foreground",children:r.type??"—"}),e(d,{className:"tabular-nums",children:r.attempts??"—"}),e(d,{className:"text-muted-foreground tabular-nums",children:r.start??"—"}),e(d,{className:"font-mono text-xs text-muted-foreground",children:ce(r)})]},`${r.name}:${String(l)}`))})]})]})})]})},ue=ee(M.createWorkflowInstance),fe=ee(M.getWorkflowInstanceStatus),he=o=>{if(o.error)return`${o.error.name}: ${o.error.message}`;if(o.output===void 0)return"—";try{return JSON.stringify(o.output,Z)}catch{return"(unserializable)"}},pe=(o,s)=>o.some(N=>N.exportName===s)?s:o[0]?.exportName??"",Ee=()=>{const o=X(),s=Y(),{data:N,error:R}=ne(M.listWorkflows,{}),[w,O]=m(""),[a,h]=m(""),[g,k]=m(""),[I,v]=m(!1),[_,b]=m(null),[f,$]=m([]),[S,F]=m(null),D=N!==void 0,p=Array.isArray(N?.workflows)?[...N.workflows].toSorted((t,u)=>t.exportName.localeCompare(u.exportName)):[],T=pe(p,w),B=p.find(t=>t.exportName===T),C=t=>{$(u=>{const c=u.filter(y=>!(y.exportName===t.exportName&&y.id===t.id));return[t,...c]})},L=async()=>{const t=T;if(t==="")return;let u;const c=g.trim();if(c!=="")try{u=JSON.parse(c)}catch{b(s("Params must be valid JSON"));return}v(!0),b(null);try{const y=a.trim(),Q=await o.query(ue,{exportName:t,id:y===""?void 0:y,params:u},V(""));C({exportName:t,id:Q.id,status:Q.status}),h("")}catch(y){b(A(y))}v(!1)},K=()=>{W(L())},q=async(t,u)=>{F(u);try{const c=await o.query(fe,{exportName:t,id:u},V(""));C({error:c.error,exportName:t,id:c.id,output:c.output,status:c.status})}catch(c){b(A(c))}F(null)},r=t=>{O(t.target.value)},l=t=>{h(t.target.value)},G=t=>{k(t.target.value)},te=t=>{const{export:u,id:c}=t.currentTarget.dataset;u!==void 0&&c!==void 0&&W(q(u,c))};return n("div",{className:"flex flex-col gap-6","data-testid":"lunora-workflows-panel",children:[R!==null&&e("p",{className:"text-sm text-destructive","data-testid":"workflows-error",role:"alert",children:R}),e("p",{className:"text-sm text-muted-foreground",children:s("Workflows are declared in code with defineWorkflow and run as durable Cloudflare Workflows. Start an instance and observe its status below.")}),D&&p.length===0?e(H,{description:s("No defineWorkflow is declared in lunora/workflows.ts in this deployment. Add one to run a durable, multi-step workflow."),testId:"workflows-empty",title:s("No workflows defined")}):e(P,{className:"overflow-hidden py-0",children:e(j,{className:"px-0",children:n(U,{"data-testid":"workflows-table",children:[e(z,{children:n(x,{children:[e(i,{children:s("Export")}),e(i,{children:s("Name")}),e(i,{children:s("Class")}),e(i,{children:s("Binding")})]})}),e(J,{children:p.map(t=>n(x,{"data-testid":`workflows-row-${t.exportName}`,children:[e(d,{className:"font-mono text-xs",children:t.exportName}),e(d,{className:"font-mono text-xs text-muted-foreground",children:t.name}),e(d,{className:"font-mono text-xs text-muted-foreground",children:t.className}),e(d,{className:"font-mono text-xs text-muted-foreground",children:t.binding})]},t.exportName))})]})})}),p.length>0&&n("div",{className:"flex flex-col gap-3","data-testid":"workflows-start",children:[e("h3",{className:"text-sm font-medium",children:s("Start instance")}),_!==null&&e("p",{className:"text-sm text-destructive","data-testid":"workflows-start-error",role:"alert",children:_}),n("div",{className:"flex flex-wrap items-center gap-2",children:[e("select",{"aria-label":s("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:r,value:T,children:p.map(t=>e("option",{value:t.exportName,children:t.exportName},t.exportName))}),e(se,{"aria-label":s("Instance id (optional)"),className:"max-w-48","data-testid":"workflows-start-id",onChange:l,placeholder:s("Instance id (optional)"),value:a}),e(E,{"data-testid":"workflows-start-button",disabled:I||T==="",onClick:K,children:s(I?"Starting…":"Start instance")})]}),e(ae,{"aria-label":s("Params (JSON)"),className:"font-mono","data-testid":"workflows-start-params",onChange:G,placeholder:s("Params (JSON, optional)"),value:g})]}),f.length>0&&n("div",{className:"flex flex-col gap-3","data-testid":"workflows-instances",children:[e("h3",{className:"text-sm font-medium",children:s("Instances")}),e(P,{className:"overflow-hidden py-0",children:e(j,{className:"px-0",children:n(U,{"data-testid":"workflows-instances-table",children:[e(z,{children:n(x,{children:[e(i,{children:s("Workflow")}),e(i,{children:s("Instance id")}),e(i,{children:s("Status")}),e(i,{children:s("Output")}),e(i,{})]})}),e(J,{children:f.map(t=>n(x,{"data-testid":`workflows-instance-${t.id}`,children:[e(d,{className:"font-mono text-xs",children:t.exportName}),e(d,{className:"font-mono text-xs text-muted-foreground",children:t.id}),e(d,{className:"font-mono text-xs",children:t.status}),e(d,{className:"font-mono text-xs text-muted-foreground",children:he(t)}),e(d,{children:e(E,{"data-export":t.exportName,"data-id":t.id,"data-testid":`workflows-instance-refresh-${t.id}`,disabled:S===t.id,onClick:te,size:"xs",variant:"outline",children:S===t.id?s("Refreshing…"):s("Refresh")})})]},`${t.exportName}:${t.id}`))})]})})})]}),B!==void 0&&e(me,{workflowName:B.name})]})};export{Ee as default};
@@ -1,2 +1,2 @@
1
- import{c as F}from"react/compiler-runtime";import{useLunora as V}from"@lunora/react";import{useState as z,useEffect as W}from"react";import{B as H}from"./button-q0UYSmrn.mjs";import{E as K}from"./empty-state-D7jEML_T.mjs";import{useT as M}from"./DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as X}from"./ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{c as Z,d as ee,g as te}from"./internal-B6haJbiP.mjs";import{jsxs as R,jsx as u}from"react/jsx-runtime";const le=Z(X.listTables),ne=["react","client","cli"],ae={action:"action",mutation:"mutation",query:"query"},Q=a=>{const e=a.indexOf(":");return e===-1?{file:"",fn:a}:{file:a.slice(0,e),fn:a.slice(e+1)}},ie=({file:a,fn:e,kind:i})=>`await client.${ae[i]}(api.${a}.${e}, { /* args */ });`,se=a=>{const e=`api.${a.file}.${a.fn}`;switch(a.kind){case"action":return`const { call: ${a.fn} } = useAction(${e});`;case"mutation":return`const ${a.fn} = useMutation(${e});`;default:return`const data = useQuery(${e}, { /* args */ });`}},oe=({file:a,fn:e})=>`lunora run ${a}:${e} --args '{ }'`,ce=a=>["// Read rows",`const rows = await ctx.db.query("${a}").collect();`,"","// Insert a row",`const id = await ctx.db.insert("${a}", { /* fields */ });`,"","// Generated types",`type Row = Doc<"${a}">;`,`type RowId = Id<"${a}">;`].join(`
1
+ import{c as F}from"react/compiler-runtime";import{useLunora as V}from"@lunora/react";import{useState as z,useEffect as W}from"react";import{B as H}from"./button-q0UYSmrn.mjs";import{E as K}from"./empty-state-D7jEML_T.mjs";import{useT as M}from"./DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as X}from"./ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{c as Z,d as ee,g as te}from"./internal-CyDwqA67.mjs";import{jsxs as R,jsx as u}from"react/jsx-runtime";const le=Z(X.listTables),ne=["react","client","cli"],ae={action:"action",mutation:"mutation",query:"query"},Q=a=>{const e=a.indexOf(":");return e===-1?{file:"",fn:a}:{file:a.slice(0,e),fn:a.slice(e+1)}},ie=({file:a,fn:e,kind:i})=>`await client.${ae[i]}(api.${a}.${e}, { /* args */ });`,se=a=>{const e=`api.${a.file}.${a.fn}`;switch(a.kind){case"action":return`const { call: ${a.fn} } = useAction(${e});`;case"mutation":return`const ${a.fn} = useMutation(${e});`;default:return`const data = useQuery(${e}, { /* args */ });`}},oe=({file:a,fn:e})=>`lunora run ${a}:${e} --args '{ }'`,ce=a=>["// Read rows",`const rows = await ctx.db.query("${a}").collect();`,"","// Insert a row",`const id = await ctx.db.insert("${a}", { /* fields */ });`,"","// Generated types",`type Row = Doc<"${a}">;`,`type RowId = Id<"${a}">;`].join(`
2
2
  `),re=(a,e)=>{switch(a){case"cli":return oe(e);case"client":return ie(e);default:return se(e)}},U=a=>{const e=F(19),{code:i,label:s,testId:l}=a,n=M();let c;e[0]!==i?(c=()=>{te(i)},e[0]=i,e[1]=c):c=e[1];const m=c;let t;e[2]!==s?(t=u("span",{className:"text-xs font-medium text-muted-foreground",children:s}),e[2]=s,e[3]=t):t=e[3];const d=`${l}-copy`;let o;e[4]!==n?(o=n("Copy"),e[4]=n,e[5]=o):o=e[5];let f;e[6]!==m||e[7]!==d||e[8]!==o?(f=u(H,{"data-testid":d,onClick:m,size:"xs",type:"button",variant:"ghost",children:o}),e[6]=m,e[7]=d,e[8]=o,e[9]=f):f=e[9];let p;e[10]!==t||e[11]!==f?(p=R("div",{className:"flex items-center justify-between gap-2",children:[t,f]}),e[10]=t,e[11]=f,e[12]=p):p=e[12];let r;e[13]!==i||e[14]!==l?(r=u("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":l,children:i}),e[13]=i,e[14]=l,e[15]=r):r=e[15];let b;return e[16]!==p||e[17]!==r?(b=R("div",{className:"flex flex-col gap-1.5",children:[p,r]}),e[16]=p,e[17]=r,e[18]=b):b=e[18],b},de=a=>{const e=F(46),{file:i,fn:s,kind:l}=a,n=M(),[c,m]=z("react");let t,d,o;if(e[0]!==i||e[1]!==s||e[2]!==l||e[3]!==n||e[4]!==c){const x={file:i,fn:s,kind:l};let k;e[8]!==n?(k=n("CLI"),e[8]=n,e[9]=k):k=e[9];let w;e[10]!==n?(w=n("Client"),e[10]=n,e[11]=w):w=e[11];let I;e[12]!==n?(I=n("React"),e[12]=n,e[13]=I):I=e[13];let C;e[14]!==k||e[15]!==w||e[16]!==I?(C={cli:k,client:w,react:I},e[14]=k,e[15]=w,e[16]=I,e[17]=C):C=e[17],o=C;let B;e[18]===Symbol.for("react.memo_cache_sentinel")?(B=D=>{m(D.currentTarget.dataset.tab)},e[18]=B):B=e[18],t=B,d=re(c,x),e[0]=i,e[1]=s,e[2]=l,e[3]=n,e[4]=c,e[5]=t,e[6]=d,e[7]=o}else t=e[5],d=e[6],o=e[7];const f=d,p=`api.${i}.${s}`;let r;e[19]!==p?(r=u("h2",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"api-fn-title",children:p}),e[19]=p,e[20]=r):r=e[20];let b;e[21]!==l||e[22]!==n?(b=n("Call this {kind} from your app.",{kind:l}),e[21]=l,e[22]=n,e[23]=b):b=e[23];let h;e[24]!==b?(h=u("p",{className:"text-xs text-muted-foreground",children:b}),e[24]=b,e[25]=h):h=e[25];let v;e[26]!==r||e[27]!==h?(v=R("div",{children:[r,h]}),e[26]=r,e[27]=h,e[28]=v):v=e[28];let $;e[29]!==n?($=n("Snippet flavour"),e[29]=n,e[30]=$):$=e[30];let y;e[31]!==t||e[32]!==c||e[33]!==o?(y=ne.map(x=>u(H,{"aria-selected":c===x,"data-tab":x,"data-testid":`api-tab-${x}`,onClick:t,role:"tab",size:"xs",type:"button",variant:c===x?"default":"outline",children:o[x]},x)),e[31]=t,e[32]=c,e[33]=o,e[34]=y):y=e[34];let N;e[35]!==$||e[36]!==y?(N=u("div",{"aria-label":$,className:"flex gap-1.5","data-testid":"api-tabs",role:"tablist",children:y}),e[35]=$,e[36]=y,e[37]=N):N=e[37];const _=o[c],A=`api-snippet-${c}`;let S;e[38]!==f||e[39]!==_||e[40]!==A?(S=u(U,{code:f,label:_,testId:A}),e[38]=f,e[39]=_,e[40]=A,e[41]=S):S=e[41];let T;return e[42]!==S||e[43]!==v||e[44]!==N?(T=R("div",{className:"flex flex-col gap-3","data-testid":"api-fn-doc",children:[v,N,S]}),e[42]=S,e[43]=v,e[44]=N,e[45]=T):T=e[45],T},fe=a=>{const e=F(19),{name:i}=a,s=M();let l;e[0]!==i?(l=ce(i),e[0]=i,e[1]=l):l=e[1];const n=l;let c;e[2]!==i?(c=u("h2",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"api-table-title",children:i}),e[2]=i,e[3]=c):c=e[3];let m;e[4]!==s?(m=s("Read and write this table through the typed data model."),e[4]=s,e[5]=m):m=e[5];let t;e[6]!==m?(t=u("p",{className:"text-xs text-muted-foreground",children:m}),e[6]=m,e[7]=t):t=e[7];let d;e[8]!==c||e[9]!==t?(d=R("div",{children:[c,t]}),e[8]=c,e[9]=t,e[10]=d):d=e[10];let o;e[11]!==s?(o=s("Data model"),e[11]=s,e[12]=o):o=e[12];let f;e[13]!==n||e[14]!==o?(f=u(U,{code:n,label:o,testId:"api-snippet-table"}),e[13]=n,e[14]=o,e[15]=f):f=e[15];let p;return e[16]!==d||e[17]!==f?(p=R("div",{className:"flex flex-col gap-3","data-testid":"api-table-doc",children:[d,f]}),e[16]=d,e[17]=f,e[18]=p):p=e[18],p},G=a=>{const e=F(8),{active:i,label:s,onSelect:l,testId:n,value:c}=a;let m;e[0]!==l||e[1]!==c?(m=()=>{l(c)},e[0]=l,e[1]=c,e[2]=m):m=e[2];const t=m,d=i?"page":void 0;let o;return e[3]!==s||e[4]!==t||e[5]!==d||e[6]!==n?(o=u("button",{"aria-current":d,className:"w-full truncate rounded-md px-2 py-1 text-start font-mono text-xs text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:bg-sidebar-accent aria-[current=page]:bg-sidebar-accent aria-[current=page]:font-medium aria-[current=page]:text-foreground","data-testid":n,onClick:t,type:"button",children:s}),e[3]=s,e[4]=t,e[5]=d,e[6]=n,e[7]=o):o=e[7],o},pe=a=>{const e=new Map;for(const i of a){const{file:s,fn:l}=Q(i.path),n=e.get(s)??[];n.push({fn:l,kind:i.kind,path:i.path}),e.set(s,n)}return[...e.entries()].map(([i,s])=>({file:i,items:s.toSorted((l,n)=>l.fn.localeCompare(n.fn))})).toSorted((i,s)=>i.file.localeCompare(s.file))},ke=a=>{const e=F(58),{functions:i,initialShardKey:s}=a,l=M(),n=V(),[c,m]=z(null),[t,d]=z(null);let o,f;e[0]!==n||e[1]!==s?(o=()=>{let D=!1;return n.query(le,{},ee(s??"")).then(L=>(D||m(L),L)).catch(()=>{D||m([])}),()=>{D=!0}},f=[n,s],e[0]=n,e[1]=s,e[2]=o,e[3]=f):(o=e[2],f=e[3]),W(o,f);let p,r,b,h,v,$,y,N,_,A;if(e[4]!==i||e[5]!==t||e[6]!==l||e[7]!==c){const D=i??[],L=pe(D),O=(c??[]).map(ue).toSorted(me);let P;e[18]===Symbol.for("react.memo_cache_sentinel")?(P=g=>{d({kind:"fn",path:g})},e[18]=P):P=e[18];const Y=P;let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=g=>{d({kind:"table",name:g})},e[19]=j):j=e[19];const J=j;r=t?.kind==="fn"?D.find(g=>g.path===t.path):void 0,p=D.length>0||O.length>0,b=r===void 0?void 0:Q(r.path),_="grid min-h-0 gap-6 md:grid-cols-[16rem_minmax(0,1fr)]",A="lunora-api-docs",e[20]!==l?(h=l("API resources"),e[20]=l,e[21]=h):h=e[21],v="flex flex-col gap-4 overflow-y-auto",$="api-rail";let q;e[22]!==t||e[23]!==l?(q=g=>R("div",{className:"flex flex-col gap-1",children:[u("span",{className:"px-2 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:g.file||l("(root)")}),g.items.map(E=>u(G,{active:t?.kind==="fn"&&t.path===E.path,label:E.fn,onSelect:Y,testId:`api-rail-fn-${E.path}`,value:E.path},E.path))]},g.file),e[22]=t,e[23]=l,e[24]=q):q=e[24],y=L.map(q),N=O.length>0&&R("div",{className:"flex flex-col gap-1",children:[u("span",{className:"px-2 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:l("Tables")}),O.map(g=>u(G,{active:t?.kind==="table"&&t.name===g,label:g,onSelect:J,testId:`api-rail-table-${g}`,value:g},g))]}),e[4]=i,e[5]=t,e[6]=l,e[7]=c,e[8]=p,e[9]=r,e[10]=b,e[11]=h,e[12]=v,e[13]=$,e[14]=y,e[15]=N,e[16]=_,e[17]=A}else p=e[8],r=e[9],b=e[10],h=e[11],v=e[12],$=e[13],y=e[14],N=e[15],_=e[16],A=e[17];let S;e[25]!==p||e[26]!==l?(S=!p&&u("p",{className:"px-2 text-xs text-muted-foreground","data-testid":"api-rail-empty",children:l("No functions or tables to document yet.")}),e[25]=p,e[26]=l,e[27]=S):S=e[27];let T;e[28]!==S||e[29]!==h||e[30]!==v||e[31]!==$||e[32]!==y||e[33]!==N?(T=R("nav",{"aria-label":h,className:v,"data-testid":$,children:[y,N,S]}),e[28]=S,e[29]=h,e[30]=v,e[31]=$,e[32]=y,e[33]=N,e[34]=T):T=e[34];let x;e[35]!==t||e[36]!==l?(x=t===null&&u(K,{description:l("Select a function or table to see how to call it from your app."),testId:"api-empty",title:l("API usage snippets")}),e[35]=t,e[36]=l,e[37]=x):x=e[37];let k;e[38]!==t?.kind||e[39]!==r||e[40]!==b?(k=t?.kind==="fn"&&r!==void 0&&b!==void 0&&u(de,{file:b.file,fn:b.fn,kind:r.kind},r.path),e[38]=t?.kind,e[39]=r,e[40]=b,e[41]=k):k=e[41];let w;e[42]!==t?.kind||e[43]!==r||e[44]!==l?(w=t?.kind==="fn"&&r===void 0&&u(K,{testId:"api-empty",title:l("API usage snippets")}),e[42]=t?.kind,e[43]=r,e[44]=l,e[45]=w):w=e[45];let I;e[46]!==t?(I=t?.kind==="table"&&u(fe,{name:t.name}),e[46]=t,e[47]=I):I=e[47];let C;e[48]!==x||e[49]!==k||e[50]!==w||e[51]!==I?(C=R("div",{className:"min-w-0",children:[x,k,w,I]}),e[48]=x,e[49]=k,e[50]=w,e[51]=I,e[52]=C):C=e[52];let B;return e[53]!==T||e[54]!==C||e[55]!==_||e[56]!==A?(B=R("div",{className:_,"data-testid":A,children:[T,C]}),e[53]=T,e[54]=C,e[55]=_,e[56]=A,e[57]=B):B=e[57],B};function ue(a){return a.name}function me(a,e){return a.localeCompare(e)}export{oe as buildCliSnippet,ie as buildClientSnippet,se as buildReactSnippet,ce as buildTableSnippet,ke as default,Q as splitPath};
@@ -1 +1 @@
1
- import{c as k}from"react/compiler-runtime";import{useLunora as v}from"@lunora/react";import{E as h}from"./empty-state-D7jEML_T.mjs";import{S as g}from"./skeleton-DX1gfixl.mjs";import{u as O,R as S}from"./reference-view-DiikOols.mjs";import{useT as A}from"./DEFAULT_LOCALE-A1Yg5ORA.mjs";import{jsxs as I,jsx as m}from"react/jsx-runtime";const P=["get","post","put","patch","delete","head","options","trace"],y=r=>r?.content?.["application/json"]?.schema,j=(r,e)=>Object.entries(r.responses??{}).map(([i,s])=>{const c=s.$ref?.replace("#/components/responses/",""),n=c===void 0?s:e.components?.responses?.[c]??s;return{description:n.description,schema:y(n),status:i}}),b=(r,e,i,s,c)=>{const n=y(s.requestBody),l=n?.properties?.functionPath?.const,t=typeof l=="string"?l:void 0,f=t===void 0?n:n?.properties?.args,a=s.operationId??`${i} ${e}`;return{argsSchema:f,description:s.description,functionPath:t,httpPath:e,key:r,kind:s["x-lunora-function-kind"],method:i.toUpperCase(),operationId:a,requestSchema:n,responses:j(s,c),summary:s.summary??a,tags:s.tags??[],title:s.summary??a}},x=r=>{const e=[];for(const[i,s]of Object.entries(r.paths??{})){const c=i.includes("#")?i.slice(0,i.indexOf("#")):i;for(const n of P){const l=s[n];l!==void 0&&e.push(b(i,c,n,l,r))}}return e},w=r=>{const e=r??{},i=x(e),s=new Map((e.tags??[]).map(t=>[t.name,t.description])),c=new Set,n=[],l=t=>{if(c.has(t))return;c.add(t);const f=i.filter(a=>(a.tags[0]??"")===t);f.length>0&&n.push({description:s.get(t),name:t,operations:f})};for(const t of e.tags??[])l(t.name);for(const t of i)l(t.tags[0]??"");return{groups:n,operationByKey:new Map(i.map(t=>[t.key,t])),server:e.servers?.[0]?.url,title:e.info?.title??"API reference",version:e.info?.version}},R=r=>{const{paths:e}=r;return e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0},T=r=>{const e=r;return R(e)?{kind:"empty"}:{kind:"ready",spec:e}},B=r=>{const e=k(23),{spec:i}=r,s=A(),c=v();let n;e[0]!==c?(n=()=>c.fetchOpenApi(),e[0]=c,e[1]=n):n=e[1];const t=O(i,n,T);let f;e[2]!==t.kind||e[3]!==t.spec?(f=t.kind==="ready"?w(t.spec):void 0,e[2]=t.kind,e[3]=t.spec,e[4]=f):f=e[4];const a=f;if(t.kind==="loading"){let o;return e[5]===Symbol.for("react.memo_cache_sentinel")?(o=I("div",{className:"flex flex-col gap-4","data-testid":"api-reference-loading",children:[m(g,{className:"h-8 w-48"}),m(g,{className:"h-64 w-full"})]}),e[5]=o):o=e[5],o}if(t.kind==="error"){let o;e[6]!==t.message||e[7]!==s?(o=s("Couldn't load the OpenAPI spec: {message}",{message:t.message}),e[6]=t.message,e[7]=s,e[8]=o):o=e[8];let p;e[9]!==s?(p=s("API reference unavailable"),e[9]=s,e[10]=p):p=e[10];let d;return e[11]!==o||e[12]!==p?(d=m(h,{description:o,testId:"api-reference-error",title:p}),e[11]=o,e[12]=p,e[13]=d):d=e[13],d}if(t.kind==="empty"||a===void 0){let o;e[14]!==s?(o=s("Run `lunora codegen` and wire `_generated/openapi.json` to the worker to render the API reference here."),e[14]=s,e[15]=o):o=e[15];let p;e[16]!==s?(p=s("No OpenAPI spec configured"),e[16]=s,e[17]=p):p=e[17];let d;return e[18]!==o||e[19]!==p?(d=m(h,{description:o,testId:"api-reference-empty",title:p}),e[18]=o,e[19]=p,e[20]=d):d=e[20],d}let u;return e[21]!==a?(u=m(S,{model:a}),e[21]=a,e[22]=u):u=e[22],u};export{B as default};
1
+ import{c as k}from"react/compiler-runtime";import{useLunora as v}from"@lunora/react";import{E as h}from"./empty-state-D7jEML_T.mjs";import{S as g}from"./skeleton-DX1gfixl.mjs";import{u as O,R as S}from"./reference-view-vNXUVPlA.mjs";import{useT as A}from"./DEFAULT_LOCALE-A1Yg5ORA.mjs";import{jsxs as I,jsx as m}from"react/jsx-runtime";const P=["get","post","put","patch","delete","head","options","trace"],y=r=>r?.content?.["application/json"]?.schema,j=(r,e)=>Object.entries(r.responses??{}).map(([i,s])=>{const c=s.$ref?.replace("#/components/responses/",""),n=c===void 0?s:e.components?.responses?.[c]??s;return{description:n.description,schema:y(n),status:i}}),b=(r,e,i,s,c)=>{const n=y(s.requestBody),l=n?.properties?.functionPath?.const,t=typeof l=="string"?l:void 0,f=t===void 0?n:n?.properties?.args,a=s.operationId??`${i} ${e}`;return{argsSchema:f,description:s.description,functionPath:t,httpPath:e,key:r,kind:s["x-lunora-function-kind"],method:i.toUpperCase(),operationId:a,requestSchema:n,responses:j(s,c),summary:s.summary??a,tags:s.tags??[],title:s.summary??a}},x=r=>{const e=[];for(const[i,s]of Object.entries(r.paths??{})){const c=i.includes("#")?i.slice(0,i.indexOf("#")):i;for(const n of P){const l=s[n];l!==void 0&&e.push(b(i,c,n,l,r))}}return e},w=r=>{const e=r??{},i=x(e),s=new Map((e.tags??[]).map(t=>[t.name,t.description])),c=new Set,n=[],l=t=>{if(c.has(t))return;c.add(t);const f=i.filter(a=>(a.tags[0]??"")===t);f.length>0&&n.push({description:s.get(t),name:t,operations:f})};for(const t of e.tags??[])l(t.name);for(const t of i)l(t.tags[0]??"");return{groups:n,operationByKey:new Map(i.map(t=>[t.key,t])),server:e.servers?.[0]?.url,title:e.info?.title??"API reference",version:e.info?.version}},R=r=>{const{paths:e}=r;return e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0},T=r=>{const e=r;return R(e)?{kind:"empty"}:{kind:"ready",spec:e}},B=r=>{const e=k(23),{spec:i}=r,s=A(),c=v();let n;e[0]!==c?(n=()=>c.fetchOpenApi(),e[0]=c,e[1]=n):n=e[1];const t=O(i,n,T);let f;e[2]!==t.kind||e[3]!==t.spec?(f=t.kind==="ready"?w(t.spec):void 0,e[2]=t.kind,e[3]=t.spec,e[4]=f):f=e[4];const a=f;if(t.kind==="loading"){let o;return e[5]===Symbol.for("react.memo_cache_sentinel")?(o=I("div",{className:"flex flex-col gap-4","data-testid":"api-reference-loading",children:[m(g,{className:"h-8 w-48"}),m(g,{className:"h-64 w-full"})]}),e[5]=o):o=e[5],o}if(t.kind==="error"){let o;e[6]!==t.message||e[7]!==s?(o=s("Couldn't load the OpenAPI spec: {message}",{message:t.message}),e[6]=t.message,e[7]=s,e[8]=o):o=e[8];let p;e[9]!==s?(p=s("API reference unavailable"),e[9]=s,e[10]=p):p=e[10];let d;return e[11]!==o||e[12]!==p?(d=m(h,{description:o,testId:"api-reference-error",title:p}),e[11]=o,e[12]=p,e[13]=d):d=e[13],d}if(t.kind==="empty"||a===void 0){let o;e[14]!==s?(o=s("Run `lunora codegen` and wire `_generated/openapi.json` to the worker to render the API reference here."),e[14]=s,e[15]=o):o=e[15];let p;e[16]!==s?(p=s("No OpenAPI spec configured"),e[16]=s,e[17]=p):p=e[17];let d;return e[18]!==o||e[19]!==p?(d=m(h,{description:o,testId:"api-reference-empty",title:p}),e[18]=o,e[19]=p,e[20]=d):d=e[20],d}let u;return e[21]!==a?(u=m(S,{model:a}),e[21]=a,e[22]=u):u=e[22],u};export{B as default};
@@ -1 +1 @@
1
- import{c as U}from"react/compiler-runtime";import{Dialog as D}from"@base-ui/react/dialog";import{useNavigate as H}from"@tanstack/react-router";import{useState as B,useRef as Q,useEffect as V}from"react";import{useT as W}from"./DEFAULT_LOCALE-A1Yg5ORA.mjs";import{f as X}from"./internal-B6haJbiP.mjs";import{u as G}from"./shortcuts-B9gDaXmw.mjs";import{c as J}from"./utils-bhneXptQ.mjs";import{jsx as r,jsxs as A}from"react/jsx-runtime";const F="lunora:command-palette",ce=()=>{"window"in globalThis&&globalThis.dispatchEvent(new Event(F))},Y=v=>{const e=U(18),{active:f,index:o,item:n,onActivate:h,onSelect:b}=v;let g;e[0]!==n||e[1]!==b?(g=()=>{b(n)},e[0]=n,e[1]=b,e[2]=g):g=e[2];const c=g;let x;e[3]!==o||e[4]!==h?(x=()=>{h(o)},e[3]=o,e[4]=h,e[5]=x):x=e[5];const d=x,m=f?"bg-accent text-accent-foreground":"text-foreground";let u;e[6]!==m?(u=J("flex w-full items-center justify-between gap-3 rounded-md px-3 py-2 text-start text-sm outline-none transition-colors hover:bg-accent hover:text-accent-foreground",m),e[6]=m,e[7]=u):u=e[7];let s;e[8]!==n.label?(s=r("span",{children:n.label}),e[8]=n.label,e[9]=s):s=e[9];let i;e[10]!==n.group?(i=r("span",{className:"text-xs text-muted-foreground",children:n.group}),e[10]=n.group,e[11]=i):i=e[11];let p;return e[12]!==c||e[13]!==d||e[14]!==u||e[15]!==s||e[16]!==i?(p=r("li",{children:A("button",{className:u,onClick:c,onMouseEnter:d,type:"button",children:[s,i]})}),e[12]=c,e[13]=d,e[14]=u,e[15]=s,e[16]=i,e[17]=p):p=e[17],p},Z=(v,e)=>{const f=e.trim().toLowerCase();return f===""?v:v.filter(o=>o.label.toLowerCase().includes(f)||o.group.toLowerCase().includes(f))},de=v=>{const e=U(40),{items:f}=v,o=W(),n=H(),{palette:h}=G(),[b,g]=B(!1),[c,x]=B(""),[d,m]=B(0),u=Q(null);let s,i;e[0]!==h?(s=()=>{const t=S=>{if(!(S.metaKey||S.ctrlKey)||S.key.toLowerCase()!==h)return;const{target:_}=S;_ instanceof HTMLElement&&(_.isContentEditable||["INPUT","SELECT","TEXTAREA"].includes(_.tagName))||(S.preventDefault(),g(!0))},l=()=>{g(!0)};return globalThis.addEventListener("keydown",t),globalThis.addEventListener(F,l),()=>{globalThis.removeEventListener("keydown",t),globalThis.removeEventListener(F,l)}},i=[h],e[0]=h,e[1]=s,e[2]=i):(s=e[1],i=e[2]),V(s,i);let p;e[3]!==f||e[4]!==c?(p=Z(f,c),e[3]=f,e[4]=c,e[5]=p):p=e[5];const a=p;let I;e[6]===Symbol.for("react.memo_cache_sentinel")?(I=t=>{g(t),t||(x(""),m(0))},e[6]=I):I=e[6];const M=I;let K;e[7]!==n?(K=t=>{if(M(!1),t.run!==void 0){t.run();return}t.to!==void 0&&X(n({to:t.to}))},e[7]=n,e[8]=K):K=e[8];const w=K;let P;e[9]===Symbol.for("react.memo_cache_sentinel")?(P=t=>{x(t.target.value),m(0)},e[9]=P):P=e[9];const q=P;let z;e[10]!==d||e[11]!==a||e[12]!==w?(z=t=>{e:switch(t.key){case"ArrowDown":{t.preventDefault(),m(l=>a.length===0?0:(l+1)%a.length);break e}case"ArrowUp":{t.preventDefault(),m(l=>a.length===0?0:(l-1+a.length)%a.length);break e}case"Enter":{t.preventDefault();const l=a[d];l!==void 0&&w(l);break e}}},e[10]=d,e[11]=a,e[12]=w,e[13]=z):z=e[13];const j=z;let R;e[14]===Symbol.for("react.memo_cache_sentinel")?(R=r(D.Backdrop,{className:"fixed inset-0 z-50 bg-black/40 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0"}),e[14]=R):R=e[14];let y;e[15]!==o?(y=o("Command palette"),e[15]=o,e[16]=y):y=e[16];let E;e[17]!==y?(E=r(D.Title,{className:"sr-only",children:y}),e[17]=y,e[18]=E):E=e[18];let O;e[19]===Symbol.for("react.memo_cache_sentinel")?(O=A("svg",{"aria-hidden":"true",className:"size-4 text-muted-foreground",fill:"none",stroke:"currentColor",strokeWidth:1.8,viewBox:"0 0 24 24",children:[r("circle",{cx:"11",cy:"11",r:"7"}),r("path",{d:"m21 21-4.3-4.3",strokeLinecap:"round"})]}),e[19]=O):O=e[19];let N;e[20]!==o?(N=o("Search…"),e[20]=o,e[21]=N):N=e[21];let C;e[22]!==j||e[23]!==c||e[24]!==N?(C=A("div",{className:"flex items-center gap-2 border-b border-border px-3",children:[O,r("input",{className:"h-11 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground","data-testid":"dash-command-input",onChange:q,onKeyDown:j,placeholder:N,ref:u,type:"text",value:c})]}),e[22]=j,e[23]=c,e[24]=N,e[25]=C):C=e[25];let T;e[26]!==d||e[27]!==a||e[28]!==w||e[29]!==o?(T=a.length===0?r("li",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:o("No results.")}):a.map((t,l)=>r(Y,{active:l===d,index:l,item:t,onActivate:m,onSelect:w},t.to??`${t.group}:${t.label}`)),e[26]=d,e[27]=a,e[28]=w,e[29]=o,e[30]=T):T=e[30];let k;e[31]!==T?(k=r("ul",{className:"max-h-80 overflow-y-auto p-1.5","data-testid":"dash-command-list",children:T}),e[31]=T,e[32]=k):k=e[32];let L;e[33]!==E||e[34]!==C||e[35]!==k?(L=A(D.Portal,{children:[R,A(D.Popup,{className:"fixed start-1/2 top-24 z-50 w-[36rem] max-w-[90vw] -translate-x-1/2 overflow-hidden rounded-lg border border-border bg-popover text-popover-foreground shadow-lg outline-none data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95","data-testid":"dash-command-palette",initialFocus:u,children:[E,C,k]})]}),e[33]=E,e[34]=C,e[35]=k,e[36]=L):L=e[36];let $;return e[37]!==b||e[38]!==L?($=r(D.Root,{onOpenChange:M,open:b,children:L}),e[37]=b,e[38]=L,e[39]=$):$=e[39],$};export{de as CommandPalette,ce as openCommandPalette};
1
+ import{c as U}from"react/compiler-runtime";import{Dialog as D}from"@base-ui/react/dialog";import{useNavigate as H}from"@tanstack/react-router";import{useState as B,useRef as Q,useEffect as V}from"react";import{useT as W}from"./DEFAULT_LOCALE-A1Yg5ORA.mjs";import{f as X}from"./internal-CyDwqA67.mjs";import{u as G}from"./shortcuts-B9gDaXmw.mjs";import{c as J}from"./utils-bhneXptQ.mjs";import{jsx as r,jsxs as A}from"react/jsx-runtime";const F="lunora:command-palette",ce=()=>{"window"in globalThis&&globalThis.dispatchEvent(new Event(F))},Y=v=>{const e=U(18),{active:f,index:o,item:n,onActivate:h,onSelect:b}=v;let g;e[0]!==n||e[1]!==b?(g=()=>{b(n)},e[0]=n,e[1]=b,e[2]=g):g=e[2];const c=g;let x;e[3]!==o||e[4]!==h?(x=()=>{h(o)},e[3]=o,e[4]=h,e[5]=x):x=e[5];const d=x,m=f?"bg-accent text-accent-foreground":"text-foreground";let u;e[6]!==m?(u=J("flex w-full items-center justify-between gap-3 rounded-md px-3 py-2 text-start text-sm outline-none transition-colors hover:bg-accent hover:text-accent-foreground",m),e[6]=m,e[7]=u):u=e[7];let s;e[8]!==n.label?(s=r("span",{children:n.label}),e[8]=n.label,e[9]=s):s=e[9];let i;e[10]!==n.group?(i=r("span",{className:"text-xs text-muted-foreground",children:n.group}),e[10]=n.group,e[11]=i):i=e[11];let p;return e[12]!==c||e[13]!==d||e[14]!==u||e[15]!==s||e[16]!==i?(p=r("li",{children:A("button",{className:u,onClick:c,onMouseEnter:d,type:"button",children:[s,i]})}),e[12]=c,e[13]=d,e[14]=u,e[15]=s,e[16]=i,e[17]=p):p=e[17],p},Z=(v,e)=>{const f=e.trim().toLowerCase();return f===""?v:v.filter(o=>o.label.toLowerCase().includes(f)||o.group.toLowerCase().includes(f))},de=v=>{const e=U(40),{items:f}=v,o=W(),n=H(),{palette:h}=G(),[b,g]=B(!1),[c,x]=B(""),[d,m]=B(0),u=Q(null);let s,i;e[0]!==h?(s=()=>{const t=S=>{if(!(S.metaKey||S.ctrlKey)||S.key.toLowerCase()!==h)return;const{target:_}=S;_ instanceof HTMLElement&&(_.isContentEditable||["INPUT","SELECT","TEXTAREA"].includes(_.tagName))||(S.preventDefault(),g(!0))},l=()=>{g(!0)};return globalThis.addEventListener("keydown",t),globalThis.addEventListener(F,l),()=>{globalThis.removeEventListener("keydown",t),globalThis.removeEventListener(F,l)}},i=[h],e[0]=h,e[1]=s,e[2]=i):(s=e[1],i=e[2]),V(s,i);let p;e[3]!==f||e[4]!==c?(p=Z(f,c),e[3]=f,e[4]=c,e[5]=p):p=e[5];const a=p;let I;e[6]===Symbol.for("react.memo_cache_sentinel")?(I=t=>{g(t),t||(x(""),m(0))},e[6]=I):I=e[6];const M=I;let K;e[7]!==n?(K=t=>{if(M(!1),t.run!==void 0){t.run();return}t.to!==void 0&&X(n({to:t.to}))},e[7]=n,e[8]=K):K=e[8];const w=K;let P;e[9]===Symbol.for("react.memo_cache_sentinel")?(P=t=>{x(t.target.value),m(0)},e[9]=P):P=e[9];const q=P;let z;e[10]!==d||e[11]!==a||e[12]!==w?(z=t=>{e:switch(t.key){case"ArrowDown":{t.preventDefault(),m(l=>a.length===0?0:(l+1)%a.length);break e}case"ArrowUp":{t.preventDefault(),m(l=>a.length===0?0:(l-1+a.length)%a.length);break e}case"Enter":{t.preventDefault();const l=a[d];l!==void 0&&w(l);break e}}},e[10]=d,e[11]=a,e[12]=w,e[13]=z):z=e[13];const j=z;let R;e[14]===Symbol.for("react.memo_cache_sentinel")?(R=r(D.Backdrop,{className:"fixed inset-0 z-50 bg-black/40 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0"}),e[14]=R):R=e[14];let y;e[15]!==o?(y=o("Command palette"),e[15]=o,e[16]=y):y=e[16];let E;e[17]!==y?(E=r(D.Title,{className:"sr-only",children:y}),e[17]=y,e[18]=E):E=e[18];let O;e[19]===Symbol.for("react.memo_cache_sentinel")?(O=A("svg",{"aria-hidden":"true",className:"size-4 text-muted-foreground",fill:"none",stroke:"currentColor",strokeWidth:1.8,viewBox:"0 0 24 24",children:[r("circle",{cx:"11",cy:"11",r:"7"}),r("path",{d:"m21 21-4.3-4.3",strokeLinecap:"round"})]}),e[19]=O):O=e[19];let N;e[20]!==o?(N=o("Search…"),e[20]=o,e[21]=N):N=e[21];let C;e[22]!==j||e[23]!==c||e[24]!==N?(C=A("div",{className:"flex items-center gap-2 border-b border-border px-3",children:[O,r("input",{className:"h-11 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground","data-testid":"dash-command-input",onChange:q,onKeyDown:j,placeholder:N,ref:u,type:"text",value:c})]}),e[22]=j,e[23]=c,e[24]=N,e[25]=C):C=e[25];let T;e[26]!==d||e[27]!==a||e[28]!==w||e[29]!==o?(T=a.length===0?r("li",{className:"px-3 py-6 text-center text-sm text-muted-foreground",children:o("No results.")}):a.map((t,l)=>r(Y,{active:l===d,index:l,item:t,onActivate:m,onSelect:w},t.to??`${t.group}:${t.label}`)),e[26]=d,e[27]=a,e[28]=w,e[29]=o,e[30]=T):T=e[30];let k;e[31]!==T?(k=r("ul",{className:"max-h-80 overflow-y-auto p-1.5","data-testid":"dash-command-list",children:T}),e[31]=T,e[32]=k):k=e[32];let L;e[33]!==E||e[34]!==C||e[35]!==k?(L=A(D.Portal,{children:[R,A(D.Popup,{className:"fixed start-1/2 top-24 z-50 w-[36rem] max-w-[90vw] -translate-x-1/2 overflow-hidden rounded-lg border border-border bg-popover text-popover-foreground shadow-lg outline-none data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95","data-testid":"dash-command-palette",initialFocus:u,children:[E,C,k]})]}),e[33]=E,e[34]=C,e[35]=k,e[36]=L):L=e[36];let $;return e[37]!==b||e[38]!==L?($=r(D.Root,{onOpenChange:M,open:b,children:L}),e[37]=b,e[38]=L,e[39]=$):$=e[39],$};export{de as CommandPalette,ce as openCommandPalette};
@@ -0,0 +1,4 @@
1
+ import{c as B}from"react/compiler-runtime";import{useLunora as at}from"@lunora/react";import{useState as D,useEffect as Be,useMemo as Tt,useRef as Ge,useCallback as lt}from"react";import{ShardInput as Bn}from"./ShardInput-C6mjgAh4.mjs";import{u as Xe}from"./use-admin-query-CR9mHt0P.mjs";import{ADMIN_FUNCTIONS as pe}from"./ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{b as Zt}from"./browser-storage-BH1MxLZs.mjs";import{f as Ne,i as Oe,j as en,b as Vt,c as Ee,d as Te,m as jn,h as zn}from"./internal-CyDwqA67.mjs";import{m as qn,c as tn,d as vt,a as Kn,u as wt,b as Gn,T as Jn,D as Wn}from"./table-list-sidebar-D30qERKx.mjs";import{u as Hn}from"./use-sql-assistant-D4XQ0v0R.mjs";import{d as Rt,i as nn,e as on,a as Un}from"./wire-codec-Bk4XZGE4.mjs";import{B as yt}from"./button-q0UYSmrn.mjs";import{I as Qn}from"./input-CXhxesPC.mjs";import{L as Bt}from"./label-DKFzyHq6.mjs";import{M as it}from"./modal-shell-CDztwLnv.mjs";import{useT as xe}from"./DEFAULT_LOCALE-A1Yg5ORA.mjs";import{jsx as d,jsxs as E,Fragment as Ze}from"react/jsx-runtime";import{ConfirmButton as jt}from"./ConfirmButton-DU4p72Er.mjs";import{E as Yn}from"./empty-state-D7jEML_T.mjs";import{C as Et,a as De}from"./control-button-BOZ5K-FC.mjs";import{tableFeatures as Xn,sortFn_text as Zn,sortFn_datetime as eo,sortFn_basic as to,sortFn_alphanumeric as no,rowSortingFeature as oo,rowSelectionFeature as so,columnVisibilityFeature as lo,columnSizingFeature as ro,columnResizingFeature as ao,columnOrderingFeature as io,createSortedRowModel as co,useTable as uo,flexRender as fo}from"@tanstack/react-table";import{useVirtualizer as mo}from"@tanstack/react-virtual";import{C as $t}from"./checkbox-CnS9cyCz.mjs";import{c as rt}from"./utils-bhneXptQ.mjs";import{f as go}from"./virtual-rect-D_j7aLxX.mjs";import{C as Ct,G as po,T as bo}from"./data-grid-BPu1a997.mjs";import{DataFilters as ho,toFilterClauses as Fe}from"./DataFilters-Cocu-WWE.mjs";import{G as xo,C as vo}from"./grid-features-ByxOklon.mjs";import{G as wo}from"./grid-pagination-DgzyzfBh.mjs";import zt from"./useDebounced-DVeQ5-oW.mjs";import{r as yo,l as Co}from"./shard-history-CaO3C4KQ.mjs";const No=s=>({tables:Object.entries(s).map(([e,n])=>({fields:n.map(o=>o.name),indexes:[],name:e,relations:n.filter(o=>o.ref!==void 0).map(o=>({field:o.name,kind:"one",name:o.name,onDelete:o.onDelete,references:o.ref,table:e}))}))}),So=s=>{const e=new Map,n=new Set;for(const o of s.tables)for(const t of o.relations){if(t.kind!=="one"||t.onDelete==="set null")continue;const c=t.references,l=`${c}\0${o.name}\0${t.field}`;if(n.has(l))continue;n.add(l);const r=e.get(c)??[];r.push({...t,table:o.name}),e.set(c,r)}return e},ko=(s,e)=>{const n=[],o=[s];for(;o.length>0;){const t=o.shift();if(t===void 0)break;e(t)&&n.push(t);for(const c of t.children)o.push(c)}return n},qt=(s,e)=>{const n=[];for(const[o,t]of Object.entries(e))for(const c of t)c.ref===s&&n.push({column:c.name,table:o});return n.sort((o,t)=>o.table.localeCompare(t.table)||o.column.localeCompare(t.column)),n},Dt=s=>`${s.table}.${s.column}`,To=s=>{const e=B(111),{columns:n,onApply:o,onClose:t,shardKey:c,table:l,total:r,uniqueColumns:a}=s,i=xe(),[m,f]=D(n[0]??""),[p,b]=D("");let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u=ee=>{f(ee.target.value)},e[0]=u):u=e[0];const g=u;let h;e[1]===Symbol.for("react.memo_cache_sentinel")?(h=ee=>{b(ee.target.value)},e[1]=h):h=e[1];const x=h;let v;e[2]!==p?(v=p.trim(),e[2]=p,e[3]=v):v=e[3];const y=v==="";let C,N;if(e[4]!==y||e[5]!==i||e[6]!==p){if(!y)try{N=Rt(JSON.parse(p))}catch(ee){C=i("Invalid JSON: {message}",{message:ee.message})}e[4]=y,e[5]=i,e[6]=p,e[7]=C,e[8]=N}else C=e[7],N=e[8];let k;e[9]!==m||e[10]!==r||e[11]!==a?(k=a.has(m)&&r>1,e[9]=m,e[10]=r,e[11]=a,e[12]=k):k=e[12];const S=k,w=m!==""&&!y&&C===void 0&&!S;let T;e[13]!==w||e[14]!==m||e[15]!==o||e[16]!==t||e[17]!==N?(T=()=>{w&&(o({[m]:N}),t())},e[13]=w,e[14]=m,e[15]=o,e[16]=t,e[17]=N,e[18]=T):T=e[18];const I=T;let R;e[19]!==i?(R=i("Set a column on matching rows"),e[19]=i,e[20]=R):R=e[20];let _;e[21]!==i?(_=i("Set a column on matching rows"),e[21]=i,e[22]=_):_=e[22];let $;e[23]!==_?($=d("h3",{className:"text-base text-foreground","data-testid":"bulk-patch-title",children:_}),e[23]=_,e[24]=$):$=e[24];let A;e[25]!==i||e[26]!==l||e[27]!==r?(A=i("Writes {total} rows of {table} through the schema-aware writer — validators and indexes apply, exactly like a mutation.",{table:l,total:r.toString()}),e[25]=i,e[26]=l,e[27]=r,e[28]=A):A=e[28];let M;e[29]!==A?(M=d("p",{className:"text-xs text-muted-foreground","data-testid":"bulk-patch-desc",children:A}),e[29]=A,e[30]=M):M=e[30];let F;e[31]!==c||e[32]!==i?(F=c===""?i("Shard: root"):i("Shard: {shardKey} — rows in other shards are not touched.",{shardKey:c}),e[31]=c,e[32]=i,e[33]=F):F=e[33];let q;e[34]!==F?(q=d("p",{className:"text-xs text-muted-foreground","data-testid":"bulk-patch-shard",children:F}),e[34]=F,e[35]=q):q=e[35];let G;e[36]!==M||e[37]!==q||e[38]!==$?(G=E("div",{className:"flex flex-col gap-0.5",children:[$,M,q]}),e[36]=M,e[37]=q,e[38]=$,e[39]=G):G=e[39];let O;e[40]!==i?(O=i("Close"),e[40]=i,e[41]=O):O=e[41];let V;e[42]!==t||e[43]!==O?(V=d(yt,{"data-testid":"bulk-patch-close",onClick:t,size:"xs",variant:"ghost",children:O}),e[42]=t,e[43]=O,e[44]=V):V=e[44];let J;e[45]!==G||e[46]!==V?(J=E("div",{className:"flex items-start justify-between",children:[G,V]}),e[45]=G,e[46]=V,e[47]=J):J=e[47];let j;e[48]!==i?(j=i("Column"),e[48]=i,e[49]=j):j=e[49];let Y;e[50]!==j?(Y=d(Bt,{htmlFor:"bulk-patch-column",children:j}),e[50]=j,e[51]=Y):Y=e[51];let U;e[52]!==i?(U=i("Column"),e[52]=i,e[53]=U):U=e[53];let H;e[54]!==n?(H=n.map(Eo),e[54]=n,e[55]=H):H=e[55];let te;e[56]!==m||e[57]!==U||e[58]!==H?(te=d("select",{"aria-label":U,className:"h-8 rounded-md border border-input bg-transparent px-2 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 dark:bg-input/30","data-testid":"bulk-patch-column",id:"bulk-patch-column",onChange:g,value:m,children:H}),e[56]=m,e[57]=U,e[58]=H,e[59]=te):te=e[59];let le;e[60]!==i?(le=i("Value"),e[60]=i,e[61]=le):le=e[61];let ue;e[62]!==le?(ue=d(Bt,{htmlFor:"bulk-patch-value",children:le}),e[62]=le,e[63]=ue):ue=e[63];let fe;e[64]!==p?(fe=d(Qn,{className:"flex-1 font-mono","data-testid":"bulk-patch-value",id:"bulk-patch-value",onChange:x,placeholder:"true",value:p}),e[64]=p,e[65]=fe):fe=e[65];let ge;e[66]!==Y||e[67]!==te||e[68]!==ue||e[69]!==fe?(ge=E("div",{className:"flex items-center gap-2",children:[Y,te,ue,fe]}),e[66]=Y,e[67]=te,e[68]=ue,e[69]=fe,e[70]=ge):ge=e[70];let ae;e[71]!==C?(ae=C!==void 0&&d("p",{className:"text-xs text-destructive","data-testid":"bulk-patch-error",role:"alert",children:C}),e[71]=C,e[72]=ae):ae=e[72];let me;e[73]!==m||e[74]!==i||e[75]!==r||e[76]!==S?(me=S&&d("p",{className:"text-xs text-destructive","data-testid":"bulk-patch-unique",role:"alert",children:i("{column} has a unique index — the same value cannot be set on {total} rows.",{column:m,total:r.toString()})}),e[73]=m,e[74]=i,e[75]=r,e[76]=S,e[77]=me):me=e[77];let ie;e[78]!==y||e[79]!==i||e[80]!==S?(ie=y&&!S&&d("p",{className:"text-xs text-muted-foreground","data-testid":"bulk-patch-hint",children:i('Enter a JSON value — for example true, 0, null, or "done".')}),e[78]=y,e[79]=i,e[80]=S,e[81]=ie):ie=e[81];let Q;e[82]!==w||e[83]!==m||e[84]!==p?(Q=w&&d("p",{className:"font-mono text-xs text-muted-foreground","data-testid":"bulk-patch-preview",children:`${m} = ${p.trim()}`}),e[82]=w,e[83]=m,e[84]=p,e[85]=Q):Q=e[85];let be;e[86]!==i?(be=i("Cancel"),e[86]=i,e[87]=be):be=e[87];let Z;e[88]!==t||e[89]!==be?(Z=d(yt,{"data-testid":"bulk-patch-cancel",onClick:t,size:"xs",variant:"outline",children:be}),e[88]=t,e[89]=be,e[90]=Z):Z=e[90];const ve=!w;let ce;e[91]!==i||e[92]!==r?(ce=i("Set on {total} rows",{total:r.toString()}),e[91]=i,e[92]=r,e[93]=ce):ce=e[93];let de;e[94]!==I||e[95]!==ve||e[96]!==ce?(de=d(yt,{"data-testid":"bulk-patch-apply",disabled:ve,onClick:I,size:"xs",children:ce}),e[94]=I,e[95]=ve,e[96]=ce,e[97]=de):de=e[97];let W;e[98]!==Z||e[99]!==de?(W=E("div",{className:"flex justify-end gap-2",children:[Z,de]}),e[98]=Z,e[99]=de,e[100]=W):W=e[100];let K;return e[101]!==t||e[102]!==J||e[103]!==ge||e[104]!==ae||e[105]!==me||e[106]!==ie||e[107]!==Q||e[108]!==W||e[109]!==R?(K=E(it,{label:R,onClose:t,panelTestId:"bulk-patch-panel",testId:"bulk-patch-overlay",variant:"dialog",children:[J,ge,ae,me,ie,Q,W]}),e[101]=t,e[102]=J,e[103]=ge,e[104]=ae,e[105]=me,e[106]=ie,e[107]=Q,e[108]=W,e[109]=R,e[110]=K):K=e[110],K};function Eo(s){return d("option",{value:s,children:s},s)}const Kt=6,ot=100,_o=s=>({paddingLeft:s*16}),Ro=s=>{const e=B(2),{table:n}=s,o=`cascade-restrict-${n}`;let t;return e[0]!==o?(t=d("span",{className:"rounded bg-destructive/10 px-1 text-destructive","data-testid":o,children:"restrict — will block delete"}),e[0]=o,e[1]=t):t=e[1],t},$o=s=>{const e=B(2),{table:n}=s,o=`cascade-cascade-${n}`;let t;return e[0]!==o?(t=d("span",{className:"rounded bg-warning/10 px-1 text-warning","data-testid":o,children:"cascade"}),e[0]=o,e[1]=t):t=e[1],t},Do=s=>{const e=B(2),{table:n}=s,o=`cascade-undeclared-${n}`;let t;return e[0]!==o?(t=d("span",{className:"rounded bg-muted px-1 text-muted-foreground","data-testid":o,children:"references — no delete action declared"}),e[0]=o,e[1]=t):t=e[1],t},Po=s=>s.relation===void 0||s.relation.onDelete==="cascade"?d($o,{table:s.table}):s.isRestrict?d(Ro,{table:s.table}):d(Do,{table:s.table}),sn=s=>{const e=B(35),{depth:n,node:o}=s,t=`cascade-row-${o.table}`;let c;e[0]!==n?(c=_o(n),e[0]=n,e[1]=c):c=e[1];let l;e[2]!==n?(l=n>0&&d("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"└"}),e[2]=n,e[3]=l):l=e[3];let r;e[4]!==o.table?(r=d("span",{className:"font-medium text-foreground",children:o.table}),e[4]=o.table,e[5]=r):r=e[5];let a;e[6]!==o.relation||e[7]!==o.table?(a=o.relation!==void 0&&E("span",{className:"text-muted-foreground","data-testid":`cascade-col-${o.table}-${o.relation.field}`,children:["via ",o.relation.field]}),e[6]=o.relation,e[7]=o.table,e[8]=a):a=e[8];let i;e[9]!==o.rowCount?(i=o.rowCount.toString(),e[9]=o.rowCount,e[10]=i):i=e[10];let m;e[11]!==i?(m=E("span",{className:"text-muted-foreground",children:["(",i," rows)"]}),e[11]=i,e[12]=m):m=e[12];let f;e[13]!==o?(f=Po(o),e[13]=o,e[14]=f):f=e[14];let p;e[15]!==o.capNote||e[16]!==o.table?(p=o.capNote!==void 0&&E("span",{className:"italic text-muted-foreground","data-testid":`cascade-cap-${o.table}`,children:["(",o.capNote,")"]}),e[15]=o.capNote,e[16]=o.table,e[17]=p):p=e[17];let b;e[18]!==t||e[19]!==c||e[20]!==l||e[21]!==r||e[22]!==a||e[23]!==m||e[24]!==f||e[25]!==p?(b=E("li",{className:"flex flex-wrap items-center gap-1.5 py-1 font-mono text-xs","data-testid":t,style:c,children:[l,r,a,m,f,p]}),e[18]=t,e[19]=c,e[20]=l,e[21]=r,e[22]=a,e[23]=m,e[24]=f,e[25]=p,e[26]=b):b=e[26];let u;if(e[27]!==n||e[28]!==o.children){let h;e[30]!==n?(h=(x,v)=>d(sn,{depth:n+1,node:x},`${x.table}-${x.relation?.field??"root"}-${v.toString()}`),e[30]=n,e[31]=h):h=e[31],u=o.children.map(h),e[27]=n,e[28]=o.children,e[29]=u}else u=e[29];let g;return e[32]!==b||e[33]!==u?(g=E(Ze,{children:[b,u]}),e[32]=b,e[33]=u,e[34]=g):g=e[34],g},Ao=s=>{const e=s._id??s.id??s.__id__??"";return typeof e=="string"?e:typeof e=="number"?e.toString():""},Io=async(s,e,n,o)=>{try{const t=await o(s,e,n),c=t.rows.flatMap(a=>Ao(a)||[]).slice(0,ot),l=t.total??0;return{capNote:l>ot?`showing first ${ot.toString()} of ${l.toString()}`:void 0,rowCount:l,rowIds:c}}catch{return{capNote:"count unavailable",rowCount:0,rowIds:[]}}},ln=async(s,e,n,o,t,c,l)=>{const{capNote:r,rowCount:a,rowIds:i}=n===void 0?{capNote:void 0,rowCount:1,rowIds:[e]}:await Io(s,n.field,e,l),m=n?.onDelete==="restrict",f=[],p=`${s}:${e}`,b=c>=Kt;if(!t.has(p)&&!b){t.add(p);const g=o.get(s)??[];for(const h of g)for(const x of i.slice(0,10)){const v=await ln(h.table,x,h,o,t,c+1,l);(v.rowCount>0||c===0)&&f.push(v)}t.delete(p)}let u=r;if(b){const g=`depth capped at ${Kt.toString()}`;u=r===void 0?g:`${r}; ${g}`}return{capNote:u,children:f,isRestrict:m,relation:n,rowCount:a,rowIds:i,table:s}},Fo=({onClose:s,onConfirm:e,readPage:n,rowId:o,schema:t,table:c})=>{const l=xe(),[r,a]=D(!0),[i,m]=D(null),[f,p]=D(null);Be(()=>{let g=!1;return Ne((async()=>{try{a(!0),p(null);const x=So(t);if(!((x.get(c)??[]).length>0)){g||(m({capNote:void 0,children:[],isRestrict:!1,relation:void 0,rowCount:1,rowIds:[o],table:c}),a(!1));return}const y=await ln(c,o,void 0,x,new Set,0,n);g||(m(y),a(!1))}catch(x){g||(p(x.message),a(!1))}})()),()=>{g=!0}},[o,c]);const b=i!==null&&ko(i,g=>g.isRestrict).length>0,u=()=>{e(),s()};return E(it,{label:"Cascade impact preview",onClose:s,panelTestId:"cascade-panel",testId:"cascade-overlay",variant:"dialog",children:[E("div",{className:"flex items-start justify-between",children:[E("div",{className:"flex flex-col gap-0.5",children:[d("h3",{className:"text-base text-foreground","data-testid":"cascade-title",children:l("Cascade impact")}),d("p",{className:"text-xs text-muted-foreground","data-testid":"cascade-desc",children:l("Delete preview — rows that would cascade or be blocked")})]}),d("button",{className:"text-xs text-muted-foreground hover:text-foreground","data-testid":"cascade-close",onClick:s,type:"button",children:l("Close")})]}),r&&d("p",{className:"text-xs text-muted-foreground","data-testid":"cascade-loading",children:l("Loading…")}),f!==null&&d("p",{className:"text-xs text-destructive","data-testid":"cascade-error",role:"alert",children:f}),!r&&i!==null&&d("ul",{className:"flex flex-col","data-testid":"cascade-tree",children:d(sn,{depth:0,node:i})}),!r&&i!==null&&i.children.length===0&&d("p",{className:"text-xs text-muted-foreground","data-testid":"cascade-no-impact",children:l("No related rows found.")}),b&&d("p",{className:"text-sm font-medium text-destructive","data-testid":"cascade-blocker-warning",role:"alert",children:l("Restrict relations will block this delete.")}),E("div",{className:"flex justify-end gap-2",children:[d("button",{className:"rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"cascade-cancel",onClick:s,type:"button",children:l("Cancel")}),d("button",{className:"rounded-md bg-destructive px-3 py-1.5 text-xs font-medium text-destructive-foreground outline-none transition-colors hover:bg-destructive/90 focus-visible:bg-destructive/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"cascade-confirm",disabled:r,onClick:u,type:"button",children:l("Delete")})]})]})},Oo=(s,e,n,o,t=300)=>{if(o<=0)return{ids:new Set(s.map(f=>f.id)),leadPx:0,tailPx:0};const c=n-t,l=n+o+t,r=new Set;let a=0,i=0,m=0;for(const f of s){const p=f.getSize(),b=e.has(f.id),u=a+p>c&&a<l;b||u?r.add(f.id):a<c?i+=p:m+=p,a+=p}return{ids:r,leadPx:i,tailPx:m}},Mo=(s,e)=>{const n=new Map;let o=0;for(const t of s)e.has(t.id)&&(n.set(t.id,o),o+=t.getSize());return n},Lo=Xn({columnOrderingFeature:io,columnResizingFeature:ao,columnSizingFeature:ro,columnVisibilityFeature:lo,rowSelectionFeature:so,rowSortingFeature:oo,sortedRowModel:co(),sortFns:{alphanumeric:no,basic:to,datetime:eo,text:Zn}}),Vo=()=>{const s=B(12);let e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e={},s[0]=e):e=s[0];const[n,o]=D(e);let t;s[1]===Symbol.for("react.memo_cache_sentinel")?(t=(g,h,x)=>{o(v=>({...v,[g]:{...v[g],[h]:x}}))},s[1]=t):t=s[1];const c=t;let l;s[2]===Symbol.for("react.memo_cache_sentinel")?(l=()=>{o({})},s[2]=l):l=s[2];const r=l;let a;s[3]===Symbol.for("react.memo_cache_sentinel")?(a=(g,h)=>{o(x=>{const v=x[g];if(v===void 0)return x;const y=Object.fromEntries(Object.entries(v).filter(C=>{const[N,k]=C;return!(N in h)||!Object.is(k,h[N])}));return Object.keys(y).length===0?Object.fromEntries(Object.entries(x).filter(C=>{const[N]=C;return N!==g})):{...x,[g]:y}})},s[3]=a):a=s[3];const i=a;let m;s[4]!==n?(m=(g,h)=>{const x=n[g];return x!==void 0&&h in x?{value:x[h]}:void 0},s[4]=n,s[5]=m):m=s[5];const f=m;let p;s[6]!==n?(p=Object.values(n).reduce(jo,0),s[6]=n,s[7]=p):p=s[7];const b=p;let u;return s[8]!==b||s[9]!==n||s[10]!==f?(u={clear:r,count:b,drop:i,stage:c,staged:n,stagedValue:f},s[8]=b,s[9]=n,s[10]=f,s[11]=u):u=s[11],u},rn=(s,e)=>{if(typeof e=="number"){const n=Number(s);return s.trim()===""||Number.isNaN(n)?s:n}if(typeof e=="boolean"){if(s==="true")return!0;if(s==="false")return!1}return s},Bo=s=>{const e=B(29),{changes:n,committing:o,onCommit:t,onDiscard:c}=s,l=xe();let r;e[0]!==n.length||e[1]!==l?(r=l("{count} pending changes",{count:n.length}),e[0]=n.length,e[1]=l,e[2]=r):r=e[2];let a;e[3]!==r?(a=d("span",{className:"font-mono text-[11px] tracking-wide uppercase text-warning","data-testid":"db-staged-count",children:r}),e[3]=r,e[4]=a):a=e[4];let i;e[5]!==o||e[6]!==l?(i=l(o?"Committing…":"Commit"),e[5]=o,e[6]=l,e[7]=i):i=e[7];let m;e[8]!==o||e[9]!==t||e[10]!==i?(m=d("button",{className:"ms-auto rounded-md bg-primary px-2.5 py-1 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"db-staged-commit",disabled:o,onClick:t,type:"button",children:i}),e[8]=o,e[9]=t,e[10]=i,e[11]=m):m=e[11];let f;e[12]!==l?(f=l("Discard"),e[12]=l,e[13]=f):f=e[13];let p;e[14]!==o||e[15]!==c||e[16]!==f?(p=d("button",{className:"rounded-md border border-border px-2.5 py-1 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"db-staged-discard",disabled:o,onClick:c,type:"button",children:f}),e[14]=o,e[15]=c,e[16]=f,e[17]=p):p=e[17];let b;e[18]!==a||e[19]!==m||e[20]!==p?(b=E("div",{className:"flex flex-wrap items-center gap-2",children:[a,m,p]}),e[18]=a,e[19]=m,e[20]=p,e[21]=b):b=e[21];let u;e[22]!==n?(u=n.map(zo),e[22]=n,e[23]=u):u=e[23];let g;e[24]!==u?(g=d("ul",{className:"flex flex-col gap-1","data-testid":"db-staged-list",children:u}),e[24]=u,e[25]=g):g=e[25];let h;return e[26]!==b||e[27]!==g?(h=E("div",{className:"flex flex-col gap-2 border border-warning/40 bg-warning/5 p-3","data-testid":"db-staged",children:[b,g]}),e[26]=b,e[27]=g,e[28]=h):h=e[28],h};function jo(s,e){return s+Object.keys(e).length}function zo(s){return E("li",{className:"flex flex-wrap items-center gap-2 font-mono text-xs",children:[E("span",{className:"text-muted-foreground",children:[s.rowId,".",s.column]}),d("span",{className:"text-destructive line-through",children:Oe(s.oldValue)}),d("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"→"}),d("span",{className:"text-foreground",children:Oe(s.newValue)})]},`${s.rowId}:${s.column}`)}const Gt=400,qo=36,Ko={flex:"1 1 0%",minHeight:0,overflow:"auto",position:"relative"},Go={width:"100%"},Jo=/\n$/u,Wo={alignItems:"center",display:"flex",left:0,position:"absolute",top:0,width:"100%"},Ho={display:"flex",width:"100%"},Jt={flex:"0 0 8.5rem",padding:"0.375rem 0.75rem"},Uo="2.5rem",an={alignItems:"center",display:"flex",flex:"0 0 2.5rem",justifyContent:"center",left:0,padding:"0.375rem 0",position:"sticky",zIndex:2},Pt=s=>({flex:"0 0 auto",overflow:"hidden",padding:"0.375rem 0.75rem",position:"relative",textOverflow:"ellipsis",whiteSpace:"nowrap",width:`${s.toString()}px`}),cn=(s,e)=>({...Pt(s),left:`calc(${Uo} + ${e.toString()}px)`,position:"sticky",zIndex:2}),Nt="rounded-md px-2 py-0.5 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50",Qo=(s,e,n)=>e.enabled&&e.columns.has(n)?void 0:s,_t="__back__:",Yo=s=>`${_t}${s.table}.${s.column}`,Xo=s=>{const e=B(3),{counts:n,rowId:o}=s;if(n===void 0){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=d("span",{className:"text-muted-foreground/50",children:"—"}),e[0]=l):l=e[0],l}const t=n[o]??0;let c;return e[1]!==t?(c=d("span",{className:"tabular-nums",children:t}),e[1]=t,e[2]=c):c=e[2],c},Pe=s=>{for(const e of["id","__id__","_id"]){const n=s[e];if(typeof n=="string"||typeof n=="number")return String(n)}return null},Zo=(s,e)=>{if(e.enumValues!==void 0&&e.enumValues.length>0)return e.enumValues.includes(s)||s===""&&e.nullable===!0?{value:s===""?null:s}:void 0;if(e.type==="boolean")return s==="true"||s==="false"?{value:s==="true"}:void 0;if(e.type==="number"){const n=Number(s);return s.trim()===""||!Number.isFinite(n)?void 0:{value:n}}return{value:s}},es=(s,e,n)=>{if(n!==void 0&&n.type!=="any")return Zo(s,n);const o=rn(s,e);return typeof e=="number"&&typeof o!="number"?void 0:{value:o}},ts=({anchor:s,columnIds:e,columnMeta:n,editableColumn:o,rows:t,text:c})=>{const l=c.replaceAll(`\r
2
+ `,`
3
+ `).replace(Jo,"").split(`
4
+ `),r=[];let a=0;for(const[i,m]of l.entries()){const f=t[s.row+i],p=f===void 0?null:Pe(f),b=m.split(" ");if(f===void 0||p===null){a+=b.length;continue}for(const[u,g]of b.entries()){const h=e[s.col+u],x=h===void 0||!o(h)?void 0:es(g,f[h],n?.[h]);h===void 0||x===void 0?a+=1:r.push({column:h,rowId:p,value:x.value})}}return{edits:r,skipped:a}},dn=(s,e)=>Pe(s)??`row-${e.toString()}`,ns=8,os=s=>{const e=B(17),{anchor:n,mask:o,state:t}=s,c=xe();let l;e[0]!==n.left||e[1]!==n.top?(l={left:n.left,position:"fixed",top:n.top,zIndex:50},e[0]=n.left,e[1]=n.top,e[2]=l):l=e[2];const r=l;let a;if(t==="loading"){let m;e[3]!==c?(m=c("Loading…"),e[3]=c,e[4]=m):m=e[4];let f;e[5]!==m?(f=d("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:m}),e[5]=m,e[6]=f):f=e[6],a=f}else if(t.row===null){let m;e[7]!==c?(m=c("No matching row."),e[7]=c,e[8]=m):m=e[8];let f;e[9]!==m?(f=d("p",{className:"px-3 py-2 text-xs text-muted-foreground",children:m}),e[9]=m,e[10]=f):f=e[10],a=f}else{let m;if(e[11]!==o||e[12]!==t.row){const f=Object.entries(tn(t.row,o)).slice(0,ns);m=d("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 px-3 py-2",children:f.map(ps)}),e[11]=o,e[12]=t.row,e[13]=m}else m=e[13];a=m}let i;return e[14]!==a||e[15]!==r?(i=d("div",{className:"pointer-events-none w-72 overflow-hidden rounded-md border border-border bg-popover text-popover-foreground","data-testid":"db-ref-preview",role:"tooltip",style:r,children:a}),e[14]=a,e[15]=r,e[16]=i):i=e[16],i},ss=s=>{const e=B(24),{column:n,id:o,maskViewFor:t,onNavigate:c,onPreview:l,target:r}=s,[a,i]=D(null),[m,f]=D("idle");let p;e[0]!==o||e[1]!==c||e[2]!==r?(p=()=>{c(r,o)},e[0]=o,e[1]=c,e[2]=r,e[3]=p):p=e[3];const b=p;let u;e[4]!==o||e[5]!==l||e[6]!==m||e[7]!==r?(u=S=>{const w=S.currentTarget.getBoundingClientRect();if(i({left:w.left,top:w.bottom+4}),m!=="idle")return;f("loading"),Ne((async()=>{try{f({row:await l(r,o)})}catch{f({row:null})}})())},e[4]=o,e[5]=l,e[6]=m,e[7]=r,e[8]=u):u=e[8];const g=u;let h;e[9]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{i(null)},e[9]=h):h=e[9];const x=h,v=`db-ref-${n}`,y=`Open ${r} ${o}`;let C;e[10]!==o||e[11]!==b||e[12]!==g||e[13]!==v||e[14]!==y?(C=E("button",{"data-testid":v,onBlur:x,onClick:b,onFocus:g,onMouseEnter:g,onMouseLeave:x,title:y,type:"button",children:[o," ↗"]}),e[10]=o,e[11]=b,e[12]=g,e[13]=v,e[14]=y,e[15]=C):C=e[15];let N;e[16]!==a||e[17]!==t||e[18]!==m||e[19]!==r?(N=a!==null&&m!=="idle"&&d(os,{anchor:a,mask:t(r,m==="loading"||m.row===null?[]:Object.keys(m.row)),state:m}),e[16]=a,e[17]=t,e[18]=m,e[19]=r,e[20]=N):N=e[20];let k;return e[21]!==C||e[22]!==N?(k=E(Ze,{children:[C,N]}),e[21]=C,e[22]=N,e[23]=k):k=e[23],k},ls=s=>s==="asc"?" ▲":s==="desc"?" ▼":"",rs="absolute end-1 top-1/2 hidden -translate-y-1/2 items-center justify-center rounded text-muted-foreground outline-none group-hover/cell:flex hover:text-foreground focus-visible:flex",Wt=s=>{const e=B(8),{column:n,onExpand:o,value:t}=s;let c;e[0]!==n||e[1]!==o||e[2]!==t?(c=()=>{o(n,t)},e[0]=n,e[1]=o,e[2]=t,e[3]=c):c=e[3];const l=c,r=`db-expand-${n}`;let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=d("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:d("path",{d:"M9 21H5a2 2 0 0 1-2-2v-4m18 0v4a2 2 0 0 1-2 2h-4M3 9V5a2 2 0 0 1 2-2h4m6 0h4a2 2 0 0 1 2 2v4"})}),e[4]=a):a=e[4];let i;return e[5]!==l||e[6]!==r?(i=d("button",{"aria-label":"Expand cell",className:rs,"data-testid":r,onClick:l,type:"button",children:a}),e[5]=l,e[6]=r,e[7]=i):i=e[7],i},as=s=>{const e=B(15),{column:n,initial:o,onCancel:t,onCommit:c,recordId:l}=s,r=Ge(null);let a,i;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{r.current?.select()},i=[],e[0]=a,e[1]=i):(a=e[0],i=e[1]),Be(a,i);let m;e[2]!==t||e[3]!==c?(m=x=>{x.key==="Enter"?(x.preventDefault(),c(x.currentTarget.value)):x.key==="Escape"&&(x.preventDefault(),t())},e[2]=t,e[3]=c,e[4]=m):m=e[4];const f=m;let p;e[5]!==c?(p=x=>{c(x.currentTarget.value)},e[5]=c,e[6]=p):p=e[6];const b=p,u=`db-cell-input-${l}-${n}`;let g;e[7]!==o?(g=Oe(o),e[7]=o,e[8]=g):g=e[8];let h;return e[9]!==n||e[10]!==b||e[11]!==f||e[12]!==u||e[13]!==g?(h=d("input",{"aria-label":n,className:"w-full rounded border border-ring bg-background px-1 py-0.5 font-mono text-xs outline-none","data-testid":u,defaultValue:g,onBlur:b,onKeyDown:f,ref:r}),e[9]=n,e[10]=b,e[11]=f,e[12]=u,e[13]=g,e[14]=h):h=e[14],h},is=s=>{const e=B(70),{cell:n,edit:o,highlight:t,mask:c,refs:l}=s,r=n.column.id;let a,i,m,f;if(e[0]!==n||e[1]!==r||e[2]!==o||e[3]!==c||e[4]!==l.columns||e[5]!==l.maskViewFor||e[6]!==l.onNavigate||e[7]!==l.onPreview){f=Symbol.for("react.early_return_sentinel");e:{i=n.getValue(),a=Pe(n.row.original);const R=l.columns?.[r];if(c.enabled&&c.columns.has(r)){const _=`db-masked-${r}`,$=d(Ct,{value:qn(i,r,c)});let A;e[12]!==_||e[13]!==$?(A=d("span",{className:"text-muted-foreground italic","data-testid":_,title:"Masked (preview)",children:$}),e[12]=_,e[13]=$,e[14]=A):A=e[14],f=A;break e}if(R!==void 0&&(typeof i=="string"||typeof i=="number")&&String(i)!==""){const _=String(i),$=`${R}:${String(i)}`;let A;e[15]!==r||e[16]!==l.maskViewFor||e[17]!==l.onNavigate||e[18]!==l.onPreview||e[19]!==_||e[20]!==$||e[21]!==R?(A=d(ss,{column:r,id:_,maskViewFor:l.maskViewFor,onNavigate:l.onNavigate,onPreview:l.onPreview,target:R},$),e[15]=r,e[16]=l.maskViewFor,e[17]=l.onNavigate,e[18]=l.onPreview,e[19]=_,e[20]=$,e[21]=R,e[22]=A):A=e[22],f=A;break e}if(a===null){let _;e[23]!==i?(_=d(Ct,{value:i}),e[23]=i,e[24]=_):_=e[24];let $;e[25]!==r||e[26]!==o.onExpandCell||e[27]!==i?($=d(Wt,{column:r,onExpand:o.onExpandCell,value:i}),e[25]=r,e[26]=o.onExpandCell,e[27]=i,e[28]=$):$=e[28];let A;e[29]!==_||e[30]!==$?(A=E(Ze,{children:[_,$]}),e[29]=_,e[30]=$,e[31]=A):A=e[31],f=A;break e}m=o.stagedValue(a,r)}e[0]=n,e[1]=r,e[2]=o,e[3]=c,e[4]=l.columns,e[5]=l.maskViewFor,e[6]=l.onNavigate,e[7]=l.onPreview,e[8]=a,e[9]=i,e[10]=m,e[11]=f}else a=e[8],i=e[9],m=e[10],f=e[11];if(f!==Symbol.for("react.early_return_sentinel"))return f;const p=m,b=p===void 0?i:p.value;let u;e[32]!==r||e[33]!==o?(u=o.editable&&o.editableColumn(r),e[32]=r,e[33]=o,e[34]=u):u=e[34];const g=u;if(o.editingCell!==null&&o.editingCell.rowId===a&&o.editingCell.column===r){let R;e[35]!==r||e[36]!==o||e[37]!==a||e[38]!==i?(R=$=>{o.stage(a,r,rn($,i)),o.cancelEdit()},e[35]=r,e[36]=o,e[37]=a,e[38]=i,e[39]=R):R=e[39];let _;return e[40]!==r||e[41]!==b||e[42]!==o.cancelEdit||e[43]!==a||e[44]!==R?(_=d(as,{column:r,initial:b,onCancel:o.cancelEdit,onCommit:R,recordId:a}),e[40]=r,e[41]=b,e[42]=o.cancelEdit,e[43]=a,e[44]=R,e[45]=_):_=e[45],_}let x;p!==void 0?x="rounded bg-warning/15 px-1":g&&(x="cursor-text");let v;e[46]!==g||e[47]!==r||e[48]!==o||e[49]!==a?(v=g?()=>{o.startEdit(a,r)}:void 0,e[46]=g,e[47]=r,e[48]=o,e[49]=a,e[50]=v):v=e[50];const y=v,C=x,N=`db-cell-${a}-${r}`;let k;e[51]!==r||e[52]!==t||e[53]!==c?(k=Qo(t,c,r),e[51]=r,e[52]=t,e[53]=c,e[54]=k):k=e[54];let S;e[55]!==b||e[56]!==k?(S=d(Ct,{highlight:k,value:b}),e[55]=b,e[56]=k,e[57]=S):S=e[57];let w;e[58]!==x||e[59]!==y||e[60]!==N||e[61]!==S?(w=d("span",{className:C,"data-testid":N,onDoubleClick:y,children:S}),e[58]=x,e[59]=y,e[60]=N,e[61]=S,e[62]=w):w=e[62];let T;e[63]!==r||e[64]!==b||e[65]!==o.onExpandCell?(T=d(Wt,{column:r,onExpand:o.onExpandCell,value:b}),e[63]=r,e[64]=b,e[65]=o.onExpandCell,e[66]=T):T=e[66];let I;return e[67]!==T||e[68]!==w?(I=E(Ze,{children:[w,T]}),e[67]=T,e[68]=w,e[69]=I):I=e[69],I},cs=s=>{s.preventDefault()},Ht={any:"?",array:"[]",bigint:"#",boolean:"01",bytes:"0x",id:"→",number:"#",object:"{}",storage:"◫",string:"T",union:"|"},ds=({declaredType:s,draggedRef:e,header:n,masked:o=!1,onTogglePin:t,pinnedOffset:c,table:l})=>{const r=()=>{e.current=n.column.id},a=()=>{const i=e.current,m=n.column.id;if(e.current=null,i===null||i===m)return;const f=l.atoms.columnOrder.get(),b=(f.length>0?f:l.getAllLeafColumns().map(g=>g.id)).filter(g=>g!==i),u=b.indexOf(m);b.splice(u===-1?b.length:u,0,i),l.setColumnOrder(b)};return E("th",{className:rt("group/head text-start text-xs font-medium text-muted-foreground",c!==void 0&&"border-e border-border bg-muted"),"data-testid":`db-head-${n.column.id}`,draggable:!0,onDragOver:cs,onDragStart:r,onDrop:a,style:c===void 0?Pt(n.getSize()):cn(n.getSize(),c),children:[E("button",{className:"inline-flex max-w-full cursor-grab items-center gap-1 truncate outline-none hover:text-foreground","data-testid":`db-sort-${n.column.id}`,onClick:n.column.getToggleSortingHandler(),type:"button",children:[fo(n.column.columnDef.header,n.getContext()),ls(n.column.getIsSorted())]}),s!==void 0&&Ht[s]!==void 0&&d("span",{className:"ms-1 font-mono text-[0.625rem] text-muted-foreground/70","data-testid":`db-type-${n.column.id}`,title:s,children:Ht[s]}),o&&d("span",{className:"ms-1 inline-flex items-center rounded-sm bg-warning/15 px-1 text-[0.625rem] font-medium uppercase text-warning","data-testid":`db-mask-chip-${n.column.id}`,title:"This column is masked by a mask() policy",children:"masked"}),d("button",{"aria-label":c===void 0?`Pin ${n.column.id}`:`Unpin ${n.column.id}`,"aria-pressed":c!==void 0,className:rt("ms-1 rounded-sm px-1 text-[0.625rem] outline-none transition-opacity hover:bg-accent focus-visible:bg-accent",c===void 0?"opacity-0 group-hover/head:opacity-100 focus-visible:opacity-100":"opacity-100 text-foreground"),"data-testid":`db-pin-${n.column.id}`,onClick:()=>{t(n.column.id)},type:"button",children:"📌"}),d("span",{"aria-hidden":"true",className:"absolute inset-y-0 end-0 w-1 cursor-col-resize touch-none select-none hover:bg-ring/60 data-[resizing=true]:bg-ring","data-resizing":n.column.getIsResizing(),"data-testid":`db-resize-${n.column.id}`,onMouseDown:n.getResizeHandler(),onTouchStart:n.getResizeHandler()})]})},us=s=>{const e=B(13),{table:n}=s,o=xe();let t;e[0]!==n?(t=m=>{n.toggleAllRowsSelected(m)},e[0]=n,e[1]=t):t=e[1];const c=t;let l;e[2]!==o?(l=o("Select all rows"),e[2]=o,e[3]=l):l=e[3];let r;e[4]!==n?(r=n.getIsAllRowsSelected(),e[4]=n,e[5]=r):r=e[5];let a;e[6]!==n?(a=n.getIsSomeRowsSelected()&&!n.getIsAllRowsSelected(),e[6]=n,e[7]=a):a=e[7];let i;return e[8]!==c||e[9]!==l||e[10]!==r||e[11]!==a?(i=d("th",{className:"bg-muted",style:an,children:d($t,{"aria-label":l,checked:r,"data-testid":"db-select-all",indeterminate:a,onCheckedChange:c})}),e[8]=c,e[9]=l,e[10]=r,e[11]=a,e[12]=i):i=e[12],i},fs=s=>{const e=B(17),{row:n}=s,o=xe();let t;e[0]!==n.original?(t=Pe(n.original),e[0]=n.original,e[1]=t):t=e[1];const c=t;let l;e[2]!==n?(l=u=>{n.toggleSelected(u)},e[2]=n,e[3]=l):l=e[3];const r=l;let a;e[4]!==o?(a=o("Select row"),e[4]=o,e[5]=a):a=e[5];let i;e[6]!==n?(i=n.getIsSelected(),e[6]=n,e[7]=i):i=e[7];let m;e[8]!==n.index||e[9]!==n.original?(m=dn(n.original,n.index),e[8]=n.index,e[9]=n.original,e[10]=m):m=e[10];const f=`db-select-${m}`,p=c===null;let b;return e[11]!==r||e[12]!==a||e[13]!==i||e[14]!==f||e[15]!==p?(b=d("td",{className:"bg-background",style:an,children:d($t,{"aria-label":a,checked:i,"data-testid":f,disabled:p,onCheckedChange:r})}),e[11]=r,e[12]=a,e[13]=i,e[14]=f,e[15]=p,e[16]=b):b=e[16],b},ms=s=>{const e=B(91),{columnMeta:n,edit:o,editable:t,mask:c,onDelete:l,onEdit:r,onInspect:a,highlight:i,backRelationCounts:m,onTogglePin:f,pinnedColumns:p,refs:b,tableModel:u}=s,g=xe(),{attachScroll:h,scrollLeft:x,scrollToIndex:v,table:y,tableRows:C,tbodyStyle:N,viewportWidth:k,virtualRows:S}=u,w=Ge(null),[T,I]=D(null);let R;e[0]===Symbol.for("react.memo_cache_sentinel")?(R={columns:"",count:0},e[0]=R):R=e[0];const[_,$]=D(R);let A;e[1]!==y?(A=y.getVisibleLeafColumns(),e[1]=y,e[2]=A):A=e[2];const M=A.length;let F;e[3]!==T||e[4]!==M||e[5]!==o||e[6]!==y||e[7]!==C?(F=ee=>{if(!["ArrowDown","ArrowLeft","ArrowRight","ArrowUp","Enter"].includes(ee.key))return;ee.preventDefault();const X=T??{col:0,row:0};if(ee.key==="Enter"){const we=C[X.row],ye=y.getVisibleLeafColumns()[X.col];if(we!==void 0&&ye!==void 0){const ne=Pe(we.original);ne!==null&&o.editableColumn(ye.id)&&o.startEdit(ne,ye.id)}I(X);return}let{col:he,row:re}=X;e:switch(ee.key){case"ArrowDown":{re=Math.min(re+1,C.length-1);break e}case"ArrowRight":{he=Math.min(he+1,M-1);break e}case"ArrowUp":{re=Math.max(re-1,0);break e}default:he=Math.max(he-1,0)}I({col:he,row:re})},e[3]=T,e[4]=M,e[5]=o,e[6]=y,e[7]=C,e[8]=F):F=e[8];const q=F;let G;e[9]!==T||e[10]!==n||e[11]!==o||e[12]!==y||e[13]!==C?(G=ee=>{const X=o.editable?ee.clipboardData.getData("text/plain"):"";if(X==="")return;ee.preventDefault();const he=y.getVisibleLeafColumns().map(bs),re=ts({anchor:T??{col:0,row:0},columnIds:he,columnMeta:n,editableColumn:o.editableColumn,rows:C.map(hs),text:X});for(const we of re.edits)o.stage(we.rowId,we.column,we.value);$({columns:he.join("\0"),count:re.skipped})},e[9]=T,e[10]=n,e[11]=o,e[12]=y,e[13]=C,e[14]=G):G=e[14];const O=G;let V,J;e[15]!==T||e[16]!==v?(V=()=>{T!==null&&v(T.row)},J=[T,v],e[15]=T,e[16]=v,e[17]=V,e[18]=J):(V=e[17],J=e[18]),Be(V,J);let j,Y,U,H,te,le,ue,fe,ge,ae,me,ie,Q,be,Z,ve;if(e[19]!==T||e[20]!==h||e[21]!==m||e[22]!==n||e[23]!==o||e[24]!==t||e[25]!==i||e[26]!==c||e[27]!==l||e[28]!==r||e[29]!==q||e[30]!==O||e[31]!==a||e[32]!==f||e[33]!==_.columns||e[34]!==_.count||e[35]!==p||e[36]!==b||e[37]!==x||e[38]!==g||e[39]!==y||e[40]!==C||e[41]!==N||e[42]!==k||e[43]!==S){const ee=y.getVisibleLeafColumns().map(xs),X=Oo(ee,p,x,k),he=Mo(y.getVisibleLeafColumns().map(vs),p),re=ne=>{const Me=C[ne.index],{original:Ce}=Me,oe=Pe(Ce),Ae=dn(Ce,ne.index),We={...Wo,height:`${ne.size.toString()}px`,transform:`translateY(${ne.start.toString()}px)`};return E("tr",{className:"border-b border-border text-xs transition-colors hover:bg-muted/50","data-testid":"db-row",style:We,children:[d(fs,{row:Me}),X.leadPx>0&&d("td",{"aria-hidden":"true",style:{flex:`0 0 ${X.leadPx.toString()}px`}}),Me.getVisibleCells().map((ke,ze)=>{if(!X.ids.has(ke.column.id))return null;const je=he.get(ke.column.id),He=T!==null&&T.row===ne.index&&T.col===ze?" ring-1 ring-ring ring-inset":"";return d("td",{className:rt("group/cell truncate font-mono text-muted-foreground",je!==void 0&&"border-e border-border bg-background",He),onPointerDown:()=>{I({col:ze,row:ne.index})},style:je===void 0?Pt(ke.column.getSize()):cn(ke.column.getSize(),je),children:ke.column.id.startsWith(_t)?d(Xo,{counts:m[ke.column.id.slice(_t.length)],rowId:Ae}):d(is,{cell:ke,edit:o,highlight:i,mask:c,refs:b})},ke.id)}),X.tailPx>0&&d("td",{"aria-hidden":"true",style:{flex:`0 0 ${X.tailPx.toString()}px`}}),E("td",{className:"flex items-center gap-1",style:Jt,children:[d("button",{className:Nt,"data-testid":`db-inspect-${Ae}`,onClick:()=>{a(Ce)},type:"button",children:"Details"}),t&&E(Ze,{children:[d("button",{className:Nt,"data-testid":`db-edit-${Ae}`,disabled:oe===null,onClick:()=>{r(oe,Ce)},type:"button",children:"Edit"}),d("button",{className:Nt,"data-testid":`db-delete-${Ae}`,disabled:oe===null,onClick:()=>{l(oe)},type:"button",children:"Delete"})]})]})]},Me.id)};j=po,ie="fill",e[60]!==_.columns||e[61]!==_.count||e[62]!==g||e[63]!==y?(Q=_.count>0&&_.columns===y.getVisibleLeafColumns().map(ws).join("\0")&&d("p",{className:"border-b border-warning/40 bg-warning/5 px-3 py-1.5 text-xs text-warning","data-testid":"db-paste-skipped",children:g("{count} pasted cells were skipped",{count:_.count})}),e[60]=_.columns,e[61]=_.count,e[62]=g,e[63]=y,e[64]=Q):Q=e[64],te="db-scroll",le=q,ue=O,fe=h,ge="grid",ae=Ko,me=0,ve="w-full text-xs",Y="db-rows",U=Go;let we;e[65]!==y?(we=d(us,{table:y}),e[65]=y,e[66]=we):we=e[66];let ye;e[67]===Symbol.for("react.memo_cache_sentinel")?(ye=d("th",{"aria-label":"Row actions",style:Jt}),e[67]=ye):ye=e[67],H=d("thead",{className:"bg-muted/50",children:E("tr",{className:"border-b border-border",style:Ho,children:[we,X.leadPx>0&&d("th",{"aria-hidden":"true",style:{flex:`0 0 ${X.leadPx.toString()}px`}}),y.getFlatHeaders().map(ne=>X.ids.has(ne.column.id)?d(ds,{declaredType:n?.[ne.column.id]?.type,draggedRef:w,header:ne,masked:c.columns.has(ne.column.id),onTogglePin:f,pinnedOffset:he.get(ne.column.id),table:y},ne.id):null),X.tailPx>0&&d("th",{"aria-hidden":"true",style:{flex:`0 0 ${X.tailPx.toString()}px`}}),ye]})}),be=N,Z=S.map(ne=>re(ne)),e[19]=T,e[20]=h,e[21]=m,e[22]=n,e[23]=o,e[24]=t,e[25]=i,e[26]=c,e[27]=l,e[28]=r,e[29]=q,e[30]=O,e[31]=a,e[32]=f,e[33]=_.columns,e[34]=_.count,e[35]=p,e[36]=b,e[37]=x,e[38]=g,e[39]=y,e[40]=C,e[41]=N,e[42]=k,e[43]=S,e[44]=j,e[45]=Y,e[46]=U,e[47]=H,e[48]=te,e[49]=le,e[50]=ue,e[51]=fe,e[52]=ge,e[53]=ae,e[54]=me,e[55]=ie,e[56]=Q,e[57]=be,e[58]=Z,e[59]=ve}else j=e[44],Y=e[45],U=e[46],H=e[47],te=e[48],le=e[49],ue=e[50],fe=e[51],ge=e[52],ae=e[53],me=e[54],ie=e[55],Q=e[56],be=e[57],Z=e[58],ve=e[59];let ce;e[68]!==be||e[69]!==Z?(ce=d("tbody",{style:be,children:Z}),e[68]=be,e[69]=Z,e[70]=ce):ce=e[70];let de;e[71]!==Y||e[72]!==U||e[73]!==H||e[74]!==ce||e[75]!==ve?(de=E("table",{className:ve,"data-testid":Y,style:U,children:[H,ce]}),e[71]=Y,e[72]=U,e[73]=H,e[74]=ce,e[75]=ve,e[76]=de):de=e[76];let W;e[77]!==te||e[78]!==le||e[79]!==ue||e[80]!==fe||e[81]!==ge||e[82]!==ae||e[83]!==me||e[84]!==de?(W=d("div",{"data-testid":te,onKeyDown:le,onPaste:ue,ref:fe,role:ge,style:ae,tabIndex:me,children:de}),e[77]=te,e[78]=le,e[79]=ue,e[80]=fe,e[81]=ge,e[82]=ae,e[83]=me,e[84]=de,e[85]=W):W=e[85];let K;return e[86]!==j||e[87]!==ie||e[88]!==Q||e[89]!==W?(K=E(j,{layout:ie,children:[Q,W]}),e[86]=j,e[87]=ie,e[88]=Q,e[89]=W,e[90]=K):K=e[90],K},gs=(s,e,n,o=[])=>{const t=s?.columns,c=s?.rows,l=s?.refs,r=Tt(()=>{if(t===void 0)return[];const w=t.map(T=>({accessorFn:I=>I[T],header:l?.[T]===void 0?T:`${T} →`,id:T}));for(const T of o)w.push({accessorFn:()=>{},enableSorting:!1,header:`← ${T.table}`,id:Yo(T)});return w},[o,t,l]),a=Tt(()=>c??[],[c]),[i,m]=D({}),[f,p]=D({}),b=uo({columnResizeMode:"onChange",columns:r,data:a,defaultColumn:{minSize:80,size:200},enableColumnResizing:!0,enableRowSelection:w=>Pe(w.original)!==null,features:Lo,getRowId:(w,T)=>Pe(w)??`row-${T.toString()}`,manualSorting:!0,onColumnVisibilityChange:p,onRowSelectionChange:m,onSortingChange:n,state:{columnVisibility:f,rowSelection:i,sorting:e}}),u=b.getRowModel().rows,g=Ge(null),h=mo({count:u.length,estimateSize:()=>qo,getScrollElement:()=>g.current,initialRect:{height:Gt,width:0},observeElementRect:(w,T)=>go(w,T,Gt),overscan:8}),x=lt(w=>{h.scrollToIndex(w)},[h]),[v,y]=D({left:0,width:0}),C=lt(w=>{if(g.current=w,w===null)return;const T=()=>{y(R=>R.left===w.scrollLeft&&R.width===w.clientWidth?R:{left:w.scrollLeft,width:w.clientWidth})};w.addEventListener("scroll",T,{passive:!0});const I=new ResizeObserver(T);return I.observe(w),()=>{w.removeEventListener("scroll",T),I.disconnect(),g.current=null}},[]),N=h.getVirtualItems(),S={display:"block",height:`${h.getTotalSize().toString()}px`,position:"relative"};return{attachScroll:C,scrollLeft:v.left,scrollToIndex:x,table:b,tableRows:u,tbodyStyle:S,viewportWidth:v.width,virtualRows:N}};function ps(s){const[e,n]=s;return E("div",{className:"contents",children:[d("dt",{className:"truncate font-mono text-[11px] text-muted-foreground",children:e}),d("dd",{className:"truncate font-mono text-[11px] text-foreground",title:Oe(n),children:Oe(n)})]},e)}function bs(s){return s.id}function hs(s){return s.original}function xs(s){return{getSize:()=>s.getSize(),id:s.id}}function vs(s){return{getSize:()=>s.getSize(),id:s.id}}function ws(s){return s.id}const ys=s=>{const e=B(22),{onCommit:n}=s,o=xe(),[t,c]=D(""),l=Ge(null);let r,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=()=>{l.current?.focus()},a=[],e[0]=r,e[1]=a):(r=e[0],a=e[1]),Be(r,a);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=y=>{c(y.target.value)},e[2]=i):i=e[2];const m=i;let f;e[3]!==t||e[4]!==n?(f=()=>{const y=t.trim();y!==""&&n(y)},e[3]=t,e[4]=n,e[5]=f):f=e[5];const p=f;let b;e[6]!==o?(b=o("Query name"),e[6]=o,e[7]=b):b=e[7];let u;e[8]!==o?(u=o("Query name"),e[8]=o,e[9]=u):u=e[9];let g;e[10]!==t||e[11]!==b||e[12]!==u?(g=d("input",{"aria-label":b,className:"h-7 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"db-save-query-name",onChange:m,placeholder:u,ref:l,value:t}),e[10]=t,e[11]=b,e[12]=u,e[13]=g):g=e[13];let h;e[14]!==o?(h=o("Save"),e[14]=o,e[15]=h):h=e[15];let x;e[16]!==p||e[17]!==h?(x=d("button",{className:Et,"data-testid":"db-save-query-confirm",onClick:p,type:"button",children:h}),e[16]=p,e[17]=h,e[18]=x):x=e[18];let v;return e[19]!==g||e[20]!==x?(v=E("span",{className:"inline-flex items-center gap-1",children:[g,x]}),e[19]=g,e[20]=x,e[21]=v):v=e[21],v},Cs=s=>{const e=B(27),{onApply:n,onCopyLink:o,onDelete:t,onSave:c,saved:l}=s,r=xe(),[a,i]=D(!1);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{i(!0)},e[0]=m):m=e[0];const f=m;let p;e[1]!==c?(p=S=>{c(S),i(!1)},e[1]=c,e[2]=p):p=e[2];const b=p;let u;e[3]!==n||e[4]!==l?(u=S=>{const w=l[Number(S.currentTarget.dataset.index)];w!==void 0&&n(w)},e[3]=n,e[4]=l,e[5]=u):u=e[5];const g=u;let h;e[6]!==t||e[7]!==l?(h=S=>{const w=l[Number(S.currentTarget.dataset.index)];w!==void 0&&t(w.name)},e[6]=t,e[7]=l,e[8]=h):h=e[8];const x=h;let v;e[9]!==r?(v=r("Copy link"),e[9]=r,e[10]=v):v=e[10];let y;e[11]!==o||e[12]!==v?(y=d("button",{className:Et,"data-testid":"db-copy-link",onClick:o,type:"button",children:v}),e[11]=o,e[12]=v,e[13]=y):y=e[13];let C;e[14]!==b||e[15]!==a||e[16]!==r?(C=a?d(ys,{onCommit:b}):d("button",{className:Et,"data-testid":"db-save-query",onClick:f,type:"button",children:r("Save query")}),e[14]=b,e[15]=a,e[16]=r,e[17]=C):C=e[17];let N;e[18]!==g||e[19]!==x||e[20]!==l||e[21]!==r?(N=l.length>0&&E("div",{className:"flex flex-wrap items-center gap-1","data-testid":"db-saved-queries",children:[d("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:r("Saved")}),l.map((S,w)=>E("span",{className:"inline-flex items-center overflow-hidden rounded-md border border-border",children:[d("button",{className:"px-2 py-0.5 text-xs text-foreground transition-colors hover:bg-accent","data-index":w,"data-testid":`db-saved-query-${S.name}`,onClick:g,type:"button",children:S.name}),d("button",{"aria-label":r("Delete saved query {name}",{name:S.name}),className:"border-l border-border px-1 py-0.5 text-xs text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive","data-index":w,"data-testid":`db-saved-query-delete-${S.name}`,onClick:x,type:"button",children:"✕"})]},S.name))]}),e[18]=g,e[19]=x,e[20]=l,e[21]=r,e[22]=N):N=e[22];let k;return e[23]!==y||e[24]!==C||e[25]!==N?(k=E("div",{className:"flex flex-wrap items-center gap-1.5","data-testid":"db-query-bar",children:[y,C,N]}),e[23]=y,e[24]=C,e[25]=N,e[26]=k):k=e[26],k},Je="w-full rounded-md border border-border bg-background px-2 py-1 font-mono text-xs outline-none focus-visible:border-ring",un=/(?:_creationtime|(?:^|[a-z])(?:time|at))$/iu,Ut=(s,e)=>typeof e=="boolean"?"boolean":typeof e=="number"?un.test(s)?"date":"number":e!==null&&typeof e=="object"?"json":"text",Ns=(s,e,n)=>n===void 0?Ut(s,e):n.enumValues!==void 0&&n.enumValues.length>0?"enum":n.type==="boolean"?"boolean":n.type==="number"?un.test(s)?"date":"number":Ut(s,e),Ss=s=>{try{const e=JSON.parse(s);return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:null}catch{return null}},ks=s=>{const e=new Date(s),n=o=>String(o).padStart(2,"0");return`${e.getFullYear().toString()}-${n(e.getMonth()+1)}-${n(e.getDate())}T${n(e.getHours())}:${n(e.getMinutes())}`},Ke="\0clear",Ts=s=>{const e=B(23),{column:n,nullable:o,onChange:t,value:c}=s,l=xe();let r;e[0]!==n||e[1]!==t?(r=v=>{t(n,v)},e[0]=n,e[1]=t,e[2]=r):r=e[2];const a=r;let i;e[3]!==n||e[4]!==t?(i=v=>{t(n,v.target.value===Ke?null:v.target.value==="true")},e[3]=n,e[4]=t,e[5]=i):i=e[5];const m=i;if(!o&&c!==null){const v=c===!0,y=`db-field-${n}`;let C;return e[6]!==n||e[7]!==a||e[8]!==v||e[9]!==y?(C=d($t,{"aria-label":n,checked:v,"data-testid":y,onCheckedChange:a}),e[6]=n,e[7]=a,e[8]=v,e[9]=y,e[10]=C):C=e[10],C}const f=`db-field-${n}`,p=c===!0||c===!1?String(c):Ke;let b;e[11]!==l?(b=l("(none)"),e[11]=l,e[12]=b):b=e[12];let u;e[13]!==b?(u=d("option",{value:Ke,children:b}),e[13]=b,e[14]=u):u=e[14];let g,h;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=d("option",{value:"true",children:"true"}),h=d("option",{value:"false",children:"false"}),e[15]=g,e[16]=h):(g=e[15],h=e[16]);let x;return e[17]!==n||e[18]!==m||e[19]!==f||e[20]!==p||e[21]!==u?(x=E("select",{"aria-label":n,className:Je,"data-testid":f,onChange:m,value:p,children:[u,g,h]}),e[17]=n,e[18]=m,e[19]=f,e[20]=p,e[21]=u,e[22]=x):x=e[22],x},Es=s=>{const e=B(23),{column:n,nullable:o,onChange:t,options:c,value:l}=s,r=xe(),a=typeof l=="string"?l:null;let i;e[0]!==c||e[1]!==a?(i=a!==null&&!c.includes(a),e[0]=c,e[1]=a,e[2]=i):i=e[2];const m=i;let f;e[3]!==n||e[4]!==t?(f=y=>{t(n,y.target.value===Ke?null:y.target.value)},e[3]=n,e[4]=t,e[5]=f):f=e[5];const p=f,b=`db-field-${n}`,u=a??Ke;let g;e[6]!==o||e[7]!==a||e[8]!==r?(g=(o||a===null)&&d("option",{value:Ke,children:r("(none)")}),e[6]=o,e[7]=a,e[8]=r,e[9]=g):g=e[9];let h;e[10]!==a||e[11]!==m?(h=m&&d("option",{value:a,children:a}),e[10]=a,e[11]=m,e[12]=h):h=e[12];let x;e[13]!==c?(x=c.map(Is),e[13]=c,e[14]=x):x=e[14];let v;return e[15]!==n||e[16]!==p||e[17]!==b||e[18]!==u||e[19]!==g||e[20]!==h||e[21]!==x?(v=E("select",{"aria-label":n,className:Je,"data-testid":b,onChange:p,value:u,children:[g,h,x]}),e[15]=n,e[16]=p,e[17]=b,e[18]=u,e[19]=g,e[20]=h,e[21]=x,e[22]=v):v=e[22],v},_s=s=>{const e=B(8),{column:n,onChange:o,value:t}=s;let c;e[0]!==n||e[1]!==o?(c=m=>{const f=Number(m.target.value);m.target.value!==""&&!Number.isNaN(f)&&o(n,f)},e[0]=n,e[1]=o,e[2]=c):c=e[2];const l=c,r=`db-field-${n}`,a=typeof t=="number"?t:"";let i;return e[3]!==n||e[4]!==l||e[5]!==r||e[6]!==a?(i=d("input",{"aria-label":n,className:Je,"data-testid":r,onChange:l,type:"number",value:a}),e[3]=n,e[4]=l,e[5]=r,e[6]=a,e[7]=i):i=e[7],i},Rs=s=>{const e=B(10),{column:n,onChange:o,value:t}=s;let c;e[0]!==n||e[1]!==o?(c=m=>{const f=new Date(m.target.value).getTime();Number.isNaN(f)||o(n,f)},e[0]=n,e[1]=o,e[2]=c):c=e[2];const l=c,r=`db-field-${n}`;let a;e[3]!==t?(a=typeof t=="number"?ks(t):"",e[3]=t,e[4]=a):a=e[4];let i;return e[5]!==n||e[6]!==l||e[7]!==r||e[8]!==a?(i=d("input",{"aria-label":n,className:Je,"data-testid":r,onChange:l,type:"datetime-local",value:a}),e[5]=n,e[6]=l,e[7]=r,e[8]=a,e[9]=i):i=e[9],i},$s=s=>{const e=B(8),{column:n,onChange:o,value:t}=s;let c;e[0]!==n||e[1]!==o?(c=m=>{o(n,m.target.value)},e[0]=n,e[1]=o,e[2]=c):c=e[2];const l=c,r=`db-field-${n}`,a=typeof t=="string"?t:"";let i;return e[3]!==n||e[4]!==l||e[5]!==r||e[6]!==a?(i=d("input",{"aria-label":n,className:Je,"data-testid":r,onChange:l,type:"text",value:a}),e[3]=n,e[4]=l,e[5]=r,e[6]=a,e[7]=i):i=e[7],i},Ds=s=>{const e=B(20),{column:n,onChange:o,value:t}=s,c=xe();let l;e[0]!==t?(l=()=>JSON.stringify(t,null,2),e[0]=t,e[1]=l):l=e[1];const[r,a]=D(l),[i,m]=D(!1);let f;e[2]!==n||e[3]!==o?(f=y=>{const C=y.target.value;a(C);try{o(n,JSON.parse(C)),m(!1)}catch{m(!0)}},e[2]=n,e[3]=o,e[4]=f):f=e[4];const p=f,b=i&&"border-destructive";let u;e[5]!==b?(u=rt(Je,"min-h-16",b),e[5]=b,e[6]=u):u=e[6];const g=`db-field-${n}`;let h;e[7]!==n||e[8]!==p||e[9]!==u||e[10]!==g||e[11]!==r?(h=d("textarea",{"aria-label":n,className:u,"data-testid":g,onChange:p,value:r}),e[7]=n,e[8]=p,e[9]=u,e[10]=g,e[11]=r,e[12]=h):h=e[12];let x;e[13]!==n||e[14]!==i||e[15]!==c?(x=i&&d("span",{className:"text-xs text-destructive","data-testid":`db-field-error-${n}`,children:c("Invalid JSON")}),e[13]=n,e[14]=i,e[15]=c,e[16]=x):x=e[16];let v;return e[17]!==h||e[18]!==x?(v=E("div",{className:"flex flex-col gap-1",children:[h,x]}),e[17]=h,e[18]=x,e[19]=v):v=e[19],v},Ps=s=>{const e=B(56),{column:n,meta:o,onChange:t,target:c,value:l}=s;let r;e[0]!==n||e[1]!==o||e[2]!==l?(r=Ns(n,l,o),e[0]=n,e[1]=o,e[2]=l,e[3]=r):r=e[3];const a=r,i=`db-field-${n}`;let m;e[4]!==n?(m=d("span",{className:"font-mono",children:n}),e[4]=n,e[5]=m):m=e[5];let f;e[6]!==n||e[7]!==o?(f=o!==void 0&&d("span",{className:"rounded bg-muted px-1 font-mono text-[10px] tracking-wide","data-testid":`db-field-type-${n}`,children:o.type}),e[6]=n,e[7]=o,e[8]=f):f=e[8];let p;e[9]!==c?(p=c!==void 0&&E("span",{className:"rounded bg-muted px-1 font-mono text-[10px] tracking-wide uppercase",children:["→ ",c]}),e[9]=c,e[10]=p):p=e[10];let b;e[11]!==m||e[12]!==f||e[13]!==p?(b=E("span",{className:"flex items-center gap-1.5 font-medium text-muted-foreground",children:[m,f,p]}),e[11]=m,e[12]=f,e[13]=p,e[14]=b):b=e[14];let u;e[15]!==n||e[16]!==a||e[17]!==o?.nullable||e[18]!==t||e[19]!==l?(u=a==="boolean"&&d(Ts,{column:n,nullable:o?.nullable===!0,onChange:t,value:l}),e[15]=n,e[16]=a,e[17]=o?.nullable,e[18]=t,e[19]=l,e[20]=u):u=e[20];let g;e[21]!==n||e[22]!==a||e[23]!==o||e[24]!==t||e[25]!==l?(g=a==="enum"&&o?.enumValues!==void 0&&d(Es,{column:n,nullable:o.nullable===!0,onChange:t,options:o.enumValues,value:l}),e[21]=n,e[22]=a,e[23]=o,e[24]=t,e[25]=l,e[26]=g):g=e[26];let h;e[27]!==n||e[28]!==a||e[29]!==t||e[30]!==l?(h=a==="number"&&d(_s,{column:n,onChange:t,value:l}),e[27]=n,e[28]=a,e[29]=t,e[30]=l,e[31]=h):h=e[31];let x;e[32]!==n||e[33]!==a||e[34]!==t||e[35]!==l?(x=a==="date"&&d(Rs,{column:n,onChange:t,value:l}),e[32]=n,e[33]=a,e[34]=t,e[35]=l,e[36]=x):x=e[36];let v;e[37]!==n||e[38]!==a||e[39]!==t||e[40]!==l?(v=a==="json"&&d(Ds,{column:n,onChange:t,value:l}),e[37]=n,e[38]=a,e[39]=t,e[40]=l,e[41]=v):v=e[41];let y;e[42]!==n||e[43]!==a||e[44]!==t||e[45]!==l?(y=a==="text"&&d($s,{column:n,onChange:t,value:l}),e[42]=n,e[43]=a,e[44]=t,e[45]=l,e[46]=y):y=e[46];let C;return e[47]!==x||e[48]!==v||e[49]!==y||e[50]!==i||e[51]!==b||e[52]!==u||e[53]!==g||e[54]!==h?(C=E("label",{className:"flex flex-col gap-1 text-xs",htmlFor:i,children:[b,u,g,h,x,v,y]}),e[47]=x,e[48]=v,e[49]=y,e[50]=i,e[51]=b,e[52]=u,e[53]=g,e[54]=h,e[55]=C):C=e[55],C},As=s=>{const e=B(49),{columnMeta:n,documentText:o,onCancel:t,onDocumentTextChange:c,onSave:l,refs:r}=s,a=xe();let i;e[0]!==o?(i=Ss(o),e[0]=o,e[1]=i):i=e[1];const m=i,[f,p]=D(!1),b=!f&&m!==null;let u;e[2]!==m||e[3]!==c?(u=(V,J)=>{c(JSON.stringify({...m,[V]:J},null,2))},e[2]=m,e[3]=c,e[4]=u):u=e[4];const g=u;let h;e[5]!==c?(h=V=>{c(V.target.value)},e[5]=c,e[6]=h):h=e[6];const x=h;let v;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{p(!1)},e[7]=v):v=e[7];const y=v;let C;e[8]===Symbol.for("react.memo_cache_sentinel")?(C=()=>{p(!0)},e[8]=C):C=e[8];const N=C,k=m===null;let S;e[9]!==a?(S=a("Form"),e[9]=a,e[10]=S):S=e[10];let w;e[11]!==b||e[12]!==k||e[13]!==S?(w=d("button",{"aria-pressed":b,className:De,"data-testid":"db-editor-form",disabled:k,onClick:y,type:"button",children:S}),e[11]=b,e[12]=k,e[13]=S,e[14]=w):w=e[14];const T=!b;let I;e[15]!==a?(I=a("JSON"),e[15]=a,e[16]=I):I=e[16];let R;e[17]!==I||e[18]!==T?(R=d("button",{"aria-pressed":T,className:De,"data-testid":"db-editor-json",onClick:N,type:"button",children:I}),e[17]=I,e[18]=T,e[19]=R):R=e[19];let _;e[20]!==R||e[21]!==w?(_=E("div",{className:"flex items-center gap-1.5",children:[w,R]}),e[20]=R,e[21]=w,e[22]=_):_=e[22];let $;e[23]!==n||e[24]!==o||e[25]!==m||e[26]!==g||e[27]!==x||e[28]!==r||e[29]!==b||e[30]!==a?($=b?d("div",{className:"flex flex-col gap-3","data-testid":"db-editor-fields",children:Object.entries(m).map(V=>{const[J,j]=V;return d(Ps,{column:J,meta:n?.[J],onChange:g,target:r?.[J],value:j},J)})}):d("textarea",{"aria-label":a("Row document JSON"),className:"min-h-28 w-full rounded-md border border-border bg-background px-2 py-1.5 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"db-editor-doc",onChange:x,value:o}),e[23]=n,e[24]=o,e[25]=m,e[26]=g,e[27]=x,e[28]=r,e[29]=b,e[30]=a,e[31]=$):$=e[31];let A;e[32]!==a?(A=a("Save"),e[32]=a,e[33]=A):A=e[33];let M;e[34]!==l||e[35]!==A?(M=d("button",{className:De,"data-testid":"db-editor-save",onClick:l,type:"button",children:A}),e[34]=l,e[35]=A,e[36]=M):M=e[36];let F;e[37]!==a?(F=a("Cancel"),e[37]=a,e[38]=F):F=e[38];let q;e[39]!==t||e[40]!==F?(q=d("button",{className:De,"data-testid":"db-editor-cancel",onClick:t,type:"button",children:F}),e[39]=t,e[40]=F,e[41]=q):q=e[41];let G;e[42]!==M||e[43]!==q?(G=E("div",{className:"flex items-center gap-1.5",children:[M,q]}),e[42]=M,e[43]=q,e[44]=G):G=e[44];let O;return e[45]!==_||e[46]!==$||e[47]!==G?(O=E("div",{className:"flex flex-col gap-2 border border-border bg-card p-3","data-testid":"db-editor",children:[_,$,G]}),e[45]=_,e[46]=$,e[47]=G,e[48]=O):O=e[48],O};function Is(s){return d("option",{value:s,children:s},s)}const Fs=s=>{const e=B(71),{columns:n,editable:o,filter:t,filters:c,hasMaskedColumns:l,hasPredicate:r,liveError:a,maskOn:i,onAddRow:m,onBulkDelete:f,onBulkPatch:p,onAskAiFilter:b,onClearTable:u,onFilterChange:g,onFiltersChange:h,onGenerateRows:x,onShowJson:v,onShowTable:y,onToggleMask:C,total:N,totalKnown:k,viewMode:S}=s,w=xe(),T=S==="table";let I;e[0]!==y||e[1]!==T?(I=d("button",{"aria-pressed":T,className:De,"data-testid":"db-view-table",onClick:y,type:"button",children:"Table"}),e[0]=y,e[1]=T,e[2]=I):I=e[2];const R=S==="json";let _;e[3]!==v||e[4]!==R?(_=d("button",{"aria-pressed":R,className:De,"data-testid":"db-view-json",onClick:v,type:"button",children:"JSON"}),e[3]=v,e[4]=R,e[5]=_):_=e[5];let $;e[6]!==a||e[7]!==w?($=a===void 0?w("Live — changes stream in automatically"):w("Live unavailable: {liveError}",{liveError:a}),e[6]=a,e[7]=w,e[8]=$):$=e[8];const A=`size-1.5 rounded-full ${a===void 0?"bg-success":"bg-muted-foreground/50"}`;let M;e[9]!==A?(M=d("span",{"aria-hidden":"true",className:A}),e[9]=A,e[10]=M):M=e[10];let F;e[11]!==a||e[12]!==w?(F=w(a===void 0?"Live":"Live unavailable"),e[11]=a,e[12]=w,e[13]=F):F=e[13];let q;e[14]!==$||e[15]!==M||e[16]!==F?(q=E("span",{className:"inline-flex items-center gap-1.5 px-1 text-xs font-medium text-muted-foreground","data-testid":"db-live-indicator",role:"status",title:$,children:[M,F]}),e[14]=$,e[15]=M,e[16]=F,e[17]=q):q=e[17];let G;e[18]!==l||e[19]!==i||e[20]!==C||e[21]!==w?(G=l&&d("button",{"aria-pressed":i,className:De,"data-testid":"db-mask-toggle",onClick:C,type:"button",children:w("Mask sensitive columns")}),e[18]=l,e[19]=i,e[20]=C,e[21]=w,e[22]=G):G=e[22];let O;e[23]!==o||e[24]!==m?(O=o&&d("button",{className:De,"data-testid":"db-add-row",onClick:m,type:"button",children:"Add row"}),e[23]=o,e[24]=m,e[25]=O):O=e[25];let V;e[26]!==o||e[27]!==x||e[28]!==w?(V=o&&d("button",{className:De,"data-testid":"db-generate-rows",onClick:x,type:"button",children:w("Generate rows")}),e[26]=o,e[27]=x,e[28]=w,e[29]=V):V=e[29];let J;e[30]!==o||e[31]!==r||e[32]!==f||e[33]!==w||e[34]!==N||e[35]!==k?(J=o&&N>0&&r&&d(jt,{confirmLabel:k?w("Permanently delete {total} matching rows and everything that cascades?",{total:N.toString()}):w("Permanently delete all matching rows and everything that cascades?"),onConfirm:f,testId:"db-bulk-delete",children:k?w("Delete {total} matching",{total:N.toString()}):w("Delete matching")}),e[30]=o,e[31]=r,e[32]=f,e[33]=w,e[34]=N,e[35]=k,e[36]=J):J=e[36];let j;e[37]!==o||e[38]!==r||e[39]!==p||e[40]!==w||e[41]!==N||e[42]!==k?(j=o&&k&&N>0&&r&&d("button",{className:De,"data-testid":"db-bulk-patch",onClick:p,type:"button",children:w("Set column on {total} matching",{total:N.toString()})}),e[37]=o,e[38]=r,e[39]=p,e[40]=w,e[41]=N,e[42]=k,e[43]=j):j=e[43];let Y;e[44]!==o||e[45]!==r||e[46]!==u||e[47]!==w||e[48]!==N||e[49]!==k?(Y=o&&N>0&&!r&&d(jt,{confirmLabel:k?w("Permanently clear all {total} rows and everything that cascades?",{total:N.toString()}):w("Permanently clear every row and everything that cascades?"),onConfirm:u,testId:"db-clear-table",children:k?w("Clear table ({total})",{total:N.toString()}):w("Clear table")}),e[44]=o,e[45]=r,e[46]=u,e[47]=w,e[48]=N,e[49]=k,e[50]=Y):Y=e[50];let U;e[51]!==G||e[52]!==O||e[53]!==V||e[54]!==J||e[55]!==j||e[56]!==Y||e[57]!==I||e[58]!==_||e[59]!==q?(U=E("div",{className:"flex flex-wrap items-center gap-1.5",children:[I,_,q,G,O,V,J,j,Y]}),e[51]=G,e[52]=O,e[53]=V,e[54]=J,e[55]=j,e[56]=Y,e[57]=I,e[58]=_,e[59]=q,e[60]=U):U=e[60];let H;e[61]!==n||e[62]!==t||e[63]!==c||e[64]!==b||e[65]!==g||e[66]!==h?(H=d(ho,{columns:n,filters:c,onAskAi:b,onFiltersChange:h,onSearchChange:g,search:t}),e[61]=n,e[62]=t,e[63]=c,e[64]=b,e[65]=g,e[66]=h,e[67]=H):H=e[67];let te;return e[68]!==U||e[69]!==H?(te=E("div",{className:"flex flex-col gap-2","data-testid":"db-view-toggle",children:[U,H]}),e[68]=U,e[69]=H,e[70]=te):te=e[70],te},Os=s=>{const e=B(110),{assistant:n,backRelations:o,browser:t,columnMeta:c,edit:l,editable:r,onAskAiFilter:a,onInspect:i,onOpenBulkPatch:m,onOpenGenerateRows:f,onRowDelete:p,onSaveQuery:b,page:u,preferences:g,queryBar:h,references:x}=s,v=g.maskColumns.size>0,y=n.unavailable?void 0:a;let C;e[0]!==t.addRow||e[1]!==t.bulkDelete||e[2]!==t.clearTable||e[3]!==t.columns||e[4]!==t.filter||e[5]!==t.filters||e[6]!==t.hasPredicate||e[7]!==t.liveError||e[8]!==t.onFilterChange||e[9]!==t.onFiltersChange||e[10]!==t.showJson||e[11]!==t.showTable||e[12]!==t.total||e[13]!==t.totalKnown||e[14]!==t.viewMode||e[15]!==r||e[16]!==m||e[17]!==f||e[18]!==g.maskOn||e[19]!==g.onToggleMask||e[20]!==v||e[21]!==y?(C=d(Fs,{columns:t.columns,editable:r,filter:t.filter,filters:t.filters,hasMaskedColumns:v,hasPredicate:t.hasPredicate,liveError:t.liveError,maskOn:g.maskOn,onAddRow:t.addRow,onAskAiFilter:y,onBulkDelete:t.bulkDelete,onBulkPatch:m,onClearTable:t.clearTable,onFilterChange:t.onFilterChange,onFiltersChange:t.onFiltersChange,onGenerateRows:f,onShowJson:t.showJson,onShowTable:t.showTable,onToggleMask:g.onToggleMask,total:t.total,totalKnown:t.totalKnown,viewMode:t.viewMode}),e[0]=t.addRow,e[1]=t.bulkDelete,e[2]=t.clearTable,e[3]=t.columns,e[4]=t.filter,e[5]=t.filters,e[6]=t.hasPredicate,e[7]=t.liveError,e[8]=t.onFilterChange,e[9]=t.onFiltersChange,e[10]=t.showJson,e[11]=t.showTable,e[12]=t.total,e[13]=t.totalKnown,e[14]=t.viewMode,e[15]=r,e[16]=m,e[17]=f,e[18]=g.maskOn,e[19]=g.onToggleMask,e[20]=v,e[21]=y,e[22]=C):C=e[22];let N;e[23]!==b||e[24]!==h?(N=h!==void 0&&d(Cs,{onApply:h.onApplyQuery,onCopyLink:h.onCopyLink,onDelete:h.onDeleteQuery,onSave:b,saved:h.saved}),e[23]=b,e[24]=h,e[25]=N):N=e[25];let k;e[26]!==o||e[27]!==t.onBulkDeleteSelected||e[28]!==t.selectedTable||e[29]!==t.table||e[30]!==t.viewMode||e[31]!==r||e[32]!==u||e[33]!==g.maskView||e[34]!==g.onToggleTranspose||e[35]!==g.transposed?(k=t.viewMode==="table"&&u.rows.length>0&&d(xo,{backRelations:o.available,columns:u.columns,editable:r,enabledBackRelations:o.enabled,name:t.selectedTable??"export",onBulkDelete:t.onBulkDeleteSelected,onToggleBackRelation:o.onToggle,onToggleTranspose:g.onToggleTranspose,rows:vt(u.rows,g.maskView),sqlColumns:u.sqlColumns,table:t.table.table,transposed:g.transposed}),e[26]=o,e[27]=t.onBulkDeleteSelected,e[28]=t.selectedTable,e[29]=t.table,e[30]=t.viewMode,e[31]=r,e[32]=u,e[33]=g.maskView,e[34]=g.onToggleTranspose,e[35]=g.transposed,e[36]=k):k=e[36];let S;e[37]!==t.cancelEdit||e[38]!==t.editing||e[39]!==t.saveEdit||e[40]!==t.setEditorDocumentText||e[41]!==c||e[42]!==r||e[43]!==u?(S=r&&t.editing!==null&&d(As,{columnMeta:c,documentText:t.editing.docText,onCancel:t.cancelEdit,onDocumentTextChange:t.setEditorDocumentText,onSave:t.saveEdit,refs:u.refs}),e[37]=t.cancelEdit,e[38]=t.editing,e[39]=t.saveEdit,e[40]=t.setEditorDocumentText,e[41]=c,e[42]=r,e[43]=u,e[44]=S):S=e[44];let w;e[45]!==t.committing||e[46]!==t.discardStaged||e[47]!==t.onCommitStaged||e[48]!==t.stagedChanges||e[49]!==r?(w=r&&t.stagedChanges.length>0&&d(Bo,{changes:t.stagedChanges,committing:t.committing,onCommit:t.onCommitStaged,onDiscard:t.discardStaged}),e[45]=t.committing,e[46]=t.discardStaged,e[47]=t.onCommitStaged,e[48]=t.stagedChanges,e[49]=r,e[50]=w):w=e[50];let T;e[51]!==t.writeError?(T=t.writeError!==null&&d("p",{className:"text-sm text-destructive","data-testid":"db-write-error",role:"alert",children:t.writeError}),e[51]=t.writeError,e[52]=T):T=e[52];let I;e[53]!==t.writeNotice?(I=t.writeNotice!==null&&d("p",{className:"text-sm text-muted-foreground","data-testid":"db-write-notice",role:"status",children:t.writeNotice}),e[53]=t.writeNotice,e[54]=I):I=e[54];let R;e[55]!==C||e[56]!==N||e[57]!==k||e[58]!==S||e[59]!==w||e[60]!==T||e[61]!==I?(R=E("div",{className:"flex shrink-0 flex-col gap-2 border-b border-border px-4 py-3",children:[C,N,k,S,w,T,I]}),e[55]=C,e[56]=N,e[57]=k,e[58]=S,e[59]=w,e[60]=T,e[61]=I,e[62]=R):R=e[62];let _;e[63]!==t.viewMode||e[64]!==u?(_=t.viewMode==="table"&&u.rows.length===0&&d("div",{className:"flex flex-1 items-center justify-center p-6",children:d(Yn,{description:"Rows you insert into this table will show up here.",icon:d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:d("path",{d:"M4 5h16v14H4V5Zm0 5h16M10 10v9M4 14.5h16"})}),testId:"db-empty-rows",title:"This table is empty."})}),e[63]=t.viewMode,e[64]=u,e[65]=_):_=e[65];let $;e[66]!==t.viewMode||e[67]!==u||e[68]!==g.maskView||e[69]!==g.transposed?($=t.viewMode==="table"&&u.rows.length>0&&g.transposed&&d(bo,{columns:u.columns,rows:vt(u.rows,g.maskView)}),e[66]=t.viewMode,e[67]=u,e[68]=g.maskView,e[69]=g.transposed,e[70]=$):$=e[70];let A;e[71]!==o||e[72]!==t.filter||e[73]!==t.onRowEdit||e[74]!==t.table||e[75]!==t.viewMode||e[76]!==c||e[77]!==l||e[78]!==r||e[79]!==i||e[80]!==p||e[81]!==u||e[82]!==g.maskView||e[83]!==g.onTogglePin||e[84]!==g.pinnedColumns||e[85]!==g.transposed||e[86]!==x?(A=t.viewMode==="table"&&u.rows.length>0&&!g.transposed&&d(ms,{backRelationCounts:o.counts,columnMeta:c,edit:l,editable:r,highlight:t.filter,mask:g.maskView,onDelete:p,onEdit:t.onRowEdit,onInspect:i,onTogglePin:g.onTogglePin,pinnedColumns:g.pinnedColumns,refs:x,tableModel:t.table}),e[71]=o,e[72]=t.filter,e[73]=t.onRowEdit,e[74]=t.table,e[75]=t.viewMode,e[76]=c,e[77]=l,e[78]=r,e[79]=i,e[80]=p,e[81]=u,e[82]=g.maskView,e[83]=g.onTogglePin,e[84]=g.pinnedColumns,e[85]=g.transposed,e[86]=x,e[87]=A):A=e[87];let M;e[88]!==t.viewMode||e[89]!==u||e[90]!==g.maskView?(M=t.viewMode==="json"&&d("pre",{className:"min-h-0 flex-1 overflow-auto border-t border-border bg-muted/30 p-3 text-xs","data-testid":"db-json",children:JSON.stringify(vt(u.rows,g.maskView),en,2)}),e[88]=t.viewMode,e[89]=u,e[90]=g.maskView,e[91]=M):M=e[91];let F;e[92]!==t.changePageSize||e[93]!==t.goNext||e[94]!==t.goPrevious||e[95]!==t.hasNext||e[96]!==t.hasPrevious||e[97]!==t.jumpToPage||e[98]!==t.pageSize||e[99]!==t.rangeEnd||e[100]!==t.rangeStart||e[101]!==t.total?(F=d("div",{className:"flex shrink-0 items-center border-t border-border px-4 py-2",children:d(wo,{hasNext:t.hasNext,hasPrevious:t.hasPrevious,onJumpToPage:t.jumpToPage,onNext:t.goNext,onPageSizeChange:t.changePageSize,onPrevious:t.goPrevious,pageSize:t.pageSize,prefix:"db",rangeEnd:t.rangeEnd,rangeStart:t.rangeStart,total:t.total})}),e[92]=t.changePageSize,e[93]=t.goNext,e[94]=t.goPrevious,e[95]=t.hasNext,e[96]=t.hasPrevious,e[97]=t.jumpToPage,e[98]=t.pageSize,e[99]=t.rangeEnd,e[100]=t.rangeStart,e[101]=t.total,e[102]=F):F=e[102];let q;return e[103]!==R||e[104]!==_||e[105]!==$||e[106]!==A||e[107]!==M||e[108]!==F?(q=E("div",{className:"flex min-h-0 flex-1 flex-col","data-testid":"db-page",children:[R,_,$,A,M,F]}),e[103]=R,e[104]=_,e[105]=$,e[106]=A,e[107]=M,e[108]=F,e[109]=q):q=e[109],q},Ms="/__lunora/seed",St=200,Ls=50,Vs=(s,e)=>{const n=[];for(const o of s)o.pk!==!0&&o.ref!==void 0&&o.type==="id"&&(e[o.ref]??[]).length===0&&n.push(o.name);return n},Bs=s=>Array.isArray(s)&&s.every(e=>nn(e)),js=async s=>{let e;try{e=await fetch(Ms,{body:JSON.stringify(s),headers:{"Content-Type":"application/json"},method:"POST"})}catch(o){return{kind:"error",message:`seed request failed: ${Vt(o)}`}}let n;try{n=await e.json()??{}}catch{return{kind:"error",message:`seed request failed (${String(e.status)})`}}if(e.ok&&n.rows!==void 0){let o;try{o=Rt(n.rows)}catch(t){return{kind:"error",message:`seed response could not be decoded: ${Vt(t)}`}}return Bs(o)?{kind:"ok",rows:o}:{kind:"error",message:"seed response did not carry a list of row documents"}}return n.error==="fk-parents-empty"?{kind:"error",message:`no rows to reference in ${(Array.isArray(n.tables)?n.tables.filter(t=>typeof t=="string"):[]).join(", ")} — seed those tables first`}:{kind:"error",message:typeof n.error=="string"?n.error:`seed request failed (${String(e.status)})`}},zs="rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50",qs="rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50",Ks=({columns:s,fkPools:e,onClose:n,onInsertRows:o,table:t})=>{const c=xe(),[l,r]=D(10),[a,i]=D(!1),[m,f]=D(void 0),[p,b]=D(void 0),[u,g]=D(0),h=N=>{const k=Number(N.target.value);!Number.isNaN(k)&&k>=1&&r(Math.min(k,St))},x=async()=>{f(void 0),b(void 0),g(0),i(!0);try{const N=await js({count:l,existingIds:e,seed:Date.now(),table:t});if(N.kind==="error"){f(N.message);return}const{rows:k}=N;if(k.length===0){f(c("No rows generated — all columns were skipped."));return}const S=await o(k);if(S.error!==void 0){f(S.error);return}b(S.inserted),g(S.conflicts)}finally{i(!1)}},v=()=>{Ne(x())},y=s.filter(N=>N.pk!==!0),C=Vs(s,e);return E(it,{label:c("Generate dummy rows"),onClose:n,panelTestId:"gen-rows-panel",testId:"gen-rows-overlay",variant:"dialog",children:[E("div",{className:"flex items-start justify-between",children:[E("div",{className:"flex flex-col gap-0.5",children:[d("h3",{className:"text-base text-foreground","data-testid":"gen-rows-title",children:c("Generate dummy rows")}),d("p",{className:"text-xs text-muted-foreground","data-testid":"gen-rows-desc",children:c("Seed {table} with Faker-generated rows. Existing rows are not affected.",{table:t})})]}),d("button",{className:"text-xs text-muted-foreground hover:text-foreground","data-testid":"gen-rows-close",onClick:n,type:"button",children:c("Close")})]}),E("div",{className:"flex items-center gap-2",children:[d("label",{className:"text-xs font-medium text-foreground",htmlFor:"gen-rows-count",children:c("Row count")}),d("input",{className:"w-20 rounded-md border border-border bg-background px-2 py-1 text-xs outline-none focus-visible:border-ring","data-testid":"gen-rows-count",id:"gen-rows-count",max:St,min:1,onChange:h,type:"number",value:l}),d("span",{className:"text-xs text-muted-foreground",children:c("(max {max})",{max:St.toString()})})]}),y.length>0&&E("div",{className:"flex flex-col gap-1",children:[d("p",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:c("Columns to seed")}),d("ul",{className:"flex flex-col gap-0.5","data-testid":"gen-rows-columns",children:y.map(N=>{const k=N.ref!==void 0&&N.type==="id",S=k&&(e[N.ref??""]??[]).length===0,w=S?"rounded bg-destructive/10 px-1 text-destructive":"rounded bg-muted px-1 text-muted-foreground",T=S?`gen-rows-fk-empty-${N.name}`:`gen-rows-fk-ok-${N.name}`,I=S?c("FK: no rows in {ref} — seed it first",{ref:N.ref??""}):c("→ {ref}",{ref:N.ref??""});return E("li",{className:"flex items-center gap-1.5 font-mono text-xs",children:[d("span",{className:"text-foreground",children:N.name}),E("span",{className:"text-muted-foreground",children:["(",N.type,")"]}),N.optional&&d("span",{className:"rounded bg-muted px-1 font-mono text-[10px] tracking-wide uppercase",children:"optional"}),k&&d("span",{className:w,"data-testid":T,children:I})]},N.name)})})]}),C.length>0&&d("p",{className:"text-xs text-destructive","data-testid":"gen-rows-blocked",role:"alert",children:c("Cannot generate rows: these columns reference tables with no rows: {cols}. Seed those tables first.",{cols:C.join(", ")})}),m!==void 0&&d("p",{className:"text-xs text-destructive","data-testid":"gen-rows-error",role:"alert",children:m}),p!==void 0&&m===void 0&&d("p",{className:"text-xs text-success","data-testid":"gen-rows-success",children:u>0?c("Inserted {inserted} of {total} rows — {conflicts} skipped as id conflicts.",{conflicts:u.toString(),inserted:p.toString(),total:(p+u).toString()}):c("Inserted {count} rows successfully.",{count:p.toString()})}),E("div",{className:"flex justify-end gap-2",children:[d("button",{className:zs,"data-testid":"gen-rows-cancel",onClick:n,type:"button",children:c("Cancel")}),d("button",{className:qs,"data-testid":"gen-rows-generate",disabled:a||C.length>0,onClick:v,type:"button",children:c(a?"Inserting…":"Generate & insert")})]})]})},Gs=Ee(pe.backRelationCounts),Js=(s,e,n,o)=>{const t=B(16),c=at();let l;t[0]===Symbol.for("react.memo_cache_sentinel")?(l={},t[0]=l):l=t[0];const[r,a]=D(l);let i;if(t[1]!==s||t[2]!==e){let x;t[4]!==s?(x=v=>s.has(Dt(v)),t[4]=s,t[5]=x):x=t[5],i=e.filter(x),t[1]=s,t[2]=e,t[3]=i}else i=t[3];const m=i;let f;t[6]!==n||t[7]!==m?(f=JSON.stringify([m,n]),t[6]=n,t[7]=m,t[8]=f):f=t[8];const p=f;let b;t[9]!==c||t[10]!==o||t[11]!==p?(b=async x=>{const[v,y]=JSON.parse(p);if(v.length===0||y.length===0){x.cancelled||a({});return}try{const C=await c.query(Gs,{ids:y,relations:v},Te(o));x.cancelled||a(Object.fromEntries(C.relations.map(Ws)))}catch{}},t[9]=c,t[10]=o,t[11]=p,t[12]=b):b=t[12];const u=b;let g,h;return t[13]!==u?(g=()=>{const x={cancelled:!1};return Ne(u(x)),()=>{x.cancelled=!0}},h=[u],t[13]=u,t[14]=g,t[15]=h):(g=t[14],h=t[15]),Be(g,h),r};function Ws(s){return[Dt(s),s.counts]}const Hs=async s=>{const{args:e,maxBatches:n,openCursor:o,query:t}=s;let c=o,l=0,r="cap-hit";for(let a=0;a<n;a+=1){const i=await t({...e,after:c});if(l+=i.count,c=i.cursor,!i.hasMore){r="completed";break}}return{cursor:r==="cap-hit"?c:void 0,outcome:r,written:l}},st=s=>{const e=s[0];return e===void 0?void 0:{column:e.id,direction:e.desc?"desc":"asc"}},fn=s=>Oe(s),Qt=s=>s.map(e=>({column:e.column,...e.value===void 0?{}:{literal:[e.value]},operator:e.operator,value:e.value===void 0?"":fn(e.value)})),Yt=s=>s===void 0?[]:[{desc:s.direction==="desc",id:s.column}],Us=s=>[s.column,s.operator,s.value],nt=(s,e,n,o)=>JSON.stringify([s??"",e??"",(n??[]).map(t=>Us(t)),o===void 0?null:[o.column,o.direction]]),At=200,Qs=20,Ys=Ee(pe.readTablePage),Xs=Ee(pe.facetColumn),kt=Ee(pe.writeRow),Zs=Ee(pe.deleteRows),el=Ee(pe.clearTable),tl=Ee(pe.patchRows),nl={},It=new Set(["__doc__","__id__","_creationTime","_id","id"]),ol=s=>{const e=s.__doc__;if(typeof e=="string"){const o=Un(e);if(o!==void 0)return o}const n={};for(const[o,t]of Object.entries(s))It.has(o)||(n[o]=t);return n},sl=(s,e,n)=>JSON.stringify([s.__lunoraRef,n,on(e)]),ll=({filters:s,offset:e,pageSize:n,search:o,sorting:t,table:c})=>({filters:Fe(s),limit:n,offset:e,orderBy:st(t),search:o,skipCount:!0,table:c}),rl=({filters:s,search:e,table:n})=>({filters:Fe(s),limit:1,search:e,table:n}),al=(s,e)=>{const n=new Map;for(const t of s?.rows??[]){const c=Pe(t);c!==null&&n.set(c,t)}const o=[];for(const[t,c]of Object.entries(e))for(const[l,r]of Object.entries(c))o.push({column:l,newValue:r,oldValue:n.get(t)?.[l],rowId:t});return o},il=s=>!It.has(s),cl=`Stopped after ${At.toString()} batches — rows still match. Run it again to remove the rest.`,dl=`Stopped after ${At.toString()} batches — rows still match. Run it again to set the rest.`,Xt={resumable:!1,truncated:cl,verb:"deleted"},ul={resumable:!0,truncated:dl,verb:"written"},fl=({initialFilters:s,initialOrderBy:e,initialSearch:n,initialShardKey:o,onSelectTable:t,onViewChange:c,pageSize:l,resolveBackRelations:r,tableParam:a})=>{const i=at(),[m,f]=D(l),[p,b]=D(o??""),u=a===void 0||a===""?null:a,[g,h]=D(0),[x,v]=D("table"),[y,C]=D(()=>Yt(e)),[N,k]=D(n??""),[S,w]=D(()=>Qt(s??[])),{clearFacets:T,facets:I,refetchFacets:R,toggleFacet:_}=Kn(),[$,A]=D(null),[M,F]=D(null),[q,G]=D(null),O=Ge(null),V=Vo(),[J,j]=D(null),[Y,U]=D(!1),[H,te]=D(a),[le,ue]=D(()=>nt(o,n,s,e)),[fe,ge]=D(0),[ae,me]=D(()=>nt(o,n,s,e)),ie=a!==H,Q=nt(o,n,s,e),Z=ie||!ie&&Q!==le&&Q!==ae;if(Z){te(a),ue(Q),ge(z=>z+1),C(Yt(e)),k(n??"");const P=Qt(s??[]);w(P),b(o??""),T(),V.clear(),j(null),A(null),h(0),F(null),G(null),O.current=null}else Q!==le&&ue(Q);const ve=Z?n??"":N,ce=Z?o??"":p,de=`${a??""}:${fe.toString()}`,W=zt(ve.trim(),300,de),K=zt(ce.trim(),400,de),[ee,X]=D(K);ee!==K&&(X(K),V.clear(),j(null),A(null));const he=nt(K,W,Fe(S),st(y));he!==ae&&me(he);const re=Xe(pe.listTables,nl,{live:!0,shardKey:K}),we=re.data??null,ye=re.error,ne=ll({filters:S,offset:g,pageSize:m,search:W,sorting:y,table:u??""}),Me=rl({filters:S,search:W,table:u??""}),Ce=Xe(pe.readTablePage,ne,{enabled:u!==null,keepPreviousData:!1,live:!0,shardKey:K}),oe=Ce.data??null,Ae=Ce.error,{liveError:We}=Ce,ke=Xe(pe.readTablePage,Me,{enabled:u!==null,live:!0,shardKey:K});Be(()=>{re.data!==void 0&&yo(K)},[re.data,K]);const ze=P=>{t?.(P)},je=(P,z)=>{t?.(P,{search:z})},He=async(P,z)=>{try{return(await i.query(Ys,{filters:[],limit:Qs,offset:0,search:z,table:P},Te(K))).rows.find(Re=>Pe(Re)===z)??null}catch{return null}},et=(P,z,Se,Re)=>$e=>i.query(Xs,{column:$e,filters:Fe(Se),search:Re,table:z},Te(P)),ct=P=>{_(P,u===null?null:et(K,u,S,W))},tt=(P,z)=>{const Se={column:P,literal:[jn(z)],operator:"eq",value:fn(z)};w(Re=>[...Re.filter($e=>$e.column!==P),Se]),h(0)},dt=wt(et),ut=wt(R),Ue=wt(c);Be(()=>{u!==null&&ut.current(dt.current(K,u,S,W))},[K,u,S,W]),Be(()=>{u===null||Ue.current===void 0||H!==a||le!==Q||Ue.current({filters:Fe(S),orderBy:st(y),search:W,shard:K})},[u,a,H,le,Q,S,y,W,K]);const Qe=P=>{u!==null&&h(Math.max(0,P))},ft=(P,z)=>{j({column:z,rowId:P})},mt=()=>{j(null)},gt=async()=>{if(u!==null){F(null),U(!0);try{for(const[P,z]of Object.entries(V.staged))await i.query(kt,{doc:z,id:P,op:"patch",table:u},Te(K)),V.drop(P,z)}catch(P){F(P.message)}j(null),Ce.refetch(),U(!1)}},pt=()=>{V.clear(),j(null)},bt=P=>{b(P),V.clear(),j(null),A(null),h(0),O.current=null},ht=al(oe,V.staged),L=async(P,z,Se)=>{if(u===null)return;F(null);let Re;if(P!=="delete"){let $e;try{$e=Se===void 0||Se.trim()===""?{}:JSON.parse(Se)}catch(Ve){F(`Invalid JSON: ${Ve.message}`);return}try{const Ve=Rt($e);if(!nn(Ve)){F("The document must be a JSON object.");return}Re=Ve}catch(Ve){F(`Invalid document: ${Ve.message}`);return}}try{await i.query(kt,{doc:Re,id:z??void 0,op:P,table:u},Te(K)),A(null),Ce.refetch()}catch($e){F($e.message)}},se=async(P,z,Se)=>{if(u===null)return 0;F(null),G(null);const Re=sl(P,z,K),$e=O.current?.key===Re?O.current.after:void 0,Ve=Se.resumable?$e??"":void 0;let qe=0;try{const Ye=await Hs({args:z,maxBatches:At,openCursor:Ve,query:async Vn=>{const Lt=await i.query(P,Vn,Te(K));return qe+=Lt.count,Lt}});return O.current=Ye.cursor===void 0?null:{after:Ye.cursor,key:Re},Ye.outcome==="cap-hit"&&F(Se.truncated),G(`${qe.toString()} ${qe===1?"row":"rows"} ${Se.verb}.`),qe}catch(Ye){return F(`${Ye.message} (at least ${qe.toString()} rows were already ${Se.verb})`),O.current=null,qe}finally{h(0),Ce.refetch()}},_e=P=>{C(P),h(0)},Ie=Tt(()=>u===null?[]:r?.(u)??[],[r,u]),Le=gs(oe,y,_e,Ie),xt={filters:Fe(S),orderBy:st(y),search:W,shard:p,table:u??void 0},Ft=ke.data?.total,Ot=Ft!==void 0,Mt=Ft??(oe===null?0:g+oe.rows.length),mn=g>0,gn=W!==""||Fe(S).length>0,pn=oe!==null&&(Ot?g+oe.rows.length<Mt:oe.rows.length===m),bn=oe===null||oe.rows.length===0?0:g+1,hn=oe===null?0:g+oe.rows.length,xn=()=>{re.refetch()},vn=()=>{v("table")},wn=()=>{v("json")},yn=()=>{Ne(se(Zs,{filters:Fe(S),search:W,table:u},Xt))},Cn=()=>{Ne(se(el,{table:u},Xt))},Nn=P=>{Ne(se(tl,{doc:P,filters:Fe(S),search:W,table:u},ul))},Sn=P=>{k(P.target.value),h(0)},kn=P=>{w(P),h(0)},Tn=()=>{F(null);const P={};for(const z of oe?.columns??[])It.has(z)||(P[z]="");A({docText:JSON.stringify(P,null,2),id:""})},En=P=>{A(z=>z===null?z:{docText:P,id:z.id})},_n=()=>{$!==null&&Ne(L($.id===""?"insert":"patch",$.id===""?null:$.id,$.docText))},Rn=()=>{A(null),F(null)},$n=()=>{Qe(g-m)},Dn=()=>{Qe(g+m)},Pn=P=>{Qe(Math.max(0,(P-1)*m))},An=P=>{f(P),h(0)},In=(P,z)=>{F(null),A({docText:JSON.stringify(on(ol(z)),null,2),id:P})},Fn=P=>{Ne(L("delete",P))},On=async P=>{if(!(u===null||P.length===0)){F(null);try{for(const z of P)await i.query(kt,{id:z,op:"delete",table:u},Te(K));Ce.refetch()}catch(z){F(z.message)}}},Mn=P=>{Ne(On(P))},Ln=()=>{Ne(gt())};return{addRow:Tn,bulkDelete:yn,bulkPatch:Nn,cancelCellEdit:mt,cancelEdit:Rn,changePageSize:An,clearTable:Cn,columns:oe?.columns??[],committing:Y,currentView:xt,discardStaged:pt,editableColumn:il,editing:$,editingCell:J,facetFilter:tt,facets:I,filter:N,filters:S,goNext:Dn,goPrevious:$n,hasNext:pn,hasPredicate:gn,hasPrevious:mn,jumpToPage:Pn,liveError:We,loadTables:xn,navigateToRef:je,onBulkDeleteSelected:Mn,onCommitStaged:Ln,onFilterChange:Sn,onFiltersChange:kn,onRowDelete:Fn,onRowEdit:In,page:oe,previewRef:He,pageError:Ae,pageSize:m,rangeEnd:hn,rangeStart:bn,queryShardKey:K,saveEdit:_n,selectedTable:u,selectTable:ze,setEditorDocumentText:En,setShardKey:bt,shardKey:p,showJson:wn,showTable:vn,stage:V.stage,stagedChanges:ht,stagedValue:V.stagedValue,startCellEdit:ft,table:Le,tables:we,tablesError:ye,toggleFacet:ct,total:Mt,totalKnown:Ot,viewMode:x,writeError:M,writeNotice:q}},ml="lunora-studio-pinned-columns",gl=s=>{const e=B(21),{columns:n,initialPins:o,selectedTable:t}=s;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];const[l,r]=Zt(ml,c),a=t??"",i=l[a];let m;e[1]!==o||e[2]!==i?(m=i===void 0?new Set((o??"").split(",").filter(pl)):new Set(i),e[1]=o,e[2]=i,e[3]=m):m=e[3];const f=m;let p;e[4]!==a||e[5]!==f||e[6]!==r?(p=T=>{r(I=>{const R=I[a]??[...f],_=R.includes(T)?R.filter($=>$!==T):[...R,T];return{...I,[a]:_}})},e[4]=a,e[5]=f,e[6]=r,e[7]=p):p=e[7];const b=p,[u,g]=D(!1);let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{g(bl)},e[8]=h):h=e[8];const x=h;let v;e[9]!==n||e[10]!==t?(v={columns:n,selectedTable:t},e[9]=n,e[10]=t,e[11]=v):v=e[11];const{maskColumns:y,maskOn:C,maskView:N,maskViewFor:k,onToggleMask:S}=Gn(v);let w;return e[12]!==y||e[13]!==C||e[14]!==N||e[15]!==k||e[16]!==S||e[17]!==b||e[18]!==f||e[19]!==u?(w={maskColumns:y,maskOn:C,maskView:N,maskViewFor:k,onToggleMask:S,onTogglePin:b,onToggleTranspose:x,pinnedColumns:f,transposed:u},e[12]=y,e[13]=C,e[14]=N,e[15]=k,e[16]=S,e[17]=b,e[18]=f,e[19]=u,e[20]=w):w=e[20],w};function pl(s){return s!==""}function bl(s){return!s}const hl=Ee(pe.describeTable),xl=Ee(pe.readTablePage),vl=Ee(pe.importShard),wl=s=>{const e=s._id??s.id??s.__id__??"";return typeof e=="string"?e:typeof e=="number"?String(e):""},yl=s=>{const e=Object.values(s.inserted).reduce((a,i)=>a+i,0),[n]=s.errors;if(n===void 0)return{conflicts:s.conflicts,error:void 0,inserted:e};const o=s.errors.length-1,t=e+s.conflicts+s.errors.length,c=o===1?"error":"errors",l=o>0?` (+${o.toString()} more ${c})`:"",r=`Inserted ${e.toString()} of ${t.toString()} rows — row ${n.line.toString()} (${n.table}): ${n.message}${l}`;return{conflicts:s.conflicts,error:r,inserted:e}},Cl=s=>{const e=at(),[n,o]=D(!1),[t,c]=D(void 0),[l,r]=D(void 0),[a,i]=D(void 0),[m,f]=D({}),[p,b]=D(!1),[u,g]=D(void 0),h=async(C,N)=>{o(!0),c(C),r(N),i(void 0),f({}),g(void 0),b(!0);try{const k=await e.query(hl,{table:C},Te(N)),{columns:S}=k;i(S);const w={},T=S.filter(I=>I.ref!==void 0&&I.type==="id"&&I.pk!==!0);for(const I of T){if(I.ref===void 0)continue;const{ref:R}=I;if(w[R]===void 0)try{const _=await e.query(xl,{filters:[],limit:Ls,offset:0,search:"",table:R},Te(N));w[R]=_.rows.flatMap($=>wl($)||[])}catch{w[R]=[]}}f(w)}catch(k){g(k.message)}b(!1)};return{closeDialog:()=>{o(!1),c(void 0),r(void 0),i(void 0),f({}),g(void 0)},columnMeta:a,error:u,fkPools:m,insertBatch:async(C,N)=>{if(t===void 0||l===void 0)return{conflicts:0,error:"No table selected.",inserted:0};try{const k=await e.query(vl,{rows:C.map(w=>({doc:w,table:t}))},Te(l)),S=yl(k);return S.error!==void 0||(N(),s()),S}catch(k){return{conflicts:0,error:k.message,inserted:0}}},loading:p,open:n,openDialog:(C,N)=>{Ne(h(C,N))},shardKey:l,table:t}},Nl=()=>{const s=B(6),[e,n]=D(null);let o;s[0]===Symbol.for("react.memo_cache_sentinel")?(o=()=>{n(null)},s[0]=o):o=s[0];const t=o,[c,l]=D(null);let r;s[1]===Symbol.for("react.memo_cache_sentinel")?(r=(p,b)=>{l({column:p,value:b})},s[1]=r):r=s[1];const a=r;let i;s[2]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{l(null)},s[2]=i):i=s[2];const m=i;let f;return s[3]!==c||s[4]!==e?(f={closeExpandedCell:m,closeInspect:t,expandedCell:c,inspecting:e,onExpandCell:a,onInspect:n},s[3]=c,s[4]=e,s[5]=f):f=s[5],f},Sl=/(?:_creationtime|(?:^|[a-z])(?:time|at))$/iu,kl=(s,e)=>typeof e=="number"&&Sl.test(s),Tl=s=>{const e=B(36),{column:n,masked:o,onNavigate:t,target:c,value:l}=s;let r;e[0]!==t||e[1]!==c||e[2]!==l?(r=()=>{c!==void 0&&t(c,String(l))},e[0]=t,e[1]=c,e[2]=l,e[3]=r):r=e[3];const a=r;if(l==null){let f;return e[4]===Symbol.for("react.memo_cache_sentinel")?(f=d("span",{className:"italic text-muted-foreground",children:"null"}),e[4]=f):f=e[4],f}if(o){const f=`rd-masked-${n}`;let p;e[5]!==l?(p=Oe(l),e[5]=l,e[6]=p):p=e[6];let b;return e[7]!==f||e[8]!==p?(b=d("span",{className:"italic text-muted-foreground","data-testid":f,title:"Masked (preview)",children:p}),e[7]=f,e[8]=p,e[9]=b):b=e[9],b}if(c!==void 0&&(typeof l=="string"||typeof l=="number")&&String(l)!==""){const f=`rd-ref-${n}`,p=`Open ${c} ${String(l)}`,b=String(l);let u;return e[10]!==a||e[11]!==f||e[12]!==p||e[13]!==b?(u=E("button",{"data-testid":f,onClick:a,title:p,type:"button",children:[b," ↗"]}),e[10]=a,e[11]=f,e[12]=p,e[13]=b,e[14]=u):u=e[14],u}if(kl(n,l)){const f=`rd-ts-${n}`;let p;e[15]!==l?(p=l.toString(),e[15]=l,e[16]=p):p=e[16];let b;e[17]!==l?(b=zn(l),e[17]=l,e[18]=b):b=e[18];let u;return e[19]!==f||e[20]!==p||e[21]!==b?(u=d("span",{"data-testid":f,title:p,children:b}),e[19]=f,e[20]=p,e[21]=b,e[22]=u):u=e[22],u}if(l instanceof ArrayBuffer||ArrayBuffer.isView(l)){const f=`rd-bytes-${n}`;let p;e[23]!==l?(p=Oe(l),e[23]=l,e[24]=p):p=e[24];let b;return e[25]!==f||e[26]!==p?(b=d("span",{"data-testid":f,children:p}),e[25]=f,e[26]=p,e[27]=b):b=e[27],b}if(typeof l=="object"){let f;e[28]!==l?(f=JSON.stringify(l,en,2),e[28]=l,e[29]=f):f=e[29];let p;return e[30]!==f?(p=d("pre",{className:"m-0 overflow-auto rounded-md bg-muted/50 p-2 text-xs",children:f}),e[30]=f,e[31]=p):p=e[31],p}let i;e[32]!==l?(i=Oe(l),e[32]=l,e[33]=i):i=e[33];let m;return e[34]!==i?(m=d("span",{children:i}),e[34]=i,e[35]=m):m=e[35],m},El=s=>{const e=B(23),{columns:n,mask:o,onClose:t,onNavigate:c,refs:l,row:r}=s;let a;e[0]!==t||e[1]!==c?(a=(g,h)=>{c(g,h),t()},e[0]=t,e[1]=c,e[2]=a):a=e[2];const i=a;let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=d("h3",{className:"m-0 text-base text-foreground",children:"Row detail"}),e[3]=m):m=e[3];let f;e[4]!==t?(f=E("div",{className:"mb-3 flex items-center justify-between",children:[m,d("button",{"data-testid":"rd-close",onClick:t,type:"button",children:"Close"})]}),e[4]=t,e[5]=f):f=e[5];let p;if(e[6]!==n||e[7]!==o||e[8]!==i||e[9]!==l||e[10]!==r){let g;e[12]!==o||e[13]!==i||e[14]!==l||e[15]!==r?(g=h=>E("div",{className:"border-t border-border py-2 first:border-t-0","data-testid":`rd-field-${h}`,children:[d("dt",{className:"mb-0.5 text-xs font-semibold text-muted-foreground",children:h}),d("dd",{className:"m-0",children:d(Tl,{column:h,masked:o.enabled&&o.columns.has(h),onNavigate:i,target:l?.[h],value:r[h]})})]},h),e[12]=o,e[13]=i,e[14]=l,e[15]=r,e[16]=g):g=e[16],p=n.map(g),e[6]=n,e[7]=o,e[8]=i,e[9]=l,e[10]=r,e[11]=p}else p=e[11];let b;e[17]!==p?(b=d("dl",{"data-testid":"rd-fields",children:p}),e[17]=p,e[18]=b):b=e[18];let u;return e[19]!==t||e[20]!==f||e[21]!==b?(u=E(it,{label:"Row detail",onClose:t,panelTestId:"rd-panel",testId:"rd-overlay",variant:"drawer",children:[f,b]}),e[19]=t,e[20]=f,e[21]=b,e[22]=u):u=e[22],u},_l=50,Rl=s=>{const e=B(8),{active:n,onPick:o,shard:t}=s;let c;e[0]!==o||e[1]!==t?(c=()=>{o(t)},e[0]=o,e[1]=t,e[2]=c):c=e[2];const l=c,r=`w-full rounded px-2 py-0.5 text-left text-xs transition-colors hover:bg-accent ${n?"bg-accent font-medium":""}`,a=`shard-explorer-item-${t}`;let i;return e[3]!==l||e[4]!==t||e[5]!==r||e[6]!==a?(i=d("button",{className:r,"data-testid":a,onClick:l,type:"button",children:t}),e[3]=l,e[4]=t,e[5]=r,e[6]=a,e[7]=i):i=e[7],i},$l=({onFetchTables:s,onSelect:e})=>{const n=xe(),[o]=D(()=>Co()),[t,c]=D(!1),[l,r]=D(void 0),[a,i]=D(void 0),[m,f]=D(!1),[p,b]=D(void 0),u=Ge(0),g=()=>{c(v=>!v)},h=async v=>{e(v),r(v),i(void 0),b(void 0),f(!0),u.current+=1;const y=u.current;try{const C=await s(v);u.current===y&&i(C?.slice(0,_l))}catch(C){u.current===y&&b(C.message)}u.current===y&&f(!1)},x=v=>{Ne(h(v))};return o.length===0?null:E("div",{"data-testid":"shard-explorer",children:[E("button",{"aria-controls":"shard-explorer-panel","aria-expanded":t,className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"shard-explorer-toggle",onClick:g,type:"button",children:[n("Shards seen"),d("span",{"aria-hidden":"true",className:`ml-0.5 transition-transform ${t?"rotate-180":""}`,children:"▾"})]}),t&&E("div",{className:"mt-1 flex flex-col gap-1 rounded-md border border-border bg-popover p-2","data-testid":"shard-explorer-panel",id:"shard-explorer-panel",children:[d("p",{className:"text-xs text-muted-foreground","data-testid":"shard-explorer-hint",children:n("Recently visited shards — click to switch")}),d("ul",{className:"flex flex-col gap-0.5","data-testid":"shard-explorer-list",children:o.map(v=>d("li",{children:d(Rl,{active:l===v,onPick:x,shard:v})},v))}),l!==void 0&&E("div",{className:"mt-1 border-t border-border pt-1","data-testid":"shard-explorer-summary",children:[d("p",{className:"mb-1 text-xs font-medium text-foreground","data-testid":"shard-explorer-summary-title",children:n("{shard} tables",{shard:l})}),m&&d("p",{className:"text-xs text-muted-foreground","data-testid":"shard-explorer-loading",children:n("Loading…")}),p!==void 0&&d("p",{className:"text-xs text-destructive","data-testid":"shard-explorer-error",role:"alert",children:p}),!m&&p===void 0&&a?.length===0&&d("p",{className:"text-xs text-muted-foreground","data-testid":"shard-explorer-empty",children:n("No tables in this shard.")}),!m&&p===void 0&&a!==void 0&&a.length>0&&d("ul",{className:"flex flex-col gap-0.5","data-testid":"shard-explorer-tables",children:a.map(v=>E("li",{className:"flex items-center justify-between text-xs",children:[d("span",{"data-testid":`shard-explorer-table-${v.name}`,children:v.name}),d("span",{className:"text-muted-foreground","data-testid":`shard-explorer-rowcount-${v.name}`,children:v.rowCount})]},v.name))})]})]})]})},Dl="lunora-studio-back-relations",Pl=s=>new Set((s??[]).filter(e=>e.unique===!0&&e.fields.length===1).map(e=>e.fields[0]??"")),Al={},Il=50,Fl=[],Ol=Ee(pe.listTables),Ml=Ee(pe.readTablePage),Ll=s=>{const e=B(10),{onFetchShardTables:n,onShardChange:o,schemaSwitch:t,shardKey:c}=s;let l;e[0]!==o||e[1]!==c?(l=d(Bn,{onChange:o,testId:"db-shard-input",value:c}),e[0]=o,e[1]=c,e[2]=l):l=e[2];let r;e[3]!==n||e[4]!==o?(r=d($l,{onFetchTables:n,onSelect:o}),e[3]=n,e[4]=o,e[5]=r):r=e[5];let a;return e[6]!==t||e[7]!==l||e[8]!==r?(a=E("div",{className:"flex shrink-0 flex-col items-stretch gap-2 border-b border-border p-3",children:[t,l,r]}),e[6]=t,e[7]=l,e[8]=r,e[9]=a):a=e[9],a},br=({editable:s=!1,globalTableNames:e,initialFilters:n,initialOrderBy:o,initialPins:t,initialSearch:c,initialShardKey:l,onNavigateToGlobal:r,onSelectTable:a,onViewChange:i,pageSize:m=Il,queryBar:f,schemaSwitch:p,tableParam:b})=>{const u=Xe(pe.describeTables,{},{shardKey:l??""}),g=Xe(pe.listTablesIndexes,{},{shardKey:l??""}),h=u.data?.columnsByTable??Al,[x,v]=Zt(Dl,{}),y=lt(L=>{const se=new Set(x[L]);return qt(L,h).filter(_e=>se.has(Dt(_e)))},[x,h]),C=fl({initialFilters:n,initialOrderBy:o,initialSearch:c,initialShardKey:l,onSelectTable:a,onViewChange:i,pageSize:m,resolveBackRelations:y,tableParam:b}),{cancelCellEdit:N,columns:k,currentView:S,editableColumn:w,editingCell:T,facetFilter:I,facets:R,loadTables:_,navigateToRef:$,onFiltersChange:A,page:M,pageError:F,previewRef:q,queryShardKey:G,selectedTable:O,selectTable:V,setShardKey:J,shardKey:j,stage:Y,stagedValue:U,startCellEdit:H,tables:te,tablesError:le,toggleFacet:ue}=C,fe=Hn(j),ge=L=>{Ne((async()=>{const _e=await fe.suggestFilter(L,O??"");_e!==void 0&&A(_e.map(Ie=>{const Le=Ie.value,xt=typeof Le=="string"||typeof Le=="number"||typeof Le=="boolean"?String(Le):"";return{column:Ie.column,operator:Ie.operator,value:xt}}))})())},ae=O===null?[]:qt(O,h),me=new Set(x[O??""]),ie=[];for(const L of M?.rows??[]){const se=L._id??L.id;typeof se=="string"&&se!==""&&ie.push(se)}const Q=Js(me,ae,ie,G),be=L=>{v(se=>{const _e=O??"",Ie=se[_e]??[];return{...se,[_e]:Ie.includes(L)?Ie.filter(Le=>Le!==L):[...Ie,L]}})},Z=gl({columns:k,initialPins:t,selectedTable:O}),ve=Nl(),[ce,de]=D(null),{closeExpandedCell:W,closeInspect:K,expandedCell:ee,inspecting:X,onExpandCell:he}=ve,re=at(),we=Object.fromEntries((h[O??""]??[]).map(L=>[L.name,L])),ye=new Map;for(const L of h[O??""]??[])L.isStorage===!0&&ye.set(L.name,L.bucket);const ne=lt(async(L,se)=>re.signedStorageUrl(L,se===void 0?{}:{bucket:se}),[re]),Me=async L=>await re.query(Ol,{},Te(L)),Ce=()=>{O!==null&&V(O)},{closeDialog:oe,columnMeta:Ae,fkPools:We,insertBatch:ke,open:ze,openDialog:je}=Cl(Ce),He=()=>{O!==null&&je(O,j)},et=L=>ke(L,oe),[ct,tt]=D(!1),dt=()=>{tt(!0)},ut=()=>{tt(!1)},Ue=(L,se)=>{if(r!==void 0&&e?.has(L)===!0){r(L,se);return}$(L,se)},Qe=f?.onSaveQuery,ft=L=>{Qe?.(L,S)},mt={cancelEdit:N,editable:s,editableColumn:w,editingCell:T,onExpandCell:he,stage:Y,stagedValue:U,startEdit:H},gt=L=>{L!==null&&de(L)},pt=()=>{C.onRowDelete(ce)},bt=async(L,se,_e)=>await re.query(Ml,{filters:[{column:se,operator:"eq",value:_e}],limit:ot,offset:0,orderBy:[],table:L},Te(G)),ht={columns:M?.refs,maskViewFor:Z.maskViewFor,onNavigate:Ue,onPreview:q};return E("div",{className:"flex h-full min-w-0","data-testid":"lunora-data-browser",children:[d(Jn,{header:d(Ll,{onFetchShardTables:Me,onShardChange:J,schemaSwitch:p,shardKey:j}),onReload:_,onSelect:V,prefix:"db",selected:O,tables:te??Fl}),E("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[le!==null&&d("p",{className:"shrink-0 border-b border-border px-4 py-2 text-sm text-destructive","data-testid":"db-tables-error",role:"alert",children:le}),M===null&&F===null&&d("div",{className:"flex flex-1 items-center justify-center p-6",children:d("p",{className:"text-sm text-muted-foreground",children:"Select a table to browse its rows."})}),F!==null&&d("p",{className:"shrink-0 border-b border-border px-4 py-2 text-sm text-destructive","data-testid":"db-page-error",role:"alert",children:F}),M!==null&&d(Os,{assistant:fe,backRelations:{available:ae,counts:Q,enabled:me,onToggle:be},browser:C,columnMeta:we,edit:mt,editable:s,onAskAiFilter:ge,onInspect:ve.onInspect,onOpenBulkPatch:dt,onOpenGenerateRows:He,onRowDelete:gt,onSaveQuery:ft,page:M,preferences:Z,queryBar:f,references:ht})]}),M!==null&&d(Wn,{columns:k,facets:R,mask:Z.maskView,onFacetFilter:I,onToggleFacet:ue}),X!==null&&M!==null&&d(El,{columns:M.columns,mask:Z.maskView,onClose:K,onNavigate:Ue,refs:M.refs,row:tn(X,Z.maskView)}),ce!==null&&O!==null&&d(Fo,{onClose:()=>{de(null)},onConfirm:pt,readPage:bt,rowId:ce,schema:No(h),table:O}),ee!==null&&d(vo,{bucket:ye.get(ee.column),column:ee.column,onClose:W,resolveUrl:ye.has(ee.column)?ne:void 0,value:ee.value}),ct&&O!==null&&d(To,{columns:C.columns.filter(L=>C.editableColumn(L)),onApply:C.bulkPatch,onClose:ut,shardKey:C.queryShardKey,table:O,total:C.total,uniqueColumns:Pl(g.data?.indexesByTable[O])}),ze&&O!==null&&Ae!==void 0&&d(Ks,{columns:Ae,fkPools:We,onClose:oe,onInsertRows:et,table:O})]})};export{br as DataBrowser};