Skip to content

Commit 63b9889

Browse files
committed
start API docs
1 parent 17649e1 commit 63b9889

File tree

8 files changed

+54
-17
lines changed

8 files changed

+54
-17
lines changed

src/collection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface CollectionOptions extends BSONSerializeOptions, WriteConcernOpt
115115
readConcern?: ReadConcernLike;
116116
/** The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). */
117117
readPreference?: ReadPreferenceLike;
118-
/** @internal TODO(NODE-5688): make this public */
118+
/** Specifies the time an operation will run until it throws a timeout error */
119119
timeoutMS?: number;
120120
}
121121

@@ -262,7 +262,6 @@ export class Collection<TSchema extends Document = Document> {
262262
this.s.collectionHint = normalizeHintField(v);
263263
}
264264

265-
/** @internal */
266265
get timeoutMS(): number | undefined {
267266
return this.s.options.timeoutMS;
268267
}

src/cursor/abstract_cursor.ts

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

64-
/** @public*/
64+
/** @public */
6565
export const CursorTimeoutMode = Object.freeze({
6666
ITERATION: 'iteration',
6767
LIFETIME: 'cursorLifetime'
6868
} as const);
6969

7070
/** @public
71-
* TODO(NODE-5688): Document and release
72-
* */
71+
* Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
72+
* When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
73+
* `cursor.next()`.
74+
* When set to `'cursorLifetime'`, the deadline applies to the life of the entire cursor.
75+
*
76+
* @example
77+
* # Example showing use of `'iteration'`
78+
* ```ts
79+
* const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
80+
* for await (const doc of cursor) {
81+
* // process doc
82+
* // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
83+
* will continue to iterate successfully otherwise, regardless of the number of batches.
84+
* }
85+
* ```
86+
*
87+
* # Example showing use of `'cursorLifetime'`
88+
*
89+
* ```ts
90+
* const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
91+
* const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
92+
* ```
93+
*/
7394
export type CursorTimeoutMode = (typeof CursorTimeoutMode)[keyof typeof CursorTimeoutMode];
7495

7596
/** @public */
@@ -115,9 +136,32 @@ export interface AbstractCursorOptions extends BSONSerializeOptions {
115136
*/
116137
awaitData?: boolean;
117138
noCursorTimeout?: boolean;
118-
/** @internal TODO(NODE-5688): make this public */
139+
/** Specifies the time an operation will run until it throws a timeout error. See {@link AbstractCursorOptions.timeoutMode} for more details. */
119140
timeoutMS?: number;
120-
/** @internal TODO(NODE-5688): make this public */
141+
/**
142+
* Specifies how `timeoutMS` is applied to the cursor. Can be either `'cursorLifeTime'` or `'iteration'`
143+
* When set to `'iteration'`, the deadline specified by `timeoutMS` applies to each call of
144+
* `cursor.next()`.
145+
* When set to `'cursorLifetime'`, the deadline applies to the life of the entire cursor.
146+
*
147+
* @example
148+
* # Example showing use of `'iteration'`
149+
* ```ts
150+
* const cursor = collection.find({}, {timeoutMS: 100, timeoutMode: 'iteration'});
151+
* for await (const doc of cursor) {
152+
* // process doc
153+
* // This will throw a timeout error if any of the iterator's `next()` calls takes more than 100ms, but
154+
* will continue to iterate successfully otherwise, regardless of the number of batches.
155+
* }
156+
* ```
157+
*
158+
* # Example showing use of `'cursorLifetime'`
159+
*
160+
* ```ts
161+
* const cursor = collection.find({}, { timeoutMS: 1000, timeoutMode: 'cursorLifetime' });
162+
* const docs = await cursor.toArray(); // This entire line will throw a timeout error if all batches are not fetched and returned within 1000ms.
163+
* ```
164+
*/
121165
timeoutMode?: CursorTimeoutMode;
122166

123167
/**

src/db.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export interface DbOptions extends BSONSerializeOptions, WriteConcernOptions {
9797
readConcern?: ReadConcern;
9898
/** Should retry failed writes */
9999
retryWrites?: boolean;
100-
/** @internal TODO(NODE-5688): make this public */
100+
/** Specifies the time an operation will run until it throws a timeout error */
101101
timeoutMS?: number;
102102
}
103103

@@ -222,7 +222,6 @@ export class Db {
222222
return this.s.namespace.toString();
223223
}
224224

225-
/** @internal */
226225
get timeoutMS(): number | undefined {
227226
return this.s.options?.timeoutMS;
228227
}

src/error.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,6 @@ export class MongoUnexpectedServerResponseError extends MongoRuntimeError {
865865
* @category Error
866866
*
867867
* This error is thrown when an operation could not be completed within the specified `timeoutMS`.
868-
* TODO(NODE-5688): expand this documentation.
869868
*
870869
* @example
871870
* ```ts

src/gridfs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface GridFSBucketOptions extends WriteConcernOptions {
3838
chunkSizeBytes?: number;
3939
/** Read preference to be passed to read operations */
4040
readPreference?: ReadPreference;
41-
/** @internal TODO(NODE-5688): make this public */
41+
/** Specifies the time an operation will run until it throws a timeout error */
4242
timeoutMS?: number;
4343
}
4444

src/mongo_client.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export type SupportedNodeConnectionOptions = SupportedTLSConnectionOptions &
130130
export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeConnectionOptions {
131131
/** Specifies the name of the replica set, if the mongod is a member of a replica set. */
132132
replicaSet?: string;
133-
/** @internal TODO(NODE-5688): This option is in development and currently has no behaviour. */
133+
/** Specifies the time an operation will run until it throws a timeout error */
134134
timeoutMS?: number;
135135
/** Enables or disables TLS/SSL for the connection. */
136136
tls?: boolean;
@@ -482,7 +482,6 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
482482
return this.s.bsonOptions;
483483
}
484484

485-
/** @internal */
486485
get timeoutMS(): number | undefined {
487486
return this.options.timeoutMS;
488487
}
@@ -971,6 +970,5 @@ export interface MongoOptions
971970
* TODO: NODE-5671 - remove internal flag
972971
*/
973972
mongodbLogPath?: 'stderr' | 'stdout' | MongoDBLogWritable;
974-
/** @internal TODO(NODE-5688): make this public */
975973
timeoutMS?: number;
976974
}

src/operations/indexes.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,6 @@ export class DropIndexOperation extends CommandOperation<Document> {
361361

362362
/** @public */
363363
export type ListIndexesOptions = AbstractCursorOptions & {
364-
/** @internal TODO(NODE-5688): make this public */
365-
timeoutMode?: CursorTimeoutMode;
366364
/** @internal */
367365
omitMaxTimeMS?: boolean;
368366
};

src/operations/operation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface OperationOptions extends BSONSerializeOptions {
3535
/** @internal Hint to `executeOperation` to omit maxTimeMS */
3636
omitMaxTimeMS?: boolean;
3737

38-
/** @internal TODO(NODE-5688): make this public */
38+
/** Specifies the time an operation will run until it throws a timeout error */
3939
timeoutMS?: number;
4040
}
4141

0 commit comments

Comments
 (0)