Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nexus

Package Overview
Dependencies
Maintainers
1
Versions
395
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nexus - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

16

lib/adapters/store.js

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

var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(id, options) {
var snapshot;
var snapshot, ret;
return regeneratorRuntime.wrap(function _callee2$(_context2) {

@@ -148,6 +148,5 @@ while (1) {

case 6:
ret = (0, _cloneDeep2.default)(snapshot);
return _context2.abrupt('return', ret);
snapshot.data = (0, _cloneDeep2.default)(snapshot.data);
return _context2.abrupt('return', snapshot);
case 8:

@@ -184,3 +183,3 @@ case 'end':

var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(id, from, to, options) {
var ops, slice;
var ops, slice, ret;
return regeneratorRuntime.wrap(function _callee3$(_context3) {

@@ -206,6 +205,7 @@ while (1) {

case 6:
slice = (0, _cloneDeep2.default)(ops.slice(from, to));
return _context3.abrupt('return', slice);
slice = ops.slice(from, to);
ret = (0, _cloneDeep2.default)(slice);
return _context3.abrupt('return', ret);
case 8:
case 9:
case 'end':

@@ -212,0 +212,0 @@ return _context3.stop();

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

if (!this.client.connected) return;
if (this.deferreds.operation && !force) return;
if (this.deferreds.submit && !force) return;

@@ -362,0 +362,0 @@ var message = this.inflight || this.queue.shift();

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

server_closed: {
message: 'You must open the Nexus server before you can listen to a transport.',
data: []
},
/**

@@ -35,0 +40,0 @@ * Messages.

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

case 21:
_context.next = 26;
_context.next = 28;
break;

@@ -301,2 +301,5 @@

this.emit('error', _context.t1);
this.server.emit('error', _context.t1);
this.send(_extends({}, message, {

@@ -310,3 +313,3 @@ error: {

case 26:
case 28:
case 'end':

@@ -313,0 +316,0 @@ return _context.stop();

@@ -126,2 +126,3 @@ 'use strict';

_this.subscribed = {};
_this.closed = true;

@@ -143,15 +144,10 @@ pubsub.on('publish', function (id, operation) {

/**
* Initialize a new connection for a `transport` stream with `context`.
*
* @param {Stream} transport
* @param {Object} context
* @return {Connection}
* Open the server's adapters.
*/
_createClass(Server, [{
key: 'listen',
key: 'open',
value: function () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(transport) {
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var server, store, pubsub, connections, connection, id;
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
var store, pubsub;
return regeneratorRuntime.wrap(function _callee$(_context) {

@@ -161,24 +157,13 @@ while (1) {

case 0:
debug('listen');
debug('open');
(0, _checkers.checkTransport)(transport);
server = this;
store = this.store, pubsub = this.pubsub, connections = this.connections;
_context.next = 6;
store = this.store, pubsub = this.pubsub;
_context.next = 4;
return Promise.all([store.open && store.open(), pubsub.open && pubsub.open()]);
case 6:
connection = new _connection2.default({ server: server, transport: transport, context: context });
id = connection.id;
case 4:
this.closed = false;
connections[id] = connection;
connection.once('close', function () {
delete connections[id];
});
return _context.abrupt('return', connection);
case 11:
case 5:
case 'end':

@@ -191,11 +176,11 @@ return _context.stop();

function listen(_x2) {
function open() {
return _ref.apply(this, arguments);
}
return listen;
return open;
}()
/**
* Close the server gracefully.
* Close the server's adapters and any open connections.
*/

@@ -227,2 +212,6 @@

case 5:
this.closed = true;
case 6:
case 'end':

@@ -243,6 +232,74 @@ return _context2.stop();

/**
* Create a connected, in-memory client for the server with `context`.
* Attach the Nexus server to an HTTP `server`, so it will open when the
* server begins listening for connections.
*
* @param {Http.Server} server
*/
}, {
key: 'attach',
value: function attach(server) {
var _this2 = this;
server.on('listen', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.prev = 0;
_context3.next = 3;
return _this2.open();
case 3:
_context3.next = 8;
break;
case 5:
_context3.prev = 5;
_context3.t0 = _context3['catch'](0);
_this2.emit('error', _context3.t0);
case 8:
case 'end':
return _context3.stop();
}
}
}, _callee3, _this2, [[0, 5]]);
})));
server.on('close', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.prev = 0;
_context4.next = 3;
return _this2.close();
case 3:
_context4.next = 8;
break;
case 5:
_context4.prev = 5;
_context4.t0 = _context4['catch'](0);
_this2.emit('error', _context4.t0);
case 8:
case 'end':
return _context4.stop();
}
}
}, _callee4, _this2, [[0, 5]]);
})));
}
/**
* Initialize a new connection for a `transport` stream with `context`.
*
* @param {Stream} transport
* @param {Object} context
* @return {Client}
* @return {Connection}
*/

@@ -253,30 +310,90 @@

value: function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(context) {
var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(transport) {
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var closed, connections, server, connection, onError, id;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
debug('listen');
(0, _checkers.checkTransport)(transport);
closed = this.closed, connections = this.connections;
server = this;
if (!closed) {
_context5.next = 6;
break;
}
throw new _nexusError2.default('server_closed');
case 6:
connection = new _connection2.default({ server: server, transport: transport, context: context });
onError = this.emit.bind(this, 'error');
id = connection.id;
connections[id] = connection;
connection.on('error', onError);
connection.once('close', function () {
connection.removeListener('error', onError);
delete connections[id];
});
case 12:
case 'end':
return _context5.stop();
}
}
}, _callee5, this);
}));
function connect(_x2) {
return _ref5.apply(this, arguments);
}
return connect;
}()
/**
* Create an in-memory client for the server with `context`.
*
* @param {Object} context
* @return {Client}
*/
}, {
key: 'client',
value: function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(context) {
var types, transport, client;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context6.prev = _context6.next) {
case 0:
types = this.types;
transport = new _transport2.default();
_context3.next = 4;
return this.listen(transport.server, context);
_context6.next = 4;
return this.connect(transport.server, context);
case 4:
client = new _client2.default({ types: types, transport: transport.client });
return _context3.abrupt('return', client);
return _context6.abrupt('return', client);
case 6:
case 'end':
return _context3.stop();
return _context6.stop();
}
}
}, _callee3, this);
}, _callee6, this);
}));
function connect(_x4) {
return _ref3.apply(this, arguments);
function client(_x4) {
return _ref6.apply(this, arguments);
}
return connect;
return client;
}()

@@ -296,3 +413,3 @@

value: function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(id, operation) {
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(id, operation) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -302,5 +419,5 @@

return regeneratorRuntime.wrap(function _callee4$(_context4) {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context7.prev = _context7.next) {
case 0:

@@ -313,7 +430,7 @@ debug('submit', { id: id, operation: operation, options: options });

_options$retry = options.retry, retry = _options$retry === undefined ? 0 : _options$retry, context = options.context;
_context4.next = 6;
_context7.next = 6;
return this.findSnapshot(id, { context: context });
case 6:
snapshot = _context4.sent;
snapshot = _context7.sent;

@@ -332,3 +449,3 @@

if (!(operation.version > snapshot.version)) {
_context4.next = 12;
_context7.next = 12;
break;

@@ -341,15 +458,15 @@ }

if (!(operation.version < snapshot.version)) {
_context4.next = 48;
_context7.next = 48;
break;
}
_context4.next = 15;
_context7.next = 15;
return this.listOperations(id, operation.version, snapshot.version, { context: context });
case 15:
existing = _context4.sent;
existing = _context7.sent;
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context4.prev = 19;
_context7.prev = 19;
_iterator = existing[Symbol.iterator]();

@@ -359,3 +476,3 @@

if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context4.next = 34;
_context7.next = 34;
break;

@@ -367,3 +484,3 @@ }

if (!(operation.id === ex.id)) {
_context4.next = 25;
_context7.next = 25;
break;

@@ -376,3 +493,3 @@ }

if (!(operation.version !== ex.version)) {
_context4.next = 27;
_context7.next = 27;
break;

@@ -394,18 +511,18 @@ }

_iteratorNormalCompletion = true;
_context4.next = 21;
_context7.next = 21;
break;
case 34:
_context4.next = 40;
_context7.next = 40;
break;
case 36:
_context4.prev = 36;
_context4.t0 = _context4['catch'](19);
_context7.prev = 36;
_context7.t0 = _context7['catch'](19);
_didIteratorError = true;
_iteratorError = _context4.t0;
_iteratorError = _context7.t0;
case 40:
_context4.prev = 40;
_context4.prev = 41;
_context7.prev = 40;
_context7.prev = 41;

@@ -417,6 +534,6 @@ if (!_iteratorNormalCompletion && _iterator.return) {

case 43:
_context4.prev = 43;
_context7.prev = 43;
if (!_didIteratorError) {
_context4.next = 46;
_context7.next = 46;
break;

@@ -428,10 +545,10 @@ }

case 46:
return _context4.finish(43);
return _context7.finish(43);
case 47:
return _context4.finish(40);
return _context7.finish(40);
case 48:
if (!(operation.version !== snapshot.version)) {
_context4.next = 50;
_context7.next = 50;
break;

@@ -451,10 +568,10 @@ }

// Attempt to commit the resolve operation and snapshot.
_context4.next = 55;
_context7.next = 55;
return this.commit(id, operation, snapshot, { context: context });
case 55:
success = _context4.sent;
success = _context7.sent;
if (success) {
_context4.next = 63;
_context7.next = 63;
break;

@@ -464,3 +581,3 @@ }

if (!(retry <= maxRetries)) {
_context4.next = 62;
_context7.next = 62;
break;

@@ -470,7 +587,7 @@ }

debug('retry', { id: id, operation: operation, options: options });
_context4.next = 61;
_context7.next = 61;
return this.submit(id, operation, _extends({}, options, { retry: retry + 1 }));
case 61:
return _context4.abrupt('return', _context4.sent);
return _context7.abrupt('return', _context7.sent);

@@ -483,14 +600,14 @@ case 62:

this.publish(id, operation, { context: context });
return _context4.abrupt('return', operations);
return _context7.abrupt('return', operations);
case 65:
case 'end':
return _context4.stop();
return _context7.stop();
}
}
}, _callee4, this, [[19, 36, 40, 48], [41,, 43, 47]]);
}, _callee7, this, [[19, 36, 40, 48], [41,, 43, 47]]);
}));
function submit(_x5, _x6) {
return _ref4.apply(this, arguments);
return _ref7.apply(this, arguments);
}

@@ -515,8 +632,8 @@

value: function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(id, operation, snapshot) {
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(id, operation, snapshot) {
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var context, success;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context8.prev = _context8.next) {
case 0:

@@ -529,10 +646,10 @@ debug('commit', { id: id, operation: operation, snapshot: snapshot, options: options });

context = options.context;
_context5.next = 6;
_context8.next = 6;
return this.store.commit(id, operation, snapshot, { context: context });
case 6:
success = _context5.sent;
success = _context8.sent;
if (!(typeof success !== 'boolean')) {
_context5.next = 9;
_context8.next = 9;
break;

@@ -544,14 +661,14 @@ }

case 9:
return _context5.abrupt('return', success);
return _context8.abrupt('return', success);
case 10:
case 'end':
return _context5.stop();
return _context8.stop();
}
}
}, _callee5, this);
}, _callee8, this);
}));
function commit(_x8, _x9, _x10) {
return _ref5.apply(this, arguments);
return _ref8.apply(this, arguments);
}

@@ -572,8 +689,8 @@

value: function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(id) {
var _ref9 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(id) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var context, snapshot;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context9.prev = _context9.next) {
case 0:

@@ -583,22 +700,22 @@ debug('findSnapshot', { id: id, options: options });

context = options.context;
_context6.next = 4;
_context9.next = 4;
return this.store.findSnapshot(id, { context: context });
case 4:
snapshot = _context6.sent;
snapshot = _context9.sent;
(0, _checkers.checkSnapshot)(snapshot);
return _context6.abrupt('return', snapshot);
return _context9.abrupt('return', snapshot);
case 7:
case 'end':
return _context6.stop();
return _context9.stop();
}
}
}, _callee6, this);
}, _callee9, this);
}));
function findSnapshot(_x12) {
return _ref6.apply(this, arguments);
return _ref9.apply(this, arguments);
}

@@ -623,9 +740,9 @@

value: function () {
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(id, from) {
var _ref10 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10(id, from) {
var to = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var context, ops;
return regeneratorRuntime.wrap(function _callee7$(_context7) {
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context10.prev = _context10.next) {
case 0:

@@ -635,7 +752,7 @@ debug('listOperations', { id: id, from: from, to: to, options: options });

context = options.context;
_context7.next = 4;
_context10.next = 4;
return this.store.listOperations(id, from, to, { context: context });
case 4:
ops = _context7.sent;
ops = _context10.sent;

@@ -645,14 +762,14 @@ ops.forEach(function (op) {

});
return _context7.abrupt('return', ops);
return _context10.abrupt('return', ops);
case 7:
case 'end':
return _context7.stop();
return _context10.stop();
}
}
}, _callee7, this);
}, _callee10, this);
}));
function listOperations(_x14, _x15) {
return _ref7.apply(this, arguments);
return _ref10.apply(this, arguments);
}

@@ -676,10 +793,10 @@

value: function () {
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9(id, version) {
var _this2 = this;
var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12(id, version) {
var _this3 = this;
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var context, subs, subscription, uid;
return regeneratorRuntime.wrap(function _callee9$(_context9) {
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) {
switch (_context9.prev = _context9.next) {
switch (_context12.prev = _context12.next) {
case 0:

@@ -696,16 +813,16 @@ debug('subscribe', { id: id, version: version });

subscription._read = function () {};
subscription.once('close', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
subscription.once('close', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() {
var s;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context11.prev = _context11.next) {
case 0:
s = _this2.subscriptions[id];
s = _this3.subscriptions[id];
if (s) {
_context8.next = 3;
_context11.next = 3;
break;
}
return _context8.abrupt('return');
return _context11.abrupt('return');

@@ -716,23 +833,23 @@ case 3:

if (!(0, _isEmpty2.default)(s)) {
_context8.next = 7;
_context11.next = 7;
break;
}
_context8.next = 7;
return _this2.unsubscribe(id, { context: context });
_context11.next = 7;
return _this3.unsubscribe(id, { context: context });
case 7:
case 'end':
return _context8.stop();
return _context11.stop();
}
}
}, _callee8, _this2);
}, _callee11, _this3);
})));
if (this.subscribed[id]) {
_context9.next = 12;
_context12.next = 12;
break;
}
_context9.next = 11;
_context12.next = 11;
return this.pubsub.subscribe(id, { context: context });

@@ -744,14 +861,14 @@

case 12:
return _context9.abrupt('return', subscription);
return _context12.abrupt('return', subscription);
case 13:
case 'end':
return _context9.stop();
return _context12.stop();
}
}
}, _callee9, this);
}, _callee12, this);
}));
function subscribe(_x18, _x19) {
return _ref8.apply(this, arguments);
return _ref11.apply(this, arguments);
}

@@ -772,8 +889,8 @@

value: function () {
var _ref10 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10(id) {
var _ref13 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13(id) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var context;
return regeneratorRuntime.wrap(function _callee10$(_context10) {
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) {
switch (_context10.prev = _context10.next) {
switch (_context13.prev = _context13.next) {
case 0:

@@ -786,3 +903,3 @@ debug('unsubscribe', { id: id });

delete this.subscribed[id];
_context10.next = 6;
_context13.next = 6;
return this.pubsub.unsubscribe(id, { context: context });

@@ -792,10 +909,10 @@

case 'end':
return _context10.stop();
return _context13.stop();
}
}
}, _callee10, this);
}, _callee13, this);
}));
function unsubscribe(_x21) {
return _ref10.apply(this, arguments);
return _ref13.apply(this, arguments);
}

@@ -817,8 +934,8 @@

value: function () {
var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(id, operation) {
var _ref14 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14(id, operation) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var context;
return regeneratorRuntime.wrap(function _callee11$(_context11) {
return regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) {
switch (_context11.prev = _context11.next) {
switch (_context14.prev = _context14.next) {
case 0:

@@ -828,3 +945,3 @@ debug('publish', { id: id, operation: operation });

context = options.context;
_context11.next = 4;
_context14.next = 4;
return this.pubsub.publish(id, operation, { context: context });

@@ -834,10 +951,10 @@

case 'end':
return _context11.stop();
return _context14.stop();
}
}
}, _callee11, this);
}, _callee14, this);
}));
function publish(_x23, _x24) {
return _ref11.apply(this, arguments);
return _ref14.apply(this, arguments);
}

@@ -858,7 +975,7 @@

value: function () {
var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12(id, operation) {
var _ref15 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15(id, operation) {
var subs, key, sub, copy;
return regeneratorRuntime.wrap(function _callee12$(_context12) {
return regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) {
switch (_context12.prev = _context12.next) {
switch (_context15.prev = _context15.next) {
case 0:

@@ -870,7 +987,7 @@ debug('broadcast', { id: id, operation: operation });

if (subs) {
_context12.next = 4;
_context15.next = 4;
break;
}
return _context12.abrupt('return');
return _context15.abrupt('return');

@@ -888,10 +1005,10 @@ case 4:

case 'end':
return _context12.stop();
return _context15.stop();
}
}
}, _callee12, this);
}, _callee15, this);
}));
function broadcast(_x26, _x27) {
return _ref12.apply(this, arguments);
return _ref15.apply(this, arguments);
}

@@ -898,0 +1015,0 @@

{
"name": "nexus",
"version": "0.2.1",
"version": "0.3.0",
"main": "./lib/index.js",
"files": [
"lib"
],
"dependencies": {

@@ -6,0 +9,0 @@ "debug": "^3.1.0",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc