New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

shapeshifter

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shapeshifter - npm Package Compare versions

Comparing version 2.2.2 to 2.3.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# 2.3.0
* Added a new shape reference feature, which allows for local reusable shapes in a JSON schema.
* Updated the visuals of errors and stack traces on the command line.
# 2.2.2

@@ -2,0 +6,0 @@ * Added flowtype definitions to the `libs/` output folder.

8

lib/constants.js

@@ -9,7 +9,7 @@ 'use strict';

* @license https://opensource.org/licenses/MIT
*
* @flow
*/
var PRIMITIVE_TYPES = exports.PRIMITIVE_TYPES = ['boolean', 'number', 'string'];
var COMPOUND_TYPES = exports.COMPOUND_TYPES = ['array', 'enum', 'instance', 'object', 'shape', 'union', 'function', 'reference'];
var TYPES = exports.TYPES = PRIMITIVE_TYPES.concat(COMPOUND_TYPES);
var PRIMITIVE_TYPES /*: string[]*/ = exports.PRIMITIVE_TYPES = ['boolean', 'number', 'string'];
var COMPOUND_TYPES /*: string[]*/ = exports.COMPOUND_TYPES = ['array', 'enum', 'instance', 'object', 'shape', 'union', 'function', 'reference'];
var TYPES /*: string[]*/ = exports.TYPES = PRIMITIVE_TYPES.concat(COMPOUND_TYPES);

@@ -7,8 +7,24 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _extends2 = require('babel-runtime/helpers/extends');
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _extends3 = _interopRequireDefault(_extends2);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
/*:: import type { Options } from './types';*/
var Definition = function () {

@@ -23,10 +39,9 @@

*/
function Definition(options, attribute) {
var config = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
function Definition(options /*: Options*/, attribute /*: string*/) {
var config /*: Object*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
(0, _classCallCheck3.default)(this, Definition);
_classCallCheck(this, Definition);
this.options = options;
this.attribute = attribute;
this.config = _extends({
this.config = (0, _extends3.default)({
null: options.defaultNull,

@@ -46,5 +61,5 @@ required: options.defaultRequired

_createClass(Definition, [{
(0, _createClass3.default)(Definition, [{
key: 'isNullable',
value: function isNullable() {
value: function isNullable() /*: boolean*/ {
return this.config.null;

@@ -61,3 +76,3 @@ }

key: 'isRequired',
value: function isRequired() {
value: function isRequired() /*: boolean*/ {
return this.config.required;

@@ -84,10 +99,5 @@ }

}]);
return Definition;
}(); /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
}();
exports.default = Definition;

@@ -7,6 +7,26 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -22,22 +42,19 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
/*:: import type { ArrayConfig } from '../types';*/
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var ArrayDefinition = function (_Definition) {
_inherits(ArrayDefinition, _Definition);
(0, _inherits3.default)(ArrayDefinition, _Definition);
function ArrayDefinition() {
_classCallCheck(this, ArrayDefinition);
return _possibleConstructorReturn(this, (ArrayDefinition.__proto__ || Object.getPrototypeOf(ArrayDefinition)).apply(this, arguments));
(0, _classCallCheck3.default)(this, ArrayDefinition);
return (0, _possibleConstructorReturn3.default)(this, (ArrayDefinition.__proto__ || (0, _getPrototypeOf2.default)(ArrayDefinition)).apply(this, arguments));
}
_createClass(ArrayDefinition, [{
(0, _createClass3.default)(ArrayDefinition, [{
key: 'validateConfig',

@@ -50,3 +67,3 @@

value: function validateConfig() {
_get(ArrayDefinition.prototype.__proto__ || Object.getPrototypeOf(ArrayDefinition.prototype), 'validateConfig', this).call(this);
(0, _get3.default)(ArrayDefinition.prototype.__proto__ || (0, _getPrototypeOf2.default)(ArrayDefinition.prototype), 'validateConfig', this).call(this);

@@ -63,3 +80,2 @@ var valueType = this.config.valueType;

}]);
return ArrayDefinition;

@@ -66,0 +82,0 @@ }(_Definition3.default);

@@ -7,2 +7,18 @@ 'use strict';

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -14,19 +30,14 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type { BoolConfig } from '../types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var BoolDefinition = function (_Definition) {
_inherits(BoolDefinition, _Definition);
(0, _inherits3.default)(BoolDefinition, _Definition);
function BoolDefinition() {
_classCallCheck(this, BoolDefinition);
return _possibleConstructorReturn(this, (BoolDefinition.__proto__ || Object.getPrototypeOf(BoolDefinition)).apply(this, arguments));
(0, _classCallCheck3.default)(this, BoolDefinition);
return (0, _possibleConstructorReturn3.default)(this, (BoolDefinition.__proto__ || (0, _getPrototypeOf2.default)(BoolDefinition)).apply(this, arguments));
}

@@ -33,0 +44,0 @@

@@ -7,8 +7,30 @@ '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 ? "symbol" : typeof obj; };
var _typeof2 = require('babel-runtime/helpers/typeof');
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof3 = _interopRequireDefault(_typeof2);
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -28,22 +50,17 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type { EnumConfig } from '../types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var EnumDefinition = function (_Definition) {
_inherits(EnumDefinition, _Definition);
(0, _inherits3.default)(EnumDefinition, _Definition);
function EnumDefinition() {
_classCallCheck(this, EnumDefinition);
return _possibleConstructorReturn(this, (EnumDefinition.__proto__ || Object.getPrototypeOf(EnumDefinition)).apply(this, arguments));
(0, _classCallCheck3.default)(this, EnumDefinition);
return (0, _possibleConstructorReturn3.default)(this, (EnumDefinition.__proto__ || (0, _getPrototypeOf2.default)(EnumDefinition)).apply(this, arguments));
}
_createClass(EnumDefinition, [{
(0, _createClass3.default)(EnumDefinition, [{
key: 'validateConfig',

@@ -58,7 +75,7 @@

_get(EnumDefinition.prototype.__proto__ || Object.getPrototypeOf(EnumDefinition.prototype), 'validateConfig', this).call(this);
(0, _get3.default)(EnumDefinition.prototype.__proto__ || (0, _getPrototypeOf2.default)(EnumDefinition.prototype), 'validateConfig', this).call(this);
var _config = this.config;
var values = _config.values;
var valueType = _config.valueType;
var _config = this.config,
values = _config.values,
valueType = _config.valueType;

@@ -88,3 +105,3 @@

key: 'validateValue',
value: function validateValue(value) {
value: function validateValue(value /*: mixed*/) /*: boolean*/ {
var valueType = (0, _normalizeType2.default)(this.config.valueType);

@@ -98,6 +115,5 @@

// eslint-disable-next-line valid-typeof
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === valueType;
return (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value)) === valueType;
}
}]);
return EnumDefinition;

@@ -104,0 +120,0 @@ }(_Definition3.default);

@@ -7,6 +7,26 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -22,22 +42,19 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
/*:: import type { FuncConfig } from '../types';*/
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var FuncDefinition = function (_Definition) {
_inherits(FuncDefinition, _Definition);
(0, _inherits3.default)(FuncDefinition, _Definition);
function FuncDefinition() {
_classCallCheck(this, FuncDefinition);
return _possibleConstructorReturn(this, (FuncDefinition.__proto__ || Object.getPrototypeOf(FuncDefinition)).apply(this, arguments));
(0, _classCallCheck3.default)(this, FuncDefinition);
return (0, _possibleConstructorReturn3.default)(this, (FuncDefinition.__proto__ || (0, _getPrototypeOf2.default)(FuncDefinition)).apply(this, arguments));
}
_createClass(FuncDefinition, [{
(0, _createClass3.default)(FuncDefinition, [{
key: 'validateConfig',

@@ -52,7 +69,7 @@

_get(FuncDefinition.prototype.__proto__ || Object.getPrototypeOf(FuncDefinition.prototype), 'validateConfig', this).call(this);
(0, _get3.default)(FuncDefinition.prototype.__proto__ || (0, _getPrototypeOf2.default)(FuncDefinition.prototype), 'validateConfig', this).call(this);
var _config = this.config;
var argTypes = _config.argTypes;
var returnType = _config.returnType;
var _config = this.config,
argTypes = _config.argTypes,
returnType = _config.returnType;

@@ -75,3 +92,2 @@

}]);
return FuncDefinition;

@@ -78,0 +94,0 @@ }(_Definition3.default);

@@ -7,6 +7,26 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -18,22 +38,17 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type { InstanceConfig } from '../types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var InstanceDefinition = function (_Definition) {
_inherits(InstanceDefinition, _Definition);
(0, _inherits3.default)(InstanceDefinition, _Definition);
function InstanceDefinition() {
_classCallCheck(this, InstanceDefinition);
return _possibleConstructorReturn(this, (InstanceDefinition.__proto__ || Object.getPrototypeOf(InstanceDefinition)).apply(this, arguments));
(0, _classCallCheck3.default)(this, InstanceDefinition);
return (0, _possibleConstructorReturn3.default)(this, (InstanceDefinition.__proto__ || (0, _getPrototypeOf2.default)(InstanceDefinition)).apply(this, arguments));
}
_createClass(InstanceDefinition, [{
(0, _createClass3.default)(InstanceDefinition, [{
key: 'validateConfig',

@@ -46,3 +61,3 @@

value: function validateConfig() {
_get(InstanceDefinition.prototype.__proto__ || Object.getPrototypeOf(InstanceDefinition.prototype), 'validateConfig', this).call(this);
(0, _get3.default)(InstanceDefinition.prototype.__proto__ || (0, _getPrototypeOf2.default)(InstanceDefinition.prototype), 'validateConfig', this).call(this);

@@ -59,3 +74,2 @@ var contract = this.config.contract;

}]);
return InstanceDefinition;

@@ -62,0 +76,0 @@ }(_Definition3.default);

@@ -7,2 +7,18 @@ 'use strict';

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -14,19 +30,14 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type { NumberConfig } from '../types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var NumberDefinition = function (_Definition) {
_inherits(NumberDefinition, _Definition);
(0, _inherits3.default)(NumberDefinition, _Definition);
function NumberDefinition() {
_classCallCheck(this, NumberDefinition);
return _possibleConstructorReturn(this, (NumberDefinition.__proto__ || Object.getPrototypeOf(NumberDefinition)).apply(this, arguments));
(0, _classCallCheck3.default)(this, NumberDefinition);
return (0, _possibleConstructorReturn3.default)(this, (NumberDefinition.__proto__ || (0, _getPrototypeOf2.default)(NumberDefinition)).apply(this, arguments));
}

@@ -33,0 +44,0 @@

@@ -7,8 +7,30 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _extends2 = require('babel-runtime/helpers/extends');
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _extends3 = _interopRequireDefault(_extends2);
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -24,14 +46,12 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
/*:: import type { Options, ObjectConfig } from '../types';*/
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var ObjectDefinition = function (_Definition) {
_inherits(ObjectDefinition, _Definition);
(0, _inherits3.default)(ObjectDefinition, _Definition);

@@ -41,6 +61,5 @@ /**

*/
function ObjectDefinition(options, attribute, config) {
_classCallCheck(this, ObjectDefinition);
return _possibleConstructorReturn(this, (ObjectDefinition.__proto__ || Object.getPrototypeOf(ObjectDefinition)).call(this, options, attribute, _extends({
function ObjectDefinition(options /*: Options*/, attribute /*: string*/, config /*: Object*/) {
(0, _classCallCheck3.default)(this, ObjectDefinition);
return (0, _possibleConstructorReturn3.default)(this, (ObjectDefinition.__proto__ || (0, _getPrototypeOf2.default)(ObjectDefinition)).call(this, options, attribute, (0, _extends3.default)({
keyType: 'string'

@@ -55,10 +74,10 @@ }, config)));

_createClass(ObjectDefinition, [{
(0, _createClass3.default)(ObjectDefinition, [{
key: 'validateConfig',
value: function validateConfig() {
_get(ObjectDefinition.prototype.__proto__ || Object.getPrototypeOf(ObjectDefinition.prototype), 'validateConfig', this).call(this);
(0, _get3.default)(ObjectDefinition.prototype.__proto__ || (0, _getPrototypeOf2.default)(ObjectDefinition.prototype), 'validateConfig', this).call(this);
var _config = this.config;
var keyType = _config.keyType;
var valueType = _config.valueType;
var _config = this.config,
keyType = _config.keyType,
valueType = _config.valueType;

@@ -78,3 +97,2 @@

}]);
return ObjectDefinition;

@@ -81,0 +99,0 @@ }(_Definition3.default);

@@ -7,8 +7,30 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _extends2 = require('babel-runtime/helpers/extends');
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _extends3 = _interopRequireDefault(_extends2);
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -20,14 +42,10 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type { Options, ReferenceConfig } from '../types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var ReferenceDefinition = function (_Definition) {
_inherits(ReferenceDefinition, _Definition);
(0, _inherits3.default)(ReferenceDefinition, _Definition);

@@ -37,6 +55,5 @@ /**

*/
function ReferenceDefinition(options, attribute, config) {
_classCallCheck(this, ReferenceDefinition);
return _possibleConstructorReturn(this, (ReferenceDefinition.__proto__ || Object.getPrototypeOf(ReferenceDefinition)).call(this, options, attribute, _extends({
function ReferenceDefinition(options /*: Options*/, attribute /*: string*/, config /*: Object*/) {
(0, _classCallCheck3.default)(this, ReferenceDefinition);
return (0, _possibleConstructorReturn3.default)(this, (ReferenceDefinition.__proto__ || (0, _getPrototypeOf2.default)(ReferenceDefinition)).call(this, options, attribute, (0, _extends3.default)({
reference: '',

@@ -53,12 +70,12 @@ self: false,

_createClass(ReferenceDefinition, [{
(0, _createClass3.default)(ReferenceDefinition, [{
key: 'validateConfig',
value: function validateConfig() {
_get(ReferenceDefinition.prototype.__proto__ || Object.getPrototypeOf(ReferenceDefinition.prototype), 'validateConfig', this).call(this);
(0, _get3.default)(ReferenceDefinition.prototype.__proto__ || (0, _getPrototypeOf2.default)(ReferenceDefinition.prototype), 'validateConfig', this).call(this);
var _config = this.config;
var reference = _config.reference;
var self = _config.self;
var subset = _config.subset;
var doExport = _config.export;
var _config = this.config,
reference = _config.reference,
self = _config.self,
subset = _config.subset,
doExport = _config.export;

@@ -83,3 +100,2 @@

}]);
return ReferenceDefinition;

@@ -86,0 +102,0 @@ }(_Definition3.default);

@@ -7,6 +7,30 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _keys = require('babel-runtime/core-js/object/keys');
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _keys2 = _interopRequireDefault(_keys);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -26,22 +50,17 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type { ShapeConfig } from '../types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var ShapeDefinition = function (_Definition) {
_inherits(ShapeDefinition, _Definition);
(0, _inherits3.default)(ShapeDefinition, _Definition);
function ShapeDefinition() {
_classCallCheck(this, ShapeDefinition);
return _possibleConstructorReturn(this, (ShapeDefinition.__proto__ || Object.getPrototypeOf(ShapeDefinition)).apply(this, arguments));
(0, _classCallCheck3.default)(this, ShapeDefinition);
return (0, _possibleConstructorReturn3.default)(this, (ShapeDefinition.__proto__ || (0, _getPrototypeOf2.default)(ShapeDefinition)).apply(this, arguments));
}
_createClass(ShapeDefinition, [{
(0, _createClass3.default)(ShapeDefinition, [{
key: 'validateConfig',

@@ -56,17 +75,26 @@

_get(ShapeDefinition.prototype.__proto__ || Object.getPrototypeOf(ShapeDefinition.prototype), 'validateConfig', this).call(this);
(0, _get3.default)(ShapeDefinition.prototype.__proto__ || (0, _getPrototypeOf2.default)(ShapeDefinition.prototype), 'validateConfig', this).call(this);
var attributes = this.config.attributes;
var _config = this.config,
attributes = _config.attributes,
reference = _config.reference;
if (!(0, _isObject2.default)(attributes) || !Object.keys(attributes).length) {
throw new SyntaxError('Shape definitions require an "attributes" property, ' + 'which is an object mapping of attributes to type definitions.');
if (reference) {
if (typeof reference !== 'string') {
throw new TypeError('Shape reference must be a string.');
}
} else if (attributes) {
if (!(0, _isObject2.default)(attributes) || !(0, _keys2.default)(attributes).length) {
throw new TypeError('Shape attributes must be a mapping of type definitions.');
}
this.attributes = (0, _keys2.default)(attributes).map(function (attribute) {
return _Factory2.default.definition(_this2.options, attribute, attributes[attribute]);
});
} else {
throw new SyntaxError('Shape definitions require an "attributes" or "reference" property.');
}
this.attributes = Object.keys(attributes).map(function (attribute) {
return _Factory2.default.definition(_this2.options, attribute, attributes[attribute]);
});
}
}]);
return ShapeDefinition;

@@ -73,0 +101,0 @@ }(_Definition3.default);

@@ -7,2 +7,18 @@ 'use strict';

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -14,19 +30,14 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type { StringConfig } from '../types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var StringDefinition = function (_Definition) {
_inherits(StringDefinition, _Definition);
(0, _inherits3.default)(StringDefinition, _Definition);
function StringDefinition() {
_classCallCheck(this, StringDefinition);
return _possibleConstructorReturn(this, (StringDefinition.__proto__ || Object.getPrototypeOf(StringDefinition)).apply(this, arguments));
(0, _classCallCheck3.default)(this, StringDefinition);
return (0, _possibleConstructorReturn3.default)(this, (StringDefinition.__proto__ || (0, _getPrototypeOf2.default)(StringDefinition)).apply(this, arguments));
}

@@ -33,0 +44,0 @@

@@ -7,6 +7,26 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Definition2 = require('../Definition');

@@ -22,22 +42,19 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
/*:: import type { UnionConfig } from '../types';*/
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var UnionDefinition = function (_Definition) {
_inherits(UnionDefinition, _Definition);
(0, _inherits3.default)(UnionDefinition, _Definition);
function UnionDefinition() {
_classCallCheck(this, UnionDefinition);
return _possibleConstructorReturn(this, (UnionDefinition.__proto__ || Object.getPrototypeOf(UnionDefinition)).apply(this, arguments));
(0, _classCallCheck3.default)(this, UnionDefinition);
return (0, _possibleConstructorReturn3.default)(this, (UnionDefinition.__proto__ || (0, _getPrototypeOf2.default)(UnionDefinition)).apply(this, arguments));
}
_createClass(UnionDefinition, [{
(0, _createClass3.default)(UnionDefinition, [{
key: 'validateConfig',

@@ -52,3 +69,3 @@

_get(UnionDefinition.prototype.__proto__ || Object.getPrototypeOf(UnionDefinition.prototype), 'validateConfig', this).call(this);
(0, _get3.default)(UnionDefinition.prototype.__proto__ || (0, _getPrototypeOf2.default)(UnionDefinition.prototype), 'validateConfig', this).call(this);

@@ -67,3 +84,2 @@ var valueTypes = this.config.valueTypes;

}]);
return UnionDefinition;

@@ -70,0 +86,0 @@ }(_Definition3.default);

@@ -7,8 +7,10 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _SchemaReader = require('./SchemaReader');

@@ -92,10 +94,14 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type { Options, BaseConfig } from './types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
var Factory = function () {
function Factory() {
_classCallCheck(this, Factory);
(0, _classCallCheck3.default)(this, Factory);
}
_createClass(Factory, null, [{
(0, _createClass3.default)(Factory, null, [{
key: 'definition',

@@ -111,7 +117,7 @@

*/
value: function definition(options, attribute, config) {
value: function definition(options /*: Options*/, attribute /*: string*/, config /*: string | BaseConfig*/) /*: Definition*/ {
// Convert primitives to configuration objects
if (typeof config === 'string') {
if ((0, _isPrimitive2.default)((0, _normalizeType2.default)(config))) {
config = { type: config };
config = ({ type: config } /*: BaseConfig*/);
} else {

@@ -179,3 +185,3 @@ throw new TypeError('Invalid primitive type "' + config + '".');

key: 'renderer',
value: function renderer(options, reader) {
value: function renderer(options /*: Options*/, reader /*: SchemaReader*/) /*: Renderer*/ {
var renderer = options.renderer;

@@ -199,3 +205,2 @@

}]);
return Factory;

@@ -202,0 +207,0 @@ }();

@@ -10,3 +10,3 @@ 'use strict';

* @license https://opensource.org/licenses/MIT
*
* @flow
*/

@@ -20,3 +20,3 @@

*/
function formatName(value) {
function formatName(value /*: string*/) /*: string*/ {
if (!value) {

@@ -23,0 +23,0 @@ return '';

@@ -10,3 +10,3 @@ 'use strict';

* @license https://opensource.org/licenses/MIT
*
* @flow
*/

@@ -21,4 +21,4 @@

*/
function indent(depth) {
var character = arguments.length <= 1 || arguments[1] === undefined ? ' ' : arguments[1];
function indent(depth /*: number*/) /*: string*/ {
var character /*: string*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' ';

@@ -25,0 +25,0 @@ var response = '';

@@ -7,9 +7,14 @@ '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 ? "symbol" : typeof obj; };
var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
exports.default = isObject;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
* @flow
*/

@@ -23,4 +28,4 @@

*/
function isObject(value) {
return (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null && !Array.isArray(value);
function isObject(value /*: mixed*/) /*: boolean*/ {
return (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value)) === 'object' && value !== null && !Array.isArray(value);
}

@@ -25,7 +25,7 @@ 'use strict';

* @license https://opensource.org/licenses/MIT
*
* @flow
*/
function isPrimitive(value) {
function isPrimitive(value /*: string*/) /*: boolean*/ {
return _constants.PRIMITIVE_TYPES.indexOf((0, _normalizeType2.default)(value)) >= 0;
}

@@ -10,3 +10,3 @@ 'use strict';

* @license https://opensource.org/licenses/MIT
*
* @flow
*/

@@ -39,3 +39,3 @@

*/
function normalizeType(type) {
function normalizeType(type /*: mixed*/) /*: string*/ {
type = String(type).toLowerCase();

@@ -42,0 +42,0 @@

@@ -7,12 +7,26 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _Factory = require('./Factory');

@@ -92,9 +106,21 @@

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type {
Options,
BaseConfig,
ReferenceConfig,
PrimitiveType,
MetadataField,
ImportStructure,
} from './types';*/
/*:: type TemplateList = string[];*/
var Renderer = function () {
function Renderer(options, reader) {
_classCallCheck(this, Renderer);
function Renderer(options /*: Options*/, reader /*: SchemaReader*/) {
(0, _classCallCheck3.default)(this, Renderer);

@@ -118,3 +144,3 @@ this.options = options;

_createClass(Renderer, [{
(0, _createClass3.default)(Renderer, [{
key: 'afterParse',

@@ -143,5 +169,5 @@ value: function afterParse() {}

key: 'formatArray',
value: function formatArray(items, depth) {
var itemSpacer = arguments.length <= 2 || arguments[2] === undefined ? '\n' : arguments[2];
var indentSpacer = arguments.length <= 3 || arguments[3] === undefined ? '\n' : arguments[3];
value: function formatArray(items /*: string | string[]*/, depth /*: number*/) /*: string*/ {
var itemSpacer /*: string*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '\n';
var indentSpacer /*: string*/ = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '\n';

@@ -167,5 +193,5 @@ if (Array.isArray(items)) {

key: 'formatObject',
value: function formatObject(props, depth) {
var propSpacer = arguments.length <= 2 || arguments[2] === undefined ? '\n' : arguments[2];
var indentSpacer = arguments.length <= 3 || arguments[3] === undefined ? '\n' : arguments[3];
value: function formatObject(props /*: string | string[]*/, depth /*: number*/) /*: string*/ {
var propSpacer /*: string*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '\n';
var indentSpacer /*: string*/ = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '\n';

@@ -189,4 +215,4 @@ if (Array.isArray(props)) {

key: 'formatValue',
value: function formatValue(value) {
var type = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
value: function formatValue(value /*: PrimitiveType*/) /*: string*/ {
var type /*: string*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

@@ -197,11 +223,11 @@ if (value === null) {

type = (0, _normalizeType2.default)(type || (typeof value === 'undefined' ? 'undefined' : _typeof(value)));
type = (0, _normalizeType2.default)(type || (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value)));
switch (type) {
case 'string':
return '\'' + value + '\'';
return '\'' + String(value) + '\'';
case 'function':
case 'boolean':
return '' + value;
return '' + String(value);

@@ -224,3 +250,3 @@ case 'number':

key: 'getConstants',
value: function getConstants() {
value: function getConstants() /*: TemplateList*/ {
return this.constants;

@@ -237,3 +263,3 @@ }

key: 'getHeader',
value: function getHeader() {
value: function getHeader() /*: TemplateList*/ {
return this.header;

@@ -250,3 +276,3 @@ }

key: 'getImports',
value: function getImports() {
value: function getImports() /*: TemplateList*/ {
return this.imports;

@@ -263,3 +289,3 @@ }

key: 'getReferences',
value: function getReferences() {
value: function getReferences() /*: TemplateList*/ {
return this.referencePaths;

@@ -277,3 +303,3 @@ }

key: 'getObjectName',
value: function getObjectName() {
value: function getObjectName() /*: string*/ {
for (var _len = arguments.length, names = Array(_len), _key = 0; _key < _len; _key++) {

@@ -294,3 +320,3 @@ names[_key] = arguments[_key];

key: 'getRelations',
value: function getRelations() {
value: function getRelations() /*: TemplateList*/ {
return this.relations;

@@ -307,3 +333,3 @@ }

key: 'getSchemas',
value: function getSchemas() {
value: function getSchemas() /*: TemplateList*/ {
return this.schemas;

@@ -320,3 +346,3 @@ }

key: 'getSets',
value: function getSets() {
value: function getSets() /*: TemplateList*/ {
return this.sets;

@@ -333,7 +359,8 @@ }

this.beforeParse();
this.parseReferences();
this.parseReferences(); // Must be first
this.parseShapes();
this.parseImports();
this.parseConstants();
this.parseSchemas();
this.parseSets();
this.parseSets(); // Must be last
this.afterParse();

@@ -354,3 +381,3 @@ }

Object.keys(constants).forEach(function (key) {
(0, _keys2.default)(constants).forEach(function (key /*: string*/) {
_this.constants.push(_this.renderConstant(key, constants[key]));

@@ -369,3 +396,3 @@ });

this.reader.imports.forEach(function (statement) {
this.reader.imports.forEach(function (statement /*: ImportStructure*/) {
_this2.imports.push(_this2.renderImport(statement));

@@ -384,3 +411,3 @@ });

Object.keys(this.reader.references).forEach(function (key) {
(0, _keys2.default)(this.reader.references).forEach(function (key /*: string*/) {
_this3.referencePaths.push(_this3.reader.references[key]);

@@ -401,6 +428,6 @@ });

var _reader = this.reader;
var attributes = _reader.attributes;
var name = _reader.name;
var metadata = _reader.metadata;
var _reader = this.reader,
attributes = _reader.attributes,
name = _reader.name,
metadata = _reader.metadata;

@@ -430,10 +457,10 @@

var baseAttributes = this.reader.data.attributes;
var _reader2 = this.reader;
var attributes = _reader2.attributes;
var subsets = _reader2.subsets;
var name = _reader2.name;
var _reader2 = this.reader,
attributes = _reader2.attributes,
subsets = _reader2.subsets,
name = _reader2.name;
// Subsets
Object.keys(subsets).forEach(function (setName) {
(0, _keys2.default)(subsets).forEach(function (setName /*: string*/) {
var setAttributes = [];

@@ -449,3 +476,3 @@ var subset = subsets[setName];

subset.attributes.forEach(function (attribute) {
subset.attributes.forEach(function (attribute /*: string*/) {
var setConfig = baseAttributes[attribute];

@@ -458,5 +485,5 @@

if (typeof setConfig === 'string') {
setConfig = { type: setConfig };
setConfig = ({ type: setConfig } /*: BaseConfig*/);
} else {
setConfig = _extends({}, setConfig); // Dereference original object
setConfig = ((0, _extends3.default)({}, setConfig) /*: BaseConfig*/); // Dereference original object
}

@@ -483,2 +510,25 @@

/**
* Render re-usable shapes.
*/
}, {
key: 'parseShapes',
value: function parseShapes() {
var _this5 = this;
var _reader3 = this.reader,
name = _reader3.name,
shapes = _reader3.shapes;
(0, _keys2.default)(shapes).forEach(function (key /*: string*/) {
var attributes = (0, _keys2.default)(shapes[key]).map(function (attribute) {
return _Factory2.default.definition(_this5.options, attribute, shapes[key][attribute]);
});
_this5.sets.push(_this5.render(_this5.getObjectName(name, key, _this5.suffix), attributes));
});
}
/**
* Render the current schema into a formatted output.

@@ -489,4 +539,4 @@ */

key: 'render',
value: function render(setName) {
var attributes = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
value: function render(setName /*: string*/) /*: string*/ {
var attributes /*: Definition[]*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];

@@ -506,4 +556,4 @@ throw new Error('Renderer not implemented.');

key: 'renderAttribute',
value: function renderAttribute(definition) {
var depth = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
value: function renderAttribute(definition /*: Definition*/) /*: string*/ {
var depth /*: number*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;

@@ -543,3 +593,3 @@ if (definition instanceof _Array2.default) {

key: 'renderArray',
value: function renderArray(definition, depth) {
value: function renderArray(definition /*: ArrayDefinition*/, depth /*: number*/) /*: string*/ {
return this.unsupported('array');

@@ -549,3 +599,3 @@ }

/**
* Render an array of items by formatting each value and prepending an indentation.
* Render an array of values by formatting each value and prepending an indentation.
*

@@ -560,10 +610,10 @@ * @param {*[]} items

key: 'renderArrayItems',
value: function renderArrayItems(items) {
var _this5 = this;
value: function renderArrayItems(items /*: PrimitiveType[]*/) /*: string[]*/ {
var _this6 = this;
var depth = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
var valueType = arguments.length <= 2 || arguments[2] === undefined ? '' : arguments[2];
var depth /*: number*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var valueType /*: string*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
return items.map(function (item) {
return _this5.wrapItem(_this5.renderOrFormat(item, depth, valueType), depth);
return _this6.wrapItem(_this6.formatValue(item, valueType), depth);
});

@@ -573,2 +623,22 @@ }

/**
* Render an array of definitions by formatting each value and prepending an indentation.
*
* @param {*[]} items
* @param {Number} depth
* @returns {Array}
*/
}, {
key: 'renderArrayDefinitions',
value: function renderArrayDefinitions(items /*: Definition[]*/) /*: string[]*/ {
var _this7 = this;
var depth /*: number*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
return items.map(function (item) {
return _this7.wrapItem(_this7.renderAttribute(item, depth), depth);
});
}
/**
* Render a boolean definition.

@@ -579,3 +649,3 @@ */

key: 'renderBool',
value: function renderBool(definition) {
value: function renderBool(definition /*: BoolDefinition*/) /*: string*/ {
return this.unsupported('boolean');

@@ -594,8 +664,8 @@ }

key: 'renderConstant',
value: function renderConstant(name, value) {
var _this6 = this;
value: function renderConstant(name /*: string*/, value /*: PrimitiveType | PrimitiveType[]*/) /*: string*/ {
var _this8 = this;
if (Array.isArray(value)) {
value = this.formatArray(value.map(function (v) {
return _this6.formatValue(v);
return _this8.formatValue(v);
}), 0, ', ', '');

@@ -615,3 +685,3 @@ } else {

key: 'renderEnum',
value: function renderEnum(definition, depth) {
value: function renderEnum(definition /*: EnumDefinition*/, depth /*: number*/) /*: string*/ {
return this.unsupported('enum');

@@ -626,3 +696,3 @@ }

key: 'renderFunc',
value: function renderFunc(definition, depth) {
value: function renderFunc(definition /*: FuncDefinition*/, depth /*: number*/) /*: string*/ {
return this.unsupported('function');

@@ -640,7 +710,7 @@ }

key: 'renderImport',
value: function renderImport(statement) {
var defaultName = statement.default;
var _statement$named = statement.named;
var named = _statement$named === undefined ? [] : _statement$named;
var path = statement.path;
value: function renderImport(statement /*: ImportStructure*/) /*: string*/ {
var defaultName = statement.default,
_statement$named = statement.named,
named = _statement$named === undefined ? [] : _statement$named,
path = statement.path;

@@ -677,3 +747,3 @@

key: 'renderInstance',
value: function renderInstance(definition) {
value: function renderInstance(definition /*: InstanceDefinition*/) /*: string*/ {
return this.unsupported('instance');

@@ -688,3 +758,3 @@ }

key: 'renderNumber',
value: function renderNumber(definition) {
value: function renderNumber(definition /*: NumberDefinition*/) /*: string*/ {
return this.unsupported('number');

@@ -699,3 +769,3 @@ }

key: 'renderObject',
value: function renderObject(definition, depth) {
value: function renderObject(definition /*: ObjectDefinition*/, depth /*: number*/) /*: string*/ {
return this.unsupported('object');

@@ -715,10 +785,10 @@ }

key: 'renderObjectProps',
value: function renderObjectProps(props) {
var _this7 = this;
value: function renderObjectProps(props /*: Definition[]*/) /*: string[]*/ {
var _this9 = this;
var depth = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
var sep = arguments.length <= 2 || arguments[2] === undefined ? ',' : arguments[2];
var depth /*: number*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var sep /*: string*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ',';
return props.map(function (prop) {
return _this7.wrapProperty(_this7.wrapPropertyName(prop), _this7.renderAttribute(prop, depth), depth, sep);
return _this9.wrapProperty(_this9.wrapPropertyName(prop), _this9.renderAttribute(prop, depth), depth, sep);
});

@@ -738,4 +808,4 @@ }

key: 'renderOrFormat',
value: function renderOrFormat(value, depth) {
var valueType = arguments.length <= 2 || arguments[2] === undefined ? '' : arguments[2];
value: function renderOrFormat(value /*: PrimitiveType | Definition*/, depth /*: number*/) /*: string*/ {
var valueType /*: string*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';

@@ -754,8 +824,8 @@ return value instanceof _Definition2.default ? this.renderAttribute(value, depth) : this.formatValue(value, valueType);

key: 'renderReference',
value: function renderReference(definition) {
var _definition$config = definition.config;
var reference = _definition$config.reference;
var self = _definition$config.self;
var _definition$config$su = _definition$config.subset;
var subset = _definition$config$su === undefined ? '' : _definition$config$su;
value: function renderReference(definition /*: ReferenceDefinition*/) /*: string*/ {
var _definition$config = definition.config,
reference = _definition$config.reference,
self = _definition$config.self,
_definition$config$su = _definition$config.subset,
subset = _definition$config$su === undefined ? '' : _definition$config$su;

@@ -786,10 +856,10 @@ var refReader = self ? this.reader : this.reader.referenceReaders[reference];

key: 'renderSchema',
value: function renderSchema(name) {
value: function renderSchema(name /*: string*/) /*: string*/ {
var _relations,
_this8 = this;
_this10 = this;
var attributes = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
var metadata = arguments[2];
var primaryKey = metadata.primaryKey;
var resourceName = metadata.resourceName;
var attributes /*: Definition[]*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var metadata /*: MetadataField*/ = arguments[2];
var primaryKey = metadata.primaryKey,
resourceName = metadata.resourceName;
var includeAttributes = this.options.includeAttributes;

@@ -799,3 +869,3 @@

var fields = [];
var relations = (_relations = {}, _defineProperty(_relations, _Schema2.default.HAS_ONE, []), _defineProperty(_relations, _Schema2.default.HAS_MANY, []), _defineProperty(_relations, _Schema2.default.BELONGS_TO, []), _defineProperty(_relations, _Schema2.default.BELONGS_TO_MANY, []), _relations);
var relations /*: { [key: string]: string[] }*/ = (_relations = {}, (0, _defineProperty3.default)(_relations, _Schema2.default.HAS_ONE, []), (0, _defineProperty3.default)(_relations, _Schema2.default.HAS_MANY, []), (0, _defineProperty3.default)(_relations, _Schema2.default.BELONGS_TO, []), (0, _defineProperty3.default)(_relations, _Schema2.default.BELONGS_TO_MANY, []), _relations);

@@ -806,10 +876,10 @@ if (!resourceName || typeof resourceName !== 'string') {

var relationDefinition = null;
var relationType = '';
var relationDefinition /*: ?ReferenceDefinition*/ = null;
var relationType /*: string*/ = '';
attributes.forEach(function (definition) {
attributes.forEach(function (definition /*: Definition*/) {
relationDefinition = null;
if (includeAttributes) {
fields.push(_this8.wrapItem(_this8.formatValue(definition.attribute, 'string'), 1));
fields.push(_this10.wrapItem(_this10.formatValue(definition.attribute, 'string'), 1));
}

@@ -835,3 +905,3 @@

var relationConfig = relationDefinition.config;
var relationConfig /*: ReferenceConfig*/ = relationDefinition.config;

@@ -842,5 +912,5 @@ if (!relationConfig.export) {

var relationName = relationConfig.self ? _this8.reader.name : references[relationConfig.reference].name;
var relationName = relationConfig.self ? _this10.reader.name : references[relationConfig.reference].name;
relations[relationConfig.relation || relationType].push(_this8.wrapProperty(relationDefinition.attribute, _this8.getObjectName(relationName, 'Schema'), 1));
relations[relationConfig.relation || relationType].push(_this10.wrapProperty(relationDefinition.attribute, _this10.getObjectName(relationName, 'Schema'), 1));
}

@@ -864,5 +934,5 @@ });

Object.keys(relations).forEach(function (relation) {
(0, _keys2.default)(relations).forEach(function (relation /*: string*/) {
if (relations[relation].length) {
relationTemplate += '.' + relation + '(' + _this8.formatObject(relations[relation], 0) + ')';
relationTemplate += '.' + relation + '(' + _this10.formatObject(relations[relation], 0) + ')';
}

@@ -884,3 +954,3 @@ });

key: 'renderShape',
value: function renderShape(definition, depth) {
value: function renderShape(definition /*: ShapeDefinition*/, depth /*: number*/) /*: string*/ {
return this.unsupported('shape');

@@ -890,2 +960,22 @@ }

/**
* Render a shape reference definition.
*
* @param {Definition} definition
* @returns {String}
*/
}, {
key: 'renderShapeReference',
value: function renderShapeReference(definition /*: ShapeDefinition*/) /*: string*/ {
var reference = definition.config.reference;
if (!reference) {
return '';
}
return this.getObjectName(this.reader.name, reference, this.suffix);
}
/**
* Render a string definition.

@@ -896,3 +986,3 @@ */

key: 'renderString',
value: function renderString(definition) {
value: function renderString(definition /*: StringDefinition*/) /*: string*/ {
return this.unsupported('string');

@@ -907,3 +997,3 @@ }

key: 'renderUnion',
value: function renderUnion(definition, depth) {
value: function renderUnion(definition /*: UnionDefinition*/, depth /*: number*/) /*: string*/ {
return this.unsupported('union');

@@ -920,3 +1010,3 @@ }

key: 'unsupported',
value: function unsupported(definition) {
value: function unsupported(definition /*: string*/) /*: string*/ {
throw new Error('The "' + definition + '" definition is not supported by ' + this.constructor.name + '.');

@@ -935,4 +1025,4 @@ }

key: 'wrapFunction',
value: function wrapFunction(name) {
var args = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];
value: function wrapFunction(name /*: string*/) /*: string*/ {
var args /*: string*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

@@ -952,3 +1042,3 @@ return name + '(' + args + ')';

key: 'wrapGenerics',
value: function wrapGenerics(alias) {
value: function wrapGenerics(alias /*: string*/) /*: string*/ {
for (var _len2 = arguments.length, types = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {

@@ -970,3 +1060,3 @@ types[_key2 - 1] = arguments[_key2];

key: 'wrapIIFE',
value: function wrapIIFE(code) {
value: function wrapIIFE(code /*: string*/) /*: string*/ {
return '(function () { return ' + code + '; }())';

@@ -985,4 +1075,4 @@ }

key: 'wrapItem',
value: function wrapItem(value) {
var depth = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1];
value: function wrapItem(value /*: string*/) /*: string*/ {
var depth /*: number*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;

@@ -1004,5 +1094,5 @@ return '' + (0, _indent2.default)(depth, this.options.indentCharacter) + value + ',';

key: 'wrapProperty',
value: function wrapProperty(key, value) {
var depth = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
var sep = arguments.length <= 3 || arguments[3] === undefined ? ',' : arguments[3];
value: function wrapProperty(key /*: string*/, value /*: string*/) /*: string*/ {
var depth /*: number*/ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var sep /*: string*/ = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ',';

@@ -1021,7 +1111,6 @@ return '' + (0, _indent2.default)(depth, this.options.indentCharacter) + key + ': ' + value + (sep || ',');

key: 'wrapPropertyName',
value: function wrapPropertyName(definition) {
value: function wrapPropertyName(definition /*: Definition*/) /*: string*/ {
return definition.attribute;
}
}]);
return Renderer;

@@ -1028,0 +1117,0 @@ }();

@@ -7,6 +7,26 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Renderer2 = require('../Renderer');

@@ -74,19 +94,15 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*:: import type { Options } from '../types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var FlowRenderer = function (_Renderer) {
_inherits(FlowRenderer, _Renderer);
(0, _inherits3.default)(FlowRenderer, _Renderer);
function FlowRenderer(options, reader) {
_classCallCheck(this, FlowRenderer);
function FlowRenderer(options /*: Options*/, reader /*: SchemaReader*/) {
(0, _classCallCheck3.default)(this, FlowRenderer);
var _this = _possibleConstructorReturn(this, (FlowRenderer.__proto__ || Object.getPrototypeOf(FlowRenderer)).call(this, options, reader));
var _this = (0, _possibleConstructorReturn3.default)(this, (FlowRenderer.__proto__ || (0, _getPrototypeOf2.default)(FlowRenderer)).call(this, options, reader));

@@ -102,3 +118,3 @@ _this.suffix = 'Type';

_createClass(FlowRenderer, [{
(0, _createClass3.default)(FlowRenderer, [{
key: 'afterParse',

@@ -115,4 +131,4 @@ value: function afterParse() {

key: 'render',
value: function render(setName) {
var attributes = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
value: function render(setName /*: string*/) {
var attributes /*: Definition[]*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];

@@ -130,3 +146,3 @@ var shape = this.formatObject(this.renderObjectProps(attributes, 1), 0);

key: 'renderArray',
value: function renderArray(definition, depth) {
value: function renderArray(definition /*: ArrayDefinition*/, depth /*: number*/) /*: string*/ {
var configType = definition.valueType.config.type;

@@ -150,3 +166,3 @@ var template = this.renderAttribute(definition.valueType, depth);

key: 'renderBool',
value: function renderBool(definition) {
value: function renderBool(definition /*: BoolDefinition*/) /*: string*/ {
return this.wrapNullable(definition, 'boolean');

@@ -161,8 +177,8 @@ }

key: 'renderEnum',
value: function renderEnum(definition, depth) {
value: function renderEnum(definition /*: EnumDefinition*/, depth /*: number*/) /*: string*/ {
var _this2 = this;
var _definition$config = definition.config;
var values = _definition$config.values;
var valueType = _definition$config.valueType;
var _definition$config = definition.config,
values = _definition$config.values,
valueType = _definition$config.valueType;

@@ -181,3 +197,3 @@

key: 'renderFunc',
value: function renderFunc(definition, depth) {
value: function renderFunc(definition /*: FuncDefinition*/, depth /*: number*/) /*: string*/ {
var returnType = definition.returnType ? this.renderAttribute(definition.returnType, depth + 1) : 'void';

@@ -198,3 +214,3 @@

key: 'renderInstance',
value: function renderInstance(definition) {
value: function renderInstance(definition /*: InstanceDefinition*/) /*: string*/ {
return this.wrapNullable(definition, this.formatValue(definition.config.contract, 'function'));

@@ -209,3 +225,3 @@ }

key: 'renderNumber',
value: function renderNumber(definition) {
value: function renderNumber(definition /*: NumberDefinition*/) /*: string*/ {
return this.wrapNullable(definition, 'number');

@@ -220,3 +236,3 @@ }

key: 'renderObject',
value: function renderObject(definition, depth) {
value: function renderObject(definition /*: ObjectDefinition*/, depth /*: number*/) /*: string*/ {
var key = this.renderAttribute(definition.keyType, depth);

@@ -234,4 +250,4 @@ var value = this.renderAttribute(definition.valueType, depth);

key: 'renderReference',
value: function renderReference(definition) {
return this.wrapNullable(definition, _get(FlowRenderer.prototype.__proto__ || Object.getPrototypeOf(FlowRenderer.prototype), 'renderReference', this).call(this, definition));
value: function renderReference(definition /*: ReferenceDefinition*/) /*: string*/ {
return this.wrapNullable(definition, (0, _get3.default)(FlowRenderer.prototype.__proto__ || (0, _getPrototypeOf2.default)(FlowRenderer.prototype), 'renderReference', this).call(this, definition));
}

@@ -245,4 +261,4 @@

key: 'renderShape',
value: function renderShape(definition, depth) {
return this.wrapNullable(definition, this.formatObject(this.renderObjectProps(definition.attributes, depth + 1), depth));
value: function renderShape(definition /*: ShapeDefinition*/, depth /*: number*/) /*: string*/ {
return this.wrapNullable(definition, this.renderShapeReference(definition) || this.formatObject(this.renderObjectProps(definition.attributes, depth + 1), depth));
}

@@ -256,3 +272,3 @@

key: 'renderString',
value: function renderString(definition) {
value: function renderString(definition /*: StringDefinition*/) /*: string*/ {
return this.wrapNullable(definition, 'string');

@@ -267,3 +283,3 @@ }

key: 'renderUnion',
value: function renderUnion(definition, depth) {
value: function renderUnion(definition /*: UnionDefinition*/, depth /*: number*/) /*: string*/ {
var _this3 = this;

@@ -286,3 +302,3 @@

key: 'wrapNullable',
value: function wrapNullable(definition, template) {
value: function wrapNullable(definition /*: Definition*/, template /*: string*/) /*: string*/ {
if (definition.isNullable && definition.isNullable()) {

@@ -295,3 +311,2 @@ return '?' + template;

}]);
return FlowRenderer;

@@ -298,0 +313,0 @@ }(_Renderer3.default);

@@ -7,6 +7,26 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _get2 = require('babel-runtime/helpers/get');
var _get3 = _interopRequireDefault(_get2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Renderer2 = require('../Renderer');

@@ -70,19 +90,17 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
/*:: import type { Options } from '../types';*/
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var ReactRenderer = function (_Renderer) {
_inherits(ReactRenderer, _Renderer);
(0, _inherits3.default)(ReactRenderer, _Renderer);
function ReactRenderer(options, reader) {
_classCallCheck(this, ReactRenderer);
function ReactRenderer(options /*: Options*/, reader /*: SchemaReader*/) {
(0, _classCallCheck3.default)(this, ReactRenderer);
var _this = _possibleConstructorReturn(this, (ReactRenderer.__proto__ || Object.getPrototypeOf(ReactRenderer)).call(this, options, reader));
var _this = (0, _possibleConstructorReturn3.default)(this, (ReactRenderer.__proto__ || (0, _getPrototypeOf2.default)(ReactRenderer)).call(this, options, reader));

@@ -98,3 +116,3 @@ _this.suffix = 'Shape';

_createClass(ReactRenderer, [{
(0, _createClass3.default)(ReactRenderer, [{
key: 'beforeParse',

@@ -111,4 +129,4 @@ value: function beforeParse() {

key: 'render',
value: function render(setName) {
var attributes = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
value: function render(setName /*: string*/) {
var attributes /*: Definition[]*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];

@@ -126,3 +144,3 @@ var shape = this.formatObject(this.renderObjectProps(attributes, 1), 0);

key: 'renderArray',
value: function renderArray(definition, depth) {
value: function renderArray(definition /*: ArrayDefinition*/, depth /*: number*/) /*: string*/ {
return this.wrapPropType(definition, this.wrapFunction('arrayOf', this.renderAttribute(definition.valueType, depth)));

@@ -137,3 +155,3 @@ }

key: 'renderBool',
value: function renderBool(definition) {
value: function renderBool(definition /*: BoolDefinition*/) /*: string*/ {
return this.wrapPropType(definition, 'bool');

@@ -148,6 +166,6 @@ }

key: 'renderEnum',
value: function renderEnum(definition, depth) {
var _definition$config = definition.config;
var values = _definition$config.values;
var valueType = _definition$config.valueType;
value: function renderEnum(definition /*: EnumDefinition*/, depth /*: number*/) /*: string*/ {
var _definition$config = definition.config,
values = _definition$config.values,
valueType = _definition$config.valueType;

@@ -164,3 +182,3 @@

key: 'renderFunc',
value: function renderFunc(definition, depth) {
value: function renderFunc(definition /*: FuncDefinition*/, depth /*: number*/) /*: string*/ {
return this.wrapPropType(definition, 'func');

@@ -175,3 +193,3 @@ }

key: 'renderInstance',
value: function renderInstance(definition) {
value: function renderInstance(definition /*: InstanceDefinition*/) /*: string*/ {
var contract = definition.config.contract;

@@ -189,3 +207,3 @@

key: 'renderNumber',
value: function renderNumber(definition) {
value: function renderNumber(definition /*: NumberDefinition*/) /*: string*/ {
return this.wrapPropType(definition, 'number');

@@ -200,3 +218,3 @@ }

key: 'renderObject',
value: function renderObject(definition, depth) {
value: function renderObject(definition /*: ObjectDefinition*/, depth /*: number*/) /*: string*/ {
return this.wrapPropType(definition, this.wrapFunction('objectOf', this.renderAttribute(definition.valueType, depth)));

@@ -211,8 +229,8 @@ }

key: 'renderReference',
value: function renderReference(definition) {
var _definition$config2 = definition.config;
var self = _definition$config2.self;
var subset = _definition$config2.subset;
value: function renderReference(definition /*: ReferenceDefinition*/) /*: string*/ {
var _definition$config2 = definition.config,
self = _definition$config2.self,
subset = _definition$config2.subset;
var reference = _get(ReactRenderer.prototype.__proto__ || Object.getPrototypeOf(ReactRenderer.prototype), 'renderReference', this).call(this, definition);
var reference = (0, _get3.default)(ReactRenderer.prototype.__proto__ || (0, _getPrototypeOf2.default)(ReactRenderer.prototype), 'renderReference', this).call(this, definition);

@@ -233,3 +251,9 @@ // Wrap a function as we need to defer the variable reference

key: 'renderShape',
value: function renderShape(definition, depth) {
value: function renderShape(definition /*: ShapeDefinition*/, depth /*: number*/) /*: string*/ {
var reference = this.renderShapeReference(definition);
if (reference) {
return this.wrapRequired(definition, reference);
}
return this.wrapPropType(definition, this.wrapFunction('shape', this.formatObject(this.renderObjectProps(definition.attributes, depth + 1), depth)));

@@ -244,3 +268,3 @@ }

key: 'renderString',
value: function renderString(definition) {
value: function renderString(definition /*: StringDefinition*/) /*: string*/ {
return this.wrapPropType(definition, 'string');

@@ -255,4 +279,4 @@ }

key: 'renderUnion',
value: function renderUnion(definition, depth) {
return this.wrapPropType(definition, this.wrapFunction('oneOfType', this.formatArray(this.renderArrayItems(definition.valueTypes, depth + 1), depth)));
value: function renderUnion(definition /*: UnionDefinition*/, depth /*: number*/) /*: string*/ {
return this.wrapPropType(definition, this.wrapFunction('oneOfType', this.formatArray(this.renderArrayDefinitions(definition.valueTypes, depth + 1), depth)));
}

@@ -270,3 +294,3 @@

key: 'wrapPropType',
value: function wrapPropType(definition, template) {
value: function wrapPropType(definition /*: Definition*/, template /*: string*/) /*: string*/ {
return this.wrapRequired(definition, 'PropTypes.' + template);

@@ -285,3 +309,3 @@ }

key: 'wrapRequired',
value: function wrapRequired(definition, template) {
value: function wrapRequired(definition /*: Definition*/, template /*: string*/) /*: string*/ {
if (definition.isRequired && definition.isRequired()) {

@@ -294,3 +318,2 @@ return template + '.isRequired';

}]);
return ReactRenderer;

@@ -297,0 +320,0 @@ }(_Renderer3.default);

@@ -7,4 +7,26 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _fromCodePoint = require('babel-runtime/core-js/string/from-code-point');
var _fromCodePoint2 = _interopRequireDefault(_fromCodePoint);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Renderer2 = require('../Renderer');

@@ -76,19 +98,17 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
/*:: import type { Options, PrimitiveType } from '../types';*/
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var TypeScriptRenderer = function (_Renderer) {
_inherits(TypeScriptRenderer, _Renderer);
(0, _inherits3.default)(TypeScriptRenderer, _Renderer);
function TypeScriptRenderer(options, reader) {
_classCallCheck(this, TypeScriptRenderer);
function TypeScriptRenderer(options /*: Options*/, reader /*: SchemaReader*/) {
(0, _classCallCheck3.default)(this, TypeScriptRenderer);
var _this = _possibleConstructorReturn(this, (TypeScriptRenderer.__proto__ || Object.getPrototypeOf(TypeScriptRenderer)).call(this, options, reader));
var _this = (0, _possibleConstructorReturn3.default)(this, (TypeScriptRenderer.__proto__ || (0, _getPrototypeOf2.default)(TypeScriptRenderer)).call(this, options, reader));

@@ -104,6 +124,6 @@ _this.suffix = 'Interface';

_createClass(TypeScriptRenderer, [{
(0, _createClass3.default)(TypeScriptRenderer, [{
key: 'render',
value: function render(setName) {
var attributes = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
value: function render(setName /*: string*/) {
var attributes /*: Definition[]*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];

@@ -121,3 +141,3 @@ var shape = this.formatObject(this.renderObjectProps(attributes, 1, ';'), 0);

key: 'renderArray',
value: function renderArray(definition, depth) {
value: function renderArray(definition /*: ArrayDefinition*/, depth /*: number*/) /*: string*/ {
var configType = definition.valueType.config.type;

@@ -141,3 +161,3 @@ var template = this.renderAttribute(definition.valueType, depth);

key: 'renderBool',
value: function renderBool(definition) {
value: function renderBool(definition /*: BoolDefinition*/) /*: string*/ {
return 'boolean';

@@ -152,7 +172,7 @@ }

key: 'renderEnum',
value: function renderEnum(definition, depth) {
value: function renderEnum(definition /*: EnumDefinition*/, depth /*: number*/) /*: string*/ {
var char = this.options.indentCharacter;
var _definition$config = definition.config;
var values = _definition$config.values;
var valueType = _definition$config.valueType;
var _definition$config = definition.config,
values = _definition$config.values,
valueType = _definition$config.valueType;

@@ -169,3 +189,3 @@ var members = [];

case 'string':
values.forEach(function (value) {
values.forEach(function (value /*: PrimitiveType*/) {
members.push('' + (0, _indent2.default)(1, char) + String(value) + ' = ' + currentIndex);

@@ -180,4 +200,4 @@ currentIndex += 1;

case 'boolean':
values.forEach(function (value) {
members.push('' + (0, _indent2.default)(1, char) + String.fromCodePoint(currentChar) + ' = ' + Number(value));
values.forEach(function (value /*: PrimitiveType*/) {
members.push('' + (0, _indent2.default)(1, char) + (0, _fromCodePoint2.default)(currentChar) + ' = ' + Number(value));
currentChar += 1;

@@ -202,3 +222,3 @@ });

key: 'renderFunc',
value: function renderFunc(definition, depth) {
value: function renderFunc(definition /*: FuncDefinition*/, depth /*: number*/) /*: string*/ {
var returnType = definition.returnType ? this.renderAttribute(definition.returnType, depth + 1) : 'void';

@@ -219,3 +239,3 @@

key: 'renderInstance',
value: function renderInstance(definition) {
value: function renderInstance(definition /*: InstanceDefinition*/) /*: string*/ {
return this.formatValue(definition.config.contract, 'function');

@@ -230,3 +250,3 @@ }

key: 'renderNumber',
value: function renderNumber(definition) {
value: function renderNumber(definition /*: NumberDefinition*/) /*: string*/ {
return 'number';

@@ -241,3 +261,3 @@ }

key: 'renderObject',
value: function renderObject(definition, depth) {
value: function renderObject(definition /*: ObjectDefinition*/, depth /*: number*/) /*: string*/ {
var key = this.renderAttribute(definition.keyType, depth);

@@ -255,4 +275,4 @@ var value = this.renderAttribute(definition.valueType, depth);

key: 'renderShape',
value: function renderShape(definition, depth) {
return this.formatObject(this.renderObjectProps(definition.attributes, depth + 1, ';'), depth);
value: function renderShape(definition /*: ShapeDefinition*/, depth /*: number*/) /*: string*/ {
return this.renderShapeReference(definition) || this.formatObject(this.renderObjectProps(definition.attributes, depth + 1, ';'), depth);
}

@@ -266,3 +286,3 @@

key: 'renderString',
value: function renderString(definition) {
value: function renderString(definition /*: StringDefinition*/) /*: string*/ {
return 'string';

@@ -277,6 +297,6 @@ }

key: 'renderUnion',
value: function renderUnion(definition, depth) {
value: function renderUnion(definition /*: UnionDefinition*/, depth /*: number*/) /*: string*/ {
var _this2 = this;
return definition.valueTypes.map(function (item) {
return definition.valueTypes.map(function (item /*: Definition*/) {
var value = _this2.renderAttribute(item, depth);

@@ -298,3 +318,3 @@

key: 'wrapPropertyName',
value: function wrapPropertyName(definition) {
value: function wrapPropertyName(definition /*: Definition*/) /*: string*/ {
var template = definition.attribute;

@@ -309,3 +329,2 @@

}]);
return TypeScriptRenderer;

@@ -312,0 +331,0 @@ }(_Renderer3.default);

@@ -7,21 +7,39 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _keys = require('babel-runtime/core-js/object/keys');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _keys2 = _interopRequireDefault(_keys);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
* @flow
*/
var BELONGS_TO = 'belongsTo';
var BELONGS_TO_MANY = 'belongsToMany';
var HAS_ONE = 'hasOne';
var HAS_MANY = 'hasMany';
var BELONGS_TO /*: string*/ = 'belongsTo';
var BELONGS_TO_MANY /*: string*/ = 'belongsToMany';
var HAS_ONE /*: string*/ = 'hasOne';
var HAS_MANY /*: string*/ = 'hasMany';
/* eslint-disable no-use-before-define */
/*:: type SchemaMap = { [attribute: string]: Schema };*/
/* eslint-enable no-use-before-define */
/*:: type Relation = {
attribute: string,
collection: boolean,
relation: string,
schema: Schema,
};*/
var Schema = function () {

@@ -35,12 +53,11 @@

*/
function Schema(resourceName) {
var primaryKey = arguments.length <= 1 || arguments[1] === undefined ? 'id' : arguments[1];
function Schema(resourceName /*: string*/) {
var primaryKey /*: string*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
(0, _classCallCheck3.default)(this, Schema);
_classCallCheck(this, Schema);
this.resourceName = resourceName;
this.attributes = [];
this.primaryKey = primaryKey;
this.attributes = [];
this.relations = [];
this.relationTypes = {};
this.resourceName = resourceName;
}

@@ -56,5 +73,5 @@

_createClass(Schema, [{
(0, _createClass3.default)(Schema, [{
key: 'addAttributes',
value: function addAttributes(attributes) {
value: function addAttributes(attributes /*: string[]*/) /*: this*/ {
this.attributes = this.attributes.concat(attributes);

@@ -76,3 +93,3 @@

key: 'addRelation',
value: function addRelation(attribute, schema, relation) {
value: function addRelation(attribute /*: string*/, schema /*: Schema*/, relation /*: string*/) /*: this*/ {
if (!(schema instanceof Schema)) {

@@ -110,6 +127,6 @@ throw new Error('Relation "' + attribute + '" is not a valid schema.');

key: 'addRelations',
value: function addRelations(schemas, relation) {
value: function addRelations(schemas /*: SchemaMap*/, relation /*: string*/) /*: this*/ {
var _this = this;
Object.keys(schemas).forEach(function (attribute) {
(0, _keys2.default)(schemas).forEach(function (attribute /*: string*/) {
_this.addRelation(attribute, schemas[attribute], relation);

@@ -130,3 +147,3 @@ });

key: 'belongsTo',
value: function belongsTo(relations) {
value: function belongsTo(relations /*: SchemaMap*/) /*: this*/ {
return this.addRelations(relations, BELONGS_TO);

@@ -144,3 +161,3 @@ }

key: 'belongsToMany',
value: function belongsToMany(relations) {
value: function belongsToMany(relations /*: SchemaMap*/) /*: this*/ {
return this.addRelations(relations, BELONGS_TO_MANY);

@@ -158,3 +175,3 @@ }

key: 'hasOne',
value: function hasOne(relations) {
value: function hasOne(relations /*: SchemaMap*/) /*: this*/ {
return this.addRelations(relations, HAS_ONE);

@@ -172,7 +189,6 @@ }

key: 'hasMany',
value: function hasMany(relations) {
value: function hasMany(relations /*: SchemaMap*/) /*: this*/ {
return this.addRelations(relations, HAS_MANY);
}
}]);
return Schema;

@@ -179,0 +195,0 @@ }();

@@ -7,8 +7,14 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _path = require('path');

@@ -32,4 +38,20 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
/*:: import type {
Options,
SchemaStructure,
AttributesField,
MetadataField,
ConstantsField,
ImportsField,
ShapesField,
SubsetsField,
ReferencesField,
} from './types';*/
var SchemaReader = function () {

@@ -44,4 +66,4 @@

*/
function SchemaReader(filePath, data, options) {
_classCallCheck(this, SchemaReader);
function SchemaReader(filePath /*: string*/, data /*: SchemaStructure*/, options /*: Options*/) {
(0, _classCallCheck3.default)(this, SchemaReader);

@@ -56,2 +78,3 @@ this.path = filePath;

this.imports = [];
this.shapes = {};
this.subsets = {};

@@ -71,5 +94,5 @@ this.references = {};

_createClass(SchemaReader, [{
(0, _createClass3.default)(SchemaReader, [{
key: 'throwError',
value: function throwError(error) {
value: function throwError(error /*: string*/) {
throw new SyntaxError('[' + this.name + '] ' + error);

@@ -106,2 +129,6 @@ }

if (typeof data.shapes !== 'undefined') {
this.setShapes(data.shapes);
}
if (typeof data.subsets !== 'undefined') {

@@ -120,6 +147,6 @@ this.setSubsets(data.subsets);

key: 'setAttributes',
value: function setAttributes(attributes) {
value: function setAttributes(attributes /*: AttributesField*/) {
var _this = this;
if (!(0, _isObject2.default)(attributes) || !Object.keys(attributes).length) {
if (!(0, _isObject2.default)(attributes) || !(0, _keys2.default)(attributes).length) {
this.throwError('No attributes found in schema.');

@@ -129,3 +156,3 @@ }

// Convert to type definitions
this.attributes = Object.keys(attributes).map(function (attribute) {
this.attributes = (0, _keys2.default)(attributes).map(function (attribute) {
return _Factory2.default.definition(_this.options, attribute, attributes[attribute]);

@@ -143,3 +170,3 @@ });

key: 'setConstants',
value: function setConstants(constants) {
value: function setConstants(constants /*: ConstantsField*/) {
if (!(0, _isObject2.default)(constants)) {

@@ -160,3 +187,3 @@ this.throwError('Schema constants must be an object that maps to primitive values.');

key: 'setImports',
value: function setImports(imports) {
value: function setImports(imports /*: ImportsField*/) {
if (!Array.isArray(imports)) {

@@ -177,3 +204,3 @@ this.throwError('Schema imports must be an array of import declarations.');

key: 'setMeta',
value: function setMeta(metadata) {
value: function setMeta(metadata /*: MetadataField*/) {
if (!(0, _isObject2.default)(metadata)) {

@@ -194,3 +221,3 @@ this.throwError('Schema metadata must be an object of strings.');

key: 'setName',
value: function setName(name) {
value: function setName(name /*: string*/) {
if (!name || typeof name !== 'string') {

@@ -211,3 +238,3 @@ this.throwError('No name found in schema.');

key: 'setReferences',
value: function setReferences(references) {
value: function setReferences(references /*: ReferencesField*/) {
if (!(0, _isObject2.default)(references)) {

@@ -221,2 +248,18 @@ this.throwError('Schema references must be an object that maps to other schemas.');

/**
* Set shapes for the schema.
*
* @param {Object} shapes
*/
}, {
key: 'setShapes',
value: function setShapes(shapes /*: ShapesField*/) {
if (!(0, _isObject2.default)(shapes)) {
this.throwError('Schema shapes must be an object.');
}
this.shapes = shapes;
}
/**
* Set subsets of the schema.

@@ -229,3 +272,3 @@ *

key: 'setSubsets',
value: function setSubsets(subsets) {
value: function setSubsets(subsets /*: SubsetsField*/) {
if (!(0, _isObject2.default)(subsets)) {

@@ -238,3 +281,2 @@ this.throwError('Schema subsets must be an object.');

}]);
return SchemaReader;

@@ -241,0 +283,0 @@ }();

@@ -7,10 +7,30 @@ 'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
*
*/
var _from = require('babel-runtime/core-js/array/from');
/* eslint-disable no-console, global-require */
var _from2 = _interopRequireDefault(_from);
var _set = require('babel-runtime/core-js/set');
var _set2 = _interopRequireDefault(_set);
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _fs = require('fs');

@@ -38,9 +58,19 @@

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
/*:: import type { Options } from './types';*/ /**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/* eslint-disable no-console, global-require */
/*:: type ResolveList = {
parentReader?: SchemaReader,
refKey?: string,
resolvePath: string,
};*/
var Transpiler = function () {
function Transpiler(options) {
_classCallCheck(this, Transpiler);
function Transpiler(options /*: Options*/) {
(0, _classCallCheck3.default)(this, Transpiler);

@@ -57,3 +87,3 @@ this.options = options;

_createClass(Transpiler, [{
(0, _createClass3.default)(Transpiler, [{
key: 'transpile',

@@ -68,7 +98,7 @@

*/
value: function transpile(target) {
value: function transpile(target /*: string*/) /*: Promise<string>*/ {
var _this = this;
return new Promise(function (resolve, reject) {
_fs2.default.stat(target, function (error, stats) {
return new _promise2.default(function (resolve /*: (result: string) => void*/, reject /*: (error: Error) => void*/) {
_fs2.default.stat(target, function (error /*: ?Error*/, stats /*: fs.Stats*/) {
if (error) {

@@ -79,8 +109,12 @@ reject(error);

if (stats.isDirectory()) {
resolve(_this.transpileFolder(target));
} else if (stats.isFile()) {
resolve(_this.transpileFile(target));
} else {
reject('Unsupported file type.');
try {
if (stats.isDirectory()) {
resolve(_this.transpileFolder(target));
} else if (stats.isFile()) {
resolve(_this.transpileFile(target));
} else {
reject(new Error('Unsupported file type.'));
}
} catch (e) {
reject(e);
}

@@ -95,3 +129,3 @@ });

* @param {String} folderPath
* @returns {Promise}
* @returns {String}
*/

@@ -101,23 +135,15 @@

key: 'transpileFolder',
value: function transpileFolder(folderPath) {
value: function transpileFolder(folderPath /*: string*/) /*: string*/ {
var _this2 = this;
return new Promise(function (resolve, reject) {
_fs2.default.readdir(folderPath, function (error, filePaths) {
if (error) {
reject(error);
return;
}
var filePaths = _fs2.default.readdirSync(folderPath);
var readers = [];
var readers = [];
filePaths.forEach(function (filePath /*: string*/) {
if (filePath.match(/\.(js|json)$/)) {
readers = [].concat((0, _toConsumableArray3.default)(readers), (0, _toConsumableArray3.default)(_this2.extractReaders(_path2.default.join(folderPath, filePath))));
}
});
filePaths.forEach(function (filePath) {
if (filePath.match(/\.(js|json)$/)) {
readers = [].concat(_toConsumableArray(readers), _toConsumableArray(_this2.extractReaders(_path2.default.join(folderPath, filePath))));
}
});
resolve(_this2.generateOutput(readers));
});
});
return this.generateOutput(readers);
}

@@ -129,3 +155,3 @@

* @param {String} file
* @returns {Promise}
* @returns {String}
*/

@@ -135,3 +161,3 @@

key: 'transpileFile',
value: function transpileFile(file) {
value: function transpileFile(file /*: string*/) /*: string*/ {
return this.generateOutput(this.extractReaders(file));

@@ -149,7 +175,7 @@ }

key: 'extractReaders',
value: function extractReaders(filePath) {
value: function extractReaders(filePath /*: string*/) /*: SchemaReader[]*/ {
var _this3 = this;
var basePath = _path2.default.dirname(filePath);
var toResolve = [{ resolvePath: filePath }];
var toResolve /*: ResolveList[]*/ = [{ resolvePath: filePath }];
var readers = [];

@@ -160,10 +186,10 @@

var _loop = function _loop() {
var _toResolve$shift = toResolve.shift();
var _toResolve$shift = toResolve.shift(),
resolvePath = _toResolve$shift.resolvePath,
parentReader = _toResolve$shift.parentReader,
refKey = _toResolve$shift.refKey;
var resolvePath = _toResolve$shift.resolvePath;
var parentReader = _toResolve$shift.parentReader;
var refKey = _toResolve$shift.refKey;
// Only support JS and JSON
if (!resolvePath.match(/\.(js|json)$/)) {

@@ -174,4 +200,6 @@ // eslint-disable-next-line no-continue

/* eslint-disable */
// $FlowIssue `resolvePath` cannot be a literal string
var reader = new _SchemaReader2.default(resolvePath, require(resolvePath), _this3.options);
/* eslint-enable */

@@ -186,3 +214,3 @@ readers.unshift(reader);

// Extract child references
Object.keys(reader.references).forEach(function (ref) {
(0, _keys2.default)(reader.references).forEach(function (ref /*: string*/) {
toResolve.push({

@@ -209,3 +237,3 @@ resolvePath: _path2.default.normalize(_path2.default.join(basePath, reader.references[ref])),

* @param {SchemaReader[]} readers
* @returns {Promise}
* @returns {String}
*/

@@ -215,57 +243,55 @@

key: 'generateOutput',
value: function generateOutput(readers) {
value: function generateOutput(readers /*: SchemaReader[]*/) /*: string*/ {
var _this4 = this;
return new Promise(function (resolve) {
var rendered = new Set();
var imports = new Set();
var constants = new Set();
var header = new Set();
var schemas = new Set();
var relations = new Set();
var sets = new Set();
var rendered = new _set2.default();
var imports = new _set2.default();
var constants = new _set2.default();
var header = new _set2.default();
var schemas = new _set2.default();
var relations = new _set2.default();
var sets = new _set2.default();
// Wrap in a set to remove duplicates
readers.forEach(function (reader) {
if (rendered.has(reader.path)) {
return;
}
// Wrap in a set to remove duplicates
readers.forEach(function (reader /*: SchemaReader*/) {
if (rendered.has(reader.path)) {
return;
}
var renderer = _Factory2.default.renderer(_this4.options, reader);
var renderer = _Factory2.default.renderer(_this4.options, reader);
renderer.parse();
renderer.parse();
imports = new Set([].concat(_toConsumableArray(Array.from(imports.values())), _toConsumableArray(renderer.getImports())));
imports = new _set2.default([].concat((0, _toConsumableArray3.default)((0, _from2.default)(imports.values())), (0, _toConsumableArray3.default)(renderer.getImports())));
constants = new Set([].concat(_toConsumableArray(Array.from(constants.values())), _toConsumableArray(renderer.getConstants())));
constants = new _set2.default([].concat((0, _toConsumableArray3.default)((0, _from2.default)(constants.values())), (0, _toConsumableArray3.default)(renderer.getConstants())));
header = new Set([].concat(_toConsumableArray(Array.from(header.values())), _toConsumableArray(renderer.getHeader())));
header = new _set2.default([].concat((0, _toConsumableArray3.default)((0, _from2.default)(header.values())), (0, _toConsumableArray3.default)(renderer.getHeader())));
schemas = new Set([].concat(_toConsumableArray(Array.from(schemas.values())), _toConsumableArray(renderer.getSchemas())));
schemas = new _set2.default([].concat((0, _toConsumableArray3.default)((0, _from2.default)(schemas.values())), (0, _toConsumableArray3.default)(renderer.getSchemas())));
relations = new Set([].concat(_toConsumableArray(Array.from(relations.values())), _toConsumableArray(renderer.getRelations())));
relations = new _set2.default([].concat((0, _toConsumableArray3.default)((0, _from2.default)(relations.values())), (0, _toConsumableArray3.default)(renderer.getRelations())));
sets = new Set([].concat(_toConsumableArray(Array.from(sets.values())), _toConsumableArray(renderer.getSets())));
sets = new _set2.default([].concat((0, _toConsumableArray3.default)((0, _from2.default)(sets.values())), (0, _toConsumableArray3.default)(renderer.getSets())));
rendered.add(reader.path);
});
rendered.add(reader.path);
});
// Combine and filter the chunks
var chunks = [];
// Combine and filter the chunks
var chunks = [];
chunks.push(Array.from(imports.values()).join('\n'));
chunks.push(Array.from(constants.values()).join('\n'));
chunks.push(Array.from(header.values()).join('\n\n'));
chunks.push(Array.from(schemas.values()).join('\n\n'));
chunks.push(Array.from(relations.values()).join('\n\n'));
chunks.push(Array.from(sets.values()).join('\n\n'));
chunks.push((0, _from2.default)(imports.values()).join('\n'));
chunks.push((0, _from2.default)(constants.values()).join('\n'));
chunks.push((0, _from2.default)(header.values()).join('\n\n'));
chunks.push((0, _from2.default)(schemas.values()).join('\n\n'));
chunks.push((0, _from2.default)(relations.values()).join('\n\n'));
chunks.push((0, _from2.default)(sets.values()).join('\n\n'));
resolve(chunks.filter(function (value) {
return !!value;
}).join('\n\n') + '\n');
});
return chunks.filter(function (value) {
return !!value;
}).join('\n\n') + '\n';
}
}], [{
key: 'output',
value: function output(value) {
value: function output(value /*: string*/) {
console.log(value);

@@ -283,10 +309,47 @@ process.exit(0);

key: 'error',
value: function error(_error) {
var message = _error instanceof Error ? _error.message : _error;
value: function (_error) {
function error(_x) {
return _error.apply(this, arguments);
}
error.toString = function () {
return _error.toString();
};
return error;
}(function (error /*: Error | string*/) {
var message = '';
var stack = [];
if (error instanceof Error) {
message = ' ' + error.message + ' ';
stack = error.stack.split('\n');
stack.shift();
stack.pop();
} else {
message = ' ' + error + ' ';
}
// Pad the primary message
var length = message.length;
var padding = '';
while (length > 0) {
padding += ' ';
length -= 1;
}
// Output the errors
console.error(padding);
console.error(_chalk2.default.bgRed.white(padding));
console.error(_chalk2.default.bgRed.white(message));
console.error(_chalk2.default.bgRed.white(padding));
console.error(padding);
console.error(_chalk2.default.gray(stack.join('\n')));
console.error(padding);
process.exit(1);
}
})
}]);
return Transpiler;

@@ -293,0 +356,0 @@ }();

@@ -1,1 +0,141 @@

"use strict";
"use strict";
/**
* @copyright 2016, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
/* eslint-disable no-use-before-define */
/*:: export type Options = {
defaultNull: boolean,
defaultRequired: boolean,
includeAttributes: boolean,
includeSchemas: boolean,
includeTypes: boolean,
indentCharacter: string,
renderer: string,
};*/
// Type Definitions
/*:: export type PrimitiveType = string | number | boolean;*/
/*:: export type BaseConfig = {
null?: boolean,
required?: boolean,
type: string,
};*/
/*:: export type ArrayConfig = {
null?: boolean,
required?: boolean,
type: string,
valueType: TypeDefinition,
};*/
/*:: export type BoolConfig = {
null?: boolean,
required?: boolean,
type: string,
};*/
/*:: export type EnumConfig = {
null?: boolean,
required?: boolean,
type: string,
values: PrimitiveType[],
valueType: string,
};*/
/*:: export type FuncConfig = {
argTypes?: TypeDefinition[],
null?: boolean,
required?: boolean,
returnType?: TypeDefinition,
type: string,
};*/
/*:: export type InstanceConfig = {
contract: string,
null?: boolean,
required?: boolean,
type: string,
};*/
/*:: export type NumberConfig = {
null?: boolean,
required?: boolean,
type: string,
};*/
/*:: export type ObjectConfig = {
keyType: TypeDefinition,
null?: boolean,
required?: boolean,
type: string,
valueType: TypeDefinition,
};*/
/*:: export type ReferenceConfig = {
export?: boolean,
null?: boolean,
reference: string,
relation?: string,
required?: boolean,
self: boolean,
subset?: string,
type: string,
};*/
/*:: export type ShapeConfig = {
attributes: { [key: string]: TypeDefinition },
null?: boolean,
reference?: string,
required?: boolean,
type: string,
};*/
/*:: export type StringConfig = {
null?: boolean,
required?: boolean,
type: string,
};*/
/*:: export type UnionConfig = {
null?: boolean,
required?: boolean,
type: string,
valueTypes: TypeDefinition[],
};*/
// JSON Structure
/*:: export type TypeDefinition = string |
ArrayConfig | BoolConfig | EnumConfig | FuncConfig | InstanceConfig | NumberConfig |
ObjectConfig | ReferenceConfig | ShapeConfig | StringConfig | UnionConfig;*/
/*:: export type MetadataField = {
primaryKey?: string,
resourceName?: string,
};*/
/*:: export type ConstantsField = { [key: string]: PrimitiveType | PrimitiveType[] };*/
/*:: export type ImportStructure = {
default?: string,
named?: string[],
path: string,
};*/
/*:: export type ImportsField = ImportStructure[];*/
/*:: export type ShapesField = {
[key: string]: {
[key: string]: TypeDefinition,
},
};*/
/*:: export type SubsetStructure = {
attributes: string[],
null?: { [key: string]: boolean },
required?: { [key: string]: boolean },
};*/
/*:: export type SubsetsField = { [key: string]: string[] | SubsetStructure };*/
/*:: export type AttributesField = { [key: string]: TypeDefinition };*/
/*:: export type ReferencesField = { [key: string]: string };*/
/*:: export type SchemaStructure = {
attributes: AttributesField,
constants?: ConstantsField,
imports?: ImportsField,
meta?: MetadataField,
name: string,
references?: ReferencesField,
shapes?: ShapesField,
subsets?: SubsetsField,
};*/
{
"name": "shapeshifter",
"version": "2.2.2",
"description": "Generate React prop types, Flow types, or TypeScript interfaces from JSON schema files.",
"version": "2.3.0",
"description": "Generate relational schemas, React prop types, Flow type aliases, or TypeScript interfaces from JSON schema files.",
"keywords": [

@@ -32,14 +32,14 @@ "generate",

"clean": "rimraf ./lib",
"build": "babel ./src -d ./lib && npm run build:flow",
"build:flow": "cp ./src/interfaces/shapeshifter.js.flow ./lib",
"build": "babel ./src -d ./lib && yarn run build:flow",
"build:flow": "cp ./flow/shapeshifter.js.flow ./lib",
"watch": "babel --watch ./src -d ./lib",
"lint": "eslint ./src ./tests",
"check": "npm run check:flow && npm run check:typescript",
"check": "yarn run check:flow && yarn run check:typescript",
"check:flow": "flow check",
"check:typescript": "tsc --noEmit --allowJs ./tests/expected/typescript/*",
"mocha": "mocha --opts ./mocha.opts ./tests/*.test.js ./tests/**/*.test.js",
"pretest": "npm run clean && npm run build && npm run lint",
"test": "npm run mocha",
"posttest": "npm run check",
"preversion": "npm test"
"mocha": "mocha --opts ./mocha.opts './tests/**/*.test.js'",
"pretest": "yarn run clean && yarn run build",
"test": "yarn run mocha",
"posttest": "yarn run lint && yarn run check",
"preversion": "yarn test"
},

@@ -60,27 +60,29 @@ "repository": {

"dependencies": {
"chalk": "^1.1.3",
"command-line-args": "^3.0.1",
"command-line-usage": "^3.0.1"
"babel-runtime": "^6.18.0",
"chalk": "^1.1.0",
"command-line-args": "^3.0.0",
"command-line-usage": "^3.0.0"
},
"devDependencies": {
"babel-cli": "^6.14.0",
"babel-eslint": "^6.1.0",
"babel-plugin-transform-flow-strip-types": "^6.14.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-stage-2": "^6.13.0",
"babel-register": "^6.14.0",
"babel-cli": "^6.18.0",
"babel-eslint": "^7.1.1",
"babel-plugin-transform-flow-comments": "^6.17.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-2": "^6.18.0",
"babel-register": "^6.18.0",
"chai": "^3.5.0",
"chai-files": "^1.4.0",
"eslint": "^3.6.0",
"eslint-config-airbnb": "^11.1.0",
"eslint-plugin-flowtype": "^2.19.0",
"eslint-plugin-import": "^1.16.0",
"eslint-plugin-jsx-a11y": "^2.2.2",
"eslint-plugin-react": "^6.3.0",
"flow-bin": "^0.32.0",
"mocha": "^3.0.2",
"react": "^15.3.2",
"eslint": "^3.12.1",
"eslint-config-airbnb": "^13.0.0",
"eslint-plugin-flowtype": "^2.25.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.7.1",
"flow-bin": "^0.37.0",
"mocha": "^3.1.2",
"react": "^15.4.0",
"rimraf": "^2.5.4",
"typescript": "^2.0.3"
"typescript": "^2.1.4"
}
}

@@ -1,2 +0,2 @@

# Shapeshifter v2.2.2
# Shapeshifter v2.3.0
[![Build Status](https://travis-ci.org/milesj/shapeshifter.svg?branch=master)](https://travis-ci.org/milesj/shapeshifter)

@@ -14,18 +14,18 @@

{
"name": "User",
"attributes": {
"id": "number",
"username": "string",
"email": {
"type": "string",
"required": true
},
"location": {
"type": "shape",
"attributes": {
"lat": "number",
"long": "number"
}
}
"name": "User",
"attributes": {
"id": "number",
"username": "string",
"email": {
"type": "string",
"required": true
},
"location": {
"type": "shape",
"attributes": {
"lat": "number",
"long": "number"
}
}
}
}

@@ -40,9 +40,9 @@ ```

export const UserShape = PropTypes.shape({
id: PropTypes.number,
username: PropTypes.string,
email: PropTypes.string.isRequired,
location: PropTypes.shape({
lat: PropTypes.number,
long: PropTypes.number,
}),
id: PropTypes.number,
username: PropTypes.string,
email: PropTypes.string.isRequired,
location: PropTypes.shape({
lat: PropTypes.number,
long: PropTypes.number,
}),
});

@@ -57,9 +57,9 @@ ```

export type UserType = {
id: number,
username: string,
email: string,
location: {
lat: number,
long: number,
},
id: number,
username: string,
email: string,
location: {
lat: number,
long: number,
},
};

@@ -72,9 +72,9 @@ ```

export interface UserInterface {
id?: number;
username?: string;
email: string;
location?: {
lat?: number;
long?: number;
};
id?: number;
username?: string;
email: string;
location?: {
lat?: number;
long?: number;
};
}

@@ -102,2 +102,4 @@ ```

npm install shapeshifter --save-dev
// Or
yarn add shapeshifter --dev
```

@@ -110,2 +112,4 @@

npm install shapeshifter --save
// Or
yarn add shapeshifter
```

@@ -157,22 +161,23 @@

* [JSON Structure](#json-structure)
* [Attributes](#attributes)
* [Subsets](#subsets)
* [Imports](#imports)
* [Constants](#constants)
* [Metadata](#metadata)
* [Attributes](#attributes)
* [Metadata](#metadata)
* [Imports](#imports)
* [Constants](#constants)
* [Subsets](#subsets)
* [Attribute Types](#attribute-types)
* [Primitives](#primitives)
* [Arrays](#arrays)
* [Objects](#objects)
* [Enums](#enums)
* [Shapes](#shapes)
* [Unions](#unions)
* [References](#references)
* [Self References](#self-references)
* [Exported Schemas](#exported-schemas)
* [Relation Type](#relation-type)
* [Instance Ofs](#instance-ofs)
* [Primitives](#primitives)
* [Arrays](#arrays)
* [Objects](#objects)
* [Enums](#enums)
* [Shapes](#shapes)
* [Shape References](#shape-references)
* [Unions](#unions)
* [References](#references)
* [Self References](#self-references)
* [Exported Schemas](#exported-schemas)
* [Relation Type](#relation-type)
* [Instance Ofs](#instance-ofs)
* [Schema Classes](#schema-classes)
* [Including Attributes](#including-attributes)
* [Including Relations](#including-relations)
* [Including Attributes](#including-attributes)
* [Including Relations](#including-relations)

@@ -192,4 +197,4 @@ ### JSON Structure

{
"name": "Users",
"attributes": {}
"name": "Users",
"attributes": {}
}

@@ -217,8 +222,8 @@ ```

"attributes": {
"primitiveField": "string",
"compoundField": {
"type": "enum",
"valueType": "number",
"values": [1, 2, 3]
}
"primitiveField": "string",
"compoundField": {
"type": "enum",
"valueType": "number",
"values": [1, 2, 3]
}
}

@@ -240,49 +245,22 @@ ```

"field": {
"type": "string",
"required": true,
"null": false
"type": "string",
"required": true,
"null": false
}
```
#### Subsets
#### Metadata
The `subsets` object allows for smaller sets of attributes to be
defined and exported in the ES2015 output. Each key in the object
represents a unique name for the subset, while the value of each
property can either be an array of [attribute names](#attributes),
or an object of `attributes`, `required` (optional), and `null`
(optional) properties.
The `meta` object allows arbitrary metadata to be defined. Only two
fields are supported currently, `primaryKey` and `resourceName`, both
of which are used when generating `Schema` classes using `--schemas`.
The `primaryKey` defines the unique identifier / primary key of the record,
usually "id" (default), while `resourceName` is the unique name found in
a URL path. For example, in the URL "/api/users/123", the "users" path
part would be the resource name, and "123" would be the primary key.
Unlike `required` and `null` properties found on type definitions,
these properties represent a mapping of attributes in the current
subset to boolean values, which enable or disable the modifier.
```json
"subsets": {
"SetA": ["foo", "bar"],
"SetB": {
"attributes": ["foo", "qux"],
"null": {
"foo": true
}
},
"SetC": {
"attributes": ["bar", "baz"],
"required": {
"bar": true,
"baz": false
}
}
},
"attributes": {
"foo": "number",
"bar": "bool",
"baz": {
"type": "string",
"required": true
},
"qux": {
"type": "string",
"null": true
}
"meta": {
"primaryKey": "id",
"resourceName": "users"
}

@@ -303,5 +281,5 @@ ```

"imports": [
{ "path": "./foo.js", "default": "FooClass" },
{ "path": "../bar.js", "named": ["funcName", "constName"] },
{ "path": "../baz/qux.js", "default": "BarClass", "named": ["className"] }
{ "path": "./foo.js", "default": "FooClass" },
{ "path": "../bar.js", "named": ["funcName", "constName"] },
{ "path": "../baz/qux.js", "default": "BarClass", "named": ["className"] }
]

@@ -322,23 +300,50 @@ ```

"constants": {
"STATUS_PENDING": 0,
"STATUS_ACTIVE": 1,
"STATUSES": [0, 1],
"ADMIN_FLAG": "admin"
"STATUS_PENDING": 0,
"STATUS_ACTIVE": 1,
"STATUSES": [0, 1],
"ADMIN_FLAG": "admin"
}
```
#### Metadata
#### Subsets
The `meta` object allows arbitrary metadata to be defined. Only two
fields are supported currently, `primaryKey` and `resourceName`, both
of which are used when generating `Schema` classes using `--schemas`.
The `primaryKey` defines the unique identifier / primary key of the record,
usually "id" (default), while `resourceName` is the unique name found in
a URL path. For example, in the URL "/api/users/123", the "users" path
part would be the resource name, and "123" would be the primary key.
The `subsets` object allows for smaller sets of attributes to be
defined and exported in the ES2015 output. Each key in the object
represents a unique name for the subset, while the value of each
property can either be an array of [attribute names](#attributes),
or an object of `attributes`, `required` (optional), and `null`
(optional) properties.
Unlike `required` and `null` properties found on type definitions,
these properties represent a mapping of attributes in the current
subset to boolean values, which enable or disable the modifier.
```json
"meta": {
"primaryKey": "id",
"resourceName": "users"
"subsets": {
"SetA": ["foo", "bar"],
"SetB": {
"attributes": ["foo", "qux"],
"null": {
"foo": true
}
},
"SetC": {
"attributes": ["bar", "baz"],
"required": {
"bar": true,
"baz": false
}
}
},
"attributes": {
"foo": "number",
"bar": "bool",
"baz": {
"type": "string",
"required": true
},
"qux": {
"type": "string",
"null": true
}
}

@@ -369,9 +374,9 @@ ```

"name": {
"type": "string"
"type": "string"
},
"status": {
"type": "number"
"type": "number"
},
"active": {
"type": "boolean"
"type": "boolean"
},

@@ -408,6 +413,6 @@ ```

"messages": {
"type": "array",
"valueType": {
"type": "string"
}
"type": "array",
"valueType": {
"type": "string"
}
}

@@ -441,7 +446,7 @@ ```

"costs": {
"type": "object",
"keyType": "string",
"valueType": {
"type": "number"
}
"type": "object",
"keyType": "string",
"valueType": {
"type": "number"
}
}

@@ -473,5 +478,5 @@ ```

"words": {
"type": "enum",
"valueType": "string",
"values": ["foo", "bar", "baz"]
"type": "enum",
"valueType": "string",
"values": ["foo", "bar", "baz"]
}

@@ -510,11 +515,11 @@ ```

"location": {
"type": "shape",
"attributes": {
"lat": "number",
"long": "number",
"name": {
"type": "string",
"required": true
}
"type": "shape",
"attributes": {
"lat": "number",
"long": "number",
"name": {
"type": "string",
"required": true
}
}
}

@@ -528,5 +533,5 @@ ```

location: PropTypes.shape({
lat: PropTypes.number,
long: PropTypes.number,
name: PropTypes.string.isRequired,
lat: PropTypes.number,
long: PropTypes.number,
name: PropTypes.string.isRequired,
}),

@@ -536,5 +541,5 @@

location: {
lat: number,
long: number,
name: string,
lat: number,
long: number,
name: string,
},

@@ -544,5 +549,5 @@

location?: {
lat?: number,
long?: number,
name: string,
lat?: number,
long?: number,
name: string,
},

@@ -553,2 +558,50 @@ ```

##### Shape References
Shapes are powerful at defining nested attributes, while
[references](#references) are great at reusing external schemas.
Shape references are a combination of both of these patterns --
it permits a local shape definition to be used throughout
multiple attributes.
To begin, define a mapping of attributes, under unique name,
in the top level `shapes` property.
```json
{
"name": "Receipt",
"shapes": {
"Price": {
"amount": "number",
"nativeAmount": "number",
"exchangeRate": "number"
}
},
"attributes": {}
}
```
Once the shape definition exists, we can point out attributes
to the shape using the `reference` property, like so.
```json
"attributes": {
"fees": {
"type": "shape",
"reference": "Price"
},
"taxes": {
"type": "shape",
"reference": "Price"
},
"total": {
"type": "shape",
"reference": "Price"
}
}
```
With this approach, the `attributes` property is not required
for each shape type.
#### Unions

@@ -562,11 +615,11 @@

"error": {
"type": "union",
"valueTypes": [
"string",
{ "type": "number" },
{
"type": "instance",
"contract": "Error"
}
]
"type": "union",
"valueTypes": [
"string",
{ "type": "number" },
{
"type": "instance",
"contract": "Error"
}
]
}

@@ -580,5 +633,5 @@ ```

error: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.instanceOf(Error),
PropTypes.string,
PropTypes.number,
PropTypes.instanceOf(Error),
]),

@@ -606,7 +659,7 @@

{
"name": "Users",
"references": {
"profile": "./profile.json"
},
"attributes": {}
"name": "Users",
"references": {
"Profile": "./profile.json"
},
"attributes": {}
}

@@ -622,5 +675,5 @@ ```

"profile": {
"type": "reference",
"reference": "profile",
"subset": ""
"type": "reference",
"reference": "Profile",
"subset": ""
}

@@ -653,4 +706,4 @@ ```

"node": {
"type": "reference",
"self": true
"type": "reference",
"self": true
}

@@ -668,5 +721,5 @@ ```

"node": {
"type": "reference",
"reference": "field",
"export": false
"type": "reference",
"reference": "field",
"export": false
}

@@ -687,5 +740,5 @@ ```

"node": {
"type": "reference",
"reference": "field",
"relation": "belongsTo"
"type": "reference",
"reference": "field",
"relation": "belongsTo"
}

@@ -706,4 +759,4 @@ ```

"model": {
"type": "instance",
"contract": "UserModel"
"type": "instance",
"contract": "UserModel"
}

@@ -717,3 +770,3 @@ ```

"imports": [
{ "default": "UserModel", "path": "../models/UserModel" }
{ "default": "UserModel", "path": "../models/UserModel" }
]

@@ -771,6 +824,6 @@ ```

{
attribute: 'foo', // Field name
schema: new Schema(), // Reference schema class
relation: Schema.HAS_ONE, // Relation type
collection: false, // Is it an array?
attribute: 'foo', // Field name
schema: new Schema(), // Reference schema class
relation: Schema.HAS_ONE, // Relation type
collection: false, // Is it an array?
}

@@ -795,3 +848,3 @@ ```

UserSchema
.addAttributes(['id', 'username', 'email', 'location']);
.addAttributes(['id', 'username', 'email', 'location']);
```

@@ -819,13 +872,13 @@

PostSchema
.belongsTo({
user: UserSchema,
});
.belongsTo({
user: UserSchema,
});
UserSchema
.hasOne({
country: CountrySchema,
})
.hasMany({
posts: PostSchema,
});
.hasOne({
country: CountrySchema,
})
.hasMany({
posts: PostSchema,
});
```

@@ -832,0 +885,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc