@orpc/client 2.0.0-beta.47 → 2.0.0-beta.49

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 (94) hide show
  1. package/README.md +6 -7
  2. package/dist/adapters/fetch/index.d.ts +2 -48
  3. package/dist/adapters/fetch/index.js +2 -0
  4. package/dist/adapters/fetch/rpc-link.d.ts +14 -0
  5. package/dist/adapters/fetch/rpc-link.js +14 -0
  6. package/dist/adapters/fetch/transport.d.ts +34 -0
  7. package/dist/adapters/fetch/transport.js +65 -0
  8. package/dist/adapters/message-port/index.d.ts +3 -80
  9. package/dist/adapters/message-port/index.js +3 -0
  10. package/dist/adapters/message-port/message-port.d.ts +29 -0
  11. package/dist/adapters/message-port/message-port.js +56 -0
  12. package/dist/adapters/message-port/rpc-link.d.ts +15 -0
  13. package/dist/adapters/message-port/rpc-link.js +15 -0
  14. package/dist/adapters/message-port/transport.d.ts +38 -0
  15. package/dist/adapters/message-port/transport.js +52 -0
  16. package/dist/adapters/standard/codec.d.ts +14 -0
  17. package/dist/adapters/standard/codec.js +1 -0
  18. package/dist/adapters/standard/index.d.ts +5 -60
  19. package/dist/adapters/standard/index.js +4 -0
  20. package/dist/adapters/standard/link.d.ts +40 -0
  21. package/dist/adapters/standard/link.js +85 -0
  22. package/dist/adapters/standard/plugin.d.ts +32 -0
  23. package/dist/adapters/standard/plugin.js +16 -0
  24. package/dist/adapters/standard/{index.d.mts → rpc-link-codec.d.ts} +17 -14
  25. package/dist/adapters/standard/rpc-link-codec.js +104 -0
  26. package/dist/adapters/standard/transport.d.ts +14 -0
  27. package/dist/adapters/standard/transport.js +1 -0
  28. package/dist/adapters/websocket/index.d.ts +2 -136
  29. package/dist/adapters/websocket/index.js +2 -0
  30. package/dist/adapters/websocket/rpc-link.d.ts +14 -0
  31. package/dist/adapters/websocket/rpc-link.js +14 -0
  32. package/dist/adapters/websocket/{index.d.mts → transport.d.ts} +32 -53
  33. package/dist/adapters/websocket/transport.js +133 -0
  34. package/dist/async-iterator-object.d.ts +2 -0
  35. package/dist/async-iterator-object.js +29 -0
  36. package/dist/client-safe.d.ts +18 -0
  37. package/dist/client-safe.js +36 -0
  38. package/dist/client.d.ts +40 -0
  39. package/dist/client.js +39 -0
  40. package/dist/consts.d.ts +10 -0
  41. package/dist/consts.js +43 -0
  42. package/dist/dynamic-link.d.ts +13 -0
  43. package/dist/dynamic-link.js +17 -0
  44. package/dist/error-utils.d.ts +21 -0
  45. package/dist/error-utils.js +58 -0
  46. package/dist/error.d.ts +132 -0
  47. package/dist/error.js +178 -0
  48. package/dist/index.d.ts +38 -129
  49. package/dist/index.js +40 -0
  50. package/dist/plugins/batch.d.ts +185 -0
  51. package/dist/plugins/batch.js +401 -0
  52. package/dist/plugins/cookie-jar.d.ts +82 -0
  53. package/dist/plugins/cookie-jar.js +268 -0
  54. package/dist/plugins/dedupe.d.ts +64 -0
  55. package/dist/plugins/dedupe.js +226 -0
  56. package/dist/plugins/index.d.ts +20 -412
  57. package/dist/plugins/index.js +23 -0
  58. package/dist/plugins/request-compression.d.ts +44 -0
  59. package/dist/plugins/request-compression.js +178 -0
  60. package/dist/plugins/response-compression.d.ts +28 -0
  61. package/dist/plugins/response-compression.js +91 -0
  62. package/dist/plugins/retry-after.d.ts +50 -0
  63. package/dist/plugins/retry-after.js +88 -0
  64. package/dist/plugins/retry.d.ts +84 -0
  65. package/dist/plugins/retry.js +140 -0
  66. package/dist/plugins/timeout.d.ts +25 -0
  67. package/dist/plugins/timeout.js +37 -0
  68. package/dist/{shared/client.DqIWeNhQ.d.mts → rpc-json-serializer.d.ts} +9 -41
  69. package/dist/rpc-json-serializer.js +392 -0
  70. package/dist/rpc-serializer.d.ts +32 -0
  71. package/dist/rpc-serializer.js +130 -0
  72. package/dist/types.d.ts +97 -0
  73. package/dist/types.js +1 -0
  74. package/dist/utils.d.ts +47 -0
  75. package/dist/utils.js +51 -0
  76. package/package.json +43 -45
  77. package/dist/adapters/fetch/index.d.mts +0 -48
  78. package/dist/adapters/fetch/index.mjs +0 -77
  79. package/dist/adapters/message-port/index.d.mts +0 -80
  80. package/dist/adapters/message-port/index.mjs +0 -101
  81. package/dist/adapters/standard/index.mjs +0 -6
  82. package/dist/adapters/websocket/index.mjs +0 -131
  83. package/dist/index.d.mts +0 -144
  84. package/dist/index.mjs +0 -147
  85. package/dist/plugins/index.d.mts +0 -420
  86. package/dist/plugins/index.mjs +0 -971
  87. package/dist/shared/client.BoHJeq15.d.mts +0 -233
  88. package/dist/shared/client.BoHJeq15.d.ts +0 -233
  89. package/dist/shared/client.CKQeJJ2U.mjs +0 -172
  90. package/dist/shared/client.DqIWeNhQ.d.ts +0 -131
  91. package/dist/shared/client.JBJwBhR8.d.ts +0 -90
  92. package/dist/shared/client.LF04eOvL.mjs +0 -115
  93. package/dist/shared/client._wG5INmC.mjs +0 -505
  94. package/dist/shared/client.euYjjcFz.d.mts +0 -90
@@ -1,131 +0,0 @@
1
- import { StandardBody } from '@standard-server/core';
2
- import { Segment } from '@orpc/shared';
3
-
4
- type RPCJsonSerializationMeta = [type: string, ...path: Segment[]];
5
- type RPCJsonSerialization = {
6
- json: unknown;
7
- meta?: RPCJsonSerializationMeta[] | undefined;
8
- maps?: undefined;
9
- blobs?: undefined;
10
- } | {
11
- json: unknown;
12
- meta?: RPCJsonSerializationMeta[] | undefined;
13
- maps: Segment[][];
14
- blobs: Blob[];
15
- };
16
- interface RPCJsonSerializerHandler {
17
- condition(value: unknown): boolean;
18
- serialize(value: any): unknown;
19
- /**
20
- * `serialized` comes from the wire, so validate its type and throw on mismatch.
21
- */
22
- deserialize(serialized: unknown): unknown;
23
- /**
24
- * If false, the result of this serializer will not be further processed by other serializers,
25
- * even if it matches their conditions and treat it as final serialized value.
26
- * This can be useful for serializers that return primitive values, which should not be further processed.
27
- * to improve performance and avoid potential issues with other serializers.
28
- *
29
- * @default false
30
- */
31
- isTerminal?: boolean | undefined;
32
- }
33
- interface RPCJsonSerializerOptions {
34
- /**
35
- * Extend or override the built-in type handlers used during serialization and deserialization.
36
- *
37
- * Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler
38
- * that defines how to detect, serialize, and deserialize values of that type.
39
- *
40
- * **Extending:** Add new keys to support custom types:
41
- * ```ts
42
- * handlers: {
43
- * buffer: {
44
- * condition: (v) => v instanceof Buffer,
45
- * serialize: (v: Buffer) => v.toString('base64'),
46
- * deserialize: (s: string) => Buffer.from(s, 'base64'),
47
- * isTerminal: true,
48
- * }
49
- * }
50
- * ```
51
- *
52
- * **Overriding:** Use an existing key to replace a built-in handler:
53
- * ```ts
54
- * handlers: {
55
- * date: {
56
- * condition: (v) => v instanceof Date,
57
- * serialize: (v: Date) => v.getTime(),
58
- * deserialize: (n: number) => new Date(n),
59
- * isTerminal: true,
60
- * }
61
- * }
62
- * ```
63
- *
64
- * **Disabling:** Set a key to `undefined` to remove a built-in handler:
65
- * ```ts
66
- * handlers: { url: undefined }
67
- * ```
68
- *
69
- * Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `infinity`, `url`, `set`, `map`.
70
- */
71
- handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined;
72
- /**
73
- * If true, properties with undefined values will be omitted during serialization.
74
- *
75
- * @default true
76
- */
77
- omitUndefinedProperties?: boolean | undefined;
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
- */
85
- declare class RPCJsonSerializer {
86
- private readonly handlers;
87
- private readonly inlineBuiltInHandlers;
88
- private readonly handlerEntries;
89
- private readonly omitUndefinedProperties;
90
- constructor(options?: RPCJsonSerializerOptions);
91
- serializeJson(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
- */
96
- private serializeValue;
97
- deserializeJson(serialized: RPCJsonSerialization): unknown;
98
- }
99
-
100
- interface RPCSerializerSerializeOptions {
101
- /**
102
- * Use FormData for serialization when nested blobs are present.
103
- * Does not apply to root-level Blob values.
104
- *
105
- * @default true
106
- */
107
- useFormDataForBlobFields?: boolean | undefined;
108
- }
109
- interface RPCSerializerOptions extends RPCJsonSerializerOptions {
110
- /**
111
- * Default options for serialize method
112
- */
113
- serialize?: RPCSerializerSerializeOptions | undefined;
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
- */
121
- declare class RPCSerializer extends RPCJsonSerializer {
122
- private readonly defaultSerializeOptions;
123
- constructor(options?: RPCSerializerOptions);
124
- serialize(data: unknown, options?: RPCSerializerSerializeOptions): StandardBody;
125
- private serializePayload;
126
- deserialize(data: StandardBody): unknown;
127
- private deserializePayload;
128
- }
129
-
130
- export { RPCJsonSerializer as b, RPCSerializer as e };
131
- export type { RPCJsonSerialization as R, RPCJsonSerializationMeta as a, RPCJsonSerializerHandler as c, RPCJsonSerializerOptions as d, RPCSerializerOptions as f, RPCSerializerSerializeOptions as g };
@@ -1,90 +0,0 @@
1
- import { Promisable, OrderablePlugin, Interceptor } from '@orpc/shared';
2
- import { StandardRequest, StandardLazyResponse } from '@standard-server/core';
3
- import { C as ClientContext, a as ClientOptions, A as AnyORPCError, b as ClientLink } from './client.BoHJeq15.js';
4
-
5
- type StandardLinkCodecDecodedResponse = {
6
- kind: 'output';
7
- output: unknown;
8
- } | {
9
- kind: 'error';
10
- error: AnyORPCError;
11
- };
12
- interface StandardLinkCodec<T extends ClientContext> {
13
- encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promisable<StandardRequest>;
14
- decodeResponse(response: StandardLazyResponse, path: string[], options: ClientOptions<T>): Promisable<StandardLinkCodecDecodedResponse>;
15
- }
16
-
17
- interface StandardLinkPlugin<T extends ClientContext> extends OrderablePlugin {
18
- /**
19
- * Initializes the plugin and returns new link options.
20
- * Called once per plugin instance during composition.
21
- *
22
- * This method allows plugins to wrap, extend, or transform link options
23
- * such as interceptors, or configuration.
24
- *
25
- * @param options - The current link options from previous plugins or base configuration
26
- * @returns Transformed link options with plugin's modifications applied
27
- *
28
- * @example
29
- * ```ts
30
- * init(options) {
31
- * return {
32
- * ...options,
33
- * interceptors: [...(options.interceptors || []), myInterceptor]
34
- * }
35
- * }
36
- * ```
37
- */
38
- init?(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
39
- }
40
-
41
- /**
42
- * Handles the transport layer for sending requests and receiving responses.
43
- *
44
- * Implementations are responsible for the actual network communication,
45
- * such as HTTP fetch, WebSocket, or other transport mechanisms.
46
- */
47
- interface StandardLinkTransport<T extends ClientContext> {
48
- /**
49
- * @throws Transport-level errors (network failures, timeouts, etc.)
50
- */
51
- send(request: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
52
- }
53
-
54
- interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
55
- path: string[];
56
- input: unknown;
57
- }
58
- type StandardLinkInterceptor<T extends ClientContext> = Interceptor<StandardLinkInterceptorOptions<T>, Promise<unknown>>;
59
- interface StandardLinkTransportInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
60
- path: string[];
61
- request: StandardRequest;
62
- }
63
- type StandardLinkTransportInterceptor<T extends ClientContext> = Interceptor<StandardLinkTransportInterceptorOptions<T>, Promise<StandardLazyResponse>>;
64
- interface StandardLinkOptions<T extends ClientContext> {
65
- /**
66
- * Interceptors that execute around the entire call, including transport and codec.
67
- * Useful for error handling, logging, metrics, ...
68
- */
69
- interceptors?: StandardLinkInterceptor<T>[] | undefined;
70
- /**
71
- * Interceptors that execute around the transport layer, after encoding and before decoding.
72
- * Useful for modifying the request or response, adding transport-level logging, ...
73
- */
74
- transportInterceptors?: StandardLinkTransportInterceptor<T>[] | undefined;
75
- plugins?: StandardLinkPlugin<T>[] | undefined;
76
- }
77
- declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
78
- private readonly codec;
79
- private readonly transport;
80
- private readonly interceptors;
81
- private readonly transportInterceptors;
82
- constructor(codec: StandardLinkCodec<T>, transport: StandardLinkTransport<T>, options?: StandardLinkOptions<T>);
83
- /**
84
- * @throws ORPCError, MalformedResponseError, transport-level errors (network failures, timeouts, etc.)
85
- */
86
- call(path: string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
87
- }
88
-
89
- export { StandardLink as a };
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 };
@@ -1,115 +0,0 @@
1
- import { resolveMaybeOptionalOptions, getConstructors, isPlainObject } from '@orpc/shared';
2
-
3
- const COMMON_ERROR_STATUS_MAP = {
4
- BAD_REQUEST: 400,
5
- UNAUTHORIZED: 401,
6
- PAYMENT_REQUIRED: 402,
7
- FORBIDDEN: 403,
8
- NOT_FOUND: 404,
9
- METHOD_NOT_SUPPORTED: 405,
10
- NOT_ACCEPTABLE: 406,
11
- TIMEOUT: 408,
12
- CONFLICT: 409,
13
- GONE: 410,
14
- LENGTH_REQUIRED: 411,
15
- PRECONDITION_FAILED: 412,
16
- PAYLOAD_TOO_LARGE: 413,
17
- UNSUPPORTED_MEDIA_TYPE: 415,
18
- UNPROCESSABLE_CONTENT: 422,
19
- PRECONDITION_REQUIRED: 428,
20
- TOO_MANY_REQUESTS: 429,
21
- CLIENT_CLOSED_REQUEST: 499,
22
- INTERNAL_SERVER_ERROR: 500,
23
- NOT_IMPLEMENTED: 501,
24
- BAD_GATEWAY: 502,
25
- SERVICE_UNAVAILABLE: 503,
26
- GATEWAY_TIMEOUT: 504
27
- };
28
- let ORPCErrorConstructors;
29
- class ORPCError extends Error {
30
- static {
31
- const ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for("ORPC_ERROR_CONSTRUCTORS");
32
- void (globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
33
- ORPCErrorConstructors = globalThis[ORPC_ERROR_CONSTRUCTORS_SYMBOL];
34
- ORPCErrorConstructors.add(ORPCError);
35
- }
36
- /**
37
- * @remarks
38
- * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish
39
- * an `ORPCError` instance from plain objects with a similar structure.
40
- */
41
- name = "ORPCError";
42
- /**
43
- * Indicates whether the error matches a definition in the procedure's `.errors` map,
44
- * which makes its type inferable on the client.
45
- */
46
- defined = false;
47
- code;
48
- data;
49
- constructor(code, ...rest) {
50
- const options = resolveMaybeOptionalOptions(rest);
51
- const message = options.message ?? codeToMessage(code);
52
- super(message, options);
53
- this.code = code;
54
- this.data = options.data;
55
- }
56
- toJSON() {
57
- return {
58
- defined: this.defined,
59
- code: this.code,
60
- message: this.message,
61
- data: this.data
62
- };
63
- }
64
- /**
65
- * Workaround for Next.js where different contexts use separate
66
- * dependency graphs, causing multiple ORPCError constructors existing and breaking
67
- * `instanceof` checks across contexts.
68
- *
69
- * This is particularly problematic with "Optimized SSR", where orpc-client
70
- * executes in one context but is invoked from another. When an error is thrown
71
- * in the execution context, `instanceof ORPCError` checks fail in the
72
- * invocation context due to separate class constructors.
73
- *
74
- * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
75
- */
76
- static [Symbol.hasInstance](instance) {
77
- if (!ORPCErrorConstructors.has(this)) {
78
- return super[Symbol.hasInstance](instance);
79
- }
80
- for (const constructor of getConstructors(instance)) {
81
- if (ORPCErrorConstructors.has(constructor)) {
82
- return true;
83
- }
84
- }
85
- return false;
86
- }
87
- }
88
- class ResponseError extends Error {
89
- name = "ResponseError";
90
- response;
91
- constructor(options) {
92
- super(options.message ?? `Received a ${options.response.status} response.`, options);
93
- this.response = options.response;
94
- }
95
- }
96
- class MalformedResponseError extends ResponseError {
97
- name = "MalformedResponseError";
98
- constructor(options) {
99
- super({ ...options, message: options.message ?? inferMalformedResponseMessage(options.response) });
100
- }
101
- }
102
- const INFERRED_MESSAGE_MAX_LENGTH = 256;
103
- function inferMalformedResponseMessage(response) {
104
- const candidate = isPlainObject(response.body) ? response.body.message : response.body;
105
- if (typeof candidate === "string" && candidate.length > 0 && candidate.length <= INFERRED_MESSAGE_MAX_LENGTH) {
106
- return candidate;
107
- }
108
- const commonCode = Object.entries(COMMON_ERROR_STATUS_MAP).find(([, status]) => status === response.status)?.[0];
109
- return commonCode ? codeToMessage(commonCode) : "Malformed oRPC Response";
110
- }
111
- function codeToMessage(code) {
112
- return code.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
113
- }
114
-
115
- export { COMMON_ERROR_STATUS_MAP as C, MalformedResponseError as M, ORPCError as O, ResponseError as R };