@orpc/client 2.0.0-beta.43 → 2.0.0-beta.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +56 -57
  2. package/dist/adapters/fetch/index.d.mts +3 -3
  3. package/dist/adapters/fetch/index.d.ts +3 -3
  4. package/dist/adapters/fetch/index.mjs +9 -3
  5. package/dist/adapters/message-port/index.d.mts +2 -2
  6. package/dist/adapters/message-port/index.d.ts +2 -2
  7. package/dist/adapters/message-port/index.mjs +3 -3
  8. package/dist/adapters/standard/index.d.mts +8 -8
  9. package/dist/adapters/standard/index.d.ts +8 -8
  10. package/dist/adapters/standard/index.mjs +3 -3
  11. package/dist/adapters/websocket/index.d.mts +9 -9
  12. package/dist/adapters/websocket/index.d.ts +9 -9
  13. package/dist/adapters/websocket/index.mjs +3 -3
  14. package/dist/index.d.mts +9 -20
  15. package/dist/index.d.ts +9 -20
  16. package/dist/index.mjs +3 -3
  17. package/dist/plugins/index.d.mts +51 -37
  18. package/dist/plugins/index.d.ts +51 -37
  19. package/dist/plugins/index.mjs +20 -10
  20. package/dist/shared/{client.Dw9_40WO.d.mts → client.BoHJeq15.d.mts} +36 -11
  21. package/dist/shared/{client.Dw9_40WO.d.ts → client.BoHJeq15.d.ts} +36 -11
  22. package/dist/shared/{client.Bstqyaro.mjs → client.Bpyj1NM2.mjs} +11 -8
  23. package/dist/shared/{client.DiHfJmHK.d.ts → client.CkwtFnrc.d.mts} +5 -5
  24. package/dist/shared/{client.BjbdW5Rj.d.mts → client.DBDKICdk.d.ts} +5 -5
  25. package/dist/shared/{client.BPa_Mmuh.d.mts → client.DqIWeNhQ.d.mts} +7 -8
  26. package/dist/shared/{client.BPa_Mmuh.d.ts → client.DqIWeNhQ.d.ts} +7 -8
  27. package/dist/shared/{client.DD2eNne_.mjs → client.LF04eOvL.mjs} +24 -6
  28. package/dist/shared/{client.DpkGsZt-.mjs → client._wG5INmC.mjs} +69 -50
  29. package/package.json +8 -8
@@ -4,7 +4,7 @@ import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
4
4
  import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standard-server/peer';
5
5
  import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.js';
6
6
  import { RPCLinkCodecOptions } from '../standard/index.js';
7
- import '../../shared/client.BPa_Mmuh.js';
7
+ import '../../shared/client.DqIWeNhQ.js';
8
8
 
9
9
  type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
10
10
  interface WebSocketLinkTransportAttemptInfo {
@@ -33,7 +33,7 @@ interface WebSocketLinkTransportReconnectOptions {
33
33
  *
34
34
  * @default info => info.attempt === 1 ? 0 : 2_000
35
35
  */
36
- delay?: undefined | ((info: WebSocketLinkTransportAttemptInfo) => number);
36
+ delay?: ((info: WebSocketLinkTransportAttemptInfo) => number) | undefined;
37
37
  /**
38
38
  * Maximum number of consecutive failed attempts before giving up.
39
39
  * When reached, calls waiting for the connection fail, and the next
@@ -42,7 +42,7 @@ interface WebSocketLinkTransportReconnectOptions {
42
42
  *
43
43
  * @default Infinity
44
44
  */
45
- maxAttempt?: undefined | number;
45
+ maxAttempt?: number | undefined;
46
46
  /**
47
47
  * Maximum number of connection attempts over the transport's lifetime,
48
48
  * successful ones included (see `totalAttempt`).
@@ -50,7 +50,7 @@ interface WebSocketLinkTransportReconnectOptions {
50
50
  *
51
51
  * @default Infinity
52
52
  */
53
- maxTotalAttempt?: undefined | number;
53
+ maxTotalAttempt?: number | undefined;
54
54
  /**
55
55
  * Whether to proactively reconnect right after the socket closes,
56
56
  * rather than waiting for the next call to trigger reconnection.
@@ -58,7 +58,7 @@ interface WebSocketLinkTransportReconnectOptions {
58
58
  *
59
59
  * @default { enabled: false }
60
60
  */
61
- onClose?: undefined | {
61
+ onClose?: {
62
62
  /**
63
63
  * Whether to proactively reconnect right after the socket closes,
64
64
  * rather than waiting for the next call to trigger reconnection.
@@ -72,8 +72,8 @@ interface WebSocketLinkTransportReconnectOptions {
72
72
  *
73
73
  * @default 0
74
74
  */
75
- delay?: number;
76
- };
75
+ delay?: number | undefined;
76
+ } | undefined;
77
77
  }
78
78
  interface WebSocketLinkTransportOptions<_T extends ClientContext> {
79
79
  /**
@@ -87,13 +87,13 @@ interface WebSocketLinkTransportOptions<_T extends ClientContext> {
87
87
  *
88
88
  * @default false
89
89
  */
90
- connectOnInit?: undefined | boolean;
90
+ connectOnInit?: boolean | undefined;
91
91
  /**
92
92
  * Reconnection behavior when the connection is lost.
93
93
  *
94
94
  * @default { enabled: false }
95
95
  */
96
- reconnect?: undefined | WebSocketLinkTransportReconnectOptions;
96
+ reconnect?: WebSocketLinkTransportReconnectOptions | undefined;
97
97
  /**
98
98
  * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
99
99
  */
@@ -1,10 +1,10 @@
1
1
  import { runWithSignal, AbortError, sleep, promiseWithResolvers, sequential, loadBytes, toStringOrBytes } from '@orpc/shared';
2
2
  import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage } from '@standard-server/peer';
3
- import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.Bstqyaro.mjs';
3
+ import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.Bpyj1NM2.mjs';
4
4
  import '@standard-server/core';
5
5
  import '@standard-server/fetch';
6
- import '../../shared/client.DpkGsZt-.mjs';
7
- import '../../shared/client.DD2eNne_.mjs';
6
+ import '../../shared/client.LF04eOvL.mjs';
7
+ import '../../shared/client._wG5INmC.mjs';
8
8
 
9
9
  const WEBSOCKET_CONNECTING = 0;
10
10
  const WEBSOCKET_OPEN = 1;
package/dist/index.d.mts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared';
2
2
  export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, PromiseWithError as ClientPromiseResult, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared';
3
- import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, F as FriendlyClientOptions, O as ORPCErrorCode, g as ORPCErrorJSON, h as ORPCError, M as MalformedResponseErrorOptions } from './shared/client.Dw9_40WO.mjs';
4
- export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, p as MalformedResponseError, N as NestedClient, q as ORPCErrorOptions } from './shared/client.Dw9_40WO.mjs';
5
- import { StandardResponse } from '@standard-server/core';
3
+ import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, F as FriendlyClientOptions, O as ORPCErrorCode, g as ORPCErrorJSON, h as ORPCError } from './shared/client.BoHJeq15.mjs';
4
+ export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, M as MalformedResponseError, p as MalformedResponseErrorOptions, N as NestedClient, q as ORPCErrorOptions, R as ResponseError, r as ResponseErrorOptions } from './shared/client.BoHJeq15.mjs';
5
+ export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.DqIWeNhQ.mjs';
6
6
  export { ErrorEvent, EventMeta, StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl, getEventMeta, unwrapEvent, withEventMeta } from '@standard-server/core';
7
- export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.BPa_Mmuh.mjs';
8
7
 
9
8
  declare function wrapAsyncIteratorPreservingEventMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>;
10
9
 
@@ -17,26 +16,26 @@ interface ORPCClientScopedOptions<TClientContext extends ClientContext, TInput,
17
16
  /**
18
17
  * Interceptors that wrap the entire client call lifecycle.
19
18
  */
20
- interceptors?: ORPCClientInterceptor<TClientContext, TInput, TOutput, TError>[];
19
+ interceptors?: ORPCClientInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
21
20
  }
22
21
  type ORPCClientScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ORPCClientScopedOptions<UClientContext, UInput, UOutput, UError> : {
23
- [K in keyof T]?: T[K] extends AnyNestedClient ? ORPCClientScoped<T[K]> : never;
22
+ [K in keyof T]?: (T[K] extends AnyNestedClient ? ORPCClientScoped<T[K]> : never) | undefined;
24
23
  };
25
24
  interface ORPCClientOptions<T extends AnyNestedClient> {
26
25
  /**
27
26
  * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
28
27
  */
29
- path?: string[];
28
+ path?: string[] | undefined;
30
29
  /**
31
30
  * Interceptors that wrap the entire client call lifecycle, applied to every procedure call.
32
31
  */
33
- interceptors?: ORPCClientInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
32
+ interceptors?: ORPCClientInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
34
33
  /**
35
34
  * Per-procedure options following the shape of the router.
36
35
  * Allows fine-grained configuration (e.g. additional interceptors) for individual procedures
37
36
  * without affecting the rest of the router.
38
37
  */
39
- scoped?: ORPCClientScoped<T>;
38
+ scoped?: ORPCClientScoped<T> | undefined;
40
39
  }
41
40
  /**
42
41
  * Creates a fully typed oRPC client from a link.
@@ -132,16 +131,6 @@ declare function isDefinedError<T>(error: T): error is Extract<T, AnyORPCError>;
132
131
  declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>;
133
132
  declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
134
133
  declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
135
- /**
136
- * Creates the `MALFORMED_ORPC_RESPONSE` `ORPCError` used when a response
137
- * does not follow the expected oRPC format. Unless overridden via `options.message`,
138
- * the message is inferred from the response body or status. The `cause` is a
139
- * `MalformedResponseError` carrying the resolved response.
140
- *
141
- * @see {@link https://orpc.dev/docs/rpc/link#malformed-responses | RPC Link - Malformed Responses}
142
- * @see {@link https://orpc.dev/docs/openapi/link#malformed-responses | OpenAPI Link - Malformed Responses}
143
- */
144
- declare function createORPCErrorFromMalformedResponse(options: MalformedResponseErrorOptions): ORPCError<'MALFORMED_ORPC_RESPONSE', StandardResponse>;
145
134
  /**
146
135
  * Clones an `ORPCError` while preserving its prototype chain, so instances of
147
136
  * `ORPCError` subclasses remain `instanceof` their class.
@@ -152,5 +141,5 @@ declare function createORPCErrorFromMalformedResponse(options: MalformedResponse
152
141
  */
153
142
  declare function cloneORPCError<T extends AnyORPCError>(error: T): T;
154
143
 
155
- export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, InferClientError as InferClientErrorUnion, MalformedResponseErrorOptions, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createORPCErrorFromMalformedResponse, createSafeClient, isDefinedError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
144
+ export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, InferClientError as InferClientErrorUnion, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
156
145
  export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared';
2
2
  export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, PromiseWithError as ClientPromiseResult, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared';
3
- import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, F as FriendlyClientOptions, O as ORPCErrorCode, g as ORPCErrorJSON, h as ORPCError, M as MalformedResponseErrorOptions } from './shared/client.Dw9_40WO.js';
4
- export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, p as MalformedResponseError, N as NestedClient, q as ORPCErrorOptions } from './shared/client.Dw9_40WO.js';
5
- import { StandardResponse } from '@standard-server/core';
3
+ import { C as ClientContext, a as ClientOptions, c as AnyNestedClient, I as InferClientContext, d as InferClientError, e as Client, b as ClientLink, A as AnyORPCError, f as ClientRest, F as FriendlyClientOptions, O as ORPCErrorCode, g as ORPCErrorJSON, h as ORPCError } from './shared/client.BoHJeq15.js';
4
+ export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, M as MalformedResponseError, p as MalformedResponseErrorOptions, N as NestedClient, q as ORPCErrorOptions, R as ResponseError, r as ResponseErrorOptions } from './shared/client.BoHJeq15.js';
5
+ export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.DqIWeNhQ.js';
6
6
  export { ErrorEvent, EventMeta, StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl, getEventMeta, unwrapEvent, withEventMeta } from '@standard-server/core';
7
- export { R as RPCJsonSerialization, a as RPCJsonSerializationMeta, b as RPCJsonSerializer, c as RPCJsonSerializerHandler, d as RPCJsonSerializerOptions, e as RPCSerializer, f as RPCSerializerOptions, g as RPCSerializerSerializeOptions } from './shared/client.BPa_Mmuh.js';
8
7
 
9
8
  declare function wrapAsyncIteratorPreservingEventMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>;
10
9
 
@@ -17,26 +16,26 @@ interface ORPCClientScopedOptions<TClientContext extends ClientContext, TInput,
17
16
  /**
18
17
  * Interceptors that wrap the entire client call lifecycle.
19
18
  */
20
- interceptors?: ORPCClientInterceptor<TClientContext, TInput, TOutput, TError>[];
19
+ interceptors?: ORPCClientInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
21
20
  }
22
21
  type ORPCClientScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ORPCClientScopedOptions<UClientContext, UInput, UOutput, UError> : {
23
- [K in keyof T]?: T[K] extends AnyNestedClient ? ORPCClientScoped<T[K]> : never;
22
+ [K in keyof T]?: (T[K] extends AnyNestedClient ? ORPCClientScoped<T[K]> : never) | undefined;
24
23
  };
25
24
  interface ORPCClientOptions<T extends AnyNestedClient> {
26
25
  /**
27
26
  * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
28
27
  */
29
- path?: string[];
28
+ path?: string[] | undefined;
30
29
  /**
31
30
  * Interceptors that wrap the entire client call lifecycle, applied to every procedure call.
32
31
  */
33
- interceptors?: ORPCClientInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
32
+ interceptors?: ORPCClientInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
34
33
  /**
35
34
  * Per-procedure options following the shape of the router.
36
35
  * Allows fine-grained configuration (e.g. additional interceptors) for individual procedures
37
36
  * without affecting the rest of the router.
38
37
  */
39
- scoped?: ORPCClientScoped<T>;
38
+ scoped?: ORPCClientScoped<T> | undefined;
40
39
  }
41
40
  /**
42
41
  * Creates a fully typed oRPC client from a link.
@@ -132,16 +131,6 @@ declare function isDefinedError<T>(error: T): error is Extract<T, AnyORPCError>;
132
131
  declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>;
133
132
  declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
134
133
  declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
135
- /**
136
- * Creates the `MALFORMED_ORPC_RESPONSE` `ORPCError` used when a response
137
- * does not follow the expected oRPC format. Unless overridden via `options.message`,
138
- * the message is inferred from the response body or status. The `cause` is a
139
- * `MalformedResponseError` carrying the resolved response.
140
- *
141
- * @see {@link https://orpc.dev/docs/rpc/link#malformed-responses | RPC Link - Malformed Responses}
142
- * @see {@link https://orpc.dev/docs/openapi/link#malformed-responses | OpenAPI Link - Malformed Responses}
143
- */
144
- declare function createORPCErrorFromMalformedResponse(options: MalformedResponseErrorOptions): ORPCError<'MALFORMED_ORPC_RESPONSE', StandardResponse>;
145
134
  /**
146
135
  * Clones an `ORPCError` while preserving its prototype chain, so instances of
147
136
  * `ORPCError` subclasses remain `instanceof` their class.
@@ -152,5 +141,5 @@ declare function createORPCErrorFromMalformedResponse(options: MalformedResponse
152
141
  */
153
142
  declare function cloneORPCError<T extends AnyORPCError>(error: T): T;
154
143
 
155
- export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, InferClientError as InferClientErrorUnion, MalformedResponseErrorOptions, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createORPCErrorFromMalformedResponse, createSafeClient, isDefinedError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
144
+ export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, InferClientError as InferClientErrorUnion, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
156
145
  export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { b as isDefinedError } from './shared/client.DpkGsZt-.mjs';
2
- export { d as RPCJsonSerializer, R as RPCSerializer, e as cloneORPCError, a as createORPCErrorFromJson, c as createORPCErrorFromMalformedResponse, i as isORPCErrorJson, t as toORPCError, w as wrapAsyncIteratorPreservingEventMeta } from './shared/client.DpkGsZt-.mjs';
1
+ import { a as isDefinedError } from './shared/client._wG5INmC.mjs';
2
+ export { b as RPCJsonSerializer, R as RPCSerializer, d as cloneORPCError, c as createORPCErrorFromJson, i as isORPCErrorJson, t as toORPCError, w as wrapAsyncIteratorPreservingEventMeta } from './shared/client._wG5INmC.mjs';
3
3
  import { toArray, intercept, isTypescriptObject } from '@orpc/shared';
4
4
  export { AsyncIteratorClass, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, consumeAsyncIterator, consumeAsyncIterator as consumeEventIterator, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared';
5
- export { C as COMMON_ERROR_STATUS_MAP, M as MalformedResponseError, O as ORPCError } from './shared/client.DD2eNne_.mjs';
5
+ export { C as COMMON_ERROR_STATUS_MAP, M as MalformedResponseError, O as ORPCError, R as ResponseError } from './shared/client.LF04eOvL.mjs';
6
6
  export { ErrorEvent, getEventMeta, unwrapEvent, withEventMeta } from '@standard-server/core';
7
7
 
8
8
  const RECURSIVE_CLIENT_UNWRAP_KEYS = /* @__PURE__ */ new Set([
@@ -3,7 +3,19 @@ import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } f
3
3
  import { ClientContext } from '../index.mjs';
4
4
  import { StandardLinkPlugin, StandardLinkTransportInterceptorOptions, StandardLinkOptions, StandardLinkInterceptorOptions } from '../adapters/standard/index.mjs';
5
5
 
6
- type BatchLinkPluginMode = 'streaming' | 'buffered';
6
+ /**
7
+ * Header that marks a request as a batch, set by the Batch Link Plugin and detected by the Batch Handler Plugin.
8
+ * Nothing between the client and server, such as a CORS policy or proxy, should block or strip it.
9
+ *
10
+ * @see {@link https://orpc.dev/docs/plugins/batch#setup | Batch Plugin - Setup}
11
+ */
12
+ declare const BATCH_HEADER = "orpc-batch";
13
+ /**
14
+ * Default `maxSize` of both the Batch Link Plugin and the Batch Handler Plugin.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
17
+ */
18
+ declare const DEFAULT_BATCH_MAX_SIZE = 10;
7
19
  interface BatchLinkPluginGroup<T extends ClientContext> {
8
20
  /**
9
21
  * Determines whether a request should be included in this batch group.
@@ -21,7 +33,7 @@ interface BatchLinkPluginGroup<T extends ClientContext> {
21
33
  *
22
34
  * @default []
23
35
  */
24
- path?: Value<string[], [items: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
36
+ path?: Value<string[], [items: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
25
37
  }
26
38
  interface BatchLinkPluginOptions<T extends ClientContext> {
27
39
  groups: [BatchLinkPluginGroup<T>, ...BatchLinkPluginGroup<T>[]];
@@ -30,20 +42,22 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
30
42
  *
31
43
  * @default () => true
32
44
  */
33
- filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
45
+ filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]> | undefined;
34
46
  /**
35
47
  * Only requests with the same scope are batched together.
36
48
  * On the server, return a value unique to the incoming request so different users never share a batch.
37
49
  *
38
50
  * @default () => undefined
39
51
  */
40
- scope?: (options: StandardLinkTransportInterceptorOptions<T>) => unknown;
52
+ scope?: ((options: StandardLinkTransportInterceptorOptions<T>) => unknown) | undefined;
41
53
  /**
42
- * The maximum number of requests in the batch.
54
+ * The maximum number of requests in the batch. Larger batches are split.
55
+ * Keep it at or below the server Batch Handler Plugin's `maxSize`, which rejects larger batches with a `413`.
43
56
  *
44
- * @default 10
57
+ * @default DEFAULT_BATCH_MAX_SIZE (10)
58
+ * @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
45
59
  */
46
- maxSize?: Value<Promisable<number>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
60
+ maxSize?: Value<Promisable<number>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
47
61
  /**
48
62
  * How long (in ms) to wait for more requests before sending the batch,
49
63
  * counted from the first queued request.
@@ -51,19 +65,13 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
51
65
  *
52
66
  * @default 0
53
67
  */
54
- wait?: number;
55
- /**
56
- * The batch response mode.
57
- *
58
- * @default 'streaming'
59
- */
60
- mode?: Value<BatchLinkPluginMode, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
68
+ wait?: number | undefined;
61
69
  /**
62
70
  * URL for the batch request.
63
71
  *
64
72
  * @default URL of the first subrequest in the batch + '/__batch__'
65
73
  */
66
- url?: Value<Promisable<StandardUrl>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
74
+ url?: Value<Promisable<StandardUrl>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
67
75
  /**
68
76
  * The maximum length of the URL that runtime supports,
69
77
  * if exceeded, the batch will be split into smaller batches and sent sequentially.
@@ -72,25 +80,25 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
72
80
  *
73
81
  * @default 2083
74
82
  */
75
- maxUrlLength?: Value<Promisable<number>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
83
+ maxUrlLength?: Value<Promisable<number>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
76
84
  /**
77
85
  * Headers used for the batch request.
78
86
  *
79
87
  * @default Common headers among all subrequests in the batch.
80
88
  */
81
- headers?: Value<Promisable<StandardHeaders>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
89
+ headers?: Value<Promisable<StandardHeaders>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
82
90
  /**
83
91
  * Map each subrequest in the batch before it is sent.
84
92
  *
85
93
  * @default Removes headers that are duplicated with the batch headers
86
94
  */
87
- mapSubrequest?: (subOptions: StandardLinkTransportInterceptorOptions<T>, partialBatchRequest: Pick<StandardRequest, 'url' | 'headers'>) => StandardRequest;
95
+ mapSubrequest?: ((subOptions: StandardLinkTransportInterceptorOptions<T>, partialBatchRequest: Pick<StandardRequest, 'url' | 'headers'>) => StandardRequest) | undefined;
88
96
  /**
89
97
  * Maps each subresponse before returning the final response.
90
98
  *
91
99
  * @default Low-priority merges headers from the batch response into each subresponse.
92
100
  */
93
- mapSubresponse?: (subResponse: StandardLazyResponse, batchResponse: StandardLazyResponse, subOptions: StandardLinkTransportInterceptorOptions<T>) => StandardLazyResponse;
101
+ mapSubresponse?: ((subResponse: StandardLazyResponse, batchResponse: StandardLazyResponse, subOptions: StandardLinkTransportInterceptorOptions<T>) => StandardLazyResponse) | undefined;
94
102
  }
95
103
  /**
96
104
  * Combines multiple client requests into a single batch request
@@ -108,7 +116,6 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
108
116
  private readonly scope;
109
117
  private readonly maxSize;
110
118
  private readonly wait;
111
- private readonly mode;
112
119
  private readonly batchUrl;
113
120
  private readonly maxUrlLength;
114
121
  private readonly batchHeaders;
@@ -151,14 +158,14 @@ interface DedupeLinkPluginOptions<T extends ClientContext> {
151
158
  *
152
159
  * @default ({ request }) => request.method === 'GET' || request.method === 'QUERY'
153
160
  */
154
- filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
161
+ filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]> | undefined;
155
162
  /**
156
163
  * Only requests with the same scope are deduplicated together.
157
164
  * On the server, return a value unique to the incoming request so different users never share a response.
158
165
  *
159
166
  * @default () => undefined
160
167
  */
161
- scope?: (options: StandardLinkTransportInterceptorOptions<T>) => unknown;
168
+ scope?: ((options: StandardLinkTransportInterceptorOptions<T>) => unknown) | undefined;
162
169
  /**
163
170
  * How long (in ms) to wait for more identical requests before sending,
164
171
  * counted from the first queued request.
@@ -166,7 +173,7 @@ interface DedupeLinkPluginOptions<T extends ClientContext> {
166
173
  *
167
174
  * @default 0
168
175
  */
169
- wait?: number;
176
+ wait?: number | undefined;
170
177
  }
171
178
  /**
172
179
  * Prevents redundant requests by deduplicating similar in-flight requests,
@@ -195,7 +202,7 @@ interface RequestCompressionLinkPluginOptions<T extends ClientContext> {
195
202
  *
196
203
  * @default 'gzip'
197
204
  */
198
- encoding?: 'gzip' | 'deflate' | 'deflate-raw';
205
+ encoding?: 'gzip' | 'deflate' | 'deflate-raw' | undefined;
199
206
  /**
200
207
  * The minimum request size in bytes required to trigger compression.
201
208
  * Requests smaller than this threshold will not be compressed to avoid overhead.
@@ -203,7 +210,7 @@ interface RequestCompressionLinkPluginOptions<T extends ClientContext> {
203
210
  *
204
211
  * @default 1024 (1KB)
205
212
  */
206
- threshold?: number;
213
+ threshold?: number | undefined;
207
214
  /**
208
215
  * Determines whether a request with the given Content-Type should be compressed.
209
216
  * Only consulted for binary transfers (streams, files, and file form-data parts).
@@ -211,7 +218,7 @@ interface RequestCompressionLinkPluginOptions<T extends ClientContext> {
211
218
  *
212
219
  * @default isCompressibleContentType (covers common text-based formats)
213
220
  */
214
- isCompressibleContentType?: (contentType: string | null | undefined, options: StandardLinkTransportInterceptorOptions<T>) => boolean;
221
+ isCompressibleContentType?: ((contentType: string | null | undefined, options: StandardLinkTransportInterceptorOptions<T>) => boolean) | undefined;
215
222
  }
216
223
  /**
217
224
  * Compresses request bodies before sending them to the server,
@@ -239,7 +246,7 @@ interface ResponseCompressionLinkPluginOptions<_T extends ClientContext> {
239
246
  *
240
247
  * @default ['gzip', 'deflate']
241
248
  */
242
- encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[];
249
+ encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[] | undefined;
243
250
  }
244
251
  /**
245
252
  * Advertises Accept-Encoding on requests and decompresses response bodies
@@ -286,7 +293,7 @@ interface RetryLinkPluginContext {
286
293
  *
287
294
  * @default 0
288
295
  */
289
- retry?: Value<Promisable<number>, [Omit<StandardLinkInterceptorOptions<RetryLinkPluginContext>, 'next'>]>;
296
+ retry?: Value<Promisable<number>, [Omit<StandardLinkInterceptorOptions<RetryLinkPluginContext>, 'next'>]> | undefined;
290
297
  /**
291
298
  * Delay (in ms) before retrying.
292
299
  *
@@ -295,17 +302,17 @@ interface RetryLinkPluginContext {
295
302
  *
296
303
  * @default (o) => o.lastEventRetry ?? 2000
297
304
  */
298
- retryDelay?: Value<Promisable<number>, [RetryLinkPluginAttemptOptions<RetryLinkPluginContext>]>;
305
+ retryDelay?: Value<Promisable<number>, [RetryLinkPluginAttemptOptions<RetryLinkPluginContext>]> | undefined;
299
306
  /**
300
307
  * Determine whether to retry.
301
308
  *
302
- * @default true
309
+ * @default (o) => isRetryableError(o.error)
303
310
  */
304
- shouldRetry?: Value<Promisable<boolean>, [RetryLinkPluginAttemptOptions<RetryLinkPluginContext>]>;
311
+ shouldRetry?: Value<Promisable<boolean>, [RetryLinkPluginAttemptOptions<RetryLinkPluginContext>]> | undefined;
305
312
  /**
306
313
  * Hook called before each retry. Can return a cleanup callback.
307
314
  */
308
- onRetry?: (options: RetryLinkPluginAttemptOptions<RetryLinkPluginContext>) => void | ((isSuccess: boolean) => void);
315
+ onRetry?: ((options: RetryLinkPluginAttemptOptions<RetryLinkPluginContext>) => void | ((isSuccess: boolean) => void)) | undefined;
309
316
  }
310
317
  interface RetryLinkPluginOptions<_T extends RetryLinkPluginContext> {
311
318
  /**
@@ -313,6 +320,13 @@ interface RetryLinkPluginOptions<_T extends RetryLinkPluginContext> {
313
320
  */
314
321
  default?: RetryLinkPluginContext | undefined;
315
322
  }
323
+ /**
324
+ * Default `shouldRetry` check of `RetryLinkPlugin`. Returns `false` only for errors
325
+ * from a 4xx response other than `408` and `429`.
326
+ *
327
+ * @see {@link https://orpc.dev/docs/plugins/retry#client-error-responses | Retry Plugin - Client Error Responses}
328
+ */
329
+ declare function isRetryableError(error: unknown): boolean;
316
330
  /**
317
331
  * Automatically retries failed requests based on customizable retry strategies,
318
332
  * improving the resilience of your application.
@@ -341,7 +355,7 @@ interface RetryAfterLinkPluginOptions<T extends ClientContext> {
341
355
  condition?: Value<boolean, [
342
356
  response: StandardLazyResponse,
343
357
  options: StandardLinkTransportInterceptorOptions<T>
344
- ]>;
358
+ ]> | undefined;
345
359
  /**
346
360
  * Maximum attempts before giving up retries.
347
361
  *
@@ -350,7 +364,7 @@ interface RetryAfterLinkPluginOptions<T extends ClientContext> {
350
364
  maxAttempts?: Value<number, [
351
365
  response: StandardLazyResponse,
352
366
  options: StandardLinkTransportInterceptorOptions<T>
353
- ]>;
367
+ ]> | undefined;
354
368
  /**
355
369
  * Maximum timeout in milliseconds to wait before giving up retries.
356
370
  *
@@ -359,7 +373,7 @@ interface RetryAfterLinkPluginOptions<T extends ClientContext> {
359
373
  timeout?: Value<number, [
360
374
  response: StandardLazyResponse,
361
375
  options: StandardLinkTransportInterceptorOptions<T>
362
- ]>;
376
+ ]> | undefined;
363
377
  }
364
378
  /**
365
379
  * The Retry After Link Plugin automatically retries requests based on server `retry-after` header.
@@ -402,5 +416,5 @@ declare class TimeoutLinkPlugin<T extends ClientContext> implements StandardLink
402
416
  init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
403
417
  }
404
418
 
405
- export { BatchLinkPlugin, RetryLinkPlugin as ClientRetryPlugin, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin };
406
- export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, RetryLinkPluginContext as ClientRetryPluginContext, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, TimeoutLinkPluginOptions };
419
+ export { BATCH_HEADER, BatchLinkPlugin, RetryLinkPlugin as ClientRetryPlugin, DEFAULT_BATCH_MAX_SIZE, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin, isRetryableError };
420
+ export type { BatchLinkPluginGroup, BatchLinkPluginOptions, RetryLinkPluginContext as ClientRetryPluginContext, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, TimeoutLinkPluginOptions };