import type { AnyElysia } from 'elysia'; import type { EdenQueryStoreKey } from '../constraints'; import type { TypeError } from '../errors'; import type { HTTPHeaders } from '../http'; import type { BatchPluginOptions } from '../plugins'; import { type EdenRequestOptions } from '../request'; import type { NonEmptyArray } from '../utils/types'; import type { EdenLink, Operation } from './internal/operation'; import { type DataTransformerOptions } from './internal/transformer'; /** * @remarks Do not derive this from HTTPLinkOptions, because it breaks the types for some reason... * * @template TTransformer * @todo Maybe check if T['store'][EdenQueryStoreKey] matches a certain interface? */ export type HttpBatchLinkOptions = Omit & { /** * Path for the batch endpoint. * * @example /batch */ endpoint?: string; /** * Configure the maximum URL length if making batch requests with GET. */ maxURLLength?: number; /** * @todo: Merge this headers type into {@link EdenRequestOptions} */ headers?: HTTPHeaders | ((operations: NonEmptyArray) => HTTPHeaders | Promise); method?: BatchMethod; } & (TTransformer extends false ? { transformer?: DataTransformerOptions; } : TTransformer extends DataTransformerOptions ? { transformer: TTransformer; } : { transformer?: DataTransformerOptions; }); export type BatchMethod = 'GET' | 'POST'; /** * If using GET request to batch, the request data will be encoded in query parameters. * This is only possible if all requests are GET requests. * * The query will look like this * * // GET request to /api/b?name=elysia, i.e. query of name=elysia * * batch=1&0.path=/api/b&0.method=GET&0.query.name=elysia */ export declare function generateGetBatchRequestInformation(operations: Operation[]): { body: null; query: Record; headers: Headers; }; /** * If using POST request to batch, most of the request data will be encoded in the FormData body. * * It will look like this: * * { * // POST request to /api/a with a JSON body of { value: 0 } * * '0.path': '/api/a', * '0.method': 'POST', * '0.body_type': 'JSON', * '0.body': '{ value: 0 }' * * // GET request to /api/b?name=elysia, i.e. query of name=elysia * * '1.path': '/api/b', * '1.method': 'GET', * '1.query.name': 'elysia' * } */ export declare function generatePostBatchRequestInformation(operations: Operation[], options?: HttpBatchLinkOptions): { body: FormData; query: {}; headers: Headers; }; /** * @see https://trpc.io/docs/v11/client/links/httpLink */ export declare const safeHttpBatchLink: (options?: HttpBatchLinkOptions) => T["store"][typeof EdenQueryStoreKey]["batch"] extends true | BatchPluginOptions ? EdenLink : TypeError<"Batch plugin not detected on Elysia.js app instance">; /** * @see https://trpc.io/docs/v11/client/links/httpLink */ export declare function httpBatchLink(options?: HttpBatchLinkOptions): EdenLink; //# sourceMappingURL=http-batch-link.d.ts.map