Skip to content

v0.76.0

Latest
Compare
Choose a tag to compare
@joshmossas joshmossas released this 23 Feb 15:11

Full Changelog: v0.75.0...v0.76.0

Typescript

Breaking Change

When using compiled validators the .compiledCode property is now undefined by default. From my tests this reduces unnecessary memory usage by 65% for small schemas and by 73% for larger schemas. Results will vary from schema to schema but overall there should be a large reduction in memory allocations. Basically now the large function body strings are no longer being stored by default so we save in memory usage.

const User = a.object("User", {
  id: a.string(),
  name: a.string(),
  email: a.nullable(a.string()),
});
const $$User = a.compile(User);
$$User.compiledCode // this is `undefined`

Since the majority of people do not use the properties available in .compiledCode this will not be a breaking change for most. If you need to access the generated function bodies for use in something like code-generation, you now need to explicitly enable the feature like so:

const User = a.object("User", {
  id: a.string(),
  name: a.string(),
  email: a.nullable(a.string()),
});
const $$User = a.compile(User, true) // passing true as the second parameter makes `.compiledCode` available

$$User.compiledCode // this is no longer undefined

// so we can access the generated function bodies
console.log($$User.compiledCode.validate)
console.log($$User.compiledCode.parse)
console.log($$User.compiledCode.serialize)