ExodusMovement / schemasafe

A reasonably safe JSON Schema validator with draft-04/06/07/2019-09/2020-12 support.
https://npmjs.com/@exodus/schemasafe
MIT License
161 stars 12 forks source link

Split validator() from compile() #110

Closed ChALkeR closed 4 years ago

ChALkeR commented 4 years ago

This allows us to add top-level preparation separately, instead of repeating it on every subschema ref compilation or having to use hacks to exclude preparation code from re-running.

I.e. buildSchemas is now called only once, and json check is now explicitly moved to a wrapping function.

That will likely be used to add some other common preparation steps that we will need to run only at top-level.

Makes all schemas be compiled with the exact same option set (as cleanup is now done outside of compile), otherwise things could have been bad in case of complex references between schemas.

This also comes with error() function cleanup as jsonCheck doesn't use it anymore, which gives a ~10x speedup on verboseErrors (without jsonCheck).

codecov-commenter commented 4 years ago

Codecov Report

Merging #110 into master will decrease coverage by 0.12%. The diff coverage is 94.73%.

Impacted Files Coverage Δ
src/index.js 98.82% <94.73%> (-0.21%) :arrow_down:
ChALkeR commented 4 years ago

I think it will be time to move compile into a separate file after this.