diff --git a/appveyor.yml b/appveyor.yml
index 8fec0ad..b0672ac 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,5 +1,5 @@
environment:
- nodejs_version: "6"
+ nodejs_version: "14"
install:
- ps: Install-Product node $env:nodejs_version
diff --git a/bin/exportLayout.js b/bin/exportLayout.js
index 9ce771d..25c7d1f 100644
--- a/bin/exportLayout.js
+++ b/bin/exportLayout.js
@@ -8,7 +8,7 @@ var lib = require('../built'),
yargs = require('yargs'),
Ajv = require('ajv');
-var ajv = new Ajv({allErrors: true, jsonPointers: true});
+var ajv = new Ajv({allErrors: true});
require('ajv-errors')(ajv);
if (require.main === module) {
diff --git a/bin/netlistsvg.js b/bin/netlistsvg.js
old mode 100644
new mode 100755
index 5eec51c..481dd69
--- a/bin/netlistsvg.js
+++ b/bin/netlistsvg.js
@@ -8,7 +8,7 @@ var lib = require('../built'),
yargs = require('yargs'),
Ajv = require('ajv');
-var ajv = new Ajv({allErrors: true, jsonPointers: true});
+var ajv = new Ajv({allErrors: true});
require('ajv-errors')(ajv);
if (require.main === module) {
diff --git a/built/netlistsvg.bundle.js b/built/netlistsvg.bundle.js
index a268328..c88028f 100644
--- a/built/netlistsvg.bundle.js
+++ b/built/netlistsvg.bundle.js
@@ -430,7 +430,7 @@ function getBits(signals, indicesString) {
}
}
-},{"./FlatModule":2,"./Port":3,"./Skin":4,"./YosysModel":5,"clone":57,"lodash":68,"onml":69}],2:[function(require,module,exports){
+},{"./FlatModule":2,"./Port":3,"./Skin":4,"./YosysModel":5,"clone":76,"lodash":83,"onml":85}],2:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeDups = exports.addToDefaultDict = exports.arrayToBitstring = exports.FlatModule = void 0;
@@ -621,7 +621,7 @@ function removeDups(inStrs) {
}
exports.removeDups = removeDups;
-},{"./Cell":1,"./Skin":4,"lodash":68}],3:[function(require,module,exports){
+},{"./Cell":1,"./Skin":4,"lodash":83}],3:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Port = void 0;
@@ -754,7 +754,7 @@ var Port = /** @class */ (function () {
}());
exports.Port = Port;
-},{"./Cell":1,"lodash":68}],4:[function(require,module,exports){
+},{"./Cell":1,"lodash":83}],4:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Skin = void 0;
@@ -886,7 +886,7 @@ var Skin;
})(Skin = exports.Skin || (exports.Skin = {}));
exports.default = Skin;
-},{"lodash":68,"onml":69}],5:[function(require,module,exports){
+},{"lodash":83,"onml":85}],5:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Yosys;
@@ -1183,7 +1183,7 @@ function removeDummyEdges(g) {
}
exports.removeDummyEdges = removeDummyEdges;
-},{"./Skin":4,"./elkGraph":7,"lodash":68,"onml":69}],7:[function(require,module,exports){
+},{"./Skin":4,"./elkGraph":7,"lodash":83,"onml":85}],7:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildElkGraph = exports.ElkModel = void 0;
@@ -1345,7 +1345,7 @@ function route(sourcePorts, targetPorts, edges, numWires) {
edges.push.apply(edges, newEdges);
}
-},{"lodash":68}],8:[function(require,module,exports){
+},{"lodash":83}],8:[function(require,module,exports){
(function (global){(function (){
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
@@ -1421,13 +1421,13 @@ function render(skinData, yosysNetlist, done, elkData) {
exports.render = render;
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
-},{"./FlatModule":2,"./Skin":4,"./drawModule":6,"./elkGraph":7,"onml":69}],9:[function(require,module,exports){
+},{"./FlatModule":2,"./Skin":4,"./drawModule":6,"./elkGraph":7,"onml":85}],9:[function(require,module,exports){
(function (Buffer){(function (){
const lib = require('../built');
const json5 = require('json5');
const Ajv = require('ajv');
-var ajv = new Ajv({allErrors: true, jsonPointers: true});
+var ajv = new Ajv({allErrors: true});
require('ajv-errors')(ajv);
const digital = "\n";
@@ -1455,5916 +1455,5720 @@ module.exports = {
};
}).call(this)}).call(this,require("buffer").Buffer)
-},{"../built":8,"ajv":12,"ajv-errors":10,"buffer":56,"json5":67}],10:[function(require,module,exports){
-'use strict';
-
-module.exports = function (ajv, options) {
- if (!ajv._opts.allErrors) throw new Error('ajv-errors: Ajv option allErrors must be true');
- if (!ajv._opts.jsonPointers) {
- console.warn('ajv-errors: Ajv option jsonPointers changed to true');
- ajv._opts.jsonPointers = true;
- }
-
- ajv.addKeyword('errorMessage', {
- inline: require('./lib/dotjs/errorMessage'),
- statements: true,
- valid: true,
- errors: 'full',
- config: {
- KEYWORD_PROPERTY_PARAMS: {
- required: 'missingProperty',
- dependencies: 'property'
- },
- options: options || {}
- },
- metaSchema: {
- 'type': ['string', 'object'],
- properties: {
- properties: {$ref: '#/definitions/stringMap'},
- items: {$ref: '#/definitions/stringList'},
- required: {$ref: '#/definitions/stringOrMap'},
- dependencies: {$ref: '#/definitions/stringOrMap'}
- },
- additionalProperties: {'type': 'string'},
- definitions: {
- stringMap: {
- 'type': ['object'],
- additionalProperties: {'type': 'string'}
- },
- stringOrMap: {
- 'type': ['string', 'object'],
- additionalProperties: {'type': 'string'}
- },
- stringList: {
- 'type': ['array'],
- items: {'type': 'string'}
- }
- }
- }
- });
- return ajv;
+},{"../built":8,"ajv":11,"ajv-errors":10,"buffer":75,"json5":82}],10:[function(require,module,exports){
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const ajv_1 = require("ajv");
+const codegen_1 = require("ajv/dist/compile/codegen");
+const code_1 = require("ajv/dist/compile/codegen/code");
+const validate_1 = require("ajv/dist/compile/validate");
+const errors_1 = require("ajv/dist/compile/errors");
+const names_1 = require("ajv/dist/compile/names");
+const keyword = "errorMessage";
+const used = new ajv_1.Name("emUsed");
+const KEYWORD_PROPERTY_PARAMS = {
+ required: "missingProperty",
+ dependencies: "property",
+ dependentRequired: "property",
};
-
-},{"./lib/dotjs/errorMessage":11}],11:[function(require,module,exports){
-'use strict';
-module.exports = function generate_errorMessage(it, $keyword, $ruleType) {
- var out = ' ';
- var $lvl = it.level;
- var $dataLvl = it.dataLevel;
- var $schema = it.schema[$keyword];
- var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
- var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
- var $breakOnError = !it.opts.allErrors;
- var $data = 'data' + ($dataLvl || '');
- if (it.createErrors !== false) {
- var INTERPOLATION = /\$\{[^\}]+\}/;
- var INTERPOLATION_REPLACE = /\$\{([^\}]+)\}/g;
- var EMPTY_STR = /^\'\'\s*\+\s*|\s*\+\s*\'\'$/g;
- var $config = it.self.getKeyword($keyword).config,
- $dataPath = '_em_dataPath' + $lvl,
- $i = '_em_i' + $lvl,
- $key = '_em_key' + $lvl,
- $keyProp = '_em_keyProp' + $lvl,
- $err = '_em_err' + $lvl,
- $child = '_em_child' + $lvl,
- $childKeyword = '_em_childKeyword' + $lvl,
- $matches = '_em_matches' + $lvl,
- $isArray = '_em_isArray' + $lvl,
- $errors = '_em_errors' + $lvl,
- $message = '_em_message' + $lvl,
- $paramsErrors = '_em_paramsErrors' + $lvl,
- $propParam = '_em_propParam' + $lvl,
- $keywordPropParams = '_em_keywordPropParams' + $lvl,
- $templates = '_em_templates' + $lvl,
- $errSchemaPathString = it.util.toQuotedString(it.errSchemaPath);
- out += ' if (errors > 0) { var ' + ($dataPath) + ' = (dataPath || \'\') + ' + (it.errorPath) + '; var ' + ($i) + ', ' + ($err) + ', ' + ($errors) + '; ';
- if (typeof $schema == 'object') {
- var $keywordErrors = {},
- $keywordPropErrors = {},
- $childErrors = {
- properties: {},
- items: {}
- },
- $hasKeywordProps = false,
- $hasProperties = false,
- $hasItems = false;
- for (var $k in $schema) {
- switch ($k) {
- case 'properties':
- for (var $prop in $schema.properties) {
- $hasProperties = true;
- $childErrors.properties[$prop] = [];
- }
- break;
- case 'items':
- for (var $item = 0; $item < $schema.items.length; $item++) {
- $hasItems = true;
- $childErrors.items[$item] = [];
- }
- break;
- default:
- if (typeof $schema[$k] == 'object') {
- $hasKeywordProps = true;
- $keywordPropErrors[$k] = {};
- for (var $prop in $schema[$k]) {
- $keywordPropErrors[$k][$prop] = [];
- }
- } else {
- $keywordErrors[$k] = [];
- }
- }
- }
- var $keywordErrorsArr = Object.keys($keywordErrors);
- if ($keywordErrorsArr.length) {
- out += ' ' + ($i) + ' = 0; ' + ($errors) + ' = ' + (JSON.stringify($keywordErrors)) + '; var ' + ($templates) + ' = { ';
- var $comma = false;
- var arr1 = $keywordErrorsArr;
- if (arr1) {
- var $k, i1 = -1,
- l1 = arr1.length - 1;
- while (i1 < l1) {
- $k = arr1[i1 += 1];
- if (INTERPOLATION.test($schema[$k])) {
- if ($comma) {
- out += ',';
- }
- out += '' + (it.util.toQuotedString($k)) + ': ' + (templateFunc($schema[$k])) + ' ';
- $comma = true;
- }
- }
- }
- out += ' }; while (' + ($i) + ' < errors) { ' + ($err) + ' = vErrors[' + ($i) + ']; if ( ' + ($err) + '.keyword != \'' + ($keyword) + '\' ';
- if ($config.options.keepErrors) {
- out += ' && !' + ($err) + '.emUsed ';
- }
- out += ' && ' + ($err) + '.keyword in ' + ($errors) + ' && ' + ($err) + '.dataPath == ' + ($dataPath) + ' && ' + ($err) + '.schemaPath.indexOf(' + ($errSchemaPathString) + ') == 0 && /^\\/[^\\/]*$/.test(' + ($err) + '.schemaPath.slice(' + (it.errSchemaPath.length) + '))) { ' + ($errors) + '[' + ($err) + '.keyword].push(' + ($err) + '); ';
- if ($config.options.keepErrors) {
- out += ' ' + ($err) + '.emUsed = true; ';
- } else {
- out += ' vErrors.splice(' + ($i) + ', 1); errors--; ';
- }
- out += ' } else { ' + ($i) + '++; } } ';
- if ($config.options.singleError) {
- out += ' var ' + ($message) + ' = \'\'; var ' + ($paramsErrors) + ' = []; ';
- }
- out += ' for (var ' + ($key) + ' in ' + ($errors) + ') { if (' + ($errors) + '[' + ($key) + '].length) { ';
- if ($config.options.singleError) {
- out += ' if (' + ($message) + ') { ' + ($message) + ' += ';
- if (typeof $config.options.singleError == 'string') {
- out += ' ' + (it.util.toQuotedString($config.options.singleError)) + ' ';
- } else {
- out += ' \'; \' ';
- }
- out += '; } ' + ($message) + ' += ' + ($key) + ' in ' + ($templates) + ' ? ' + ($templates) + '[' + ($key) + '] () : validate.schema' + ($schemaPath) + '[' + ($key) + ']; ' + ($paramsErrors) + ' = ' + ($paramsErrors) + '.concat(' + ($errors) + '[' + ($key) + ']); } } ';
- } else {
- out += ' var ' + ($message) + ' = ' + ($key) + ' in ' + ($templates) + ' ? ' + ($templates) + '[' + ($key) + '] () : validate.schema' + ($schemaPath) + '[' + ($key) + ']; var ' + ($paramsErrors) + ' = ' + ($errors) + '[' + ($key) + ']; ';
- }
- out += ' var err = { keyword: \'' + ($keyword) + '\' , dataPath: ' + ($dataPath) + ' , schemaPath: ' + ($errSchemaPathString) + ' + \'/' + ($keyword) + '\' , params: { errors: ' + ($paramsErrors) + ' } , message: ' + ($message) + ' ';
- if (it.opts.verbose) {
- out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
- }
- out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
- if (!$config.options.singleError) {
- out += ' } } ';
- }
- }
- if ($hasKeywordProps) {
- out += ' ' + ($i) + ' = 0; ' + ($errors) + ' = ' + (JSON.stringify($keywordPropErrors)) + '; var ' + ($paramsErrors) + ', ' + ($propParam) + '; var ' + ($keywordPropParams) + ' = ' + (JSON.stringify($config.KEYWORD_PROPERTY_PARAMS)) + '; var ' + ($templates) + ' = { ';
- var $comma = false;
- var arr2 = Object.keys($keywordPropErrors);
- if (arr2) {
- var $k, i2 = -1,
- l2 = arr2.length - 1;
- while (i2 < l2) {
- $k = arr2[i2 += 1];
- var $keywordMsgs = $schema[$k];
- if ($comma) {
- out += ',';
+const INTERPOLATION = /\$\{[^}]+\}/;
+const INTERPOLATION_REPLACE = /\$\{([^}]+)\}/g;
+const EMPTY_STR = /^""\s*\+\s*|\s*\+\s*""$/g;
+function errorMessage(options) {
+ return {
+ keyword,
+ schemaType: ["string", "object"],
+ post: true,
+ code(cxt) {
+ const { gen, data, schema, schemaValue, it } = cxt;
+ if (it.createErrors === false)
+ return;
+ const sch = schema;
+ const instancePath = codegen_1.strConcat(names_1.default.instancePath, it.errorPath);
+ gen.if(ajv_1._ `${names_1.default.errors} > 0`, () => {
+ if (typeof sch == "object") {
+ const [kwdPropErrors, kwdErrors] = keywordErrorsConfig(sch);
+ if (kwdErrors)
+ processKeywordErrors(kwdErrors);
+ if (kwdPropErrors)
+ processKeywordPropErrors(kwdPropErrors);
+ processChildErrors(childErrorsConfig(sch));
+ }
+ const schMessage = typeof sch == "string" ? sch : sch._;
+ if (schMessage)
+ processAllErrors(schMessage);
+ if (!options.keepErrors)
+ removeUsedErrors();
+ });
+ function childErrorsConfig({ properties, items }) {
+ const errors = {};
+ if (properties) {
+ errors.props = {};
+ for (const p in properties)
+ errors.props[p] = [];
+ }
+ if (items) {
+ errors.items = {};
+ for (let i = 0; i < items.length; i++)
+ errors.items[i] = [];
+ }
+ return errors;
}
- out += '' + (it.util.toQuotedString($k)) + ': { ';
- $comma = true;
- var $innerComma = false;
- var arr3 = Object.keys($keywordMsgs);
- if (arr3) {
- var $prop, i3 = -1,
- l3 = arr3.length - 1;
- while (i3 < l3) {
- $prop = arr3[i3 += 1];
- if (INTERPOLATION.test($keywordMsgs[$prop])) {
- if ($innerComma) {
- out += ',';
- }
- out += '' + (it.util.toQuotedString($prop)) + ': ' + (templateFunc($keywordMsgs[$prop])) + ' ';
- $innerComma = true;
+ function keywordErrorsConfig(emSchema) {
+ let propErrors;
+ let errors;
+ for (const k in emSchema) {
+ if (k === "properties" || k === "items")
+ continue;
+ const kwdSch = emSchema[k];
+ if (typeof kwdSch == "object") {
+ propErrors || (propErrors = {});
+ const errMap = (propErrors[k] = {});
+ for (const p in kwdSch)
+ errMap[p] = [];
+ }
+ else {
+ errors || (errors = {});
+ errors[k] = [];
+ }
}
- }
+ return [propErrors, errors];
}
- out += ' } ';
- }
- }
- out += ' }; while (' + ($i) + ' < errors) { ' + ($err) + ' = vErrors[' + ($i) + ']; if ( ' + ($err) + '.keyword != \'' + ($keyword) + '\' ';
- if ($config.options.keepErrors) {
- out += ' && !' + ($err) + '.emUsed ';
- }
- out += ' && ' + ($err) + '.keyword in ' + ($errors) + ' && ' + ($err) + '.dataPath == ' + ($dataPath) + ' && ' + ($err) + '.schemaPath.indexOf(' + ($errSchemaPathString) + ') == 0 && /^\\/[^\\/]*$/.test(' + ($err) + '.schemaPath.slice(' + (it.errSchemaPath.length) + '))) { ' + ($propParam) + ' = ' + ($keywordPropParams) + '[' + ($err) + '.keyword]; ' + ($paramsErrors) + ' = ' + ($errors) + '[' + ($err) + '.keyword][' + ($err) + '.params[' + ($propParam) + ']]; if (' + ($paramsErrors) + ') { ' + ($paramsErrors) + '.push(' + ($err) + '); ';
- if ($config.options.keepErrors) {
- out += ' ' + ($err) + '.emUsed = true; ';
- } else {
- out += ' vErrors.splice(' + ($i) + ', 1); errors--; ';
- }
- out += ' } else { ' + ($i) + '++; } } else { ' + ($i) + '++; } } for (var ' + ($key) + ' in ' + ($errors) + ') { for (var ' + ($keyProp) + ' in ' + ($errors) + '[' + ($key) + ']) { ' + ($paramsErrors) + ' = ' + ($errors) + '[' + ($key) + '][' + ($keyProp) + ']; if (' + ($paramsErrors) + '.length) { var ' + ($message) + ' = ' + ($key) + ' in ' + ($templates) + ' && ' + ($keyProp) + ' in ' + ($templates) + '[' + ($key) + '] ? ' + ($templates) + '[' + ($key) + '][' + ($keyProp) + '] () : validate.schema' + ($schemaPath) + '[' + ($key) + '][' + ($keyProp) + ']; var err = { keyword: \'' + ($keyword) + '\' , dataPath: ' + ($dataPath) + ' , schemaPath: ' + ($errSchemaPathString) + ' + \'/' + ($keyword) + '\' , params: { errors: ' + ($paramsErrors) + ' } , message: ' + ($message) + ' ';
- if (it.opts.verbose) {
- out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
- }
- out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } } ';
- }
- if ($hasProperties || $hasItems) {
- out += ' var ' + ($isArray) + ' = Array.isArray(' + ($data) + '); if ';
- if ($hasProperties && $hasItems) {
- out += ' (typeof ' + ($data) + ' == \'object\') { ';
- var $childProp = '[' + $childKeyword + ']';
- out += ' ' + ($i) + ' = 0; if (' + ($isArray) + ') { var ' + ($childKeyword) + ' = \'items\'; ' + ($errors) + ' = ' + (JSON.stringify($childErrors.items)) + '; ';
- var _keysArray = Object.keys($childErrors.items);
- out += ' var ' + ($templates) + ' = { ';
- var $comma = false;
- var arr4 = _keysArray;
- if (arr4) {
- var $k, i4 = -1,
- l4 = arr4.length - 1;
- while (i4 < l4) {
- $k = arr4[i4 += 1];
- if (INTERPOLATION.test($schema.items[$k])) {
- if ($comma) {
- out += ',';
+ function processKeywordErrors(kwdErrors) {
+ const kwdErrs = gen.const("emErrors", ajv_1.stringify(kwdErrors));
+ const templates = gen.const("templates", getTemplatesCode(kwdErrors, schema));
+ gen.forOf("err", names_1.default.vErrors, (err) => gen.if(matchKeywordError(err, kwdErrs), () => gen.code(ajv_1._ `${kwdErrs}[${err}.keyword].push(${err})`).assign(ajv_1._ `${err}.${used}`, true)));
+ const { singleError } = options;
+ if (singleError) {
+ const message = gen.let("message", ajv_1._ `""`);
+ const paramsErrors = gen.let("paramsErrors", ajv_1._ `[]`);
+ loopErrors((key) => {
+ gen.if(message, () => gen.code(ajv_1._ `${message} += ${typeof singleError == "string" ? singleError : ";"}`));
+ gen.code(ajv_1._ `${message} += ${errMessage(key)}`);
+ gen.assign(paramsErrors, ajv_1._ `${paramsErrors}.concat(${kwdErrs}[${key}])`);
+ });
+ errors_1.reportError(cxt, { message, params: ajv_1._ `{errors: ${paramsErrors}}` });
+ }
+ else {
+ loopErrors((key) => errors_1.reportError(cxt, {
+ message: errMessage(key),
+ params: ajv_1._ `{errors: ${kwdErrs}[${key}]}`,
+ }));
+ }
+ function loopErrors(body) {
+ gen.forIn("key", kwdErrs, (key) => gen.if(ajv_1._ `${kwdErrs}[${key}].length`, () => body(key)));
+ }
+ function errMessage(key) {
+ return ajv_1._ `${key} in ${templates} ? ${templates}[${key}]() : ${schemaValue}[${key}]`;
}
- out += '' + (it.util.toQuotedString($k)) + ': ' + (templateFunc($schema.items[$k])) + ' ';
- $comma = true;
- }
}
- }
- out += ' }; } else { var ' + ($childKeyword) + ' = \'properties\'; ' + ($errors) + ' = ' + (JSON.stringify($childErrors.properties)) + '; ';
- var _keysArray = Object.keys($childErrors.properties);
- out += ' var ' + ($templates) + ' = { ';
- var $comma = false;
- var arr5 = _keysArray;
- if (arr5) {
- var $k, i5 = -1,
- l5 = arr5.length - 1;
- while (i5 < l5) {
- $k = arr5[i5 += 1];
- if (INTERPOLATION.test($schema.properties[$k])) {
- if ($comma) {
- out += ',';
+ function processKeywordPropErrors(kwdPropErrors) {
+ const kwdErrs = gen.const("emErrors", ajv_1.stringify(kwdPropErrors));
+ const templatesCode = [];
+ for (const k in kwdPropErrors) {
+ templatesCode.push([
+ k,
+ getTemplatesCode(kwdPropErrors[k], schema[k]),
+ ]);
}
- out += '' + (it.util.toQuotedString($k)) + ': ' + (templateFunc($schema.properties[$k])) + ' ';
- $comma = true;
- }
+ const templates = gen.const("templates", gen.object(...templatesCode));
+ const kwdPropParams = gen.scopeValue("obj", {
+ ref: KEYWORD_PROPERTY_PARAMS,
+ code: ajv_1.stringify(KEYWORD_PROPERTY_PARAMS),
+ });
+ const propParam = gen.let("emPropParams");
+ const paramsErrors = gen.let("emParamsErrors");
+ gen.forOf("err", names_1.default.vErrors, (err) => gen.if(matchKeywordError(err, kwdErrs), () => {
+ gen.assign(propParam, ajv_1._ `${kwdPropParams}[${err}.keyword]`);
+ gen.assign(paramsErrors, ajv_1._ `${kwdErrs}[${err}.keyword][${err}.params[${propParam}]]`);
+ gen.if(paramsErrors, () => gen.code(ajv_1._ `${paramsErrors}.push(${err})`).assign(ajv_1._ `${err}.${used}`, true));
+ }));
+ gen.forIn("key", kwdErrs, (key) => gen.forIn("keyProp", ajv_1._ `${kwdErrs}[${key}]`, (keyProp) => {
+ gen.assign(paramsErrors, ajv_1._ `${kwdErrs}[${key}][${keyProp}]`);
+ gen.if(ajv_1._ `${paramsErrors}.length`, () => {
+ const tmpl = gen.const("tmpl", ajv_1._ `${templates}[${key}] && ${templates}[${key}][${keyProp}]`);
+ errors_1.reportError(cxt, {
+ message: ajv_1._ `${tmpl} ? ${tmpl}() : ${schemaValue}[${key}][${keyProp}]`,
+ params: ajv_1._ `{errors: ${paramsErrors}}`,
+ });
+ });
+ }));
}
- }
- out += ' }; } ';
- } else if ($hasProperties) {
- out += ' (typeof ' + ($data) + ' == \'object\' && !' + ($isArray) + ') { ';
- var $childProp = '.properties';
- out += ' ' + ($i) + ' = 0; ' + ($errors) + ' = ' + (JSON.stringify($childErrors.properties)) + '; ';
- var _keysArray = Object.keys($childErrors.properties);
- out += ' var ' + ($templates) + ' = { ';
- var $comma = false;
- var arr6 = _keysArray;
- if (arr6) {
- var $k, i6 = -1,
- l6 = arr6.length - 1;
- while (i6 < l6) {
- $k = arr6[i6 += 1];
- if (INTERPOLATION.test($schema.properties[$k])) {
- if ($comma) {
- out += ',';
+ function processChildErrors(childErrors) {
+ const { props, items } = childErrors;
+ if (!props && !items)
+ return;
+ const isObj = ajv_1._ `typeof ${data} == "object"`;
+ const isArr = ajv_1._ `Array.isArray(${data})`;
+ const childErrs = gen.let("emErrors");
+ let childKwd;
+ let childProp;
+ const templates = gen.let("templates");
+ if (props && items) {
+ childKwd = gen.let("emChildKwd");
+ gen.if(isObj);
+ gen.if(isArr, () => {
+ init(items, schema.items);
+ gen.assign(childKwd, ajv_1.str `items`);
+ }, () => {
+ init(props, schema.properties);
+ gen.assign(childKwd, ajv_1.str `properties`);
+ });
+ childProp = ajv_1._ `[${childKwd}]`;
+ }
+ else if (items) {
+ gen.if(isArr);
+ init(items, schema.items);
+ childProp = ajv_1._ `.items`;
+ }
+ else if (props) {
+ gen.if(codegen_1.and(isObj, codegen_1.not(isArr)));
+ init(props, schema.properties);
+ childProp = ajv_1._ `.properties`;
+ }
+ gen.forOf("err", names_1.default.vErrors, (err) => ifMatchesChildError(err, childErrs, (child) => gen.code(ajv_1._ `${childErrs}[${child}].push(${err})`).assign(ajv_1._ `${err}.${used}`, true)));
+ gen.forIn("key", childErrs, (key) => gen.if(ajv_1._ `${childErrs}[${key}].length`, () => {
+ errors_1.reportError(cxt, {
+ message: ajv_1._ `${key} in ${templates} ? ${templates}[${key}]() : ${schemaValue}${childProp}[${key}]`,
+ params: ajv_1._ `{errors: ${childErrs}[${key}]}`,
+ });
+ gen.assign(ajv_1._ `${names_1.default.vErrors}[${names_1.default.errors}-1].instancePath`, ajv_1._ `${instancePath} + "/" + ${key}.replace(/~/g, "~0").replace(/\\//g, "~1")`);
+ }));
+ gen.endIf();
+ function init(children, msgs) {
+ gen.assign(childErrs, ajv_1.stringify(children));
+ gen.assign(templates, getTemplatesCode(children, msgs));
}
- out += '' + (it.util.toQuotedString($k)) + ': ' + (templateFunc($schema.properties[$k])) + ' ';
- $comma = true;
- }
}
- }
- out += ' }; ';
- } else {
- out += ' (' + ($isArray) + ') { ';
- var $childProp = '.items';
- out += ' ' + ($i) + ' = 0; ' + ($errors) + ' = ' + (JSON.stringify($childErrors.items)) + '; ';
- var _keysArray = Object.keys($childErrors.items);
- out += ' var ' + ($templates) + ' = { ';
- var $comma = false;
- var arr7 = _keysArray;
- if (arr7) {
- var $k, i7 = -1,
- l7 = arr7.length - 1;
- while (i7 < l7) {
- $k = arr7[i7 += 1];
- if (INTERPOLATION.test($schema.items[$k])) {
- if ($comma) {
- out += ',';
+ function processAllErrors(schMessage) {
+ const errs = gen.const("emErrs", ajv_1._ `[]`);
+ gen.forOf("err", names_1.default.vErrors, (err) => gen.if(matchAnyError(err), () => gen.code(ajv_1._ `${errs}.push(${err})`).assign(ajv_1._ `${err}.${used}`, true)));
+ gen.if(ajv_1._ `${errs}.length`, () => errors_1.reportError(cxt, {
+ message: templateExpr(schMessage),
+ params: ajv_1._ `{errors: ${errs}}`,
+ }));
+ }
+ function removeUsedErrors() {
+ const errs = gen.const("emErrs", ajv_1._ `[]`);
+ gen.forOf("err", names_1.default.vErrors, (err) => gen.if(ajv_1._ `!${err}.${used}`, () => gen.code(ajv_1._ `${errs}.push(${err})`)));
+ gen.assign(names_1.default.vErrors, errs).assign(names_1.default.errors, ajv_1._ `${errs}.length`);
+ }
+ function matchKeywordError(err, kwdErrs) {
+ return codegen_1.and(ajv_1._ `${err}.keyword !== ${keyword}`, ajv_1._ `!${err}.${used}`, ajv_1._ `${err}.instancePath === ${instancePath}`, ajv_1._ `${err}.keyword in ${kwdErrs}`,
+ // TODO match the end of the string?
+ ajv_1._ `${err}.schemaPath.indexOf(${it.errSchemaPath}) === 0`, ajv_1._ `/^\\/[^\\/]*$/.test(${err}.schemaPath.slice(${it.errSchemaPath.length}))`);
+ }
+ function ifMatchesChildError(err, childErrs, thenBody) {
+ gen.if(codegen_1.and(ajv_1._ `${err}.keyword !== ${keyword}`, ajv_1._ `!${err}.${used}`, ajv_1._ `${err}.instancePath.indexOf(${instancePath}) === 0`), () => {
+ const childRegex = gen.scopeValue("pattern", {
+ ref: /^\/([^/]*)(?:\/|$)/,
+ code: ajv_1._ `new RegExp("^\\\/([^/]*)(?:\\\/|$)")`,
+ });
+ const matches = gen.const("emMatches", ajv_1._ `${childRegex}.exec(${err}.instancePath.slice(${instancePath}.length))`);
+ const child = gen.const("emChild", ajv_1._ `${matches} && ${matches}[1].replace(/~1/g, "/").replace(/~0/g, "~")`);
+ gen.if(ajv_1._ `${child} !== undefined && ${child} in ${childErrs}`, () => thenBody(child));
+ });
+ }
+ function matchAnyError(err) {
+ return codegen_1.and(ajv_1._ `${err}.keyword !== ${keyword}`, ajv_1._ `!${err}.${used}`, codegen_1.or(ajv_1._ `${err}.instancePath === ${instancePath}`, codegen_1.and(ajv_1._ `${err}.instancePath.indexOf(${instancePath}) === 0`, ajv_1._ `${err}.instancePath[${instancePath}.length] === "/"`)), ajv_1._ `${err}.schemaPath.indexOf(${it.errSchemaPath}) === 0`, ajv_1._ `${err}.schemaPath[${it.errSchemaPath}.length] === "/"`);
+ }
+ function getTemplatesCode(keys, msgs) {
+ const templatesCode = [];
+ for (const k in keys) {
+ const msg = msgs[k];
+ if (INTERPOLATION.test(msg))
+ templatesCode.push([k, templateFunc(msg)]);
}
- out += '' + (it.util.toQuotedString($k)) + ': ' + (templateFunc($schema.items[$k])) + ' ';
- $comma = true;
- }
+ return gen.object(...templatesCode);
}
- }
- out += ' }; ';
- }
- out += ' var ' + ($child) + ', ' + ($matches) + '; while (' + ($i) + ' < errors) { ' + ($err) + ' = vErrors[' + ($i) + ']; if ( ' + ($err) + '.keyword != \'' + ($keyword) + '\' ';
- if ($config.options.keepErrors) {
- out += ' && !' + ($err) + '.emUsed ';
- }
- out += ' && ' + ($err) + '.dataPath.indexOf(' + ($dataPath) + ') == 0 && (' + ($matches) + ' = ' + ($err) + '.dataPath.slice(' + ($dataPath) + '.length).match(/^\\/([^\\/]*)(?:\\/|$)/), ' + ($child) + ' = ' + ($matches) + ' && ' + ($matches) + '[1].replace(/~1/g, \'/\').replace(/~0/g, \'~\') ) !== undefined && ' + ($child) + ' in ' + ($errors) + ') { ' + ($errors) + '[' + ($child) + '].push(' + ($err) + '); ';
- if ($config.options.keepErrors) {
- out += ' ' + ($err) + '.emUsed = true; ';
- } else {
- out += ' vErrors.splice(' + ($i) + ', 1); errors--; ';
- }
- out += ' } else { ' + ($i) + '++; } } for (var ' + ($key) + ' in ' + ($errors) + ') { if (' + ($errors) + '[' + ($key) + '].length) { var err = { keyword: \'' + ($keyword) + '\' , dataPath: ' + ($dataPath) + ' + \'/\' + ' + ($key) + '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\') , schemaPath: ' + ($errSchemaPathString) + ' + \'/' + ($keyword) + '\' , params: { errors: ' + ($errors) + '[' + ($key) + '] } , message: ' + ($key) + ' in ' + ($templates) + ' ? ' + ($templates) + '[' + ($key) + '] () : validate.schema' + ($schemaPath) + ($childProp) + '[' + ($key) + '] ';
- if (it.opts.verbose) {
- out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
- }
- out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } } ';
- }
- }
- var $schemaMessage = typeof $schema == 'string' ? $schema : $schema._;
- if ($schemaMessage) {
- out += ' ' + ($i) + ' = 0; ' + ($errors) + ' = []; while (' + ($i) + ' < errors) { ' + ($err) + ' = vErrors[' + ($i) + ']; if ( ' + ($err) + '.keyword != \'' + ($keyword) + '\' ';
- if ($config.options.keepErrors) {
- out += ' && !' + ($err) + '.emUsed ';
- }
- out += ' && (' + ($err) + '.dataPath == ' + ($dataPath) + ' || (' + ($err) + '.dataPath.indexOf(' + ($dataPath) + ') == 0 && ' + ($err) + '.dataPath[' + ($dataPath) + '.length] == \'/\')) && ' + ($err) + '.schemaPath.indexOf(' + ($errSchemaPathString) + ') == 0 && ' + ($err) + '.schemaPath[' + (it.errSchemaPath.length) + '] == \'/\') { ' + ($errors) + '.push(' + ($err) + '); ';
- if ($config.options.keepErrors) {
- out += ' ' + ($err) + '.emUsed = true; ';
- } else {
- out += ' vErrors.splice(' + ($i) + ', 1); errors--; ';
- }
- out += ' } else { ' + ($i) + '++; } } if (' + ($errors) + '.length) { var err = { keyword: \'' + ($keyword) + '\' , dataPath: ' + ($dataPath) + ' , schemaPath: ' + ($errSchemaPathString) + ' + \'/' + ($keyword) + '\' , params: { errors: ' + ($errors) + ' } , message: ' + (templateExpr($schemaMessage)) + ' ';
- if (it.opts.verbose) {
- out += ' , schema: ' + (it.util.toQuotedString($schemaMessage)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
- }
- out += ' }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
+ function templateExpr(msg) {
+ if (!INTERPOLATION.test(msg))
+ return ajv_1.stringify(msg);
+ return new code_1._Code(code_1.safeStringify(msg)
+ .replace(INTERPOLATION_REPLACE, (_s, ptr) => `" + JSON.stringify(${validate_1.getData(ptr, it)}) + "`)
+ .replace(EMPTY_STR, ""));
+ }
+ function templateFunc(msg) {
+ return ajv_1._ `function(){return ${templateExpr(msg)}}`;
+ }
+ },
+ metaSchema: {
+ anyOf: [
+ { type: "string" },
+ {
+ type: "object",
+ properties: {
+ properties: { $ref: "#/$defs/stringMap" },
+ items: { $ref: "#/$defs/stringList" },
+ required: { $ref: "#/$defs/stringOrMap" },
+ dependencies: { $ref: "#/$defs/stringOrMap" },
+ },
+ additionalProperties: { type: "string" },
+ },
+ ],
+ $defs: {
+ stringMap: {
+ type: "object",
+ additionalProperties: { type: "string" },
+ },
+ stringOrMap: {
+ anyOf: [{ type: "string" }, { $ref: "#/$defs/stringMap" }],
+ },
+ stringList: { type: "array", items: { type: "string" } },
+ },
+ },
+ };
+}
+const ajvErrors = (ajv, options = {}) => {
+ if (!ajv.opts.allErrors)
+ throw new Error("ajv-errors: Ajv option allErrors must be true");
+ if (ajv.opts.jsPropertySyntax) {
+ throw new Error("ajv-errors: ajv option jsPropertySyntax is not supported");
}
- out += ' }';
- }
-
- function templateExpr(str) {
- str = it.util.escapeQuotes(str);
- if (!INTERPOLATION.test(str)) return "'" + str + "'";
- var expr = "'" + str.replace(INTERPOLATION_REPLACE, function($0, $1) {
- return "' + JSON.stringify(" + it.util.getData($1, $dataLvl, it.dataPathArr) + ") + '";
- }) + "'";
- return expr.replace(EMPTY_STR, '');
- }
+ return ajv.addKeyword(errorMessage(options));
+};
+exports.default = ajvErrors;
+module.exports = ajvErrors;
+module.exports.default = ajvErrors;
- function templateFunc(str) {
- return 'function() { return ' + templateExpr(str) + '; }';
- }
- return out;
+},{"ajv":11,"ajv/dist/compile/codegen":13,"ajv/dist/compile/codegen/code":12,"ajv/dist/compile/errors":15,"ajv/dist/compile/names":17,"ajv/dist/compile/validate":26}],11:[function(require,module,exports){
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = void 0;
+const core_1 = require("./core");
+const draft7_1 = require("./vocabularies/draft7");
+const discriminator_1 = require("./vocabularies/discriminator");
+const draft7MetaSchema = require("./refs/json-schema-draft-07.json");
+const META_SUPPORT_DATA = ["/properties"];
+const META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
+class Ajv extends core_1.default {
+ _addVocabularies() {
+ super._addVocabularies();
+ draft7_1.default.forEach((v) => this.addVocabulary(v));
+ if (this.opts.discriminator)
+ this.addKeyword(discriminator_1.default);
+ }
+ _addDefaultMetaSchema() {
+ super._addDefaultMetaSchema();
+ if (!this.opts.meta)
+ return;
+ const metaSchema = this.opts.$data
+ ? this.$dataMetaSchema(draft7MetaSchema, META_SUPPORT_DATA)
+ : draft7MetaSchema;
+ this.addMetaSchema(metaSchema, META_SCHEMA_ID, false);
+ this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
+ }
+ defaultMeta() {
+ return (this.opts.defaultMeta =
+ super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined));
+ }
}
-
-},{}],12:[function(require,module,exports){
-'use strict';
-
-var compileSchema = require('./compile')
- , resolve = require('./compile/resolve')
- , Cache = require('./cache')
- , SchemaObject = require('./compile/schema_obj')
- , stableStringify = require('fast-json-stable-stringify')
- , formats = require('./compile/formats')
- , rules = require('./compile/rules')
- , $dataMetaSchema = require('./data')
- , util = require('./compile/util');
-
-module.exports = Ajv;
-
-Ajv.prototype.validate = validate;
-Ajv.prototype.compile = compile;
-Ajv.prototype.addSchema = addSchema;
-Ajv.prototype.addMetaSchema = addMetaSchema;
-Ajv.prototype.validateSchema = validateSchema;
-Ajv.prototype.getSchema = getSchema;
-Ajv.prototype.removeSchema = removeSchema;
-Ajv.prototype.addFormat = addFormat;
-Ajv.prototype.errorsText = errorsText;
-
-Ajv.prototype._addSchema = _addSchema;
-Ajv.prototype._compile = _compile;
-
-Ajv.prototype.compileAsync = require('./compile/async');
-var customKeyword = require('./keyword');
-Ajv.prototype.addKeyword = customKeyword.add;
-Ajv.prototype.getKeyword = customKeyword.get;
-Ajv.prototype.removeKeyword = customKeyword.remove;
-Ajv.prototype.validateKeyword = customKeyword.validate;
-
-var errorClasses = require('./compile/error_classes');
-Ajv.ValidationError = errorClasses.Validation;
-Ajv.MissingRefError = errorClasses.MissingRef;
-Ajv.$dataMetaSchema = $dataMetaSchema;
-
-var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema';
-
-var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'strictDefaults' ];
-var META_SUPPORT_DATA = ['/properties'];
-
-/**
- * Creates validator instance.
- * Usage: `Ajv(opts)`
- * @param {Object} opts optional options
- * @return {Object} ajv instance
- */
-function Ajv(opts) {
- if (!(this instanceof Ajv)) return new Ajv(opts);
- opts = this._opts = util.copy(opts) || {};
- setLogger(this);
- this._schemas = {};
- this._refs = {};
- this._fragments = {};
- this._formats = formats(opts.format);
-
- this._cache = opts.cache || new Cache;
- this._loadingSchemas = {};
- this._compilations = [];
- this.RULES = rules();
- this._getId = chooseGetId(opts);
-
- opts.loopRequired = opts.loopRequired || Infinity;
- if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
- if (opts.serialize === undefined) opts.serialize = stableStringify;
- this._metaOpts = getMetaSchemaOptions(this);
-
- if (opts.formats) addInitialFormats(this);
- if (opts.keywords) addInitialKeywords(this);
- addDefaultMetaSchema(this);
- if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta);
- if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}});
- addInitialSchemas(this);
+module.exports = exports = Ajv;
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.default = Ajv;
+var validate_1 = require("./compile/validate");
+Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function () { return validate_1.KeywordCxt; } });
+var codegen_1 = require("./compile/codegen");
+Object.defineProperty(exports, "_", { enumerable: true, get: function () { return codegen_1._; } });
+Object.defineProperty(exports, "str", { enumerable: true, get: function () { return codegen_1.str; } });
+Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return codegen_1.stringify; } });
+Object.defineProperty(exports, "nil", { enumerable: true, get: function () { return codegen_1.nil; } });
+Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return codegen_1.Name; } });
+Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function () { return codegen_1.CodeGen; } });
+
+},{"./compile/codegen":13,"./compile/validate":26,"./core":29,"./refs/json-schema-draft-07.json":31,"./vocabularies/discriminator":56,"./vocabularies/draft7":58}],12:[function(require,module,exports){
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.regexpCode = exports.getProperty = exports.safeStringify = exports.stringify = exports.strConcat = exports.addCodeArg = exports.str = exports._ = exports.nil = exports._Code = exports.Name = exports.IDENTIFIER = exports._CodeOrName = void 0;
+class _CodeOrName {
+}
+exports._CodeOrName = _CodeOrName;
+exports.IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
+class Name extends _CodeOrName {
+ constructor(s) {
+ super();
+ if (!exports.IDENTIFIER.test(s))
+ throw new Error("CodeGen: name must be a valid identifier");
+ this.str = s;
+ }
+ toString() {
+ return this.str;
+ }
+ emptyStr() {
+ return false;
+ }
+ get names() {
+ return { [this.str]: 1 };
+ }
}
-
-
-
-/**
- * Validate data using schema
- * Schema will be compiled and cached (using serialized JSON as key. [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used to serialize.
- * @this Ajv
- * @param {String|Object} schemaKeyRef key, ref or schema object
- * @param {Any} data to be validated
- * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
- */
-function validate(schemaKeyRef, data) {
- var v;
- if (typeof schemaKeyRef == 'string') {
- v = this.getSchema(schemaKeyRef);
- if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
- } else {
- var schemaObj = this._addSchema(schemaKeyRef);
- v = schemaObj.validate || this._compile(schemaObj);
- }
-
- var valid = v(data);
- if (v.$async !== true) this.errors = v.errors;
- return valid;
+exports.Name = Name;
+class _Code extends _CodeOrName {
+ constructor(code) {
+ super();
+ this._items = typeof code === "string" ? [code] : code;
+ }
+ toString() {
+ return this.str;
+ }
+ emptyStr() {
+ if (this._items.length > 1)
+ return false;
+ const item = this._items[0];
+ return item === "" || item === '""';
+ }
+ get str() {
+ var _a;
+ return ((_a = this._str) !== null && _a !== void 0 ? _a : (this._str = this._items.reduce((s, c) => `${s}${c}`, "")));
+ }
+ get names() {
+ var _a;
+ return ((_a = this._names) !== null && _a !== void 0 ? _a : (this._names = this._items.reduce((names, c) => {
+ if (c instanceof Name)
+ names[c.str] = (names[c.str] || 0) + 1;
+ return names;
+ }, {})));
+ }
+}
+exports._Code = _Code;
+exports.nil = new _Code("");
+function _(strs, ...args) {
+ const code = [strs[0]];
+ let i = 0;
+ while (i < args.length) {
+ addCodeArg(code, args[i]);
+ code.push(strs[++i]);
+ }
+ return new _Code(code);
}
-
-
-/**
- * Create validating function for passed schema.
- * @this Ajv
- * @param {Object} schema schema object
- * @param {Boolean} _meta true if schema is a meta-schema. Used internally to compile meta schemas of custom keywords.
- * @return {Function} validating function
- */
-function compile(schema, _meta) {
- var schemaObj = this._addSchema(schema, undefined, _meta);
- return schemaObj.validate || this._compile(schemaObj);
+exports._ = _;
+const plus = new _Code("+");
+function str(strs, ...args) {
+ const expr = [safeStringify(strs[0])];
+ let i = 0;
+ while (i < args.length) {
+ expr.push(plus);
+ addCodeArg(expr, args[i]);
+ expr.push(plus, safeStringify(strs[++i]));
+ }
+ optimize(expr);
+ return new _Code(expr);
+}
+exports.str = str;
+function addCodeArg(code, arg) {
+ if (arg instanceof _Code)
+ code.push(...arg._items);
+ else if (arg instanceof Name)
+ code.push(arg);
+ else
+ code.push(interpolate(arg));
+}
+exports.addCodeArg = addCodeArg;
+function optimize(expr) {
+ let i = 1;
+ while (i < expr.length - 1) {
+ if (expr[i] === plus) {
+ const res = mergeExprItems(expr[i - 1], expr[i + 1]);
+ if (res !== undefined) {
+ expr.splice(i - 1, 3, res);
+ continue;
+ }
+ expr[i++] = "+";
+ }
+ i++;
+ }
}
-
-
-/**
- * Adds schema to the instance.
- * @this Ajv
- * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
- * @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
- * @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
- * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
- * @return {Ajv} this for method chaining
- */
-function addSchema(schema, key, _skipValidation, _meta) {
- if (Array.isArray(schema)){
- for (var i=0; i"),
+ GTE: new code_1._Code(">="),
+ LT: new code_1._Code("<"),
+ LTE: new code_1._Code("<="),
+ EQ: new code_1._Code("==="),
+ NEQ: new code_1._Code("!=="),
+ NOT: new code_1._Code("!"),
+ OR: new code_1._Code("||"),
+ AND: new code_1._Code("&&"),
+ ADD: new code_1._Code("+"),
+};
+class Node {
+ optimizeNodes() {
+ return this;
+ }
+ optimizeNames(_names, _constants) {
+ return this;
}
- }
-}
-
-
-/* @this Ajv */
-function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
- if (typeof schema != 'object' && typeof schema != 'boolean')
- throw new Error('schema should be object or boolean');
- var serialize = this._opts.serialize;
- var cacheKey = serialize ? serialize(schema) : schema;
- var cached = this._cache.get(cacheKey);
- if (cached) return cached;
-
- shouldAddSchema = shouldAddSchema || this._opts.addUsedSchema !== false;
-
- var id = resolve.normalizeId(this._getId(schema));
- if (id && shouldAddSchema) checkUnique(this, id);
-
- var willValidate = this._opts.validateSchema !== false && !skipValidation;
- var recursiveMeta;
- if (willValidate && !(recursiveMeta = id && id == resolve.normalizeId(schema.$schema)))
- this.validateSchema(schema, true);
-
- var localRefs = resolve.ids.call(this, schema);
-
- var schemaObj = new SchemaObject({
- id: id,
- schema: schema,
- localRefs: localRefs,
- cacheKey: cacheKey,
- meta: meta
- });
-
- if (id[0] != '#' && shouldAddSchema) this._refs[id] = schemaObj;
- this._cache.put(cacheKey, schemaObj);
-
- if (willValidate && recursiveMeta) this.validateSchema(schema, true);
-
- return schemaObj;
}
-
-
-/* @this Ajv */
-function _compile(schemaObj, root) {
- if (schemaObj.compiling) {
- schemaObj.validate = callValidate;
- callValidate.schema = schemaObj.schema;
- callValidate.errors = null;
- callValidate.root = root ? root : callValidate;
- if (schemaObj.schema.$async === true)
- callValidate.$async = true;
- return callValidate;
- }
- schemaObj.compiling = true;
-
- var currentOpts;
- if (schemaObj.meta) {
- currentOpts = this._opts;
- this._opts = this._metaOpts;
- }
-
- var v;
- try { v = compileSchema.call(this, schemaObj.schema, root, schemaObj.localRefs); }
- catch(e) {
- delete schemaObj.validate;
- throw e;
- }
- finally {
- schemaObj.compiling = false;
- if (schemaObj.meta) this._opts = currentOpts;
- }
-
- schemaObj.validate = v;
- schemaObj.refs = v.refs;
- schemaObj.refVal = v.refVal;
- schemaObj.root = v.root;
- return v;
-
-
- /* @this {*} - custom context, see passContext option */
- function callValidate() {
- /* jshint validthis: true */
- var _validate = schemaObj.validate;
- var result = _validate.apply(this, arguments);
- callValidate.errors = _validate.errors;
- return result;
- }
+class Def extends Node {
+ constructor(varKind, name, rhs) {
+ super();
+ this.varKind = varKind;
+ this.name = name;
+ this.rhs = rhs;
+ }
+ render({ es5, _n }) {
+ const varKind = es5 ? scope_1.varKinds.var : this.varKind;
+ const rhs = this.rhs === undefined ? "" : ` = ${this.rhs}`;
+ return `${varKind} ${this.name}${rhs};` + _n;
+ }
+ optimizeNames(names, constants) {
+ if (!names[this.name.str])
+ return;
+ if (this.rhs)
+ this.rhs = optimizeExpr(this.rhs, names, constants);
+ return this;
+ }
+ get names() {
+ return this.rhs instanceof code_1._CodeOrName ? this.rhs.names : {};
+ }
}
-
-
-function chooseGetId(opts) {
- switch (opts.schemaId) {
- case 'auto': return _get$IdOrId;
- case 'id': return _getId;
- default: return _get$Id;
- }
+class Assign extends Node {
+ constructor(lhs, rhs, sideEffects) {
+ super();
+ this.lhs = lhs;
+ this.rhs = rhs;
+ this.sideEffects = sideEffects;
+ }
+ render({ _n }) {
+ return `${this.lhs} = ${this.rhs};` + _n;
+ }
+ optimizeNames(names, constants) {
+ if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
+ return;
+ this.rhs = optimizeExpr(this.rhs, names, constants);
+ return this;
+ }
+ get names() {
+ const names = this.lhs instanceof code_1.Name ? {} : { ...this.lhs.names };
+ return addExprNames(names, this.rhs);
+ }
}
-
-/* @this Ajv */
-function _getId(schema) {
- if (schema.$id) this.logger.warn('schema $id ignored', schema.$id);
- return schema.id;
+class AssignOp extends Assign {
+ constructor(lhs, op, rhs, sideEffects) {
+ super(lhs, rhs, sideEffects);
+ this.op = op;
+ }
+ render({ _n }) {
+ return `${this.lhs} ${this.op}= ${this.rhs};` + _n;
+ }
}
-
-/* @this Ajv */
-function _get$Id(schema) {
- if (schema.id) this.logger.warn('schema id ignored', schema.id);
- return schema.$id;
+class Label extends Node {
+ constructor(label) {
+ super();
+ this.label = label;
+ this.names = {};
+ }
+ render({ _n }) {
+ return `${this.label}:` + _n;
+ }
}
-
-
-function _get$IdOrId(schema) {
- if (schema.$id && schema.id && schema.$id != schema.id)
- throw new Error('schema $id is different from id');
- return schema.$id || schema.id;
+class Break extends Node {
+ constructor(label) {
+ super();
+ this.label = label;
+ this.names = {};
+ }
+ render({ _n }) {
+ const label = this.label ? ` ${this.label}` : "";
+ return `break${label};` + _n;
+ }
}
-
-
-/**
- * Convert array of error message objects to string
- * @this Ajv
- * @param {Array