@orpc/client 0.0.0-next.e6490f2 → 0.0.0-next.e77ba7d
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 +7 -2
- package/dist/adapters/fetch/index.d.mts +23 -10
- package/dist/adapters/fetch/index.d.ts +23 -10
- package/dist/adapters/fetch/index.mjs +25 -8
- package/dist/adapters/message-port/index.d.mts +36 -15
- package/dist/adapters/message-port/index.d.ts +36 -15
- package/dist/adapters/message-port/index.mjs +30 -14
- package/dist/adapters/standard/index.d.mts +6 -5
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.mjs +4 -2
- package/dist/adapters/websocket/index.d.mts +11 -11
- package/dist/adapters/websocket/index.d.ts +11 -11
- package/dist/adapters/websocket/index.mjs +13 -10
- package/dist/index.d.mts +86 -25
- package/dist/index.d.ts +86 -25
- package/dist/index.mjs +54 -7
- package/dist/plugins/index.d.mts +52 -5
- package/dist/plugins/index.d.ts +52 -5
- package/dist/plugins/index.mjs +121 -25
- package/dist/shared/client.BH1AYT_p.d.mts +83 -0
- package/dist/shared/client.BH1AYT_p.d.ts +83 -0
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/{client.7UM0t5o-.d.ts → client.BxV-mzeR.d.ts} +3 -3
- package/dist/shared/{client.C0KbSWlC.d.ts → client.CPgZaUox.d.mts} +1 -2
- package/dist/shared/{client.BdD8cpjs.d.mts → client.D8lMmWVC.d.mts} +3 -3
- package/dist/shared/{client.BMoG_EdN.d.mts → client.De8SW4Kw.d.ts} +1 -2
- package/dist/shared/{client.CQCGVpTM.mjs → client.DhaRdXZm.mjs} +63 -20
- package/dist/shared/{client.BX0_8bnM.mjs → client.DzB57HRO.mjs} +37 -38
- package/package.json +6 -6
- package/dist/shared/client.4TS_0JaO.d.mts +0 -29
- package/dist/shared/client.4TS_0JaO.d.ts +0 -29
package/README.md
CHANGED
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
18
|
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
19
|
</a>
|
|
20
|
+
<a href="https://deepwiki.com/unnoq/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
20
23
|
</div>
|
|
21
24
|
|
|
22
25
|
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
@@ -30,7 +33,8 @@
|
|
|
30
33
|
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
31
34
|
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
32
35
|
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
33
|
-
-
|
|
36
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
34
38
|
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
35
39
|
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
36
40
|
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
@@ -38,7 +42,6 @@
|
|
|
38
42
|
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
39
43
|
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
40
44
|
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
41
|
-
- **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
|
|
42
45
|
|
|
43
46
|
## Documentation
|
|
44
47
|
|
|
@@ -50,9 +53,11 @@ You can find the full documentation [here](https://orpc.unnoq.com).
|
|
|
50
53
|
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
51
54
|
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
52
55
|
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
56
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
53
57
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
54
58
|
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
55
59
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
56
61
|
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
57
62
|
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
58
63
|
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
@@ -1,23 +1,36 @@
|
|
|
1
|
+
import { Interceptor } from '@orpc/shared';
|
|
1
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
3
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
|
3
|
-
import {
|
|
4
|
-
import { f as StandardLinkClient } from '../../shared/client.
|
|
5
|
-
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.
|
|
6
|
-
import '@orpc/shared';
|
|
4
|
+
import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.mjs';
|
|
5
|
+
import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.CPgZaUox.mjs';
|
|
6
|
+
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.D8lMmWVC.mjs';
|
|
7
7
|
|
|
8
|
-
interface
|
|
9
|
-
|
|
8
|
+
interface LinkFetchPlugin<T extends ClientContext> extends StandardLinkPlugin<T> {
|
|
9
|
+
initRuntimeAdapter?(options: LinkFetchClientOptions<T>): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface LinkFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
13
|
+
request: Request;
|
|
14
|
+
init: {
|
|
10
15
|
redirect?: Request['redirect'];
|
|
11
|
-
}
|
|
16
|
+
};
|
|
17
|
+
path: readonly string[];
|
|
18
|
+
input: unknown;
|
|
19
|
+
}
|
|
20
|
+
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
|
21
|
+
fetch?: (request: Request, init: LinkFetchInterceptorOptions<T>['init'], options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
|
22
|
+
adapterInterceptors?: Interceptor<LinkFetchInterceptorOptions<T>, Promise<Response>>[];
|
|
23
|
+
plugins?: LinkFetchPlugin<T>[];
|
|
12
24
|
}
|
|
13
25
|
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
|
14
26
|
private readonly fetch;
|
|
15
27
|
private readonly toFetchRequestOptions;
|
|
28
|
+
private readonly adapterInterceptors;
|
|
16
29
|
constructor(options: LinkFetchClientOptions<T>);
|
|
17
|
-
call(
|
|
30
|
+
call(standardRequest: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
18
31
|
}
|
|
19
32
|
|
|
20
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
|
33
|
+
interface RPCLinkOptions<T extends ClientContext> extends LinkFetchClientOptions<T>, Omit<StandardRPCLinkOptions<T>, 'plugins'> {
|
|
21
34
|
}
|
|
22
35
|
/**
|
|
23
36
|
* The RPC Link communicates with the server using the RPC protocol.
|
|
@@ -30,4 +43,4 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
|
30
43
|
}
|
|
31
44
|
|
|
32
45
|
export { LinkFetchClient, RPCLink };
|
|
33
|
-
export type { LinkFetchClientOptions, RPCLinkOptions };
|
|
46
|
+
export type { LinkFetchClientOptions, LinkFetchInterceptorOptions, RPCLinkOptions };
|
|
@@ -1,23 +1,36 @@
|
|
|
1
|
+
import { Interceptor } from '@orpc/shared';
|
|
1
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
3
|
import { ToFetchRequestOptions } from '@orpc/standard-server-fetch';
|
|
3
|
-
import {
|
|
4
|
-
import { f as StandardLinkClient } from '../../shared/client.
|
|
5
|
-
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.
|
|
6
|
-
import '@orpc/shared';
|
|
4
|
+
import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.js';
|
|
5
|
+
import { a as StandardLinkPlugin, f as StandardLinkClient } from '../../shared/client.De8SW4Kw.js';
|
|
6
|
+
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BxV-mzeR.js';
|
|
7
7
|
|
|
8
|
-
interface
|
|
9
|
-
|
|
8
|
+
interface LinkFetchPlugin<T extends ClientContext> extends StandardLinkPlugin<T> {
|
|
9
|
+
initRuntimeAdapter?(options: LinkFetchClientOptions<T>): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface LinkFetchInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
|
|
13
|
+
request: Request;
|
|
14
|
+
init: {
|
|
10
15
|
redirect?: Request['redirect'];
|
|
11
|
-
}
|
|
16
|
+
};
|
|
17
|
+
path: readonly string[];
|
|
18
|
+
input: unknown;
|
|
19
|
+
}
|
|
20
|
+
interface LinkFetchClientOptions<T extends ClientContext> extends ToFetchRequestOptions {
|
|
21
|
+
fetch?: (request: Request, init: LinkFetchInterceptorOptions<T>['init'], options: ClientOptions<T>, path: readonly string[], input: unknown) => Promise<Response>;
|
|
22
|
+
adapterInterceptors?: Interceptor<LinkFetchInterceptorOptions<T>, Promise<Response>>[];
|
|
23
|
+
plugins?: LinkFetchPlugin<T>[];
|
|
12
24
|
}
|
|
13
25
|
declare class LinkFetchClient<T extends ClientContext> implements StandardLinkClient<T> {
|
|
14
26
|
private readonly fetch;
|
|
15
27
|
private readonly toFetchRequestOptions;
|
|
28
|
+
private readonly adapterInterceptors;
|
|
16
29
|
constructor(options: LinkFetchClientOptions<T>);
|
|
17
|
-
call(
|
|
30
|
+
call(standardRequest: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
|
|
18
31
|
}
|
|
19
32
|
|
|
20
|
-
interface RPCLinkOptions<T extends ClientContext> extends
|
|
33
|
+
interface RPCLinkOptions<T extends ClientContext> extends LinkFetchClientOptions<T>, Omit<StandardRPCLinkOptions<T>, 'plugins'> {
|
|
21
34
|
}
|
|
22
35
|
/**
|
|
23
36
|
* The RPC Link communicates with the server using the RPC protocol.
|
|
@@ -30,4 +43,4 @@ declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
|
30
43
|
}
|
|
31
44
|
|
|
32
45
|
export { LinkFetchClient, RPCLink };
|
|
33
|
-
export type { LinkFetchClientOptions, RPCLinkOptions };
|
|
46
|
+
export type { LinkFetchClientOptions, LinkFetchInterceptorOptions, RPCLinkOptions };
|
|
@@ -1,20 +1,37 @@
|
|
|
1
|
+
import { toArray, intercept } from '@orpc/shared';
|
|
1
2
|
import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch';
|
|
2
|
-
import '
|
|
3
|
-
import { c as StandardRPCLink } from '../../shared/client.CQCGVpTM.mjs';
|
|
3
|
+
import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.DhaRdXZm.mjs';
|
|
4
4
|
import '@orpc/standard-server';
|
|
5
|
-
import '../../shared/client.
|
|
5
|
+
import '../../shared/client.DzB57HRO.mjs';
|
|
6
|
+
import '../../shared/client.BLtwTQUg.mjs';
|
|
7
|
+
|
|
8
|
+
class CompositeLinkFetchPlugin extends CompositeStandardLinkPlugin {
|
|
9
|
+
initRuntimeAdapter(options) {
|
|
10
|
+
for (const plugin of this.plugins) {
|
|
11
|
+
plugin.initRuntimeAdapter?.(options);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
6
15
|
|
|
7
16
|
class LinkFetchClient {
|
|
8
17
|
fetch;
|
|
9
18
|
toFetchRequestOptions;
|
|
19
|
+
adapterInterceptors;
|
|
10
20
|
constructor(options) {
|
|
11
|
-
|
|
21
|
+
const plugin = new CompositeLinkFetchPlugin(options.plugins);
|
|
22
|
+
plugin.initRuntimeAdapter(options);
|
|
23
|
+
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
12
24
|
this.toFetchRequestOptions = options;
|
|
25
|
+
this.adapterInterceptors = toArray(options.adapterInterceptors);
|
|
13
26
|
}
|
|
14
|
-
async call(
|
|
15
|
-
const
|
|
16
|
-
const fetchResponse = await
|
|
17
|
-
|
|
27
|
+
async call(standardRequest, options, path, input) {
|
|
28
|
+
const request = toFetchRequest(standardRequest, this.toFetchRequestOptions);
|
|
29
|
+
const fetchResponse = await intercept(
|
|
30
|
+
this.adapterInterceptors,
|
|
31
|
+
{ ...options, request, path, input, init: { redirect: "manual" } },
|
|
32
|
+
({ request: request2, path: path2, input: input2, init, ...options2 }) => this.fetch(request2, init, options2, path2, input2)
|
|
33
|
+
);
|
|
34
|
+
const lazyResponse = toStandardLazyResponse(fetchResponse, { signal: request.signal });
|
|
18
35
|
return lazyResponse;
|
|
19
36
|
}
|
|
20
37
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
1
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { f as
|
|
5
|
-
import '
|
|
3
|
+
import { DecodedRequestMessage } from '@orpc/standard-server-peer';
|
|
4
|
+
import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.mjs';
|
|
5
|
+
import { f as StandardLinkClient } from '../../shared/client.CPgZaUox.mjs';
|
|
6
|
+
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.D8lMmWVC.mjs';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* The message port used by electron in main process
|
|
@@ -11,7 +12,7 @@ interface MessagePortMainLike {
|
|
|
11
12
|
on: <T extends string>(event: T, callback: (event?: {
|
|
12
13
|
data: any;
|
|
13
14
|
}) => void) => void;
|
|
14
|
-
postMessage: (data: any) => void;
|
|
15
|
+
postMessage: (data: any, transfer?: any[]) => void;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* The message port used by browser extension
|
|
@@ -29,21 +30,41 @@ type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'
|
|
|
29
30
|
/**
|
|
30
31
|
* Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
|
|
31
32
|
*/
|
|
32
|
-
type SupportedMessagePortData =
|
|
33
|
-
declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData): void;
|
|
33
|
+
type SupportedMessagePortData = any;
|
|
34
|
+
declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
|
|
34
35
|
declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
|
|
35
36
|
declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
|
|
36
37
|
|
|
37
|
-
interface
|
|
38
|
+
interface LinkMessagePortClientOptions {
|
|
38
39
|
port: SupportedMessagePort;
|
|
40
|
+
/**
|
|
41
|
+
* By default, oRPC serializes request/response messages to string/binary data before sending over message port.
|
|
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),
|
|
43
|
+
* such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* - return null | undefined to disable this feature
|
|
47
|
+
*
|
|
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.unnoq.com/docs/adapters/message-port#transfer Message Port Transfer Docs}
|
|
58
|
+
*/
|
|
59
|
+
experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
|
|
39
60
|
}
|
|
40
|
-
declare class
|
|
61
|
+
declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
|
|
41
62
|
private readonly peer;
|
|
42
|
-
constructor(options:
|
|
63
|
+
constructor(options: LinkMessagePortClientOptions);
|
|
43
64
|
call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
|
|
44
65
|
}
|
|
45
66
|
|
|
46
|
-
interface
|
|
67
|
+
interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkMessagePortClientOptions {
|
|
47
68
|
}
|
|
48
69
|
/**
|
|
49
70
|
* The RPC Link for common message port implementations.
|
|
@@ -51,9 +72,9 @@ interface experimental_RPCLinkOptions<T extends ClientContext> extends Omit<Stan
|
|
|
51
72
|
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
|
|
52
73
|
* @see {@link https://orpc.unnoq.com/docs/adapters/message-port Message Port Adapter Docs}
|
|
53
74
|
*/
|
|
54
|
-
declare class
|
|
55
|
-
constructor(options:
|
|
75
|
+
declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
76
|
+
constructor(options: RPCLinkOptions<T>);
|
|
56
77
|
}
|
|
57
78
|
|
|
58
|
-
export {
|
|
59
|
-
export type { BrowserPortLike,
|
|
79
|
+
export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
80
|
+
export type { BrowserPortLike, LinkMessagePortClientOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
1
2
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { f as
|
|
5
|
-
import '
|
|
3
|
+
import { DecodedRequestMessage } from '@orpc/standard-server-peer';
|
|
4
|
+
import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.js';
|
|
5
|
+
import { f as StandardLinkClient } from '../../shared/client.De8SW4Kw.js';
|
|
6
|
+
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BxV-mzeR.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* The message port used by electron in main process
|
|
@@ -11,7 +12,7 @@ interface MessagePortMainLike {
|
|
|
11
12
|
on: <T extends string>(event: T, callback: (event?: {
|
|
12
13
|
data: any;
|
|
13
14
|
}) => void) => void;
|
|
14
|
-
postMessage: (data: any) => void;
|
|
15
|
+
postMessage: (data: any, transfer?: any[]) => void;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* The message port used by browser extension
|
|
@@ -29,21 +30,41 @@ type SupportedMessagePort = Pick<MessagePort, 'addEventListener' | 'postMessage'
|
|
|
29
30
|
/**
|
|
30
31
|
* Message port can support [The structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)
|
|
31
32
|
*/
|
|
32
|
-
type SupportedMessagePortData =
|
|
33
|
-
declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData): void;
|
|
33
|
+
type SupportedMessagePortData = any;
|
|
34
|
+
declare function postMessagePortMessage(port: SupportedMessagePort, data: SupportedMessagePortData, transfer?: any[]): void;
|
|
34
35
|
declare function onMessagePortMessage(port: SupportedMessagePort, callback: (data: SupportedMessagePortData) => void): void;
|
|
35
36
|
declare function onMessagePortClose(port: SupportedMessagePort, callback: () => void): void;
|
|
36
37
|
|
|
37
|
-
interface
|
|
38
|
+
interface LinkMessagePortClientOptions {
|
|
38
39
|
port: SupportedMessagePort;
|
|
40
|
+
/**
|
|
41
|
+
* By default, oRPC serializes request/response messages to string/binary data before sending over message port.
|
|
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),
|
|
43
|
+
* such as transferring ownership of objects to the other side or support unserializable objects like `OffscreenCanvas`.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* - return null | undefined to disable this feature
|
|
47
|
+
*
|
|
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.unnoq.com/docs/adapters/message-port#transfer Message Port Transfer Docs}
|
|
58
|
+
*/
|
|
59
|
+
experimental_transfer?: Value<Promisable<object[] | null | undefined>, [message: DecodedRequestMessage, port: SupportedMessagePort]>;
|
|
39
60
|
}
|
|
40
|
-
declare class
|
|
61
|
+
declare class LinkMessagePortClient<T extends ClientContext> implements StandardLinkClient<T> {
|
|
41
62
|
private readonly peer;
|
|
42
|
-
constructor(options:
|
|
63
|
+
constructor(options: LinkMessagePortClientOptions);
|
|
43
64
|
call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
|
|
44
65
|
}
|
|
45
66
|
|
|
46
|
-
interface
|
|
67
|
+
interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkMessagePortClientOptions {
|
|
47
68
|
}
|
|
48
69
|
/**
|
|
49
70
|
* The RPC Link for common message port implementations.
|
|
@@ -51,9 +72,9 @@ interface experimental_RPCLinkOptions<T extends ClientContext> extends Omit<Stan
|
|
|
51
72
|
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
|
|
52
73
|
* @see {@link https://orpc.unnoq.com/docs/adapters/message-port Message Port Adapter Docs}
|
|
53
74
|
*/
|
|
54
|
-
declare class
|
|
55
|
-
constructor(options:
|
|
75
|
+
declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
76
|
+
constructor(options: RPCLinkOptions<T>);
|
|
56
77
|
}
|
|
57
78
|
|
|
58
|
-
export {
|
|
59
|
-
export type { BrowserPortLike,
|
|
79
|
+
export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
80
|
+
export type { BrowserPortLike, LinkMessagePortClientOptions, MessagePortMainLike, RPCLinkOptions, SupportedMessagePort, SupportedMessagePortData };
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '@orpc/
|
|
3
|
-
import { c as StandardRPCLink } from '../../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.DhaRdXZm.mjs';
|
|
4
4
|
import '@orpc/standard-server';
|
|
5
|
-
import '../../shared/client.
|
|
5
|
+
import '../../shared/client.DzB57HRO.mjs';
|
|
6
|
+
import '@orpc/standard-server-fetch';
|
|
7
|
+
import '../../shared/client.BLtwTQUg.mjs';
|
|
6
8
|
|
|
7
|
-
function postMessagePortMessage(port, data) {
|
|
8
|
-
|
|
9
|
+
function postMessagePortMessage(port, data, transfer) {
|
|
10
|
+
if (transfer) {
|
|
11
|
+
port.postMessage(data, transfer);
|
|
12
|
+
} else {
|
|
13
|
+
port.postMessage(data);
|
|
14
|
+
}
|
|
9
15
|
}
|
|
10
16
|
function onMessagePortMessage(port, callback) {
|
|
11
17
|
if ("addEventListener" in port) {
|
|
@@ -42,14 +48,24 @@ function onMessagePortClose(port, callback) {
|
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
|
|
45
|
-
class
|
|
51
|
+
class LinkMessagePortClient {
|
|
46
52
|
peer;
|
|
47
53
|
constructor(options) {
|
|
48
|
-
this.peer = new
|
|
49
|
-
|
|
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);
|
|
57
|
+
if (transfer) {
|
|
58
|
+
postMessagePortMessage(options.port, serializeRequestMessage(id, type, payload), transfer);
|
|
59
|
+
} else {
|
|
60
|
+
postMessagePortMessage(options.port, await encodeRequestMessage(id, type, payload));
|
|
61
|
+
}
|
|
50
62
|
});
|
|
51
63
|
onMessagePortMessage(options.port, async (message) => {
|
|
52
|
-
|
|
64
|
+
if (isObject(message)) {
|
|
65
|
+
await this.peer.message(deserializeResponseMessage(message));
|
|
66
|
+
} else {
|
|
67
|
+
await this.peer.message(await decodeResponseMessage(message));
|
|
68
|
+
}
|
|
53
69
|
});
|
|
54
70
|
onMessagePortClose(options.port, () => {
|
|
55
71
|
this.peer.close();
|
|
@@ -61,11 +77,11 @@ class experimental_LinkMessagePortClient {
|
|
|
61
77
|
}
|
|
62
78
|
}
|
|
63
79
|
|
|
64
|
-
class
|
|
80
|
+
class RPCLink extends StandardRPCLink {
|
|
65
81
|
constructor(options) {
|
|
66
|
-
const linkClient = new
|
|
67
|
-
super(linkClient, { ...options, url: "orpc
|
|
82
|
+
const linkClient = new LinkMessagePortClient(options);
|
|
83
|
+
super(linkClient, { ...options, url: "orpc://localhost" });
|
|
68
84
|
}
|
|
69
85
|
}
|
|
70
86
|
|
|
71
|
-
export {
|
|
87
|
+
export { LinkMessagePortClient, RPCLink, onMessagePortClose, onMessagePortMessage, postMessagePortMessage };
|
|
@@ -1,10 +1,11 @@
|
|
|
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.
|
|
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.
|
|
3
|
-
import {
|
|
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.CPgZaUox.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.D8lMmWVC.mjs';
|
|
3
|
+
import { StandardHeaders } from '@orpc/standard-server';
|
|
4
|
+
import { H as HTTPPath } from '../../shared/client.BH1AYT_p.mjs';
|
|
4
5
|
import '@orpc/shared';
|
|
5
|
-
import '@orpc/standard-server';
|
|
6
6
|
|
|
7
7
|
declare function toHttpPath(path: readonly string[]): HTTPPath;
|
|
8
|
+
declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
|
|
8
9
|
declare function getMalformedResponseErrorCode(status: number): string;
|
|
9
10
|
|
|
10
|
-
export { getMalformedResponseErrorCode, toHttpPath };
|
|
11
|
+
export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
|
|
@@ -1,10 +1,11 @@
|
|
|
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.
|
|
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.
|
|
3
|
-
import {
|
|
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.De8SW4Kw.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.BxV-mzeR.js';
|
|
3
|
+
import { StandardHeaders } from '@orpc/standard-server';
|
|
4
|
+
import { H as HTTPPath } from '../../shared/client.BH1AYT_p.js';
|
|
4
5
|
import '@orpc/shared';
|
|
5
|
-
import '@orpc/standard-server';
|
|
6
6
|
|
|
7
7
|
declare function toHttpPath(path: readonly string[]): HTTPPath;
|
|
8
|
+
declare function toStandardHeaders(headers: Headers | StandardHeaders): StandardHeaders;
|
|
8
9
|
declare function getMalformedResponseErrorCode(status: number): string;
|
|
9
10
|
|
|
10
|
-
export { getMalformedResponseErrorCode, toHttpPath };
|
|
11
|
+
export { getMalformedResponseErrorCode, toHttpPath, toStandardHeaders };
|
|
@@ -1,4 +1,6 @@
|
|
|
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 } from '../../shared/client.
|
|
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.DhaRdXZm.mjs';
|
|
2
2
|
import '@orpc/shared';
|
|
3
3
|
import '@orpc/standard-server';
|
|
4
|
-
import '../../shared/client.
|
|
4
|
+
import '../../shared/client.DzB57HRO.mjs';
|
|
5
|
+
import '@orpc/standard-server-fetch';
|
|
6
|
+
import '../../shared/client.BLtwTQUg.mjs';
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
-
import {
|
|
3
|
-
import { f as StandardLinkClient } from '../../shared/client.
|
|
4
|
-
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.
|
|
2
|
+
import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.mjs';
|
|
3
|
+
import { f as StandardLinkClient } from '../../shared/client.CPgZaUox.mjs';
|
|
4
|
+
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.D8lMmWVC.mjs';
|
|
5
5
|
import '@orpc/shared';
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
interface LinkWebsocketClientOptions {
|
|
8
8
|
websocket: Pick<WebSocket, 'addEventListener' | 'send' | 'readyState'>;
|
|
9
9
|
}
|
|
10
|
-
declare class
|
|
10
|
+
declare class LinkWebsocketClient<T extends ClientContext> implements StandardLinkClient<T> {
|
|
11
11
|
private readonly peer;
|
|
12
|
-
constructor(options:
|
|
12
|
+
constructor(options: LinkWebsocketClientOptions);
|
|
13
13
|
call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
interface
|
|
16
|
+
interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkWebsocketClientOptions {
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* The RPC Link communicates with the server using the RPC protocol over WebSocket.
|
|
@@ -21,9 +21,9 @@ interface experimental_RPCLinkOptions<T extends ClientContext> extends Omit<Stan
|
|
|
21
21
|
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
|
|
22
22
|
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket WebSocket Adapter Docs}
|
|
23
23
|
*/
|
|
24
|
-
declare class
|
|
25
|
-
constructor(options:
|
|
24
|
+
declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
25
|
+
constructor(options: RPCLinkOptions<T>);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export {
|
|
29
|
-
export type {
|
|
28
|
+
export { LinkWebsocketClient, RPCLink };
|
|
29
|
+
export type { LinkWebsocketClientOptions, RPCLinkOptions };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
2
|
-
import {
|
|
3
|
-
import { f as StandardLinkClient } from '../../shared/client.
|
|
4
|
-
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.
|
|
2
|
+
import { b as ClientContext, c as ClientOptions } from '../../shared/client.BH1AYT_p.js';
|
|
3
|
+
import { f as StandardLinkClient } from '../../shared/client.De8SW4Kw.js';
|
|
4
|
+
import { f as StandardRPCLinkOptions, g as StandardRPCLink } from '../../shared/client.BxV-mzeR.js';
|
|
5
5
|
import '@orpc/shared';
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
interface LinkWebsocketClientOptions {
|
|
8
8
|
websocket: Pick<WebSocket, 'addEventListener' | 'send' | 'readyState'>;
|
|
9
9
|
}
|
|
10
|
-
declare class
|
|
10
|
+
declare class LinkWebsocketClient<T extends ClientContext> implements StandardLinkClient<T> {
|
|
11
11
|
private readonly peer;
|
|
12
|
-
constructor(options:
|
|
12
|
+
constructor(options: LinkWebsocketClientOptions);
|
|
13
13
|
call(request: StandardRequest, _options: ClientOptions<T>, _path: readonly string[], _input: unknown): Promise<StandardLazyResponse>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
interface
|
|
16
|
+
interface RPCLinkOptions<T extends ClientContext> extends Omit<StandardRPCLinkOptions<T>, 'url' | 'method' | 'fallbackMethod' | 'maxUrlLength'>, LinkWebsocketClientOptions {
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* The RPC Link communicates with the server using the RPC protocol over WebSocket.
|
|
@@ -21,9 +21,9 @@ interface experimental_RPCLinkOptions<T extends ClientContext> extends Omit<Stan
|
|
|
21
21
|
* @see {@link https://orpc.unnoq.com/docs/client/rpc-link RPC Link Docs}
|
|
22
22
|
* @see {@link https://orpc.unnoq.com/docs/adapters/websocket WebSocket Adapter Docs}
|
|
23
23
|
*/
|
|
24
|
-
declare class
|
|
25
|
-
constructor(options:
|
|
24
|
+
declare class RPCLink<T extends ClientContext> extends StandardRPCLink<T> {
|
|
25
|
+
constructor(options: RPCLinkOptions<T>);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export {
|
|
29
|
-
export type {
|
|
28
|
+
export { LinkWebsocketClient, RPCLink };
|
|
29
|
+
export type { LinkWebsocketClientOptions, RPCLinkOptions };
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { readAsBuffer } from '@orpc/shared';
|
|
1
2
|
import { ClientPeer } from '@orpc/standard-server-peer';
|
|
2
|
-
import '
|
|
3
|
-
import { c as StandardRPCLink } from '../../shared/client.CQCGVpTM.mjs';
|
|
3
|
+
import { c as StandardRPCLink } from '../../shared/client.DhaRdXZm.mjs';
|
|
4
4
|
import '@orpc/standard-server';
|
|
5
|
-
import '../../shared/client.
|
|
5
|
+
import '../../shared/client.DzB57HRO.mjs';
|
|
6
|
+
import '@orpc/standard-server-fetch';
|
|
7
|
+
import '../../shared/client.BLtwTQUg.mjs';
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
const WEBSOCKET_CONNECTING = 0;
|
|
10
|
+
class LinkWebsocketClient {
|
|
8
11
|
peer;
|
|
9
12
|
constructor(options) {
|
|
10
13
|
const untilOpen = new Promise((resolve) => {
|
|
11
|
-
if (options.websocket.readyState ===
|
|
14
|
+
if (options.websocket.readyState === WEBSOCKET_CONNECTING) {
|
|
12
15
|
options.websocket.addEventListener("open", () => {
|
|
13
16
|
resolve();
|
|
14
17
|
}, { once: true });
|
|
@@ -21,7 +24,7 @@ class experimental_LinkWebsocketClient {
|
|
|
21
24
|
return options.websocket.send(message);
|
|
22
25
|
});
|
|
23
26
|
options.websocket.addEventListener("message", async (event) => {
|
|
24
|
-
const message = event.data instanceof Blob ? await event.data
|
|
27
|
+
const message = event.data instanceof Blob ? await readAsBuffer(event.data) : event.data;
|
|
25
28
|
this.peer.message(message);
|
|
26
29
|
});
|
|
27
30
|
options.websocket.addEventListener("close", () => {
|
|
@@ -34,11 +37,11 @@ class experimental_LinkWebsocketClient {
|
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
class
|
|
40
|
+
class RPCLink extends StandardRPCLink {
|
|
38
41
|
constructor(options) {
|
|
39
|
-
const linkClient = new
|
|
40
|
-
super(linkClient, { ...options, url: "orpc
|
|
42
|
+
const linkClient = new LinkWebsocketClient(options);
|
|
43
|
+
super(linkClient, { ...options, url: "orpc://localhost" });
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
export {
|
|
47
|
+
export { LinkWebsocketClient, RPCLink };
|