Skip to content

[docs] Explain the new validation code #940

@gadicc

Description

@gadicc

Explain the rationale and history.

We use our own custom validators, that provide similar(ish) errors as ajv.

  1. "Fast" validators like ajv and others rely on runtime compilation using new Function(). This is fast but is a blocker for Cloudflare Workers and other (secure) environments which can block this. There are some ways to precompile but they don't have all the same features. To remain fast at runtime without precompilation, we have a custom validator that doesn't cover the entire json-schema spec, but rather, only the few features we need. Speed is particularly important for > 1,000 tests we have.

  2. We tried typebox for a while which had the best DX but unfortunately, was not completely stable at time of use, and struggled with certain TS features we needed. But, the biggest deal breaker is the trend for libraries not to export inferred types (so called "slow types"), because of the performance impact. (They're fine for your own main project, if libraries and libraries they depend on are all inferring, things get slow). It also helps to have clear types to use for tsdoc, etc.

  3. TypeScript is the single source of truth.

Anything else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions