@crvouga/mockingbird-service-flex 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-flex
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
@@ -1925,6 +1925,167 @@ function faultPresetList(value) {
1925
1925
  })
1926
1926
  };
1927
1927
  }
1928
+ function mountSqlExplorer(root, api) {
1929
+ const cell = (value) => {
1930
+ if (value === null || value === void 0)
1931
+ return "";
1932
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1933
+ return String(value);
1934
+ }
1935
+ return JSON.stringify(value) ?? "";
1936
+ };
1937
+ root.replaceChildren();
1938
+ const layout2 = document.createElement("div");
1939
+ layout2.className = "sql-layout";
1940
+ const tables = document.createElement("div");
1941
+ tables.className = "sql-tables";
1942
+ const stack = document.createElement("div");
1943
+ stack.className = "stack";
1944
+ const banner = document.createElement("p");
1945
+ banner.className = "banner";
1946
+ const grid = document.createElement("div");
1947
+ const input = document.createElement("textarea");
1948
+ input.className = "sql-input";
1949
+ input.spellcheck = false;
1950
+ input.placeholder = "SELECT * FROM ...";
1951
+ const actions = document.createElement("div");
1952
+ actions.className = "row-actions";
1953
+ const run = document.createElement("button");
1954
+ run.type = "button";
1955
+ run.textContent = "Run";
1956
+ actions.append(run);
1957
+ const result = document.createElement("pre");
1958
+ stack.append(banner, grid, input, actions, result);
1959
+ layout2.append(tables, stack);
1960
+ root.append(layout2);
1961
+ const showError = (error2) => {
1962
+ banner.textContent = error2 instanceof Error ? error2.message : String(error2);
1963
+ banner.classList.add("show");
1964
+ };
1965
+ const clearError = () => {
1966
+ banner.textContent = "";
1967
+ banner.classList.remove("show");
1968
+ };
1969
+ const renderGrid = (columns, rows) => {
1970
+ grid.replaceChildren();
1971
+ if (columns.length === 0) {
1972
+ const empty = document.createElement("p");
1973
+ empty.className = "empty";
1974
+ empty.textContent = "No rows.";
1975
+ grid.append(empty);
1976
+ return;
1977
+ }
1978
+ const table = document.createElement("table");
1979
+ const head = document.createElement("thead");
1980
+ const headRow = document.createElement("tr");
1981
+ for (const column of columns) {
1982
+ const th = document.createElement("th");
1983
+ th.textContent = column;
1984
+ headRow.append(th);
1985
+ }
1986
+ head.append(headRow);
1987
+ const body = document.createElement("tbody");
1988
+ for (const row of rows) {
1989
+ const tr = document.createElement("tr");
1990
+ for (const column of columns) {
1991
+ const td = document.createElement("td");
1992
+ td.dataset.label = column;
1993
+ td.textContent = cell(row[column]);
1994
+ tr.append(td);
1995
+ }
1996
+ body.append(tr);
1997
+ }
1998
+ table.append(head, body);
1999
+ grid.append(table);
2000
+ };
2001
+ const rowsOf = (value) => {
2002
+ if (!isRecord2(value) || !Array.isArray(value.rows))
2003
+ return [];
2004
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
2005
+ };
2006
+ const columnsOf = (value, rows) => {
2007
+ if (isRecord2(value) && Array.isArray(value.columns)) {
2008
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
2009
+ if (named.length > 0)
2010
+ return named;
2011
+ }
2012
+ const first = rows[0];
2013
+ return first === void 0 ? [] : Object.keys(first);
2014
+ };
2015
+ let selected = "";
2016
+ const loadPage = async (schema, name) => {
2017
+ selected = `${schema}.${name}`;
2018
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
2019
+ const rows = rowsOf(page);
2020
+ renderGrid(columnsOf(page, rows), rows);
2021
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
2022
+ result.textContent = `${selected} \xB7 ${total} rows`;
2023
+ for (const button of tables.querySelectorAll("button")) {
2024
+ if (!(button instanceof HTMLButtonElement))
2025
+ continue;
2026
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
2027
+ }
2028
+ };
2029
+ const loadTables = async () => {
2030
+ const payload = await api.get("/sql/tables");
2031
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
2032
+ tables.replaceChildren();
2033
+ if (listed.length === 0) {
2034
+ const empty = document.createElement("p");
2035
+ empty.className = "empty";
2036
+ empty.textContent = "No tables.";
2037
+ tables.append(empty);
2038
+ return;
2039
+ }
2040
+ for (const item of listed) {
2041
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
2042
+ continue;
2043
+ const button = document.createElement("button");
2044
+ button.type = "button";
2045
+ button.dataset.schema = item.schema;
2046
+ button.dataset.table = item.name;
2047
+ button.textContent = `${item.schema}.${item.name}`;
2048
+ tables.append(button);
2049
+ }
2050
+ };
2051
+ tables.addEventListener("click", (event) => {
2052
+ const target = event.target;
2053
+ if (!(target instanceof Element))
2054
+ return;
2055
+ const button = target.closest("button");
2056
+ if (!(button instanceof HTMLButtonElement))
2057
+ return;
2058
+ const schema = button.dataset.schema;
2059
+ const name = button.dataset.table;
2060
+ if (schema === void 0 || name === void 0)
2061
+ return;
2062
+ clearError();
2063
+ loadPage(schema, name).catch(showError);
2064
+ });
2065
+ run.addEventListener("click", () => {
2066
+ const sql = input.value.trim();
2067
+ if (sql === "") {
2068
+ showError(new Error("Enter a statement"));
2069
+ return;
2070
+ }
2071
+ clearError();
2072
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
2073
+ const rows = rowsOf(payload);
2074
+ renderGrid(columnsOf(payload, rows), rows);
2075
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
2076
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
2077
+ result.textContent = `${count} rows${truncated}`;
2078
+ }).catch(showError);
2079
+ });
2080
+ const namespace = document.getElementById("namespace");
2081
+ if (namespace) {
2082
+ namespace.addEventListener("change", () => {
2083
+ clearError();
2084
+ loadTables().catch(showError);
2085
+ });
2086
+ }
2087
+ loadTables().catch(showError);
2088
+ }
1928
2089
  function bootAdmin(config) {
1929
2090
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1930
2091
  const sources = ["declared", "inferred", "mixed"];
@@ -2601,6 +2762,22 @@ function bootAdmin(config) {
2601
2762
  panel.script = value.script;
2602
2763
  return panel;
2603
2764
  };
2765
+ const decodeExtension = (value) => {
2766
+ if (!isRecord2(value))
2767
+ return void 0;
2768
+ if (value.kind === "sql") {
2769
+ return {
2770
+ kind: "sql",
2771
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2772
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2773
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2774
+ };
2775
+ }
2776
+ if (value.kind !== "panel")
2777
+ return void 0;
2778
+ const panel = decodePanel(value);
2779
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2780
+ };
2604
2781
  const mountPanels = (panels) => {
2605
2782
  const nav = el("nav", HTMLElement);
2606
2783
  const views = el("views", HTMLElement);
@@ -2654,10 +2831,48 @@ function bootAdmin(config) {
2654
2831
  return decoded === void 0 ? [] : [decoded];
2655
2832
  });
2656
2833
  mountPanels(panels);
2834
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2835
+ const decoded = decodeExtension(extension);
2836
+ return decoded === void 0 ? [] : [decoded];
2837
+ });
2838
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2839
+ mountPanels(extensionPanels);
2840
+ for (const extension of extensions) {
2841
+ if (extension.kind !== "sql")
2842
+ continue;
2843
+ const nav = el("nav", HTMLElement);
2844
+ const views = el("views", HTMLElement);
2845
+ const button = document.createElement("button");
2846
+ button.type = "button";
2847
+ button.dataset.view = extension.id;
2848
+ button.textContent = extension.title;
2849
+ nav.append(button);
2850
+ const section = document.createElement("section");
2851
+ section.className = "view";
2852
+ section.id = `view-${extension.id}`;
2853
+ section.hidden = true;
2854
+ const title = document.createElement("h2");
2855
+ title.textContent = extension.title;
2856
+ const lede = document.createElement("p");
2857
+ lede.className = "lede";
2858
+ lede.textContent = extension.description;
2859
+ const body = document.createElement("div");
2860
+ body.className = "panel-body";
2861
+ section.append(title, lede, body);
2862
+ views.append(section);
2863
+ mountSqlExplorer(body, panelApi);
2864
+ }
2657
2865
  return refresh();
2658
2866
  }).catch(showError);
2659
2867
  }
2660
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2868
+ var clientPrelude = [
2869
+ isRecord2,
2870
+ mountAdminBrand,
2871
+ startAdminBrand,
2872
+ faultPresetList,
2873
+ mountSqlExplorer,
2874
+ bootAdmin
2875
+ ].map((fn) => fn.toString()).join("\n");
2661
2876
  var adminClientSource = (config) => {
2662
2877
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2663
2878
  const entry = bootAdmin.name;
@@ -2707,19 +2922,33 @@ var STANDARD_ADMIN_ROUTES = [
2707
2922
  "GET /ui/manifest"
2708
2923
  ];
2709
2924
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2925
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2926
+ var checkPanel = (panel, seen, label) => {
2927
+ if (!PANEL_ID.test(panel.id)) {
2928
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2929
+ }
2930
+ if (RESERVED_VIEWS.has(panel.id)) {
2931
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2932
+ }
2933
+ if (seen.has(panel.id))
2934
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2935
+ seen.add(panel.id);
2936
+ if (panel.title.trim() === "")
2937
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2938
+ };
2710
2939
  var assertAdminUi = (ui) => {
2711
- if (!ui?.panels)
2940
+ if (!ui)
2712
2941
  return;
2713
2942
  const seen = /* @__PURE__ */ new Set();
2714
- for (const panel of ui.panels) {
2715
- if (!PANEL_ID.test(panel.id)) {
2716
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2943
+ for (const panel of ui.panels ?? [])
2944
+ checkPanel(panel, seen, "admin panel");
2945
+ for (const extension of ui.extensions ?? []) {
2946
+ if (extension.kind === "panel") {
2947
+ checkPanel(extension, seen, "admin extension");
2948
+ continue;
2717
2949
  }
2718
- if (seen.has(panel.id))
2719
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2720
- seen.add(panel.id);
2721
- if (panel.title.trim() === "")
2722
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2950
+ const id = extension.id ?? "sql";
2951
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2723
2952
  }
2724
2953
  };
2725
2954
 
@@ -2953,6 +3182,12 @@ var renderAdminDocument = (service) => {
2953
3182
  border-radius: 999px; padding: 4px 8px;
2954
3183
  }
2955
3184
  .chip i { color: var(--faint); font-style: normal; }
3185
+ .sql-layout {
3186
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3187
+ }
3188
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3189
+ .sql-tables button { text-align: left; }
3190
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2956
3191
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2957
3192
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2958
3193
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -3016,7 +3251,7 @@ var renderAdminDocument = (service) => {
3016
3251
  padding: 8px;
3017
3252
  }
3018
3253
  nav.side button { white-space: nowrap; flex: none; }
3019
- .split { grid-template-columns: minmax(0, 1fr); }
3254
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
3020
3255
  main { padding: 14px; }
3021
3256
  table, thead, tbody, tr, th, td { display: block; }
3022
3257
  thead { display: none; }
@@ -3187,6 +3422,24 @@ var json2 = (body) => new Response(JSON.stringify(body), {
3187
3422
  status: 200,
3188
3423
  headers: { "content-type": "application/json; charset=utf-8" }
3189
3424
  });
3425
+ var describeExtension = (extension) => {
3426
+ if (extension.kind === "sql") {
3427
+ return {
3428
+ kind: "sql",
3429
+ id: extension.id ?? "sql",
3430
+ title: extension.title ?? "SQL",
3431
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3432
+ };
3433
+ }
3434
+ return {
3435
+ kind: "panel",
3436
+ id: extension.id,
3437
+ title: extension.title,
3438
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3439
+ html: extension.html,
3440
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3441
+ };
3442
+ };
3190
3443
  var adminUiRoutes = (service, ui) => {
3191
3444
  const shell = () => renderAdminDocument(service);
3192
3445
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -3201,7 +3454,8 @@ var adminUiRoutes = (service, ui) => {
3201
3454
  ...panel.description !== void 0 ? { description: panel.description } : {},
3202
3455
  html: panel.html,
3203
3456
  ...panel.script !== void 0 ? { script: panel.script } : {}
3204
- }))
3457
+ })),
3458
+ extensions: (ui?.extensions ?? []).map(describeExtension)
3205
3459
  })
3206
3460
  };
3207
3461
  };
@@ -3878,7 +4132,7 @@ var stateAdminRoutes = (routes) => {
3878
4132
  };
3879
4133
 
3880
4134
  // ../core/dist/version.js
3881
- var PACKAGE_VERSION = true ? "1.6.1" : UNRELEASED_VERSION;
4135
+ var PACKAGE_VERSION = true ? "1.7.0" : UNRELEASED_VERSION;
3882
4136
 
3883
4137
  // ../core/dist/signing.js
3884
4138
  var encoder = new TextEncoder();
@@ -7010,4 +7264,4 @@ export {
7010
7264
  FlexAPI,
7011
7265
  isNextActionType
7012
7266
  };
7013
- //# sourceMappingURL=chunk-TA2IWDFT.js.map
7267
+ //# sourceMappingURL=chunk-56LAVEQL.js.map