@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.
- package/README.md +71 -101
- package/dist/adapters/fetch/index.d.mts +10 -5
- package/dist/adapters/fetch/index.d.ts +10 -5
- package/dist/adapters/fetch/index.mjs +31 -6
- package/dist/adapters/message-port/index.d.mts +11 -6
- package/dist/adapters/message-port/index.d.ts +11 -6
- package/dist/adapters/message-port/index.mjs +20 -15
- package/dist/adapters/standard/index.d.mts +6 -7
- package/dist/adapters/standard/index.d.ts +6 -7
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/adapters/websocket/index.d.mts +19 -14
- package/dist/adapters/websocket/index.d.ts +19 -14
- package/dist/adapters/websocket/index.mjs +11 -11
- package/dist/index.d.mts +49 -48
- package/dist/index.d.ts +49 -48
- package/dist/index.mjs +32 -49
- package/dist/plugins/index.d.mts +124 -12
- package/dist/plugins/index.d.ts +124 -12
- package/dist/plugins/index.mjs +290 -23
- package/dist/shared/{client.Cby_-GGh.d.mts → client.B0-4UDVl.d.mts} +1 -1
- package/dist/shared/{client.CPF3hX6O.d.ts → client.BhTyskpV.d.ts} +1 -1
- package/dist/shared/{client.DMXKFDyV.mjs → client.BnATe4Ob.mjs} +176 -58
- package/dist/shared/{client.8ug8I-zu.d.mts → client.CFVTHyN6.d.mts} +54 -6
- package/dist/shared/{client.8ug8I-zu.d.ts → client.CFVTHyN6.d.ts} +54 -6
- package/dist/shared/{client.Dnfj8jnT.mjs → client.DcoDDrD4.mjs} +17 -8
- package/dist/shared/{client.BdItY5DT.d.mts → client.Qwo2aQOm.d.mts} +18 -0
- package/dist/shared/{client.BdItY5DT.d.ts → client.Qwo2aQOm.d.ts} +18 -0
- package/dist/shared/{client.DXhchJ84.mjs → client.vEM0O_Eg.mjs} +8 -9
- package/package.json +19 -6
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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.
|
|
1
|
+
import { b as isInferableError } from './shared/client.BnATe4Ob.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.BnATe4Ob.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.DcoDDrD4.mjs';
|
|
6
6
|
export { ErrorEvent, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core';
|
|
7
7
|
|
|
8
8
|
const RECURSIVE_CLIENT_UNWRAP_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -66,35 +66,6 @@ async function safe(promise) {
|
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
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
69
|
|
|
99
70
|
function createORPCClient(link, { path = [], ...options } = {}) {
|
|
100
71
|
const procedureClient = (...rest) => {
|
|
@@ -109,30 +80,44 @@ function createORPCClient(link, { path = [], ...options } = {}) {
|
|
|
109
80
|
({ path: path2, input: input2, ...callOptions2 }) => link.call(path2, input2, callOptions2)
|
|
110
81
|
);
|
|
111
82
|
};
|
|
83
|
+
const cache = /* @__PURE__ */ new Map();
|
|
112
84
|
const recursive = new Proxy(procedureClient, {
|
|
113
85
|
get(target, key) {
|
|
114
86
|
if (typeof key !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) {
|
|
115
|
-
return
|
|
87
|
+
return Reflect.get(target, key);
|
|
88
|
+
}
|
|
89
|
+
let client = cache.get(key);
|
|
90
|
+
if (client === void 0) {
|
|
91
|
+
client = createORPCClient(link, {
|
|
92
|
+
...options,
|
|
93
|
+
path: [...path, key],
|
|
94
|
+
scoped: options.scoped?.[key]
|
|
95
|
+
});
|
|
96
|
+
cache.set(key, client);
|
|
116
97
|
}
|
|
117
|
-
|
|
118
|
-
return createORPCClient(link, {
|
|
119
|
-
...options,
|
|
120
|
-
path: [...path, key],
|
|
121
|
-
scoped
|
|
122
|
-
});
|
|
98
|
+
return client;
|
|
123
99
|
}
|
|
124
100
|
});
|
|
125
101
|
return recursive;
|
|
126
102
|
}
|
|
127
103
|
|
|
128
104
|
function createSafeClient(client) {
|
|
105
|
+
const cache = /* @__PURE__ */ new Map();
|
|
129
106
|
const proxy = new Proxy((...args) => safe(client(...args)), {
|
|
130
|
-
get(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return value;
|
|
107
|
+
get(target, prop) {
|
|
108
|
+
if (typeof prop !== "string" || RECURSIVE_CLIENT_UNWRAP_KEYS.has(prop)) {
|
|
109
|
+
return Reflect.get(target, prop);
|
|
134
110
|
}
|
|
135
|
-
|
|
111
|
+
let safeClient = cache.get(prop);
|
|
112
|
+
if (safeClient === void 0) {
|
|
113
|
+
const value = client[prop];
|
|
114
|
+
if (!isTypescriptObject(value)) {
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
safeClient = createSafeClient(value);
|
|
118
|
+
cache.set(prop, safeClient);
|
|
119
|
+
}
|
|
120
|
+
return safeClient;
|
|
136
121
|
}
|
|
137
122
|
});
|
|
138
123
|
return proxy;
|
|
@@ -149,6 +134,4 @@ class DynamicLink {
|
|
|
149
134
|
}
|
|
150
135
|
}
|
|
151
136
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, consumeEventIterator, createORPCClient, createSafeClient, isDefinedError, isInferableError, resolveClientRest, resolveFriendlyClientOptions, safe };
|
|
137
|
+
export { DynamicLink, RECURSIVE_CLIENT_UNWRAP_KEYS, createORPCClient, createSafeClient, isInferableError as isDefinedError, isInferableError, resolveClientRest, resolveFriendlyClientOptions, safe };
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Value, Promisable } from '@orpc/shared';
|
|
2
2
|
import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
/**
|
|
@@ -79,6 +77,15 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
79
77
|
*/
|
|
80
78
|
mapSubresponse?: (subResponse: StandardLazyResponse, batchResponse: StandardLazyResponse, subOptions: StandardLinkTransportInterceptorOptions<T>) => StandardLazyResponse;
|
|
81
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Combines multiple client requests into a single batch request
|
|
82
|
+
* and splits the batch response back into individual responses.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* **Note**: HTTP/2 and later already multiplex requests over a single connection, so this plugin is often less useful than it once was.
|
|
86
|
+
*
|
|
87
|
+
* @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
|
|
88
|
+
*/
|
|
82
89
|
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
83
90
|
name: string;
|
|
84
91
|
private readonly groups;
|
|
@@ -119,10 +126,16 @@ interface DedupeLinkPluginOptions<T extends ClientContext> {
|
|
|
119
126
|
/**
|
|
120
127
|
* Filters requests to dedupe.
|
|
121
128
|
*
|
|
122
|
-
* @default ({ request }) => request.method === 'GET'
|
|
129
|
+
* @default ({ request }) => request.method === 'GET' || request.method === 'QUERY'
|
|
123
130
|
*/
|
|
124
131
|
filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
|
|
125
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Prevents redundant requests by deduplicating similar in-flight requests,
|
|
135
|
+
* reducing the number of requests sent to the server.
|
|
136
|
+
*
|
|
137
|
+
* @see {@link https://orpc.dev/docs/plugins/dedupe | Dedupe Plugin}
|
|
138
|
+
*/
|
|
126
139
|
declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
127
140
|
name: string;
|
|
128
141
|
before: string[];
|
|
@@ -136,6 +149,67 @@ declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkP
|
|
|
136
149
|
private execute;
|
|
137
150
|
}
|
|
138
151
|
|
|
152
|
+
interface RequestCompressionLinkPluginOptions<_T extends ClientContext> {
|
|
153
|
+
/**
|
|
154
|
+
* The compression scheme to use for request compression.
|
|
155
|
+
*
|
|
156
|
+
* @default 'gzip'
|
|
157
|
+
*/
|
|
158
|
+
encoding?: 'gzip' | 'deflate' | 'deflate-raw';
|
|
159
|
+
/**
|
|
160
|
+
* The minimum request size in bytes required to trigger compression.
|
|
161
|
+
* Requests smaller than this threshold will not be compressed to avoid overhead.
|
|
162
|
+
* If the request size cannot be determined, compression will still be applied.
|
|
163
|
+
*
|
|
164
|
+
* @default 1024 (1KB)
|
|
165
|
+
*/
|
|
166
|
+
threshold?: number;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Compresses request bodies before sending them to the server,
|
|
170
|
+
* reducing bandwidth usage for large payloads.
|
|
171
|
+
*
|
|
172
|
+
* @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
|
|
173
|
+
*/
|
|
174
|
+
declare class RequestCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
175
|
+
name: string;
|
|
176
|
+
/**
|
|
177
|
+
* Compression should be done after batching, to compress the final request
|
|
178
|
+
*/
|
|
179
|
+
after: string[];
|
|
180
|
+
private readonly encoding;
|
|
181
|
+
private readonly threshold;
|
|
182
|
+
constructor(options?: RequestCompressionLinkPluginOptions<T>);
|
|
183
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface ResponseCompressionLinkPluginOptions<_T extends ClientContext> {
|
|
187
|
+
/**
|
|
188
|
+
* Compression schemes to advertise via Accept-Encoding, in preference order.
|
|
189
|
+
* Only schemes that can be decompressed by this plugin should be listed.
|
|
190
|
+
*
|
|
191
|
+
* @default ['gzip', 'deflate']
|
|
192
|
+
*/
|
|
193
|
+
encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[];
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Advertises Accept-Encoding on requests and decompresses response bodies
|
|
197
|
+
* based on the Content-Encoding header. Works at the standard link level,
|
|
198
|
+
* so it supports all adapters.
|
|
199
|
+
*
|
|
200
|
+
* @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
|
|
201
|
+
*/
|
|
202
|
+
declare class ResponseCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
203
|
+
name: string;
|
|
204
|
+
/**
|
|
205
|
+
* Decompression should wrap the final batch response instead of sub-responses.
|
|
206
|
+
*/
|
|
207
|
+
after: string[];
|
|
208
|
+
private readonly encodings;
|
|
209
|
+
constructor(options?: ResponseCompressionLinkPluginOptions<T>);
|
|
210
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
211
|
+
}
|
|
212
|
+
|
|
139
213
|
interface RetryLinkPluginAttemptOptions<T extends RetryLinkPluginContext> extends StandardLinkInterceptorOptions<T> {
|
|
140
214
|
/**
|
|
141
215
|
* Latest retry delay advertised by the server via event metadata.
|
|
@@ -150,10 +224,16 @@ interface RetryLinkPluginAttemptOptions<T extends RetryLinkPluginContext> extend
|
|
|
150
224
|
*/
|
|
151
225
|
error: unknown;
|
|
152
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Client context options that control retry behavior per call
|
|
229
|
+
* when the `RetryLinkPlugin` is enabled.
|
|
230
|
+
*
|
|
231
|
+
* @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin}
|
|
232
|
+
*/
|
|
153
233
|
interface RetryLinkPluginContext {
|
|
154
234
|
/**
|
|
155
235
|
* Maximum retry attempts before throwing.
|
|
156
|
-
* Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for
|
|
236
|
+
* Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for AsyncIteratorObject).
|
|
157
237
|
*
|
|
158
238
|
* @default 0
|
|
159
239
|
*/
|
|
@@ -161,7 +241,9 @@ interface RetryLinkPluginContext {
|
|
|
161
241
|
/**
|
|
162
242
|
* Delay (in ms) before retrying.
|
|
163
243
|
*
|
|
164
|
-
* @
|
|
244
|
+
* @remarks
|
|
245
|
+
* **Note**: Why 2000ms? The EventSource spec suggests a default retry delay of 2 seconds if it doesn't specify
|
|
246
|
+
*
|
|
165
247
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
166
248
|
*/
|
|
167
249
|
retryDelay?: Value<Promisable<number>, [RetryLinkPluginAttemptOptions<RetryLinkPluginContext>]>;
|
|
@@ -182,8 +264,15 @@ interface RetryLinkPluginOptions<_T extends RetryLinkPluginContext> {
|
|
|
182
264
|
*/
|
|
183
265
|
default?: RetryLinkPluginContext | undefined;
|
|
184
266
|
}
|
|
185
|
-
|
|
186
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Automatically retries failed requests based on customizable retry strategies,
|
|
269
|
+
* improving the resilience of your application.
|
|
270
|
+
*
|
|
271
|
+
* @remarks
|
|
272
|
+
* **Note**: Retry behavior is configured through the client context on each call.
|
|
273
|
+
*
|
|
274
|
+
* @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin}
|
|
275
|
+
*/
|
|
187
276
|
declare class RetryLinkPlugin<T extends RetryLinkPluginContext & ClientContext> implements StandardLinkPlugin<T> {
|
|
188
277
|
private readonly defaultRetry;
|
|
189
278
|
private readonly defaultRetryDelay;
|
|
@@ -227,7 +316,7 @@ interface RetryAfterLinkPluginOptions<T extends ClientContext> {
|
|
|
227
316
|
* The Retry After Link Plugin automatically retries requests based on server `retry-after` header.
|
|
228
317
|
* This is particularly useful for handling rate limiting and temporary server unavailability.
|
|
229
318
|
*
|
|
230
|
-
* @see {@link https://orpc.dev/docs/plugins/retry-after Retry After Plugin
|
|
319
|
+
* @see {@link https://orpc.dev/docs/plugins/retry-after | Retry After Plugin}
|
|
231
320
|
*/
|
|
232
321
|
declare class RetryAfterLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
233
322
|
private readonly condition;
|
|
@@ -238,5 +327,28 @@ declare class RetryAfterLinkPlugin<T extends ClientContext> implements StandardL
|
|
|
238
327
|
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
239
328
|
}
|
|
240
329
|
|
|
241
|
-
|
|
242
|
-
|
|
330
|
+
interface TimeoutLinkPluginOptions<T extends ClientContext> {
|
|
331
|
+
/**
|
|
332
|
+
* Timeout in milliseconds before the request is aborted.
|
|
333
|
+
* Use `null` or `undefined` to disable the timeout.
|
|
334
|
+
*/
|
|
335
|
+
timeout: Value<number | null | undefined, [options: StandardLinkInterceptorOptions<T>]>;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* The Timeout Link Plugin aborts requests that exceed a configured timeout with an `AbortError`.
|
|
339
|
+
*
|
|
340
|
+
* @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
|
|
341
|
+
*/
|
|
342
|
+
declare class TimeoutLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
343
|
+
private readonly timeout;
|
|
344
|
+
name: string;
|
|
345
|
+
/**
|
|
346
|
+
* Should abort if the total retry time exceeds the configured timeout
|
|
347
|
+
*/
|
|
348
|
+
after: string[];
|
|
349
|
+
constructor(options: NoInfer<TimeoutLinkPluginOptions<T>>);
|
|
350
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export { BatchLinkPlugin, RetryLinkPlugin as ClientRetryPlugin, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin };
|
|
354
|
+
export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, RetryLinkPluginContext as ClientRetryPluginContext, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, TimeoutLinkPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Value, Promisable } from '@orpc/shared';
|
|
2
2
|
import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { ClientContext } from '../index.js';
|
|
4
|
+
import { StandardLinkPlugin, StandardLinkTransportInterceptorOptions, StandardLinkOptions, StandardLinkInterceptorOptions } from '../adapters/standard/index.js';
|
|
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
|
/**
|
|
@@ -79,6 +77,15 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
79
77
|
*/
|
|
80
78
|
mapSubresponse?: (subResponse: StandardLazyResponse, batchResponse: StandardLazyResponse, subOptions: StandardLinkTransportInterceptorOptions<T>) => StandardLazyResponse;
|
|
81
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Combines multiple client requests into a single batch request
|
|
82
|
+
* and splits the batch response back into individual responses.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* **Note**: HTTP/2 and later already multiplex requests over a single connection, so this plugin is often less useful than it once was.
|
|
86
|
+
*
|
|
87
|
+
* @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
|
|
88
|
+
*/
|
|
82
89
|
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
83
90
|
name: string;
|
|
84
91
|
private readonly groups;
|
|
@@ -119,10 +126,16 @@ interface DedupeLinkPluginOptions<T extends ClientContext> {
|
|
|
119
126
|
/**
|
|
120
127
|
* Filters requests to dedupe.
|
|
121
128
|
*
|
|
122
|
-
* @default ({ request }) => request.method === 'GET'
|
|
129
|
+
* @default ({ request }) => request.method === 'GET' || request.method === 'QUERY'
|
|
123
130
|
*/
|
|
124
131
|
filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
|
|
125
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Prevents redundant requests by deduplicating similar in-flight requests,
|
|
135
|
+
* reducing the number of requests sent to the server.
|
|
136
|
+
*
|
|
137
|
+
* @see {@link https://orpc.dev/docs/plugins/dedupe | Dedupe Plugin}
|
|
138
|
+
*/
|
|
126
139
|
declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
127
140
|
name: string;
|
|
128
141
|
before: string[];
|
|
@@ -136,6 +149,67 @@ declare class DedupeLinkPlugin<T extends ClientContext> implements StandardLinkP
|
|
|
136
149
|
private execute;
|
|
137
150
|
}
|
|
138
151
|
|
|
152
|
+
interface RequestCompressionLinkPluginOptions<_T extends ClientContext> {
|
|
153
|
+
/**
|
|
154
|
+
* The compression scheme to use for request compression.
|
|
155
|
+
*
|
|
156
|
+
* @default 'gzip'
|
|
157
|
+
*/
|
|
158
|
+
encoding?: 'gzip' | 'deflate' | 'deflate-raw';
|
|
159
|
+
/**
|
|
160
|
+
* The minimum request size in bytes required to trigger compression.
|
|
161
|
+
* Requests smaller than this threshold will not be compressed to avoid overhead.
|
|
162
|
+
* If the request size cannot be determined, compression will still be applied.
|
|
163
|
+
*
|
|
164
|
+
* @default 1024 (1KB)
|
|
165
|
+
*/
|
|
166
|
+
threshold?: number;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Compresses request bodies before sending them to the server,
|
|
170
|
+
* reducing bandwidth usage for large payloads.
|
|
171
|
+
*
|
|
172
|
+
* @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
|
|
173
|
+
*/
|
|
174
|
+
declare class RequestCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
175
|
+
name: string;
|
|
176
|
+
/**
|
|
177
|
+
* Compression should be done after batching, to compress the final request
|
|
178
|
+
*/
|
|
179
|
+
after: string[];
|
|
180
|
+
private readonly encoding;
|
|
181
|
+
private readonly threshold;
|
|
182
|
+
constructor(options?: RequestCompressionLinkPluginOptions<T>);
|
|
183
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface ResponseCompressionLinkPluginOptions<_T extends ClientContext> {
|
|
187
|
+
/**
|
|
188
|
+
* Compression schemes to advertise via Accept-Encoding, in preference order.
|
|
189
|
+
* Only schemes that can be decompressed by this plugin should be listed.
|
|
190
|
+
*
|
|
191
|
+
* @default ['gzip', 'deflate']
|
|
192
|
+
*/
|
|
193
|
+
encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[];
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Advertises Accept-Encoding on requests and decompresses response bodies
|
|
197
|
+
* based on the Content-Encoding header. Works at the standard link level,
|
|
198
|
+
* so it supports all adapters.
|
|
199
|
+
*
|
|
200
|
+
* @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
|
|
201
|
+
*/
|
|
202
|
+
declare class ResponseCompressionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
203
|
+
name: string;
|
|
204
|
+
/**
|
|
205
|
+
* Decompression should wrap the final batch response instead of sub-responses.
|
|
206
|
+
*/
|
|
207
|
+
after: string[];
|
|
208
|
+
private readonly encodings;
|
|
209
|
+
constructor(options?: ResponseCompressionLinkPluginOptions<T>);
|
|
210
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
211
|
+
}
|
|
212
|
+
|
|
139
213
|
interface RetryLinkPluginAttemptOptions<T extends RetryLinkPluginContext> extends StandardLinkInterceptorOptions<T> {
|
|
140
214
|
/**
|
|
141
215
|
* Latest retry delay advertised by the server via event metadata.
|
|
@@ -150,10 +224,16 @@ interface RetryLinkPluginAttemptOptions<T extends RetryLinkPluginContext> extend
|
|
|
150
224
|
*/
|
|
151
225
|
error: unknown;
|
|
152
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Client context options that control retry behavior per call
|
|
229
|
+
* when the `RetryLinkPlugin` is enabled.
|
|
230
|
+
*
|
|
231
|
+
* @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin}
|
|
232
|
+
*/
|
|
153
233
|
interface RetryLinkPluginContext {
|
|
154
234
|
/**
|
|
155
235
|
* Maximum retry attempts before throwing.
|
|
156
|
-
* Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for
|
|
236
|
+
* Use `Number.POSITIVE_INFINITY` for infinite retries (e.g. for AsyncIteratorObject).
|
|
157
237
|
*
|
|
158
238
|
* @default 0
|
|
159
239
|
*/
|
|
@@ -161,7 +241,9 @@ interface RetryLinkPluginContext {
|
|
|
161
241
|
/**
|
|
162
242
|
* Delay (in ms) before retrying.
|
|
163
243
|
*
|
|
164
|
-
* @
|
|
244
|
+
* @remarks
|
|
245
|
+
* **Note**: Why 2000ms? The EventSource spec suggests a default retry delay of 2 seconds if it doesn't specify
|
|
246
|
+
*
|
|
165
247
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
166
248
|
*/
|
|
167
249
|
retryDelay?: Value<Promisable<number>, [RetryLinkPluginAttemptOptions<RetryLinkPluginContext>]>;
|
|
@@ -182,8 +264,15 @@ interface RetryLinkPluginOptions<_T extends RetryLinkPluginContext> {
|
|
|
182
264
|
*/
|
|
183
265
|
default?: RetryLinkPluginContext | undefined;
|
|
184
266
|
}
|
|
185
|
-
|
|
186
|
-
|
|
267
|
+
/**
|
|
268
|
+
* Automatically retries failed requests based on customizable retry strategies,
|
|
269
|
+
* improving the resilience of your application.
|
|
270
|
+
*
|
|
271
|
+
* @remarks
|
|
272
|
+
* **Note**: Retry behavior is configured through the client context on each call.
|
|
273
|
+
*
|
|
274
|
+
* @see {@link https://orpc.dev/docs/plugins/retry | Retry Plugin}
|
|
275
|
+
*/
|
|
187
276
|
declare class RetryLinkPlugin<T extends RetryLinkPluginContext & ClientContext> implements StandardLinkPlugin<T> {
|
|
188
277
|
private readonly defaultRetry;
|
|
189
278
|
private readonly defaultRetryDelay;
|
|
@@ -227,7 +316,7 @@ interface RetryAfterLinkPluginOptions<T extends ClientContext> {
|
|
|
227
316
|
* The Retry After Link Plugin automatically retries requests based on server `retry-after` header.
|
|
228
317
|
* This is particularly useful for handling rate limiting and temporary server unavailability.
|
|
229
318
|
*
|
|
230
|
-
* @see {@link https://orpc.dev/docs/plugins/retry-after Retry After Plugin
|
|
319
|
+
* @see {@link https://orpc.dev/docs/plugins/retry-after | Retry After Plugin}
|
|
231
320
|
*/
|
|
232
321
|
declare class RetryAfterLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
233
322
|
private readonly condition;
|
|
@@ -238,5 +327,28 @@ declare class RetryAfterLinkPlugin<T extends ClientContext> implements StandardL
|
|
|
238
327
|
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
239
328
|
}
|
|
240
329
|
|
|
241
|
-
|
|
242
|
-
|
|
330
|
+
interface TimeoutLinkPluginOptions<T extends ClientContext> {
|
|
331
|
+
/**
|
|
332
|
+
* Timeout in milliseconds before the request is aborted.
|
|
333
|
+
* Use `null` or `undefined` to disable the timeout.
|
|
334
|
+
*/
|
|
335
|
+
timeout: Value<number | null | undefined, [options: StandardLinkInterceptorOptions<T>]>;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* The Timeout Link Plugin aborts requests that exceed a configured timeout with an `AbortError`.
|
|
339
|
+
*
|
|
340
|
+
* @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
|
|
341
|
+
*/
|
|
342
|
+
declare class TimeoutLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
343
|
+
private readonly timeout;
|
|
344
|
+
name: string;
|
|
345
|
+
/**
|
|
346
|
+
* Should abort if the total retry time exceeds the configured timeout
|
|
347
|
+
*/
|
|
348
|
+
after: string[];
|
|
349
|
+
constructor(options: NoInfer<TimeoutLinkPluginOptions<T>>);
|
|
350
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export { BatchLinkPlugin, RetryLinkPlugin as ClientRetryPlugin, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin };
|
|
354
|
+
export type { BatchLinkPluginGroup, BatchLinkPluginMode, BatchLinkPluginOptions, RetryLinkPluginContext as ClientRetryPluginContext, DedupeLinkPluginGroup, DedupeLinkPluginOptions, RequestCompressionLinkPluginOptions, ResponseCompressionLinkPluginOptions, RetryAfterLinkPluginOptions, RetryLinkPluginAttemptOptions, RetryLinkPluginContext, RetryLinkPluginOptions, TimeoutLinkPluginOptions };
|