Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/devtools-rpc/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BirpcOptions } from 'birpc'
import type { BirpcOptions, BirpcReturn } from 'birpc'
import { createBirpc } from 'birpc'

export function createRpcClient<
Expand All @@ -10,7 +10,7 @@ export function createRpcClient<
preset: BirpcOptions<ServerFunctions>
rpcOptions?: Partial<BirpcOptions<ServerFunctions>>
},
) {
): BirpcReturn<ServerFunctions, ClientFunctions> {
const { preset, rpcOptions = {} } = options
return createBirpc<ServerFunctions, ClientFunctions>(functions, {
...preset,
Expand Down
8 changes: 7 additions & 1 deletion packages/devtools-rpc/src/presets/ws/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { RpcClientPreset } from '..'
import { parse, stringify } from 'structured-clone-es'
import { defineRpcClientPreset } from '..'

Expand All @@ -10,7 +11,12 @@ export interface WebSocketRpcClientOptions {

function NOOP() {}

export const createWsRpcPreset = defineRpcClientPreset((options: WebSocketRpcClientOptions) => {
export const createWsRpcPreset: RpcClientPreset<(options: WebSocketRpcClientOptions) => {
on: (handler: (data: string) => void) => void
post: (data: string) => void
serialize: (obj: any) => string
deserialize: (str: string) => unknown
}> = defineRpcClientPreset((options: WebSocketRpcClientOptions) => {
const ws = new WebSocket(options.url)
const {
onConnected = NOOP,
Expand Down
3 changes: 2 additions & 1 deletion packages/devtools-rpc/src/presets/ws/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BirpcGroup, BirpcOptions, ChannelOptions } from 'birpc'
import type { WebSocket } from 'ws'
import type { RpcServerPreset } from '..'
import { parse, stringify } from 'structured-clone-es'
import { WebSocketServer } from 'ws'
import { defineRpcServerPreset } from '..'
Expand All @@ -12,7 +13,7 @@ export interface WebSocketRpcServerOptions {

function NOOP() {}

export const createWsRpcPreset = defineRpcServerPreset((options: WebSocketRpcServerOptions) => {
export const createWsRpcPreset: RpcServerPreset<(options: WebSocketRpcServerOptions) => <ClientFunctions, ServerFunctions>(rpc: BirpcGroup<ClientFunctions, ServerFunctions>, options?: Pick<BirpcOptions<ClientFunctions>, 'serialize' | 'deserialize'>) => void> = defineRpcServerPreset((options: WebSocketRpcServerOptions) => {
const {
port,
onConnected = NOOP,
Expand Down
2 changes: 1 addition & 1 deletion packages/devtools-rpc/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function createRpcServer<
preset: (rpc: BirpcGroup<ClientFunctions, ServerFunctions>) => void
rpcOptions?: EventOptions<ClientFunctions>
},
) {
): BirpcGroup<ClientFunctions, ServerFunctions> {
const rpc = createBirpcGroup<ClientFunctions, ServerFunctions>(functions, [], options?.rpcOptions ?? {})
options?.preset(rpc)

Expand Down
2 changes: 2 additions & 0 deletions packages/devtools-rpc/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ export default defineConfig([{
],
clean: true,
fixedExtension: true,
dts: { isolatedDeclarations: true },
}, {
entry: ['src/presets/ws/client.ts', 'src/presets/ws/server.ts', 'src/presets/index.ts'],
clean: true,
fixedExtension: true,
outDir: 'dist/presets',
dts: { isolatedDeclarations: true },
}])
2 changes: 1 addition & 1 deletion packages/devtools/src/dirs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { fileURLToPath } from 'node:url'

export const distDir = fileURLToPath(new URL('../dist/public', import.meta.url))
export const distDir: string = fileURLToPath(new URL('../dist/public', import.meta.url))
1 change: 1 addition & 0 deletions packages/devtools/tsdown.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export default defineConfig({
clean: false,
target: 'esnext',
fixedExtension: true,
dts: { isolatedDeclarations: true },
})