@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
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import "../adapters/standard/index.js";
|
|
2
|
+
import { StandardLinkPlugin } from "../adapters/standard/plugin.js";
|
|
3
|
+
import { StandardLinkInterceptorOptions, StandardLinkOptions } from "../adapters/standard/link.js";
|
|
4
|
+
import { ClientContext } from "../types.js";
|
|
5
|
+
import { Value } from "@orpc/shared";
|
|
4
6
|
export interface TimeoutLinkPluginOptions<T extends ClientContext> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Timeout in milliseconds before the request is aborted.
|
|
9
|
+
* Use `null` or `undefined` to disable the timeout.
|
|
10
|
+
*/
|
|
11
|
+
timeout: Value<number | null | undefined, [options: StandardLinkInterceptorOptions<T>]>;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
12
14
|
* The Timeout Link Plugin aborts requests that exceed a configured timeout with an `AbortError`.
|
|
@@ -14,12 +16,12 @@ export interface TimeoutLinkPluginOptions<T extends ClientContext> {
|
|
|
14
16
|
* @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
|
|
15
17
|
*/
|
|
16
18
|
export declare class TimeoutLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
19
|
+
private readonly timeout;
|
|
20
|
+
name: string;
|
|
21
|
+
/**
|
|
22
|
+
* Should abort if the total retry time exceeds the configured timeout
|
|
23
|
+
*/
|
|
24
|
+
after: string[];
|
|
25
|
+
constructor(options: NoInfer<TimeoutLinkPluginOptions<T>>);
|
|
26
|
+
init(options: StandardLinkOptions<T>): StandardLinkOptions<T>;
|
|
27
|
+
}
|
package/dist/plugins/timeout.js
CHANGED
|
@@ -1,37 +1,42 @@
|
|
|
1
|
-
import { AbortError, anyAbortSignal, toArray, value } from
|
|
1
|
+
import { AbortError, anyAbortSignal, toArray, value } from "@orpc/shared";
|
|
2
|
+
// src/plugins/timeout.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
4
|
+
* The Timeout Link Plugin aborts requests that exceed a configured timeout with an `AbortError`.
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
|
|
7
|
+
*/
|
|
8
|
+
var TimeoutLinkPlugin = class {
|
|
9
|
+
timeout;
|
|
10
|
+
name = "~timeout";
|
|
11
|
+
/**
|
|
12
|
+
* Should abort if the total retry time exceeds the configured timeout
|
|
13
|
+
*/
|
|
14
|
+
after = ["~retry"];
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.timeout = options.timeout;
|
|
17
|
+
}
|
|
18
|
+
init(options) {
|
|
19
|
+
const interceptor = async (interceptorOptions) => {
|
|
20
|
+
const timeoutMs = value(this.timeout, interceptorOptions);
|
|
21
|
+
if (timeoutMs === null || timeoutMs === void 0) return interceptorOptions.next();
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
const timeoutId = setTimeout(() => {
|
|
24
|
+
controller.abort(new AbortError(`Request timed out after ${timeoutMs}ms`));
|
|
25
|
+
}, timeoutMs);
|
|
26
|
+
const signal = anyAbortSignal([interceptorOptions.signal, controller.signal]);
|
|
27
|
+
try {
|
|
28
|
+
return await interceptorOptions.next({
|
|
29
|
+
...interceptorOptions,
|
|
30
|
+
signal
|
|
31
|
+
});
|
|
32
|
+
} finally {
|
|
33
|
+
clearTimeout(timeoutId);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
...options,
|
|
38
|
+
interceptors: [interceptor, ...toArray(options.interceptors)]
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export { TimeoutLinkPlugin };
|
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Segment } from "@orpc/shared";
|
|
2
2
|
export type RPCJsonSerializationMeta = [type: string, ...path: Segment[]];
|
|
3
3
|
export type RPCJsonSerialization = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
json: unknown;
|
|
5
|
+
meta?: RPCJsonSerializationMeta[] | undefined;
|
|
6
|
+
maps?: undefined;
|
|
7
|
+
blobs?: undefined;
|
|
8
8
|
} | {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
json: unknown;
|
|
10
|
+
meta?: RPCJsonSerializationMeta[] | undefined;
|
|
11
|
+
maps: Segment[][];
|
|
12
|
+
blobs: Blob[];
|
|
13
13
|
};
|
|
14
14
|
export interface RPCJsonSerializerHandler {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
condition(value: unknown): boolean;
|
|
16
|
+
serialize(value: any): unknown;
|
|
17
|
+
/**
|
|
18
|
+
* `serialized` comes from the wire, so validate its type and throw on mismatch.
|
|
19
|
+
*/
|
|
20
|
+
deserialize(serialized: unknown): unknown;
|
|
21
|
+
/**
|
|
22
|
+
* If false, the result of this serializer will not be further processed by other serializers,
|
|
23
|
+
* even if it matches their conditions and treat it as final serialized value.
|
|
24
|
+
* This can be useful for serializers that return primitive values, which should not be further processed.
|
|
25
|
+
* to improve performance and avoid potential issues with other serializers.
|
|
26
|
+
*
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
isTerminal?: boolean | undefined;
|
|
30
30
|
}
|
|
31
31
|
export interface RPCJsonSerializerOptions {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Extend or override the built-in type handlers used during serialization and deserialization.
|
|
34
|
+
*
|
|
35
|
+
* Each key is a unique type identifier (e.g. `"date"`, `"bigint"`) and maps to a handler
|
|
36
|
+
* that defines how to detect, serialize, and deserialize values of that type.
|
|
37
|
+
*
|
|
38
|
+
* **Extending:** Add new keys to support custom types:
|
|
39
|
+
* ```ts
|
|
40
|
+
* handlers: {
|
|
41
|
+
* buffer: {
|
|
42
|
+
* condition: (v) => v instanceof Buffer,
|
|
43
|
+
* serialize: (v: Buffer) => v.toString('base64'),
|
|
44
|
+
* deserialize: (s: string) => Buffer.from(s, 'base64'),
|
|
45
|
+
* isTerminal: true,
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* **Overriding:** Use an existing key to replace a built-in handler:
|
|
51
|
+
* ```ts
|
|
52
|
+
* handlers: {
|
|
53
|
+
* date: {
|
|
54
|
+
* condition: (v) => v instanceof Date,
|
|
55
|
+
* serialize: (v: Date) => v.getTime(),
|
|
56
|
+
* deserialize: (n: number) => new Date(n),
|
|
57
|
+
* isTerminal: true,
|
|
58
|
+
* }
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* **Disabling:** Set a key to `undefined` to remove a built-in handler:
|
|
63
|
+
* ```ts
|
|
64
|
+
* handlers: { url: undefined }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* During deserialization, values whose type has no handler are left in their serialized form,
|
|
68
|
+
* so a client and server with different handlers can still communicate.
|
|
69
|
+
*
|
|
70
|
+
* Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `infinity`, `url`, `set`, `map`.
|
|
71
|
+
*/
|
|
72
|
+
handlers?: Record<string, undefined | RPCJsonSerializerHandler> | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* If true, properties with undefined values will be omitted during serialization.
|
|
75
|
+
*
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
omitUndefinedProperties?: boolean | undefined;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Serializes and deserializes native types like Date, BigInt, Set, and Map
|
|
@@ -84,16 +84,16 @@ export interface RPCJsonSerializerOptions {
|
|
|
84
84
|
* @see {@link https://orpc.dev/docs/rpc/serializer#rpc-json-serializer | RPC Serializer - RPC JSON Serializer}
|
|
85
85
|
*/
|
|
86
86
|
export declare class RPCJsonSerializer {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
87
|
+
private readonly handlers;
|
|
88
|
+
private readonly inlineBuiltInHandlers;
|
|
89
|
+
private readonly handlerEntries;
|
|
90
|
+
private readonly omitUndefinedProperties;
|
|
91
|
+
constructor(options?: RPCJsonSerializerOptions);
|
|
92
|
+
serializeJson(data: unknown): RPCJsonSerialization;
|
|
93
|
+
/**
|
|
94
|
+
* `segments` is a shared mutable stack (push/pop while walking),
|
|
95
|
+
* so it must be copied before being stored in `meta` or `maps`.
|
|
96
|
+
*/
|
|
97
|
+
private serializeValue;
|
|
98
|
+
deserializeJson(serialized: RPCJsonSerialization): unknown;
|
|
99
|
+
}
|