@orpc/client
Advanced tools
| 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 { 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 { 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.DqYwRDUO.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 { isPlainObject, wrapAsyncIterator, isTypescriptObject, 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 = /^\/(.*)\/([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; | ||
| omitUndefinedProperties; | ||
| constructor(options = {}) { | ||
| this.handlers = { | ||
| ...DEFAULT_RPC_JSON_SERIALIZER_HANDLERS, | ||
| ...options.handlers | ||
| }; | ||
| this.omitUndefinedProperties = options.omitUndefinedProperties !== false; | ||
| } | ||
| serialize(data) { | ||
| const [json, meta_, maps, blobs] = this.serializeValue(data, [], [], [], []); | ||
| const meta = meta_.length === 0 ? void 0 : meta_; | ||
| if (maps.length === 0) { | ||
| return { json, meta }; | ||
| } | ||
| return { json, meta, maps, blobs }; | ||
| } | ||
| serializeValue(data, segments, meta, maps, blobs) { | ||
| for (const key in this.handlers) { | ||
| const handler = this.handlers[key]; | ||
| if (handler && handler.condition(data)) { | ||
| const serialized = handler.serialize(data); | ||
| if (handler.isTerminal) { | ||
| meta.push([key, ...segments]); | ||
| return [serialized, meta, maps, blobs]; | ||
| } | ||
| const result = this.serializeValue(serialized, segments, meta, maps, blobs); | ||
| meta.push([key, ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| if (data instanceof Blob) { | ||
| maps.push(segments); | ||
| blobs.push(data); | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| if (Array.isArray(data)) { | ||
| const json = data.map((v, i) => { | ||
| return this.serializeValue(v, [...segments, i], meta, maps, blobs)[0]; | ||
| }); | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| if (isPlainObject(data)) { | ||
| const json = {}; | ||
| for (const k in data) { | ||
| const v = data[k]; | ||
| if (k === "toJSON" && typeof v === "function") { | ||
| continue; | ||
| } | ||
| if (v === void 0 && this.omitUndefinedProperties) { | ||
| continue; | ||
| } | ||
| json[k] = this.serializeValue(v, [...segments, k], meta, maps, blobs)[0]; | ||
| } | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| deserialize(serialized) { | ||
| const ref = { data: serialized.json }; | ||
| if (serialized.blobs?.length) { | ||
| serialized.maps.forEach((segments, i) => { | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| segments.forEach((segment) => { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = segment; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: Invalid serialized data. Segment "${preSegment}" does not exist.`); | ||
| } | ||
| }); | ||
| currentRef[preSegment] = serialized.blobs[i]; | ||
| }); | ||
| } | ||
| serialized.meta?.forEach((item) => { | ||
| 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, options) }; | ||
| }, | ||
| mapError: (e) => new ErrorEvent( | ||
| this.serializeValue(toORPCError(e).toJSON(), { ...options, useFormDataForBlobFields: false }), | ||
| { cause: e } | ||
| ) | ||
| }); | ||
| } | ||
| return this.serializeValue(data, options); | ||
| } | ||
| serializeValue(data, options) { | ||
| const useFormDataForBlobs = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true; | ||
| 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 }; |
@@ -1,6 +0,6 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.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.Cby_-GGh.mjs'; | ||
| import { S as StandardLinkTransport, c as StandardLinkPlugin, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.8f4DNmdE.mjs'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.mjs'; | ||
@@ -24,3 +24,3 @@ import '../../shared/client.BdItY5DT.mjs'; | ||
| /** | ||
| * Options for how to convert the Standard Request to a Fetch Request, like event iterator options, etc. | ||
| * Options for how to convert the Standard Request to a Fetch Request, like event stream options, etc. | ||
| */ | ||
@@ -27,0 +27,0 @@ toFetchRequest?: undefined | ToFetchBodyOptions; |
@@ -1,6 +0,6 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.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.CPF3hX6O.js'; | ||
| import { S as StandardLinkTransport, c as StandardLinkPlugin, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BMKYqpdy.js'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.js'; | ||
@@ -24,3 +24,3 @@ import '../../shared/client.BdItY5DT.js'; | ||
| /** | ||
| * Options for how to convert the Standard Request to a Fetch Request, like event iterator options, etc. | ||
| * Options for how to convert the Standard Request to a Fetch Request, like event stream options, etc. | ||
| */ | ||
@@ -27,0 +27,0 @@ toFetchRequest?: undefined | ToFetchBodyOptions; |
| import { sortPlugins, value, intercept } from '@orpc/shared'; | ||
| import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standardserver/fetch'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.BN52ep3E.mjs'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.BRJnOJ0R.mjs'; | ||
| import '@standardserver/core'; | ||
| import '../../shared/client.Dnfj8jnT.mjs'; | ||
| import '../../shared/client.D3TIIok6.mjs'; | ||
| import '../../shared/client.DqYwRDUO.mjs'; | ||
@@ -8,0 +8,0 @@ class CompositeFetchLinkTransportPlugin { |
@@ -1,6 +0,6 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.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.Cby_-GGh.mjs'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.8f4DNmdE.mjs'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.mjs'; | ||
@@ -7,0 +7,0 @@ import '../../shared/client.BdItY5DT.mjs'; |
@@ -1,6 +0,6 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.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.CPF3hX6O.js'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BMKYqpdy.js'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.js'; | ||
@@ -7,0 +7,0 @@ import '../../shared/client.BdItY5DT.js'; |
| import { value } from '@orpc/shared'; | ||
| import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage, isPeerMessage } from '@standardserver/peer'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.BN52ep3E.mjs'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.BRJnOJ0R.mjs'; | ||
| import '@standardserver/core'; | ||
| import '@standardserver/fetch'; | ||
| import '../../shared/client.Dnfj8jnT.mjs'; | ||
| import '../../shared/client.D3TIIok6.mjs'; | ||
| import '../../shared/client.DqYwRDUO.mjs'; | ||
@@ -9,0 +9,0 @@ function postMessagePortMessage(port, data, transfer) { |
@@ -1,7 +0,7 @@ | ||
| import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.Cby_-GGh.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.Cby_-GGh.mjs'; | ||
| 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 { 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.8ug8I-zu.mjs'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.mjs'; | ||
| import { e as RPCSerializer } from '../../shared/client.BdItY5DT.mjs'; | ||
@@ -8,0 +8,0 @@ |
@@ -1,7 +0,7 @@ | ||
| import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.CPF3hX6O.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.CPF3hX6O.js'; | ||
| 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 { 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.8ug8I-zu.js'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.js'; | ||
| import { e as RPCSerializer } from '../../shared/client.BdItY5DT.js'; | ||
@@ -8,0 +8,0 @@ |
@@ -1,2 +0,2 @@ | ||
| export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.BN52ep3E.mjs'; | ||
| export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.BRJnOJ0R.mjs'; | ||
| import '@orpc/shared'; | ||
@@ -6,2 +6,2 @@ import '@standardserver/core'; | ||
| import '../../shared/client.Dnfj8jnT.mjs'; | ||
| import '../../shared/client.D3TIIok6.mjs'; | ||
| import '../../shared/client.DqYwRDUO.mjs'; |
@@ -1,6 +0,6 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.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.Cby_-GGh.mjs'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.8f4DNmdE.mjs'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.mjs'; | ||
@@ -7,0 +7,0 @@ import '../../shared/client.BdItY5DT.mjs'; |
@@ -1,6 +0,6 @@ | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js'; | ||
| import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.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.CPF3hX6O.js'; | ||
| import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.BMKYqpdy.js'; | ||
| import { RPCLinkCodecOptions } from '../standard/index.js'; | ||
@@ -7,0 +7,0 @@ import '../../shared/client.BdItY5DT.js'; |
| 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.BN52ep3E.mjs'; | ||
| import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.BRJnOJ0R.mjs'; | ||
| import '@standardserver/core'; | ||
| import '@standardserver/fetch'; | ||
| import '../../shared/client.Dnfj8jnT.mjs'; | ||
| import '../../shared/client.D3TIIok6.mjs'; | ||
| import '../../shared/client.DqYwRDUO.mjs'; | ||
@@ -9,0 +9,0 @@ const WEBSOCKET_CONNECTING = 0; |
+12
-46
@@ -1,13 +0,9 @@ | ||
| import { O as ORPCErrorCode, c as ORPCError, d as ORPCErrorJSON, A as AnyORPCError, C as ClientContext, a as ClientOptions, e as AnyNestedClient, I as InferClientContext, f as InferClientError, g as Client, b as ClientLink, h as ClientRest, F as FriendlyClientOptions } from './shared/client.8ug8I-zu.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.8ug8I-zu.mjs'; | ||
| import { Interceptor, PromiseWithError, ThrowableError, Promisable, WrapAsyncIteratorOptions, AsyncIteratorClass } from '@orpc/shared'; | ||
| export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared'; | ||
| 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.BdItY5DT.mjs'; | ||
| export { ErrorEvent, EventMeta, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core'; | ||
| declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>; | ||
| declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>; | ||
| declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>; | ||
| declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>; | ||
| declare function cloneORPCError<T extends ORPCErrorCode, TData>(error: ORPCError<T, TData>): ORPCError<T, TData>; | ||
| declare function wrapAsyncIteratorPreservingEventMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>; | ||
@@ -77,31 +73,2 @@ interface ORPCClientInterceptorOptions<TClientContext extends ClientContext, TInput> extends ClientOptions<TClientContext> { | ||
| declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>; | ||
| interface ConsumeEventIteratorOptions<T, TReturn, TError> { | ||
| /** | ||
| * Called on each event | ||
| */ | ||
| onEvent: (event: T) => void; | ||
| /** | ||
| * Called once error happens | ||
| */ | ||
| onError?: (error: TError) => void; | ||
| /** | ||
| * Called once event iterator is done | ||
| * | ||
| * @info If iterator is canceled, `undefined` can be passed on success | ||
| */ | ||
| onSuccess?: (value: TReturn | undefined) => void; | ||
| /** | ||
| * Called once after onError or onSuccess | ||
| * | ||
| * @info If iterator is canceled, `undefined` can be passed on success | ||
| */ | ||
| onFinish?: (state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void; | ||
| } | ||
| /** | ||
| * Consumes an event iterator with lifecycle callbacks | ||
| * | ||
| * @warning If no `onError` or `onFinish` is provided, error will be thrown into unhandled rejection channel. | ||
| * @return unsubscribe callback | ||
| */ | ||
| declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | PromiseWithError<AsyncIterator<T, TReturn>, TError>, options: ConsumeEventIteratorOptions<T, TReturn, TError>): () => Promise<void>; | ||
@@ -148,10 +115,9 @@ type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : { | ||
| declare function wrapEventIteratorPreservingMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>; | ||
| declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>; | ||
| declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>; | ||
| declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>; | ||
| declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>; | ||
| declare function cloneORPCError<T extends ORPCErrorCode, TData>(error: ORPCError<T, TData>): ORPCError<T, TData>; | ||
| /** | ||
| * @deprecated Use `isInferableError` instead. | ||
| */ | ||
| declare const isDefinedError: typeof isInferableError; | ||
| export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, consumeEventIterator, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapEventIteratorPreservingMeta }; | ||
| export type { ConsumeEventIteratorOptions, ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult }; | ||
| 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 type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult }; |
+12
-46
@@ -1,13 +0,9 @@ | ||
| import { O as ORPCErrorCode, c as ORPCError, d as ORPCErrorJSON, A as AnyORPCError, C as ClientContext, a as ClientOptions, e as AnyNestedClient, I as InferClientContext, f as InferClientError, g as Client, b as ClientLink, h as ClientRest, F as FriendlyClientOptions } from './shared/client.8ug8I-zu.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.8ug8I-zu.js'; | ||
| import { Interceptor, PromiseWithError, ThrowableError, Promisable, WrapAsyncIteratorOptions, AsyncIteratorClass } from '@orpc/shared'; | ||
| export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared'; | ||
| 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.BdItY5DT.js'; | ||
| export { ErrorEvent, EventMeta, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core'; | ||
| declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>; | ||
| declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>; | ||
| declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>; | ||
| declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>; | ||
| declare function cloneORPCError<T extends ORPCErrorCode, TData>(error: ORPCError<T, TData>): ORPCError<T, TData>; | ||
| declare function wrapAsyncIteratorPreservingEventMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>; | ||
@@ -77,31 +73,2 @@ interface ORPCClientInterceptorOptions<TClientContext extends ClientContext, TInput> extends ClientOptions<TClientContext> { | ||
| declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>; | ||
| interface ConsumeEventIteratorOptions<T, TReturn, TError> { | ||
| /** | ||
| * Called on each event | ||
| */ | ||
| onEvent: (event: T) => void; | ||
| /** | ||
| * Called once error happens | ||
| */ | ||
| onError?: (error: TError) => void; | ||
| /** | ||
| * Called once event iterator is done | ||
| * | ||
| * @info If iterator is canceled, `undefined` can be passed on success | ||
| */ | ||
| onSuccess?: (value: TReturn | undefined) => void; | ||
| /** | ||
| * Called once after onError or onSuccess | ||
| * | ||
| * @info If iterator is canceled, `undefined` can be passed on success | ||
| */ | ||
| onFinish?: (state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void; | ||
| } | ||
| /** | ||
| * Consumes an event iterator with lifecycle callbacks | ||
| * | ||
| * @warning If no `onError` or `onFinish` is provided, error will be thrown into unhandled rejection channel. | ||
| * @return unsubscribe callback | ||
| */ | ||
| declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | PromiseWithError<AsyncIterator<T, TReturn>, TError>, options: ConsumeEventIteratorOptions<T, TReturn, TError>): () => Promise<void>; | ||
@@ -148,10 +115,9 @@ type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : { | ||
| declare function wrapEventIteratorPreservingMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>; | ||
| declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>; | ||
| declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>; | ||
| declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>; | ||
| declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>; | ||
| declare function cloneORPCError<T extends ORPCErrorCode, TData>(error: ORPCError<T, TData>): ORPCError<T, TData>; | ||
| /** | ||
| * @deprecated Use `isInferableError` instead. | ||
| */ | ||
| declare const isDefinedError: typeof isInferableError; | ||
| export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, consumeEventIterator, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapEventIteratorPreservingMeta }; | ||
| export type { ConsumeEventIteratorOptions, ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult }; | ||
| 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 type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult }; |
+4
-35
@@ -1,5 +0,5 @@ | ||
| import { a as isInferableError } from './shared/client.D3TIIok6.mjs'; | ||
| export { b as RPCJsonSerializer, R as RPCSerializer, d as cloneORPCError, c as createORPCErrorFromJson, i as isORPCErrorJson, t as toORPCError, w as wrapEventIteratorPreservingMeta } from './shared/client.D3TIIok6.mjs'; | ||
| import { a as isInferableError } from './shared/client.DqYwRDUO.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.DqYwRDUO.mjs'; | ||
| import { getOrBind, toArray, intercept, isTypescriptObject } from '@orpc/shared'; | ||
| export { AsyncIteratorClass, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } 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'; | ||
@@ -69,31 +69,2 @@ export { ErrorEvent, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core'; | ||
| } | ||
| function consumeEventIterator(iterator, options) { | ||
| void (async () => { | ||
| let onFinishState; | ||
| try { | ||
| const resolvedIterator = await iterator; | ||
| while (true) { | ||
| const { done, value } = await resolvedIterator.next(); | ||
| if (done) { | ||
| const realValue = value; | ||
| onFinishState = [null, realValue, true]; | ||
| options.onSuccess?.(realValue); | ||
| break; | ||
| } | ||
| options.onEvent(value); | ||
| } | ||
| } catch (error) { | ||
| onFinishState = [error, void 0, false]; | ||
| if (!options.onError && !options.onFinish) { | ||
| throw error; | ||
| } | ||
| options.onError?.(error); | ||
| } finally { | ||
| options.onFinish?.(onFinishState); | ||
| } | ||
| })(); | ||
| return async () => { | ||
| await (await iterator)?.return?.(); | ||
| }; | ||
| } | ||
@@ -153,4 +124,2 @@ function createORPCClient(link, { path = [], ...options } = {}) { | ||
| const isDefinedError = isInferableError; | ||
| export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, consumeEventIterator, createORPCClient, createSafeClient, isDefinedError, isInferableError, resolveClientRest, resolveFriendlyClientOptions, safe }; | ||
| export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, createORPCClient, createSafeClient, isInferableError as isDefinedError, isInferableError, resolveClientRest, resolveFriendlyClientOptions, safe }; |
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { C as ClientContext } from '../shared/client.8ug8I-zu.mjs'; | ||
| import { c as StandardLinkPlugin, d as StandardLinkTransportInterceptorOptions, b as StandardLinkOptions, e as StandardLinkInterceptorOptions } from '../shared/client.Cby_-GGh.mjs'; | ||
| 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'; | ||
@@ -156,3 +156,3 @@ type BatchLinkPluginMode = 'streaming' | 'buffered'; | ||
| * Maximum retry attempts before throwing. | ||
| * Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for event iterators). | ||
| * Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for AsyncIteratorObject). | ||
| * | ||
@@ -186,4 +186,2 @@ * @default 0 | ||
| } | ||
| declare class RetryLinkPluginInvalidEventIteratorRetryResponse extends Error { | ||
| } | ||
| declare class RetryLinkPlugin<T extends RetryLinkPluginContext & ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -243,3 +241,3 @@ private readonly defaultRetry; | ||
| export { BatchLinkPlugin, BatchLinkPluginError, DedupeLinkPlugin, RetryAfterLinkPlugin, RetryLinkPlugin, RetryLinkPluginInvalidEventIteratorRetryResponse }; | ||
| export { BatchLinkPlugin, BatchLinkPluginError, DedupeLinkPlugin, RetryAfterLinkPlugin, RetryLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions }; |
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core'; | ||
| import { C as ClientContext } from '../shared/client.8ug8I-zu.js'; | ||
| import { c as StandardLinkPlugin, d as StandardLinkTransportInterceptorOptions, b as StandardLinkOptions, e as StandardLinkInterceptorOptions } from '../shared/client.CPF3hX6O.js'; | ||
| 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'; | ||
@@ -156,3 +156,3 @@ type BatchLinkPluginMode = 'streaming' | 'buffered'; | ||
| * Maximum retry attempts before throwing. | ||
| * Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for event iterators). | ||
| * Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for AsyncIteratorObject). | ||
| * | ||
@@ -186,4 +186,2 @@ * @default 0 | ||
| } | ||
| declare class RetryLinkPluginInvalidEventIteratorRetryResponse extends Error { | ||
| } | ||
| declare class RetryLinkPlugin<T extends RetryLinkPluginContext & ClientContext> implements StandardLinkPlugin<T> { | ||
@@ -243,3 +241,3 @@ private readonly defaultRetry; | ||
| export { BatchLinkPlugin, BatchLinkPluginError, DedupeLinkPlugin, RetryAfterLinkPlugin, RetryLinkPlugin, RetryLinkPluginInvalidEventIteratorRetryResponse }; | ||
| export { BatchLinkPlugin, BatchLinkPluginError, DedupeLinkPlugin, RetryAfterLinkPlugin, RetryLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions }; |
@@ -390,4 +390,2 @@ import { toArray, value, splitInHalf, stringifyJSON, isAsyncIteratorObject, defer, loadBytes, allAbortSignal, replicateAsyncIterator, replicateReadableStream, override, AsyncIteratorClass, sleep } from '@orpc/shared'; | ||
| class RetryLinkPluginInvalidEventIteratorRetryResponse extends Error { | ||
| } | ||
| class RetryLinkPlugin { | ||
@@ -488,9 +486,9 @@ defaultRetry; | ||
| lastEventRetry = meta?.retry ?? lastEventRetry; | ||
| const maybeEventIterator = await callNext({ error }); | ||
| if (!isAsyncIteratorObject(maybeEventIterator)) { | ||
| throw new RetryLinkPluginInvalidEventIteratorRetryResponse( | ||
| "RetryLinkPlugin: Expected an Event Iterator, got a non-Event Iterator" | ||
| const asyncIteratorObject = await callNext({ error }); | ||
| if (!isAsyncIteratorObject(asyncIteratorObject)) { | ||
| throw new TypeError( | ||
| "RetryLinkPlugin: Expected an AsyncIteratorObject, got a different type." | ||
| ); | ||
| } | ||
| current = maybeEventIterator; | ||
| current = asyncIteratorObject; | ||
| if (isIteratorAborted) { | ||
@@ -576,2 +574,2 @@ await current.return?.(); | ||
| export { BatchLinkPlugin, BatchLinkPluginError, DedupeLinkPlugin, RetryAfterLinkPlugin, RetryLinkPlugin, RetryLinkPluginInvalidEventIteratorRetryResponse }; | ||
| export { BatchLinkPlugin, BatchLinkPluginError, DedupeLinkPlugin, RetryAfterLinkPlugin, RetryLinkPlugin }; |
+5
-5
| { | ||
| "name": "@orpc/client", | ||
| "type": "module", | ||
| "version": "2.0.0-beta.14", | ||
| "version": "2.0.0-beta.15", | ||
| "license": "MIT", | ||
@@ -53,6 +53,6 @@ "homepage": "https://orpc.dev", | ||
| "dependencies": { | ||
| "@standardserver/core": "^0.0.25", | ||
| "@standardserver/fetch": "^0.0.25", | ||
| "@standardserver/peer": "^0.0.25", | ||
| "@orpc/shared": "2.0.0-beta.14" | ||
| "@standardserver/core": "^0.0.32", | ||
| "@standardserver/fetch": "^0.0.32", | ||
| "@standardserver/peer": "^0.0.32", | ||
| "@orpc/shared": "2.0.0-beta.15" | ||
| }, | ||
@@ -59,0 +59,0 @@ "devDependencies": { |
+1
-1
@@ -110,3 +110,2 @@ <h1 align="center">oRPC - Typesafe APIs Made Simple 🪄</h1> | ||
| <td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td> | ||
| <td align="center"><a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&v=4" width="139" alt="Peter Adam"/><br />Peter Adam</a></td> | ||
| <td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td> | ||
@@ -172,2 +171,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> | ||
| <a href="https://github.com/SKostyukovich?ref=orpc" target="_blank" rel="noopener" title="SKostyukovich"><img src="https://avatars.githubusercontent.com/u/10700067?v=4" width="32" height="32" alt="SKostyukovich" /></a> | ||
| <a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&v=4" width="32" height="32" alt="Peter Adam" /></a> | ||
| <a href="https://github.com/FabworksHQ?ref=orpc" target="_blank" rel="noopener" title="Fabworks"><img src="https://avatars.githubusercontent.com/u/160179500?v=4" width="32" height="32" alt="Fabworks" /></a> | ||
@@ -174,0 +174,0 @@ <a href="https://github.com/NovakAnton?ref=orpc" target="_blank" rel="noopener" title="Novak Antonijevic"><img src="https://avatars.githubusercontent.com/u/157126729?u=ae49fa22292d55c0434ff0ca008206155b18663b&v=4" width="32" height="32" alt="Novak Antonijevic" /></a> |
| 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 c, 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, ORPCErrorJSON as d, AnyNestedClient as e, InferClientError as f, Client as g, ClientRest 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 c, 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, ORPCErrorJSON as d, AnyNestedClient as e, InferClientError as f, Client as g, ClientRest 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.D3TIIok6.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_event_iterator_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_event_iterator_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 >= 200 && 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.8ug8I-zu.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 { 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.8ug8I-zu.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 { isPlainObject, wrapAsyncIterator, isTypescriptObject, 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 wrapEventIteratorPreservingMeta(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 = /^\/(.*)\/([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; | ||
| omitUndefinedProperties; | ||
| constructor(options = {}) { | ||
| this.handlers = { | ||
| ...DEFAULT_RPC_JSON_SERIALIZER_HANDLERS, | ||
| ...options.handlers | ||
| }; | ||
| this.omitUndefinedProperties = options.omitUndefinedProperties !== false; | ||
| } | ||
| serialize(data) { | ||
| const [json, meta_, maps, blobs] = this.serializeValue(data, [], [], [], []); | ||
| const meta = meta_.length === 0 ? void 0 : meta_; | ||
| if (maps.length === 0) { | ||
| return { json, meta }; | ||
| } | ||
| return { json, meta, maps, blobs }; | ||
| } | ||
| serializeValue(data, segments, meta, maps, blobs) { | ||
| for (const key in this.handlers) { | ||
| const handler = this.handlers[key]; | ||
| if (handler && handler.condition(data)) { | ||
| const serialized = handler.serialize(data); | ||
| if (handler.isTerminal) { | ||
| meta.push([key, ...segments]); | ||
| return [serialized, meta, maps, blobs]; | ||
| } | ||
| const result = this.serializeValue(serialized, segments, meta, maps, blobs); | ||
| meta.push([key, ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| if (data instanceof Blob) { | ||
| maps.push(segments); | ||
| blobs.push(data); | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| if (Array.isArray(data)) { | ||
| const json = data.map((v, i) => { | ||
| return this.serializeValue(v, [...segments, i], meta, maps, blobs)[0]; | ||
| }); | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| if (isPlainObject(data)) { | ||
| const json = {}; | ||
| for (const k in data) { | ||
| const v = data[k]; | ||
| if (k === "toJSON" && typeof v === "function") { | ||
| continue; | ||
| } | ||
| if (v === void 0 && this.omitUndefinedProperties) { | ||
| continue; | ||
| } | ||
| json[k] = this.serializeValue(v, [...segments, k], meta, maps, blobs)[0]; | ||
| } | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| deserialize(serialized) { | ||
| const ref = { data: serialized.json }; | ||
| if (serialized.blobs?.length) { | ||
| serialized.maps.forEach((segments, i) => { | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| segments.forEach((segment) => { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = segment; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: Invalid serialized data. Segment "${preSegment}" does not exist.`); | ||
| } | ||
| }); | ||
| currentRef[preSegment] = serialized.blobs[i]; | ||
| }); | ||
| } | ||
| serialized.meta?.forEach((item) => { | ||
| 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 wrapEventIteratorPreservingMeta(data, { | ||
| mapResult: (result) => { | ||
| if (result.value === void 0) { | ||
| return result; | ||
| } | ||
| return { done: result.done, value: this.serializeValue(result.value, options) }; | ||
| }, | ||
| mapError: (e) => new ErrorEvent( | ||
| this.serializeValue(toORPCError(e).toJSON(), { ...options, useFormDataForBlobFields: false }), | ||
| { cause: e } | ||
| ) | ||
| }); | ||
| } | ||
| return this.serializeValue(data, options); | ||
| } | ||
| serializeValue(data, options) { | ||
| const useFormDataForBlobs = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true; | ||
| 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 wrapEventIteratorPreservingMeta(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, wrapEventIteratorPreservingMeta as w }; |
178929
-1.76%2581
-2.46%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated