mongodb 6.8.0-dev.20240821.sha.55bdeaa9 → 6.8.0-dev.20240824.sha.40ace73c
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/lib/beta.d.ts +29 -5
- package/lib/beta.js +0 -1
- package/lib/beta.js.map +1 -1
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +9 -11
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +0 -6
- package/lib/change_stream.js.map +1 -1
- package/lib/client-side-encryption/mongocryptd_manager.js +1 -1
- package/lib/client-side-encryption/mongocryptd_manager.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/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +0 -2
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/machine_workflow.js +0 -2
- package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +1 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connection.js +0 -2
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +0 -1
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +1 -1
- package/lib/cmap/handshake/client_metadata.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +0 -2
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +0 -5
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/deps.js +8 -0
- package/lib/deps.js.map +1 -1
- package/lib/error.js +2 -1
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +0 -3
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/upload.js +0 -4
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/mongo_logger.js +0 -3
- package/lib/mongo_logger.js.map +1 -1
- package/lib/mongo_types.js +1 -0
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/aggregate.js +1 -0
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/execute_operation.js +2 -1
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find_and_modify.js +1 -1
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/operation.js +1 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/search_indexes/drop.js.map +1 -1
- package/lib/resource_management.js +4 -4
- package/lib/resource_management.js.map +1 -1
- package/lib/sdam/monitor.js +1 -5
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/srv_polling.js +1 -2
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sessions.js +1 -1
- package/lib/sessions.js.map +1 -1
- package/lib/sort.js +1 -1
- package/lib/sort.js.map +1 -1
- package/lib/timeout.js +0 -1
- package/lib/timeout.js.map +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +0 -1
- package/lib/utils.js.map +1 -1
- package/lib/write_concern.js.map +1 -1
- package/mongodb.d.ts +29 -5
- package/package.json +23 -25
- package/src/beta.ts +1 -1
- package/src/bson.ts +1 -2
- package/src/bulk/common.ts +12 -9
- package/src/change_stream.ts +10 -11
- package/src/client-side-encryption/mongocryptd_manager.ts +1 -1
- package/src/cmap/auth/gssapi.ts +1 -1
- package/src/cmap/auth/mongodb_aws.ts +2 -2
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +2 -2
- package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +2 -2
- package/src/cmap/commands.ts +5 -1
- package/src/cmap/connection.ts +2 -2
- package/src/cmap/connection_pool.ts +0 -1
- package/src/cmap/handshake/client_metadata.ts +1 -1
- package/src/cmap/wire_protocol/shared.ts +1 -2
- package/src/collection.ts +13 -12
- package/src/connection_string.ts +1 -2
- package/src/constants.ts +1 -0
- package/src/cursor/abstract_cursor.ts +0 -5
- package/src/cursor/aggregation_cursor.ts +6 -4
- package/src/deps.ts +8 -1
- package/src/error.ts +2 -3
- package/src/gridfs/download.ts +1 -3
- package/src/gridfs/upload.ts +1 -6
- package/src/mongo_logger.ts +2 -3
- package/src/mongo_types.ts +69 -68
- package/src/operations/aggregate.ts +2 -1
- package/src/operations/execute_operation.ts +6 -4
- package/src/operations/find_and_modify.ts +1 -1
- package/src/operations/insert.ts +1 -2
- package/src/operations/operation.ts +5 -8
- package/src/operations/search_indexes/drop.ts +4 -1
- package/src/resource_management.ts +4 -4
- package/src/sdam/monitor.ts +3 -5
- package/src/sdam/server_description.ts +5 -6
- package/src/sdam/srv_polling.ts +1 -2
- package/src/sessions.ts +1 -1
- package/src/sort.ts +1 -1
- package/src/timeout.ts +0 -1
- package/src/transactions.ts +1 -2
- package/src/utils.ts +9 -4
- package/src/write_concern.ts +2 -2
package/src/constants.ts
CHANGED
|
@@ -656,7 +656,6 @@ export abstract class AbstractCursor<
|
|
|
656
656
|
// We only want to end this session if we created it, and it hasn't ended yet
|
|
657
657
|
if (session.explicit === false) {
|
|
658
658
|
if (!session.hasEnded) {
|
|
659
|
-
// eslint-disable-next-line github/no-then
|
|
660
659
|
session.endSession().then(undefined, squashError);
|
|
661
660
|
}
|
|
662
661
|
this.cursorSession = this.cursorClient.startSession({ owner: this, explicit: false });
|
|
@@ -882,7 +881,6 @@ class ReadableCursorStream extends Readable {
|
|
|
882
881
|
}
|
|
883
882
|
|
|
884
883
|
override _destroy(error: Error | null, callback: (error?: Error | null) => void): void {
|
|
885
|
-
// eslint-disable-next-line github/no-then
|
|
886
884
|
this._cursor.close().then(
|
|
887
885
|
() => callback(error),
|
|
888
886
|
closeError => callback(closeError)
|
|
@@ -895,13 +893,11 @@ class ReadableCursorStream extends Readable {
|
|
|
895
893
|
return;
|
|
896
894
|
}
|
|
897
895
|
|
|
898
|
-
// eslint-disable-next-line github/no-then
|
|
899
896
|
this._cursor.next().then(
|
|
900
897
|
result => {
|
|
901
898
|
if (result == null) {
|
|
902
899
|
this.push(null);
|
|
903
900
|
} else if (this.destroyed) {
|
|
904
|
-
// eslint-disable-next-line github/no-then
|
|
905
901
|
this._cursor.close().then(undefined, squashError);
|
|
906
902
|
} else {
|
|
907
903
|
if (this.push(result)) {
|
|
@@ -917,7 +913,6 @@ class ReadableCursorStream extends Readable {
|
|
|
917
913
|
// a client during iteration. Alternatively, we could do the "right" thing and
|
|
918
914
|
// propagate the error message by removing this special case.
|
|
919
915
|
if (err.message.match(/server is closed/)) {
|
|
920
|
-
// eslint-disable-next-line github/no-then
|
|
921
916
|
this._cursor.close().then(undefined, squashError);
|
|
922
917
|
return this.push(null);
|
|
923
918
|
}
|
|
@@ -5,10 +5,12 @@ import { AggregateOperation, type AggregateOptions } from '../operations/aggrega
|
|
|
5
5
|
import { executeOperation } from '../operations/execute_operation';
|
|
6
6
|
import type { ClientSession } from '../sessions';
|
|
7
7
|
import type { Sort } from '../sort';
|
|
8
|
-
import type
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import { mergeOptions, type MongoDBNamespace } from '../utils';
|
|
9
|
+
import {
|
|
10
|
+
AbstractCursor,
|
|
11
|
+
type AbstractCursorOptions,
|
|
12
|
+
type InitialCursorResponse
|
|
13
|
+
} from './abstract_cursor';
|
|
12
14
|
|
|
13
15
|
/** @public */
|
|
14
16
|
export interface AggregationCursorOptions extends AbstractCursorOptions, AggregateOptions {}
|
package/src/deps.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
1
|
import { type Stream } from './cmap/connect';
|
|
3
2
|
import { MongoMissingDependencyError } from './error';
|
|
4
3
|
import type { Callback } from './utils';
|
|
@@ -24,6 +23,7 @@ export function getKerberos(): Kerberos {
|
|
|
24
23
|
let kerberos: Kerberos;
|
|
25
24
|
try {
|
|
26
25
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
27
27
|
kerberos = require('kerberos');
|
|
28
28
|
} catch (error) {
|
|
29
29
|
kerberos = makeErrorModule(
|
|
@@ -63,6 +63,7 @@ export type ZStandard = ZStandardLib | { kModuleError: MongoMissingDependencyErr
|
|
|
63
63
|
export function getZstdLibrary(): ZStandardLib | { kModuleError: MongoMissingDependencyError } {
|
|
64
64
|
let ZStandard: ZStandardLib | { kModuleError: MongoMissingDependencyError };
|
|
65
65
|
try {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
66
67
|
ZStandard = require('@mongodb-js/zstd');
|
|
67
68
|
} catch (error) {
|
|
68
69
|
ZStandard = makeErrorModule(
|
|
@@ -101,6 +102,7 @@ export function getAwsCredentialProvider():
|
|
|
101
102
|
| { kModuleError: MongoMissingDependencyError } {
|
|
102
103
|
try {
|
|
103
104
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
104
106
|
const credentialProvider = require('@aws-sdk/credential-providers');
|
|
105
107
|
return credentialProvider;
|
|
106
108
|
} catch (error) {
|
|
@@ -122,6 +124,7 @@ export type GcpMetadata =
|
|
|
122
124
|
export function getGcpMetadata(): GcpMetadata {
|
|
123
125
|
try {
|
|
124
126
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
125
128
|
const credentialProvider = require('gcp-metadata');
|
|
126
129
|
return credentialProvider;
|
|
127
130
|
} catch (error) {
|
|
@@ -153,6 +156,7 @@ export type SnappyLib = {
|
|
|
153
156
|
export function getSnappy(): SnappyLib | { kModuleError: MongoMissingDependencyError } {
|
|
154
157
|
try {
|
|
155
158
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
156
160
|
const value = require('snappy');
|
|
157
161
|
return value;
|
|
158
162
|
} catch (error) {
|
|
@@ -187,6 +191,7 @@ export type SocksLib = {
|
|
|
187
191
|
export function getSocks(): SocksLib | { kModuleError: MongoMissingDependencyError } {
|
|
188
192
|
try {
|
|
189
193
|
// Ensure you always wrap an optional require in the try block NODE-3199
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
190
195
|
const value = require('socks');
|
|
191
196
|
return value;
|
|
192
197
|
} catch (error) {
|
|
@@ -244,6 +249,7 @@ export const aws4: AWS4 | { kModuleError: MongoMissingDependencyError } = loadAw
|
|
|
244
249
|
function loadAws4() {
|
|
245
250
|
let aws4: AWS4 | { kModuleError: MongoMissingDependencyError };
|
|
246
251
|
try {
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
247
253
|
aws4 = require('aws4');
|
|
248
254
|
} catch (error) {
|
|
249
255
|
aws4 = makeErrorModule(
|
|
@@ -267,6 +273,7 @@ export function getMongoDBClientEncryption():
|
|
|
267
273
|
// NOTE(NODE-3199): Ensure you always wrap an optional require literally in the try block
|
|
268
274
|
// Cannot be moved to helper utility function, bundlers search and replace the actual require call
|
|
269
275
|
// in a way that makes this line throw at bundle time, not runtime, catching here will make bundling succeed
|
|
276
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
270
277
|
mongodbClientEncryption = require('mongodb-client-encryption');
|
|
271
278
|
} catch (error) {
|
|
272
279
|
const kModuleError = new MongoMissingDependencyError(
|
package/src/error.ts
CHANGED
|
@@ -1255,9 +1255,8 @@ export function needsRetryableWriteLabel(
|
|
|
1255
1255
|
// use original top-level code from server response
|
|
1256
1256
|
return RETRYABLE_WRITE_ERROR_CODES.has(error.result.code ?? 0);
|
|
1257
1257
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
);
|
|
1258
|
+
const code = error.result.writeConcernError.code ?? Number(error.code);
|
|
1259
|
+
return RETRYABLE_WRITE_ERROR_CODES.has(Number.isNaN(code) ? 0 : code);
|
|
1261
1260
|
}
|
|
1262
1261
|
|
|
1263
1262
|
if (error instanceof MongoError) {
|
package/src/gridfs/download.ts
CHANGED
|
@@ -216,7 +216,7 @@ function doRead(stream: GridFSBucketReadStream): void {
|
|
|
216
216
|
|
|
217
217
|
if (!doc) {
|
|
218
218
|
stream.push(null);
|
|
219
|
-
|
|
219
|
+
|
|
220
220
|
stream.s.cursor?.close().then(undefined, error => stream.destroy(error));
|
|
221
221
|
return;
|
|
222
222
|
}
|
|
@@ -288,7 +288,6 @@ function doRead(stream: GridFSBucketReadStream): void {
|
|
|
288
288
|
return;
|
|
289
289
|
};
|
|
290
290
|
|
|
291
|
-
// eslint-disable-next-line github/no-then
|
|
292
291
|
stream.s.cursor.next().then(handleReadResult, error => {
|
|
293
292
|
if (stream.destroyed) return;
|
|
294
293
|
stream.destroy(error);
|
|
@@ -372,7 +371,6 @@ function init(stream: GridFSBucketReadStream): void {
|
|
|
372
371
|
return;
|
|
373
372
|
};
|
|
374
373
|
|
|
375
|
-
// eslint-disable-next-line github/no-then
|
|
376
374
|
stream.s.files.findOne(stream.s.filter, findOneOptions).then(handleReadResult, error => {
|
|
377
375
|
if (stream.destroyed) return;
|
|
378
376
|
stream.destroy(error);
|
package/src/gridfs/upload.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Writable } from 'stream';
|
|
2
2
|
|
|
3
|
-
import type
|
|
4
|
-
import { ObjectId } from '../bson';
|
|
3
|
+
import { type Document, ObjectId } from '../bson';
|
|
5
4
|
import type { Collection } from '../collection';
|
|
6
5
|
import { MongoAPIError, MONGODB_ERROR_CODES, MongoError } from '../error';
|
|
7
6
|
import { type Callback, squashError } from '../utils';
|
|
@@ -135,7 +134,6 @@ export class GridFSBucketWriteStream extends Writable {
|
|
|
135
134
|
if (!this.bucket.s.calledOpenUploadStream) {
|
|
136
135
|
this.bucket.s.calledOpenUploadStream = true;
|
|
137
136
|
|
|
138
|
-
// eslint-disable-next-line github/no-then
|
|
139
137
|
checkIndexes(this).then(() => {
|
|
140
138
|
this.bucket.s.checkedIndexes = true;
|
|
141
139
|
this.bucket.emit('index');
|
|
@@ -272,7 +270,6 @@ function checkDone(stream: GridFSBucketWriteStream, callback: Callback): void {
|
|
|
272
270
|
return;
|
|
273
271
|
}
|
|
274
272
|
|
|
275
|
-
// eslint-disable-next-line github/no-then
|
|
276
273
|
stream.files.insertOne(gridFSFile, { writeConcern: stream.writeConcern }).then(
|
|
277
274
|
() => {
|
|
278
275
|
stream.gridFSFile = gridFSFile;
|
|
@@ -396,7 +393,6 @@ function doWrite(
|
|
|
396
393
|
return;
|
|
397
394
|
}
|
|
398
395
|
|
|
399
|
-
// eslint-disable-next-line github/no-then
|
|
400
396
|
stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(
|
|
401
397
|
() => {
|
|
402
398
|
--stream.state.outstandingRequests;
|
|
@@ -437,7 +433,6 @@ function writeRemnant(stream: GridFSBucketWriteStream, callback: Callback): void
|
|
|
437
433
|
return;
|
|
438
434
|
}
|
|
439
435
|
|
|
440
|
-
// eslint-disable-next-line github/no-then
|
|
441
436
|
stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(
|
|
442
437
|
() => {
|
|
443
438
|
--stream.state.outstandingRequests;
|
package/src/mongo_logger.ts
CHANGED
|
@@ -839,9 +839,9 @@ export class MongoLogger {
|
|
|
839
839
|
|
|
840
840
|
if (isPromiseLike(this.pendingLog)) {
|
|
841
841
|
this.pendingLog = this.pendingLog
|
|
842
|
-
|
|
842
|
+
|
|
843
843
|
.then(() => this.logDestination.write(logMessage))
|
|
844
|
-
|
|
844
|
+
|
|
845
845
|
.then(this.clearPendingLog.bind(this), this.logWriteFailureHandler.bind(this));
|
|
846
846
|
return;
|
|
847
847
|
}
|
|
@@ -849,7 +849,6 @@ export class MongoLogger {
|
|
|
849
849
|
try {
|
|
850
850
|
const logResult = this.logDestination.write(logMessage);
|
|
851
851
|
if (isPromiseLike(logResult)) {
|
|
852
|
-
// eslint-disable-next-line github/no-then
|
|
853
852
|
this.pendingLog = logResult.then(
|
|
854
853
|
this.clearPendingLog.bind(this),
|
|
855
854
|
this.logWriteFailureHandler.bind(this)
|
package/src/mongo_types.ts
CHANGED
|
@@ -34,11 +34,11 @@ export type InferIdType<TSchema> = TSchema extends { _id: infer IdType }
|
|
|
34
34
|
? never // explicitly forbid empty objects as the type of _id
|
|
35
35
|
: IdType
|
|
36
36
|
: TSchema extends { _id?: infer IdType }
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
? // optional _id defined - return ObjectId | IdType
|
|
38
|
+
unknown extends IdType
|
|
39
|
+
? ObjectId // infer the _id type as ObjectId if the type of _id is unknown
|
|
40
|
+
: IdType
|
|
41
|
+
: ObjectId; // user has not defined _id on schema
|
|
42
42
|
|
|
43
43
|
/** Add an _id field to an object shaped type @public */
|
|
44
44
|
export type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & { _id: InferIdType<TSchema> };
|
|
@@ -68,8 +68,8 @@ export type OptionalUnlessRequiredId<TSchema> = TSchema extends { _id: any }
|
|
|
68
68
|
export type EnhancedOmit<TRecordOrUnion, KeyUnion> = string extends keyof TRecordOrUnion
|
|
69
69
|
? TRecordOrUnion // TRecordOrUnion has indexed type e.g. { _id: string; [k: string]: any; } or it is "any"
|
|
70
70
|
: TRecordOrUnion extends any
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
? Pick<TRecordOrUnion, Exclude<keyof TRecordOrUnion, KeyUnion>> // discriminated unions
|
|
72
|
+
: never;
|
|
73
73
|
|
|
74
74
|
/** Remove the _id field from an object shaped type @public */
|
|
75
75
|
export type WithoutId<TSchema> = Omit<TSchema, '_id'>;
|
|
@@ -88,9 +88,8 @@ export type Condition<T> = AlternativeType<T> | FilterOperators<AlternativeType<
|
|
|
88
88
|
* array types can be searched using their element type
|
|
89
89
|
* @public
|
|
90
90
|
*/
|
|
91
|
-
export type AlternativeType<T> =
|
|
92
|
-
? T | RegExpOrString<U>
|
|
93
|
-
: RegExpOrString<T>;
|
|
91
|
+
export type AlternativeType<T> =
|
|
92
|
+
T extends ReadonlyArray<infer U> ? T | RegExpOrString<U> : RegExpOrString<T>;
|
|
94
93
|
|
|
95
94
|
/** @public */
|
|
96
95
|
export type RegExpOrString<T> = T extends string ? BSONRegExp | RegExp | T : T;
|
|
@@ -192,9 +191,10 @@ export type IntegerType = number | Int32 | Long | bigint;
|
|
|
192
191
|
export type NumericType = IntegerType | Decimal128 | Double;
|
|
193
192
|
|
|
194
193
|
/** @public */
|
|
195
|
-
export type FilterOperations<T> =
|
|
196
|
-
|
|
197
|
-
|
|
194
|
+
export type FilterOperations<T> =
|
|
195
|
+
T extends Record<string, any>
|
|
196
|
+
? { [key in keyof T]?: FilterOperators<T[key]> }
|
|
197
|
+
: FilterOperators<T>;
|
|
198
198
|
|
|
199
199
|
/** @public */
|
|
200
200
|
export type KeysOfAType<TSchema, Type> = {
|
|
@@ -412,6 +412,7 @@ export declare interface TypedEventEmitter<Events extends EventsDescription> ext
|
|
|
412
412
|
* @public
|
|
413
413
|
*/
|
|
414
414
|
|
|
415
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
415
416
|
export class TypedEventEmitter<Events extends EventsDescription> extends EventEmitter {
|
|
416
417
|
/** @internal */
|
|
417
418
|
protected mongoLogger?: MongoLogger;
|
|
@@ -480,31 +481,31 @@ export class CancellationToken extends TypedEventEmitter<{ cancel(): void }> {}
|
|
|
480
481
|
export type Join<T extends unknown[], D extends string> = T extends []
|
|
481
482
|
? ''
|
|
482
483
|
: T extends [string | number]
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
484
|
+
? `${T[0]}`
|
|
485
|
+
: T extends [string | number, ...infer R]
|
|
486
|
+
? `${T[0]}${D}${Join<R, D>}`
|
|
487
|
+
: string;
|
|
487
488
|
|
|
488
489
|
/** @public */
|
|
489
490
|
export type PropertyType<Type, Property extends string> = string extends Property
|
|
490
491
|
? unknown
|
|
491
492
|
: Property extends keyof Type
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
493
|
+
? Type[Property]
|
|
494
|
+
: Property extends `${number}`
|
|
495
|
+
? Type extends ReadonlyArray<infer ArrayType>
|
|
496
|
+
? ArrayType
|
|
497
|
+
: unknown
|
|
498
|
+
: Property extends `${infer Key}.${infer Rest}`
|
|
499
|
+
? Key extends `${number}`
|
|
500
|
+
? Type extends ReadonlyArray<infer ArrayType>
|
|
501
|
+
? PropertyType<ArrayType, Rest>
|
|
502
|
+
: unknown
|
|
503
|
+
: Key extends keyof Type
|
|
504
|
+
? Type[Key] extends Map<string, infer MapType>
|
|
505
|
+
? MapType
|
|
506
|
+
: PropertyType<Type[Key], Rest>
|
|
507
|
+
: unknown
|
|
508
|
+
: unknown;
|
|
508
509
|
|
|
509
510
|
/**
|
|
510
511
|
* @public
|
|
@@ -521,41 +522,41 @@ export type PropertyType<Type, Property extends string> = string extends Propert
|
|
|
521
522
|
export type NestedPaths<Type, Depth extends number[]> = Depth['length'] extends 8
|
|
522
523
|
? []
|
|
523
524
|
: Type extends
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
525
|
+
| string
|
|
526
|
+
| number
|
|
527
|
+
| bigint
|
|
528
|
+
| boolean
|
|
529
|
+
| Date
|
|
530
|
+
| RegExp
|
|
531
|
+
| Buffer
|
|
532
|
+
| Uint8Array
|
|
533
|
+
| ((...args: any[]) => any)
|
|
534
|
+
| { _bsontype: string }
|
|
535
|
+
? []
|
|
536
|
+
: Type extends ReadonlyArray<infer ArrayType>
|
|
537
|
+
? [] | [number, ...NestedPaths<ArrayType, [...Depth, 1]>]
|
|
538
|
+
: Type extends Map<string, any>
|
|
539
|
+
? [string]
|
|
540
|
+
: Type extends object
|
|
541
|
+
? {
|
|
542
|
+
[Key in Extract<keyof Type, string>]: Type[Key] extends Type // type of value extends the parent
|
|
543
|
+
? [Key]
|
|
544
|
+
: // for a recursive union type, the child will never extend the parent type.
|
|
545
|
+
// but the parent will still extend the child
|
|
546
|
+
Type extends Type[Key]
|
|
547
|
+
? [Key]
|
|
548
|
+
: Type[Key] extends ReadonlyArray<infer ArrayType> // handling recursive types with arrays
|
|
549
|
+
? Type extends ArrayType // is the type of the parent the same as the type of the array?
|
|
550
|
+
? [Key] // yes, it's a recursive array type
|
|
551
|
+
: // for unions, the child type extends the parent
|
|
552
|
+
ArrayType extends Type
|
|
553
|
+
? [Key] // we have a recursive array union
|
|
554
|
+
: // child is an array, but it's not a recursive array
|
|
555
|
+
[Key, ...NestedPaths<Type[Key], [...Depth, 1]>]
|
|
556
|
+
: // child is not structured the same as the parent
|
|
557
|
+
[Key, ...NestedPaths<Type[Key], [...Depth, 1]>] | [Key];
|
|
558
|
+
}[Extract<keyof Type, string>]
|
|
559
|
+
: [];
|
|
559
560
|
|
|
560
561
|
/**
|
|
561
562
|
* @public
|
|
@@ -9,8 +9,9 @@ import { type CollationOptions, CommandOperation, type CommandOperationOptions }
|
|
|
9
9
|
import { Aspect, defineAspects, type Hint } from './operation';
|
|
10
10
|
|
|
11
11
|
/** @internal */
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
12
13
|
export const DB_AGGREGATE_COLLECTION = 1 as const;
|
|
13
|
-
const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8
|
|
14
|
+
const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8;
|
|
14
15
|
|
|
15
16
|
/** @public */
|
|
16
17
|
export interface AggregateOptions extends CommandOperationOptions {
|
|
@@ -31,9 +31,8 @@ const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
|
|
|
31
31
|
const MMAPv1_RETRY_WRITES_ERROR_MESSAGE =
|
|
32
32
|
'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.';
|
|
33
33
|
|
|
34
|
-
type ResultTypeFromOperation<TOperation> =
|
|
35
|
-
? K
|
|
36
|
-
: never;
|
|
34
|
+
type ResultTypeFromOperation<TOperation> =
|
|
35
|
+
TOperation extends AbstractOperation<infer K> ? K : never;
|
|
37
36
|
|
|
38
37
|
/**
|
|
39
38
|
* Executes the given operation with provided arguments.
|
|
@@ -276,5 +275,8 @@ async function tryOperation<
|
|
|
276
275
|
}
|
|
277
276
|
}
|
|
278
277
|
|
|
279
|
-
throw
|
|
278
|
+
throw (
|
|
279
|
+
previousOperationError ??
|
|
280
|
+
new MongoRuntimeError('Tried to propagate retryability error, but no error was found.')
|
|
281
|
+
);
|
|
280
282
|
}
|
|
@@ -209,7 +209,7 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
|
|
|
209
209
|
|
|
210
210
|
// Execute the command
|
|
211
211
|
const result = await super.executeCommand(server, session, cmd);
|
|
212
|
-
return options.includeResultMetadata ? result : result.value ?? null;
|
|
212
|
+
return options.includeResultMetadata ? result : (result.value ?? null);
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
package/src/operations/insert.ts
CHANGED
|
@@ -5,8 +5,7 @@ import { MongoInvalidArgumentError, MongoServerError } from '../error';
|
|
|
5
5
|
import type { InferIdType } from '../mongo_types';
|
|
6
6
|
import type { Server } from '../sdam/server';
|
|
7
7
|
import type { ClientSession } from '../sessions';
|
|
8
|
-
import type
|
|
9
|
-
import { maybeAddIdToDocuments } from '../utils';
|
|
8
|
+
import { maybeAddIdToDocuments, type MongoDBNamespace } from '../utils';
|
|
10
9
|
import { WriteConcern } from '../write_concern';
|
|
11
10
|
import { BulkWriteOperation } from './bulk_write';
|
|
12
11
|
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
@@ -17,11 +17,6 @@ export const Aspect = {
|
|
|
17
17
|
/** @public */
|
|
18
18
|
export type Hint = string | Document;
|
|
19
19
|
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
21
|
-
export interface OperationConstructor extends Function {
|
|
22
|
-
aspects?: Set<symbol>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
20
|
/** @public */
|
|
26
21
|
export interface OperationOptions extends BSONSerializeOptions {
|
|
27
22
|
/** Specify ClientSession for this command */
|
|
@@ -63,10 +58,12 @@ export abstract class AbstractOperation<TResult = any> {
|
|
|
63
58
|
|
|
64
59
|
[kSession]: ClientSession | undefined;
|
|
65
60
|
|
|
61
|
+
static aspects?: Set<symbol>;
|
|
62
|
+
|
|
66
63
|
constructor(options: OperationOptions = {}) {
|
|
67
64
|
this.readPreference = this.hasAspect(Aspect.WRITE_OPERATION)
|
|
68
65
|
? ReadPreference.primary
|
|
69
|
-
: ReadPreference.fromOptions(options) ?? ReadPreference.primary;
|
|
66
|
+
: (ReadPreference.fromOptions(options) ?? ReadPreference.primary);
|
|
70
67
|
|
|
71
68
|
// Pull the BSON serialize options from the already-resolved options
|
|
72
69
|
this.bsonOptions = resolveBSONOptions(options);
|
|
@@ -85,7 +82,7 @@ export abstract class AbstractOperation<TResult = any> {
|
|
|
85
82
|
abstract execute(server: Server, session: ClientSession | undefined): Promise<TResult>;
|
|
86
83
|
|
|
87
84
|
hasAspect(aspect: symbol): boolean {
|
|
88
|
-
const ctor = this.constructor as
|
|
85
|
+
const ctor = this.constructor as { aspects?: Set<symbol> };
|
|
89
86
|
if (ctor.aspects == null) {
|
|
90
87
|
return false;
|
|
91
88
|
}
|
|
@@ -111,7 +108,7 @@ export abstract class AbstractOperation<TResult = any> {
|
|
|
111
108
|
}
|
|
112
109
|
|
|
113
110
|
export function defineAspects(
|
|
114
|
-
operation:
|
|
111
|
+
operation: { aspects?: Set<symbol> },
|
|
115
112
|
aspects: symbol | symbol[] | Set<symbol>
|
|
116
113
|
): Set<symbol> {
|
|
117
114
|
if (!Array.isArray(aspects) && !(aspects instanceof Set)) {
|
|
@@ -8,7 +8,10 @@ import { AbstractOperation } from '../operation';
|
|
|
8
8
|
|
|
9
9
|
/** @internal */
|
|
10
10
|
export class DropSearchIndexOperation extends AbstractOperation<void> {
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(
|
|
12
|
+
private readonly collection: Collection,
|
|
13
|
+
private readonly name: string
|
|
14
|
+
) {
|
|
12
15
|
super();
|
|
13
16
|
}
|
|
14
17
|
|
|
@@ -58,13 +58,13 @@ export function configureExplicitResourceManagement() {
|
|
|
58
58
|
// function, but keeping all resource-management related code together seemed preferable and I chose
|
|
59
59
|
// lazy requiring of resources instead.
|
|
60
60
|
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
62
62
|
const { MongoClient } = require('./mongo_client');
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
64
64
|
const { ClientSession } = require('./sessions');
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
66
66
|
const { AbstractCursor } = require('./cursor/abstract_cursor');
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
68
68
|
const { ChangeStream } = require('./change_stream');
|
|
69
69
|
|
|
70
70
|
configureResourceManagement(MongoClient.prototype);
|
package/src/sdam/monitor.ts
CHANGED
|
@@ -308,7 +308,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
|
|
|
308
308
|
// duration
|
|
309
309
|
const duration =
|
|
310
310
|
isAwaitable && monitor.rttPinger
|
|
311
|
-
? monitor.rttPinger.latestRtt ?? calculateDurationInMs(start)
|
|
311
|
+
? (monitor.rttPinger.latestRtt ?? calculateDurationInMs(start))
|
|
312
312
|
: calculateDurationInMs(start);
|
|
313
313
|
|
|
314
314
|
monitor.addRttSample(duration);
|
|
@@ -378,7 +378,7 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
|
|
|
378
378
|
awaited = false;
|
|
379
379
|
connection
|
|
380
380
|
.command(ns('admin.$cmd'), cmd, options)
|
|
381
|
-
|
|
381
|
+
|
|
382
382
|
.then(onHeartbeatSucceeded, onHeartbeatFailed);
|
|
383
383
|
|
|
384
384
|
return;
|
|
@@ -397,7 +397,6 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
|
|
|
397
397
|
connection.destroy();
|
|
398
398
|
throw error;
|
|
399
399
|
}
|
|
400
|
-
// eslint-disable-next-line github/no-then
|
|
401
400
|
})().then(
|
|
402
401
|
connection => {
|
|
403
402
|
if (isInCloseState(monitor)) {
|
|
@@ -547,7 +546,6 @@ export class RTTPinger {
|
|
|
547
546
|
|
|
548
547
|
const connection = this.connection;
|
|
549
548
|
if (connection == null) {
|
|
550
|
-
// eslint-disable-next-line github/no-then
|
|
551
549
|
connect(this.monitor.connectOptions).then(
|
|
552
550
|
connection => {
|
|
553
551
|
this.measureAndReschedule(start, connection);
|
|
@@ -561,7 +559,7 @@ export class RTTPinger {
|
|
|
561
559
|
|
|
562
560
|
const commandName =
|
|
563
561
|
connection.serverApi?.version || connection.helloOk ? 'hello' : LEGACY_HELLO_COMMAND;
|
|
564
|
-
|
|
562
|
+
|
|
565
563
|
connection.command(ns('admin.$cmd'), { [commandName]: 1 }, undefined).then(
|
|
566
564
|
() => this.measureAndReschedule(start),
|
|
567
565
|
() => {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type Document, Long, type ObjectId } from '../bson';
|
|
2
2
|
import { type MongoError, MongoRuntimeError } from '../error';
|
|
3
3
|
import { arrayStrictEqual, compareObjectId, errorStrictEqual, HostAddress, now } from '../utils';
|
|
4
|
-
import type
|
|
5
|
-
import { ServerType } from './common';
|
|
4
|
+
import { type ClusterTime, ServerType } from './common';
|
|
6
5
|
|
|
7
6
|
const WRITABLE_SERVER_TYPES = new Set<ServerType>([
|
|
8
7
|
ServerType.RSPrimary,
|
|
@@ -262,15 +261,15 @@ export function compareTopologyVersion(
|
|
|
262
261
|
typeof currentTv.counter === 'bigint'
|
|
263
262
|
? Long.fromBigInt(currentTv.counter)
|
|
264
263
|
: Long.isLong(currentTv.counter)
|
|
265
|
-
|
|
266
|
-
|
|
264
|
+
? currentTv.counter
|
|
265
|
+
: Long.fromNumber(currentTv.counter);
|
|
267
266
|
|
|
268
267
|
const newCounter =
|
|
269
268
|
typeof newTv.counter === 'bigint'
|
|
270
269
|
? Long.fromBigInt(newTv.counter)
|
|
271
270
|
: Long.isLong(newTv.counter)
|
|
272
|
-
|
|
273
|
-
|
|
271
|
+
? newTv.counter
|
|
272
|
+
: Long.fromNumber(newTv.counter);
|
|
274
273
|
|
|
275
274
|
return currentCounter.compare(newCounter);
|
|
276
275
|
}
|
package/src/sdam/srv_polling.ts
CHANGED
|
@@ -95,7 +95,6 @@ export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
this._timeout = setTimeout(() => {
|
|
98
|
-
// eslint-disable-next-line github/no-then
|
|
99
98
|
this._poll().then(undefined, squashError);
|
|
100
99
|
}, this.intervalMS);
|
|
101
100
|
}
|
|
@@ -117,7 +116,7 @@ export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {
|
|
|
117
116
|
|
|
118
117
|
try {
|
|
119
118
|
srvRecords = await dns.promises.resolveSrv(this.srvAddress);
|
|
120
|
-
} catch
|
|
119
|
+
} catch {
|
|
121
120
|
this.failure();
|
|
122
121
|
return;
|
|
123
122
|
}
|