@orpc/client 2.0.0-beta.47 → 2.0.0-beta.48

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 (91) hide show
  1. package/README.md +2 -3
  2. package/dist/adapters/fetch/index.d.mts +2 -48
  3. package/dist/adapters/fetch/index.mjs +2 -77
  4. package/dist/adapters/fetch/rpc-link.d.mts +13 -0
  5. package/dist/adapters/fetch/rpc-link.mjs +10 -0
  6. package/dist/adapters/fetch/transport.d.mts +31 -0
  7. package/dist/adapters/fetch/transport.mjs +65 -0
  8. package/dist/adapters/message-port/index.d.mts +3 -80
  9. package/dist/adapters/message-port/index.mjs +3 -101
  10. package/dist/adapters/message-port/message-port.d.mts +29 -0
  11. package/dist/adapters/message-port/message-port.mjs +43 -0
  12. package/dist/adapters/message-port/rpc-link.d.mts +14 -0
  13. package/dist/adapters/message-port/rpc-link.mjs +10 -0
  14. package/dist/adapters/message-port/transport.d.mts +35 -0
  15. package/dist/adapters/message-port/transport.mjs +47 -0
  16. package/dist/adapters/standard/codec.d.mts +14 -0
  17. package/dist/adapters/standard/codec.mjs +1 -0
  18. package/dist/adapters/standard/index.d.mts +5 -60
  19. package/dist/adapters/standard/index.mjs +4 -6
  20. package/dist/adapters/standard/link.d.mts +40 -0
  21. package/dist/adapters/standard/link.mjs +79 -0
  22. package/dist/adapters/standard/plugin.d.mts +32 -0
  23. package/dist/adapters/standard/plugin.mjs +16 -0
  24. package/dist/adapters/standard/rpc-link-codec.d.mts +55 -0
  25. package/dist/adapters/standard/rpc-link-codec.mjs +104 -0
  26. package/dist/adapters/standard/transport.d.mts +14 -0
  27. package/dist/adapters/standard/transport.mjs +1 -0
  28. package/dist/adapters/websocket/index.d.mts +2 -136
  29. package/dist/adapters/websocket/index.mjs +2 -131
  30. package/dist/adapters/websocket/rpc-link.d.mts +13 -0
  31. package/dist/adapters/websocket/rpc-link.mjs +10 -0
  32. package/dist/adapters/websocket/transport.d.mts +119 -0
  33. package/dist/adapters/websocket/transport.mjs +123 -0
  34. package/dist/async-iterator-object.d.mts +7 -0
  35. package/dist/async-iterator-object.mjs +30 -0
  36. package/dist/client-safe.d.mts +16 -0
  37. package/dist/client-safe.mjs +23 -0
  38. package/dist/client.d.mts +51 -0
  39. package/dist/client.mjs +32 -0
  40. package/dist/consts.d.mts +10 -0
  41. package/dist/consts.mjs +10 -0
  42. package/dist/dynamic-link.d.mts +13 -0
  43. package/dist/dynamic-link.mjs +12 -0
  44. package/dist/error-utils.d.mts +24 -0
  45. package/dist/error-utils.mjs +44 -0
  46. package/dist/error.d.mts +138 -0
  47. package/dist/error.mjs +105 -0
  48. package/dist/index.d.mts +42 -137
  49. package/dist/index.mjs +18 -142
  50. package/dist/plugins/batch.d.mts +150 -0
  51. package/dist/plugins/batch.mjs +339 -0
  52. package/dist/plugins/cookie-jar.d.mts +82 -0
  53. package/dist/plugins/cookie-jar.mjs +229 -0
  54. package/dist/plugins/dedupe.d.mts +58 -0
  55. package/dist/plugins/dedupe.mjs +199 -0
  56. package/dist/plugins/index.d.mts +28 -420
  57. package/dist/plugins/index.mjs +17 -971
  58. package/dist/plugins/request-compression.d.mts +44 -0
  59. package/dist/plugins/request-compression.mjs +150 -0
  60. package/dist/plugins/response-compression.d.mts +28 -0
  61. package/dist/plugins/response-compression.mjs +78 -0
  62. package/dist/plugins/retry-after.d.mts +41 -0
  63. package/dist/plugins/retry-after.mjs +71 -0
  64. package/dist/plugins/retry.d.mts +82 -0
  65. package/dist/plugins/retry.mjs +127 -0
  66. package/dist/plugins/timeout.d.mts +25 -0
  67. package/dist/plugins/timeout.mjs +36 -0
  68. package/dist/rpc-json-serializer.d.mts +99 -0
  69. package/dist/rpc-json-serializer.mjs +365 -0
  70. package/dist/rpc-serializer.d.mts +32 -0
  71. package/dist/rpc-serializer.mjs +100 -0
  72. package/dist/types.d.mts +93 -0
  73. package/dist/types.mjs +1 -0
  74. package/dist/utils.d.mts +46 -0
  75. package/dist/utils.mjs +53 -0
  76. package/package.json +5 -5
  77. package/dist/adapters/fetch/index.d.ts +0 -48
  78. package/dist/adapters/message-port/index.d.ts +0 -80
  79. package/dist/adapters/standard/index.d.ts +0 -60
  80. package/dist/adapters/websocket/index.d.ts +0 -136
  81. package/dist/index.d.ts +0 -144
  82. package/dist/plugins/index.d.ts +0 -420
  83. package/dist/shared/client.BoHJeq15.d.mts +0 -233
  84. package/dist/shared/client.BoHJeq15.d.ts +0 -233
  85. package/dist/shared/client.CKQeJJ2U.mjs +0 -172
  86. package/dist/shared/client.DqIWeNhQ.d.mts +0 -131
  87. package/dist/shared/client.DqIWeNhQ.d.ts +0 -131
  88. package/dist/shared/client.JBJwBhR8.d.ts +0 -90
  89. package/dist/shared/client.LF04eOvL.mjs +0 -115
  90. package/dist/shared/client._wG5INmC.mjs +0 -505
  91. package/dist/shared/client.euYjjcFz.d.mts +0 -90
@@ -1,420 +0,0 @@
1
- import { Value, Promisable } from '@orpc/shared';
2
- import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standard-server/core';
3
- import { ClientContext } from '../index.js';
4
- import { StandardLinkPlugin, StandardLinkTransportInterceptorOptions, StandardLinkOptions, StandardLinkInterceptorOptions } from '../adapters/standard/index.js';
5
-
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;
19
- interface BatchLinkPluginGroup<T extends ClientContext> {
20
- /**
21
- * Determines whether a request should be included in this batch group.
22
- * Requests will be evaluated against each group's condition in order,
23
- * and included in the first group whose condition returns true.
24
- * If no group's condition returns true, the request will not be batched.
25
- */
26
- condition: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
27
- /**
28
- * The client context applied to requests in this batch group for the remainder of the link chain.
29
- */
30
- context: Value<T, [items: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
31
- /**
32
- * The path segments applied to requests in this batch group for the remainder of the link chain.
33
- *
34
- * @default []
35
- */
36
- path?: Value<string[], [items: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
37
- }
38
- interface BatchLinkPluginOptions<T extends ClientContext> {
39
- groups: [BatchLinkPluginGroup<T>, ...BatchLinkPluginGroup<T>[]];
40
- /**
41
- * Filters requests to batch.
42
- *
43
- * @default () => true
44
- */
45
- filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]> | undefined;
46
- /**
47
- * Only requests with the same scope are batched together.
48
- * On the server, return a value unique to the incoming request so different users never share a batch.
49
- *
50
- * @default () => undefined
51
- */
52
- scope?: ((options: StandardLinkTransportInterceptorOptions<T>) => unknown) | undefined;
53
- /**
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`.
56
- *
57
- * @default DEFAULT_BATCH_MAX_SIZE (10)
58
- * @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
59
- */
60
- maxSize?: Value<Promisable<number>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
61
- /**
62
- * How long (in ms) to wait for more requests before sending the batch,
63
- * counted from the first queued request.
64
- * With `0`, only requests made in the same event loop tick are batched.
65
- *
66
- * @default 0
67
- */
68
- wait?: number | undefined;
69
- /**
70
- * URL for the batch request.
71
- *
72
- * @default URL of the first subrequest in the batch + '/__batch__'
73
- */
74
- url?: Value<Promisable<StandardUrl>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
75
- /**
76
- * The maximum length of the URL that runtime supports,
77
- * if exceeded, the batch will be split into smaller batches and sent sequentially.
78
- *
79
- * This only applies to GET batch requests where the batch data is sent via URL query parameter.
80
- *
81
- * @default 2083
82
- */
83
- maxUrlLength?: Value<Promisable<number>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
84
- /**
85
- * Headers used for the batch request.
86
- *
87
- * @default Common headers among all subrequests in the batch.
88
- */
89
- headers?: Value<Promisable<StandardHeaders>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
90
- /**
91
- * Map each subrequest in the batch before it is sent.
92
- *
93
- * @default Removes headers that are duplicated with the batch headers
94
- */
95
- mapSubrequest?: ((subOptions: StandardLinkTransportInterceptorOptions<T>, partialBatchRequest: Pick<StandardRequest, 'url' | 'headers'>) => StandardRequest) | undefined;
96
- /**
97
- * Maps each subresponse before returning the final response.
98
- *
99
- * @default Low-priority merges headers from the batch response into each subresponse.
100
- */
101
- mapSubresponse?: ((subResponse: StandardLazyResponse, batchResponse: StandardLazyResponse, subOptions: StandardLinkTransportInterceptorOptions<T>) => StandardLazyResponse) | undefined;
102
- }
103
- /**
104
- * Combines multiple client requests into a single batch request
105
- * and splits the batch response back into individual responses.
106
- *
107
- * @remarks
108
- * **Note**: HTTP/2 and later already multiplex requests over a single connection, so this plugin is often less useful than it once was.
109
- *
110
- * @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
111
- */
112
- declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
113
- name: string;
114
- private readonly groups;
115
- private readonly filter;
116
- private readonly scope;
117
- private readonly maxSize;
118
- private readonly wait;
119
- private readonly batchUrl;
120
- private readonly maxUrlLength;
121
- private readonly batchHeaders;
122
- private readonly mapSubrequest;
123
- private readonly mapSubresponse;
124
- private readonly queue;
125
- constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
126
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
127
- private processPendingBatches;
128
- /**
129
- * Runs the batch in the async context of its first request instead of the timer's,
130
- * so the transport and batch options see that caller's request state.
131
- * `executeBatch` always runs in the context of its first request.
132
- */
133
- private executeBatchInOwnContext;
134
- private executeBatch;
135
- }
136
-
137
- interface DedupeLinkPluginGroup<T extends ClientContext> {
138
- condition: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
139
- /**
140
- * The context used for the rest of the request lifecycle.
141
- */
142
- context: Value<T, [
143
- items: [
144
- StandardLinkTransportInterceptorOptions<T>,
145
- StandardLinkTransportInterceptorOptions<T>,
146
- ...StandardLinkTransportInterceptorOptions<T>[]
147
- ]
148
- ]>;
149
- }
150
- interface DedupeLinkPluginOptions<T extends ClientContext> {
151
- /**
152
- * To enable deduplication, a request must match at least one defined group.
153
- * Requests that fall into the same group are considered for deduplication together.
154
- */
155
- groups: [DedupeLinkPluginGroup<T>, ...DedupeLinkPluginGroup<T>[]];
156
- /**
157
- * Filters requests to dedupe.
158
- *
159
- * @default ({ request }) => request.method === 'GET' || request.method === 'QUERY'
160
- */
161
- filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]> | undefined;
162
- /**
163
- * Only requests with the same scope are deduplicated together.
164
- * On the server, return a value unique to the incoming request so different users never share a response.
165
- *
166
- * @default () => undefined
167
- */
168
- scope?: ((options: StandardLinkTransportInterceptorOptions<T>) => unknown) | undefined;
169
- /**
170
- * How long (in ms) to wait for more identical requests before sending,
171
- * counted from the first queued request.
172
- * With `0`, only requests made in the same event loop tick are deduplicated.
173
- *
174
- * @default 0
175
- */
176
- wait?: number | undefined;
177
- }
178
- /**
179
- * Prevents redundant requests by deduplicating similar in-flight requests,
180
- * reducing the number of requests sent to the server.
181
- *
182
- * @see {@link https://orpc.dev/docs/plugins/dedupe | Dedupe Plugin}
183
- */
184
- declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
185
- name: string;
186
- before: string[];
187
- private readonly groups;
188
- private readonly filter;
189
- private readonly scope;
190
- private readonly wait;
191
- private readonly queue;
192
- constructor(options: NoInfer<DedupeLinkPluginOptions<T>>);
193
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
194
- private enqueue;
195
- private processPendingRequests;
196
- private execute;
197
- }
198
-
199
- interface RequestCompressionLinkPluginOptions<T extends ClientContext> {
200
- /**
201
- * The compression scheme to use for request compression.
202
- *
203
- * @default 'gzip'
204
- */
205
- encoding?: 'gzip' | 'deflate' | 'deflate-raw' | undefined;
206
- /**
207
- * The minimum request size in bytes required to trigger compression.
208
- * Requests smaller than this threshold will not be compressed to avoid overhead.
209
- * If the request size cannot be determined, compression will still be applied.
210
- *
211
- * @default 1024 (1KB)
212
- */
213
- threshold?: number | undefined;
214
- /**
215
- * Determines whether a request with the given Content-Type should be compressed.
216
- * Only consulted for binary transfers (streams, files, and file form-data parts).
217
- * Also receives the transport interceptor options for per-request decisions.
218
- *
219
- * @default isCompressibleContentType (covers common text-based formats)
220
- */
221
- isCompressibleContentType?: ((contentType: string | null | undefined, options: StandardLinkTransportInterceptorOptions<T>) => boolean) | undefined;
222
- }
223
- /**
224
- * Compresses request bodies before sending them to the server,
225
- * reducing bandwidth usage for large payloads.
226
- *
227
- * @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
228
- */
229
- declare class RequestCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
230
- name: string;
231
- /**
232
- * Compression should be done after batching, to compress the final request
233
- */
234
- after: string[];
235
- private readonly encoding;
236
- private readonly threshold;
237
- private readonly isCompressibleContentType;
238
- constructor(options?: RequestCompressionLinkPluginOptions<T>);
239
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
240
- }
241
-
242
- interface ResponseCompressionLinkPluginOptions<_T extends ClientContext> {
243
- /**
244
- * Compression schemes to advertise via Accept-Encoding, in preference order.
245
- * Only schemes that can be decompressed by this plugin should be listed.
246
- *
247
- * @default ['gzip', 'deflate']
248
- */
249
- encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[] | undefined;
250
- }
251
- /**
252
- * Advertises Accept-Encoding on requests and decompresses response bodies
253
- * based on the Content-Encoding header. Works at the standard link level,
254
- * so it supports all adapters.
255
- *
256
- * @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
257
- */
258
- declare class ResponseCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
259
- name: string;
260
- /**
261
- * Decompression should wrap the final batch response instead of sub-responses.
262
- */
263
- after: string[];
264
- private readonly encodings;
265
- constructor(options?: ResponseCompressionLinkPluginOptions<T>);
266
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
267
- }
268
-
269
- interface RetryLinkPluginAttemptOptions<T extends RetryLinkPluginContext> extends StandardLinkInterceptorOptions<T> {
270
- /**
271
- * Latest retry delay advertised by the server via event metadata.
272
- */
273
- lastEventRetry: number | undefined;
274
- /**
275
- * Current retry attempt number, starting at 1.
276
- */
277
- attempt: number;
278
- /**
279
- * Error that triggered this retry attempt.
280
- */
281
- error: unknown;
282
- }
283
- /**
284
- * Client context options that control retry behavior per call
285
- * when the `RetryLinkPlugin` is enabled.
286
- *
287
- * @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin}
288
- */
289
- interface RetryLinkPluginContext {
290
- /**
291
- * Maximum retry attempts before throwing.
292
- * Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for AsyncIteratorObject).
293
- *
294
- * @default 0
295
- */
296
- retry?: Value<Promisable<number>, [Omit<StandardLinkInterceptorOptions<RetryLinkPluginContext>, 'next'>]> | undefined;
297
- /**
298
- * Delay (in ms) before retrying.
299
- *
300
- * @remarks
301
- * **Note**: Why 2000ms? The EventSource spec suggests a default retry delay of 2 seconds if it doesn't specify
302
- *
303
- * @default (o) => o.lastEventRetry ?? 2000
304
- */
305
- retryDelay?: Value<Promisable<number>, [RetryLinkPluginAttemptOptions<RetryLinkPluginContext>]> | undefined;
306
- /**
307
- * Determine whether to retry.
308
- *
309
- * @default (o) => isRetryableError(o.error)
310
- */
311
- shouldRetry?: Value<Promisable<boolean>, [RetryLinkPluginAttemptOptions<RetryLinkPluginContext>]> | undefined;
312
- /**
313
- * Hook called before each retry. Can return a cleanup callback.
314
- */
315
- onRetry?: ((options: RetryLinkPluginAttemptOptions<RetryLinkPluginContext>) => void | ((isSuccess: boolean) => void)) | undefined;
316
- }
317
- interface RetryLinkPluginOptions<_T extends RetryLinkPluginContext> {
318
- /**
319
- * Default retry options. Can be overridden by individual calls via the context.
320
- */
321
- default?: RetryLinkPluginContext | undefined;
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;
330
- /**
331
- * Automatically retries failed requests based on customizable retry strategies,
332
- * improving the resilience of your application.
333
- *
334
- * @remarks
335
- * **Note**: Retry behavior is configured through the client context on each call.
336
- *
337
- * @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin}
338
- */
339
- declare class RetryLinkPlugin<T extends RetryLinkPluginContext & ClientContext> implements StandardLinkPlugin<T> {
340
- private readonly defaultRetry;
341
- private readonly defaultRetryDelay;
342
- private readonly defaultShouldRetry;
343
- private readonly defaultOnRetry;
344
- name: string;
345
- constructor(options?: RetryLinkPluginOptions<T>);
346
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
347
- }
348
-
349
- interface RetryAfterLinkPluginOptions<T extends ClientContext> {
350
- /**
351
- * Override condition to determine whether to retry or not.
352
- *
353
- * @default ((response) => response.status === 429 || response.status === 503)
354
- */
355
- condition?: Value<boolean, [
356
- response: StandardLazyResponse,
357
- options: StandardLinkTransportInterceptorOptions<T>
358
- ]> | undefined;
359
- /**
360
- * Maximum attempts before giving up retries.
361
- *
362
- * @default 3
363
- */
364
- maxAttempts?: Value<number, [
365
- response: StandardLazyResponse,
366
- options: StandardLinkTransportInterceptorOptions<T>
367
- ]> | undefined;
368
- /**
369
- * Maximum timeout in milliseconds to wait before giving up retries.
370
- *
371
- * @default 5 * 60 * 1000 (5 minutes)
372
- */
373
- timeout?: Value<number, [
374
- response: StandardLazyResponse,
375
- options: StandardLinkTransportInterceptorOptions<T>
376
- ]> | undefined;
377
- }
378
- /**
379
- * The Retry After Link Plugin automatically retries requests based on server `retry-after` header.
380
- * This is particularly useful for handling rate limiting and temporary server unavailability.
381
- *
382
- * @remarks
383
- * **Note**: Requests with a stream or async iterator body are never retried, since the body cannot be resent.
384
- *
385
- * @see {@link https://orpc.dev/docs/plugins/retry-after | Retry After Plugin}
386
- */
387
- declare class RetryAfterLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
388
- private readonly condition;
389
- private readonly maxAttempts;
390
- private readonly timeout;
391
- name: string;
392
- constructor(options?: RetryAfterLinkPluginOptions<T>);
393
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
394
- }
395
-
396
- interface TimeoutLinkPluginOptions<T extends ClientContext> {
397
- /**
398
- * Timeout in milliseconds before the request is aborted.
399
- * Use `null` or `undefined` to disable the timeout.
400
- */
401
- timeout: Value<number | null | undefined, [options: StandardLinkInterceptorOptions<T>]>;
402
- }
403
- /**
404
- * The Timeout Link Plugin aborts requests that exceed a configured timeout with an `AbortError`.
405
- *
406
- * @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
407
- */
408
- declare class TimeoutLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
409
- private readonly timeout;
410
- name: string;
411
- /**
412
- * Should abort if the total retry time exceeds the configured timeout
413
- */
414
- after: string[];
415
- constructor(options: NoInfer<TimeoutLinkPluginOptions<T>>);
416
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
417
- }
418
-
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 };
@@ -1,233 +0,0 @@
1
- import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared';
2
- import { StandardResponse } from '@standard-server/core';
3
-
4
- interface ClientContext {
5
- [key: PropertyKey]: any;
6
- }
7
- interface ClientOptions<T extends ClientContext> {
8
- signal?: AbortSignal | undefined;
9
- lastEventId?: string | undefined;
10
- context: T;
11
- }
12
- type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
13
- context?: T | undefined;
14
- } : {
15
- context: T;
16
- });
17
- type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
18
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
19
- (...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>;
20
- }
21
- type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
22
- [k: string]: NestedClient<TClientContext>;
23
- };
24
- type AnyNestedClient = NestedClient<any>;
25
- /**
26
- * Infers the **client context type** required by a client.
27
- *
28
- * @see {@link https://orpc.dev/docs/client/client-side#infer-client-context | Client-Side Clients - Infer Client Context}
29
- */
30
- type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never;
31
- interface ClientLink<TClientContext extends ClientContext> {
32
- call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
33
- }
34
- /**
35
- * Recursively infers the **input types** from a client.
36
- *
37
- * Produces a nested map where each endpoint's input type is preserved.
38
- *
39
- * @see {@link https://orpc.dev/docs/client/client-side#infer-client-inputs | Client-Side Clients - Infer Client Inputs}
40
- */
41
- type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : {
42
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never;
43
- };
44
- /**
45
- * Recursively infers the **body input types** from a client.
46
- *
47
- * If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
48
- * Produces a nested map of body input types.
49
- *
50
- * @see {@link https://orpc.dev/docs/client/client-side#infer-client-body-inputs | Client-Side Clients - Infer Client Body Inputs}
51
- */
52
- type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends {
53
- body: infer UBody;
54
- } ? UBody : U : {
55
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyInputs<T[K]> : never;
56
- };
57
- /**
58
- * Recursively infers the **output types** from a client.
59
- *
60
- * Produces a nested map where each endpoint's output type is preserved.
61
- *
62
- * @see {@link https://orpc.dev/docs/client/client-side#infer-client-outputs | Client-Side Clients - Infer Client Outputs}
63
- */
64
- type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : {
65
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never;
66
- };
67
- /**
68
- * Recursively infers the **body output types** from a client.
69
- *
70
- * If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
71
- * Produces a nested map of body output types.
72
- *
73
- * @see {@link https://orpc.dev/docs/client/client-side#infer-client-body-outputs | Client-Side Clients - Infer Client Body Outputs}
74
- */
75
- type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends {
76
- body: infer UBody;
77
- } ? UBody : U : {
78
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never;
79
- };
80
- /**
81
- * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors).
82
- *
83
- * Produces a nested map where each endpoint's error type is preserved.
84
- *
85
- * @see {@link https://orpc.dev/docs/client/client-side#infer-client-errors | Client-Side Clients - Infer Client Errors}
86
- */
87
- type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
88
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never;
89
- };
90
- /**
91
- * Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors).
92
- *
93
- * Useful when you want to handle all possible errors from any endpoint at once.
94
- *
95
- * @see {@link https://orpc.dev/docs/client/client-side#infer-client-error | Client-Side Clients - Infer Client Error}
96
- */
97
- type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
98
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never;
99
- }[keyof T];
100
-
101
- /**
102
- * Default mapping between common oRPC error codes and HTTP status codes.
103
- * Handlers use it to determine response status codes; spread it to build a custom `errorStatusMap`.
104
- *
105
- * @see {@link https://orpc.dev/docs/rpc/handler#custom-error-response | RPC Handler - Custom Error Response}
106
- * @see {@link https://orpc.dev/docs/openapi/handler#custom-error-response | OpenAPI Handler - Custom Error Response}
107
- */
108
- declare const COMMON_ERROR_STATUS_MAP: {
109
- BAD_REQUEST: number;
110
- UNAUTHORIZED: number;
111
- PAYMENT_REQUIRED: number;
112
- FORBIDDEN: number;
113
- NOT_FOUND: number;
114
- METHOD_NOT_SUPPORTED: number;
115
- NOT_ACCEPTABLE: number;
116
- TIMEOUT: number;
117
- CONFLICT: number;
118
- GONE: number;
119
- LENGTH_REQUIRED: number;
120
- PRECONDITION_FAILED: number;
121
- PAYLOAD_TOO_LARGE: number;
122
- UNSUPPORTED_MEDIA_TYPE: number;
123
- UNPROCESSABLE_CONTENT: number;
124
- PRECONDITION_REQUIRED: number;
125
- TOO_MANY_REQUESTS: number;
126
- CLIENT_CLOSED_REQUEST: number;
127
- INTERNAL_SERVER_ERROR: number;
128
- NOT_IMPLEMENTED: number;
129
- BAD_GATEWAY: number;
130
- SERVICE_UNAVAILABLE: number;
131
- GATEWAY_TIMEOUT: number;
132
- };
133
- type ORPCErrorCode = Registry extends {
134
- ORPCErrorCode: infer T extends string;
135
- } ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {});
136
- type ORPCErrorOptions<TData> = ErrorOptions & {
137
- message?: string | undefined;
138
- } & (undefined extends TData ? {
139
- data?: TData;
140
- } : {
141
- data: TData;
142
- });
143
- /**
144
- * Typed error carrying a `code`, a `message`, and optional `data`.
145
- * Throw it from handlers or middleware to produce typed error responses on the client.
146
- *
147
- * @see {@link https://orpc.dev/docs/error-handling#orpcerror-class | Error Handling - ORPCError Class}
148
- */
149
- declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
150
- /**
151
- * @remarks
152
- * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish
153
- * an `ORPCError` instance from plain objects with a similar structure.
154
- */
155
- readonly name: "ORPCError" & {
156
- __branch: "ORPCError";
157
- };
158
- /**
159
- * Indicates whether the error matches a definition in the procedure's `.errors` map,
160
- * which makes its type inferable on the client.
161
- */
162
- readonly defined: boolean;
163
- code: TCode;
164
- data: TData;
165
- constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
166
- toJSON(): ORPCErrorJSON<TCode, TData>;
167
- /**
168
- * Workaround for Next.js where different contexts use separate
169
- * dependency graphs, causing multiple ORPCError constructors existing and breaking
170
- * `instanceof` checks across contexts.
171
- *
172
- * This is particularly problematic with "Optimized SSR", where orpc-client
173
- * executes in one context but is invoked from another. When an error is thrown
174
- * in the execution context, `instanceof ORPCError` checks fail in the
175
- * invocation context due to separate class constructors.
176
- *
177
- * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
178
- */
179
- static [Symbol.hasInstance](instance: unknown): boolean;
180
- }
181
- interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> {
182
- /**
183
- * remove readonly
184
- */
185
- defined: boolean;
186
- }
187
- type AnyORPCError = ORPCError<any, any>;
188
- type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
189
- interface ResponseErrorOptions extends ErrorOptions {
190
- /**
191
- * @default inferred from the response status
192
- */
193
- message?: string | undefined;
194
- response: StandardResponse;
195
- }
196
- /**
197
- * Error carrying the resolved response a link received. Links set it as the `cause`
198
- * of an `ORPCError` decoded from an error response, so details that are not part
199
- * of the error itself, such as its status or headers, stay available.
200
- *
201
- * @see {@link https://orpc.dev/docs/rpc/link#error-responses | RPC Link - Error Responses}
202
- * @see {@link https://orpc.dev/docs/openapi/link#error-responses | OpenAPI Link - Error Responses}
203
- */
204
- declare class ResponseError extends Error {
205
- readonly name: string;
206
- response: StandardResponse;
207
- constructor(options: ResponseErrorOptions);
208
- }
209
- interface MalformedResponseErrorOptions extends ResponseErrorOptions {
210
- /**
211
- * @default inferred from the response body or status
212
- */
213
- message?: string | undefined;
214
- }
215
- /**
216
- * Error thrown by links when a response does not follow the expected oRPC format,
217
- * for example when a proxy or gateway answers instead of your handler. Extends
218
- * `ResponseError`, so it carries the resolved response. Unless overridden via
219
- * `options.message`, the message is inferred from the response body or status.
220
- *
221
- * Unlike `ORPCError`, it reaches a handler's callers as a generic `INTERNAL_SERVER_ERROR`
222
- * when thrown from the handler, so an upstream's response is not sent to them.
223
- *
224
- * @see {@link https://orpc.dev/docs/rpc/link#malformed-responses | RPC Link - Malformed Responses}
225
- * @see {@link https://orpc.dev/docs/openapi/link#malformed-responses | OpenAPI Link - Malformed Responses}
226
- */
227
- declare class MalformedResponseError extends ResponseError {
228
- readonly name = "MalformedResponseError";
229
- constructor(options: MalformedResponseErrorOptions);
230
- }
231
-
232
- export { MalformedResponseError as M, ResponseError as R, ORPCError as h, COMMON_ERROR_STATUS_MAP as j };
233
- export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, AnyNestedClient as c, InferClientError as d, Client as e, ClientRest as f, ORPCErrorJSON as g, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, MalformedResponseErrorOptions as p, ORPCErrorOptions as q, ResponseErrorOptions as r };