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

Let's consider a validator #166

Closed
slifty opened this issue Jun 20, 2022 · 0 comments · Fixed by #167
Closed

Let's consider a validator #166

slifty opened this issue Jun 20, 2022 · 0 comments · Fixed by #167
Labels
enhancement New feature or request

Comments

@slifty
Copy link
Member

slifty commented Jun 20, 2022

I recently added a type guard to make payload deserialization safer -- it's written in vanilla javascript which, while certainly fast, is a bit verbose. I explored this a bit in #163.

Joi is a popular and powerful validator, but it is apparently maybe a bit slow. Speed is a major consideration here because of the volume of data that is going to be validated in short time spans.

Ajv is way more used and also, it seems, faster maybe even to the tune of 100x. I get the sense it is less powerful but since we really are just trying to validate at a schema level I think that power would not be needed, and we would value the speed.

All this is to say: I think it would be appropriate for TV Kitchen to add ajv as a dependency and use it to validate all inputs.

@slifty slifty added the enhancement New feature or request label Jun 20, 2022
slifty added a commit that referenced this issue Jun 20, 2022
Ajv is a javascript schema validator that we will be using to validate
runtime types and schemas. From what I have learned it is significantly
faster than Joi.  It also has some nice pairings with TypeScript which
will make it possible to use it to create type guards[1].

[1] https://ajv.js.org/guide/typescript.html

Issue #166
slifty added a commit that referenced this issue Jun 20, 2022
JavaScript's built in Error doesn't let us pass along more detail about
what exactly went wrong.  This custom error allows us to pass that
context along in addition to letting us write more specific tests

Issue #166
slifty added a commit that referenced this issue Jun 20, 2022
This corrects a mistake in the deserialization typeguards related to
decoded Buffer data.  It also updates Payload to use the new
ValidationError which exposes more detail about what exactly is going
wrong on a failure.

Issue #166
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
None yet
Development

Successfully merging a pull request may close this issue.

1 participant