UNPKG

@proofkit/fmodata

Version:
62 lines (61 loc) 2.54 kB
/** * Batch Request Utilities * * Utilities for formatting and parsing OData batch requests using multipart/mixed format. * OData batch requests allow bundling multiple operations into a single HTTP request, * with support for transactional changesets. */ export interface RequestConfig { method: string; url: string; body?: string; headers?: Record<string, string>; } export interface ParsedBatchResponse { status: number; statusText: string; headers: Record<string, string>; body: any; } /** * Generates a random boundary string for multipart requests * @param prefix - Prefix for the boundary (e.g., "batch_" or "changeset_") * @returns A boundary string with the prefix and 32 random hex characters */ export declare function generateBoundary(prefix?: string): string; /** * Formats multiple requests into a batch request body * @param requests - Array of request configurations * @param baseUrl - The base URL to prepend to relative URLs * @param batchBoundary - Optional boundary string for the batch (generated if not provided) * @returns Object containing the formatted body and boundary */ export declare function formatBatchRequest(requests: RequestConfig[], baseUrl: string, batchBoundary?: string): { body: string; boundary: string; }; /** * Formats multiple Request objects into a batch request body * Supports explicit changesets via Request arrays * @param requests - Array of Request objects or Request arrays (for explicit changesets) * @param baseUrl - The base URL to prepend to relative URLs * @param batchBoundary - Optional boundary string for the batch (generated if not provided) * @returns Promise resolving to object containing the formatted body and boundary */ export declare function formatBatchRequestFromNative(requests: Array<Request | Request[]>, baseUrl: string, batchBoundary?: string): Promise<{ body: string; boundary: string; }>; /** * Extracts the boundary from a Content-Type header * @param contentType - The Content-Type header value * @returns The boundary string, or null if not found */ export declare function extractBoundary(contentType: string): string | null; /** * Parses a batch response into individual responses * @param responseText - The raw batch response text * @param contentType - The Content-Type header from the response * @returns Array of parsed responses in the same order as the request */ export declare function parseBatchResponse(responseText: string, contentType: string): ParsedBatchResponse[];