@orpc/client 0.0.0-next.eae6003 → 0.0.0-next.eaec0b2
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 +19 -16
- package/dist/adapters/fetch/index.d.mts +25 -12
- package/dist/adapters/fetch/index.d.ts +25 -12
- package/dist/adapters/fetch/index.mjs +25 -8
- package/dist/adapters/message-port/index.d.mts +80 -0
- package/dist/adapters/message-port/index.d.ts +80 -0
- package/dist/adapters/message-port/index.mjs +87 -0
- package/dist/adapters/standard/index.d.mts +6 -5
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.mjs +4 -2
- package/dist/adapters/websocket/index.d.mts +14 -14
- package/dist/adapters/websocket/index.d.ts +14 -14
- package/dist/adapters/websocket/index.mjs +27 -11
- package/dist/index.d.mts +88 -27
- package/dist/index.d.ts +88 -27
- package/dist/index.mjs +55 -8
- package/dist/plugins/index.d.mts +107 -20
- package/dist/plugins/index.d.ts +107 -20
- package/dist/plugins/index.mjs +221 -27
- package/dist/shared/{client.7ZYxJok_.d.ts → client.2jUAqzYU.d.ts} +4 -5
- package/dist/shared/{client.B2432-Lu.d.ts → client.B3pNRBih.d.ts} +7 -7
- package/dist/shared/{client.ClwIM_ku.d.mts → client.BFAVy68H.d.mts} +7 -7
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/{client.ds1abV85.d.mts → client.CpCa3si8.d.mts} +4 -5
- package/dist/shared/{client.CRWEpqLB.mjs → client.D9OcfSSt.mjs} +37 -41
- package/dist/shared/{client.DpICn1BD.mjs → client.DtEZLmWK.mjs} +63 -20
- package/dist/shared/client.i2uoJbEp.d.mts +83 -0
- package/dist/shared/client.i2uoJbEp.d.ts +83 -0
- package/package.json +13 -9
- package/dist/shared/client.4TS_0JaO.d.mts +0 -29
- package/dist/shared/client.4TS_0JaO.d.ts +0 -29
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Value } from '@orpc/shared';
|
|
2
|
-
import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { BatchResponseMode } from '@orpc/standard-server/batch';
|
|
4
|
+
import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.CpCa3si8.mjs';
|
|
5
|
+
import { b as ClientContext } from '../shared/client.i2uoJbEp.mjs';
|
|
5
6
|
|
|
6
7
|
interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
7
8
|
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
@@ -16,25 +17,31 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
16
17
|
*
|
|
17
18
|
* @default 10
|
|
18
19
|
*/
|
|
19
|
-
maxSize?: Value<number
|
|
20
|
+
maxSize?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
21
|
+
/**
|
|
22
|
+
* The batch response mode.
|
|
23
|
+
*
|
|
24
|
+
* @default 'streaming'
|
|
25
|
+
*/
|
|
26
|
+
mode?: Value<BatchResponseMode, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
20
27
|
/**
|
|
21
28
|
* Defines the URL to use for the batch request.
|
|
22
29
|
*
|
|
23
30
|
* @default the URL of the first request in the batch + '/__batch__'
|
|
24
31
|
*/
|
|
25
|
-
url?: Value<string | URL
|
|
32
|
+
url?: Value<Promisable<string | URL>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
26
33
|
/**
|
|
27
34
|
* The maximum length of the URL.
|
|
28
35
|
*
|
|
29
36
|
* @default 2083
|
|
30
37
|
*/
|
|
31
|
-
maxUrlLength?: Value<number
|
|
38
|
+
maxUrlLength?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
32
39
|
/**
|
|
33
40
|
* Defines the HTTP headers to use for the batch request.
|
|
34
41
|
*
|
|
35
42
|
* @default The same headers of all requests in the batch
|
|
36
43
|
*/
|
|
37
|
-
headers?: Value<StandardHeaders
|
|
44
|
+
headers?: Value<Promisable<StandardHeaders>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
38
45
|
/**
|
|
39
46
|
* Map the batch request items before sending them.
|
|
40
47
|
*
|
|
@@ -52,10 +59,10 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
52
59
|
exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
55
|
-
* The Batch
|
|
62
|
+
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
56
63
|
* reducing the overhead of sending each one separately.
|
|
57
64
|
*
|
|
58
|
-
* @see {@link https://orpc.
|
|
65
|
+
* @see {@link https://orpc.dev/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
59
66
|
*/
|
|
60
67
|
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
61
68
|
#private;
|
|
@@ -66,12 +73,45 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
|
|
|
66
73
|
private readonly batchHeaders;
|
|
67
74
|
private readonly mapRequestItem;
|
|
68
75
|
private readonly exclude;
|
|
76
|
+
private readonly mode;
|
|
69
77
|
private pending;
|
|
70
78
|
order: number;
|
|
71
79
|
constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
|
|
72
80
|
init(options: StandardLinkOptions<T>): void;
|
|
73
81
|
}
|
|
74
82
|
|
|
83
|
+
interface DedupeRequestsPluginGroup<T extends ClientContext> {
|
|
84
|
+
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* The context used for the rest of the request lifecycle.
|
|
87
|
+
*/
|
|
88
|
+
context: T;
|
|
89
|
+
}
|
|
90
|
+
interface DedupeRequestsPluginOptions<T extends ClientContext> {
|
|
91
|
+
/**
|
|
92
|
+
* To enable deduplication, a request must match at least one defined group.
|
|
93
|
+
* Requests that fall into the same group are considered for deduplication together.
|
|
94
|
+
*/
|
|
95
|
+
groups: readonly [DedupeRequestsPluginGroup<T>, ...DedupeRequestsPluginGroup<T>[]];
|
|
96
|
+
/**
|
|
97
|
+
* Filters requests to dedupe
|
|
98
|
+
*
|
|
99
|
+
* @default (({ request }) => request.method === 'GET')
|
|
100
|
+
*/
|
|
101
|
+
filter?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Prevents duplicate requests by deduplicating similar ones to reduce server load.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link https://orpc.dev/docs/plugins/dedupe-requests Dedupe Requests Plugin}
|
|
107
|
+
*/
|
|
108
|
+
declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
109
|
+
#private;
|
|
110
|
+
order: number;
|
|
111
|
+
constructor(options: NoInfer<DedupeRequestsPluginOptions<T>>);
|
|
112
|
+
init(options: StandardLinkOptions<T>): void;
|
|
113
|
+
}
|
|
114
|
+
|
|
75
115
|
interface ClientRetryPluginAttemptOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
76
116
|
lastEventRetry: number | undefined;
|
|
77
117
|
attemptIndex: number;
|
|
@@ -84,19 +124,19 @@ interface ClientRetryPluginContext {
|
|
|
84
124
|
*
|
|
85
125
|
* @default 0
|
|
86
126
|
*/
|
|
87
|
-
retry?: Value<number
|
|
127
|
+
retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
|
88
128
|
/**
|
|
89
129
|
* Delay (in ms) before retrying.
|
|
90
130
|
*
|
|
91
131
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
92
132
|
*/
|
|
93
|
-
retryDelay?: Value<number
|
|
133
|
+
retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
94
134
|
/**
|
|
95
135
|
* Determine should retry or not.
|
|
96
136
|
*
|
|
97
137
|
* @default true
|
|
98
138
|
*/
|
|
99
|
-
shouldRetry?: Value<boolean
|
|
139
|
+
shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
100
140
|
/**
|
|
101
141
|
* The hook called when retrying, and return the unsubscribe function.
|
|
102
142
|
*/
|
|
@@ -110,44 +150,91 @@ interface ClientRetryPluginOptions {
|
|
|
110
150
|
/**
|
|
111
151
|
* The Client Retry Plugin enables retrying client calls when errors occur.
|
|
112
152
|
*
|
|
113
|
-
* @see {@link https://orpc.
|
|
153
|
+
* @see {@link https://orpc.dev/docs/plugins/client-retry Client Retry Plugin Docs}
|
|
114
154
|
*/
|
|
115
155
|
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
|
116
156
|
private readonly defaultRetry;
|
|
117
157
|
private readonly defaultRetryDelay;
|
|
118
158
|
private readonly defaultShouldRetry;
|
|
119
159
|
private readonly defaultOnRetry;
|
|
160
|
+
order: number;
|
|
120
161
|
constructor(options?: ClientRetryPluginOptions);
|
|
121
162
|
init(options: StandardLinkOptions<T>): void;
|
|
122
163
|
}
|
|
123
164
|
|
|
165
|
+
interface RetryAfterPluginOptions<T extends ClientContext> {
|
|
166
|
+
/**
|
|
167
|
+
* Override condition to determine whether to retry or not.
|
|
168
|
+
*
|
|
169
|
+
* @default ((response) => response.status === 429 || response.status === 503)
|
|
170
|
+
*/
|
|
171
|
+
condition?: Value<boolean, [
|
|
172
|
+
response: StandardLazyResponse,
|
|
173
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
174
|
+
]>;
|
|
175
|
+
/**
|
|
176
|
+
* Maximum attempts before giving up retries.
|
|
177
|
+
*
|
|
178
|
+
* @default 3
|
|
179
|
+
*/
|
|
180
|
+
maxAttempts?: Value<number, [
|
|
181
|
+
response: StandardLazyResponse,
|
|
182
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
183
|
+
]>;
|
|
184
|
+
/**
|
|
185
|
+
* Maximum timeout in milliseconds to wait before giving up retries.
|
|
186
|
+
*
|
|
187
|
+
* @default 5 * 60 * 1000 (5 minutes)
|
|
188
|
+
*/
|
|
189
|
+
timeout?: Value<number, [
|
|
190
|
+
response: StandardLazyResponse,
|
|
191
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
192
|
+
]>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The Retry After Plugin automatically retries requests based on server `Retry-After` headers.
|
|
196
|
+
* This is particularly useful for handling rate limiting and temporary server unavailability.
|
|
197
|
+
*
|
|
198
|
+
* @see {@link https://orpc.dev/docs/plugins/retry-after Retry After Plugin Docs}
|
|
199
|
+
*/
|
|
200
|
+
declare class RetryAfterPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
201
|
+
private readonly condition;
|
|
202
|
+
private readonly maxAttempts;
|
|
203
|
+
private readonly timeout;
|
|
204
|
+
order: number;
|
|
205
|
+
constructor(options?: RetryAfterPluginOptions<T>);
|
|
206
|
+
init(options: StandardLinkOptions<T>): void;
|
|
207
|
+
private parseRetryAfterHeader;
|
|
208
|
+
private delayExecution;
|
|
209
|
+
}
|
|
210
|
+
|
|
124
211
|
interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> {
|
|
125
212
|
/**
|
|
126
213
|
* The name of the header to check.
|
|
127
214
|
*
|
|
128
215
|
* @default 'x-csrf-token'
|
|
129
216
|
*/
|
|
130
|
-
headerName?: Value<string
|
|
217
|
+
headerName?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
131
218
|
/**
|
|
132
219
|
* The value of the header to check.
|
|
133
220
|
*
|
|
134
221
|
* @default 'orpc'
|
|
135
222
|
*
|
|
136
223
|
*/
|
|
137
|
-
headerValue?: Value<string
|
|
224
|
+
headerValue?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
138
225
|
/**
|
|
139
226
|
* Exclude a procedure from the plugin.
|
|
140
227
|
*
|
|
141
228
|
* @default false
|
|
142
229
|
*/
|
|
143
|
-
exclude?: Value<boolean
|
|
230
|
+
exclude?: Value<Promisable<boolean>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
144
231
|
}
|
|
145
232
|
/**
|
|
146
233
|
* This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
|
147
234
|
* It helps ensure that requests to your procedures originate from JavaScript code,
|
|
148
235
|
* not from other sources like standard HTML forms or direct browser navigation.
|
|
149
236
|
*
|
|
150
|
-
* @see {@link https://orpc.
|
|
237
|
+
* @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
|
|
151
238
|
*/
|
|
152
239
|
declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
153
240
|
private readonly headerName;
|
|
@@ -158,5 +245,5 @@ declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements
|
|
|
158
245
|
init(options: StandardLinkOptions<T>): void;
|
|
159
246
|
}
|
|
160
247
|
|
|
161
|
-
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, SimpleCsrfProtectionLinkPlugin };
|
|
162
|
-
export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
|
|
248
|
+
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, RetryAfterPlugin, SimpleCsrfProtectionLinkPlugin };
|
|
249
|
+
export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, RetryAfterPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Value } from '@orpc/shared';
|
|
2
|
-
import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { BatchResponseMode } from '@orpc/standard-server/batch';
|
|
4
|
+
import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.2jUAqzYU.js';
|
|
5
|
+
import { b as ClientContext } from '../shared/client.i2uoJbEp.js';
|
|
5
6
|
|
|
6
7
|
interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
7
8
|
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
@@ -16,25 +17,31 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
16
17
|
*
|
|
17
18
|
* @default 10
|
|
18
19
|
*/
|
|
19
|
-
maxSize?: Value<number
|
|
20
|
+
maxSize?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
21
|
+
/**
|
|
22
|
+
* The batch response mode.
|
|
23
|
+
*
|
|
24
|
+
* @default 'streaming'
|
|
25
|
+
*/
|
|
26
|
+
mode?: Value<BatchResponseMode, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
20
27
|
/**
|
|
21
28
|
* Defines the URL to use for the batch request.
|
|
22
29
|
*
|
|
23
30
|
* @default the URL of the first request in the batch + '/__batch__'
|
|
24
31
|
*/
|
|
25
|
-
url?: Value<string | URL
|
|
32
|
+
url?: Value<Promisable<string | URL>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
26
33
|
/**
|
|
27
34
|
* The maximum length of the URL.
|
|
28
35
|
*
|
|
29
36
|
* @default 2083
|
|
30
37
|
*/
|
|
31
|
-
maxUrlLength?: Value<number
|
|
38
|
+
maxUrlLength?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
32
39
|
/**
|
|
33
40
|
* Defines the HTTP headers to use for the batch request.
|
|
34
41
|
*
|
|
35
42
|
* @default The same headers of all requests in the batch
|
|
36
43
|
*/
|
|
37
|
-
headers?: Value<StandardHeaders
|
|
44
|
+
headers?: Value<Promisable<StandardHeaders>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
38
45
|
/**
|
|
39
46
|
* Map the batch request items before sending them.
|
|
40
47
|
*
|
|
@@ -52,10 +59,10 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
52
59
|
exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
53
60
|
}
|
|
54
61
|
/**
|
|
55
|
-
* The Batch
|
|
62
|
+
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
56
63
|
* reducing the overhead of sending each one separately.
|
|
57
64
|
*
|
|
58
|
-
* @see {@link https://orpc.
|
|
65
|
+
* @see {@link https://orpc.dev/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
59
66
|
*/
|
|
60
67
|
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
61
68
|
#private;
|
|
@@ -66,12 +73,45 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
|
|
|
66
73
|
private readonly batchHeaders;
|
|
67
74
|
private readonly mapRequestItem;
|
|
68
75
|
private readonly exclude;
|
|
76
|
+
private readonly mode;
|
|
69
77
|
private pending;
|
|
70
78
|
order: number;
|
|
71
79
|
constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
|
|
72
80
|
init(options: StandardLinkOptions<T>): void;
|
|
73
81
|
}
|
|
74
82
|
|
|
83
|
+
interface DedupeRequestsPluginGroup<T extends ClientContext> {
|
|
84
|
+
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* The context used for the rest of the request lifecycle.
|
|
87
|
+
*/
|
|
88
|
+
context: T;
|
|
89
|
+
}
|
|
90
|
+
interface DedupeRequestsPluginOptions<T extends ClientContext> {
|
|
91
|
+
/**
|
|
92
|
+
* To enable deduplication, a request must match at least one defined group.
|
|
93
|
+
* Requests that fall into the same group are considered for deduplication together.
|
|
94
|
+
*/
|
|
95
|
+
groups: readonly [DedupeRequestsPluginGroup<T>, ...DedupeRequestsPluginGroup<T>[]];
|
|
96
|
+
/**
|
|
97
|
+
* Filters requests to dedupe
|
|
98
|
+
*
|
|
99
|
+
* @default (({ request }) => request.method === 'GET')
|
|
100
|
+
*/
|
|
101
|
+
filter?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Prevents duplicate requests by deduplicating similar ones to reduce server load.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link https://orpc.dev/docs/plugins/dedupe-requests Dedupe Requests Plugin}
|
|
107
|
+
*/
|
|
108
|
+
declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
109
|
+
#private;
|
|
110
|
+
order: number;
|
|
111
|
+
constructor(options: NoInfer<DedupeRequestsPluginOptions<T>>);
|
|
112
|
+
init(options: StandardLinkOptions<T>): void;
|
|
113
|
+
}
|
|
114
|
+
|
|
75
115
|
interface ClientRetryPluginAttemptOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
|
|
76
116
|
lastEventRetry: number | undefined;
|
|
77
117
|
attemptIndex: number;
|
|
@@ -84,19 +124,19 @@ interface ClientRetryPluginContext {
|
|
|
84
124
|
*
|
|
85
125
|
* @default 0
|
|
86
126
|
*/
|
|
87
|
-
retry?: Value<number
|
|
127
|
+
retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
|
88
128
|
/**
|
|
89
129
|
* Delay (in ms) before retrying.
|
|
90
130
|
*
|
|
91
131
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
92
132
|
*/
|
|
93
|
-
retryDelay?: Value<number
|
|
133
|
+
retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
94
134
|
/**
|
|
95
135
|
* Determine should retry or not.
|
|
96
136
|
*
|
|
97
137
|
* @default true
|
|
98
138
|
*/
|
|
99
|
-
shouldRetry?: Value<boolean
|
|
139
|
+
shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
100
140
|
/**
|
|
101
141
|
* The hook called when retrying, and return the unsubscribe function.
|
|
102
142
|
*/
|
|
@@ -110,44 +150,91 @@ interface ClientRetryPluginOptions {
|
|
|
110
150
|
/**
|
|
111
151
|
* The Client Retry Plugin enables retrying client calls when errors occur.
|
|
112
152
|
*
|
|
113
|
-
* @see {@link https://orpc.
|
|
153
|
+
* @see {@link https://orpc.dev/docs/plugins/client-retry Client Retry Plugin Docs}
|
|
114
154
|
*/
|
|
115
155
|
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
|
116
156
|
private readonly defaultRetry;
|
|
117
157
|
private readonly defaultRetryDelay;
|
|
118
158
|
private readonly defaultShouldRetry;
|
|
119
159
|
private readonly defaultOnRetry;
|
|
160
|
+
order: number;
|
|
120
161
|
constructor(options?: ClientRetryPluginOptions);
|
|
121
162
|
init(options: StandardLinkOptions<T>): void;
|
|
122
163
|
}
|
|
123
164
|
|
|
165
|
+
interface RetryAfterPluginOptions<T extends ClientContext> {
|
|
166
|
+
/**
|
|
167
|
+
* Override condition to determine whether to retry or not.
|
|
168
|
+
*
|
|
169
|
+
* @default ((response) => response.status === 429 || response.status === 503)
|
|
170
|
+
*/
|
|
171
|
+
condition?: Value<boolean, [
|
|
172
|
+
response: StandardLazyResponse,
|
|
173
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
174
|
+
]>;
|
|
175
|
+
/**
|
|
176
|
+
* Maximum attempts before giving up retries.
|
|
177
|
+
*
|
|
178
|
+
* @default 3
|
|
179
|
+
*/
|
|
180
|
+
maxAttempts?: Value<number, [
|
|
181
|
+
response: StandardLazyResponse,
|
|
182
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
183
|
+
]>;
|
|
184
|
+
/**
|
|
185
|
+
* Maximum timeout in milliseconds to wait before giving up retries.
|
|
186
|
+
*
|
|
187
|
+
* @default 5 * 60 * 1000 (5 minutes)
|
|
188
|
+
*/
|
|
189
|
+
timeout?: Value<number, [
|
|
190
|
+
response: StandardLazyResponse,
|
|
191
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
192
|
+
]>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The Retry After Plugin automatically retries requests based on server `Retry-After` headers.
|
|
196
|
+
* This is particularly useful for handling rate limiting and temporary server unavailability.
|
|
197
|
+
*
|
|
198
|
+
* @see {@link https://orpc.dev/docs/plugins/retry-after Retry After Plugin Docs}
|
|
199
|
+
*/
|
|
200
|
+
declare class RetryAfterPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
201
|
+
private readonly condition;
|
|
202
|
+
private readonly maxAttempts;
|
|
203
|
+
private readonly timeout;
|
|
204
|
+
order: number;
|
|
205
|
+
constructor(options?: RetryAfterPluginOptions<T>);
|
|
206
|
+
init(options: StandardLinkOptions<T>): void;
|
|
207
|
+
private parseRetryAfterHeader;
|
|
208
|
+
private delayExecution;
|
|
209
|
+
}
|
|
210
|
+
|
|
124
211
|
interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> {
|
|
125
212
|
/**
|
|
126
213
|
* The name of the header to check.
|
|
127
214
|
*
|
|
128
215
|
* @default 'x-csrf-token'
|
|
129
216
|
*/
|
|
130
|
-
headerName?: Value<string
|
|
217
|
+
headerName?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
131
218
|
/**
|
|
132
219
|
* The value of the header to check.
|
|
133
220
|
*
|
|
134
221
|
* @default 'orpc'
|
|
135
222
|
*
|
|
136
223
|
*/
|
|
137
|
-
headerValue?: Value<string
|
|
224
|
+
headerValue?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
138
225
|
/**
|
|
139
226
|
* Exclude a procedure from the plugin.
|
|
140
227
|
*
|
|
141
228
|
* @default false
|
|
142
229
|
*/
|
|
143
|
-
exclude?: Value<boolean
|
|
230
|
+
exclude?: Value<Promisable<boolean>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
144
231
|
}
|
|
145
232
|
/**
|
|
146
233
|
* This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
|
147
234
|
* It helps ensure that requests to your procedures originate from JavaScript code,
|
|
148
235
|
* not from other sources like standard HTML forms or direct browser navigation.
|
|
149
236
|
*
|
|
150
|
-
* @see {@link https://orpc.
|
|
237
|
+
* @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
|
|
151
238
|
*/
|
|
152
239
|
declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
153
240
|
private readonly headerName;
|
|
@@ -158,5 +245,5 @@ declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements
|
|
|
158
245
|
init(options: StandardLinkOptions<T>): void;
|
|
159
246
|
}
|
|
160
247
|
|
|
161
|
-
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, SimpleCsrfProtectionLinkPlugin };
|
|
162
|
-
export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
|
|
248
|
+
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, RetryAfterPlugin, SimpleCsrfProtectionLinkPlugin };
|
|
249
|
+
export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, RetryAfterPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
|