From 6962952b289adef3c23c65e87f50a77abbea5c44 Mon Sep 17 00:00:00 2001 From: Talysson Date: Wed, 1 Feb 2017 14:33:00 -0200 Subject: [PATCH 1/5] Add docs to circular reference --- docs/README.md | 14 ++++++++++++ docs/schema-concept.md | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/docs/README.md b/docs/README.md index 29e5db9..2ca6ee7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,8 +2,22 @@ * [Introduction](/README.md) * [Schema concept](/docs/schema-concept.md) + * [Shorthand type descriptor](/docs/schema-concept.md#shorthand-type-descriptor) + * [Complete type descriptor](/docs/schema-concept.md#complete-type-descriptor) + * [Circular references and dynamic types](/docs/schema-concept.md#circular-references-and-dynamic-types) * [Coercion](/docs/coercion.md) + * [Primitive type coercion](/docs/coercion.md#primitive-type-coercion) + * [Arrays coercion](/docs/coercion.md#arrays-and-array-subclasses) + * [Generic coercion](/docs/coercion.md#generic-coercion) * [Validation](/docs/validation.md) + * [String validations](/docs/validation.md#string-validations) + * [Number validations](/docs/validation.md#number-validations) + * [Boolean validations](/docs/validation.md#boolean-validations) + * [Date validations](/docs/validation.md#date-validations) + * [Array validations](/docs/validation.md#array-validations) + * [Attribute reference](/docs/validation.md#attribute-reference) + * [Nested validations](/docs/validation.md#nested-validations) + * [Validate raw data](/docs/validation.md#validate-raw-data) * [Serialization](/docs/serialization.md) * [Contributing](/contributing.md) * [License](/license.md) diff --git a/docs/schema-concept.md b/docs/schema-concept.md index d503c47..a6c191d 100644 --- a/docs/schema-concept.md +++ b/docs/schema-concept.md @@ -54,3 +54,52 @@ Each attribute needs a __Type__ definition, that's how Structure validates and c - Classes (Date, Object, regular Classes and Structure classes as well) - Array/Array-like (Array, extended Array) +### Circular references and dynamic types + +Sometimes we may need to have a type reference itself in its attributes, or have two types that reference eachother in separate files, it can be a complication because it's not possible to do this using the type definitions like we did before. For cases like this we can use a feature called "dynamic types". + +When using dynamic types you can pass a string instead of the type itself in the type definition, and pass an object as the _second_ parameter of the `attributes` function with an object with a key called `dynamics`. This key will have functions named after the dynamic attribute types, that will be called when the given type is used, like this: + + +```javascript +/* + * User.js +*/ +const User = attributes({ + name: String, + friends: { + type: Array, + itemType: 'User' // << dynamic type name + }, + favoriteBook: { + type: 'Book', // << dynamic type name + required: true + }, + books: { + type: 'BooksCollection', // << dynamic type name + itemType: String + } +}, { + dynamics: { // << dynamic types values + User: () => User, + Book: () => require('./Book'), + BooksCollection: () => require('./BooksCollection') + } +})(class User { }); + +/* + * Book.js +*/ +const Book = attributes({ + name: String, + owner: 'User', // << dynamic type name + nextBook: 'Book' // << dynamic type name +}, { + dynamics: { // << dynamic types values + User: () => require('./User'), + Book: () => Book + } +})(class Book { }); +``` + +Notice that the _name_ of the type has to be the same name of the key inside the `dynamics` object. Also, it's important that the require be done __inside__ the function when the dynamic type also references the current type (in the example above, the type `User` has an attribute of the type `Book`, and the type `Book` has an attribute of the type `User`). From c28a3da9bd385137d5f1899fab7e1a5e7d532cdc Mon Sep 17 00:00:00 2001 From: Talysson Date: Wed, 1 Feb 2017 14:33:11 -0200 Subject: [PATCH 2/5] Updte changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 445f6ac..7e9d57f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,12 @@ +## 1.2.0 - 2017-02-01 +Features: +* Allow circular reference on type definitions ([@talyssonoc](https://github.com/talyssonoc/structure/pull/30)) + +Enhancements: +* Make validation faster ([@talyssonoc](https://github.com/talyssonoc/structure/pull/28)) + +Dependencies update: +* Update joi from 9.2.0 to 10.2.0 ([@talyssonoc](https://github.com/talyssonoc/structure/pull/26)) + ## 1.1.0 - 2017-01-17 * Added static method `validate()` to structures ([@talyssonoc](https://github.com/talyssonoc/structure/pull/25)) From f214f7fc3806def7af9616b5b695f5ac0b44a369 Mon Sep 17 00:00:00 2001 From: Talysson Date: Wed, 1 Feb 2017 14:33:20 -0200 Subject: [PATCH 3/5] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1391ba5..13ecb91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "structure", - "version": "1.1.0", + "version": "1.2.0", "description": "A simple schema/attributes library built on top of modern JavaScript", "main": "src/index.js", "browser": "dist/structure.js", From 4266b6ae98aba048c100f336209356d244e1e9d1 Mon Sep 17 00:00:00 2001 From: Talysson Date: Wed, 1 Feb 2017 14:33:36 -0200 Subject: [PATCH 4/5] Update dist file --- dist/structure.js | 305 +++++++++++++++++++++++++++++----------------- 1 file changed, 192 insertions(+), 113 deletions(-) diff --git a/dist/structure.js b/dist/structure.js index a54c21d..d0b3f42 100644 --- a/dist/structure.js +++ b/dist/structure.js @@ -7,7 +7,7 @@ exports["Structure"] = factory(require("lodash"), require("joi")); else root["Structure"] = factory(root["_"], root["joi"]); -})(this, function(__WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_13__) { +})(this, function(__WEBPACK_EXTERNAL_MODULE_10__, __WEBPACK_EXTERNAL_MODULE_14__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; @@ -73,28 +73,32 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + var _require = __webpack_require__(3), normalizeSchema = _require.normalizeSchema; - var _require2 = __webpack_require__(22), + var _require2 = __webpack_require__(23), getInitialValues = _require2.getInitialValues; - var _require3 = __webpack_require__(14), + var _require3 = __webpack_require__(15), SCHEMA = _require3.SCHEMA; - var _require4 = __webpack_require__(23), + var _require4 = __webpack_require__(24), attributesDescriptor = _require4.attributesDescriptor, serializationDescriptor = _require4.serializationDescriptor; - var _require5 = __webpack_require__(12), - validationDescriptor = _require5.validationDescriptor, - staticValidationDescriptor = _require5.staticValidationDescriptor; + var _require5 = __webpack_require__(13), + validationDescriptorForSchema = _require5.validationDescriptorForSchema, + staticValidationDescriptorForSchema = _require5.staticValidationDescriptorForSchema; var define = Object.defineProperty; function attributesDecorator(declaredSchema) { - if (arguments.length > 1) { - var ErroneousPassedClass = arguments[1]; + var schemaOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if ((typeof schemaOptions === 'undefined' ? 'undefined' : _typeof(schemaOptions)) !== 'object') { + var ErroneousPassedClass = schemaOptions; var errorMessage = 'You passed the structure class as the second parameter of attributes(). The expected usage is `attributes(schema)(' + (ErroneousPassedClass.name || 'StructureClass') + ')`.'; @@ -113,7 +117,7 @@ return /******/ (function(modules) { // webpackBootstrap } }); - declaredSchema = normalizeSchema(declaredSchema); + declaredSchema = normalizeSchema(declaredSchema, schemaOptions); if (WrapperClass[SCHEMA]) { declaredSchema = Object.assign({}, WrapperClass[SCHEMA], declaredSchema); @@ -123,7 +127,7 @@ return /******/ (function(modules) { // webpackBootstrap value: declaredSchema }); - define(WrapperClass, 'validate', staticValidationDescriptor); + define(WrapperClass, 'validate', staticValidationDescriptorForSchema(declaredSchema)); define(WrapperClass.prototype, SCHEMA, { value: declaredSchema @@ -143,7 +147,7 @@ return /******/ (function(modules) { // webpackBootstrap }); }); - define(WrapperClass.prototype, 'validate', validationDescriptor); + define(WrapperClass.prototype, 'validate', validationDescriptorForSchema(declaredSchema)); define(WrapperClass.prototype, 'toJSON', serializationDescriptor); @@ -164,26 +168,49 @@ return /******/ (function(modules) { // webpackBootstrap var _require = __webpack_require__(4), coercionFor = _require.coercionFor; - var _require2 = __webpack_require__(12), + var _require2 = __webpack_require__(13), validationForAttribute = _require2.validationForAttribute, validationForSchema = _require2.validationForSchema; - var _require3 = __webpack_require__(14), + var _require3 = __webpack_require__(15), VALIDATE = _require3.VALIDATE; - function normalizeAttribute(attribute, attributeName) { + function normalizeSchema(rawSchema, schemaOptions) { + var schema = Object.create(null); + + Object.keys(rawSchema).forEach(function (attributeName) { + schema[attributeName] = normalizeAttribute(schemaOptions, rawSchema[attributeName], attributeName); + }); + + var schemaValidation = validationForSchema(schema); + + Object.defineProperty(schema, VALIDATE, { + value: schemaValidation + }); + + return schema; + } + + function normalizeAttribute(schemaOptions, attribute, attributeName) { switch (typeof attribute === 'undefined' ? 'undefined' : _typeof(attribute)) { case 'object': if (!attribute.type) { throw new Error('Missing type for attribute: ' + attributeName + '.'); } - if (typeof attribute.type !== 'function') { + if (typeof attribute.type === 'string') { + if (!schemaOptions.dynamics || !schemaOptions.dynamics[attribute.type]) { + throw new Error('There is no dynamic type for attribute: ' + attributeName + '.'); + } + + attribute.getType = schemaOptions.dynamics[attribute.type]; + attribute.dynamicType = true; + } else if (typeof attribute.type !== 'function') { throw new TypeError('Attribute type must be a constructor: ' + attributeName + '.'); } if (attribute.itemType) { - attribute.itemType = normalizeAttribute(attribute.itemType, 'itemType'); + attribute.itemType = normalizeAttribute(schemaOptions, attribute.itemType, 'itemType'); } return Object.assign({}, attribute, { @@ -192,33 +219,14 @@ return /******/ (function(modules) { // webpackBootstrap }); case 'function': - var normalizedType = { type: attribute }; - normalizedType.coerce = coercionFor(normalizedType); - normalizedType.validation = validationForAttribute(normalizedType); - - return normalizedType; + case 'string': + return normalizeAttribute(schemaOptions, { type: attribute }, attributeName); default: throw new TypeError('Invalid type for attribute: ' + attributeName + '.'); } } - function normalizeSchema(rawSchema) { - var schema = Object.create(null); - - Object.keys(rawSchema).forEach(function (attributeName) { - schema[attributeName] = normalizeAttribute(rawSchema[attributeName], attributeName); - }); - - var schemaValidation = validationForSchema(schema); - - Object.defineProperty(schema, VALIDATE, { - value: schemaValidation - }); - - return schema; - } - exports.normalizeSchema = normalizeSchema; exports.VALIDATE = VALIDATE; @@ -229,9 +237,9 @@ return /******/ (function(modules) { // webpackBootstrap 'use strict'; var arrayCoercionFor = __webpack_require__(5); - var genericCoercionFor = __webpack_require__(7); + var genericCoercionFor = __webpack_require__(8); - var types = [__webpack_require__(8), __webpack_require__(10), __webpack_require__(11)]; + var types = [__webpack_require__(9), __webpack_require__(11), __webpack_require__(12)]; function coercionFor(typeDescriptor, itemTypeDescriptor) { if (itemTypeDescriptor) { @@ -272,6 +280,9 @@ return /******/ (function(modules) { // webpackBootstrap var _require = __webpack_require__(6), ARRAY_OR_ITERABLE = _require.ARRAY_OR_ITERABLE; + var _require2 = __webpack_require__(7), + getType = _require2.getType; + module.exports = function arrayCoercionFor(typeDescriptor, itemTypeDescriptor) { return function coerceArray(value) { if (value === undefined) { @@ -286,7 +297,8 @@ return /******/ (function(modules) { // webpackBootstrap value = Array.apply(undefined, _toConsumableArray(value)); } - var coercedValue = new typeDescriptor.type(); + var type = getType(typeDescriptor); + var coercedValue = new type(); for (var i = 0; i < value.length; i++) { coercedValue.push(itemTypeDescriptor.coerce(value[i])); @@ -313,27 +325,46 @@ return /******/ (function(modules) { // webpackBootstrap "use strict"; + exports.getType = function getType(typeDescriptor) { + if (typeDescriptor.dynamicType) { + return typeDescriptor.getType(); + } + + return typeDescriptor.type; + }; + +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var _require = __webpack_require__(7), + getType = _require.getType; + module.exports = function genericCoercionFor(typeDescriptor) { return function coerce(value) { if (value === undefined) { return; } - if (value instanceof typeDescriptor.type) { + var type = getType(typeDescriptor); + + if (value instanceof type) { return value; } - return new typeDescriptor.type(value); + return new type(value); }; }; /***/ }, -/* 8 */ +/* 9 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var _require = __webpack_require__(9), + var _require = __webpack_require__(10), isString = _require.isString; module.exports = { @@ -349,18 +380,18 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 9 */ +/* 10 */ /***/ function(module, exports) { - module.exports = __WEBPACK_EXTERNAL_MODULE_9__; + module.exports = __WEBPACK_EXTERNAL_MODULE_10__; /***/ }, -/* 10 */ +/* 11 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var _require = __webpack_require__(9), + var _require = __webpack_require__(10), isNumber = _require.isNumber; module.exports = { @@ -376,7 +407,7 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 11 */ +/* 12 */ /***/ function(module, exports) { "use strict"; @@ -389,21 +420,21 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 12 */ +/* 13 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var joi = __webpack_require__(13); + var joi = __webpack_require__(14); - var _require = __webpack_require__(14), + var _require = __webpack_require__(15), SCHEMA = _require.SCHEMA, VALIDATE = _require.VALIDATE; - var validations = [__webpack_require__(15), __webpack_require__(17), __webpack_require__(18), __webpack_require__(19)]; + var validations = [__webpack_require__(16), __webpack_require__(18), __webpack_require__(19), __webpack_require__(20)]; - var nestedValidation = __webpack_require__(20); - var arrayValidation = __webpack_require__(21); + var nestedValidation = __webpack_require__(21); + var arrayValidation = __webpack_require__(22); exports.validationForAttribute = function validationForAttribute(typeDescriptor) { if (typeDescriptor.itemType !== undefined) { @@ -458,25 +489,30 @@ return /******/ (function(modules) { // webpackBootstrap }; }; - exports.validationDescriptor = { - value: function validate() { - var validation = this[SCHEMA][VALIDATE]; - var serializedStructure = this.toJSON(); + exports.validationDescriptorForSchema = function validationDescriptorForSchema(schema) { + var validation = schema[VALIDATE]; - return validateData(validation, serializedStructure); - } - }; + return { + value: function validate() { + var serializedStructure = this.toJSON(); - exports.staticValidationDescriptor = { - value: function validate(data) { - if (data[SCHEMA]) { - data = data.toJSON(); + return validateData(validation, serializedStructure); } + }; + }; - var validation = this[SCHEMA][VALIDATE]; + exports.staticValidationDescriptorForSchema = function staticValidationDescriptorForSchema(schema) { + var validation = schema[VALIDATE]; - return validateData(validation, data); - } + return { + value: function validate(data) { + if (data[SCHEMA]) { + data = data.toJSON(); + } + + return validateData(validation, data); + } + }; }; function validateData(validation, data) { @@ -493,13 +529,13 @@ return /******/ (function(modules) { // webpackBootstrap } /***/ }, -/* 13 */ +/* 14 */ /***/ function(module, exports) { - module.exports = __WEBPACK_EXTERNAL_MODULE_13__; + module.exports = __WEBPACK_EXTERNAL_MODULE_14__; /***/ }, -/* 14 */ +/* 15 */ /***/ function(module, exports) { 'use strict'; @@ -511,14 +547,14 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 15 */ +/* 16 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var joi = __webpack_require__(13); + var joi = __webpack_require__(14); - var _require = __webpack_require__(16), + var _require = __webpack_require__(17), mapToJoi = _require.mapToJoi, equalOption = _require.equalOption; @@ -539,16 +575,16 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 16 */ +/* 17 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _slicedToArray = function () { function sliceIterator(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"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); - var joi = __webpack_require__(13); + var joi = __webpack_require__(14); - var _require = __webpack_require__(9), + var _require = __webpack_require__(10), isPlainObject = _require.isPlainObject; exports.mapToJoi = function mapToJoi(typeDescriptor, _ref) { @@ -620,15 +656,25 @@ return /******/ (function(modules) { // webpackBootstrap return initial.equal(possibilities); }; + exports.requiredOption = function requiredOption(typeDescriptor, _ref8) { + var initial = _ref8.initial; + + if (typeDescriptor.required) { + return initial.required(); + } + + return initial; + }; + /***/ }, -/* 17 */ +/* 18 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var joi = __webpack_require__(13); + var joi = __webpack_require__(14); - var _require = __webpack_require__(16), + var _require = __webpack_require__(17), mapToJoi = _require.mapToJoi, mapToJoiWithReference = _require.mapToJoiWithReference, equalOption = _require.equalOption; @@ -650,14 +696,14 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 18 */ +/* 19 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var joi = __webpack_require__(13); + var joi = __webpack_require__(14); - var _require = __webpack_require__(16), + var _require = __webpack_require__(17), mapToJoi = _require.mapToJoi, equalOption = _require.equalOption; @@ -674,14 +720,14 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 19 */ +/* 20 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var joi = __webpack_require__(13); + var joi = __webpack_require__(14); - var _require = __webpack_require__(16), + var _require = __webpack_require__(17), mapToJoi = _require.mapToJoi, mapToJoiWithReference = _require.mapToJoiWithReference, equalOption = _require.equalOption; @@ -703,46 +749,72 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 20 */ +/* 21 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var joi = __webpack_require__(13); + var joi = __webpack_require__(14); - var _require = __webpack_require__(14), + var _require = __webpack_require__(15), SCHEMA = _require.SCHEMA; + var _require2 = __webpack_require__(17), + requiredOption = _require2.requiredOption; + module.exports = function nestedValidation(typeDescriptor) { - var joiSchema = joi.object(); + if (typeDescriptor.dynamicType) { + return validationToDynamicType(typeDescriptor); + } + var typeSchema = typeDescriptor.type[SCHEMA]; + var joiSchema = getNestedValidations(typeSchema); - if (typeSchema !== undefined) { - var nestedValidations = {}; + joiSchema = requiredOption(typeDescriptor, { + initial: joiSchema + }); - Object.keys(typeSchema).forEach(function (v) { - nestedValidations[v] = typeSchema[v].validation; - }); + return joiSchema; + }; - joiSchema = joiSchema.keys(nestedValidations); - } + function validationToDynamicType(typeDescriptor) { + var joiSchema = joi.lazy(function () { + var typeSchema = typeDescriptor.getType()[SCHEMA]; - if (typeDescriptor.required) { - joiSchema = joiSchema.required(); + return getNestedValidations(typeSchema); + }); + + joiSchema = requiredOption(typeDescriptor, { + initial: joiSchema + }); + + return joiSchema; + } + + function getNestedValidations(typeSchema) { + var joiSchema = joi.object(); + + if (typeSchema) { + var nestedValidations = Object.keys(typeSchema).reduce(function (validations, v) { + validations[v] = typeSchema[v].validation; + return validations; + }, {}); + + joiSchema = joiSchema.keys(nestedValidations); } return joiSchema; - }; + } /***/ }, -/* 21 */ +/* 22 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var joi = __webpack_require__(13); + var joi = __webpack_require__(14); - var _require = __webpack_require__(16), + var _require = __webpack_require__(17), mapToJoi = _require.mapToJoi; var joiMappings = [['required', 'required'], ['minLength', 'min', true], ['maxLength', 'max', true], ['exactLength', 'length', true]]; @@ -759,7 +831,7 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 22 */ +/* 23 */ /***/ function(module, exports) { 'use strict'; @@ -783,21 +855,21 @@ return /******/ (function(modules) { // webpackBootstrap exports.getInitialValues = getInitialValues; /***/ }, -/* 23 */ +/* 24 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; - var _require = __webpack_require__(14), + var _require = __webpack_require__(15), SCHEMA = _require.SCHEMA, ATTRIBUTES = _require.ATTRIBUTES; var _require2 = __webpack_require__(6), NON_OBJECT_ATTRIBUTES = _require2.NON_OBJECT_ATTRIBUTES; - var _require3 = __webpack_require__(24), + var _require3 = __webpack_require__(25), serialize = _require3.serialize; var createAttrs = function createAttrs() { @@ -836,14 +908,17 @@ return /******/ (function(modules) { // webpackBootstrap }; /***/ }, -/* 24 */ +/* 25 */ /***/ function(module, exports, __webpack_require__) { 'use strict'; - var _require = __webpack_require__(14), + var _require = __webpack_require__(15), SCHEMA = _require.SCHEMA; + var _require2 = __webpack_require__(7), + getType = _require2.getType; + function serialize(structure) { if (structure === undefined) { return; @@ -861,9 +936,9 @@ return /******/ (function(modules) { // webpackBootstrap var serializedValue = void 0; - if (schema[attrName].itemType && schema[attrName].itemType.type[SCHEMA] !== undefined) { + if (schema[attrName].itemType && getTypeSchema(schema[attrName].itemType)) { serializedValue = attribute.map(serialize); - } else if (schema[attrName].type[SCHEMA] !== undefined) { + } else if (getTypeSchema(schema[attrName])) { serializedValue = serialize(attribute); } else { serializedValue = attribute; @@ -875,6 +950,10 @@ return /******/ (function(modules) { // webpackBootstrap return serializedStructure; } + function getTypeSchema(typeDescriptor) { + return getType(typeDescriptor)[SCHEMA]; + } + exports.serialize = serialize; /***/ } From 01dedeb9c94c2f2e76393ff6d5d5e3c68f79f5f7 Mon Sep 17 00:00:00 2001 From: Talysson Date: Wed, 1 Feb 2017 14:37:10 -0200 Subject: [PATCH 5/5] Make summary item shorter --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 2ca6ee7..533a47c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,7 @@ * [Schema concept](/docs/schema-concept.md) * [Shorthand type descriptor](/docs/schema-concept.md#shorthand-type-descriptor) * [Complete type descriptor](/docs/schema-concept.md#complete-type-descriptor) - * [Circular references and dynamic types](/docs/schema-concept.md#circular-references-and-dynamic-types) + * [Circular reference](/docs/schema-concept.md#circular-references-and-dynamic-types) * [Coercion](/docs/coercion.md) * [Primitive type coercion](/docs/coercion.md#primitive-type-coercion) * [Arrays coercion](/docs/coercion.md#arrays-and-array-subclasses)