diff --git a/src/index.js b/src/index.js index aecaa4f..8d743d4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,7 @@ const ProtoDef = require('./protodef') -const proto = new ProtoDef() +// No validation: this instance only supplies the default types export, and +// validation here would load the validator for every consumer of the package. +const proto = new ProtoDef(false) module.exports = { ProtoDef, diff --git a/src/protodef.js b/src/protodef.js index 0cee5e1..ad6e6d8 100644 --- a/src/protodef.js +++ b/src/protodef.js @@ -1,6 +1,5 @@ const { getFieldInfo, tryCatch } = require('./utils') const reduce = require('lodash.reduce') -const Validator = require('protodef-validator') function isFieldInfo (type) { return typeof type === 'string' || @@ -43,7 +42,9 @@ function extendType (functions, defaultTypeArgs) { class ProtoDef { constructor (validation = true) { this.types = {} - this.validator = validation ? new Validator() : null + // Required here, not at the top: the validator's schema stack (ajv) + // must not load when validation is disabled. + this.validator = validation ? new (require('protodef-validator'))() : null this.addDefaultTypes() }