@@ -2,24 +2,6 @@ import type { Collection as RawCollection, Db as RawDb } from 'mongodb'
22import { MongoFieldSpecifier , MongoModifier , MongoQuery , SortSpecifier } from '@sofie-automation/corelib/dist/mongo'
33import { ProtectedString } from '@sofie-automation/corelib/dist/protectedString'
44
5- export interface MongoAsyncReadOnlyCollection < DBInterface extends { _id : ProtectedString < any > } > {
6- /**
7- * Find and return multiple documents
8- * @param selector A query describing the documents to find
9- * @param options Options for the operation
10- */
11- findFetchAsync ( selector : MongoQuery < DBInterface > , options ?: FindOptions < DBInterface > ) : Promise < Array < DBInterface > >
12-
13- /**
14- * Finds the first document that matches the selector, as ordered by sort and skip options. Returns `undefined` if no matching document is found.
15- * @param selector A query describing the documents to find
16- */
17- findOneAsync (
18- selector : MongoQuery < DBInterface > | DBInterface [ '_id' ] ,
19- options ?: FindOneOptions < DBInterface >
20- ) : Promise < DBInterface | undefined >
21- }
22-
235export interface MongoReadOnlyCollection < DBInterface extends { _id : ProtectedString < any > } > {
246 /**
257 * Find the documents in a collection that match the selector.
@@ -127,13 +109,21 @@ export interface MongoLiveQueryHandle {
127109}
128110
129111// Note: This is a subset of the Meteor Mongo.Cursor type
130-
131- export interface MongoAsyncCursor < DBInterface extends { _id : ProtectedString < any > } > {
112+ export interface MongoCursor < DBInterface extends { _id : ProtectedString < any > } > {
113+ /**
114+ * Returns the number of documents that match a query.
115+ * @param applySkipLimit If set to `false`, the value returned will reflect the total number of matching documents, ignoring any value supplied for limit. (Default: true)
116+ */
117+ count ( applySkipLimit ?: boolean ) : number
132118 /**
133119 * Returns the number of documents that match a query.
134120 * @param applySkipLimit If set to `false`, the value returned will reflect the total number of matching documents, ignoring any value supplied for limit. (Default: true)
135121 */
136122 countAsync ( applySkipLimit ?: boolean ) : Promise < number >
123+ /**
124+ * Return all matching documents as an Array.
125+ */
126+ fetch ( ) : Array < DBInterface >
137127 /**
138128 * Return all matching documents as an Array.
139129 */
@@ -144,63 +134,35 @@ export interface MongoAsyncCursor<DBInterface extends { _id: ProtectedString<any
144134 * @param callback Function to call. It will be called with three arguments: the document, a 0-based index, and <em>cursor</em> itself.
145135 * @param thisArg An object which will be the value of `this` inside `callback`.
146136 */
147- forEachAsync (
148- callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => void ,
149- thisArg ?: any
150- ) : Promise < void >
137+ forEach ( callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => void , thisArg ?: any ) : void
151138 /**
152- * Map callback over all matching documents. Returns an Array.
139+ * Call `callback` once for each matching document, sequentially and
140+ * synchronously.
153141 * @param callback Function to call. It will be called with three arguments: the document, a 0-based index, and <em>cursor</em> itself.
154142 * @param thisArg An object which will be the value of `this` inside `callback`.
155143 */
156- mapAsync < M > (
157- callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => M ,
144+ forEachAsync (
145+ callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => void ,
158146 thisArg ?: any
159- ) : Promise < Array < M > >
160-
161- [ Symbol . asyncIterator ] ( ) : AsyncIterator < DBInterface , never , never >
162-
163- /**
164- * Watch a query. Receive callbacks as the result set changes.
165- * @param callbacks Functions to call to deliver the result set as it changes
166- */
167- observeAsync ( callbacks : ObserveCallbacks < DBInterface > ) : Promise < MongoLiveQueryHandle >
168- /**
169- * Watch a query. Receive callbacks as the result set changes. Only the differences between the old and new documents are passed to the callbacks.
170- * @param callbacks Functions to call to deliver the result set as it changes
171- * @param options { nonMutatingCallbacks: boolean }
172- */
173- observeChangesAsync (
174- callbacks : ObserveChangesCallbacks < DBInterface > ,
175- options ?: { nonMutatingCallbacks ?: boolean | undefined }
176- ) : Promise < MongoLiveQueryHandle >
177- }
178-
179- export interface MongoCursor < DBInterface extends { _id : ProtectedString < any > } > extends MongoAsyncCursor < DBInterface > {
180- /**
181- * Returns the number of documents that match a query.
182- * @param applySkipLimit If set to `false`, the value returned will reflect the total number of matching documents, ignoring any value supplied for limit. (Default: true)
183- */
184- count ( applySkipLimit ?: boolean ) : number
185- /**
186- * Return all matching documents as an Array.
187- */
188- fetch ( ) : Array < DBInterface >
147+ ) : Promise < void >
189148 /**
190- * Call `callback` once for each matching document, sequentially and
191- * synchronously.
149+ * Map callback over all matching documents. Returns an Array.
192150 * @param callback Function to call. It will be called with three arguments: the document, a 0-based index, and <em>cursor</em> itself.
193151 * @param thisArg An object which will be the value of `this` inside `callback`.
194152 */
195- forEach ( callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => void , thisArg ?: any ) : void
153+ map < M > ( callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => M , thisArg ?: any ) : Array < M >
196154 /**
197155 * Map callback over all matching documents. Returns an Array.
198156 * @param callback Function to call. It will be called with three arguments: the document, a 0-based index, and <em>cursor</em> itself.
199157 * @param thisArg An object which will be the value of `this` inside `callback`.
200158 */
201- map < M > ( callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => M , thisArg ?: any ) : Array < M >
159+ mapAsync < M > (
160+ callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => M ,
161+ thisArg ?: any
162+ ) : Promise < Array < M > >
202163
203164 [ Symbol . iterator ] ( ) : Iterator < DBInterface , never , never >
165+ [ Symbol . asyncIterator ] ( ) : AsyncIterator < DBInterface , never , never >
204166
205167 /**
206168 * Watch a query. Receive callbacks as the result set changes.
0 commit comments