@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,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { RPCLink, RPCLinkOptions } from "./rpc-link.js";
|
|
2
|
+
import { FetchLinkTransport, FetchLinkTransportOptions } from "./transport.js";
|
|
3
|
+
export { FetchLinkTransport, FetchLinkTransportOptions, RPCLink, RPCLinkOptions };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { RPCLink } from "./rpc-link.js";
|
|
2
|
+
export { FetchLinkTransport } from "./transport.js";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import { ClientContext } from "../../types.js";
|
|
2
|
+
import { StandardLink, StandardLinkOptions } from "../standard/link.js";
|
|
3
|
+
import { RPCLinkCodecOptions } from "../standard/rpc-link-codec.js";
|
|
4
|
+
import "../standard/index.js";
|
|
5
|
+
import { FetchLinkTransportOptions } from "./transport.js";
|
|
6
|
+
export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, FetchLinkTransportOptions<T>, RPCLinkCodecOptions<T> {}
|
|
7
7
|
/**
|
|
8
8
|
* Client link that communicates with an RPC Handler over the Fetch API (HTTP).
|
|
9
9
|
*
|
|
10
10
|
* @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
|
|
11
11
|
*/
|
|
12
12
|
export declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
13
|
-
|
|
14
|
-
}
|
|
13
|
+
constructor(options: RPCLinkOptions<T>);
|
|
14
|
+
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { RPCLinkCodec
|
|
2
|
-
import {
|
|
1
|
+
import { RPCLinkCodec } from "../standard/rpc-link-codec.js";
|
|
2
|
+
import { StandardLink } from "../standard/link.js";
|
|
3
|
+
import { FetchLinkTransport } from "./transport.js";
|
|
4
|
+
// src/adapters/fetch/rpc-link.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
6
|
+
* Client link that communicates with an RPC Handler over the Fetch API (HTTP).
|
|
7
|
+
*
|
|
8
|
+
* @see {@link https://orpc.dev/docs/adapters/fetch-api | Fetch API Adapter}
|
|
9
|
+
*/
|
|
10
|
+
var RPCLink = class extends StandardLink {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
const codec = new RPCLinkCodec(options);
|
|
13
|
+
const transport = new FetchLinkTransport(options);
|
|
14
|
+
super(codec, transport, options);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export { RPCLink };
|
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { ClientContext, ClientOptions } from "../../types.js";
|
|
2
|
+
import { StandardLinkTransport } from "../standard/transport.js";
|
|
3
|
+
import "../standard/index.js";
|
|
4
|
+
import { Promisable, Value } from "@orpc/shared";
|
|
5
|
+
import { StandardLazyResponse, StandardRequest } from "@standard-server/core";
|
|
6
|
+
import { ToFetchBodyOptions } from "@standard-server/fetch";
|
|
6
7
|
export interface FetchLinkTransportOptions<T extends ClientContext> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* @default (url, init) => globalThis.fetch(url, init)
|
|
25
|
-
*/
|
|
26
|
-
fetch?(url: string, init: RequestInit, options: ClientOptions<T>, path: string[]): Promise<Response>;
|
|
8
|
+
/**
|
|
9
|
+
* The origin to prepend to all request URLs, useful for CORS requests.
|
|
10
|
+
*
|
|
11
|
+
* @example 'https://api.example.com'
|
|
12
|
+
* @example 'http://localhost:3000'
|
|
13
|
+
*/
|
|
14
|
+
origin?: Value<Promisable<`https://${string}` | `http://${string}` | ({} & string) | undefined>, [options: ClientOptions<T>, path: string[]]> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Options for how to convert the Standard Request to a Fetch Request, like event stream options, etc.
|
|
17
|
+
*/
|
|
18
|
+
toFetchRequest?: ToFetchBodyOptions | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Override the default fetch implementation.
|
|
21
|
+
*
|
|
22
|
+
* @default (url, init) => globalThis.fetch(url, init)
|
|
23
|
+
*/
|
|
24
|
+
fetch?(url: string, init: RequestInit, options: ClientOptions<T>, path: string[]): Promise<Response>;
|
|
27
25
|
}
|
|
28
26
|
export declare class FetchLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
27
|
+
private readonly origin;
|
|
28
|
+
private readonly fetch;
|
|
29
|
+
private readonly toFetchRequestOptions;
|
|
30
|
+
constructor(options: FetchLinkTransportOptions<T>);
|
|
31
|
+
send(standardRequest: StandardRequest, path: string[], options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
32
|
+
}
|
|
@@ -1,65 +1,51 @@
|
|
|
1
|
-
import { once, value } from
|
|
2
|
-
import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from
|
|
1
|
+
import { once, value } from "@orpc/shared";
|
|
2
|
+
import { toFetchBody, toFetchHeaders, toStandardLazyResponse } from "@standard-server/fetch";
|
|
3
|
+
// src/adapters/fetch/transport.ts
|
|
3
4
|
const GET_SUPPORTED_DUPLEX_MODE = /* @__PURE__ */ once(() => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
5
|
+
try {
|
|
6
|
+
let duplex;
|
|
7
|
+
new Request("https://example.com", {
|
|
8
|
+
method: "POST",
|
|
9
|
+
body: new ReadableStream(),
|
|
10
|
+
get duplex() {
|
|
11
|
+
duplex = "half";
|
|
12
|
+
return "half";
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return duplex;
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
20
19
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const response = await fetch(url, init, options, path);
|
|
54
|
-
// Opaque responses (status 0, no headers or body) would otherwise decode as a successful empty output.
|
|
55
|
-
// Browsers return them for redirects under `redirect: 'manual'` and for cross-origin `no-cors` requests.
|
|
56
|
-
if (response.type === 'opaqueredirect') {
|
|
57
|
-
throw new TypeError("Unexpected opaque redirect response: browsers hide redirects under `redirect: 'manual'`.");
|
|
58
|
-
}
|
|
59
|
-
if (response.type === 'opaque') {
|
|
60
|
-
throw new TypeError('Unexpected opaque response: the response is unreadable, likely due to a no-cors request.');
|
|
61
|
-
}
|
|
62
|
-
const standardResponse = toStandardLazyResponse(response);
|
|
63
|
-
return standardResponse;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
20
|
+
var FetchLinkTransport = class {
|
|
21
|
+
origin;
|
|
22
|
+
fetch;
|
|
23
|
+
toFetchRequestOptions;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.origin = options.origin;
|
|
26
|
+
this.fetch = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
|
|
27
|
+
this.toFetchRequestOptions = options.toFetchRequest;
|
|
28
|
+
}
|
|
29
|
+
async send(standardRequest, path, options) {
|
|
30
|
+
let origin = await value(this.origin, options, path);
|
|
31
|
+
if (origin?.endsWith("/")) origin = origin.slice(0, -1);
|
|
32
|
+
const url = `${origin ?? ""}${standardRequest.url}`;
|
|
33
|
+
const [body, standardHeaders] = toFetchBody(standardRequest.body, standardRequest.headers, this.toFetchRequestOptions);
|
|
34
|
+
const init = {
|
|
35
|
+
body,
|
|
36
|
+
headers: toFetchHeaders(standardHeaders),
|
|
37
|
+
method: standardRequest.method,
|
|
38
|
+
signal: options.signal
|
|
39
|
+
};
|
|
40
|
+
if (body instanceof ReadableStream) {
|
|
41
|
+
const duplex = GET_SUPPORTED_DUPLEX_MODE();
|
|
42
|
+
if (duplex !== void 0) init.duplex = duplex;
|
|
43
|
+
}
|
|
44
|
+
const fetch = this.fetch;
|
|
45
|
+
const response = await fetch(url, init, options, path);
|
|
46
|
+
if (response.type === "opaqueredirect") throw new TypeError("Unexpected opaque redirect response: browsers hide redirects under `redirect: 'manual'`.");
|
|
47
|
+
if (response.type === "opaque") throw new TypeError("Unexpected opaque response: the response is unreadable, likely due to a no-cors request.");
|
|
48
|
+
return toStandardLazyResponse(response);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export { FetchLinkTransport };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BrowserPortLike, MessagePortMainLike, SupportedMessagePort, SupportedMessagePortData, onMessagePortClose, onMessagePortMessage, postMessagePortMessage } from "./message-port.js";
|
|
2
|
+
import { RPCLink, RPCLinkOptions } from "./rpc-link.js";
|
|
3
|
+
import { MessagePortLinkTransport, MessagePortLinkTransportOptions } from "./transport.js";
|
|
4
|
+
export { BrowserPortLike, MessagePortLinkTransport, MessagePortLinkTransportOptions, MessagePortMainLike, RPCLink, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { onMessagePortClose, onMessagePortMessage, postMessagePortMessage } from "./message-port.js";
|
|
2
|
+
export { RPCLink } from "./rpc-link.js";
|
|
3
|
+
export { MessagePortLinkTransport } from "./transport.js";
|
|
@@ -2,28 +2,28 @@
|
|
|
2
2
|
* The message port used by electron in main process
|
|
3
3
|
*/
|
|
4
4
|
export interface MessagePortMainLike {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
on: <T extends string>(event: T, callback: (event?: {
|
|
6
|
+
data: any;
|
|
7
|
+
}) => void) => void;
|
|
8
|
+
postMessage: (data: any, transfer?: any[]) => void;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* The message port used by browser extension
|
|
12
12
|
*/
|
|
13
13
|
export interface BrowserPortLike {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
onMessage: {
|
|
15
|
+
addListener: (callback: (data: any) => void) => void;
|
|
16
|
+
};
|
|
17
|
+
onDisconnect: {
|
|
18
|
+
addListener: (callback: () => void) => void;
|
|
19
|
+
};
|
|
20
|
+
postMessage: (data: any) => void;
|
|
21
21
|
}
|
|
22
|
-
export type SupportedMessagePort = Pick<MessagePort,
|
|
22
|
+
export type SupportedMessagePort = Pick<MessagePort, "addEventListener" | "postMessage"> | MessagePortMainLike | BrowserPortLike;
|
|
23
23
|
/**
|
|
24
24
|
* Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
|
|
25
25
|
*/
|
|
26
26
|
export type SupportedMessagePortData = any;
|
|
27
27
|
export declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
|
|
28
28
|
export declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
|
|
29
|
-
export declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
|
|
29
|
+
export declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
|
|
@@ -1,56 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
else {
|
|
6
|
-
port.postMessage(data);
|
|
7
|
-
}
|
|
1
|
+
// src/adapters/message-port/message-port.ts
|
|
2
|
+
function postMessagePortMessage(port, data, transfer) {
|
|
3
|
+
if (transfer) port.postMessage(data, transfer);
|
|
4
|
+
else port.postMessage(data);
|
|
8
5
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
else if ('onMessage' in port) {
|
|
25
|
-
port.onMessage.addListener((data) => {
|
|
26
|
-
callback(data);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw new Error('Cannot find a addEventListener/on/onMessage method on the port');
|
|
31
|
-
}
|
|
6
|
+
function onMessagePortMessage(port, callback) {
|
|
7
|
+
/**
|
|
8
|
+
* MessagePort in node.js might have "on" method but it pass different parameters vs MessagePortMainLike
|
|
9
|
+
* So we need check "addEventListener" before "on"
|
|
10
|
+
*/
|
|
11
|
+
if ("addEventListener" in port) port.addEventListener("message", (event) => {
|
|
12
|
+
callback(event.data);
|
|
13
|
+
});
|
|
14
|
+
else if ("on" in port) port.on("message", (event) => {
|
|
15
|
+
callback(event?.data);
|
|
16
|
+
});
|
|
17
|
+
else if ("onMessage" in port) port.onMessage.addListener((data) => {
|
|
18
|
+
callback(data);
|
|
19
|
+
});
|
|
20
|
+
else throw new Error("Cannot find a addEventListener/on/onMessage method on the port");
|
|
32
21
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
else if ('onDisconnect' in port) {
|
|
49
|
-
port.onDisconnect.addListener(() => {
|
|
50
|
-
callback();
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
throw new Error('Cannot find a addEventListener/on/onDisconnect method on the port');
|
|
55
|
-
}
|
|
22
|
+
function onMessagePortClose(port, callback) {
|
|
23
|
+
/**
|
|
24
|
+
* MessagePort in node.js might have "on" method but it pass different parameters vs MessagePortMainLike
|
|
25
|
+
* So we need check "addEventListener" before "on"
|
|
26
|
+
*/
|
|
27
|
+
if ("addEventListener" in port) port.addEventListener("close", () => {
|
|
28
|
+
callback();
|
|
29
|
+
});
|
|
30
|
+
else if ("on" in port) port.on("close", () => {
|
|
31
|
+
callback();
|
|
32
|
+
});
|
|
33
|
+
else if ("onDisconnect" in port) port.onDisconnect.addListener(() => {
|
|
34
|
+
callback();
|
|
35
|
+
});
|
|
36
|
+
else throw new Error("Cannot find a addEventListener/on/onDisconnect method on the port");
|
|
56
37
|
}
|
|
38
|
+
export { onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import { ClientContext } from "../../types.js";
|
|
2
|
+
import { StandardLink, StandardLinkOptions } from "../standard/link.js";
|
|
3
|
+
import { RPCLinkCodecOptions } from "../standard/rpc-link-codec.js";
|
|
4
|
+
import "../standard/index.js";
|
|
5
|
+
import { MessagePortLinkTransportOptions } from "./transport.js";
|
|
6
|
+
export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, MessagePortLinkTransportOptions<T>, RPCLinkCodecOptions<T> {}
|
|
7
7
|
/**
|
|
8
8
|
* Client link that communicates with an RPC Handler over a Message Port
|
|
9
9
|
* (e.g. workers, iframes, browser extensions, Electron).
|
|
@@ -11,5 +11,5 @@ export interface RPCLinkOptions<T extends ClientContext> extends StandardLinkOpt
|
|
|
11
11
|
* @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
|
|
12
12
|
*/
|
|
13
13
|
export declare class RPCLink<T extends ClientContext> extends StandardLink<T> {
|
|
14
|
-
|
|
15
|
-
}
|
|
14
|
+
constructor(options: RPCLinkOptions<T>);
|
|
15
|
+
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { RPCLinkCodec
|
|
2
|
-
import {
|
|
1
|
+
import { RPCLinkCodec } from "../standard/rpc-link-codec.js";
|
|
2
|
+
import { StandardLink } from "../standard/link.js";
|
|
3
|
+
import { MessagePortLinkTransport } from "./transport.js";
|
|
4
|
+
// src/adapters/message-port/rpc-link.ts
|
|
3
5
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
6
|
+
* Client link that communicates with an RPC Handler over a Message Port
|
|
7
|
+
* (e.g. workers, iframes, browser extensions, Electron).
|
|
8
|
+
*
|
|
9
|
+
* @see {@link https://orpc.dev/docs/adapters/message-port | Message Port Adapter}
|
|
10
|
+
*/
|
|
11
|
+
var RPCLink = class extends StandardLink {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
const codec = new RPCLinkCodec(options);
|
|
14
|
+
const transport = new MessagePortLinkTransport(options);
|
|
15
|
+
super(codec, transport, options);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export { RPCLink };
|
|
@@ -1,38 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends (message: infer TMessage) => unknown ? TMessage : never;
|
|
1
|
+
import { ClientContext, ClientOptions } from "../../types.js";
|
|
2
|
+
import { StandardLinkTransport } from "../standard/transport.js";
|
|
3
|
+
import "../standard/index.js";
|
|
4
|
+
import { SupportedMessagePort } from "./message-port.js";
|
|
5
|
+
import { Promisable, Value } from "@orpc/shared";
|
|
6
|
+
import { StandardLazyResponse, StandardRequest } from "@standard-server/core";
|
|
7
|
+
import { ClientPeer, DecodePeerMessageOptions, EncodePeerMessageOptions } from "@standard-server/peer";
|
|
8
|
+
type DecodedRequestMessage = ConstructorParameters<typeof ClientPeer>[0] extends ((message: infer TMessage) => unknown) ? TMessage : never;
|
|
9
9
|
export interface MessagePortLinkTransportOptions<_T extends ClientContext> {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* Options for decoding peer messages, such as `prefix` for distinguishing messages on the same channel.
|
|
30
|
-
*/
|
|
31
|
-
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
10
|
+
port: SupportedMessagePort;
|
|
11
|
+
/**
|
|
12
|
+
* By default, oRPC serializes request/response messages to string/binary data before sending over message port.
|
|
13
|
+
* If needed, define this option to utilize full power of [MessagePort: postMessage() method](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/postMessage),
|
|
14
|
+
* such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* **Note**: Returning `null` or `undefined` disables this feature.
|
|
18
|
+
* **Warning**: Make sure your message port supports `transfer` before using this feature.
|
|
19
|
+
*/
|
|
20
|
+
experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]> | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Options for encoding peer messages. such as `prefix` for distinguishing messages on the same channel..
|
|
23
|
+
*/
|
|
24
|
+
encodePeerMessage?: EncodePeerMessageOptions | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Options for decoding peer messages, such as `prefix` for distinguishing messages on the same channel.
|
|
27
|
+
*/
|
|
28
|
+
decodePeerMessage?: DecodePeerMessageOptions | undefined;
|
|
32
29
|
}
|
|
33
30
|
export declare class MessagePortLinkTransport<T extends ClientContext> implements StandardLinkTransport<T> {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
private readonly peer;
|
|
32
|
+
constructor({ port, experimental_transfer, encodePeerMessage: encodePeerMessageOptions, decodePeerMessage: decodePeerMessageOptions }: MessagePortLinkTransportOptions<T>);
|
|
33
|
+
send(standardRequest: StandardRequest, _path: string[], _options: ClientOptions<T>): Promise<StandardLazyResponse>;
|
|
37
34
|
}
|
|
38
|
-
export {};
|
|
35
|
+
export {};
|