Socket
Socket
Sign inDemoInstall

mongodb-core

Package Overview
Dependencies
Maintainers
1
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-core - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

lib/wireprotocol/3_2_support.js

6

HISTORY.md

@@ -0,4 +1,8 @@

1.2.3 06-26-2015
-----------------
- Minor bug fixes.
1.2.2 06-22-2015
-----------------
- Fix issue with SCRAM authentication causing authentication to return true on failed authentication (Issue 26, https://github.com/cglass17)
- Fix issue with SCRAM authentication causing authentication to return true on failed authentication (Issue 26, https://github.com/cglass17).

@@ -5,0 +9,0 @@ 1.2.1 06-17-2015

@@ -431,2 +431,12 @@ "use strict";

// Validation buffers
var firstBatch = new Buffer('firstBatch', 'utf8');
var nextBatch = new Buffer('nextBatch', 'utf8');
var cursorId = new Buffer('id', 'utf8').toString('hex');
var documentBuffers = {
firstBatch: firstBatch.toString('hex'),
nextBatch: nextBatch.toString('hex')
};
Response.prototype.parse = function(options) {

@@ -436,6 +446,41 @@ // Don't parse again if not needed

options = options || {};
// Allow the return of raw documents instead of parsing
var raw = options.raw || false;
var documentsReturnedIn = options.documentsReturnedIn || null;
//
// Single document and documentsReturnedIn set
//
if(this.numberReturned == 1 && documentsReturnedIn != null && raw) {
// Calculate the bson size
var bsonSize = this.data[this.index] | this.data[this.index + 1] << 8 | this.data[this.index + 2] << 16 | this.data[this.index + 3] << 24;
// Slice out the buffer containing the command result document
var document = this.data.slice(this.index, this.index + bsonSize);
// Set up field we wish to keep as raw
var fieldsAsRaw = {}
fieldsAsRaw[documentsReturnedIn] = true;
// Set up the options
var _options = {promoteLongs: this.opts.promoteLongs, fieldsAsRaw: fieldsAsRaw};
// Deserialize but keep the array of documents in non-parsed form
var doc = this.bson.deserialize(document, _options);
// Get the documents
this.documents = doc.cursor[documentsReturnedIn];
this.numberReturned = this.documents.length;
// Ensure we have a Long valie cursor id
this.cursorId = typeof doc.cursor.id == 'number'
? Long.fromNumber(doc.cursor.id)
: doc.cursor.id;
// Adjust the index
this.index = this.index + bsonSize;
// Set as parsed
this.parsed = true
return;
}
//
// Parse Body

@@ -442,0 +487,0 @@ //

@@ -94,2 +94,3 @@ "use strict";

cursorId: null
, cmd: cmd
, documents: options.documents || []

@@ -170,3 +171,3 @@ , cursorIndex: 0

if (result.queryFailure) {
if(result.queryFailure) {
return callback(MongoError.create(result.documents[0]), null);

@@ -176,3 +177,10 @@ }

// Check if we have a command cursor
if(Array.isArray(result.documents) && result.documents.length == 1 && !cmd.find) {
if(Array.isArray(result.documents) && result.documents.length == 1// && !cmd.find
&& (result.documents[0].cursor != 'string'
|| result.documents[0]['$err']
|| result.documents[0]['errmsg']
|| Array.isArray(result.documents[0].result))
) {
// We have a an error document return the error
if(result.documents[0]['$err']

@@ -183,2 +191,3 @@ || result.documents[0]['errmsg']) {

// We have a cursor document
if(result.documents[0].cursor != null

@@ -227,2 +236,7 @@ && typeof result.documents[0].cursor != 'string') {

// Do we have documentsReturnedIn set on the query
if(typeof query.documentsReturnedIn == 'string') {
queryCallback.documentsReturnedIn = query.documentsReturnedIn;
}
// Set up callback

@@ -344,3 +358,3 @@ callbacks.register(query.requestId, queryCallback);

// Execute command
this.server.wireProtocolHandler.killCursor(this.bson, this.cursorState.cursorId, this.connection, callback);
this.server.wireProtocolHandler.killCursor(this.bson, this.ns, this.cursorState.cursorId, this.connection, this.callbacks, callback);
}

@@ -487,2 +501,3 @@

self.cursorState.init = true;
// Get the right wire protocol command

@@ -577,3 +592,6 @@ self.query = self.server.wireProtocolHandler.command(self.bson, self.ns, self.cmd, self.cursorState, self.topology, self.options);

if(err) return handleCallback(callback, err);
if(self.cursorState.documents.length == 0 && Long.ZERO.equals(self.cursorState.cursorId)) self.cursorState.dead = true;
if(self.cursorState.documents.length == 0
&& Long.ZERO.equals(self.cursorState.cursorId)) {
self.cursorState.dead = true;
}

@@ -580,0 +598,0 @@ // Tailable cursor getMore result, notify owner about it

@@ -20,2 +20,3 @@ "use strict";

, TwoSixWireProtocolSupport = require('../wireprotocol/2_6_support')
, ThreeTwoWireProtocolSupport = require('../wireprotocol/3_2_support')
, Session = require('./session')

@@ -103,2 +104,7 @@ , Logger = require('../connection/logger')

Callbacks.prototype.documentsReturnedIn = function(id) {
if(this.callbacks[id] == null) return false;
return typeof this.callbacks[id].documentsReturnedIn == 'string' ? this.callbacks[id].documentsReturnedIn : null;
}
Callbacks.prototype.unregister = function(id) {

@@ -134,2 +140,7 @@ delete this.callbacks[id];

var createWireProtocolHandler = function(result) {
// 3.2 wire protocol handler
if(result && result.maxWireVersion >= 4) {
return new ThreeTwoWireProtocolSupport(new TwoSixWireProtocolSupport());
}
// 2.6 wire protocol handler

@@ -236,3 +247,3 @@ if(result && result.maxWireVersion >= 2) {

// Parse the message
response.parse({raw: state.callbacks.raw(response.responseTo)});
response.parse({raw: state.callbacks.raw(response.responseTo), documentsReturnedIn: state.callbacks.documentsReturnedIn(response.responseTo)});
if(state.logger.isDebug()) state.logger.debug(f('message [%s] received from %s', response.raw.toString('hex'), self.name));

@@ -239,0 +250,0 @@ state.callbacks.emit(response.responseTo, null, response);

82

lib/wireprotocol/2_4_support.js

@@ -20,3 +20,3 @@ "use strict";

var LegacySupport = function() {}
var WireProtocol = function() {}

@@ -27,4 +27,4 @@ //

//
LegacySupport.prototype.insert = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
options = options || {};
WireProtocol.prototype.insert = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
options = options || {};
// Default is ordered execution

@@ -49,4 +49,4 @@ var ordered = typeof options.ordered == 'boolean' ? options.ordered : true;

LegacySupport.prototype.update = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
options = options || {};
WireProtocol.prototype.update = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
options = options || {};
// Default is ordered execution

@@ -64,7 +64,7 @@ var ordered = typeof options.ordered == 'boolean' ? options.ordered : true;

return executeOrdered('update', Update, ismaster, ns, bson, pool, callbacks, ops, options, callback);
return executeOrdered('update', Update, ismaster, ns, bson, pool, callbacks, ops, options, callback);
}
LegacySupport.prototype.remove = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
options = options || {};
WireProtocol.prototype.remove = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
options = options || {};
// Default is ordered execution

@@ -82,6 +82,6 @@ var ordered = typeof options.ordered == 'boolean' ? options.ordered : true;

return executeOrdered('remove', Remove, ismaster, ns, bson, pool, callbacks, ops, options, callback);
return executeOrdered('remove', Remove, ismaster, ns, bson, pool, callbacks, ops, options, callback);
}
LegacySupport.prototype.killCursor = function(bson, cursorId, connection, callback) {
WireProtocol.prototype.killCursor = function(bson, ns, cursorId, connection, callbacks, callback) {
// Create a kill cursor command

@@ -97,3 +97,3 @@ var killCursor = new KillCursor(bson, [cursorId]);

LegacySupport.prototype.getMore = function(bson, ns, cursorState, batchSize, raw, connection, callbacks, options, callback) {
WireProtocol.prototype.getMore = function(bson, ns, cursorState, batchSize, raw, connection, callbacks, options, callback) {
// Create getMore command

@@ -104,4 +104,4 @@ var getMore = new GetMore(bson, ns, cursorState.cursorId, {numberToReturn: batchSize});

var queryCallback = function(err, r) {
if(err) return callback(err);
if(err) return callback(err);
// If we have a timed out query or a cursor that was killed

@@ -112,5 +112,11 @@ if((r.responseFlags & (1 << 0)) != 0) {

// Ensure we have a Long valie cursor id
var cursorId = typeof r.cursorId == 'number'
? Long.fromNumber(r.cursorId)
: r.cursorId;
// Set all the values
cursorState.documents = r.documents;
cursorState.cursorId = r.cursorId;
cursorState.cursorId = cursorId;
// Return

@@ -124,3 +130,3 @@ callback(null);

}
// Register a callback

@@ -132,3 +138,3 @@ callbacks.register(getMore.requestId, queryCallback);

LegacySupport.prototype.command = function(bson, ns, cmd, cursorState, topology, options) {
WireProtocol.prototype.command = function(bson, ns, cmd, cursorState, topology, options) {
// Establish type of command

@@ -157,3 +163,3 @@ if(cmd.find) {

var numberToReturn = 0;
// Unpack the limit and batchSize values

@@ -200,3 +206,3 @@ if(cursorState.limit == 0) {

// If we have a special modifier
if(usesSpecialModifier) {
if(usesSpecialModifier) {
findCmd['$query'] = cmd.query;

@@ -225,3 +231,3 @@ } else {

return query;
}
}

@@ -278,6 +284,6 @@ //

var hasWriteConcern = function(writeConcern) {
if(writeConcern.w
|| writeConcern.wtimeout
|| writeConcern.j == true
|| writeConcern.fsync == true
if(writeConcern.w
|| writeConcern.wtimeout
|| writeConcern.j == true
|| writeConcern.fsync == true
|| Object.keys(writeConcern).length == 0) {

@@ -303,3 +309,3 @@ return true;

var finalResult = { ok: 1, n: 0 }
// Map all the results coming back

@@ -336,4 +342,4 @@ for(var i = 0; i < results.length; i++) {

// Check if we have a write error
if(result.code == 11000
|| result.code == 11001
if(result.code == 11000
|| result.code == 11001
|| result.code == 12582

@@ -354,3 +360,3 @@ || result.code == 16544

code: result.code
, errmsg: result.errmsg || result.err || result.errMsg
, errmsg: result.errmsg || result.err || result.errMsg
}

@@ -363,3 +369,3 @@ }

}
// Result as expected

@@ -389,6 +395,6 @@ if(result != null && result.lastOp) finalResult.lastOp = result.lastOp;

if(list.length == 0) return _callback(null, aggregateWriteOperationResults(opType, ops, getLastErrors, connection));
// Get the first operation
var doc = list.shift();
var doc = list.shift();
// Create an insert command

@@ -405,3 +411,3 @@ var op = new command(Query.getRequestId(), ismaster, bson, ns, [doc], options);

// Error out if no connection available
if(connection == null)
if(connection == null)
return _callback(new MongoError("no connection available"));

@@ -437,3 +443,3 @@

executeOp(list, callback);
});
});
}

@@ -477,3 +483,3 @@ } catch(err) {

// Error out if no connection available
if(connection == null)
if(connection == null)
return _callback(new MongoError("no connection available"));

@@ -497,4 +503,4 @@

connection.write(getLastErrorOp.toBin());
// Give the result from getLastError the right index
// Give the result from getLastError the right index
var callbackOp = function(_index) {

@@ -531,3 +537,3 @@ return function(err, result) {

// Empty w:0 return
if(writeConcern
if(writeConcern
&& writeConcern.w == 0 && callback) {

@@ -538,2 +544,2 @@ callback(null, null);

module.exports = LegacySupport;
module.exports = WireProtocol;

@@ -17,3 +17,3 @@ "use strict";

var LegacySupport = function() {}
var WireProtocol = function() {}

@@ -55,15 +55,15 @@ //

//
LegacySupport.prototype.insert = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
WireProtocol.prototype.insert = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
executeWrite(topology, 'insert', 'documents', ns, ops, options, callback);
}
LegacySupport.prototype.update = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
WireProtocol.prototype.update = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
executeWrite(topology, 'update', 'updates', ns, ops, options, callback);
}
LegacySupport.prototype.remove = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
WireProtocol.prototype.remove = function(topology, ismaster, ns, bson, pool, callbacks, ops, options, callback) {
executeWrite(topology, 'delete', 'deletes', ns, ops, options, callback);
}
LegacySupport.prototype.killCursor = function(bson, cursorId, connection, callback) {
WireProtocol.prototype.killCursor = function(bson, ns, cursorId, connection, callbacks, callback) {
// Create a kill cursor command

@@ -79,3 +79,3 @@ var killCursor = new KillCursor(bson, [cursorId]);

LegacySupport.prototype.getMore = function(bson, ns, cursorState, batchSize, raw, connection, callbacks, options, callback) {
WireProtocol.prototype.getMore = function(bson, ns, cursorState, batchSize, raw, connection, callbacks, options, callback) {
// Create getMore command

@@ -93,5 +93,11 @@ var getMore = new GetMore(bson, ns, cursorState.cursorId, {numberToReturn: batchSize});

// Ensure we have a Long valie cursor id
var cursorId = typeof r.cursorId == 'number'
? Long.fromNumber(r.cursorId)
: r.cursorId;
// Set all the values
cursorState.documents = r.documents;
cursorState.cursorId = r.cursorId;
cursorState.cursorId = cursorId;
// Return

@@ -112,3 +118,3 @@ callback(null);

LegacySupport.prototype.command = function(bson, ns, cmd, cursorState, topology, options) {
WireProtocol.prototype.command = function(bson, ns, cmd, cursorState, topology, options) {
// Establish type of command

@@ -263,2 +269,2 @@ if(cmd.find) {

module.exports = LegacySupport;
module.exports = WireProtocol;
{
"name": "mongodb-core",
"version": "1.2.2",
"version": "1.2.3",
"description": "Core MongoDB driver functionality, no bells and whistles and meant for integration not end applications",

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

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