mongodb 4.1.4 → 4.3.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 +16 -15
- package/lib/admin.js +3 -3
- package/lib/admin.js.map +1 -1
- package/lib/bson.js +16 -14
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +3 -4
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js +1 -1
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +6 -7
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +3 -3
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +16 -18
- 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 +6 -6
- 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/providers.js +21 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +4 -4
- 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 +1 -1
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +20 -11
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +102 -15
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +27 -26
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +19 -30
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js +3 -3
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +4 -4
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +4 -4
- package/lib/cmap/wire_protocol/shared.js +4 -3
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +46 -47
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +106 -49
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +108 -1
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +10 -7
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +1 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +1 -1
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +23 -13
- package/lib/db.js.map +1 -1
- package/lib/deps.js +0 -1
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +12 -4
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +47 -24
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +1 -1
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +3 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +3 -2
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +81 -81
- package/lib/index.js.map +1 -1
- package/lib/logger.js +1 -1
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +5 -5
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +2 -2
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +2 -3
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/collections.js +1 -1
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js +9 -6
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/connect.js +4 -13
- 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 +3 -2
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +3 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +3 -3
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js +1 -1
- 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 +2 -2
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +23 -7
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +5 -5
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +2 -2
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js +28 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +4 -4
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +11 -6
- 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 +4 -3
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +4 -2
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js +1 -1
- package/lib/operations/profiling_level.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 +3 -3
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/run_command.js +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/set_profiling_level.js +2 -2
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +2 -2
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_preference.js +15 -5
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/monitor.js +4 -4
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +31 -31
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +1 -1
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +38 -3
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +11 -11
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +40 -62
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +36 -14
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +13 -28
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +90 -23
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +159 -65
- package/mongodb.ts34.d.ts +184 -65
- package/package.json +26 -24
- package/src/admin.ts +9 -9
- package/src/bson.ts +26 -17
- package/src/bulk/common.ts +26 -20
- package/src/bulk/ordered.ts +4 -4
- package/src/bulk/unordered.ts +5 -5
- package/src/change_stream.ts +35 -32
- package/src/cmap/auth/auth_provider.ts +3 -3
- package/src/cmap/auth/gssapi.ts +8 -8
- package/src/cmap/auth/mongo_credentials.ts +2 -6
- package/src/cmap/auth/mongocr.ts +3 -2
- package/src/cmap/auth/mongodb_aws.ts +10 -11
- package/src/cmap/auth/plain.ts +1 -1
- package/src/cmap/auth/providers.ts +21 -0
- package/src/cmap/auth/scram.ts +9 -9
- package/src/cmap/auth/x509.ts +3 -3
- package/src/cmap/command_monitoring_events.ts +2 -2
- package/src/cmap/commands.ts +30 -19
- package/src/cmap/connect.ts +142 -22
- package/src/cmap/connection.ts +73 -52
- package/src/cmap/connection_pool.ts +39 -39
- package/src/cmap/connection_pool_events.ts +1 -1
- package/src/cmap/message_stream.ts +9 -8
- package/src/cmap/stream_description.ts +5 -5
- package/src/cmap/wire_protocol/compression.ts +2 -2
- package/src/cmap/wire_protocol/constants.ts +4 -4
- package/src/cmap/wire_protocol/shared.ts +10 -9
- package/src/collection.ts +133 -106
- package/src/connection_string.ts +141 -60
- package/src/constants.ts +116 -0
- package/src/cursor/abstract_cursor.ts +21 -22
- package/src/cursor/aggregation_cursor.ts +6 -6
- package/src/cursor/find_cursor.ts +2 -2
- package/src/db.ts +49 -39
- package/src/deps.ts +3 -1
- package/src/encrypter.ts +12 -3
- package/src/error.ts +52 -24
- package/src/gridfs/download.ts +10 -8
- package/src/gridfs/index.ts +11 -11
- package/src/gridfs/upload.ts +13 -10
- package/src/index.ts +204 -199
- package/src/logger.ts +2 -1
- package/src/mongo_client.ts +58 -32
- package/src/mongo_types.ts +98 -20
- package/src/operations/add_user.ts +6 -5
- package/src/operations/aggregate.ts +6 -7
- package/src/operations/bulk_write.ts +5 -5
- package/src/operations/collections.ts +2 -2
- package/src/operations/command.ts +19 -8
- package/src/operations/common_functions.ts +4 -4
- package/src/operations/connect.ts +4 -14
- package/src/operations/count.ts +4 -4
- package/src/operations/count_documents.ts +3 -3
- package/src/operations/create_collection.ts +8 -7
- package/src/operations/delete.ts +5 -5
- package/src/operations/distinct.ts +4 -4
- package/src/operations/drop.ts +4 -4
- package/src/operations/estimated_document_count.ts +5 -5
- package/src/operations/eval.ts +5 -5
- package/src/operations/execute_operation.ts +30 -11
- package/src/operations/find.ts +14 -14
- package/src/operations/find_and_modify.ts +7 -7
- package/src/operations/get_more.ts +49 -0
- package/src/operations/indexes.ts +16 -16
- package/src/operations/insert.ts +9 -9
- package/src/operations/is_capped.ts +3 -3
- package/src/operations/list_collections.ts +18 -10
- package/src/operations/list_databases.ts +4 -4
- package/src/operations/map_reduce.ts +10 -9
- package/src/operations/operation.ts +8 -4
- package/src/operations/options_operation.ts +3 -3
- package/src/operations/profiling_level.ts +4 -4
- package/src/operations/remove_user.ts +4 -4
- package/src/operations/rename.ts +6 -6
- package/src/operations/run_command.ts +3 -3
- package/src/operations/set_profiling_level.ts +6 -5
- package/src/operations/stats.ts +4 -4
- package/src/operations/update.ts +10 -10
- package/src/operations/validate_collection.ts +4 -4
- package/src/read_preference.ts +18 -7
- package/src/sdam/common.ts +2 -2
- package/src/sdam/events.ts +1 -1
- package/src/sdam/monitor.ts +13 -14
- package/src/sdam/server.ts +71 -61
- package/src/sdam/server_description.ts +4 -4
- package/src/sdam/server_selection.ts +46 -3
- package/src/sdam/srv_polling.ts +15 -13
- package/src/sdam/topology.ts +89 -90
- package/src/sdam/topology_description.ts +39 -15
- package/src/sessions.ts +31 -48
- package/src/transactions.ts +6 -6
- package/src/utils.ts +123 -43
- package/lib/cmap/auth/defaultAuthProviders.js +0 -30
- package/lib/cmap/auth/defaultAuthProviders.js.map +0 -1
- package/src/cmap/auth/defaultAuthProviders.ts +0 -32
package/src/db.ts
CHANGED
|
@@ -1,39 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
resolveOptions,
|
|
4
|
-
filterOptions,
|
|
5
|
-
MongoDBNamespace,
|
|
6
|
-
getTopology,
|
|
7
|
-
DEFAULT_PK_FACTORY
|
|
8
|
-
} from './utils';
|
|
9
|
-
import { AggregationCursor } from './cursor/aggregation_cursor';
|
|
10
|
-
import { Document, BSONSerializeOptions, resolveBSONOptions } from './bson';
|
|
11
|
-
import { ReadPreference, ReadPreferenceLike } from './read_preference';
|
|
12
|
-
import { MongoAPIError, MongoInvalidArgumentError } from './error';
|
|
13
|
-
import { Collection, CollectionOptions } from './collection';
|
|
1
|
+
import { Admin } from './admin';
|
|
2
|
+
import { BSONSerializeOptions, Document, resolveBSONOptions } from './bson';
|
|
14
3
|
import { ChangeStream, ChangeStreamOptions } from './change_stream';
|
|
4
|
+
import { Collection, CollectionOptions } from './collection';
|
|
15
5
|
import * as CONSTANTS from './constants';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
6
|
+
import { AggregationCursor } from './cursor/aggregation_cursor';
|
|
7
|
+
import { MongoAPIError, MongoInvalidArgumentError } from './error';
|
|
18
8
|
import { Logger, LoggerOptions } from './logger';
|
|
19
|
-
import type {
|
|
9
|
+
import type { MongoClient, PkFactory } from './mongo_client';
|
|
10
|
+
import type { TODO_NODE_3286 } from './mongo_types';
|
|
20
11
|
import { AddUserOperation, AddUserOptions } from './operations/add_user';
|
|
12
|
+
import type { AggregateOptions } from './operations/aggregate';
|
|
21
13
|
import { CollectionsOperation } from './operations/collections';
|
|
22
|
-
import {
|
|
23
|
-
import { RunCommandOperation, RunCommandOptions } from './operations/run_command';
|
|
14
|
+
import type { IndexInformationOptions } from './operations/common_functions';
|
|
24
15
|
import { CreateCollectionOperation, CreateCollectionOptions } from './operations/create_collection';
|
|
25
16
|
import {
|
|
17
|
+
DropCollectionOperation,
|
|
18
|
+
DropCollectionOptions,
|
|
19
|
+
DropDatabaseOperation,
|
|
20
|
+
DropDatabaseOptions
|
|
21
|
+
} from './operations/drop';
|
|
22
|
+
import { executeOperation } from './operations/execute_operation';
|
|
23
|
+
import {
|
|
24
|
+
CreateIndexesOptions,
|
|
26
25
|
CreateIndexOperation,
|
|
27
26
|
IndexInformationOperation,
|
|
28
|
-
CreateIndexesOptions,
|
|
29
27
|
IndexSpecification
|
|
30
28
|
} from './operations/indexes';
|
|
31
|
-
import {
|
|
32
|
-
DropCollectionOperation,
|
|
33
|
-
DropDatabaseOperation,
|
|
34
|
-
DropDatabaseOptions,
|
|
35
|
-
DropCollectionOptions
|
|
36
|
-
} from './operations/drop';
|
|
37
29
|
import {
|
|
38
30
|
CollectionInfo,
|
|
39
31
|
ListCollectionsCursor,
|
|
@@ -42,16 +34,24 @@ import {
|
|
|
42
34
|
import { ProfilingLevelOperation, ProfilingLevelOptions } from './operations/profiling_level';
|
|
43
35
|
import { RemoveUserOperation, RemoveUserOptions } from './operations/remove_user';
|
|
44
36
|
import { RenameOperation, RenameOptions } from './operations/rename';
|
|
37
|
+
import { RunCommandOperation, RunCommandOptions } from './operations/run_command';
|
|
45
38
|
import {
|
|
39
|
+
ProfilingLevel,
|
|
46
40
|
SetProfilingLevelOperation,
|
|
47
|
-
SetProfilingLevelOptions
|
|
48
|
-
ProfilingLevel
|
|
41
|
+
SetProfilingLevelOptions
|
|
49
42
|
} from './operations/set_profiling_level';
|
|
50
|
-
import {
|
|
51
|
-
import
|
|
52
|
-
import
|
|
53
|
-
import {
|
|
54
|
-
|
|
43
|
+
import { DbStatsOperation, DbStatsOptions } from './operations/stats';
|
|
44
|
+
import { ReadConcern } from './read_concern';
|
|
45
|
+
import { ReadPreference, ReadPreferenceLike } from './read_preference';
|
|
46
|
+
import {
|
|
47
|
+
Callback,
|
|
48
|
+
DEFAULT_PK_FACTORY,
|
|
49
|
+
filterOptions,
|
|
50
|
+
getTopology,
|
|
51
|
+
MongoDBNamespace,
|
|
52
|
+
resolveOptions
|
|
53
|
+
} from './utils';
|
|
54
|
+
import { WriteConcern, WriteConcernOptions } from './write_concern';
|
|
55
55
|
|
|
56
56
|
// Allowed parameters
|
|
57
57
|
const DB_OPTIONS_ALLOW_LIST = [
|
|
@@ -73,6 +73,7 @@ const DB_OPTIONS_ALLOW_LIST = [
|
|
|
73
73
|
'promoteBuffers',
|
|
74
74
|
'promoteLongs',
|
|
75
75
|
'bsonRegExp',
|
|
76
|
+
'enableUtf8Validation',
|
|
76
77
|
'promoteValues',
|
|
77
78
|
'compression',
|
|
78
79
|
'retryWrites'
|
|
@@ -184,8 +185,18 @@ export class Db {
|
|
|
184
185
|
return this.s.options;
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
|
|
188
|
+
/**
|
|
189
|
+
* slaveOk specified
|
|
190
|
+
* @deprecated Use secondaryOk instead
|
|
191
|
+
*/
|
|
188
192
|
get slaveOk(): boolean {
|
|
193
|
+
return this.secondaryOk;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Check if a secondary can be used (because the read preference is *not* set to primary)
|
|
198
|
+
*/
|
|
199
|
+
get secondaryOk(): boolean {
|
|
189
200
|
return this.s.readPreference?.preference !== 'primary' || false;
|
|
190
201
|
}
|
|
191
202
|
|
|
@@ -226,18 +237,17 @@ export class Db {
|
|
|
226
237
|
* @param options - Optional settings for the command
|
|
227
238
|
* @param callback - An optional callback, a Promise will be returned if none is provided
|
|
228
239
|
*/
|
|
229
|
-
createCollection<TSchema extends Document = Document>(name: string): Promise<Collection<TSchema>>;
|
|
230
240
|
createCollection<TSchema extends Document = Document>(
|
|
231
241
|
name: string,
|
|
232
|
-
|
|
233
|
-
):
|
|
242
|
+
options?: CreateCollectionOptions
|
|
243
|
+
): Promise<Collection<TSchema>>;
|
|
234
244
|
createCollection<TSchema extends Document = Document>(
|
|
235
245
|
name: string,
|
|
236
|
-
|
|
237
|
-
):
|
|
246
|
+
callback: Callback<Collection<TSchema>>
|
|
247
|
+
): void;
|
|
238
248
|
createCollection<TSchema extends Document = Document>(
|
|
239
249
|
name: string,
|
|
240
|
-
options: CreateCollectionOptions,
|
|
250
|
+
options: CreateCollectionOptions | undefined,
|
|
241
251
|
callback: Callback<Collection<TSchema>>
|
|
242
252
|
): void;
|
|
243
253
|
createCollection<TSchema extends Document = Document>(
|
package/src/deps.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
import type { deserialize, Document, serialize } from './bson';
|
|
3
|
+
import type { ProxyOptions } from './cmap/connection';
|
|
2
4
|
import { MongoMissingDependencyError } from './error';
|
|
3
5
|
import type { MongoClient } from './mongo_client';
|
|
4
|
-
import type { deserialize, Document, serialize } from './bson';
|
|
5
6
|
import { Callback, parsePackageVersion } from './utils';
|
|
6
7
|
|
|
7
8
|
export const PKG_VERSION = Symbol('kPkgVersion');
|
|
@@ -262,6 +263,7 @@ export interface AutoEncryptionOptions {
|
|
|
262
263
|
/** Command line arguments to use when auto-spawning a mongocryptd */
|
|
263
264
|
mongocryptdSpawnArgs?: string[];
|
|
264
265
|
};
|
|
266
|
+
proxyOptions?: ProxyOptions;
|
|
265
267
|
}
|
|
266
268
|
|
|
267
269
|
/** @public */
|
package/src/encrypter.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
import {
|
|
2
|
+
import { deserialize, serialize } from './bson';
|
|
3
|
+
import { MONGO_CLIENT_EVENTS } from './constants';
|
|
3
4
|
import type { AutoEncrypter, AutoEncryptionOptions } from './deps';
|
|
4
5
|
import { MongoInvalidArgumentError, MongoMissingDependencyError } from './error';
|
|
5
|
-
import {
|
|
6
|
+
import { MongoClient, MongoClientOptions } from './mongo_client';
|
|
6
7
|
import type { Callback } from './utils';
|
|
7
|
-
import { MONGO_CLIENT_EVENTS } from './operations/connect';
|
|
8
8
|
|
|
9
9
|
let AutoEncrypterClass: AutoEncrypter;
|
|
10
10
|
|
|
@@ -46,6 +46,15 @@ export class Encrypter {
|
|
|
46
46
|
options.autoEncryption.metadataClient = this.getInternalClient(client, uri, options);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
if (options.proxyHost) {
|
|
50
|
+
options.autoEncryption.proxyOptions = {
|
|
51
|
+
proxyHost: options.proxyHost,
|
|
52
|
+
proxyPort: options.proxyPort,
|
|
53
|
+
proxyUsername: options.proxyUsername,
|
|
54
|
+
proxyPassword: options.proxyPassword
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
49
58
|
options.autoEncryption.bson = Object.create(null);
|
|
50
59
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
51
60
|
options.autoEncryption.bson!.serialize = serialize;
|
package/src/error.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TopologyVersion } from './sdam/server_description';
|
|
2
1
|
import type { Document } from './bson';
|
|
2
|
+
import type { TopologyVersion } from './sdam/server_description';
|
|
3
3
|
import type { TopologyDescription } from './sdam/topology_description';
|
|
4
4
|
|
|
5
5
|
/** @public */
|
|
@@ -8,6 +8,27 @@ export type AnyError = MongoError | Error;
|
|
|
8
8
|
/** @internal */
|
|
9
9
|
const kErrorLabels = Symbol('errorLabels');
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
* The legacy error message from the server that indicates the node is not a writable primary
|
|
14
|
+
* https://github.com/mongodb/specifications/blob/b07c26dc40d04ac20349f989db531c9845fdd755/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-writable-primary-and-node-is-recovering
|
|
15
|
+
*/
|
|
16
|
+
export const LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE = 'not master';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
* The legacy error message from the server that indicates the node is not a primary or secondary
|
|
21
|
+
* https://github.com/mongodb/specifications/blob/b07c26dc40d04ac20349f989db531c9845fdd755/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-writable-primary-and-node-is-recovering
|
|
22
|
+
*/
|
|
23
|
+
export const LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE = 'not master or secondary';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
* The error message from the server that indicates the node is recovering
|
|
28
|
+
* https://github.com/mongodb/specifications/blob/b07c26dc40d04ac20349f989db531c9845fdd755/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#not-writable-primary-and-node-is-recovering
|
|
29
|
+
*/
|
|
30
|
+
export const NODE_IS_RECOVERING_ERROR_MESSAGE = 'node is recovering';
|
|
31
|
+
|
|
11
32
|
/** @internal MongoDB Error Codes */
|
|
12
33
|
export const MONGODB_ERROR_CODES = Object.freeze({
|
|
13
34
|
HostUnreachable: 6,
|
|
@@ -17,11 +38,11 @@ export const MONGODB_ERROR_CODES = Object.freeze({
|
|
|
17
38
|
PrimarySteppedDown: 189,
|
|
18
39
|
ExceededTimeLimit: 262,
|
|
19
40
|
SocketException: 9001,
|
|
20
|
-
|
|
41
|
+
NotWritablePrimary: 10107,
|
|
21
42
|
InterruptedAtShutdown: 11600,
|
|
22
43
|
InterruptedDueToReplStateChange: 11602,
|
|
23
|
-
|
|
24
|
-
|
|
44
|
+
NotPrimaryNoSecondaryOk: 13435,
|
|
45
|
+
NotPrimaryOrSecondary: 13436,
|
|
25
46
|
StaleShardVersion: 63,
|
|
26
47
|
StaleEpoch: 150,
|
|
27
48
|
StaleConfig: 13388,
|
|
@@ -46,11 +67,11 @@ export const GET_MORE_RESUMABLE_CODES = new Set<number>([
|
|
|
46
67
|
MONGODB_ERROR_CODES.PrimarySteppedDown,
|
|
47
68
|
MONGODB_ERROR_CODES.ExceededTimeLimit,
|
|
48
69
|
MONGODB_ERROR_CODES.SocketException,
|
|
49
|
-
MONGODB_ERROR_CODES.
|
|
70
|
+
MONGODB_ERROR_CODES.NotWritablePrimary,
|
|
50
71
|
MONGODB_ERROR_CODES.InterruptedAtShutdown,
|
|
51
72
|
MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
|
|
52
|
-
MONGODB_ERROR_CODES.
|
|
53
|
-
MONGODB_ERROR_CODES.
|
|
73
|
+
MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
|
|
74
|
+
MONGODB_ERROR_CODES.NotPrimaryOrSecondary,
|
|
54
75
|
MONGODB_ERROR_CODES.StaleShardVersion,
|
|
55
76
|
MONGODB_ERROR_CODES.StaleEpoch,
|
|
56
77
|
MONGODB_ERROR_CODES.StaleConfig,
|
|
@@ -675,19 +696,19 @@ const RETRYABLE_ERROR_CODES = new Set<number>([
|
|
|
675
696
|
MONGODB_ERROR_CODES.ShutdownInProgress,
|
|
676
697
|
MONGODB_ERROR_CODES.PrimarySteppedDown,
|
|
677
698
|
MONGODB_ERROR_CODES.SocketException,
|
|
678
|
-
MONGODB_ERROR_CODES.
|
|
699
|
+
MONGODB_ERROR_CODES.NotWritablePrimary,
|
|
679
700
|
MONGODB_ERROR_CODES.InterruptedAtShutdown,
|
|
680
701
|
MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
|
|
681
|
-
MONGODB_ERROR_CODES.
|
|
682
|
-
MONGODB_ERROR_CODES.
|
|
702
|
+
MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
|
|
703
|
+
MONGODB_ERROR_CODES.NotPrimaryOrSecondary
|
|
683
704
|
]);
|
|
684
705
|
|
|
685
706
|
const RETRYABLE_WRITE_ERROR_CODES = new Set<number>([
|
|
686
707
|
MONGODB_ERROR_CODES.InterruptedAtShutdown,
|
|
687
708
|
MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
|
|
688
|
-
MONGODB_ERROR_CODES.
|
|
689
|
-
MONGODB_ERROR_CODES.
|
|
690
|
-
MONGODB_ERROR_CODES.
|
|
709
|
+
MONGODB_ERROR_CODES.NotWritablePrimary,
|
|
710
|
+
MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
|
|
711
|
+
MONGODB_ERROR_CODES.NotPrimaryOrSecondary,
|
|
691
712
|
MONGODB_ERROR_CODES.PrimarySteppedDown,
|
|
692
713
|
MONGODB_ERROR_CODES.ShutdownInProgress,
|
|
693
714
|
MONGODB_ERROR_CODES.HostNotFound,
|
|
@@ -697,6 +718,10 @@ const RETRYABLE_WRITE_ERROR_CODES = new Set<number>([
|
|
|
697
718
|
MONGODB_ERROR_CODES.ExceededTimeLimit
|
|
698
719
|
]);
|
|
699
720
|
|
|
721
|
+
export function isRetryableEndTransactionError(error: MongoError): boolean {
|
|
722
|
+
return error.hasErrorLabel('RetryableWriteError');
|
|
723
|
+
}
|
|
724
|
+
|
|
700
725
|
export function isRetryableWriteError(error: MongoError): boolean {
|
|
701
726
|
if (error instanceof MongoWriteConcernError) {
|
|
702
727
|
return RETRYABLE_WRITE_ERROR_CODES.has(error.result?.code ?? error.code ?? 0);
|
|
@@ -710,8 +735,8 @@ export function isRetryableError(error: MongoError): boolean {
|
|
|
710
735
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
711
736
|
(typeof error.code === 'number' && RETRYABLE_ERROR_CODES.has(error.code!)) ||
|
|
712
737
|
error instanceof MongoNetworkError ||
|
|
713
|
-
!!error.message.match(
|
|
714
|
-
!!error.message.match(
|
|
738
|
+
!!error.message.match(new RegExp(LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE)) ||
|
|
739
|
+
!!error.message.match(new RegExp(NODE_IS_RECOVERING_ERROR_MESSAGE))
|
|
715
740
|
);
|
|
716
741
|
}
|
|
717
742
|
|
|
@@ -720,12 +745,12 @@ const SDAM_RECOVERING_CODES = new Set<number>([
|
|
|
720
745
|
MONGODB_ERROR_CODES.PrimarySteppedDown,
|
|
721
746
|
MONGODB_ERROR_CODES.InterruptedAtShutdown,
|
|
722
747
|
MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
|
|
723
|
-
MONGODB_ERROR_CODES.
|
|
748
|
+
MONGODB_ERROR_CODES.NotPrimaryOrSecondary
|
|
724
749
|
]);
|
|
725
750
|
|
|
726
|
-
const
|
|
727
|
-
MONGODB_ERROR_CODES.
|
|
728
|
-
MONGODB_ERROR_CODES.
|
|
751
|
+
const SDAM_NOTPRIMARY_CODES = new Set<number>([
|
|
752
|
+
MONGODB_ERROR_CODES.NotWritablePrimary,
|
|
753
|
+
MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
|
|
729
754
|
MONGODB_ERROR_CODES.LegacyNotPrimary
|
|
730
755
|
]);
|
|
731
756
|
|
|
@@ -740,20 +765,23 @@ function isRecoveringError(err: MongoError) {
|
|
|
740
765
|
return SDAM_RECOVERING_CODES.has(err.code);
|
|
741
766
|
}
|
|
742
767
|
|
|
743
|
-
return
|
|
768
|
+
return (
|
|
769
|
+
new RegExp(LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE).test(err.message) ||
|
|
770
|
+
new RegExp(NODE_IS_RECOVERING_ERROR_MESSAGE).test(err.message)
|
|
771
|
+
);
|
|
744
772
|
}
|
|
745
773
|
|
|
746
|
-
function
|
|
774
|
+
function isNotWritablePrimaryError(err: MongoError) {
|
|
747
775
|
if (typeof err.code === 'number') {
|
|
748
776
|
// If any error code exists, we ignore the error.message
|
|
749
|
-
return
|
|
777
|
+
return SDAM_NOTPRIMARY_CODES.has(err.code);
|
|
750
778
|
}
|
|
751
779
|
|
|
752
780
|
if (isRecoveringError(err)) {
|
|
753
781
|
return false;
|
|
754
782
|
}
|
|
755
783
|
|
|
756
|
-
return
|
|
784
|
+
return new RegExp(LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE).test(err.message);
|
|
757
785
|
}
|
|
758
786
|
|
|
759
787
|
export function isNodeShuttingDownError(err: MongoError): boolean {
|
|
@@ -774,7 +802,7 @@ export function isSDAMUnrecoverableError(error: MongoError): boolean {
|
|
|
774
802
|
return true;
|
|
775
803
|
}
|
|
776
804
|
|
|
777
|
-
return isRecoveringError(error) ||
|
|
805
|
+
return isRecoveringError(error) || isNotWritablePrimaryError(error);
|
|
778
806
|
}
|
|
779
807
|
|
|
780
808
|
export function isNetworkTimeoutError(err: MongoError): err is MongoNetworkError {
|
package/src/gridfs/download.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Readable } from 'stream';
|
|
2
|
+
|
|
3
|
+
import type { Document, ObjectId } from '../bson';
|
|
4
|
+
import type { Collection } from '../collection';
|
|
5
|
+
import type { FindCursor } from '../cursor/find_cursor';
|
|
2
6
|
import {
|
|
3
|
-
MongoRuntimeError,
|
|
4
7
|
MongoGridFSChunkError,
|
|
5
8
|
MongoGridFSStreamError,
|
|
6
|
-
MongoInvalidArgumentError
|
|
9
|
+
MongoInvalidArgumentError,
|
|
10
|
+
MongoRuntimeError
|
|
7
11
|
} from '../error';
|
|
8
|
-
import type { Document } from '../bson';
|
|
9
12
|
import type { FindOptions } from '../operations/find';
|
|
13
|
+
import type { ReadPreference } from '../read_preference';
|
|
10
14
|
import type { Sort } from '../sort';
|
|
11
15
|
import type { Callback } from '../utils';
|
|
12
|
-
import type { Collection } from '../collection';
|
|
13
|
-
import type { ReadPreference } from '../read_preference';
|
|
14
16
|
import type { GridFSChunk } from './upload';
|
|
15
|
-
import type { FindCursor } from '../cursor/find_cursor';
|
|
16
|
-
import type { ObjectId } from 'bson';
|
|
17
17
|
|
|
18
18
|
/** @public */
|
|
19
19
|
export interface GridFSBucketReadStreamOptions {
|
|
@@ -262,7 +262,9 @@ function doRead(stream: GridFSBucketReadStream): void {
|
|
|
262
262
|
if (bytesRemaining <= 0) {
|
|
263
263
|
return stream.emit(
|
|
264
264
|
GridFSBucketReadStream.ERROR,
|
|
265
|
-
new MongoGridFSChunkError(
|
|
265
|
+
new MongoGridFSChunkError(
|
|
266
|
+
`ExtraChunk: Got unexpected n: ${doc.n}, expected file length ${stream.s.file.length} bytes but already read ${stream.s.bytesRead} bytes`
|
|
267
|
+
)
|
|
266
268
|
);
|
|
267
269
|
}
|
|
268
270
|
|
package/src/gridfs/index.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import type { ObjectId } from '../bson';
|
|
2
|
+
import type { Collection } from '../collection';
|
|
3
|
+
import type { FindCursor } from '../cursor/find_cursor';
|
|
4
|
+
import type { Db } from '../db';
|
|
1
5
|
import { MongoRuntimeError } from '../error';
|
|
6
|
+
import type { Logger } from '../logger';
|
|
7
|
+
import { Filter, TypedEventEmitter } from '../mongo_types';
|
|
8
|
+
import type { ReadPreference } from '../read_preference';
|
|
9
|
+
import type { Sort } from '../sort';
|
|
10
|
+
import { Callback, executeLegacyOperation, getTopology } from '../utils';
|
|
11
|
+
import { WriteConcern, WriteConcernOptions } from '../write_concern';
|
|
12
|
+
import type { FindOptions } from './../operations/find';
|
|
2
13
|
import {
|
|
3
14
|
GridFSBucketReadStream,
|
|
4
15
|
GridFSBucketReadStreamOptions,
|
|
@@ -6,17 +17,6 @@ import {
|
|
|
6
17
|
GridFSFile
|
|
7
18
|
} from './download';
|
|
8
19
|
import { GridFSBucketWriteStream, GridFSBucketWriteStreamOptions, GridFSChunk } from './upload';
|
|
9
|
-
import { executeLegacyOperation, Callback, getTopology } from '../utils';
|
|
10
|
-
import { WriteConcernOptions, WriteConcern } from '../write_concern';
|
|
11
|
-
import type { ObjectId } from '../bson';
|
|
12
|
-
import type { Db } from '../db';
|
|
13
|
-
import type { ReadPreference } from '../read_preference';
|
|
14
|
-
import type { Collection } from '../collection';
|
|
15
|
-
import type { FindOptions } from './../operations/find';
|
|
16
|
-
import type { Sort } from '../sort';
|
|
17
|
-
import type { Logger } from '../logger';
|
|
18
|
-
import type { FindCursor } from '../cursor/find_cursor';
|
|
19
|
-
import { Filter, TypedEventEmitter } from '../mongo_types';
|
|
20
20
|
|
|
21
21
|
const DEFAULT_GRIDFS_BUCKET_OPTIONS: {
|
|
22
22
|
bucketName: string;
|
package/src/gridfs/upload.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Writable } from 'stream';
|
|
2
|
+
|
|
2
3
|
import type { Document } from '../bson';
|
|
3
4
|
import { ObjectId } from '../bson';
|
|
4
5
|
import type { Collection } from '../collection';
|
|
5
|
-
import { AnyError, MONGODB_ERROR_CODES, MongoError
|
|
6
|
+
import { AnyError, MongoAPIError, MONGODB_ERROR_CODES, MongoError } from '../error';
|
|
6
7
|
import { Callback, maybePromise } from '../utils';
|
|
7
8
|
import type { WriteConcernOptions } from '../write_concern';
|
|
8
9
|
import { WriteConcern } from './../write_concern';
|
|
@@ -171,21 +172,21 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
|
|
|
171
172
|
* @param encoding - Optional encoding for the buffer
|
|
172
173
|
* @param callback - Function to call when all files and chunks have been persisted to MongoDB
|
|
173
174
|
*/
|
|
174
|
-
end():
|
|
175
|
-
end(chunk: Buffer):
|
|
176
|
-
end(callback: Callback<GridFSFile | void>):
|
|
177
|
-
end(chunk: Buffer, callback: Callback<GridFSFile | void>):
|
|
178
|
-
end(chunk: Buffer, encoding: BufferEncoding):
|
|
175
|
+
end(): this;
|
|
176
|
+
end(chunk: Buffer): this;
|
|
177
|
+
end(callback: Callback<GridFSFile | void>): this;
|
|
178
|
+
end(chunk: Buffer, callback: Callback<GridFSFile | void>): this;
|
|
179
|
+
end(chunk: Buffer, encoding: BufferEncoding): this;
|
|
179
180
|
end(
|
|
180
181
|
chunk: Buffer,
|
|
181
182
|
encoding: BufferEncoding | undefined,
|
|
182
183
|
callback: Callback<GridFSFile | void>
|
|
183
|
-
):
|
|
184
|
+
): this;
|
|
184
185
|
end(
|
|
185
186
|
chunkOrCallback?: Buffer | Callback<GridFSFile | void>,
|
|
186
187
|
encodingOrCallback?: BufferEncoding | Callback<GridFSFile | void>,
|
|
187
188
|
callback?: Callback<GridFSFile | void>
|
|
188
|
-
):
|
|
189
|
+
): this {
|
|
189
190
|
const chunk = typeof chunkOrCallback === 'function' ? undefined : chunkOrCallback;
|
|
190
191
|
const encoding = typeof encodingOrCallback === 'function' ? undefined : encodingOrCallback;
|
|
191
192
|
callback =
|
|
@@ -195,7 +196,7 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
|
|
|
195
196
|
? encodingOrCallback
|
|
196
197
|
: callback;
|
|
197
198
|
|
|
198
|
-
if (checkAborted(this, callback)) return;
|
|
199
|
+
if (checkAborted(this, callback)) return this;
|
|
199
200
|
|
|
200
201
|
this.state.streamEnd = true;
|
|
201
202
|
|
|
@@ -207,12 +208,14 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
|
|
|
207
208
|
|
|
208
209
|
if (!chunk) {
|
|
209
210
|
waitForIndexes(this, () => !!writeRemnant(this));
|
|
210
|
-
return;
|
|
211
|
+
return this;
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
this.write(chunk, encoding, () => {
|
|
214
215
|
writeRemnant(this);
|
|
215
216
|
});
|
|
217
|
+
|
|
218
|
+
return this;
|
|
216
219
|
}
|
|
217
220
|
}
|
|
218
221
|
|