@crvouga/mockingbird-service-aha 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-aha
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
@@ -1918,6 +1918,167 @@ function faultPresetList(value) {
1918
1918
  })
1919
1919
  };
1920
1920
  }
1921
+ function mountSqlExplorer(root, api) {
1922
+ const cell = (value) => {
1923
+ if (value === null || value === void 0)
1924
+ return "";
1925
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1926
+ return String(value);
1927
+ }
1928
+ return JSON.stringify(value) ?? "";
1929
+ };
1930
+ root.replaceChildren();
1931
+ const layout = document.createElement("div");
1932
+ layout.className = "sql-layout";
1933
+ const tables = document.createElement("div");
1934
+ tables.className = "sql-tables";
1935
+ const stack = document.createElement("div");
1936
+ stack.className = "stack";
1937
+ const banner = document.createElement("p");
1938
+ banner.className = "banner";
1939
+ const grid = document.createElement("div");
1940
+ const input = document.createElement("textarea");
1941
+ input.className = "sql-input";
1942
+ input.spellcheck = false;
1943
+ input.placeholder = "SELECT * FROM ...";
1944
+ const actions = document.createElement("div");
1945
+ actions.className = "row-actions";
1946
+ const run = document.createElement("button");
1947
+ run.type = "button";
1948
+ run.textContent = "Run";
1949
+ actions.append(run);
1950
+ const result = document.createElement("pre");
1951
+ stack.append(banner, grid, input, actions, result);
1952
+ layout.append(tables, stack);
1953
+ root.append(layout);
1954
+ const showError = (error2) => {
1955
+ banner.textContent = error2 instanceof Error ? error2.message : String(error2);
1956
+ banner.classList.add("show");
1957
+ };
1958
+ const clearError = () => {
1959
+ banner.textContent = "";
1960
+ banner.classList.remove("show");
1961
+ };
1962
+ const renderGrid = (columns, rows) => {
1963
+ grid.replaceChildren();
1964
+ if (columns.length === 0) {
1965
+ const empty = document.createElement("p");
1966
+ empty.className = "empty";
1967
+ empty.textContent = "No rows.";
1968
+ grid.append(empty);
1969
+ return;
1970
+ }
1971
+ const table = document.createElement("table");
1972
+ const head = document.createElement("thead");
1973
+ const headRow = document.createElement("tr");
1974
+ for (const column of columns) {
1975
+ const th = document.createElement("th");
1976
+ th.textContent = column;
1977
+ headRow.append(th);
1978
+ }
1979
+ head.append(headRow);
1980
+ const body = document.createElement("tbody");
1981
+ for (const row of rows) {
1982
+ const tr = document.createElement("tr");
1983
+ for (const column of columns) {
1984
+ const td = document.createElement("td");
1985
+ td.dataset.label = column;
1986
+ td.textContent = cell(row[column]);
1987
+ tr.append(td);
1988
+ }
1989
+ body.append(tr);
1990
+ }
1991
+ table.append(head, body);
1992
+ grid.append(table);
1993
+ };
1994
+ const rowsOf = (value) => {
1995
+ if (!isRecord2(value) || !Array.isArray(value.rows))
1996
+ return [];
1997
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
1998
+ };
1999
+ const columnsOf = (value, rows) => {
2000
+ if (isRecord2(value) && Array.isArray(value.columns)) {
2001
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
2002
+ if (named.length > 0)
2003
+ return named;
2004
+ }
2005
+ const first = rows[0];
2006
+ return first === void 0 ? [] : Object.keys(first);
2007
+ };
2008
+ let selected = "";
2009
+ const loadPage = async (schema, name) => {
2010
+ selected = `${schema}.${name}`;
2011
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
2012
+ const rows = rowsOf(page);
2013
+ renderGrid(columnsOf(page, rows), rows);
2014
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
2015
+ result.textContent = `${selected} \xB7 ${total} rows`;
2016
+ for (const button of tables.querySelectorAll("button")) {
2017
+ if (!(button instanceof HTMLButtonElement))
2018
+ continue;
2019
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
2020
+ }
2021
+ };
2022
+ const loadTables = async () => {
2023
+ const payload = await api.get("/sql/tables");
2024
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
2025
+ tables.replaceChildren();
2026
+ if (listed.length === 0) {
2027
+ const empty = document.createElement("p");
2028
+ empty.className = "empty";
2029
+ empty.textContent = "No tables.";
2030
+ tables.append(empty);
2031
+ return;
2032
+ }
2033
+ for (const item of listed) {
2034
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
2035
+ continue;
2036
+ const button = document.createElement("button");
2037
+ button.type = "button";
2038
+ button.dataset.schema = item.schema;
2039
+ button.dataset.table = item.name;
2040
+ button.textContent = `${item.schema}.${item.name}`;
2041
+ tables.append(button);
2042
+ }
2043
+ };
2044
+ tables.addEventListener("click", (event) => {
2045
+ const target = event.target;
2046
+ if (!(target instanceof Element))
2047
+ return;
2048
+ const button = target.closest("button");
2049
+ if (!(button instanceof HTMLButtonElement))
2050
+ return;
2051
+ const schema = button.dataset.schema;
2052
+ const name = button.dataset.table;
2053
+ if (schema === void 0 || name === void 0)
2054
+ return;
2055
+ clearError();
2056
+ loadPage(schema, name).catch(showError);
2057
+ });
2058
+ run.addEventListener("click", () => {
2059
+ const sql = input.value.trim();
2060
+ if (sql === "") {
2061
+ showError(new Error("Enter a statement"));
2062
+ return;
2063
+ }
2064
+ clearError();
2065
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
2066
+ const rows = rowsOf(payload);
2067
+ renderGrid(columnsOf(payload, rows), rows);
2068
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
2069
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
2070
+ result.textContent = `${count} rows${truncated}`;
2071
+ }).catch(showError);
2072
+ });
2073
+ const namespace = document.getElementById("namespace");
2074
+ if (namespace) {
2075
+ namespace.addEventListener("change", () => {
2076
+ clearError();
2077
+ loadTables().catch(showError);
2078
+ });
2079
+ }
2080
+ loadTables().catch(showError);
2081
+ }
1921
2082
  function bootAdmin(config) {
1922
2083
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1923
2084
  const sources = ["declared", "inferred", "mixed"];
@@ -2594,6 +2755,22 @@ function bootAdmin(config) {
2594
2755
  panel.script = value.script;
2595
2756
  return panel;
2596
2757
  };
2758
+ const decodeExtension = (value) => {
2759
+ if (!isRecord2(value))
2760
+ return void 0;
2761
+ if (value.kind === "sql") {
2762
+ return {
2763
+ kind: "sql",
2764
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2765
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2766
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2767
+ };
2768
+ }
2769
+ if (value.kind !== "panel")
2770
+ return void 0;
2771
+ const panel = decodePanel(value);
2772
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2773
+ };
2597
2774
  const mountPanels = (panels) => {
2598
2775
  const nav = el("nav", HTMLElement);
2599
2776
  const views = el("views", HTMLElement);
@@ -2647,10 +2824,48 @@ function bootAdmin(config) {
2647
2824
  return decoded === void 0 ? [] : [decoded];
2648
2825
  });
2649
2826
  mountPanels(panels);
2827
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2828
+ const decoded = decodeExtension(extension);
2829
+ return decoded === void 0 ? [] : [decoded];
2830
+ });
2831
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2832
+ mountPanels(extensionPanels);
2833
+ for (const extension of extensions) {
2834
+ if (extension.kind !== "sql")
2835
+ continue;
2836
+ const nav = el("nav", HTMLElement);
2837
+ const views = el("views", HTMLElement);
2838
+ const button = document.createElement("button");
2839
+ button.type = "button";
2840
+ button.dataset.view = extension.id;
2841
+ button.textContent = extension.title;
2842
+ nav.append(button);
2843
+ const section = document.createElement("section");
2844
+ section.className = "view";
2845
+ section.id = `view-${extension.id}`;
2846
+ section.hidden = true;
2847
+ const title = document.createElement("h2");
2848
+ title.textContent = extension.title;
2849
+ const lede = document.createElement("p");
2850
+ lede.className = "lede";
2851
+ lede.textContent = extension.description;
2852
+ const body = document.createElement("div");
2853
+ body.className = "panel-body";
2854
+ section.append(title, lede, body);
2855
+ views.append(section);
2856
+ mountSqlExplorer(body, panelApi);
2857
+ }
2650
2858
  return refresh();
2651
2859
  }).catch(showError);
2652
2860
  }
2653
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2861
+ var clientPrelude = [
2862
+ isRecord2,
2863
+ mountAdminBrand,
2864
+ startAdminBrand,
2865
+ faultPresetList,
2866
+ mountSqlExplorer,
2867
+ bootAdmin
2868
+ ].map((fn) => fn.toString()).join("\n");
2654
2869
  var adminClientSource = (config) => {
2655
2870
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2656
2871
  const entry = bootAdmin.name;
@@ -2700,19 +2915,33 @@ var STANDARD_ADMIN_ROUTES = [
2700
2915
  "GET /ui/manifest"
2701
2916
  ];
2702
2917
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2918
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2919
+ var checkPanel = (panel, seen, label) => {
2920
+ if (!PANEL_ID.test(panel.id)) {
2921
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2922
+ }
2923
+ if (RESERVED_VIEWS.has(panel.id)) {
2924
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2925
+ }
2926
+ if (seen.has(panel.id))
2927
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2928
+ seen.add(panel.id);
2929
+ if (panel.title.trim() === "")
2930
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2931
+ };
2703
2932
  var assertAdminUi = (ui) => {
2704
- if (!ui?.panels)
2933
+ if (!ui)
2705
2934
  return;
2706
2935
  const seen = /* @__PURE__ */ new Set();
2707
- for (const panel of ui.panels) {
2708
- if (!PANEL_ID.test(panel.id)) {
2709
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2936
+ for (const panel of ui.panels ?? [])
2937
+ checkPanel(panel, seen, "admin panel");
2938
+ for (const extension of ui.extensions ?? []) {
2939
+ if (extension.kind === "panel") {
2940
+ checkPanel(extension, seen, "admin extension");
2941
+ continue;
2710
2942
  }
2711
- if (seen.has(panel.id))
2712
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2713
- seen.add(panel.id);
2714
- if (panel.title.trim() === "")
2715
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2943
+ const id = extension.id ?? "sql";
2944
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2716
2945
  }
2717
2946
  };
2718
2947
 
@@ -2946,6 +3175,12 @@ var renderAdminDocument = (service) => {
2946
3175
  border-radius: 999px; padding: 4px 8px;
2947
3176
  }
2948
3177
  .chip i { color: var(--faint); font-style: normal; }
3178
+ .sql-layout {
3179
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3180
+ }
3181
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3182
+ .sql-tables button { text-align: left; }
3183
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2949
3184
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2950
3185
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2951
3186
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -3009,7 +3244,7 @@ var renderAdminDocument = (service) => {
3009
3244
  padding: 8px;
3010
3245
  }
3011
3246
  nav.side button { white-space: nowrap; flex: none; }
3012
- .split { grid-template-columns: minmax(0, 1fr); }
3247
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
3013
3248
  main { padding: 14px; }
3014
3249
  table, thead, tbody, tr, th, td { display: block; }
3015
3250
  thead { display: none; }
@@ -3180,6 +3415,24 @@ var json2 = (body) => new Response(JSON.stringify(body), {
3180
3415
  status: 200,
3181
3416
  headers: { "content-type": "application/json; charset=utf-8" }
3182
3417
  });
3418
+ var describeExtension = (extension) => {
3419
+ if (extension.kind === "sql") {
3420
+ return {
3421
+ kind: "sql",
3422
+ id: extension.id ?? "sql",
3423
+ title: extension.title ?? "SQL",
3424
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3425
+ };
3426
+ }
3427
+ return {
3428
+ kind: "panel",
3429
+ id: extension.id,
3430
+ title: extension.title,
3431
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3432
+ html: extension.html,
3433
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3434
+ };
3435
+ };
3183
3436
  var adminUiRoutes = (service, ui) => {
3184
3437
  const shell = () => renderAdminDocument(service);
3185
3438
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -3194,7 +3447,8 @@ var adminUiRoutes = (service, ui) => {
3194
3447
  ...panel.description !== void 0 ? { description: panel.description } : {},
3195
3448
  html: panel.html,
3196
3449
  ...panel.script !== void 0 ? { script: panel.script } : {}
3197
- }))
3450
+ })),
3451
+ extensions: (ui?.extensions ?? []).map(describeExtension)
3198
3452
  })
3199
3453
  };
3200
3454
  };
@@ -3881,7 +4135,7 @@ var stateAdminRoutes = (routes) => {
3881
4135
  };
3882
4136
 
3883
4137
  // ../core/dist/version.js
3884
- var PACKAGE_VERSION = true ? "1.6.1" : UNRELEASED_VERSION;
4138
+ var PACKAGE_VERSION = true ? "1.7.0" : UNRELEASED_VERSION;
3885
4139
 
3886
4140
  // ../core/dist/signing.js
3887
4141
  var encoder = new TextEncoder();
@@ -5601,4 +5855,4 @@ export {
5601
5855
  apiKeyCredential,
5602
5856
  AhaAPI
5603
5857
  };
5604
- //# sourceMappingURL=chunk-O6ESJ7KQ.js.map
5858
+ //# sourceMappingURL=chunk-R4LJGILO.js.map