@vitejs/devtools-rpc 0.0.0-alpha.2 → 0.0.0-alpha.20
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/index.d.mts +15 -0
- package/dist/{index.js → index.mjs} +6 -2
- package/dist/{index-BOWJO778.d.ts → presets/index.d.mts} +1 -1
- package/dist/presets/ws/client.d.mts +13 -0
- package/dist/presets/ws/{client.js → client.mjs} +2 -3
- package/dist/presets/ws/server.d.mts +13 -0
- package/dist/presets/ws/{server.js → server.mjs} +270 -289
- package/package.json +11 -11
- package/dist/index.d.ts +0 -15
- package/dist/presets/index.d.ts +0 -2
- package/dist/presets/index.js +0 -3
- package/dist/presets/ws/client.d.ts +0 -17
- package/dist/presets/ws/server.d.ts +0 -13
- /package/dist/{presets-CXNlz3L-.js → presets/index.mjs} +0 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BirpcGroup, BirpcOptions, BirpcReturn, EventOptions } from "birpc";
|
|
2
|
+
|
|
3
|
+
//#region src/client.d.ts
|
|
4
|
+
declare function createRpcClient<ServerFunctions extends object = Record<string, never>, ClientFunctions extends object = Record<string, never>>(functions: ClientFunctions, options: {
|
|
5
|
+
preset: BirpcOptions<ServerFunctions, ClientFunctions, false>;
|
|
6
|
+
rpcOptions?: Partial<BirpcOptions<ServerFunctions, ClientFunctions, boolean>>;
|
|
7
|
+
}): BirpcReturn<ServerFunctions, ClientFunctions, false>;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/server.d.ts
|
|
10
|
+
declare function createRpcServer<ClientFunctions extends object = Record<string, never>, ServerFunctions extends object = Record<string, never>>(functions: ServerFunctions, options: {
|
|
11
|
+
preset: (rpc: BirpcGroup<ClientFunctions, ServerFunctions, false>) => void;
|
|
12
|
+
rpcOptions?: EventOptions<ClientFunctions, ServerFunctions, false>;
|
|
13
|
+
}): BirpcGroup<ClientFunctions, ServerFunctions, false>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createRpcClient, createRpcServer };
|
|
@@ -6,14 +6,18 @@ function createRpcClient(functions, options) {
|
|
|
6
6
|
return createBirpc(functions, {
|
|
7
7
|
...preset,
|
|
8
8
|
timeout: -1,
|
|
9
|
-
...rpcOptions
|
|
9
|
+
...rpcOptions,
|
|
10
|
+
proxify: false
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
//#endregion
|
|
14
15
|
//#region src/server.ts
|
|
15
16
|
function createRpcServer(functions, options) {
|
|
16
|
-
const rpc = createBirpcGroup(functions, [],
|
|
17
|
+
const rpc = createBirpcGroup(functions, [], {
|
|
18
|
+
...options?.rpcOptions,
|
|
19
|
+
proxify: false
|
|
20
|
+
});
|
|
17
21
|
options?.preset(rpc);
|
|
18
22
|
return rpc;
|
|
19
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BirpcGroup, BirpcOptions, ChannelOptions } from "birpc";
|
|
2
2
|
|
|
3
3
|
//#region src/presets/index.d.ts
|
|
4
|
-
type RpcServerPresetReturnType = <ClientFunctions, ServerFunctions>(rpc: BirpcGroup<ClientFunctions, ServerFunctions>, options?: Pick<BirpcOptions<ClientFunctions>, 'serialize' | 'deserialize'>) => void;
|
|
4
|
+
type RpcServerPresetReturnType = <ClientFunctions extends object, ServerFunctions extends object>(rpc: BirpcGroup<ClientFunctions, ServerFunctions, false>, options?: Pick<BirpcOptions<ClientFunctions, ServerFunctions, false>, 'serialize' | 'deserialize'>) => void;
|
|
5
5
|
type RpcServerPresetBasicType = (...args: any[]) => RpcServerPresetReturnType;
|
|
6
6
|
type RpcServerPreset<T extends RpcServerPresetBasicType> = (...args: Parameters<T>) => RpcServerPresetReturnType;
|
|
7
7
|
declare function defineRpcServerPreset<T extends RpcServerPresetBasicType>(preset: T): RpcServerPreset<T>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RpcClientPreset } from "../index.mjs";
|
|
2
|
+
import { ChannelOptions } from "birpc";
|
|
3
|
+
|
|
4
|
+
//#region src/presets/ws/client.d.ts
|
|
5
|
+
interface WebSocketRpcClientOptions {
|
|
6
|
+
url: string;
|
|
7
|
+
onConnected?: (e: Event) => void;
|
|
8
|
+
onError?: (e: Error) => void;
|
|
9
|
+
onDisconnected?: (e: CloseEvent) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const createWsRpcPreset: RpcClientPreset<(options: WebSocketRpcClientOptions) => ChannelOptions>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { WebSocketRpcClientOptions, createWsRpcPreset };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineRpcClientPreset } from "
|
|
1
|
+
import { defineRpcClientPreset } from "../index.mjs";
|
|
2
2
|
import { parse, stringify } from "structured-clone-es";
|
|
3
3
|
|
|
4
4
|
//#region src/presets/ws/client.ts
|
|
@@ -10,8 +10,7 @@ const createWsRpcPreset = defineRpcClientPreset((options) => {
|
|
|
10
10
|
onConnected(e);
|
|
11
11
|
});
|
|
12
12
|
ws.addEventListener("error", (e) => {
|
|
13
|
-
|
|
14
|
-
onError(_e);
|
|
13
|
+
onError(e instanceof Error ? e : new Error(e.type));
|
|
15
14
|
});
|
|
16
15
|
ws.addEventListener("close", (e) => {
|
|
17
16
|
onDisconnected(e);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RpcServerPreset } from "../index.mjs";
|
|
2
|
+
import { BirpcGroup, BirpcOptions } from "birpc";
|
|
3
|
+
import { WebSocket } from "ws";
|
|
4
|
+
|
|
5
|
+
//#region src/presets/ws/server.d.ts
|
|
6
|
+
interface WebSocketRpcServerOptions {
|
|
7
|
+
port: number;
|
|
8
|
+
onConnected?: (ws: WebSocket) => void;
|
|
9
|
+
onDisconnected?: (ws: WebSocket) => void;
|
|
10
|
+
}
|
|
11
|
+
declare const createWsRpcPreset: RpcServerPreset<(options: WebSocketRpcServerOptions) => <ClientFunctions extends object, ServerFunctions extends object>(rpc: BirpcGroup<ClientFunctions, ServerFunctions, false>, options?: Pick<BirpcOptions<ClientFunctions, ServerFunctions, false>, 'serialize' | 'deserialize'>) => void>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { WebSocketRpcServerOptions, createWsRpcPreset };
|