From daba0c5ccb9b74e68ff8748b34f90663ffcab9d3 Mon Sep 17 00:00:00 2001 From: Ricky Boyce Date: Tue, 30 Apr 2024 12:01:20 +1200 Subject: [PATCH] removed optional chaining, for now --- lib/collection.js | 14 +++++++------- lib/index.js | 4 ++-- lib/model.js | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/collection.js b/lib/collection.js index fadf0a4..13db9dd 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -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 } } @@ -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) { @@ -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' } @@ -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) } } @@ -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) } } @@ -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 } diff --git a/lib/index.js b/lib/index.js index c8ec074..475e198 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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] diff --git a/lib/model.js b/lib/model.js index 66c5c65..c736159 100644 --- a/lib/model.js +++ b/lib/model.js @@ -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.`) }