From bb3d120c1f71c8094f68b5540a9c4239455a5458 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 29 Sep 2023 12:10:12 +0100 Subject: [PATCH 001/193] feat: upgrade docker-compose.yml from deprecated syntax --- docker-compose.yml | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f4a773433..05953338b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,24 @@ -adapter: - image: node:12 - volumes: - - $PWD:/home/node/sails-mongo - links: - - mongo - environment: - - WATERLINE_ADAPTER_TESTS_DATABASE=sails-mongo - - WATERLINE_ADAPTER_TESTS_URL=mongo/testdb - - WATERLINE_ADAPTER_TESTS_HOST=mongo - - NODE_ENV=test - user: node - working_dir: /home/node/sails-mongo - command: - - bash -c "npm test" +version: '3' +services: + adapter: + image: node:20 + volumes: + - $PWD:/home/node/sails-mongo + links: + - mongo + environment: + - WATERLINE_ADAPTER_TESTS_DATABASE=sails-mongo + - WATERLINE_ADAPTER_TESTS_URL=mongo/testdb + - WATERLINE_ADAPTER_TESTS_HOST=mongo + - NODE_ENV=test + user: node + working_dir: /home/node/sails-mongo + command: + - bash -c "npm test" -mongo: - image: mongo:4.2 - restart: always - command: "--logpath=/dev/null" - ports: - - "27017:27017" + mongo: + image: mongo:6.0 + restart: always + command: "--logpath=/dev/null" + ports: + - "27017:27017" From b70cb736262d598e6be11cd191eb013e0c0e3572 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 29 Sep 2023 12:13:41 +0100 Subject: [PATCH 002/193] chore: update mongodb driver to 6.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 112875582..f239af8b6 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "async": "3.2.4", "flaverr": "^1.10.0", "machine": "^15.2.2", - "mongodb": "3.7.3", + "mongodb": "6.1.0", "qs": "6.9.7" }, "devDependencies": { From fa906e57f455e4fe4d05eac6ddd3b8a1996c5bc7 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 29 Sep 2023 12:26:31 +0100 Subject: [PATCH 003/193] feat: remove deprecated client option --- lib/private/machines/create-manager.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index bd64f0d4d..9c4d87016 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -125,14 +125,6 @@ module.exports = { var mongoUrl = _clientConfig.url; _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); - // Use unified topology. MongoDB node maintainers recommends this to be enabled - // https://github.com/mongodb/node-mongodb-native/releases/tag/v3.2.1 - // Use new url parser to remove warnings - _clientConfig = Object.assign({ - useNewUrlParser: true, - useUnifiedTopology: true - }, _clientConfig); - // http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html#.connect NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig, function connectCb(err, client) { if (err) { From 5d1ef99755366b4dcb1e23b3ce2d2d1c9c333d47 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 29 Sep 2023 12:47:59 +0100 Subject: [PATCH 004/193] feat: update connect() to promise-based syntax --- lib/private/machines/create-manager.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index 9c4d87016..787df9fec 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -91,6 +91,7 @@ module.exports = { fn: function (inputs, exits) { + // @ts-ignore var _ = require('@sailshq/lodash'); var NodeMongoDBNativeLib = require('mongodb'); var CONFIG_WHITELIST = require('../constants/config-whitelist.constant'); @@ -125,13 +126,12 @@ module.exports = { var mongoUrl = _clientConfig.url; _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); - // http://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html#.connect - NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig, function connectCb(err, client) { - if (err) { - return exits.error(err); - } + // https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect/ + NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig) + .then(function (client) { var manager = client.db(_clientConfig.database); + // @ts-ignore manager.client = client; // Now mutate this manager, giving it a telltale. @@ -142,13 +142,14 @@ module.exports = { // > (^^But that's not the real reason to include it -- we ended up solving it differently // > anyway. No, the real reason is so that there's a way to tell if a given Mongo client // > instance came from mp-mongo or not, for debugging reasons.) + // @ts-ignore manager._isFromMPMongo = true; return exits.success({ manager: manager, meta: inputs.meta }); - });// + }).catch(function(err) { exits.error(err); });// } From 6e918a5320bbda1a1469a7e505629d3cbc366749 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 10:43:43 +0100 Subject: [PATCH 005/193] chore: upgrade mongodb to 4.x and eslint to 8.x --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index f239af8b6..a69d8ae13 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,12 @@ "async": "3.2.4", "flaverr": "^1.10.0", "machine": "^15.2.2", - "mongodb": "6.1.0", + "mongodb": "^4.17.1", "qs": "6.9.7" }, "devDependencies": { "benchmark": "2.1.4", - "eslint": "4.19.1", + "eslint": "^8.50.0", "mocha": "3.0.2", "waterline": "^0.13.6", "waterline-adapter-tests": "^1.0.1", From ec3dad7b7f557b177ef820eb2fbca1551b85ad30 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 10:43:58 +0100 Subject: [PATCH 006/193] chore: update ecmaVersion to 14 --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 80fa6bfff..ddf2ee84d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,7 @@ }, "parserOptions": { - "ecmaVersion": 5 + "ecmaVersion": 14 // ^^This can be changed to `8` if this package doesn't need to support <= Node v6. }, From c579e5871d3eb52b0f1acca395ddaf7e6044d68b Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 10:53:42 +0100 Subject: [PATCH 007/193] fix: use findOne to get back the newly created document --- lib/private/machines/create-record.js | 38 ++++++++------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 22d390657..510ee7fbc 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -29,7 +29,7 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - var util = require('util'); + // @ts-ignore var _ = require('@sailshq/lodash'); var processNativeRecord = require('./private/process-native-record'); var processNativeError = require('./private/process-native-error'); @@ -76,43 +76,21 @@ module.exports = { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var db = inputs.connection; var mongoCollection = db.collection(tableName); - mongoCollection.insertOne(s3q.newRecord, function (err, nativeResult) { - if (err) { - err = processNativeError(err); - if (err.footprint && err.footprint.identity === 'notUnique') { - return exits.notUnique(err); - } - return exits.error(err); - }//-• - - + mongoCollection.insertOne(s3q.newRecord).then(async function documentInserted(nativeResult) { // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // FUTURE: Provide access to `insertId` somehow, even if `fetch` is not enabled: - // ``` - // var insertId = nativeResult.insertedId; - // ``` - // (Changes would need to happen in driver spec first---see: - // https://github.com/node-machine/driver-interface) - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - return exits.success(); + return exits.success({ _id: nativeResult.insertedId }); }//-• // Otherwise, IWMIH we'll be sending back a record: // ============================================ - // Sanity check: Verify that there is only one record. - if (nativeResult.ops.length !== 1) { - return exits.error(new Error('Consistency violation: Unexpected # of records returned from Mongo (in `.ops`). Native result:\n```\n'+util.inspect(nativeResult, {depth: 5})+'\n```')); - } - // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐ // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ ││ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘ // Process record (mutate in-place) to wash away adapter-specific eccentricities. - var phRecord = nativeResult.ops[0]; + var phRecord = await mongoCollection.findOne({ _id: nativeResult.insertedId }); try { processNativeRecord(phRecord, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -120,6 +98,12 @@ module.exports = { // Then send it back. return exits.success(phRecord); - }); // + }).catch(function(err) { + err = processNativeError(err); + if (err.footprint && err.footprint.identity === 'notUnique') { + return exits.notUnique(err); + } + return exits.error(err); + }); // } }; From 15fe1c490d0675f4be1efb79f6696dd10146778f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 10:58:36 +0100 Subject: [PATCH 008/193] fix: use id not _id --- lib/private/machines/create-record.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 510ee7fbc..dbc2e8865 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -79,7 +79,7 @@ module.exports = { mongoCollection.insertOne(s3q.newRecord).then(async function documentInserted(nativeResult) { // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { - return exits.success({ _id: nativeResult.insertedId }); + return exits.success({ id: nativeResult.insertedId }); }//-• From 63180396643946fb65dc10abb48bdbda6ab02d5e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 11:02:42 +0100 Subject: [PATCH 009/193] chore: update var declarations to const/let --- lib/private/machines/create-record.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index dbc2e8865..06f384771 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -30,22 +30,22 @@ module.exports = { fn: function (inputs, exits) { // Dependencies // @ts-ignore - var _ = require('@sailshq/lodash'); - var processNativeRecord = require('./private/process-native-record'); - var processNativeError = require('./private/process-native-error'); - var reifyValuesToSet = require('./private/reify-values-to-set'); + const _ = require('@sailshq/lodash'); + const processNativeRecord = require('./private/process-native-record'); + const processNativeError = require('./private/process-native-error'); + const reifyValuesToSet = require('./private/reify-values-to-set'); // Local var for the stage 3 query, for easier access. - var s3q = inputs.query; + const s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (CREATE RECORD):',require('util').inspect(s3q,{depth:5}),'\n'); } // Local var for the `tableName`, for clarity. - var tableName = s3q.using; + const tableName = s3q.using; // Grab the model definition - var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -62,7 +62,7 @@ module.exports = { // ╔╦╗╔═╗╔╦╗╔═╗╦═╗╔╦╗╦╔╗╔╔═╗ ┬ ┬┬ ┬┌─┐┌┬┐┬ ┬┌─┐┬─┐ ┌┬┐┌─┐ ╔═╗╔═╗╔╦╗╔═╗╦ ╦ ┌─┐┬─┐ ┌┐┌┌─┐┌┬┐ // ║║║╣ ║ ║╣ ╠╦╝║║║║║║║║╣ │││├─┤├┤ │ ├─┤├┤ ├┬┘ │ │ │ ╠╣ ║╣ ║ ║ ╠═╣ │ │├┬┘ ││││ │ │ // ═╩╝╚═╝ ╩ ╚═╝╩╚═╩ ╩╩╝╚╝╚═╝ └┴┘┴ ┴└─┘ ┴ ┴ ┴└─┘┴└─ ┴ └─┘ ╚ ╚═╝ ╩ ╚═╝╩ ╩ └─┘┴└─ ┘└┘└─┘ ┴ - var isFetchEnabled; + let isFetchEnabled; if (s3q.meta && s3q.meta.fetch) { isFetchEnabled = true; } else { isFetchEnabled = false; } @@ -74,8 +74,8 @@ module.exports = { // FUTURE: Carry through the `fetch: false` optimization all the way to Mongo here, // if possible (e.g. using Mongo's projections API) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var db = inputs.connection; - var mongoCollection = db.collection(tableName); + const db = inputs.connection; + const mongoCollection = db.collection(tableName); mongoCollection.insertOne(s3q.newRecord).then(async function documentInserted(nativeResult) { // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { @@ -90,7 +90,7 @@ module.exports = { // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ ││ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘ // Process record (mutate in-place) to wash away adapter-specific eccentricities. - var phRecord = await mongoCollection.findOne({ _id: nativeResult.insertedId }); + const phRecord = await mongoCollection.findOne({ _id: nativeResult.insertedId }); try { processNativeRecord(phRecord, WLModel, s3q.meta); } catch (e) { return exits.error(e); } From 0ec5228fa5759fb2dd959bc3d87a87e21cbb5128 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 12:06:35 +0100 Subject: [PATCH 010/193] chore: change comment for .insertOne end --- lib/private/machines/create-record.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 06f384771..9d203d1e5 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -104,6 +104,6 @@ module.exports = { return exits.notUnique(err); } return exits.error(err); - }); // + }); // } }; From 2a39aadf8e431da4cd942fb1c997bd54b3148a75 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 12:09:29 +0100 Subject: [PATCH 011/193] feat: move to new syntax for insertMany and return records created via find --- lib/private/machines/create-each-record.js | 38 ++++++++++------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/private/machines/create-each-record.js b/lib/private/machines/create-each-record.js index 57ad7cd83..b95d4b942 100644 --- a/lib/private/machines/create-each-record.js +++ b/lib/private/machines/create-each-record.js @@ -29,15 +29,15 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - var _ = require('@sailshq/lodash'); - var processNativeRecord = require('./private/process-native-record'); - var processNativeError = require('./private/process-native-error'); - var reifyValuesToSet = require('./private/reify-values-to-set'); + const _ = require('@sailshq/lodash'); + const processNativeRecord = require('./private/process-native-record'); + const processNativeError = require('./private/process-native-error'); + const reifyValuesToSet = require('./private/reify-values-to-set'); // Local var for the stage 3 query, for easier access. - var s3q = inputs.query; + const s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (CREATE EACH RECORD):',require('util').inspect(s3q,{depth:5}),'\n'); } @@ -46,7 +46,7 @@ module.exports = { var tableName = s3q.using; // Grab the model definition - var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -65,7 +65,7 @@ module.exports = { // ╔╦╗╔═╗╔╦╗╔═╗╦═╗╔╦╗╦╔╗╔╔═╗ ┬ ┬┬ ┬┌─┐┌┬┐┬ ┬┌─┐┬─┐ ┌┬┐┌─┐ ╔═╗╔═╗╔╦╗╔═╗╦ ╦ ┌─┐┬─┐ ┌┐┌┌─┐┌┬┐ // ║║║╣ ║ ║╣ ╠╦╝║║║║║║║║╣ │││├─┤├┤ │ ├─┤├┤ ├┬┘ │ │ │ ╠╣ ║╣ ║ ║ ╠═╣ │ │├┬┘ ││││ │ │ // ═╩╝╚═╝ ╩ ╚═╝╩╚═╩ ╩╩╝╚╝╚═╝ └┴┘┴ ┴└─┘ ┴ ┴ ┴└─┘┴└─ ┴ └─┘ ╚ ╚═╝ ╩ ╚═╝╩ ╩ └─┘┴└─ ┘└┘└─┘ ┴ - var isFetchEnabled; + let isFetchEnabled; if (s3q.meta && s3q.meta.fetch) { isFetchEnabled = true; } else { isFetchEnabled = false; } @@ -77,26 +77,18 @@ module.exports = { // FUTURE: Carry through the `fetch: false` optimization all the way to Mongo here, // if possible (e.g. using Mongo's projections API) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var db = inputs.connection; - var mongoCollection = db.collection(tableName); + const db = inputs.connection; + const mongoCollection = db.collection(tableName); // if (s3q.meta && s3q.meta.logMongoS3Qs) { // console.log('- - - - - - - - - -CREATE EACH: s3q.newRecords:',require('util').inspect(s3q.newRecords,{depth:5}),'\n'); // } - mongoCollection.insertMany(s3q.newRecords, function (err, nativeResult) { - if (err) { - err = processNativeError(err); - if (err.footprint && err.footprint.identity === 'notUnique') { - return exits.notUnique(err); - } - return exits.error(err); - }//-• - - + mongoCollection.insertMany(s3q.newRecords).then(async function (nativeResult) { // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { return exits.success(); }//-• + const insertedIds = Object.values(nativeResult.insertedIds); // Otherwise, IWMIH we'll be sending back records: // ============================================ @@ -105,7 +97,7 @@ module.exports = { // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ │││ └─┐ │ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘└─└─┘─┘ // Process record(s) (mutate in-place) to wash away adapter-specific eccentricities. - var phRecords = nativeResult.ops; + const phRecords = await mongoCollection.find({ _id: { $in: insertedIds } }).toArray(); try { _.each(phRecords, function (phRecord){ processNativeRecord(phRecord, WLModel, s3q.meta); @@ -114,6 +106,12 @@ module.exports = { return exits.success(phRecords); + }).catch(function(err) { + err = processNativeError(err); + if (err.footprint && err.footprint.identity === 'notUnique') { + return exits.notUnique(err); + } + return exits.error(err); }); // } From 31e6a9a9d1b8ee99b25f4f3687a9753b8bf82ddd Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 12:31:20 +0100 Subject: [PATCH 012/193] feat: replace deprecated .count with .countDocuments --- lib/private/machines/count-records.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/private/machines/count-records.js b/lib/private/machines/count-records.js index 5d0e7156b..70c1e8220 100644 --- a/lib/private/machines/count-records.js +++ b/lib/private/machines/count-records.js @@ -28,20 +28,20 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - var _ = require('@sailshq/lodash'); - var buildMongoWhereClause = require('./private/build-mongo-where-clause'); + const _ = require('@sailshq/lodash'); + const buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - var s3q = inputs.query; + const s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (COUNT RECORDS):',require('util').inspect(s3q,{depth:5}),'\n'); } // Local var for the `tableName`, for clarity. - var tableName = s3q.using; + const tableName = s3q.using; // Grab the model definition - var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -50,7 +50,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - var mongoWhere; + let mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -59,13 +59,11 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - var db = inputs.connection; - var mongoCollection = db.collection(tableName); - mongoCollection.find(mongoWhere).count(function countCb(err, nativeResult) { - if (err) { return exits.error(err); } - + const db = inputs.connection; + const mongoCollection = db.collection(tableName); + mongoCollection.countDocuments(mongoWhere).then(function count(nativeResult) { return exits.success(nativeResult); - }); + }).catch(function (err) { return exits.error(err); }); } From 190633515af214830a078af3b258297b4988e500 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 18:31:49 +0100 Subject: [PATCH 013/193] chore: add return --- lib/private/machines/create-manager.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index 787df9fec..c0168959f 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -129,7 +129,6 @@ module.exports = { // https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect/ NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig) .then(function (client) { - var manager = client.db(_clientConfig.database); // @ts-ignore manager.client = client; @@ -149,7 +148,7 @@ module.exports = { manager: manager, meta: inputs.meta }); - }).catch(function(err) { exits.error(err); });// + }).catch(function(err) { return exits.error(err); });// } From b30146400162d7e699d649e9c75c160d8846a885 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 18:46:36 +0100 Subject: [PATCH 014/193] chore: move to mongodb 5 driver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a69d8ae13..52a8667fd 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "async": "3.2.4", "flaverr": "^1.10.0", "machine": "^15.2.2", - "mongodb": "^4.17.1", + "mongodb": "^5.9.0", "qs": "6.9.7" }, "devDependencies": { From 16506bd7f983c21161ea41e3d732627f7d3b493b Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 19:02:15 +0100 Subject: [PATCH 015/193] chore: migrate drop to promies --- lib/index.js | 53 ++++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/lib/index.js b/lib/index.js index 531c779fb..221f2d068 100644 --- a/lib/index.js +++ b/lib/index.js @@ -743,9 +743,8 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ define: function (datastoreName, tableName, phmDef, done) { - // Look up the datastore entry (manager/driver/config). - var dsEntry = registeredDsEntries[datastoreName]; + const dsEntry = registeredDsEntries[datastoreName]; // Sanity check: if (_.isUndefined(dsEntry)) { @@ -763,7 +762,7 @@ module.exports = { // Build an array of any UNIQUE indexes needed // > Go through each item in the definition to locate fields // > which demand a uniqueness constraint. - var uniqueIndexesToCreate = []; + const uniqueIndexesToCreate = []; _.each(phmDef, function (phmAttrDef, key) { if (_.has(phmAttrDef, 'unique') && phmAttrDef.unique) { uniqueIndexesToCreate.push(key); @@ -783,8 +782,8 @@ module.exports = { // Otherwise we'll need to create some indexes.... // First, get a reference to the Mongo collection. - var db = dsEntry.manager; - var mongoCollection = db.collection(tableName); + const db = dsEntry.manager; + const mongoCollection = db.collection(tableName); // Then simultaneously create all of the indexes: async.each(uniqueIndexesToCreate, function (key, next) { @@ -794,7 +793,7 @@ module.exports = { // // > This is the definition for a "single-field index". // > (https://docs.mongodb.com/manual/indexes/#index-types) - var mongoSingleFieldIdxKeys = {}; + const mongoSingleFieldIdxKeys = {}; mongoSingleFieldIdxKeys[key] = 1; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ^^^NOTE: @@ -847,10 +846,9 @@ module.exports = { * @param {Error?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - drop: function (datastoreName, tableName, unused, done) { - + drop: async function (datastoreName, tableName, unused, done) { // Look up the datastore entry (manager/driver/config). - var dsEntry = registeredDsEntries[datastoreName]; + const dsEntry = registeredDsEntries[datastoreName]; // Sanity check: if (_.isUndefined(dsEntry)) { @@ -858,31 +856,24 @@ module.exports = { } // Drop the physical model (e.g. table/etc.) - var db = dsEntry.manager; - db.collection(tableName).drop(function (err) { - try { - - if (err) { - if (err.errmsg === 'ns not found') { - throw flaverr('E_PHM_NOT_FOUND', new Error('No such physical model is currently defined.')); - } - else if (_.isError(err)) { throw err; } - else { throw new Error('Consistency violation: Expecting Error instance, but instead got: '+util.inspect(err)); } - }//>- - - } catch (e) { - switch (e.code) { - case 'E_PHM_NOT_FOUND': break; - default: - e.raw = err; - return done(e); - } - }// - + const db = dsEntry.manager; + db.collection(tableName).drop().then(function (dropped) { // >-• // IWMIH, then either the physical model was successfully dropped, // or it didn't exist in the first place. - return done(); + return done(dropped); + }).catch(function (err) { + switch (err.code) { + case 'E_PHM_NOT_FOUND': break; + default: + err.raw = err; + return done(err); + } + if (err.errmsg === 'ns not found') { + throw flaverr('E_PHM_NOT_FOUND', new Error('No such physical model is currently defined.')); + } + else if (_.isError(err)) { throw err; } + else { throw new Error('Consistency violation: Expecting Error instance, but instead got: '+util.inspect(err)); } });// }, From 337fac485451b52337e4d5c9578fc7eae816d61a Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 19:12:35 +0100 Subject: [PATCH 016/193] fix: remove dropped from callback --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 221f2d068..0e1512ca7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -857,11 +857,11 @@ module.exports = { // Drop the physical model (e.g. table/etc.) const db = dsEntry.manager; - db.collection(tableName).drop().then(function (dropped) { + db.collection(tableName).drop().then(function () { // >-• // IWMIH, then either the physical model was successfully dropped, // or it didn't exist in the first place. - return done(dropped); + return done(); }).catch(function (err) { switch (err.code) { case 'E_PHM_NOT_FOUND': break; From 97f981023a8085df63b5d849260413705224e6c5 Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 1 Oct 2023 13:26:30 -0500 Subject: [PATCH 017/193] Fixes typo --- test/run-adapter-specific-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 557fb7d33..d6ceef00d 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -49,7 +49,7 @@ describe('aggregations', function() { return done(); }); - it('should not throw an error if the given critieria don\'t match any records', function(done) { + it('should not throw an error if the given criteria don\'t match any records', function(done) { models.user.sum('id', {name: 'joe'}).exec(function(err, sum) { if (err) { return done(err); } assert.equal(sum, 0); From 0636f4c343ee1969a8a3c40ee817001dc97a5c39 Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sun, 1 Oct 2023 13:27:36 -0500 Subject: [PATCH 018/193] sum aggregation: Change from callback to promises avg aggregation: Change from callback to promises --- lib/private/machines/sum-records.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index 490077da3..4a0a0b60a 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -76,13 +76,15 @@ module.exports = { } ], { cursor: {} }); - cursor.toArray(function aggregateCb(err, nativeResult) { - if (err) { return exits.error(err); } - - var sum = 0; - if (_.first(nativeResult)) { sum = _.first(nativeResult).sum; } + cursor.toArray().then((nativeResult) => { + let sum = 0; + if( _.first(nativeResult) ) { + sum = _.first(nativeResult).sum; + } return exits.success(sum); - });// + }).catch((err) => { + return exits.error(err); + }); // } }; From cf3b4fa8c6aaf93a4110d68a0d5f4da9086f515f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 19:45:33 +0100 Subject: [PATCH 019/193] chore: reverting to callbacks until ns not found fix --- lib/private/machines/avg-records.js | 1 - lib/private/machines/sum-records.js | 14 ++++++-------- package.json | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/private/machines/avg-records.js b/lib/private/machines/avg-records.js index d48ec9f4c..0457dfe98 100644 --- a/lib/private/machines/avg-records.js +++ b/lib/private/machines/avg-records.js @@ -84,5 +84,4 @@ module.exports = { return exits.success(mean); });// } - }; diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index 4a0a0b60a..490077da3 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -76,15 +76,13 @@ module.exports = { } ], { cursor: {} }); - cursor.toArray().then((nativeResult) => { - let sum = 0; - if( _.first(nativeResult) ) { - sum = _.first(nativeResult).sum; - } + cursor.toArray(function aggregateCb(err, nativeResult) { + if (err) { return exits.error(err); } + + var sum = 0; + if (_.first(nativeResult)) { sum = _.first(nativeResult).sum; } return exits.success(sum); - }).catch((err) => { - return exits.error(err); - }); // + });// } }; diff --git a/package.json b/package.json index 52a8667fd..a69d8ae13 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "async": "3.2.4", "flaverr": "^1.10.0", "machine": "^15.2.2", - "mongodb": "^5.9.0", + "mongodb": "^4.17.1", "qs": "6.9.7" }, "devDependencies": { From 222d25f06a14eb36cc82f442261d0ca7297c0477 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 20:28:46 +0100 Subject: [PATCH 020/193] fix: retain error handling for drop --- lib/index.js | 29 ++++++++++++++++++----------- package.json | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/index.js b/lib/index.js index 0e1512ca7..81acf0fc3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -863,17 +863,24 @@ module.exports = { // or it didn't exist in the first place. return done(); }).catch(function (err) { - switch (err.code) { - case 'E_PHM_NOT_FOUND': break; - default: - err.raw = err; - return done(err); - } - if (err.errmsg === 'ns not found') { - throw flaverr('E_PHM_NOT_FOUND', new Error('No such physical model is currently defined.')); - } - else if (_.isError(err)) { throw err; } - else { throw new Error('Consistency violation: Expecting Error instance, but instead got: '+util.inspect(err)); } + try { + + if (err) { + if (err.errmsg === 'ns not found') { + throw flaverr('E_PHM_NOT_FOUND', new Error('No such physical model is currently defined.')); + } + else if (_.isError(err)) { throw err; } + else { throw new Error('Consistency violation: Expecting Error instance, but instead got: '+util.inspect(err)); } + }//>- + + } catch (e) { + switch (e.code) { + case 'E_PHM_NOT_FOUND': break; + default: + e.raw = err; + return done(e); + } + }// });// }, diff --git a/package.json b/package.json index a69d8ae13..52a8667fd 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "async": "3.2.4", "flaverr": "^1.10.0", "machine": "^15.2.2", - "mongodb": "^4.17.1", + "mongodb": "^5.9.0", "qs": "6.9.7" }, "devDependencies": { From c91383424c174db4f2ecebbf77fc348ef6fbe83f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 20:48:23 +0100 Subject: [PATCH 021/193] fix: add needed done() --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 81acf0fc3..fcd775760 100644 --- a/lib/index.js +++ b/lib/index.js @@ -864,7 +864,6 @@ module.exports = { return done(); }).catch(function (err) { try { - if (err) { if (err.errmsg === 'ns not found') { throw flaverr('E_PHM_NOT_FOUND', new Error('No such physical model is currently defined.')); @@ -880,6 +879,7 @@ module.exports = { e.raw = err; return done(e); } + return done(); }// });// From 1ea5d219b1c4416223eb974b5ed833f2c572ae1c Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 20:49:13 +0100 Subject: [PATCH 022/193] feat: move sum-records to promise and const/let --- lib/private/machines/sum-records.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index 490077da3..0199e2102 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -28,24 +28,24 @@ module.exports = { fn: function sum(inputs, exits) { // Dependencies - var _ = require('@sailshq/lodash'); - var buildMongoWhereClause = require('./private/build-mongo-where-clause'); + const _ = require('@sailshq/lodash'); + const buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - var s3q = inputs.query; + const s3q = inputs.query; // Local var for the `tableName`, for clarity. - var tableName = s3q.using; + const tableName = s3q.using; // Local var for the name of the numeric field, for clarity. // // > Remember: Contrary to what you might think given its naming, // > by the time it gets to the adapter (in an s3q), the `numericAttrName` // > qk has already been normalized to be a column name, not an attribute name. - var numericFieldName = s3q.numericAttrName; + let numericFieldName = s3q.numericAttrName; // Grab the model definition - var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + let WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -54,7 +54,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - var mongoWhere; + let mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -62,9 +62,9 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - var db = inputs.connection; - var mongoCollection = db.collection(tableName); - var cursor = mongoCollection.aggregate([ + const db = inputs.connection; + const mongoCollection = db.collection(tableName); + const cursor = mongoCollection.aggregate([ { $match: mongoWhere }, { $group: { @@ -76,13 +76,12 @@ module.exports = { } ], { cursor: {} }); - cursor.toArray(function aggregateCb(err, nativeResult) { - if (err) { return exits.error(err); } - - var sum = 0; + cursor.toArray().then(function aggregateCb(nativeResult) { + let sum = 0; if (_.first(nativeResult)) { sum = _.first(nativeResult).sum; } return exits.success(sum); + }).catch(function(err) { + if (err) { return exits.error(err); } });// } - }; From 8bd1d343856be88af1b59e6e9f64cb8f91076d85 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 20:58:09 +0100 Subject: [PATCH 023/193] feat: move avg-records to promise-based implementation --- lib/private/machines/avg-records.js | 29 ++++++++++++++--------------- test/run-adapter-specific-tests.js | 1 - 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/private/machines/avg-records.js b/lib/private/machines/avg-records.js index 0457dfe98..7ff0361f8 100644 --- a/lib/private/machines/avg-records.js +++ b/lib/private/machines/avg-records.js @@ -26,26 +26,25 @@ module.exports = { fn: function (inputs, exits) { - // Dependencies - var _ = require('@sailshq/lodash'); - var buildMongoWhereClause = require('./private/build-mongo-where-clause'); + const _ = require('@sailshq/lodash'); + const buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - var s3q = inputs.query; + const s3q = inputs.query; // Local var for the `tableName`, for clarity. - var tableName = s3q.using; + const tableName = s3q.using; // Local var for the name of the numeric field, for clarity. // // > Remember: Contrary to what you might think given its naming, // > by the time it gets to the adapter (in an s3q), the `numericAttrName` // > qk has already been normalized to be a column name, not an attribute name. - var numericFieldName = s3q.numericAttrName; + const numericFieldName = s3q.numericAttrName; // Grab the model definition - var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -54,7 +53,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - var mongoWhere; + let mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -62,9 +61,9 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - var db = inputs.connection; - var mongoCollection = db.collection(tableName); - var cursor = mongoCollection.aggregate([ + const db = inputs.connection; + const mongoCollection = db.collection(tableName); + const cursor = mongoCollection.aggregate([ { $match: mongoWhere }, { $group: { @@ -76,12 +75,12 @@ module.exports = { } ], { cursor: {} }); - cursor.toArray(function aggregateCb(err, nativeResult) { - if (err) { return exits.error(err); } - - var mean = 0; + cursor.toArray().then(function aggregateCb(nativeResult) { + let mean = 0; if (_.first(nativeResult)) { mean = _.first(nativeResult).avg; } return exits.success(mean); + }).catch(function(err) { + if (err) { return exits.error(err); } });// } }; diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index d6ceef00d..55f6b3f1b 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -775,4 +775,3 @@ function createModel (identity, options) { return model; } - From 12c669d1c25b8a8daef5504f1ad80b95a1f59334 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 21:22:42 +0100 Subject: [PATCH 024/193] feat: change update-records to use promise and update test --- lib/private/machines/update-records.js | 61 ++++++++++++-------------- test/run-adapter-specific-tests.js | 15 +++---- 2 files changed, 35 insertions(+), 41 deletions(-) diff --git a/lib/private/machines/update-records.js b/lib/private/machines/update-records.js index d885a96b7..ca45c8d33 100644 --- a/lib/private/machines/update-records.js +++ b/lib/private/machines/update-records.js @@ -30,31 +30,31 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - var _ = require('@sailshq/lodash'); - var processNativeRecord = require('./private/process-native-record'); - var processNativeError = require('./private/process-native-error'); - var reifyValuesToSet = require('./private/reify-values-to-set'); - var buildMongoWhereClause = require('./private/build-mongo-where-clause'); + const _ = require('@sailshq/lodash'); + const processNativeRecord = require('./private/process-native-record'); + const processNativeError = require('./private/process-native-error'); + const reifyValuesToSet = require('./private/reify-values-to-set'); + const buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - var s3q = inputs.query; + const s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (UPDATE RECORDS):',require('util').inspect(s3q,{depth:5}),'\n'); // console.log(typeof s3q.criteria.where._id.in[0]); } // Local var for the `tableName`, for clarity. - var tableName = s3q.using; + const tableName = s3q.using; // Grab the model definition - var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• // Grab the pk column name (for use below) - var pkColumnName; + let pkColumnName; try { pkColumnName = WLModel.attributes[WLModel.primaryKey].columnName; } catch (e) { return exits.error(e); } @@ -63,7 +63,7 @@ module.exports = { // ╔╦╗╔═╗╔╦╗╔═╗╦═╗╔╦╗╦╔╗╔╔═╗ ┬ ┬┬ ┬┌─┐┌┬┐┬ ┬┌─┐┬─┐ ┌┬┐┌─┐ ╔═╗╔═╗╔╦╗╔═╗╦ ╦ ┌─┐┬─┐ ┌┐┌┌─┐┌┬┐ // ║║║╣ ║ ║╣ ╠╦╝║║║║║║║║╣ │││├─┤├┤ │ ├─┤├┤ ├┬┘ │ │ │ ╠╣ ║╣ ║ ║ ╠═╣ │ │├┬┘ ││││ │ │ // ═╩╝╚═╝ ╩ ╚═╝╩╚═╩ ╩╩╝╚╝╚═╝ └┴┘┴ ┴└─┘ ┴ ┴ ┴└─┘┴└─ ┴ └─┘ ╚ ╚═╝ ╩ ╚═╝╩ ╩ └─┘┴└─ ┘└┘└─┘ ┴ - var isFetchEnabled; + let isFetchEnabled; if (s3q.meta && s3q.meta.fetch) { isFetchEnabled = true; } else { isFetchEnabled = false; } @@ -79,7 +79,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - var mongoWhere; + let mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -88,8 +88,8 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - var db = inputs.connection; - var mongoCollection = db.collection(tableName); + let db = inputs.connection; + let mongoCollection = db.collection(tableName); // First, get the IDs of records which match this criteria (if needed). (function findMatchingIdsMaybe(proceed) { @@ -97,22 +97,21 @@ module.exports = { return proceed(); } - var projection = {}; + let projection = {}; projection[pkColumnName] = 1; // console.log('* * * *'); // console.log('mongoWhere:',mongoWhere); // console.log('typeof mongoWhere._id.$in[0]:',typeof mongoWhere._id.$in[0]); // console.log('projection:',projection); - mongoCollection.find(mongoWhere, projection).toArray(function findCb(err, nativeResult) { - if (err) { return proceed(err); } + mongoCollection.find(mongoWhere, projection).toArray().then(function findCb(nativeResult) { return proceed(undefined, _.pluck(nativeResult, pkColumnName)); - }); + }).catch(function (err) { return proceed(err); }); })(function findMatchingIdsMaybeCb(err, pkValsOfMatchingRecords) { if (err) { return exits.error(err); } // Update the documents in the db. - var secondaryMongoWhere; + let secondaryMongoWhere; if (!isFetchEnabled) { secondaryMongoWhere = mongoWhere; } @@ -126,15 +125,7 @@ module.exports = { // console.log('- - - - - - - - - -UPDATE: secondaryMongoWhere:',secondaryMongoWhere, { '$set': s3q.valuesToSet }); // } - mongoCollection.updateMany(secondaryMongoWhere, { '$set': s3q.valuesToSet }, function updateManyCb(err) { - if (err) { - err = processNativeError(err); - if (err.footprint && err.footprint.identity === 'notUnique') { - return exits.notUnique(err); - } - return exits.error(err); - }//-• - + mongoCollection.updateMany(secondaryMongoWhere, { '$set': s3q.valuesToSet }).then(function updateManyCb() { // If fetch:true was not enabled, we're done! if (!isFetchEnabled) { return exits.success(); @@ -148,9 +139,9 @@ module.exports = { // There should only ever be either zero or one record that were found before. if (pkValsOfMatchingRecords.length === 0) { /* do nothing */ } else if (pkValsOfMatchingRecords.length === 1) { - var oldPkValue = pkValsOfMatchingRecords[0]; + const oldPkValue = pkValsOfMatchingRecords[0]; _.remove(secondaryMongoWhere[pkColumnName]['$in'], oldPkValue); - var newPkValue = s3q.valuesToSet[pkColumnName]; + const newPkValue = s3q.valuesToSet[pkColumnName]; secondaryMongoWhere[pkColumnName]['$in'].push(newPkValue); } else { return exits.error(new Error('Consistency violation: Updated multiple records to have the same primary key value. (PK values should be unique!)')); } @@ -158,9 +149,7 @@ module.exports = { // Now re-fetch the now-updated records. - mongoCollection.find(secondaryMongoWhere).toArray(function (err, phRecords) { - if (err) { return exits.error(err); } - + mongoCollection.find(secondaryMongoWhere).toArray().then(function (phRecords) { // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐┌─┌─┐─┐ // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ │││ └─┐ │ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘└─└─┘─┘ @@ -172,7 +161,15 @@ module.exports = { } catch (e) { return exits.error(e); } return exits.success(phRecords); + }).catch(function err() { + return exits.error(err); });// + }).catch(function (err) { + err = processNativeError(err); + if (err.footprint && err.footprint.identity === 'notUnique') { + return exits.notUnique(err); + } + return exits.error(err); });// });// } diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 55f6b3f1b..4290ee65d 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -145,8 +145,8 @@ describe('dontUseObjectIds', function() { describe('Updating a single record', function() { it('should update the record correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}, function(err) { - if (err) {return done(err);} + models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}) + .then(function insertCb() { models.user.updateOne({id: 123}, {name: 'joe'}).exec(function(err, record) { if (err) {return done(err);} assert.equal(record.id, 123); @@ -154,7 +154,7 @@ describe('dontUseObjectIds', function() { return done(); }); - }); + }).catch(function (err) { return done(err); }); }); @@ -164,8 +164,8 @@ describe('dontUseObjectIds', function() { it('should update the records correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}], function(err) { - if (err) {return done(err);} + models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}]) + .then(function insertManyCb() { models.user.update({id: {'>': 0}}, {name: 'joe'}).exec(function(err, records) { if (err) {return done(err);} assert.equal(records[0].id, 123); @@ -174,11 +174,8 @@ describe('dontUseObjectIds', function() { assert.equal(records[1].name, 'joe'); return done(); }); - - }); - + }).catch(function (err) { return done(err); }); }); - }); describe('Finding a single record', function() { From d327eea96cb901c73e34ebc4fd2f4230132e363a Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 21:30:30 +0100 Subject: [PATCH 025/193] feat: update find-record to use promise and update tests --- lib/private/machines/find-records.js | 38 +++++++++++++--------------- test/run-adapter-specific-tests.js | 13 +++++----- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/lib/private/machines/find-records.js b/lib/private/machines/find-records.js index e5b53bfc1..97b398e3c 100644 --- a/lib/private/machines/find-records.js +++ b/lib/private/machines/find-records.js @@ -27,23 +27,23 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - var assert = require('assert'); - var _ = require('@sailshq/lodash'); - var processNativeRecord = require('./private/process-native-record'); - var buildMongoWhereClause = require('./private/build-mongo-where-clause'); + const assert = require('assert'); + const _ = require('@sailshq/lodash'); + const processNativeRecord = require('./private/process-native-record'); + const buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - var s3q = inputs.query; + const s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (FIND RECORDS):',require('util').inspect(s3q,{depth:10}),'\n'); } // Local var for the `tableName`, for clarity. - var tableName = s3q.using; + const tableName = s3q.using; // Grab the model definition - var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -53,11 +53,11 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ - var db = inputs.connection; - var mongoCollection = db.collection(tableName); + const db = inputs.connection; + const mongoCollection = db.collection(tableName); // Build a Mongo-style WHERE from the `where` clause. - var mongoWhere; + let mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -69,14 +69,14 @@ module.exports = { // Transform the `sort` clause from a stage 3 query into a Mongo sort. - var mongoSort = _.map(s3q.criteria.sort, function mapSort(s3qSortDirective) { + const mongoSort = _.map(s3q.criteria.sort, function mapSort(s3qSortDirective) { - var mongoSortDirective = []; + const mongoSortDirective = []; - var sortByKey = _.first(_.keys(s3qSortDirective)); + const sortByKey = _.first(_.keys(s3qSortDirective)); mongoSortDirective.push(sortByKey); - var sortDirection = s3qSortDirective[sortByKey]; + const sortDirection = s3qSortDirective[sortByKey]; assert(sortDirection === 'ASC' || sortDirection === 'DESC', 'At this point, the sort direction should always be ASC or DESC (capitalized). If you are seeing this message, there is probably a bug somewhere in your version of Waterline core.'); mongoSortDirective.push(sortDirection === 'ASC' ? 1 : -1); @@ -85,7 +85,7 @@ module.exports = { }); // Create the initial Mongo deferred, taking care of `where`, `limit`, and `sort`. - var mongoDeferred; + let mongoDeferred; try { assert(_.isNumber(s3q.criteria.limit), 'At this point, the limit should always be a number, but instead it is `'+s3q.criteria.limit+'`. If you are seeing this message, there is probably a bug somewhere in your version of Waterline core.'); mongoDeferred = mongoCollection.find(mongoWhere).limit(s3q.criteria.limit); @@ -99,7 +99,7 @@ module.exports = { if (s3q.criteria.select) { // Transform the stage-3 query select array into a Mongo projection dictionary. - var projection = _.reduce(s3q.criteria.select, function reduceProjection(memo, colName) { + const projection = _.reduce(s3q.criteria.select, function reduceProjection(memo, colName) { memo[colName] = 1; return memo; }, {}); @@ -117,9 +117,7 @@ module.exports = { // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ // Find the documents in the db. - mongoDeferred.toArray(function findCb(err, nativeResult) { - if (err) { return exits.error(err); } - + mongoDeferred.toArray().then(function findCb(nativeResult) { // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐┌─┌─┐─┐ // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ │││ └─┐ │ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘└─└─┘─┘ @@ -137,7 +135,7 @@ module.exports = { // } return exits.success(phRecords); - }); // + }).catch(function (err) { return exits.error(err); }); // } }; diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 4290ee65d..36a98af31 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -182,15 +182,15 @@ describe('dontUseObjectIds', function() { it('should find a record w/ a numeric ID', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}, function(err) { - if (err) {return done(err);} + models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}) + .then(function() { models.user.findOne({id: 123}).exec(function(err, record) { if (err) {return done(err);} assert.equal(record.id, 123); assert.equal(record.name, 'bob'); return done(); }); - }); + }).catch(function (err) { return done(err); }); }); @@ -200,8 +200,8 @@ describe('dontUseObjectIds', function() { it('should find the records correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}], function(err) { - if (err) {return done(err);} + models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}]) + .then(function() { models.user.find({id: {'>': 0}}).exec(function(err, records) { if (err) {return done(err);} assert.equal(records[0].id, 123); @@ -210,8 +210,7 @@ describe('dontUseObjectIds', function() { assert.equal(records[1].name, 'nancy'); return done(); }); - - }); + }).catch(function (err) { return done(err); }); }); }); From 591f7011836a0bcc4b8d59fcfd1ab12e45d328a2 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sun, 1 Oct 2023 21:49:43 +0100 Subject: [PATCH 026/193] feat: update code for destroy-records and related tests --- lib/private/machines/destroy-records.js | 35 +++++++++++-------------- test/run-adapter-specific-tests.js | 32 ++++++++++------------ 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/lib/private/machines/destroy-records.js b/lib/private/machines/destroy-records.js index 38833766b..8f4c563ca 100644 --- a/lib/private/machines/destroy-records.js +++ b/lib/private/machines/destroy-records.js @@ -28,28 +28,28 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - var _ = require('@sailshq/lodash'); - var processNativeRecord = require('./private/process-native-record'); - var buildMongoWhereClause = require('./private/build-mongo-where-clause'); + const _ = require('@sailshq/lodash'); + const processNativeRecord = require('./private/process-native-record'); + const buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - var s3q = inputs.query; + const s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (DESTROY RECORDS):',require('util').inspect(s3q,{depth:5}),'\n'); } // Local var for the `tableName`, for clarity. - var tableName = s3q.using; + const tableName = s3q.using; // Grab the model definition - var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• // Grab the pk column name (for use below) - var pkColumnName; + let pkColumnName; try { pkColumnName = WLModel.attributes[WLModel.primaryKey].columnName; } catch (e) { return exits.error(e); } @@ -58,7 +58,7 @@ module.exports = { // ╔╦╗╔═╗╔╦╗╔═╗╦═╗╔╦╗╦╔╗╔╔═╗ ┬ ┬┬ ┬┌─┐┌┬┐┬ ┬┌─┐┬─┐ ┌┬┐┌─┐ ╔═╗╔═╗╔╦╗╔═╗╦ ╦ ┌─┐┬─┐ ┌┐┌┌─┐┌┬┐ // ║║║╣ ║ ║╣ ╠╦╝║║║║║║║║╣ │││├─┤├┤ │ ├─┤├┤ ├┬┘ │ │ │ ╠╣ ║╣ ║ ║ ╠═╣ │ │├┬┘ ││││ │ │ // ═╩╝╚═╝ ╩ ╚═╝╩╚═╩ ╩╩╝╚╝╚═╝ └┴┘┴ ┴└─┘ ┴ ┴ ┴└─┘┴└─ ┴ └─┘ ╚ ╚═╝ ╩ ╚═╝╩ ╩ └─┘┴└─ ┘└┘└─┘ ┴ - var isFetchEnabled; + let isFetchEnabled; if (s3q.meta && s3q.meta.fetch) { isFetchEnabled = true; } else { isFetchEnabled = false; } @@ -67,7 +67,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - var mongoWhere; + let mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -76,8 +76,8 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - var db = inputs.connection; - var mongoCollection = db.collection(tableName); + const db = inputs.connection; + const mongoCollection = db.collection(tableName); // First, if fetch is set to true get all the records that match the given // criteria. This way they can be returned after the destroy. @@ -87,16 +87,15 @@ module.exports = { } // Find matching records. - mongoCollection.find(mongoWhere).toArray(function findCb(err, nativeResult) { - if (err) { return proceed(err); } + mongoCollection.find(mongoWhere).toArray().then(function findCb(nativeResult) { return proceed(undefined, nativeResult); - }); + }).catch(function (err) { return proceed(err); }); })(function findMatchingRecordsCb(err, phRecords) { if (err) { return exits.error(err); } // Destroy the documents in the db. - var secondaryMongoWhere; + let secondaryMongoWhere; if (!isFetchEnabled) { secondaryMongoWhere = mongoWhere; } @@ -104,9 +103,7 @@ module.exports = { secondaryMongoWhere = {}; secondaryMongoWhere[pkColumnName] = { '$in': _.pluck(phRecords, pkColumnName) }; } - mongoCollection.deleteMany(secondaryMongoWhere, function deleteCb(err) { - if (err) { return exits.error(err); } - + mongoCollection.deleteMany(secondaryMongoWhere).then(function deleteCb() { if (!isFetchEnabled) { return exits.success(); }//-• @@ -123,7 +120,7 @@ module.exports = { return exits.success(phRecords); - }); // + }).catch(function (err) { return exits.error(err); }); // });// } diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 36a98af31..de606704c 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -218,40 +218,36 @@ describe('dontUseObjectIds', function() { describe('Deleting a single record', function() { it('should delete the record correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}, function(err) { - if (err) {return done(err);} + models.user._adapter.datastores.test.manager.collection('user') + .insertOne({_id: 123, name: 'bob'}) + .then(function() { models.user.destroy({id: 123}).exec(function(err) { - if (err) {return done(err);} - models.user._adapter.datastores.test.manager.collection('user').find({}).toArray(function(err, records) { - if (err) {return done(err);} + if (err) { return done(err); } + models.user._adapter.datastores.test.manager.collection('user').find({}) + .toArray().then(function(records) { assert.equal(records.length, 0); return done(); - }); - + }).catch(function (err) { return done(err); }); }); - - }); - + }).catch(function (err) { return done(err); }); }); - }); describe('Deleting multiple records', function() { it('should delete the records correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}], function(err) { - if (err) {return done(err);} + models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}]) + .then(function() { models.user.destroy({id: {'>': 0}}).exec(function(err) { if (err) {return done(err);} - models.user._adapter.datastores.test.manager.collection('user').find({}).toArray(function(err, records) { - if (err) {return done(err);} + models.user._adapter.datastores.test.manager.collection('user').find({}).toArray() + .then(function(records) { assert.equal(records.length, 0); return done(); - }); + }).catch(function (err) { return done(err); }); }); - - }); + }).catch(function (err) { return done(err); }); }); }); From 9cb19f5d9217a8edb757b268abd93e1966b83efe Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:07:15 +0100 Subject: [PATCH 027/193] chore: change jsDocs and var to let/const --- lib/index.js | 88 ++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/index.js b/lib/index.js index fcd775760..fb71b23e8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,14 +2,14 @@ * Module dependencies */ -var util = require('util'); -var _ = require('@sailshq/lodash'); -var flaverr = require('flaverr'); -var async = require('async'); -var Machine = require('machine'); -var mongodb = require('mongodb'); -var normalizeDatastoreConfig = require('./private/normalize-datastore-config'); -var buildStdAdapterMethod = require('./private/build-std-adapter-method'); +const util = require('util'); +const _ = require('@sailshq/lodash'); +const flaverr = require('flaverr'); +const async = require('async'); +const Machine = require('machine'); +const mongodb = require('mongodb'); +const normalizeDatastoreConfig = require('./private/normalize-datastore-config'); +const buildStdAdapterMethod = require('./private/build-std-adapter-method'); /** @@ -19,7 +19,7 @@ var buildStdAdapterMethod = require('./private/build-std-adapter-method'); // Private var to cache dry machine definitions. // > This is set up in a dictionary instead of as separate variables // > just to allow the code below to be a bit easier to read) -var DRY_MACHINES = { +const DRY_MACHINES = { verifyModelDef: require('./private/machines/verify-model-def'), createManager: require('./private/machines/create-manager'), destroyManager: require('./private/machines/destroy-manager'), @@ -33,16 +33,16 @@ var DRY_MACHINES = { // Private var to cache pre-built machines for certain adapter methods. // (This is an optimization for improved performance.) -var WET_MACHINES = {}; +const WET_MACHINES = {}; _.each(DRY_MACHINES, function(def, methodName) { WET_MACHINES[methodName] = Machine.build(def); }); -var CONFIG_WHITELIST = require('./private/constants/config-whitelist.constant'); +const CONFIG_WHITELIST = require('./private/constants/config-whitelist.constant'); -var EXPECTED_URL_PROTOCOL_PFX = require('./private/constants/expected-url-protocol-pfx.constant'); +const EXPECTED_URL_PROTOCOL_PFX = require('./private/constants/expected-url-protocol-pfx.constant'); @@ -57,12 +57,12 @@ var EXPECTED_URL_PROTOCOL_PFX = require('./private/constants/expected-url-protoc // > Note that this approach of process global state will be changing in an upcoming version of // > the Waterline adapter spec (a breaking change). But if you follow the conventions laid out // > below in this adapter template, future upgrades should be a breeze. -var registeredDsEntries = {}; +const registeredDsEntries = {}; // Keep track of all the model definitions registered by the adapter (for the entire Node process). // (indexed by the model's `identity` -- NOT by its `tableName`!!) -var registeredDryModels = {}; +const registeredDryModels = {}; @@ -88,10 +88,10 @@ var registeredDryModels = {}; * > If you do go that route, it's conventional in Node to create a `./lib` directory for your private submodules * > and `require` them at the top of this file with other dependencies. e.g.: * > ``` - * > var updateMethod = require('./lib/update'); + * > const updateMethod = require('./lib/update'); * > ``` * - * @type {Dictionary} + * @type {Object} */ @@ -164,9 +164,9 @@ module.exports = { * * > Waterline calls this method once for every datastore that is configured to use this adapter. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} dsConfig »-> Dictionary (plain JavaScript object) of configuration options for this datastore (e.g. host, port, etc.) + * @param {Object} dsConfig »-> Dictionary (plain JavaScript object) of configuration options for this datastore (e.g. host, port, etc.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} physicalModelsReport »–> Experimental: The physical models using this datastore (keyed by "tableName"-- NOT by `identity`!). This may change in a future release of the adapter spec. + * @param {Object} physicalModelsReport »–> Experimental: The physical models using this datastore (keyed by "tableName"-- NOT by `identity`!). This may change in a future release of the adapter spec. * ˚¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ * ˙ **: {Dictionary} :: Info about a physical model using this datastore. WARNING: This is in a bit of an unusual format. * ˚¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ @@ -188,7 +188,7 @@ module.exports = { registerDatastore: function (dsConfig, physicalModelsReport, done) { // Grab the unique name for this datastore for easy access below. - var datastoreName = dsConfig.identity; + const datastoreName = dsConfig.identity; // Some sanity checks: if (!datastoreName) { @@ -223,7 +223,7 @@ module.exports = { // ============================================================================================ if (WET_MACHINES.verifyModelDef) { - var modelIncompatibilitiesMap = {}; + const modelIncompatibilitiesMap = {}; try { _.each(physicalModelsReport, function (phModelInfo){ try { @@ -237,7 +237,7 @@ module.exports = { });// } catch (e) { return done(e); } - var numNotCompatible = _.keys(modelIncompatibilitiesMap).length; + const numNotCompatible = _.keys(modelIncompatibilitiesMap).length; if (numNotCompatible > 0) { return done(flaverr('E_MODELS_NOT_COMPATIBLE', new Error( numNotCompatible+' model(s) are not compatible with this adapter:\n'+ @@ -400,7 +400,7 @@ module.exports = { WET_MACHINES.destroyManager({ manager: dsEntry.manager }).switch({ error: function(err) { return done(new Error('Encountered unexpected error when attempting to destroy the connection manager.\n\n```\n'+err.stack+'\n```')); }, failed: function(report) { - var err = new Error('Datastore (`'+datastoreName+'`) could not be torn down because of a failure when attempting to destroy the connection manager.\n\n```\n'+report.error.stack+'\n```'); + const err = new Error('Datastore (`'+datastoreName+'`) could not be torn down because of a failure when attempting to destroy the connection manager.\n\n```\n'+report.error.stack+'\n```'); err.raw = report.error; if (report.meta) { err.meta = report.meta; } return done(err); @@ -512,7 +512,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} s3q The stage-3 query to perform. + * @param {Object} s3q The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} @@ -535,7 +535,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} query The stage-3 query to perform. + * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} @@ -559,7 +559,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} query The stage-3 query to perform. + * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} @@ -582,7 +582,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} query The stage-3 query to perform. + * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} @@ -615,11 +615,11 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} query The stage-3 query to perform. + * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} - * @param {Array} [matching physical records] + * @param {Error?} err + * @param {Array} physicalRecords [matching physical records] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ find: buildStdAdapterMethod(require('./private/machines/find-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -641,11 +641,11 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} query The stage-3 query to perform. + * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} - * @param {Array} [matching physical records, populated according to the join instructions] + * @param {Error?} err + * @param {Array} physicalRecords [matching physical records, populated according to the join instructions] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ // ----------------------------------------------------- @@ -665,11 +665,11 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} query The stage-3 query to perform. + * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} - * @param {Number} [the number of matching records] + * @param {Error?} err + * @param {Number} numberOfMatchingRecords [the number of matching records] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ count: buildStdAdapterMethod(require('./private/machines/count-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -682,11 +682,11 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} query The stage-3 query to perform. + * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} - * @param {Number} [the sum] + * @param {Error?} err + * @param {Number} sum [the sum] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ sum: buildStdAdapterMethod(require('./private/machines/sum-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -699,11 +699,11 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} query The stage-3 query to perform. + * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} - * @param {Number} [the average ("mean")] + * @param {Error?} err + * @param {Number} average [the average ("mean")] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ avg: buildStdAdapterMethod(require('./private/machines/avg-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -736,7 +736,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} tableName The name of the table to define. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} phmDef The physical model definition (not a normal Sails/Waterline model-- log this for details.) + * @param {Object} phmDef The physical model definition (not a normal Sails/Waterline model-- log this for details.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} @@ -802,7 +802,7 @@ module.exports = { // Avoiding it for clarity, but just making note of the reason why. // Here's what it would look like, for reference: // ``` - // var mongoSingleFieldIdxKeys = _.zipObject([[key, 1]]); + // const mongoSingleFieldIdxKeys = _.zipObject([[key, 1]]); // ``` // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -840,7 +840,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} tableName The name of the table to drop. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Ref} unused Currently unused (do not use this argument.) + * @param {Undefined} unused Currently unused (do not use this argument.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} From 5c0a0e305c1adde27c1954b3c2e80d3cc71bc792 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:18:13 +0100 Subject: [PATCH 028/193] chore: more cleanups for jsDoc --- lib/index.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/index.js b/lib/index.js index fb71b23e8..fd5513e6b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -515,8 +515,8 @@ module.exports = { * @param {Object} s3q The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} - * @param {Dictionary?} + * @param {Error?} err + * @param {Object?} record * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ create: buildStdAdapterMethod(require('./private/machines/create-record'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -538,8 +538,8 @@ module.exports = { * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} - * @param {Array?} + * @param {Error?} err + * @param {Array?} createdRecords * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ createEach: buildStdAdapterMethod(require('./private/machines/create-each-record'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -562,8 +562,8 @@ module.exports = { * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} - * @param {Array?} + * @param {Error?} err + * @param {Array?} updatedRecords * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ update: buildStdAdapterMethod(require('./private/machines/update-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -585,8 +585,8 @@ module.exports = { * @param {Object} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} - * @param {Array?} + * @param {Error?} err + * @param {Array?} destroyedRecords * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ destroy: buildStdAdapterMethod(require('./private/machines/destroy-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -739,7 +739,7 @@ module.exports = { * @param {Object} phmDef The physical model definition (not a normal Sails/Waterline model-- log this for details.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} + * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ define: function (datastoreName, tableName, phmDef, done) { @@ -809,6 +809,7 @@ module.exports = { // Create the index on the Mongo collection. // (https://docs.mongodb.com/manual/reference/method/db.collection.createIndex) + console.log(mongoSingleFieldIdxKeys); mongoCollection.createIndex(mongoSingleFieldIdxKeys, { unique: true }, function (err) { if (err && !_.isError(err)) { err = flaverr({raw: err}, new Error('Consistency violation: Expecting Error instance, but instead got: '+util.inspect(err))); @@ -843,7 +844,7 @@ module.exports = { * @param {Undefined} unused Currently unused (do not use this argument.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} + * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ drop: async function (datastoreName, tableName, unused, done) { @@ -905,7 +906,7 @@ module.exports = { * @param {Number} sequenceValue The new value for the sequence (e.g. 1) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} + * @param {Error?} err * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ From 3615b2c1c116a30f4e9e450bfb00bc4a7d6b8a26 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:20:27 +0100 Subject: [PATCH 029/193] feat: move createIndex to use promise --- lib/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index fd5513e6b..d3ee848e8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -810,13 +810,14 @@ module.exports = { // Create the index on the Mongo collection. // (https://docs.mongodb.com/manual/reference/method/db.collection.createIndex) console.log(mongoSingleFieldIdxKeys); - mongoCollection.createIndex(mongoSingleFieldIdxKeys, { unique: true }, function (err) { + mongoCollection.createIndex(mongoSingleFieldIdxKeys, { unique: true }).then(function () { + return next(); + }).catch(function(err) { if (err && !_.isError(err)) { err = flaverr({raw: err}, new Error('Consistency violation: Expecting Error instance, but instead got: '+util.inspect(err))); return next(err); } else if (err) { return next(err); } - else { return next(); } });// }, function (err) { From a8c6f6a56eb82ad7090679717f1bdd1ba77f02f8 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:27:30 +0100 Subject: [PATCH 030/193] chore: install @types/mocha --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 52a8667fd..be7200fd9 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "qs": "6.9.7" }, "devDependencies": { + "@types/mocha": "^10.0.2", "benchmark": "2.1.4", "eslint": "^8.50.0", "mocha": "3.0.2", From 80345023a22ad53756f55151d6e39fca59c5a09c Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:35:20 +0100 Subject: [PATCH 031/193] chore: update JSDocs --- lib/private/normalize-datastore-config/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/normalize-datastore-config/index.js b/lib/private/normalize-datastore-config/index.js index f42b0665f..d6b8ca446 100644 --- a/lib/private/normalize-datastore-config/index.js +++ b/lib/private/normalize-datastore-config/index.js @@ -33,7 +33,7 @@ var normalizePassword = require('./private/normalize-password'); * · They are left as-is in the URL as well. * · They are treated as strings (e.g. `?foo=0&bar=false` becomes `{foo:'0', bar: 'false'}`) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} dsConfig + * @param {Object} dsConfig * ˚¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ * ˙ url: {String?} :: * ˙ host: {String?} :: @@ -42,12 +42,12 @@ var normalizePassword = require('./private/normalize-password'); * ˙ password: {String?} :: * ˙ database: {String?} :: * - * @param {Array} whitelist + * @param {Array|Undefined?} whitelist * Optional. If provided, this is an array of strings indicating which custom settings * are recognized and should be allowed. The standard `url`/`host`/`database` etc. are * always allowed, no matter what. e.g. `['ssl', 'replicaSet']` * - * @param {String} expectedProtocolPrefix + * @param {String?} expectedProtocolPrefix * Optional. If specified, this restricts `dsConfig.url` to use a mandatory protocol (e.g. "mongodb") * If no protocol is included (or if it is simply `://`), then this mandatory protocol * will be tacked on automatically. From 82168af432bd4af1b967a6e6c136399b23a1a026 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:36:07 +0100 Subject: [PATCH 032/193] chore: move var to let/const --- test/run-adapter-specific-tests.js | 44 ++++++++++++++---------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index de606704c..3db2a8d66 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -1,17 +1,17 @@ -var assert = require('assert'); -var _ = require('@sailshq/lodash'); -var Waterline = require('waterline'); -var waterlineUtils = require('waterline-utils'); -var normalizeDatastoreConfig = require('../lib/private/normalize-datastore-config'); +const assert = require('assert'); +const _ = require('@sailshq/lodash'); +const Waterline = require('waterline'); +const waterlineUtils = require('waterline-utils'); +const normalizeDatastoreConfig = require('../lib/private/normalize-datastore-config'); -var waterline; -var models = {}; +let waterline; +let models = {}; describe('normalizeDatastoreConfig', function() { it('Given a URL without a prefix, normalizeDatastoreConfig should add the prefix', function() { - var config = { + const config = { url: 'creepygiggles:shipyard4eva@localhost/test' }; normalizeDatastoreConfig(config, undefined, 'mongodb'); @@ -19,8 +19,8 @@ describe('normalizeDatastoreConfig', function() { }); it('Given a URL with a comma in it (like a Mongo Atlas URL), normalizeDatastoreConfig should not modify the URL.', function() { - var url = 'mongodb://creepygiggles:shipyard4eva@cluster0-shard-00-00-ienyq.mongodb.net:27017,cluster0-shard-00-01-ienyq.mongodb.net:27017,cluster0-shard-00-02-ienyq.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin'; - var config = { + const url = 'mongodb://creepygiggles:shipyard4eva@cluster0-shard-00-00-ienyq.mongodb.net:27017,cluster0-shard-00-01-ienyq.mongodb.net:27017,cluster0-shard-00-02-ienyq.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin'; + const config = { url: 'mongodb://creepygiggles:shipyard4eva@cluster0-shard-00-00-ienyq.mongodb.net:27017,cluster0-shard-00-01-ienyq.mongodb.net:27017,cluster0-shard-00-02-ienyq.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin' }; normalizeDatastoreConfig(config); @@ -336,7 +336,7 @@ describe('dontUseObjectIds', function() { describe('Where a collection using number keys belongsTo a model using ObjectID ', function() { - var userId; + let userId; before(function(done) { setup( @@ -396,7 +396,7 @@ describe('dontUseObjectIds', function() { describe('Where a collection using ObjectID belongsTo a model using number keys', function() { - var petId; + let petId; before(function(done) { setup( @@ -455,7 +455,7 @@ describe('dontUseObjectIds', function() { describe('Where a collection using number keys belongsTo a model using ObjectID (vialess)', function() { - var userId; + let userId; before(function(done) { setup( @@ -501,9 +501,9 @@ describe('dontUseObjectIds', function() { describe('Where a collection using ObjectID belongsTo a model using number keys (vialess)', function() { - var petId; + let petId; // eslint-disable-next-line no-unused-vars - var userId; + let userId; before(function(done) { setup( @@ -550,7 +550,7 @@ describe('dontUseObjectIds', function() { describe('Where a collection using ObjectID has many-to-many relationship with a model using number keys', function() { - var petId; + let petId; before(function(done) { setup( @@ -669,7 +669,7 @@ describe('dontUseObjectIds', function() { function setup(fixtures, modelsContainer, cb) { - var defaults = { + const defaults = { primaryKey: 'id', datastore: 'test', fetchRecordsOnUpdate: true, @@ -682,11 +682,11 @@ function setup(fixtures, modelsContainer, cb) { waterline = new Waterline(); _.each(fixtures, function(val, key) { - var modelFixture = _.extend({}, defaults, fixtures[key]); + const modelFixture = _.extend({}, defaults, fixtures[key]); waterline.registerModel(Waterline.Collection.extend(modelFixture)); }); - var datastores = { + const datastores = { test: { adapter: 'sails-mongo', url: process.env.WATERLINE_ADAPTER_TESTS_URL || 'localhost/sails_mongo' @@ -702,7 +702,7 @@ function setup(fixtures, modelsContainer, cb) { } // Save a reference to the ORM - var ORM = orm; + const ORM = orm; // Run migrations waterlineUtils.autoMigrations('drop', orm, function(err) { @@ -721,10 +721,9 @@ function setup(fixtures, modelsContainer, cb) { } function createModel (identity, options) { - options = options || {}; - var model = { + const model = { datastore: 'test', identity: identity, attributes: { @@ -763,7 +762,6 @@ function createModel (identity, options) { collection: options.toManyVialess }; } - return model; } From ec5b6a69e630ecea0542dd2e2558bee2be7eae4c Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:36:32 +0100 Subject: [PATCH 033/193] chore: remove debugging console log --- lib/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index d3ee848e8..9b41a5922 100644 --- a/lib/index.js +++ b/lib/index.js @@ -809,7 +809,6 @@ module.exports = { // Create the index on the Mongo collection. // (https://docs.mongodb.com/manual/reference/method/db.collection.createIndex) - console.log(mongoSingleFieldIdxKeys); mongoCollection.createIndex(mongoSingleFieldIdxKeys, { unique: true }).then(function () { return next(); }).catch(function(err) { From d764465597ee585c0682ce30a562a9be02bc88d4 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:39:14 +0100 Subject: [PATCH 034/193] =?UTF-8?q?feat:=20move=20to=20mongodb=20driver=20?= =?UTF-8?q?version=206=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be7200fd9..83fc19b6b 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "async": "3.2.4", "flaverr": "^1.10.0", "machine": "^15.2.2", - "mongodb": "^5.9.0", + "mongodb": "^6.1.0", "qs": "6.9.7" }, "devDependencies": { From a20b8fb8307f506812bcab4fcdc74f0913a1a736 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:46:04 +0100 Subject: [PATCH 035/193] chore: install exact version of mongodb driver --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83fc19b6b..9183d0dd9 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "async": "3.2.4", "flaverr": "^1.10.0", "machine": "^15.2.2", - "mongodb": "^6.1.0", + "mongodb": "6.1.0", "qs": "6.9.7" }, "devDependencies": { From 2cde4d163bf2915af6bdb80e2f16523279366b3f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:58:44 +0100 Subject: [PATCH 036/193] fix: move to let/const --- .../private/build-mongo-where-clause.js | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/private/machines/private/build-mongo-where-clause.js b/lib/private/machines/private/build-mongo-where-clause.js index 39b775537..a611283b1 100644 --- a/lib/private/machines/private/build-mongo-where-clause.js +++ b/lib/private/machines/private/build-mongo-where-clause.js @@ -2,10 +2,10 @@ * Module dependencies */ -var util = require('util'); -var assert = require('assert'); -var _ = require('@sailshq/lodash'); -var normalizeMongoObjectId = require('./normalize-mongo-object-id'); +const util = require('util'); +const assert = require('assert'); +const _ = require('@sailshq/lodash'); +const normalizeMongoObjectId = require('./normalize-mongo-object-id'); /** @@ -14,11 +14,11 @@ var normalizeMongoObjectId = require('./normalize-mongo-object-id'); * Build a Mongo "query filter" from the specified S3Q `where` clause. * > Note: The provided `where` clause is NOT mutated. * - * @param {Dictionary} whereClause [`where` clause from the criteria of a S3Q] - * @param {Ref} WLModel - * @param {Dictionary?} meta [`meta` query key from the s3q] + * @param {Object} whereClause [`where` clause from the criteria of a S3Q] + * @param {Object} WLModel + * @param {Object?} meta const [`meta` query key from the s3q] * - * @returns {Dictionary} [Mongo "query filter"] + * @returns {Object} [Mongo "query filter"] */ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { @@ -42,14 +42,14 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Recursively build and return a transformed `where` clause for use with Mongo. - var mongoQueryFilter = (function recurse(branch) { - var loneKey = _.first(_.keys(branch)); + const mongoQueryFilter = (function recurse(branch) { + const loneKey = _.first(_.keys(branch)); // ╔═╗╦═╗╔═╗╔╦╗╦╔═╗╔═╗╔╦╗╔═╗ // ╠═╝╠╦╝║╣ ║║║║ ╠═╣ ║ ║╣ // ╩ ╩╚═╚═╝═╩╝╩╚═╝╩ ╩ ╩ ╚═╝ if (loneKey === 'and' || loneKey === 'or') { - var conjunctsOrDisjuncts = branch[loneKey]; + const conjunctsOrDisjuncts = branch[loneKey]; branch['$' + loneKey] = _.map(conjunctsOrDisjuncts, function(conjunctOrDisjunct){ return recurse(conjunctOrDisjunct); }); @@ -58,8 +58,8 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { }//-• // IWMIH, we're dealing with a constraint of some kind. - var constraintColumnName = loneKey; - var constraint = branch[constraintColumnName]; + const constraintColumnName = loneKey; + const constraint = branch[constraintColumnName]; // Determine whether we should compare as an object id. @@ -72,12 +72,12 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { // > try to convert the eq constraint / relevant modifier into an ObjectId // > instance, if possible. (We still gracefully fall back to tolerate // > filtering by pk/fk vs. miscellaneous strings.) - var doCompareAsObjectIdIfPossible; + let doCompareAsObjectIdIfPossible; assert(_.isString(WLModel.primaryKey) && WLModel.primaryKey, 'Model def should always have a `primaryKey` setting by the time the model definition is handed down to the adapter (this should have already been taken care of in WL core)'); - var pkAttrDef = WLModel.attributes[WLModel.primaryKey]; + const pkAttrDef = WLModel.attributes[WLModel.primaryKey]; assert(_.isObject(pkAttrDef), 'PK attribute should always exist (this should have already been taken care of in WL core)'); - var pkColumnName = pkAttrDef.columnName; + const pkColumnName = pkAttrDef.columnName; assert(_.isString(pkColumnName) && pkColumnName, 'PK attribute should always have a column name by the time the model definition is handed down to the adapter (this should have already been taken care of in WL core). But actual pk attribute def on the model looks like this: '+util.inspect(pkAttrDef, {depth:5})+''); if (constraintColumnName === pkColumnName && (!meta || !meta.modelsNotUsingObjectIds || !_.contains(meta.modelsNotUsingObjectIds, WLModel.identity))) { @@ -85,7 +85,7 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { } else { _.each(WLModel.attributes, function (attrDef /*, attrName */) { - var isForeignKey = !!attrDef.model; + const isForeignKey = !!attrDef.model; // Sanity checks: if (isForeignKey) { assert(attrDef.foreignKey, 'attribute has a `model` property, but wl-schema did not give it `foreignKey: true`!'); @@ -123,8 +123,8 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { // ╔═╗╔═╗╔╦╗╔═╗╦ ╔═╗═╗ ╦ ╔═╗╔═╗╔╗╔╔═╗╔╦╗╦═╗╔═╗╦╔╗╔╔╦╗ // ║ ║ ║║║║╠═╝║ ║╣ ╔╩╦╝ ║ ║ ║║║║╚═╗ ║ ╠╦╝╠═╣║║║║ ║ // ╚═╝╚═╝╩ ╩╩ ╩═╝╚═╝╩ ╚═ ╚═╝╚═╝╝╚╝╚═╝ ╩ ╩╚═╩ ╩╩╝╚╝ ╩ - var modifierKind = _.first(_.keys(constraint)); - var modifier = constraint[modifierKind]; + const modifierKind = _.first(_.keys(constraint)); + let modifier = constraint[modifierKind]; delete constraint[modifierKind]; From 69f725aac4e289b85e8bb2a6d0229a3e76baede1 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 13:58:58 +0100 Subject: [PATCH 037/193] chore: fix JSDoc issues --- lib/private/constants/connection.input.js | 2 +- lib/private/constants/dry-orm.input.js | 2 +- lib/private/constants/meta.input.js | 2 +- lib/private/constants/not-unique.exit.js | 2 +- lib/private/constants/query.input.js | 2 +- lib/private/constants/table-name.input.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/private/constants/connection.input.js b/lib/private/constants/connection.input.js index 790c9e5e4..56b32d46e 100644 --- a/lib/private/constants/connection.input.js +++ b/lib/private/constants/connection.input.js @@ -2,7 +2,7 @@ * `connection` * * @constant - * @type {InputDef} + * @type {Object} */ module.exports = { description: 'The active database connection to use.', diff --git a/lib/private/constants/dry-orm.input.js b/lib/private/constants/dry-orm.input.js index 5f82e9ec0..e1a113654 100644 --- a/lib/private/constants/dry-orm.input.js +++ b/lib/private/constants/dry-orm.input.js @@ -2,7 +2,7 @@ * `dryOrm` * * @constant - * @type {InputDef} + * @type {Object} */ module.exports = { friendlyName: 'Dry ORM', diff --git a/lib/private/constants/meta.input.js b/lib/private/constants/meta.input.js index 0bf3355c1..1104e0079 100644 --- a/lib/private/constants/meta.input.js +++ b/lib/private/constants/meta.input.js @@ -2,7 +2,7 @@ * `meta` * * @constant - * @type {InputDef} + * @type {Object} */ module.exports = { friendlyName: 'Meta (custom)', diff --git a/lib/private/constants/not-unique.exit.js b/lib/private/constants/not-unique.exit.js index 9270d668e..9d860b48f 100644 --- a/lib/private/constants/not-unique.exit.js +++ b/lib/private/constants/not-unique.exit.js @@ -2,7 +2,7 @@ * `notUnique` * * @constant - * @type {ExitDef} + * @type {Object} */ module.exports = { description: 'Could not persist changes because they would violate one or more uniqueness constraints.', diff --git a/lib/private/constants/query.input.js b/lib/private/constants/query.input.js index 9921bc3f0..074ce9db0 100644 --- a/lib/private/constants/query.input.js +++ b/lib/private/constants/query.input.js @@ -2,7 +2,7 @@ * `query` * * @constant - * @type {InputDef} + * @type {Object} */ module.exports = { friendlyName: 'Query (s3q)', diff --git a/lib/private/constants/table-name.input.js b/lib/private/constants/table-name.input.js index a0238e4a0..a925ce408 100644 --- a/lib/private/constants/table-name.input.js +++ b/lib/private/constants/table-name.input.js @@ -2,7 +2,7 @@ * `tableName` * * @constant - * @type {InputDef} + * @type {Object} */ module.exports = { friendlyName: 'Table name', From e5924a605847bee4f22a8ffa0df1ed8a290f1964 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:01:55 +0100 Subject: [PATCH 038/193] fix: move to let/const --- .../machines/private/normalize-mongo-object-id.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/private/machines/private/normalize-mongo-object-id.js b/lib/private/machines/private/normalize-mongo-object-id.js index c1e109b6a..a8ef594b8 100644 --- a/lib/private/machines/private/normalize-mongo-object-id.js +++ b/lib/private/machines/private/normalize-mongo-object-id.js @@ -2,9 +2,9 @@ * Module dependencies */ -var _ = require('@sailshq/lodash'); -var flaverr = require('flaverr'); -var ObjectId = require('mongodb').ObjectID || require('mongodb').ObjectId; +const _ = require('@sailshq/lodash'); +const flaverr = require('flaverr'); +const ObjectId = require('mongodb').ObjectID || require('mongodb').ObjectId; /** * normalizeMongoObjectId() @@ -12,8 +12,8 @@ var ObjectId = require('mongodb').ObjectID || require('mongodb').ObjectId; * Ensure that the provided reference is either an Object Id instance; * or if it isn't, then attempt to construct one from it. * ----------------------------------------------------------------------------- - * @param {Ref} supposedId [either a hex string or an ObjectId instance) - * @returns {Ref} [an ObjectId instance] + * @param {String|Object} supposedId [either a hex string or an ObjectId instance) + * @returns {Object} [an ObjectId instance] * @throws {E_CANNOT_INTERPRET_AS_OBJECTID} * ----------------------------------------------------------------------------- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -73,7 +73,7 @@ module.exports = function normalizeMongoObjectId(supposedId) { // Otherwise try to interpret the supposed mongo id as a hex string. // (note that we also implement a failsafe) else if (_.isString(supposedId) && ObjectId.isValid(supposedId)) { - var objectified = new ObjectId(supposedId); + const objectified = new ObjectId(supposedId); // Sanity check: if (objectified.toString() !== supposedId) { From efe3235fe3be4c7a5b148477c04c6571362ea9b9 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:03:42 +0100 Subject: [PATCH 039/193] fix: move to let/const --- lib/private/machines/private/process-native-error.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/machines/private/process-native-error.js b/lib/private/machines/private/process-native-error.js index 8cd0f738e..27f070f4b 100644 --- a/lib/private/machines/private/process-native-error.js +++ b/lib/private/machines/private/process-native-error.js @@ -2,7 +2,7 @@ * Module dependencies */ -var _ = require('@sailshq/lodash'); +const _ = require('@sailshq/lodash'); /** @@ -11,7 +11,7 @@ var _ = require('@sailshq/lodash'); * Examine the provided native error and attach a `footprint`, if appropriate. * > The error MAY be mutated in place -- or rarely, a new Error instance might be returned instead. * - * @param {Ref} err + * @param {Object} err * @returns {Error} */ module.exports = function processNativeError(err) { @@ -42,7 +42,7 @@ module.exports = function processNativeError(err) { // If we can infer which field this error is referring to, then add // that problematic key to the `keys` array of the footprint. // > Remember, this is by "columnName", not attr name! - var problematicKey; + let problematicKey; // For now, we avoid trying to determine this extra information, since we don't // have a strategy that can successfully figure it out in a performant way From 6d41daabe6d2aaaac4d367f89f55886ff2d8e824 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:04:54 +0100 Subject: [PATCH 040/193] fix: move to let/const --- .../machines/private/reify-values-to-set.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/private/machines/private/reify-values-to-set.js b/lib/private/machines/private/reify-values-to-set.js index ed7557a50..d5132e4bb 100644 --- a/lib/private/machines/private/reify-values-to-set.js +++ b/lib/private/machines/private/reify-values-to-set.js @@ -2,10 +2,10 @@ * Module dependencies */ -var assert = require('assert'); -var _ = require('@sailshq/lodash'); -var flaverr = require('flaverr'); -var normalizeMongoObjectId = require('./normalize-mongo-object-id'); +const assert = require('assert'); +const _ = require('@sailshq/lodash'); +const flaverr = require('flaverr'); +const normalizeMongoObjectId = require('./normalize-mongo-object-id'); /** @@ -14,9 +14,9 @@ var normalizeMongoObjectId = require('./normalize-mongo-object-id'); * Prepare a dictionary of values to be used in a native database operation. * > The provided `valuesToSet` will be mutated in-place. * - * @param {Ref} valuesToSet - * @param {Ref} WLModel - * @param {Dictionary?} meta [`meta` query key from the s3q] + * @param {Object} valuesToSet + * @param {Object} WLModel + * @param {Object?} meta [`meta` query key from the s3q] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @throws {E_CANNOT_INTERPRET_AS_OBJECTID} */ @@ -29,15 +29,15 @@ module.exports = function reifyValuesToSet(valuesToSet, WLModel, meta) { assert(_.isObject(valuesToSet) && !_.isArray(valuesToSet) && !_.isFunction(valuesToSet),'2nd argument must be a WLModel, and it has to have a `definition` property for this utility to work.'); // Determine whether or not to use object ids. - var useObjectIds = !meta || !meta.modelsNotUsingObjectIds || !_.contains(meta.modelsNotUsingObjectIds, WLModel.identity); + const useObjectIds = !meta || !meta.modelsNotUsingObjectIds || !_.contains(meta.modelsNotUsingObjectIds, WLModel.identity); // If trying to set the PK value explicitly (e.g. `_id`), try to interpret it // as a hex string, instantiate a Mongo ObjectId instance for it, and swap out // the original string for that instead before proceeding. // (Why? See http://stackoverflow.com/a/27897720/486547) - var primaryKeyAttrName = WLModel.primaryKey; - var primaryKeyColumnName = WLModel.attributes[WLModel.primaryKey].columnName; - var pkValue = valuesToSet[primaryKeyColumnName]; + const primaryKeyAttrName = WLModel.primaryKey; + const primaryKeyColumnName = WLModel.attributes[WLModel.primaryKey].columnName; + const pkValue = valuesToSet[primaryKeyColumnName]; // If the PK value is set to `null`, then remove it. // > Remember: `null` here has special meaning in Waterline -- it means there @@ -66,9 +66,9 @@ module.exports = function reifyValuesToSet(valuesToSet, WLModel, meta) { // Now we'll do the same thing for any explicit foreign keys that were provided. // (i.e. for singular associations) _.each(WLModel.attributes, function (attrDef, attrName) { - var phRecordKey = attrDef.columnName; + const phRecordKey = attrDef.columnName; - var isForeignKey = !!attrDef.model; + const isForeignKey = !!attrDef.model; // Sanity checks: if (isForeignKey) { assert(attrDef.foreignKey, 'attribute has a `model` property, but wl-schema did not give it `foreignKey: true`!'); From c636498fb8b48396315ae9f604b3e24fcd939937 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:09:51 +0100 Subject: [PATCH 041/193] fix: move to let/const --- lib/private/machines/create-manager.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index c0168959f..38774d841 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -91,12 +91,11 @@ module.exports = { fn: function (inputs, exits) { - // @ts-ignore - var _ = require('@sailshq/lodash'); - var NodeMongoDBNativeLib = require('mongodb'); - var CONFIG_WHITELIST = require('../constants/config-whitelist.constant'); - var EXPECTED_URL_PROTOCOL_PFX = require('../constants/expected-url-protocol-pfx.constant'); - var normalizeDatastoreConfig = require('../normalize-datastore-config'); + const _ = require('@sailshq/lodash'); + const NodeMongoDBNativeLib = require('mongodb'); + const CONFIG_WHITELIST = require('../constants/config-whitelist.constant'); + const EXPECTED_URL_PROTOCOL_PFX = require('../constants/expected-url-protocol-pfx.constant'); + const normalizeDatastoreConfig = require('../normalize-datastore-config'); // Note: // Support for different types of managers is database-specific, and is not @@ -107,7 +106,7 @@ module.exports = { // contributions to the core adapter in this area are welcome and greatly appreciated! // Normalize datastore. - var _clientConfig = _.extend({ + let _clientConfig = _.extend({ url: inputs.connectionString }, inputs.meta); @@ -123,14 +122,14 @@ module.exports = { // Mongo doesn't like some of our standard properties, so we'll remove them // (we don't need any of them now anyway, since we know at this point that // they'll have been baked into the URL) - var mongoUrl = _clientConfig.url; + const mongoUrl = _clientConfig.url; _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); // https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect/ NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig) .then(function (client) { - var manager = client.db(_clientConfig.database); - // @ts-ignore + const manager = client.db(_clientConfig.database); + manager.client = client; // Now mutate this manager, giving it a telltale. @@ -141,7 +140,7 @@ module.exports = { // > (^^But that's not the real reason to include it -- we ended up solving it differently // > anyway. No, the real reason is so that there's a way to tell if a given Mongo client // > instance came from mp-mongo or not, for debugging reasons.) - // @ts-ignore + manager._isFromMPMongo = true; return exits.success({ From ae9fbb92a2b6acf51a5b1f26c9a86a5683b99392 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:22:46 +0100 Subject: [PATCH 042/193] fix: move to let/const --- lib/private/build-std-adapter-method.js | 23 +++++++++---------- lib/private/machines/destroy-manager.js | 2 +- lib/private/machines/release-connection.js | 2 +- .../normalize-datastore-config/index.js | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/private/build-std-adapter-method.js b/lib/private/build-std-adapter-method.js index 90c9ff85e..4ff8e2999 100644 --- a/lib/private/build-std-adapter-method.js +++ b/lib/private/build-std-adapter-method.js @@ -2,9 +2,9 @@ * Module dependencies */ -var _ = require('@sailshq/lodash'); -var Machine = require('machine'); -var doWithConnection = require('./do-with-connection'); +const _ = require('@sailshq/lodash'); +const Machine = require('machine'); +const doWithConnection = require('./do-with-connection'); /** @@ -21,27 +21,27 @@ var doWithConnection = require('./do-with-connection'); * > This is a stopgap. * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} machineDef (dry) - * @param {Dictionary} WET_MACHINES (for convenience) - * @param {Dictionary} registeredDsEntries - * @param {Dictionary} registeredDryModels + * @param {Object} machineDef (dry) + * @param {Object} WET_MACHINES (for convenience) + * @param {Object} registeredDsEntries + * @param {Object} registeredDryModels * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {Function} * @param {String} datastoreName - * @param {Dictionary} s3q + * @param {Object} s3q * @param {Function} done * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ module.exports = function buildStdAdapterMethod (machineDef, WET_MACHINES, registeredDsEntries, registeredDryModels) { // Build wet machine. - var performQuery = Machine.build(machineDef); + const performQuery = Machine.build(machineDef); // Return function that will be the adapter method. return function (datastoreName, s3q, done) { // Look up the datastore entry (to get the manager). - var dsEntry = registeredDsEntries[datastoreName]; + const dsEntry = registeredDsEntries[datastoreName]; // Sanity check: if (_.isUndefined(dsEntry)) { @@ -56,7 +56,7 @@ module.exports = function buildStdAdapterMethod (machineDef, WET_MACHINES, regis meta: s3q.meta, during: function (connection, proceed) { - var handlers = { + const handlers = { error: function (err) { return proceed(err); }, success: function (result) { return proceed(undefined, result); } }; @@ -79,4 +79,3 @@ module.exports = function buildStdAdapterMethod (machineDef, WET_MACHINES, regis };// }; - diff --git a/lib/private/machines/destroy-manager.js b/lib/private/machines/destroy-manager.js index 4643dd5dc..0a5ae175a 100644 --- a/lib/private/machines/destroy-manager.js +++ b/lib/private/machines/destroy-manager.js @@ -1,4 +1,4 @@ -var _ = require('@sailshq/lodash'); +const _ = require('@sailshq/lodash'); module.exports = { diff --git a/lib/private/machines/release-connection.js b/lib/private/machines/release-connection.js index d7d18f0a0..f89dbee18 100644 --- a/lib/private/machines/release-connection.js +++ b/lib/private/machines/release-connection.js @@ -1,4 +1,4 @@ -var _ = require('@sailshq/lodash'); +const _ = require('@sailshq/lodash'); module.exports = { diff --git a/lib/private/normalize-datastore-config/index.js b/lib/private/normalize-datastore-config/index.js index d6b8ca446..4b594e883 100644 --- a/lib/private/normalize-datastore-config/index.js +++ b/lib/private/normalize-datastore-config/index.js @@ -33,7 +33,7 @@ var normalizePassword = require('./private/normalize-password'); * · They are left as-is in the URL as well. * · They are treated as strings (e.g. `?foo=0&bar=false` becomes `{foo:'0', bar: 'false'}`) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} dsConfig + * @param {Object?} dsConfig * ˚¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ * ˙ url: {String?} :: * ˙ host: {String?} :: From d220a4145bae8d10273b5b9b720e7805135be7aa Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:25:57 +0100 Subject: [PATCH 043/193] fix: move to let/const --- .../private/normalize-database.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-database.js b/lib/private/normalize-datastore-config/private/normalize-database.js index 8f4d82857..5a19f4749 100644 --- a/lib/private/normalize-datastore-config/private/normalize-database.js +++ b/lib/private/normalize-datastore-config/private/normalize-database.js @@ -2,17 +2,17 @@ * Module dependencies */ -var util = require('util'); -var assert = require('assert'); -var _ = require('@sailshq/lodash'); -var flaverr = require('flaverr'); +const util = require('util'); +const assert = require('assert'); +const _ = require('@sailshq/lodash'); +const flaverr = require('flaverr'); /** * normalizeDatabase() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Ref} dbName + * @param {String} dbName * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {String} * The normalized value. From 8d82b3256d73e1072dbcaf00897825edc76ced8b Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:27:01 +0100 Subject: [PATCH 044/193] fix: move to let/const --- .../private/normalize-host.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-host.js b/lib/private/normalize-datastore-config/private/normalize-host.js index 836fc6531..26a0defec 100644 --- a/lib/private/normalize-datastore-config/private/normalize-host.js +++ b/lib/private/normalize-datastore-config/private/normalize-host.js @@ -2,17 +2,17 @@ * Module dependencies */ -var util = require('util'); -var assert = require('assert'); -var _ = require('@sailshq/lodash'); -var flaverr = require('flaverr'); +const util = require('util'); +const assert = require('assert'); +const _ = require('@sailshq/lodash'); +const flaverr = require('flaverr'); /** * normalizeHost() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Ref} host + * @param {String} host * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {String} * The normalized value. From ea9d8670422ce36a6ec6d1635420c7bbb078e6e8 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:27:38 +0100 Subject: [PATCH 045/193] fix: move to let/const --- .../private/normalize-password.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-password.js b/lib/private/normalize-datastore-config/private/normalize-password.js index ceca20543..5ddbb65f3 100644 --- a/lib/private/normalize-datastore-config/private/normalize-password.js +++ b/lib/private/normalize-datastore-config/private/normalize-password.js @@ -2,16 +2,16 @@ * Module dependencies */ -var assert = require('assert'); -var _ = require('@sailshq/lodash'); -var flaverr = require('flaverr'); +const assert = require('assert'); +const _ = require('@sailshq/lodash'); +const flaverr = require('flaverr'); /** * normalizePassword() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Ref} password + * @param {String} password * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {String} * The normalized value. From bef408922f541eefde29fcc0fe37503c2b384829 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:28:34 +0100 Subject: [PATCH 046/193] fix: move to let/const --- .../private/normalize-port.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-port.js b/lib/private/normalize-datastore-config/private/normalize-port.js index 8aa468979..6553e3124 100644 --- a/lib/private/normalize-datastore-config/private/normalize-port.js +++ b/lib/private/normalize-datastore-config/private/normalize-port.js @@ -2,17 +2,17 @@ * Module dependencies */ -var util = require('util'); -var assert = require('assert'); -var _ = require('@sailshq/lodash'); -var flaverr = require('flaverr'); +const util = require('util'); +const assert = require('assert'); +const _ = require('@sailshq/lodash'); +const flaverr = require('flaverr'); /** * normalizePort() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Ref} port + * @param {Number} port * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {Number} * The normalized value. From cd4bee3a0a168700e5ec34291281cb766d96ce3e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:29:08 +0100 Subject: [PATCH 047/193] fix: move to let/const --- .../private/normalize-user.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-user.js b/lib/private/normalize-datastore-config/private/normalize-user.js index ab3acf8fb..573e56bc9 100644 --- a/lib/private/normalize-datastore-config/private/normalize-user.js +++ b/lib/private/normalize-datastore-config/private/normalize-user.js @@ -2,17 +2,17 @@ * Module dependencies */ -var util = require('util'); -var assert = require('assert'); -var _ = require('@sailshq/lodash'); -var flaverr = require('flaverr'); +const util = require('util'); +const assert = require('assert'); +const _ = require('@sailshq/lodash'); +const flaverr = require('flaverr'); /** * normalizeUser() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Ref} user + * @param {String} user * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {String} * The normalized value. From b951b05e4b7397e3eac000dcd4dce5c4fe2e46a7 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:35:53 +0100 Subject: [PATCH 048/193] fix: move to let/const --- .../normalize-datastore-config/index.js | 62 +++++++++---------- .../private/normalize-database.js | 2 +- .../private/normalize-port.js | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/private/normalize-datastore-config/index.js b/lib/private/normalize-datastore-config/index.js index 4b594e883..607b00f32 100644 --- a/lib/private/normalize-datastore-config/index.js +++ b/lib/private/normalize-datastore-config/index.js @@ -2,17 +2,17 @@ * Module dependencies */ -var assert = require('assert'); -var util = require('util'); -var url = require('url'); -var _ = require('@sailshq/lodash'); -var flaverr = require('flaverr'); -var qs = require('qs'); -var normalizeDatabase = require('./private/normalize-database'); -var normalizeUser = require('./private/normalize-user'); -var normalizePort = require('./private/normalize-port'); -var normalizeHost = require('./private/normalize-host'); -var normalizePassword = require('./private/normalize-password'); +const assert = require('assert'); +const util = require('util'); +const url = require('url'); +const _ = require('@sailshq/lodash'); +const flaverr = require('flaverr'); +const qs = require('qs'); +const normalizeDatabase = require('./private/normalize-database'); +const normalizeUser = require('./private/normalize-user'); +const normalizePort = require('./private/normalize-port'); +const normalizeHost = require('./private/normalize-host'); +const normalizePassword = require('./private/normalize-password'); /** @@ -66,7 +66,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // If items in BASELINE_PROPS are included in the querystring of the connection url, // they are allowed to remain, but are not automatically applied at the top-level. // (Note that this whitelist applies to overrides AND to querystring-encoded values) - var BASELINE_PROPS = [ + const BASELINE_PROPS = [ 'url', 'adapter', 'schema', @@ -84,12 +84,12 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Have a look at the datastore config to get an idea of what's there. - var hasUrl = !_.isUndefined(dsConfig.url); - var hasUserOverride = !_.isUndefined(dsConfig.user); - var hasPasswordOverride = !_.isUndefined(dsConfig.password); - var hasHostOverride = !_.isUndefined(dsConfig.host); - var hasPortOverride = !_.isUndefined(dsConfig.port); - var hasDatabaseOverride = !_.isUndefined(dsConfig.database); + const hasUrl = !_.isUndefined(dsConfig.url); + const hasUserOverride = !_.isUndefined(dsConfig.user); + const hasPasswordOverride = !_.isUndefined(dsConfig.password); + const hasHostOverride = !_.isUndefined(dsConfig.host); + const hasPortOverride = !_.isUndefined(dsConfig.port); + const hasDatabaseOverride = !_.isUndefined(dsConfig.database); // ┌┐┌┌─┐┬─┐┌┬┐┌─┐┬ ┬┌─┐┌─┐ ╔═╗╦ ╦╔═╗╦═╗╦═╗╦╔╦╗╔═╗╔═╗ @@ -141,7 +141,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Strip out any overrides w/ undefined values. // (And along the way, check overrides against whitelist if relevant) - var unrecognizedKeys; + let unrecognizedKeys; _.each(Object.keys(dsConfig), function (key) { if (_.isUndefined(dsConfig[key])) { delete dsConfig[key]; @@ -182,7 +182,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // FUTURE: Appropriately URL/URIComponent-encode this stuff as we build the url // Invent a connection URL on the fly. - var inventedUrl = (expectedProtocolPrefix||'db')+'://'; + let inventedUrl = (expectedProtocolPrefix||'db')+'://'; // If authentication info was specified, add it: if (hasPasswordOverride && hasUserOverride) { @@ -288,7 +288,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Plus, more importantly, Node's `url.parse()` returns funky results if the argument doesn't // have one. So we'll add one if necessary. // > See https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax - var urlToParse; + let urlToParse; if (dsConfig.url.match(/^:\/\//)) { urlToParse = dsConfig.url.replace(/^:\/\//, (expectedProtocolPrefix||'db')+'://'); } @@ -303,7 +303,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // console.log('\n\n**********\nurl to parse:',urlToParse, (new Error()).stack); // Now attempt to parse out the URL's pieces and validate each one. - var parsedConnectionStr = url.parse(urlToParse); + let parsedConnectionStr = url.parse(urlToParse); // Ensure a valid protocol. @@ -334,10 +334,10 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Parse authentication credentials from url, if specified. - var userInUrl; - var passwordInUrl; + let userInUrl; + let passwordInUrl; if (parsedConnectionStr.auth && _.isString(parsedConnectionStr.auth)) { - var authPieces = parsedConnectionStr.auth.split(/:/); + const authPieces = parsedConnectionStr.auth.split(/:/); if (authPieces[0]) { userInUrl = authPieces[0]; }//>- @@ -348,12 +348,12 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Parse the rest of the standard information from the URL. - var hostInUrl = parsedConnectionStr.hostname; - var portInUrl = parsedConnectionStr.port; - var databaseInUrl = parsedConnectionStr.pathname; + const hostInUrl = parsedConnectionStr.hostname; + const portInUrl = parsedConnectionStr.port; + let databaseInUrl = parsedConnectionStr.pathname; // And finally parse the non-standard info from the URL's querystring. - var miscOptsInUrlQs; + let miscOptsInUrlQs; try { miscOptsInUrlQs = qs.parse(parsedConnectionStr.query); } catch (e) { @@ -441,7 +441,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // And finally, rebuild the URL - var rebuiltUrl = ''; + let rebuiltUrl = ''; // Start with the protocol... rebuiltUrl += parsedConnectionStr.protocol+'//'; @@ -508,7 +508,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // > If there were any non-standard options, we'll **LEAVE THEM IN** the URL // > when we rebuild it. But note that we did fold them into the dsConfig // > dictionary as well earlier. - var newQs = qs.stringify(miscOptsInUrlQs); + const newQs = qs.stringify(miscOptsInUrlQs); if (newQs.length > 0) { rebuiltUrl += '?'+newQs; } diff --git a/lib/private/normalize-datastore-config/private/normalize-database.js b/lib/private/normalize-datastore-config/private/normalize-database.js index 5a19f4749..2d5c9d327 100644 --- a/lib/private/normalize-datastore-config/private/normalize-database.js +++ b/lib/private/normalize-datastore-config/private/normalize-database.js @@ -12,7 +12,7 @@ const flaverr = require('flaverr'); * normalizeDatabase() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} dbName + * @param {any} dbName * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {String} * The normalized value. diff --git a/lib/private/normalize-datastore-config/private/normalize-port.js b/lib/private/normalize-datastore-config/private/normalize-port.js index 6553e3124..8aad3d2c5 100644 --- a/lib/private/normalize-datastore-config/private/normalize-port.js +++ b/lib/private/normalize-datastore-config/private/normalize-port.js @@ -12,7 +12,7 @@ const flaverr = require('flaverr'); * normalizePort() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Number} port + * @param {any} port * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {Number} * The normalized value. From 0a29e4d8978feb134c6835651c3ac6102ce6107b Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:37:23 +0100 Subject: [PATCH 049/193] fix: move to let/const --- lib/private/do-with-connection.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/private/do-with-connection.js b/lib/private/do-with-connection.js index d8cbfafb1..06c544e08 100644 --- a/lib/private/do-with-connection.js +++ b/lib/private/do-with-connection.js @@ -2,9 +2,9 @@ * Module dependencies */ -var assert = require('assert'); -var util = require('util'); -var _ = require('@sailshq/lodash'); +const assert = require('assert'); +const util = require('util'); +const _ = require('@sailshq/lodash'); /** @@ -18,14 +18,14 @@ var _ = require('@sailshq/lodash'); * > https://github.com/balderdashy/sails-hook-orm/blob/1cdb652aea41e2ede2305caef0d0167b79c5c052/lib/datastore-method-utils/private/do-with-connection.js * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Dictionary} options + * @param {Object} options * @required {Ref} WET_MACHINES * @required * @either {Ref} manager * @or {Ref} connection * * @required {Function} during - * @param {Ref} db [The database connection.] + * @param {any} db [The database connection.] * @param {Function} proceed * @param {Error?} err * @param {Ref?} resultMaybe @@ -62,13 +62,13 @@ module.exports = function doWithConnection(options, done){ }//-• if (options.WET_MACHINES.getConnection.sync) { - var connection; + let connection; try { connection = options.WET_MACHINES.getConnection({ manager: options.manager }).execSync().connection; // (`report.meta` is ignored...) } catch (e) { if (e.exit === 'failed') { - var failureReport = e.output; + const failureReport = e.output; if (failureReport.meta) { failureReport.error.meta = failureReport.meta; } return proceed(failureReport.error); } @@ -104,7 +104,7 @@ module.exports = function doWithConnection(options, done){ // Note that, if you try to call the callback more than once in the iteratee, // this method logs a warning explaining what's up, ignoring any subsequent calls // to the callback that occur after the first one. - var didDuringFnAlreadyHalt; + let didDuringFnAlreadyHalt; try { options.during(db, function (err, resultMaybe) { if (err) { return proceed(err); } From d6819fa4f67365ea11dc77cc160e56976f9c527f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:39:39 +0100 Subject: [PATCH 050/193] fix: move to let/const --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 9b41a5922..1bc1f08da 100644 --- a/lib/index.js +++ b/lib/index.js @@ -284,7 +284,7 @@ module.exports = { success: function (report) { try { - var manager = report.manager; + const manager = report.manager; // ╔╦╗╦═╗╔═╗╔═╗╦╔═ ┌┬┐┌─┐ ┌─┐┌┐┌┌┬┐┬─┐┬ ┬ // ║ ╠╦╝╠═╣║ ╠╩╗ ││└─┐ ├┤ │││ │ ├┬┘└┬┘ @@ -380,7 +380,7 @@ module.exports = { teardown: function (datastoreName, done) { // Look up the datastore entry (manager/driver/config). - var dsEntry = registeredDsEntries[datastoreName]; + const dsEntry = registeredDsEntries[datastoreName]; // Sanity checks: if (!datastoreName) { From 10ee8aaf1dc7a041c0aed6b59446b8907f2632e1 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:41:30 +0100 Subject: [PATCH 051/193] chore: move to let/const --- test/connectable/create-manager.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/connectable/create-manager.test.js b/test/connectable/create-manager.test.js index c3ecfe5a6..c96e66897 100644 --- a/test/connectable/create-manager.test.js +++ b/test/connectable/create-manager.test.js @@ -1,6 +1,6 @@ -var assert = require('assert'); -var createManager = require('machine').build(require('../../').createManager); -var MongoClient = require('mongodb').MongoClient; +const assert = require('assert'); +const createManager = require('machine').build(require('../../').createManager); +const MongoClient = require('mongodb').MongoClient; describe('Connectable ::', function() { describe('Create Manager', function() { @@ -32,7 +32,7 @@ describe('Connectable ::', function() { it('should successfully return a Mongo Server instance', function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + const host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' From 2a04922e69aa6bb7206bcc030f0bada13614df60 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:42:03 +0100 Subject: [PATCH 052/193] chore: move to let/const --- test/connectable/destroy-manager.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/connectable/destroy-manager.test.js b/test/connectable/destroy-manager.test.js index 61928732d..079444dd4 100644 --- a/test/connectable/destroy-manager.test.js +++ b/test/connectable/destroy-manager.test.js @@ -1,14 +1,14 @@ -var createManager = require('machine').build(require('../../').createManager); -var destroyManager = require('machine').build(require('../../').destroyManager); +const createManager = require('machine').build(require('../../').createManager); +const destroyManager = require('machine').build(require('../../').destroyManager); describe('Connectable ::', function() { describe('Destroy Manager', function() { - var manager; + let manager; // Create a manager before(function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + const host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' From bb786c1b6a68b9748091632e27a101740d7c0a0a Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:42:31 +0100 Subject: [PATCH 053/193] chore: move to let/const --- test/connectable/get-connection.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/connectable/get-connection.test.js b/test/connectable/get-connection.test.js index 9829424fd..1dd3667c3 100644 --- a/test/connectable/get-connection.test.js +++ b/test/connectable/get-connection.test.js @@ -1,15 +1,15 @@ -var assert = require('assert'); -var createManager = require('machine').build(require('../../').createManager); -var getConnection = require('machine').build(require('../../').getConnection); +const assert = require('assert'); +const createManager = require('machine').build(require('../../').createManager); +const getConnection = require('machine').build(require('../../').getConnection); describe('Connectable ::', function() { describe('Get Connection', function() { - var manager; + let manager; // Create a manager before(function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + const host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' From 2147264f377ea6a5af94aa9e6f50a3a435429c4f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:42:59 +0100 Subject: [PATCH 054/193] chore: move to let/const --- test/connectable/release-connection.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/connectable/release-connection.test.js b/test/connectable/release-connection.test.js index 5fa68fe1e..bad12c105 100644 --- a/test/connectable/release-connection.test.js +++ b/test/connectable/release-connection.test.js @@ -1,16 +1,16 @@ -var createManager = require('machine').build(require('../../').createManager); -var getConnection = require('machine').build(require('../../').getConnection); -var releaseConnection = require('machine').build(require('../../').releaseConnection); +const createManager = require('machine').build(require('../../').createManager); +const getConnection = require('machine').build(require('../../').getConnection); +const releaseConnection = require('machine').build(require('../../').releaseConnection); describe('Connectable ::', function() { describe('Release Connection', function() { - var manager; - var connection; + let manager; + let connection; // Create a manager and connection before(function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + const host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' From 6cf7cc2c3240f4df4d80a1ec4ddad151d1822003 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:43:40 +0100 Subject: [PATCH 055/193] chore: move to let/const --- test/run-standard-tests.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/run-standard-tests.js b/test/run-standard-tests.js index 145130ed1..6a350c8b7 100644 --- a/test/run-standard-tests.js +++ b/test/run-standard-tests.js @@ -4,10 +4,10 @@ * Module dependencies */ -var util = require('util'); -var TestRunner = require('waterline-adapter-tests'); -var packageMD = require('../package.json'); -var Adapter = require('../'); +const util = require('util'); +const TestRunner = require('waterline-adapter-tests'); +const packageMD = require('../package.json'); +const Adapter = require('../'); @@ -100,4 +100,3 @@ new TestRunner({ // to an adapter maintainer @ http://sailsjs.com/support. // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 14c2d72bf8f313ee91c1af711f85f465c7089a67 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 14:54:30 +0100 Subject: [PATCH 056/193] chore: add github actions for tests on ubuntu & windows and linting --- .github/lint.yml | 25 +++++++++++++++++ .github/test-ubuntu.yml | 41 +++++++++++++++++++++++++++ .github/test-windows.yml | 60 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 .github/lint.yml create mode 100644 .github/test-ubuntu.yml create mode 100644 .github/test-windows.yml diff --git a/.github/lint.yml b/.github/lint.yml new file mode 100644 index 000000000..8fcfdc5dc --- /dev/null +++ b/.github/lint.yml @@ -0,0 +1,25 @@ + +name: sails-mongo lint + +on: + push + +jobs: + lint: + runs-on: ubuntu-22.04 + + strategy: + matrix: + node-version: [20] + + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + npm ci + - name: Run lint + run: | + npm run lint diff --git a/.github/test-ubuntu.yml b/.github/test-ubuntu.yml new file mode 100644 index 000000000..d85cd2592 --- /dev/null +++ b/.github/test-ubuntu.yml @@ -0,0 +1,41 @@ +name: sails-mongo test (Ubuntu) + +on: + push + +env: + WATERLINE_ADAPTER_TESTS_URL: mongo/testdb:27027 + WATERLINE_ADAPTER_TESTS_HOST: mongo + WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo + NODE_ENV: test + +jobs: + test-ubuntu: + runs-on: ubuntu-22.04 + container: node:${{ matrix.node-version }} + + strategy: + matrix: + node-version: [16, 18, 20] + mongodb-version: ['4.4', '5', '6', '7'] + + services: + mongo: + image: mongo:${{ matrix.mongodb-version }} + ports: + - 27027:27017 + + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + node --eval "console.log('Running Node.js: ' + process.version)" + node --eval "console.log('Current directory: ' + process.cwd())" + node --eval "console.log('Files in directory: ' + require('fs').readdirSync(process.cwd()))" + npm ci + - name: Run test + run: | + npm run custom-tests diff --git a/.github/test-windows.yml b/.github/test-windows.yml new file mode 100644 index 000000000..402c474b2 --- /dev/null +++ b/.github/test-windows.yml @@ -0,0 +1,60 @@ +name: sails-mongo test (Windows) + +on: + push + +env: + WATERLINE_ADAPTER_TESTS_URL: 127.0.0.1/testdb + WATERLINE_ADAPTER_TESTS_HOST: 127.0.0.1 + WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo + NODE_ENV: test + +jobs: + test-windows: + runs-on: windows-2022 + + strategy: + matrix: + node-version: [16, 18, 20] + mongodb-version: ['4.4', '5', '6', '7'] + + steps: + - uses: ankane/setup-mongodb@ce30d9041565cb469945895d5bde3384a254dd2e # use commit ID until action is versioned, see https://github.com/ankane/setup-mongodb/issues/2 + with: + mongodb-version: ${{ matrix.mongodb-version }} + + - name: Wait for MongoDB to start + run: | + while ($true) { + $status = Get-Service MongoDB | Select-Object -ExpandProperty Status + if ($status -eq "Running") { + Write-Host "MongoDB is running." + break + } + Write-Host "Waiting for MongoDB to start..." + Start-Sleep -Seconds 5 + } + shell: pwsh + + - name: Install Mongodb Shell + run: | + choco install mongodb-shell -y + shell: pwsh + + - name: Check connection to Mongodb using mongodb shell + run: | + mongosh --eval "db.adminCommand('listDatabases')" + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + npm ci + - name: Run test + run: | + npm run custom-tests From 19e0d03f2ebb794a59bd452daca0ac3b857ce2e1 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 19:34:44 +0100 Subject: [PATCH 057/193] fix: update waterline to latest version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9183d0dd9..81c48a4bc 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "benchmark": "2.1.4", "eslint": "^8.50.0", "mocha": "3.0.2", - "waterline": "^0.13.6", + "waterline": "^0.15.2", "waterline-adapter-tests": "^1.0.1", "waterline-utils": "^1.4.2" }, From 55e70014be07d695c98b9aaa211062127490f831 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 19:51:30 +0100 Subject: [PATCH 058/193] chore: upgrade mocha to latest version and adjust script --- .mocharc.json | 4 ++++ package.json | 4 ++-- test/mocha.opts | 2 -- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 .mocharc.json delete mode 100644 test/mocha.opts diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 000000000..48f183d44 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,4 @@ +{ + "bail": true, + "timeout": 5000 +} diff --git a/package.json b/package.json index 81c48a4bc..f1442c34f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "./lib", "scripts": { "test": "npm run lint && npm run custom-tests", - "custom-tests": "node node_modules/mocha/bin/mocha test/run-adapter-specific-tests && node node_modules/mocha/bin/mocha test/connectable/ && node test/run-standard-tests", + "custom-tests": "node node_modules/mocha/bin/mocha", "lint": "node node_modules/eslint/bin/eslint . --max-warnings=0", "start-mongodb": "docker-compose up -d mongo", "stop-mongodb": "docker-compose down", @@ -41,7 +41,7 @@ "@types/mocha": "^10.0.2", "benchmark": "2.1.4", "eslint": "^8.50.0", - "mocha": "3.0.2", + "mocha": "^10.2.0", "waterline": "^0.15.2", "waterline-adapter-tests": "^1.0.1", "waterline-utils": "^1.4.2" diff --git a/test/mocha.opts b/test/mocha.opts deleted file mode 100644 index 111eceeca..000000000 --- a/test/mocha.opts +++ /dev/null @@ -1,2 +0,0 @@ ---timeout 5000 ---bail From 61629ceded9043ca2e21a210c87f104509f350ac Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Mon, 2 Oct 2023 20:03:51 +0100 Subject: [PATCH 059/193] chore: update mocha config --- .mocharc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mocharc.json b/.mocharc.json index 48f183d44..33d06aeaa 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,4 +1,4 @@ { "bail": true, - "timeout": 5000 + "timeout": "5000" } From a8bf4feef3a3dc44f1facf7c0da7469961f34d4f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 3 Oct 2023 19:05:32 +0100 Subject: [PATCH 060/193] chore: change mongo image to 7 --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 05953338b..6f7ac00da 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: - bash -c "npm test" mongo: - image: mongo:6.0 + image: mongo:7 restart: always command: "--logpath=/dev/null" ports: From e3872d7e59602bdbc11b2c92b05da40ba088eec3 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 3 Oct 2023 19:13:28 +0100 Subject: [PATCH 061/193] chore: use modern docker compose command --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f1442c34f..0cb0bc6f5 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,11 @@ "test": "npm run lint && npm run custom-tests", "custom-tests": "node node_modules/mocha/bin/mocha", "lint": "node node_modules/eslint/bin/eslint . --max-warnings=0", - "start-mongodb": "docker-compose up -d mongo", - "stop-mongodb": "docker-compose down", - "docker": "docker-compose run adapter bash", - "mongodb-shell": "docker-compose exec mongo mongo", - "docker-test": "docker-compose run adapter bash -c \"npm test\" && docker-compose down" + "start-mongodb": "docker compose up -d mongo", + "stop-mongodb": "docker compose down", + "docker": "docker compose run adapter bash", + "mongodb-shell": "docker compose exec mongo mongo", + "docker-test": "docker compose run adapter bash -c \"npm test\" && docker compose down" }, "keywords": [ "mongo", From 0574896952c02e4e8a017c1001e36ba913b7e38f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 6 Oct 2023 11:25:29 +0100 Subject: [PATCH 062/193] chore: update GitHub actions --- .github/lint.yml | 2 +- .github/test-ubuntu.yml | 2 +- .github/test-windows.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/lint.yml b/.github/lint.yml index 8fcfdc5dc..ae62f67fa 100644 --- a/.github/lint.yml +++ b/.github/lint.yml @@ -19,7 +19,7 @@ jobs: - name: Install dependencies run: | - npm ci + npm install --no-audit --no-fund - name: Run lint run: | npm run lint diff --git a/.github/test-ubuntu.yml b/.github/test-ubuntu.yml index d85cd2592..f167330ac 100644 --- a/.github/test-ubuntu.yml +++ b/.github/test-ubuntu.yml @@ -35,7 +35,7 @@ jobs: node --eval "console.log('Running Node.js: ' + process.version)" node --eval "console.log('Current directory: ' + process.cwd())" node --eval "console.log('Files in directory: ' + require('fs').readdirSync(process.cwd()))" - npm ci + npm install --no-audit --no-fund - name: Run test run: | npm run custom-tests diff --git a/.github/test-windows.yml b/.github/test-windows.yml index 402c474b2..d609e6f1c 100644 --- a/.github/test-windows.yml +++ b/.github/test-windows.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: node-version: [16, 18, 20] - mongodb-version: ['4.4', '5', '6', '7'] + mongodb-version: ['5'] steps: - uses: ankane/setup-mongodb@ce30d9041565cb469945895d5bde3384a254dd2e # use commit ID until action is versioned, see https://github.com/ankane/setup-mongodb/issues/2 @@ -54,7 +54,7 @@ jobs: - name: Install dependencies run: | - npm ci + npm install --no-audit --no-fund - name: Run test run: | npm run custom-tests From a5f8e124628c4edbc3a0e579ed8688e56a77888e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 6 Oct 2023 11:31:55 +0100 Subject: [PATCH 063/193] chore: remove Travis and AppVeyor --- .npmignore | 2 - .travis.yml | 69 ---------------------------- README.md | 2 +- appveyor.yml | 67 --------------------------- package.json | 3 +- scripts/appveyor/install_mongodb.ps1 | 20 -------- scripts/travis/install_mongodb.sh | 17 ------- scripts/travis/run_mongodb.sh | 6 --- 8 files changed, 2 insertions(+), 184 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 scripts/appveyor/install_mongodb.ps1 delete mode 100755 scripts/travis/install_mongodb.sh delete mode 100755 scripts/travis/run_mongodb.sh diff --git a/.npmignore b/.npmignore index 7f802e752..0819c5a6b 100644 --- a/.npmignore +++ b/.npmignore @@ -2,8 +2,6 @@ ./.gitignore ./.jshintrc ./.editorconfig -./.travis.yml -./appveyor.yml ./example ./examples ./test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4564cc1b6..000000000 --- a/.travis.yml +++ /dev/null @@ -1,69 +0,0 @@ -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# ╔╦╗╦═╗╔═╗╦ ╦╦╔═╗ ┬ ┬┌┬┐┬ # -# ║ ╠╦╝╠═╣╚╗╔╝║╚═╗ └┬┘││││ # -# o ╩ ╩╚═╩ ╩ ╚╝ ╩╚═╝o ┴ ┴ ┴┴─┘ # -# # -# This file configures Travis CI. # -# (i.e. how we run the tests... mainly) # -# # -# https://docs.travis-ci.com/user/customizing-the-build # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # - -dist: xenial - -language: node_js - -node_js: - - "12" - - "14" - - "16" - -env: - global: - - WATERLINE_ADAPTER_TESTS_URL=localhost/testdb - - WATERLINE_ADAPTER_TESTS_HOST=localhost - - WATERLINE_ADAPTER_TESTS_DATABASE=sails-mongo - - NODE_ENV=test - - matrix: - - MONGODB=3.6.18 - - MONGODB=4.0.18 - - MONGODB=4.2.7 - -cache: - directories: - - "$TRAVIS_BUILD_DIR/mongodb" - - "$HOME/.npm" - -matrix: - fast_finish: true - -before_install: - - chmod +x "$TRAVIS_BUILD_DIR/scripts/travis/install_mongodb.sh" "$TRAVIS_BUILD_DIR/scripts/travis/run_mongodb.sh" - - npm i -g npm@8.11.0 - -install: - # Don't let npm send metrics as it creates a file in the .npm folder invalidating the cache every time - - npm config set send-metrics false - - npm i --no-audit - - "$TRAVIS_BUILD_DIR/scripts/travis/install_mongodb.sh" - -before_script: - - "$TRAVIS_BUILD_DIR/scripts/travis/run_mongodb.sh" - -script: - - npm test - -after_script: - - pkill mongod - -branches: - only: - - master - - upgrade-mongodb-drivers - - update-test-environment - -notifications: - email: - - ci@sailsjs.com - - luislobo@gmail.com diff --git a/README.md b/README.md index 5f0bb9f24..391b861bd 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ This adapter implements the following methods: See [Extending Sails > Adapters > Custom Adapters](http://sailsjs.com/documentation/concepts/extending-sails/adapters/custom-adapters) in the [Sails documentation](http://sailsjs.com/documentation), or check out [recommended support options](http://sailsjs.com/support). -## Contributing   [![Build Status](https://travis-ci.org/balderdashy/sails-mongo.svg?branch=master)](https://travis-ci.org/balderdashy/sails-mongo)   [![Build status on Windows](https://ci.appveyor.com/api/projects/status/u0i1o62tsw6ymbjd/branch/master?svg=true)](https://ci.appveyor.com/project/mikermcneil/sails-mongo/branch/master) +## Contributing Please observe the guidelines and conventions laid out in the [Sails project contribution guide](http://sailsjs.com/documentation/contributing) when opening issues or submitting pull requests. diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index c68b2724d..000000000 --- a/appveyor.yml +++ /dev/null @@ -1,67 +0,0 @@ -# # # # # # # # # # # # # # # # # # # # # # # # # # -# ╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╦╔═╗╦═╗ ┬ ┬┌┬┐┬ # -# ╠═╣╠═╝╠═╝╚╗╔╝║╣ ╚╦╝║ ║╠╦╝ └┬┘││││ # -# ╩ ╩╩ ╩ ╚╝ ╚═╝ ╩ ╚═╝╩╚═o ┴ ┴ ┴┴─┘ # -# # -# This file configures Appveyor CI. # -# (i.e. how we run the tests on Windows) # -# # -# https://www.appveyor.com/docs/lang/nodejs-iojs/ # -# # # # # # # # # # # # # # # # # # # # # # # # # # - - -# Test against these versions of Node.js. -environment: - WATERLINE_ADAPTER_TESTS_URL: localhost/testdb - WATERLINE_ADAPTER_TESTS_HOST: localhost - WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo - NODE_ENV: test - matrix: - - nodejs_version: "10" - - nodejs_version: "12" - - nodejs_version: "14" - -# Install scripts. (runs after repo cloning) -install: - # Get the latest stable version of Node.js - # (Not sure what this is for, it's just in Appveyor's example.) - - ps: Install-Product node $env:nodejs_version - # Don't let npm send metrics as it creates a file in the .npm folder invalidating the cache every time - - npm config set send-metrics false - # Install declared dependencies - - npm install --no-audit - -branches: - only: - - master - - upgrade-mongodb-drivers - - update-test-environment - -# Post-install test scripts. -test_script: - # Output Node and NPM version info. - # (Presumably just in case Appveyor decides to try any funny business? - # But seriously, always good to audit this kind of stuff for debugging.) - - node --version - - npm --version - # Run the actual tests. - - npm test - -# Setup Mongo Database -services: - - mongodb - - -# Don't actually build. -# (Not sure what this is for, it's just in Appveyor's example. -# I'm not sure what we're not building... but I'm OK with not -# building it. I guess.) -build: off - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # - -# TODO: Set up appveyor + mongo*: -# https://www.appveyor.com/docs/services-databases/ -# Old example on how to install different versions of MongoDB added to `scripts/appveyor/install_mongodb.ps1` -# # # # # # # # # # # # # # # # # # # # # # # # # # # # diff --git a/package.json b/package.json index 0cb0bc6f5..9edec5fe0 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,6 @@ "migratable" ], "machineDir": "lib/private/machines/", - "exportStyle": "dryDictionary", - "testsUrl": "https://travis-ci.org/balderdashy/sails-mongo" + "exportStyle": "dryDictionary" } } diff --git a/scripts/appveyor/install_mongodb.ps1 b/scripts/appveyor/install_mongodb.ps1 deleted file mode 100644 index 0c3cfdb68..000000000 --- a/scripts/appveyor/install_mongodb.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -# Example. Not yet being used -$msiPath = "$($env:USERPROFILE)\mongodb-win32-x86_64-2008plus-ssl-3.0.4-signed.msi" -(New-Object Net.WebClient).DownloadFile('https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.0.4-signed.msi', $msiPath) -cmd /c start /wait msiexec /q /i $msiPath INSTALLLOCATION=C:\mongodb ADDLOCAL="all" -del $msiPath - -mkdir c:\mongodb\data\db | Out-Null -mkdir c:\mongodb\log | Out-Null - -'systemLog: - destination: file - path: c:\mongodb\log\mongod.log -storage: - dbPath: c:\mongodb\data\db' | Out-File C:\mongodb\mongod.cfg -Encoding utf8 - -cmd /c start /wait sc create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=C:\mongodb\mongod.cfg" DisplayName= "MongoDB" start= "demand" - -& c:\mongodb\bin\mongod --version - -Start-Service mongodb diff --git a/scripts/travis/install_mongodb.sh b/scripts/travis/install_mongodb.sh deleted file mode 100755 index 499b7190f..000000000 --- a/scripts/travis/install_mongodb.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -MDB_TGZ=mongodb-linux-x86_64-ubuntu1604-${MONGODB}.tgz -MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} -MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data - -# If it doesn't exist, it means the cache didn't pull it -if [ ! -f "${MDB_ROOT}/bin/mongod" ]; then - mkdir -p $MDB_ROOT - pushd $MDB_ROOT - wget https://fastdl.mongodb.org/linux/${MDB_TGZ} - tar xzf ${MDB_TGZ} --strip 1 - rm -f ${MDB_TGZ} - popd -fi -mkdir -p $MDB_DATA -"${MDB_ROOT}/bin/mongod" --version diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh deleted file mode 100755 index ef67727a5..000000000 --- a/scripts/travis/run_mongodb.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} -MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data - -${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork From 765c9d9a82419f5062e7dfab7a2f3d38c522cb62 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 7 Oct 2023 00:42:43 +0100 Subject: [PATCH 064/193] fix: stop returning id when fetch is disabled --- lib/private/machines/create-record.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 9d203d1e5..28d01a716 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -79,7 +79,7 @@ module.exports = { mongoCollection.insertOne(s3q.newRecord).then(async function documentInserted(nativeResult) { // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { - return exits.success({ id: nativeResult.insertedId }); + return exits.success(); }//-• From 68f8b94750071e00979cc99790871cc63e369c59 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 7 Oct 2023 00:43:43 +0100 Subject: [PATCH 065/193] chore: remove outdated future comment --- lib/private/machines/create-record.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 28d01a716..f80387269 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -70,10 +70,6 @@ module.exports = { // ║║║║╚═╗║╣ ╠╦╝ ║ ├┬┘├┤ │ │ │├┬┘ ││ // ╩╝╚╝╚═╝╚═╝╩╚═ ╩ ┴└─└─┘└─┘└─┘┴└──┴┘ // Create this new record in the database by inserting a document in the appropriate Mongo collection. - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // FUTURE: Carry through the `fetch: false` optimization all the way to Mongo here, - // if possible (e.g. using Mongo's projections API) - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const db = inputs.connection; const mongoCollection = db.collection(tableName); mongoCollection.insertOne(s3q.newRecord).then(async function documentInserted(nativeResult) { From 056ccde125cdb2a3f02e4296bc1a1f06cbd1210e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 20:16:44 +0100 Subject: [PATCH 066/193] chore: revert back to var --- .../private/normalize-database.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-database.js b/lib/private/normalize-datastore-config/private/normalize-database.js index 2d5c9d327..8f4d82857 100644 --- a/lib/private/normalize-datastore-config/private/normalize-database.js +++ b/lib/private/normalize-datastore-config/private/normalize-database.js @@ -2,17 +2,17 @@ * Module dependencies */ -const util = require('util'); -const assert = require('assert'); -const _ = require('@sailshq/lodash'); -const flaverr = require('flaverr'); +var util = require('util'); +var assert = require('assert'); +var _ = require('@sailshq/lodash'); +var flaverr = require('flaverr'); /** * normalizeDatabase() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {any} dbName + * @param {Ref} dbName * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {String} * The normalized value. From 533f6d5d5d2aa76360edb8e7738326c7b9c36dad Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 20:22:07 +0100 Subject: [PATCH 067/193] chore: revert changes --- .../private/normalize-user.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-user.js b/lib/private/normalize-datastore-config/private/normalize-user.js index 573e56bc9..ab3acf8fb 100644 --- a/lib/private/normalize-datastore-config/private/normalize-user.js +++ b/lib/private/normalize-datastore-config/private/normalize-user.js @@ -2,17 +2,17 @@ * Module dependencies */ -const util = require('util'); -const assert = require('assert'); -const _ = require('@sailshq/lodash'); -const flaverr = require('flaverr'); +var util = require('util'); +var assert = require('assert'); +var _ = require('@sailshq/lodash'); +var flaverr = require('flaverr'); /** * normalizeUser() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} user + * @param {Ref} user * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {String} * The normalized value. From 998b2ea756edfd0febfda2abd11d3541b7c61ac6 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 20:23:50 +0100 Subject: [PATCH 068/193] chore: revert changes --- .../private/normalize-port.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-port.js b/lib/private/normalize-datastore-config/private/normalize-port.js index 8aad3d2c5..8aa468979 100644 --- a/lib/private/normalize-datastore-config/private/normalize-port.js +++ b/lib/private/normalize-datastore-config/private/normalize-port.js @@ -2,17 +2,17 @@ * Module dependencies */ -const util = require('util'); -const assert = require('assert'); -const _ = require('@sailshq/lodash'); -const flaverr = require('flaverr'); +var util = require('util'); +var assert = require('assert'); +var _ = require('@sailshq/lodash'); +var flaverr = require('flaverr'); /** * normalizePort() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {any} port + * @param {Ref} port * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {Number} * The normalized value. From 93d399f0e8678c41d83e3199a37e72cbc323e483 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 20:24:58 +0100 Subject: [PATCH 069/193] chore: revert changes --- .../private/normalize-password.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-password.js b/lib/private/normalize-datastore-config/private/normalize-password.js index 5ddbb65f3..ceca20543 100644 --- a/lib/private/normalize-datastore-config/private/normalize-password.js +++ b/lib/private/normalize-datastore-config/private/normalize-password.js @@ -2,16 +2,16 @@ * Module dependencies */ -const assert = require('assert'); -const _ = require('@sailshq/lodash'); -const flaverr = require('flaverr'); +var assert = require('assert'); +var _ = require('@sailshq/lodash'); +var flaverr = require('flaverr'); /** * normalizePassword() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} password + * @param {Ref} password * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {String} * The normalized value. From 467b8eab37ad09c610142378352d9b36cf587910 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 20:25:53 +0100 Subject: [PATCH 070/193] chore: revert changes --- .../private/normalize-host.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/private/normalize-datastore-config/private/normalize-host.js b/lib/private/normalize-datastore-config/private/normalize-host.js index 26a0defec..836fc6531 100644 --- a/lib/private/normalize-datastore-config/private/normalize-host.js +++ b/lib/private/normalize-datastore-config/private/normalize-host.js @@ -2,17 +2,17 @@ * Module dependencies */ -const util = require('util'); -const assert = require('assert'); -const _ = require('@sailshq/lodash'); -const flaverr = require('flaverr'); +var util = require('util'); +var assert = require('assert'); +var _ = require('@sailshq/lodash'); +var flaverr = require('flaverr'); /** * normalizeHost() * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} host + * @param {Ref} host * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {String} * The normalized value. From cc527654accd03bab0713b5a5cb81a358f17fd73 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 20:30:09 +0100 Subject: [PATCH 071/193] chore: revert changes --- .../normalize-datastore-config/index.js | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/private/normalize-datastore-config/index.js b/lib/private/normalize-datastore-config/index.js index 607b00f32..ea197d4c1 100644 --- a/lib/private/normalize-datastore-config/index.js +++ b/lib/private/normalize-datastore-config/index.js @@ -2,17 +2,17 @@ * Module dependencies */ -const assert = require('assert'); -const util = require('util'); -const url = require('url'); -const _ = require('@sailshq/lodash'); -const flaverr = require('flaverr'); -const qs = require('qs'); -const normalizeDatabase = require('./private/normalize-database'); -const normalizeUser = require('./private/normalize-user'); -const normalizePort = require('./private/normalize-port'); -const normalizeHost = require('./private/normalize-host'); -const normalizePassword = require('./private/normalize-password'); +var assert = require('assert'); +var util = require('util'); +var url = require('url'); +var _ = require('@sailshq/lodash'); +var flaverr = require('flaverr'); +var qs = require('qs'); +var normalizeDatabase = require('./private/normalize-database'); +var normalizeUser = require('./private/normalize-user'); +var normalizePort = require('./private/normalize-port'); +var normalizeHost = require('./private/normalize-host'); +var normalizePassword = require('./private/normalize-password'); /** @@ -33,7 +33,7 @@ const normalizePassword = require('./private/normalize-password'); * · They are left as-is in the URL as well. * · They are treated as strings (e.g. `?foo=0&bar=false` becomes `{foo:'0', bar: 'false'}`) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object?} dsConfig + * @param {Dictionary} dsConfig * ˚¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ * ˙ url: {String?} :: * ˙ host: {String?} :: @@ -42,12 +42,12 @@ const normalizePassword = require('./private/normalize-password'); * ˙ password: {String?} :: * ˙ database: {String?} :: * - * @param {Array|Undefined?} whitelist + * @param {Array} whitelist * Optional. If provided, this is an array of strings indicating which custom settings * are recognized and should be allowed. The standard `url`/`host`/`database` etc. are * always allowed, no matter what. e.g. `['ssl', 'replicaSet']` * - * @param {String?} expectedProtocolPrefix + * @param {String} expectedProtocolPrefix * Optional. If specified, this restricts `dsConfig.url` to use a mandatory protocol (e.g. "mongodb") * If no protocol is included (or if it is simply `://`), then this mandatory protocol * will be tacked on automatically. @@ -66,7 +66,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // If items in BASELINE_PROPS are included in the querystring of the connection url, // they are allowed to remain, but are not automatically applied at the top-level. // (Note that this whitelist applies to overrides AND to querystring-encoded values) - const BASELINE_PROPS = [ + varvar BASELINE_PROPS = [ 'url', 'adapter', 'schema', @@ -84,12 +84,12 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Have a look at the datastore config to get an idea of what's there. - const hasUrl = !_.isUndefined(dsConfig.url); - const hasUserOverride = !_.isUndefined(dsConfig.user); - const hasPasswordOverride = !_.isUndefined(dsConfig.password); - const hasHostOverride = !_.isUndefined(dsConfig.host); - const hasPortOverride = !_.isUndefined(dsConfig.port); - const hasDatabaseOverride = !_.isUndefined(dsConfig.database); + var hasUrl = !_.isUndefined(dsConfig.url); + var hasUserOverride = !_.isUndefined(dsConfig.user); + var hasPasswordOverride = !_.isUndefined(dsConfig.password); + var hasHostOverride = !_.isUndefined(dsConfig.host); + var hasPortOverride = !_.isUndefined(dsConfig.port); + var hasDatabaseOverride = !_.isUndefined(dsConfig.database); // ┌┐┌┌─┐┬─┐┌┬┐┌─┐┬ ┬┌─┐┌─┐ ╔═╗╦ ╦╔═╗╦═╗╦═╗╦╔╦╗╔═╗╔═╗ @@ -141,7 +141,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Strip out any overrides w/ undefined values. // (And along the way, check overrides against whitelist if relevant) - let unrecognizedKeys; + var unrecognizedKeys; _.each(Object.keys(dsConfig), function (key) { if (_.isUndefined(dsConfig[key])) { delete dsConfig[key]; @@ -182,7 +182,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // FUTURE: Appropriately URL/URIComponent-encode this stuff as we build the url // Invent a connection URL on the fly. - let inventedUrl = (expectedProtocolPrefix||'db')+'://'; + var inventedUrl = (expectedProtocolPrefix||'db')+'://'; // If authentication info was specified, add it: if (hasPasswordOverride && hasUserOverride) { @@ -288,7 +288,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Plus, more importantly, Node's `url.parse()` returns funky results if the argument doesn't // have one. So we'll add one if necessary. // > See https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax - let urlToParse; + var urlToParse; if (dsConfig.url.match(/^:\/\//)) { urlToParse = dsConfig.url.replace(/^:\/\//, (expectedProtocolPrefix||'db')+'://'); } @@ -303,7 +303,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // console.log('\n\n**********\nurl to parse:',urlToParse, (new Error()).stack); // Now attempt to parse out the URL's pieces and validate each one. - let parsedConnectionStr = url.parse(urlToParse); + var parsedConnectionStr = url.parse(urlToParse); // Ensure a valid protocol. @@ -334,8 +334,8 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Parse authentication credentials from url, if specified. - let userInUrl; - let passwordInUrl; + varvar userInUrl; + varvar passwordInUrl; if (parsedConnectionStr.auth && _.isString(parsedConnectionStr.auth)) { const authPieces = parsedConnectionStr.auth.split(/:/); if (authPieces[0]) { @@ -348,12 +348,12 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Parse the rest of the standard information from the URL. - const hostInUrl = parsedConnectionStr.hostname; - const portInUrl = parsedConnectionStr.port; - let databaseInUrl = parsedConnectionStr.pathname; + var hostInUrl = parsedConnectionStr.hostname; + var portInUrl = parsedConnectionStr.port; + var databaseInUrl = parsedConnectionStr.pathname; // And finally parse the non-standard info from the URL's querystring. - let miscOptsInUrlQs; + var miscOptsInUrlQs; try { miscOptsInUrlQs = qs.parse(parsedConnectionStr.query); } catch (e) { @@ -441,7 +441,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // And finally, rebuild the URL - let rebuiltUrl = ''; + var rebuiltUrl = ''; // Start with the protocol... rebuiltUrl += parsedConnectionStr.protocol+'//'; @@ -508,7 +508,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // > If there were any non-standard options, we'll **LEAVE THEM IN** the URL // > when we rebuild it. But note that we did fold them into the dsConfig // > dictionary as well earlier. - const newQs = qs.stringify(miscOptsInUrlQs); + var newQs = qs.stringify(miscOptsInUrlQs); if (newQs.length > 0) { rebuiltUrl += '?'+newQs; } From e7392091dc098cfcce12f4f7de19a40e2c2614a7 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 20:31:52 +0100 Subject: [PATCH 072/193] chore: revert changes --- lib/private/normalize-datastore-config/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/normalize-datastore-config/index.js b/lib/private/normalize-datastore-config/index.js index ea197d4c1..f42b0665f 100644 --- a/lib/private/normalize-datastore-config/index.js +++ b/lib/private/normalize-datastore-config/index.js @@ -66,7 +66,7 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // If items in BASELINE_PROPS are included in the querystring of the connection url, // they are allowed to remain, but are not automatically applied at the top-level. // (Note that this whitelist applies to overrides AND to querystring-encoded values) - varvar BASELINE_PROPS = [ + var BASELINE_PROPS = [ 'url', 'adapter', 'schema', @@ -334,10 +334,10 @@ module.exports = function normalizeDatastoreConfig (dsConfig, whitelist, expecte // Parse authentication credentials from url, if specified. - varvar userInUrl; - varvar passwordInUrl; + var userInUrl; + var passwordInUrl; if (parsedConnectionStr.auth && _.isString(parsedConnectionStr.auth)) { - const authPieces = parsedConnectionStr.auth.split(/:/); + var authPieces = parsedConnectionStr.auth.split(/:/); if (authPieces[0]) { userInUrl = authPieces[0]; }//>- From 8370a46040c521f8b0e33e9ef7db8eb16dc4a6e8 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:01:33 +0100 Subject: [PATCH 073/193] chore: revert changes --- lib/private/constants/table-name.input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/constants/table-name.input.js b/lib/private/constants/table-name.input.js index a925ce408..a0238e4a0 100644 --- a/lib/private/constants/table-name.input.js +++ b/lib/private/constants/table-name.input.js @@ -2,7 +2,7 @@ * `tableName` * * @constant - * @type {Object} + * @type {InputDef} */ module.exports = { friendlyName: 'Table name', From cc6d9825c23fa631cf017117fd5eac0e69b4ef21 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:02:55 +0100 Subject: [PATCH 074/193] chore: revert changes --- lib/private/constants/query.input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/constants/query.input.js b/lib/private/constants/query.input.js index 074ce9db0..9921bc3f0 100644 --- a/lib/private/constants/query.input.js +++ b/lib/private/constants/query.input.js @@ -2,7 +2,7 @@ * `query` * * @constant - * @type {Object} + * @type {InputDef} */ module.exports = { friendlyName: 'Query (s3q)', From 5bdce054b18f4e8cda4e0c596328554ca9fbc4a9 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:03:43 +0100 Subject: [PATCH 075/193] chore: revert changes --- lib/private/constants/not-unique.exit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/constants/not-unique.exit.js b/lib/private/constants/not-unique.exit.js index 9d860b48f..9270d668e 100644 --- a/lib/private/constants/not-unique.exit.js +++ b/lib/private/constants/not-unique.exit.js @@ -2,7 +2,7 @@ * `notUnique` * * @constant - * @type {Object} + * @type {ExitDef} */ module.exports = { description: 'Could not persist changes because they would violate one or more uniqueness constraints.', From 04630104bfedb9f3d579fbf9d997cd4950e9791e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:04:44 +0100 Subject: [PATCH 076/193] chore: revert changes --- lib/private/constants/meta.input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/constants/meta.input.js b/lib/private/constants/meta.input.js index 1104e0079..0bf3355c1 100644 --- a/lib/private/constants/meta.input.js +++ b/lib/private/constants/meta.input.js @@ -2,7 +2,7 @@ * `meta` * * @constant - * @type {Object} + * @type {InputDef} */ module.exports = { friendlyName: 'Meta (custom)', From 17f1656ea987a3f3591ed860502548019542f364 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:05:26 +0100 Subject: [PATCH 077/193] chore: revert changes --- lib/private/constants/connection.input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/constants/connection.input.js b/lib/private/constants/connection.input.js index 56b32d46e..790c9e5e4 100644 --- a/lib/private/constants/connection.input.js +++ b/lib/private/constants/connection.input.js @@ -2,7 +2,7 @@ * `connection` * * @constant - * @type {Object} + * @type {InputDef} */ module.exports = { description: 'The active database connection to use.', From a80f9250faebadb8706ec39c0a093f9163712f1c Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:06:55 +0100 Subject: [PATCH 078/193] chore: revert changes --- lib/private/constants/dry-orm.input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/constants/dry-orm.input.js b/lib/private/constants/dry-orm.input.js index e1a113654..5f82e9ec0 100644 --- a/lib/private/constants/dry-orm.input.js +++ b/lib/private/constants/dry-orm.input.js @@ -2,7 +2,7 @@ * `dryOrm` * * @constant - * @type {Object} + * @type {InputDef} */ module.exports = { friendlyName: 'Dry ORM', From 94097b90f90a96b053c3a14af6e83c25b4fe56d8 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:13:57 +0100 Subject: [PATCH 079/193] chore: revert changes --- lib/private/do-with-connection.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/private/do-with-connection.js b/lib/private/do-with-connection.js index 06c544e08..d8cbfafb1 100644 --- a/lib/private/do-with-connection.js +++ b/lib/private/do-with-connection.js @@ -2,9 +2,9 @@ * Module dependencies */ -const assert = require('assert'); -const util = require('util'); -const _ = require('@sailshq/lodash'); +var assert = require('assert'); +var util = require('util'); +var _ = require('@sailshq/lodash'); /** @@ -18,14 +18,14 @@ const _ = require('@sailshq/lodash'); * > https://github.com/balderdashy/sails-hook-orm/blob/1cdb652aea41e2ede2305caef0d0167b79c5c052/lib/datastore-method-utils/private/do-with-connection.js * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} options + * @param {Dictionary} options * @required {Ref} WET_MACHINES * @required * @either {Ref} manager * @or {Ref} connection * * @required {Function} during - * @param {any} db [The database connection.] + * @param {Ref} db [The database connection.] * @param {Function} proceed * @param {Error?} err * @param {Ref?} resultMaybe @@ -62,13 +62,13 @@ module.exports = function doWithConnection(options, done){ }//-• if (options.WET_MACHINES.getConnection.sync) { - let connection; + var connection; try { connection = options.WET_MACHINES.getConnection({ manager: options.manager }).execSync().connection; // (`report.meta` is ignored...) } catch (e) { if (e.exit === 'failed') { - const failureReport = e.output; + var failureReport = e.output; if (failureReport.meta) { failureReport.error.meta = failureReport.meta; } return proceed(failureReport.error); } @@ -104,7 +104,7 @@ module.exports = function doWithConnection(options, done){ // Note that, if you try to call the callback more than once in the iteratee, // this method logs a warning explaining what's up, ignoring any subsequent calls // to the callback that occur after the first one. - let didDuringFnAlreadyHalt; + var didDuringFnAlreadyHalt; try { options.during(db, function (err, resultMaybe) { if (err) { return proceed(err); } From 1f058f79cc2bac874e9e4d296f41ae921c22b371 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:16:15 +0100 Subject: [PATCH 080/193] chore: revert changes --- lib/private/build-std-adapter-method.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/private/build-std-adapter-method.js b/lib/private/build-std-adapter-method.js index 4ff8e2999..34e1eca8a 100644 --- a/lib/private/build-std-adapter-method.js +++ b/lib/private/build-std-adapter-method.js @@ -1,10 +1,10 @@ /** * Module dependencies */ - -const _ = require('@sailshq/lodash'); -const Machine = require('machine'); -const doWithConnection = require('./do-with-connection'); +Dictionary; +var _ = require('@sailshq/lodash'); +var Machine = require('machine'); +var doWithConnection = require('./do-with-connection'); /** @@ -21,27 +21,27 @@ const doWithConnection = require('./do-with-connection'); * > This is a stopgap. * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} machineDef (dry) - * @param {Object} WET_MACHINES (for convenience) - * @param {Object} registeredDsEntries - * @param {Object} registeredDryModels + * @param {Dictionary} machineDef (dry) + * @param {Dictionary} WET_MACHINES (for convenience) + * @param {Dictionary} registeredDsEntries + * @param {Dictionary} registeredDryModels * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @returns {Function} * @param {String} datastoreName - * @param {Object} s3q + * @param {Dictionary} s3q * @param {Function} done * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ module.exports = function buildStdAdapterMethod (machineDef, WET_MACHINES, registeredDsEntries, registeredDryModels) { // Build wet machine. - const performQuery = Machine.build(machineDef); + var performQuery = Machine.build(machineDef); // Return function that will be the adapter method. return function (datastoreName, s3q, done) { // Look up the datastore entry (to get the manager). - const dsEntry = registeredDsEntries[datastoreName]; + var dsEntry = registeredDsEntries[datastoreName]; // Sanity check: if (_.isUndefined(dsEntry)) { @@ -56,7 +56,7 @@ module.exports = function buildStdAdapterMethod (machineDef, WET_MACHINES, regis meta: s3q.meta, during: function (connection, proceed) { - const handlers = { + var handlers = { error: function (err) { return proceed(err); }, success: function (result) { return proceed(undefined, result); } }; From e0fb78dc1cfcd24a6462f09e59adb5b45105faa0 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:16:51 +0100 Subject: [PATCH 081/193] chore: revert changes --- lib/private/build-std-adapter-method.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/private/build-std-adapter-method.js b/lib/private/build-std-adapter-method.js index 34e1eca8a..3f9e2c796 100644 --- a/lib/private/build-std-adapter-method.js +++ b/lib/private/build-std-adapter-method.js @@ -1,7 +1,6 @@ /** * Module dependencies */ -Dictionary; var _ = require('@sailshq/lodash'); var Machine = require('machine'); var doWithConnection = require('./do-with-connection'); From cb5699a78807821e98f3d7c84ca1ea478a0df650 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:18:01 +0100 Subject: [PATCH 082/193] chore: revert changes --- lib/private/build-std-adapter-method.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/build-std-adapter-method.js b/lib/private/build-std-adapter-method.js index 3f9e2c796..c3687c404 100644 --- a/lib/private/build-std-adapter-method.js +++ b/lib/private/build-std-adapter-method.js @@ -1,6 +1,7 @@ /** * Module dependencies */ + var _ = require('@sailshq/lodash'); var Machine = require('machine'); var doWithConnection = require('./do-with-connection'); From 0de57fe48f6a1ff55257bd92f701e800c43d0d2b Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:20:20 +0100 Subject: [PATCH 083/193] chore: revert changes --- lib/private/machines/avg-records.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/private/machines/avg-records.js b/lib/private/machines/avg-records.js index 7ff0361f8..344e931f1 100644 --- a/lib/private/machines/avg-records.js +++ b/lib/private/machines/avg-records.js @@ -27,24 +27,24 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - const _ = require('@sailshq/lodash'); - const buildMongoWhereClause = require('./private/build-mongo-where-clause'); + var _ = require('@sailshq/lodash'); + var buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - const s3q = inputs.query; + var s3q = inputs.query; // Local var for the `tableName`, for clarity. - const tableName = s3q.using; + var tableName = s3q.using; // Local var for the name of the numeric field, for clarity. // // > Remember: Contrary to what you might think given its naming, // > by the time it gets to the adapter (in an s3q), the `numericAttrName` // > qk has already been normalized to be a column name, not an attribute name. - const numericFieldName = s3q.numericAttrName; + var numericFieldName = s3q.numericAttrName; // Grab the model definition - const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -53,7 +53,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - let mongoWhere; + var mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -61,9 +61,9 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - const db = inputs.connection; - const mongoCollection = db.collection(tableName); - const cursor = mongoCollection.aggregate([ + var db = inputs.connection; + var mongoCollection = db.collection(tableName); + var cursor = mongoCollection.aggregate([ { $match: mongoWhere }, { $group: { @@ -76,7 +76,7 @@ module.exports = { ], { cursor: {} }); cursor.toArray().then(function aggregateCb(nativeResult) { - let mean = 0; + var mean = 0; if (_.first(nativeResult)) { mean = _.first(nativeResult).avg; } return exits.success(mean); }).catch(function(err) { From fba5a2aa33bdd46e616cc0bc7fe5947664cca66b Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:23:11 +0100 Subject: [PATCH 084/193] chore: revert changes --- lib/private/machines/count-records.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/private/machines/count-records.js b/lib/private/machines/count-records.js index 70c1e8220..58974cb3b 100644 --- a/lib/private/machines/count-records.js +++ b/lib/private/machines/count-records.js @@ -28,20 +28,20 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - const _ = require('@sailshq/lodash'); - const buildMongoWhereClause = require('./private/build-mongo-where-clause'); + var _ = require('@sailshq/lodash'); + var buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - const s3q = inputs.query; + var s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (COUNT RECORDS):',require('util').inspect(s3q,{depth:5}),'\n'); } // Local var for the `tableName`, for clarity. - const tableName = s3q.using; + var tableName = s3q.using; // Grab the model definition - const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -50,7 +50,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - let mongoWhere; + var mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -59,8 +59,8 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - const db = inputs.connection; - const mongoCollection = db.collection(tableName); + var db = inputs.connection; + var mongoCollection = db.collection(tableName); mongoCollection.countDocuments(mongoWhere).then(function count(nativeResult) { return exits.success(nativeResult); }).catch(function (err) { return exits.error(err); }); From 966450aa5b2a6b1a90995cdd2bd121c2c7974ef2 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 3 Nov 2023 21:28:13 +0100 Subject: [PATCH 085/193] chore: revert changes --- lib/private/machines/create-each-record.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/private/machines/create-each-record.js b/lib/private/machines/create-each-record.js index b95d4b942..30e045ff9 100644 --- a/lib/private/machines/create-each-record.js +++ b/lib/private/machines/create-each-record.js @@ -29,15 +29,15 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - const _ = require('@sailshq/lodash'); - const processNativeRecord = require('./private/process-native-record'); - const processNativeError = require('./private/process-native-error'); - const reifyValuesToSet = require('./private/reify-values-to-set'); + var _ = require('@sailshq/lodash'); + var processNativeRecord = require('./private/process-native-record'); + var processNativeError = require('./private/process-native-error'); + var reifyValuesToSet = require('./private/reify-values-to-set'); // Local var for the stage 3 query, for easier access. - const s3q = inputs.query; + var s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (CREATE EACH RECORD):',require('util').inspect(s3q,{depth:5}),'\n'); } @@ -46,7 +46,7 @@ module.exports = { var tableName = s3q.using; // Grab the model definition - const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -65,7 +65,7 @@ module.exports = { // ╔╦╗╔═╗╔╦╗╔═╗╦═╗╔╦╗╦╔╗╔╔═╗ ┬ ┬┬ ┬┌─┐┌┬┐┬ ┬┌─┐┬─┐ ┌┬┐┌─┐ ╔═╗╔═╗╔╦╗╔═╗╦ ╦ ┌─┐┬─┐ ┌┐┌┌─┐┌┬┐ // ║║║╣ ║ ║╣ ╠╦╝║║║║║║║║╣ │││├─┤├┤ │ ├─┤├┤ ├┬┘ │ │ │ ╠╣ ║╣ ║ ║ ╠═╣ │ │├┬┘ ││││ │ │ // ═╩╝╚═╝ ╩ ╚═╝╩╚═╩ ╩╩╝╚╝╚═╝ └┴┘┴ ┴└─┘ ┴ ┴ ┴└─┘┴└─ ┴ └─┘ ╚ ╚═╝ ╩ ╚═╝╩ ╩ └─┘┴└─ ┘└┘└─┘ ┴ - let isFetchEnabled; + var isFetchEnabled; if (s3q.meta && s3q.meta.fetch) { isFetchEnabled = true; } else { isFetchEnabled = false; } @@ -77,8 +77,8 @@ module.exports = { // FUTURE: Carry through the `fetch: false` optimization all the way to Mongo here, // if possible (e.g. using Mongo's projections API) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - const db = inputs.connection; - const mongoCollection = db.collection(tableName); + var db = inputs.connection; + var mongoCollection = db.collection(tableName); // if (s3q.meta && s3q.meta.logMongoS3Qs) { // console.log('- - - - - - - - - -CREATE EACH: s3q.newRecords:',require('util').inspect(s3q.newRecords,{depth:5}),'\n'); // } @@ -88,7 +88,7 @@ module.exports = { return exits.success(); }//-• - const insertedIds = Object.values(nativeResult.insertedIds); + var insertedIds = Object.values(nativeResult.insertedIds); // Otherwise, IWMIH we'll be sending back records: // ============================================ @@ -97,7 +97,7 @@ module.exports = { // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ │││ └─┐ │ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘└─└─┘─┘ // Process record(s) (mutate in-place) to wash away adapter-specific eccentricities. - const phRecords = await mongoCollection.find({ _id: { $in: insertedIds } }).toArray(); + var phRecords = await mongoCollection.find({ _id: { $in: insertedIds } }).toArray(); try { _.each(phRecords, function (phRecord){ processNativeRecord(phRecord, WLModel, s3q.meta); From 66b14905601439445c42191f61fd1a2d28c8f31b Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:17:57 +0100 Subject: [PATCH 086/193] chore: revert changes --- lib/index.js | 84 ++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/lib/index.js b/lib/index.js index 1bc1f08da..f14edf6d8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,14 +2,14 @@ * Module dependencies */ -const util = require('util'); -const _ = require('@sailshq/lodash'); -const flaverr = require('flaverr'); -const async = require('async'); -const Machine = require('machine'); -const mongodb = require('mongodb'); -const normalizeDatastoreConfig = require('./private/normalize-datastore-config'); -const buildStdAdapterMethod = require('./private/build-std-adapter-method'); +var util = require('util'); +var _ = require('@sailshq/lodash'); +var flaverr = require('flaverr'); +var async = require('async'); +var Machine = require('machine'); +var mongodb = require('mongodb'); +var normalizeDatastoreConfig = require('./private/normalize-datastore-config'); +var buildStdAdapterMethod = require('./private/build-std-adapter-method'); /** @@ -19,7 +19,7 @@ const buildStdAdapterMethod = require('./private/build-std-adapter-method'); // Private var to cache dry machine definitions. // > This is set up in a dictionary instead of as separate variables // > just to allow the code below to be a bit easier to read) -const DRY_MACHINES = { +var DRY_MACHINES = { verifyModelDef: require('./private/machines/verify-model-def'), createManager: require('./private/machines/create-manager'), destroyManager: require('./private/machines/destroy-manager'), @@ -33,16 +33,16 @@ const DRY_MACHINES = { // Private var to cache pre-built machines for certain adapter methods. // (This is an optimization for improved performance.) -const WET_MACHINES = {}; +var WET_MACHINES = {}; _.each(DRY_MACHINES, function(def, methodName) { WET_MACHINES[methodName] = Machine.build(def); }); -const CONFIG_WHITELIST = require('./private/constants/config-whitelist.constant'); +var CONFIG_WHITELIST = require('./private/constants/config-whitelist.constant'); -const EXPECTED_URL_PROTOCOL_PFX = require('./private/constants/expected-url-protocol-pfx.constant'); +var EXPECTED_URL_PROTOCOL_PFX = require('./private/constants/expected-url-protocol-pfx.constant'); @@ -57,12 +57,12 @@ const EXPECTED_URL_PROTOCOL_PFX = require('./private/constants/expected-url-prot // > Note that this approach of process global state will be changing in an upcoming version of // > the Waterline adapter spec (a breaking change). But if you follow the conventions laid out // > below in this adapter template, future upgrades should be a breeze. -const registeredDsEntries = {}; +var registeredDsEntries = {}; // Keep track of all the model definitions registered by the adapter (for the entire Node process). // (indexed by the model's `identity` -- NOT by its `tableName`!!) -const registeredDryModels = {}; +var registeredDryModels = {}; @@ -88,10 +88,10 @@ const registeredDryModels = {}; * > If you do go that route, it's conventional in Node to create a `./lib` directory for your private submodules * > and `require` them at the top of this file with other dependencies. e.g.: * > ``` - * > const updateMethod = require('./lib/update'); + * > var updateMethod = require('./lib/update'); * > ``` * - * @type {Object} + * @type {Dictionary} */ @@ -164,9 +164,9 @@ module.exports = { * * > Waterline calls this method once for every datastore that is configured to use this adapter. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} dsConfig »-> Dictionary (plain JavaScript object) of configuration options for this datastore (e.g. host, port, etc.) + * @param {Dictionary} dsConfig »-> Dictionary (plain JavaScript object) of configuration options for this datastore (e.g. host, port, etc.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} physicalModelsReport »–> Experimental: The physical models using this datastore (keyed by "tableName"-- NOT by `identity`!). This may change in a future release of the adapter spec. + * @param {Dictionary} physicalModelsReport »–> Experimental: The physical models using this datastore (keyed by "tableName"-- NOT by `identity`!). This may change in a future release of the adapter spec. * ˚¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ * ˙ **: {Dictionary} :: Info about a physical model using this datastore. WARNING: This is in a bit of an unusual format. * ˚¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\ @@ -188,7 +188,7 @@ module.exports = { registerDatastore: function (dsConfig, physicalModelsReport, done) { // Grab the unique name for this datastore for easy access below. - const datastoreName = dsConfig.identity; + var datastoreName = dsConfig.identity; // Some sanity checks: if (!datastoreName) { @@ -223,7 +223,7 @@ module.exports = { // ============================================================================================ if (WET_MACHINES.verifyModelDef) { - const modelIncompatibilitiesMap = {}; + var modelIncompatibilitiesMap = {}; try { _.each(physicalModelsReport, function (phModelInfo){ try { @@ -237,7 +237,7 @@ module.exports = { });// } catch (e) { return done(e); } - const numNotCompatible = _.keys(modelIncompatibilitiesMap).length; + var numNotCompatible = _.keys(modelIncompatibilitiesMap).length; if (numNotCompatible > 0) { return done(flaverr('E_MODELS_NOT_COMPATIBLE', new Error( numNotCompatible+' model(s) are not compatible with this adapter:\n'+ @@ -380,7 +380,7 @@ module.exports = { teardown: function (datastoreName, done) { // Look up the datastore entry (manager/driver/config). - const dsEntry = registeredDsEntries[datastoreName]; + var dsEntry = registeredDsEntries[datastoreName]; // Sanity checks: if (!datastoreName) { @@ -400,7 +400,7 @@ module.exports = { WET_MACHINES.destroyManager({ manager: dsEntry.manager }).switch({ error: function(err) { return done(new Error('Encountered unexpected error when attempting to destroy the connection manager.\n\n```\n'+err.stack+'\n```')); }, failed: function(report) { - const err = new Error('Datastore (`'+datastoreName+'`) could not be torn down because of a failure when attempting to destroy the connection manager.\n\n```\n'+report.error.stack+'\n```'); + var err = new Error('Datastore (`'+datastoreName+'`) could not be torn down because of a failure when attempting to destroy the connection manager.\n\n```\n'+report.error.stack+'\n```'); err.raw = report.error; if (report.meta) { err.meta = report.meta; } return done(err); @@ -512,11 +512,11 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} s3q The stage-3 query to perform. + * @param {Dictionary} s3q The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} err - * @param {Object?} record + * @param {Dictionary?} record * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ create: buildStdAdapterMethod(require('./private/machines/create-record'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -535,7 +535,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} query The stage-3 query to perform. + * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} err @@ -559,7 +559,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} query The stage-3 query to perform. + * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} err @@ -582,7 +582,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} query The stage-3 query to perform. + * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} err @@ -615,7 +615,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} query The stage-3 query to perform. + * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} err @@ -641,7 +641,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} query The stage-3 query to perform. + * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} err @@ -665,7 +665,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} query The stage-3 query to perform. + * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} err @@ -699,7 +699,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} query The stage-3 query to perform. + * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} err @@ -736,7 +736,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} tableName The name of the table to define. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} phmDef The physical model definition (not a normal Sails/Waterline model-- log this for details.) + * @param {Dictionary} phmDef The physical model definition (not a normal Sails/Waterline model-- log this for details.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @@ -744,7 +744,7 @@ module.exports = { */ define: function (datastoreName, tableName, phmDef, done) { // Look up the datastore entry (manager/driver/config). - const dsEntry = registeredDsEntries[datastoreName]; + var dsEntry = registeredDsEntries[datastoreName]; // Sanity check: if (_.isUndefined(dsEntry)) { @@ -782,8 +782,8 @@ module.exports = { // Otherwise we'll need to create some indexes.... // First, get a reference to the Mongo collection. - const db = dsEntry.manager; - const mongoCollection = db.collection(tableName); + var db = dsEntry.manager; + var mongoCollection = db.collection(tableName); // Then simultaneously create all of the indexes: async.each(uniqueIndexesToCreate, function (key, next) { @@ -793,7 +793,7 @@ module.exports = { // // > This is the definition for a "single-field index". // > (https://docs.mongodb.com/manual/indexes/#index-types) - const mongoSingleFieldIdxKeys = {}; + var mongoSingleFieldIdxKeys = {}; mongoSingleFieldIdxKeys[key] = 1; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ^^^NOTE: @@ -841,15 +841,15 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} tableName The name of the table to drop. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Undefined} unused Currently unused (do not use this argument.) + * @param {Ref} unused Currently unused (do not use this argument.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * + * @param {Error?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ drop: async function (datastoreName, tableName, unused, done) { // Look up the datastore entry (manager/driver/config). - const dsEntry = registeredDsEntries[datastoreName]; + var dsEntry = registeredDsEntries[datastoreName]; // Sanity check: if (_.isUndefined(dsEntry)) { @@ -857,7 +857,7 @@ module.exports = { } // Drop the physical model (e.g. table/etc.) - const db = dsEntry.manager; + var db = dsEntry.manager; db.collection(tableName).drop().then(function () { // >-• // IWMIH, then either the physical model was successfully dropped, @@ -906,7 +906,7 @@ module.exports = { * @param {Number} sequenceValue The new value for the sequence (e.g. 1) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err + * @param {Error?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ From 96531c3df194c9246da11f44dd3a4c65e3fddaa7 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:22:46 +0100 Subject: [PATCH 087/193] chore: revert changes --- lib/index.js | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/index.js b/lib/index.js index f14edf6d8..e60c2c225 100644 --- a/lib/index.js +++ b/lib/index.js @@ -284,7 +284,7 @@ module.exports = { success: function (report) { try { - const manager = report.manager; + var manager = report.manager; // ╔╦╗╦═╗╔═╗╔═╗╦╔═ ┌┬┐┌─┐ ┌─┐┌┐┌┌┬┐┬─┐┬ ┬ // ║ ╠╦╝╠═╣║ ╠╩╗ ││└─┐ ├┤ │││ │ ├┬┘└┬┘ @@ -515,8 +515,8 @@ module.exports = { * @param {Dictionary} s3q The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err - * @param {Dictionary?} record + * @param {Error?} + * @param {Dictionary?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ create: buildStdAdapterMethod(require('./private/machines/create-record'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -538,8 +538,8 @@ module.exports = { * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err - * @param {Array?} createdRecords + * @param {Error?} + * @param {Array?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ createEach: buildStdAdapterMethod(require('./private/machines/create-each-record'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -562,8 +562,8 @@ module.exports = { * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err - * @param {Array?} updatedRecords + * @param {Error?} + * @param {Array?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ update: buildStdAdapterMethod(require('./private/machines/update-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -585,8 +585,8 @@ module.exports = { * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err - * @param {Array?} destroyedRecords + * @param {Error?} + * @param {Array?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ destroy: buildStdAdapterMethod(require('./private/machines/destroy-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -618,8 +618,8 @@ module.exports = { * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err - * @param {Array} physicalRecords [matching physical records] + * @param {Error?} + * @param {Array} [matching physical records] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ find: buildStdAdapterMethod(require('./private/machines/find-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -644,8 +644,8 @@ module.exports = { * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err - * @param {Array} physicalRecords [matching physical records, populated according to the join instructions] + * @param {Error?} + * @param {Array} [matching physical records, populated according to the join instructions] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ // ----------------------------------------------------- @@ -668,8 +668,8 @@ module.exports = { * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err - * @param {Number} numberOfMatchingRecords [the number of matching records] + * @param {Error?} + * @param {Number} [the number of matching records] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ count: buildStdAdapterMethod(require('./private/machines/count-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -682,11 +682,11 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {String} datastoreName The name of the datastore to perform the query on. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Object} query The stage-3 query to perform. + * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err - * @param {Number} sum [the sum] + * @param {Error?} + * @param {Number} [the sum] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ sum: buildStdAdapterMethod(require('./private/machines/sum-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -702,8 +702,8 @@ module.exports = { * @param {Dictionary} query The stage-3 query to perform. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} err - * @param {Number} average [the average ("mean")] + * @param {Error?} + * @param {Number} [the average ("mean")] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ avg: buildStdAdapterMethod(require('./private/machines/avg-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -739,7 +739,7 @@ module.exports = { * @param {Dictionary} phmDef The physical model definition (not a normal Sails/Waterline model-- log this for details.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * + * @param {Error?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ define: function (datastoreName, tableName, phmDef, done) { @@ -762,7 +762,7 @@ module.exports = { // Build an array of any UNIQUE indexes needed // > Go through each item in the definition to locate fields // > which demand a uniqueness constraint. - const uniqueIndexesToCreate = []; + var uniqueIndexesToCreate = []; _.each(phmDef, function (phmAttrDef, key) { if (_.has(phmAttrDef, 'unique') && phmAttrDef.unique) { uniqueIndexesToCreate.push(key); @@ -802,7 +802,7 @@ module.exports = { // Avoiding it for clarity, but just making note of the reason why. // Here's what it would look like, for reference: // ``` - // const mongoSingleFieldIdxKeys = _.zipObject([[key, 1]]); + // var mongoSingleFieldIdxKeys = _.zipObject([[key, 1]]); // ``` // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -847,7 +847,7 @@ module.exports = { * @param {Error?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - drop: async function (datastoreName, tableName, unused, done) { + drop: function (datastoreName, tableName, unused, done) { // Look up the datastore entry (manager/driver/config). var dsEntry = registeredDsEntries[datastoreName]; From cde8fcdd736ff4890615bb714c3ec3c6fb634be2 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:25:19 +0100 Subject: [PATCH 088/193] chore: revert changes --- lib/index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index e60c2c225..353767caf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -619,7 +619,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} - * @param {Array} [matching physical records] + * @param {Array} [matching physical records] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ find: buildStdAdapterMethod(require('./private/machines/find-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -645,7 +645,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} - * @param {Array} [matching physical records, populated according to the join instructions] + * @param {Array} [matching physical records, populated according to the join instructions] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ // ----------------------------------------------------- @@ -686,7 +686,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} - * @param {Number} [the sum] + * @param {Number} [the sum] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ sum: buildStdAdapterMethod(require('./private/machines/sum-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -703,7 +703,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback * @param {Error?} - * @param {Number} [the average ("mean")] + * @param {Number} [the average ("mean")] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ avg: buildStdAdapterMethod(require('./private/machines/avg-records'), WET_MACHINES, registeredDsEntries, registeredDryModels), @@ -739,10 +739,11 @@ module.exports = { * @param {Dictionary} phmDef The physical model definition (not a normal Sails/Waterline model-- log this for details.) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @param {Function} done Callback - * @param {Error?} + * @param {Error?} * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ define: function (datastoreName, tableName, phmDef, done) { + // Look up the datastore entry (manager/driver/config). var dsEntry = registeredDsEntries[datastoreName]; From c46934a035ab1cd235341e8fcc8bd2401c19a366 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:26:10 +0100 Subject: [PATCH 089/193] chore: revert changes --- lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/index.js b/lib/index.js index 353767caf..7e4bcd8cb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -849,6 +849,7 @@ module.exports = { * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ drop: function (datastoreName, tableName, unused, done) { + // Look up the datastore entry (manager/driver/config). var dsEntry = registeredDsEntries[datastoreName]; From 4fd3e26638eaa9d268060407ee8821449d47a17a Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:26:52 +0100 Subject: [PATCH 090/193] chore: revert changes --- lib/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/index.js b/lib/index.js index 7e4bcd8cb..09627fbc8 100644 --- a/lib/index.js +++ b/lib/index.js @@ -867,6 +867,7 @@ module.exports = { return done(); }).catch(function (err) { try { + if (err) { if (err.errmsg === 'ns not found') { throw flaverr('E_PHM_NOT_FOUND', new Error('No such physical model is currently defined.')); From 59b46822a769f959fd6aa5e0eccda1be63e48db8 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:36:03 +0100 Subject: [PATCH 091/193] chore: revert changes --- lib/private/machines/create-manager.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index 38774d841..8f3d86187 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -91,11 +91,11 @@ module.exports = { fn: function (inputs, exits) { - const _ = require('@sailshq/lodash'); - const NodeMongoDBNativeLib = require('mongodb'); - const CONFIG_WHITELIST = require('../constants/config-whitelist.constant'); - const EXPECTED_URL_PROTOCOL_PFX = require('../constants/expected-url-protocol-pfx.constant'); - const normalizeDatastoreConfig = require('../normalize-datastore-config'); + var _ = require('@sailshq/lodash'); + var NodeMongoDBNativeLib = require('mongodb'); + var CONFIG_WHITELIST = require('../constants/config-whitelist.constant'); + var EXPECTED_URL_PROTOCOL_PFX = require('../constants/expected-url-protocol-pfx.constant'); + var normalizeDatastoreConfig = require('../normalize-datastore-config'); // Note: // Support for different types of managers is database-specific, and is not @@ -106,7 +106,7 @@ module.exports = { // contributions to the core adapter in this area are welcome and greatly appreciated! // Normalize datastore. - let _clientConfig = _.extend({ + var _clientConfig = _.extend({ url: inputs.connectionString }, inputs.meta); @@ -122,13 +122,13 @@ module.exports = { // Mongo doesn't like some of our standard properties, so we'll remove them // (we don't need any of them now anyway, since we know at this point that // they'll have been baked into the URL) - const mongoUrl = _clientConfig.url; + var mongoUrl = _clientConfig.url; _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); // https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect/ NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig) .then(function (client) { - const manager = client.db(_clientConfig.database); + var manager = client.db(_clientConfig.database); manager.client = client; From 915e89c690a53393d02a150955f87544a34c7187 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:39:09 +0100 Subject: [PATCH 092/193] chore: revert changes --- lib/private/machines/create-record.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index f80387269..5bb50447f 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -29,23 +29,22 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - // @ts-ignore - const _ = require('@sailshq/lodash'); - const processNativeRecord = require('./private/process-native-record'); - const processNativeError = require('./private/process-native-error'); - const reifyValuesToSet = require('./private/reify-values-to-set'); + var _ = require('@sailshq/lodash'); + var processNativeRecord = require('./private/process-native-record'); + var processNativeError = require('./private/process-native-error'); + var reifyValuesToSet = require('./private/reify-values-to-set'); // Local var for the stage 3 query, for easier access. - const s3q = inputs.query; + var s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (CREATE RECORD):',require('util').inspect(s3q,{depth:5}),'\n'); } // Local var for the `tableName`, for clarity. - const tableName = s3q.using; + var tableName = s3q.using; // Grab the model definition - const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -62,7 +61,7 @@ module.exports = { // ╔╦╗╔═╗╔╦╗╔═╗╦═╗╔╦╗╦╔╗╔╔═╗ ┬ ┬┬ ┬┌─┐┌┬┐┬ ┬┌─┐┬─┐ ┌┬┐┌─┐ ╔═╗╔═╗╔╦╗╔═╗╦ ╦ ┌─┐┬─┐ ┌┐┌┌─┐┌┬┐ // ║║║╣ ║ ║╣ ╠╦╝║║║║║║║║╣ │││├─┤├┤ │ ├─┤├┤ ├┬┘ │ │ │ ╠╣ ║╣ ║ ║ ╠═╣ │ │├┬┘ ││││ │ │ // ═╩╝╚═╝ ╩ ╚═╝╩╚═╩ ╩╩╝╚╝╚═╝ └┴┘┴ ┴└─┘ ┴ ┴ ┴└─┘┴└─ ┴ └─┘ ╚ ╚═╝ ╩ ╚═╝╩ ╩ └─┘┴└─ ┘└┘└─┘ ┴ - let isFetchEnabled; + var isFetchEnabled; if (s3q.meta && s3q.meta.fetch) { isFetchEnabled = true; } else { isFetchEnabled = false; } @@ -75,6 +74,14 @@ module.exports = { mongoCollection.insertOne(s3q.newRecord).then(async function documentInserted(nativeResult) { // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // FUTURE: Provide access to `insertId` somehow, even if `fetch` is not enabled: + // ``` + // var insertId = nativeResult.insertedId; + // ``` + // (Changes would need to happen in driver spec first---see: + // https://github.com/node-machine/driver-interface) + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - return exits.success(); }//-• From e38df9a483ba7024933836dbe07a1512ec9b0139 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:39:59 +0100 Subject: [PATCH 093/193] chore: revert changes --- lib/private/machines/create-record.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 5bb50447f..fc08cce80 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -69,8 +69,8 @@ module.exports = { // ║║║║╚═╗║╣ ╠╦╝ ║ ├┬┘├┤ │ │ │├┬┘ ││ // ╩╝╚╝╚═╝╚═╝╩╚═ ╩ ┴└─└─┘└─┘└─┘┴└──┴┘ // Create this new record in the database by inserting a document in the appropriate Mongo collection. - const db = inputs.connection; - const mongoCollection = db.collection(tableName); + var db = inputs.connection; + var mongoCollection = db.collection(tableName); mongoCollection.insertOne(s3q.newRecord).then(async function documentInserted(nativeResult) { // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { @@ -93,7 +93,7 @@ module.exports = { // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ ││ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘ // Process record (mutate in-place) to wash away adapter-specific eccentricities. - const phRecord = await mongoCollection.findOne({ _id: nativeResult.insertedId }); + var phRecord = await mongoCollection.findOne({ _id: nativeResult.insertedId }); try { processNativeRecord(phRecord, WLModel, s3q.meta); } catch (e) { return exits.error(e); } From 23aeb4a94d39c37aee9f99404f6caa1925e81cb4 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:40:56 +0100 Subject: [PATCH 094/193] chore: revert changes --- lib/private/machines/destroy-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/destroy-manager.js b/lib/private/machines/destroy-manager.js index 0a5ae175a..4643dd5dc 100644 --- a/lib/private/machines/destroy-manager.js +++ b/lib/private/machines/destroy-manager.js @@ -1,4 +1,4 @@ -const _ = require('@sailshq/lodash'); +var _ = require('@sailshq/lodash'); module.exports = { From 240e8b849cb0af5fc181f49927c5f80ce1b1b651 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:42:43 +0100 Subject: [PATCH 095/193] chore: revert changes --- lib/private/machines/find-records.js | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/private/machines/find-records.js b/lib/private/machines/find-records.js index 97b398e3c..97065e645 100644 --- a/lib/private/machines/find-records.js +++ b/lib/private/machines/find-records.js @@ -27,23 +27,23 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - const assert = require('assert'); - const _ = require('@sailshq/lodash'); - const processNativeRecord = require('./private/process-native-record'); - const buildMongoWhereClause = require('./private/build-mongo-where-clause'); + var assert = require('assert'); + var _ = require('@sailshq/lodash'); + var processNativeRecord = require('./private/process-native-record'); + var buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - const s3q = inputs.query; + var s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (FIND RECORDS):',require('util').inspect(s3q,{depth:10}),'\n'); } // Local var for the `tableName`, for clarity. - const tableName = s3q.using; + var tableName = s3q.using; // Grab the model definition - const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -53,11 +53,11 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ - const db = inputs.connection; - const mongoCollection = db.collection(tableName); + var db = inputs.connection; + var mongoCollection = db.collection(tableName); // Build a Mongo-style WHERE from the `where` clause. - let mongoWhere; + var mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -69,14 +69,14 @@ module.exports = { // Transform the `sort` clause from a stage 3 query into a Mongo sort. - const mongoSort = _.map(s3q.criteria.sort, function mapSort(s3qSortDirective) { + var mongoSort = _.map(s3q.criteria.sort, function mapSort(s3qSortDirective) { - const mongoSortDirective = []; + var mongoSortDirective = []; - const sortByKey = _.first(_.keys(s3qSortDirective)); + var sortByKey = _.first(_.keys(s3qSortDirective)); mongoSortDirective.push(sortByKey); - const sortDirection = s3qSortDirective[sortByKey]; + var sortDirection = s3qSortDirective[sortByKey]; assert(sortDirection === 'ASC' || sortDirection === 'DESC', 'At this point, the sort direction should always be ASC or DESC (capitalized). If you are seeing this message, there is probably a bug somewhere in your version of Waterline core.'); mongoSortDirective.push(sortDirection === 'ASC' ? 1 : -1); @@ -85,7 +85,7 @@ module.exports = { }); // Create the initial Mongo deferred, taking care of `where`, `limit`, and `sort`. - let mongoDeferred; + var mongoDeferred; try { assert(_.isNumber(s3q.criteria.limit), 'At this point, the limit should always be a number, but instead it is `'+s3q.criteria.limit+'`. If you are seeing this message, there is probably a bug somewhere in your version of Waterline core.'); mongoDeferred = mongoCollection.find(mongoWhere).limit(s3q.criteria.limit); @@ -99,7 +99,7 @@ module.exports = { if (s3q.criteria.select) { // Transform the stage-3 query select array into a Mongo projection dictionary. - const projection = _.reduce(s3q.criteria.select, function reduceProjection(memo, colName) { + var projection = _.reduce(s3q.criteria.select, function reduceProjection(memo, colName) { memo[colName] = 1; return memo; }, {}); From ffff3f16201a3624c4381153672bbd95acfba4df Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:44:53 +0100 Subject: [PATCH 096/193] chore: revert changes --- .../private/build-mongo-where-clause.js | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/private/machines/private/build-mongo-where-clause.js b/lib/private/machines/private/build-mongo-where-clause.js index a611283b1..d6c6f618f 100644 --- a/lib/private/machines/private/build-mongo-where-clause.js +++ b/lib/private/machines/private/build-mongo-where-clause.js @@ -2,10 +2,10 @@ * Module dependencies */ -const util = require('util'); -const assert = require('assert'); -const _ = require('@sailshq/lodash'); -const normalizeMongoObjectId = require('./normalize-mongo-object-id'); +var util = require('util'); +var assert = require('assert'); +var _ = require('@sailshq/lodash'); +var normalizeMongoObjectId = require('./normalize-mongo-object-id'); /** @@ -14,11 +14,11 @@ const normalizeMongoObjectId = require('./normalize-mongo-object-id'); * Build a Mongo "query filter" from the specified S3Q `where` clause. * > Note: The provided `where` clause is NOT mutated. * - * @param {Object} whereClause [`where` clause from the criteria of a S3Q] - * @param {Object} WLModel - * @param {Object?} meta const [`meta` query key from the s3q] + * @param {Dictionary} whereClause [`where` clause from the criteria of a S3Q] + * @param {Ref} WLModel + * @param {Dictionary?} meta const [`meta` query key from the s3q] * - * @returns {Object} [Mongo "query filter"] + * @returns {Dictionary} [Mongo "query filter"] */ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { @@ -42,8 +42,8 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Recursively build and return a transformed `where` clause for use with Mongo. - const mongoQueryFilter = (function recurse(branch) { - const loneKey = _.first(_.keys(branch)); + var mongoQueryFilter = (function recurse(branch) { + var loneKey = _.first(_.keys(branch)); // ╔═╗╦═╗╔═╗╔╦╗╦╔═╗╔═╗╔╦╗╔═╗ // ╠═╝╠╦╝║╣ ║║║║ ╠═╣ ║ ║╣ @@ -58,8 +58,8 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { }//-• // IWMIH, we're dealing with a constraint of some kind. - const constraintColumnName = loneKey; - const constraint = branch[constraintColumnName]; + var constraintColumnName = loneKey; + var constraint = branch[constraintColumnName]; // Determine whether we should compare as an object id. @@ -72,12 +72,12 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { // > try to convert the eq constraint / relevant modifier into an ObjectId // > instance, if possible. (We still gracefully fall back to tolerate // > filtering by pk/fk vs. miscellaneous strings.) - let doCompareAsObjectIdIfPossible; + var doCompareAsObjectIdIfPossible; assert(_.isString(WLModel.primaryKey) && WLModel.primaryKey, 'Model def should always have a `primaryKey` setting by the time the model definition is handed down to the adapter (this should have already been taken care of in WL core)'); - const pkAttrDef = WLModel.attributes[WLModel.primaryKey]; + var pkAttrDef = WLModel.attributes[WLModel.primaryKey]; assert(_.isObject(pkAttrDef), 'PK attribute should always exist (this should have already been taken care of in WL core)'); - const pkColumnName = pkAttrDef.columnName; + var pkColumnName = pkAttrDef.columnName; assert(_.isString(pkColumnName) && pkColumnName, 'PK attribute should always have a column name by the time the model definition is handed down to the adapter (this should have already been taken care of in WL core). But actual pk attribute def on the model looks like this: '+util.inspect(pkAttrDef, {depth:5})+''); if (constraintColumnName === pkColumnName && (!meta || !meta.modelsNotUsingObjectIds || !_.contains(meta.modelsNotUsingObjectIds, WLModel.identity))) { @@ -85,7 +85,7 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { } else { _.each(WLModel.attributes, function (attrDef /*, attrName */) { - const isForeignKey = !!attrDef.model; + var isForeignKey = !!attrDef.model; // Sanity checks: if (isForeignKey) { assert(attrDef.foreignKey, 'attribute has a `model` property, but wl-schema did not give it `foreignKey: true`!'); @@ -123,8 +123,8 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { // ╔═╗╔═╗╔╦╗╔═╗╦ ╔═╗═╗ ╦ ╔═╗╔═╗╔╗╔╔═╗╔╦╗╦═╗╔═╗╦╔╗╔╔╦╗ // ║ ║ ║║║║╠═╝║ ║╣ ╔╩╦╝ ║ ║ ║║║║╚═╗ ║ ╠╦╝╠═╣║║║║ ║ // ╚═╝╚═╝╩ ╩╩ ╩═╝╚═╝╩ ╚═ ╚═╝╚═╝╝╚╝╚═╝ ╩ ╩╚═╩ ╩╩╝╚╝ ╩ - const modifierKind = _.first(_.keys(constraint)); - let modifier = constraint[modifierKind]; + var modifierKind = _.first(_.keys(constraint)); + var modifier = constraint[modifierKind]; delete constraint[modifierKind]; From 640519cd7f4c9f369dafc45bd7bb4bb7bac9cd87 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:45:49 +0100 Subject: [PATCH 097/193] chore: revert changes --- lib/private/machines/private/build-mongo-where-clause.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/machines/private/build-mongo-where-clause.js b/lib/private/machines/private/build-mongo-where-clause.js index d6c6f618f..3cd9b4039 100644 --- a/lib/private/machines/private/build-mongo-where-clause.js +++ b/lib/private/machines/private/build-mongo-where-clause.js @@ -16,7 +16,7 @@ var normalizeMongoObjectId = require('./normalize-mongo-object-id'); * * @param {Dictionary} whereClause [`where` clause from the criteria of a S3Q] * @param {Ref} WLModel - * @param {Dictionary?} meta const [`meta` query key from the s3q] + * @param {Dictionary?} meta [`meta` query key from the s3q] * * @returns {Dictionary} [Mongo "query filter"] */ @@ -49,7 +49,7 @@ module.exports = function buildMongoWhereClause(whereClause, WLModel, meta) { // ╠═╝╠╦╝║╣ ║║║║ ╠═╣ ║ ║╣ // ╩ ╩╚═╚═╝═╩╝╩╚═╝╩ ╩ ╩ ╚═╝ if (loneKey === 'and' || loneKey === 'or') { - const conjunctsOrDisjuncts = branch[loneKey]; + var conjunctsOrDisjuncts = branch[loneKey]; branch['$' + loneKey] = _.map(conjunctsOrDisjuncts, function(conjunctOrDisjunct){ return recurse(conjunctOrDisjunct); }); From 404a92dcff77083392b6ba294021ebe8508f3e2d Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:46:40 +0100 Subject: [PATCH 098/193] chore: revert changes --- lib/private/machines/private/build-mongo-where-clause.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/private/build-mongo-where-clause.js b/lib/private/machines/private/build-mongo-where-clause.js index 3cd9b4039..39b775537 100644 --- a/lib/private/machines/private/build-mongo-where-clause.js +++ b/lib/private/machines/private/build-mongo-where-clause.js @@ -16,7 +16,7 @@ var normalizeMongoObjectId = require('./normalize-mongo-object-id'); * * @param {Dictionary} whereClause [`where` clause from the criteria of a S3Q] * @param {Ref} WLModel - * @param {Dictionary?} meta [`meta` query key from the s3q] + * @param {Dictionary?} meta [`meta` query key from the s3q] * * @returns {Dictionary} [Mongo "query filter"] */ From 472c68ec5218081e5be7bb0134ea5671deec347d Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:48:00 +0100 Subject: [PATCH 099/193] chore: revert changes --- .../machines/private/normalize-mongo-object-id.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/private/machines/private/normalize-mongo-object-id.js b/lib/private/machines/private/normalize-mongo-object-id.js index a8ef594b8..c1e109b6a 100644 --- a/lib/private/machines/private/normalize-mongo-object-id.js +++ b/lib/private/machines/private/normalize-mongo-object-id.js @@ -2,9 +2,9 @@ * Module dependencies */ -const _ = require('@sailshq/lodash'); -const flaverr = require('flaverr'); -const ObjectId = require('mongodb').ObjectID || require('mongodb').ObjectId; +var _ = require('@sailshq/lodash'); +var flaverr = require('flaverr'); +var ObjectId = require('mongodb').ObjectID || require('mongodb').ObjectId; /** * normalizeMongoObjectId() @@ -12,8 +12,8 @@ const ObjectId = require('mongodb').ObjectID || require('mongodb').ObjectId; * Ensure that the provided reference is either an Object Id instance; * or if it isn't, then attempt to construct one from it. * ----------------------------------------------------------------------------- - * @param {String|Object} supposedId [either a hex string or an ObjectId instance) - * @returns {Object} [an ObjectId instance] + * @param {Ref} supposedId [either a hex string or an ObjectId instance) + * @returns {Ref} [an ObjectId instance] * @throws {E_CANNOT_INTERPRET_AS_OBJECTID} * ----------------------------------------------------------------------------- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -73,7 +73,7 @@ module.exports = function normalizeMongoObjectId(supposedId) { // Otherwise try to interpret the supposed mongo id as a hex string. // (note that we also implement a failsafe) else if (_.isString(supposedId) && ObjectId.isValid(supposedId)) { - const objectified = new ObjectId(supposedId); + var objectified = new ObjectId(supposedId); // Sanity check: if (objectified.toString() !== supposedId) { From 1057938607930cec27b707aff1386652a95f19ac Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:49:02 +0100 Subject: [PATCH 100/193] chore: revert changes --- lib/private/machines/private/process-native-error.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/machines/private/process-native-error.js b/lib/private/machines/private/process-native-error.js index 27f070f4b..8cd0f738e 100644 --- a/lib/private/machines/private/process-native-error.js +++ b/lib/private/machines/private/process-native-error.js @@ -2,7 +2,7 @@ * Module dependencies */ -const _ = require('@sailshq/lodash'); +var _ = require('@sailshq/lodash'); /** @@ -11,7 +11,7 @@ const _ = require('@sailshq/lodash'); * Examine the provided native error and attach a `footprint`, if appropriate. * > The error MAY be mutated in place -- or rarely, a new Error instance might be returned instead. * - * @param {Object} err + * @param {Ref} err * @returns {Error} */ module.exports = function processNativeError(err) { @@ -42,7 +42,7 @@ module.exports = function processNativeError(err) { // If we can infer which field this error is referring to, then add // that problematic key to the `keys` array of the footprint. // > Remember, this is by "columnName", not attr name! - let problematicKey; + var problematicKey; // For now, we avoid trying to determine this extra information, since we don't // have a strategy that can successfully figure it out in a performant way From b4a7a66a573f1f84d9299e14e9cd6d8f93d6b722 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:50:38 +0100 Subject: [PATCH 101/193] chore: revert changes --- .../machines/private/reify-values-to-set.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/private/machines/private/reify-values-to-set.js b/lib/private/machines/private/reify-values-to-set.js index d5132e4bb..ed7557a50 100644 --- a/lib/private/machines/private/reify-values-to-set.js +++ b/lib/private/machines/private/reify-values-to-set.js @@ -2,10 +2,10 @@ * Module dependencies */ -const assert = require('assert'); -const _ = require('@sailshq/lodash'); -const flaverr = require('flaverr'); -const normalizeMongoObjectId = require('./normalize-mongo-object-id'); +var assert = require('assert'); +var _ = require('@sailshq/lodash'); +var flaverr = require('flaverr'); +var normalizeMongoObjectId = require('./normalize-mongo-object-id'); /** @@ -14,9 +14,9 @@ const normalizeMongoObjectId = require('./normalize-mongo-object-id'); * Prepare a dictionary of values to be used in a native database operation. * > The provided `valuesToSet` will be mutated in-place. * - * @param {Object} valuesToSet - * @param {Object} WLModel - * @param {Object?} meta [`meta` query key from the s3q] + * @param {Ref} valuesToSet + * @param {Ref} WLModel + * @param {Dictionary?} meta [`meta` query key from the s3q] * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * @throws {E_CANNOT_INTERPRET_AS_OBJECTID} */ @@ -29,15 +29,15 @@ module.exports = function reifyValuesToSet(valuesToSet, WLModel, meta) { assert(_.isObject(valuesToSet) && !_.isArray(valuesToSet) && !_.isFunction(valuesToSet),'2nd argument must be a WLModel, and it has to have a `definition` property for this utility to work.'); // Determine whether or not to use object ids. - const useObjectIds = !meta || !meta.modelsNotUsingObjectIds || !_.contains(meta.modelsNotUsingObjectIds, WLModel.identity); + var useObjectIds = !meta || !meta.modelsNotUsingObjectIds || !_.contains(meta.modelsNotUsingObjectIds, WLModel.identity); // If trying to set the PK value explicitly (e.g. `_id`), try to interpret it // as a hex string, instantiate a Mongo ObjectId instance for it, and swap out // the original string for that instead before proceeding. // (Why? See http://stackoverflow.com/a/27897720/486547) - const primaryKeyAttrName = WLModel.primaryKey; - const primaryKeyColumnName = WLModel.attributes[WLModel.primaryKey].columnName; - const pkValue = valuesToSet[primaryKeyColumnName]; + var primaryKeyAttrName = WLModel.primaryKey; + var primaryKeyColumnName = WLModel.attributes[WLModel.primaryKey].columnName; + var pkValue = valuesToSet[primaryKeyColumnName]; // If the PK value is set to `null`, then remove it. // > Remember: `null` here has special meaning in Waterline -- it means there @@ -66,9 +66,9 @@ module.exports = function reifyValuesToSet(valuesToSet, WLModel, meta) { // Now we'll do the same thing for any explicit foreign keys that were provided. // (i.e. for singular associations) _.each(WLModel.attributes, function (attrDef, attrName) { - const phRecordKey = attrDef.columnName; + var phRecordKey = attrDef.columnName; - const isForeignKey = !!attrDef.model; + var isForeignKey = !!attrDef.model; // Sanity checks: if (isForeignKey) { assert(attrDef.foreignKey, 'attribute has a `model` property, but wl-schema did not give it `foreignKey: true`!'); From b456449025be3a71c60702218f493238675e8d46 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:52:46 +0100 Subject: [PATCH 102/193] chore: revert changes --- lib/private/machines/release-connection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/release-connection.js b/lib/private/machines/release-connection.js index f89dbee18..d7d18f0a0 100644 --- a/lib/private/machines/release-connection.js +++ b/lib/private/machines/release-connection.js @@ -1,4 +1,4 @@ -const _ = require('@sailshq/lodash'); +var _ = require('@sailshq/lodash'); module.exports = { From 3fe2b8409ed19f3b92282bfdfa261b8a767979f6 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:54:09 +0100 Subject: [PATCH 103/193] chore: revert changes --- scripts/appveyor/install_mongodb.ps1 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 scripts/appveyor/install_mongodb.ps1 diff --git a/scripts/appveyor/install_mongodb.ps1 b/scripts/appveyor/install_mongodb.ps1 new file mode 100644 index 000000000..0c3cfdb68 --- /dev/null +++ b/scripts/appveyor/install_mongodb.ps1 @@ -0,0 +1,20 @@ +# Example. Not yet being used +$msiPath = "$($env:USERPROFILE)\mongodb-win32-x86_64-2008plus-ssl-3.0.4-signed.msi" +(New-Object Net.WebClient).DownloadFile('https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.0.4-signed.msi', $msiPath) +cmd /c start /wait msiexec /q /i $msiPath INSTALLLOCATION=C:\mongodb ADDLOCAL="all" +del $msiPath + +mkdir c:\mongodb\data\db | Out-Null +mkdir c:\mongodb\log | Out-Null + +'systemLog: + destination: file + path: c:\mongodb\log\mongod.log +storage: + dbPath: c:\mongodb\data\db' | Out-File C:\mongodb\mongod.cfg -Encoding utf8 + +cmd /c start /wait sc create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=C:\mongodb\mongod.cfg" DisplayName= "MongoDB" start= "demand" + +& c:\mongodb\bin\mongod --version + +Start-Service mongodb From be326d922861d6cfa9981a194fe8e1cd3851dbd8 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:55:13 +0100 Subject: [PATCH 104/193] chore: revert changes --- scripts/travis/install_mongodb.sh | 17 +++++++++++++++++ scripts/travis/run_mongodb.sh | 6 ++++++ 2 files changed, 23 insertions(+) create mode 100644 scripts/travis/install_mongodb.sh create mode 100644 scripts/travis/run_mongodb.sh diff --git a/scripts/travis/install_mongodb.sh b/scripts/travis/install_mongodb.sh new file mode 100644 index 000000000..499b7190f --- /dev/null +++ b/scripts/travis/install_mongodb.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +MDB_TGZ=mongodb-linux-x86_64-ubuntu1604-${MONGODB}.tgz +MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} +MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data + +# If it doesn't exist, it means the cache didn't pull it +if [ ! -f "${MDB_ROOT}/bin/mongod" ]; then + mkdir -p $MDB_ROOT + pushd $MDB_ROOT + wget https://fastdl.mongodb.org/linux/${MDB_TGZ} + tar xzf ${MDB_TGZ} --strip 1 + rm -f ${MDB_TGZ} + popd +fi +mkdir -p $MDB_DATA +"${MDB_ROOT}/bin/mongod" --version diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh new file mode 100644 index 000000000..ef67727a5 --- /dev/null +++ b/scripts/travis/run_mongodb.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} +MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data + +${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork From 8feb197d296b2a36162070cdc6eda3f8edb17943 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:57:57 +0100 Subject: [PATCH 105/193] chore: revert changes --- scripts/travis/run_mongodb.sh | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 scripts/travis/run_mongodb.sh diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh deleted file mode 100644 index ef67727a5..000000000 --- a/scripts/travis/run_mongodb.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} -MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data - -${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork From 895fed0a9b90583470feb36a0793e437b96a5903 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 09:58:51 +0100 Subject: [PATCH 106/193] chore: revert changes --- scripts/travis/run_mongodb.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 scripts/travis/run_mongodb.sh diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh new file mode 100644 index 000000000..ef67727a5 --- /dev/null +++ b/scripts/travis/run_mongodb.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} +MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data + +${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork From c54d1f76443e25814eb4a3d44cb60caf832c1606 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:00:41 +0100 Subject: [PATCH 107/193] chore: revert changes --- lib/private/machines/avg-records.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/private/machines/avg-records.js b/lib/private/machines/avg-records.js index 344e931f1..7b8e4097b 100644 --- a/lib/private/machines/avg-records.js +++ b/lib/private/machines/avg-records.js @@ -26,6 +26,7 @@ module.exports = { fn: function (inputs, exits) { + // Dependencies var _ = require('@sailshq/lodash'); var buildMongoWhereClause = require('./private/build-mongo-where-clause'); @@ -83,4 +84,5 @@ module.exports = { if (err) { return exits.error(err); } });// } + }; From 28b7cfde15b8ca83a48fc1bc6ed06d3a7c93c79f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:01:42 +0100 Subject: [PATCH 108/193] chore: revert changes --- test/connectable/create-manager.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/connectable/create-manager.test.js b/test/connectable/create-manager.test.js index c96e66897..c3ecfe5a6 100644 --- a/test/connectable/create-manager.test.js +++ b/test/connectable/create-manager.test.js @@ -1,6 +1,6 @@ -const assert = require('assert'); -const createManager = require('machine').build(require('../../').createManager); -const MongoClient = require('mongodb').MongoClient; +var assert = require('assert'); +var createManager = require('machine').build(require('../../').createManager); +var MongoClient = require('mongodb').MongoClient; describe('Connectable ::', function() { describe('Create Manager', function() { @@ -32,7 +32,7 @@ describe('Connectable ::', function() { it('should successfully return a Mongo Server instance', function(done) { // Needed to dynamically get the host using the docker container - const host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' From 7203ae877e1d4bf98461af6242d2844d62c19c59 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:02:19 +0100 Subject: [PATCH 109/193] chore: revert changes --- test/connectable/destroy-manager.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/connectable/destroy-manager.test.js b/test/connectable/destroy-manager.test.js index 079444dd4..61928732d 100644 --- a/test/connectable/destroy-manager.test.js +++ b/test/connectable/destroy-manager.test.js @@ -1,14 +1,14 @@ -const createManager = require('machine').build(require('../../').createManager); -const destroyManager = require('machine').build(require('../../').destroyManager); +var createManager = require('machine').build(require('../../').createManager); +var destroyManager = require('machine').build(require('../../').destroyManager); describe('Connectable ::', function() { describe('Destroy Manager', function() { - let manager; + var manager; // Create a manager before(function(done) { // Needed to dynamically get the host using the docker container - const host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' From 3886dd7c15abfd143e134be5116578c24ef4d5b1 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:03:06 +0100 Subject: [PATCH 110/193] chore: revert changes --- test/connectable/get-connection.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/connectable/get-connection.test.js b/test/connectable/get-connection.test.js index 1dd3667c3..9829424fd 100644 --- a/test/connectable/get-connection.test.js +++ b/test/connectable/get-connection.test.js @@ -1,15 +1,15 @@ -const assert = require('assert'); -const createManager = require('machine').build(require('../../').createManager); -const getConnection = require('machine').build(require('../../').getConnection); +var assert = require('assert'); +var createManager = require('machine').build(require('../../').createManager); +var getConnection = require('machine').build(require('../../').getConnection); describe('Connectable ::', function() { describe('Get Connection', function() { - let manager; + var manager; // Create a manager before(function(done) { // Needed to dynamically get the host using the docker container - const host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' From 6f94e5f2aed8a6ee603d53e0abeb8cbb66ad5822 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:04:02 +0100 Subject: [PATCH 111/193] chore: revert changes --- test/connectable/release-connection.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/connectable/release-connection.test.js b/test/connectable/release-connection.test.js index bad12c105..5fa68fe1e 100644 --- a/test/connectable/release-connection.test.js +++ b/test/connectable/release-connection.test.js @@ -1,16 +1,16 @@ -const createManager = require('machine').build(require('../../').createManager); -const getConnection = require('machine').build(require('../../').getConnection); -const releaseConnection = require('machine').build(require('../../').releaseConnection); +var createManager = require('machine').build(require('../../').createManager); +var getConnection = require('machine').build(require('../../').getConnection); +var releaseConnection = require('machine').build(require('../../').releaseConnection); describe('Connectable ::', function() { describe('Release Connection', function() { - let manager; - let connection; + var manager; + var connection; // Create a manager and connection before(function(done) { // Needed to dynamically get the host using the docker container - const host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' From fd98a297d8b77e431d0a0d6d7d0d4239e63e5c1e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:05:09 +0100 Subject: [PATCH 112/193] chore: revert changes --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 391b861bd..38792cbc6 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ This adapter implements the following methods: See [Extending Sails > Adapters > Custom Adapters](http://sailsjs.com/documentation/concepts/extending-sails/adapters/custom-adapters) in the [Sails documentation](http://sailsjs.com/documentation), or check out [recommended support options](http://sailsjs.com/support). -## Contributing + +## Contributing   [![Build Status](https://travis-ci.org/balderdashy/sails-mongo.svg?branch=master)](https://travis-ci.org/balderdashy/sails-mongo)   [![Build status on Windows](https://ci.appveyor.com/api/projects/status/u0i1o62tsw6ymbjd/branch/master?svg=true)](https://ci.appveyor.com/project/mikermcneil/sails-mongo/branch/master) Please observe the guidelines and conventions laid out in the [Sails project contribution guide](http://sailsjs.com/documentation/contributing) when opening issues or submitting pull requests. From 6b6e8a851b515345e9a1c59d31fa5fb85f39db86 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:05:37 +0100 Subject: [PATCH 113/193] chore: revert changes --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 38792cbc6..5f0bb9f24 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ This adapter implements the following methods: See [Extending Sails > Adapters > Custom Adapters](http://sailsjs.com/documentation/concepts/extending-sails/adapters/custom-adapters) in the [Sails documentation](http://sailsjs.com/documentation), or check out [recommended support options](http://sailsjs.com/support). - ## Contributing   [![Build Status](https://travis-ci.org/balderdashy/sails-mongo.svg?branch=master)](https://travis-ci.org/balderdashy/sails-mongo)   [![Build status on Windows](https://ci.appveyor.com/api/projects/status/u0i1o62tsw6ymbjd/branch/master?svg=true)](https://ci.appveyor.com/project/mikermcneil/sails-mongo/branch/master) Please observe the guidelines and conventions laid out in the [Sails project contribution guide](http://sailsjs.com/documentation/contributing) when opening issues or submitting pull requests. From 721095d9529d1554a7b93faffcd53d40db307a69 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:06:22 +0100 Subject: [PATCH 114/193] chore: revert changes --- appveyor.yml | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..c68b2724d --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,67 @@ +# # # # # # # # # # # # # # # # # # # # # # # # # # +# ╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╦╔═╗╦═╗ ┬ ┬┌┬┐┬ # +# ╠═╣╠═╝╠═╝╚╗╔╝║╣ ╚╦╝║ ║╠╦╝ └┬┘││││ # +# ╩ ╩╩ ╩ ╚╝ ╚═╝ ╩ ╚═╝╩╚═o ┴ ┴ ┴┴─┘ # +# # +# This file configures Appveyor CI. # +# (i.e. how we run the tests on Windows) # +# # +# https://www.appveyor.com/docs/lang/nodejs-iojs/ # +# # # # # # # # # # # # # # # # # # # # # # # # # # + + +# Test against these versions of Node.js. +environment: + WATERLINE_ADAPTER_TESTS_URL: localhost/testdb + WATERLINE_ADAPTER_TESTS_HOST: localhost + WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo + NODE_ENV: test + matrix: + - nodejs_version: "10" + - nodejs_version: "12" + - nodejs_version: "14" + +# Install scripts. (runs after repo cloning) +install: + # Get the latest stable version of Node.js + # (Not sure what this is for, it's just in Appveyor's example.) + - ps: Install-Product node $env:nodejs_version + # Don't let npm send metrics as it creates a file in the .npm folder invalidating the cache every time + - npm config set send-metrics false + # Install declared dependencies + - npm install --no-audit + +branches: + only: + - master + - upgrade-mongodb-drivers + - update-test-environment + +# Post-install test scripts. +test_script: + # Output Node and NPM version info. + # (Presumably just in case Appveyor decides to try any funny business? + # But seriously, always good to audit this kind of stuff for debugging.) + - node --version + - npm --version + # Run the actual tests. + - npm test + +# Setup Mongo Database +services: + - mongodb + + +# Don't actually build. +# (Not sure what this is for, it's just in Appveyor's example. +# I'm not sure what we're not building... but I'm OK with not +# building it. I guess.) +build: off + + +# # # # # # # # # # # # # # # # # # # # # # # # # # # # + +# TODO: Set up appveyor + mongo*: +# https://www.appveyor.com/docs/services-databases/ +# Old example on how to install different versions of MongoDB added to `scripts/appveyor/install_mongodb.ps1` +# # # # # # # # # # # # # # # # # # # # # # # # # # # # From 5a3bf56f8b3aac8e8ed3250451a812298a6dd125 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:06:58 +0100 Subject: [PATCH 115/193] chore: revert changes --- .travis.yml | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..4564cc1b6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,69 @@ +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # +# ╔╦╗╦═╗╔═╗╦ ╦╦╔═╗ ┬ ┬┌┬┐┬ # +# ║ ╠╦╝╠═╣╚╗╔╝║╚═╗ └┬┘││││ # +# o ╩ ╩╚═╩ ╩ ╚╝ ╩╚═╝o ┴ ┴ ┴┴─┘ # +# # +# This file configures Travis CI. # +# (i.e. how we run the tests... mainly) # +# # +# https://docs.travis-ci.com/user/customizing-the-build # +# # # # # # # # # # # # # # # # # # # # # # # # # # # # # + +dist: xenial + +language: node_js + +node_js: + - "12" + - "14" + - "16" + +env: + global: + - WATERLINE_ADAPTER_TESTS_URL=localhost/testdb + - WATERLINE_ADAPTER_TESTS_HOST=localhost + - WATERLINE_ADAPTER_TESTS_DATABASE=sails-mongo + - NODE_ENV=test + + matrix: + - MONGODB=3.6.18 + - MONGODB=4.0.18 + - MONGODB=4.2.7 + +cache: + directories: + - "$TRAVIS_BUILD_DIR/mongodb" + - "$HOME/.npm" + +matrix: + fast_finish: true + +before_install: + - chmod +x "$TRAVIS_BUILD_DIR/scripts/travis/install_mongodb.sh" "$TRAVIS_BUILD_DIR/scripts/travis/run_mongodb.sh" + - npm i -g npm@8.11.0 + +install: + # Don't let npm send metrics as it creates a file in the .npm folder invalidating the cache every time + - npm config set send-metrics false + - npm i --no-audit + - "$TRAVIS_BUILD_DIR/scripts/travis/install_mongodb.sh" + +before_script: + - "$TRAVIS_BUILD_DIR/scripts/travis/run_mongodb.sh" + +script: + - npm test + +after_script: + - pkill mongod + +branches: + only: + - master + - upgrade-mongodb-drivers + - update-test-environment + +notifications: + email: + - ci@sailsjs.com + - luislobo@gmail.com From 0e857a342e66d4d7582e7df1dbdf76385c9f7fde Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:07:34 +0100 Subject: [PATCH 116/193] chore: revert changes --- .github/lint.yml | 25 ----------------- .github/test-ubuntu.yml | 41 --------------------------- .github/test-windows.yml | 60 ---------------------------------------- 3 files changed, 126 deletions(-) delete mode 100644 .github/lint.yml delete mode 100644 .github/test-ubuntu.yml delete mode 100644 .github/test-windows.yml diff --git a/.github/lint.yml b/.github/lint.yml deleted file mode 100644 index ae62f67fa..000000000 --- a/.github/lint.yml +++ /dev/null @@ -1,25 +0,0 @@ - -name: sails-mongo lint - -on: - push - -jobs: - lint: - runs-on: ubuntu-22.04 - - strategy: - matrix: - node-version: [20] - - steps: - - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - npm install --no-audit --no-fund - - name: Run lint - run: | - npm run lint diff --git a/.github/test-ubuntu.yml b/.github/test-ubuntu.yml deleted file mode 100644 index f167330ac..000000000 --- a/.github/test-ubuntu.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: sails-mongo test (Ubuntu) - -on: - push - -env: - WATERLINE_ADAPTER_TESTS_URL: mongo/testdb:27027 - WATERLINE_ADAPTER_TESTS_HOST: mongo - WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo - NODE_ENV: test - -jobs: - test-ubuntu: - runs-on: ubuntu-22.04 - container: node:${{ matrix.node-version }} - - strategy: - matrix: - node-version: [16, 18, 20] - mongodb-version: ['4.4', '5', '6', '7'] - - services: - mongo: - image: mongo:${{ matrix.mongodb-version }} - ports: - - 27027:27017 - - steps: - - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - node --eval "console.log('Running Node.js: ' + process.version)" - node --eval "console.log('Current directory: ' + process.cwd())" - node --eval "console.log('Files in directory: ' + require('fs').readdirSync(process.cwd()))" - npm install --no-audit --no-fund - - name: Run test - run: | - npm run custom-tests diff --git a/.github/test-windows.yml b/.github/test-windows.yml deleted file mode 100644 index d609e6f1c..000000000 --- a/.github/test-windows.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: sails-mongo test (Windows) - -on: - push - -env: - WATERLINE_ADAPTER_TESTS_URL: 127.0.0.1/testdb - WATERLINE_ADAPTER_TESTS_HOST: 127.0.0.1 - WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo - NODE_ENV: test - -jobs: - test-windows: - runs-on: windows-2022 - - strategy: - matrix: - node-version: [16, 18, 20] - mongodb-version: ['5'] - - steps: - - uses: ankane/setup-mongodb@ce30d9041565cb469945895d5bde3384a254dd2e # use commit ID until action is versioned, see https://github.com/ankane/setup-mongodb/issues/2 - with: - mongodb-version: ${{ matrix.mongodb-version }} - - - name: Wait for MongoDB to start - run: | - while ($true) { - $status = Get-Service MongoDB | Select-Object -ExpandProperty Status - if ($status -eq "Running") { - Write-Host "MongoDB is running." - break - } - Write-Host "Waiting for MongoDB to start..." - Start-Sleep -Seconds 5 - } - shell: pwsh - - - name: Install Mongodb Shell - run: | - choco install mongodb-shell -y - shell: pwsh - - - name: Check connection to Mongodb using mongodb shell - run: | - mongosh --eval "db.adminCommand('listDatabases')" - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install dependencies - run: | - npm install --no-audit --no-fund - - name: Run test - run: | - npm run custom-tests From bb27cdde25b838802226dc8b9903902be88b5142 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:08:40 +0100 Subject: [PATCH 117/193] chore: revert changes --- .npmignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.npmignore b/.npmignore index 0819c5a6b..7f802e752 100644 --- a/.npmignore +++ b/.npmignore @@ -2,6 +2,8 @@ ./.gitignore ./.jshintrc ./.editorconfig +./.travis.yml +./appveyor.yml ./example ./examples ./test From bca521513331cf9e0ef23fda175d430a72537369 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:10:31 +0100 Subject: [PATCH 118/193] chore: revert changes --- test/run-standard-tests.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/run-standard-tests.js b/test/run-standard-tests.js index 6a350c8b7..689aed23e 100644 --- a/test/run-standard-tests.js +++ b/test/run-standard-tests.js @@ -4,10 +4,10 @@ * Module dependencies */ -const util = require('util'); -const TestRunner = require('waterline-adapter-tests'); -const packageMD = require('../package.json'); -const Adapter = require('../'); +var util = require('util'); +var TestRunner = require('waterline-adapter-tests'); +var packageMD = require('../package.json'); +var Adapter = require('../'); From 594afd63876043ef7d24d7406f525b68aee3f996 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:12:36 +0100 Subject: [PATCH 119/193] chore: revert changes --- test/run-adapter-specific-tests.js | 43 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 3db2a8d66..f542fbbb2 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -1,17 +1,14 @@ -const assert = require('assert'); -const _ = require('@sailshq/lodash'); -const Waterline = require('waterline'); -const waterlineUtils = require('waterline-utils'); -const normalizeDatastoreConfig = require('../lib/private/normalize-datastore-config'); - - -let waterline; -let models = {}; +var assert = require('assert'); +var _ = require('@sailshq/lodash'); +var Waterline = require('waterline'); +var waterlineUtils = require('waterline-utils'); +var normalizeDatastoreConfig = require('../lib/private/normalize-datastore-config'); +var waterlinevar models = {}; describe('normalizeDatastoreConfig', function() { it('Given a URL without a prefix, normalizeDatastoreConfig should add the prefix', function() { - const config = { + var config = { url: 'creepygiggles:shipyard4eva@localhost/test' }; normalizeDatastoreConfig(config, undefined, 'mongodb'); @@ -19,8 +16,8 @@ describe('normalizeDatastoreConfig', function() { }); it('Given a URL with a comma in it (like a Mongo Atlas URL), normalizeDatastoreConfig should not modify the URL.', function() { - const url = 'mongodb://creepygiggles:shipyard4eva@cluster0-shard-00-00-ienyq.mongodb.net:27017,cluster0-shard-00-01-ienyq.mongodb.net:27017,cluster0-shard-00-02-ienyq.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin'; - const config = { + var url = 'mongodb://creepygiggles:shipyard4eva@cluster0-shard-00-00-ienyq.mongodb.net:27017,cluster0-shard-00-01-ienyq.mongodb.net:27017,cluster0-shard-00-02-ienyq.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin'; + var config = { url: 'mongodb://creepygiggles:shipyard4eva@cluster0-shard-00-00-ienyq.mongodb.net:27017,cluster0-shard-00-01-ienyq.mongodb.net:27017,cluster0-shard-00-02-ienyq.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin' }; normalizeDatastoreConfig(config); @@ -336,7 +333,7 @@ describe('dontUseObjectIds', function() { describe('Where a collection using number keys belongsTo a model using ObjectID ', function() { - let userId; + var userId; before(function(done) { setup( @@ -396,7 +393,7 @@ describe('dontUseObjectIds', function() { describe('Where a collection using ObjectID belongsTo a model using number keys', function() { - let petId; + var petId; before(function(done) { setup( @@ -455,7 +452,7 @@ describe('dontUseObjectIds', function() { describe('Where a collection using number keys belongsTo a model using ObjectID (vialess)', function() { - let userId; + var userId; before(function(done) { setup( @@ -501,9 +498,9 @@ describe('dontUseObjectIds', function() { describe('Where a collection using ObjectID belongsTo a model using number keys (vialess)', function() { - let petId; + var petId; // eslint-disable-next-line no-unused-vars - let userId; + var userId; before(function(done) { setup( @@ -550,7 +547,7 @@ describe('dontUseObjectIds', function() { describe('Where a collection using ObjectID has many-to-many relationship with a model using number keys', function() { - let petId; + var petId; before(function(done) { setup( @@ -669,7 +666,7 @@ describe('dontUseObjectIds', function() { function setup(fixtures, modelsContainer, cb) { - const defaults = { + var defaults = { primaryKey: 'id', datastore: 'test', fetchRecordsOnUpdate: true, @@ -682,11 +679,11 @@ function setup(fixtures, modelsContainer, cb) { waterline = new Waterline(); _.each(fixtures, function(val, key) { - const modelFixture = _.extend({}, defaults, fixtures[key]); + var modelFixture = _.extend({}, defaults, fixtures[key]); waterline.registerModel(Waterline.Collection.extend(modelFixture)); }); - const datastores = { + var datastores = { test: { adapter: 'sails-mongo', url: process.env.WATERLINE_ADAPTER_TESTS_URL || 'localhost/sails_mongo' @@ -702,7 +699,7 @@ function setup(fixtures, modelsContainer, cb) { } // Save a reference to the ORM - const ORM = orm; + var ORM = orm; // Run migrations waterlineUtils.autoMigrations('drop', orm, function(err) { @@ -723,7 +720,7 @@ function setup(fixtures, modelsContainer, cb) { function createModel (identity, options) { options = options || {}; - const model = { + var model = { datastore: 'test', identity: identity, attributes: { From 272b2fe298867620c150d93a58a342364d31ae25 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:14:58 +0100 Subject: [PATCH 120/193] chore: revert changes --- .eslintrc | 2 +- test/run-adapter-specific-tests.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index ddf2ee84d..80fa6bfff 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,7 @@ }, "parserOptions": { - "ecmaVersion": 14 + "ecmaVersion": 5 // ^^This can be changed to `8` if this package doesn't need to support <= Node v6. }, diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index f542fbbb2..38fe2db7b 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -46,7 +46,7 @@ describe('aggregations', function() { return done(); }); - it('should not throw an error if the given criteria don\'t match any records', function(done) { + it('should not throw an error if the given critieria don\'t match any records', function(done) { models.user.sum('id', {name: 'joe'}).exec(function(err, sum) { if (err) { return done(err); } assert.equal(sum, 0); @@ -718,6 +718,7 @@ function setup(fixtures, modelsContainer, cb) { } function createModel (identity, options) { + options = options || {}; var model = { @@ -759,6 +760,7 @@ function createModel (identity, options) { collection: options.toManyVialess }; } + return model; } From a3476937bb790e7671a9c6682bf3dcf52e24c46f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:16:31 +0100 Subject: [PATCH 121/193] chore: revert changes --- test/run-adapter-specific-tests.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 38fe2db7b..4329a9034 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -1,3 +1,5 @@ + + var assert = require('assert'); var _ = require('@sailshq/lodash'); var Waterline = require('waterline'); From fb3e1d16ea7c2770cf74cfdc912cfb32553eafb7 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:17:50 +0100 Subject: [PATCH 122/193] chore: revert changes --- lib/private/machines/destroy-records.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/private/machines/destroy-records.js b/lib/private/machines/destroy-records.js index 8f4c563ca..c3307c5fa 100644 --- a/lib/private/machines/destroy-records.js +++ b/lib/private/machines/destroy-records.js @@ -28,28 +28,28 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - const _ = require('@sailshq/lodash'); - const processNativeRecord = require('./private/process-native-record'); - const buildMongoWhereClause = require('./private/build-mongo-where-clause'); + var _ = require('@sailshq/lodash'); + var processNativeRecord = require('./private/process-native-record'); + var buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - const s3q = inputs.query; + var s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (DESTROY RECORDS):',require('util').inspect(s3q,{depth:5}),'\n'); } // Local var for the `tableName`, for clarity. - const tableName = s3q.using; + var tableName = s3q.using; // Grab the model definition - const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• // Grab the pk column name (for use below) - let pkColumnName; + var pkColumnName; try { pkColumnName = WLModel.attributes[WLModel.primaryKey].columnName; } catch (e) { return exits.error(e); } @@ -58,7 +58,7 @@ module.exports = { // ╔╦╗╔═╗╔╦╗╔═╗╦═╗╔╦╗╦╔╗╔╔═╗ ┬ ┬┬ ┬┌─┐┌┬┐┬ ┬┌─┐┬─┐ ┌┬┐┌─┐ ╔═╗╔═╗╔╦╗╔═╗╦ ╦ ┌─┐┬─┐ ┌┐┌┌─┐┌┬┐ // ║║║╣ ║ ║╣ ╠╦╝║║║║║║║║╣ │││├─┤├┤ │ ├─┤├┤ ├┬┘ │ │ │ ╠╣ ║╣ ║ ║ ╠═╣ │ │├┬┘ ││││ │ │ // ═╩╝╚═╝ ╩ ╚═╝╩╚═╩ ╩╩╝╚╝╚═╝ └┴┘┴ ┴└─┘ ┴ ┴ ┴└─┘┴└─ ┴ └─┘ ╚ ╚═╝ ╩ ╚═╝╩ ╩ └─┘┴└─ ┘└┘└─┘ ┴ - let isFetchEnabled; + var isFetchEnabled; if (s3q.meta && s3q.meta.fetch) { isFetchEnabled = true; } else { isFetchEnabled = false; } @@ -67,7 +67,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - let mongoWhere; + var mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -76,8 +76,8 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - const db = inputs.connection; - const mongoCollection = db.collection(tableName); + var db = inputs.connection; + var mongoCollection = db.collection(tableName); // First, if fetch is set to true get all the records that match the given // criteria. This way they can be returned after the destroy. @@ -95,7 +95,7 @@ module.exports = { if (err) { return exits.error(err); } // Destroy the documents in the db. - let secondaryMongoWhere; + var secondaryMongoWhere; if (!isFetchEnabled) { secondaryMongoWhere = mongoWhere; } From 800656dc267f067fc793b0c81289c09632fdadd2 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:28:02 +0100 Subject: [PATCH 123/193] chore: revert changes --- .eslintrc | 2 +- test/run-adapter-specific-tests.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 80fa6bfff..ddf2ee84d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,7 @@ }, "parserOptions": { - "ecmaVersion": 5 + "ecmaVersion": 14 // ^^This can be changed to `8` if this package doesn't need to support <= Node v6. }, diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 4329a9034..d92e1f5b8 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -5,7 +5,8 @@ var _ = require('@sailshq/lodash'); var Waterline = require('waterline'); var waterlineUtils = require('waterline-utils'); var normalizeDatastoreConfig = require('../lib/private/normalize-datastore-config'); -var waterlinevar models = {}; +var waterline; +var models = {}; describe('normalizeDatastoreConfig', function() { From b9b70410c23cda737bde9e3b8a944ddaa7966d06 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Sat, 4 Nov 2023 10:31:08 +0100 Subject: [PATCH 124/193] chore: revert changes --- lib/private/machines/update-records.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/private/machines/update-records.js b/lib/private/machines/update-records.js index ca45c8d33..efb79d0ea 100644 --- a/lib/private/machines/update-records.js +++ b/lib/private/machines/update-records.js @@ -30,31 +30,31 @@ module.exports = { fn: function (inputs, exits) { // Dependencies - const _ = require('@sailshq/lodash'); - const processNativeRecord = require('./private/process-native-record'); - const processNativeError = require('./private/process-native-error'); - const reifyValuesToSet = require('./private/reify-values-to-set'); - const buildMongoWhereClause = require('./private/build-mongo-where-clause'); + var _ = require('@sailshq/lodash'); + var processNativeRecord = require('./private/process-native-record'); + var processNativeError = require('./private/process-native-error'); + var reifyValuesToSet = require('./private/reify-values-to-set'); + var buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - const s3q = inputs.query; + var s3q = inputs.query; if (s3q.meta && s3q.meta.logMongoS3Qs) { console.log('* * * * * *\nADAPTER (UPDATE RECORDS):',require('util').inspect(s3q,{depth:5}),'\n'); // console.log(typeof s3q.criteria.where._id.in[0]); } // Local var for the `tableName`, for clarity. - const tableName = s3q.using; + var tableName = s3q.using; // Grab the model definition - const WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• // Grab the pk column name (for use below) - let pkColumnName; + var pkColumnName; try { pkColumnName = WLModel.attributes[WLModel.primaryKey].columnName; } catch (e) { return exits.error(e); } @@ -63,7 +63,7 @@ module.exports = { // ╔╦╗╔═╗╔╦╗╔═╗╦═╗╔╦╗╦╔╗╔╔═╗ ┬ ┬┬ ┬┌─┐┌┬┐┬ ┬┌─┐┬─┐ ┌┬┐┌─┐ ╔═╗╔═╗╔╦╗╔═╗╦ ╦ ┌─┐┬─┐ ┌┐┌┌─┐┌┬┐ // ║║║╣ ║ ║╣ ╠╦╝║║║║║║║║╣ │││├─┤├┤ │ ├─┤├┤ ├┬┘ │ │ │ ╠╣ ║╣ ║ ║ ╠═╣ │ │├┬┘ ││││ │ │ // ═╩╝╚═╝ ╩ ╚═╝╩╚═╩ ╩╩╝╚╝╚═╝ └┴┘┴ ┴└─┘ ┴ ┴ ┴└─┘┴└─ ┴ └─┘ ╚ ╚═╝ ╩ ╚═╝╩ ╩ └─┘┴└─ ┘└┘└─┘ ┴ - let isFetchEnabled; + var isFetchEnabled; if (s3q.meta && s3q.meta.fetch) { isFetchEnabled = true; } else { isFetchEnabled = false; } @@ -79,7 +79,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - let mongoWhere; + var mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } From 838a0d658f38bcdc21e5d4b6269b749005d199a6 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 7 Nov 2023 20:41:33 +0100 Subject: [PATCH 125/193] chore: revert changes --- lib/private/machines/sum-records.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index 0199e2102..3d72c7506 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -28,24 +28,24 @@ module.exports = { fn: function sum(inputs, exits) { // Dependencies - const _ = require('@sailshq/lodash'); - const buildMongoWhereClause = require('./private/build-mongo-where-clause'); + var _ = require('@sailshq/lodash'); + var buildMongoWhereClause = require('./private/build-mongo-where-clause'); // Local var for the stage 3 query, for easier access. - const s3q = inputs.query; + var s3q = inputs.query; // Local var for the `tableName`, for clarity. - const tableName = s3q.using; + var tableName = s3q.using; // Local var for the name of the numeric field, for clarity. // // > Remember: Contrary to what you might think given its naming, // > by the time it gets to the adapter (in an s3q), the `numericAttrName` // > qk has already been normalized to be a column name, not an attribute name. - let numericFieldName = s3q.numericAttrName; + var numericFieldName = s3q.numericAttrName; // Grab the model definition - let WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); + var WLModel = _.find(inputs.dryOrm.models, {tableName: tableName}); if (!WLModel) { return exits.error(new Error('No model with that tableName (`'+tableName+'`) has been registered with this adapter. Were any unexpected modifications made to the stage 3 query? Could the adapter\'s internal state have been corrupted? (This error is usually due to a bug in this adapter\'s implementation.)')); }//-• @@ -54,7 +54,7 @@ module.exports = { // ││││ │││││ ┬│ ││├┤ └┬┘ ║ ╠╦╝║ ║ ║╣ ╠╦╝║╠═╣ // ┴ ┴└─┘┘└┘└─┘└─┘┴└ ┴ ╚═╝╩╚═╩ ╩ ╚═╝╩╚═╩╩ ╩ // Build a Mongo-style WHERE from the `where` clause. - let mongoWhere; + var mongoWhere; try { mongoWhere = buildMongoWhereClause(s3q.criteria.where, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -62,9 +62,9 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - const db = inputs.connection; - const mongoCollection = db.collection(tableName); - const cursor = mongoCollection.aggregate([ + var db = inputs.connection; + var mongoCollection = db.collection(tableName); + var cursor = mongoCollection.aggregate([ { $match: mongoWhere }, { $group: { @@ -77,7 +77,7 @@ module.exports = { ], { cursor: {} }); cursor.toArray().then(function aggregateCb(nativeResult) { - let sum = 0; + var sum = 0; if (_.first(nativeResult)) { sum = _.first(nativeResult).sum; } return exits.success(sum); }).catch(function(err) { From c8148545b2bc549790479596470d84c618c59000 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Tue, 7 Nov 2023 20:44:05 +0100 Subject: [PATCH 126/193] chore: revert changes --- lib/private/machines/create-record.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index fc08cce80..0ee254679 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -69,6 +69,10 @@ module.exports = { // ║║║║╚═╗║╣ ╠╦╝ ║ ├┬┘├┤ │ │ │├┬┘ ││ // ╩╝╚╝╚═╝╚═╝╩╚═ ╩ ┴└─└─┘└─┘└─┘┴└──┴┘ // Create this new record in the database by inserting a document in the appropriate Mongo collection. + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // FUTURE: Carry through the `fetch: false` optimization all the way to Mongo here, + // if possible (e.g. using Mongo's projections API) + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var db = inputs.connection; var mongoCollection = db.collection(tableName); mongoCollection.insertOne(s3q.newRecord).then(async function documentInserted(nativeResult) { From 624e7847b57f4e92568c6b0d9758870fcbc36ac1 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 08:46:16 +0100 Subject: [PATCH 127/193] chore: revert changes --- lib/private/machines/update-records.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/private/machines/update-records.js b/lib/private/machines/update-records.js index efb79d0ea..f87543652 100644 --- a/lib/private/machines/update-records.js +++ b/lib/private/machines/update-records.js @@ -88,8 +88,8 @@ module.exports = { // ╔═╗╔═╗╔╦╗╔╦╗╦ ╦╔╗╔╦╔═╗╔═╗╔╦╗╔═╗ ┬ ┬┬┌┬┐┬ ┬ ┌┬┐┌┐ // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ - let db = inputs.connection; - let mongoCollection = db.collection(tableName); + var db = inputs.connection; + var mongoCollection = db.collection(tableName); // First, get the IDs of records which match this criteria (if needed). (function findMatchingIdsMaybe(proceed) { @@ -97,7 +97,7 @@ module.exports = { return proceed(); } - let projection = {}; + var projection = {}; projection[pkColumnName] = 1; // console.log('* * * *'); // console.log('mongoWhere:',mongoWhere); @@ -111,7 +111,7 @@ module.exports = { if (err) { return exits.error(err); } // Update the documents in the db. - let secondaryMongoWhere; + var secondaryMongoWhere; if (!isFetchEnabled) { secondaryMongoWhere = mongoWhere; } @@ -139,9 +139,9 @@ module.exports = { // There should only ever be either zero or one record that were found before. if (pkValsOfMatchingRecords.length === 0) { /* do nothing */ } else if (pkValsOfMatchingRecords.length === 1) { - const oldPkValue = pkValsOfMatchingRecords[0]; + var oldPkValue = pkValsOfMatchingRecords[0]; _.remove(secondaryMongoWhere[pkColumnName]['$in'], oldPkValue); - const newPkValue = s3q.valuesToSet[pkColumnName]; + var newPkValue = s3q.valuesToSet[pkColumnName]; secondaryMongoWhere[pkColumnName]['$in'].push(newPkValue); } else { return exits.error(new Error('Consistency violation: Updated multiple records to have the same primary key value. (PK values should be unique!)')); } From 570881ac5e2cbf3e5726783a269d6bf333397472 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 08:57:50 +0100 Subject: [PATCH 128/193] chore: revert changes --- .eslintrc | 2 +- package.json | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.eslintrc b/.eslintrc index ddf2ee84d..80fa6bfff 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,7 @@ }, "parserOptions": { - "ecmaVersion": 14 + "ecmaVersion": 5 // ^^This can be changed to `8` if this package doesn't need to support <= Node v6. }, diff --git a/package.json b/package.json index 9edec5fe0..f239af8b6 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,13 @@ "main": "./lib", "scripts": { "test": "npm run lint && npm run custom-tests", - "custom-tests": "node node_modules/mocha/bin/mocha", + "custom-tests": "node node_modules/mocha/bin/mocha test/run-adapter-specific-tests && node node_modules/mocha/bin/mocha test/connectable/ && node test/run-standard-tests", "lint": "node node_modules/eslint/bin/eslint . --max-warnings=0", - "start-mongodb": "docker compose up -d mongo", - "stop-mongodb": "docker compose down", - "docker": "docker compose run adapter bash", - "mongodb-shell": "docker compose exec mongo mongo", - "docker-test": "docker compose run adapter bash -c \"npm test\" && docker compose down" + "start-mongodb": "docker-compose up -d mongo", + "stop-mongodb": "docker-compose down", + "docker": "docker-compose run adapter bash", + "mongodb-shell": "docker-compose exec mongo mongo", + "docker-test": "docker-compose run adapter bash -c \"npm test\" && docker-compose down" }, "keywords": [ "mongo", @@ -38,11 +38,10 @@ "qs": "6.9.7" }, "devDependencies": { - "@types/mocha": "^10.0.2", "benchmark": "2.1.4", - "eslint": "^8.50.0", - "mocha": "^10.2.0", - "waterline": "^0.15.2", + "eslint": "4.19.1", + "mocha": "3.0.2", + "waterline": "^0.13.6", "waterline-adapter-tests": "^1.0.1", "waterline-utils": "^1.4.2" }, @@ -66,6 +65,7 @@ "migratable" ], "machineDir": "lib/private/machines/", - "exportStyle": "dryDictionary" + "exportStyle": "dryDictionary", + "testsUrl": "https://travis-ci.org/balderdashy/sails-mongo" } } From 3b6dc39844795d47dd2d3c8583e8d24d08c6ec57 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 08:58:33 +0100 Subject: [PATCH 129/193] chore: revert changes --- .mocharc.json | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .mocharc.json diff --git a/.mocharc.json b/.mocharc.json deleted file mode 100644 index 33d06aeaa..000000000 --- a/.mocharc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "bail": true, - "timeout": "5000" -} From 1829c0753e62856e8f19b67fb54adae671c45ca9 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 09:05:34 +0100 Subject: [PATCH 130/193] feat: use IIFE for implementing drop --- lib/index.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/index.js b/lib/index.js index 09627fbc8..5d4301028 100644 --- a/lib/index.js +++ b/lib/index.js @@ -860,14 +860,8 @@ module.exports = { // Drop the physical model (e.g. table/etc.) var db = dsEntry.manager; - db.collection(tableName).drop().then(function () { - // >-• - // IWMIH, then either the physical model was successfully dropped, - // or it didn't exist in the first place. - return done(); - }).catch(function (err) { + (function(iifeDone) { db.collection(tableName).drop().then(function() {iifeDone();}).catch(function(err) {iifeDone(err);});})(function (err) { try { - if (err) { if (err.errmsg === 'ns not found') { throw flaverr('E_PHM_NOT_FOUND', new Error('No such physical model is currently defined.')); @@ -875,7 +869,6 @@ module.exports = { else if (_.isError(err)) { throw err; } else { throw new Error('Consistency violation: Expecting Error instance, but instead got: '+util.inspect(err)); } }//>- - } catch (e) { switch (e.code) { case 'E_PHM_NOT_FOUND': break; @@ -883,10 +876,13 @@ module.exports = { e.raw = err; return done(e); } - return done(); }// - });// + // >-• + // IWMIH, then either the physical model was successfully dropped, + // or it didn't exist in the first place. + return done(); + });// }, From 12ad6e0dbf0d80b316a00a69dd347b3b1b4f64a3 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 09:06:34 +0100 Subject: [PATCH 131/193] chore: revert changes --- lib/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/index.js b/lib/index.js index 5d4301028..4a96d1e7d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -862,6 +862,7 @@ module.exports = { var db = dsEntry.manager; (function(iifeDone) { db.collection(tableName).drop().then(function() {iifeDone();}).catch(function(err) {iifeDone(err);});})(function (err) { try { + if (err) { if (err.errmsg === 'ns not found') { throw flaverr('E_PHM_NOT_FOUND', new Error('No such physical model is currently defined.')); @@ -869,6 +870,7 @@ module.exports = { else if (_.isError(err)) { throw err; } else { throw new Error('Consistency violation: Expecting Error instance, but instead got: '+util.inspect(err)); } }//>- + } catch (e) { switch (e.code) { case 'E_PHM_NOT_FOUND': break; @@ -883,6 +885,7 @@ module.exports = { // or it didn't exist in the first place. return done(); });// + }, From 9291e9aa120f038c26c9b724a2315e0a9e824acd Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 09:17:42 +0100 Subject: [PATCH 132/193] feat: use IIFE for createIndex --- lib/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/index.js b/lib/index.js index 4a96d1e7d..c0ff5e9b7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -810,16 +810,14 @@ module.exports = { // Create the index on the Mongo collection. // (https://docs.mongodb.com/manual/reference/method/db.collection.createIndex) - mongoCollection.createIndex(mongoSingleFieldIdxKeys, { unique: true }).then(function () { - return next(); - }).catch(function(err) { + (function(iifeDone) { mongoCollection.createIndex(mongoSingleFieldIdxKeys, { unique: true }).then(function() { iifeDone(); }).catch(function(err) {iifeDone(err);});})(function (err) { if (err && !_.isError(err)) { err = flaverr({raw: err}, new Error('Consistency violation: Expecting Error instance, but instead got: '+util.inspect(err))); return next(err); } else if (err) { return next(err); } + return next(); });// - }, function (err) { if (err) { return done(err); } return done(); From 13cfa65aa65792465356af7136469563fe5f8bbc Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 09:19:10 +0100 Subject: [PATCH 133/193] chore: revert changes --- lib/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index c0ff5e9b7..5a45a280f 100644 --- a/lib/index.js +++ b/lib/index.js @@ -816,8 +816,9 @@ module.exports = { return next(err); } else if (err) { return next(err); } - return next(); + else { return next(); } });// + }, function (err) { if (err) { return done(err); } return done(); From d1e3e15f884d1b2a8c236d01ad95de08511ad7a0 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 09:22:42 +0100 Subject: [PATCH 134/193] feat: use IIFE for avg-records --- lib/private/machines/avg-records.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/private/machines/avg-records.js b/lib/private/machines/avg-records.js index 7b8e4097b..fad5f04f4 100644 --- a/lib/private/machines/avg-records.js +++ b/lib/private/machines/avg-records.js @@ -76,12 +76,11 @@ module.exports = { } ], { cursor: {} }); - cursor.toArray().then(function aggregateCb(nativeResult) { + (function(iifeDone) { cursor.toArray().then(function(nativeResult) { iifeDone(null, nativeResult); }).catch(function (err){iifeDone(err, null);}); })(function(err, nativeResult) { + if (err) { return exits.error(err); } var mean = 0; if (_.first(nativeResult)) { mean = _.first(nativeResult).avg; } return exits.success(mean); - }).catch(function(err) { - if (err) { return exits.error(err); } });// } From 817a9e33fabe3fdc6ab1e3f36bb8ace85a83249a Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 09:23:16 +0100 Subject: [PATCH 135/193] feat: use IIFE for avg-records --- lib/private/machines/avg-records.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/private/machines/avg-records.js b/lib/private/machines/avg-records.js index fad5f04f4..935bb3fdb 100644 --- a/lib/private/machines/avg-records.js +++ b/lib/private/machines/avg-records.js @@ -83,5 +83,4 @@ module.exports = { return exits.success(mean); });// } - }; From b109abc146a908ab7b76d1cedac303cfa52cf667 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 09:24:02 +0100 Subject: [PATCH 136/193] chore: revert changes --- lib/private/machines/avg-records.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/private/machines/avg-records.js b/lib/private/machines/avg-records.js index 935bb3fdb..9fbc2af2c 100644 --- a/lib/private/machines/avg-records.js +++ b/lib/private/machines/avg-records.js @@ -78,9 +78,11 @@ module.exports = { (function(iifeDone) { cursor.toArray().then(function(nativeResult) { iifeDone(null, nativeResult); }).catch(function (err){iifeDone(err, null);}); })(function(err, nativeResult) { if (err) { return exits.error(err); } + var mean = 0; if (_.first(nativeResult)) { mean = _.first(nativeResult).avg; } return exits.success(mean); });// } + }; From 529d82fda91831b1126ef81c619427a27e564739 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 09:25:03 +0100 Subject: [PATCH 137/193] chore: revert changes --- lib/private/machines/avg-records.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/avg-records.js b/lib/private/machines/avg-records.js index 9fbc2af2c..344ee967b 100644 --- a/lib/private/machines/avg-records.js +++ b/lib/private/machines/avg-records.js @@ -76,7 +76,7 @@ module.exports = { } ], { cursor: {} }); - (function(iifeDone) { cursor.toArray().then(function(nativeResult) { iifeDone(null, nativeResult); }).catch(function (err){iifeDone(err, null);}); })(function(err, nativeResult) { + (function(iifeDone) { cursor.toArray().then(function(nativeResult) { iifeDone(null, nativeResult); }).catch(function (err){iifeDone(err, null);}); })(function aggregateCb(err, nativeResult) { if (err) { return exits.error(err); } var mean = 0; From 772a717e84792c491aa284ac63e8540057c62a16 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 09:29:58 +0100 Subject: [PATCH 138/193] feat: use IIFE for count-records --- lib/private/machines/count-records.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/private/machines/count-records.js b/lib/private/machines/count-records.js index 58974cb3b..74cd1027f 100644 --- a/lib/private/machines/count-records.js +++ b/lib/private/machines/count-records.js @@ -61,9 +61,11 @@ module.exports = { // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ var db = inputs.connection; var mongoCollection = db.collection(tableName); - mongoCollection.countDocuments(mongoWhere).then(function count(nativeResult) { + (function(iifeDone) { mongoCollection.countDocuments(mongoWhere).then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function countCb(err, nativeResult) { + if (err) { return exits.error(err); } + return exits.success(nativeResult); - }).catch(function (err) { return exits.error(err); }); + }); } From 11aacde94371c4293e86dcc27b954a6eafbd47a4 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 10:01:16 +0100 Subject: [PATCH 139/193] feat: use IIFE for create-record --- lib/private/machines/create-record.js | 35 +++++++++++++++------------ 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 0ee254679..d16fc303c 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -75,7 +75,15 @@ module.exports = { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var db = inputs.connection; var mongoCollection = db.collection(tableName); - mongoCollection.insertOne(s3q.newRecord).then(async function documentInserted(nativeResult) { + (function(iifeDone){ mongoCollection.insertOne(s3q.newRecord).then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err){ iifeDone(err, null);});})(function(err, nativeResult) { + if (err) { + err = processNativeError(err); + if (err.footprint && err.footprint.identity === 'notUnique') { + return exits.notUnique(err); + } + return exits.error(err); + }//-• + // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -89,15 +97,18 @@ module.exports = { return exits.success(); }//-• - - // Otherwise, IWMIH we'll be sending back a record: - // ============================================ - - // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐ - // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ ││ - // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘ // Process record (mutate in-place) to wash away adapter-specific eccentricities. - var phRecord = await mongoCollection.findOne({ _id: nativeResult.insertedId }); + var phRecord; + (function() { + mongoCollection.findOne({ _id: nativeResult.insertedId }) + .then(function(result) { + phRecord = result; + }) + .catch(function(err) { + return exits.error(err); + }); + })(); + try { processNativeRecord(phRecord, WLModel, s3q.meta); } catch (e) { return exits.error(e); } @@ -105,12 +116,6 @@ module.exports = { // Then send it back. return exits.success(phRecord); - }).catch(function(err) { - err = processNativeError(err); - if (err.footprint && err.footprint.identity === 'notUnique') { - return exits.notUnique(err); - } - return exits.error(err); }); // } }; From 2cd402e76929b963fac4b1c3668ad02901d9f91f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 10:02:21 +0100 Subject: [PATCH 140/193] chore: revert changes --- lib/private/machines/create-record.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index d16fc303c..070de0639 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -84,6 +84,7 @@ module.exports = { return exits.error(err); }//-• + // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From fc73eaa08ee727a15e6e9c8e6c3bce95da821aac Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 10:03:43 +0100 Subject: [PATCH 141/193] chore: revert changes --- lib/private/machines/create-record.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 070de0639..faf23cc46 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -98,6 +98,12 @@ module.exports = { return exits.success(); }//-• + // Otherwise, IWMIH we'll be sending back a record: + // ============================================ + + // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐ + // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ ││ + // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘ // Process record (mutate in-place) to wash away adapter-specific eccentricities. var phRecord; (function() { From da8e6fb5f83f4dcaf5e013ab3ad43d2ff3ad8428 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 10:04:07 +0100 Subject: [PATCH 142/193] chore: revert changes --- lib/private/machines/create-record.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index faf23cc46..f15950c68 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -98,6 +98,7 @@ module.exports = { return exits.success(); }//-• + // Otherwise, IWMIH we'll be sending back a record: // ============================================ From 5ecf56a6d7652dabea07e0e6a575fe77db900433 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 10:05:36 +0100 Subject: [PATCH 143/193] fix: make getting record created a one-liner --- lib/private/machines/create-record.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index f15950c68..a48c49d65 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -107,15 +107,7 @@ module.exports = { // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘ // Process record (mutate in-place) to wash away adapter-specific eccentricities. var phRecord; - (function() { - mongoCollection.findOne({ _id: nativeResult.insertedId }) - .then(function(result) { - phRecord = result; - }) - .catch(function(err) { - return exits.error(err); - }); - })(); + (function() { mongoCollection.findOne({ _id: nativeResult.insertedId }).then(function(result) { phRecord = result; }).catch(function(err) {return exits.error(err);});})(); try { processNativeRecord(phRecord, WLModel, s3q.meta); From 8cd70348612052ed3e780e1e83c1cc9b0830b77e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 10:35:19 +0100 Subject: [PATCH 144/193] fix: resolve not returning record(s) --- lib/private/machines/create-each-record.js | 39 ++++++++++++---------- lib/private/machines/create-record.js | 18 +++++----- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/lib/private/machines/create-each-record.js b/lib/private/machines/create-each-record.js index 30e045ff9..d6379dd44 100644 --- a/lib/private/machines/create-each-record.js +++ b/lib/private/machines/create-each-record.js @@ -82,12 +82,19 @@ module.exports = { // if (s3q.meta && s3q.meta.logMongoS3Qs) { // console.log('- - - - - - - - - -CREATE EACH: s3q.newRecords:',require('util').inspect(s3q.newRecords,{depth:5}),'\n'); // } - mongoCollection.insertMany(s3q.newRecords).then(async function (nativeResult) { + (function(iifeDone){ mongoCollection.insertMany(s3q.newRecords).then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function(err, nativeResult) { + if (err) { + err = processNativeError(err); + if (err.footprint && err.footprint.identity === 'notUnique') { + return exits.notUnique(err); + } + return exits.error(err); + }//-• + // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { return exits.success(); }//-• - var insertedIds = Object.values(nativeResult.insertedIds); // Otherwise, IWMIH we'll be sending back records: @@ -97,21 +104,19 @@ module.exports = { // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ │││ └─┐ │ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘└─└─┘─┘ // Process record(s) (mutate in-place) to wash away adapter-specific eccentricities. - var phRecords = await mongoCollection.find({ _id: { $in: insertedIds } }).toArray(); - try { - _.each(phRecords, function (phRecord){ - processNativeRecord(phRecord, WLModel, s3q.meta); - }); - } catch (e) { return exits.error(e); } - - return exits.success(phRecords); - - }).catch(function(err) { - err = processNativeError(err); - if (err.footprint && err.footprint.identity === 'notUnique') { - return exits.notUnique(err); - } - return exits.error(err); + + (function(iifeDone){ mongoCollection.find({ _id: { $in: insertedIds } }).toArray().then(function(phRecords) { iifeDone(null, phRecords); }).catch(function(err) { iifeDone(err, null);});})(function(err, phRecords) { + if (err) { + return exits.error(err); + } + try { + _.each(phRecords, function (phRecord){ + processNativeRecord(phRecord, WLModel, s3q.meta); + }); + } catch (e) { return exits.error(e); } + + return exits.success(phRecords); + }); }); // } diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index a48c49d65..408bd4614 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -106,15 +106,17 @@ module.exports = { // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ ││ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘ // Process record (mutate in-place) to wash away adapter-specific eccentricities. - var phRecord; - (function() { mongoCollection.findOne({ _id: nativeResult.insertedId }).then(function(result) { phRecord = result; }).catch(function(err) {return exits.error(err);});})(); - - try { - processNativeRecord(phRecord, WLModel, s3q.meta); - } catch (e) { return exits.error(e); } + (function(iifeDone) { mongoCollection.findOne({ _id: nativeResult.insertedId }).then(function(phRecord) { iifeDone(null, phRecord);}).catch(function(err) { iifeDone(err, null);});})(function(err, phRecord) { + if (err) { + return exits.error(err); + } + try { + processNativeRecord(phRecord, WLModel, s3q.meta); + } catch (e) { return exits.error(e); } - // Then send it back. - return exits.success(phRecord); + // Then send it back. + return exits.success(phRecord); + }); }); // } From 36a4e309190b2ac1a046bdf573860d07410ca368 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 10:38:27 +0100 Subject: [PATCH 145/193] chore: revert changes --- lib/private/machines/create-each-record.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/private/machines/create-each-record.js b/lib/private/machines/create-each-record.js index d6379dd44..b013870b9 100644 --- a/lib/private/machines/create-each-record.js +++ b/lib/private/machines/create-each-record.js @@ -91,10 +91,12 @@ module.exports = { return exits.error(err); }//-• + // If `fetch` is NOT enabled, we're done. if (!isFetchEnabled) { return exits.success(); }//-• + var insertedIds = Object.values(nativeResult.insertedIds); // Otherwise, IWMIH we'll be sending back records: From 507afd3bf8a185d95ca99fa03a19f6204135d3f2 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 10:54:15 +0100 Subject: [PATCH 146/193] feat: use IIFE for create-manager --- lib/private/machines/create-manager.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index 8f3d86187..2e97489ba 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -126,10 +126,12 @@ module.exports = { _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); // https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect/ - NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig) - .then(function (client) { - var manager = client.db(_clientConfig.database); + (function(iifeDone){ NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig).then(function(client){ iifeDone(null, client);}).catch(function(err) { iifeDone(err, null);});})(function(err, client){ + if (err) { + return exits.error(err); + } + var manager = client.db(_clientConfig.database); manager.client = client; // Now mutate this manager, giving it a telltale. @@ -140,14 +142,13 @@ module.exports = { // > (^^But that's not the real reason to include it -- we ended up solving it differently // > anyway. No, the real reason is so that there's a way to tell if a given Mongo client // > instance came from mp-mongo or not, for debugging reasons.) - manager._isFromMPMongo = true; return exits.success({ manager: manager, meta: inputs.meta }); - }).catch(function(err) { return exits.error(err); });// + });// } From b2795b5d13fd240361c588073d2aae889d7fbdc2 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 10:58:22 +0100 Subject: [PATCH 147/193] feat: upgrade mongodb driver to 6.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f239af8b6..13df7b50a 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "async": "3.2.4", "flaverr": "^1.10.0", "machine": "^15.2.2", - "mongodb": "6.1.0", + "mongodb": "6.3.0", "qs": "6.9.7" }, "devDependencies": { From f3624165ae33dd01ee83de6d6c1dde0fc2837eb1 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:00:00 +0100 Subject: [PATCH 148/193] chore: update connect comment --- lib/private/machines/create-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index 2e97489ba..dc1e840e1 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -125,7 +125,7 @@ module.exports = { var mongoUrl = _clientConfig.url; _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); - // https://www.mongodb.com/docs/drivers/node/current/fundamentals/connection/connect/ + // http://mongodb.github.io/node-mongodb-native/6.3/classes/MongoClient.html#connect (function(iifeDone){ NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig).then(function(client){ iifeDone(null, client);}).catch(function(err) { iifeDone(err, null);});})(function(err, client){ if (err) { return exits.error(err); From 162a5b4114107c83d379b32cae71673e9197ee1c Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:00:50 +0100 Subject: [PATCH 149/193] chore: update comment link to use https --- lib/private/machines/create-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index dc1e840e1..236996f4c 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -125,7 +125,7 @@ module.exports = { var mongoUrl = _clientConfig.url; _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); - // http://mongodb.github.io/node-mongodb-native/6.3/classes/MongoClient.html#connect + // https://mongodb.github.io/node-mongodb-native/6.3/classes/MongoClient.html#connect (function(iifeDone){ NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig).then(function(client){ iifeDone(null, client);}).catch(function(err) { iifeDone(err, null);});})(function(err, client){ if (err) { return exits.error(err); From 5d5ea5c429eb084e4049682e5596341e070eedc2 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:09:08 +0100 Subject: [PATCH 150/193] feat: use IIFE for destroy-records --- lib/private/machines/destroy-records.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/private/machines/destroy-records.js b/lib/private/machines/destroy-records.js index c3307c5fa..9cd53f9b7 100644 --- a/lib/private/machines/destroy-records.js +++ b/lib/private/machines/destroy-records.js @@ -87,9 +87,10 @@ module.exports = { } // Find matching records. - mongoCollection.find(mongoWhere).toArray().then(function findCb(nativeResult) { + (function(iifeDone) {mongoCollection.find(mongoWhere).toArray().then(function findCb(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function findCb(err, nativeResult) { + if (err) { return proceed(err); } return proceed(undefined, nativeResult); - }).catch(function (err) { return proceed(err); }); + }); })(function findMatchingRecordsCb(err, phRecords) { if (err) { return exits.error(err); } @@ -103,7 +104,9 @@ module.exports = { secondaryMongoWhere = {}; secondaryMongoWhere[pkColumnName] = { '$in': _.pluck(phRecords, pkColumnName) }; } - mongoCollection.deleteMany(secondaryMongoWhere).then(function deleteCb() { + (function(iifeDone) { mongoCollection.deleteMany(secondaryMongoWhere).then(function() { iifeDone();}).catch(function(err) { iifeDone(err);});})(function deleteCb(err) { + if (err) { return exits.error(err); } + if (!isFetchEnabled) { return exits.success(); }//-• @@ -119,8 +122,7 @@ module.exports = { } catch (e) { return exits.error(e); } return exits.success(phRecords); - - }).catch(function (err) { return exits.error(err); }); // + }); // });// } From 76da6f86c4b68272574841efed727841b00a2341 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:09:53 +0100 Subject: [PATCH 151/193] chore: revert changes --- lib/private/machines/destroy-records.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/private/machines/destroy-records.js b/lib/private/machines/destroy-records.js index 9cd53f9b7..04f5ce2f1 100644 --- a/lib/private/machines/destroy-records.js +++ b/lib/private/machines/destroy-records.js @@ -122,7 +122,8 @@ module.exports = { } catch (e) { return exits.error(e); } return exits.success(phRecords); - }); // + + }); // });// } From f6bc8f47181e34c0303be88784028c2457f3e927 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:14:34 +0100 Subject: [PATCH 152/193] feat: use IIFE for find-records --- lib/private/machines/find-records.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/private/machines/find-records.js b/lib/private/machines/find-records.js index 97065e645..16894536f 100644 --- a/lib/private/machines/find-records.js +++ b/lib/private/machines/find-records.js @@ -117,7 +117,9 @@ module.exports = { // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ // Find the documents in the db. - mongoDeferred.toArray().then(function findCb(nativeResult) { + (function(iifeDone) { mongoDeferred.toArray().then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function findCb(err, nativeResult) { + if (err) { return exits.error(err); } + // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐┌─┌─┐─┐ // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ │││ └─┐ │ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘└─└─┘─┘ @@ -135,7 +137,7 @@ module.exports = { // } return exits.success(phRecords); - }).catch(function (err) { return exits.error(err); }); // + }); // } }; From 229c36315f1adacf7fa63ad0396acde884cfc692 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:17:57 +0100 Subject: [PATCH 153/193] feat: use IIFE for sum-records --- lib/private/machines/sum-records.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index 3d72c7506..fa731232f 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -76,12 +76,12 @@ module.exports = { } ], { cursor: {} }); - cursor.toArray().then(function aggregateCb(nativeResult) { + (function(iifeDone) { cursor.toArray().then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function(err, nativeResult) { + if (err) { return exits.error(err); } + var sum = 0; if (_.first(nativeResult)) { sum = _.first(nativeResult).sum; } return exits.success(sum); - }).catch(function(err) { - if (err) { return exits.error(err); } - });// + }); // } }; From fb34f80bdbbdb118faeccd7129f52bf4635199f9 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:18:28 +0100 Subject: [PATCH 154/193] chore: revert changes --- lib/private/machines/sum-records.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index fa731232f..e6bd54a5e 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -82,6 +82,6 @@ module.exports = { var sum = 0; if (_.first(nativeResult)) { sum = _.first(nativeResult).sum; } return exits.success(sum); - }); // + });// } }; From 715f0d4473575f1e6114d5e6477b705a793a380a Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:18:46 +0100 Subject: [PATCH 155/193] chore: revert changes --- lib/private/machines/sum-records.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index e6bd54a5e..713566d91 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -76,7 +76,7 @@ module.exports = { } ], { cursor: {} }); - (function(iifeDone) { cursor.toArray().then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function(err, nativeResult) { + (function(iifeDone) { cursor.toArray().then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function aggregateCb(err, nativeResult) { if (err) { return exits.error(err); } var sum = 0; From 0e5c0b07153f3f5ddcb546c9f3b10673203eebe2 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:19:16 +0100 Subject: [PATCH 156/193] chore: revert changes --- lib/private/machines/sum-records.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index 713566d91..1c376dcda 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -83,5 +83,6 @@ module.exports = { if (_.first(nativeResult)) { sum = _.first(nativeResult).sum; } return exits.success(sum); });// + } }; From 3de69b4571d676b8dfc76da6db2ec234598ce233 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:19:33 +0100 Subject: [PATCH 157/193] chore: revert changes --- lib/private/machines/sum-records.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/sum-records.js b/lib/private/machines/sum-records.js index 1c376dcda..742c63ce8 100644 --- a/lib/private/machines/sum-records.js +++ b/lib/private/machines/sum-records.js @@ -83,6 +83,6 @@ module.exports = { if (_.first(nativeResult)) { sum = _.first(nativeResult).sum; } return exits.success(sum); });// - } + }; From bf4d9761e55b4a7f10527169fba44b3aa3916f01 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:20:43 +0100 Subject: [PATCH 158/193] chore: revert changes --- test/mocha.opts | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test/mocha.opts diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 000000000..111eceeca --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,2 @@ +--timeout 5000 +--bail From 80296ace1b99168b92f7598cf466a92a55d4c5be Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:31:05 +0100 Subject: [PATCH 159/193] feat: use IFFE for update-records --- lib/private/machines/update-records.js | 29 +++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/private/machines/update-records.js b/lib/private/machines/update-records.js index f87543652..c7cd80a64 100644 --- a/lib/private/machines/update-records.js +++ b/lib/private/machines/update-records.js @@ -103,9 +103,10 @@ module.exports = { // console.log('mongoWhere:',mongoWhere); // console.log('typeof mongoWhere._id.$in[0]:',typeof mongoWhere._id.$in[0]); // console.log('projection:',projection); - mongoCollection.find(mongoWhere, projection).toArray().then(function findCb(nativeResult) { + (function(iifeDone) { mongoCollection.find(mongoWhere, projection).toArray().then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function findCb(err, nativeResult) { + if (err) { return proceed(err); } return proceed(undefined, _.pluck(nativeResult, pkColumnName)); - }).catch(function (err) { return proceed(err); }); + }); })(function findMatchingIdsMaybeCb(err, pkValsOfMatchingRecords) { if (err) { return exits.error(err); } @@ -125,13 +126,20 @@ module.exports = { // console.log('- - - - - - - - - -UPDATE: secondaryMongoWhere:',secondaryMongoWhere, { '$set': s3q.valuesToSet }); // } - mongoCollection.updateMany(secondaryMongoWhere, { '$set': s3q.valuesToSet }).then(function updateManyCb() { + (function(iifeDone) { mongoCollection.updateMany(secondaryMongoWhere, { '$set': s3q.valuesToSet }).then(function() { iifeDone();}).catch(function(err) { iifeDone(err);});})(function(err) { + if (err) { + err = processNativeError(err); + if (err.footprint && err.footprint.identity === 'notUnique') { + return exits.notUnique(err); + } + return exits.error(err); + }//-• + // If fetch:true was not enabled, we're done! if (!isFetchEnabled) { return exits.success(); }//-• - // Handle case where pk value was changed: // > This isn't really relevant for Mongo, but it's still included to // > improve the error message and to future-proof this adapter. @@ -147,9 +155,10 @@ module.exports = { else { return exits.error(new Error('Consistency violation: Updated multiple records to have the same primary key value. (PK values should be unique!)')); } }//>- - // Now re-fetch the now-updated records. - mongoCollection.find(secondaryMongoWhere).toArray().then(function (phRecords) { + (function(iifeDone) { mongoCollection.find(secondaryMongoWhere).toArray().then(function(phRecords) { iifeDone(null, phRecords);}).catch(function(err) { iifeDone(err, null);});})(function(err, phRecords) { + if (err) { return exits.error(err); } + // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐┌─┌─┐─┐ // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ │││ └─┐ │ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘└─└─┘─┘ @@ -161,15 +170,7 @@ module.exports = { } catch (e) { return exits.error(e); } return exits.success(phRecords); - }).catch(function err() { - return exits.error(err); });// - }).catch(function (err) { - err = processNativeError(err); - if (err.footprint && err.footprint.identity === 'notUnique') { - return exits.notUnique(err); - } - return exits.error(err); });// });// } From c2e4ac0a15583f169d4fe7e8c851018e5b19612f Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:31:59 +0100 Subject: [PATCH 160/193] chore: revert changes --- lib/private/machines/update-records.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/private/machines/update-records.js b/lib/private/machines/update-records.js index c7cd80a64..2a573cf99 100644 --- a/lib/private/machines/update-records.js +++ b/lib/private/machines/update-records.js @@ -140,6 +140,7 @@ module.exports = { return exits.success(); }//-• + // Handle case where pk value was changed: // > This isn't really relevant for Mongo, but it's still included to // > improve the error message and to future-proof this adapter. @@ -155,6 +156,7 @@ module.exports = { else { return exits.error(new Error('Consistency violation: Updated multiple records to have the same primary key value. (PK values should be unique!)')); } }//>- + // Now re-fetch the now-updated records. (function(iifeDone) { mongoCollection.find(secondaryMongoWhere).toArray().then(function(phRecords) { iifeDone(null, phRecords);}).catch(function(err) { iifeDone(err, null);});})(function(err, phRecords) { if (err) { return exits.error(err); } From 171fd4e23973b4ab3534ed485ceffb3263872a23 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:32:46 +0100 Subject: [PATCH 161/193] chore: revert changes --- lib/private/machines/update-records.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/machines/update-records.js b/lib/private/machines/update-records.js index 2a573cf99..b799634cf 100644 --- a/lib/private/machines/update-records.js +++ b/lib/private/machines/update-records.js @@ -126,7 +126,7 @@ module.exports = { // console.log('- - - - - - - - - -UPDATE: secondaryMongoWhere:',secondaryMongoWhere, { '$set': s3q.valuesToSet }); // } - (function(iifeDone) { mongoCollection.updateMany(secondaryMongoWhere, { '$set': s3q.valuesToSet }).then(function() { iifeDone();}).catch(function(err) { iifeDone(err);});})(function(err) { + (function(iifeDone) { mongoCollection.updateMany(secondaryMongoWhere, { '$set': s3q.valuesToSet }).then(function() { iifeDone();}).catch(function(err) { iifeDone(err);});})(function updateManyCb(err) { if (err) { err = processNativeError(err); if (err.footprint && err.footprint.identity === 'notUnique') { From f8e4972bec0ca1f0998608e6545da410fe8358eb Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:35:13 +0100 Subject: [PATCH 162/193] Update run_mongodb.sh --- scripts/travis/run_mongodb.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh index ef67727a5..88c58a2d5 100644 --- a/scripts/travis/run_mongodb.sh +++ b/scripts/travis/run_mongodb.sh @@ -4,3 +4,4 @@ MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data ${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork + From a9791c37d16275c5a0fabe46d3544f1444fb9f27 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:35:54 +0100 Subject: [PATCH 163/193] chore: revert changes --- scripts/travis/run_mongodb.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh index 88c58a2d5..ef67727a5 100644 --- a/scripts/travis/run_mongodb.sh +++ b/scripts/travis/run_mongodb.sh @@ -4,4 +4,3 @@ MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data ${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork - From c31379892237521fa4658fe45f1262cacfb629ed Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:38:01 +0100 Subject: [PATCH 164/193] Update run-standard-tests.js From 8322fa64501f981f087ceca238238499951dbdf5 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:38:30 +0100 Subject: [PATCH 165/193] Update run-standard-tests.js --- test/run-standard-tests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/run-standard-tests.js b/test/run-standard-tests.js index 689aed23e..145130ed1 100644 --- a/test/run-standard-tests.js +++ b/test/run-standard-tests.js @@ -100,3 +100,4 @@ new TestRunner({ // to an adapter maintainer @ http://sailsjs.com/support. // // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + From 6e0de2015b2faf2b5779b8618891c45b23e0e75a Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:39:48 +0100 Subject: [PATCH 166/193] Update build-std-adapter-method.js --- lib/private/build-std-adapter-method.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/private/build-std-adapter-method.js b/lib/private/build-std-adapter-method.js index c3687c404..79206f3a7 100644 --- a/lib/private/build-std-adapter-method.js +++ b/lib/private/build-std-adapter-method.js @@ -79,3 +79,5 @@ module.exports = function buildStdAdapterMethod (machineDef, WET_MACHINES, regis };// }; + + From 0e78883966cbc64b5235d123c930bf8816ce6eaf Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 11:40:08 +0100 Subject: [PATCH 167/193] Update build-std-adapter-method.js --- lib/private/build-std-adapter-method.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/private/build-std-adapter-method.js b/lib/private/build-std-adapter-method.js index 79206f3a7..90c9ff85e 100644 --- a/lib/private/build-std-adapter-method.js +++ b/lib/private/build-std-adapter-method.js @@ -80,4 +80,3 @@ module.exports = function buildStdAdapterMethod (machineDef, WET_MACHINES, regis }; - From 4b12cf6229ab659ebf37e5b3a3607d9f8eed124c Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 12:56:29 +0100 Subject: [PATCH 168/193] chore: use IIFE for refactoring tests to promises --- test/run-adapter-specific-tests.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index d92e1f5b8..373a47718 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -1,10 +1,9 @@ - - var assert = require('assert'); var _ = require('@sailshq/lodash'); var Waterline = require('waterline'); var waterlineUtils = require('waterline-utils'); var normalizeDatastoreConfig = require('../lib/private/normalize-datastore-config'); + var waterline; var models = {}; @@ -145,8 +144,8 @@ describe('dontUseObjectIds', function() { describe('Updating a single record', function() { it('should update the record correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}) - .then(function insertCb() { + (function(iifeDone) { models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}).then(function(){ iifeDone();}).catch(function(err){ iifeDone(err);});})(function(err) { + if (err) {return done(err);} models.user.updateOne({id: 123}, {name: 'joe'}).exec(function(err, record) { if (err) {return done(err);} assert.equal(record.id, 123); @@ -154,7 +153,7 @@ describe('dontUseObjectIds', function() { return done(); }); - }).catch(function (err) { return done(err); }); + }); }); From 852a17c7624f0f7ed49a56bfdf0f54ac21c7abc9 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 12:57:21 +0100 Subject: [PATCH 169/193] chore: revert changes --- test/run-adapter-specific-tests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 373a47718..fe9250aa9 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -4,6 +4,7 @@ var Waterline = require('waterline'); var waterlineUtils = require('waterline-utils'); var normalizeDatastoreConfig = require('../lib/private/normalize-datastore-config'); + var waterline; var models = {}; From 77b24fc282214190a1e7b6b3d70de926d8f9d04e Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:01:25 +0100 Subject: [PATCH 170/193] chore: use IIFE for refactoring tests to promises --- test/run-adapter-specific-tests.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index fe9250aa9..1f1471b7c 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -164,8 +164,8 @@ describe('dontUseObjectIds', function() { it('should update the records correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}]) - .then(function insertManyCb() { + (function(iifeDone) {models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}]).then(function() { iifeDone();}).catch(function(err) { iifeDone(err);});})(function(err) { + if (err) {return done(err);} models.user.update({id: {'>': 0}}, {name: 'joe'}).exec(function(err, records) { if (err) {return done(err);} assert.equal(records[0].id, 123); @@ -174,7 +174,8 @@ describe('dontUseObjectIds', function() { assert.equal(records[1].name, 'joe'); return done(); }); - }).catch(function (err) { return done(err); }); + + }); }); }); From 0afecb90ed95684968d6e1ed0edab5ee918f5d31 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:01:59 +0100 Subject: [PATCH 171/193] chore: revert changes --- test/run-adapter-specific-tests.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 1f1471b7c..79d3b8b22 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -176,7 +176,9 @@ describe('dontUseObjectIds', function() { }); }); + }); + }); describe('Finding a single record', function() { From 1ef1b8c547b93e9d2915a7baec73b860d947d80a Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:24:41 +0100 Subject: [PATCH 172/193] chore: use IIFE for refactoring tests to promises --- test/run-adapter-specific-tests.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 79d3b8b22..b65299e98 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -185,15 +185,16 @@ describe('dontUseObjectIds', function() { it('should find a record w/ a numeric ID', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}) - .then(function() { + + (function(iifeDone) {models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}).then(function(){ iifeDone();}).catch(function(err) { iifeDone(err);});})(function(err) { + if (err) {return done(err);} models.user.findOne({id: 123}).exec(function(err, record) { if (err) {return done(err);} assert.equal(record.id, 123); assert.equal(record.name, 'bob'); return done(); }); - }).catch(function (err) { return done(err); }); + }); }); From 19e086916f5f0e02c739be307be1c92594e318a1 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:25:34 +0100 Subject: [PATCH 173/193] chore: revert changes --- test/run-adapter-specific-tests.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index b65299e98..efa9b814b 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -185,7 +185,6 @@ describe('dontUseObjectIds', function() { it('should find a record w/ a numeric ID', function(done) { - (function(iifeDone) {models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}).then(function(){ iifeDone();}).catch(function(err) { iifeDone(err);});})(function(err) { if (err) {return done(err);} models.user.findOne({id: 123}).exec(function(err, record) { From 0de511944a6a506cdcc9190f051b1082709db1aa Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:28:10 +0100 Subject: [PATCH 174/193] chore: use IIFE for refactoring tests to promises --- test/run-adapter-specific-tests.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index efa9b814b..83e2c39ef 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -203,8 +203,8 @@ describe('dontUseObjectIds', function() { it('should find the records correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}]) - .then(function() { + (function(iifeDone) {models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}]).then(function() { iifeDone();}).catch(function(err) { iifeDone(err);});})(function(err) { + if (err) {return done(err);} models.user.find({id: {'>': 0}}).exec(function(err, records) { if (err) {return done(err);} assert.equal(records[0].id, 123); @@ -213,7 +213,8 @@ describe('dontUseObjectIds', function() { assert.equal(records[1].name, 'nancy'); return done(); }); - }).catch(function (err) { return done(err); }); + + }); }); }); From 6b989a3d0765fbe7d57592afea5990e7dbe803ea Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:46:35 +0100 Subject: [PATCH 175/193] chore: use IIFE for refactoring tests to promises --- test/run-adapter-specific-tests.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 83e2c39ef..8495922e5 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -222,19 +222,22 @@ describe('dontUseObjectIds', function() { describe('Deleting a single record', function() { it('should delete the record correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user') - .insertOne({_id: 123, name: 'bob'}) - .then(function() { + (function(iifeDone) {models.user._adapter.datastores.test.manager.collection('user').insertOne({_id: 123, name: 'bob'}).then(function() { iifeDone();}).catch(function(err) { iifeDone(err);});})(function(err) { + if (err) {return done(err);} models.user.destroy({id: 123}).exec(function(err) { - if (err) { return done(err); } - models.user._adapter.datastores.test.manager.collection('user').find({}) - .toArray().then(function(records) { + if (err) {return done(err);} + (function(iifeDone) { models.user._adapter.datastores.test.manager.collection('user').find({}).toArray().then(function(records) { iifeDone(null, records);}).catch(function(err) { iifeDone(err, null);});})(function(err, records) { + if (err) {return done(err);} assert.equal(records.length, 0); return done(); - }).catch(function (err) { return done(err); }); + }); + }); - }).catch(function (err) { return done(err); }); + + }); + }); + }); describe('Deleting multiple records', function() { From 3ccd0e7d60ef6d054c84720c8f82d821f738d8a1 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:52:46 +0100 Subject: [PATCH 176/193] chore: use IIFE for refactoring tests to promises --- test/run-adapter-specific-tests.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 8495922e5..2b5b9f86e 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -244,17 +244,18 @@ describe('dontUseObjectIds', function() { it('should delete the records correctly', function(done) { - models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}]) - .then(function() { + (function(iifeDone) { models.user._adapter.datastores.test.manager.collection('user').insertMany([{_id: 123, name: 'sid'}, {_id: 555, name: 'nancy'}]).then(function() { iifeDone();}).catch(function(err) { iifeDone(err);});})(function(err) { + if (err) {return done(err);} models.user.destroy({id: {'>': 0}}).exec(function(err) { if (err) {return done(err);} - models.user._adapter.datastores.test.manager.collection('user').find({}).toArray() - .then(function(records) { + (function(iifeDone) { models.user._adapter.datastores.test.manager.collection('user').find({}).toArray().then(function(records) { iifeDone(null, records);}).catch(function(err) { iifeDone(err, null);});})(function(err, records) { + if (err) {return done(err);} assert.equal(records.length, 0); return done(); - }).catch(function (err) { return done(err); }); + }); }); - }).catch(function (err) { return done(err); }); + + }); }); }); From 60fb9c811a76d7349c3af6f525efe0aee891294c Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:53:27 +0100 Subject: [PATCH 177/193] Update run-adapter-specific-tests.js --- test/run-adapter-specific-tests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 2b5b9f86e..3d2e3b8bb 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -775,3 +775,4 @@ function createModel (identity, options) { return model; } + From 5a301880d3dc2d4b06711a76a900c1abd55ee8aa Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:54:01 +0100 Subject: [PATCH 178/193] Update install_mongodb.sh From 1ad41acb68cb737eb1156b310f7900bafab29998 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:54:45 +0100 Subject: [PATCH 179/193] Delete scripts/travis/install_mongodb.sh --- scripts/travis/install_mongodb.sh | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 scripts/travis/install_mongodb.sh diff --git a/scripts/travis/install_mongodb.sh b/scripts/travis/install_mongodb.sh deleted file mode 100644 index 499b7190f..000000000 --- a/scripts/travis/install_mongodb.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -MDB_TGZ=mongodb-linux-x86_64-ubuntu1604-${MONGODB}.tgz -MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} -MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data - -# If it doesn't exist, it means the cache didn't pull it -if [ ! -f "${MDB_ROOT}/bin/mongod" ]; then - mkdir -p $MDB_ROOT - pushd $MDB_ROOT - wget https://fastdl.mongodb.org/linux/${MDB_TGZ} - tar xzf ${MDB_TGZ} --strip 1 - rm -f ${MDB_TGZ} - popd -fi -mkdir -p $MDB_DATA -"${MDB_ROOT}/bin/mongod" --version From acfd322dde040ab071ac5f4ab716abd030516c70 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:55:07 +0100 Subject: [PATCH 180/193] Delete scripts/travis/run_mongodb.sh --- scripts/travis/run_mongodb.sh | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 scripts/travis/run_mongodb.sh diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh deleted file mode 100644 index ef67727a5..000000000 --- a/scripts/travis/run_mongodb.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} -MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data - -${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork From 49eeeb5a10a0ec3160b063a0907a370c0d4e5482 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:56:48 +0100 Subject: [PATCH 181/193] chore: revert changes --- scripts/travis/install_mongodb.sh | 17 +++++++++++++++++ scripts/travis/run_mongodb.sh | 6 ++++++ 2 files changed, 23 insertions(+) create mode 100644 scripts/travis/install_mongodb.sh create mode 100644 scripts/travis/run_mongodb.sh diff --git a/scripts/travis/install_mongodb.sh b/scripts/travis/install_mongodb.sh new file mode 100644 index 000000000..499b7190f --- /dev/null +++ b/scripts/travis/install_mongodb.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +MDB_TGZ=mongodb-linux-x86_64-ubuntu1604-${MONGODB}.tgz +MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} +MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data + +# If it doesn't exist, it means the cache didn't pull it +if [ ! -f "${MDB_ROOT}/bin/mongod" ]; then + mkdir -p $MDB_ROOT + pushd $MDB_ROOT + wget https://fastdl.mongodb.org/linux/${MDB_TGZ} + tar xzf ${MDB_TGZ} --strip 1 + rm -f ${MDB_TGZ} + popd +fi +mkdir -p $MDB_DATA +"${MDB_ROOT}/bin/mongod" --version diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh new file mode 100644 index 000000000..ef67727a5 --- /dev/null +++ b/scripts/travis/run_mongodb.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} +MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data + +${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork From 0f856d46e13a05619cb0715be98cc760ec482f7d Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:58:30 +0100 Subject: [PATCH 182/193] Update install_mongodb.sh --- scripts/travis/install_mongodb.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/travis/install_mongodb.sh b/scripts/travis/install_mongodb.sh index 499b7190f..40ddb12bf 100644 --- a/scripts/travis/install_mongodb.sh +++ b/scripts/travis/install_mongodb.sh @@ -15,3 +15,4 @@ if [ ! -f "${MDB_ROOT}/bin/mongod" ]; then fi mkdir -p $MDB_DATA "${MDB_ROOT}/bin/mongod" --version + From 4558ab67ef8b9701874b1daf9aa2dd8d68247ff7 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:58:56 +0100 Subject: [PATCH 183/193] Update run_mongodb.sh --- scripts/travis/run_mongodb.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh index ef67727a5..2da6c6979 100644 --- a/scripts/travis/run_mongodb.sh +++ b/scripts/travis/run_mongodb.sh @@ -3,4 +3,4 @@ MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data -${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork +${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork From 856a9e140ebfae5c8e17bca87ef88a9b1b2342d9 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 13:59:56 +0100 Subject: [PATCH 184/193] chore: revert changes --- scripts/travis/install_mongodb.sh | 1 - scripts/travis/run_mongodb.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/travis/install_mongodb.sh b/scripts/travis/install_mongodb.sh index 40ddb12bf..499b7190f 100644 --- a/scripts/travis/install_mongodb.sh +++ b/scripts/travis/install_mongodb.sh @@ -15,4 +15,3 @@ if [ ! -f "${MDB_ROOT}/bin/mongod" ]; then fi mkdir -p $MDB_DATA "${MDB_ROOT}/bin/mongod" --version - diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh index 2da6c6979..ef67727a5 100644 --- a/scripts/travis/run_mongodb.sh +++ b/scripts/travis/run_mongodb.sh @@ -3,4 +3,4 @@ MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data -${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork +${MDB_ROOT}/bin/mongod --dbpath ${MDB_DATA} --logpath=/dev/null --fork From 4b69023e99cd1c7913b6c7c817164dc52dce2621 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Fri, 17 Nov 2023 14:03:40 +0100 Subject: [PATCH 185/193] chore: revert changes --- scripts/travis/install_mongodb.sh | 0 scripts/travis/run_mongodb.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/travis/install_mongodb.sh mode change 100644 => 100755 scripts/travis/run_mongodb.sh diff --git a/scripts/travis/install_mongodb.sh b/scripts/travis/install_mongodb.sh old mode 100644 new mode 100755 diff --git a/scripts/travis/run_mongodb.sh b/scripts/travis/run_mongodb.sh old mode 100644 new mode 100755 From dff776782c7d0a1b4df17c5b47dd48b2e5372ebb Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 22 Nov 2023 12:47:43 -0600 Subject: [PATCH 186/193] update iife functions to return undefined instead of null, remove second argument on catch() --- lib/private/machines/avg-records.js | 2 +- lib/private/machines/count-records.js | 2 +- lib/private/machines/create-each-record.js | 4 ++-- lib/private/machines/create-manager.js | 2 +- lib/private/machines/create-record.js | 4 ++-- lib/private/machines/destroy-records.js | 2 +- lib/private/machines/find-records.js | 2 +- lib/private/machines/update-records.js | 4 ++-- test/run-adapter-specific-tests.js | 4 ++-- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/private/machines/avg-records.js b/lib/private/machines/avg-records.js index 344ee967b..377b722c7 100644 --- a/lib/private/machines/avg-records.js +++ b/lib/private/machines/avg-records.js @@ -76,7 +76,7 @@ module.exports = { } ], { cursor: {} }); - (function(iifeDone) { cursor.toArray().then(function(nativeResult) { iifeDone(null, nativeResult); }).catch(function (err){iifeDone(err, null);}); })(function aggregateCb(err, nativeResult) { + (function(iifeDone) { cursor.toArray().then(function(nativeResult) { iifeDone(undefined, nativeResult); }).catch(function (err){iifeDone(err);}); })(function aggregateCb(err, nativeResult) { if (err) { return exits.error(err); } var mean = 0; diff --git a/lib/private/machines/count-records.js b/lib/private/machines/count-records.js index 74cd1027f..9a4d82ca6 100644 --- a/lib/private/machines/count-records.js +++ b/lib/private/machines/count-records.js @@ -61,7 +61,7 @@ module.exports = { // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ var db = inputs.connection; var mongoCollection = db.collection(tableName); - (function(iifeDone) { mongoCollection.countDocuments(mongoWhere).then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function countCb(err, nativeResult) { + (function(iifeDone) { mongoCollection.countDocuments(mongoWhere).then(function(nativeResult) { iifeDone(undefined, nativeResult);}).catch(function(err) { iifeDone(err);});})(function countCb(err, nativeResult) { if (err) { return exits.error(err); } return exits.success(nativeResult); diff --git a/lib/private/machines/create-each-record.js b/lib/private/machines/create-each-record.js index b013870b9..a20b14d8e 100644 --- a/lib/private/machines/create-each-record.js +++ b/lib/private/machines/create-each-record.js @@ -82,7 +82,7 @@ module.exports = { // if (s3q.meta && s3q.meta.logMongoS3Qs) { // console.log('- - - - - - - - - -CREATE EACH: s3q.newRecords:',require('util').inspect(s3q.newRecords,{depth:5}),'\n'); // } - (function(iifeDone){ mongoCollection.insertMany(s3q.newRecords).then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function(err, nativeResult) { + (function(iifeDone){ mongoCollection.insertMany(s3q.newRecords).then(function(nativeResult) { iifeDone(undefined, nativeResult);}).catch(function(err) { iifeDone(err);});})(function(err, nativeResult) { if (err) { err = processNativeError(err); if (err.footprint && err.footprint.identity === 'notUnique') { @@ -107,7 +107,7 @@ module.exports = { // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘└─└─┘─┘ // Process record(s) (mutate in-place) to wash away adapter-specific eccentricities. - (function(iifeDone){ mongoCollection.find({ _id: { $in: insertedIds } }).toArray().then(function(phRecords) { iifeDone(null, phRecords); }).catch(function(err) { iifeDone(err, null);});})(function(err, phRecords) { + (function(iifeDone){ mongoCollection.find({ _id: { $in: insertedIds } }).toArray().then(function(phRecords) { iifeDone(undefined, phRecords); }).catch(function(err) { iifeDone(err);});})(function(err, phRecords) { if (err) { return exits.error(err); } diff --git a/lib/private/machines/create-manager.js b/lib/private/machines/create-manager.js index 236996f4c..0c8447109 100644 --- a/lib/private/machines/create-manager.js +++ b/lib/private/machines/create-manager.js @@ -126,7 +126,7 @@ module.exports = { _clientConfig = _.omit(_clientConfig, ['url', 'user', 'password', 'host', 'port', 'database']); // https://mongodb.github.io/node-mongodb-native/6.3/classes/MongoClient.html#connect - (function(iifeDone){ NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig).then(function(client){ iifeDone(null, client);}).catch(function(err) { iifeDone(err, null);});})(function(err, client){ + (function(iifeDone){ NodeMongoDBNativeLib.MongoClient.connect(mongoUrl, _clientConfig).then(function(client){ iifeDone(undefined, client);}).catch(function(err) { iifeDone(err);});})(function(err, client){ if (err) { return exits.error(err); } diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 408bd4614..a2f55b3a5 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -75,7 +75,7 @@ module.exports = { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - var db = inputs.connection; var mongoCollection = db.collection(tableName); - (function(iifeDone){ mongoCollection.insertOne(s3q.newRecord).then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err){ iifeDone(err, null);});})(function(err, nativeResult) { + (function(iifeDone){ mongoCollection.insertOne(s3q.newRecord).then(function(nativeResult) { iifeDone(undefined, nativeResult);}).catch(function(err){ iifeDone(err);});})(function(err, nativeResult) { if (err) { err = processNativeError(err); if (err.footprint && err.footprint.identity === 'notUnique') { @@ -106,7 +106,7 @@ module.exports = { // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ ││ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘ // Process record (mutate in-place) to wash away adapter-specific eccentricities. - (function(iifeDone) { mongoCollection.findOne({ _id: nativeResult.insertedId }).then(function(phRecord) { iifeDone(null, phRecord);}).catch(function(err) { iifeDone(err, null);});})(function(err, phRecord) { + (function(iifeDone) { mongoCollection.findOne({ _id: nativeResult.insertedId }).then(function(phRecord) { iifeDone(undefined, phRecord);}).catch(function(err) { iifeDone(err);});})(function(err, phRecord) { if (err) { return exits.error(err); } diff --git a/lib/private/machines/destroy-records.js b/lib/private/machines/destroy-records.js index 04f5ce2f1..5ea9c5e93 100644 --- a/lib/private/machines/destroy-records.js +++ b/lib/private/machines/destroy-records.js @@ -87,7 +87,7 @@ module.exports = { } // Find matching records. - (function(iifeDone) {mongoCollection.find(mongoWhere).toArray().then(function findCb(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function findCb(err, nativeResult) { + (function(iifeDone) {mongoCollection.find(mongoWhere).toArray().then(function findCb(nativeResult) { iifeDone(undefined, nativeResult);}).catch(function(err) { iifeDone(err);});})(function findCb(err, nativeResult) { if (err) { return proceed(err); } return proceed(undefined, nativeResult); }); diff --git a/lib/private/machines/find-records.js b/lib/private/machines/find-records.js index 16894536f..3473ba23f 100644 --- a/lib/private/machines/find-records.js +++ b/lib/private/machines/find-records.js @@ -117,7 +117,7 @@ module.exports = { // ║ ║ ║║║║║║║║ ║║║║║║ ╠═╣ ║ ║╣ ││││ │ ├─┤ ││├┴┐ // ╚═╝╚═╝╩ ╩╩ ╩╚═╝╝╚╝╩╚═╝╩ ╩ ╩ ╚═╝ └┴┘┴ ┴ ┴ ┴ ─┴┘└─┘ // Find the documents in the db. - (function(iifeDone) { mongoDeferred.toArray().then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function findCb(err, nativeResult) { + (function(iifeDone) { mongoDeferred.toArray().then(function(nativeResult) { iifeDone(undefined, nativeResult);}).catch(function(err) { iifeDone(err);});})(function findCb(err, nativeResult) { if (err) { return exits.error(err); } // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐┌─┌─┐─┐ diff --git a/lib/private/machines/update-records.js b/lib/private/machines/update-records.js index b799634cf..8b723ffc0 100644 --- a/lib/private/machines/update-records.js +++ b/lib/private/machines/update-records.js @@ -103,7 +103,7 @@ module.exports = { // console.log('mongoWhere:',mongoWhere); // console.log('typeof mongoWhere._id.$in[0]:',typeof mongoWhere._id.$in[0]); // console.log('projection:',projection); - (function(iifeDone) { mongoCollection.find(mongoWhere, projection).toArray().then(function(nativeResult) { iifeDone(null, nativeResult);}).catch(function(err) { iifeDone(err, null);});})(function findCb(err, nativeResult) { + (function(iifeDone) { mongoCollection.find(mongoWhere, projection).toArray().then(function(nativeResult) { iifeDone(undefined, nativeResult);}).catch(function(err) { iifeDone(err);});})(function findCb(err, nativeResult) { if (err) { return proceed(err); } return proceed(undefined, _.pluck(nativeResult, pkColumnName)); }); @@ -158,7 +158,7 @@ module.exports = { // Now re-fetch the now-updated records. - (function(iifeDone) { mongoCollection.find(secondaryMongoWhere).toArray().then(function(phRecords) { iifeDone(null, phRecords);}).catch(function(err) { iifeDone(err, null);});})(function(err, phRecords) { + (function(iifeDone) { mongoCollection.find(secondaryMongoWhere).toArray().then(function(phRecords) { iifeDone(undefined, phRecords);}).catch(function(err) { iifeDone(err);});})(function(err, phRecords) { if (err) { return exits.error(err); } // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐┌─┌─┐─┐ diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 3d2e3b8bb..9133c356f 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -226,7 +226,7 @@ describe('dontUseObjectIds', function() { if (err) {return done(err);} models.user.destroy({id: 123}).exec(function(err) { if (err) {return done(err);} - (function(iifeDone) { models.user._adapter.datastores.test.manager.collection('user').find({}).toArray().then(function(records) { iifeDone(null, records);}).catch(function(err) { iifeDone(err, null);});})(function(err, records) { + (function(iifeDone) { models.user._adapter.datastores.test.manager.collection('user').find({}).toArray().then(function(records) { iifeDone(undefined, records);}).catch(function(err) { iifeDone(err);});})(function(err, records) { if (err) {return done(err);} assert.equal(records.length, 0); return done(); @@ -248,7 +248,7 @@ describe('dontUseObjectIds', function() { if (err) {return done(err);} models.user.destroy({id: {'>': 0}}).exec(function(err) { if (err) {return done(err);} - (function(iifeDone) { models.user._adapter.datastores.test.manager.collection('user').find({}).toArray().then(function(records) { iifeDone(null, records);}).catch(function(err) { iifeDone(err, null);});})(function(err, records) { + (function(iifeDone) { models.user._adapter.datastores.test.manager.collection('user').find({}).toArray().then(function(records) { iifeDone(undefined, records);}).catch(function(err) { iifeDone(err);});})(function(err, records) { if (err) {return done(err);} assert.equal(records.length, 0); return done(); From f190ffb32f9d706abb70609f247d532d165d28b9 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 22 Nov 2023 13:08:37 -0600 Subject: [PATCH 187/193] update comments --- lib/private/machines/create-each-record.js | 4 ++-- lib/private/machines/create-record.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/private/machines/create-each-record.js b/lib/private/machines/create-each-record.js index a20b14d8e..8bd1081f4 100644 --- a/lib/private/machines/create-each-record.js +++ b/lib/private/machines/create-each-record.js @@ -105,14 +105,14 @@ module.exports = { // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐┌─┌─┐─┐ // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ │││ └─┐ │ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘└─└─┘─┘ - // Process record(s) (mutate in-place) to wash away adapter-specific eccentricities. - + // Use the new record ID(s) to find the record(s) that were created. (function(iifeDone){ mongoCollection.find({ _id: { $in: insertedIds } }).toArray().then(function(phRecords) { iifeDone(undefined, phRecords); }).catch(function(err) { iifeDone(err);});})(function(err, phRecords) { if (err) { return exits.error(err); } try { _.each(phRecords, function (phRecord){ + // Process record(s) (mutate in-place) to wash away adapter-specific eccentricities. processNativeRecord(phRecord, WLModel, s3q.meta); }); } catch (e) { return exits.error(e); } diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index a2f55b3a5..67dd9a1e2 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -105,12 +105,13 @@ module.exports = { // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐ // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ ││ // ╩ ╩╚═╚═╝╚═╝╚═╝╚═╝╚═╝ ┘└┘┴ ┴ ┴ ┴ └┘ └─┘ ┴└─└─┘└─┘└─┘┴└──┴┘ - // Process record (mutate in-place) to wash away adapter-specific eccentricities. + // Use the new record ID to find the record that was created. (function(iifeDone) { mongoCollection.findOne({ _id: nativeResult.insertedId }).then(function(phRecord) { iifeDone(undefined, phRecord);}).catch(function(err) { iifeDone(err);});})(function(err, phRecord) { if (err) { return exits.error(err); } try { + // Process record (mutate in-place) to wash away adapter-specific eccentricities. processNativeRecord(phRecord, WLModel, s3q.meta); } catch (e) { return exits.error(e); } From 817c742a25545a6bf2cef208e5348c411e6d2ee5 Mon Sep 17 00:00:00 2001 From: Kelvin Oghenerhoro Omereshone Date: Thu, 23 Nov 2023 11:15:31 +0100 Subject: [PATCH 188/193] feat: add assertions for results returned from MongoDB --- lib/private/machines/create-each-record.js | 6 ++++++ lib/private/machines/create-record.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/private/machines/create-each-record.js b/lib/private/machines/create-each-record.js index 8bd1081f4..6c3c49357 100644 --- a/lib/private/machines/create-each-record.js +++ b/lib/private/machines/create-each-record.js @@ -29,6 +29,7 @@ module.exports = { fn: function (inputs, exits) { // Dependencies + var util = require('util'); var _ = require('@sailshq/lodash'); var processNativeRecord = require('./private/process-native-record'); var processNativeError = require('./private/process-native-error'); @@ -97,6 +98,11 @@ module.exports = { return exits.success(); }//-• + // Sanity check: Verify that IDs were sent back. + if (_.isUndefined(nativeResult.insertedIds) || !_.isObject(nativeResult.insertedIds)) { + return exits.error(new Error('Consistency violation: Unable to retrieve valid insertedIds from the result. This might indicate a consistency violation. Native result details:\n```\n' + util.inspect(nativeResult, {depth: 5}) + '\n```')); + } + var insertedIds = Object.values(nativeResult.insertedIds); // Otherwise, IWMIH we'll be sending back records: diff --git a/lib/private/machines/create-record.js b/lib/private/machines/create-record.js index 67dd9a1e2..830e37897 100644 --- a/lib/private/machines/create-record.js +++ b/lib/private/machines/create-record.js @@ -29,6 +29,7 @@ module.exports = { fn: function (inputs, exits) { // Dependencies + var util = require('util'); var _ = require('@sailshq/lodash'); var processNativeRecord = require('./private/process-native-record'); var processNativeError = require('./private/process-native-error'); @@ -101,6 +102,11 @@ module.exports = { // Otherwise, IWMIH we'll be sending back a record: // ============================================ + // Sanity check: Verify that an ID was sent back. + if (_.isUndefined(nativeResult.insertedId)) { + return exits.error(new Error('Consistency violation: Unable to retrieve insertedId from the result. This might indicate a consistency violation. Native result details:\n```\n' + util.inspect(nativeResult, {depth: 5}) + '\n```')); + } + // ╔═╗╦═╗╔═╗╔═╗╔═╗╔═╗╔═╗ ┌┐┌┌─┐┌┬┐┬┬ ┬┌─┐ ┬─┐┌─┐┌─┐┌─┐┬─┐┌┬┐ // ╠═╝╠╦╝║ ║║ ║╣ ╚═╗╚═╗ │││├─┤ │ │└┐┌┘├┤ ├┬┘├┤ │ │ │├┬┘ ││ From c151a310d356ff2415d0c47eb77dcc8294e5dc27 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 28 Nov 2023 19:43:33 -0600 Subject: [PATCH 189/193] update node versions in CI config files --- .travis.yml | 4 ++-- appveyor.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4564cc1b6..a4342255d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,9 +14,9 @@ dist: xenial language: node_js node_js: - - "12" - - "14" - "16" + - "18" + - "20" env: global: diff --git a/appveyor.yml b/appveyor.yml index c68b2724d..cf0060f73 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -17,9 +17,9 @@ environment: WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo NODE_ENV: test matrix: - - nodejs_version: "10" - - nodejs_version: "12" - - nodejs_version: "14" + - nodejs_version: "16" + - nodejs_version: "18" + - nodejs_version: "20" # Install scripts. (runs after repo cloning) install: From 4cc13ca41722625857af74ac22acd0cc07a82afa Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 28 Nov 2023 19:53:30 -0600 Subject: [PATCH 190/193] update CI tests --- .travis.yml | 2 +- appveyor.yml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a4342255d..4bab5fb6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ # https://docs.travis-ci.com/user/customizing-the-build # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -dist: xenial +dist: focal language: node_js diff --git a/appveyor.yml b/appveyor.yml index cf0060f73..8ed2b6d5c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,8 +26,6 @@ install: # Get the latest stable version of Node.js # (Not sure what this is for, it's just in Appveyor's example.) - ps: Install-Product node $env:nodejs_version - # Don't let npm send metrics as it creates a file in the .npm folder invalidating the cache every time - - npm config set send-metrics false # Install declared dependencies - npm install --no-audit From a7c8f6f8a63c4a37e9657bbc6e3d6ddbbdde6fa6 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 28 Nov 2023 20:47:23 -0600 Subject: [PATCH 191/193] run travis test on ubuntu 16, comment out incompatible node versions --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4bab5fb6d..67641bd6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,15 +9,14 @@ # https://docs.travis-ci.com/user/customizing-the-build # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -dist: focal +dist: xenial language: node_js node_js: - "16" - - "18" - - "20" - + # - "18" + # - "20" env: global: - WATERLINE_ADAPTER_TESTS_URL=localhost/testdb From 49948b56c3374905b2311d42951b46d00c5927e7 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 4 Dec 2023 16:01:37 -0600 Subject: [PATCH 192/193] =?UTF-8?q?Update=20tests=20(localhost=20=C2=BB=20?= =?UTF-8?q?127.0.0.1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/connectable/create-manager.test.js | 6 +++--- test/connectable/destroy-manager.test.js | 2 +- test/connectable/get-connection.test.js | 2 +- test/connectable/release-connection.test.js | 2 +- test/run-adapter-specific-tests.js | 2 +- test/run-standard-tests.js | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/connectable/create-manager.test.js b/test/connectable/create-manager.test.js index c3ecfe5a6..2bda23170 100644 --- a/test/connectable/create-manager.test.js +++ b/test/connectable/create-manager.test.js @@ -6,7 +6,7 @@ describe('Connectable ::', function() { describe('Create Manager', function() { it('should work without a protocol in the connection string', function(done) { createManager({ - connectionString: process.env.WATERLINE_ADAPTER_TESTS_URL || 'localhost:27017/mppg' + connectionString: process.env.WATERLINE_ADAPTER_TESTS_URL || '127.0.0.1:27017/mppg' }) .exec(function(err) { if (err) { @@ -18,7 +18,7 @@ describe('Connectable ::', function() { it('should not work with an invalid protocol in the connection string', function(done) { createManager({ - connectionString: 'foobar://localhost:27017/mppg' + connectionString: 'foobar://127.0.0.1:27017/mppg' }) .exec(function(err) { try { @@ -32,7 +32,7 @@ describe('Connectable ::', function() { it('should successfully return a Mongo Server instance', function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || '127.0.0.1'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' diff --git a/test/connectable/destroy-manager.test.js b/test/connectable/destroy-manager.test.js index 61928732d..4be813d74 100644 --- a/test/connectable/destroy-manager.test.js +++ b/test/connectable/destroy-manager.test.js @@ -8,7 +8,7 @@ describe('Connectable ::', function() { // Create a manager before(function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || '127.0.0.1'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' diff --git a/test/connectable/get-connection.test.js b/test/connectable/get-connection.test.js index 9829424fd..56bf6bb39 100644 --- a/test/connectable/get-connection.test.js +++ b/test/connectable/get-connection.test.js @@ -9,7 +9,7 @@ describe('Connectable ::', function() { // Create a manager before(function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || '127.0.0.1'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' diff --git a/test/connectable/release-connection.test.js b/test/connectable/release-connection.test.js index 5fa68fe1e..7d6393388 100644 --- a/test/connectable/release-connection.test.js +++ b/test/connectable/release-connection.test.js @@ -10,7 +10,7 @@ describe('Connectable ::', function() { // Create a manager and connection before(function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || '127.0.0.1'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 9133c356f..6228b6593 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -697,7 +697,7 @@ function setup(fixtures, modelsContainer, cb) { var datastores = { test: { adapter: 'sails-mongo', - url: process.env.WATERLINE_ADAPTER_TESTS_URL || 'localhost/sails_mongo' + url: process.env.WATERLINE_ADAPTER_TESTS_URL || '127.0.0.1/sails_mongo' } }; diff --git a/test/run-standard-tests.js b/test/run-standard-tests.js index 145130ed1..22241fe1d 100644 --- a/test/run-standard-tests.js +++ b/test/run-standard-tests.js @@ -71,7 +71,7 @@ new TestRunner({ // Adapter config to use for tests. config: { - url: process.env.WATERLINE_ADAPTER_TESTS_URL || 'localhost/testdb' + url: process.env.WATERLINE_ADAPTER_TESTS_URL || '127.0.0.1/testdb' }, // The set of adapter interface layers & specific features to test against. From ecf1f420db0438a1514828dbaf9609a9af38393f Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 4 Dec 2023 16:07:35 -0600 Subject: [PATCH 193/193] Revert test changes, update env variables in appveyor test to use ipv4 localhost address --- appveyor.yml | 4 ++-- test/connectable/create-manager.test.js | 6 +++--- test/connectable/destroy-manager.test.js | 2 +- test/connectable/get-connection.test.js | 2 +- test/connectable/release-connection.test.js | 2 +- test/run-adapter-specific-tests.js | 2 +- test/run-standard-tests.js | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 8ed2b6d5c..8628af7fd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,8 +12,8 @@ # Test against these versions of Node.js. environment: - WATERLINE_ADAPTER_TESTS_URL: localhost/testdb - WATERLINE_ADAPTER_TESTS_HOST: localhost + WATERLINE_ADAPTER_TESTS_URL: 127.0.0.1/testdb + WATERLINE_ADAPTER_TESTS_HOST: 127.0.0.1 WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo NODE_ENV: test matrix: diff --git a/test/connectable/create-manager.test.js b/test/connectable/create-manager.test.js index 2bda23170..c3ecfe5a6 100644 --- a/test/connectable/create-manager.test.js +++ b/test/connectable/create-manager.test.js @@ -6,7 +6,7 @@ describe('Connectable ::', function() { describe('Create Manager', function() { it('should work without a protocol in the connection string', function(done) { createManager({ - connectionString: process.env.WATERLINE_ADAPTER_TESTS_URL || '127.0.0.1:27017/mppg' + connectionString: process.env.WATERLINE_ADAPTER_TESTS_URL || 'localhost:27017/mppg' }) .exec(function(err) { if (err) { @@ -18,7 +18,7 @@ describe('Connectable ::', function() { it('should not work with an invalid protocol in the connection string', function(done) { createManager({ - connectionString: 'foobar://127.0.0.1:27017/mppg' + connectionString: 'foobar://localhost:27017/mppg' }) .exec(function(err) { try { @@ -32,7 +32,7 @@ describe('Connectable ::', function() { it('should successfully return a Mongo Server instance', function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || '127.0.0.1'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' diff --git a/test/connectable/destroy-manager.test.js b/test/connectable/destroy-manager.test.js index 4be813d74..61928732d 100644 --- a/test/connectable/destroy-manager.test.js +++ b/test/connectable/destroy-manager.test.js @@ -8,7 +8,7 @@ describe('Connectable ::', function() { // Create a manager before(function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || '127.0.0.1'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' diff --git a/test/connectable/get-connection.test.js b/test/connectable/get-connection.test.js index 56bf6bb39..9829424fd 100644 --- a/test/connectable/get-connection.test.js +++ b/test/connectable/get-connection.test.js @@ -9,7 +9,7 @@ describe('Connectable ::', function() { // Create a manager before(function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || '127.0.0.1'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' diff --git a/test/connectable/release-connection.test.js b/test/connectable/release-connection.test.js index 7d6393388..5fa68fe1e 100644 --- a/test/connectable/release-connection.test.js +++ b/test/connectable/release-connection.test.js @@ -10,7 +10,7 @@ describe('Connectable ::', function() { // Create a manager and connection before(function(done) { // Needed to dynamically get the host using the docker container - var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || '127.0.0.1'; + var host = process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost'; createManager({ connectionString: 'mongodb://' + host + ':27017/mppg' diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 6228b6593..9133c356f 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -697,7 +697,7 @@ function setup(fixtures, modelsContainer, cb) { var datastores = { test: { adapter: 'sails-mongo', - url: process.env.WATERLINE_ADAPTER_TESTS_URL || '127.0.0.1/sails_mongo' + url: process.env.WATERLINE_ADAPTER_TESTS_URL || 'localhost/sails_mongo' } }; diff --git a/test/run-standard-tests.js b/test/run-standard-tests.js index 22241fe1d..145130ed1 100644 --- a/test/run-standard-tests.js +++ b/test/run-standard-tests.js @@ -71,7 +71,7 @@ new TestRunner({ // Adapter config to use for tests. config: { - url: process.env.WATERLINE_ADAPTER_TESTS_URL || '127.0.0.1/testdb' + url: process.env.WATERLINE_ADAPTER_TESTS_URL || 'localhost/testdb' }, // The set of adapter interface layers & specific features to test against.