@mongosh/shell-api 3.22.0 → 3.24.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.
@@ -3,26 +3,20 @@
3
3
  import type { Agent } from 'https';
4
4
  import type { AgentConnectOpts } from 'agent-base';
5
5
  import { Binary } from 'bson';
6
+ import type { BSON } from '@mongosh/shell-bson';
6
7
  import { BSONRegExp } from 'bson';
7
- import { BSONSymbol } from 'bson';
8
8
  import { BSONType } from 'bson';
9
- import { calculateObjectSize } from 'bson';
10
9
  import type { ClientRequest } from 'http';
11
- import { Code } from 'bson';
12
10
  import type { ConnectionOptions } from 'tls';
13
- import { DBRef } from 'bson';
14
11
  import { Decimal128 } from 'bson';
15
12
  import type { DeserializeOptions } from 'bson';
16
13
  import { Document as Document_2 } from 'bson';
17
14
  import { Double } from 'bson';
18
15
  import type { Duplex } from 'stream';
19
- import { EJSONOptions } from 'bson';
20
16
  import { EventEmitter } from 'events';
21
17
  import type { IncomingMessage } from 'http';
22
18
  import { Int32 } from 'bson';
23
19
  import { Long } from 'bson';
24
- import { MaxKey } from 'bson';
25
- import { MinKey } from 'bson';
26
20
  import { ObjectId } from 'bson';
27
21
  import type { ObjectIdLike } from 'bson';
28
22
  import { Readable } from 'stream';
@@ -30,6 +24,7 @@ import type { RequestOptions } from 'https';
30
24
  import type { SecureContextOptions } from 'tls';
31
25
  import type { SerializeOptions } from 'bson';
32
26
  import type { ServerResponse } from 'http';
27
+ import { ShellBson } from '@mongosh/shell-bson';
33
28
  import type { SrvRecord } from 'dns';
34
29
  import type { TcpNetConnectOpts } from 'net';
35
30
  import { Timestamp } from 'bson';
@@ -253,32 +248,6 @@ declare abstract class AbstractCursor<TSchema = any, CursorEvents extends Abstra
253
248
  /* Excluded from this release type: transformDocument */
254
249
  /* Excluded from this release type: throwIfInitialized */
255
250
  }
256
- declare abstract class AbstractCursor_2<CursorType extends ServiceProviderAggregationCursor | ServiceProviderFindCursor | ServiceProviderRunCommandCursor> extends ShellApiWithMongoClass {
257
- _mongo: Mongo;
258
- _cursor: CursorType;
259
- _transform: ((doc: any) => any) | null;
260
- _currentIterationResult: CursorIterationResult | null;
261
- constructor(mongo: Mongo, cursor: CursorType);
262
- [asPrintable](): Promise<CursorIterationResult>;
263
- _it(): Promise<CursorIterationResult>;
264
- batchSize(size: number): this;
265
- close(): Promise<void>;
266
- forEach(f: (doc: Document_2) => void | boolean | Promise<void> | Promise<boolean>): Promise<void>;
267
- hasNext(): Promise<boolean>;
268
- tryNext(): Promise<Document_2 | null>;
269
- _tryNext(): Promise<Document_2 | null>;
270
- _canDelegateIterationToUnderlyingCursor(): boolean;
271
- [Symbol.asyncIterator](): AsyncGenerator<Document_2, void, void>;
272
- isClosed(): boolean;
273
- isExhausted(): boolean;
274
- itcount(): Promise<number>;
275
- toArray(): Promise<Document_2[]>;
276
- pretty(): this;
277
- map(f: (doc: Document_2) => Document_2): this;
278
- maxTimeMS(value: number): this;
279
- next(): Promise<Document_2 | null>;
280
- objsLeftInBatch(): number;
281
- }
282
251
 
283
252
  /** @public */
284
253
  declare type AbstractCursorEvents = {
@@ -362,6 +331,16 @@ declare interface AbstractCursorOptions extends BSONSerializeOptions {
362
331
  timeoutMode?: CursorTimeoutMode;
363
332
  /* Excluded from this release type: timeoutContext */
364
333
  }
334
+ declare abstract class AbstractFiniteCursor<CursorType extends ServiceProviderAggregationCursor | ServiceProviderFindCursor | ServiceProviderRunCommandCursor> extends BaseCursor<CursorType> {
335
+ _currentIterationResult: CursorIterationResult | null;
336
+ constructor(mongo: Mongo, cursor: CursorType);
337
+ [asPrintable](): Promise<CursorIterationResult | string>;
338
+ _it(): Promise<CursorIterationResult>;
339
+ batchSize(size: number): this;
340
+ toArray(): Promise<Document_2[]>;
341
+ maxTimeMS(value: number): this;
342
+ objsLeftInBatch(): number;
343
+ }
365
344
 
366
345
  /** @public */
367
346
  declare type AcceptedFields<TSchema, FieldType, AssignableType> = { readonly [key in KeysOfAType<TSchema, FieldType>]?: AssignableType };
@@ -470,7 +449,8 @@ declare class Admin {
470
449
  declare interface Admin_2 {
471
450
  platform: ReplPlatform;
472
451
  initialDb: string;
473
- bsonLibrary: typeof bson;
452
+ bsonLibrary: BSON;
453
+ computeLegacyHexMD5?(str: string): Promise<string>;
474
454
  listDatabases(database: string, options?: ListDatabasesOptions): Promise<Document_2>;
475
455
  getNewConnection(uri: string, options: MongoClientOptions): Promise<any>;
476
456
  getURI(): string | undefined;
@@ -532,7 +512,7 @@ declare interface AggregateOptions extends Omit<CommandOperationOptions, 'explai
532
512
  explain?: ExplainOptions['explain'];
533
513
  /* Excluded from this release type: timeoutMode */
534
514
  }
535
- declare abstract class AggregateOrFindCursor<CursorType extends ServiceProviderAggregationCursor | ServiceProviderFindCursor> extends AbstractCursor_2<CursorType> {
515
+ declare abstract class AggregateOrFindCursor<CursorType extends ServiceProviderAggregationCursor | ServiceProviderFindCursor> extends AbstractFiniteCursor<CursorType> {
536
516
  projection(spec: Document_2): this;
537
517
  skip(value: number): this;
538
518
  sort(spec: Document_2): this;
@@ -1043,6 +1023,32 @@ declare type AzureKMSProviderConfiguration = {
1043
1023
  */
1044
1024
  accessToken: string;
1045
1025
  };
1026
+ declare abstract class BaseCursor<CursorType extends ServiceProviderBaseCursor> extends ShellApiWithMongoClass {
1027
+ _mongo: Mongo;
1028
+ _cursor: CursorType;
1029
+ _transform: ((doc: any) => any) | null;
1030
+ _blockingWarningDisabled: boolean;
1031
+ constructor(mongo: Mongo, cursor: CursorType);
1032
+ close(): Promise<void>;
1033
+ forEach(f: (doc: Document_2) => void | boolean | Promise<void> | Promise<boolean>): Promise<void>;
1034
+ hasNext(): Promise<boolean>;
1035
+ tryNext(): Promise<Document_2 | null>;
1036
+ _tryNext(): Promise<Document_2 | null>;
1037
+ _canDelegateIterationToUnderlyingCursor(): boolean;
1038
+ [Symbol.asyncIterator](): AsyncGenerator<Document_2, void, void>;
1039
+ isClosed(): boolean;
1040
+ isExhausted(): boolean;
1041
+ itcount(): Promise<number>;
1042
+ pretty(): this;
1043
+ map(f: (doc: Document_2) => Document_2): this;
1044
+ next(): Promise<Document_2 | null>;
1045
+ disableBlockWarnings(): this;
1046
+ abstract batchSize(size: number): this;
1047
+ abstract toArray(): Promise<Document_2[]>;
1048
+ abstract maxTimeMS(value: number): this;
1049
+ abstract objsLeftInBatch(): number;
1050
+ abstract _it(): Promise<CursorIterationResult>;
1051
+ }
1046
1052
  declare interface BaseSocks5RequestMetadata {
1047
1053
  srcAddr: string;
1048
1054
  srcPort: number;
@@ -1079,28 +1085,6 @@ declare type BatchType = (typeof BatchType)[keyof typeof BatchType];
1079
1085
 
1080
1086
  /** @public */
1081
1087
  declare type BitwiseFilter = number /** numeric bit mask */ | Binary /** BinData bit mask */ | ReadonlyArray<number>;
1082
- declare const bson: {
1083
- ObjectId: typeof ObjectId;
1084
- DBRef: typeof DBRef;
1085
- MaxKey: typeof MaxKey;
1086
- MinKey: typeof MinKey;
1087
- Timestamp: typeof Timestamp;
1088
- BSONSymbol: typeof BSONSymbol;
1089
- Code: typeof Code;
1090
- Decimal128: typeof Decimal128;
1091
- Int32: typeof Int32;
1092
- Long: typeof Long;
1093
- Binary: typeof Binary;
1094
- calculateObjectSize: typeof calculateObjectSize;
1095
- Double: typeof Double;
1096
- EJSON: {
1097
- parse: (text: string, options?: EJSONOptions) => any;
1098
- stringify: (value: any, replacer?: (number | string)[] | ((this: any, key: string, value: any) => any) | EJSONOptions, space?: string | number, options?: EJSONOptions) => string;
1099
- serialize: (value: any, options?: EJSONOptions) => Document_2;
1100
- deserialize: (ejson: Document_2, options?: EJSONOptions) => any;
1101
- };
1102
- BSONRegExp: typeof BSONRegExp;
1103
- };
1104
1088
 
1105
1089
  /**
1106
1090
  * BSON Serialization options.
@@ -1532,18 +1516,12 @@ declare interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCo
1532
1516
  /** Describes the type of operation represented in this change notification */
1533
1517
  operationType: 'createIndexes';
1534
1518
  }
1535
- declare class ChangeStreamCursor extends ShellApiWithMongoClass {
1536
- _mongo: Mongo;
1537
- _cursor: ServiceProviderChangeStream<Document_2>;
1519
+ declare class ChangeStreamCursor extends BaseCursor<ServiceProviderChangeStream> {
1538
1520
  _currentIterationResult: CursorIterationResult | null;
1539
1521
  _on: string;
1540
- constructor(cursor: ServiceProviderChangeStream<Document_2>, on: string, mongo: Mongo);
1522
+ constructor(cursor: ServiceProviderChangeStream, on: string, mongo: Mongo);
1541
1523
  _it(): Promise<CursorIterationResult>;
1542
- [asPrintable](): string;
1543
- /*
1544
- Instructs the server to close a cursor and free associated server resources.
1545
- */
1546
- close(): void;
1524
+ [asPrintable](): Promise<string>;
1547
1525
  /*
1548
1526
  WARNING: on change streams this method will block unless the cursor is closed. Use tryNext to check if there are any documents in the batch. This is a breaking change
1549
1527
  */
@@ -1552,20 +1530,11 @@ declare class ChangeStreamCursor extends ShellApiWithMongoClass {
1552
1530
  If there is a document in the change stream, it will be returned. Otherwise returns null.
1553
1531
  */
1554
1532
  tryNext(): Document_2 | null;
1555
- [Symbol.asyncIterator](): AsyncGenerator<Document_2, void, unknown>;
1556
- /*
1557
- Returns true if the cursor is closed
1558
- */
1559
- isClosed(): boolean;
1560
1533
  /*
1561
1534
  This method is deprecated because because after closing a cursor, the remaining documents in the batch are no longer accessible. If you want to see if the cursor is closed use cursor.isClosed. If you want to see if there are documents left in the batch, use cursor.tryNext. This is a breaking change
1562
1535
  */
1563
1536
  isExhausted(): never;
1564
1537
  /*
1565
- Returns the number of documents in the current batch. NOTE: this method exhausts the cursor batch
1566
- */
1567
- itcount(): number;
1568
- /*
1569
1538
  WARNING: on change streams this method will block unless the cursor is closed. Use tryNext to get the next document in the batch. This is a breaking change
1570
1539
  */
1571
1540
  next(): Document_2;
@@ -1573,11 +1542,16 @@ declare class ChangeStreamCursor extends ShellApiWithMongoClass {
1573
1542
  Returns the ResumeToken of the change stream
1574
1543
  */
1575
1544
  getResumeToken(): ResumeToken;
1576
- map(): ChangeStreamCursor;
1577
- forEach(): Promise<void>;
1578
- toArray(): Promise<Document_2[]>;
1579
- objsLeftInBatch(): void;
1580
- pretty(): ChangeStreamCursor;
1545
+ toArray(): never;
1546
+ /*
1547
+ Not available on change streams
1548
+ */
1549
+ batchSize(): never;
1550
+ objsLeftInBatch(): never;
1551
+ /*
1552
+ Not available on change streams
1553
+ */
1554
+ maxTimeMS(): never;
1581
1555
  }
1582
1556
 
1583
1557
  /**
@@ -6265,26 +6239,6 @@ declare interface HedgeOptions {
6265
6239
  /** Explicitly enable or disable hedged reads. */
6266
6240
  enabled?: boolean;
6267
6241
  }
6268
- declare class Help {
6269
- private help;
6270
- private docs;
6271
- private attr;
6272
- constructor(properties: HelpProperties, options?: HelpOptions);
6273
- [asPrintable](): HelpProperties;
6274
- get [shellApiType](): string;
6275
- }
6276
- declare type HelpOptions = {
6277
- translate(key: string): string | undefined;
6278
- };
6279
- declare type HelpProperties = {
6280
- help: string;
6281
- docs?: string;
6282
- attr?: HelpPropertiesAttr[];
6283
- };
6284
- declare type HelpPropertiesAttr = {
6285
- name?: string;
6286
- description: string;
6287
- };
6288
6242
 
6289
6243
  /** @public */
6290
6244
  declare type Hint = string | Document_2;
@@ -6941,7 +6895,6 @@ declare interface LogComponentSeveritiesClientOptions {
6941
6895
  /** Optional default severity level to be used if any of the above are unset */
6942
6896
  default?: SeverityLevel;
6943
6897
  }
6944
- declare type LongWithoutAccidentallyExposedMethods = Omit<typeof bson.Long, 'fromExtendedJSON'>;
6945
6898
  declare type MapReduceShellOptions = Document_2 | string;
6946
6899
  declare type MasterKey = AWSEncryptionKeyOptions | AzureEncryptionKeyOptions | GCPEncryptionKeyOptions;
6947
6900
 
@@ -6997,7 +6950,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
6997
6950
  _listDatabases(opts?: ListDatabasesOptions): Promise<{
6998
6951
  databases: {
6999
6952
  name: string;
7000
- sizeOnDisk: number | ShellBson['Long'];
6953
+ sizeOnDisk: number | BSON['Long']['prototype'];
7001
6954
  empty: boolean;
7002
6955
  }[];
7003
6956
  ok: 1;
@@ -7009,7 +6962,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
7009
6962
  getDBs(options?: ListDatabasesOptions): {
7010
6963
  databases: {
7011
6964
  name: string;
7012
- sizeOnDisk: number | ShellBson['Long'];
6965
+ sizeOnDisk: number | BSON['Long']['prototype'];
7013
6966
  empty: boolean;
7014
6967
  }[];
7015
6968
  ok: 1;
@@ -7102,7 +7055,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
7102
7055
  /*
7103
7056
  Returns the hashed value for the input using the same hashing function as a hashed index.
7104
7057
  */
7105
- convertShardKeyToHashed(value: any): unknown;
7058
+ convertShardKeyToHashed(value: any): ShellBson['Long']['prototype'];
7106
7059
  }
7107
7060
 
7108
7061
  /** @public */
@@ -7730,7 +7683,7 @@ declare interface MongoDBOIDCLogEventsMap {
7730
7683
  }) => void;
7731
7684
  'mongodb-oidc-plugin:skip-auth-attempt': (event: {
7732
7685
  authStateId: string;
7733
- reason: string;
7686
+ reason: 'not-expired' | 'not-expired-refresh-failed' | 'refresh-succeeded';
7734
7687
  }) => void;
7735
7688
  'mongodb-oidc-plugin:auth-failed': (event: {
7736
7689
  authStateId: string;
@@ -8902,7 +8855,7 @@ declare class RunCommandCursor extends AbstractCursor {
8902
8855
  /* Excluded from this release type: _initialize */
8903
8856
  /* Excluded from this release type: getMore */
8904
8857
  }
8905
- declare class RunCommandCursor_2 extends AbstractCursor_2<ServiceProviderRunCommandCursor> {
8858
+ declare class RunCommandCursor_2 extends AbstractFiniteCursor<ServiceProviderRunCommandCursor> {
8906
8859
  constructor(mongo: Mongo, cursor: ServiceProviderRunCommandCursor);
8907
8860
  }
8908
8861
 
@@ -9460,6 +9413,15 @@ export declare class Shard<M extends GenericServerSideSchema = GenericServerSide
9460
9413
  Disable balancing on a single collection in a sharded database. Does not affect balancing of other collections in a sharded cluster.
9461
9414
  */
9462
9415
  disableBalancing(ns: string): UpdateResult_2;
9416
+ private _setAllowMigrations;
9417
+ /*
9418
+ Enables migrations for a specific collection. Uses `setAllowMigrations` admin command.
9419
+ */
9420
+ enableMigrations(ns: string): Document_2;
9421
+ /*
9422
+ Disables migrations for a specific collection. Uses `setAllowMigrations` admin command.
9423
+ */
9424
+ disableMigrations(ns: string): Document_2;
9463
9425
  /*
9464
9426
  Returns true when the balancer is enabled and false if the balancer is disabled. This does not reflect the current state of balancing operations: use sh.isBalancerRunning() to check the balancer’s current state.
9465
9427
  */
@@ -9643,7 +9605,7 @@ export declare class ShellApi extends ShellApiClass {
9643
9605
  /*
9644
9606
  result of the last line evaluated; use to further iterate
9645
9607
  */
9646
- it(): any;
9608
+ it(): CursorIterationResult;
9647
9609
  /*
9648
9610
  Shell version
9649
9611
  */
@@ -9713,35 +9675,7 @@ declare interface ShellAuthOptions {
9713
9675
  digestPassword?: boolean;
9714
9676
  authDb?: string;
9715
9677
  }
9716
- export declare type ShellBson = WithHelp<ShellBsonBase>;
9717
- declare interface ShellBsonBase {
9718
- DBRef: (namespace: string, oid: any, db?: string, fields?: Document_2) => typeof bson.DBRef.prototype;
9719
- bsonsize: (object: any) => number;
9720
- MaxKey: () => typeof bson.MaxKey.prototype;
9721
- MinKey: () => typeof bson.MinKey.prototype;
9722
- ObjectId: (id?: string | number | typeof bson.ObjectId.prototype | Buffer) => typeof bson.ObjectId.prototype;
9723
- Timestamp: (t?: number | typeof bson.Long.prototype | {
9724
- t: number;
9725
- i: number;
9726
- }, i?: number) => typeof bson.Timestamp.prototype;
9727
- Code: (c?: string | Function, s?: any) => typeof bson.Code.prototype;
9728
- NumberDecimal: (s?: string) => typeof bson.Decimal128.prototype;
9729
- NumberInt: (v?: string) => typeof bson.Int32.prototype;
9730
- NumberLong: (s?: string | number) => typeof bson.Long.prototype;
9731
- ISODate: (input?: string) => Date;
9732
- BinData: (subtype: number, b64string: string) => Binary;
9733
- HexData: (subtype: number, hexstr: string) => Binary;
9734
- UUID: (hexstr?: string) => Binary;
9735
- MD5: (hexstr: string) => Binary;
9736
- Decimal128: typeof bson.Decimal128;
9737
- BSONSymbol: typeof bson.BSONSymbol;
9738
- Int32: typeof bson.Int32;
9739
- Long: LongWithoutAccidentallyExposedMethods;
9740
- Binary: typeof bson.Binary;
9741
- Double: typeof bson.Double;
9742
- EJSON: typeof bson.EJSON;
9743
- BSONRegExp: typeof bson.BSONRegExp;
9744
- }
9678
+ export { ShellBson };
9745
9679
  declare interface ShellCliOptions {
9746
9680
  nodb?: boolean;
9747
9681
  }
@@ -9765,7 +9699,7 @@ declare class ShellConfig extends ShellApiClass {
9765
9699
  [asPrintable](): Promise<Map<keyof ShellUserConfig, ShellUserConfig[keyof ShellUserConfig]>>;
9766
9700
  }
9767
9701
  declare class ShellInstanceState {
9768
- currentCursor: Cursor | AggregationCursor_2 | ChangeStreamCursor | RunCommandCursor_2 | null;
9702
+ currentCursor: BaseCursor<ServiceProviderBaseCursor> | null;
9769
9703
  currentDb: DatabaseWithSchema;
9770
9704
  messageBus: MongoshBus;
9771
9705
  initialServiceProvider: ServiceProvider;
@@ -9790,6 +9724,7 @@ declare class ShellInstanceState {
9790
9724
  private alreadyTransformedErrors;
9791
9725
  private preFetchCollectionAndDatabaseNames;
9792
9726
  constructor(initialServiceProvider: ServiceProvider, messageBus?: any, cliOptions?: ShellCliOptions);
9727
+ private constructShellBson;
9793
9728
  fetchConnectionInfo(): Promise<ConnectionInfo_2 | undefined>;
9794
9729
  cachedConnectionInfo(): ConnectionInfo_2 | undefined;
9795
9730
  close(): Promise<void>;
@@ -10516,9 +10451,6 @@ declare interface ValidateCollectionOptions extends CommandOperationOptions {
10516
10451
 
10517
10452
  /** @public */
10518
10453
  declare type W = number | 'majority';
10519
- declare type WithHelp<T> = { [prop in keyof T]: T[prop] & {
10520
- help?: () => Help;
10521
- } };
10522
10454
 
10523
10455
  /** Add an _id field to an object shaped type @public */
10524
10456
  declare type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & {