UNPKG

grafast

Version:

Cutting edge GraphQL planning and execution engine

98 lines 6.15 kB
import type { ConnectionOptimizedStep, ExecutionDetails } from "../index.js"; import type { GrafastResultsList, Maybe, PromiseOrDirect, Thunk } from "../interfaces.js"; import type { Multistep, UnwrapMultistep } from "../multistep.js"; import { Step } from "../step.js"; import { type IOEquivalence } from "./_loadCommon.js"; import type { PaginationFeatures, PaginationParams } from "./connection.js"; import { LoadedRecordStep } from "./loadedRecord.js"; export interface LoadManyInfo<TItem, TParams extends Record<string, any>, TShared = never> { shared: TShared; attributes: ReadonlyArray<keyof TItem>; params: Partial<TParams>; /** @deprecated Please use `shared` instead (it's simply renamed) */ unary: TShared; } export type LoadManyCallback<TLookup, TItem, TData extends Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>> = Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>>, TParams extends Record<string, any> = Record<string, any>, TShared = never> = { (lookups: ReadonlyArray<TLookup>, info: LoadManyInfo<TItem, TParams, TShared>): PromiseOrDirect<ReadonlyArray<TData>>; displayName?: string; }; /** * A TypeScript Identity Function to help you strongly type your * LoadManyCallback. */ export declare function loadManyCallback<TLookup, TItem, TData extends Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>> = Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>>, TParams extends Record<string, any> = Record<string, any>, TShared = never>(load: LoadManyCallback<TLookup, TItem, TData, TParams, TShared>): LoadManyCallback<TLookup, TItem, TData, TParams, TShared>; /** * A TypeScript Identity Function to help you strongly type your * LoadManyLoader. */ export declare function loadManyLoader<const TLookup extends Multistep, TItem, TData extends Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>> = Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>>, TParams extends Record<string, any> = Record<string, any>, const TShared extends Multistep = never>(load: LoadManyLoader<TLookup, TItem, TData, TParams, TShared>): LoadManyLoader<TLookup, TItem, TData, TParams, TShared>; interface LoadManyBaseParams { [key: string]: Maybe<any>; reverse?: Maybe<boolean>; after?: Maybe<string>; offset?: Maybe<number>; limit?: Maybe<number>; } export declare class LoadManyStep<const TLookup extends Multistep, TItem, TData extends Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>>, // loadMany TParams extends LoadManyBaseParams = any, const TShared extends Multistep = never> extends Step<TData> implements Partial<ConnectionOptimizedStep<TItem, any, any, any>> { static $$export: { moduleName: string; exportName: string; }; isSyncAndSafe: boolean; loadInfo: Omit<LoadManyInfo<TItem, TParams, UnwrapMultistep<TShared>>, "shared" | "unary" | "params"> | null; loadInfoKey: string; attributes: Set<keyof TItem>; paramDepIdByKey: { [TKey in keyof TParams]: number; }; sharedDepId: number | null; private ioEquivalence; private load; paginationSupport?: PaginationFeatures; private name; constructor(lookup: TLookup, loader: LoadManyLoader<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared>); toStringMeta(): string | null; private _accessMap; private getAccessMap; listItem($item: Step): LoadedRecordStep<TItem, TData extends Maybe<ReadonlyArrayOrAsyncIterable<infer U>> ? U extends Maybe<TItem> ? U : never : never, TParams>; setParam<TParamKey extends keyof TParams>(paramKey: TParamKey, value: TParams[TParamKey] | Step<Maybe<TParams[TParamKey]>>): void; addAttributes(attributes: Set<keyof TItem>): void; deduplicate(peers: readonly LoadManyStep<any, any, any, any, any>[]): LoadManyStep<any, any, any, any, any>[]; deduplicatedWith(replacement: LoadManyStep<any, any, any, any, any>): void; _paramSig?: string; getParamSignature(): string; finalize(): void; execute(details: ExecutionDetails): PromiseOrDirect<GrafastResultsList<TData>>; applyPagination?($params: Step<PaginationParams<any>>): void; connectionClone(): LoadManyStep<TLookup, TItem, TData, TParams, TShared> & ConnectionOptimizedStep<any, any, any, any>; } export interface LoadManyLoader<TSpec, TItem, TData extends Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>> = Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>>, TParams extends LoadManyBaseParams = LoadManyBaseParams, TShared extends Multistep = never> { /** * The function that actually loads data from the backend */ load: LoadManyCallback<TSpec, TItem, TData, TParams, UnwrapMultistep<TShared>>; /** Name your function (for plan diagrams/debugging) */ name?: string; /** * Details of anything your `load` function will need access to, for example * database connections, API clients, etc. */ shared?: Thunk<TShared>; /** * Details of which attributes on the output are equivalent to those on the * input (if any), useful for reducing unnecessary fetches (e.g. load the * friends of a user by their id without ever loading the user). */ ioEquivalence?: IOEquivalence<TSpec>; /** * Describes the feature the `load` function supports relating to pagination. * Even an empty object indicates that the load function supports `limit`, so * if this is not supported do not set this attribute. */ paginationSupport?: PaginationFeatures; } export declare function loadMany<const TLookup extends Multistep, TItem, TData extends Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>> = Maybe<ReadonlyArrayOrAsyncIterable<Maybe<TItem>>>, TParams extends Record<string, any> = Record<string, any>, const TShared extends Multistep = never>(lookup: TLookup, loader: LoadManyCallback<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared> | LoadManyLoader<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared>): LoadManyStep<UnwrapMultistep<TLookup>, TItem, TData, TParams, UnwrapMultistep<TShared>>; type ReadonlyArrayOrAsyncIterable<T> = ReadonlyArray<T> | AsyncIterable<T, void, unknown>; export {}; //# sourceMappingURL=loadMany.d.ts.map