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.
- package/dist/internal/custom.d.ts +6 -6
- package/dist/internal/custom.d.ts.map +1 -1
- package/dist/internal/functionContracts.d.ts +1 -1
- package/dist/internal/functionContracts.d.ts.map +1 -1
- package/dist/internal/init.d.ts +24 -3
- package/dist/internal/init.d.ts.map +1 -1
- package/dist/legacy/index.js +13 -12
- package/dist/legacy/index.js.map +1 -1
- package/dist/mini/server/index.js +13 -12
- package/dist/mini/server/index.js.map +1 -1
- package/dist/server/index.js +13 -12
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
- package/src/internal/custom.ts +32 -11
- package/src/internal/functionContracts.ts +11 -9
- package/src/internal/init.ts +36 -8
|
@@ -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
|
-
|
|
811
|
-
|
|
812
|
-
|
|
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
|
|
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);
|