wowok
Version:
Wowok Blockchain TypeScript API
44 lines (43 loc) • 1.42 kB
TypeScript
export declare class DataLoader<K, V, C = K> {
constructor(batchLoadFn: DataLoader.BatchLoadFn<K, V>, options?: DataLoader.Options<K, V, C>);
_batchLoadFn: DataLoader.BatchLoadFn<K, V>;
_maxBatchSize: number;
_batchScheduleFn: (cb: () => void) => void;
_cacheKeyFn: (key: K) => C;
_cacheMap: DataLoader.CacheMap<C, Promise<V>> | null;
_batch: Batch<K, V> | null;
load(key: K): Promise<V>;
loadMany(keys: ReadonlyArray<K>): Promise<Array<V | Error>>;
clear(key: K): this;
clearAll(): this;
prime(key: K, value: V | Promise<V> | Error): this;
name: string | null;
}
type Batch<K, V> = {
hasDispatched: boolean;
keys: Array<K>;
callbacks: Array<{
resolve: (value: V) => void;
reject: (error: Error) => void;
}>;
cacheHits?: Array<() => void>;
};
export declare namespace DataLoader {
type CacheMap<K, V> = {
get(key: K): V | void;
set(key: K, value: V): any;
delete(key: K): any;
clear(): any;
};
type BatchLoadFn<K, V> = (keys: ReadonlyArray<K>) => PromiseLike<ArrayLike<V | Error>>;
type Options<K, V, C = K> = {
batch?: boolean;
maxBatchSize?: number;
batchScheduleFn?: (callback: () => void) => void;
cache?: boolean;
cacheKeyFn?: (key: K) => C;
cacheMap?: CacheMap<C, Promise<V>> | null;
name?: string | null;
};
}
export {};