@orpc/client 0.0.0-next.c0ca4c7 → 0.0.0-next.c112960
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 +22 -22
- package/dist/adapters/fetch/index.d.mts +31 -11
- package/dist/adapters/fetch/index.d.ts +31 -11
- package/dist/adapters/fetch/index.mjs +26 -13
- package/dist/adapters/message-port/index.d.mts +59 -0
- package/dist/adapters/message-port/index.d.ts +59 -0
- package/dist/adapters/message-port/index.mjs +72 -0
- package/dist/adapters/standard/index.d.mts +6 -5
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.mjs +3 -2
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +46 -0
- package/dist/index.d.mts +104 -29
- package/dist/index.d.ts +104 -29
- package/dist/index.mjs +57 -11
- package/dist/plugins/index.d.mts +163 -25
- package/dist/plugins/index.d.ts +163 -25
- package/dist/plugins/index.mjs +332 -56
- package/dist/shared/{client.5813Ufvs.d.mts → client.BG98rYdO.d.ts} +21 -15
- package/dist/shared/{client.C0lT7w02.d.mts → client.BOYsZIRq.d.mts} +8 -9
- package/dist/shared/{client.C0lT7w02.d.ts → client.BOYsZIRq.d.ts} +8 -9
- package/dist/shared/{client.grRbC25r.d.ts → client.Bwgm6dgk.d.mts} +21 -15
- package/dist/shared/{client.DhAxdT4W.mjs → client.Bx-B_kf6.mjs} +90 -29
- package/dist/shared/{client.D-jrSuDb.d.ts → client.CVVVqf1Y.d.ts} +13 -25
- package/dist/shared/client.ZLgATkMs.mjs +208 -0
- package/dist/shared/{client.Bt94sjrK.d.mts → client._Y_enhib.d.mts} +13 -25
- package/package.json +16 -5
- package/dist/shared/client.jKEwIsRd.mjs +0 -175
|
@@ -1,36 +1,78 @@
|
|
|
1
|
-
import { toArray, intercept, isObject, value,
|
|
1
|
+
import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared';
|
|
2
2
|
import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server';
|
|
3
|
-
import { C as COMMON_ORPC_ERROR_DEFS,
|
|
3
|
+
import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, m as mapEventIterator, t as toORPCError } from './client.ZLgATkMs.mjs';
|
|
4
|
+
import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch';
|
|
4
5
|
|
|
5
|
-
class
|
|
6
|
+
class CompositeStandardLinkPlugin {
|
|
7
|
+
plugins;
|
|
8
|
+
constructor(plugins = []) {
|
|
9
|
+
this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
10
|
+
}
|
|
11
|
+
init(options) {
|
|
12
|
+
for (const plugin of this.plugins) {
|
|
13
|
+
plugin.init?.(options);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
6
16
|
}
|
|
17
|
+
|
|
7
18
|
class StandardLink {
|
|
8
19
|
constructor(codec, sender, options = {}) {
|
|
9
20
|
this.codec = codec;
|
|
10
21
|
this.sender = sender;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
22
|
+
const plugin = new CompositeStandardLinkPlugin(options.plugins);
|
|
23
|
+
plugin.init(options);
|
|
14
24
|
this.interceptors = toArray(options.interceptors);
|
|
15
25
|
this.clientInterceptors = toArray(options.clientInterceptors);
|
|
16
26
|
}
|
|
17
27
|
interceptors;
|
|
18
28
|
clientInterceptors;
|
|
19
29
|
call(path, input, options) {
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
return runWithSpan(
|
|
31
|
+
{ name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal },
|
|
32
|
+
(span) => {
|
|
33
|
+
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
34
|
+
span?.setAttribute("rpc.method", path.join("."));
|
|
35
|
+
if (isAsyncIteratorObject(input)) {
|
|
36
|
+
input = asyncIteratorWithSpan(
|
|
37
|
+
{ name: "consume_event_iterator_input", signal: options.signal },
|
|
38
|
+
input
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => {
|
|
42
|
+
const otelConfig = getGlobalOtelConfig();
|
|
43
|
+
let otelContext;
|
|
44
|
+
const currentSpan = otelConfig?.trace.getActiveSpan() ?? span;
|
|
45
|
+
if (currentSpan && otelConfig) {
|
|
46
|
+
otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan);
|
|
47
|
+
}
|
|
48
|
+
const request = await runWithSpan(
|
|
49
|
+
{ name: "encode_request", context: otelContext },
|
|
50
|
+
() => this.codec.encode(path2, input2, options2)
|
|
51
|
+
);
|
|
52
|
+
const response = await intercept(
|
|
53
|
+
this.clientInterceptors,
|
|
54
|
+
{ ...options2, input: input2, path: path2, request },
|
|
55
|
+
({ input: input3, path: path3, request: request2, ...options3 }) => {
|
|
56
|
+
return runWithSpan(
|
|
57
|
+
{ name: "send_request", signal: options3.signal, context: otelContext },
|
|
58
|
+
() => this.sender.call(request2, options3, path3, input3)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
const output = await runWithSpan(
|
|
63
|
+
{ name: "decode_response", context: otelContext },
|
|
64
|
+
() => this.codec.decode(response, options2, path2, input2)
|
|
65
|
+
);
|
|
66
|
+
if (isAsyncIteratorObject(output)) {
|
|
67
|
+
return asyncIteratorWithSpan(
|
|
68
|
+
{ name: "consume_event_iterator_output", signal: options2.signal },
|
|
69
|
+
output
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return output;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
31
75
|
);
|
|
32
|
-
const output = await this.codec.decode(response, options, path, input);
|
|
33
|
-
return output;
|
|
34
76
|
}
|
|
35
77
|
}
|
|
36
78
|
|
|
@@ -183,6 +225,12 @@ class StandardRPCJsonSerializer {
|
|
|
183
225
|
function toHttpPath(path) {
|
|
184
226
|
return `/${path.map(encodeURIComponent).join("/")}`;
|
|
185
227
|
}
|
|
228
|
+
function toStandardHeaders(headers) {
|
|
229
|
+
if (typeof headers.forEach === "function") {
|
|
230
|
+
return toStandardHeaders$1(headers);
|
|
231
|
+
}
|
|
232
|
+
return headers;
|
|
233
|
+
}
|
|
186
234
|
function getMalformedResponseErrorCode(status) {
|
|
187
235
|
return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE";
|
|
188
236
|
}
|
|
@@ -202,13 +250,14 @@ class StandardRPCLinkCodec {
|
|
|
202
250
|
expectedMethod;
|
|
203
251
|
headers;
|
|
204
252
|
async encode(path, input, options) {
|
|
205
|
-
|
|
206
|
-
let headers = await value(this.headers, options, path, input);
|
|
207
|
-
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
208
|
-
const url = new URL(`${baseUrl.toString().replace(/\/$/, "")}${toHttpPath(path)}`);
|
|
253
|
+
let headers = toStandardHeaders(await value(this.headers, options, path, input));
|
|
209
254
|
if (options.lastEventId !== void 0) {
|
|
210
255
|
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
211
256
|
}
|
|
257
|
+
const expectedMethod = await value(this.expectedMethod, options, path, input);
|
|
258
|
+
const baseUrl = await value(this.baseUrl, options, path, input);
|
|
259
|
+
const url = new URL(baseUrl);
|
|
260
|
+
url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`;
|
|
212
261
|
const serialized = this.serializer.serialize(input);
|
|
213
262
|
if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
|
214
263
|
const maxUrlLength = await value(this.maxUrlLength, options, path, input);
|
|
@@ -252,12 +301,12 @@ class StandardRPCLinkCodec {
|
|
|
252
301
|
}
|
|
253
302
|
})();
|
|
254
303
|
if (!isOk) {
|
|
255
|
-
if (
|
|
256
|
-
throw
|
|
304
|
+
if (isORPCErrorJson(deserialized)) {
|
|
305
|
+
throw createORPCErrorFromJson(deserialized);
|
|
257
306
|
}
|
|
258
307
|
throw new ORPCError(getMalformedResponseErrorCode(response.status), {
|
|
259
308
|
status: response.status,
|
|
260
|
-
data: deserialized
|
|
309
|
+
data: { ...response, body: deserialized }
|
|
261
310
|
});
|
|
262
311
|
}
|
|
263
312
|
return deserialized;
|
|
@@ -307,8 +356,8 @@ class StandardRPCSerializer {
|
|
|
307
356
|
return e;
|
|
308
357
|
}
|
|
309
358
|
const deserialized = this.#deserialize(e.data);
|
|
310
|
-
if (
|
|
311
|
-
return
|
|
359
|
+
if (isORPCErrorJson(deserialized)) {
|
|
360
|
+
return createORPCErrorFromJson(deserialized, { cause: e });
|
|
312
361
|
}
|
|
313
362
|
return new ErrorEvent({
|
|
314
363
|
data: deserialized,
|
|
@@ -320,6 +369,9 @@ class StandardRPCSerializer {
|
|
|
320
369
|
return this.#deserialize(data);
|
|
321
370
|
}
|
|
322
371
|
#deserialize(data) {
|
|
372
|
+
if (data === void 0) {
|
|
373
|
+
return void 0;
|
|
374
|
+
}
|
|
323
375
|
if (!(data instanceof FormData)) {
|
|
324
376
|
return this.jsonSerializer.deserialize(data.json, data.meta ?? []);
|
|
325
377
|
}
|
|
@@ -333,4 +385,13 @@ class StandardRPCSerializer {
|
|
|
333
385
|
}
|
|
334
386
|
}
|
|
335
387
|
|
|
336
|
-
|
|
388
|
+
class StandardRPCLink extends StandardLink {
|
|
389
|
+
constructor(linkClient, options) {
|
|
390
|
+
const jsonSerializer = new StandardRPCJsonSerializer(options);
|
|
391
|
+
const serializer = new StandardRPCSerializer(jsonSerializer);
|
|
392
|
+
const linkCodec = new StandardRPCLinkCodec(serializer, options);
|
|
393
|
+
super(linkCodec, linkClient, options);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, toStandardHeaders as f, getMalformedResponseErrorCode as g, toHttpPath as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Segment, Value } from '@orpc/shared';
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.js';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.BG98rYdO.js';
|
|
3
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
5
|
|
|
6
6
|
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
@@ -44,46 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL,
|
|
48
|
-
options: ClientOptions<T>,
|
|
49
|
-
path: readonly string[],
|
|
50
|
-
input: unknown
|
|
51
|
-
]>;
|
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
52
48
|
/**
|
|
53
49
|
* The maximum length of the URL.
|
|
54
50
|
*
|
|
55
51
|
* @default 2083
|
|
56
52
|
*/
|
|
57
|
-
maxUrlLength?: Value<number,
|
|
58
|
-
options: ClientOptions<T>,
|
|
59
|
-
path: readonly string[],
|
|
60
|
-
input: unknown
|
|
61
|
-
]>;
|
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
62
54
|
/**
|
|
63
55
|
* The method used to make the request.
|
|
64
56
|
*
|
|
65
57
|
* @default 'POST'
|
|
66
58
|
*/
|
|
67
|
-
method?: Value<HTTPMethod, [
|
|
68
|
-
options: ClientOptions<T>,
|
|
69
|
-
path: readonly string[],
|
|
70
|
-
input: unknown
|
|
71
|
-
]>;
|
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
72
60
|
/**
|
|
73
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
74
62
|
* GET is not allowed, it's very dangerous.
|
|
75
63
|
*
|
|
76
64
|
* @default 'POST'
|
|
77
65
|
*/
|
|
78
|
-
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
|
|
79
67
|
/**
|
|
80
68
|
* Inject headers to the request.
|
|
81
69
|
*/
|
|
82
|
-
headers?: Value<StandardHeaders,
|
|
83
|
-
options: ClientOptions<T>,
|
|
84
|
-
path: readonly string[],
|
|
85
|
-
input: unknown
|
|
86
|
-
]>;
|
|
70
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
87
71
|
}
|
|
88
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
89
73
|
private readonly serializer;
|
|
@@ -99,5 +83,9 @@ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardL
|
|
|
99
83
|
|
|
100
84
|
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
|
101
85
|
}
|
|
86
|
+
declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
87
|
+
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
|
88
|
+
}
|
|
102
89
|
|
|
103
|
-
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S,
|
|
90
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
|
|
91
|
+
export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { resolveMaybeOptionalOptions, getConstructor, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
|
2
|
+
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
|
3
|
+
|
|
4
|
+
const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client";
|
|
5
|
+
const ORPC_CLIENT_PACKAGE_VERSION = "0.0.0-next.c112960";
|
|
6
|
+
|
|
7
|
+
const COMMON_ORPC_ERROR_DEFS = {
|
|
8
|
+
BAD_REQUEST: {
|
|
9
|
+
status: 400,
|
|
10
|
+
message: "Bad Request"
|
|
11
|
+
},
|
|
12
|
+
UNAUTHORIZED: {
|
|
13
|
+
status: 401,
|
|
14
|
+
message: "Unauthorized"
|
|
15
|
+
},
|
|
16
|
+
FORBIDDEN: {
|
|
17
|
+
status: 403,
|
|
18
|
+
message: "Forbidden"
|
|
19
|
+
},
|
|
20
|
+
NOT_FOUND: {
|
|
21
|
+
status: 404,
|
|
22
|
+
message: "Not Found"
|
|
23
|
+
},
|
|
24
|
+
METHOD_NOT_SUPPORTED: {
|
|
25
|
+
status: 405,
|
|
26
|
+
message: "Method Not Supported"
|
|
27
|
+
},
|
|
28
|
+
NOT_ACCEPTABLE: {
|
|
29
|
+
status: 406,
|
|
30
|
+
message: "Not Acceptable"
|
|
31
|
+
},
|
|
32
|
+
TIMEOUT: {
|
|
33
|
+
status: 408,
|
|
34
|
+
message: "Request Timeout"
|
|
35
|
+
},
|
|
36
|
+
CONFLICT: {
|
|
37
|
+
status: 409,
|
|
38
|
+
message: "Conflict"
|
|
39
|
+
},
|
|
40
|
+
PRECONDITION_FAILED: {
|
|
41
|
+
status: 412,
|
|
42
|
+
message: "Precondition Failed"
|
|
43
|
+
},
|
|
44
|
+
PAYLOAD_TOO_LARGE: {
|
|
45
|
+
status: 413,
|
|
46
|
+
message: "Payload Too Large"
|
|
47
|
+
},
|
|
48
|
+
UNSUPPORTED_MEDIA_TYPE: {
|
|
49
|
+
status: 415,
|
|
50
|
+
message: "Unsupported Media Type"
|
|
51
|
+
},
|
|
52
|
+
UNPROCESSABLE_CONTENT: {
|
|
53
|
+
status: 422,
|
|
54
|
+
message: "Unprocessable Content"
|
|
55
|
+
},
|
|
56
|
+
TOO_MANY_REQUESTS: {
|
|
57
|
+
status: 429,
|
|
58
|
+
message: "Too Many Requests"
|
|
59
|
+
},
|
|
60
|
+
CLIENT_CLOSED_REQUEST: {
|
|
61
|
+
status: 499,
|
|
62
|
+
message: "Client Closed Request"
|
|
63
|
+
},
|
|
64
|
+
INTERNAL_SERVER_ERROR: {
|
|
65
|
+
status: 500,
|
|
66
|
+
message: "Internal Server Error"
|
|
67
|
+
},
|
|
68
|
+
NOT_IMPLEMENTED: {
|
|
69
|
+
status: 501,
|
|
70
|
+
message: "Not Implemented"
|
|
71
|
+
},
|
|
72
|
+
BAD_GATEWAY: {
|
|
73
|
+
status: 502,
|
|
74
|
+
message: "Bad Gateway"
|
|
75
|
+
},
|
|
76
|
+
SERVICE_UNAVAILABLE: {
|
|
77
|
+
status: 503,
|
|
78
|
+
message: "Service Unavailable"
|
|
79
|
+
},
|
|
80
|
+
GATEWAY_TIMEOUT: {
|
|
81
|
+
status: 504,
|
|
82
|
+
message: "Gateway Timeout"
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function fallbackORPCErrorStatus(code, status) {
|
|
86
|
+
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
|
87
|
+
}
|
|
88
|
+
function fallbackORPCErrorMessage(code, message) {
|
|
89
|
+
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
90
|
+
}
|
|
91
|
+
const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`);
|
|
92
|
+
void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet());
|
|
93
|
+
const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL];
|
|
94
|
+
class ORPCError extends Error {
|
|
95
|
+
defined;
|
|
96
|
+
code;
|
|
97
|
+
status;
|
|
98
|
+
data;
|
|
99
|
+
constructor(code, ...rest) {
|
|
100
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
101
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
|
102
|
+
throw new Error("[ORPCError] Invalid error status code.");
|
|
103
|
+
}
|
|
104
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
|
105
|
+
super(message, options);
|
|
106
|
+
this.code = code;
|
|
107
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
|
108
|
+
this.defined = options.defined ?? false;
|
|
109
|
+
this.data = options.data;
|
|
110
|
+
}
|
|
111
|
+
toJSON() {
|
|
112
|
+
return {
|
|
113
|
+
defined: this.defined,
|
|
114
|
+
code: this.code,
|
|
115
|
+
status: this.status,
|
|
116
|
+
message: this.message,
|
|
117
|
+
data: this.data
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Workaround for Next.js where different contexts use separate
|
|
122
|
+
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
123
|
+
* `instanceof` checks across contexts.
|
|
124
|
+
*
|
|
125
|
+
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
126
|
+
* executes in one context but is invoked from another. When an error is thrown
|
|
127
|
+
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
128
|
+
* invocation context due to separate class constructors.
|
|
129
|
+
*
|
|
130
|
+
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
131
|
+
*/
|
|
132
|
+
static [Symbol.hasInstance](instance) {
|
|
133
|
+
if (globalORPCErrorConstructors.has(this)) {
|
|
134
|
+
const constructor = getConstructor(instance);
|
|
135
|
+
if (constructor && globalORPCErrorConstructors.has(constructor)) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return super[Symbol.hasInstance](instance);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
globalORPCErrorConstructors.add(ORPCError);
|
|
143
|
+
function isDefinedError(error) {
|
|
144
|
+
return error instanceof ORPCError && error.defined;
|
|
145
|
+
}
|
|
146
|
+
function toORPCError(error) {
|
|
147
|
+
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
148
|
+
message: "Internal server error",
|
|
149
|
+
cause: error
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function isORPCErrorStatus(status) {
|
|
153
|
+
return status < 200 || status >= 400;
|
|
154
|
+
}
|
|
155
|
+
function isORPCErrorJson(json) {
|
|
156
|
+
if (!isObject(json)) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
const validKeys = ["defined", "code", "status", "message", "data"];
|
|
160
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string";
|
|
164
|
+
}
|
|
165
|
+
function createORPCErrorFromJson(json, options = {}) {
|
|
166
|
+
return new ORPCError(json.code, {
|
|
167
|
+
...options,
|
|
168
|
+
...json
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function mapEventIterator(iterator, maps) {
|
|
173
|
+
const mapError = async (error) => {
|
|
174
|
+
let mappedError = await maps.error(error);
|
|
175
|
+
if (mappedError !== error) {
|
|
176
|
+
const meta = getEventMeta(error);
|
|
177
|
+
if (meta && isTypescriptObject(mappedError)) {
|
|
178
|
+
mappedError = withEventMeta(mappedError, meta);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return mappedError;
|
|
182
|
+
};
|
|
183
|
+
return new AsyncIteratorClass(async () => {
|
|
184
|
+
const { done, value } = await (async () => {
|
|
185
|
+
try {
|
|
186
|
+
return await iterator.next();
|
|
187
|
+
} catch (error) {
|
|
188
|
+
throw await mapError(error);
|
|
189
|
+
}
|
|
190
|
+
})();
|
|
191
|
+
let mappedValue = await maps.value(value, done);
|
|
192
|
+
if (mappedValue !== value) {
|
|
193
|
+
const meta = getEventMeta(value);
|
|
194
|
+
if (meta && isTypescriptObject(mappedValue)) {
|
|
195
|
+
mappedValue = withEventMeta(mappedValue, meta);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return { done, value: mappedValue };
|
|
199
|
+
}, async () => {
|
|
200
|
+
try {
|
|
201
|
+
await iterator.return?.();
|
|
202
|
+
} catch (error) {
|
|
203
|
+
throw await mapError(error);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Segment, Value } from '@orpc/shared';
|
|
1
|
+
import { b as ClientContext, c as ClientOptions, f as HTTPMethod } from './client.BOYsZIRq.mjs';
|
|
2
|
+
import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.Bwgm6dgk.mjs';
|
|
3
|
+
import { Segment, Value, Promisable } from '@orpc/shared';
|
|
4
4
|
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
5
5
|
|
|
6
6
|
declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
|
|
@@ -44,46 +44,30 @@ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
|
|
|
44
44
|
/**
|
|
45
45
|
* Base url for all requests.
|
|
46
46
|
*/
|
|
47
|
-
url: Value<string | URL,
|
|
48
|
-
options: ClientOptions<T>,
|
|
49
|
-
path: readonly string[],
|
|
50
|
-
input: unknown
|
|
51
|
-
]>;
|
|
47
|
+
url: Value<Promisable<string | URL>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
52
48
|
/**
|
|
53
49
|
* The maximum length of the URL.
|
|
54
50
|
*
|
|
55
51
|
* @default 2083
|
|
56
52
|
*/
|
|
57
|
-
maxUrlLength?: Value<number,
|
|
58
|
-
options: ClientOptions<T>,
|
|
59
|
-
path: readonly string[],
|
|
60
|
-
input: unknown
|
|
61
|
-
]>;
|
|
53
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
62
54
|
/**
|
|
63
55
|
* The method used to make the request.
|
|
64
56
|
*
|
|
65
57
|
* @default 'POST'
|
|
66
58
|
*/
|
|
67
|
-
method?: Value<HTTPMethod, [
|
|
68
|
-
options: ClientOptions<T>,
|
|
69
|
-
path: readonly string[],
|
|
70
|
-
input: unknown
|
|
71
|
-
]>;
|
|
59
|
+
method?: Value<Promisable<Exclude<HTTPMethod, 'HEAD'>>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
72
60
|
/**
|
|
73
61
|
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
74
62
|
* GET is not allowed, it's very dangerous.
|
|
75
63
|
*
|
|
76
64
|
* @default 'POST'
|
|
77
65
|
*/
|
|
78
|
-
fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
|
|
66
|
+
fallbackMethod?: Exclude<HTTPMethod, 'HEAD' | 'GET'>;
|
|
79
67
|
/**
|
|
80
68
|
* Inject headers to the request.
|
|
81
69
|
*/
|
|
82
|
-
headers?: Value<StandardHeaders,
|
|
83
|
-
options: ClientOptions<T>,
|
|
84
|
-
path: readonly string[],
|
|
85
|
-
input: unknown
|
|
86
|
-
]>;
|
|
70
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
|
|
87
71
|
}
|
|
88
72
|
declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
89
73
|
private readonly serializer;
|
|
@@ -99,5 +83,9 @@ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardL
|
|
|
99
83
|
|
|
100
84
|
interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
|
|
101
85
|
}
|
|
86
|
+
declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
87
|
+
constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
|
|
88
|
+
}
|
|
102
89
|
|
|
103
|
-
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S,
|
|
90
|
+
export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, StandardRPCJsonSerializer as e, StandardRPCLink as g, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
|
|
91
|
+
export type { StandardRPCJsonSerializedMetaItem as a, StandardRPCJsonSerialized as b, StandardRPCCustomJsonSerializer as c, StandardRPCJsonSerializerOptions as d, StandardRPCLinkOptions as f, StandardRPCLinkCodecOptions as h };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.c112960",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -33,18 +33,29 @@
|
|
|
33
33
|
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
34
|
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
35
|
"default": "./dist/adapters/fetch/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./websocket": {
|
|
38
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./message-port": {
|
|
43
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
36
46
|
}
|
|
37
47
|
},
|
|
38
48
|
"files": [
|
|
39
49
|
"dist"
|
|
40
50
|
],
|
|
41
51
|
"dependencies": {
|
|
42
|
-
"@orpc/shared": "0.0.0-next.
|
|
43
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
44
|
-
"@orpc/standard-server-
|
|
52
|
+
"@orpc/shared": "0.0.0-next.c112960",
|
|
53
|
+
"@orpc/standard-server": "0.0.0-next.c112960",
|
|
54
|
+
"@orpc/standard-server-peer": "0.0.0-next.c112960",
|
|
55
|
+
"@orpc/standard-server-fetch": "0.0.0-next.c112960"
|
|
45
56
|
},
|
|
46
57
|
"devDependencies": {
|
|
47
|
-
"zod": "^
|
|
58
|
+
"zod": "^4.1.11"
|
|
48
59
|
},
|
|
49
60
|
"scripts": {
|
|
50
61
|
"build": "unbuild",
|