style(storage,workspace): satisfy the repository lint gate

eslint --fix formatting sweep plus the manual residue: sync method
bodies drop async behind Promise-returning signatures (the sqlite unit
routes primitives through a settle() guard preserving the never-throws-
synchronously contract), catch callbacks type their reason as unknown,
loadAll's global slot is plain unknown (null semantics stay in JSDoc),
a non-null assertion becomes a narrowing, and unsafe any assignments in
tests gain explicit types. One justified eslint-disable for
prefer-promise-reject-errors follows the core/session precedent —
wrapping would discard the original StorageError code.
This commit is contained in:
imccyu
2026-07-24 23:41:39 +08:00
parent 25a4a2063b
commit 2e986ee1e3
14 changed files with 113 additions and 78 deletions
+2 -2
View File
@@ -8,10 +8,10 @@
import { StorageError } from '@deepseek-ai/dsh-storage'
import type { KvUnitDescriptor } from '@deepseek-ai/dsh-storage'
/** In-memory authoritative state of one unit; the file is its projection. */
/** In-memory authoritative state of one unit; the file is its projection. `global` is `null` until first written. */
export interface UnitState {
version: number
global: unknown | null
global: unknown
tables: Map<string, Map<string, unknown>>
}
+9 -9
View File
@@ -36,10 +36,10 @@ export async function openJsonUnit(
const state: UnitState =
text === undefined
? {
version: descriptor.version,
global: null,
tables: new Map(descriptor.tables.map((table) => [table, new Map()])),
}
version: descriptor.version,
global: null,
tables: new Map(descriptor.tables.map(table => [table, new Map<string, unknown>()])),
}
: parse(text, descriptor)
return new JsonKvUnit(descriptor, path, state, onClose)
}
@@ -56,13 +56,13 @@ class JsonKvUnit implements KvUnit {
private readonly onClose: () => void,
) {}
async loadAll(): Promise<{ tables: Record<string, Record<string, unknown>>; global: unknown | null }> {
loadAll(): Promise<{ tables: Record<string, Record<string, unknown>>; global: unknown }> {
this.assertOpen()
const tables: Record<string, Record<string, unknown>> = {}
for (const [table, records] of this.state.tables) {
tables[table] = Object.fromEntries(records)
}
return { tables, global: this.state.global }
return Promise.resolve({ tables, global: this.state.global })
}
async putRecord(table: string, key: string, value: unknown): Promise<void> {
@@ -73,7 +73,7 @@ class JsonKvUnit implements KvUnit {
records.set(key, value)
// Roll back on a failed publish: memory is authoritative, so a rejected
// write must not survive in memory (or ride along with the next publish).
await this.publish().catch(async (error) => {
await this.publish().catch((error: unknown) => {
if (hadKey) records.set(key, previous)
else records.delete(key)
throw error
@@ -86,7 +86,7 @@ class JsonKvUnit implements KvUnit {
if (!records.has(key)) return
const previous = records.get(key)
records.delete(key)
await this.publish().catch(async (error) => {
await this.publish().catch((error: unknown) => {
records.set(key, previous)
throw error
})
@@ -99,7 +99,7 @@ class JsonKvUnit implements KvUnit {
}
const previous = this.state.global
this.state.global = value
await this.publish().catch(async (error) => {
await this.publish().catch((error: unknown) => {
this.state.global = previous
throw error
})