Appearance
Storage API
Signatures for @idlekitjs/storage and the contract it implements. Concepts: storage overview.
The contract
Defined in @idlekitjs/types (re-exported by @idlekitjs/core):
ts
interface SaveAdapter {
read(key: string): string | null | Promise<string | null>;
write(key: string, value: string): void | Promise<void>;
remove(key: string): void | Promise<void>;
}Sync and async implementations are interchangeable — the SaveManager awaits every call. read may throw/reject; the manager treats that as "no save".
MemoryAdapter
ts
import { MemoryAdapter } from "@idlekitjs/storage/memory";
const adapter = new MemoryAdapter();Synchronous, Map-backed, per-instance isolation. Nothing persists beyond the process. Details: Memory adapter.
LocalStorageAdapter
ts
import { LocalStorageAdapter } from "@idlekitjs/storage/local-storage";
const adapter = new LocalStorageAdapter();Synchronous, window.localStorage-backed — writes complete within pagehide handlers, which the autosave plugin relies on. Browser-only. Details: Local storage adapter.
Custom backends
Implement the three methods and pass your adapter to SaveManager — the custom adapter guide has sessionStorage and REST examples plus the caveats (async writes vs page close).