@crvouga/mockingbird-service-pharmetika 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 +10 -0
- package/dist/{chunk-UM5N2SBR.js → chunk-JVKOLQ3A.js} +2 -2
- package/dist/{chunk-N2MDJR53.js → chunk-ZAUHRESG.js} +268 -14
- package/dist/chunk-ZAUHRESG.js.map +7 -0
- package/dist/cli.js +2 -2
- package/dist/index.js +1 -1
- package/dist/server.js +2 -2
- package/package.json +2 -2
- package/dist/chunk-N2MDJR53.js.map +0 -7
- /package/dist/{chunk-UM5N2SBR.js.map → chunk-JVKOLQ3A.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog — @crvouga/mockingbird-service-pharmetika
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createRuntime
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZAUHRESG.js";
|
|
4
4
|
|
|
5
5
|
// ../../adapters/node/dist/cli.js
|
|
6
6
|
import { readFile } from "node:fs/promises";
|
|
@@ -396,4 +396,4 @@ export {
|
|
|
396
396
|
createServer2 as createServer,
|
|
397
397
|
serveTarget
|
|
398
398
|
};
|
|
399
|
-
//# sourceMappingURL=chunk-
|
|
399
|
+
//# sourceMappingURL=chunk-JVKOLQ3A.js.map
|
|
@@ -1916,6 +1916,167 @@ function faultPresetList(value) {
|
|
|
1916
1916
|
})
|
|
1917
1917
|
};
|
|
1918
1918
|
}
|
|
1919
|
+
function mountSqlExplorer(root, api) {
|
|
1920
|
+
const cell = (value) => {
|
|
1921
|
+
if (value === null || value === void 0)
|
|
1922
|
+
return "";
|
|
1923
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
1924
|
+
return String(value);
|
|
1925
|
+
}
|
|
1926
|
+
return JSON.stringify(value) ?? "";
|
|
1927
|
+
};
|
|
1928
|
+
root.replaceChildren();
|
|
1929
|
+
const layout = document.createElement("div");
|
|
1930
|
+
layout.className = "sql-layout";
|
|
1931
|
+
const tables = document.createElement("div");
|
|
1932
|
+
tables.className = "sql-tables";
|
|
1933
|
+
const stack = document.createElement("div");
|
|
1934
|
+
stack.className = "stack";
|
|
1935
|
+
const banner = document.createElement("p");
|
|
1936
|
+
banner.className = "banner";
|
|
1937
|
+
const grid = document.createElement("div");
|
|
1938
|
+
const input = document.createElement("textarea");
|
|
1939
|
+
input.className = "sql-input";
|
|
1940
|
+
input.spellcheck = false;
|
|
1941
|
+
input.placeholder = "SELECT * FROM ...";
|
|
1942
|
+
const actions = document.createElement("div");
|
|
1943
|
+
actions.className = "row-actions";
|
|
1944
|
+
const run = document.createElement("button");
|
|
1945
|
+
run.type = "button";
|
|
1946
|
+
run.textContent = "Run";
|
|
1947
|
+
actions.append(run);
|
|
1948
|
+
const result = document.createElement("pre");
|
|
1949
|
+
stack.append(banner, grid, input, actions, result);
|
|
1950
|
+
layout.append(tables, stack);
|
|
1951
|
+
root.append(layout);
|
|
1952
|
+
const showError = (error2) => {
|
|
1953
|
+
banner.textContent = error2 instanceof Error ? error2.message : String(error2);
|
|
1954
|
+
banner.classList.add("show");
|
|
1955
|
+
};
|
|
1956
|
+
const clearError = () => {
|
|
1957
|
+
banner.textContent = "";
|
|
1958
|
+
banner.classList.remove("show");
|
|
1959
|
+
};
|
|
1960
|
+
const renderGrid = (columns, rows) => {
|
|
1961
|
+
grid.replaceChildren();
|
|
1962
|
+
if (columns.length === 0) {
|
|
1963
|
+
const empty = document.createElement("p");
|
|
1964
|
+
empty.className = "empty";
|
|
1965
|
+
empty.textContent = "No rows.";
|
|
1966
|
+
grid.append(empty);
|
|
1967
|
+
return;
|
|
1968
|
+
}
|
|
1969
|
+
const table = document.createElement("table");
|
|
1970
|
+
const head = document.createElement("thead");
|
|
1971
|
+
const headRow = document.createElement("tr");
|
|
1972
|
+
for (const column of columns) {
|
|
1973
|
+
const th = document.createElement("th");
|
|
1974
|
+
th.textContent = column;
|
|
1975
|
+
headRow.append(th);
|
|
1976
|
+
}
|
|
1977
|
+
head.append(headRow);
|
|
1978
|
+
const body = document.createElement("tbody");
|
|
1979
|
+
for (const row of rows) {
|
|
1980
|
+
const tr = document.createElement("tr");
|
|
1981
|
+
for (const column of columns) {
|
|
1982
|
+
const td = document.createElement("td");
|
|
1983
|
+
td.dataset.label = column;
|
|
1984
|
+
td.textContent = cell(row[column]);
|
|
1985
|
+
tr.append(td);
|
|
1986
|
+
}
|
|
1987
|
+
body.append(tr);
|
|
1988
|
+
}
|
|
1989
|
+
table.append(head, body);
|
|
1990
|
+
grid.append(table);
|
|
1991
|
+
};
|
|
1992
|
+
const rowsOf = (value) => {
|
|
1993
|
+
if (!isRecord2(value) || !Array.isArray(value.rows))
|
|
1994
|
+
return [];
|
|
1995
|
+
return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
|
|
1996
|
+
};
|
|
1997
|
+
const columnsOf = (value, rows) => {
|
|
1998
|
+
if (isRecord2(value) && Array.isArray(value.columns)) {
|
|
1999
|
+
const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
|
|
2000
|
+
if (named.length > 0)
|
|
2001
|
+
return named;
|
|
2002
|
+
}
|
|
2003
|
+
const first = rows[0];
|
|
2004
|
+
return first === void 0 ? [] : Object.keys(first);
|
|
2005
|
+
};
|
|
2006
|
+
let selected = "";
|
|
2007
|
+
const loadPage = async (schema, name) => {
|
|
2008
|
+
selected = `${schema}.${name}`;
|
|
2009
|
+
const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
|
|
2010
|
+
const rows = rowsOf(page);
|
|
2011
|
+
renderGrid(columnsOf(page, rows), rows);
|
|
2012
|
+
const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
|
|
2013
|
+
result.textContent = `${selected} \xB7 ${total} rows`;
|
|
2014
|
+
for (const button of tables.querySelectorAll("button")) {
|
|
2015
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2016
|
+
continue;
|
|
2017
|
+
button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
2020
|
+
const loadTables = async () => {
|
|
2021
|
+
const payload = await api.get("/sql/tables");
|
|
2022
|
+
const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
|
|
2023
|
+
tables.replaceChildren();
|
|
2024
|
+
if (listed.length === 0) {
|
|
2025
|
+
const empty = document.createElement("p");
|
|
2026
|
+
empty.className = "empty";
|
|
2027
|
+
empty.textContent = "No tables.";
|
|
2028
|
+
tables.append(empty);
|
|
2029
|
+
return;
|
|
2030
|
+
}
|
|
2031
|
+
for (const item of listed) {
|
|
2032
|
+
if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
|
|
2033
|
+
continue;
|
|
2034
|
+
const button = document.createElement("button");
|
|
2035
|
+
button.type = "button";
|
|
2036
|
+
button.dataset.schema = item.schema;
|
|
2037
|
+
button.dataset.table = item.name;
|
|
2038
|
+
button.textContent = `${item.schema}.${item.name}`;
|
|
2039
|
+
tables.append(button);
|
|
2040
|
+
}
|
|
2041
|
+
};
|
|
2042
|
+
tables.addEventListener("click", (event) => {
|
|
2043
|
+
const target = event.target;
|
|
2044
|
+
if (!(target instanceof Element))
|
|
2045
|
+
return;
|
|
2046
|
+
const button = target.closest("button");
|
|
2047
|
+
if (!(button instanceof HTMLButtonElement))
|
|
2048
|
+
return;
|
|
2049
|
+
const schema = button.dataset.schema;
|
|
2050
|
+
const name = button.dataset.table;
|
|
2051
|
+
if (schema === void 0 || name === void 0)
|
|
2052
|
+
return;
|
|
2053
|
+
clearError();
|
|
2054
|
+
loadPage(schema, name).catch(showError);
|
|
2055
|
+
});
|
|
2056
|
+
run.addEventListener("click", () => {
|
|
2057
|
+
const sql = input.value.trim();
|
|
2058
|
+
if (sql === "") {
|
|
2059
|
+
showError(new Error("Enter a statement"));
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
clearError();
|
|
2063
|
+
api.send("POST", "/sql/query", { sql }).then((payload) => {
|
|
2064
|
+
const rows = rowsOf(payload);
|
|
2065
|
+
renderGrid(columnsOf(payload, rows), rows);
|
|
2066
|
+
const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
|
|
2067
|
+
const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
|
|
2068
|
+
result.textContent = `${count} rows${truncated}`;
|
|
2069
|
+
}).catch(showError);
|
|
2070
|
+
});
|
|
2071
|
+
const namespace = document.getElementById("namespace");
|
|
2072
|
+
if (namespace) {
|
|
2073
|
+
namespace.addEventListener("change", () => {
|
|
2074
|
+
clearError();
|
|
2075
|
+
loadTables().catch(showError);
|
|
2076
|
+
});
|
|
2077
|
+
}
|
|
2078
|
+
loadTables().catch(showError);
|
|
2079
|
+
}
|
|
1919
2080
|
function bootAdmin(config) {
|
|
1920
2081
|
const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
|
|
1921
2082
|
const sources = ["declared", "inferred", "mixed"];
|
|
@@ -2592,6 +2753,22 @@ function bootAdmin(config) {
|
|
|
2592
2753
|
panel.script = value.script;
|
|
2593
2754
|
return panel;
|
|
2594
2755
|
};
|
|
2756
|
+
const decodeExtension = (value) => {
|
|
2757
|
+
if (!isRecord2(value))
|
|
2758
|
+
return void 0;
|
|
2759
|
+
if (value.kind === "sql") {
|
|
2760
|
+
return {
|
|
2761
|
+
kind: "sql",
|
|
2762
|
+
id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
|
|
2763
|
+
title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
|
|
2764
|
+
description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
if (value.kind !== "panel")
|
|
2768
|
+
return void 0;
|
|
2769
|
+
const panel = decodePanel(value);
|
|
2770
|
+
return panel === void 0 ? void 0 : { kind: "panel", ...panel };
|
|
2771
|
+
};
|
|
2595
2772
|
const mountPanels = (panels) => {
|
|
2596
2773
|
const nav = el("nav", HTMLElement);
|
|
2597
2774
|
const views = el("views", HTMLElement);
|
|
@@ -2645,10 +2822,48 @@ function bootAdmin(config) {
|
|
|
2645
2822
|
return decoded === void 0 ? [] : [decoded];
|
|
2646
2823
|
});
|
|
2647
2824
|
mountPanels(panels);
|
|
2825
|
+
const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
|
|
2826
|
+
const decoded = decodeExtension(extension);
|
|
2827
|
+
return decoded === void 0 ? [] : [decoded];
|
|
2828
|
+
});
|
|
2829
|
+
const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
|
|
2830
|
+
mountPanels(extensionPanels);
|
|
2831
|
+
for (const extension of extensions) {
|
|
2832
|
+
if (extension.kind !== "sql")
|
|
2833
|
+
continue;
|
|
2834
|
+
const nav = el("nav", HTMLElement);
|
|
2835
|
+
const views = el("views", HTMLElement);
|
|
2836
|
+
const button = document.createElement("button");
|
|
2837
|
+
button.type = "button";
|
|
2838
|
+
button.dataset.view = extension.id;
|
|
2839
|
+
button.textContent = extension.title;
|
|
2840
|
+
nav.append(button);
|
|
2841
|
+
const section = document.createElement("section");
|
|
2842
|
+
section.className = "view";
|
|
2843
|
+
section.id = `view-${extension.id}`;
|
|
2844
|
+
section.hidden = true;
|
|
2845
|
+
const title = document.createElement("h2");
|
|
2846
|
+
title.textContent = extension.title;
|
|
2847
|
+
const lede = document.createElement("p");
|
|
2848
|
+
lede.className = "lede";
|
|
2849
|
+
lede.textContent = extension.description;
|
|
2850
|
+
const body = document.createElement("div");
|
|
2851
|
+
body.className = "panel-body";
|
|
2852
|
+
section.append(title, lede, body);
|
|
2853
|
+
views.append(section);
|
|
2854
|
+
mountSqlExplorer(body, panelApi);
|
|
2855
|
+
}
|
|
2648
2856
|
return refresh();
|
|
2649
2857
|
}).catch(showError);
|
|
2650
2858
|
}
|
|
2651
|
-
var clientPrelude = [
|
|
2859
|
+
var clientPrelude = [
|
|
2860
|
+
isRecord2,
|
|
2861
|
+
mountAdminBrand,
|
|
2862
|
+
startAdminBrand,
|
|
2863
|
+
faultPresetList,
|
|
2864
|
+
mountSqlExplorer,
|
|
2865
|
+
bootAdmin
|
|
2866
|
+
].map((fn) => fn.toString()).join("\n");
|
|
2652
2867
|
var adminClientSource = (config) => {
|
|
2653
2868
|
const payload = JSON.stringify(config).replace(/</g, "\\u003c");
|
|
2654
2869
|
const entry = bootAdmin.name;
|
|
@@ -2698,19 +2913,33 @@ var STANDARD_ADMIN_ROUTES = [
|
|
|
2698
2913
|
"GET /ui/manifest"
|
|
2699
2914
|
];
|
|
2700
2915
|
var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
2916
|
+
var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
|
|
2917
|
+
var checkPanel = (panel, seen, label) => {
|
|
2918
|
+
if (!PANEL_ID.test(panel.id)) {
|
|
2919
|
+
throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
|
|
2920
|
+
}
|
|
2921
|
+
if (RESERVED_VIEWS.has(panel.id)) {
|
|
2922
|
+
throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
|
|
2923
|
+
}
|
|
2924
|
+
if (seen.has(panel.id))
|
|
2925
|
+
throw new RangeError(`duplicate admin view id ${panel.id}`);
|
|
2926
|
+
seen.add(panel.id);
|
|
2927
|
+
if (panel.title.trim() === "")
|
|
2928
|
+
throw new RangeError(`${label} ${panel.id} needs a title`);
|
|
2929
|
+
};
|
|
2701
2930
|
var assertAdminUi = (ui) => {
|
|
2702
|
-
if (!ui
|
|
2931
|
+
if (!ui)
|
|
2703
2932
|
return;
|
|
2704
2933
|
const seen = /* @__PURE__ */ new Set();
|
|
2705
|
-
for (const panel of ui.panels)
|
|
2706
|
-
|
|
2707
|
-
|
|
2934
|
+
for (const panel of ui.panels ?? [])
|
|
2935
|
+
checkPanel(panel, seen, "admin panel");
|
|
2936
|
+
for (const extension of ui.extensions ?? []) {
|
|
2937
|
+
if (extension.kind === "panel") {
|
|
2938
|
+
checkPanel(extension, seen, "admin extension");
|
|
2939
|
+
continue;
|
|
2708
2940
|
}
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
seen.add(panel.id);
|
|
2712
|
-
if (panel.title.trim() === "")
|
|
2713
|
-
throw new RangeError(`admin panel ${panel.id} needs a title`);
|
|
2941
|
+
const id = extension.id ?? "sql";
|
|
2942
|
+
checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
|
|
2714
2943
|
}
|
|
2715
2944
|
};
|
|
2716
2945
|
|
|
@@ -2944,6 +3173,12 @@ var renderAdminDocument = (service) => {
|
|
|
2944
3173
|
border-radius: 999px; padding: 4px 8px;
|
|
2945
3174
|
}
|
|
2946
3175
|
.chip i { color: var(--faint); font-style: normal; }
|
|
3176
|
+
.sql-layout {
|
|
3177
|
+
display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
|
|
3178
|
+
}
|
|
3179
|
+
.sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
|
|
3180
|
+
.sql-tables button { text-align: left; }
|
|
3181
|
+
.sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
|
|
2947
3182
|
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
|
2948
3183
|
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
2949
3184
|
th { color: var(--faint); font-weight: 600; font-size: 12px; }
|
|
@@ -3007,7 +3242,7 @@ var renderAdminDocument = (service) => {
|
|
|
3007
3242
|
padding: 8px;
|
|
3008
3243
|
}
|
|
3009
3244
|
nav.side button { white-space: nowrap; flex: none; }
|
|
3010
|
-
.split { grid-template-columns: minmax(0, 1fr); }
|
|
3245
|
+
.split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
|
|
3011
3246
|
main { padding: 14px; }
|
|
3012
3247
|
table, thead, tbody, tr, th, td { display: block; }
|
|
3013
3248
|
thead { display: none; }
|
|
@@ -3178,6 +3413,24 @@ var json2 = (body) => new Response(JSON.stringify(body), {
|
|
|
3178
3413
|
status: 200,
|
|
3179
3414
|
headers: { "content-type": "application/json; charset=utf-8" }
|
|
3180
3415
|
});
|
|
3416
|
+
var describeExtension = (extension) => {
|
|
3417
|
+
if (extension.kind === "sql") {
|
|
3418
|
+
return {
|
|
3419
|
+
kind: "sql",
|
|
3420
|
+
id: extension.id ?? "sql",
|
|
3421
|
+
title: extension.title ?? "SQL",
|
|
3422
|
+
...extension.description !== void 0 ? { description: extension.description } : {}
|
|
3423
|
+
};
|
|
3424
|
+
}
|
|
3425
|
+
return {
|
|
3426
|
+
kind: "panel",
|
|
3427
|
+
id: extension.id,
|
|
3428
|
+
title: extension.title,
|
|
3429
|
+
...extension.description !== void 0 ? { description: extension.description } : {},
|
|
3430
|
+
html: extension.html,
|
|
3431
|
+
...extension.script !== void 0 ? { script: extension.script } : {}
|
|
3432
|
+
};
|
|
3433
|
+
};
|
|
3181
3434
|
var adminUiRoutes = (service, ui) => {
|
|
3182
3435
|
const shell = () => renderAdminDocument(service);
|
|
3183
3436
|
const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
|
|
@@ -3192,7 +3445,8 @@ var adminUiRoutes = (service, ui) => {
|
|
|
3192
3445
|
...panel.description !== void 0 ? { description: panel.description } : {},
|
|
3193
3446
|
html: panel.html,
|
|
3194
3447
|
...panel.script !== void 0 ? { script: panel.script } : {}
|
|
3195
|
-
}))
|
|
3448
|
+
})),
|
|
3449
|
+
extensions: (ui?.extensions ?? []).map(describeExtension)
|
|
3196
3450
|
})
|
|
3197
3451
|
};
|
|
3198
3452
|
};
|
|
@@ -3869,7 +4123,7 @@ var stateAdminRoutes = (routes) => {
|
|
|
3869
4123
|
};
|
|
3870
4124
|
|
|
3871
4125
|
// ../core/dist/version.js
|
|
3872
|
-
var PACKAGE_VERSION = true ? "1.
|
|
4126
|
+
var PACKAGE_VERSION = true ? "1.7.0" : UNRELEASED_VERSION;
|
|
3873
4127
|
|
|
3874
4128
|
// ../core/dist/signing.js
|
|
3875
4129
|
var encoder = new TextEncoder();
|
|
@@ -5828,4 +6082,4 @@ export {
|
|
|
5828
6082
|
tokenCredential,
|
|
5829
6083
|
PharmetikaAPI
|
|
5830
6084
|
};
|
|
5831
|
-
//# sourceMappingURL=chunk-
|
|
6085
|
+
//# sourceMappingURL=chunk-ZAUHRESG.js.map
|