Skip to content

Commit

Permalink
removed optional chaining, for now
Browse files Browse the repository at this point in the history
  • Loading branch information
boycce committed Apr 30, 2024
1 parent b91d519 commit daba0c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Collection.prototype.drop = async function () {
await this.col.drop()
// this.col = null
} catch (err) {
if (err?.message == 'ns not found') return 'ns not found'
if ((err||{}).message == 'ns not found') return 'ns not found'
throw err
}
}
Expand Down Expand Up @@ -186,7 +186,7 @@ Collection.prototype.find = async function (query, opts) {
Collection.prototype.findOne = async function (query, opts) {
const args = await this._middleware({ query, opts })
const docs = await this.col.find(args.query, args.opts).limit(1).toArray()
return docs?.[0] || null
return (docs||{})[0] || null
}

Collection.prototype.findOneAndDelete = async function (query, opts) {
Expand All @@ -202,10 +202,10 @@ Collection.prototype.findOneAndUpdate = async function (query, update, opts) {
const args = await this._middleware({ query, update, opts })
let method = 'findOneAndUpdate'

if (typeof args.opts?.returnDocument === 'undefined') {
if (typeof (args.opts||{}).returnDocument === 'undefined') {
args.opts.returnDocument = 'after'
}
if (typeof args.opts?.returnOriginal !== 'undefined') {
if (typeof (args.opts||{}).returnOriginal !== 'undefined') {
this.manager.warn('The `returnOriginal` option is deprecated, use `returnDocument` instead.')
args.opts.returnDocument = args.opts.returnOriginal ? 'before' : 'after'
}
Expand All @@ -230,7 +230,7 @@ Collection.prototype.indexInformation = async function (opts) {
return await this.col.indexInformation(args.opts)
} catch (e) {
// col.indexInformation() throws an error if the collection is created yet...
if (e?.message.match(/ns does not exist/)) return {}
if ((e||{}).message.match(/ns does not exist/)) return {}
else throw new Error(e)
}
}
Expand All @@ -241,7 +241,7 @@ Collection.prototype.indexes = async function (opts) {
return await this.col.indexes(args.opts)
} catch (e) {
// col.indexes() throws an error if the collection is created yet...
if (e?.message.match(/ns does not exist/)) return []
if ((e||{}).message.match(/ns does not exist/)) return []
else throw new Error(e)
}
}
Expand Down Expand Up @@ -317,7 +317,7 @@ Collection.prototype.update = async function (query, update, opts) {
}

const doc = await this.col[method](args.query, args.update, args.opts)
// return doc?.result || doc
// return (doc||{}).result || doc
return doc
}

Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ Manager.prototype.get = function(name, options) {
* @param {Object} [options] - options to pass to the collection
* @return {MongoDB Collection}
*/
if (!this.collections[name] || options?.cache === false) {
delete options?.cache
if (!this.collections[name] || (options||{}).cache === false) {
delete (options||{}).cache
this.collections[name] = new Collection(this, name, options)
}
return this.collections[name]
Expand Down
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Model.prototype._setupIndexes = async function(fields, opts={}) {
let textIndex = { name: 'text', key: {} }

// No db defined
if (!model.manager?._state?.match(/^open/)) {
if (!((model.manager||{})._state||{}).match(/^open/)) {
throw new Error(`Skipping createIndex on the '${model.name||''}' model, no mongodb connection found.`)
}

Expand Down

0 comments on commit daba0c5

Please sign in to comment.