Skip to content

Commit 3dae6da

Browse files
feat(NODE-4751)!: drop support for client encryption < 2.3.0 (#3521)
1 parent 14427d1 commit 3dae6da

File tree

6 files changed

+11
-36
lines changed

6 files changed

+11
-36
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@
3434
},
3535
"peerDependencies": {
3636
"@aws-sdk/credential-providers": "^3.201.0",
37-
"snappy": "7.x.x"
37+
"snappy": "7.x.x",
38+
"mongodb-client-encryption": "^2.3.0"
3839
},
3940
"peerDependenciesMeta": {
4041
"@aws-sdk/credential-providers": {
4142
"optional": true
4243
},
4344
"snappy": {
4445
"optional": true
46+
},
47+
"mongodb-client-encryption": {
48+
"optional": true
4549
}
4650
},
4751
"devDependencies": {

src/collection.ts

-7
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ import {
8686
Callback,
8787
checkCollectionName,
8888
DEFAULT_PK_FACTORY,
89-
emitWarningOnce,
9089
MongoDBNamespace,
9190
normalizeHintField,
9291
resolveOptions
@@ -283,12 +282,6 @@ export class Collection<TSchema extends Document = Document> {
283282
options = {};
284283
}
285284

286-
// versions of mongodb-client-encryption before v1.2.6 pass in hardcoded { w: 'majority' }
287-
// specifically to an insertOne call in createDataKey, so we want to support this only here
288-
if (options && Reflect.get(options, 'w')) {
289-
options.writeConcern = WriteConcern.fromOptions(Reflect.get(options, 'w'));
290-
}
291-
292285
return executeOperation(
293286
this.s.db.s.client,
294287
new InsertOneOperation(

src/deps.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
2-
import type { deserialize, Document, serialize } from './bson';
2+
import type { Document } from './bson';
33
import type { AWSCredentials } from './cmap/auth/mongodb_aws';
44
import type { ProxyOptions } from './cmap/connection';
55
import { MongoMissingDependencyError } from './error';
@@ -214,8 +214,6 @@ export interface AutoEncryptionTlsOptions {
214214

215215
/** @public */
216216
export interface AutoEncryptionOptions {
217-
/** @internal */
218-
bson?: { serialize: typeof serialize; deserialize: typeof deserialize };
219217
/** @internal client for metadata lookups */
220218
metadataClient?: MongoClient;
221219
/** A `MongoClient` used to fetch keys from a key vault */

src/encrypter.ts

-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22

3-
import { deserialize, serialize } from './bson';
43
import { MONGO_CLIENT_EVENTS } from './constants';
54
import type { AutoEncrypter, AutoEncryptionOptions } from './deps';
65
import { MongoInvalidArgumentError, MongoMissingDependencyError } from './error';
@@ -58,12 +57,6 @@ export class Encrypter {
5857
};
5958
}
6059

61-
options.autoEncryption.bson = Object.create(null);
62-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
63-
options.autoEncryption.bson!.serialize = serialize;
64-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
65-
options.autoEncryption.bson!.deserialize = deserialize;
66-
6760
this.autoEncrypter = new AutoEncrypterClass(client, options.autoEncryption);
6861
}
6962

src/sdam/topology.ts

-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { clearTimeout, setTimeout } from 'timers';
22
import { promisify } from 'util';
33

44
import type { BSONSerializeOptions, Document } from '../bson';
5-
import { deserialize, serialize } from '../bson';
65
import type { MongoCredentials } from '../cmap/auth/mongo_credentials';
76
import type { ConnectionEvents, DestroyOptions } from '../cmap/connection';
87
import type { CloseOptions, ConnectionPoolEvents } from '../cmap/connection_pool';
@@ -222,16 +221,6 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
222221
/** @event */
223222
static readonly TIMEOUT = TIMEOUT;
224223

225-
/**
226-
* @internal
227-
*
228-
* @privateRemarks
229-
* mongodb-client-encryption's class ClientEncryption falls back to finding the bson lib
230-
* defined on client.topology.bson, in order to maintain compatibility with any version
231-
* of mongodb-client-encryption we keep a reference to serialize and deserialize here.
232-
*/
233-
bson: { serialize: typeof serialize; deserialize: typeof deserialize };
234-
235224
selectServerAsync: (
236225
selector: string | ReadPreference | ServerSelector,
237226
options: SelectServerOptions
@@ -251,12 +240,6 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
251240
) => this.selectServer(selector, options, callback as any)
252241
);
253242

254-
// Saving a reference to these BSON functions
255-
// supports v2.2.0 and older versions of mongodb-client-encryption
256-
this.bson = Object.create(null);
257-
this.bson.serialize = serialize;
258-
this.bson.deserialize = deserialize;
259-
260243
// Options should only be undefined in tests, MongoClient will always have defined options
261244
options = options ?? {
262245
hosts: [HostAddress.fromString('localhost:27017')],

test/action/dependency.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import { expect } from 'chai';
77
import { dependencies, peerDependencies, peerDependenciesMeta } from '../../package.json';
88

99
const EXPECTED_DEPENDENCIES = ['bson', 'mongodb-connection-string-url', 'socks'];
10-
const EXPECTED_PEER_DEPENDENCIES = ['@aws-sdk/credential-providers', 'snappy'];
10+
const EXPECTED_PEER_DEPENDENCIES = [
11+
'@aws-sdk/credential-providers',
12+
'snappy',
13+
'mongodb-client-encryption'
14+
];
1115

1216
describe('package.json', function () {
1317
describe('dependencies', function () {

0 commit comments

Comments
 (0)