fix: slow-types
This commit is contained in:
@@ -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<TSchema>) => void) {
|
||||
onChange(cb: (event: ChangeEvent<TSchema>) => void): Subscription {
|
||||
return this.storage.event.subscribe("change", cb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ export class IndexedDBStorage<TSchema extends AnyDocument = AnyDocument> 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<this> {
|
||||
if (this.#db === undefined) {
|
||||
this.#db = await this.#promise;
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ export class MemoryDatabase<TOptions extends MemoryDatabaseOptions> {
|
||||
}
|
||||
}
|
||||
|
||||
get name() {
|
||||
get name(): TOptions["name"] {
|
||||
return this.options.name;
|
||||
}
|
||||
|
||||
get registrars() {
|
||||
get registrars(): TOptions["registrars"] {
|
||||
return this.options.registrars;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@ export class MemoryStorage<TSchema extends AnyDocument = AnyDocument> extends St
|
||||
this.index = new IndexManager(indexes);
|
||||
}
|
||||
|
||||
get documents() {
|
||||
get documents(): TSchema[] {
|
||||
return this.index.primary.documents;
|
||||
}
|
||||
|
||||
async resolve() {
|
||||
async resolve(): Promise<this> {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ const EMPTY_SET: ReadonlySet<PrimaryKey> = Object.freeze(new Set<PrimaryKey>());
|
||||
export class IndexManager<TSchema extends AnyDocument> {
|
||||
readonly primary: PrimaryIndex<TSchema>;
|
||||
|
||||
readonly unique = new Map<StringKeyOf<TSchema>, UniqueIndex>();
|
||||
readonly shared = new Map<StringKeyOf<TSchema>, SharedIndex>();
|
||||
readonly unique: Map<StringKeyOf<TSchema>, UniqueIndex> = new Map<StringKeyOf<TSchema>, UniqueIndex>();
|
||||
readonly shared: Map<StringKeyOf<TSchema>, SharedIndex> = new Map<StringKeyOf<TSchema>, SharedIndex>();
|
||||
|
||||
constructor(readonly specs: IndexSpec<TSchema>[]) {
|
||||
const primary = specs.find((spec) => spec.kind === "primary");
|
||||
@@ -40,7 +40,7 @@ export class IndexManager<TSchema extends AnyDocument> {
|
||||
*
|
||||
* @param document - Document to insert.
|
||||
*/
|
||||
insert(document: TSchema) {
|
||||
insert(document: TSchema): void {
|
||||
const pk = document[this.primary.key];
|
||||
|
||||
const insertedUniques: [StringKeyOf<TSchema>, any][] = [];
|
||||
@@ -225,12 +225,13 @@ export class IndexManager<TSchema extends AnyDocument> {
|
||||
*
|
||||
* @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<TSchema>, any][] = [];
|
||||
|
||||
@@ -7,11 +7,11 @@ export class PrimaryIndex<TSchema extends AnyDocument> {
|
||||
|
||||
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<TSchema extends AnyDocument> {
|
||||
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<TSchema extends AnyDocument> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { AnyDocument } from "./types.ts";
|
||||
type StorageEvent = "change" | "flush";
|
||||
|
||||
export abstract class Storage<TSchema extends AnyDocument = AnyDocument> {
|
||||
readonly event = new EventEmitter<StorageEvent>();
|
||||
readonly event: EventEmitter<StorageEvent> = new EventEmitter<StorageEvent>();
|
||||
|
||||
status: Status = "loading";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user