feat(redis): add custom key groups
This commit is contained in:
1 parent
a535cf8f51
commit
1cbb5abf3b
53 files changed
+1951
-13
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { beforeEach, expect, it, vi } from "vitest";
|
||||
import { defaultRedisKeyGrouping } from "@/lib/redis/redisKeyGrouping";
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
setActivePinia(createPinia());
|
||||
vi.stubGlobal("localStorage", { getItem: () => null, setItem: () => {}, removeItem: () => {} });
|
||||
});
|
||||
|
||||
it("persists presentation without reconnecting and keeps old config after failure", async () => {
|
||||
const saveConnections = vi.fn().mockResolvedValue(undefined);
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({ saveConnections }));
|
||||
const { useConnectionStore } = await import("../connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.addEphemeralConnection({ id: "group-test", name: "Redis", db_type: "redis", host: "localhost", port: 6379, username: "", password: "" });
|
||||
const config = { ...defaultRedisKeyGrouping(), enabled: true };
|
||||
await store.updateRedisKeyGrouping("group-test", config);
|
||||
expect(saveConnections).toHaveBeenCalledWith([expect.objectContaining({ redis_key_grouping: config })]);
|
||||
expect(store.connectedIds.has("group-test")).toBe(true);
|
||||
saveConnections.mockRejectedValueOnce(new Error("disk full"));
|
||||
await expect(store.updateRedisKeyGrouping("group-test", { ...config, enabled: false })).rejects.toThrow("disk full");
|
||||
expect(store.getConfig("group-test")?.redis_key_grouping?.enabled).toBe(true);
|
||||
});
|
||||
@@ -3433,6 +3433,18 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function updateRedisKeyGrouping(connectionId: string, grouping: import("@/lib/redis/redisKeyGrouping").RedisKeyGrouping) {
|
||||
const { validateRedisKeyGrouping } = await import("@/lib/redis/redisKeyGrouping");
|
||||
const validated = validateRedisKeyGrouping(grouping);
|
||||
const index = connections.value.findIndex((connection) => connection.id === connectionId);
|
||||
if (index < 0) throw new Error("Connection not found");
|
||||
const next = [...connections.value];
|
||||
next[index] = { ...next[index]!, redis_key_grouping: validated };
|
||||
await persistConnections(next);
|
||||
// Presentation-only preferences must not invalidate a live connection.
|
||||
connections.value = next;
|
||||
}
|
||||
|
||||
async function renameConnection(connectionId: string, name: string): Promise<boolean> {
|
||||
const trimmed = name.trim();
|
||||
if (!trimmed) return false;
|
||||
@@ -8970,6 +8982,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
pasteConnectionClipboard,
|
||||
addEphemeralConnection,
|
||||
updateConnection,
|
||||
updateRedisKeyGrouping,
|
||||
renameConnection,
|
||||
applyGlobalTimeouts,
|
||||
updateConnectionDatabaseInfo,
|
||||
|
||||
Reference in new issue
Block a user