metaschema
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -139,5 +139,34 @@ 'use strict'; | ||
}; | ||
var MetaschemaError = | ||
/*#__PURE__*/ | ||
function (_Error3) { | ||
_inherits(MetaschemaError, _Error3); | ||
function MetaschemaError(errors) { | ||
var _this3; | ||
_classCallCheck(this, MetaschemaError); | ||
_this3 = _possibleConstructorReturn(this, _getPrototypeOf(MetaschemaError).call(this)); | ||
_this3.errors = errors; | ||
return _this3; | ||
} | ||
_createClass(MetaschemaError, [{ | ||
key: "toString", | ||
value: function toString() { | ||
return this.errors.map(function (e) { | ||
return e.toString(); | ||
}).join('\n'); | ||
} | ||
}]); | ||
return MetaschemaError; | ||
}(_wrapNativeSuper(Error)); | ||
module.exports = { | ||
SchemaValidationError: SchemaValidationError, | ||
ValidationError: ValidationError | ||
ValidationError: ValidationError, | ||
MetaschemaError: MetaschemaError | ||
}; |
@@ -198,3 +198,3 @@ 'use strict'; | ||
// types with lower values are processed earlier. | ||
// Returns: [<Error[]>, <Metaschema>] | ||
// Returns: <Metaschema> | ||
@@ -201,0 +201,0 @@ |
@@ -11,2 +11,10 @@ 'use strict'; | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -21,2 +29,5 @@ | ||
var _require2 = require('./errors'), | ||
MetaschemaError = _require2.MetaschemaError; | ||
var Metaschema = | ||
@@ -46,3 +57,3 @@ /*#__PURE__*/ | ||
// options <Object> | ||
// Returns: <Error[]> | ||
// Returns: <Error> | <null> | ||
value: function validate(type, schema, instance, options) { | ||
@@ -59,3 +70,4 @@ if (typeof schema === 'string') { | ||
return validator(this, schema, instance, options); | ||
var errors = validator(this, schema, instance, options); | ||
return errors.length === 0 ? null : new MetaschemaError(errors); | ||
} // Creates an instance of given schema | ||
@@ -67,5 +79,3 @@ // type <string> | ||
// options <Object> | ||
// Returns: | ||
// <Error[]> | ||
// <any> | ||
// Returns: <any> | ||
@@ -85,6 +95,11 @@ }, { | ||
return creator(this, schema, args, options); | ||
var _creator = creator(this, schema, args, options), | ||
_creator2 = _slicedToArray(_creator, 2), | ||
errors = _creator2[0], | ||
result = _creator2[1]; | ||
if (errors.length !== 0) throw new MetaschemaError(errors); | ||
return result; | ||
} // Adds multiple schemas | ||
// schemas <Schema> | <Schema[]> | ||
// Returns: <Error[]> | ||
@@ -200,5 +215,3 @@ }, { | ||
if (errors.length) { | ||
return errors; | ||
} | ||
if (errors.length !== 0) throw new MetaschemaError(errors); | ||
@@ -258,3 +271,3 @@ (_this$schemas = this.schemas).push.apply(_this$schemas, _toConsumableArray(schemas)); | ||
return errors; | ||
if (errors.length !== 0) throw new MetaschemaError(errors); | ||
} // Creates Metaschema object and fills it with schemas | ||
@@ -311,3 +324,3 @@ // schemas <Schema[]> | ||
// types with lower values are processed earlier. | ||
// Returns: [<Error[]>, <Metaschema>] | ||
// Returns: <Metaschema> | ||
@@ -335,3 +348,4 @@ }, { | ||
return [ms.addSchemas(schemas), ms]; | ||
ms.addSchemas(schemas); | ||
return ms; | ||
} | ||
@@ -338,0 +352,0 @@ }]); |
@@ -198,10 +198,16 @@ 'use strict'; | ||
var err = void 0; | ||
if (definition.domain) { | ||
opts.path = "".concat(path).concat(prop); | ||
errors.push.apply(errors, _toConsumableArray(ms.validate('domains', definition.domain, value, opts))); | ||
err = ms.validate('domains', definition.domain, value, opts); | ||
} else if (definition.category) { | ||
opts.path = "".concat(path).concat(prop, "."); | ||
errors.push.apply(errors, _toConsumableArray(ms.validate('category', definition.category, value, opts))); | ||
err = ms.validate('category', definition.category, value, opts); | ||
} | ||
if (err) { | ||
errors.push.apply(errors, _toConsumableArray(err.errors)); | ||
} | ||
if (definition.validate && !definition.validate(value)) { | ||
@@ -208,0 +214,0 @@ errors.push(new ValidationError('propValidation', "".concat(path).concat(prop))); |
@@ -60,5 +60,17 @@ 'use strict'; | ||
class MetaschemaError extends Error { | ||
constructor(errors) { | ||
super(); | ||
this.errors = errors; | ||
} | ||
toString() { | ||
return this.errors.map(e => e.toString()).join('\n'); | ||
} | ||
} | ||
module.exports = { | ||
SchemaValidationError, | ||
ValidationError, | ||
MetaschemaError, | ||
}; |
@@ -130,3 +130,3 @@ 'use strict'; | ||
// types with lower values are processed earlier. | ||
// Returns: [<Error[]>, <Metaschema>] | ||
// Returns: <Metaschema> | ||
const load = async (dir, options, config) => { | ||
@@ -133,0 +133,0 @@ if (!Array.isArray(dir)) { |
'use strict'; | ||
const { getProcessOrder } = require('./utils'); | ||
const { MetaschemaError } = require('./errors'); | ||
@@ -32,3 +33,3 @@ class Metaschema { | ||
// options <Object> | ||
// Returns: <Error[]> | ||
// Returns: <Error> | <null> | ||
validate(type, schema, instance, options) { | ||
@@ -42,3 +43,4 @@ if (typeof schema === 'string') { | ||
} | ||
return validator(this, schema, instance, options); | ||
const errors = validator(this, schema, instance, options); | ||
return errors.length === 0 ? null : new MetaschemaError(errors); | ||
} | ||
@@ -52,5 +54,3 @@ | ||
// options <Object> | ||
// Returns: | ||
// <Error[]> | ||
// <any> | ||
// Returns: <any> | ||
create(type, schema, args, options) { | ||
@@ -64,3 +64,5 @@ if (typeof schema === 'string') { | ||
} | ||
return creator(this, schema, args, options); | ||
const [errors, result] = creator(this, schema, args, options); | ||
if (errors.length !== 0) throw new MetaschemaError(errors); | ||
return result; | ||
} | ||
@@ -70,3 +72,2 @@ | ||
// schemas <Schema> | <Schema[]> | ||
// Returns: <Error[]> | ||
addSchemas(schemas) { | ||
@@ -97,5 +98,4 @@ const errors = []; | ||
if (errors.length) { | ||
return errors; | ||
} | ||
if (errors.length !== 0) throw new MetaschemaError(errors); | ||
this.schemas.push(...schemas); | ||
@@ -113,3 +113,3 @@ | ||
return errors; | ||
if (errors.length !== 0) throw new MetaschemaError(errors); | ||
} | ||
@@ -168,3 +168,3 @@ | ||
// types with lower values are processed earlier. | ||
// Returns: [<Error[]>, <Metaschema>] | ||
// Returns: <Metaschema> | ||
static create(schemas, config) { | ||
@@ -175,3 +175,4 @@ const ms = new Metaschema(config); | ||
} | ||
return [ms.addSchemas(schemas), ms]; | ||
ms.addSchemas(schemas); | ||
return ms; | ||
} | ||
@@ -178,0 +179,0 @@ } |
@@ -161,9 +161,13 @@ 'use strict'; | ||
let err; | ||
if (definition.domain) { | ||
opts.path = `${path}${prop}`; | ||
errors.push(...ms.validate('domains', definition.domain, value, opts)); | ||
err = ms.validate('domains', definition.domain, value, opts); | ||
} else if (definition.category) { | ||
opts.path = `${path}${prop}.`; | ||
errors.push(...ms.validate('category', definition.category, value, opts)); | ||
err = ms.validate('category', definition.category, value, opts); | ||
} | ||
if (err) { | ||
errors.push(...err.errors); | ||
} | ||
@@ -170,0 +174,0 @@ if (definition.validate && !definition.validate(value)) { |
{ | ||
"name": "metaschema", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Metadata Schema and Interface Definition Language (IDL)", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118627
2888