@orpc/client 2.0.0-beta.4 → 2.0.0-beta.41
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.
- package/README.md +97 -94
- package/dist/adapters/fetch/index.d.mts +16 -33
- package/dist/adapters/fetch/index.d.ts +16 -33
- package/dist/adapters/fetch/index.mjs +33 -30
- package/dist/adapters/message-port/index.d.mts +13 -8
- package/dist/adapters/message-port/index.d.ts +13 -8
- package/dist/adapters/message-port/index.mjs +27 -17
- package/dist/adapters/standard/index.d.mts +9 -10
- package/dist/adapters/standard/index.d.ts +9 -10
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/websocket/index.d.mts +33 -18
- package/dist/adapters/websocket/index.d.ts +33 -18
- package/dist/adapters/websocket/index.mjs +45 -24
- package/dist/index.d.mts +62 -61
- package/dist/index.d.ts +62 -61
- package/dist/index.mjs +47 -54
- package/dist/plugins/index.d.mts +174 -13
- package/dist/plugins/index.d.ts +174 -13
- package/dist/plugins/index.mjs +580 -198
- package/dist/shared/{client.BdItY5DT.d.mts → client.BPa_Mmuh.d.mts} +25 -4
- package/dist/shared/{client.BdItY5DT.d.ts → client.BPa_Mmuh.d.ts} +25 -4
- package/dist/shared/{client.Cby_-GGh.d.mts → client.BjbdW5Rj.d.mts} +2 -2
- package/dist/shared/{client.DXhchJ84.mjs → client.Bstqyaro.mjs} +25 -30
- package/dist/shared/{client.Dnfj8jnT.mjs → client.DD2eNne_.mjs} +20 -15
- package/dist/shared/{client.CPF3hX6O.d.ts → client.DiHfJmHK.d.ts} +2 -2
- package/dist/shared/client.DpkGsZt-.mjs +486 -0
- package/dist/shared/{client.8ug8I-zu.d.mts → client.Dw9_40WO.d.mts} +57 -16
- package/dist/shared/{client.8ug8I-zu.d.ts → client.Dw9_40WO.d.ts} +57 -16
- package/package.json +22 -8
- package/dist/shared/client.DMXKFDyV.mjs +0 -343
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
export { AsyncIteratorClass, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess,
|
|
5
|
-
export { C as COMMON_ERROR_STATUS_MAP, O as ORPCError } from './shared/client.
|
|
6
|
-
export { ErrorEvent, getEventMeta, unwrapEvent, withEventMeta } from '@
|
|
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';
|
|
3
|
+
import { toArray, intercept, isTypescriptObject } from '@orpc/shared';
|
|
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';
|
|
6
|
+
export { ErrorEvent, getEventMeta, unwrapEvent, withEventMeta } from '@standard-server/core';
|
|
7
7
|
|
|
8
8
|
const RECURSIVE_CLIENT_UNWRAP_KEYS = /* @__PURE__ */ new Set([
|
|
9
9
|
/**
|
|
@@ -16,6 +16,16 @@ const RECURSIVE_CLIENT_UNWRAP_KEYS = /* @__PURE__ */ new Set([
|
|
|
16
16
|
* context.
|
|
17
17
|
*/
|
|
18
18
|
"bind",
|
|
19
|
+
/**
|
|
20
|
+
* Commonly used by libraries to invoke functions with a specific `this`
|
|
21
|
+
* context.
|
|
22
|
+
*/
|
|
23
|
+
"call",
|
|
24
|
+
/**
|
|
25
|
+
* Commonly used by libraries to invoke functions with a specific `this`
|
|
26
|
+
* context and an arguments array.
|
|
27
|
+
*/
|
|
28
|
+
"apply",
|
|
19
29
|
/**
|
|
20
30
|
* Commonly accessed during primitive conversion, inspection, and logging.
|
|
21
31
|
*/
|
|
@@ -50,51 +60,22 @@ async function safe(promise) {
|
|
|
50
60
|
const output = await promise;
|
|
51
61
|
return Object.assign(
|
|
52
62
|
[null, output, null, true],
|
|
53
|
-
{ error: null, data: output,
|
|
63
|
+
{ error: null, data: output, definedError: null, isSuccess: true }
|
|
54
64
|
);
|
|
55
65
|
} catch (e) {
|
|
56
66
|
const error = e;
|
|
57
|
-
if (
|
|
67
|
+
if (isDefinedError(error)) {
|
|
58
68
|
return Object.assign(
|
|
59
69
|
[error, void 0, error, false],
|
|
60
|
-
{ error, data: void 0,
|
|
70
|
+
{ error, data: void 0, definedError: error, isSuccess: false }
|
|
61
71
|
);
|
|
62
72
|
}
|
|
63
73
|
return Object.assign(
|
|
64
74
|
[error, void 0, null, false],
|
|
65
|
-
{ error, data: void 0,
|
|
75
|
+
{ error, data: void 0, definedError: null, isSuccess: false }
|
|
66
76
|
);
|
|
67
77
|
}
|
|
68
78
|
}
|
|
69
|
-
function consumeEventIterator(iterator, options) {
|
|
70
|
-
void (async () => {
|
|
71
|
-
let onFinishState;
|
|
72
|
-
try {
|
|
73
|
-
const resolvedIterator = await iterator;
|
|
74
|
-
while (true) {
|
|
75
|
-
const { done, value } = await resolvedIterator.next();
|
|
76
|
-
if (done) {
|
|
77
|
-
const realValue = value;
|
|
78
|
-
onFinishState = [null, realValue, true];
|
|
79
|
-
options.onSuccess?.(realValue);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
options.onEvent(value);
|
|
83
|
-
}
|
|
84
|
-
} catch (error) {
|
|
85
|
-
onFinishState = [error, void 0, false];
|
|
86
|
-
if (!options.onError && !options.onFinish) {
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
options.onError?.(error);
|
|
90
|
-
} finally {
|
|
91
|
-
options.onFinish?.(onFinishState);
|
|
92
|
-
}
|
|
93
|
-
})();
|
|
94
|
-
return async () => {
|
|
95
|
-
await (await iterator)?.return?.();
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
79
|
|
|
99
80
|
function createORPCClient(link, { path = [], ...options } = {}) {
|
|
100
81
|
const procedureClient = (...rest) => {
|
|
@@ -109,30 +90,44 @@ function createORPCClient(link, { path = [], ...options } = {}) {
|
|
|
109
90
|
({ path: path2, input: input2, ...callOptions2 }) => link.call(path2, input2, callOptions2)
|
|
110
91
|
);
|
|
111
92
|
};
|
|
93
|
+
const cache = /* @__PURE__ */ new Map();
|
|
112
94
|
const recursive = new Proxy(procedureClient, {
|
|
113
95
|
get(target, key) {
|
|
114
96
|
if (typeof key !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) {
|
|
115
|
-
return
|
|
97
|
+
return Reflect.get(target, key);
|
|
98
|
+
}
|
|
99
|
+
let client = cache.get(key);
|
|
100
|
+
if (client === void 0) {
|
|
101
|
+
client = createORPCClient(link, {
|
|
102
|
+
...options,
|
|
103
|
+
path: [...path, key],
|
|
104
|
+
scoped: options.scoped?.[key]
|
|
105
|
+
});
|
|
106
|
+
cache.set(key, client);
|
|
116
107
|
}
|
|
117
|
-
|
|
118
|
-
return createORPCClient(link, {
|
|
119
|
-
...options,
|
|
120
|
-
path: [...path, key],
|
|
121
|
-
scoped
|
|
122
|
-
});
|
|
108
|
+
return client;
|
|
123
109
|
}
|
|
124
110
|
});
|
|
125
111
|
return recursive;
|
|
126
112
|
}
|
|
127
113
|
|
|
128
114
|
function createSafeClient(client) {
|
|
115
|
+
const cache = /* @__PURE__ */ new Map();
|
|
129
116
|
const proxy = new Proxy((...args) => safe(client(...args)), {
|
|
130
|
-
get(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return value;
|
|
117
|
+
get(target, prop) {
|
|
118
|
+
if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
|
|
119
|
+
return Reflect.get(target, prop);
|
|
134
120
|
}
|
|
135
|
-
|
|
121
|
+
let safeClient = cache.get(prop);
|
|
122
|
+
if (safeClient === void 0) {
|
|
123
|
+
const value = client[prop];
|
|
124
|
+
if (!isTypescriptObject(value)) {
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
safeClient = createSafeClient(value);
|
|
128
|
+
cache.set(prop, safeClient);
|
|
129
|
+
}
|
|
130
|
+
return safeClient;
|
|
136
131
|
}
|
|
137
132
|
});
|
|
138
133
|
return proxy;
|
|
@@ -149,6 +144,4 @@ class DynamicLink {
|
|
|
149
144
|
}
|
|
150
145
|
}
|
|
151
146
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, consumeEventIterator, createORPCClient, createSafeClient, isDefinedError, isInferableError, resolveClientRest, resolveFriendlyClientOptions, safe };
|
|
147
|
+
export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, createORPCClient, createSafeClient, isDefinedError, resolveClientRest, resolveFriendlyClientOptions, safe };
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
-
import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standard-server/core';
|
|
3
|
+
import { ClientContext } from '../index.mjs';
|
|
4
|
+
import { StandardLinkPlugin, StandardLinkTransportInterceptorOptions, StandardLinkOptions, StandardLinkInterceptorOptions } from '../adapters/standard/index.mjs';
|
|
5
5
|
|
|
6
6
|
type BatchLinkPluginMode = 'streaming' | 'buffered';
|
|
7
7
|
interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
@@ -23,8 +23,6 @@ interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
|
23
23
|
*/
|
|
24
24
|
path?: Value<string[], [items: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
|
|
25
25
|
}
|
|
26
|
-
declare class BatchLinkPluginError extends TypeError {
|
|
27
|
-
}
|
|
28
26
|
interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
29
27
|
groups: [BatchLinkPluginGroup<T>, ...BatchLinkPluginGroup<T>[]];
|
|
30
28
|
/**
|
|
@@ -33,12 +31,27 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
33
31
|
* @default () => true
|
|
34
32
|
*/
|
|
35
33
|
filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
|
|
34
|
+
/**
|
|
35
|
+
* Only requests with the same scope are batched together.
|
|
36
|
+
* On the server, return a value unique to the incoming request so different users never share a batch.
|
|
37
|
+
*
|
|
38
|
+
* @default () => undefined
|
|
39
|
+
*/
|
|
40
|
+
scope?: (options: StandardLinkTransportInterceptorOptions<T>) => unknown;
|
|
36
41
|
/**
|
|
37
42
|
* The maximum number of requests in the batch.
|
|
38
43
|
*
|
|
39
44
|
* @default 10
|
|
40
45
|
*/
|
|
41
46
|
maxSize?: Value<Promisable<number>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
|
|
47
|
+
/**
|
|
48
|
+
* How long (in ms) to wait for more requests before sending the batch,
|
|
49
|
+
* counted from the first queued request.
|
|
50
|
+
* With `0`, only requests made in the same event loop tick are batched.
|
|
51
|
+
*
|
|
52
|
+
* @default 0
|
|
53
|
+
*/
|
|
54
|
+
wait?: number;
|
|
42
55
|
/**
|
|
43
56
|
* The batch response mode.
|
|
44
57
|
*
|
|
@@ -79,11 +92,22 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
79
92
|
*/
|
|
80
93
|
mapSubresponse?: (subResponse: StandardLazyResponse, batchResponse: StandardLazyResponse, subOptions: StandardLinkTransportInterceptorOptions<T>) => StandardLazyResponse;
|
|
81
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Combines multiple client requests into a single batch request
|
|
97
|
+
* and splits the batch response back into individual responses.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* **Note**: HTTP/2 and later already multiplex requests over a single connection, so this plugin is often less useful than it once was.
|
|
101
|
+
*
|
|
102
|
+
* @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
|
|
103
|
+
*/
|
|
82
104
|
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
83
105
|
name: string;
|
|
84
106
|
private readonly groups;
|
|
85
107
|
private readonly filter;
|
|
108
|
+
private readonly scope;
|
|
86
109
|
private readonly maxSize;
|
|
110
|
+
private readonly wait;
|
|
87
111
|
private readonly mode;
|
|
88
112
|
private readonly batchUrl;
|
|
89
113
|
private readonly maxUrlLength;
|
|
@@ -94,6 +118,12 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
|
|
|
94
118
|
constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
|
|
95
119
|
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
96
120
|
private processPendingBatches;
|
|
121
|
+
/**
|
|
122
|
+
* Runs the batch in the async context of its first request instead of the timer's,
|
|
123
|
+
* so the transport and batch options see that caller's request state.
|
|
124
|
+
* `executeBatch` always runs in the context of its first request.
|
|
125
|
+
*/
|
|
126
|
+
private executeBatchInOwnContext;
|
|
97
127
|
private executeBatch;
|
|
98
128
|
}
|
|
99
129
|
|
|
@@ -119,15 +149,38 @@ interface DedupeLinkPluginOptions<T extends ClientContext> {
|
|
|
119
149
|
/**
|
|
120
150
|
* Filters requests to dedupe.
|
|
121
151
|
*
|
|
122
|
-
* @default ({ request }) => request.method === 'GET'
|
|
152
|
+
* @default ({ request }) => request.method === 'GET' || request.method === 'QUERY'
|
|
123
153
|
*/
|
|
124
154
|
filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
|
|
155
|
+
/**
|
|
156
|
+
* Only requests with the same scope are deduplicated together.
|
|
157
|
+
* On the server, return a value unique to the incoming request so different users never share a response.
|
|
158
|
+
*
|
|
159
|
+
* @default () => undefined
|
|
160
|
+
*/
|
|
161
|
+
scope?: (options: StandardLinkTransportInterceptorOptions<T>) => unknown;
|
|
162
|
+
/**
|
|
163
|
+
* How long (in ms) to wait for more identical requests before sending,
|
|
164
|
+
* counted from the first queued request.
|
|
165
|
+
* With `0`, only requests made in the same event loop tick are deduplicated.
|
|
166
|
+
*
|
|
167
|
+
* @default 0
|
|
168
|
+
*/
|
|
169
|
+
wait?: number;
|
|
125
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Prevents redundant requests by deduplicating similar in-flight requests,
|
|
173
|
+
* reducing the number of requests sent to the server.
|
|
174
|
+
*
|
|
175
|
+
* @see {@link https://orpc.dev/docs/plugins/dedupe | Dedupe Plugin}
|
|
176
|
+
*/
|
|
126
177
|
declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
127
178
|
name: string;
|
|
128
179
|
before: string[];
|
|
129
180
|
private readonly groups;
|
|
130
181
|
private readonly filter;
|
|
182
|
+
private readonly scope;
|
|
183
|
+
private readonly wait;
|
|
131
184
|
private readonly queue;
|
|
132
185
|
constructor(options: NoInfer<DedupeLinkPluginOptions<T>>);
|
|
133
186
|
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
@@ -136,6 +189,76 @@ declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkP
|
|
|
136
189
|
private execute;
|
|
137
190
|
}
|
|
138
191
|
|
|
192
|
+
interface RequestCompressionLinkPluginOptions<T extends ClientContext> {
|
|
193
|
+
/**
|
|
194
|
+
* The compression scheme to use for request compression.
|
|
195
|
+
*
|
|
196
|
+
* @default 'gzip'
|
|
197
|
+
*/
|
|
198
|
+
encoding?: 'gzip' | 'deflate' | 'deflate-raw';
|
|
199
|
+
/**
|
|
200
|
+
* The minimum request size in bytes required to trigger compression.
|
|
201
|
+
* Requests smaller than this threshold will not be compressed to avoid overhead.
|
|
202
|
+
* If the request size cannot be determined, compression will still be applied.
|
|
203
|
+
*
|
|
204
|
+
* @default 1024 (1KB)
|
|
205
|
+
*/
|
|
206
|
+
threshold?: number;
|
|
207
|
+
/**
|
|
208
|
+
* Determines whether a request with the given Content-Type should be compressed.
|
|
209
|
+
* Only consulted for binary transfers (streams, files, and file form-data parts).
|
|
210
|
+
* Also receives the transport interceptor options for per-request decisions.
|
|
211
|
+
*
|
|
212
|
+
* @default isCompressibleContentType (covers common text-based formats)
|
|
213
|
+
*/
|
|
214
|
+
isCompressibleContentType?: (contentType: string | null | undefined, options: StandardLinkTransportInterceptorOptions<T>) => boolean;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Compresses request bodies before sending them to the server,
|
|
218
|
+
* reducing bandwidth usage for large payloads.
|
|
219
|
+
*
|
|
220
|
+
* @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
|
|
221
|
+
*/
|
|
222
|
+
declare class RequestCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
223
|
+
name: string;
|
|
224
|
+
/**
|
|
225
|
+
* Compression should be done after batching, to compress the final request
|
|
226
|
+
*/
|
|
227
|
+
after: string[];
|
|
228
|
+
private readonly encoding;
|
|
229
|
+
private readonly threshold;
|
|
230
|
+
private readonly isCompressibleContentType;
|
|
231
|
+
constructor(options?: RequestCompressionLinkPluginOptions<T>);
|
|
232
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
interface ResponseCompressionLinkPluginOptions<_T extends ClientContext> {
|
|
236
|
+
/**
|
|
237
|
+
* Compression schemes to advertise via Accept-Encoding, in preference order.
|
|
238
|
+
* Only schemes that can be decompressed by this plugin should be listed.
|
|
239
|
+
*
|
|
240
|
+
* @default ['gzip', 'deflate']
|
|
241
|
+
*/
|
|
242
|
+
encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[];
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Advertises Accept-Encoding on requests and decompresses response bodies
|
|
246
|
+
* based on the Content-Encoding header. Works at the standard link level,
|
|
247
|
+
* so it supports all adapters.
|
|
248
|
+
*
|
|
249
|
+
* @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
|
|
250
|
+
*/
|
|
251
|
+
declare class ResponseCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
252
|
+
name: string;
|
|
253
|
+
/**
|
|
254
|
+
* Decompression should wrap the final batch response instead of sub-responses.
|
|
255
|
+
*/
|
|
256
|
+
after: string[];
|
|
257
|
+
private readonly encodings;
|
|
258
|
+
constructor(options?: ResponseCompressionLinkPluginOptions<T>);
|
|
259
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
260
|
+
}
|
|
261
|
+
|
|
139
262
|
interface RetryLinkPluginAttemptOptions<T extends RetryLinkPluginContext> extends StandardLinkInterceptorOptions<T> {
|
|
140
263
|
/**
|
|
141
264
|
* Latest retry delay advertised by the server via event metadata.
|
|
@@ -150,10 +273,16 @@ interface RetryLinkPluginAttemptOptions<T extends RetryLinkPluginContext> extend
|
|
|
150
273
|
*/
|
|
151
274
|
error: unknown;
|
|
152
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Client context options that control retry behavior per call
|
|
278
|
+
* when the `RetryLinkPlugin` is enabled.
|
|
279
|
+
*
|
|
280
|
+
* @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin}
|
|
281
|
+
*/
|
|
153
282
|
interface RetryLinkPluginContext {
|
|
154
283
|
/**
|
|
155
284
|
* Maximum retry attempts before throwing.
|
|
156
|
-
* Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for
|
|
285
|
+
* Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for AsyncIteratorObject).
|
|
157
286
|
*
|
|
158
287
|
* @default 0
|
|
159
288
|
*/
|
|
@@ -161,7 +290,9 @@ interface RetryLinkPluginContext {
|
|
|
161
290
|
/**
|
|
162
291
|
* Delay (in ms) before retrying.
|
|
163
292
|
*
|
|
164
|
-
* @
|
|
293
|
+
* @remarks
|
|
294
|
+
* **Note**: Why 2000ms? The EventSource spec suggests a default retry delay of 2 seconds if it doesn't specify
|
|
295
|
+
*
|
|
165
296
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
166
297
|
*/
|
|
167
298
|
retryDelay?: Value<Promisable<number>, [RetryLinkPluginAttemptOptions<RetryLinkPluginContext>]>;
|
|
@@ -182,8 +313,15 @@ interface RetryLinkPluginOptions<_T extends RetryLinkPluginContext> {
|
|
|
182
313
|
*/
|
|
183
314
|
default?: RetryLinkPluginContext | undefined;
|
|
184
315
|
}
|
|
185
|
-
|
|
186
|
-
|
|
316
|
+
/**
|
|
317
|
+
* Automatically retries failed requests based on customizable retry strategies,
|
|
318
|
+
* improving the resilience of your application.
|
|
319
|
+
*
|
|
320
|
+
* @remarks
|
|
321
|
+
* **Note**: Retry behavior is configured through the client context on each call.
|
|
322
|
+
*
|
|
323
|
+
* @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin}
|
|
324
|
+
*/
|
|
187
325
|
declare class RetryLinkPlugin<T extends RetryLinkPluginContext & ClientContext> implements StandardLinkPlugin<T> {
|
|
188
326
|
private readonly defaultRetry;
|
|
189
327
|
private readonly defaultRetryDelay;
|
|
@@ -227,7 +365,7 @@ interface RetryAfterLinkPluginOptions<T extends ClientContext> {
|
|
|
227
365
|
* The Retry After Link Plugin automatically retries requests based on server `retry-after` header.
|
|
228
366
|
* This is particularly useful for handling rate limiting and temporary server unavailability.
|
|
229
367
|
*
|
|
230
|
-
* @see {@link https://orpc.dev/docs/plugins/retry-after Retry After Plugin
|
|
368
|
+
* @see {@link https://orpc.dev/docs/plugins/retry-after | Retry After Plugin}
|
|
231
369
|
*/
|
|
232
370
|
declare class RetryAfterLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
233
371
|
private readonly condition;
|
|
@@ -238,5 +376,28 @@ declare class RetryAfterLinkPlugin<T extends ClientContext> implements StandardL
|
|
|
238
376
|
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
239
377
|
}
|
|
240
378
|
|
|
241
|
-
|
|
242
|
-
|
|
379
|
+
interface TimeoutLinkPluginOptions<T extends ClientContext> {
|
|
380
|
+
/**
|
|
381
|
+
* Timeout in milliseconds before the request is aborted.
|
|
382
|
+
* Use `null` or `undefined` to disable the timeout.
|
|
383
|
+
*/
|
|
384
|
+
timeout: Value<number | null | undefined, [options: StandardLinkInterceptorOptions<T>]>;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* The Timeout Link Plugin aborts requests that exceed a configured timeout with an `AbortError`.
|
|
388
|
+
*
|
|
389
|
+
* @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
|
|
390
|
+
*/
|
|
391
|
+
declare class TimeoutLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
392
|
+
private readonly timeout;
|
|
393
|
+
name: string;
|
|
394
|
+
/**
|
|
395
|
+
* Should abort if the total retry time exceeds the configured timeout
|
|
396
|
+
*/
|
|
397
|
+
after: string[];
|
|
398
|
+
constructor(options: NoInfer<TimeoutLinkPluginOptions<T>>);
|
|
399
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export { BatchLinkPlugin, RetryLinkPlugin as ClientRetryPlugin, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin };
|
|
403
|
+
export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, RetryLinkPluginContext as ClientRetryPluginContext, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, TimeoutLinkPluginOptions };
|