@orpc/client 1.14.11 → 1.14.12
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 +68 -52
- package/dist/adapters/fetch/index.d.mts +35 -54
- package/dist/adapters/fetch/index.d.ts +35 -54
- package/dist/adapters/fetch/index.mjs +27 -74
- package/dist/adapters/message-port/index.d.mts +30 -25
- package/dist/adapters/message-port/index.d.ts +30 -25
- package/dist/adapters/message-port/index.mjs +30 -39
- package/dist/adapters/standard/index.d.mts +9 -59
- package/dist/adapters/standard/index.d.ts +9 -59
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/websocket/index.d.mts +21 -113
- package/dist/adapters/websocket/index.d.ts +21 -113
- package/dist/adapters/websocket/index.mjs +37 -95
- package/dist/index.d.mts +184 -75
- package/dist/index.d.ts +184 -75
- package/dist/index.mjs +63 -74
- package/dist/plugins/index.d.mts +122 -191
- package/dist/plugins/index.d.ts +122 -191
- package/dist/plugins/index.mjs +281 -627
- package/dist/shared/client.2jUAqzYU.d.ts +45 -0
- package/dist/shared/client.B3pNRBih.d.ts +91 -0
- package/dist/shared/client.BFAVy68H.d.mts +91 -0
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/client.C1VUaWTu.mjs +404 -0
- package/dist/shared/client.CpCa3si8.d.mts +45 -0
- package/dist/shared/client.DrCRv_sG.mjs +174 -0
- package/dist/shared/client.i2uoJbEp.d.mts +83 -0
- package/dist/shared/client.i2uoJbEp.d.ts +83 -0
- package/package.json +7 -7
- package/dist/shared/client.8f4DNmdE.d.mts +0 -96
- package/dist/shared/client.BBZBQID8.d.mts +0 -167
- package/dist/shared/client.BBZBQID8.d.ts +0 -167
- package/dist/shared/client.BMKYqpdy.d.ts +0 -96
- package/dist/shared/client.BRJnOJ0R.mjs +0 -174
- package/dist/shared/client.BdItY5DT.d.mts +0 -111
- package/dist/shared/client.BdItY5DT.d.ts +0 -111
- package/dist/shared/client.Dnfj8jnT.mjs +0 -92
- package/dist/shared/client.DqYwRDUO.mjs +0 -343
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.js';
|
|
2
1
|
import { Value, Promisable } from '@orpc/shared';
|
|
3
|
-
import { StandardRequest, StandardLazyResponse } from '@
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import '../../shared/client.
|
|
2
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { DecodedRequestMessage } from '@orpc/standard-server-peer';
|
|
4
|
+
import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.js';
|
|
5
|
+
import { f as StandardLinkClient } from '../../shared/client.2jUAqzYU.js';
|
|
6
|
+
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B3pNRBih.js';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* The message port used by electron in main process
|
|
@@ -29,47 +28,53 @@ interface BrowserPortLike {
|
|
|
29
28
|
}
|
|
30
29
|
type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
|
|
31
30
|
/**
|
|
32
|
-
*
|
|
31
|
+
* Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
|
|
33
32
|
*/
|
|
34
33
|
type SupportedMessagePortData = any;
|
|
35
34
|
declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
|
|
36
35
|
declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
|
|
37
36
|
declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
interface MessagePortLinkTransportOptions<_T extends ClientContext> {
|
|
38
|
+
interface LinkMessagePortClientOptions {
|
|
41
39
|
port: SupportedMessagePort;
|
|
42
40
|
/**
|
|
43
41
|
* By default, oRPC serializes request/response messages to string/binary data before sending over message port.
|
|
44
|
-
* If needed, define this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
|
|
42
|
+
* If needed, you can define the this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
|
|
45
43
|
* such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
|
|
46
44
|
*
|
|
47
45
|
* @remarks
|
|
48
46
|
* - return null | undefined to disable this feature
|
|
49
47
|
*
|
|
50
48
|
* @warning Make sure your message port supports `transfer` before using this feature.
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* experimental_transfer: (message, port) => {
|
|
52
|
+
* const transfer = deepFindTransferableObjects(message) // implement your own logic
|
|
53
|
+
* return transfer.length ? transfer : null // only enable when needed
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @see {@link https://orpc.dev/docs/adapters/message-port#transfer Message Port Transfer Docs}
|
|
51
58
|
*/
|
|
52
59
|
experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
|
|
53
|
-
/**
|
|
54
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
55
|
-
*/
|
|
56
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
57
|
-
/**
|
|
58
|
-
* Options for decoding peer messages, such as `prefix` for distinguishing messages on the same channel.
|
|
59
|
-
*/
|
|
60
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
61
60
|
}
|
|
62
|
-
declare class
|
|
61
|
+
declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
|
|
63
62
|
private readonly peer;
|
|
64
|
-
constructor(
|
|
65
|
-
|
|
63
|
+
constructor(options: LinkMessagePortClientOptions);
|
|
64
|
+
call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
|
67
|
+
interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkMessagePortClientOptions {
|
|
69
68
|
}
|
|
70
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The RPC Link for common message port implementations.
|
|
71
|
+
*
|
|
72
|
+
* @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs}
|
|
73
|
+
* @see {@link https://orpc.dev/docs/adapters/message-port Message Port Adapter Docs}
|
|
74
|
+
*/
|
|
75
|
+
declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
71
76
|
constructor(options: RPCLinkOptions<T>);
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
export {
|
|
75
|
-
export type { BrowserPortLike,
|
|
79
|
+
export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
80
|
+
export type { BrowserPortLike, LinkMessagePortClientOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { value } from '@orpc/shared';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import '@
|
|
5
|
-
import '
|
|
6
|
-
import '
|
|
7
|
-
import '../../shared/client.
|
|
1
|
+
import { value, isObject } from '@orpc/shared';
|
|
2
|
+
import { experimental_ClientPeerWithoutCodec, serializeRequestMessage, encodeRequestMessage, deserializeResponseMessage, decodeResponseMessage } from '@orpc/standard-server-peer';
|
|
3
|
+
import { c as StandardRPCLink } from '../../shared/client.C1VUaWTu.mjs';
|
|
4
|
+
import '@orpc/standard-server';
|
|
5
|
+
import '../../shared/client.DrCRv_sG.mjs';
|
|
6
|
+
import '@orpc/standard-server-fetch';
|
|
7
|
+
import '../../shared/client.BLtwTQUg.mjs';
|
|
8
8
|
|
|
9
9
|
function postMessagePortMessage(port, data, transfer) {
|
|
10
10
|
if (transfer) {
|
|
@@ -32,11 +32,11 @@ function onMessagePortMessage(port, callback) {
|
|
|
32
32
|
}
|
|
33
33
|
function onMessagePortClose(port, callback) {
|
|
34
34
|
if ("addEventListener" in port) {
|
|
35
|
-
port.addEventListener("close", () => {
|
|
35
|
+
port.addEventListener("close", async () => {
|
|
36
36
|
callback();
|
|
37
37
|
});
|
|
38
38
|
} else if ("on" in port) {
|
|
39
|
-
port.on("close", () => {
|
|
39
|
+
port.on("close", async () => {
|
|
40
40
|
callback();
|
|
41
41
|
});
|
|
42
42
|
} else if ("onDisconnect" in port) {
|
|
@@ -48,49 +48,40 @@ function onMessagePortClose(port, callback) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
class
|
|
51
|
+
class LinkMessagePortClient {
|
|
52
52
|
peer;
|
|
53
|
-
constructor(
|
|
54
|
-
this.peer = new
|
|
55
|
-
const
|
|
53
|
+
constructor(options) {
|
|
54
|
+
this.peer = new experimental_ClientPeerWithoutCodec(async (message) => {
|
|
55
|
+
const [id, type, payload] = message;
|
|
56
|
+
const transfer = await value(options.experimental_transfer, message, options.port);
|
|
56
57
|
if (transfer) {
|
|
57
|
-
postMessagePortMessage(port,
|
|
58
|
+
postMessagePortMessage(options.port, serializeRequestMessage(id, type, payload), transfer);
|
|
58
59
|
} else {
|
|
59
|
-
postMessagePortMessage(port, await
|
|
60
|
+
postMessagePortMessage(options.port, await encodeRequestMessage(id, type, payload));
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
|
-
onMessagePortMessage(port, async (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
peerMessage = result.message;
|
|
68
|
-
}
|
|
69
|
-
} else if (isPeerMessage(data) && isServerPeerSendMessage(data)) {
|
|
70
|
-
peerMessage = data;
|
|
71
|
-
}
|
|
72
|
-
if (peerMessage === void 0) {
|
|
73
|
-
return { matched: false };
|
|
63
|
+
onMessagePortMessage(options.port, async (message) => {
|
|
64
|
+
if (isObject(message)) {
|
|
65
|
+
await this.peer.message(deserializeResponseMessage(message));
|
|
66
|
+
} else {
|
|
67
|
+
await this.peer.message(await decodeResponseMessage(message));
|
|
74
68
|
}
|
|
75
|
-
await this.peer.message(peerMessage);
|
|
76
|
-
return { matched: true };
|
|
77
69
|
});
|
|
78
|
-
onMessagePortClose(port,
|
|
79
|
-
|
|
70
|
+
onMessagePortClose(options.port, () => {
|
|
71
|
+
this.peer.close();
|
|
80
72
|
});
|
|
81
73
|
}
|
|
82
|
-
async
|
|
83
|
-
const
|
|
84
|
-
return
|
|
74
|
+
async call(request, _options, _path, _input) {
|
|
75
|
+
const response = await this.peer.request(request);
|
|
76
|
+
return { ...response, body: () => Promise.resolve(response.body) };
|
|
85
77
|
}
|
|
86
78
|
}
|
|
87
79
|
|
|
88
|
-
class RPCLink extends
|
|
80
|
+
class RPCLink extends StandardRPCLink {
|
|
89
81
|
constructor(options) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
super(codec, transport, options);
|
|
82
|
+
const linkClient = new LinkMessagePortClient(options);
|
|
83
|
+
super(linkClient, { ...options, url: "http://orpc" });
|
|
93
84
|
}
|
|
94
85
|
}
|
|
95
86
|
|
|
96
|
-
export {
|
|
87
|
+
export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
@@ -1,61 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.mjs';
|
|
7
|
-
import { e as RPCSerializer } from '../../shared/client.BdItY5DT.mjs';
|
|
1
|
+
export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.CpCa3si8.mjs';
|
|
2
|
+
export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.BFAVy68H.mjs';
|
|
3
|
+
import { StandardHeaders } from '@orpc/standard-server';
|
|
4
|
+
import { H as HTTPPath } from '../../shared/client.i2uoJbEp.mjs';
|
|
5
|
+
import '@orpc/shared';
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @example '/rpc?base=1'
|
|
14
|
-
*
|
|
15
|
-
* @default '/'
|
|
16
|
-
*/
|
|
17
|
-
url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
18
|
-
/**
|
|
19
|
-
* The maximum length of the URL.
|
|
20
|
-
*
|
|
21
|
-
* If the URL exceeds this length, the codec should use the `fallbackMethod` to send the request with the payload in the body instead of the URL.
|
|
22
|
-
*
|
|
23
|
-
* @default 2083
|
|
24
|
-
*/
|
|
25
|
-
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
26
|
-
/**
|
|
27
|
-
* The method used to make the request.
|
|
28
|
-
*
|
|
29
|
-
* @default 'POST'
|
|
30
|
-
*/
|
|
31
|
-
method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
32
|
-
/**
|
|
33
|
-
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
34
|
-
* GET is not allowed, it's very dangerous.
|
|
35
|
-
*
|
|
36
|
-
* @default 'POST'
|
|
37
|
-
*/
|
|
38
|
-
fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
39
|
-
/**
|
|
40
|
-
* Inject headers to the request.
|
|
41
|
-
*/
|
|
42
|
-
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
43
|
-
/**
|
|
44
|
-
* Override the default RPC serializer.
|
|
45
|
-
*/
|
|
46
|
-
serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
|
|
47
|
-
}
|
|
48
|
-
declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
49
|
-
private readonly baseUrl;
|
|
50
|
-
private readonly maxUrlLength;
|
|
51
|
-
private readonly fallbackMethod;
|
|
52
|
-
private readonly expectedMethod;
|
|
53
|
-
private readonly headers;
|
|
54
|
-
private readonly serializer;
|
|
55
|
-
constructor(options: RPCLinkCodecOptions<T>);
|
|
56
|
-
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
57
|
-
decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
|
|
58
|
-
}
|
|
7
|
+
declare function toHttpPath(path: readonly string[]): HTTPPath;
|
|
8
|
+
declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
|
|
9
|
+
declare function getMalformedResponseErrorCode(status: number): string;
|
|
59
10
|
|
|
60
|
-
export {
|
|
61
|
-
export type { RPCLinkCodecOptions };
|
|
11
|
+
export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
|
|
@@ -1,61 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { C as ClientContext, a as ClientOptions } from '../../shared/client.BBZBQID8.js';
|
|
7
|
-
import { e as RPCSerializer } from '../../shared/client.BdItY5DT.js';
|
|
1
|
+
export { C as CompositeStandardLinkPlugin, d as StandardLink, f as StandardLinkClient, S as StandardLinkClientInterceptorOptions, e as StandardLinkCodec, c as StandardLinkInterceptorOptions, b as StandardLinkOptions, a as StandardLinkPlugin } from '../../shared/client.2jUAqzYU.js';
|
|
2
|
+
export { S as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, c as StandardRPCCustomJsonSerializer, b as StandardRPCJsonSerialized, a as StandardRPCJsonSerializedMetaItem, e as StandardRPCJsonSerializer, d as StandardRPCJsonSerializerOptions, g as StandardRPCLink, i as StandardRPCLinkCodec, h as StandardRPCLinkCodecOptions, f as StandardRPCLinkOptions, j as StandardRPCSerializer } from '../../shared/client.B3pNRBih.js';
|
|
3
|
+
import { StandardHeaders } from '@orpc/standard-server';
|
|
4
|
+
import { H as HTTPPath } from '../../shared/client.i2uoJbEp.js';
|
|
5
|
+
import '@orpc/shared';
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @example '/rpc?base=1'
|
|
14
|
-
*
|
|
15
|
-
* @default '/'
|
|
16
|
-
*/
|
|
17
|
-
url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
18
|
-
/**
|
|
19
|
-
* The maximum length of the URL.
|
|
20
|
-
*
|
|
21
|
-
* If the URL exceeds this length, the codec should use the `fallbackMethod` to send the request with the payload in the body instead of the URL.
|
|
22
|
-
*
|
|
23
|
-
* @default 2083
|
|
24
|
-
*/
|
|
25
|
-
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
26
|
-
/**
|
|
27
|
-
* The method used to make the request.
|
|
28
|
-
*
|
|
29
|
-
* @default 'POST'
|
|
30
|
-
*/
|
|
31
|
-
method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
32
|
-
/**
|
|
33
|
-
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
34
|
-
* GET is not allowed, it's very dangerous.
|
|
35
|
-
*
|
|
36
|
-
* @default 'POST'
|
|
37
|
-
*/
|
|
38
|
-
fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
39
|
-
/**
|
|
40
|
-
* Inject headers to the request.
|
|
41
|
-
*/
|
|
42
|
-
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
43
|
-
/**
|
|
44
|
-
* Override the default RPC serializer.
|
|
45
|
-
*/
|
|
46
|
-
serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
|
|
47
|
-
}
|
|
48
|
-
declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
49
|
-
private readonly baseUrl;
|
|
50
|
-
private readonly maxUrlLength;
|
|
51
|
-
private readonly fallbackMethod;
|
|
52
|
-
private readonly expectedMethod;
|
|
53
|
-
private readonly headers;
|
|
54
|
-
private readonly serializer;
|
|
55
|
-
constructor(options: RPCLinkCodecOptions<T>);
|
|
56
|
-
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
57
|
-
decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
|
|
58
|
-
}
|
|
7
|
+
declare function toHttpPath(path: readonly string[]): HTTPPath;
|
|
8
|
+
declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
|
|
9
|
+
declare function getMalformedResponseErrorCode(status: number): string;
|
|
59
10
|
|
|
60
|
-
export {
|
|
61
|
-
export type { RPCLinkCodecOptions };
|
|
11
|
+
export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { C as CompositeStandardLinkPlugin,
|
|
1
|
+
export { C as CompositeStandardLinkPlugin, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLink, d as StandardRPCLinkCodec, e as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath, f as toStandardHeaders } from '../../shared/client.C1VUaWTu.mjs';
|
|
2
2
|
import '@orpc/shared';
|
|
3
|
-
import '@
|
|
4
|
-
import '
|
|
5
|
-
import '
|
|
6
|
-
import '../../shared/client.
|
|
3
|
+
import '@orpc/standard-server';
|
|
4
|
+
import '../../shared/client.DrCRv_sG.mjs';
|
|
5
|
+
import '@orpc/standard-server-fetch';
|
|
6
|
+
import '../../shared/client.BLtwTQUg.mjs';
|
|
@@ -1,121 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { RPCLinkCodecOptions } from '../standard/index.mjs';
|
|
7
|
-
import '../../shared/client.BdItY5DT.mjs';
|
|
1
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
+
import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.mjs';
|
|
3
|
+
import { f as StandardLinkClient } from '../../shared/client.CpCa3si8.mjs';
|
|
4
|
+
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BFAVy68H.mjs';
|
|
5
|
+
import '@orpc/shared';
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Total number of connection attempts for this transport's lifetime.
|
|
13
|
-
* Starts at 1 on the first attempt, increments on every subsequent
|
|
14
|
-
* attempt, and never resets.
|
|
15
|
-
*/
|
|
16
|
-
totalAttempt: number;
|
|
17
|
-
/**
|
|
18
|
-
* Attempt number within the current (re)connect cycle.
|
|
19
|
-
* Starts at 1, increments on each consecutive failure, and resets to 1
|
|
20
|
-
* once a connection succeeds. Use this for backoff calculations.
|
|
21
|
-
*/
|
|
22
|
-
attempt: number;
|
|
7
|
+
interface LinkWebsocketClientOptions {
|
|
8
|
+
websocket: Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
|
|
23
9
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* @default false
|
|
29
|
-
*/
|
|
30
|
-
enabled: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Delay before a (re)connect attempt, in milliseconds.
|
|
33
|
-
*
|
|
34
|
-
* @default info => info.attempt === 1 ? 0 : 2_000
|
|
35
|
-
*/
|
|
36
|
-
delay?: undefined | ((info: WebSocketLinkTransportAttemptInfo) => number);
|
|
37
|
-
/**
|
|
38
|
-
* Maximum number of consecutive failed attempts before giving up.
|
|
39
|
-
* When exceeded, `getConnectedPeer` throws instead of retrying.
|
|
40
|
-
* Should greater than 1
|
|
41
|
-
*
|
|
42
|
-
* @default Infinity
|
|
43
|
-
*/
|
|
44
|
-
maxAttempt?: undefined | number;
|
|
45
|
-
/**
|
|
46
|
-
* Whether to proactively reconnect right after the socket closes,
|
|
47
|
-
* rather than waiting for the next call to trigger reconnection.
|
|
48
|
-
* Reduces latency for the next request.
|
|
49
|
-
*
|
|
50
|
-
* @default { enabled: false }
|
|
51
|
-
*/
|
|
52
|
-
onClose?: undefined | {
|
|
53
|
-
/**
|
|
54
|
-
* Whether to proactively reconnect right after the socket closes,
|
|
55
|
-
* rather than waiting for the next call to trigger reconnection.
|
|
56
|
-
* Reduces latency for the next request.
|
|
57
|
-
*
|
|
58
|
-
* @default false
|
|
59
|
-
*/
|
|
60
|
-
enabled: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Delay before reconnecting after the socket closes, in milliseconds.
|
|
63
|
-
*
|
|
64
|
-
* @default 0
|
|
65
|
-
*/
|
|
66
|
-
delay?: number;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
interface WebSocketLinkTransportOptions<_T extends ClientContext> {
|
|
70
|
-
/**
|
|
71
|
-
* Returns a WebSocket instance for peer communication.
|
|
72
|
-
* Can be async for lazy resolution.
|
|
73
|
-
*/
|
|
74
|
-
connect: (info: WebSocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
|
|
75
|
-
/**
|
|
76
|
-
* Whether to connect immediately on initialization, instead of waiting
|
|
77
|
-
* for the first call. Reduces latency for the first request.
|
|
78
|
-
*
|
|
79
|
-
* @default false
|
|
80
|
-
*/
|
|
81
|
-
connectOnInit?: undefined | boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Reconnection behavior when the connection is lost.
|
|
84
|
-
*
|
|
85
|
-
* @default { enabled: false }
|
|
86
|
-
*/
|
|
87
|
-
reconnect?: undefined | WebSocketLinkTransportReconnectOptions;
|
|
88
|
-
/**
|
|
89
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
90
|
-
*/
|
|
91
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
94
|
-
*/
|
|
95
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
96
|
-
}
|
|
97
|
-
declare class WebSocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
|
|
98
|
-
private readonly connect;
|
|
99
|
-
private readonly reconnectEnabled;
|
|
100
|
-
private readonly reconnectDelay;
|
|
101
|
-
private readonly reconnectMaxAttempt;
|
|
102
|
-
private readonly reconnectOnCloseEnabled;
|
|
103
|
-
private readonly reconnectOnCloseDelay;
|
|
104
|
-
private readonly encodePeerMessageOptions;
|
|
105
|
-
private readonly decodePeerMessageOptions;
|
|
106
|
-
constructor(options: WebSocketLinkTransportOptions<T>);
|
|
107
|
-
send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
108
|
-
private totalAttempt;
|
|
109
|
-
private attempt;
|
|
110
|
-
private current;
|
|
111
|
-
private getConnectedPeer;
|
|
10
|
+
declare class LinkWebsocketClient<T extends ClientContext> implements StandardLinkClient<T> {
|
|
11
|
+
private readonly peer;
|
|
12
|
+
constructor(options: LinkWebsocketClientOptions);
|
|
13
|
+
call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
|
|
112
14
|
}
|
|
113
15
|
|
|
114
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
|
16
|
+
interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkWebsocketClientOptions {
|
|
115
17
|
}
|
|
116
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The RPC Link communicates with the server using the RPC protocol over WebSocket.
|
|
20
|
+
*
|
|
21
|
+
* @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs}
|
|
22
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket WebSocket Adapter Docs}
|
|
23
|
+
*/
|
|
24
|
+
declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
117
25
|
constructor(options: RPCLinkOptions<T>);
|
|
118
26
|
}
|
|
119
27
|
|
|
120
|
-
export {
|
|
121
|
-
export type {
|
|
28
|
+
export { LinkWebsocketClient, RPCLink };
|
|
29
|
+
export type { LinkWebsocketClientOptions, RPCLinkOptions };
|
|
@@ -1,121 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { RPCLinkCodecOptions } from '../standard/index.js';
|
|
7
|
-
import '../../shared/client.BdItY5DT.js';
|
|
1
|
+
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
+
import { b as ClientContext, c as ClientOptions } from '../../shared/client.i2uoJbEp.js';
|
|
3
|
+
import { f as StandardLinkClient } from '../../shared/client.2jUAqzYU.js';
|
|
4
|
+
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.B3pNRBih.js';
|
|
5
|
+
import '@orpc/shared';
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Total number of connection attempts for this transport's lifetime.
|
|
13
|
-
* Starts at 1 on the first attempt, increments on every subsequent
|
|
14
|
-
* attempt, and never resets.
|
|
15
|
-
*/
|
|
16
|
-
totalAttempt: number;
|
|
17
|
-
/**
|
|
18
|
-
* Attempt number within the current (re)connect cycle.
|
|
19
|
-
* Starts at 1, increments on each consecutive failure, and resets to 1
|
|
20
|
-
* once a connection succeeds. Use this for backoff calculations.
|
|
21
|
-
*/
|
|
22
|
-
attempt: number;
|
|
7
|
+
interface LinkWebsocketClientOptions {
|
|
8
|
+
websocket: Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
|
|
23
9
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* @default false
|
|
29
|
-
*/
|
|
30
|
-
enabled: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Delay before a (re)connect attempt, in milliseconds.
|
|
33
|
-
*
|
|
34
|
-
* @default info => info.attempt === 1 ? 0 : 2_000
|
|
35
|
-
*/
|
|
36
|
-
delay?: undefined | ((info: WebSocketLinkTransportAttemptInfo) => number);
|
|
37
|
-
/**
|
|
38
|
-
* Maximum number of consecutive failed attempts before giving up.
|
|
39
|
-
* When exceeded, `getConnectedPeer` throws instead of retrying.
|
|
40
|
-
* Should greater than 1
|
|
41
|
-
*
|
|
42
|
-
* @default Infinity
|
|
43
|
-
*/
|
|
44
|
-
maxAttempt?: undefined | number;
|
|
45
|
-
/**
|
|
46
|
-
* Whether to proactively reconnect right after the socket closes,
|
|
47
|
-
* rather than waiting for the next call to trigger reconnection.
|
|
48
|
-
* Reduces latency for the next request.
|
|
49
|
-
*
|
|
50
|
-
* @default { enabled: false }
|
|
51
|
-
*/
|
|
52
|
-
onClose?: undefined | {
|
|
53
|
-
/**
|
|
54
|
-
* Whether to proactively reconnect right after the socket closes,
|
|
55
|
-
* rather than waiting for the next call to trigger reconnection.
|
|
56
|
-
* Reduces latency for the next request.
|
|
57
|
-
*
|
|
58
|
-
* @default false
|
|
59
|
-
*/
|
|
60
|
-
enabled: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Delay before reconnecting after the socket closes, in milliseconds.
|
|
63
|
-
*
|
|
64
|
-
* @default 0
|
|
65
|
-
*/
|
|
66
|
-
delay?: number;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
interface WebSocketLinkTransportOptions<_T extends ClientContext> {
|
|
70
|
-
/**
|
|
71
|
-
* Returns a WebSocket instance for peer communication.
|
|
72
|
-
* Can be async for lazy resolution.
|
|
73
|
-
*/
|
|
74
|
-
connect: (info: WebSocketLinkTransportAttemptInfo) => Promisable<WebSocketLike>;
|
|
75
|
-
/**
|
|
76
|
-
* Whether to connect immediately on initialization, instead of waiting
|
|
77
|
-
* for the first call. Reduces latency for the first request.
|
|
78
|
-
*
|
|
79
|
-
* @default false
|
|
80
|
-
*/
|
|
81
|
-
connectOnInit?: undefined | boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Reconnection behavior when the connection is lost.
|
|
84
|
-
*
|
|
85
|
-
* @default { enabled: false }
|
|
86
|
-
*/
|
|
87
|
-
reconnect?: undefined | WebSocketLinkTransportReconnectOptions;
|
|
88
|
-
/**
|
|
89
|
-
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
90
|
-
*/
|
|
91
|
-
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
92
|
-
/**
|
|
93
|
-
* Options for decoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
94
|
-
*/
|
|
95
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
96
|
-
}
|
|
97
|
-
declare class WebSocketLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
|
|
98
|
-
private readonly connect;
|
|
99
|
-
private readonly reconnectEnabled;
|
|
100
|
-
private readonly reconnectDelay;
|
|
101
|
-
private readonly reconnectMaxAttempt;
|
|
102
|
-
private readonly reconnectOnCloseEnabled;
|
|
103
|
-
private readonly reconnectOnCloseDelay;
|
|
104
|
-
private readonly encodePeerMessageOptions;
|
|
105
|
-
private readonly decodePeerMessageOptions;
|
|
106
|
-
constructor(options: WebSocketLinkTransportOptions<T>);
|
|
107
|
-
send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
108
|
-
private totalAttempt;
|
|
109
|
-
private attempt;
|
|
110
|
-
private current;
|
|
111
|
-
private getConnectedPeer;
|
|
10
|
+
declare class LinkWebsocketClient<T extends ClientContext> implements StandardLinkClient<T> {
|
|
11
|
+
private readonly peer;
|
|
12
|
+
constructor(options: LinkWebsocketClientOptions);
|
|
13
|
+
call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
|
|
112
14
|
}
|
|
113
15
|
|
|
114
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
|
16
|
+
interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkWebsocketClientOptions {
|
|
115
17
|
}
|
|
116
|
-
|
|
18
|
+
/**
|
|
19
|
+
* The RPC Link communicates with the server using the RPC protocol over WebSocket.
|
|
20
|
+
*
|
|
21
|
+
* @see {@link https://orpc.dev/docs/client/rpc-link RPC Link Docs}
|
|
22
|
+
* @see {@link https://orpc.dev/docs/adapters/websocket WebSocket Adapter Docs}
|
|
23
|
+
*/
|
|
24
|
+
declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
117
25
|
constructor(options: RPCLinkOptions<T>);
|
|
118
26
|
}
|
|
119
27
|
|
|
120
|
-
export {
|
|
121
|
-
export type {
|
|
28
|
+
export { LinkWebsocketClient, RPCLink };
|
|
29
|
+
export type { LinkWebsocketClientOptions, RPCLinkOptions };
|