@crvouga/mockingbird-service-slack 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-slack
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
@@ -5,7 +5,7 @@ import {
5
5
  markSocketClosed,
6
6
  openSocketCount,
7
7
  unbindSocketTransport
8
- } from "./chunk-6NKJ75J3.js";
8
+ } from "./chunk-E47OMSFP.js";
9
9
 
10
10
  // ../../adapters/node/dist/cli.js
11
11
  import { readFile } from "node:fs/promises";
@@ -650,4 +650,4 @@ export {
650
650
  createServer2 as createServer,
651
651
  serveTarget
652
652
  };
653
- //# sourceMappingURL=chunk-PKYQRMRQ.js.map
653
+ //# sourceMappingURL=chunk-3RJHDGHW.js.map
@@ -1722,6 +1722,167 @@ function faultPresetList(value) {
1722
1722
  })
1723
1723
  };
1724
1724
  }
1725
+ function mountSqlExplorer(root, api) {
1726
+ const cell = (value) => {
1727
+ if (value === null || value === void 0)
1728
+ return "";
1729
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1730
+ return String(value);
1731
+ }
1732
+ return JSON.stringify(value) ?? "";
1733
+ };
1734
+ root.replaceChildren();
1735
+ const layout = document.createElement("div");
1736
+ layout.className = "sql-layout";
1737
+ const tables = document.createElement("div");
1738
+ tables.className = "sql-tables";
1739
+ const stack = document.createElement("div");
1740
+ stack.className = "stack";
1741
+ const banner = document.createElement("p");
1742
+ banner.className = "banner";
1743
+ const grid = document.createElement("div");
1744
+ const input = document.createElement("textarea");
1745
+ input.className = "sql-input";
1746
+ input.spellcheck = false;
1747
+ input.placeholder = "SELECT * FROM ...";
1748
+ const actions = document.createElement("div");
1749
+ actions.className = "row-actions";
1750
+ const run = document.createElement("button");
1751
+ run.type = "button";
1752
+ run.textContent = "Run";
1753
+ actions.append(run);
1754
+ const result = document.createElement("pre");
1755
+ stack.append(banner, grid, input, actions, result);
1756
+ layout.append(tables, stack);
1757
+ root.append(layout);
1758
+ const showError = (error) => {
1759
+ banner.textContent = error instanceof Error ? error.message : String(error);
1760
+ banner.classList.add("show");
1761
+ };
1762
+ const clearError = () => {
1763
+ banner.textContent = "";
1764
+ banner.classList.remove("show");
1765
+ };
1766
+ const renderGrid = (columns, rows) => {
1767
+ grid.replaceChildren();
1768
+ if (columns.length === 0) {
1769
+ const empty = document.createElement("p");
1770
+ empty.className = "empty";
1771
+ empty.textContent = "No rows.";
1772
+ grid.append(empty);
1773
+ return;
1774
+ }
1775
+ const table = document.createElement("table");
1776
+ const head = document.createElement("thead");
1777
+ const headRow = document.createElement("tr");
1778
+ for (const column of columns) {
1779
+ const th = document.createElement("th");
1780
+ th.textContent = column;
1781
+ headRow.append(th);
1782
+ }
1783
+ head.append(headRow);
1784
+ const body = document.createElement("tbody");
1785
+ for (const row of rows) {
1786
+ const tr = document.createElement("tr");
1787
+ for (const column of columns) {
1788
+ const td = document.createElement("td");
1789
+ td.dataset.label = column;
1790
+ td.textContent = cell(row[column]);
1791
+ tr.append(td);
1792
+ }
1793
+ body.append(tr);
1794
+ }
1795
+ table.append(head, body);
1796
+ grid.append(table);
1797
+ };
1798
+ const rowsOf = (value) => {
1799
+ if (!isRecord2(value) || !Array.isArray(value.rows))
1800
+ return [];
1801
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
1802
+ };
1803
+ const columnsOf = (value, rows) => {
1804
+ if (isRecord2(value) && Array.isArray(value.columns)) {
1805
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
1806
+ if (named.length > 0)
1807
+ return named;
1808
+ }
1809
+ const first = rows[0];
1810
+ return first === void 0 ? [] : Object.keys(first);
1811
+ };
1812
+ let selected = "";
1813
+ const loadPage = async (schema, name) => {
1814
+ selected = `${schema}.${name}`;
1815
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
1816
+ const rows = rowsOf(page);
1817
+ renderGrid(columnsOf(page, rows), rows);
1818
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
1819
+ result.textContent = `${selected} \xB7 ${total} rows`;
1820
+ for (const button of tables.querySelectorAll("button")) {
1821
+ if (!(button instanceof HTMLButtonElement))
1822
+ continue;
1823
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
1824
+ }
1825
+ };
1826
+ const loadTables = async () => {
1827
+ const payload = await api.get("/sql/tables");
1828
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
1829
+ tables.replaceChildren();
1830
+ if (listed.length === 0) {
1831
+ const empty = document.createElement("p");
1832
+ empty.className = "empty";
1833
+ empty.textContent = "No tables.";
1834
+ tables.append(empty);
1835
+ return;
1836
+ }
1837
+ for (const item of listed) {
1838
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
1839
+ continue;
1840
+ const button = document.createElement("button");
1841
+ button.type = "button";
1842
+ button.dataset.schema = item.schema;
1843
+ button.dataset.table = item.name;
1844
+ button.textContent = `${item.schema}.${item.name}`;
1845
+ tables.append(button);
1846
+ }
1847
+ };
1848
+ tables.addEventListener("click", (event) => {
1849
+ const target = event.target;
1850
+ if (!(target instanceof Element))
1851
+ return;
1852
+ const button = target.closest("button");
1853
+ if (!(button instanceof HTMLButtonElement))
1854
+ return;
1855
+ const schema = button.dataset.schema;
1856
+ const name = button.dataset.table;
1857
+ if (schema === void 0 || name === void 0)
1858
+ return;
1859
+ clearError();
1860
+ loadPage(schema, name).catch(showError);
1861
+ });
1862
+ run.addEventListener("click", () => {
1863
+ const sql = input.value.trim();
1864
+ if (sql === "") {
1865
+ showError(new Error("Enter a statement"));
1866
+ return;
1867
+ }
1868
+ clearError();
1869
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
1870
+ const rows = rowsOf(payload);
1871
+ renderGrid(columnsOf(payload, rows), rows);
1872
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
1873
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
1874
+ result.textContent = `${count} rows${truncated}`;
1875
+ }).catch(showError);
1876
+ });
1877
+ const namespace = document.getElementById("namespace");
1878
+ if (namespace) {
1879
+ namespace.addEventListener("change", () => {
1880
+ clearError();
1881
+ loadTables().catch(showError);
1882
+ });
1883
+ }
1884
+ loadTables().catch(showError);
1885
+ }
1725
1886
  function bootAdmin(config) {
1726
1887
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1727
1888
  const sources = ["declared", "inferred", "mixed"];
@@ -2398,6 +2559,22 @@ function bootAdmin(config) {
2398
2559
  panel.script = value.script;
2399
2560
  return panel;
2400
2561
  };
2562
+ const decodeExtension = (value) => {
2563
+ if (!isRecord2(value))
2564
+ return void 0;
2565
+ if (value.kind === "sql") {
2566
+ return {
2567
+ kind: "sql",
2568
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2569
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2570
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2571
+ };
2572
+ }
2573
+ if (value.kind !== "panel")
2574
+ return void 0;
2575
+ const panel = decodePanel(value);
2576
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2577
+ };
2401
2578
  const mountPanels = (panels) => {
2402
2579
  const nav = el("nav", HTMLElement);
2403
2580
  const views = el("views", HTMLElement);
@@ -2451,10 +2628,48 @@ function bootAdmin(config) {
2451
2628
  return decoded === void 0 ? [] : [decoded];
2452
2629
  });
2453
2630
  mountPanels(panels);
2631
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2632
+ const decoded = decodeExtension(extension);
2633
+ return decoded === void 0 ? [] : [decoded];
2634
+ });
2635
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2636
+ mountPanels(extensionPanels);
2637
+ for (const extension of extensions) {
2638
+ if (extension.kind !== "sql")
2639
+ continue;
2640
+ const nav = el("nav", HTMLElement);
2641
+ const views = el("views", HTMLElement);
2642
+ const button = document.createElement("button");
2643
+ button.type = "button";
2644
+ button.dataset.view = extension.id;
2645
+ button.textContent = extension.title;
2646
+ nav.append(button);
2647
+ const section = document.createElement("section");
2648
+ section.className = "view";
2649
+ section.id = `view-${extension.id}`;
2650
+ section.hidden = true;
2651
+ const title = document.createElement("h2");
2652
+ title.textContent = extension.title;
2653
+ const lede = document.createElement("p");
2654
+ lede.className = "lede";
2655
+ lede.textContent = extension.description;
2656
+ const body = document.createElement("div");
2657
+ body.className = "panel-body";
2658
+ section.append(title, lede, body);
2659
+ views.append(section);
2660
+ mountSqlExplorer(body, panelApi);
2661
+ }
2454
2662
  return refresh();
2455
2663
  }).catch(showError);
2456
2664
  }
2457
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2665
+ var clientPrelude = [
2666
+ isRecord2,
2667
+ mountAdminBrand,
2668
+ startAdminBrand,
2669
+ faultPresetList,
2670
+ mountSqlExplorer,
2671
+ bootAdmin
2672
+ ].map((fn) => fn.toString()).join("\n");
2458
2673
  var adminClientSource = (config) => {
2459
2674
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2460
2675
  const entry = bootAdmin.name;
@@ -2504,19 +2719,33 @@ var STANDARD_ADMIN_ROUTES = [
2504
2719
  "GET /ui/manifest"
2505
2720
  ];
2506
2721
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2722
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2723
+ var checkPanel = (panel, seen, label) => {
2724
+ if (!PANEL_ID.test(panel.id)) {
2725
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2726
+ }
2727
+ if (RESERVED_VIEWS.has(panel.id)) {
2728
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2729
+ }
2730
+ if (seen.has(panel.id))
2731
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2732
+ seen.add(panel.id);
2733
+ if (panel.title.trim() === "")
2734
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2735
+ };
2507
2736
  var assertAdminUi = (ui) => {
2508
- if (!ui?.panels)
2737
+ if (!ui)
2509
2738
  return;
2510
2739
  const seen = /* @__PURE__ */ new Set();
2511
- for (const panel of ui.panels) {
2512
- if (!PANEL_ID.test(panel.id)) {
2513
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2740
+ for (const panel of ui.panels ?? [])
2741
+ checkPanel(panel, seen, "admin panel");
2742
+ for (const extension of ui.extensions ?? []) {
2743
+ if (extension.kind === "panel") {
2744
+ checkPanel(extension, seen, "admin extension");
2745
+ continue;
2514
2746
  }
2515
- if (seen.has(panel.id))
2516
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2517
- seen.add(panel.id);
2518
- if (panel.title.trim() === "")
2519
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2747
+ const id = extension.id ?? "sql";
2748
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2520
2749
  }
2521
2750
  };
2522
2751
 
@@ -2750,6 +2979,12 @@ var renderAdminDocument = (service) => {
2750
2979
  border-radius: 999px; padding: 4px 8px;
2751
2980
  }
2752
2981
  .chip i { color: var(--faint); font-style: normal; }
2982
+ .sql-layout {
2983
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
2984
+ }
2985
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
2986
+ .sql-tables button { text-align: left; }
2987
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2753
2988
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2754
2989
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2755
2990
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -2813,7 +3048,7 @@ var renderAdminDocument = (service) => {
2813
3048
  padding: 8px;
2814
3049
  }
2815
3050
  nav.side button { white-space: nowrap; flex: none; }
2816
- .split { grid-template-columns: minmax(0, 1fr); }
3051
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
2817
3052
  main { padding: 14px; }
2818
3053
  table, thead, tbody, tr, th, td { display: block; }
2819
3054
  thead { display: none; }
@@ -2984,6 +3219,24 @@ var json3 = (body) => new Response(JSON.stringify(body), {
2984
3219
  status: 200,
2985
3220
  headers: { "content-type": "application/json; charset=utf-8" }
2986
3221
  });
3222
+ var describeExtension = (extension) => {
3223
+ if (extension.kind === "sql") {
3224
+ return {
3225
+ kind: "sql",
3226
+ id: extension.id ?? "sql",
3227
+ title: extension.title ?? "SQL",
3228
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3229
+ };
3230
+ }
3231
+ return {
3232
+ kind: "panel",
3233
+ id: extension.id,
3234
+ title: extension.title,
3235
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3236
+ html: extension.html,
3237
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3238
+ };
3239
+ };
2987
3240
  var adminUiRoutes = (service, ui) => {
2988
3241
  const shell = () => renderAdminDocument(service);
2989
3242
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -2998,7 +3251,8 @@ var adminUiRoutes = (service, ui) => {
2998
3251
  ...panel.description !== void 0 ? { description: panel.description } : {},
2999
3252
  html: panel.html,
3000
3253
  ...panel.script !== void 0 ? { script: panel.script } : {}
3001
- }))
3254
+ })),
3255
+ extensions: (ui?.extensions ?? []).map(describeExtension)
3002
3256
  })
3003
3257
  };
3004
3258
  };
@@ -3601,7 +3855,7 @@ var stateAdminRoutes = (routes) => {
3601
3855
  };
3602
3856
 
3603
3857
  // ../core/dist/version.js
3604
- var PACKAGE_VERSION = true ? "1.6.1" : UNRELEASED_VERSION;
3858
+ var PACKAGE_VERSION = true ? "1.7.0" : UNRELEASED_VERSION;
3605
3859
 
3606
3860
  // ../core/dist/webhooks.js
3607
3861
  var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
@@ -5431,4 +5685,4 @@ export {
5431
5685
  slackCredential,
5432
5686
  SlackAPI
5433
5687
  };
5434
- //# sourceMappingURL=chunk-6NKJ75J3.js.map
5688
+ //# sourceMappingURL=chunk-E47OMSFP.js.map