@orpc/client 0.0.0-next.57d90ad → 0.0.0-next.583344a

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.
@@ -1,7 +1,7 @@
1
- import { Value } from '@orpc/shared';
1
+ import { Value, Promisable } from '@orpc/shared';
2
2
  import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
3
- import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.Bt2hFtM_.mjs';
4
- import { a as ClientContext } from '../shared/client.CipPQkhk.mjs';
3
+ import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.BMoG_EdN.mjs';
4
+ import { a as ClientContext } from '../shared/client.4TS_0JaO.mjs';
5
5
 
6
6
  interface BatchLinkPluginGroup<T extends ClientContext> {
7
7
  condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
@@ -16,25 +16,25 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
16
16
  *
17
17
  * @default 10
18
18
  */
19
- maxSize?: Value<number, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
19
+ maxSize?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
20
20
  /**
21
21
  * Defines the URL to use for the batch request.
22
22
  *
23
23
  * @default the URL of the first request in the batch + '/__batch__'
24
24
  */
25
- url?: Value<string | URL, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
25
+ url?: Value<Promisable<string | URL>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
26
26
  /**
27
27
  * The maximum length of the URL.
28
28
  *
29
29
  * @default 2083
30
30
  */
31
- maxUrlLength?: Value<number, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
31
+ maxUrlLength?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
32
32
  /**
33
33
  * Defines the HTTP headers to use for the batch request.
34
34
  *
35
35
  * @default The same headers of all requests in the batch
36
36
  */
37
- headers?: Value<StandardHeaders, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
37
+ headers?: Value<Promisable<StandardHeaders>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
38
38
  /**
39
39
  * Map the batch request items before sending them.
40
40
  *
@@ -51,6 +51,12 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
51
51
  */
52
52
  exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
53
53
  }
54
+ /**
55
+ * The Batch Request/Response Plugin allows you to combine multiple requests and responses into a single batch,
56
+ * reducing the overhead of sending each one separately.
57
+ *
58
+ * @see {@link https://orpc.unnoq.com/docs/plugins/batch-request-response Batch Request/Response Plugin Docs}
59
+ */
54
60
  declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
55
61
  #private;
56
62
  private readonly groups;
@@ -62,7 +68,39 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
62
68
  private readonly exclude;
63
69
  private pending;
64
70
  order: number;
65
- constructor(options: BatchLinkPluginOptions<T>);
71
+ constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
72
+ init(options: StandardLinkOptions<T>): void;
73
+ }
74
+
75
+ interface DedupeRequestsPluginGroup<T extends ClientContext> {
76
+ condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
77
+ /**
78
+ * The context used for the rest of the request lifecycle.
79
+ */
80
+ context: T;
81
+ }
82
+ interface DedupeRequestsPluginOptions<T extends ClientContext> {
83
+ /**
84
+ * To enable deduplication, a request must match at least one defined group.
85
+ * Requests that fall into the same group are considered for deduplication together.
86
+ */
87
+ groups: readonly [DedupeRequestsPluginGroup<T>, ...DedupeRequestsPluginGroup<T>[]];
88
+ /**
89
+ * Filters requests to dedupe
90
+ *
91
+ * @default (({ request }) => request.method === 'GET')
92
+ */
93
+ filter?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
94
+ }
95
+ /**
96
+ * Prevents duplicate requests by deduplicating similar ones to reduce server load.
97
+ *
98
+ * @see {@link https://orpc.unnoq.com/docs/plugins/dedupe-requests Dedupe Requests Plugin}
99
+ */
100
+ declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
101
+ #private;
102
+ order: number;
103
+ constructor(options: NoInfer<DedupeRequestsPluginOptions<T>>);
66
104
  init(options: StandardLinkOptions<T>): void;
67
105
  }
68
106
 
@@ -78,29 +116,34 @@ interface ClientRetryPluginContext {
78
116
  *
79
117
  * @default 0
80
118
  */
81
- retry?: Value<number, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
119
+ retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
82
120
  /**
83
121
  * Delay (in ms) before retrying.
84
122
  *
85
123
  * @default (o) => o.lastEventRetry ?? 2000
86
124
  */
87
- retryDelay?: Value<number, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
125
+ retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
88
126
  /**
89
127
  * Determine should retry or not.
90
128
  *
91
129
  * @default true
92
130
  */
93
- shouldRetry?: Value<boolean, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
131
+ shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
94
132
  /**
95
133
  * The hook called when retrying, and return the unsubscribe function.
96
134
  */
97
- onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | (() => void);
135
+ onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
98
136
  }
99
137
  declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
100
138
  }
101
139
  interface ClientRetryPluginOptions {
102
140
  default?: ClientRetryPluginContext;
103
141
  }
142
+ /**
143
+ * The Client Retry Plugin enables retrying client calls when errors occur.
144
+ *
145
+ * @see {@link https://orpc.unnoq.com/docs/plugins/client-retry Client Retry Plugin Docs}
146
+ */
104
147
  declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
105
148
  private readonly defaultRetry;
106
149
  private readonly defaultRetryDelay;
@@ -116,21 +159,28 @@ interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> {
116
159
  *
117
160
  * @default 'x-csrf-token'
118
161
  */
119
- headerName?: Value<string, [options: StandardLinkClientInterceptorOptions<T>]>;
162
+ headerName?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
120
163
  /**
121
164
  * The value of the header to check.
122
165
  *
123
166
  * @default 'orpc'
124
167
  *
125
168
  */
126
- headerValue?: Value<string, [options: StandardLinkClientInterceptorOptions<T>]>;
169
+ headerValue?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
127
170
  /**
128
171
  * Exclude a procedure from the plugin.
129
172
  *
130
173
  * @default false
131
174
  */
132
- exclude?: Value<boolean, [options: StandardLinkClientInterceptorOptions<T>]>;
175
+ exclude?: Value<Promisable<boolean>, [options: StandardLinkClientInterceptorOptions<T>]>;
133
176
  }
177
+ /**
178
+ * This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
179
+ * It helps ensure that requests to your procedures originate from JavaScript code,
180
+ * not from other sources like standard HTML forms or direct browser navigation.
181
+ *
182
+ * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
183
+ */
134
184
  declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
135
185
  private readonly headerName;
136
186
  private readonly headerValue;
@@ -140,4 +190,5 @@ declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements
140
190
  init(options: StandardLinkOptions<T>): void;
141
191
  }
142
192
 
143
- export { BatchLinkPlugin, type BatchLinkPluginGroup, type BatchLinkPluginOptions, ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions, SimpleCsrfProtectionLinkPlugin, type SimpleCsrfProtectionLinkPluginOptions };
193
+ export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin };
194
+ export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
@@ -1,7 +1,7 @@
1
- import { Value } from '@orpc/shared';
1
+ import { Value, Promisable } from '@orpc/shared';
2
2
  import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
3
- import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.FvDtk0Vr.js';
4
- import { a as ClientContext } from '../shared/client.CipPQkhk.js';
3
+ import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.C0KbSWlC.js';
4
+ import { a as ClientContext } from '../shared/client.4TS_0JaO.js';
5
5
 
6
6
  interface BatchLinkPluginGroup<T extends ClientContext> {
7
7
  condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
@@ -16,25 +16,25 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
16
16
  *
17
17
  * @default 10
18
18
  */
19
- maxSize?: Value<number, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
19
+ maxSize?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
20
20
  /**
21
21
  * Defines the URL to use for the batch request.
22
22
  *
23
23
  * @default the URL of the first request in the batch + '/__batch__'
24
24
  */
25
- url?: Value<string | URL, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
25
+ url?: Value<Promisable<string | URL>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
26
26
  /**
27
27
  * The maximum length of the URL.
28
28
  *
29
29
  * @default 2083
30
30
  */
31
- maxUrlLength?: Value<number, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
31
+ maxUrlLength?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
32
32
  /**
33
33
  * Defines the HTTP headers to use for the batch request.
34
34
  *
35
35
  * @default The same headers of all requests in the batch
36
36
  */
37
- headers?: Value<StandardHeaders, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
37
+ headers?: Value<Promisable<StandardHeaders>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
38
38
  /**
39
39
  * Map the batch request items before sending them.
40
40
  *
@@ -51,6 +51,12 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
51
51
  */
52
52
  exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
53
53
  }
54
+ /**
55
+ * The Batch Request/Response Plugin allows you to combine multiple requests and responses into a single batch,
56
+ * reducing the overhead of sending each one separately.
57
+ *
58
+ * @see {@link https://orpc.unnoq.com/docs/plugins/batch-request-response Batch Request/Response Plugin Docs}
59
+ */
54
60
  declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
55
61
  #private;
56
62
  private readonly groups;
@@ -62,7 +68,39 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
62
68
  private readonly exclude;
63
69
  private pending;
64
70
  order: number;
65
- constructor(options: BatchLinkPluginOptions<T>);
71
+ constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
72
+ init(options: StandardLinkOptions<T>): void;
73
+ }
74
+
75
+ interface DedupeRequestsPluginGroup<T extends ClientContext> {
76
+ condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
77
+ /**
78
+ * The context used for the rest of the request lifecycle.
79
+ */
80
+ context: T;
81
+ }
82
+ interface DedupeRequestsPluginOptions<T extends ClientContext> {
83
+ /**
84
+ * To enable deduplication, a request must match at least one defined group.
85
+ * Requests that fall into the same group are considered for deduplication together.
86
+ */
87
+ groups: readonly [DedupeRequestsPluginGroup<T>, ...DedupeRequestsPluginGroup<T>[]];
88
+ /**
89
+ * Filters requests to dedupe
90
+ *
91
+ * @default (({ request }) => request.method === 'GET')
92
+ */
93
+ filter?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
94
+ }
95
+ /**
96
+ * Prevents duplicate requests by deduplicating similar ones to reduce server load.
97
+ *
98
+ * @see {@link https://orpc.unnoq.com/docs/plugins/dedupe-requests Dedupe Requests Plugin}
99
+ */
100
+ declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
101
+ #private;
102
+ order: number;
103
+ constructor(options: NoInfer<DedupeRequestsPluginOptions<T>>);
66
104
  init(options: StandardLinkOptions<T>): void;
67
105
  }
68
106
 
@@ -78,29 +116,34 @@ interface ClientRetryPluginContext {
78
116
  *
79
117
  * @default 0
80
118
  */
81
- retry?: Value<number, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
119
+ retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
82
120
  /**
83
121
  * Delay (in ms) before retrying.
84
122
  *
85
123
  * @default (o) => o.lastEventRetry ?? 2000
86
124
  */
87
- retryDelay?: Value<number, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
125
+ retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
88
126
  /**
89
127
  * Determine should retry or not.
90
128
  *
91
129
  * @default true
92
130
  */
93
- shouldRetry?: Value<boolean, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
131
+ shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
94
132
  /**
95
133
  * The hook called when retrying, and return the unsubscribe function.
96
134
  */
97
- onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | (() => void);
135
+ onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
98
136
  }
99
137
  declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
100
138
  }
101
139
  interface ClientRetryPluginOptions {
102
140
  default?: ClientRetryPluginContext;
103
141
  }
142
+ /**
143
+ * The Client Retry Plugin enables retrying client calls when errors occur.
144
+ *
145
+ * @see {@link https://orpc.unnoq.com/docs/plugins/client-retry Client Retry Plugin Docs}
146
+ */
104
147
  declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
105
148
  private readonly defaultRetry;
106
149
  private readonly defaultRetryDelay;
@@ -116,21 +159,28 @@ interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> {
116
159
  *
117
160
  * @default 'x-csrf-token'
118
161
  */
119
- headerName?: Value<string, [options: StandardLinkClientInterceptorOptions<T>]>;
162
+ headerName?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
120
163
  /**
121
164
  * The value of the header to check.
122
165
  *
123
166
  * @default 'orpc'
124
167
  *
125
168
  */
126
- headerValue?: Value<string, [options: StandardLinkClientInterceptorOptions<T>]>;
169
+ headerValue?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
127
170
  /**
128
171
  * Exclude a procedure from the plugin.
129
172
  *
130
173
  * @default false
131
174
  */
132
- exclude?: Value<boolean, [options: StandardLinkClientInterceptorOptions<T>]>;
175
+ exclude?: Value<Promisable<boolean>, [options: StandardLinkClientInterceptorOptions<T>]>;
133
176
  }
177
+ /**
178
+ * This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
179
+ * It helps ensure that requests to your procedures originate from JavaScript code,
180
+ * not from other sources like standard HTML forms or direct browser navigation.
181
+ *
182
+ * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
183
+ */
134
184
  declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
135
185
  private readonly headerName;
136
186
  private readonly headerValue;
@@ -140,4 +190,5 @@ declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements
140
190
  init(options: StandardLinkOptions<T>): void;
141
191
  }
142
192
 
143
- export { BatchLinkPlugin, type BatchLinkPluginGroup, type BatchLinkPluginOptions, ClientRetryPlugin, type ClientRetryPluginAttemptOptions, type ClientRetryPluginContext, ClientRetryPluginInvalidEventIteratorRetryResponse, type ClientRetryPluginOptions, SimpleCsrfProtectionLinkPlugin, type SimpleCsrfProtectionLinkPluginOptions };
193
+ export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin };
194
+ export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
@@ -1,6 +1,6 @@
1
- import { isAsyncIteratorObject, value, splitInHalf, toArray } from '@orpc/shared';
2
- import { toBatchRequest, parseBatchResponse } from '@orpc/standard-server/batch';
3
- import { getEventMeta } from '@orpc/standard-server';
1
+ import { isAsyncIteratorObject, value, splitInHalf, toArray, stringifyJSON } from '@orpc/shared';
2
+ import { toBatchRequest, parseBatchResponse, toBatchAbortSignal } from '@orpc/standard-server/batch';
3
+ import { replicateStandardLazyResponse, getEventMeta } from '@orpc/standard-server';
4
4
 
5
5
  class BatchLinkPlugin {
6
6
  groups;
@@ -147,6 +147,101 @@ class BatchLinkPlugin {
147
147
  }
148
148
  }
149
149
 
150
+ class DedupeRequestsPlugin {
151
+ #groups;
152
+ #filter;
153
+ order = 4e6;
154
+ // make sure execute before batch plugin
155
+ #queue = /* @__PURE__ */ new Map();
156
+ constructor(options) {
157
+ this.#groups = options.groups;
158
+ this.#filter = options.filter ?? (({ request }) => request.method === "GET");
159
+ }
160
+ init(options) {
161
+ options.clientInterceptors ??= [];
162
+ options.clientInterceptors.push((options2) => {
163
+ if (options2.request.body instanceof Blob || options2.request.body instanceof FormData || options2.request.body instanceof URLSearchParams || isAsyncIteratorObject(options2.request.body) || !this.#filter(options2)) {
164
+ return options2.next();
165
+ }
166
+ const group = this.#groups.find((group2) => group2.condition(options2));
167
+ if (!group) {
168
+ return options2.next();
169
+ }
170
+ return new Promise((resolve, reject) => {
171
+ this.#enqueue(group, options2, resolve, reject);
172
+ setTimeout(() => this.#dequeue());
173
+ });
174
+ });
175
+ }
176
+ #enqueue(group, options, resolve, reject) {
177
+ let queue = this.#queue.get(group);
178
+ if (!queue) {
179
+ this.#queue.set(group, queue = []);
180
+ }
181
+ const matched = queue.find((item) => {
182
+ const requestString1 = stringifyJSON({
183
+ body: item.options.request.body,
184
+ headers: item.options.request.headers,
185
+ method: item.options.request.method,
186
+ url: item.options.request.url
187
+ });
188
+ const requestString2 = stringifyJSON({
189
+ body: options.request.body,
190
+ headers: options.request.headers,
191
+ method: options.request.method,
192
+ url: options.request.url
193
+ });
194
+ return requestString1 === requestString2;
195
+ });
196
+ if (matched) {
197
+ matched.signals.push(options.request.signal);
198
+ matched.resolves.push(resolve);
199
+ matched.rejects.push(reject);
200
+ } else {
201
+ queue.push({
202
+ options,
203
+ signals: [options.request.signal],
204
+ resolves: [resolve],
205
+ rejects: [reject]
206
+ });
207
+ }
208
+ }
209
+ async #dequeue() {
210
+ const promises = [];
211
+ for (const [group, items] of this.#queue) {
212
+ for (const { options, signals, resolves, rejects } of items) {
213
+ promises.push(
214
+ this.#execute(group, options, signals, resolves, rejects)
215
+ );
216
+ }
217
+ }
218
+ this.#queue.clear();
219
+ await Promise.all(promises);
220
+ }
221
+ async #execute(group, options, signals, resolves, rejects) {
222
+ try {
223
+ const dedupedRequest = {
224
+ ...options.request,
225
+ signal: toBatchAbortSignal(signals)
226
+ };
227
+ const response = await options.next({
228
+ ...options,
229
+ request: dedupedRequest,
230
+ signal: dedupedRequest.signal,
231
+ context: group.context
232
+ });
233
+ const replicatedResponses = replicateStandardLazyResponse(response, resolves.length);
234
+ for (const resolve of resolves) {
235
+ resolve(replicatedResponses.shift());
236
+ }
237
+ } catch (error) {
238
+ for (const reject of rejects) {
239
+ reject(error);
240
+ }
241
+ }
242
+ }
243
+ }
244
+
150
245
  class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
151
246
  }
152
247
  class ClientRetryPlugin {
@@ -175,20 +270,20 @@ class ClientRetryPlugin {
175
270
  }
176
271
  let lastEventId = interceptorOptions.lastEventId;
177
272
  let lastEventRetry;
178
- let unsubscribe;
273
+ let callback;
179
274
  let attemptIndex = 0;
180
- const next = async (initial) => {
181
- let current = initial;
275
+ const next = async (initialError) => {
276
+ let currentError = initialError;
182
277
  while (true) {
183
278
  const updatedInterceptorOptions = { ...interceptorOptions, lastEventId };
184
- if (current) {
279
+ if (currentError) {
185
280
  if (attemptIndex >= maxAttempts) {
186
- throw current.error;
281
+ throw currentError.error;
187
282
  }
188
283
  const attemptOptions = {
189
284
  ...updatedInterceptorOptions,
190
285
  attemptIndex,
191
- error: current.error,
286
+ error: currentError.error,
192
287
  lastEventRetry
193
288
  };
194
289
  const shouldRetryBool = await value(
@@ -196,23 +291,24 @@ class ClientRetryPlugin {
196
291
  attemptOptions
197
292
  );
198
293
  if (!shouldRetryBool) {
199
- throw current.error;
294
+ throw currentError.error;
200
295
  }
201
- unsubscribe = onRetry?.(attemptOptions);
296
+ callback = onRetry?.(attemptOptions);
202
297
  const retryDelayMs = await value(retryDelay, attemptOptions);
203
298
  await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
204
299
  attemptIndex++;
205
300
  }
206
301
  try {
302
+ currentError = void 0;
207
303
  return await interceptorOptions.next(updatedInterceptorOptions);
208
304
  } catch (error) {
305
+ currentError = { error };
209
306
  if (updatedInterceptorOptions.signal?.aborted === true) {
210
307
  throw error;
211
308
  }
212
- current = { error };
213
309
  } finally {
214
- unsubscribe?.();
215
- unsubscribe = void 0;
310
+ callback?.(!currentError);
311
+ callback = void 0;
216
312
  }
217
313
  }
218
314
  };
@@ -287,4 +383,4 @@ class SimpleCsrfProtectionLinkPlugin {
287
383
  }
288
384
  }
289
385
 
290
- export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, SimpleCsrfProtectionLinkPlugin };
386
+ export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin };
@@ -1,7 +1,7 @@
1
1
  import { PromiseWithError } from '@orpc/shared';
2
2
 
3
3
  type HTTPPath = `/${string}`;
4
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
4
+ type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
5
  type ClientContext = Record<PropertyKey, any>;
6
6
  interface ClientOptions<T extends ClientContext> {
7
7
  signal?: AbortSignal;
@@ -1,7 +1,7 @@
1
1
  import { PromiseWithError } from '@orpc/shared';
2
2
 
3
3
  type HTTPPath = `/${string}`;
4
- type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
4
+ type HTTPMethod = 'HEAD' | 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
5
5
  type ClientContext = Record<PropertyKey, any>;
6
6
  interface ClientOptions<T extends ClientContext> {
7
7
  signal?: AbortSignal;
@@ -1,6 +1,6 @@
1
- import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.CipPQkhk.js';
2
- import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.FvDtk0Vr.js';
3
- import { Segment, Value } from '@orpc/shared';
1
+ import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.4TS_0JaO.js';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.C0KbSWlC.js';
3
+ import { Segment, Value, Promisable } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
6
6
  declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
@@ -44,30 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
44
  /**
45
45
  * Base url for all requests.
46
46
  */
47
- url: Value<string | URL, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
47
+ url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
48
  /**
49
49
  * The maximum length of the URL.
50
50
  *
51
51
  * @default 2083
52
52
  */
53
- maxUrlLength?: Value<number, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
53
+ maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
54
  /**
55
55
  * The method used to make the request.
56
56
  *
57
57
  * @default 'POST'
58
58
  */
59
- method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
59
+ method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
60
  /**
61
61
  * The method to use when the payload cannot safely pass to the server with method return from method function.
62
62
  * GET is not allowed, it's very dangerous.
63
63
  *
64
64
  * @default 'POST'
65
65
  */
66
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
66
+ fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
67
67
  /**
68
68
  * Inject headers to the request.
69
69
  */
70
- headers?: Value<StandardHeaders, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
70
+ headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
71
  }
72
72
  declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
73
  private readonly serializer;
@@ -87,4 +87,5 @@ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
87
87
  constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
88
88
  }
89
89
 
90
- export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, StandardRPCLink as g, type StandardRPCLinkCodecOptions as h, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
90
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
91
+ export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
@@ -1,14 +1,6 @@
1
- import { Interceptor, ThrowableError } from '@orpc/shared';
1
+ import { Interceptor } from '@orpc/shared';
2
2
  import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
- import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.CipPQkhk.js';
4
-
5
- interface StandardLinkCodec<T extends ClientContext> {
6
- encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
7
- decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
- }
9
- interface StandardLinkClient<T extends ClientContext> {
10
- call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
- }
3
+ import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.4TS_0JaO.mjs';
12
4
 
13
5
  interface StandardLinkPlugin<T extends ClientContext> {
14
6
  order?: number;
@@ -20,6 +12,14 @@ declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin exten
20
12
  init(options: StandardLinkOptions<T>): void;
21
13
  }
22
14
 
15
+ interface StandardLinkCodec<T extends ClientContext> {
16
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
17
+ decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
18
+ }
19
+ interface StandardLinkClient<T extends ClientContext> {
20
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
21
+ }
22
+
23
23
  interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
24
24
  path: readonly string[];
25
25
  input: unknown;
@@ -28,8 +28,8 @@ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends
28
28
  request: StandardRequest;
29
29
  }
30
30
  interface StandardLinkOptions<T extends ClientContext> {
31
- interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown, ThrowableError>[];
32
- clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse, ThrowableError>[];
31
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>[];
32
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, Promise<StandardLazyResponse>>[];
33
33
  plugins?: StandardLinkPlugin<T>[];
34
34
  }
35
35
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
@@ -42,4 +42,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
42
42
  call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
43
43
  }
44
44
 
45
- export { CompositeStandardLinkPlugin as C, type StandardLinkClientInterceptorOptions as S, type StandardLinkPlugin as a, type StandardLinkOptions as b, type StandardLinkInterceptorOptions as c, StandardLink as d, type StandardLinkCodec as e, type StandardLinkClient as f };
45
+ export { CompositeStandardLinkPlugin as C, StandardLink as d };
46
+ export type { StandardLinkClientInterceptorOptions as S, StandardLinkPlugin as a, StandardLinkOptions as b, StandardLinkInterceptorOptions as c, StandardLinkCodec as e, StandardLinkClient as f };