broker-factory
Advanced tools
Comparing version 1.2.11 to 1.2.12
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('babel-runtime/regenerator'), require('tslib'), require('babel-runtime/helpers/defineProperty'), require('babel-runtime/helpers/slicedToArray'), require('fast-unique-numbers')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'babel-runtime/regenerator', 'tslib', 'babel-runtime/helpers/defineProperty', 'babel-runtime/helpers/slicedToArray', 'fast-unique-numbers'], factory) : | ||
(factory((global.brokerFactory = {}),global._regeneratorRuntime,global.tslib_1,global._defineProperty,global._slicedToArray,global.fastUniqueNumbers)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('babel-runtime/regenerator'), require('tslib'), require('babel-runtime/helpers/defineProperty'), require('babel-runtime/helpers/slicedToArray'), require('fast-unique-numbers')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'babel-runtime/regenerator', 'tslib', 'babel-runtime/helpers/defineProperty', 'babel-runtime/helpers/slicedToArray', 'fast-unique-numbers'], factory) : | ||
(factory((global.brokerFactory = {}),global._regeneratorRuntime,global.tslib_1,global._defineProperty,global._slicedToArray,global.fastUniqueNumbers)); | ||
}(this, (function (exports,_regeneratorRuntime,tslib_1,_defineProperty,_slicedToArray,fastUniqueNumbers) { 'use strict'; | ||
_regeneratorRuntime = _regeneratorRuntime && _regeneratorRuntime.hasOwnProperty('default') ? _regeneratorRuntime['default'] : _regeneratorRuntime; | ||
_defineProperty = _defineProperty && _defineProperty.hasOwnProperty('default') ? _defineProperty['default'] : _defineProperty; | ||
_slicedToArray = _slicedToArray && _slicedToArray.hasOwnProperty('default') ? _slicedToArray['default'] : _slicedToArray; | ||
_regeneratorRuntime = _regeneratorRuntime && _regeneratorRuntime.hasOwnProperty('default') ? _regeneratorRuntime['default'] : _regeneratorRuntime; | ||
_defineProperty = _defineProperty && _defineProperty.hasOwnProperty('default') ? _defineProperty['default'] : _defineProperty; | ||
_slicedToArray = _slicedToArray && _slicedToArray.hasOwnProperty('default') ? _slicedToArray['default'] : _slicedToArray; | ||
var PORT_MAP = new WeakMap(); | ||
var PORT_MAP = new WeakMap(); | ||
var _this = undefined; | ||
var extendBrokerImplementation = function extendBrokerImplementation(partialBrokerImplementation) { | ||
// @todo The spread operator can't be used here because TypeScript does not believe that partialBrokerImplementation is an object. | ||
return Object.assign({}, partialBrokerImplementation, { | ||
connect: function connect(_ref) { | ||
var call = _ref.call; | ||
var _this = undefined; | ||
var extendBrokerImplementation = function extendBrokerImplementation(partialBrokerImplementation) { | ||
// @todo The spread operator can't be used here because TypeScript does not believe that partialBrokerImplementation is an object. | ||
return Object.assign({}, partialBrokerImplementation, { | ||
connect: function connect(_ref) { | ||
var call = _ref.call; | ||
return function () { | ||
return tslib_1.__awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var _ref2, port1, port2, portId; | ||
return function () { | ||
return tslib_1.__awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var _ref2, port1, port2, portId; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_ref2 = new MessageChannel(), port1 = _ref2.port1, port2 = _ref2.port2; | ||
_context.next = 3; | ||
return call('connect', { port: port1 }, [port1]); | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_ref2 = new MessageChannel(), port1 = _ref2.port1, port2 = _ref2.port2; | ||
_context.next = 3; | ||
return call('connect', { port: port1 }, [port1]); | ||
case 3: | ||
portId = _context.sent; | ||
case 3: | ||
portId = _context.sent; | ||
PORT_MAP.set(port2, portId); | ||
return _context.abrupt('return', port2); | ||
PORT_MAP.set(port2, portId); | ||
return _context.abrupt('return', port2); | ||
case 6: | ||
case 'end': | ||
return _context.stop(); | ||
case 6: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
}; | ||
}, | ||
disconnect: function disconnect(_ref3) { | ||
var call = _ref3.call; | ||
}, _callee, this); | ||
})); | ||
}; | ||
}, | ||
disconnect: function disconnect(_ref3) { | ||
var call = _ref3.call; | ||
return function (port) { | ||
return tslib_1.__awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
var portId; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
portId = PORT_MAP.get(port); | ||
return function (port) { | ||
return tslib_1.__awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
var portId; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
portId = PORT_MAP.get(port); | ||
if (!(portId === undefined)) { | ||
_context2.next = 3; | ||
break; | ||
} | ||
if (!(portId === undefined)) { | ||
_context2.next = 3; | ||
break; | ||
} | ||
throw new Error('The given port is not connected.'); | ||
throw new Error('The given port is not connected.'); | ||
case 3: | ||
_context2.next = 5; | ||
return call('disconnect', { portId: portId }); | ||
case 3: | ||
_context2.next = 5; | ||
return call('disconnect', { portId: portId }); | ||
case 5: | ||
case 'end': | ||
return _context2.stop(); | ||
case 5: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
}; | ||
}, _callee2, this); | ||
})); | ||
}; | ||
} | ||
}); | ||
}; | ||
var ONGOING_REQUESTS = new WeakMap(); | ||
var createOrGetOngoingRequests = function createOrGetOngoingRequests(sender) { | ||
if (ONGOING_REQUESTS.has(sender)) { | ||
// @todo TypeScript needs to be convinced that has() works as expected. | ||
return ONGOING_REQUESTS.get(sender); | ||
} | ||
}); | ||
}; | ||
var ongoingRequests = new Map(); | ||
ONGOING_REQUESTS.set(sender, ongoingRequests); | ||
return ongoingRequests; | ||
}; | ||
var createBroker = function createBroker(brokerImplementation) { | ||
var fullBrokerImplementation = extendBrokerImplementation(brokerImplementation); | ||
return function (sender) { | ||
var ongoingRequests = createOrGetOngoingRequests(sender); | ||
sender.addEventListener('message', function (_ref) { | ||
var message = _ref.data; | ||
var id = message.id; | ||
var ONGOING_REQUESTS = new WeakMap(); | ||
var createOrGetOngoingRequests = function createOrGetOngoingRequests(sender) { | ||
if (ONGOING_REQUESTS.has(sender)) { | ||
// @todo TypeScript needs to be convinced that has() works as expected. | ||
return ONGOING_REQUESTS.get(sender); | ||
} | ||
var ongoingRequests = new Map(); | ||
ONGOING_REQUESTS.set(sender, ongoingRequests); | ||
return ongoingRequests; | ||
}; | ||
var createBroker = function createBroker(brokerImplementation) { | ||
var fullBrokerImplementation = extendBrokerImplementation(brokerImplementation); | ||
return function (sender) { | ||
var ongoingRequests = createOrGetOngoingRequests(sender); | ||
sender.addEventListener('message', function (_ref) { | ||
var message = _ref.data; | ||
var id = message.id; | ||
if (id !== null && ongoingRequests.has(id)) { | ||
var _ongoingRequests$get = ongoingRequests.get(id), | ||
reject = _ongoingRequests$get.reject, | ||
resolve = _ongoingRequests$get.resolve; | ||
if (id !== null && ongoingRequests.has(id)) { | ||
var _ongoingRequests$get = ongoingRequests.get(id), | ||
reject = _ongoingRequests$get.reject, | ||
resolve = _ongoingRequests$get.resolve; | ||
ongoingRequests.delete(id); | ||
if (message.error === undefined) { | ||
resolve(message.result); | ||
} else { | ||
reject(new Error(message.error.message)); | ||
ongoingRequests.delete(id); | ||
if (message.error === undefined) { | ||
resolve(message.result); | ||
} else { | ||
reject(new Error(message.error.message)); | ||
} | ||
} | ||
} | ||
}); | ||
var call = function call(method, params) { | ||
var transferables = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
return new Promise(function (resolve, reject) { | ||
var id = fastUniqueNumbers.generateUniqueNumber(ongoingRequests); | ||
ongoingRequests.set(id, { reject: reject, resolve: resolve }); | ||
sender.postMessage({ id: id, method: method, params: params }, transferables); | ||
}); | ||
}; | ||
var notify = function notify(method, params) { | ||
var transferables = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
var call = function call(method, params) { | ||
var transferables = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
sender.postMessage({ id: null, method: method, params: params }, transferables); | ||
}; | ||
var functions = {}; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
return new Promise(function (resolve, reject) { | ||
var id = fastUniqueNumbers.generateUniqueNumber(ongoingRequests); | ||
ongoingRequests.set(id, { reject: reject, resolve: resolve }); | ||
sender.postMessage({ id: id, method: method, params: params }, transferables); | ||
}); | ||
}; | ||
var notify = function notify(method, params) { | ||
var transferables = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
try { | ||
for (var _iterator = Object.entries(fullBrokerImplementation)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _step$value = _slicedToArray(_step.value, 2), | ||
key = _step$value[0], | ||
handler = _step$value[1]; | ||
sender.postMessage({ id: null, method: method, params: params }, transferables); | ||
}; | ||
var functions = {}; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
functions = Object.assign({}, functions, _defineProperty({}, key, handler({ call: call, notify: notify }))); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
for (var _iterator = Object.entries(fullBrokerImplementation)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _step$value = _slicedToArray(_step.value, 2), | ||
key = _step$value[0], | ||
handler = _step$value[1]; | ||
functions = Object.assign({}, functions, _defineProperty({}, key, handler({ call: call, notify: notify }))); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
return Object.assign({}, functions); | ||
return Object.assign({}, functions); | ||
}; | ||
}; | ||
}; | ||
exports.createBroker = createBroker; | ||
exports.createBroker = createBroker; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -6,10 +6,17 @@ { | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "cz-conventional-changelog" | ||
} | ||
}, | ||
"dependencies": { | ||
"babel-runtime": "^6.26.0", | ||
"fast-unique-numbers": "^1.1.3", | ||
"fast-unique-numbers": "^1.1.4", | ||
"tslib": "^1.9.0", | ||
"worker-factory": "^2.2.1" | ||
"worker-factory": "^2.2.3" | ||
}, | ||
"description": "A little factory function to create a broker for a JSON-RPC based Web Worker.", | ||
"devDependencies": { | ||
"@commitlint/cli": "^6.1.3", | ||
"@commitlint/config-angular": "^6.1.3", | ||
"babel-core": "^6.26.0", | ||
@@ -20,5 +27,7 @@ "babel-plugin-external-helpers": "^6.22.0", | ||
"chai": "^4.1.2", | ||
"eslint": "^4.18.1", | ||
"eslint-config-holy-grail": "^25.0.0", | ||
"greenkeeper-lockfile": "^1.13.2", | ||
"commitizen": "^2.9.6", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"eslint": "^4.19.0", | ||
"eslint-config-holy-grail": "^26.0.0", | ||
"greenkeeper-lockfile": "^1.14.0", | ||
"grunt": "^1.0.2", | ||
@@ -40,19 +49,19 @@ "grunt-cli": "^1.2.0", | ||
"karma-sinon-chai": "^1.3.3", | ||
"karma-webpack": "^2.0.9", | ||
"karma-webpack": "^2.0.13", | ||
"load-grunt-config": "^0.19.2", | ||
"mocha": "^5.0.1", | ||
"rollup": "^0.56.3", | ||
"mocha": "^5.0.4", | ||
"rollup": "^0.57.1", | ||
"rollup-plugin-babel": "^3.0.3", | ||
"sinon": "^4.4.2", | ||
"sinon-chai": "^2.14.0", | ||
"ts-loader": "^3.5.0", | ||
"tsconfig-holy-grail": "^4.0.0", | ||
"sinon": "^4.4.6", | ||
"sinon-chai": "^3.0.0", | ||
"ts-loader": "^4.1.0", | ||
"tsconfig-holy-grail": "^4.0.1", | ||
"tslint": "^5.9.1", | ||
"tslint-config-holy-grail": "^22.0.6", | ||
"tslint-config-holy-grail": "^23.0.3", | ||
"typescript": "^2.7.2", | ||
"webpack": "^3.11.0" | ||
"webpack": "^4.1.1" | ||
}, | ||
"files": [ | ||
"build/es2015/", | ||
"build/es5/", | ||
"build/es2015/", | ||
"build/esm/", | ||
@@ -71,2 +80,3 @@ "src/" | ||
"scripts": { | ||
"commitmsg": "commitlint --edit --extends @commitlint/config-angular", | ||
"precommit": "grunt lint", | ||
@@ -77,3 +87,3 @@ "prepublishOnly": "grunt build", | ||
"types": "build/es2015/module.d.ts", | ||
"version": "1.2.11" | ||
"version": "1.2.12" | ||
} |
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
36941
41
Updatedfast-unique-numbers@^1.1.4
Updatedworker-factory@^2.2.3