From 7bb356203f49be76f1b328cd38e0ca5ff9cc378b Mon Sep 17 00:00:00 2001 From: kodemon Date: Mon, 5 Jan 2026 23:23:53 +0100 Subject: [PATCH] fix: slow-types --- src/collection.ts | 4 ++-- src/databases/indexeddb/storage.ts | 4 ++-- src/databases/memory/database.ts | 4 ++-- src/databases/memory/storage.ts | 4 ++-- src/index/manager.ts | 11 ++++++----- src/index/primary.ts | 12 ++++++------ src/storage.ts | 2 +- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/collection.ts b/src/collection.ts index d397491..cad6cdb 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -166,11 +166,11 @@ export class Collection< |-------------------------------------------------------------------------------- */ - onFlush(cb: () => void) { + onFlush(cb: () => void): Subscription { return this.storage.event.subscribe("flush", cb); } - onChange(cb: (event: ChangeEvent) => void) { + onChange(cb: (event: ChangeEvent) => void): Subscription { return this.storage.event.subscribe("change", cb); } } diff --git a/src/databases/indexeddb/storage.ts b/src/databases/indexeddb/storage.ts index 90353aa..e8de61d 100644 --- a/src/databases/indexeddb/storage.ts +++ b/src/databases/indexeddb/storage.ts @@ -29,14 +29,14 @@ export class IndexedDBStorage extends this.#promise = promise; } - get db() { + get db(): IDBPDatabase { if (this.#db === undefined) { throw new Error("Database not initialized"); } return this.#db; } - async resolve() { + async resolve(): Promise { if (this.#db === undefined) { this.#db = await this.#promise; } diff --git a/src/databases/memory/database.ts b/src/databases/memory/database.ts index 2baee89..1ed08f6 100644 --- a/src/databases/memory/database.ts +++ b/src/databases/memory/database.ts @@ -20,11 +20,11 @@ export class MemoryDatabase { } } - get name() { + get name(): TOptions["name"] { return this.options.name; } - get registrars() { + get registrars(): TOptions["registrars"] { return this.options.registrars; } diff --git a/src/databases/memory/storage.ts b/src/databases/memory/storage.ts index ca25d43..2f03b7a 100644 --- a/src/databases/memory/storage.ts +++ b/src/databases/memory/storage.ts @@ -15,11 +15,11 @@ export class MemoryStorage extends St this.index = new IndexManager(indexes); } - get documents() { + get documents(): TSchema[] { return this.index.primary.documents; } - async resolve() { + async resolve(): Promise { return this; } diff --git a/src/index/manager.ts b/src/index/manager.ts index bf517e3..ee8ba00 100644 --- a/src/index/manager.ts +++ b/src/index/manager.ts @@ -10,8 +10,8 @@ const EMPTY_SET: ReadonlySet = Object.freeze(new Set()); export class IndexManager { readonly primary: PrimaryIndex; - readonly unique = new Map, UniqueIndex>(); - readonly shared = new Map, SharedIndex>(); + readonly unique: Map, UniqueIndex> = new Map, UniqueIndex>(); + readonly shared: Map, SharedIndex> = new Map, SharedIndex>(); constructor(readonly specs: IndexSpec[]) { const primary = specs.find((spec) => spec.kind === "primary"); @@ -40,7 +40,7 @@ export class IndexManager { * * @param document - Document to insert. */ - insert(document: TSchema) { + insert(document: TSchema): void { const pk = document[this.primary.key]; const insertedUniques: [StringKeyOf, any][] = []; @@ -225,12 +225,13 @@ export class IndexManager { * * @param document - Document to update against current index. */ - update(document: TSchema) { + update(document: TSchema): void { const pk = document[this.primary.key]; const current = this.primary.get(pk); if (current === undefined) { - return this.insert(document); + this.insert(document); + return; } const revertedUniques: [StringKeyOf, any][] = []; diff --git a/src/index/primary.ts b/src/index/primary.ts index fe45e8d..c91bcf9 100644 --- a/src/index/primary.ts +++ b/src/index/primary.ts @@ -7,11 +7,11 @@ export class PrimaryIndex { constructor(readonly key: string) {} - get documents() { + get documents(): TSchema[] { return Array.from(this.#index.values()); } - keys() { + keys(): string[] { return Array.from(this.#index.keys()); } @@ -19,7 +19,7 @@ export class PrimaryIndex { return this.#index.has(pk); } - insert(pk: PrimaryKey, document: TSchema) { + insert(pk: PrimaryKey, document: TSchema): void { if (this.#index.has(pk)) { throw new Error(`Duplicate primary key: ${pk}`); } @@ -30,15 +30,15 @@ export class PrimaryIndex { return this.#index.get(pk); } - replace(pk: PrimaryKey, document: TSchema) { + replace(pk: PrimaryKey, document: TSchema): void { this.#index.set(pk, document); } - delete(pk: PrimaryKey) { + delete(pk: PrimaryKey): void { this.#index.delete(pk); } - flush() { + flush(): void { this.#index.clear(); } } diff --git a/src/storage.ts b/src/storage.ts index 35bde81..1082e62 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -10,7 +10,7 @@ import type { AnyDocument } from "./types.ts"; type StorageEvent = "change" | "flush"; export abstract class Storage { - readonly event = new EventEmitter(); + readonly event: EventEmitter = new EventEmitter(); status: Status = "loading";