Release query Tools v0.1.0

This commit is contained in:
2026-09-01 14:10:51 +02:00
commit 2730ce08b2
59 changed files with 8775 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import { parseData } from "../../src/core/data";
import { runQuery } from "../../src/core/query";
describe("query engine", () => {
const root = parseData(
'[{"team":"a","n":2},{"team":"a","n":4},{"team":"b","n":9}]',
"json",
).root;
it("filters groups aggregates sorts and limits", () => {
expect(
runQuery(
root,
"SELECT team, COUNT(*) AS count, AVG(n) AS mean WHERE n >= 2 GROUP BY team ORDER BY mean DESC LIMIT 2",
"sql",
).rows,
).toEqual([
{ team: "b", count: 1, mean: 9 },
{ team: "a", count: 2, mean: 3 },
]);
});
it("supports bounded path navigation and filtering", () => {
expect(runQuery(root, "$[?(@.n >= 4)].team", "path").value).toEqual([
"a",
"b",
]);
});
it("rejects unsupported syntax rather than evaluating it", () => {
expect(() => runQuery(root, "SELECT eval(n)", "sql")).toThrow(
/Invalid SELECT/iu,
);
expect(() => runQuery(root, "$..team", "path")).toThrow(
/Unsupported path/iu,
);
});
});