import { BatchFormat, BatchRequestBody, HttpResponseModel, ODataHttpClient } from "@odata2ts/http-client-api"; import { RequestCmd } from "../request/RequestCmd"; /** * The response odata2ts puts into a single slot of a batch result: that sub-request's answer, run through * the command's own response converters - or, where the sub-request never made it through, a synthesized * marker carrying status `0`. `T` is the command's final response structure, so the tuple {@link BatchBuilder.execute} * returns is element-for-element what the application would expect from running those requests one by one: * a slot that never ran is `T | undefined`, not a second batch-specific shape. */ export type BatchResponse = HttpResponseModel; /** Options for adding one request to a batch. */ export interface BatchAddOptions { /** * The wire ids of the requests in this batch whose sub-request must run before this one's. Order within a * change set guarantees nothing (§11.7.2), so this is the only way to say it. A static list names already-added * ids; in the factory form of {@link BatchBuilder.add} a callback `(selfRef) => number[]` is resolved against * the id the command is about to receive, so a relative dependency (`[selfRef - 1]`) is expressible. Each id * must name a request added before this one (a wire id between `1` and this request's own id minus one); a * self- or forward-reference is refused. Only a JSON batch may order its requests, so this option lives on * {@link JsonBatchBuilder.add} alone - a multipart batch carries no `dependsOn`. */ dependsOn?: Array | ((selfRef: number) => Array); } /** Options for sending one batch. */ export interface BatchExecuteOptions { /** Ask the server to answer what it can even where a sub-request fails (the `Prefer` header). */ continueOnError?: boolean; } /** * Collects a set of requests and sends them as one `$batch`. * * The builder does not re-implement the pipeline a request goes through: each collected command is prepared * with the very {@link RequestCmd.prepareRequest} and its answer dispatched with the very * {@link RequestCmd.handleResponse} a direct request uses, so converters, the concurrency rule and the * cache-key harvesting all behave exactly as they would one by one. What the builder owns is what a direct * request has no need of: the wire ids, the one url rewrite (the service base path, stripped), the * atomicity-group framing, and the normalization of a sub-answer that never happened. * * The wire format is fixed for the life of a builder and carried by the two concrete subclasses * {@link MultipartBatchBuilder} and {@link JsonBatchBuilder}; which one a generated service builds - and the * `TBuilder` type it is stamped with - is a generation-time decision, not a per-call option. */ export declare abstract class BatchBuilder = []> { private readonly __client; private readonly __basePath; private readonly __format; private readonly __entries; private __openGroup?; protected constructor(client: ODataHttpClient, basePath: string, format: BatchFormat); /** * Shared add plumbing: assigns the wire id, resolves and validates `dependsOn`, builds the command (plain or * factory form), refuses a blob or stream, and records the entry. The subclass's public `add` picks the return * type; the factory form is handed the wire id the command is about to receive, so the immediately-preceding * request is `selfRef - 1`. */ protected __addEntry(cmdOrFactory: RequestCmd | ((selfRef: number) => RequestCmd), dependsOnOption: BatchAddOptions["dependsOn"]): TThis; /** * A `dependsOn` may be stated statically or, in the factory form of {@link add}, as a callback that is * resolved against the id the command is about to receive - which is what lets a relative dependency * (`[selfRef - 1]`) name the previous request. */ private static resolveDependsOn; /** * A `dependsOn` may only name a request added before this one - the ids it are the wire ids of the * requests already in the batch, and this request cannot wait on itself or on a request that comes after it. * Checked here, where the dependency is stated, so a bad one is refused before the batch is built or sent. */ private __validateDependsOn; /** Open an atomicity group (a multipart change set). Commands added while it is open belong to it. */ startGroup(groupId: string): this; /** Close the open atomicity group. */ endGroup(): this; /** * The batch as it will be sent: wire ids assigned in the order the commands were added, the service base * path stripped off every sub-request url, and the atomicity group and `dependsOn` where they were set. */ getRequestInfo(): BatchRequestBody; /** * Send the collected requests as one `$batch` and return their answers, one element per added command. * * A slot whose sub-request never ran is a synthesized answer with status `0` (`"Never Ran"`); one whose * own status is 2xx but whose atomicity group carries a failure is likewise a status-`0` marker * (`"Rolled Back"`), because a rolled-back change set undid it (§11.7.2). Everything else is the * sub-request's real answer, converted - the builder does not invent a second result type. */ execute(options?: BatchExecuteOptions): Promise; private static isBatchIncompatible; private __batchUrl; private __prepareAll; private __buildBody; private __normalize; private static is2xx; private static toBatchMethod; private __stripBasePath; private static statusTextFor; } /** * A `$batch` in the multipart wire format - the default. The multipart batch is the one change sets (atomicity * groups) frame; it carries no `dependsOn`, so {@link MultipartBatchBuilder.add} takes no {@link BatchAddOptions}. */ export declare class MultipartBatchBuilder = []> extends BatchBuilder { constructor(client: ODataHttpClient, basePath: string); /** * Add one request to the batch. Blob and stream commands are refused - they carry a binary body the batch * wire formats cannot carry. The same command may be added more than once: it is reused across its slots * (the batch never mutates a command's state), so sending the same request twice is simply adding it twice. * * Two forms. The plain form takes the ready command. The factory form takes a function that builds the * command knowing the wire id it is about to receive - `selfRef` - so the immediately-preceding request is * `selfRef - 1` and a reference to it (`byRef(selfRef - 1)`) needs no hand-counting. Both return the builder, * so the chain stays fluent. */ add(cmdOrFactory: RequestCmd | ((selfRef: number) => RequestCmd)): MultipartBatchBuilder<[...R, BatchResponse]>; } /** * A `$batch` in the JSON wire format. Only a JSON batch may order its requests, so `dependsOn` - and thus the * {@link BatchAddOptions} - lives on {@link JsonBatchBuilder.add} alone. */ export declare class JsonBatchBuilder = []> extends BatchBuilder { constructor(client: ODataHttpClient, basePath: string); /** * Add one request to the batch, optionally naming the requests it must run after (`dependsOn`). The command * may be given plain or as a factory (which is handed the wire id `selfRef` the command is about to receive); * a blob or stream command is refused. Returns the builder, so the chain stays fluent. */ add(cmdOrFactory: RequestCmd | ((selfRef: number) => RequestCmd), options?: BatchAddOptions): JsonBatchBuilder<[...R, BatchResponse]>; }