@@ -106,7 +106,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
106
106
*
107
107
* @returns The namespace of the collection that's being iterated over.
108
108
*/
109
- get namespace ( ) : string {
109
+ public get namespace ( ) : string {
110
110
return this . _namespace ;
111
111
}
112
112
@@ -115,7 +115,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
115
115
*
116
116
* @returns Whether or not the cursor is closed.
117
117
*/
118
- get closed ( ) : boolean {
118
+ public get closed ( ) : boolean {
119
119
return this . _state === CursorStatus . Closed ;
120
120
}
121
121
@@ -124,7 +124,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
124
124
*
125
125
* @returns The number of documents in the buffer.
126
126
*/
127
- bufferedCount ( ) : number {
127
+ public bufferedCount ( ) : number {
128
128
return this . _buffer . length ;
129
129
}
130
130
@@ -140,7 +140,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
140
140
*
141
141
* @returns The cursor.
142
142
*/
143
- filter ( filter : Filter < TRaw > ) : FindCursor < T , TRaw > {
143
+ public filter ( filter : Filter < TRaw > ) : FindCursor < T , TRaw > {
144
144
this . _assertUninitialized ( ) ;
145
145
this . _filter = filter as any ;
146
146
return this ;
@@ -158,7 +158,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
158
158
*
159
159
* @returns The cursor.
160
160
*/
161
- sort ( sort : Sort ) : FindCursor < T , TRaw > {
161
+ public sort ( sort : Sort ) : FindCursor < T , TRaw > {
162
162
this . _assertUninitialized ( ) ;
163
163
this . _options . sort = normalizeSort ( sort ) ;
164
164
return this ;
@@ -175,7 +175,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
175
175
*
176
176
* @returns The cursor.
177
177
*/
178
- limit ( limit : number ) : FindCursor < T , TRaw > {
178
+ public limit ( limit : number ) : FindCursor < T , TRaw > {
179
179
this . _assertUninitialized ( ) ;
180
180
this . _options . limit = limit || Infinity ;
181
181
return this ;
@@ -190,7 +190,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
190
190
*
191
191
* @returns The cursor.
192
192
*/
193
- skip ( skip : number ) : FindCursor < T , TRaw > {
193
+ public skip ( skip : number ) : FindCursor < T , TRaw > {
194
194
this . _assertUninitialized ( ) ;
195
195
this . _options . skip = skip ;
196
196
return this ;
@@ -232,7 +232,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
232
232
*
233
233
* @returns The cursor.
234
234
*/
235
- project < R = any , RRaw extends SomeDoc = SomeDoc > ( projection : Projection ) : FindCursor < R , RRaw > {
235
+ public project < R = any , RRaw extends SomeDoc = SomeDoc > ( projection : Projection ) : FindCursor < R , RRaw > {
236
236
this . _assertUninitialized ( ) ;
237
237
this . _options . projection = projection ;
238
238
return this as any ;
@@ -247,7 +247,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
247
247
*
248
248
* @returns The cursor.
249
249
*/
250
- includeSimilarity ( includeSimilarity : boolean = true ) : FindCursor < T , TRaw > {
250
+ public includeSimilarity ( includeSimilarity : boolean = true ) : FindCursor < T , TRaw > {
251
251
this . _assertUninitialized ( ) ;
252
252
this . _options . includeSimilarity = includeSimilarity ;
253
253
return this ;
@@ -265,7 +265,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
265
265
*
266
266
* @returns The cursor.
267
267
*/
268
- map < R > ( mapping : ( doc : T ) => R ) : FindCursor < R , TRaw > {
268
+ public map < R > ( mapping : ( doc : T ) => R ) : FindCursor < R , TRaw > {
269
269
this . _assertUninitialized ( ) ;
270
270
271
271
if ( this . _mapping ) {
@@ -291,7 +291,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
291
291
*
292
292
* @returns A behavioral clone of this cursor.
293
293
*/
294
- clone ( ) : FindCursor < TRaw , TRaw > {
294
+ public clone ( ) : FindCursor < TRaw , TRaw > {
295
295
return new FindCursor < TRaw , TRaw > ( this . _namespace , this . _httpClient , this . _filter , this . _options ) ;
296
296
}
297
297
@@ -304,7 +304,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
304
304
*
305
305
* @returns The documents read from the buffer.
306
306
*/
307
- readBufferedDocuments ( max ?: number ) : TRaw [ ] {
307
+ public readBufferedDocuments ( max ?: number ) : TRaw [ ] {
308
308
const toRead = Math . min ( max ?? this . _buffer . length , this . _buffer . length ) ;
309
309
return this . _buffer . splice ( 0 , toRead ) ;
310
310
}
@@ -314,7 +314,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
314
314
* cursor will remain, but iteration will start from the beginning, sending new queries to the server, even if the
315
315
* resultant data was already fetched by this cursor.
316
316
*/
317
- rewind ( ) : void {
317
+ public rewind ( ) : void {
318
318
this . _buffer . length = 0 ;
319
319
this . _nextPageState = undefined ;
320
320
this . _state = CursorStatus . Uninitialized ;
@@ -327,7 +327,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
327
327
*
328
328
* @returns The next document, or `null` if there are no more documents.
329
329
*/
330
- async next ( ) : Promise < T | null > {
330
+ public async next ( ) : Promise < T | null > {
331
331
return this . _next ( false ) ;
332
332
}
333
333
@@ -338,7 +338,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
338
338
*
339
339
* @returns Whether or not there is a next document.
340
340
*/
341
- async hasNext ( ) : Promise < boolean > {
341
+ public async hasNext ( ) : Promise < boolean > {
342
342
if ( this . _buffer . length > 0 ) {
343
343
return true ;
344
344
}
@@ -370,7 +370,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
370
370
* }
371
371
* ```
372
372
*/
373
- async * [ Symbol . asyncIterator ] ( ) : AsyncGenerator < T , void , void > {
373
+ public async * [ Symbol . asyncIterator ] ( ) : AsyncGenerator < T , void , void > {
374
374
try {
375
375
while ( true ) {
376
376
const doc = await this . next ( ) ;
@@ -382,7 +382,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
382
382
yield doc ;
383
383
}
384
384
} finally {
385
- await this . close ( ) ;
385
+ this . close ( ) ;
386
386
}
387
387
}
388
388
@@ -404,7 +404,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
404
404
*
405
405
* @deprecated - Prefer the `for await (const doc of cursor) { ... }` syntax instead.
406
406
*/
407
- async forEach ( consumer : ( doc : T ) => boolean | void ) : Promise < void > {
407
+ public async forEach ( consumer : ( doc : T ) => boolean | void ) : Promise < void > {
408
408
for await ( const doc of this ) {
409
409
if ( consumer ( doc ) === false ) {
410
410
break ;
@@ -423,7 +423,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
423
423
*
424
424
* @returns An array of all documents in the cursor.
425
425
*/
426
- async toArray ( ) : Promise < T [ ] > {
426
+ public async toArray ( ) : Promise < T [ ] > {
427
427
const docs : T [ ] = [ ] ;
428
428
for await ( const doc of this ) {
429
429
docs . push ( doc ) ;
@@ -434,8 +434,9 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
434
434
/**
435
435
* Closes the cursor. The cursor will be unusable after this method is called, or until {@link FindCursor.rewind} is called.
436
436
*/
437
- async close ( ) : Promise < void > {
437
+ public close ( ) : void {
438
438
this . _state = CursorStatus . Closed ;
439
+ this . _buffer = [ ] ;
439
440
}
440
441
441
442
private _assertUninitialized ( ) : void {
@@ -460,7 +461,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
460
461
? this . _mapping ( doc )
461
462
: doc ;
462
463
} catch ( err ) {
463
- await this . close ( ) ;
464
+ this . close ( ) ;
464
465
throw err ;
465
466
}
466
467
}
@@ -472,7 +473,7 @@ export class FindCursor<T, TRaw extends SomeDoc = SomeDoc> {
472
473
try {
473
474
await this . _getMore ( ) ;
474
475
} catch ( err ) {
475
- await this . close ( ) ;
476
+ this . close ( ) ;
476
477
throw err ;
477
478
}
478
479
} while ( this . _buffer . length !== 0 ) ;
0 commit comments