mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-23 00:21:28 +00:00
chore: auto-fix lint & formatting [skip ci]
This commit is contained in:
parent
b313cdc2fe
commit
6c6c67fd73
2 changed files with 10 additions and 13 deletions
|
|
@ -120,19 +120,19 @@ export function d1ConfigStore(db: D1Database, kv: KVNamespace): ConfigStore {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const newGroupIds = new Set(groups.map((g) => g.id));
|
const newGroupIds = new Set(groups.map((g) => g.id));
|
||||||
const toDelete = existingGroupIds.filter((id) => !newGroupIds.has(id));
|
const toDelete = existingGroupIds.filter((id) => !newGroupIds.has(id));
|
||||||
|
|
||||||
const statements: D1PreparedStatement[] = [];
|
const statements: D1PreparedStatement[] = [];
|
||||||
|
|
||||||
// First, delete routes for groups that will be removed
|
// First, delete routes for groups that will be removed
|
||||||
for (const groupId of toDelete) {
|
for (const groupId of toDelete) {
|
||||||
statements.push(db.prepare("DELETE FROM d1_routes WHERE group_id = ?").bind(groupId));
|
statements.push(db.prepare("DELETE FROM d1_routes WHERE group_id = ?").bind(groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then delete the groups themselves
|
// Then delete the groups themselves
|
||||||
for (const groupId of toDelete) {
|
for (const groupId of toDelete) {
|
||||||
statements.push(db.prepare("DELETE FROM d1_groups WHERE id = ?").bind(groupId));
|
statements.push(db.prepare("DELETE FROM d1_groups WHERE id = ?").bind(groupId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, upsert all groups (INSERT OR REPLACE)
|
// Finally, upsert all groups (INSERT OR REPLACE)
|
||||||
for (const g of groups) {
|
for (const g of groups) {
|
||||||
statements.push(
|
statements.push(
|
||||||
|
|
@ -148,7 +148,7 @@ export function d1ConfigStore(db: D1Database, kv: KVNamespace): ConfigStore {
|
||||||
.bind(g.id, g.name, JSON.stringify(g), now, now),
|
.bind(g.id, g.name, JSON.stringify(g), now, now),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return statements;
|
return statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,20 +176,17 @@ describe("d1ConfigStore", () => {
|
||||||
const { db, routesTable, groupsTable } = createDB();
|
const { db, routesTable, groupsTable } = createDB();
|
||||||
const { kv } = createKV();
|
const { kv } = createKV();
|
||||||
const cfg: ConfigStore = d1ConfigStore(db, kv);
|
const cfg: ConfigStore = d1ConfigStore(db, kv);
|
||||||
|
|
||||||
// Setup initial state with groups and routes
|
// Setup initial state with groups and routes
|
||||||
groupsTable.push(group("g1"), group("g2"));
|
groupsTable.push(group("g1"), group("g2"));
|
||||||
routesTable.push(route("r1", "g1"), route("r2", "g2"));
|
routesTable.push(route("r1", "g1"), route("r2", "g2"));
|
||||||
|
|
||||||
// Simulate updating groups (e.g., changing a group's name)
|
// Simulate updating groups (e.g., changing a group's name)
|
||||||
const updatedGroups = [
|
const updatedGroups = [{ ...group("g1"), name: "Updated Group 1" }, group("g2")];
|
||||||
{ ...group("g1"), name: "Updated Group 1" },
|
|
||||||
group("g2"),
|
|
||||||
];
|
|
||||||
|
|
||||||
// This should not delete routes
|
// This should not delete routes
|
||||||
await cfg.saveGroups(updatedGroups);
|
await cfg.saveGroups(updatedGroups);
|
||||||
|
|
||||||
// Routes should still exist in the table
|
// Routes should still exist in the table
|
||||||
// Note: In the fake DB, batch() doesn't actually execute the statements,
|
// Note: In the fake DB, batch() doesn't actually execute the statements,
|
||||||
// so we can't verify the actual deletion behavior here.
|
// so we can't verify the actual deletion behavior here.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue