@orpc/client 0.0.0-next.fc23c8d → 0.0.0-next.fc2dc8f

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 (31) hide show
  1. package/README.md +10 -5
  2. package/dist/adapters/fetch/index.d.mts +25 -12
  3. package/dist/adapters/fetch/index.d.ts +25 -12
  4. package/dist/adapters/fetch/index.mjs +25 -8
  5. package/dist/adapters/message-port/index.d.mts +38 -17
  6. package/dist/adapters/message-port/index.d.ts +38 -17
  7. package/dist/adapters/message-port/index.mjs +30 -14
  8. package/dist/adapters/standard/index.d.mts +6 -5
  9. package/dist/adapters/standard/index.d.ts +6 -5
  10. package/dist/adapters/standard/index.mjs +4 -2
  11. package/dist/adapters/websocket/index.d.mts +13 -13
  12. package/dist/adapters/websocket/index.d.ts +13 -13
  13. package/dist/adapters/websocket/index.mjs +13 -10
  14. package/dist/index.d.mts +88 -27
  15. package/dist/index.d.ts +88 -27
  16. package/dist/index.mjs +54 -7
  17. package/dist/plugins/index.d.mts +56 -9
  18. package/dist/plugins/index.d.ts +56 -9
  19. package/dist/plugins/index.mjs +121 -25
  20. package/dist/shared/{client.C0KbSWlC.d.ts → client.2jUAqzYU.d.ts} +1 -2
  21. package/dist/shared/{client.CQCGVpTM.mjs → client.6DHUcvyB.mjs} +63 -20
  22. package/dist/shared/{client.7UM0t5o-.d.ts → client.B3pNRBih.d.ts} +3 -3
  23. package/dist/shared/{client.BdD8cpjs.d.mts → client.BFAVy68H.d.mts} +3 -3
  24. package/dist/shared/client.BLtwTQUg.mjs +40 -0
  25. package/dist/shared/{client.BX0_8bnM.mjs → client.CM-FejDR.mjs} +37 -38
  26. package/dist/shared/{client.BMoG_EdN.d.mts → client.CpCa3si8.d.mts} +1 -2
  27. package/dist/shared/client.i2uoJbEp.d.mts +83 -0
  28. package/dist/shared/client.i2uoJbEp.d.ts +83 -0
  29. package/package.json +7 -7
  30. package/dist/shared/client.4TS_0JaO.d.mts +0 -29
  31. package/dist/shared/client.4TS_0JaO.d.ts +0 -29
@@ -1,8 +1,8 @@
1
1
  import { Value, Promisable } from '@orpc/shared';
2
- import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
2
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
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.C0KbSWlC.js';
5
- import { a as ClientContext } from '../shared/client.4TS_0JaO.js';
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';
6
6
 
7
7
  interface BatchLinkPluginGroup<T extends ClientContext> {
8
8
  condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
@@ -62,7 +62,7 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
62
62
  * The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
63
63
  * reducing the overhead of sending each one separately.
64
64
  *
65
- * @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
65
+ * @see {@link https://orpc.dev/docs/plugins/batch-requests Batch Requests Plugin Docs}
66
66
  */
67
67
  declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
68
68
  #private;
@@ -103,7 +103,7 @@ interface DedupeRequestsPluginOptions<T extends ClientContext> {
103
103
  /**
104
104
  * Prevents duplicate requests by deduplicating similar ones to reduce server load.
105
105
  *
106
- * @see {@link https://orpc.unnoq.com/docs/plugins/dedupe-requests Dedupe Requests Plugin}
106
+ * @see {@link https://orpc.dev/docs/plugins/dedupe-requests Dedupe Requests Plugin}
107
107
  */
108
108
  declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
109
109
  #private;
@@ -150,17 +150,64 @@ interface ClientRetryPluginOptions {
150
150
  /**
151
151
  * The Client Retry Plugin enables retrying client calls when errors occur.
152
152
  *
153
- * @see {@link https://orpc.unnoq.com/docs/plugins/client-retry Client Retry Plugin Docs}
153
+ * @see {@link https://orpc.dev/docs/plugins/client-retry Client Retry Plugin Docs}
154
154
  */
155
155
  declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
156
156
  private readonly defaultRetry;
157
157
  private readonly defaultRetryDelay;
158
158
  private readonly defaultShouldRetry;
159
159
  private readonly defaultOnRetry;
160
+ order: number;
160
161
  constructor(options?: ClientRetryPluginOptions);
161
162
  init(options: StandardLinkOptions<T>): void;
162
163
  }
163
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
+
164
211
  interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> {
165
212
  /**
166
213
  * The name of the header to check.
@@ -187,7 +234,7 @@ interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> {
187
234
  * It helps ensure that requests to your procedures originate from JavaScript code,
188
235
  * not from other sources like standard HTML forms or direct browser navigation.
189
236
  *
190
- * @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
237
+ * @see {@link https://orpc.dev/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
191
238
  */
192
239
  declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
193
240
  private readonly headerName;
@@ -198,5 +245,5 @@ declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements
198
245
  init(options: StandardLinkOptions<T>): void;
199
246
  }
200
247
 
201
- export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin };
202
- export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
248
+ export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, RetryAfterPlugin, SimpleCsrfProtectionLinkPlugin };
249
+ export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, RetryAfterPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
@@ -1,6 +1,7 @@
1
- import { isAsyncIteratorObject, defer, value, splitInHalf, toArray, stringifyJSON } from '@orpc/shared';
1
+ import { isAsyncIteratorObject, defer, value, splitInHalf, toArray, stringifyJSON, overlayProxy, AsyncIteratorClass } from '@orpc/shared';
2
2
  import { toBatchRequest, parseBatchResponse, toBatchAbortSignal } from '@orpc/standard-server/batch';
3
- import { replicateStandardLazyResponse, getEventMeta } from '@orpc/standard-server';
3
+ import { replicateStandardLazyResponse, getEventMeta, flattenHeader } from '@orpc/standard-server';
4
+ import { C as COMMON_ORPC_ERROR_DEFS } from '../shared/client.CM-FejDR.mjs';
4
5
 
5
6
  class BatchLinkPlugin {
6
7
  groups;
@@ -64,7 +65,7 @@ class BatchLinkPlugin {
64
65
  });
65
66
  });
66
67
  options.clientInterceptors.push((options2) => {
67
- if (this.exclude(options2) || options2.request.body instanceof Blob || options2.request.body instanceof FormData || isAsyncIteratorObject(options2.request.body)) {
68
+ if (this.exclude(options2) || options2.request.body instanceof Blob || options2.request.body instanceof FormData || isAsyncIteratorObject(options2.request.body) || options2.request.signal?.aborted) {
68
69
  return options2.next();
69
70
  }
70
71
  const group = this.groups.find((group2) => group2.condition(options2));
@@ -130,16 +131,27 @@ class BatchLinkPlugin {
130
131
  return;
131
132
  }
132
133
  const mode = value(this.mode, options);
133
- const lazyResponse = await options[0].next({
134
- request: { ...batchRequest, headers: { ...batchRequest.headers, "x-orpc-batch": mode } },
135
- signal: batchRequest.signal,
136
- context: group.context,
137
- input: group.input,
138
- path: toArray(group.path)
139
- });
140
- const parsed = parseBatchResponse({ ...lazyResponse, body: await lazyResponse.body() });
141
- for await (const item of parsed) {
142
- batchItems[item.index]?.[1]({ ...item, body: () => Promise.resolve(item.body) });
134
+ try {
135
+ const lazyResponse = await options[0].next({
136
+ request: { ...batchRequest, headers: { ...batchRequest.headers, "x-orpc-batch": mode } },
137
+ signal: batchRequest.signal,
138
+ context: group.context,
139
+ input: group.input,
140
+ path: toArray(group.path)
141
+ });
142
+ const parsed = parseBatchResponse({ ...lazyResponse, body: await lazyResponse.body() });
143
+ for await (const item of parsed) {
144
+ batchItems[item.index]?.[1]({ ...item, body: () => Promise.resolve(item.body) });
145
+ }
146
+ } catch (err) {
147
+ if (batchRequest.signal?.aborted && batchRequest.signal.reason === err) {
148
+ for (const [{ signal }, , reject] of batchItems) {
149
+ if (signal?.aborted) {
150
+ reject(signal.reason);
151
+ }
152
+ }
153
+ }
154
+ throw err;
143
155
  }
144
156
  throw new Error("Something went wrong make batch response not contains enough responses. This can be a bug please report it.");
145
157
  } catch (error) {
@@ -252,6 +264,7 @@ class ClientRetryPlugin {
252
264
  defaultRetryDelay;
253
265
  defaultShouldRetry;
254
266
  defaultOnRetry;
267
+ order = 18e5;
255
268
  constructor(options = {}) {
256
269
  this.defaultRetry = options.default?.retry ?? 0;
257
270
  this.defaultRetryDelay = options.default?.retryDelay ?? ((o) => o.lastEventRetry ?? 2e3);
@@ -306,7 +319,7 @@ class ClientRetryPlugin {
306
319
  return await interceptorOptions.next(updatedInterceptorOptions);
307
320
  } catch (error) {
308
321
  currentError = { error };
309
- if (updatedInterceptorOptions.signal?.aborted === true) {
322
+ if (updatedInterceptorOptions.signal?.aborted) {
310
323
  throw error;
311
324
  }
312
325
  } finally {
@@ -319,19 +332,17 @@ class ClientRetryPlugin {
319
332
  if (!isAsyncIteratorObject(output)) {
320
333
  return output;
321
334
  }
322
- return async function* () {
323
- let current = output;
324
- try {
335
+ let current = output;
336
+ let isIteratorAborted = false;
337
+ return overlayProxy(() => current, new AsyncIteratorClass(
338
+ async () => {
325
339
  while (true) {
326
340
  try {
327
341
  const item = await current.next();
328
342
  const meta = getEventMeta(item.value);
329
343
  lastEventId = meta?.id ?? lastEventId;
330
344
  lastEventRetry = meta?.retry ?? lastEventRetry;
331
- if (item.done) {
332
- return item.value;
333
- }
334
- yield item.value;
345
+ return item;
335
346
  } catch (error) {
336
347
  const meta = getEventMeta(error);
337
348
  lastEventId = meta?.id ?? lastEventId;
@@ -343,12 +354,97 @@ class ClientRetryPlugin {
343
354
  );
344
355
  }
345
356
  current = maybeEventIterator;
357
+ if (isIteratorAborted) {
358
+ await current.return?.();
359
+ throw error;
360
+ }
346
361
  }
347
362
  }
348
- } finally {
349
- await current.return?.();
363
+ },
364
+ async (reason) => {
365
+ isIteratorAborted = true;
366
+ if (reason !== "next") {
367
+ await current.return?.();
368
+ }
350
369
  }
351
- }();
370
+ ));
371
+ });
372
+ }
373
+ }
374
+
375
+ class RetryAfterPlugin {
376
+ condition;
377
+ maxAttempts;
378
+ timeout;
379
+ order = 19e5;
380
+ constructor(options = {}) {
381
+ this.condition = options.condition ?? ((response) => response.status === COMMON_ORPC_ERROR_DEFS.TOO_MANY_REQUESTS.status || response.status === COMMON_ORPC_ERROR_DEFS.SERVICE_UNAVAILABLE.status);
382
+ this.maxAttempts = options.maxAttempts ?? 3;
383
+ this.timeout = options.timeout ?? 5 * 60 * 1e3;
384
+ }
385
+ init(options) {
386
+ options.clientInterceptors ??= [];
387
+ options.clientInterceptors.push(async (interceptorOptions) => {
388
+ const startTime = Date.now();
389
+ let attemptCount = 0;
390
+ while (true) {
391
+ attemptCount++;
392
+ const response = await interceptorOptions.next();
393
+ if (!value(this.condition, response, interceptorOptions)) {
394
+ return response;
395
+ }
396
+ const retryAfterHeader = flattenHeader(response.headers["retry-after"]);
397
+ const retryAfterMs = this.parseRetryAfterHeader(retryAfterHeader);
398
+ if (retryAfterMs === void 0) {
399
+ return response;
400
+ }
401
+ if (attemptCount >= value(this.maxAttempts, response, interceptorOptions)) {
402
+ return response;
403
+ }
404
+ const timeoutMs = value(this.timeout, response, interceptorOptions);
405
+ const elapsedTime = Date.now() - startTime;
406
+ if (elapsedTime + retryAfterMs > timeoutMs) {
407
+ return response;
408
+ }
409
+ await this.delayExecution(retryAfterMs, interceptorOptions.signal);
410
+ if (interceptorOptions.signal?.aborted) {
411
+ return response;
412
+ }
413
+ }
414
+ });
415
+ }
416
+ parseRetryAfterHeader(value2) {
417
+ value2 = value2?.trim();
418
+ if (!value2) {
419
+ return void 0;
420
+ }
421
+ const seconds = Number(value2);
422
+ if (Number.isFinite(seconds)) {
423
+ return Math.max(0, seconds * 1e3);
424
+ }
425
+ const retryDate = Date.parse(value2);
426
+ if (!Number.isNaN(retryDate)) {
427
+ return Math.max(0, retryDate - Date.now());
428
+ }
429
+ return void 0;
430
+ }
431
+ delayExecution(ms, signal) {
432
+ return new Promise((resolve) => {
433
+ if (signal?.aborted) {
434
+ resolve();
435
+ return;
436
+ }
437
+ let timeout;
438
+ const onAbort = () => {
439
+ clearTimeout(timeout);
440
+ timeout = void 0;
441
+ resolve();
442
+ };
443
+ signal?.addEventListener("abort", onAbort, { once: true });
444
+ timeout = setTimeout(() => {
445
+ signal?.removeEventListener("abort", onAbort);
446
+ resolve();
447
+ }, ms);
352
448
  });
353
449
  }
354
450
  }
@@ -386,4 +482,4 @@ class SimpleCsrfProtectionLinkPlugin {
386
482
  }
387
483
  }
388
484
 
389
- export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, SimpleCsrfProtectionLinkPlugin };
485
+ export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, RetryAfterPlugin, SimpleCsrfProtectionLinkPlugin };
@@ -1,6 +1,6 @@
1
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.4TS_0JaO.js';
3
+ import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.i2uoJbEp.js';
4
4
 
5
5
  interface StandardLinkPlugin<T extends ClientContext> {
6
6
  order?: number;
@@ -33,7 +33,6 @@ interface StandardLinkOptions<T extends ClientContext> {
33
33
  plugins?: StandardLinkPlugin<T>[];
34
34
  }
35
35
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
36
- #private;
37
36
  readonly codec: StandardLinkCodec<T>;
38
37
  readonly sender: StandardLinkClient<T>;
39
38
  private readonly interceptors;
@@ -1,6 +1,8 @@
1
- import { toArray, intercept, isObject, value, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
1
+ import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared';
2
2
  import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
3
- import { C as COMMON_ORPC_ERROR_DEFS, b as isORPCErrorStatus, c as isORPCErrorJson, d as createORPCErrorFromJson, O as ORPCError, m as mapEventIterator, t as toORPCError } from './client.BX0_8bnM.mjs';
3
+ import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, t as toORPCError } from './client.CM-FejDR.mjs';
4
+ import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
5
+ import { m as mapEventIterator } from './client.BLtwTQUg.mjs';
4
6
 
5
7
  class CompositeStandardLinkPlugin {
6
8
  plugins;
@@ -26,20 +28,52 @@ class StandardLink {
26
28
  interceptors;
27
29
  clientInterceptors;
28
30
  call(path, input, options) {
29
- return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
30
- const output = await this.#call(path2, input2, options2);
31
- return output;
32
- });
33
- }
34
- async #call(path, input, options) {
35
- const request = await this.codec.encode(path, input, options);
36
- const response = await intercept(
37
- this.clientInterceptors,
38
- { ...options, input, path, request },
39
- ({ input: input2, path: path2, request: request2, ...options2 }) => this.sender.call(request2, options2, path2, input2)
31
+ return runWithSpan(
32
+ { name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal },
33
+ (span) => {
34
+ span?.setAttribute("rpc.system", ORPC_NAME);
35
+ span?.setAttribute("rpc.method", path.join("."));
36
+ if (isAsyncIteratorObject(input)) {
37
+ input = asyncIteratorWithSpan(
38
+ { name: "consume_event_iterator_input", signal: options.signal },
39
+ input
40
+ );
41
+ }
42
+ return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
43
+ const otelConfig = getGlobalOtelConfig();
44
+ let otelContext;
45
+ const currentSpan = otelConfig?.trace.getActiveSpan() ?? span;
46
+ if (currentSpan && otelConfig) {
47
+ otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan);
48
+ }
49
+ const request = await runWithSpan(
50
+ { name: "encode_request", context: otelContext },
51
+ () => this.codec.encode(path2, input2, options2)
52
+ );
53
+ const response = await intercept(
54
+ this.clientInterceptors,
55
+ { ...options2, input: input2, path: path2, request },
56
+ ({ input: input3, path: path3, request: request2, ...options3 }) => {
57
+ return runWithSpan(
58
+ { name: "send_request", signal: options3.signal, context: otelContext },
59
+ () => this.sender.call(request2, options3, path3, input3)
60
+ );
61
+ }
62
+ );
63
+ const output = await runWithSpan(
64
+ { name: "decode_response", context: otelContext },
65
+ () => this.codec.decode(response, options2, path2, input2)
66
+ );
67
+ if (isAsyncIteratorObject(output)) {
68
+ return asyncIteratorWithSpan(
69
+ { name: "consume_event_iterator_output", signal: options2.signal },
70
+ output
71
+ );
72
+ }
73
+ return output;
74
+ });
75
+ }
40
76
  );
41
- const output = await this.codec.decode(response, options, path, input);
42
- return output;
43
77
  }
44
78
  }
45
79
 
@@ -192,6 +226,12 @@ class StandardRPCJsonSerializer {
192
226
  function toHttpPath(path) {
193
227
  return `/${path.map(encodeURIComponent).join("/")}`;
194
228
  }
229
+ function toStandardHeaders(headers) {
230
+ if (typeof headers.forEach === "function") {
231
+ return toStandardHeaders$1(headers);
232
+ }
233
+ return headers;
234
+ }
195
235
  function getMalformedResponseErrorCode(status) {
196
236
  return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
197
237
  }
@@ -211,14 +251,14 @@ class StandardRPCLinkCodec {
211
251
  expectedMethod;
212
252
  headers;
213
253
  async encode(path, input, options) {
254
+ let headers = toStandardHeaders(await value(this.headers, options, path, input));
255
+ if (options.lastEventId !== void 0) {
256
+ headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
257
+ }
214
258
  const expectedMethod = await value(this.expectedMethod, options, path, input);
215
- let headers = await value(this.headers, options, path, input);
216
259
  const baseUrl = await value(this.baseUrl, options, path, input);
217
260
  const url = new URL(baseUrl);
218
261
  url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
219
- if (options.lastEventId !== void 0) {
220
- headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
221
- }
222
262
  const serialized = this.serializer.serialize(input);
223
263
  if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
224
264
  const maxUrlLength = await value(this.maxUrlLength, options, path, input);
@@ -330,6 +370,9 @@ class StandardRPCSerializer {
330
370
  return this.#deserialize(data);
331
371
  }
332
372
  #deserialize(data) {
373
+ if (data === void 0) {
374
+ return void 0;
375
+ }
333
376
  if (!(data instanceof FormData)) {
334
377
  return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
335
378
  }
@@ -352,4 +395,4 @@ class StandardRPCLink extends StandardLink {
352
395
  }
353
396
  }
354
397
 
355
- export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, getMalformedResponseErrorCode as g, toHttpPath as t };
398
+ export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, toStandardHeaders as f, getMalformedResponseErrorCode as g, toHttpPath as t };
@@ -1,5 +1,5 @@
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';
1
+ import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.i2uoJbEp.js';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.2jUAqzYU.js';
3
3
  import { Segment, Value, Promisable } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
67
67
  /**
68
68
  * Inject headers to the request.
69
69
  */
70
- headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
70
+ headers?: Value<Promisable<StandardHeaders | Headers>, [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;
@@ -1,5 +1,5 @@
1
- import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.4TS_0JaO.mjs';
2
- import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.BMoG_EdN.mjs';
1
+ import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.i2uoJbEp.mjs';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.CpCa3si8.mjs';
3
3
  import { Segment, Value, Promisable } from '@orpc/shared';
4
4
  import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
5
 
@@ -67,7 +67,7 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
67
67
  /**
68
68
  * Inject headers to the request.
69
69
  */
70
- headers?: Value<Promisable<StandardHeaders>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
70
+ headers?: Value<Promisable<StandardHeaders | Headers>, [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;
@@ -0,0 +1,40 @@
1
+ import { AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
2
+ import { getEventMeta, withEventMeta } from '@orpc/standard-server';
3
+
4
+ function mapEventIterator(iterator, maps) {
5
+ const mapError = async (error) => {
6
+ let mappedError = await maps.error(error);
7
+ if (mappedError !== error) {
8
+ const meta = getEventMeta(error);
9
+ if (meta && isTypescriptObject(mappedError)) {
10
+ mappedError = withEventMeta(mappedError, meta);
11
+ }
12
+ }
13
+ return mappedError;
14
+ };
15
+ return new AsyncIteratorClass(async () => {
16
+ const { done, value } = await (async () => {
17
+ try {
18
+ return await iterator.next();
19
+ } catch (error) {
20
+ throw await mapError(error);
21
+ }
22
+ })();
23
+ let mappedValue = await maps.value(value, done);
24
+ if (mappedValue !== value) {
25
+ const meta = getEventMeta(value);
26
+ if (meta && isTypescriptObject(mappedValue)) {
27
+ mappedValue = withEventMeta(mappedValue, meta);
28
+ }
29
+ }
30
+ return { done, value: mappedValue };
31
+ }, async () => {
32
+ try {
33
+ await iterator.return?.();
34
+ } catch (error) {
35
+ throw await mapError(error);
36
+ }
37
+ });
38
+ }
39
+
40
+ export { mapEventIterator as m };
@@ -1,5 +1,7 @@
1
- import { isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
2
- import { getEventMeta, withEventMeta } from '@orpc/standard-server';
1
+ import { resolveMaybeOptionalOptions, getConstructor, isObject } from '@orpc/shared';
2
+
3
+ const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
4
+ const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.fc2dc8f";
3
5
 
4
6
  const COMMON_ORPC_ERROR_DEFS = {
5
7
  BAD_REQUEST: {
@@ -85,21 +87,25 @@ function fallbackORPCErrorStatus(code, status) {
85
87
  function fallbackORPCErrorMessage(code, message) {
86
88
  return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
87
89
  }
90
+ const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
91
+ void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
92
+ const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
88
93
  class ORPCError extends Error {
89
94
  defined;
90
95
  code;
91
96
  status;
92
97
  data;
93
- constructor(code, ...[options]) {
94
- if (options?.status && !isORPCErrorStatus(options.status)) {
98
+ constructor(code, ...rest) {
99
+ const options = resolveMaybeOptionalOptions(rest);
100
+ if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
95
101
  throw new Error("[ORPCError] Invalid error status code.");
96
102
  }
97
- const message = fallbackORPCErrorMessage(code, options?.message);
103
+ const message = fallbackORPCErrorMessage(code, options.message);
98
104
  super(message, options);
99
105
  this.code = code;
100
- this.status = fallbackORPCErrorStatus(code, options?.status);
101
- this.defined = options?.defined ?? false;
102
- this.data = options?.data;
106
+ this.status = fallbackORPCErrorStatus(code, options.status);
107
+ this.defined = options.defined ?? false;
108
+ this.data = options.data;
103
109
  }
104
110
  toJSON() {
105
111
  return {
@@ -110,7 +116,29 @@ class ORPCError extends Error {
110
116
  data: this.data
111
117
  };
112
118
  }
119
+ /**
120
+ * Workaround for Next.js where different contexts use separate
121
+ * dependency graphs, causing multiple ORPCError constructors existing and breaking
122
+ * `instanceof` checks across contexts.
123
+ *
124
+ * This is particularly problematic with "Optimized SSR", where orpc-client
125
+ * executes in one context but is invoked from another. When an error is thrown
126
+ * in the execution context, `instanceof ORPCError` checks fail in the
127
+ * invocation context due to separate class constructors.
128
+ *
129
+ * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
130
+ */
131
+ static [Symbol.hasInstance](instance) {
132
+ if (globalORPCErrorConstructors.has(this)) {
133
+ const constructor = getConstructor(instance);
134
+ if (constructor && globalORPCErrorConstructors.has(constructor)) {
135
+ return true;
136
+ }
137
+ }
138
+ return super[Symbol.hasInstance](instance);
139
+ }
113
140
  }
141
+ globalORPCErrorConstructors.add(ORPCError);
114
142
  function isDefinedError(error) {
115
143
  return error instanceof ORPCError && error.defined;
116
144
  }
@@ -140,33 +168,4 @@ function createORPCErrorFromJson(json, options = {}) {
140
168
  });
141
169
  }
142
170
 
143
- function mapEventIterator(iterator, maps) {
144
- return new AsyncIteratorClass(async () => {
145
- try {
146
- const { done, value } = await iterator.next();
147
- let mappedValue = await maps.value(value, done);
148
- if (mappedValue !== value) {
149
- const meta = getEventMeta(value);
150
- if (meta && isTypescriptObject(mappedValue)) {
151
- mappedValue = withEventMeta(mappedValue, meta);
152
- }
153
- }
154
- return { done, value: mappedValue };
155
- } catch (error) {
156
- let mappedError = await maps.error(error);
157
- if (mappedError !== error) {
158
- const meta = getEventMeta(error);
159
- if (meta && isTypescriptObject(mappedError)) {
160
- mappedError = withEventMeta(mappedError, meta);
161
- }
162
- }
163
- throw mappedError;
164
- }
165
- }, async (reason) => {
166
- if (reason !== "next") {
167
- await iterator.return?.();
168
- }
169
- });
170
- }
171
-
172
- export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, isORPCErrorJson as c, createORPCErrorFromJson as d, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
171
+ export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, toORPCError as t };
@@ -1,6 +1,6 @@
1
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.4TS_0JaO.mjs';
3
+ import { b as ClientContext, c as ClientOptions, C as ClientLink } from './client.i2uoJbEp.mjs';
4
4
 
5
5
  interface StandardLinkPlugin<T extends ClientContext> {
6
6
  order?: number;
@@ -33,7 +33,6 @@ interface StandardLinkOptions<T extends ClientContext> {
33
33
  plugins?: StandardLinkPlugin<T>[];
34
34
  }
35
35
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
36
- #private;
37
36
  readonly codec: StandardLinkCodec<T>;
38
37
  readonly sender: StandardLinkClient<T>;
39
38
  private readonly interceptors;