From 7bd12b231ab2ee9d87be43487b027c3ceb97a83e Mon Sep 17 00:00:00 2001 From: Aaron Heckmann Date: Tue, 26 Feb 2013 22:32:43 -0800 Subject: [PATCH] fixed; Constructor / version exposure new require('mongoose').Mongoose now contains all constructors that require('mongoose') exposes. see https://github.com/donpark/mongeese relates to #1124 --- lib/index.js | 66 +++++++++++++++++++++++++++------------------- test/index.test.js | 45 +++++++++++++++++++------------ 2 files changed, 67 insertions(+), 44 deletions(-) diff --git a/lib/index.js b/lib/index.js index ca692f3c5e6..13f66b97847 100644 --- a/lib/index.js +++ b/lib/index.js @@ -398,40 +398,32 @@ var Connection = require(driver + '/connection'); var Collection = require(driver + '/collection'); -/** - * The exports object is an instance of Mongoose. - * - * @api public - */ - -module.exports = exports = new Mongoose; -var mongoose = module.exports; - /** * The Mongoose Collection constructor * + * @method Collection * @api public */ -mongoose.Collection = Collection; +Mongoose.prototype.Collection = Collection; /** * The Mongoose Connection constructor * + * @method Connection * @api public */ -mongoose.Connection = Connection; +Mongoose.prototype.Connection = Connection; /** - * Mongoose version + * The Mongoose version * + * @property version * @api public */ -mongoose.version = JSON.parse( - require('fs').readFileSync(__dirname + '/../package.json', 'utf8') -).version; +Mongoose.prototype.version = require(__dirname + '/../package.json').version; /** * The Mongoose constructor @@ -443,10 +435,11 @@ mongoose.version = JSON.parse( * var mongoose = require('mongoose'); * var mongoose2 = new mongoose.Mongoose(); * + * @method Mongoose * @api public */ -mongoose.Mongoose = Mongoose; +Mongoose.prototype.Mongoose = Mongoose; /** * The Mongoose Schema constructor @@ -457,18 +450,20 @@ mongoose.Mongoose = Mongoose; * var Schema = mongoose.Schema; * var CatSchema = new Schema(..); * + * @method Schema * @api public */ -mongoose.Schema = Schema; +Mongoose.prototype.Schema = Schema; /** * The Mongoose SchemaType constructor. * + * @method SchemaType * @api public */ -mongoose.SchemaType = SchemaType; +Mongoose.prototype.SchemaType = SchemaType; /** * The various Mongoose SchemaTypes. @@ -477,19 +472,21 @@ mongoose.SchemaType = SchemaType; * * _Alias of mongoose.Schema.Types for backwards compatibility._ * + * @property SchemaTypes * @see Schema.SchemaTypes #schema_Schema.Types * @api public */ -mongoose.SchemaTypes = Schema.Types; +Mongoose.prototype.SchemaTypes = Schema.Types; /** * The Mongoose VirtualType constructor. * + * @method VirtualType * @api public */ -mongoose.VirtualType = VirtualType; +Mongoose.prototype.VirtualType = VirtualType; /** * The various Mongoose Types. @@ -513,55 +510,70 @@ mongoose.VirtualType = VirtualType; * var ObjectId = mongoose.Types.ObjectId; * var id1 = new ObjectId; * + * @property Types * @api public */ -mongoose.Types = Types; +Mongoose.prototype.Types = Types; /** * The Mongoose Query constructor. * + * @method Query * @api public */ -mongoose.Query = Query; +Mongoose.prototype.Query = Query; /** * The Mongoose Promise constructor. * + * @method Promise * @api public */ -mongoose.Promise = Promise; +Mongoose.prototype.Promise = Promise; /** * The Mongoose Model constructor. * + * @method Model * @api public */ -mongoose.Model = Model; +Mongoose.prototype.Model = Model; /** * The Mongoose Document constructor. * + * @method Document * @api public */ -mongoose.Document = Document; +Mongoose.prototype.Document = Document; /** * The MongooseError constructor. * + * @method Error * @api public */ -mongoose.Error = require('./error'); +Mongoose.prototype.Error = require('./error'); /** * The node-mongodb-native driver Mongoose uses. * + * @property mongo + * @api public + */ + +Mongoose.prototype.mongo = require('mongodb'); + +/*! + * The exports object is an instance of Mongoose. + * * @api public */ -mongoose.mongo = require('mongodb'); +var mongoose = module.exports = exports = new Mongoose; diff --git a/test/index.test.js b/test/index.test.js index 376b13d2a1c..5f6854050a8 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -366,23 +366,34 @@ describe('mongoose module:', function(){ } }); - it('public exports', function(done){ - assert.equal('string', typeof mongoose.version); - assert.equal('function', typeof mongoose.Collection); - assert.equal('function', typeof mongoose.Connection); - assert.equal('function', typeof mongoose.Schema); - assert.equal('function', typeof mongoose.SchemaType); - assert.equal('function', typeof mongoose.Query); - assert.equal('function', typeof mongoose.Promise); - assert.equal('function', typeof mongoose.Model); - assert.equal('function', typeof mongoose.Document); - assert.equal('function', typeof mongoose.Error); - assert.equal('function', typeof mongoose.Error.CastError); - assert.equal('function', typeof mongoose.Error.DocumentError); - assert.equal('function', typeof mongoose.Error.ValidationError); - assert.equal('function', typeof mongoose.Error.ValidatorError); - assert.equal('function', typeof mongoose.Error.VersionError); - done() + describe('exports', function(){ + function test (mongoose) { + assert.equal('string', typeof mongoose.version); + assert.equal('function', typeof mongoose.Mongoose); + assert.equal('function', typeof mongoose.Collection); + assert.equal('function', typeof mongoose.Connection); + assert.equal('function', typeof mongoose.Schema); + assert.equal('function', typeof mongoose.SchemaType); + assert.equal('function', typeof mongoose.Query); + assert.equal('function', typeof mongoose.Promise); + assert.equal('function', typeof mongoose.Model); + assert.equal('function', typeof mongoose.Document); + assert.equal('function', typeof mongoose.Error); + assert.equal('function', typeof mongoose.Error.CastError); + assert.equal('function', typeof mongoose.Error.DocumentError); + assert.equal('function', typeof mongoose.Error.ValidationError); + assert.equal('function', typeof mongoose.Error.ValidatorError); + assert.equal('function', typeof mongoose.Error.VersionError); + } + + it('of module', function(done){ + test(mongoose); + done(); + }) + it('of new Mongoose instances', function(done){ + test(new mongoose.Mongoose); + done(); + }) }) });