@orpc/client 2.0.0-beta.49 → 2.0.0-beta.50
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/dist/adapters/fetch/index.d.ts +3 -2
- package/dist/adapters/fetch/index.js +2 -2
- package/dist/adapters/fetch/rpc-link.d.ts +8 -8
- package/dist/adapters/fetch/rpc-link.js +16 -13
- package/dist/adapters/fetch/transport.d.ts +29 -31
- package/dist/adapters/fetch/transport.js +49 -63
- package/dist/adapters/message-port/index.d.ts +4 -3
- package/dist/adapters/message-port/index.js +3 -3
- package/dist/adapters/message-port/message-port.d.ts +13 -13
- package/dist/adapters/message-port/message-port.js +35 -53
- package/dist/adapters/message-port/rpc-link.d.ts +8 -8
- package/dist/adapters/message-port/rpc-link.js +17 -14
- package/dist/adapters/message-port/transport.d.ts +31 -34
- package/dist/adapters/message-port/transport.js +38 -52
- package/dist/adapters/standard/codec.d.ts +10 -10
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.js +2 -4
- package/dist/adapters/standard/link.d.ts +31 -31
- package/dist/adapters/standard/link.js +101 -85
- package/dist/adapters/standard/plugin.d.ts +25 -31
- package/dist/adapters/standard/plugin.js +14 -16
- package/dist/adapters/standard/rpc-link-codec.d.ts +53 -60
- package/dist/adapters/standard/rpc-link-codec.js +98 -102
- package/dist/adapters/standard/transport.d.ts +7 -7
- package/dist/adapters/websocket/index.d.ts +3 -2
- package/dist/adapters/websocket/index.js +2 -2
- package/dist/adapters/websocket/rpc-link.d.ts +8 -8
- package/dist/adapters/websocket/rpc-link.js +16 -13
- package/dist/adapters/websocket/transport.d.ts +101 -100
- package/dist/adapters/websocket/transport.js +102 -130
- package/dist/async-iterator-object.d.ts +2 -2
- package/dist/async-iterator-object.js +27 -28
- package/dist/client-safe.d.ts +4 -6
- package/dist/client-safe.js +29 -34
- package/dist/client.d.ts +24 -26
- package/dist/client.js +35 -37
- package/dist/consts.d.ts +1 -1
- package/dist/consts.js +18 -41
- package/dist/dynamic-link.d.ts +6 -6
- package/dist/dynamic-link.js +16 -16
- package/dist/error-utils.d.ts +3 -4
- package/dist/error-utils.js +47 -51
- package/dist/error.d.ts +79 -79
- package/dist/error.js +154 -166
- package/dist/index.d.ts +14 -53
- package/dist/index.js +12 -40
- package/dist/plugins/batch.d.ts +122 -155
- package/dist/plugins/batch.js +320 -391
- package/dist/plugins/cookie-jar.d.ts +64 -61
- package/dist/plugins/cookie-jar.js +208 -245
- package/dist/plugins/dedupe.d.ts +49 -53
- package/dist/plugins/dedupe.js +168 -211
- package/dist/plugins/index.d.ts +9 -28
- package/dist/plugins/index.js +8 -23
- package/dist/plugins/request-compression.d.ts +38 -35
- package/dist/plugins/request-compression.js +131 -177
- package/dist/plugins/response-compression.d.ts +21 -18
- package/dist/plugins/response-compression.js +64 -88
- package/dist/plugins/retry-after.d.ts +31 -38
- package/dist/plugins/retry-after.js +60 -85
- package/dist/plugins/retry.d.ts +55 -55
- package/dist/plugins/retry.js +118 -137
- package/dist/plugins/timeout.d.ts +19 -17
- package/dist/plugins/timeout.js +41 -36
- package/dist/rpc-json-serializer.d.ts +84 -84
- package/dist/rpc-json-serializer.js +338 -383
- package/dist/rpc-serializer.d.ts +20 -21
- package/dist/rpc-serializer.js +97 -125
- package/dist/types.d.ts +19 -31
- package/dist/utils.d.ts +18 -29
- package/dist/utils.js +63 -47
- package/package.json +5 -5
- package/dist/adapters/standard/codec.js +0 -1
- package/dist/adapters/standard/transport.js +0 -1
- package/dist/types.js +0 -1
package/dist/dynamic-link.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
// src/dynamic-link.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
3
|
+
* DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
|
|
4
|
+
* based on the request path, input, and context.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://orpc.dev/docs/client/dynamic-link | DynamicLink}
|
|
7
|
+
*/
|
|
8
|
+
var DynamicLink = class {
|
|
9
|
+
linkResolver;
|
|
10
|
+
constructor(linkResolver) {
|
|
11
|
+
this.linkResolver = linkResolver;
|
|
12
|
+
}
|
|
13
|
+
async call(path, input, options) {
|
|
14
|
+
return await (await this.linkResolver(options, path, input)).call(path, input, options);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export { DynamicLink };
|
package/dist/error-utils.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ORPCError } from './error.ts';
|
|
1
|
+
import { AnyORPCError, ORPCError, ORPCErrorCode, ORPCErrorJSON } from "./error.js";
|
|
3
2
|
/**
|
|
4
3
|
* Checks if an error is an `ORPCError` that matches a definition in the procedure's `.errors` map,
|
|
5
4
|
* narrowing it so `code` and `data` are fully typed.
|
|
@@ -7,7 +6,7 @@ import { ORPCError } from './error.ts';
|
|
|
7
6
|
* @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isdefinederror | Client Error Handling - Using safe and isDefinedError}
|
|
8
7
|
*/
|
|
9
8
|
export declare function isDefinedError<T>(error: T): error is Extract<T, AnyORPCError>;
|
|
10
|
-
export declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<
|
|
9
|
+
export declare function toORPCError<T>(error: T): Extract<T, AnyORPCError> | ORPCError<"INTERNAL_SERVER_ERROR", undefined>;
|
|
11
10
|
export declare function isORPCErrorJson(json: unknown): json is ORPCErrorJSON<ORPCErrorCode, unknown>;
|
|
12
11
|
export declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TData>(json: ORPCErrorJSON<TCode, TData>, options?: ErrorOptions): ORPCError<TCode, TData>;
|
|
13
12
|
/**
|
|
@@ -18,4 +17,4 @@ export declare function createORPCErrorFromJson<TCode extends ORPCErrorCode, TDa
|
|
|
18
17
|
* (`#field`) are not carried over and subclass members that read them
|
|
19
18
|
* will throw on the clone.
|
|
20
19
|
*/
|
|
21
|
-
export declare function cloneORPCError<T extends AnyORPCError>(error: T): T;
|
|
20
|
+
export declare function cloneORPCError<T extends AnyORPCError>(error: T): T;
|
package/dist/error-utils.js
CHANGED
|
@@ -1,58 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ORPCError } from "./error.js";
|
|
2
|
+
import { isPlainObject } from "@orpc/shared";
|
|
3
|
+
// src/error-utils.ts
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
* Checks if an error is an `ORPCError` that matches a definition in the procedure's `.errors` map,
|
|
6
|
+
* narrowing it so `code` and `data` are fully typed.
|
|
7
|
+
*
|
|
8
|
+
* @see {@link https://orpc.dev/docs/client/error-handling#using-safe-and-isdefinederror | Client Error Handling - Using safe and isDefinedError}
|
|
9
|
+
*/
|
|
10
|
+
function isDefinedError(error) {
|
|
11
|
+
return error instanceof ORPCError && error.defined;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
? error
|
|
15
|
-
: new ORPCError('INTERNAL_SERVER_ERROR', { cause: error });
|
|
13
|
+
function toORPCError(error) {
|
|
14
|
+
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { cause: error });
|
|
16
15
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
'code' in json &&
|
|
28
|
-
typeof json.code === 'string' &&
|
|
29
|
-
'message' in json &&
|
|
30
|
-
typeof json.message === 'string');
|
|
16
|
+
function isORPCErrorJson(json) {
|
|
17
|
+
if (!isPlainObject(json)) return false;
|
|
18
|
+
const validKeys = [
|
|
19
|
+
"defined",
|
|
20
|
+
"code",
|
|
21
|
+
"message",
|
|
22
|
+
"data"
|
|
23
|
+
];
|
|
24
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) return false;
|
|
25
|
+
return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "message" in json && typeof json.message === "string";
|
|
31
26
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
function createORPCErrorFromJson(json, options = {}) {
|
|
28
|
+
const error = new ORPCError(json.code, {
|
|
29
|
+
...json,
|
|
30
|
+
...options
|
|
31
|
+
});
|
|
32
|
+
error.defined = json.defined;
|
|
33
|
+
return error;
|
|
39
34
|
}
|
|
40
35
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
36
|
+
* Clones an `ORPCError` while preserving its prototype chain, so instances of
|
|
37
|
+
* `ORPCError` subclasses remain `instanceof` their class.
|
|
38
|
+
*
|
|
39
|
+
* Limitation: subclass constructors are not re-run, so private fields
|
|
40
|
+
* (`#field`) are not carried over and subclass members that read them
|
|
41
|
+
* will throw on the clone.
|
|
42
|
+
*/
|
|
43
|
+
function cloneORPCError(error) {
|
|
44
|
+
const cloned = new ORPCError(error.code, {
|
|
45
|
+
message: error.message,
|
|
46
|
+
data: error.data,
|
|
47
|
+
cause: error.cause
|
|
48
|
+
});
|
|
49
|
+
Object.setPrototypeOf(cloned, Object.getPrototypeOf(error));
|
|
50
|
+
Object.defineProperties(cloned, Object.getOwnPropertyDescriptors(error));
|
|
51
|
+
cloned.stack = error.stack;
|
|
52
|
+
return cloned;
|
|
58
53
|
}
|
|
54
|
+
export { cloneORPCError, createORPCErrorFromJson, isDefinedError, isORPCErrorJson, toORPCError };
|
package/dist/error.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { MaybeOptionalOptions, Registry } from "@orpc/shared";
|
|
2
|
+
import { StandardResponse } from "@standard-server/core";
|
|
3
3
|
/**
|
|
4
4
|
* Default mapping between common oRPC error codes and HTTP status codes.
|
|
5
5
|
* Handlers use it to determine response status codes; spread it to build a custom `errorStatusMap`.
|
|
@@ -8,39 +8,39 @@ import type { StandardResponse } from '@standard-server/core';
|
|
|
8
8
|
* @see {@link https://orpc.dev/docs/openapi/handler#custom-error-response | OpenAPI Handler - Custom Error Response}
|
|
9
9
|
*/
|
|
10
10
|
export declare const COMMON_ERROR_STATUS_MAP: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
BAD_REQUEST: number;
|
|
12
|
+
UNAUTHORIZED: number;
|
|
13
|
+
PAYMENT_REQUIRED: number;
|
|
14
|
+
FORBIDDEN: number;
|
|
15
|
+
NOT_FOUND: number;
|
|
16
|
+
METHOD_NOT_SUPPORTED: number;
|
|
17
|
+
NOT_ACCEPTABLE: number;
|
|
18
|
+
TIMEOUT: number;
|
|
19
|
+
CONFLICT: number;
|
|
20
|
+
GONE: number;
|
|
21
|
+
LENGTH_REQUIRED: number;
|
|
22
|
+
PRECONDITION_FAILED: number;
|
|
23
|
+
PAYLOAD_TOO_LARGE: number;
|
|
24
|
+
UNSUPPORTED_MEDIA_TYPE: number;
|
|
25
|
+
UNPROCESSABLE_CONTENT: number;
|
|
26
|
+
PRECONDITION_REQUIRED: number;
|
|
27
|
+
TOO_MANY_REQUESTS: number;
|
|
28
|
+
CLIENT_CLOSED_REQUEST: number;
|
|
29
|
+
INTERNAL_SERVER_ERROR: number;
|
|
30
|
+
NOT_IMPLEMENTED: number;
|
|
31
|
+
BAD_GATEWAY: number;
|
|
32
|
+
SERVICE_UNAVAILABLE: number;
|
|
33
|
+
GATEWAY_TIMEOUT: number;
|
|
34
34
|
};
|
|
35
35
|
export type ORPCErrorCode = Registry extends {
|
|
36
|
-
|
|
36
|
+
ORPCErrorCode: infer T extends string;
|
|
37
37
|
} ? T : keyof typeof COMMON_ERROR_STATUS_MAP | (string & {});
|
|
38
38
|
export type ORPCErrorOptions<TData> = ErrorOptions & {
|
|
39
|
-
|
|
39
|
+
message?: string | undefined;
|
|
40
40
|
} & (undefined extends TData ? {
|
|
41
|
-
|
|
41
|
+
data?: TData;
|
|
42
42
|
} : {
|
|
43
|
-
|
|
43
|
+
data: TData;
|
|
44
44
|
});
|
|
45
45
|
/**
|
|
46
46
|
* Typed error carrying a `code`, a `message`, and optional `data`.
|
|
@@ -49,51 +49,51 @@ export type ORPCErrorOptions<TData> = ErrorOptions & {
|
|
|
49
49
|
* @see {@link https://orpc.dev/docs/error-handling#orpcerror-class | Error Handling - ORPCError Class}
|
|
50
50
|
*/
|
|
51
51
|
export declare class ORPCError<TCode extends ORPCErrorCode, TData> extends Error {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
52
|
+
/**
|
|
53
|
+
* @remarks
|
|
54
|
+
* **Note**: The `__branch` property is used for type branding, helping TypeScript distinguish
|
|
55
|
+
* an `ORPCError` instance from plain objects with a similar structure.
|
|
56
|
+
*/
|
|
57
|
+
override readonly name: "ORPCError" & {
|
|
58
|
+
__branch: "ORPCError";
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Indicates whether the error matches a definition in the procedure's `.errors` map,
|
|
62
|
+
* which makes its type inferable on the client.
|
|
63
|
+
*/
|
|
64
|
+
readonly defined: boolean;
|
|
65
|
+
code: TCode;
|
|
66
|
+
data: TData;
|
|
67
|
+
constructor(code: TCode, ...rest: MaybeOptionalOptions<ORPCErrorOptions<TData>>);
|
|
68
|
+
toJSON(): ORPCErrorJSON<TCode, TData>;
|
|
69
|
+
/**
|
|
70
|
+
* Workaround for Next.js where different contexts use separate
|
|
71
|
+
* dependency graphs, causing multiple ORPCError constructors existing and breaking
|
|
72
|
+
* `instanceof` checks across contexts.
|
|
73
|
+
*
|
|
74
|
+
* This is particularly problematic with "Optimized SSR", where orpc-client
|
|
75
|
+
* executes in one context but is invoked from another. When an error is thrown
|
|
76
|
+
* in the execution context, `instanceof ORPCError` checks fail in the
|
|
77
|
+
* invocation context due to separate class constructors.
|
|
78
|
+
*
|
|
79
|
+
* @todo Remove this and related code if Next.js resolves the multiple dependency graph issue.
|
|
80
|
+
*/
|
|
81
|
+
static override [Symbol.hasInstance](instance: unknown): boolean;
|
|
82
82
|
}
|
|
83
|
-
export interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
export interface ORPCErrorJSON<TCode extends string, TData> extends Pick<ORPCError<TCode, TData>, "code" | "message" | "data"> {
|
|
84
|
+
/**
|
|
85
|
+
* remove readonly
|
|
86
|
+
*/
|
|
87
|
+
defined: boolean;
|
|
88
88
|
}
|
|
89
89
|
export type AnyORPCError = ORPCError<any, any>;
|
|
90
90
|
export type AnyORPCErrorJSON = ORPCErrorJSON<any, any>;
|
|
91
91
|
export interface ResponseErrorOptions extends ErrorOptions {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
/**
|
|
93
|
+
* @default inferred from the response status
|
|
94
|
+
*/
|
|
95
|
+
message?: string | undefined;
|
|
96
|
+
response: StandardResponse;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* Error carrying the resolved response a link received. Links set it as the `cause`
|
|
@@ -104,15 +104,15 @@ export interface ResponseErrorOptions extends ErrorOptions {
|
|
|
104
104
|
* @see {@link https://orpc.dev/docs/openapi/link#error-responses | OpenAPI Link - Error Responses}
|
|
105
105
|
*/
|
|
106
106
|
export declare class ResponseError extends Error {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
override readonly name: string;
|
|
108
|
+
response: StandardResponse;
|
|
109
|
+
constructor(options: ResponseErrorOptions);
|
|
110
110
|
}
|
|
111
111
|
export interface MalformedResponseErrorOptions extends ResponseErrorOptions {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
/**
|
|
113
|
+
* @default inferred from the response body or status
|
|
114
|
+
*/
|
|
115
|
+
message?: string | undefined;
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* Error thrown by links when a response does not follow the expected oRPC format,
|
|
@@ -127,6 +127,6 @@ export interface MalformedResponseErrorOptions extends ResponseErrorOptions {
|
|
|
127
127
|
* @see {@link https://orpc.dev/docs/openapi/link#malformed-responses | OpenAPI Link - Malformed Responses}
|
|
128
128
|
*/
|
|
129
129
|
export declare class MalformedResponseError extends ResponseError {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
130
|
+
override readonly name = "MalformedResponseError";
|
|
131
|
+
constructor(options: MalformedResponseErrorOptions);
|
|
132
|
+
}
|