@crvouga/mockingbird-service-odx 1.6.1 → 1.7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog — @crvouga/mockingbird-service-odx
2
2
 
3
+ ## 1.7.0 (2026-10-01)
4
+
5
+ ### Features
6
+
7
+ - record SQL timelines and serve the admin explorer ([8ced17a](https://github.com/crvouga/mockingbird/commit/8ced17ac398e386ef4e9d7e01fc7744c34b95d07))
8
+
9
+ ### Dependencies
10
+
11
+ - `@crvouga/mockingbird-service-sqlite`
12
+
3
13
  ## 1.6.1 (2026-09-30)
4
14
 
5
15
  ### Fixes and improvements
@@ -1626,6 +1626,167 @@ function faultPresetList(value) {
1626
1626
  })
1627
1627
  };
1628
1628
  }
1629
+ function mountSqlExplorer(root, api) {
1630
+ const cell = (value) => {
1631
+ if (value === null || value === void 0)
1632
+ return "";
1633
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1634
+ return String(value);
1635
+ }
1636
+ return JSON.stringify(value) ?? "";
1637
+ };
1638
+ root.replaceChildren();
1639
+ const layout = document.createElement("div");
1640
+ layout.className = "sql-layout";
1641
+ const tables = document.createElement("div");
1642
+ tables.className = "sql-tables";
1643
+ const stack = document.createElement("div");
1644
+ stack.className = "stack";
1645
+ const banner = document.createElement("p");
1646
+ banner.className = "banner";
1647
+ const grid = document.createElement("div");
1648
+ const input = document.createElement("textarea");
1649
+ input.className = "sql-input";
1650
+ input.spellcheck = false;
1651
+ input.placeholder = "SELECT * FROM ...";
1652
+ const actions = document.createElement("div");
1653
+ actions.className = "row-actions";
1654
+ const run = document.createElement("button");
1655
+ run.type = "button";
1656
+ run.textContent = "Run";
1657
+ actions.append(run);
1658
+ const result = document.createElement("pre");
1659
+ stack.append(banner, grid, input, actions, result);
1660
+ layout.append(tables, stack);
1661
+ root.append(layout);
1662
+ const showError = (error) => {
1663
+ banner.textContent = error instanceof Error ? error.message : String(error);
1664
+ banner.classList.add("show");
1665
+ };
1666
+ const clearError = () => {
1667
+ banner.textContent = "";
1668
+ banner.classList.remove("show");
1669
+ };
1670
+ const renderGrid = (columns, rows) => {
1671
+ grid.replaceChildren();
1672
+ if (columns.length === 0) {
1673
+ const empty = document.createElement("p");
1674
+ empty.className = "empty";
1675
+ empty.textContent = "No rows.";
1676
+ grid.append(empty);
1677
+ return;
1678
+ }
1679
+ const table = document.createElement("table");
1680
+ const head = document.createElement("thead");
1681
+ const headRow = document.createElement("tr");
1682
+ for (const column of columns) {
1683
+ const th = document.createElement("th");
1684
+ th.textContent = column;
1685
+ headRow.append(th);
1686
+ }
1687
+ head.append(headRow);
1688
+ const body = document.createElement("tbody");
1689
+ for (const row of rows) {
1690
+ const tr = document.createElement("tr");
1691
+ for (const column of columns) {
1692
+ const td = document.createElement("td");
1693
+ td.dataset.label = column;
1694
+ td.textContent = cell(row[column]);
1695
+ tr.append(td);
1696
+ }
1697
+ body.append(tr);
1698
+ }
1699
+ table.append(head, body);
1700
+ grid.append(table);
1701
+ };
1702
+ const rowsOf = (value) => {
1703
+ if (!isRecord2(value) || !Array.isArray(value.rows))
1704
+ return [];
1705
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
1706
+ };
1707
+ const columnsOf = (value, rows) => {
1708
+ if (isRecord2(value) && Array.isArray(value.columns)) {
1709
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
1710
+ if (named.length > 0)
1711
+ return named;
1712
+ }
1713
+ const first = rows[0];
1714
+ return first === void 0 ? [] : Object.keys(first);
1715
+ };
1716
+ let selected = "";
1717
+ const loadPage = async (schema, name) => {
1718
+ selected = `${schema}.${name}`;
1719
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
1720
+ const rows = rowsOf(page);
1721
+ renderGrid(columnsOf(page, rows), rows);
1722
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
1723
+ result.textContent = `${selected} \xB7 ${total} rows`;
1724
+ for (const button of tables.querySelectorAll("button")) {
1725
+ if (!(button instanceof HTMLButtonElement))
1726
+ continue;
1727
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
1728
+ }
1729
+ };
1730
+ const loadTables = async () => {
1731
+ const payload = await api.get("/sql/tables");
1732
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
1733
+ tables.replaceChildren();
1734
+ if (listed.length === 0) {
1735
+ const empty = document.createElement("p");
1736
+ empty.className = "empty";
1737
+ empty.textContent = "No tables.";
1738
+ tables.append(empty);
1739
+ return;
1740
+ }
1741
+ for (const item of listed) {
1742
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
1743
+ continue;
1744
+ const button = document.createElement("button");
1745
+ button.type = "button";
1746
+ button.dataset.schema = item.schema;
1747
+ button.dataset.table = item.name;
1748
+ button.textContent = `${item.schema}.${item.name}`;
1749
+ tables.append(button);
1750
+ }
1751
+ };
1752
+ tables.addEventListener("click", (event) => {
1753
+ const target = event.target;
1754
+ if (!(target instanceof Element))
1755
+ return;
1756
+ const button = target.closest("button");
1757
+ if (!(button instanceof HTMLButtonElement))
1758
+ return;
1759
+ const schema = button.dataset.schema;
1760
+ const name = button.dataset.table;
1761
+ if (schema === void 0 || name === void 0)
1762
+ return;
1763
+ clearError();
1764
+ loadPage(schema, name).catch(showError);
1765
+ });
1766
+ run.addEventListener("click", () => {
1767
+ const sql = input.value.trim();
1768
+ if (sql === "") {
1769
+ showError(new Error("Enter a statement"));
1770
+ return;
1771
+ }
1772
+ clearError();
1773
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
1774
+ const rows = rowsOf(payload);
1775
+ renderGrid(columnsOf(payload, rows), rows);
1776
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
1777
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
1778
+ result.textContent = `${count} rows${truncated}`;
1779
+ }).catch(showError);
1780
+ });
1781
+ const namespace = document.getElementById("namespace");
1782
+ if (namespace) {
1783
+ namespace.addEventListener("change", () => {
1784
+ clearError();
1785
+ loadTables().catch(showError);
1786
+ });
1787
+ }
1788
+ loadTables().catch(showError);
1789
+ }
1629
1790
  function bootAdmin(config) {
1630
1791
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1631
1792
  const sources = ["declared", "inferred", "mixed"];
@@ -2302,6 +2463,22 @@ function bootAdmin(config) {
2302
2463
  panel.script = value.script;
2303
2464
  return panel;
2304
2465
  };
2466
+ const decodeExtension = (value) => {
2467
+ if (!isRecord2(value))
2468
+ return void 0;
2469
+ if (value.kind === "sql") {
2470
+ return {
2471
+ kind: "sql",
2472
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2473
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2474
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2475
+ };
2476
+ }
2477
+ if (value.kind !== "panel")
2478
+ return void 0;
2479
+ const panel = decodePanel(value);
2480
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2481
+ };
2305
2482
  const mountPanels = (panels) => {
2306
2483
  const nav = el("nav", HTMLElement);
2307
2484
  const views = el("views", HTMLElement);
@@ -2355,10 +2532,48 @@ function bootAdmin(config) {
2355
2532
  return decoded === void 0 ? [] : [decoded];
2356
2533
  });
2357
2534
  mountPanels(panels);
2535
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2536
+ const decoded = decodeExtension(extension);
2537
+ return decoded === void 0 ? [] : [decoded];
2538
+ });
2539
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2540
+ mountPanels(extensionPanels);
2541
+ for (const extension of extensions) {
2542
+ if (extension.kind !== "sql")
2543
+ continue;
2544
+ const nav = el("nav", HTMLElement);
2545
+ const views = el("views", HTMLElement);
2546
+ const button = document.createElement("button");
2547
+ button.type = "button";
2548
+ button.dataset.view = extension.id;
2549
+ button.textContent = extension.title;
2550
+ nav.append(button);
2551
+ const section = document.createElement("section");
2552
+ section.className = "view";
2553
+ section.id = `view-${extension.id}`;
2554
+ section.hidden = true;
2555
+ const title = document.createElement("h2");
2556
+ title.textContent = extension.title;
2557
+ const lede = document.createElement("p");
2558
+ lede.className = "lede";
2559
+ lede.textContent = extension.description;
2560
+ const body = document.createElement("div");
2561
+ body.className = "panel-body";
2562
+ section.append(title, lede, body);
2563
+ views.append(section);
2564
+ mountSqlExplorer(body, panelApi);
2565
+ }
2358
2566
  return refresh();
2359
2567
  }).catch(showError);
2360
2568
  }
2361
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2569
+ var clientPrelude = [
2570
+ isRecord2,
2571
+ mountAdminBrand,
2572
+ startAdminBrand,
2573
+ faultPresetList,
2574
+ mountSqlExplorer,
2575
+ bootAdmin
2576
+ ].map((fn) => fn.toString()).join("\n");
2362
2577
  var adminClientSource = (config) => {
2363
2578
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2364
2579
  const entry = bootAdmin.name;
@@ -2408,19 +2623,33 @@ var STANDARD_ADMIN_ROUTES = [
2408
2623
  "GET /ui/manifest"
2409
2624
  ];
2410
2625
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2626
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2627
+ var checkPanel = (panel, seen, label) => {
2628
+ if (!PANEL_ID.test(panel.id)) {
2629
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2630
+ }
2631
+ if (RESERVED_VIEWS.has(panel.id)) {
2632
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2633
+ }
2634
+ if (seen.has(panel.id))
2635
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2636
+ seen.add(panel.id);
2637
+ if (panel.title.trim() === "")
2638
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2639
+ };
2411
2640
  var assertAdminUi = (ui) => {
2412
- if (!ui?.panels)
2641
+ if (!ui)
2413
2642
  return;
2414
2643
  const seen = /* @__PURE__ */ new Set();
2415
- for (const panel of ui.panels) {
2416
- if (!PANEL_ID.test(panel.id)) {
2417
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2644
+ for (const panel of ui.panels ?? [])
2645
+ checkPanel(panel, seen, "admin panel");
2646
+ for (const extension of ui.extensions ?? []) {
2647
+ if (extension.kind === "panel") {
2648
+ checkPanel(extension, seen, "admin extension");
2649
+ continue;
2418
2650
  }
2419
- if (seen.has(panel.id))
2420
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2421
- seen.add(panel.id);
2422
- if (panel.title.trim() === "")
2423
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2651
+ const id = extension.id ?? "sql";
2652
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2424
2653
  }
2425
2654
  };
2426
2655
 
@@ -2654,6 +2883,12 @@ var renderAdminDocument = (service) => {
2654
2883
  border-radius: 999px; padding: 4px 8px;
2655
2884
  }
2656
2885
  .chip i { color: var(--faint); font-style: normal; }
2886
+ .sql-layout {
2887
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
2888
+ }
2889
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
2890
+ .sql-tables button { text-align: left; }
2891
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2657
2892
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2658
2893
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2659
2894
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -2717,7 +2952,7 @@ var renderAdminDocument = (service) => {
2717
2952
  padding: 8px;
2718
2953
  }
2719
2954
  nav.side button { white-space: nowrap; flex: none; }
2720
- .split { grid-template-columns: minmax(0, 1fr); }
2955
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
2721
2956
  main { padding: 14px; }
2722
2957
  table, thead, tbody, tr, th, td { display: block; }
2723
2958
  thead { display: none; }
@@ -2888,6 +3123,24 @@ var json2 = (body) => new Response(JSON.stringify(body), {
2888
3123
  status: 200,
2889
3124
  headers: { "content-type": "application/json; charset=utf-8" }
2890
3125
  });
3126
+ var describeExtension = (extension) => {
3127
+ if (extension.kind === "sql") {
3128
+ return {
3129
+ kind: "sql",
3130
+ id: extension.id ?? "sql",
3131
+ title: extension.title ?? "SQL",
3132
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3133
+ };
3134
+ }
3135
+ return {
3136
+ kind: "panel",
3137
+ id: extension.id,
3138
+ title: extension.title,
3139
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3140
+ html: extension.html,
3141
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3142
+ };
3143
+ };
2891
3144
  var adminUiRoutes = (service, ui) => {
2892
3145
  const shell = () => renderAdminDocument(service);
2893
3146
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -2902,7 +3155,8 @@ var adminUiRoutes = (service, ui) => {
2902
3155
  ...panel.description !== void 0 ? { description: panel.description } : {},
2903
3156
  html: panel.html,
2904
3157
  ...panel.script !== void 0 ? { script: panel.script } : {}
2905
- }))
3158
+ })),
3159
+ extensions: (ui?.extensions ?? []).map(describeExtension)
2906
3160
  })
2907
3161
  };
2908
3162
  };
@@ -3505,7 +3759,7 @@ var stateAdminRoutes = (routes) => {
3505
3759
  };
3506
3760
 
3507
3761
  // ../core/dist/version.js
3508
- var PACKAGE_VERSION = true ? "1.6.1" : UNRELEASED_VERSION;
3762
+ var PACKAGE_VERSION = true ? "1.7.0" : UNRELEASED_VERSION;
3509
3763
 
3510
3764
  // ../core/dist/signing.js
3511
3765
  var encoder = new TextEncoder();
@@ -5541,4 +5795,4 @@ export {
5541
5795
  apiKeyCredential,
5542
5796
  OdxAPI
5543
5797
  };
5544
- //# sourceMappingURL=chunk-QY3DD74Z.js.map
5798
+ //# sourceMappingURL=chunk-BCUAAJT4.js.map