// Typed schema for Repo Durable Object storage // Provides a light wrapper to get strong typing on storage keys/values in tests and code. export type ObjKey = `obj:${string}`; export type Ref = { name: string; oid: string }; export type Head = { target: string; oid?: string; unborn?: boolean }; export type RepoLease = { token: string; createdAt: number; expiresAt: number; }; export type RepoStateSchema = { refs: Ref[]; head: Head; refsVersion: number; packsetVersion: number; nextPackSeq: number; receiveLease: RepoLease | undefined; compactLease: RepoLease | undefined; compactionWantedAt: number | undefined; lastAccessMs: number; } & Record; export type TypedStorage = { get(key: K): Promise; get(keys: K[]): Promise>; put(key: K, value: S[K]): Promise; delete(key: K): Promise; }; export function asTypedStorage(storage: DurableObjectStorage): TypedStorage { async function get(key: K): Promise; async function get(keys: K[]): Promise>; async function get(keyOrKeys: any): Promise { return storage.get(keyOrKeys as any); } const put = (key: K, value: S[K]) => storage.put(key as string, value); const del = (key: K) => storage.delete(key as string); return { get: get as any, put: put as any, delete: del as any }; } // Key helpers for template-literal key families export function objKey(oid: string): ObjKey { return `obj:${oid}` as ObjKey; }