Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add checks @ ZodBigInt. #1711

Merged
merged 9 commits into from Feb 27, 2023
Merged

Conversation

igalklebanov
Copy link
Contributor

@igalklebanov igalklebanov commented Dec 16, 2022

Hey 👋

This PR adds .gt, .gte, .lt, .lte, .positive, .negative, .nonpositive, .nonnegative & .multipleOf to ZodBigInt.

closes #1592.

@netlify
Copy link

netlify bot commented Dec 16, 2022

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c465cb4
🔍 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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@igalklebanov igalklebanov marked this pull request as ready for review December 17, 2022 02:38
@colinhacks
Copy link
Owner

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.

@igalklebanov
Copy link
Contributor Author

igalklebanov commented Dec 24, 2022

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.

@colinhacks
Copy link
Owner

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.

This makes a lot of sense, sorry.

@colinhacks colinhacks merged commit 75cb9e8 into colinhacks:master Feb 27, 2023
@igalklebanov igalklebanov deleted the big-int-checks branch February 27, 2023 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BigInt refinements
2 participants