@lunora/studio 1.0.0-alpha.350 → 1.0.0-alpha.351

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 (125) hide show
  1. package/dist/index.d.mts +4 -1
  2. package/dist/index.d.ts +4 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/mount.mjs +1 -1
  5. package/dist/packem_chunks/AdvisorHealthPanel.mjs +1 -1
  6. package/dist/packem_chunks/ApiTab.mjs +1 -1
  7. package/dist/packem_chunks/AuditPanel.mjs +1 -1
  8. package/dist/packem_chunks/ExportImportPanel.mjs +8 -8
  9. package/dist/packem_chunks/FileBrowser.mjs +1 -1
  10. package/dist/packem_chunks/FunctionRunner.mjs +1 -1
  11. package/dist/packem_chunks/FunctionStatsPanel.mjs +1 -1
  12. package/dist/packem_chunks/HealthPanel.mjs +1 -1
  13. package/dist/packem_chunks/InsightsPanel.mjs +1 -1
  14. package/dist/packem_chunks/LogsPanel.mjs +1 -1
  15. package/dist/packem_chunks/MailPanel.mjs +1 -1
  16. package/dist/packem_chunks/MetricsPanel.mjs +1 -1
  17. package/dist/packem_chunks/NotificationsPanel.mjs +1 -1
  18. package/dist/packem_chunks/PitrPanel.mjs +1 -1
  19. package/dist/packem_chunks/SchemaViewer.mjs +1 -1
  20. package/dist/packem_chunks/SecurityAdvisorPanel.mjs +1 -1
  21. package/dist/packem_chunks/SettingsPanel.mjs +1 -1
  22. package/dist/packem_chunks/SqlEditorPanel.mjs +1 -1
  23. package/dist/packem_chunks/TableEditor.mjs +1 -1
  24. package/dist/packem_chunks/agents-panel.mjs +1 -1
  25. package/dist/packem_chunks/ai-usage-panel.mjs +1 -1
  26. package/dist/packem_chunks/auth-audit-panel.mjs +1 -1
  27. package/dist/packem_chunks/containers-panel.mjs +1 -1
  28. package/dist/packem_chunks/dashboards-panel.mjs +1 -1
  29. package/dist/packem_chunks/evals-panel.mjs +1 -1
  30. package/dist/packem_chunks/fanout-panel.mjs +1 -1
  31. package/dist/packem_chunks/flags-panel.mjs +1 -1
  32. package/dist/packem_chunks/issues-panel.mjs +1 -1
  33. package/dist/packem_chunks/kv-browser.mjs +1 -1
  34. package/dist/packem_chunks/migrations-route.mjs +1 -1
  35. package/dist/packem_chunks/payments-panel.mjs +1 -1
  36. package/dist/packem_chunks/permissions-panel.mjs +1 -1
  37. package/dist/packem_chunks/queues-panel.mjs +1 -1
  38. package/dist/packem_chunks/reactors-panel.mjs +1 -1
  39. package/dist/packem_chunks/rls-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/traces-panel.mjs +1 -1
  43. package/dist/packem_chunks/workflows-panel.mjs +1 -1
  44. package/dist/packem_shared/{ADMIN_FUNCTIONS-B8yyk5BX.mjs → ADMIN_FUNCTIONS-4aGsMs95.mjs} +1 -1
  45. package/dist/packem_shared/{ApiDocsPanel-B_RaW7Br.mjs → ApiDocsPanel-E4Vr-8zW.mjs} +1 -1
  46. package/dist/packem_shared/{DataBrowser-Cc1qZX-4.mjs → DataBrowser-C5HbI4TH.mjs} +1 -1
  47. package/dist/packem_shared/{GlobalDataBrowser-Hq6gTlkb.mjs → GlobalDataBrowser-D0H2yJSl.mjs} +1 -1
  48. package/dist/packem_shared/{HomePanel-DeyYLVxc.mjs → HomePanel-CcYkDlR-.mjs} +1 -1
  49. package/dist/packem_shared/{MigrationsPanel-CMZYYcQ5.mjs → MigrationsPanel-YyCO_T-3.mjs} +1 -1
  50. package/dist/packem_shared/{Studio-BhTqTeGb.mjs → Studio-4vJzwwNa.mjs} +1 -1
  51. package/dist/packem_shared/{StudioApp-B1d0beD4.mjs → StudioApp-px2FMPDS.mjs} +1 -1
  52. package/dist/packem_shared/{home-panel-0XMGe1hP.mjs → home-panel-DPiMVQZ2.mjs} +1 -1
  53. package/dist/packem_shared/{studio-CA3ZKwVK.mjs → studio-DIUgH7k0.mjs} +1 -1
  54. package/dist/packem_shared/{table-list-sidebar-nA7g7uSk.mjs → table-list-sidebar-CCRB_iYz.mjs} +1 -1
  55. package/dist/packem_shared/{use-sql-assistant-DXnqbBs-.mjs → use-sql-assistant-BMVlguKF.mjs} +1 -1
  56. package/dist/standalone/{chunk-WQGT24W6.js → chunk-22O2JDWR.js} +1 -1
  57. package/dist/standalone/{chunk-RXVXXRYD.js → chunk-2DV455PX.js} +1 -1
  58. package/dist/standalone/{chunk-B7MHW3A5.js → chunk-2EMNPL3B.js} +1 -1
  59. package/dist/standalone/{chunk-LOV52GLG.js → chunk-35BGGOWV.js} +1 -1
  60. package/dist/standalone/{chunk-BTRYFPZH.js → chunk-3MQ477EE.js} +1 -1
  61. package/dist/standalone/{chunk-XWEDIIIT.js → chunk-453GHHZ4.js} +1 -1
  62. package/dist/standalone/{chunk-QAQVT4FS.js → chunk-4CITH2NU.js} +1 -1
  63. package/dist/standalone/{chunk-E32FS6PE.js → chunk-4EDOPHLM.js} +1 -1
  64. package/dist/standalone/{chunk-EDGOSJXL.js → chunk-4QRVJDM4.js} +1 -1
  65. package/dist/standalone/{chunk-B3AXFXAD.js → chunk-4UWYDYM5.js} +1 -1
  66. package/dist/standalone/{chunk-SXD6JQXF.js → chunk-57ZNR6IA.js} +1 -1
  67. package/dist/standalone/{chunk-R3KLR5EP.js → chunk-6DYXTEU7.js} +1 -1
  68. package/dist/standalone/chunk-6GPEHYCG.js +1 -0
  69. package/dist/standalone/{chunk-E3VSRIQU.js → chunk-6GRI2HXU.js} +1 -1
  70. package/dist/standalone/{chunk-7F3S5OQT.js → chunk-6QBK3Z7A.js} +1 -1
  71. package/dist/standalone/{chunk-4ZEL6BYL.js → chunk-6UTZXEW3.js} +1 -1
  72. package/dist/standalone/{chunk-CGZVMM3P.js → chunk-7EAHHRJR.js} +1 -1
  73. package/dist/standalone/{chunk-HOPAJ5F6.js → chunk-ACNWZIAH.js} +1 -1
  74. package/dist/standalone/{chunk-5J32EGHF.js → chunk-ANACHJRU.js} +1 -1
  75. package/dist/standalone/chunk-BAGJYLSU.js +8 -0
  76. package/dist/standalone/{chunk-HLAAOW33.js → chunk-BCOOULSO.js} +1 -1
  77. package/dist/standalone/{chunk-ZMQ6PKLN.js → chunk-BKH2NALB.js} +1 -1
  78. package/dist/standalone/{chunk-ZBFWT34B.js → chunk-BTOOJXUL.js} +1 -1
  79. package/dist/standalone/{chunk-2EL4EMYZ.js → chunk-C6FNBKCO.js} +1 -1
  80. package/dist/standalone/{chunk-OECMBE6Q.js → chunk-DSTNWB4N.js} +1 -1
  81. package/dist/standalone/{chunk-WIET27J3.js → chunk-DTW4E5AB.js} +1 -1
  82. package/dist/standalone/{chunk-VB6YJKPA.js → chunk-FNWRS4VQ.js} +1 -1
  83. package/dist/standalone/{chunk-UTX6IBA3.js → chunk-FST24UXA.js} +1 -1
  84. package/dist/standalone/{chunk-ZTOXQK4V.js → chunk-FXGYX2V6.js} +1 -1
  85. package/dist/standalone/{chunk-MFNO5BFR.js → chunk-HWTX54JM.js} +1 -1
  86. package/dist/standalone/{chunk-26OKWFLO.js → chunk-HZCLLEWP.js} +1 -1
  87. package/dist/standalone/{chunk-7AZYREIY.js → chunk-IRCUXARN.js} +1 -1
  88. package/dist/standalone/{chunk-W7Z35E2E.js → chunk-IVQKQBKK.js} +1 -1
  89. package/dist/standalone/{chunk-W2XSKODB.js → chunk-K7FZTYAY.js} +1 -1
  90. package/dist/standalone/{chunk-5NZWQEEJ.js → chunk-KNX3KB7E.js} +1 -1
  91. package/dist/standalone/{chunk-MMJTKSHL.js → chunk-LYHEBMM6.js} +1 -1
  92. package/dist/standalone/{chunk-BVKQA5OL.js → chunk-M2RIGPGL.js} +1 -1
  93. package/dist/standalone/{chunk-EOR73TZZ.js → chunk-MKVZXGJQ.js} +1 -1
  94. package/dist/standalone/chunk-OIDFWEJX.js +21 -0
  95. package/dist/standalone/{chunk-CLINNLLE.js → chunk-OJG65AG4.js} +1 -1
  96. package/dist/standalone/{chunk-XMEVNOCA.js → chunk-Q4N3TJPV.js} +1 -1
  97. package/dist/standalone/{chunk-NVHHB5EV.js → chunk-QEVFVWGC.js} +1 -1
  98. package/dist/standalone/{chunk-JAHK7RRJ.js → chunk-RHOQJNDW.js} +1 -1
  99. package/dist/standalone/{chunk-7MN724WR.js → chunk-RQDSPVVH.js} +1 -1
  100. package/dist/standalone/{chunk-P5GAJKDW.js → chunk-S5S2YICJ.js} +1 -1
  101. package/dist/standalone/{chunk-ZZAJHNZ6.js → chunk-S6JFSLBK.js} +1 -1
  102. package/dist/standalone/{chunk-GMW2DYFU.js → chunk-SDTHCM5H.js} +1 -1
  103. package/dist/standalone/{chunk-JG2C7SS2.js → chunk-SM2IQWCJ.js} +1 -1
  104. package/dist/standalone/{chunk-GPOSJNMV.js → chunk-T2QAOXUO.js} +1 -1
  105. package/dist/standalone/{chunk-2WNL74MI.js → chunk-T4VAXHRL.js} +1 -1
  106. package/dist/standalone/{chunk-FPIUVV7Q.js → chunk-TBDJVYCB.js} +1 -1
  107. package/dist/standalone/{chunk-HFYFYNSX.js → chunk-TTD7BKB6.js} +1 -1
  108. package/dist/standalone/{chunk-KFNDET5D.js → chunk-UCK6ITED.js} +1 -1
  109. package/dist/standalone/{chunk-UZIBQZ2F.js → chunk-UKKZJRJT.js} +1 -1
  110. package/dist/standalone/{chunk-F5LTDUMB.js → chunk-V74BXQXC.js} +1 -1
  111. package/dist/standalone/{chunk-2ZO7XY3Z.js → chunk-VHMA6YPT.js} +1 -1
  112. package/dist/standalone/{chunk-SOO2HXV6.js → chunk-W4X4J7BU.js} +1 -1
  113. package/dist/standalone/{chunk-S7XAAH7U.js → chunk-W6ZKEW5M.js} +1 -1
  114. package/dist/standalone/{chunk-D7JK65OK.js → chunk-WIYDA4XT.js} +1 -1
  115. package/dist/standalone/{chunk-2X6O33OX.js → chunk-X7GSROPX.js} +1 -1
  116. package/dist/standalone/{chunk-O3FDK56W.js → chunk-Y7SN6CTX.js} +1 -1
  117. package/dist/standalone/{chunk-JGMQQ3S7.js → chunk-YRQHFMEY.js} +1 -1
  118. package/dist/standalone/{chunk-YJ2WHOGO.js → chunk-ZKPRORLI.js} +1 -1
  119. package/dist/standalone/{chunk-TWMS2TMF.js → chunk-ZLSNET6H.js} +1 -1
  120. package/dist/standalone/{chunk-CIVMATZK.js → chunk-ZM4K2ETZ.js} +1 -1
  121. package/dist/standalone/studio.js +1 -1
  122. package/package.json +5 -5
  123. package/dist/standalone/chunk-BHOLL76W.js +0 -8
  124. package/dist/standalone/chunk-GQYA5W5T.js +0 -1
  125. package/dist/standalone/chunk-U76DVXTR.js +0 -21
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{StudioApp as r}from"./packem_shared/StudioApp-B1d0beD4.mjs";import{CommandPalette as a,openCommandPalette as f}from"./packem_shared/CommandPalette-5OsK8PNe.mjs";import{S as m}from"./packem_shared/studio-CA3ZKwVK.mjs";import{ConfirmButton as l}from"./packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{default as s}from"./packem_shared/ConnectionBadge-BfcoN-VE.mjs";import{ErrorBoundary as d}from"./packem_shared/ErrorBoundary-BWNF98VF.mjs";import{ShardInput as P}from"./packem_shared/ShardInput-CoySruKZ.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-B_RaW7Br.mjs";import{default as C}from"./packem_shared/ApiReferencePanel-u9Rrljdf.mjs";import{default as O}from"./packem_chunks/ApiTab.mjs";import{default as N}from"./packem_shared/OpenRpcReferencePanel-E9cDfHRv.mjs";import{DataBrowser as U}from"./packem_shared/DataBrowser-Cc1qZX-4.mjs";import{DataFilters as b,toFilterClauses as v}from"./packem_shared/DataFilters--ocFTVT2.mjs";import{GlobalDataBrowser as y}from"./packem_shared/GlobalDataBrowser-Hq6gTlkb.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-CMZYYcQ5.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-0XMGe1hP.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-D4CUj7aX.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-CG7Q45ZS.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-BQ3jRT74.mjs";import{StudioI18nProvider as we}from"./packem_shared/StudioI18nProvider-CGXCPnQn.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-px2FMPDS.mjs";import{CommandPalette as a,openCommandPalette as f}from"./packem_shared/CommandPalette-5OsK8PNe.mjs";import{S as m}from"./packem_shared/studio-DIUgH7k0.mjs";import{ConfirmButton as l}from"./packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{default as s}from"./packem_shared/ConnectionBadge-BfcoN-VE.mjs";import{ErrorBoundary as d}from"./packem_shared/ErrorBoundary-BWNF98VF.mjs";import{ShardInput as P}from"./packem_shared/ShardInput-CoySruKZ.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-E4Vr-8zW.mjs";import{default as C}from"./packem_shared/ApiReferencePanel-u9Rrljdf.mjs";import{default as O}from"./packem_chunks/ApiTab.mjs";import{default as N}from"./packem_shared/OpenRpcReferencePanel-E9cDfHRv.mjs";import{DataBrowser as U}from"./packem_shared/DataBrowser-C5HbI4TH.mjs";import{DataFilters as b,toFilterClauses as v}from"./packem_shared/DataFilters--ocFTVT2.mjs";import{GlobalDataBrowser as y}from"./packem_shared/GlobalDataBrowser-D0H2yJSl.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-YyCO_T-3.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-DPiMVQZ2.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-D4CUj7aX.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-CG7Q45ZS.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-BQ3jRT74.mjs";import{StudioI18nProvider as we}from"./packem_shared/StudioI18nProvider-CGXCPnQn.mjs";import{ADMIN_FUNCTIONS as Ge,ADMIN_FUNCTION_PREFIX as qe}from"./packem_shared/ADMIN_FUNCTIONS-4aGsMs95.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-B1d0beD4.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-px2FMPDS.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-54TiaMvZ.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-BW9IuacC.mjs";import{useT as C}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.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-54TiaMvZ.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-BW9IuacC.mjs";import{useT as C}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-4aGsMs95.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{c as L}from"react/compiler-runtime";import{useState as F}from"react";import{B as K}from"../packem_shared/button-q0UYSmrn.mjs";import{useT as Y}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import D from"../packem_shared/ApiDocsPanel-B_RaW7Br.mjs";import M from"../packem_shared/ApiReferencePanel-u9Rrljdf.mjs";import W from"../packem_shared/OpenRpcReferencePanel-E9cDfHRv.mjs";import{jsx as r,jsxs as E}from"react/jsx-runtime";const _=["reference","snippets"],q=["openapi","openrpc"],k=V=>{const e=L(51),{functions:R,initialShardKey:N,openApiSpec:T,openRpcSpec:I}=V,t=Y(),[i,$]=F("reference"),[a,j]=F("openapi");let s;e[0]!==t?(s=t("Reference"),e[0]=t,e[1]=s):s=e[1];let o;e[2]!==t?(o=t("Snippets"),e[2]=t,e[3]=o):o=e[3];let w;e[4]!==s||e[5]!==o?(w={reference:s,snippets:o},e[4]=s,e[5]=o,e[6]=w):w=e[6];const O=w;let n;e[7]!==t?(n=t("OpenAPI"),e[7]=t,e[8]=n):n=e[8];let c;e[9]!==t?(c=t("OpenRPC"),e[9]=t,e[10]=c):c=e[10];let g;e[11]!==n||e[12]!==c?(g={openapi:n,openrpc:c},e[11]=n,e[12]=c,e[13]=g):g=e[13];const C=g;let S;e[14]===Symbol.for("react.memo_cache_sentinel")?(S=l=>{$(l.currentTarget.dataset.view)},e[14]=S):S=e[14];const z=S;let A;e[15]===Symbol.for("react.memo_cache_sentinel")?(A=l=>{j(l.currentTarget.dataset.format)},e[15]=A):A=e[15];const B=A;let p;e[16]!==t?(p=t("API view"),e[16]=t,e[17]=p):p=e[17];let f;e[18]!==i||e[19]!==O?(f=_.map(l=>r(K,{"aria-selected":i===l,"data-testid":`api-view-${l}`,"data-view":l,onClick:z,role:"tab",size:"sm",type:"button",variant:i===l?"default":"outline",children:O[l]},l)),e[18]=i,e[19]=O,e[20]=f):f=e[20];let m;e[21]!==f||e[22]!==p?(m=r("div",{"aria-label":p,className:"flex gap-1.5","data-testid":"api-view-toggle",role:"tablist",children:f}),e[21]=f,e[22]=p,e[23]=m):m=e[23];let d;e[24]!==a||e[25]!==C||e[26]!==t||e[27]!==i?(d=i==="reference"&&r("div",{"aria-label":t("API spec format"),className:"flex gap-1.5","data-testid":"api-format-toggle",role:"tablist",children:q.map(l=>r(K,{"aria-selected":a===l,"data-format":l,"data-testid":`api-format-${l}`,onClick:B,role:"tab",size:"sm",type:"button",variant:a===l?"default":"outline",children:C[l]},l))}),e[24]=a,e[25]=C,e[26]=t,e[27]=i,e[28]=d):d=e[28];let b;e[29]!==m||e[30]!==d?(b=E("div",{className:"flex shrink-0 flex-wrap items-center gap-3 border-b border-border px-6 py-3",children:[m,d]}),e[29]=m,e[30]=d,e[31]=b):b=e[31];let v;e[32]!==R||e[33]!==N||e[34]!==i?(v=i==="snippets"&&r("div",{className:"min-h-0 flex-1 overflow-y-auto p-6",children:r(D,{functions:R,initialShardKey:N})}),e[32]=R,e[33]=N,e[34]=i,e[35]=v):v=e[35];let h;e[36]!==a||e[37]!==T||e[38]!==i?(h=i==="reference"&&a==="openapi"&&r(M,{spec:T}),e[36]=a,e[37]=T,e[38]=i,e[39]=h):h=e[39];let u;e[40]!==a||e[41]!==I||e[42]!==i?(u=i==="reference"&&a==="openrpc"&&r(W,{spec:I}),e[40]=a,e[41]=I,e[42]=i,e[43]=u):u=e[43];let x;e[44]!==v||e[45]!==h||e[46]!==u?(x=E("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[v,h,u]}),e[44]=v,e[45]=h,e[46]=u,e[47]=x):x=e[47];let P;return e[48]!==b||e[49]!==x?(P=E("div",{className:"flex min-h-0 flex-1 flex-col","data-testid":"lunora-api-tab",children:[b,x]}),e[48]=b,e[49]=x,e[50]=P):P=e[50],P};export{k as default};
1
+ import{c as L}from"react/compiler-runtime";import{useState as F}from"react";import{B as K}from"../packem_shared/button-q0UYSmrn.mjs";import{useT as Y}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import D from"../packem_shared/ApiDocsPanel-E4Vr-8zW.mjs";import M from"../packem_shared/ApiReferencePanel-u9Rrljdf.mjs";import W from"../packem_shared/OpenRpcReferencePanel-E9cDfHRv.mjs";import{jsx as r,jsxs as E}from"react/jsx-runtime";const _=["reference","snippets"],q=["openapi","openrpc"],k=V=>{const e=L(51),{functions:R,initialShardKey:N,openApiSpec:T,openRpcSpec:I}=V,t=Y(),[i,$]=F("reference"),[a,j]=F("openapi");let s;e[0]!==t?(s=t("Reference"),e[0]=t,e[1]=s):s=e[1];let o;e[2]!==t?(o=t("Snippets"),e[2]=t,e[3]=o):o=e[3];let w;e[4]!==s||e[5]!==o?(w={reference:s,snippets:o},e[4]=s,e[5]=o,e[6]=w):w=e[6];const O=w;let n;e[7]!==t?(n=t("OpenAPI"),e[7]=t,e[8]=n):n=e[8];let c;e[9]!==t?(c=t("OpenRPC"),e[9]=t,e[10]=c):c=e[10];let g;e[11]!==n||e[12]!==c?(g={openapi:n,openrpc:c},e[11]=n,e[12]=c,e[13]=g):g=e[13];const C=g;let S;e[14]===Symbol.for("react.memo_cache_sentinel")?(S=l=>{$(l.currentTarget.dataset.view)},e[14]=S):S=e[14];const z=S;let A;e[15]===Symbol.for("react.memo_cache_sentinel")?(A=l=>{j(l.currentTarget.dataset.format)},e[15]=A):A=e[15];const B=A;let p;e[16]!==t?(p=t("API view"),e[16]=t,e[17]=p):p=e[17];let f;e[18]!==i||e[19]!==O?(f=_.map(l=>r(K,{"aria-selected":i===l,"data-testid":`api-view-${l}`,"data-view":l,onClick:z,role:"tab",size:"sm",type:"button",variant:i===l?"default":"outline",children:O[l]},l)),e[18]=i,e[19]=O,e[20]=f):f=e[20];let m;e[21]!==f||e[22]!==p?(m=r("div",{"aria-label":p,className:"flex gap-1.5","data-testid":"api-view-toggle",role:"tablist",children:f}),e[21]=f,e[22]=p,e[23]=m):m=e[23];let d;e[24]!==a||e[25]!==C||e[26]!==t||e[27]!==i?(d=i==="reference"&&r("div",{"aria-label":t("API spec format"),className:"flex gap-1.5","data-testid":"api-format-toggle",role:"tablist",children:q.map(l=>r(K,{"aria-selected":a===l,"data-format":l,"data-testid":`api-format-${l}`,onClick:B,role:"tab",size:"sm",type:"button",variant:a===l?"default":"outline",children:C[l]},l))}),e[24]=a,e[25]=C,e[26]=t,e[27]=i,e[28]=d):d=e[28];let b;e[29]!==m||e[30]!==d?(b=E("div",{className:"flex shrink-0 flex-wrap items-center gap-3 border-b border-border px-6 py-3",children:[m,d]}),e[29]=m,e[30]=d,e[31]=b):b=e[31];let v;e[32]!==R||e[33]!==N||e[34]!==i?(v=i==="snippets"&&r("div",{className:"min-h-0 flex-1 overflow-y-auto p-6",children:r(D,{functions:R,initialShardKey:N})}),e[32]=R,e[33]=N,e[34]=i,e[35]=v):v=e[35];let h;e[36]!==a||e[37]!==T||e[38]!==i?(h=i==="reference"&&a==="openapi"&&r(M,{spec:T}),e[36]=a,e[37]=T,e[38]=i,e[39]=h):h=e[39];let u;e[40]!==a||e[41]!==I||e[42]!==i?(u=i==="reference"&&a==="openrpc"&&r(W,{spec:I}),e[40]=a,e[41]=I,e[42]=i,e[43]=u):u=e[43];let x;e[44]!==v||e[45]!==h||e[46]!==u?(x=E("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[v,h,u]}),e[44]=v,e[45]=h,e[46]=u,e[47]=x):x=e[47];let P;return e[48]!==b||e[49]!==x?(P=E("div",{className:"flex min-h-0 flex-1 flex-col","data-testid":"lunora-api-tab",children:[b,x]}),e[48]=b,e[49]=x,e[50]=P):P=e[50],P};export{k 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-54TiaMvZ.mjs";import{L as _}from"../packem_shared/live-status-D1GasNsH.mjs";import{ShardInput as j}from"../packem_shared/ShardInput-CoySruKZ.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-BW9IuacC.mjs";import{u as Z}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as X}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.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-54TiaMvZ.mjs";import{L as _}from"../packem_shared/live-status-D1GasNsH.mjs";import{ShardInput as j}from"../packem_shared/ShardInput-CoySruKZ.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-BW9IuacC.mjs";import{u as Z}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as X}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as Y}from"../packem_shared/ADMIN_FUNCTIONS-4aGsMs95.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,8 +1,8 @@
1
- import{c as xe}from"react/compiler-runtime";import{LunoraError as K}from"@lunora/errors";import{encodeWire as X,decodeWire as ve}from"@lunora/wire";import{useState as S}from"react";import{ConfirmButton as ye}from"../packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{ShardInput as be}from"../packem_shared/ShardInput-CoySruKZ.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 Ne,S as Ce,a as ke,b as Ee,d as Te}from"../packem_shared/select-DPyS18Vy.mjs";import{b as Ie,u as Se}from"../packem_shared/use-admin-query-BW9IuacC.mjs";import{u as Re}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as re}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as _}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{f as Z,d as O,b as L,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-2c5SaBtH.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",Fe=()=>{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=Fe();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}},Le=/^-?\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(!Le.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=ve(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:L(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):L(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}=Se(_.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(Ce,{placeholder:a}),e[8]=a,e[9]=u):u=e[9];let y;e[10]!==l||e[11]!==u?(y=m(ke,{"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(Ee,{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(Te,{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:L(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:L(f),nextLine:g,rows:h,unknownFrom:b.startLine,...N},total:i}}},$t=({initialShardKey:t})=>{const e=Re(),n=Ie(),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 F=await e.query(et,{},O(x));let v=new Blob([],{type:q}),I=0;const j=[];for(const{name:ge}of F){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(F){p(L(F))}},de=async(x,F)=>{u(!0),p(null),g(null),f(null);const{failure:v,total:I}=await xt(e,r,o,b,x,F);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(be,{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(ye,{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(Ne,{value:t.name,children:t.name},t.name)}export{$t as ExportImportPanel};
1
+ import{c as se}from"react/compiler-runtime";import{LunoraError as U}from"@lunora/errors";import{encodeWire as X,decodeWire as be}from"@lunora/wire";import{useState as I}from"react";import{ConfirmButton as Ne}from"../packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{ShardInput as Ce}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{B as Y}from"../packem_shared/button-q0UYSmrn.mjs";import{C as Z,a as z}from"../packem_shared/card-By2O8ULa.mjs";import{L as ke}from"../packem_shared/label-DKFzyHq6.mjs";import{c as Ee,S as Te,a as Ie,b as Se,d as Re}from"../packem_shared/select-DPyS18Vy.mjs";import{b as _e,u as Oe}from"../packem_shared/use-admin-query-BW9IuacC.mjs";import{u as Le}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as V}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as O}from"../packem_shared/ADMIN_FUNCTIONS-4aGsMs95.mjs";import{f as G,d as L,b as j,c as B}from"../packem_shared/internal-BXEjuLPN.mjs";import{r as Q}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{d as Fe}from"../packem_shared/grid-features-2c5SaBtH.mjs";import{jsxs as k,jsx as u}from"react/jsx-runtime";class _ extends Error{problem;constructor(e){super(e.kind),this.name="CsvFormatError",this.problem=e}}const je="\uFEFF",De=()=>{let t=[],e=1,n=!1,r=!1,o="start",s="";const i=()=>{t.push(o==="closing"||s!==""?s:void 0),o="start",s=""},l=a=>{i(),t.some(d=>d!==void 0)&&a.push({cells:t,number:e}),t=[],e+=1},c=(a,d)=>{const f=n;if(n=!1,!(f&&a===`
2
+ `)){if(o==="quoted"){a==='"'?o="closing":s+=a;return}if(o==="closing"&&a==='"'){s+=a,o="quoted";return}if(a===","){i();return}if(a==="\r"){l(d),n=!0;return}if(a===`
3
+ `){l(d);return}if(o==="closing")throw new _({kind:"text-after-quote",record:e});if(o==="start"&&a==='"'){o="quoted";return}o="unquoted",s+=a}};return{finish:()=>{if(o==="quoted")throw new _({kind:"unterminated-quote",record:e});const a=[];return l(a),a},push:a=>{const d=[];let f=0;for(!r&&a!==""&&(r=!0,f=a.startsWith(je)?1:0);f<a.length;f+=1)c(a.charAt(f),d);return d}}},ie=async function*(t){const e=De();for await(const n of t)yield*e.push(n);yield*e.finish()},$=(t,e,n)=>{Object.defineProperty(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0})},le=t=>{const e=[],n=new Set;return t.forEach((r,o)=>{const s=(r??"").trim();if(s==="")throw new _({column:o+1,kind:"empty-header"});if(n.has(s))throw new _({kind:"duplicate-header",name:s});n.add(s),e.push(s)}),e},ae=({cells:t,number:e},n,r)=>{if(t.length!==n.length)throw new _({expected:n.length,found:t.length,kind:"ragged",record:e});const o={};return n.forEach((s,i)=>{const l=t[i];l!==void 0?$(o,s,l):r.has(s)&&$(o,s,null)}),{doc:o,record:e}},Ae=/^-?\d+$/u,$e=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/iu,Be=/^-?\d{11,}$/u,Pe=/^(\d{4})-(\d{2})-(\d{2})$/u,Me=/^(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(Z|[+-]\d{2}:\d{2})?$/u,qe=/\.(\d+)/u,Ke=/[1-9]/u,Ue=/^[+-]?(\d*)(?:\.(\d*))?(?:e([+-]?\d+))?$/iu,ee=t=>{const[,e="",n="",r="0"]=Ue.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)}},Xe=(t,e)=>{const n=ee(t),r=ee(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))},Ve=t=>{const e=t.trim();if(!$e.test(e))return;const n=Number(e);if(Number.isFinite(n))return Xe(e,n)?{number:n}:{inexact:!0}},He=(t,e,n)=>{const r=new Date(0);return r.setUTCFullYear(t,e-1,n),r.getUTCMonth()===e-1&&r.getUTCDate()===n},We=(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),Je=t=>{const[e="",n,...r]=t.split("T"),o=Pe.exec(e),s=n===void 0?void 0:Me.exec(n);if(o===null||r.length>0||n!==void 0&&s===null)return;const[,i="",l="",c=""]=o;if(!He(Number(i),Number(l),Number(c)))return;const[,a="0",d="0",f="0",g]=s??[];if(!We(a,d,f,g??"Z"))return;const p=qe.exec(n??"")?.[1]??"";if(Ke.test(p.slice(3)))return;const x=Date.parse(s!==void 0&&g===void 0?`${t}Z`:t);return Number.isFinite(x)?x:void 0},Ye=t=>{const e=Ve(t);return e===void 0?{expected:"number",kind:"rejected"}:"number"in e?{kind:"ok",value:e.number}:{expected:"number",inexact:!0,kind:"rejected"}},Ze=t=>{const e=t.trim();let n=Je(e);return n===void 0&&Be.test(e)&&(n=Number(e)),n===void 0||!Number.isFinite(new Date(n).getTime())?{expected:"date",kind:"rejected"}:{kind:"ok",value:n}},ze=t=>{try{return X(t),!0}catch{return!1}},Ge=(t,e)=>{if(e==="bigint"){const n=t.trim();if(!Ae.test(n))return{expected:"bigint",kind:"rejected"};const r=BigInt(n);return ze(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"?Ye(t):e==="date"||e==="timestamp"?Ze(t):{kind:"ok",value:t}},ce=({doc:t,record:e},n)=>{const r={};for(const[o,s]of Object.entries(t)){if(s===null){$(r,o,null);continue}const i=Ge(s,n.get(o));if(i.kind==="rejected")throw new _({column:o,expected:i.expected,...i.inexact===!0&&{inexact:!0},kind:"cell-type",record:e,...i.tooLong===!0&&{tooLong:!0},value:s});$(r,o,i.value)}return{doc:r,record:e}},Qe=async function*(t,e,n){let r;for await(const o of ie(t))r===void 0?r=le(o.cells):yield ce(ae(o,r,n),e)},et=t=>new Set(t.filter(e=>e.nullable===!0&&!e.optional).map(e=>e.name)),te=t=>{if(t instanceof _)return t;throw t},tt=async(t,e,n,r)=>{let o,s,i;for await(const c of ie(t)){if(o===void 0){try{o=le(c.cells)}catch(d){s=te(d),o=[]}continue}let a;try{a=ce(ae(c,o,n),e)}catch(d){i??=te(d);continue}r(a)}const l=s??i;if(l!==void 0)throw l},nt=B(O.exportShard),q=B(O.importShard),rt=B(O.listTables),ot=B(O.describeTable),st={},it=t=>t.map(e=>JSON.stringify(X(e))).join(`
4
+ `),lt=(t,e)=>{const n=t.trim();if(n==="")return;const r=be(JSON.parse(n));if(typeof r!="object"||r===null)throw new U("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 U("INTERNAL",`line ${e.toString()}: expected a { table, doc } object`);return o},ne=1024*1024,H=async function*(t){const e=new TextDecoder("utf-8",{fatal:!0});for(let r=0;r<t.size;r+=ne){const o=await t.slice(r,r+ne).arrayBuffer();yield e.decode(o,{stream:!0})}const n=e.decode();n!==""&&(yield n)},at=async function*(t){let e="",n=0;for await(const r of H(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})},ct=async function*(t){for await(const{line:e,lineNumber:n}of at(t)){const r=lt(e,n);r!==void 0&&(yield{line:n,row:r})}},dt=async function*(t,e,n,r){for await(const{doc:o,record:s}of Qe(H(t),n,r))yield{line:s,row:{doc:o,table:e}}},ut=async(t,e,n,r)=>{try{const{columns:o}=await t.query(ot,{table:r},L(n));return{kinds:new Map(o.map(s=>[s.name,s.type])),nullOnEmpty:et(o)}}catch(o){return{failure:e("Couldn't read the columns of {table}: {message}",{message:j(o),table:r})}}},re=50,ft=500,P=9e5,W=t=>new TextEncoder().encode(JSON.stringify(X(t))).byteLength,K="application/x-ndjson",de=t=>new U("INTERNAL",`line ${t.toString()}: a single row is over the ${P.toString()}-byte import limit`),mt=async t=>{let e=0;for await(const{line:n,row:r}of t){if(W(r)>P)throw de(n);e+=1}return e},ht=async(t,e,n,r)=>{const o={rows:0};if(await tt(H(t),n,r,({doc:s,record:i})=>{o.rows+=1,o.wide===void 0&&W({doc:s,table:e})>P&&(o.wide=i)}),o.wide!==void 0)throw de(o.wide);return o.rows},oe=async(t,e)=>{let n=[],r=0,o=0,s=0;for await(const{line:i,row:l}of t){const c=W(l),a=i!==s+1;n.length>0&&(a||n.length===ft||r+c>P)&&(await e(n,o),n=[],r=0),n.length===0&&(o=i),n.push(l),r+=c,s=i}n.length>0&&await e(n,o)},pt=/\.csv$/iu,wt=t=>pt.test(t.name)||t.type==="text/csv",gt=(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}),xt=(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"?gt(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}),yt=(t,e,n)=>{const r=e instanceof _?xt(e.problem,n):j(e);return t===null?n("Invalid NDJSON: {message}",{message:r}):n("Invalid CSV: {message}",{message:r})},vt=t=>{const e=se(31),{onChange:n,shardKey:r,value:o}=t,s=V();let i;e[0]!==r?(i={shardKey:r},e[0]=r,e[1]=i):i=e[1];const{data:l}=Oe(O.listTables,st,i);let c;e[2]!==n?(c=m=>{n(m??"")},e[2]=n,e[3]=c):c=e[3];let a;e[4]!==s?(a=s("Target table"),e[4]=s,e[5]=a):a=e[5];let d;e[6]!==s?(d=s("Choose a table"),e[6]=s,e[7]=d):d=e[7];let f;e[8]!==d?(f=u(Te,{placeholder:d}),e[8]=d,e[9]=f):f=e[9];let g;e[10]!==a||e[11]!==f?(g=u(Ie,{"aria-label":a,className:"w-56","data-testid":"ei-csv-table",children:f}),e[10]=a,e[11]=f,e[12]=g):g=e[12];let p;e[13]!==l?(p=l??[],e[13]=l,e[14]=p):p=e[14];let x;e[15]!==p?(x=p.map(Ct),e[15]=p,e[16]=x):x=e[16];let w;e[17]!==x?(w=u(Se,{children:x}),e[17]=x,e[18]=w):w=e[18];let b;e[19]!==c||e[20]!==g||e[21]!==w||e[22]!==o?(b=k(Re,{onValueChange:c,value:o,children:[g,w]}),e[19]=c,e[20]=g,e[21]=w,e[22]=o,e[23]=b):b=e[23];let N;e[24]!==s?(N=s("CSV rows have no table column, so choose the table they go into."),e[24]=s,e[25]=N):N=e[25];let h;e[26]!==N?(h=u("p",{className:"text-xs text-muted-foreground",children:N}),e[26]=N,e[27]=h):h=e[27];let T;return e[28]!==b||e[29]!==h?(T=k("div",{className:"flex flex-col gap-1.5",children:[b,h]}),e[28]=b,e[29]=h,e[30]=T):T=e[30],T},ue=t=>Object.values(t).reduce((e,n)=>e+n,0),bt=async(t,e,n,r,o,s,i)=>{const l={conflicts:0,errors:[],inserted:{},replaced:0};let c;const a=s===null?{kinds:new Map,nullOnEmpty:new Set}:await ut(t,e,n,s);if("failure"in a)return{failure:{message:a.failure,rows:0},total:l};const{kinds:d,nullOnEmpty:f}=a;try{if(s===null){const m=()=>ct(o);c={rows:await mt(m()),source:m}}else c={rows:await ht(o,s,d,f),source:()=>dt(o,s,d,f)}}catch(m){return{failure:{message:yt(s,m,e),rows:0},total:l}}const{rows:g,source:p}=c;if(s!==null&&g===0)return{failure:{message:e("The CSV has no data rows after the header."),rows:0},total:l};const x={conflicts:0,errors:[],inserted:{}};r(e("Checking {total} rows before writing…",{total:g}));try{const m=await t.query(q,{dryRun:!0,onConflict:i,rows:[],startLine:1},L(n));if(m.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:l};if(i==="replace"&&typeof m.replaced!="number")return{failure:{message:e("This shard cannot overwrite existing rows. Nothing was sent. Update the app and import again."),rows:0},total:l};await oe(p(),async(S,v)=>{const E=await t.query(q,{dryRun:!0,onConflict:i,rows:S,startLine:v},L(n));x.errors.push(...E.errors)})}catch(m){return{failure:{message:j(m),rows:0},total:l}}if(x.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:x};let w=0,b=1;const N={},h={},T=async(m,S)=>{r(e("Importing rows {from}–{to} of {total}…",{from:w+1,to:w+m.length,total:g})),h.startLine=S;const v=await t.query(q,{dryRun:!1,onConflict:i,rows:m,startLine:S},L(n));h.startLine=void 0,l.conflicts+=v.conflicts,l.replaced=(l.replaced??0)+(v.replaced??0),l.errors.push(...v.errors);for(const[E,D]of Object.entries(v.inserted))l.inserted[E]=(l.inserted[E]??0)+D;if(w+=m.length,b=S+m.length,v.errors.length>0){const E=ue(l.inserted)+(l.replaced??0);throw N.refused=!0,new Error(E===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:v.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:v.errors.length,line:S+m.length,written:E}))}};try{return await oe(p(),T),{failure:void 0,total:l}}catch(m){return{failure:{message:j(m),nextLine:b,rows:w,unknownFrom:h.startLine,...N},total:l}}},Nt=t=>{const e=se(14),{result:n}=t,r=V();let o;e[0]!==n.conflicts||e[1]!==n.errors.length||e[2]!==n.inserted||e[3]!==n.replaced||e[4]!==r?(o=r("Inserted {inserted}, replaced {replaced}, {conflicts} conflicts, {errors} errors.",{conflicts:n.conflicts,errors:n.errors.length,inserted:ue(n.inserted),replaced:n.replaced??0}),e[0]=n.conflicts,e[1]=n.errors.length,e[2]=n.inserted,e[3]=n.replaced,e[4]=r,e[5]=o):o=e[5];let s;e[6]!==o?(s=u("p",{className:"text-sm text-muted-foreground",children:o}),e[6]=o,e[7]=s):s=e[7];let i;e[8]!==n.errors||e[9]!==r?(i=n.errors.length>0&&u("ul",{className:"flex flex-col gap-1","data-testid":"ei-import-errors",children:n.errors.map(c=>u("li",{className:"text-xs text-destructive",children:r("line {line} ({table}): {message}",{line:c.line,message:c.message,table:c.table})},`${c.table}-${c.line.toString()}`))}),e[8]=n.errors,e[9]=r,e[10]=i):i=e[10];let l;return e[11]!==s||e[12]!==i?(l=k("div",{className:"flex flex-col gap-2","data-testid":"ei-import-result",children:[s,i]}),e[11]=s,e[12]=i,e[13]=l):l=e[13],l},Kt=({initialShardKey:t})=>{const e=Le(),n=_e(),r=V(),[o,s]=I(t??""),[i,l]=I(null),[c,a]=I(null),[d,f]=I(!1),[g,p]=I(null),[x,w]=I(null),[b,N]=I(null),[h,T]=I(null),[m,S]=I(!1),v=i!==null&&wt(i),E=c!==null&&c.shardKey===o?c.table:"",D=i!==null&&(!v||E!==""),fe=async()=>{const C=o;f(!0),p(null),w(null),T(null);try{const F=await e.query(rt,{},L(C));let y=new Blob([],{type:K}),R=0;const A=[];for(const{name:ve}of F){const{rows:M}=await e.query(nt,{tables:[ve]},L(C));if(M.length===0)continue;const J=it(M);y=new Blob([y,`${J}
6
+ `],{type:K}),R+=M.length,A.length<re&&A.push(...J.split(`
7
+ `).slice(0,re-A.length))}Q(C),T({blob:y,count:R,preview:A.join(`
8
+ `),shardKey:C})}catch(F){p(j(F))}},me=async(C,F)=>{f(!0),p(null),w(null),T(null);const{failure:y,total:R}=await bt(e,r,o,N,C,F,m?"replace":"skip");y===void 0?(Q(o),w(R)):y.unknownFrom===void 0&&(y.refused===!0||y.rows===0)?(R.errors.length>0&&w(R),p(y.message)):y.unknownFrom===void 0?(w(R),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:y.nextLine,message:y.message,rows:y.rows}))):(w(R),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:y.unknownFrom,message:y.message,rows:y.rows}))),n(O.readTablePage),n(O.listTables)},he=()=>{G(fe().finally(()=>{f(!1)}))},pe=()=>{i!==null&&D&&G(me(i,v?E:null).finally(()=>{N(null),f(!1)}))},we=()=>{h!==null&&Fe(`${h.shardKey.trim()===""?"shard":h.shardKey.trim()}.ndjson`,h.blob,K)},ge=C=>{l(C.target.files?.[0]??null),a(null)},xe=C=>{a({shardKey:o,table:C})},ye=C=>{S(C.target.checked)};return k("div",{className:"flex flex-col gap-4","data-testid":"lunora-export-import",children:[k(Z,{className:"gap-0 py-0 rounded-xl border border-border bg-card shadow-xs",children:[u("header",{className:"border-b border-border px-4 py-3",children:u("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Export")})}),k(z,{className:"flex flex-col gap-3 p-4",children:[k("div",{className:"flex flex-wrap items-center gap-2",children:[u(Ce,{onChange:s,testId:"ei-shard-input",value:o}),u(Y,{"data-testid":"ei-export",disabled:d,onClick:he,type:"button",children:r("Export")})]}),h!==null&&k("div",{className:"flex flex-col gap-2",children:[k("div",{className:"flex flex-wrap items-center gap-2",children:[u("p",{className:"text-sm text-muted-foreground","data-testid":"ei-export-result",children:r("Exported {count} rows.",{count:h.count})}),u(Y,{"data-testid":"ei-download",onClick:we,size:"sm",type:"button",variant:"outline",children:r("Download")})]}),h.preview!==""&&u("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:h.preview})]})]})]}),k(Z,{className:"gap-0 py-0 rounded-xl border border-border bg-card shadow-xs",children:[u("header",{className:"border-b border-border px-4 py-3",children:u("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Import")})}),k(z,{className:"flex flex-col gap-3 p-4",children:[u("input",{accept:".ndjson,.jsonl,.csv,application/x-ndjson,text/csv","aria-label":r("Import file"),className:"text-sm","data-testid":"ei-file",onChange:ge,type:"file"}),v&&u(vt,{onChange:xe,shardKey:o,value:E}),k(ke,{className:"flex items-center gap-2 text-xs font-normal text-muted-foreground",htmlFor:"ei-replace",children:[u("input",{checked:m,className:"size-4 accent-primary","data-testid":"ei-replace",id:"ei-replace",onChange:ye,type:"checkbox"}),r("Overwrite rows whose _id already exists (otherwise they are left unchanged and counted as conflicts)")]}),u("div",{className:"flex flex-wrap items-center gap-2",children:u(Ne,{confirmLabel:r("Import (writes rows)?"),disabled:d||!D,onConfirm:pe,testId:"ei-import",children:r("Import")})}),b!==null&&u("p",{className:"text-sm text-muted-foreground","data-testid":"ei-progress",role:"status",children:b}),x!==null&&u(Nt,{result:x})]})]}),g!==null&&u("p",{className:"text-sm text-destructive","data-testid":"ei-error",role:"alert",children:g})]})};function Ct(t){return u(Ee,{value:t.name,children:t.name},t.name)}export{Kt as ExportImportPanel};
@@ -1,4 +1,4 @@
1
- import{c as U}from"react/compiler-runtime";import{useState as B,useEffect as ne,useRef as de,useMemo as ge,useCallback as ot}from"react";import{ShardInput as rt}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{B as oe}from"../packem_shared/button-q0UYSmrn.mjs";import{E as Te}from"../packem_shared/empty-state-D7jEML_T.mjs";import{useT as it}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{S as at}from"../packem_shared/grid-features-2c5SaBtH.mjs";import{C as ct,a as dt}from"../packem_shared/card-By2O8ULa.mjs";import{C as Ee}from"../packem_shared/checkbox-CnS9cyCz.mjs";import{c as le,a as ft,b as be,d as ut,T as ht,e as Q}from"../packem_shared/table-D0SBiDu-.mjs";import{n as _e,f as q,b as ie,d as Se,c as $e,g as mt}from"../packem_shared/internal-BXEjuLPN.mjs";import{ConfirmButton as pt}from"../packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{B as fe}from"../packem_shared/badge-r_5B4LHP.mjs";import{jsx as r,jsxs as R,Fragment as gt}from"react/jsx-runtime";import{I as bt}from"../packem_shared/input-CXhxesPC.mjs";import{d as yt}from"../packem_shared/cf-links-CBJ5SywP.mjs";import{useAutoRefresh as xt}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-CG7Q45ZS.mjs";import{u as vt}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{ADMIN_FUNCTIONS as Fe}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";const Re=(d,e,t)=>{const{onCopy:s,onDelete:n,onDownload:l,onToggleSelect:a}=t,c=()=>{s(d.key)},o=()=>{l(d.key)},f=()=>{n(d.key)},h=()=>{a(d.key)};return{copy:c,download:o,name:d.key.slice(e.length),remove:f,toggle:h}},ze=d=>{const e=U(31),{busy:t,buttonClassName:s,copied:n,objectKey:l,onCopy:a,onDelete:c,onDownload:o,t:f}=d,h=`storage-copy-${l}`;let u;e[0]!==n||e[1]!==f?(u=f(n?"Copied":"Copy URL"),e[0]=n,e[1]=f,e[2]=u):u=e[2];let m;e[3]!==t||e[4]!==s||e[5]!==a||e[6]!==h||e[7]!==u?(m=r(oe,{className:s,"data-testid":h,disabled:t,onClick:a,size:"sm",type:"button",variant:"ghost",children:u}),e[3]=t,e[4]=s,e[5]=a,e[6]=h,e[7]=u,e[8]=m):m=e[8];const k=`storage-download-${l}`;let i;e[9]!==f?(i=f("Download"),e[9]=f,e[10]=i):i=e[10];let v;e[11]!==t||e[12]!==s||e[13]!==o||e[14]!==k||e[15]!==i?(v=r(oe,{className:s,"data-testid":k,disabled:t,onClick:o,size:"sm",type:"button",variant:"ghost",children:i}),e[11]=t,e[12]=s,e[13]=o,e[14]=k,e[15]=i,e[16]=v):v=e[16];let S;e[17]!==f?(S=f("Delete object?"),e[17]=f,e[18]=S):S=e[18];const y=`storage-delete-${l}`;let g;e[19]!==f?(g=f("Delete"),e[19]=f,e[20]=g):g=e[20];let b;e[21]!==t||e[22]!==c||e[23]!==S||e[24]!==y||e[25]!==g?(b=r(pt,{confirmLabel:S,disabled:t,onConfirm:c,testId:y,children:g}),e[21]=t,e[22]=c,e[23]=S,e[24]=y,e[25]=g,e[26]=b):b=e[26];let x;return e[27]!==b||e[28]!==m||e[29]!==v?(x=R(gt,{children:[m,v,b]}),e[27]=b,e[28]=m,e[29]=v,e[30]=x):x=e[30],x},De=d=>{const e=U(14),{objectKey:t,references:s,t:n}=d;if(s===void 0)return null;if(s.length===0){const h=`storage-orphan-${t}`;let u;e[0]!==n?(u=n("Orphan"),e[0]=n,e[1]=u):u=e[1];let m;return e[2]!==h||e[3]!==u?(m=r(fe,{"data-testid":h,variant:"warning",children:u}),e[2]=h,e[3]=u,e[4]=m):m=e[4],m}let l;e[5]!==s?(l=s.map(kt).join(`
1
+ import{c as U}from"react/compiler-runtime";import{useState as B,useEffect as ne,useRef as de,useMemo as ge,useCallback as ot}from"react";import{ShardInput as rt}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{B as oe}from"../packem_shared/button-q0UYSmrn.mjs";import{E as Te}from"../packem_shared/empty-state-D7jEML_T.mjs";import{useT as it}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{S as at}from"../packem_shared/grid-features-2c5SaBtH.mjs";import{C as ct,a as dt}from"../packem_shared/card-By2O8ULa.mjs";import{C as Ee}from"../packem_shared/checkbox-CnS9cyCz.mjs";import{c as le,a as ft,b as be,d as ut,T as ht,e as Q}from"../packem_shared/table-D0SBiDu-.mjs";import{n as _e,f as q,b as ie,d as Se,c as $e,g as mt}from"../packem_shared/internal-BXEjuLPN.mjs";import{ConfirmButton as pt}from"../packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{B as fe}from"../packem_shared/badge-r_5B4LHP.mjs";import{jsx as r,jsxs as R,Fragment as gt}from"react/jsx-runtime";import{I as bt}from"../packem_shared/input-CXhxesPC.mjs";import{d as yt}from"../packem_shared/cf-links-CBJ5SywP.mjs";import{useAutoRefresh as xt}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-CG7Q45ZS.mjs";import{u as vt}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{ADMIN_FUNCTIONS as Fe}from"../packem_shared/ADMIN_FUNCTIONS-4aGsMs95.mjs";const Re=(d,e,t)=>{const{onCopy:s,onDelete:n,onDownload:l,onToggleSelect:a}=t,c=()=>{s(d.key)},o=()=>{l(d.key)},f=()=>{n(d.key)},h=()=>{a(d.key)};return{copy:c,download:o,name:d.key.slice(e.length),remove:f,toggle:h}},ze=d=>{const e=U(31),{busy:t,buttonClassName:s,copied:n,objectKey:l,onCopy:a,onDelete:c,onDownload:o,t:f}=d,h=`storage-copy-${l}`;let u;e[0]!==n||e[1]!==f?(u=f(n?"Copied":"Copy URL"),e[0]=n,e[1]=f,e[2]=u):u=e[2];let m;e[3]!==t||e[4]!==s||e[5]!==a||e[6]!==h||e[7]!==u?(m=r(oe,{className:s,"data-testid":h,disabled:t,onClick:a,size:"sm",type:"button",variant:"ghost",children:u}),e[3]=t,e[4]=s,e[5]=a,e[6]=h,e[7]=u,e[8]=m):m=e[8];const k=`storage-download-${l}`;let i;e[9]!==f?(i=f("Download"),e[9]=f,e[10]=i):i=e[10];let v;e[11]!==t||e[12]!==s||e[13]!==o||e[14]!==k||e[15]!==i?(v=r(oe,{className:s,"data-testid":k,disabled:t,onClick:o,size:"sm",type:"button",variant:"ghost",children:i}),e[11]=t,e[12]=s,e[13]=o,e[14]=k,e[15]=i,e[16]=v):v=e[16];let S;e[17]!==f?(S=f("Delete object?"),e[17]=f,e[18]=S):S=e[18];const y=`storage-delete-${l}`;let g;e[19]!==f?(g=f("Delete"),e[19]=f,e[20]=g):g=e[20];let b;e[21]!==t||e[22]!==c||e[23]!==S||e[24]!==y||e[25]!==g?(b=r(pt,{confirmLabel:S,disabled:t,onConfirm:c,testId:y,children:g}),e[21]=t,e[22]=c,e[23]=S,e[24]=y,e[25]=g,e[26]=b):b=e[26];let x;return e[27]!==b||e[28]!==m||e[29]!==v?(x=R(gt,{children:[m,v,b]}),e[27]=b,e[28]=m,e[29]=v,e[30]=x):x=e[30],x},De=d=>{const e=U(14),{objectKey:t,references:s,t:n}=d;if(s===void 0)return null;if(s.length===0){const h=`storage-orphan-${t}`;let u;e[0]!==n?(u=n("Orphan"),e[0]=n,e[1]=u):u=e[1];let m;return e[2]!==h||e[3]!==u?(m=r(fe,{"data-testid":h,variant:"warning",children:u}),e[2]=h,e[3]=u,e[4]=m):m=e[4],m}let l;e[5]!==s?(l=s.map(kt).join(`
2
2
  `),e[5]=s,e[6]=l):l=e[6];const a=l,c=`storage-refs-${t}`;let o;e[7]!==s.length||e[8]!==n?(o=s.length===1?n("1 record"):n("{count} records",{count:s.length}),e[7]=s.length,e[8]=n,e[9]=o):o=e[9];let f;return e[10]!==a||e[11]!==c||e[12]!==o?(f=r(fe,{"data-testid":c,title:a,variant:"secondary",children:o}),e[10]=a,e[11]=c,e[12]=o,e[13]=f):f=e[13],f},je=d=>{const e=U(7),{objectKey:t,onToggle:s,selected:n,t:l}=d;let a;e[0]!==l?(a=l("Select row"),e[0]=l,e[1]=a):a=e[1];const c=`storage-select-${t}`;let o;return e[2]!==s||e[3]!==n||e[4]!==a||e[5]!==c?(o=r(Ee,{"aria-label":a,checked:n,"data-testid":c,onCheckedChange:s}),e[2]=s,e[3]=n,e[4]=a,e[5]=c,e[6]=o):o=e[6],o};function kt(d){return`${d.table}·${d.id}`}const St=d=>{const e=U(10),{colSpan:t,name:s,onEnter:n}=d;let l;e[0]!==s||e[1]!==n?(l=()=>{n(s)},e[0]=s,e[1]=n,e[2]=l):l=e[2];const a=l;let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=r("svg",{"aria-hidden":"true",className:"size-4 text-muted-foreground",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:r("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z"})}),e[3]=c):c=e[3];let o;e[4]!==a||e[5]!==s?(o=R("button",{className:"inline-flex items-center gap-2 font-mono text-xs outline-none hover:text-foreground focus-visible:text-foreground","data-testid":"fb-folder",onClick:a,type:"button",children:[c,s]}),e[4]=a,e[5]=s,e[6]=o):o=e[6];let f;return e[7]!==t||e[8]!==o?(f=r(be,{children:r(Q,{colSpan:t,children:o})}),e[7]=t,e[8]=o,e[9]=f):f=e[9],f},wt=d=>{const e=U(37),{busy:t,copiedKey:s,handlers:n,object:l,prefix:a,references:c,selected:o,showReferences:f,t:h}=d;let u;e[0]!==n||e[1]!==l||e[2]!==a?(u=Re(l,a,n),e[0]=n,e[1]=l,e[2]=a,e[3]=u):u=e[3];const{copy:m,download:k,name:i,remove:v,toggle:S}=u;let y;e[4]!==l.key||e[5]!==o||e[6]!==h||e[7]!==S?(y=r(Q,{className:"w-8",children:r(je,{objectKey:l.key,onToggle:S,selected:o,t:h})}),e[4]=l.key,e[5]=o,e[6]=h,e[7]=S,e[8]=y):y=e[8];let g;e[9]!==i?(g=r(Q,{className:"font-mono text-xs",children:i}),e[9]=i,e[10]=g):g=e[10];let b;e[11]!==l.size?(b=_e(l.size),e[11]=l.size,e[12]=b):b=e[12];let x;e[13]!==b?(x=r(Q,{className:"tabular-nums text-muted-foreground",children:b}),e[13]=b,e[14]=x):x=e[14];const N=l.httpMetadata?.contentType??"";let w;e[15]!==N?(w=r(Q,{children:N}),e[15]=N,e[16]=w):w=e[16];let C;e[17]!==l.key||e[18]!==c||e[19]!==f||e[20]!==h?(C=f&&r(Q,{children:r(De,{objectKey:l.key,references:c,t:h})}),e[17]=l.key,e[18]=c,e[19]=f,e[20]=h,e[21]=C):C=e[21];const E=s===l.key;let T;e[22]!==t||e[23]!==m||e[24]!==k||e[25]!==l.key||e[26]!==v||e[27]!==h||e[28]!==E?(T=r(Q,{className:"text-right",children:r("span",{className:"inline-flex items-center gap-1",children:r(ze,{busy:t,copied:E,objectKey:l.key,onCopy:m,onDelete:v,onDownload:k,t:h})})}),e[22]=t,e[23]=m,e[24]=k,e[25]=l.key,e[26]=v,e[27]=h,e[28]=E,e[29]=T):T=e[29];let F;return e[30]!==T||e[31]!==y||e[32]!==g||e[33]!==x||e[34]!==w||e[35]!==C?(F=R(be,{"data-testid":"fb-row",children:[y,g,x,w,C,T]}),e[30]=T,e[31]=y,e[32]=g,e[33]=x,e[34]=w,e[35]=C,e[36]=F):F=e[36],F},Ct=d=>{const e=U(65),{allSelected:t,busy:s,copiedKey:n,files:l,folders:a,handlers:c,onEnterFolder:o,prefix:f,references:h,selected:u,showReferences:m,someSelected:k,t:i,toggleSelectAll:v}=d;let S;e[0]!==i?(S=i("Select all rows"),e[0]=i,e[1]=S):S=e[1];let y;e[2]!==t||e[3]!==k||e[4]!==S||e[5]!==v?(y=r(le,{className:"w-8",children:r(Ee,{"aria-label":S,checked:t,"data-testid":"storage-select-all",indeterminate:k,onCheckedChange:v})}),e[2]=t,e[3]=k,e[4]=S,e[5]=v,e[6]=y):y=e[6];let g;e[7]!==i?(g=i("key"),e[7]=i,e[8]=g):g=e[8];let b;e[9]!==g?(b=r(le,{children:g}),e[9]=g,e[10]=b):b=e[10];let x;e[11]!==i?(x=i("size"),e[11]=i,e[12]=x):x=e[12];let N;e[13]!==x?(N=r(le,{children:x}),e[13]=x,e[14]=N):N=e[14];let w;e[15]!==i?(w=i("content-type"),e[15]=i,e[16]=w):w=e[16];let C;e[17]!==w?(C=r(le,{children:w}),e[17]=w,e[18]=C):C=e[18];let E;e[19]!==m||e[20]!==i?(E=m&&r(le,{children:i("used by")}),e[19]=m,e[20]=i,e[21]=E):E=e[21];let T;e[22]!==i?(T=i("Actions"),e[22]=i,e[23]=T):T=e[23];let F;e[24]!==T?(F=r(le,{"aria-label":T}),e[24]=T,e[25]=F):F=e[25];let _;e[26]!==F||e[27]!==y||e[28]!==b||e[29]!==N||e[30]!==C||e[31]!==E?(_=r(ft,{children:R(be,{children:[y,b,N,C,E,F]})}),e[26]=F,e[27]=y,e[28]=b,e[29]=N,e[30]=C,e[31]=E,e[32]=_):_=e[32];let z;if(e[33]!==a||e[34]!==o||e[35]!==m){let D;e[37]!==o||e[38]!==m?(D=K=>r(St,{colSpan:m?6:5,name:K,onEnter:o},K),e[37]=o,e[38]=m,e[39]=D):D=e[39],z=a.map(D),e[33]=a,e[34]=o,e[35]=m,e[36]=z}else z=e[36];let L;if(e[40]!==s||e[41]!==n||e[42]!==l||e[43]!==c||e[44]!==f||e[45]!==h||e[46]!==u||e[47]!==m||e[48]!==i){let D;e[50]!==s||e[51]!==n||e[52]!==c||e[53]!==f||e[54]!==h||e[55]!==u||e[56]!==m||e[57]!==i?(D=K=>r(wt,{busy:s,copiedKey:n,handlers:c,object:K,prefix:f,references:h[K.key],selected:u.has(K.key),showReferences:m,t:i},K.key),e[50]=s,e[51]=n,e[52]=c,e[53]=f,e[54]=h,e[55]=u,e[56]=m,e[57]=i,e[58]=D):D=e[58],L=l.map(D),e[40]=s,e[41]=n,e[42]=l,e[43]=c,e[44]=f,e[45]=h,e[46]=u,e[47]=m,e[48]=i,e[49]=L}else L=e[49];let j;e[59]!==z||e[60]!==L?(j=R(ut,{children:[z,L]}),e[59]=z,e[60]=L,e[61]=j):j=e[61];let I;return e[62]!==_||e[63]!==j?(I=r(ct,{className:"overflow-hidden py-0",children:r(dt,{className:"px-0",children:R(ht,{"data-testid":"fb-table",children:[_,j]})})}),e[62]=_,e[63]=j,e[64]=I):I=e[64],I},Nt=[{label:"15m",seconds:900},{label:"1h",seconds:3600},{label:"24h",seconds:86400},{label:"7d",seconds:604800}],Tt=3600,we=(d,e)=>{if(e==="size")return d.size;if(e==="type")return d.httpMetadata?.contentType??"";if(e==="date"){if(d.uploaded===void 0)return 0;const t=new Date(d.uploaded).getTime();return Number.isNaN(t)?0:t}return e.startsWith("tag:")?d.customMetadata?.[e.slice(4)]??"":d.key},Et=(d,e,t)=>{const s=t==="desc"?-1:1;return d.toSorted((n,l)=>{const a=we(n,e),c=we(l,e);return(typeof a=="number"&&typeof c=="number"?a-c:String(a).localeCompare(String(c)))*s})},_t=(d,e)=>{const t=new Set,s=[];for(const n of d){const l=n.key.slice(e.length),a=l.indexOf("/");a===-1?s.push(n):t.add(l.slice(0,a+1))}return{files:s,folders:[...t].toSorted((n,l)=>n.localeCompare(l))}},$t=d=>{const e=U(59),{bucket:t,buckets:s,busy:n,draftPrefix:l,expiry:a,fileInputRef:c,onBucketChange:o,onExpiryChange:f,onFileChange:h,onList:u,onPrefixChange:m,onUploadClick:k,t:i}=d;let v;e[0]!==m?(v=G=>{m(G.target.value)},e[0]=m,e[1]=v):v=e[1];const S=v;let y;e[2]!==o?(y=G=>{o(G.target.value)},e[2]=o,e[3]=y):y=e[3];const g=y;let b;e[4]!==f?(b=G=>{f(Number.parseInt(G.target.value,10))},e[4]=f,e[5]=b):b=e[5];const x=b;let N;e[6]!==t||e[7]!==s||e[8]!==g||e[9]!==i?(N=s.length>0&&r("select",{"aria-label":i("Bucket"),className:"h-8 rounded-md border border-border bg-background px-1 outline-none focus-visible:border-ring","data-testid":"fb-bucket",onChange:g,value:t,children:s.map(Rt)}),e[6]=t,e[7]=s,e[8]=g,e[9]=i,e[10]=N):N=e[10];let w;e[11]!==i?(w=i("Key prefix"),e[11]=i,e[12]=w):w=e[12];let C;e[13]!==i?(C=i("key prefix (optional)"),e[13]=i,e[14]=C):C=e[14];let E;e[15]!==l||e[16]!==S||e[17]!==w||e[18]!==C?(E=r(bt,{"aria-label":w,className:"h-8 w-64 max-w-full","data-testid":"fb-prefix-input",onChange:S,placeholder:C,value:l}),e[15]=l,e[16]=S,e[17]=w,e[18]=C,e[19]=E):E=e[19];let T;e[20]!==i?(T=i("List"),e[20]=i,e[21]=T):T=e[21];let F;e[22]!==n||e[23]!==u||e[24]!==T?(F=r(oe,{"data-testid":"fb-list",disabled:n,onClick:u,size:"sm",type:"button",children:T}),e[22]=n,e[23]=u,e[24]=T,e[25]=F):F=e[25];let _;e[26]!==n||e[27]!==i?(_=i(n?"Uploading…":"Upload"),e[26]=n,e[27]=i,e[28]=_):_=e[28];let z;e[29]!==n||e[30]!==k||e[31]!==_?(z=r(oe,{"data-testid":"storage-upload",disabled:n,onClick:k,size:"sm",type:"button",variant:"outline",children:_}),e[29]=n,e[30]=k,e[31]=_,e[32]=z):z=e[32];let L;e[33]!==c||e[34]!==h?(L=r("input",{className:"hidden","data-testid":"storage-file-input",onChange:h,ref:c,type:"file"}),e[33]=c,e[34]=h,e[35]=L):L=e[35];let j;e[36]!==i?(j=i("Link expiry"),e[36]=i,e[37]=j):j=e[37];let I;e[38]!==i?(I=Nt.map(G=>r("option",{value:G.seconds,children:i(G.label)},G.seconds)),e[38]=i,e[39]=I):I=e[39];let D;e[40]!==a||e[41]!==x||e[42]!==I?(D=r("select",{className:"h-8 rounded-md border border-border bg-background px-1 tabular-nums outline-none focus-visible:border-ring","data-testid":"storage-expiry",id:"storage-expiry",onChange:x,value:a,children:I}),e[40]=a,e[41]=x,e[42]=I,e[43]=D):D=e[43];let K;e[44]!==j||e[45]!==D?(K=R("label",{className:"ml-auto flex items-center gap-1.5 text-xs text-muted-foreground",htmlFor:"storage-expiry",children:[j,D]}),e[44]=j,e[45]=D,e[46]=K):K=e[46];let A;e[47]!==i?(A=i("Open in Cloudflare"),e[47]=i,e[48]=A):A=e[48];let M;e[49]!==A?(M=r("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"fb-cf-link",href:yt,rel:"noreferrer",target:"_blank",children:A}),e[49]=A,e[50]=M):M=e[50];let H;return e[51]!==z||e[52]!==L||e[53]!==K||e[54]!==M||e[55]!==N||e[56]!==E||e[57]!==F?(H=R("div",{className:"flex flex-wrap items-center gap-2",children:[N,E,F,z,L,K,M]}),e[51]=z,e[52]=L,e[53]=K,e[54]=M,e[55]=N,e[56]=E,e[57]=F,e[58]=H):H=e[58],H},Ft=d=>{const e=U(66),{onSortKeyChange:t,onThumbSizeChange:s,showGrid:n,showList:l,sortDirection:a,sortKey:c,t:o,tagKeys:f,thumbSize:h,toggleSortDirection:u,view:m}=d;let k;e[0]!==t?(k=W=>{t(W.target.value)},e[0]=t,e[1]=k):k=e[1];const i=k;let v;e[2]!==s?(v=W=>{s(Number.parseInt(W.target.value,10))},e[2]=s,e[3]=v):v=e[3];const S=v,y=m==="list";let g;e[4]!==o?(g=o("List"),e[4]=o,e[5]=g):g=e[5];let b;e[6]!==l||e[7]!==y||e[8]!==g?(b=r("button",{"aria-pressed":y,className:"px-2 py-1 outline-none transition-colors hover:bg-accent aria-pressed:bg-accent aria-pressed:text-accent-foreground","data-testid":"fb-view-list",onClick:l,type:"button",children:g}),e[6]=l,e[7]=y,e[8]=g,e[9]=b):b=e[9];const x=m==="grid";let N;e[10]!==o?(N=o("Grid"),e[10]=o,e[11]=N):N=e[11];let w;e[12]!==n||e[13]!==x||e[14]!==N?(w=r("button",{"aria-pressed":x,className:"border-s border-border px-2 py-1 outline-none transition-colors hover:bg-accent aria-pressed:bg-accent aria-pressed:text-accent-foreground","data-testid":"fb-view-grid",onClick:n,type:"button",children:N}),e[12]=n,e[13]=x,e[14]=N,e[15]=w):w=e[15];let C;e[16]!==b||e[17]!==w?(C=R("div",{className:"inline-flex overflow-hidden rounded-md border border-border",children:[b,w]}),e[16]=b,e[17]=w,e[18]=C):C=e[18];let E;e[19]!==o?(E=o("Sort"),e[19]=o,e[20]=E):E=e[20];let T;e[21]!==o?(T=o("Name"),e[21]=o,e[22]=T):T=e[22];let F;e[23]!==T?(F=r("option",{value:"name",children:T}),e[23]=T,e[24]=F):F=e[24];let _;e[25]!==o?(_=o("size"),e[25]=o,e[26]=_):_=e[26];let z;e[27]!==_?(z=r("option",{value:"size",children:_}),e[27]=_,e[28]=z):z=e[28];let L;e[29]!==o?(L=o("Type"),e[29]=o,e[30]=L):L=e[30];let j;e[31]!==L?(j=r("option",{value:"type",children:L}),e[31]=L,e[32]=j):j=e[32];let I;e[33]!==o?(I=o("Modified"),e[33]=o,e[34]=I):I=e[34];let D;e[35]!==I?(D=r("option",{value:"date",children:I}),e[35]=I,e[36]=D):D=e[36];let K;e[37]!==f?(K=f.map(zt),e[37]=f,e[38]=K):K=e[38];let A;e[39]!==i||e[40]!==c||e[41]!==F||e[42]!==z||e[43]!==j||e[44]!==D||e[45]!==K?(A=R("select",{className:"h-8 rounded-md border border-border bg-background px-1 outline-none focus-visible:border-ring","data-testid":"fb-sort",id:"fb-sort",onChange:i,value:c,children:[F,z,j,D,K]}),e[39]=i,e[40]=c,e[41]=F,e[42]=z,e[43]=j,e[44]=D,e[45]=K,e[46]=A):A=e[46];let M;e[47]!==E||e[48]!==A?(M=R("label",{className:"flex items-center gap-1.5 text-muted-foreground",htmlFor:"fb-sort",children:[E,A]}),e[47]=E,e[48]=A,e[49]=M):M=e[49];let H;e[50]!==o?(H=o("Toggle sort direction"),e[50]=o,e[51]=H):H=e[51];const G=a==="asc"?"↑":"↓";let P;e[52]!==H||e[53]!==G||e[54]!==u?(P=r("button",{"aria-label":H,className:"flex size-8 items-center justify-center rounded-md border border-border tabular-nums outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"fb-sort-dir",onClick:u,type:"button",children:G}),e[52]=H,e[53]=G,e[54]=u,e[55]=P):P=e[55];let Z;e[56]!==S||e[57]!==o||e[58]!==h||e[59]!==m?(Z=m==="grid"&&R("label",{className:"ml-auto flex items-center gap-1.5 text-muted-foreground",htmlFor:"fb-thumb-size",children:[o("Thumbnail size"),r("input",{className:"accent-primary","data-testid":"fb-thumb-size",id:"fb-thumb-size",max:240,min:80,onChange:S,step:8,type:"range",value:h})]}),e[56]=S,e[57]=o,e[58]=h,e[59]=m,e[60]=Z):Z=e[60];let ee;return e[61]!==M||e[62]!==P||e[63]!==Z||e[64]!==C?(ee=R("div",{className:"flex flex-wrap items-center gap-2 text-xs","data-testid":"fb-controls",children:[C,M,P,Z]}),e[61]=M,e[62]=P,e[63]=Z,e[64]=C,e[65]=ee):ee=e[65],ee};function Rt(d){return r("option",{value:d,children:d},d)}function zt(d){return r("option",{value:`tag:${d}`,children:d},d)}const Dt=/\.(?:avif|bmp|gif|ico|jpe?g|png|svg|webp)$/iu,jt=d=>(d.httpMetadata?.contentType??"").startsWith("image/")||Dt.test(d.key),Kt=()=>{const d=U(1);let e;return d[0]===Symbol.for("react.memo_cache_sentinel")?(e=r("svg",{"aria-hidden":"true",className:"size-8 text-muted-foreground/60",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.4,viewBox:"0 0 24 24",children:r("path",{d:"M7 3h7l5 5v13a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Zm7 0v5h5"})}),d[0]=e):e=d[0],e},Bt=d=>{const e=U(13),{object:t,resolveUrl:s}=d,[n,l]=B(null),[a,c]=B(!1);let o;e[0]!==t?(o=jt(t),e[0]=t,e[1]=o):o=e[1];const f=o;let h,u;e[2]!==f||e[3]!==t.key||e[4]!==s?(h=()=>{if(!f)return;const v={cancelled:!1};return q((async()=>{try{const S=await s(t.key);v.cancelled||l(S)}catch{v.cancelled||c(!0)}})()),()=>{v.cancelled=!0}},u=[f,t.key,s],e[2]=f,e[3]=t.key,e[4]=s,e[5]=h,e[6]=u):(h=e[5],u=e[6]),ne(h,u);let m;e[7]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{c(!0)},e[7]=m):m=e[7];const k=m;let i;return e[8]!==a||e[9]!==f||e[10]!==t.key||e[11]!==n?(i=r("div",{className:"flex aspect-square w-full items-center justify-center overflow-hidden rounded-md border border-border bg-muted/30",children:f&&n!==null&&!a?r("img",{alt:t.key,className:"size-full object-cover",loading:"lazy",onError:k,src:n}):r(Kt,{})}),e[8]=a,e[9]=f,e[10]=t.key,e[11]=n,e[12]=i):i=e[12],i},Lt=d=>{const e=U(42),{busy:t,copiedKey:s,handlers:n,object:l,prefix:a,references:c,resolveUrl:o,selected:f,showReferences:h,t:u}=d;let m;e[0]!==n||e[1]!==l||e[2]!==a?(m=Re(l,a,n),e[0]=n,e[1]=l,e[2]=a,e[3]=m):m=e[3];const{copy:k,download:i,name:v,remove:S,toggle:y}=m;let g;e[4]!==l||e[5]!==o?(g=r(Bt,{object:l,resolveUrl:o}),e[4]=l,e[5]=o,e[6]=g):g=e[6];let b;e[7]!==l.key||e[8]!==f||e[9]!==u||e[10]!==y?(b=r("span",{className:"absolute left-1.5 top-1.5 rounded bg-background/80 p-0.5",children:r(je,{objectKey:l.key,onToggle:y,selected:f,t:u})}),e[7]=l.key,e[8]=f,e[9]=u,e[10]=y,e[11]=b):b=e[11];let x;e[12]!==g||e[13]!==b?(x=R("div",{className:"relative",children:[g,b]}),e[12]=g,e[13]=b,e[14]=x):x=e[14];let N;e[15]!==v?(N=r("p",{className:"truncate font-mono text-xs",title:v,children:v}),e[15]=v,e[16]=N):N=e[16];let w;e[17]!==l.size?(w=_e(l.size),e[17]=l.size,e[18]=w):w=e[18];let C;e[19]!==w?(C=r("p",{className:"text-[11px] tabular-nums text-muted-foreground",children:w}),e[19]=w,e[20]=C):C=e[20];let E;e[21]!==l.key||e[22]!==c||e[23]!==h||e[24]!==u?(E=h&&r("div",{className:"mt-1",children:r(De,{objectKey:l.key,references:c,t:u})}),e[21]=l.key,e[22]=c,e[23]=h,e[24]=u,e[25]=E):E=e[25];let T;e[26]!==N||e[27]!==C||e[28]!==E?(T=R("div",{className:"min-w-0",children:[N,C,E]}),e[26]=N,e[27]=C,e[28]=E,e[29]=T):T=e[29];const F=s===l.key;let _;e[30]!==t||e[31]!==k||e[32]!==i||e[33]!==l.key||e[34]!==S||e[35]!==u||e[36]!==F?(_=r("div",{className:"flex items-center gap-1",children:r(ze,{busy:t,buttonClassName:"h-7 px-2 text-xs",copied:F,objectKey:l.key,onCopy:k,onDelete:S,onDownload:i,t:u})}),e[30]=t,e[31]=k,e[32]=i,e[33]=l.key,e[34]=S,e[35]=u,e[36]=F,e[37]=_):_=e[37];let z;return e[38]!==_||e[39]!==x||e[40]!==T?(z=R("div",{className:"flex flex-col gap-1.5","data-testid":"fb-tile",children:[x,T,_]}),e[38]=_,e[39]=x,e[40]=T,e[41]=z):z=e[41],z},It=d=>{const e=U(9),{name:t,onEnter:s}=d;let n;e[0]!==t||e[1]!==s?(n=()=>{s(t)},e[0]=t,e[1]=s,e[2]=n):n=e[2];const l=n;let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a=r("span",{className:"flex aspect-square w-full items-center justify-center rounded-md border border-border bg-muted/30 transition-colors hover:bg-accent",children:r("svg",{"aria-hidden":"true",className:"size-10 text-muted-foreground",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.4,viewBox:"0 0 24 24",children:r("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z"})})}),e[3]=a):a=e[3];let c;e[4]!==t?(c=r("span",{className:"truncate font-mono text-xs",title:t,children:t}),e[4]=t,e[5]=c):c=e[5];let o;return e[6]!==l||e[7]!==c?(o=R("button",{className:"flex flex-col gap-1.5 text-left outline-none","data-testid":"fb-folder",onClick:l,type:"button",children:[a,c]}),e[6]=l,e[7]=c,e[8]=o):o=e[8],o},Ot=d=>{const e=U(34),{busy:t,copiedKey:s,files:n,folders:l,handlers:a,onEnterFolder:c,prefix:o,references:f,resolveUrl:h,selected:u,showReferences:m,size:k,t:i}=d;let v;e[0]!==k?(v=k.toString(),e[0]=k,e[1]=v):v=e[1];const S=`repeat(auto-fill, minmax(${v}px, 1fr))`;let y;e[2]!==S?(y={gridTemplateColumns:S},e[2]=S,e[3]=y):y=e[3];const g=y;let b;if(e[4]!==l||e[5]!==c){let w;e[7]!==c?(w=C=>r(It,{name:C,onEnter:c},C),e[7]=c,e[8]=w):w=e[8],b=l.map(w),e[4]=l,e[5]=c,e[6]=b}else b=e[6];let x;if(e[9]!==t||e[10]!==s||e[11]!==n||e[12]!==a||e[13]!==o||e[14]!==f||e[15]!==h||e[16]!==u||e[17]!==m||e[18]!==i){let w;e[20]!==t||e[21]!==s||e[22]!==a||e[23]!==o||e[24]!==f||e[25]!==h||e[26]!==u||e[27]!==m||e[28]!==i?(w=C=>r(Lt,{busy:t,copiedKey:s,handlers:a,object:C,prefix:o,references:f[C.key],resolveUrl:h,selected:u.has(C.key),showReferences:m,t:i},C.key),e[20]=t,e[21]=s,e[22]=a,e[23]=o,e[24]=f,e[25]=h,e[26]=u,e[27]=m,e[28]=i,e[29]=w):w=e[29],x=n.map(w),e[9]=t,e[10]=s,e[11]=n,e[12]=a,e[13]=o,e[14]=f,e[15]=h,e[16]=u,e[17]=m,e[18]=i,e[19]=x}else x=e[19];let N;return e[30]!==g||e[31]!==b||e[32]!==x?(N=R("div",{className:"grid gap-4","data-testid":"fb-gallery",style:g,children:[b,x]}),e[30]=g,e[31]=b,e[32]=x,e[33]=N):N=e[33],N},At=d=>{const e=U(23),{reference:t,t:s}=d,n=`fb-dangling-${t.table}-${t.id}-${t.column}`,l=`${t.table}·${t.id}`;let a;e[0]!==l?(a=r(fe,{variant:"secondary",children:l}),e[0]=l,e[1]=a):a=e[1];let c;e[2]!==t.column?(c=r("span",{className:"text-muted-foreground",children:t.column}),e[2]=t.column,e[3]=c):c=e[3];let o;e[4]!==s?(o=s("→"),e[4]=s,e[5]=o):o=e[5];let f;e[6]!==o?(f=r("span",{className:"text-muted-foreground/60",children:o}),e[6]=o,e[7]=f):f=e[7];let h;e[8]!==t.key?(h=r("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-foreground",children:t.key}),e[8]=t.key,e[9]=h):h=e[9];let u;e[10]!==a||e[11]!==c||e[12]!==f||e[13]!==h?(u=R("span",{className:"flex flex-wrap items-center gap-1.5",children:[a,c,f,h]}),e[10]=a,e[11]=c,e[12]=f,e[13]=h,e[14]=u):u=e[14];let m;e[15]!==s?(m=s("Missing object"),e[15]=s,e[16]=m):m=e[16];let k;e[17]!==m?(k=r(fe,{className:"border-destructive/40 text-destructive",variant:"outline",children:m}),e[17]=m,e[18]=k):k=e[18];let i;return e[19]!==n||e[20]!==k||e[21]!==u?(i=R("li",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-border/60 px-3 py-2 text-xs","data-testid":n,children:[u,k]}),e[19]=n,e[20]=k,e[21]=u,e[22]=i):i=e[22],i},Ut=d=>{const e=U(42),{busy:t,onCheck:s,references:n,t:l,truncated:a}=d;let c;e[0]!==l?(c=l("Integrity"),e[0]=l,e[1]=c):c=e[1];let o;e[2]!==c?(o=r("span",{className:"font-mono text-[11px] uppercase tracking-wide text-muted-foreground",children:c}),e[2]=c,e[3]=o):o=e[3];let f;e[4]!==l?(f=l("Orphaned objects"),e[4]=l,e[5]=f):f=e[5];let h;e[6]!==f?(h=r("span",{className:"text-sm font-medium text-foreground",children:f}),e[6]=f,e[7]=h):h=e[7];let u;e[8]!==l?(u=l("Find records whose file reference points at an object the bucket no longer has."),e[8]=l,e[9]=u):u=e[9];let m;e[10]!==u?(m=r("span",{className:"text-xs text-muted-foreground",children:u}),e[10]=u,e[11]=m):m=e[11];let k;e[12]!==o||e[13]!==h||e[14]!==m?(k=R("div",{className:"flex flex-col gap-1",children:[o,h,m]}),e[12]=o,e[13]=h,e[14]=m,e[15]=k):k=e[15];let i;e[16]!==t||e[17]!==l?(i=l(t?"Checking…":"Check for orphans"),e[16]=t,e[17]=l,e[18]=i):i=e[18];let v;e[19]!==t||e[20]!==s||e[21]!==i?(v=r(oe,{"data-testid":"fb-orphans-check",disabled:t,onClick:s,size:"sm",type:"button",variant:"outline",children:i}),e[19]=t,e[20]=s,e[21]=i,e[22]=v):v=e[22];let S;e[23]!==k||e[24]!==v?(S=R("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[k,v]}),e[23]=k,e[24]=v,e[25]=S):S=e[25];let y;e[26]!==n||e[27]!==l||e[28]!==a?(y=a&&r("p",{className:"text-xs text-warning","data-testid":"fb-orphans-truncated",children:n===void 0||n.length===0?l("The bucket is larger than the scan's key limit, so dangling references could not be checked."):l("Showing the first {count} dangling references — the scan was truncated.",{count:n.length})}),e[26]=n,e[27]=l,e[28]=a,e[29]=y):y=e[29];let g;e[30]!==n?.length||e[31]!==l||e[32]!==a?(g=n?.length===0&&!a&&r(Te,{description:l("Every record's file reference points at an object that exists in the bucket."),testId:"fb-orphans-empty",title:l("No dangling references.")}),e[30]=n?.length,e[31]=l,e[32]=a,e[33]=g):g=e[33];let b;e[34]!==n||e[35]!==l?(b=n!==void 0&&n.length>0&&r("ul",{className:"flex flex-col gap-1.5","data-testid":"fb-orphans-list",children:n.map(N=>r(At,{reference:N,t:l},`${N.table}·${N.id}·${N.column}`))}),e[34]=n,e[35]=l,e[36]=b):b=e[36];let x;return e[37]!==S||e[38]!==y||e[39]!==g||e[40]!==b?(x=R("section",{className:"flex flex-col gap-2 rounded-lg border border-border/60 p-3","data-testid":"fb-orphans",children:[S,y,g,b]}),e[37]=S,e[38]=y,e[39]=g,e[40]=b,e[41]=x):x=e[41],x},Mt=function(d,e){const t=U(18);let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s=new Set,t[0]=s):s=t[0];const[n,l]=B(s);let a;t[1]===Symbol.for("react.memo_cache_sentinel")?(a=y=>{l(g=>{const b=new Set(g);return b.has(y)?b.delete(y):b.add(y),b})},t[1]=a):a=t[1];const c=a;let o;t[2]===Symbol.for("react.memo_cache_sentinel")?(o=()=>{l(new Set)},t[2]=o):o=t[2];const f=o;let h,u,m;if(t[3]!==d||t[4]!==e||t[5]!==n){let y;t[9]!==e?(y=g=>e(g),t[9]=e,t[10]=y):y=t[10],u=d.map(y),h=u.length>0&&u.every(g=>n.has(g)),m=!h&&u.some(g=>n.has(g)),t[3]=d,t[4]=e,t[5]=n,t[6]=h,t[7]=u,t[8]=m}else h=t[6],u=t[7],m=t[8];const k=m;let i;t[11]!==u?(i=()=>{l(y=>u.every(g=>y.has(g))?new Set:new Set(u))},t[11]=u,t[12]=i):i=t[12];const v=i;let S;return t[13]!==h||t[14]!==n||t[15]!==k||t[16]!==v?(S={allSelected:h,clear:f,selected:n,someSelected:k,toggle:c,toggleAll:v},t[13]=h,t[14]=n,t[15]=k,t[16]=v,t[17]=S):S=t[17],S},Gt=$e(Fe.storageReferences),Ht=$e(Fe.storageOrphans),Ce=1e4,Pt=1e3,qt=async d=>{const e=[];let t,s=!0,n=!1;for(;s&&e.length<Ce;){const l=await d.list({cursor:t,limit:Pt}),a=Ce-e.length;for(const c of l.objects.slice(0,a))e.push(c.key);n||=l.objects.length>a,t=l.cursor,s=t!==void 0}return{liveKeys:e,truncated:n||s}},Wt=3600,Vt=(d,e)=>{if(!("document"in globalThis))return;const t=globalThis.document.createElement("a");t.href=d,t.download=e,t.rel="noopener",globalThis.document.body.append(t),t.click(),t.remove()},Zt=d=>d.key,Xt=({initialPrefix:d,pageSize:e})=>{const t=vt(),[s,n]=B(d??""),[l,a]=B(d??""),[c,o]=B(Tt),[f,h]=B("list"),[u,m]=B(128),[k,i]=B("name"),[v,S]=B("asc"),[y,g]=B(void 0),[b,x]=B(void 0),[N,w]=B(!1),[C,E]=B(void 0),[T,F]=B(void 0),[_,z]=B(""),[L,j]=B({}),[I,D]=B(!1),[K,A]=B(void 0),[M,H]=B(!1),[G,P]=B(!1),[Z,ee]=B([]),[W,ye]=B(""),te=de(0),X=de(0),ae=de(0);ne(()=>{const p={cancelled:!1};return q((async()=>{try{const $=await t.listStorageBuckets();if(!p.cancelled){ee($);const[O]=$;O!==void 0&&ye(J=>J===""?O:J)}}catch{}})()),()=>{p.cancelled=!0}},[t]);const V=ge(()=>({list:p=>t.listStorageObjects({...p,bucket:W}),remove:p=>t.deleteStorageObject(p,{bucket:W}),signedUrl:(p,$)=>t.signedStorageUrl(p,{...$,bucket:W}),upload:p=>t.uploadStorageObject({...p,bucket:W})}),[W,t]),Y=ot(async(p,$,O,J=!1)=>{te.current+=1;const pe=te.current;x(void 0),w(!0);try{const se=await V.list({cursor:$,limit:e,prefix:p});if(pe!==te.current)return;g(ke=>O&&ke!==void 0?[...ke,...se.objects]:se.objects),F(se.cursor)}catch(se){if(pe!==te.current)return;if(O||g(void 0),x(ie(se)),J)throw se}finally{pe===te.current&&w(!1)}},[e,V]);ne(()=>{q(Y(d??"",void 0,!1))},[Y,d]);const Ke=(y?.length??0)<=e;xt(()=>Y(s,void 0,!1,!0),Ke);const{files:ue,folders:Be}=_t(y??[],s),Le=ge(()=>{const p=new Set;for(const $ of ue)for(const O of Object.keys($.customMetadata??{}))p.add(O);return[...p].toSorted(($,O)=>$.localeCompare(O))},[ue]),ce=Et(ue,k,v),he=ge(()=>[...new Set(ce.map(p=>p.key))].toSorted((p,$)=>p.localeCompare($)).join(`
3
3
  `),[ce]);ne(()=>{const p=he===""?[]:he.split(`
4
4
  `);if(p.length===0){j({});return}const $={current:!0};return q((async()=>{try{const O=await t.query(Gt,{keys:p},Se(_));$.current&&(j(O.references??{}),D(Object.keys(O.storageColumns??{}).length>0))}catch{$.current&&(j({}),D(!1))}})()),()=>{$.current=!1}},[t,he,_]);const{allSelected:Ie,clear:re,selected:xe,someSelected:Oe,toggle:Ae,toggleAll:Ue}=Mt(ce,Zt),Me=()=>{n(l),re(),q(Y(l,void 0,!1))},Ge=()=>{q(Y(s,T,!0))},ve=p=>{n(p),a(p),re(),q(Y(p,void 0,!1))},He=p=>{ve(`${s}${p}`)},Pe=p=>V.signedUrl(p,{expiresInSeconds:Wt}),qe=()=>{h("list")},We=()=>{h("grid")},Ve=p=>{i(p)},Ze=()=>{S(p=>p==="asc"?"desc":"asc")},Xe=p=>{m(p)},Ye=p=>{o(p)},me=p=>{const $=ae.current;x(void 0),w(!0),q((async()=>{try{await p(),$===ae.current&&await Y(s,void 0,!1)}catch(O){x(ie(O))}$===ae.current&&w(!1)})())},Je=()=>{me(async()=>{for(const p of xe)await V.remove(p);re()})},Qe=p=>{x(void 0),q((async()=>{try{const $=await V.signedUrl(p,{expiresInSeconds:c});mt($)&&E(p)}catch($){x(ie($))}})())},et=p=>{x(void 0),q((async()=>{try{const $=await V.signedUrl(p,{expiresInSeconds:c}),O=p.slice(p.lastIndexOf("/")+1)||p;Vt($,O)}catch($){x(ie($))}})())};ne(()=>{if(C===void 0)return;const p=globalThis.setTimeout(()=>{E(void 0)},2e3);return()=>{globalThis.clearTimeout(p)}},[C]);const tt=p=>{me(async()=>{await V.remove(p)})},st=p=>{const $=`${s}${p.name}`;me(async()=>{const O=await p.arrayBuffer();await V.upload({body:O,contentType:p.type===""?void 0:p.type,key:$})})};ne(()=>{X.current+=1,A(void 0),P(!1)},[_]);const lt=()=>{X.current+=1;const p=X.current;x(void 0),H(!0),q((async()=>{try{const{liveKeys:$,truncated:O}=await qt(V);if(O)p===X.current&&(A(void 0),P(!0));else{const J=await t.query(Ht,{liveKeys:$},Se(_));p===X.current&&(A(J.references??[]),P(J.truncated===!0))}}catch($){p===X.current&&(A(void 0),P(!1),x(ie($)))}p===X.current&&H(!1)})())},nt=p=>{te.current+=1,X.current+=1,ae.current+=1,ye(p),n(d??""),a(d??""),g(void 0),A(void 0),P(!1),re()};return{allSelected:Ie,bucket:W,buckets:Z,bulkDelete:Je,busy:N,checkOrphans:lt,clearSelection:re,copiedKey:C,danglingBusy:M,danglingReferences:K,danglingTruncated:G,draftPrefix:l,enterFolder:He,error:b,expiry:c,files:ce,folders:Be,hasObjects:y!==void 0&&y.length>0,hasStorageColumns:I,listFirst:Me,loaded:y!==void 0,loadMore:Ge,navigate:ve,nextCursor:T,onCopy:Qe,onDelete:tt,onDownload:et,onExpiryChange:Ye,onFile:st,onSortKeyChange:Ve,onThumbSizeChange:Xe,prefix:s,referenceShard:_,references:L,resolveUrl:Pe,selectBucket:nt,selected:xe,setDraftPrefix:a,setReferenceShard:z,showGrid:We,showList:qe,someSelected:Oe,sortDirection:v,sortKey:k,tagKeys:Le,thumbSize:u,toggleSelect:Ae,toggleSelectAll:Ue,toggleSortDirection:Ze,view:f}},Yt=100,Ne=d=>{const e=U(6),{label:t,onNavigate:s,target:n}=d;let l;e[0]!==s||e[1]!==n?(l=()=>{s(n)},e[0]=s,e[1]=n,e[2]=l):l=e[2];const a=l;let c;return e[3]!==a||e[4]!==t?(c=r("button",{className:"rounded px-1 text-muted-foreground outline-none hover:text-foreground focus-visible:text-foreground",onClick:a,type:"button",children:t}),e[3]=a,e[4]=t,e[5]=c):c=e[5],c},Jt=d=>{const e=U(11),{onNavigate:t,prefix:s,t:n}=d;let l;if(e[0]!==t||e[1]!==s||e[2]!==n){const a=s.split("/").filter(Qt);let c;e[4]!==n?(c=n("Folder path"),e[4]=n,e[5]=c):c=e[5];let o;e[6]!==n?(o=n("root"),e[6]=n,e[7]=o):o=e[7];let f;e[8]!==t||e[9]!==o?(f=r(Ne,{label:o,onNavigate:t,target:""}),e[8]=t,e[9]=o,e[10]=f):f=e[10],l=R("nav",{"aria-label":c,className:"flex flex-wrap items-center gap-0.5 text-xs","data-testid":"fb-breadcrumbs",children:[f,a.map((h,u)=>R("span",{className:"flex items-center gap-0.5",children:[r("span",{className:"text-muted-foreground/50",children:"/"}),r(Ne,{label:h,onNavigate:t,target:`${a.slice(0,u+1).join("/")}/`})]},`${h}-${u.toString()}`))]}),e[0]=t,e[1]=s,e[2]=n,e[3]=l}else l=e[3];return l},xs=({initialPrefix:d,pageSize:e=Yt})=>{const t=it(),s=Xt({initialPrefix:d,pageSize:e}),n=de(null),{onCopy:l,onDelete:a,onDownload:c,onFile:o,toggleSelect:f}=s,h={onCopy:l,onDelete:a,onDownload:c,onToggleSelect:f},u=()=>{n.current?.click()},m=i=>{const v=i.target,S=v.files?.[0];v.value="",S&&o(S)},k=s.loaded&&!s.hasObjects;return R("div",{className:"flex flex-col gap-3","data-testid":"lunora-file-browser",children:[r($t,{bucket:s.bucket,buckets:s.buckets,busy:s.busy,draftPrefix:s.draftPrefix,expiry:s.expiry,fileInputRef:n,onBucketChange:s.selectBucket,onExpiryChange:s.onExpiryChange,onFileChange:m,onList:s.listFirst,onPrefixChange:s.setDraftPrefix,onUploadClick:u,t}),s.loaded&&r(Jt,{onNavigate:s.navigate,prefix:s.prefix,t}),s.hasObjects&&r(Ft,{onSortKeyChange:s.onSortKeyChange,onThumbSizeChange:s.onThumbSizeChange,showGrid:s.showGrid,showList:s.showList,sortDirection:s.sortDirection,sortKey:s.sortKey,t,tagKeys:s.tagKeys,thumbSize:s.thumbSize,toggleSortDirection:s.toggleSortDirection,view:s.view}),s.hasStorageColumns&&R("div",{className:"flex flex-wrap items-center gap-2","data-testid":"fb-references-shard",children:[r("label",{className:"text-xs text-muted-foreground",htmlFor:"fb-reference-shard-input",children:t("References shard")}),r(rt,{id:"fb-reference-shard-input",onChange:s.setReferenceShard,testId:"fb-reference-shard-input",value:s.referenceShard}),r("span",{className:"text-xs text-muted-foreground",children:t("Which shard's records are checked for references to these files. Empty = root shard.")})]}),s.hasStorageColumns&&r(Ut,{busy:s.danglingBusy,onCheck:s.checkOrphans,references:s.danglingReferences,t,truncated:s.danglingTruncated}),s.selected.size>0&&r(at,{count:s.selected.size,editable:!0,onClear:s.clearSelection,onDelete:s.bulkDelete}),s.error!==void 0&&r("p",{className:"text-sm text-destructive","data-testid":"storage-error",role:"alert",children:s.error}),k&&r(Te,{description:t("Objects you upload to your R2 buckets will appear here."),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:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z"}),r("path",{d:"M12 11v5m-2.5-2.5h5"})]}),testId:"fb-empty",title:t("No objects.")}),s.hasObjects&&s.view==="list"&&r(Ct,{allSelected:s.allSelected,busy:s.busy,copiedKey:s.copiedKey,files:s.files,folders:s.folders,handlers:h,onEnterFolder:s.enterFolder,prefix:s.prefix,references:s.references,selected:s.selected,showReferences:s.hasStorageColumns,someSelected:s.someSelected,t,toggleSelectAll:s.toggleSelectAll}),s.hasObjects&&s.view==="grid"&&r(Ot,{busy:s.busy,copiedKey:s.copiedKey,files:s.files,folders:s.folders,handlers:h,onEnterFolder:s.enterFolder,prefix:s.prefix,references:s.references,resolveUrl:s.resolveUrl,selected:s.selected,showReferences:s.hasStorageColumns,size:s.thumbSize,t}),s.nextCursor!==void 0&&r("div",{children:r(oe,{"data-testid":"fb-next",disabled:s.busy,onClick:s.loadMore,size:"sm",type:"button",variant:"outline",children:t("Load more")})})]})};function Qt(d){return d!==""}export{xs as FileBrowser};
@@ -1 +1 @@
1
- import{encodeWire as U,decodeWire as ee}from"@lunora/wire";import{useState as u,useEffect as te}from"react";import{ConfirmButton as re}from"../packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{ShardInput as se}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{B as z}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as k}from"../packem_shared/button-q0UYSmrn.mjs";import{I as ne}from"../packem_shared/input-CXhxesPC.mjs";import{L as R}from"../packem_shared/label-DKFzyHq6.mjs";import{T as oe}from"../packem_shared/textarea--40GKAyz.mjs";import{u as ae}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as ie}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as ce}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{b as J,h as le,f as de,k as ue,m as fe,c as he}from"../packem_shared/internal-BXEjuLPN.mjs";import{r as pe}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{jsxs as d,jsx as a}from"react/jsx-runtime";const me=t=>t.kind==="id"?t.table===void 0?"id":`id<${t.table}>`:t.kind==="array"?t.element===void 0?"array":`${t.element}[]`:t.kind,ge=t=>t===void 0||t.length===0?"()":`(${t.map(e=>`${e.name}${e.optional?"?":""}: ${me(e)}`).join(", ")})`,be=t=>{switch(t){case"array":return[];case"bigint":return U(0n);case"boolean":return!1;case"bytes":return U(new ArrayBuffer(0));case"number":return 0;case"object":case"record":return{};default:return""}},xe=t=>{const e={};for(const r of t??[])r.optional||(e[r.name]=be(r.kind));return JSON.stringify(e,void 0,2)},ye=he(ce.runAs),m="«sensitive»",ve=t=>(t??[]).filter(e=>e.sensitive===!0).map(e=>e.name),Ne=(t,e)=>{if(e.length===0)return t;try{const r=JSON.parse(t);if(typeof r!="object"||r===null||Array.isArray(r))return"";const i={...r};for(const n of e)Object.hasOwn(i,n)&&(i[n]=m);return JSON.stringify(i,null,2)}catch{return""}},Se=4,Ae=t=>{const e=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{return}},we=t=>Array.isArray(t)?[]:Object.keys(t).filter(e=>e.length>0),ke=t=>{const e=[],r=new Set,i=[t];for(;i.length>0;){const n=i.pop();if(typeof n=="string")n.length>0&&e.push(n);else if(typeof n=="number"||typeof n=="bigint")e.push(String(n));else if(n instanceof ArrayBuffer||ArrayBuffer.isView(n)){const l=Ae(n);l!==void 0&&l.length>0&&e.push(l)}else typeof n=="object"&&n!==null&&!r.has(n)&&(r.add(n),e.push(...we(n)),i.push(...Object.values(n)))}return e},Re=(t,e)=>{const r=[],i=new Set,n=[[t,e]];for(;n.length>0;){const[l,o]=n.pop()??[void 0,void 0];typeof o=="boolean"?r.push({key:l,text:o?"true":"false"}):typeof o=="object"&&o!==null&&!i.has(o)&&(i.add(o),Array.isArray(o)?n.push(...o.map(h=>[void 0,h])):n.push(...Object.entries(o)))}return r},P=t=>t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`),Oe=(t,e)=>e.length>=Se?t.replaceAll(e,m):t.replaceAll(new RegExp(`(?<![A-Za-z0-9])${P(e)}(?![A-Za-z0-9])`,"gu"),m),Ie=(t,e)=>{const r=t.replaceAll(`"${e.text}"`,m);if(e.key===void 0)return r;const i=P(e.key);return r.replaceAll(new RegExp(`(?<![A-Za-z0-9_])${i}=${e.text}(?![A-Za-z0-9_])`,"gu"),`${e.key}=${m}`).replaceAll(new RegExp(String.raw`"${i}":\s*${e.text}(?![A-Za-z0-9_])`,"gu"),`"${e.key}":${m}`)},$e=(t,e,r)=>{if(r.length===0||typeof e!="object"||e===null)return t;const i=r.flatMap(o=>Re(o,e[o])),n=r.flatMap(o=>ke(e[o])).flatMap(o=>{const h=JSON.stringify(o).slice(1,-1);return h===o?[o]:[o,h]}).toSorted((o,h)=>h.length-o.length);let l=t;for(const o of i)l=Ie(l,o);for(const o of n)l=Oe(l,o);return l},Te=10,Ce=t=>t===void 0?"undefined":JSON.stringify(t,ue,2),Ee=(t,e)=>[{argsText:Ne(e.argsText,e.sensitive),at:Date.now(),id:(t[0]?.id??0)+1,kind:e.selected.kind,path:e.selected.path,redacted:e.sensitive.length>0,shardKey:e.shardKey,status:e.runStatus},...t].slice(0,Te),Ge=({functions:t,runAsIdentity:e=!1}={})=>{const r=ie(),i=ae(),[n,l]=u(null),[o,h]=u(null),S=t??n??[],[O,I]=u(""),[y,A]=u("{}"),[g,$]=u(""),[b,V]=u(""),[w,x]=u("idle"),[Z,v]=u(void 0),[T,N]=u(null),[C,q]=u([]);te(()=>{if(t!==void 0)return;let s=!1;return i.listFunctions().then(f=>(s||l(f),f)).catch(f=>{s||h(J(f))}),()=>{s=!0}},[i,t]);const E=O===""?S[0]?.path??"":O,c=S.find(s=>s.path===E),H=async()=>{if(!c)return;let s;try{s=y.trim()===""?{}:ee(JSON.parse(y))}catch(p){x("error"),v(void 0),N(r("Invalid JSON args: {message}",{message:p.message}));return}const f={__lunoraRef:c.path},L=g.trim()===""?{}:{shardKey:g.trim()},K=e?b.trim():"",D=ve(c.args),M=p=>{q(Q=>Ee(Q,{argsText:y,runStatus:p,selected:c,sensitive:D,shardKey:g}))};x("running"),N(null);try{const p=K===""?await fe(i,c.kind,f,s,L):await i.query(ye,{args:s,functionPath:c.path,userId:K},L);pe(g),v(p),x("success"),M("success")}catch(p){v(void 0),N($e(J(p),s,D)),x("error"),M("error")}},G=s=>{if(I(s.path),$(s.shardKey),s.redacted){v(void 0),N(r("Re-enter the sensitive values before running this again.")),x("error");return}A(s.argsText)},W=s=>{I(s.target.value)},X=s=>{A(s.target.value)},Y=s=>{V(s.target.value)},j=()=>{de(H())},B=e?b.trim():"",F=w==="running"||c===void 0,_=()=>{A(xe(c?.args))};return d("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-runner",children:[o!==null&&a("p",{className:"text-sm text-destructive","data-testid":"function-discover-error",role:"alert",children:o}),d("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4",children:[d("div",{className:"flex flex-col gap-1.5",children:[a(R,{htmlFor:"function-select",children:r("Function")}),a("select",{"aria-label":r("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50","data-testid":"function-select",id:"function-select",onChange:W,value:E,children:S.map(s=>d("option",{value:s.path,children:[s.path," (",s.kind,")"]},s.path))}),c!==void 0&&d("p",{className:"text-xs text-muted-foreground",children:[a("span",{className:"mr-1.5 font-medium",children:r("Signature")}),a("code",{className:"font-mono","data-testid":"function-signature",children:ge(c.args)})]})]}),d("div",{className:"flex flex-col gap-1.5",children:[d("div",{className:"flex items-center justify-between gap-2",children:[a(R,{htmlFor:"args-input",children:r("Arguments")}),a(k,{"data-testid":"prefill-button",disabled:c===void 0,onClick:_,size:"xs",type:"button",variant:"ghost",children:r("Prefill")})]}),a(oe,{"aria-label":r("Arguments"),className:"font-mono text-xs","data-testid":"args-input",id:"args-input",onChange:X,value:y})]}),a(se,{onChange:$,testId:"shard-input",value:g}),e&&d("div",{className:"flex flex-col gap-1.5","data-testid":"run-as-field",children:[a(R,{htmlFor:"run-as-input",children:r("Run as identity (userId)")}),a(ne,{"aria-label":r("Run as identity (userId)"),className:"font-mono text-xs","data-testid":"run-as-input",id:"run-as-input",onChange:Y,placeholder:r("Leave empty to run as admin"),value:b}),a("p",{className:"text-[11px] text-muted-foreground",children:r("Dev only: runs the function as this user so you can test auth and RLS. Forged over the admin gate.")})]}),d("div",{className:"flex flex-wrap items-center gap-2",children:[B!==""&&c!==void 0&&c.kind!=="query"?a(re,{confirmLabel:r("This will execute `{functionPath}` as user `{userId}`.",{functionPath:c.path,userId:B}),disabled:F,onConfirm:j,testId:"run-button",children:r("Run")}):a(k,{"data-testid":"run-button",disabled:F,onClick:j,type:"button",children:r("Run")}),c!==void 0&&a(z,{variant:"outline",children:c.kind}),e&&b.trim()!==""&&a(z,{"data-testid":"run-as-badge",variant:"secondary",children:r("as {userId}",{userId:b.trim()})})]})]}),w==="error"&&T!==null&&a("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"error",role:"alert",children:T}),w==="success"&&a("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"result",children:Ce(Z)}),C.length>0&&a("ul",{className:"flex flex-col overflow-hidden rounded-xl border border-border","data-testid":"fn-history",children:C.map((s,f)=>d("li",{className:"flex flex-wrap items-center gap-2 border-b border-border px-3 py-2 text-sm last:border-b-0","data-testid":"fn-history-row",children:[a("span",{className:s.status==="success"?"text-success":"text-destructive","data-testid":`fn-history-status-${f.toString()}`,children:s.status==="success"?"✓":"✗"})," ",d("span",{className:"font-mono text-xs",children:[s.path," (",s.kind,")"]})," ",a("time",{className:"text-xs text-muted-foreground",children:le(s.at)})," ",a(k,{className:"ml-auto","data-testid":`fn-history-load-${f.toString()}`,onClick:()=>{G(s)},size:"xs",type:"button",variant:"ghost",children:r("Load")})]},s.id))})]})};export{Ge as FunctionRunner};
1
+ import{encodeWire as U,decodeWire as ee}from"@lunora/wire";import{useState as u,useEffect as te}from"react";import{ConfirmButton as re}from"../packem_shared/ConfirmButton-CIXYF6Mg.mjs";import{ShardInput as se}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{B as z}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as k}from"../packem_shared/button-q0UYSmrn.mjs";import{I as ne}from"../packem_shared/input-CXhxesPC.mjs";import{L as R}from"../packem_shared/label-DKFzyHq6.mjs";import{T as oe}from"../packem_shared/textarea--40GKAyz.mjs";import{u as ae}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as ie}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as ce}from"../packem_shared/ADMIN_FUNCTIONS-4aGsMs95.mjs";import{b as J,h as le,f as de,k as ue,m as fe,c as he}from"../packem_shared/internal-BXEjuLPN.mjs";import{r as pe}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{jsxs as d,jsx as a}from"react/jsx-runtime";const me=t=>t.kind==="id"?t.table===void 0?"id":`id<${t.table}>`:t.kind==="array"?t.element===void 0?"array":`${t.element}[]`:t.kind,ge=t=>t===void 0||t.length===0?"()":`(${t.map(e=>`${e.name}${e.optional?"?":""}: ${me(e)}`).join(", ")})`,be=t=>{switch(t){case"array":return[];case"bigint":return U(0n);case"boolean":return!1;case"bytes":return U(new ArrayBuffer(0));case"number":return 0;case"object":case"record":return{};default:return""}},xe=t=>{const e={};for(const r of t??[])r.optional||(e[r.name]=be(r.kind));return JSON.stringify(e,void 0,2)},ye=he(ce.runAs),m="«sensitive»",ve=t=>(t??[]).filter(e=>e.sensitive===!0).map(e=>e.name),Ne=(t,e)=>{if(e.length===0)return t;try{const r=JSON.parse(t);if(typeof r!="object"||r===null||Array.isArray(r))return"";const i={...r};for(const n of e)Object.hasOwn(i,n)&&(i[n]=m);return JSON.stringify(i,null,2)}catch{return""}},Se=4,Ae=t=>{const e=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);try{return new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{return}},we=t=>Array.isArray(t)?[]:Object.keys(t).filter(e=>e.length>0),ke=t=>{const e=[],r=new Set,i=[t];for(;i.length>0;){const n=i.pop();if(typeof n=="string")n.length>0&&e.push(n);else if(typeof n=="number"||typeof n=="bigint")e.push(String(n));else if(n instanceof ArrayBuffer||ArrayBuffer.isView(n)){const l=Ae(n);l!==void 0&&l.length>0&&e.push(l)}else typeof n=="object"&&n!==null&&!r.has(n)&&(r.add(n),e.push(...we(n)),i.push(...Object.values(n)))}return e},Re=(t,e)=>{const r=[],i=new Set,n=[[t,e]];for(;n.length>0;){const[l,o]=n.pop()??[void 0,void 0];typeof o=="boolean"?r.push({key:l,text:o?"true":"false"}):typeof o=="object"&&o!==null&&!i.has(o)&&(i.add(o),Array.isArray(o)?n.push(...o.map(h=>[void 0,h])):n.push(...Object.entries(o)))}return r},P=t=>t.replaceAll(/[$()*+.?[\\\]^{|}]/gu,String.raw`\$&`),Oe=(t,e)=>e.length>=Se?t.replaceAll(e,m):t.replaceAll(new RegExp(`(?<![A-Za-z0-9])${P(e)}(?![A-Za-z0-9])`,"gu"),m),Ie=(t,e)=>{const r=t.replaceAll(`"${e.text}"`,m);if(e.key===void 0)return r;const i=P(e.key);return r.replaceAll(new RegExp(`(?<![A-Za-z0-9_])${i}=${e.text}(?![A-Za-z0-9_])`,"gu"),`${e.key}=${m}`).replaceAll(new RegExp(String.raw`"${i}":\s*${e.text}(?![A-Za-z0-9_])`,"gu"),`"${e.key}":${m}`)},$e=(t,e,r)=>{if(r.length===0||typeof e!="object"||e===null)return t;const i=r.flatMap(o=>Re(o,e[o])),n=r.flatMap(o=>ke(e[o])).flatMap(o=>{const h=JSON.stringify(o).slice(1,-1);return h===o?[o]:[o,h]}).toSorted((o,h)=>h.length-o.length);let l=t;for(const o of i)l=Ie(l,o);for(const o of n)l=Oe(l,o);return l},Te=10,Ce=t=>t===void 0?"undefined":JSON.stringify(t,ue,2),Ee=(t,e)=>[{argsText:Ne(e.argsText,e.sensitive),at:Date.now(),id:(t[0]?.id??0)+1,kind:e.selected.kind,path:e.selected.path,redacted:e.sensitive.length>0,shardKey:e.shardKey,status:e.runStatus},...t].slice(0,Te),Ge=({functions:t,runAsIdentity:e=!1}={})=>{const r=ie(),i=ae(),[n,l]=u(null),[o,h]=u(null),S=t??n??[],[O,I]=u(""),[y,A]=u("{}"),[g,$]=u(""),[b,V]=u(""),[w,x]=u("idle"),[Z,v]=u(void 0),[T,N]=u(null),[C,q]=u([]);te(()=>{if(t!==void 0)return;let s=!1;return i.listFunctions().then(f=>(s||l(f),f)).catch(f=>{s||h(J(f))}),()=>{s=!0}},[i,t]);const E=O===""?S[0]?.path??"":O,c=S.find(s=>s.path===E),H=async()=>{if(!c)return;let s;try{s=y.trim()===""?{}:ee(JSON.parse(y))}catch(p){x("error"),v(void 0),N(r("Invalid JSON args: {message}",{message:p.message}));return}const f={__lunoraRef:c.path},L=g.trim()===""?{}:{shardKey:g.trim()},K=e?b.trim():"",D=ve(c.args),M=p=>{q(Q=>Ee(Q,{argsText:y,runStatus:p,selected:c,sensitive:D,shardKey:g}))};x("running"),N(null);try{const p=K===""?await fe(i,c.kind,f,s,L):await i.query(ye,{args:s,functionPath:c.path,userId:K},L);pe(g),v(p),x("success"),M("success")}catch(p){v(void 0),N($e(J(p),s,D)),x("error"),M("error")}},G=s=>{if(I(s.path),$(s.shardKey),s.redacted){v(void 0),N(r("Re-enter the sensitive values before running this again.")),x("error");return}A(s.argsText)},W=s=>{I(s.target.value)},X=s=>{A(s.target.value)},Y=s=>{V(s.target.value)},j=()=>{de(H())},B=e?b.trim():"",F=w==="running"||c===void 0,_=()=>{A(xe(c?.args))};return d("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-runner",children:[o!==null&&a("p",{className:"text-sm text-destructive","data-testid":"function-discover-error",role:"alert",children:o}),d("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4",children:[d("div",{className:"flex flex-col gap-1.5",children:[a(R,{htmlFor:"function-select",children:r("Function")}),a("select",{"aria-label":r("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50","data-testid":"function-select",id:"function-select",onChange:W,value:E,children:S.map(s=>d("option",{value:s.path,children:[s.path," (",s.kind,")"]},s.path))}),c!==void 0&&d("p",{className:"text-xs text-muted-foreground",children:[a("span",{className:"mr-1.5 font-medium",children:r("Signature")}),a("code",{className:"font-mono","data-testid":"function-signature",children:ge(c.args)})]})]}),d("div",{className:"flex flex-col gap-1.5",children:[d("div",{className:"flex items-center justify-between gap-2",children:[a(R,{htmlFor:"args-input",children:r("Arguments")}),a(k,{"data-testid":"prefill-button",disabled:c===void 0,onClick:_,size:"xs",type:"button",variant:"ghost",children:r("Prefill")})]}),a(oe,{"aria-label":r("Arguments"),className:"font-mono text-xs","data-testid":"args-input",id:"args-input",onChange:X,value:y})]}),a(se,{onChange:$,testId:"shard-input",value:g}),e&&d("div",{className:"flex flex-col gap-1.5","data-testid":"run-as-field",children:[a(R,{htmlFor:"run-as-input",children:r("Run as identity (userId)")}),a(ne,{"aria-label":r("Run as identity (userId)"),className:"font-mono text-xs","data-testid":"run-as-input",id:"run-as-input",onChange:Y,placeholder:r("Leave empty to run as admin"),value:b}),a("p",{className:"text-[11px] text-muted-foreground",children:r("Dev only: runs the function as this user so you can test auth and RLS. Forged over the admin gate.")})]}),d("div",{className:"flex flex-wrap items-center gap-2",children:[B!==""&&c!==void 0&&c.kind!=="query"?a(re,{confirmLabel:r("This will execute `{functionPath}` as user `{userId}`.",{functionPath:c.path,userId:B}),disabled:F,onConfirm:j,testId:"run-button",children:r("Run")}):a(k,{"data-testid":"run-button",disabled:F,onClick:j,type:"button",children:r("Run")}),c!==void 0&&a(z,{variant:"outline",children:c.kind}),e&&b.trim()!==""&&a(z,{"data-testid":"run-as-badge",variant:"secondary",children:r("as {userId}",{userId:b.trim()})})]})]}),w==="error"&&T!==null&&a("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"error",role:"alert",children:T}),w==="success"&&a("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"result",children:Ce(Z)}),C.length>0&&a("ul",{className:"flex flex-col overflow-hidden rounded-xl border border-border","data-testid":"fn-history",children:C.map((s,f)=>d("li",{className:"flex flex-wrap items-center gap-2 border-b border-border px-3 py-2 text-sm last:border-b-0","data-testid":"fn-history-row",children:[a("span",{className:s.status==="success"?"text-success":"text-destructive","data-testid":`fn-history-status-${f.toString()}`,children:s.status==="success"?"✓":"✗"})," ",d("span",{className:"font-mono text-xs",children:[s.path," (",s.kind,")"]})," ",a("time",{className:"text-xs text-muted-foreground",children:le(s.at)})," ",a(k,{className:"ml-auto","data-testid":`fn-history-load-${f.toString()}`,onClick:()=>{G(s)},size:"xs",type:"button",variant:"ghost",children:r("Load")})]},s.id))})]})};export{Ge as FunctionRunner};
@@ -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-54TiaMvZ.mjs";import{L as W}from"../packem_shared/live-status-D1GasNsH.mjs";import{ShardInput as G}from"../packem_shared/ShardInput-CoySruKZ.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-BW9IuacC.mjs";import{u as ae}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.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-54TiaMvZ.mjs";import{L as W}from"../packem_shared/live-status-D1GasNsH.mjs";import{ShardInput as G}from"../packem_shared/ShardInput-CoySruKZ.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-BW9IuacC.mjs";import{u as ae}from"../packem_shared/use-shard-key-BsP3o5wT.mjs";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-4aGsMs95.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 se}from"react/compiler-runtime";import{useState as F,useRef as Z,useCallback as xe,useEffect as ie}from"react";import ve from"../packem_shared/ConnectionBadge-BfcoN-VE.mjs";import{L as Ne}from"../packem_shared/live-status-D1GasNsH.mjs";import{B as te}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as X}from"../packem_shared/card-By2O8ULa.mjs";import{u as be}from"../packem_shared/use-admin-query-BW9IuacC.mjs";import{u as Se}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as z}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{h as ye,f as ae,d as ce,b as ue,c as J}from"../packem_shared/internal-BXEjuLPN.mjs";import{l as Ee}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{c as W}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as a,jsxs as m}from"react/jsx-runtime";import{shardsToAggregate as we}from"../packem_shared/aggregateMetrics-DKFJc-o5.mjs";import{S as ne}from"../packem_shared/sparkline-B_sPPO_8.mjs";const Te={crit:"destructive",ok:"secondary",warn:"default"},re=(s,e)=>e===0?"—":`${(s/e*100).toFixed(1)}%`,oe=(s,e,l)=>Number.isNaN(s)?"ok":s>=l?"crit":s>=e?"warn":"ok",me=.01,he=.05,_e=s=>{const e=se(36),{errorCount:l,logsError:t,topErrors:r,worstFunctions:c}=s,i=le();let n;e[0]!==i?(n=i("Functions by error rate"),e[0]=i,e[1]=n):n=e[1];let o;e[2]!==n?(o=a("header",{className:"border-b border-border px-4 py-3",children:a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n})}),e[2]=n,e[3]=o):o=e[3];let d;e[4]!==i||e[5]!==c?(d=c.length===0?a("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:i("No function activity yet.")}):a("ul",{className:"divide-y divide-border",children:c.map(b=>m("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[a("span",{className:"truncate font-mono text-foreground",children:b.path}),m("span",{className:"flex shrink-0 items-center gap-2",children:[a("span",{className:"tabular-nums text-muted-foreground",children:i("{count} calls",{count:b.calls.toString()})}),a(te,{variant:Te[oe(b.errors/b.calls,me,he)],children:re(b.errors,b.calls)})]})]},b.path))}),e[4]=i,e[5]=c,e[6]=d):d=e[6];let p;e[7]!==o||e[8]!==d?(p=m(X,{className:"gap-0 py-0","data-testid":"hl-functions",children:[o,d]}),e[7]=o,e[8]=d,e[9]=p):p=e[9];let x;e[10]!==i?(x=i("Recent errors"),e[10]=i,e[11]=x):x=e[11];let f;e[12]!==x?(f=a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:x}),e[12]=x,e[13]=f):f=e[13];const u=l>0?"destructive":"outline";let g;e[14]!==l||e[15]!==u?(g=a(te,{"data-testid":"hl-error-count",variant:u,children:l}),e[14]=l,e[15]=u,e[16]=g):g=e[16];let h;e[17]!==f||e[18]!==g?(h=m("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[f,g]}),e[17]=f,e[18]=g,e[19]=h):h=e[19];let E;e[20]!==t?(E=t!==null&&a("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]=E):E=e[21];let w;e[22]!==t||e[23]!==i||e[24]!==r.length?(w=t===null&&r.length===0&&a("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:i("No recent errors.")}),e[22]=t,e[23]=i,e[24]=r.length,e[25]=w):w=e[25];let T;e[26]!==r?(T=r.length>0&&a("ul",{className:"divide-y divide-border",children:r.map(Ae)}),e[26]=r,e[27]=T):T=e[27];let S;e[28]!==E||e[29]!==w||e[30]!==T||e[31]!==h?(S=m(X,{className:"gap-0 py-0",children:[h,E,w,T]}),e[28]=E,e[29]=w,e[30]=T,e[31]=h,e[32]=S):S=e[32];let y;return e[33]!==S||e[34]!==p?(y=m("div",{className:"grid gap-3 lg:grid-cols-2",children:[p,S]}),e[33]=S,e[34]=p,e[35]=y):y=e[35],y};function Ae(s,e){return m("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[m("span",{className:"flex items-center gap-2",children:[a("time",{className:"shrink-0 text-muted-foreground",children:ye(s.timestamp)}),s.functionPath!==void 0&&a("span",{className:"truncate font-mono text-foreground",children:s.functionPath})]}),a("span",{className:"text-destructive",children:s.message})]},`${s.timestamp.toString()}-${e.toString()}`)}const de={completed:0,failed:2,in_progress:1},ke=s=>{let e=0,l=0,t=0,r=0,c=!1;const i=[];for(const{metrics:n}of s){if(n===null){r+=1;continue}t+=1,e+=n.requests,l+=n.errors,i.push(...n.history??[]),c||=n.historyTruncated===!0}return{errors:l,failed:r,history:i,historyTruncated:c,reachable:t,requests:e}},Re=s=>{const e=new Map;for(const l of s)for(const t of l){const r=e.get(t.path);if(r===void 0){e.set(t.path,{...t});continue}r.calls+=t.calls,r.errors+=t.errors,r.totalDurationMs+=t.totalDurationMs,r.scans=(r.scans??0)+(t.scans??0),r.maxDurationMs=Math.max(r.maxDurationMs,t.maxDurationMs),r.lastCalledAt=Math.max(r.lastCalledAt,t.lastCalledAt),(t.lastErrorAt??0)>(r.lastErrorAt??0)&&(r.lastErrorAt=t.lastErrorAt,r.lastErrorMessage=t.lastErrorMessage)}return[...e.values()]},Me=s=>{const e=new Map;for(const l of s)for(const t of l){const r=e.get(t.id);if(r===void 0){e.set(t.id,t);continue}const c=de[t.status]-de[r.status];(c>0||c===0&&(t.updatedAt??0)>(r.updatedAt??0))&&e.set(t.id,t)}return[...e.values()]},Le=J(z.getAuthMetrics),Ie=J(z.getFunctionStats),Ce=J(z.getLogs),qe=J(z.getMetrics),Oe=J(z.migrationStatus),Fe=5,fe=2e3,De=5,je=.1,Ue=.3,Pe=1,Ge=50,$e=(s,e,l)=>s>=l?"crit":s>=e?"warn":"ok",Be=s=>{const e=new Map;for(const t of s??[]){const r=e.get(t.bucketMs)??{calls:0,errors:0};r.calls+=t.calls,r.errors+=t.errors,e.set(t.bucketMs,r)}const l=[...e.entries()].toSorted((t,r)=>t[0]-r[0]);return{errors:l.map(([,t])=>t.errors),requests:l.map(([,t])=>t.calls)}},Ve=s=>{let e=0,l=0;for(const r of s)r.status==="failed"?e+=1:r.status==="in_progress"&&(l+=1);let t="ok";return e>0?t="crit":l>0&&(t="warn"),{failed:e,level:t,running:l}},He=(s,e)=>s.failed>0?e("{count} failed",{count:s.failed.toString()}):s.running>0?e("{count} running",{count:s.running.toString()}):e("OK"),pe={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},ge={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},Ke={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},ze=s=>s.includes("crit")?"crit":s.includes("warn")?"warn":"ok",ee=s=>{const e=se(19),{chart:l,label:t,level:r,testId:c,value:i}=s,n=pe[r];let o;e[0]!==n?(o=W("size-1.5 shrink-0 rounded-full",n),e[0]=n,e[1]=o):o=e[1];let d;e[2]!==o?(d=a("span",{"aria-hidden":"true",className:o}),e[2]=o,e[3]=d):d=e[3];let p;e[4]!==t||e[5]!==d?(p=m("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]=p):p=e[6];const x=ge[r];let f;e[7]!==x?(f=W("truncate text-2xl font-semibold tabular-nums",x),e[7]=x,e[8]=f):f=e[8];let u;e[9]!==f||e[10]!==c||e[11]!==i?(u=a("span",{className:f,"data-testid":c,children:i}),e[9]=f,e[10]=c,e[11]=i,e[12]=u):u=e[12];let g;e[13]!==l||e[14]!==u?(g=m("div",{className:"flex items-center justify-between gap-3",children:[u,l]}),e[13]=l,e[14]=u,e[15]=g):g=e[15];let h;return e[16]!==p||e[17]!==g?(h=a(X,{className:"gap-0 py-0",children:m("div",{className:"flex flex-col gap-2.5 p-4",children:[p,g]})}),e[16]=p,e[17]=g,e[18]=h):h=e[18],h},Qe=async(s,e,l)=>{const t=await Promise.all(l.map(f=>{const u=ce(f);return Promise.allSettled([s.query(qe,{},u),s.query(Ie,{},u),s.query(Oe,{},u)])})),r=ce(e),c=typeof s.schedulerStatus=="function"?s.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[i,n,o]=await Promise.allSettled([s.query(Ce,{},r),s.query(Le,{},r),c]),d=t.map(([f,u,g])=>({functions:u.status==="fulfilled"?u.value.functions:[],metrics:f.status==="fulfilled"?f.value:null,migrations:g.status==="fulfilled"?g.value.migrations:[]})),p=ke(d),x=t[0]?.[0];return{auth:n.status==="fulfilled"?n.value:null,entries:i.status==="fulfilled"?i.value.entries:[],functions:Re(d.map(f=>f.functions)),logsError:i.status==="rejected"?ue(i.reason):null,metricsError:p.reachable===0&&x?.status==="rejected"?ue(x.reason):null,migrations:Me(d.map(f=>f.migrations)),scheduler:o.status==="fulfilled"?o.value:null,totals:p}},We=s=>{const e=s?.history??[];return{attempts:e.map(l=>l.attempts),failures:e.map(l=>l.failures)}},Xe=(s,e)=>s==="crit"?{description:e("One or more service levels are breached."),label:e("Critical")}:s==="warn"?{description:e("Some service levels need attention."),label:e("Degraded")}:{description:e("All service levels are within target."),label:e("All systems healthy")},Je=s=>{const e=se(75),{errorLevel:l,liveError:t,metricsError:r,overall:c,requestSeries:i,totals:n}=s,o=le();let d;e[0]!==c||e[1]!==o?(d=Xe(c,o),e[0]=c,e[1]=o,e[2]=d):d=e[2];const{description:p,label:x}=d,f=Ke[c];let u;e[3]!==f?(u=W("flex size-10 shrink-0 items-center justify-center rounded-full",f),e[3]=f,e[4]=u):u=e[4];const g=pe[c];let h;e[5]!==g?(h=W("size-3 rounded-full",g),e[5]=g,e[6]=h):h=e[6];let E;e[7]!==h?(E=a("span",{className:h}),e[7]=h,e[8]=E):E=e[8];let w;e[9]!==u||e[10]!==E?(w=a("span",{"aria-hidden":"true",className:u,children:E}),e[9]=u,e[10]=E,e[11]=w):w=e[11];let T;e[12]!==x?(T=a("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:x}),e[12]=x,e[13]=T):T=e[13];let S;e[14]!==p?(S=a("span",{className:"text-[13px] text-muted-foreground",children:p}),e[14]=p,e[15]=S):S=e[15];let y;e[16]!==T||e[17]!==S?(y=m("div",{className:"grid leading-tight",children:[T,S]}),e[16]=T,e[17]=S,e[18]=y):y=e[18];let b;e[19]!==y||e[20]!==w?(b=m("div",{className:"flex items-center gap-3",children:[w,y]}),e[19]=y,e[20]=w,e[21]=b):b=e[21];let k;e[22]!==o?(k=o("Requests"),e[22]=o,e[23]=k):k=e[23];let _;e[24]!==k?(_=a("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:k}),e[24]=k,e[25]=_):_=e[25];let A;e[26]!==i||e[27]!==o?(A=i.length>=2&&a(ne,{ariaLabel:o("Requests over time"),className:"h-6 w-20 text-foreground",series:i,testId:"hl-spark-requests"}),e[26]=i,e[27]=o,e[28]=A):A=e[28];const D=n?.requests??0;let j;e[29]!==D?(j=D.toString(),e[29]=D,e[30]=j):j=e[30];let I;e[31]!==j?(I=a("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:j}),e[31]=j,e[32]=I):I=e[32];let U;e[33]!==A||e[34]!==I?(U=m("div",{className:"flex items-center justify-end gap-2",children:[A,I]}),e[33]=A,e[34]=I,e[35]=U):U=e[35];let C;e[36]!==_||e[37]!==U?(C=m("div",{className:"text-end",children:[_,U]}),e[36]=_,e[37]=U,e[38]=C):C=e[38];let $;e[39]===Symbol.for("react.memo_cache_sentinel")?($=a("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),e[39]=$):$=e[39];let R;e[40]!==o?(R=o("Error rate"),e[40]=o,e[41]=R):R=e[41];let q;e[42]!==R?(q=a("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:R}),e[42]=R,e[43]=q):q=e[43];const Q=ge[l];let M;e[44]!==Q?(M=W("text-lg font-semibold tabular-nums",Q),e[44]=Q,e[45]=M):M=e[45];let P;e[46]!==n?(P=n===null?"—":re(n.errors,n.requests),e[46]=n,e[47]=P):P=e[47];let L;e[48]!==M||e[49]!==P?(L=a("div",{className:M,"data-testid":"hl-error-rate",children:P}),e[48]=M,e[49]=P,e[50]=L):L=e[50];let O;e[51]!==q||e[52]!==L?(O=m("div",{className:"text-end",children:[q,L]}),e[51]=q,e[52]=L,e[53]=O):O=e[53];let G;e[54]===Symbol.for("react.memo_cache_sentinel")?(G=a("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),e[54]=G):G=e[54];let B;e[55]===Symbol.for("react.memo_cache_sentinel")?(B=a(ve,{}),e[55]=B):B=e[55];let v;e[56]!==t?(v=m("div",{className:"flex items-center gap-2",children:[B,a(Ne,{message:t,prefix:"hl"})]}),e[56]=t,e[57]=v):v=e[57];let N;e[58]!==C||e[59]!==O||e[60]!==v?(N=m("div",{className:"flex flex-wrap items-center gap-4",children:[C,$,O,G,v]}),e[58]=C,e[59]=O,e[60]=v,e[61]=N):N=e[61];let V;e[62]!==b||e[63]!==N?(V=m("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[b,N]}),e[62]=b,e[63]=N,e[64]=V):V=e[64];let H;e[65]!==r?(H=r!==null&&a("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:r}),e[65]=r,e[66]=H):H=e[66];let K;e[67]!==r||e[68]!==o||e[69]!==n?.historyTruncated?(K=r===null&&n?.historyTruncated===!0&&a("div",{className:"border-t border-border bg-warning/5 px-4 py-2 text-sm text-muted-foreground","data-testid":"hl-history-truncated",children:o("Showing a partial request/error history — one or more shards have more data than the trend chart can display.")}),e[67]=r,e[68]=o,e[69]=n?.historyTruncated,e[70]=K):K=e[70];let Y;return e[71]!==V||e[72]!==H||e[73]!==K?(Y=m(X,{className:"gap-0 py-0",children:[V,H,K]}),e[71]=V,e[72]=H,e[73]=K,e[74]=Y):Y=e[74],Y},Ye=s=>{const e=se(14),{shards:l}=s,t=le();let r;e[0]!==t?(r=t("Shards seen"),e[0]=t,e[1]=r):r=e[1];let c;e[2]!==r?(c=a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r}),e[2]=r,e[3]=c):c=e[3];let i;e[4]!==l.length?(i=a(te,{"data-testid":"hl-shard-count",variant:"outline",children:l.length}),e[4]=l.length,e[5]=i):i=e[5];let n;e[6]!==c||e[7]!==i?(n=m("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[c,i]}),e[6]=c,e[7]=i,e[8]=n):n=e[8];let o;e[9]!==l?(o=l.length>0&&a("ul",{className:"flex flex-wrap gap-1.5 p-4",children:l.map(Ze)}),e[9]=l,e[10]=o):o=e[10];let d;return e[11]!==n||e[12]!==o?(d=m(X,{className:"gap-0 py-0",children:[n,o]}),e[11]=n,e[12]=o,e[13]=d):d=e[13],d},gt=({initialShardKey:s})=>{const e=Se(),l=le(),[t,r]=F([]),[c,i]=F(null),[n,o]=F(null),[d,p]=F(null),[x,f]=F([]),[u,g]=F(null),[h,E]=F(null),[w,T]=F([]),[S]=F(Ee),y=Z(!1),b=Z(0),k=Z(0),_=Z(null),A=s??"",D=xe(async()=>{if(y.current)return;y.current=!0;const v=b.current,N=await Qe(e,A,we(A,S));v===b.current&&(o(N.totals),p(N.metricsError),f(N.functions),T(N.migrations),r(N.entries),i(N.logsError),g(N.auth),E(N.scheduler),y.current=!1)},[e,S,A]);ie(()=>(ae(D()),()=>{b.current+=1,y.current=!1,_.current!==null&&(clearTimeout(_.current),_.current=null)}),[D]);const j=()=>{const v=Date.now()-k.current;if(v>=fe){k.current=Date.now(),ae(D());return}_.current===null&&(_.current=setTimeout(()=>{_.current=null,k.current=Date.now(),ae(D())},fe-v))},{data:I,liveError:U}=be(z.getMetrics,{},{live:!0,shardKey:A});ie(()=>{I!==void 0&&j()},[I]);const C=t.filter(v=>v.level==="error"),$=C.slice(0,Fe),R=Be(n?.history),q=We(u),Q=x.filter(v=>v.calls>0).toSorted((v,N)=>N.errors/N.calls-v.errors/v.calls||N.calls-v.calls).slice(0,De),M=Ve(w),P=n===null||n.requests===0?0:n.errors/n.requests,L=oe(P,me,he),O=u===null?"ok":oe(u.failureRate,je,Ue),G=h===null?"ok":$e(h.backlog,Pe,Ge),B=ze([L,O,G,M.level]);return m("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[a(Je,{errorLevel:L,liveError:U,metricsError:d,overall:B,requestSeries:R.requests,totals:n}),m("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[a(ee,{chart:R.errors.length>=2?a(ne,{ariaLabel:l("Errors over time"),className:"h-7 w-20 text-destructive",series:R.errors,testId:"hl-spark-errors"}):void 0,label:l("Error rate"),level:L,testId:"hl-slo-errorrate",value:n===null?"—":re(n.errors,n.requests)}),a(ee,{chart:q.failures.length>=2?a(ne,{ariaLabel:l("Auth failures over time"),className:"h-7 w-20 text-destructive",series:q.failures,testId:"hl-spark-auth"}):void 0,label:l("Auth failures"),level:O,testId:"hl-slo-auth",value:u===null?"—":re(u.failures,u.attempts)}),a(ee,{label:l("Scheduler backlog"),level:G,testId:"hl-slo-backlog",value:h===null?"—":h.backlog.toString()}),a(ee,{label:l("Migrations"),level:M.level,testId:"hl-slo-migrations",value:He(M,l)})]}),a(_e,{errorCount:C.length,logsError:c,topErrors:$,worstFunctions:Q}),a(Ye,{shards:S})]})};function Ze(s){return a("li",{"data-testid":"hl-shard",children:a(te,{variant:"secondary",children:s})},s)}export{gt as HealthPanel};
1
+ import{c as se}from"react/compiler-runtime";import{useState as F,useRef as Z,useCallback as xe,useEffect as ie}from"react";import ve from"../packem_shared/ConnectionBadge-BfcoN-VE.mjs";import{L as Ne}from"../packem_shared/live-status-D1GasNsH.mjs";import{B as te}from"../packem_shared/badge-r_5B4LHP.mjs";import{C as X}from"../packem_shared/card-By2O8ULa.mjs";import{u as be}from"../packem_shared/use-admin-query-BW9IuacC.mjs";import{u as Se}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as z}from"../packem_shared/ADMIN_FUNCTIONS-4aGsMs95.mjs";import{h as ye,f as ae,d as ce,b as ue,c as J}from"../packem_shared/internal-BXEjuLPN.mjs";import{l as Ee}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{c as W}from"../packem_shared/utils-bhneXptQ.mjs";import{jsx as a,jsxs as m}from"react/jsx-runtime";import{shardsToAggregate as we}from"../packem_shared/aggregateMetrics-DKFJc-o5.mjs";import{S as ne}from"../packem_shared/sparkline-B_sPPO_8.mjs";const Te={crit:"destructive",ok:"secondary",warn:"default"},re=(s,e)=>e===0?"—":`${(s/e*100).toFixed(1)}%`,oe=(s,e,l)=>Number.isNaN(s)?"ok":s>=l?"crit":s>=e?"warn":"ok",me=.01,he=.05,_e=s=>{const e=se(36),{errorCount:l,logsError:t,topErrors:r,worstFunctions:c}=s,i=le();let n;e[0]!==i?(n=i("Functions by error rate"),e[0]=i,e[1]=n):n=e[1];let o;e[2]!==n?(o=a("header",{className:"border-b border-border px-4 py-3",children:a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n})}),e[2]=n,e[3]=o):o=e[3];let d;e[4]!==i||e[5]!==c?(d=c.length===0?a("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:i("No function activity yet.")}):a("ul",{className:"divide-y divide-border",children:c.map(b=>m("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[a("span",{className:"truncate font-mono text-foreground",children:b.path}),m("span",{className:"flex shrink-0 items-center gap-2",children:[a("span",{className:"tabular-nums text-muted-foreground",children:i("{count} calls",{count:b.calls.toString()})}),a(te,{variant:Te[oe(b.errors/b.calls,me,he)],children:re(b.errors,b.calls)})]})]},b.path))}),e[4]=i,e[5]=c,e[6]=d):d=e[6];let p;e[7]!==o||e[8]!==d?(p=m(X,{className:"gap-0 py-0","data-testid":"hl-functions",children:[o,d]}),e[7]=o,e[8]=d,e[9]=p):p=e[9];let x;e[10]!==i?(x=i("Recent errors"),e[10]=i,e[11]=x):x=e[11];let f;e[12]!==x?(f=a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:x}),e[12]=x,e[13]=f):f=e[13];const u=l>0?"destructive":"outline";let g;e[14]!==l||e[15]!==u?(g=a(te,{"data-testid":"hl-error-count",variant:u,children:l}),e[14]=l,e[15]=u,e[16]=g):g=e[16];let h;e[17]!==f||e[18]!==g?(h=m("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[f,g]}),e[17]=f,e[18]=g,e[19]=h):h=e[19];let E;e[20]!==t?(E=t!==null&&a("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]=E):E=e[21];let w;e[22]!==t||e[23]!==i||e[24]!==r.length?(w=t===null&&r.length===0&&a("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:i("No recent errors.")}),e[22]=t,e[23]=i,e[24]=r.length,e[25]=w):w=e[25];let T;e[26]!==r?(T=r.length>0&&a("ul",{className:"divide-y divide-border",children:r.map(Ae)}),e[26]=r,e[27]=T):T=e[27];let S;e[28]!==E||e[29]!==w||e[30]!==T||e[31]!==h?(S=m(X,{className:"gap-0 py-0",children:[h,E,w,T]}),e[28]=E,e[29]=w,e[30]=T,e[31]=h,e[32]=S):S=e[32];let y;return e[33]!==S||e[34]!==p?(y=m("div",{className:"grid gap-3 lg:grid-cols-2",children:[p,S]}),e[33]=S,e[34]=p,e[35]=y):y=e[35],y};function Ae(s,e){return m("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[m("span",{className:"flex items-center gap-2",children:[a("time",{className:"shrink-0 text-muted-foreground",children:ye(s.timestamp)}),s.functionPath!==void 0&&a("span",{className:"truncate font-mono text-foreground",children:s.functionPath})]}),a("span",{className:"text-destructive",children:s.message})]},`${s.timestamp.toString()}-${e.toString()}`)}const de={completed:0,failed:2,in_progress:1},ke=s=>{let e=0,l=0,t=0,r=0,c=!1;const i=[];for(const{metrics:n}of s){if(n===null){r+=1;continue}t+=1,e+=n.requests,l+=n.errors,i.push(...n.history??[]),c||=n.historyTruncated===!0}return{errors:l,failed:r,history:i,historyTruncated:c,reachable:t,requests:e}},Re=s=>{const e=new Map;for(const l of s)for(const t of l){const r=e.get(t.path);if(r===void 0){e.set(t.path,{...t});continue}r.calls+=t.calls,r.errors+=t.errors,r.totalDurationMs+=t.totalDurationMs,r.scans=(r.scans??0)+(t.scans??0),r.maxDurationMs=Math.max(r.maxDurationMs,t.maxDurationMs),r.lastCalledAt=Math.max(r.lastCalledAt,t.lastCalledAt),(t.lastErrorAt??0)>(r.lastErrorAt??0)&&(r.lastErrorAt=t.lastErrorAt,r.lastErrorMessage=t.lastErrorMessage)}return[...e.values()]},Me=s=>{const e=new Map;for(const l of s)for(const t of l){const r=e.get(t.id);if(r===void 0){e.set(t.id,t);continue}const c=de[t.status]-de[r.status];(c>0||c===0&&(t.updatedAt??0)>(r.updatedAt??0))&&e.set(t.id,t)}return[...e.values()]},Le=J(z.getAuthMetrics),Ie=J(z.getFunctionStats),Ce=J(z.getLogs),qe=J(z.getMetrics),Oe=J(z.migrationStatus),Fe=5,fe=2e3,De=5,je=.1,Ue=.3,Pe=1,Ge=50,$e=(s,e,l)=>s>=l?"crit":s>=e?"warn":"ok",Be=s=>{const e=new Map;for(const t of s??[]){const r=e.get(t.bucketMs)??{calls:0,errors:0};r.calls+=t.calls,r.errors+=t.errors,e.set(t.bucketMs,r)}const l=[...e.entries()].toSorted((t,r)=>t[0]-r[0]);return{errors:l.map(([,t])=>t.errors),requests:l.map(([,t])=>t.calls)}},Ve=s=>{let e=0,l=0;for(const r of s)r.status==="failed"?e+=1:r.status==="in_progress"&&(l+=1);let t="ok";return e>0?t="crit":l>0&&(t="warn"),{failed:e,level:t,running:l}},He=(s,e)=>s.failed>0?e("{count} failed",{count:s.failed.toString()}):s.running>0?e("{count} running",{count:s.running.toString()}):e("OK"),pe={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},ge={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},Ke={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},ze=s=>s.includes("crit")?"crit":s.includes("warn")?"warn":"ok",ee=s=>{const e=se(19),{chart:l,label:t,level:r,testId:c,value:i}=s,n=pe[r];let o;e[0]!==n?(o=W("size-1.5 shrink-0 rounded-full",n),e[0]=n,e[1]=o):o=e[1];let d;e[2]!==o?(d=a("span",{"aria-hidden":"true",className:o}),e[2]=o,e[3]=d):d=e[3];let p;e[4]!==t||e[5]!==d?(p=m("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]=p):p=e[6];const x=ge[r];let f;e[7]!==x?(f=W("truncate text-2xl font-semibold tabular-nums",x),e[7]=x,e[8]=f):f=e[8];let u;e[9]!==f||e[10]!==c||e[11]!==i?(u=a("span",{className:f,"data-testid":c,children:i}),e[9]=f,e[10]=c,e[11]=i,e[12]=u):u=e[12];let g;e[13]!==l||e[14]!==u?(g=m("div",{className:"flex items-center justify-between gap-3",children:[u,l]}),e[13]=l,e[14]=u,e[15]=g):g=e[15];let h;return e[16]!==p||e[17]!==g?(h=a(X,{className:"gap-0 py-0",children:m("div",{className:"flex flex-col gap-2.5 p-4",children:[p,g]})}),e[16]=p,e[17]=g,e[18]=h):h=e[18],h},Qe=async(s,e,l)=>{const t=await Promise.all(l.map(f=>{const u=ce(f);return Promise.allSettled([s.query(qe,{},u),s.query(Ie,{},u),s.query(Oe,{},u)])})),r=ce(e),c=typeof s.schedulerStatus=="function"?s.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[i,n,o]=await Promise.allSettled([s.query(Ce,{},r),s.query(Le,{},r),c]),d=t.map(([f,u,g])=>({functions:u.status==="fulfilled"?u.value.functions:[],metrics:f.status==="fulfilled"?f.value:null,migrations:g.status==="fulfilled"?g.value.migrations:[]})),p=ke(d),x=t[0]?.[0];return{auth:n.status==="fulfilled"?n.value:null,entries:i.status==="fulfilled"?i.value.entries:[],functions:Re(d.map(f=>f.functions)),logsError:i.status==="rejected"?ue(i.reason):null,metricsError:p.reachable===0&&x?.status==="rejected"?ue(x.reason):null,migrations:Me(d.map(f=>f.migrations)),scheduler:o.status==="fulfilled"?o.value:null,totals:p}},We=s=>{const e=s?.history??[];return{attempts:e.map(l=>l.attempts),failures:e.map(l=>l.failures)}},Xe=(s,e)=>s==="crit"?{description:e("One or more service levels are breached."),label:e("Critical")}:s==="warn"?{description:e("Some service levels need attention."),label:e("Degraded")}:{description:e("All service levels are within target."),label:e("All systems healthy")},Je=s=>{const e=se(75),{errorLevel:l,liveError:t,metricsError:r,overall:c,requestSeries:i,totals:n}=s,o=le();let d;e[0]!==c||e[1]!==o?(d=Xe(c,o),e[0]=c,e[1]=o,e[2]=d):d=e[2];const{description:p,label:x}=d,f=Ke[c];let u;e[3]!==f?(u=W("flex size-10 shrink-0 items-center justify-center rounded-full",f),e[3]=f,e[4]=u):u=e[4];const g=pe[c];let h;e[5]!==g?(h=W("size-3 rounded-full",g),e[5]=g,e[6]=h):h=e[6];let E;e[7]!==h?(E=a("span",{className:h}),e[7]=h,e[8]=E):E=e[8];let w;e[9]!==u||e[10]!==E?(w=a("span",{"aria-hidden":"true",className:u,children:E}),e[9]=u,e[10]=E,e[11]=w):w=e[11];let T;e[12]!==x?(T=a("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:x}),e[12]=x,e[13]=T):T=e[13];let S;e[14]!==p?(S=a("span",{className:"text-[13px] text-muted-foreground",children:p}),e[14]=p,e[15]=S):S=e[15];let y;e[16]!==T||e[17]!==S?(y=m("div",{className:"grid leading-tight",children:[T,S]}),e[16]=T,e[17]=S,e[18]=y):y=e[18];let b;e[19]!==y||e[20]!==w?(b=m("div",{className:"flex items-center gap-3",children:[w,y]}),e[19]=y,e[20]=w,e[21]=b):b=e[21];let k;e[22]!==o?(k=o("Requests"),e[22]=o,e[23]=k):k=e[23];let _;e[24]!==k?(_=a("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:k}),e[24]=k,e[25]=_):_=e[25];let A;e[26]!==i||e[27]!==o?(A=i.length>=2&&a(ne,{ariaLabel:o("Requests over time"),className:"h-6 w-20 text-foreground",series:i,testId:"hl-spark-requests"}),e[26]=i,e[27]=o,e[28]=A):A=e[28];const D=n?.requests??0;let j;e[29]!==D?(j=D.toString(),e[29]=D,e[30]=j):j=e[30];let I;e[31]!==j?(I=a("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:j}),e[31]=j,e[32]=I):I=e[32];let U;e[33]!==A||e[34]!==I?(U=m("div",{className:"flex items-center justify-end gap-2",children:[A,I]}),e[33]=A,e[34]=I,e[35]=U):U=e[35];let C;e[36]!==_||e[37]!==U?(C=m("div",{className:"text-end",children:[_,U]}),e[36]=_,e[37]=U,e[38]=C):C=e[38];let $;e[39]===Symbol.for("react.memo_cache_sentinel")?($=a("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),e[39]=$):$=e[39];let R;e[40]!==o?(R=o("Error rate"),e[40]=o,e[41]=R):R=e[41];let q;e[42]!==R?(q=a("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:R}),e[42]=R,e[43]=q):q=e[43];const Q=ge[l];let M;e[44]!==Q?(M=W("text-lg font-semibold tabular-nums",Q),e[44]=Q,e[45]=M):M=e[45];let P;e[46]!==n?(P=n===null?"—":re(n.errors,n.requests),e[46]=n,e[47]=P):P=e[47];let L;e[48]!==M||e[49]!==P?(L=a("div",{className:M,"data-testid":"hl-error-rate",children:P}),e[48]=M,e[49]=P,e[50]=L):L=e[50];let O;e[51]!==q||e[52]!==L?(O=m("div",{className:"text-end",children:[q,L]}),e[51]=q,e[52]=L,e[53]=O):O=e[53];let G;e[54]===Symbol.for("react.memo_cache_sentinel")?(G=a("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),e[54]=G):G=e[54];let B;e[55]===Symbol.for("react.memo_cache_sentinel")?(B=a(ve,{}),e[55]=B):B=e[55];let v;e[56]!==t?(v=m("div",{className:"flex items-center gap-2",children:[B,a(Ne,{message:t,prefix:"hl"})]}),e[56]=t,e[57]=v):v=e[57];let N;e[58]!==C||e[59]!==O||e[60]!==v?(N=m("div",{className:"flex flex-wrap items-center gap-4",children:[C,$,O,G,v]}),e[58]=C,e[59]=O,e[60]=v,e[61]=N):N=e[61];let V;e[62]!==b||e[63]!==N?(V=m("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[b,N]}),e[62]=b,e[63]=N,e[64]=V):V=e[64];let H;e[65]!==r?(H=r!==null&&a("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:r}),e[65]=r,e[66]=H):H=e[66];let K;e[67]!==r||e[68]!==o||e[69]!==n?.historyTruncated?(K=r===null&&n?.historyTruncated===!0&&a("div",{className:"border-t border-border bg-warning/5 px-4 py-2 text-sm text-muted-foreground","data-testid":"hl-history-truncated",children:o("Showing a partial request/error history — one or more shards have more data than the trend chart can display.")}),e[67]=r,e[68]=o,e[69]=n?.historyTruncated,e[70]=K):K=e[70];let Y;return e[71]!==V||e[72]!==H||e[73]!==K?(Y=m(X,{className:"gap-0 py-0",children:[V,H,K]}),e[71]=V,e[72]=H,e[73]=K,e[74]=Y):Y=e[74],Y},Ye=s=>{const e=se(14),{shards:l}=s,t=le();let r;e[0]!==t?(r=t("Shards seen"),e[0]=t,e[1]=r):r=e[1];let c;e[2]!==r?(c=a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r}),e[2]=r,e[3]=c):c=e[3];let i;e[4]!==l.length?(i=a(te,{"data-testid":"hl-shard-count",variant:"outline",children:l.length}),e[4]=l.length,e[5]=i):i=e[5];let n;e[6]!==c||e[7]!==i?(n=m("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[c,i]}),e[6]=c,e[7]=i,e[8]=n):n=e[8];let o;e[9]!==l?(o=l.length>0&&a("ul",{className:"flex flex-wrap gap-1.5 p-4",children:l.map(Ze)}),e[9]=l,e[10]=o):o=e[10];let d;return e[11]!==n||e[12]!==o?(d=m(X,{className:"gap-0 py-0",children:[n,o]}),e[11]=n,e[12]=o,e[13]=d):d=e[13],d},gt=({initialShardKey:s})=>{const e=Se(),l=le(),[t,r]=F([]),[c,i]=F(null),[n,o]=F(null),[d,p]=F(null),[x,f]=F([]),[u,g]=F(null),[h,E]=F(null),[w,T]=F([]),[S]=F(Ee),y=Z(!1),b=Z(0),k=Z(0),_=Z(null),A=s??"",D=xe(async()=>{if(y.current)return;y.current=!0;const v=b.current,N=await Qe(e,A,we(A,S));v===b.current&&(o(N.totals),p(N.metricsError),f(N.functions),T(N.migrations),r(N.entries),i(N.logsError),g(N.auth),E(N.scheduler),y.current=!1)},[e,S,A]);ie(()=>(ae(D()),()=>{b.current+=1,y.current=!1,_.current!==null&&(clearTimeout(_.current),_.current=null)}),[D]);const j=()=>{const v=Date.now()-k.current;if(v>=fe){k.current=Date.now(),ae(D());return}_.current===null&&(_.current=setTimeout(()=>{_.current=null,k.current=Date.now(),ae(D())},fe-v))},{data:I,liveError:U}=be(z.getMetrics,{},{live:!0,shardKey:A});ie(()=>{I!==void 0&&j()},[I]);const C=t.filter(v=>v.level==="error"),$=C.slice(0,Fe),R=Be(n?.history),q=We(u),Q=x.filter(v=>v.calls>0).toSorted((v,N)=>N.errors/N.calls-v.errors/v.calls||N.calls-v.calls).slice(0,De),M=Ve(w),P=n===null||n.requests===0?0:n.errors/n.requests,L=oe(P,me,he),O=u===null?"ok":oe(u.failureRate,je,Ue),G=h===null?"ok":$e(h.backlog,Pe,Ge),B=ze([L,O,G,M.level]);return m("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[a(Je,{errorLevel:L,liveError:U,metricsError:d,overall:B,requestSeries:R.requests,totals:n}),m("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[a(ee,{chart:R.errors.length>=2?a(ne,{ariaLabel:l("Errors over time"),className:"h-7 w-20 text-destructive",series:R.errors,testId:"hl-spark-errors"}):void 0,label:l("Error rate"),level:L,testId:"hl-slo-errorrate",value:n===null?"—":re(n.errors,n.requests)}),a(ee,{chart:q.failures.length>=2?a(ne,{ariaLabel:l("Auth failures over time"),className:"h-7 w-20 text-destructive",series:q.failures,testId:"hl-spark-auth"}):void 0,label:l("Auth failures"),level:O,testId:"hl-slo-auth",value:u===null?"—":re(u.failures,u.attempts)}),a(ee,{label:l("Scheduler backlog"),level:G,testId:"hl-slo-backlog",value:h===null?"—":h.backlog.toString()}),a(ee,{label:l("Migrations"),level:M.level,testId:"hl-slo-migrations",value:He(M,l)})]}),a(_e,{errorCount:C.length,logsError:c,topErrors:$,worstFunctions:Q}),a(Ye,{shards:S})]})};function Ze(s){return a("li",{"data-testid":"hl-shard",children:a(te,{variant:"secondary",children:s})},s)}export{gt as HealthPanel};