From 37d1fb03eb758fd853368690ff3c9e8b6115fc08 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Mar 2021 06:43:53 +0000 Subject: [PATCH 1/8] Bump eslint-config-prettier from 7.2.0 to 8.1.0 Bumps [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) from 7.2.0 to 8.1.0. - [Release notes](https://github.com/prettier/eslint-config-prettier/releases) - [Changelog](https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/eslint-config-prettier/compare/v7.2.0...v8.1.0) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3a63e4b..8b80e9e 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "clone-deep": "^4.0.1", "eslint": "^7.16.0", "eslint-config-google": "^0.14.0", - "eslint-config-prettier": "^7.1.0", + "eslint-config-prettier": "^8.1.0", "mocha": "^8.2.1", "nyc": "^15.1.0", "prettier": "^2.2.1" From 24f36a88a3de986e0818fe06161bb434a0fcff13 Mon Sep 17 00:00:00 2001 From: simonebeets Date: Thu, 17 Jun 2021 21:24:13 +0200 Subject: [PATCH 2/8] feat(serialize EJSON) [1200308109557680]: add option for EJSON serialization when querying as a stream --- lib/Collection.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Collection.js b/lib/Collection.js index 0020697..ceb9fb8 100644 --- a/lib/Collection.js +++ b/lib/Collection.js @@ -83,9 +83,13 @@ class Collection { } } - queryAsStream(query) { + queryAsStream(query, serializeOption) { if (!$check.instanceStrict(query, MongoQuery)) throw new Error('Invalid query object'); const cur = this.queryAsCursor(query); + + if(serializeOption === 'EJSON') + return cur.stream({transform: x => EJSON.serialize(x, {})}); + return cur.stream(); } From 8cd1dac9f0ff9a244e294b8ffefaf6ebc6bf4026 Mon Sep 17 00:00:00 2001 From: simonebeets Date: Thu, 17 Jun 2021 21:48:50 +0200 Subject: [PATCH 3/8] feat(tests) [1200308109557680]: added missing reference to EJSON --- lib/Collection.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Collection.js b/lib/Collection.js index ceb9fb8..ef5c915 100644 --- a/lib/Collection.js +++ b/lib/Collection.js @@ -2,6 +2,7 @@ const $moment = require('moment'); const _s = require('underscore.string'); const $check = require('check-types'); const MongoQuery = require('./MongoQuery.js'); +const {EJSON} = require('bson'); const _defaultQueryTimeoutMS = 120000; // const _specialFields = ['$select', '$limit', '$top', '$filter', '$skip', '$sort', '$orderby', '$rawQuery', '$aggregate', '$group']; From f2a96c29ed34f93c565d72a461d1b5af3afa3fa9 Mon Sep 17 00:00:00 2001 From: simonebeets Date: Fri, 18 Jun 2021 09:22:18 +0200 Subject: [PATCH 4/8] feat(serialize JSON): update options and added test --- lib/Collection.js | 8 ++------ package.json | 1 + test/02. Collection.js | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/Collection.js b/lib/Collection.js index ef5c915..449ca3d 100644 --- a/lib/Collection.js +++ b/lib/Collection.js @@ -2,7 +2,6 @@ const $moment = require('moment'); const _s = require('underscore.string'); const $check = require('check-types'); const MongoQuery = require('./MongoQuery.js'); -const {EJSON} = require('bson'); const _defaultQueryTimeoutMS = 120000; // const _specialFields = ['$select', '$limit', '$top', '$filter', '$skip', '$sort', '$orderby', '$rawQuery', '$aggregate', '$group']; @@ -84,14 +83,11 @@ class Collection { } } - queryAsStream(query, serializeOption) { + queryAsStream(query, options = {}) { if (!$check.instanceStrict(query, MongoQuery)) throw new Error('Invalid query object'); const cur = this.queryAsCursor(query); - if(serializeOption === 'EJSON') - return cur.stream({transform: x => EJSON.serialize(x, {})}); - - return cur.stream(); + return cur.stream(options); } updateStats(options, callback) { diff --git a/package.json b/package.json index 8b80e9e..e22179f 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "node": ">=12" }, "dependencies": { + "bson": "^4.4.0", "check-types": "11.1.2", "deepmerge": "4.2.2", "moment": "2.29.1", diff --git a/test/02. Collection.js b/test/02. Collection.js index 90f6592..47b12ef 100644 --- a/test/02. Collection.js +++ b/test/02. Collection.js @@ -6,6 +6,7 @@ const _s = require('underscore.string'); const {MongoClient} = require('mongodb'); const Collection = require('../lib').Collection; const MongoQuery = require('../lib').MongoQuery; +const {EJSON} = require('bson'); const config = { databaseName: 'mongo-magic-tests', @@ -128,6 +129,24 @@ describe('Collection', function () { const mQuery = new MongoQuery({limit: 1000}); collection.queryAsStream(mQuery).pipe(ws); }); + + it('should stream and transform results', function (done) { + const collection = new Collection(_db.collection('testquery')); + const ws = new stream.Writable({objectMode: true}); + let writeCnt = 0; + ws._write = function (chunk, encoding, done) { + writeCnt++; + return done(); + }; + + ws.on('finish', function () { + assert.strictEqual(writeCnt, 2, 'Invalid writes'); + return done(); + }); + + const mQuery = new MongoQuery({limit: 1000}); + collection.queryAsStream(mQuery, {transform: x => EJSON.serialize(x, {})}).pipe(ws); + }); }); describe('Stats', function () { From c094c4aba3f27bac778b10e1965918387614fb44 Mon Sep 17 00:00:00 2001 From: simonebeets Date: Fri, 18 Jun 2021 09:27:47 +0200 Subject: [PATCH 5/8] 0.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e22179f..10936a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@synatic/mongo-magic", - "version": "0.3.0", + "version": "0.4.0", "description": "mongo magic utils", "main": "index.js", "files": [ From d09ce1b505117b9a49f979a395f51753ab9441b1 Mon Sep 17 00:00:00 2001 From: simonebeets Date: Fri, 18 Jun 2021 09:32:10 +0200 Subject: [PATCH 6/8] [revert] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 10936a0..e22179f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@synatic/mongo-magic", - "version": "0.4.0", + "version": "0.3.0", "description": "mongo magic utils", "main": "index.js", "files": [ From 998d435655f9093f042349513ee7588940e70d48 Mon Sep 17 00:00:00 2001 From: simonebeets Date: Fri, 18 Jun 2021 09:32:39 +0200 Subject: [PATCH 7/8] 0.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e22179f..27a490e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@synatic/mongo-magic", - "version": "0.3.0", + "version": "0.3.1", "description": "mongo magic utils", "main": "index.js", "files": [ From 6b0c35566fc9a040d585616698b5154049babdf7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Jun 2021 06:04:07 +0000 Subject: [PATCH 8/8] Bump mocha from 8.4.0 to 9.0.0 Bumps [mocha](https://github.com/mochajs/mocha) from 8.4.0 to 9.0.0. - [Release notes](https://github.com/mochajs/mocha/releases) - [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md) - [Commits](https://github.com/mochajs/mocha/compare/v8.4.0...v9.0.0) --- updated-dependencies: - dependency-name: mocha dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 27a490e..f1c1493 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "eslint": "^7.16.0", "eslint-config-google": "^0.14.0", "eslint-config-prettier": "^8.1.0", - "mocha": "^8.2.1", + "mocha": "^9.0.0", "nyc": "^15.1.0", "prettier": "^2.2.1" }