Skip to content

fix date string zod validation #355

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

Merged
merged 8 commits into from
Apr 22, 2023
Merged

fix date string zod validation #355

merged 8 commits into from
Apr 22, 2023

Conversation

Xemah
Copy link
Contributor

@Xemah Xemah commented Apr 18, 2023

No description provided.

@ymc9 ymc9 changed the base branch from main to dev April 18, 2023 15:43
@@ -114,7 +114,7 @@ export default class Transformer {
} else if (inputType.type === 'Boolean') {
result.push(this.wrapWithZodValidators('z.boolean()', field, inputType));
} else if (inputType.type === 'DateTime') {
result.push(this.wrapWithZodValidators('z.date()', field, inputType));
result.push(this.wrapWithZodValidators('z.union([z.date(), z.string().datetime()])', field, inputType));
Copy link
Member

@ymc9 ymc9 Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for working on this @Xemah !

I tried it out, and there's a problem with the distribution of union over array:

image

image

Here the inferred type doesn't conform to Prisma filter's typing. The union needs to wrap around array. Maybe we should refactor wrapWithZodValidators and and pass in a list of validators so we can deal with the array distribution inside of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, we have to do like if its a union, then use '.array()' for each of the rule inside union
Like if it's z.union([z.date(), z.string().datetime()]), it should do z.union([z.date().array(), z.string().datetime().array()])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so.

@ymc9 ymc9 changed the base branch from dev to fix/zod-date April 22, 2023 00:48
@ymc9 ymc9 merged commit c3493e7 into zenstackhq:fix/zod-date Apr 22, 2023
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.

2 participants