fdarian / prisma-generator-drizzle

A Prisma generator for generating Drizzle schema with ease
88 stars 10 forks source link

fix: if field is a list custom type should also be #53

Open chikof opened 2 months ago

chikof commented 2 months ago

If your field is an array but your custom type is not, drizzle will think that the data you have to enter to create a new entry has to be one instead of a list.

fdarian commented 2 months ago

I believe that the .$type<TType>() helper should allow such mistakes, as the specified TType should serve as the absolute definition for the type. Magically overriding the type could lead to unintended behavior. For instance, defining drizzle.type mod::List[] would lead to .$type<List[][]>.

However as I tested with [], it fails. The fix I think would be to sanitize the type before defining the import.

Ideally, the API should be modified in the future to separate the import and usage. This way, composing and inferring types would not result in errors. For instance, drizzle.type module::Array<Item> and drizzle.type module::Item['one'] aren't supported at the moment.

chikof commented 2 months ago

I also tried with [] haha. Instead of doing it as you showed above drizzle.type module::Array<Item>. I was thinking of just sanitizing the type, as you said, and validate if they tried to import an Array drizzle.type module::Item[].