mongodb 6.17.0-dev.20250604.sha.441186ae → 6.17.0-dev.20250605.sha.57ef31be

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.
Files changed (53) hide show
  1. package/lib/beta.d.ts +28 -16
  2. package/lib/bulk/common.js.map +1 -1
  3. package/lib/change_stream.js.map +1 -1
  4. package/lib/client-side-encryption/state_machine.js.map +1 -1
  5. package/lib/cmap/commands.js +10 -8
  6. package/lib/cmap/commands.js.map +1 -1
  7. package/lib/cmap/handshake/client_metadata.js +1 -1
  8. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  9. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  10. package/lib/cmap/wire_protocol/on_data.js +4 -0
  11. package/lib/cmap/wire_protocol/on_data.js.map +1 -1
  12. package/lib/cmap/wire_protocol/on_demand/document.js +16 -15
  13. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
  14. package/lib/cmap/wire_protocol/responses.js +11 -4
  15. package/lib/cmap/wire_protocol/responses.js.map +1 -1
  16. package/lib/connection_string.js +2 -0
  17. package/lib/connection_string.js.map +1 -1
  18. package/lib/cursor/abstract_cursor.js.map +1 -1
  19. package/lib/index.js.map +1 -1
  20. package/lib/operations/distinct.js +1 -0
  21. package/lib/operations/distinct.js.map +1 -1
  22. package/lib/operations/rename.js.map +1 -1
  23. package/lib/operations/run_command.js.map +1 -1
  24. package/lib/operations/search_indexes/create.js.map +1 -1
  25. package/lib/operations/search_indexes/drop.js.map +1 -1
  26. package/lib/operations/search_indexes/update.js.map +1 -1
  27. package/lib/utils.js +0 -1
  28. package/lib/utils.js.map +1 -1
  29. package/lib/write_concern.js +2 -4
  30. package/lib/write_concern.js.map +1 -1
  31. package/mongodb.d.ts +28 -16
  32. package/package.json +3 -3
  33. package/src/bulk/common.ts +3 -5
  34. package/src/change_stream.ts +38 -13
  35. package/src/client-side-encryption/state_machine.ts +7 -4
  36. package/src/cmap/commands.ts +31 -16
  37. package/src/cmap/handshake/client_metadata.ts +5 -1
  38. package/src/cmap/wire_protocol/compression.ts +2 -1
  39. package/src/cmap/wire_protocol/on_data.ts +5 -0
  40. package/src/cmap/wire_protocol/on_demand/document.ts +19 -14
  41. package/src/cmap/wire_protocol/responses.ts +8 -8
  42. package/src/connection_string.ts +2 -0
  43. package/src/cursor/abstract_cursor.ts +6 -4
  44. package/src/index.ts +2 -0
  45. package/src/operations/distinct.ts +1 -0
  46. package/src/operations/rename.ts +8 -5
  47. package/src/operations/run_command.ts +17 -4
  48. package/src/operations/search_indexes/create.ts +6 -4
  49. package/src/operations/search_indexes/drop.ts +6 -4
  50. package/src/operations/search_indexes/update.ts +8 -5
  51. package/src/utils.ts +8 -8
  52. package/src/write_concern.ts +2 -4
  53. package/tsconfig.json +2 -1
@@ -76,12 +76,10 @@ export class OpQueryRequest {
76
76
  partial: boolean;
77
77
  /** moreToCome is an OP_MSG only concept */
78
78
  moreToCome = false;
79
+ databaseName: string;
80
+ query: Document;
79
81
 
80
- constructor(
81
- public databaseName: string,
82
- public query: Document,
83
- options: OpQueryOptions
84
- ) {
82
+ constructor(databaseName: string, query: Document, options: OpQueryOptions) {
85
83
  // Basic options needed to be passed in
86
84
  // TODO(NODE-3483): Replace with MongoCommandError
87
85
  const ns = `${databaseName}.$cmd`;
@@ -97,7 +95,9 @@ export class OpQueryRequest {
97
95
  throw new MongoRuntimeError('Namespace cannot contain a null character');
98
96
  }
99
97
 
100
- // Basic options
98
+ // Basic optionsa
99
+ this.databaseName = databaseName;
100
+ this.query = query;
101
101
  this.ns = ns;
102
102
 
103
103
  // Additional options
@@ -496,17 +496,18 @@ export class OpMsgRequest {
496
496
  checksumPresent: boolean;
497
497
  moreToCome: boolean;
498
498
  exhaustAllowed: boolean;
499
+ databaseName: string;
500
+ command: Document;
501
+ options: OpQueryOptions;
499
502
 
500
- constructor(
501
- public databaseName: string,
502
- public command: Document,
503
- public options: OpQueryOptions
504
- ) {
503
+ constructor(databaseName: string, command: Document, options: OpQueryOptions) {
505
504
  // Basic options needed to be passed in
506
505
  if (command == null)
507
506
  throw new MongoInvalidArgumentError('Query document must be specified for query');
508
507
 
509
- // Basic options
508
+ // Basic optionsa
509
+ this.databaseName = databaseName;
510
+ this.command = command;
510
511
  this.command.$db = databaseName;
511
512
 
512
513
  // Ensure empty options
@@ -724,16 +725,30 @@ export class OpMsgResponse {
724
725
  const MESSAGE_HEADER_SIZE = 16;
725
726
  const COMPRESSION_DETAILS_SIZE = 9; // originalOpcode + uncompressedSize, compressorID
726
727
 
728
+ /**
729
+ * @internal
730
+ */
731
+ export interface OpCompressesRequestOptions {
732
+ zlibCompressionLevel: number;
733
+ agreedCompressor: CompressorName;
734
+ }
735
+
727
736
  /**
728
737
  * @internal
729
738
  *
730
739
  * An OP_COMPRESSED request wraps either an OP_QUERY or OP_MSG message.
731
740
  */
732
741
  export class OpCompressedRequest {
733
- constructor(
734
- private command: WriteProtocolMessageType,
735
- private options: { zlibCompressionLevel: number; agreedCompressor: CompressorName }
736
- ) {}
742
+ private command: WriteProtocolMessageType;
743
+ private options: OpCompressesRequestOptions;
744
+
745
+ constructor(command: WriteProtocolMessageType, options: OpCompressesRequestOptions) {
746
+ this.command = command;
747
+ this.options = {
748
+ zlibCompressionLevel: options.zlibCompressionLevel,
749
+ agreedCompressor: options.agreedCompressor
750
+ };
751
+ }
737
752
 
738
753
  // Return whether a command contains an uncompressible command term
739
754
  // Will return true if command contains no uncompressible command terms
@@ -53,7 +53,11 @@ export class LimitedSizeDocument {
53
53
  private document = new Map();
54
54
  /** BSON overhead: Int32 + Null byte */
55
55
  private documentSize = 5;
56
- constructor(private maxSize: number) {}
56
+ private maxSize: number;
57
+
58
+ constructor(maxSize: number) {
59
+ this.maxSize = maxSize;
60
+ }
57
61
 
58
62
  /** Only adds key/value if the bsonByteLength is less than MAX_SIZE */
59
63
  public ifItFitsItSits(key: string, value: Record<string, any> | string): boolean {
@@ -7,6 +7,7 @@ import { MongoDecompressionError, MongoInvalidArgumentError } from '../../error'
7
7
  import {
8
8
  type MessageHeader,
9
9
  OpCompressedRequest,
10
+ type OpCompressesRequestOptions,
10
11
  OpMsgResponse,
11
12
  OpReply,
12
13
  type WriteProtocolMessageType
@@ -60,7 +61,7 @@ function loadSnappy() {
60
61
 
61
62
  // Facilitate compressing a message using an agreed compressor
62
63
  export async function compress(
63
- options: { zlibCompressionLevel: number; agreedCompressor: CompressorName },
64
+ options: OpCompressesRequestOptions,
64
65
  dataToBeCompressed: Buffer
65
66
  ): Promise<Buffer> {
66
67
  const zlibOptions = {} as zlib.ZlibOptions;
@@ -87,6 +87,11 @@ export function onData(
87
87
 
88
88
  [Symbol.asyncIterator]() {
89
89
  return this;
90
+ },
91
+
92
+ // Note this should currently not be used, but is required by the AsyncGenerator interface.
93
+ async [Symbol.asyncDispose]() {
94
+ await closeHandler();
90
95
  }
91
96
  };
92
97
 
@@ -14,14 +14,13 @@ import {
14
14
  toUTF8
15
15
  } from '../../../bson';
16
16
 
17
- // eslint-disable-next-line no-restricted-syntax
18
- const enum BSONElementOffset {
19
- type = 0,
20
- nameOffset = 1,
21
- nameLength = 2,
22
- offset = 3,
23
- length = 4
24
- }
17
+ const BSONElementOffset = {
18
+ type: 0,
19
+ nameOffset: 1,
20
+ nameLength: 2,
21
+ offset: 3,
22
+ length: 4
23
+ } as const;
25
24
 
26
25
  /** @internal */
27
26
  export type JSTypeOf = {
@@ -67,17 +66,23 @@ export class OnDemandDocument {
67
66
 
68
67
  /** All bson elements in this document */
69
68
  private readonly elements: ReadonlyArray<BSONElement>;
69
+ /** BSON bytes, this document begins at offset */
70
+ protected readonly bson: Uint8Array;
71
+ /** The start of the document */
72
+ private readonly offset: number;
73
+ /** If this is an embedded document, indicates if this was a BSON array */
74
+ public readonly isArray: boolean;
70
75
 
71
76
  constructor(
72
- /** BSON bytes, this document begins at offset */
73
- protected readonly bson: Uint8Array,
74
- /** The start of the document */
75
- private readonly offset = 0,
76
- /** If this is an embedded document, indicates if this was a BSON array */
77
- public readonly isArray = false,
77
+ bson: Uint8Array,
78
+ offset = 0,
79
+ isArray = false,
78
80
  /** If elements was already calculated */
79
81
  elements?: BSONElement[]
80
82
  ) {
83
+ this.bson = bson;
84
+ this.offset = offset;
85
+ this.isArray = isArray;
81
86
  this.elements = elements ?? parseToElementsToArray(this.bson, offset);
82
87
  }
83
88
 
@@ -20,14 +20,14 @@ import {
20
20
  type OnDemandDocumentDeserializeOptions
21
21
  } from './on_demand/document';
22
22
 
23
- // eslint-disable-next-line no-restricted-syntax
24
- const enum BSONElementOffset {
25
- type = 0,
26
- nameOffset = 1,
27
- nameLength = 2,
28
- offset = 3,
29
- length = 4
30
- }
23
+ const BSONElementOffset = {
24
+ type: 0,
25
+ nameOffset: 1,
26
+ nameLength: 2,
27
+ offset: 3,
28
+ length: 4
29
+ } as const;
30
+
31
31
  /**
32
32
  * Accepts a BSON payload and checks for na "ok: 0" element.
33
33
  * This utility is intended to prevent calling response class constructors
@@ -605,6 +605,8 @@ function setOption(
605
605
  if (values[0] == null) {
606
606
  break;
607
607
  }
608
+ // The value should always be a string here, but since the array is typed as unknown
609
+ // there still needs to be an explicit cast.
608
610
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
609
611
  mongoOptions[name] = String(values[0]);
610
612
  break;
@@ -1213,11 +1213,13 @@ configureResourceManagement(AbstractCursor.prototype);
1213
1213
  * All timeout behavior is exactly the same as the wrapped timeout context's.
1214
1214
  */
1215
1215
  export class CursorTimeoutContext extends TimeoutContext {
1216
- constructor(
1217
- public timeoutContext: TimeoutContext,
1218
- public owner: symbol | AbstractCursor
1219
- ) {
1216
+ timeoutContext: TimeoutContext;
1217
+ owner: symbol | AbstractCursor;
1218
+
1219
+ constructor(timeoutContext: TimeoutContext, owner: symbol | AbstractCursor) {
1220
1220
  super();
1221
+ this.timeoutContext = timeoutContext;
1222
+ this.owner = owner;
1221
1223
  }
1222
1224
  override get serverSelectionTimeout(): Timeout | null {
1223
1225
  return this.timeoutContext.serverSelectionTimeout;
package/src/index.ts CHANGED
@@ -208,6 +208,7 @@ export type {
208
208
  ChangeStreamDocumentCommon,
209
209
  ChangeStreamDocumentKey,
210
210
  ChangeStreamDocumentOperationDescription,
211
+ ChangeStreamDocumentWallTime,
211
212
  ChangeStreamDropDatabaseDocument,
212
213
  ChangeStreamDropDocument,
213
214
  ChangeStreamDropIndexDocument,
@@ -287,6 +288,7 @@ export type { TokenCache } from './cmap/auth/mongodb_oidc/token_cache';
287
288
  export type {
288
289
  MessageHeader,
289
290
  OpCompressedRequest,
291
+ OpCompressesRequestOptions,
290
292
  OpMsgOptions,
291
293
  OpMsgRequest,
292
294
  OpMsgResponse,
@@ -96,6 +96,7 @@ export class DistinctOperation extends CommandOperation<any[]> {
96
96
 
97
97
  const result = await super.executeCommand(server, session, cmd, timeoutContext);
98
98
 
99
+ // @ts-expect-error: Explain always returns a document
99
100
  return this.explain ? result : result.values;
100
101
  }
101
102
  }
@@ -17,12 +17,15 @@ export interface RenameOptions extends CommandOperationOptions {
17
17
 
18
18
  /** @internal */
19
19
  export class RenameOperation extends CommandOperation<Document> {
20
- constructor(
21
- public collection: Collection,
22
- public newName: string,
23
- public override options: RenameOptions
24
- ) {
20
+ collection: Collection;
21
+ newName: string;
22
+ override options: RenameOptions;
23
+
24
+ constructor(collection: Collection, newName: string, options: RenameOptions) {
25
25
  super(collection, options);
26
+ this.collection = collection;
27
+ this.newName = newName;
28
+ this.options = options;
26
29
  this.ns = new MongoDBNamespace('admin', '$cmd');
27
30
  }
28
31
 
@@ -26,12 +26,17 @@ export type RunCommandOptions = {
26
26
 
27
27
  /** @internal */
28
28
  export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
29
+ command: Document;
30
+ override options: RunCommandOptions & { responseType?: MongoDBResponseConstructor };
31
+
29
32
  constructor(
30
33
  parent: Db,
31
- public command: Document,
32
- public override options: RunCommandOptions & { responseType?: MongoDBResponseConstructor }
34
+ command: Document,
35
+ options: RunCommandOptions & { responseType?: MongoDBResponseConstructor }
33
36
  ) {
34
37
  super(options);
38
+ this.command = command;
39
+ this.options = options;
35
40
  this.ns = parent.s.namespace.withCollection('$cmd');
36
41
  }
37
42
 
@@ -62,14 +67,22 @@ export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
62
67
  }
63
68
 
64
69
  export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T> {
70
+ command: Document;
71
+ override options: RunCommandOptions & {
72
+ noResponse?: boolean;
73
+ bypassPinningCheck?: boolean;
74
+ };
75
+
65
76
  constructor(
66
- public command: Document,
67
- public override options: RunCommandOptions & {
77
+ command: Document,
78
+ options: RunCommandOptions & {
68
79
  noResponse?: boolean;
69
80
  bypassPinningCheck?: boolean;
70
81
  }
71
82
  ) {
72
83
  super(options);
84
+ this.command = command;
85
+ this.options = options;
73
86
  this.ns = new MongoDBNamespace('admin', '$cmd');
74
87
  }
75
88
 
@@ -21,11 +21,13 @@ export interface SearchIndexDescription extends Document {
21
21
 
22
22
  /** @internal */
23
23
  export class CreateSearchIndexesOperation extends AbstractOperation<string[]> {
24
- constructor(
25
- private readonly collection: Collection,
26
- private readonly descriptions: ReadonlyArray<SearchIndexDescription>
27
- ) {
24
+ private readonly collection: Collection;
25
+ private readonly descriptions: ReadonlyArray<SearchIndexDescription>;
26
+
27
+ constructor(collection: Collection, descriptions: ReadonlyArray<SearchIndexDescription>) {
28
28
  super();
29
+ this.collection = collection;
30
+ this.descriptions = descriptions;
29
31
  }
30
32
 
31
33
  override get commandName() {
@@ -8,11 +8,13 @@ import { AbstractOperation } from '../operation';
8
8
 
9
9
  /** @internal */
10
10
  export class DropSearchIndexOperation extends AbstractOperation<void> {
11
- constructor(
12
- private readonly collection: Collection,
13
- private readonly name: string
14
- ) {
11
+ private readonly collection: Collection;
12
+ private readonly name: string;
13
+
14
+ constructor(collection: Collection, name: string) {
15
15
  super();
16
+ this.collection = collection;
17
+ this.name = name;
16
18
  }
17
19
 
18
20
  override get commandName() {
@@ -7,12 +7,15 @@ import { AbstractOperation } from '../operation';
7
7
 
8
8
  /** @internal */
9
9
  export class UpdateSearchIndexOperation extends AbstractOperation<void> {
10
- constructor(
11
- private readonly collection: Collection,
12
- private readonly name: string,
13
- private readonly definition: Document
14
- ) {
10
+ private readonly collection: Collection;
11
+ private readonly name: string;
12
+ private readonly definition: Document;
13
+
14
+ constructor(collection: Collection, name: string, definition: Document) {
15
15
  super();
16
+ this.collection = collection;
17
+ this.name = name;
18
+ this.definition = definition;
16
19
  }
17
20
 
18
21
  override get commandName() {
package/src/utils.ts CHANGED
@@ -281,16 +281,16 @@ export function ns(ns: string): MongoDBNamespace {
281
281
 
282
282
  /** @public */
283
283
  export class MongoDBNamespace {
284
+ db: string;
285
+ collection?: string;
284
286
  /**
285
287
  * Create a namespace object
286
288
  *
287
289
  * @param db - database name
288
290
  * @param collection - collection name
289
291
  */
290
- constructor(
291
- public db: string,
292
- public collection?: string
293
- ) {
292
+ constructor(db: string, collection?: string) {
293
+ this.db = db;
294
294
  this.collection = collection === '' ? undefined : collection;
295
295
  }
296
296
 
@@ -322,11 +322,11 @@ export class MongoDBNamespace {
322
322
  * used in scenarios where this can be guaranteed.
323
323
  */
324
324
  export class MongoDBCollectionNamespace extends MongoDBNamespace {
325
- constructor(
326
- db: string,
327
- override collection: string
328
- ) {
325
+ override collection: string;
326
+
327
+ constructor(db: string, collection: string) {
329
328
  super(db, collection);
329
+ this.collection = collection;
330
330
  }
331
331
 
332
332
  static override fromString(namespace?: string): MongoDBCollectionNamespace {
@@ -143,6 +143,7 @@ export class WriteConcern {
143
143
  const parentOpts: WriteConcern | WriteConcernSettings | undefined =
144
144
  inherit instanceof WriteConcern ? inherit : inherit.writeConcern;
145
145
 
146
+ const mergedOpts = { ...parentOpts, ...opts } as WriteConcernSettings;
146
147
  const {
147
148
  w = undefined,
148
149
  wtimeout = undefined,
@@ -150,10 +151,7 @@ export class WriteConcern {
150
151
  fsync = undefined,
151
152
  journal = undefined,
152
153
  wtimeoutMS = undefined
153
- } = {
154
- ...parentOpts,
155
- ...opts
156
- };
154
+ } = mergedOpts;
157
155
  if (
158
156
  w != null ||
159
157
  wtimeout != null ||
package/tsconfig.json CHANGED
@@ -11,7 +11,8 @@
11
11
  "lib": [
12
12
  "es2021",
13
13
  "ES2022.Error",
14
- "ES2022.Object"
14
+ "ES2022.Object",
15
+ "esnext.disposable"
15
16
  ],
16
17
  // We don't make use of tslib helpers, all syntax used is supported by target engine
17
18
  "importHelpers": false,