@lunora/studio 1.0.0-alpha.340 → 1.0.0-alpha.342

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 (131) hide show
  1. package/dist/index.d.mts +5 -4
  2. package/dist/index.d.ts +5 -4
  3. package/dist/index.mjs +1 -1
  4. package/dist/mount.mjs +1 -1
  5. package/dist/packem_chunks/AdvisorHealthPanel.mjs +1 -1
  6. package/dist/packem_chunks/AuditPanel.mjs +1 -1
  7. package/dist/packem_chunks/ExportImportPanel.mjs +8 -6
  8. package/dist/packem_chunks/FunctionStatsPanel.mjs +1 -1
  9. package/dist/packem_chunks/HealthPanel.mjs +1 -1
  10. package/dist/packem_chunks/InsightsPanel.mjs +1 -1
  11. package/dist/packem_chunks/LogsPanel.mjs +1 -1
  12. package/dist/packem_chunks/MailPanel.mjs +1 -1
  13. package/dist/packem_chunks/MetricsPanel.mjs +1 -1
  14. package/dist/packem_chunks/NotificationsPanel.mjs +1 -1
  15. package/dist/packem_chunks/SecurityAdvisorPanel.mjs +1 -1
  16. package/dist/packem_chunks/SettingsPanel.mjs +1 -1
  17. package/dist/packem_chunks/SqlEditorPanel.mjs +1 -1
  18. package/dist/packem_chunks/TableEditor.mjs +1 -1
  19. package/dist/packem_chunks/agents-panel.mjs +1 -1
  20. package/dist/packem_chunks/ai-usage-panel.mjs +1 -1
  21. package/dist/packem_chunks/auth-audit-panel.mjs +1 -1
  22. package/dist/packem_chunks/auth-config-panel.mjs +1 -1
  23. package/dist/packem_chunks/auth-sessions-panel.mjs +1 -1
  24. package/dist/packem_chunks/containers-panel.mjs +1 -1
  25. package/dist/packem_chunks/dashboards-panel.mjs +1 -1
  26. package/dist/packem_chunks/evals-panel.mjs +1 -1
  27. package/dist/packem_chunks/fanout-panel.mjs +1 -1
  28. package/dist/packem_chunks/flags-panel.mjs +1 -1
  29. package/dist/packem_chunks/issues-panel.mjs +1 -1
  30. package/dist/packem_chunks/kv-browser.mjs +1 -1
  31. package/dist/packem_chunks/migrations-route.mjs +1 -1
  32. package/dist/packem_chunks/organizations-panel.mjs +1 -1
  33. package/dist/packem_chunks/payments-panel.mjs +1 -1
  34. package/dist/packem_chunks/permissions-panel.mjs +1 -1
  35. package/dist/packem_chunks/privacy-requests-panel.mjs +1 -1
  36. package/dist/packem_chunks/queues-panel.mjs +1 -1
  37. package/dist/packem_chunks/reactors-panel.mjs +1 -1
  38. package/dist/packem_chunks/rls-panel.mjs +1 -1
  39. package/dist/packem_chunks/schedule-panel.mjs +1 -1
  40. package/dist/packem_chunks/storage-rules-panel.mjs +1 -1
  41. package/dist/packem_chunks/subscriptions-panel.mjs +1 -1
  42. package/dist/packem_chunks/sync-client-panel.mjs +1 -1
  43. package/dist/packem_chunks/traces-panel.mjs +1 -1
  44. package/dist/packem_chunks/users-panel.mjs +1 -1
  45. package/dist/packem_chunks/workflows-panel.mjs +1 -1
  46. package/dist/packem_shared/{DataBrowser-DxlLv5x1.mjs → DataBrowser-BDsxK-Jk.mjs} +1 -1
  47. package/dist/packem_shared/{GlobalDataBrowser-TFTQpSVj.mjs → GlobalDataBrowser-CPfjubP_.mjs} +1 -1
  48. package/dist/packem_shared/{HomePanel-BVz2sDQ4.mjs → HomePanel-C8sb1fFJ.mjs} +1 -1
  49. package/dist/packem_shared/{MigrationsPanel-fUyhbt0w.mjs → MigrationsPanel-Dzjf42y8.mjs} +1 -1
  50. package/dist/packem_shared/{ScheduledJobs-zSeU_6cN.mjs → ScheduledJobs-BJ1uZW1U.mjs} +1 -1
  51. package/dist/packem_shared/{Studio-CNqMkRmB.mjs → Studio-CL3-IiIi.mjs} +1 -1
  52. package/dist/packem_shared/{StudioApp-CUxEVr__.mjs → StudioApp-ClaUkjR_.mjs} +1 -1
  53. package/dist/packem_shared/{advisor-view-CXiPdw4B.mjs → advisor-view-B8oIluyS.mjs} +1 -1
  54. package/dist/packem_shared/{error-alert-D-ftqyo-.mjs → error-alert-CNQjdAhi.mjs} +1 -1
  55. package/dist/packem_shared/{home-panel-CF-MfsnH.mjs → home-panel-BJXZsAaD.mjs} +1 -1
  56. package/dist/packem_shared/{recording-client-CFBkH4uZ.mjs → recording-client-neIRrUNz.mjs} +1 -1
  57. package/dist/packem_shared/{studio-BcHsk7mT.mjs → studio-BSiyNdXi.mjs} +1 -1
  58. package/dist/packem_shared/{table-list-sidebar-DwqtHSHU.mjs → table-list-sidebar-B7IOSxLN.mjs} +1 -1
  59. package/dist/packem_shared/{use-admin-query-I1uILsUP.mjs → use-admin-query-CLStXJ7v.mjs} +1 -1
  60. package/dist/packem_shared/{use-auth-config-DQ8tNyBh.mjs → use-auth-config-DtZeS_qf.mjs} +1 -1
  61. package/dist/packem_shared/{use-sql-assistant-DetnUyFf.mjs → use-sql-assistant-DxNeNdCs.mjs} +1 -1
  62. package/dist/standalone/{chunk-M3QKMHAP.js → chunk-35Q6XYRL.js} +1 -1
  63. package/dist/standalone/{chunk-OLIKYC3C.js → chunk-3BCMZMOX.js} +1 -1
  64. package/dist/standalone/{chunk-VJ7RCBJ7.js → chunk-3BF2QRJM.js} +1 -1
  65. package/dist/standalone/{chunk-VNMKNORK.js → chunk-3F3742NV.js} +1 -1
  66. package/dist/standalone/{chunk-ENIA26XP.js → chunk-4RLRI34N.js} +1 -1
  67. package/dist/standalone/{chunk-7GVT36VI.js → chunk-5CW7W7LQ.js} +1 -1
  68. package/dist/standalone/{chunk-43GV7LQK.js → chunk-5DKOUMFY.js} +1 -1
  69. package/dist/standalone/{chunk-O2FW4VRL.js → chunk-5QTTNVDW.js} +1 -1
  70. package/dist/standalone/{chunk-K3UAOIR7.js → chunk-5X7LJ6UT.js} +1 -1
  71. package/dist/standalone/{chunk-VENSZ6LF.js → chunk-66MXYZBW.js} +1 -1
  72. package/dist/standalone/{chunk-R3ADWOYR.js → chunk-6ZRYMZEX.js} +1 -1
  73. package/dist/standalone/{chunk-UVL7N5IL.js → chunk-A4WUN5R3.js} +1 -1
  74. package/dist/standalone/{chunk-KF7Y5S5O.js → chunk-ATVJ7XYZ.js} +1 -1
  75. package/dist/standalone/{chunk-HPYJUVCC.js → chunk-BEODZ54J.js} +1 -1
  76. package/dist/standalone/{chunk-GWVYDOBH.js → chunk-CT7KV34V.js} +1 -1
  77. package/dist/standalone/{chunk-HCFJBY65.js → chunk-CUIPEXIW.js} +1 -1
  78. package/dist/standalone/{chunk-VVCXVAA7.js → chunk-D6CNULEI.js} +1 -1
  79. package/dist/standalone/{chunk-UIIKW4II.js → chunk-DD7J6RMR.js} +1 -1
  80. package/dist/standalone/{chunk-DHGPCQ2F.js → chunk-DFVQBXUZ.js} +1 -1
  81. package/dist/standalone/{chunk-4NOMAGEO.js → chunk-DNIDQC3K.js} +1 -1
  82. package/dist/standalone/{chunk-LHG2JVIM.js → chunk-DQAXICZV.js} +1 -1
  83. package/dist/standalone/{chunk-BFQMOALO.js → chunk-E57JT34T.js} +1 -1
  84. package/dist/standalone/{chunk-SU6QNITV.js → chunk-EJSTZM7A.js} +1 -1
  85. package/dist/standalone/{chunk-BTG6YDYM.js → chunk-EUTV2OGD.js} +1 -1
  86. package/dist/standalone/{chunk-5SLTDY4C.js → chunk-EYTZURBK.js} +1 -1
  87. package/dist/standalone/{chunk-DBZ4TBP5.js → chunk-FMSWGAHK.js} +1 -1
  88. package/dist/standalone/{chunk-ICRKYAYO.js → chunk-FR2MJIZG.js} +1 -1
  89. package/dist/standalone/{chunk-3FYMEXVB.js → chunk-G5P5DUVD.js} +1 -1
  90. package/dist/standalone/{chunk-GC4XRCRZ.js → chunk-GTEER76O.js} +1 -1
  91. package/dist/standalone/{chunk-NCBLHBRW.js → chunk-GWCMBJ2U.js} +1 -1
  92. package/dist/standalone/{chunk-GYBCO7NN.js → chunk-GXRBCKNP.js} +1 -1
  93. package/dist/standalone/{chunk-G2F22AMT.js → chunk-HXC2I6YI.js} +1 -1
  94. package/dist/standalone/{chunk-RB3WPSY5.js → chunk-IC2NNXPZ.js} +1 -1
  95. package/dist/standalone/{chunk-YZ72ZAGX.js → chunk-IDX6KQRG.js} +1 -1
  96. package/dist/standalone/chunk-ITFHDBLD.js +8 -0
  97. package/dist/standalone/{chunk-HH52IEFY.js → chunk-J5CU2YKR.js} +1 -1
  98. package/dist/standalone/{chunk-XBQ66PGW.js → chunk-JAPCIIQC.js} +1 -1
  99. package/dist/standalone/{chunk-SC6P4M3S.js → chunk-KLQVRXER.js} +1 -1
  100. package/dist/standalone/{chunk-ZKV2XC5B.js → chunk-L7OWZOME.js} +1 -1
  101. package/dist/standalone/{chunk-BTQ72TPT.js → chunk-N36IWCKG.js} +1 -1
  102. package/dist/standalone/{chunk-VXJJSPX3.js → chunk-N66HNAEX.js} +1 -1
  103. package/dist/standalone/{chunk-UJQNKTYE.js → chunk-NJ3YQOVN.js} +1 -1
  104. package/dist/standalone/{chunk-FUL4ROKH.js → chunk-NQZMPZNU.js} +1 -1
  105. package/dist/standalone/{chunk-HGHIVU76.js → chunk-OIG3OORA.js} +1 -1
  106. package/dist/standalone/{chunk-DEFCA7GG.js → chunk-PMNMWB3N.js} +1 -1
  107. package/dist/standalone/{chunk-IRSSZXC3.js → chunk-QMJTL4SW.js} +1 -1
  108. package/dist/standalone/{chunk-E5DXYVPB.js → chunk-QNAKWBFW.js} +1 -1
  109. package/dist/standalone/{chunk-T6IV7OKH.js → chunk-RGCYH5VO.js} +1 -1
  110. package/dist/standalone/{chunk-NCCORPSU.js → chunk-RGDSRUIX.js} +1 -1
  111. package/dist/standalone/{chunk-KCFO2BVI.js → chunk-S3KIA2QB.js} +1 -1
  112. package/dist/standalone/{chunk-6XKL22OG.js → chunk-S7XJPD6Z.js} +2 -2
  113. package/dist/standalone/chunk-SFMWHWJG.js +1 -0
  114. package/dist/standalone/{chunk-ZJQIGWLG.js → chunk-SMZHXNCR.js} +1 -1
  115. package/dist/standalone/{chunk-JR4ROUBB.js → chunk-SPLVBIFP.js} +1 -1
  116. package/dist/standalone/{chunk-5Y5UTG4N.js → chunk-SQ4ZU5YB.js} +1 -1
  117. package/dist/standalone/{chunk-DBHZXRL6.js → chunk-SRNH27XV.js} +1 -1
  118. package/dist/standalone/{chunk-WVYIBXUH.js → chunk-TFLKMZK5.js} +1 -1
  119. package/dist/standalone/{chunk-ZPNTFCVI.js → chunk-UMPQDFU6.js} +1 -1
  120. package/dist/standalone/{chunk-GOFZ4Y74.js → chunk-VVHORMP3.js} +1 -1
  121. package/dist/standalone/{chunk-OI5HX3ZO.js → chunk-WXMYNIXK.js} +1 -1
  122. package/dist/standalone/{chunk-2SNK7KHX.js → chunk-WZ2CXW4B.js} +1 -1
  123. package/dist/standalone/{chunk-WUI2PUY6.js → chunk-XUS6E3C7.js} +1 -1
  124. package/dist/standalone/{chunk-EE227HDE.js → chunk-YNJEO3WB.js} +1 -1
  125. package/dist/standalone/{chunk-APEQELK3.js → chunk-YR5YXUZT.js} +1 -1
  126. package/dist/standalone/{chunk-FCXFQF2W.js → chunk-YYEQLN53.js} +1 -1
  127. package/dist/standalone/{chunk-ITT6MM23.js → chunk-ZUB5DMJT.js} +1 -1
  128. package/dist/standalone/studio.js +1 -1
  129. package/package.json +5 -5
  130. package/dist/standalone/chunk-3N5PRV3V.js +0 -1
  131. package/dist/standalone/chunk-6ZSIPBTC.js +0 -6
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{StudioApp as r}from"./packem_shared/StudioApp-CUxEVr__.mjs";import{CommandPalette as a,openCommandPalette as f}from"./packem_shared/CommandPalette-CM1hqAOD.mjs";import{S as m}from"./packem_shared/studio-BcHsk7mT.mjs";import{ConfirmButton as l}from"./packem_shared/ConfirmButton-DU4p72Er.mjs";import{default as s}from"./packem_shared/ConnectionBadge-B8Hj5DaE.mjs";import{ErrorBoundary as d}from"./packem_shared/ErrorBoundary-BWNF98VF.mjs";import{ShardInput as P}from"./packem_shared/ShardInput-C6mjgAh4.mjs";import{default as A}from"./packem_chunks/AdvisorHealthPanel.mjs";import{DEFAULT_INSIGHT_THRESHOLDS as I,deriveInsights as T}from"./packem_shared/DEFAULT_INSIGHT_THRESHOLDS-D5YMT0gM.mjs";import{InsightsPanel as g}from"./packem_chunks/InsightsPanel.mjs";import{default as F}from"./packem_chunks/SecurityAdvisorPanel.mjs";import{default as h}from"./packem_shared/ApiDocsPanel-Py7C4ibM.mjs";import{default as C}from"./packem_shared/ApiReferencePanel-DlYVADAy.mjs";import{default as O}from"./packem_chunks/ApiTab.mjs";import{default as N}from"./packem_shared/OpenRpcReferencePanel-nYyfjjse.mjs";import{DataBrowser as U}from"./packem_shared/DataBrowser-DxlLv5x1.mjs";import{DataFilters as b,toFilterClauses as v}from"./packem_shared/DataFilters-CYZFt2EK.mjs";import{GlobalDataBrowser as y}from"./packem_shared/GlobalDataBrowser-TFTQpSVj.mjs";import{TableEditor as q}from"./packem_chunks/TableEditor.mjs";import{ExportImportPanel as V}from"./packem_chunks/ExportImportPanel.mjs";import{MigrationsPanel as j}from"./packem_shared/MigrationsPanel-fUyhbt0w.mjs";import{PitrPanel as z}from"./packem_chunks/PitrPanel.mjs";import{FunctionRunner as Q}from"./packem_chunks/FunctionRunner.mjs";import{FunctionStatsPanel as Y}from"./packem_chunks/FunctionStatsPanel.mjs";import{DeploymentHealthPanel as $}from"./packem_chunks/DeploymentHealthPanel.mjs";import{H as oe}from"./packem_shared/home-panel-CF-MfsnH.mjs";import{AuditPanel as te}from"./packem_chunks/AuditPanel.mjs";import{LogsPanel as fe}from"./packem_chunks/LogsPanel.mjs";import{MailPanel as me}from"./packem_chunks/MailPanel.mjs";import{ScheduledJobs as le}from"./packem_shared/ScheduledJobs-zSeU_6cN.mjs";import{default as se}from"./packem_chunks/NotificationsPanel.mjs";import{HealthPanel as de}from"./packem_chunks/HealthPanel.mjs";import{aggregateMetrics as Pe,shardsToAggregate as Se}from"./packem_shared/aggregateMetrics-DKFJc-o5.mjs";import{MetricsPanel as ce}from"./packem_chunks/MetricsPanel.mjs";import{SchemaViewer as Te}from"./packem_chunks/SchemaViewer.mjs";import{SettingsPanel as ge}from"./packem_chunks/SettingsPanel.mjs";import{SqlEditorPanel as Fe}from"./packem_chunks/SqlEditorPanel.mjs";import{FileBrowser as he}from"./packem_chunks/FileBrowser.mjs";import{DEFAULT_AUTO_REFRESH_MS as Ce,useAutoRefresh as He}from"./packem_shared/DEFAULT_AUTO_REFRESH_MS-DvhNw0BI.mjs";import{default as Le}from"./packem_shared/useDebounced-DVeQ5-oW.mjs";import{DEFAULT_LOCALE as Me,createStudioI18n as Ue,studioI18n as Be,useT as be}from"./packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{StudioI18nProvider as we}from"./packem_shared/StudioI18nProvider-fVsCSs5L.mjs";import{ADMIN_FUNCTIONS as Ge,ADMIN_FUNCTION_PREFIX as qe}from"./packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{default as Ve}from"./packem_shared/STUDIO_ROOT_CLASS-C6MccdVk.mjs";export{Ge as ADMIN_FUNCTIONS,qe as ADMIN_FUNCTION_PREFIX,A as AdvisorHealthPanel,h as ApiDocsPanel,C as ApiReferencePanel,O as ApiTab,te as AuditPanel,a as CommandPalette,l as ConfirmButton,s as ConnectionBadge,Ce as DEFAULT_AUTO_REFRESH_MS,I as DEFAULT_INSIGHT_THRESHOLDS,Me as DEFAULT_LOCALE,U as DataBrowser,b as DataFilters,$ as DeploymentHealthPanel,d as ErrorBoundary,V as ExportImportPanel,he as FileBrowser,Q as FunctionRunner,Y as FunctionStatsPanel,y as GlobalDataBrowser,de as HealthPanel,oe as HomePanel,g as InsightsPanel,fe as LogsPanel,me as MailPanel,ce as MetricsPanel,j as MigrationsPanel,se as NotificationsPanel,N as OpenRpcReferencePanel,z as PitrPanel,Ve as STUDIO_ROOT_CLASS,le as ScheduledJobs,Te as SchemaViewer,F as SecurityAdvisorPanel,ge as SettingsPanel,P as ShardInput,Fe as SqlEditorPanel,m as Studio,r as StudioApp,we as StudioI18nProvider,q as TableEditor,Pe as aggregateMetrics,Ue as createStudioI18n,T as deriveInsights,f as openCommandPalette,Se as shardsToAggregate,Be as studioI18n,v as toFilterClauses,He as useAutoRefresh,Le as useDebounced,be as useT};
1
+ import{StudioApp as r}from"./packem_shared/StudioApp-ClaUkjR_.mjs";import{CommandPalette as a,openCommandPalette as f}from"./packem_shared/CommandPalette-CM1hqAOD.mjs";import{S as m}from"./packem_shared/studio-BSiyNdXi.mjs";import{ConfirmButton as l}from"./packem_shared/ConfirmButton-DU4p72Er.mjs";import{default as s}from"./packem_shared/ConnectionBadge-B8Hj5DaE.mjs";import{ErrorBoundary as d}from"./packem_shared/ErrorBoundary-BWNF98VF.mjs";import{ShardInput as P}from"./packem_shared/ShardInput-C6mjgAh4.mjs";import{default as A}from"./packem_chunks/AdvisorHealthPanel.mjs";import{DEFAULT_INSIGHT_THRESHOLDS as I,deriveInsights as T}from"./packem_shared/DEFAULT_INSIGHT_THRESHOLDS-D5YMT0gM.mjs";import{InsightsPanel as g}from"./packem_chunks/InsightsPanel.mjs";import{default as F}from"./packem_chunks/SecurityAdvisorPanel.mjs";import{default as h}from"./packem_shared/ApiDocsPanel-Py7C4ibM.mjs";import{default as C}from"./packem_shared/ApiReferencePanel-DlYVADAy.mjs";import{default as O}from"./packem_chunks/ApiTab.mjs";import{default as N}from"./packem_shared/OpenRpcReferencePanel-nYyfjjse.mjs";import{DataBrowser as U}from"./packem_shared/DataBrowser-BDsxK-Jk.mjs";import{DataFilters as b,toFilterClauses as v}from"./packem_shared/DataFilters-CYZFt2EK.mjs";import{GlobalDataBrowser as y}from"./packem_shared/GlobalDataBrowser-CPfjubP_.mjs";import{TableEditor as q}from"./packem_chunks/TableEditor.mjs";import{ExportImportPanel as V}from"./packem_chunks/ExportImportPanel.mjs";import{MigrationsPanel as j}from"./packem_shared/MigrationsPanel-Dzjf42y8.mjs";import{PitrPanel as z}from"./packem_chunks/PitrPanel.mjs";import{FunctionRunner as Q}from"./packem_chunks/FunctionRunner.mjs";import{FunctionStatsPanel as Y}from"./packem_chunks/FunctionStatsPanel.mjs";import{DeploymentHealthPanel as $}from"./packem_chunks/DeploymentHealthPanel.mjs";import{H as oe}from"./packem_shared/home-panel-BJXZsAaD.mjs";import{AuditPanel as te}from"./packem_chunks/AuditPanel.mjs";import{LogsPanel as fe}from"./packem_chunks/LogsPanel.mjs";import{MailPanel as me}from"./packem_chunks/MailPanel.mjs";import{ScheduledJobs as le}from"./packem_shared/ScheduledJobs-BJ1uZW1U.mjs";import{default as se}from"./packem_chunks/NotificationsPanel.mjs";import{HealthPanel as de}from"./packem_chunks/HealthPanel.mjs";import{aggregateMetrics as Pe,shardsToAggregate as Se}from"./packem_shared/aggregateMetrics-DKFJc-o5.mjs";import{MetricsPanel as ce}from"./packem_chunks/MetricsPanel.mjs";import{SchemaViewer as Te}from"./packem_chunks/SchemaViewer.mjs";import{SettingsPanel as ge}from"./packem_chunks/SettingsPanel.mjs";import{SqlEditorPanel as Fe}from"./packem_chunks/SqlEditorPanel.mjs";import{FileBrowser as he}from"./packem_chunks/FileBrowser.mjs";import{DEFAULT_AUTO_REFRESH_MS as Ce,useAutoRefresh as He}from"./packem_shared/DEFAULT_AUTO_REFRESH_MS-DvhNw0BI.mjs";import{default as Le}from"./packem_shared/useDebounced-DVeQ5-oW.mjs";import{DEFAULT_LOCALE as Me,createStudioI18n as Ue,studioI18n as Be,useT as be}from"./packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{StudioI18nProvider as we}from"./packem_shared/StudioI18nProvider-fVsCSs5L.mjs";import{ADMIN_FUNCTIONS as Ge,ADMIN_FUNCTION_PREFIX as qe}from"./packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{default as Ve}from"./packem_shared/STUDIO_ROOT_CLASS-C6MccdVk.mjs";export{Ge as ADMIN_FUNCTIONS,qe as ADMIN_FUNCTION_PREFIX,A as AdvisorHealthPanel,h as ApiDocsPanel,C as ApiReferencePanel,O as ApiTab,te as AuditPanel,a as CommandPalette,l as ConfirmButton,s as ConnectionBadge,Ce as DEFAULT_AUTO_REFRESH_MS,I as DEFAULT_INSIGHT_THRESHOLDS,Me as DEFAULT_LOCALE,U as DataBrowser,b as DataFilters,$ as DeploymentHealthPanel,d as ErrorBoundary,V as ExportImportPanel,he as FileBrowser,Q as FunctionRunner,Y as FunctionStatsPanel,y as GlobalDataBrowser,de as HealthPanel,oe as HomePanel,g as InsightsPanel,fe as LogsPanel,me as MailPanel,ce as MetricsPanel,j as MigrationsPanel,se as NotificationsPanel,N as OpenRpcReferencePanel,z as PitrPanel,Ve as STUDIO_ROOT_CLASS,le as ScheduledJobs,Te as SchemaViewer,F as SecurityAdvisorPanel,ge as SettingsPanel,P as ShardInput,Fe as SqlEditorPanel,m as Studio,r as StudioApp,we as StudioI18nProvider,q as TableEditor,Pe as aggregateMetrics,Ue as createStudioI18n,T as deriveInsights,f as openCommandPalette,Se as shardsToAggregate,Be as studioI18n,v as toFilterClauses,He as useAutoRefresh,Le as useDebounced,be as useT};
package/dist/mount.mjs CHANGED
@@ -1 +1 @@
1
- import{LunoraError as m}from"@lunora/errors";import{createRoot as i}from"react-dom/client";import{StudioApp as p}from"./packem_shared/StudioApp-CUxEVr__.mjs";import{jsx as u}from"react/jsx-runtime";const a=(n={})=>{const{container:o="#root",...e}=n,t=typeof o=="string"?document.querySelector(o):o;if(t===null)throw new m("INTERNAL",`mountStudio: container ${typeof o=="string"?o:"element"} not found`);const r=i(t);return r.render(u(p,{...e})),r};export{a as mountStudio};
1
+ import{LunoraError as m}from"@lunora/errors";import{createRoot as i}from"react-dom/client";import{StudioApp as p}from"./packem_shared/StudioApp-ClaUkjR_.mjs";import{jsx as u}from"react/jsx-runtime";const a=(n={})=>{const{container:o="#root",...e}=n,t=typeof o=="string"?document.querySelector(o):o;if(t===null)throw new m("INTERNAL",`mountStudio: container ${typeof o=="string"?o:"element"} not found`);const r=i(t);return r.render(u(p,{...e})),r};export{a as mountStudio};
@@ -1 +1 @@
1
- import{scoreAdvisor as T}from"@lunora/advisor";import{E as A}from"../packem_shared/error-alert-D-ftqyo-.mjs";import{C as c,a as o}from"../packem_shared/card-By2O8ULa.mjs";import{T as j,a as R,b as f,c as i,d as $,e as m}from"../packem_shared/table-D0SBiDu-.mjs";import{u as v}from"../packem_shared/use-admin-query-I1uILsUP.mjs";import{useT as C}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{c as u}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as e,jsxs as r}from"react/jsx-runtime";const n={clean:"text-emerald-600 dark:text-emerald-400",exempt:"text-muted-foreground",failing:"text-red-600 dark:text-red-400",warned:"text-amber-600 dark:text-amber-400"},b={"at-risk":"text-red-600 dark:text-red-400",excellent:"text-emerald-600 dark:text-emerald-400",good:"text-emerald-600 dark:text-emerald-400","needs-work":"text-amber-600 dark:text-amber-400"},E=(s,a)=>`exempt: ${s.exemptReason===void 0||s.exemptReason===""?a:s.exemptReason}`,S=s=>s.toSorted((a,l)=>a.coverage==="clean"&&l.coverage!=="clean"?1:l.coverage==="clean"&&a.coverage!=="clean"?-1:a.score-l.score),Y=({testId:s="advisor-health"})=>{const a=C(),l=v(N.getAdvisories,{},{live:!0}),x=v(N.getAdvisorProcedures,{},{live:!0}),p=l.data?.advisories??null,h=x.data?.procedures??null,t=p===null||h===null?null:T(h,p),g=x.error??l.error;if(g!==null)return e(A,{error:g,testId:`${s}-error`});if(t===null)return e(c,{children:e(o,{className:"py-8 text-center text-muted-foreground","data-testid":`${s}-loading`,children:a("Loading…")})});const k=S(t.procedures);return r("div",{className:"space-y-4","data-testid":s,children:[e(c,{children:r(o,{className:"flex flex-wrap items-baseline gap-x-6 gap-y-2 py-6",children:[r("div",{children:[e("span",{className:u("text-4xl font-semibold tabular-nums",b[t.grade]),"data-testid":`${s}-score`,children:t.score}),e("span",{className:"text-muted-foreground text-lg",children:"/100"})]}),e("span",{className:u("text-sm font-medium uppercase tracking-wide",b[t.grade]),"data-testid":`${s}-grade`,children:t.grade}),r("div",{className:"text-muted-foreground flex gap-4 text-sm tabular-nums","data-testid":`${s}-summary`,children:[r("span",{className:n.clean,children:[t.summary.clean," ",a("clean")]}),r("span",{className:n.warned,children:[t.summary.warned," ",a("warned")]}),r("span",{className:n.failing,children:[t.summary.failing," ",a("failing")]}),r("span",{className:n.exempt,children:[t.summary.exempt," ",a("exempt")]})]})]})}),t.project.checks.length>0&&e(c,{children:r(o,{className:"py-4 text-sm","data-testid":`${s}-project`,children:[r("span",{className:"font-medium",children:[a("Schema & config")," ",t.project.score,"/100"]}),r("span",{className:"text-muted-foreground",children:[" — ",t.project.checks.map(d=>d.name).join(", ")]})]})}),e(c,{children:e(o,{className:"p-0",children:r(j,{children:[e(R,{children:r(f,{children:[e(i,{className:"w-20",children:a("Score")}),e(i,{children:a("Procedure")}),e(i,{className:"w-32",children:a("Kind")}),e(i,{children:a("Rules fired")})]})}),e($,{children:k.map(d=>r(f,{"data-testid":`${s}-row`,children:[e(m,{className:u("tabular-nums font-medium",n[d.coverage]),children:d.coverage==="exempt"?"—":d.score}),e(m,{className:"font-mono text-xs",children:d.id}),r(m,{className:"text-muted-foreground text-xs",children:[d.visibility," ",d.kind,d.sensitivity.level==="high"&&e("span",{className:"ml-1 text-amber-600 dark:text-amber-400",children:a("sensitive")})]}),e(m,{className:"text-muted-foreground text-xs",children:d.coverage==="exempt"?E(d,a("no reason given")):d.checks.map(w=>w.name).join(", ")})]},d.id))})]})})})]})};export{Y as default};
1
+ import{scoreAdvisor as T}from"@lunora/advisor";import{E as A}from"../packem_shared/error-alert-CNQjdAhi.mjs";import{C as c,a as o}from"../packem_shared/card-By2O8ULa.mjs";import{T as j,a as R,b as f,c as i,d as $,e as m}from"../packem_shared/table-D0SBiDu-.mjs";import{u as v}from"../packem_shared/use-admin-query-CLStXJ7v.mjs";import{useT as C}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{c as u}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as e,jsxs as r}from"react/jsx-runtime";const n={clean:"text-emerald-600 dark:text-emerald-400",exempt:"text-muted-foreground",failing:"text-red-600 dark:text-red-400",warned:"text-amber-600 dark:text-amber-400"},b={"at-risk":"text-red-600 dark:text-red-400",excellent:"text-emerald-600 dark:text-emerald-400",good:"text-emerald-600 dark:text-emerald-400","needs-work":"text-amber-600 dark:text-amber-400"},E=(s,a)=>`exempt: ${s.exemptReason===void 0||s.exemptReason===""?a:s.exemptReason}`,S=s=>s.toSorted((a,l)=>a.coverage==="clean"&&l.coverage!=="clean"?1:l.coverage==="clean"&&a.coverage!=="clean"?-1:a.score-l.score),Y=({testId:s="advisor-health"})=>{const a=C(),l=v(N.getAdvisories,{},{live:!0}),x=v(N.getAdvisorProcedures,{},{live:!0}),p=l.data?.advisories??null,h=x.data?.procedures??null,t=p===null||h===null?null:T(h,p),g=x.error??l.error;if(g!==null)return e(A,{error:g,testId:`${s}-error`});if(t===null)return e(c,{children:e(o,{className:"py-8 text-center text-muted-foreground","data-testid":`${s}-loading`,children:a("Loading…")})});const k=S(t.procedures);return r("div",{className:"space-y-4","data-testid":s,children:[e(c,{children:r(o,{className:"flex flex-wrap items-baseline gap-x-6 gap-y-2 py-6",children:[r("div",{children:[e("span",{className:u("text-4xl font-semibold tabular-nums",b[t.grade]),"data-testid":`${s}-score`,children:t.score}),e("span",{className:"text-muted-foreground text-lg",children:"/100"})]}),e("span",{className:u("text-sm font-medium uppercase tracking-wide",b[t.grade]),"data-testid":`${s}-grade`,children:t.grade}),r("div",{className:"text-muted-foreground flex gap-4 text-sm tabular-nums","data-testid":`${s}-summary`,children:[r("span",{className:n.clean,children:[t.summary.clean," ",a("clean")]}),r("span",{className:n.warned,children:[t.summary.warned," ",a("warned")]}),r("span",{className:n.failing,children:[t.summary.failing," ",a("failing")]}),r("span",{className:n.exempt,children:[t.summary.exempt," ",a("exempt")]})]})]})}),t.project.checks.length>0&&e(c,{children:r(o,{className:"py-4 text-sm","data-testid":`${s}-project`,children:[r("span",{className:"font-medium",children:[a("Schema & config")," ",t.project.score,"/100"]}),r("span",{className:"text-muted-foreground",children:[" — ",t.project.checks.map(d=>d.name).join(", ")]})]})}),e(c,{children:e(o,{className:"p-0",children:r(j,{children:[e(R,{children:r(f,{children:[e(i,{className:"w-20",children:a("Score")}),e(i,{children:a("Procedure")}),e(i,{className:"w-32",children:a("Kind")}),e(i,{children:a("Rules fired")})]})}),e($,{children:k.map(d=>r(f,{"data-testid":`${s}-row`,children:[e(m,{className:u("tabular-nums font-medium",n[d.coverage]),children:d.coverage==="exempt"?"—":d.score}),e(m,{className:"font-mono text-xs",children:d.id}),r(m,{className:"text-muted-foreground text-xs",children:[d.visibility," ",d.kind,d.sensitivity.level==="high"&&e("span",{className:"ml-1 text-amber-600 dark:text-amber-400",children:a("sensitive")})]}),e(m,{className:"text-muted-foreground text-xs",children:d.coverage==="exempt"?E(d,a("no reason given")):d.checks.map(w=>w.name).join(", ")})]},d.id))})]})})})]})};export{Y as default};
@@ -1 +1 @@
1
- import{useVirtualizer as A,observeElementRect as B}from"@tanstack/react-virtual";import{useState as K,useMemo as w,useRef as M}from"react";import{E as V}from"../packem_shared/error-alert-D-ftqyo-.mjs";import{L as _}from"../packem_shared/live-status-BuJdUZFU.mjs";import{ShardInput as j}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{B as U}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as q,a as D}from"../packem_shared/card-By2O8ULa.mjs";import{E as F}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as G}from"../packem_shared/input-CXhxesPC.mjs";import{T as W,a as J,b as N,c as s,d as P,e as l}from"../packem_shared/table-D0SBiDu-.mjs";import{u as Q}from"../packem_shared/use-admin-query-I1uILsUP.mjs";import{u as Z}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as X}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as Y}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as $,k as ee}from"../packem_shared/internal-BXEjuLPN.mjs";import{jsxs as i,jsx as e}from"react/jsx-runtime";const te=o=>o===void 0?"":JSON.stringify(o,ee),re=41,C=480,b=5,ae=(o,t)=>B(o,n=>{t(n.height>0?n:{height:C,width:n.width})}),we=({initialShardKey:o})=>{const t=X(),{queryShardKey:n,setShardKey:y,shardKey:T}=Z(o),[c,L]=K(""),{data:u,error:p,errorSource:R,isLoading:E,liveError:I}=Q(Y.getAuditLog,{},{live:!0,shardKey:n}),m=w(()=>u?.entries??[],[u]),d=w(()=>{const a=c.trim().toLowerCase();return a===""?m:m.filter(r=>r.op.toLowerCase().includes(a)||(r.table??"").toLowerCase().includes(a)||(r.id??"").toLowerCase().includes(a))},[m,c]),f=M(null),g=A({count:d.length,estimateSize:()=>re,getScrollElement:()=>f.current,initialRect:{height:C,width:800},observeElementRect:ae,overscan:8}),h=g.getVirtualItems(),H=g.getTotalSize(),v=h[0]?.start??0,x=H-(h.at(-1)?.end??0),O={height:v},k={height:x},z=a=>{L(a.target.value)};return i("div",{className:"flex flex-col gap-4","data-testid":"lunora-audit",children:[i("div",{className:"flex flex-wrap items-center gap-2",children:[e(j,{onChange:y,testId:"au-shard-input",value:T}),e(_,{message:I,prefix:"au"}),e(G,{"aria-label":t("Filter audit log"),className:"h-8 w-48","data-testid":"au-search",onChange:z,placeholder:t("filter op, table, id"),value:c})]}),p!==null&&e(V,{error:R,testId:"au-error"}),p===null&&!E&&d.length===0&&e(F,{description:t("State-changing admin operations are recorded here."),icon:e("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:e("path",{d:"M8 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2h-2M9 3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1V3Zm-1 9h8m-8 4h5"})}),testId:"au-empty",title:t("No audit entries.")}),d.length>0&&e(q,{className:"overflow-hidden py-0",children:e(D,{className:"max-h-[30rem] overflow-auto px-0",ref:f,children:i(W,{"data-testid":"au-table",children:[e(J,{children:i(N,{children:[e(s,{children:t("time")}),e(s,{children:t("op")}),e(s,{children:t("table")}),e(s,{children:t("id")}),e(s,{children:t("detail")})]})}),i(P,{children:[v>0&&e("tr",{"aria-hidden":"true",children:e("td",{colSpan:b,style:O})}),h.map(a=>{const r=d[a.index],S=te(r.detail);return i(N,{"data-testid":"au-row",children:[e(l,{className:"text-muted-foreground tabular-nums",children:$(r.ts,"—")}),e(l,{children:e(U,{variant:"secondary",children:r.op})}),e(l,{className:"font-medium",children:r.table??e("span",{className:"text-muted-foreground",children:"—"})}),e(l,{className:"max-w-[20ch] truncate font-mono text-xs",children:r.id??e("span",{className:"text-muted-foreground",children:"—"})}),e(l,{className:"max-w-[32ch] truncate font-mono text-xs text-muted-foreground",title:S||void 0,children:S||e("span",{className:"text-muted-foreground",children:"—"})})]},r.seq)}),x>0&&e("tr",{"aria-hidden":"true",children:e("td",{colSpan:b,style:k})})]})]})})})]})};export{we as AuditPanel};
1
+ import{useVirtualizer as A,observeElementRect as B}from"@tanstack/react-virtual";import{useState as K,useMemo as w,useRef as M}from"react";import{E as V}from"../packem_shared/error-alert-CNQjdAhi.mjs";import{L as _}from"../packem_shared/live-status-BuJdUZFU.mjs";import{ShardInput as j}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{B as U}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as q,a as D}from"../packem_shared/card-By2O8ULa.mjs";import{E as F}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as G}from"../packem_shared/input-CXhxesPC.mjs";import{T as W,a as J,b as N,c as s,d as P,e as l}from"../packem_shared/table-D0SBiDu-.mjs";import{u as Q}from"../packem_shared/use-admin-query-CLStXJ7v.mjs";import{u as Z}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as X}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as Y}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as $,k as ee}from"../packem_shared/internal-BXEjuLPN.mjs";import{jsxs as i,jsx as e}from"react/jsx-runtime";const te=o=>o===void 0?"":JSON.stringify(o,ee),re=41,C=480,b=5,ae=(o,t)=>B(o,n=>{t(n.height>0?n:{height:C,width:n.width})}),we=({initialShardKey:o})=>{const t=X(),{queryShardKey:n,setShardKey:y,shardKey:T}=Z(o),[c,L]=K(""),{data:u,error:p,errorSource:R,isLoading:E,liveError:I}=Q(Y.getAuditLog,{},{live:!0,shardKey:n}),m=w(()=>u?.entries??[],[u]),d=w(()=>{const a=c.trim().toLowerCase();return a===""?m:m.filter(r=>r.op.toLowerCase().includes(a)||(r.table??"").toLowerCase().includes(a)||(r.id??"").toLowerCase().includes(a))},[m,c]),f=M(null),g=A({count:d.length,estimateSize:()=>re,getScrollElement:()=>f.current,initialRect:{height:C,width:800},observeElementRect:ae,overscan:8}),h=g.getVirtualItems(),H=g.getTotalSize(),v=h[0]?.start??0,x=H-(h.at(-1)?.end??0),O={height:v},k={height:x},z=a=>{L(a.target.value)};return i("div",{className:"flex flex-col gap-4","data-testid":"lunora-audit",children:[i("div",{className:"flex flex-wrap items-center gap-2",children:[e(j,{onChange:y,testId:"au-shard-input",value:T}),e(_,{message:I,prefix:"au"}),e(G,{"aria-label":t("Filter audit log"),className:"h-8 w-48","data-testid":"au-search",onChange:z,placeholder:t("filter op, table, id"),value:c})]}),p!==null&&e(V,{error:R,testId:"au-error"}),p===null&&!E&&d.length===0&&e(F,{description:t("State-changing admin operations are recorded here."),icon:e("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:e("path",{d:"M8 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2h-2M9 3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1V3Zm-1 9h8m-8 4h5"})}),testId:"au-empty",title:t("No audit entries.")}),d.length>0&&e(q,{className:"overflow-hidden py-0",children:e(D,{className:"max-h-[30rem] overflow-auto px-0",ref:f,children:i(W,{"data-testid":"au-table",children:[e(J,{children:i(N,{children:[e(s,{children:t("time")}),e(s,{children:t("op")}),e(s,{children:t("table")}),e(s,{children:t("id")}),e(s,{children:t("detail")})]})}),i(P,{children:[v>0&&e("tr",{"aria-hidden":"true",children:e("td",{colSpan:b,style:O})}),h.map(a=>{const r=d[a.index],S=te(r.detail);return i(N,{"data-testid":"au-row",children:[e(l,{className:"text-muted-foreground tabular-nums",children:$(r.ts,"—")}),e(l,{children:e(U,{variant:"secondary",children:r.op})}),e(l,{className:"font-medium",children:r.table??e("span",{className:"text-muted-foreground",children:"—"})}),e(l,{className:"max-w-[20ch] truncate font-mono text-xs",children:r.id??e("span",{className:"text-muted-foreground",children:"—"})}),e(l,{className:"max-w-[32ch] truncate font-mono text-xs text-muted-foreground",title:S||void 0,children:S||e("span",{className:"text-muted-foreground",children:"—"})})]},r.seq)}),x>0&&e("tr",{"aria-hidden":"true",children:e("td",{colSpan:b,style:k})})]})]})})})]})};export{we as AuditPanel};
@@ -1,6 +1,8 @@
1
- import{LunoraError as R}from"@lunora/errors";import{useLunora as oe}from"@lunora/react";import{encodeWire as W,decodeWire as se}from"@lunora/wire";import{useState as w}from"react";import{ConfirmButton as ne}from"../packem_shared/ConfirmButton-DU4p72Er.mjs";import{ShardInput as le}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{B as D}from"../packem_shared/button-q0UYSmrn.mjs";import{C as P,a as K}from"../packem_shared/card-By2O8ULa.mjs";import{a as ae}from"../packem_shared/use-admin-query-I1uILsUP.mjs";import{useT as ie}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as I}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{f as J,d as C,b as _,c as A}from"../packem_shared/internal-BXEjuLPN.mjs";import{r as M}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{d as ce}from"../packem_shared/grid-features-CIdZ8Dqo.mjs";import{jsxs as m,jsx as l}from"react/jsx-runtime";const de=A(I.exportShard),pe=A(I.importShard),me=A(I.listTables),ue=a=>a.map(n=>JSON.stringify(W(n))).join(`
2
- `),q=(a,n)=>{const t=a.trim();if(t==="")return;const e=se(JSON.parse(t));if(typeof e!="object"||e===null)throw new R("INTERNAL",`line ${n.toString()}: expected a { table, doc } object`);const r=e;if(typeof r.table!="string"||typeof r.doc!="object"||r.doc===null||Array.isArray(r.doc))throw new R("INTERNAL",`line ${n.toString()}: expected a { table, doc } object`);return r},F=1024*1024,U=async function*(a){const n=new TextDecoder("utf-8",{fatal:!0});let t="",e=0;for(let i=0;i<a.size;i+=F){const h=await a.slice(i,i+F).arrayBuffer(),c=`${t}${n.decode(h,{stream:!0})}`.split(`
3
- `);t=c.pop()??"";for(const u of c)e+=1,yield{line:u,lineNumber:e}}const r=t+n.decode();r!==""&&(yield{line:r,lineNumber:e+1})},H=50,fe=500,L=9e5,z=a=>new TextEncoder().encode(JSON.stringify(W(a))).byteLength,O="application/x-ndjson",he=async a=>{let n=0;for await(const{line:t,lineNumber:e}of U(a)){const r=q(t,e);if(r!==void 0){if(z(r)>L)throw new R("INTERNAL",`line ${e.toString()}: a single row is over the ${L.toString()}-byte import limit`);n+=1}}return n},xe=async(a,n)=>{let t=[],e=0,r=0,i=0;for await(const{line:h,lineNumber:c}of U(a)){const u=q(h,c);if(u===void 0)continue;const x=z(u),j=c!==i+1;t.length>0&&(j||t.length===fe||e+x>L)&&(await n(t,r),t=[],e=0),t.length===0&&(r=c),t.push(u),e+=x,i=c}t.length>0&&await n(t,r)},Le=({initialShardKey:a})=>{const n=oe(),t=ae(),e=ie(),[r,i]=w(a??""),[h,c]=w(null),[u,x]=w(!1),[j,S]=w(null),[g,T]=w(null),[B,k]=w(null),[f,E]=w(null),Y=async()=>{const o=r;x(!0),S(null),T(null),E(null);try{const s=await n.query(me,{},C(o));let d=new Blob([],{type:O}),b=0;const N=[];for(const{name:p}of s){const{rows:v}=await n.query(de,{tables:[p]},C(o));if(v.length===0)continue;const y=ue(v);d=new Blob([d,`${y}
4
- `],{type:O}),b+=v.length,N.length<H&&N.push(...y.split(`
5
- `).slice(0,H-N.length))}M(o),E({blob:d,count:b,preview:N.join(`
6
- `),shardKey:o})}catch(s){S(_(s))}},V=async o=>{const s={conflicts:0,errors:[],inserted:{}};let d;try{d=await he(o)}catch(p){return{failure:{message:e("Invalid NDJSON: {message}",{message:_(p)}),rows:0},total:s}}let b=0;const N=async(p,v)=>{k(e("Importing rows {from}–{to} of {total}…",{from:b+1,to:b+p.length,total:d}));const y=await n.query(pe,{rows:p,startLine:v},C(r));s.conflicts+=y.conflicts,s.errors.push(...y.errors);for(const[$,re]of Object.entries(y.inserted))s.inserted[$]=(s.inserted[$]??0)+re;b+=p.length};try{return await xe(o,N),{failure:void 0,total:s}}catch(p){return{failure:{message:_(p),rows:b},total:s}}},X=async o=>{x(!0),S(null),T(null),E(null);const{failure:s,total:d}=await V(o);s===void 0?(M(r),T(d)):s.rows>0?(T(d),S(e("Import stopped after {rows} rows: {message}. The counts below cover completed chunks only; the failed chunk may also have written rows.",{message:s.message,rows:s.rows}))):S(s.message),t(I.readTablePage),t(I.listTables)},G=g===null?0:Object.values(g.inserted).reduce((o,s)=>o+s,0),Q=()=>{J(Y().finally(()=>{x(!1)}))},Z=()=>{h!==null&&J(X(h).finally(()=>{k(null),x(!1)}))},ee=()=>{f!==null&&ce(`${f.shardKey.trim()===""?"shard":f.shardKey.trim()}.ndjson`,f.blob,O)},te=o=>{c(o.target.files?.[0]??null)};return m("div",{className:"flex flex-col gap-4","data-testid":"lunora-export-import",children:[m(P,{className:"gap-0 py-0 rounded-xl border border-border bg-card shadow-xs",children:[l("header",{className:"border-b border-border px-4 py-3",children:l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("Export")})}),m(K,{className:"flex flex-col gap-3 p-4",children:[m("div",{className:"flex flex-wrap items-center gap-2",children:[l(le,{onChange:i,testId:"ei-shard-input",value:r}),l(D,{"data-testid":"ei-export",disabled:u,onClick:Q,type:"button",children:e("Export")})]}),f!==null&&m("div",{className:"flex flex-col gap-2",children:[m("div",{className:"flex flex-wrap items-center gap-2",children:[l("p",{className:"text-sm text-muted-foreground","data-testid":"ei-export-result",children:e("Exported {count} rows.",{count:f.count})}),l(D,{"data-testid":"ei-download",onClick:ee,size:"sm",type:"button",variant:"outline",children:e("Download")})]}),f.preview!==""&&l("pre",{className:"max-h-60 overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"ei-preview",children:f.preview})]})]})]}),m(P,{className:"gap-0 py-0 rounded-xl border border-border bg-card shadow-xs",children:[l("header",{className:"border-b border-border px-4 py-3",children:l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("Import")})}),m(K,{className:"flex flex-col gap-3 p-4",children:[l("input",{accept:".ndjson,.jsonl,application/x-ndjson","aria-label":"NDJSON",className:"text-sm","data-testid":"ei-file",onChange:te,type:"file"}),l("div",{className:"flex flex-wrap items-center gap-2",children:l(ne,{confirmLabel:e("Import (writes rows)?"),disabled:u||h===null,onConfirm:Z,testId:"ei-import",children:e("Import")})}),B!==null&&l("p",{className:"text-sm text-muted-foreground","data-testid":"ei-progress",role:"status",children:B}),g!==null&&m("div",{className:"flex flex-col gap-2","data-testid":"ei-import-result",children:[l("p",{className:"text-sm text-muted-foreground",children:e("Inserted {inserted}, {conflicts} conflicts, {errors} errors.",{conflicts:g.conflicts,errors:g.errors.length,inserted:G})}),g.errors.length>0&&l("ul",{className:"flex flex-col gap-1","data-testid":"ei-import-errors",children:g.errors.map(o=>l("li",{className:"text-xs text-destructive",children:e("line {line} ({table}): {message}",{line:o.line,message:o.message,table:o.table})},`${o.table}-${o.line.toString()}`))})]})]})]}),j!==null&&l("p",{className:"text-sm text-destructive","data-testid":"ei-error",role:"alert",children:j})]})};export{Le as ExportImportPanel};
1
+ import{c as xe}from"react/compiler-runtime";import{LunoraError as K}from"@lunora/errors";import{useLunora as ve}from"@lunora/react";import{encodeWire as X,decodeWire as ye}from"@lunora/wire";import{useState as S}from"react";import{ConfirmButton as be}from"../packem_shared/ConfirmButton-DU4p72Er.mjs";import{ShardInput as Ne}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{B as W}from"../packem_shared/button-q0UYSmrn.mjs";import{C as J,a as Y}from"../packem_shared/card-By2O8ULa.mjs";import{c as Ce,S as ke,a as Ee,b as Te,d as Ie}from"../packem_shared/select-DPyS18Vy.mjs";import{b as Se,u as Re}from"../packem_shared/use-admin-query-CLStXJ7v.mjs";import{useT as re}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as _}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{f as Z,d as O,b as F,c as A}from"../packem_shared/internal-BXEjuLPN.mjs";import{r as G}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{d as _e}from"../packem_shared/grid-features-CIdZ8Dqo.mjs";import{jsxs as E,jsx as m}from"react/jsx-runtime";class R extends Error{problem;constructor(e){super(e.kind),this.name="CsvFormatError",this.problem=e}}const Oe="\uFEFF",Le=()=>{let t=[],e=1,n=!1,r=!1,o="start",s="";const i=()=>{t.push(o==="closing"||s!==""?s:void 0),o="start",s=""},c=l=>{i(),t.some(a=>a!==void 0)&&l.push({cells:t,number:e}),t=[],e+=1},d=(l,a)=>{const u=n;if(n=!1,!(u&&l===`
2
+ `)){if(o==="quoted"){l==='"'?o="closing":s+=l;return}if(o==="closing"&&l==='"'){s+=l,o="quoted";return}if(l===","){i();return}if(l==="\r"){c(a),n=!0;return}if(l===`
3
+ `){c(a);return}if(o==="closing")throw new R({kind:"text-after-quote",record:e});if(o==="start"&&l==='"'){o="quoted";return}o="unquoted",s+=l}};return{finish:()=>{if(o==="quoted")throw new R({kind:"unterminated-quote",record:e});const l=[];return c(l),l},push:l=>{const a=[];let u=0;for(!r&&l!==""&&(r=!0,u=l.startsWith(Oe)?1:0);u<l.length;u+=1)d(l.charAt(u),a);return a}}},oe=async function*(t){const e=Le();for await(const n of t)yield*e.push(n);yield*e.finish()},D=(t,e,n)=>{Object.defineProperty(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0})},se=t=>{const e=[],n=new Set;return t.forEach((r,o)=>{const s=(r??"").trim();if(s==="")throw new R({column:o+1,kind:"empty-header"});if(n.has(s))throw new R({kind:"duplicate-header",name:s});n.add(s),e.push(s)}),e},ie=({cells:t,number:e},n,r)=>{if(t.length!==n.length)throw new R({expected:n.length,found:t.length,kind:"ragged",record:e});const o={};return n.forEach((s,i)=>{const c=t[i];c!==void 0?D(o,s,c):r.has(s)&&D(o,s,null)}),{doc:o,record:e}},Fe=/^-?\d+$/u,je=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/iu,De=/^-?\d{11,}$/u,Ae=/^(\d{4})-(\d{2})-(\d{2})$/u,$e=/^(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/u,Be=/\.(\d+)/u,Pe=/[1-9]/u,Me=/^[+-]?(\d*)(?:\.(\d*))?(?:e([+-]?\d+))?$/iu,z=t=>{const[,e="",n="",r="0"]=Me.exec(t)??[],o=`${e}${n}`;let s=0,i=o.length;for(;s<i&&o.charAt(s)==="0";)s+=1;for(;i>s&&o.charAt(i-1)==="0";)i-=1;return s===i?{digits:"",exponent:0}:{digits:o.slice(s,i),exponent:Number(r)-n.length+(o.length-i)}},qe=(t,e)=>{const n=z(t),r=z(e.toExponential());return n.digits===r.digits&&n.exponent===r.exponent?!0:n.digits!==""&&n.exponent>=0&&Number.isInteger(e)&&BigInt(n.digits)*10n**BigInt(n.exponent)===BigInt(Math.abs(e))},Ke=t=>{const e=t.trim();if(!je.test(e))return;const n=Number(e);if(Number.isFinite(n))return qe(e,n)?{number:n}:{inexact:!0}},Xe=(t,e,n)=>{const r=new Date(0);return r.setUTCFullYear(t,e-1,n),r.getUTCMonth()===e-1&&r.getUTCDate()===n},Ue=(t,e,n,r)=>Number(t)<=23&&Number(e)<=59&&Number(n)<=59&&(r==="Z"||Number(r.slice(1,3))<=23&&Number(r.slice(4,6))<=59),Ve=t=>{const[e="",n,...r]=t.split("T"),o=Ae.exec(e),s=n===void 0?void 0:$e.exec(n);if(o===null||r.length>0||n!==void 0&&s===null)return;const[,i="",c="",d=""]=o;if(!Xe(Number(i),Number(c),Number(d)))return;const[,l="0",a="0",u="0",y]=s??[];if(!Ue(l,a,u,y??"Z"))return;const p=Be.exec(n??"")?.[1]??"";if(Pe.test(p.slice(3)))return;const h=Date.parse(s!==void 0&&y===void 0?`${t}Z`:t);return Number.isFinite(h)?h:void 0},He=t=>{const e=Ke(t);return e===void 0?{expected:"number",kind:"rejected"}:"number"in e?{kind:"ok",value:e.number}:{expected:"number",inexact:!0,kind:"rejected"}},We=t=>{const e=t.trim();let n=Ve(e);return n===void 0&&De.test(e)&&(n=Number(e)),n===void 0||!Number.isFinite(new Date(n).getTime())?{expected:"date",kind:"rejected"}:{kind:"ok",value:n}},Je=t=>{try{return X(t),!0}catch{return!1}},Ye=(t,e)=>{if(e==="bigint"){const n=t.trim();if(!Fe.test(n))return{expected:"bigint",kind:"rejected"};const r=BigInt(n);return Je(r)?{kind:"ok",value:r}:{expected:"bigint",kind:"rejected",tooLong:!0}}if(e==="boolean"){const n=t.trim().toLowerCase();return n==="true"||n==="false"?{kind:"ok",value:n==="true"}:{expected:"boolean",kind:"rejected"}}return e==="number"?He(t):e==="date"||e==="timestamp"?We(t):{kind:"ok",value:t}},le=({doc:t,record:e},n)=>{const r={};for(const[o,s]of Object.entries(t)){if(s===null){D(r,o,null);continue}const i=Ye(s,n.get(o));if(i.kind==="rejected")throw new R({column:o,expected:i.expected,...i.inexact===!0&&{inexact:!0},kind:"cell-type",record:e,...i.tooLong===!0&&{tooLong:!0},value:s});D(r,o,i.value)}return{doc:r,record:e}},Ze=async function*(t,e,n){let r;for await(const o of oe(t))r===void 0?r=se(o.cells):yield le(ie(o,r,n),e)},Ge=t=>new Set(t.filter(e=>e.nullable===!0&&!e.optional).map(e=>e.name)),Q=t=>{if(t instanceof R)return t;throw t},ze=async(t,e,n,r)=>{let o,s,i;for await(const d of oe(t)){if(o===void 0){try{o=se(d.cells)}catch(a){s=Q(a),o=[]}continue}let l;try{l=le(ie(d,o,n),e)}catch(a){i??=Q(a);continue}r(l)}const c=s??i;if(c!==void 0)throw c},Qe=A(_.exportShard),M=A(_.importShard),et=A(_.listTables),tt=A(_.describeTable),nt={},rt=t=>t.map(e=>JSON.stringify(X(e))).join(`
4
+ `),ot=(t,e)=>{const n=t.trim();if(n==="")return;const r=ye(JSON.parse(n));if(typeof r!="object"||r===null)throw new K("INTERNAL",`line ${e.toString()}: expected a { table, doc } object`);const o=r;if(typeof o.table!="string"||typeof o.doc!="object"||o.doc===null||Array.isArray(o.doc))throw new K("INTERNAL",`line ${e.toString()}: expected a { table, doc } object`);return o},ee=1024*1024,U=async function*(t){const e=new TextDecoder("utf-8",{fatal:!0});for(let r=0;r<t.size;r+=ee){const o=await t.slice(r,r+ee).arrayBuffer();yield e.decode(o,{stream:!0})}const n=e.decode();n!==""&&(yield n)},st=async function*(t){let e="",n=0;for await(const r of U(t)){const o=`${e}${r}`.split(`
5
+ `);e=o.pop()??"";for(const s of o)n+=1,yield{line:s,lineNumber:n}}e!==""&&(yield{line:e,lineNumber:n+1})},it=async function*(t){for await(const{line:e,lineNumber:n}of st(t)){const r=ot(e,n);r!==void 0&&(yield{line:n,row:r})}},lt=async function*(t,e,n,r){for await(const{doc:o,record:s}of Ze(U(t),n,r))yield{line:s,row:{doc:o,table:e}}},at=async(t,e,n,r)=>{try{const{columns:o}=await t.query(tt,{table:r},O(n));return{kinds:new Map(o.map(s=>[s.name,s.type])),nullOnEmpty:Ge(o)}}catch(o){return{failure:e("Couldn't read the columns of {table}: {message}",{message:F(o),table:r})}}},te=50,ct=500,$=9e5,V=t=>new TextEncoder().encode(JSON.stringify(X(t))).byteLength,q="application/x-ndjson",ae=t=>new K("INTERNAL",`line ${t.toString()}: a single row is over the ${$.toString()}-byte import limit`),dt=async t=>{let e=0;for await(const{line:n,row:r}of t){if(V(r)>$)throw ae(n);e+=1}return e},ut=async(t,e,n,r)=>{const o={rows:0};if(await ze(U(t),n,r,({doc:s,record:i})=>{o.rows+=1,o.wide===void 0&&V({doc:s,table:e})>$&&(o.wide=i)}),o.wide!==void 0)throw ae(o.wide);return o.rows},ne=async(t,e)=>{let n=[],r=0,o=0,s=0;for await(const{line:i,row:c}of t){const d=V(c),l=i!==s+1;n.length>0&&(l||n.length===ct||r+d>$)&&(await e(n,o),n=[],r=0),n.length===0&&(o=i),n.push(c),r+=d,s=i}n.length>0&&await e(n,o)},ft=/\.csv$/iu,mt=t=>ft.test(t.name)||t.type==="text/csv",ht=(t,e)=>t.expected==="boolean"?e("line {line}: column “{column}” must be true or false, got “{value}”.",{column:t.column,line:t.record,value:t.value}):t.tooLong===!0?e("line {line}: column “{column}” holds an integer longer than the import can send.",{column:t.column,line:t.record}):t.expected==="bigint"?e("line {line}: column “{column}” must be an integer, got “{value}”.",{column:t.column,line:t.record,value:t.value}):t.expected==="date"?e("line {line}: column “{column}” must be an ISO-8601 date or epoch milliseconds of at least 11 digits, got “{value}”.",{column:t.column,line:t.record,value:t.value}):t.inexact===!0?e("line {line}: column “{column}” holds “{value}”, which a number column cannot store exactly. Store a whole number past 9007199254740991 in a bigint column.",{column:t.column,line:t.record,value:t.value}):e("line {line}: column “{column}” must be a number, got “{value}”.",{column:t.column,line:t.record,value:t.value}),pt=(t,e)=>t.kind==="duplicate-header"?e("The header “{name}” appears more than once.",{name:t.name}):t.kind==="empty-header"?e("Header column {column} is empty.",{column:t.column}):t.kind==="ragged"?e("line {line}: expected {expected} cells, found {found}.",{expected:t.expected,found:t.found,line:t.record}):t.kind==="cell-type"?ht(t,e):t.kind==="text-after-quote"?e("line {line}: text follows a closing quote.",{line:t.record}):e("line {line}: a quoted field is never closed.",{line:t.record}),wt=(t,e,n)=>{const r=e instanceof R?pt(e.problem,n):F(e);return t===null?n("Invalid NDJSON: {message}",{message:r}):n("Invalid CSV: {message}",{message:r})},gt=t=>{const e=xe(31),{onChange:n,shardKey:r,value:o}=t,s=re();let i;e[0]!==r?(i={shardKey:r},e[0]=r,e[1]=i):i=e[1];const{data:c}=Re(_.listTables,nt,i);let d;e[2]!==n?(d=C=>{n(C??"")},e[2]=n,e[3]=d):d=e[3];let l;e[4]!==s?(l=s("Target table"),e[4]=s,e[5]=l):l=e[5];let a;e[6]!==s?(a=s("Choose a table"),e[6]=s,e[7]=a):a=e[7];let u;e[8]!==a?(u=m(ke,{placeholder:a}),e[8]=a,e[9]=u):u=e[9];let y;e[10]!==l||e[11]!==u?(y=m(Ee,{"aria-label":l,className:"w-56","data-testid":"ei-csv-table",children:u}),e[10]=l,e[11]=u,e[12]=y):y=e[12];let p;e[13]!==c?(p=c??[],e[13]=c,e[14]=p):p=e[14];let h;e[15]!==p?(h=p.map(vt),e[15]=p,e[16]=h):h=e[16];let g;e[17]!==h?(g=m(Te,{children:h}),e[17]=h,e[18]=g):g=e[18];let N;e[19]!==d||e[20]!==y||e[21]!==g||e[22]!==o?(N=E(Ie,{onValueChange:d,value:o,children:[y,g]}),e[19]=d,e[20]=y,e[21]=g,e[22]=o,e[23]=N):N=e[23];let b;e[24]!==s?(b=s("CSV rows have no table column, so choose the table they go into."),e[24]=s,e[25]=b):b=e[25];let w;e[26]!==b?(w=m("p",{className:"text-xs text-muted-foreground",children:b}),e[26]=b,e[27]=w):w=e[27];let f;return e[28]!==N||e[29]!==w?(f=E("div",{className:"flex flex-col gap-1.5",children:[N,w]}),e[28]=N,e[29]=w,e[30]=f):f=e[30],f},ce=t=>Object.values(t).reduce((e,n)=>e+n,0),xt=async(t,e,n,r,o,s)=>{const i={conflicts:0,errors:[],inserted:{}};let c;const d=s===null?{kinds:new Map,nullOnEmpty:new Set}:await at(t,e,n,s);if("failure"in d)return{failure:{message:d.failure,rows:0},total:i};const{kinds:l,nullOnEmpty:a}=d;try{if(s===null){const f=()=>it(o);c={rows:await dt(f()),source:f}}else c={rows:await ut(o,s,l,a),source:()=>lt(o,s,l,a)}}catch(f){return{failure:{message:wt(s,f,e),rows:0},total:i}}const{rows:u,source:y}=c;if(s!==null&&u===0)return{failure:{message:e("The CSV has no data rows after the header."),rows:0},total:i};const p={conflicts:0,errors:[],inserted:{}};r(e("Checking {total} rows before writing…",{total:u}));try{if((await t.query(M,{dryRun:!0,rows:[],startLine:1},O(n))).dryRun!==!0)return{failure:{message:e("This shard predates import checks, so it would write the file while checking it. Nothing was sent. Update the app and import again."),rows:0},total:i};await ne(y(),async(C,k)=>{const T=await t.query(M,{dryRun:!0,rows:C,startLine:k},O(n));p.errors.push(...T.errors)})}catch(f){return{failure:{message:F(f),rows:0},total:i}}if(p.errors.length>0)return{failure:{message:e("Nothing was written, because some rows would be refused. Fix the rows listed below and import again."),rows:0},total:p};let h=0,g=1;const N={},b={},w=async(f,C)=>{r(e("Importing rows {from}–{to} of {total}…",{from:h+1,to:h+f.length,total:u})),b.startLine=C;const k=await t.query(M,{dryRun:!1,rows:f,startLine:C},O(n));b.startLine=void 0,i.conflicts+=k.conflicts,i.errors.push(...k.errors);for(const[T,B]of Object.entries(k.inserted))i.inserted[T]=(i.inserted[T]??0)+B;if(h+=f.length,g=C+f.length,k.errors.length>0){const T=ce(i.inserted);throw N.refused=!0,new Error(T===0?e("The shard refused {count} rows, so the rest of the file was not sent. Nothing was written. Fix the rows listed below and import again.",{count:k.errors.length}):e("The shard refused {count} rows, so the rest of the file was not sent. {written} rows were already written, so do not import the whole file again. Import the refused rows and any rows from line {line} onward, or delete the written rows first and then import the whole file.",{count:k.errors.length,line:C+f.length,written:T}))}};try{return await ne(y(),w),{failure:void 0,total:i}}catch(f){return{failure:{message:F(f),nextLine:g,rows:h,unknownFrom:b.startLine,...N},total:i}}},$t=({initialShardKey:t})=>{const e=ve(),n=Se(),r=re(),[o,s]=S(t??""),[i,c]=S(null),[d,l]=S(null),[a,u]=S(!1),[y,p]=S(null),[h,g]=S(null),[N,b]=S(null),[w,f]=S(null),C=i!==null&&mt(i),k=d!==null&&d.shardKey===o?d.table:"",T=i!==null&&(!C||k!==""),B=async()=>{const x=o;u(!0),p(null),g(null),f(null);try{const L=await e.query(et,{},O(x));let v=new Blob([],{type:q}),I=0;const j=[];for(const{name:ge}of L){const{rows:P}=await e.query(Qe,{tables:[ge]},O(x));if(P.length===0)continue;const H=rt(P);v=new Blob([v,`${H}
6
+ `],{type:q}),I+=P.length,j.length<te&&j.push(...H.split(`
7
+ `).slice(0,te-j.length))}G(x),f({blob:v,count:I,preview:j.join(`
8
+ `),shardKey:x})}catch(L){p(F(L))}},de=async(x,L)=>{u(!0),p(null),g(null),f(null);const{failure:v,total:I}=await xt(e,r,o,b,x,L);v===void 0?(G(o),g(I)):v.unknownFrom===void 0&&(v.refused===!0||v.rows===0)?(I.errors.length>0&&g(I),p(v.message)):v.unknownFrom===void 0?(g(I),p(r("Import stopped after {rows} rows: {message}. The counts below cover those rows. Rows from line {line} onward were not sent: do not import the whole file again, import from that line onward, or delete the written rows first and then import the whole file.",{line:v.nextLine,message:v.message,rows:v.rows}))):(g(I),p(r("Import stopped after {rows} rows: {message}. The counts below cover completed chunks only. The chunk from line {line} may have written rows: check the table for rows from line {line} onward before importing again, or delete the written rows first and then import the whole file.",{line:v.unknownFrom,message:v.message,rows:v.rows}))),n(_.readTablePage),n(_.listTables)},ue=h===null?0:ce(h.inserted),fe=()=>{Z(B().finally(()=>{u(!1)}))},me=()=>{i!==null&&T&&Z(de(i,C?k:null).finally(()=>{b(null),u(!1)}))},he=()=>{w!==null&&_e(`${w.shardKey.trim()===""?"shard":w.shardKey.trim()}.ndjson`,w.blob,q)},pe=x=>{c(x.target.files?.[0]??null),l(null)},we=x=>{l({shardKey:o,table:x})};return E("div",{className:"flex flex-col gap-4","data-testid":"lunora-export-import",children:[E(J,{className:"gap-0 py-0 rounded-xl border border-border bg-card shadow-xs",children:[m("header",{className:"border-b border-border px-4 py-3",children:m("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Export")})}),E(Y,{className:"flex flex-col gap-3 p-4",children:[E("div",{className:"flex flex-wrap items-center gap-2",children:[m(Ne,{onChange:s,testId:"ei-shard-input",value:o}),m(W,{"data-testid":"ei-export",disabled:a,onClick:fe,type:"button",children:r("Export")})]}),w!==null&&E("div",{className:"flex flex-col gap-2",children:[E("div",{className:"flex flex-wrap items-center gap-2",children:[m("p",{className:"text-sm text-muted-foreground","data-testid":"ei-export-result",children:r("Exported {count} rows.",{count:w.count})}),m(W,{"data-testid":"ei-download",onClick:he,size:"sm",type:"button",variant:"outline",children:r("Download")})]}),w.preview!==""&&m("pre",{className:"max-h-60 overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"ei-preview",children:w.preview})]})]})]}),E(J,{className:"gap-0 py-0 rounded-xl border border-border bg-card shadow-xs",children:[m("header",{className:"border-b border-border px-4 py-3",children:m("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Import")})}),E(Y,{className:"flex flex-col gap-3 p-4",children:[m("input",{accept:".ndjson,.jsonl,.csv,application/x-ndjson,text/csv","aria-label":r("Import file"),className:"text-sm","data-testid":"ei-file",onChange:pe,type:"file"}),C&&m(gt,{onChange:we,shardKey:o,value:k}),m("div",{className:"flex flex-wrap items-center gap-2",children:m(be,{confirmLabel:r("Import (writes rows)?"),disabled:a||!T,onConfirm:me,testId:"ei-import",children:r("Import")})}),N!==null&&m("p",{className:"text-sm text-muted-foreground","data-testid":"ei-progress",role:"status",children:N}),h!==null&&E("div",{className:"flex flex-col gap-2","data-testid":"ei-import-result",children:[m("p",{className:"text-sm text-muted-foreground",children:r("Inserted {inserted}, {conflicts} conflicts, {errors} errors.",{conflicts:h.conflicts,errors:h.errors.length,inserted:ue})}),h.errors.length>0&&m("ul",{className:"flex flex-col gap-1","data-testid":"ei-import-errors",children:h.errors.map(x=>m("li",{className:"text-xs text-destructive",children:r("line {line} ({table}): {message}",{line:x.line,message:x.message,table:x.table})},`${x.table}-${x.line.toString()}`))})]})]})]}),y!==null&&m("p",{className:"text-sm text-destructive","data-testid":"ei-error",role:"alert",children:y})]})};function vt(t){return m(Ce,{value:t.name,children:t.name},t.name)}export{$t as ExportImportPanel};
@@ -1 +1 @@
1
- import{c as Q}from"react/compiler-runtime";import{useState as U}from"react";import{E as V}from"../packem_shared/error-alert-D-ftqyo-.mjs";import{L as W}from"../packem_shared/live-status-BuJdUZFU.mjs";import{ShardInput as G}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{B as J}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as X}from"../packem_shared/button-q0UYSmrn.mjs";import{C as Y,a as Z}from"../packem_shared/card-By2O8ULa.mjs";import{E as ee}from"../packem_shared/empty-state-D7jEML_T.mjs";import{T as te,a as re,b as L,c as a,d as le,e as n}from"../packem_shared/table-D0SBiDu-.mjs";import{u as se}from"../packem_shared/use-admin-query-I1uILsUP.mjs";import{u as ae}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as ie}from"../packem_shared/internal-BXEjuLPN.mjs";import{c as j}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as t,jsxs as y}from"react/jsx-runtime";const ce={action:"outline",mutation:"default",query:"secondary"},q=r=>r<1e3?`${r<10?r.toFixed(1):Math.round(r).toString()}ms`:`${(r/1e3).toFixed(2)}s`,de=r=>r.calls===0?"—":r.errors===0?"0":`${r.errors.toString()} (${(r.errors/r.calls*100).toFixed(1)}%)`,me=r=>{const e=r.conflicts??0;return r.calls===0?"—":e===0?"0":`${e.toString()} (${(e/r.calls*100).toFixed(1)}%)`},ue={calls:(r,e)=>e.calls-r.calls,recent:(r,e)=>e.lastCalledAt-r.lastCalledAt,slowest:(r,e)=>e.maxDurationMs-r.maxDurationMs},Ae=r=>{const e=Q(47),{functions:I,initialShardKey:P}=r,s=ne(),{queryShardKey:F,setShardKey:N,shardKey:S}=ae(P),[o,H]=U("recent");let M;e[0]===Symbol.for("react.memo_cache_sentinel")?(M={},e[0]=M):M=e[0];let T;e[1]!==F?(T={live:!0,shardKey:F},e[1]=F,e[2]=T):T=e[2];const{data:O,error:i,errorSource:b,liveError:v}=se(oe.getFunctionStats,M,T),k=O?.functions??null;let w;e[3]!==I?(w=new Map((I??[]).map(fe)),e[3]=I,e[4]=w):w=e[4];const _=w;let E;e[5]===Symbol.for("react.memo_cache_sentinel")?(E=C=>{H(C.currentTarget.dataset.sort)},e[5]=E):E=e[5];const z=E;let K;if(e[6]!==i||e[7]!==b||e[8]!==_||e[9]!==v||e[10]!==N||e[11]!==S||e[12]!==o||e[13]!==k||e[14]!==s){const C=k===null?[]:k.toSorted(ue[o]);let c;e[16]!==s?(c=s("Recent"),e[16]=s,e[17]=c):c=e[17];let d;e[18]!==c?(d={key:"recent",label:c},e[18]=c,e[19]=d):d=e[19];let m;e[20]!==s?(m=s("Most called"),e[20]=s,e[21]=m):m=e[21];let u;e[22]!==m?(u={key:"calls",label:m},e[22]=m,e[23]=u):u=e[23];let f;e[24]!==s?(f=s("Slowest"),e[24]=s,e[25]=f):f=e[25];let h;e[26]!==f?(h={key:"slowest",label:f},e[26]=f,e[27]=h):h=e[27];let $;e[28]!==h||e[29]!==d||e[30]!==u?($=[d,u,h],e[28]=h,e[29]=d,e[30]=u,e[31]=$):$=e[31];const D=$;let p;e[32]!==N||e[33]!==S?(p=t(G,{onChange:N,testId:"fs-shard-input",value:S}),e[32]=N,e[33]=S,e[34]=p):p=e[34];let x;e[35]!==v?(x=t(W,{message:v,prefix:"fs"}),e[35]=v,e[36]=x):x=e[36];let g;e[37]!==D||e[38]!==o?(g=t("div",{className:"ml-auto flex items-center gap-1",role:"group",children:D.map(l=>t(X,{"data-sort":l.key,"data-testid":`fs-sort-${l.key}`,onClick:z,size:"sm",type:"button",variant:o===l.key?"secondary":"ghost",children:l.label},l.key))}),e[37]=D,e[38]=o,e[39]=g):g=e[39];let A;e[40]!==p||e[41]!==x||e[42]!==g?(A=y("div",{className:"flex flex-wrap items-center gap-2",children:[p,x,g]}),e[40]=p,e[41]=x,e[42]=g,e[43]=A):A=e[43];let B;e[44]!==i||e[45]!==b?(B=i!==null&&t(V,{error:b,testId:"fs-error"}),e[44]=i,e[45]=b,e[46]=B):B=e[46],K=y("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-stats",children:[A,B,k!==null&&C.length===0&&i===null&&t(ee,{description:s("Per-function call counts, error rates, and latency land here after your first request."),icon:y("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[t("path",{d:"M3 3v18h18"}),t("path",{d:"M7 14l4-4 3 3 5-6"})]}),testId:"fs-empty",title:s("No functions have run on this shard yet.")}),C.length>0&&t(Y,{className:"overflow-hidden py-0",children:t(Z,{className:"px-0",children:y(te,{"data-testid":"fs-table",children:[t(re,{children:y(L,{children:[t(a,{children:s("function")}),t(a,{children:s("kind")}),t(a,{className:"text-right",children:s("calls")}),t(a,{className:"text-right",children:s("errors")}),t(a,{className:"text-right",children:s("conflicts")}),t(a,{className:"text-right",children:s("avg")}),t(a,{className:"text-right",children:s("max")}),t(a,{children:s("last run")}),t(a,{children:s("last error")})]})}),t(le,{children:C.map(l=>{const R=_.get(l.path);return y(L,{"data-testid":`fs-row-${l.path}`,children:[t(n,{className:"font-medium",children:l.path}),t(n,{children:R===void 0?t("span",{className:"text-muted-foreground",children:"—"}):t(J,{variant:ce[R],children:R})}),t(n,{className:"text-right tabular-nums",children:l.calls}),t(n,{className:j("text-right tabular-nums",l.errors>0&&"text-destructive"),children:de(l)}),t(n,{className:j("text-right tabular-nums",(l.conflicts??0)>0&&"text-warning"),children:me(l)}),t(n,{className:"text-right tabular-nums",children:l.calls===0?"—":q(l.totalDurationMs/l.calls)}),t(n,{className:"text-right tabular-nums",children:l.calls===0?"—":q(l.maxDurationMs)}),t(n,{className:"text-muted-foreground",children:ie(l.lastCalledAt,"—")}),t(n,{className:"max-w-[24ch] truncate text-destructive",title:l.lastErrorMessage??void 0,children:l.lastErrorMessage??t("span",{className:"text-muted-foreground",children:"—"})})]},l.path)})})]})})})]}),e[6]=i,e[7]=b,e[8]=_,e[9]=v,e[10]=N,e[11]=S,e[12]=o,e[13]=k,e[14]=s,e[15]=K}else K=e[15];return K};function fe(r){return[r.path,r.kind]}export{Ae as FunctionStatsPanel};
1
+ import{c as Q}from"react/compiler-runtime";import{useState as U}from"react";import{E as V}from"../packem_shared/error-alert-CNQjdAhi.mjs";import{L as W}from"../packem_shared/live-status-BuJdUZFU.mjs";import{ShardInput as G}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{B as J}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as X}from"../packem_shared/button-q0UYSmrn.mjs";import{C as Y,a as Z}from"../packem_shared/card-By2O8ULa.mjs";import{E as ee}from"../packem_shared/empty-state-D7jEML_T.mjs";import{T as te,a as re,b as L,c as a,d as le,e as n}from"../packem_shared/table-D0SBiDu-.mjs";import{u as se}from"../packem_shared/use-admin-query-CLStXJ7v.mjs";import{u as ae}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as ie}from"../packem_shared/internal-BXEjuLPN.mjs";import{c as j}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as t,jsxs as y}from"react/jsx-runtime";const ce={action:"outline",mutation:"default",query:"secondary"},q=r=>r<1e3?`${r<10?r.toFixed(1):Math.round(r).toString()}ms`:`${(r/1e3).toFixed(2)}s`,de=r=>r.calls===0?"—":r.errors===0?"0":`${r.errors.toString()} (${(r.errors/r.calls*100).toFixed(1)}%)`,me=r=>{const e=r.conflicts??0;return r.calls===0?"—":e===0?"0":`${e.toString()} (${(e/r.calls*100).toFixed(1)}%)`},ue={calls:(r,e)=>e.calls-r.calls,recent:(r,e)=>e.lastCalledAt-r.lastCalledAt,slowest:(r,e)=>e.maxDurationMs-r.maxDurationMs},Ae=r=>{const e=Q(47),{functions:I,initialShardKey:P}=r,s=ne(),{queryShardKey:F,setShardKey:N,shardKey:S}=ae(P),[o,H]=U("recent");let M;e[0]===Symbol.for("react.memo_cache_sentinel")?(M={},e[0]=M):M=e[0];let T;e[1]!==F?(T={live:!0,shardKey:F},e[1]=F,e[2]=T):T=e[2];const{data:O,error:i,errorSource:b,liveError:v}=se(oe.getFunctionStats,M,T),k=O?.functions??null;let w;e[3]!==I?(w=new Map((I??[]).map(fe)),e[3]=I,e[4]=w):w=e[4];const _=w;let E;e[5]===Symbol.for("react.memo_cache_sentinel")?(E=C=>{H(C.currentTarget.dataset.sort)},e[5]=E):E=e[5];const z=E;let K;if(e[6]!==i||e[7]!==b||e[8]!==_||e[9]!==v||e[10]!==N||e[11]!==S||e[12]!==o||e[13]!==k||e[14]!==s){const C=k===null?[]:k.toSorted(ue[o]);let c;e[16]!==s?(c=s("Recent"),e[16]=s,e[17]=c):c=e[17];let d;e[18]!==c?(d={key:"recent",label:c},e[18]=c,e[19]=d):d=e[19];let m;e[20]!==s?(m=s("Most called"),e[20]=s,e[21]=m):m=e[21];let u;e[22]!==m?(u={key:"calls",label:m},e[22]=m,e[23]=u):u=e[23];let f;e[24]!==s?(f=s("Slowest"),e[24]=s,e[25]=f):f=e[25];let h;e[26]!==f?(h={key:"slowest",label:f},e[26]=f,e[27]=h):h=e[27];let $;e[28]!==h||e[29]!==d||e[30]!==u?($=[d,u,h],e[28]=h,e[29]=d,e[30]=u,e[31]=$):$=e[31];const D=$;let p;e[32]!==N||e[33]!==S?(p=t(G,{onChange:N,testId:"fs-shard-input",value:S}),e[32]=N,e[33]=S,e[34]=p):p=e[34];let x;e[35]!==v?(x=t(W,{message:v,prefix:"fs"}),e[35]=v,e[36]=x):x=e[36];let g;e[37]!==D||e[38]!==o?(g=t("div",{className:"ml-auto flex items-center gap-1",role:"group",children:D.map(l=>t(X,{"data-sort":l.key,"data-testid":`fs-sort-${l.key}`,onClick:z,size:"sm",type:"button",variant:o===l.key?"secondary":"ghost",children:l.label},l.key))}),e[37]=D,e[38]=o,e[39]=g):g=e[39];let A;e[40]!==p||e[41]!==x||e[42]!==g?(A=y("div",{className:"flex flex-wrap items-center gap-2",children:[p,x,g]}),e[40]=p,e[41]=x,e[42]=g,e[43]=A):A=e[43];let B;e[44]!==i||e[45]!==b?(B=i!==null&&t(V,{error:b,testId:"fs-error"}),e[44]=i,e[45]=b,e[46]=B):B=e[46],K=y("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-stats",children:[A,B,k!==null&&C.length===0&&i===null&&t(ee,{description:s("Per-function call counts, error rates, and latency land here after your first request."),icon:y("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[t("path",{d:"M3 3v18h18"}),t("path",{d:"M7 14l4-4 3 3 5-6"})]}),testId:"fs-empty",title:s("No functions have run on this shard yet.")}),C.length>0&&t(Y,{className:"overflow-hidden py-0",children:t(Z,{className:"px-0",children:y(te,{"data-testid":"fs-table",children:[t(re,{children:y(L,{children:[t(a,{children:s("function")}),t(a,{children:s("kind")}),t(a,{className:"text-right",children:s("calls")}),t(a,{className:"text-right",children:s("errors")}),t(a,{className:"text-right",children:s("conflicts")}),t(a,{className:"text-right",children:s("avg")}),t(a,{className:"text-right",children:s("max")}),t(a,{children:s("last run")}),t(a,{children:s("last error")})]})}),t(le,{children:C.map(l=>{const R=_.get(l.path);return y(L,{"data-testid":`fs-row-${l.path}`,children:[t(n,{className:"font-medium",children:l.path}),t(n,{children:R===void 0?t("span",{className:"text-muted-foreground",children:"—"}):t(J,{variant:ce[R],children:R})}),t(n,{className:"text-right tabular-nums",children:l.calls}),t(n,{className:j("text-right tabular-nums",l.errors>0&&"text-destructive"),children:de(l)}),t(n,{className:j("text-right tabular-nums",(l.conflicts??0)>0&&"text-warning"),children:me(l)}),t(n,{className:"text-right tabular-nums",children:l.calls===0?"—":q(l.totalDurationMs/l.calls)}),t(n,{className:"text-right tabular-nums",children:l.calls===0?"—":q(l.maxDurationMs)}),t(n,{className:"text-muted-foreground",children:ie(l.lastCalledAt,"—")}),t(n,{className:"max-w-[24ch] truncate text-destructive",title:l.lastErrorMessage??void 0,children:l.lastErrorMessage??t("span",{className:"text-muted-foreground",children:"—"})})]},l.path)})})]})})})]}),e[6]=i,e[7]=b,e[8]=_,e[9]=v,e[10]=N,e[11]=S,e[12]=o,e[13]=k,e[14]=s,e[15]=K}else K=e[15];return K};function fe(r){return[r.path,r.kind]}export{Ae as FunctionStatsPanel};
@@ -1 +1 @@
1
- import{c as ae}from"react/compiler-runtime";import{useLunora as pe}from"@lunora/react";import{useState as S,useRef as j,useCallback as ge,useEffect as Z}from"react";import xe from"../packem_shared/ConnectionBadge-B8Hj5DaE.mjs";import{L as ve}from"../packem_shared/live-status-BuJdUZFU.mjs";import{B as G}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as _}from"../packem_shared/card-By2O8ULa.mjs";import{u as Ne}from"../packem_shared/use-admin-query-I1uILsUP.mjs";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as R}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as be,f as K,d as ee,b as te,c as L}from"../packem_shared/internal-BXEjuLPN.mjs";import{l as we}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{c as M}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as l,jsxs as u}from"react/jsx-runtime";import{shardsToAggregate as Ee}from"../packem_shared/aggregateMetrics-DKFJc-o5.mjs";import{S as $}from"../packem_shared/sparkline-B_sPPO_8.mjs";const Se={crit:"destructive",ok:"secondary",warn:"default"},P=(s,e)=>e===0?"—":`${(s/e*100).toFixed(1)}%`,z=(s,e,r)=>Number.isNaN(s)?"ok":s>=r?"crit":s>=e?"warn":"ok",ne=.01,oe=.05,ye=s=>{const e=ae(36),{errorCount:r,logsError:t,topErrors:a,worstFunctions:m}=s,o=le();let n;e[0]!==o?(n=o("Functions by error rate"),e[0]=o,e[1]=n):n=e[1];let f;e[2]!==n?(f=l("header",{className:"border-b border-border px-4 py-3",children:l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n})}),e[2]=n,e[3]=f):f=e[3];let d;e[4]!==o||e[5]!==m?(d=m.length===0?l("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:o("No function activity yet.")}):l("ul",{className:"divide-y divide-border",children:m.map(w=>u("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[l("span",{className:"truncate font-mono text-foreground",children:w.path}),u("span",{className:"flex shrink-0 items-center gap-2",children:[l("span",{className:"tabular-nums text-muted-foreground",children:o("{count} calls",{count:w.calls.toString()})}),l(G,{variant:Se[z(w.errors/w.calls,ne,oe)],children:P(w.errors,w.calls)})]})]},w.path))}),e[4]=o,e[5]=m,e[6]=d):d=e[6];let h;e[7]!==f||e[8]!==d?(h=u(_,{className:"gap-0 py-0","data-testid":"hl-functions",children:[f,d]}),e[7]=f,e[8]=d,e[9]=h):h=e[9];let x;e[10]!==o?(x=o("Recent errors"),e[10]=o,e[11]=x):x=e[11];let i;e[12]!==x?(i=l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:x}),e[12]=x,e[13]=i):i=e[13];const c=r>0?"destructive":"outline";let p;e[14]!==r||e[15]!==c?(p=l(G,{"data-testid":"hl-error-count",variant:c,children:r}),e[14]=r,e[15]=c,e[16]=p):p=e[16];let g;e[17]!==i||e[18]!==p?(g=u("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[i,p]}),e[17]=i,e[18]=p,e[19]=g):g=e[19];let y;e[20]!==t?(y=t!==null&&l("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:t}),e[20]=t,e[21]=y):y=e[21];let T;e[22]!==t||e[23]!==o||e[24]!==a.length?(T=t===null&&a.length===0&&l("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:o("No recent errors.")}),e[22]=t,e[23]=o,e[24]=a.length,e[25]=T):T=e[25];let A;e[26]!==a?(A=a.length>0&&l("ul",{className:"divide-y divide-border",children:a.map(Te)}),e[26]=a,e[27]=A):A=e[27];let N;e[28]!==y||e[29]!==T||e[30]!==A||e[31]!==g?(N=u(_,{className:"gap-0 py-0",children:[g,y,T,A]}),e[28]=y,e[29]=T,e[30]=A,e[31]=g,e[32]=N):N=e[32];let E;return e[33]!==N||e[34]!==h?(E=u("div",{className:"grid gap-3 lg:grid-cols-2",children:[h,N]}),e[33]=N,e[34]=h,e[35]=E):E=e[35],E};function Te(s,e){return u("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[u("span",{className:"flex items-center gap-2",children:[l("time",{className:"shrink-0 text-muted-foreground",children:be(s.timestamp)}),s.functionPath!==void 0&&l("span",{className:"truncate font-mono text-foreground",children:s.functionPath})]}),l("span",{className:"text-destructive",children:s.message})]},`${s.timestamp.toString()}-${e.toString()}`)}const re={completed:0,failed:2,in_progress:1},Ae=s=>{let e=0,r=0,t=0,a=0,m=!1;const o=[];for(const{metrics:n}of s){if(n===null){a+=1;continue}t+=1,e+=n.requests,r+=n.errors,o.push(...n.history??[]),m||=n.historyTruncated===!0}return{errors:r,failed:a,history:o,historyTruncated:m,reachable:t,requests:e}},ke=s=>{const e=new Map;for(const r of s)for(const t of r){const a=e.get(t.path);if(a===void 0){e.set(t.path,{...t});continue}a.calls+=t.calls,a.errors+=t.errors,a.totalDurationMs+=t.totalDurationMs,a.scans=(a.scans??0)+(t.scans??0),a.maxDurationMs=Math.max(a.maxDurationMs,t.maxDurationMs),a.lastCalledAt=Math.max(a.lastCalledAt,t.lastCalledAt),(t.lastErrorAt??0)>(a.lastErrorAt??0)&&(a.lastErrorAt=t.lastErrorAt,a.lastErrorMessage=t.lastErrorMessage)}return[...e.values()]},Re=s=>{const e=new Map;for(const r of s)for(const t of r){const a=e.get(t.id);if(a===void 0){e.set(t.id,t);continue}const m=re[t.status]-re[a.status];(m>0||m===0&&(t.updatedAt??0)>(a.updatedAt??0))&&e.set(t.id,t)}return[...e.values()]},Me=L(R.getAuthMetrics),_e=L(R.getFunctionStats),Le=L(R.getLogs),Ie=L(R.getMetrics),Ce=L(R.migrationStatus),qe=5,se=2e3,Oe=5,Fe=.1,De=.3,je=1,Ue=50,Pe=(s,e,r)=>s>=r?"crit":s>=e?"warn":"ok",Ge=s=>{const e=new Map;for(const t of s??[]){const a=e.get(t.bucketMs)??{calls:0,errors:0};a.calls+=t.calls,a.errors+=t.errors,e.set(t.bucketMs,a)}const r=[...e.entries()].toSorted((t,a)=>t[0]-a[0]);return{errors:r.map(([,t])=>t.errors),requests:r.map(([,t])=>t.calls)}},Ve=s=>{let e=0,r=0;for(const a of s)a.status==="failed"?e+=1:a.status==="in_progress"&&(r+=1);let t="ok";return e>0?t="crit":r>0&&(t="warn"),{failed:e,level:t,running:r}},Be=(s,e)=>s.failed>0?e("{count} failed",{count:s.failed.toString()}):s.running>0?e("{count} running",{count:s.running.toString()}):e("OK"),ie={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},ce={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},He={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Ke=s=>s.includes("crit")?"crit":s.includes("warn")?"warn":"ok",U=s=>{const e=ae(19),{chart:r,label:t,level:a,testId:m,value:o}=s,n=ie[a];let f;e[0]!==n?(f=M("size-1.5 shrink-0 rounded-full",n),e[0]=n,e[1]=f):f=e[1];let d;e[2]!==f?(d=l("span",{"aria-hidden":"true",className:f}),e[2]=f,e[3]=d):d=e[3];let h;e[4]!==t||e[5]!==d?(h=u("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[d,t]}),e[4]=t,e[5]=d,e[6]=h):h=e[6];const x=ce[a];let i;e[7]!==x?(i=M("truncate text-2xl font-semibold tabular-nums",x),e[7]=x,e[8]=i):i=e[8];let c;e[9]!==i||e[10]!==m||e[11]!==o?(c=l("span",{className:i,"data-testid":m,children:o}),e[9]=i,e[10]=m,e[11]=o,e[12]=c):c=e[12];let p;e[13]!==r||e[14]!==c?(p=u("div",{className:"flex items-center justify-between gap-3",children:[c,r]}),e[13]=r,e[14]=c,e[15]=p):p=e[15];let g;return e[16]!==h||e[17]!==p?(g=l(_,{className:"gap-0 py-0",children:u("div",{className:"flex flex-col gap-2.5 p-4",children:[h,p]})}),e[16]=h,e[17]=p,e[18]=g):g=e[18],g},$e=async(s,e,r)=>{const t=await Promise.all(r.map(i=>{const c=ee(i);return Promise.allSettled([s.query(Ie,{},c),s.query(_e,{},c),s.query(Ce,{},c)])})),a=ee(e),m=typeof s.schedulerStatus=="function"?s.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[o,n,f]=await Promise.allSettled([s.query(Le,{},a),s.query(Me,{},a),m]),d=t.map(([i,c,p])=>({functions:c.status==="fulfilled"?c.value.functions:[],metrics:i.status==="fulfilled"?i.value:null,migrations:p.status==="fulfilled"?p.value.migrations:[]})),h=Ae(d),x=t[0]?.[0];return{auth:n.status==="fulfilled"?n.value:null,entries:o.status==="fulfilled"?o.value.entries:[],functions:ke(d.map(i=>i.functions)),logsError:o.status==="rejected"?te(o.reason):null,metricsError:h.reachable===0&&x?.status==="rejected"?te(x.reason):null,migrations:Re(d.map(i=>i.migrations)),scheduler:f.status==="fulfilled"?f.value:null,totals:h}},ze=s=>{const e=s?.history??[];return{attempts:e.map(r=>r.attempts),failures:e.map(r=>r.failures)}},ut=({initialShardKey:s})=>{const e=pe(),r=le(),[t,a]=S([]),[m,o]=S(null),[n,f]=S(null),[d,h]=S(null),[x,i]=S([]),[c,p]=S(null),[g,y]=S(null),[T,A]=S([]),[N]=S(we),E=j(!1),w=j(0),V=j(0),k=j(null),I=s??"",C=ge(async()=>{if(E.current)return;E.current=!0;const v=w.current,b=await $e(e,I,Ee(I,N));v===w.current&&(f(b.totals),h(b.metricsError),i(b.functions),A(b.migrations),a(b.entries),o(b.logsError),p(b.auth),y(b.scheduler),E.current=!1)},[e,N,I]);Z(()=>(K(C()),()=>{w.current+=1,E.current=!1,k.current!==null&&(clearTimeout(k.current),k.current=null)}),[C]);const ue=()=>{const v=Date.now()-V.current;if(v>=se){V.current=Date.now(),K(C());return}k.current===null&&(k.current=setTimeout(()=>{k.current=null,V.current=Date.now(),K(C())},se-v))},{data:Q,liveError:de}=Ne(R.getMetrics,{},{live:!0,shardKey:I});Z(()=>{Q!==void 0&&ue()},[Q]);const W=t.filter(v=>v.level==="error"),me=W.slice(0,qe),q=Ge(n?.history),X=ze(c),fe=x.filter(v=>v.calls>0).toSorted((v,b)=>b.errors/b.calls-v.errors/v.calls||b.calls-v.calls).slice(0,Oe),B=Ve(T),he=n===null||n.requests===0?0:n.errors/n.requests,H=z(he,ne,oe),J=c===null?"ok":z(c.failureRate,Fe,De),Y=g===null?"ok":Pe(g.backlog,je,Ue),O=Ke([H,J,Y,B.level]);let F,D;return O==="crit"?(F=r("Critical"),D=r("One or more service levels are breached.")):O==="warn"?(F=r("Degraded"),D=r("Some service levels need attention.")):(F=r("All systems healthy"),D=r("All service levels are within target.")),u("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[u(_,{className:"gap-0 py-0",children:[u("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[u("div",{className:"flex items-center gap-3",children:[l("span",{"aria-hidden":"true",className:M("flex size-10 shrink-0 items-center justify-center rounded-full",He[O]),children:l("span",{className:M("size-3 rounded-full",ie[O])})}),u("div",{className:"grid leading-tight",children:[l("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:F}),l("span",{className:"text-[13px] text-muted-foreground",children:D})]})]}),u("div",{className:"flex flex-wrap items-center gap-4",children:[u("div",{className:"text-end",children:[l("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:r("Requests")}),u("div",{className:"flex items-center justify-end gap-2",children:[q.requests.length>=2&&l($,{ariaLabel:r("Requests over time"),className:"h-6 w-20 text-foreground",series:q.requests,testId:"hl-spark-requests"}),l("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(n?.requests??0).toString()})]})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),u("div",{className:"text-end",children:[l("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:r("Error rate")}),l("div",{className:M("text-lg font-semibold tabular-nums",ce[H]),"data-testid":"hl-error-rate",children:n===null?"—":P(n.errors,n.requests)})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),u("div",{className:"flex items-center gap-2",children:[l(xe,{}),l(ve,{message:de,prefix:"hl"})]})]})]}),d!==null&&l("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-sm text-destructive","data-testid":"hl-metrics-error",role:"alert",children:d}),d===null&&n?.historyTruncated===!0&&l("div",{className:"border-t border-border bg-warning/5 px-4 py-2 text-sm text-muted-foreground","data-testid":"hl-history-truncated",children:r("Showing a partial request/error history — one or more shards have more data than the trend chart can display.")})]}),u("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[l(U,{chart:q.errors.length>=2?l($,{ariaLabel:r("Errors over time"),className:"h-7 w-20 text-destructive",series:q.errors,testId:"hl-spark-errors"}):void 0,label:r("Error rate"),level:H,testId:"hl-slo-errorrate",value:n===null?"—":P(n.errors,n.requests)}),l(U,{chart:X.failures.length>=2?l($,{ariaLabel:r("Auth failures over time"),className:"h-7 w-20 text-destructive",series:X.failures,testId:"hl-spark-auth"}):void 0,label:r("Auth failures"),level:J,testId:"hl-slo-auth",value:c===null?"—":P(c.failures,c.attempts)}),l(U,{label:r("Scheduler backlog"),level:Y,testId:"hl-slo-backlog",value:g===null?"—":g.backlog.toString()}),l(U,{label:r("Migrations"),level:B.level,testId:"hl-slo-migrations",value:Be(B,r)})]}),l(ye,{errorCount:W.length,logsError:m,topErrors:me,worstFunctions:fe}),u(_,{className:"gap-0 py-0",children:[u("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Shards seen")}),l(G,{"data-testid":"hl-shard-count",variant:"outline",children:N.length})]}),N.length>0&&l("ul",{className:"flex flex-wrap gap-1.5 p-4",children:N.map(v=>l("li",{"data-testid":"hl-shard",children:l(G,{variant:"secondary",children:v})},v))})]})]})};export{ut as HealthPanel};
1
+ import{c as ae}from"react/compiler-runtime";import{useLunora as pe}from"@lunora/react";import{useState as S,useRef as j,useCallback as ge,useEffect as Z}from"react";import xe from"../packem_shared/ConnectionBadge-B8Hj5DaE.mjs";import{L as ve}from"../packem_shared/live-status-BuJdUZFU.mjs";import{B as G}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as _}from"../packem_shared/card-By2O8ULa.mjs";import{u as Ne}from"../packem_shared/use-admin-query-CLStXJ7v.mjs";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as R}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as be,f as K,d as ee,b as te,c as L}from"../packem_shared/internal-BXEjuLPN.mjs";import{l as we}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{c as M}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as l,jsxs as u}from"react/jsx-runtime";import{shardsToAggregate as Ee}from"../packem_shared/aggregateMetrics-DKFJc-o5.mjs";import{S as $}from"../packem_shared/sparkline-B_sPPO_8.mjs";const Se={crit:"destructive",ok:"secondary",warn:"default"},P=(s,e)=>e===0?"—":`${(s/e*100).toFixed(1)}%`,z=(s,e,r)=>Number.isNaN(s)?"ok":s>=r?"crit":s>=e?"warn":"ok",ne=.01,oe=.05,ye=s=>{const e=ae(36),{errorCount:r,logsError:t,topErrors:a,worstFunctions:m}=s,o=le();let n;e[0]!==o?(n=o("Functions by error rate"),e[0]=o,e[1]=n):n=e[1];let f;e[2]!==n?(f=l("header",{className:"border-b border-border px-4 py-3",children:l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n})}),e[2]=n,e[3]=f):f=e[3];let d;e[4]!==o||e[5]!==m?(d=m.length===0?l("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:o("No function activity yet.")}):l("ul",{className:"divide-y divide-border",children:m.map(w=>u("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[l("span",{className:"truncate font-mono text-foreground",children:w.path}),u("span",{className:"flex shrink-0 items-center gap-2",children:[l("span",{className:"tabular-nums text-muted-foreground",children:o("{count} calls",{count:w.calls.toString()})}),l(G,{variant:Se[z(w.errors/w.calls,ne,oe)],children:P(w.errors,w.calls)})]})]},w.path))}),e[4]=o,e[5]=m,e[6]=d):d=e[6];let h;e[7]!==f||e[8]!==d?(h=u(_,{className:"gap-0 py-0","data-testid":"hl-functions",children:[f,d]}),e[7]=f,e[8]=d,e[9]=h):h=e[9];let x;e[10]!==o?(x=o("Recent errors"),e[10]=o,e[11]=x):x=e[11];let i;e[12]!==x?(i=l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:x}),e[12]=x,e[13]=i):i=e[13];const c=r>0?"destructive":"outline";let p;e[14]!==r||e[15]!==c?(p=l(G,{"data-testid":"hl-error-count",variant:c,children:r}),e[14]=r,e[15]=c,e[16]=p):p=e[16];let g;e[17]!==i||e[18]!==p?(g=u("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[i,p]}),e[17]=i,e[18]=p,e[19]=g):g=e[19];let y;e[20]!==t?(y=t!==null&&l("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:t}),e[20]=t,e[21]=y):y=e[21];let T;e[22]!==t||e[23]!==o||e[24]!==a.length?(T=t===null&&a.length===0&&l("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:o("No recent errors.")}),e[22]=t,e[23]=o,e[24]=a.length,e[25]=T):T=e[25];let A;e[26]!==a?(A=a.length>0&&l("ul",{className:"divide-y divide-border",children:a.map(Te)}),e[26]=a,e[27]=A):A=e[27];let N;e[28]!==y||e[29]!==T||e[30]!==A||e[31]!==g?(N=u(_,{className:"gap-0 py-0",children:[g,y,T,A]}),e[28]=y,e[29]=T,e[30]=A,e[31]=g,e[32]=N):N=e[32];let E;return e[33]!==N||e[34]!==h?(E=u("div",{className:"grid gap-3 lg:grid-cols-2",children:[h,N]}),e[33]=N,e[34]=h,e[35]=E):E=e[35],E};function Te(s,e){return u("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[u("span",{className:"flex items-center gap-2",children:[l("time",{className:"shrink-0 text-muted-foreground",children:be(s.timestamp)}),s.functionPath!==void 0&&l("span",{className:"truncate font-mono text-foreground",children:s.functionPath})]}),l("span",{className:"text-destructive",children:s.message})]},`${s.timestamp.toString()}-${e.toString()}`)}const re={completed:0,failed:2,in_progress:1},Ae=s=>{let e=0,r=0,t=0,a=0,m=!1;const o=[];for(const{metrics:n}of s){if(n===null){a+=1;continue}t+=1,e+=n.requests,r+=n.errors,o.push(...n.history??[]),m||=n.historyTruncated===!0}return{errors:r,failed:a,history:o,historyTruncated:m,reachable:t,requests:e}},ke=s=>{const e=new Map;for(const r of s)for(const t of r){const a=e.get(t.path);if(a===void 0){e.set(t.path,{...t});continue}a.calls+=t.calls,a.errors+=t.errors,a.totalDurationMs+=t.totalDurationMs,a.scans=(a.scans??0)+(t.scans??0),a.maxDurationMs=Math.max(a.maxDurationMs,t.maxDurationMs),a.lastCalledAt=Math.max(a.lastCalledAt,t.lastCalledAt),(t.lastErrorAt??0)>(a.lastErrorAt??0)&&(a.lastErrorAt=t.lastErrorAt,a.lastErrorMessage=t.lastErrorMessage)}return[...e.values()]},Re=s=>{const e=new Map;for(const r of s)for(const t of r){const a=e.get(t.id);if(a===void 0){e.set(t.id,t);continue}const m=re[t.status]-re[a.status];(m>0||m===0&&(t.updatedAt??0)>(a.updatedAt??0))&&e.set(t.id,t)}return[...e.values()]},Me=L(R.getAuthMetrics),_e=L(R.getFunctionStats),Le=L(R.getLogs),Ie=L(R.getMetrics),Ce=L(R.migrationStatus),qe=5,se=2e3,Oe=5,Fe=.1,De=.3,je=1,Ue=50,Pe=(s,e,r)=>s>=r?"crit":s>=e?"warn":"ok",Ge=s=>{const e=new Map;for(const t of s??[]){const a=e.get(t.bucketMs)??{calls:0,errors:0};a.calls+=t.calls,a.errors+=t.errors,e.set(t.bucketMs,a)}const r=[...e.entries()].toSorted((t,a)=>t[0]-a[0]);return{errors:r.map(([,t])=>t.errors),requests:r.map(([,t])=>t.calls)}},Ve=s=>{let e=0,r=0;for(const a of s)a.status==="failed"?e+=1:a.status==="in_progress"&&(r+=1);let t="ok";return e>0?t="crit":r>0&&(t="warn"),{failed:e,level:t,running:r}},Be=(s,e)=>s.failed>0?e("{count} failed",{count:s.failed.toString()}):s.running>0?e("{count} running",{count:s.running.toString()}):e("OK"),ie={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},ce={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},He={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Ke=s=>s.includes("crit")?"crit":s.includes("warn")?"warn":"ok",U=s=>{const e=ae(19),{chart:r,label:t,level:a,testId:m,value:o}=s,n=ie[a];let f;e[0]!==n?(f=M("size-1.5 shrink-0 rounded-full",n),e[0]=n,e[1]=f):f=e[1];let d;e[2]!==f?(d=l("span",{"aria-hidden":"true",className:f}),e[2]=f,e[3]=d):d=e[3];let h;e[4]!==t||e[5]!==d?(h=u("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[d,t]}),e[4]=t,e[5]=d,e[6]=h):h=e[6];const x=ce[a];let i;e[7]!==x?(i=M("truncate text-2xl font-semibold tabular-nums",x),e[7]=x,e[8]=i):i=e[8];let c;e[9]!==i||e[10]!==m||e[11]!==o?(c=l("span",{className:i,"data-testid":m,children:o}),e[9]=i,e[10]=m,e[11]=o,e[12]=c):c=e[12];let p;e[13]!==r||e[14]!==c?(p=u("div",{className:"flex items-center justify-between gap-3",children:[c,r]}),e[13]=r,e[14]=c,e[15]=p):p=e[15];let g;return e[16]!==h||e[17]!==p?(g=l(_,{className:"gap-0 py-0",children:u("div",{className:"flex flex-col gap-2.5 p-4",children:[h,p]})}),e[16]=h,e[17]=p,e[18]=g):g=e[18],g},$e=async(s,e,r)=>{const t=await Promise.all(r.map(i=>{const c=ee(i);return Promise.allSettled([s.query(Ie,{},c),s.query(_e,{},c),s.query(Ce,{},c)])})),a=ee(e),m=typeof s.schedulerStatus=="function"?s.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[o,n,f]=await Promise.allSettled([s.query(Le,{},a),s.query(Me,{},a),m]),d=t.map(([i,c,p])=>({functions:c.status==="fulfilled"?c.value.functions:[],metrics:i.status==="fulfilled"?i.value:null,migrations:p.status==="fulfilled"?p.value.migrations:[]})),h=Ae(d),x=t[0]?.[0];return{auth:n.status==="fulfilled"?n.value:null,entries:o.status==="fulfilled"?o.value.entries:[],functions:ke(d.map(i=>i.functions)),logsError:o.status==="rejected"?te(o.reason):null,metricsError:h.reachable===0&&x?.status==="rejected"?te(x.reason):null,migrations:Re(d.map(i=>i.migrations)),scheduler:f.status==="fulfilled"?f.value:null,totals:h}},ze=s=>{const e=s?.history??[];return{attempts:e.map(r=>r.attempts),failures:e.map(r=>r.failures)}},ut=({initialShardKey:s})=>{const e=pe(),r=le(),[t,a]=S([]),[m,o]=S(null),[n,f]=S(null),[d,h]=S(null),[x,i]=S([]),[c,p]=S(null),[g,y]=S(null),[T,A]=S([]),[N]=S(we),E=j(!1),w=j(0),V=j(0),k=j(null),I=s??"",C=ge(async()=>{if(E.current)return;E.current=!0;const v=w.current,b=await $e(e,I,Ee(I,N));v===w.current&&(f(b.totals),h(b.metricsError),i(b.functions),A(b.migrations),a(b.entries),o(b.logsError),p(b.auth),y(b.scheduler),E.current=!1)},[e,N,I]);Z(()=>(K(C()),()=>{w.current+=1,E.current=!1,k.current!==null&&(clearTimeout(k.current),k.current=null)}),[C]);const ue=()=>{const v=Date.now()-V.current;if(v>=se){V.current=Date.now(),K(C());return}k.current===null&&(k.current=setTimeout(()=>{k.current=null,V.current=Date.now(),K(C())},se-v))},{data:Q,liveError:de}=Ne(R.getMetrics,{},{live:!0,shardKey:I});Z(()=>{Q!==void 0&&ue()},[Q]);const W=t.filter(v=>v.level==="error"),me=W.slice(0,qe),q=Ge(n?.history),X=ze(c),fe=x.filter(v=>v.calls>0).toSorted((v,b)=>b.errors/b.calls-v.errors/v.calls||b.calls-v.calls).slice(0,Oe),B=Ve(T),he=n===null||n.requests===0?0:n.errors/n.requests,H=z(he,ne,oe),J=c===null?"ok":z(c.failureRate,Fe,De),Y=g===null?"ok":Pe(g.backlog,je,Ue),O=Ke([H,J,Y,B.level]);let F,D;return O==="crit"?(F=r("Critical"),D=r("One or more service levels are breached.")):O==="warn"?(F=r("Degraded"),D=r("Some service levels need attention.")):(F=r("All systems healthy"),D=r("All service levels are within target.")),u("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[u(_,{className:"gap-0 py-0",children:[u("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[u("div",{className:"flex items-center gap-3",children:[l("span",{"aria-hidden":"true",className:M("flex size-10 shrink-0 items-center justify-center rounded-full",He[O]),children:l("span",{className:M("size-3 rounded-full",ie[O])})}),u("div",{className:"grid leading-tight",children:[l("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:F}),l("span",{className:"text-[13px] text-muted-foreground",children:D})]})]}),u("div",{className:"flex flex-wrap items-center gap-4",children:[u("div",{className:"text-end",children:[l("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:r("Requests")}),u("div",{className:"flex items-center justify-end gap-2",children:[q.requests.length>=2&&l($,{ariaLabel:r("Requests over time"),className:"h-6 w-20 text-foreground",series:q.requests,testId:"hl-spark-requests"}),l("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(n?.requests??0).toString()})]})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),u("div",{className:"text-end",children:[l("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:r("Error rate")}),l("div",{className:M("text-lg font-semibold tabular-nums",ce[H]),"data-testid":"hl-error-rate",children:n===null?"—":P(n.errors,n.requests)})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),u("div",{className:"flex items-center gap-2",children:[l(xe,{}),l(ve,{message:de,prefix:"hl"})]})]})]}),d!==null&&l("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-sm text-destructive","data-testid":"hl-metrics-error",role:"alert",children:d}),d===null&&n?.historyTruncated===!0&&l("div",{className:"border-t border-border bg-warning/5 px-4 py-2 text-sm text-muted-foreground","data-testid":"hl-history-truncated",children:r("Showing a partial request/error history — one or more shards have more data than the trend chart can display.")})]}),u("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[l(U,{chart:q.errors.length>=2?l($,{ariaLabel:r("Errors over time"),className:"h-7 w-20 text-destructive",series:q.errors,testId:"hl-spark-errors"}):void 0,label:r("Error rate"),level:H,testId:"hl-slo-errorrate",value:n===null?"—":P(n.errors,n.requests)}),l(U,{chart:X.failures.length>=2?l($,{ariaLabel:r("Auth failures over time"),className:"h-7 w-20 text-destructive",series:X.failures,testId:"hl-spark-auth"}):void 0,label:r("Auth failures"),level:J,testId:"hl-slo-auth",value:c===null?"—":P(c.failures,c.attempts)}),l(U,{label:r("Scheduler backlog"),level:Y,testId:"hl-slo-backlog",value:g===null?"—":g.backlog.toString()}),l(U,{label:r("Migrations"),level:B.level,testId:"hl-slo-migrations",value:Be(B,r)})]}),l(ye,{errorCount:W.length,logsError:m,topErrors:me,worstFunctions:fe}),u(_,{className:"gap-0 py-0",children:[u("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Shards seen")}),l(G,{"data-testid":"hl-shard-count",variant:"outline",children:N.length})]}),N.length>0&&l("ul",{className:"flex flex-wrap gap-1.5 p-4",children:N.map(v=>l("li",{"data-testid":"hl-shard",children:l(G,{variant:"secondary",children:v})},v))})]})]})};export{ut as HealthPanel};
@@ -1 +1 @@
1
- import{c as X}from"react/compiler-runtime";import{useLunora as se}from"@lunora/react";import{useNavigate as ae}from"@tanstack/react-router";import{useState as H,useRef as re,useEffectEvent as Q,useEffect as z,useCallback as oe,useMemo as N}from"react";import{ShardInput as ie}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{B as ce}from"../packem_shared/button-q0UYSmrn.mjs";import{u as B}from"../packem_shared/use-admin-query-I1uILsUP.mjs";import{u as le}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as K}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as w}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{f as k,d as E,c as M,n as de}from"../packem_shared/internal-BXEjuLPN.mjs";import{r as ue}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{a as G,A as fe}from"../packem_shared/advisor-view-CXiPdw4B.mjs";import{ConfirmButton as me}from"../packem_shared/ConfirmButton-DU4p72Er.mjs";import{jsx as v,jsxs as he}from"react/jsx-runtime";import{deriveInsights as pe}from"../packem_shared/DEFAULT_INSIGHT_THRESHOLDS-D5YMT0gM.mjs";import{runAdvisor as be,RUNTIME_LINTS as xe}from"@lunora/advisor";const ye=t=>{const{suggestedIndex:e,table:a}=t;if(typeof a!="string"||a.length===0||typeof e!="object"||e===null)return!1;const{fields:n,name:s}=e;return!Array.isArray(n)||n.length===0||n.some(i=>typeof i!="string"||i.length===0)?!1:typeof s=="string"&&s.length>0},ge=(t,e)=>`.index(${JSON.stringify(t)}, [${e.map(a=>JSON.stringify(a)).join(", ")}])`,ve=t=>{const e=X(19),{fields:a,indexName:n,table:s,testId:i}=t,l=K(),[f,d]=H(null);let m;e[0]!==a||e[1]!==n?(m=()=>{const b=ge(n,a),I="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if(I===void 0){d({copied:!1,declaration:b});return}k(I.writeText(b).then(()=>(d({copied:!0,declaration:b}),!0)),()=>{d({copied:!1,declaration:b})})},e[0]=a,e[1]=n,e[2]=m):m=e[2];const S=m;if(f!==null){let b;return e[3]!==f.copied||e[4]!==f.declaration||e[5]!==l||e[6]!==s||e[7]!==i?(b=f.copied?v("span",{className:"text-xs text-muted-foreground","data-testid":`${i}-applied`,children:l("Index declaration copied — add it to {table} in lunora/schema.ts.",{table:s})}):he("span",{className:"flex flex-col gap-1 text-xs text-muted-foreground","data-testid":`${i}-manual`,children:[l("Could not reach the clipboard — add this to {table} in lunora/schema.ts:",{table:s}),v("code",{className:"font-mono break-all select-all",children:f.declaration})]}),e[3]=f.copied,e[4]=f.declaration,e[5]=l,e[6]=s,e[7]=i,e[8]=b):b=e[8],b}let u;e[9]!==l?(u=l("Copy?"),e[9]=l,e[10]=u):u=e[10];let h;e[11]!==l||e[12]!==s?(h=l("Copy index declaration for {table}",{table:s}),e[11]=l,e[12]=s,e[13]=h):h=e[13];let y;return e[14]!==S||e[15]!==u||e[16]!==h||e[17]!==i?(y=v(me,{confirmLabel:u,onConfirm:S,testId:i,children:h}),e[14]=S,e[15]=u,e[16]=h,e[17]=i,e[18]=y):y=e[18],y},Se=(t,e)=>{const a=new Map;for(const n of e){const s=`${n.table} ${n.index}`;a.set(s,(a.get(s)??0)+n.reads)}return t.map(n=>({index:n.index,reads:a.get(`${n.table} ${n.index}`)??0,table:n.table}))},Te=t=>{const e=new Map;for(const a of t)for(const n of a.scannedTables??[])e.set(n.table,(e.get(n.table)??0)+n.scans);return[...e].map(([a,n])=>({scans:n,table:a}))},P=(t,e)=>e.map(a=>({index:a.name,table:t})),we=t=>{const e=Se(t.declaredIndexes??[],t.indexHits??[]),a=Te(t.functions??[]),n=t.shardTraffic??[],s=t.analyticsMetrics,i=s&&s.indexHits.length>0?s.indexHits:e,l=s&&s.tableScans.length>0?s.tableScans:a,f=s&&s.shardTraffic.length>0?s.shardTraffic:n,d=be({indexHits:i,schema:{tables:[]},shardTraffic:f,tableScans:l},{lints:xe,source:"runtime"}),m=t.suppressHotScanTables;return(m===void 0?d:d.filter(u=>!(u.metadata.kind==="hot_scan"&&typeof u.metadata.table=="string"&&m.has(u.metadata.table)))).map(u=>G(u))},Ie=M(w.listTables),$e=M(w.listTableIndexes),Ae=M(w.listTablesIndexes),L=t=>`${(t*100).toFixed(1)}%`,V=t=>`${(t/1e3).toFixed(2)}s`,Ne=t=>{if(t.length<=1)return t[0]??"";const e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},ke=(t,e)=>({"high-error-rate":t("High error rate"),"high-evictions":t("High cache eviction rate"),"high-write-contention":t("High write contention"),"low-cache-hit-rate":t("Low cache hit rate"),"missing-index":t("Missing index"),"slow-function":t("Slow function"),"storage-headroom":t("Storage headroom")})[e.kind],U=(t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:L(e.value)}),"high-evictions":t("{count} entries evicted recently.",{count:e.value}),"high-write-contention":t("{rate} of calls hit a write conflict — consider sharding to cut contention.",{rate:L(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:L(e.value)}),"missing-index":t("Slowest call took {duration} — it full-scanned {tables} with no index.",{duration:V(e.value),tables:Ne(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:V(e.value)}),"storage-headroom":t("{size} of the 10 GiB per-shard ceiling — plan a .shardBy() migration while it still has runway.",{size:de(e.value)})})[e.kind],Be=t=>{const e=X(10),{onJump:a,table:n}=t,s=K();let i;e[0]!==a||e[1]!==n?(i=()=>{a(n)},e[0]=a,e[1]=n,e[2]=i):i=e[2];const l=i,f=`in-add-index-${n}`;let d;e[3]!==s||e[4]!==n?(d=s("Add index on {table}",{table:n}),e[3]=s,e[4]=n,e[5]=d):d=e[5];let m;return e[6]!==l||e[7]!==f||e[8]!==d?(m=v(ce,{"data-testid":f,onClick:l,size:"sm",type:"button",variant:"outline",children:d}),e[6]=l,e[7]=f,e[8]=d,e[9]=m):m=e[9],m},Ue=({initialShardKey:t,loadShardTraffic:e})=>{const a=se(),n=ae(),s=K(),{queryShardKey:i,setShardKey:l,shardKey:f}=le(t),[d,m]=H(null),[S,u]=H(null),h=re(""),y=B(w.getMetrics,{},{live:!0,shardKey:i}),b=B(w.getFunctionStats,{},{live:!0,shardKey:i}),I=B(w.getAdvisories,{},{live:!0,shardKey:i}),D=y.data??null,$=b.data?.functions??null,R=I.data?.advisories??null,C=y.data?.indexHits??null,j=y.error!==null&&b.error!==null?y.error:null,W=e??(r=>a.shardTraffic(r)),Y=async(r,x)=>{const g=r[0];if(g===void 0||g===""){h.current===x&&u(null);return}try{const o=await W(g);if(h.current!==x)return;const c=new Map;for(const p of o.shards)c.has(p.shardKey)||c.set(p.shardKey,{requests:p.requests,shardKey:p.shardKey});u([...c.values()])}catch{h.current===x&&u(null)}},Z=async(r,x)=>{const g=await Promise.allSettled(r.map(async c=>[c,await a.query($e,{table:c},E(x))])),o=[];for(const c of g)if(c.status==="fulfilled"){const[p,T]=c.value;o.push(...P(p,T.indexes))}return o},F=Q(async r=>{h.current=r;let x=[];try{const g=await a.query(Ie,{},E(r));if(h.current!==r)return;ue(r),x=g.map(c=>c.name);let o=[];if(x.length>0)try{const c=await a.query(Ae,{tables:x},E(r));if(h.current!==r)return;for(const[p,T]of Object.entries(c.indexesByTable))o.push(...P(p,T))}catch{if(o=await Z(x,r),h.current!==r)return}m(o)}catch{h.current===r&&m(null)}await Y(x,r)});z(()=>{k(F(i))},[i]);const _=Q(()=>{y.refetch(),b.refetch(),I.refetch(),k(F(i))});z(()=>{const r=()=>{document.visibilityState==="visible"&&_()};return document.addEventListener("visibilitychange",r),()=>{document.removeEventListener("visibilitychange",r)}},[]);const O=oe(r=>{k(n({search:{table:r},to:"/schema"}))},[n]),A=N(()=>pe(D,$),[$,D]),q=N(()=>new Set(A.filter(r=>r.kind==="missing-index").flatMap(r=>r.tables??[])),[A]),J=N(()=>we({declaredIndexes:d??[],functions:$,indexHits:C,shardTraffic:S,suppressHotScanTables:q}),[d,$,C,q,S]),ee=N(()=>{const r=A.map(o=>{const c=o.kind==="missing-index"?o.tables??[]:[];return{action:c.length>0?c.map(p=>v(Be,{onJump:O,table:p},p)):void 0,description:o.message===void 0?U(s,o):`${U(s,o)} — ${o.message}`,entity:o.fn,issueType:ke(s,o),key:`${o.kind}:${o.fn??""}`,level:o.severity}}),x=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(R??[]).map(o=>{const c=G(o);if(x.has(o.name)&&ye(o.metadata)){const{table:p,suggestedIndex:T}=o.metadata,ne=`in-apply-index-${p}-${T.name}`;return{...c,action:v(ve,{fields:T.fields,indexName:T.name,table:p,testId:ne})}}return c}),...J,...r]},[R,A,O,J,s]),te=v(ie,{onChange:l,testId:"in-shard-input",value:f});return v(fe,{error:j,errorSource:j===null?void 0:y.errorSource,rows:ee,testId:"lunora-insights",toolbar:te})};export{Ue as InsightsPanel};
1
+ import{c as X}from"react/compiler-runtime";import{useLunora as se}from"@lunora/react";import{useNavigate as ae}from"@tanstack/react-router";import{useState as H,useRef as re,useEffectEvent as Q,useEffect as z,useCallback as oe,useMemo as N}from"react";import{ShardInput as ie}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{B as ce}from"../packem_shared/button-q0UYSmrn.mjs";import{u as B}from"../packem_shared/use-admin-query-CLStXJ7v.mjs";import{u as le}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as K}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as w}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{f as k,d as E,c as M,n as de}from"../packem_shared/internal-BXEjuLPN.mjs";import{r as ue}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{a as G,A as fe}from"../packem_shared/advisor-view-B8oIluyS.mjs";import{ConfirmButton as me}from"../packem_shared/ConfirmButton-DU4p72Er.mjs";import{jsx as v,jsxs as he}from"react/jsx-runtime";import{deriveInsights as pe}from"../packem_shared/DEFAULT_INSIGHT_THRESHOLDS-D5YMT0gM.mjs";import{runAdvisor as be,RUNTIME_LINTS as xe}from"@lunora/advisor";const ye=t=>{const{suggestedIndex:e,table:a}=t;if(typeof a!="string"||a.length===0||typeof e!="object"||e===null)return!1;const{fields:n,name:s}=e;return!Array.isArray(n)||n.length===0||n.some(i=>typeof i!="string"||i.length===0)?!1:typeof s=="string"&&s.length>0},ge=(t,e)=>`.index(${JSON.stringify(t)}, [${e.map(a=>JSON.stringify(a)).join(", ")}])`,ve=t=>{const e=X(19),{fields:a,indexName:n,table:s,testId:i}=t,l=K(),[f,d]=H(null);let m;e[0]!==a||e[1]!==n?(m=()=>{const b=ge(n,a),I="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if(I===void 0){d({copied:!1,declaration:b});return}k(I.writeText(b).then(()=>(d({copied:!0,declaration:b}),!0)),()=>{d({copied:!1,declaration:b})})},e[0]=a,e[1]=n,e[2]=m):m=e[2];const S=m;if(f!==null){let b;return e[3]!==f.copied||e[4]!==f.declaration||e[5]!==l||e[6]!==s||e[7]!==i?(b=f.copied?v("span",{className:"text-xs text-muted-foreground","data-testid":`${i}-applied`,children:l("Index declaration copied — add it to {table} in lunora/schema.ts.",{table:s})}):he("span",{className:"flex flex-col gap-1 text-xs text-muted-foreground","data-testid":`${i}-manual`,children:[l("Could not reach the clipboard — add this to {table} in lunora/schema.ts:",{table:s}),v("code",{className:"font-mono break-all select-all",children:f.declaration})]}),e[3]=f.copied,e[4]=f.declaration,e[5]=l,e[6]=s,e[7]=i,e[8]=b):b=e[8],b}let u;e[9]!==l?(u=l("Copy?"),e[9]=l,e[10]=u):u=e[10];let h;e[11]!==l||e[12]!==s?(h=l("Copy index declaration for {table}",{table:s}),e[11]=l,e[12]=s,e[13]=h):h=e[13];let y;return e[14]!==S||e[15]!==u||e[16]!==h||e[17]!==i?(y=v(me,{confirmLabel:u,onConfirm:S,testId:i,children:h}),e[14]=S,e[15]=u,e[16]=h,e[17]=i,e[18]=y):y=e[18],y},Se=(t,e)=>{const a=new Map;for(const n of e){const s=`${n.table} ${n.index}`;a.set(s,(a.get(s)??0)+n.reads)}return t.map(n=>({index:n.index,reads:a.get(`${n.table} ${n.index}`)??0,table:n.table}))},Te=t=>{const e=new Map;for(const a of t)for(const n of a.scannedTables??[])e.set(n.table,(e.get(n.table)??0)+n.scans);return[...e].map(([a,n])=>({scans:n,table:a}))},P=(t,e)=>e.map(a=>({index:a.name,table:t})),we=t=>{const e=Se(t.declaredIndexes??[],t.indexHits??[]),a=Te(t.functions??[]),n=t.shardTraffic??[],s=t.analyticsMetrics,i=s&&s.indexHits.length>0?s.indexHits:e,l=s&&s.tableScans.length>0?s.tableScans:a,f=s&&s.shardTraffic.length>0?s.shardTraffic:n,d=be({indexHits:i,schema:{tables:[]},shardTraffic:f,tableScans:l},{lints:xe,source:"runtime"}),m=t.suppressHotScanTables;return(m===void 0?d:d.filter(u=>!(u.metadata.kind==="hot_scan"&&typeof u.metadata.table=="string"&&m.has(u.metadata.table)))).map(u=>G(u))},Ie=M(w.listTables),$e=M(w.listTableIndexes),Ae=M(w.listTablesIndexes),L=t=>`${(t*100).toFixed(1)}%`,V=t=>`${(t/1e3).toFixed(2)}s`,Ne=t=>{if(t.length<=1)return t[0]??"";const e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},ke=(t,e)=>({"high-error-rate":t("High error rate"),"high-evictions":t("High cache eviction rate"),"high-write-contention":t("High write contention"),"low-cache-hit-rate":t("Low cache hit rate"),"missing-index":t("Missing index"),"slow-function":t("Slow function"),"storage-headroom":t("Storage headroom")})[e.kind],U=(t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:L(e.value)}),"high-evictions":t("{count} entries evicted recently.",{count:e.value}),"high-write-contention":t("{rate} of calls hit a write conflict — consider sharding to cut contention.",{rate:L(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:L(e.value)}),"missing-index":t("Slowest call took {duration} — it full-scanned {tables} with no index.",{duration:V(e.value),tables:Ne(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:V(e.value)}),"storage-headroom":t("{size} of the 10 GiB per-shard ceiling — plan a .shardBy() migration while it still has runway.",{size:de(e.value)})})[e.kind],Be=t=>{const e=X(10),{onJump:a,table:n}=t,s=K();let i;e[0]!==a||e[1]!==n?(i=()=>{a(n)},e[0]=a,e[1]=n,e[2]=i):i=e[2];const l=i,f=`in-add-index-${n}`;let d;e[3]!==s||e[4]!==n?(d=s("Add index on {table}",{table:n}),e[3]=s,e[4]=n,e[5]=d):d=e[5];let m;return e[6]!==l||e[7]!==f||e[8]!==d?(m=v(ce,{"data-testid":f,onClick:l,size:"sm",type:"button",variant:"outline",children:d}),e[6]=l,e[7]=f,e[8]=d,e[9]=m):m=e[9],m},Ue=({initialShardKey:t,loadShardTraffic:e})=>{const a=se(),n=ae(),s=K(),{queryShardKey:i,setShardKey:l,shardKey:f}=le(t),[d,m]=H(null),[S,u]=H(null),h=re(""),y=B(w.getMetrics,{},{live:!0,shardKey:i}),b=B(w.getFunctionStats,{},{live:!0,shardKey:i}),I=B(w.getAdvisories,{},{live:!0,shardKey:i}),D=y.data??null,$=b.data?.functions??null,R=I.data?.advisories??null,C=y.data?.indexHits??null,j=y.error!==null&&b.error!==null?y.error:null,W=e??(r=>a.shardTraffic(r)),Y=async(r,x)=>{const g=r[0];if(g===void 0||g===""){h.current===x&&u(null);return}try{const o=await W(g);if(h.current!==x)return;const c=new Map;for(const p of o.shards)c.has(p.shardKey)||c.set(p.shardKey,{requests:p.requests,shardKey:p.shardKey});u([...c.values()])}catch{h.current===x&&u(null)}},Z=async(r,x)=>{const g=await Promise.allSettled(r.map(async c=>[c,await a.query($e,{table:c},E(x))])),o=[];for(const c of g)if(c.status==="fulfilled"){const[p,T]=c.value;o.push(...P(p,T.indexes))}return o},F=Q(async r=>{h.current=r;let x=[];try{const g=await a.query(Ie,{},E(r));if(h.current!==r)return;ue(r),x=g.map(c=>c.name);let o=[];if(x.length>0)try{const c=await a.query(Ae,{tables:x},E(r));if(h.current!==r)return;for(const[p,T]of Object.entries(c.indexesByTable))o.push(...P(p,T))}catch{if(o=await Z(x,r),h.current!==r)return}m(o)}catch{h.current===r&&m(null)}await Y(x,r)});z(()=>{k(F(i))},[i]);const _=Q(()=>{y.refetch(),b.refetch(),I.refetch(),k(F(i))});z(()=>{const r=()=>{document.visibilityState==="visible"&&_()};return document.addEventListener("visibilitychange",r),()=>{document.removeEventListener("visibilitychange",r)}},[]);const O=oe(r=>{k(n({search:{table:r},to:"/schema"}))},[n]),A=N(()=>pe(D,$),[$,D]),q=N(()=>new Set(A.filter(r=>r.kind==="missing-index").flatMap(r=>r.tables??[])),[A]),J=N(()=>we({declaredIndexes:d??[],functions:$,indexHits:C,shardTraffic:S,suppressHotScanTables:q}),[d,$,C,q,S]),ee=N(()=>{const r=A.map(o=>{const c=o.kind==="missing-index"?o.tables??[]:[];return{action:c.length>0?c.map(p=>v(Be,{onJump:O,table:p},p)):void 0,description:o.message===void 0?U(s,o):`${U(s,o)} — ${o.message}`,entity:o.fn,issueType:ke(s,o),key:`${o.kind}:${o.fn??""}`,level:o.severity}}),x=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(R??[]).map(o=>{const c=G(o);if(x.has(o.name)&&ye(o.metadata)){const{table:p,suggestedIndex:T}=o.metadata,ne=`in-apply-index-${p}-${T.name}`;return{...c,action:v(ve,{fields:T.fields,indexName:T.name,table:p,testId:ne})}}return c}),...J,...r]},[R,A,O,J,s]),te=v(ie,{onChange:l,testId:"in-shard-input",value:f});return v(fe,{error:j,errorSource:j===null?void 0:y.errorSource,rows:ee,testId:"lunora-insights",toolbar:te})};export{Ue as InsightsPanel};
@@ -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-BolUoZ9g.mjs";import{E as Se}from"../packem_shared/error-alert-D-ftqyo-.mjs";import{B as he}from"../packem_shared/badge-r_5B4LHP.mjs";import{E as ee}from"../packem_shared/empty-state-D7jEML_T.mjs";import{u as le}from"../packem_shared/use-admin-query-I1uILsUP.mjs";import{u as Te}from"../packem_shared/use-open-trace-B_0LbTD7.mjs";import{u as Ie}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as Q}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{r as Re}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{f as ke}from"../packem_shared/virtual-rect-D_j7aLxX.mjs";import{useLunora as Pe}from"@lunora/react";import{B as Ee}from"../packem_shared/button-q0UYSmrn.mjs";import{I as D}from"../packem_shared/input-CXhxesPC.mjs";import{T as Oe,a as _e,b as ge,c as B,d as Fe,e as V}from"../packem_shared/table-D0SBiDu-.mjs";import ae from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{a as pe}from"../packem_shared/cf-links-CBJ5SywP.mjs";import{f as ne,j as qe,b as ie}from"../packem_shared/internal-BXEjuLPN.mjs";import{a as Ae,L as Me}from"../packem_shared/log-line-BWDt_F56.mjs";import{jsx as r,jsxs as E,Fragment as $e}from"react/jsx-runtime";import{c as H}from"../packem_shared/utils-bhneXptQ.mjs";import{L as Ue}from"../packem_shared/live-status-BuJdUZFU.mjs";import{ShardInput as Ke}from"../packem_shared/ShardInput-C6mjgAh4.mjs";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-BolUoZ9g.mjs";import{E as Se}from"../packem_shared/error-alert-CNQjdAhi.mjs";import{B as he}from"../packem_shared/badge-r_5B4LHP.mjs";import{E as ee}from"../packem_shared/empty-state-D7jEML_T.mjs";import{u as le}from"../packem_shared/use-admin-query-CLStXJ7v.mjs";import{u as Te}from"../packem_shared/use-open-trace-B_0LbTD7.mjs";import{u as Ie}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as Q}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{r as Re}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{f as ke}from"../packem_shared/virtual-rect-D_j7aLxX.mjs";import{useLunora as Pe}from"@lunora/react";import{B as Ee}from"../packem_shared/button-q0UYSmrn.mjs";import{I as D}from"../packem_shared/input-CXhxesPC.mjs";import{T as Oe,a as _e,b as ge,c as B,d as Fe,e as V}from"../packem_shared/table-D0SBiDu-.mjs";import ae from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{a as pe}from"../packem_shared/cf-links-CBJ5SywP.mjs";import{f as ne,j as qe,b as ie}from"../packem_shared/internal-BXEjuLPN.mjs";import{a as Ae,L as Me}from"../packem_shared/log-line-BWDt_F56.mjs";import{jsx as r,jsxs as E,Fragment as $e}from"react/jsx-runtime";import{c as H}from"../packem_shared/utils-bhneXptQ.mjs";import{L as Ue}from"../packem_shared/live-status-BuJdUZFU.mjs";import{ShardInput as Ke}from"../packem_shared/ShardInput-C6mjgAh4.mjs";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 se}from"../packem_shared/error-alert-D-ftqyo-.mjs";import{B as oe}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as g}from"../packem_shared/button-q0UYSmrn.mjs";import{E as ie}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as ne}from"../packem_shared/input-CXhxesPC.mjs";import{S as le}from"../packem_shared/scroll-area-CXCQH7VT.mjs";import{Separator as de}from"@base-ui/react/separator";import{c as ce}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as t,jsxs as n,Fragment as me}from"react/jsx-runtime";import{useT as ue}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{c as ae,d as X,b as Z,f as ee,g as he,h as te}from"../packem_shared/internal-BXEjuLPN.mjs";import{c as pe}from"react/compiler-runtime";import{useLunora as fe}from"@lunora/react";import{useState as F}from"react";import{u as xe}from"../packem_shared/use-admin-query-I1uILsUP.mjs";import{useAutoRefresh as be}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DvhNw0BI.mjs";import{ADMIN_FUNCTIONS as J}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";function ge({className:r,orientation:e="horizontal",...o}){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),...o})}const ve=/https?:\/\/[^\s"'<>)]+/i,re=r=>r===void 0?void 0:ve.exec(r)?.[0],v=r=>r===void 0?"":Array.isArray(r)?r.join(", "):r,Ne=/<a\s(?:[^>]*?\s)?href\s*=\s*["'](https?:\/\/[^"'\s]+)["']/iu,we=/&(?:amp|#0*38|#x0*26);/giu,ye=r=>r===void 0?void 0:((r.html===void 0?void 0:Ne.exec(r.html)?.[1])??re(r.text)??re(r.html))?.replaceAll(we,"&"),Ce=(r,e)=>{const o=e.trim().toLowerCase();return o===""?r:r.filter(i=>`${i.subject} ${v(i.to)} ${v(i.cc)}`.toLowerCase().includes(o))},Se=(r,e)=>{if(r.length!==0)return r.find(o=>o.id===e)??r[0]},Te=ae(J.clearCapturedMail),ke=ae(J.sendTestMail),Ae=r=>{const e=pe(36),{limit:o}=r,i=fe();let p;e[0]!==o?(p={limit:o},e[0]=o,e[1]=p):p=e[1];const{data:P,error:N,errorSource:w,isLoading:b,poll:R,refetch:m}=xe(J.getCapturedMail,p),[y,f]=F(null),[O,C]=F(null),[s,h]=F("html"),[x,H]=F(""),a=P?.entries??[],u=N??y,B=N===null?y:w;let S;e[2]!==i||e[3]!==m?(S=async()=>{f(null);try{await i.query(Te,{},X("")),C(null),m()}catch(d){f(Z(d))}},e[2]=i,e[3]=m,e[4]=S):S=e[4];const D=S;let T;e[5]!==i||e[6]!==m?(T=async()=>{f(null);try{await i.query(ke,{},X("")),m()}catch(d){f(Z(d))}},e[5]=i,e[6]=m,e[7]=T):T=e[7];const q=T;be(R,!0);let k;e[8]!==D?(k=()=>{ee(D())},e[8]=D,e[9]=k):k=e[9];const U=k;let A;e[10]!==q?(A=()=>{ee(q())},e[10]=q,e[11]=A):A=e[11];const W=A;let E;e[12]===Symbol.for("react.memo_cache_sentinel")?(E=d=>{H(d.currentTarget.value)},e[12]=E):E=e[12];const K=E;let L;e[13]===Symbol.for("react.memo_cache_sentinel")?(L=d=>{const{id:c}=d.currentTarget.dataset;c!==void 0&&C(c)},e[13]=L):L=e[13];const Q=L;let _;e[14]===Symbol.for("react.memo_cache_sentinel")?(_=d=>{const c=d.currentTarget.dataset.tab;(c==="headers"||c==="html"||c==="text")&&h(c)},e[14]=_):_=e[14];const V=_,M=Ce(a,x),I=Se(M,O),l=ye(I);let j;e[15]!==l?(j=()=>{l!==void 0&&he(l)},e[15]=l,e[16]=j):j=e[16];const Y=j;let $;e[17]!==l?($=()=>{l!==void 0&&"window"in globalThis&&globalThis.window.open(l,"_blank","noopener")},e[17]=l,e[18]=$):$=e[18];const G=$;let z;return e[19]!==a||e[20]!==u||e[21]!==B||e[22]!==x||e[23]!==b||e[24]!==l||e[25]!==U||e[26]!==Y||e[27]!==K||e[28]!==G||e[29]!==Q||e[30]!==V||e[31]!==W||e[32]!==I||e[33]!==s||e[34]!==M?(z={entries:a,error:u,errorSource:B,filter:x,isLoading:b,link:l,onClear:U,onCopyLink:Y,onFilterChange:K,onOpenLink:G,onSelectMessage:Q,onSelectTab:V,onSendTest:W,selected:I,tab:s,visible:M},e[19]=a,e[20]=u,e[21]=B,e[22]=x,e[23]=b,e[24]=l,e[25]=U,e[26]=Y,e[27]=K,e[28]=G,e[29]=Q,e[30]=V,e[31]=W,e[32]=I,e[33]=s,e[34]=M,e[35]=z):z=e[35],z},Ee=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,Le=r=>`${Ee}${r}`,Qe=({limit:r=100})=>{const e=ue(),{entries:o,error:i,errorSource:p,filter:P,isLoading:N,link:w,onClear:b,onCopyLink:R,onFilterChange:m,onOpenLink:y,onSelectMessage:f,onSelectTab:O,onSendTest:C,selected:s,tab:h,visible:x}=Ae({limit:r}),H=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(g,{"data-testid":"mail-send-test",onClick:C,size:"sm",type:"button",variant:"outline",children:e("Send test")}),t(g,{"data-testid":"mail-clear",disabled:o.length===0,onClick:b,size:"sm",type:"button",variant:"outline",children:e("Clear inbox")}),o.length>0&&t(oe,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:e("{count} messages",{count:o.length})})]}),i!==null&&t(se,{error:p,testId:"mail-error"}),i===null&&!N&&o.length===0&&t(ie,{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.")}),o.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:m,placeholder:e("Filter messages"),type:"search",value:P}),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:x.map(a=>{const u=a.id===s?.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 ${u?"bg-muted":""}`,"data-active":u,"data-id":a.id,"data-testid":"mail-list-item",onClick:f,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:v(a.to)}),t("span",{className:"text-xs text-muted-foreground tabular-nums",children:te(a.capturedAt,"—")})]})},a.id)})})})]}),s!==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:s.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:s.from??"—"}),t("dt",{children:e("To")}),t("dd",{className:"truncate font-mono",children:v(s.to)}),s.cc!==void 0&&s.cc.length>0&&n(me,{children:[t("dt",{children:e("Cc")}),t("dd",{className:"truncate font-mono",children:v(s.cc)})]}),t("dt",{children:e("Sent")}),t("dd",{className:"tabular-nums",children:te(s.capturedAt,"—")})]})]}),n("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[t(g,{"data-testid":"mail-copy-link",disabled:w===void 0,onClick:R,size:"sm",type:"button",variant:"outline",children:e("Copy link")}),t(g,{"data-testid":"mail-open-link",disabled:w===void 0,onClick:y,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(g,{"aria-selected":h===a,"data-tab":a,"data-testid":`mail-tab-${a}`,onClick:O,role:"tab",size:"sm",type:"button",variant:h===a?"secondary":"ghost",children:H(a)},a))}),n("div",{className:"min-h-[12rem]",children:[h==="html"&&(s.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(s.html),title:e("Email preview")})),h==="text"&&(s.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:s.text})),h==="headers"&&(s.headers===void 0||Object.keys(s.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(s.headers).map(([a,u])=>`${a}: ${u}`).join(`
1
+ import{E as se}from"../packem_shared/error-alert-CNQjdAhi.mjs";import{B as oe}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as g}from"../packem_shared/button-q0UYSmrn.mjs";import{E as ie}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as ne}from"../packem_shared/input-CXhxesPC.mjs";import{S as le}from"../packem_shared/scroll-area-CXCQH7VT.mjs";import{Separator as de}from"@base-ui/react/separator";import{c as ce}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as t,jsxs as n,Fragment as me}from"react/jsx-runtime";import{useT as ue}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{c as ae,d as X,b as Z,f as ee,g as he,h as te}from"../packem_shared/internal-BXEjuLPN.mjs";import{c as pe}from"react/compiler-runtime";import{useLunora as fe}from"@lunora/react";import{useState as F}from"react";import{u as xe}from"../packem_shared/use-admin-query-CLStXJ7v.mjs";import{useAutoRefresh as be}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DvhNw0BI.mjs";import{ADMIN_FUNCTIONS as J}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";function ge({className:r,orientation:e="horizontal",...o}){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),...o})}const ve=/https?:\/\/[^\s"'<>)]+/i,re=r=>r===void 0?void 0:ve.exec(r)?.[0],v=r=>r===void 0?"":Array.isArray(r)?r.join(", "):r,Ne=/<a\s(?:[^>]*?\s)?href\s*=\s*["'](https?:\/\/[^"'\s]+)["']/iu,we=/&(?:amp|#0*38|#x0*26);/giu,ye=r=>r===void 0?void 0:((r.html===void 0?void 0:Ne.exec(r.html)?.[1])??re(r.text)??re(r.html))?.replaceAll(we,"&"),Ce=(r,e)=>{const o=e.trim().toLowerCase();return o===""?r:r.filter(i=>`${i.subject} ${v(i.to)} ${v(i.cc)}`.toLowerCase().includes(o))},Se=(r,e)=>{if(r.length!==0)return r.find(o=>o.id===e)??r[0]},Te=ae(J.clearCapturedMail),ke=ae(J.sendTestMail),Ae=r=>{const e=pe(36),{limit:o}=r,i=fe();let p;e[0]!==o?(p={limit:o},e[0]=o,e[1]=p):p=e[1];const{data:P,error:N,errorSource:w,isLoading:b,poll:R,refetch:m}=xe(J.getCapturedMail,p),[y,f]=F(null),[O,C]=F(null),[s,h]=F("html"),[x,H]=F(""),a=P?.entries??[],u=N??y,B=N===null?y:w;let S;e[2]!==i||e[3]!==m?(S=async()=>{f(null);try{await i.query(Te,{},X("")),C(null),m()}catch(d){f(Z(d))}},e[2]=i,e[3]=m,e[4]=S):S=e[4];const D=S;let T;e[5]!==i||e[6]!==m?(T=async()=>{f(null);try{await i.query(ke,{},X("")),m()}catch(d){f(Z(d))}},e[5]=i,e[6]=m,e[7]=T):T=e[7];const q=T;be(R,!0);let k;e[8]!==D?(k=()=>{ee(D())},e[8]=D,e[9]=k):k=e[9];const U=k;let A;e[10]!==q?(A=()=>{ee(q())},e[10]=q,e[11]=A):A=e[11];const W=A;let E;e[12]===Symbol.for("react.memo_cache_sentinel")?(E=d=>{H(d.currentTarget.value)},e[12]=E):E=e[12];const K=E;let L;e[13]===Symbol.for("react.memo_cache_sentinel")?(L=d=>{const{id:c}=d.currentTarget.dataset;c!==void 0&&C(c)},e[13]=L):L=e[13];const Q=L;let _;e[14]===Symbol.for("react.memo_cache_sentinel")?(_=d=>{const c=d.currentTarget.dataset.tab;(c==="headers"||c==="html"||c==="text")&&h(c)},e[14]=_):_=e[14];const V=_,M=Ce(a,x),I=Se(M,O),l=ye(I);let j;e[15]!==l?(j=()=>{l!==void 0&&he(l)},e[15]=l,e[16]=j):j=e[16];const Y=j;let $;e[17]!==l?($=()=>{l!==void 0&&"window"in globalThis&&globalThis.window.open(l,"_blank","noopener")},e[17]=l,e[18]=$):$=e[18];const G=$;let z;return e[19]!==a||e[20]!==u||e[21]!==B||e[22]!==x||e[23]!==b||e[24]!==l||e[25]!==U||e[26]!==Y||e[27]!==K||e[28]!==G||e[29]!==Q||e[30]!==V||e[31]!==W||e[32]!==I||e[33]!==s||e[34]!==M?(z={entries:a,error:u,errorSource:B,filter:x,isLoading:b,link:l,onClear:U,onCopyLink:Y,onFilterChange:K,onOpenLink:G,onSelectMessage:Q,onSelectTab:V,onSendTest:W,selected:I,tab:s,visible:M},e[19]=a,e[20]=u,e[21]=B,e[22]=x,e[23]=b,e[24]=l,e[25]=U,e[26]=Y,e[27]=K,e[28]=G,e[29]=Q,e[30]=V,e[31]=W,e[32]=I,e[33]=s,e[34]=M,e[35]=z):z=e[35],z},Ee=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,Le=r=>`${Ee}${r}`,Qe=({limit:r=100})=>{const e=ue(),{entries:o,error:i,errorSource:p,filter:P,isLoading:N,link:w,onClear:b,onCopyLink:R,onFilterChange:m,onOpenLink:y,onSelectMessage:f,onSelectTab:O,onSendTest:C,selected:s,tab:h,visible:x}=Ae({limit:r}),H=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(g,{"data-testid":"mail-send-test",onClick:C,size:"sm",type:"button",variant:"outline",children:e("Send test")}),t(g,{"data-testid":"mail-clear",disabled:o.length===0,onClick:b,size:"sm",type:"button",variant:"outline",children:e("Clear inbox")}),o.length>0&&t(oe,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:e("{count} messages",{count:o.length})})]}),i!==null&&t(se,{error:p,testId:"mail-error"}),i===null&&!N&&o.length===0&&t(ie,{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.")}),o.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:m,placeholder:e("Filter messages"),type:"search",value:P}),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:x.map(a=>{const u=a.id===s?.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 ${u?"bg-muted":""}`,"data-active":u,"data-id":a.id,"data-testid":"mail-list-item",onClick:f,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:v(a.to)}),t("span",{className:"text-xs text-muted-foreground tabular-nums",children:te(a.capturedAt,"—")})]})},a.id)})})})]}),s!==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:s.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:s.from??"—"}),t("dt",{children:e("To")}),t("dd",{className:"truncate font-mono",children:v(s.to)}),s.cc!==void 0&&s.cc.length>0&&n(me,{children:[t("dt",{children:e("Cc")}),t("dd",{className:"truncate font-mono",children:v(s.cc)})]}),t("dt",{children:e("Sent")}),t("dd",{className:"tabular-nums",children:te(s.capturedAt,"—")})]})]}),n("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[t(g,{"data-testid":"mail-copy-link",disabled:w===void 0,onClick:R,size:"sm",type:"button",variant:"outline",children:e("Copy link")}),t(g,{"data-testid":"mail-open-link",disabled:w===void 0,onClick:y,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(g,{"aria-selected":h===a,"data-tab":a,"data-testid":`mail-tab-${a}`,onClick:O,role:"tab",size:"sm",type:"button",variant:h===a?"secondary":"ghost",children:H(a)},a))}),n("div",{className:"min-h-[12rem]",children:[h==="html"&&(s.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(s.html),title:e("Email preview")})),h==="text"&&(s.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:s.text})),h==="headers"&&(s.headers===void 0||Object.keys(s.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(s.headers).map(([a,u])=>`${a}: ${u}`).join(`
2
2
  `)}))]})]})]})]})};export{Qe as MailPanel};