@orpc/client
Advanced tools
| import { sortPlugins, runWithSpan, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, intercept, getOpenTelemetryConfig, value, pathToHttpPath, stringifyJSON } from '@orpc/shared'; | ||
| import { mergeStandardHeaders, parseStandardUrl } from '@standardserver/core'; | ||
| import { toStandardHeaders } from '@standardserver/fetch'; | ||
| import { O as ORPCError } from './client.CPcOxSex.mjs'; | ||
| import { R as RPCSerializer, i as isORPCErrorJson, c as createORPCErrorFromJson } from './client.BZMJyvQd.mjs'; | ||
| class CompositeStandardLinkPlugin { | ||
| name = "~composite"; | ||
| plugins; | ||
| constructor(plugins = []) { | ||
| this.plugins = sortPlugins(plugins); | ||
| } | ||
| init(options) { | ||
| for (const plugin of this.plugins) { | ||
| if (plugin.init) { | ||
| options = plugin.init(options); | ||
| } | ||
| } | ||
| return options; | ||
| } | ||
| } | ||
| class StandardLink { | ||
| constructor(codec, transport, options = {}) { | ||
| this.codec = codec; | ||
| this.transport = transport; | ||
| options = new CompositeStandardLinkPlugin(options.plugins).init(options); | ||
| this.interceptors = options.interceptors; | ||
| this.transportInterceptors = options.transportInterceptors; | ||
| } | ||
| interceptors; | ||
| transportInterceptors; | ||
| /** | ||
| * @throws ORPCError, transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| call(path, input, options) { | ||
| return runWithSpan(`${ORPC_NAME}.${path.join("/")}`, (span) => { | ||
| span?.setAttribute("rpc.system", ORPC_NAME); | ||
| span?.setAttribute("rpc.method", path.join(".")); | ||
| if (isAsyncIteratorObject(input)) { | ||
| input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input)); | ||
| } | ||
| return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => { | ||
| const otel = getOpenTelemetryConfig(); | ||
| let activeContext; | ||
| const activeSpan = otel?.trace.getActiveSpan() ?? span; | ||
| if (activeSpan && otel) { | ||
| activeContext = otel.trace.setSpan(otel.context.active(), activeSpan); | ||
| } | ||
| let request = await runWithSpan( | ||
| { name: "encode_input", context: activeContext }, | ||
| () => this.codec.encodeInput(input2, path2, options2) | ||
| ); | ||
| if (activeContext && otel?.propagation) { | ||
| const headers = { ...request.headers }; | ||
| otel.propagation.inject(activeContext, headers); | ||
| request = { ...request, headers }; | ||
| } | ||
| const response = await intercept( | ||
| this.transportInterceptors, | ||
| { ...options2, path: path2, request }, | ||
| ({ path: path3, request: request2, ...options3 }) => { | ||
| let activeTransportContext; | ||
| const activeTransportSpan = otel?.trace.getActiveSpan() ?? activeSpan; | ||
| if (activeTransportSpan && otel) { | ||
| activeTransportContext = otel.trace.setSpan(otel.context.active(), activeTransportSpan); | ||
| } | ||
| return runWithSpan( | ||
| { name: "send_request", context: activeTransportContext }, | ||
| () => this.transport.send(request2, path3, options3) | ||
| ); | ||
| } | ||
| ); | ||
| const decodedResult = await runWithSpan( | ||
| { name: "decode_response", context: activeContext }, | ||
| () => this.codec.decodeResponse(response, path2, options2) | ||
| ); | ||
| if (decodedResult.kind === "error") { | ||
| throw decodedResult.error; | ||
| } | ||
| const output = decodedResult.output; | ||
| if (isAsyncIteratorObject(output)) { | ||
| return override(output, traceAsyncIterator("consume_async_iterator_object_output", output)); | ||
| } | ||
| return output; | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| const END_SLASH_REGEX = /\/$/; | ||
| class RPCLinkCodec { | ||
| baseUrl; | ||
| maxUrlLength; | ||
| fallbackMethod; | ||
| expectedMethod; | ||
| headers; | ||
| serializer; | ||
| constructor(options) { | ||
| this.baseUrl = options.url ?? "/"; | ||
| this.maxUrlLength = options.maxUrlLength ?? 2083; | ||
| this.fallbackMethod = options.fallbackMethod ?? "POST"; | ||
| this.expectedMethod = options.method ?? this.fallbackMethod; | ||
| this.headers = options.headers ?? {}; | ||
| this.serializer = options.serializer ?? new RPCSerializer(); | ||
| } | ||
| async encodeInput(input, path, options) { | ||
| let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input)); | ||
| if (options.lastEventId !== void 0) { | ||
| headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId }); | ||
| } | ||
| const expectedMethod = await value(this.expectedMethod, options, path, input); | ||
| const baseUrl = await value(this.baseUrl, options, path, input); | ||
| const [pathname, search, hash] = parseStandardUrl(baseUrl); | ||
| const newPathname = `${pathname.replace(END_SLASH_REGEX, "")}${pathToHttpPath(path)}`; | ||
| const serialized = this.serializer.serialize(input); | ||
| if (expectedMethod === "GET" && !(serialized instanceof Blob) && !(serialized instanceof ReadableStream) && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) { | ||
| const maxUrlLength = await value(this.maxUrlLength, options, path, input); | ||
| const mergedSearch = new URLSearchParams(search); | ||
| mergedSearch.append("data", stringifyJSON(serialized) ?? ""); | ||
| const url2 = `${newPathname}?${mergedSearch}${hash ?? ""}`; | ||
| if (url2.length <= maxUrlLength) { | ||
| return { | ||
| body: void 0, | ||
| method: expectedMethod, | ||
| headers, | ||
| url: url2, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| } | ||
| const url = `${newPathname}${search ?? ""}${hash ?? ""}`; | ||
| return { | ||
| url, | ||
| method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod, | ||
| headers, | ||
| body: serialized, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| async decodeResponse(response) { | ||
| const isOk = response.status < 400; | ||
| const body = await response.resolveBody(); | ||
| const deserialized = await (async () => { | ||
| try { | ||
| return this.serializer.deserialize(body); | ||
| } catch (cause) { | ||
| throw new Error("Invalid RPC response format.", { | ||
| cause | ||
| }); | ||
| } | ||
| })(); | ||
| if (!isOk) { | ||
| if (isORPCErrorJson(deserialized)) { | ||
| return { kind: "error", error: createORPCErrorFromJson(deserialized) }; | ||
| } | ||
| return { | ||
| kind: "error", | ||
| error: new ORPCError("MALFORMED_ORPC_ERROR_RESPONSE", { | ||
| data: { headers: response.headers, status: response.status, body: deserialized } | ||
| }) | ||
| }; | ||
| } | ||
| return { kind: "output", output: deserialized }; | ||
| } | ||
| } | ||
| function toResolvedStandardHeaders(headers) { | ||
| if (typeof headers.forEach === "function") { | ||
| return toStandardHeaders(headers); | ||
| } | ||
| return headers; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, RPCLinkCodec as R, StandardLink as S }; |
| import { StandardBody } from '@standardserver/core'; | ||
| import { Segment } from '@orpc/shared'; | ||
| type RPCJsonSerializationMeta = [type: string, ...path: Segment[]]; | ||
| type RPCJsonSerialization = { | ||
| json: unknown; | ||
| meta?: RPCJsonSerializationMeta[] | undefined; | ||
| maps?: undefined; | ||
| blobs?: undefined; | ||
| } | { | ||
| json: unknown; | ||
| meta?: RPCJsonSerializationMeta[] | undefined; | ||
| maps: Segment[][]; | ||
| blobs: Blob[]; | ||
| }; | ||
| interface RPCJsonSerializerHandler { | ||
| condition(value: unknown): boolean; | ||
| serialize(value: any): unknown; | ||
| deserialize(serialized: any): unknown; | ||
| /** | ||
| * If false, the result of this serializer will not be further processed by other serializers, | ||
| * even if it matches their conditions and treat it as final serialized value. | ||
| * This can be useful for serializers that return primitive values, which should not be further processed. | ||
| * to improve performance and avoid potential issues with other serializers. | ||
| * | ||
| * @default false | ||
| */ | ||
| isTerminal?: boolean; | ||
| } | ||
| interface RPCJsonSerializerOptions { | ||
| /** | ||
| * Extend or override the built-in type handlers used during serialization and deserialization. | ||
| * | ||
| * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler | ||
| * that defines how to detect, serialize, and deserialize values of that type. | ||
| * | ||
| * **Extending:** Add new keys to support custom types: | ||
| * ```ts | ||
| * handlers: { | ||
| * buffer: { | ||
| * condition: (v) => v instanceof Buffer, | ||
| * serialize: (v: Buffer) => v.toString('base64'), | ||
| * deserialize: (s: string) => Buffer.from(s, 'base64'), | ||
| * isTerminal: true, | ||
| * } | ||
| * } | ||
| * ``` | ||
| * | ||
| * **Overriding:** Use an existing key to replace a built-in handler: | ||
| * ```ts | ||
| * handlers: { | ||
| * date: { | ||
| * condition: (v) => v instanceof Date, | ||
| * serialize: (v: Date) => v.getTime(), | ||
| * deserialize: (n: number) => new Date(n), | ||
| * isTerminal: true, | ||
| * } | ||
| * } | ||
| * ``` | ||
| * | ||
| * **Disabling:** Set a key to `undefined` to remove a built-in handler: | ||
| * ```ts | ||
| * handlers: { regexp: undefined } | ||
| * ``` | ||
| * | ||
| * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `regexp`, `set`, `map`. | ||
| */ | ||
| handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined; | ||
| /** | ||
| * If true, properties with undefined values will be omitted during serialization. | ||
| * | ||
| * @default true | ||
| */ | ||
| omitUndefinedProperties?: boolean | undefined; | ||
| } | ||
| declare class RPCJsonSerializer { | ||
| private readonly handlers; | ||
| private readonly inlineBuiltInHandlers; | ||
| private readonly handlerEntries; | ||
| private readonly omitUndefinedProperties; | ||
| constructor(options?: RPCJsonSerializerOptions); | ||
| serialize(data: unknown): RPCJsonSerialization; | ||
| /** | ||
| * `segments` is a shared mutable stack (push/pop while walking), | ||
| * so it must be copied before being stored in `meta` or `maps`. | ||
| */ | ||
| private serializeValue; | ||
| deserialize(serialized: RPCJsonSerialization): unknown; | ||
| } | ||
| interface RPCSerializerSerializeOptions { | ||
| /** | ||
| * Use FormData for serialization when nested blobs are present. | ||
| * Does not apply to root-level Blob values. | ||
| * | ||
| * @default true | ||
| */ | ||
| useFormDataForBlobFields?: boolean; | ||
| } | ||
| interface RPCSerializerOptions extends RPCJsonSerializerOptions { | ||
| /** | ||
| * Default options for serialize method | ||
| */ | ||
| serialize?: RPCSerializerSerializeOptions | undefined; | ||
| } | ||
| /** | ||
| * Serializes and deserializes data for the RPC protocol, | ||
| * preserving native types like Date, BigInt, Set, and Map that plain JSON cannot represent. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/rpc/serializer | RPC Serializer} | ||
| */ | ||
| declare class RPCSerializer { | ||
| private readonly jsonSerializer; | ||
| private readonly defaultSerializeOptions; | ||
| constructor(options?: RPCSerializerOptions); | ||
| serialize(data: unknown, options?: RPCSerializerSerializeOptions): StandardBody; | ||
| private serializeValue; | ||
| deserialize(data: StandardBody): unknown; | ||
| private deserializeValue; | ||
| } | ||
| export { RPCJsonSerializer as b, RPCSerializer as e }; | ||
| export type { RPCJsonSerialization as R, RPCJsonSerializationMeta as a, RPCJsonSerializerHandler as c, RPCJsonSerializerOptions as d, RPCSerializerOptions as f, RPCSerializerSerializeOptions as g }; |
| import { StandardBody } from '@standardserver/core'; | ||
| import { Segment } from '@orpc/shared'; | ||
| type RPCJsonSerializationMeta = [type: string, ...path: Segment[]]; | ||
| type RPCJsonSerialization = { | ||
| json: unknown; | ||
| meta?: RPCJsonSerializationMeta[] | undefined; | ||
| maps?: undefined; | ||
| blobs?: undefined; | ||
| } | { | ||
| json: unknown; | ||
| meta?: RPCJsonSerializationMeta[] | undefined; | ||
| maps: Segment[][]; | ||
| blobs: Blob[]; | ||
| }; | ||
| interface RPCJsonSerializerHandler { | ||
| condition(value: unknown): boolean; | ||
| serialize(value: any): unknown; | ||
| deserialize(serialized: any): unknown; | ||
| /** | ||
| * If false, the result of this serializer will not be further processed by other serializers, | ||
| * even if it matches their conditions and treat it as final serialized value. | ||
| * This can be useful for serializers that return primitive values, which should not be further processed. | ||
| * to improve performance and avoid potential issues with other serializers. | ||
| * | ||
| * @default false | ||
| */ | ||
| isTerminal?: boolean; | ||
| } | ||
| interface RPCJsonSerializerOptions { | ||
| /** | ||
| * Extend or override the built-in type handlers used during serialization and deserialization. | ||
| * | ||
| * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler | ||
| * that defines how to detect, serialize, and deserialize values of that type. | ||
| * | ||
| * **Extending:** Add new keys to support custom types: | ||
| * ```ts | ||
| * handlers: { | ||
| * buffer: { | ||
| * condition: (v) => v instanceof Buffer, | ||
| * serialize: (v: Buffer) => v.toString('base64'), | ||
| * deserialize: (s: string) => Buffer.from(s, 'base64'), | ||
| * isTerminal: true, | ||
| * } | ||
| * } | ||
| * ``` | ||
| * | ||
| * **Overriding:** Use an existing key to replace a built-in handler: | ||
| * ```ts | ||
| * handlers: { | ||
| * date: { | ||
| * condition: (v) => v instanceof Date, | ||
| * serialize: (v: Date) => v.getTime(), | ||
| * deserialize: (n: number) => new Date(n), | ||
| * isTerminal: true, | ||
| * } | ||
| * } | ||
| * ``` | ||
| * | ||
| * **Disabling:** Set a key to `undefined` to remove a built-in handler: | ||
| * ```ts | ||
| * handlers: { regexp: undefined } | ||
| * ``` | ||
| * | ||
| * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `regexp`, `set`, `map`. | ||
| */ | ||
| handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined; | ||
| /** | ||
| * If true, properties with undefined values will be omitted during serialization. | ||
| * | ||
| * @default true | ||
| */ | ||
| omitUndefinedProperties?: boolean | undefined; | ||
| } | ||
| declare class RPCJsonSerializer { | ||
| private readonly handlers; | ||
| private readonly inlineBuiltInHandlers; | ||
| private readonly handlerEntries; | ||
| private readonly omitUndefinedProperties; | ||
| constructor(options?: RPCJsonSerializerOptions); | ||
| serialize(data: unknown): RPCJsonSerialization; | ||
| /** | ||
| * `segments` is a shared mutable stack (push/pop while walking), | ||
| * so it must be copied before being stored in `meta` or `maps`. | ||
| */ | ||
| private serializeValue; | ||
| deserialize(serialized: RPCJsonSerialization): unknown; | ||
| } | ||
| interface RPCSerializerSerializeOptions { | ||
| /** | ||
| * Use FormData for serialization when nested blobs are present. | ||
| * Does not apply to root-level Blob values. | ||
| * | ||
| * @default true | ||
| */ | ||
| useFormDataForBlobFields?: boolean; | ||
| } | ||
| interface RPCSerializerOptions extends RPCJsonSerializerOptions { | ||
| /** | ||
| * Default options for serialize method | ||
| */ | ||
| serialize?: RPCSerializerSerializeOptions | undefined; | ||
| } | ||
| /** | ||
| * Serializes and deserializes data for the RPC protocol, | ||
| * preserving native types like Date, BigInt, Set, and Map that plain JSON cannot represent. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/rpc/serializer | RPC Serializer} | ||
| */ | ||
| declare class RPCSerializer { | ||
| private readonly jsonSerializer; | ||
| private readonly defaultSerializeOptions; | ||
| constructor(options?: RPCSerializerOptions); | ||
| serialize(data: unknown, options?: RPCSerializerSerializeOptions): StandardBody; | ||
| private serializeValue; | ||
| deserialize(data: StandardBody): unknown; | ||
| private deserializeValue; | ||
| } | ||
| export { RPCJsonSerializer as b, RPCSerializer as e }; | ||
| export type { RPCJsonSerialization as R, RPCJsonSerializationMeta as a, RPCJsonSerializerHandler as c, RPCJsonSerializerOptions as d, RPCSerializerOptions as f, RPCSerializerSerializeOptions as g }; |
| import { Promisable, OrderablePlugin, Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.EMUKnkap.js'; | ||
| type StandardLinkCodecDecodedResponse = { | ||
| kind: 'output'; | ||
| output: unknown; | ||
| } | { | ||
| kind: 'error'; | ||
| error: AnyORPCError; | ||
| }; | ||
| interface StandardLinkCodec<T extends ClientContext> { | ||
| encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promisable<StandardRequest>; | ||
| decodeResponse(response: StandardLazyResponse, path: string[], options: ClientOptions<T>): Promisable<StandardLinkCodecDecodedResponse>; | ||
| } | ||
| interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin { | ||
| /** | ||
| * Initializes the plugin and returns new link options. | ||
| * Called once per plugin instance during composition. | ||
| * | ||
| * This method allows plugins to wrap, extend, or transform link options | ||
| * such as interceptors, or configuration. | ||
| * | ||
| * @param options - The current link options from previous plugins or base configuration | ||
| * @returns Transformed link options with plugin's modifications applied | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * init(options) { | ||
| * return { | ||
| * ...options, | ||
| * interceptors: [...(options.interceptors || []), myInterceptor] | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>; | ||
| } | ||
| declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| name: string; | ||
| protected readonly plugins: StandardLinkPlugin<T>[]; | ||
| constructor(plugins?: StandardLinkPlugin<T>[]); | ||
| init(options: StandardLinkOptions<T>): StandardLinkOptions<T>; | ||
| } | ||
| /** | ||
| * Handles the transport layer for sending requests and receiving responses. | ||
| * | ||
| * Implementations are responsible for the actual network communication, | ||
| * such as HTTP fetch, WebSocket, or other transport mechanisms. | ||
| */ | ||
| interface StandardLinkTransport<T extends ClientContext> { | ||
| /** | ||
| * @throws Transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| send(request: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>; | ||
| } | ||
| interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: string[]; | ||
| input: unknown; | ||
| } | ||
| type StandardLinkInterceptor<T extends ClientContext> = Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>; | ||
| interface StandardLinkTransportInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: string[]; | ||
| request: StandardRequest; | ||
| } | ||
| type StandardLinkTransportInterceptor<T extends ClientContext> = Interceptor<StandardLinkTransportInterceptorOptions<T>, Promise<StandardLazyResponse>>; | ||
| interface StandardLinkOptions<T extends ClientContext> { | ||
| /** | ||
| * Interceptors that execute around the entire call, including transport and codec. | ||
| * Useful for error handling, logging, metrics, ... | ||
| */ | ||
| interceptors?: StandardLinkInterceptor<T>[]; | ||
| /** | ||
| * Interceptors that execute around the transport layer, after encoding and before decoding. | ||
| * Useful for modifying the request or response, adding transport-level logging, ... | ||
| */ | ||
| transportInterceptors?: StandardLinkTransportInterceptor<T>[]; | ||
| plugins?: StandardLinkPlugin<T>[]; | ||
| } | ||
| declare class StandardLink<T extends ClientContext> implements ClientLink<T> { | ||
| private readonly codec; | ||
| private readonly transport; | ||
| private readonly interceptors; | ||
| private readonly transportInterceptors; | ||
| constructor(codec: StandardLinkCodec<T>, transport: StandardLinkTransport<T>, options?: StandardLinkOptions<T>); | ||
| /** | ||
| * @throws ORPCError, transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as a }; | ||
| export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i }; |
| import { Promisable, OrderablePlugin, Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.EMUKnkap.mjs'; | ||
| type StandardLinkCodecDecodedResponse = { | ||
| kind: 'output'; | ||
| output: unknown; | ||
| } | { | ||
| kind: 'error'; | ||
| error: AnyORPCError; | ||
| }; | ||
| interface StandardLinkCodec<T extends ClientContext> { | ||
| encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promisable<StandardRequest>; | ||
| decodeResponse(response: StandardLazyResponse, path: string[], options: ClientOptions<T>): Promisable<StandardLinkCodecDecodedResponse>; | ||
| } | ||
| interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin { | ||
| /** | ||
| * Initializes the plugin and returns new link options. | ||
| * Called once per plugin instance during composition. | ||
| * | ||
| * This method allows plugins to wrap, extend, or transform link options | ||
| * such as interceptors, or configuration. | ||
| * | ||
| * @param options - The current link options from previous plugins or base configuration | ||
| * @returns Transformed link options with plugin's modifications applied | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * init(options) { | ||
| * return { | ||
| * ...options, | ||
| * interceptors: [...(options.interceptors || []), myInterceptor] | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>; | ||
| } | ||
| declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| name: string; | ||
| protected readonly plugins: StandardLinkPlugin<T>[]; | ||
| constructor(plugins?: StandardLinkPlugin<T>[]); | ||
| init(options: StandardLinkOptions<T>): StandardLinkOptions<T>; | ||
| } | ||
| /** | ||
| * Handles the transport layer for sending requests and receiving responses. | ||
| * | ||
| * Implementations are responsible for the actual network communication, | ||
| * such as HTTP fetch, WebSocket, or other transport mechanisms. | ||
| */ | ||
| interface StandardLinkTransport<T extends ClientContext> { | ||
| /** | ||
| * @throws Transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| send(request: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>; | ||
| } | ||
| interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: string[]; | ||
| input: unknown; | ||
| } | ||
| type StandardLinkInterceptor<T extends ClientContext> = Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>; | ||
| interface StandardLinkTransportInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: string[]; | ||
| request: StandardRequest; | ||
| } | ||
| type StandardLinkTransportInterceptor<T extends ClientContext> = Interceptor<StandardLinkTransportInterceptorOptions<T>, Promise<StandardLazyResponse>>; | ||
| interface StandardLinkOptions<T extends ClientContext> { | ||
| /** | ||
| * Interceptors that execute around the entire call, including transport and codec. | ||
| * Useful for error handling, logging, metrics, ... | ||
| */ | ||
| interceptors?: StandardLinkInterceptor<T>[]; | ||
| /** | ||
| * Interceptors that execute around the transport layer, after encoding and before decoding. | ||
| * Useful for modifying the request or response, adding transport-level logging, ... | ||
| */ | ||
| transportInterceptors?: StandardLinkTransportInterceptor<T>[]; | ||
| plugins?: StandardLinkPlugin<T>[]; | ||
| } | ||
| declare class StandardLink<T extends ClientContext> implements ClientLink<T> { | ||
| private readonly codec; | ||
| private readonly transport; | ||
| private readonly interceptors; | ||
| private readonly transportInterceptors; | ||
| constructor(codec: StandardLinkCodec<T>, transport: StandardLinkTransport<T>, options?: StandardLinkOptions<T>); | ||
| /** | ||
| * @throws ORPCError, transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as a }; | ||
| export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i }; |
| import { isPlainObject, wrapAsyncIterator, isTypescriptObject, NullProtoObj, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared'; | ||
| import { getEventMeta, withEventMeta, ErrorEvent } from '@standardserver/core'; | ||
| import { O as ORPCError } from './client.CPcOxSex.mjs'; | ||
| function isInferableError(error) { | ||
| return error instanceof ORPCError && error.inferable; | ||
| } | ||
| function toORPCError(error) { | ||
| return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { cause: error }); | ||
| } | ||
| function isORPCErrorJson(json) { | ||
| if (!isPlainObject(json)) { | ||
| return false; | ||
| } | ||
| const validKeys = ["defined", "inferable", "code", "message", "data"]; | ||
| if (Object.keys(json).some((k) => !validKeys.includes(k))) { | ||
| return false; | ||
| } | ||
| return "defined" in json && typeof json.defined === "boolean" && "inferable" in json && typeof json.inferable === "boolean" && "code" in json && typeof json.code === "string" && "message" in json && typeof json.message === "string"; | ||
| } | ||
| function createORPCErrorFromJson(json, options = {}) { | ||
| const error = new ORPCError(json.code, { | ||
| ...json, | ||
| ...options | ||
| }); | ||
| error.defined = json.defined; | ||
| error.inferable = json.inferable; | ||
| return error; | ||
| } | ||
| function cloneORPCError(error) { | ||
| const cloned = new ORPCError(error.code, { | ||
| ...error, | ||
| message: error.message, | ||
| data: error.data, | ||
| cause: error.cause | ||
| }); | ||
| cloned.stack = error.stack; | ||
| cloned.defined = error.defined; | ||
| cloned.inferable = error.inferable; | ||
| return cloned; | ||
| } | ||
| function wrapAsyncIteratorPreservingEventMeta(iterator, { mapResult, mapError, ...rest }) { | ||
| return wrapAsyncIterator(iterator, { | ||
| ...rest, | ||
| mapResult: mapResult && (async (result) => { | ||
| const mapped = await mapResult(result); | ||
| if (mapped.value !== result.value) { | ||
| const meta = getEventMeta(result.value); | ||
| if (meta && isTypescriptObject(mapped.value)) { | ||
| return { done: mapped.done, value: withEventMeta(mapped.value, meta) }; | ||
| } | ||
| } | ||
| return mapped; | ||
| }), | ||
| mapError: mapError && (async (error) => { | ||
| const mapped = await mapError(error); | ||
| if (mapped !== error) { | ||
| const meta = getEventMeta(error); | ||
| if (meta && isTypescriptObject(mapped)) { | ||
| return withEventMeta(mapped, meta); | ||
| } | ||
| } | ||
| return mapped; | ||
| }) | ||
| }); | ||
| } | ||
| const REGEX_STRING_PATTERN = /^\/([\s\S]*)\/([a-z]*)$/; | ||
| const DEFAULT_RPC_JSON_SERIALIZER_HANDLERS = { | ||
| undefined: { | ||
| condition(data) { | ||
| return data === void 0; | ||
| }, | ||
| serialize() { | ||
| return null; | ||
| }, | ||
| deserialize() { | ||
| return void 0; | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| bigint: { | ||
| condition(data) { | ||
| return typeof data === "bigint"; | ||
| }, | ||
| serialize(data) { | ||
| return data.toString(); | ||
| }, | ||
| deserialize(serialized) { | ||
| return BigInt(serialized); | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| date: { | ||
| condition(data) { | ||
| return data instanceof Date; | ||
| }, | ||
| serialize(data) { | ||
| if (Number.isNaN(data.getTime())) { | ||
| return null; | ||
| } | ||
| return data.toISOString(); | ||
| }, | ||
| deserialize(serialized) { | ||
| return new Date(serialized ?? "Invalid Date"); | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| nan: { | ||
| condition(data) { | ||
| return typeof data === "number" && Number.isNaN(data); | ||
| }, | ||
| serialize() { | ||
| return null; | ||
| }, | ||
| deserialize() { | ||
| return Number.NaN; | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| url: { | ||
| condition(data) { | ||
| return data instanceof URL; | ||
| }, | ||
| serialize(data) { | ||
| return data.toString(); | ||
| }, | ||
| deserialize(serialized) { | ||
| return new URL(serialized); | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| regexp: { | ||
| condition(data) { | ||
| return data instanceof RegExp; | ||
| }, | ||
| serialize(data) { | ||
| return data.toString(); | ||
| }, | ||
| deserialize(serialized) { | ||
| const [, pattern, flags] = serialized.match(REGEX_STRING_PATTERN); | ||
| return new RegExp(pattern, flags); | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| set: { | ||
| condition(data) { | ||
| return data instanceof Set; | ||
| }, | ||
| serialize(data) { | ||
| return Array.from(data); | ||
| }, | ||
| deserialize(serialized) { | ||
| return new Set(serialized); | ||
| } | ||
| }, | ||
| map: { | ||
| condition(data) { | ||
| return data instanceof Map; | ||
| }, | ||
| serialize(data) { | ||
| return Array.from(data.entries()); | ||
| }, | ||
| deserialize(serialized) { | ||
| return new Map(serialized); | ||
| } | ||
| } | ||
| }; | ||
| class RPCJsonSerializer { | ||
| handlers; | ||
| inlineBuiltInHandlers; | ||
| handlerEntries; | ||
| omitUndefinedProperties; | ||
| constructor(options = {}) { | ||
| this.omitUndefinedProperties = options.omitUndefinedProperties !== false; | ||
| this.handlers = Object.assign(new NullProtoObj(), DEFAULT_RPC_JSON_SERIALIZER_HANDLERS); | ||
| const customHandlers = options.handlers; | ||
| if (customHandlers === void 0) { | ||
| this.inlineBuiltInHandlers = true; | ||
| return; | ||
| } | ||
| let inlineBuiltInHandlers = true; | ||
| let handlerEntries = []; | ||
| for (const key in customHandlers) { | ||
| const handler = customHandlers[key]; | ||
| this.handlers[key] = handler; | ||
| if (inlineBuiltInHandlers && key in DEFAULT_RPC_JSON_SERIALIZER_HANDLERS) { | ||
| inlineBuiltInHandlers = false; | ||
| } | ||
| if (inlineBuiltInHandlers && handler !== void 0) { | ||
| handlerEntries.push([key, handler]); | ||
| } | ||
| } | ||
| if (!inlineBuiltInHandlers) { | ||
| handlerEntries = []; | ||
| for (const key in this.handlers) { | ||
| const handler = this.handlers[key]; | ||
| if (handler !== void 0) { | ||
| handlerEntries.push([key, handler]); | ||
| } | ||
| } | ||
| } | ||
| this.inlineBuiltInHandlers = inlineBuiltInHandlers; | ||
| this.handlerEntries = handlerEntries; | ||
| } | ||
| serialize(data) { | ||
| let meta = []; | ||
| const maps = []; | ||
| const blobs = []; | ||
| const json = this.serializeValue(data, [], meta, maps, blobs); | ||
| meta = meta.length === 0 ? void 0 : meta; | ||
| if (maps.length === 0) { | ||
| return { json, meta }; | ||
| } | ||
| return { json, meta, maps, blobs }; | ||
| } | ||
| /** | ||
| * `segments` is a shared mutable stack (push/pop while walking), | ||
| * so it must be copied before being stored in `meta` or `maps`. | ||
| */ | ||
| serializeValue(data, segments, meta, maps, blobs) { | ||
| if (this.inlineBuiltInHandlers) { | ||
| switch (typeof data) { | ||
| case "string": | ||
| case "boolean": | ||
| return data; | ||
| case "number": | ||
| if (Number.isNaN(data)) { | ||
| meta.push(["nan", ...segments]); | ||
| return null; | ||
| } | ||
| return data; | ||
| case "undefined": | ||
| meta.push(["undefined", ...segments]); | ||
| return null; | ||
| case "bigint": | ||
| meta.push(["bigint", ...segments]); | ||
| return data.toString(); | ||
| case "object": { | ||
| if (data === null) { | ||
| return data; | ||
| } | ||
| if (data instanceof Date) { | ||
| meta.push(["date", ...segments]); | ||
| return Number.isNaN(data.getTime()) ? null : data.toISOString(); | ||
| } | ||
| if (data instanceof URL) { | ||
| meta.push(["url", ...segments]); | ||
| return data.toString(); | ||
| } | ||
| if (data instanceof RegExp) { | ||
| meta.push(["regexp", ...segments]); | ||
| return data.toString(); | ||
| } | ||
| if (data instanceof Set) { | ||
| const result = this.serializeValue(Array.from(data), segments, meta, maps, blobs); | ||
| meta.push(["set", ...segments]); | ||
| return result; | ||
| } | ||
| if (data instanceof Map) { | ||
| const result = this.serializeValue(Array.from(data.entries()), segments, meta, maps, blobs); | ||
| meta.push(["map", ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| const handlerEntries = this.handlerEntries; | ||
| if (handlerEntries) { | ||
| for (let i = 0; i < handlerEntries.length; i++) { | ||
| const entry = handlerEntries[i]; | ||
| const handler = entry[1]; | ||
| if (handler.condition(data)) { | ||
| const serialized = handler.serialize(data); | ||
| if (handler.isTerminal) { | ||
| meta.push([entry[0], ...segments]); | ||
| if (serialized instanceof Blob) { | ||
| maps.push(segments.slice()); | ||
| blobs.push(serialized); | ||
| } | ||
| return serialized; | ||
| } | ||
| const result = this.serializeValue(serialized, segments, meta, maps, blobs); | ||
| meta.push([entry[0], ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
| if (data instanceof Blob) { | ||
| maps.push(segments.slice()); | ||
| blobs.push(data); | ||
| return data; | ||
| } | ||
| if (Array.isArray(data)) { | ||
| const json = []; | ||
| for (let i = 0; i < data.length; i++) { | ||
| segments.push(i); | ||
| json.push(this.serializeValue(data[i], segments, meta, maps, blobs)); | ||
| segments.pop(); | ||
| } | ||
| return json; | ||
| } | ||
| if (isPlainObject(data)) { | ||
| const json = new NullProtoObj(); | ||
| for (const k in data) { | ||
| const v = data[k]; | ||
| if (k === "toJSON" && typeof v === "function") { | ||
| continue; | ||
| } | ||
| if (v === void 0 && this.omitUndefinedProperties) { | ||
| continue; | ||
| } | ||
| segments.push(k); | ||
| json[k] = this.serializeValue(v, segments, meta, maps, blobs); | ||
| segments.pop(); | ||
| } | ||
| return json; | ||
| } | ||
| return data; | ||
| } | ||
| deserialize(serialized) { | ||
| const ref = { data: serialized.json }; | ||
| if (serialized.blobs?.length) { | ||
| for (let i = 0; i < serialized.maps.length; i++) { | ||
| const segments = serialized.maps[i]; | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| for (let j = 0; j < segments.length; j++) { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = segments[j]; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: Invalid serialized data. Segment "${preSegment}" does not exist.`); | ||
| } | ||
| } | ||
| currentRef[preSegment] = serialized.blobs[i]; | ||
| } | ||
| } | ||
| if (serialized.meta) { | ||
| for (const item of serialized.meta) { | ||
| const type = item[0]; | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| for (let i = 1; i < item.length; i++) { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = item[i]; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: Invalid serialized data. Segment "${preSegment}" does not exist.`); | ||
| } | ||
| } | ||
| currentRef[preSegment] = this.handlers[type].deserialize(currentRef[preSegment]); | ||
| } | ||
| } | ||
| return ref.data; | ||
| } | ||
| } | ||
| class RPCSerializer { | ||
| jsonSerializer; | ||
| defaultSerializeOptions; | ||
| constructor(options = {}) { | ||
| this.jsonSerializer = new RPCJsonSerializer(options); | ||
| this.defaultSerializeOptions = options.serialize; | ||
| } | ||
| serialize(data, options = {}) { | ||
| if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) { | ||
| return data; | ||
| } | ||
| if (isAsyncIteratorObject(data)) { | ||
| return wrapAsyncIteratorPreservingEventMeta(data, { | ||
| mapResult: (result) => { | ||
| if (result.value === void 0) { | ||
| return result; | ||
| } | ||
| return { done: result.done, value: this.serializeValue(result.value, false) }; | ||
| }, | ||
| mapError: (e) => new ErrorEvent( | ||
| this.serializeValue(toORPCError(e).toJSON(), false), | ||
| { cause: e } | ||
| ) | ||
| }); | ||
| } | ||
| const useFormDataForBlobs = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true; | ||
| return this.serializeValue(data, useFormDataForBlobs); | ||
| } | ||
| serializeValue(data, useFormDataForBlobs) { | ||
| const { json, meta, maps, blobs } = this.jsonSerializer.serialize(data); | ||
| if (!useFormDataForBlobs || !blobs?.length) { | ||
| return { json, meta }; | ||
| } | ||
| const form = new FormData(); | ||
| form.set("data", stringifyJSON({ json, meta, maps })); | ||
| blobs.forEach((blob, i) => { | ||
| form.set(i.toString(), blob); | ||
| }); | ||
| return form; | ||
| } | ||
| deserialize(data) { | ||
| if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) { | ||
| return data; | ||
| } | ||
| if (isAsyncIteratorObject(data)) { | ||
| return wrapAsyncIteratorPreservingEventMeta(data, { | ||
| mapResult: (result) => { | ||
| if (result.value === void 0) { | ||
| return result; | ||
| } | ||
| return { done: result.done, value: this.deserializeValue(result.value) }; | ||
| }, | ||
| mapError: (e) => { | ||
| if (!(e instanceof ErrorEvent)) { | ||
| return e; | ||
| } | ||
| const deserialized = this.deserializeValue(e.data); | ||
| if (isORPCErrorJson(deserialized)) { | ||
| return createORPCErrorFromJson(deserialized, { cause: e }); | ||
| } | ||
| return new ErrorEvent(deserialized, { cause: e }); | ||
| } | ||
| }); | ||
| } | ||
| return this.deserializeValue(data); | ||
| } | ||
| deserializeValue(data) { | ||
| if (!(data instanceof FormData)) { | ||
| return this.jsonSerializer.deserialize(data); | ||
| } | ||
| const serialized = JSON.parse(data.get("data")); | ||
| const blobs = []; | ||
| for (const [key, value] of data) { | ||
| if (value instanceof Blob) { | ||
| blobs[Number(key)] = value; | ||
| } | ||
| } | ||
| return this.jsonSerializer.deserialize({ ...serialized, blobs }); | ||
| } | ||
| } | ||
| export { RPCSerializer as R, isInferableError as a, RPCJsonSerializer as b, createORPCErrorFromJson as c, cloneORPCError as d, isORPCErrorJson as i, toORPCError as t, wrapAsyncIteratorPreservingEventMeta as w }; |
| import { resolveMaybeOptionalOptions, getConstructors } from '@orpc/shared'; | ||
| const COMMON_ERROR_STATUS_MAP = { | ||
| BAD_REQUEST: 400, | ||
| UNAUTHORIZED: 401, | ||
| PAYMENT_REQUIRED: 402, | ||
| FORBIDDEN: 403, | ||
| NOT_FOUND: 404, | ||
| METHOD_NOT_SUPPORTED: 405, | ||
| NOT_ACCEPTABLE: 406, | ||
| TIMEOUT: 408, | ||
| CONFLICT: 409, | ||
| GONE: 410, | ||
| PRECONDITION_FAILED: 412, | ||
| PAYLOAD_TOO_LARGE: 413, | ||
| UNSUPPORTED_MEDIA_TYPE: 415, | ||
| UNPROCESSABLE_CONTENT: 422, | ||
| PRECONDITION_REQUIRED: 428, | ||
| TOO_MANY_REQUESTS: 429, | ||
| CLIENT_CLOSED_REQUEST: 499, | ||
| INTERNAL_SERVER_ERROR: 500, | ||
| NOT_IMPLEMENTED: 501, | ||
| BAD_GATEWAY: 502, | ||
| SERVICE_UNAVAILABLE: 503, | ||
| GATEWAY_TIMEOUT: 504 | ||
| }; | ||
| let ORPCErrorConstructors; | ||
| class ORPCError extends Error { | ||
| static { | ||
| const ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for("ORPC_ERROR_CONSTRUCTORS"); | ||
| void (globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet()); | ||
| ORPCErrorConstructors = globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL]; | ||
| ORPCErrorConstructors.add(ORPCError); | ||
| } | ||
| /** | ||
| * @remarks | ||
| * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish | ||
| * an `ORPCError` instance from plain objects with a similar structure. | ||
| */ | ||
| name = "ORPCError"; | ||
| /** | ||
| * Indicates whether the error matches a definition in the procedure's `.errors` map. | ||
| */ | ||
| defined = false; | ||
| /** | ||
| * Indicates whether the error's type is inferable at the TypeScript level. | ||
| * This is typically true when the error is explicitly defined or returned within a handler. | ||
| */ | ||
| inferable = false; | ||
| code; | ||
| data; | ||
| constructor(code, ...rest) { | ||
| const options = resolveMaybeOptionalOptions(rest); | ||
| const message = options.message ?? code.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" "); | ||
| super(message, options); | ||
| this.code = code; | ||
| this.data = options.data; | ||
| } | ||
| toJSON() { | ||
| return { | ||
| defined: this.defined, | ||
| inferable: this.inferable, | ||
| code: this.code, | ||
| message: this.message, | ||
| data: this.data | ||
| }; | ||
| } | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance) { | ||
| if (!ORPCErrorConstructors.has(this)) { | ||
| return super[Symbol.hasInstance](instance); | ||
| } | ||
| for (const constructor of getConstructors(instance)) { | ||
| if (ORPCErrorConstructors.has(constructor)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| export { COMMON_ERROR_STATUS_MAP as C, ORPCError as O }; |
| import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared'; | ||
| interface ClientContext { | ||
| [key: PropertyKey]: any; | ||
| } | ||
| interface ClientOptions<T extends ClientContext> { | ||
| signal?: AbortSignal | undefined; | ||
| lastEventId?: string | undefined; | ||
| context: T; | ||
| } | ||
| type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? { | ||
| context?: T; | ||
| } : { | ||
| context: T; | ||
| }); | ||
| type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>]; | ||
| interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> { | ||
| (...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>; | ||
| } | ||
| type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | { | ||
| [k: string]: NestedClient<TClientContext>; | ||
| }; | ||
| type AnyNestedClient = NestedClient<any>; | ||
| /** | ||
| * Infers the **client context type** required by a client. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-context | Client-Side Clients - Infer Client Context} | ||
| */ | ||
| type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never; | ||
| interface ClientLink<TClientContext extends ClientContext> { | ||
| call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>; | ||
| } | ||
| /** | ||
| * Recursively infers the **input types** from a client. | ||
| * | ||
| * Produces a nested map where each endpoint's input type is preserved. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-inputs | Client-Side Clients - Infer Client Inputs} | ||
| */ | ||
| type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **body input types** from a client. | ||
| * | ||
| * If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted. | ||
| * Produces a nested map of body input types. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-body-inputs | Client-Side Clients - Infer Client Body Inputs} | ||
| */ | ||
| type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyInputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **output types** from a client. | ||
| * | ||
| * Produces a nested map where each endpoint's output type is preserved. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-outputs | Client-Side Clients - Infer Client Outputs} | ||
| */ | ||
| type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **body output types** from a client. | ||
| * | ||
| * If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted. | ||
| * Produces a nested map of body output types. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-body-outputs | Client-Side Clients - Infer Client Body Outputs} | ||
| */ | ||
| type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors). | ||
| * | ||
| * Produces a nested map where each endpoint's error type is preserved. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-errors | Client-Side Clients - Infer Client Errors} | ||
| */ | ||
| type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors). | ||
| * | ||
| * Useful when you want to handle all possible errors from any endpoint at once. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-error | Client-Side Clients - Infer Client Error} | ||
| */ | ||
| type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never; | ||
| }[keyof T]; | ||
| /** | ||
| * Default mapping between common oRPC error codes and HTTP status codes. | ||
| * Handlers use it to determine response status codes; spread it to build a custom `errorStatusMap`. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/rpc/handler#custom-error-response | RPC Handler - Custom Error Response} | ||
| * @see {@link https://orpc.dev/docs/openapi/handler#custom-error-response | OpenAPI Handler - Custom Error Response} | ||
| */ | ||
| declare const COMMON_ERROR_STATUS_MAP: { | ||
| BAD_REQUEST: number; | ||
| UNAUTHORIZED: number; | ||
| PAYMENT_REQUIRED: number; | ||
| FORBIDDEN: number; | ||
| NOT_FOUND: number; | ||
| METHOD_NOT_SUPPORTED: number; | ||
| NOT_ACCEPTABLE: number; | ||
| TIMEOUT: number; | ||
| CONFLICT: number; | ||
| GONE: number; | ||
| PRECONDITION_FAILED: number; | ||
| PAYLOAD_TOO_LARGE: number; | ||
| UNSUPPORTED_MEDIA_TYPE: number; | ||
| UNPROCESSABLE_CONTENT: number; | ||
| PRECONDITION_REQUIRED: number; | ||
| TOO_MANY_REQUESTS: number; | ||
| CLIENT_CLOSED_REQUEST: number; | ||
| INTERNAL_SERVER_ERROR: number; | ||
| NOT_IMPLEMENTED: number; | ||
| BAD_GATEWAY: number; | ||
| SERVICE_UNAVAILABLE: number; | ||
| GATEWAY_TIMEOUT: number; | ||
| }; | ||
| type ORPCErrorCode = Registry extends { | ||
| ORPCErrorCode: infer T extends string; | ||
| } ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {}); | ||
| type ORPCErrorOptions<TData> = ErrorOptions & { | ||
| message?: string; | ||
| } & (undefined extends TData ? { | ||
| data?: TData; | ||
| } : { | ||
| data: TData; | ||
| }); | ||
| /** | ||
| * Typed error carrying a `code`, a `message`, and optional `data`. | ||
| * Throw it from handlers or middleware to produce typed error responses on the client. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/error-handling#orpcerror-class | Error Handling - ORPCError Class} | ||
| */ | ||
| declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error { | ||
| /** | ||
| * @remarks | ||
| * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish | ||
| * an `ORPCError` instance from plain objects with a similar structure. | ||
| */ | ||
| readonly name: "ORPCError" & { | ||
| __branch: "ORPCError"; | ||
| }; | ||
| /** | ||
| * Indicates whether the error matches a definition in the procedure's `.errors` map. | ||
| */ | ||
| readonly defined: boolean; | ||
| /** | ||
| * Indicates whether the error's type is inferable at the TypeScript level. | ||
| * This is typically true when the error is explicitly defined or returned within a handler. | ||
| */ | ||
| readonly inferable: boolean; | ||
| code: TCode; | ||
| data: TData; | ||
| constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>); | ||
| toJSON(): ORPCErrorJSON<TCode, TData>; | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance: unknown): boolean; | ||
| } | ||
| interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> { | ||
| /** | ||
| * remove readonly | ||
| */ | ||
| defined: boolean; | ||
| /** | ||
| * remove readonly | ||
| */ | ||
| inferable: boolean; | ||
| } | ||
| type AnyORPCError = ORPCError<any, any>; | ||
| type AnyORPCErrorJSON = ORPCErrorJSON<any, any>; | ||
| export { ORPCError as g, COMMON_ERROR_STATUS_MAP as j }; | ||
| export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, AnyNestedClient as c, InferClientError as d, Client as e, ClientRest as f, ORPCErrorJSON as h, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as p }; |
| import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared'; | ||
| interface ClientContext { | ||
| [key: PropertyKey]: any; | ||
| } | ||
| interface ClientOptions<T extends ClientContext> { | ||
| signal?: AbortSignal | undefined; | ||
| lastEventId?: string | undefined; | ||
| context: T; | ||
| } | ||
| type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? { | ||
| context?: T; | ||
| } : { | ||
| context: T; | ||
| }); | ||
| type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>]; | ||
| interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> { | ||
| (...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>; | ||
| } | ||
| type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | { | ||
| [k: string]: NestedClient<TClientContext>; | ||
| }; | ||
| type AnyNestedClient = NestedClient<any>; | ||
| /** | ||
| * Infers the **client context type** required by a client. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-context | Client-Side Clients - Infer Client Context} | ||
| */ | ||
| type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never; | ||
| interface ClientLink<TClientContext extends ClientContext> { | ||
| call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>; | ||
| } | ||
| /** | ||
| * Recursively infers the **input types** from a client. | ||
| * | ||
| * Produces a nested map where each endpoint's input type is preserved. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-inputs | Client-Side Clients - Infer Client Inputs} | ||
| */ | ||
| type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **body input types** from a client. | ||
| * | ||
| * If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted. | ||
| * Produces a nested map of body input types. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-body-inputs | Client-Side Clients - Infer Client Body Inputs} | ||
| */ | ||
| type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyInputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **output types** from a client. | ||
| * | ||
| * Produces a nested map where each endpoint's output type is preserved. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-outputs | Client-Side Clients - Infer Client Outputs} | ||
| */ | ||
| type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **body output types** from a client. | ||
| * | ||
| * If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted. | ||
| * Produces a nested map of body output types. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-body-outputs | Client-Side Clients - Infer Client Body Outputs} | ||
| */ | ||
| type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors). | ||
| * | ||
| * Produces a nested map where each endpoint's error type is preserved. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-errors | Client-Side Clients - Infer Client Errors} | ||
| */ | ||
| type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors). | ||
| * | ||
| * Useful when you want to handle all possible errors from any endpoint at once. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side#infer-client-error | Client-Side Clients - Infer Client Error} | ||
| */ | ||
| type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never; | ||
| }[keyof T]; | ||
| /** | ||
| * Default mapping between common oRPC error codes and HTTP status codes. | ||
| * Handlers use it to determine response status codes; spread it to build a custom `errorStatusMap`. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/rpc/handler#custom-error-response | RPC Handler - Custom Error Response} | ||
| * @see {@link https://orpc.dev/docs/openapi/handler#custom-error-response | OpenAPI Handler - Custom Error Response} | ||
| */ | ||
| declare const COMMON_ERROR_STATUS_MAP: { | ||
| BAD_REQUEST: number; | ||
| UNAUTHORIZED: number; | ||
| PAYMENT_REQUIRED: number; | ||
| FORBIDDEN: number; | ||
| NOT_FOUND: number; | ||
| METHOD_NOT_SUPPORTED: number; | ||
| NOT_ACCEPTABLE: number; | ||
| TIMEOUT: number; | ||
| CONFLICT: number; | ||
| GONE: number; | ||
| PRECONDITION_FAILED: number; | ||
| PAYLOAD_TOO_LARGE: number; | ||
| UNSUPPORTED_MEDIA_TYPE: number; | ||
| UNPROCESSABLE_CONTENT: number; | ||
| PRECONDITION_REQUIRED: number; | ||
| TOO_MANY_REQUESTS: number; | ||
| CLIENT_CLOSED_REQUEST: number; | ||
| INTERNAL_SERVER_ERROR: number; | ||
| NOT_IMPLEMENTED: number; | ||
| BAD_GATEWAY: number; | ||
| SERVICE_UNAVAILABLE: number; | ||
| GATEWAY_TIMEOUT: number; | ||
| }; | ||
| type ORPCErrorCode = Registry extends { | ||
| ORPCErrorCode: infer T extends string; | ||
| } ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {}); | ||
| type ORPCErrorOptions<TData> = ErrorOptions & { | ||
| message?: string; | ||
| } & (undefined extends TData ? { | ||
| data?: TData; | ||
| } : { | ||
| data: TData; | ||
| }); | ||
| /** | ||
| * Typed error carrying a `code`, a `message`, and optional `data`. | ||
| * Throw it from handlers or middleware to produce typed error responses on the client. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/error-handling#orpcerror-class | Error Handling - ORPCError Class} | ||
| */ | ||
| declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error { | ||
| /** | ||
| * @remarks | ||
| * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish | ||
| * an `ORPCError` instance from plain objects with a similar structure. | ||
| */ | ||
| readonly name: "ORPCError" & { | ||
| __branch: "ORPCError"; | ||
| }; | ||
| /** | ||
| * Indicates whether the error matches a definition in the procedure's `.errors` map. | ||
| */ | ||
| readonly defined: boolean; | ||
| /** | ||
| * Indicates whether the error's type is inferable at the TypeScript level. | ||
| * This is typically true when the error is explicitly defined or returned within a handler. | ||
| */ | ||
| readonly inferable: boolean; | ||
| code: TCode; | ||
| data: TData; | ||
| constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>); | ||
| toJSON(): ORPCErrorJSON<TCode, TData>; | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance: unknown): boolean; | ||
| } | ||
| interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> { | ||
| /** | ||
| * remove readonly | ||
| */ | ||
| defined: boolean; | ||
| /** | ||
| * remove readonly | ||
| */ | ||
| inferable: boolean; | ||
| } | ||
| type AnyORPCError = ORPCError<any, any>; | ||
| type AnyORPCErrorJSON = ORPCErrorJSON<any, any>; | ||
| export { ORPCError as g, COMMON_ERROR_STATUS_MAP as j }; | ||
| export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, AnyNestedClient as c, InferClientError as d, Client as e, ClientRest as f, ORPCErrorJSON as h, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as p }; |
@@ -1,8 +0,8 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.mjs'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.EMUKnkap.mjs'; | ||
| import { Value, Promisable, Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { ToFetchBodyOptions } from '@standardserver/fetch'; | ||
| import { S as StandardLinkTransport, c as StandardLinkPlugin, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.8f4DNmdE.mjs'; | ||
| import { S as StandardLinkTransport, c as StandardLinkPlugin, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BpRn9TAI.mjs'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.mjs'; | ||
| import '../../shared/client.Dlxz9Qw5.mjs'; | ||
| import '../../shared/client.B8tCfDzm.mjs'; | ||
@@ -60,2 +60,7 @@ interface FetchLinkTransportFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| } | ||
| /** | ||
| * Client link that communicates with an RPC Handler over the Fetch API (HTTP). | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter} | ||
| */ | ||
| declare class RPCLink<T extends ClientContext> extends StandardLink<T> { | ||
@@ -62,0 +67,0 @@ constructor(options: RPCLinkOptions<T>); |
@@ -1,8 +0,8 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.js'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.EMUKnkap.js'; | ||
| import { Value, Promisable, Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { ToFetchBodyOptions } from '@standardserver/fetch'; | ||
| import { S as StandardLinkTransport, c as StandardLinkPlugin, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BMKYqpdy.js'; | ||
| import { S as StandardLinkTransport, c as StandardLinkPlugin, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BGShxYPR.js'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.js'; | ||
| import '../../shared/client.Dlxz9Qw5.js'; | ||
| import '../../shared/client.B8tCfDzm.js'; | ||
@@ -60,2 +60,7 @@ interface FetchLinkTransportFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| } | ||
| /** | ||
| * Client link that communicates with an RPC Handler over the Fetch API (HTTP). | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter} | ||
| */ | ||
| declare class RPCLink<T extends ClientContext> extends StandardLink<T> { | ||
@@ -62,0 +67,0 @@ constructor(options: RPCLinkOptions<T>); |
| import { sortPlugins, value, intercept, once } from '@orpc/shared'; | ||
| import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standardserver/fetch'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.Bl4junIW.mjs'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.B6ItE3bt.mjs'; | ||
| import '@standardserver/core'; | ||
| import '../../shared/client.Dnfj8jnT.mjs'; | ||
| import '../../shared/client.DQpq_Sdn.mjs'; | ||
| import '../../shared/client.CPcOxSex.mjs'; | ||
| import '../../shared/client.BZMJyvQd.mjs'; | ||
@@ -13,3 +13,3 @@ class CompositeFetchLinkTransportPlugin { | ||
| } | ||
| name = "~composite/fetch-link-transport"; | ||
| name = "~composite/fetch"; | ||
| initFetchLinkTransportOptions(options) { | ||
@@ -16,0 +16,0 @@ for (const plugin of this.plugins) { |
@@ -1,8 +0,8 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.mjs'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.EMUKnkap.mjs'; | ||
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.8f4DNmdE.mjs'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BpRn9TAI.mjs'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.mjs'; | ||
| import '../../shared/client.Dlxz9Qw5.mjs'; | ||
| import '../../shared/client.B8tCfDzm.mjs'; | ||
@@ -48,5 +48,4 @@ /** | ||
| * @remarks | ||
| * - return null | undefined to disable this feature | ||
| * | ||
| * @warning Make sure your message port supports `transfer` before using this feature. | ||
| * **Note**: Returning `null` or `undefined` disables this feature. | ||
| * **Warning**: Make sure your message port supports `transfer` before using this feature. | ||
| */ | ||
@@ -71,2 +70,8 @@ experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>; | ||
| } | ||
| /** | ||
| * Client link that communicates with an RPC Handler over a Message Port | ||
| * (e.g. workers, iframes, browser extensions, Electron). | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter} | ||
| */ | ||
| declare class RPCLink<T extends ClientContext> extends StandardLink<T> { | ||
@@ -73,0 +78,0 @@ constructor(options: RPCLinkOptions<T>); |
@@ -1,8 +0,8 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.js'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.EMUKnkap.js'; | ||
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BMKYqpdy.js'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BGShxYPR.js'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.js'; | ||
| import '../../shared/client.Dlxz9Qw5.js'; | ||
| import '../../shared/client.B8tCfDzm.js'; | ||
@@ -48,5 +48,4 @@ /** | ||
| * @remarks | ||
| * - return null | undefined to disable this feature | ||
| * | ||
| * @warning Make sure your message port supports `transfer` before using this feature. | ||
| * **Note**: Returning `null` or `undefined` disables this feature. | ||
| * **Warning**: Make sure your message port supports `transfer` before using this feature. | ||
| */ | ||
@@ -71,2 +70,8 @@ experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>; | ||
| } | ||
| /** | ||
| * Client link that communicates with an RPC Handler over a Message Port | ||
| * (e.g. workers, iframes, browser extensions, Electron). | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter} | ||
| */ | ||
| declare class RPCLink<T extends ClientContext> extends StandardLink<T> { | ||
@@ -73,0 +78,0 @@ constructor(options: RPCLinkOptions<T>); |
| import { value } from '@orpc/shared'; | ||
| import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage, isPeerMessage } from '@standardserver/peer'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.Bl4junIW.mjs'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.B6ItE3bt.mjs'; | ||
| import '@standardserver/core'; | ||
| import '@standardserver/fetch'; | ||
| import '../../shared/client.Dnfj8jnT.mjs'; | ||
| import '../../shared/client.DQpq_Sdn.mjs'; | ||
| import '../../shared/client.CPcOxSex.mjs'; | ||
| import '../../shared/client.BZMJyvQd.mjs'; | ||
@@ -9,0 +9,0 @@ function postMessagePortMessage(port, data, transfer) { |
@@ -1,8 +0,8 @@ | ||
| import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.8f4DNmdE.mjs'; | ||
| export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.8f4DNmdE.mjs'; | ||
| import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.BpRn9TAI.mjs'; | ||
| export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.BpRn9TAI.mjs'; | ||
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.mjs'; | ||
| import { e as RPCSerializer } from '../../shared/client.Dlxz9Qw5.mjs'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.EMUKnkap.mjs'; | ||
| import { e as RPCSerializer } from '../../shared/client.B8tCfDzm.mjs'; | ||
@@ -9,0 +9,0 @@ interface RPCLinkCodecOptions<T extends ClientContext> { |
@@ -1,8 +0,8 @@ | ||
| import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.BMKYqpdy.js'; | ||
| export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.BMKYqpdy.js'; | ||
| import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.BGShxYPR.js'; | ||
| export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.BGShxYPR.js'; | ||
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.js'; | ||
| import { e as RPCSerializer } from '../../shared/client.Dlxz9Qw5.js'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.EMUKnkap.js'; | ||
| import { e as RPCSerializer } from '../../shared/client.B8tCfDzm.js'; | ||
@@ -9,0 +9,0 @@ interface RPCLinkCodecOptions<T extends ClientContext> { |
@@ -1,6 +0,6 @@ | ||
| export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.Bl4junIW.mjs'; | ||
| export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.B6ItE3bt.mjs'; | ||
| import '@orpc/shared'; | ||
| import '@standardserver/core'; | ||
| import '@standardserver/fetch'; | ||
| import '../../shared/client.Dnfj8jnT.mjs'; | ||
| import '../../shared/client.DQpq_Sdn.mjs'; | ||
| import '../../shared/client.CPcOxSex.mjs'; | ||
| import '../../shared/client.BZMJyvQd.mjs'; |
@@ -1,8 +0,8 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.mjs'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.EMUKnkap.mjs'; | ||
| import { Promisable } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.8f4DNmdE.mjs'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BpRn9TAI.mjs'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.mjs'; | ||
| import '../../shared/client.Dlxz9Qw5.mjs'; | ||
| import '../../shared/client.B8tCfDzm.mjs'; | ||
@@ -116,2 +116,7 @@ type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>; | ||
| } | ||
| /** | ||
| * Client link that communicates with an RPC Handler over a WebSocket connection. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters} | ||
| */ | ||
| declare class RPCLink<T extends ClientContext> extends StandardLink<T> { | ||
@@ -118,0 +123,0 @@ constructor(options: RPCLinkOptions<T>); |
@@ -1,8 +0,8 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.js'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.EMUKnkap.js'; | ||
| import { Promisable } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BMKYqpdy.js'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BGShxYPR.js'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.js'; | ||
| import '../../shared/client.Dlxz9Qw5.js'; | ||
| import '../../shared/client.B8tCfDzm.js'; | ||
@@ -116,2 +116,7 @@ type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>; | ||
| } | ||
| /** | ||
| * Client link that communicates with an RPC Handler over a WebSocket connection. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters} | ||
| */ | ||
| declare class RPCLink<T extends ClientContext> extends StandardLink<T> { | ||
@@ -118,0 +123,0 @@ constructor(options: RPCLinkOptions<T>); |
| import { runWithSignal, AbortError, sleep, promiseWithResolvers, sequential, loadBytes, toStringOrBytes } from '@orpc/shared'; | ||
| import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage } from '@standardserver/peer'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.Bl4junIW.mjs'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.B6ItE3bt.mjs'; | ||
| import '@standardserver/core'; | ||
| import '@standardserver/fetch'; | ||
| import '../../shared/client.Dnfj8jnT.mjs'; | ||
| import '../../shared/client.DQpq_Sdn.mjs'; | ||
| import '../../shared/client.CPcOxSex.mjs'; | ||
| import '../../shared/client.BZMJyvQd.mjs'; | ||
@@ -9,0 +9,0 @@ const WEBSOCKET_CONNECTING = 0; |
+23
-7
| import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared'; | ||
| export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared'; | ||
| import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, F as FriendlyClientOptions, O as ORPCErrorCode, g as ORPCError, h as ORPCErrorJSON } from './shared/client.BBZBQID8.mjs'; | ||
| export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, N as NestedClient, p as ORPCErrorOptions } from './shared/client.BBZBQID8.mjs'; | ||
| export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.Dlxz9Qw5.mjs'; | ||
| export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, PromiseWithError as ClientPromiseResult, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared'; | ||
| import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, F as FriendlyClientOptions, O as ORPCErrorCode, g as ORPCError, h as ORPCErrorJSON } from './shared/client.EMUKnkap.mjs'; | ||
| export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, N as NestedClient, p as ORPCErrorOptions } from './shared/client.EMUKnkap.mjs'; | ||
| export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.B8tCfDzm.mjs'; | ||
| export { ErrorEvent, EventMeta, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core'; | ||
@@ -40,2 +40,9 @@ | ||
| } | ||
| /** | ||
| * Creates a fully typed oRPC client from a link. | ||
| * The returned client mirrors the shape of your router or contract, | ||
| * so calling a procedure is as simple as calling a function. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side | Client-Side Clients} | ||
| */ | ||
| declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T; | ||
@@ -72,2 +79,5 @@ | ||
| * } | ||
| * ``` | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isinferableerror | Client Error Handling - Using safe and isInferableError} | ||
| */ | ||
@@ -89,3 +99,3 @@ declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>; | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs} | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#safe-client | Client Error Handling - Safe Client} | ||
| */ | ||
@@ -109,3 +119,3 @@ declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeClient<T>; | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/dynamic-link Dynamic Link Docs} | ||
| * @see {@link https://orpc.dev/docs/client/dynamic-link | DynamicLink} | ||
| */ | ||
@@ -118,2 +128,8 @@ declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> { | ||
| /** | ||
| * Checks if an error is an `ORPCError` whose type is inferable at the TypeScript level, | ||
| * narrowing it so `code` and `data` are fully typed. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isinferableerror | Client Error Handling - Using safe and isInferableError} | ||
| */ | ||
| declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>; | ||
@@ -125,3 +141,3 @@ declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>; | ||
| export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isInferableError as isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta }; | ||
| export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, InferClientError as InferClientErrorUnion, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isInferableError as isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta }; | ||
| export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult }; |
+23
-7
| import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared'; | ||
| export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared'; | ||
| import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, F as FriendlyClientOptions, O as ORPCErrorCode, g as ORPCError, h as ORPCErrorJSON } from './shared/client.BBZBQID8.js'; | ||
| export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, N as NestedClient, p as ORPCErrorOptions } from './shared/client.BBZBQID8.js'; | ||
| export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.Dlxz9Qw5.js'; | ||
| export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, PromiseWithError as ClientPromiseResult, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared'; | ||
| import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, F as FriendlyClientOptions, O as ORPCErrorCode, g as ORPCError, h as ORPCErrorJSON } from './shared/client.EMUKnkap.js'; | ||
| export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, N as NestedClient, p as ORPCErrorOptions } from './shared/client.EMUKnkap.js'; | ||
| export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.B8tCfDzm.js'; | ||
| export { ErrorEvent, EventMeta, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core'; | ||
@@ -40,2 +40,9 @@ | ||
| } | ||
| /** | ||
| * Creates a fully typed oRPC client from a link. | ||
| * The returned client mirrors the shape of your router or contract, | ||
| * so calling a procedure is as simple as calling a function. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/client-side | Client-Side Clients} | ||
| */ | ||
| declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T; | ||
@@ -72,2 +79,5 @@ | ||
| * } | ||
| * ``` | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isinferableerror | Client Error Handling - Using safe and isInferableError} | ||
| */ | ||
@@ -89,3 +99,3 @@ declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>; | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs} | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#safe-client | Client Error Handling - Safe Client} | ||
| */ | ||
@@ -109,3 +119,3 @@ declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeClient<T>; | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/dynamic-link Dynamic Link Docs} | ||
| * @see {@link https://orpc.dev/docs/client/dynamic-link | DynamicLink} | ||
| */ | ||
@@ -118,2 +128,8 @@ declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> { | ||
| /** | ||
| * Checks if an error is an `ORPCError` whose type is inferable at the TypeScript level, | ||
| * narrowing it so `code` and `data` are fully typed. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isinferableerror | Client Error Handling - Using safe and isInferableError} | ||
| */ | ||
| declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>; | ||
@@ -125,3 +141,3 @@ declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>; | ||
| export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isInferableError as isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta }; | ||
| export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, InferClientError as InferClientErrorUnion, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isInferableError as isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta }; | ||
| export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult }; |
+30
-16
@@ -1,6 +0,6 @@ | ||
| import { a as isInferableError } from './shared/client.DQpq_Sdn.mjs'; | ||
| export { b as RPCJsonSerializer, R as RPCSerializer, d as cloneORPCError, c as createORPCErrorFromJson, i as isORPCErrorJson, t as toORPCError, w as wrapAsyncIteratorPreservingEventMeta } from './shared/client.DQpq_Sdn.mjs'; | ||
| import { getOrBind, toArray, intercept, isTypescriptObject } from '@orpc/shared'; | ||
| import { a as isInferableError } from './shared/client.BZMJyvQd.mjs'; | ||
| export { b as RPCJsonSerializer, R as RPCSerializer, d as cloneORPCError, c as createORPCErrorFromJson, i as isORPCErrorJson, t as toORPCError, w as wrapAsyncIteratorPreservingEventMeta } from './shared/client.BZMJyvQd.mjs'; | ||
| import { toArray, intercept, isTypescriptObject } from '@orpc/shared'; | ||
| export { AsyncIteratorClass, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared'; | ||
| export { C as COMMON_ERROR_STATUS_MAP, O as ORPCError } from './shared/client.Dnfj8jnT.mjs'; | ||
| export { C as COMMON_ERROR_STATUS_MAP, O as ORPCError } from './shared/client.CPcOxSex.mjs'; | ||
| export { ErrorEvent, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core'; | ||
@@ -83,13 +83,18 @@ | ||
| }; | ||
| const cache = /* @__PURE__ */ new Map(); | ||
| const recursive = new Proxy(procedureClient, { | ||
| get(target, key) { | ||
| if (typeof key !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) { | ||
| return getOrBind(target, key); | ||
| return Reflect.get(target, key); | ||
| } | ||
| const scoped = options.scoped === void 0 ? void 0 : options.scoped[key]; | ||
| return createORPCClient(link, { | ||
| ...options, | ||
| path: [...path, key], | ||
| scoped | ||
| }); | ||
| let client = cache.get(key); | ||
| if (client === void 0) { | ||
| client = createORPCClient(link, { | ||
| ...options, | ||
| path: [...path, key], | ||
| scoped: options.scoped?.[key] | ||
| }); | ||
| cache.set(key, client); | ||
| } | ||
| return client; | ||
| } | ||
@@ -101,9 +106,18 @@ }); | ||
| function createSafeClient(client) { | ||
| const cache = /* @__PURE__ */ new Map(); | ||
| const proxy = new Proxy((...args) => safe(client(...args)), { | ||
| get(_, prop) { | ||
| const value = getOrBind(client, prop); | ||
| if (!isTypescriptObject(value)) { | ||
| return value; | ||
| get(target, prop) { | ||
| if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) { | ||
| return Reflect.get(target, prop); | ||
| } | ||
| return createSafeClient(value); | ||
| let safeClient = cache.get(prop); | ||
| if (safeClient === void 0) { | ||
| const value = client[prop]; | ||
| if (!isTypescriptObject(value)) { | ||
| return value; | ||
| } | ||
| safeClient = createSafeClient(value); | ||
| cache.set(prop, safeClient); | ||
| } | ||
| return safeClient; | ||
| } | ||
@@ -110,0 +124,0 @@ }); |
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { C as ClientContext } from '../shared/client.BBZBQID8.mjs'; | ||
| import { c as StandardLinkPlugin, d as StandardLinkTransportInterceptorOptions, b as StandardLinkOptions, e as StandardLinkInterceptorOptions } from '../shared/client.8f4DNmdE.mjs'; | ||
| import { C as ClientContext } from '../shared/client.EMUKnkap.mjs'; | ||
| import { c as StandardLinkPlugin, d as StandardLinkTransportInterceptorOptions, b as StandardLinkOptions, e as StandardLinkInterceptorOptions } from '../shared/client.BpRn9TAI.mjs'; | ||
@@ -82,2 +82,11 @@ type BatchLinkPluginMode = 'streaming' | 'buffered'; | ||
| } | ||
| /** | ||
| * Combines multiple client requests into a single batch request | ||
| * and splits the batch response back into individual responses. | ||
| * | ||
| * @remarks | ||
| * **Note**: HTTP/2 and later already multiplex requests over a single connection, so this plugin is often less useful than it once was. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin} | ||
| */ | ||
| declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -127,2 +136,8 @@ name: string; | ||
| } | ||
| /** | ||
| * Prevents redundant requests by deduplicating similar in-flight requests, | ||
| * reducing the number of requests sent to the server. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/dedupe | Dedupe Plugin} | ||
| */ | ||
| declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -157,2 +172,8 @@ name: string; | ||
| } | ||
| /** | ||
| * Compresses request bodies before sending them to the server, | ||
| * reducing bandwidth usage for large payloads. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin} | ||
| */ | ||
| declare class RequestCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -184,3 +205,3 @@ name: string; | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/response-compression Response Compression Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin} | ||
| */ | ||
@@ -212,2 +233,8 @@ declare class ResponseCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| } | ||
| /** | ||
| * Client context options that control retry behavior per call | ||
| * when the `RetryLinkPlugin` is enabled. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin} | ||
| */ | ||
| interface RetryLinkPluginContext { | ||
@@ -224,3 +251,5 @@ /** | ||
| * | ||
| * @info Why 2000ms? The EventSource spec suggests a default retry delay of 2 seconds if it doesn't specify | ||
| * @remarks | ||
| * **Note**: Why 2000ms? The EventSource spec suggests a default retry delay of 2 seconds if it doesn't specify | ||
| * | ||
| * @default (o) => o.lastEventRetry ?? 2000 | ||
@@ -246,2 +275,11 @@ */ | ||
| } | ||
| /** | ||
| * Automatically retries failed requests based on customizable retry strategies, | ||
| * improving the resilience of your application. | ||
| * | ||
| * @remarks | ||
| * **Note**: Retry behavior is configured through the client context on each call. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin} | ||
| */ | ||
| declare class RetryLinkPlugin<T extends RetryLinkPluginContext & ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -290,3 +328,3 @@ private readonly defaultRetry; | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/retry-after Retry After Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/retry-after | Retry After Plugin} | ||
| */ | ||
@@ -312,3 +350,3 @@ declare class RetryAfterLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/timeout Timeout Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin} | ||
| */ | ||
@@ -326,3 +364,3 @@ declare class TimeoutLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| export { BatchLinkPlugin, BatchLinkPluginError, DedupeLinkPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryLinkPlugin, TimeoutLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, TimeoutLinkPluginOptions }; | ||
| export { BatchLinkPlugin, BatchLinkPluginError, RetryLinkPlugin as ClientRetryPlugin, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, RetryLinkPluginContext as ClientRetryPluginContext, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, TimeoutLinkPluginOptions }; |
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { C as ClientContext } from '../shared/client.BBZBQID8.js'; | ||
| import { c as StandardLinkPlugin, d as StandardLinkTransportInterceptorOptions, b as StandardLinkOptions, e as StandardLinkInterceptorOptions } from '../shared/client.BMKYqpdy.js'; | ||
| import { C as ClientContext } from '../shared/client.EMUKnkap.js'; | ||
| import { c as StandardLinkPlugin, d as StandardLinkTransportInterceptorOptions, b as StandardLinkOptions, e as StandardLinkInterceptorOptions } from '../shared/client.BGShxYPR.js'; | ||
@@ -82,2 +82,11 @@ type BatchLinkPluginMode = 'streaming' | 'buffered'; | ||
| } | ||
| /** | ||
| * Combines multiple client requests into a single batch request | ||
| * and splits the batch response back into individual responses. | ||
| * | ||
| * @remarks | ||
| * **Note**: HTTP/2 and later already multiplex requests over a single connection, so this plugin is often less useful than it once was. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin} | ||
| */ | ||
| declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -127,2 +136,8 @@ name: string; | ||
| } | ||
| /** | ||
| * Prevents redundant requests by deduplicating similar in-flight requests, | ||
| * reducing the number of requests sent to the server. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/dedupe | Dedupe Plugin} | ||
| */ | ||
| declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -157,2 +172,8 @@ name: string; | ||
| } | ||
| /** | ||
| * Compresses request bodies before sending them to the server, | ||
| * reducing bandwidth usage for large payloads. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin} | ||
| */ | ||
| declare class RequestCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -184,3 +205,3 @@ name: string; | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/response-compression Response Compression Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin} | ||
| */ | ||
@@ -212,2 +233,8 @@ declare class ResponseCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| } | ||
| /** | ||
| * Client context options that control retry behavior per call | ||
| * when the `RetryLinkPlugin` is enabled. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin} | ||
| */ | ||
| interface RetryLinkPluginContext { | ||
@@ -224,3 +251,5 @@ /** | ||
| * | ||
| * @info Why 2000ms? The EventSource spec suggests a default retry delay of 2 seconds if it doesn't specify | ||
| * @remarks | ||
| * **Note**: Why 2000ms? The EventSource spec suggests a default retry delay of 2 seconds if it doesn't specify | ||
| * | ||
| * @default (o) => o.lastEventRetry ?? 2000 | ||
@@ -246,2 +275,11 @@ */ | ||
| } | ||
| /** | ||
| * Automatically retries failed requests based on customizable retry strategies, | ||
| * improving the resilience of your application. | ||
| * | ||
| * @remarks | ||
| * **Note**: Retry behavior is configured through the client context on each call. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin} | ||
| */ | ||
| declare class RetryLinkPlugin<T extends RetryLinkPluginContext & ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -290,3 +328,3 @@ private readonly defaultRetry; | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/retry-after Retry After Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/retry-after | Retry After Plugin} | ||
| */ | ||
@@ -312,3 +350,3 @@ declare class RetryAfterLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/timeout Timeout Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin} | ||
| */ | ||
@@ -326,3 +364,3 @@ declare class TimeoutLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| export { BatchLinkPlugin, BatchLinkPluginError, DedupeLinkPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryLinkPlugin, TimeoutLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, TimeoutLinkPluginOptions }; | ||
| export { BatchLinkPlugin, BatchLinkPluginError, RetryLinkPlugin as ClientRetryPlugin, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, RetryLinkPluginContext as ClientRetryPluginContext, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, TimeoutLinkPluginOptions }; |
@@ -5,3 +5,3 @@ import { toArray, value, splitInHalf, stringifyJSON, isAsyncIteratorObject, defer, loadBytes, allAbortSignal, replicateAsyncIterator, replicateReadableStream, isCompressibleContentType, override, AsyncIteratorClass, sleep, AbortError, anyAbortSignal } from '@orpc/shared'; | ||
| import { toFetchHeaders, toStandardBody } from '@standardserver/fetch'; | ||
| import { C as COMMON_ERROR_STATUS_MAP } from '../shared/client.Dnfj8jnT.mjs'; | ||
| import { C as COMMON_ERROR_STATUS_MAP } from '../shared/client.CPcOxSex.mjs'; | ||
@@ -832,2 +832,2 @@ class BatchLinkPluginError extends TypeError { | ||
| export { BatchLinkPlugin, BatchLinkPluginError, DedupeLinkPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryLinkPlugin, TimeoutLinkPlugin }; | ||
| export { BatchLinkPlugin, BatchLinkPluginError, RetryLinkPlugin as ClientRetryPlugin, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin }; |
+5
-5
| { | ||
| "name": "@orpc/client", | ||
| "type": "module", | ||
| "version": "2.0.0-beta.23", | ||
| "version": "2.0.0-beta.24", | ||
| "license": "MIT", | ||
@@ -53,6 +53,6 @@ "homepage": "https://orpc.dev", | ||
| "dependencies": { | ||
| "@standardserver/core": "^0.6.0", | ||
| "@standardserver/fetch": "^0.6.0", | ||
| "@standardserver/peer": "^0.6.0", | ||
| "@orpc/shared": "2.0.0-beta.23" | ||
| "@standardserver/core": "^0.7.1", | ||
| "@standardserver/fetch": "^0.7.1", | ||
| "@standardserver/peer": "^0.7.1", | ||
| "@orpc/shared": "2.0.0-beta.24" | ||
| }, | ||
@@ -59,0 +59,0 @@ "devDependencies": { |
+4
-1
@@ -47,2 +47,3 @@ <h1 align="center">oRPC - Typesafe APIs Made Simple 🪄</h1> | ||
| - [@orpc/ratelimit](https://www.npmjs.com/package/@orpc/ratelimit): Rate limiting with memory, Redis, and Upstash adapters. | ||
| - [@orpc/hibernation](https://www.npmjs.com/package/@orpc/hibernation): Leverage Hibernation APIs like [Cloudflare's Hibernation WebSocket](https://developers.cloudflare.com/durable-objects/best-practices/websockets/#durable-objects-hibernation-websocket-api). | ||
| - [@orpc/json-schema](https://www.npmjs.com/package/@orpc/json-schema): Smart coercion for OpenAPI requests. | ||
@@ -118,2 +119,3 @@ | ||
| <td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td> | ||
| <td align="center"><a href="https://github.com/ellis-driscoll?ref=orpc" target="_blank" rel="noopener" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="139" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td> | ||
| </tr> | ||
@@ -144,4 +146,5 @@ </table> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/guyariely?ref=orpc" target="_blank" rel="noopener" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&v=4" width="119" alt="Guy Ariely"/><br />Guy Ariely</a></td> | ||
| <td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td> | ||
| <td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=29e91400dbd4a9c217048a8f59562c4f740498e6&v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td> | ||
| <td align="center"><a href="https://github.com/finom?ref=orpc" target="_blank" rel="noopener" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&v=4" width="119" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td> | ||
| </tr> | ||
@@ -148,0 +151,0 @@ </table> |
| import { Promisable, OrderablePlugin, Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.BBZBQID8.mjs'; | ||
| type StandardLinkCodecDecodedResponse = { | ||
| kind: 'output'; | ||
| output: unknown; | ||
| } | { | ||
| kind: 'error'; | ||
| error: AnyORPCError; | ||
| }; | ||
| interface StandardLinkCodec<T extends ClientContext> { | ||
| encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promisable<StandardRequest>; | ||
| decodeResponse(response: StandardLazyResponse, path: string[], options: ClientOptions<T>): Promisable<StandardLinkCodecDecodedResponse>; | ||
| } | ||
| interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin { | ||
| /** | ||
| * Initializes the plugin and returns new link options. | ||
| * Called once per plugin instance during composition. | ||
| * | ||
| * This method allows plugins to wrap, extend, or transform link options | ||
| * such as interceptors, or configuration. | ||
| * | ||
| * @param options - The current link options from previous plugins or base configuration | ||
| * @returns Transformed link options with plugin's modifications applied | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * init(options) { | ||
| * return { | ||
| * ...options, | ||
| * interceptors: [...(options.interceptors || []), myInterceptor] | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>; | ||
| } | ||
| declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| name: string; | ||
| protected readonly plugins: StandardLinkPlugin<T>[]; | ||
| constructor(plugins?: StandardLinkPlugin<T>[]); | ||
| init(options: StandardLinkOptions<T>): StandardLinkOptions<T>; | ||
| } | ||
| /** | ||
| * Handles the transport layer for sending requests and receiving responses. | ||
| * | ||
| * Implementations are responsible for the actual network communication, | ||
| * such as HTTP fetch, WebSocket, or other transport mechanisms. | ||
| */ | ||
| interface StandardLinkTransport<T extends ClientContext> { | ||
| /** | ||
| * @throws Transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| send(request: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>; | ||
| } | ||
| interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: string[]; | ||
| input: unknown; | ||
| } | ||
| type StandardLinkInterceptor<T extends ClientContext> = Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>; | ||
| interface StandardLinkTransportInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: string[]; | ||
| request: StandardRequest; | ||
| } | ||
| type StandardLinkTransportInterceptor<T extends ClientContext> = Interceptor<StandardLinkTransportInterceptorOptions<T>, Promise<StandardLazyResponse>>; | ||
| interface StandardLinkOptions<T extends ClientContext> { | ||
| /** | ||
| * Interceptors that execute around the entire call, including transport and codec. | ||
| * Useful for error handling, logging, metrics, ... | ||
| */ | ||
| interceptors?: StandardLinkInterceptor<T>[]; | ||
| /** | ||
| * Interceptors that execute around the transport layer, after encoding and before decoding. | ||
| * Useful for modifying the request or response, adding transport-level logging, ... | ||
| */ | ||
| transportInterceptors?: StandardLinkTransportInterceptor<T>[]; | ||
| plugins?: StandardLinkPlugin<T>[]; | ||
| } | ||
| declare class StandardLink<T extends ClientContext> implements ClientLink<T> { | ||
| private readonly codec; | ||
| private readonly transport; | ||
| private readonly interceptors; | ||
| private readonly transportInterceptors; | ||
| constructor(codec: StandardLinkCodec<T>, transport: StandardLinkTransport<T>, options?: StandardLinkOptions<T>); | ||
| /** | ||
| * @throws ORPCError, transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as a }; | ||
| export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i }; |
| import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared'; | ||
| interface ClientContext { | ||
| [key: PropertyKey]: any; | ||
| } | ||
| interface ClientOptions<T extends ClientContext> { | ||
| signal?: AbortSignal | undefined; | ||
| lastEventId?: string | undefined; | ||
| context: T; | ||
| } | ||
| type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? { | ||
| context?: T; | ||
| } : { | ||
| context: T; | ||
| }); | ||
| type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>]; | ||
| interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> { | ||
| (...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>; | ||
| } | ||
| type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | { | ||
| [k: string]: NestedClient<TClientContext>; | ||
| }; | ||
| type AnyNestedClient = NestedClient<any>; | ||
| type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never; | ||
| interface ClientLink<TClientContext extends ClientContext> { | ||
| call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>; | ||
| } | ||
| /** | ||
| * Recursively infers the **input types** from a client. | ||
| * | ||
| * Produces a nested map where each endpoint's input type is preserved. | ||
| */ | ||
| type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **body input types** from a client. | ||
| * | ||
| * If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted. | ||
| * Produces a nested map of body input types. | ||
| */ | ||
| type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyInputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **output types** from a client. | ||
| * | ||
| * Produces a nested map where each endpoint's output type is preserved. | ||
| */ | ||
| type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **body output types** from a client. | ||
| * | ||
| * If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted. | ||
| * Produces a nested map of body output types. | ||
| */ | ||
| type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling). | ||
| * | ||
| * Produces a nested map where each endpoint's error type is preserved. | ||
| */ | ||
| type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling). | ||
| * | ||
| * Useful when you want to handle all possible errors from any endpoint at once. | ||
| */ | ||
| type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never; | ||
| }[keyof T]; | ||
| declare const COMMON_ERROR_STATUS_MAP: { | ||
| BAD_REQUEST: number; | ||
| UNAUTHORIZED: number; | ||
| PAYMENT_REQUIRED: number; | ||
| FORBIDDEN: number; | ||
| NOT_FOUND: number; | ||
| METHOD_NOT_SUPPORTED: number; | ||
| NOT_ACCEPTABLE: number; | ||
| TIMEOUT: number; | ||
| CONFLICT: number; | ||
| GONE: number; | ||
| PRECONDITION_FAILED: number; | ||
| PAYLOAD_TOO_LARGE: number; | ||
| UNSUPPORTED_MEDIA_TYPE: number; | ||
| UNPROCESSABLE_CONTENT: number; | ||
| PRECONDITION_REQUIRED: number; | ||
| TOO_MANY_REQUESTS: number; | ||
| CLIENT_CLOSED_REQUEST: number; | ||
| INTERNAL_SERVER_ERROR: number; | ||
| NOT_IMPLEMENTED: number; | ||
| BAD_GATEWAY: number; | ||
| SERVICE_UNAVAILABLE: number; | ||
| GATEWAY_TIMEOUT: number; | ||
| }; | ||
| type ORPCErrorCode = Registry extends { | ||
| ORPCErrorCode: infer T extends string; | ||
| } ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {}); | ||
| type ORPCErrorOptions<TData> = ErrorOptions & { | ||
| message?: string; | ||
| } & (undefined extends TData ? { | ||
| data?: TData; | ||
| } : { | ||
| data: TData; | ||
| }); | ||
| declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error { | ||
| /** | ||
| * @info | ||
| * The `__branch` property is used for type branding, helping TypeScript distinguish | ||
| * an `ORPCError` instance from plain objects with a similar structure. | ||
| */ | ||
| readonly name: "ORPCError" & { | ||
| __branch: "ORPCError"; | ||
| }; | ||
| /** | ||
| * Indicates whether the error matches a definition in the procedure's `.errors` map. | ||
| */ | ||
| readonly defined: boolean; | ||
| /** | ||
| * Indicates whether the error's type is inferable at the TypeScript level. | ||
| * This is typically true when the error is explicitly defined or returned within a handler. | ||
| */ | ||
| readonly inferable: boolean; | ||
| code: TCode; | ||
| data: TData; | ||
| constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>); | ||
| toJSON(): ORPCErrorJSON<TCode, TData>; | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance: unknown): boolean; | ||
| } | ||
| interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> { | ||
| /** | ||
| * remove readonly | ||
| */ | ||
| defined: boolean; | ||
| /** | ||
| * remove readonly | ||
| */ | ||
| inferable: boolean; | ||
| } | ||
| type AnyORPCError = ORPCError<any, any>; | ||
| type AnyORPCErrorJSON = ORPCErrorJSON<any, any>; | ||
| export { ORPCError as g, COMMON_ERROR_STATUS_MAP as j }; | ||
| export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, AnyNestedClient as c, InferClientError as d, Client as e, ClientRest as f, ORPCErrorJSON as h, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as p }; |
| import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared'; | ||
| interface ClientContext { | ||
| [key: PropertyKey]: any; | ||
| } | ||
| interface ClientOptions<T extends ClientContext> { | ||
| signal?: AbortSignal | undefined; | ||
| lastEventId?: string | undefined; | ||
| context: T; | ||
| } | ||
| type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? { | ||
| context?: T; | ||
| } : { | ||
| context: T; | ||
| }); | ||
| type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>]; | ||
| interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> { | ||
| (...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>; | ||
| } | ||
| type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | { | ||
| [k: string]: NestedClient<TClientContext>; | ||
| }; | ||
| type AnyNestedClient = NestedClient<any>; | ||
| type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never; | ||
| interface ClientLink<TClientContext extends ClientContext> { | ||
| call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>; | ||
| } | ||
| /** | ||
| * Recursively infers the **input types** from a client. | ||
| * | ||
| * Produces a nested map where each endpoint's input type is preserved. | ||
| */ | ||
| type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **body input types** from a client. | ||
| * | ||
| * If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted. | ||
| * Produces a nested map of body input types. | ||
| */ | ||
| type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyInputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **output types** from a client. | ||
| * | ||
| * Produces a nested map where each endpoint's output type is preserved. | ||
| */ | ||
| type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **body output types** from a client. | ||
| * | ||
| * If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted. | ||
| * Produces a nested map of body output types. | ||
| */ | ||
| type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling). | ||
| * | ||
| * Produces a nested map where each endpoint's error type is preserved. | ||
| */ | ||
| type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling). | ||
| * | ||
| * Useful when you want to handle all possible errors from any endpoint at once. | ||
| */ | ||
| type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never; | ||
| }[keyof T]; | ||
| declare const COMMON_ERROR_STATUS_MAP: { | ||
| BAD_REQUEST: number; | ||
| UNAUTHORIZED: number; | ||
| PAYMENT_REQUIRED: number; | ||
| FORBIDDEN: number; | ||
| NOT_FOUND: number; | ||
| METHOD_NOT_SUPPORTED: number; | ||
| NOT_ACCEPTABLE: number; | ||
| TIMEOUT: number; | ||
| CONFLICT: number; | ||
| GONE: number; | ||
| PRECONDITION_FAILED: number; | ||
| PAYLOAD_TOO_LARGE: number; | ||
| UNSUPPORTED_MEDIA_TYPE: number; | ||
| UNPROCESSABLE_CONTENT: number; | ||
| PRECONDITION_REQUIRED: number; | ||
| TOO_MANY_REQUESTS: number; | ||
| CLIENT_CLOSED_REQUEST: number; | ||
| INTERNAL_SERVER_ERROR: number; | ||
| NOT_IMPLEMENTED: number; | ||
| BAD_GATEWAY: number; | ||
| SERVICE_UNAVAILABLE: number; | ||
| GATEWAY_TIMEOUT: number; | ||
| }; | ||
| type ORPCErrorCode = Registry extends { | ||
| ORPCErrorCode: infer T extends string; | ||
| } ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {}); | ||
| type ORPCErrorOptions<TData> = ErrorOptions & { | ||
| message?: string; | ||
| } & (undefined extends TData ? { | ||
| data?: TData; | ||
| } : { | ||
| data: TData; | ||
| }); | ||
| declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error { | ||
| /** | ||
| * @info | ||
| * The `__branch` property is used for type branding, helping TypeScript distinguish | ||
| * an `ORPCError` instance from plain objects with a similar structure. | ||
| */ | ||
| readonly name: "ORPCError" & { | ||
| __branch: "ORPCError"; | ||
| }; | ||
| /** | ||
| * Indicates whether the error matches a definition in the procedure's `.errors` map. | ||
| */ | ||
| readonly defined: boolean; | ||
| /** | ||
| * Indicates whether the error's type is inferable at the TypeScript level. | ||
| * This is typically true when the error is explicitly defined or returned within a handler. | ||
| */ | ||
| readonly inferable: boolean; | ||
| code: TCode; | ||
| data: TData; | ||
| constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>); | ||
| toJSON(): ORPCErrorJSON<TCode, TData>; | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance: unknown): boolean; | ||
| } | ||
| interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> { | ||
| /** | ||
| * remove readonly | ||
| */ | ||
| defined: boolean; | ||
| /** | ||
| * remove readonly | ||
| */ | ||
| inferable: boolean; | ||
| } | ||
| type AnyORPCError = ORPCError<any, any>; | ||
| type AnyORPCErrorJSON = ORPCErrorJSON<any, any>; | ||
| export { ORPCError as g, COMMON_ERROR_STATUS_MAP as j }; | ||
| export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, AnyNestedClient as c, InferClientError as d, Client as e, ClientRest as f, ORPCErrorJSON as h, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as p }; |
| import { sortPlugins, runWithSpan, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, intercept, getOpenTelemetryConfig, value, pathToHttpPath, stringifyJSON } from '@orpc/shared'; | ||
| import { mergeStandardHeaders, parseStandardUrl } from '@standardserver/core'; | ||
| import { toStandardHeaders } from '@standardserver/fetch'; | ||
| import { O as ORPCError } from './client.Dnfj8jnT.mjs'; | ||
| import { R as RPCSerializer, i as isORPCErrorJson, c as createORPCErrorFromJson } from './client.DQpq_Sdn.mjs'; | ||
| class CompositeStandardLinkPlugin { | ||
| name = "~composite"; | ||
| plugins; | ||
| constructor(plugins = []) { | ||
| this.plugins = sortPlugins(plugins); | ||
| } | ||
| init(options) { | ||
| for (const plugin of this.plugins) { | ||
| if (plugin.init) { | ||
| options = plugin.init(options); | ||
| } | ||
| } | ||
| return options; | ||
| } | ||
| } | ||
| class StandardLink { | ||
| constructor(codec, transport, options = {}) { | ||
| this.codec = codec; | ||
| this.transport = transport; | ||
| options = new CompositeStandardLinkPlugin(options.plugins).init(options); | ||
| this.interceptors = options.interceptors; | ||
| this.transportInterceptors = options.transportInterceptors; | ||
| } | ||
| interceptors; | ||
| transportInterceptors; | ||
| /** | ||
| * @throws ORPCError, transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| call(path, input, options) { | ||
| return runWithSpan(`${ORPC_NAME}.${path.join("/")}`, (span) => { | ||
| span?.setAttribute("rpc.system", ORPC_NAME); | ||
| span?.setAttribute("rpc.method", path.join(".")); | ||
| if (isAsyncIteratorObject(input)) { | ||
| input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input)); | ||
| } | ||
| return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => { | ||
| const otel = getOpenTelemetryConfig(); | ||
| let activeContext; | ||
| const activeSpan = otel?.trace.getActiveSpan() ?? span; | ||
| if (activeSpan && otel) { | ||
| activeContext = otel.trace.setSpan(otel.context.active(), activeSpan); | ||
| } | ||
| let request = await runWithSpan( | ||
| { name: "encode_input", context: activeContext }, | ||
| () => this.codec.encodeInput(input2, path2, options2) | ||
| ); | ||
| if (activeContext && otel?.propagation) { | ||
| const headers = { ...request.headers }; | ||
| otel.propagation.inject(activeContext, headers); | ||
| request = { ...request, headers }; | ||
| } | ||
| const response = await intercept( | ||
| this.transportInterceptors, | ||
| { ...options2, path: path2, request }, | ||
| ({ path: path3, request: request2, ...options3 }) => { | ||
| let activeTransportContext; | ||
| const activeTransportSpan = otel?.trace.getActiveSpan() ?? activeSpan; | ||
| if (activeTransportSpan && otel) { | ||
| activeTransportContext = otel.trace.setSpan(otel.context.active(), activeTransportSpan); | ||
| } | ||
| return runWithSpan( | ||
| { name: "send_request", context: activeTransportContext }, | ||
| () => this.transport.send(request2, path3, options3) | ||
| ); | ||
| } | ||
| ); | ||
| const decodedResult = await runWithSpan( | ||
| { name: "decode_response", context: activeContext }, | ||
| () => this.codec.decodeResponse(response, path2, options2) | ||
| ); | ||
| if (decodedResult.kind === "error") { | ||
| throw decodedResult.error; | ||
| } | ||
| const output = decodedResult.output; | ||
| if (isAsyncIteratorObject(output)) { | ||
| return override(output, traceAsyncIterator("consume_async_iterator_object_output", output)); | ||
| } | ||
| return output; | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
| const END_SLASH_REGEX = /\/$/; | ||
| class RPCLinkCodec { | ||
| baseUrl; | ||
| maxUrlLength; | ||
| fallbackMethod; | ||
| expectedMethod; | ||
| headers; | ||
| serializer; | ||
| constructor(options) { | ||
| this.baseUrl = options.url ?? "/"; | ||
| this.maxUrlLength = options.maxUrlLength ?? 2083; | ||
| this.fallbackMethod = options.fallbackMethod ?? "POST"; | ||
| this.expectedMethod = options.method ?? this.fallbackMethod; | ||
| this.headers = options.headers ?? {}; | ||
| this.serializer = options.serializer ?? new RPCSerializer(); | ||
| } | ||
| async encodeInput(input, path, options) { | ||
| let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input)); | ||
| if (options.lastEventId !== void 0) { | ||
| headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId }); | ||
| } | ||
| const expectedMethod = await value(this.expectedMethod, options, path, input); | ||
| const baseUrl = await value(this.baseUrl, options, path, input); | ||
| const [pathname, search, hash] = parseStandardUrl(baseUrl); | ||
| const newPathname = `${pathname.replace(END_SLASH_REGEX, "")}${pathToHttpPath(path)}`; | ||
| const serialized = this.serializer.serialize(input); | ||
| if (expectedMethod === "GET" && !(serialized instanceof Blob) && !(serialized instanceof ReadableStream) && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) { | ||
| const maxUrlLength = await value(this.maxUrlLength, options, path, input); | ||
| const mergedSearch = new URLSearchParams(search); | ||
| mergedSearch.append("data", stringifyJSON(serialized) ?? ""); | ||
| const url2 = `${newPathname}?${mergedSearch}${hash ?? ""}`; | ||
| if (url2.length <= maxUrlLength) { | ||
| return { | ||
| body: void 0, | ||
| method: expectedMethod, | ||
| headers, | ||
| url: url2, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| } | ||
| const url = `${newPathname}${search ?? ""}${hash ?? ""}`; | ||
| return { | ||
| url, | ||
| method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod, | ||
| headers, | ||
| body: serialized, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| async decodeResponse(response) { | ||
| const isOk = response.status < 400; | ||
| const body = await response.resolveBody(); | ||
| const deserialized = await (async () => { | ||
| try { | ||
| return this.serializer.deserialize(body); | ||
| } catch (cause) { | ||
| throw new Error("Invalid RPC response format.", { | ||
| cause | ||
| }); | ||
| } | ||
| })(); | ||
| if (!isOk) { | ||
| if (isORPCErrorJson(deserialized)) { | ||
| return { kind: "error", error: createORPCErrorFromJson(deserialized) }; | ||
| } | ||
| return { | ||
| kind: "error", | ||
| error: new ORPCError("MALFORMED_ORPC_ERROR_RESPONSE", { | ||
| data: { headers: response.headers, status: response.status, body: deserialized } | ||
| }) | ||
| }; | ||
| } | ||
| return { kind: "output", output: deserialized }; | ||
| } | ||
| } | ||
| function toResolvedStandardHeaders(headers) { | ||
| if (typeof headers.forEach === "function") { | ||
| return toStandardHeaders(headers); | ||
| } | ||
| return headers; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, RPCLinkCodec as R, StandardLink as S }; |
| import { Promisable, OrderablePlugin, Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.BBZBQID8.js'; | ||
| type StandardLinkCodecDecodedResponse = { | ||
| kind: 'output'; | ||
| output: unknown; | ||
| } | { | ||
| kind: 'error'; | ||
| error: AnyORPCError; | ||
| }; | ||
| interface StandardLinkCodec<T extends ClientContext> { | ||
| encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promisable<StandardRequest>; | ||
| decodeResponse(response: StandardLazyResponse, path: string[], options: ClientOptions<T>): Promisable<StandardLinkCodecDecodedResponse>; | ||
| } | ||
| interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin { | ||
| /** | ||
| * Initializes the plugin and returns new link options. | ||
| * Called once per plugin instance during composition. | ||
| * | ||
| * This method allows plugins to wrap, extend, or transform link options | ||
| * such as interceptors, or configuration. | ||
| * | ||
| * @param options - The current link options from previous plugins or base configuration | ||
| * @returns Transformed link options with plugin's modifications applied | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * init(options) { | ||
| * return { | ||
| * ...options, | ||
| * interceptors: [...(options.interceptors || []), myInterceptor] | ||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>; | ||
| } | ||
| declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| name: string; | ||
| protected readonly plugins: StandardLinkPlugin<T>[]; | ||
| constructor(plugins?: StandardLinkPlugin<T>[]); | ||
| init(options: StandardLinkOptions<T>): StandardLinkOptions<T>; | ||
| } | ||
| /** | ||
| * Handles the transport layer for sending requests and receiving responses. | ||
| * | ||
| * Implementations are responsible for the actual network communication, | ||
| * such as HTTP fetch, WebSocket, or other transport mechanisms. | ||
| */ | ||
| interface StandardLinkTransport<T extends ClientContext> { | ||
| /** | ||
| * @throws Transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| send(request: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>; | ||
| } | ||
| interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: string[]; | ||
| input: unknown; | ||
| } | ||
| type StandardLinkInterceptor<T extends ClientContext> = Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>; | ||
| interface StandardLinkTransportInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: string[]; | ||
| request: StandardRequest; | ||
| } | ||
| type StandardLinkTransportInterceptor<T extends ClientContext> = Interceptor<StandardLinkTransportInterceptorOptions<T>, Promise<StandardLazyResponse>>; | ||
| interface StandardLinkOptions<T extends ClientContext> { | ||
| /** | ||
| * Interceptors that execute around the entire call, including transport and codec. | ||
| * Useful for error handling, logging, metrics, ... | ||
| */ | ||
| interceptors?: StandardLinkInterceptor<T>[]; | ||
| /** | ||
| * Interceptors that execute around the transport layer, after encoding and before decoding. | ||
| * Useful for modifying the request or response, adding transport-level logging, ... | ||
| */ | ||
| transportInterceptors?: StandardLinkTransportInterceptor<T>[]; | ||
| plugins?: StandardLinkPlugin<T>[]; | ||
| } | ||
| declare class StandardLink<T extends ClientContext> implements ClientLink<T> { | ||
| private readonly codec; | ||
| private readonly transport; | ||
| private readonly interceptors; | ||
| private readonly transportInterceptors; | ||
| constructor(codec: StandardLinkCodec<T>, transport: StandardLinkTransport<T>, options?: StandardLinkOptions<T>); | ||
| /** | ||
| * @throws ORPCError, transport-level errors (network failures, timeouts, etc.) | ||
| */ | ||
| call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as a }; | ||
| export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i }; |
| import { StandardBody } from '@standardserver/core'; | ||
| import { Segment } from '@orpc/shared'; | ||
| type RPCJsonSerializationMeta = [type: string, ...path: Segment[]]; | ||
| type RPCJsonSerialization = { | ||
| json: unknown; | ||
| meta?: RPCJsonSerializationMeta[] | undefined; | ||
| maps?: undefined; | ||
| blobs?: undefined; | ||
| } | { | ||
| json: unknown; | ||
| meta?: RPCJsonSerializationMeta[] | undefined; | ||
| maps: Segment[][]; | ||
| blobs: Blob[]; | ||
| }; | ||
| interface RPCJsonSerializerHandler { | ||
| condition(value: unknown): boolean; | ||
| serialize(value: any): unknown; | ||
| deserialize(serialized: any): unknown; | ||
| /** | ||
| * If false, the result of this serializer will not be further processed by other serializers, | ||
| * even if it matches their conditions and treat it as final serialized value. | ||
| * This can be useful for serializers that return primitive values, which should not be further processed. | ||
| * to improve performance and avoid potential issues with other serializers. | ||
| * | ||
| * @default false | ||
| */ | ||
| isTerminal?: boolean; | ||
| } | ||
| interface RPCJsonSerializerOptions { | ||
| /** | ||
| * Extend or override the built-in type handlers used during serialization and deserialization. | ||
| * | ||
| * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler | ||
| * that defines how to detect, serialize, and deserialize values of that type. | ||
| * | ||
| * **Extending:** Add new keys to support custom types: | ||
| * ```ts | ||
| * handlers: { | ||
| * buffer: { | ||
| * condition: (v) => v instanceof Buffer, | ||
| * serialize: (v: Buffer) => v.toString('base64'), | ||
| * deserialize: (s: string) => Buffer.from(s, 'base64'), | ||
| * isTerminal: true, | ||
| * } | ||
| * } | ||
| * ``` | ||
| * | ||
| * **Overriding:** Use an existing key to replace a built-in handler: | ||
| * ```ts | ||
| * handlers: { | ||
| * date: { | ||
| * condition: (v) => v instanceof Date, | ||
| * serialize: (v: Date) => v.getTime(), | ||
| * deserialize: (n: number) => new Date(n), | ||
| * isTerminal: true, | ||
| * } | ||
| * } | ||
| * ``` | ||
| * | ||
| * **Disabling:** Set a key to `undefined` to remove a built-in handler: | ||
| * ```ts | ||
| * handlers: { regexp: undefined } | ||
| * ``` | ||
| * | ||
| * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `regexp`, `set`, `map`. | ||
| */ | ||
| handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined; | ||
| /** | ||
| * If true, properties with undefined values will be omitted during serialization. | ||
| * | ||
| * @default true | ||
| */ | ||
| omitUndefinedProperties?: boolean | undefined; | ||
| } | ||
| declare class RPCJsonSerializer { | ||
| private readonly handlers; | ||
| private readonly inlineBuiltInHandlers; | ||
| private readonly handlerEntries; | ||
| private readonly omitUndefinedProperties; | ||
| constructor(options?: RPCJsonSerializerOptions); | ||
| serialize(data: unknown): RPCJsonSerialization; | ||
| /** | ||
| * `segments` is a shared mutable stack (push/pop while walking), | ||
| * so it must be copied before being stored in `meta` or `maps`. | ||
| */ | ||
| private serializeValue; | ||
| deserialize(serialized: RPCJsonSerialization): unknown; | ||
| } | ||
| interface RPCSerializerSerializeOptions { | ||
| /** | ||
| * Use FormData for serialization when nested blobs are present. | ||
| * Does not apply to root-level Blob values. | ||
| * | ||
| * @default true | ||
| */ | ||
| useFormDataForBlobFields?: boolean; | ||
| } | ||
| interface RPCSerializerOptions extends RPCJsonSerializerOptions { | ||
| /** | ||
| * Default options for serialize method | ||
| */ | ||
| serialize?: RPCSerializerSerializeOptions | undefined; | ||
| } | ||
| declare class RPCSerializer { | ||
| private readonly jsonSerializer; | ||
| private readonly defaultSerializeOptions; | ||
| constructor(options?: RPCSerializerOptions); | ||
| serialize(data: unknown, options?: RPCSerializerSerializeOptions): StandardBody; | ||
| private serializeValue; | ||
| deserialize(data: StandardBody): unknown; | ||
| private deserializeValue; | ||
| } | ||
| export { RPCJsonSerializer as b, RPCSerializer as e }; | ||
| export type { RPCJsonSerialization as R, RPCJsonSerializationMeta as a, RPCJsonSerializerHandler as c, RPCJsonSerializerOptions as d, RPCSerializerOptions as f, RPCSerializerSerializeOptions as g }; |
| import { StandardBody } from '@standardserver/core'; | ||
| import { Segment } from '@orpc/shared'; | ||
| type RPCJsonSerializationMeta = [type: string, ...path: Segment[]]; | ||
| type RPCJsonSerialization = { | ||
| json: unknown; | ||
| meta?: RPCJsonSerializationMeta[] | undefined; | ||
| maps?: undefined; | ||
| blobs?: undefined; | ||
| } | { | ||
| json: unknown; | ||
| meta?: RPCJsonSerializationMeta[] | undefined; | ||
| maps: Segment[][]; | ||
| blobs: Blob[]; | ||
| }; | ||
| interface RPCJsonSerializerHandler { | ||
| condition(value: unknown): boolean; | ||
| serialize(value: any): unknown; | ||
| deserialize(serialized: any): unknown; | ||
| /** | ||
| * If false, the result of this serializer will not be further processed by other serializers, | ||
| * even if it matches their conditions and treat it as final serialized value. | ||
| * This can be useful for serializers that return primitive values, which should not be further processed. | ||
| * to improve performance and avoid potential issues with other serializers. | ||
| * | ||
| * @default false | ||
| */ | ||
| isTerminal?: boolean; | ||
| } | ||
| interface RPCJsonSerializerOptions { | ||
| /** | ||
| * Extend or override the built-in type handlers used during serialization and deserialization. | ||
| * | ||
| * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler | ||
| * that defines how to detect, serialize, and deserialize values of that type. | ||
| * | ||
| * **Extending:** Add new keys to support custom types: | ||
| * ```ts | ||
| * handlers: { | ||
| * buffer: { | ||
| * condition: (v) => v instanceof Buffer, | ||
| * serialize: (v: Buffer) => v.toString('base64'), | ||
| * deserialize: (s: string) => Buffer.from(s, 'base64'), | ||
| * isTerminal: true, | ||
| * } | ||
| * } | ||
| * ``` | ||
| * | ||
| * **Overriding:** Use an existing key to replace a built-in handler: | ||
| * ```ts | ||
| * handlers: { | ||
| * date: { | ||
| * condition: (v) => v instanceof Date, | ||
| * serialize: (v: Date) => v.getTime(), | ||
| * deserialize: (n: number) => new Date(n), | ||
| * isTerminal: true, | ||
| * } | ||
| * } | ||
| * ``` | ||
| * | ||
| * **Disabling:** Set a key to `undefined` to remove a built-in handler: | ||
| * ```ts | ||
| * handlers: { regexp: undefined } | ||
| * ``` | ||
| * | ||
| * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `regexp`, `set`, `map`. | ||
| */ | ||
| handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined; | ||
| /** | ||
| * If true, properties with undefined values will be omitted during serialization. | ||
| * | ||
| * @default true | ||
| */ | ||
| omitUndefinedProperties?: boolean | undefined; | ||
| } | ||
| declare class RPCJsonSerializer { | ||
| private readonly handlers; | ||
| private readonly inlineBuiltInHandlers; | ||
| private readonly handlerEntries; | ||
| private readonly omitUndefinedProperties; | ||
| constructor(options?: RPCJsonSerializerOptions); | ||
| serialize(data: unknown): RPCJsonSerialization; | ||
| /** | ||
| * `segments` is a shared mutable stack (push/pop while walking), | ||
| * so it must be copied before being stored in `meta` or `maps`. | ||
| */ | ||
| private serializeValue; | ||
| deserialize(serialized: RPCJsonSerialization): unknown; | ||
| } | ||
| interface RPCSerializerSerializeOptions { | ||
| /** | ||
| * Use FormData for serialization when nested blobs are present. | ||
| * Does not apply to root-level Blob values. | ||
| * | ||
| * @default true | ||
| */ | ||
| useFormDataForBlobFields?: boolean; | ||
| } | ||
| interface RPCSerializerOptions extends RPCJsonSerializerOptions { | ||
| /** | ||
| * Default options for serialize method | ||
| */ | ||
| serialize?: RPCSerializerSerializeOptions | undefined; | ||
| } | ||
| declare class RPCSerializer { | ||
| private readonly jsonSerializer; | ||
| private readonly defaultSerializeOptions; | ||
| constructor(options?: RPCSerializerOptions); | ||
| serialize(data: unknown, options?: RPCSerializerSerializeOptions): StandardBody; | ||
| private serializeValue; | ||
| deserialize(data: StandardBody): unknown; | ||
| private deserializeValue; | ||
| } | ||
| export { RPCJsonSerializer as b, RPCSerializer as e }; | ||
| export type { RPCJsonSerialization as R, RPCJsonSerializationMeta as a, RPCJsonSerializerHandler as c, RPCJsonSerializerOptions as d, RPCSerializerOptions as f, RPCSerializerSerializeOptions as g }; |
| import { resolveMaybeOptionalOptions, getConstructor } from '@orpc/shared'; | ||
| const COMMON_ERROR_STATUS_MAP = { | ||
| BAD_REQUEST: 400, | ||
| UNAUTHORIZED: 401, | ||
| PAYMENT_REQUIRED: 402, | ||
| FORBIDDEN: 403, | ||
| NOT_FOUND: 404, | ||
| METHOD_NOT_SUPPORTED: 405, | ||
| NOT_ACCEPTABLE: 406, | ||
| TIMEOUT: 408, | ||
| CONFLICT: 409, | ||
| GONE: 410, | ||
| PRECONDITION_FAILED: 412, | ||
| PAYLOAD_TOO_LARGE: 413, | ||
| UNSUPPORTED_MEDIA_TYPE: 415, | ||
| UNPROCESSABLE_CONTENT: 422, | ||
| PRECONDITION_REQUIRED: 428, | ||
| TOO_MANY_REQUESTS: 429, | ||
| CLIENT_CLOSED_REQUEST: 499, | ||
| INTERNAL_SERVER_ERROR: 500, | ||
| NOT_IMPLEMENTED: 501, | ||
| BAD_GATEWAY: 502, | ||
| SERVICE_UNAVAILABLE: 503, | ||
| GATEWAY_TIMEOUT: 504 | ||
| }; | ||
| let ORPCErrorConstructors; | ||
| class ORPCError extends Error { | ||
| static { | ||
| const ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for("ORPC_ERROR_CONSTRUCTORS"); | ||
| void (globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet()); | ||
| ORPCErrorConstructors = globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL]; | ||
| ORPCErrorConstructors.add(ORPCError); | ||
| } | ||
| /** | ||
| * @info | ||
| * The `__branch` property is used for type branding, helping TypeScript distinguish | ||
| * an `ORPCError` instance from plain objects with a similar structure. | ||
| */ | ||
| name = "ORPCError"; | ||
| /** | ||
| * Indicates whether the error matches a definition in the procedure's `.errors` map. | ||
| */ | ||
| defined = false; | ||
| /** | ||
| * Indicates whether the error's type is inferable at the TypeScript level. | ||
| * This is typically true when the error is explicitly defined or returned within a handler. | ||
| */ | ||
| inferable = false; | ||
| code; | ||
| data; | ||
| constructor(code, ...rest) { | ||
| const options = resolveMaybeOptionalOptions(rest); | ||
| const message = options.message ?? code.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" "); | ||
| super(message, options); | ||
| this.code = code; | ||
| this.data = options.data; | ||
| } | ||
| toJSON() { | ||
| return { | ||
| defined: this.defined, | ||
| inferable: this.inferable, | ||
| code: this.code, | ||
| message: this.message, | ||
| data: this.data | ||
| }; | ||
| } | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance) { | ||
| if (!ORPCErrorConstructors.has(this)) { | ||
| return super[Symbol.hasInstance](instance); | ||
| } | ||
| const constructor = getConstructor(instance); | ||
| if (constructor && ORPCErrorConstructors.has(constructor)) { | ||
| return true; | ||
| } | ||
| return super[Symbol.hasInstance](instance); | ||
| } | ||
| } | ||
| export { COMMON_ERROR_STATUS_MAP as C, ORPCError as O }; |
| import { isPlainObject, wrapAsyncIterator, isTypescriptObject, NullProtoObj, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared'; | ||
| import { getEventMeta, withEventMeta, ErrorEvent } from '@standardserver/core'; | ||
| import { O as ORPCError } from './client.Dnfj8jnT.mjs'; | ||
| function isInferableError(error) { | ||
| return error instanceof ORPCError && error.inferable; | ||
| } | ||
| function toORPCError(error) { | ||
| return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { cause: error }); | ||
| } | ||
| function isORPCErrorJson(json) { | ||
| if (!isPlainObject(json)) { | ||
| return false; | ||
| } | ||
| const validKeys = ["defined", "inferable", "code", "message", "data"]; | ||
| if (Object.keys(json).some((k) => !validKeys.includes(k))) { | ||
| return false; | ||
| } | ||
| return "defined" in json && typeof json.defined === "boolean" && "inferable" in json && typeof json.inferable === "boolean" && "code" in json && typeof json.code === "string" && "message" in json && typeof json.message === "string"; | ||
| } | ||
| function createORPCErrorFromJson(json, options = {}) { | ||
| const error = new ORPCError(json.code, { | ||
| ...json, | ||
| ...options | ||
| }); | ||
| error.defined = json.defined; | ||
| error.inferable = json.inferable; | ||
| return error; | ||
| } | ||
| function cloneORPCError(error) { | ||
| const cloned = new ORPCError(error.code, { | ||
| ...error, | ||
| message: error.message, | ||
| data: error.data, | ||
| cause: error.cause | ||
| }); | ||
| cloned.stack = error.stack; | ||
| cloned.defined = error.defined; | ||
| cloned.inferable = error.inferable; | ||
| return cloned; | ||
| } | ||
| function wrapAsyncIteratorPreservingEventMeta(iterator, { mapResult, mapError, ...rest }) { | ||
| return wrapAsyncIterator(iterator, { | ||
| ...rest, | ||
| mapResult: mapResult && (async (result) => { | ||
| const mapped = await mapResult(result); | ||
| if (mapped.value !== result.value) { | ||
| const meta = getEventMeta(result.value); | ||
| if (meta && isTypescriptObject(mapped.value)) { | ||
| return { done: mapped.done, value: withEventMeta(mapped.value, meta) }; | ||
| } | ||
| } | ||
| return mapped; | ||
| }), | ||
| mapError: mapError && (async (error) => { | ||
| const mapped = await mapError(error); | ||
| if (mapped !== error) { | ||
| const meta = getEventMeta(error); | ||
| if (meta && isTypescriptObject(mapped)) { | ||
| return withEventMeta(mapped, meta); | ||
| } | ||
| } | ||
| return mapped; | ||
| }) | ||
| }); | ||
| } | ||
| const REGEX_STRING_PATTERN = /^\/([\s\S]*)\/([a-z]*)$/; | ||
| const DEFAULT_RPC_JSON_SERIALIZER_HANDLERS = { | ||
| undefined: { | ||
| condition(data) { | ||
| return data === void 0; | ||
| }, | ||
| serialize() { | ||
| return null; | ||
| }, | ||
| deserialize() { | ||
| return void 0; | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| bigint: { | ||
| condition(data) { | ||
| return typeof data === "bigint"; | ||
| }, | ||
| serialize(data) { | ||
| return data.toString(); | ||
| }, | ||
| deserialize(serialized) { | ||
| return BigInt(serialized); | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| date: { | ||
| condition(data) { | ||
| return data instanceof Date; | ||
| }, | ||
| serialize(data) { | ||
| if (Number.isNaN(data.getTime())) { | ||
| return null; | ||
| } | ||
| return data.toISOString(); | ||
| }, | ||
| deserialize(serialized) { | ||
| return new Date(serialized ?? "Invalid Date"); | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| nan: { | ||
| condition(data) { | ||
| return typeof data === "number" && Number.isNaN(data); | ||
| }, | ||
| serialize() { | ||
| return null; | ||
| }, | ||
| deserialize() { | ||
| return Number.NaN; | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| url: { | ||
| condition(data) { | ||
| return data instanceof URL; | ||
| }, | ||
| serialize(data) { | ||
| return data.toString(); | ||
| }, | ||
| deserialize(serialized) { | ||
| return new URL(serialized); | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| regexp: { | ||
| condition(data) { | ||
| return data instanceof RegExp; | ||
| }, | ||
| serialize(data) { | ||
| return data.toString(); | ||
| }, | ||
| deserialize(serialized) { | ||
| const [, pattern, flags] = serialized.match(REGEX_STRING_PATTERN); | ||
| return new RegExp(pattern, flags); | ||
| }, | ||
| isTerminal: true | ||
| }, | ||
| set: { | ||
| condition(data) { | ||
| return data instanceof Set; | ||
| }, | ||
| serialize(data) { | ||
| return Array.from(data); | ||
| }, | ||
| deserialize(serialized) { | ||
| return new Set(serialized); | ||
| } | ||
| }, | ||
| map: { | ||
| condition(data) { | ||
| return data instanceof Map; | ||
| }, | ||
| serialize(data) { | ||
| return Array.from(data.entries()); | ||
| }, | ||
| deserialize(serialized) { | ||
| return new Map(serialized); | ||
| } | ||
| } | ||
| }; | ||
| class RPCJsonSerializer { | ||
| handlers; | ||
| inlineBuiltInHandlers; | ||
| handlerEntries; | ||
| omitUndefinedProperties; | ||
| constructor(options = {}) { | ||
| this.omitUndefinedProperties = options.omitUndefinedProperties !== false; | ||
| this.handlers = Object.assign(new NullProtoObj(), DEFAULT_RPC_JSON_SERIALIZER_HANDLERS); | ||
| const customHandlers = options.handlers; | ||
| if (customHandlers === void 0) { | ||
| this.inlineBuiltInHandlers = true; | ||
| return; | ||
| } | ||
| let inlineBuiltInHandlers = true; | ||
| let handlerEntries = []; | ||
| for (const key in customHandlers) { | ||
| const handler = customHandlers[key]; | ||
| this.handlers[key] = handler; | ||
| if (inlineBuiltInHandlers && key in DEFAULT_RPC_JSON_SERIALIZER_HANDLERS) { | ||
| inlineBuiltInHandlers = false; | ||
| } | ||
| if (inlineBuiltInHandlers && handler !== void 0) { | ||
| handlerEntries.push([key, handler]); | ||
| } | ||
| } | ||
| if (!inlineBuiltInHandlers) { | ||
| handlerEntries = []; | ||
| for (const key in this.handlers) { | ||
| const handler = this.handlers[key]; | ||
| if (handler !== void 0) { | ||
| handlerEntries.push([key, handler]); | ||
| } | ||
| } | ||
| } | ||
| this.inlineBuiltInHandlers = inlineBuiltInHandlers; | ||
| this.handlerEntries = handlerEntries; | ||
| } | ||
| serialize(data) { | ||
| let meta = []; | ||
| const maps = []; | ||
| const blobs = []; | ||
| const json = this.serializeValue(data, [], meta, maps, blobs); | ||
| meta = meta.length === 0 ? void 0 : meta; | ||
| if (maps.length === 0) { | ||
| return { json, meta }; | ||
| } | ||
| return { json, meta, maps, blobs }; | ||
| } | ||
| /** | ||
| * `segments` is a shared mutable stack (push/pop while walking), | ||
| * so it must be copied before being stored in `meta` or `maps`. | ||
| */ | ||
| serializeValue(data, segments, meta, maps, blobs) { | ||
| if (this.inlineBuiltInHandlers) { | ||
| switch (typeof data) { | ||
| case "string": | ||
| case "boolean": | ||
| return data; | ||
| case "number": | ||
| if (Number.isNaN(data)) { | ||
| meta.push(["nan", ...segments]); | ||
| return null; | ||
| } | ||
| return data; | ||
| case "undefined": | ||
| meta.push(["undefined", ...segments]); | ||
| return null; | ||
| case "bigint": | ||
| meta.push(["bigint", ...segments]); | ||
| return data.toString(); | ||
| case "object": { | ||
| if (data === null) { | ||
| return data; | ||
| } | ||
| if (data instanceof Date) { | ||
| meta.push(["date", ...segments]); | ||
| return Number.isNaN(data.getTime()) ? null : data.toISOString(); | ||
| } | ||
| if (data instanceof URL) { | ||
| meta.push(["url", ...segments]); | ||
| return data.toString(); | ||
| } | ||
| if (data instanceof RegExp) { | ||
| meta.push(["regexp", ...segments]); | ||
| return data.toString(); | ||
| } | ||
| if (data instanceof Set) { | ||
| const result = this.serializeValue(Array.from(data), segments, meta, maps, blobs); | ||
| meta.push(["set", ...segments]); | ||
| return result; | ||
| } | ||
| if (data instanceof Map) { | ||
| const result = this.serializeValue(Array.from(data.entries()), segments, meta, maps, blobs); | ||
| meta.push(["map", ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| const handlerEntries = this.handlerEntries; | ||
| if (handlerEntries) { | ||
| for (let i = 0; i < handlerEntries.length; i++) { | ||
| const entry = handlerEntries[i]; | ||
| const handler = entry[1]; | ||
| if (handler.condition(data)) { | ||
| const serialized = handler.serialize(data); | ||
| if (handler.isTerminal) { | ||
| meta.push([entry[0], ...segments]); | ||
| if (serialized instanceof Blob) { | ||
| maps.push(segments.slice()); | ||
| blobs.push(serialized); | ||
| } | ||
| return serialized; | ||
| } | ||
| const result = this.serializeValue(serialized, segments, meta, maps, blobs); | ||
| meta.push([entry[0], ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
| if (data instanceof Blob) { | ||
| maps.push(segments.slice()); | ||
| blobs.push(data); | ||
| return data; | ||
| } | ||
| if (Array.isArray(data)) { | ||
| const json = []; | ||
| for (let i = 0; i < data.length; i++) { | ||
| segments.push(i); | ||
| json.push(this.serializeValue(data[i], segments, meta, maps, blobs)); | ||
| segments.pop(); | ||
| } | ||
| return json; | ||
| } | ||
| if (isPlainObject(data)) { | ||
| const json = new NullProtoObj(); | ||
| for (const k in data) { | ||
| const v = data[k]; | ||
| if (k === "toJSON" && typeof v === "function") { | ||
| continue; | ||
| } | ||
| if (v === void 0 && this.omitUndefinedProperties) { | ||
| continue; | ||
| } | ||
| segments.push(k); | ||
| json[k] = this.serializeValue(v, segments, meta, maps, blobs); | ||
| segments.pop(); | ||
| } | ||
| return json; | ||
| } | ||
| return data; | ||
| } | ||
| deserialize(serialized) { | ||
| const ref = { data: serialized.json }; | ||
| if (serialized.blobs?.length) { | ||
| for (let i = 0; i < serialized.maps.length; i++) { | ||
| const segments = serialized.maps[i]; | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| for (let j = 0; j < segments.length; j++) { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = segments[j]; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: Invalid serialized data. Segment "${preSegment}" does not exist.`); | ||
| } | ||
| } | ||
| currentRef[preSegment] = serialized.blobs[i]; | ||
| } | ||
| } | ||
| if (serialized.meta) { | ||
| for (const item of serialized.meta) { | ||
| const type = item[0]; | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| for (let i = 1; i < item.length; i++) { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = item[i]; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: Invalid serialized data. Segment "${preSegment}" does not exist.`); | ||
| } | ||
| } | ||
| currentRef[preSegment] = this.handlers[type].deserialize(currentRef[preSegment]); | ||
| } | ||
| } | ||
| return ref.data; | ||
| } | ||
| } | ||
| class RPCSerializer { | ||
| jsonSerializer; | ||
| defaultSerializeOptions; | ||
| constructor(options = {}) { | ||
| this.jsonSerializer = new RPCJsonSerializer(options); | ||
| this.defaultSerializeOptions = options.serialize; | ||
| } | ||
| serialize(data, options = {}) { | ||
| if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) { | ||
| return data; | ||
| } | ||
| if (isAsyncIteratorObject(data)) { | ||
| return wrapAsyncIteratorPreservingEventMeta(data, { | ||
| mapResult: (result) => { | ||
| if (result.value === void 0) { | ||
| return result; | ||
| } | ||
| return { done: result.done, value: this.serializeValue(result.value, false) }; | ||
| }, | ||
| mapError: (e) => new ErrorEvent( | ||
| this.serializeValue(toORPCError(e).toJSON(), false), | ||
| { cause: e } | ||
| ) | ||
| }); | ||
| } | ||
| const useFormDataForBlobs = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true; | ||
| return this.serializeValue(data, useFormDataForBlobs); | ||
| } | ||
| serializeValue(data, useFormDataForBlobs) { | ||
| const { json, meta, maps, blobs } = this.jsonSerializer.serialize(data); | ||
| if (!useFormDataForBlobs || !blobs?.length) { | ||
| return { json, meta }; | ||
| } | ||
| const form = new FormData(); | ||
| form.set("data", stringifyJSON({ json, meta, maps })); | ||
| blobs.forEach((blob, i) => { | ||
| form.set(i.toString(), blob); | ||
| }); | ||
| return form; | ||
| } | ||
| deserialize(data) { | ||
| if (data === void 0 || data instanceof ReadableStream || data instanceof Blob) { | ||
| return data; | ||
| } | ||
| if (isAsyncIteratorObject(data)) { | ||
| return wrapAsyncIteratorPreservingEventMeta(data, { | ||
| mapResult: (result) => { | ||
| if (result.value === void 0) { | ||
| return result; | ||
| } | ||
| return { done: result.done, value: this.deserializeValue(result.value) }; | ||
| }, | ||
| mapError: (e) => { | ||
| if (!(e instanceof ErrorEvent)) { | ||
| return e; | ||
| } | ||
| const deserialized = this.deserializeValue(e.data); | ||
| if (isORPCErrorJson(deserialized)) { | ||
| return createORPCErrorFromJson(deserialized, { cause: e }); | ||
| } | ||
| return new ErrorEvent(deserialized, { cause: e }); | ||
| } | ||
| }); | ||
| } | ||
| return this.deserializeValue(data); | ||
| } | ||
| deserializeValue(data) { | ||
| if (!(data instanceof FormData)) { | ||
| return this.jsonSerializer.deserialize(data); | ||
| } | ||
| const serialized = JSON.parse(data.get("data")); | ||
| const blobs = []; | ||
| for (const [key, value] of data) { | ||
| if (value instanceof Blob) { | ||
| blobs[Number(key)] = value; | ||
| } | ||
| } | ||
| return this.jsonSerializer.deserialize({ ...serialized, blobs }); | ||
| } | ||
| } | ||
| export { RPCSerializer as R, isInferableError as a, RPCJsonSerializer as b, createORPCErrorFromJson as c, cloneORPCError as d, isORPCErrorJson as i, toORPCError as t, wrapAsyncIteratorPreservingEventMeta as w }; |
210015
5.46%3162
4.01%203
1.5%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated