UNPKG

@clickup/ent-framework

Version:

A PostgreSQL graph-database-alike library with microsharding and row-level security

37 lines 1.74 kB
export interface Handler<TLoadArgs extends unknown[], TReturn> { onCollect: (...args: TLoadArgs) => void | "flush" | "wait"; onWait?: () => Promise<void>; onFlush: (collected: number) => Promise<void>; onReturn: (...args: TLoadArgs) => TReturn; } /** * Loader allows to batch single-item requests into batches. It uses a different * architecture than Facebook's DataLoader: * * - it's more developers-friendly: multi-parameter loadings, you may implement * automatic deduplication of requests at onCollect stage, no requirement to * serialize/deserialize requests into string keys; * - strong-typed load() and handler arguments. * * To create your own specific loader: * 1. Define a handler class with onCollect/onReturn/onFlush methods. * 2. In onCollect, accumulate the incoming requests in the handler object's * private property. * 3. In onFlush, process what you accumulated so far and save to another * handler object's private property (and by adding, say, delay(50) in the * beginning of onFlush, you may group the requests coming within the 1st 50 * ms). * 3. In onReturn, extract the result corresponding to the request and return * it, so the caller will receive it seamlessly as a load() return value. * * In the future, Batcher may be refactored to use Loader as the underlying * engine, but for now they're separate (Batcher is much more domain logic * specific and Loader is completely abstract). */ export declare class Loader<TLoadArgs extends unknown[], TReturn> { private handlerCreator; private session; constructor(handlerCreator: () => Handler<TLoadArgs, TReturn>); load(...args: TLoadArgs): Promise<TReturn>; } //# sourceMappingURL=Loader.d.ts.map