Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more callback doc references & some small other changes #15095

Merged
merged 14 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ module.exports.Decimal128 = mongoose.Decimal128;
module.exports.Mixed = mongoose.Mixed;
module.exports.Date = mongoose.Date;
module.exports.Number = mongoose.Number;
module.exports.Double = mongoose.Double;
module.exports.Error = mongoose.Error;
module.exports.MongooseError = mongoose.MongooseError;
module.exports.now = mongoose.now;
Expand Down
58 changes: 40 additions & 18 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Object.defineProperty(Connection.prototype, 'readyState', {
* @api public
*/

Connection.prototype.get = function(key) {
Connection.prototype.get = function getOption(key) {
if (this.config.hasOwnProperty(key)) {
return this.config[key];
}
Expand Down Expand Up @@ -186,7 +186,7 @@ Connection.prototype.get = function(key) {
* @api public
*/

Connection.prototype.set = function(key, val) {
Connection.prototype.set = function setOption(key, val) {
if (this.config.hasOwnProperty(key)) {
this.config[key] = val;
return val;
Expand Down Expand Up @@ -925,7 +925,7 @@ Connection.prototype._shouldBufferCommands = function _shouldBufferCommands() {
* @api private
*/

Connection.prototype.error = function(err, callback) {
Connection.prototype.error = function error(err, callback) {
if (callback) {
callback(err);
return null;
Expand All @@ -939,6 +939,7 @@ Connection.prototype.error = function(err, callback) {
/**
* Called when the connection is opened
*
* @emits "open"
* @api private
*/

Expand Down Expand Up @@ -1043,23 +1044,43 @@ Connection.prototype.openUri = async function openUri(uri, options) {
return this;
};

/*!
* Treat `on('error')` handlers as handling the initialConnection promise
* to avoid uncaught exceptions when using `on('error')`. See gh-14377.
/**
* Listen to events in the Connection
*
* @param {String} event The event to listen on
* @param {Function} callback
* @see Connection#readyState https://mongoosejs.com/docs/api/connection.html#Connection.prototype.readyState
*
* @method on
* @instance
* @memberOf Connection
* @api public
*/

// Treat `on('error')` handlers as handling the initialConnection promise
// to avoid uncaught exceptions when using `on('error')`. See gh-14377.
Connection.prototype.on = function on(event, callback) {
if (event === 'error' && this.$initialConnection) {
this.$initialConnection.catch(() => {});
}
return EventEmitter.prototype.on.call(this, event, callback);
};

/*!
* Treat `once('error')` handlers as handling the initialConnection promise
* to avoid uncaught exceptions when using `on('error')`. See gh-14377.
/**
* Listen to a event once in the Connection
*
* @param {String} event The event to listen on
* @param {Function} callback
* @see Connection#readyState https://mongoosejs.com/docs/api/connection.html#Connection.prototype.readyState
*
* @method once
* @instance
* @memberOf Connection
* @api public
*/

// Treat `on('error')` handlers as handling the initialConnection promise
// to avoid uncaught exceptions when using `on('error')`. See gh-14377.
Connection.prototype.once = function on(event, callback) {
if (event === 'error' && this.$initialConnection) {
this.$initialConnection.catch(() => {});
Expand Down Expand Up @@ -1220,17 +1241,18 @@ Connection.prototype._close = async function _close(force, destroy) {
* @api private
*/

Connection.prototype.doClose = function() {
Connection.prototype.doClose = function doClose() {
throw new Error('Connection#doClose unimplemented by driver');
};

/**
* Called when the connection closes
*
* @emits "close"
* @api private
*/

Connection.prototype.onClose = function(force) {
Connection.prototype.onClose = function onClose(force) {
this.readyState = STATES.disconnected;

// avoid having the collection subscribe to our event emitter
Expand Down Expand Up @@ -1334,7 +1356,7 @@ Connection.prototype.plugin = function(fn, opts) {
* @api public
*/

Connection.prototype.model = function(name, schema, collection, options) {
Connection.prototype.model = function model(name, schema, collection, options) {
if (!(this instanceof Connection)) {
throw new MongooseError('`connection.model()` should not be run with ' +
'`new`. If you are doing `new db.model(foo)(bar)`, use ' +
Expand Down Expand Up @@ -1454,7 +1476,7 @@ Connection.prototype.model = function(name, schema, collection, options) {
* @return {Connection} this
*/

Connection.prototype.deleteModel = function(name) {
Connection.prototype.deleteModel = function deleteModel(name) {
if (typeof name === 'string') {
const model = this.model(name);
if (model == null) {
Expand Down Expand Up @@ -1510,7 +1532,7 @@ Connection.prototype.deleteModel = function(name) {
* @return {ChangeStream} mongoose-specific change stream wrapper, inherits from EventEmitter
*/

Connection.prototype.watch = function(pipeline, options) {
Connection.prototype.watch = function watch(pipeline, options) {
const changeStreamThunk = cb => {
immediate(() => {
if (this.readyState === STATES.connecting) {
Expand Down Expand Up @@ -1559,7 +1581,7 @@ Connection.prototype.asPromise = async function asPromise() {
* @return {String[]}
*/

Connection.prototype.modelNames = function() {
Connection.prototype.modelNames = function modelNames() {
return Object.keys(this.models);
};

Expand All @@ -1571,7 +1593,7 @@ Connection.prototype.modelNames = function() {
* @api private
* @return {Boolean} true if the connection should be authenticated after it is opened, otherwise false.
*/
Connection.prototype.shouldAuthenticate = function() {
Connection.prototype.shouldAuthenticate = function shouldAuthenticate() {
return this.user != null &&
(this.pass != null || this.authMechanismDoesNotRequirePassword());
};
Expand All @@ -1584,7 +1606,7 @@ Connection.prototype.shouldAuthenticate = function() {
* @return {Boolean} true if the authentication mechanism specified in the options object requires
* a password, otherwise false.
*/
Connection.prototype.authMechanismDoesNotRequirePassword = function() {
Connection.prototype.authMechanismDoesNotRequirePassword = function authMechanismDoesNotRequirePassword() {
if (this.options && this.options.auth) {
return noPasswordAuthMechanisms.indexOf(this.options.auth.authMechanism) >= 0;
}
Expand All @@ -1602,7 +1624,7 @@ Connection.prototype.authMechanismDoesNotRequirePassword = function() {
* @return {Boolean} true if the provided options object provides enough data to authenticate with,
* otherwise false.
*/
Connection.prototype.optionsProvideAuthenticationData = function(options) {
Connection.prototype.optionsProvideAuthenticationData = function optionsProvideAuthenticationData(options) {
return (options) &&
(options.user) &&
((options.pass) || this.authMechanismDoesNotRequirePassword());
Expand Down
3 changes: 1 addition & 2 deletions lib/cursor/aggregationCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,10 @@ AggregationCursor.prototype._markError = function(error) {
* Marks this cursor as closed. Will stop streaming and subsequent calls to
* `next()` will error.
*
* @param {Function} callback
* @return {Promise}
* @api public
* @method close
* @emits close
* @emits "close"
* @see AggregationCursor.close https://mongodb.github.io/node-mongodb-native/4.9/classes/AggregationCursor.html#close
*/

Expand Down
6 changes: 2 additions & 4 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ function init(self, obj, doc, opts, prefix) {
*
* #### Example:
*
* weirdCar.updateOne({$inc: {wheels:1}}, { w: 1 }, callback);
* weirdCar.updateOne({$inc: {wheels:1}}, { w: 1 });
*
* #### Valid options:
*
Expand All @@ -843,7 +843,6 @@ function init(self, obj, doc, opts, prefix) {
* @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](https://mongoosejs.com/docs/api/query.html#Query.prototype.lean()) and the [Mongoose lean tutorial](https://mongoosejs.com/docs/tutorials/lean.html).
* @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
* @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
* @param {Function} [callback]
* @return {Query}
* @api public
* @memberOf Document
Expand Down Expand Up @@ -3439,12 +3438,11 @@ function _checkImmutableSubpaths(subdoc, schematype, priorVal) {
* @param {Number} [options.wtimeout] sets a [timeout for the write concern](https://www.mongodb.com/docs/manual/reference/write-concern/#wtimeout). Overrides the [schema-level `writeConcern` option](https://mongoosejs.com/docs/guide.html#writeConcern).
* @param {Boolean} [options.checkKeys=true] the MongoDB driver prevents you from saving keys that start with '$' or contain '.' by default. Set this option to `false` to skip that check. See [restrictions on field names](https://www.mongodb.com/docs/manual/reference/limits/#Restrictions-on-Field-Names)
* @param {Boolean} [options.timestamps=true] if `false` and [timestamps](https://mongoosejs.com/docs/guide.html#timestamps) are enabled, skip timestamps for this `save()`.
* @param {Function} [fn] optional callback
* @method save
* @memberOf Document
* @instance
* @throws {DocumentNotFoundError} if this [save updates an existing document](https://mongoosejs.com/docs/api/document.html#Document.prototype.isNew()) but the document doesn't exist in the database. For example, you will get this error if the document is [deleted between when you retrieved the document and when you saved it](documents.html#updating).
* @return {Promise|undefined} Returns undefined if used with callback or a Promise otherwise.
* @return {Promise}
* @api public
* @see middleware https://mongoosejs.com/docs/middleware.html
*/
Expand Down
1 change: 0 additions & 1 deletion lib/drivers/node-mongodb-native/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ function format(obj, sub, color, shell) {
/**
* Retrieves information about this collections indexes.
*
* @param {Function} callback
* @method getIndexes
* @api public
*/
Expand Down
9 changes: 2 additions & 7 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ Model.$where = function $where() {
/**
* Issues a mongodb findOneAndUpdate command.
*
* Finds a matching document, updates it according to the `update` arg, passing any `options`, and returns the found document (if any) to the callback. The query executes if `callback` is passed else a Query object is returned.
* Finds a matching document, updates it according to the `update` arg, passing any `options`. A Query object is returned.
*
* #### Example:
*
Expand Down Expand Up @@ -3992,7 +3992,7 @@ function _update(model, op, conditions, doc, options) {
/**
* Performs [aggregations](https://www.mongodb.com/docs/manual/aggregation/) on the models collection.
*
* If a `callback` is passed, the `aggregate` is executed and a `Promise` is returned. If a callback is not passed, the `aggregate` itself is returned.
* The `aggregate` itself is returned.
*
* This function triggers the following middleware.
*
Expand Down Expand Up @@ -4047,10 +4047,6 @@ Model.aggregate = function aggregate(pipeline, options) {
aggregate.option(options);
}

if (typeof callback === 'undefined') {
return aggregate;
}

return aggregate;
};

Expand Down Expand Up @@ -4238,7 +4234,6 @@ Model.validate = async function validate(obj, pathsOrOptions, context) {
* @param {Object} [options.options=null] Additional options like `limit` and `lean`.
* @param {Function} [options.transform=null] Function that Mongoose will call on every populated document that allows you to transform the populated document.
* @param {Boolean} [options.forceRepopulate=true] Set to `false` to prevent Mongoose from repopulating paths that are already populated
* @param {Function} [callback(err,doc)] Optional callback, executed upon completion. Receives `err` and the `doc(s)`.
* @return {Promise}
* @api public
*/
Expand Down
Loading
Loading