zod 3.22.0 → 3.22.1
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/lib/index.mjs +16 -8
- package/lib/index.umd.js +16 -8
- package/lib/types.js +10 -8
- package/package.json +1 -1
package/lib/index.mjs
CHANGED
|
@@ -3147,16 +3147,20 @@ class ZodFunction extends ZodType {
|
|
|
3147
3147
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3148
3148
|
const fn = ctx.data;
|
|
3149
3149
|
if (this._def.returns instanceof ZodPromise) {
|
|
3150
|
-
|
|
3150
|
+
// Would love a way to avoid disabling this rule, but we need
|
|
3151
|
+
// an alias (using an arrow function was what caused 2651).
|
|
3152
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3153
|
+
const me = this;
|
|
3154
|
+
return OK(async function (...args) {
|
|
3151
3155
|
const error = new ZodError([]);
|
|
3152
|
-
const parsedArgs = await
|
|
3156
|
+
const parsedArgs = await me._def.args
|
|
3153
3157
|
.parseAsync(args, params)
|
|
3154
3158
|
.catch((e) => {
|
|
3155
3159
|
error.addIssue(makeArgsIssue(args, e));
|
|
3156
3160
|
throw error;
|
|
3157
3161
|
});
|
|
3158
|
-
const result = await fn
|
|
3159
|
-
const parsedReturns = await
|
|
3162
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3163
|
+
const parsedReturns = await me._def.returns._def.type
|
|
3160
3164
|
.parseAsync(result, params)
|
|
3161
3165
|
.catch((e) => {
|
|
3162
3166
|
error.addIssue(makeReturnsIssue(result, e));
|
|
@@ -3166,13 +3170,17 @@ class ZodFunction extends ZodType {
|
|
|
3166
3170
|
});
|
|
3167
3171
|
}
|
|
3168
3172
|
else {
|
|
3169
|
-
|
|
3170
|
-
|
|
3173
|
+
// Would love a way to avoid disabling this rule, but we need
|
|
3174
|
+
// an alias (using an arrow function was what caused 2651).
|
|
3175
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3176
|
+
const me = this;
|
|
3177
|
+
return OK(function (...args) {
|
|
3178
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3171
3179
|
if (!parsedArgs.success) {
|
|
3172
3180
|
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3173
3181
|
}
|
|
3174
|
-
const result = fn
|
|
3175
|
-
const parsedReturns =
|
|
3182
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3183
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3176
3184
|
if (!parsedReturns.success) {
|
|
3177
3185
|
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3178
3186
|
}
|
package/lib/index.umd.js
CHANGED
|
@@ -3153,16 +3153,20 @@
|
|
|
3153
3153
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3154
3154
|
const fn = ctx.data;
|
|
3155
3155
|
if (this._def.returns instanceof ZodPromise) {
|
|
3156
|
-
|
|
3156
|
+
// Would love a way to avoid disabling this rule, but we need
|
|
3157
|
+
// an alias (using an arrow function was what caused 2651).
|
|
3158
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3159
|
+
const me = this;
|
|
3160
|
+
return OK(async function (...args) {
|
|
3157
3161
|
const error = new ZodError([]);
|
|
3158
|
-
const parsedArgs = await
|
|
3162
|
+
const parsedArgs = await me._def.args
|
|
3159
3163
|
.parseAsync(args, params)
|
|
3160
3164
|
.catch((e) => {
|
|
3161
3165
|
error.addIssue(makeArgsIssue(args, e));
|
|
3162
3166
|
throw error;
|
|
3163
3167
|
});
|
|
3164
|
-
const result = await fn
|
|
3165
|
-
const parsedReturns = await
|
|
3168
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3169
|
+
const parsedReturns = await me._def.returns._def.type
|
|
3166
3170
|
.parseAsync(result, params)
|
|
3167
3171
|
.catch((e) => {
|
|
3168
3172
|
error.addIssue(makeReturnsIssue(result, e));
|
|
@@ -3172,13 +3176,17 @@
|
|
|
3172
3176
|
});
|
|
3173
3177
|
}
|
|
3174
3178
|
else {
|
|
3175
|
-
|
|
3176
|
-
|
|
3179
|
+
// Would love a way to avoid disabling this rule, but we need
|
|
3180
|
+
// an alias (using an arrow function was what caused 2651).
|
|
3181
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3182
|
+
const me = this;
|
|
3183
|
+
return OK(function (...args) {
|
|
3184
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3177
3185
|
if (!parsedArgs.success) {
|
|
3178
3186
|
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3179
3187
|
}
|
|
3180
|
-
const result = fn
|
|
3181
|
-
const parsedReturns =
|
|
3188
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3189
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3182
3190
|
if (!parsedReturns.success) {
|
|
3183
3191
|
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3184
3192
|
}
|
package/lib/types.js
CHANGED
|
@@ -2505,16 +2505,17 @@ class ZodFunction extends ZodType {
|
|
|
2505
2505
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
2506
2506
|
const fn = ctx.data;
|
|
2507
2507
|
if (this._def.returns instanceof ZodPromise) {
|
|
2508
|
-
|
|
2508
|
+
const me = this;
|
|
2509
|
+
return (0, parseUtil_1.OK)(async function (...args) {
|
|
2509
2510
|
const error = new ZodError_1.ZodError([]);
|
|
2510
|
-
const parsedArgs = await
|
|
2511
|
+
const parsedArgs = await me._def.args
|
|
2511
2512
|
.parseAsync(args, params)
|
|
2512
2513
|
.catch((e) => {
|
|
2513
2514
|
error.addIssue(makeArgsIssue(args, e));
|
|
2514
2515
|
throw error;
|
|
2515
2516
|
});
|
|
2516
|
-
const result = await fn
|
|
2517
|
-
const parsedReturns = await
|
|
2517
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
2518
|
+
const parsedReturns = await me._def.returns._def.type
|
|
2518
2519
|
.parseAsync(result, params)
|
|
2519
2520
|
.catch((e) => {
|
|
2520
2521
|
error.addIssue(makeReturnsIssue(result, e));
|
|
@@ -2524,13 +2525,14 @@ class ZodFunction extends ZodType {
|
|
|
2524
2525
|
});
|
|
2525
2526
|
}
|
|
2526
2527
|
else {
|
|
2527
|
-
|
|
2528
|
-
|
|
2528
|
+
const me = this;
|
|
2529
|
+
return (0, parseUtil_1.OK)(function (...args) {
|
|
2530
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
2529
2531
|
if (!parsedArgs.success) {
|
|
2530
2532
|
throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
2531
2533
|
}
|
|
2532
|
-
const result = fn
|
|
2533
|
-
const parsedReturns =
|
|
2534
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
2535
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
2534
2536
|
if (!parsedReturns.success) {
|
|
2535
2537
|
throw new ZodError_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
2536
2538
|
}
|