@tucmc/hazel
Version:
Clubs Data Processing Framework
29 lines (28 loc) • 1.63 kB
TypeScript
import type { DataType } from '../data/DataType';
import { DMap } from '../data/DMap';
import type { ChangeList, DataChanges } from '../data/DMapUtil';
import { LiveDMap } from '../data/LiveDMap';
import { ReferableMapEntity } from '../data/ReferableEntity';
import { Debugger } from '../debugger/Debugger';
export type CollectionMutator<T> = (d: T) => DataType;
export declare abstract class Collection<T extends DataType, M = any, C = any> {
protected readonly name: string;
protected debug: Debugger;
protected abstract collectionMutator: CollectionMutator<M>;
private rootPath;
private readonly resourcePath;
protected readonly dbInstance: C;
constructor(name: string);
protected abstract initInstance(collectionName: string): C;
protected abstract retrieveCollection(): Promise<M>;
protected abstract handleChanges(changes: DataChanges[]): Promise<DataChanges[]>;
protected abstract verifyChanges(changes: DataChanges[]): Promise<boolean>;
setDefaultMutator(mutator: CollectionMutator<M>): this;
pushChanges(changes: ChangeList, strict?: boolean): Promise<boolean>;
private makeReferableEntities;
fetch(mutator?: CollectionMutator<M>): Promise<LiveDMap<string, ReferableMapEntity<T[keyof T]>>>;
readFromCache(autoFetch?: boolean): Promise<DMap<string, ReferableMapEntity<T[keyof T]>> | null>;
readFromCacheNoRef(autoFetch?: boolean): Promise<DMap<string, T[keyof T]> | null>;
fetchNoRef(mutator?: CollectionMutator<M>): Promise<LiveDMap<string, T[keyof T]>>;
protected clearEntityReference<G extends DataType>(data: G): Record<string, G[keyof G]>;
}