UNPKG

@proofkit/fmodata

Version:
55 lines (54 loc) 2.19 kB
import { ExecutableBuilder, ExecutionContext, Result, ExecuteOptions } from '../types.js'; import { FFetchOptions } from '@fetchkit/ffetch'; /** * Helper type to extract result types from a tuple of ExecutableBuilders. * Uses a mapped type which TypeScript 4.1+ can handle for tuples. */ type ExtractTupleTypes<T extends readonly ExecutableBuilder<any>[]> = { [K in keyof T]: T[K] extends ExecutableBuilder<infer U> ? U : never; }; /** * Builder for batch operations that allows multiple queries to be executed together * in a single transactional request. */ export declare class BatchBuilder<Builders extends readonly ExecutableBuilder<any>[]> implements ExecutableBuilder<ExtractTupleTypes<Builders>> { private readonly databaseName; private readonly context; private builders; private readonly originalBuilders; constructor(builders: Builders, databaseName: string, context: ExecutionContext); /** * Add a request to the batch dynamically. * This allows building up batch operations programmatically. * * @param builder - An executable builder to add to the batch * @returns This BatchBuilder for method chaining * @example * ```ts * const batch = db.batch([]); * batch.addRequest(db.from('contacts').list()); * batch.addRequest(db.from('users').list()); * const result = await batch.execute(); * ``` */ addRequest<T>(builder: ExecutableBuilder<T>): this; /** * Get the request configuration for this batch operation. * This is used internally by the execution system. */ getRequestConfig(): { method: string; url: string; body?: any; }; toRequest(baseUrl: string): Request; processResponse(response: Response, options?: ExecuteOptions): Promise<Result<any>>; /** * Execute the batch operation. * * @param options - Optional fetch options and batch-specific options (includes beforeRequest hook) * @returns A tuple of results matching the input builders */ execute<EO extends ExecuteOptions>(options?: RequestInit & FFetchOptions & EO): Promise<Result<ExtractTupleTypes<Builders>>>; } export {};