Skip to content

Commit 1470115

Browse files
nbbeekendurran
andauthored
feat(NODE-4950)!: remove bson-ext import (#3523)
Co-authored-by: Durran Jordan <[email protected]>
1 parent fee783c commit 1470115

File tree

11 files changed

+109
-423
lines changed

11 files changed

+109
-423
lines changed

.evergreen/config.in.yml

-15
Original file line numberDiff line numberDiff line change
@@ -832,21 +832,6 @@ functions:
832832
${PREPARE_SHELL}
833833
${PROJECT_DIRECTORY}/.evergreen/run-lambda-aws-tests.sh
834834
835-
"run bson-ext test":
836-
- command: subprocess.exec
837-
type: test
838-
params:
839-
working_dir: "src"
840-
timeout_secs: 60
841-
env:
842-
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
843-
MONGODB_URI: ${MONGODB_URI}
844-
TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT}
845-
binary: bash
846-
args:
847-
- '${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh'
848-
849-
850835
"upload test results":
851836
# Upload the xunit-format test results.
852837
- command: attach.xunit_results

.evergreen/config.yml

-49
Original file line numberDiff line numberDiff line change
@@ -790,19 +790,6 @@ functions:
790790
script: |
791791
${PREPARE_SHELL}
792792
${PROJECT_DIRECTORY}/.evergreen/run-lambda-aws-tests.sh
793-
run bson-ext test:
794-
- command: subprocess.exec
795-
type: test
796-
params:
797-
working_dir: src
798-
timeout_secs: 60
799-
env:
800-
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
801-
MONGODB_URI: ${MONGODB_URI}
802-
TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT}
803-
binary: bash
804-
args:
805-
- ${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh
806793
upload test results:
807794
- command: attach.xunit_results
808795
params:
@@ -2131,40 +2118,6 @@ tasks:
21312118
variant: '*'
21322119
status: '*'
21332120
patch_optional: true
2134-
- name: run-bson-ext-integration
2135-
tags:
2136-
- run-custom-dependency-tests
2137-
commands:
2138-
- func: install dependencies
2139-
vars:
2140-
NODE_LTS_NAME: fermium
2141-
- func: bootstrap mongo-orchestration
2142-
vars:
2143-
VERSION: '5.0'
2144-
TOPOLOGY: server
2145-
AUTH: auth
2146-
- name: run-bson-ext-integration
2147-
func: run bson-ext test
2148-
vars:
2149-
NODE_LTS_NAME: fermium
2150-
TEST_NPM_SCRIPT: check:test
2151-
- name: run-bson-ext-unit
2152-
tags:
2153-
- run-custom-dependency-tests
2154-
commands:
2155-
- func: install dependencies
2156-
vars:
2157-
NODE_LTS_NAME: fermium
2158-
- func: bootstrap mongo-orchestration
2159-
vars:
2160-
VERSION: '5.0'
2161-
TOPOLOGY: server
2162-
AUTH: auth
2163-
- name: run-bson-ext-unit
2164-
func: run bson-ext test
2165-
vars:
2166-
NODE_LTS_NAME: fermium
2167-
TEST_NPM_SCRIPT: check:unit
21682121
- name: run-custom-csfle-tests-5.0-pinned-commit
21692122
tags:
21702123
- run-custom-dependency-tests
@@ -3060,8 +3013,6 @@ buildvariants:
30603013
display_name: Custom Dependency Version Test
30613014
run_on: rhel80-large
30623015
tasks:
3063-
- run-bson-ext-integration
3064-
- run-bson-ext-unit
30653016
- run-custom-csfle-tests-5.0-pinned-commit
30663017
- run-custom-csfle-tests-5.0-master
30673018
- run-custom-csfle-tests-rapid-pinned-commit

.evergreen/generate_evergreen_tasks.js

+1-40
Original file line numberDiff line numberDiff line change
@@ -576,46 +576,7 @@ BUILD_VARIANTS.push({
576576
tasks: AWS_AUTH_TASKS
577577
});
578578

579-
const oneOffFuncs = [
580-
{
581-
name: 'run-bson-ext-integration',
582-
func: 'run bson-ext test',
583-
vars: {
584-
NODE_LTS_NAME: LOWEST_LTS,
585-
TEST_NPM_SCRIPT: 'check:test'
586-
}
587-
},
588-
{
589-
name: 'run-bson-ext-unit',
590-
func: 'run bson-ext test',
591-
vars: {
592-
NODE_LTS_NAME: LOWEST_LTS,
593-
TEST_NPM_SCRIPT: 'check:unit'
594-
}
595-
}
596-
];
597-
598-
const oneOffFuncAsTasks = oneOffFuncs.map(oneOffFunc => ({
599-
name: oneOffFunc.name,
600-
tags: ['run-custom-dependency-tests'],
601-
commands: [
602-
{
603-
func: 'install dependencies',
604-
vars: {
605-
NODE_LTS_NAME: LOWEST_LTS
606-
}
607-
},
608-
{
609-
func: 'bootstrap mongo-orchestration',
610-
vars: {
611-
VERSION: '5.0',
612-
TOPOLOGY: 'server',
613-
AUTH: 'auth'
614-
}
615-
},
616-
oneOffFunc
617-
]
618-
}));
579+
const oneOffFuncAsTasks = []
619580

620581
for (const version of ['5.0', 'rapid', 'latest']) {
621582
for (const ref of ['ddb19ae22dc4a5f8b9208096f69fc23e19bae6c9', 'master']) {

.evergreen/run-bson-ext-test.sh

-32
This file was deleted.

README.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,24 @@ If you are a Typescript user, you will need the Node.js type definitions to use
7171
npm install -D @types/node
7272
```
7373

74-
## Troubleshooting
74+
## Driver Extensions
7575

76-
The MongoDB driver depends on several other packages. These are:
76+
The MongoDB driver can optionally be enhanced by the following feature packages:
7777

78-
- [bson](https://github.com/mongodb/js-bson)
79-
- [bson-ext](https://github.com/mongodb-js/bson-ext)
80-
- [kerberos](https://github.com/mongodb-js/kerberos)
81-
- [mongodb-client-encryption](https://github.com/mongodb/libmongocrypt#readme)
78+
Maintained by MongoDB:
79+
80+
- Zstd network compression - [@mongodb-js/zstd](https://github.com/mongodb-js/zstd)
81+
- MongoDB field level and queryable encryption - [mongodb-client-encryption](https://github.com/mongodb/libmongocrypt#readme)
82+
- GSSAPI / SSPI / Kerberos authentication - [kerberos](https://github.com/mongodb-js/kerberos)
83+
84+
Some of these packages include native C++ extensions.
85+
Consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/native-extensions.md) if you run into compilation issues.
86+
87+
Third party:
88+
89+
- Snappy network compression - [snappy](https://github.com/Brooooooklyn/snappy)
90+
- AWS authentication - [@aws-sdk/credential-providers](https://github.com/aws/aws-sdk-js-v3/tree/main/packages/credential-providers)
8291

83-
Some of these packages include native C++ extensions. Consult the [trouble shooting guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/native-extensions.md) if you run into issues.
8492

8593
## Quick Start
8694

etc/notes/CHANGES_5.0.0.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,13 @@ await collection.insertMany([{ name: 'fido' }, { name: 'luna' }])
192192
The `keepGoing` option was a legacy name for setting `ordered` to `false` for bulk inserts.
193193
It was only supported by the legacy `collection.insert()` method which is now removed as noted above.
194194

195+
### `bson-ext` support removed
196+
197+
The `bson-ext` package will no longer automatically import and supplant the `bson` dependency.
198+
195199
### `BulkWriteResult` no longer contains a publicly enumerable `result` property.
196200

197-
To access the raw result, please use `bulkWriteResult.getRawResponse()`.
201+
To access the raw result, please use `bulkWriteResult.getRawResponse()`.
198202

199203
### `BulkWriteResult` now contains individual ressult properties.
200204

src/bson.ts

+8-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
1-
import type {
2-
calculateObjectSize as calculateObjectSizeFn,
3-
deserialize as deserializeFn,
4-
DeserializeOptions,
5-
serialize as serializeFn,
6-
SerializeOptions
7-
} from 'bson';
8-
9-
/** @internal */
10-
// eslint-disable-next-line @typescript-eslint/no-var-requires
11-
let BSON = require('bson');
12-
13-
try {
14-
// Ensure you always wrap an optional require in the try block NODE-3199
15-
BSON = require('bson-ext');
16-
} catch {} // eslint-disable-line
17-
18-
/** @internal */
19-
export const deserialize = BSON.deserialize as typeof deserializeFn;
20-
/** @internal */
21-
export const serialize = BSON.serialize as typeof serializeFn;
22-
/** @internal */
23-
export const calculateObjectSize = BSON.calculateObjectSize as typeof calculateObjectSizeFn;
1+
import type { DeserializeOptions, SerializeOptions } from 'bson';
242

253
export {
264
Binary,
275
BSONRegExp,
286
BSONSymbol,
7+
calculateObjectSize,
298
Code,
309
DBRef,
3110
Decimal128,
11+
deserialize,
3212
Document,
3313
Double,
3414
Int32,
@@ -37,10 +17,15 @@ export {
3717
MaxKey,
3818
MinKey,
3919
ObjectId,
20+
serialize,
4021
Timestamp
4122
} from 'bson';
4223

24+
// TODO(NODE-4867): fix with bson v5
4325
/** @internal */
26+
// eslint-disable-next-line @typescript-eslint/no-var-requires
27+
const BSON = require('bson');
28+
4429
export { BSON };
4530

4631
/**

test/benchmarks/driverBench/index.js

-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ let bsonType = 'js-bson';
88
// TODO(NODE-4606): test against different driver configurations in CI
99

1010
const BSON = require('bson');
11-
// try {
12-
// BSON = require('bson-ext');
13-
// bsonType = 'bson-ext';
14-
// } catch (_) {
15-
// // do not care
16-
// }
1711

1812
const { inspect } = require('util');
1913
const { writeFile } = require('fs/promises');

test/tools/utils.ts

-7
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,6 @@ export class UnifiedTestSuiteBuilder {
507507
}
508508
}
509509

510-
/** Test whether the driver is using bson-ext */
511-
export function isBSONExtImported() {
512-
// eslint-disable-next-line @typescript-eslint/no-var-requires
513-
const driverBSON = require('../mongodb');
514-
return driverBSON.deserialize.toString().includes('[native code]');
515-
}
516-
517510
export const byStrings = (a: any, b: any) => {
518511
const res = `${a}`.localeCompare(`${b}`);
519512
return res < 0 ? -1 : res > 0 ? 1 : 0;

test/unit/bson.test.js

+13-48
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const { expect } = require('chai');
44
const BSON = require('../mongodb');
5-
const { isBSONExtImported } = require('../tools/utils');
65

76
describe('When importing BSON', function () {
87
const types = [
@@ -27,56 +26,22 @@ describe('When importing BSON', function () {
2726
bsonRegExp: true
2827
};
2928

30-
function testTypes() {
31-
for (const [type, ctorArg] of types) {
32-
it(`should correctly round trip ${type}`, function () {
33-
const typeCtor = BSON[type];
34-
expect(typeCtor).to.be.a('function');
35-
const doc = { key: new typeCtor(ctorArg) };
36-
const outputDoc = BSON.deserialize(BSON.serialize(doc), options);
37-
expect(outputDoc).to.have.property('key').that.is.instanceOf(typeCtor);
38-
expect(outputDoc).to.deep.equal(doc);
39-
});
40-
}
41-
42-
it('should correctly round trip Map', function () {
43-
expect(BSON.Map).to.be.a('function');
44-
const doc = { key: new BSON.Map([['2', 2]]) };
45-
const outputDoc = BSON.deserialize(BSON.serialize(doc));
46-
expect(outputDoc).to.have.nested.property('key.2', 2);
29+
for (const [type, ctorArg] of types) {
30+
it(`should correctly round trip ${type}`, function () {
31+
const typeCtor = BSON[type];
32+
expect(typeCtor).to.be.a('function');
33+
const doc = { key: new typeCtor(ctorArg) };
34+
const outputDoc = BSON.deserialize(BSON.serialize(doc), options);
35+
expect(outputDoc).to.have.property('key').that.is.instanceOf(typeCtor);
36+
expect(outputDoc).to.deep.equal(doc);
4737
});
4838
}
4939

50-
describe('bson-ext', function () {
51-
before(function () {
52-
if (!isBSONExtImported()) {
53-
this.skip();
54-
}
55-
});
56-
57-
it('should be imported if it exists', function () {
58-
expect(BSON.deserialize.toString()).to.include('[native code]');
59-
expect(BSON.serialize.toString()).to.include('[native code]');
60-
expect(BSON.calculateObjectSize.toString()).to.include('[native code]');
61-
});
62-
63-
testTypes();
64-
});
65-
66-
describe('js-bson', function () {
67-
before(function () {
68-
if (isBSONExtImported()) {
69-
this.skip();
70-
}
71-
});
72-
73-
it('should be imported by default', function () {
74-
expect(BSON.deserialize.toString()).to.not.include('[native code]');
75-
expect(BSON.serialize.toString()).to.not.include('[native code]');
76-
expect(BSON.calculateObjectSize.toString()).to.not.include('[native code]');
77-
});
78-
79-
testTypes();
40+
it('should correctly round trip Map', function () {
41+
expect(BSON.Map).to.be.a('function');
42+
const doc = { key: new BSON.Map([['2', 2]]) };
43+
const outputDoc = BSON.deserialize(BSON.serialize(doc));
44+
expect(outputDoc).to.have.nested.property('key.2', 2);
8045
});
8146
});
8247

0 commit comments

Comments
 (0)