Skip to content

Commit 0598e9b

Browse files
committed
noop satisfies Customization
1 parent ceac87c commit 0598e9b

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

packages/convex-helpers/server/customFunctions.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
customCtx,
55
customMutation,
66
customQuery,
7+
NoOp,
78
} from "./customFunctions.js";
89
import { wrapDatabaseWriter } from "./rowLevelSecurity.js";
910
import type { SessionId } from "./sessions.js";
@@ -35,6 +36,7 @@ import {
3536
beforeEach,
3637
describe,
3738
expect,
39+
expectTypeOf,
3840
test,
3941
vi,
4042
} from "vitest";
@@ -519,6 +521,54 @@ describe("custom functions with api auth", () => {
519521
});
520522

521523
describe("custom functions", () => {
524+
test("noop", async () => {
525+
const noopQuery = customQuery(query, NoOp);
526+
const noopQueryFn = noopQuery({
527+
args: { foo: v.string() },
528+
handler: async (ctx, args) => {
529+
return { bar: args.foo };
530+
},
531+
});
532+
queryMatches(noopQueryFn, { foo: "" }, { bar: "" });
533+
const sameQuery = query({
534+
args: { foo: v.string() },
535+
handler: async (ctx, args) => {
536+
return { bar: args.foo };
537+
},
538+
});
539+
expectTypeOf(noopQueryFn).toEqualTypeOf(sameQuery);
540+
541+
const noopMutation = customMutation(mutation, NoOp);
542+
const noopMutationFn = noopMutation({
543+
args: { foo: v.string() },
544+
handler: async (ctx, args) => {
545+
return { bar: args.foo };
546+
},
547+
});
548+
const sameMutation = mutation({
549+
args: { foo: v.string() },
550+
handler: async (ctx, args) => {
551+
return { bar: args.foo };
552+
},
553+
});
554+
expectTypeOf(noopMutationFn).toEqualTypeOf(sameMutation);
555+
556+
const noopAction = customAction(action, NoOp);
557+
const noopActionFn = noopAction({
558+
args: { foo: v.string() },
559+
handler: async (ctx, args) => {
560+
return { bar: args.foo };
561+
},
562+
});
563+
const sameAction = action({
564+
args: { foo: v.string() },
565+
handler: async (ctx, args) => {
566+
return { bar: args.foo };
567+
},
568+
});
569+
expectTypeOf(noopActionFn).toEqualTypeOf(sameAction);
570+
});
571+
522572
test("add args", async () => {
523573
const t = convexTest(schema, modules);
524574
expect(await t.query(testApi.add, {})).toMatchObject({

packages/convex-helpers/server/customFunctions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export const NoOp = {
200200
input() {
201201
return { args: {}, ctx: {} };
202202
},
203-
};
203+
} satisfies Customization<any, any, any, any, any>;
204204

205205
/**
206206
* customQuery helps define custom behavior on top of `query` or `internalQuery`

0 commit comments

Comments
 (0)