Skip to content

Commit

Permalink
Bump to 1.5.0 (#93)
Browse files Browse the repository at this point in the history
* Bump to 1.5.0

* Update changelog
  • Loading branch information
talyssonoc authored Jul 8, 2019
1 parent f254c0d commit 6de520a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.5.0 - 2019-07-08
Enhancements:
* Add `buildStrict` static method

## 1.4.0 - 2019-03-26
Enhancements:
* Add `nullable` option
Expand Down
23 changes: 22 additions & 1 deletion dist/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ return /******/ (function(modules) { // webpackBootstrap
}
});

function buildStrict(constructorArgs) {
var instance = new WrapperClass(constructorArgs);

var _instance$validate = instance.validate(),
valid = _instance$validate.valid,
errors = _instance$validate.errors;

if (!valid) throw Errors.invalidAttributes(errors);

return instance;
}

WrapperClass.buildStrict = buildStrict;

if (WrapperClass[SCHEMA]) {
schema = Object.assign({}, WrapperClass[SCHEMA], schema);
}
Expand Down Expand Up @@ -838,6 +852,12 @@ return /******/ (function(modules) { // webpackBootstrap

'use strict';

function invalidAttributes(errors) {
var error = new Error('Invalid Attributes');
error.details = errors;
return error;
}

module.exports = {
classAsSecondParam: function classAsSecondParam(ErroneousPassedClass) {
return new Error('You passed the structure class as the second parameter of attributes(). The expected usage is `attributes(schema)(' + (ErroneousPassedClass.name || 'StructureClass') + ')`.');
Expand All @@ -853,7 +873,8 @@ return /******/ (function(modules) { // webpackBootstrap
},
invalidType: function invalidType(attributeName) {
return new TypeError('Attribute type must be a constructor or the name of a dynamic type: ' + attributeName + '.');
}
},
invalidAttributes: invalidAttributes
};

/***/ },
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "structure",
"version": "1.4.0",
"version": "1.5.0",
"description": "A simple schema/attributes library built on top of modern JavaScript",
"main": "src/index.js",
"browser": "dist/structure.js",
Expand Down

0 comments on commit 6de520a

Please sign in to comment.