@@ -11,7 +11,7 @@ import type { Hint } from '../operations/operation';
11
11
import type { ClientSession } from '../sessions' ;
12
12
import { formatSort , type Sort , type SortDirection } from '../sort' ;
13
13
import { emitWarningOnce , mergeOptions , type MongoDBNamespace , squashError } from '../utils' ;
14
- import { AbstractCursor , assertUninitialized } from './abstract_cursor' ;
14
+ import { AbstractCursor } from './abstract_cursor' ;
15
15
16
16
/** @internal */
17
17
const kFilter = Symbol ( 'filter' ) ;
@@ -163,7 +163,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
163
163
164
164
/** Set the cursor query */
165
165
filter ( filter : Document ) : this {
166
- assertUninitialized ( this ) ;
166
+ this . throwIfInitialized ( ) ;
167
167
this [ kFilter ] = filter ;
168
168
return this ;
169
169
}
@@ -174,7 +174,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
174
174
* @param hint - If specified, then the query system will only consider plans using the hinted index.
175
175
*/
176
176
hint ( hint : Hint ) : this {
177
- assertUninitialized ( this ) ;
177
+ this . throwIfInitialized ( ) ;
178
178
this [ kBuiltOptions ] . hint = hint ;
179
179
return this ;
180
180
}
@@ -185,7 +185,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
185
185
* @param min - Specify a $min value to specify the inclusive lower bound for a specific index in order to constrain the results of find(). The $min specifies the lower bound for all keys of a specific index in order.
186
186
*/
187
187
min ( min : Document ) : this {
188
- assertUninitialized ( this ) ;
188
+ this . throwIfInitialized ( ) ;
189
189
this [ kBuiltOptions ] . min = min ;
190
190
return this ;
191
191
}
@@ -196,7 +196,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
196
196
* @param max - Specify a $max value to specify the exclusive upper bound for a specific index in order to constrain the results of find(). The $max specifies the upper bound for all keys of a specific index in order.
197
197
*/
198
198
max ( max : Document ) : this {
199
- assertUninitialized ( this ) ;
199
+ this . throwIfInitialized ( ) ;
200
200
this [ kBuiltOptions ] . max = max ;
201
201
return this ;
202
202
}
@@ -209,7 +209,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
209
209
* @param value - the returnKey value.
210
210
*/
211
211
returnKey ( value : boolean ) : this {
212
- assertUninitialized ( this ) ;
212
+ this . throwIfInitialized ( ) ;
213
213
this [ kBuiltOptions ] . returnKey = value ;
214
214
return this ;
215
215
}
@@ -220,7 +220,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
220
220
* @param value - The $showDiskLoc option has now been deprecated and replaced with the showRecordId field. $showDiskLoc will still be accepted for OP_QUERY stye find.
221
221
*/
222
222
showRecordId ( value : boolean ) : this {
223
- assertUninitialized ( this ) ;
223
+ this . throwIfInitialized ( ) ;
224
224
this [ kBuiltOptions ] . showRecordId = value ;
225
225
return this ;
226
226
}
@@ -232,7 +232,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
232
232
* @param value - The modifier value.
233
233
*/
234
234
addQueryModifier ( name : string , value : string | boolean | number | Document ) : this {
235
- assertUninitialized ( this ) ;
235
+ this . throwIfInitialized ( ) ;
236
236
if ( name [ 0 ] !== '$' ) {
237
237
throw new MongoInvalidArgumentError ( `${ name } is not a valid query modifier` ) ;
238
238
}
@@ -295,7 +295,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
295
295
* @param value - The comment attached to this query.
296
296
*/
297
297
comment ( value : string ) : this {
298
- assertUninitialized ( this ) ;
298
+ this . throwIfInitialized ( ) ;
299
299
this [ kBuiltOptions ] . comment = value ;
300
300
return this ;
301
301
}
@@ -306,7 +306,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
306
306
* @param value - Number of milliseconds to wait before aborting the tailed query.
307
307
*/
308
308
maxAwaitTimeMS ( value : number ) : this {
309
- assertUninitialized ( this ) ;
309
+ this . throwIfInitialized ( ) ;
310
310
if ( typeof value !== 'number' ) {
311
311
throw new MongoInvalidArgumentError ( 'Argument for maxAwaitTimeMS must be a number' ) ;
312
312
}
@@ -321,7 +321,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
321
321
* @param value - Number of milliseconds to wait before aborting the query.
322
322
*/
323
323
override maxTimeMS ( value : number ) : this {
324
- assertUninitialized ( this ) ;
324
+ this . throwIfInitialized ( ) ;
325
325
if ( typeof value !== 'number' ) {
326
326
throw new MongoInvalidArgumentError ( 'Argument for maxTimeMS must be a number' ) ;
327
327
}
@@ -371,7 +371,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
371
371
* ```
372
372
*/
373
373
project < T extends Document = Document > ( value : Document ) : FindCursor < T > {
374
- assertUninitialized ( this ) ;
374
+ this . throwIfInitialized ( ) ;
375
375
this [ kBuiltOptions ] . projection = value ;
376
376
return this as unknown as FindCursor < T > ;
377
377
}
@@ -383,7 +383,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
383
383
* @param direction - The direction of the sorting (1 or -1).
384
384
*/
385
385
sort ( sort : Sort | string , direction ?: SortDirection ) : this {
386
- assertUninitialized ( this ) ;
386
+ this . throwIfInitialized ( ) ;
387
387
if ( this [ kBuiltOptions ] . tailable ) {
388
388
throw new MongoTailableCursorError ( 'Tailable cursor does not support sorting' ) ;
389
389
}
@@ -399,7 +399,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
399
399
* {@link https://www.mongodb.com/docs/manual/reference/command/find/#find-cmd-allowdiskuse | find command allowDiskUse documentation }
400
400
*/
401
401
allowDiskUse ( allow = true ) : this {
402
- assertUninitialized ( this ) ;
402
+ this . throwIfInitialized ( ) ;
403
403
404
404
if ( ! this [ kBuiltOptions ] . sort ) {
405
405
throw new MongoInvalidArgumentError ( 'Option "allowDiskUse" requires a sort specification' ) ;
@@ -421,7 +421,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
421
421
* @param value - The cursor collation options (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
422
422
*/
423
423
collation ( value : CollationOptions ) : this {
424
- assertUninitialized ( this ) ;
424
+ this . throwIfInitialized ( ) ;
425
425
this [ kBuiltOptions ] . collation = value ;
426
426
return this ;
427
427
}
@@ -432,7 +432,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
432
432
* @param value - The limit for the cursor query.
433
433
*/
434
434
limit ( value : number ) : this {
435
- assertUninitialized ( this ) ;
435
+ this . throwIfInitialized ( ) ;
436
436
if ( this [ kBuiltOptions ] . tailable ) {
437
437
throw new MongoTailableCursorError ( 'Tailable cursor does not support limit' ) ;
438
438
}
@@ -451,7 +451,7 @@ export class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
451
451
* @param value - The skip for the cursor query.
452
452
*/
453
453
skip ( value : number ) : this {
454
- assertUninitialized ( this ) ;
454
+ this . throwIfInitialized ( ) ;
455
455
if ( this [ kBuiltOptions ] . tailable ) {
456
456
throw new MongoTailableCursorError ( 'Tailable cursor does not support skip' ) ;
457
457
}
0 commit comments