@crvouga/mockingbird-service-otel 1.6.1 → 1.7.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog — @crvouga/mockingbird-service-otel
2
2
 
3
+ ## 1.7.1 (2026-10-01)
4
+
5
+ ### Fixes and improvements
6
+
7
+ - freeze clock before setting time ([a054a1d](https://github.com/crvouga/mockingbird/commit/a054a1defad62539d719b1d31c15107afea623bd))
8
+
9
+ ## 1.7.0 (2026-09-30)
10
+
11
+ ### Features
12
+
13
+ - record SQL timelines and serve the admin explorer ([8ced17a](https://github.com/crvouga/mockingbird/commit/8ced17ac398e386ef4e9d7e01fc7744c34b95d07))
14
+
3
15
  ## 1.6.1 (2026-09-30)
4
16
 
5
17
  ### Fixes and improvements
@@ -189,6 +189,8 @@ var createControlPlane = (context) => {
189
189
  return adminError(400, "expected a JSON object");
190
190
  if (body.reset === true)
191
191
  context.clock.reset();
192
+ if (body.freeze === true)
193
+ context.clock.freeze();
192
194
  if (body.set !== void 0) {
193
195
  const instant = parseInstant(body.set);
194
196
  if (instant === void 0)
@@ -201,8 +203,6 @@ var createControlPlane = (context) => {
201
203
  return adminError(400, 'advance: expected ms or "15m"-style');
202
204
  context.clock.advance(delta);
203
205
  }
204
- if (body.freeze === true)
205
- context.clock.freeze();
206
206
  if (body.freeze === false)
207
207
  context.clock.unfreeze();
208
208
  return json(200, context.clock.state());
@@ -1647,6 +1647,167 @@ function faultPresetList(value) {
1647
1647
  })
1648
1648
  };
1649
1649
  }
1650
+ function mountSqlExplorer(root, api) {
1651
+ const cell = (value) => {
1652
+ if (value === null || value === void 0)
1653
+ return "";
1654
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1655
+ return String(value);
1656
+ }
1657
+ return JSON.stringify(value) ?? "";
1658
+ };
1659
+ root.replaceChildren();
1660
+ const layout = document.createElement("div");
1661
+ layout.className = "sql-layout";
1662
+ const tables = document.createElement("div");
1663
+ tables.className = "sql-tables";
1664
+ const stack = document.createElement("div");
1665
+ stack.className = "stack";
1666
+ const banner = document.createElement("p");
1667
+ banner.className = "banner";
1668
+ const grid = document.createElement("div");
1669
+ const input = document.createElement("textarea");
1670
+ input.className = "sql-input";
1671
+ input.spellcheck = false;
1672
+ input.placeholder = "SELECT * FROM ...";
1673
+ const actions = document.createElement("div");
1674
+ actions.className = "row-actions";
1675
+ const run = document.createElement("button");
1676
+ run.type = "button";
1677
+ run.textContent = "Run";
1678
+ actions.append(run);
1679
+ const result = document.createElement("pre");
1680
+ stack.append(banner, grid, input, actions, result);
1681
+ layout.append(tables, stack);
1682
+ root.append(layout);
1683
+ const showError = (error) => {
1684
+ banner.textContent = error instanceof Error ? error.message : String(error);
1685
+ banner.classList.add("show");
1686
+ };
1687
+ const clearError = () => {
1688
+ banner.textContent = "";
1689
+ banner.classList.remove("show");
1690
+ };
1691
+ const renderGrid = (columns, rows) => {
1692
+ grid.replaceChildren();
1693
+ if (columns.length === 0) {
1694
+ const empty = document.createElement("p");
1695
+ empty.className = "empty";
1696
+ empty.textContent = "No rows.";
1697
+ grid.append(empty);
1698
+ return;
1699
+ }
1700
+ const table = document.createElement("table");
1701
+ const head = document.createElement("thead");
1702
+ const headRow = document.createElement("tr");
1703
+ for (const column of columns) {
1704
+ const th = document.createElement("th");
1705
+ th.textContent = column;
1706
+ headRow.append(th);
1707
+ }
1708
+ head.append(headRow);
1709
+ const body = document.createElement("tbody");
1710
+ for (const row of rows) {
1711
+ const tr = document.createElement("tr");
1712
+ for (const column of columns) {
1713
+ const td = document.createElement("td");
1714
+ td.dataset.label = column;
1715
+ td.textContent = cell(row[column]);
1716
+ tr.append(td);
1717
+ }
1718
+ body.append(tr);
1719
+ }
1720
+ table.append(head, body);
1721
+ grid.append(table);
1722
+ };
1723
+ const rowsOf = (value) => {
1724
+ if (!isRecord2(value) || !Array.isArray(value.rows))
1725
+ return [];
1726
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
1727
+ };
1728
+ const columnsOf = (value, rows) => {
1729
+ if (isRecord2(value) && Array.isArray(value.columns)) {
1730
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
1731
+ if (named.length > 0)
1732
+ return named;
1733
+ }
1734
+ const first = rows[0];
1735
+ return first === void 0 ? [] : Object.keys(first);
1736
+ };
1737
+ let selected = "";
1738
+ const loadPage = async (schema, name) => {
1739
+ selected = `${schema}.${name}`;
1740
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
1741
+ const rows = rowsOf(page);
1742
+ renderGrid(columnsOf(page, rows), rows);
1743
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
1744
+ result.textContent = `${selected} \xB7 ${total} rows`;
1745
+ for (const button of tables.querySelectorAll("button")) {
1746
+ if (!(button instanceof HTMLButtonElement))
1747
+ continue;
1748
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
1749
+ }
1750
+ };
1751
+ const loadTables = async () => {
1752
+ const payload = await api.get("/sql/tables");
1753
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
1754
+ tables.replaceChildren();
1755
+ if (listed.length === 0) {
1756
+ const empty = document.createElement("p");
1757
+ empty.className = "empty";
1758
+ empty.textContent = "No tables.";
1759
+ tables.append(empty);
1760
+ return;
1761
+ }
1762
+ for (const item of listed) {
1763
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
1764
+ continue;
1765
+ const button = document.createElement("button");
1766
+ button.type = "button";
1767
+ button.dataset.schema = item.schema;
1768
+ button.dataset.table = item.name;
1769
+ button.textContent = `${item.schema}.${item.name}`;
1770
+ tables.append(button);
1771
+ }
1772
+ };
1773
+ tables.addEventListener("click", (event) => {
1774
+ const target = event.target;
1775
+ if (!(target instanceof Element))
1776
+ return;
1777
+ const button = target.closest("button");
1778
+ if (!(button instanceof HTMLButtonElement))
1779
+ return;
1780
+ const schema = button.dataset.schema;
1781
+ const name = button.dataset.table;
1782
+ if (schema === void 0 || name === void 0)
1783
+ return;
1784
+ clearError();
1785
+ loadPage(schema, name).catch(showError);
1786
+ });
1787
+ run.addEventListener("click", () => {
1788
+ const sql = input.value.trim();
1789
+ if (sql === "") {
1790
+ showError(new Error("Enter a statement"));
1791
+ return;
1792
+ }
1793
+ clearError();
1794
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
1795
+ const rows = rowsOf(payload);
1796
+ renderGrid(columnsOf(payload, rows), rows);
1797
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
1798
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
1799
+ result.textContent = `${count} rows${truncated}`;
1800
+ }).catch(showError);
1801
+ });
1802
+ const namespace = document.getElementById("namespace");
1803
+ if (namespace) {
1804
+ namespace.addEventListener("change", () => {
1805
+ clearError();
1806
+ loadTables().catch(showError);
1807
+ });
1808
+ }
1809
+ loadTables().catch(showError);
1810
+ }
1650
1811
  function bootAdmin(config) {
1651
1812
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1652
1813
  const sources = ["declared", "inferred", "mixed"];
@@ -2323,6 +2484,22 @@ function bootAdmin(config) {
2323
2484
  panel.script = value.script;
2324
2485
  return panel;
2325
2486
  };
2487
+ const decodeExtension = (value) => {
2488
+ if (!isRecord2(value))
2489
+ return void 0;
2490
+ if (value.kind === "sql") {
2491
+ return {
2492
+ kind: "sql",
2493
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2494
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2495
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2496
+ };
2497
+ }
2498
+ if (value.kind !== "panel")
2499
+ return void 0;
2500
+ const panel = decodePanel(value);
2501
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2502
+ };
2326
2503
  const mountPanels = (panels) => {
2327
2504
  const nav = el("nav", HTMLElement);
2328
2505
  const views = el("views", HTMLElement);
@@ -2376,10 +2553,48 @@ function bootAdmin(config) {
2376
2553
  return decoded === void 0 ? [] : [decoded];
2377
2554
  });
2378
2555
  mountPanels(panels);
2556
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2557
+ const decoded = decodeExtension(extension);
2558
+ return decoded === void 0 ? [] : [decoded];
2559
+ });
2560
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2561
+ mountPanels(extensionPanels);
2562
+ for (const extension of extensions) {
2563
+ if (extension.kind !== "sql")
2564
+ continue;
2565
+ const nav = el("nav", HTMLElement);
2566
+ const views = el("views", HTMLElement);
2567
+ const button = document.createElement("button");
2568
+ button.type = "button";
2569
+ button.dataset.view = extension.id;
2570
+ button.textContent = extension.title;
2571
+ nav.append(button);
2572
+ const section = document.createElement("section");
2573
+ section.className = "view";
2574
+ section.id = `view-${extension.id}`;
2575
+ section.hidden = true;
2576
+ const title = document.createElement("h2");
2577
+ title.textContent = extension.title;
2578
+ const lede = document.createElement("p");
2579
+ lede.className = "lede";
2580
+ lede.textContent = extension.description;
2581
+ const body = document.createElement("div");
2582
+ body.className = "panel-body";
2583
+ section.append(title, lede, body);
2584
+ views.append(section);
2585
+ mountSqlExplorer(body, panelApi);
2586
+ }
2379
2587
  return refresh();
2380
2588
  }).catch(showError);
2381
2589
  }
2382
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2590
+ var clientPrelude = [
2591
+ isRecord2,
2592
+ mountAdminBrand,
2593
+ startAdminBrand,
2594
+ faultPresetList,
2595
+ mountSqlExplorer,
2596
+ bootAdmin
2597
+ ].map((fn) => fn.toString()).join("\n");
2383
2598
  var adminClientSource = (config) => {
2384
2599
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2385
2600
  const entry = bootAdmin.name;
@@ -2429,19 +2644,33 @@ var STANDARD_ADMIN_ROUTES = [
2429
2644
  "GET /ui/manifest"
2430
2645
  ];
2431
2646
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2647
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2648
+ var checkPanel = (panel, seen, label) => {
2649
+ if (!PANEL_ID.test(panel.id)) {
2650
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2651
+ }
2652
+ if (RESERVED_VIEWS.has(panel.id)) {
2653
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2654
+ }
2655
+ if (seen.has(panel.id))
2656
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2657
+ seen.add(panel.id);
2658
+ if (panel.title.trim() === "")
2659
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2660
+ };
2432
2661
  var assertAdminUi = (ui) => {
2433
- if (!ui?.panels)
2662
+ if (!ui)
2434
2663
  return;
2435
2664
  const seen = /* @__PURE__ */ new Set();
2436
- for (const panel of ui.panels) {
2437
- if (!PANEL_ID.test(panel.id)) {
2438
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2665
+ for (const panel of ui.panels ?? [])
2666
+ checkPanel(panel, seen, "admin panel");
2667
+ for (const extension of ui.extensions ?? []) {
2668
+ if (extension.kind === "panel") {
2669
+ checkPanel(extension, seen, "admin extension");
2670
+ continue;
2439
2671
  }
2440
- if (seen.has(panel.id))
2441
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2442
- seen.add(panel.id);
2443
- if (panel.title.trim() === "")
2444
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2672
+ const id2 = extension.id ?? "sql";
2673
+ checkPanel({ id: id2, title: extension.title ?? "SQL" }, seen, "admin extension");
2445
2674
  }
2446
2675
  };
2447
2676
 
@@ -2675,6 +2904,12 @@ var renderAdminDocument = (service) => {
2675
2904
  border-radius: 999px; padding: 4px 8px;
2676
2905
  }
2677
2906
  .chip i { color: var(--faint); font-style: normal; }
2907
+ .sql-layout {
2908
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
2909
+ }
2910
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
2911
+ .sql-tables button { text-align: left; }
2912
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2678
2913
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2679
2914
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2680
2915
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -2738,7 +2973,7 @@ var renderAdminDocument = (service) => {
2738
2973
  padding: 8px;
2739
2974
  }
2740
2975
  nav.side button { white-space: nowrap; flex: none; }
2741
- .split { grid-template-columns: minmax(0, 1fr); }
2976
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
2742
2977
  main { padding: 14px; }
2743
2978
  table, thead, tbody, tr, th, td { display: block; }
2744
2979
  thead { display: none; }
@@ -2909,6 +3144,24 @@ var json2 = (body) => new Response(JSON.stringify(body), {
2909
3144
  status: 200,
2910
3145
  headers: { "content-type": "application/json; charset=utf-8" }
2911
3146
  });
3147
+ var describeExtension = (extension) => {
3148
+ if (extension.kind === "sql") {
3149
+ return {
3150
+ kind: "sql",
3151
+ id: extension.id ?? "sql",
3152
+ title: extension.title ?? "SQL",
3153
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3154
+ };
3155
+ }
3156
+ return {
3157
+ kind: "panel",
3158
+ id: extension.id,
3159
+ title: extension.title,
3160
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3161
+ html: extension.html,
3162
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3163
+ };
3164
+ };
2912
3165
  var adminUiRoutes = (service, ui) => {
2913
3166
  const shell = () => renderAdminDocument(service);
2914
3167
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -2923,7 +3176,8 @@ var adminUiRoutes = (service, ui) => {
2923
3176
  ...panel.description !== void 0 ? { description: panel.description } : {},
2924
3177
  html: panel.html,
2925
3178
  ...panel.script !== void 0 ? { script: panel.script } : {}
2926
- }))
3179
+ })),
3180
+ extensions: (ui?.extensions ?? []).map(describeExtension)
2927
3181
  })
2928
3182
  };
2929
3183
  };
@@ -3526,7 +3780,7 @@ var stateAdminRoutes = (routes) => {
3526
3780
  };
3527
3781
 
3528
3782
  // ../core/dist/version.js
3529
- var PACKAGE_VERSION = true ? "1.6.1" : UNRELEASED_VERSION;
3783
+ var PACKAGE_VERSION = true ? "1.7.1" : UNRELEASED_VERSION;
3530
3784
 
3531
3785
  // ../core/dist/webhooks.js
3532
3786
  var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
@@ -5869,4 +6123,4 @@ export {
5869
6123
  OtelAPI,
5870
6124
  adminRow
5871
6125
  };
5872
- //# sourceMappingURL=chunk-7RKIGFVE.js.map
6126
+ //# sourceMappingURL=chunk-36MHAEFN.js.map