@orpc/client 2.0.0-beta.44 → 2.0.0-beta.45
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.
- package/README.md +55 -48
- package/dist/adapters/fetch/index.d.mts +3 -3
- package/dist/adapters/fetch/index.d.ts +3 -3
- package/dist/adapters/fetch/index.mjs +3 -3
- package/dist/adapters/message-port/index.d.mts +2 -2
- package/dist/adapters/message-port/index.d.ts +2 -2
- package/dist/adapters/message-port/index.mjs +3 -3
- package/dist/adapters/standard/index.d.mts +8 -8
- package/dist/adapters/standard/index.d.ts +8 -8
- package/dist/adapters/standard/index.mjs +3 -3
- package/dist/adapters/websocket/index.d.mts +9 -9
- package/dist/adapters/websocket/index.d.ts +9 -9
- package/dist/adapters/websocket/index.mjs +3 -3
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.mjs +3 -3
- package/dist/plugins/index.d.mts +51 -38
- package/dist/plugins/index.d.ts +51 -38
- package/dist/plugins/index.mjs +15 -8
- package/dist/shared/{client.DZHZRyR6.d.mts → client.BoHJeq15.d.mts} +30 -12
- package/dist/shared/{client.DZHZRyR6.d.ts → client.BoHJeq15.d.ts} +30 -12
- package/dist/shared/{client.B7P_ugvl.mjs → client.Bpyj1NM2.mjs} +8 -3
- package/dist/shared/{client.BzAY7ZC2.d.mts → client.CkwtFnrc.d.mts} +4 -4
- package/dist/shared/{client.CHH2CNMj.d.ts → client.DBDKICdk.d.ts} +4 -4
- package/dist/shared/{client.BPa_Mmuh.d.mts → client.DqIWeNhQ.d.mts} +7 -8
- package/dist/shared/{client.BPa_Mmuh.d.ts → client.DqIWeNhQ.d.ts} +7 -8
- package/dist/shared/{client.CrHurHrq.mjs → client.LF04eOvL.mjs} +10 -4
- package/dist/shared/{client.BLfXUpyF.mjs → client._wG5INmC.mjs} +16 -17
- package/package.json +6 -6
package/dist/plugins/index.mjs
CHANGED
|
@@ -2,8 +2,10 @@ import { toArray, value, splitInHalf, promiseWithResolvers, safeEncodeURICompone
|
|
|
2
2
|
import { parseStandardUrl, flattenStandardHeader, generateContentDisposition, getEventMeta } from '@standard-server/core';
|
|
3
3
|
import { ClientPeer, isServerPeerSendMessage, decodePeerMessage } from '@standard-server/peer';
|
|
4
4
|
import { toFetchHeaders, toStandardBody } from '@standard-server/fetch';
|
|
5
|
-
import { C as COMMON_ERROR_STATUS_MAP } from '../shared/client.
|
|
5
|
+
import { O as ORPCError, R as ResponseError, C as COMMON_ERROR_STATUS_MAP } from '../shared/client.LF04eOvL.mjs';
|
|
6
6
|
|
|
7
|
+
const BATCH_HEADER = "orpc-batch";
|
|
8
|
+
const DEFAULT_BATCH_MAX_SIZE = 10;
|
|
7
9
|
class BatchLinkPlugin {
|
|
8
10
|
name = "~batch";
|
|
9
11
|
groups;
|
|
@@ -11,7 +13,6 @@ class BatchLinkPlugin {
|
|
|
11
13
|
scope;
|
|
12
14
|
maxSize;
|
|
13
15
|
wait;
|
|
14
|
-
mode;
|
|
15
16
|
batchUrl;
|
|
16
17
|
maxUrlLength;
|
|
17
18
|
batchHeaders;
|
|
@@ -22,9 +23,8 @@ class BatchLinkPlugin {
|
|
|
22
23
|
this.groups = options.groups;
|
|
23
24
|
this.filter = options.filter ?? (() => true);
|
|
24
25
|
this.scope = options.scope ?? (() => void 0);
|
|
25
|
-
this.maxSize = options.maxSize ??
|
|
26
|
+
this.maxSize = options.maxSize ?? DEFAULT_BATCH_MAX_SIZE;
|
|
26
27
|
this.wait = options.wait ?? 0;
|
|
27
|
-
this.mode = options.mode ?? "streaming";
|
|
28
28
|
this.batchUrl = options.url ?? ((options2) => {
|
|
29
29
|
const [pathname] = parseStandardUrl(options2[0].request.url);
|
|
30
30
|
return `${pathname}/__batch__`;
|
|
@@ -141,7 +141,6 @@ class BatchLinkPlugin {
|
|
|
141
141
|
}
|
|
142
142
|
const url = await value(this.batchUrl, subOptionsList);
|
|
143
143
|
const headers = await value(this.batchHeaders, subOptionsList);
|
|
144
|
-
const mode = value(this.mode, subOptionsList);
|
|
145
144
|
let suppressErrorFromCurrentBatch = false;
|
|
146
145
|
const controller = new AbortController();
|
|
147
146
|
const pendingMessages = [];
|
|
@@ -185,7 +184,7 @@ class BatchLinkPlugin {
|
|
|
185
184
|
const request = {
|
|
186
185
|
url,
|
|
187
186
|
method,
|
|
188
|
-
headers: { ...headers, "
|
|
187
|
+
headers: { ...headers, [BATCH_HEADER]: "1" },
|
|
189
188
|
signal: controller.signal
|
|
190
189
|
};
|
|
191
190
|
if (method === "GET") {
|
|
@@ -745,6 +744,14 @@ function parseContentEncodings(header) {
|
|
|
745
744
|
return header.split(",").map((part) => part.trim().toLowerCase());
|
|
746
745
|
}
|
|
747
746
|
|
|
747
|
+
function isRetryableError(error) {
|
|
748
|
+
const responseError = error instanceof ORPCError ? error.cause : error;
|
|
749
|
+
if (!(responseError instanceof ResponseError)) {
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
const { status } = responseError.response;
|
|
753
|
+
return status < 400 || status >= 500 || status === COMMON_ERROR_STATUS_MAP.TIMEOUT || status === COMMON_ERROR_STATUS_MAP.TOO_MANY_REQUESTS;
|
|
754
|
+
}
|
|
748
755
|
class RetryLinkPlugin {
|
|
749
756
|
defaultRetry;
|
|
750
757
|
defaultRetryDelay;
|
|
@@ -754,7 +761,7 @@ class RetryLinkPlugin {
|
|
|
754
761
|
constructor(options = {}) {
|
|
755
762
|
this.defaultRetry = options.default?.retry ?? 0;
|
|
756
763
|
this.defaultRetryDelay = options.default?.retryDelay ?? ((o) => o.lastEventRetry ?? 2e3);
|
|
757
|
-
this.defaultShouldRetry = options.default?.shouldRetry ??
|
|
764
|
+
this.defaultShouldRetry = options.default?.shouldRetry ?? ((o) => isRetryableError(o.error));
|
|
758
765
|
this.defaultOnRetry = options.default?.onRetry;
|
|
759
766
|
}
|
|
760
767
|
init(options) {
|
|
@@ -961,4 +968,4 @@ class TimeoutLinkPlugin {
|
|
|
961
968
|
}
|
|
962
969
|
}
|
|
963
970
|
|
|
964
|
-
export { BatchLinkPlugin, RetryLinkPlugin as ClientRetryPlugin, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin };
|
|
971
|
+
export { BATCH_HEADER, BatchLinkPlugin, RetryLinkPlugin as ClientRetryPlugin, DEFAULT_BATCH_MAX_SIZE, DedupeLinkPlugin, DedupeLinkPlugin as DedupeRequestsPlugin, RequestCompressionLinkPlugin, ResponseCompressionLinkPlugin, RetryAfterLinkPlugin, RetryAfterLinkPlugin as RetryAfterPlugin, RetryLinkPlugin, TimeoutLinkPlugin, isRetryableError };
|
|
@@ -10,7 +10,7 @@ interface ClientOptions<T extends ClientContext> {
|
|
|
10
10
|
context: T;
|
|
11
11
|
}
|
|
12
12
|
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
|
|
13
|
-
context?: T;
|
|
13
|
+
context?: T | undefined;
|
|
14
14
|
} : {
|
|
15
15
|
context: T;
|
|
16
16
|
});
|
|
@@ -134,7 +134,7 @@ type ORPCErrorCode = Registry extends {
|
|
|
134
134
|
ORPCErrorCode: infer T extends string;
|
|
135
135
|
} ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {});
|
|
136
136
|
type ORPCErrorOptions<TData> = ErrorOptions & {
|
|
137
|
-
message?: string;
|
|
137
|
+
message?: string | undefined;
|
|
138
138
|
} & (undefined extends TData ? {
|
|
139
139
|
data?: TData;
|
|
140
140
|
} : {
|
|
@@ -186,18 +186,37 @@ interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCod
|
|
|
186
186
|
}
|
|
187
187
|
type AnyORPCError = ORPCError<any, any>;
|
|
188
188
|
type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
|
|
189
|
-
interface
|
|
189
|
+
interface ResponseErrorOptions extends ErrorOptions {
|
|
190
190
|
/**
|
|
191
|
-
* @default inferred from the response
|
|
191
|
+
* @default inferred from the response status
|
|
192
192
|
*/
|
|
193
|
-
message?: string;
|
|
193
|
+
message?: string | undefined;
|
|
194
194
|
response: StandardResponse;
|
|
195
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
|
+
}
|
|
196
215
|
/**
|
|
197
216
|
* Error thrown by links when a response does not follow the expected oRPC format,
|
|
198
|
-
* for example when a proxy or gateway answers instead of your handler.
|
|
199
|
-
* resolved response. Unless overridden via
|
|
200
|
-
* inferred from the response body or status.
|
|
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.
|
|
201
220
|
*
|
|
202
221
|
* Unlike `ORPCError`, it reaches a handler's callers as a generic `INTERNAL_SERVER_ERROR`
|
|
203
222
|
* when thrown from the handler, so an upstream's response is not sent to them.
|
|
@@ -205,11 +224,10 @@ interface MalformedResponseErrorOptions extends ErrorOptions {
|
|
|
205
224
|
* @see {@link https://orpc.dev/docs/rpc/link#malformed-responses | RPC Link - Malformed Responses}
|
|
206
225
|
* @see {@link https://orpc.dev/docs/openapi/link#malformed-responses | OpenAPI Link - Malformed Responses}
|
|
207
226
|
*/
|
|
208
|
-
declare class MalformedResponseError extends
|
|
227
|
+
declare class MalformedResponseError extends ResponseError {
|
|
209
228
|
readonly name = "MalformedResponseError";
|
|
210
|
-
response: StandardResponse;
|
|
211
229
|
constructor(options: MalformedResponseErrorOptions);
|
|
212
230
|
}
|
|
213
231
|
|
|
214
|
-
export { MalformedResponseError as M, ORPCError as h, COMMON_ERROR_STATUS_MAP as j };
|
|
215
|
-
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 };
|
|
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 };
|
|
@@ -10,7 +10,7 @@ interface ClientOptions<T extends ClientContext> {
|
|
|
10
10
|
context: T;
|
|
11
11
|
}
|
|
12
12
|
type FriendlyClientOptions<T extends ClientContext> = Omit<ClientOptions<T>, 'context'> & (object extends T ? {
|
|
13
|
-
context?: T;
|
|
13
|
+
context?: T | undefined;
|
|
14
14
|
} : {
|
|
15
15
|
context: T;
|
|
16
16
|
});
|
|
@@ -134,7 +134,7 @@ type ORPCErrorCode = Registry extends {
|
|
|
134
134
|
ORPCErrorCode: infer T extends string;
|
|
135
135
|
} ? T : (keyof typeof COMMON_ERROR_STATUS_MAP) | (string & {});
|
|
136
136
|
type ORPCErrorOptions<TData> = ErrorOptions & {
|
|
137
|
-
message?: string;
|
|
137
|
+
message?: string | undefined;
|
|
138
138
|
} & (undefined extends TData ? {
|
|
139
139
|
data?: TData;
|
|
140
140
|
} : {
|
|
@@ -186,18 +186,37 @@ interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCod
|
|
|
186
186
|
}
|
|
187
187
|
type AnyORPCError = ORPCError<any, any>;
|
|
188
188
|
type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
|
|
189
|
-
interface
|
|
189
|
+
interface ResponseErrorOptions extends ErrorOptions {
|
|
190
190
|
/**
|
|
191
|
-
* @default inferred from the response
|
|
191
|
+
* @default inferred from the response status
|
|
192
192
|
*/
|
|
193
|
-
message?: string;
|
|
193
|
+
message?: string | undefined;
|
|
194
194
|
response: StandardResponse;
|
|
195
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
|
+
}
|
|
196
215
|
/**
|
|
197
216
|
* Error thrown by links when a response does not follow the expected oRPC format,
|
|
198
|
-
* for example when a proxy or gateway answers instead of your handler.
|
|
199
|
-
* resolved response. Unless overridden via
|
|
200
|
-
* inferred from the response body or status.
|
|
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.
|
|
201
220
|
*
|
|
202
221
|
* Unlike `ORPCError`, it reaches a handler's callers as a generic `INTERNAL_SERVER_ERROR`
|
|
203
222
|
* when thrown from the handler, so an upstream's response is not sent to them.
|
|
@@ -205,11 +224,10 @@ interface MalformedResponseErrorOptions extends ErrorOptions {
|
|
|
205
224
|
* @see {@link https://orpc.dev/docs/rpc/link#malformed-responses | RPC Link - Malformed Responses}
|
|
206
225
|
* @see {@link https://orpc.dev/docs/openapi/link#malformed-responses | OpenAPI Link - Malformed Responses}
|
|
207
226
|
*/
|
|
208
|
-
declare class MalformedResponseError extends
|
|
227
|
+
declare class MalformedResponseError extends ResponseError {
|
|
209
228
|
readonly name = "MalformedResponseError";
|
|
210
|
-
response: StandardResponse;
|
|
211
229
|
constructor(options: MalformedResponseErrorOptions);
|
|
212
230
|
}
|
|
213
231
|
|
|
214
|
-
export { MalformedResponseError as M, ORPCError as h, COMMON_ERROR_STATUS_MAP as j };
|
|
215
|
-
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 };
|
|
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,8 +1,8 @@
|
|
|
1
1
|
import { sortPlugins, runWithSpan, ORPC_NAME, getTracer, isAsyncIteratorObject, override, traceAsyncIterator, traceReadableStream, intercept, value, pathToHttpPath, stringifyJSON } from '@orpc/shared';
|
|
2
2
|
import { mergeStandardHeaders, parseStandardUrl } from '@standard-server/core';
|
|
3
3
|
import { toStandardHeaders } from '@standard-server/fetch';
|
|
4
|
-
import { M as MalformedResponseError } from './client.
|
|
5
|
-
import { R as RPCSerializer, i as isORPCErrorJson, c as createORPCErrorFromJson } from './client.
|
|
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
6
|
|
|
7
7
|
class CompositeStandardLinkPlugin {
|
|
8
8
|
name = "~composite";
|
|
@@ -150,7 +150,12 @@ class RPCLinkCodec {
|
|
|
150
150
|
})();
|
|
151
151
|
if (!isOk) {
|
|
152
152
|
if (isORPCErrorJson(deserialized)) {
|
|
153
|
-
return {
|
|
153
|
+
return {
|
|
154
|
+
kind: "error",
|
|
155
|
+
error: createORPCErrorFromJson(deserialized, {
|
|
156
|
+
cause: new ResponseError({ response: { status: response.status, headers: response.headers, body } })
|
|
157
|
+
})
|
|
158
|
+
};
|
|
154
159
|
}
|
|
155
160
|
throw new MalformedResponseError({ response: { headers: response.headers, status: response.status, body } });
|
|
156
161
|
}
|
|
@@ -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.
|
|
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';
|
|
@@ -72,13 +72,13 @@ interface StandardLinkOptions<T extends ClientContext> {
|
|
|
72
72
|
* Interceptors that execute around the entire call, including transport and codec.
|
|
73
73
|
* Useful for error handling, logging, metrics, ...
|
|
74
74
|
*/
|
|
75
|
-
interceptors?: StandardLinkInterceptor<T>[];
|
|
75
|
+
interceptors?: StandardLinkInterceptor<T>[] | undefined;
|
|
76
76
|
/**
|
|
77
77
|
* Interceptors that execute around the transport layer, after encoding and before decoding.
|
|
78
78
|
* Useful for modifying the request or response, adding transport-level logging, ...
|
|
79
79
|
*/
|
|
80
|
-
transportInterceptors?: StandardLinkTransportInterceptor<T>[];
|
|
81
|
-
plugins?: StandardLinkPlugin<T>[];
|
|
80
|
+
transportInterceptors?: StandardLinkTransportInterceptor<T>[] | undefined;
|
|
81
|
+
plugins?: StandardLinkPlugin<T>[] | undefined;
|
|
82
82
|
}
|
|
83
83
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
84
84
|
private readonly codec;
|
|
@@ -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.
|
|
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';
|
|
@@ -72,13 +72,13 @@ interface StandardLinkOptions<T extends ClientContext> {
|
|
|
72
72
|
* Interceptors that execute around the entire call, including transport and codec.
|
|
73
73
|
* Useful for error handling, logging, metrics, ...
|
|
74
74
|
*/
|
|
75
|
-
interceptors?: StandardLinkInterceptor<T>[];
|
|
75
|
+
interceptors?: StandardLinkInterceptor<T>[] | undefined;
|
|
76
76
|
/**
|
|
77
77
|
* Interceptors that execute around the transport layer, after encoding and before decoding.
|
|
78
78
|
* Useful for modifying the request or response, adding transport-level logging, ...
|
|
79
79
|
*/
|
|
80
|
-
transportInterceptors?: StandardLinkTransportInterceptor<T>[];
|
|
81
|
-
plugins?: StandardLinkPlugin<T>[];
|
|
80
|
+
transportInterceptors?: StandardLinkTransportInterceptor<T>[] | undefined;
|
|
81
|
+
plugins?: StandardLinkPlugin<T>[] | undefined;
|
|
82
82
|
}
|
|
83
83
|
declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
|
|
84
84
|
private readonly codec;
|
|
@@ -28,7 +28,7 @@ interface RPCJsonSerializerHandler {
|
|
|
28
28
|
*
|
|
29
29
|
* @default false
|
|
30
30
|
*/
|
|
31
|
-
isTerminal?: boolean;
|
|
31
|
+
isTerminal?: boolean | undefined;
|
|
32
32
|
}
|
|
33
33
|
interface RPCJsonSerializerOptions {
|
|
34
34
|
/**
|
|
@@ -88,13 +88,13 @@ declare class RPCJsonSerializer {
|
|
|
88
88
|
private readonly handlerEntries;
|
|
89
89
|
private readonly omitUndefinedProperties;
|
|
90
90
|
constructor(options?: RPCJsonSerializerOptions);
|
|
91
|
-
|
|
91
|
+
serializeJson(data: unknown): RPCJsonSerialization;
|
|
92
92
|
/**
|
|
93
93
|
* `segments` is a shared mutable stack (push/pop while walking),
|
|
94
94
|
* so it must be copied before being stored in `meta` or `maps`.
|
|
95
95
|
*/
|
|
96
96
|
private serializeValue;
|
|
97
|
-
|
|
97
|
+
deserializeJson(serialized: RPCJsonSerialization): unknown;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
interface RPCSerializerSerializeOptions {
|
|
@@ -104,7 +104,7 @@ interface RPCSerializerSerializeOptions {
|
|
|
104
104
|
*
|
|
105
105
|
* @default true
|
|
106
106
|
*/
|
|
107
|
-
useFormDataForBlobFields?: boolean;
|
|
107
|
+
useFormDataForBlobFields?: boolean | undefined;
|
|
108
108
|
}
|
|
109
109
|
interface RPCSerializerOptions extends RPCJsonSerializerOptions {
|
|
110
110
|
/**
|
|
@@ -118,14 +118,13 @@ interface RPCSerializerOptions extends RPCJsonSerializerOptions {
|
|
|
118
118
|
*
|
|
119
119
|
* @see {@link https://orpc.dev/docs/rpc/serializer | RPC Serializer}
|
|
120
120
|
*/
|
|
121
|
-
declare class RPCSerializer {
|
|
122
|
-
private readonly jsonSerializer;
|
|
121
|
+
declare class RPCSerializer extends RPCJsonSerializer {
|
|
123
122
|
private readonly defaultSerializeOptions;
|
|
124
123
|
constructor(options?: RPCSerializerOptions);
|
|
125
124
|
serialize(data: unknown, options?: RPCSerializerSerializeOptions): StandardBody;
|
|
126
|
-
private
|
|
125
|
+
private serializePayload;
|
|
127
126
|
deserialize(data: StandardBody): unknown;
|
|
128
|
-
private
|
|
127
|
+
private deserializePayload;
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
export { RPCJsonSerializer as b, RPCSerializer as e };
|
|
@@ -28,7 +28,7 @@ interface RPCJsonSerializerHandler {
|
|
|
28
28
|
*
|
|
29
29
|
* @default false
|
|
30
30
|
*/
|
|
31
|
-
isTerminal?: boolean;
|
|
31
|
+
isTerminal?: boolean | undefined;
|
|
32
32
|
}
|
|
33
33
|
interface RPCJsonSerializerOptions {
|
|
34
34
|
/**
|
|
@@ -88,13 +88,13 @@ declare class RPCJsonSerializer {
|
|
|
88
88
|
private readonly handlerEntries;
|
|
89
89
|
private readonly omitUndefinedProperties;
|
|
90
90
|
constructor(options?: RPCJsonSerializerOptions);
|
|
91
|
-
|
|
91
|
+
serializeJson(data: unknown): RPCJsonSerialization;
|
|
92
92
|
/**
|
|
93
93
|
* `segments` is a shared mutable stack (push/pop while walking),
|
|
94
94
|
* so it must be copied before being stored in `meta` or `maps`.
|
|
95
95
|
*/
|
|
96
96
|
private serializeValue;
|
|
97
|
-
|
|
97
|
+
deserializeJson(serialized: RPCJsonSerialization): unknown;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
interface RPCSerializerSerializeOptions {
|
|
@@ -104,7 +104,7 @@ interface RPCSerializerSerializeOptions {
|
|
|
104
104
|
*
|
|
105
105
|
* @default true
|
|
106
106
|
*/
|
|
107
|
-
useFormDataForBlobFields?: boolean;
|
|
107
|
+
useFormDataForBlobFields?: boolean | undefined;
|
|
108
108
|
}
|
|
109
109
|
interface RPCSerializerOptions extends RPCJsonSerializerOptions {
|
|
110
110
|
/**
|
|
@@ -118,14 +118,13 @@ interface RPCSerializerOptions extends RPCJsonSerializerOptions {
|
|
|
118
118
|
*
|
|
119
119
|
* @see {@link https://orpc.dev/docs/rpc/serializer | RPC Serializer}
|
|
120
120
|
*/
|
|
121
|
-
declare class RPCSerializer {
|
|
122
|
-
private readonly jsonSerializer;
|
|
121
|
+
declare class RPCSerializer extends RPCJsonSerializer {
|
|
123
122
|
private readonly defaultSerializeOptions;
|
|
124
123
|
constructor(options?: RPCSerializerOptions);
|
|
125
124
|
serialize(data: unknown, options?: RPCSerializerSerializeOptions): StandardBody;
|
|
126
|
-
private
|
|
125
|
+
private serializePayload;
|
|
127
126
|
deserialize(data: StandardBody): unknown;
|
|
128
|
-
private
|
|
127
|
+
private deserializePayload;
|
|
129
128
|
}
|
|
130
129
|
|
|
131
130
|
export { RPCJsonSerializer as b, RPCSerializer as e };
|
|
@@ -85,14 +85,20 @@ class ORPCError extends Error {
|
|
|
85
85
|
return false;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
class
|
|
89
|
-
name = "
|
|
88
|
+
class ResponseError extends Error {
|
|
89
|
+
name = "ResponseError";
|
|
90
90
|
response;
|
|
91
91
|
constructor(options) {
|
|
92
|
-
super(options.message ??
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
441
|
+
return { done: result.done, value: this.serializePayload(result.value, false) };
|
|
443
442
|
},
|
|
444
443
|
mapError: (e) => new ErrorEvent(
|
|
445
|
-
this.
|
|
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.
|
|
450
|
+
return this.serializePayload(data, useFormDataForBlobs);
|
|
452
451
|
}
|
|
453
|
-
|
|
454
|
-
const { json, meta, maps, blobs } = this.
|
|
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.
|
|
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.
|
|
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.
|
|
488
|
+
return this.deserializePayload(data);
|
|
490
489
|
}
|
|
491
|
-
|
|
490
|
+
deserializePayload(data) {
|
|
492
491
|
if (!(data instanceof FormData)) {
|
|
493
|
-
return this.
|
|
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.
|
|
501
|
+
return this.deserializeJson({ ...serialized, blobs });
|
|
503
502
|
}
|
|
504
503
|
}
|
|
505
504
|
|
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.
|
|
4
|
+
"version": "2.0.0-beta.45",
|
|
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.
|
|
67
|
-
"@standard-server/core": "~0.
|
|
68
|
-
"@standard-server/fetch": "~0.
|
|
69
|
-
"@standard-server/peer": "~0.
|
|
66
|
+
"@orpc/shared": "2.0.0-beta.45",
|
|
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.
|
|
74
|
+
"zod": "^4.6.7"
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"type:check": "tsc -b"
|