Changes
4 changed files (+43/-24)
-
-
@@ -3,10 +3,27 @@ //// SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com> // SPDX-License-Identifier: AGPL-3.0-only import { type IDBPDatabase } from "idb"; import { type DBSchema, type IDBPDatabase } from "idb"; export interface YamoriDB extends DBSchema { workspaces: { key: string; value: { id: string; displayName: string; capabilities: { deletionKey: Uint8Array; updateKey: Uint8Array; workerAddKey: Uint8Array; }; updatedAt: number; }; indexes: { updatedAt: number }; }; } export interface Context { db: IDBPDatabase; db: IDBPDatabase<YamoriDB>; } /**
-
-
-
@@ -99,6 +99,9 @@ let added: Workspace;try { const addedEntry = await db.get("workspaces", addedKey); if (!addedEntry) { throw "Failed to query an added entry"; } added = createMessage(WorkspaceSchema, { id: { value: addedEntry.id },
-
-
-
@@ -3,7 +3,10 @@ // SPDX-License-Identifier: AGPL-3.0-onlyimport { create, toBinary } from "@bufbuild/protobuf"; import { ListResponseSchema } from "@yamori/proto/yamori/workspace/v1/list_response_pb.js"; import { WorkspaceSchema } from "@yamori/proto/yamori/workspace/v1/workspace_pb.js"; import { WorkspaceSchema, type Workspace, } from "@yamori/proto/yamori/workspace/v1/workspace_pb.js"; import { type Context } from "../../../../types";
-
@@ -12,9 +15,19 @@ try {const tx = db.transaction("workspaces", "readonly"); const index = tx.store.index("updatedAt"); const workspaces: any[] = []; const workspaces: Workspace[] = []; for await (const cursor of index.iterate(null, "prev")) { workspaces.push({ ...cursor.value }); workspaces.push( create(WorkspaceSchema, { id: { value: cursor.value.id, }, displayName: cursor.value.displayName, deletionKey: { key: cursor.value.capabilities.deletionKey }, updateKey: { key: cursor.value.capabilities.updateKey }, workerAddKey: { key: cursor.value.capabilities.workerAddKey }, }), ); } await tx.done;
-
@@ -24,25 +37,7 @@ ListResponseSchema,create(ListResponseSchema, { result: { case: "ok", value: { workspaces: workspaces.map((workspace) => { return create(WorkspaceSchema, { id: { value: workspace.id, }, displayName: workspace.displayName, deletionKey: { key: workspace.capabilities.deletionKey, }, updateKey: { key: workspace.capabilities.updateKey, }, workerAddKey: { key: workspace.capabilities.workerAddKey, }, }); }), }, value: { workspaces }, }, }), );
-
-
-
@@ -152,6 +152,10 @@const updated = await store.get(key); await tx.done; if (!updated) { throw "Failed to query an updated entry"; } return respond({ result: { case: "ok",
-