Skip to content

Commit

Permalink
Allow handler to return a promise when using PropertyValidators (#31895)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: f210a4fb93772b0fa2c4dbca3561622e5ea2d157
  • Loading branch information
goffrie authored and Convex, Inc. committed Dec 3, 2024
1 parent 188918f commit 174ccc8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/server/registration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,36 @@ describe("argument and return value validators can be objects or validators", ()
},
}),

queryAsync: query({
args: v.object({
arg: v.string(),
}),
returns: { arg: v.string() },
handler: async (_, { arg }) => {
return { arg: arg };
},
}),

mutationAsync: mutation({
args: v.object({
arg: v.string(),
}),
returns: { arg: v.string() },
handler: async (_, { arg }) => {
return { arg: arg };
},
}),

actionAsync: action({
args: v.object({
arg: v.string(),
}),
returns: { arg: v.string() },
handler: async (_, { arg }) => {
return { arg: arg };
},
}),

// This is syntx that we no longer want to support when typechecking because they result in undefined behavior.
mutationNoOptionalValidators: mutation({
// @ts-expect-error Optional validators are not supported at the top level
Expand Down
2 changes: 1 addition & 1 deletion src/server/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export type ReturnValueForOptionalValidator<
> = [ReturnsValidator] extends [Validator<any, any, any>]
? ValidatorTypeToReturnType<Infer<ReturnsValidator>>
: [ReturnsValidator] extends [PropertyValidators]
? ObjectType<ReturnsValidator>
? ValidatorTypeToReturnType<ObjectType<ReturnsValidator>>
: any;

export type ArgsArrayForOptionalValidator<
Expand Down

0 comments on commit 174ccc8

Please sign in to comment.