@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,233 +0,0 @@
1
- import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared';
2
- import { StandardResponse } from '@standard-server/core';
3
-
4
- interface ClientContext {
5
- [key: PropertyKey]: any;
6
- }
7
- interface ClientOptions<T extends ClientContext> {
8
- signal?: AbortSignal | undefined;
9
- lastEventId?: string | undefined;
10
- context: T;
11
- }
12
- type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
13
- context?: T | undefined;
14
- } : {
15
- context: T;
16
- });
17
- type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
18
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
19
- (...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>;
20
- }
21
- type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
22
- [k: string]: NestedClient<TClientContext>;
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
- */
30
- type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never;
31
- interface ClientLink<TClientContext extends ClientContext> {
32
- call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
33
- }
34
- /**
35
- * Recursively infers the **input types** from a client.
36
- *
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}
40
- */
41
- type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : {
42
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never;
43
- };
44
- /**
45
- * Recursively infers the **body input types** from a client.
46
- *
47
- * If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
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}
51
- */
52
- type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends {
53
- body: infer UBody;
54
- } ? UBody : U : {
55
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyInputs<T[K]> : never;
56
- };
57
- /**
58
- * Recursively infers the **output types** from a client.
59
- *
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}
63
- */
64
- type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : {
65
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never;
66
- };
67
- /**
68
- * Recursively infers the **body output types** from a client.
69
- *
70
- * If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
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}
74
- */
75
- type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends {
76
- body: infer UBody;
77
- } ? UBody : U : {
78
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never;
79
- };
80
- /**
81
- * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors).
82
- *
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}
86
- */
87
- type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
88
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never;
89
- };
90
- /**
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).
92
- *
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}
96
- */
97
- type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
98
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never;
99
- }[keyof T];
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
- */
108
- declare const COMMON_ERROR_STATUS_MAP: {
109
- BAD_REQUEST: number;
110
- UNAUTHORIZED: number;
111
- PAYMENT_REQUIRED: number;
112
- FORBIDDEN: number;
113
- NOT_FOUND: number;
114
- METHOD_NOT_SUPPORTED: number;
115
- NOT_ACCEPTABLE: number;
116
- TIMEOUT: number;
117
- CONFLICT: number;
118
- GONE: number;
119
- LENGTH_REQUIRED: number;
120
- PRECONDITION_FAILED: number;
121
- PAYLOAD_TOO_LARGE: number;
122
- UNSUPPORTED_MEDIA_TYPE: number;
123
- UNPROCESSABLE_CONTENT: number;
124
- PRECONDITION_REQUIRED: number;
125
- TOO_MANY_REQUESTS: number;
126
- CLIENT_CLOSED_REQUEST: number;
127
- INTERNAL_SERVER_ERROR: number;
128
- NOT_IMPLEMENTED: number;
129
- BAD_GATEWAY: number;
130
- SERVICE_UNAVAILABLE: number;
131
- GATEWAY_TIMEOUT: number;
132
- };
133
- type ORPCErrorCode = Registry extends {
134
- ORPCErrorCode: infer T extends string;
135
- } ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {});
136
- type ORPCErrorOptions<TData> = ErrorOptions & {
137
- message?: string | undefined;
138
- } & (undefined extends TData ? {
139
- data?: TData;
140
- } : {
141
- data: TData;
142
- });
143
- /**
144
- * Typed error carrying a `code`, a `message`, and optional `data`.
145
- * Throw it from handlers or middleware to produce typed error responses on the client.
146
- *
147
- * @see {@link https://orpc.dev/docs/error-handling#orpcerror-class | Error Handling - ORPCError Class}
148
- */
149
- declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
150
- /**
151
- * @remarks
152
- * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish
153
- * an `ORPCError` instance from plain objects with a similar structure.
154
- */
155
- readonly name: "ORPCError" & {
156
- __branch: "ORPCError";
157
- };
158
- /**
159
- * Indicates whether the error matches a definition in the procedure's `.errors` map,
160
- * which makes its type inferable on the client.
161
- */
162
- readonly defined: boolean;
163
- code: TCode;
164
- data: TData;
165
- constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
166
- toJSON(): ORPCErrorJSON<TCode, TData>;
167
- /**
168
- * Workaround for Next.js where different contexts use separate
169
- * dependency graphs, causing multiple ORPCError constructors existing and breaking
170
- * `instanceof` checks across contexts.
171
- *
172
- * This is particularly problematic with "Optimized SSR", where orpc-client
173
- * executes in one context but is invoked from another. When an error is thrown
174
- * in the execution context, `instanceof ORPCError` checks fail in the
175
- * invocation context due to separate class constructors.
176
- *
177
- * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
178
- */
179
- static [Symbol.hasInstance](instance: unknown): boolean;
180
- }
181
- interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> {
182
- /**
183
- * remove readonly
184
- */
185
- defined: boolean;
186
- }
187
- type AnyORPCError = ORPCError<any, any>;
188
- type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
189
- interface ResponseErrorOptions extends ErrorOptions {
190
- /**
191
- * @default inferred from the response status
192
- */
193
- message?: string | undefined;
194
- response: StandardResponse;
195
- }
196
- /**
197
- * Error carrying the resolved response a link received. Links set it as the `cause`
198
- * of an `ORPCError` decoded from an error response, so details that are not part
199
- * of the error itself, such as its status or headers, stay available.
200
- *
201
- * @see {@link https://orpc.dev/docs/rpc/link#error-responses | RPC Link - Error Responses}
202
- * @see {@link https://orpc.dev/docs/openapi/link#error-responses | OpenAPI Link - Error Responses}
203
- */
204
- declare class ResponseError extends Error {
205
- readonly name: string;
206
- response: StandardResponse;
207
- constructor(options: ResponseErrorOptions);
208
- }
209
- interface MalformedResponseErrorOptions extends ResponseErrorOptions {
210
- /**
211
- * @default inferred from the response body or status
212
- */
213
- message?: string | undefined;
214
- }
215
- /**
216
- * Error thrown by links when a response does not follow the expected oRPC format,
217
- * for example when a proxy or gateway answers instead of your handler. Extends
218
- * `ResponseError`, so it carries the resolved response. Unless overridden via
219
- * `options.message`, the message is inferred from the response body or status.
220
- *
221
- * Unlike `ORPCError`, it reaches a handler's callers as a generic `INTERNAL_SERVER_ERROR`
222
- * when thrown from the handler, so an upstream's response is not sent to them.
223
- *
224
- * @see {@link https://orpc.dev/docs/rpc/link#malformed-responses | RPC Link - Malformed Responses}
225
- * @see {@link https://orpc.dev/docs/openapi/link#malformed-responses | OpenAPI Link - Malformed Responses}
226
- */
227
- declare class MalformedResponseError extends ResponseError {
228
- readonly name = "MalformedResponseError";
229
- constructor(options: MalformedResponseErrorOptions);
230
- }
231
-
232
- export { MalformedResponseError as M, ResponseError as R, ORPCError as h, COMMON_ERROR_STATUS_MAP as j };
233
- 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, 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, MalformedResponseErrorOptions as p, ORPCErrorOptions as q, ResponseErrorOptions as r };
@@ -1,233 +0,0 @@
1
- import { PromiseWithError, Registry, MaybeOptionalOptions } from '@orpc/shared';
2
- import { StandardResponse } from '@standard-server/core';
3
-
4
- interface ClientContext {
5
- [key: PropertyKey]: any;
6
- }
7
- interface ClientOptions<T extends ClientContext> {
8
- signal?: AbortSignal | undefined;
9
- lastEventId?: string | undefined;
10
- context: T;
11
- }
12
- type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
13
- context?: T | undefined;
14
- } : {
15
- context: T;
16
- });
17
- type ClientRest<TClientContext extends ClientContext, TInput> = object extends TClientContext ? undefined extends TInput ? [input?: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options?: FriendlyClientOptions<TClientContext>] : [input: TInput, options: FriendlyClientOptions<TClientContext>];
18
- interface Client<TClientContext extends ClientContext, TInput, TOutput, TError> {
19
- (...rest: ClientRest<TClientContext, TInput>): PromiseWithError<TOutput, TError>;
20
- }
21
- type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
22
- [k: string]: NestedClient<TClientContext>;
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
- */
30
- type InferClientContext<T extends AnyNestedClient> = T extends NestedClient<infer U> ? U : never;
31
- interface ClientLink<TClientContext extends ClientContext> {
32
- call: (path: string[], input: unknown, options: ClientOptions<TClientContext>) => Promise<unknown>;
33
- }
34
- /**
35
- * Recursively infers the **input types** from a client.
36
- *
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}
40
- */
41
- type InferClientInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U : {
42
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientInputs<T[K]> : never;
43
- };
44
- /**
45
- * Recursively infers the **body input types** from a client.
46
- *
47
- * If an endpoint's input includes `{ body: ... }`, only the `body` portion is extracted.
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}
51
- */
52
- type InferClientBodyInputs<T extends AnyNestedClient> = T extends Client<any, infer U, any, any> ? U extends {
53
- body: infer UBody;
54
- } ? UBody : U : {
55
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyInputs<T[K]> : never;
56
- };
57
- /**
58
- * Recursively infers the **output types** from a client.
59
- *
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}
63
- */
64
- type InferClientOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U : {
65
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientOutputs<T[K]> : never;
66
- };
67
- /**
68
- * Recursively infers the **body output types** from a client.
69
- *
70
- * If an endpoint's output includes `{ body: ... }`, only the `body` portion is extracted.
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}
74
- */
75
- type InferClientBodyOutputs<T extends AnyNestedClient> = T extends Client<any, any, infer U, any> ? U extends {
76
- body: infer UBody;
77
- } ? UBody : U : {
78
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientBodyOutputs<T[K]> : never;
79
- };
80
- /**
81
- * Recursively infers the **error types** from a client when you use [type-safe errors](https://orpc.dev/docs/error-handling#typesafe-errors).
82
- *
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}
86
- */
87
- type InferClientErrors<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
88
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientErrors<T[K]> : never;
89
- };
90
- /**
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).
92
- *
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}
96
- */
97
- type InferClientError<T extends AnyNestedClient> = T extends Client<any, any, any, infer U> ? U : {
98
- [K in keyof T]: T[K] extends AnyNestedClient ? InferClientError<T[K]> : never;
99
- }[keyof T];
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
- */
108
- declare const COMMON_ERROR_STATUS_MAP: {
109
- BAD_REQUEST: number;
110
- UNAUTHORIZED: number;
111
- PAYMENT_REQUIRED: number;
112
- FORBIDDEN: number;
113
- NOT_FOUND: number;
114
- METHOD_NOT_SUPPORTED: number;
115
- NOT_ACCEPTABLE: number;
116
- TIMEOUT: number;
117
- CONFLICT: number;
118
- GONE: number;
119
- LENGTH_REQUIRED: number;
120
- PRECONDITION_FAILED: number;
121
- PAYLOAD_TOO_LARGE: number;
122
- UNSUPPORTED_MEDIA_TYPE: number;
123
- UNPROCESSABLE_CONTENT: number;
124
- PRECONDITION_REQUIRED: number;
125
- TOO_MANY_REQUESTS: number;
126
- CLIENT_CLOSED_REQUEST: number;
127
- INTERNAL_SERVER_ERROR: number;
128
- NOT_IMPLEMENTED: number;
129
- BAD_GATEWAY: number;
130
- SERVICE_UNAVAILABLE: number;
131
- GATEWAY_TIMEOUT: number;
132
- };
133
- type ORPCErrorCode = Registry extends {
134
- ORPCErrorCode: infer T extends string;
135
- } ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {});
136
- type ORPCErrorOptions<TData> = ErrorOptions & {
137
- message?: string | undefined;
138
- } & (undefined extends TData ? {
139
- data?: TData;
140
- } : {
141
- data: TData;
142
- });
143
- /**
144
- * Typed error carrying a `code`, a `message`, and optional `data`.
145
- * Throw it from handlers or middleware to produce typed error responses on the client.
146
- *
147
- * @see {@link https://orpc.dev/docs/error-handling#orpcerror-class | Error Handling - ORPCError Class}
148
- */
149
- declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
150
- /**
151
- * @remarks
152
- * **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish
153
- * an `ORPCError` instance from plain objects with a similar structure.
154
- */
155
- readonly name: "ORPCError" & {
156
- __branch: "ORPCError";
157
- };
158
- /**
159
- * Indicates whether the error matches a definition in the procedure's `.errors` map,
160
- * which makes its type inferable on the client.
161
- */
162
- readonly defined: boolean;
163
- code: TCode;
164
- data: TData;
165
- constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
166
- toJSON(): ORPCErrorJSON<TCode, TData>;
167
- /**
168
- * Workaround for Next.js where different contexts use separate
169
- * dependency graphs, causing multiple ORPCError constructors existing and breaking
170
- * `instanceof` checks across contexts.
171
- *
172
- * This is particularly problematic with "Optimized SSR", where orpc-client
173
- * executes in one context but is invoked from another. When an error is thrown
174
- * in the execution context, `instanceof ORPCError` checks fail in the
175
- * invocation context due to separate class constructors.
176
- *
177
- * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
178
- */
179
- static [Symbol.hasInstance](instance: unknown): boolean;
180
- }
181
- interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, 'code' | 'message' | 'data'> {
182
- /**
183
- * remove readonly
184
- */
185
- defined: boolean;
186
- }
187
- type AnyORPCError = ORPCError<any, any>;
188
- type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
189
- interface ResponseErrorOptions extends ErrorOptions {
190
- /**
191
- * @default inferred from the response status
192
- */
193
- message?: string | undefined;
194
- response: StandardResponse;
195
- }
196
- /**
197
- * Error carrying the resolved response a link received. Links set it as the `cause`
198
- * of an `ORPCError` decoded from an error response, so details that are not part
199
- * of the error itself, such as its status or headers, stay available.
200
- *
201
- * @see {@link https://orpc.dev/docs/rpc/link#error-responses | RPC Link - Error Responses}
202
- * @see {@link https://orpc.dev/docs/openapi/link#error-responses | OpenAPI Link - Error Responses}
203
- */
204
- declare class ResponseError extends Error {
205
- readonly name: string;
206
- response: StandardResponse;
207
- constructor(options: ResponseErrorOptions);
208
- }
209
- interface MalformedResponseErrorOptions extends ResponseErrorOptions {
210
- /**
211
- * @default inferred from the response body or status
212
- */
213
- message?: string | undefined;
214
- }
215
- /**
216
- * Error thrown by links when a response does not follow the expected oRPC format,
217
- * for example when a proxy or gateway answers instead of your handler. Extends
218
- * `ResponseError`, so it carries the resolved response. Unless overridden via
219
- * `options.message`, the message is inferred from the response body or status.
220
- *
221
- * Unlike `ORPCError`, it reaches a handler's callers as a generic `INTERNAL_SERVER_ERROR`
222
- * when thrown from the handler, so an upstream's response is not sent to them.
223
- *
224
- * @see {@link https://orpc.dev/docs/rpc/link#malformed-responses | RPC Link - Malformed Responses}
225
- * @see {@link https://orpc.dev/docs/openapi/link#malformed-responses | OpenAPI Link - Malformed Responses}
226
- */
227
- declare class MalformedResponseError extends ResponseError {
228
- readonly name = "MalformedResponseError";
229
- constructor(options: MalformedResponseErrorOptions);
230
- }
231
-
232
- export { MalformedResponseError as M, ResponseError as R, ORPCError as h, COMMON_ERROR_STATUS_MAP as j };
233
- 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, 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, MalformedResponseErrorOptions as p, ORPCErrorOptions as q, ResponseErrorOptions as r };
@@ -1,172 +0,0 @@
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 { M as MalformedResponseError, R as ResponseError } from './client.LF04eOvL.mjs';
5
- import { R as RPCSerializer, i as isORPCErrorJson, c as createORPCErrorFromJson } from './client._wG5INmC.mjs';
6
-
7
- class CompositeStandardLinkPlugin {
8
- name = "~composite";
9
- plugins;
10
- constructor(plugins = []) {
11
- this.plugins = sortPlugins(plugins);
12
- }
13
- init(options) {
14
- for (const plugin of this.plugins) {
15
- if (plugin.init) {
16
- options = plugin.init(options);
17
- }
18
- }
19
- return options;
20
- }
21
- }
22
-
23
- class StandardLink {
24
- constructor(codec, transport, options = {}) {
25
- this.codec = codec;
26
- this.transport = transport;
27
- options = new CompositeStandardLinkPlugin(options.plugins).init(options);
28
- this.interceptors = options.interceptors;
29
- this.transportInterceptors = options.transportInterceptors;
30
- }
31
- interceptors;
32
- transportInterceptors;
33
- /**
34
- * @throws ORPCError, MalformedResponseError, transport-level errors (network failures, timeouts, etc.)
35
- */
36
- call(path, input, options) {
37
- return runWithSpan(`${ORPC_NAME}.${path.join("/")}`, (span) => {
38
- span?.setAttribute("rpc.system", ORPC_NAME);
39
- span?.setAttribute("rpc.method", path.join("."));
40
- if (getTracer() && isAsyncIteratorObject(input)) {
41
- input = override(input, traceAsyncIterator("consume_async_iterator_object_input", input));
42
- } else if (getTracer() && input instanceof ReadableStream) {
43
- input = override(input, traceReadableStream("consume_octet_stream_input", input));
44
- }
45
- return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
46
- const tracer = getTracer();
47
- const activeSpan = tracer?.getActiveSpan() ?? span;
48
- let request = await runWithSpan(
49
- { name: "encode_input", parent: activeSpan },
50
- () => this.codec.encodeInput(input2, path2, options2)
51
- );
52
- if (activeSpan && tracer?.inject) {
53
- const headers = { ...request.headers };
54
- tracer.inject(activeSpan, headers);
55
- request = { ...request, headers };
56
- }
57
- const response = await intercept(
58
- this.transportInterceptors,
59
- { ...options2, path: path2, request },
60
- ({ path: path3, request: request2, ...options3 }) => {
61
- const activeTransportSpan = tracer?.getActiveSpan() ?? activeSpan;
62
- return runWithSpan(
63
- { name: "send_request", parent: activeTransportSpan },
64
- () => this.transport.send(request2, path3, options3)
65
- );
66
- }
67
- );
68
- const decodedResult = await runWithSpan(
69
- { name: "decode_response", parent: activeSpan },
70
- () => this.codec.decodeResponse(response, path2, options2)
71
- );
72
- if (decodedResult.kind === "error") {
73
- throw decodedResult.error;
74
- }
75
- const output = decodedResult.output;
76
- if (getTracer() && isAsyncIteratorObject(output)) {
77
- return override(output, traceAsyncIterator("consume_async_iterator_object_output", output));
78
- } else if (getTracer() && output instanceof ReadableStream) {
79
- return override(output, traceReadableStream("consume_octet_stream_output", output));
80
- }
81
- return output;
82
- });
83
- });
84
- }
85
- }
86
-
87
- const END_SLASH_REGEX = /\/$/;
88
- class RPCLinkCodec {
89
- baseUrl;
90
- maxUrlLength;
91
- fallbackMethod;
92
- expectedMethod;
93
- headers;
94
- serializer;
95
- constructor(options) {
96
- this.baseUrl = options.url ?? "/";
97
- this.maxUrlLength = options.maxUrlLength ?? 2083;
98
- this.fallbackMethod = options.fallbackMethod ?? "POST";
99
- this.expectedMethod = options.method ?? this.fallbackMethod;
100
- this.headers = options.headers ?? {};
101
- this.serializer = options.serializer ?? new RPCSerializer();
102
- }
103
- async encodeInput(input, path, options) {
104
- let headers = toResolvedStandardHeaders(await value(this.headers, options, path, input));
105
- if (options.lastEventId !== void 0) {
106
- headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
107
- }
108
- const expectedMethod = await value(this.expectedMethod, options, path, input);
109
- const baseUrl = await value(this.baseUrl, options, path, input);
110
- const [pathname, search, hash] = parseStandardUrl(baseUrl);
111
- const newPathname = `${pathname.replace(END_SLASH_REGEX, "")}${pathToHttpPath(path)}`;
112
- const serialized = this.serializer.serialize(input);
113
- if (expectedMethod === "GET" && !(serialized instanceof Blob) && !(serialized instanceof ReadableStream) && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
114
- const maxUrlLength = await value(this.maxUrlLength, options, path, input);
115
- const mergedSearch = new URLSearchParams(search);
116
- mergedSearch.append("data", stringifyJSON(serialized) ?? "");
117
- const url2 = `${newPathname}?${mergedSearch}${hash ?? ""}`;
118
- if (url2.length <= maxUrlLength) {
119
- return {
120
- body: void 0,
121
- method: expectedMethod,
122
- headers,
123
- url: url2,
124
- signal: options.signal
125
- };
126
- }
127
- }
128
- const url = `${newPathname}${search ?? ""}${hash ?? ""}`;
129
- return {
130
- url,
131
- method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod,
132
- headers,
133
- body: serialized,
134
- signal: options.signal
135
- };
136
- }
137
- async decodeResponse(response) {
138
- const isOk = response.status < 400;
139
- const body = await response.resolveBody();
140
- const deserialized = await (async () => {
141
- try {
142
- return this.serializer.deserialize(body);
143
- } catch (cause) {
144
- throw new MalformedResponseError({
145
- message: "Invalid RPC response format.",
146
- response: { status: response.status, headers: response.headers, body },
147
- cause
148
- });
149
- }
150
- })();
151
- if (!isOk) {
152
- if (isORPCErrorJson(deserialized)) {
153
- return {
154
- kind: "error",
155
- error: createORPCErrorFromJson(deserialized, {
156
- cause: new ResponseError({ response: { status: response.status, headers: response.headers, body } })
157
- })
158
- };
159
- }
160
- throw new MalformedResponseError({ response: { headers: response.headers, status: response.status, body } });
161
- }
162
- return { kind: "output", output: deserialized };
163
- }
164
- }
165
- function toResolvedStandardHeaders(headers) {
166
- if (typeof headers.forEach === "function") {
167
- return toStandardHeaders(headers);
168
- }
169
- return headers;
170
- }
171
-
172
- export { RPCLinkCodec as R, StandardLink as S };