Skip to content

feat(NODE-4950)!: remove bson-ext import #3523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .evergreen/config.in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -832,21 +832,6 @@ functions:
${PREPARE_SHELL}
${PROJECT_DIRECTORY}/.evergreen/run-lambda-aws-tests.sh

"run bson-ext test":
- command: subprocess.exec
type: test
params:
working_dir: "src"
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
MONGODB_URI: ${MONGODB_URI}
TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT}
binary: bash
args:
- '${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh'


"upload test results":
# Upload the xunit-format test results.
- command: attach.xunit_results
Expand Down
49 changes: 0 additions & 49 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -790,19 +790,6 @@ functions:
script: |
${PREPARE_SHELL}
${PROJECT_DIRECTORY}/.evergreen/run-lambda-aws-tests.sh
run bson-ext test:
- command: subprocess.exec
type: test
params:
working_dir: src
timeout_secs: 60
env:
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
MONGODB_URI: ${MONGODB_URI}
TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT}
binary: bash
args:
- ${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh
upload test results:
- command: attach.xunit_results
params:
Expand Down Expand Up @@ -2131,40 +2118,6 @@ tasks:
variant: '*'
status: '*'
patch_optional: true
- name: run-bson-ext-integration
tags:
- run-custom-dependency-tests
commands:
- func: install dependencies
vars:
NODE_LTS_NAME: fermium
- func: bootstrap mongo-orchestration
vars:
VERSION: '5.0'
TOPOLOGY: server
AUTH: auth
- name: run-bson-ext-integration
func: run bson-ext test
vars:
NODE_LTS_NAME: fermium
TEST_NPM_SCRIPT: check:test
- name: run-bson-ext-unit
tags:
- run-custom-dependency-tests
commands:
- func: install dependencies
vars:
NODE_LTS_NAME: fermium
- func: bootstrap mongo-orchestration
vars:
VERSION: '5.0'
TOPOLOGY: server
AUTH: auth
- name: run-bson-ext-unit
func: run bson-ext test
vars:
NODE_LTS_NAME: fermium
TEST_NPM_SCRIPT: check:unit
- name: run-custom-csfle-tests-5.0-pinned-commit
tags:
- run-custom-dependency-tests
Expand Down Expand Up @@ -3060,8 +3013,6 @@ buildvariants:
display_name: Custom Dependency Version Test
run_on: rhel80-large
tasks:
- run-bson-ext-integration
- run-bson-ext-unit
- run-custom-csfle-tests-5.0-pinned-commit
- run-custom-csfle-tests-5.0-master
- run-custom-csfle-tests-rapid-pinned-commit
Expand Down
41 changes: 1 addition & 40 deletions .evergreen/generate_evergreen_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,46 +576,7 @@ BUILD_VARIANTS.push({
tasks: AWS_AUTH_TASKS
});

const oneOffFuncs = [
{
name: 'run-bson-ext-integration',
func: 'run bson-ext test',
vars: {
NODE_LTS_NAME: LOWEST_LTS,
TEST_NPM_SCRIPT: 'check:test'
}
},
{
name: 'run-bson-ext-unit',
func: 'run bson-ext test',
vars: {
NODE_LTS_NAME: LOWEST_LTS,
TEST_NPM_SCRIPT: 'check:unit'
}
}
];

const oneOffFuncAsTasks = oneOffFuncs.map(oneOffFunc => ({
name: oneOffFunc.name,
tags: ['run-custom-dependency-tests'],
commands: [
{
func: 'install dependencies',
vars: {
NODE_LTS_NAME: LOWEST_LTS
}
},
{
func: 'bootstrap mongo-orchestration',
vars: {
VERSION: '5.0',
TOPOLOGY: 'server',
AUTH: 'auth'
}
},
oneOffFunc
]
}));
const oneOffFuncAsTasks = []

for (const version of ['5.0', 'rapid', 'latest']) {
for (const ref of ['ddb19ae22dc4a5f8b9208096f69fc23e19bae6c9', 'master']) {
Expand Down
32 changes: 0 additions & 32 deletions .evergreen/run-bson-ext-test.sh

This file was deleted.

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ npm install -D @types/node

## Troubleshooting

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

- [bson](https://github.com/mongodb/js-bson)
- [bson-ext](https://github.com/mongodb-js/bson-ext)
- [kerberos](https://github.com/mongodb-js/kerberos)
- [mongodb-client-encryption](https://github.com/mongodb/libmongocrypt#readme)
- [Zstd network compression](https://github.com/mongodb-js/zstd)
- [Snappy network compression](https://github.com/Brooooooklyn/snappy)
- [GSSAPI / SSPI / Kerberos authentication](https://github.com/mongodb-js/kerberos)
- [AWS authentication](https://github.com/aws/aws-sdk-js-v3/tree/main/packages/credential-providers)
- [MongoDB field level and queryable encryption](https://github.com/mongodb/libmongocrypt#readme)

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.

Expand Down
6 changes: 5 additions & 1 deletion etc/notes/CHANGES_5.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,13 @@ await collection.insertMany([{ name: 'fido' }, { name: 'luna' }])
The `keepGoing` option was a legacy name for setting `ordered` to `false` for bulk inserts.
It was only supported by the legacy `collection.insert()` method which is now removed as noted above.

### `bson-ext` support removed

The `bson-ext` package will no longer automatically import and supplant the `bson` dependency.

### `BulkWriteResult` no longer contains a publicly enumerable `result` property.

To access the raw result, please use `bulkWriteResult.getRawResponse()`.
To access the raw result, please use `bulkWriteResult.getRawResponse()`.

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

Expand Down
31 changes: 8 additions & 23 deletions src/bson.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
import type {
calculateObjectSize as calculateObjectSizeFn,
deserialize as deserializeFn,
DeserializeOptions,
serialize as serializeFn,
SerializeOptions
} from 'bson';

/** @internal */
// eslint-disable-next-line @typescript-eslint/no-var-requires
let BSON = require('bson');

try {
// Ensure you always wrap an optional require in the try block NODE-3199
BSON = require('bson-ext');
} catch {} // eslint-disable-line

/** @internal */
export const deserialize = BSON.deserialize as typeof deserializeFn;
/** @internal */
export const serialize = BSON.serialize as typeof serializeFn;
/** @internal */
export const calculateObjectSize = BSON.calculateObjectSize as typeof calculateObjectSizeFn;
import type { DeserializeOptions, SerializeOptions } from 'bson';

export {
Binary,
BSONRegExp,
BSONSymbol,
calculateObjectSize,
Code,
DBRef,
Decimal128,
deserialize,
Document,
Double,
Int32,
Expand All @@ -37,10 +17,15 @@ export {
MaxKey,
MinKey,
ObjectId,
serialize,
Timestamp
} from 'bson';

// TODO(NODE-4867): fix with bson v5
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-var-requires
const BSON = require('bson');

export { BSON };

/**
Expand Down
6 changes: 0 additions & 6 deletions test/benchmarks/driverBench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ let bsonType = 'js-bson';
// TODO(NODE-4606): test against different driver configurations in CI

const BSON = require('bson');
// try {
// BSON = require('bson-ext');
// bsonType = 'bson-ext';
// } catch (_) {
// // do not care
// }

const { inspect } = require('util');
const { writeFile } = require('fs/promises');
Expand Down
7 changes: 0 additions & 7 deletions test/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,6 @@ export class UnifiedTestSuiteBuilder {
}
}

/** Test whether the driver is using bson-ext */
export function isBSONExtImported() {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const driverBSON = require('../mongodb');
return driverBSON.deserialize.toString().includes('[native code]');
}

export const byStrings = (a: any, b: any) => {
const res = `${a}`.localeCompare(`${b}`);
return res < 0 ? -1 : res > 0 ? 1 : 0;
Expand Down
61 changes: 13 additions & 48 deletions test/unit/bson.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { expect } = require('chai');
const BSON = require('../mongodb');
const { isBSONExtImported } = require('../tools/utils');

describe('When importing BSON', function () {
const types = [
Expand All @@ -27,56 +26,22 @@ describe('When importing BSON', function () {
bsonRegExp: true
};

function testTypes() {
for (const [type, ctorArg] of types) {
it(`should correctly round trip ${type}`, function () {
const typeCtor = BSON[type];
expect(typeCtor).to.be.a('function');
const doc = { key: new typeCtor(ctorArg) };
const outputDoc = BSON.deserialize(BSON.serialize(doc), options);
expect(outputDoc).to.have.property('key').that.is.instanceOf(typeCtor);
expect(outputDoc).to.deep.equal(doc);
});
}

it('should correctly round trip Map', function () {
expect(BSON.Map).to.be.a('function');
const doc = { key: new BSON.Map([['2', 2]]) };
const outputDoc = BSON.deserialize(BSON.serialize(doc));
expect(outputDoc).to.have.nested.property('key.2', 2);
for (const [type, ctorArg] of types) {
it(`should correctly round trip ${type}`, function () {
const typeCtor = BSON[type];
expect(typeCtor).to.be.a('function');
const doc = { key: new typeCtor(ctorArg) };
const outputDoc = BSON.deserialize(BSON.serialize(doc), options);
expect(outputDoc).to.have.property('key').that.is.instanceOf(typeCtor);
expect(outputDoc).to.deep.equal(doc);
});
}

describe('bson-ext', function () {
before(function () {
if (!isBSONExtImported()) {
this.skip();
}
});

it('should be imported if it exists', function () {
expect(BSON.deserialize.toString()).to.include('[native code]');
expect(BSON.serialize.toString()).to.include('[native code]');
expect(BSON.calculateObjectSize.toString()).to.include('[native code]');
});

testTypes();
});

describe('js-bson', function () {
before(function () {
if (isBSONExtImported()) {
this.skip();
}
});

it('should be imported by default', function () {
expect(BSON.deserialize.toString()).to.not.include('[native code]');
expect(BSON.serialize.toString()).to.not.include('[native code]');
expect(BSON.calculateObjectSize.toString()).to.not.include('[native code]');
});

testTypes();
it('should correctly round trip Map', function () {
expect(BSON.Map).to.be.a('function');
const doc = { key: new BSON.Map([['2', 2]]) };
const outputDoc = BSON.deserialize(BSON.serialize(doc));
expect(outputDoc).to.have.nested.property('key.2', 2);
});
});

Expand Down
Loading