Skip to content

Commit 29d6e19

Browse files
authored
Merge branch 'main' into NODE-4815/stringify_and_truncate_BSON_responses
2 parents 5d94624 + d502eb0 commit 29d6e19

16 files changed

+360
-77
lines changed

.evergreen/config.in.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,10 @@ task_groups:
12751275
file: src/testazurekms-expansions.yml
12761276

12771277
teardown_group:
1278+
# Load expansions again. The setup task may have failed before running `expansions.update`.
1279+
- command: expansions.update
1280+
params:
1281+
file: testazurekms-expansions.yml
12781282
- command: subprocess.exec
12791283
params:
12801284
binary: bash

.evergreen/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,6 +3149,9 @@ task_groups:
31493149
params:
31503150
file: src/testazurekms-expansions.yml
31513151
teardown_group:
3152+
- command: expansions.update
3153+
params:
3154+
file: testazurekms-expansions.yml
31523155
- command: subprocess.exec
31533156
params:
31543157
binary: bash

src/cmap/command_monitoring_events.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class CommandStartedEvent {
2424
address: string;
2525
connectionId?: string | number;
2626
serviceId?: ObjectId;
27+
/** @internal */
2728
name = COMMAND_STARTED;
2829

2930
/**
@@ -72,6 +73,7 @@ export class CommandSucceededEvent {
7273
commandName: string;
7374
reply: unknown;
7475
serviceId?: ObjectId;
76+
/** @internal */
7577
name = COMMAND_SUCCEEDED;
7678

7779
/**
@@ -121,6 +123,7 @@ export class CommandFailedEvent {
121123
commandName: string;
122124
failure: Error;
123125
serviceId?: ObjectId;
126+
/** @internal */
124127
name = COMMAND_FAILED;
125128

126129
/**

src/cmap/connection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ export interface ConnectionOptions
122122
credentials?: MongoCredentials;
123123
connectTimeoutMS?: number;
124124
tls: boolean;
125+
/** @deprecated - Will not be able to turn off in the future. */
125126
keepAlive?: boolean;
127+
/** @deprecated - Will not be configurable in the future. */
126128
keepAliveInitialDelay?: number;
127129
noDelay?: boolean;
128130
socketTimeoutMS?: number;

src/cmap/connection_pool.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
821821
const error = this.closed ? new PoolClosedError(this) : new PoolClearedError(this);
822822
this.emit(
823823
ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
824-
new ConnectionCheckOutFailedEvent(this, reason)
824+
new ConnectionCheckOutFailedEvent(this, reason, error)
825825
);
826826
if (waitQueueMember.timer) {
827827
clearTimeout(waitQueueMember.timer);
@@ -874,7 +874,8 @@ export class ConnectionPool extends TypedEventEmitter<ConnectionPoolEvents> {
874874
if (err) {
875875
this.emit(
876876
ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
877-
new ConnectionCheckOutFailedEvent(this, 'connectionError')
877+
// TODO(NODE-5192): Remove this cast
878+
new ConnectionCheckOutFailedEvent(this, 'connectionError', err as MongoError)
878879
);
879880
} else if (connection) {
880881
this[kCheckedOut].add(connection);

src/cmap/connection_pool_events.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
CONNECTION_POOL_READY,
1313
CONNECTION_READY
1414
} from '../constants';
15-
import type { AnyError, MongoError } from '../error';
15+
import type { MongoError } from '../error';
1616
import type { Connection } from './connection';
1717
import type { ConnectionPool, ConnectionPoolOptions } from './connection_pool';
1818

@@ -26,6 +26,7 @@ export abstract class ConnectionPoolMonitoringEvent {
2626
time: Date;
2727
/** The address (host/port pair) of the pool */
2828
address: string;
29+
/** @internal */
2930
abstract name:
3031
| typeof CONNECTION_CHECK_OUT_FAILED
3132
| typeof CONNECTION_CHECK_OUT_STARTED
@@ -54,6 +55,7 @@ export abstract class ConnectionPoolMonitoringEvent {
5455
export class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
5556
/** The options used to create this connection pool */
5657
options?: ConnectionPoolOptions;
58+
/** @internal */
5759
name = CONNECTION_POOL_CREATED;
5860

5961
/** @internal */
@@ -71,6 +73,9 @@ export class ConnectionPoolCreatedEvent extends ConnectionPoolMonitoringEvent {
7173
export class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEvent {
7274
name = CONNECTION_POOL_READY;
7375

76+
/** @internal */
77+
name = CONNECTION_POOL_READY;
78+
7479
/** @internal */
7580
constructor(pool: ConnectionPool) {
7681
super(pool);
@@ -85,6 +90,9 @@ export class ConnectionPoolReadyEvent extends ConnectionPoolMonitoringEvent {
8590
export class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
8691
name = CONNECTION_POOL_CLOSED;
8792

93+
/** @internal */
94+
name = CONNECTION_POOL_CLOSED;
95+
8896
/** @internal */
8997
constructor(pool: ConnectionPool) {
9098
super(pool);
@@ -99,6 +107,7 @@ export class ConnectionPoolClosedEvent extends ConnectionPoolMonitoringEvent {
99107
export class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
100108
/** A monotonically increasing, per-pool id for the newly created connection */
101109
connectionId: number | '<monitor>';
110+
/** @internal */
102111
name = CONNECTION_CREATED;
103112

104113
/** @internal */
@@ -116,6 +125,7 @@ export class ConnectionCreatedEvent extends ConnectionPoolMonitoringEvent {
116125
export class ConnectionReadyEvent extends ConnectionPoolMonitoringEvent {
117126
/** The id of the connection */
118127
connectionId: number | '<monitor>';
128+
/** @internal */
119129
name = CONNECTION_READY;
120130

121131
/** @internal */
@@ -136,7 +146,9 @@ export class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
136146
/** The reason the connection was closed */
137147
reason: string;
138148
serviceId?: ObjectId;
149+
/** @internal */
139150
name = CONNECTION_CLOSED;
151+
/** @internal */
140152
error: MongoError | null;
141153

142154
/** @internal */
@@ -162,6 +174,9 @@ export class ConnectionClosedEvent extends ConnectionPoolMonitoringEvent {
162174
export class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEvent {
163175
name = CONNECTION_CHECK_OUT_STARTED;
164176

177+
/** @internal */
178+
name = CONNECTION_CHECK_OUT_STARTED;
179+
165180
/** @internal */
166181
constructor(pool: ConnectionPool) {
167182
super(pool);
@@ -175,13 +190,21 @@ export class ConnectionCheckOutStartedEvent extends ConnectionPoolMonitoringEven
175190
*/
176191
export class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent {
177192
/** The reason the attempt to check out failed */
178-
reason: AnyError | string;
193+
reason: string;
194+
/** @internal */
195+
error?: MongoError;
196+
/** @internal */
179197
name = CONNECTION_CHECK_OUT_FAILED;
180198

181199
/** @internal */
182-
constructor(pool: ConnectionPool, reason: AnyError | string) {
200+
constructor(
201+
pool: ConnectionPool,
202+
reason: 'poolClosed' | 'timeout' | 'connectionError',
203+
error?: MongoError
204+
) {
183205
super(pool);
184206
this.reason = reason;
207+
this.error = error;
185208
}
186209
}
187210

@@ -193,6 +216,7 @@ export class ConnectionCheckOutFailedEvent extends ConnectionPoolMonitoringEvent
193216
export class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
194217
/** The id of the connection */
195218
connectionId: number | '<monitor>';
219+
/** @internal */
196220
name = CONNECTION_CHECKED_OUT;
197221

198222
/** @internal */
@@ -210,6 +234,7 @@ export class ConnectionCheckedOutEvent extends ConnectionPoolMonitoringEvent {
210234
export class ConnectionCheckedInEvent extends ConnectionPoolMonitoringEvent {
211235
/** The id of the connection */
212236
connectionId: number | '<monitor>';
237+
/** @internal */
213238
name = CONNECTION_CHECKED_IN;
214239

215240
/** @internal */
@@ -229,6 +254,7 @@ export class ConnectionPoolClearedEvent extends ConnectionPoolMonitoringEvent {
229254
serviceId?: ObjectId;
230255

231256
interruptInUseConnections?: boolean;
257+
/** @internal */
232258
name = CONNECTION_POOL_CLEARED;
233259

234260
/** @internal */

src/cmap/handshake/client_metadata.ts

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ export function makeClientMetadata(options: MakeClientMetadataOptions): ClientMe
116116
);
117117
}
118118

119-
const platformInfo =
120-
platform.length > 0
121-
? `Node.js ${process.version}, ${os.endianness()}|${platform}`
122-
: `Node.js ${process.version}, ${os.endianness()}`;
119+
let runtimeInfo = getRuntimeInfo();
120+
if (platform.length > 0) {
121+
runtimeInfo = `${runtimeInfo}|${platform}`;
122+
}
123123

124-
if (!metadataDocument.ifItFitsItSits('platform', platformInfo)) {
124+
if (!metadataDocument.ifItFitsItSits('platform', runtimeInfo)) {
125125
throw new MongoInvalidArgumentError(
126126
'Unable to include driverInfo platform, metadata cannot exceed 512 bytes'
127127
);
@@ -234,3 +234,39 @@ export function getFAASEnv(): Map<string, string | Int32> | null {
234234

235235
return null;
236236
}
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+
}

src/collection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export class Collection<TSchema extends Document = Document> {
334334
filter: Filter<TSchema>,
335335
update: UpdateFilter<TSchema> | Partial<TSchema>,
336336
options?: UpdateOptions
337-
): Promise<UpdateResult> {
337+
): Promise<UpdateResult<TSchema>> {
338338
return executeOperation(
339339
this.s.db.s.client,
340340
new UpdateOneOperation(
@@ -357,7 +357,7 @@ export class Collection<TSchema extends Document = Document> {
357357
filter: Filter<TSchema>,
358358
replacement: WithoutId<TSchema>,
359359
options?: ReplaceOptions
360-
): Promise<UpdateResult | Document> {
360+
): Promise<UpdateResult<TSchema> | Document> {
361361
return executeOperation(
362362
this.s.db.s.client,
363363
new ReplaceOneOperation(
@@ -380,7 +380,7 @@ export class Collection<TSchema extends Document = Document> {
380380
filter: Filter<TSchema>,
381381
update: UpdateFilter<TSchema>,
382382
options?: UpdateOptions
383-
): Promise<UpdateResult> {
383+
): Promise<UpdateResult<TSchema>> {
384384
return executeOperation(
385385
this.s.db.s.client,
386386
new UpdateManyOperation(

src/connection_string.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,13 @@ export const OPTIONS = {
852852
},
853853
keepAlive: {
854854
default: true,
855-
type: 'boolean'
855+
type: 'boolean',
856+
deprecated: 'Will not be able to turn off in the future.'
856857
},
857858
keepAliveInitialDelay: {
858859
default: 120000,
859-
type: 'uint'
860+
type: 'uint',
861+
deprecated: 'Will not be configurable in the future.'
860862
},
861863
loadBalanced: {
862864
default: false,

src/constants.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ export const SERVER_DESCRIPTION_CHANGED = 'serverDescriptionChanged' as const;
2323
export const TOPOLOGY_OPENING = 'topologyOpening' as const;
2424
export const TOPOLOGY_CLOSED = 'topologyClosed' as const;
2525
export const TOPOLOGY_DESCRIPTION_CHANGED = 'topologyDescriptionChanged' as const;
26-
/** @public */
26+
/** @internal */
2727
export const CONNECTION_POOL_CREATED = 'connectionPoolCreated' as const;
28-
/** @public */
28+
/** @internal */
2929
export const CONNECTION_POOL_CLOSED = 'connectionPoolClosed' as const;
30-
/** @public */
30+
/** @internal */
3131
export const CONNECTION_POOL_CLEARED = 'connectionPoolCleared' as const;
32-
/** @public */
32+
/** @internal */
3333
export const CONNECTION_POOL_READY = 'connectionPoolReady' as const;
34-
/** @public */
34+
/** @internal */
3535
export const CONNECTION_CREATED = 'connectionCreated' as const;
36-
/** @public */
36+
/** @internal */
3737
export const CONNECTION_READY = 'connectionReady' as const;
38-
/** @public */
38+
/** @internal */
3939
export const CONNECTION_CLOSED = 'connectionClosed' as const;
40-
/** @public */
40+
/** @internal */
4141
export const CONNECTION_CHECK_OUT_STARTED = 'connectionCheckOutStarted' as const;
42-
/** @public */
42+
/** @internal */
4343
export const CONNECTION_CHECK_OUT_FAILED = 'connectionCheckOutFailed' as const;
44-
/** @public */
44+
/** @internal */
4545
export const CONNECTION_CHECKED_OUT = 'connectionCheckedOut' as const;
46-
/** @public */
46+
/** @internal */
4747
export const CONNECTION_CHECKED_IN = 'connectionCheckedIn' as const;
4848
export const CLUSTER_TIME_RECEIVED = 'clusterTimeReceived' as const;
4949
export const COMMAND_STARTED = 'commandStarted' as const;

src/mongo_client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,12 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
212212
sslCRL?: string;
213213
/** TCP Connection no delay */
214214
noDelay?: boolean;
215-
/** TCP Connection keep alive enabled */
215+
/** @deprecated TCP Connection keep alive enabled. Will not be able to turn off in the future. */
216216
keepAlive?: boolean;
217-
/** The number of milliseconds to wait before initiating keepAlive on the TCP socket */
217+
/**
218+
* @deprecated The number of milliseconds to wait before initiating keepAlive on the TCP socket.
219+
* Will not be configurable in the future.
220+
*/
218221
keepAliveInitialDelay?: number;
219222
/** Force server to assign `_id` values instead of driver */
220223
forceServerObjectId?: boolean;

0 commit comments

Comments
 (0)