zodvex 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -806,15 +806,10 @@ function parseObjectArgsOrThrow(argsSchema, rawArgs) {
806
806
  }
807
807
  return parsed.data;
808
808
  }
809
- async function runCustomizationInput(customInput, ctx, allArgs, inputArgs, extra) {
810
- return await customInput(
811
- ctx,
812
- // Cast justification: customInput expects ObjectType<CustomArgsValidator>, but pick()
813
- // returns Partial<T>. The cast is safe because inputArgs keys are derived from
814
- // CustomArgsValidator at the type level.
815
- pick(allArgs, Object.keys(inputArgs)),
816
- extra
817
- );
809
+ async function runCustomizationInput(customInput, ctx, allArgs, inputArgs, extra, argsSchema) {
810
+ const picked = pick(allArgs, Object.keys(inputArgs));
811
+ const customArgs = argsSchema ? parseObjectArgsOrThrow(argsSchema, picked) : picked;
812
+ return await customInput(ctx, customArgs, extra);
818
813
  }
819
814
  function applyCustomizationResult(ctx, baseArgs, added) {
820
815
  const finalCtx = { ...ctx, ...added?.ctx ?? {} };
@@ -842,7 +837,11 @@ async function finalizeFunctionReturn(result, options) {
842
837
  // src/internal/custom.ts
843
838
  function customFnBuilder(builder, customization) {
844
839
  const customInput = customization.input ?? NoOp.input;
845
- const inputArgs = customization.args ?? NoOp.args;
840
+ const rawInputArgs = customization.args ?? NoOp.args;
841
+ const customArgEntries = Object.entries(rawInputArgs);
842
+ const customArgsAreZod = customArgEntries.length > 0 && customArgEntries.every(([, v7]) => v7 instanceof $ZodType);
843
+ const inputArgs = customArgsAreZod ? zodToConvexFields(rawInputArgs) : rawInputArgs;
844
+ const customArgsSchema = customArgsAreZod ? z.object(rawInputArgs) : void 0;
846
845
  return function customBuilder(fn) {
847
846
  const { args, handler = fn, returns: maybeObject, ...extra } = fn;
848
847
  const skipConvexValidation = fn.skipConvexValidation ?? false;
@@ -865,7 +864,8 @@ function customFnBuilder(builder, customization) {
865
864
  ctx,
866
865
  allArgs,
867
866
  inputArgs,
868
- extra
867
+ extra,
868
+ customArgsSchema
869
869
  );
870
870
  const argKeys = Object.keys(argsValidator);
871
871
  const rawArgs = pick(allArgs, argKeys);
@@ -888,7 +888,8 @@ function customFnBuilder(builder, customization) {
888
888
  ctx,
889
889
  allArgs,
890
890
  inputArgs,
891
- extra
891
+ extra,
892
+ customArgsSchema
892
893
  );
893
894
  const { finalCtx, finalArgs } = applyCustomizationResult(ctx, baseArgs, added);
894
895
  const ret = await handler(finalCtx, finalArgs);