Skip to content

Commit 05e1939

Browse files
committed
fix skipConvexValidation - still do zod validation
1 parent a6099d3 commit 05e1939

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

packages/convex-helpers/server/zod3.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,25 @@ function customFnBuilder(
345345
customization.input ?? NoOp.input;
346346
const inputArgs = customization.args ?? NoOp.args;
347347
return function customBuilder(fn: any): any {
348-
const { args, handler = fn, returns: maybeObject, ...extra } = fn;
348+
const {
349+
args,
350+
handler = fn,
351+
skipConvexValidation = false,
352+
returns: maybeObject,
353+
...extra
354+
} = fn;
349355

350356
const returns =
351357
maybeObject && !(maybeObject instanceof z.ZodType)
352358
? z.object(maybeObject)
353359
: maybeObject;
354360

355361
const returnValidator =
356-
returns && !fn.skipConvexValidation
362+
returns && !skipConvexValidation
357363
? { returns: zodOutputToConvex(returns) }
358364
: null;
359365

360-
if (args && !fn.skipConvexValidation) {
366+
if (args) {
361367
let argsValidator = args;
362368
if (argsValidator instanceof z.ZodType) {
363369
if (argsValidator instanceof z.ZodObject) {
@@ -371,7 +377,9 @@ function customFnBuilder(
371377
}
372378
const convexValidator = zodToConvexFields(argsValidator);
373379
return builder({
374-
args: addFieldsToValidator(convexValidator, inputArgs),
380+
args: skipConvexValidation
381+
? undefined
382+
: addFieldsToValidator(convexValidator, inputArgs),
375383
...returnValidator,
376384
handler: async (ctx: any, allArgs: any) => {
377385
const added = await customInput(
@@ -404,10 +412,10 @@ function customFnBuilder(
404412
},
405413
});
406414
}
407-
if (Object.keys(inputArgs).length > 0 && !fn.skipConvexValidation) {
415+
if (skipConvexValidation && Object.keys(inputArgs).length > 0) {
408416
throw new Error(
409417
"If you're using a custom function with arguments for the input " +
410-
"customization, you must declare the arguments for the function too.",
418+
"customization, you cannot skip convex validation.",
411419
);
412420
}
413421
return builder({

packages/convex-helpers/server/zod4.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -849,19 +849,25 @@ function customFnBuilder(
849849
customization.input ?? NoOp.input;
850850
const inputArgs = customization.args ?? NoOp.args;
851851
return function customBuilder(fn: any): any {
852-
const { args, handler = fn, returns: maybeObject, ...extra } = fn;
852+
const {
853+
args,
854+
handler = fn,
855+
skipConvexValidation = false,
856+
returns: maybeObject,
857+
...extra
858+
} = fn;
853859

854860
const returns =
855861
maybeObject && !(maybeObject instanceof zCore.$ZodType)
856862
? z.object(maybeObject)
857863
: maybeObject;
858864

859865
const returnValidator =
860-
returns && !fn.skipConvexValidation
866+
returns && !skipConvexValidation
861867
? { returns: zodOutputToConvex(returns) }
862868
: null;
863869

864-
if (args && !fn.skipConvexValidation) {
870+
if (args) {
865871
let argsValidator = args;
866872
if (argsValidator instanceof zCore.$ZodType) {
867873
if (argsValidator instanceof zCore.$ZodObject) {
@@ -875,7 +881,9 @@ function customFnBuilder(
875881
}
876882
const convexValidator = zodToConvexFields(argsValidator);
877883
return builder({
878-
args: addFieldsToValidator(convexValidator, inputArgs),
884+
args: skipConvexValidation
885+
? undefined
886+
: addFieldsToValidator(convexValidator, inputArgs),
879887
...returnValidator,
880888
handler: async (ctx: any, allArgs: any) => {
881889
const added = await customInput(
@@ -908,10 +916,10 @@ function customFnBuilder(
908916
},
909917
});
910918
}
911-
if (Object.keys(inputArgs).length > 0 && !fn.skipConvexValidation) {
919+
if (skipConvexValidation && Object.keys(inputArgs).length > 0) {
912920
throw new Error(
913921
"If you're using a custom function with arguments for the input " +
914-
"customization, you must declare the arguments for the function too.",
922+
"customization, you cannot skip convex validation.",
915923
);
916924
}
917925
return builder({

0 commit comments

Comments
 (0)