Path: blob/master/node_modules/ajv/lib/dotjs/not.js
2593 views
'use strict';1module.exports = function generate_not(it, $keyword, $ruleType) {2var out = ' ';3var $lvl = it.level;4var $dataLvl = it.dataLevel;5var $schema = it.schema[$keyword];6var $schemaPath = it.schemaPath + it.util.getProperty($keyword);7var $errSchemaPath = it.errSchemaPath + '/' + $keyword;8var $breakOnError = !it.opts.allErrors;9var $data = 'data' + ($dataLvl || '');10var $errs = 'errs__' + $lvl;11var $it = it.util.copy(it);12$it.level++;13var $nextValid = 'valid' + $it.level;14if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {15$it.schema = $schema;16$it.schemaPath = $schemaPath;17$it.errSchemaPath = $errSchemaPath;18out += ' var ' + ($errs) + ' = errors; ';19var $wasComposite = it.compositeRule;20it.compositeRule = $it.compositeRule = true;21$it.createErrors = false;22var $allErrorsOption;23if ($it.opts.allErrors) {24$allErrorsOption = $it.opts.allErrors;25$it.opts.allErrors = false;26}27out += ' ' + (it.validate($it)) + ' ';28$it.createErrors = true;29if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;30it.compositeRule = $it.compositeRule = $wasComposite;31out += ' if (' + ($nextValid) + ') { ';32var $$outStack = $$outStack || [];33$$outStack.push(out);34out = ''; /* istanbul ignore else */35if (it.createErrors !== false) {36out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';37if (it.opts.messages !== false) {38out += ' , message: \'should NOT be valid\' ';39}40if (it.opts.verbose) {41out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';42}43out += ' } ';44} else {45out += ' {} ';46}47var __err = out;48out = $$outStack.pop();49if (!it.compositeRule && $breakOnError) {50/* istanbul ignore if */51if (it.async) {52out += ' throw new ValidationError([' + (__err) + ']); ';53} else {54out += ' validate.errors = [' + (__err) + ']; return false; ';55}56} else {57out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';58}59out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';60if (it.opts.allErrors) {61out += ' } ';62}63} else {64out += ' var err = '; /* istanbul ignore else */65if (it.createErrors !== false) {66out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';67if (it.opts.messages !== false) {68out += ' , message: \'should NOT be valid\' ';69}70if (it.opts.verbose) {71out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';72}73out += ' } ';74} else {75out += ' {} ';76}77out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';78if ($breakOnError) {79out += ' if (false) { ';80}81}82return out;83}848586