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

mong

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mong - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

.eslintrc

5

index.js
'use strict';
module.exports = require('./lib');
if (process.env.MONG_COVERAGE){
var dir = './lib-cov/';
module.exports = require(dir);
}

@@ -6,6 +6,8 @@ 'use strict';

var inherits = require('util').inherits;
var ObjectId = require('mongodb').ObjectID;
var Document = require('./model');
var promisify = require('./promisify');
var $private = require('./private').createAccessor();
var $private = require('./private').create();

@@ -20,10 +22,12 @@ module.exports = Connection;

if (uri) {
this.connect(uri);
connect.call(this, uri);
}
}
Connection.prototype.connect = function (uri, done) {
Connection.prototype.ObjectId = ObjectId;
Connection.prototype.connect = promisify(connect);
function connect(uri, done) {
var options = {
db: {
native_parser: true
'native_parser': true
}

@@ -57,3 +61,3 @@ };

return this;
};
}

@@ -66,3 +70,3 @@ Connection.prototype.queue = function (fn) {

Connection.prototype.disconnect = function (done) {
Connection.prototype.disconnect = promisify(function (done) {
var active = $private(this).db;

@@ -75,3 +79,3 @@ delete $private(this).db;

if (done) done();
};
});

@@ -92,3 +96,3 @@ /**

var self = this;
CollectionDocument.setConnection(self);

@@ -95,0 +99,0 @@ CollectionDocument.setCollectionProvider(function () {

2

lib/index.js

@@ -10,2 +10,2 @@ 'use strict';

exports.create = exports.createConnection;
exports.create = exports.createConnection;

@@ -7,3 +7,4 @@ 'use strict';

var QueryStream = require('./stream');
var $private = require('./private').createAccessor();
var $private = require('./private').create();
var p = require('./promisify');

@@ -21,3 +22,3 @@ function Document (o) {

this._id = this._id || new ObjectId();
for(var i in o) {

@@ -35,3 +36,3 @@ if (i !== '_id' && Object.hasOwnProperty.call(o, i)) {

*/
function GC(constructor) {
function getCollection(constructor) {
var conInternal = $private(constructor);

@@ -63,4 +64,4 @@ if (!conInternal.collection) {

Document.find = function (query, fields, options) {
var collection = GC(this);
Document.find = p.stream(function (query, fields, options) {
var collection = getCollection(this);
var callback = arguments[arguments.length - 1];

@@ -98,7 +99,7 @@ var l = arguments.length;

return new QueryStream(cursor, this.prototype);
};
});
Document.findOne = function () {
Document.findOne = p(function () {
var prototype = this.prototype;

@@ -110,15 +111,15 @@ var cb = arguments[arguments.length - 1];

};
var collection = GC(this);
var collection = getCollection(this);
return collection.findOne.apply(collection, arguments);
};
});
Document.findById = function (_id, callback) {
Document.findById = p(function (_id, callback) {
if (typeof _id === 'string') _id = new ObjectId(_id);
return this.findOne({_id: _id}, callback);
};
});
Document.findAndModify = function (query, sort, update, options, callback) {
var collection = GC(this);
Document.findAndModify = p(function () {
var collection = getCollection(this);
return collection.findAndModify.apply(collection, arguments);
};
});

@@ -128,3 +129,3 @@ /**

* http://docs.mongodb.org/manual/reference/command/aggregate/#dbcmd.aggregate
*
*
* @param [Object] pipeline

@@ -135,7 +136,7 @@ * @param {Object} options (Optinal)

*/
Document.aggregate = function (pipeline, options, callback) {
Document.aggregate = p.stream(function (pipeline, options) {
var _callback;
var l = arguments.length;
if (typeof arguments[arguments.length - 1] === 'function') {
_callback = arguments[arguments.length -1];
_callback = arguments[arguments.length - 1];
l--;

@@ -146,3 +147,3 @@ }

}
var collection = GC(this);
var collection = getCollection(this);
if (!options.cursor) {

@@ -163,3 +164,3 @@ options.cursor = {};

return cursor;
};
});

@@ -173,6 +174,6 @@ /**

*/
Document.ensureIndex = function (fieldOrSpec, options, done) {
Document.ensureIndex = p(function (fieldOrSpec, options, done) {
var self = this;
$private(this).connection.queue(function () {
var collection = GC(self);
var collection = getCollection(self);
collection.ensureIndex(fieldOrSpec, options, function (err) {

@@ -185,13 +186,13 @@ if (done) return done(err);

return this;
};
});
Document.update = function (query, update, options, callback) {
var collection = GC(this);
Document.update = p(function () {
var collection = getCollection(this);
return collection.update.apply(collection, arguments);
};
});
Document.remove = function (query, options, callback) {
var collection = GC(this);
Document.remove = p(function () {
var collection = getCollection(this);
return collection.remove.apply(collection, arguments);
};
});

@@ -202,26 +203,26 @@

Document.prototype.save = function (done) {
Document.prototype.save = p(function (done) {
done = done || function (err) {
if (err) throw err;
};
var collection = GC(this.constructor);
var collection = getCollection(this.constructor);
var self = this;
collection.save(this, function (err, numAffected, details) {
collection.save(this, function (err) {
if (err) return done(err);
done(null, self);
});
};
});
Document.prototype.update = function (update, options, callback) {
var collection = GC(this.constructor);
Document.prototype.update = p(function () {
var collection = getCollection(this.constructor);
var args = [{_id: this._id}].concat(Array.prototype.slice.call(arguments));
return collection.update.apply(collection, args);
};
});
Document.prototype.remove = function (options, callback) {
var collection = GC(this.constructor);
Document.prototype.remove = p(function () {
var collection = getCollection(this.constructor);
var args = [{_id: this._id}].concat(Array.prototype.slice.call(arguments));
return collection.remove.apply(collection, args);
};
});

@@ -235,6 +236,6 @@ /**

*/
Document.prototype.updateIf = function (query, options, callback) {
Document.prototype.updateIf = p(function (query) {
query = Object.create(query);
query._id = this._id;
return Document.update.apply(this.constructor, arguments);
};
});

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

exports.createAccessor = function () {
exports.create = function () {
// Important: the only scope state maintained is this immutable object.

@@ -8,0 +8,0 @@ // This ensures there are no memory leaks:

@@ -22,4 +22,3 @@ 'use strict';

if (err) {
console.error('ERRRR', err);
throw err;
stream.emit('error', err);
}

@@ -29,2 +28,2 @@ if (doc) doc.__proto__ = prototype;

});
};
};
{
"name": "mong",
"version": "1.0.3",
"version": "1.1.0",
"description": "Lightweight models for mongodb objects",
"main": "lib/index",
"scripts": {
"test": "[[ -z $TRAVIS_JOB_ID ]] && mocha --recursive || npm run travis",
"travis": "jscoverage lib lib-cov && MONG_COVERAGE=1 mocha --recursive -R mocha-lcov-reporter | coveralls && mocha --recursive",
"coverage": "jscoverage lib lib-cov && MONG_COVERAGE=1 mocha --recursive -R html-cov > lib-cov/test.html && open lib-cov/test.html"
"lint": "eslint --ignore-path .gitignore .",
"test": "mocha --recursive test/ && ([[ -z $TRAVIS_JOB_ID ]] || npm run travis)",
"coverage": "mkdir -p coverage && mocha --recursive -r blanket -R html-cov --recursive test/ > coverage/index.html",
"travis": "mocha -r blanket -R mocha-lcov-reporter --recursive test/ | coveralls"
},
"config": {
"blanket": {
"pattern": [
""
],
"data-cover-never": [
"node_modules",
"test"
]
}
},
"repository": {

@@ -16,12 +28,4 @@ "type": "git",

"engines": {
"node": ">=0.10"
"node": ">=0.11"
},
"jshintConfig": {
"laxcomma": true,
"eqeqeq": true,
"newcap": true,
"undef": true,
"node": true,
"mocha": true
},
"keywords": [

@@ -42,3 +46,4 @@ "mongodb",

"dependencies": {
"mongodb": "^2.0.27"
"es6-promise": "^2.3.0",
"mongodb": "^2.0.39"
},

@@ -49,9 +54,10 @@ "directories": {

"devDependencies": {
"coveralls": "~2.6.1",
"jscoverage": "~0.3.8",
"mocha": "^2.2.4",
"mocha-lcov-reporter": "0.0.1",
"should": "^6.0.1",
"blanket": "^1.1.7",
"coveralls": "^2.11.3",
"eslint": "^0.24.1",
"mocha": "^2.2.5",
"mocha-lcov-reporter": "0.0.2",
"should": "^7.0.2",
"sinon": "~1.7.3"
}
}

@@ -0,1 +1,3 @@

'use strict';
var lib = require('../../index');

@@ -21,2 +23,2 @@ var should = require('should');

});
});
});

@@ -0,3 +1,4 @@

'use strict';
var lib = require('../../index');
var should = require('should');

@@ -19,6 +20,6 @@ describe('Model()', function () {

var o2 = {};
Model.call(o2, {_id: lib.ObjectId('55338635d671fa19fe5855c6')});
Model.call(o2, {_id: new lib.ObjectId('55338635d671fa19fe5855c6')});
o2._id.equals('55338635d671fa19fe5855c6').should.equal(true);
});
});
});

@@ -25,4 +25,4 @@ 'use strict';

should.exist(collection);
collection.insert({_id: _id, random: random}, function (err) {
collection.insert({_id: _id2, random: Math.random()}, function (err) {
collection.insert({_id: _id, random: random}, function () {
collection.insert({_id: _id2, random: Math.random()}, function () {
_db.close(done);

@@ -69,2 +69,7 @@ });

it('should support promises', function () {
return User.find()
.then();
});
it('should support providing callbacks', function (done) {

@@ -83,3 +88,3 @@

});
})
});

@@ -94,3 +99,3 @@ describe('.findById', function () {

it('should support callbacks', function (done) {
User.update({_id: _id}, {$set: {list: [1,2,3]}}, done);
User.update({_id: _id}, {$set: {list: [1, 2, 3]}}, done);
});

@@ -97,0 +102,0 @@ });

@@ -0,1 +1,3 @@

'use strict';
var lib = require('../../index');

@@ -12,2 +14,2 @@ var should = require('should');

});
});
});

Sorry, the diff of this file is not supported yet

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