fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
5.67k stars 170 forks source link

Add Grit migration script #591

Closed morgante closed 1 month ago

morgante commented 1 month ago

You can try this out by running

grit apply valibot_v03

Grit also includes built-in testing for the markdown file. Just run grit patterns test in this repo.

fabian-hiller commented 1 month ago

You can always copy the output to our playground to see if the transformed code is valid.

fabian-hiller commented 1 month ago

If I run grit apply valibot_v03 I get the following error: Error: Permission denied (os error 13)

fabian-hiller commented 1 month ago

Once I can confirm that the codemod works, I will add instructions on how to run it to our migration guide. Do people need to manually add the .grit/patterns/valibot_v03.md file to their repo to run the command? Does it only works on Linux and MacOS?

morgante commented 1 month ago

If I run grit apply valibot_v03 I get the following error: Error: Permission denied (os error 13)

Hmm, what steps did you take to install it / can you provide reproduction instructions? This isn't expected.

Do people need to manually add the .grit/patterns/valibot_v03.md file to their repo to run the command?

Yes, currently they will need to download it. I'm planning to add a feature for applying remote patterns directly too.

Does it only works on Linux and MacOS?

We also have Windows releases available.

fabian-hiller commented 1 month ago

Hmm, what steps did you take to install it / can you provide reproduction instructions? This isn't expected.

I followed the Quickstart guide and executed: npm install --location=global @getgrit/launcher. I can run grit. So the installation was successful.

I got it to work with sudo but it should work without it. I will test the codemod in the next few days and get back to you. Thanks again!

Yes, currently they will need to download it. I'm planning to add a https://github.com/getgrit/gritql/issues/356 for applying remote patterns directly too. We also have Windows releases available.

👍

morgante commented 1 month ago

I got it to work with sudo but it should work without it.

Agreed, sudo definitely shouldn't be required. Maybe you can try running grit doctor without sudo to figure out why. I'm also happy to help debug on Discord.

fabian-hiller commented 1 month ago

I get the same error when I type grit doctor. With sudo it prints out environment and configuration info. Seems like a permission problem. I will get back to you on Discord tonight or in the next few days. In the meantime, if you have time, you can try to get the following codemod to work.

Hint: transform and brand can be deeply nested and should now be placed next to each other in the pipeline of the wrapped schema.

// Before
const Schema = v.transform(
  v.brand(v.string(), "Name"),
  (input) => input.length
);

// After
const Schema = v.pipe(
  v.string(),
  v.brand('Name'),
  v.transform((input) => input.length)
);
morgante commented 1 month ago

This now handles brand and transform.