@mongosh/shell-api 3.22.0 → 3.23.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,7 @@ declare class Admin {
470
449
  declare interface Admin_2 {
471
450
  platform: ReplPlatform;
472
451
  initialDb: string;
473
- bsonLibrary: typeof bson;
452
+ bsonLibrary: BSON;
474
453
  listDatabases(database: string, options?: ListDatabasesOptions): Promise<Document_2>;
475
454
  getNewConnection(uri: string, options: MongoClientOptions): Promise<any>;
476
455
  getURI(): string | undefined;
@@ -532,7 +511,7 @@ declare interface AggregateOptions extends Omit<CommandOperationOptions, 'explai
532
511
  explain?: ExplainOptions['explain'];
533
512
  /* Excluded from this release type: timeoutMode */
534
513
  }
535
- declare abstract class AggregateOrFindCursor<CursorType extends ServiceProviderAggregationCursor | ServiceProviderFindCursor> extends AbstractCursor_2<CursorType> {
514
+ declare abstract class AggregateOrFindCursor<CursorType extends ServiceProviderAggregationCursor | ServiceProviderFindCursor> extends AbstractFiniteCursor<CursorType> {
536
515
  projection(spec: Document_2): this;
537
516
  skip(value: number): this;
538
517
  sort(spec: Document_2): this;
@@ -1043,6 +1022,32 @@ declare type AzureKMSProviderConfiguration = {
1043
1022
  */
1044
1023
  accessToken: string;
1045
1024
  };
1025
+ declare abstract class BaseCursor<CursorType extends ServiceProviderBaseCursor> extends ShellApiWithMongoClass {
1026
+ _mongo: Mongo;
1027
+ _cursor: CursorType;
1028
+ _transform: ((doc: any) => any) | null;
1029
+ _blockingWarningDisabled: boolean;
1030
+ constructor(mongo: Mongo, cursor: CursorType);
1031
+ close(): Promise<void>;
1032
+ forEach(f: (doc: Document_2) => void | boolean | Promise<void> | Promise<boolean>): Promise<void>;
1033
+ hasNext(): Promise<boolean>;
1034
+ tryNext(): Promise<Document_2 | null>;
1035
+ _tryNext(): Promise<Document_2 | null>;
1036
+ _canDelegateIterationToUnderlyingCursor(): boolean;
1037
+ [Symbol.asyncIterator](): AsyncGenerator<Document_2, void, void>;
1038
+ isClosed(): boolean;
1039
+ isExhausted(): boolean;
1040
+ itcount(): Promise<number>;
1041
+ pretty(): this;
1042
+ map(f: (doc: Document_2) => Document_2): this;
1043
+ next(): Promise<Document_2 | null>;
1044
+ disableBlockWarnings(): this;
1045
+ abstract batchSize(size: number): this;
1046
+ abstract toArray(): Promise<Document_2[]>;
1047
+ abstract maxTimeMS(value: number): this;
1048
+ abstract objsLeftInBatch(): number;
1049
+ abstract _it(): Promise<CursorIterationResult>;
1050
+ }
1046
1051
  declare interface BaseSocks5RequestMetadata {
1047
1052
  srcAddr: string;
1048
1053
  srcPort: number;
@@ -1079,28 +1084,6 @@ declare type BatchType = (typeof BatchType)[keyof typeof BatchType];
1079
1084
 
1080
1085
  /** @public */
1081
1086
  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
1087
 
1105
1088
  /**
1106
1089
  * BSON Serialization options.
@@ -1532,18 +1515,12 @@ declare interface ChangeStreamCreateIndexDocument extends ChangeStreamDocumentCo
1532
1515
  /** Describes the type of operation represented in this change notification */
1533
1516
  operationType: 'createIndexes';
1534
1517
  }
1535
- declare class ChangeStreamCursor extends ShellApiWithMongoClass {
1536
- _mongo: Mongo;
1537
- _cursor: ServiceProviderChangeStream<Document_2>;
1518
+ declare class ChangeStreamCursor extends BaseCursor<ServiceProviderChangeStream> {
1538
1519
  _currentIterationResult: CursorIterationResult | null;
1539
1520
  _on: string;
1540
- constructor(cursor: ServiceProviderChangeStream<Document_2>, on: string, mongo: Mongo);
1521
+ constructor(cursor: ServiceProviderChangeStream, on: string, mongo: Mongo);
1541
1522
  _it(): Promise<CursorIterationResult>;
1542
- [asPrintable](): string;
1543
- /*
1544
- Instructs the server to close a cursor and free associated server resources.
1545
- */
1546
- close(): void;
1523
+ [asPrintable](): Promise<string>;
1547
1524
  /*
1548
1525
  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
1526
  */
@@ -1552,20 +1529,11 @@ declare class ChangeStreamCursor extends ShellApiWithMongoClass {
1552
1529
  If there is a document in the change stream, it will be returned. Otherwise returns null.
1553
1530
  */
1554
1531
  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
1532
  /*
1561
1533
  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
1534
  */
1563
1535
  isExhausted(): never;
1564
1536
  /*
1565
- Returns the number of documents in the current batch. NOTE: this method exhausts the cursor batch
1566
- */
1567
- itcount(): number;
1568
- /*
1569
1537
  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
1538
  */
1571
1539
  next(): Document_2;
@@ -1573,11 +1541,16 @@ declare class ChangeStreamCursor extends ShellApiWithMongoClass {
1573
1541
  Returns the ResumeToken of the change stream
1574
1542
  */
1575
1543
  getResumeToken(): ResumeToken;
1576
- map(): ChangeStreamCursor;
1577
- forEach(): Promise<void>;
1578
- toArray(): Promise<Document_2[]>;
1579
- objsLeftInBatch(): void;
1580
- pretty(): ChangeStreamCursor;
1544
+ toArray(): never;
1545
+ /*
1546
+ Not available on change streams
1547
+ */
1548
+ batchSize(): never;
1549
+ objsLeftInBatch(): never;
1550
+ /*
1551
+ Not available on change streams
1552
+ */
1553
+ maxTimeMS(): never;
1581
1554
  }
1582
1555
 
1583
1556
  /**
@@ -6265,26 +6238,6 @@ declare interface HedgeOptions {
6265
6238
  /** Explicitly enable or disable hedged reads. */
6266
6239
  enabled?: boolean;
6267
6240
  }
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
6241
 
6289
6242
  /** @public */
6290
6243
  declare type Hint = string | Document_2;
@@ -6941,7 +6894,6 @@ declare interface LogComponentSeveritiesClientOptions {
6941
6894
  /** Optional default severity level to be used if any of the above are unset */
6942
6895
  default?: SeverityLevel;
6943
6896
  }
6944
- declare type LongWithoutAccidentallyExposedMethods = Omit<typeof bson.Long, 'fromExtendedJSON'>;
6945
6897
  declare type MapReduceShellOptions = Document_2 | string;
6946
6898
  declare type MasterKey = AWSEncryptionKeyOptions | AzureEncryptionKeyOptions | GCPEncryptionKeyOptions;
6947
6899
 
@@ -6997,7 +6949,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
6997
6949
  _listDatabases(opts?: ListDatabasesOptions): Promise<{
6998
6950
  databases: {
6999
6951
  name: string;
7000
- sizeOnDisk: number | ShellBson['Long'];
6952
+ sizeOnDisk: number | BSON['Long']['prototype'];
7001
6953
  empty: boolean;
7002
6954
  }[];
7003
6955
  ok: 1;
@@ -7009,7 +6961,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
7009
6961
  getDBs(options?: ListDatabasesOptions): {
7010
6962
  databases: {
7011
6963
  name: string;
7012
- sizeOnDisk: number | ShellBson['Long'];
6964
+ sizeOnDisk: number | BSON['Long']['prototype'];
7013
6965
  empty: boolean;
7014
6966
  }[];
7015
6967
  ok: 1;
@@ -7102,7 +7054,7 @@ export declare class Mongo<M extends GenericServerSideSchema = GenericServerSide
7102
7054
  /*
7103
7055
  Returns the hashed value for the input using the same hashing function as a hashed index.
7104
7056
  */
7105
- convertShardKeyToHashed(value: any): unknown;
7057
+ convertShardKeyToHashed(value: any): ShellBson['Long']['prototype'];
7106
7058
  }
7107
7059
 
7108
7060
  /** @public */
@@ -7730,7 +7682,7 @@ declare interface MongoDBOIDCLogEventsMap {
7730
7682
  }) => void;
7731
7683
  'mongodb-oidc-plugin:skip-auth-attempt': (event: {
7732
7684
  authStateId: string;
7733
- reason: string;
7685
+ reason: 'not-expired' | 'not-expired-refresh-failed' | 'refresh-succeeded';
7734
7686
  }) => void;
7735
7687
  'mongodb-oidc-plugin:auth-failed': (event: {
7736
7688
  authStateId: string;
@@ -8902,7 +8854,7 @@ declare class RunCommandCursor extends AbstractCursor {
8902
8854
  /* Excluded from this release type: _initialize */
8903
8855
  /* Excluded from this release type: getMore */
8904
8856
  }
8905
- declare class RunCommandCursor_2 extends AbstractCursor_2<ServiceProviderRunCommandCursor> {
8857
+ declare class RunCommandCursor_2 extends AbstractFiniteCursor<ServiceProviderRunCommandCursor> {
8906
8858
  constructor(mongo: Mongo, cursor: ServiceProviderRunCommandCursor);
8907
8859
  }
8908
8860
 
@@ -9643,7 +9595,7 @@ export declare class ShellApi extends ShellApiClass {
9643
9595
  /*
9644
9596
  result of the last line evaluated; use to further iterate
9645
9597
  */
9646
- it(): any;
9598
+ it(): CursorIterationResult;
9647
9599
  /*
9648
9600
  Shell version
9649
9601
  */
@@ -9713,35 +9665,7 @@ declare interface ShellAuthOptions {
9713
9665
  digestPassword?: boolean;
9714
9666
  authDb?: string;
9715
9667
  }
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
- }
9668
+ export { ShellBson };
9745
9669
  declare interface ShellCliOptions {
9746
9670
  nodb?: boolean;
9747
9671
  }
@@ -9765,7 +9689,7 @@ declare class ShellConfig extends ShellApiClass {
9765
9689
  [asPrintable](): Promise<Map<keyof ShellUserConfig, ShellUserConfig[keyof ShellUserConfig]>>;
9766
9690
  }
9767
9691
  declare class ShellInstanceState {
9768
- currentCursor: Cursor | AggregationCursor_2 | ChangeStreamCursor | RunCommandCursor_2 | null;
9692
+ currentCursor: BaseCursor<ServiceProviderBaseCursor> | null;
9769
9693
  currentDb: DatabaseWithSchema;
9770
9694
  messageBus: MongoshBus;
9771
9695
  initialServiceProvider: ServiceProvider;
@@ -9790,6 +9714,7 @@ declare class ShellInstanceState {
9790
9714
  private alreadyTransformedErrors;
9791
9715
  private preFetchCollectionAndDatabaseNames;
9792
9716
  constructor(initialServiceProvider: ServiceProvider, messageBus?: any, cliOptions?: ShellCliOptions);
9717
+ private constructShellBson;
9793
9718
  fetchConnectionInfo(): Promise<ConnectionInfo_2 | undefined>;
9794
9719
  cachedConnectionInfo(): ConnectionInfo_2 | undefined;
9795
9720
  close(): Promise<void>;
@@ -10516,9 +10441,6 @@ declare interface ValidateCollectionOptions extends CommandOperationOptions {
10516
10441
 
10517
10442
  /** @public */
10518
10443
  declare type W = number | 'majority';
10519
- declare type WithHelp<T> = { [prop in keyof T]: T[prop] & {
10520
- help?: () => Help;
10521
- } };
10522
10444
 
10523
10445
  /** Add an _id field to an object shaped type @public */
10524
10446
  declare type WithId<TSchema> = EnhancedOmit<TSchema, '_id'> & {