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

Upgrade and migrate drizzle-valibot to v0.31.0 #2481

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

fabian-hiller
Copy link

@fabian-hiller fabian-hiller commented Jun 9, 2024

This PR is not perfect and not finished as I had many questions. I added some TODO: to the code with more details. I also did not change the pnpm-lock.yaml file because my version of pnpm automatically updates it to lockfileVersion: '9.0'.

There is also another PR migrating to Valibot to v0.31.0 with #2477

Hint: BaseSchema is the type we use internally because it forces us to define all generics. This reduces errors on our end. For end users, Valibot also exports the GenericSchema type, which can be used to simplify the code.

@fabian-hiller fabian-hiller marked this pull request as draft June 9, 2024 13:42
@dankochetov
Copy link
Contributor

@fabian-hiller pnpm-lock is 9.0 now in main so you can update it

@fabian-hiller
Copy link
Author

Done

: PicklistSchema<TColumn['enumValues']>
// TODO: Can we somehow check `.length` to know if it's a string schema with or without a max length check?
? Equal<TColumn['enumValues'], [string, ...string[]]> extends true ? StringSchema<undefined> | SchemaWithPipe<[StringSchema<undefined>, MaxLengthAction<string, number, undefined>]>
: PicklistSchema<TColumn['enumValues'], undefined>
Copy link
Contributor

@emmanuelchucks emmanuelchucks Jun 10, 2024

Choose a reason for hiding this comment

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

Is adding 'readonly' to these lines necessary or is actual meant to be intentionally loose?

Line 102

-  : PicklistSchema<TColumn['enumValues'], undefined>
+  : PicklistSchema<Readonly<TColumn['enumValues']>, undefined>

Line 135

-  [K in keyof TColumns & string]: MaybeOptional<
+  readonly [K in keyof TColumns & string]: MaybeOptional<

Line 151

-  [K in keyof TTable['_']['columns']]: MaybeOptional<
+  readonly [K in keyof TTable['_']['columns']]: MaybeOptional<

Before:
Screenshot 2024-06-10 at 15 59 33

After:
Screenshot 2024-06-10 at 15 59 14

Copy link
Author

Choose a reason for hiding this comment

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

I think readonly is not necessary and is only added by Valibot because we use TypeScript's as const feature for specific generic types.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for clarifying

@fabian-hiller
Copy link
Author

@drizzle-team feel free to take over this PR and reach out if you have any questions. I am happy to help!

@CestDiego
Copy link

What steps would be needed to finish this off from the drizzle-valibot perspective? :)

@fabian-hiller
Copy link
Author

Review my changes and answer or fix my TODO: comments. I am happy to help.

: TColumn extends { enumValues: [string, ...string[]] }
? Equal<TColumn['enumValues'], [string, ...string[]]> extends true ? StringSchema
: PicklistSchema<TColumn['enumValues']>
// TODO: Can we somehow check `.length` to know if it's a string schema with or without a max length check?
Copy link

@N0tExisting N0tExisting Jul 1, 2024

Choose a reason for hiding this comment

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

What do you want to get here exacly?
In theory the following should work, but there is a chance that typescript no longer has the exact information of T["length"] and it has just become number.

type MaybeLength<T extends { length?: number }> =
  T["length"] extends 0 | undefined ? NoLengthType<0> : LengthType<T["length"]>

Copy link
Author

Choose a reason for hiding this comment

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

I was just trying to be more specific about the returned type. I think the Drizzle core team knows how to proceed and are free to modify the code as I am busy with other things.

@fabian-hiller
Copy link
Author

@dankochetov can you review this PR?

@rewnad
Copy link

rewnad commented Jul 27, 2024

any update on this? 🙏🏼

@fabian-hiller
Copy link
Author

Andrew from the Drizzle team told me that they will be reviewing and finalizing it soon.

@CestDiego
Copy link

Is this PR at least in an state that we can patch Drizzle to use it?

@fabian-hiller
Copy link
Author

I am not sure, but I think so.

@camflan
Copy link

camflan commented Aug 27, 2024

Bump, hopefully this isn't lost forever

@fabian-hiller
Copy link
Author

I hope so too 🙏

@camflan
Copy link

camflan commented Aug 27, 2024

@drizzle-team, @dankochetov, @emmanuelchucks I've added a new PR that is up to date with main (#2860) to supercede this one

cc @fabian-hiller @CestDiego @rewnad

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.

7 participants