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

feat(astro): improved validators #11195

Merged
merged 6 commits into from
Jun 10, 2024

Conversation

florian-lefebvre
Copy link
Member

@florian-lefebvre florian-lefebvre commented Jun 6, 2024

Changes

  • Adds support for enums
  • Add more validation rules
  • Simplifies envField types

Testing

Added unit tests

Docs

N/A

Verified

This commit was signed with the committer’s verified signature.
henryiii Henry Schreiner
Copy link

changeset-bot bot commented Jun 6, 2024

🦋 Changeset detected

Latest commit: c4127d2

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jun 6, 2024

Verified

This commit was signed with the committer’s verified signature.
henryiii Henry Schreiner

Verified

This commit was signed with the committer’s verified signature.
mayeut Matthieu Darbois

Verified

This commit was signed with the committer’s verified signature.
mayeut Matthieu Darbois
@florian-lefebvre florian-lefebvre marked this pull request as ready for review June 6, 2024 15:09
@matthewp
Copy link
Contributor

matthewp commented Jun 6, 2024

Can you update the RFC with these types?

url: true,
includes: 'foo',
startsWith: 'bar',
endsWith: 'baz'
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the reason we can't have a check(value: string) => boolean sort of thing is because this needs to happen at runtime, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah exactly, everything has to be serializable

max: 32,
min: 3,
length: 12,
url: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this do, does it turn it into a URL object? If so I feel like a new type of URL, envField.url() might be better.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the equivalent of z.string().url(), so it only returns a string that is a valid url. Happy to add envField.url if some users request it

@florian-lefebvre
Copy link
Member Author

I updated the RFC

@florian-lefebvre florian-lefebvre requested a review from matthewp June 7, 2024 15:29
export type EnumFieldInput<T extends string> = Prettify<
_FieldInput<typeof EnumSchema, 'type' | 'values' | 'default'> & {
values: Array<T>;
default?: NoInfer<T> | undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

This has been released in TS 5.4, could that be an issue?

Copy link
Member

Choose a reason for hiding this comment

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

No, it should not

@ematipico
Copy link
Member

Can we merge this one @florian-lefebvre ?

@florian-lefebvre
Copy link
Member Author

Yes, I was waiting in case Matthew wanted to follow up on the reviews

@florian-lefebvre florian-lefebvre merged commit 0a6ab6f into main Jun 10, 2024
13 checks passed
@florian-lefebvre florian-lefebvre deleted the feat/astro-env-improved-validators branch June 10, 2024 11:40
@astrobot-houston astrobot-houston mentioned this pull request Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants