Open DavidTimms opened 1 year ago
I tried to start working on the new bigint
features (lt
, gt
, etc.). Unfortunately in this release email validation was broken https://github.com/colinhacks/zod/issues/2396. After upgrading zod
the email test fails with Counterexample: ["a@a.a.aa"]
. I might give it another shot once the email issue is resolved in zod.
Since I only need min/max support for my use-case I patched zod-fast-check
using pnpm patch
/ yarn patch
.
diff --git a/dist/zod-fast-check.js b/dist/zod-fast-check.js
index 43b3f209cb5740f9407b90494a0299d307a35cc2..ef7f4178fffc6891b83fdb491e0ec758def39de7 100644
--- a/dist/zod-fast-check.js
+++ b/dist/zod-fast-check.js
@@ -213,8 +213,22 @@ const arbitraryBuilders = {
}
}
},
- ZodBigInt() {
- return fast_check_1.default.bigInt();
+ ZodBigInt(schema) {
+ let min = undefined;
+ let max = undefined;
+
+ for (const check of schema._def.checks) {
+ switch (check.kind) {
+ case "min":
+ min = min === undefined || check.value < min ? check.value : min;
+ break;
+ case "max":
+ max = max === undefined || check.value > max ? check.value : max;
+ break;
+ }
+ }
+
+ return fast_check_1.default.bigInt({min, max});
},
ZodBoolean() {
return fast_check_1.default.boolean();
The new version of Zod brings new schema features which will need corresponding support in zod-fast-check.
https://github.com/colinhacks/zod/releases/tag/v3.21
Features:
.emoji
.cuid2
.ip
z.bigint().{gt|gte|lt|lte}()
z.enum(...).extract()
andz.enum(...).exclude()
.ulid
.readonly