@crvouga/mockingbird-runtime 0.3.2 → 0.5.0

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.
@@ -35,6 +35,14 @@ var createJournal = (size = DEFAULT_JOURNAL_SIZE) => {
35
35
  return matched;
36
36
  return query.limit <= 0 ? [] : matched.slice(-query.limit);
37
37
  },
38
+ count(namespace) {
39
+ if (namespace !== void 0)
40
+ return rings.get(namespace)?.entries.length ?? 0;
41
+ let total = 0;
42
+ for (const ring of rings.values())
43
+ total += ring.entries.length;
44
+ return total;
45
+ },
38
46
  clear(namespace) {
39
47
  if (namespace === void 0)
40
48
  rings.clear();
@@ -1378,6 +1386,7 @@ var createNamespaceControls = (options) => {
1378
1386
  });
1379
1387
  const start = (namespace, scope) => {
1380
1388
  ensured.add(namespace);
1389
+ options.onStart?.(namespace);
1381
1390
  const { snapshot, ...plan } = bootPlan(namespace);
1382
1391
  const early = faults.snapshot(namespace).rules;
1383
1392
  if (early.length > 0)
@@ -2138,7 +2147,10 @@ var createControlPlane = (context) => {
2138
2147
  return json(200, { status: "ok" });
2139
2148
  },
2140
2149
  // Totals across every namespace, unless the caller names one.
2141
- "GET /metrics": ({ request, url, namespace }) => json(200, context.metrics.report(explicitNamespace(request, url) ? namespace : void 0)),
2150
+ "GET /metrics": ({ request, url, namespace }) => json(200, explicitNamespace(request, url) ? context.metrics.report(namespace) : {
2151
+ ...context.metrics.report(),
2152
+ ...context.resources && url.searchParams.get("resources") === "1" ? { resources: context.resources() } : {}
2153
+ }),
2142
2154
  "DELETE /metrics": ({ request, url, namespace }) => {
2143
2155
  context.metrics.reset(explicitNamespace(request, url) ? namespace : void 0);
2144
2156
  return json(200, { status: "ok" });
@@ -2308,6 +2320,9 @@ var createMetrics = (partition = true) => {
2308
2320
  };
2309
2321
  };
2310
2322
 
2323
+ // ../service/core/dist/admin-ui.js
2324
+ import { escapeHtml, renderDocument } from "@crvouga/mockingbird-ui/document";
2325
+
2311
2326
  // ../service/core/dist/admin-client.js
2312
2327
  var loading;
2313
2328
  var loadAdminClient = () => {
@@ -2319,20 +2334,6 @@ var loadAdminClient = () => {
2319
2334
  };
2320
2335
 
2321
2336
  // ../service/core/dist/admin-ui.js
2322
- var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
2323
- switch (char) {
2324
- case "&":
2325
- return "&amp;";
2326
- case "<":
2327
- return "&lt;";
2328
- case ">":
2329
- return "&gt;";
2330
- case '"':
2331
- return "&quot;";
2332
- default:
2333
- return "&#39;";
2334
- }
2335
- });
2336
2337
  var EMBEDDED_BRAND = typeof __MOCKINGBIRD_ADMIN_BRAND__ === "object" ? __MOCKINGBIRD_ADMIN_BRAND__ : void 0;
2337
2338
  var adminBrandCatalog = (service, brand = EMBEDDED_BRAND) => brand ? { [service]: brand } : {};
2338
2339
  var adminDocument = (client, service, adminPrefix) => {
@@ -2344,22 +2345,11 @@ var adminDocument = (client, service, adminPrefix) => {
2344
2345
  brandsUrl: `${adminPrefix}${ADMIN_BRANDS_PATH}`,
2345
2346
  service
2346
2347
  });
2347
- return `<!DOCTYPE html>
2348
- <html lang="en">
2349
- <head>
2350
- <meta charset="utf-8">
2351
- <meta name="viewport" content="width=device-width, initial-scale=1">
2352
- <meta name="color-scheme" content="light dark">
2353
- <title>${name2} admin</title>
2354
- <style>html,body{margin:0;min-height:100%}#admin-root{min-height:100%}</style>
2355
- </head>
2356
- <body>
2357
- <main id="admin-root" data-mockingbird-admin data-admin-ui-library="antd" data-service="${name2}">
2358
- <noscript>Enable JavaScript to use administration.</noscript>
2359
- </main>
2360
- ${script}
2361
- </body>
2362
- </html>`;
2348
+ return renderDocument({
2349
+ title: `${service} admin`,
2350
+ css: "html,body,[data-mockingbird-root],#admin-root{min-height:100%}body{margin:0}",
2351
+ body: `<main id="admin-root" data-mockingbird-admin data-admin-ui-library="heroui" data-service="${name2}"><noscript>Enable JavaScript to use administration.</noscript></main>${script}`
2352
+ });
2363
2353
  };
2364
2354
  var htmlResponse = (body) => new Response(body, {
2365
2355
  status: 200,
@@ -2492,4 +2482,4 @@ export {
2492
2482
  createMetrics,
2493
2483
  adminUiRoutes
2494
2484
  };
2495
- //# sourceMappingURL=chunk-M4HUKBLC.js.map
2485
+ //# sourceMappingURL=chunk-GAIPLMRY.js.map