@crvouga/mockingbird-service-paddle 0.3.1 → 0.4.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-paddle
2
2
 
3
+ ## 0.4.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
  ## 0.3.1 (2026-09-30)
4
14
 
5
15
  ### Fixes and improvements
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createRuntime
3
- } from "./chunk-LW2XNBX2.js";
3
+ } from "./chunk-RJQUGROO.js";
4
4
 
5
5
  // ../../adapters/node/dist/cli.js
6
6
  import { readFile } from "node:fs/promises";
@@ -370,4 +370,4 @@ export {
370
370
  createServer2 as createServer,
371
371
  serveTarget
372
372
  };
373
- //# sourceMappingURL=chunk-KVA6Z6FB.js.map
373
+ //# sourceMappingURL=chunk-LPIE6CZL.js.map
@@ -1843,6 +1843,167 @@ function faultPresetList(value) {
1843
1843
  })
1844
1844
  };
1845
1845
  }
1846
+ function mountSqlExplorer(root, api) {
1847
+ const cell = (value) => {
1848
+ if (value === null || value === void 0)
1849
+ return "";
1850
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1851
+ return String(value);
1852
+ }
1853
+ return JSON.stringify(value) ?? "";
1854
+ };
1855
+ root.replaceChildren();
1856
+ const layout = document.createElement("div");
1857
+ layout.className = "sql-layout";
1858
+ const tables = document.createElement("div");
1859
+ tables.className = "sql-tables";
1860
+ const stack = document.createElement("div");
1861
+ stack.className = "stack";
1862
+ const banner = document.createElement("p");
1863
+ banner.className = "banner";
1864
+ const grid = document.createElement("div");
1865
+ const input = document.createElement("textarea");
1866
+ input.className = "sql-input";
1867
+ input.spellcheck = false;
1868
+ input.placeholder = "SELECT * FROM ...";
1869
+ const actions = document.createElement("div");
1870
+ actions.className = "row-actions";
1871
+ const run = document.createElement("button");
1872
+ run.type = "button";
1873
+ run.textContent = "Run";
1874
+ actions.append(run);
1875
+ const result = document.createElement("pre");
1876
+ stack.append(banner, grid, input, actions, result);
1877
+ layout.append(tables, stack);
1878
+ root.append(layout);
1879
+ const showError = (error) => {
1880
+ banner.textContent = error instanceof Error ? error.message : String(error);
1881
+ banner.classList.add("show");
1882
+ };
1883
+ const clearError = () => {
1884
+ banner.textContent = "";
1885
+ banner.classList.remove("show");
1886
+ };
1887
+ const renderGrid = (columns, rows) => {
1888
+ grid.replaceChildren();
1889
+ if (columns.length === 0) {
1890
+ const empty = document.createElement("p");
1891
+ empty.className = "empty";
1892
+ empty.textContent = "No rows.";
1893
+ grid.append(empty);
1894
+ return;
1895
+ }
1896
+ const table = document.createElement("table");
1897
+ const head = document.createElement("thead");
1898
+ const headRow = document.createElement("tr");
1899
+ for (const column of columns) {
1900
+ const th = document.createElement("th");
1901
+ th.textContent = column;
1902
+ headRow.append(th);
1903
+ }
1904
+ head.append(headRow);
1905
+ const body = document.createElement("tbody");
1906
+ for (const row of rows) {
1907
+ const tr = document.createElement("tr");
1908
+ for (const column of columns) {
1909
+ const td = document.createElement("td");
1910
+ td.dataset.label = column;
1911
+ td.textContent = cell(row[column]);
1912
+ tr.append(td);
1913
+ }
1914
+ body.append(tr);
1915
+ }
1916
+ table.append(head, body);
1917
+ grid.append(table);
1918
+ };
1919
+ const rowsOf = (value) => {
1920
+ if (!isRecord2(value) || !Array.isArray(value.rows))
1921
+ return [];
1922
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
1923
+ };
1924
+ const columnsOf = (value, rows) => {
1925
+ if (isRecord2(value) && Array.isArray(value.columns)) {
1926
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
1927
+ if (named.length > 0)
1928
+ return named;
1929
+ }
1930
+ const first = rows[0];
1931
+ return first === void 0 ? [] : Object.keys(first);
1932
+ };
1933
+ let selected = "";
1934
+ const loadPage = async (schema, name) => {
1935
+ selected = `${schema}.${name}`;
1936
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
1937
+ const rows = rowsOf(page);
1938
+ renderGrid(columnsOf(page, rows), rows);
1939
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
1940
+ result.textContent = `${selected} \xB7 ${total} rows`;
1941
+ for (const button of tables.querySelectorAll("button")) {
1942
+ if (!(button instanceof HTMLButtonElement))
1943
+ continue;
1944
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
1945
+ }
1946
+ };
1947
+ const loadTables = async () => {
1948
+ const payload = await api.get("/sql/tables");
1949
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
1950
+ tables.replaceChildren();
1951
+ if (listed.length === 0) {
1952
+ const empty = document.createElement("p");
1953
+ empty.className = "empty";
1954
+ empty.textContent = "No tables.";
1955
+ tables.append(empty);
1956
+ return;
1957
+ }
1958
+ for (const item of listed) {
1959
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
1960
+ continue;
1961
+ const button = document.createElement("button");
1962
+ button.type = "button";
1963
+ button.dataset.schema = item.schema;
1964
+ button.dataset.table = item.name;
1965
+ button.textContent = `${item.schema}.${item.name}`;
1966
+ tables.append(button);
1967
+ }
1968
+ };
1969
+ tables.addEventListener("click", (event) => {
1970
+ const target = event.target;
1971
+ if (!(target instanceof Element))
1972
+ return;
1973
+ const button = target.closest("button");
1974
+ if (!(button instanceof HTMLButtonElement))
1975
+ return;
1976
+ const schema = button.dataset.schema;
1977
+ const name = button.dataset.table;
1978
+ if (schema === void 0 || name === void 0)
1979
+ return;
1980
+ clearError();
1981
+ loadPage(schema, name).catch(showError);
1982
+ });
1983
+ run.addEventListener("click", () => {
1984
+ const sql = input.value.trim();
1985
+ if (sql === "") {
1986
+ showError(new Error("Enter a statement"));
1987
+ return;
1988
+ }
1989
+ clearError();
1990
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
1991
+ const rows = rowsOf(payload);
1992
+ renderGrid(columnsOf(payload, rows), rows);
1993
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
1994
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
1995
+ result.textContent = `${count} rows${truncated}`;
1996
+ }).catch(showError);
1997
+ });
1998
+ const namespace = document.getElementById("namespace");
1999
+ if (namespace) {
2000
+ namespace.addEventListener("change", () => {
2001
+ clearError();
2002
+ loadTables().catch(showError);
2003
+ });
2004
+ }
2005
+ loadTables().catch(showError);
2006
+ }
1846
2007
  function bootAdmin(config) {
1847
2008
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1848
2009
  const sources = ["declared", "inferred", "mixed"];
@@ -2519,6 +2680,22 @@ function bootAdmin(config) {
2519
2680
  panel.script = value.script;
2520
2681
  return panel;
2521
2682
  };
2683
+ const decodeExtension = (value) => {
2684
+ if (!isRecord2(value))
2685
+ return void 0;
2686
+ if (value.kind === "sql") {
2687
+ return {
2688
+ kind: "sql",
2689
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2690
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2691
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2692
+ };
2693
+ }
2694
+ if (value.kind !== "panel")
2695
+ return void 0;
2696
+ const panel = decodePanel(value);
2697
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2698
+ };
2522
2699
  const mountPanels = (panels) => {
2523
2700
  const nav = el("nav", HTMLElement);
2524
2701
  const views = el("views", HTMLElement);
@@ -2572,10 +2749,48 @@ function bootAdmin(config) {
2572
2749
  return decoded === void 0 ? [] : [decoded];
2573
2750
  });
2574
2751
  mountPanels(panels);
2752
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2753
+ const decoded = decodeExtension(extension);
2754
+ return decoded === void 0 ? [] : [decoded];
2755
+ });
2756
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2757
+ mountPanels(extensionPanels);
2758
+ for (const extension of extensions) {
2759
+ if (extension.kind !== "sql")
2760
+ continue;
2761
+ const nav = el("nav", HTMLElement);
2762
+ const views = el("views", HTMLElement);
2763
+ const button = document.createElement("button");
2764
+ button.type = "button";
2765
+ button.dataset.view = extension.id;
2766
+ button.textContent = extension.title;
2767
+ nav.append(button);
2768
+ const section = document.createElement("section");
2769
+ section.className = "view";
2770
+ section.id = `view-${extension.id}`;
2771
+ section.hidden = true;
2772
+ const title = document.createElement("h2");
2773
+ title.textContent = extension.title;
2774
+ const lede = document.createElement("p");
2775
+ lede.className = "lede";
2776
+ lede.textContent = extension.description;
2777
+ const body = document.createElement("div");
2778
+ body.className = "panel-body";
2779
+ section.append(title, lede, body);
2780
+ views.append(section);
2781
+ mountSqlExplorer(body, panelApi);
2782
+ }
2575
2783
  return refresh();
2576
2784
  }).catch(showError);
2577
2785
  }
2578
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2786
+ var clientPrelude = [
2787
+ isRecord2,
2788
+ mountAdminBrand,
2789
+ startAdminBrand,
2790
+ faultPresetList,
2791
+ mountSqlExplorer,
2792
+ bootAdmin
2793
+ ].map((fn) => fn.toString()).join("\n");
2579
2794
  var adminClientSource = (config) => {
2580
2795
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2581
2796
  const entry = bootAdmin.name;
@@ -2625,19 +2840,33 @@ var STANDARD_ADMIN_ROUTES = [
2625
2840
  "GET /ui/manifest"
2626
2841
  ];
2627
2842
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2843
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2844
+ var checkPanel = (panel, seen, label) => {
2845
+ if (!PANEL_ID.test(panel.id)) {
2846
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2847
+ }
2848
+ if (RESERVED_VIEWS.has(panel.id)) {
2849
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2850
+ }
2851
+ if (seen.has(panel.id))
2852
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2853
+ seen.add(panel.id);
2854
+ if (panel.title.trim() === "")
2855
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2856
+ };
2628
2857
  var assertAdminUi = (ui) => {
2629
- if (!ui?.panels)
2858
+ if (!ui)
2630
2859
  return;
2631
2860
  const seen = /* @__PURE__ */ new Set();
2632
- for (const panel of ui.panels) {
2633
- if (!PANEL_ID.test(panel.id)) {
2634
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2861
+ for (const panel of ui.panels ?? [])
2862
+ checkPanel(panel, seen, "admin panel");
2863
+ for (const extension of ui.extensions ?? []) {
2864
+ if (extension.kind === "panel") {
2865
+ checkPanel(extension, seen, "admin extension");
2866
+ continue;
2635
2867
  }
2636
- if (seen.has(panel.id))
2637
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2638
- seen.add(panel.id);
2639
- if (panel.title.trim() === "")
2640
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2868
+ const id = extension.id ?? "sql";
2869
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2641
2870
  }
2642
2871
  };
2643
2872
 
@@ -2871,6 +3100,12 @@ var renderAdminDocument = (service) => {
2871
3100
  border-radius: 999px; padding: 4px 8px;
2872
3101
  }
2873
3102
  .chip i { color: var(--faint); font-style: normal; }
3103
+ .sql-layout {
3104
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3105
+ }
3106
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3107
+ .sql-tables button { text-align: left; }
3108
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2874
3109
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2875
3110
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2876
3111
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -2934,7 +3169,7 @@ var renderAdminDocument = (service) => {
2934
3169
  padding: 8px;
2935
3170
  }
2936
3171
  nav.side button { white-space: nowrap; flex: none; }
2937
- .split { grid-template-columns: minmax(0, 1fr); }
3172
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
2938
3173
  main { padding: 14px; }
2939
3174
  table, thead, tbody, tr, th, td { display: block; }
2940
3175
  thead { display: none; }
@@ -3105,6 +3340,24 @@ var json2 = (body) => new Response(JSON.stringify(body), {
3105
3340
  status: 200,
3106
3341
  headers: { "content-type": "application/json; charset=utf-8" }
3107
3342
  });
3343
+ var describeExtension = (extension) => {
3344
+ if (extension.kind === "sql") {
3345
+ return {
3346
+ kind: "sql",
3347
+ id: extension.id ?? "sql",
3348
+ title: extension.title ?? "SQL",
3349
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3350
+ };
3351
+ }
3352
+ return {
3353
+ kind: "panel",
3354
+ id: extension.id,
3355
+ title: extension.title,
3356
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3357
+ html: extension.html,
3358
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3359
+ };
3360
+ };
3108
3361
  var adminUiRoutes = (service, ui) => {
3109
3362
  const shell = () => renderAdminDocument(service);
3110
3363
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -3119,7 +3372,8 @@ var adminUiRoutes = (service, ui) => {
3119
3372
  ...panel.description !== void 0 ? { description: panel.description } : {},
3120
3373
  html: panel.html,
3121
3374
  ...panel.script !== void 0 ? { script: panel.script } : {}
3122
- }))
3375
+ })),
3376
+ extensions: (ui?.extensions ?? []).map(describeExtension)
3123
3377
  })
3124
3378
  };
3125
3379
  };
@@ -3796,7 +4050,7 @@ var stateAdminRoutes = (routes) => {
3796
4050
  };
3797
4051
 
3798
4052
  // ../core/dist/version.js
3799
- var PACKAGE_VERSION = true ? "0.3.1" : UNRELEASED_VERSION;
4053
+ var PACKAGE_VERSION = true ? "0.4.0" : UNRELEASED_VERSION;
3800
4054
 
3801
4055
  // ../core/dist/signing.js
3802
4056
  var encoder = new TextEncoder();
@@ -7515,4 +7769,4 @@ export {
7515
7769
  AUTH_TOKEN_TTL_MS,
7516
7770
  PaddleAPI
7517
7771
  };
7518
- //# sourceMappingURL=chunk-LW2XNBX2.js.map
7772
+ //# sourceMappingURL=chunk-RJQUGROO.js.map