zod
zod copied to clipboard
add checks @ `ZodBigInt`.
Hey 👋
This PR adds .gt, .gte, .lt, .lte, .positive, .negative, .nonpositive, .nonnegative, .gigantic (.unsafe), .safe & .multipleOf to ZodBigInt.
closes #1592.
Deploy Preview for guileless-rolypoly-866f8a ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | c465cb4848802e7d6fe3ee33f1647d6eb1264fe8 |
| Latest deploy log | https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/63d7034736fce70009f36b09 |
| Deploy Preview | https://deploy-preview-1711--guileless-rolypoly-866f8a.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site settings.
Thanks Igal! I like a lot of this but I made some changes.
I consolidated ZodBigIntTooSmallIssue into ZodTooSmallIssue by converting minimum: number to minimum: number | bigint. I appreciate the effort to avoid breaking changes on the existing issue types, but I'd rather keep too_big/too_small/etc consolidated into a single issue type.
I got rid of all the .safe()/.unsafe() stuff, since it doesn't apply to bigints - the point of using a bigint is to not worry about being inside the safe integer range. I'd accept a PR to add .safe() to ZodNumber where it'd have more utility. But .gigantic/.unsafe seem unnecessary to me.
Thanks Colin! ⚡
I got rid of all the .safe()/.unsafe() stuff, since it doesn't apply to bigints - the point of using a bigint is to not worry about being inside the safe integer range. I'd accept a PR to add .safe() to ZodNumber where it'd have more utility. But .gigantic/.unsafe seem unnecessary to me.
The use case I was thinking about was a 3rd party library, e.g. a database driver, returning bigint values, but zod consumer knows the underlying value should be in the safe integer range (select count(*) as friends from people left join friendships group by people.id - friends column might return as bigint, but although there's lots of people, most people don't have that many friends). So a helper such as ZodBigInt.safe() allows to describe this explictly and chain with .transform(Number) knowing the parsed underlying value is unchanged.
I'll add a separate PR for ZodNumber.safe() as js behavior with anything beyond Number.MAX_SAFE_INTEGER behaves weirdly.
Done #1753.
The use case I was thinking about was a 3rd party library, e.g. a database driver, returning
bigintvalues, but zod consumer knows the underlying value should be in the safe integer range (select count(*) as friends from people left join friendships group by people.id- friends column might return as bigint, but although there's lots of people, most people don't have that many friends). So a helper such asZodBigInt.safe()allows to describe this explictly and chain with.transform(Number)knowing the parsed underlying value is unchanged.
This makes a lot of sense, sorry.