@crvouga/mockingbird-service-plane 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-plane
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
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createRuntime
3
- } from "./chunk-IVHDD2UD.js";
3
+ } from "./chunk-NVLTLMDI.js";
4
4
 
5
5
  // ../../adapters/node/dist/cli.js
6
6
  import { readFile } from "node:fs/promises";
@@ -356,4 +356,4 @@ export {
356
356
  createServer2 as createServer,
357
357
  serveTarget
358
358
  };
359
- //# sourceMappingURL=chunk-IO3CU5ZF.js.map
359
+ //# sourceMappingURL=chunk-DC2XELGV.js.map
@@ -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());
@@ -1899,6 +1899,167 @@ function faultPresetList(value) {
1899
1899
  })
1900
1900
  };
1901
1901
  }
1902
+ function mountSqlExplorer(root, api) {
1903
+ const cell = (value) => {
1904
+ if (value === null || value === void 0)
1905
+ return "";
1906
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1907
+ return String(value);
1908
+ }
1909
+ return JSON.stringify(value) ?? "";
1910
+ };
1911
+ root.replaceChildren();
1912
+ const layout = document.createElement("div");
1913
+ layout.className = "sql-layout";
1914
+ const tables = document.createElement("div");
1915
+ tables.className = "sql-tables";
1916
+ const stack = document.createElement("div");
1917
+ stack.className = "stack";
1918
+ const banner = document.createElement("p");
1919
+ banner.className = "banner";
1920
+ const grid = document.createElement("div");
1921
+ const input = document.createElement("textarea");
1922
+ input.className = "sql-input";
1923
+ input.spellcheck = false;
1924
+ input.placeholder = "SELECT * FROM ...";
1925
+ const actions = document.createElement("div");
1926
+ actions.className = "row-actions";
1927
+ const run = document.createElement("button");
1928
+ run.type = "button";
1929
+ run.textContent = "Run";
1930
+ actions.append(run);
1931
+ const result = document.createElement("pre");
1932
+ stack.append(banner, grid, input, actions, result);
1933
+ layout.append(tables, stack);
1934
+ root.append(layout);
1935
+ const showError = (error) => {
1936
+ banner.textContent = error instanceof Error ? error.message : String(error);
1937
+ banner.classList.add("show");
1938
+ };
1939
+ const clearError = () => {
1940
+ banner.textContent = "";
1941
+ banner.classList.remove("show");
1942
+ };
1943
+ const renderGrid = (columns, rows) => {
1944
+ grid.replaceChildren();
1945
+ if (columns.length === 0) {
1946
+ const empty = document.createElement("p");
1947
+ empty.className = "empty";
1948
+ empty.textContent = "No rows.";
1949
+ grid.append(empty);
1950
+ return;
1951
+ }
1952
+ const table = document.createElement("table");
1953
+ const head = document.createElement("thead");
1954
+ const headRow = document.createElement("tr");
1955
+ for (const column of columns) {
1956
+ const th = document.createElement("th");
1957
+ th.textContent = column;
1958
+ headRow.append(th);
1959
+ }
1960
+ head.append(headRow);
1961
+ const body = document.createElement("tbody");
1962
+ for (const row of rows) {
1963
+ const tr = document.createElement("tr");
1964
+ for (const column of columns) {
1965
+ const td = document.createElement("td");
1966
+ td.dataset.label = column;
1967
+ td.textContent = cell(row[column]);
1968
+ tr.append(td);
1969
+ }
1970
+ body.append(tr);
1971
+ }
1972
+ table.append(head, body);
1973
+ grid.append(table);
1974
+ };
1975
+ const rowsOf = (value) => {
1976
+ if (!isRecord2(value) || !Array.isArray(value.rows))
1977
+ return [];
1978
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
1979
+ };
1980
+ const columnsOf = (value, rows) => {
1981
+ if (isRecord2(value) && Array.isArray(value.columns)) {
1982
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
1983
+ if (named.length > 0)
1984
+ return named;
1985
+ }
1986
+ const first = rows[0];
1987
+ return first === void 0 ? [] : Object.keys(first);
1988
+ };
1989
+ let selected = "";
1990
+ const loadPage = async (schema, name) => {
1991
+ selected = `${schema}.${name}`;
1992
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
1993
+ const rows = rowsOf(page);
1994
+ renderGrid(columnsOf(page, rows), rows);
1995
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
1996
+ result.textContent = `${selected} \xB7 ${total} rows`;
1997
+ for (const button of tables.querySelectorAll("button")) {
1998
+ if (!(button instanceof HTMLButtonElement))
1999
+ continue;
2000
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
2001
+ }
2002
+ };
2003
+ const loadTables = async () => {
2004
+ const payload = await api.get("/sql/tables");
2005
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
2006
+ tables.replaceChildren();
2007
+ if (listed.length === 0) {
2008
+ const empty = document.createElement("p");
2009
+ empty.className = "empty";
2010
+ empty.textContent = "No tables.";
2011
+ tables.append(empty);
2012
+ return;
2013
+ }
2014
+ for (const item of listed) {
2015
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
2016
+ continue;
2017
+ const button = document.createElement("button");
2018
+ button.type = "button";
2019
+ button.dataset.schema = item.schema;
2020
+ button.dataset.table = item.name;
2021
+ button.textContent = `${item.schema}.${item.name}`;
2022
+ tables.append(button);
2023
+ }
2024
+ };
2025
+ tables.addEventListener("click", (event) => {
2026
+ const target = event.target;
2027
+ if (!(target instanceof Element))
2028
+ return;
2029
+ const button = target.closest("button");
2030
+ if (!(button instanceof HTMLButtonElement))
2031
+ return;
2032
+ const schema = button.dataset.schema;
2033
+ const name = button.dataset.table;
2034
+ if (schema === void 0 || name === void 0)
2035
+ return;
2036
+ clearError();
2037
+ loadPage(schema, name).catch(showError);
2038
+ });
2039
+ run.addEventListener("click", () => {
2040
+ const sql = input.value.trim();
2041
+ if (sql === "") {
2042
+ showError(new Error("Enter a statement"));
2043
+ return;
2044
+ }
2045
+ clearError();
2046
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
2047
+ const rows = rowsOf(payload);
2048
+ renderGrid(columnsOf(payload, rows), rows);
2049
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
2050
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
2051
+ result.textContent = `${count} rows${truncated}`;
2052
+ }).catch(showError);
2053
+ });
2054
+ const namespace = document.getElementById("namespace");
2055
+ if (namespace) {
2056
+ namespace.addEventListener("change", () => {
2057
+ clearError();
2058
+ loadTables().catch(showError);
2059
+ });
2060
+ }
2061
+ loadTables().catch(showError);
2062
+ }
1902
2063
  function bootAdmin(config) {
1903
2064
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1904
2065
  const sources = ["declared", "inferred", "mixed"];
@@ -2575,6 +2736,22 @@ function bootAdmin(config) {
2575
2736
  panel.script = value.script;
2576
2737
  return panel;
2577
2738
  };
2739
+ const decodeExtension = (value) => {
2740
+ if (!isRecord2(value))
2741
+ return void 0;
2742
+ if (value.kind === "sql") {
2743
+ return {
2744
+ kind: "sql",
2745
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2746
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2747
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2748
+ };
2749
+ }
2750
+ if (value.kind !== "panel")
2751
+ return void 0;
2752
+ const panel = decodePanel(value);
2753
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2754
+ };
2578
2755
  const mountPanels = (panels) => {
2579
2756
  const nav = el("nav", HTMLElement);
2580
2757
  const views = el("views", HTMLElement);
@@ -2628,10 +2805,48 @@ function bootAdmin(config) {
2628
2805
  return decoded === void 0 ? [] : [decoded];
2629
2806
  });
2630
2807
  mountPanels(panels);
2808
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2809
+ const decoded = decodeExtension(extension);
2810
+ return decoded === void 0 ? [] : [decoded];
2811
+ });
2812
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2813
+ mountPanels(extensionPanels);
2814
+ for (const extension of extensions) {
2815
+ if (extension.kind !== "sql")
2816
+ continue;
2817
+ const nav = el("nav", HTMLElement);
2818
+ const views = el("views", HTMLElement);
2819
+ const button = document.createElement("button");
2820
+ button.type = "button";
2821
+ button.dataset.view = extension.id;
2822
+ button.textContent = extension.title;
2823
+ nav.append(button);
2824
+ const section = document.createElement("section");
2825
+ section.className = "view";
2826
+ section.id = `view-${extension.id}`;
2827
+ section.hidden = true;
2828
+ const title = document.createElement("h2");
2829
+ title.textContent = extension.title;
2830
+ const lede = document.createElement("p");
2831
+ lede.className = "lede";
2832
+ lede.textContent = extension.description;
2833
+ const body = document.createElement("div");
2834
+ body.className = "panel-body";
2835
+ section.append(title, lede, body);
2836
+ views.append(section);
2837
+ mountSqlExplorer(body, panelApi);
2838
+ }
2631
2839
  return refresh();
2632
2840
  }).catch(showError);
2633
2841
  }
2634
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2842
+ var clientPrelude = [
2843
+ isRecord2,
2844
+ mountAdminBrand,
2845
+ startAdminBrand,
2846
+ faultPresetList,
2847
+ mountSqlExplorer,
2848
+ bootAdmin
2849
+ ].map((fn) => fn.toString()).join("\n");
2635
2850
  var adminClientSource = (config) => {
2636
2851
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2637
2852
  const entry = bootAdmin.name;
@@ -2681,19 +2896,33 @@ var STANDARD_ADMIN_ROUTES = [
2681
2896
  "GET /ui/manifest"
2682
2897
  ];
2683
2898
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2899
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2900
+ var checkPanel = (panel, seen, label) => {
2901
+ if (!PANEL_ID.test(panel.id)) {
2902
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2903
+ }
2904
+ if (RESERVED_VIEWS.has(panel.id)) {
2905
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2906
+ }
2907
+ if (seen.has(panel.id))
2908
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2909
+ seen.add(panel.id);
2910
+ if (panel.title.trim() === "")
2911
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2912
+ };
2684
2913
  var assertAdminUi = (ui) => {
2685
- if (!ui?.panels)
2914
+ if (!ui)
2686
2915
  return;
2687
2916
  const seen = /* @__PURE__ */ new Set();
2688
- for (const panel of ui.panels) {
2689
- if (!PANEL_ID.test(panel.id)) {
2690
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2917
+ for (const panel of ui.panels ?? [])
2918
+ checkPanel(panel, seen, "admin panel");
2919
+ for (const extension of ui.extensions ?? []) {
2920
+ if (extension.kind === "panel") {
2921
+ checkPanel(extension, seen, "admin extension");
2922
+ continue;
2691
2923
  }
2692
- if (seen.has(panel.id))
2693
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2694
- seen.add(panel.id);
2695
- if (panel.title.trim() === "")
2696
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2924
+ const id = extension.id ?? "sql";
2925
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2697
2926
  }
2698
2927
  };
2699
2928
 
@@ -2927,6 +3156,12 @@ var renderAdminDocument = (service) => {
2927
3156
  border-radius: 999px; padding: 4px 8px;
2928
3157
  }
2929
3158
  .chip i { color: var(--faint); font-style: normal; }
3159
+ .sql-layout {
3160
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3161
+ }
3162
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3163
+ .sql-tables button { text-align: left; }
3164
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2930
3165
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2931
3166
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2932
3167
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -2990,7 +3225,7 @@ var renderAdminDocument = (service) => {
2990
3225
  padding: 8px;
2991
3226
  }
2992
3227
  nav.side button { white-space: nowrap; flex: none; }
2993
- .split { grid-template-columns: minmax(0, 1fr); }
3228
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
2994
3229
  main { padding: 14px; }
2995
3230
  table, thead, tbody, tr, th, td { display: block; }
2996
3231
  thead { display: none; }
@@ -3161,6 +3396,24 @@ var json2 = (body) => new Response(JSON.stringify(body), {
3161
3396
  status: 200,
3162
3397
  headers: { "content-type": "application/json; charset=utf-8" }
3163
3398
  });
3399
+ var describeExtension = (extension) => {
3400
+ if (extension.kind === "sql") {
3401
+ return {
3402
+ kind: "sql",
3403
+ id: extension.id ?? "sql",
3404
+ title: extension.title ?? "SQL",
3405
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3406
+ };
3407
+ }
3408
+ return {
3409
+ kind: "panel",
3410
+ id: extension.id,
3411
+ title: extension.title,
3412
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3413
+ html: extension.html,
3414
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3415
+ };
3416
+ };
3164
3417
  var adminUiRoutes = (service, ui) => {
3165
3418
  const shell = () => renderAdminDocument(service);
3166
3419
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -3175,7 +3428,8 @@ var adminUiRoutes = (service, ui) => {
3175
3428
  ...panel.description !== void 0 ? { description: panel.description } : {},
3176
3429
  html: panel.html,
3177
3430
  ...panel.script !== void 0 ? { script: panel.script } : {}
3178
- }))
3431
+ })),
3432
+ extensions: (ui?.extensions ?? []).map(describeExtension)
3179
3433
  })
3180
3434
  };
3181
3435
  };
@@ -3852,7 +4106,7 @@ var stateAdminRoutes = (routes) => {
3852
4106
  };
3853
4107
 
3854
4108
  // ../core/dist/version.js
3855
- var PACKAGE_VERSION = true ? "1.6.1" : UNRELEASED_VERSION;
4109
+ var PACKAGE_VERSION = true ? "1.7.1" : UNRELEASED_VERSION;
3856
4110
 
3857
4111
  // ../core/dist/webhooks.js
3858
4112
  var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
@@ -5222,4 +5476,4 @@ export {
5222
5476
  apiKeyCredential,
5223
5477
  PlaneAPI
5224
5478
  };
5225
- //# sourceMappingURL=chunk-IVHDD2UD.js.map
5479
+ //# sourceMappingURL=chunk-NVLTLMDI.js.map