-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11488 from Uzlopak/chore-extract-and-refactor-agg…
…regationcursor-and-querycursor chore: extract and refactor aggregationcursor and querycursor
- Loading branch information
Showing
4 changed files
with
60 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import stream = require('stream'); | ||
|
||
declare module 'mongoose' { | ||
type CursorFlag = 'tailable' | 'oplogReplay' | 'noCursorTimeout' | 'awaitData' | 'partial'; | ||
|
||
class Cursor<DocType = any, Options = never> extends stream.Readable { | ||
[Symbol.asyncIterator](): AsyncIterableIterator<DocType>; | ||
|
||
/** | ||
* Adds a [cursor flag](http://mongodb.github.io/node-mongodb-native/2.2/api/Cursor.html#addCursorFlag). | ||
* Useful for setting the `noCursorTimeout` and `tailable` flags. | ||
*/ | ||
addCursorFlag(flag: CursorFlag, value: boolean): this; | ||
|
||
/** | ||
* Marks this cursor as closed. Will stop streaming and subsequent calls to | ||
* `next()` will error. | ||
*/ | ||
close(callback: CallbackWithoutResult): void; | ||
close(): Promise<void>; | ||
|
||
/** | ||
* Execute `fn` for every document(s) in the cursor. If batchSize is provided | ||
* `fn` will be executed for each batch of documents. If `fn` returns a promise, | ||
* will wait for the promise to resolve before iterating on to the next one. | ||
* Returns a promise that resolves when done. | ||
*/ | ||
eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }, callback: CallbackWithoutResult): void; | ||
eachAsync(fn: (doc: DocType) => any, options: { parallel?: number }, callback: CallbackWithoutResult): void; | ||
eachAsync(fn: (doc: DocType[]) => any, options: { parallel?: number, batchSize: number }): Promise<void>; | ||
eachAsync(fn: (doc: DocType) => any, options?: { parallel?: number }): Promise<void>; | ||
|
||
/** | ||
* Registers a transform function which subsequently maps documents retrieved | ||
* via the streams interface or `.next()` | ||
*/ | ||
map<ResultType>(fn: (res: DocType) => ResultType): Cursor<ResultType, Options>; | ||
|
||
/** | ||
* Get the next document from this cursor. Will return `null` when there are | ||
* no documents left. | ||
*/ | ||
next(callback: Callback<DocType | null>): void; | ||
next(): Promise<DocType>; | ||
|
||
options: Options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters