@crvouga/mockingbird-service-posthog 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-posthog
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
@@ -2,7 +2,7 @@ import {
2
2
  ACME_FLAG_STATE,
3
3
  createRuntime,
4
4
  specsFromState
5
- } from "./chunk-F5TQPEXZ.js";
5
+ } from "./chunk-ZRB53DZ6.js";
6
6
 
7
7
  // ../../adapters/node/dist/cli.js
8
8
  import { readFile } from "node:fs/promises";
@@ -357,4 +357,4 @@ export {
357
357
  createServer2 as createServer,
358
358
  serveTarget
359
359
  };
360
- //# sourceMappingURL=chunk-3MHSTPMV.js.map
360
+ //# sourceMappingURL=chunk-FWRNARH5.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());
@@ -1682,6 +1682,167 @@ function faultPresetList(value) {
1682
1682
  })
1683
1683
  };
1684
1684
  }
1685
+ function mountSqlExplorer(root, api) {
1686
+ const cell = (value) => {
1687
+ if (value === null || value === void 0)
1688
+ return "";
1689
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1690
+ return String(value);
1691
+ }
1692
+ return JSON.stringify(value) ?? "";
1693
+ };
1694
+ root.replaceChildren();
1695
+ const layout = document.createElement("div");
1696
+ layout.className = "sql-layout";
1697
+ const tables = document.createElement("div");
1698
+ tables.className = "sql-tables";
1699
+ const stack = document.createElement("div");
1700
+ stack.className = "stack";
1701
+ const banner = document.createElement("p");
1702
+ banner.className = "banner";
1703
+ const grid = document.createElement("div");
1704
+ const input = document.createElement("textarea");
1705
+ input.className = "sql-input";
1706
+ input.spellcheck = false;
1707
+ input.placeholder = "SELECT * FROM ...";
1708
+ const actions = document.createElement("div");
1709
+ actions.className = "row-actions";
1710
+ const run = document.createElement("button");
1711
+ run.type = "button";
1712
+ run.textContent = "Run";
1713
+ actions.append(run);
1714
+ const result = document.createElement("pre");
1715
+ stack.append(banner, grid, input, actions, result);
1716
+ layout.append(tables, stack);
1717
+ root.append(layout);
1718
+ const showError = (error2) => {
1719
+ banner.textContent = error2 instanceof Error ? error2.message : String(error2);
1720
+ banner.classList.add("show");
1721
+ };
1722
+ const clearError = () => {
1723
+ banner.textContent = "";
1724
+ banner.classList.remove("show");
1725
+ };
1726
+ const renderGrid = (columns, rows) => {
1727
+ grid.replaceChildren();
1728
+ if (columns.length === 0) {
1729
+ const empty = document.createElement("p");
1730
+ empty.className = "empty";
1731
+ empty.textContent = "No rows.";
1732
+ grid.append(empty);
1733
+ return;
1734
+ }
1735
+ const table = document.createElement("table");
1736
+ const head = document.createElement("thead");
1737
+ const headRow = document.createElement("tr");
1738
+ for (const column of columns) {
1739
+ const th = document.createElement("th");
1740
+ th.textContent = column;
1741
+ headRow.append(th);
1742
+ }
1743
+ head.append(headRow);
1744
+ const body = document.createElement("tbody");
1745
+ for (const row of rows) {
1746
+ const tr = document.createElement("tr");
1747
+ for (const column of columns) {
1748
+ const td = document.createElement("td");
1749
+ td.dataset.label = column;
1750
+ td.textContent = cell(row[column]);
1751
+ tr.append(td);
1752
+ }
1753
+ body.append(tr);
1754
+ }
1755
+ table.append(head, body);
1756
+ grid.append(table);
1757
+ };
1758
+ const rowsOf = (value) => {
1759
+ if (!isRecord2(value) || !Array.isArray(value.rows))
1760
+ return [];
1761
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
1762
+ };
1763
+ const columnsOf = (value, rows) => {
1764
+ if (isRecord2(value) && Array.isArray(value.columns)) {
1765
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
1766
+ if (named.length > 0)
1767
+ return named;
1768
+ }
1769
+ const first = rows[0];
1770
+ return first === void 0 ? [] : Object.keys(first);
1771
+ };
1772
+ let selected = "";
1773
+ const loadPage = async (schema, name) => {
1774
+ selected = `${schema}.${name}`;
1775
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
1776
+ const rows = rowsOf(page);
1777
+ renderGrid(columnsOf(page, rows), rows);
1778
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
1779
+ result.textContent = `${selected} \xB7 ${total} rows`;
1780
+ for (const button of tables.querySelectorAll("button")) {
1781
+ if (!(button instanceof HTMLButtonElement))
1782
+ continue;
1783
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
1784
+ }
1785
+ };
1786
+ const loadTables = async () => {
1787
+ const payload = await api.get("/sql/tables");
1788
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
1789
+ tables.replaceChildren();
1790
+ if (listed.length === 0) {
1791
+ const empty = document.createElement("p");
1792
+ empty.className = "empty";
1793
+ empty.textContent = "No tables.";
1794
+ tables.append(empty);
1795
+ return;
1796
+ }
1797
+ for (const item of listed) {
1798
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
1799
+ continue;
1800
+ const button = document.createElement("button");
1801
+ button.type = "button";
1802
+ button.dataset.schema = item.schema;
1803
+ button.dataset.table = item.name;
1804
+ button.textContent = `${item.schema}.${item.name}`;
1805
+ tables.append(button);
1806
+ }
1807
+ };
1808
+ tables.addEventListener("click", (event) => {
1809
+ const target = event.target;
1810
+ if (!(target instanceof Element))
1811
+ return;
1812
+ const button = target.closest("button");
1813
+ if (!(button instanceof HTMLButtonElement))
1814
+ return;
1815
+ const schema = button.dataset.schema;
1816
+ const name = button.dataset.table;
1817
+ if (schema === void 0 || name === void 0)
1818
+ return;
1819
+ clearError();
1820
+ loadPage(schema, name).catch(showError);
1821
+ });
1822
+ run.addEventListener("click", () => {
1823
+ const sql = input.value.trim();
1824
+ if (sql === "") {
1825
+ showError(new Error("Enter a statement"));
1826
+ return;
1827
+ }
1828
+ clearError();
1829
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
1830
+ const rows = rowsOf(payload);
1831
+ renderGrid(columnsOf(payload, rows), rows);
1832
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
1833
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
1834
+ result.textContent = `${count} rows${truncated}`;
1835
+ }).catch(showError);
1836
+ });
1837
+ const namespace = document.getElementById("namespace");
1838
+ if (namespace) {
1839
+ namespace.addEventListener("change", () => {
1840
+ clearError();
1841
+ loadTables().catch(showError);
1842
+ });
1843
+ }
1844
+ loadTables().catch(showError);
1845
+ }
1685
1846
  function bootAdmin(config) {
1686
1847
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1687
1848
  const sources = ["declared", "inferred", "mixed"];
@@ -2358,6 +2519,22 @@ function bootAdmin(config) {
2358
2519
  panel.script = value.script;
2359
2520
  return panel;
2360
2521
  };
2522
+ const decodeExtension = (value) => {
2523
+ if (!isRecord2(value))
2524
+ return void 0;
2525
+ if (value.kind === "sql") {
2526
+ return {
2527
+ kind: "sql",
2528
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2529
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2530
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2531
+ };
2532
+ }
2533
+ if (value.kind !== "panel")
2534
+ return void 0;
2535
+ const panel = decodePanel(value);
2536
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2537
+ };
2361
2538
  const mountPanels = (panels) => {
2362
2539
  const nav = el("nav", HTMLElement);
2363
2540
  const views = el("views", HTMLElement);
@@ -2411,10 +2588,48 @@ function bootAdmin(config) {
2411
2588
  return decoded2 === void 0 ? [] : [decoded2];
2412
2589
  });
2413
2590
  mountPanels(panels);
2591
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2592
+ const decoded2 = decodeExtension(extension);
2593
+ return decoded2 === void 0 ? [] : [decoded2];
2594
+ });
2595
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2596
+ mountPanels(extensionPanels);
2597
+ for (const extension of extensions) {
2598
+ if (extension.kind !== "sql")
2599
+ continue;
2600
+ const nav = el("nav", HTMLElement);
2601
+ const views = el("views", HTMLElement);
2602
+ const button = document.createElement("button");
2603
+ button.type = "button";
2604
+ button.dataset.view = extension.id;
2605
+ button.textContent = extension.title;
2606
+ nav.append(button);
2607
+ const section = document.createElement("section");
2608
+ section.className = "view";
2609
+ section.id = `view-${extension.id}`;
2610
+ section.hidden = true;
2611
+ const title = document.createElement("h2");
2612
+ title.textContent = extension.title;
2613
+ const lede = document.createElement("p");
2614
+ lede.className = "lede";
2615
+ lede.textContent = extension.description;
2616
+ const body = document.createElement("div");
2617
+ body.className = "panel-body";
2618
+ section.append(title, lede, body);
2619
+ views.append(section);
2620
+ mountSqlExplorer(body, panelApi);
2621
+ }
2414
2622
  return refresh();
2415
2623
  }).catch(showError);
2416
2624
  }
2417
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2625
+ var clientPrelude = [
2626
+ isRecord2,
2627
+ mountAdminBrand,
2628
+ startAdminBrand,
2629
+ faultPresetList,
2630
+ mountSqlExplorer,
2631
+ bootAdmin
2632
+ ].map((fn) => fn.toString()).join("\n");
2418
2633
  var adminClientSource = (config) => {
2419
2634
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2420
2635
  const entry = bootAdmin.name;
@@ -2464,19 +2679,33 @@ var STANDARD_ADMIN_ROUTES = [
2464
2679
  "GET /ui/manifest"
2465
2680
  ];
2466
2681
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2682
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2683
+ var checkPanel = (panel, seen, label) => {
2684
+ if (!PANEL_ID.test(panel.id)) {
2685
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2686
+ }
2687
+ if (RESERVED_VIEWS.has(panel.id)) {
2688
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2689
+ }
2690
+ if (seen.has(panel.id))
2691
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2692
+ seen.add(panel.id);
2693
+ if (panel.title.trim() === "")
2694
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2695
+ };
2467
2696
  var assertAdminUi = (ui) => {
2468
- if (!ui?.panels)
2697
+ if (!ui)
2469
2698
  return;
2470
2699
  const seen = /* @__PURE__ */ new Set();
2471
- for (const panel of ui.panels) {
2472
- if (!PANEL_ID.test(panel.id)) {
2473
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2700
+ for (const panel of ui.panels ?? [])
2701
+ checkPanel(panel, seen, "admin panel");
2702
+ for (const extension of ui.extensions ?? []) {
2703
+ if (extension.kind === "panel") {
2704
+ checkPanel(extension, seen, "admin extension");
2705
+ continue;
2474
2706
  }
2475
- if (seen.has(panel.id))
2476
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2477
- seen.add(panel.id);
2478
- if (panel.title.trim() === "")
2479
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2707
+ const id = extension.id ?? "sql";
2708
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2480
2709
  }
2481
2710
  };
2482
2711
 
@@ -2710,6 +2939,12 @@ var renderAdminDocument = (service) => {
2710
2939
  border-radius: 999px; padding: 4px 8px;
2711
2940
  }
2712
2941
  .chip i { color: var(--faint); font-style: normal; }
2942
+ .sql-layout {
2943
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
2944
+ }
2945
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
2946
+ .sql-tables button { text-align: left; }
2947
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2713
2948
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2714
2949
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2715
2950
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -2773,7 +3008,7 @@ var renderAdminDocument = (service) => {
2773
3008
  padding: 8px;
2774
3009
  }
2775
3010
  nav.side button { white-space: nowrap; flex: none; }
2776
- .split { grid-template-columns: minmax(0, 1fr); }
3011
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
2777
3012
  main { padding: 14px; }
2778
3013
  table, thead, tbody, tr, th, td { display: block; }
2779
3014
  thead { display: none; }
@@ -2944,6 +3179,24 @@ var json2 = (body) => new Response(JSON.stringify(body), {
2944
3179
  status: 200,
2945
3180
  headers: { "content-type": "application/json; charset=utf-8" }
2946
3181
  });
3182
+ var describeExtension = (extension) => {
3183
+ if (extension.kind === "sql") {
3184
+ return {
3185
+ kind: "sql",
3186
+ id: extension.id ?? "sql",
3187
+ title: extension.title ?? "SQL",
3188
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3189
+ };
3190
+ }
3191
+ return {
3192
+ kind: "panel",
3193
+ id: extension.id,
3194
+ title: extension.title,
3195
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3196
+ html: extension.html,
3197
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3198
+ };
3199
+ };
2947
3200
  var adminUiRoutes = (service, ui) => {
2948
3201
  const shell = () => renderAdminDocument(service);
2949
3202
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -2958,7 +3211,8 @@ var adminUiRoutes = (service, ui) => {
2958
3211
  ...panel.description !== void 0 ? { description: panel.description } : {},
2959
3212
  html: panel.html,
2960
3213
  ...panel.script !== void 0 ? { script: panel.script } : {}
2961
- }))
3214
+ })),
3215
+ extensions: (ui?.extensions ?? []).map(describeExtension)
2962
3216
  })
2963
3217
  };
2964
3218
  };
@@ -3561,7 +3815,7 @@ var stateAdminRoutes = (routes) => {
3561
3815
  };
3562
3816
 
3563
3817
  // ../core/dist/version.js
3564
- var PACKAGE_VERSION = true ? "1.6.1" : UNRELEASED_VERSION;
3818
+ var PACKAGE_VERSION = true ? "1.7.1" : UNRELEASED_VERSION;
3565
3819
 
3566
3820
  // ../core/dist/signing.js
3567
3821
  var encoder = new TextEncoder();
@@ -5232,4 +5486,4 @@ export {
5232
5486
  scrubProperties,
5233
5487
  PostHogAPI
5234
5488
  };
5235
- //# sourceMappingURL=chunk-F5TQPEXZ.js.map
5489
+ //# sourceMappingURL=chunk-ZRB53DZ6.js.map