Skip to content

Commit

Permalink
fixed; Constructor / version exposure
Browse files Browse the repository at this point in the history
new require('mongoose').Mongoose now contains all constructors
that require('mongoose') exposes.

see https://github.com/donpark/mongeese

relates to #1124
  • Loading branch information
aheckmann committed Feb 27, 2013
1 parent 32617bc commit 7bd12b2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 44 deletions.
66 changes: 39 additions & 27 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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;
45 changes: 28 additions & 17 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
})

});

0 comments on commit 7bd12b2

Please sign in to comment.