import type { InferMethodOutputEncoding, InferOutput, LexValue, Payload, Procedure, Query, ResultSuccess, Validator } from '@atproto/lex-schema'; import type { EncodingString } from './types.js'; type InferEncodingType = TEncoding extends '*/*' ? EncodingString : TEncoding extends `${infer T extends string}/*` ? `${T}/${string}` : TEncoding; type InferBodyType = TSchema extends Validator ? InferOutput : TEncoding extends `application/json` ? LexValue : Uint8Array; /** * The body type of an XRPC response, inferred from the method's output schema. * * For JSON responses, this is the parsed LexValue. For binary responses, * this is a Uint8Array. * * @typeParam M - The XRPC method type (Procedure or Query) */ export type XrpcResponseBody = M['output'] extends Payload ? TEncoding extends string ? InferBodyType : undefined | LexValue | Uint8Array : never; /** * The full payload type of an XRPC response, including body and encoding. * * Returns `null` for methods that have no output. * * @typeParam M - The XRPC method type (Procedure or Query) */ export type XrpcResponsePayload = M['output'] extends Payload ? TEncoding extends string ? { encoding: InferEncodingType; body: InferBodyType; } : undefined | { body: LexValue | Uint8Array; encoding: string; } : never; export type XrpcResponseOptions = { /** * Whether to validate the response against the method's output schema. * Disabling this can improve performance but may lead to runtime errors if * the response does not conform to the expected schema. Only set this to * `false` if you are certain that the upstream service will always return * valid responses. * * @default true */ validateResponse?: boolean; /** * Whether to strictly process response payloads according to Lex encoding * rules. By default, the client will reject responses with invalid Lex data * (floats and invalid $bytes / $link objects). * * Setting this option to `false` will allow the client to accept such * responses in a non-strict mode, where invalid Lex data will be returned * as-is (e.g., floats will not be rejected, and invalid $bytes / $link * objects will not be converted to Uint8Array / Cid). When in non-strict * mode, the validation will also be relaxed when validating the response * against the method's output schema, allowing values that do not strictly * conform to the schema (e.g. datetime strings that are not valid RFC3339 * format, blobs that are not of the right size/mime-type, etc.) to be * accepted as long as their basic structure is correct. * * When validation is enabled (the default), the values defined through the * method schema will be enforced, ensuring that the client can still process * the response even if the server returns invalid Lex data. * * @default true * @see {@link LexParseOptions.strict} */ strictResponseProcessing?: boolean; }; /** * Small container for XRPC response. * * @implements {ResultSuccess>} for convenience in result handling contexts. * * @example * * ```typescript * import { app } from '#/lexicons' * import { XrpcResponse } from '@atproto/lex-client' * * const fetchResponse = await fetch('https://example.com/xrpc/app.bsky.feed.getTimeline') * * const response = await XrpcResponse.fromFetchResponse( * app.bsky.feed.getTimeline.main, * fetchResponse, * ) * * // Fully typed (validated) response body, according to the method's output schema * const { cursor, feed } = response.body * ``` */ export declare class XrpcResponse implements ResultSuccess> { readonly method: M; readonly status: number; readonly headers: Headers; readonly payload: XrpcResponsePayload; /** @see {@link ResultSuccess.success} */ readonly success: true; /** @see {@link ResultSuccess.value} */ get value(): this; constructor(method: M, status: number, headers: Headers, payload: XrpcResponsePayload); /** * Whether the response payload was parsed as {@link LexValue} (`true`) or is * in binary form {@link Uint8Array} (`false`). */ get isParsed(): boolean; /** * The Content-Type encoding of the response (e.g., 'application/json'). * Returns `undefined` if the response has no body. */ get encoding(): InferMethodOutputEncoding; /** * The parsed response body. * * For 'application/json' responses, this is the parsed and validated LexValue. * For binary responses, this is a Uint8Array. * Returns `undefined` if the response has no body. */ get body(): XrpcResponseBody; /** * @throws {XrpcResponseError} in case of (valid) XRPC error responses. Use * {@link XrpcResponseError.matchesSchemaErrors} to narrow the error type based on * the method's declared error schema. This can be narrowed further as a * {@link XrpcAuthenticationError} if the error is an authentication error. * @throws {XrpcInvalidResponseError} when the response is not a valid XRPC * response, or if the response does not conform to the method's schema. */ static fromFetchResponse(method: M, response: Response, options?: XrpcResponseOptions): Promise>; } export {}; //# sourceMappingURL=response.d.ts.map