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

vubsub

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vubsub - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

69

lib/channel.js

@@ -11,33 +11,41 @@ var util = require('util')

self.db = client.db;
self.collection = Channel.collection(self.db, client.namespace).then(function(collection) {
var cursor = collection.find().sort({ $natural: -1 }).limit(1);
cursor.nextObject(function(err, doc) {
if (err) {
throw err;
} else if (!doc) {
throw new Error('empty collection');
return q.ninvoke(cursor, 'nextObject').then(function(doc) {
if (doc) {
return doc;
} else {
// if we've come here, then:
// - the collection exists
// - it had at least a document
// - and we know the _id to the most recent one
var query = {
_id: { $gt: (lastMessage ? mongo.ObjectID(lastMessage) : doc._id) },
channel: name,
from: { $ne: client.id }
};
var options = {
tailable: true,
numberOfRetries: -1,
tailableRetryInterval: Channel.TAILABLE_RETRY_INTERVAL
}
self.cursor = self.collection.find(query, options).sort({ $natural: 1 });
self.cursor.nextObject(function(err, data) {
self._handleNext(err, data);
var deferred = q.defer();
collection.insert({ init: true }, { w: 'majority' }, function(err, docs) {
if (err || !docs || !docs.length) {
deferred.reject('failed to insert the first doc');
} else {
deferred.resolve(docs[0]);
}
});
self.emit('ready', collection);
return collection;
return deferred.promise;
}
}).then(function(doc) {
// if we've come here, then:
// - the collection exists
// - it had at least a document
// - and we know the _id to the most recent one
var query = {
_id: { $gt: (lastMessage ? mongo.ObjectID(lastMessage) : doc._id) },
channel: name,
from: { $ne: client.id }
};
var options = {
tailable: true,
numberOfRetries: -1,
tailableRetryInterval: Channel.TAILABLE_RETRY_INTERVAL
}
self.cursor = collection.find(query, options).sort({ $natural: 1 });
self.cursor.nextObject(function(err, data) {
self._handleNext(err, data);
});
self.emit('ready', collection);
return collection;
});

@@ -138,10 +146,3 @@ }).fail(function(err) {

} else {
collection.insert({ init: true }, { w: 'majority' }, function(err, bootstrap) {
if (err || !bootstrap) {
console.error('Channel.collection', 'failed to bootstrap namespace collection', name);
d.reject(new Error('failed to create bootstrap namespace collection'));
} else {
d.resolve(collection);
}
});
d.resolve(collection);
}

@@ -148,0 +149,0 @@ });

@@ -48,3 +48,7 @@ var q = require('q')

clients[client.id] = client;
deferred.resolve(client);
Channel.collection(db, meta.ns).then(function() {
deferred.resolve(client);
}).fail(function(err) {
deferred.reject(err);
});
}

@@ -51,0 +55,0 @@ });

{
"name": "vubsub",
"version": "1.1.3",
"version": "1.1.4",
"description": "Pub/Sub for Node.js and MongoDB",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/vivocha/vubsub",

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