Skip to content

Commit 14abcb2

Browse files
committed
docs: fix fmt, export enum
1 parent f0243cb commit 14abcb2

File tree

9 files changed

+45
-52
lines changed

9 files changed

+45
-52
lines changed

src/collection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class Collection<TSchema extends Document = Document> {
262262
this.s.collectionHint = normalizeHintField(v);
263263
}
264264

265-
get timeoutMS(): number | undefined {
265+
public get timeoutMS(): number | undefined {
266266
return this.s.options.timeoutMS;
267267
}
268268

src/cursor/abstract_cursor.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,8 @@ export interface CursorStreamOptions {
6161
/** @public */
6262
export type CursorFlag = (typeof CURSOR_FLAGS)[number];
6363

64-
/** @public */
65-
export const CursorTimeoutMode = Object.freeze({
66-
ITERATION: 'iteration',
67-
LIFETIME: 'cursorLifetime'
68-
} as const);
69-
70-
/** @public
64+
/**
65+
* @public
7166
* Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
7267
* When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
7368
* `cursor.next()`.
@@ -85,7 +80,7 @@ export const CursorTimeoutMode = Object.freeze({
8580
* for await (const doc of cursor) {
8681
* // process doc
8782
* // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
88-
* will continue to iterate successfully otherwise, regardless of the number of batches.
83+
* // will continue to iterate successfully otherwise, regardless of the number of batches.
8984
* }
9085
* ```
9186
*
@@ -96,6 +91,12 @@ export const CursorTimeoutMode = Object.freeze({
9691
* const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
9792
* ```
9893
*/
94+
export const CursorTimeoutMode = Object.freeze({
95+
ITERATION: 'iteration',
96+
LIFETIME: 'cursorLifetime'
97+
} as const);
98+
99+
/** @public */
99100
export type CursorTimeoutMode = (typeof CursorTimeoutMode)[keyof typeof CursorTimeoutMode];
100101

101102
/** @public */
@@ -154,21 +155,19 @@ export interface AbstractCursorOptions extends BSONSerializeOptions {
154155
* it has the potential to hang on an operation for the entirety of `timeoutMS`.
155156
*
156157
* @example
157-
* # Example showing use of `'iteration'`
158158
* ```ts
159159
* const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
160160
* for await (const doc of cursor) {
161161
* // process doc
162162
* // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
163-
* will continue to iterate successfully otherwise, regardless of the number of batches.
163+
* // will continue to iterate successfully otherwise, regardless of the number of batches.
164164
* }
165165
* ```
166166
*
167-
* # Example showing use of `'cursorLifetime'`
168-
*
167+
* @example
169168
* ```ts
170169
* const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
171-
* const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
170+
* const docs = await cursor.toArray(); // This line will throw a timeout error if all batches are not fetched and returned within 1000ms.
172171
* ```
173172
*/
174173
timeoutMode?: CursorTimeoutMode;

src/cursor/run_command_cursor.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ import {
1919
export type RunCursorCommandOptions = {
2020
readPreference?: ReadPreferenceLike;
2121
session?: ClientSession;
22-
/** Specifies the time an operation will run until it throws a timeout error. Note that if
22+
/**
23+
* Specifies the time an operation will run until it throws a timeout error. Note that if
2324
* `maxTimeMS` is provided in the command in addition to setting `timeoutMS` in the options, then
24-
* the original value of `maxTimeMS` will be overwritten. */
25+
* the original value of `maxTimeMS` will be overwritten.
26+
*/
2527
timeoutMS?: number;
26-
/** @public
28+
/**
29+
* @public
2730
* Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
2831
* When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
2932
* `cursor.next()`.
@@ -35,7 +38,6 @@ export type RunCursorCommandOptions = {
3538
* definition can have an arbitrarily long lifetime.
3639
*
3740
* @example
38-
* # Example showing use of `'iteration'`
3941
* ```ts
4042
* const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
4143
* for await (const doc of cursor) {
@@ -45,8 +47,7 @@ export type RunCursorCommandOptions = {
4547
* }
4648
* ```
4749
*
48-
* # Example showing use of `'cursorLifetime'`
49-
*
50+
* @example
5051
* ```ts
5152
* const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
5253
* const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.

src/gridfs/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export interface GridFSBucketOptions extends WriteConcernOptions {
3838
chunkSizeBytes?: number;
3939
/** Read preference to be passed to read operations */
4040
readPreference?: ReadPreference;
41-
/** Specifies the lifetime duration of a gridFS stream. If any async operations are in progress
42-
* when this timeout expires, the stream will throw a timeout error. */
41+
/**
42+
* Specifies the lifetime duration of a gridFS stream. If any async operations are in progress
43+
* when this timeout expires, the stream will throw a timeout error.
44+
*/
4345
timeoutMS?: number;
4446
}
4547

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export {
3737
Timestamp,
3838
UUID
3939
} from './bson';
40-
export { AnyBulkWriteOperation, BulkWriteOptions, MongoBulkWriteError } from './bulk/common';
40+
export {
41+
type AnyBulkWriteOperation,
42+
type BulkWriteOptions,
43+
MongoBulkWriteError
44+
} from './bulk/common';
4145
export { ClientEncryption } from './client-side-encryption/client_encryption';
4246
export { ChangeStreamCursor } from './cursor/change_stream_cursor';
4347
export {
@@ -111,7 +115,7 @@ export { AutoEncryptionLoggerLevel } from './client-side-encryption/auto_encrypt
111115
export { GSSAPICanonicalizationValue } from './cmap/auth/gssapi';
112116
export { AuthMechanism } from './cmap/auth/providers';
113117
export { Compressor } from './cmap/wire_protocol/compression';
114-
export { CURSOR_FLAGS, type CursorTimeoutMode } from './cursor/abstract_cursor';
118+
export { CURSOR_FLAGS, CursorTimeoutMode } from './cursor/abstract_cursor';
115119
export { MongoErrorLabel } from './error';
116120
export { ExplainVerbosity } from './explain';
117121
export { ServerApiVersion } from './mongo_client';

src/operations/operation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ export abstract class AbstractOperation<TResult = any> {
6161

6262
options: OperationOptions;
6363

64-
/** @internal TODO(NODE-6197): remove dead code */
64+
/** TODO(NODE-6197): remove dead code */
6565
timeout?: Timeout;
66-
/** Specifies the time an operation will run until it throws a timeout error.*/
66+
/** Specifies the time an operation will run until it throws a timeout error. */
6767
timeoutMS?: number;
6868

6969
[kSession]: ClientSession | undefined;

src/sessions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ export class ClientSession
711711
* undefined behaviour.
712712
*
713713
* **IMPORTANT:** When running an operation inside a `withTransaction` callback, if it is not
714-
* provided the explicit session in its options, it will not respect the timeoutMS.
714+
* provided the explicit session in its options, it will not be part of the transaction and it will not respect timeoutMS.
715715
*
716716
*
717717
* @remarks

test/integration/client-side-operations-timeout/node_csot.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
type CommandStartedEvent,
1919
type CommandSucceededEvent,
2020
Connection,
21+
CursorTimeoutMode,
2122
type Db,
2223
type FindCursor,
2324
GridFSBucket,
@@ -423,7 +424,7 @@ describe('CSOT driver tests', metadata, () => {
423424
const cursor = client
424425
.db('db')
425426
.collection('coll')
426-
.find({}, { batchSize: 3, timeoutMode: 'iteration', timeoutMS: 10 })
427+
.find({}, { batchSize: 3, timeoutMode: CursorTimeoutMode.ITERATION, timeoutMS: 10 })
427428
.limit(3);
428429

429430
const maybeError = await cursor.next().then(

test/unit/index.test.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ import { expect } from 'chai';
55
import * as mongodb from '../../src/index';
66
import { setDifference } from '../mongodb';
77

8-
/**
9-
* TS-NODE Adds these keys but they are undefined, they are not present when you import from lib
10-
* We did not think this strangeness was worth investigating so we just make sure they remain set to undefined
11-
*/
12-
const TS_NODE_EXPORTS = ['AnyBulkWriteOperation', 'BulkWriteOptions'];
13-
148
const EXPECTED_EXPORTS = [
15-
...TS_NODE_EXPORTS,
169
'AbstractCursor',
1710
'Admin',
1811
'AggregationCursor',
@@ -31,11 +24,11 @@ const EXPECTED_EXPORTS = [
3124
'ClientSession',
3225
'Code',
3326
'Collection',
34-
'configureExplicitResourceManagement',
3527
'CommandFailedEvent',
3628
'CommandStartedEvent',
3729
'CommandSucceededEvent',
3830
'Compressor',
31+
'configureExplicitResourceManagement',
3932
'ConnectionCheckedInEvent',
4033
'ConnectionCheckedOutEvent',
4134
'ConnectionCheckOutFailedEvent',
@@ -49,12 +42,13 @@ const EXPECTED_EXPORTS = [
4942
'ConnectionPoolReadyEvent',
5043
'ConnectionReadyEvent',
5144
'CURSOR_FLAGS',
45+
'CursorTimeoutMode',
5246
'Db',
5347
'DBRef',
5448
'Decimal128',
5549
'Double',
56-
'ExplainVerbosity',
5750
'ExplainableCursor',
51+
'ExplainVerbosity',
5852
'FindCursor',
5953
'GridFSBucket',
6054
'GridFSBucketReadStream',
@@ -102,6 +96,7 @@ const EXPECTED_EXPORTS = [
10296
'MongoNetworkTimeoutError',
10397
'MongoNotConnectedError',
10498
'MongoOIDCError',
99+
'MongoOperationTimeoutError',
105100
'MongoParseError',
106101
'MongoRuntimeError',
107102
'MongoServerClosedError',
@@ -111,10 +106,8 @@ const EXPECTED_EXPORTS = [
111106
'MongoTailableCursorError',
112107
'MongoTopologyClosedError',
113108
'MongoTransactionError',
114-
'MongoOperationTimeoutError',
115109
'MongoUnexpectedServerResponseError',
116110
'MongoWriteConcernError',
117-
'WriteConcernErrorResult',
118111
'ObjectId',
119112
'OrderedBulkOperation',
120113
'ProfilingLevel',
@@ -130,6 +123,10 @@ const EXPECTED_EXPORTS = [
130123
'ServerHeartbeatStartedEvent',
131124
'ServerHeartbeatSucceededEvent',
132125
'ServerOpeningEvent',
126+
'ServerSelectionEvent',
127+
'ServerSelectionFailedEvent',
128+
'ServerSelectionStartedEvent',
129+
'ServerSelectionSucceededEvent',
133130
'ServerType',
134131
'SrvPollingEvent',
135132
'Timestamp',
@@ -139,12 +136,9 @@ const EXPECTED_EXPORTS = [
139136
'TopologyType',
140137
'UnorderedBulkOperation',
141138
'UUID',
139+
'WaitingForSuitableServerEvent',
142140
'WriteConcern',
143-
'ServerSelectionEvent',
144-
'ServerSelectionFailedEvent',
145-
'ServerSelectionStartedEvent',
146-
'ServerSelectionSucceededEvent',
147-
'WaitingForSuitableServerEvent'
141+
'WriteConcernErrorResult'
148142
];
149143

150144
describe('mongodb entrypoint', () => {
@@ -155,12 +149,4 @@ describe('mongodb entrypoint', () => {
155149
it('exports only the expected keys', () => {
156150
expect(setDifference(Object.keys(mongodb), EXPECTED_EXPORTS)).to.be.empty;
157151
});
158-
159-
it('should export keys added by ts-node as undefined', () => {
160-
// If the array is empty, this test would be a no-op so we should remove it
161-
expect(TS_NODE_EXPORTS).to.have.length.greaterThan(0);
162-
for (const tsNodeExportKey of TS_NODE_EXPORTS) {
163-
expect(mongodb).to.have.property(tsNodeExportKey, undefined);
164-
}
165-
});
166152
});

0 commit comments

Comments
 (0)