@lunora/studio 1.0.0-alpha.113 → 1.0.0-alpha.114

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 (153) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/mount.js +1 -1
  3. package/dist/packem_chunks/AdvisorHealthPanel.js +1 -1
  4. package/dist/packem_chunks/ApiTab.js +1 -1
  5. package/dist/packem_chunks/AuditPanel.js +1 -1
  6. package/dist/packem_chunks/DeploymentHealthPanel.js +1 -1
  7. package/dist/packem_chunks/ExportImportPanel.js +1 -1
  8. package/dist/packem_chunks/FileBrowser.js +1 -1
  9. package/dist/packem_chunks/FunctionRunner.js +1 -1
  10. package/dist/packem_chunks/FunctionStatsPanel.js +1 -1
  11. package/dist/packem_chunks/HealthPanel.js +1 -1
  12. package/dist/packem_chunks/InsightsPanel.js +1 -1
  13. package/dist/packem_chunks/LogsPanel.js +1 -1
  14. package/dist/packem_chunks/MailPanel.js +1 -1
  15. package/dist/packem_chunks/MetricsPanel.js +1 -1
  16. package/dist/packem_chunks/NotificationsPanel.js +1 -1
  17. package/dist/packem_chunks/PitrPanel.js +1 -1
  18. package/dist/packem_chunks/SchemaViewer.js +1 -1
  19. package/dist/packem_chunks/SecurityAdvisorPanel.js +1 -1
  20. package/dist/packem_chunks/SettingsPanel.js +1 -1
  21. package/dist/packem_chunks/SqlEditorPanel.js +1 -1
  22. package/dist/packem_chunks/TableEditor.js +1 -1
  23. package/dist/packem_chunks/agents-panel.js +1 -1
  24. package/dist/packem_chunks/analytics-panel.js +1 -1
  25. package/dist/packem_chunks/auth-audit-panel.js +1 -1
  26. package/dist/packem_chunks/auth-config-panel.js +1 -1
  27. package/dist/packem_chunks/auth-sessions-panel.js +1 -1
  28. package/dist/packem_chunks/containers-panel.js +1 -1
  29. package/dist/packem_chunks/dashboards-panel.js +1 -1
  30. package/dist/packem_chunks/evals-panel.js +1 -1
  31. package/dist/packem_chunks/fanout-panel.js +1 -1
  32. package/dist/packem_chunks/flags-panel.js +1 -1
  33. package/dist/packem_chunks/issues-panel.js +1 -1
  34. package/dist/packem_chunks/kv-browser.js +1 -1
  35. package/dist/packem_chunks/log-drains-panel.js +1 -1
  36. package/dist/packem_chunks/migrations-route.js +1 -1
  37. package/dist/packem_chunks/organizations-panel.js +1 -1
  38. package/dist/packem_chunks/payments-panel.js +1 -1
  39. package/dist/packem_chunks/permissions-panel.js +1 -1
  40. package/dist/packem_chunks/queues-panel.js +1 -1
  41. package/dist/packem_chunks/rls-panel.js +1 -1
  42. package/dist/packem_chunks/schedule-panel.js +1 -1
  43. package/dist/packem_chunks/storage-rules-panel.js +1 -1
  44. package/dist/packem_chunks/subscriptions-panel.js +1 -1
  45. package/dist/packem_chunks/sync-client-panel.js +1 -1
  46. package/dist/packem_chunks/traces-panel.js +1 -1
  47. package/dist/packem_chunks/users-panel.js +1 -1
  48. package/dist/packem_chunks/vector-browser.js +1 -1
  49. package/dist/packem_chunks/workflows-panel.js +1 -1
  50. package/dist/packem_shared/{ApiDocsPanel-BL5lMig5.js → ApiDocsPanel-C_dZt4ve.js} +1 -1
  51. package/dist/packem_shared/{ApiReferencePanel-CkCFMCBb.js → ApiReferencePanel-6W_QfOlv.js} +1 -1
  52. package/dist/packem_shared/{CommandPalette-B5yLEABs.js → CommandPalette-BAiOc1hT.js} +1 -1
  53. package/dist/packem_shared/{DataBrowser-BnDIFN-S.js → DataBrowser-CrkvQAMf.js} +1 -1
  54. package/dist/packem_shared/{GlobalDataBrowser-DusjXzRF.js → GlobalDataBrowser-BHFgEqMl.js} +1 -1
  55. package/dist/packem_shared/{HomePanel-BcaHVBJh.js → HomePanel-B8U_LJkK.js} +1 -1
  56. package/dist/packem_shared/{MigrationsPanel-CCOENX4X.js → MigrationsPanel-CW4MNUa4.js} +1 -1
  57. package/dist/packem_shared/{OpenRpcReferencePanel-21OWMH45.js → OpenRpcReferencePanel-Cx-qwpZW.js} +1 -1
  58. package/dist/packem_shared/{ScheduledJobs-CiO3eXgI.js → ScheduledJobs-DRmOKtDa.js} +1 -1
  59. package/dist/packem_shared/Studio-k_HuJZYW.js +1 -0
  60. package/dist/packem_shared/{StudioApp-DCdbsciH.js → StudioApp-CWpwayvp.js} +1 -1
  61. package/dist/packem_shared/{advisor-view-C1KFTXSH.js → advisor-view-CqCG22DB.js} +1 -1
  62. package/dist/packem_shared/{data-grid-BFTQnkXq.js → data-grid-pjv4t5Yi.js} +1 -1
  63. package/dist/packem_shared/{error-alert-TYdKetJd.js → error-alert-CKqB2CiN.js} +1 -1
  64. package/dist/packem_shared/{grid-features-C_yXlMc_.js → grid-features-3wfN2PeE.js} +4 -4
  65. package/dist/packem_shared/{home-panel-BiJHXeDC.js → home-panel-DywiFhDs.js} +1 -1
  66. package/dist/packem_shared/{internal-CwaF9YNk.js → internal-7bgd8inO.js} +1 -1
  67. package/dist/packem_shared/{log-line-UnE93Ovi.js → log-line-D0XBZaDn.js} +1 -1
  68. package/dist/packem_shared/{recording-client-CKn4-vUx.js → recording-client-BPY8sYUl.js} +1 -1
  69. package/dist/packem_shared/{reference-view-CUIDzLf0.js → reference-view-DhxnzBtf.js} +1 -1
  70. package/dist/packem_shared/{result-chart-Ca3YLzt8.js → result-chart-Q-gVLi4_.js} +1 -1
  71. package/dist/packem_shared/{schema-diagram-DHD13TjS.js → schema-diagram-CPcjPZj3.js} +1 -1
  72. package/dist/packem_shared/{studio-B3eEcBK0.js → studio-BFvT56qK.js} +1 -1
  73. package/dist/packem_shared/{table-list-sidebar-Bluzd1_2.js → table-list-sidebar-BCxqrZ0s.js} +1 -1
  74. package/dist/packem_shared/{use-admin-query-P0RJrjsD.js → use-admin-query-DV9xmFl8.js} +1 -1
  75. package/dist/packem_shared/{use-async-submit-DdLd0MdK.js → use-async-submit-C9xXjXWX.js} +1 -1
  76. package/dist/packem_shared/{use-auth-config-z3KRWAqD.js → use-auth-config-DIAyVsa3.js} +1 -1
  77. package/dist/packem_shared/{use-open-trace-4tIa0SXZ.js → use-open-trace-IfIlKEWd.js} +1 -1
  78. package/dist/packem_shared/{use-sql-assistant-CP90nLLh.js → use-sql-assistant-DFO2i-n-.js} +1 -1
  79. package/dist/standalone/chunk-22WJHOC4.js +11 -0
  80. package/dist/standalone/{chunk-ZN6KUP3O.js → chunk-2CHFHPR3.js} +1 -1
  81. package/dist/standalone/{chunk-OG57FC7W.js → chunk-2EJQ7SPV.js} +1 -1
  82. package/dist/standalone/{chunk-FSWPREH3.js → chunk-2Q7HAFRK.js} +1 -1
  83. package/dist/standalone/{chunk-44WNSIGQ.js → chunk-2UIT2HC2.js} +1 -1
  84. package/dist/standalone/{chunk-YUWMB6EV.js → chunk-2UWKGSEA.js} +1 -1
  85. package/dist/standalone/{chunk-ZQLIKKIY.js → chunk-3IXTF53Q.js} +1 -1
  86. package/dist/standalone/{chunk-J6MNOKO5.js → chunk-44FJEOAY.js} +1 -1
  87. package/dist/standalone/{chunk-26VREVWU.js → chunk-5XMZP64Z.js} +1 -1
  88. package/dist/standalone/{chunk-45YWYMD5.js → chunk-6MRGARL5.js} +1 -1
  89. package/dist/standalone/{chunk-3F5I435D.js → chunk-6UOC4ZJL.js} +1 -1
  90. package/dist/standalone/{chunk-FBAZHG35.js → chunk-6ZSAMAYN.js} +1 -1
  91. package/dist/standalone/{chunk-BORG7WUC.js → chunk-7IQT5M4O.js} +1 -1
  92. package/dist/standalone/{chunk-KQIHXYE6.js → chunk-7TFEJVX4.js} +1 -1
  93. package/dist/standalone/{chunk-3QB5JI32.js → chunk-7W6TQTW7.js} +1 -1
  94. package/dist/standalone/{chunk-4MAJFNON.js → chunk-A7WKYEQ4.js} +1 -1
  95. package/dist/standalone/chunk-AG265V66.js +1 -0
  96. package/dist/standalone/{chunk-6SAAMM4S.js → chunk-BE76GAFE.js} +1 -1
  97. package/dist/standalone/{chunk-6ZPTNC34.js → chunk-BKM6PMSO.js} +1 -1
  98. package/dist/standalone/{chunk-D7DUQS2Y.js → chunk-CE7WVPLK.js} +1 -1
  99. package/dist/standalone/{chunk-MSFUDXBA.js → chunk-D4HJ2VM2.js} +1 -1
  100. package/dist/standalone/{chunk-FLCK2WWQ.js → chunk-DC5AAWSA.js} +1 -1
  101. package/dist/standalone/{chunk-6NJAHOGO.js → chunk-DEGERMXH.js} +1 -1
  102. package/dist/standalone/{chunk-JURAVSE7.js → chunk-E6P2ERQV.js} +1 -1
  103. package/dist/standalone/{chunk-TLPWZ5NI.js → chunk-EQSVW6LZ.js} +1 -1
  104. package/dist/standalone/{chunk-T2LDA6WP.js → chunk-FCEPVFIJ.js} +1 -1
  105. package/dist/standalone/chunk-FEEZPSMA.js +1 -0
  106. package/dist/standalone/{chunk-25OIGX2A.js → chunk-FEW2WNS7.js} +1 -1
  107. package/dist/standalone/{chunk-KFZ37KQP.js → chunk-FRSTZO5P.js} +1 -1
  108. package/dist/standalone/{chunk-X6Q5DWLZ.js → chunk-GKHUQDVI.js} +1 -1
  109. package/dist/standalone/{chunk-SL5R7WBN.js → chunk-H2WBIULE.js} +1 -1
  110. package/dist/standalone/{chunk-WIG3HCUJ.js → chunk-H3M57MCN.js} +1 -1
  111. package/dist/standalone/{chunk-UIF57LBO.js → chunk-H4SLAZAN.js} +1 -1
  112. package/dist/standalone/{chunk-6FWN26RH.js → chunk-HLEXBOCL.js} +1 -1
  113. package/dist/standalone/{chunk-QZ55OWAB.js → chunk-HLHO5AHK.js} +1 -1
  114. package/dist/standalone/{chunk-MOUI44OT.js → chunk-INLHZKCS.js} +1 -1
  115. package/dist/standalone/{chunk-L7CJ5PGH.js → chunk-JACBQWRB.js} +1 -1
  116. package/dist/standalone/{chunk-YS7HEZC2.js → chunk-KEMHRM53.js} +1 -1
  117. package/dist/standalone/{chunk-GIRZD3UB.js → chunk-KOH52XKG.js} +1 -1
  118. package/dist/standalone/{chunk-C5E5PLJT.js → chunk-LDVDE3LE.js} +1 -1
  119. package/dist/standalone/{chunk-3RYEUXY2.js → chunk-LFEDP3Y6.js} +1 -1
  120. package/dist/standalone/{chunk-V6QPVFDL.js → chunk-MG7VPUFA.js} +1 -1
  121. package/dist/standalone/{chunk-OE4KGVJW.js → chunk-MLYZZD5C.js} +1 -1
  122. package/dist/standalone/{chunk-WHRG6S5P.js → chunk-NSR345ID.js} +1 -1
  123. package/dist/standalone/{chunk-IWNVQHF7.js → chunk-OAXOITHK.js} +1 -1
  124. package/dist/standalone/chunk-OQS4HFKC.js +1 -0
  125. package/dist/standalone/{chunk-XGIG4EDG.js → chunk-OTZRXUHF.js} +1 -1
  126. package/dist/standalone/{chunk-PJDKRUWT.js → chunk-PNLUMMXO.js} +1 -1
  127. package/dist/standalone/{chunk-AOE75NAT.js → chunk-Q2G22JHG.js} +1 -1
  128. package/dist/standalone/{chunk-BELLXCN7.js → chunk-RUIWLLAI.js} +1 -1
  129. package/dist/standalone/{chunk-S77D4SHR.js → chunk-RVQRXKRJ.js} +1 -1
  130. package/dist/standalone/{chunk-JVAYDDMK.js → chunk-SCXAZ74Y.js} +1 -1
  131. package/dist/standalone/{chunk-2DC6F7NH.js → chunk-SLOB2B2T.js} +1 -1
  132. package/dist/standalone/{chunk-LT4XQDD2.js → chunk-SM764GPA.js} +1 -1
  133. package/dist/standalone/{chunk-5T7KRUPX.js → chunk-U2KBAKZ6.js} +1 -1
  134. package/dist/standalone/chunk-U7J3LXJ4.js +6 -0
  135. package/dist/standalone/{chunk-KEKIGANB.js → chunk-UCA5MYCL.js} +1 -1
  136. package/dist/standalone/{chunk-GPP4VSUO.js → chunk-UJXKS27L.js} +1 -1
  137. package/dist/standalone/{chunk-C7E4I7JZ.js → chunk-UKIDHICQ.js} +1 -1
  138. package/dist/standalone/{chunk-5NRQIDQA.js → chunk-V2KCESII.js} +1 -1
  139. package/dist/standalone/{chunk-OOBJFXYB.js → chunk-W5CYX66B.js} +1 -1
  140. package/dist/standalone/{chunk-2BDM6HNL.js → chunk-WSNFV7ZW.js} +1 -1
  141. package/dist/standalone/{chunk-OLQWBGKT.js → chunk-YYFHDYYT.js} +1 -1
  142. package/dist/standalone/{chunk-PHHMPYEP.js → chunk-ZHDCWHRT.js} +1 -1
  143. package/dist/standalone/{chunk-CEPMQS24.js → chunk-ZIHYXKQJ.js} +1 -1
  144. package/dist/standalone/{chunk-DL3UOEWN.js → chunk-ZIYO55T2.js} +1 -1
  145. package/dist/standalone/{chunk-6JGXSMKV.js → chunk-ZNNKKJRT.js} +1 -1
  146. package/dist/standalone/studio.js +1 -1
  147. package/package.json +5 -5
  148. package/dist/packem_shared/Studio-CHmLCjBR.js +0 -1
  149. package/dist/standalone/chunk-GZMBMNL3.js +0 -6
  150. package/dist/standalone/chunk-RBUVNO22.js +0 -1
  151. package/dist/standalone/chunk-SMKRXJUC.js +0 -1
  152. package/dist/standalone/chunk-T6HLABZW.js +0 -1
  153. package/dist/standalone/chunk-TBXK3FKP.js +0 -11
@@ -1 +1 @@
1
- import{c as q}from"react/compiler-runtime";import{useVirtualizer as Ce}from"@tanstack/react-virtual";import{useState as F,useReducer as Le,useRef as ue,useEffect as me,useMemo as Ne}from"react";import{f as fe}from"../packem_shared/log-fields-SBxKyBug.js";import{E as Se}from"../packem_shared/error-alert-TYdKetJd.js";import{B as he}from"../packem_shared/badge-cAk9Di1Q.js";import{E as ee}from"../packem_shared/empty-state-B939z6K2.js";import{u as le}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{u as Te}from"../packem_shared/use-open-trace-4tIa0SXZ.js";import{u as Ie}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as Q}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{r as Re}from"../packem_shared/shard-history-QcjcMnCA.js";import{f as ke}from"../packem_shared/virtual-rect-D_j7aLxX.js";import{useLunora as Pe}from"@lunora/react";import{B as Ee}from"../packem_shared/button-BOPLD1un.js";import{I as D}from"../packem_shared/input-CY5W3wzv.js";import{T as Oe,a as _e,b as ge,c as B,d as Fe,e as V}from"../packem_shared/table-BMsuYFhk.js";import ae from"../packem_shared/useDebounced-DVeQ5-oW.js";import{a as pe}from"../packem_shared/cf-links-CBJ5SywP.js";import{f as ne,m as qe,b as ie}from"../packem_shared/internal-CwaF9YNk.js";import{a as Ae,L as Me}from"../packem_shared/log-line-UnE93Ovi.js";import{jsx as r,jsxs as E,Fragment as $e}from"react/jsx-runtime";import{c as H}from"../packem_shared/utils-bhneXptQ.js";import{L as Ue}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as Ke}from"../packem_shared/ShardInput-XumEzeT0.js";const re=["trace","debug","log","info","warn","error","fatal"],Be="LOG_ARCHIVE_NOT_CONFIGURED",Ve={cursor:void 0,error:null,loading:!1,notConfigured:!1,rows:null},De=(i,e)=>{switch(e.type){case"append":return{...i,cursor:e.cursor,error:null,loading:!1,rows:[...i.rows??[],...e.rows]};case"failed":return{cursor:void 0,error:e.message,loading:!1,notConfigured:!1,rows:null};case"loaded":return{cursor:e.cursor,error:null,loading:!1,notConfigured:!1,rows:e.rows};case"loading":return{...i,error:null,loading:!0,notConfigured:!1};case"notConfigured":return{cursor:void 0,error:null,loading:!1,notConfigured:!0,rows:null};case"pageFailed":return{...i,error:e.message,loading:!1};default:return i}},Qe=i=>{const e=q(33),{row:t}=i;let a;e[0]!==t.fields?(a=fe(t.fields),e[0]=t.fields,e[1]=a):a=e[1];const n=a,o=`lg-archive-row-${String(t.ts)}`;let d;e[2]!==t.ts?(d=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=d):d=e[3];let p;e[4]!==d?(p=r(V,{className:"tabular-nums whitespace-nowrap text-xs text-muted-foreground",children:d}),e[4]=d,e[5]=p):p=e[5];const m=Ae[t.level];let c;e[6]!==t.level||e[7]!==m?(c=r(V,{children:r(he,{variant:m,children:t.level})}),e[6]=t.level,e[7]=m,e[8]=c):c=e[8];let s;e[9]!==t.functionPath?(s=r(V,{className:"font-mono text-xs",children:t.functionPath}),e[9]=t.functionPath,e[10]=s):s=e[10];let f;e[11]!==t.message?(f=r("div",{className:"truncate",title:t.message,children:t.message}),e[11]=t.message,e[12]=f):f=e[12];let l;e[13]!==n?(l=n!==""&&r("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:n,children:n}),e[13]=n,e[14]=l):l=e[14];let u;e[15]!==f||e[16]!==l?(u=E(V,{className:"max-w-md",children:[f,l]}),e[15]=f,e[16]=l,e[17]=u):u=e[17];const h=t.traceId??"—";let v;e[18]!==h?(v=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:h}),e[18]=h,e[19]=v):v=e[19];const b=t.shardKey??"—";let y;e[20]!==b?(y=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:b}),e[20]=b,e[21]=y):y=e[21];const w=t.userId??"—";let x;e[22]!==w?(x=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:w}),e[22]=w,e[23]=x):x=e[23];let T;return e[24]!==u||e[25]!==v||e[26]!==y||e[27]!==x||e[28]!==o||e[29]!==p||e[30]!==c||e[31]!==s?(T=E(ge,{"data-testid":o,children:[p,c,s,u,v,y,x]}),e[24]=u,e[25]=v,e[26]=y,e[27]=x,e[28]=o,e[29]=p,e[30]=c,e[31]=s,e[32]=T):T=e[32],T},ze=({shardKey:i})=>{const e=Pe(),t=Q(),[a,n]=F(""),[o,d]=F(""),[p,m]=F(""),[{cursor:c,error:s,loading:f,notConfigured:l,rows:u},h]=Le(De,Ve),v=ae(a.trim(),400),b=ae(o.trim(),400),y={...v===""?{}:{functionPathPrefix:v},...p===""?{}:{minLevel:p},...i===""?{}:{shardKey:i},...b===""?{}:{userId:b}},w=JSON.stringify(y),x=ue(w);me(()=>{const g={cancelled:!1};return x.current=w,ne((async()=>{h({type:"loading"});try{const C=await e.queryLogArchive(y);g.cancelled||h({cursor:C.nextCursor,rows:C.rows,type:"loaded"})}catch(C){g.cancelled||h(qe(C)===Be?{type:"notConfigured"}:{message:ie(C),type:"failed"})}})()),()=>{g.cancelled=!0}},[e,w]);const T=async()=>{if(c===void 0)return;const g=w;h({type:"loading"});try{const C=await e.queryLogArchive({...y,cursor:c});x.current===g&&h({cursor:C.nextCursor,rows:C.rows,type:"append"})}catch(C){x.current===g&&h({message:ie(C),type:"pageFailed"})}},R=g=>{n(g.target.value)},N=g=>{d(g.target.value)},L=g=>{m(g.target.value)},S=()=>{ne(T())};return l?r(ee,{action:r("a",{className:"text-sm text-primary underline-offset-4 hover:underline",href:pe,rel:"noreferrer",target:"_blank",children:t("Open in Cloudflare")}),description:t("Wire pipelineLogSink to a Cloudflare Pipeline → R2 Data Catalog table and set R2_SQL_ACCOUNT_ID, R2_SQL_TOKEN, R2_SQL_BUCKET to browse the durable log archive here."),testId:"lg-archive-not-configured",title:t("Log archive not configured")}):E("div",{className:"flex flex-col gap-4","data-testid":"lg-archive",children:[E("div",{className:"flex flex-wrap items-center gap-2",children:[r(D,{"aria-label":t("Function path prefix"),className:"h-8 w-48","data-testid":"lg-archive-path",onChange:R,placeholder:t("function path…"),value:a}),r(D,{"aria-label":t("User id"),className:"h-8 w-40","data-testid":"lg-archive-user",onChange:N,placeholder:t("user id…"),value:o}),E("select",{"aria-label":t("Minimum level"),className:"h-8 rounded-md border border-border bg-background px-2 text-sm","data-testid":"lg-archive-min-level",onChange:L,value:p,children:[r("option",{value:"",children:t("min level")}),re.map(g=>r("option",{value:g,children:g},g))]})]}),s!==null&&r("p",{className:"text-sm text-destructive","data-testid":"lg-archive-error",role:"alert",children:s}),f&&u===null&&s===null&&r("p",{className:"text-sm text-muted-foreground","data-testid":"lg-archive-loading",children:t("Loading…")}),u!==null&&u.length===0&&r(ee,{description:t("No archived logs match these filters. The durable archive fills as pipelineLogSink flushes records to R2."),testId:"lg-archive-empty",title:t("No archived logs.")}),u!==null&&u.length>0&&r("div",{className:"overflow-hidden rounded-xl border border-border shadow-xs",children:E(Oe,{"data-testid":"lg-archive-table",children:[r(_e,{children:E(ge,{children:[r(B,{children:t("Time")}),r(B,{children:t("Level")}),r(B,{children:t("Function")}),r(B,{children:t("Message")}),r(B,{children:t("Trace")}),r(B,{children:t("Shard")}),r(B,{children:t("User")})]})}),r(Fe,{children:u.map((g,C)=>r(Qe,{row:g},`${String(g.ts)}-${String(C)}`))})]})}),c!==void 0&&r("div",{children:r(Ee,{"data-testid":"lg-archive-more",disabled:f,onClick:S,size:"sm",variant:"outline",children:t(f?"Loading…":"Load more")})})]})},Ge=i=>{const e=q(11),{level:t,onToggle:a,selected:n}=i;let o;e[0]!==t||e[1]!==a?(o=()=>{a(t)},e[0]=t,e[1]=a,e[2]=o):o=e[2];const d=o,p=n?"border-border bg-muted font-medium":"border-input text-muted-foreground";let m;e[3]!==p?(m=H("rounded-md border px-2 py-1 text-xs",p),e[3]=p,e[4]=m):m=e[4];const c=`logs-level-${t}`;let s;return e[5]!==t||e[6]!==d||e[7]!==n||e[8]!==m||e[9]!==c?(s=r("button",{"aria-pressed":n,className:m,"data-testid":c,onClick:d,type:"button",children:t}),e[5]=t,e[6]=d,e[7]=n,e[8]=m,e[9]=c,e[10]=s):s=e[10],s},He=i=>{const e=q(68),{levelFilter:t,onLogPathChange:a,onSearchChange:n,onTimeRangeChange:o,onToggleLevel:d,onToggleSummary:p,pathFilter:m,search:c,showSummary:s,timeRange:f}=i,l=Q();let u;e[0]!==l?(u=l("Search messages"),e[0]=l,e[1]=u):u=e[1];let h;e[2]!==l?(h=l("search message"),e[2]=l,e[3]=h):h=e[3];let v;e[4]!==n||e[5]!==c||e[6]!==u||e[7]!==h?(v=r(D,{"aria-label":u,className:"h-8 w-48","data-testid":"lg-search",onChange:n,placeholder:h,value:c}),e[4]=n,e[5]=c,e[6]=u,e[7]=h,e[8]=v):v=e[8];let b;e[9]!==l?(b=l("Function path"),e[9]=l,e[10]=b):b=e[10];let y;e[11]!==l?(y=l("filter path"),e[11]=l,e[12]=y):y=e[12];let w;e[13]!==a||e[14]!==m||e[15]!==b||e[16]!==y?(w=r(D,{"aria-label":b,className:"h-8 w-40","data-testid":"logs-path-filter",onChange:a,placeholder:y,value:m}),e[13]=a,e[14]=m,e[15]=b,e[16]=y,e[17]=w):w=e[17];let x;e[18]!==l?(x=l("Level filter"),e[18]=l,e[19]=x):x=e[19];let T;e[20]!==t||e[21]!==d?(T=re.map(G=>r(Ge,{level:G,onToggle:d,selected:t.has(G)},G)),e[20]=t,e[21]=d,e[22]=T):T=e[22];let R;e[23]!==x||e[24]!==T?(R=r("div",{"aria-label":x,className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:T}),e[23]=x,e[24]=T,e[25]=R):R=e[25];let N;e[26]!==l?(N=l("Time range"),e[26]=l,e[27]=N):N=e[27];let L;e[28]!==l?(L=l("All time"),e[28]=l,e[29]=L):L=e[29];let S;e[30]!==L?(S=r("option",{value:"all",children:L}),e[30]=L,e[31]=S):S=e[31];let g;e[32]!==l?(g=l("Last 5m"),e[32]=l,e[33]=g):g=e[33];let C;e[34]!==g?(C=r("option",{value:"5m",children:g}),e[34]=g,e[35]=C):C=e[35];let k;e[36]!==l?(k=l("Last 15m"),e[36]=l,e[37]=k):k=e[37];let P;e[38]!==k?(P=r("option",{value:"15m",children:k}),e[38]=k,e[39]=P):P=e[39];let O;e[40]!==l?(O=l("Last hour"),e[40]=l,e[41]=O):O=e[41];let _;e[42]!==O?(_=r("option",{value:"1h",children:O}),e[42]=O,e[43]=_):_=e[43];let A;e[44]!==o||e[45]!==N||e[46]!==S||e[47]!==C||e[48]!==P||e[49]!==_||e[50]!==f?(A=E("select",{"aria-label":N,className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"logs-time-range",onChange:o,value:f,children:[S,C,P,_]}),e[44]=o,e[45]=N,e[46]=S,e[47]=C,e[48]=P,e[49]=_,e[50]=f,e[51]=A):A=e[51];const z=s?"border-border bg-muted font-medium":"border-input text-muted-foreground";let M;e[52]!==z?(M=H("h-8 rounded-md border px-3 text-sm",z),e[52]=z,e[53]=M):M=e[53];let U;e[54]!==s||e[55]!==l?(U=l(s?"List":"Summary"),e[54]=s,e[55]=l,e[56]=U):U=e[56];let $;e[57]!==p||e[58]!==s||e[59]!==M||e[60]!==U?($=r("button",{"aria-pressed":s,className:M,"data-testid":"logs-summary-toggle",onClick:p,type:"button",children:U}),e[57]=p,e[58]=s,e[59]=M,e[60]=U,e[61]=$):$=e[61];let K;return e[62]!==A||e[63]!==$||e[64]!==v||e[65]!==w||e[66]!==R?(K=E("div",{className:"flex flex-wrap items-center gap-2",children:[v,w,R,A,$]}),e[62]=A,e[63]=$,e[64]=v,e[65]=w,e[66]=R,e[67]=K):K=e[67],K},We=i=>{const e=q(53),{onOutcomeChange:t,onPathChange:a,onTableChange:n,onUserChange:o,outcomeFilter:d,pathPrefix:p,tableFilter:m,userIdFilter:c}=i,s=Q();let f;e[0]!==s?(f=s("Function path"),e[0]=s,e[1]=f):f=e[1];let l;e[2]!==s?(l=s("file:function"),e[2]=s,e[3]=l):l=e[3];let u;e[4]!==a||e[5]!==p||e[6]!==f||e[7]!==l?(u=r(D,{"aria-label":f,className:"h-8 w-44","data-testid":"lg-req-path",onChange:a,placeholder:l,value:p}),e[4]=a,e[5]=p,e[6]=f,e[7]=l,e[8]=u):u=e[8];let h;e[9]!==s?(h=s("User id"),e[9]=s,e[10]=h):h=e[10];let v;e[11]!==s?(v=s("userId"),e[11]=s,e[12]=v):v=e[12];let b;e[13]!==o||e[14]!==h||e[15]!==v||e[16]!==c?(b=r(D,{"aria-label":h,className:"h-8 w-32","data-testid":"lg-req-user",onChange:o,placeholder:v,value:c}),e[13]=o,e[14]=h,e[15]=v,e[16]=c,e[17]=b):b=e[17];let y;e[18]!==s?(y=s("Table touched"),e[18]=s,e[19]=y):y=e[19];let w;e[20]!==s?(w=s("table"),e[20]=s,e[21]=w):w=e[21];let x;e[22]!==n||e[23]!==y||e[24]!==w||e[25]!==m?(x=r(D,{"aria-label":y,className:"h-8 w-32","data-testid":"lg-req-table",onChange:n,placeholder:w,value:m}),e[22]=n,e[23]=y,e[24]=w,e[25]=m,e[26]=x):x=e[26];let T;e[27]!==s?(T=s("Outcome filter"),e[27]=s,e[28]=T):T=e[28];let R;e[29]!==s?(R=s("all"),e[29]=s,e[30]=R):R=e[30];let N;e[31]!==R?(N=r("option",{value:"all",children:R}),e[31]=R,e[32]=N):N=e[32];let L;e[33]!==s?(L=s("ok"),e[33]=s,e[34]=L):L=e[34];let S;e[35]!==L?(S=r("option",{value:"ok",children:L}),e[35]=L,e[36]=S):S=e[36];let g;e[37]!==s?(g=s("error"),e[37]=s,e[38]=g):g=e[38];let C;e[39]!==g?(C=r("option",{value:"error",children:g}),e[39]=g,e[40]=C):C=e[40];let k;e[41]!==t||e[42]!==d||e[43]!==T||e[44]!==N||e[45]!==S||e[46]!==C?(k=E("select",{"aria-label":T,className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"lg-req-outcome",onChange:t,value:d,children:[N,S,C]}),e[41]=t,e[42]=d,e[43]=T,e[44]=N,e[45]=S,e[46]=C,e[47]=k):k=e[47];let P;return e[48]!==k||e[49]!==u||e[50]!==b||e[51]!==x?(P=E("div",{className:"flex flex-wrap items-center gap-2",children:[u,b,x,k]}),e[48]=k,e[49]=u,e[50]=b,e[51]=x,e[52]=P):P=e[52],P},ve=i=>{const e=q(7),{bucket:t}=i;let a;e[0]!==t.key?(a=r("span",{className:"truncate text-muted-foreground",role:"gridcell",children:t.key}),e[0]=t.key,e[1]=a):a=e[1];let n;e[2]!==t.count?(n=r("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:t.count}),e[2]=t.count,e[3]=n):n=e[3];let o;return e[4]!==a||e[5]!==n?(o=E("div",{className:"flex items-center justify-between gap-4 px-3 py-1 font-mono text-xs","data-testid":"logs-summary-row",role:"row",children:[a,n]}),e[4]=a,e[5]=n,e[6]=o):o=e[6],o},Ye=i=>{const e=q(31),{summary:t}=i,a=Q();let n;e[0]!==t.total||e[1]!==a?(n=a("{count} entries",{count:t.total}),e[0]=t.total,e[1]=a,e[2]=n):n=e[2];let o;e[3]!==n?(o=r("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:n}),e[3]=n,e[4]=o):o=e[4];let d;e[5]!==a?(d=a("By level"),e[5]=a,e[6]=d):d=e[6];let p;e[7]!==d?(p=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d}),e[7]=d,e[8]=p):p=e[8];let m;e[9]!==t.byLevel?(m=t.byLevel.map(je),e[9]=t.byLevel,e[10]=m):m=e[10];let c;e[11]!==m?(c=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:m}),e[11]=m,e[12]=c):c=e[12];let s;e[13]!==p||e[14]!==c?(s=E("div",{children:[p,c]}),e[13]=p,e[14]=c,e[15]=s):s=e[15];let f;e[16]!==a?(f=a("By function"),e[16]=a,e[17]=f):f=e[17];let l;e[18]!==f?(l=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:f}),e[18]=f,e[19]=l):l=e[19];let u;e[20]!==t.byPath?(u=t.byPath.map(Je),e[20]=t.byPath,e[21]=u):u=e[21];let h;e[22]!==u?(h=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:u}),e[22]=u,e[23]=h):h=e[23];let v;e[24]!==h||e[25]!==l?(v=E("div",{children:[l,h]}),e[24]=h,e[25]=l,e[26]=v):v=e[26];let b;return e[27]!==v||e[28]!==o||e[29]!==s?(b=E("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[o,s,v]}),e[27]=v,e[28]=o,e[29]=s,e[30]=b):b=e[30],b};function je(i){return r(ve,{bucket:i},i.key)}function Je(i){return r(ve,{bucket:i},i.key)}const Xe=i=>{const e=q(46),{liveError:t,onShardKeyChange:a,onShowArchive:n,onShowErrors:o,onShowRequests:d,shardKey:p,view:m}=i,c=Q(),s=m==="requests",f=m==="requests"?"bg-muted font-medium":"text-muted-foreground";let l;e[0]!==f?(l=H("px-3 py-1 text-sm",f),e[0]=f,e[1]=l):l=e[1];let u;e[2]!==c?(u=c("Requests"),e[2]=c,e[3]=u):u=e[3];let h;e[4]!==d||e[5]!==s||e[6]!==l||e[7]!==u?(h=r("button",{"aria-selected":s,className:l,"data-testid":"lg-view-requests",onClick:d,role:"tab",type:"button",children:u}),e[4]=d,e[5]=s,e[6]=l,e[7]=u,e[8]=h):h=e[8];const v=m==="errors",b=m==="errors"?"bg-muted font-medium":"text-muted-foreground";let y;e[9]!==b?(y=H("px-3 py-1 text-sm",b),e[9]=b,e[10]=y):y=e[10];let w;e[11]!==c?(w=c("Errors"),e[11]=c,e[12]=w):w=e[12];let x;e[13]!==o||e[14]!==v||e[15]!==y||e[16]!==w?(x=r("button",{"aria-selected":v,className:y,"data-testid":"lg-view-errors",onClick:o,role:"tab",type:"button",children:w}),e[13]=o,e[14]=v,e[15]=y,e[16]=w,e[17]=x):x=e[17];const T=m==="archive",R=m==="archive"?"bg-muted font-medium":"text-muted-foreground";let N;e[18]!==R?(N=H("px-3 py-1 text-sm",R),e[18]=R,e[19]=N):N=e[19];let L;e[20]!==c?(L=c("Archive"),e[20]=c,e[21]=L):L=e[21];let S;e[22]!==n||e[23]!==T||e[24]!==N||e[25]!==L?(S=r("button",{"aria-selected":T,className:N,"data-testid":"lg-view-archive",onClick:n,role:"tab",type:"button",children:L}),e[22]=n,e[23]=T,e[24]=N,e[25]=L,e[26]=S):S=e[26];let g;e[27]!==x||e[28]!==S||e[29]!==h?(g=E("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[h,x,S]}),e[27]=x,e[28]=S,e[29]=h,e[30]=g):g=e[30];let C;e[31]!==a||e[32]!==p?(C=r(Ke,{onChange:a,testId:"lg-shard-input",value:p}),e[31]=a,e[32]=p,e[33]=C):C=e[33];let k;e[34]!==t||e[35]!==m?(k=m!=="archive"&&r(Ue,{message:t,prefix:"lg"}),e[34]=t,e[35]=m,e[36]=k):k=e[36];let P;e[37]!==c?(P=c("Open in Cloudflare"),e[37]=c,e[38]=P):P=e[38];let O;e[39]!==P?(O=r("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:pe,rel:"noreferrer",target:"_blank",children:P}),e[39]=P,e[40]=O):O=e[40];let _;return e[41]!==g||e[42]!==C||e[43]!==k||e[44]!==O?(_=E("div",{className:"flex flex-wrap items-center gap-2",children:[g,C,k,O]}),e[41]=g,e[42]=C,e[43]=k,e[44]=O,e[45]=_):_=e[45],_},te=400,Ze=36,et={height:te,overflow:"auto"},be={left:0,position:"absolute",top:0,width:"100%"},tt={error:"destructive",ok:"secondary"},xe=i=>{const e=q(6),{onOpenTrace:t,traceId:a}=i,n=Q();let o;e[0]!==t||e[1]!==n||e[2]!==a?(o=a===void 0?null:r("button",{className:"text-primary underline-offset-2 hover:underline","data-testid":"lg-trace-link",onClick:()=>{t(a)},type:"button",children:n("Trace")}),e[0]=t,e[1]=n,e[2]=a,e[3]=o):o=e[3];let d;return e[4]!==o?(d=r("span",{className:"w-16 shrink-0 text-right",role:"gridcell",children:o}),e[4]=o,e[5]=d):d=e[5],d},rt=i=>{const e=q(13),{entry:t,index:a,measureRef:n,onOpenTrace:o,start:d}=i,p=`translateY(${String(d)}px)`;let m;e[0]!==p?(m={...be,transform:p},e[0]=p,e[1]=m):m=e[1];const c=m;let s;e[2]!==t?(s=r(Me,{entry:t}),e[2]=t,e[3]=s):s=e[3];let f;e[4]!==t.traceId||e[5]!==o?(f=r(xe,{onOpenTrace:o,traceId:t.traceId}),e[4]=t.traceId,e[5]=o,e[6]=f):f=e[6];let l;return e[7]!==a||e[8]!==n||e[9]!==c||e[10]!==s||e[11]!==f?(l=E("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":a,"data-testid":"lg-row",ref:n,role:"row",style:c,children:[s,f]}),e[7]=a,e[8]=n,e[9]=c,e[10]=s,e[11]=f,e[12]=l):l=e[12],l},ce=i=>i.length===0?"—":i.join(", "),st=i=>{const e=q(41),{entry:t,index:a,measureRef:n,onOpenTrace:o,start:d}=i,p=`translateY(${String(d)}px)`;let m;e[0]!==p?(m={...be,transform:p},e[0]=p,e[1]=m):m=e[1];const c=m;let s;e[2]!==t.ts?(s=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=s):s=e[3];let f;e[4]!==s?(f=r("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:s}),e[4]=s,e[5]=f):f=e[5];const l=tt[t.outcome];let u;e[6]!==t.outcome||e[7]!==l?(u=r("span",{className:"w-16 shrink-0",role:"gridcell",children:r(he,{variant:l,children:t.outcome})}),e[6]=t.outcome,e[7]=l,e[8]=u):u=e[8];let h;e[9]!==t.functionPath?(h=r("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:t.functionPath,children:t.functionPath}),e[9]=t.functionPath,e[10]=h):h=e[10];const v=t.shardKey??"—";let b;e[11]!==v?(b=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:v}),e[11]=v,e[12]=b):b=e[12];const y=t.userId??"—";let w;e[13]!==y?(w=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:y}),e[13]=y,e[14]=w):w=e[14];let x;e[15]!==t.durationMs?(x=Math.round(t.durationMs),e[15]=t.durationMs,e[16]=x):x=e[16];const T=`${String(x)}ms`;let R;e[17]!==T?(R=r("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:T}),e[17]=T,e[18]=R):R=e[18];let N;e[19]!==t.errorMessage||e[20]!==t.outcome||e[21]!==t.tablesRead||e[22]!==t.tablesWritten?(N=t.outcome==="error"&&t.errorMessage!==void 0?t.errorMessage:`r:${ce(t.tablesRead)} · w:${ce(t.tablesWritten)}`,e[19]=t.errorMessage,e[20]=t.outcome,e[21]=t.tablesRead,e[22]=t.tablesWritten,e[23]=N):N=e[23];let L;e[24]!==N?(L=r("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:N}),e[24]=N,e[25]=L):L=e[25];let S;e[26]!==t.traceId||e[27]!==o?(S=r(xe,{onOpenTrace:o,traceId:t.traceId}),e[26]=t.traceId,e[27]=o,e[28]=S):S=e[28];let g;return e[29]!==a||e[30]!==n||e[31]!==c||e[32]!==w||e[33]!==R||e[34]!==L||e[35]!==S||e[36]!==f||e[37]!==u||e[38]!==h||e[39]!==b?(g=E("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":a,"data-testid":"lg-req-row",ref:n,role:"row",style:c,children:[f,u,h,b,w,R,L,S]}),e[29]=a,e[30]=n,e[31]=c,e[32]=w,e[33]=R,e[34]=L,e[35]=S,e[36]=f,e[37]=u,e[38]=h,e[39]=b,e[40]=g):g=e[40],g},de=i=>{const{entries:e}=i??{};return Array.isArray(e)?e:[]},lt=i=>{const e={};return i.functionPathPrefix.trim()!==""&&(e.functionPathPrefix=i.functionPathPrefix.trim()),i.userId.trim()!==""&&(e.userId=i.userId.trim()),i.tableTouched.trim()!==""&&(e.tableTouched=i.tableTouched.trim()),(i.outcome==="ok"||i.outcome==="error")&&(e.outcome=i.outcome),e},ot={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},at=(i,e)=>{const t=e.search.trim().toLowerCase(),a=e.path.trim().toLowerCase(),n=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-ot[e.range];return i.filter(o=>e.levels.size>0&&!e.levels.has(o.level)||o.timestamp<n||a!==""&&!(o.functionPath??"").toLowerCase().includes(a)?!1:t===""||o.message.toLowerCase().includes(t)||fe(o.fields).toLowerCase().includes(t))},nt="—",it=i=>{const e=new Map,t=new Map;for(const o of i){e.set(o.level,(e.get(o.level)??0)+1);const d=o.functionPath??nt;t.set(d,(t.get(d)??0)+1)}const a=re.filter(o=>e.has(o)).map(o=>({count:e.get(o)??0,key:o})),n=[...t.entries()].map(([o,d])=>({count:d,key:o})).toSorted((o,d)=>d.count===o.count?o.key.localeCompare(d.key):d.count-o.count);return{byLevel:a,byPath:n,total:i.length}},Wt=({initialShardKey:i})=>{const e=Q(),[t,a]=F("requests"),{queryShardKey:n,setShardKey:o,shardKey:d}=Ie(i),[p,m]=F(""),[c,s]=F(()=>new Set),[f,l]=F(""),[u,h]=F("all"),[v,b]=F(!1),[y,w]=F(""),[x,T]=F(""),[R,N]=F(""),[L,S]=F("all"),g=lt({functionPathPrefix:y,outcome:L,tableTouched:R,userId:x}),C=le(oe.getRequestLog,g,{enabled:t==="requests",live:!0,shardKey:n}),k=le(oe.getLogs,{},{enabled:t==="errors",live:!0,shardKey:n}),P=t==="requests"?C:k,{error:O,errorSource:_,isLoading:A,liveError:z}=P,M=Te(n),U=de(k.data),$=de(C.data);me(()=>{P.data!==void 0&&Re(n)},[P.data,n]);const K=at(U,{levels:c,now:Date.now(),path:f,range:u,search:p}),G=it(K),J=t==="requests"?$.length:K.length,X=t==="errors"&&v,W=Ne(()=>O!==null?"error":J===0?A?X?"summary":"list":"empty":X?"summary":"list",[J,A,O,X]),se=ue(null),Y=Ce({count:J,estimateSize:()=>Ze,getScrollElement:()=>se.current,initialRect:{height:te,width:800},observeElementRect:(I,Z)=>ke(I,Z,te),overscan:8}),ye=Y.getVirtualItems(),we={height:Y.getTotalSize(),position:"relative",width:"100%"};return E("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[r(Xe,{liveError:z,onShardKeyChange:o,onShowArchive:()=>{a("archive"),b(!1)},onShowErrors:()=>{a("errors"),b(!1)},onShowRequests:()=>{a("requests"),b(!1)},shardKey:d,view:t}),t==="errors"&&r(He,{levelFilter:c,onLogPathChange:I=>{l(I.target.value)},onSearchChange:I=>{m(I.target.value)},onTimeRangeChange:I=>{h(I.target.value)},onToggleLevel:I=>{s(Z=>{const j=new Set(Z);return j.has(I)?j.delete(I):j.add(I),j})},onToggleSummary:()=>{b(I=>!I)},pathFilter:f,search:p,showSummary:v,timeRange:u}),t==="requests"&&r(We,{onOutcomeChange:I=>{S(I.target.value)},onPathChange:I=>{w(I.target.value)},onTableChange:I=>{N(I.target.value)},onUserChange:I=>{T(I.target.value)},outcomeFilter:L,pathPrefix:y,tableFilter:R,userIdFilter:x}),t==="archive"?r(ze,{shardKey:n}):E($e,{children:[W==="error"&&r(Se,{error:_,testId:"lg-error"}),W==="empty"&&r(ee,{description:e("Function and request logs for this shard show up here as your app handles traffic."),icon:r("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:r("path",{d:"M4 5h16M4 12h16M4 19h10"})}),testId:"lg-empty",title:e("No logs.")}),W==="summary"&&r(Ye,{summary:G}),W==="list"&&r("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:se,style:et,children:r("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:we,children:ye.map(I=>t==="requests"?r(st,{entry:$[I.index],index:I.index,measureRef:Y.measureElement,onOpenTrace:M,start:I.start},I.key):r(rt,{entry:K[I.index],index:I.index,measureRef:Y.measureElement,onOpenTrace:M,start:I.start},I.key))})})]})]})};export{Wt as LogsPanel,at as filterLogs,it as summarizeLogs};
1
+ import{c as q}from"react/compiler-runtime";import{useVirtualizer as Ce}from"@tanstack/react-virtual";import{useState as F,useReducer as Le,useRef as ue,useEffect as me,useMemo as Ne}from"react";import{f as fe}from"../packem_shared/log-fields-SBxKyBug.js";import{E as Se}from"../packem_shared/error-alert-CKqB2CiN.js";import{B as he}from"../packem_shared/badge-cAk9Di1Q.js";import{E as ee}from"../packem_shared/empty-state-B939z6K2.js";import{u as le}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{u as Te}from"../packem_shared/use-open-trace-IfIlKEWd.js";import{u as Ie}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as Q}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{r as Re}from"../packem_shared/shard-history-QcjcMnCA.js";import{f as ke}from"../packem_shared/virtual-rect-D_j7aLxX.js";import{useLunora as Pe}from"@lunora/react";import{B as Ee}from"../packem_shared/button-BOPLD1un.js";import{I as D}from"../packem_shared/input-CY5W3wzv.js";import{T as Oe,a as _e,b as ge,c as B,d as Fe,e as V}from"../packem_shared/table-BMsuYFhk.js";import ae from"../packem_shared/useDebounced-DVeQ5-oW.js";import{a as pe}from"../packem_shared/cf-links-CBJ5SywP.js";import{f as ne,m as qe,b as ie}from"../packem_shared/internal-7bgd8inO.js";import{a as Ae,L as Me}from"../packem_shared/log-line-D0XBZaDn.js";import{jsx as r,jsxs as E,Fragment as $e}from"react/jsx-runtime";import{c as H}from"../packem_shared/utils-bhneXptQ.js";import{L as Ue}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as Ke}from"../packem_shared/ShardInput-XumEzeT0.js";const re=["trace","debug","log","info","warn","error","fatal"],Be="LOG_ARCHIVE_NOT_CONFIGURED",Ve={cursor:void 0,error:null,loading:!1,notConfigured:!1,rows:null},De=(i,e)=>{switch(e.type){case"append":return{...i,cursor:e.cursor,error:null,loading:!1,rows:[...i.rows??[],...e.rows]};case"failed":return{cursor:void 0,error:e.message,loading:!1,notConfigured:!1,rows:null};case"loaded":return{cursor:e.cursor,error:null,loading:!1,notConfigured:!1,rows:e.rows};case"loading":return{...i,error:null,loading:!0,notConfigured:!1};case"notConfigured":return{cursor:void 0,error:null,loading:!1,notConfigured:!0,rows:null};case"pageFailed":return{...i,error:e.message,loading:!1};default:return i}},Qe=i=>{const e=q(33),{row:t}=i;let a;e[0]!==t.fields?(a=fe(t.fields),e[0]=t.fields,e[1]=a):a=e[1];const n=a,o=`lg-archive-row-${String(t.ts)}`;let d;e[2]!==t.ts?(d=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=d):d=e[3];let p;e[4]!==d?(p=r(V,{className:"tabular-nums whitespace-nowrap text-xs text-muted-foreground",children:d}),e[4]=d,e[5]=p):p=e[5];const m=Ae[t.level];let c;e[6]!==t.level||e[7]!==m?(c=r(V,{children:r(he,{variant:m,children:t.level})}),e[6]=t.level,e[7]=m,e[8]=c):c=e[8];let s;e[9]!==t.functionPath?(s=r(V,{className:"font-mono text-xs",children:t.functionPath}),e[9]=t.functionPath,e[10]=s):s=e[10];let f;e[11]!==t.message?(f=r("div",{className:"truncate",title:t.message,children:t.message}),e[11]=t.message,e[12]=f):f=e[12];let l;e[13]!==n?(l=n!==""&&r("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:n,children:n}),e[13]=n,e[14]=l):l=e[14];let u;e[15]!==f||e[16]!==l?(u=E(V,{className:"max-w-md",children:[f,l]}),e[15]=f,e[16]=l,e[17]=u):u=e[17];const h=t.traceId??"—";let v;e[18]!==h?(v=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:h}),e[18]=h,e[19]=v):v=e[19];const b=t.shardKey??"—";let y;e[20]!==b?(y=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:b}),e[20]=b,e[21]=y):y=e[21];const w=t.userId??"—";let x;e[22]!==w?(x=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:w}),e[22]=w,e[23]=x):x=e[23];let T;return e[24]!==u||e[25]!==v||e[26]!==y||e[27]!==x||e[28]!==o||e[29]!==p||e[30]!==c||e[31]!==s?(T=E(ge,{"data-testid":o,children:[p,c,s,u,v,y,x]}),e[24]=u,e[25]=v,e[26]=y,e[27]=x,e[28]=o,e[29]=p,e[30]=c,e[31]=s,e[32]=T):T=e[32],T},ze=({shardKey:i})=>{const e=Pe(),t=Q(),[a,n]=F(""),[o,d]=F(""),[p,m]=F(""),[{cursor:c,error:s,loading:f,notConfigured:l,rows:u},h]=Le(De,Ve),v=ae(a.trim(),400),b=ae(o.trim(),400),y={...v===""?{}:{functionPathPrefix:v},...p===""?{}:{minLevel:p},...i===""?{}:{shardKey:i},...b===""?{}:{userId:b}},w=JSON.stringify(y),x=ue(w);me(()=>{const g={cancelled:!1};return x.current=w,ne((async()=>{h({type:"loading"});try{const C=await e.queryLogArchive(y);g.cancelled||h({cursor:C.nextCursor,rows:C.rows,type:"loaded"})}catch(C){g.cancelled||h(qe(C)===Be?{type:"notConfigured"}:{message:ie(C),type:"failed"})}})()),()=>{g.cancelled=!0}},[e,w]);const T=async()=>{if(c===void 0)return;const g=w;h({type:"loading"});try{const C=await e.queryLogArchive({...y,cursor:c});x.current===g&&h({cursor:C.nextCursor,rows:C.rows,type:"append"})}catch(C){x.current===g&&h({message:ie(C),type:"pageFailed"})}},R=g=>{n(g.target.value)},N=g=>{d(g.target.value)},L=g=>{m(g.target.value)},S=()=>{ne(T())};return l?r(ee,{action:r("a",{className:"text-sm text-primary underline-offset-4 hover:underline",href:pe,rel:"noreferrer",target:"_blank",children:t("Open in Cloudflare")}),description:t("Wire pipelineLogSink to a Cloudflare Pipeline → R2 Data Catalog table and set R2_SQL_ACCOUNT_ID, R2_SQL_TOKEN, R2_SQL_BUCKET to browse the durable log archive here."),testId:"lg-archive-not-configured",title:t("Log archive not configured")}):E("div",{className:"flex flex-col gap-4","data-testid":"lg-archive",children:[E("div",{className:"flex flex-wrap items-center gap-2",children:[r(D,{"aria-label":t("Function path prefix"),className:"h-8 w-48","data-testid":"lg-archive-path",onChange:R,placeholder:t("function path…"),value:a}),r(D,{"aria-label":t("User id"),className:"h-8 w-40","data-testid":"lg-archive-user",onChange:N,placeholder:t("user id…"),value:o}),E("select",{"aria-label":t("Minimum level"),className:"h-8 rounded-md border border-border bg-background px-2 text-sm","data-testid":"lg-archive-min-level",onChange:L,value:p,children:[r("option",{value:"",children:t("min level")}),re.map(g=>r("option",{value:g,children:g},g))]})]}),s!==null&&r("p",{className:"text-sm text-destructive","data-testid":"lg-archive-error",role:"alert",children:s}),f&&u===null&&s===null&&r("p",{className:"text-sm text-muted-foreground","data-testid":"lg-archive-loading",children:t("Loading…")}),u!==null&&u.length===0&&r(ee,{description:t("No archived logs match these filters. The durable archive fills as pipelineLogSink flushes records to R2."),testId:"lg-archive-empty",title:t("No archived logs.")}),u!==null&&u.length>0&&r("div",{className:"overflow-hidden rounded-xl border border-border shadow-xs",children:E(Oe,{"data-testid":"lg-archive-table",children:[r(_e,{children:E(ge,{children:[r(B,{children:t("Time")}),r(B,{children:t("Level")}),r(B,{children:t("Function")}),r(B,{children:t("Message")}),r(B,{children:t("Trace")}),r(B,{children:t("Shard")}),r(B,{children:t("User")})]})}),r(Fe,{children:u.map((g,C)=>r(Qe,{row:g},`${String(g.ts)}-${String(C)}`))})]})}),c!==void 0&&r("div",{children:r(Ee,{"data-testid":"lg-archive-more",disabled:f,onClick:S,size:"sm",variant:"outline",children:t(f?"Loading…":"Load more")})})]})},Ge=i=>{const e=q(11),{level:t,onToggle:a,selected:n}=i;let o;e[0]!==t||e[1]!==a?(o=()=>{a(t)},e[0]=t,e[1]=a,e[2]=o):o=e[2];const d=o,p=n?"border-border bg-muted font-medium":"border-input text-muted-foreground";let m;e[3]!==p?(m=H("rounded-md border px-2 py-1 text-xs",p),e[3]=p,e[4]=m):m=e[4];const c=`logs-level-${t}`;let s;return e[5]!==t||e[6]!==d||e[7]!==n||e[8]!==m||e[9]!==c?(s=r("button",{"aria-pressed":n,className:m,"data-testid":c,onClick:d,type:"button",children:t}),e[5]=t,e[6]=d,e[7]=n,e[8]=m,e[9]=c,e[10]=s):s=e[10],s},He=i=>{const e=q(68),{levelFilter:t,onLogPathChange:a,onSearchChange:n,onTimeRangeChange:o,onToggleLevel:d,onToggleSummary:p,pathFilter:m,search:c,showSummary:s,timeRange:f}=i,l=Q();let u;e[0]!==l?(u=l("Search messages"),e[0]=l,e[1]=u):u=e[1];let h;e[2]!==l?(h=l("search message"),e[2]=l,e[3]=h):h=e[3];let v;e[4]!==n||e[5]!==c||e[6]!==u||e[7]!==h?(v=r(D,{"aria-label":u,className:"h-8 w-48","data-testid":"lg-search",onChange:n,placeholder:h,value:c}),e[4]=n,e[5]=c,e[6]=u,e[7]=h,e[8]=v):v=e[8];let b;e[9]!==l?(b=l("Function path"),e[9]=l,e[10]=b):b=e[10];let y;e[11]!==l?(y=l("filter path"),e[11]=l,e[12]=y):y=e[12];let w;e[13]!==a||e[14]!==m||e[15]!==b||e[16]!==y?(w=r(D,{"aria-label":b,className:"h-8 w-40","data-testid":"logs-path-filter",onChange:a,placeholder:y,value:m}),e[13]=a,e[14]=m,e[15]=b,e[16]=y,e[17]=w):w=e[17];let x;e[18]!==l?(x=l("Level filter"),e[18]=l,e[19]=x):x=e[19];let T;e[20]!==t||e[21]!==d?(T=re.map(G=>r(Ge,{level:G,onToggle:d,selected:t.has(G)},G)),e[20]=t,e[21]=d,e[22]=T):T=e[22];let R;e[23]!==x||e[24]!==T?(R=r("div",{"aria-label":x,className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:T}),e[23]=x,e[24]=T,e[25]=R):R=e[25];let N;e[26]!==l?(N=l("Time range"),e[26]=l,e[27]=N):N=e[27];let L;e[28]!==l?(L=l("All time"),e[28]=l,e[29]=L):L=e[29];let S;e[30]!==L?(S=r("option",{value:"all",children:L}),e[30]=L,e[31]=S):S=e[31];let g;e[32]!==l?(g=l("Last 5m"),e[32]=l,e[33]=g):g=e[33];let C;e[34]!==g?(C=r("option",{value:"5m",children:g}),e[34]=g,e[35]=C):C=e[35];let k;e[36]!==l?(k=l("Last 15m"),e[36]=l,e[37]=k):k=e[37];let P;e[38]!==k?(P=r("option",{value:"15m",children:k}),e[38]=k,e[39]=P):P=e[39];let O;e[40]!==l?(O=l("Last hour"),e[40]=l,e[41]=O):O=e[41];let _;e[42]!==O?(_=r("option",{value:"1h",children:O}),e[42]=O,e[43]=_):_=e[43];let A;e[44]!==o||e[45]!==N||e[46]!==S||e[47]!==C||e[48]!==P||e[49]!==_||e[50]!==f?(A=E("select",{"aria-label":N,className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"logs-time-range",onChange:o,value:f,children:[S,C,P,_]}),e[44]=o,e[45]=N,e[46]=S,e[47]=C,e[48]=P,e[49]=_,e[50]=f,e[51]=A):A=e[51];const z=s?"border-border bg-muted font-medium":"border-input text-muted-foreground";let M;e[52]!==z?(M=H("h-8 rounded-md border px-3 text-sm",z),e[52]=z,e[53]=M):M=e[53];let U;e[54]!==s||e[55]!==l?(U=l(s?"List":"Summary"),e[54]=s,e[55]=l,e[56]=U):U=e[56];let $;e[57]!==p||e[58]!==s||e[59]!==M||e[60]!==U?($=r("button",{"aria-pressed":s,className:M,"data-testid":"logs-summary-toggle",onClick:p,type:"button",children:U}),e[57]=p,e[58]=s,e[59]=M,e[60]=U,e[61]=$):$=e[61];let K;return e[62]!==A||e[63]!==$||e[64]!==v||e[65]!==w||e[66]!==R?(K=E("div",{className:"flex flex-wrap items-center gap-2",children:[v,w,R,A,$]}),e[62]=A,e[63]=$,e[64]=v,e[65]=w,e[66]=R,e[67]=K):K=e[67],K},We=i=>{const e=q(53),{onOutcomeChange:t,onPathChange:a,onTableChange:n,onUserChange:o,outcomeFilter:d,pathPrefix:p,tableFilter:m,userIdFilter:c}=i,s=Q();let f;e[0]!==s?(f=s("Function path"),e[0]=s,e[1]=f):f=e[1];let l;e[2]!==s?(l=s("file:function"),e[2]=s,e[3]=l):l=e[3];let u;e[4]!==a||e[5]!==p||e[6]!==f||e[7]!==l?(u=r(D,{"aria-label":f,className:"h-8 w-44","data-testid":"lg-req-path",onChange:a,placeholder:l,value:p}),e[4]=a,e[5]=p,e[6]=f,e[7]=l,e[8]=u):u=e[8];let h;e[9]!==s?(h=s("User id"),e[9]=s,e[10]=h):h=e[10];let v;e[11]!==s?(v=s("userId"),e[11]=s,e[12]=v):v=e[12];let b;e[13]!==o||e[14]!==h||e[15]!==v||e[16]!==c?(b=r(D,{"aria-label":h,className:"h-8 w-32","data-testid":"lg-req-user",onChange:o,placeholder:v,value:c}),e[13]=o,e[14]=h,e[15]=v,e[16]=c,e[17]=b):b=e[17];let y;e[18]!==s?(y=s("Table touched"),e[18]=s,e[19]=y):y=e[19];let w;e[20]!==s?(w=s("table"),e[20]=s,e[21]=w):w=e[21];let x;e[22]!==n||e[23]!==y||e[24]!==w||e[25]!==m?(x=r(D,{"aria-label":y,className:"h-8 w-32","data-testid":"lg-req-table",onChange:n,placeholder:w,value:m}),e[22]=n,e[23]=y,e[24]=w,e[25]=m,e[26]=x):x=e[26];let T;e[27]!==s?(T=s("Outcome filter"),e[27]=s,e[28]=T):T=e[28];let R;e[29]!==s?(R=s("all"),e[29]=s,e[30]=R):R=e[30];let N;e[31]!==R?(N=r("option",{value:"all",children:R}),e[31]=R,e[32]=N):N=e[32];let L;e[33]!==s?(L=s("ok"),e[33]=s,e[34]=L):L=e[34];let S;e[35]!==L?(S=r("option",{value:"ok",children:L}),e[35]=L,e[36]=S):S=e[36];let g;e[37]!==s?(g=s("error"),e[37]=s,e[38]=g):g=e[38];let C;e[39]!==g?(C=r("option",{value:"error",children:g}),e[39]=g,e[40]=C):C=e[40];let k;e[41]!==t||e[42]!==d||e[43]!==T||e[44]!==N||e[45]!==S||e[46]!==C?(k=E("select",{"aria-label":T,className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"lg-req-outcome",onChange:t,value:d,children:[N,S,C]}),e[41]=t,e[42]=d,e[43]=T,e[44]=N,e[45]=S,e[46]=C,e[47]=k):k=e[47];let P;return e[48]!==k||e[49]!==u||e[50]!==b||e[51]!==x?(P=E("div",{className:"flex flex-wrap items-center gap-2",children:[u,b,x,k]}),e[48]=k,e[49]=u,e[50]=b,e[51]=x,e[52]=P):P=e[52],P},ve=i=>{const e=q(7),{bucket:t}=i;let a;e[0]!==t.key?(a=r("span",{className:"truncate text-muted-foreground",role:"gridcell",children:t.key}),e[0]=t.key,e[1]=a):a=e[1];let n;e[2]!==t.count?(n=r("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:t.count}),e[2]=t.count,e[3]=n):n=e[3];let o;return e[4]!==a||e[5]!==n?(o=E("div",{className:"flex items-center justify-between gap-4 px-3 py-1 font-mono text-xs","data-testid":"logs-summary-row",role:"row",children:[a,n]}),e[4]=a,e[5]=n,e[6]=o):o=e[6],o},Ye=i=>{const e=q(31),{summary:t}=i,a=Q();let n;e[0]!==t.total||e[1]!==a?(n=a("{count} entries",{count:t.total}),e[0]=t.total,e[1]=a,e[2]=n):n=e[2];let o;e[3]!==n?(o=r("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:n}),e[3]=n,e[4]=o):o=e[4];let d;e[5]!==a?(d=a("By level"),e[5]=a,e[6]=d):d=e[6];let p;e[7]!==d?(p=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d}),e[7]=d,e[8]=p):p=e[8];let m;e[9]!==t.byLevel?(m=t.byLevel.map(je),e[9]=t.byLevel,e[10]=m):m=e[10];let c;e[11]!==m?(c=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:m}),e[11]=m,e[12]=c):c=e[12];let s;e[13]!==p||e[14]!==c?(s=E("div",{children:[p,c]}),e[13]=p,e[14]=c,e[15]=s):s=e[15];let f;e[16]!==a?(f=a("By function"),e[16]=a,e[17]=f):f=e[17];let l;e[18]!==f?(l=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:f}),e[18]=f,e[19]=l):l=e[19];let u;e[20]!==t.byPath?(u=t.byPath.map(Je),e[20]=t.byPath,e[21]=u):u=e[21];let h;e[22]!==u?(h=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:u}),e[22]=u,e[23]=h):h=e[23];let v;e[24]!==h||e[25]!==l?(v=E("div",{children:[l,h]}),e[24]=h,e[25]=l,e[26]=v):v=e[26];let b;return e[27]!==v||e[28]!==o||e[29]!==s?(b=E("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[o,s,v]}),e[27]=v,e[28]=o,e[29]=s,e[30]=b):b=e[30],b};function je(i){return r(ve,{bucket:i},i.key)}function Je(i){return r(ve,{bucket:i},i.key)}const Xe=i=>{const e=q(46),{liveError:t,onShardKeyChange:a,onShowArchive:n,onShowErrors:o,onShowRequests:d,shardKey:p,view:m}=i,c=Q(),s=m==="requests",f=m==="requests"?"bg-muted font-medium":"text-muted-foreground";let l;e[0]!==f?(l=H("px-3 py-1 text-sm",f),e[0]=f,e[1]=l):l=e[1];let u;e[2]!==c?(u=c("Requests"),e[2]=c,e[3]=u):u=e[3];let h;e[4]!==d||e[5]!==s||e[6]!==l||e[7]!==u?(h=r("button",{"aria-selected":s,className:l,"data-testid":"lg-view-requests",onClick:d,role:"tab",type:"button",children:u}),e[4]=d,e[5]=s,e[6]=l,e[7]=u,e[8]=h):h=e[8];const v=m==="errors",b=m==="errors"?"bg-muted font-medium":"text-muted-foreground";let y;e[9]!==b?(y=H("px-3 py-1 text-sm",b),e[9]=b,e[10]=y):y=e[10];let w;e[11]!==c?(w=c("Errors"),e[11]=c,e[12]=w):w=e[12];let x;e[13]!==o||e[14]!==v||e[15]!==y||e[16]!==w?(x=r("button",{"aria-selected":v,className:y,"data-testid":"lg-view-errors",onClick:o,role:"tab",type:"button",children:w}),e[13]=o,e[14]=v,e[15]=y,e[16]=w,e[17]=x):x=e[17];const T=m==="archive",R=m==="archive"?"bg-muted font-medium":"text-muted-foreground";let N;e[18]!==R?(N=H("px-3 py-1 text-sm",R),e[18]=R,e[19]=N):N=e[19];let L;e[20]!==c?(L=c("Archive"),e[20]=c,e[21]=L):L=e[21];let S;e[22]!==n||e[23]!==T||e[24]!==N||e[25]!==L?(S=r("button",{"aria-selected":T,className:N,"data-testid":"lg-view-archive",onClick:n,role:"tab",type:"button",children:L}),e[22]=n,e[23]=T,e[24]=N,e[25]=L,e[26]=S):S=e[26];let g;e[27]!==x||e[28]!==S||e[29]!==h?(g=E("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[h,x,S]}),e[27]=x,e[28]=S,e[29]=h,e[30]=g):g=e[30];let C;e[31]!==a||e[32]!==p?(C=r(Ke,{onChange:a,testId:"lg-shard-input",value:p}),e[31]=a,e[32]=p,e[33]=C):C=e[33];let k;e[34]!==t||e[35]!==m?(k=m!=="archive"&&r(Ue,{message:t,prefix:"lg"}),e[34]=t,e[35]=m,e[36]=k):k=e[36];let P;e[37]!==c?(P=c("Open in Cloudflare"),e[37]=c,e[38]=P):P=e[38];let O;e[39]!==P?(O=r("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:pe,rel:"noreferrer",target:"_blank",children:P}),e[39]=P,e[40]=O):O=e[40];let _;return e[41]!==g||e[42]!==C||e[43]!==k||e[44]!==O?(_=E("div",{className:"flex flex-wrap items-center gap-2",children:[g,C,k,O]}),e[41]=g,e[42]=C,e[43]=k,e[44]=O,e[45]=_):_=e[45],_},te=400,Ze=36,et={height:te,overflow:"auto"},be={left:0,position:"absolute",top:0,width:"100%"},tt={error:"destructive",ok:"secondary"},xe=i=>{const e=q(6),{onOpenTrace:t,traceId:a}=i,n=Q();let o;e[0]!==t||e[1]!==n||e[2]!==a?(o=a===void 0?null:r("button",{className:"text-primary underline-offset-2 hover:underline","data-testid":"lg-trace-link",onClick:()=>{t(a)},type:"button",children:n("Trace")}),e[0]=t,e[1]=n,e[2]=a,e[3]=o):o=e[3];let d;return e[4]!==o?(d=r("span",{className:"w-16 shrink-0 text-right",role:"gridcell",children:o}),e[4]=o,e[5]=d):d=e[5],d},rt=i=>{const e=q(13),{entry:t,index:a,measureRef:n,onOpenTrace:o,start:d}=i,p=`translateY(${String(d)}px)`;let m;e[0]!==p?(m={...be,transform:p},e[0]=p,e[1]=m):m=e[1];const c=m;let s;e[2]!==t?(s=r(Me,{entry:t}),e[2]=t,e[3]=s):s=e[3];let f;e[4]!==t.traceId||e[5]!==o?(f=r(xe,{onOpenTrace:o,traceId:t.traceId}),e[4]=t.traceId,e[5]=o,e[6]=f):f=e[6];let l;return e[7]!==a||e[8]!==n||e[9]!==c||e[10]!==s||e[11]!==f?(l=E("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":a,"data-testid":"lg-row",ref:n,role:"row",style:c,children:[s,f]}),e[7]=a,e[8]=n,e[9]=c,e[10]=s,e[11]=f,e[12]=l):l=e[12],l},ce=i=>i.length===0?"—":i.join(", "),st=i=>{const e=q(41),{entry:t,index:a,measureRef:n,onOpenTrace:o,start:d}=i,p=`translateY(${String(d)}px)`;let m;e[0]!==p?(m={...be,transform:p},e[0]=p,e[1]=m):m=e[1];const c=m;let s;e[2]!==t.ts?(s=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=s):s=e[3];let f;e[4]!==s?(f=r("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:s}),e[4]=s,e[5]=f):f=e[5];const l=tt[t.outcome];let u;e[6]!==t.outcome||e[7]!==l?(u=r("span",{className:"w-16 shrink-0",role:"gridcell",children:r(he,{variant:l,children:t.outcome})}),e[6]=t.outcome,e[7]=l,e[8]=u):u=e[8];let h;e[9]!==t.functionPath?(h=r("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:t.functionPath,children:t.functionPath}),e[9]=t.functionPath,e[10]=h):h=e[10];const v=t.shardKey??"—";let b;e[11]!==v?(b=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:v}),e[11]=v,e[12]=b):b=e[12];const y=t.userId??"—";let w;e[13]!==y?(w=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:y}),e[13]=y,e[14]=w):w=e[14];let x;e[15]!==t.durationMs?(x=Math.round(t.durationMs),e[15]=t.durationMs,e[16]=x):x=e[16];const T=`${String(x)}ms`;let R;e[17]!==T?(R=r("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:T}),e[17]=T,e[18]=R):R=e[18];let N;e[19]!==t.errorMessage||e[20]!==t.outcome||e[21]!==t.tablesRead||e[22]!==t.tablesWritten?(N=t.outcome==="error"&&t.errorMessage!==void 0?t.errorMessage:`r:${ce(t.tablesRead)} · w:${ce(t.tablesWritten)}`,e[19]=t.errorMessage,e[20]=t.outcome,e[21]=t.tablesRead,e[22]=t.tablesWritten,e[23]=N):N=e[23];let L;e[24]!==N?(L=r("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:N}),e[24]=N,e[25]=L):L=e[25];let S;e[26]!==t.traceId||e[27]!==o?(S=r(xe,{onOpenTrace:o,traceId:t.traceId}),e[26]=t.traceId,e[27]=o,e[28]=S):S=e[28];let g;return e[29]!==a||e[30]!==n||e[31]!==c||e[32]!==w||e[33]!==R||e[34]!==L||e[35]!==S||e[36]!==f||e[37]!==u||e[38]!==h||e[39]!==b?(g=E("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":a,"data-testid":"lg-req-row",ref:n,role:"row",style:c,children:[f,u,h,b,w,R,L,S]}),e[29]=a,e[30]=n,e[31]=c,e[32]=w,e[33]=R,e[34]=L,e[35]=S,e[36]=f,e[37]=u,e[38]=h,e[39]=b,e[40]=g):g=e[40],g},de=i=>{const{entries:e}=i??{};return Array.isArray(e)?e:[]},lt=i=>{const e={};return i.functionPathPrefix.trim()!==""&&(e.functionPathPrefix=i.functionPathPrefix.trim()),i.userId.trim()!==""&&(e.userId=i.userId.trim()),i.tableTouched.trim()!==""&&(e.tableTouched=i.tableTouched.trim()),(i.outcome==="ok"||i.outcome==="error")&&(e.outcome=i.outcome),e},ot={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},at=(i,e)=>{const t=e.search.trim().toLowerCase(),a=e.path.trim().toLowerCase(),n=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-ot[e.range];return i.filter(o=>e.levels.size>0&&!e.levels.has(o.level)||o.timestamp<n||a!==""&&!(o.functionPath??"").toLowerCase().includes(a)?!1:t===""||o.message.toLowerCase().includes(t)||fe(o.fields).toLowerCase().includes(t))},nt="—",it=i=>{const e=new Map,t=new Map;for(const o of i){e.set(o.level,(e.get(o.level)??0)+1);const d=o.functionPath??nt;t.set(d,(t.get(d)??0)+1)}const a=re.filter(o=>e.has(o)).map(o=>({count:e.get(o)??0,key:o})),n=[...t.entries()].map(([o,d])=>({count:d,key:o})).toSorted((o,d)=>d.count===o.count?o.key.localeCompare(d.key):d.count-o.count);return{byLevel:a,byPath:n,total:i.length}},Wt=({initialShardKey:i})=>{const e=Q(),[t,a]=F("requests"),{queryShardKey:n,setShardKey:o,shardKey:d}=Ie(i),[p,m]=F(""),[c,s]=F(()=>new Set),[f,l]=F(""),[u,h]=F("all"),[v,b]=F(!1),[y,w]=F(""),[x,T]=F(""),[R,N]=F(""),[L,S]=F("all"),g=lt({functionPathPrefix:y,outcome:L,tableTouched:R,userId:x}),C=le(oe.getRequestLog,g,{enabled:t==="requests",live:!0,shardKey:n}),k=le(oe.getLogs,{},{enabled:t==="errors",live:!0,shardKey:n}),P=t==="requests"?C:k,{error:O,errorSource:_,isLoading:A,liveError:z}=P,M=Te(n),U=de(k.data),$=de(C.data);me(()=>{P.data!==void 0&&Re(n)},[P.data,n]);const K=at(U,{levels:c,now:Date.now(),path:f,range:u,search:p}),G=it(K),J=t==="requests"?$.length:K.length,X=t==="errors"&&v,W=Ne(()=>O!==null?"error":J===0?A?X?"summary":"list":"empty":X?"summary":"list",[J,A,O,X]),se=ue(null),Y=Ce({count:J,estimateSize:()=>Ze,getScrollElement:()=>se.current,initialRect:{height:te,width:800},observeElementRect:(I,Z)=>ke(I,Z,te),overscan:8}),ye=Y.getVirtualItems(),we={height:Y.getTotalSize(),position:"relative",width:"100%"};return E("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[r(Xe,{liveError:z,onShardKeyChange:o,onShowArchive:()=>{a("archive"),b(!1)},onShowErrors:()=>{a("errors"),b(!1)},onShowRequests:()=>{a("requests"),b(!1)},shardKey:d,view:t}),t==="errors"&&r(He,{levelFilter:c,onLogPathChange:I=>{l(I.target.value)},onSearchChange:I=>{m(I.target.value)},onTimeRangeChange:I=>{h(I.target.value)},onToggleLevel:I=>{s(Z=>{const j=new Set(Z);return j.has(I)?j.delete(I):j.add(I),j})},onToggleSummary:()=>{b(I=>!I)},pathFilter:f,search:p,showSummary:v,timeRange:u}),t==="requests"&&r(We,{onOutcomeChange:I=>{S(I.target.value)},onPathChange:I=>{w(I.target.value)},onTableChange:I=>{N(I.target.value)},onUserChange:I=>{T(I.target.value)},outcomeFilter:L,pathPrefix:y,tableFilter:R,userIdFilter:x}),t==="archive"?r(ze,{shardKey:n}):E($e,{children:[W==="error"&&r(Se,{error:_,testId:"lg-error"}),W==="empty"&&r(ee,{description:e("Function and request logs for this shard show up here as your app handles traffic."),icon:r("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:r("path",{d:"M4 5h16M4 12h16M4 19h10"})}),testId:"lg-empty",title:e("No logs.")}),W==="summary"&&r(Ye,{summary:G}),W==="list"&&r("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:se,style:et,children:r("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:we,children:ye.map(I=>t==="requests"?r(st,{entry:$[I.index],index:I.index,measureRef:Y.measureElement,onOpenTrace:M,start:I.start},I.key):r(rt,{entry:K[I.index],index:I.index,measureRef:Y.measureElement,onOpenTrace:M,start:I.start},I.key))})})]})]})};export{Wt as LogsPanel,at as filterLogs,it as summarizeLogs};
@@ -1,2 +1,2 @@
1
- import{E as ie}from"../packem_shared/error-alert-TYdKetJd.js";import{B as se}from"../packem_shared/badge-cAk9Di1Q.js";import{B as v}from"../packem_shared/button-BOPLD1un.js";import{E as oe}from"../packem_shared/empty-state-B939z6K2.js";import{I as ne}from"../packem_shared/input-CY5W3wzv.js";import{S as le}from"../packem_shared/scroll-area-DSJftwu_.js";import{Separator as de}from"@base-ui/react/separator";import{c as ce}from"../packem_shared/utils-bhneXptQ.js";import{jsx as t,jsxs as n,Fragment as me}from"react/jsx-runtime";import{useT as ue}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{c as ae,d as Y,b as Z,f as ee,g as he,i as te}from"../packem_shared/internal-CwaF9YNk.js";import{c as pe}from"react/compiler-runtime";import{useLunora as fe}from"@lunora/react";import{useState as O}from"react";import{u as be}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{useAutoRefresh as xe}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.js";import{ADMIN_FUNCTIONS as X}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";function ge({className:r,orientation:e="horizontal",...s}){return t(de,{"data-slot":"separator",orientation:e,className:ce("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",r),...s})}const ve=/https?:\/\/[^\s"'<>)]+/i,re=r=>r===void 0?void 0:ve.exec(r)?.[0],N=r=>r===void 0?"":Array.isArray(r)?r.join(", "):r,Ne=r=>{if(r!==void 0)return re(r.html)??re(r.text)},we=(r,e)=>{const s=e.trim().toLowerCase();return s===""?r:r.filter(o=>`${o.subject} ${N(o.to)} ${N(o.cc)}`.toLowerCase().includes(s))},ye=(r,e)=>{if(r.length!==0)return r.find(s=>s.id===e)??r[0]},Ce=ae(X.clearCapturedMail),Se=ae(X.sendTestMail),Te=r=>{const e=pe(38),{limit:s}=r,o=fe();let p;e[0]!==s?(p={limit:s},e[0]=s,e[1]=p):p=e[1];const{data:R,error:w,errorSource:y,isLoading:x,refetch:l}=be(X.getCapturedMail,p),[C,f]=O(null),[B,S]=O(null),[g,i]=O("html"),[c,D]=O(""),b=R?.entries??[],a=w??C,h=w===null?C:y;let T;e[2]!==o||e[3]!==l?(T=async()=>{f(null);try{await o.query(Ce,{},Y("")),S(null),l()}catch(m){f(Z(m))}},e[2]=o,e[3]=l,e[4]=T):T=e[4];const H=T;let k;e[5]!==o||e[6]!==l?(k=async()=>{f(null);try{await o.query(Se,{},Y("")),l()}catch(m){f(Z(m))}},e[5]=o,e[6]=l,e[7]=k):k=e[7];const q=k;let L;e[8]!==l?(L=()=>{l()},e[8]=l,e[9]=L):L=e[9],xe(L,!0);let A;e[10]!==H?(A=()=>{ee(H())},e[10]=H,e[11]=A):A=e[11];const U=A;let E;e[12]!==q?(E=()=>{ee(q())},e[12]=q,e[13]=E):E=e[13];const W=E;let _;e[14]===Symbol.for("react.memo_cache_sentinel")?(_=m=>{D(m.currentTarget.value)},e[14]=_):_=e[14];const K=_;let M;e[15]===Symbol.for("react.memo_cache_sentinel")?(M=m=>{const{id:u}=m.currentTarget.dataset;u!==void 0&&S(u)},e[15]=M):M=e[15];const Q=M;let j;e[16]===Symbol.for("react.memo_cache_sentinel")?(j=m=>{const u=m.currentTarget.dataset.tab;(u==="headers"||u==="html"||u==="text")&&i(u)},e[16]=j):j=e[16];const V=j,I=we(b,c),$=ye(I,B),d=Ne($);let z;e[17]!==d?(z=()=>{d!==void 0&&he(d)},e[17]=d,e[18]=z):z=e[18];const G=z;let F;e[19]!==d?(F=()=>{d!==void 0&&"window"in globalThis&&globalThis.window.open(d,"_blank","noopener")},e[19]=d,e[20]=F):F=e[20];const J=F;let P;return e[21]!==b||e[22]!==a||e[23]!==h||e[24]!==c||e[25]!==x||e[26]!==d||e[27]!==U||e[28]!==G||e[29]!==K||e[30]!==J||e[31]!==Q||e[32]!==V||e[33]!==W||e[34]!==$||e[35]!==g||e[36]!==I?(P={entries:b,error:a,errorSource:h,filter:c,isLoading:x,link:d,onClear:U,onCopyLink:G,onFilterChange:K,onOpenLink:J,onSelectMessage:Q,onSelectTab:V,onSendTest:W,selected:$,tab:g,visible:I},e[21]=b,e[22]=a,e[23]=h,e[24]=c,e[25]=x,e[26]=d,e[27]=U,e[28]=G,e[29]=K,e[30]=J,e[31]=Q,e[32]=V,e[33]=W,e[34]=$,e[35]=g,e[36]=I,e[37]=P):P=e[37],P},ke=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,Le=r=>`${ke}${r}`,We=({limit:r=100})=>{const e=ue(),{entries:s,error:o,errorSource:p,filter:R,isLoading:w,link:y,onClear:x,onCopyLink:l,onFilterChange:C,onOpenLink:f,onSelectMessage:B,onSelectTab:S,onSendTest:g,selected:i,tab:c,visible:D}=Te({limit:r}),b=a=>e(a==="html"?"HTML":a==="text"?"Plain text":"Headers");return n("div",{className:"flex flex-col gap-4","data-testid":"mail-panel",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t(v,{"data-testid":"mail-send-test",onClick:g,size:"sm",type:"button",variant:"outline",children:e("Send test")}),t(v,{"data-testid":"mail-clear",disabled:s.length===0,onClick:x,size:"sm",type:"button",variant:"outline",children:e("Clear inbox")}),s.length>0&&t(se,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:e("{count} messages",{count:s.length})})]}),o!==null&&t(ie,{error:p,testId:"mail-error"}),o===null&&!w&&s.length===0&&t(oe,{description:e("Email your app sends in dev is captured here — nothing is delivered."),icon:n("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[t("path",{d:"M4 5h16v14H4z"}),t("path",{d:"m4 6 8 6 8-6"})]}),testId:"mail-empty",title:e("No captured email.")}),s.length>0&&n("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-[minmax(0,22rem)_1fr]","data-testid":"mail-reader",children:[n("div",{className:"flex flex-col gap-2",children:[t(ne,{"aria-label":e("Search messages"),"data-testid":"mail-search",onChange:C,placeholder:e("Filter messages"),type:"search",value:R}),t(le,{className:"max-h-[32rem] rounded-xl border border-border bg-card shadow-xs","data-testid":"mail-list",children:t("ul",{className:"divide-y",children:D.map(a=>{const h=a.id===i?.id;return t("li",{children:n("button",{className:`flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left text-sm hover:bg-muted/60 ${h?"bg-muted":""}`,"data-active":h,"data-id":a.id,"data-testid":"mail-list-item",onClick:B,type:"button",children:[t("span",{className:"w-full truncate font-medium",children:a.subject||e("(no subject)")}),t("span",{className:"w-full truncate text-xs text-muted-foreground",children:N(a.to)}),t("span",{className:"text-xs text-muted-foreground tabular-nums",children:te(a.capturedAt,"—")})]})},a.id)})})})]}),i!==void 0&&n("div",{className:"flex min-w-0 flex-col gap-3 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"mail-detail",children:[n("div",{className:"flex flex-col gap-1",children:[t("h2",{className:"truncate text-base font-semibold","data-testid":"mail-subject",children:i.subject||e("(no subject)")}),n("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-xs text-muted-foreground",children:[t("dt",{children:e("From")}),t("dd",{className:"truncate font-mono",children:i.from??"—"}),t("dt",{children:e("To")}),t("dd",{className:"truncate font-mono",children:N(i.to)}),i.cc!==void 0&&i.cc.length>0&&n(me,{children:[t("dt",{children:e("Cc")}),t("dd",{className:"truncate font-mono",children:N(i.cc)})]}),t("dt",{children:e("Sent")}),t("dd",{className:"tabular-nums",children:te(i.capturedAt,"—")})]})]}),n("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[t(v,{"data-testid":"mail-copy-link",disabled:y===void 0,onClick:l,size:"sm",type:"button",variant:"outline",children:e("Copy link")}),t(v,{"data-testid":"mail-open-link",disabled:y===void 0,onClick:f,size:"sm",type:"button",variant:"outline",children:e("Open in new tab")})]}),t(ge,{}),t("div",{className:"flex items-center gap-1","data-testid":"mail-tabs",role:"tablist",children:["html","text","headers"].map(a=>t(v,{"aria-selected":c===a,"data-tab":a,"data-testid":`mail-tab-${a}`,onClick:S,role:"tab",size:"sm",type:"button",variant:c===a?"secondary":"ghost",children:b(a)},a))}),n("div",{className:"min-h-[12rem]",children:[c==="html"&&(i.html===void 0?t("p",{className:"text-sm text-muted-foreground",children:e("No HTML body.")}):t("iframe",{className:"h-[24rem] w-full rounded-md border bg-white","data-testid":"mail-preview-html",sandbox:"",srcDoc:Le(i.html),title:e("Email preview")})),c==="text"&&(i.text===void 0?t("p",{className:"text-sm text-muted-foreground",children:e("No text body.")}):t("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-text",children:i.text})),c==="headers"&&(i.headers===void 0||Object.keys(i.headers).length===0?t("p",{className:"text-sm text-muted-foreground",children:e("No headers.")}):t("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-headers",children:Object.entries(i.headers).map(([a,h])=>`${a}: ${h}`).join(`
1
+ import{E as ie}from"../packem_shared/error-alert-CKqB2CiN.js";import{B as se}from"../packem_shared/badge-cAk9Di1Q.js";import{B as v}from"../packem_shared/button-BOPLD1un.js";import{E as oe}from"../packem_shared/empty-state-B939z6K2.js";import{I as ne}from"../packem_shared/input-CY5W3wzv.js";import{S as le}from"../packem_shared/scroll-area-DSJftwu_.js";import{Separator as de}from"@base-ui/react/separator";import{c as ce}from"../packem_shared/utils-bhneXptQ.js";import{jsx as t,jsxs as n,Fragment as me}from"react/jsx-runtime";import{useT as ue}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{c as ae,d as Y,b as Z,f as ee,g as he,i as te}from"../packem_shared/internal-7bgd8inO.js";import{c as pe}from"react/compiler-runtime";import{useLunora as fe}from"@lunora/react";import{useState as O}from"react";import{u as be}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{useAutoRefresh as xe}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.js";import{ADMIN_FUNCTIONS as X}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";function ge({className:r,orientation:e="horizontal",...s}){return t(de,{"data-slot":"separator",orientation:e,className:ce("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",r),...s})}const ve=/https?:\/\/[^\s"'<>)]+/i,re=r=>r===void 0?void 0:ve.exec(r)?.[0],N=r=>r===void 0?"":Array.isArray(r)?r.join(", "):r,Ne=r=>{if(r!==void 0)return re(r.html)??re(r.text)},we=(r,e)=>{const s=e.trim().toLowerCase();return s===""?r:r.filter(o=>`${o.subject} ${N(o.to)} ${N(o.cc)}`.toLowerCase().includes(s))},ye=(r,e)=>{if(r.length!==0)return r.find(s=>s.id===e)??r[0]},Ce=ae(X.clearCapturedMail),Se=ae(X.sendTestMail),Te=r=>{const e=pe(38),{limit:s}=r,o=fe();let p;e[0]!==s?(p={limit:s},e[0]=s,e[1]=p):p=e[1];const{data:R,error:w,errorSource:y,isLoading:x,refetch:l}=be(X.getCapturedMail,p),[C,f]=O(null),[B,S]=O(null),[g,i]=O("html"),[c,D]=O(""),b=R?.entries??[],a=w??C,h=w===null?C:y;let T;e[2]!==o||e[3]!==l?(T=async()=>{f(null);try{await o.query(Ce,{},Y("")),S(null),l()}catch(m){f(Z(m))}},e[2]=o,e[3]=l,e[4]=T):T=e[4];const H=T;let k;e[5]!==o||e[6]!==l?(k=async()=>{f(null);try{await o.query(Se,{},Y("")),l()}catch(m){f(Z(m))}},e[5]=o,e[6]=l,e[7]=k):k=e[7];const q=k;let L;e[8]!==l?(L=()=>{l()},e[8]=l,e[9]=L):L=e[9],xe(L,!0);let A;e[10]!==H?(A=()=>{ee(H())},e[10]=H,e[11]=A):A=e[11];const U=A;let E;e[12]!==q?(E=()=>{ee(q())},e[12]=q,e[13]=E):E=e[13];const W=E;let _;e[14]===Symbol.for("react.memo_cache_sentinel")?(_=m=>{D(m.currentTarget.value)},e[14]=_):_=e[14];const K=_;let M;e[15]===Symbol.for("react.memo_cache_sentinel")?(M=m=>{const{id:u}=m.currentTarget.dataset;u!==void 0&&S(u)},e[15]=M):M=e[15];const Q=M;let j;e[16]===Symbol.for("react.memo_cache_sentinel")?(j=m=>{const u=m.currentTarget.dataset.tab;(u==="headers"||u==="html"||u==="text")&&i(u)},e[16]=j):j=e[16];const V=j,I=we(b,c),$=ye(I,B),d=Ne($);let z;e[17]!==d?(z=()=>{d!==void 0&&he(d)},e[17]=d,e[18]=z):z=e[18];const G=z;let F;e[19]!==d?(F=()=>{d!==void 0&&"window"in globalThis&&globalThis.window.open(d,"_blank","noopener")},e[19]=d,e[20]=F):F=e[20];const J=F;let P;return e[21]!==b||e[22]!==a||e[23]!==h||e[24]!==c||e[25]!==x||e[26]!==d||e[27]!==U||e[28]!==G||e[29]!==K||e[30]!==J||e[31]!==Q||e[32]!==V||e[33]!==W||e[34]!==$||e[35]!==g||e[36]!==I?(P={entries:b,error:a,errorSource:h,filter:c,isLoading:x,link:d,onClear:U,onCopyLink:G,onFilterChange:K,onOpenLink:J,onSelectMessage:Q,onSelectTab:V,onSendTest:W,selected:$,tab:g,visible:I},e[21]=b,e[22]=a,e[23]=h,e[24]=c,e[25]=x,e[26]=d,e[27]=U,e[28]=G,e[29]=K,e[30]=J,e[31]=Q,e[32]=V,e[33]=W,e[34]=$,e[35]=g,e[36]=I,e[37]=P):P=e[37],P},ke=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,Le=r=>`${ke}${r}`,We=({limit:r=100})=>{const e=ue(),{entries:s,error:o,errorSource:p,filter:R,isLoading:w,link:y,onClear:x,onCopyLink:l,onFilterChange:C,onOpenLink:f,onSelectMessage:B,onSelectTab:S,onSendTest:g,selected:i,tab:c,visible:D}=Te({limit:r}),b=a=>e(a==="html"?"HTML":a==="text"?"Plain text":"Headers");return n("div",{className:"flex flex-col gap-4","data-testid":"mail-panel",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t(v,{"data-testid":"mail-send-test",onClick:g,size:"sm",type:"button",variant:"outline",children:e("Send test")}),t(v,{"data-testid":"mail-clear",disabled:s.length===0,onClick:x,size:"sm",type:"button",variant:"outline",children:e("Clear inbox")}),s.length>0&&t(se,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:e("{count} messages",{count:s.length})})]}),o!==null&&t(ie,{error:p,testId:"mail-error"}),o===null&&!w&&s.length===0&&t(oe,{description:e("Email your app sends in dev is captured here — nothing is delivered."),icon:n("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[t("path",{d:"M4 5h16v14H4z"}),t("path",{d:"m4 6 8 6 8-6"})]}),testId:"mail-empty",title:e("No captured email.")}),s.length>0&&n("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-[minmax(0,22rem)_1fr]","data-testid":"mail-reader",children:[n("div",{className:"flex flex-col gap-2",children:[t(ne,{"aria-label":e("Search messages"),"data-testid":"mail-search",onChange:C,placeholder:e("Filter messages"),type:"search",value:R}),t(le,{className:"max-h-[32rem] rounded-xl border border-border bg-card shadow-xs","data-testid":"mail-list",children:t("ul",{className:"divide-y",children:D.map(a=>{const h=a.id===i?.id;return t("li",{children:n("button",{className:`flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left text-sm hover:bg-muted/60 ${h?"bg-muted":""}`,"data-active":h,"data-id":a.id,"data-testid":"mail-list-item",onClick:B,type:"button",children:[t("span",{className:"w-full truncate font-medium",children:a.subject||e("(no subject)")}),t("span",{className:"w-full truncate text-xs text-muted-foreground",children:N(a.to)}),t("span",{className:"text-xs text-muted-foreground tabular-nums",children:te(a.capturedAt,"—")})]})},a.id)})})})]}),i!==void 0&&n("div",{className:"flex min-w-0 flex-col gap-3 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"mail-detail",children:[n("div",{className:"flex flex-col gap-1",children:[t("h2",{className:"truncate text-base font-semibold","data-testid":"mail-subject",children:i.subject||e("(no subject)")}),n("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-xs text-muted-foreground",children:[t("dt",{children:e("From")}),t("dd",{className:"truncate font-mono",children:i.from??"—"}),t("dt",{children:e("To")}),t("dd",{className:"truncate font-mono",children:N(i.to)}),i.cc!==void 0&&i.cc.length>0&&n(me,{children:[t("dt",{children:e("Cc")}),t("dd",{className:"truncate font-mono",children:N(i.cc)})]}),t("dt",{children:e("Sent")}),t("dd",{className:"tabular-nums",children:te(i.capturedAt,"—")})]})]}),n("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[t(v,{"data-testid":"mail-copy-link",disabled:y===void 0,onClick:l,size:"sm",type:"button",variant:"outline",children:e("Copy link")}),t(v,{"data-testid":"mail-open-link",disabled:y===void 0,onClick:f,size:"sm",type:"button",variant:"outline",children:e("Open in new tab")})]}),t(ge,{}),t("div",{className:"flex items-center gap-1","data-testid":"mail-tabs",role:"tablist",children:["html","text","headers"].map(a=>t(v,{"aria-selected":c===a,"data-tab":a,"data-testid":`mail-tab-${a}`,onClick:S,role:"tab",size:"sm",type:"button",variant:c===a?"secondary":"ghost",children:b(a)},a))}),n("div",{className:"min-h-[12rem]",children:[c==="html"&&(i.html===void 0?t("p",{className:"text-sm text-muted-foreground",children:e("No HTML body.")}):t("iframe",{className:"h-[24rem] w-full rounded-md border bg-white","data-testid":"mail-preview-html",sandbox:"",srcDoc:Le(i.html),title:e("Email preview")})),c==="text"&&(i.text===void 0?t("p",{className:"text-sm text-muted-foreground",children:e("No text body.")}):t("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-text",children:i.text})),c==="headers"&&(i.headers===void 0||Object.keys(i.headers).length===0?t("p",{className:"text-sm text-muted-foreground",children:e("No headers.")}):t("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-headers",children:Object.entries(i.headers).map(([a,h])=>`${a}: ${h}`).join(`
2
2
  `)}))]})]})]})]})};export{We as MailPanel};
@@ -1 +1 @@
1
- import{useLunora as gt}from"@lunora/react";import{useState as pe,useRef as Ge,useEffect as tt,useMemo as pt}from"react";import{L as xt}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as bt}from"../packem_shared/ShardInput-XumEzeT0.js";import{B as rt}from"../packem_shared/button-BOPLD1un.js";import{u as Ue}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{u as vt}from"../packem_shared/use-open-trace-4tIa0SXZ.js";import{u as yt}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as xe}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as Le}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{c as Nt}from"../packem_shared/cf-links-CBJ5SywP.js";import{m as St,l as Xe,f as wt,d as qt,b as Tt,c as _t}from"../packem_shared/internal-CwaF9YNk.js";import{r as $t,l as Ct}from"../packem_shared/shard-history-QcjcMnCA.js";import{c as Ee}from"react/compiler-runtime";import{f as Rt}from"../packem_shared/log-fields-SBxKyBug.js";import{B as et}from"../packem_shared/badge-cAk9Di1Q.js";import{C as he,a as ge,c as je,d as kt,b as Be}from"../packem_shared/card-BGlQzQY-.js";import{b as Je,e as oe,T as ct,c as de,a as dt,d as mt}from"../packem_shared/table-BMsuYFhk.js";import{S as ut}from"../packem_shared/sparkline-BreIqzDO.js";import{jsxs as n,jsx as t,Fragment as Ye}from"react/jsx-runtime";import{aggregateMetrics as Mt,computeLatencyPercentiles as It,enrichQueryStats as Dt,shardsToAggregate as At}from"../packem_shared/aggregateMetrics-A-Y7OH6R.js";import{S as me}from"../packem_shared/stat-card-B9uIvAHg.js";import{ResponsiveContainer as st,AreaChart as Et,CartesianGrid as lt,XAxis as at,YAxis as it,Tooltip as nt,Area as Ft,LineChart as Lt,Line as Ot}from"recharts";import{E as zt}from"../packem_shared/empty-state-B939z6K2.js";import{c as Kt}from"../packem_shared/utils-bhneXptQ.js";import{S as Pt,a as jt,c as Qe,b as Bt,d as Qt}from"../packem_shared/select-BPISLTcv.js";const Ht=(l,e)=>l<e?-1:l>e?1:0,Ze=l=>{if(l===void 0)return"null";if(typeof l=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(l===null||typeof l!="object")return JSON.stringify(l);if(Array.isArray(l))return`[${l.map(d=>Ze(d)).join(",")}]`;const e=Object.getPrototypeOf(l);if(e!==null&&e!==Object.prototype){const d=l.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${d} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const a=l,s=Object.keys(a).toSorted(Ht),r=[];for(const d of s){const o=a[d];o!==void 0&&r.push(`${JSON.stringify(d)}:${Ze(o)}`)}return`{${r.join(",")}}`},ft=(l,e,a)=>`${l}:${e}:${Ze(a??{})}`,ht=(l,e)=>l==="gauge"?e.last:l==="histogram"?e.sum/Math.max(1,e.count):e.sum,Ut=(l,e)=>ht(l,e),Jt=l=>ht(l.kind,l),We=l=>Number.isInteger(l)?l.toLocaleString():l.toLocaleString(void 0,{maximumFractionDigits:2}),Vt=l=>Array.isArray(l?.series)?l.series:[],Gt="FUNCTION_NOT_FOUND",Wt=l=>{const e=new Map;if(!Array.isArray(l?.series))return e;for(const a of l.series)e.set(ft(a.kind,a.name,a.attributes),a.points);return e},Xt={counter:"secondary",gauge:"default",histogram:"outline"},Yt=l=>{const e=Ee(18),{name:a,onOpenTrace:s,traceId:r}=l,d=xe();if(r===void 0){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=t("span",{className:"text-muted-foreground",children:"—"}),e[0]=m):m=e[0],m}let o;e[1]!==r?(o=r.slice(0,8),e[1]=r,e[2]=o):o=e[2];const i=o;if(s===void 0){const m=`mt-instrument-trace-${a}`;let h;return e[3]!==i||e[4]!==m||e[5]!==r?(h=t("span",{className:"text-muted-foreground","data-testid":m,title:r,children:i}),e[3]=i,e[4]=m,e[5]=r,e[6]=h):h=e[6],h}const S=`mt-instrument-trace-${a}`;let v;e[7]!==s||e[8]!==r?(v=()=>{s(r)},e[7]=s,e[8]=r,e[9]=v):v=e[9];let w;e[10]!==d||e[11]!==r?(w=d("Open the exemplar trace {trace}",{trace:r}),e[10]=d,e[11]=r,e[12]=w):w=e[12];let f;return e[13]!==i||e[14]!==S||e[15]!==v||e[16]!==w?(f=t("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":S,onClick:v,title:w,type:"button",children:i}),e[13]=i,e[14]=S,e[15]=v,e[16]=w,e[17]=f):f=e[17],f},Zt=l=>{const e=Ee(105),{onOpenTrace:a,shardKey:s}=l,r=xe();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];let o;e[1]!==s?(o={live:!0,shardKey:s},e[1]=s,e[2]=o):o=e[2];const{data:i,error:S,errorSource:v}=Ue(Le.getMetricSeries,d,o);let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w={},e[3]=w):w=e[3];let f;e[4]!==s?(f={live:!0,shardKey:s},e[4]=s,e[5]=f):f=e[5];const{data:m}=Ue(Le.getMetricHistory,w,f);let h,y,q,$,c,p,g,x,T,C,N,k,R;if(e[6]!==i||e[7]!==S||e[8]!==v||e[9]!==m||e[10]!==a||e[11]!==r){x=Symbol.for("react.early_return_sentinel");e:{const F=Vt(i),O=St(v)===Gt;if(S!==null&&!O){let u;e[25]!==r?(u=r("Instruments"),e[25]=r,e[26]=u):u=e[26];let K;e[27]!==u?(K=t("h3",{className:"text-sm font-semibold text-foreground",children:u}),e[27]=u,e[28]=K):K=e[28];let j;e[29]!==S||e[30]!==r?(j=r("Instruments unavailable: {error}",{error:S}),e[29]=S,e[30]=r,e[31]=j):j=e[31];let B;e[32]!==j?(B=t("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:j}),e[32]=j,e[33]=B):B=e[33];let Q;e[34]!==K||e[35]!==B?(Q=n("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[K,B]}),e[34]=K,e[35]=B,e[36]=Q):Q=e[36],x=Q;break e}if(F.length===0){x=null;break e}const E=Wt(m);let z;e[37]!==r?(z=u=>r(u==="counter"?"Counter":u==="gauge"?"Gauge":"Histogram"),e[37]=r,e[38]=z):z=e[38];const P=z;c="flex flex-col gap-2",p="mt-instruments";let L;e[39]!==r?(L=r("Instruments"),e[39]=r,e[40]=L):L=e[40],e[41]!==L?(g=t("h3",{className:"text-sm font-semibold text-foreground",children:L}),e[41]=L,e[42]=g):g=e[42],$=he,R="overflow-hidden py-0",q=ge,k="px-0",y=ct,C="mt-instruments-table";let U;e[43]!==r?(U=r("name"),e[43]=r,e[44]=U):U=e[44];let J;e[45]!==U?(J=t(de,{children:U}),e[45]=U,e[46]=J):J=e[46];let V;e[47]!==r?(V=r("kind"),e[47]=r,e[48]=V):V=e[48];let G;e[49]!==V?(G=t(de,{children:V}),e[49]=V,e[50]=G):G=e[50];let W;e[51]!==r?(W=r("value"),e[51]=r,e[52]=W):W=e[52];let X;e[53]!==W?(X=t(de,{className:"text-right",children:W}),e[53]=W,e[54]=X):X=e[54];let Y;e[55]!==r?(Y=r("count"),e[55]=r,e[56]=Y):Y=e[56];let Z;e[57]!==Y?(Z=t(de,{className:"text-right",children:Y}),e[57]=Y,e[58]=Z):Z=e[58];let ee;e[59]!==r?(ee=r("range"),e[59]=r,e[60]=ee):ee=e[60];let te;e[61]!==ee?(te=t(de,{className:"text-right",children:ee}),e[61]=ee,e[62]=te):te=e[62];let re;e[63]!==r?(re=r("trend"),e[63]=r,e[64]=re):re=e[64];let se;e[65]!==re?(se=t(de,{children:re}),e[65]=re,e[66]=se):se=e[66];let le;e[67]!==r?(le=r("trace"),e[67]=r,e[68]=le):le=e[68];let ae;e[69]!==le?(ae=t(de,{children:le}),e[69]=le,e[70]=ae):ae=e[70];let ie;e[71]!==r?(ie=r("dimensions"),e[71]=r,e[72]=ie):ie=e[72];let ne;e[73]!==ie?(ne=t(de,{children:ie}),e[73]=ie,e[74]=ne):ne=e[74],e[75]!==J||e[76]!==G||e[77]!==X||e[78]!==Z||e[79]!==te||e[80]!==se||e[81]!==ae||e[82]!==ne?(N=t(dt,{children:n(Je,{children:[J,G,X,Z,te,se,ae,ne]})}),e[75]=J,e[76]=G,e[77]=X,e[78]=Z,e[79]=te,e[80]=se,e[81]=ae,e[82]=ne,e[83]=N):N=e[83],h=mt,T=F.map(u=>{const K=Rt(u.attributes),j=ft(u.kind,u.name,u.attributes),Q=(E.get(j)??[]).map(ue=>Ut(u.kind,ue));return n(Je,{"data-testid":`mt-instrument-${u.name}`,children:[t(oe,{className:"font-mono text-xs",title:u.functionPath,children:u.name}),t(oe,{children:t(et,{variant:Xt[u.kind],children:P(u.kind)})}),t(oe,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${u.name}`,children:We(Jt(u))}),t(oe,{className:"text-right tabular-nums text-muted-foreground",children:u.count.toLocaleString()}),t(oe,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:u.min===u.max?"—":`${We(u.min)}–${We(u.max)}`}),t(oe,{children:Q.length>=2?t(ut,{ariaLabel:r("{name} trend",{name:u.name}),className:"h-6 w-24 text-foreground",series:Q,testId:`mt-instrument-trend-${u.name}`}):t("span",{className:"text-xs text-muted-foreground",children:"—"})}),t(oe,{className:"font-mono text-xs",children:t(Yt,{name:u.name,onOpenTrace:a,traceId:u.exemplarTraceId})}),t(oe,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:K,children:K===""?"—":K})]},j)})}e[6]=i,e[7]=S,e[8]=v,e[9]=m,e[10]=a,e[11]=r,e[12]=h,e[13]=y,e[14]=q,e[15]=$,e[16]=c,e[17]=p,e[18]=g,e[19]=x,e[20]=T,e[21]=C,e[22]=N,e[23]=k,e[24]=R}else h=e[12],y=e[13],q=e[14],$=e[15],c=e[16],p=e[17],g=e[18],x=e[19],T=e[20],C=e[21],N=e[22],k=e[23],R=e[24];if(x!==Symbol.for("react.early_return_sentinel"))return x;let M;e[84]!==h||e[85]!==T?(M=t(h,{children:T}),e[84]=h,e[85]=T,e[86]=M):M=e[86];let _;e[87]!==y||e[88]!==M||e[89]!==C||e[90]!==N?(_=n(y,{"data-testid":C,children:[N,M]}),e[87]=y,e[88]=M,e[89]=C,e[90]=N,e[91]=_):_=e[91];let b;e[92]!==q||e[93]!==_||e[94]!==k?(b=t(q,{className:k,children:_}),e[92]=q,e[93]=_,e[94]=k,e[95]=b):b=e[95];let I;e[96]!==$||e[97]!==b||e[98]!==R?(I=t($,{className:R,children:b}),e[96]=$,e[97]=b,e[98]=R,e[99]=I):I=e[99];let A;return e[100]!==c||e[101]!==p||e[102]!==g||e[103]!==I?(A=n("section",{className:c,"data-testid":p,children:[g,I]}),e[100]=c,e[101]=p,e[102]=g,e[103]=I,e[104]=A):A=e[104],A},er=l=>{const e=Ee(74),{aggregate:a,shardResults:s}=l,r=xe();let d;e[0]!==r?(d=r("Shards"),e[0]=r,e[1]=d):d=e[1];let o;e[2]!==a.failed||e[3]!==a.reachable||e[4]!==r?(o=a.failed>0?r("{reachable} reachable, {failed} unreachable",{failed:a.failed,reachable:a.reachable}):r("{reachable} reachable",{reachable:a.reachable}),e[2]=a.failed,e[3]=a.reachable,e[4]=r,e[5]=o):o=e[5];let i;e[6]!==d||e[7]!==o?(i=t(me,{label:d,testId:"mt-agg-shards",value:o}),e[6]=d,e[7]=o,e[8]=i):i=e[8];let S;e[9]!==r?(S=r("Total requests"),e[9]=r,e[10]=S):S=e[10];let v;e[11]!==a.totalRequests||e[12]!==S?(v=t(me,{label:S,testId:"mt-agg-requests",value:a.totalRequests}),e[11]=a.totalRequests,e[12]=S,e[13]=v):v=e[13];let w;e[14]!==r?(w=r("Total errors"),e[14]=r,e[15]=w):w=e[15];let f;e[16]!==a.totalErrors||e[17]!==w?(f=t(me,{label:w,testId:"mt-agg-errors",value:a.totalErrors}),e[16]=a.totalErrors,e[17]=w,e[18]=f):f=e[18];let m;e[19]!==r?(m=r("Total database size"),e[19]=r,e[20]=m):m=e[20];let h;e[21]!==a.totalDatabaseSize?(h=Xe(a.totalDatabaseSize),e[21]=a.totalDatabaseSize,e[22]=h):h=e[22];let y;e[23]!==m||e[24]!==h?(y=t(me,{label:m,testId:"mt-agg-db-size",value:h}),e[23]=m,e[24]=h,e[25]=y):y=e[25];let q;e[26]!==r?(q=r("Combined cache hit rate"),e[26]=r,e[27]=q):q=e[27];let $;e[28]!==a.hitRate||e[29]!==r?($=a.hitRate===null?r("no cache configured"):`${(a.hitRate*100).toFixed(1)}%`,e[28]=a.hitRate,e[29]=r,e[30]=$):$=e[30];let c;e[31]!==q||e[32]!==$?(c=t(me,{label:q,testId:"mt-agg-cache",value:$}),e[31]=q,e[32]=$,e[33]=c):c=e[33];let p;e[34]!==y||e[35]!==c||e[36]!==i||e[37]!==v||e[38]!==f?(p=n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[i,v,f,y,c]}),e[34]=y,e[35]=c,e[36]=i,e[37]=v,e[38]=f,e[39]=p):p=e[39];let g;e[40]!==r?(g=r("shard"),e[40]=r,e[41]=g):g=e[41];let x;e[42]!==g?(x=t(de,{children:g}),e[42]=g,e[43]=x):x=e[43];let T;e[44]!==r?(T=r("requests"),e[44]=r,e[45]=T):T=e[45];let C;e[46]!==T?(C=t(de,{children:T}),e[46]=T,e[47]=C):C=e[47];let N;e[48]!==r?(N=r("errors"),e[48]=r,e[49]=N):N=e[49];let k;e[50]!==N?(k=t(de,{children:N}),e[50]=N,e[51]=k):k=e[51];let R;e[52]!==r?(R=r("db size"),e[52]=r,e[53]=R):R=e[53];let M;e[54]!==R?(M=t(de,{children:R}),e[54]=R,e[55]=M):M=e[55];let _;e[56]!==x||e[57]!==C||e[58]!==k||e[59]!==M?(_=t(dt,{children:n(Je,{children:[x,C,k,M]})}),e[56]=x,e[57]=C,e[58]=k,e[59]=M,e[60]=_):_=e[60];let b;if(e[61]!==s||e[62]!==r){let O;e[64]!==r?(O=E=>n(Je,{"data-testid":`mt-agg-row-${E.shard}`,children:[t(oe,{children:E.shard}),E.metrics===null?t(oe,{className:"text-destructive",colSpan:3,children:E.error??r("unreachable")}):n(Ye,{children:[t(oe,{className:"tabular-nums",children:E.metrics.requests}),t(oe,{className:"tabular-nums",children:E.metrics.errors}),t(oe,{className:"tabular-nums",children:Xe(E.metrics.databaseSize)})]})]},E.shard),e[64]=r,e[65]=O):O=e[65],b=s.map(O),e[61]=s,e[62]=r,e[63]=b}else b=e[63];let I;e[66]!==b?(I=t(mt,{children:b}),e[66]=b,e[67]=I):I=e[67];let A;e[68]!==_||e[69]!==I?(A=t(he,{className:"overflow-hidden py-0",children:t(ge,{className:"px-0",children:n(ct,{"data-testid":"mt-agg-table",children:[_,I]})})}),e[68]=_,e[69]=I,e[70]=A):A=e[70];let F;return e[71]!==p||e[72]!==A?(F=n("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[p,A]}),e[71]=p,e[72]=A,e[73]=F):F=e[73],F},tr=l=>{const e=Math.floor(l/1e3),a=Math.floor(e/3600),s=Math.floor(e%3600/60),r=e%60;return a>0?`${a.toString()}h ${s.toString()}m`:s>0?`${s.toString()}m ${r.toString()}s`:`${r.toString()}s`},rr=(l,e)=>{const a=l+e;return a===0?"—":`${(l/a*100).toFixed(1)}%`},ot=l=>l<=0?"—":l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,sr=l=>{const e=Ee(75),{currentDelta:a,errorRate:s,history:r,latencyPercentiles:d,metrics:o}=l,i=xe();let S;e[0]!==r||e[1]!==i?(S=r.length>=2?t(ut,{ariaLabel:i("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:r,testId:"mt-sparkline"}):void 0,e[0]=r,e[1]=i,e[2]=S):S=e[2];let v;e[3]!==a||e[4]!==r.length||e[5]!==i?(v=r.length>=2?n(Ye,{children:[t("span",{className:"font-semibold text-foreground",children:`+${a.toLocaleString()}`})," ",i("last interval")]}):t("span",{"data-testid":"mt-sparkline-empty",children:i("collecting samples…")}),e[3]=a,e[4]=r.length,e[5]=i,e[6]=v):v=e[6];let w;e[7]!==i?(w=i("Requests"),e[7]=i,e[8]=w):w=e[8];let f;e[9]!==o.requests||e[10]!==S||e[11]!==v||e[12]!==w?(f=t(me,{chart:S,footer:v,label:w,testId:"mt-requests",value:o.requests}),e[9]=o.requests,e[10]=S,e[11]=v,e[12]=w,e[13]=f):f=e[13];let m;e[14]!==s||e[15]!==i?(m=i("{rate} error rate",{rate:s}),e[14]=s,e[15]=i,e[16]=m):m=e[16];let h;e[17]!==i?(h=i("Errors"),e[17]=i,e[18]=h):h=e[18];let y;e[19]!==s||e[20]!==o.errors?(y=n(Ye,{children:[o.errors," (",s,")"]}),e[19]=s,e[20]=o.errors,e[21]=y):y=e[21];let q;e[22]!==m||e[23]!==h||e[24]!==y?(q=t(me,{footer:m,label:h,testId:"mt-errors",value:y}),e[22]=m,e[23]=h,e[24]=y,e[25]=q):q=e[25];let $;e[26]!==d.p90?($=d.p90>0?`P90 ${ot(d.p90)}`:void 0,e[26]=d.p90,e[27]=$):$=e[27];let c;e[28]!==i?(c=i("P95 latency"),e[28]=i,e[29]=c):c=e[29];let p;e[30]!==d.p95?(p=d.p95>0?ot(d.p95):"—",e[30]=d.p95,e[31]=p):p=e[31];let g;e[32]!==c||e[33]!==p||e[34]!==$?(g=t(me,{footer:$,label:c,testId:"mt-p95",value:p}),e[32]=c,e[33]=p,e[34]=$,e[35]=g):g=e[35];let x;e[36]!==o.cache||e[37]!==i?(x=o.cache===null?void 0:`${o.cache.entries.toLocaleString()} ${i("cache entries")}`,e[36]=o.cache,e[37]=i,e[38]=x):x=e[38];let T;e[39]!==i?(T=i("Database size"),e[39]=i,e[40]=T):T=e[40];let C;e[41]!==o.databaseSize?(C=Xe(o.databaseSize),e[41]=o.databaseSize,e[42]=C):C=e[42];let N;e[43]!==x||e[44]!==T||e[45]!==C?(N=t(me,{footer:x,label:T,testId:"mt-db-size",value:C}),e[43]=x,e[44]=T,e[45]=C,e[46]=N):N=e[46];let k;e[47]!==i?(k=i("Shard"),e[47]=i,e[48]=k):k=e[48];let R;e[49]!==o.shard||e[50]!==k?(R=t(me,{label:k,testId:"mt-shard",value:o.shard}),e[49]=o.shard,e[50]=k,e[51]=R):R=e[51];let M;e[52]!==i?(M=i("Uptime"),e[52]=i,e[53]=M):M=e[53];let _;e[54]!==o.uptimeMs?(_=tr(o.uptimeMs),e[54]=o.uptimeMs,e[55]=_):_=e[55];let b;e[56]!==M||e[57]!==_?(b=t(me,{label:M,testId:"mt-uptime",value:_}),e[56]=M,e[57]=_,e[58]=b):b=e[58];let I;e[59]!==i?(I=i("Cache hit rate"),e[59]=i,e[60]=I):I=e[60];let A;e[61]!==o.cache||e[62]!==i?(A=o.cache===null?i("no cache configured"):i("{rate} ({count} entries)",{count:o.cache.entries,rate:rr(o.cache.hits,o.cache.misses)}),e[61]=o.cache,e[62]=i,e[63]=A):A=e[63];let F;e[64]!==I||e[65]!==A?(F=t(me,{label:I,testId:"mt-cache",value:A}),e[64]=I,e[65]=A,e[66]=F):F=e[66];let O;return e[67]!==g||e[68]!==N||e[69]!==R||e[70]!==b||e[71]!==F||e[72]!==f||e[73]!==q?(O=n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[f,q,g,N,R,b,F]}),e[67]=g,e[68]=N,e[69]=R,e[70]=b,e[71]=F,e[72]=f,e[73]=q,e[74]=O):O=e[74],O},Ve=l=>l>=100?"critical":l>=50?"warning":"good",Fe=l=>l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,He=l=>l>=1e9?`${(l/1e9).toFixed(1)}B`:l>=1e6?`${(l/1e6).toFixed(1)}M`:l>=1e3?`${(l/1e3).toFixed(1)}K`:l.toLocaleString(),lr=l=>{const e=Ee(3),{level:a}=l;if(a==="critical"){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=t(et,{variant:"destructive",children:"Slow"}),e[0]=r):r=e[0],r}if(a==="warning"){let r;return e[1]===Symbol.for("react.memo_cache_sentinel")?(r=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-warning/10 px-2 py-0.5 text-xs font-medium text-warning",children:"Moderate"}),e[1]=r):r=e[1],r}let s;return e[2]===Symbol.for("react.memo_cache_sentinel")?(s=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-success/10 px-2 py-0.5 text-xs font-medium text-success",children:"Fast"}),e[2]=s):s=e[2],s},ar=(l,e)=>{const a=[...l];return a.sort((s,r)=>{switch(e){case"avgTime":return r.avgDurationMs-s.avgDurationMs;case"execCount":return r.execCount-s.execCount;case"rowsRead":return r.rowsRead-s.rowsRead;default:return r.totalDurationMs-s.totalDurationMs}}),a},ir=l=>{const e=Ee(161),{queryStats:a}=l,s=xe(),[r,d]=pe("totalTime");let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=new Set,e[0]=o):o=e[0];const[i,S]=pe(o);let v;e[1]===Symbol.for("react.memo_cache_sentinel")?(v=R=>{R!==null&&d(R)},e[1]=v):v=e[1];const w=v;let f,m,h,y,q,$,c,p,g,x;if(e[2]!==i||e[3]!==a||e[4]!==r||e[5]!==s){h=Symbol.for("react.early_return_sentinel");e:{const R=ar(a,r);let M;e[16]!==a?(M=a.filter(nr),e[16]=a,e[17]=M):M=e[17];const _=M.length;let b;e[18]!==a?(b=a.filter(or),e[18]=a,e[19]=b):b=e[19];const I=b.length;let A;e[20]!==a?(A=a.filter(cr),e[20]=a,e[21]=A):A=e[21];const F=A.length;let O;e[22]===Symbol.for("react.memo_cache_sentinel")?(O=D=>{S(ce=>{const H=new Set(ce);return H.has(D)?H.delete(D):H.add(D),H})},e[22]=O):O=e[22];const E=O;if(a.length===0){let D;e[23]!==s?(D=s("No query insights yet"),e[23]=s,e[24]=D):D=e[24];let ce;e[25]!==D?(ce=t("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:D}),e[25]=D,e[26]=ce):ce=e[26];let H;e[27]!==s?(H=s("Query insights appear once statements are executed against this shard."),e[27]=s,e[28]=H):H=e[28];let fe;e[29]!==H?(fe=t("p",{className:"mt-1 text-sm",children:H}),e[29]=H,e[30]=fe):fe=e[30];let Pe;e[31]!==ce||e[32]!==fe?(Pe=t(he,{children:t(ge,{className:"py-12",children:n("div",{className:"text-center text-muted-foreground",children:[ce,fe]})})}),e[31]=ce,e[32]=fe,e[33]=Pe):Pe=e[33],h=Pe;break e}c="space-y-4",p="qi-root";let z;e[34]!==s?(z=s("Critical queries"),e[34]=s,e[35]=z):z=e[35];let P;e[36]!==z?(P=t(je,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:z})}),e[36]=z,e[37]=P):P=e[37];let L;e[38]!==_?(L=t("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:_}),e[38]=_,e[39]=L):L=e[39];let U;e[40]!==s?(U=s(">100ms avg execution"),e[40]=s,e[41]=U):U=e[41];let J;e[42]!==U?(J=t("p",{className:"text-xs text-muted-foreground",children:U}),e[42]=U,e[43]=J):J=e[43];let V;e[44]!==L||e[45]!==J?(V=n(ge,{children:[L,J]}),e[44]=L,e[45]=J,e[46]=V):V=e[46];let G;e[47]!==P||e[48]!==V?(G=n(he,{children:[P,V]}),e[47]=P,e[48]=V,e[49]=G):G=e[49];let W;e[50]!==s?(W=s("Moderate queries"),e[50]=s,e[51]=W):W=e[51];let X;e[52]!==W?(X=t(je,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:W})}),e[52]=W,e[53]=X):X=e[53];let Y;e[54]!==I?(Y=t("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:I}),e[54]=I,e[55]=Y):Y=e[55];let Z;e[56]!==s?(Z=s("50–100ms avg execution"),e[56]=s,e[57]=Z):Z=e[57];let ee;e[58]!==Z?(ee=t("p",{className:"text-xs text-muted-foreground",children:Z}),e[58]=Z,e[59]=ee):ee=e[59];let te;e[60]!==Y||e[61]!==ee?(te=n(ge,{children:[Y,ee]}),e[60]=Y,e[61]=ee,e[62]=te):te=e[62];let re;e[63]!==X||e[64]!==te?(re=n(he,{children:[X,te]}),e[63]=X,e[64]=te,e[65]=re):re=e[65];let se;e[66]!==s?(se=s("Fast queries"),e[66]=s,e[67]=se):se=e[67];let le;e[68]!==se?(le=t(je,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:se})}),e[68]=se,e[69]=le):le=e[69];let ae;e[70]!==F?(ae=t("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:F}),e[70]=F,e[71]=ae):ae=e[71];let ie;e[72]!==s?(ie=s("<50ms avg execution"),e[72]=s,e[73]=ie):ie=e[73];let ne;e[74]!==ie?(ne=t("p",{className:"text-xs text-muted-foreground",children:ie}),e[74]=ie,e[75]=ne):ne=e[75];let u;e[76]!==ae||e[77]!==ne?(u=n(ge,{children:[ae,ne]}),e[76]=ae,e[77]=ne,e[78]=u):u=e[78];let K;e[79]!==le||e[80]!==u?(K=n(he,{children:[le,u]}),e[79]=le,e[80]=u,e[81]=K):K=e[81],e[82]!==G||e[83]!==re||e[84]!==K?(g=n("div",{className:"grid gap-4 md:grid-cols-3",children:[G,re,K]}),e[82]=G,e[83]=re,e[84]=K,e[85]=g):g=e[85];let j;e[86]!==s?(j=s("Query leaderboard"),e[86]=s,e[87]=j):j=e[87];let B;e[88]!==j?(B=t("h3",{className:"text-lg font-semibold",children:j}),e[88]=j,e[89]=B):B=e[89];let Q;e[90]!==r||e[91]!==s?(Q=s("Slow queries sorted by {sortField}",{sortField:s(r)}),e[90]=r,e[91]=s,e[92]=Q):Q=e[92];let ue;e[93]!==Q?(ue=t("p",{className:"text-sm text-muted-foreground",children:Q}),e[93]=Q,e[94]=ue):ue=e[94];let be;e[95]!==B||e[96]!==ue?(be=n("div",{children:[B,ue]}),e[95]=B,e[96]=ue,e[97]=be):be=e[97];let ve;e[98]!==s?(ve=s("Sort by"),e[98]=s,e[99]=ve):ve=e[99];let ye;e[100]!==ve?(ye=t("span",{className:"text-sm text-muted-foreground",children:ve}),e[100]=ve,e[101]=ye):ye=e[101];let Ne;e[102]!==s?(Ne=s("Sort queries by"),e[102]=s,e[103]=Ne):Ne=e[103];let Oe;e[104]===Symbol.for("react.memo_cache_sentinel")?(Oe=t(Pt,{}),e[104]=Oe):Oe=e[104];let Se;e[105]!==Ne?(Se=t(jt,{"aria-label":Ne,className:"w-[140px]","data-testid":"qi-sort",children:Oe}),e[105]=Ne,e[106]=Se):Se=e[106];let we;e[107]!==s?(we=s("Total time"),e[107]=s,e[108]=we):we=e[108];let qe;e[109]!==we?(qe=t(Qe,{value:"totalTime",children:we}),e[109]=we,e[110]=qe):qe=e[110];let Te;e[111]!==s?(Te=s("Avg time"),e[111]=s,e[112]=Te):Te=e[112];let _e;e[113]!==Te?(_e=t(Qe,{value:"avgTime",children:Te}),e[113]=Te,e[114]=_e):_e=e[114];let $e;e[115]!==s?($e=s("Execution count"),e[115]=s,e[116]=$e):$e=e[116];let Ce;e[117]!==$e?(Ce=t(Qe,{value:"execCount",children:$e}),e[117]=$e,e[118]=Ce):Ce=e[118];let Re;e[119]!==s?(Re=s("Rows read"),e[119]=s,e[120]=Re):Re=e[120];let ke;e[121]!==Re?(ke=t(Qe,{value:"rowsRead",children:Re}),e[121]=Re,e[122]=ke):ke=e[122];let Me;e[123]!==qe||e[124]!==_e||e[125]!==Ce||e[126]!==ke?(Me=n(Bt,{children:[qe,_e,Ce,ke]}),e[123]=qe,e[124]=_e,e[125]=Ce,e[126]=ke,e[127]=Me):Me=e[127];let Ie;e[128]!==r||e[129]!==Se||e[130]!==Me?(Ie=n(Qt,{onValueChange:w,value:r,children:[Se,Me]}),e[128]=r,e[129]=Se,e[130]=Me,e[131]=Ie):Ie=e[131];let De;e[132]!==ye||e[133]!==Ie?(De=n("div",{className:"flex items-center gap-2",children:[ye,Ie]}),e[132]=ye,e[133]=Ie,e[134]=De):De=e[134],e[135]!==be||e[136]!==De?(x=n("div",{className:"flex items-center justify-between",children:[be,De]}),e[135]=be,e[136]=De,e[137]=x):x=e[137],m=he;let Ae;e[138]!==s?(Ae=s("Statements"),e[138]=s,e[139]=Ae):Ae=e[139];let ze;e[140]!==Ae?(ze=t(Be,{children:Ae}),e[140]=Ae,e[141]=ze):ze=e[141],$=n(je,{children:[ze,t(kt,{children:s("{count} tracked statements",{count:R.length})})]}),f=ge,y="space-y-2";let Ke;e[142]!==i||e[143]!==s?(Ke=D=>{const ce=D.normalizedSql,H=i.has(ce),fe=Ve(D.avgDurationMs);return n("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[n("button",{"aria-expanded":H,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:()=>{E(ce)},type:"button",children:[n("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t(lr,{level:fe}),t("span",{className:"max-w-[300px] truncate font-mono text-sm lg:max-w-[500px]",children:D.normalizedSql})]}),n("div",{className:"flex shrink-0 items-center gap-4",children:[n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Fe(D.totalDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("total")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Fe(D.avgDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("avg")})]}),D.p95DurationMs!==void 0&&n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Fe(D.p95DurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("p95")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:He(D.execCount)}),t("div",{className:"text-xs text-muted-foreground",children:s("calls")})]})]})]}),H&&n("div",{className:"space-y-3 border-t bg-muted/30 p-4",children:[n("div",{children:[t("p",{className:"mb-2 text-sm font-medium",children:s("Full statement")}),t("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:D.normalizedSql})]}),n("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[D.p50DurationMs!==void 0&&n("div",{children:[t("span",{className:"text-muted-foreground",children:s("p50")}),t("span",{className:"block font-medium tabular-nums",children:Fe(D.p50DurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Exec count")}),t("span",{className:"block font-medium tabular-nums",children:He(D.execCount)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Total time")}),t("span",{className:"block font-medium tabular-nums",children:Fe(D.totalDurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Rows read")}),t("span",{className:"block font-medium tabular-nums",children:He(D.rowsRead)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Rows written")}),t("span",{className:"block font-medium tabular-nums",children:He(D.rowsWritten)})]})]})]})]},ce)},e[142]=i,e[143]=s,e[144]=Ke):Ke=e[144],q=R.map(Ke)}e[2]=i,e[3]=a,e[4]=r,e[5]=s,e[6]=f,e[7]=m,e[8]=h,e[9]=y,e[10]=q,e[11]=$,e[12]=c,e[13]=p,e[14]=g,e[15]=x}else f=e[6],m=e[7],h=e[8],y=e[9],q=e[10],$=e[11],c=e[12],p=e[13],g=e[14],x=e[15];if(h!==Symbol.for("react.early_return_sentinel"))return h;let T;e[145]!==y||e[146]!==q?(T=t("div",{className:y,children:q}),e[145]=y,e[146]=q,e[147]=T):T=e[147];let C;e[148]!==f||e[149]!==T?(C=t(f,{children:T}),e[148]=f,e[149]=T,e[150]=C):C=e[150];let N;e[151]!==m||e[152]!==C||e[153]!==$?(N=n(m,{children:[$,C]}),e[151]=m,e[152]=C,e[153]=$,e[154]=N):N=e[154];let k;return e[155]!==N||e[156]!==c||e[157]!==p||e[158]!==g||e[159]!==x?(k=n("div",{className:c,"data-testid":p,children:[g,x,N]}),e[155]=N,e[156]=c,e[157]=p,e[158]=g,e[159]=x,e[160]=k):k=e[160],k};function nr(l){return Ve(l.avgDurationMs)==="critical"}function or(l){return Ve(l.avgDurationMs)==="warning"}function cr(l){return Ve(l.avgDurationMs)==="good"}const dr=["1m","5m","15m","1h"],mr=l=>new Date(l).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}),ur=l=>l.map(e=>({avg:Math.round(e.avgDurationMs*100)/100,execs:e.execCount,label:mr(e.bucketMs)})),fr=({shardKey:l=""})=>{const e=xe(),[a,s]=pe("15m"),d=Ue(Le.getQueryInsights,{range:a},{live:!0,shardKey:l}).data,o=ur(d?.buckets??[]);return n("div",{className:"flex flex-col gap-4","data-testid":"qi-range",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t("div",{className:"flex gap-1 rounded-lg border border-border p-0.5","data-testid":"qi-ranges",role:"group",children:dr.map(i=>t("button",{"aria-pressed":i===a,className:Kt("rounded px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",i===a&&"bg-accent font-medium text-foreground"),"data-testid":`qi-range-${i}`,onClick:()=>{s(i)},type:"button",children:i},i))}),d?.capped===!0&&t(et,{"data-testid":"qi-capped",variant:"secondary",children:e("showing a capped set")})]}),o.length===0?t(zt,{description:e("Statements executed in the selected window appear here, with throughput and latency over time."),testId:"qi-empty",title:e("No queries in this window.")}):n("div",{className:"grid gap-4 lg:grid-cols-2",children:[n("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-throughput",children:[t("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Throughput")}),t(st,{height:140,width:"100%",children:n(Et,{data:o,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(at,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{allowDecimals:!1,fontSize:10,tickLine:!1,width:32}),t(nt,{}),t(Ft,{dataKey:"execs",fill:"var(--color-primary)",fillOpacity:.15,stroke:"var(--color-primary)",type:"monotone"})]})})]}),n("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-latency",children:[t("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Mean latency (ms)")}),t(st,{height:140,width:"100%",children:n(Lt,{data:o,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(at,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{fontSize:10,tickLine:!1,width:32}),t(nt,{}),t(Ot,{dataKey:"avg",dot:!1,stroke:"var(--color-destructive)",type:"monotone"})]})})]})]}),t(ir,{queryStats:d?.entries??[]})]})},hr=_t(Le.getMetrics),gr=(l,e)=>l?e:"overview",jr=({initialShardKey:l})=>{const e=gt(),a=xe(),{queryShardKey:s,setShardKey:r,shardKey:d}=yt(l),[o,i]=pe("overview"),[S,v]=pe([]),w=Ge(null),f=Ge(null),m=Ge(!0);tt(()=>(m.current=!0,()=>{m.current=!1}),[]);const h=vt(s),{data:y,error:q,liveError:$}=Ue(Le.getMetrics,{},{live:!0,shardKey:s}),c=y??null;tt(()=>{if(y===void 0)return;$t(s);const E=y,z=w.current,P=f.current!==null&&f.current!==E.shard;if(f.current=E.shard,w.current=E.requests,P){v([]);return}z!==null&&E.requests>=z&&v(L=>[...L,E.requests-z].slice(-30))},[y,s]);const[p,g]=pe(null),[x,T]=pe(!1),C=async()=>{T(!0);const E=At(d,Ct());try{const z=await Promise.all(E.map(async P=>{try{const L=await e.query(hr,{},qt(P));return{error:null,metrics:L,shard:P===""?L.shard:P}}catch(L){return{error:Tt(L),metrics:null,shard:P===""?"__root__":P}}}));m.current&&g(z)}finally{m.current&&T(!1)}},N=p===null?null:Mt(p),k=c===null||c.requests===0?"—":`${(c.errors/c.requests*100).toFixed(1)}%`,R=S.length>0?S.at(-1):0,M=c?It(c):{p90:0,p95:0},_=pt(()=>{if(!c||!("queryStats"in c))return;const E=c.queryStats;if(!(!E||!Array.isArray(E)))return Dt(E)},[c]),b=gr(_!==void 0,o),I=()=>{wt(C())},A=()=>{g(null)},F=()=>{i("overview")},O=()=>{i("query-insights")};return n("div",{className:"flex flex-col gap-4","data-testid":"lunora-metrics",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t(bt,{onChange:r,testId:"mt-shard-input",value:d}),t(xt,{message:$,prefix:"mt"}),t(rt,{"data-testid":"mt-aggregate",disabled:x,onClick:I,size:"sm",type:"button",variant:"secondary",children:a(x?"Aggregating…":"All shards")}),p!==null&&t(rt,{"data-testid":"mt-aggregate-clear",onClick:A,size:"sm",type:"button",variant:"ghost",children:a("Hide")}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:Nt,rel:"noreferrer",target:"_blank",children:a("Open in Cloudflare")})]}),q!==null&&t("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:q}),_!==void 0&&n("div",{className:"flex gap-2 border-b","data-testid":"mt-tabs",children:[t("button",{className:`pb-2 text-sm font-medium transition-colors ${b==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:F,type:"button",children:a("Overview")}),n("button",{className:`pb-2 text-sm font-medium transition-colors ${b==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:O,type:"button",children:[a("Query insights"),_.length>0&&t("span",{className:"ml-1.5 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:_.length})]})]}),b==="query-insights"&&_!==void 0&&t(fr,{shardKey:s}),b==="overview"&&c!==null&&t(sr,{currentDelta:R,errorRate:k,history:S,latencyPercentiles:M,metrics:c}),b==="overview"&&c===null&&null,b==="overview"&&t(Zt,{onOpenTrace:h,shardKey:s}),b==="overview"&&N!==null&&p!==null&&t(er,{aggregate:N,shardResults:p})]})};export{jr as MetricsPanel};
1
+ import{useLunora as gt}from"@lunora/react";import{useState as pe,useRef as Ge,useEffect as tt,useMemo as pt}from"react";import{L as xt}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as bt}from"../packem_shared/ShardInput-XumEzeT0.js";import{B as rt}from"../packem_shared/button-BOPLD1un.js";import{u as Ue}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{u as yt}from"../packem_shared/use-open-trace-IfIlKEWd.js";import{u as vt}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as xe}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as Fe}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{c as Nt}from"../packem_shared/cf-links-CBJ5SywP.js";import{m as St,l as Xe,f as wt,d as qt,b as Tt,c as _t}from"../packem_shared/internal-7bgd8inO.js";import{r as $t,l as Ct}from"../packem_shared/shard-history-QcjcMnCA.js";import{c as Oe}from"react/compiler-runtime";import{f as Rt}from"../packem_shared/log-fields-SBxKyBug.js";import{B as et}from"../packem_shared/badge-cAk9Di1Q.js";import{C as he,a as ge,c as Pe,d as kt,b as Be}from"../packem_shared/card-BGlQzQY-.js";import{b as Je,e as oe,T as ct,c as de,a as dt,d as mt}from"../packem_shared/table-BMsuYFhk.js";import{S as ut}from"../packem_shared/sparkline-BreIqzDO.js";import{jsxs as n,jsx as t,Fragment as Ye}from"react/jsx-runtime";import{aggregateMetrics as Mt,computeLatencyPercentiles as It,enrichQueryStats as Dt,shardsToAggregate as At}from"../packem_shared/aggregateMetrics-A-Y7OH6R.js";import{S as me}from"../packem_shared/stat-card-B9uIvAHg.js";import{ResponsiveContainer as st,AreaChart as Ot,CartesianGrid as lt,XAxis as at,YAxis as it,Tooltip as nt,Area as Et,LineChart as Ft,Line as Lt}from"recharts";import{E as zt}from"../packem_shared/empty-state-B939z6K2.js";import{c as Kt}from"../packem_shared/utils-bhneXptQ.js";import{S as jt,a as Pt,c as Qe,b as Bt,d as Qt}from"../packem_shared/select-BPISLTcv.js";const Ht=(l,e)=>l<e?-1:l>e?1:0,Ze=l=>{if(l===void 0)return"null";if(typeof l=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(typeof l=="number"){if(Number.isNaN(l))return"nan";if(l===1/0)return"inf";if(l===-1/0)return"-inf";if(Object.is(l,-0))return"-0"}if(l===null||typeof l!="object")return JSON.stringify(l);if(Array.isArray(l))return`[${l.map(d=>Ze(d)).join(",")}]`;const e=Object.getPrototypeOf(l);if(e!==null&&e!==Object.prototype){const d=l.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${d} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const a=l,s=Object.keys(a).toSorted(Ht),r=[];for(const d of s){const o=a[d];o!==void 0&&r.push(`${JSON.stringify(d)}:${Ze(o)}`)}return`{${r.join(",")}}`},ft=(l,e,a)=>`${l}:${e}:${Ze(a??{})}`,ht=(l,e)=>l==="gauge"?e.last:l==="histogram"?e.sum/Math.max(1,e.count):e.sum,Ut=(l,e)=>ht(l,e),Jt=l=>ht(l.kind,l),We=l=>Number.isInteger(l)?l.toLocaleString():l.toLocaleString(void 0,{maximumFractionDigits:2}),Vt=l=>Array.isArray(l?.series)?l.series:[],Gt="FUNCTION_NOT_FOUND",Wt=l=>{const e=new Map;if(!Array.isArray(l?.series))return e;for(const a of l.series)e.set(ft(a.kind,a.name,a.attributes),a.points);return e},Xt={counter:"secondary",gauge:"default",histogram:"outline"},Yt=l=>{const e=Oe(18),{name:a,onOpenTrace:s,traceId:r}=l,d=xe();if(r===void 0){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=t("span",{className:"text-muted-foreground",children:"—"}),e[0]=m):m=e[0],m}let o;e[1]!==r?(o=r.slice(0,8),e[1]=r,e[2]=o):o=e[2];const i=o;if(s===void 0){const m=`mt-instrument-trace-${a}`;let h;return e[3]!==i||e[4]!==m||e[5]!==r?(h=t("span",{className:"text-muted-foreground","data-testid":m,title:r,children:i}),e[3]=i,e[4]=m,e[5]=r,e[6]=h):h=e[6],h}const S=`mt-instrument-trace-${a}`;let y;e[7]!==s||e[8]!==r?(y=()=>{s(r)},e[7]=s,e[8]=r,e[9]=y):y=e[9];let w;e[10]!==d||e[11]!==r?(w=d("Open the exemplar trace {trace}",{trace:r}),e[10]=d,e[11]=r,e[12]=w):w=e[12];let f;return e[13]!==i||e[14]!==S||e[15]!==y||e[16]!==w?(f=t("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":S,onClick:y,title:w,type:"button",children:i}),e[13]=i,e[14]=S,e[15]=y,e[16]=w,e[17]=f):f=e[17],f},Zt=l=>{const e=Oe(105),{onOpenTrace:a,shardKey:s}=l,r=xe();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];let o;e[1]!==s?(o={live:!0,shardKey:s},e[1]=s,e[2]=o):o=e[2];const{data:i,error:S,errorSource:y}=Ue(Fe.getMetricSeries,d,o);let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w={},e[3]=w):w=e[3];let f;e[4]!==s?(f={live:!0,shardKey:s},e[4]=s,e[5]=f):f=e[5];const{data:m}=Ue(Fe.getMetricHistory,w,f);let h,v,q,$,c,p,g,x,T,C,N,k,R;if(e[6]!==i||e[7]!==S||e[8]!==y||e[9]!==m||e[10]!==a||e[11]!==r){x=Symbol.for("react.early_return_sentinel");e:{const E=Vt(i),L=St(y)===Gt;if(S!==null&&!L){let u;e[25]!==r?(u=r("Instruments"),e[25]=r,e[26]=u):u=e[26];let K;e[27]!==u?(K=t("h3",{className:"text-sm font-semibold text-foreground",children:u}),e[27]=u,e[28]=K):K=e[28];let P;e[29]!==S||e[30]!==r?(P=r("Instruments unavailable: {error}",{error:S}),e[29]=S,e[30]=r,e[31]=P):P=e[31];let B;e[32]!==P?(B=t("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:P}),e[32]=P,e[33]=B):B=e[33];let Q;e[34]!==K||e[35]!==B?(Q=n("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[K,B]}),e[34]=K,e[35]=B,e[36]=Q):Q=e[36],x=Q;break e}if(E.length===0){x=null;break e}const O=Wt(m);let z;e[37]!==r?(z=u=>r(u==="counter"?"Counter":u==="gauge"?"Gauge":"Histogram"),e[37]=r,e[38]=z):z=e[38];const j=z;c="flex flex-col gap-2",p="mt-instruments";let F;e[39]!==r?(F=r("Instruments"),e[39]=r,e[40]=F):F=e[40],e[41]!==F?(g=t("h3",{className:"text-sm font-semibold text-foreground",children:F}),e[41]=F,e[42]=g):g=e[42],$=he,R="overflow-hidden py-0",q=ge,k="px-0",v=ct,C="mt-instruments-table";let U;e[43]!==r?(U=r("name"),e[43]=r,e[44]=U):U=e[44];let J;e[45]!==U?(J=t(de,{children:U}),e[45]=U,e[46]=J):J=e[46];let V;e[47]!==r?(V=r("kind"),e[47]=r,e[48]=V):V=e[48];let G;e[49]!==V?(G=t(de,{children:V}),e[49]=V,e[50]=G):G=e[50];let W;e[51]!==r?(W=r("value"),e[51]=r,e[52]=W):W=e[52];let X;e[53]!==W?(X=t(de,{className:"text-right",children:W}),e[53]=W,e[54]=X):X=e[54];let Y;e[55]!==r?(Y=r("count"),e[55]=r,e[56]=Y):Y=e[56];let Z;e[57]!==Y?(Z=t(de,{className:"text-right",children:Y}),e[57]=Y,e[58]=Z):Z=e[58];let ee;e[59]!==r?(ee=r("range"),e[59]=r,e[60]=ee):ee=e[60];let te;e[61]!==ee?(te=t(de,{className:"text-right",children:ee}),e[61]=ee,e[62]=te):te=e[62];let re;e[63]!==r?(re=r("trend"),e[63]=r,e[64]=re):re=e[64];let se;e[65]!==re?(se=t(de,{children:re}),e[65]=re,e[66]=se):se=e[66];let le;e[67]!==r?(le=r("trace"),e[67]=r,e[68]=le):le=e[68];let ae;e[69]!==le?(ae=t(de,{children:le}),e[69]=le,e[70]=ae):ae=e[70];let ie;e[71]!==r?(ie=r("dimensions"),e[71]=r,e[72]=ie):ie=e[72];let ne;e[73]!==ie?(ne=t(de,{children:ie}),e[73]=ie,e[74]=ne):ne=e[74],e[75]!==J||e[76]!==G||e[77]!==X||e[78]!==Z||e[79]!==te||e[80]!==se||e[81]!==ae||e[82]!==ne?(N=t(dt,{children:n(Je,{children:[J,G,X,Z,te,se,ae,ne]})}),e[75]=J,e[76]=G,e[77]=X,e[78]=Z,e[79]=te,e[80]=se,e[81]=ae,e[82]=ne,e[83]=N):N=e[83],h=mt,T=E.map(u=>{const K=Rt(u.attributes),P=ft(u.kind,u.name,u.attributes),Q=(O.get(P)??[]).map(ue=>Ut(u.kind,ue));return n(Je,{"data-testid":`mt-instrument-${u.name}`,children:[t(oe,{className:"font-mono text-xs",title:u.functionPath,children:u.name}),t(oe,{children:t(et,{variant:Xt[u.kind],children:j(u.kind)})}),t(oe,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${u.name}`,children:We(Jt(u))}),t(oe,{className:"text-right tabular-nums text-muted-foreground",children:u.count.toLocaleString()}),t(oe,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:u.min===u.max?"—":`${We(u.min)}–${We(u.max)}`}),t(oe,{children:Q.length>=2?t(ut,{ariaLabel:r("{name} trend",{name:u.name}),className:"h-6 w-24 text-foreground",series:Q,testId:`mt-instrument-trend-${u.name}`}):t("span",{className:"text-xs text-muted-foreground",children:"—"})}),t(oe,{className:"font-mono text-xs",children:t(Yt,{name:u.name,onOpenTrace:a,traceId:u.exemplarTraceId})}),t(oe,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:K,children:K===""?"—":K})]},P)})}e[6]=i,e[7]=S,e[8]=y,e[9]=m,e[10]=a,e[11]=r,e[12]=h,e[13]=v,e[14]=q,e[15]=$,e[16]=c,e[17]=p,e[18]=g,e[19]=x,e[20]=T,e[21]=C,e[22]=N,e[23]=k,e[24]=R}else h=e[12],v=e[13],q=e[14],$=e[15],c=e[16],p=e[17],g=e[18],x=e[19],T=e[20],C=e[21],N=e[22],k=e[23],R=e[24];if(x!==Symbol.for("react.early_return_sentinel"))return x;let M;e[84]!==h||e[85]!==T?(M=t(h,{children:T}),e[84]=h,e[85]=T,e[86]=M):M=e[86];let _;e[87]!==v||e[88]!==M||e[89]!==C||e[90]!==N?(_=n(v,{"data-testid":C,children:[N,M]}),e[87]=v,e[88]=M,e[89]=C,e[90]=N,e[91]=_):_=e[91];let b;e[92]!==q||e[93]!==_||e[94]!==k?(b=t(q,{className:k,children:_}),e[92]=q,e[93]=_,e[94]=k,e[95]=b):b=e[95];let I;e[96]!==$||e[97]!==b||e[98]!==R?(I=t($,{className:R,children:b}),e[96]=$,e[97]=b,e[98]=R,e[99]=I):I=e[99];let A;return e[100]!==c||e[101]!==p||e[102]!==g||e[103]!==I?(A=n("section",{className:c,"data-testid":p,children:[g,I]}),e[100]=c,e[101]=p,e[102]=g,e[103]=I,e[104]=A):A=e[104],A},er=l=>{const e=Oe(74),{aggregate:a,shardResults:s}=l,r=xe();let d;e[0]!==r?(d=r("Shards"),e[0]=r,e[1]=d):d=e[1];let o;e[2]!==a.failed||e[3]!==a.reachable||e[4]!==r?(o=a.failed>0?r("{reachable} reachable, {failed} unreachable",{failed:a.failed,reachable:a.reachable}):r("{reachable} reachable",{reachable:a.reachable}),e[2]=a.failed,e[3]=a.reachable,e[4]=r,e[5]=o):o=e[5];let i;e[6]!==d||e[7]!==o?(i=t(me,{label:d,testId:"mt-agg-shards",value:o}),e[6]=d,e[7]=o,e[8]=i):i=e[8];let S;e[9]!==r?(S=r("Total requests"),e[9]=r,e[10]=S):S=e[10];let y;e[11]!==a.totalRequests||e[12]!==S?(y=t(me,{label:S,testId:"mt-agg-requests",value:a.totalRequests}),e[11]=a.totalRequests,e[12]=S,e[13]=y):y=e[13];let w;e[14]!==r?(w=r("Total errors"),e[14]=r,e[15]=w):w=e[15];let f;e[16]!==a.totalErrors||e[17]!==w?(f=t(me,{label:w,testId:"mt-agg-errors",value:a.totalErrors}),e[16]=a.totalErrors,e[17]=w,e[18]=f):f=e[18];let m;e[19]!==r?(m=r("Total database size"),e[19]=r,e[20]=m):m=e[20];let h;e[21]!==a.totalDatabaseSize?(h=Xe(a.totalDatabaseSize),e[21]=a.totalDatabaseSize,e[22]=h):h=e[22];let v;e[23]!==m||e[24]!==h?(v=t(me,{label:m,testId:"mt-agg-db-size",value:h}),e[23]=m,e[24]=h,e[25]=v):v=e[25];let q;e[26]!==r?(q=r("Combined cache hit rate"),e[26]=r,e[27]=q):q=e[27];let $;e[28]!==a.hitRate||e[29]!==r?($=a.hitRate===null?r("no cache configured"):`${(a.hitRate*100).toFixed(1)}%`,e[28]=a.hitRate,e[29]=r,e[30]=$):$=e[30];let c;e[31]!==q||e[32]!==$?(c=t(me,{label:q,testId:"mt-agg-cache",value:$}),e[31]=q,e[32]=$,e[33]=c):c=e[33];let p;e[34]!==v||e[35]!==c||e[36]!==i||e[37]!==y||e[38]!==f?(p=n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[i,y,f,v,c]}),e[34]=v,e[35]=c,e[36]=i,e[37]=y,e[38]=f,e[39]=p):p=e[39];let g;e[40]!==r?(g=r("shard"),e[40]=r,e[41]=g):g=e[41];let x;e[42]!==g?(x=t(de,{children:g}),e[42]=g,e[43]=x):x=e[43];let T;e[44]!==r?(T=r("requests"),e[44]=r,e[45]=T):T=e[45];let C;e[46]!==T?(C=t(de,{children:T}),e[46]=T,e[47]=C):C=e[47];let N;e[48]!==r?(N=r("errors"),e[48]=r,e[49]=N):N=e[49];let k;e[50]!==N?(k=t(de,{children:N}),e[50]=N,e[51]=k):k=e[51];let R;e[52]!==r?(R=r("db size"),e[52]=r,e[53]=R):R=e[53];let M;e[54]!==R?(M=t(de,{children:R}),e[54]=R,e[55]=M):M=e[55];let _;e[56]!==x||e[57]!==C||e[58]!==k||e[59]!==M?(_=t(dt,{children:n(Je,{children:[x,C,k,M]})}),e[56]=x,e[57]=C,e[58]=k,e[59]=M,e[60]=_):_=e[60];let b;if(e[61]!==s||e[62]!==r){let L;e[64]!==r?(L=O=>n(Je,{"data-testid":`mt-agg-row-${O.shard}`,children:[t(oe,{children:O.shard}),O.metrics===null?t(oe,{className:"text-destructive",colSpan:3,children:O.error??r("unreachable")}):n(Ye,{children:[t(oe,{className:"tabular-nums",children:O.metrics.requests}),t(oe,{className:"tabular-nums",children:O.metrics.errors}),t(oe,{className:"tabular-nums",children:Xe(O.metrics.databaseSize)})]})]},O.shard),e[64]=r,e[65]=L):L=e[65],b=s.map(L),e[61]=s,e[62]=r,e[63]=b}else b=e[63];let I;e[66]!==b?(I=t(mt,{children:b}),e[66]=b,e[67]=I):I=e[67];let A;e[68]!==_||e[69]!==I?(A=t(he,{className:"overflow-hidden py-0",children:t(ge,{className:"px-0",children:n(ct,{"data-testid":"mt-agg-table",children:[_,I]})})}),e[68]=_,e[69]=I,e[70]=A):A=e[70];let E;return e[71]!==p||e[72]!==A?(E=n("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[p,A]}),e[71]=p,e[72]=A,e[73]=E):E=e[73],E},tr=l=>{const e=Math.floor(l/1e3),a=Math.floor(e/3600),s=Math.floor(e%3600/60),r=e%60;return a>0?`${a.toString()}h ${s.toString()}m`:s>0?`${s.toString()}m ${r.toString()}s`:`${r.toString()}s`},rr=(l,e)=>{const a=l+e;return a===0?"—":`${(l/a*100).toFixed(1)}%`},ot=l=>l<=0?"—":l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,sr=l=>{const e=Oe(75),{currentDelta:a,errorRate:s,history:r,latencyPercentiles:d,metrics:o}=l,i=xe();let S;e[0]!==r||e[1]!==i?(S=r.length>=2?t(ut,{ariaLabel:i("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:r,testId:"mt-sparkline"}):void 0,e[0]=r,e[1]=i,e[2]=S):S=e[2];let y;e[3]!==a||e[4]!==r.length||e[5]!==i?(y=r.length>=2?n(Ye,{children:[t("span",{className:"font-semibold text-foreground",children:`+${a.toLocaleString()}`})," ",i("last interval")]}):t("span",{"data-testid":"mt-sparkline-empty",children:i("collecting samples…")}),e[3]=a,e[4]=r.length,e[5]=i,e[6]=y):y=e[6];let w;e[7]!==i?(w=i("Requests"),e[7]=i,e[8]=w):w=e[8];let f;e[9]!==o.requests||e[10]!==S||e[11]!==y||e[12]!==w?(f=t(me,{chart:S,footer:y,label:w,testId:"mt-requests",value:o.requests}),e[9]=o.requests,e[10]=S,e[11]=y,e[12]=w,e[13]=f):f=e[13];let m;e[14]!==s||e[15]!==i?(m=i("{rate} error rate",{rate:s}),e[14]=s,e[15]=i,e[16]=m):m=e[16];let h;e[17]!==i?(h=i("Errors"),e[17]=i,e[18]=h):h=e[18];let v;e[19]!==s||e[20]!==o.errors?(v=n(Ye,{children:[o.errors," (",s,")"]}),e[19]=s,e[20]=o.errors,e[21]=v):v=e[21];let q;e[22]!==m||e[23]!==h||e[24]!==v?(q=t(me,{footer:m,label:h,testId:"mt-errors",value:v}),e[22]=m,e[23]=h,e[24]=v,e[25]=q):q=e[25];let $;e[26]!==d.p90?($=d.p90>0?`P90 ${ot(d.p90)}`:void 0,e[26]=d.p90,e[27]=$):$=e[27];let c;e[28]!==i?(c=i("P95 latency"),e[28]=i,e[29]=c):c=e[29];let p;e[30]!==d.p95?(p=d.p95>0?ot(d.p95):"—",e[30]=d.p95,e[31]=p):p=e[31];let g;e[32]!==c||e[33]!==p||e[34]!==$?(g=t(me,{footer:$,label:c,testId:"mt-p95",value:p}),e[32]=c,e[33]=p,e[34]=$,e[35]=g):g=e[35];let x;e[36]!==o.cache||e[37]!==i?(x=o.cache===null?void 0:`${o.cache.entries.toLocaleString()} ${i("cache entries")}`,e[36]=o.cache,e[37]=i,e[38]=x):x=e[38];let T;e[39]!==i?(T=i("Database size"),e[39]=i,e[40]=T):T=e[40];let C;e[41]!==o.databaseSize?(C=Xe(o.databaseSize),e[41]=o.databaseSize,e[42]=C):C=e[42];let N;e[43]!==x||e[44]!==T||e[45]!==C?(N=t(me,{footer:x,label:T,testId:"mt-db-size",value:C}),e[43]=x,e[44]=T,e[45]=C,e[46]=N):N=e[46];let k;e[47]!==i?(k=i("Shard"),e[47]=i,e[48]=k):k=e[48];let R;e[49]!==o.shard||e[50]!==k?(R=t(me,{label:k,testId:"mt-shard",value:o.shard}),e[49]=o.shard,e[50]=k,e[51]=R):R=e[51];let M;e[52]!==i?(M=i("Uptime"),e[52]=i,e[53]=M):M=e[53];let _;e[54]!==o.uptimeMs?(_=tr(o.uptimeMs),e[54]=o.uptimeMs,e[55]=_):_=e[55];let b;e[56]!==M||e[57]!==_?(b=t(me,{label:M,testId:"mt-uptime",value:_}),e[56]=M,e[57]=_,e[58]=b):b=e[58];let I;e[59]!==i?(I=i("Cache hit rate"),e[59]=i,e[60]=I):I=e[60];let A;e[61]!==o.cache||e[62]!==i?(A=o.cache===null?i("no cache configured"):i("{rate} ({count} entries)",{count:o.cache.entries,rate:rr(o.cache.hits,o.cache.misses)}),e[61]=o.cache,e[62]=i,e[63]=A):A=e[63];let E;e[64]!==I||e[65]!==A?(E=t(me,{label:I,testId:"mt-cache",value:A}),e[64]=I,e[65]=A,e[66]=E):E=e[66];let L;return e[67]!==g||e[68]!==N||e[69]!==R||e[70]!==b||e[71]!==E||e[72]!==f||e[73]!==q?(L=n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[f,q,g,N,R,b,E]}),e[67]=g,e[68]=N,e[69]=R,e[70]=b,e[71]=E,e[72]=f,e[73]=q,e[74]=L):L=e[74],L},Ve=l=>l>=100?"critical":l>=50?"warning":"good",Ee=l=>l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,He=l=>l>=1e9?`${(l/1e9).toFixed(1)}B`:l>=1e6?`${(l/1e6).toFixed(1)}M`:l>=1e3?`${(l/1e3).toFixed(1)}K`:l.toLocaleString(),lr=l=>{const e=Oe(3),{level:a}=l;if(a==="critical"){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=t(et,{variant:"destructive",children:"Slow"}),e[0]=r):r=e[0],r}if(a==="warning"){let r;return e[1]===Symbol.for("react.memo_cache_sentinel")?(r=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-warning/10 px-2 py-0.5 text-xs font-medium text-warning",children:"Moderate"}),e[1]=r):r=e[1],r}let s;return e[2]===Symbol.for("react.memo_cache_sentinel")?(s=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-success/10 px-2 py-0.5 text-xs font-medium text-success",children:"Fast"}),e[2]=s):s=e[2],s},ar=(l,e)=>{const a=[...l];return a.sort((s,r)=>{switch(e){case"avgTime":return r.avgDurationMs-s.avgDurationMs;case"execCount":return r.execCount-s.execCount;case"rowsRead":return r.rowsRead-s.rowsRead;default:return r.totalDurationMs-s.totalDurationMs}}),a},ir=l=>{const e=Oe(161),{queryStats:a}=l,s=xe(),[r,d]=pe("totalTime");let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=new Set,e[0]=o):o=e[0];const[i,S]=pe(o);let y;e[1]===Symbol.for("react.memo_cache_sentinel")?(y=R=>{R!==null&&d(R)},e[1]=y):y=e[1];const w=y;let f,m,h,v,q,$,c,p,g,x;if(e[2]!==i||e[3]!==a||e[4]!==r||e[5]!==s){h=Symbol.for("react.early_return_sentinel");e:{const R=ar(a,r);let M;e[16]!==a?(M=a.filter(nr),e[16]=a,e[17]=M):M=e[17];const _=M.length;let b;e[18]!==a?(b=a.filter(or),e[18]=a,e[19]=b):b=e[19];const I=b.length;let A;e[20]!==a?(A=a.filter(cr),e[20]=a,e[21]=A):A=e[21];const E=A.length;let L;e[22]===Symbol.for("react.memo_cache_sentinel")?(L=D=>{S(ce=>{const H=new Set(ce);return H.has(D)?H.delete(D):H.add(D),H})},e[22]=L):L=e[22];const O=L;if(a.length===0){let D;e[23]!==s?(D=s("No query insights yet"),e[23]=s,e[24]=D):D=e[24];let ce;e[25]!==D?(ce=t("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:D}),e[25]=D,e[26]=ce):ce=e[26];let H;e[27]!==s?(H=s("Query insights appear once statements are executed against this shard."),e[27]=s,e[28]=H):H=e[28];let fe;e[29]!==H?(fe=t("p",{className:"mt-1 text-sm",children:H}),e[29]=H,e[30]=fe):fe=e[30];let je;e[31]!==ce||e[32]!==fe?(je=t(he,{children:t(ge,{className:"py-12",children:n("div",{className:"text-center text-muted-foreground",children:[ce,fe]})})}),e[31]=ce,e[32]=fe,e[33]=je):je=e[33],h=je;break e}c="space-y-4",p="qi-root";let z;e[34]!==s?(z=s("Critical queries"),e[34]=s,e[35]=z):z=e[35];let j;e[36]!==z?(j=t(Pe,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:z})}),e[36]=z,e[37]=j):j=e[37];let F;e[38]!==_?(F=t("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:_}),e[38]=_,e[39]=F):F=e[39];let U;e[40]!==s?(U=s(">100ms avg execution"),e[40]=s,e[41]=U):U=e[41];let J;e[42]!==U?(J=t("p",{className:"text-xs text-muted-foreground",children:U}),e[42]=U,e[43]=J):J=e[43];let V;e[44]!==F||e[45]!==J?(V=n(ge,{children:[F,J]}),e[44]=F,e[45]=J,e[46]=V):V=e[46];let G;e[47]!==j||e[48]!==V?(G=n(he,{children:[j,V]}),e[47]=j,e[48]=V,e[49]=G):G=e[49];let W;e[50]!==s?(W=s("Moderate queries"),e[50]=s,e[51]=W):W=e[51];let X;e[52]!==W?(X=t(Pe,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:W})}),e[52]=W,e[53]=X):X=e[53];let Y;e[54]!==I?(Y=t("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:I}),e[54]=I,e[55]=Y):Y=e[55];let Z;e[56]!==s?(Z=s("50–100ms avg execution"),e[56]=s,e[57]=Z):Z=e[57];let ee;e[58]!==Z?(ee=t("p",{className:"text-xs text-muted-foreground",children:Z}),e[58]=Z,e[59]=ee):ee=e[59];let te;e[60]!==Y||e[61]!==ee?(te=n(ge,{children:[Y,ee]}),e[60]=Y,e[61]=ee,e[62]=te):te=e[62];let re;e[63]!==X||e[64]!==te?(re=n(he,{children:[X,te]}),e[63]=X,e[64]=te,e[65]=re):re=e[65];let se;e[66]!==s?(se=s("Fast queries"),e[66]=s,e[67]=se):se=e[67];let le;e[68]!==se?(le=t(Pe,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:se})}),e[68]=se,e[69]=le):le=e[69];let ae;e[70]!==E?(ae=t("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:E}),e[70]=E,e[71]=ae):ae=e[71];let ie;e[72]!==s?(ie=s("<50ms avg execution"),e[72]=s,e[73]=ie):ie=e[73];let ne;e[74]!==ie?(ne=t("p",{className:"text-xs text-muted-foreground",children:ie}),e[74]=ie,e[75]=ne):ne=e[75];let u;e[76]!==ae||e[77]!==ne?(u=n(ge,{children:[ae,ne]}),e[76]=ae,e[77]=ne,e[78]=u):u=e[78];let K;e[79]!==le||e[80]!==u?(K=n(he,{children:[le,u]}),e[79]=le,e[80]=u,e[81]=K):K=e[81],e[82]!==G||e[83]!==re||e[84]!==K?(g=n("div",{className:"grid gap-4 md:grid-cols-3",children:[G,re,K]}),e[82]=G,e[83]=re,e[84]=K,e[85]=g):g=e[85];let P;e[86]!==s?(P=s("Query leaderboard"),e[86]=s,e[87]=P):P=e[87];let B;e[88]!==P?(B=t("h3",{className:"text-lg font-semibold",children:P}),e[88]=P,e[89]=B):B=e[89];let Q;e[90]!==r||e[91]!==s?(Q=s("Slow queries sorted by {sortField}",{sortField:s(r)}),e[90]=r,e[91]=s,e[92]=Q):Q=e[92];let ue;e[93]!==Q?(ue=t("p",{className:"text-sm text-muted-foreground",children:Q}),e[93]=Q,e[94]=ue):ue=e[94];let be;e[95]!==B||e[96]!==ue?(be=n("div",{children:[B,ue]}),e[95]=B,e[96]=ue,e[97]=be):be=e[97];let ye;e[98]!==s?(ye=s("Sort by"),e[98]=s,e[99]=ye):ye=e[99];let ve;e[100]!==ye?(ve=t("span",{className:"text-sm text-muted-foreground",children:ye}),e[100]=ye,e[101]=ve):ve=e[101];let Ne;e[102]!==s?(Ne=s("Sort queries by"),e[102]=s,e[103]=Ne):Ne=e[103];let Le;e[104]===Symbol.for("react.memo_cache_sentinel")?(Le=t(jt,{}),e[104]=Le):Le=e[104];let Se;e[105]!==Ne?(Se=t(Pt,{"aria-label":Ne,className:"w-[140px]","data-testid":"qi-sort",children:Le}),e[105]=Ne,e[106]=Se):Se=e[106];let we;e[107]!==s?(we=s("Total time"),e[107]=s,e[108]=we):we=e[108];let qe;e[109]!==we?(qe=t(Qe,{value:"totalTime",children:we}),e[109]=we,e[110]=qe):qe=e[110];let Te;e[111]!==s?(Te=s("Avg time"),e[111]=s,e[112]=Te):Te=e[112];let _e;e[113]!==Te?(_e=t(Qe,{value:"avgTime",children:Te}),e[113]=Te,e[114]=_e):_e=e[114];let $e;e[115]!==s?($e=s("Execution count"),e[115]=s,e[116]=$e):$e=e[116];let Ce;e[117]!==$e?(Ce=t(Qe,{value:"execCount",children:$e}),e[117]=$e,e[118]=Ce):Ce=e[118];let Re;e[119]!==s?(Re=s("Rows read"),e[119]=s,e[120]=Re):Re=e[120];let ke;e[121]!==Re?(ke=t(Qe,{value:"rowsRead",children:Re}),e[121]=Re,e[122]=ke):ke=e[122];let Me;e[123]!==qe||e[124]!==_e||e[125]!==Ce||e[126]!==ke?(Me=n(Bt,{children:[qe,_e,Ce,ke]}),e[123]=qe,e[124]=_e,e[125]=Ce,e[126]=ke,e[127]=Me):Me=e[127];let Ie;e[128]!==r||e[129]!==Se||e[130]!==Me?(Ie=n(Qt,{onValueChange:w,value:r,children:[Se,Me]}),e[128]=r,e[129]=Se,e[130]=Me,e[131]=Ie):Ie=e[131];let De;e[132]!==ve||e[133]!==Ie?(De=n("div",{className:"flex items-center gap-2",children:[ve,Ie]}),e[132]=ve,e[133]=Ie,e[134]=De):De=e[134],e[135]!==be||e[136]!==De?(x=n("div",{className:"flex items-center justify-between",children:[be,De]}),e[135]=be,e[136]=De,e[137]=x):x=e[137],m=he;let Ae;e[138]!==s?(Ae=s("Statements"),e[138]=s,e[139]=Ae):Ae=e[139];let ze;e[140]!==Ae?(ze=t(Be,{children:Ae}),e[140]=Ae,e[141]=ze):ze=e[141],$=n(Pe,{children:[ze,t(kt,{children:s("{count} tracked statements",{count:R.length})})]}),f=ge,v="space-y-2";let Ke;e[142]!==i||e[143]!==s?(Ke=D=>{const ce=D.normalizedSql,H=i.has(ce),fe=Ve(D.avgDurationMs);return n("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[n("button",{"aria-expanded":H,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:()=>{O(ce)},type:"button",children:[n("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t(lr,{level:fe}),t("span",{className:"max-w-[300px] truncate font-mono text-sm lg:max-w-[500px]",children:D.normalizedSql})]}),n("div",{className:"flex shrink-0 items-center gap-4",children:[n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Ee(D.totalDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("total")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Ee(D.avgDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("avg")})]}),D.p95DurationMs!==void 0&&n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Ee(D.p95DurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("p95")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:He(D.execCount)}),t("div",{className:"text-xs text-muted-foreground",children:s("calls")})]})]})]}),H&&n("div",{className:"space-y-3 border-t bg-muted/30 p-4",children:[n("div",{children:[t("p",{className:"mb-2 text-sm font-medium",children:s("Full statement")}),t("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:D.normalizedSql})]}),n("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[D.p50DurationMs!==void 0&&n("div",{children:[t("span",{className:"text-muted-foreground",children:s("p50")}),t("span",{className:"block font-medium tabular-nums",children:Ee(D.p50DurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Exec count")}),t("span",{className:"block font-medium tabular-nums",children:He(D.execCount)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Total time")}),t("span",{className:"block font-medium tabular-nums",children:Ee(D.totalDurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Rows read")}),t("span",{className:"block font-medium tabular-nums",children:He(D.rowsRead)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Rows written")}),t("span",{className:"block font-medium tabular-nums",children:He(D.rowsWritten)})]})]})]})]},ce)},e[142]=i,e[143]=s,e[144]=Ke):Ke=e[144],q=R.map(Ke)}e[2]=i,e[3]=a,e[4]=r,e[5]=s,e[6]=f,e[7]=m,e[8]=h,e[9]=v,e[10]=q,e[11]=$,e[12]=c,e[13]=p,e[14]=g,e[15]=x}else f=e[6],m=e[7],h=e[8],v=e[9],q=e[10],$=e[11],c=e[12],p=e[13],g=e[14],x=e[15];if(h!==Symbol.for("react.early_return_sentinel"))return h;let T;e[145]!==v||e[146]!==q?(T=t("div",{className:v,children:q}),e[145]=v,e[146]=q,e[147]=T):T=e[147];let C;e[148]!==f||e[149]!==T?(C=t(f,{children:T}),e[148]=f,e[149]=T,e[150]=C):C=e[150];let N;e[151]!==m||e[152]!==C||e[153]!==$?(N=n(m,{children:[$,C]}),e[151]=m,e[152]=C,e[153]=$,e[154]=N):N=e[154];let k;return e[155]!==N||e[156]!==c||e[157]!==p||e[158]!==g||e[159]!==x?(k=n("div",{className:c,"data-testid":p,children:[g,x,N]}),e[155]=N,e[156]=c,e[157]=p,e[158]=g,e[159]=x,e[160]=k):k=e[160],k};function nr(l){return Ve(l.avgDurationMs)==="critical"}function or(l){return Ve(l.avgDurationMs)==="warning"}function cr(l){return Ve(l.avgDurationMs)==="good"}const dr=["1m","5m","15m","1h"],mr=l=>new Date(l).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}),ur=l=>l.map(e=>({avg:Math.round(e.avgDurationMs*100)/100,execs:e.execCount,label:mr(e.bucketMs)})),fr=({shardKey:l=""})=>{const e=xe(),[a,s]=pe("15m"),d=Ue(Fe.getQueryInsights,{range:a},{live:!0,shardKey:l}).data,o=ur(d?.buckets??[]);return n("div",{className:"flex flex-col gap-4","data-testid":"qi-range",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t("div",{className:"flex gap-1 rounded-lg border border-border p-0.5","data-testid":"qi-ranges",role:"group",children:dr.map(i=>t("button",{"aria-pressed":i===a,className:Kt("rounded px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",i===a&&"bg-accent font-medium text-foreground"),"data-testid":`qi-range-${i}`,onClick:()=>{s(i)},type:"button",children:i},i))}),d?.capped===!0&&t(et,{"data-testid":"qi-capped",variant:"secondary",children:e("showing a capped set")})]}),o.length===0?t(zt,{description:e("Statements executed in the selected window appear here, with throughput and latency over time."),testId:"qi-empty",title:e("No queries in this window.")}):n("div",{className:"grid gap-4 lg:grid-cols-2",children:[n("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-throughput",children:[t("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Throughput")}),t(st,{height:140,width:"100%",children:n(Ot,{data:o,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(at,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{allowDecimals:!1,fontSize:10,tickLine:!1,width:32}),t(nt,{}),t(Et,{dataKey:"execs",fill:"var(--color-primary)",fillOpacity:.15,stroke:"var(--color-primary)",type:"monotone"})]})})]}),n("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-latency",children:[t("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Mean latency (ms)")}),t(st,{height:140,width:"100%",children:n(Ft,{data:o,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(at,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{fontSize:10,tickLine:!1,width:32}),t(nt,{}),t(Lt,{dataKey:"avg",dot:!1,stroke:"var(--color-destructive)",type:"monotone"})]})})]})]}),t(ir,{queryStats:d?.entries??[]})]})},hr=_t(Fe.getMetrics),gr=(l,e)=>l?e:"overview",Pr=({initialShardKey:l})=>{const e=gt(),a=xe(),{queryShardKey:s,setShardKey:r,shardKey:d}=vt(l),[o,i]=pe("overview"),[S,y]=pe([]),w=Ge(null),f=Ge(null),m=Ge(!0);tt(()=>(m.current=!0,()=>{m.current=!1}),[]);const h=yt(s),{data:v,error:q,liveError:$}=Ue(Fe.getMetrics,{},{live:!0,shardKey:s}),c=v??null;tt(()=>{if(v===void 0)return;$t(s);const O=v,z=w.current,j=f.current!==null&&f.current!==O.shard;if(f.current=O.shard,w.current=O.requests,j){y([]);return}z!==null&&O.requests>=z&&y(F=>[...F,O.requests-z].slice(-30))},[v,s]);const[p,g]=pe(null),[x,T]=pe(!1),C=async()=>{T(!0);const O=At(d,Ct());try{const z=await Promise.all(O.map(async j=>{try{const F=await e.query(hr,{},qt(j));return{error:null,metrics:F,shard:j===""?F.shard:j}}catch(F){return{error:Tt(F),metrics:null,shard:j===""?"__root__":j}}}));m.current&&g(z)}finally{m.current&&T(!1)}},N=p===null?null:Mt(p),k=c===null||c.requests===0?"—":`${(c.errors/c.requests*100).toFixed(1)}%`,R=S.length>0?S.at(-1):0,M=c?It(c):{p90:0,p95:0},_=pt(()=>{if(!c||!("queryStats"in c))return;const O=c.queryStats;if(!(!O||!Array.isArray(O)))return Dt(O)},[c]),b=gr(_!==void 0,o),I=()=>{wt(C())},A=()=>{g(null)},E=()=>{i("overview")},L=()=>{i("query-insights")};return n("div",{className:"flex flex-col gap-4","data-testid":"lunora-metrics",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t(bt,{onChange:r,testId:"mt-shard-input",value:d}),t(xt,{message:$,prefix:"mt"}),t(rt,{"data-testid":"mt-aggregate",disabled:x,onClick:I,size:"sm",type:"button",variant:"secondary",children:a(x?"Aggregating…":"All shards")}),p!==null&&t(rt,{"data-testid":"mt-aggregate-clear",onClick:A,size:"sm",type:"button",variant:"ghost",children:a("Hide")}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:Nt,rel:"noreferrer",target:"_blank",children:a("Open in Cloudflare")})]}),q!==null&&t("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:q}),_!==void 0&&n("div",{className:"flex gap-2 border-b","data-testid":"mt-tabs",children:[t("button",{className:`pb-2 text-sm font-medium transition-colors ${b==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:E,type:"button",children:a("Overview")}),n("button",{className:`pb-2 text-sm font-medium transition-colors ${b==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:L,type:"button",children:[a("Query insights"),_.length>0&&t("span",{className:"ml-1.5 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:_.length})]})]}),b==="query-insights"&&_!==void 0&&t(fr,{shardKey:s}),b==="overview"&&c!==null&&t(sr,{currentDelta:R,errorRate:k,history:S,latencyPercentiles:M,metrics:c}),b==="overview"&&c===null&&null,b==="overview"&&t(Zt,{onOpenTrace:h,shardKey:s}),b==="overview"&&N!==null&&p!==null&&t(er,{aggregate:N,shardResults:p})]})};export{Pr as MetricsPanel};
@@ -1 +1 @@
1
- import{c as D}from"react/compiler-runtime";import{useState as j}from"react";import{E as K}from"../packem_shared/error-alert-TYdKetJd.js";import{B as L}from"../packem_shared/badge-cAk9Di1Q.js";import{B as F}from"../packem_shared/button-BOPLD1un.js";import{C as O,a as Q}from"../packem_shared/card-BGlQzQY-.js";import{E as U}from"../packem_shared/empty-state-B939z6K2.js";import{I as q}from"../packem_shared/input-CY5W3wzv.js";import{T as G,a as J,b as H,c as h,d as X,e as u}from"../packem_shared/table-BMsuYFhk.js";import{u as Y}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{useT as Z}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as _}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{i as ee}from"../packem_shared/internal-CwaF9YNk.js";import{jsx as t,jsxs as x}from"react/jsx-runtime";const te=e=>e==="ok"?"success":e==="failed"?"destructive":e==="expired"?"warning":"secondary",M=e=>e.endpoint??e.id,ge=()=>{const e=D(38),r=Z(),[a,P]=j("all"),[n,V]=j("");let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b={},e[0]=b):b=e[0];const{data:T,error:i,errorSource:p,isLoading:v,refetch:g}=Y(_.listPushSubscriptions,b);let N;if(e[1]!==T?.subscriptions||e[2]!==i||e[3]!==p||e[4]!==v||e[5]!==a||e[6]!==g||e[7]!==n||e[8]!==r){const I=T?.subscriptions??[],$=n.trim().toLowerCase(),A=I.filter(s=>a!=="all"&&s.kind!==a?!1:$===""?!0:`${M(s)} ${s.userId??""}`.toLowerCase().includes($));let w;e[10]===Symbol.for("react.memo_cache_sentinel")?(w=s=>{V(s.target.value)},e[10]=w):w=e[10];const z=w;let y;e[11]!==g?(y=()=>{g()},e[11]=g,e[12]=y):y=e[12];const B=y;let C;e[13]===Symbol.for("react.memo_cache_sentinel")?(C=["all","web-push","fcm"],e[13]=C):C=e[13];const W=C;let o;e[14]!==a||e[15]!==r?(o=t("div",{className:"flex items-center gap-1","data-testid":"nt-kind-filter",role:"tablist",children:W.map(s=>t(F,{"aria-selected":a===s,"data-testid":`nt-kind-${s}`,onClick:()=>{P(s)},role:"tab",size:"sm",type:"button",variant:a===s?"secondary":"ghost",children:s==="all"?r("All"):s},s))}),e[14]=a,e[15]=r,e[16]=o):o=e[16];let l;e[17]!==r?(l=r("Filter devices"),e[17]=r,e[18]=l):l=e[18];let d;e[19]!==r?(d=r("filter endpoint, user"),e[19]=r,e[20]=d):d=e[20];let c;e[21]!==n||e[22]!==l||e[23]!==d?(c=t(q,{"aria-label":l,className:"h-8 w-56","data-testid":"nt-search",onChange:z,placeholder:d,value:n}),e[21]=n,e[22]=l,e[23]=d,e[24]=c):c=e[24];let m;e[25]!==r?(m=r("Refresh"),e[25]=r,e[26]=m):m=e[26];let f;e[27]!==B||e[28]!==m?(f=t(F,{className:"ml-auto","data-testid":"nt-refresh",onClick:B,size:"sm",type:"button",variant:"outline",children:m}),e[27]=B,e[28]=m,e[29]=f):f=e[29];const E=I.length>0&&t(L,{"data-testid":"nt-count",variant:"secondary",children:r("{count} devices",{count:I.length})});let k;e[30]!==f||e[31]!==E||e[32]!==o||e[33]!==c?(k=x("div",{className:"flex flex-wrap items-center gap-2",children:[o,c,f,E]}),e[30]=f,e[31]=E,e[32]=o,e[33]=c,e[34]=k):k=e[34];let S;e[35]!==i||e[36]!==p?(S=i!==null&&t(K,{error:p,testId:"nt-error"}),e[35]=i,e[36]=p,e[37]=S):S=e[37],N=x("div",{className:"flex flex-col gap-4","data-testid":"lunora-notifications",children:[k,S,i===null&&!v&&A.length===0&&t(U,{description:r("Registered Web Push / FCM devices appear here. Configure lunora/notify.ts with defineNotify({ store }) and register a device with ctx.push.register(...)."),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:"M15 17h5l-1.4-1.4A2 2 0 0 1 18 14.2V11a6 6 0 0 0-4-5.7V5a2 2 0 1 0-4 0v.3A6 6 0 0 0 6 11v3.2a2 2 0 0 1-.6 1.4L4 17h5m6 0v1a3 3 0 1 1-6 0v-1m6 0H9"})}),testId:"nt-empty",title:r("No registered devices.")}),A.length>0&&t(O,{className:"overflow-hidden py-0",children:t(Q,{className:"max-h-[30rem] overflow-auto px-0",children:x(G,{"data-testid":"nt-table",children:[t(J,{children:x(H,{children:[t(h,{children:r("kind")}),t(h,{children:r("endpoint")}),t(h,{children:r("user")}),t(h,{children:r("last seen")}),t(h,{children:r("status")}),t(h,{children:r("error")})]})}),t(X,{children:A.map(s=>{const R=M(s);return x(H,{"data-testid":"nt-row",children:[t(u,{children:t(L,{variant:"outline",children:s.kind})}),t(u,{className:"max-w-[28ch] truncate font-mono text-xs",title:R,children:R}),t(u,{className:"max-w-[16ch] truncate font-mono text-xs",children:s.userId??t("span",{className:"text-muted-foreground",children:"—"})}),t(u,{className:"text-muted-foreground tabular-nums",children:ee(s.lastSeenAt,"—")}),t(u,{children:t(L,{"data-testid":`nt-status-${s.id}`,variant:te(s.lastStatus),children:s.lastStatus??r("n/a")})}),t(u,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",title:s.lastError??void 0,children:s.lastError??t("span",{className:"text-muted-foreground",children:"—"})})]},s.id)})})]})})})]}),e[1]=T?.subscriptions,e[2]=i,e[3]=p,e[4]=v,e[5]=a,e[6]=g,e[7]=n,e[8]=r,e[9]=N}else N=e[9];return N};export{ge as default};
1
+ import{c as D}from"react/compiler-runtime";import{useState as j}from"react";import{E as K}from"../packem_shared/error-alert-CKqB2CiN.js";import{B as L}from"../packem_shared/badge-cAk9Di1Q.js";import{B as F}from"../packem_shared/button-BOPLD1un.js";import{C as O,a as Q}from"../packem_shared/card-BGlQzQY-.js";import{E as U}from"../packem_shared/empty-state-B939z6K2.js";import{I as q}from"../packem_shared/input-CY5W3wzv.js";import{T as G,a as J,b as H,c as h,d as X,e as u}from"../packem_shared/table-BMsuYFhk.js";import{u as Y}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{useT as Z}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as _}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{i as ee}from"../packem_shared/internal-7bgd8inO.js";import{jsx as t,jsxs as x}from"react/jsx-runtime";const te=e=>e==="ok"?"success":e==="failed"?"destructive":e==="expired"?"warning":"secondary",M=e=>e.endpoint??e.id,ge=()=>{const e=D(38),r=Z(),[a,P]=j("all"),[n,V]=j("");let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b={},e[0]=b):b=e[0];const{data:T,error:i,errorSource:p,isLoading:v,refetch:g}=Y(_.listPushSubscriptions,b);let N;if(e[1]!==T?.subscriptions||e[2]!==i||e[3]!==p||e[4]!==v||e[5]!==a||e[6]!==g||e[7]!==n||e[8]!==r){const I=T?.subscriptions??[],$=n.trim().toLowerCase(),A=I.filter(s=>a!=="all"&&s.kind!==a?!1:$===""?!0:`${M(s)} ${s.userId??""}`.toLowerCase().includes($));let w;e[10]===Symbol.for("react.memo_cache_sentinel")?(w=s=>{V(s.target.value)},e[10]=w):w=e[10];const z=w;let y;e[11]!==g?(y=()=>{g()},e[11]=g,e[12]=y):y=e[12];const B=y;let C;e[13]===Symbol.for("react.memo_cache_sentinel")?(C=["all","web-push","fcm"],e[13]=C):C=e[13];const W=C;let o;e[14]!==a||e[15]!==r?(o=t("div",{className:"flex items-center gap-1","data-testid":"nt-kind-filter",role:"tablist",children:W.map(s=>t(F,{"aria-selected":a===s,"data-testid":`nt-kind-${s}`,onClick:()=>{P(s)},role:"tab",size:"sm",type:"button",variant:a===s?"secondary":"ghost",children:s==="all"?r("All"):s},s))}),e[14]=a,e[15]=r,e[16]=o):o=e[16];let l;e[17]!==r?(l=r("Filter devices"),e[17]=r,e[18]=l):l=e[18];let d;e[19]!==r?(d=r("filter endpoint, user"),e[19]=r,e[20]=d):d=e[20];let c;e[21]!==n||e[22]!==l||e[23]!==d?(c=t(q,{"aria-label":l,className:"h-8 w-56","data-testid":"nt-search",onChange:z,placeholder:d,value:n}),e[21]=n,e[22]=l,e[23]=d,e[24]=c):c=e[24];let m;e[25]!==r?(m=r("Refresh"),e[25]=r,e[26]=m):m=e[26];let f;e[27]!==B||e[28]!==m?(f=t(F,{className:"ml-auto","data-testid":"nt-refresh",onClick:B,size:"sm",type:"button",variant:"outline",children:m}),e[27]=B,e[28]=m,e[29]=f):f=e[29];const E=I.length>0&&t(L,{"data-testid":"nt-count",variant:"secondary",children:r("{count} devices",{count:I.length})});let k;e[30]!==f||e[31]!==E||e[32]!==o||e[33]!==c?(k=x("div",{className:"flex flex-wrap items-center gap-2",children:[o,c,f,E]}),e[30]=f,e[31]=E,e[32]=o,e[33]=c,e[34]=k):k=e[34];let S;e[35]!==i||e[36]!==p?(S=i!==null&&t(K,{error:p,testId:"nt-error"}),e[35]=i,e[36]=p,e[37]=S):S=e[37],N=x("div",{className:"flex flex-col gap-4","data-testid":"lunora-notifications",children:[k,S,i===null&&!v&&A.length===0&&t(U,{description:r("Registered Web Push / FCM devices appear here. Configure lunora/notify.ts with defineNotify({ store }) and register a device with ctx.push.register(...)."),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:"M15 17h5l-1.4-1.4A2 2 0 0 1 18 14.2V11a6 6 0 0 0-4-5.7V5a2 2 0 1 0-4 0v.3A6 6 0 0 0 6 11v3.2a2 2 0 0 1-.6 1.4L4 17h5m6 0v1a3 3 0 1 1-6 0v-1m6 0H9"})}),testId:"nt-empty",title:r("No registered devices.")}),A.length>0&&t(O,{className:"overflow-hidden py-0",children:t(Q,{className:"max-h-[30rem] overflow-auto px-0",children:x(G,{"data-testid":"nt-table",children:[t(J,{children:x(H,{children:[t(h,{children:r("kind")}),t(h,{children:r("endpoint")}),t(h,{children:r("user")}),t(h,{children:r("last seen")}),t(h,{children:r("status")}),t(h,{children:r("error")})]})}),t(X,{children:A.map(s=>{const R=M(s);return x(H,{"data-testid":"nt-row",children:[t(u,{children:t(L,{variant:"outline",children:s.kind})}),t(u,{className:"max-w-[28ch] truncate font-mono text-xs",title:R,children:R}),t(u,{className:"max-w-[16ch] truncate font-mono text-xs",children:s.userId??t("span",{className:"text-muted-foreground",children:"—"})}),t(u,{className:"text-muted-foreground tabular-nums",children:ee(s.lastSeenAt,"—")}),t(u,{children:t(L,{"data-testid":`nt-status-${s.id}`,variant:te(s.lastStatus),children:s.lastStatus??r("n/a")})}),t(u,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",title:s.lastError??void 0,children:s.lastError??t("span",{className:"text-muted-foreground",children:"—"})})]},s.id)})})]})})})]}),e[1]=T?.subscriptions,e[2]=i,e[3]=p,e[4]=v,e[5]=a,e[6]=g,e[7]=n,e[8]=r,e[9]=N}else N=e[9];return N};export{ge as default};
@@ -1 +1 @@
1
- import{useLunora as D}from"@lunora/react";import{useState as s,useCallback as G,useEffect as Z}from"react";import{ConfirmButton as B}from"../packem_shared/ConfirmButton-Cj2SOapE.js";import{B as H}from"../packem_shared/badge-cAk9Di1Q.js";import{B as J}from"../packem_shared/button-BOPLD1un.js";import{I as _}from"../packem_shared/input-CY5W3wzv.js";import{L as g}from"../packem_shared/label-BOUo-DP0.js";import{useAutoRefresh as Q}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.js";import{useT as V}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as T}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{d as u,b as v,f as p,c as I}from"../packem_shared/internal-CwaF9YNk.js";import{jsxs as o,jsx as r}from"react/jsx-runtime";const N=I(T.getPitrBookmark),W=I(T.pitrRestore),de=({initialShardKey:O})=>{const c=D(),t=V(),n=O??"",[P,f]=s(null),[i,F]=s(""),[y,w]=s(null),[m,E]=s(""),[h,L]=s(!1),[a,S]=s(null),[R,l]=s(null),[x,d]=s(!1),k=G(async()=>{d(!0),l(null);try{const e=await c.query(N,{},u(n));f(e.current)}catch(e){l(v(e))}d(!1)},[c,n]);Z(()=>{p(k())},[k]),Q(()=>{p((async()=>{try{const e=await c.query(N,{},u(n));f(e.current)}catch{}})())},!0);const A=e=>{F(e.target.value)},U=e=>{E(e.target.value)},q=e=>{L(e.target.checked)},K=()=>{i.trim()!==""&&p((async()=>{d(!0),l(null);try{const e=await c.query(N,{time:i.trim()},u(n));w(e.forTime??null),f(e.current)}catch(e){w(null),l(v(e))}d(!1)})())},C=e=>{p((async()=>{d(!0),l(null);try{const b=await c.mutation(W,e,u(n));S(b),await k()}catch(b){l(v(b))}d(!1)})())},M=m.trim()!==""||i.trim()!=="",j=()=>{const e=h?{restart:!0}:{};m.trim()===""?e.time=i.trim():e.bookmark=m.trim(),C(e)},z=()=>{a!==null&&C(h?{bookmark:a.undoBookmark,restart:!0}:{bookmark:a.undoBookmark})};return o("div",{className:"flex flex-col gap-4","data-testid":"lunora-pitr",children:[r("div",{className:"flex flex-wrap items-center gap-3",children:o("span",{className:"text-xs text-muted-foreground",children:[t("Shard"),": ",r("span",{className:"font-mono",children:n===""?t("root"):n})]})}),r("p",{className:"text-sm text-muted-foreground","data-testid":"pitr-note",children:t("In-place recovery to any moment in the last 30 days. For older or portable recovery, use the snapshot backup tier.")}),R!==null&&r("p",{className:"text-sm text-destructive","data-testid":"pitr-error",role:"alert",children:R}),o("section",{className:"rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"mb-2 text-sm font-semibold",children:t("Current bookmark")}),r("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-current",children:P??r("span",{className:"text-muted-foreground",children:"—"})})]}),o("section",{className:"flex flex-col gap-3 rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore")}),o("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-time",children:t("Time (ISO or epoch-ms, last 30 days)")}),o("div",{className:"flex items-center gap-2",children:[r(_,{"data-testid":"pitr-time",id:"pitr-time",onChange:A,placeholder:"2026-06-01T00:00:00.000Z",value:i}),r(J,{"data-testid":"pitr-preview",disabled:x||i.trim()==="",onClick:K,size:"sm",type:"button",variant:"outline",children:t("Preview")})]}),y!==null&&o("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-preview-bookmark",children:[t("Bookmark for that time"),": ",y]})]}),o("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-bookmark",children:t("Or an explicit bookmark (wins over time)")}),r(_,{"data-testid":"pitr-bookmark",id:"pitr-bookmark",onChange:U,placeholder:t("bookmark string"),value:m})]}),o(g,{className:"flex items-center gap-2 text-xs font-normal text-muted-foreground",htmlFor:"pitr-restart",children:[r("input",{checked:h,className:"size-4 accent-primary","data-testid":"pitr-restart",id:"pitr-restart",onChange:q,type:"checkbox"}),t("Restart the shard now so recovery applies immediately")]}),r("div",{children:r(B,{confirmLabel:t("Confirm restore"),disabled:x||!M,onConfirm:j,testId:"pitr-restore",children:t("Restore")})})]}),a!==null&&o("section",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs","data-testid":"pitr-result",children:[o("div",{className:"flex items-center gap-2",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore armed")}),r(H,{variant:a.restarted?"destructive":"secondary",children:a.restarted?t("restarted now"):t("on next restart")})]}),o("p",{className:"font-mono text-xs break-all text-muted-foreground",children:[t("Restored to"),": ",a.restoredTo]}),o("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-undo-bookmark",children:[t("Undo bookmark"),": ",a.undoBookmark]}),r("div",{children:r(B,{confirmLabel:t("Confirm undo"),disabled:x,onConfirm:z,testId:"pitr-undo",children:t("Undo restore")})})]})]})};export{de as PitrPanel};
1
+ import{useLunora as D}from"@lunora/react";import{useState as s,useCallback as G,useEffect as Z}from"react";import{ConfirmButton as B}from"../packem_shared/ConfirmButton-Cj2SOapE.js";import{B as H}from"../packem_shared/badge-cAk9Di1Q.js";import{B as J}from"../packem_shared/button-BOPLD1un.js";import{I as _}from"../packem_shared/input-CY5W3wzv.js";import{L as g}from"../packem_shared/label-BOUo-DP0.js";import{useAutoRefresh as Q}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.js";import{useT as V}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as T}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{d as u,b as v,f as p,c as I}from"../packem_shared/internal-7bgd8inO.js";import{jsxs as o,jsx as r}from"react/jsx-runtime";const N=I(T.getPitrBookmark),W=I(T.pitrRestore),de=({initialShardKey:O})=>{const c=D(),t=V(),n=O??"",[P,f]=s(null),[i,F]=s(""),[y,w]=s(null),[m,E]=s(""),[h,L]=s(!1),[a,S]=s(null),[R,l]=s(null),[x,d]=s(!1),k=G(async()=>{d(!0),l(null);try{const e=await c.query(N,{},u(n));f(e.current)}catch(e){l(v(e))}d(!1)},[c,n]);Z(()=>{p(k())},[k]),Q(()=>{p((async()=>{try{const e=await c.query(N,{},u(n));f(e.current)}catch{}})())},!0);const A=e=>{F(e.target.value)},U=e=>{E(e.target.value)},q=e=>{L(e.target.checked)},K=()=>{i.trim()!==""&&p((async()=>{d(!0),l(null);try{const e=await c.query(N,{time:i.trim()},u(n));w(e.forTime??null),f(e.current)}catch(e){w(null),l(v(e))}d(!1)})())},C=e=>{p((async()=>{d(!0),l(null);try{const b=await c.mutation(W,e,u(n));S(b),await k()}catch(b){l(v(b))}d(!1)})())},M=m.trim()!==""||i.trim()!=="",j=()=>{const e=h?{restart:!0}:{};m.trim()===""?e.time=i.trim():e.bookmark=m.trim(),C(e)},z=()=>{a!==null&&C(h?{bookmark:a.undoBookmark,restart:!0}:{bookmark:a.undoBookmark})};return o("div",{className:"flex flex-col gap-4","data-testid":"lunora-pitr",children:[r("div",{className:"flex flex-wrap items-center gap-3",children:o("span",{className:"text-xs text-muted-foreground",children:[t("Shard"),": ",r("span",{className:"font-mono",children:n===""?t("root"):n})]})}),r("p",{className:"text-sm text-muted-foreground","data-testid":"pitr-note",children:t("In-place recovery to any moment in the last 30 days. For older or portable recovery, use the snapshot backup tier.")}),R!==null&&r("p",{className:"text-sm text-destructive","data-testid":"pitr-error",role:"alert",children:R}),o("section",{className:"rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"mb-2 text-sm font-semibold",children:t("Current bookmark")}),r("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-current",children:P??r("span",{className:"text-muted-foreground",children:"—"})})]}),o("section",{className:"flex flex-col gap-3 rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore")}),o("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-time",children:t("Time (ISO or epoch-ms, last 30 days)")}),o("div",{className:"flex items-center gap-2",children:[r(_,{"data-testid":"pitr-time",id:"pitr-time",onChange:A,placeholder:"2026-06-01T00:00:00.000Z",value:i}),r(J,{"data-testid":"pitr-preview",disabled:x||i.trim()==="",onClick:K,size:"sm",type:"button",variant:"outline",children:t("Preview")})]}),y!==null&&o("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-preview-bookmark",children:[t("Bookmark for that time"),": ",y]})]}),o("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-bookmark",children:t("Or an explicit bookmark (wins over time)")}),r(_,{"data-testid":"pitr-bookmark",id:"pitr-bookmark",onChange:U,placeholder:t("bookmark string"),value:m})]}),o(g,{className:"flex items-center gap-2 text-xs font-normal text-muted-foreground",htmlFor:"pitr-restart",children:[r("input",{checked:h,className:"size-4 accent-primary","data-testid":"pitr-restart",id:"pitr-restart",onChange:q,type:"checkbox"}),t("Restart the shard now so recovery applies immediately")]}),r("div",{children:r(B,{confirmLabel:t("Confirm restore"),disabled:x||!M,onConfirm:j,testId:"pitr-restore",children:t("Restore")})})]}),a!==null&&o("section",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs","data-testid":"pitr-result",children:[o("div",{className:"flex items-center gap-2",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore armed")}),r(H,{variant:a.restarted?"destructive":"secondary",children:a.restarted?t("restarted now"):t("on next restart")})]}),o("p",{className:"font-mono text-xs break-all text-muted-foreground",children:[t("Restored to"),": ",a.restoredTo]}),o("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-undo-bookmark",children:[t("Undo bookmark"),": ",a.undoBookmark]}),r("div",{children:r(B,{confirmLabel:t("Confirm undo"),disabled:x,onConfirm:z,testId:"pitr-undo",children:t("Undo restore")})})]})]})};export{de as PitrPanel};
@@ -1 +1 @@
1
- import{c as Ne}from"react/compiler-runtime";import{ShardInput as We}from"../packem_shared/ShardInput-XumEzeT0.js";import{S as Re,T as Pe}from"../packem_shared/storage-tier-C2mKwYRj.js";import{B as Fe}from"../packem_shared/badge-cAk9Di1Q.js";import{b as ze,d as qe,c as Be,a as De,C as je}from"../packem_shared/card-BGlQzQY-.js";import{E as Qe}from"../packem_shared/empty-state-B939z6K2.js";import{I as ke}from"../packem_shared/input-CY5W3wzv.js";import{useT as Le}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{c as Oe,d as Ae,b as $e,f as be}from"../packem_shared/internal-CwaF9YNk.js";import{c as Je}from"../packem_shared/utils-bhneXptQ.js";import{useLunora as Ze}from"@lunora/react";import{useState as E,useEffect as Ge,useRef as et}from"react";import{u as tt}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{ADMIN_FUNCTIONS as Me}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{r as lt}from"../packem_shared/shard-history-QcjcMnCA.js";import{S as st}from"../packem_shared/schema-diagram-DHD13TjS.js";import{useNavigate as at}from"@tanstack/react-router";import{B as ge}from"../packem_shared/button-BOPLD1un.js";import{L as _e}from"../packem_shared/label-BOUo-DP0.js";import{jsx as l,jsxs as p,Fragment as Ke}from"react/jsx-runtime";const nt=Oe(Me.listTables),ot=Oe(Me.listTableIndexes),it=Oe(Me.readTablePage),rt=Oe(Me.describeTables),dt={},Ue=[],ct=n=>{const e=Ne(74),{initialShardKey:m,initialTable:a}=n,t=Ze(),[s,c]=E("graph"),{queryShardKey:d,setShardKey:r,shardKey:b}=tt(m),[o,f]=E(""),[i,v]=E(null),[h,G]=E(null);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w={},e[0]=w):w=e[0];const[B,y]=E(w);let z;e[1]===Symbol.for("react.memo_cache_sentinel")?(z={},e[1]=z):z=e[1];const[F,D]=E(z),[S,C]=E(null);let A;e[2]===Symbol.for("react.memo_cache_sentinel")?(A={},e[2]=A):A=e[2];const[L,me]=E(A);let W;e[3]===Symbol.for("react.memo_cache_sentinel")?(W={},e[3]=W):W=e[3];const[I,q]=E(W),[_,ue]=E(null),[j,ie]=E(null);let Q;e[4]===Symbol.for("react.memo_cache_sentinel")?(Q={},e[4]=Q):Q=e[4];const[Y,xe]=E(Q),[H,re]=E(null);let ve;e[5]!==t?(ve=async u=>{G(null);try{const N=await t.query(nt,{},Ae(u));lt(u),v(N),y({}),D({}),C(null),me(x=>Object.fromEntries(Object.entries(x).filter(P=>{const[k]=P;return k!==u}))),q(x=>Object.fromEntries(Object.entries(x).filter(P=>{const[k]=P;return k!==u})))}catch(N){const x=N;v(null),G($e(x))}},e[5]=t,e[6]=ve):ve=e[6];const O=ve;let Z;e[7]!==t?(Z=async()=>{ie(null);try{ue(await t.listGlobalTables())}catch(u){const N=u;ue(null),ie($e(N))}},e[7]=t,e[8]=Z):Z=e[8];const ee=Z;let de,R;e[9]!==d||e[10]!==O||e[11]!==ee?(de=()=>{be(O(d)),be(ee())},R=[O,ee,d],e[9]=d,e[10]=O,e[11]=ee,e[12]=de,e[13]=R):(de=e[12],R=e[13]),Ge(de,R);let te;e[14]!==t||e[15]!==B||e[16]!==S||e[17]!==d?(te=async u=>{if(S===u){C(null);return}C(u);const N=`${d}:${u}`;if(B[N]!==void 0)return;const[x,P]=await Promise.allSettled([t.query(it,{limit:1,offset:0,table:u},Ae(d)),t.query(ot,{table:u},Ae(d))]);x.status==="fulfilled"?y(k=>({...k,[N]:x.value.columns})):G($e(x.reason)),P.status==="fulfilled"&&D(k=>({...k,[N]:P.value.indexes}))},e[14]=t,e[15]=B,e[16]=S,e[17]=d,e[18]=te):te=e[18];const M=te;let ye;e[19]!==t||e[20]!==Y||e[21]!==H?(ye=async u=>{if(H===u){re(null);return}if(re(u),Y[u]===void 0)try{const N=await t.readGlobalTablePage({limit:1,offset:0,table:u});xe(x=>({...x,[u]:N.columns}))}catch(N){ie($e(N))}},e[19]=t,e[20]=Y,e[21]=H,e[22]=ye):ye=e[22];const ce=ye,fe=et(void 0);let K,X;e[23]!==a||e[24]!==i||e[25]!==M?(K=()=>{a===void 0||i===null||fe.current===a||i.some(u=>u.name===a)&&(fe.current=a,be(M(a)))},X=[a,i,M],e[23]=a,e[24]=i,e[25]=M,e[26]=K,e[27]=X):(K=e[26],X=e[27]),Ge(K,X);let U;e[28]!==t?(U=async(u,N,x)=>{const[P,k]=await Promise.all([Promise.allSettled([t.query(rt,{tables:[...N,...x]},Ae(u))]),Promise.all(x.map(async T=>{const pe=await Promise.allSettled([t.readGlobalTablePage({limit:1,offset:0,table:T})]),Ie=pe[0].status==="fulfilled"?pe[0].value:void 0;return{columns:Ie?.columns??[],refs:Ie?.refs??{},table:T}}))]),Te=P[0].status==="fulfilled"?P[0].value?.columnsByTable??{}:{},Se=P[0].status==="rejected",we=new Map(k.map(mt)),Ee=[...N,...x].map(T=>{const pe=Te[T]??[];return[T,pe.length>0?pe:we.get(T)??[]]});me(T=>({...T,[u]:Object.fromEntries(Ee)})),q(T=>({...T,[u]:Se}))},e[28]=t,e[29]=U):U=e[29];const le=U;let V,se;e[30]!==j||e[31]!==_||e[32]!==le||e[33]!==d||e[34]!==L||e[35]!==i||e[36]!==s?(V=()=>{s!=="graph"||i===null||_===null&&j===null||L[d]!==void 0||be(le(d,i.map(ut),(_??[]).map(ft)))},se=[s,i,_,j,d,L,le],e[30]=j,e[31]=_,e[32]=le,e[33]=d,e[34]=L,e[35]=i,e[36]=s,e[37]=V,e[38]=se):(V=e[37],se=e[38]),Ge(V,se);const $=L[d]??dt;let ae;if(e[39]!==$||e[40]!==_||e[41]!==i){let u;e[43]!==$?(u=k=>({columns:$[k.name]??Ue,name:k.name,tier:"shard"}),e[43]=$,e[44]=u):u=e[44];const N=(i??[]).map(u);let x;e[45]!==$?(x=k=>({columns:$[k.name]??Ue,name:k.name,tier:"global"}),e[45]=$,e[46]=x):x=e[46];const P=(_??[]).map(x);ae=[...N,...P],e[39]=$,e[40]=_,e[41]=i,e[42]=ae}else ae=e[42];const ne=ae;let g;if(e[47]!==o||e[48]!==i){const u=o.trim().toLowerCase();g=(i??[]).filter(N=>N.name.toLowerCase().includes(u)),e[47]=o,e[48]=i,e[49]=g}else g=e[49];const oe=g;let J;if(e[50]!==_||e[51]!==o){const u=o.trim().toLowerCase();J=(_??[]).filter(N=>N.name.toLowerCase().includes(u)),e[50]=_,e[51]=o,e[52]=J}else J=e[52];const Ce=J;let he;return e[53]!==B||e[54]!==ne||e[55]!==h||e[56]!==S||e[57]!==Ce||e[58]!==oe||e[59]!==Y||e[60]!==j||e[61]!==H||e[62]!==_||e[63]!==F||e[64]!==O||e[65]!==r||e[66]!==I||e[67]!==b||e[68]!==o||e[69]!==i||e[70]!==M||e[71]!==ce||e[72]!==s?(he={columns:B,diagramTables:ne,error:h,expanded:S,filteredGlobalTables:Ce,filteredTables:oe,globalColumns:Y,globalError:j,globalExpanded:H,globalTables:_,indexes:F,refresh:O,setShardKey:r,setTableFilter:f,setView:c,shardColumnsError:I,shardKey:b,tableFilter:o,tables:i,toggle:M,toggleGlobal:ce,view:s},e[53]=B,e[54]=ne,e[55]=h,e[56]=S,e[57]=Ce,e[58]=oe,e[59]=Y,e[60]=j,e[61]=H,e[62]=_,e[63]=F,e[64]=O,e[65]=r,e[66]=I,e[67]=b,e[68]=o,e[69]=i,e[70]=M,e[71]=ce,e[72]=s,e[73]=he):he=e[73],he};function mt(n){const{columns:e,refs:m,table:a}=n;return[a,e.map(t=>{const s=m[t];return s===void 0?{name:t,optional:!1,type:""}:{name:t,optional:!1,ref:s,type:"id"}})]}function ut(n){return n.name}function ft(n){return n.name}const ht="/__lunora/schema-edit",pt=async n=>{const e=await fetch(ht,{body:JSON.stringify(n),headers:{"Content-Type":"application/json","X-Lunora-Studio":"1"},method:"POST"}),m=await e.json();return m.needsMigration===!0?{kind:"needs-migration",message:m.message??"This edit needs a migration."}:e.ok&&m.tables!==void 0?{diagnostics:m.diagnostics??[],kind:"ok",tables:m.tables}:{kind:"error",message:m.error??`schema edit failed (${String(e.status)})`}},gt=n=>{const e=Ne(32),{hasTables:m,mode:a,onAddColumn:t,onAddIndex:s,onAddTable:c,onDestructive:d}=n,r=Le(),b=a==="addTable"?"default":"outline";let o;e[0]!==r?(o=r("Add table"),e[0]=r,e[1]=o):o=e[1];let f;e[2]!==c||e[3]!==b||e[4]!==o?(f=l(ge,{"data-testid":"sc-editor-add-table",onClick:c,size:"xs",type:"button",variant:b,children:o}),e[2]=c,e[3]=b,e[4]=o,e[5]=f):f=e[5];const i=!m,v=a==="addColumn"?"default":"outline";let h;e[6]!==r?(h=r("Add column"),e[6]=r,e[7]=h):h=e[7];let G;e[8]!==t||e[9]!==i||e[10]!==v||e[11]!==h?(G=l(ge,{"data-testid":"sc-editor-add-column",disabled:i,onClick:t,size:"xs",type:"button",variant:v,children:h}),e[8]=t,e[9]=i,e[10]=v,e[11]=h,e[12]=G):G=e[12];const w=!m,B=a==="addIndex"?"default":"outline";let y;e[13]!==r?(y=r("Add index"),e[13]=r,e[14]=y):y=e[14];let z;e[15]!==s||e[16]!==y||e[17]!==w||e[18]!==B?(z=l(ge,{"data-testid":"sc-editor-add-index",disabled:w,onClick:s,size:"xs",type:"button",variant:B,children:y}),e[15]=s,e[16]=y,e[17]=w,e[18]=B,e[19]=z):z=e[19];const F=!m,D=a==="destructive"?"default":"ghost";let S;e[20]!==r?(S=r("Rename / drop / change type…"),e[20]=r,e[21]=S):S=e[21];let C;e[22]!==d||e[23]!==F||e[24]!==D||e[25]!==S?(C=l(ge,{"data-testid":"sc-editor-destructive",disabled:F,onClick:d,size:"xs",type:"button",variant:D,children:S}),e[22]=d,e[23]=F,e[24]=D,e[25]=S,e[26]=C):C=e[26];let A;return e[27]!==z||e[28]!==C||e[29]!==f||e[30]!==G?(A=p("div",{className:"flex flex-wrap gap-2",children:[f,G,z,C]}),e[27]=z,e[28]=C,e[29]=f,e[30]=G,e[31]=A):A=e[31],A},bt=n=>{const e=Ne(28),{onOpenMigrations:m,result:a}=n,t=Le();if(a===null){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ke,{}),e[0]=o):o=e[0],o}if(a.kind==="error"){let o;return e[1]!==a.message?(o=l("p",{className:"mt-3 text-sm text-destructive","data-testid":"sc-editor-error",role:"alert",children:a.message}),e[1]=a.message,e[2]=o):o=e[2],o}if(a.kind==="needs-migration"){let o;e[3]!==a.message||e[4]!==t?(o=a.message===""?t("This edit changes stored data and must go through a migration. Review the migration before applying."):a.message,e[3]=a.message,e[4]=t,e[5]=o):o=e[5];let f;e[6]!==o?(f=l("p",{className:"text-sm text-warning",role:"alert",children:o}),e[6]=o,e[7]=f):f=e[7];let i;e[8]!==t?(i=t("Open Migrations"),e[8]=t,e[9]=i):i=e[9];let v;e[10]!==m||e[11]!==i?(v=l(ge,{className:"self-start","data-testid":"sc-editor-open-migrations",onClick:m,size:"xs",type:"button",variant:"outline",children:i}),e[10]=m,e[11]=i,e[12]=v):v=e[12];let h;return e[13]!==f||e[14]!==v?(h=p("div",{className:"mt-3 flex flex-col gap-2","data-testid":"sc-editor-needs-migration",children:[f,v]}),e[13]=f,e[14]=v,e[15]=h):h=e[15],h}if(a.diagnostics.length===0){let o;return e[16]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ke,{}),e[16]=o):o=e[16],o}let s;e[17]!==t?(s=t("Codegen reported diagnostics:"),e[17]=t,e[18]=s):s=e[18];let c;e[19]!==s?(c=l("p",{className:"text-sm text-destructive",role:"alert",children:s}),e[19]=s,e[20]=c):c=e[20];let d;e[21]!==a.diagnostics?(d=a.diagnostics.map(xt),e[21]=a.diagnostics,e[22]=d):d=e[22];let r;e[23]!==d?(r=l("ul",{className:"flex flex-col gap-0.5",children:d}),e[23]=d,e[24]=r):r=e[24];let b;return e[25]!==c||e[26]!==r?(b=p("div",{className:"mt-3 flex flex-col gap-1","data-testid":"sc-editor-diagnostics",children:[c,r]}),e[25]=c,e[26]=r,e[27]=b):b=e[27],b};function xt(n){return l("li",{className:"font-mono text-[11px] text-destructive",children:n},n)}const vt=[{label:"string",validator:"v.string()"},{label:"number",validator:"v.number()"},{label:"boolean",validator:"v.boolean()"},{label:"bigint",validator:"v.int64()"},{label:"bytes",validator:"v.bytes()"},{label:"any",validator:"v.any()"}],yt="v.string()",Ct=n=>n.split(",").map(e=>e.trim()).filter(e=>e!==""),Nt=n=>{const e=Ne(83),{onApplied:m,tableNames:a}=n,t=Le(),s=at(),[c,d]=E(null),[r,b]=E(!1),[o,f]=E(null),[i,v]=E(""),[h,G]=E(""),[w,B]=E(yt),[y,z]=E(a[0]??""),[F,D]=E(""),[S,C]=E(""),[A,L]=E(!1);let me;e[0]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{d(null),v(""),G(""),D(""),C(""),L(!1)},e[0]=me):me=e[0];const W=me;let I;e[1]!==m?(I=async T=>{b(!0),f(null);try{const pe=await pt(T);f(pe),pe.kind==="ok"&&(m(pe.tables),W())}catch(pe){const Ie=pe;f({kind:"error",message:Ie instanceof Error?Ie.message:String(Ie)})}b(!1)},e[1]=m,e[2]=I):I=e[2];const q=I;let _;e[3]!==q||e[4]!==i?(_=()=>{be(q({kind:"addTable",table:i.trim()}))},e[3]=q,e[4]=i,e[5]=_):_=e[5];const ue=_;let j;e[6]!==h||e[7]!==q||e[8]!==y||e[9]!==w?(j=()=>{be(q({column:h.trim(),kind:"addOptionalColumn",table:y,validator:w}))},e[6]=h,e[7]=q,e[8]=y,e[9]=w,e[10]=j):j=e[10];const ie=j;let Q;e[11]!==S||e[12]!==F||e[13]!==q||e[14]!==y||e[15]!==A?(Q=()=>{be(q({fields:Ct(S),kind:"addIndex",name:F.trim(),table:y,unique:A}))},e[11]=S,e[12]=F,e[13]=q,e[14]=y,e[15]=A,e[16]=Q):Q=e[16];const Y=Q;let xe;e[17]===Symbol.for("react.memo_cache_sentinel")?(xe=()=>{f(null),d("addTable")},e[17]=xe):xe=e[17];const H=xe;let re;e[18]===Symbol.for("react.memo_cache_sentinel")?(re=()=>{f(null),d("addColumn")},e[18]=re):re=e[18];const ve=re;let O;e[19]===Symbol.for("react.memo_cache_sentinel")?(O=()=>{f(null),d("addIndex")},e[19]=O):O=e[19];const Z=O;let ee;e[20]!==t?(ee=()=>{d("destructive"),f({kind:"needs-migration",message:t("This edit changes stored data and must go through a migration. Review the migration before applying.")})},e[20]=t,e[21]=ee):ee=e[21];const de=ee;let R;e[22]===Symbol.for("react.memo_cache_sentinel")?(R=T=>{v(T.target.value)},e[22]=R):R=e[22];const te=R;let M;e[23]===Symbol.for("react.memo_cache_sentinel")?(M=T=>{G(T.target.value)},e[23]=M):M=e[23];const ye=M;let ce;e[24]===Symbol.for("react.memo_cache_sentinel")?(ce=T=>{B(T.target.value)},e[24]=ce):ce=e[24];const fe=ce;let K;e[25]===Symbol.for("react.memo_cache_sentinel")?(K=T=>{z(T.target.value)},e[25]=K):K=e[25];const X=K;let U;e[26]===Symbol.for("react.memo_cache_sentinel")?(U=T=>{D(T.target.value)},e[26]=U):U=e[26];const le=U;let V;e[27]===Symbol.for("react.memo_cache_sentinel")?(V=T=>{C(T.target.value)},e[27]=V):V=e[27];const se=V;let $;e[28]===Symbol.for("react.memo_cache_sentinel")?($=T=>{L(T.target.checked)},e[28]=$):$=e[28];const ae=$;let ne;e[29]!==s?(ne=()=>{be(s({to:"/migrations"}))},e[29]=s,e[30]=ne):ne=e[30];const g=ne;let oe;e[31]!==t?(oe=t("Edit schema"),e[31]=t,e[32]=oe):oe=e[32];let J;e[33]!==oe?(J=l(ze,{children:oe}),e[33]=oe,e[34]=J):J=e[34];let Ce;e[35]!==t?(Ce=t("Adds a table, column, or index to lunora/schema.ts and reruns codegen."),e[35]=t,e[36]=Ce):Ce=e[36];let he;e[37]!==Ce?(he=l(qe,{children:Ce}),e[37]=Ce,e[38]=he):he=e[38];let u;e[39]!==J||e[40]!==he?(u=p(Be,{children:[J,he]}),e[39]=J,e[40]=he,e[41]=u):u=e[41];const N=a.length>0;let x;e[42]!==c||e[43]!==de||e[44]!==N?(x=l(gt,{hasTables:N,mode:c,onAddColumn:ve,onAddIndex:Z,onAddTable:H,onDestructive:de}),e[42]=c,e[43]=de,e[44]=N,e[45]=x):x=e[45];let P;e[46]!==r||e[47]!==c||e[48]!==ue||e[49]!==t||e[50]!==i?(P=c==="addTable"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-table-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-table-name",children:t("Table name")}),l(ke,{"data-testid":"sc-editor-table-name",id:"sc-editor-table-name",onChange:te,value:i})]}),l(ge,{"data-testid":"sc-editor-table-apply",disabled:r||i.trim()==="",onClick:ue,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ge,{onClick:W,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[46]=r,e[47]=c,e[48]=ue,e[49]=t,e[50]=i,e[51]=P):P=e[51];let k;e[52]!==r||e[53]!==h||e[54]!==c||e[55]!==ie||e[56]!==t||e[57]!==a||e[58]!==y||e[59]!==w?(k=c==="addColumn"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-column-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-column-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-table",id:"sc-editor-column-table",onChange:X,value:y,children:a.map(Tt)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-column-name",children:t("Column name")}),l(ke,{"data-testid":"sc-editor-column-name",id:"sc-editor-column-name",onChange:ye,value:h})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-column-type",children:t("Column type")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-type",id:"sc-editor-column-type",onChange:fe,value:w,children:vt.map(St)})]}),l("span",{className:"text-[11px] text-muted-foreground",children:t("Optional")}),l(ge,{"data-testid":"sc-editor-column-apply",disabled:r||h.trim()===""||y==="",onClick:ie,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ge,{onClick:W,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[52]=r,e[53]=h,e[54]=c,e[55]=ie,e[56]=t,e[57]=a,e[58]=y,e[59]=w,e[60]=k):k=e[60];let Te;e[61]!==r||e[62]!==S||e[63]!==F||e[64]!==c||e[65]!==Y||e[66]!==t||e[67]!==a||e[68]!==y||e[69]!==A?(Te=c==="addIndex"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-index-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-index-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-index-table",id:"sc-editor-index-table",onChange:X,value:y,children:a.map(wt)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-index-name",children:t("Index name")}),l(ke,{"data-testid":"sc-editor-index-name",id:"sc-editor-index-name",onChange:le,value:F})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-index-fields",children:t("Index fields (comma-separated)")}),l(ke,{"data-testid":"sc-editor-index-fields",id:"sc-editor-index-fields",onChange:se,value:S})]}),p(_e,{className:"flex items-center gap-1 text-xs",htmlFor:"sc-editor-index-unique",children:[l("input",{checked:A,"data-testid":"sc-editor-index-unique",id:"sc-editor-index-unique",onChange:ae,type:"checkbox"}),l("span",{className:"text-muted-foreground",children:t("Unique")})]}),l(ge,{"data-testid":"sc-editor-index-apply",disabled:r||F.trim()===""||S.trim()==="",onClick:Y,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ge,{onClick:W,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[61]=r,e[62]=S,e[63]=F,e[64]=c,e[65]=Y,e[66]=t,e[67]=a,e[68]=y,e[69]=A,e[70]=Te):Te=e[70];let Se;e[71]!==g||e[72]!==o?(Se=l(bt,{onOpenMigrations:g,result:o}),e[71]=g,e[72]=o,e[73]=Se):Se=e[73];let we;e[74]!==x||e[75]!==P||e[76]!==k||e[77]!==Te||e[78]!==Se?(we=p(De,{children:[x,P,k,Te,Se]}),e[74]=x,e[75]=P,e[76]=k,e[77]=Te,e[78]=Se,e[79]=we):we=e[79];let Ee;return e[80]!==u||e[81]!==we?(Ee=p(je,{"data-testid":"sc-editor",size:"sm",children:[u,we]}),e[80]=u,e[81]=we,e[82]=Ee):Ee=e[82],Ee};function Tt(n){return l("option",{value:n,children:n},n)}function St(n){return l("option",{value:n.validator,children:n.label},n.validator)}function wt(n){return l("option",{value:n,children:n},n)}const Ve=[],_t=n=>{const e=Ne(5),{open:m}=n,a=m&&"rotate-90";let t;e[0]!==a?(t=Je("size-3.5 shrink-0 text-muted-foreground transition-transform duration-150",a),e[0]=a,e[1]=t):t=e[1];let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=l("path",{d:"m9 6 6 6-6 6"}),e[2]=s):s=e[2];let c;return e[3]!==t?(c=l("svg",{"aria-hidden":"true",className:t,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:s}),e[3]=t,e[4]=c):c=e[4],c},Ye=n=>{const e=Ne(20),{children:m,expanded:a,name:t,onToggle:s,rowCount:c,rowTestId:d,toggleTestId:r}=n;let b;e[0]!==a?(b=l(_t,{open:a}),e[0]=a,e[1]=b):b=e[1];let o;e[2]!==t?(o=l("span",{className:"truncate font-mono text-xs text-foreground",title:t,children:t}),e[2]=t,e[3]=o):o=e[3];let f;e[4]!==c?(f=p("span",{className:"ms-auto shrink-0 text-xs text-muted-foreground tabular-nums",children:["(",c,")"]}),e[4]=c,e[5]=f):f=e[5];let i;e[6]!==a||e[7]!==s||e[8]!==b||e[9]!==o||e[10]!==f||e[11]!==r?(i=p("button",{"aria-expanded":a,className:"flex w-full items-center gap-2 px-3 py-2 text-start transition-colors hover:bg-muted/50 aria-expanded:bg-muted/40","data-testid":r,onClick:s,type:"button",children:[b,o," ",f]}),e[6]=a,e[7]=s,e[8]=b,e[9]=o,e[10]=f,e[11]=r,e[12]=i):i=e[12];let v;e[13]!==m||e[14]!==a?(v=a&&l("div",{className:"px-3 pb-3 ps-8",children:m}),e[13]=m,e[14]=a,e[15]=v):v=e[15];let h;return e[16]!==d||e[17]!==i||e[18]!==v?(h=p("li",{className:"border-t border-border/60 first:border-t-0","data-testid":d,children:[i,v]}),e[16]=d,e[17]=i,e[18]=v,e[19]=h):h=e[19],h},He=n=>{const e=Ne(5),{columns:m,testId:a}=n;let t;e[0]!==m?(t=m.map(It),e[0]=m,e[1]=t):t=e[1];let s;return e[2]!==t||e[3]!==a?(s=l("ul",{className:"flex flex-wrap gap-1.5 pt-1","data-testid":a,children:t}),e[2]=t,e[3]=a,e[4]=s):s=e[4],s},Et=n=>{const e=Ne(10),{heading:m,indexes:a,testId:t}=n;let s;e[0]!==m?(s=l("p",{className:"mb-1.5 font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:m}),e[0]=m,e[1]=s):s=e[1];let c;e[2]!==a?(c=a.map(kt),e[2]=a,e[3]=c):c=e[3];let d;e[4]!==c||e[5]!==t?(d=l("ul",{className:"flex flex-col gap-1","data-testid":t,children:c}),e[4]=c,e[5]=t,e[6]=d):d=e[6];let r;return e[7]!==s||e[8]!==d?(r=p("div",{className:"pt-3",children:[s,d]}),e[7]=s,e[8]=d,e[9]=r):r=e[9],r},Xe=n=>Je("border-b-2 px-3 py-2 font-mono text-[11px] tracking-widest uppercase outline-none transition-colors",n?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),Wt=n=>{const e=Ne(85),{initialShardKey:m,initialTable:a,schemaEditable:t}=n,s=Le();let c;e[0]!==m||e[1]!==a?(c={initialShardKey:m,initialTable:a},e[0]=m,e[1]=a,e[2]=c):c=e[2];const{columns:d,diagramTables:r,error:b,expanded:o,filteredGlobalTables:f,filteredTables:i,globalColumns:v,globalError:h,globalExpanded:G,globalTables:w,indexes:B,refresh:y,setShardKey:z,setTableFilter:F,setView:D,shardColumnsError:S,shardKey:C,tableFilter:A,tables:L,toggle:me,toggleGlobal:W,view:I}=ct(c);let q;e[3]!==D?(q=()=>{D("list")},e[3]=D,e[4]=q):q=e[4];const _=q;let ue;e[5]!==D?(ue=()=>{D("graph")},e[5]=D,e[6]=ue):ue=e[6];const j=ue;let ie;e[7]!==F?(ie=g=>{F(g.target.value)},e[7]=F,e[8]=ie):ie=e[8];const Q=ie;let Y;e[9]!==y||e[10]!==C?(Y=g=>{be(y(C))},e[9]=y,e[10]=C,e[11]=Y):Y=e[11];const xe=Y;let H;e[12]!==L?(H=L??[],e[12]=L,e[13]=H):H=e[13];let re;e[14]!==H?(re=H.map(At),e[14]=H,e[15]=re):re=e[15];const ve=re;let O;e[16]!==z||e[17]!==C?(O=l(We,{onChange:z,testId:"sc-shard-input",value:C}),e[16]=z,e[17]=C,e[18]=O):O=e[18];let Z;e[19]!==s?(Z=s("Schema view"),e[19]=s,e[20]=Z):Z=e[20];const ee=I==="graph",de=I==="graph";let R;e[21]!==de?(R=Xe(de),e[21]=de,e[22]=R):R=e[22];let te;e[23]!==s?(te=s("Graph"),e[23]=s,e[24]=te):te=e[24];let M;e[25]!==j||e[26]!==ee||e[27]!==R||e[28]!==te?(M=l("button",{"aria-selected":ee,className:R,"data-testid":"sc-view-graph",onClick:j,role:"tab",type:"button",children:te}),e[25]=j,e[26]=ee,e[27]=R,e[28]=te,e[29]=M):M=e[29];const ye=I==="list",ce=I==="list";let fe;e[30]!==ce?(fe=Xe(ce),e[30]=ce,e[31]=fe):fe=e[31];let K;e[32]!==s?(K=s("Table list"),e[32]=s,e[33]=K):K=e[33];let X;e[34]!==_||e[35]!==ye||e[36]!==fe||e[37]!==K?(X=l("button",{"aria-selected":ye,className:fe,"data-testid":"sc-view-list",onClick:_,role:"tab",type:"button",children:K}),e[34]=_,e[35]=ye,e[36]=fe,e[37]=K,e[38]=X):X=e[38];let U;e[39]!==M||e[40]!==X||e[41]!==Z?(U=p("div",{"aria-label":Z,className:"flex items-center gap-1","data-testid":"sc-view-toggle",role:"tablist",children:[M,X]}),e[39]=M,e[40]=X,e[41]=Z,e[42]=U):U=e[42];let le;e[43]!==U||e[44]!==O?(le=p("div",{className:"flex flex-wrap items-center gap-3",children:[O,U]}),e[43]=U,e[44]=O,e[45]=le):le=e[45];let V;e[46]!==xe||e[47]!==t||e[48]!==ve?(V=t===!0&&l(Nt,{onApplied:xe,tableNames:ve}),e[46]=xe,e[47]=t,e[48]=ve,e[49]=V):V=e[49];let se;e[50]!==Q||e[51]!==s||e[52]!==A||e[53]!==I?(se=I==="list"&&l(ke,{"aria-label":s("Filter tables"),className:"h-8 max-w-xs","data-testid":"sc-filter",onChange:Q,placeholder:s("Filter tables"),value:A}),e[50]=Q,e[51]=s,e[52]=A,e[53]=I,e[54]=se):se=e[54];let $;e[55]!==r||e[56]!==b||e[57]!==h||e[58]!==S||e[59]!==C||e[60]!==I?($=I==="graph"&&p("div",{className:"flex flex-col gap-2","data-testid":"sc-graph-view",children:[b!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:b}),h!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:h}),l(st,{columnsError:S[C]===!0,tables:r,testIdPrefix:"sc-graph"})]}),e[55]=r,e[56]=b,e[57]=h,e[58]=S,e[59]=C,e[60]=I,e[61]=$):$=e[61];let ae;e[62]!==d||e[63]!==b||e[64]!==o||e[65]!==f||e[66]!==i||e[67]!==v||e[68]!==h||e[69]!==G||e[70]!==w||e[71]!==B||e[72]!==C||e[73]!==s||e[74]!==L||e[75]!==me||e[76]!==W||e[77]!==I?(ae=I==="list"&&p("div",{className:"flex flex-col gap-4",children:[p(je,{"data-testid":"sc-shard-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Re,{tier:"shard"}),l(ze,{children:s("Shard tables")}),L!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:i.length})]}),l(qe,{children:Pe.shard.hint})]}),p(De,{children:[b!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:b}),L!==null&&L.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-empty",children:s("No tables in this shard.")}),L!==null&&L.length>0&&i.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-no-match",children:s("No tables match your filter.")}),i.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-table-list",children:i.map(g=>{const oe=`${C}:${g.name}`,J=B[oe]??[];return p(Ye,{expanded:o===g.name,name:g.name,onToggle:()=>{be(me(g.name))},rowCount:g.rowCount,rowTestId:`sc-table-${g.name}`,toggleTestId:`sc-toggle-${g.name}`,children:[l(He,{columns:d[oe]??Ve,testId:`sc-columns-${g.name}`}),J.length>0&&l(Et,{heading:s("Indexes"),indexes:J,testId:`sc-indexes-${g.name}`})]},g.name)})})]})]}),p(je,{"data-testid":"sc-global-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Re,{tier:"global"}),l(ze,{children:s("Global tables (D1)")}),w!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:f.length})]}),l(qe,{children:Pe.global.hint})]}),p(De,{children:[h!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:h}),w!==null&&w.length===0&&l(Qe,{description:Pe.global.hint,testId:"sc-global-empty",title:s("No global tables.")}),w!==null&&w.length>0&&f.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-global-no-match",children:s("No tables match your filter.")}),f.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-global-table-list",children:f.map(g=>l(Ye,{expanded:G===g.name,name:g.name,onToggle:()=>{be(W(g.name))},rowCount:g.rowCount,rowTestId:`sc-global-table-${g.name}`,toggleTestId:`sc-global-toggle-${g.name}`,children:l(He,{columns:v[g.name]??Ve,testId:`sc-global-columns-${g.name}`})},g.name))})]})]})]}),e[62]=d,e[63]=b,e[64]=o,e[65]=f,e[66]=i,e[67]=v,e[68]=h,e[69]=G,e[70]=w,e[71]=B,e[72]=C,e[73]=s,e[74]=L,e[75]=me,e[76]=W,e[77]=I,e[78]=ae):ae=e[78];let ne;return e[79]!==le||e[80]!==V||e[81]!==se||e[82]!==$||e[83]!==ae?(ne=p("div",{className:"flex flex-col gap-4","data-testid":"lunora-schema",children:[le,V,se,$,ae]}),e[79]=le,e[80]=V,e[81]=se,e[82]=$,e[83]=ae,e[84]=ne):ne=e[84],ne};function It(n){return l("li",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:n},n)}function kt(n){return p("li",{className:"flex flex-wrap items-center gap-1.5 text-xs",children:[l("span",{className:"font-mono",children:n.name}),l(Fe,{variant:"outline",children:n.type}),n.unique===!0&&l(Fe,{variant:"secondary",children:"unique"}),l("span",{className:"text-muted-foreground",children:n.fields.join(", ")})]},`${n.type}:${n.name}`)}function At(n){return n.name}export{Wt as SchemaViewer};
1
+ import{c as Ne}from"react/compiler-runtime";import{ShardInput as We}from"../packem_shared/ShardInput-XumEzeT0.js";import{S as Re,T as Pe}from"../packem_shared/storage-tier-C2mKwYRj.js";import{B as Fe}from"../packem_shared/badge-cAk9Di1Q.js";import{b as ze,d as qe,c as Be,a as De,C as je}from"../packem_shared/card-BGlQzQY-.js";import{E as Qe}from"../packem_shared/empty-state-B939z6K2.js";import{I as ke}from"../packem_shared/input-CY5W3wzv.js";import{useT as Le}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{c as Oe,d as Ae,b as $e,f as be}from"../packem_shared/internal-7bgd8inO.js";import{c as Je}from"../packem_shared/utils-bhneXptQ.js";import{useLunora as Ze}from"@lunora/react";import{useState as E,useEffect as Ge,useRef as et}from"react";import{u as tt}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{ADMIN_FUNCTIONS as Me}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{r as lt}from"../packem_shared/shard-history-QcjcMnCA.js";import{S as st}from"../packem_shared/schema-diagram-CPcjPZj3.js";import{useNavigate as at}from"@tanstack/react-router";import{B as ge}from"../packem_shared/button-BOPLD1un.js";import{L as _e}from"../packem_shared/label-BOUo-DP0.js";import{jsx as l,jsxs as p,Fragment as Ke}from"react/jsx-runtime";const nt=Oe(Me.listTables),ot=Oe(Me.listTableIndexes),it=Oe(Me.readTablePage),rt=Oe(Me.describeTables),dt={},Ue=[],ct=n=>{const e=Ne(74),{initialShardKey:m,initialTable:a}=n,t=Ze(),[s,c]=E("graph"),{queryShardKey:d,setShardKey:r,shardKey:b}=tt(m),[o,f]=E(""),[i,v]=E(null),[h,G]=E(null);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w={},e[0]=w):w=e[0];const[B,y]=E(w);let z;e[1]===Symbol.for("react.memo_cache_sentinel")?(z={},e[1]=z):z=e[1];const[F,D]=E(z),[S,C]=E(null);let A;e[2]===Symbol.for("react.memo_cache_sentinel")?(A={},e[2]=A):A=e[2];const[L,me]=E(A);let W;e[3]===Symbol.for("react.memo_cache_sentinel")?(W={},e[3]=W):W=e[3];const[I,q]=E(W),[_,ue]=E(null),[j,ie]=E(null);let Q;e[4]===Symbol.for("react.memo_cache_sentinel")?(Q={},e[4]=Q):Q=e[4];const[Y,xe]=E(Q),[H,re]=E(null);let ve;e[5]!==t?(ve=async u=>{G(null);try{const N=await t.query(nt,{},Ae(u));lt(u),v(N),y({}),D({}),C(null),me(x=>Object.fromEntries(Object.entries(x).filter(P=>{const[k]=P;return k!==u}))),q(x=>Object.fromEntries(Object.entries(x).filter(P=>{const[k]=P;return k!==u})))}catch(N){const x=N;v(null),G($e(x))}},e[5]=t,e[6]=ve):ve=e[6];const O=ve;let Z;e[7]!==t?(Z=async()=>{ie(null);try{ue(await t.listGlobalTables())}catch(u){const N=u;ue(null),ie($e(N))}},e[7]=t,e[8]=Z):Z=e[8];const ee=Z;let de,R;e[9]!==d||e[10]!==O||e[11]!==ee?(de=()=>{be(O(d)),be(ee())},R=[O,ee,d],e[9]=d,e[10]=O,e[11]=ee,e[12]=de,e[13]=R):(de=e[12],R=e[13]),Ge(de,R);let te;e[14]!==t||e[15]!==B||e[16]!==S||e[17]!==d?(te=async u=>{if(S===u){C(null);return}C(u);const N=`${d}:${u}`;if(B[N]!==void 0)return;const[x,P]=await Promise.allSettled([t.query(it,{limit:1,offset:0,table:u},Ae(d)),t.query(ot,{table:u},Ae(d))]);x.status==="fulfilled"?y(k=>({...k,[N]:x.value.columns})):G($e(x.reason)),P.status==="fulfilled"&&D(k=>({...k,[N]:P.value.indexes}))},e[14]=t,e[15]=B,e[16]=S,e[17]=d,e[18]=te):te=e[18];const M=te;let ye;e[19]!==t||e[20]!==Y||e[21]!==H?(ye=async u=>{if(H===u){re(null);return}if(re(u),Y[u]===void 0)try{const N=await t.readGlobalTablePage({limit:1,offset:0,table:u});xe(x=>({...x,[u]:N.columns}))}catch(N){ie($e(N))}},e[19]=t,e[20]=Y,e[21]=H,e[22]=ye):ye=e[22];const ce=ye,fe=et(void 0);let K,X;e[23]!==a||e[24]!==i||e[25]!==M?(K=()=>{a===void 0||i===null||fe.current===a||i.some(u=>u.name===a)&&(fe.current=a,be(M(a)))},X=[a,i,M],e[23]=a,e[24]=i,e[25]=M,e[26]=K,e[27]=X):(K=e[26],X=e[27]),Ge(K,X);let U;e[28]!==t?(U=async(u,N,x)=>{const[P,k]=await Promise.all([Promise.allSettled([t.query(rt,{tables:[...N,...x]},Ae(u))]),Promise.all(x.map(async T=>{const pe=await Promise.allSettled([t.readGlobalTablePage({limit:1,offset:0,table:T})]),Ie=pe[0].status==="fulfilled"?pe[0].value:void 0;return{columns:Ie?.columns??[],refs:Ie?.refs??{},table:T}}))]),Te=P[0].status==="fulfilled"?P[0].value?.columnsByTable??{}:{},Se=P[0].status==="rejected",we=new Map(k.map(mt)),Ee=[...N,...x].map(T=>{const pe=Te[T]??[];return[T,pe.length>0?pe:we.get(T)??[]]});me(T=>({...T,[u]:Object.fromEntries(Ee)})),q(T=>({...T,[u]:Se}))},e[28]=t,e[29]=U):U=e[29];const le=U;let V,se;e[30]!==j||e[31]!==_||e[32]!==le||e[33]!==d||e[34]!==L||e[35]!==i||e[36]!==s?(V=()=>{s!=="graph"||i===null||_===null&&j===null||L[d]!==void 0||be(le(d,i.map(ut),(_??[]).map(ft)))},se=[s,i,_,j,d,L,le],e[30]=j,e[31]=_,e[32]=le,e[33]=d,e[34]=L,e[35]=i,e[36]=s,e[37]=V,e[38]=se):(V=e[37],se=e[38]),Ge(V,se);const $=L[d]??dt;let ae;if(e[39]!==$||e[40]!==_||e[41]!==i){let u;e[43]!==$?(u=k=>({columns:$[k.name]??Ue,name:k.name,tier:"shard"}),e[43]=$,e[44]=u):u=e[44];const N=(i??[]).map(u);let x;e[45]!==$?(x=k=>({columns:$[k.name]??Ue,name:k.name,tier:"global"}),e[45]=$,e[46]=x):x=e[46];const P=(_??[]).map(x);ae=[...N,...P],e[39]=$,e[40]=_,e[41]=i,e[42]=ae}else ae=e[42];const ne=ae;let g;if(e[47]!==o||e[48]!==i){const u=o.trim().toLowerCase();g=(i??[]).filter(N=>N.name.toLowerCase().includes(u)),e[47]=o,e[48]=i,e[49]=g}else g=e[49];const oe=g;let J;if(e[50]!==_||e[51]!==o){const u=o.trim().toLowerCase();J=(_??[]).filter(N=>N.name.toLowerCase().includes(u)),e[50]=_,e[51]=o,e[52]=J}else J=e[52];const Ce=J;let he;return e[53]!==B||e[54]!==ne||e[55]!==h||e[56]!==S||e[57]!==Ce||e[58]!==oe||e[59]!==Y||e[60]!==j||e[61]!==H||e[62]!==_||e[63]!==F||e[64]!==O||e[65]!==r||e[66]!==I||e[67]!==b||e[68]!==o||e[69]!==i||e[70]!==M||e[71]!==ce||e[72]!==s?(he={columns:B,diagramTables:ne,error:h,expanded:S,filteredGlobalTables:Ce,filteredTables:oe,globalColumns:Y,globalError:j,globalExpanded:H,globalTables:_,indexes:F,refresh:O,setShardKey:r,setTableFilter:f,setView:c,shardColumnsError:I,shardKey:b,tableFilter:o,tables:i,toggle:M,toggleGlobal:ce,view:s},e[53]=B,e[54]=ne,e[55]=h,e[56]=S,e[57]=Ce,e[58]=oe,e[59]=Y,e[60]=j,e[61]=H,e[62]=_,e[63]=F,e[64]=O,e[65]=r,e[66]=I,e[67]=b,e[68]=o,e[69]=i,e[70]=M,e[71]=ce,e[72]=s,e[73]=he):he=e[73],he};function mt(n){const{columns:e,refs:m,table:a}=n;return[a,e.map(t=>{const s=m[t];return s===void 0?{name:t,optional:!1,type:""}:{name:t,optional:!1,ref:s,type:"id"}})]}function ut(n){return n.name}function ft(n){return n.name}const ht="/__lunora/schema-edit",pt=async n=>{const e=await fetch(ht,{body:JSON.stringify(n),headers:{"Content-Type":"application/json","X-Lunora-Studio":"1"},method:"POST"}),m=await e.json();return m.needsMigration===!0?{kind:"needs-migration",message:m.message??"This edit needs a migration."}:e.ok&&m.tables!==void 0?{diagnostics:m.diagnostics??[],kind:"ok",tables:m.tables}:{kind:"error",message:m.error??`schema edit failed (${String(e.status)})`}},gt=n=>{const e=Ne(32),{hasTables:m,mode:a,onAddColumn:t,onAddIndex:s,onAddTable:c,onDestructive:d}=n,r=Le(),b=a==="addTable"?"default":"outline";let o;e[0]!==r?(o=r("Add table"),e[0]=r,e[1]=o):o=e[1];let f;e[2]!==c||e[3]!==b||e[4]!==o?(f=l(ge,{"data-testid":"sc-editor-add-table",onClick:c,size:"xs",type:"button",variant:b,children:o}),e[2]=c,e[3]=b,e[4]=o,e[5]=f):f=e[5];const i=!m,v=a==="addColumn"?"default":"outline";let h;e[6]!==r?(h=r("Add column"),e[6]=r,e[7]=h):h=e[7];let G;e[8]!==t||e[9]!==i||e[10]!==v||e[11]!==h?(G=l(ge,{"data-testid":"sc-editor-add-column",disabled:i,onClick:t,size:"xs",type:"button",variant:v,children:h}),e[8]=t,e[9]=i,e[10]=v,e[11]=h,e[12]=G):G=e[12];const w=!m,B=a==="addIndex"?"default":"outline";let y;e[13]!==r?(y=r("Add index"),e[13]=r,e[14]=y):y=e[14];let z;e[15]!==s||e[16]!==y||e[17]!==w||e[18]!==B?(z=l(ge,{"data-testid":"sc-editor-add-index",disabled:w,onClick:s,size:"xs",type:"button",variant:B,children:y}),e[15]=s,e[16]=y,e[17]=w,e[18]=B,e[19]=z):z=e[19];const F=!m,D=a==="destructive"?"default":"ghost";let S;e[20]!==r?(S=r("Rename / drop / change type…"),e[20]=r,e[21]=S):S=e[21];let C;e[22]!==d||e[23]!==F||e[24]!==D||e[25]!==S?(C=l(ge,{"data-testid":"sc-editor-destructive",disabled:F,onClick:d,size:"xs",type:"button",variant:D,children:S}),e[22]=d,e[23]=F,e[24]=D,e[25]=S,e[26]=C):C=e[26];let A;return e[27]!==z||e[28]!==C||e[29]!==f||e[30]!==G?(A=p("div",{className:"flex flex-wrap gap-2",children:[f,G,z,C]}),e[27]=z,e[28]=C,e[29]=f,e[30]=G,e[31]=A):A=e[31],A},bt=n=>{const e=Ne(28),{onOpenMigrations:m,result:a}=n,t=Le();if(a===null){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ke,{}),e[0]=o):o=e[0],o}if(a.kind==="error"){let o;return e[1]!==a.message?(o=l("p",{className:"mt-3 text-sm text-destructive","data-testid":"sc-editor-error",role:"alert",children:a.message}),e[1]=a.message,e[2]=o):o=e[2],o}if(a.kind==="needs-migration"){let o;e[3]!==a.message||e[4]!==t?(o=a.message===""?t("This edit changes stored data and must go through a migration. Review the migration before applying."):a.message,e[3]=a.message,e[4]=t,e[5]=o):o=e[5];let f;e[6]!==o?(f=l("p",{className:"text-sm text-warning",role:"alert",children:o}),e[6]=o,e[7]=f):f=e[7];let i;e[8]!==t?(i=t("Open Migrations"),e[8]=t,e[9]=i):i=e[9];let v;e[10]!==m||e[11]!==i?(v=l(ge,{className:"self-start","data-testid":"sc-editor-open-migrations",onClick:m,size:"xs",type:"button",variant:"outline",children:i}),e[10]=m,e[11]=i,e[12]=v):v=e[12];let h;return e[13]!==f||e[14]!==v?(h=p("div",{className:"mt-3 flex flex-col gap-2","data-testid":"sc-editor-needs-migration",children:[f,v]}),e[13]=f,e[14]=v,e[15]=h):h=e[15],h}if(a.diagnostics.length===0){let o;return e[16]===Symbol.for("react.memo_cache_sentinel")?(o=l(Ke,{}),e[16]=o):o=e[16],o}let s;e[17]!==t?(s=t("Codegen reported diagnostics:"),e[17]=t,e[18]=s):s=e[18];let c;e[19]!==s?(c=l("p",{className:"text-sm text-destructive",role:"alert",children:s}),e[19]=s,e[20]=c):c=e[20];let d;e[21]!==a.diagnostics?(d=a.diagnostics.map(xt),e[21]=a.diagnostics,e[22]=d):d=e[22];let r;e[23]!==d?(r=l("ul",{className:"flex flex-col gap-0.5",children:d}),e[23]=d,e[24]=r):r=e[24];let b;return e[25]!==c||e[26]!==r?(b=p("div",{className:"mt-3 flex flex-col gap-1","data-testid":"sc-editor-diagnostics",children:[c,r]}),e[25]=c,e[26]=r,e[27]=b):b=e[27],b};function xt(n){return l("li",{className:"font-mono text-[11px] text-destructive",children:n},n)}const vt=[{label:"string",validator:"v.string()"},{label:"number",validator:"v.number()"},{label:"boolean",validator:"v.boolean()"},{label:"bigint",validator:"v.int64()"},{label:"bytes",validator:"v.bytes()"},{label:"any",validator:"v.any()"}],yt="v.string()",Ct=n=>n.split(",").map(e=>e.trim()).filter(e=>e!==""),Nt=n=>{const e=Ne(83),{onApplied:m,tableNames:a}=n,t=Le(),s=at(),[c,d]=E(null),[r,b]=E(!1),[o,f]=E(null),[i,v]=E(""),[h,G]=E(""),[w,B]=E(yt),[y,z]=E(a[0]??""),[F,D]=E(""),[S,C]=E(""),[A,L]=E(!1);let me;e[0]===Symbol.for("react.memo_cache_sentinel")?(me=()=>{d(null),v(""),G(""),D(""),C(""),L(!1)},e[0]=me):me=e[0];const W=me;let I;e[1]!==m?(I=async T=>{b(!0),f(null);try{const pe=await pt(T);f(pe),pe.kind==="ok"&&(m(pe.tables),W())}catch(pe){const Ie=pe;f({kind:"error",message:Ie instanceof Error?Ie.message:String(Ie)})}b(!1)},e[1]=m,e[2]=I):I=e[2];const q=I;let _;e[3]!==q||e[4]!==i?(_=()=>{be(q({kind:"addTable",table:i.trim()}))},e[3]=q,e[4]=i,e[5]=_):_=e[5];const ue=_;let j;e[6]!==h||e[7]!==q||e[8]!==y||e[9]!==w?(j=()=>{be(q({column:h.trim(),kind:"addOptionalColumn",table:y,validator:w}))},e[6]=h,e[7]=q,e[8]=y,e[9]=w,e[10]=j):j=e[10];const ie=j;let Q;e[11]!==S||e[12]!==F||e[13]!==q||e[14]!==y||e[15]!==A?(Q=()=>{be(q({fields:Ct(S),kind:"addIndex",name:F.trim(),table:y,unique:A}))},e[11]=S,e[12]=F,e[13]=q,e[14]=y,e[15]=A,e[16]=Q):Q=e[16];const Y=Q;let xe;e[17]===Symbol.for("react.memo_cache_sentinel")?(xe=()=>{f(null),d("addTable")},e[17]=xe):xe=e[17];const H=xe;let re;e[18]===Symbol.for("react.memo_cache_sentinel")?(re=()=>{f(null),d("addColumn")},e[18]=re):re=e[18];const ve=re;let O;e[19]===Symbol.for("react.memo_cache_sentinel")?(O=()=>{f(null),d("addIndex")},e[19]=O):O=e[19];const Z=O;let ee;e[20]!==t?(ee=()=>{d("destructive"),f({kind:"needs-migration",message:t("This edit changes stored data and must go through a migration. Review the migration before applying.")})},e[20]=t,e[21]=ee):ee=e[21];const de=ee;let R;e[22]===Symbol.for("react.memo_cache_sentinel")?(R=T=>{v(T.target.value)},e[22]=R):R=e[22];const te=R;let M;e[23]===Symbol.for("react.memo_cache_sentinel")?(M=T=>{G(T.target.value)},e[23]=M):M=e[23];const ye=M;let ce;e[24]===Symbol.for("react.memo_cache_sentinel")?(ce=T=>{B(T.target.value)},e[24]=ce):ce=e[24];const fe=ce;let K;e[25]===Symbol.for("react.memo_cache_sentinel")?(K=T=>{z(T.target.value)},e[25]=K):K=e[25];const X=K;let U;e[26]===Symbol.for("react.memo_cache_sentinel")?(U=T=>{D(T.target.value)},e[26]=U):U=e[26];const le=U;let V;e[27]===Symbol.for("react.memo_cache_sentinel")?(V=T=>{C(T.target.value)},e[27]=V):V=e[27];const se=V;let $;e[28]===Symbol.for("react.memo_cache_sentinel")?($=T=>{L(T.target.checked)},e[28]=$):$=e[28];const ae=$;let ne;e[29]!==s?(ne=()=>{be(s({to:"/migrations"}))},e[29]=s,e[30]=ne):ne=e[30];const g=ne;let oe;e[31]!==t?(oe=t("Edit schema"),e[31]=t,e[32]=oe):oe=e[32];let J;e[33]!==oe?(J=l(ze,{children:oe}),e[33]=oe,e[34]=J):J=e[34];let Ce;e[35]!==t?(Ce=t("Adds a table, column, or index to lunora/schema.ts and reruns codegen."),e[35]=t,e[36]=Ce):Ce=e[36];let he;e[37]!==Ce?(he=l(qe,{children:Ce}),e[37]=Ce,e[38]=he):he=e[38];let u;e[39]!==J||e[40]!==he?(u=p(Be,{children:[J,he]}),e[39]=J,e[40]=he,e[41]=u):u=e[41];const N=a.length>0;let x;e[42]!==c||e[43]!==de||e[44]!==N?(x=l(gt,{hasTables:N,mode:c,onAddColumn:ve,onAddIndex:Z,onAddTable:H,onDestructive:de}),e[42]=c,e[43]=de,e[44]=N,e[45]=x):x=e[45];let P;e[46]!==r||e[47]!==c||e[48]!==ue||e[49]!==t||e[50]!==i?(P=c==="addTable"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-table-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-table-name",children:t("Table name")}),l(ke,{"data-testid":"sc-editor-table-name",id:"sc-editor-table-name",onChange:te,value:i})]}),l(ge,{"data-testid":"sc-editor-table-apply",disabled:r||i.trim()==="",onClick:ue,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ge,{onClick:W,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[46]=r,e[47]=c,e[48]=ue,e[49]=t,e[50]=i,e[51]=P):P=e[51];let k;e[52]!==r||e[53]!==h||e[54]!==c||e[55]!==ie||e[56]!==t||e[57]!==a||e[58]!==y||e[59]!==w?(k=c==="addColumn"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-column-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-column-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-table",id:"sc-editor-column-table",onChange:X,value:y,children:a.map(Tt)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-column-name",children:t("Column name")}),l(ke,{"data-testid":"sc-editor-column-name",id:"sc-editor-column-name",onChange:ye,value:h})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-column-type",children:t("Column type")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-type",id:"sc-editor-column-type",onChange:fe,value:w,children:vt.map(St)})]}),l("span",{className:"text-[11px] text-muted-foreground",children:t("Optional")}),l(ge,{"data-testid":"sc-editor-column-apply",disabled:r||h.trim()===""||y==="",onClick:ie,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ge,{onClick:W,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[52]=r,e[53]=h,e[54]=c,e[55]=ie,e[56]=t,e[57]=a,e[58]=y,e[59]=w,e[60]=k):k=e[60];let Te;e[61]!==r||e[62]!==S||e[63]!==F||e[64]!==c||e[65]!==Y||e[66]!==t||e[67]!==a||e[68]!==y||e[69]!==A?(Te=c==="addIndex"&&p("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-index-form",children:[p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-index-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-index-table",id:"sc-editor-index-table",onChange:X,value:y,children:a.map(wt)})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-index-name",children:t("Index name")}),l(ke,{"data-testid":"sc-editor-index-name",id:"sc-editor-index-name",onChange:le,value:F})]}),p("div",{className:"flex flex-col gap-1 text-xs",children:[l(_e,{htmlFor:"sc-editor-index-fields",children:t("Index fields (comma-separated)")}),l(ke,{"data-testid":"sc-editor-index-fields",id:"sc-editor-index-fields",onChange:se,value:S})]}),p(_e,{className:"flex items-center gap-1 text-xs",htmlFor:"sc-editor-index-unique",children:[l("input",{checked:A,"data-testid":"sc-editor-index-unique",id:"sc-editor-index-unique",onChange:ae,type:"checkbox"}),l("span",{className:"text-muted-foreground",children:t("Unique")})]}),l(ge,{"data-testid":"sc-editor-index-apply",disabled:r||F.trim()===""||S.trim()==="",onClick:Y,size:"xs",type:"button",children:t(r?"Applying…":"Apply")}),l(ge,{onClick:W,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[61]=r,e[62]=S,e[63]=F,e[64]=c,e[65]=Y,e[66]=t,e[67]=a,e[68]=y,e[69]=A,e[70]=Te):Te=e[70];let Se;e[71]!==g||e[72]!==o?(Se=l(bt,{onOpenMigrations:g,result:o}),e[71]=g,e[72]=o,e[73]=Se):Se=e[73];let we;e[74]!==x||e[75]!==P||e[76]!==k||e[77]!==Te||e[78]!==Se?(we=p(De,{children:[x,P,k,Te,Se]}),e[74]=x,e[75]=P,e[76]=k,e[77]=Te,e[78]=Se,e[79]=we):we=e[79];let Ee;return e[80]!==u||e[81]!==we?(Ee=p(je,{"data-testid":"sc-editor",size:"sm",children:[u,we]}),e[80]=u,e[81]=we,e[82]=Ee):Ee=e[82],Ee};function Tt(n){return l("option",{value:n,children:n},n)}function St(n){return l("option",{value:n.validator,children:n.label},n.validator)}function wt(n){return l("option",{value:n,children:n},n)}const Ve=[],_t=n=>{const e=Ne(5),{open:m}=n,a=m&&"rotate-90";let t;e[0]!==a?(t=Je("size-3.5 shrink-0 text-muted-foreground transition-transform duration-150",a),e[0]=a,e[1]=t):t=e[1];let s;e[2]===Symbol.for("react.memo_cache_sentinel")?(s=l("path",{d:"m9 6 6 6-6 6"}),e[2]=s):s=e[2];let c;return e[3]!==t?(c=l("svg",{"aria-hidden":"true",className:t,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:s}),e[3]=t,e[4]=c):c=e[4],c},Ye=n=>{const e=Ne(20),{children:m,expanded:a,name:t,onToggle:s,rowCount:c,rowTestId:d,toggleTestId:r}=n;let b;e[0]!==a?(b=l(_t,{open:a}),e[0]=a,e[1]=b):b=e[1];let o;e[2]!==t?(o=l("span",{className:"truncate font-mono text-xs text-foreground",title:t,children:t}),e[2]=t,e[3]=o):o=e[3];let f;e[4]!==c?(f=p("span",{className:"ms-auto shrink-0 text-xs text-muted-foreground tabular-nums",children:["(",c,")"]}),e[4]=c,e[5]=f):f=e[5];let i;e[6]!==a||e[7]!==s||e[8]!==b||e[9]!==o||e[10]!==f||e[11]!==r?(i=p("button",{"aria-expanded":a,className:"flex w-full items-center gap-2 px-3 py-2 text-start transition-colors hover:bg-muted/50 aria-expanded:bg-muted/40","data-testid":r,onClick:s,type:"button",children:[b,o," ",f]}),e[6]=a,e[7]=s,e[8]=b,e[9]=o,e[10]=f,e[11]=r,e[12]=i):i=e[12];let v;e[13]!==m||e[14]!==a?(v=a&&l("div",{className:"px-3 pb-3 ps-8",children:m}),e[13]=m,e[14]=a,e[15]=v):v=e[15];let h;return e[16]!==d||e[17]!==i||e[18]!==v?(h=p("li",{className:"border-t border-border/60 first:border-t-0","data-testid":d,children:[i,v]}),e[16]=d,e[17]=i,e[18]=v,e[19]=h):h=e[19],h},He=n=>{const e=Ne(5),{columns:m,testId:a}=n;let t;e[0]!==m?(t=m.map(It),e[0]=m,e[1]=t):t=e[1];let s;return e[2]!==t||e[3]!==a?(s=l("ul",{className:"flex flex-wrap gap-1.5 pt-1","data-testid":a,children:t}),e[2]=t,e[3]=a,e[4]=s):s=e[4],s},Et=n=>{const e=Ne(10),{heading:m,indexes:a,testId:t}=n;let s;e[0]!==m?(s=l("p",{className:"mb-1.5 font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:m}),e[0]=m,e[1]=s):s=e[1];let c;e[2]!==a?(c=a.map(kt),e[2]=a,e[3]=c):c=e[3];let d;e[4]!==c||e[5]!==t?(d=l("ul",{className:"flex flex-col gap-1","data-testid":t,children:c}),e[4]=c,e[5]=t,e[6]=d):d=e[6];let r;return e[7]!==s||e[8]!==d?(r=p("div",{className:"pt-3",children:[s,d]}),e[7]=s,e[8]=d,e[9]=r):r=e[9],r},Xe=n=>Je("border-b-2 px-3 py-2 font-mono text-[11px] tracking-widest uppercase outline-none transition-colors",n?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),Wt=n=>{const e=Ne(85),{initialShardKey:m,initialTable:a,schemaEditable:t}=n,s=Le();let c;e[0]!==m||e[1]!==a?(c={initialShardKey:m,initialTable:a},e[0]=m,e[1]=a,e[2]=c):c=e[2];const{columns:d,diagramTables:r,error:b,expanded:o,filteredGlobalTables:f,filteredTables:i,globalColumns:v,globalError:h,globalExpanded:G,globalTables:w,indexes:B,refresh:y,setShardKey:z,setTableFilter:F,setView:D,shardColumnsError:S,shardKey:C,tableFilter:A,tables:L,toggle:me,toggleGlobal:W,view:I}=ct(c);let q;e[3]!==D?(q=()=>{D("list")},e[3]=D,e[4]=q):q=e[4];const _=q;let ue;e[5]!==D?(ue=()=>{D("graph")},e[5]=D,e[6]=ue):ue=e[6];const j=ue;let ie;e[7]!==F?(ie=g=>{F(g.target.value)},e[7]=F,e[8]=ie):ie=e[8];const Q=ie;let Y;e[9]!==y||e[10]!==C?(Y=g=>{be(y(C))},e[9]=y,e[10]=C,e[11]=Y):Y=e[11];const xe=Y;let H;e[12]!==L?(H=L??[],e[12]=L,e[13]=H):H=e[13];let re;e[14]!==H?(re=H.map(At),e[14]=H,e[15]=re):re=e[15];const ve=re;let O;e[16]!==z||e[17]!==C?(O=l(We,{onChange:z,testId:"sc-shard-input",value:C}),e[16]=z,e[17]=C,e[18]=O):O=e[18];let Z;e[19]!==s?(Z=s("Schema view"),e[19]=s,e[20]=Z):Z=e[20];const ee=I==="graph",de=I==="graph";let R;e[21]!==de?(R=Xe(de),e[21]=de,e[22]=R):R=e[22];let te;e[23]!==s?(te=s("Graph"),e[23]=s,e[24]=te):te=e[24];let M;e[25]!==j||e[26]!==ee||e[27]!==R||e[28]!==te?(M=l("button",{"aria-selected":ee,className:R,"data-testid":"sc-view-graph",onClick:j,role:"tab",type:"button",children:te}),e[25]=j,e[26]=ee,e[27]=R,e[28]=te,e[29]=M):M=e[29];const ye=I==="list",ce=I==="list";let fe;e[30]!==ce?(fe=Xe(ce),e[30]=ce,e[31]=fe):fe=e[31];let K;e[32]!==s?(K=s("Table list"),e[32]=s,e[33]=K):K=e[33];let X;e[34]!==_||e[35]!==ye||e[36]!==fe||e[37]!==K?(X=l("button",{"aria-selected":ye,className:fe,"data-testid":"sc-view-list",onClick:_,role:"tab",type:"button",children:K}),e[34]=_,e[35]=ye,e[36]=fe,e[37]=K,e[38]=X):X=e[38];let U;e[39]!==M||e[40]!==X||e[41]!==Z?(U=p("div",{"aria-label":Z,className:"flex items-center gap-1","data-testid":"sc-view-toggle",role:"tablist",children:[M,X]}),e[39]=M,e[40]=X,e[41]=Z,e[42]=U):U=e[42];let le;e[43]!==U||e[44]!==O?(le=p("div",{className:"flex flex-wrap items-center gap-3",children:[O,U]}),e[43]=U,e[44]=O,e[45]=le):le=e[45];let V;e[46]!==xe||e[47]!==t||e[48]!==ve?(V=t===!0&&l(Nt,{onApplied:xe,tableNames:ve}),e[46]=xe,e[47]=t,e[48]=ve,e[49]=V):V=e[49];let se;e[50]!==Q||e[51]!==s||e[52]!==A||e[53]!==I?(se=I==="list"&&l(ke,{"aria-label":s("Filter tables"),className:"h-8 max-w-xs","data-testid":"sc-filter",onChange:Q,placeholder:s("Filter tables"),value:A}),e[50]=Q,e[51]=s,e[52]=A,e[53]=I,e[54]=se):se=e[54];let $;e[55]!==r||e[56]!==b||e[57]!==h||e[58]!==S||e[59]!==C||e[60]!==I?($=I==="graph"&&p("div",{className:"flex flex-col gap-2","data-testid":"sc-graph-view",children:[b!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:b}),h!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:h}),l(st,{columnsError:S[C]===!0,tables:r,testIdPrefix:"sc-graph"})]}),e[55]=r,e[56]=b,e[57]=h,e[58]=S,e[59]=C,e[60]=I,e[61]=$):$=e[61];let ae;e[62]!==d||e[63]!==b||e[64]!==o||e[65]!==f||e[66]!==i||e[67]!==v||e[68]!==h||e[69]!==G||e[70]!==w||e[71]!==B||e[72]!==C||e[73]!==s||e[74]!==L||e[75]!==me||e[76]!==W||e[77]!==I?(ae=I==="list"&&p("div",{className:"flex flex-col gap-4",children:[p(je,{"data-testid":"sc-shard-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Re,{tier:"shard"}),l(ze,{children:s("Shard tables")}),L!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:i.length})]}),l(qe,{children:Pe.shard.hint})]}),p(De,{children:[b!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:b}),L!==null&&L.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-empty",children:s("No tables in this shard.")}),L!==null&&L.length>0&&i.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-no-match",children:s("No tables match your filter.")}),i.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-table-list",children:i.map(g=>{const oe=`${C}:${g.name}`,J=B[oe]??[];return p(Ye,{expanded:o===g.name,name:g.name,onToggle:()=>{be(me(g.name))},rowCount:g.rowCount,rowTestId:`sc-table-${g.name}`,toggleTestId:`sc-toggle-${g.name}`,children:[l(He,{columns:d[oe]??Ve,testId:`sc-columns-${g.name}`}),J.length>0&&l(Et,{heading:s("Indexes"),indexes:J,testId:`sc-indexes-${g.name}`})]},g.name)})})]})]}),p(je,{"data-testid":"sc-global-section",size:"sm",children:[p(Be,{children:[p("div",{className:"flex items-center gap-2",children:[l(Re,{tier:"global"}),l(ze,{children:s("Global tables (D1)")}),w!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:f.length})]}),l(qe,{children:Pe.global.hint})]}),p(De,{children:[h!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:h}),w!==null&&w.length===0&&l(Qe,{description:Pe.global.hint,testId:"sc-global-empty",title:s("No global tables.")}),w!==null&&w.length>0&&f.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-global-no-match",children:s("No tables match your filter.")}),f.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-global-table-list",children:f.map(g=>l(Ye,{expanded:G===g.name,name:g.name,onToggle:()=>{be(W(g.name))},rowCount:g.rowCount,rowTestId:`sc-global-table-${g.name}`,toggleTestId:`sc-global-toggle-${g.name}`,children:l(He,{columns:v[g.name]??Ve,testId:`sc-global-columns-${g.name}`})},g.name))})]})]})]}),e[62]=d,e[63]=b,e[64]=o,e[65]=f,e[66]=i,e[67]=v,e[68]=h,e[69]=G,e[70]=w,e[71]=B,e[72]=C,e[73]=s,e[74]=L,e[75]=me,e[76]=W,e[77]=I,e[78]=ae):ae=e[78];let ne;return e[79]!==le||e[80]!==V||e[81]!==se||e[82]!==$||e[83]!==ae?(ne=p("div",{className:"flex flex-col gap-4","data-testid":"lunora-schema",children:[le,V,se,$,ae]}),e[79]=le,e[80]=V,e[81]=se,e[82]=$,e[83]=ae,e[84]=ne):ne=e[84],ne};function It(n){return l("li",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:n},n)}function kt(n){return p("li",{className:"flex flex-wrap items-center gap-1.5 text-xs",children:[l("span",{className:"font-mono",children:n.name}),l(Fe,{variant:"outline",children:n.type}),n.unique===!0&&l(Fe,{variant:"secondary",children:"unique"}),l("span",{className:"text-muted-foreground",children:n.fields.join(", ")})]},`${n.type}:${n.name}`)}function At(n){return n.name}export{Wt as SchemaViewer};