playlyfe / themis

A blazing fast JSON Schema v4 validator!
Other
60 stars 7 forks source link

Ability to save generated validator code #21

Open NathanRSmith opened 9 years ago

NathanRSmith commented 9 years ago

Hi, I really like how performant Themis is after is generates the validators but, as we know, it can be quite slow in doing the actual generation. Would it be possible to get access to the generated code to save it separately as a pre-prepared validator? This would be very useful when schemas are all known ahead of time and change very slowly.

My immediate use case is for using Themis in the browser. It was simple to use Browserify to bundle it up, but it takes 6 seconds to generate all my validators EVERY TIME the page loads. This would be tolerable when starting a long running service, but is somewhat of a deal-breaker for the front-end. Caching generated validators in separate scripts would be a nice compromise for the cases when all schemas are known beforehand and the generation step could be put into an assert build pipeline.

Thoughts?

NathanRSmith commented 9 years ago

Wow, talk about a quick response time, it appears that this feature already exists since last November! The methods are currently undocumented, but for future visitors, see writeToFile at line 2149 and loadFromFile at line 2403 (commit at time of writing is f4bc33c895aa32b27a931cde887e162e73719bf3).

Documentation for these features would probably be good to add at some point. Thanks!

kumarharsh commented 9 years ago

Hi @NathanRSmith! Yup, this feature of pre-compiling the schemas exists, and as you've rightly deduced, it is in those functions. We're using themis for the backend in our project, where the compiled schemas are cached in-memory, so I presume we didn't give much thought to those functions. You're more than welcome to add to the documentation. @atrniv would certainly love that! :smile: