From ff47debc664bd075b7831a04b0c7e47c0ea347f7 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 30 Aug 2021 15:40:23 -0400 Subject: [PATCH 1/5] fix(NODE-3574): reintroduce ObjectID export --- package-lock.json | 48 ++++++++++++++++++++++-------------- src/index.ts | 7 ++++++ test/types/mongodb.test-d.ts | 5 +++- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index a58544dc303..a2a3ee76490 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9719,6 +9719,16 @@ "semver": "^7.3.2", "shelljs": "^0.8.3", "typescript": "^4.1.0-dev.20201026" + }, + "dependencies": { + "semver": { + "version": "7.3.5", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + } } }, "electron-to-chromium": { @@ -10429,12 +10439,6 @@ "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", "dev": true }, - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", - "dev": true - }, "string_decoder": { "version": "1.1.1", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", @@ -11812,6 +11816,14 @@ "is-core-module": "^2.2.0", "path-parse": "^1.0.6" } + }, + "semver": { + "version": "7.3.5", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } } } }, @@ -12361,12 +12373,6 @@ "version": "3.0.0", "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", "dev": true - }, - "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", - "dev": true } } }, @@ -12555,13 +12561,9 @@ "dev": true }, "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } + "version": "5.7.1", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true }, "set-blocking": { "version": "2.0.0", @@ -12876,6 +12878,14 @@ "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true }, + "semver": { + "version": "7.3.5", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, "supports-color": { "version": "5.5.0", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", diff --git a/src/index.ts b/src/index.ts index ad62dff5a45..4a80f643bdd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,6 +29,13 @@ export { Map } from './bson'; +import { ObjectId } from 'bson'; +/** + * @public + * @deprecated Please use `ObjectId` + */ +export const ObjectID = ObjectId; + export { MongoError, MongoServerError, diff --git a/test/types/mongodb.test-d.ts b/test/types/mongodb.test-d.ts index bd16ce67950..54f857b668b 100644 --- a/test/types/mongodb.test-d.ts +++ b/test/types/mongodb.test-d.ts @@ -1,4 +1,4 @@ -import { expectType, expectDeprecated, expectError } from 'tsd'; +import { expectType, expectDeprecated, expectNotDeprecated, expectError } from 'tsd'; import { MongoClient } from '../../src/mongo_client'; import { Collection } from '../../src/collection'; import { AggregationCursor } from '../../src/cursor/aggregation_cursor'; @@ -6,6 +6,7 @@ import type { FindCursor } from '../../src/cursor/find_cursor'; import type { Document } from 'bson'; import { Db } from '../../src'; import { Topology } from '../../src/sdam/topology'; +import { ObjectId, ObjectID } from '../../src'; // We wish to keep these APIs but continue to ensure they are marked as deprecated. expectDeprecated(Collection.prototype.insert); @@ -15,6 +16,8 @@ expectDeprecated(Collection.prototype.count); expectDeprecated(AggregationCursor.prototype.geoNear); expectDeprecated(Topology.prototype.unref); expectDeprecated(Db.prototype.unref); +expectDeprecated(ObjectID); +expectNotDeprecated(ObjectId); // test mapped cursor types const client = new MongoClient(''); From c49f176300fa1e4f616b190d56ee581a805d4aad Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 30 Aug 2021 17:13:52 -0400 Subject: [PATCH 2/5] test: assert both ObjectId spellings exist --- test/types/mongodb.test-d.ts | 4 ++-- test/unit/bson_import.test.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/types/mongodb.test-d.ts b/test/types/mongodb.test-d.ts index 54f857b668b..32b83366050 100644 --- a/test/types/mongodb.test-d.ts +++ b/test/types/mongodb.test-d.ts @@ -6,7 +6,7 @@ import type { FindCursor } from '../../src/cursor/find_cursor'; import type { Document } from 'bson'; import { Db } from '../../src'; import { Topology } from '../../src/sdam/topology'; -import { ObjectId, ObjectID } from '../../src'; +import { ObjectId } from '../../src'; // We wish to keep these APIs but continue to ensure they are marked as deprecated. expectDeprecated(Collection.prototype.insert); @@ -16,7 +16,7 @@ expectDeprecated(Collection.prototype.count); expectDeprecated(AggregationCursor.prototype.geoNear); expectDeprecated(Topology.prototype.unref); expectDeprecated(Db.prototype.unref); -expectDeprecated(ObjectID); +// expectDeprecated(ObjectID); // not sure why tsd can't assert the deprecation expectNotDeprecated(ObjectId); // test mapped cursor types diff --git a/test/unit/bson_import.test.js b/test/unit/bson_import.test.js index 28b3922b7da..7951ab28192 100644 --- a/test/unit/bson_import.test.js +++ b/test/unit/bson_import.test.js @@ -87,3 +87,13 @@ describe('When importing BSON', function () { testTypes(); }); }); + +describe('MongoDB export', () => { + const mongodb = require('../../src'); + it('should include ObjectId', () => + expect(mongodb).to.have.property('ObjectId').that.is.a('function')); + it('should include ObjectID', () => + expect(mongodb).to.have.property('ObjectID').that.is.a('function')); + it('should have ObjectID and ObjectId equal each other', () => + expect(mongodb.ObjectId).to.deep.equal(mongodb.ObjectID)); +}); From b3978aeedc88d4119b37165b7943e8bd00ed62c7 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 1 Sep 2021 11:44:54 -0400 Subject: [PATCH 3/5] test: assert deprecation on ObjectID --- test/types/mongodb.test-d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/types/mongodb.test-d.ts b/test/types/mongodb.test-d.ts index 32b83366050..3ec4f79db58 100644 --- a/test/types/mongodb.test-d.ts +++ b/test/types/mongodb.test-d.ts @@ -6,7 +6,7 @@ import type { FindCursor } from '../../src/cursor/find_cursor'; import type { Document } from 'bson'; import { Db } from '../../src'; import { Topology } from '../../src/sdam/topology'; -import { ObjectId } from '../../src'; +import * as MongoDBDriver from '../../src'; // We wish to keep these APIs but continue to ensure they are marked as deprecated. expectDeprecated(Collection.prototype.insert); @@ -16,8 +16,8 @@ expectDeprecated(Collection.prototype.count); expectDeprecated(AggregationCursor.prototype.geoNear); expectDeprecated(Topology.prototype.unref); expectDeprecated(Db.prototype.unref); -// expectDeprecated(ObjectID); // not sure why tsd can't assert the deprecation -expectNotDeprecated(ObjectId); +expectDeprecated(MongoDBDriver.ObjectID); +expectNotDeprecated(MongoDBDriver.ObjectId); // test mapped cursor types const client = new MongoClient(''); From 80da1e375acbd55d46e93030c7cdad78b74e5fb2 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 7 Sep 2021 16:47:14 -0400 Subject: [PATCH 4/5] chore: fix lock file --- package-lock.json | 48 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index a2a3ee76490..a58544dc303 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9719,16 +9719,6 @@ "semver": "^7.3.2", "shelljs": "^0.8.3", "typescript": "^4.1.0-dev.20201026" - }, - "dependencies": { - "semver": { - "version": "7.3.5", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - } } }, "electron-to-chromium": { @@ -10439,6 +10429,12 @@ "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", "dev": true }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + }, "string_decoder": { "version": "1.1.1", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", @@ -11816,14 +11812,6 @@ "is-core-module": "^2.2.0", "path-parse": "^1.0.6" } - }, - "semver": { - "version": "7.3.5", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } } } }, @@ -12373,6 +12361,12 @@ "version": "3.0.0", "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", "dev": true + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true } } }, @@ -12561,9 +12555,13 @@ "dev": true }, "semver": { - "version": "5.7.1", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", - "dev": true + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } }, "set-blocking": { "version": "2.0.0", @@ -12878,14 +12876,6 @@ "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true }, - "semver": { - "version": "7.3.5", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", - "dev": true, - "requires": { - "lru-cache": "^6.0.0" - } - }, "supports-color": { "version": "5.5.0", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", From 8c2792cea9a7b7c7e0b2486b64bc2f63806fb0b4 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 7 Sep 2021 16:49:07 -0400 Subject: [PATCH 5/5] chore: check reference equality --- test/unit/bson_import.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/bson_import.test.js b/test/unit/bson_import.test.js index 7951ab28192..e55c708d57e 100644 --- a/test/unit/bson_import.test.js +++ b/test/unit/bson_import.test.js @@ -95,5 +95,5 @@ describe('MongoDB export', () => { it('should include ObjectID', () => expect(mongodb).to.have.property('ObjectID').that.is.a('function')); it('should have ObjectID and ObjectId equal each other', () => - expect(mongodb.ObjectId).to.deep.equal(mongodb.ObjectID)); + expect(mongodb.ObjectId).to.equal(mongodb.ObjectID)); });