Skip to content

Commit

Permalink
style(connection): name some more function
Browse files Browse the repository at this point in the history
also add some "emits" jsdoc on private functions
  • Loading branch information
hasezoey committed Dec 14, 2024
1 parent 7ddbb0c commit 2080511
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 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 @@ -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
Expand Down Expand Up @@ -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 ' +
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
};

Expand All @@ -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());
};
Expand All @@ -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;
}
Expand All @@ -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());
Expand Down

0 comments on commit 2080511

Please sign in to comment.