@orpc/client 2.0.0-beta.49 → 2.0.0-beta.50
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/dist/adapters/fetch/index.d.ts +3 -2
- package/dist/adapters/fetch/index.js +2 -2
- package/dist/adapters/fetch/rpc-link.d.ts +8 -8
- package/dist/adapters/fetch/rpc-link.js +16 -13
- package/dist/adapters/fetch/transport.d.ts +29 -31
- package/dist/adapters/fetch/transport.js +49 -63
- package/dist/adapters/message-port/index.d.ts +4 -3
- package/dist/adapters/message-port/index.js +3 -3
- package/dist/adapters/message-port/message-port.d.ts +13 -13
- package/dist/adapters/message-port/message-port.js +35 -53
- package/dist/adapters/message-port/rpc-link.d.ts +8 -8
- package/dist/adapters/message-port/rpc-link.js +17 -14
- package/dist/adapters/message-port/transport.d.ts +31 -34
- package/dist/adapters/message-port/transport.js +38 -52
- package/dist/adapters/standard/codec.d.ts +10 -10
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.js +2 -4
- package/dist/adapters/standard/link.d.ts +31 -31
- package/dist/adapters/standard/link.js +101 -85
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-link-codec.d.ts +53 -60
- package/dist/adapters/standard/rpc-link-codec.js +98 -102
- package/dist/adapters/standard/transport.d.ts +7 -7
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-link.d.ts +8 -8
- package/dist/adapters/websocket/rpc-link.js +16 -13
- package/dist/adapters/websocket/transport.d.ts +101 -100
- package/dist/adapters/websocket/transport.js +102 -130
- package/dist/async-iterator-object.d.ts +2 -2
- package/dist/async-iterator-object.js +27 -28
- package/dist/client-safe.d.ts +4 -6
- package/dist/client-safe.js +29 -34
- package/dist/client.d.ts +24 -26
- package/dist/client.js +35 -37
- package/dist/consts.d.ts +1 -1
- package/dist/consts.js +18 -41
- package/dist/dynamic-link.d.ts +6 -6
- package/dist/dynamic-link.js +16 -16
- package/dist/error-utils.d.ts +3 -4
- package/dist/error-utils.js +47 -51
- package/dist/error.d.ts +79 -79
- package/dist/error.js +154 -166
- package/dist/index.d.ts +14 -53
- package/dist/index.js +12 -40
- package/dist/plugins/batch.d.ts +122 -155
- package/dist/plugins/batch.js +320 -391
- package/dist/plugins/cookie-jar.d.ts +64 -61
- package/dist/plugins/cookie-jar.js +208 -245
- package/dist/plugins/dedupe.d.ts +49 -53
- package/dist/plugins/dedupe.js +168 -211
- package/dist/plugins/index.d.ts +9 -28
- package/dist/plugins/index.js +8 -23
- package/dist/plugins/request-compression.d.ts +38 -35
- package/dist/plugins/request-compression.js +131 -177
- package/dist/plugins/response-compression.d.ts +21 -18
- package/dist/plugins/response-compression.js +64 -88
- package/dist/plugins/retry-after.d.ts +31 -38
- package/dist/plugins/retry-after.js +60 -85
- package/dist/plugins/retry.d.ts +55 -55
- package/dist/plugins/retry.js +118 -137
- package/dist/plugins/timeout.d.ts +19 -17
- package/dist/plugins/timeout.js +41 -36
- package/dist/rpc-json-serializer.d.ts +84 -84
- package/dist/rpc-json-serializer.js +338 -383
- package/dist/rpc-serializer.d.ts +20 -21
- package/dist/rpc-serializer.js +97 -125
- package/dist/types.d.ts +19 -31
- package/dist/utils.d.ts +18 -29
- package/dist/utils.js +63 -47
- package/package.json +5 -5
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/adapters/standard/transport.js +0 -1
- package/dist/types.js +0 -1
package/dist/plugins/batch.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import "../adapters/standard/index.js";
|
|
2
|
+
import { StandardLinkPlugin } from "../adapters/standard/plugin.js";
|
|
3
|
+
import { StandardLinkOptions, StandardLinkTransportInterceptorOptions } from "../adapters/standard/link.js";
|
|
4
|
+
import { ClientContext } from "../types.js";
|
|
5
|
+
import { Promisable, Value } from "@orpc/shared";
|
|
6
|
+
import { StandardHeaders, StandardLazyResponse, StandardRequest, StandardUrl } from "@standard-server/core";
|
|
5
7
|
/**
|
|
6
8
|
* Header that marks a request as a batch, set by the Batch Link Plugin and detected by the Batch Handler Plugin.
|
|
7
9
|
* Nothing between the client and server, such as a CORS policy or proxy, should block or strip it.
|
|
@@ -18,136 +20,101 @@ export declare const DEFAULT_BATCH_MAX_SIZE = 10;
|
|
|
18
20
|
/**
|
|
19
21
|
* @see {@link https://orpc.dev/docs/plugins/batch#response-modes | Batch Plugin - Response Modes}
|
|
20
22
|
*/
|
|
21
|
-
export type BatchLinkPluginMode =
|
|
23
|
+
export type BatchLinkPluginMode = "buffered" | "streaming";
|
|
22
24
|
export interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* The path segments applied to requests in this batch group for the remainder of the link chain.
|
|
41
|
-
*
|
|
42
|
-
* @default []
|
|
43
|
-
*/
|
|
44
|
-
path?: Value<string[], [
|
|
45
|
-
items: [
|
|
46
|
-
StandardLinkTransportInterceptorOptions<T>,
|
|
47
|
-
...StandardLinkTransportInterceptorOptions<T>[]
|
|
48
|
-
]
|
|
49
|
-
]> | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Determines whether a request should be included in this batch group.
|
|
27
|
+
* Requests will be evaluated against each group's condition in order,
|
|
28
|
+
* and included in the first group whose condition returns true.
|
|
29
|
+
* If no group's condition returns true, the request will not be batched.
|
|
30
|
+
*/
|
|
31
|
+
condition: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]>;
|
|
32
|
+
/**
|
|
33
|
+
* The client context applied to requests in this batch group for the remainder of the link chain.
|
|
34
|
+
*/
|
|
35
|
+
context: Value<T, [items: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]>;
|
|
36
|
+
/**
|
|
37
|
+
* The path segments applied to requests in this batch group for the remainder of the link chain.
|
|
38
|
+
*
|
|
39
|
+
* @default []
|
|
40
|
+
*/
|
|
41
|
+
path?: Value<string[], [items: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
|
|
50
42
|
}
|
|
51
43
|
export interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
]
|
|
127
|
-
]> | undefined;
|
|
128
|
-
/**
|
|
129
|
-
* Headers used for the batch request.
|
|
130
|
-
*
|
|
131
|
-
* @default Common headers among all subrequests in the batch.
|
|
132
|
-
*/
|
|
133
|
-
headers?: Value<Promisable<StandardHeaders>, [
|
|
134
|
-
subOptionsList: [
|
|
135
|
-
StandardLinkTransportInterceptorOptions<T>,
|
|
136
|
-
...StandardLinkTransportInterceptorOptions<T>[]
|
|
137
|
-
]
|
|
138
|
-
]> | undefined;
|
|
139
|
-
/**
|
|
140
|
-
* Map each subrequest in the batch before it is sent.
|
|
141
|
-
*
|
|
142
|
-
* @default Removes headers that are duplicated with the batch headers
|
|
143
|
-
*/
|
|
144
|
-
mapSubrequest?: ((subOptions: StandardLinkTransportInterceptorOptions<T>, partialBatchRequest: Pick<StandardRequest, 'url' | 'headers'>) => StandardRequest) | undefined;
|
|
145
|
-
/**
|
|
146
|
-
* Maps each subresponse before returning the final response.
|
|
147
|
-
*
|
|
148
|
-
* @default Low-priority merges headers from the batch response into each subresponse.
|
|
149
|
-
*/
|
|
150
|
-
mapSubresponse?: ((subResponse: StandardLazyResponse, batchResponse: StandardLazyResponse, subOptions: StandardLinkTransportInterceptorOptions<T>) => StandardLazyResponse) | undefined;
|
|
44
|
+
groups: [BatchLinkPluginGroup<T>, ...BatchLinkPluginGroup<T>[]];
|
|
45
|
+
/**
|
|
46
|
+
* Filters requests to batch.
|
|
47
|
+
*
|
|
48
|
+
* @default () => true
|
|
49
|
+
*/
|
|
50
|
+
filter?: Value<boolean, [options: StandardLinkTransportInterceptorOptions<T>]> | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Only requests with the same scope are batched together.
|
|
53
|
+
* On the server, return a value unique to the incoming request so different users never share a batch.
|
|
54
|
+
*
|
|
55
|
+
* @default () => undefined
|
|
56
|
+
*/
|
|
57
|
+
scope?: ((options: StandardLinkTransportInterceptorOptions<T>) => unknown) | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* The maximum number of requests in the batch. Larger batches are split.
|
|
60
|
+
* Keep it at or below the server Batch Handler Plugin's `maxSize`, which rejects larger batches with a `413`.
|
|
61
|
+
*
|
|
62
|
+
* @default DEFAULT_BATCH_MAX_SIZE (10)
|
|
63
|
+
* @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
|
|
64
|
+
*/
|
|
65
|
+
maxSize?: Value<Promisable<number>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* How long (in ms) to wait for more requests before sending the batch,
|
|
68
|
+
* counted from the first queued request.
|
|
69
|
+
* With `0`, only requests made in the same event loop tick are batched.
|
|
70
|
+
*
|
|
71
|
+
* @default 0
|
|
72
|
+
*/
|
|
73
|
+
wait?: number | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* How the server sends the batch response.
|
|
76
|
+
*
|
|
77
|
+
* - `buffered`: waits for every subrequest, so the response carries their cookies and shared headers.
|
|
78
|
+
* - `streaming`: starts once the first subrequest responds and sends each other response as soon as it is
|
|
79
|
+
* ready, but carries only that first one's cookies.
|
|
80
|
+
*
|
|
81
|
+
* @default 'buffered'
|
|
82
|
+
* @see {@link https://orpc.dev/docs/plugins/batch#response-modes | Batch Plugin - Response Modes}
|
|
83
|
+
*/
|
|
84
|
+
mode?: Value<Promisable<BatchLinkPluginMode>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* URL for the batch request.
|
|
87
|
+
*
|
|
88
|
+
* @default URL of the first subrequest in the batch + '/__batch__'
|
|
89
|
+
*/
|
|
90
|
+
url?: Value<Promisable<StandardUrl>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* The maximum length of the URL that runtime supports,
|
|
93
|
+
* if exceeded, the batch will be split into smaller batches and sent sequentially.
|
|
94
|
+
*
|
|
95
|
+
* This only applies to GET batch requests where the batch data is sent via URL query parameter.
|
|
96
|
+
*
|
|
97
|
+
* @default 2083
|
|
98
|
+
*/
|
|
99
|
+
maxUrlLength?: Value<Promisable<number>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Headers used for the batch request.
|
|
102
|
+
*
|
|
103
|
+
* @default Common headers among all subrequests in the batch.
|
|
104
|
+
*/
|
|
105
|
+
headers?: Value<Promisable<StandardHeaders>, [subOptionsList: [StandardLinkTransportInterceptorOptions<T>, ...StandardLinkTransportInterceptorOptions<T>[]]]> | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Map each subrequest in the batch before it is sent.
|
|
108
|
+
*
|
|
109
|
+
* @default Removes headers that are duplicated with the batch headers
|
|
110
|
+
*/
|
|
111
|
+
mapSubrequest?: ((subOptions: StandardLinkTransportInterceptorOptions<T>, partialBatchRequest: Pick<StandardRequest, "url" | "headers">) => StandardRequest) | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Maps each subresponse before returning the final response.
|
|
114
|
+
*
|
|
115
|
+
* @default Low-priority merges headers from the batch response into each subresponse.
|
|
116
|
+
*/
|
|
117
|
+
mapSubresponse?: ((subResponse: StandardLazyResponse, batchResponse: StandardLazyResponse, subOptions: StandardLinkTransportInterceptorOptions<T>) => StandardLazyResponse) | undefined;
|
|
151
118
|
}
|
|
152
119
|
/**
|
|
153
120
|
* Combines multiple client requests into a single batch request
|
|
@@ -159,27 +126,27 @@ export interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
159
126
|
* @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
|
|
160
127
|
*/
|
|
161
128
|
export declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
129
|
+
name: string;
|
|
130
|
+
private readonly groups;
|
|
131
|
+
private readonly filter;
|
|
132
|
+
private readonly scope;
|
|
133
|
+
private readonly maxSize;
|
|
134
|
+
private readonly wait;
|
|
135
|
+
private readonly mode;
|
|
136
|
+
private readonly batchUrl;
|
|
137
|
+
private readonly maxUrlLength;
|
|
138
|
+
private readonly batchHeaders;
|
|
139
|
+
private readonly mapSubrequest;
|
|
140
|
+
private readonly mapSubresponse;
|
|
141
|
+
private readonly queue;
|
|
142
|
+
constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
|
|
143
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
144
|
+
private processPendingBatches;
|
|
145
|
+
/**
|
|
146
|
+
* Runs the batch in the async context of its first request instead of the timer's,
|
|
147
|
+
* so the transport and batch options see that caller's request state.
|
|
148
|
+
* `executeBatch` always runs in the context of its first request.
|
|
149
|
+
*/
|
|
150
|
+
private executeBatchInOwnContext;
|
|
151
|
+
private executeBatch;
|
|
152
|
+
}
|