Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/protodef.js
Original file line number Diff line number Diff line change
@@ -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' ||
Expand Down Expand Up @@ -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()
}

Expand Down
Loading