@orpc/client 2.0.0-beta.4 → 2.0.0-beta.40

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 (30) hide show
  1. package/README.md +97 -94
  2. package/dist/adapters/fetch/index.d.mts +16 -33
  3. package/dist/adapters/fetch/index.d.ts +16 -33
  4. package/dist/adapters/fetch/index.mjs +32 -30
  5. package/dist/adapters/message-port/index.d.mts +13 -8
  6. package/dist/adapters/message-port/index.d.ts +13 -8
  7. package/dist/adapters/message-port/index.mjs +22 -17
  8. package/dist/adapters/standard/index.d.mts +9 -10
  9. package/dist/adapters/standard/index.d.ts +9 -10
  10. package/dist/adapters/standard/index.mjs +5 -5
  11. package/dist/adapters/websocket/index.d.mts +21 -16
  12. package/dist/adapters/websocket/index.d.ts +21 -16
  13. package/dist/adapters/websocket/index.mjs +14 -14
  14. package/dist/index.d.mts +62 -61
  15. package/dist/index.d.ts +62 -61
  16. package/dist/index.mjs +47 -54
  17. package/dist/plugins/index.d.mts +134 -13
  18. package/dist/plugins/index.d.ts +134 -13
  19. package/dist/plugins/index.mjs +298 -27
  20. package/dist/shared/{client.Cby_-GGh.d.mts → client.BWkR2vPU.d.mts} +2 -2
  21. package/dist/shared/client.BYHnU_Z3.mjs +469 -0
  22. package/dist/shared/{client.CPF3hX6O.d.ts → client.BnpRXnLi.d.ts} +2 -2
  23. package/dist/shared/{client.8ug8I-zu.d.mts → client.BoXZCzuS.d.mts} +56 -16
  24. package/dist/shared/{client.8ug8I-zu.d.ts → client.BoXZCzuS.d.ts} +56 -16
  25. package/dist/shared/{client.Dnfj8jnT.mjs → client.Dtv1JPkU.mjs} +19 -15
  26. package/dist/shared/{client.DXhchJ84.mjs → client.VXsLhJtT.mjs} +25 -30
  27. package/dist/shared/{client.BdItY5DT.d.mts → client.n8K9dFhY.d.mts} +25 -4
  28. package/dist/shared/{client.BdItY5DT.d.ts → client.n8K9dFhY.d.ts} +25 -4
  29. package/package.json +20 -8
  30. package/dist/shared/client.DMXKFDyV.mjs +0 -343
@@ -1,4 +1,5 @@
1
1
  import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared';
2
+ import { StandardResponse } from '@standard-server/core';
2
3
 
3
4
  interface ClientContext {
4
5
  [key: PropertyKey]: any;
@@ -21,6 +22,11 @@ type NestedClient<TClientContext extends ClientContext> = Client<TClientContext,
21
22
  [k: string]: NestedClient<TClientContext>;
22
23
  };
23
24
  type AnyNestedClient = NestedClient<any>;
25
+ /**
26
+ * Infers the **client context type** required by a client.
27
+ *
28
+ * @see {@link https://orpc.dev/docs/client/client-side#infer-client-context | Client-Side Clients - Infer Client Context}
29
+ */
24
30
  type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never;
25
31
  interface ClientLink<TClientContext extends ClientContext> {
26
32
  call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
@@ -29,6 +35,8 @@ interface ClientLink<TClientContext extends ClientContext> {
29
35
  * Recursively infers the **input types** from a client.
30
36
  *
31
37
  * Produces a nested map where each endpoint's input type is preserved.
38
+ *
39
+ * @see {@link https://orpc.dev/docs/client/client-side#infer-client-inputs | Client-Side Clients - Infer Client Inputs}
32
40
  */
33
41
  type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : {
34
42
  [K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never;
@@ -38,6 +46,8 @@ type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer
38
46
  *
39
47
  * If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
40
48
  * Produces a nested map of body input types.
49
+ *
50
+ * @see {@link https://orpc.dev/docs/client/client-side#infer-client-body-inputs | Client-Side Clients - Infer Client Body Inputs}
41
51
  */
42
52
  type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends {
43
53
  body: infer UBody;
@@ -48,6 +58,8 @@ type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, in
48
58
  * Recursively infers the **output types** from a client.
49
59
  *
50
60
  * Produces a nested map where each endpoint's output type is preserved.
61
+ *
62
+ * @see {@link https://orpc.dev/docs/client/client-side#infer-client-outputs | Client-Side Clients - Infer Client Outputs}
51
63
  */
52
64
  type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : {
53
65
  [K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never;
@@ -57,6 +69,8 @@ type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any,
57
69
  *
58
70
  * If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
59
71
  * Produces a nested map of body output types.
72
+ *
73
+ * @see {@link https://orpc.dev/docs/client/client-side#infer-client-body-outputs | Client-Side Clients - Infer Client Body Outputs}
60
74
  */
61
75
  type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends {
62
76
  body: infer UBody;
@@ -64,22 +78,33 @@ type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, a
64
78
  [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never;
65
79
  };
66
80
  /**
67
- * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
81
+ * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors).
68
82
  *
69
83
  * Produces a nested map where each endpoint's error type is preserved.
84
+ *
85
+ * @see {@link https://orpc.dev/docs/client/client-side#infer-client-errors | Client-Side Clients - Infer Client Errors}
70
86
  */
71
87
  type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
72
88
  [K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never;
73
89
  };
74
90
  /**
75
- * Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#type‐safe-error-handling).
91
+ * Recursively infers a **union of all error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors).
76
92
  *
77
93
  * Useful when you want to handle all possible errors from any endpoint at once.
94
+ *
95
+ * @see {@link https://orpc.dev/docs/client/client-side#infer-client-error | Client-Side Clients - Infer Client Error}
78
96
  */
79
97
  type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
80
98
  [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never;
81
99
  }[keyof T];
82
100
 
101
+ /**
102
+ * Default mapping between common oRPC error codes and HTTP status codes.
103
+ * Handlers use it to determine response status codes; spread it to build a custom `errorStatusMap`.
104
+ *
105
+ * @see {@link https://orpc.dev/docs/rpc/handler#custom-error-response | RPC Handler - Custom Error Response}
106
+ * @see {@link https://orpc.dev/docs/openapi/handler#custom-error-response | OpenAPI Handler - Custom Error Response}
107
+ */
83
108
  declare const COMMON_ERROR_STATUS_MAP: {
84
109
  BAD_REQUEST: number;
85
110
  UNAUTHORIZED: number;
@@ -114,24 +139,26 @@ type ORPCErrorOptions<TData> = ErrorOptions & {
114
139
  } : {
115
140
  data: TData;
116
141
  });
142
+ /**
143
+ * Typed error carrying a `code`, a `message`, and optional `data`.
144
+ * Throw it from handlers or middleware to produce typed error responses on the client.
145
+ *
146
+ * @see {@link https://orpc.dev/docs/error-handling#orpcerror-class | Error Handling - ORPCError Class}
147
+ */
117
148
  declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
118
149
  /**
119
- * @info
120
- * The `__branch` property is used for type branding, helping TypeScript distinguish
150
+ * @remarks
151
+ * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish
121
152
  * an `ORPCError` instance from plain objects with a similar structure.
122
153
  */
123
154
  readonly name: "ORPCError" & {
124
155
  __branch: "ORPCError";
125
156
  };
126
157
  /**
127
- * Indicates whether the error matches a definition in the procedure's `.errors` map.
158
+ * Indicates whether the error matches a definition in the procedure's `.errors` map,
159
+ * which makes its type inferable on the client.
128
160
  */
129
161
  readonly defined: boolean;
130
- /**
131
- * Indicates whether the error's type is inferable at the TypeScript level.
132
- * This is typically true when the error is explicitly defined or returned within a handler.
133
- */
134
- readonly inferable: boolean;
135
162
  code: TCode;
136
163
  data: TData;
137
164
  constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
@@ -155,13 +182,26 @@ interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCod
155
182
  * remove readonly
156
183
  */
157
184
  defined: boolean;
158
- /**
159
- * remove readonly
160
- */
161
- inferable: boolean;
162
185
  }
163
186
  type AnyORPCError = ORPCError<any, any>;
164
187
  type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
188
+ interface MalformedResponseErrorOptions extends ErrorOptions {
189
+ message?: string;
190
+ response: StandardResponse;
191
+ }
192
+ /**
193
+ * Error indicating a response does not follow the expected oRPC format, carrying
194
+ * the resolved response. Found as the `cause` of a `MALFORMED_ORPC_RESPONSE`
195
+ * `ORPCError`.
196
+ *
197
+ * @see {@link https://orpc.dev/docs/rpc/link#malformed-responses | RPC Link - Malformed Responses}
198
+ * @see {@link https://orpc.dev/docs/openapi/link#malformed-responses | OpenAPI Link - Malformed Responses}
199
+ */
200
+ declare class MalformedResponseError extends Error {
201
+ readonly name = "MalformedResponseError";
202
+ response: StandardResponse;
203
+ constructor(options: MalformedResponseErrorOptions);
204
+ }
165
205
 
166
- export { ORPCError as c, COMMON_ERROR_STATUS_MAP as j };
167
- export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, ORPCErrorJSON as d, AnyNestedClient as e, InferClientError as f, Client as g, ClientRest as h, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as p };
206
+ export { ORPCError as h, COMMON_ERROR_STATUS_MAP as j, MalformedResponseError as p };
207
+ export type { AnyORPCError as A, ClientContext as C, FriendlyClientOptions as F, InferClientContext as I, MalformedResponseErrorOptions as M, NestedClient as N, ORPCErrorCode as O, ClientOptions as a, ClientLink as b, AnyNestedClient as c, InferClientError as d, Client as e, ClientRest as f, ORPCErrorJSON as g, AnyORPCErrorJSON as i, InferClientBodyInputs as k, InferClientBodyOutputs as l, InferClientErrors as m, InferClientInputs as n, InferClientOutputs as o, ORPCErrorOptions as q };
@@ -1,4 +1,4 @@
1
- import { resolveMaybeOptionalOptions, getConstructor } from '@orpc/shared';
1
+ import { resolveMaybeOptionalOptions, getConstructors } from '@orpc/shared';
2
2
 
3
3
  const COMMON_ERROR_STATUS_MAP = {
4
4
  BAD_REQUEST: 400,
@@ -33,20 +33,16 @@ class ORPCError extends Error {
33
33
  ORPCErrorConstructors.add(ORPCError);
34
34
  }
35
35
  /**
36
- * @info
37
- * The `__branch` property is used for type branding, helping TypeScript distinguish
36
+ * @remarks
37
+ * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish
38
38
  * an `ORPCError` instance from plain objects with a similar structure.
39
39
  */
40
40
  name = "ORPCError";
41
41
  /**
42
- * Indicates whether the error matches a definition in the procedure's `.errors` map.
42
+ * Indicates whether the error matches a definition in the procedure's `.errors` map,
43
+ * which makes its type inferable on the client.
43
44
  */
44
45
  defined = false;
45
- /**
46
- * Indicates whether the error's type is inferable at the TypeScript level.
47
- * This is typically true when the error is explicitly defined or returned within a handler.
48
- */
49
- inferable = false;
50
46
  code;
51
47
  data;
52
48
  constructor(code, ...rest) {
@@ -59,7 +55,6 @@ class ORPCError extends Error {
59
55
  toJSON() {
60
56
  return {
61
57
  defined: this.defined,
62
- inferable: this.inferable,
63
58
  code: this.code,
64
59
  message: this.message,
65
60
  data: this.data
@@ -81,12 +76,21 @@ class ORPCError extends Error {
81
76
  if (!ORPCErrorConstructors.has(this)) {
82
77
  return super[Symbol.hasInstance](instance);
83
78
  }
84
- const constructor = getConstructor(instance);
85
- if (constructor && ORPCErrorConstructors.has(constructor)) {
86
- return true;
79
+ for (const constructor of getConstructors(instance)) {
80
+ if (ORPCErrorConstructors.has(constructor)) {
81
+ return true;
82
+ }
87
83
  }
88
- return super[Symbol.hasInstance](instance);
84
+ return false;
85
+ }
86
+ }
87
+ class MalformedResponseError extends Error {
88
+ name = "MalformedResponseError";
89
+ response;
90
+ constructor(options) {
91
+ super(options.message, options);
92
+ this.response = options.response;
89
93
  }
90
94
  }
91
95
 
92
- export { COMMON_ERROR_STATUS_MAP as C, ORPCError as O };
96
+ export { COMMON_ERROR_STATUS_MAP as C, MalformedResponseError as M, ORPCError as O };
@@ -1,8 +1,7 @@
1
- import { sortPlugins, runWithSpan, ORPC_NAME, isAsyncIteratorObject, override, traceAsyncIterator, intercept, getOpenTelemetryConfig, value, pathToHttpPath, stringifyJSON } from '@orpc/shared';
2
- import { mergeStandardHeaders, parseStandardUrl } from '@standardserver/core';
3
- import { toStandardHeaders } from '@standardserver/fetch';
4
- import { O as ORPCError } from './client.Dnfj8jnT.mjs';
5
- import { R as RPCSerializer, i as isORPCErrorJson, c as createORPCErrorFromJson } from './client.DMXKFDyV.mjs';
1
+ import { sortPlugins, runWithSpan, ORPC_NAME, getTracer, isAsyncIteratorObject, override, traceAsyncIterator, traceReadableStream, intercept, value, pathToHttpPath, stringifyJSON } from '@orpc/shared';
2
+ import { mergeStandardHeaders, parseStandardUrl } from '@standard-server/core';
3
+ import { toStandardHeaders } from '@standard-server/fetch';
4
+ import { R as RPCSerializer, c as createORPCErrorFromMalformedResponse, i as isORPCErrorJson, a as createORPCErrorFromJson } from './client.BYHnU_Z3.mjs';
6
5
 
7
6
  class CompositeStandardLinkPlugin {
8
7
  name = "~composite";
@@ -37,50 +36,46 @@ class StandardLink {
37
36
  return runWithSpan(`${ORPC_NAME}.${path.join("/")}`, (span) => {
38
37
  span?.setAttribute("rpc.system", ORPC_NAME);
39
38
  span?.setAttribute("rpc.method", path.join("."));
40
- if (isAsyncIteratorObject(input)) {
41
- input = override(input, traceAsyncIterator("consume_event_iterator_input", input));
39
+ if (getTracer() && isAsyncIteratorObject(input)) {
40
+ input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
41
+ } else if (getTracer() && input instanceof ReadableStream) {
42
+ input = override(input, traceReadableStream("consume_octet_stream_input", input));
42
43
  }
43
44
  return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
44
- const otel = getOpenTelemetryConfig();
45
- let activeContext;
46
- const activeSpan = otel?.trace.getActiveSpan() ?? span;
47
- if (activeSpan && otel) {
48
- activeContext = otel.trace.setSpan(otel.context.active(), activeSpan);
49
- }
45
+ const tracer = getTracer();
46
+ const activeSpan = tracer?.getActiveSpan() ?? span;
50
47
  let request = await runWithSpan(
51
- { name: "encode_input", context: activeContext },
48
+ { name: "encode_input", parent: activeSpan },
52
49
  () => this.codec.encodeInput(input2, path2, options2)
53
50
  );
54
- if (activeContext && otel?.propagation) {
51
+ if (activeSpan && tracer?.inject) {
55
52
  const headers = { ...request.headers };
56
- otel.propagation.inject(activeContext, headers);
53
+ tracer.inject(activeSpan, headers);
57
54
  request = { ...request, headers };
58
55
  }
59
56
  const response = await intercept(
60
57
  this.transportInterceptors,
61
58
  { ...options2, path: path2, request },
62
59
  ({ path: path3, request: request2, ...options3 }) => {
63
- let activeTransportContext;
64
- const activeTransportSpan = otel?.trace.getActiveSpan() ?? activeSpan;
65
- if (activeTransportSpan && otel) {
66
- activeTransportContext = otel.trace.setSpan(otel.context.active(), activeTransportSpan);
67
- }
60
+ const activeTransportSpan = tracer?.getActiveSpan() ?? activeSpan;
68
61
  return runWithSpan(
69
- { name: "send_request", context: activeTransportContext },
62
+ { name: "send_request", parent: activeTransportSpan },
70
63
  () => this.transport.send(request2, path3, options3)
71
64
  );
72
65
  }
73
66
  );
74
67
  const decodedResult = await runWithSpan(
75
- { name: "decode_response", context: activeContext },
68
+ { name: "decode_response", parent: activeSpan },
76
69
  () => this.codec.decodeResponse(response, path2, options2)
77
70
  );
78
71
  if (decodedResult.kind === "error") {
79
72
  throw decodedResult.error;
80
73
  }
81
74
  const output = decodedResult.output;
82
- if (isAsyncIteratorObject(output)) {
83
- return override(output, traceAsyncIterator("consume_event_iterator_output", output));
75
+ if (getTracer() && isAsyncIteratorObject(output)) {
76
+ return override(output, traceAsyncIterator("consume_async_iterator_object_output", output));
77
+ } else if (getTracer() && output instanceof ReadableStream) {
78
+ return override(output, traceReadableStream("consume_octet_stream_output", output));
84
79
  }
85
80
  return output;
86
81
  });
@@ -139,13 +134,15 @@ class RPCLinkCodec {
139
134
  };
140
135
  }
141
136
  async decodeResponse(response) {
142
- const isOk = response.status >= 200 && response.status < 400;
137
+ const isOk = response.status < 400;
143
138
  const body = await response.resolveBody();
144
139
  const deserialized = await (async () => {
145
140
  try {
146
141
  return this.serializer.deserialize(body);
147
142
  } catch (cause) {
148
- throw new Error("Invalid RPC response format.", {
143
+ throw createORPCErrorFromMalformedResponse({
144
+ message: "Invalid RPC response format.",
145
+ response: { status: response.status, headers: response.headers, body },
149
146
  cause
150
147
  });
151
148
  }
@@ -156,9 +153,7 @@ class RPCLinkCodec {
156
153
  }
157
154
  return {
158
155
  kind: "error",
159
- error: new ORPCError("MALFORMED_ORPC_ERROR_RESPONSE", {
160
- data: { headers: response.headers, status: response.status, body: deserialized }
161
- })
156
+ error: createORPCErrorFromMalformedResponse({ response: { headers: response.headers, status: response.status, body } })
162
157
  };
163
158
  }
164
159
  return { kind: "output", output: deserialized };
@@ -1,4 +1,4 @@
1
- import { StandardBody } from '@standardserver/core';
1
+ import { StandardBody } from '@standard-server/core';
2
2
  import { Segment } from '@orpc/shared';
3
3
 
4
4
  type RPCJsonSerializationMeta = [type: string, ...path: Segment[]];
@@ -16,7 +16,10 @@ type RPCJsonSerialization = {
16
16
  interface RPCJsonSerializerHandler {
17
17
  condition(value: unknown): boolean;
18
18
  serialize(value: any): unknown;
19
- deserialize(serialized: any): unknown;
19
+ /**
20
+ * `serialized` comes from the wire, so validate its type and throw on mismatch.
21
+ */
22
+ deserialize(serialized: unknown): unknown;
20
23
  /**
21
24
  * If false, the result of this serializer will not be further processed by other serializers,
22
25
  * even if it matches their conditions and treat it as final serialized value.
@@ -60,10 +63,10 @@ interface RPCJsonSerializerOptions {
60
63
  *
61
64
  * **Disabling:** Set a key to `undefined` to remove a built-in handler:
62
65
  * ```ts
63
- * handlers: { regexp: undefined }
66
+ * handlers: { url: undefined }
64
67
  * ```
65
68
  *
66
- * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `regexp`, `set`, `map`.
69
+ * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `set`, `map`.
67
70
  */
68
71
  handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined;
69
72
  /**
@@ -73,11 +76,23 @@ interface RPCJsonSerializerOptions {
73
76
  */
74
77
  omitUndefinedProperties?: boolean | undefined;
75
78
  }
79
+ /**
80
+ * Serializes and deserializes native types like Date, BigInt, Set, and Map
81
+ * into a JSON value plus separate metadata describing how to restore them.
82
+ *
83
+ * @see {@link https://orpc.dev/docs/rpc/serializer#rpc-json-serializer | RPC Serializer - RPC JSON Serializer}
84
+ */
76
85
  declare class RPCJsonSerializer {
77
86
  private readonly handlers;
87
+ private readonly inlineBuiltInHandlers;
88
+ private readonly handlerEntries;
78
89
  private readonly omitUndefinedProperties;
79
90
  constructor(options?: RPCJsonSerializerOptions);
80
91
  serialize(data: unknown): RPCJsonSerialization;
92
+ /**
93
+ * `segments` is a shared mutable stack (push/pop while walking),
94
+ * so it must be copied before being stored in `meta` or `maps`.
95
+ */
81
96
  private serializeValue;
82
97
  deserialize(serialized: RPCJsonSerialization): unknown;
83
98
  }
@@ -97,6 +112,12 @@ interface RPCSerializerOptions extends RPCJsonSerializerOptions {
97
112
  */
98
113
  serialize?: RPCSerializerSerializeOptions | undefined;
99
114
  }
115
+ /**
116
+ * Serializes and deserializes data for the RPC protocol,
117
+ * preserving native types like Date, BigInt, Set, and Map that plain JSON cannot represent.
118
+ *
119
+ * @see {@link https://orpc.dev/docs/rpc/serializer | RPC Serializer}
120
+ */
100
121
  declare class RPCSerializer {
101
122
  private readonly jsonSerializer;
102
123
  private readonly defaultSerializeOptions;
@@ -1,4 +1,4 @@
1
- import { StandardBody } from '@standardserver/core';
1
+ import { StandardBody } from '@standard-server/core';
2
2
  import { Segment } from '@orpc/shared';
3
3
 
4
4
  type RPCJsonSerializationMeta = [type: string, ...path: Segment[]];
@@ -16,7 +16,10 @@ type RPCJsonSerialization = {
16
16
  interface RPCJsonSerializerHandler {
17
17
  condition(value: unknown): boolean;
18
18
  serialize(value: any): unknown;
19
- deserialize(serialized: any): unknown;
19
+ /**
20
+ * `serialized` comes from the wire, so validate its type and throw on mismatch.
21
+ */
22
+ deserialize(serialized: unknown): unknown;
20
23
  /**
21
24
  * If false, the result of this serializer will not be further processed by other serializers,
22
25
  * even if it matches their conditions and treat it as final serialized value.
@@ -60,10 +63,10 @@ interface RPCJsonSerializerOptions {
60
63
  *
61
64
  * **Disabling:** Set a key to `undefined` to remove a built-in handler:
62
65
  * ```ts
63
- * handlers: { regexp: undefined }
66
+ * handlers: { url: undefined }
64
67
  * ```
65
68
  *
66
- * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `regexp`, `set`, `map`.
69
+ * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `url`, `set`, `map`.
67
70
  */
68
71
  handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined;
69
72
  /**
@@ -73,11 +76,23 @@ interface RPCJsonSerializerOptions {
73
76
  */
74
77
  omitUndefinedProperties?: boolean | undefined;
75
78
  }
79
+ /**
80
+ * Serializes and deserializes native types like Date, BigInt, Set, and Map
81
+ * into a JSON value plus separate metadata describing how to restore them.
82
+ *
83
+ * @see {@link https://orpc.dev/docs/rpc/serializer#rpc-json-serializer | RPC Serializer - RPC JSON Serializer}
84
+ */
76
85
  declare class RPCJsonSerializer {
77
86
  private readonly handlers;
87
+ private readonly inlineBuiltInHandlers;
88
+ private readonly handlerEntries;
78
89
  private readonly omitUndefinedProperties;
79
90
  constructor(options?: RPCJsonSerializerOptions);
80
91
  serialize(data: unknown): RPCJsonSerialization;
92
+ /**
93
+ * `segments` is a shared mutable stack (push/pop while walking),
94
+ * so it must be copied before being stored in `meta` or `maps`.
95
+ */
81
96
  private serializeValue;
82
97
  deserialize(serialized: RPCJsonSerialization): unknown;
83
98
  }
@@ -97,6 +112,12 @@ interface RPCSerializerOptions extends RPCJsonSerializerOptions {
97
112
  */
98
113
  serialize?: RPCSerializerSerializeOptions | undefined;
99
114
  }
115
+ /**
116
+ * Serializes and deserializes data for the RPC protocol,
117
+ * preserving native types like Date, BigInt, Set, and Map that plain JSON cannot represent.
118
+ *
119
+ * @see {@link https://orpc.dev/docs/rpc/serializer | RPC Serializer}
120
+ */
100
121
  declare class RPCSerializer {
101
122
  private readonly jsonSerializer;
102
123
  private readonly defaultSerializeOptions;
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.4",
4
+ "version": "2.0.0-beta.40",
5
+ "description": "Consume oRPC and OpenAPI APIs with end-to-end type safety over HTTP, WebSocket, or message ports",
5
6
  "license": "MIT",
7
+ "funding": [
8
+ "https://github.com/sponsors/dinwwwh",
9
+ "https://opencollective.com/middleapi"
10
+ ],
6
11
  "homepage": "https://orpc.dev",
7
12
  "repository": {
8
13
  "type": "git",
@@ -10,7 +15,15 @@
10
15
  "directory": "packages/client"
11
16
  },
12
17
  "keywords": [
13
- "orpc"
18
+ "orpc",
19
+ "rpc",
20
+ "api",
21
+ "typescript",
22
+ "typesafe",
23
+ "client",
24
+ "fetch",
25
+ "websocket",
26
+ "openapi"
14
27
  ],
15
28
  "sideEffects": false,
16
29
  "exports": {
@@ -50,16 +63,15 @@
50
63
  "dist"
51
64
  ],
52
65
  "dependencies": {
53
- "@standardserver/core": "^0.0.25",
54
- "@standardserver/fetch": "^0.0.25",
55
- "@standardserver/peer": "^0.0.25",
56
- "@orpc/shared": "2.0.0-beta.4"
66
+ "@orpc/shared": "2.0.0-beta.40",
67
+ "@standard-server/core": "~0.9.2",
68
+ "@standard-server/fetch": "~0.9.2",
69
+ "@standard-server/peer": "~0.9.2"
57
70
  },
58
71
  "devDependencies": {
59
- "zod": "^4.4.3"
72
+ "zod": "^4.5.4"
60
73
  },
61
74
  "scripts": {
62
- "build": "unbuild",
63
75
  "type:check": "tsc -b"
64
76
  }
65
77
  }