@orpc/client
Advanced tools
| import { Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.i2uoJbEp.js'; | ||
| interface StandardLinkPlugin<T extends ClientContext> { | ||
| order?: number; | ||
| init?(options: StandardLinkOptions<T>): void; | ||
| } | ||
| declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> { | ||
| protected readonly plugins: TPlugin[]; | ||
| constructor(plugins?: readonly TPlugin[]); | ||
| init(options: StandardLinkOptions<T>): void; | ||
| } | ||
| interface StandardLinkCodec<T extends ClientContext> { | ||
| encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>; | ||
| decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>; | ||
| } | ||
| interface StandardLinkClient<T extends ClientContext> { | ||
| call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>; | ||
| } | ||
| interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: readonly string[]; | ||
| input: unknown; | ||
| } | ||
| interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> { | ||
| request: StandardRequest; | ||
| } | ||
| interface StandardLinkOptions<T extends ClientContext> { | ||
| interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[]; | ||
| clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[]; | ||
| plugins?: StandardLinkPlugin<T>[]; | ||
| } | ||
| declare class StandardLink<T extends ClientContext> implements ClientLink<T> { | ||
| readonly codec: StandardLinkCodec<T>; | ||
| readonly sender: StandardLinkClient<T>; | ||
| private readonly interceptors; | ||
| private readonly clientInterceptors; | ||
| constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>); | ||
| call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as d }; | ||
| export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f }; |
| import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.i2uoJbEp.js'; | ||
| import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.2jUAqzYU.js'; | ||
| import { Segment, Value, Promisable } from '@orpc/shared'; | ||
| import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: { | ||
| readonly BIGINT: 0; | ||
| readonly DATE: 1; | ||
| readonly NAN: 2; | ||
| readonly UNDEFINED: 3; | ||
| readonly URL: 4; | ||
| readonly REGEXP: 5; | ||
| readonly SET: 6; | ||
| readonly MAP: 7; | ||
| }; | ||
| type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]]; | ||
| type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]]; | ||
| interface StandardRPCCustomJsonSerializer { | ||
| type: number; | ||
| condition(data: unknown): boolean; | ||
| serialize(data: any): unknown; | ||
| deserialize(serialized: any): unknown; | ||
| } | ||
| interface StandardRPCJsonSerializerOptions { | ||
| customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[]; | ||
| } | ||
| declare class StandardRPCJsonSerializer { | ||
| private readonly customSerializers; | ||
| constructor(options?: StandardRPCJsonSerializerOptions); | ||
| serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized; | ||
| deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown; | ||
| deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown; | ||
| } | ||
| declare class StandardRPCSerializer { | ||
| #private; | ||
| private readonly jsonSerializer; | ||
| constructor(jsonSerializer: StandardRPCJsonSerializer); | ||
| serialize(data: unknown): object; | ||
| deserialize(data: unknown): unknown; | ||
| } | ||
| interface StandardRPCLinkCodecOptions<T extends ClientContext> { | ||
| /** | ||
| * Base url for all requests. | ||
| */ | ||
| url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The maximum length of the URL. | ||
| * | ||
| * @default 2083 | ||
| */ | ||
| maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The method used to make the request. | ||
| * | ||
| * @default 'POST' | ||
| */ | ||
| method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The method to use when the payload cannot safely pass to the server with method return from method function. | ||
| * GET is not allowed, it's very dangerous. | ||
| * | ||
| * @default 'POST' | ||
| */ | ||
| fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>; | ||
| /** | ||
| * Inject headers to the request. | ||
| */ | ||
| headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| } | ||
| declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> { | ||
| private readonly serializer; | ||
| private readonly baseUrl; | ||
| private readonly maxUrlLength; | ||
| private readonly fallbackMethod; | ||
| private readonly expectedMethod; | ||
| private readonly headers; | ||
| constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>); | ||
| encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>; | ||
| decode(response: StandardLazyResponse): Promise<unknown>; | ||
| } | ||
| interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions { | ||
| } | ||
| declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> { | ||
| constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>); | ||
| } | ||
| export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j }; | ||
| export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h }; |
| import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.i2uoJbEp.mjs'; | ||
| import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CpCa3si8.mjs'; | ||
| import { Segment, Value, Promisable } from '@orpc/shared'; | ||
| import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: { | ||
| readonly BIGINT: 0; | ||
| readonly DATE: 1; | ||
| readonly NAN: 2; | ||
| readonly UNDEFINED: 3; | ||
| readonly URL: 4; | ||
| readonly REGEXP: 5; | ||
| readonly SET: 6; | ||
| readonly MAP: 7; | ||
| }; | ||
| type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]]; | ||
| type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]]; | ||
| interface StandardRPCCustomJsonSerializer { | ||
| type: number; | ||
| condition(data: unknown): boolean; | ||
| serialize(data: any): unknown; | ||
| deserialize(serialized: any): unknown; | ||
| } | ||
| interface StandardRPCJsonSerializerOptions { | ||
| customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[]; | ||
| } | ||
| declare class StandardRPCJsonSerializer { | ||
| private readonly customSerializers; | ||
| constructor(options?: StandardRPCJsonSerializerOptions); | ||
| serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized; | ||
| deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown; | ||
| deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown; | ||
| } | ||
| declare class StandardRPCSerializer { | ||
| #private; | ||
| private readonly jsonSerializer; | ||
| constructor(jsonSerializer: StandardRPCJsonSerializer); | ||
| serialize(data: unknown): object; | ||
| deserialize(data: unknown): unknown; | ||
| } | ||
| interface StandardRPCLinkCodecOptions<T extends ClientContext> { | ||
| /** | ||
| * Base url for all requests. | ||
| */ | ||
| url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The maximum length of the URL. | ||
| * | ||
| * @default 2083 | ||
| */ | ||
| maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The method used to make the request. | ||
| * | ||
| * @default 'POST' | ||
| */ | ||
| method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The method to use when the payload cannot safely pass to the server with method return from method function. | ||
| * GET is not allowed, it's very dangerous. | ||
| * | ||
| * @default 'POST' | ||
| */ | ||
| fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>; | ||
| /** | ||
| * Inject headers to the request. | ||
| */ | ||
| headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| } | ||
| declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> { | ||
| private readonly serializer; | ||
| private readonly baseUrl; | ||
| private readonly maxUrlLength; | ||
| private readonly fallbackMethod; | ||
| private readonly expectedMethod; | ||
| private readonly headers; | ||
| constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>); | ||
| encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>; | ||
| decode(response: StandardLazyResponse): Promise<unknown>; | ||
| } | ||
| interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions { | ||
| } | ||
| declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> { | ||
| constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>); | ||
| } | ||
| export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j }; | ||
| export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h }; |
| import { AsyncIteratorClass, isTypescriptObject } from '@orpc/shared'; | ||
| import { getEventMeta, withEventMeta } from '@orpc/standard-server'; | ||
| function mapEventIterator(iterator, maps) { | ||
| const mapError = async (error) => { | ||
| let mappedError = await maps.error(error); | ||
| if (mappedError !== error) { | ||
| const meta = getEventMeta(error); | ||
| if (meta && isTypescriptObject(mappedError)) { | ||
| mappedError = withEventMeta(mappedError, meta); | ||
| } | ||
| } | ||
| return mappedError; | ||
| }; | ||
| return new AsyncIteratorClass(async () => { | ||
| const { done, value } = await (async () => { | ||
| try { | ||
| return await iterator.next(); | ||
| } catch (error) { | ||
| throw await mapError(error); | ||
| } | ||
| })(); | ||
| let mappedValue = await maps.value(value, done); | ||
| if (mappedValue !== value) { | ||
| const meta = getEventMeta(value); | ||
| if (meta && isTypescriptObject(mappedValue)) { | ||
| mappedValue = withEventMeta(mappedValue, meta); | ||
| } | ||
| } | ||
| return { done, value: mappedValue }; | ||
| }, async () => { | ||
| try { | ||
| await iterator.return?.(); | ||
| } catch (error) { | ||
| throw await mapError(error); | ||
| } | ||
| }); | ||
| } | ||
| export { mapEventIterator as m }; |
| import { Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.i2uoJbEp.mjs'; | ||
| interface StandardLinkPlugin<T extends ClientContext> { | ||
| order?: number; | ||
| init?(options: StandardLinkOptions<T>): void; | ||
| } | ||
| declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> { | ||
| protected readonly plugins: TPlugin[]; | ||
| constructor(plugins?: readonly TPlugin[]); | ||
| init(options: StandardLinkOptions<T>): void; | ||
| } | ||
| interface StandardLinkCodec<T extends ClientContext> { | ||
| encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>; | ||
| decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>; | ||
| } | ||
| interface StandardLinkClient<T extends ClientContext> { | ||
| call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>; | ||
| } | ||
| interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: readonly string[]; | ||
| input: unknown; | ||
| } | ||
| interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> { | ||
| request: StandardRequest; | ||
| } | ||
| interface StandardLinkOptions<T extends ClientContext> { | ||
| interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[]; | ||
| clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[]; | ||
| plugins?: StandardLinkPlugin<T>[]; | ||
| } | ||
| declare class StandardLink<T extends ClientContext> implements ClientLink<T> { | ||
| readonly codec: StandardLinkCodec<T>; | ||
| readonly sender: StandardLinkClient<T>; | ||
| private readonly interceptors; | ||
| private readonly clientInterceptors; | ||
| constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>); | ||
| call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as d }; | ||
| export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f }; |
| import { PromiseWithError } from '@orpc/shared'; | ||
| type HTTPPath = `/${string}`; | ||
| type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; | ||
| type ClientContext = Record<PropertyKey, any>; | ||
| interface ClientOptions<T extends ClientContext> { | ||
| signal?: AbortSignal; | ||
| lastEventId?: string | undefined; | ||
| context: T; | ||
| } | ||
| type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? { | ||
| context?: T; | ||
| } : { | ||
| context: T; | ||
| }); | ||
| type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>]; | ||
| type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>; | ||
| interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> { | ||
| (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>; | ||
| } | ||
| type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | { | ||
| [k: string]: NestedClient<TClientContext>; | ||
| }; | ||
| type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never; | ||
| interface ClientLink<TClientContext extends ClientContext> { | ||
| call: (path: readonly 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 NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never; | ||
| }[keyof T]; | ||
| export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l }; |
| import { PromiseWithError } from '@orpc/shared'; | ||
| type HTTPPath = `/${string}`; | ||
| type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; | ||
| type ClientContext = Record<PropertyKey, any>; | ||
| interface ClientOptions<T extends ClientContext> { | ||
| signal?: AbortSignal; | ||
| lastEventId?: string | undefined; | ||
| context: T; | ||
| } | ||
| type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? { | ||
| context?: T; | ||
| } : { | ||
| context: T; | ||
| }); | ||
| type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>]; | ||
| type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>; | ||
| interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> { | ||
| (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>; | ||
| } | ||
| type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | { | ||
| [k: string]: NestedClient<TClientContext>; | ||
| }; | ||
| type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never; | ||
| interface ClientLink<TClientContext extends ClientContext> { | ||
| call: (path: readonly 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 NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never; | ||
| }[keyof T]; | ||
| export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l }; |
| import { resolveMaybeOptionalOptions, getConstructor, isObject } from '@orpc/shared'; | ||
| const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client"; | ||
| const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.1bc0bef"; | ||
| const COMMON_ORPC_ERROR_DEFS = { | ||
| BAD_REQUEST: { | ||
| status: 400, | ||
| message: "Bad Request" | ||
| }, | ||
| UNAUTHORIZED: { | ||
| status: 401, | ||
| message: "Unauthorized" | ||
| }, | ||
| FORBIDDEN: { | ||
| status: 403, | ||
| message: "Forbidden" | ||
| }, | ||
| NOT_FOUND: { | ||
| status: 404, | ||
| message: "Not Found" | ||
| }, | ||
| METHOD_NOT_SUPPORTED: { | ||
| status: 405, | ||
| message: "Method Not Supported" | ||
| }, | ||
| NOT_ACCEPTABLE: { | ||
| status: 406, | ||
| message: "Not Acceptable" | ||
| }, | ||
| TIMEOUT: { | ||
| status: 408, | ||
| message: "Request Timeout" | ||
| }, | ||
| CONFLICT: { | ||
| status: 409, | ||
| message: "Conflict" | ||
| }, | ||
| PRECONDITION_FAILED: { | ||
| status: 412, | ||
| message: "Precondition Failed" | ||
| }, | ||
| PAYLOAD_TOO_LARGE: { | ||
| status: 413, | ||
| message: "Payload Too Large" | ||
| }, | ||
| UNSUPPORTED_MEDIA_TYPE: { | ||
| status: 415, | ||
| message: "Unsupported Media Type" | ||
| }, | ||
| UNPROCESSABLE_CONTENT: { | ||
| status: 422, | ||
| message: "Unprocessable Content" | ||
| }, | ||
| TOO_MANY_REQUESTS: { | ||
| status: 429, | ||
| message: "Too Many Requests" | ||
| }, | ||
| CLIENT_CLOSED_REQUEST: { | ||
| status: 499, | ||
| message: "Client Closed Request" | ||
| }, | ||
| INTERNAL_SERVER_ERROR: { | ||
| status: 500, | ||
| message: "Internal Server Error" | ||
| }, | ||
| NOT_IMPLEMENTED: { | ||
| status: 501, | ||
| message: "Not Implemented" | ||
| }, | ||
| BAD_GATEWAY: { | ||
| status: 502, | ||
| message: "Bad Gateway" | ||
| }, | ||
| SERVICE_UNAVAILABLE: { | ||
| status: 503, | ||
| message: "Service Unavailable" | ||
| }, | ||
| GATEWAY_TIMEOUT: { | ||
| status: 504, | ||
| message: "Gateway Timeout" | ||
| } | ||
| }; | ||
| function fallbackORPCErrorStatus(code, status) { | ||
| return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500; | ||
| } | ||
| function fallbackORPCErrorMessage(code, message) { | ||
| return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code; | ||
| } | ||
| const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`); | ||
| void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet()); | ||
| const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL]; | ||
| class ORPCError extends Error { | ||
| defined; | ||
| code; | ||
| status; | ||
| data; | ||
| constructor(code, ...rest) { | ||
| const options = resolveMaybeOptionalOptions(rest); | ||
| if (options.status !== void 0 && !isORPCErrorStatus(options.status)) { | ||
| throw new Error("[ORPCError] Invalid error status code."); | ||
| } | ||
| const message = fallbackORPCErrorMessage(code, options.message); | ||
| super(message, options); | ||
| this.code = code; | ||
| this.status = fallbackORPCErrorStatus(code, options.status); | ||
| this.defined = options.defined ?? false; | ||
| this.data = options.data; | ||
| } | ||
| toJSON() { | ||
| return { | ||
| defined: this.defined, | ||
| code: this.code, | ||
| status: this.status, | ||
| message: this.message, | ||
| data: this.data | ||
| }; | ||
| } | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance) { | ||
| if (globalORPCErrorConstructors.has(this)) { | ||
| const constructor = getConstructor(instance); | ||
| if (constructor && globalORPCErrorConstructors.has(constructor)) { | ||
| return true; | ||
| } | ||
| } | ||
| return super[Symbol.hasInstance](instance); | ||
| } | ||
| } | ||
| globalORPCErrorConstructors.add(ORPCError); | ||
| function isDefinedError(error) { | ||
| return error instanceof ORPCError && error.defined; | ||
| } | ||
| function toORPCError(error) { | ||
| return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { | ||
| message: "Internal server error", | ||
| cause: error | ||
| }); | ||
| } | ||
| function isORPCErrorStatus(status) { | ||
| return status < 200 || status >= 400; | ||
| } | ||
| function isORPCErrorJson(json) { | ||
| if (!isObject(json)) { | ||
| return false; | ||
| } | ||
| const validKeys = ["defined", "code", "status", "message", "data"]; | ||
| if (Object.keys(json).some((k) => !validKeys.includes(k))) { | ||
| return false; | ||
| } | ||
| return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string"; | ||
| } | ||
| function createORPCErrorFromJson(json, options = {}) { | ||
| return new ORPCError(json.code, { | ||
| ...options, | ||
| ...json | ||
| }); | ||
| } | ||
| export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, toORPCError as t }; |
| import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared'; | ||
| import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server'; | ||
| import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, t as toORPCError } from './client.Wi-Wxp9P.mjs'; | ||
| import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch'; | ||
| import { m as mapEventIterator } from './client.BLtwTQUg.mjs'; | ||
| class CompositeStandardLinkPlugin { | ||
| plugins; | ||
| constructor(plugins = []) { | ||
| this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0)); | ||
| } | ||
| init(options) { | ||
| for (const plugin of this.plugins) { | ||
| plugin.init?.(options); | ||
| } | ||
| } | ||
| } | ||
| class StandardLink { | ||
| constructor(codec, sender, options = {}) { | ||
| this.codec = codec; | ||
| this.sender = sender; | ||
| const plugin = new CompositeStandardLinkPlugin(options.plugins); | ||
| plugin.init(options); | ||
| this.interceptors = toArray(options.interceptors); | ||
| this.clientInterceptors = toArray(options.clientInterceptors); | ||
| } | ||
| interceptors; | ||
| clientInterceptors; | ||
| call(path, input, options) { | ||
| return runWithSpan( | ||
| { name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal }, | ||
| (span) => { | ||
| span?.setAttribute("rpc.system", ORPC_NAME); | ||
| span?.setAttribute("rpc.method", path.join(".")); | ||
| if (isAsyncIteratorObject(input)) { | ||
| input = asyncIteratorWithSpan( | ||
| { name: "consume_event_iterator_input", signal: options.signal }, | ||
| input | ||
| ); | ||
| } | ||
| return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => { | ||
| const otelConfig = getGlobalOtelConfig(); | ||
| let otelContext; | ||
| const currentSpan = otelConfig?.trace.getActiveSpan() ?? span; | ||
| if (currentSpan && otelConfig) { | ||
| otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan); | ||
| } | ||
| const request = await runWithSpan( | ||
| { name: "encode_request", context: otelContext }, | ||
| () => this.codec.encode(path2, input2, options2) | ||
| ); | ||
| const response = await intercept( | ||
| this.clientInterceptors, | ||
| { ...options2, input: input2, path: path2, request }, | ||
| ({ input: input3, path: path3, request: request2, ...options3 }) => { | ||
| return runWithSpan( | ||
| { name: "send_request", signal: options3.signal, context: otelContext }, | ||
| () => this.sender.call(request2, options3, path3, input3) | ||
| ); | ||
| } | ||
| ); | ||
| const output = await runWithSpan( | ||
| { name: "decode_response", context: otelContext }, | ||
| () => this.codec.decode(response, options2, path2, input2) | ||
| ); | ||
| if (isAsyncIteratorObject(output)) { | ||
| return asyncIteratorWithSpan( | ||
| { name: "consume_event_iterator_output", signal: options2.signal }, | ||
| output | ||
| ); | ||
| } | ||
| return output; | ||
| }); | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES = { | ||
| BIGINT: 0, | ||
| DATE: 1, | ||
| NAN: 2, | ||
| UNDEFINED: 3, | ||
| URL: 4, | ||
| REGEXP: 5, | ||
| SET: 6, | ||
| MAP: 7 | ||
| }; | ||
| class StandardRPCJsonSerializer { | ||
| customSerializers; | ||
| constructor(options = {}) { | ||
| this.customSerializers = options.customJsonSerializers ?? []; | ||
| if (this.customSerializers.length !== new Set(this.customSerializers.map((custom) => custom.type)).size) { | ||
| throw new Error("Custom serializer type must be unique."); | ||
| } | ||
| } | ||
| serialize(data, segments = [], meta = [], maps = [], blobs = []) { | ||
| for (const custom of this.customSerializers) { | ||
| if (custom.condition(data)) { | ||
| const result = this.serialize(custom.serialize(data), segments, meta, maps, blobs); | ||
| meta.push([custom.type, ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| if (data instanceof Blob) { | ||
| maps.push(segments); | ||
| blobs.push(data); | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| if (typeof data === "bigint") { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof Date) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE, ...segments]); | ||
| if (Number.isNaN(data.getTime())) { | ||
| return [null, meta, maps, blobs]; | ||
| } | ||
| return [data.toISOString(), meta, maps, blobs]; | ||
| } | ||
| if (Number.isNaN(data)) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN, ...segments]); | ||
| return [null, meta, maps, blobs]; | ||
| } | ||
| if (data instanceof URL) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof RegExp) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof Set) { | ||
| const result = this.serialize(Array.from(data), segments, meta, maps, blobs); | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET, ...segments]); | ||
| return result; | ||
| } | ||
| if (data instanceof Map) { | ||
| const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs); | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP, ...segments]); | ||
| return result; | ||
| } | ||
| if (Array.isArray(data)) { | ||
| const json = data.map((v, i) => { | ||
| if (v === void 0) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED, ...segments, i]); | ||
| return null; | ||
| } | ||
| return this.serialize(v, [...segments, i], meta, maps, blobs)[0]; | ||
| }); | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| if (isObject(data)) { | ||
| const json = {}; | ||
| for (const k in data) { | ||
| if (k === "toJSON" && typeof data[k] === "function") { | ||
| continue; | ||
| } | ||
| json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0]; | ||
| } | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| deserialize(json, meta, maps, getBlob) { | ||
| const ref = { data: json }; | ||
| if (maps && getBlob) { | ||
| 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: accessing non-existent path during deserialization. Path segment: ${preSegment}`); | ||
| } | ||
| }); | ||
| currentRef[preSegment] = getBlob(i); | ||
| }); | ||
| } | ||
| for (const item of meta) { | ||
| const type = item[0]; | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| for (let i = 1; i < item.length; i++) { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = item[i]; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: accessing non-existent path during deserialization. Path segment: ${preSegment}`); | ||
| } | ||
| } | ||
| for (const custom of this.customSerializers) { | ||
| if (custom.type === type) { | ||
| currentRef[preSegment] = custom.deserialize(currentRef[preSegment]); | ||
| break; | ||
| } | ||
| } | ||
| switch (type) { | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT: | ||
| currentRef[preSegment] = BigInt(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE: | ||
| currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date"); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN: | ||
| currentRef[preSegment] = Number.NaN; | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED: | ||
| currentRef[preSegment] = void 0; | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL: | ||
| currentRef[preSegment] = new URL(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP: { | ||
| const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/); | ||
| currentRef[preSegment] = new RegExp(pattern, flags); | ||
| break; | ||
| } | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET: | ||
| currentRef[preSegment] = new Set(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP: | ||
| currentRef[preSegment] = new Map(currentRef[preSegment]); | ||
| break; | ||
| } | ||
| } | ||
| return ref.data; | ||
| } | ||
| } | ||
| function toHttpPath(path) { | ||
| return `/${path.map(encodeURIComponent).join("/")}`; | ||
| } | ||
| function toStandardHeaders(headers) { | ||
| if (typeof headers.forEach === "function") { | ||
| return toStandardHeaders$1(headers); | ||
| } | ||
| return headers; | ||
| } | ||
| function getMalformedResponseErrorCode(status) { | ||
| return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE"; | ||
| } | ||
| class StandardRPCLinkCodec { | ||
| constructor(serializer, options) { | ||
| this.serializer = serializer; | ||
| this.baseUrl = options.url; | ||
| this.maxUrlLength = options.maxUrlLength ?? 2083; | ||
| this.fallbackMethod = options.fallbackMethod ?? "POST"; | ||
| this.expectedMethod = options.method ?? this.fallbackMethod; | ||
| this.headers = options.headers ?? {}; | ||
| } | ||
| baseUrl; | ||
| maxUrlLength; | ||
| fallbackMethod; | ||
| expectedMethod; | ||
| headers; | ||
| async encode(path, input, options) { | ||
| let headers = toStandardHeaders(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 url = new URL(baseUrl); | ||
| url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`; | ||
| const serialized = this.serializer.serialize(input); | ||
| if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) { | ||
| const maxUrlLength = await value(this.maxUrlLength, options, path, input); | ||
| const getUrl = new URL(url); | ||
| getUrl.searchParams.append("data", stringifyJSON(serialized)); | ||
| if (getUrl.toString().length <= maxUrlLength) { | ||
| return { | ||
| body: void 0, | ||
| method: expectedMethod, | ||
| headers, | ||
| url: getUrl, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| url, | ||
| method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod, | ||
| headers, | ||
| body: serialized, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| async decode(response) { | ||
| const isOk = !isORPCErrorStatus(response.status); | ||
| const deserialized = await (async () => { | ||
| let isBodyOk = false; | ||
| try { | ||
| const body = await response.body(); | ||
| isBodyOk = true; | ||
| return this.serializer.deserialize(body); | ||
| } catch (error) { | ||
| if (!isBodyOk) { | ||
| throw new Error("Cannot parse response body, please check the response body and content-type.", { | ||
| cause: error | ||
| }); | ||
| } | ||
| throw new Error("Invalid RPC response format.", { | ||
| cause: error | ||
| }); | ||
| } | ||
| })(); | ||
| if (!isOk) { | ||
| if (isORPCErrorJson(deserialized)) { | ||
| throw createORPCErrorFromJson(deserialized); | ||
| } | ||
| throw new ORPCError(getMalformedResponseErrorCode(response.status), { | ||
| status: response.status, | ||
| data: { ...response, body: deserialized } | ||
| }); | ||
| } | ||
| return deserialized; | ||
| } | ||
| } | ||
| class StandardRPCSerializer { | ||
| constructor(jsonSerializer) { | ||
| this.jsonSerializer = jsonSerializer; | ||
| } | ||
| serialize(data) { | ||
| if (isAsyncIteratorObject(data)) { | ||
| return mapEventIterator(data, { | ||
| value: async (value) => this.#serialize(value, false), | ||
| error: async (e) => { | ||
| return new ErrorEvent({ | ||
| data: this.#serialize(toORPCError(e).toJSON(), false), | ||
| cause: e | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| return this.#serialize(data, true); | ||
| } | ||
| #serialize(data, enableFormData) { | ||
| const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data); | ||
| const meta = meta_.length === 0 ? void 0 : meta_; | ||
| if (!enableFormData || blobs.length === 0) { | ||
| 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 (isAsyncIteratorObject(data)) { | ||
| return mapEventIterator(data, { | ||
| value: async (value) => this.#deserialize(value), | ||
| error: async (e) => { | ||
| if (!(e instanceof ErrorEvent)) { | ||
| return e; | ||
| } | ||
| const deserialized = this.#deserialize(e.data); | ||
| if (isORPCErrorJson(deserialized)) { | ||
| return createORPCErrorFromJson(deserialized, { cause: e }); | ||
| } | ||
| return new ErrorEvent({ | ||
| data: deserialized, | ||
| cause: e | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| return this.#deserialize(data); | ||
| } | ||
| #deserialize(data) { | ||
| if (data === void 0) { | ||
| return void 0; | ||
| } | ||
| if (!(data instanceof FormData)) { | ||
| return this.jsonSerializer.deserialize(data.json, data.meta ?? []); | ||
| } | ||
| const serialized = JSON.parse(data.get("data")); | ||
| return this.jsonSerializer.deserialize( | ||
| serialized.json, | ||
| serialized.meta ?? [], | ||
| serialized.maps, | ||
| (i) => data.get(i.toString()) | ||
| ); | ||
| } | ||
| } | ||
| class StandardRPCLink extends StandardLink { | ||
| constructor(linkClient, options) { | ||
| const jsonSerializer = new StandardRPCJsonSerializer(options); | ||
| const serializer = new StandardRPCSerializer(jsonSerializer); | ||
| const linkCodec = new StandardRPCLinkCodec(serializer, options); | ||
| super(linkCodec, linkClient, options); | ||
| } | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, toStandardHeaders as f, getMalformedResponseErrorCode as g, toHttpPath as t }; |
| import { Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { ToFetchRequestOptions } from '@orpc/standard-server-fetch'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.mjs'; | ||
| import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.CPgZaUox.mjs'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.D8lMmWVC.mjs'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.mjs'; | ||
| import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.CpCa3si8.mjs'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BFAVy68H.mjs'; | ||
@@ -38,4 +38,4 @@ interface LinkFetchPlugin<T extends ClientContext> extends StandardLinkPlugin<T> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.unnoq.com/docs/advanced/rpc-protocol RPC Protocol Docs} | ||
| * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.dev/docs/advanced/rpc-protocol RPC Protocol Docs} | ||
| */ | ||
@@ -42,0 +42,0 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> { |
| import { Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { ToFetchRequestOptions } from '@orpc/standard-server-fetch'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.js'; | ||
| import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.De8SW4Kw.js'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BxV-mzeR.js'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.js'; | ||
| import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.2jUAqzYU.js'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B3pNRBih.js'; | ||
@@ -38,4 +38,4 @@ interface LinkFetchPlugin<T extends ClientContext> extends StandardLinkPlugin<T> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.unnoq.com/docs/advanced/rpc-protocol RPC Protocol Docs} | ||
| * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.dev/docs/advanced/rpc-protocol RPC Protocol Docs} | ||
| */ | ||
@@ -42,0 +42,0 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> { |
| import { toArray, intercept } from '@orpc/shared'; | ||
| import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch'; | ||
| import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.C3VuLuRT.mjs'; | ||
| import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.WIDz3wHe.mjs'; | ||
| import '@orpc/standard-server'; | ||
| import '../../shared/client.-NUQxnPk.mjs'; | ||
| import '../../shared/client.Wi-Wxp9P.mjs'; | ||
| import '../../shared/client.BLtwTQUg.mjs'; | ||
@@ -7,0 +8,0 @@ class CompositeLinkFetchPlugin extends CompositeStandardLinkPlugin { |
@@ -0,6 +1,7 @@ | ||
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.mjs'; | ||
| import { f as StandardLinkClient } from '../../shared/client.CPgZaUox.mjs'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.D8lMmWVC.mjs'; | ||
| import '@orpc/shared'; | ||
| import { DecodedRequestMessage } from '@orpc/standard-server-peer'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.mjs'; | ||
| import { f as StandardLinkClient } from '../../shared/client.CpCa3si8.mjs'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BFAVy68H.mjs'; | ||
@@ -14,3 +15,3 @@ /** | ||
| }) => void) => void; | ||
| postMessage: (data: any) => void; | ||
| postMessage: (data: any, transfer?: any[]) => void; | ||
| } | ||
@@ -33,4 +34,4 @@ /** | ||
| */ | ||
| type SupportedMessagePortData = string | ArrayBufferLike | Uint8Array; | ||
| declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData): void; | ||
| type SupportedMessagePortData = any; | ||
| declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void; | ||
| declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void; | ||
@@ -41,2 +42,22 @@ declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void; | ||
| port: SupportedMessagePort; | ||
| /** | ||
| * By default, oRPC serializes request/response messages to string/binary data before sending over message port. | ||
| * If needed, you can define the this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage), | ||
| * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`. | ||
| * | ||
| * @remarks | ||
| * - return null | undefined to disable this feature | ||
| * | ||
| * @warning Make sure your message port supports `transfer` before using this feature. | ||
| * @example | ||
| * ```ts | ||
| * experimental_transfer: (message, port) => { | ||
| * const transfer = deepFindTransferableObjects(message) // implement your own logic | ||
| * return transfer.length ? transfer : null // only enable when needed | ||
| * } | ||
| * ``` | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/message-port#transfer Message Port Transfer Docs} | ||
| */ | ||
| experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>; | ||
| } | ||
@@ -54,4 +75,4 @@ declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.unnoq.com/docs/adapters/message-port Message Port Adapter Docs} | ||
| * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.dev/docs/adapters/message-port Message Port Adapter Docs} | ||
| */ | ||
@@ -58,0 +79,0 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> { |
@@ -0,6 +1,7 @@ | ||
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.js'; | ||
| import { f as StandardLinkClient } from '../../shared/client.De8SW4Kw.js'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BxV-mzeR.js'; | ||
| import '@orpc/shared'; | ||
| import { DecodedRequestMessage } from '@orpc/standard-server-peer'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.js'; | ||
| import { f as StandardLinkClient } from '../../shared/client.2jUAqzYU.js'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B3pNRBih.js'; | ||
@@ -14,3 +15,3 @@ /** | ||
| }) => void) => void; | ||
| postMessage: (data: any) => void; | ||
| postMessage: (data: any, transfer?: any[]) => void; | ||
| } | ||
@@ -33,4 +34,4 @@ /** | ||
| */ | ||
| type SupportedMessagePortData = string | ArrayBufferLike | Uint8Array; | ||
| declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData): void; | ||
| type SupportedMessagePortData = any; | ||
| declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void; | ||
| declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void; | ||
@@ -41,2 +42,22 @@ declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void; | ||
| port: SupportedMessagePort; | ||
| /** | ||
| * By default, oRPC serializes request/response messages to string/binary data before sending over message port. | ||
| * If needed, you can define the this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage), | ||
| * such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`. | ||
| * | ||
| * @remarks | ||
| * - return null | undefined to disable this feature | ||
| * | ||
| * @warning Make sure your message port supports `transfer` before using this feature. | ||
| * @example | ||
| * ```ts | ||
| * experimental_transfer: (message, port) => { | ||
| * const transfer = deepFindTransferableObjects(message) // implement your own logic | ||
| * return transfer.length ? transfer : null // only enable when needed | ||
| * } | ||
| * ``` | ||
| * | ||
| * @see {@link https://orpc.dev/docs/adapters/message-port#transfer Message Port Transfer Docs} | ||
| */ | ||
| experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>; | ||
| } | ||
@@ -54,4 +75,4 @@ declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.unnoq.com/docs/adapters/message-port Message Port Adapter Docs} | ||
| * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.dev/docs/adapters/message-port Message Port Adapter Docs} | ||
| */ | ||
@@ -58,0 +79,0 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> { |
@@ -1,10 +0,15 @@ | ||
| import { ClientPeer } from '@orpc/standard-server-peer'; | ||
| import '@orpc/shared'; | ||
| import { c as StandardRPCLink } from '../../shared/client.C3VuLuRT.mjs'; | ||
| import { value, isObject } from '@orpc/shared'; | ||
| import { experimental_ClientPeerWithoutCodec, serializeRequestMessage, encodeRequestMessage, deserializeResponseMessage, decodeResponseMessage } from '@orpc/standard-server-peer'; | ||
| import { c as StandardRPCLink } from '../../shared/client.WIDz3wHe.mjs'; | ||
| import '@orpc/standard-server'; | ||
| import '../../shared/client.-NUQxnPk.mjs'; | ||
| import '../../shared/client.Wi-Wxp9P.mjs'; | ||
| import '@orpc/standard-server-fetch'; | ||
| import '../../shared/client.BLtwTQUg.mjs'; | ||
| function postMessagePortMessage(port, data) { | ||
| port.postMessage(data); | ||
| function postMessagePortMessage(port, data, transfer) { | ||
| if (transfer) { | ||
| port.postMessage(data, transfer); | ||
| } else { | ||
| port.postMessage(data); | ||
| } | ||
| } | ||
@@ -49,7 +54,17 @@ function onMessagePortMessage(port, callback) { | ||
| constructor(options) { | ||
| this.peer = new ClientPeer((message) => { | ||
| return postMessagePortMessage(options.port, message); | ||
| this.peer = new experimental_ClientPeerWithoutCodec(async (message) => { | ||
| const [id, type, payload] = message; | ||
| const transfer = await value(options.experimental_transfer, message, options.port); | ||
| if (transfer) { | ||
| postMessagePortMessage(options.port, serializeRequestMessage(id, type, payload), transfer); | ||
| } else { | ||
| postMessagePortMessage(options.port, await encodeRequestMessage(id, type, payload)); | ||
| } | ||
| }); | ||
| onMessagePortMessage(options.port, async (message) => { | ||
| await this.peer.message(message); | ||
| if (isObject(message)) { | ||
| await this.peer.message(deserializeResponseMessage(message)); | ||
| } else { | ||
| await this.peer.message(await decodeResponseMessage(message)); | ||
| } | ||
| }); | ||
@@ -69,3 +84,3 @@ onMessagePortClose(options.port, () => { | ||
| const linkClient = new LinkMessagePortClient(options); | ||
| super(linkClient, { ...options, url: "orpc://localhost" }); | ||
| super(linkClient, { ...options, url: "http://orpc" }); | ||
| } | ||
@@ -72,0 +87,0 @@ } |
@@ -1,5 +0,5 @@ | ||
| export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.CPgZaUox.mjs'; | ||
| export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.D8lMmWVC.mjs'; | ||
| export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.CpCa3si8.mjs'; | ||
| export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.BFAVy68H.mjs'; | ||
| import { StandardHeaders } from '@orpc/standard-server'; | ||
| import { H as HTTPPath } from '../../shared/client.BH1AYT_p.mjs'; | ||
| import { H as HTTPPath } from '../../shared/client.i2uoJbEp.mjs'; | ||
| import '@orpc/shared'; | ||
@@ -6,0 +6,0 @@ |
@@ -1,5 +0,5 @@ | ||
| export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.De8SW4Kw.js'; | ||
| export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.BxV-mzeR.js'; | ||
| export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.2jUAqzYU.js'; | ||
| export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.B3pNRBih.js'; | ||
| import { StandardHeaders } from '@orpc/standard-server'; | ||
| import { H as HTTPPath } from '../../shared/client.BH1AYT_p.js'; | ||
| import { H as HTTPPath } from '../../shared/client.i2uoJbEp.js'; | ||
| import '@orpc/shared'; | ||
@@ -6,0 +6,0 @@ |
@@ -1,5 +0,6 @@ | ||
| export { C as CompositeStandardLinkPlugin, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLink, d as StandardRPCLinkCodec, e as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath, f as toStandardHeaders } from '../../shared/client.C3VuLuRT.mjs'; | ||
| export { C as CompositeStandardLinkPlugin, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLink, d as StandardRPCLinkCodec, e as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath, f as toStandardHeaders } from '../../shared/client.WIDz3wHe.mjs'; | ||
| import '@orpc/shared'; | ||
| import '@orpc/standard-server'; | ||
| import '../../shared/client.-NUQxnPk.mjs'; | ||
| import '../../shared/client.Wi-Wxp9P.mjs'; | ||
| import '@orpc/standard-server-fetch'; | ||
| import '../../shared/client.BLtwTQUg.mjs'; |
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.mjs'; | ||
| import { f as StandardLinkClient } from '../../shared/client.CPgZaUox.mjs'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.D8lMmWVC.mjs'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.mjs'; | ||
| import { f as StandardLinkClient } from '../../shared/client.CpCa3si8.mjs'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BFAVy68H.mjs'; | ||
| import '@orpc/shared'; | ||
@@ -21,4 +21,4 @@ | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.unnoq.com/docs/adapters/websocket WebSocket Adapter Docs} | ||
| * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.dev/docs/adapters/websocket WebSocket Adapter Docs} | ||
| */ | ||
@@ -25,0 +25,0 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> { |
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.js'; | ||
| import { f as StandardLinkClient } from '../../shared/client.De8SW4Kw.js'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BxV-mzeR.js'; | ||
| import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.js'; | ||
| import { f as StandardLinkClient } from '../../shared/client.2jUAqzYU.js'; | ||
| import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B3pNRBih.js'; | ||
| import '@orpc/shared'; | ||
@@ -21,4 +21,4 @@ | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.unnoq.com/docs/adapters/websocket WebSocket Adapter Docs} | ||
| * @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs} | ||
| * @see {@link https://orpc.dev/docs/adapters/websocket WebSocket Adapter Docs} | ||
| */ | ||
@@ -25,0 +25,0 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> { |
| import { readAsBuffer } from '@orpc/shared'; | ||
| import { ClientPeer } from '@orpc/standard-server-peer'; | ||
| import { c as StandardRPCLink } from '../../shared/client.C3VuLuRT.mjs'; | ||
| import { c as StandardRPCLink } from '../../shared/client.WIDz3wHe.mjs'; | ||
| import '@orpc/standard-server'; | ||
| import '../../shared/client.-NUQxnPk.mjs'; | ||
| import '../../shared/client.Wi-Wxp9P.mjs'; | ||
| import '@orpc/standard-server-fetch'; | ||
| import '../../shared/client.BLtwTQUg.mjs'; | ||
@@ -42,3 +43,3 @@ const WEBSOCKET_CONNECTING = 0; | ||
| const linkClient = new LinkWebsocketClient(options); | ||
| super(linkClient, { ...options, url: "orpc://localhost" }); | ||
| super(linkClient, { ...options, url: "http://orpc" }); | ||
| } | ||
@@ -45,0 +46,0 @@ } |
+9
-9
@@ -1,6 +0,6 @@ | ||
| import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.BH1AYT_p.mjs'; | ||
| export { f as HTTPMethod, H as HTTPPath, h as InferClientBodyInputs, j as InferClientBodyOutputs, l as InferClientErrorUnion, k as InferClientErrors, g as InferClientInputs, i as InferClientOutputs } from './shared/client.BH1AYT_p.mjs'; | ||
| import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.i2uoJbEp.mjs'; | ||
| export { f as HTTPMethod, H as HTTPPath, h as InferClientBodyInputs, j as InferClientBodyOutputs, l as InferClientErrorUnion, k as InferClientErrors, g as InferClientInputs, i as InferClientOutputs } from './shared/client.i2uoJbEp.mjs'; | ||
| import { MaybeOptionalOptions, ThrowableError, OnFinishState, Promisable, AsyncIteratorClass } from '@orpc/shared'; | ||
| export { AsyncIteratorClass, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared'; | ||
| export { ErrorEvent } from '@orpc/standard-server'; | ||
| export { AsyncIteratorClass, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared'; | ||
| export { ErrorEvent, EventMeta, getEventMeta, withEventMeta } from '@orpc/standard-server'; | ||
@@ -16,3 +16,3 @@ interface createORPCClientOptions { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/client-side Client-side Client Docs} | ||
| * @see {@link https://orpc.dev/docs/client/client-side Client-side Client Docs} | ||
| */ | ||
@@ -160,3 +160,3 @@ declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T; | ||
| * @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles. | ||
| * @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs} | ||
| * @see {@link https://orpc.dev/docs/client/error-handling Client Error Handling Docs} | ||
| */ | ||
@@ -207,3 +207,3 @@ declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>; | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/error-handling#using-createsafeclient Safe Client Docs} | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs} | ||
| */ | ||
@@ -213,3 +213,3 @@ declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>; | ||
| declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client"; | ||
| declare const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.1bb99f9"; | ||
| declare const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.1bc0bef"; | ||
@@ -220,3 +220,3 @@ /** | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/dynamic-link Dynamic Link Docs} | ||
| * @see {@link https://orpc.dev/docs/client/dynamic-link Dynamic Link Docs} | ||
| */ | ||
@@ -223,0 +223,0 @@ declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> { |
+9
-9
@@ -1,6 +0,6 @@ | ||
| import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.BH1AYT_p.js'; | ||
| export { f as HTTPMethod, H as HTTPPath, h as InferClientBodyInputs, j as InferClientBodyOutputs, l as InferClientErrorUnion, k as InferClientErrors, g as InferClientInputs, i as InferClientOutputs } from './shared/client.BH1AYT_p.js'; | ||
| import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.i2uoJbEp.js'; | ||
| export { f as HTTPMethod, H as HTTPPath, h as InferClientBodyInputs, j as InferClientBodyOutputs, l as InferClientErrorUnion, k as InferClientErrors, g as InferClientInputs, i as InferClientOutputs } from './shared/client.i2uoJbEp.js'; | ||
| import { MaybeOptionalOptions, ThrowableError, OnFinishState, Promisable, AsyncIteratorClass } from '@orpc/shared'; | ||
| export { AsyncIteratorClass, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared'; | ||
| export { ErrorEvent } from '@orpc/standard-server'; | ||
| export { AsyncIteratorClass, EventPublisher, EventPublisherOptions, EventPublisherSubscribeIteratorOptions, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared'; | ||
| export { ErrorEvent, EventMeta, getEventMeta, withEventMeta } from '@orpc/standard-server'; | ||
@@ -16,3 +16,3 @@ interface createORPCClientOptions { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/client-side Client-side Client Docs} | ||
| * @see {@link https://orpc.dev/docs/client/client-side Client-side Client Docs} | ||
| */ | ||
@@ -160,3 +160,3 @@ declare function createORPCClient<T extends NestedClient<any>>(link: ClientLink<InferClientContext<T>>, options?: createORPCClientOptions): T; | ||
| * @info support both tuple `[error, data, isDefined, isSuccess]` and object `{ error, data, isDefined, isSuccess }` styles. | ||
| * @see {@link https://orpc.unnoq.com/docs/client/error-handling Client Error Handling Docs} | ||
| * @see {@link https://orpc.dev/docs/client/error-handling Client Error Handling Docs} | ||
| */ | ||
@@ -207,3 +207,3 @@ declare function safe<TOutput, TError = ThrowableError>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>; | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/error-handling#using-createsafeclient Safe Client Docs} | ||
| * @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs} | ||
| */ | ||
@@ -213,3 +213,3 @@ declare function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T>; | ||
| declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client"; | ||
| declare const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.1bb99f9"; | ||
| declare const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.1bc0bef"; | ||
@@ -220,3 +220,3 @@ /** | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/client/dynamic-link Dynamic Link Docs} | ||
| * @see {@link https://orpc.dev/docs/client/dynamic-link Dynamic Link Docs} | ||
| */ | ||
@@ -223,0 +223,0 @@ declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> { |
+5
-4
| import { preventNativeAwait, isTypescriptObject } from '@orpc/shared'; | ||
| export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared'; | ||
| import { i as isDefinedError } from './shared/client.-NUQxnPk.mjs'; | ||
| export { C as COMMON_ORPC_ERROR_DEFS, c as ORPCError, O as ORPC_CLIENT_PACKAGE_NAME, a as ORPC_CLIENT_PACKAGE_VERSION, g as createORPCErrorFromJson, b as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, e as isORPCErrorJson, d as isORPCErrorStatus, m as mapEventIterator, t as toORPCError } from './shared/client.-NUQxnPk.mjs'; | ||
| export { ErrorEvent } from '@orpc/standard-server'; | ||
| export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared'; | ||
| import { i as isDefinedError } from './shared/client.Wi-Wxp9P.mjs'; | ||
| export { C as COMMON_ORPC_ERROR_DEFS, c as ORPCError, O as ORPC_CLIENT_PACKAGE_NAME, a as ORPC_CLIENT_PACKAGE_VERSION, g as createORPCErrorFromJson, b as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, e as isORPCErrorJson, d as isORPCErrorStatus, t as toORPCError } from './shared/client.Wi-Wxp9P.mjs'; | ||
| export { m as mapEventIterator } from './shared/client.BLtwTQUg.mjs'; | ||
| export { ErrorEvent, getEventMeta, withEventMeta } from '@orpc/standard-server'; | ||
@@ -7,0 +8,0 @@ async function safe(promise) { |
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardHeaders, StandardRequest } from '@orpc/standard-server'; | ||
| import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { BatchResponseMode } from '@orpc/standard-server/batch'; | ||
| import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.CPgZaUox.mjs'; | ||
| import { b as ClientContext } from '../shared/client.BH1AYT_p.mjs'; | ||
| import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.CpCa3si8.mjs'; | ||
| import { b as ClientContext } from '../shared/client.i2uoJbEp.mjs'; | ||
@@ -65,3 +65,3 @@ interface BatchLinkPluginGroup<T extends ClientContext> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/batch-requests Batch Requests Plugin Docs} | ||
| */ | ||
@@ -107,3 +107,3 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/plugins/dedupe-requests Dedupe Requests Plugin} | ||
| * @see {@link https://orpc.dev/docs/plugins/dedupe-requests Dedupe Requests Plugin} | ||
| */ | ||
@@ -155,3 +155,3 @@ declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/plugins/client-retry Client Retry Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/client-retry Client Retry Plugin Docs} | ||
| */ | ||
@@ -168,2 +168,48 @@ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> { | ||
| interface RetryAfterPluginOptions<T extends ClientContext> { | ||
| /** | ||
| * Override condition to determine whether to retry or not. | ||
| * | ||
| * @default ((response) => response.status === 429 || response.status === 503) | ||
| */ | ||
| condition?: Value<boolean, [ | ||
| response: StandardLazyResponse, | ||
| options: StandardLinkClientInterceptorOptions<T> | ||
| ]>; | ||
| /** | ||
| * Maximum attempts before giving up retries. | ||
| * | ||
| * @default 3 | ||
| */ | ||
| maxAttempts?: Value<number, [ | ||
| response: StandardLazyResponse, | ||
| options: StandardLinkClientInterceptorOptions<T> | ||
| ]>; | ||
| /** | ||
| * Maximum timeout in milliseconds to wait before giving up retries. | ||
| * | ||
| * @default 5 * 60 * 1000 (5 minutes) | ||
| */ | ||
| timeout?: Value<number, [ | ||
| response: StandardLazyResponse, | ||
| options: StandardLinkClientInterceptorOptions<T> | ||
| ]>; | ||
| } | ||
| /** | ||
| * The Retry After Plugin automatically retries requests based on server `Retry-After` headers. | ||
| * This is particularly useful for handling rate limiting and temporary server unavailability. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/retry-after Retry After Plugin Docs} | ||
| */ | ||
| declare class RetryAfterPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| private readonly condition; | ||
| private readonly maxAttempts; | ||
| private readonly timeout; | ||
| order: number; | ||
| constructor(options?: RetryAfterPluginOptions<T>); | ||
| init(options: StandardLinkOptions<T>): void; | ||
| private parseRetryAfterHeader; | ||
| private delayExecution; | ||
| } | ||
| interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> { | ||
@@ -195,3 +241,3 @@ /** | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs} | ||
| */ | ||
@@ -207,3 +253,3 @@ declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, SimpleCsrfProtectionLinkPluginOptions }; | ||
| export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, RetryAfterPlugin, SimpleCsrfProtectionLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, RetryAfterPluginOptions, SimpleCsrfProtectionLinkPluginOptions }; |
| import { Value, Promisable } from '@orpc/shared'; | ||
| import { StandardHeaders, StandardRequest } from '@orpc/standard-server'; | ||
| import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { BatchResponseMode } from '@orpc/standard-server/batch'; | ||
| import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.De8SW4Kw.js'; | ||
| import { b as ClientContext } from '../shared/client.BH1AYT_p.js'; | ||
| import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.2jUAqzYU.js'; | ||
| import { b as ClientContext } from '../shared/client.i2uoJbEp.js'; | ||
@@ -65,3 +65,3 @@ interface BatchLinkPluginGroup<T extends ClientContext> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/batch-requests Batch Requests Plugin Docs} | ||
| */ | ||
@@ -107,3 +107,3 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/plugins/dedupe-requests Dedupe Requests Plugin} | ||
| * @see {@link https://orpc.dev/docs/plugins/dedupe-requests Dedupe Requests Plugin} | ||
| */ | ||
@@ -155,3 +155,3 @@ declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/plugins/client-retry Client Retry Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/client-retry Client Retry Plugin Docs} | ||
| */ | ||
@@ -168,2 +168,48 @@ declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> { | ||
| interface RetryAfterPluginOptions<T extends ClientContext> { | ||
| /** | ||
| * Override condition to determine whether to retry or not. | ||
| * | ||
| * @default ((response) => response.status === 429 || response.status === 503) | ||
| */ | ||
| condition?: Value<boolean, [ | ||
| response: StandardLazyResponse, | ||
| options: StandardLinkClientInterceptorOptions<T> | ||
| ]>; | ||
| /** | ||
| * Maximum attempts before giving up retries. | ||
| * | ||
| * @default 3 | ||
| */ | ||
| maxAttempts?: Value<number, [ | ||
| response: StandardLazyResponse, | ||
| options: StandardLinkClientInterceptorOptions<T> | ||
| ]>; | ||
| /** | ||
| * Maximum timeout in milliseconds to wait before giving up retries. | ||
| * | ||
| * @default 5 * 60 * 1000 (5 minutes) | ||
| */ | ||
| timeout?: Value<number, [ | ||
| response: StandardLazyResponse, | ||
| options: StandardLinkClientInterceptorOptions<T> | ||
| ]>; | ||
| } | ||
| /** | ||
| * The Retry After Plugin automatically retries requests based on server `Retry-After` headers. | ||
| * This is particularly useful for handling rate limiting and temporary server unavailability. | ||
| * | ||
| * @see {@link https://orpc.dev/docs/plugins/retry-after Retry After Plugin Docs} | ||
| */ | ||
| declare class RetryAfterPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| private readonly condition; | ||
| private readonly maxAttempts; | ||
| private readonly timeout; | ||
| order: number; | ||
| constructor(options?: RetryAfterPluginOptions<T>); | ||
| init(options: StandardLinkOptions<T>): void; | ||
| private parseRetryAfterHeader; | ||
| private delayExecution; | ||
| } | ||
| interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> { | ||
@@ -195,3 +241,3 @@ /** | ||
| * | ||
| * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs} | ||
| * @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs} | ||
| */ | ||
@@ -207,3 +253,3 @@ declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> { | ||
| export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, SimpleCsrfProtectionLinkPluginOptions }; | ||
| export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, RetryAfterPlugin, SimpleCsrfProtectionLinkPlugin }; | ||
| export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, RetryAfterPluginOptions, SimpleCsrfProtectionLinkPluginOptions }; |
| import { isAsyncIteratorObject, defer, value, splitInHalf, toArray, stringifyJSON, overlayProxy, AsyncIteratorClass } from '@orpc/shared'; | ||
| import { toBatchRequest, parseBatchResponse, toBatchAbortSignal } from '@orpc/standard-server/batch'; | ||
| import { replicateStandardLazyResponse, getEventMeta } from '@orpc/standard-server'; | ||
| import { replicateStandardLazyResponse, getEventMeta, flattenHeader } from '@orpc/standard-server'; | ||
| import { C as COMMON_ORPC_ERROR_DEFS } from '../shared/client.Wi-Wxp9P.mjs'; | ||
@@ -374,2 +375,79 @@ class BatchLinkPlugin { | ||
| class RetryAfterPlugin { | ||
| condition; | ||
| maxAttempts; | ||
| timeout; | ||
| order = 19e5; | ||
| constructor(options = {}) { | ||
| this.condition = options.condition ?? ((response) => response.status === COMMON_ORPC_ERROR_DEFS.TOO_MANY_REQUESTS.status || response.status === COMMON_ORPC_ERROR_DEFS.SERVICE_UNAVAILABLE.status); | ||
| this.maxAttempts = options.maxAttempts ?? 3; | ||
| this.timeout = options.timeout ?? 5 * 60 * 1e3; | ||
| } | ||
| init(options) { | ||
| options.clientInterceptors ??= []; | ||
| options.clientInterceptors.push(async (interceptorOptions) => { | ||
| const startTime = Date.now(); | ||
| let attemptCount = 0; | ||
| while (true) { | ||
| attemptCount++; | ||
| const response = await interceptorOptions.next(); | ||
| if (!value(this.condition, response, interceptorOptions)) { | ||
| return response; | ||
| } | ||
| const retryAfterHeader = flattenHeader(response.headers["retry-after"]); | ||
| const retryAfterMs = this.parseRetryAfterHeader(retryAfterHeader); | ||
| if (retryAfterMs === void 0) { | ||
| return response; | ||
| } | ||
| if (attemptCount >= value(this.maxAttempts, response, interceptorOptions)) { | ||
| return response; | ||
| } | ||
| const timeoutMs = value(this.timeout, response, interceptorOptions); | ||
| const elapsedTime = Date.now() - startTime; | ||
| if (elapsedTime + retryAfterMs > timeoutMs) { | ||
| return response; | ||
| } | ||
| await this.delayExecution(retryAfterMs, interceptorOptions.signal); | ||
| if (interceptorOptions.signal?.aborted) { | ||
| return response; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| parseRetryAfterHeader(value2) { | ||
| value2 = value2?.trim(); | ||
| if (!value2) { | ||
| return void 0; | ||
| } | ||
| const seconds = Number(value2); | ||
| if (Number.isFinite(seconds)) { | ||
| return Math.max(0, seconds * 1e3); | ||
| } | ||
| const retryDate = Date.parse(value2); | ||
| if (!Number.isNaN(retryDate)) { | ||
| return Math.max(0, retryDate - Date.now()); | ||
| } | ||
| return void 0; | ||
| } | ||
| delayExecution(ms, signal) { | ||
| return new Promise((resolve) => { | ||
| if (signal?.aborted) { | ||
| resolve(); | ||
| return; | ||
| } | ||
| let timeout; | ||
| const onAbort = () => { | ||
| clearTimeout(timeout); | ||
| timeout = void 0; | ||
| resolve(); | ||
| }; | ||
| signal?.addEventListener("abort", onAbort, { once: true }); | ||
| timeout = setTimeout(() => { | ||
| signal?.removeEventListener("abort", onAbort); | ||
| resolve(); | ||
| }, ms); | ||
| }); | ||
| } | ||
| } | ||
| class SimpleCsrfProtectionLinkPlugin { | ||
@@ -408,2 +486,2 @@ headerName; | ||
| export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin }; | ||
| export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, RetryAfterPlugin, SimpleCsrfProtectionLinkPlugin }; |
+8
-9
| { | ||
| "name": "@orpc/client", | ||
| "type": "module", | ||
| "version": "0.0.0-next.1bb99f9", | ||
| "version": "0.0.0-next.1bc0bef", | ||
| "license": "MIT", | ||
| "homepage": "https://orpc.unnoq.com", | ||
| "homepage": "https://orpc.dev", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/unnoq/orpc.git", | ||
| "url": "git+https://github.com/middleapi/orpc.git", | ||
| "directory": "packages/client" | ||
| }, | ||
| "keywords": [ | ||
| "unnoq", | ||
| "orpc" | ||
@@ -52,9 +51,9 @@ ], | ||
| "dependencies": { | ||
| "@orpc/shared": "0.0.0-next.1bb99f9", | ||
| "@orpc/standard-server-fetch": "0.0.0-next.1bb99f9", | ||
| "@orpc/standard-server": "0.0.0-next.1bb99f9", | ||
| "@orpc/standard-server-peer": "0.0.0-next.1bb99f9" | ||
| "@orpc/shared": "0.0.0-next.1bc0bef", | ||
| "@orpc/standard-server-fetch": "0.0.0-next.1bc0bef", | ||
| "@orpc/standard-server": "0.0.0-next.1bc0bef", | ||
| "@orpc/standard-server-peer": "0.0.0-next.1bc0bef" | ||
| }, | ||
| "devDependencies": { | ||
| "zod": "^4.1.12" | ||
| "zod": "^4.3.6" | ||
| }, | ||
@@ -61,0 +60,0 @@ "scripts": { |
+117
-13
| <div align="center"> | ||
| <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" /> | ||
| <image align="center" src="https://orpc.dev/logo.webp" width=280 alt="oRPC logo" /> | ||
| </div> | ||
@@ -8,4 +8,4 @@ | ||
| <div align="center"> | ||
| <a href="https://codecov.io/gh/unnoq/orpc"> | ||
| <img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg"> | ||
| <a href="https://codecov.io/gh/middleapi/orpc"> | ||
| <img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg"> | ||
| </a> | ||
@@ -15,4 +15,4 @@ <a href="https://www.npmjs.com/package/@orpc/client"> | ||
| </a> | ||
| <a href="https://github.com/unnoq/orpc/blob/main/LICENSE"> | ||
| <img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" /> | ||
| <a href="https://github.com/middleapi/orpc/blob/main/LICENSE"> | ||
| <img alt="MIT License" src="https://img.shields.io/github/license/middleapi/orpc?logo=open-source-initiative" /> | ||
| </a> | ||
@@ -22,3 +22,3 @@ <a href="https://discord.gg/TXEbwRBvQn"> | ||
| </a> | ||
| <a href="https://deepwiki.com/unnoq/orpc"> | ||
| <a href="https://deepwiki.com/middleapi/orpc"> | ||
| <img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"> | ||
@@ -51,3 +51,3 @@ </a> | ||
| You can find the full documentation [here](https://orpc.unnoq.com). | ||
| You can find the full documentation [here](https://orpc.dev). | ||
@@ -73,3 +73,3 @@ ## Packages | ||
| Consume your API on the client with type-safety. Read the [documentation](https://orpc.unnoq.com/docs/client/client-side) for more information. | ||
| Consume your API on the client with type-safety. Read the [documentation](https://orpc.dev/docs/client/client-side) for more information. | ||
@@ -98,6 +98,110 @@ ```ts | ||
| <p align="center"> | ||
| <a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg"> | ||
| <img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/> | ||
| </a> | ||
| If you find oRPC valuable and would like to support its development, you can do so here: [GitHub Sponsors](https://github.com/sponsors/dinwwwh). | ||
| ### 🏆 Platinum Sponsor | ||
| <table> | ||
| <tr> | ||
| <td align="center"><a href="https://screenshotone.com/?ref=orpc" target="_blank" rel="noopener" title="ScreenshotOne.com"><img src="https://avatars.githubusercontent.com/u/97035603?v=4" width="279" alt="ScreenshotOne.com"/><br />ScreenshotOne.com</a></td> | ||
| </tr> | ||
| </table> | ||
| ### 🥈 Silver Sponsor | ||
| <table> | ||
| <tr> | ||
| <td align="center"><a href="https://misskey.io/?ref=orpc" target="_blank" rel="noopener" title="村上さん"><img src="https://avatars.githubusercontent.com/u/37681609?u=0dd4c7e4ba937cbb52b068c55914b1d8164dc0c7&v=4" width="209" alt="村上さん"/><br />村上さん</a></td> | ||
| <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="209" alt="christ12938"/><br />christ12938</a></td> | ||
| </tr> | ||
| </table> | ||
| ### Generous Sponsors | ||
| <table> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/ln-markets?ref=orpc" target="_blank" rel="noopener" title="LN Markets"><img src="https://avatars.githubusercontent.com/u/70597625?v=4" width="167" alt="LN Markets"/><br />LN Markets</a></td> | ||
| </tr> | ||
| </table> | ||
| ### Sponsors | ||
| <table> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/hrmcdonald?ref=orpc" target="_blank" rel="noopener" title="Reece McDonald"><img src="https://avatars.githubusercontent.com/u/39349270?v=4" width="139" alt="Reece McDonald"/><br />Reece McDonald</a></td> | ||
| <td align="center"><a href="https://github.com/u1-liquid?ref=orpc" target="_blank" rel="noopener" title="あわわわとーにゅ"><img src="https://avatars.githubusercontent.com/u/17376330?u=de3353804be889f009f7e0a1582daf04d0ab292d&v=4" width="139" alt="あわわわとーにゅ"/><br />あわわわとーにゅ</a></td> | ||
| <td align="center"><a href="https://github.com/nicognaW?ref=orpc" target="_blank" rel="noopener" title="nk"><img src="https://avatars.githubusercontent.com/u/66731869?u=4699bda3a9092d3ec34fbd959450767bcc8b8b6d&v=4" width="139" alt="nk"/><br />nk</a></td> | ||
| <td align="center"><a href="https://github.com/supastarter?ref=orpc" target="_blank" rel="noopener" title="supastarter"><img src="https://avatars.githubusercontent.com/u/110960143?v=4" width="139" alt="supastarter"/><br />supastarter</a></td> | ||
| <td align="center"><a href="https://github.com/divmgl?ref=orpc" target="_blank" rel="noopener" title="Dexter Miguel"><img src="https://avatars.githubusercontent.com/u/5452298?u=645993204be8696c085ecf0d228c3062efe2ed65&v=4" width="139" alt="Dexter Miguel"/><br />Dexter Miguel</a></td> | ||
| <td align="center"><a href="https://github.com/herrfugbaum?ref=orpc" target="_blank" rel="noopener" title="herrfugbaum"><img src="https://avatars.githubusercontent.com/u/12859776?u=644dc1666d0220bc0468eb0de3c56b919f635b16&v=4" width="139" alt="herrfugbaum"/><br />herrfugbaum</a></td> | ||
| </tr> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/ryota-murakami?ref=orpc" target="_blank" rel="noopener" title="Ryota Murakami"><img src="https://avatars.githubusercontent.com/u/5501268?u=599389e03340734325726ca3f8f423c021d47d7f&v=4" width="139" alt="Ryota Murakami"/><br />Ryota Murakami</a></td> | ||
| <td align="center"><a href="https://github.com/dcramer?ref=orpc" target="_blank" rel="noopener" title="David Cramer"><img src="https://avatars.githubusercontent.com/u/23610?v=4" width="139" alt="David Cramer"/><br />David Cramer</a></td> | ||
| <td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td> | ||
| <td align="center"><a href="https://github.com/happyboy2022?ref=orpc" target="_blank" rel="noopener" title="happyboy"><img src="https://avatars.githubusercontent.com/u/103669586?u=65b49c4b893ed3703909fbb3a7a22313f3f9c121&v=4" width="139" alt="happyboy"/><br />happyboy</a></td> | ||
| <td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td> | ||
| <td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td> | ||
| </tr> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="139" alt="Andrew Peters"/><br />Andrew Peters</a></td> | ||
| <td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</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/yukimotochern?ref=orpc" target="_blank" rel="noopener" title="Chen, Zhi-Yuan"><img src="https://avatars.githubusercontent.com/u/20896173?u=945c33fc21725e4d566a0d02afc54b136ca1d67a&v=4" width="139" alt="Chen, Zhi-Yuan"/><br />Chen, Zhi-Yuan</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> | ||
| </tr> | ||
| </table> | ||
| ### Backers | ||
| <table> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/rhinodavid?ref=orpc" target="_blank" rel="noopener" title="David Walsh"><img src="https://avatars.githubusercontent.com/u/5778036?u=b5521f07d2f88c3db2a0dae62b5f2f8357214af0&v=4" width="119" alt="David Walsh"/><br />David Walsh</a></td> | ||
| <td align="center"><a href="https://github.com/Robbe95?ref=orpc" target="_blank" rel="noopener" title="Robbe Vaes"><img src="https://avatars.githubusercontent.com/u/44748019?u=e0232402c045ad4eac7cbd217f1f47e083103b89&v=4" width="119" alt="Robbe Vaes"/><br />Robbe Vaes</a></td> | ||
| <td align="center"><a href="https://github.com/aidansunbury?ref=orpc" target="_blank" rel="noopener" title="Aidan Sunbury"><img src="https://avatars.githubusercontent.com/u/64103161?v=4" width="119" alt="Aidan Sunbury"/><br />Aidan Sunbury</a></td> | ||
| <td align="center"><a href="https://github.com/soonoo?ref=orpc" target="_blank" rel="noopener" title="soonoo"><img src="https://avatars.githubusercontent.com/u/5436405?u=5d0b4aa955c87e30e6bda7f0cccae5402da99528&v=4" width="119" alt="soonoo"/><br />soonoo</a></td> | ||
| <td align="center"><a href="https://github.com/kporten?ref=orpc" target="_blank" rel="noopener" title="Kevin Porten"><img src="https://avatars.githubusercontent.com/u/1839345?u=dc2263d5cfe0d927ce1a0be04a1d55dd6b55405c&v=4" width="119" alt="Kevin Porten"/><br />Kevin Porten</a></td> | ||
| <td align="center"><a href="https://github.com/pumpkinlink?ref=orpc" target="_blank" rel="noopener" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&v=4" width="119" alt="Denis"/><br />Denis</a></td> | ||
| <td align="center"><a href="https://github.com/christopher-kapic?ref=orpc" target="_blank" rel="noopener" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&v=4" width="119" alt="Christopher Kapic"/><br />Christopher Kapic</a></td> | ||
| </tr> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/thomasballinger?ref=orpc" target="_blank" rel="noopener" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&v=4" width="119" alt="Tom Ballinger"/><br />Tom Ballinger</a></td> | ||
| <td align="center"><a href="https://github.com/SSam0419?ref=orpc" target="_blank" rel="noopener" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&v=4" width="119" alt="Sam"/><br />Sam</a></td> | ||
| <td align="center"><a href="https://github.com/Titoine?ref=orpc" target="_blank" rel="noopener" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&v=4" width="119" alt="Titoine"/><br />Titoine</a></td> | ||
| <td align="center"><a href="https://github.com/Mnigos?ref=orpc" target="_blank" rel="noopener" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&v=4" width="119" alt="Igor Makowski"/><br />Igor Makowski</a></td> | ||
| <td align="center"><a href="https://github.com/steelbrain?ref=orpc" target="_blank" rel="noopener" title="Anees Iqbal"><img src="https://avatars.githubusercontent.com/u/4278113?u=22b80b5399eed68ac76cd58b02961b0481f1db11&v=4" width="119" alt="Anees Iqbal"/><br />Anees Iqbal</a></td> | ||
| <td align="center"><a href="https://github.com/hanayashiki?ref=orpc" target="_blank" rel="noopener" title="wang chenyu"><img src="https://avatars.githubusercontent.com/u/26056783?u=98c5ceda64b19874ed2a31515467332ea991e590&v=4" width="119" alt="wang chenyu"/><br />wang chenyu</a></td> | ||
| <td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td> | ||
| </tr> | ||
| </table> | ||
| ### Past Sponsors | ||
| <p> | ||
| <a href="https://github.com/MrMaxie?ref=orpc" target="_blank" rel="noopener" title="Maxie"><img src="https://avatars.githubusercontent.com/u/3857836?u=5e6b57973d4385d655663ffdd836e487856f2984&v=4" width="32" height="32" alt="Maxie" /></a> | ||
| <a href="https://github.com/Stijn-Timmer?ref=orpc" target="_blank" rel="noopener" title="Stijn Timmer"><img src="https://avatars.githubusercontent.com/u/100147665?u=106b2c18e9c98a61861b4ee7fc100f5b9906a6c9&v=4" width="32" height="32" alt="Stijn Timmer" /></a> | ||
| <a href="https://github.com/zuplo?ref=orpc" target="_blank" rel="noopener" title="Zuplo"><img src="https://avatars.githubusercontent.com/u/85497839?v=4" width="32" height="32" alt="Zuplo" /></a> | ||
| <a href="https://github.com/motopods?ref=orpc" target="_blank" rel="noopener" title="motopods"><img src="https://avatars.githubusercontent.com/u/58200641?u=18833983d65b481ae90a4adec2373064ec58bcf3&v=4" width="32" height="32" alt="motopods" /></a> | ||
| <a href="https://github.com/franciscohermida?ref=orpc" target="_blank" rel="noopener" title="Francisco Hermida"><img src="https://avatars.githubusercontent.com/u/483242?u=bbcbc80eb9d8781ff401f7dafc3b59cd7bea0561&v=4" width="32" height="32" alt="Francisco Hermida" /></a> | ||
| <a href="https://github.com/theoludwig?ref=orpc" target="_blank" rel="noopener" title="Théo LUDWIG"><img src="https://avatars.githubusercontent.com/u/25207499?u=a6a9653725a2f574c07893748806668e0598cdbe&v=4" width="32" height="32" alt="Théo LUDWIG" /></a> | ||
| <a href="https://github.com/abhay-ramesh?ref=orpc" target="_blank" rel="noopener" title="Abhay Ramesh"><img src="https://avatars.githubusercontent.com/u/66196314?u=c5c2b0327b26606c2efcfaf17046ab18c3d25c57&v=4" width="32" height="32" alt="Abhay Ramesh" /></a> | ||
| <a href="https://github.com/shr-ink?ref=orpc" target="_blank" rel="noopener" title="shr.ink oü"><img src="https://avatars.githubusercontent.com/u/139700438?v=4" width="32" height="32" alt="shr.ink oü" /></a> | ||
| <a href="https://github.com/johngerome?ref=orpc" target="_blank" rel="noopener" title="0x4e32"><img src="https://avatars.githubusercontent.com/u/2002000?u=24e8dd943cfc862aa284d858a023532c75071ade&v=4" width="32" height="32" alt="0x4e32" /></a> | ||
| <a href="https://github.com/yzuyr?ref=orpc" target="_blank" rel="noopener" title="Ryuz"><img src="https://avatars.githubusercontent.com/u/196539378?u=d38374588d219b6748b16406982f6559411466d4&v=4" width="32" height="32" alt="Ryuz" /></a> | ||
| <a href="https://github.com/YiCChi?ref=orpc" target="_blank" rel="noopener" title="yicchi"><img src="https://avatars.githubusercontent.com/u/86967274?u=6c2756f09fe15dd94d572f560e979cd157982852&v=4" width="32" height="32" alt="yicchi" /></a> | ||
| <a href="https://github.com/cloudycotton?ref=orpc" target="_blank" rel="noopener" title="Saksham"><img src="https://avatars.githubusercontent.com/u/168998965?u=9b9634a5aed66a51c1b880663272725b00b92b14&v=4" width="32" height="32" alt="Saksham" /></a> | ||
| <a href="https://github.com/hrynevychroman?ref=orpc" target="_blank" rel="noopener" title="Roman Hrynevych"><img src="https://avatars.githubusercontent.com/u/82209198?u=1a1d111ab3d589855b9cc8a7fefb1b5c6a4fbbaf&v=4" width="32" height="32" alt="Roman Hrynevych" /></a> | ||
| <a href="https://github.com/rokitgg?ref=orpc" target="_blank" rel="noopener" title="rokitg"><img src="https://avatars.githubusercontent.com/u/125133357?u=06c74aefaa2236b06a2e5fba5a5c612339f45912&v=4" width="32" height="32" alt="rokitg" /></a> | ||
| <a href="https://github.com/omarkhatibgg?ref=orpc" target="_blank" rel="noopener" title="Omar Khatib"><img src="https://avatars.githubusercontent.com/u/9054278?u=afbba7331b85c51b8eee4130f5fd31b1017dc919&v=4" width="32" height="32" alt="Omar Khatib" /></a> | ||
| <a href="https://github.com/YuSabo90002?ref=orpc" target="_blank" rel="noopener" title="Yu-Sabo"><img src="https://avatars.githubusercontent.com/u/13120582?v=4" width="32" height="32" alt="Yu-Sabo" /></a> | ||
| <a href="https://github.com/bapspatil?ref=orpc" target="_blank" rel="noopener" title="Bapusaheb Patil"><img src="https://avatars.githubusercontent.com/u/16699418?v=4" width="32" height="32" alt="Bapusaheb Patil" /></a> | ||
| <a href="https://github.com/ripgrim?ref=orpc" target="_blank" rel="noopener" title="grim"><img src="https://avatars.githubusercontent.com/u/75869731?u=b17c42ec2309552fdb822a86b25a2f99146a4d72&v=4" width="32" height="32" alt="grim" /></a> | ||
| <a href="https://github.com/nelsonlaidev?ref=orpc" target="_blank" rel="noopener" title="Nelson Lai"><img src="https://avatars.githubusercontent.com/u/75498339?u=2fc0e0b95dd184c5ffb744df977cb15a18b60672&v=4" width="32" height="32" alt="Nelson Lai" /></a> | ||
| <a href="https://github.com/nguyenlc1993?ref=orpc" target="_blank" rel="noopener" title="Lê Cao Nguyên"><img src="https://avatars.githubusercontent.com/u/13871971?u=83c8b69d9e35b589c4e1f066cc113b1d9461386f&v=4" width="32" height="32" alt="Lê Cao Nguyên" /></a> | ||
| <a href="https://github.com/wobsoriano?ref=orpc" target="_blank" rel="noopener" title="Robert Soriano"><img src="https://avatars.githubusercontent.com/u/13049130?u=6d72104182e7c9ed25934815313fb69107332111&v=4" width="32" height="32" alt="Robert Soriano" /></a> | ||
| <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/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> | ||
| <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> | ||
| <a href="https://github.com/laduniestu?ref=orpc" target="_blank" rel="noopener" title="Laduni Estu Syalwa"><img src="https://avatars.githubusercontent.com/u/44757637?u=a2fc1ea8f7d827a96721176f79d30592d1c48059&v=4" width="32" height="32" alt="Laduni Estu Syalwa" /></a> | ||
| <a href="https://github.com/illarionvk?ref=orpc" target="_blank" rel="noopener" title="Illarion Koperski"><img src="https://avatars.githubusercontent.com/u/5012724?u=7cfa13652f7ac5fb3c56d880e3eb3fbe40c3ea34&v=4" width="32" height="32" alt="Illarion Koperski" /></a> | ||
| <a href="https://github.com/Scrumplex?ref=orpc" target="_blank" rel="noopener" title="Sefa Eyeoglu"><img src="https://avatars.githubusercontent.com/u/11587657?u=ab503582165c0bbff0cca47ce31c9450bb1553c9&v=4" width="32" height="32" alt="Sefa Eyeoglu" /></a> | ||
| </p> | ||
@@ -107,2 +211,2 @@ | ||
| Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information. | ||
| Distributed under the MIT License. See [LICENSE](https://github.com/middleapi/orpc/blob/main/LICENSE) for more information. |
| import { resolveMaybeOptionalOptions, getConstructor, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared'; | ||
| import { getEventMeta, withEventMeta } from '@orpc/standard-server'; | ||
| const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client"; | ||
| const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.1bb99f9"; | ||
| const COMMON_ORPC_ERROR_DEFS = { | ||
| BAD_REQUEST: { | ||
| status: 400, | ||
| message: "Bad Request" | ||
| }, | ||
| UNAUTHORIZED: { | ||
| status: 401, | ||
| message: "Unauthorized" | ||
| }, | ||
| FORBIDDEN: { | ||
| status: 403, | ||
| message: "Forbidden" | ||
| }, | ||
| NOT_FOUND: { | ||
| status: 404, | ||
| message: "Not Found" | ||
| }, | ||
| METHOD_NOT_SUPPORTED: { | ||
| status: 405, | ||
| message: "Method Not Supported" | ||
| }, | ||
| NOT_ACCEPTABLE: { | ||
| status: 406, | ||
| message: "Not Acceptable" | ||
| }, | ||
| TIMEOUT: { | ||
| status: 408, | ||
| message: "Request Timeout" | ||
| }, | ||
| CONFLICT: { | ||
| status: 409, | ||
| message: "Conflict" | ||
| }, | ||
| PRECONDITION_FAILED: { | ||
| status: 412, | ||
| message: "Precondition Failed" | ||
| }, | ||
| PAYLOAD_TOO_LARGE: { | ||
| status: 413, | ||
| message: "Payload Too Large" | ||
| }, | ||
| UNSUPPORTED_MEDIA_TYPE: { | ||
| status: 415, | ||
| message: "Unsupported Media Type" | ||
| }, | ||
| UNPROCESSABLE_CONTENT: { | ||
| status: 422, | ||
| message: "Unprocessable Content" | ||
| }, | ||
| TOO_MANY_REQUESTS: { | ||
| status: 429, | ||
| message: "Too Many Requests" | ||
| }, | ||
| CLIENT_CLOSED_REQUEST: { | ||
| status: 499, | ||
| message: "Client Closed Request" | ||
| }, | ||
| INTERNAL_SERVER_ERROR: { | ||
| status: 500, | ||
| message: "Internal Server Error" | ||
| }, | ||
| NOT_IMPLEMENTED: { | ||
| status: 501, | ||
| message: "Not Implemented" | ||
| }, | ||
| BAD_GATEWAY: { | ||
| status: 502, | ||
| message: "Bad Gateway" | ||
| }, | ||
| SERVICE_UNAVAILABLE: { | ||
| status: 503, | ||
| message: "Service Unavailable" | ||
| }, | ||
| GATEWAY_TIMEOUT: { | ||
| status: 504, | ||
| message: "Gateway Timeout" | ||
| } | ||
| }; | ||
| function fallbackORPCErrorStatus(code, status) { | ||
| return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500; | ||
| } | ||
| function fallbackORPCErrorMessage(code, message) { | ||
| return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code; | ||
| } | ||
| const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`); | ||
| void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet()); | ||
| const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL]; | ||
| class ORPCError extends Error { | ||
| defined; | ||
| code; | ||
| status; | ||
| data; | ||
| constructor(code, ...rest) { | ||
| const options = resolveMaybeOptionalOptions(rest); | ||
| if (options.status !== void 0 && !isORPCErrorStatus(options.status)) { | ||
| throw new Error("[ORPCError] Invalid error status code."); | ||
| } | ||
| const message = fallbackORPCErrorMessage(code, options.message); | ||
| super(message, options); | ||
| this.code = code; | ||
| this.status = fallbackORPCErrorStatus(code, options.status); | ||
| this.defined = options.defined ?? false; | ||
| this.data = options.data; | ||
| } | ||
| toJSON() { | ||
| return { | ||
| defined: this.defined, | ||
| code: this.code, | ||
| status: this.status, | ||
| message: this.message, | ||
| data: this.data | ||
| }; | ||
| } | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance) { | ||
| if (globalORPCErrorConstructors.has(this)) { | ||
| const constructor = getConstructor(instance); | ||
| if (constructor && globalORPCErrorConstructors.has(constructor)) { | ||
| return true; | ||
| } | ||
| } | ||
| return super[Symbol.hasInstance](instance); | ||
| } | ||
| } | ||
| globalORPCErrorConstructors.add(ORPCError); | ||
| function isDefinedError(error) { | ||
| return error instanceof ORPCError && error.defined; | ||
| } | ||
| function toORPCError(error) { | ||
| return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { | ||
| message: "Internal server error", | ||
| cause: error | ||
| }); | ||
| } | ||
| function isORPCErrorStatus(status) { | ||
| return status < 200 || status >= 400; | ||
| } | ||
| function isORPCErrorJson(json) { | ||
| if (!isObject(json)) { | ||
| return false; | ||
| } | ||
| const validKeys = ["defined", "code", "status", "message", "data"]; | ||
| if (Object.keys(json).some((k) => !validKeys.includes(k))) { | ||
| return false; | ||
| } | ||
| return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string"; | ||
| } | ||
| function createORPCErrorFromJson(json, options = {}) { | ||
| return new ORPCError(json.code, { | ||
| ...options, | ||
| ...json | ||
| }); | ||
| } | ||
| function mapEventIterator(iterator, maps) { | ||
| const mapError = async (error) => { | ||
| let mappedError = await maps.error(error); | ||
| if (mappedError !== error) { | ||
| const meta = getEventMeta(error); | ||
| if (meta && isTypescriptObject(mappedError)) { | ||
| mappedError = withEventMeta(mappedError, meta); | ||
| } | ||
| } | ||
| return mappedError; | ||
| }; | ||
| return new AsyncIteratorClass(async () => { | ||
| const { done, value } = await (async () => { | ||
| try { | ||
| return await iterator.next(); | ||
| } catch (error) { | ||
| throw await mapError(error); | ||
| } | ||
| })(); | ||
| let mappedValue = await maps.value(value, done); | ||
| if (mappedValue !== value) { | ||
| const meta = getEventMeta(value); | ||
| if (meta && isTypescriptObject(mappedValue)) { | ||
| mappedValue = withEventMeta(mappedValue, meta); | ||
| } | ||
| } | ||
| return { done, value: mappedValue }; | ||
| }, async () => { | ||
| try { | ||
| await iterator.return?.(); | ||
| } catch (error) { | ||
| throw await mapError(error); | ||
| } | ||
| }); | ||
| } | ||
| export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, mapEventIterator as m, toORPCError as t }; |
| import { PromiseWithError } from '@orpc/shared'; | ||
| type HTTPPath = `/${string}`; | ||
| type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; | ||
| type ClientContext = Record<PropertyKey, any>; | ||
| interface ClientOptions<T extends ClientContext> { | ||
| signal?: AbortSignal; | ||
| lastEventId?: string | undefined; | ||
| context: T; | ||
| } | ||
| type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? { | ||
| context?: T; | ||
| } : { | ||
| context: T; | ||
| }); | ||
| type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>]; | ||
| type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>; | ||
| interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> { | ||
| (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>; | ||
| } | ||
| type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | { | ||
| [k: string]: NestedClient<TClientContext>; | ||
| }; | ||
| type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never; | ||
| interface ClientLink<TClientContext extends ClientContext> { | ||
| call: (path: readonly 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 NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.unnoq.com/docs/error-handling#type‐safe-error-handling). | ||
| * | ||
| * Produces a nested map where each endpoint's error type is preserved. | ||
| */ | ||
| type InferClientErrors<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrors<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.unnoq.com/docs/error-handling#type‐safe-error-handling). | ||
| * | ||
| * Useful when you want to handle all possible errors from any endpoint at once. | ||
| */ | ||
| type InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never; | ||
| }[keyof T]; | ||
| export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l }; |
| import { PromiseWithError } from '@orpc/shared'; | ||
| type HTTPPath = `/${string}`; | ||
| type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; | ||
| type ClientContext = Record<PropertyKey, any>; | ||
| interface ClientOptions<T extends ClientContext> { | ||
| signal?: AbortSignal; | ||
| lastEventId?: string | undefined; | ||
| context: T; | ||
| } | ||
| type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (Record<never, never> extends T ? { | ||
| context?: T; | ||
| } : { | ||
| context: T; | ||
| }); | ||
| type ClientRest<TClientContext extends ClientContext, TInput> = Record<never, never> extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>]; | ||
| type ClientPromiseResult<TOutput, TError> = PromiseWithError<TOutput, TError>; | ||
| interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> { | ||
| (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>; | ||
| } | ||
| type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | { | ||
| [k: string]: NestedClient<TClientContext>; | ||
| }; | ||
| type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never; | ||
| interface ClientLink<TClientContext extends ClientContext> { | ||
| call: (path: readonly 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 NestedClient<any>> = T extends Client<any, infer U, any, any> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, infer U, any, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, infer U, any> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? 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 NestedClient<any>> = T extends Client<any, any, infer U, any> ? U extends { | ||
| body: infer UBody; | ||
| } ? UBody : U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? InferClientBodyOutputs<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.unnoq.com/docs/error-handling#type‐safe-error-handling). | ||
| * | ||
| * Produces a nested map where each endpoint's error type is preserved. | ||
| */ | ||
| type InferClientErrors<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrors<T[K]> : never; | ||
| }; | ||
| /** | ||
| * Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.unnoq.com/docs/error-handling#type‐safe-error-handling). | ||
| * | ||
| * Useful when you want to handle all possible errors from any endpoint at once. | ||
| */ | ||
| type InferClientErrorUnion<T extends NestedClient<any>> = T extends Client<any, any, any, infer U> ? U : { | ||
| [K in keyof T]: T[K] extends NestedClient<any> ? InferClientErrorUnion<T[K]> : never; | ||
| }[keyof T]; | ||
| export type { ClientLink as C, FriendlyClientOptions as F, HTTPPath as H, InferClientContext as I, NestedClient as N, ClientPromiseResult as a, ClientContext as b, ClientOptions as c, Client as d, ClientRest as e, HTTPMethod as f, InferClientInputs as g, InferClientBodyInputs as h, InferClientOutputs as i, InferClientBodyOutputs as j, InferClientErrors as k, InferClientErrorUnion as l }; |
| import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BH1AYT_p.js'; | ||
| import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.De8SW4Kw.js'; | ||
| import { Segment, Value, Promisable } from '@orpc/shared'; | ||
| import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: { | ||
| readonly BIGINT: 0; | ||
| readonly DATE: 1; | ||
| readonly NAN: 2; | ||
| readonly UNDEFINED: 3; | ||
| readonly URL: 4; | ||
| readonly REGEXP: 5; | ||
| readonly SET: 6; | ||
| readonly MAP: 7; | ||
| }; | ||
| type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]]; | ||
| type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]]; | ||
| interface StandardRPCCustomJsonSerializer { | ||
| type: number; | ||
| condition(data: unknown): boolean; | ||
| serialize(data: any): unknown; | ||
| deserialize(serialized: any): unknown; | ||
| } | ||
| interface StandardRPCJsonSerializerOptions { | ||
| customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[]; | ||
| } | ||
| declare class StandardRPCJsonSerializer { | ||
| private readonly customSerializers; | ||
| constructor(options?: StandardRPCJsonSerializerOptions); | ||
| serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized; | ||
| deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown; | ||
| deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown; | ||
| } | ||
| declare class StandardRPCSerializer { | ||
| #private; | ||
| private readonly jsonSerializer; | ||
| constructor(jsonSerializer: StandardRPCJsonSerializer); | ||
| serialize(data: unknown): object; | ||
| deserialize(data: unknown): unknown; | ||
| } | ||
| interface StandardRPCLinkCodecOptions<T extends ClientContext> { | ||
| /** | ||
| * Base url for all requests. | ||
| */ | ||
| url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The maximum length of the URL. | ||
| * | ||
| * @default 2083 | ||
| */ | ||
| maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The method used to make the request. | ||
| * | ||
| * @default 'POST' | ||
| */ | ||
| method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The method to use when the payload cannot safely pass to the server with method return from method function. | ||
| * GET is not allowed, it's very dangerous. | ||
| * | ||
| * @default 'POST' | ||
| */ | ||
| fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>; | ||
| /** | ||
| * Inject headers to the request. | ||
| */ | ||
| headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| } | ||
| declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> { | ||
| private readonly serializer; | ||
| private readonly baseUrl; | ||
| private readonly maxUrlLength; | ||
| private readonly fallbackMethod; | ||
| private readonly expectedMethod; | ||
| private readonly headers; | ||
| constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>); | ||
| encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>; | ||
| decode(response: StandardLazyResponse): Promise<unknown>; | ||
| } | ||
| interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions { | ||
| } | ||
| declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> { | ||
| constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>); | ||
| } | ||
| export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j }; | ||
| export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h }; |
| import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared'; | ||
| import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server'; | ||
| import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, m as mapEventIterator, t as toORPCError } from './client.-NUQxnPk.mjs'; | ||
| import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch'; | ||
| class CompositeStandardLinkPlugin { | ||
| plugins; | ||
| constructor(plugins = []) { | ||
| this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0)); | ||
| } | ||
| init(options) { | ||
| for (const plugin of this.plugins) { | ||
| plugin.init?.(options); | ||
| } | ||
| } | ||
| } | ||
| class StandardLink { | ||
| constructor(codec, sender, options = {}) { | ||
| this.codec = codec; | ||
| this.sender = sender; | ||
| const plugin = new CompositeStandardLinkPlugin(options.plugins); | ||
| plugin.init(options); | ||
| this.interceptors = toArray(options.interceptors); | ||
| this.clientInterceptors = toArray(options.clientInterceptors); | ||
| } | ||
| interceptors; | ||
| clientInterceptors; | ||
| call(path, input, options) { | ||
| return runWithSpan( | ||
| { name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal }, | ||
| (span) => { | ||
| span?.setAttribute("rpc.system", ORPC_NAME); | ||
| span?.setAttribute("rpc.method", path.join(".")); | ||
| if (isAsyncIteratorObject(input)) { | ||
| input = asyncIteratorWithSpan( | ||
| { name: "consume_event_iterator_input", signal: options.signal }, | ||
| input | ||
| ); | ||
| } | ||
| return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => { | ||
| const otelConfig = getGlobalOtelConfig(); | ||
| let otelContext; | ||
| const currentSpan = otelConfig?.trace.getActiveSpan() ?? span; | ||
| if (currentSpan && otelConfig) { | ||
| otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan); | ||
| } | ||
| const request = await runWithSpan( | ||
| { name: "encode_request", context: otelContext }, | ||
| () => this.codec.encode(path2, input2, options2) | ||
| ); | ||
| const response = await intercept( | ||
| this.clientInterceptors, | ||
| { ...options2, input: input2, path: path2, request }, | ||
| ({ input: input3, path: path3, request: request2, ...options3 }) => { | ||
| return runWithSpan( | ||
| { name: "send_request", signal: options3.signal, context: otelContext }, | ||
| () => this.sender.call(request2, options3, path3, input3) | ||
| ); | ||
| } | ||
| ); | ||
| const output = await runWithSpan( | ||
| { name: "decode_response", context: otelContext }, | ||
| () => this.codec.decode(response, options2, path2, input2) | ||
| ); | ||
| if (isAsyncIteratorObject(output)) { | ||
| return asyncIteratorWithSpan( | ||
| { name: "consume_event_iterator_output", signal: options2.signal }, | ||
| output | ||
| ); | ||
| } | ||
| return output; | ||
| }); | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES = { | ||
| BIGINT: 0, | ||
| DATE: 1, | ||
| NAN: 2, | ||
| UNDEFINED: 3, | ||
| URL: 4, | ||
| REGEXP: 5, | ||
| SET: 6, | ||
| MAP: 7 | ||
| }; | ||
| class StandardRPCJsonSerializer { | ||
| customSerializers; | ||
| constructor(options = {}) { | ||
| this.customSerializers = options.customJsonSerializers ?? []; | ||
| if (this.customSerializers.length !== new Set(this.customSerializers.map((custom) => custom.type)).size) { | ||
| throw new Error("Custom serializer type must be unique."); | ||
| } | ||
| } | ||
| serialize(data, segments = [], meta = [], maps = [], blobs = []) { | ||
| for (const custom of this.customSerializers) { | ||
| if (custom.condition(data)) { | ||
| const result = this.serialize(custom.serialize(data), segments, meta, maps, blobs); | ||
| meta.push([custom.type, ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| if (data instanceof Blob) { | ||
| maps.push(segments); | ||
| blobs.push(data); | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| if (typeof data === "bigint") { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof Date) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE, ...segments]); | ||
| if (Number.isNaN(data.getTime())) { | ||
| return [null, meta, maps, blobs]; | ||
| } | ||
| return [data.toISOString(), meta, maps, blobs]; | ||
| } | ||
| if (Number.isNaN(data)) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN, ...segments]); | ||
| return [null, meta, maps, blobs]; | ||
| } | ||
| if (data instanceof URL) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof RegExp) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof Set) { | ||
| const result = this.serialize(Array.from(data), segments, meta, maps, blobs); | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET, ...segments]); | ||
| return result; | ||
| } | ||
| if (data instanceof Map) { | ||
| const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs); | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP, ...segments]); | ||
| return result; | ||
| } | ||
| if (Array.isArray(data)) { | ||
| const json = data.map((v, i) => { | ||
| if (v === void 0) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED, ...segments, i]); | ||
| return v; | ||
| } | ||
| return this.serialize(v, [...segments, i], meta, maps, blobs)[0]; | ||
| }); | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| if (isObject(data)) { | ||
| const json = {}; | ||
| for (const k in data) { | ||
| if (k === "toJSON" && typeof data[k] === "function") { | ||
| continue; | ||
| } | ||
| json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0]; | ||
| } | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| deserialize(json, meta, maps, getBlob) { | ||
| const ref = { data: json }; | ||
| if (maps && getBlob) { | ||
| maps.forEach((segments, i) => { | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| segments.forEach((segment) => { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = segment; | ||
| }); | ||
| currentRef[preSegment] = getBlob(i); | ||
| }); | ||
| } | ||
| for (const item of meta) { | ||
| const type = item[0]; | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| for (let i = 1; i < item.length; i++) { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = item[i]; | ||
| } | ||
| for (const custom of this.customSerializers) { | ||
| if (custom.type === type) { | ||
| currentRef[preSegment] = custom.deserialize(currentRef[preSegment]); | ||
| break; | ||
| } | ||
| } | ||
| switch (type) { | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT: | ||
| currentRef[preSegment] = BigInt(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE: | ||
| currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date"); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN: | ||
| currentRef[preSegment] = Number.NaN; | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED: | ||
| currentRef[preSegment] = void 0; | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL: | ||
| currentRef[preSegment] = new URL(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP: { | ||
| const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/); | ||
| currentRef[preSegment] = new RegExp(pattern, flags); | ||
| break; | ||
| } | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET: | ||
| currentRef[preSegment] = new Set(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP: | ||
| currentRef[preSegment] = new Map(currentRef[preSegment]); | ||
| break; | ||
| } | ||
| } | ||
| return ref.data; | ||
| } | ||
| } | ||
| function toHttpPath(path) { | ||
| return `/${path.map(encodeURIComponent).join("/")}`; | ||
| } | ||
| function toStandardHeaders(headers) { | ||
| if (typeof headers.forEach === "function") { | ||
| return toStandardHeaders$1(headers); | ||
| } | ||
| return headers; | ||
| } | ||
| function getMalformedResponseErrorCode(status) { | ||
| return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE"; | ||
| } | ||
| class StandardRPCLinkCodec { | ||
| constructor(serializer, options) { | ||
| this.serializer = serializer; | ||
| this.baseUrl = options.url; | ||
| this.maxUrlLength = options.maxUrlLength ?? 2083; | ||
| this.fallbackMethod = options.fallbackMethod ?? "POST"; | ||
| this.expectedMethod = options.method ?? this.fallbackMethod; | ||
| this.headers = options.headers ?? {}; | ||
| } | ||
| baseUrl; | ||
| maxUrlLength; | ||
| fallbackMethod; | ||
| expectedMethod; | ||
| headers; | ||
| async encode(path, input, options) { | ||
| let headers = toStandardHeaders(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 url = new URL(baseUrl); | ||
| url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`; | ||
| const serialized = this.serializer.serialize(input); | ||
| if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) { | ||
| const maxUrlLength = await value(this.maxUrlLength, options, path, input); | ||
| const getUrl = new URL(url); | ||
| getUrl.searchParams.append("data", stringifyJSON(serialized)); | ||
| if (getUrl.toString().length <= maxUrlLength) { | ||
| return { | ||
| body: void 0, | ||
| method: expectedMethod, | ||
| headers, | ||
| url: getUrl, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| url, | ||
| method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod, | ||
| headers, | ||
| body: serialized, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| async decode(response) { | ||
| const isOk = !isORPCErrorStatus(response.status); | ||
| const deserialized = await (async () => { | ||
| let isBodyOk = false; | ||
| try { | ||
| const body = await response.body(); | ||
| isBodyOk = true; | ||
| return this.serializer.deserialize(body); | ||
| } catch (error) { | ||
| if (!isBodyOk) { | ||
| throw new Error("Cannot parse response body, please check the response body and content-type.", { | ||
| cause: error | ||
| }); | ||
| } | ||
| throw new Error("Invalid RPC response format.", { | ||
| cause: error | ||
| }); | ||
| } | ||
| })(); | ||
| if (!isOk) { | ||
| if (isORPCErrorJson(deserialized)) { | ||
| throw createORPCErrorFromJson(deserialized); | ||
| } | ||
| throw new ORPCError(getMalformedResponseErrorCode(response.status), { | ||
| status: response.status, | ||
| data: { ...response, body: deserialized } | ||
| }); | ||
| } | ||
| return deserialized; | ||
| } | ||
| } | ||
| class StandardRPCSerializer { | ||
| constructor(jsonSerializer) { | ||
| this.jsonSerializer = jsonSerializer; | ||
| } | ||
| serialize(data) { | ||
| if (isAsyncIteratorObject(data)) { | ||
| return mapEventIterator(data, { | ||
| value: async (value) => this.#serialize(value, false), | ||
| error: async (e) => { | ||
| return new ErrorEvent({ | ||
| data: this.#serialize(toORPCError(e).toJSON(), false), | ||
| cause: e | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| return this.#serialize(data, true); | ||
| } | ||
| #serialize(data, enableFormData) { | ||
| const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data); | ||
| const meta = meta_.length === 0 ? void 0 : meta_; | ||
| if (!enableFormData || blobs.length === 0) { | ||
| 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 (isAsyncIteratorObject(data)) { | ||
| return mapEventIterator(data, { | ||
| value: async (value) => this.#deserialize(value), | ||
| error: async (e) => { | ||
| if (!(e instanceof ErrorEvent)) { | ||
| return e; | ||
| } | ||
| const deserialized = this.#deserialize(e.data); | ||
| if (isORPCErrorJson(deserialized)) { | ||
| return createORPCErrorFromJson(deserialized, { cause: e }); | ||
| } | ||
| return new ErrorEvent({ | ||
| data: deserialized, | ||
| cause: e | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| return this.#deserialize(data); | ||
| } | ||
| #deserialize(data) { | ||
| if (data === void 0) { | ||
| return void 0; | ||
| } | ||
| if (!(data instanceof FormData)) { | ||
| return this.jsonSerializer.deserialize(data.json, data.meta ?? []); | ||
| } | ||
| const serialized = JSON.parse(data.get("data")); | ||
| return this.jsonSerializer.deserialize( | ||
| serialized.json, | ||
| serialized.meta ?? [], | ||
| serialized.maps, | ||
| (i) => data.get(i.toString()) | ||
| ); | ||
| } | ||
| } | ||
| class StandardRPCLink extends StandardLink { | ||
| constructor(linkClient, options) { | ||
| const jsonSerializer = new StandardRPCJsonSerializer(options); | ||
| const serializer = new StandardRPCSerializer(jsonSerializer); | ||
| const linkCodec = new StandardRPCLinkCodec(serializer, options); | ||
| super(linkCodec, linkClient, options); | ||
| } | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, toStandardHeaders as f, getMalformedResponseErrorCode as g, toHttpPath as t }; |
| import { Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BH1AYT_p.mjs'; | ||
| interface StandardLinkPlugin<T extends ClientContext> { | ||
| order?: number; | ||
| init?(options: StandardLinkOptions<T>): void; | ||
| } | ||
| declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> { | ||
| protected readonly plugins: TPlugin[]; | ||
| constructor(plugins?: readonly TPlugin[]); | ||
| init(options: StandardLinkOptions<T>): void; | ||
| } | ||
| interface StandardLinkCodec<T extends ClientContext> { | ||
| encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>; | ||
| decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>; | ||
| } | ||
| interface StandardLinkClient<T extends ClientContext> { | ||
| call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>; | ||
| } | ||
| interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: readonly string[]; | ||
| input: unknown; | ||
| } | ||
| interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> { | ||
| request: StandardRequest; | ||
| } | ||
| interface StandardLinkOptions<T extends ClientContext> { | ||
| interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[]; | ||
| clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[]; | ||
| plugins?: StandardLinkPlugin<T>[]; | ||
| } | ||
| declare class StandardLink<T extends ClientContext> implements ClientLink<T> { | ||
| readonly codec: StandardLinkCodec<T>; | ||
| readonly sender: StandardLinkClient<T>; | ||
| private readonly interceptors; | ||
| private readonly clientInterceptors; | ||
| constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>); | ||
| call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as d }; | ||
| export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f }; |
| import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BH1AYT_p.mjs'; | ||
| import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CPgZaUox.mjs'; | ||
| import { Segment, Value, Promisable } from '@orpc/shared'; | ||
| import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: { | ||
| readonly BIGINT: 0; | ||
| readonly DATE: 1; | ||
| readonly NAN: 2; | ||
| readonly UNDEFINED: 3; | ||
| readonly URL: 4; | ||
| readonly REGEXP: 5; | ||
| readonly SET: 6; | ||
| readonly MAP: 7; | ||
| }; | ||
| type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]]; | ||
| type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]]; | ||
| interface StandardRPCCustomJsonSerializer { | ||
| type: number; | ||
| condition(data: unknown): boolean; | ||
| serialize(data: any): unknown; | ||
| deserialize(serialized: any): unknown; | ||
| } | ||
| interface StandardRPCJsonSerializerOptions { | ||
| customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[]; | ||
| } | ||
| declare class StandardRPCJsonSerializer { | ||
| private readonly customSerializers; | ||
| constructor(options?: StandardRPCJsonSerializerOptions); | ||
| serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized; | ||
| deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown; | ||
| deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown; | ||
| } | ||
| declare class StandardRPCSerializer { | ||
| #private; | ||
| private readonly jsonSerializer; | ||
| constructor(jsonSerializer: StandardRPCJsonSerializer); | ||
| serialize(data: unknown): object; | ||
| deserialize(data: unknown): unknown; | ||
| } | ||
| interface StandardRPCLinkCodecOptions<T extends ClientContext> { | ||
| /** | ||
| * Base url for all requests. | ||
| */ | ||
| url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The maximum length of the URL. | ||
| * | ||
| * @default 2083 | ||
| */ | ||
| maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The method used to make the request. | ||
| * | ||
| * @default 'POST' | ||
| */ | ||
| method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| /** | ||
| * The method to use when the payload cannot safely pass to the server with method return from method function. | ||
| * GET is not allowed, it's very dangerous. | ||
| * | ||
| * @default 'POST' | ||
| */ | ||
| fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>; | ||
| /** | ||
| * Inject headers to the request. | ||
| */ | ||
| headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>; | ||
| } | ||
| declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> { | ||
| private readonly serializer; | ||
| private readonly baseUrl; | ||
| private readonly maxUrlLength; | ||
| private readonly fallbackMethod; | ||
| private readonly expectedMethod; | ||
| private readonly headers; | ||
| constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>); | ||
| encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>; | ||
| decode(response: StandardLazyResponse): Promise<unknown>; | ||
| } | ||
| interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions { | ||
| } | ||
| declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> { | ||
| constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>); | ||
| } | ||
| export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j }; | ||
| export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h }; |
| import { Interceptor } from '@orpc/shared'; | ||
| import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server'; | ||
| import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.BH1AYT_p.js'; | ||
| interface StandardLinkPlugin<T extends ClientContext> { | ||
| order?: number; | ||
| init?(options: StandardLinkOptions<T>): void; | ||
| } | ||
| declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> { | ||
| protected readonly plugins: TPlugin[]; | ||
| constructor(plugins?: readonly TPlugin[]); | ||
| init(options: StandardLinkOptions<T>): void; | ||
| } | ||
| interface StandardLinkCodec<T extends ClientContext> { | ||
| encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>; | ||
| decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>; | ||
| } | ||
| interface StandardLinkClient<T extends ClientContext> { | ||
| call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>; | ||
| } | ||
| interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> { | ||
| path: readonly string[]; | ||
| input: unknown; | ||
| } | ||
| interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> { | ||
| request: StandardRequest; | ||
| } | ||
| interface StandardLinkOptions<T extends ClientContext> { | ||
| interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[]; | ||
| clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[]; | ||
| plugins?: StandardLinkPlugin<T>[]; | ||
| } | ||
| declare class StandardLink<T extends ClientContext> implements ClientLink<T> { | ||
| readonly codec: StandardLinkCodec<T>; | ||
| readonly sender: StandardLinkClient<T>; | ||
| private readonly interceptors; | ||
| private readonly clientInterceptors; | ||
| constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>); | ||
| call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>; | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as d }; | ||
| export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f }; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
153508
20.99%30
3.45%2199
8.49%206
101.96%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed