refactor: simplify and add memory indexing

This commit is contained in:
2026-01-05 04:42:46 +01:00
parent 74d45cbe92
commit ed15a0eb27
37 changed files with 854 additions and 1328 deletions

24
src/index/primary.ts Normal file
View File

@@ -0,0 +1,24 @@
import type { AnyDocument } from "../types.ts";
export type PrimaryKey = string;
export class PrimaryIndex<TSchema extends AnyDocument> {
readonly #index = new Map<PrimaryKey, TSchema>();
constructor(readonly key: string) {}
insert(pk: PrimaryKey, document: TSchema) {
if (this.#index.has(pk)) {
throw new Error(`Duplicate primary key: ${pk}`);
}
this.#index.set(pk, document);
}
get(pk: PrimaryKey): TSchema | undefined {
return this.#index.get(pk);
}
delete(pk: PrimaryKey) {
this.#index.delete(pk);
}
}