@orpc/client 1.14.6 → 2.0.0-beta.10
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 +78 -107
- package/dist/adapters/fetch/index.d.mts +54 -35
- package/dist/adapters/fetch/index.d.ts +54 -35
- package/dist/adapters/fetch/index.mjs +49 -27
- 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 +59 -9
- package/dist/adapters/standard/index.d.ts +59 -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.BN52ep3E.mjs +174 -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.D3TIIok6.mjs +343 -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,46 +1,68 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import '@
|
|
5
|
-
import '../../shared/client.
|
|
6
|
-
import '../../shared/client.
|
|
1
|
+
import { sortPlugins, value, intercept } from '@orpc/shared';
|
|
2
|
+
import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from '@standardserver/fetch';
|
|
3
|
+
import { S as StandardLink, R as RPCLinkCodec } from '../../shared/client.BN52ep3E.mjs';
|
|
4
|
+
import '@standardserver/core';
|
|
5
|
+
import '../../shared/client.Dnfj8jnT.mjs';
|
|
6
|
+
import '../../shared/client.D3TIIok6.mjs';
|
|
7
7
|
|
|
8
|
-
class
|
|
9
|
-
|
|
8
|
+
class CompositeFetchLinkTransportPlugin {
|
|
9
|
+
constructor(plugins = []) {
|
|
10
|
+
this.plugins = plugins;
|
|
11
|
+
this.plugins = sortPlugins(plugins);
|
|
12
|
+
}
|
|
13
|
+
name = "~composite/fetch-link-transport";
|
|
14
|
+
initFetchLinkTransportOptions(options) {
|
|
10
15
|
for (const plugin of this.plugins) {
|
|
11
|
-
plugin.
|
|
16
|
+
if (plugin.initFetchLinkTransportOptions) {
|
|
17
|
+
options = plugin.initFetchLinkTransportOptions(options);
|
|
18
|
+
}
|
|
12
19
|
}
|
|
20
|
+
return options;
|
|
13
21
|
}
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
class
|
|
24
|
+
class FetchLinkTransport {
|
|
25
|
+
origin;
|
|
17
26
|
fetch;
|
|
18
27
|
toFetchRequestOptions;
|
|
19
|
-
|
|
28
|
+
fetchInterceptors;
|
|
20
29
|
constructor(options) {
|
|
21
|
-
|
|
22
|
-
|
|
30
|
+
options = new CompositeFetchLinkTransportPlugin(options.plugins).initFetchLinkTransportOptions(options);
|
|
31
|
+
this.origin = options.origin;
|
|
23
32
|
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
24
|
-
this.toFetchRequestOptions = options;
|
|
25
|
-
this.
|
|
33
|
+
this.toFetchRequestOptions = options.toFetchRequest;
|
|
34
|
+
this.fetchInterceptors = options.fetchInterceptors;
|
|
26
35
|
}
|
|
27
|
-
async
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
async send(standardRequest, path, options) {
|
|
37
|
+
let origin = await value(this.origin, options, path);
|
|
38
|
+
if (origin?.endsWith("/")) {
|
|
39
|
+
origin = origin.slice(0, -1);
|
|
40
|
+
}
|
|
41
|
+
const url = `${origin ?? ""}${standardRequest.url}`;
|
|
42
|
+
const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers, this.toFetchRequestOptions);
|
|
43
|
+
const init = {
|
|
44
|
+
body,
|
|
45
|
+
headers: toFetchHeaders(standardHeaders),
|
|
46
|
+
method: standardRequest.method,
|
|
47
|
+
signal: options.signal,
|
|
48
|
+
redirect: "manual"
|
|
49
|
+
};
|
|
50
|
+
const response = await intercept(
|
|
51
|
+
this.fetchInterceptors,
|
|
52
|
+
{ ...options, url, path, init },
|
|
53
|
+
({ url: url2, path: path2, init: init2, ...options2 }) => this.fetch(url2, init2, options2, path2)
|
|
33
54
|
);
|
|
34
|
-
const
|
|
35
|
-
return
|
|
55
|
+
const standardResponse = toStandardLazyResponse(response);
|
|
56
|
+
return standardResponse;
|
|
36
57
|
}
|
|
37
58
|
}
|
|
38
59
|
|
|
39
|
-
class RPCLink extends
|
|
60
|
+
class RPCLink extends StandardLink {
|
|
40
61
|
constructor(options) {
|
|
41
|
-
const
|
|
42
|
-
|
|
62
|
+
const codec = new RPCLinkCodec(options);
|
|
63
|
+
const transport = new FetchLinkTransport(options);
|
|
64
|
+
super(codec, transport, options);
|
|
43
65
|
}
|
|
44
66
|
}
|
|
45
67
|
|
|
46
|
-
export {
|
|
68
|
+
export { CompositeFetchLinkTransportPlugin, FetchLinkTransport, RPCLink };
|
|
@@ -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.BN52ep3E.mjs';
|
|
4
|
+
import '@standardserver/core';
|
|
5
|
+
import '@standardserver/fetch';
|
|
6
|
+
import '../../shared/client.Dnfj8jnT.mjs';
|
|
7
|
+
import '../../shared/client.D3TIIok6.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,61 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
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
|
+
export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
|
|
6
|
+
import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.mjs';
|
|
7
|
+
import { e as RPCSerializer } from '../../shared/client.BdItY5DT.mjs';
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
interface RPCLinkCodecOptions<T extends ClientContext> {
|
|
10
|
+
/**
|
|
11
|
+
* Base url for all requests (without origin). Should match with handler's prefix.
|
|
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
|
+
}
|
|
10
59
|
|
|
11
|
-
export {
|
|
60
|
+
export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
|
|
61
|
+
export type { RPCLinkCodecOptions };
|
|
@@ -1,11 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
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
|
+
export { StandardBody, StandardBodyHint, StandardHeaders, StandardLazyRequest, StandardLazyResponse, StandardMethod, StandardRequest, StandardResponse, StandardUrl } from '@standardserver/core';
|
|
6
|
+
import { C as ClientContext, a as ClientOptions } from '../../shared/client.8ug8I-zu.js';
|
|
7
|
+
import { e as RPCSerializer } from '../../shared/client.BdItY5DT.js';
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
interface RPCLinkCodecOptions<T extends ClientContext> {
|
|
10
|
+
/**
|
|
11
|
+
* Base url for all requests (without origin). Should match with handler's prefix.
|
|
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
|
+
}
|
|
10
59
|
|
|
11
|
-
export {
|
|
60
|
+
export { RPCLinkCodec, StandardLinkCodec, StandardLinkCodecDecodedResponse };
|
|
61
|
+
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.BN52ep3E.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.D3TIIok6.mjs';
|