New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

marsdb-sync-server

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marsdb-sync-server - npm Package Compare versions

Comparing version 0.0.4 to 0.0.6

.tern-project

32

dist/CollectionManager.js

@@ -34,2 +34,4 @@ 'use strict';

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"); } }

@@ -65,5 +67,6 @@

_definedCollections[modelName] = 1;
(0, _MethodCallManager.method)('/' + modelName + '/insert', (0, _bind3.default)(manager._remoteInsert, manager), { noAnswer: true });
(0, _MethodCallManager.method)('/' + modelName + '/update', (0, _bind3.default)(manager._remoteUpdate, manager), { noAnswer: true });
(0, _MethodCallManager.method)('/' + modelName + '/remove', (0, _bind3.default)(manager._remoteRemove, manager), { noAnswer: true });
(0, _MethodCallManager.method)('/' + modelName + '/insert', (0, _bind3.default)(manager._remoteInsert, manager));
(0, _MethodCallManager.method)('/' + modelName + '/update', (0, _bind3.default)(manager._remoteUpdate, manager));
(0, _MethodCallManager.method)('/' + modelName + '/remove', (0, _bind3.default)(manager._remoteRemove, manager));
(0, _MethodCallManager.method)('/' + modelName + '/sync', (0, _bind3.default)(manager._remoteSync, manager));
}

@@ -104,3 +107,3 @@

key: '_remoteInsert',
value: function _remoteInsert(_ref, doc) {
value: function _remoteInsert(_ref, doc, options) {
var randomSeed = _ref.randomSeed;

@@ -112,7 +115,7 @@ var connection = _ref.connection;

}
return this.db.insert(doc);
return this.db.insert(doc, options);
}
}, {
key: '_remoteUpdate',
value: function _remoteUpdate(_ref2, query, modifier) {
value: function _remoteUpdate(_ref2, query, modifier, options) {
var randomSeed = _ref2.randomSeed;

@@ -122,10 +125,21 @@ var connection = _ref2.connection;

this._ensureDocumentId(modifier, connection, randomSeed);
return this.db.update(query, modifier);
return this.db.update(query, modifier, options);
}
}, {
key: '_remoteRemove',
value: function _remoteRemove(ctx, query) {
return this.db.remove(query);
value: function _remoteRemove(ctx, query, options) {
return this.db.remove(query, options);
}
}, {
key: '_remoteSync',
value: function _remoteSync(ctx, remoteIds) {
return this.db.ids({ _id: { $in: remoteIds } }).then(function (dbIds) {
remoteIds = new Set(remoteIds);
(0, _forEach2.default)(dbIds, function (id) {
return remoteIds.delete(id);
});
return [].concat(_toConsumableArray(remoteIds));
});
}
}, {
key: '_ensureDocumentId',

@@ -132,0 +146,0 @@ value: function _ensureDocumentId(doc, connection, randomSeed) {

@@ -47,2 +47,6 @@ 'use strict';

// Internals
var HEARTBEAT_INTERVAL = 15000;
var HEARTBEAT_TIMEOUT = 15000;
/**

@@ -68,3 +72,3 @@ * WebSocket connection wrapper, that handles incoming messages

_this._sessionId = null;
_this._heartbeat = new _HeartbeatManager2.default();
_this._heartbeat = new _HeartbeatManager2.default(HEARTBEAT_INTERVAL, HEARTBEAT_TIMEOUT);

@@ -194,10 +198,6 @@ _this._heartbeat.on('timeout', (0, _bind3.default)(_this._handleHearbeatTimeout, _this));

return this._queue.add(function () {
var res = (0, _try3.default)(function () {
var msgObj = _marsdb.EJSON.parse(rawMsg);
return _this3._processMessage(msgObj);
});
if (res instanceof Error) {
return _this3._handleProcessingError(res);
}
return res;
var msgObj = _marsdb.EJSON.parse(rawMsg);
return _this3._processMessage(msgObj);
}).then(null, function (err) {
return _this3._handleProcessingError(err);
});

@@ -208,2 +208,3 @@ }

value: function _handleProcessingError(err) {
this.emit('error', err);
this._sendMessage({

@@ -210,0 +211,0 @@ msg: 'error',

@@ -37,2 +37,6 @@ 'use strict';

var _ErrorManager = require('./ErrorManager');
var _ErrorManager2 = _interopRequireDefault(_ErrorManager);
var _CollectionManager = require('./CollectionManager');

@@ -55,7 +59,8 @@

var ddpConn = new _DDPConnection2.default(connection);
ddpConn.methodsManager = new _MethodCallManager2.default(ddpConn);
ddpConn.subManager = new _SubscriptionManager2.default(ddpConn);
ddpConn.customManagers = (0, _map3.default)(_customManagers, function (m) {
return new m(ddpConn);
});
ddpConn.methodsManager = new _MethodCallManager2.default(ddpConn);
ddpConn.subManager = new _SubscriptionManager2.default(ddpConn);
ddpConn.errorManager = new _ErrorManager2.default(ddpConn);
return ddpConn;

@@ -62,0 +67,0 @@ }

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

if (callResult instanceof Error) {
this._ddpConn.emit('error', { error: callResult, method: method, params: params, id: id });
this._handleProcessingError(id, callResult);

@@ -110,0 +111,0 @@ return Promise.resolve();

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

if (callResult instanceof Error) {
this._ddpConn.emit('error', { error: callResult, name: name, params: params, id: id });
this._ddpConn.sendNoSub(id, callResult);

@@ -284,0 +285,0 @@ return Promise.resolve();

@@ -36,5 +36,6 @@ import _check from 'check-types';

_definedCollections[modelName] = 1;
method(`/${modelName}/insert`, _bind(manager._remoteInsert, manager), { noAnswer: true });
method(`/${modelName}/update`, _bind(manager._remoteUpdate, manager), { noAnswer: true });
method(`/${modelName}/remove`, _bind(manager._remoteRemove, manager), { noAnswer: true });
method(`/${modelName}/insert`, _bind(manager._remoteInsert, manager));
method(`/${modelName}/update`, _bind(manager._remoteUpdate, manager));
method(`/${modelName}/remove`, _bind(manager._remoteRemove, manager));
method(`/${modelName}/sync`, _bind(manager._remoteSync, manager));
}

@@ -60,3 +61,3 @@

_remoteInsert({ randomSeed, connection }, doc) {
_remoteInsert({ randomSeed, connection }, doc, options) {
if (this._ensureDocumentId(doc, connection, randomSeed)) {

@@ -67,14 +68,22 @@ connection.subManager._handleAcceptedRemoteInsert(

}
return this.db.insert(doc);
return this.db.insert(doc, options);
}
_remoteUpdate({ randomSeed, connection }, query, modifier) {
_remoteUpdate({ randomSeed, connection }, query, modifier, options) {
this._ensureDocumentId(modifier, connection, randomSeed);
return this.db.update(query, modifier);
return this.db.update(query, modifier, options);
}
_remoteRemove(ctx, query) {
return this.db.remove(query);
_remoteRemove(ctx, query, options) {
return this.db.remove(query, options);
}
_remoteSync(ctx, remoteIds) {
return this.db.ids({_id: {$in: remoteIds}}).then((dbIds) => {
remoteIds = new Set(remoteIds);
_each(dbIds, id => remoteIds.delete(id));
return [...remoteIds];
});
}
_ensureDocumentId(doc, connection, randomSeed) {

@@ -81,0 +90,0 @@ if (doc._id) {

@@ -11,2 +11,6 @@ import _check from 'check-types';

// Internals
const HEARTBEAT_INTERVAL = 15000;
const HEARTBEAT_TIMEOUT = 15000;
/**

@@ -26,3 +30,5 @@ * WebSocket connection wrapper, that handles incoming messages

this._sessionId = null;
this._heartbeat = new HeartbeatManager();
this._heartbeat = new HeartbeatManager(
HEARTBEAT_INTERVAL, HEARTBEAT_TIMEOUT
);

@@ -131,14 +137,11 @@ this._heartbeat.on('timeout', _bind(this._handleHearbeatTimeout, this));

return this._queue.add(() => {
const res = _try(() => {
const msgObj = EJSON.parse(rawMsg);
return this._processMessage(msgObj);
});
if (res instanceof Error) {
return this._handleProcessingError(res);
}
return res;
});
const msgObj = EJSON.parse(rawMsg);
return this._processMessage(msgObj);
}).then(null, err =>
this._handleProcessingError(err)
);
}
_handleProcessingError(err) {
this.emit('error', err);
this._sendMessage({

@@ -145,0 +148,0 @@ msg: 'error',

@@ -8,2 +8,3 @@ import _map from 'fast.js/map';

import SubscriptionManager from './SubscriptionManager';
import ErrorManager from './ErrorManager';
import { createCollectionManager } from './CollectionManager';

@@ -25,5 +26,6 @@

const ddpConn = new DDPConnection(connection);
ddpConn.customManagers = _map(_customManagers, (m) => new m(ddpConn));
ddpConn.methodsManager = new MethodCallManager(ddpConn);
ddpConn.subManager = new SubscriptionManager(ddpConn);
ddpConn.customManagers = _map(_customManagers, (m) => new m(ddpConn));
ddpConn.errorManager = new ErrorManager(ddpConn);
return ddpConn;

@@ -30,0 +32,0 @@ }

@@ -73,2 +73,3 @@ import _check from 'check-types';

if (callResult instanceof Error) {
this._ddpConn.emit('error', {error: callResult, method, params, id});
this._handleProcessingError(id, callResult);

@@ -75,0 +76,0 @@ return Promise.resolve();

@@ -217,2 +217,3 @@ import _check from 'check-types';

if (callResult instanceof Error) {
this._ddpConn.emit('error', {error: callResult, name, params, id});
this._ddpConn.sendNoSub(id, callResult);

@@ -219,0 +220,0 @@ return Promise.resolve();

{
"name": "marsdb-sync-server",
"version": "0.0.4",
"version": "0.0.6",
"author": {

@@ -36,3 +36,3 @@ "name": "Artem Artemev",

"invariant": "^2.2.0",
"marsdb": "^0.5.14",
"marsdb": "^0.5.21",
"ws": "^1.0.1"

@@ -71,4 +71,4 @@ },

"test": "mocha --require babelhook --reporter spec --timeout 1000 test/both test/node",
"coverage": "./node_modules/.bin/babel-node ./node_modules/istanbul/lib/cli cover _mocha test/both test/node -- -u exports -R spec && open coverage/lcov-report/index.html",
"coveralls": "./node_modules/.bin/babel-node ./node_modules/istanbul/lib/cli cover _mocha test/both test/node --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js ./lib && rm -rf ./coverage"
"coverage": "./node_modules/.bin/babel-node ./node_modules/istanbul/lib/cli cover _mocha test/both test/node -- -u exports -R spec --require babelhook && open coverage/lcov-report/index.html",
"coveralls": "./node_modules/.bin/babel-node ./node_modules/istanbul/lib/cli cover _mocha test/both test/node --report lcovonly -- -R spec --require babelhook && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js ./lib && rm -rf ./coverage"
},

@@ -75,0 +75,0 @@ "main": "index.js",

@@ -6,3 +6,3 @@ [MarsDB DDP Server](https://github.com/c58/marsdb-sync-server)

[![npm version](https://badge.fury.io/js/marsdb-sync-server.svg)](https://www.npmjs.com/package/marsdb-sync-server)
[![Coverage Status](https://coveralls.io/repos/c58/marsdb-sync-server/badge.svg?branch=master&service=github)](https://coveralls.io/github/c58/marsdb-sync-server?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/c58/marsdb-sync-server/badge.svg?branch=master)](https://coveralls.io/github/c58/marsdb-sync-server?branch=master)
[![Dependency Status](https://david-dm.org/c58/marsdb-sync-server.svg)](https://david-dm.org/c58/marsdb-sync-server)

@@ -9,0 +9,0 @@

@@ -104,2 +104,27 @@ import MethodCallManager, { _cleanMethods } from '../../lib/MethodCallManager';

});
it('should accpet options for upserting and muktiple updates', function () {
const connMock = {
on: sinon.spy(),
sendResult: sinon.spy(),
sendUpdated: sinon.spy(),
subManager: { whenAllCursorsUpdated: () => Promise.resolve() },
};
const coll = new Collection('test');
const manager = new MethodCallManager(connMock);
const handler = connMock.on.getCall(0).args[1];
return coll.insertAll([{a: 1}, {a: 2}]).then(() => {
return handler({
method: '/test/update',
params: [{}, {$set: {a: 3}}, {multi: true}]
});
}).then((res) => {
return coll.find();
}).then((res) => {
res.should.have.length(2);
res[0].a.should.be.equal(3);
res[1].a.should.be.equal(3);
});
});
});

@@ -130,4 +155,50 @@

});
it('should accept options for multiple removing', function () {
const connMock = {
on: sinon.spy(),
sendResult: sinon.spy(),
sendUpdated: sinon.spy(),
subManager: { whenAllCursorsUpdated: () => Promise.resolve() },
};
const coll = new Collection('test');
const manager = new MethodCallManager(connMock);
const handler = connMock.on.getCall(0).args[1];
return coll.insertAll([{a: 1}, {a: 2}]).then(() => {
return handler({
method: '/test/remove',
params: [{}, {multi: true}]
});
}).then((res) => {
return coll.find({});
}).then((res) => {
res.should.have.length(0);
});
});
});
describe('#_removeSync', function () {
it('should return a list of removed ids in db', function () {
const connMock = {
on: sinon.spy(),
sendResult: sinon.spy(),
sendUpdated: sinon.spy(),
subManager: { whenAllCursorsUpdated: () => Promise.resolve() },
};
const coll = new Collection('test');
const manager = new MethodCallManager(connMock);
const handler = connMock.on.getCall(0).args[1];
return coll.insertAll([{_id: 1}, {_id: 2}]).then(() => {
return handler({
method: '/test/sync',
params: [[1,2,3]]
});
}).then((res) => {
res.should.be.deep.equal([3]);
})
});
});
describe('#_ensureDocumentId', function () {

@@ -134,0 +205,0 @@ it('should ignore ensuring if no id or no seed provided', function () {

@@ -231,25 +231,23 @@ import DDPConnection from '../../lib/DDPConnection';

it('should return a promise that resolved when message processed', function () {
conn._processMessage = () => conn._sendMessage();
conn._processMessage = sinon.spy(() => Promise.resolve());
const p = conn._handleRawMessage(EJSON.stringify('{"msg": "ping", "id": "123"}'));
const p1 = conn._handleRawMessage(EJSON.stringify('{"msg": "ping", "id": "123"}'));
const p2 = conn._handleRawMessage(EJSON.stringify('{"msg": "ping", "id": "123"}'));
conn._sendMessage.should.have.callCount(1);
return p.then(() => {
conn._sendMessage.should.have.callCount(2);
return p1;
}).then(() => {
conn._sendMessage.should.have.callCount(3);
return p2;
}).then(() => {
conn._sendMessage.should.have.callCount(3);
})
conn._processMessage.should.have.callCount(0);
return Promise.resolve().then(() => {
conn._processMessage.should.have.callCount(1);
return p1.then(() => {
conn._processMessage.should.have.callCount(3);
})
});
});
it('should send an error message if error rised while proccessing', function () {
conn._handleRawMessage('{"a": 1');
conn._sendMessage.getCall(0).args[0].msg.should.be.equals('error');
return conn._handleRawMessage('{"msg": "unknown_type"}').then(() => {
conn._sendMessage.getCall(1).args[0].msg.should.be.equals('error');
conn._sendMessage.should.have.callCount(2);
});
return conn._handleRawMessage('{"a": 1').then(() => {
conn._sendMessage.getCall(0).args[0].msg.should.be.equals('error');
return conn._handleRawMessage('{"msg": "unknown_type"}').then(() => {
conn._sendMessage.getCall(1).args[0].msg.should.be.equals('error');
conn._sendMessage.should.have.callCount(2);
})
});
});

@@ -256,0 +254,0 @@ });

@@ -26,2 +26,10 @@ import HeartbeatManager from '../../lib/HeartbeatManager';

describe('#consturctor', function () {
it('should set default wait time', function () {
const newhb = new HeartbeatManager();
expect(newhb.pingTimeout).to.be.gt(0);
expect(newhb.pongTimeout).to.be.gt(0);
});
});
describe('#waitPing', function () {

@@ -28,0 +36,0 @@ it('should wait ping message and send ping on timeout', function () {

@@ -42,2 +42,3 @@ import MethodCallManager, { method, _cleanMethods } from '../../lib/MethodCallManager';

sendUpdated: sinon.spy(),
emit: sinon.spy(),
subManager: { whenAllCursorsUpdated: () => Promise.resolve() },

@@ -82,2 +83,3 @@ };

on: sinon.spy(),
emit: sinon.spy(),
subManager: { whenAllCursorsUpdated: () => Promise.resolve() }

@@ -156,2 +158,3 @@ };

sendUpdated: sinon.spy(),
emit: sinon.spy(),
subManager: { whenAllCursorsUpdated: () => Promise.resolve() },

@@ -158,0 +161,0 @@ };

@@ -22,2 +22,3 @@ import MethodCallManager, { _cleanMethods } from '../../lib/MethodCallManager';

once: sinon.spy(),
emit: sinon.spy(),
sendReady: sinon.spy(),

@@ -24,0 +25,0 @@ sendAdded: sinon.spy(),

Sorry, the diff of this file is not supported yet

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