@orpc/client 1.14.6 → 2.0.0-beta.2
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 +74 -106
- package/dist/adapters/fetch/index.d.mts +55 -36
- package/dist/adapters/fetch/index.d.ts +55 -36
- package/dist/adapters/fetch/index.mjs +50 -28
- package/dist/adapters/message-port/index.d.mts +25 -30
- package/dist/adapters/message-port/index.d.ts +25 -30
- package/dist/adapters/message-port/index.mjs +33 -29
- package/dist/adapters/standard/index.d.mts +58 -9
- package/dist/adapters/standard/index.d.ts +58 -9
- package/dist/adapters/standard/index.mjs +5 -5
- package/dist/adapters/websocket/index.d.mts +113 -21
- package/dist/adapters/websocket/index.d.ts +113 -21
- package/dist/adapters/websocket/index.mjs +95 -37
- package/dist/index.d.mts +84 -159
- package/dist/index.d.ts +84 -159
- package/dist/index.mjs +76 -34
- package/dist/plugins/index.d.mts +125 -132
- package/dist/plugins/index.d.ts +125 -132
- package/dist/plugins/index.mjs +373 -284
- package/dist/shared/client.8ug8I-zu.d.mts +167 -0
- package/dist/shared/client.8ug8I-zu.d.ts +167 -0
- package/dist/shared/client.BdItY5DT.d.mts +111 -0
- package/dist/shared/client.BdItY5DT.d.ts +111 -0
- package/dist/shared/client.CPF3hX6O.d.ts +96 -0
- package/dist/shared/client.Cby_-GGh.d.mts +96 -0
- package/dist/shared/client.DMXKFDyV.mjs +343 -0
- package/dist/shared/client.DXhchJ84.mjs +174 -0
- package/dist/shared/client.Dnfj8jnT.mjs +92 -0
- package/package.json +7 -7
- package/dist/shared/client.2jUAqzYU.d.ts +0 -45
- package/dist/shared/client.B3pNRBih.d.ts +0 -91
- package/dist/shared/client.BFAVy68H.d.mts +0 -91
- package/dist/shared/client.BLtwTQUg.mjs +0 -40
- package/dist/shared/client.CpCa3si8.d.mts +0 -45
- package/dist/shared/client.D9eWXdBV.mjs +0 -174
- package/dist/shared/client.DLhbktiD.mjs +0 -404
- package/dist/shared/client.i2uoJbEp.d.mts +0 -83
- package/dist/shared/client.i2uoJbEp.d.ts +0 -83
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
|
|
1
2
|
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
-
import { StandardRequest, StandardLazyResponse } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
3
|
+
import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
|
|
4
|
+
import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
5
|
+
import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.Cby_-GGh.mjs';
|
|
6
|
+
import { RPCLinkCodecOptions } from '../standard/index.mjs';
|
|
7
|
+
import '../../shared/client.BdItY5DT.mjs';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* The message port used by electron in main process
|
|
@@ -28,53 +29,47 @@ interface BrowserPortLike {
|
|
|
28
29
|
}
|
|
29
30
|
type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
|
|
30
31
|
/**
|
|
31
|
-
*
|
|
32
|
+
* Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
|
|
32
33
|
*/
|
|
33
34
|
type SupportedMessagePortData = any;
|
|
34
35
|
declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
|
|
35
36
|
declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
|
|
36
37
|
declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
|
|
40
|
+
interface MessagePortLinkTransportOptions<_T extends ClientContext> {
|
|
39
41
|
port: SupportedMessagePort;
|
|
40
42
|
/**
|
|
41
43
|
* By default, oRPC serializes request/response messages to string/binary data before sending over message port.
|
|
42
|
-
* If needed,
|
|
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),
|
|
43
45
|
* such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
|
|
44
46
|
*
|
|
45
47
|
* @remarks
|
|
46
48
|
* - return null | undefined to disable this feature
|
|
47
49
|
*
|
|
48
50
|
* @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}
|
|
58
51
|
*/
|
|
59
52
|
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;
|
|
60
61
|
}
|
|
61
|
-
declare class
|
|
62
|
+
declare class MessagePortLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
|
|
62
63
|
private readonly peer;
|
|
63
|
-
constructor(
|
|
64
|
-
|
|
64
|
+
constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }: MessagePortLinkTransportOptions<T>);
|
|
65
|
+
send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
|
68
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
|
|
68
69
|
}
|
|
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> {
|
|
70
|
+
declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
76
71
|
constructor(options: RPCLinkOptions<T>);
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
export {
|
|
80
|
-
export type { BrowserPortLike,
|
|
74
|
+
export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
75
|
+
export type { BrowserPortLike, MessagePortLinkTransportOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
|
|
1
2
|
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
-
import { StandardRequest, StandardLazyResponse } from '@
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
3
|
+
import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
|
|
4
|
+
import { ClientPeer, EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
5
|
+
import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.CPF3hX6O.js';
|
|
6
|
+
import { RPCLinkCodecOptions } from '../standard/index.js';
|
|
7
|
+
import '../../shared/client.BdItY5DT.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* The message port used by electron in main process
|
|
@@ -28,53 +29,47 @@ interface BrowserPortLike {
|
|
|
28
29
|
}
|
|
29
30
|
type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'> | MessagePortMainLike | BrowserPortLike;
|
|
30
31
|
/**
|
|
31
|
-
*
|
|
32
|
+
* Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
|
|
32
33
|
*/
|
|
33
34
|
type SupportedMessagePortData = any;
|
|
34
35
|
declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
|
|
35
36
|
declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
|
|
36
37
|
declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
|
|
40
|
+
interface MessagePortLinkTransportOptions<_T extends ClientContext> {
|
|
39
41
|
port: SupportedMessagePort;
|
|
40
42
|
/**
|
|
41
43
|
* By default, oRPC serializes request/response messages to string/binary data before sending over message port.
|
|
42
|
-
* If needed,
|
|
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),
|
|
43
45
|
* such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
|
|
44
46
|
*
|
|
45
47
|
* @remarks
|
|
46
48
|
* - return null | undefined to disable this feature
|
|
47
49
|
*
|
|
48
50
|
* @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}
|
|
58
51
|
*/
|
|
59
52
|
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;
|
|
60
61
|
}
|
|
61
|
-
declare class
|
|
62
|
+
declare class MessagePortLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
|
|
62
63
|
private readonly peer;
|
|
63
|
-
constructor(
|
|
64
|
-
|
|
64
|
+
constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }: MessagePortLinkTransportOptions<T>);
|
|
65
|
+
send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
|
68
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
|
|
68
69
|
}
|
|
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> {
|
|
70
|
+
declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
76
71
|
constructor(options: RPCLinkOptions<T>);
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
export {
|
|
80
|
-
export type { BrowserPortLike,
|
|
74
|
+
export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
75
|
+
export type { BrowserPortLike, MessagePortLinkTransportOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { value,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import '@
|
|
5
|
-
import '
|
|
6
|
-
import '
|
|
7
|
-
import '../../shared/client.
|
|
1
|
+
import { value, isPlainObject, toStringOrBytes } from '@orpc/shared';
|
|
2
|
+
import { ClientPeer, encodePeerMessage, decodePeerMessage, isServerPeerSendMessage } from '@standardserver/peer';
|
|
3
|
+
import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.DXhchJ84.mjs';
|
|
4
|
+
import '@standardserver/core';
|
|
5
|
+
import '@standardserver/fetch';
|
|
6
|
+
import '../../shared/client.Dnfj8jnT.mjs';
|
|
7
|
+
import '../../shared/client.DMXKFDyV.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", () => {
|
|
36
36
|
callback();
|
|
37
37
|
});
|
|
38
38
|
} else if ("on" in port) {
|
|
39
|
-
port.on("close",
|
|
39
|
+
port.on("close", () => {
|
|
40
40
|
callback();
|
|
41
41
|
});
|
|
42
42
|
} else if ("onDisconnect" in port) {
|
|
@@ -48,40 +48,44 @@ function onMessagePortClose(port, callback) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
class
|
|
51
|
+
class MessagePortLinkTransport {
|
|
52
52
|
peer;
|
|
53
|
-
constructor(
|
|
54
|
-
this.peer = new
|
|
55
|
-
const
|
|
56
|
-
const transfer = await value(options.experimental_transfer, message, options.port);
|
|
53
|
+
constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }) {
|
|
54
|
+
this.peer = new ClientPeer(async (message) => {
|
|
55
|
+
const transfer = await value(experimental_transfer, message, port);
|
|
57
56
|
if (transfer) {
|
|
58
|
-
postMessagePortMessage(
|
|
57
|
+
postMessagePortMessage(port, message, transfer);
|
|
59
58
|
} else {
|
|
60
|
-
postMessagePortMessage(
|
|
59
|
+
postMessagePortMessage(port, await encodePeerMessage(message, encodePeerMessageOptions));
|
|
61
60
|
}
|
|
62
61
|
});
|
|
63
|
-
onMessagePortMessage(
|
|
64
|
-
if (
|
|
65
|
-
await this.peer.message(
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
onMessagePortMessage(port, async (message) => {
|
|
63
|
+
if (isPlainObject(message)) {
|
|
64
|
+
await this.peer.message(message);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const encodedMessage = await toStringOrBytes(message);
|
|
68
|
+
const result = decodePeerMessage(encodedMessage, decodePeerMessageOptions);
|
|
69
|
+
if (result.matched && isServerPeerSendMessage(result.message)) {
|
|
70
|
+
await this.peer.message(result.message);
|
|
68
71
|
}
|
|
69
72
|
});
|
|
70
|
-
onMessagePortClose(
|
|
73
|
+
onMessagePortClose(port, () => {
|
|
71
74
|
this.peer.close();
|
|
72
75
|
});
|
|
73
76
|
}
|
|
74
|
-
async
|
|
75
|
-
const
|
|
76
|
-
return
|
|
77
|
+
async send(standardRequest, _path, _options) {
|
|
78
|
+
const standardResponse = await this.peer.request(standardRequest);
|
|
79
|
+
return standardResponse;
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
class RPCLink extends
|
|
83
|
+
class RPCLink extends StandardLink {
|
|
81
84
|
constructor(options) {
|
|
82
|
-
const
|
|
83
|
-
|
|
85
|
+
const codec = new RPCLinkCodec(options);
|
|
86
|
+
const transport = new MessagePortLinkTransport(options);
|
|
87
|
+
super(codec, transport, options);
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
export {
|
|
91
|
+
export { MessagePortLinkTransport, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
@@ -1,11 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import '
|
|
1
|
+
import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.Cby_-GGh.mjs';
|
|
2
|
+
export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.Cby_-GGh.mjs';
|
|
3
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
4
|
+
import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core';
|
|
5
|
+
import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
|
|
6
|
+
import { e as RPCSerializer } from '../../shared/client.BdItY5DT.mjs';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
interface RPCLinkCodecOptions<T extends ClientContext> {
|
|
9
|
+
/**
|
|
10
|
+
* Base url for all requests (without origin). Should match with handler's prefix.
|
|
11
|
+
*
|
|
12
|
+
* @example '/rpc?base=1'
|
|
13
|
+
*
|
|
14
|
+
* @default '/'
|
|
15
|
+
*/
|
|
16
|
+
url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
17
|
+
/**
|
|
18
|
+
* The maximum length of the URL.
|
|
19
|
+
*
|
|
20
|
+
* 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.
|
|
21
|
+
*
|
|
22
|
+
* @default 2083
|
|
23
|
+
*/
|
|
24
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
25
|
+
/**
|
|
26
|
+
* The method used to make the request.
|
|
27
|
+
*
|
|
28
|
+
* @default 'POST'
|
|
29
|
+
*/
|
|
30
|
+
method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
31
|
+
/**
|
|
32
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
33
|
+
* GET is not allowed, it's very dangerous.
|
|
34
|
+
*
|
|
35
|
+
* @default 'POST'
|
|
36
|
+
*/
|
|
37
|
+
fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
38
|
+
/**
|
|
39
|
+
* Inject headers to the request.
|
|
40
|
+
*/
|
|
41
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
42
|
+
/**
|
|
43
|
+
* Override the default RPC serializer.
|
|
44
|
+
*/
|
|
45
|
+
serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
|
|
46
|
+
}
|
|
47
|
+
declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
48
|
+
private readonly baseUrl;
|
|
49
|
+
private readonly maxUrlLength;
|
|
50
|
+
private readonly fallbackMethod;
|
|
51
|
+
private readonly expectedMethod;
|
|
52
|
+
private readonly headers;
|
|
53
|
+
private readonly serializer;
|
|
54
|
+
constructor(options: RPCLinkCodecOptions<T>);
|
|
55
|
+
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
56
|
+
decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
|
|
57
|
+
}
|
|
10
58
|
|
|
11
|
-
export {
|
|
59
|
+
export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
|
|
60
|
+
export type { RPCLinkCodecOptions };
|
|
@@ -1,11 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import '
|
|
1
|
+
import { f as StandardLinkCodec, g as StandardLinkCodecDecodedResponse } from '../../shared/client.CPF3hX6O.js';
|
|
2
|
+
export { C as CompositeStandardLinkPlugin, a as StandardLink, h as StandardLinkInterceptor, e as StandardLinkInterceptorOptions, b as StandardLinkOptions, c as StandardLinkPlugin, S as StandardLinkTransport, i as StandardLinkTransportInterceptor, d as StandardLinkTransportInterceptorOptions } from '../../shared/client.CPF3hX6O.js';
|
|
3
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
4
|
+
import { StandardUrl, StandardHeaders, StandardRequest, StandardLazyResponse } from '@standardserver/core';
|
|
5
|
+
import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
|
|
6
|
+
import { e as RPCSerializer } from '../../shared/client.BdItY5DT.js';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
interface RPCLinkCodecOptions<T extends ClientContext> {
|
|
9
|
+
/**
|
|
10
|
+
* Base url for all requests (without origin). Should match with handler's prefix.
|
|
11
|
+
*
|
|
12
|
+
* @example '/rpc?base=1'
|
|
13
|
+
*
|
|
14
|
+
* @default '/'
|
|
15
|
+
*/
|
|
16
|
+
url?: Value<Promisable<StandardUrl>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
17
|
+
/**
|
|
18
|
+
* The maximum length of the URL.
|
|
19
|
+
*
|
|
20
|
+
* 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.
|
|
21
|
+
*
|
|
22
|
+
* @default 2083
|
|
23
|
+
*/
|
|
24
|
+
maxUrlLength?: Value<Promisable<number>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
25
|
+
/**
|
|
26
|
+
* The method used to make the request.
|
|
27
|
+
*
|
|
28
|
+
* @default 'POST'
|
|
29
|
+
*/
|
|
30
|
+
method?: Value<Promisable<'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
31
|
+
/**
|
|
32
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
33
|
+
* GET is not allowed, it's very dangerous.
|
|
34
|
+
*
|
|
35
|
+
* @default 'POST'
|
|
36
|
+
*/
|
|
37
|
+
fallbackMethod?: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
38
|
+
/**
|
|
39
|
+
* Inject headers to the request.
|
|
40
|
+
*/
|
|
41
|
+
headers?: Value<Promisable<StandardHeaders | Headers>, [options: ClientOptions<T>, path: string[], input: unknown]>;
|
|
42
|
+
/**
|
|
43
|
+
* Override the default RPC serializer.
|
|
44
|
+
*/
|
|
45
|
+
serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
|
|
46
|
+
}
|
|
47
|
+
declare class RPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
|
|
48
|
+
private readonly baseUrl;
|
|
49
|
+
private readonly maxUrlLength;
|
|
50
|
+
private readonly fallbackMethod;
|
|
51
|
+
private readonly expectedMethod;
|
|
52
|
+
private readonly headers;
|
|
53
|
+
private readonly serializer;
|
|
54
|
+
constructor(options: RPCLinkCodecOptions<T>);
|
|
55
|
+
encodeInput(input: unknown, path: string[], options: ClientOptions<T>): Promise<StandardRequest>;
|
|
56
|
+
decodeResponse(response: StandardLazyResponse): Promise<StandardLinkCodecDecodedResponse>;
|
|
57
|
+
}
|
|
10
58
|
|
|
11
|
-
export {
|
|
59
|
+
export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
|
|
60
|
+
export type { RPCLinkCodecOptions };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { C as CompositeStandardLinkPlugin,
|
|
1
|
+
export { C as CompositeStandardLinkPlugin, R as RPCLinkCodec, S as StandardLink } from '../../shared/client.DXhchJ84.mjs';
|
|
2
2
|
import '@orpc/shared';
|
|
3
|
-
import '@
|
|
4
|
-
import '
|
|
5
|
-
import '
|
|
6
|
-
import '../../shared/client.
|
|
3
|
+
import '@standardserver/core';
|
|
4
|
+
import '@standardserver/fetch';
|
|
5
|
+
import '../../shared/client.Dnfj8jnT.mjs';
|
|
6
|
+
import '../../shared/client.DMXKFDyV.mjs';
|
|
@@ -1,29 +1,121 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import '
|
|
1
|
+
import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
|
|
2
|
+
import { Promisable } from '@orpc/shared';
|
|
3
|
+
import { StandardRequest, StandardLazyResponse } from '@standardserver/core';
|
|
4
|
+
import { EncodePeerMessageOptions, DecodePeerMessageOptions } from '@standardserver/peer';
|
|
5
|
+
import { S as StandardLinkTransport, a as StandardLink, b as StandardLinkOptions } from '../../shared/client.Cby_-GGh.mjs';
|
|
6
|
+
import { RPCLinkCodecOptions } from '../standard/index.mjs';
|
|
7
|
+
import '../../shared/client.BdItY5DT.mjs';
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
type WebSocketLike = Pick<WebSocket, 'addEventListener' | 'removeEventListener' | 'send' | 'readyState'>;
|
|
10
|
+
interface WebsocketLinkTransportAttemptInfo {
|
|
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;
|
|
9
23
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
interface WebsocketLinkTransportReconnectOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Whether to automatically reconnect when the connection is lost.
|
|
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;
|
|
14
112
|
}
|
|
15
113
|
|
|
16
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
|
114
|
+
interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, WebsocketLinkTransportOptions<T>, RPCLinkCodecOptions<T> {
|
|
17
115
|
}
|
|
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> {
|
|
116
|
+
declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
25
117
|
constructor(options: RPCLinkOptions<T>);
|
|
26
118
|
}
|
|
27
119
|
|
|
28
|
-
export {
|
|
29
|
-
export type {
|
|
120
|
+
export { RPCLink, WebsocketLinkTransport };
|
|
121
|
+
export type { RPCLinkOptions, WebSocketLike, WebsocketLinkTransportAttemptInfo, WebsocketLinkTransportOptions, WebsocketLinkTransportReconnectOptions };
|