deep-core
Advanced tools
Comparing version 1.12.14 to 1.12.15
@@ -54,3 +54,3 @@ /** | ||
value: function list() { | ||
return [Service.ANY, Service.LAMBDA, Service.SIMPLE_STORAGE_SERVICE, Service.DYNAMO_DB, Service.SIMPLE_NOTIFICATION_SERVICE, Service.COGNITO_IDENTITY, Service.COGNITO_IDENTITY_PROVIDER, Service.COGNITO_SYNC, Service.ELASTIC_CACHE, Service.IDENTITY_AND_ACCESS_MANAGEMENT, Service.KINESIS, Service.CLOUD_FRONT, Service.SECURITY_TOKEN_SERVICE, Service.CLOUD_WATCH_LOGS, Service.API_GATEWAY, Service.API_GATEWAY_EXECUTE, Service.CLOUD_SEARCH, Service.SIMPLE_QUEUE_SERVICE, Service.CERTIFICATE_MANAGER, Service.EC2, Service.ELASTIC_SEARCH, Service.CLOUD_WATCH_EVENTS, Service.CLOUD_WATCH, Service.SIMPLE_EMAIL_SERVICE, Service.LAMBDA_EDGE]; | ||
return [Service.ANY, Service.LAMBDA, Service.SIMPLE_STORAGE_SERVICE, Service.DYNAMO_DB, Service.SIMPLE_NOTIFICATION_SERVICE, Service.COGNITO_IDENTITY, Service.COGNITO_IDENTITY_PROVIDER, Service.COGNITO_SYNC, Service.ELASTIC_CACHE, Service.IDENTITY_AND_ACCESS_MANAGEMENT, Service.KINESIS, Service.CLOUD_FRONT, Service.SECURITY_TOKEN_SERVICE, Service.CLOUD_WATCH_LOGS, Service.API_GATEWAY, Service.API_GATEWAY_EXECUTE, Service.CLOUD_SEARCH, Service.SIMPLE_QUEUE_SERVICE, Service.CERTIFICATE_MANAGER, Service.EC2, Service.ELASTIC_SEARCH, Service.CLOUD_WATCH_EVENTS, Service.CLOUD_WATCH, Service.SIMPLE_EMAIL_SERVICE, Service.LAMBDA_EDGE, Service.X_RAY]; | ||
} | ||
@@ -306,2 +306,12 @@ }, { | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'X_RAY', | ||
get: function get() { | ||
return 'xray'; | ||
} | ||
}]); | ||
@@ -308,0 +318,0 @@ |
@@ -12,4 +12,6 @@ /** | ||
var _Extractable = require('./Extractable'); | ||
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 _Extractable2 = require('./Extractable'); | ||
var _Service = require('../Service'); | ||
@@ -21,6 +23,14 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Iam statement action | ||
*/ | ||
class Action extends _Extractable.Extractable { | ||
let Action = exports.Action = function (_Extractable) { | ||
_inherits(Action, _Extractable); | ||
/** | ||
@@ -30,9 +40,15 @@ * @param {String} service | ||
*/ | ||
constructor(service = _Service.Service.ANY, actionName = _Policy.Policy.ANY) { | ||
super(); | ||
function Action() { | ||
let service = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _Service.Service.ANY; | ||
let actionName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _Policy.Policy.ANY; | ||
this._service = null; | ||
this._action = actionName; | ||
_classCallCheck(this, Action); | ||
this.service = service; | ||
var _this = _possibleConstructorReturn(this, (Action.__proto__ || Object.getPrototypeOf(Action)).call(this)); | ||
_this._service = null; | ||
_this._action = actionName; | ||
_this.service = service; | ||
return _this; | ||
} | ||
@@ -43,41 +59,55 @@ | ||
*/ | ||
set action(action) { | ||
this._action = action; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
get action() { | ||
return this._action; | ||
} | ||
/** | ||
* @param {String} name | ||
*/ | ||
set service(name) { | ||
if (!_Service.Service.exists(name)) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(name, _Service.Service); | ||
_createClass(Action, [{ | ||
key: 'extract', | ||
/** | ||
* @returns {String} | ||
*/ | ||
value: function extract() { | ||
let service = this._service; | ||
let action = this._action; | ||
return `${service}:${action}`; | ||
} | ||
}, { | ||
key: 'action', | ||
set: function set(action) { | ||
this._action = action; | ||
} | ||
this._service = name; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._action; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
get service() { | ||
return this._service; | ||
} | ||
/** | ||
* @param {String} name | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
extract() { | ||
let service = this._service; | ||
let action = this._action; | ||
}, { | ||
key: 'service', | ||
set: function set(name) { | ||
if (!_Service.Service.exists(name)) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(name, _Service.Service); | ||
} | ||
return `${service}:${action}`; | ||
} | ||
} | ||
exports.Action = Action; | ||
this._service = name; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._service; | ||
} | ||
}]); | ||
return Action; | ||
}(_Extractable2.Extractable); |
@@ -14,22 +14,35 @@ /** | ||
var _Extractable = require('./Extractable'); | ||
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 _Extractable2 = require('./Extractable'); | ||
var _InvalidArgumentException = require('../../Exception/InvalidArgumentException'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Collection of something | ||
*/ | ||
class Collection extends _Extractable.Extractable { | ||
let Collection = exports.Collection = function (_Extractable) { | ||
_inherits(Collection, _Extractable); | ||
/** | ||
* @param {Object} prototype | ||
*/ | ||
constructor(prototype) { | ||
super(); | ||
function Collection(prototype) { | ||
_classCallCheck(this, Collection); | ||
if (prototype.__proto__ !== _Extractable.Extractable) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(prototype, _Extractable.Extractable); | ||
var _this = _possibleConstructorReturn(this, (Collection.__proto__ || Object.getPrototypeOf(Collection)).call(this)); | ||
if (prototype.__proto__ !== _Extractable2.Extractable) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(prototype, _Extractable2.Extractable); | ||
} | ||
this._prototype = prototype; | ||
this._vector = []; | ||
_this._prototype = prototype; | ||
_this._vector = []; | ||
return _this; | ||
} | ||
@@ -40,59 +53,84 @@ | ||
*/ | ||
get prototype() { | ||
return this._prototype; | ||
} | ||
/** | ||
* @param {Array} args | ||
* @returns {Object} | ||
*/ | ||
create(...args) { | ||
return new this._prototype(...args); | ||
} | ||
/** | ||
* @param {Array} args | ||
* @returns {Object} | ||
*/ | ||
add(...args) { | ||
let instance = args.length === 1 && args[0] instanceof this._prototype ? args[0] : this.create(...args); | ||
_createClass(Collection, [{ | ||
key: 'create', | ||
this._vector.push(instance); | ||
return instance; | ||
} | ||
/** | ||
* @param {Array} args | ||
* @returns {Object} | ||
*/ | ||
value: function create() { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
/** | ||
* @returns {Number} | ||
*/ | ||
count() { | ||
return this._vector.length; | ||
} | ||
return new (Function.prototype.bind.apply(this._prototype, [null].concat(args)))(); | ||
} | ||
/** | ||
* @returns {Array} | ||
*/ | ||
list() { | ||
return this._vector; | ||
} | ||
/** | ||
* @param {Array} args | ||
* @returns {Object} | ||
*/ | ||
/** | ||
* @returns {Array} | ||
*/ | ||
extract() { | ||
let vector = []; | ||
}, { | ||
key: 'add', | ||
value: function add() { | ||
let instance = arguments.length === 1 && (arguments.length <= 0 ? undefined : arguments[0]) instanceof this._prototype ? arguments.length <= 0 ? undefined : arguments[0] : this.create.apply(this, arguments); | ||
for (let itemKey in this._vector) { | ||
if (!this._vector.hasOwnProperty(itemKey)) { | ||
continue; | ||
} | ||
this._vector.push(instance); | ||
let item = this._vector[itemKey]; | ||
return instance; | ||
} | ||
vector.push(item.extract()); | ||
/** | ||
* @returns {Number} | ||
*/ | ||
}, { | ||
key: 'count', | ||
value: function count() { | ||
return this._vector.length; | ||
} | ||
return vector; | ||
} | ||
} | ||
exports.Collection = Collection; | ||
/** | ||
* @returns {Array} | ||
*/ | ||
}, { | ||
key: 'list', | ||
value: function list() { | ||
return this._vector; | ||
} | ||
/** | ||
* @returns {Array} | ||
*/ | ||
}, { | ||
key: 'extract', | ||
value: function extract() { | ||
let vector = []; | ||
for (let itemKey in this._vector) { | ||
if (!this._vector.hasOwnProperty(itemKey)) { | ||
continue; | ||
} | ||
let item = this._vector[itemKey]; | ||
vector.push(item.extract()); | ||
} | ||
return vector; | ||
} | ||
}, { | ||
key: 'prototype', | ||
get: function get() { | ||
return this._prototype; | ||
} | ||
}]); | ||
return Collection; | ||
}(_Extractable2.Extractable); |
@@ -12,15 +12,26 @@ /** | ||
var _Exception = require('../../../Exception/Exception'); | ||
var _Exception2 = require('../../../Exception/Exception'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Thrown when ARN is invalid | ||
*/ | ||
class InvalidArnException extends _Exception.Exception { | ||
let InvalidArnException = exports.InvalidArnException = function (_Exception) { | ||
_inherits(InvalidArnException, _Exception); | ||
/** | ||
* @param {String} arn | ||
*/ | ||
constructor(arn) { | ||
super(`Invalid arn string "${arn}".`); | ||
function InvalidArnException(arn) { | ||
_classCallCheck(this, InvalidArnException); | ||
return _possibleConstructorReturn(this, (InvalidArnException.__proto__ || Object.getPrototypeOf(InvalidArnException)).call(this, `Invalid arn string "${arn}".`)); | ||
} | ||
} | ||
exports.InvalidArnException = InvalidArnException; | ||
return InvalidArnException; | ||
}(_Exception2.Exception); |
@@ -12,12 +12,23 @@ /** | ||
var _Interface = require('../../OOP/Interface'); | ||
var _Interface2 = require('../../OOP/Interface'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Extractable helper | ||
*/ | ||
class Extractable extends _Interface.Interface { | ||
constructor() { | ||
super(['extract']); | ||
let Extractable = exports.Extractable = function (_Interface) { | ||
_inherits(Extractable, _Interface); | ||
function Extractable() { | ||
_classCallCheck(this, Extractable); | ||
return _possibleConstructorReturn(this, (Extractable.__proto__ || Object.getPrototypeOf(Extractable)).call(this, ['extract'])); | ||
} | ||
} | ||
exports.Extractable = Extractable; | ||
return Extractable; | ||
}(_Interface2.Interface); |
@@ -12,2 +12,4 @@ /** | ||
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 _Resource = require('./Resource'); | ||
@@ -23,72 +25,105 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
* AWS IAM factory | ||
*/ | ||
class Factory { | ||
/** | ||
* @param {Function|*} Prototype | ||
* @param {Array} args | ||
* @returns {Object} | ||
*/ | ||
static create(Prototype, ...args) { | ||
Prototype = Factory._assurePrototype(Prototype); | ||
return new Prototype(...args); | ||
let Factory = exports.Factory = function () { | ||
function Factory() { | ||
_classCallCheck(this, Factory); | ||
} | ||
/** | ||
* @param {Function|*} Prototype | ||
* @returns {Collection} | ||
*/ | ||
static createCollection(Prototype) { | ||
Prototype = Factory._assurePrototype(Prototype); | ||
_createClass(Factory, null, [{ | ||
key: 'create', | ||
return new _Collection.Collection(Prototype); | ||
} | ||
/** | ||
* @param {Function|*} Prototype | ||
* @param {Array} args | ||
* @returns {Object} | ||
*/ | ||
value: function create(Prototype) { | ||
Prototype = Factory._assurePrototype(Prototype); | ||
/** | ||
* @param {Function|*} Prototype | ||
* @returns {Function} | ||
* @private | ||
*/ | ||
static _assurePrototype(Prototype) { | ||
if (typeof Prototype === 'string') { | ||
Prototype = Factory[Prototype.toUpperCase()]; | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
return new (Function.prototype.bind.apply(Prototype, [null].concat(args)))(); | ||
} | ||
return Prototype; | ||
} | ||
/** | ||
* @param {Function|*} Prototype | ||
* @returns {Collection} | ||
*/ | ||
/** | ||
* @returns {Policy} | ||
* @constructor | ||
*/ | ||
static get POLICY() { | ||
return _Policy.Policy; | ||
} | ||
}, { | ||
key: 'createCollection', | ||
value: function createCollection(Prototype) { | ||
Prototype = Factory._assurePrototype(Prototype); | ||
/** | ||
* @returns {Action} | ||
* @constructor | ||
*/ | ||
static get RESOURCE() { | ||
return _Resource.Resource; | ||
} | ||
return new _Collection.Collection(Prototype); | ||
} | ||
/** | ||
* @returns {Resource} | ||
* @constructor | ||
*/ | ||
static get ACTION() { | ||
return _Action.Action; | ||
} | ||
/** | ||
* @param {Function|*} Prototype | ||
* @returns {Function} | ||
* @private | ||
*/ | ||
/** | ||
* @returns {Statement} | ||
* @constructor | ||
*/ | ||
static get STATEMENT() { | ||
return _Statement.Statement; | ||
} | ||
} | ||
exports.Factory = Factory; | ||
}, { | ||
key: '_assurePrototype', | ||
value: function _assurePrototype(Prototype) { | ||
if (typeof Prototype === 'string') { | ||
Prototype = Factory[Prototype.toUpperCase()]; | ||
} | ||
return Prototype; | ||
} | ||
/** | ||
* @returns {Policy} | ||
* @constructor | ||
*/ | ||
}, { | ||
key: 'POLICY', | ||
get: function get() { | ||
return _Policy.Policy; | ||
} | ||
/** | ||
* @returns {Action} | ||
* @constructor | ||
*/ | ||
}, { | ||
key: 'RESOURCE', | ||
get: function get() { | ||
return _Resource.Resource; | ||
} | ||
/** | ||
* @returns {Resource} | ||
* @constructor | ||
*/ | ||
}, { | ||
key: 'ACTION', | ||
get: function get() { | ||
return _Action.Action; | ||
} | ||
/** | ||
* @returns {Statement} | ||
* @constructor | ||
*/ | ||
}, { | ||
key: 'STATEMENT', | ||
get: function get() { | ||
return _Statement.Statement; | ||
} | ||
}]); | ||
return Factory; | ||
}(); |
@@ -12,4 +12,6 @@ /** | ||
var _Extractable = require('./Extractable'); | ||
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 _Extractable2 = require('./Extractable'); | ||
var _Collection = require('./Collection'); | ||
@@ -19,18 +21,22 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* IAM policy | ||
*/ | ||
class Policy extends _Extractable.Extractable { | ||
constructor() { | ||
super(); | ||
let Policy = exports.Policy = function (_Extractable) { | ||
_inherits(Policy, _Extractable); | ||
this._version = Policy.DEFAULT_VERSION; | ||
this._statement = new _Collection.Collection(_Statement.Statement); | ||
} | ||
function Policy() { | ||
_classCallCheck(this, Policy); | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ANY() { | ||
return '*'; | ||
var _this = _possibleConstructorReturn(this, (Policy.__proto__ || Object.getPrototypeOf(Policy)).call(this)); | ||
_this._version = Policy.DEFAULT_VERSION; | ||
_this._statement = new _Collection.Collection(_Statement.Statement); | ||
return _this; | ||
} | ||
@@ -41,44 +47,73 @@ | ||
*/ | ||
static get DEFAULT_VERSION() { | ||
return '2012-10-17'; | ||
} | ||
/** | ||
* @param {String} version | ||
*/ | ||
set version(version) { | ||
this._version = version; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
get version() { | ||
return this._version; | ||
} | ||
_createClass(Policy, [{ | ||
key: 'extract', | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
get statement() { | ||
return this._statement; | ||
} | ||
/** | ||
* @return {Object} | ||
*/ | ||
extract() { | ||
return { | ||
Version: this._version, | ||
Statement: this._statement.extract() | ||
}; | ||
} | ||
/** | ||
* @return {Object} | ||
*/ | ||
value: function extract() { | ||
return { | ||
Version: this._version, | ||
Statement: this._statement.extract() | ||
}; | ||
} | ||
/** | ||
* @return {String} | ||
*/ | ||
toString() { | ||
return JSON.stringify(this.extract()); | ||
} | ||
} | ||
exports.Policy = Policy; | ||
/** | ||
* @return {String} | ||
*/ | ||
}, { | ||
key: 'toString', | ||
value: function toString() { | ||
return JSON.stringify(this.extract()); | ||
} | ||
}, { | ||
key: 'version', | ||
/** | ||
* @param {String} version | ||
*/ | ||
set: function set(version) { | ||
this._version = version; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._version; | ||
} | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
}, { | ||
key: 'statement', | ||
get: function get() { | ||
return this._statement; | ||
} | ||
}], [{ | ||
key: 'ANY', | ||
get: function get() { | ||
return '*'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'DEFAULT_VERSION', | ||
get: function get() { | ||
return '2012-10-17'; | ||
} | ||
}]); | ||
return Policy; | ||
}(_Extractable2.Extractable); |
@@ -12,4 +12,6 @@ /** | ||
var _Extractable = require('./Extractable'); | ||
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 _Extractable2 = require('./Extractable'); | ||
var _Region = require('../Region'); | ||
@@ -23,18 +25,34 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* IAM statement resource | ||
*/ | ||
class Resource extends _Extractable.Extractable { | ||
constructor(service = _Service.Service.ANY, region = '', accountId = '', descriptor = '') { | ||
super(); | ||
let Resource = exports.Resource = function (_Extractable) { | ||
_inherits(Resource, _Extractable); | ||
this._service = null; | ||
this._region = null; | ||
this._accountId = accountId; | ||
this._descriptor = descriptor; | ||
function Resource() { | ||
let service = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _Service.Service.ANY; | ||
let region = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
let accountId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; | ||
let descriptor = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ''; | ||
this.service = service; | ||
this.region = region; | ||
_classCallCheck(this, Resource); | ||
this._any = false; | ||
var _this = _possibleConstructorReturn(this, (Resource.__proto__ || Object.getPrototypeOf(Resource)).call(this)); | ||
_this._service = null; | ||
_this._region = null; | ||
_this._accountId = accountId; | ||
_this._descriptor = descriptor; | ||
_this.service = service; | ||
_this.region = region; | ||
_this._any = false; | ||
return _this; | ||
} | ||
@@ -45,108 +63,136 @@ | ||
*/ | ||
any() { | ||
this._any = true; | ||
return this; | ||
} | ||
/** | ||
* @param {String} identifier | ||
*/ | ||
set accountId(identifier) { | ||
this._accountId = identifier; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
get accountId() { | ||
return this._accountId; | ||
} | ||
_createClass(Resource, [{ | ||
key: 'any', | ||
value: function any() { | ||
this._any = true; | ||
return this; | ||
} | ||
/** | ||
* @param {String} descriptor | ||
*/ | ||
set descriptor(descriptor) { | ||
this._descriptor = descriptor; | ||
} | ||
/** | ||
* @param {String} identifier | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
get descriptor() { | ||
return this._descriptor; | ||
} | ||
}, { | ||
key: 'updateFromArn', | ||
/** | ||
* @param {String} name | ||
*/ | ||
set region(name) { | ||
if (!_Region.Region.exists(name)) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(name, _Region.Region); | ||
/** | ||
* @see - http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html | ||
* | ||
* @param {string} arn | ||
* @returns {Resource} | ||
*/ | ||
value: function updateFromArn(arn) { | ||
let arnParts = arn.split(':'); | ||
if (arnParts.length < 6) { | ||
throw new _InvalidArnException.InvalidArnException(arn); | ||
} | ||
this.service = arnParts[2]; | ||
this.region = arnParts[3]; | ||
this.accountId = arnParts[4]; | ||
this.descriptor = arnParts.slice(5).join(':'); | ||
return this; | ||
} | ||
this._region = name; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
get region() { | ||
return this._region; | ||
} | ||
}, { | ||
key: 'extract', | ||
value: function extract() { | ||
if (this._any) { | ||
return '*'; | ||
} | ||
/** | ||
* @param {String} name | ||
*/ | ||
set service(name) { | ||
if (!_Service.Service.exists(name)) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(name, _Service.Service); | ||
let service = this._service; | ||
let region = this._region; | ||
let accountId = this._accountId; | ||
let descriptor = this._descriptor; | ||
return `arn:aws:${service}:${region}:${accountId}:${descriptor}`; | ||
} | ||
}, { | ||
key: 'accountId', | ||
set: function set(identifier) { | ||
this._accountId = identifier; | ||
} | ||
this._service = name; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._accountId; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
get service() { | ||
return this._service; | ||
} | ||
/** | ||
* @param {String} descriptor | ||
*/ | ||
/** | ||
* @see - http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html | ||
* | ||
* @param {string} arn | ||
* @returns {Resource} | ||
*/ | ||
updateFromArn(arn) { | ||
let arnParts = arn.split(':'); | ||
}, { | ||
key: 'descriptor', | ||
set: function set(descriptor) { | ||
this._descriptor = descriptor; | ||
} | ||
if (arnParts.length < 6) { | ||
throw new _InvalidArnException.InvalidArnException(arn); | ||
/** | ||
* @returns {String} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._descriptor; | ||
} | ||
this.service = arnParts[2]; | ||
this.region = arnParts[3]; | ||
this.accountId = arnParts[4]; | ||
this.descriptor = arnParts.slice(5).join(':'); | ||
/** | ||
* @param {String} name | ||
*/ | ||
return this; | ||
} | ||
}, { | ||
key: 'region', | ||
set: function set(name) { | ||
if (!_Region.Region.exists(name)) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(name, _Region.Region); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
extract() { | ||
if (this._any) { | ||
return '*'; | ||
this._region = name; | ||
} | ||
let service = this._service; | ||
let region = this._region; | ||
let accountId = this._accountId; | ||
let descriptor = this._descriptor; | ||
/** | ||
* @returns {String} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._region; | ||
} | ||
return `arn:aws:${service}:${region}:${accountId}:${descriptor}`; | ||
} | ||
} | ||
exports.Resource = Resource; | ||
/** | ||
* @param {String} name | ||
*/ | ||
}, { | ||
key: 'service', | ||
set: function set(name) { | ||
if (!_Service.Service.exists(name)) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(name, _Service.Service); | ||
} | ||
this._service = name; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._service; | ||
} | ||
}]); | ||
return Resource; | ||
}(_Extractable2.Extractable); |
@@ -14,2 +14,4 @@ /** | ||
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 _Resource = require('./Resource'); | ||
@@ -23,20 +25,31 @@ | ||
var _Extractable = require('./Extractable'); | ||
var _Extractable2 = require('./Extractable'); | ||
var _InvalidArgumentException = require('../../Exception/InvalidArgumentException'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* IAM policy statement | ||
*/ | ||
class Statement extends _Extractable.Extractable { | ||
constructor() { | ||
super(); | ||
let Statement = exports.Statement = function (_Extractable) { | ||
_inherits(Statement, _Extractable); | ||
this._effect = Statement.ALLOW; | ||
this._action = new _Collection.Collection(_Action.Action); | ||
this._notAction = new _Collection.Collection(_Action.Action); | ||
this._resource = new _Collection.Collection(_Resource.Resource); | ||
this._notResource = new _Collection.Collection(_Resource.Resource); | ||
this._condition = null; | ||
this._principal = null; | ||
function Statement() { | ||
_classCallCheck(this, Statement); | ||
var _this = _possibleConstructorReturn(this, (Statement.__proto__ || Object.getPrototypeOf(Statement)).call(this)); | ||
_this._effect = Statement.ALLOW; | ||
_this._action = new _Collection.Collection(_Action.Action); | ||
_this._notAction = new _Collection.Collection(_Action.Action); | ||
_this._resource = new _Collection.Collection(_Resource.Resource); | ||
_this._notResource = new _Collection.Collection(_Resource.Resource); | ||
_this._condition = null; | ||
_this._principal = null; | ||
return _this; | ||
} | ||
@@ -47,123 +60,159 @@ | ||
*/ | ||
set effect(effect) { | ||
if ([Statement.ALLOW, Statement.DENY].indexOf(effect) === -1) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(effect, '[Statement.ALLOW, Statement.DENY]'); | ||
} | ||
this._effect = effect; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
get effect() { | ||
return this._effect; | ||
} | ||
_createClass(Statement, [{ | ||
key: 'extract', | ||
/** | ||
* @param {Object} condition | ||
*/ | ||
set condition(condition) { | ||
this._condition = condition; | ||
} | ||
/** | ||
* @returns {Object} | ||
*/ | ||
get condition() { | ||
return this._condition; | ||
} | ||
/** | ||
* @returns {Object} | ||
*/ | ||
value: function extract() { | ||
let actions = this._action.count() > 0 ? this._action.extract() : _Policy.Policy.ANY; | ||
let resources = this._resource.count() > 0 ? this._resource.extract() : null; | ||
/** | ||
* @param {*} principal | ||
*/ | ||
set principal(principal) { | ||
this._principal = principal; | ||
} | ||
let statement = { | ||
Effect: this._effect, | ||
Action: actions | ||
}; | ||
/** | ||
* @returns {*} | ||
*/ | ||
get principal() { | ||
return this._principal; | ||
} | ||
if (resources !== null) { | ||
statement.Resource = resources; | ||
} | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
get notResource() { | ||
return this._notResource; | ||
} | ||
if (this._condition !== null && this._condition instanceof Object) { | ||
statement.Condition = this._condition; | ||
} | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
get resource() { | ||
return this._resource; | ||
} | ||
// @todo - create separate class for Principal | ||
if (this._principal != null) { | ||
statement.Principal = this._principal; | ||
} | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
get notAction() { | ||
return this._notAction; | ||
} | ||
if (this._notAction.count() > 0) { | ||
statement.NotAction = this._notAction.extract(); | ||
} | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
get action() { | ||
return this._action; | ||
} | ||
if (this._notResource.count() > 0) { | ||
statement.NotResource = this._notResource.extract(); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ALLOW() { | ||
return 'Allow'; | ||
} | ||
return statement; | ||
} | ||
}, { | ||
key: 'effect', | ||
set: function set(effect) { | ||
if ([Statement.ALLOW, Statement.DENY].indexOf(effect) === -1) { | ||
throw new _InvalidArgumentException.InvalidArgumentException(effect, '[Statement.ALLOW, Statement.DENY]'); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get DENY() { | ||
return 'Deny'; | ||
} | ||
this._effect = effect; | ||
} | ||
/** | ||
* @returns {Object} | ||
*/ | ||
extract() { | ||
let actions = this._action.count() > 0 ? this._action.extract() : _Policy.Policy.ANY; | ||
let resources = this._resource.count() > 0 ? this._resource.extract() : null; | ||
/** | ||
* @returns {String} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._effect; | ||
} | ||
let statement = { | ||
Effect: this._effect, | ||
Action: actions | ||
}; | ||
/** | ||
* @param {Object} condition | ||
*/ | ||
if (resources !== null) { | ||
statement.Resource = resources; | ||
}, { | ||
key: 'condition', | ||
set: function set(condition) { | ||
this._condition = condition; | ||
} | ||
if (this._condition !== null && this._condition instanceof Object) { | ||
statement.Condition = this._condition; | ||
/** | ||
* @returns {Object} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._condition; | ||
} | ||
// @todo - create separate class for Principal | ||
if (this._principal != null) { | ||
statement.Principal = this._principal; | ||
/** | ||
* @param {*} principal | ||
*/ | ||
}, { | ||
key: 'principal', | ||
set: function set(principal) { | ||
this._principal = principal; | ||
} | ||
if (this._notAction.count() > 0) { | ||
statement.NotAction = this._notAction.extract(); | ||
/** | ||
* @returns {*} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._principal; | ||
} | ||
if (this._notResource.count() > 0) { | ||
statement.NotResource = this._notResource.extract(); | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
}, { | ||
key: 'notResource', | ||
get: function get() { | ||
return this._notResource; | ||
} | ||
return statement; | ||
} | ||
} | ||
exports.Statement = Statement; | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
}, { | ||
key: 'resource', | ||
get: function get() { | ||
return this._resource; | ||
} | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
}, { | ||
key: 'notAction', | ||
get: function get() { | ||
return this._notAction; | ||
} | ||
/** | ||
* @returns {Collection} | ||
*/ | ||
}, { | ||
key: 'action', | ||
get: function get() { | ||
return this._action; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}], [{ | ||
key: 'ALLOW', | ||
get: function get() { | ||
return 'Allow'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'DENY', | ||
get: function get() { | ||
return 'Deny'; | ||
} | ||
}]); | ||
return Statement; | ||
}(_Extractable2.Extractable); |
@@ -12,7 +12,14 @@ /** | ||
}); | ||
class Context { | ||
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; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
let Context = exports.Context = function () { | ||
/** | ||
* @param {Object} lambdaContext | ||
*/ | ||
constructor(lambdaContext) { | ||
function Context(lambdaContext) { | ||
_classCallCheck(this, Context); | ||
this._lambdaContext = lambdaContext; | ||
@@ -26,54 +33,74 @@ | ||
*/ | ||
get options() { | ||
return this._lambdaContext; | ||
} | ||
/** | ||
* @private | ||
*/ | ||
_registerDataAsOptions() { | ||
for (let key in this._lambdaContext) { | ||
if (!this._lambdaContext.hasOwnProperty(key)) { | ||
continue; | ||
_createClass(Context, [{ | ||
key: '_registerDataAsOptions', | ||
/** | ||
* @private | ||
*/ | ||
value: function _registerDataAsOptions() { | ||
for (let key in this._lambdaContext) { | ||
if (!this._lambdaContext.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
Object.defineProperty(this, key, { | ||
value: this._lambdaContext[key], | ||
writable: false, | ||
configurable: false, | ||
enumerable: true | ||
}); | ||
} | ||
Object.defineProperty(this, key, { | ||
value: this._lambdaContext[key], | ||
writable: false, | ||
// Avoid _data key listing on Object.keys(request) | ||
Object.defineProperty(this, '_options', { | ||
configurable: false, | ||
enumerable: true | ||
enumerable: false | ||
}); | ||
} | ||
// Avoid _data key listing on Object.keys(request) | ||
Object.defineProperty(this, '_options', { | ||
configurable: false, | ||
enumerable: false | ||
}); | ||
} | ||
/** | ||
* @param {String} option | ||
* @returns {boolean} | ||
*/ | ||
/** | ||
* @param {String} option | ||
* @returns {boolean} | ||
*/ | ||
has(option) { | ||
return this._lambdaContext.hasOwnProperty(option); | ||
} | ||
}, { | ||
key: 'has', | ||
value: function has(option) { | ||
return this._lambdaContext.hasOwnProperty(option); | ||
} | ||
/** | ||
* @param {String} option | ||
* @param {*} defaultValue | ||
* @returns {*} | ||
*/ | ||
getOption(option, defaultValue = undefined) { | ||
return this._lambdaContext.hasOwnProperty(option) ? this._lambdaContext[option] : defaultValue; | ||
} | ||
/** | ||
* @param {String} option | ||
* @param {*} defaultValue | ||
* @returns {*} | ||
*/ | ||
/** | ||
* Enables Callback wait for empty event loop | ||
*/ | ||
waitForEmptyEventLoop() { | ||
this._lambdaContext.callbackWaitsForEmptyEventLoop = true; | ||
} | ||
} | ||
exports.Context = Context; | ||
}, { | ||
key: 'getOption', | ||
value: function getOption(option) { | ||
let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
return this._lambdaContext.hasOwnProperty(option) ? this._lambdaContext[option] : defaultValue; | ||
} | ||
/** | ||
* Enables Callback wait for empty event loop | ||
*/ | ||
}, { | ||
key: 'waitForEmptyEventLoop', | ||
value: function waitForEmptyEventLoop() { | ||
this._lambdaContext.callbackWaitsForEmptyEventLoop = true; | ||
} | ||
}, { | ||
key: 'options', | ||
get: function get() { | ||
return this._lambdaContext; | ||
} | ||
}]); | ||
return Context; | ||
}(); |
@@ -12,4 +12,6 @@ /** | ||
var _Response = require('./Response'); | ||
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 _Response2 = require('./Response'); | ||
var _Exception = require('../../Exception/Exception'); | ||
@@ -19,6 +21,14 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Error response sent to the lambda context | ||
*/ | ||
class ErrorResponse extends _Response.Response { | ||
let ErrorResponse = exports.ErrorResponse = function (_Response) { | ||
_inherits(ErrorResponse, _Response); | ||
/** | ||
@@ -28,4 +38,6 @@ * @param {Runtime} runtime | ||
*/ | ||
constructor(runtime, error) { | ||
super(runtime, ErrorResponse.createErrorObject(error)); | ||
function ErrorResponse(runtime, error) { | ||
_classCallCheck(this, ErrorResponse); | ||
return _possibleConstructorReturn(this, (ErrorResponse.__proto__ || Object.getPrototypeOf(ErrorResponse)).call(this, runtime, ErrorResponse.createErrorObject(error))); | ||
} | ||
@@ -37,52 +49,64 @@ | ||
*/ | ||
static createErrorObject(error) { | ||
let errorObj = {}; | ||
let errorCode = _Exception.Exception.DEFAULT_CODE; | ||
if (error.name === 'ValidationError') { | ||
// we assume it's a joi validation error | ||
errorCode = 400; | ||
errorObj = { | ||
errorType: error.name, | ||
errorMessage: error.annotate(), | ||
errorStack: error.stack || new Error(error.message).stack, | ||
validationErrors: error.details | ||
}; | ||
} else if (error instanceof Error) { | ||
errorObj = { | ||
errorType: error.name, | ||
errorMessage: error.message, | ||
errorStack: error.stack || new Error(error.message).stack | ||
}; | ||
} else { | ||
let plainError = (error || 'Unexpected error occurred.').toString(); | ||
errorObj = { | ||
errorType: 'Error', | ||
errorMessage: plainError, | ||
errorStack: new Error(plainError).stack | ||
}; | ||
_createClass(ErrorResponse, [{ | ||
key: 'data', | ||
/** | ||
* | ||
* @returns {Object} | ||
* @private | ||
*/ | ||
get: function get() { | ||
return JSON.stringify(this._data); | ||
} | ||
errorObj[_Exception.Exception.CODE_KEY] = _Helper.Helper.assureDefinedCode(error.code || errorCode); | ||
/** | ||
* @returns {String} | ||
*/ | ||
return errorObj; | ||
} | ||
}], [{ | ||
key: 'createErrorObject', | ||
value: function createErrorObject(error) { | ||
let errorObj = {}; | ||
let errorCode = _Exception.Exception.DEFAULT_CODE; | ||
/** | ||
* | ||
* @returns {Object} | ||
* @private | ||
*/ | ||
get data() { | ||
return JSON.stringify(this._data); | ||
} | ||
if (error.name === 'ValidationError') { | ||
// we assume it's a joi validation error | ||
errorCode = 400; | ||
errorObj = { | ||
errorType: error.name, | ||
errorMessage: error.annotate(), | ||
errorStack: error.stack || new Error(error.message).stack, | ||
validationErrors: error.details | ||
}; | ||
} else if (error instanceof Error) { | ||
errorObj = { | ||
errorType: error.name, | ||
errorMessage: error.message, | ||
errorStack: error.stack || new Error(error.message).stack | ||
}; | ||
} else { | ||
let plainError = (error || 'Unexpected error occurred.').toString(); | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get contextMethod() { | ||
return 'fail'; | ||
} | ||
} | ||
exports.ErrorResponse = ErrorResponse; | ||
errorObj = { | ||
errorType: 'Error', | ||
errorMessage: plainError, | ||
errorStack: new Error(plainError).stack | ||
}; | ||
} | ||
errorObj[_Exception.Exception.CODE_KEY] = _Helper.Helper.assureDefinedCode(error.code || errorCode); | ||
return errorObj; | ||
} | ||
}, { | ||
key: 'contextMethod', | ||
get: function get() { | ||
return 'fail'; | ||
} | ||
}]); | ||
return ErrorResponse; | ||
}(_Response2.Response); |
@@ -12,9 +12,20 @@ /** | ||
var _Exception = require('../../../Exception/Exception'); | ||
var _Exception2 = require('../../../Exception/Exception'); | ||
class ContextAlreadySentException extends _Exception.Exception { | ||
constructor() { | ||
super('The Lambda context have been already sent'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
let ContextAlreadySentException = exports.ContextAlreadySentException = function (_Exception) { | ||
_inherits(ContextAlreadySentException, _Exception); | ||
function ContextAlreadySentException() { | ||
_classCallCheck(this, ContextAlreadySentException); | ||
return _possibleConstructorReturn(this, (ContextAlreadySentException.__proto__ || Object.getPrototypeOf(ContextAlreadySentException)).call(this, 'The Lambda context have been already sent')); | ||
} | ||
} | ||
exports.ContextAlreadySentException = ContextAlreadySentException; | ||
return ContextAlreadySentException; | ||
}(_Exception2.Exception); |
@@ -12,15 +12,26 @@ /** | ||
var _Exception = require('../../../Exception/Exception'); | ||
var _Exception2 = require('../../../Exception/Exception'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Thrown when context identity pool id does not much identity pool id from security service | ||
*/ | ||
class InvalidCognitoIdentityException extends _Exception.Exception { | ||
let InvalidCognitoIdentityException = exports.InvalidCognitoIdentityException = function (_Exception) { | ||
_inherits(InvalidCognitoIdentityException, _Exception); | ||
/** | ||
* @param {String} identityPoolId | ||
*/ | ||
constructor(identityPoolId) { | ||
super(`Invalid cognito identity pool "${identityPoolId}".`, 403); | ||
function InvalidCognitoIdentityException(identityPoolId) { | ||
_classCallCheck(this, InvalidCognitoIdentityException); | ||
return _possibleConstructorReturn(this, (InvalidCognitoIdentityException.__proto__ || Object.getPrototypeOf(InvalidCognitoIdentityException)).call(this, `Invalid cognito identity pool "${identityPoolId}".`, 403)); | ||
} | ||
} | ||
exports.InvalidCognitoIdentityException = InvalidCognitoIdentityException; | ||
return InvalidCognitoIdentityException; | ||
}(_Exception2.Exception); |
@@ -12,12 +12,23 @@ /** | ||
var _Exception = require('../../../Exception/Exception'); | ||
var _Exception2 = require('../../../Exception/Exception'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Thrown when missing runtime lambda context | ||
*/ | ||
class MissingRuntimeContextException extends _Exception.Exception { | ||
constructor() { | ||
super('Missing Lambda runtime context', 400); | ||
let MissingRuntimeContextException = exports.MissingRuntimeContextException = function (_Exception) { | ||
_inherits(MissingRuntimeContextException, _Exception); | ||
function MissingRuntimeContextException() { | ||
_classCallCheck(this, MissingRuntimeContextException); | ||
return _possibleConstructorReturn(this, (MissingRuntimeContextException.__proto__ || Object.getPrototypeOf(MissingRuntimeContextException)).call(this, 'Missing Lambda runtime context', 400)); | ||
} | ||
} | ||
exports.MissingRuntimeContextException = MissingRuntimeContextException; | ||
return MissingRuntimeContextException; | ||
}(_Exception2.Exception); |
@@ -12,9 +12,20 @@ /** | ||
var _Exception = require('../../../Exception/Exception'); | ||
var _Exception2 = require('../../../Exception/Exception'); | ||
class MissingUserContextException extends _Exception.Exception { | ||
constructor() { | ||
super('Missing user context in the Lambda runtime', 403); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
let MissingUserContextException = exports.MissingUserContextException = function (_Exception) { | ||
_inherits(MissingUserContextException, _Exception); | ||
function MissingUserContextException() { | ||
_classCallCheck(this, MissingUserContextException); | ||
return _possibleConstructorReturn(this, (MissingUserContextException.__proto__ || Object.getPrototypeOf(MissingUserContextException)).call(this, 'Missing user context in the Lambda runtime', 403)); | ||
} | ||
} | ||
exports.MissingUserContextException = MissingUserContextException; | ||
return MissingUserContextException; | ||
}(_Exception2.Exception); |
@@ -14,2 +14,4 @@ /** | ||
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 _qs = require('qs'); | ||
@@ -21,10 +23,16 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
* Request received by the lambda context | ||
*/ | ||
class Request { | ||
let Request = exports.Request = function () { | ||
/** | ||
* @param {*} data | ||
*/ | ||
constructor(data = {}) { | ||
function Request() { | ||
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
_classCallCheck(this, Request); | ||
this._data = !Array.isArray(data) ? _qs2.default.parse(data) : data; | ||
@@ -38,39 +46,53 @@ | ||
*/ | ||
_registerDataAsParams() { | ||
for (let key in this._data) { | ||
if (!this._data.hasOwnProperty(key)) { | ||
continue; | ||
_createClass(Request, [{ | ||
key: '_registerDataAsParams', | ||
value: function _registerDataAsParams() { | ||
for (let key in this._data) { | ||
if (!this._data.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
Object.defineProperty(this, key, { | ||
value: this._data[key], | ||
writable: false, | ||
configurable: false, | ||
enumerable: true | ||
}); | ||
} | ||
Object.defineProperty(this, key, { | ||
value: this._data[key], | ||
writable: false, | ||
configurable: false, | ||
enumerable: true | ||
// Avoid _data key listing on Object.keys(request) | ||
Object.defineProperty(this, '_data', { | ||
configurable: false | ||
}); | ||
} | ||
// Avoid _data key listing on Object.keys(request) | ||
Object.defineProperty(this, '_data', { | ||
configurable: false | ||
}); | ||
} | ||
/** | ||
* @returns {*} | ||
*/ | ||
/** | ||
* @returns {*} | ||
*/ | ||
get data() { | ||
return this._data; | ||
} | ||
}, { | ||
key: 'getParam', | ||
/** | ||
* @param {String} name | ||
* @param {String|Object|null} defaultValue | ||
* | ||
* @returns {String|Object|null} | ||
*/ | ||
getParam(name, defaultValue = undefined) { | ||
return this._data.hasOwnProperty(name) ? this._data[name] : defaultValue; | ||
} | ||
} | ||
exports.Request = Request; | ||
/** | ||
* @param {String} name | ||
* @param {String|Object|null} defaultValue | ||
* | ||
* @returns {String|Object|null} | ||
*/ | ||
value: function getParam(name) { | ||
let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; | ||
return this._data.hasOwnProperty(name) ? this._data[name] : defaultValue; | ||
} | ||
}, { | ||
key: 'data', | ||
get: function get() { | ||
return this._data; | ||
} | ||
}]); | ||
return Request; | ||
}(); |
@@ -14,7 +14,14 @@ /** | ||
}); | ||
class Resolver { | ||
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; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
let Resolver = exports.Resolver = function () { | ||
/** | ||
* @param {Function} lambdaCallback | ||
*/ | ||
constructor(lambdaCallback) { | ||
function Resolver(lambdaCallback) { | ||
_classCallCheck(this, Resolver); | ||
this._lambdaCallback = lambdaCallback; | ||
@@ -27,22 +34,34 @@ this._onSucceed = []; | ||
*/ | ||
succeed(object) { | ||
this._onSucceed.forEach(cb => cb(object)); | ||
this._lambdaCallback(null, object); | ||
} | ||
/** | ||
* @param {Object} object | ||
*/ | ||
fail(object) { | ||
this._lambdaCallback(object, null); | ||
} | ||
_createClass(Resolver, [{ | ||
key: 'succeed', | ||
value: function succeed(object) { | ||
this._onSucceed.forEach(cb => cb(object)); | ||
/** | ||
* @param {Function} cb; | ||
*/ | ||
registerSucceedCallback(cb) { | ||
this._onSucceed.push(cb); | ||
} | ||
} | ||
exports.Resolver = Resolver; | ||
this._lambdaCallback(null, object); | ||
} | ||
/** | ||
* @param {Object} object | ||
*/ | ||
}, { | ||
key: 'fail', | ||
value: function fail(object) { | ||
this._lambdaCallback(object, null); | ||
} | ||
/** | ||
* @param {Function} cb; | ||
*/ | ||
}, { | ||
key: 'registerSucceedCallback', | ||
value: function registerSucceedCallback(cb) { | ||
this._onSucceed.push(cb); | ||
} | ||
}]); | ||
return Resolver; | ||
}(); |
@@ -12,8 +12,12 @@ /** | ||
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 _MissingRuntimeContextException = require('./Exception/MissingRuntimeContextException'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
* Response sent to the lambda context | ||
*/ | ||
class Response { | ||
let Response = exports.Response = function () { | ||
/** | ||
@@ -23,3 +27,5 @@ * @param {Runtime} runtime | ||
*/ | ||
constructor(runtime, data) { | ||
function Response(runtime, data) { | ||
_classCallCheck(this, Response); | ||
this._data = data; | ||
@@ -32,65 +38,86 @@ this._runtime = runtime; | ||
*/ | ||
get runtime() { | ||
return this._runtime; | ||
} | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
get contextSent() { | ||
return this._runtime.contextSent; | ||
} | ||
/** | ||
* @returns {Response} | ||
*/ | ||
send() { | ||
if (!this._runtime.context) { | ||
throw new _MissingRuntimeContextException.MissingRuntimeContextException(); | ||
// @todo: Figure out why lambda container caches _runtime.contextSent | ||
// } else if (this.contextSent) { | ||
// throw new ContextAlreadySentException(); | ||
_createClass(Response, [{ | ||
key: 'send', | ||
/** | ||
* @returns {Response} | ||
*/ | ||
value: function send() { | ||
if (!this._runtime.context) { | ||
throw new _MissingRuntimeContextException.MissingRuntimeContextException(); | ||
// @todo: Figure out why lambda container caches _runtime.contextSent | ||
// } else if (this.contextSent) { | ||
// throw new ContextAlreadySentException(); | ||
} | ||
this.runtime.logService.rumLog({ | ||
service: 'deep-core', | ||
resourceType: 'Lambda', | ||
resourceId: this.runtime.context.invokedFunctionArn, | ||
eventName: 'Run' | ||
}); | ||
// flush RUM batched messages if any | ||
this.runtime.logService.rumFlush((error, data) => { | ||
// @todo: via setter? | ||
this._runtime._contextSent = true; | ||
(this._runtime.resolver || this._runtime.context)[this.constructor.contextMethod](this.data); | ||
}); | ||
return this; | ||
} | ||
this.runtime.logService.rumLog({ | ||
service: 'deep-core', | ||
resourceType: 'Lambda', | ||
resourceId: this.runtime.context.invokedFunctionArn, | ||
eventName: 'Run' | ||
}); | ||
/** | ||
* | ||
* @returns {Object} | ||
* @private | ||
*/ | ||
// flush RUM batched messages if any | ||
this.runtime.logService.rumFlush((error, data) => { | ||
// @todo: via setter? | ||
this._runtime._contextSent = true; | ||
}, { | ||
key: 'runtime', | ||
get: function get() { | ||
return this._runtime; | ||
} | ||
(this._runtime.resolver || this._runtime.context)[this.constructor.contextMethod](this.data); | ||
}); | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
return this; | ||
} | ||
}, { | ||
key: 'contextSent', | ||
get: function get() { | ||
return this._runtime.contextSent; | ||
} | ||
}, { | ||
key: 'data', | ||
get: function get() { | ||
return this._data; | ||
} | ||
/** | ||
* | ||
* @returns {Object} | ||
* @private | ||
*/ | ||
get data() { | ||
return this._data; | ||
} | ||
/** | ||
* @returns {Object} | ||
*/ | ||
/** | ||
* @returns {Object} | ||
*/ | ||
get rawData() { | ||
return this._data; | ||
} | ||
}, { | ||
key: 'rawData', | ||
get: function get() { | ||
return this._data; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get contextMethod() { | ||
return 'succeed'; | ||
} | ||
} | ||
exports.Response = Response; | ||
/** | ||
* @returns {String} | ||
*/ | ||
}], [{ | ||
key: 'contextMethod', | ||
get: function get() { | ||
return 'succeed'; | ||
} | ||
}]); | ||
return Response; | ||
}(); |
@@ -11,4 +11,6 @@ /** | ||
var _Interface = require('../../OOP/Interface'); | ||
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 _Interface2 = require('../../OOP/Interface'); | ||
var _Response = require('./Response'); | ||
@@ -36,24 +38,35 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Lambda runtime context | ||
*/ | ||
class Runtime extends _Interface.Interface { | ||
let Runtime = exports.Runtime = function (_Interface) { | ||
_inherits(Runtime, _Interface); | ||
/** | ||
* @param {Object} kernel | ||
*/ | ||
constructor(kernel) { | ||
super(['handle']); | ||
function Runtime(kernel) { | ||
_classCallCheck(this, Runtime); | ||
this._kernel = kernel; | ||
this._request = null; | ||
this._context = null; | ||
this._resolver = null; | ||
var _this2 = _possibleConstructorReturn(this, (Runtime.__proto__ || Object.getPrototypeOf(Runtime)).call(this, ['handle'])); | ||
this._loggedUserId = null; | ||
this._forceUserIdentity = false; | ||
this._contextSent = false; | ||
_this2._kernel = kernel; | ||
_this2._request = null; | ||
_this2._context = null; | ||
_this2._resolver = null; | ||
this._calleeConfig = null; | ||
_this2._loggedUserId = null; | ||
_this2._forceUserIdentity = false; | ||
_this2._contextSent = false; | ||
this._fillDenyMissingUserContextOption(); | ||
_this2._calleeConfig = null; | ||
_this2._fillDenyMissingUserContextOption(); | ||
return _this2; | ||
} | ||
@@ -64,314 +77,402 @@ | ||
*/ | ||
get context() { | ||
return this._context; | ||
} | ||
/** | ||
* @returns {null|Resolver} | ||
*/ | ||
get resolver() { | ||
return this._resolver; | ||
} | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
get contextSent() { | ||
return this._contextSent; | ||
} | ||
_createClass(Runtime, [{ | ||
key: 'validateInput', | ||
/** | ||
* @returns {String} | ||
*/ | ||
get loggedUserId() { | ||
return this._loggedUserId; | ||
} | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
get forceUserIdentity() { | ||
return this._forceUserIdentity; | ||
} | ||
/** | ||
* @param {String} schemaName | ||
* @param {Function} cb | ||
* @returns {Runtime} | ||
*/ | ||
value: function validateInput(schemaName, cb) { | ||
let validation = this._kernel.get('validation'); | ||
/** | ||
* @returns {Object} | ||
*/ | ||
get kernel() { | ||
return this._kernel; | ||
} | ||
validation.validateRuntimeInput(this, schemaName, cb); | ||
/** | ||
* @returns {Function} | ||
*/ | ||
get lambda() { | ||
let _this = this; | ||
return this; | ||
} | ||
return function (event, context) { | ||
_this.run(event, context); | ||
}; | ||
} | ||
/** | ||
* @param {Object} event | ||
* @param {Object} context | ||
* @param {Function} lambdaCallback | ||
* @returns {Runtime} | ||
*/ | ||
/** | ||
* @param {String} schemaName | ||
* @param {Function} cb | ||
* @returns {Runtime} | ||
*/ | ||
validateInput(schemaName, cb) { | ||
let validation = this._kernel.get('validation'); | ||
}, { | ||
key: 'run', | ||
value: function run(event, context) { | ||
let lambdaCallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
validation.validateRuntimeInput(this, schemaName, cb); | ||
this._context = new _Context.Context(context); | ||
this._request = new _Request.Request(event); | ||
return this; | ||
} | ||
if (lambdaCallback) { | ||
this._resolver = new _Resolver.Resolver(lambdaCallback); | ||
/** | ||
* @param {Object} event | ||
* @param {Object} context | ||
* @param {Function} lambdaCallback | ||
* @returns {Runtime} | ||
*/ | ||
run(event, context, lambdaCallback = null) { | ||
this._context = new _Context.Context(context); | ||
this._request = new _Request.Request(event); | ||
this._resolver.registerSucceedCallback(this.kernel.kernelCleanup.bind(this.kernel)); | ||
} | ||
if (lambdaCallback) { | ||
this._resolver = new _Resolver.Resolver(lambdaCallback); | ||
this._context.waitForEmptyEventLoop(); | ||
this._resolver.registerSucceedCallback(this.kernel.kernelCleanup.bind(this.kernel)); | ||
this.logService.rumLog({ | ||
service: 'deep-core', | ||
resourceType: 'Lambda', | ||
resourceId: this._context.invokedFunctionArn, | ||
eventName: 'Run' | ||
}); | ||
new _Sandbox.Sandbox(() => { | ||
this._fillUserContext().then(() => { | ||
if (!this._loggedUserId && this._forceUserIdentity) { | ||
throw new _MissingUserContextException.MissingUserContextException(); | ||
} | ||
this._initDBPartitionKey(); | ||
let validationSchema = this.validationSchema; | ||
if (validationSchema) { | ||
this._runValidate(validationSchema); | ||
} else { | ||
this.handle(this._request); | ||
} | ||
}).catch(e => this.createError(e).send()); | ||
}).fail(error => { | ||
this.createError(error).send(); | ||
}).run(); | ||
return this; | ||
} | ||
this._context.waitForEmptyEventLoop(); | ||
/** | ||
* @param {String} validationSchema | ||
* @private | ||
*/ | ||
this.logService.rumLog({ | ||
service: 'deep-core', | ||
resourceType: 'Lambda', | ||
resourceId: this._context.invokedFunctionArn, | ||
eventName: 'Run' | ||
}); | ||
}, { | ||
key: '_runValidate', | ||
value: function _runValidate(validationSchema) { | ||
let validationSchemaName = validationSchema; | ||
new _Sandbox.Sandbox(() => { | ||
this._fillUserContext().then(() => { | ||
if (!this._loggedUserId && this._forceUserIdentity) { | ||
throw new _MissingUserContextException.MissingUserContextException(); | ||
} | ||
if (typeof validationSchema !== 'string') { | ||
validationSchemaName = this._injectValidationSchema(validationSchema); | ||
} | ||
this._initDBPartitionKey(); | ||
this.validateInput(validationSchemaName, validatedData => { | ||
this.handle(validatedData); | ||
}); | ||
} | ||
let validationSchema = this.validationSchema; | ||
/** | ||
* @param {Object} schema | ||
* @param {String|null} name | ||
* @returns {String} | ||
* @private | ||
*/ | ||
if (validationSchema) { | ||
this._runValidate(validationSchema); | ||
} else { | ||
this.handle(this._request); | ||
} | ||
}).catch(e => this.createError(e).send()); | ||
}).fail(error => { | ||
this.createError(error).send(); | ||
}).run(); | ||
}, { | ||
key: '_injectValidationSchema', | ||
value: function _injectValidationSchema(schema) { | ||
let name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
return this; | ||
} | ||
let validation = this._kernel.get('validation'); | ||
/** | ||
* @param {String} validationSchema | ||
* @private | ||
*/ | ||
_runValidate(validationSchema) { | ||
let validationSchemaName = validationSchema; | ||
name = name || `DeepHandlerValidation_${new Date().getTime()}`; | ||
if (typeof validationSchema !== 'string') { | ||
validationSchemaName = this._injectValidationSchema(validationSchema); | ||
validation.setGuessSchema(name, schema); | ||
return name; | ||
} | ||
this.validateInput(validationSchemaName, validatedData => { | ||
this.handle(validatedData); | ||
}); | ||
} | ||
/** | ||
* @param {String|Error|*} error | ||
* @returns {ErrorResponse} | ||
*/ | ||
/** | ||
* @param {Object} schema | ||
* @param {String|null} name | ||
* @returns {String} | ||
* @private | ||
*/ | ||
_injectValidationSchema(schema, name = null) { | ||
let validation = this._kernel.get('validation'); | ||
}, { | ||
key: 'createError', | ||
value: function createError(error) { | ||
return new _ErrorResponse.ErrorResponse(this, error); | ||
} | ||
name = name || `DeepHandlerValidation_${new Date().getTime()}`; | ||
/** | ||
* @param {Object} data | ||
* @returns {Response} | ||
*/ | ||
validation.setGuessSchema(name, schema); | ||
}, { | ||
key: 'createResponse', | ||
value: function createResponse(data) { | ||
return new _Response.Response(this, data); | ||
} | ||
return name; | ||
} | ||
/** | ||
* @param {Object} data | ||
* @param {Number} ttl | ||
* @param {Function} callback | ||
*/ | ||
/** | ||
* @param {String|Error|*} error | ||
* @returns {ErrorResponse} | ||
*/ | ||
createError(error) { | ||
return new _ErrorResponse.ErrorResponse(this, error); | ||
} | ||
}, { | ||
key: 'createCachedResponse', | ||
value: function createCachedResponse(data) { | ||
let ttl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
let callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : response => response.send(); | ||
/** | ||
* @param {Object} data | ||
* @returns {Response} | ||
*/ | ||
createResponse(data) { | ||
return new _Response.Response(this, data); | ||
} | ||
let publicCache = this._kernel.get('cache').shared; | ||
let publicCacheKey = publicCache.buildKeyFromLambdaRuntime(this); | ||
let response = new _Response.Response(this, data); | ||
/** | ||
* @param {Object} data | ||
* @param {Number} ttl | ||
* @param {Function} callback | ||
*/ | ||
createCachedResponse(data, ttl = 0, callback = response => response.send()) { | ||
let publicCache = this._kernel.get('cache').shared; | ||
let publicCacheKey = publicCache.buildKeyFromLambdaRuntime(this); | ||
let response = new _Response.Response(this, data); | ||
publicCache.assure(publicCacheKey, { body: data }, ttl, () => { | ||
callback(response); | ||
}); | ||
} | ||
publicCache.assure(publicCacheKey, { body: data }, ttl, () => { | ||
callback(response); | ||
}); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
get calleeName() { | ||
if (this._context && this._context.has('invokedFunctionArn')) { | ||
let calleeArn = this._context.getOption('invokedFunctionArn'); | ||
}, { | ||
key: '_fillDenyMissingUserContextOption', | ||
return calleeArn.replace(/^.+:function:/i, ''); | ||
/** | ||
* @private | ||
*/ | ||
value: function _fillDenyMissingUserContextOption() { | ||
if (this._kernel.config.hasOwnProperty('forceUserIdentity')) { | ||
this._forceUserIdentity = this._kernel.config.forceUserIdentity; | ||
} | ||
} | ||
return null; | ||
} | ||
/** | ||
* @returns {Runtime} | ||
* @private | ||
*/ | ||
/** | ||
* @returns {null|Object} | ||
*/ | ||
get calleeConfig() { | ||
if (!this._calleeConfig && this._context && this._kernel && this._context.has('invokedFunctionArn')) { | ||
}, { | ||
key: '_initDBPartitionKey', | ||
value: function _initDBPartitionKey() { | ||
if (!this.kernel.accountMicroservice || !this.forceUserIdentity) { | ||
return this; | ||
} | ||
let resource = this._kernel.get('resource'); | ||
let calleeArn = this._context.getOption('invokedFunctionArn'); | ||
let db = this.dbService; | ||
let user = this.securityService.token && this.securityService.token.user; | ||
let partitionKey = Runtime.DB_ANONYMOUS_PARTITION; | ||
this._calleeConfig = resource.getActionConfig(calleeArn); | ||
if (user && user.ActiveAccount) { | ||
partitionKey = user.ActiveAccount.Id; | ||
} | ||
db.setDynamoDBPartitionKey(partitionKey); | ||
return this; | ||
} | ||
return this._calleeConfig; | ||
} | ||
/** | ||
* Retrieves logged user id from lambda context | ||
* | ||
* @private | ||
* @returns {Promise} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
get validationSchema() { | ||
return this.calleeConfig ? this.calleeConfig.validationSchema || null : null; | ||
} | ||
}, { | ||
key: '_fillUserContext', | ||
value: function _fillUserContext() { | ||
if (this._context && this._context.identity && this._context.identity.cognitoIdentityPoolId && this._context.identity.cognitoIdentityId) { | ||
let identityPoolId = this._context.identity.cognitoIdentityPoolId; | ||
/** | ||
* @returns {Request} | ||
*/ | ||
get request() { | ||
return this._request; | ||
} | ||
if (this.securityService.identityPoolId !== identityPoolId && !this._kernel.container.localBackend) { | ||
/** | ||
* @returns {Object} | ||
*/ | ||
get securityService() { | ||
return this.kernel.get('security'); | ||
} | ||
return Promise.reject(new _InvalidCognitoIdentityException.InvalidCognitoIdentityException(identityPoolId)); | ||
} | ||
/** | ||
* @returns {DB} | ||
*/ | ||
get dbService() { | ||
return this.kernel.get('db'); | ||
} | ||
// inject lambda context into security service | ||
// and instantiate security token without loading user credentials | ||
return this.securityService.warmupBackendLogin(this._context).then(credentials => { | ||
let dbService = this.dbService; | ||
/** | ||
* @returns {Object} | ||
*/ | ||
get logService() { | ||
return this.kernel.get('log'); | ||
} | ||
_awsSdk2.default.config.credentials = credentials; | ||
credentials && dbService.overwriteCredentials(credentials); | ||
/** | ||
* @private | ||
*/ | ||
_fillDenyMissingUserContextOption() { | ||
if (this._kernel.config.hasOwnProperty('forceUserIdentity')) { | ||
this._forceUserIdentity = this._kernel.config.forceUserIdentity; | ||
this._loggedUserId = this._context.identity.cognitoIdentityId; | ||
}); | ||
} | ||
return Promise.resolve(null); | ||
} | ||
} | ||
/** | ||
* @returns {Runtime} | ||
* @private | ||
*/ | ||
_initDBPartitionKey() { | ||
if (!this.kernel.accountMicroservice || !this.forceUserIdentity) { | ||
return this; | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'context', | ||
get: function get() { | ||
return this._context; | ||
} | ||
let db = this.dbService; | ||
let user = this.securityService.token && this.securityService.token.user; | ||
let partitionKey = Runtime.DB_ANONYMOUS_PARTITION; | ||
/** | ||
* @returns {null|Resolver} | ||
*/ | ||
if (user && user.ActiveAccount) { | ||
partitionKey = user.ActiveAccount.Id; | ||
}, { | ||
key: 'resolver', | ||
get: function get() { | ||
return this._resolver; | ||
} | ||
db.setDynamoDBPartitionKey(partitionKey); | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
return this; | ||
} | ||
}, { | ||
key: 'contextSent', | ||
get: function get() { | ||
return this._contextSent; | ||
} | ||
/** | ||
* Retrieves logged user id from lambda context | ||
* | ||
* @private | ||
* @returns {Promise} | ||
*/ | ||
_fillUserContext() { | ||
if (this._context && this._context.identity && this._context.identity.cognitoIdentityPoolId && this._context.identity.cognitoIdentityId) { | ||
let identityPoolId = this._context.identity.cognitoIdentityPoolId; | ||
/** | ||
* @returns {String} | ||
*/ | ||
if (this.securityService.identityPoolId !== identityPoolId && !this._kernel.container.localBackend) { | ||
}, { | ||
key: 'loggedUserId', | ||
get: function get() { | ||
return this._loggedUserId; | ||
} | ||
return Promise.reject(new _InvalidCognitoIdentityException.InvalidCognitoIdentityException(identityPoolId)); | ||
/** | ||
* @returns {Boolean} | ||
*/ | ||
}, { | ||
key: 'forceUserIdentity', | ||
get: function get() { | ||
return this._forceUserIdentity; | ||
} | ||
/** | ||
* @returns {Object} | ||
*/ | ||
}, { | ||
key: 'kernel', | ||
get: function get() { | ||
return this._kernel; | ||
} | ||
/** | ||
* @returns {Function} | ||
*/ | ||
}, { | ||
key: 'lambda', | ||
get: function get() { | ||
let _this = this; | ||
return function (event, context) { | ||
_this.run(event, context); | ||
}; | ||
} | ||
}, { | ||
key: 'calleeName', | ||
get: function get() { | ||
if (this._context && this._context.has('invokedFunctionArn')) { | ||
let calleeArn = this._context.getOption('invokedFunctionArn'); | ||
return calleeArn.replace(/^.+:function:/i, ''); | ||
} | ||
// inject lambda context into security service | ||
// and instantiate security token without loading user credentials | ||
return this.securityService.warmupBackendLogin(this._context).then(credentials => { | ||
let dbService = this.dbService; | ||
return null; | ||
} | ||
_awsSdk2.default.config.credentials = credentials; | ||
credentials && dbService.overwriteCredentials(credentials); | ||
/** | ||
* @returns {null|Object} | ||
*/ | ||
this._loggedUserId = this._context.identity.cognitoIdentityId; | ||
}); | ||
}, { | ||
key: 'calleeConfig', | ||
get: function get() { | ||
if (!this._calleeConfig && this._context && this._kernel && this._context.has('invokedFunctionArn')) { | ||
let resource = this._kernel.get('resource'); | ||
let calleeArn = this._context.getOption('invokedFunctionArn'); | ||
this._calleeConfig = resource.getActionConfig(calleeArn); | ||
} | ||
return this._calleeConfig; | ||
} | ||
return Promise.resolve(null); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get DB_ANONYMOUS_PARTITION() { | ||
return 'anonymous'; | ||
} | ||
}, { | ||
key: 'validationSchema', | ||
get: function get() { | ||
return this.calleeConfig ? this.calleeConfig.validationSchema || null : null; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get VALIDATION_SCHEMAS_DIR() { | ||
return '__deep_validation_schemas__'; | ||
} | ||
} | ||
exports.Runtime = Runtime; | ||
/** | ||
* @returns {Request} | ||
*/ | ||
}, { | ||
key: 'request', | ||
get: function get() { | ||
return this._request; | ||
} | ||
/** | ||
* @returns {Object} | ||
*/ | ||
}, { | ||
key: 'securityService', | ||
get: function get() { | ||
return this.kernel.get('security'); | ||
} | ||
/** | ||
* @returns {DB} | ||
*/ | ||
}, { | ||
key: 'dbService', | ||
get: function get() { | ||
return this.kernel.get('db'); | ||
} | ||
/** | ||
* @returns {Object} | ||
*/ | ||
}, { | ||
key: 'logService', | ||
get: function get() { | ||
return this.kernel.get('log'); | ||
} | ||
}], [{ | ||
key: 'DB_ANONYMOUS_PARTITION', | ||
get: function get() { | ||
return 'anonymous'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'VALIDATION_SCHEMAS_DIR', | ||
get: function get() { | ||
return '__deep_validation_schemas__'; | ||
} | ||
}]); | ||
return Runtime; | ||
}(_Interface2.Interface); |
@@ -14,166 +14,234 @@ /** | ||
}); | ||
class Region { | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ANY() { | ||
return '*'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ASIA_PACIFIC_TOKYO() { | ||
return 'ap-northeast-1'; | ||
} | ||
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; }; }(); | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ASIA_PACIFIC_SEOUL() { | ||
return 'ap-northeast-2'; | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ASIA_PACIFIC_SINGAPORE() { | ||
return 'ap-southeast-1'; | ||
let Region = exports.Region = function () { | ||
function Region() { | ||
_classCallCheck(this, Region); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ASIA_PACIFIC_SYDNEY() { | ||
return 'ap-southeast-2'; | ||
} | ||
_createClass(Region, null, [{ | ||
key: 'exists', | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get EU_FRANKFURT() { | ||
return 'eu-central-1'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get EU_IRELAND() { | ||
return 'eu-west-1'; | ||
} | ||
/** | ||
* @param {String} name | ||
* @returns {Boolean} | ||
*/ | ||
value: function exists(name) { | ||
return name === '' || -1 !== Region.list().indexOf(name); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get EU_LONDON() { | ||
return 'eu-west-2'; | ||
} | ||
/** | ||
* @returns {String[]} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get SOUTH_AMERICA_SAO_PAULO() { | ||
return 'sa-east-1'; | ||
} | ||
}, { | ||
key: 'list', | ||
value: function list() { | ||
return [Region.ANY, Region.ASIA_PACIFIC_TOKYO, Region.ASIA_PACIFIC_SEOUL, Region.ASIA_PACIFIC_SYDNEY, Region.ASIA_PACIFIC_SINGAPORE, Region.EU_FRANKFURT, Region.EU_IRELAND, Region.EU_LONDON, Region.SOUTH_AMERICA_SAO_PAULO, Region.US_EAST_N_VIRGINIA, Region.US_EAST_OHIO, Region.US_WEST_N_CALIFORNIA, Region.US_WEST_OREGON, Region.AP_SOUTH_MUMBAI]; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get US_EAST_N_VIRGINIA() { | ||
return 'us-east-1'; | ||
} | ||
/** | ||
* List method alias | ||
* | ||
* @returns {String[]} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get US_EAST_OHIO() { | ||
return 'us-east-2'; | ||
} | ||
}, { | ||
key: 'all', | ||
value: function all() { | ||
return Region.list(); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get US_WEST_N_CALIFORNIA() { | ||
return 'us-west-1'; | ||
} | ||
/** | ||
* @param {string} defaultRegion | ||
* @param {array} availableRegions | ||
* @returns {string} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get US_WEST_OREGON() { | ||
return 'us-west-2'; | ||
} | ||
}, { | ||
key: 'getAppropriateAwsRegion', | ||
value: function getAppropriateAwsRegion(defaultRegion, availableRegions) { | ||
if (availableRegions.indexOf(defaultRegion) !== -1) { | ||
return defaultRegion; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get AP_SOUTH_MUMBAI() { | ||
return 'ap-south-1'; | ||
} | ||
let regionContinent = defaultRegion.split('-')[0]; | ||
/** | ||
* @param {String} name | ||
* @returns {Boolean} | ||
*/ | ||
static exists(name) { | ||
return name === '' || -1 !== Region.list().indexOf(name); | ||
} | ||
for (let regionKey in availableRegions) { | ||
if (!availableRegions.hasOwnProperty(regionKey)) { | ||
continue; | ||
} | ||
/** | ||
* @returns {String[]} | ||
*/ | ||
static list() { | ||
return [Region.ANY, Region.ASIA_PACIFIC_TOKYO, Region.ASIA_PACIFIC_SEOUL, Region.ASIA_PACIFIC_SYDNEY, Region.ASIA_PACIFIC_SINGAPORE, Region.EU_FRANKFURT, Region.EU_IRELAND, Region.EU_LONDON, Region.SOUTH_AMERICA_SAO_PAULO, Region.US_EAST_N_VIRGINIA, Region.US_EAST_OHIO, Region.US_WEST_N_CALIFORNIA, Region.US_WEST_OREGON, Region.AP_SOUTH_MUMBAI]; | ||
} | ||
let region = availableRegions[regionKey]; | ||
/** | ||
* List method alias | ||
* | ||
* @returns {String[]} | ||
*/ | ||
static all() { | ||
return Region.list(); | ||
} | ||
if (region === Region.ANY) { | ||
return defaultRegion; | ||
} | ||
/** | ||
* @param {string} defaultRegion | ||
* @param {array} availableRegions | ||
* @returns {string} | ||
*/ | ||
static getAppropriateAwsRegion(defaultRegion, availableRegions) { | ||
if (availableRegions.indexOf(defaultRegion) !== -1) { | ||
return defaultRegion; | ||
if (region.split('-')[0] === regionContinent) { | ||
return region; | ||
} | ||
} | ||
return availableRegions[0]; // fallback to first available region | ||
} | ||
let regionContinent = defaultRegion.split('-')[0]; | ||
/** | ||
* | ||
* @param {String} region | ||
* @returns {String} | ||
*/ | ||
for (let regionKey in availableRegions) { | ||
if (!availableRegions.hasOwnProperty(regionKey)) { | ||
continue; | ||
} | ||
}, { | ||
key: 'getRegionPrefix', | ||
value: function getRegionPrefix(region) { | ||
let regionsWithDifferentPrefix = [Region.EU_FRANKFURT, Region.ASIA_PACIFIC_SEOUL]; | ||
return regionsWithDifferentPrefix.indexOf(region) !== -1 ? '.' : '-'; | ||
} | ||
}, { | ||
key: 'ANY', | ||
let region = availableRegions[regionKey]; | ||
/** | ||
* @returns {String} | ||
*/ | ||
get: function get() { | ||
return '*'; | ||
} | ||
if (region === Region.ANY) { | ||
return defaultRegion; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
if (region.split('-')[0] === regionContinent) { | ||
return region; | ||
} | ||
}, { | ||
key: 'ASIA_PACIFIC_TOKYO', | ||
get: function get() { | ||
return 'ap-northeast-1'; | ||
} | ||
return availableRegions[0]; // fallback to first available region | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* | ||
* @param {String} region | ||
* @returns {String} | ||
*/ | ||
static getRegionPrefix(region) { | ||
let regionsWithDifferentPrefix = [Region.EU_FRANKFURT, Region.ASIA_PACIFIC_SEOUL]; | ||
return regionsWithDifferentPrefix.indexOf(region) !== -1 ? '.' : '-'; | ||
} | ||
} | ||
exports.Region = Region; | ||
}, { | ||
key: 'ASIA_PACIFIC_SEOUL', | ||
get: function get() { | ||
return 'ap-northeast-2'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'ASIA_PACIFIC_SINGAPORE', | ||
get: function get() { | ||
return 'ap-southeast-1'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'ASIA_PACIFIC_SYDNEY', | ||
get: function get() { | ||
return 'ap-southeast-2'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'EU_FRANKFURT', | ||
get: function get() { | ||
return 'eu-central-1'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'EU_IRELAND', | ||
get: function get() { | ||
return 'eu-west-1'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'EU_LONDON', | ||
get: function get() { | ||
return 'eu-west-2'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'SOUTH_AMERICA_SAO_PAULO', | ||
get: function get() { | ||
return 'sa-east-1'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'US_EAST_N_VIRGINIA', | ||
get: function get() { | ||
return 'us-east-1'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'US_EAST_OHIO', | ||
get: function get() { | ||
return 'us-east-2'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'US_WEST_N_CALIFORNIA', | ||
get: function get() { | ||
return 'us-west-1'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'US_WEST_OREGON', | ||
get: function get() { | ||
return 'us-west-2'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'AP_SOUTH_MUMBAI', | ||
get: function get() { | ||
return 'ap-south-1'; | ||
} | ||
}]); | ||
return Region; | ||
}(); |
@@ -14,201 +14,306 @@ /** | ||
}); | ||
class Service { | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ANY() { | ||
return '*'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get EC2() { | ||
return 'ec2'; | ||
} | ||
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; }; }(); | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get LAMBDA() { | ||
return 'lambda'; | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get SIMPLE_EMAIL_SERVICE() { | ||
return 'ses'; | ||
let Service = exports.Service = function () { | ||
function Service() { | ||
_classCallCheck(this, Service); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get SIMPLE_STORAGE_SERVICE() { | ||
return 's3'; | ||
} | ||
_createClass(Service, null, [{ | ||
key: 'identifier', | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get DYNAMO_DB() { | ||
return 'dynamodb'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get SIMPLE_NOTIFICATION_SERVICE() { | ||
return 'sns'; | ||
} | ||
/** | ||
* @param {String} service | ||
* @returns {String} | ||
*/ | ||
value: function identifier(service) { | ||
return `${service}.amazonaws.com`; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get COGNITO_IDENTITY() { | ||
return 'cognito-identity'; | ||
} | ||
/** | ||
* @param {String} name | ||
* @returns {Boolean} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get COGNITO_IDENTITY_PROVIDER() { | ||
return 'cognito-idp'; | ||
} | ||
}, { | ||
key: 'exists', | ||
value: function exists(name) { | ||
return -1 !== Service.list().indexOf(name); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get COGNITO_SYNC() { | ||
return 'cognito-sync'; | ||
} | ||
/** | ||
* @returns {String[]} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ELASTIC_CACHE() { | ||
return 'elasticache'; | ||
} | ||
}, { | ||
key: 'list', | ||
value: function list() { | ||
return [Service.ANY, Service.LAMBDA, Service.SIMPLE_STORAGE_SERVICE, Service.DYNAMO_DB, Service.SIMPLE_NOTIFICATION_SERVICE, Service.COGNITO_IDENTITY, Service.COGNITO_IDENTITY_PROVIDER, Service.COGNITO_SYNC, Service.ELASTIC_CACHE, Service.IDENTITY_AND_ACCESS_MANAGEMENT, Service.KINESIS, Service.CLOUD_FRONT, Service.SECURITY_TOKEN_SERVICE, Service.CLOUD_WATCH_LOGS, Service.API_GATEWAY, Service.API_GATEWAY_EXECUTE, Service.CLOUD_SEARCH, Service.SIMPLE_QUEUE_SERVICE, Service.CERTIFICATE_MANAGER, Service.EC2, Service.ELASTIC_SEARCH, Service.CLOUD_WATCH_EVENTS, Service.CLOUD_WATCH, Service.SIMPLE_EMAIL_SERVICE, Service.LAMBDA_EDGE, Service.X_RAY]; | ||
} | ||
}, { | ||
key: 'ANY', | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get IDENTITY_AND_ACCESS_MANAGEMENT() { | ||
return 'iam'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
get: function get() { | ||
return '*'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get KINESIS() { | ||
return 'kinesis'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get CLOUD_FRONT() { | ||
return 'cloudfront'; | ||
} | ||
}, { | ||
key: 'EC2', | ||
get: function get() { | ||
return 'ec2'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get CLOUD_SEARCH() { | ||
return 'cloudsearch'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get SECURITY_TOKEN_SERVICE() { | ||
return 'sts'; | ||
} | ||
}, { | ||
key: 'LAMBDA', | ||
get: function get() { | ||
return 'lambda'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get CLOUD_WATCH() { | ||
return 'cloudwatch'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get CLOUD_WATCH_LOGS() { | ||
return 'logs'; | ||
} | ||
}, { | ||
key: 'SIMPLE_EMAIL_SERVICE', | ||
get: function get() { | ||
return 'ses'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get CLOUD_WATCH_EVENTS() { | ||
return 'events'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get API_GATEWAY() { | ||
return 'apigateway'; | ||
} | ||
}, { | ||
key: 'SIMPLE_STORAGE_SERVICE', | ||
get: function get() { | ||
return 's3'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get API_GATEWAY_EXECUTE() { | ||
return 'execute-api'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get SIMPLE_QUEUE_SERVICE() { | ||
return 'sqs'; | ||
} | ||
}, { | ||
key: 'DYNAMO_DB', | ||
get: function get() { | ||
return 'dynamodb'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get CERTIFICATE_MANAGER() { | ||
return 'acm'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get ELASTIC_SEARCH() { | ||
return 'es'; | ||
} | ||
}, { | ||
key: 'SIMPLE_NOTIFICATION_SERVICE', | ||
get: function get() { | ||
return 'sns'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get LAMBDA_EDGE() { | ||
return 'edgelambda'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @param {String} service | ||
* @returns {String} | ||
*/ | ||
static identifier(service) { | ||
return `${service}.amazonaws.com`; | ||
} | ||
}, { | ||
key: 'COGNITO_IDENTITY', | ||
get: function get() { | ||
return 'cognito-identity'; | ||
} | ||
/** | ||
* @param {String} name | ||
* @returns {Boolean} | ||
*/ | ||
static exists(name) { | ||
return -1 !== Service.list().indexOf(name); | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
/** | ||
* @returns {String[]} | ||
*/ | ||
static list() { | ||
return [Service.ANY, Service.LAMBDA, Service.SIMPLE_STORAGE_SERVICE, Service.DYNAMO_DB, Service.SIMPLE_NOTIFICATION_SERVICE, Service.COGNITO_IDENTITY, Service.COGNITO_IDENTITY_PROVIDER, Service.COGNITO_SYNC, Service.ELASTIC_CACHE, Service.IDENTITY_AND_ACCESS_MANAGEMENT, Service.KINESIS, Service.CLOUD_FRONT, Service.SECURITY_TOKEN_SERVICE, Service.CLOUD_WATCH_LOGS, Service.API_GATEWAY, Service.API_GATEWAY_EXECUTE, Service.CLOUD_SEARCH, Service.SIMPLE_QUEUE_SERVICE, Service.CERTIFICATE_MANAGER, Service.EC2, Service.ELASTIC_SEARCH, Service.CLOUD_WATCH_EVENTS, Service.CLOUD_WATCH, Service.SIMPLE_EMAIL_SERVICE, Service.LAMBDA_EDGE]; | ||
} | ||
} | ||
exports.Service = Service; | ||
}, { | ||
key: 'COGNITO_IDENTITY_PROVIDER', | ||
get: function get() { | ||
return 'cognito-idp'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'COGNITO_SYNC', | ||
get: function get() { | ||
return 'cognito-sync'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'ELASTIC_CACHE', | ||
get: function get() { | ||
return 'elasticache'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'IDENTITY_AND_ACCESS_MANAGEMENT', | ||
get: function get() { | ||
return 'iam'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'KINESIS', | ||
get: function get() { | ||
return 'kinesis'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'CLOUD_FRONT', | ||
get: function get() { | ||
return 'cloudfront'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'CLOUD_SEARCH', | ||
get: function get() { | ||
return 'cloudsearch'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'SECURITY_TOKEN_SERVICE', | ||
get: function get() { | ||
return 'sts'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'CLOUD_WATCH', | ||
get: function get() { | ||
return 'cloudwatch'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'CLOUD_WATCH_LOGS', | ||
get: function get() { | ||
return 'logs'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'CLOUD_WATCH_EVENTS', | ||
get: function get() { | ||
return 'events'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'API_GATEWAY', | ||
get: function get() { | ||
return 'apigateway'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'API_GATEWAY_EXECUTE', | ||
get: function get() { | ||
return 'execute-api'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'SIMPLE_QUEUE_SERVICE', | ||
get: function get() { | ||
return 'sqs'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'CERTIFICATE_MANAGER', | ||
get: function get() { | ||
return 'acm'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'ELASTIC_SEARCH', | ||
get: function get() { | ||
return 'es'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'LAMBDA_EDGE', | ||
get: function get() { | ||
return 'edgelambda'; | ||
} | ||
/** | ||
* @returns {String} | ||
*/ | ||
}, { | ||
key: 'X_RAY', | ||
get: function get() { | ||
return 'xray'; | ||
} | ||
}]); | ||
return Service; | ||
}(); |
@@ -8,8 +8,15 @@ 'use strict'; | ||
var _Exception = require('./Exception'); | ||
var _Exception2 = require('./Exception'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Thrown when operation on the database failed | ||
*/ | ||
class DatabaseOperationException extends _Exception.Exception { | ||
let DatabaseOperationException = exports.DatabaseOperationException = function (_Exception) { | ||
_inherits(DatabaseOperationException, _Exception); | ||
@@ -19,6 +26,9 @@ /** | ||
*/ | ||
constructor(error) { | ||
super(`Database operation failed. ${error}`, 500); | ||
function DatabaseOperationException(error) { | ||
_classCallCheck(this, DatabaseOperationException); | ||
return _possibleConstructorReturn(this, (DatabaseOperationException.__proto__ || Object.getPrototypeOf(DatabaseOperationException)).call(this, `Database operation failed. ${error}`, 500)); | ||
} | ||
} | ||
exports.DatabaseOperationException = DatabaseOperationException; | ||
return DatabaseOperationException; | ||
}(_Exception2.Exception); |
@@ -19,2 +19,11 @@ /** | ||
}); | ||
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; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
function Extendable(errorClass) { | ||
@@ -38,28 +47,44 @@ | ||
*/ | ||
class Exception extends Extendable(Error) { | ||
/** | ||
* @returns {String} | ||
*/ | ||
static get CODE_KEY() { | ||
return '_deep_error_code_'; | ||
} | ||
/** | ||
* @returns {Number} | ||
*/ | ||
static get DEFAULT_CODE() { | ||
return 400; | ||
} | ||
let Exception = exports.Exception = function (_Extendable) { | ||
_inherits(Exception, _Extendable); | ||
/** | ||
* @param {String} message | ||
* @param {Number} code | ||
*/ | ||
constructor(message, code = Exception.DEFAULT_CODE) { | ||
super(); | ||
_createClass(Exception, null, [{ | ||
key: 'CODE_KEY', | ||
/** | ||
* @returns {String} | ||
*/ | ||
get: function get() { | ||
return '_deep_error_code_'; | ||
} | ||
/** | ||
* @returns {Number} | ||
*/ | ||
}, { | ||
key: 'DEFAULT_CODE', | ||
get: function get() { | ||
return 400; | ||
} | ||
/** | ||
* @param {String} message | ||
* @param {Number} code | ||
*/ | ||
}]); | ||
function Exception(message) { | ||
let code = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Exception.DEFAULT_CODE; | ||
_classCallCheck(this, Exception); | ||
var _this = _possibleConstructorReturn(this, (Exception.__proto__ || Object.getPrototypeOf(Exception)).call(this)); | ||
if (Error.hasOwnProperty('captureStackTrace')) { | ||
Error.captureStackTrace(this, this.constructor); | ||
Error.captureStackTrace(_this, _this.constructor); | ||
} else { | ||
Object.defineProperty(this, 'stack', { | ||
Object.defineProperty(_this, 'stack', { | ||
value: new Error().stack | ||
@@ -69,3 +94,3 @@ }); | ||
Object.defineProperty(this, 'message', { | ||
Object.defineProperty(_this, 'message', { | ||
value: message | ||
@@ -75,3 +100,4 @@ }); | ||
// It's used to map error codes to API Gateway http status codes | ||
this._code = code; | ||
_this._code = code; | ||
return _this; | ||
} | ||
@@ -82,20 +108,30 @@ | ||
*/ | ||
get name() { | ||
return this.constructor.name; | ||
} | ||
/** | ||
* @param {Number} code | ||
*/ | ||
set code(code) { | ||
this._code = code; | ||
} | ||
/** | ||
* @returns {Number} | ||
*/ | ||
get code() { | ||
return this._code; | ||
} | ||
} | ||
exports.Exception = Exception; | ||
_createClass(Exception, [{ | ||
key: 'name', | ||
get: function get() { | ||
return this.constructor.name; | ||
} | ||
/** | ||
* @param {Number} code | ||
*/ | ||
}, { | ||
key: 'code', | ||
set: function set(code) { | ||
this._code = code; | ||
} | ||
/** | ||
* @returns {Number} | ||
*/ | ||
, | ||
get: function get() { | ||
return this._code; | ||
} | ||
}]); | ||
return Exception; | ||
}(Extendable(Error)); |
@@ -12,8 +12,16 @@ /** | ||
var _Exception = require('./Exception'); | ||
var _Exception2 = require('./Exception'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Thrown when invalid argument provided | ||
*/ | ||
class InvalidArgumentException extends _Exception.Exception { | ||
let InvalidArgumentException = exports.InvalidArgumentException = function (_Exception) { | ||
_inherits(InvalidArgumentException, _Exception); | ||
/** | ||
@@ -23,8 +31,11 @@ * @param {*} argument | ||
*/ | ||
constructor(argument, meantType) { | ||
function InvalidArgumentException(argument, meantType) { | ||
_classCallCheck(this, InvalidArgumentException); | ||
let argumentType = typeof argument; | ||
super(`Invalid argument ${argument} of type ${argumentType} provided (meant ${meantType}).`, 400); | ||
return _possibleConstructorReturn(this, (InvalidArgumentException.__proto__ || Object.getPrototypeOf(InvalidArgumentException)).call(this, `Invalid argument ${argument} of type ${argumentType} provided (meant ${meantType}).`, 400)); | ||
} | ||
} | ||
exports.InvalidArgumentException = InvalidArgumentException; | ||
return InvalidArgumentException; | ||
}(_Exception2.Exception); |
@@ -12,14 +12,24 @@ /** | ||
var _Exception = require('./Exception'); | ||
var _Exception2 = require('./Exception'); | ||
var _InvalidArgumentException = require('./InvalidArgumentException'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Thrown when methods from interface or abstract class are not implemented | ||
*/ | ||
class MethodsNotImplementedException extends _Exception.Exception { | ||
let MethodsNotImplementedException = exports.MethodsNotImplementedException = function (_Exception) { | ||
_inherits(MethodsNotImplementedException, _Exception); | ||
/** | ||
* @param {Array} methods | ||
*/ | ||
constructor(methods) { | ||
function MethodsNotImplementedException(methods) { | ||
_classCallCheck(this, MethodsNotImplementedException); | ||
if (!Array.isArray(methods)) { | ||
@@ -31,5 +41,6 @@ throw new _InvalidArgumentException.InvalidArgumentException(methods, 'Array'); | ||
super(`One or more method are not implemented (${methodPlain}).`, 500); | ||
return _possibleConstructorReturn(this, (MethodsNotImplementedException.__proto__ || Object.getPrototypeOf(MethodsNotImplementedException)).call(this, `One or more method are not implemented (${methodPlain}).`, 500)); | ||
} | ||
} | ||
exports.MethodsNotImplementedException = MethodsNotImplementedException; | ||
return MethodsNotImplementedException; | ||
}(_Exception2.Exception); |
@@ -12,17 +12,30 @@ /** | ||
var _Exception = require('./Exception'); | ||
var _Exception2 = require('./Exception'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
/** | ||
* Thrown when resource not found | ||
*/ | ||
class ResourceNotFoundException extends _Exception.Exception { | ||
let ResourceNotFoundException = exports.ResourceNotFoundException = function (_Exception) { | ||
_inherits(ResourceNotFoundException, _Exception); | ||
/** | ||
* @param {String|Number|null} resourceName | ||
*/ | ||
constructor(resourceName = null) { | ||
function ResourceNotFoundException() { | ||
let resourceName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; | ||
_classCallCheck(this, ResourceNotFoundException); | ||
let message = resourceName ? `Resource "${resourceName}" was not found.` : 'Resource not found.'; | ||
super(message, 404); | ||
return _possibleConstructorReturn(this, (ResourceNotFoundException.__proto__ || Object.getPrototypeOf(ResourceNotFoundException)).call(this, message, 404)); | ||
} | ||
} | ||
exports.ResourceNotFoundException = ResourceNotFoundException; | ||
return ResourceNotFoundException; | ||
}(_Exception2.Exception); |
@@ -17,7 +17,16 @@ /** | ||
}); | ||
class MethodsProxy { | ||
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; }; }(); | ||
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); } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
let MethodsProxy = exports.MethodsProxy = function () { | ||
/** | ||
* @param {Object} target | ||
*/ | ||
constructor(target) { | ||
function MethodsProxy(target) { | ||
_classCallCheck(this, MethodsProxy); | ||
this._target = target; | ||
@@ -30,88 +39,124 @@ this._decorator = null; | ||
*/ | ||
get target() { | ||
return this._target; | ||
} | ||
/** | ||
* @param {Function} decorator | ||
* @returns {MethodsProxy} | ||
*/ | ||
decorate(decorator) { | ||
this._decorator = decorator; | ||
return this; | ||
} | ||
_createClass(MethodsProxy, [{ | ||
key: 'decorate', | ||
/** | ||
* @param {Object} handler | ||
* @param {String|String[]} explMethods | ||
* @returns {Object} | ||
*/ | ||
proxyOverride(handler, ...explMethods) { | ||
let methods = Object.keys(handler).concat(explMethods); | ||
for (let i in methods) { | ||
if (!methods.hasOwnProperty(i)) { | ||
continue; | ||
/** | ||
* @param {Function} decorator | ||
* @returns {MethodsProxy} | ||
*/ | ||
value: function decorate(decorator) { | ||
this._decorator = decorator; | ||
return this; | ||
} | ||
/** | ||
* @param {Object} handler | ||
* @param {String|String[]} explMethods | ||
* @returns {Object} | ||
*/ | ||
}, { | ||
key: 'proxyOverride', | ||
value: function proxyOverride(handler) { | ||
var _this = this; | ||
for (var _len = arguments.length, explMethods = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
explMethods[_key - 1] = arguments[_key]; | ||
} | ||
let prop = methods[i]; | ||
let methods = Object.keys(handler).concat(explMethods); | ||
if (!handler.hasOwnProperty(prop) && explMethods.indexOf(prop) === -1) { | ||
continue; | ||
for (let i in methods) { | ||
if (!methods.hasOwnProperty(i)) { | ||
continue; | ||
} | ||
let prop = methods[i]; | ||
if (!handler.hasOwnProperty(prop) && explMethods.indexOf(prop) === -1) { | ||
continue; | ||
} | ||
if (typeof handler[prop] === 'function') { | ||
Object.defineProperty(this._target, prop, { | ||
value: function value() { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return typeof _this._decorator === 'function' ? _this._decorator.apply(_this, [handler, prop].concat(args)) : handler[prop].apply(handler, args); | ||
} | ||
}); | ||
} | ||
} | ||
if (typeof handler[prop] === 'function') { | ||
Object.defineProperty(this._target, prop, { | ||
value: (...args) => { | ||
return typeof this._decorator === 'function' ? this._decorator(handler, prop, ...args) : handler[prop](...args); | ||
} | ||
}); | ||
} | ||
return this._target; | ||
} | ||
return this._target; | ||
} | ||
/** | ||
* @param {String} handler | ||
* @param {Object[]} explProps | ||
* @returns {Object|*} | ||
*/ | ||
/** | ||
* @param {String} handler | ||
* @param {Object[]} explProps | ||
* @returns {Object|*} | ||
*/ | ||
proxyProperties(handler, ...explProps) { | ||
let propList = Object.keys(handler).concat(explProps); | ||
}, { | ||
key: 'proxyProperties', | ||
value: function proxyProperties(handler) { | ||
for (var _len3 = arguments.length, explProps = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
explProps[_key3 - 1] = arguments[_key3]; | ||
} | ||
for (let prop of propList) { | ||
if (typeof handler[prop] === 'function') { | ||
continue; | ||
let propList = Object.keys(handler).concat(explProps); | ||
for (let prop of propList) { | ||
if (typeof handler[prop] === 'function') { | ||
continue; | ||
} | ||
let descriptor = Object.getOwnPropertyDescriptor(handler, prop); | ||
let targetDescriptor = { | ||
enumerable: descriptor.enumerable, | ||
configurable: descriptor.configurable, | ||
get: () => handler[prop] | ||
}; | ||
if (descriptor.writable) { | ||
targetDescriptor.set = value => handler[prop] = value; | ||
} | ||
Object.defineProperty(this._target, prop, targetDescriptor); | ||
} | ||
let descriptor = Object.getOwnPropertyDescriptor(handler, prop); | ||
let targetDescriptor = { | ||
enumerable: descriptor.enumerable, | ||
configurable: descriptor.configurable, | ||
get: () => handler[prop] | ||
}; | ||
return this._target; | ||
} | ||
if (descriptor.writable) { | ||
targetDescriptor.set = value => handler[prop] = value; | ||
/** | ||
* @param {Object} handler | ||
* @param {String|String[]} explMethods | ||
* @returns {Object} | ||
* | ||
* @todo Replace typeof hook with hasOwnProperty() when get rid of babel | ||
*/ | ||
}, { | ||
key: 'proxy', | ||
value: function proxy(handler) { | ||
for (var _len4 = arguments.length, explMethods = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
explMethods[_key4 - 1] = arguments[_key4]; | ||
} | ||
Object.defineProperty(this._target, prop, targetDescriptor); | ||
return this.proxyOverride.apply(this, [handler].concat(_toConsumableArray(explMethods.filter(prop => typeof this._target[prop] === 'undefined')))); | ||
} | ||
}, { | ||
key: 'target', | ||
get: function get() { | ||
return this._target; | ||
} | ||
}]); | ||
return this._target; | ||
} | ||
/** | ||
* @param {Object} handler | ||
* @param {String|String[]} explMethods | ||
* @returns {Object} | ||
* | ||
* @todo Replace typeof hook with hasOwnProperty() when get rid of babel | ||
*/ | ||
proxy(handler, ...explMethods) { | ||
return this.proxyOverride(handler, ...explMethods.filter(prop => typeof this._target[prop] === 'undefined')); | ||
} | ||
} | ||
exports.MethodsProxy = MethodsProxy; | ||
return MethodsProxy; | ||
}(); |
@@ -14,7 +14,18 @@ /** | ||
}); | ||
class ObjectStorage { | ||
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; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
let ObjectStorage = exports.ObjectStorage = function () { | ||
/** | ||
* @param {Array} objects | ||
*/ | ||
constructor(...objects) { | ||
function ObjectStorage() { | ||
for (var _len = arguments.length, objects = Array(_len), _key = 0; _key < _len; _key++) { | ||
objects[_key] = arguments[_key]; | ||
} | ||
_classCallCheck(this, ObjectStorage); | ||
if (objects.length === 1 && objects[0] instanceof Array) { | ||
@@ -31,36 +42,50 @@ objects = objects[0]; | ||
*/ | ||
add(object) { | ||
this._vector.push(object); | ||
return this; | ||
} | ||
/** | ||
* @param {Function|Object} thing | ||
* @param {Boolean} strict | ||
* @returns {Object|null} | ||
*/ | ||
find(thing, strict = false) { | ||
for (let objectKey in this._vector) { | ||
if (!this._vector.hasOwnProperty(objectKey)) { | ||
continue; | ||
} | ||
_createClass(ObjectStorage, [{ | ||
key: 'add', | ||
value: function add(object) { | ||
this._vector.push(object); | ||
let object = this._vector[objectKey]; | ||
return this; | ||
} | ||
if (strict && object === thing || !strict && object instanceof thing) { | ||
return object; | ||
/** | ||
* @param {Function|Object} thing | ||
* @param {Boolean} strict | ||
* @returns {Object|null} | ||
*/ | ||
}, { | ||
key: 'find', | ||
value: function find(thing) { | ||
let strict = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
for (let objectKey in this._vector) { | ||
if (!this._vector.hasOwnProperty(objectKey)) { | ||
continue; | ||
} | ||
let object = this._vector[objectKey]; | ||
if (strict && object === thing || !strict && object instanceof thing) { | ||
return object; | ||
} | ||
} | ||
return null; | ||
} | ||
return null; | ||
} | ||
/** | ||
* @returns {Array} | ||
*/ | ||
/** | ||
* @returns {Array} | ||
*/ | ||
get iterator() { | ||
return this._vector; | ||
} | ||
} | ||
exports.ObjectStorage = ObjectStorage; | ||
}, { | ||
key: 'iterator', | ||
get: function get() { | ||
return this._vector; | ||
} | ||
}]); | ||
return ObjectStorage; | ||
}(); |
@@ -6,4 +6,9 @@ 'use strict'; | ||
}); | ||
class ObjectVector { | ||
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; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
let ObjectVector = exports.ObjectVector = function () { | ||
/** | ||
@@ -13,7 +18,13 @@ * @param {Function} proto | ||
*/ | ||
constructor(proto, ...instances) { | ||
function ObjectVector(proto) { | ||
_classCallCheck(this, ObjectVector); | ||
this._proto = proto; | ||
this._vector = []; | ||
this.add(...instances); | ||
for (var _len = arguments.length, instances = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
instances[_key - 1] = arguments[_key]; | ||
} | ||
this.add.apply(this, instances); | ||
} | ||
@@ -26,28 +37,41 @@ | ||
*/ | ||
add(...instances) { | ||
for (let i in instances) { | ||
if (!instances.hasOwnProperty(i)) { | ||
continue; | ||
_createClass(ObjectVector, [{ | ||
key: 'add', | ||
value: function add() { | ||
for (var _len2 = arguments.length, instances = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
instances[_key2] = arguments[_key2]; | ||
} | ||
let instance = instances[i]; | ||
for (let i in instances) { | ||
if (!instances.hasOwnProperty(i)) { | ||
continue; | ||
} | ||
if (!(instance instanceof this._proto)) { | ||
throw new Error(`The object ${instance.constructor.name} is not an instance of ${this._proto.name}`); | ||
let instance = instances[i]; | ||
if (!(instance instanceof this._proto)) { | ||
throw new Error(`The object ${instance.constructor.name} is not an instance of ${this._proto.name}`); | ||
} | ||
this._vector.push(instance); | ||
} | ||
this._vector.push(instance); | ||
return this; | ||
} | ||
return this; | ||
} | ||
/** | ||
* Get collection of instances | ||
* @returns {Object[]} | ||
*/ | ||
/** | ||
* Get collection of instances | ||
* @returns {Object[]} | ||
*/ | ||
get collection() { | ||
return this._vector; | ||
} | ||
} | ||
exports.ObjectVector = ObjectVector; | ||
}, { | ||
key: 'collection', | ||
get: function get() { | ||
return this._vector; | ||
} | ||
}]); | ||
return ObjectVector; | ||
}(); |
@@ -12,2 +12,4 @@ /** | ||
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 _path = require('path'); | ||
@@ -19,4 +21,8 @@ | ||
class UniversalRequire { | ||
constructor() { | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
let UniversalRequire = exports.UniversalRequire = function () { | ||
function UniversalRequire() { | ||
_classCallCheck(this, UniversalRequire); | ||
this._require = this._guessRequireFunc(); | ||
@@ -30,38 +36,50 @@ } | ||
*/ | ||
require(module, cb) { | ||
if (UniversalRequire._isFrontend) { | ||
module = _path2.default.normalize(module); // avoid './' or '../' | ||
_createClass(UniversalRequire, [{ | ||
key: 'require', | ||
value: function require(module, cb) { | ||
if (UniversalRequire._isFrontend) { | ||
module = _path2.default.normalize(module); // avoid './' or '../' | ||
} | ||
return this._require(module, cb); | ||
} | ||
return this._require(module, cb); | ||
} | ||
/** | ||
* @returns {Boolean} | ||
* @private | ||
*/ | ||
/** | ||
* @returns {Boolean} | ||
* @private | ||
*/ | ||
static get _isFrontend() { | ||
return typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
} | ||
}, { | ||
key: '_guessRequireFunc', | ||
/** | ||
* @returns {Function} | ||
* @private | ||
*/ | ||
_guessRequireFunc() { | ||
if (!UniversalRequire._isFrontend) { | ||
return (module, cb) => { | ||
try { | ||
cb(null, require(module)); | ||
} catch (e) { | ||
cb(e, null); | ||
} | ||
}; | ||
/** | ||
* @returns {Function} | ||
* @private | ||
*/ | ||
value: function _guessRequireFunc() { | ||
if (!UniversalRequire._isFrontend) { | ||
return (module, cb) => { | ||
try { | ||
cb(null, require(module)); | ||
} catch (e) { | ||
cb(e, null); | ||
} | ||
}; | ||
} | ||
require('./require1k.js'); | ||
return window.__deepRequireBrowser__; | ||
} | ||
}], [{ | ||
key: '_isFrontend', | ||
get: function get() { | ||
return typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
} | ||
}]); | ||
require('./require1k.js'); | ||
return window.__deepRequireBrowser__; | ||
} | ||
} | ||
exports.UniversalRequire = UniversalRequire; | ||
return UniversalRequire; | ||
}(); |
@@ -14,27 +14,44 @@ /** | ||
}); | ||
class Helper { | ||
/** | ||
* @returns {Number[]} | ||
*/ | ||
static get CODES() { | ||
return [200, 400, 401, 403, 404, 406, 409, 500]; | ||
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; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
let Helper = exports.Helper = function () { | ||
function Helper() { | ||
_classCallCheck(this, Helper); | ||
} | ||
/** | ||
* @param {String|Number}code | ||
* @returns {Number} | ||
*/ | ||
static assureDefinedCode(code) { | ||
code = parseInt(code); | ||
_createClass(Helper, null, [{ | ||
key: 'assureDefinedCode', | ||
if (Helper.CODES.indexOf(code) !== -1) { | ||
return code; | ||
/** | ||
* @param {String|Number}code | ||
* @returns {Number} | ||
*/ | ||
value: function assureDefinedCode(code) { | ||
code = parseInt(code); | ||
if (Helper.CODES.indexOf(code) !== -1) { | ||
return code; | ||
} | ||
// fallback to a defined error code | ||
code = parseInt(String(code).charAt(0) + '00'); | ||
return Helper.CODES.indexOf(code) !== -1 ? code : 500; | ||
} | ||
}, { | ||
key: 'CODES', | ||
// fallback to a defined error code | ||
code = parseInt(String(code).charAt(0) + '00'); | ||
/** | ||
* @returns {Number[]} | ||
*/ | ||
get: function get() { | ||
return [200, 400, 401, 403, 404, 406, 409, 500]; | ||
} | ||
}]); | ||
return Helper.CODES.indexOf(code) !== -1 ? code : 500; | ||
} | ||
} | ||
exports.Helper = Helper; | ||
return Helper; | ||
}(); |
@@ -14,30 +14,36 @@ /** | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/** | ||
* Interface implementation | ||
*/ | ||
class Interface { | ||
/** | ||
* @param {String[]|String} abstractMethods | ||
*/ | ||
constructor(...abstractMethods) { | ||
let methods = abstractMethods.length === 1 && abstractMethods[0] instanceof Array ? abstractMethods[0] : abstractMethods; | ||
let Interface = | ||
/** | ||
* @param {String[]|String} abstractMethods | ||
*/ | ||
exports.Interface = function Interface() { | ||
_classCallCheck(this, Interface); | ||
let notImplementedMethods = []; | ||
for (var _len = arguments.length, abstractMethods = Array(_len), _key = 0; _key < _len; _key++) { | ||
abstractMethods[_key] = arguments[_key]; | ||
} | ||
for (let abstractMethodKey in methods) { | ||
if (!methods.hasOwnProperty(abstractMethodKey)) { | ||
continue; | ||
} | ||
let methods = abstractMethods.length === 1 && abstractMethods[0] instanceof Array ? abstractMethods[0] : abstractMethods; | ||
let abstractMethod = methods[abstractMethodKey]; | ||
if (!(this[abstractMethod] instanceof Function)) { | ||
notImplementedMethods.push(abstractMethod); | ||
} | ||
let notImplementedMethods = []; | ||
for (let abstractMethodKey in methods) { | ||
if (!methods.hasOwnProperty(abstractMethodKey)) { | ||
continue; | ||
} | ||
if (notImplementedMethods.length > 0) { | ||
throw new _MethodsNotImplementedException.MethodsNotImplementedException(notImplementedMethods); | ||
let abstractMethod = methods[abstractMethodKey]; | ||
if (!(this[abstractMethod] instanceof Function)) { | ||
notImplementedMethods.push(abstractMethod); | ||
} | ||
} | ||
} | ||
exports.Interface = Interface; | ||
if (notImplementedMethods.length > 0) { | ||
throw new _MethodsNotImplementedException.MethodsNotImplementedException(notImplementedMethods); | ||
} | ||
}; |
@@ -12,2 +12,4 @@ /** | ||
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 _domain = require('domain'); | ||
@@ -23,7 +25,11 @@ | ||
class Sandbox { | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
let Sandbox = exports.Sandbox = function () { | ||
/** | ||
* @param {Function} func | ||
*/ | ||
constructor(func) { | ||
function Sandbox(func) { | ||
_classCallCheck(this, Sandbox); | ||
this._func = func; | ||
@@ -36,65 +42,84 @@ this._onFail = Sandbox.ON_FAIL_CB; | ||
*/ | ||
get func() { | ||
return this._func; | ||
} | ||
/** | ||
* @returns {Sandbox} | ||
*/ | ||
run(...args) { | ||
let execDomain = _domain2.default.create(); | ||
let failCbTriggered = false; | ||
let failCb = error => { | ||
if (failCbTriggered) { | ||
return; | ||
} | ||
_createClass(Sandbox, [{ | ||
key: 'run', | ||
failCbTriggered = true; | ||
/** | ||
* @returns {Sandbox} | ||
*/ | ||
value: function run() { | ||
let execDomain = _domain2.default.create(); | ||
let failCbTriggered = false; | ||
let failCb = error => { | ||
if (failCbTriggered) { | ||
return; | ||
} | ||
failCbTriggered = true; | ||
try { | ||
execDomain.exit(); | ||
} catch (e) {/* silent fail */} | ||
setImmediate(() => { | ||
this._onFail(error); | ||
}); | ||
}; | ||
execDomain.once('error', failCb); | ||
// lambda predefined listeners forces "Process exited ..." error | ||
_process2.default.removeAllListeners('uncaughtException'); | ||
_process2.default.removeAllListeners('unhandledRejection'); | ||
_process2.default.on('uncaughtException', failCb); | ||
_process2.default.on('unhandledRejection', failCb); | ||
try { | ||
execDomain.exit(); | ||
} catch (e) {/* silent fail */} | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
setImmediate(() => { | ||
this._onFail(error); | ||
}); | ||
}; | ||
execDomain.run.apply(execDomain, [this._func].concat(args)); | ||
} catch (error) { | ||
failCb(error); | ||
} | ||
execDomain.once('error', failCb); | ||
return this; | ||
} | ||
// lambda predefined listeners forces "Process exited ..." error | ||
_process2.default.removeAllListeners('uncaughtException'); | ||
_process2.default.removeAllListeners('unhandledRejection'); | ||
_process2.default.on('uncaughtException', failCb); | ||
_process2.default.on('unhandledRejection', failCb); | ||
/** | ||
* @param {Function} cb | ||
* @returns {Sandbox} | ||
*/ | ||
try { | ||
execDomain.run(this._func, ...args); | ||
} catch (error) { | ||
failCb(error); | ||
}, { | ||
key: 'fail', | ||
value: function fail(cb) { | ||
this._onFail = cb; | ||
return this; | ||
} | ||
return this; | ||
} | ||
/** | ||
* @returns {Function} | ||
*/ | ||
/** | ||
* @param {Function} cb | ||
* @returns {Sandbox} | ||
*/ | ||
fail(cb) { | ||
this._onFail = cb; | ||
}, { | ||
key: 'func', | ||
get: function get() { | ||
return this._func; | ||
} | ||
}], [{ | ||
key: 'ON_FAIL_CB', | ||
get: function get() { | ||
return error => { | ||
console.error(error); | ||
}; | ||
} | ||
}]); | ||
return this; | ||
} | ||
/** | ||
* @returns {Function} | ||
*/ | ||
static get ON_FAIL_CB() { | ||
return error => { | ||
console.error(error); | ||
}; | ||
} | ||
} | ||
exports.Sandbox = Sandbox; | ||
return Sandbox; | ||
}(); |
{ | ||
"name": "deep-core", | ||
"version": "1.12.14", | ||
"version": "1.12.15", | ||
"description": "DEEP Core Library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
224982
5834