mongodb 4.1.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -17
- package/lib/admin.js +5 -5
- package/lib/admin.js.map +1 -1
- package/lib/bulk/common.js +60 -56
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +15 -13
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +1 -1
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +2 -1
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +2 -2
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +23 -28
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/plain.js +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/scram.js +5 -5
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +15 -15
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +1 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +2 -2
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +15 -15
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +3 -3
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js +2 -2
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +1 -1
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +4 -4
- package/lib/collection.js +42 -41
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +94 -58
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +11 -11
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +15 -15
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +23 -23
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +20 -20
- package/lib/db.js.map +1 -1
- package/lib/deps.js +1 -1
- package/lib/deps.js.map +1 -1
- package/lib/gridfs/index.js +3 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +1 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +8 -2
- package/lib/index.js.map +1 -1
- package/lib/logger.js +5 -5
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +7 -7
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +3 -3
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +3 -4
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/command.js +7 -3
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js +1 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/connect.js +1 -1
- package/lib/operations/connect.js.map +1 -1
- package/lib/operations/count.js +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/create_collection.js +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +6 -6
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +4 -4
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js +2 -2
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js +2 -2
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +17 -7
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +8 -8
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +7 -7
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/indexes.js +14 -14
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +5 -5
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/list_collections.js +12 -7
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/map_reduce.js +6 -6
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +2 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/remove_user.js +1 -1
- package/lib/operations/remove_user.js.map +1 -1
- package/lib/operations/rename.js +2 -2
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/set_profiling_level.js +1 -1
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js +2 -2
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +12 -12
- package/lib/operations/update.js.map +1 -1
- package/lib/sdam/monitor.js +14 -14
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +19 -12
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +3 -3
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +20 -1
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +9 -9
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +29 -21
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +34 -12
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +19 -19
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +53 -46
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +97 -50
- package/mongodb.ts34.d.ts +96 -50
- package/package.json +44 -47
- package/src/bulk/common.ts +56 -35
- package/src/change_stream.ts +8 -6
- package/src/cmap/auth/mongo_credentials.ts +14 -3
- package/src/cmap/auth/mongodb_aws.ts +32 -31
- package/src/cmap/command_monitoring_events.ts +1 -1
- package/src/cmap/connection.ts +1 -0
- package/src/cmap/wire_protocol/constants.ts +4 -4
- package/src/collection.ts +32 -24
- package/src/connection_string.ts +103 -52
- package/src/cursor/abstract_cursor.ts +6 -4
- package/src/cursor/aggregation_cursor.ts +3 -3
- package/src/cursor/find_cursor.ts +1 -1
- package/src/db.ts +5 -6
- package/src/deps.ts +56 -19
- package/src/gridfs/download.ts +1 -1
- package/src/gridfs/upload.ts +11 -7
- package/src/index.ts +12 -1
- package/src/mongo_client.ts +18 -11
- package/src/mongo_types.ts +10 -13
- package/src/operations/aggregate.ts +1 -2
- package/src/operations/command.ts +5 -0
- package/src/operations/count.ts +1 -1
- package/src/operations/count_documents.ts +1 -1
- package/src/operations/create_collection.ts +1 -1
- package/src/operations/eval.ts +1 -1
- package/src/operations/execute_operation.ts +13 -2
- package/src/operations/indexes.ts +2 -2
- package/src/operations/list_collections.ts +12 -4
- package/src/operations/list_databases.ts +6 -1
- package/src/operations/operation.ts +3 -0
- package/src/sdam/server.ts +8 -0
- package/src/sdam/server_selection.ts +25 -0
- package/src/sdam/srv_polling.ts +12 -11
- package/src/sdam/topology.ts +27 -10
- package/src/sdam/topology_description.ts +35 -11
- package/src/transactions.ts +2 -2
- package/src/utils.ts +67 -56
package/src/connection_string.ts
CHANGED
|
@@ -32,7 +32,7 @@ import type { TagSet } from './sdam/server_description';
|
|
|
32
32
|
import { Logger, LoggerLevel } from './logger';
|
|
33
33
|
import { PromiseProvider } from './promise_provider';
|
|
34
34
|
import { Encrypter } from './encrypter';
|
|
35
|
-
import { Compressor } from './cmap/wire_protocol/compression';
|
|
35
|
+
import { Compressor, CompressorName } from './cmap/wire_protocol/compression';
|
|
36
36
|
|
|
37
37
|
const VALID_TXT_RECORDS = ['authSource', 'replicaSet', 'loadBalanced'];
|
|
38
38
|
|
|
@@ -75,7 +75,7 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
|
|
|
75
75
|
|
|
76
76
|
// Resolve the SRV record and use the result as the list of hosts to connect to.
|
|
77
77
|
const lookupAddress = options.srvHost;
|
|
78
|
-
dns.resolveSrv(`
|
|
78
|
+
dns.resolveSrv(`_${options.srvServiceName}._tcp.${lookupAddress}`, (err, addresses) => {
|
|
79
79
|
if (err) return callback(err);
|
|
80
80
|
|
|
81
81
|
if (addresses.length === 0) {
|
|
@@ -92,7 +92,7 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
|
|
|
92
92
|
HostAddress.fromString(`${r.name}:${r.port ?? 27017}`)
|
|
93
93
|
);
|
|
94
94
|
|
|
95
|
-
const lbError = validateLoadBalancedOptions(hostAddresses, options);
|
|
95
|
+
const lbError = validateLoadBalancedOptions(hostAddresses, options, true);
|
|
96
96
|
if (lbError) {
|
|
97
97
|
return callback(lbError);
|
|
98
98
|
}
|
|
@@ -116,14 +116,14 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
|
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
if (VALID_TXT_RECORDS.some(option => txtRecordOptions.get(option) === '')) {
|
|
120
|
+
return callback(new MongoParseError('Cannot have empty URI params in DNS TXT Record'));
|
|
121
|
+
}
|
|
122
|
+
|
|
119
123
|
const source = txtRecordOptions.get('authSource') ?? undefined;
|
|
120
124
|
const replicaSet = txtRecordOptions.get('replicaSet') ?? undefined;
|
|
121
125
|
const loadBalanced = txtRecordOptions.get('loadBalanced') ?? undefined;
|
|
122
126
|
|
|
123
|
-
if (source === '' || replicaSet === '') {
|
|
124
|
-
return callback(new MongoParseError('Cannot have empty URI params in DNS TXT Record'));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
127
|
if (!options.userSpecifiedAuthSource && source) {
|
|
128
128
|
options.credentials = MongoCredentials.merge(options.credentials, { source });
|
|
129
129
|
}
|
|
@@ -136,7 +136,11 @@ export function resolveSRVRecord(options: MongoOptions, callback: Callback<HostA
|
|
|
136
136
|
options.loadBalanced = true;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
|
|
139
|
+
if (options.replicaSet && options.srvMaxHosts > 0) {
|
|
140
|
+
return callback(new MongoParseError('Cannot combine replicaSet option with srvMaxHosts'));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const lbError = validateLoadBalancedOptions(hostAddresses, options, true);
|
|
140
144
|
if (lbError) {
|
|
141
145
|
return callback(lbError);
|
|
142
146
|
}
|
|
@@ -176,7 +180,7 @@ function getBoolean(name: string, value: unknown): boolean {
|
|
|
176
180
|
const valueString = String(value).toLowerCase();
|
|
177
181
|
if (TRUTHS.has(valueString)) return true;
|
|
178
182
|
if (FALSEHOODS.has(valueString)) return false;
|
|
179
|
-
throw new MongoParseError(`
|
|
183
|
+
throw new MongoParseError(`Expected ${name} to be stringified boolean value, got: ${value}`);
|
|
180
184
|
}
|
|
181
185
|
|
|
182
186
|
function getInt(name: string, value: unknown): number {
|
|
@@ -251,13 +255,6 @@ export function parseOptions(
|
|
|
251
255
|
|
|
252
256
|
const mongoOptions = Object.create(null);
|
|
253
257
|
mongoOptions.hosts = isSRV ? [] : hosts.map(HostAddress.fromString);
|
|
254
|
-
if (isSRV) {
|
|
255
|
-
// SRV Record is resolved upon connecting
|
|
256
|
-
mongoOptions.srvHost = hosts[0];
|
|
257
|
-
if (!url.searchParams.has('tls') && !url.searchParams.has('ssl')) {
|
|
258
|
-
options.tls = true;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
258
|
|
|
262
259
|
const urlOptions = new CaseInsensitiveMap();
|
|
263
260
|
|
|
@@ -289,30 +286,34 @@ export function parseOptions(
|
|
|
289
286
|
throw new MongoAPIError('URI cannot contain options with no value');
|
|
290
287
|
}
|
|
291
288
|
|
|
292
|
-
if (key.toLowerCase() === 'serverapi') {
|
|
293
|
-
throw new MongoParseError(
|
|
294
|
-
'URI cannot contain `serverApi`, it can only be passed to the client'
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (key.toLowerCase() === 'authsource' && urlOptions.has('authSource')) {
|
|
299
|
-
// If authSource is an explicit key in the urlOptions we need to remove the implicit dbName
|
|
300
|
-
urlOptions.delete('authSource');
|
|
301
|
-
}
|
|
302
|
-
|
|
303
289
|
if (!urlOptions.has(key)) {
|
|
304
290
|
urlOptions.set(key, values);
|
|
305
291
|
}
|
|
306
292
|
}
|
|
307
293
|
|
|
294
|
+
if (urlOptions.has('authSource')) {
|
|
295
|
+
// If authSource is an explicit key in the urlOptions we need to remove the dbName
|
|
296
|
+
urlOptions.delete('dbName');
|
|
297
|
+
}
|
|
298
|
+
|
|
308
299
|
const objectOptions = new CaseInsensitiveMap(
|
|
309
300
|
Object.entries(options).filter(([, v]) => v != null)
|
|
310
301
|
);
|
|
311
302
|
|
|
303
|
+
// Validate options that can only be provided by one of uri or object
|
|
304
|
+
|
|
305
|
+
if (urlOptions.has('serverApi')) {
|
|
306
|
+
throw new MongoParseError(
|
|
307
|
+
'URI cannot contain `serverApi`, it can only be passed to the client'
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
312
311
|
if (objectOptions.has('loadBalanced')) {
|
|
313
312
|
throw new MongoParseError('loadBalanced is only a valid option in the URI');
|
|
314
313
|
}
|
|
315
314
|
|
|
315
|
+
// All option collection
|
|
316
|
+
|
|
316
317
|
const allOptions = new CaseInsensitiveMap();
|
|
317
318
|
|
|
318
319
|
const allKeys = new Set<string>([
|
|
@@ -335,6 +336,19 @@ export function parseOptions(
|
|
|
335
336
|
allOptions.set(key, values);
|
|
336
337
|
}
|
|
337
338
|
|
|
339
|
+
if (allOptions.has('tlsCertificateKeyFile') && !allOptions.has('tlsCertificateFile')) {
|
|
340
|
+
allOptions.set('tlsCertificateFile', allOptions.get('tlsCertificateKeyFile'));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (allOptions.has('tls') || allOptions.has('ssl')) {
|
|
344
|
+
const tlsAndSslOpts = (allOptions.get('tls') || [])
|
|
345
|
+
.concat(allOptions.get('ssl') || [])
|
|
346
|
+
.map(getBoolean.bind(null, 'tls/ssl'));
|
|
347
|
+
if (new Set(tlsAndSslOpts).size !== 1) {
|
|
348
|
+
throw new MongoParseError('All values of tls/ssl must be the same.');
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
338
352
|
const unsupportedOptions = setDifference(
|
|
339
353
|
allKeys,
|
|
340
354
|
Array.from(Object.keys(OPTIONS)).map(s => s.toLowerCase())
|
|
@@ -347,6 +361,8 @@ export function parseOptions(
|
|
|
347
361
|
);
|
|
348
362
|
}
|
|
349
363
|
|
|
364
|
+
// Option parsing and setting
|
|
365
|
+
|
|
350
366
|
for (const [key, descriptor] of Object.entries(OPTIONS)) {
|
|
351
367
|
const values = allOptions.get(key);
|
|
352
368
|
if (!values || values.length === 0) continue;
|
|
@@ -384,41 +400,57 @@ export function parseOptions(
|
|
|
384
400
|
mongoOptions.dbName = 'test';
|
|
385
401
|
}
|
|
386
402
|
|
|
387
|
-
if (allOptions.has('tls')) {
|
|
388
|
-
if (new Set(allOptions.get('tls')?.map(getBoolean)).size !== 1) {
|
|
389
|
-
throw new MongoParseError('All values of tls must be the same.');
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
if (allOptions.has('ssl')) {
|
|
394
|
-
if (new Set(allOptions.get('ssl')?.map(getBoolean)).size !== 1) {
|
|
395
|
-
throw new MongoParseError('All values of ssl must be the same.');
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
403
|
checkTLSOptions(mongoOptions);
|
|
400
404
|
|
|
401
405
|
if (options.promiseLibrary) PromiseProvider.set(options.promiseLibrary);
|
|
402
406
|
|
|
403
|
-
|
|
404
|
-
throw new MongoAPIError('SRV URI does not support directConnection');
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
const lbError = validateLoadBalancedOptions(hosts, mongoOptions);
|
|
407
|
+
const lbError = validateLoadBalancedOptions(hosts, mongoOptions, isSRV);
|
|
408
408
|
if (lbError) {
|
|
409
409
|
throw lbError;
|
|
410
410
|
}
|
|
411
|
+
if (mongoClient && mongoOptions.autoEncryption) {
|
|
412
|
+
Encrypter.checkForMongoCrypt();
|
|
413
|
+
mongoOptions.encrypter = new Encrypter(mongoClient, uri, options);
|
|
414
|
+
mongoOptions.autoEncrypter = mongoOptions.encrypter.autoEncrypter;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Potential SRV Overrides and SRV connection string validations
|
|
411
418
|
|
|
412
|
-
// Potential SRV Overrides
|
|
413
419
|
mongoOptions.userSpecifiedAuthSource =
|
|
414
420
|
objectOptions.has('authSource') || urlOptions.has('authSource');
|
|
415
421
|
mongoOptions.userSpecifiedReplicaSet =
|
|
416
422
|
objectOptions.has('replicaSet') || urlOptions.has('replicaSet');
|
|
417
423
|
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
mongoOptions.
|
|
421
|
-
|
|
424
|
+
if (isSRV) {
|
|
425
|
+
// SRV Record is resolved upon connecting
|
|
426
|
+
mongoOptions.srvHost = hosts[0];
|
|
427
|
+
|
|
428
|
+
if (mongoOptions.directConnection) {
|
|
429
|
+
throw new MongoAPIError('SRV URI does not support directConnection');
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (mongoOptions.srvMaxHosts > 0 && typeof mongoOptions.replicaSet === 'string') {
|
|
433
|
+
throw new MongoParseError('Cannot use srvMaxHosts option with replicaSet');
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// SRV turns on TLS by default, but users can override and turn it off
|
|
437
|
+
const noUserSpecifiedTLS = !objectOptions.has('tls') && !urlOptions.has('tls');
|
|
438
|
+
const noUserSpecifiedSSL = !objectOptions.has('ssl') && !urlOptions.has('ssl');
|
|
439
|
+
if (noUserSpecifiedTLS && noUserSpecifiedSSL) {
|
|
440
|
+
mongoOptions.tls = true;
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
const userSpecifiedSrvOptions =
|
|
444
|
+
urlOptions.has('srvMaxHosts') ||
|
|
445
|
+
objectOptions.has('srvMaxHosts') ||
|
|
446
|
+
urlOptions.has('srvServiceName') ||
|
|
447
|
+
objectOptions.has('srvServiceName');
|
|
448
|
+
|
|
449
|
+
if (userSpecifiedSrvOptions) {
|
|
450
|
+
throw new MongoParseError(
|
|
451
|
+
'Cannot use srvMaxHosts or srvServiceName with a non-srv connection string'
|
|
452
|
+
);
|
|
453
|
+
}
|
|
422
454
|
}
|
|
423
455
|
|
|
424
456
|
return mongoOptions;
|
|
@@ -426,7 +458,8 @@ export function parseOptions(
|
|
|
426
458
|
|
|
427
459
|
function validateLoadBalancedOptions(
|
|
428
460
|
hosts: HostAddress[] | string[],
|
|
429
|
-
mongoOptions: MongoOptions
|
|
461
|
+
mongoOptions: MongoOptions,
|
|
462
|
+
isSrv: boolean
|
|
430
463
|
): MongoParseError | undefined {
|
|
431
464
|
if (mongoOptions.loadBalanced) {
|
|
432
465
|
if (hosts.length > 1) {
|
|
@@ -438,6 +471,10 @@ function validateLoadBalancedOptions(
|
|
|
438
471
|
if (mongoOptions.directConnection) {
|
|
439
472
|
return new MongoParseError(LB_DIRECT_CONNECTION_ERROR);
|
|
440
473
|
}
|
|
474
|
+
|
|
475
|
+
if (isSrv && mongoOptions.srvMaxHosts > 0) {
|
|
476
|
+
return new MongoParseError('Cannot limit srv hosts with loadBalanced enabled');
|
|
477
|
+
}
|
|
441
478
|
}
|
|
442
479
|
}
|
|
443
480
|
|
|
@@ -612,8 +649,14 @@ export const OPTIONS = {
|
|
|
612
649
|
target: 'compressors',
|
|
613
650
|
transform({ values }) {
|
|
614
651
|
const compressionList = new Set();
|
|
615
|
-
for (const compVal of values as string[]) {
|
|
616
|
-
|
|
652
|
+
for (const compVal of values as (CompressorName[] | string)[]) {
|
|
653
|
+
const compValArray = typeof compVal === 'string' ? compVal.split(',') : compVal;
|
|
654
|
+
if (!Array.isArray(compValArray)) {
|
|
655
|
+
throw new MongoInvalidArgumentError(
|
|
656
|
+
'compressors must be an array or a comma-delimited list of strings'
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
for (const c of compValArray) {
|
|
617
660
|
if (Object.keys(Compressor).includes(String(c))) {
|
|
618
661
|
compressionList.add(String(c));
|
|
619
662
|
} else {
|
|
@@ -917,6 +960,14 @@ export const OPTIONS = {
|
|
|
917
960
|
default: 0,
|
|
918
961
|
type: 'uint'
|
|
919
962
|
},
|
|
963
|
+
srvMaxHosts: {
|
|
964
|
+
type: 'uint',
|
|
965
|
+
default: 0
|
|
966
|
+
},
|
|
967
|
+
srvServiceName: {
|
|
968
|
+
type: 'string',
|
|
969
|
+
default: 'mongodb'
|
|
970
|
+
},
|
|
920
971
|
ssl: {
|
|
921
972
|
target: 'tls',
|
|
922
973
|
type: 'boolean'
|
|
@@ -418,9 +418,11 @@ export abstract class AbstractCursor<
|
|
|
418
418
|
docs.push(doc);
|
|
419
419
|
|
|
420
420
|
// these do need to be transformed since they are copying the rest of the batch
|
|
421
|
-
const internalDocs = (
|
|
422
|
-
|
|
423
|
-
|
|
421
|
+
const internalDocs = (
|
|
422
|
+
transform
|
|
423
|
+
? this[kDocuments].splice(0, this[kDocuments].length).map(transform)
|
|
424
|
+
: this[kDocuments].splice(0, this[kDocuments].length)
|
|
425
|
+
) as TSchema[]; // TODO(NODE-3283): Improve transform typing
|
|
424
426
|
|
|
425
427
|
if (internalDocs) {
|
|
426
428
|
docs.push(...internalDocs);
|
|
@@ -484,7 +486,7 @@ export abstract class AbstractCursor<
|
|
|
484
486
|
this[kTransform] = transform;
|
|
485
487
|
}
|
|
486
488
|
|
|
487
|
-
return
|
|
489
|
+
return this as unknown as AbstractCursor<T>;
|
|
488
490
|
}
|
|
489
491
|
|
|
490
492
|
/**
|
|
@@ -120,8 +120,8 @@ export class AggregationCursor<TSchema = Document> extends AbstractCursor<TSchem
|
|
|
120
120
|
return this;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
/** Add
|
|
124
|
-
out($out:
|
|
123
|
+
/** Add an out stage to the aggregation pipeline */
|
|
124
|
+
out($out: { db: string; coll: string } | string): this {
|
|
125
125
|
assertUninitialized(this);
|
|
126
126
|
this[kPipeline].push({ $out });
|
|
127
127
|
return this;
|
|
@@ -171,7 +171,7 @@ export class AggregationCursor<TSchema = Document> extends AbstractCursor<TSchem
|
|
|
171
171
|
project<T extends Document = Document>($project: Document): AggregationCursor<T> {
|
|
172
172
|
assertUninitialized(this);
|
|
173
173
|
this[kPipeline].push({ $project });
|
|
174
|
-
return
|
|
174
|
+
return this as unknown as AggregationCursor<T>;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
/** Add a lookup stage to the aggregation pipeline */
|
|
@@ -379,7 +379,7 @@ export class FindCursor<TSchema = Document> extends AbstractCursor<TSchema> {
|
|
|
379
379
|
project<T extends Document = Document>(value: Document): FindCursor<T> {
|
|
380
380
|
assertUninitialized(this);
|
|
381
381
|
this[kBuiltOptions].projection = value;
|
|
382
|
-
return
|
|
382
|
+
return this as unknown as FindCursor<T>;
|
|
383
383
|
}
|
|
384
384
|
|
|
385
385
|
/**
|
package/src/db.ts
CHANGED
|
@@ -226,18 +226,17 @@ export class Db {
|
|
|
226
226
|
* @param options - Optional settings for the command
|
|
227
227
|
* @param callback - An optional callback, a Promise will be returned if none is provided
|
|
228
228
|
*/
|
|
229
|
-
createCollection<TSchema extends Document = Document>(name: string): Promise<Collection<TSchema>>;
|
|
230
229
|
createCollection<TSchema extends Document = Document>(
|
|
231
230
|
name: string,
|
|
232
|
-
|
|
233
|
-
):
|
|
231
|
+
options?: CreateCollectionOptions
|
|
232
|
+
): Promise<Collection<TSchema>>;
|
|
234
233
|
createCollection<TSchema extends Document = Document>(
|
|
235
234
|
name: string,
|
|
236
|
-
|
|
237
|
-
):
|
|
235
|
+
callback: Callback<Collection<TSchema>>
|
|
236
|
+
): void;
|
|
238
237
|
createCollection<TSchema extends Document = Document>(
|
|
239
238
|
name: string,
|
|
240
|
-
options: CreateCollectionOptions,
|
|
239
|
+
options: CreateCollectionOptions | undefined,
|
|
241
240
|
callback: Callback<Collection<TSchema>>
|
|
242
241
|
): void;
|
|
243
242
|
createCollection<TSchema extends Document = Document>(
|
package/src/deps.ts
CHANGED
|
@@ -21,13 +21,12 @@ function makeErrorModule(error: any) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export let Kerberos:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
30
|
-
);
|
|
24
|
+
export let Kerberos: typeof import('kerberos') | { kModuleError: MongoMissingDependencyError } =
|
|
25
|
+
makeErrorModule(
|
|
26
|
+
new MongoMissingDependencyError(
|
|
27
|
+
'Optional module `kerberos` not found. Please install it to enable kerberos authentication'
|
|
28
|
+
)
|
|
29
|
+
);
|
|
31
30
|
|
|
32
31
|
try {
|
|
33
32
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
@@ -97,23 +96,60 @@ try {
|
|
|
97
96
|
} catch {} // eslint-disable-line
|
|
98
97
|
} catch {} // eslint-disable-line
|
|
99
98
|
|
|
100
|
-
export let saslprep:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
)
|
|
107
|
-
);
|
|
99
|
+
export let saslprep: typeof import('saslprep') | { kModuleError: MongoMissingDependencyError } =
|
|
100
|
+
makeErrorModule(
|
|
101
|
+
new MongoMissingDependencyError(
|
|
102
|
+
'Optional module `saslprep` not found.' +
|
|
103
|
+
' Please install it to enable Stringprep Profile for User Names and Passwords'
|
|
104
|
+
)
|
|
105
|
+
);
|
|
108
106
|
|
|
109
107
|
try {
|
|
110
108
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
111
109
|
saslprep = require('saslprep');
|
|
112
110
|
} catch {} // eslint-disable-line
|
|
113
111
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
interface AWS4 {
|
|
113
|
+
/**
|
|
114
|
+
* Created these inline types to better assert future usage of this API
|
|
115
|
+
* @param options - options for request
|
|
116
|
+
* @param credentials - AWS credential details, sessionToken should be omitted entirely if its false-y
|
|
117
|
+
*/
|
|
118
|
+
sign(
|
|
119
|
+
options: {
|
|
120
|
+
path: '/';
|
|
121
|
+
body: string;
|
|
122
|
+
host: string;
|
|
123
|
+
method: 'POST';
|
|
124
|
+
headers: {
|
|
125
|
+
'Content-Type': 'application/x-www-form-urlencoded';
|
|
126
|
+
'Content-Length': number;
|
|
127
|
+
'X-MongoDB-Server-Nonce': string;
|
|
128
|
+
'X-MongoDB-GS2-CB-Flag': 'n';
|
|
129
|
+
};
|
|
130
|
+
service: string;
|
|
131
|
+
region: string;
|
|
132
|
+
},
|
|
133
|
+
credentials:
|
|
134
|
+
| {
|
|
135
|
+
accessKeyId: string;
|
|
136
|
+
secretAccessKey: string;
|
|
137
|
+
sessionToken: string;
|
|
138
|
+
}
|
|
139
|
+
| {
|
|
140
|
+
accessKeyId: string;
|
|
141
|
+
secretAccessKey: string;
|
|
142
|
+
}
|
|
143
|
+
| undefined
|
|
144
|
+
): {
|
|
145
|
+
headers: {
|
|
146
|
+
Authorization: string;
|
|
147
|
+
'X-Amz-Date': string;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export let aws4: AWS4 | { kModuleError: MongoMissingDependencyError } = makeErrorModule(
|
|
117
153
|
new MongoMissingDependencyError(
|
|
118
154
|
'Optional module `aws4` not found. Please install it to enable AWS authentication'
|
|
119
155
|
)
|
|
@@ -134,7 +170,8 @@ export const AutoEncryptionLoggerLevel = Object.freeze({
|
|
|
134
170
|
} as const);
|
|
135
171
|
|
|
136
172
|
/** @public */
|
|
137
|
-
export type AutoEncryptionLoggerLevel =
|
|
173
|
+
export type AutoEncryptionLoggerLevel =
|
|
174
|
+
typeof AutoEncryptionLoggerLevel[keyof typeof AutoEncryptionLoggerLevel];
|
|
138
175
|
|
|
139
176
|
/** @public */
|
|
140
177
|
export interface AutoEncryptionOptions {
|
package/src/gridfs/download.ts
CHANGED
|
@@ -73,7 +73,7 @@ export interface GridFSBucketReadStreamPrivate {
|
|
|
73
73
|
* Do not instantiate this class directly. Use `openDownloadStream()` instead.
|
|
74
74
|
* @public
|
|
75
75
|
*/
|
|
76
|
-
export class GridFSBucketReadStream extends Readable {
|
|
76
|
+
export class GridFSBucketReadStream extends Readable implements NodeJS.ReadableStream {
|
|
77
77
|
/** @internal */
|
|
78
78
|
s: GridFSBucketReadStreamPrivate;
|
|
79
79
|
|
package/src/gridfs/upload.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
|
|
|
37
37
|
* Do not instantiate this class directly. Use `openUploadStream()` instead.
|
|
38
38
|
* @public
|
|
39
39
|
*/
|
|
40
|
-
export class GridFSBucketWriteStream extends Writable {
|
|
40
|
+
export class GridFSBucketWriteStream extends Writable implements NodeJS.WritableStream {
|
|
41
41
|
bucket: GridFSBucket;
|
|
42
42
|
chunks: Collection<GridFSChunk>;
|
|
43
43
|
filename: string;
|
|
@@ -118,12 +118,16 @@ export class GridFSBucketWriteStream extends Writable {
|
|
|
118
118
|
* @param callback - Function to call when the chunk was added to the buffer, or if the entire chunk was persisted to MongoDB if this chunk caused a flush.
|
|
119
119
|
* @returns False if this write required flushing a chunk to MongoDB. True otherwise.
|
|
120
120
|
*/
|
|
121
|
-
write(chunk: Buffer): boolean;
|
|
122
|
-
write(chunk: Buffer, callback: Callback<void>): boolean;
|
|
123
|
-
write(chunk: Buffer, encoding: BufferEncoding | undefined): boolean;
|
|
124
|
-
write(chunk: Buffer, encoding: BufferEncoding | undefined, callback: Callback<void>): boolean;
|
|
121
|
+
write(chunk: Buffer | string): boolean;
|
|
122
|
+
write(chunk: Buffer | string, callback: Callback<void>): boolean;
|
|
123
|
+
write(chunk: Buffer | string, encoding: BufferEncoding | undefined): boolean;
|
|
125
124
|
write(
|
|
126
|
-
chunk: Buffer,
|
|
125
|
+
chunk: Buffer | string,
|
|
126
|
+
encoding: BufferEncoding | undefined,
|
|
127
|
+
callback: Callback<void>
|
|
128
|
+
): boolean;
|
|
129
|
+
write(
|
|
130
|
+
chunk: Buffer | string,
|
|
127
131
|
encodingOrCallback?: Callback<void> | BufferEncoding,
|
|
128
132
|
callback?: Callback<void>
|
|
129
133
|
): boolean {
|
|
@@ -417,7 +421,7 @@ function createFilesDoc(
|
|
|
417
421
|
|
|
418
422
|
function doWrite(
|
|
419
423
|
stream: GridFSBucketWriteStream,
|
|
420
|
-
chunk: Buffer,
|
|
424
|
+
chunk: Buffer | string,
|
|
421
425
|
encoding?: BufferEncoding,
|
|
422
426
|
callback?: Callback<void>
|
|
423
427
|
): boolean {
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,13 @@ export {
|
|
|
29
29
|
Map
|
|
30
30
|
} from './bson';
|
|
31
31
|
|
|
32
|
+
import { ObjectId } from 'bson';
|
|
33
|
+
/**
|
|
34
|
+
* @public
|
|
35
|
+
* @deprecated Please use `ObjectId`
|
|
36
|
+
*/
|
|
37
|
+
export const ObjectID = ObjectId;
|
|
38
|
+
|
|
32
39
|
export {
|
|
33
40
|
MongoError,
|
|
34
41
|
MongoServerError,
|
|
@@ -160,7 +167,11 @@ export type {
|
|
|
160
167
|
OperationTime,
|
|
161
168
|
ResumeOptions
|
|
162
169
|
} from './change_stream';
|
|
163
|
-
export type {
|
|
170
|
+
export type {
|
|
171
|
+
MongoCredentials,
|
|
172
|
+
AuthMechanismProperties,
|
|
173
|
+
MongoCredentialsOptions
|
|
174
|
+
} from './cmap/auth/mongo_credentials';
|
|
164
175
|
export type {
|
|
165
176
|
WriteProtocolMessageType,
|
|
166
177
|
Query,
|
package/src/mongo_client.ts
CHANGED
|
@@ -27,7 +27,7 @@ import type { AuthMechanism } from './cmap/auth/defaultAuthProviders';
|
|
|
27
27
|
import type { Topology, TopologyEvents } from './sdam/topology';
|
|
28
28
|
import type { ClientSession, ClientSessionOptions } from './sessions';
|
|
29
29
|
import type { TagSet } from './sdam/server_description';
|
|
30
|
-
import type { MongoCredentials } from './cmap/auth/mongo_credentials';
|
|
30
|
+
import type { AuthMechanismProperties, MongoCredentials } from './cmap/auth/mongo_credentials';
|
|
31
31
|
import { parseOptions } from './connection_string';
|
|
32
32
|
import type { CompressorName } from './cmap/wire_protocol/compression';
|
|
33
33
|
import type { TLSSocketOptions, ConnectionOptions as TLSConnectionOptions } from 'tls';
|
|
@@ -112,7 +112,7 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
|
|
|
112
112
|
ssl?: boolean;
|
|
113
113
|
/** Specifies the location of a local TLS Certificate */
|
|
114
114
|
tlsCertificateFile?: string;
|
|
115
|
-
/** Specifies the location of a local .pem file that contains either the client
|
|
115
|
+
/** Specifies the location of a local .pem file that contains either the client's TLS/SSL certificate and key or only the client's TLS/SSL key when tlsCertificateFile is used to provide the certificate. */
|
|
116
116
|
tlsCertificateKeyFile?: string;
|
|
117
117
|
/** Specifies the password to de-crypt the tlsCertificateKeyFile. */
|
|
118
118
|
tlsCertificateKeyFilePassword?: string;
|
|
@@ -128,10 +128,20 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
|
|
|
128
128
|
connectTimeoutMS?: number;
|
|
129
129
|
/** The time in milliseconds to attempt a send or receive on a socket before the attempt times out. */
|
|
130
130
|
socketTimeoutMS?: number;
|
|
131
|
-
/**
|
|
132
|
-
compressors?: CompressorName[];
|
|
131
|
+
/** An array or comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance. */
|
|
132
|
+
compressors?: CompressorName[] | string;
|
|
133
133
|
/** An integer that specifies the compression level if using zlib for network compression. */
|
|
134
134
|
zlibCompressionLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | undefined;
|
|
135
|
+
/** The maximum number of hosts to connect to when using an srv connection string, a setting of `0` means unlimited hosts */
|
|
136
|
+
srvMaxHosts?: number;
|
|
137
|
+
/**
|
|
138
|
+
* Modifies the srv URI to look like:
|
|
139
|
+
*
|
|
140
|
+
* `_{srvServiceName}._tcp.{hostname}.{domainname}`
|
|
141
|
+
*
|
|
142
|
+
* Querying this DNS URI is expected to respond with SRV records
|
|
143
|
+
*/
|
|
144
|
+
srvServiceName?: string;
|
|
135
145
|
/** The maximum number of connections in the connection pool. */
|
|
136
146
|
maxPoolSize?: number;
|
|
137
147
|
/** The minimum number of connections in the connection pool. */
|
|
@@ -157,12 +167,7 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
|
|
|
157
167
|
/** Specify the authentication mechanism that MongoDB will use to authenticate the connection. */
|
|
158
168
|
authMechanism?: AuthMechanism;
|
|
159
169
|
/** Specify properties for the specified authMechanism as a comma-separated list of colon-separated key-value pairs. */
|
|
160
|
-
authMechanismProperties?:
|
|
161
|
-
SERVICE_NAME?: string;
|
|
162
|
-
CANONICALIZE_HOST_NAME?: boolean;
|
|
163
|
-
SERVICE_REALM?: string;
|
|
164
|
-
[key: string]: any;
|
|
165
|
-
};
|
|
170
|
+
authMechanismProperties?: AuthMechanismProperties;
|
|
166
171
|
/** The size (in milliseconds) of the latency window for selecting among multiple suitable MongoDB instances. */
|
|
167
172
|
localThresholdMS?: number;
|
|
168
173
|
/** Specifies how long (in milliseconds) to block for server selection before throwing an exception. */
|
|
@@ -625,7 +630,6 @@ export interface MongoOptions
|
|
|
625
630
|
Pick<
|
|
626
631
|
MongoClientOptions,
|
|
627
632
|
| 'autoEncryption'
|
|
628
|
-
| 'compressors'
|
|
629
633
|
| 'connectTimeoutMS'
|
|
630
634
|
| 'directConnection'
|
|
631
635
|
| 'driverInfo'
|
|
@@ -649,6 +653,8 @@ export interface MongoOptions
|
|
|
649
653
|
| 'retryWrites'
|
|
650
654
|
| 'serverSelectionTimeoutMS'
|
|
651
655
|
| 'socketTimeoutMS'
|
|
656
|
+
| 'srvMaxHosts'
|
|
657
|
+
| 'srvServiceName'
|
|
652
658
|
| 'tlsAllowInvalidCertificates'
|
|
653
659
|
| 'tlsAllowInvalidHostnames'
|
|
654
660
|
| 'tlsInsecure'
|
|
@@ -664,6 +670,7 @@ export interface MongoOptions
|
|
|
664
670
|
readConcern: ReadConcern;
|
|
665
671
|
loadBalanced: boolean;
|
|
666
672
|
serverApi: ServerApi;
|
|
673
|
+
compressors: CompressorName[];
|
|
667
674
|
writeConcern: WriteConcern;
|
|
668
675
|
dbName: string;
|
|
669
676
|
metadata: ClientMetadata;
|