@colony/colony-js-contract-client
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -269,3 +269,3 @@ 'use strict'; | ||
Object.assign(this, (0, _defineProperty3.default)({}, name, new Method((0, _extends3.default)({ functionName: name, client: this }, def)))); | ||
Object.assign(this, (0, _defineProperty3.default)({}, name, new Method((0, _extends3.default)({ name: name, functionName: name, client: this }, def)))); | ||
} | ||
@@ -272,0 +272,0 @@ }, { |
@@ -39,25 +39,6 @@ 'use strict'; | ||
var assertValid = (0, _colonyJsUtils.makeAssert)('Validation failed'); | ||
/** | ||
* Abstract class for interacting with contract methods. | ||
*/ | ||
/* eslint-disable no-underscore-dangle */ | ||
var ContractMethod = function () { | ||
(0, _createClass3.default)(ContractMethod, null, [{ | ||
key: '_validateValue', | ||
value: function _validateValue(value, paramType, paramName) { | ||
var reason = void 0; | ||
var isValid = false; | ||
try { | ||
isValid = (0, _paramTypes.validateValue)(value, paramType); | ||
} catch (error) { | ||
reason = error.message || error.toString(); | ||
} | ||
return assertValid(Boolean(isValid), 'Parameter "' + paramName + '" expected a value of type "' + paramType + '"' + (reason ? ' (' + reason + ')' : '')); | ||
} | ||
}]); | ||
function ContractMethod() { | ||
@@ -67,2 +48,3 @@ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
functionName = _ref.functionName, | ||
name = _ref.name, | ||
input = _ref.input, | ||
@@ -73,5 +55,7 @@ output = _ref.output; | ||
this.name = name; | ||
this.client = client; | ||
this.input = input; | ||
this.functionName = functionName; | ||
this.assertValid = (0, _colonyJsUtils.makeAssert)('Validation failed for ' + name); | ||
if (output) this.output = output; | ||
@@ -187,21 +171,56 @@ } | ||
assertValid((0, _lodash2.default)(input), 'Expected parameters as an object'); | ||
this.assertValid((0, _lodash2.default)(input), 'Expected parameters as an object'); | ||
var inputValues = Object.assign({}, input); | ||
assertValid(Object.getOwnPropertyNames(inputValues).length === this.input.length, 'Mismatching parameters/method parameters sizes'); | ||
var paramNames = this.input.map(function (_ref8) { | ||
var _ref9 = (0, _slicedToArray3.default)(_ref8, 1), | ||
name = _ref9[0]; | ||
return this.input.every(function (_ref8) { | ||
var _ref9 = (0, _slicedToArray3.default)(_ref8, 2), | ||
paramName = _ref9[0], | ||
paramType = _ref9[1]; | ||
return name; | ||
}); | ||
var extraParams = Object.keys(inputValues).filter(function (name) { | ||
return !paramNames.includes(name); | ||
}); | ||
this.assertValid(extraParams.length === 0, 'Unexpected parameters: "' + extraParams.join(', ') + '"'); | ||
return _this.constructor._validateValue(inputValues[paramName], paramType, paramName); | ||
// Either the parameter name should exist in the inputValues, | ||
// or the parameter should have a default value. | ||
var missingParams = this.input.filter(function (param) { | ||
return !(Object.hasOwnProperty.call(inputValues, param[0]) || param.length === 3); | ||
}); | ||
this.assertValid(missingParams.length === 0, 'Missing parameters: "' + missingParams.map(function (_ref10) { | ||
var _ref11 = (0, _slicedToArray3.default)(_ref10, 1), | ||
name = _ref11[0]; | ||
return name; | ||
}).join(', ') + '"'); | ||
return this.input.every(function (param) { | ||
return _this._validateValue(inputValues[param[0]], param); | ||
}); | ||
} | ||
}, { | ||
key: '_validateValue', | ||
value: function _validateValue(value, _ref12) { | ||
var _ref13 = (0, _slicedToArray3.default)(_ref12, 3), | ||
name = _ref13[0], | ||
type = _ref13[1], | ||
defaultValue = _ref13[2]; | ||
var reason = void 0; | ||
var isValid = false; | ||
try { | ||
isValid = (0, _paramTypes.validateValue)(typeof value !== 'undefined' ? value : defaultValue, type); | ||
} catch (error) { | ||
reason = error.message || error.toString(); | ||
} | ||
return this.assertValid(Boolean(isValid), 'Parameter "' + name + '" expected a value of type "' + type + '"' + (reason ? ' (' + reason + ')' : '')); | ||
} | ||
}]); | ||
return ContractMethod; | ||
}(); | ||
/* eslint-disable no-underscore-dangle */ | ||
exports.default = ContractMethod; | ||
//# sourceMappingURL=ContractMethod.js.map |
@@ -63,2 +63,3 @@ 'use strict'; | ||
output = _ref.output, | ||
name = _ref.name, | ||
validateEmpty = _ref.validateEmpty; | ||
@@ -68,3 +69,3 @@ | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (ContractMethodCaller.__proto__ || Object.getPrototypeOf(ContractMethodCaller)).call(this, { client: client, functionName: functionName, input: input, output: output })); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (ContractMethodCaller.__proto__ || Object.getPrototypeOf(ContractMethodCaller)).call(this, { client: client, name: name, functionName: functionName, input: input, output: output })); | ||
@@ -71,0 +72,0 @@ if (validateEmpty) _this._validateEmpty = validateEmpty; |
@@ -69,2 +69,3 @@ 'use strict'; | ||
input = _ref.input, | ||
name = _ref.name, | ||
getRequiredSignees = _ref.getRequiredSignees, | ||
@@ -76,3 +77,3 @@ multisigFunctionName = _ref.multisigFunctionName, | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (ContractMethodMultisigSender.__proto__ || Object.getPrototypeOf(ContractMethodMultisigSender)).call(this, { client: client, output: output, input: input, eventHandlers: eventHandlers, functionName: functionName })); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (ContractMethodMultisigSender.__proto__ || Object.getPrototypeOf(ContractMethodMultisigSender)).call(this, { client: client, name: name, output: output, input: input, eventHandlers: eventHandlers, functionName: functionName })); | ||
@@ -79,0 +80,0 @@ _this._getRequiredSignees = getRequiredSignees; |
@@ -76,7 +76,9 @@ 'use strict'; | ||
convertOutput: function convertOutput(value) { | ||
var converted = Number((0, _colonyJsUtils.isBigNumber)(value) ? value.toNumber() : value); | ||
var converted = parseInt((0, _colonyJsUtils.isBigNumber)(value) ? value.toNumber() : value, 10); | ||
// Recreate the date by adding milliseconds to the timestamp | ||
return converted > 0 ? new Date(converted * 1000) : null; | ||
}, | ||
convertInput: function convertInput(value) { | ||
return value.getTime() / 1000; | ||
// Dates are stored as timestamps without milliseconds | ||
return parseInt(value.setMilliseconds(0) / 1000, 10); | ||
} | ||
@@ -83,0 +85,0 @@ }, |
{ | ||
"name": "@colony/colony-js-contract-client", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Method-like interface for Smart Contracts", | ||
@@ -20,3 +20,2 @@ "main": "lib/index.js", | ||
"precommit": "lint-staged", | ||
"prepublish": "yarn run precommit && yarn run build", | ||
"test": "yarn run lint && yarn run test:unit", | ||
@@ -40,5 +39,2 @@ "test:unit": "jest --coverage --config=jest.conf.json" | ||
"devDependencies": { | ||
"babel-plugin-dynamic-import-node": "^1.2.0", | ||
"babel-plugin-syntax-dynamic-import": "^6.18.0", | ||
"babel-plugin-transform-class-properties": "^6.24.1", | ||
"flow-bin": "^0.72.0", | ||
@@ -50,5 +46,5 @@ "jest-sandbox": "^1.1.2", | ||
"dependencies": { | ||
"@colony/colony-js-adapter": "^1.2.0", | ||
"@colony/colony-js-contract-loader": "^1.2.0", | ||
"@colony/colony-js-utils": "^1.2.0", | ||
"@colony/colony-js-adapter": "^1.2.1", | ||
"@colony/colony-js-contract-loader": "^1.2.1", | ||
"@colony/colony-js-utils": "^1.2.1", | ||
"babel-runtime": "^6.26.0", | ||
@@ -63,5 +59,5 @@ "bn.js": "^4.11.6", | ||
"engines": { | ||
"node": ">=8.6.0", | ||
"node": ">=8.2.1", | ||
"yarn": ">=1.3.2" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1075715
4
5649