@orpc/client 2.0.0-beta.3 → 2.0.0-beta.31

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 +71 -101
  2. package/dist/adapters/fetch/index.d.mts +10 -5
  3. package/dist/adapters/fetch/index.d.ts +10 -5
  4. package/dist/adapters/fetch/index.mjs +31 -6
  5. package/dist/adapters/message-port/index.d.mts +11 -6
  6. package/dist/adapters/message-port/index.d.ts +11 -6
  7. package/dist/adapters/message-port/index.mjs +20 -15
  8. package/dist/adapters/standard/index.d.mts +6 -7
  9. package/dist/adapters/standard/index.d.ts +6 -7
  10. package/dist/adapters/standard/index.mjs +3 -3
  11. package/dist/adapters/websocket/index.d.mts +19 -14
  12. package/dist/adapters/websocket/index.d.ts +19 -14
  13. package/dist/adapters/websocket/index.mjs +11 -11
  14. package/dist/index.d.mts +49 -48
  15. package/dist/index.d.ts +49 -48
  16. package/dist/index.mjs +32 -49
  17. package/dist/plugins/index.d.mts +124 -12
  18. package/dist/plugins/index.d.ts +124 -12
  19. package/dist/plugins/index.mjs +290 -23
  20. package/dist/shared/{client.Cby_-GGh.d.mts → client.B0-4UDVl.d.mts} +1 -1
  21. package/dist/shared/{client.CPF3hX6O.d.ts → client.BhTyskpV.d.ts} +1 -1
  22. package/dist/shared/{client.DMXKFDyV.mjs → client.BnATe4Ob.mjs} +176 -58
  23. package/dist/shared/{client.8ug8I-zu.d.mts → client.CFVTHyN6.d.mts} +54 -6
  24. package/dist/shared/{client.8ug8I-zu.d.ts → client.CFVTHyN6.d.ts} +54 -6
  25. package/dist/shared/{client.Dnfj8jnT.mjs → client.DcoDDrD4.mjs} +17 -8
  26. package/dist/shared/{client.BdItY5DT.d.mts → client.Qwo2aQOm.d.mts} +18 -0
  27. package/dist/shared/{client.BdItY5DT.d.ts → client.Qwo2aQOm.d.ts} +18 -0
  28. package/dist/shared/{client.DXhchJ84.mjs → client.vEM0O_Eg.mjs} +8 -9
  29. package/package.json +19 -6
@@ -1,10 +1,9 @@
1
- import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.Cby_-GGh.mjs';
2
- export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.Cby_-GGh.mjs';
1
+ import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.B0-4UDVl.mjs';
2
+ export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.B0-4UDVl.mjs';
3
3
  import { Value, Promisable } from '@orpc/shared';
4
4
  import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core';
5
- export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
6
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
7
- import { e as RPCSerializer } from '../../shared/client.BdItY5DT.mjs';
5
+ import { ClientContext, ClientOptions } from '../../index.mjs';
6
+ import { RPCSerializer } from '../../index.mjs';
8
7
 
9
8
  interface RPCLinkCodecOptions<T extends ClientContext> {
10
9
  /**
@@ -28,14 +27,14 @@ interface RPCLinkCodecOptions<T extends ClientContext> {
28
27
  *
29
28
  * @default 'POST'
30
29
  */
31
- method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
30
+ method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
32
31
  /**
33
32
  * The method to use when the payload cannot safely pass to the server with method return from method function.
34
33
  * GET is not allowed, it's very dangerous.
35
34
  *
36
35
  * @default 'POST'
37
36
  */
38
- fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
37
+ fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY';
39
38
  /**
40
39
  * Inject headers to the request.
41
40
  */
@@ -1,10 +1,9 @@
1
- import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.CPF3hX6O.js';
2
- export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.CPF3hX6O.js';
1
+ import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.BhTyskpV.js';
2
+ export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.BhTyskpV.js';
3
3
  import { Value, Promisable } from '@orpc/shared';
4
4
  import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core';
5
- export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
6
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
7
- import { e as RPCSerializer } from '../../shared/client.BdItY5DT.js';
5
+ import { ClientContext, ClientOptions } from '../../index.js';
6
+ import { RPCSerializer } from '../../index.js';
8
7
 
9
8
  interface RPCLinkCodecOptions<T extends ClientContext> {
10
9
  /**
@@ -28,14 +27,14 @@ interface RPCLinkCodecOptions<T extends ClientContext> {
28
27
  *
29
28
  * @default 'POST'
30
29
  */
31
- method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
30
+ method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
32
31
  /**
33
32
  * The method to use when the payload cannot safely pass to the server with method return from method function.
34
33
  * GET is not allowed, it's very dangerous.
35
34
  *
36
35
  * @default 'POST'
37
36
  */
38
- fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
37
+ fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'QUERY';
39
38
  /**
40
39
  * Inject headers to the request.
41
40
  */
@@ -1,6 +1,6 @@
1
- export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.DXhchJ84.mjs';
1
+ export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.vEM0O_Eg.mjs';
2
2
  import '@orpc/shared';
3
3
  import '@standardserver/core';
4
4
  import '@standardserver/fetch';
5
- import '../../shared/client.Dnfj8jnT.mjs';
6
- import '../../shared/client.DMXKFDyV.mjs';
5
+ import '../../shared/client.BnATe4Ob.mjs';
6
+ import '../../shared/client.DcoDDrD4.mjs';
@@ -1,13 +1,13 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
1
+ import { ClientContext, ClientOptions } from '../../index.mjs';
2
2
  import { Promisable } from '@orpc/shared';
3
3
  import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
4
  import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
5
- import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.Cby_-GGh.mjs';
5
+ import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.mjs';
6
6
  import { RPCLinkCodecOptions } from '../standard/index.mjs';
7
- import '../../shared/client.BdItY5DT.mjs';
7
+ import '../../shared/client.Qwo2aQOm.mjs';
8
8
 
9
9
  type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
10
- interface WebsocketLinkTransportAttemptInfo {
10
+ interface WebSocketLinkTransportAttemptInfo {
11
11
  /**
12
12
  * Total number of connection attempts for this transport's lifetime.
13
13
  * Starts at 1 on the first attempt, increments on every subsequent
@@ -21,7 +21,7 @@ interface WebsocketLinkTransportAttemptInfo {
21
21
  */
22
22
  attempt: number;
23
23
  }
24
- interface WebsocketLinkTransportReconnectOptions {
24
+ interface WebSocketLinkTransportReconnectOptions {
25
25
  /**
26
26
  * Whether to automatically reconnect when the connection is lost.
27
27
  *
@@ -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?: undefined | ((info: WebSocketLinkTransportAttemptInfo) => number);
37
37
  /**
38
38
  * Maximum number of consecutive failed attempts before giving up.
39
39
  * When exceeded, `getConnectedPeer` throws instead of retrying.
@@ -66,12 +66,12 @@ interface WebsocketLinkTransportReconnectOptions {
66
66
  delay?: number;
67
67
  };
68
68
  }
69
- interface WebsocketLinkTransportOptions<_T extends ClientContext> {
69
+ interface WebSocketLinkTransportOptions<_T extends ClientContext> {
70
70
  /**
71
71
  * Returns a WebSocket instance for peer communication.
72
72
  * Can be async for lazy resolution.
73
73
  */
74
- connect: (info: WebsocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
74
+ connect: (info: WebSocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
75
75
  /**
76
76
  * Whether to connect immediately on initialization, instead of waiting
77
77
  * for the first call. Reduces latency for the first request.
@@ -84,7 +84,7 @@ interface WebsocketLinkTransportOptions<_T extends ClientContext> {
84
84
  *
85
85
  * @default { enabled: false }
86
86
  */
87
- reconnect?: undefined | WebsocketLinkTransportReconnectOptions;
87
+ reconnect?: undefined | WebSocketLinkTransportReconnectOptions;
88
88
  /**
89
89
  * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
90
90
  */
@@ -94,7 +94,7 @@ interface WebsocketLinkTransportOptions<_T extends ClientContext> {
94
94
  */
95
95
  decodePeerMessage?: DecodePeerMessageOptions | undefined;
96
96
  }
97
- declare class WebsocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
97
+ declare class WebSocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
98
98
  private readonly connect;
99
99
  private readonly reconnectEnabled;
100
100
  private readonly reconnectDelay;
@@ -103,7 +103,7 @@ declare class WebsocketLinkTransport<T extends ClientContext> implements Standar
103
103
  private readonly reconnectOnCloseDelay;
104
104
  private readonly encodePeerMessageOptions;
105
105
  private readonly decodePeerMessageOptions;
106
- constructor(options: WebsocketLinkTransportOptions<T>);
106
+ constructor(options: WebSocketLinkTransportOptions<T>);
107
107
  send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
108
108
  private totalAttempt;
109
109
  private attempt;
@@ -111,11 +111,16 @@ declare class WebsocketLinkTransport<T extends ClientContext> implements Standar
111
111
  private getConnectedPeer;
112
112
  }
113
113
 
114
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebsocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
114
+ interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebSocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
115
115
  }
116
+ /**
117
+ * Client link that communicates with an RPC Handler over a WebSocket connection.
118
+ *
119
+ * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
120
+ */
116
121
  declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
117
122
  constructor(options: RPCLinkOptions<T>);
118
123
  }
119
124
 
120
- export { RPCLink, WebsocketLinkTransport };
121
- export type { RPCLinkOptions, WebSocketLike, WebsocketLinkTransportAttemptInfo, WebsocketLinkTransportOptions, WebsocketLinkTransportReconnectOptions };
125
+ export { RPCLink, WebSocketLinkTransport };
126
+ export type { RPCLinkOptions, WebSocketLike, WebSocketLinkTransportAttemptInfo, WebSocketLinkTransportOptions, WebSocketLinkTransportReconnectOptions };
@@ -1,13 +1,13 @@
1
- import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
1
+ import { ClientContext, ClientOptions } from '../../index.js';
2
2
  import { Promisable } from '@orpc/shared';
3
3
  import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
4
4
  import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
5
- import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.CPF3hX6O.js';
5
+ import { StandardLinkTransport, StandardLink, StandardLinkOptions } from '../standard/index.js';
6
6
  import { RPCLinkCodecOptions } from '../standard/index.js';
7
- import '../../shared/client.BdItY5DT.js';
7
+ import '../../shared/client.Qwo2aQOm.js';
8
8
 
9
9
  type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
10
- interface WebsocketLinkTransportAttemptInfo {
10
+ interface WebSocketLinkTransportAttemptInfo {
11
11
  /**
12
12
  * Total number of connection attempts for this transport's lifetime.
13
13
  * Starts at 1 on the first attempt, increments on every subsequent
@@ -21,7 +21,7 @@ interface WebsocketLinkTransportAttemptInfo {
21
21
  */
22
22
  attempt: number;
23
23
  }
24
- interface WebsocketLinkTransportReconnectOptions {
24
+ interface WebSocketLinkTransportReconnectOptions {
25
25
  /**
26
26
  * Whether to automatically reconnect when the connection is lost.
27
27
  *
@@ -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?: undefined | ((info: WebSocketLinkTransportAttemptInfo) => number);
37
37
  /**
38
38
  * Maximum number of consecutive failed attempts before giving up.
39
39
  * When exceeded, `getConnectedPeer` throws instead of retrying.
@@ -66,12 +66,12 @@ interface WebsocketLinkTransportReconnectOptions {
66
66
  delay?: number;
67
67
  };
68
68
  }
69
- interface WebsocketLinkTransportOptions<_T extends ClientContext> {
69
+ interface WebSocketLinkTransportOptions<_T extends ClientContext> {
70
70
  /**
71
71
  * Returns a WebSocket instance for peer communication.
72
72
  * Can be async for lazy resolution.
73
73
  */
74
- connect: (info: WebsocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
74
+ connect: (info: WebSocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
75
75
  /**
76
76
  * Whether to connect immediately on initialization, instead of waiting
77
77
  * for the first call. Reduces latency for the first request.
@@ -84,7 +84,7 @@ interface WebsocketLinkTransportOptions<_T extends ClientContext> {
84
84
  *
85
85
  * @default { enabled: false }
86
86
  */
87
- reconnect?: undefined | WebsocketLinkTransportReconnectOptions;
87
+ reconnect?: undefined | WebSocketLinkTransportReconnectOptions;
88
88
  /**
89
89
  * Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
90
90
  */
@@ -94,7 +94,7 @@ interface WebsocketLinkTransportOptions<_T extends ClientContext> {
94
94
  */
95
95
  decodePeerMessage?: DecodePeerMessageOptions | undefined;
96
96
  }
97
- declare class WebsocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
97
+ declare class WebSocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
98
98
  private readonly connect;
99
99
  private readonly reconnectEnabled;
100
100
  private readonly reconnectDelay;
@@ -103,7 +103,7 @@ declare class WebsocketLinkTransport<T extends ClientContext> implements Standar
103
103
  private readonly reconnectOnCloseDelay;
104
104
  private readonly encodePeerMessageOptions;
105
105
  private readonly decodePeerMessageOptions;
106
- constructor(options: WebsocketLinkTransportOptions<T>);
106
+ constructor(options: WebSocketLinkTransportOptions<T>);
107
107
  send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
108
108
  private totalAttempt;
109
109
  private attempt;
@@ -111,11 +111,16 @@ declare class WebsocketLinkTransport<T extends ClientContext> implements Standar
111
111
  private getConnectedPeer;
112
112
  }
113
113
 
114
- interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebsocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
114
+ interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebSocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
115
115
  }
116
+ /**
117
+ * Client link that communicates with an RPC Handler over a WebSocket connection.
118
+ *
119
+ * @see {@link https://orpc.dev/docs/adapters/websocket | WebSocket Adapters}
120
+ */
116
121
  declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
117
122
  constructor(options: RPCLinkOptions<T>);
118
123
  }
119
124
 
120
- export { RPCLink, WebsocketLinkTransport };
121
- export type { RPCLinkOptions, WebSocketLike, WebsocketLinkTransportAttemptInfo, WebsocketLinkTransportOptions, WebsocketLinkTransportReconnectOptions };
125
+ export { RPCLink, WebSocketLinkTransport };
126
+ export type { RPCLinkOptions, WebSocketLike, WebSocketLinkTransportAttemptInfo, WebSocketLinkTransportOptions, WebSocketLinkTransportReconnectOptions };
@@ -1,14 +1,14 @@
1
- import { runWithSignal, AbortError, sleep, promiseWithResolvers, toStringOrBytes } from '@orpc/shared';
1
+ import { runWithSignal, AbortError, sleep, promiseWithResolvers, sequential, loadBytes, toStringOrBytes } from '@orpc/shared';
2
2
  import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage } from '@standardserver/peer';
3
- import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.DXhchJ84.mjs';
3
+ import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.vEM0O_Eg.mjs';
4
4
  import '@standardserver/core';
5
5
  import '@standardserver/fetch';
6
- import '../../shared/client.Dnfj8jnT.mjs';
7
- import '../../shared/client.DMXKFDyV.mjs';
6
+ import '../../shared/client.BnATe4Ob.mjs';
7
+ import '../../shared/client.DcoDDrD4.mjs';
8
8
 
9
9
  const WEBSOCKET_CONNECTING = 0;
10
10
  const WEBSOCKET_OPEN = 1;
11
- class WebsocketLinkTransport {
11
+ class WebSocketLinkTransport {
12
12
  connect;
13
13
  reconnectEnabled;
14
14
  reconnectDelay;
@@ -71,13 +71,13 @@ class WebsocketLinkTransport {
71
71
  connectingResolvers?.resolve();
72
72
  });
73
73
  }
74
- websocket.addEventListener("message", async (event) => {
75
- const message = await toStringOrBytes(event.data);
74
+ websocket.addEventListener("message", sequential(async (event) => {
75
+ const message = event.data instanceof Blob ? await loadBytes(event.data) : toStringOrBytes(event.data);
76
76
  const result = decodePeerMessage(message, this.decodePeerMessageOptions);
77
77
  if (result.matched && isServerPeerSendMessage(result.message)) {
78
- await peer.message(result.message);
78
+ peer.message(result.message);
79
79
  }
80
- });
80
+ }));
81
81
  websocket.addEventListener("close", async (event) => {
82
82
  connectingResolvers?.resolve();
83
83
  if (this.reconnectOnCloseEnabled) {
@@ -102,9 +102,9 @@ class WebsocketLinkTransport {
102
102
  class RPCLink extends StandardLink {
103
103
  constructor(options) {
104
104
  const codec = new RPCLinkCodec(options);
105
- const transport = new WebsocketLinkTransport(options);
105
+ const transport = new WebSocketLinkTransport(options);
106
106
  super(codec, transport, options);
107
107
  }
108
108
  }
109
109
 
110
- export { RPCLink, WebsocketLinkTransport };
110
+ export { RPCLink, WebSocketLinkTransport };
package/dist/index.d.mts CHANGED
@@ -1,15 +1,12 @@
1
- import { O as ORPCErrorCode, c as ORPCError, d as ORPCErrorJSON, A as AnyORPCError, C as ClientContext, a as ClientOptions, e as AnyNestedClient, I as InferClientContext, f as InferClientError, g as Client, b as ClientLink, h as ClientRest, F as FriendlyClientOptions } from './shared/client.8ug8I-zu.mjs';
2
- export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, N as NestedClient, p as ORPCErrorOptions } from './shared/client.8ug8I-zu.mjs';
3
- import { Interceptor, PromiseWithError, ThrowableError, Promisable, WrapAsyncIteratorOptions, AsyncIteratorClass } from '@orpc/shared';
4
- export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
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.BdItY5DT.mjs';
6
- export { ErrorEvent, EventMeta, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core';
1
+ import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared';
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.CFVTHyN6.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.CFVTHyN6.mjs';
5
+ import { StandardResponse } from '@standardserver/core';
6
+ export { ErrorEvent, EventMeta, StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/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.Qwo2aQOm.mjs';
7
8
 
8
- declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>;
9
- declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>;
10
- declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
11
- declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
12
- declare function cloneORPCError<T extends ORPCErrorCode, TData>(error: ORPCError<T, TData>): ORPCError<T, TData>;
9
+ declare function wrapAsyncIteratorPreservingEventMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>;
13
10
 
14
11
  interface ORPCClientInterceptorOptions<TClientContext extends ClientContext, TInput> extends ClientOptions<TClientContext> {
15
12
  path: string[];
@@ -41,6 +38,13 @@ interface ORPCClientOptions<T extends AnyNestedClient> {
41
38
  */
42
39
  scoped?: ORPCClientScoped<T>;
43
40
  }
41
+ /**
42
+ * Creates a fully typed oRPC client from a link.
43
+ * The returned client mirrors the shape of your router or contract,
44
+ * so calling a procedure is as simple as calling a function.
45
+ *
46
+ * @see {@link https://orpc.dev/docs/client/client-side | Client-Side Clients}
47
+ */
44
48
  declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T;
45
49
 
46
50
  declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
@@ -72,37 +76,11 @@ type SafeResult<TOutput, TError> = [error: null, data: TOutput, inferableError:
72
76
  * if (inferableError) {
73
77
  * console.log(inferableError) // or error, both are well typed
74
78
  * }
75
- */
76
- declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
77
- interface ConsumeEventIteratorOptions<T, TReturn, TError> {
78
- /**
79
- * Called on each event
80
- */
81
- onEvent: (event: T) => void;
82
- /**
83
- * Called once error happens
84
- */
85
- onError?: (error: TError) => void;
86
- /**
87
- * Called once event iterator is done
88
- *
89
- * @info If iterator is canceled, `undefined` can be passed on success
90
- */
91
- onSuccess?: (value: TReturn | undefined) => void;
92
- /**
93
- * Called once after onError or onSuccess
94
- *
95
- * @info If iterator is canceled, `undefined` can be passed on success
96
- */
97
- onFinish?: (state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void;
98
- }
99
- /**
100
- * Consumes an event iterator with lifecycle callbacks
79
+ * ```
101
80
  *
102
- * @warning If no `onError` or `onFinish` is provided, error will be thrown into unhandled rejection channel.
103
- * @return unsubscribe callback
81
+ * @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isinferableerror | Client Error Handling - Using safe and isInferableError}
104
82
  */
105
- declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | PromiseWithError<AsyncIterator<T, TReturn>, TError>, options: ConsumeEventIteratorOptions<T, TReturn, TError>): () => Promise<void>;
83
+ declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
106
84
 
107
85
  type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
108
86
  [K in keyof T]: T[K] extends AnyNestedClient ? SafeClient<T[K]> : never;
@@ -117,7 +95,7 @@ type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, in
117
95
  * // or const [error, data, inferrableError, isSuccess] = await safeClient.doSomething({ id: '123' })
118
96
  * ```
119
97
  *
120
- * @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs}
98
+ * @see {@link https://orpc.dev/docs/client/error-handling#safe-client | Client Error Handling - Safe Client}
121
99
  */
122
100
  declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeClient<T>;
123
101
 
@@ -136,7 +114,7 @@ declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<string>;
136
114
  * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
137
115
  * based on the request path, input, and context.
138
116
  *
139
- * @see {@link https://orpc.dev/docs/client/dynamic-link Dynamic Link Docs}
117
+ * @see {@link https://orpc.dev/docs/client/dynamic-link | DynamicLink}
140
118
  */
141
119
  declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
142
120
  private readonly linkResolver;
@@ -144,12 +122,35 @@ declare class DynamicLink<TClientContext extends ClientContext> implements Clien
144
122
  call(path: string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
145
123
  }
146
124
 
147
- declare function wrapEventIteratorPreservingMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>;
148
-
149
125
  /**
150
- * @deprecated Use `isInferableError` instead.
126
+ * Checks if an error is an `ORPCError` whose type is inferable at the TypeScript level,
127
+ * narrowing it so `code` and `data` are fully typed.
128
+ *
129
+ * @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isinferableerror | Client Error Handling - Using safe and isInferableError}
130
+ */
131
+ declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>;
132
+ declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>;
133
+ declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
134
+ 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
+ /**
146
+ * Clones an `ORPCError` while preserving its prototype chain, so instances of
147
+ * `ORPCError` subclasses remain `instanceof` their class.
148
+ *
149
+ * Limitation: subclass constructors are not re-run, so private fields
150
+ * (`#field`) are not carried over and subclass members that read them
151
+ * will throw on the clone.
151
152
  */
152
- declare const isDefinedError: typeof isInferableError;
153
+ declare function cloneORPCError<T extends AnyORPCError>(error: T): T;
153
154
 
154
- export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, consumeEventIterator, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapEventIteratorPreservingMeta };
155
- export type { ConsumeEventIteratorOptions, ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
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, isInferableError as isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
156
+ export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,12 @@
1
- import { O as ORPCErrorCode, c as ORPCError, d as ORPCErrorJSON, A as AnyORPCError, C as ClientContext, a as ClientOptions, e as AnyNestedClient, I as InferClientContext, f as InferClientError, g as Client, b as ClientLink, h as ClientRest, F as FriendlyClientOptions } from './shared/client.8ug8I-zu.js';
2
- export { i as AnyORPCErrorJSON, j as COMMON_ERROR_STATUS_MAP, k as InferClientBodyInputs, l as InferClientBodyOutputs, m as InferClientErrors, n as InferClientInputs, o as InferClientOutputs, N as NestedClient, p as ORPCErrorOptions } from './shared/client.8ug8I-zu.js';
3
- import { Interceptor, PromiseWithError, ThrowableError, Promisable, WrapAsyncIteratorOptions, AsyncIteratorClass } from '@orpc/shared';
4
- export { AsyncCleanupFn, AsyncIteratorClass, AsyncIteratorClassNextFn, MaybeOptionalOptions, PromiseWithError, Registry, ThrowableError, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
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.BdItY5DT.js';
6
- export { ErrorEvent, EventMeta, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core';
1
+ import { WrapAsyncIteratorOptions, AsyncIteratorClass, Interceptor, PromiseWithError, ThrowableError, Promisable } from '@orpc/shared';
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.CFVTHyN6.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.CFVTHyN6.js';
5
+ import { StandardResponse } from '@standardserver/core';
6
+ export { ErrorEvent, EventMeta, StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/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.Qwo2aQOm.js';
7
8
 
8
- declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>;
9
- declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>;
10
- declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
11
- declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
12
- declare function cloneORPCError<T extends ORPCErrorCode, TData>(error: ORPCError<T, TData>): ORPCError<T, TData>;
9
+ declare function wrapAsyncIteratorPreservingEventMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>;
13
10
 
14
11
  interface ORPCClientInterceptorOptions<TClientContext extends ClientContext, TInput> extends ClientOptions<TClientContext> {
15
12
  path: string[];
@@ -41,6 +38,13 @@ interface ORPCClientOptions<T extends AnyNestedClient> {
41
38
  */
42
39
  scoped?: ORPCClientScoped<T>;
43
40
  }
41
+ /**
42
+ * Creates a fully typed oRPC client from a link.
43
+ * The returned client mirrors the shape of your router or contract,
44
+ * so calling a procedure is as simple as calling a function.
45
+ *
46
+ * @see {@link https://orpc.dev/docs/client/client-side | Client-Side Clients}
47
+ */
44
48
  declare function createORPCClient<T extends AnyNestedClient>(link: ClientLink<InferClientContext<T>>, { path, ...options }?: NoInfer<ORPCClientOptions<T>>): T;
45
49
 
46
50
  declare function resolveFriendlyClientOptions<T extends ClientContext>(options: FriendlyClientOptions<T>): ClientOptions<T>;
@@ -72,37 +76,11 @@ type SafeResult<TOutput, TError> = [error: null, data: TOutput, inferableError:
72
76
  * if (inferableError) {
73
77
  * console.log(inferableError) // or error, both are well typed
74
78
  * }
75
- */
76
- declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
77
- interface ConsumeEventIteratorOptions<T, TReturn, TError> {
78
- /**
79
- * Called on each event
80
- */
81
- onEvent: (event: T) => void;
82
- /**
83
- * Called once error happens
84
- */
85
- onError?: (error: TError) => void;
86
- /**
87
- * Called once event iterator is done
88
- *
89
- * @info If iterator is canceled, `undefined` can be passed on success
90
- */
91
- onSuccess?: (value: TReturn | undefined) => void;
92
- /**
93
- * Called once after onError or onSuccess
94
- *
95
- * @info If iterator is canceled, `undefined` can be passed on success
96
- */
97
- onFinish?: (state: [error: TError, data: undefined, isSuccess: false] | [error: null, data: TReturn | undefined, isSuccess: true]) => void;
98
- }
99
- /**
100
- * Consumes an event iterator with lifecycle callbacks
79
+ * ```
101
80
  *
102
- * @warning If no `onError` or `onFinish` is provided, error will be thrown into unhandled rejection channel.
103
- * @return unsubscribe callback
81
+ * @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isinferableerror | Client Error Handling - Using safe and isInferableError}
104
82
  */
105
- declare function consumeEventIterator<T, TReturn, TError = ThrowableError>(iterator: AsyncIterator<T, TReturn> | PromiseWithError<AsyncIterator<T, TReturn>, TError>, options: ConsumeEventIteratorOptions<T, TReturn, TError>): () => Promise<void>;
83
+ declare function safe<TOutput, TError = ThrowableError>(promise: PromiseWithError<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
106
84
 
107
85
  type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, infer UInput, infer UOutput, infer UError> ? (...rest: ClientRest<UContext, UInput>) => Promise<SafeResult<UOutput, UError>> : {
108
86
  [K in keyof T]: T[K] extends AnyNestedClient ? SafeClient<T[K]> : never;
@@ -117,7 +95,7 @@ type SafeClient<T extends AnyNestedClient> = T extends Client<infer UContext, in
117
95
  * // or const [error, data, inferrableError, isSuccess] = await safeClient.doSomething({ id: '123' })
118
96
  * ```
119
97
  *
120
- * @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs}
98
+ * @see {@link https://orpc.dev/docs/client/error-handling#safe-client | Client Error Handling - Safe Client}
121
99
  */
122
100
  declare function createSafeClient<T extends AnyNestedClient>(client: T): SafeClient<T>;
123
101
 
@@ -136,7 +114,7 @@ declare const RECURSIVE_CLIENT_UNWRAP_KEYS: Set<string>;
136
114
  * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
137
115
  * based on the request path, input, and context.
138
116
  *
139
- * @see {@link https://orpc.dev/docs/client/dynamic-link Dynamic Link Docs}
117
+ * @see {@link https://orpc.dev/docs/client/dynamic-link | DynamicLink}
140
118
  */
141
119
  declare class DynamicLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
142
120
  private readonly linkResolver;
@@ -144,12 +122,35 @@ declare class DynamicLink<TClientContext extends ClientContext> implements Clien
144
122
  call(path: string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
145
123
  }
146
124
 
147
- declare function wrapEventIteratorPreservingMeta<TYield, TReturn, TMappedYield = TYield, TMappedReturn = TReturn>(iterator: AsyncIterator<TYield, TReturn>, { mapResult, mapError, ...rest }: WrapAsyncIteratorOptions<TYield, TReturn, TMappedYield, TMappedReturn>): AsyncIteratorClass<TMappedYield, TMappedReturn>;
148
-
149
125
  /**
150
- * @deprecated Use `isInferableError` instead.
126
+ * Checks if an error is an `ORPCError` whose type is inferable at the TypeScript level,
127
+ * narrowing it so `code` and `data` are fully typed.
128
+ *
129
+ * @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isinferableerror | Client Error Handling - Using safe and isInferableError}
130
+ */
131
+ declare function isInferableError<T>(error: T): error is Extract<T, AnyORPCError>;
132
+ declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<'INTERNAL_SERVER_ERROR', undefined>;
133
+ declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
134
+ 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
+ /**
146
+ * Clones an `ORPCError` while preserving its prototype chain, so instances of
147
+ * `ORPCError` subclasses remain `instanceof` their class.
148
+ *
149
+ * Limitation: subclass constructors are not re-run, so private fields
150
+ * (`#field`) are not carried over and subclass members that read them
151
+ * will throw on the clone.
151
152
  */
152
- declare const isDefinedError: typeof isInferableError;
153
+ declare function cloneORPCError<T extends AnyORPCError>(error: T): T;
153
154
 
154
- export { AnyNestedClient, AnyORPCError, Client, ClientContext, ClientLink, ClientOptions, ClientRest, DynamicLink, FriendlyClientOptions, InferClientContext, InferClientError, ORPCError, ORPCErrorCode, ORPCErrorJSON, RECURSIVE_CLIENT_UNWRAP_KEYS, cloneORPCError, consumeEventIterator, createORPCClient, createORPCErrorFromJson, createSafeClient, isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapEventIteratorPreservingMeta };
155
- export type { ConsumeEventIteratorOptions, ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };
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, isInferableError as isDefinedError, isInferableError, isORPCErrorJson, resolveClientRest, resolveFriendlyClientOptions, safe, toORPCError, wrapAsyncIteratorPreservingEventMeta };
156
+ export type { ORPCClientInterceptor, ORPCClientInterceptorOptions, ORPCClientOptions, ORPCClientScoped, ORPCClientScopedOptions, SafeClient, SafeResult };