Skip to content

Commit e015103

Browse files
committed
fix: correct args and return properties in defineRpcFunction
1 parent 31d18dd commit e015103

3 files changed

Lines changed: 25 additions & 37 deletions

File tree

packages/core/src/node/rpc/internal/docks-on-launch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import * as v from 'valibot'
44
export const docksOnLaunch = defineRpcFunction({
55
name: 'vite:internal:docks:on-launch',
66
type: 'action',
7-
args: v.string(),
8-
returns: v.void(),
7+
args: [v.string()],
8+
return: v.void(),
99
setup: (context) => {
1010
const launchMap = new Map<string, Promise<void>>()
1111
return {

packages/kit/src/utils/define.ts

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,35 @@
1-
import type { RpcFunctionDefinition, RpcFunctionSetupResult, RpcFunctionType, Thenable } from 'birpc-x'
2-
import type { GenericSchema, InferInput } from 'valibot'
1+
import type { RpcFunctionDefinition, RpcFunctionType } from 'birpc-x'
2+
import type { GenericSchema } from 'valibot'
33
import type { DevToolsNodeContext } from '../types'
44
import { createDefineWrapperWithContext } from 'birpc-x'
55

6-
type InferInputsTuple<AS>
7-
= AS extends readonly GenericSchema[]
8-
? { -readonly [K in keyof AS]: AS[K] extends GenericSchema ? InferInput<AS[K]> : any }
9-
: any[]
10-
116
export interface RpcOptions<
12-
AS,
13-
RS,
147
NAME extends string,
158
TYPE extends RpcFunctionType,
16-
> extends Omit<
17-
RpcFunctionDefinition<
18-
NAME,
19-
TYPE,
20-
InferInputsTuple<AS>,
21-
RS extends GenericSchema ? InferInput<RS> : any,
22-
DevToolsNodeContext
23-
>,
24-
'setup'
25-
> {
9+
A extends any[],
10+
R,
11+
AS extends GenericSchema[] | undefined = undefined,
12+
RS extends GenericSchema | undefined = undefined,
13+
>
14+
extends RpcFunctionDefinition<NAME, TYPE, A, R, DevToolsNodeContext> {
2615
args?: AS
27-
returns?: RS
28-
29-
setup: (ctx: DevToolsNodeContext) => Thenable<
30-
RpcFunctionSetupResult<InferInputsTuple<AS>, RS extends GenericSchema ? InferInput<RS> : any>
31-
>
16+
return?: RS
3217
}
3318

34-
export function defineRpcFunction<AS = undefined, RS = undefined, NAME extends string = string, TYPE extends RpcFunctionType = 'query'>(
35-
options: RpcOptions<AS, RS, NAME, TYPE>,
19+
export function defineRpcFunction<
20+
NAME extends string,
21+
TYPE extends RpcFunctionType,
22+
A extends any[],
23+
R,
24+
AS extends GenericSchema[] | undefined = undefined,
25+
RS extends GenericSchema | undefined = undefined,
26+
>(
27+
options: RpcOptions<NAME, TYPE, A, R, AS, RS>,
3628
) {
37-
const { args: argsSchema, returns: returnsSchema, ...rest } = options
29+
const { args, return: ret, ...rest } = options
3830
const birpc = createDefineWrapperWithContext<DevToolsNodeContext>()
3931

40-
return {
41-
fn: birpc<any, TYPE, InferInputsTuple<AS>, RS extends GenericSchema ? InferInput<RS> : any>({
42-
...rest,
43-
}),
44-
args: argsSchema,
45-
returns: returnsSchema,
46-
}
32+
const fn = birpc(rest)
33+
34+
return fn as typeof fn & { argsSchema?: AS, returnSchema?: RS }
4735
}

packages/vite/src/modules/rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default defineNuxtModule({
1515
devtools: {
1616
setup(ctx) {
1717
for (const fn of rpcFunctions) {
18-
ctx.rpc.register(fn.fn)
18+
ctx.rpc.register(fn)
1919
}
2020
},
2121
},

0 commit comments

Comments
 (0)