diff options
Diffstat (limited to 'node_modules/mongoose/lib/drivers')
13 files changed, 0 insertions, 717 deletions
diff --git a/node_modules/mongoose/lib/drivers/SPEC.md b/node_modules/mongoose/lib/drivers/SPEC.md deleted file mode 100644 index 6464693..0000000 --- a/node_modules/mongoose/lib/drivers/SPEC.md +++ /dev/null @@ -1,4 +0,0 @@ - -# Driver Spec - -TODO diff --git a/node_modules/mongoose/lib/drivers/browser/ReadPreference.js b/node_modules/mongoose/lib/drivers/browser/ReadPreference.js deleted file mode 100644 index 1363570..0000000 --- a/node_modules/mongoose/lib/drivers/browser/ReadPreference.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ignore - */ - -'use strict'; - -module.exports = function() {}; diff --git a/node_modules/mongoose/lib/drivers/browser/binary.js b/node_modules/mongoose/lib/drivers/browser/binary.js deleted file mode 100644 index 4658f7b..0000000 --- a/node_modules/mongoose/lib/drivers/browser/binary.js +++ /dev/null @@ -1,14 +0,0 @@ - -/*! - * Module dependencies. - */ - -'use strict'; - -const Binary = require('bson').Binary; - -/*! - * Module exports. - */ - -module.exports = exports = Binary; diff --git a/node_modules/mongoose/lib/drivers/browser/decimal128.js b/node_modules/mongoose/lib/drivers/browser/decimal128.js deleted file mode 100644 index 5668182..0000000 --- a/node_modules/mongoose/lib/drivers/browser/decimal128.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ignore - */ - -'use strict'; - -module.exports = require('bson').Decimal128; diff --git a/node_modules/mongoose/lib/drivers/browser/index.js b/node_modules/mongoose/lib/drivers/browser/index.js deleted file mode 100644 index 56d0b8a..0000000 --- a/node_modules/mongoose/lib/drivers/browser/index.js +++ /dev/null @@ -1,13 +0,0 @@ -/*! - * Module exports. - */ - -'use strict'; - -exports.Binary = require('./binary'); -exports.Collection = function() { - throw new Error('Cannot create a collection from browser library'); -}; -exports.Decimal128 = require('./decimal128'); -exports.ObjectId = require('./objectid'); -exports.ReadPreference = require('./ReadPreference'); diff --git a/node_modules/mongoose/lib/drivers/browser/objectid.js b/node_modules/mongoose/lib/drivers/browser/objectid.js deleted file mode 100644 index b1e603d..0000000 --- a/node_modules/mongoose/lib/drivers/browser/objectid.js +++ /dev/null @@ -1,28 +0,0 @@ - -/*! - * [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) ObjectId - * @constructor NodeMongoDbObjectId - * @see ObjectId - */ - -'use strict'; - -const ObjectId = require('bson').ObjectID; - -/*! - * Getter for convenience with populate, see gh-6115 - */ - -Object.defineProperty(ObjectId.prototype, '_id', { - enumerable: false, - configurable: true, - get: function() { - return this; - } -}); - -/*! - * ignore - */ - -module.exports = exports = ObjectId; diff --git a/node_modules/mongoose/lib/drivers/node-mongodb-native/ReadPreference.js b/node_modules/mongoose/lib/drivers/node-mongodb-native/ReadPreference.js deleted file mode 100644 index 024ee18..0000000 --- a/node_modules/mongoose/lib/drivers/node-mongodb-native/ReadPreference.js +++ /dev/null @@ -1,47 +0,0 @@ -/*! - * Module dependencies. - */ - -'use strict'; - -const mongodb = require('mongodb'); -const ReadPref = mongodb.ReadPreference; - -/*! - * Converts arguments to ReadPrefs the driver - * can understand. - * - * @param {String|Array} pref - * @param {Array} [tags] - */ - -module.exports = function readPref(pref, tags) { - if (Array.isArray(pref)) { - tags = pref[1]; - pref = pref[0]; - } - - if (pref instanceof ReadPref) { - return pref; - } - - switch (pref) { - case 'p': - pref = 'primary'; - break; - case 'pp': - pref = 'primaryPreferred'; - break; - case 's': - pref = 'secondary'; - break; - case 'sp': - pref = 'secondaryPreferred'; - break; - case 'n': - pref = 'nearest'; - break; - } - - return new ReadPref(pref, tags); -}; diff --git a/node_modules/mongoose/lib/drivers/node-mongodb-native/binary.js b/node_modules/mongoose/lib/drivers/node-mongodb-native/binary.js deleted file mode 100644 index 4e3c86f..0000000 --- a/node_modules/mongoose/lib/drivers/node-mongodb-native/binary.js +++ /dev/null @@ -1,10 +0,0 @@ - -/*! - * Module dependencies. - */ - -'use strict'; - -const Binary = require('mongodb').Binary; - -module.exports = exports = Binary; diff --git a/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js b/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js deleted file mode 100644 index d660c7d..0000000 --- a/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js +++ /dev/null @@ -1,368 +0,0 @@ -'use strict'; - -/*! - * Module dependencies. - */ - -const MongooseCollection = require('../../collection'); -const MongooseError = require('../../error/mongooseError'); -const Collection = require('mongodb').Collection; -const get = require('../../helpers/get'); -const sliced = require('sliced'); -const stream = require('stream'); -const util = require('util'); - -/** - * A [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) collection implementation. - * - * All methods methods from the [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) driver are copied and wrapped in queue management. - * - * @inherits Collection - * @api private - */ - -function NativeCollection(name, options) { - this.collection = null; - this.Promise = options.Promise || Promise; - this._closed = false; - MongooseCollection.apply(this, arguments); -} - -/*! - * Inherit from abstract Collection. - */ - -NativeCollection.prototype.__proto__ = MongooseCollection.prototype; - -/** - * Called when the connection opens. - * - * @api private - */ - -NativeCollection.prototype.onOpen = function() { - const _this = this; - - // always get a new collection in case the user changed host:port - // of parent db instance when re-opening the connection. - - if (!_this.opts.capped.size) { - // non-capped - callback(null, _this.conn.db.collection(_this.name)); - return _this.collection; - } - - if (_this.opts.autoCreate === false) { - _this.collection = _this.conn.db.collection(_this.name); - return _this.collection; - } - - // capped - return _this.conn.db.collection(_this.name, function(err, c) { - if (err) return callback(err); - - // discover if this collection exists and if it is capped - _this.conn.db.listCollections({ name: _this.name }).toArray(function(err, docs) { - if (err) { - return callback(err); - } - const doc = docs[0]; - const exists = !!doc; - - if (exists) { - if (doc.options && doc.options.capped) { - callback(null, c); - } else { - const msg = 'A non-capped collection exists with the name: ' + _this.name + '\n\n' - + ' To use this collection as a capped collection, please ' - + 'first convert it.\n' - + ' http://www.mongodb.org/display/DOCS/Capped+Collections#CappedCollections-Convertingacollectiontocapped'; - err = new Error(msg); - callback(err); - } - } else { - // create - const opts = Object.assign({}, _this.opts.capped); - opts.capped = true; - _this.conn.db.createCollection(_this.name, opts, callback); - } - }); - }); - - function callback(err, collection) { - if (err) { - // likely a strict mode error - _this.conn.emit('error', err); - } else { - _this.collection = collection; - MongooseCollection.prototype.onOpen.call(_this); - } - } -}; - -/** - * Called when the connection closes - * - * @api private - */ - -NativeCollection.prototype.onClose = function(force) { - MongooseCollection.prototype.onClose.call(this, force); -}; - -/*! - * ignore - */ - -const syncCollectionMethods = { watch: true }; - -/*! - * Copy the collection methods and make them subject to queues - */ - -function iter(i) { - NativeCollection.prototype[i] = function() { - const collection = this.collection; - const args = Array.from(arguments); - const _this = this; - const debug = get(_this, 'conn.base.options.debug'); - const lastArg = arguments[arguments.length - 1]; - - // If user force closed, queueing will hang forever. See #5664 - if (this.conn.$wasForceClosed) { - const error = new MongooseError('Connection was force closed'); - if (args.length > 0 && - typeof args[args.length - 1] === 'function') { - args[args.length - 1](error); - return; - } else { - throw error; - } - } - - if (this._shouldBufferCommands() && this.buffer) { - if (syncCollectionMethods[i]) { - throw new Error('Collection method ' + i + ' is synchronous'); - } - if (typeof lastArg === 'function') { - this.addQueue(i, args); - return; - } - - this.conn.emit('buffer', { method: i, args: args }); - - return new this.Promise((resolve, reject) => { - this.addQueue(i, [].concat(args).concat([(err, res) => { - if (err != null) { - return reject(err); - } - resolve(res); - }])); - }); - } - - if (debug) { - if (typeof debug === 'function') { - debug.apply(_this, - [_this.name, i].concat(sliced(args, 0, args.length - 1))); - } else if (debug instanceof stream.Writable) { - this.$printToStream(_this.name, i, args, debug); - } else { - this.$print(_this.name, i, args, typeof debug.color === 'undefined' ? true : debug.color); - } - } - - try { - if (collection == null) { - throw new MongooseError('Cannot call `' + this.name + '.' + i + '()` before initial connection is complete if `bufferCommands = false`. Make sure you `await mongoose.connect()` if you have `bufferCommands = false`.'); - } - - return collection[i].apply(collection, args); - } catch (error) { - // Collection operation may throw because of max bson size, catch it here - // See gh-3906 - if (args.length > 0 && - typeof args[args.length - 1] === 'function') { - args[args.length - 1](error); - } else { - throw error; - } - } - }; -} - -for (const key of Object.keys(Collection.prototype)) { - // Janky hack to work around gh-3005 until we can get rid of the mongoose - // collection abstraction - const descriptor = Object.getOwnPropertyDescriptor(Collection.prototype, key); - // Skip properties with getters because they may throw errors (gh-8528) - if (descriptor.get !== undefined) { - continue; - } - if (typeof Collection.prototype[key] !== 'function') { - continue; - } - - iter(key); -} - -/** - * Debug print helper - * - * @api public - * @method $print - */ - -NativeCollection.prototype.$print = function(name, i, args, color) { - const moduleName = color ? '\x1B[0;36mMongoose:\x1B[0m ' : 'Mongoose: '; - const functionCall = [name, i].join('.'); - const _args = []; - for (let j = args.length - 1; j >= 0; --j) { - if (this.$format(args[j]) || _args.length) { - _args.unshift(this.$format(args[j], color)); - } - } - const params = '(' + _args.join(', ') + ')'; - - console.info(moduleName + functionCall + params); -}; - -/** - * Debug print helper - * - * @api public - * @method $print - */ - -NativeCollection.prototype.$printToStream = function(name, i, args, stream) { - const functionCall = [name, i].join('.'); - const _args = []; - for (let j = args.length - 1; j >= 0; --j) { - if (this.$format(args[j]) || _args.length) { - _args.unshift(this.$format(args[j])); - } - } - const params = '(' + _args.join(', ') + ')'; - - stream.write(functionCall + params, 'utf8'); -}; - -/** - * Formatter for debug print args - * - * @api public - * @method $format - */ - -NativeCollection.prototype.$format = function(arg, color) { - const type = typeof arg; - if (type === 'function' || type === 'undefined') return ''; - return format(arg, false, color); -}; - -/*! - * Debug print helper - */ - -function inspectable(representation) { - const ret = { - inspect: function() { return representation; } - }; - if (util.inspect.custom) { - ret[util.inspect.custom] = ret.inspect; - } - return ret; -} -function map(o) { - return format(o, true); -} -function formatObjectId(x, key) { - x[key] = inspectable('ObjectId("' + x[key].toHexString() + '")'); -} -function formatDate(x, key) { - x[key] = inspectable('new Date("' + x[key].toUTCString() + '")'); -} -function format(obj, sub, color) { - if (obj && typeof obj.toBSON === 'function') { - obj = obj.toBSON(); - } - if (obj == null) { - return obj; - } - - const clone = require('../../helpers/clone'); - let x = clone(obj, { transform: false }); - - if (x.constructor.name === 'Binary') { - x = 'BinData(' + x.sub_type + ', "' + x.toString('base64') + '")'; - } else if (x.constructor.name === 'ObjectID') { - x = inspectable('ObjectId("' + x.toHexString() + '")'); - } else if (x.constructor.name === 'Date') { - x = inspectable('new Date("' + x.toUTCString() + '")'); - } else if (x.constructor.name === 'Object') { - const keys = Object.keys(x); - const numKeys = keys.length; - let key; - for (let i = 0; i < numKeys; ++i) { - key = keys[i]; - if (x[key]) { - let error; - if (typeof x[key].toBSON === 'function') { - try { - // `session.toBSON()` throws an error. This means we throw errors - // in debug mode when using transactions, see gh-6712. As a - // workaround, catch `toBSON()` errors, try to serialize without - // `toBSON()`, and rethrow if serialization still fails. - x[key] = x[key].toBSON(); - } catch (_error) { - error = _error; - } - } - if (x[key].constructor.name === 'Binary') { - x[key] = 'BinData(' + x[key].sub_type + ', "' + - x[key].buffer.toString('base64') + '")'; - } else if (x[key].constructor.name === 'Object') { - x[key] = format(x[key], true); - } else if (x[key].constructor.name === 'ObjectID') { - formatObjectId(x, key); - } else if (x[key].constructor.name === 'Date') { - formatDate(x, key); - } else if (x[key].constructor.name === 'ClientSession') { - x[key] = inspectable('ClientSession("' + - get(x[key], 'id.id.buffer', '').toString('hex') + '")'); - } else if (Array.isArray(x[key])) { - x[key] = x[key].map(map); - } else if (error != null) { - // If there was an error with `toBSON()` and the object wasn't - // already converted to a string representation, rethrow it. - // Open to better ideas on how to handle this. - throw error; - } - } - } - } - if (sub) { - return x; - } - - return util. - inspect(x, false, 10, color). - replace(/\n/g, ''). - replace(/\s{2,}/g, ' '); -} - -/** - * Retrieves information about this collections indexes. - * - * @param {Function} callback - * @method getIndexes - * @api public - */ - -NativeCollection.prototype.getIndexes = NativeCollection.prototype.indexInformation; - -/*! - * Module exports. - */ - -module.exports = NativeCollection; diff --git a/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js b/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js deleted file mode 100644 index 8041a88..0000000 --- a/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js +++ /dev/null @@ -1,185 +0,0 @@ -/*! - * Module dependencies. - */ - -'use strict'; - -const MongooseConnection = require('../../connection'); -const STATES = require('../../connectionstate'); - -/** - * A [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) connection implementation. - * - * @inherits Connection - * @api private - */ - -function NativeConnection() { - MongooseConnection.apply(this, arguments); - this._listening = false; -} - -/** - * Expose the possible connection states. - * @api public - */ - -NativeConnection.STATES = STATES; - -/*! - * Inherits from Connection. - */ - -NativeConnection.prototype.__proto__ = MongooseConnection.prototype; - -/** - * Switches to a different database using the same connection pool. - * - * Returns a new connection object, with the new db. If you set the `useCache` - * option, `useDb()` will cache connections by `name`. - * - * @param {String} name The database name - * @param {Object} [options] - * @param {Boolean} [options.useCache=false] If true, cache results so calling `useDb()` multiple times with the same name only creates 1 connection object. - * @return {Connection} New Connection Object - * @api public - */ - -NativeConnection.prototype.useDb = function(name, options) { - // Return immediately if cached - if (options && options.useCache && this.relatedDbs[name]) { - return this.relatedDbs[name]; - } - - // we have to manually copy all of the attributes... - const newConn = new this.constructor(); - newConn.name = name; - newConn.base = this.base; - newConn.collections = {}; - newConn.models = {}; - newConn.replica = this.replica; - newConn.config = Object.assign({}, this.base.connection.config, newConn.config); - newConn.name = this.name; - newConn.options = this.options; - newConn._readyState = this._readyState; - newConn._closeCalled = this._closeCalled; - newConn._hasOpened = this._hasOpened; - newConn._listening = false; - - newConn.host = this.host; - newConn.port = this.port; - newConn.user = this.user; - newConn.pass = this.pass; - - // First, when we create another db object, we are not guaranteed to have a - // db object to work with. So, in the case where we have a db object and it - // is connected, we can just proceed with setting everything up. However, if - // we do not have a db or the state is not connected, then we need to wait on - // the 'open' event of the connection before doing the rest of the setup - // the 'connected' event is the first time we'll have access to the db object - - const _this = this; - - newConn.client = _this.client; - - if (this.db && this._readyState === STATES.connected) { - wireup(); - } else { - this.once('connected', wireup); - } - - function wireup() { - newConn.client = _this.client; - newConn.db = _this.client.db(name); - newConn.onOpen(); - // setup the events appropriately - listen(newConn); - } - - newConn.name = name; - - // push onto the otherDbs stack, this is used when state changes - this.otherDbs.push(newConn); - newConn.otherDbs.push(this); - - // push onto the relatedDbs cache, this is used when state changes - if (options && options.useCache) { - this.relatedDbs[newConn.name] = newConn; - newConn.relatedDbs = this.relatedDbs; - } - - return newConn; -}; - -/*! - * Register listeners for important events and bubble appropriately. - */ - -function listen(conn) { - if (conn.db._listening) { - return; - } - conn.db._listening = true; - - conn.db.on('close', function(force) { - if (conn._closeCalled) return; - - // the driver never emits an `open` event. auto_reconnect still - // emits a `close` event but since we never get another - // `open` we can't emit close - if (conn.db.serverConfig.autoReconnect) { - conn.readyState = STATES.disconnected; - conn.emit('close'); - return; - } - conn.onClose(force); - }); - conn.db.on('error', function(err) { - conn.emit('error', err); - }); - conn.db.on('reconnect', function() { - conn.readyState = STATES.connected; - conn.emit('reconnect'); - conn.emit('reconnected'); - conn.onOpen(); - }); - conn.db.on('timeout', function(err) { - conn.emit('timeout', err); - }); - conn.db.on('open', function(err, db) { - if (STATES.disconnected === conn.readyState && db && db.databaseName) { - conn.readyState = STATES.connected; - conn.emit('reconnect'); - conn.emit('reconnected'); - } - }); - conn.db.on('parseError', function(err) { - conn.emit('parseError', err); - }); -} - -/** - * Closes the connection - * - * @param {Boolean} [force] - * @param {Function} [fn] - * @return {Connection} this - * @api private - */ - -NativeConnection.prototype.doClose = function(force, fn) { - this.client.close(force, (err, res) => { - // Defer because the driver will wait at least 1ms before finishing closing - // the pool, see https://github.com/mongodb-js/mongodb-core/blob/a8f8e4ce41936babc3b9112bf42d609779f03b39/lib/connection/pool.js#L1026-L1030. - // If there's queued operations, you may still get some background work - // after the callback is called. - setTimeout(() => fn(err, res), 1); - }); - return this; -}; - -/*! - * Module exports. - */ - -module.exports = NativeConnection; diff --git a/node_modules/mongoose/lib/drivers/node-mongodb-native/decimal128.js b/node_modules/mongoose/lib/drivers/node-mongodb-native/decimal128.js deleted file mode 100644 index c895f17..0000000 --- a/node_modules/mongoose/lib/drivers/node-mongodb-native/decimal128.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * ignore - */ - -'use strict'; - -module.exports = require('mongodb').Decimal128; diff --git a/node_modules/mongoose/lib/drivers/node-mongodb-native/index.js b/node_modules/mongoose/lib/drivers/node-mongodb-native/index.js deleted file mode 100644 index 2cd749e..0000000 --- a/node_modules/mongoose/lib/drivers/node-mongodb-native/index.js +++ /dev/null @@ -1,11 +0,0 @@ -/*! - * Module exports. - */ - -'use strict'; - -exports.Binary = require('./binary'); -exports.Collection = require('./collection'); -exports.Decimal128 = require('./decimal128'); -exports.ObjectId = require('./objectid'); -exports.ReadPreference = require('./ReadPreference');
\ No newline at end of file diff --git a/node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js b/node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js deleted file mode 100644 index 6f432b7..0000000 --- a/node_modules/mongoose/lib/drivers/node-mongodb-native/objectid.js +++ /dev/null @@ -1,16 +0,0 @@ - -/*! - * [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) ObjectId - * @constructor NodeMongoDbObjectId - * @see ObjectId - */ - -'use strict'; - -const ObjectId = require('mongodb').ObjectId; - -/*! - * ignore - */ - -module.exports = exports = ObjectId; |