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