UNPKG

cabbie-sync

Version:
230 lines (159 loc) 7.65 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeOutsConfig = exports.TimeoutValue = undefined; var _stringify = require('babel-runtime/core-js/json/stringify'); var _stringify2 = _interopRequireDefault(_stringify); var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); var _inherits2 = require('babel-runtime/helpers/inherits'); var _inherits3 = _interopRequireDefault(_inherits2); var _timeOutTypes = require('./enums/time-out-types'); var _timeOutTypes2 = _interopRequireDefault(_timeOutTypes); var _driver = require('./driver'); var _driver2 = _interopRequireDefault(_driver); var _addDebugging = require('./add-debugging'); var _addDebugging2 = _interopRequireDefault(_addDebugging); var _ms = require('ms'); var _ms2 = _interopRequireDefault(_ms); var _baseClass = require('./base-class'); var _baseClass2 = _interopRequireDefault(_baseClass); var _flowRuntime = require('flow-runtime'); var _flowRuntime2 = _interopRequireDefault(_flowRuntime); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var Driver = _flowRuntime2.default.tdz(function () { return _driver2.default; }); /** * * This file is generated automatically, run npm run build to re-generate. **/ var TimeOutType = _flowRuntime2.default.tdz(function () { return _timeOutTypes.TimeOutType; }); var TimeoutValue = exports.TimeoutValue = _flowRuntime2.default.type('TimeoutValue', _flowRuntime2.default.union(_flowRuntime2.default.number(), _flowRuntime2.default.string())); var TimeOutsConfig = exports.TimeOutsConfig = _flowRuntime2.default.type('TimeOutsConfig', _flowRuntime2.default.object(_flowRuntime2.default.property('script', _flowRuntime2.default.union(TimeoutValue, TimeoutValue, TimeoutValue, TimeoutValue), true))); /* * Managing time-out */ var TimeOut = function (_BaseClass) { (0, _inherits3.default)(TimeOut, _BaseClass); function TimeOut(driver /*: Driver*/) { (0, _classCallCheck3.default)(this, TimeOut); var _driverType = _flowRuntime2.default.ref(Driver); _flowRuntime2.default.param('driver', _driverType).assert(driver); return (0, _possibleConstructorReturn3.default)(this, (TimeOut.__proto__ || (0, _getPrototypeOf2.default)(TimeOut)).call(this, driver, '/timeouts')); } /* * Set a time-out */ (0, _createClass3.default)(TimeOut, [{ key: 'setTimeOut', value: function setTimeOut(timeOutType /*: TimeOutType*/, ms /*: TimeoutValue*/) /*: void*/ { var _timeOutTypeType = _flowRuntime2.default.ref(TimeOutType); var _msType = TimeoutValue; var _returnType = _flowRuntime2.default.return(_flowRuntime2.default.void()); _flowRuntime2.default.param('timeOutType', _timeOutTypeType).assert(timeOutType); _flowRuntime2.default.param('ms', _msType).assert(ms); switch (timeOutType) { case _timeOutTypes2.default.SCRIPT: this.setScriptTimeOut(ms); break; case _timeOutTypes2.default.ASYNC_SCRIPT: this.setAsyncScriptTimeOut(ms); break; case _timeOutTypes2.default.PAGE_LOAD: this.setPageLoadTimeOut(ms); break; case _timeOutTypes2.default.IMPLICIT: this.setImplicitTimeOut(ms); break; default: throw new Error('Invalid timeout type ' + (0, _stringify2.default)(timeOutType) + ', expected "script", "page load", "implicit" or "async"'); } } /* * Set multiple time-outs at once */ }, { key: 'setTimeOuts', value: function setTimeOuts(timeOuts /*: TimeOutsConfig*/) /*: void*/ { var _timeOutsType = TimeOutsConfig; var _returnType2 = _flowRuntime2.default.return(_flowRuntime2.default.void()); _flowRuntime2.default.param('timeOuts', _timeOutsType).assert(timeOuts); if (timeOuts['script'] != null) { this.setTimeOut('script', timeOuts['script']); } if (timeOuts['implicit'] != null) { this.setTimeOut('implicit', timeOuts['implicit']); } if (timeOuts['async'] != null) { this.setTimeOut('async', timeOuts['async']); } if (timeOuts['page load'] != null) { this.setTimeOut('page load', timeOuts['page load']); } } /* * Set the amount of time, in milliseconds, that scripts are permitted * to run before they are aborted and a "Timeout" error is returned to the client. */ }, { key: 'setScriptTimeOut', value: function setScriptTimeOut(timeout /*: TimeoutValue*/) /*: void*/ { var _timeoutType = TimeoutValue; var _returnType3 = _flowRuntime2.default.return(_flowRuntime2.default.void()); _flowRuntime2.default.param('timeout', _timeoutType).assert(timeout); timeout = _timeoutType.assert((0, _ms2.default)(timeout.toString())); this.requestJSON('POST', '', { type: _timeOutTypes2.default.SCRIPT, ms: timeout }); } /* * Set the amount of time, in milliseconds, that asynchronous scripts are permitted * to run before they are aborted and a "Timeout" error is returned to the client. */ }, { key: 'setAsyncScriptTimeOut', value: function setAsyncScriptTimeOut(timeout /*: TimeoutValue*/) /*: void*/ { var _timeoutType2 = TimeoutValue; var _returnType4 = _flowRuntime2.default.return(_flowRuntime2.default.void()); _flowRuntime2.default.param('timeout', _timeoutType2).assert(timeout); timeout = _timeoutType2.assert((0, _ms2.default)(timeout.toString())); this.requestJSON('POST', '/async_script', { ms: timeout }); } /* * Set the amount of time, in milliseconds, that a page is permitted to be loaded * before they it is aborted and a "Timeout" error is returned to the client. */ }, { key: 'setPageLoadTimeOut', value: function setPageLoadTimeOut(timeout /*: TimeoutValue*/) /*: void*/ { var _timeoutType3 = TimeoutValue; var _returnType5 = _flowRuntime2.default.return(_flowRuntime2.default.void()); _flowRuntime2.default.param('timeout', _timeoutType3).assert(timeout); timeout = _timeoutType3.assert((0, _ms2.default)(timeout.toString())); this.requestJSON('POST', '', { type: _timeOutTypes2.default.PAGE_LOAD, ms: timeout }); } /* * Set the amount of time, in milliseconds, that scripts executed are permitted * to run before they are aborted and a "Timeout" error is returned to the client. */ }, { key: 'setImplicitTimeOut', value: function setImplicitTimeOut(timeout /*: TimeoutValue*/) /*: void*/ { var _timeoutType4 = TimeoutValue; var _returnType6 = _flowRuntime2.default.return(_flowRuntime2.default.void()); _flowRuntime2.default.param('timeout', _timeoutType4).assert(timeout); timeout = _timeoutType4.assert((0, _ms2.default)(timeout.toString())); this.requestJSON('POST', '', { type: _timeOutTypes2.default.IMPLICIT, ms: timeout }); } }]); return TimeOut; }(_baseClass2.default); (0, _addDebugging2.default)(TimeOut); exports.default = TimeOut;