From 2a594285edb5979d50e74d549539b7043332adb9 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Thu, 13 Jun 2024 13:59:06 +0200 Subject: [PATCH 1/6] fixing case on orderBy --- lib/Collection.js | 2 +- lib/MongoQuery.js | 2 +- lib/types.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Collection.js b/lib/Collection.js index 9b5cd42..3d66a40 100644 --- a/lib/Collection.js +++ b/lib/Collection.js @@ -6,7 +6,7 @@ const MongoQuery = require('./MongoQuery.js'); const _defaultQueryTimeoutMS = 120000; -// const _specialFields = ['$select', '$limit', '$top', '$filter', '$skip', '$sort', '$orderby', '$rawQuery', '$aggregate', '$group']; +// const _specialFields = ['$select', '$limit', '$top', '$filter', '$skip', '$sort', '$orderBy', '$rawQuery', '$aggregate', '$group']; /** * @typedef {import('mongodb').EstimatedDocumentCountOptions} EstimatedDocumentCountOptions * @typedef {import('mongodb').CountDocumentsOptions} CountDocumentsOptions diff --git a/lib/MongoQuery.js b/lib/MongoQuery.js index 2314186..58400d7 100644 --- a/lib/MongoQuery.js +++ b/lib/MongoQuery.js @@ -236,7 +236,7 @@ function getSelect(query) { * @template {Document} TSchema */ function getSortOrOrderBy(query) { - const sortStr = query.$orderby ? query.$orderby : query.$sort; + const sortStr = query.$orderBy ? query.$orderBy : query.$sort; if (!sortStr) { return null; } diff --git a/lib/types.ts b/lib/types.ts index 51b4572..d21efb7 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -18,10 +18,10 @@ export interface Query { * $orderBy: "+name,-description,price desc,date asc,index" * } * */ - $orderby?: string; + $orderBy?: string; /** - * $orderby takes priority over $sort, see it for docs - * @alias $orderby + * $orderBy takes priority over $sort, see it for docs + * @alias $orderBy */ $sort?: string; /** From e405304634b1d5634db8a8020796e0ea6fcd4309 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Thu, 13 Jun 2024 14:02:21 +0200 Subject: [PATCH 2/6] adding support for both spellings --- lib/MongoQuery.js | 2 +- lib/types.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/MongoQuery.js b/lib/MongoQuery.js index 58400d7..5cec3a7 100644 --- a/lib/MongoQuery.js +++ b/lib/MongoQuery.js @@ -236,7 +236,7 @@ function getSelect(query) { * @template {Document} TSchema */ function getSortOrOrderBy(query) { - const sortStr = query.$orderBy ? query.$orderBy : query.$sort; + const sortStr = query.$orderBy || query.$orderby || query.$sort; if (!sortStr) { return null; } diff --git a/lib/types.ts b/lib/types.ts index d21efb7..e2f6db7 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -19,6 +19,11 @@ export interface Query { * } * */ $orderBy?: string; + /** + * @deprecated incorrect spelling of $orderBy, will be removed in future + * @alias $orderBy + * */ + $ordery?: string; /** * $orderBy takes priority over $sort, see it for docs * @alias $orderBy From c254e93adc91545410153d90616816ce9b937d19 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Thu, 13 Jun 2024 14:02:36 +0200 Subject: [PATCH 3/6] 2.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a1f0d5e..beac0e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@synatic/mongo-magic", - "version": "2.2.0", + "version": "2.2.1", "description": "Synatic utility classes for interacting with MongoDB", "main": "index.js", "files": [ From 58a5bd68f1c833795dbe2ef04358c8be4cdc17b5 Mon Sep 17 00:00:00 2001 From: Ryan Kotzen Date: Tue, 18 Jun 2024 09:12:52 +0200 Subject: [PATCH 4/6] Revert "fixing case on orderBy" This reverts commit 2a594285edb5979d50e74d549539b7043332adb9. --- lib/Collection.js | 2 +- lib/MongoQuery.js | 2 +- lib/types.ts | 11 +++-------- package.json | 2 +- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/Collection.js b/lib/Collection.js index 3d66a40..9b5cd42 100644 --- a/lib/Collection.js +++ b/lib/Collection.js @@ -6,7 +6,7 @@ const MongoQuery = require('./MongoQuery.js'); const _defaultQueryTimeoutMS = 120000; -// const _specialFields = ['$select', '$limit', '$top', '$filter', '$skip', '$sort', '$orderBy', '$rawQuery', '$aggregate', '$group']; +// const _specialFields = ['$select', '$limit', '$top', '$filter', '$skip', '$sort', '$orderby', '$rawQuery', '$aggregate', '$group']; /** * @typedef {import('mongodb').EstimatedDocumentCountOptions} EstimatedDocumentCountOptions * @typedef {import('mongodb').CountDocumentsOptions} CountDocumentsOptions diff --git a/lib/MongoQuery.js b/lib/MongoQuery.js index 5cec3a7..2314186 100644 --- a/lib/MongoQuery.js +++ b/lib/MongoQuery.js @@ -236,7 +236,7 @@ function getSelect(query) { * @template {Document} TSchema */ function getSortOrOrderBy(query) { - const sortStr = query.$orderBy || query.$orderby || query.$sort; + const sortStr = query.$orderby ? query.$orderby : query.$sort; if (!sortStr) { return null; } diff --git a/lib/types.ts b/lib/types.ts index e2f6db7..51b4572 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -18,15 +18,10 @@ export interface Query { * $orderBy: "+name,-description,price desc,date asc,index" * } * */ - $orderBy?: string; + $orderby?: string; /** - * @deprecated incorrect spelling of $orderBy, will be removed in future - * @alias $orderBy - * */ - $ordery?: string; - /** - * $orderBy takes priority over $sort, see it for docs - * @alias $orderBy + * $orderby takes priority over $sort, see it for docs + * @alias $orderby */ $sort?: string; /** diff --git a/package.json b/package.json index beac0e6..a1f0d5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@synatic/mongo-magic", - "version": "2.2.1", + "version": "2.2.0", "description": "Synatic utility classes for interacting with MongoDB", "main": "index.js", "files": [ From e0a6a9002de27c01108fe0c408f9296047ecae73 Mon Sep 17 00:00:00 2001 From: Thiren Bunsee Date: Tue, 18 Jun 2024 09:45:46 +0200 Subject: [PATCH 5/6] fix: wrapped the mongodb sdk promises in callbackify --- .github/workflows/ci-build.yml | 4 +- .github/workflows/ci-codeql-analysis.yml | 4 -- .github/workflows/ci-npm-publish.yml | 2 +- lib/Collection.js | 62 +++++++++++++----------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index f22e529..1f9a298 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -2,8 +2,6 @@ name: "Build" on: push: - branches: [master, develop] - pull_request: workflow_dispatch: inputs: reason: @@ -19,7 +17,7 @@ jobs: runs-on: ubuntu-latest services: mongo: - image: mongo:6.0 + image: mongo:7.0 options: >- --health-cmd mongosh --health-interval 10s diff --git a/.github/workflows/ci-codeql-analysis.yml b/.github/workflows/ci-codeql-analysis.yml index 21dc055..1256cf9 100644 --- a/.github/workflows/ci-codeql-analysis.yml +++ b/.github/workflows/ci-codeql-analysis.yml @@ -2,10 +2,6 @@ name: "CodeQL Analysis" on: push: - branches: [master, develop] - pull_request: - # The branches below must be a subset of the branches above - branches: [master, develop] workflow_dispatch: inputs: reason: diff --git a/.github/workflows/ci-npm-publish.yml b/.github/workflows/ci-npm-publish.yml index dc51904..47c989d 100644 --- a/.github/workflows/ci-npm-publish.yml +++ b/.github/workflows/ci-npm-publish.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest services: mongo: - image: mongo:6.0 + image: mongo:7.0 options: >- --health-cmd mongosh --health-interval 10s diff --git a/lib/Collection.js b/lib/Collection.js index 9b5cd42..cb4f14b 100644 --- a/lib/Collection.js +++ b/lib/Collection.js @@ -1,5 +1,6 @@ /* eslint-disable valid-jsdoc */ +const {callbackify} = require('node:util'); const $moment = require('moment'); const $check = require('check-types'); const MongoQuery = require('./MongoQuery.js'); @@ -70,16 +71,19 @@ class Collection { } const filter = query.parsedQuery.query || {}; - this._collection - .countDocuments(filter, options) - .then((count) => { - if (!count) { - return callback(null, 0); - } - - return callback(null, count); - }) - .catch(callback); + callbackify(() => { + return this._collection.countDocuments(filter, options); + })((err, count) => { + if (err) { + return callback(err); + } + + if (!count) { + return callback(null, 0); + } + + return callback(null, count); + }); } /** @@ -143,19 +147,18 @@ class Collection { return callback(new Error('Invalid query object')); } try { - const cursor = this.queryAsCursor(query, options); - - cursor - .toArray() - .then((results) => { - if (!results) { - return callback(null, []); - } - return callback(null, results); - }) - .catch((err) => { + callbackify(() => { + return this.queryAsCursor(query, options).toArray(); + })((err, results) => { + if (err) { return callback(err); - }); + } + + if (!results) { + return callback(null, []); + } + return callback(null, results); + }); } catch (exp) { return callback(exp); } @@ -225,12 +228,15 @@ class Collection { update.$inc[dayPath + '.' + increment.field] = increment.value; update.$inc[hourPath + '.' + increment.field] = increment.value; } - this._collection - .updateOne(options.query, update) - .then((result) => { - return callback(null, result); - }) - .catch(callback); + callbackify(() => { + return this._collection.updateOne(options.query, update); + })((err, result) => { + if (err) { + return callback(err); + } + + return callback(null, result); + }); } /** From 4f6f76e4c0845270a8ceef8b1d8872795451ebb2 Mon Sep 17 00:00:00 2001 From: Thiren Bunsee Date: Tue, 18 Jun 2024 09:45:53 +0200 Subject: [PATCH 6/6] 2.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a1f0d5e..ce0755f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@synatic/mongo-magic", - "version": "2.2.0", + "version": "2.3.0", "description": "Synatic utility classes for interacting with MongoDB", "main": "index.js", "files": [