mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat(filters): JSONPath field filters, operators, AST groups, fragments, and test-match
Add a field filter type reading any payload value by JSONPath with array expansion, 12 comparison operators (eq/ne/contains/startsWith/endsWith/regex/gt/gte/lt/lte/in/exists), a visual AST builder (all/any/not) in the route editor, chip-based multi-value input, a stateless POST /admin/api/test-match dry-run, and named filter fragments stored in D1 (d1_fragments, migration 0010) inlined into route ASTs on insert.
This commit is contained in:
parent
c955db03c3
commit
c090281cb2
30 changed files with 1793 additions and 422 deletions
55
server/lib/fragments.ts
Normal file
55
server/lib/fragments.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import type { FilterNode } from "./types";
|
||||
import { log } from "./lib/log";
|
||||
|
||||
export interface NamedFragment {
|
||||
id: string;
|
||||
groupId?: string;
|
||||
name: string;
|
||||
node: FilterNode;
|
||||
}
|
||||
|
||||
interface D1FragmentRow {
|
||||
id: string;
|
||||
group_id: string;
|
||||
name: string;
|
||||
node: string;
|
||||
}
|
||||
|
||||
export async function loadFragments(db: D1Database): Promise<NamedFragment[]> {
|
||||
try {
|
||||
const stmt = db.prepare(
|
||||
"SELECT id, group_id, name, node FROM d1_fragments ORDER BY id",
|
||||
);
|
||||
if (typeof stmt.all !== "function") return [];
|
||||
const { results } = await stmt.all<D1FragmentRow>();
|
||||
if (!results || results.length === 0) return [];
|
||||
return results.map((r) => ({
|
||||
id: r.id,
|
||||
groupId: r.group_id || undefined,
|
||||
name: r.name,
|
||||
node: JSON.parse(r.node) as FilterNode,
|
||||
}));
|
||||
} catch (err) {
|
||||
log.warn({ err }, "Failed to load fragments from D1");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveFragments(
|
||||
db: D1Database,
|
||||
fragments: NamedFragment[],
|
||||
): Promise<void> {
|
||||
const now = Date.now();
|
||||
const statements: D1PreparedStatement[] = [
|
||||
db.prepare("DELETE FROM d1_fragments"),
|
||||
...fragments.map((f) =>
|
||||
db
|
||||
.prepare(
|
||||
`INSERT INTO d1_fragments (id, group_id, name, node, version, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, 1, ?, ?)`,
|
||||
)
|
||||
.bind(f.id, f.groupId ?? "", f.name, JSON.stringify(f.node), now, now),
|
||||
),
|
||||
];
|
||||
await db.batch(statements);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue