mongodb 5.1.0 → 5.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 +25 -22
- package/lib/admin.js +2 -0
- package/lib/admin.js.map +1 -1
- package/lib/bulk/common.js +28 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +1 -1
- package/lib/cmap/auth/auth_provider.js +21 -10
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +71 -116
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +7 -9
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +20 -29
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +125 -140
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +28 -0
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +178 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +41 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js +115 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js +3 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +59 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
- package/lib/cmap/auth/plain.js +4 -5
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/providers.js +1 -1
- package/lib/cmap/auth/providers.js.map +1 -1
- package/lib/cmap/auth/scram.js +45 -73
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +8 -11
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +14 -5
- 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 +73 -86
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +19 -23
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +56 -14
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/connection_pool_events.js +28 -3
- package/lib/cmap/connection_pool_events.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +173 -0
- package/lib/cmap/handshake/client_metadata.js.map +1 -0
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +1 -16
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +10 -10
- package/lib/connection_string.js +50 -69
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +11 -0
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +2 -1
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +1 -1
- package/lib/db.js +4 -2
- package/lib/db.js.map +1 -1
- package/lib/error.js +2 -1
- package/lib/error.js.map +1 -1
- package/lib/mongo_client.js +23 -2
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +236 -23
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/execute_operation.js +8 -27
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +1 -8
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/read_concern.js +1 -1
- package/lib/read_preference.js +2 -2
- package/lib/sdam/srv_polling.js +1 -15
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +0 -16
- package/lib/sdam/topology.js.map +1 -1
- package/lib/utils.js +33 -90
- package/lib/utils.js.map +1 -1
- package/lib/write_concern.js +1 -1
- package/mongodb.d.ts +242 -93
- package/package.json +30 -31
- package/src/admin.ts +2 -0
- package/src/bulk/common.ts +29 -8
- package/src/change_stream.ts +5 -5
- package/src/cmap/auth/auth_provider.ts +29 -16
- package/src/cmap/auth/gssapi.ts +102 -149
- package/src/cmap/auth/mongo_credentials.ts +14 -23
- package/src/cmap/auth/mongocr.ts +31 -36
- package/src/cmap/auth/mongodb_aws.ts +166 -189
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +26 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +259 -0
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +47 -0
- package/src/cmap/auth/mongodb_oidc/token_entry_cache.ts +166 -0
- package/src/cmap/auth/mongodb_oidc/workflow.ts +21 -0
- package/src/cmap/auth/mongodb_oidc.ts +101 -17
- package/src/cmap/auth/plain.ts +6 -6
- package/src/cmap/auth/providers.ts +2 -2
- package/src/cmap/auth/scram.ts +56 -90
- package/src/cmap/auth/x509.ts +12 -18
- package/src/cmap/command_monitoring_events.ts +18 -3
- package/src/cmap/commands.ts +1 -1
- package/src/cmap/connect.ts +92 -114
- package/src/cmap/connection.ts +39 -25
- package/src/cmap/connection_pool.ts +89 -18
- package/src/cmap/connection_pool_events.ts +68 -6
- package/src/cmap/handshake/client_metadata.ts +272 -0
- package/src/cmap/message_stream.ts +0 -2
- package/src/cmap/wire_protocol/compression.ts +1 -1
- package/src/cmap/wire_protocol/shared.ts +1 -23
- package/src/collection.ts +13 -13
- package/src/connection_string.ts +56 -72
- package/src/constants.ts +11 -0
- package/src/cursor/abstract_cursor.ts +3 -2
- package/src/cursor/change_stream_cursor.ts +5 -5
- package/src/cursor/find_cursor.ts +1 -1
- package/src/db.ts +4 -2
- package/src/deps.ts +3 -2
- package/src/error.ts +3 -2
- package/src/index.ts +21 -3
- package/src/mongo_client.ts +60 -14
- package/src/mongo_logger.ts +341 -40
- package/src/mongo_types.ts +2 -2
- package/src/operations/add_user.ts +8 -2
- package/src/operations/aggregate.ts +1 -1
- package/src/operations/create_collection.ts +1 -1
- package/src/operations/execute_operation.ts +8 -25
- package/src/operations/find.ts +1 -11
- package/src/operations/find_and_modify.ts +4 -4
- package/src/operations/set_profiling_level.ts +1 -1
- package/src/operations/stats.ts +1 -1
- package/src/operations/update.ts +8 -4
- package/src/read_concern.ts +2 -2
- package/src/read_preference.ts +3 -3
- package/src/sdam/common.ts +2 -2
- package/src/sdam/srv_polling.ts +1 -16
- package/src/sdam/topology.ts +1 -23
- package/src/transactions.ts +1 -1
- package/src/utils.ts +37 -147
- package/src/write_concern.ts +1 -1
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { ObjectId } from '../bson';
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
CONNECTION_CHECK_OUT_FAILED,
|
|
4
|
+
CONNECTION_CHECK_OUT_STARTED,
|
|
5
|
+
CONNECTION_CHECKED_IN,
|
|
6
|
+
CONNECTION_CHECKED_OUT,
|
|
7
|
+
CONNECTION_CLOSED,
|
|
8
|
+
CONNECTION_CREATED,
|
|
9
|
+
CONNECTION_POOL_CLEARED,
|
|
10
|
+
CONNECTION_POOL_CLOSED,
|
|
11
|
+
CONNECTION_POOL_CREATED,
|
|
12
|
+
CONNECTION_POOL_READY,
|
|
13
|
+
CONNECTION_READY
|
|
14
|
+
} from '../constants';
|
|
15
|
+
import type { MongoError } from '../error';
|
|
3
16
|
import type { Connection } from './connection';
|
|
4
17
|
import type { ConnectionPool, ConnectionPoolOptions } from './connection_pool';
|
|
5
18
|
|
|
@@ -8,11 +21,24 @@ import type { ConnectionPool, ConnectionPoolOptions } from './connection_pool';
|
|
|
8
21
|
* @public
|
|
9
22
|
* @category Event
|
|
10
23
|
*/
|
|
11
|
-
export class ConnectionPoolMonitoringEvent {
|
|
24
|
+
export abstract class ConnectionPoolMonitoringEvent {
|
|
12
25
|
/** A timestamp when the event was created */
|
|
13
26
|
time: Date;
|
|
14
27
|
/** The address (host/port pair) of the pool */
|
|
15
28
|
address: string;
|
|
29
|
+
/** @internal */
|
|
30
|
+
abstract name:
|
|
31
|
+
| typeof CONNECTION_CHECK_OUT_FAILED
|
|
32
|
+
| typeof CONNECTION_CHECK_OUT_STARTED
|
|
33
|
+
| typeof CONNECTION_CHECKED_IN
|
|
34
|
+
| typeof CONNECTION_CHECKED_OUT
|
|
35
|
+
| typeof CONNECTION_CLOSED
|
|
36
|
+
| typeof CONNECTION_CREATED
|
|
37
|
+
| typeof CONNECTION_POOL_CLEARED
|
|
38
|
+
| typeof CONNECTION_POOL_CLOSED
|
|
39
|
+
| typeof CONNECTION_POOL_CREATED
|
|
40
|
+
| typeof CONNECTION_POOL_READY
|
|
41
|
+
| typeof CONNECTION_READY;
|
|
16
42
|
|
|
17
43
|
/** @internal */
|
|
18
44
|
constructor(pool: ConnectionPool) {
|
|
@@ -29,6 +55,8 @@ export class ConnectionPoolMonitoringEvent {
|
|
|
29
55
|
export class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
|
|
30
56
|
/** The options used to create this connection pool */
|
|
31
57
|
options?: ConnectionPoolOptions;
|
|
58
|
+
/** @internal */
|
|
59
|
+
name = CONNECTION_POOL_CREATED;
|
|
32
60
|
|
|
33
61
|
/** @internal */
|
|
34
62
|
constructor(pool: ConnectionPool) {
|
|
@@ -43,6 +71,9 @@ export class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
43
71
|
* @category Event
|
|
44
72
|
*/
|
|
45
73
|
export class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEvent {
|
|
74
|
+
/** @internal */
|
|
75
|
+
name = CONNECTION_POOL_READY;
|
|
76
|
+
|
|
46
77
|
/** @internal */
|
|
47
78
|
constructor(pool: ConnectionPool) {
|
|
48
79
|
super(pool);
|
|
@@ -55,6 +86,9 @@ export class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEvent {
|
|
|
55
86
|
* @category Event
|
|
56
87
|
*/
|
|
57
88
|
export class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
|
|
89
|
+
/** @internal */
|
|
90
|
+
name = CONNECTION_POOL_CLOSED;
|
|
91
|
+
|
|
58
92
|
/** @internal */
|
|
59
93
|
constructor(pool: ConnectionPool) {
|
|
60
94
|
super(pool);
|
|
@@ -69,6 +103,8 @@ export class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
69
103
|
export class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
|
|
70
104
|
/** A monotonically increasing, per-pool id for the newly created connection */
|
|
71
105
|
connectionId: number | '<monitor>';
|
|
106
|
+
/** @internal */
|
|
107
|
+
name = CONNECTION_CREATED;
|
|
72
108
|
|
|
73
109
|
/** @internal */
|
|
74
110
|
constructor(pool: ConnectionPool, connection: { id: number | '<monitor>' }) {
|
|
@@ -85,6 +121,8 @@ export class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
85
121
|
export class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
|
|
86
122
|
/** The id of the connection */
|
|
87
123
|
connectionId: number | '<monitor>';
|
|
124
|
+
/** @internal */
|
|
125
|
+
name = CONNECTION_READY;
|
|
88
126
|
|
|
89
127
|
/** @internal */
|
|
90
128
|
constructor(pool: ConnectionPool, connection: Connection) {
|
|
@@ -104,17 +142,23 @@ export class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
104
142
|
/** The reason the connection was closed */
|
|
105
143
|
reason: string;
|
|
106
144
|
serviceId?: ObjectId;
|
|
145
|
+
/** @internal */
|
|
146
|
+
name = CONNECTION_CLOSED;
|
|
147
|
+
/** @internal */
|
|
148
|
+
error: MongoError | null;
|
|
107
149
|
|
|
108
150
|
/** @internal */
|
|
109
151
|
constructor(
|
|
110
152
|
pool: ConnectionPool,
|
|
111
153
|
connection: Pick<Connection, 'id' | 'serviceId'>,
|
|
112
|
-
reason:
|
|
154
|
+
reason: 'idle' | 'stale' | 'poolClosed' | 'error',
|
|
155
|
+
error?: MongoError
|
|
113
156
|
) {
|
|
114
157
|
super(pool);
|
|
115
158
|
this.connectionId = connection.id;
|
|
116
|
-
this.reason = reason
|
|
159
|
+
this.reason = reason;
|
|
117
160
|
this.serviceId = connection.serviceId;
|
|
161
|
+
this.error = error ?? null;
|
|
118
162
|
}
|
|
119
163
|
}
|
|
120
164
|
|
|
@@ -124,6 +168,9 @@ export class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
124
168
|
* @category Event
|
|
125
169
|
*/
|
|
126
170
|
export class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent {
|
|
171
|
+
/** @internal */
|
|
172
|
+
name = CONNECTION_CHECK_OUT_STARTED;
|
|
173
|
+
|
|
127
174
|
/** @internal */
|
|
128
175
|
constructor(pool: ConnectionPool) {
|
|
129
176
|
super(pool);
|
|
@@ -137,12 +184,21 @@ export class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEven
|
|
|
137
184
|
*/
|
|
138
185
|
export class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent {
|
|
139
186
|
/** The reason the attempt to check out failed */
|
|
140
|
-
reason:
|
|
187
|
+
reason: string;
|
|
188
|
+
/** @internal */
|
|
189
|
+
error?: MongoError;
|
|
190
|
+
/** @internal */
|
|
191
|
+
name = CONNECTION_CHECK_OUT_FAILED;
|
|
141
192
|
|
|
142
193
|
/** @internal */
|
|
143
|
-
constructor(
|
|
194
|
+
constructor(
|
|
195
|
+
pool: ConnectionPool,
|
|
196
|
+
reason: 'poolClosed' | 'timeout' | 'connectionError',
|
|
197
|
+
error?: MongoError
|
|
198
|
+
) {
|
|
144
199
|
super(pool);
|
|
145
200
|
this.reason = reason;
|
|
201
|
+
this.error = error;
|
|
146
202
|
}
|
|
147
203
|
}
|
|
148
204
|
|
|
@@ -154,6 +210,8 @@ export class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent
|
|
|
154
210
|
export class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
|
|
155
211
|
/** The id of the connection */
|
|
156
212
|
connectionId: number | '<monitor>';
|
|
213
|
+
/** @internal */
|
|
214
|
+
name = CONNECTION_CHECKED_OUT;
|
|
157
215
|
|
|
158
216
|
/** @internal */
|
|
159
217
|
constructor(pool: ConnectionPool, connection: Connection) {
|
|
@@ -170,6 +228,8 @@ export class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
|
|
|
170
228
|
export class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent {
|
|
171
229
|
/** The id of the connection */
|
|
172
230
|
connectionId: number | '<monitor>';
|
|
231
|
+
/** @internal */
|
|
232
|
+
name = CONNECTION_CHECKED_IN;
|
|
173
233
|
|
|
174
234
|
/** @internal */
|
|
175
235
|
constructor(pool: ConnectionPool, connection: Connection) {
|
|
@@ -188,6 +248,8 @@ export class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent {
|
|
|
188
248
|
serviceId?: ObjectId;
|
|
189
249
|
|
|
190
250
|
interruptInUseConnections?: boolean;
|
|
251
|
+
/** @internal */
|
|
252
|
+
name = CONNECTION_POOL_CLEARED;
|
|
191
253
|
|
|
192
254
|
/** @internal */
|
|
193
255
|
constructor(
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import * as os from 'os';
|
|
2
|
+
import * as process from 'process';
|
|
3
|
+
|
|
4
|
+
import { BSON, Int32 } from '../../bson';
|
|
5
|
+
import { MongoInvalidArgumentError } from '../../error';
|
|
6
|
+
import type { MongoOptions } from '../../mongo_client';
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9
|
+
const NODE_DRIVER_VERSION = require('../../../package.json').version;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
* @see https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#hello-command
|
|
14
|
+
*/
|
|
15
|
+
export interface ClientMetadata {
|
|
16
|
+
driver: {
|
|
17
|
+
name: string;
|
|
18
|
+
version: string;
|
|
19
|
+
};
|
|
20
|
+
os: {
|
|
21
|
+
type: string;
|
|
22
|
+
name?: NodeJS.Platform;
|
|
23
|
+
architecture?: string;
|
|
24
|
+
version?: string;
|
|
25
|
+
};
|
|
26
|
+
platform: string;
|
|
27
|
+
application?: {
|
|
28
|
+
name: string;
|
|
29
|
+
};
|
|
30
|
+
/** FaaS environment information */
|
|
31
|
+
env?: {
|
|
32
|
+
name: 'aws.lambda' | 'gcp.func' | 'azure.func' | 'vercel';
|
|
33
|
+
timeout_sec?: Int32;
|
|
34
|
+
memory_mb?: Int32;
|
|
35
|
+
region?: string;
|
|
36
|
+
url?: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @public */
|
|
41
|
+
export interface ClientMetadataOptions {
|
|
42
|
+
driverInfo?: {
|
|
43
|
+
name?: string;
|
|
44
|
+
version?: string;
|
|
45
|
+
platform?: string;
|
|
46
|
+
};
|
|
47
|
+
appName?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @internal */
|
|
51
|
+
export class LimitedSizeDocument {
|
|
52
|
+
private document = new Map();
|
|
53
|
+
/** BSON overhead: Int32 + Null byte */
|
|
54
|
+
private documentSize = 5;
|
|
55
|
+
constructor(private maxSize: number) {}
|
|
56
|
+
|
|
57
|
+
/** Only adds key/value if the bsonByteLength is less than MAX_SIZE */
|
|
58
|
+
public ifItFitsItSits(key: string, value: Record<string, any> | string): boolean {
|
|
59
|
+
// The BSON byteLength of the new element is the same as serializing it to its own document
|
|
60
|
+
// subtracting the document size int32 and the null terminator.
|
|
61
|
+
const newElementSize = BSON.serialize(new Map().set(key, value)).byteLength - 5;
|
|
62
|
+
|
|
63
|
+
if (newElementSize + this.documentSize > this.maxSize) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.documentSize += newElementSize;
|
|
68
|
+
|
|
69
|
+
this.document.set(key, value);
|
|
70
|
+
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
toObject(): ClientMetadata {
|
|
75
|
+
return BSON.deserialize(BSON.serialize(this.document), {
|
|
76
|
+
promoteLongs: false,
|
|
77
|
+
promoteBuffers: false,
|
|
78
|
+
promoteValues: false,
|
|
79
|
+
useBigInt64: false
|
|
80
|
+
}) as ClientMetadata;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
type MakeClientMetadataOptions = Pick<MongoOptions, 'appName' | 'driverInfo'>;
|
|
85
|
+
/**
|
|
86
|
+
* From the specs:
|
|
87
|
+
* Implementors SHOULD cumulatively update fields in the following order until the document is under the size limit:
|
|
88
|
+
* 1. Omit fields from `env` except `env.name`.
|
|
89
|
+
* 2. Omit fields from `os` except `os.type`.
|
|
90
|
+
* 3. Omit the `env` document entirely.
|
|
91
|
+
* 4. Truncate `platform`. -- special we do not truncate this field
|
|
92
|
+
*/
|
|
93
|
+
export function makeClientMetadata(options: MakeClientMetadataOptions): ClientMetadata {
|
|
94
|
+
const metadataDocument = new LimitedSizeDocument(512);
|
|
95
|
+
|
|
96
|
+
const { appName = '' } = options;
|
|
97
|
+
// Add app name first, it must be sent
|
|
98
|
+
if (appName.length > 0) {
|
|
99
|
+
const name =
|
|
100
|
+
Buffer.byteLength(appName, 'utf8') <= 128
|
|
101
|
+
? options.appName
|
|
102
|
+
: Buffer.from(appName, 'utf8').subarray(0, 128).toString('utf8');
|
|
103
|
+
metadataDocument.ifItFitsItSits('application', { name });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const { name = '', version = '', platform = '' } = options.driverInfo;
|
|
107
|
+
|
|
108
|
+
const driverInfo = {
|
|
109
|
+
name: name.length > 0 ? `nodejs|${name}` : 'nodejs',
|
|
110
|
+
version: version.length > 0 ? `${NODE_DRIVER_VERSION}|${version}` : NODE_DRIVER_VERSION
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (!metadataDocument.ifItFitsItSits('driver', driverInfo)) {
|
|
114
|
+
throw new MongoInvalidArgumentError(
|
|
115
|
+
'Unable to include driverInfo name and version, metadata cannot exceed 512 bytes'
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let runtimeInfo = getRuntimeInfo();
|
|
120
|
+
if (platform.length > 0) {
|
|
121
|
+
runtimeInfo = `${runtimeInfo}|${platform}`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!metadataDocument.ifItFitsItSits('platform', runtimeInfo)) {
|
|
125
|
+
throw new MongoInvalidArgumentError(
|
|
126
|
+
'Unable to include driverInfo platform, metadata cannot exceed 512 bytes'
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Note: order matters, os.type is last so it will be removed last if we're at maxSize
|
|
131
|
+
const osInfo = new Map()
|
|
132
|
+
.set('name', process.platform)
|
|
133
|
+
.set('architecture', process.arch)
|
|
134
|
+
.set('version', os.release())
|
|
135
|
+
.set('type', os.type());
|
|
136
|
+
|
|
137
|
+
if (!metadataDocument.ifItFitsItSits('os', osInfo)) {
|
|
138
|
+
for (const key of osInfo.keys()) {
|
|
139
|
+
osInfo.delete(key);
|
|
140
|
+
if (osInfo.size === 0) break;
|
|
141
|
+
if (metadataDocument.ifItFitsItSits('os', osInfo)) break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const faasEnv = getFAASEnv();
|
|
146
|
+
if (faasEnv != null) {
|
|
147
|
+
if (!metadataDocument.ifItFitsItSits('env', faasEnv)) {
|
|
148
|
+
for (const key of faasEnv.keys()) {
|
|
149
|
+
faasEnv.delete(key);
|
|
150
|
+
if (faasEnv.size === 0) break;
|
|
151
|
+
if (metadataDocument.ifItFitsItSits('env', faasEnv)) break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return metadataDocument.toObject();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Collects FaaS metadata.
|
|
161
|
+
* - `name` MUST be the last key in the Map returned.
|
|
162
|
+
*/
|
|
163
|
+
export function getFAASEnv(): Map<string, string | Int32> | null {
|
|
164
|
+
const {
|
|
165
|
+
AWS_EXECUTION_ENV = '',
|
|
166
|
+
AWS_LAMBDA_RUNTIME_API = '',
|
|
167
|
+
FUNCTIONS_WORKER_RUNTIME = '',
|
|
168
|
+
K_SERVICE = '',
|
|
169
|
+
FUNCTION_NAME = '',
|
|
170
|
+
VERCEL = '',
|
|
171
|
+
AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '',
|
|
172
|
+
AWS_REGION = '',
|
|
173
|
+
FUNCTION_MEMORY_MB = '',
|
|
174
|
+
FUNCTION_REGION = '',
|
|
175
|
+
FUNCTION_TIMEOUT_SEC = '',
|
|
176
|
+
VERCEL_REGION = ''
|
|
177
|
+
} = process.env;
|
|
178
|
+
|
|
179
|
+
const isAWSFaaS = AWS_EXECUTION_ENV.length > 0 || AWS_LAMBDA_RUNTIME_API.length > 0;
|
|
180
|
+
const isAzureFaaS = FUNCTIONS_WORKER_RUNTIME.length > 0;
|
|
181
|
+
const isGCPFaaS = K_SERVICE.length > 0 || FUNCTION_NAME.length > 0;
|
|
182
|
+
const isVercelFaaS = VERCEL.length > 0;
|
|
183
|
+
|
|
184
|
+
// Note: order matters, name must always be the last key
|
|
185
|
+
const faasEnv = new Map();
|
|
186
|
+
|
|
187
|
+
// When isVercelFaaS is true so is isAWSFaaS; Vercel inherits the AWS env
|
|
188
|
+
if (isVercelFaaS && !(isAzureFaaS || isGCPFaaS)) {
|
|
189
|
+
if (VERCEL_REGION.length > 0) {
|
|
190
|
+
faasEnv.set('region', VERCEL_REGION);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
faasEnv.set('name', 'vercel');
|
|
194
|
+
return faasEnv;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (isAWSFaaS && !(isAzureFaaS || isGCPFaaS || isVercelFaaS)) {
|
|
198
|
+
if (AWS_REGION.length > 0) {
|
|
199
|
+
faasEnv.set('region', AWS_REGION);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (
|
|
203
|
+
AWS_LAMBDA_FUNCTION_MEMORY_SIZE.length > 0 &&
|
|
204
|
+
Number.isInteger(+AWS_LAMBDA_FUNCTION_MEMORY_SIZE)
|
|
205
|
+
) {
|
|
206
|
+
faasEnv.set('memory_mb', new Int32(AWS_LAMBDA_FUNCTION_MEMORY_SIZE));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
faasEnv.set('name', 'aws.lambda');
|
|
210
|
+
return faasEnv;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (isAzureFaaS && !(isGCPFaaS || isAWSFaaS || isVercelFaaS)) {
|
|
214
|
+
faasEnv.set('name', 'azure.func');
|
|
215
|
+
return faasEnv;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (isGCPFaaS && !(isAzureFaaS || isAWSFaaS || isVercelFaaS)) {
|
|
219
|
+
if (FUNCTION_REGION.length > 0) {
|
|
220
|
+
faasEnv.set('region', FUNCTION_REGION);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (FUNCTION_MEMORY_MB.length > 0 && Number.isInteger(+FUNCTION_MEMORY_MB)) {
|
|
224
|
+
faasEnv.set('memory_mb', new Int32(FUNCTION_MEMORY_MB));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (FUNCTION_TIMEOUT_SEC.length > 0 && Number.isInteger(+FUNCTION_TIMEOUT_SEC)) {
|
|
228
|
+
faasEnv.set('timeout_sec', new Int32(FUNCTION_TIMEOUT_SEC));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
faasEnv.set('name', 'gcp.func');
|
|
232
|
+
return faasEnv;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @internal
|
|
240
|
+
* This type represents the global Deno object and the minimal type contract we expect it to satisfy.
|
|
241
|
+
*/
|
|
242
|
+
declare const Deno: { version?: { deno?: string } } | undefined;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @internal
|
|
246
|
+
* This type represents the global Bun object and the minimal type contract we expect it to satisfy.
|
|
247
|
+
*/
|
|
248
|
+
declare const Bun: { (): void; version?: string } | undefined;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @internal
|
|
252
|
+
* Get current JavaScript runtime platform
|
|
253
|
+
*
|
|
254
|
+
* NOTE: The version information fetching is intentionally written defensively
|
|
255
|
+
* to avoid having a released driver version that becomes incompatible
|
|
256
|
+
* with a future change to these global objects.
|
|
257
|
+
*/
|
|
258
|
+
function getRuntimeInfo(): string {
|
|
259
|
+
if ('Deno' in globalThis) {
|
|
260
|
+
const version = typeof Deno?.version?.deno === 'string' ? Deno?.version?.deno : '0.0.0-unknown';
|
|
261
|
+
|
|
262
|
+
return `Deno v${version}, ${os.endianness()}`;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if ('Bun' in globalThis) {
|
|
266
|
+
const version = typeof Bun?.version === 'string' ? Bun?.version : '0.0.0-unknown';
|
|
267
|
+
|
|
268
|
+
return `Bun v${version}, ${os.endianness()}`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return `Node.js ${process.version}, ${os.endianness()}`;
|
|
272
|
+
}
|
|
@@ -30,13 +30,11 @@ export interface MessageStreamOptions extends DuplexOptions {
|
|
|
30
30
|
export interface OperationDescription extends BSONSerializeOptions {
|
|
31
31
|
started: number;
|
|
32
32
|
cb: Callback<Document>;
|
|
33
|
-
command: boolean;
|
|
34
33
|
documentsReturnedIn?: string;
|
|
35
34
|
noResponse: boolean;
|
|
36
35
|
raw: boolean;
|
|
37
36
|
requestId: number;
|
|
38
37
|
session?: ClientSession;
|
|
39
|
-
socketTimeoutOverride?: boolean;
|
|
40
38
|
agreedCompressor?: CompressorName;
|
|
41
39
|
zlibCompressionLevel?: number;
|
|
42
40
|
$clusterTime?: Document;
|
|
@@ -14,7 +14,7 @@ export const Compressor = Object.freeze({
|
|
|
14
14
|
} as const);
|
|
15
15
|
|
|
16
16
|
/** @public */
|
|
17
|
-
export type Compressor = typeof Compressor[CompressorName];
|
|
17
|
+
export type Compressor = (typeof Compressor)[CompressorName];
|
|
18
18
|
|
|
19
19
|
/** @public */
|
|
20
20
|
export type CompressorName = keyof typeof Compressor;
|
|
@@ -7,8 +7,7 @@ import type { Server } from '../../sdam/server';
|
|
|
7
7
|
import type { ServerDescription } from '../../sdam/server_description';
|
|
8
8
|
import type { Topology } from '../../sdam/topology';
|
|
9
9
|
import { TopologyDescription } from '../../sdam/topology_description';
|
|
10
|
-
import type {
|
|
11
|
-
import type { CommandOptions, Connection } from '../connection';
|
|
10
|
+
import type { Connection } from '../connection';
|
|
12
11
|
|
|
13
12
|
export interface ReadPreferenceOption {
|
|
14
13
|
readPreference?: ReadPreferenceLike;
|
|
@@ -35,27 +34,6 @@ export function getReadPreference(cmd: Document, options?: ReadPreferenceOption)
|
|
|
35
34
|
return readPreference;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
export function applyCommonQueryOptions(
|
|
39
|
-
queryOptions: OpQueryOptions,
|
|
40
|
-
options: CommandOptions
|
|
41
|
-
): CommandOptions {
|
|
42
|
-
Object.assign(queryOptions, {
|
|
43
|
-
raw: typeof options.raw === 'boolean' ? options.raw : false,
|
|
44
|
-
promoteLongs: typeof options.promoteLongs === 'boolean' ? options.promoteLongs : true,
|
|
45
|
-
promoteValues: typeof options.promoteValues === 'boolean' ? options.promoteValues : true,
|
|
46
|
-
promoteBuffers: typeof options.promoteBuffers === 'boolean' ? options.promoteBuffers : false,
|
|
47
|
-
bsonRegExp: typeof options.bsonRegExp === 'boolean' ? options.bsonRegExp : false,
|
|
48
|
-
enableUtf8Validation:
|
|
49
|
-
typeof options.enableUtf8Validation === 'boolean' ? options.enableUtf8Validation : true
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (options.session) {
|
|
53
|
-
queryOptions.session = options.session;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return queryOptions;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
37
|
export function isSharded(topologyOrServer?: Topology | Server | Connection): boolean {
|
|
60
38
|
if (topologyOrServer == null) {
|
|
61
39
|
return false;
|
package/src/collection.ts
CHANGED
|
@@ -334,7 +334,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
334
334
|
filter: Filter<TSchema>,
|
|
335
335
|
update: UpdateFilter<TSchema> | Partial<TSchema>,
|
|
336
336
|
options?: UpdateOptions
|
|
337
|
-
): Promise<UpdateResult
|
|
337
|
+
): Promise<UpdateResult<TSchema>> {
|
|
338
338
|
return executeOperation(
|
|
339
339
|
this.s.db.s.client,
|
|
340
340
|
new UpdateOneOperation(
|
|
@@ -357,7 +357,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
357
357
|
filter: Filter<TSchema>,
|
|
358
358
|
replacement: WithoutId<TSchema>,
|
|
359
359
|
options?: ReplaceOptions
|
|
360
|
-
): Promise<UpdateResult | Document> {
|
|
360
|
+
): Promise<UpdateResult<TSchema> | Document> {
|
|
361
361
|
return executeOperation(
|
|
362
362
|
this.s.db.s.client,
|
|
363
363
|
new ReplaceOneOperation(
|
|
@@ -380,7 +380,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
380
380
|
filter: Filter<TSchema>,
|
|
381
381
|
update: UpdateFilter<TSchema>,
|
|
382
382
|
options?: UpdateOptions
|
|
383
|
-
): Promise<UpdateResult
|
|
383
|
+
): Promise<UpdateResult<TSchema>> {
|
|
384
384
|
return executeOperation(
|
|
385
385
|
this.s.db.s.client,
|
|
386
386
|
new UpdateManyOperation(
|
|
@@ -568,7 +568,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
568
568
|
* error.
|
|
569
569
|
*
|
|
570
570
|
* **Note**: Unlike {@link Collection#createIndex| createIndex}, this function takes in raw index specifications.
|
|
571
|
-
* Index specifications are defined {@link
|
|
571
|
+
* Index specifications are defined {@link https://www.mongodb.com/docs/manual/reference/command/createIndexes/| here}.
|
|
572
572
|
*
|
|
573
573
|
* @param indexSpecs - An array of index specifications to be created
|
|
574
574
|
* @param options - Optional settings for the command
|
|
@@ -705,18 +705,18 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
705
705
|
* | `$near` | [`$geoWithin`][2] with [`$center`][3] |
|
|
706
706
|
* | `$nearSphere` | [`$geoWithin`][2] with [`$centerSphere`][4] |
|
|
707
707
|
*
|
|
708
|
-
* [1]: https://
|
|
709
|
-
* [2]: https://
|
|
710
|
-
* [3]: https://
|
|
711
|
-
* [4]: https://
|
|
708
|
+
* [1]: https://www.mongodb.com/docs/manual/reference/operator/query/expr/
|
|
709
|
+
* [2]: https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
|
|
710
|
+
* [3]: https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center
|
|
711
|
+
* [4]: https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere
|
|
712
712
|
*
|
|
713
713
|
* @param filter - The filter for the count
|
|
714
714
|
* @param options - Optional settings for the command
|
|
715
715
|
*
|
|
716
|
-
* @see https://
|
|
717
|
-
* @see https://
|
|
718
|
-
* @see https://
|
|
719
|
-
* @see https://
|
|
716
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/query/expr/
|
|
717
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
|
|
718
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center
|
|
719
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere
|
|
720
720
|
*/
|
|
721
721
|
async countDocuments(
|
|
722
722
|
filter: Document = {},
|
|
@@ -916,7 +916,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
916
916
|
* });
|
|
917
917
|
* ```
|
|
918
918
|
*
|
|
919
|
-
* @param pipeline - An array of {@link https://
|
|
919
|
+
* @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
|
|
920
920
|
* @param options - Optional settings for the command
|
|
921
921
|
* @typeParam TLocal - Type of the data being detected by the change stream
|
|
922
922
|
* @typeParam TChange - Type of the whole change stream document emitted
|