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