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

Improve package metadata validation #34

Open
kmturley opened this issue Dec 1, 2024 · 0 comments
Open

Improve package metadata validation #34

kmturley opened this issue Dec 1, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@kmturley
Copy link
Member

kmturley commented Dec 1, 2024

Currently package metadata is committed to git as freely-typed yaml files.
When the Registry is built, Yaml files are converted to JSON and checked with some custom validation logic:
https://github.com/open-audio-stack/open-audio-stack-core/blob/main/src/helpers/package.ts#L86

Things to validate:

  • Field names are correct
  • Required fields are populated
  • Values are valid type
  • Values are valid values
  • Values length, formatting

Essentially it means coming up with a custom validation library, which requires lots of effort and could miss validations and/or contain bugs.

Instead of spending more time on custom validation logic, instead use a validation library which will do it automatically.
JSON schema is one obvious option, but it requires a lot of work to define the JSON schema files. JavaScript does not contain enough information for proper validation, but TypeScript does.

Recommendation to use Zod

Zod is a TypeScript-first schema declaration and validation library. With Zod, you declare a validator once and Zod will automatically infer the static TypeScript type

https://github.com/colinhacks/zod

This allows validators to be defined in TypeScript, which can be used for both Types and for Validations. Reducing the amount of code required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In progress
Development

No branches or pull requests

1 participant