From 2080511363e9ee54f48cc3beb34fcde39f3ca814 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sat, 14 Dec 2024 16:12:55 +0100 Subject: [PATCH] style(connection): name some more function also add some "emits" jsdoc on private functions --- lib/connection.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 531541edab0..85f148fcaa3 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -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]; } @@ -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; @@ -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; @@ -939,6 +939,7 @@ Connection.prototype.error = function(err, callback) { /** * Called when the connection is opened * + * @emits "open" * @api private */ @@ -1240,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 @@ -1354,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 ' + @@ -1474,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) { @@ -1530,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) { @@ -1579,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); }; @@ -1591,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()); }; @@ -1604,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; } @@ -1622,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());