@orpc/client 2.0.0-beta.44 → 2.0.0-beta.46

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 (29) hide show
  1. package/README.md +100 -62
  2. package/dist/adapters/fetch/index.d.mts +3 -3
  3. package/dist/adapters/fetch/index.d.ts +3 -3
  4. package/dist/adapters/fetch/index.mjs +3 -3
  5. package/dist/adapters/message-port/index.d.mts +2 -2
  6. package/dist/adapters/message-port/index.d.ts +2 -2
  7. package/dist/adapters/message-port/index.mjs +3 -3
  8. package/dist/adapters/standard/index.d.mts +8 -8
  9. package/dist/adapters/standard/index.d.ts +8 -8
  10. package/dist/adapters/standard/index.mjs +3 -3
  11. package/dist/adapters/websocket/index.d.mts +9 -9
  12. package/dist/adapters/websocket/index.d.ts +9 -9
  13. package/dist/adapters/websocket/index.mjs +3 -3
  14. package/dist/index.d.mts +10 -11
  15. package/dist/index.d.ts +10 -11
  16. package/dist/index.mjs +4 -4
  17. package/dist/plugins/index.d.mts +51 -38
  18. package/dist/plugins/index.d.ts +51 -38
  19. package/dist/plugins/index.mjs +17 -10
  20. package/dist/shared/{client.DZHZRyR6.d.mts → client.BoHJeq15.d.mts} +30 -12
  21. package/dist/shared/{client.DZHZRyR6.d.ts → client.BoHJeq15.d.ts} +30 -12
  22. package/dist/shared/{client.B7P_ugvl.mjs → client.CKQeJJ2U.mjs} +9 -4
  23. package/dist/shared/{client.BPa_Mmuh.d.mts → client.DqIWeNhQ.d.mts} +7 -8
  24. package/dist/shared/{client.BPa_Mmuh.d.ts → client.DqIWeNhQ.d.ts} +7 -8
  25. package/dist/shared/{client.CHH2CNMj.d.ts → client.JBJwBhR8.d.ts} +5 -11
  26. package/dist/shared/{client.CrHurHrq.mjs → client.LF04eOvL.mjs} +10 -4
  27. package/dist/shared/{client.BLfXUpyF.mjs → client._wG5INmC.mjs} +16 -17
  28. package/dist/shared/{client.BzAY7ZC2.d.mts → client.euYjjcFz.d.mts} +5 -11
  29. package/package.json +6 -6
@@ -1,6 +1,6 @@
1
1
  import { Promisable, OrderablePlugin, Interceptor } from '@orpc/shared';
2
2
  import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
3
- import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.DZHZRyR6.js';
3
+ import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.BoHJeq15.js';
4
4
 
5
5
  type StandardLinkCodecDecodedResponse = {
6
6
  kind: 'output';
@@ -37,12 +37,6 @@ interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin {
37
37
  */
38
38
  init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
39
39
  }
40
- declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
41
- name: string;
42
- protected readonly plugins: StandardLinkPlugin<T>[];
43
- constructor(plugins?: StandardLinkPlugin<T>[]);
44
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
45
- }
46
40
 
47
41
  /**
48
42
  * Handles the transport layer for sending requests and receiving responses.
@@ -72,13 +66,13 @@ interface StandardLinkOptions<T extends ClientContext> {
72
66
  * Interceptors that execute around the entire call, including transport and codec.
73
67
  * Useful for error handling, logging, metrics, ...
74
68
  */
75
- interceptors?: StandardLinkInterceptor<T>[];
69
+ interceptors?: StandardLinkInterceptor<T>[] | undefined;
76
70
  /**
77
71
  * Interceptors that execute around the transport layer, after encoding and before decoding.
78
72
  * Useful for modifying the request or response, adding transport-level logging, ...
79
73
  */
80
- transportInterceptors?: StandardLinkTransportInterceptor<T>[];
81
- plugins?: StandardLinkPlugin<T>[];
74
+ transportInterceptors?: StandardLinkTransportInterceptor<T>[] | undefined;
75
+ plugins?: StandardLinkPlugin<T>[] | undefined;
82
76
  }
83
77
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
84
78
  private readonly codec;
@@ -92,5 +86,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
92
86
  call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
93
87
  }
94
88
 
95
- export { CompositeStandardLinkPlugin as C, StandardLink as a };
89
+ export { StandardLink as a };
96
90
  export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i };
@@ -85,14 +85,20 @@ class ORPCError extends Error {
85
85
  return false;
86
86
  }
87
87
  }
88
- class MalformedResponseError extends Error {
89
- name = "MalformedResponseError";
88
+ class ResponseError extends Error {
89
+ name = "ResponseError";
90
90
  response;
91
91
  constructor(options) {
92
- super(options.message ?? inferMalformedResponseMessage(options.response), options);
92
+ super(options.message ?? `Received a ${options.response.status} response.`, options);
93
93
  this.response = options.response;
94
94
  }
95
95
  }
96
+ class MalformedResponseError extends ResponseError {
97
+ name = "MalformedResponseError";
98
+ constructor(options) {
99
+ super({ ...options, message: options.message ?? inferMalformedResponseMessage(options.response) });
100
+ }
101
+ }
96
102
  const INFERRED_MESSAGE_MAX_LENGTH = 256;
97
103
  function inferMalformedResponseMessage(response) {
98
104
  const candidate = isPlainObject(response.body) ? response.body.message : response.body;
@@ -106,4 +112,4 @@ function codeToMessage(code) {
106
112
  return code.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
107
113
  }
108
114
 
109
- export { COMMON_ERROR_STATUS_MAP as C, MalformedResponseError as M, ORPCError as O };
115
+ export { COMMON_ERROR_STATUS_MAP as C, MalformedResponseError as M, ORPCError as O, ResponseError as R };
@@ -1,6 +1,6 @@
1
1
  import { isPlainObject, wrapAsyncIterator, isTypescriptObject, NullProtoObj, parseBigIntString, DEFAULT_MAX_BIGINT_DIGITS, copyOnWrite, isAsyncIteratorObject, stringifyJSON } from '@orpc/shared';
2
2
  import { getEventMeta, withEventMeta, ErrorEvent } from '@standard-server/core';
3
- import { O as ORPCError } from './client.CrHurHrq.mjs';
3
+ import { O as ORPCError } from './client.LF04eOvL.mjs';
4
4
 
5
5
  function isDefinedError(error) {
6
6
  return error instanceof ORPCError && error.defined;
@@ -230,7 +230,7 @@ class RPCJsonSerializer {
230
230
  this.inlineBuiltInHandlers = inlineBuiltInHandlers;
231
231
  this.handlerEntries = handlerEntries;
232
232
  }
233
- serialize(data) {
233
+ serializeJson(data) {
234
234
  let meta = [];
235
235
  const maps = [];
236
236
  const blobs = [];
@@ -345,7 +345,7 @@ class RPCJsonSerializer {
345
345
  }
346
346
  return data;
347
347
  }
348
- deserialize(serialized) {
348
+ deserializeJson(serialized) {
349
349
  const ref = { json: serialized.json };
350
350
  if (serialized.blobs?.length) {
351
351
  for (let i = 0; i < serialized.maps.length; i++) {
@@ -422,11 +422,10 @@ class RPCJsonSerializer {
422
422
  }
423
423
  }
424
424
 
425
- class RPCSerializer {
426
- jsonSerializer;
425
+ class RPCSerializer extends RPCJsonSerializer {
427
426
  defaultSerializeOptions;
428
427
  constructor(options = {}) {
429
- this.jsonSerializer = new RPCJsonSerializer(options);
428
+ super(options);
430
429
  this.defaultSerializeOptions = options.serialize;
431
430
  }
432
431
  serialize(data, options = {}) {
@@ -439,19 +438,19 @@ class RPCSerializer {
439
438
  if (result.value === void 0) {
440
439
  return result;
441
440
  }
442
- return { done: result.done, value: this.serializeValue(result.value, false) };
441
+ return { done: result.done, value: this.serializePayload(result.value, false) };
443
442
  },
444
443
  mapError: (e) => new ErrorEvent(
445
- this.serializeValue(toORPCError(e).toJSON(), false),
444
+ this.serializePayload(toORPCError(e).toJSON(), false),
446
445
  { cause: e }
447
446
  )
448
447
  });
449
448
  }
450
449
  const useFormDataForBlobs = options.useFormDataForBlobFields ?? this.defaultSerializeOptions?.useFormDataForBlobFields ?? true;
451
- return this.serializeValue(data, useFormDataForBlobs);
450
+ return this.serializePayload(data, useFormDataForBlobs);
452
451
  }
453
- serializeValue(data, useFormDataForBlobs) {
454
- const { json, meta, maps, blobs } = this.jsonSerializer.serialize(data);
452
+ serializePayload(data, useFormDataForBlobs) {
453
+ const { json, meta, maps, blobs } = this.serializeJson(data);
455
454
  if (!useFormDataForBlobs || !blobs?.length) {
456
455
  return { json, meta };
457
456
  }
@@ -472,13 +471,13 @@ class RPCSerializer {
472
471
  if (result.value === void 0) {
473
472
  return result;
474
473
  }
475
- return { done: result.done, value: this.deserializeValue(result.value) };
474
+ return { done: result.done, value: this.deserializePayload(result.value) };
476
475
  },
477
476
  mapError: (e) => {
478
477
  if (!(e instanceof ErrorEvent)) {
479
478
  return e;
480
479
  }
481
- const deserialized = this.deserializeValue(e.data);
480
+ const deserialized = this.deserializePayload(e.data);
482
481
  if (isORPCErrorJson(deserialized)) {
483
482
  return createORPCErrorFromJson(deserialized, { cause: e });
484
483
  }
@@ -486,11 +485,11 @@ class RPCSerializer {
486
485
  }
487
486
  });
488
487
  }
489
- return this.deserializeValue(data);
488
+ return this.deserializePayload(data);
490
489
  }
491
- deserializeValue(data) {
490
+ deserializePayload(data) {
492
491
  if (!(data instanceof FormData)) {
493
- return this.jsonSerializer.deserialize(data);
492
+ return this.deserializeJson(data);
494
493
  }
495
494
  const serialized = JSON.parse(data.get("data"));
496
495
  const blobs = [];
@@ -499,7 +498,7 @@ class RPCSerializer {
499
498
  blobs[Number(key)] = value;
500
499
  }
501
500
  }
502
- return this.jsonSerializer.deserialize({ ...serialized, blobs });
501
+ return this.deserializeJson({ ...serialized, blobs });
503
502
  }
504
503
  }
505
504
 
@@ -1,6 +1,6 @@
1
1
  import { Promisable, OrderablePlugin, Interceptor } from '@orpc/shared';
2
2
  import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
3
- import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.DZHZRyR6.mjs';
3
+ import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.BoHJeq15.mjs';
4
4
 
5
5
  type StandardLinkCodecDecodedResponse = {
6
6
  kind: 'output';
@@ -37,12 +37,6 @@ interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin {
37
37
  */
38
38
  init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
39
39
  }
40
- declare class CompositeStandardLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
41
- name: string;
42
- protected readonly plugins: StandardLinkPlugin<T>[];
43
- constructor(plugins?: StandardLinkPlugin<T>[]);
44
- init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
45
- }
46
40
 
47
41
  /**
48
42
  * Handles the transport layer for sending requests and receiving responses.
@@ -72,13 +66,13 @@ interface StandardLinkOptions<T extends ClientContext> {
72
66
  * Interceptors that execute around the entire call, including transport and codec.
73
67
  * Useful for error handling, logging, metrics, ...
74
68
  */
75
- interceptors?: StandardLinkInterceptor<T>[];
69
+ interceptors?: StandardLinkInterceptor<T>[] | undefined;
76
70
  /**
77
71
  * Interceptors that execute around the transport layer, after encoding and before decoding.
78
72
  * Useful for modifying the request or response, adding transport-level logging, ...
79
73
  */
80
- transportInterceptors?: StandardLinkTransportInterceptor<T>[];
81
- plugins?: StandardLinkPlugin<T>[];
74
+ transportInterceptors?: StandardLinkTransportInterceptor<T>[] | undefined;
75
+ plugins?: StandardLinkPlugin<T>[] | undefined;
82
76
  }
83
77
  declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
84
78
  private readonly codec;
@@ -92,5 +86,5 @@ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
92
86
  call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
93
87
  }
94
88
 
95
- export { CompositeStandardLinkPlugin as C, StandardLink as a };
89
+ export { StandardLink as a };
96
90
  export type { StandardLinkTransport as S, StandardLinkOptions as b, StandardLinkPlugin as c, StandardLinkTransportInterceptorOptions as d, StandardLinkInterceptorOptions as e, StandardLinkCodec as f, StandardLinkCodecDecodedResponse as g, StandardLinkInterceptor as h, StandardLinkTransportInterceptor as i };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.44",
4
+ "version": "2.0.0-beta.46",
5
5
  "description": "Consume oRPC and OpenAPI APIs with end-to-end type safety over HTTP, WebSocket, or message ports",
6
6
  "license": "MIT",
7
7
  "funding": [
@@ -63,15 +63,15 @@
63
63
  "dist"
64
64
  ],
65
65
  "dependencies": {
66
- "@orpc/shared": "2.0.0-beta.44",
67
- "@standard-server/core": "~0.10.3",
68
- "@standard-server/fetch": "~0.10.3",
69
- "@standard-server/peer": "~0.10.3"
66
+ "@orpc/shared": "2.0.0-beta.46",
67
+ "@standard-server/core": "~0.11.0",
68
+ "@standard-server/fetch": "~0.11.0",
69
+ "@standard-server/peer": "~0.11.0"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@types/ws": "^8.18.2",
73
73
  "ws": "^8.22.0",
74
- "zod": "^4.6.5"
74
+ "zod": "^4.6.7"
75
75
  },
76
76
  "scripts": {
77
77
  "type:check": "tsc -b"