UNPKG

@dataplan/pg

Version:
62 lines 5.3 kB
import type { ExecutionDetails, GrafastResultsList, LoadManyInfo, LoadManyLoader, LoadManyStep, LoadOneInfo, LoadOneLoader, LoadOneStep, Maybe, Multistep, PromiseOrDirect, UnwrapMultistep } from "grafast"; import { Step } from "grafast"; import type { PgClient, PgExecutor, WithPgClient } from "../executor"; export type SideEffectWithPgClientStepCallback<TData, TResult, TPgClient extends PgClient = PgClient> = (client: TPgClient, data: TData) => Promise<TResult>; /** * Runs the given `callback` against the given `executor` using any plan data * from `$data` (which can be `constant(null)` if you don't need it). Typically * useful for running custom transactions. */ export declare class SideEffectWithPgClientStep<TData = any, TResult = any, TPgClient extends PgClient = PgClient> extends Step<TResult> { private callback; static $$export: { moduleName: string; exportName: string; }; isSyncAndSafe: boolean; /** * Tells us what we're dealing with - data type, columns, where to insert it, * what it's called, etc. */ readonly executor: PgExecutor; /** * The id for the PostgreSQL context plan. */ private contextId; /** * The id for the data plan. */ private dataId; constructor(executor: PgExecutor, $data: Step<TData>, callback: SideEffectWithPgClientStepCallback<TData, TResult, TPgClient>); execute({ indexMap, values, }: ExecutionDetails<[ { pgSettings: any; withPgClient: WithPgClient<TPgClient>; }, TData ]>): GrafastResultsList<TResult>; } export declare function sideEffectWithPgClient<const TInMultistep extends Multistep, TResult, TPgClient extends PgClient = PgClient>(executor: PgExecutor, spec: TInMultistep, callback: SideEffectWithPgClientStepCallback<UnwrapMultistep<TInMultistep>, TResult, TPgClient>): SideEffectWithPgClientStep<UnwrapMultistep<TInMultistep>, TResult, TPgClient>; export declare function sideEffectWithPgClientTransaction<const TInMultistep extends Multistep, TResult, TPgClient extends PgClient = PgClient>(executor: PgExecutor, spec: TInMultistep, callback: SideEffectWithPgClientStepCallback<UnwrapMultistep<TInMultistep>, TResult, TPgClient>): SideEffectWithPgClientStep<UnwrapMultistep<TInMultistep>, TResult, TPgClient>; /** @deprecated Use `sideEffectWithPgClient` or `loadOneWithPgClient` or `loadManyWithPgClient` instead */ export declare const withPgClient: typeof sideEffectWithPgClient; /** @deprecated Use `sideEffectWithPgClientTransaction` instead (or `loadOneWithPgClient`/`loadManyWithPgClient` if you're not doing a mutation) */ export declare const withPgClientTransaction: typeof sideEffectWithPgClientTransaction; export declare function loadOneWithPgClient<const TLookup extends Multistep, TItem, TData extends Maybe<TItem> = Maybe<TItem>, TParams extends Record<string, any> = Record<string, any>, const TShared extends Record<string, Step> = Record<string, never>>(executor: PgExecutor, lookup: TLookup, loader: LoadOneWithPgClientLoader<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared>): LoadOneStep<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared>; export type LoadOneWithPgClientCallback<TSpec, TItem, TData extends Maybe<TItem> = Maybe<TItem>, TParams extends Record<string, any> = Record<string, any>, TUnarySpec = never> = { (pgClient: PgClient, lookups: ReadonlyArray<TSpec>, info: LoadOneInfo<TItem, TParams, TUnarySpec>): PromiseOrDirect<ReadonlyArray<TData>>; displayName?: string; }; type LoadOneWithPgClientLoader<TSpec, TItem, TData extends Maybe<TItem>, TParams extends Record<string, any>, TShared extends Record<string, Step>> = LoadOneWithPgClientCallback<TSpec, TItem, TData, TParams, never> | (Omit<LoadOneLoader<TSpec, TItem, TData, TParams, TShared>, "load"> & { load: LoadOneWithPgClientCallback<TSpec, TItem, TData, TParams, UnwrapMultistep<TShared>>; }); export type LoadManyWithPgClientCallback<TSpec, TItem, TData extends Maybe<ReadonlyArray<Maybe<TItem>>> = Maybe<ReadonlyArray<Maybe<TItem>>>, TParams extends Record<string, any> = Record<string, any>, TUnarySpec = never> = { (pgClient: PgClient, lookups: ReadonlyArray<TSpec>, info: LoadManyInfo<TItem, TParams, TUnarySpec>): PromiseOrDirect<ReadonlyArray<TData>>; displayName?: string; }; type LoadManyWithPgClientLoader<TSpec, TItem, TData extends Maybe<ReadonlyArray<Maybe<TItem>>>, TParams extends Record<string, any>, TShared extends Record<string, Step>> = LoadManyWithPgClientCallback<TSpec, TItem, TData, TParams, never> | (Omit<LoadManyLoader<TSpec, TItem, TData, TParams, TShared>, "load"> & { load: LoadManyWithPgClientCallback<TSpec, TItem, TData, TParams, UnwrapMultistep<TShared>>; }); export declare function loadManyWithPgClient<const TLookup extends Multistep, TItem, TData extends Maybe<ReadonlyArray<Maybe<TItem>>> = Maybe<ReadonlyArray<Maybe<TItem>>>, TParams extends Record<string, any> = Record<string, any>, const TShared extends Record<string, Step> = Record<string, never>>(executor: PgExecutor, lookup: TLookup, loader: LoadManyWithPgClientLoader<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared>): LoadManyStep<UnwrapMultistep<TLookup>, TItem, TData, TParams, TShared>; export {}; //# sourceMappingURL=withPgClient.d.ts.map