@orpc/openapi-client
Version:
<div align="center"> <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" /> </div>
98 lines (91 loc) • 4.66 kB
text/typescript
import { ClientContext, ClientOptions } from '@orpc/client';
import { StandardLinkCodec, StandardLinkOptions, StandardLink, StandardLinkClient } from '@orpc/client/standard';
import { AnyContractRouter } from '@orpc/contract';
import { Segment, Value, Promisable } from '@orpc/shared';
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
type StandardBracketNotationSerialized = [string, unknown][];
interface StandardBracketNotationSerializerOptions {
/**
* Maximum allowed array index for bracket notation deserialization.
*
* This helps protect against memory exhaustion attacks where malicious input
* uses extremely large array indices (e.g., `?arr[4294967296]=value`).
*
* While bracket notation creates sparse arrays that handle large indices efficiently,
* downstream code might inadvertently convert these sparse arrays to dense arrays,
* potentially creating millions of undefined elements and causing memory issues.
*
* @note Only applies to deserialization.
* @default 9_999 (array with 10,000 elements)
*/
maxBracketNotationArrayIndex?: number;
}
declare class StandardBracketNotationSerializer {
private readonly maxArrayIndex;
constructor(options?: StandardBracketNotationSerializerOptions);
serialize(data: unknown, segments?: Segment[], result?: StandardBracketNotationSerialized): StandardBracketNotationSerialized;
deserialize(serialized: StandardBracketNotationSerialized): Record<string, unknown> | unknown[];
stringifyPath(segments: readonly Segment[]): string;
parsePath(path: string): string[];
}
type StandardOpenAPIJsonSerialized = [json: unknown, hasBlob: boolean];
interface StandardOpenAPICustomJsonSerializer {
condition(data: unknown): boolean;
serialize(data: any): unknown;
}
interface StandardOpenAPIJsonSerializerOptions {
customJsonSerializers?: readonly StandardOpenAPICustomJsonSerializer[];
}
declare class StandardOpenAPIJsonSerializer {
private readonly customSerializers;
constructor(options?: StandardOpenAPIJsonSerializerOptions);
serialize(data: unknown, hasBlobRef?: {
value: boolean;
}): StandardOpenAPIJsonSerialized;
}
interface StandardOpenAPISerializeOptions {
outputFormat?: 'plain' | 'URLSearchParams';
}
declare class StandardOpenAPISerializer {
#private;
private readonly jsonSerializer;
private readonly bracketNotation;
constructor(jsonSerializer: StandardOpenAPIJsonSerializer, bracketNotation: StandardBracketNotationSerializer);
serialize(data: unknown, options?: StandardOpenAPISerializeOptions): unknown;
deserialize(data: unknown): unknown;
}
interface StandardOpenapiLinkCodecOptions<T extends ClientContext> {
/**
* Base url for all requests.
*/
url: Value<Promisable<string | URL>, [
options: ClientOptions<T>,
path: readonly string[],
input: unknown
]>;
/**
* Inject headers to the request.
*/
headers?: Value<Promisable<StandardHeaders>, [
options: ClientOptions<T>,
path: readonly string[],
input: unknown
]>;
}
declare class StandardOpenapiLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
#private;
private readonly contract;
private readonly serializer;
private readonly baseUrl;
private readonly headers;
constructor(contract: AnyContractRouter, serializer: StandardOpenAPISerializer, options: StandardOpenapiLinkCodecOptions<T>);
encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
decode(response: StandardLazyResponse, _options: ClientOptions<T>, path: readonly string[]): Promise<unknown>;
}
interface StandardOpenAPILinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardOpenapiLinkCodecOptions<T>, StandardOpenAPIJsonSerializerOptions {
}
declare class StandardOpenAPILink<T extends ClientContext> extends StandardLink<T> {
constructor(contract: AnyContractRouter, linkClient: StandardLinkClient<T>, options: StandardOpenAPILinkOptions<T>);
}
export { StandardBracketNotationSerializer as b, StandardOpenAPIJsonSerializer as f, StandardOpenAPILink as h, StandardOpenapiLinkCodec as j, StandardOpenAPISerializer as l };
export type { StandardBracketNotationSerialized as S, StandardBracketNotationSerializerOptions as a, StandardOpenAPIJsonSerialized as c, StandardOpenAPICustomJsonSerializer as d, StandardOpenAPIJsonSerializerOptions as e, StandardOpenAPILinkOptions as g, StandardOpenapiLinkCodecOptions as i, StandardOpenAPISerializeOptions as k };