1- import type { Collection as RawCollection } from 'mongodb'
2- import {
3- MongoFieldSpecifier ,
4- MongoModifier ,
5- MongoQuery ,
6- SortSpecifier ,
7- ObserveCallbacks ,
8- ObserveChangesCallbacks ,
9- } from '@sofie-automation/corelib/dist/mongo'
10- import { ProtectedString } from '@sofie-automation/corelib/dist/protectedString'
11-
12- export interface MongoReadOnlyCollection < DBInterface extends { _id : ProtectedString < any > } > {
13- /**
14- * Find the documents in a collection that match the selector.
15- * @param selector A query describing the documents to find
16- */
17- find (
18- selector ?: MongoQuery < DBInterface > | DBInterface [ '_id' ] ,
19- options ?: FindOptions < DBInterface >
20- ) : MongoCursor < DBInterface >
21-
22- /**
23- * Finds the first document that matches the selector, as ordered by sort and skip options. Returns `undefined` if no matching document is found.
24- * @param selector A query describing the documents to find
25- */
26- findOne (
27- selector ?: MongoQuery < DBInterface > | DBInterface [ '_id' ] ,
28- options ?: FindOneOptions < DBInterface >
29- ) : DBInterface | undefined
30- }
31- /**
32- * A minimal MongoCollection type based on the Meteor Mongo.Collection type, but with our improved _id type safety.
33- * Note: when updating method signatures, make sure to update the implementions as new properties may not be fed through without additional work
34- */
35- export interface MongoCollection <
36- DBInterface extends { _id : ProtectedString < any > } ,
37- > extends MongoReadOnlyCollection < DBInterface > {
38- /**
39- * Insert a document in the collection. Returns its unique _id.
40- * @param doc The document to insert. May not yet have an _id attribute, in which case Meteor will generate one for you.
41- */
42- insert ( doc : DBInterface ) : DBInterface [ '_id' ]
43-
44- /**
45- * Returns the [`Collection`](http://mongodb.github.io/node-mongodb-native/3.0/api/Collection.html) object corresponding to this collection from the
46- * [npm `mongodb` driver module](https://www.npmjs.com/package/mongodb) which is wrapped by `Mongo.Collection`.
47- */
48- rawCollection ( ) : RawCollection < DBInterface >
49-
50- /**
51- * Remove documents from the collection
52- * @param selector Specifies which documents to remove
53- */
54- remove ( selector : MongoQuery < DBInterface > | DBInterface [ '_id' ] ) : number
55-
56- /**
57- * Modify one or more documents in the collection. Returns the number of matched documents.
58- * @param selector Specifies which documents to modify
59- * @param modifier Specifies how to modify the documents
60- */
61- update (
62- selector : DBInterface [ '_id' ] | { _id : DBInterface [ '_id' ] } ,
63- modifier : MongoModifier < DBInterface > ,
64- options ?: UpdateOptions
65- ) : number
66- update (
67- selector : MongoQuery < DBInterface > ,
68- modifier : MongoModifier < DBInterface > ,
69- // Require { multi } to be set when selecting multiple documents to be updated, otherwise only the first found document will be updated
70- options : UpdateOptions & Required < Pick < UpdateOptions , 'multi' > >
71- ) : number
72-
73- /**
74- * Modify one or more documents in the collection, or insert one if no matching documents were found. Returns an object with keys `numberAffected` (the number of documents modified) and
75- * `insertedId` (the unique _id of the document that was inserted, if any).
76- * @param selector Specifies which documents to modify
77- * @param modifier Specifies how to modify the documents
78- */
79- upsert (
80- selector : MongoQuery < DBInterface > | DBInterface [ '_id' ] ,
81- modifier : MongoModifier < DBInterface > ,
82- options ?: UpsertOptions
83- ) : {
84- numberAffected ?: number
85- insertedId ?: DBInterface [ '_id' ]
86- }
87- }
1+ import { MongoFieldSpecifier , SortSpecifier } from '@sofie-automation/corelib/dist/mongo'
882
893export interface UpdateOptions {
904 /** True to modify all matching documents; false to only modify one of the matching documents (the default). */
@@ -110,88 +24,6 @@ export interface MongoLiveQueryHandle {
11024 stop ( ) : void
11125}
11226
113- // Note: This is a subset of the Meteor Mongo.Cursor type
114- export interface MongoCursor < DBInterface extends { _id : ProtectedString < any > } > {
115- /**
116- * Returns the number of documents that match a query.
117- * @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)
118- */
119- count ( applySkipLimit ?: boolean ) : number
120- /**
121- * Returns the number of documents that match a query.
122- * @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)
123- */
124- countAsync ( applySkipLimit ?: boolean ) : Promise < number >
125- /**
126- * Return all matching documents as an Array.
127- */
128- fetch ( ) : Array < DBInterface >
129- /**
130- * Return all matching documents as an Array.
131- */
132- fetchAsync ( ) : Promise < Array < DBInterface > >
133- /**
134- * Call `callback` once for each matching document, sequentially and
135- * synchronously.
136- * @param callback Function to call. It will be called with three arguments: the document, a 0-based index, and <em>cursor</em> itself.
137- * @param thisArg An object which will be the value of `this` inside `callback`.
138- */
139- forEach ( callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => void , thisArg ?: any ) : void
140- /**
141- * Call `callback` once for each matching document, sequentially and
142- * synchronously.
143- * @param callback Function to call. It will be called with three arguments: the document, a 0-based index, and <em>cursor</em> itself.
144- * @param thisArg An object which will be the value of `this` inside `callback`.
145- */
146- forEachAsync (
147- callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => void ,
148- thisArg ?: any
149- ) : Promise < void >
150- /**
151- * Map callback over all matching documents. Returns an Array.
152- * @param callback Function to call. It will be called with three arguments: the document, a 0-based index, and <em>cursor</em> itself.
153- * @param thisArg An object which will be the value of `this` inside `callback`.
154- */
155- map < M > ( callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => M , thisArg ?: any ) : Array < M >
156- /**
157- * Map callback over all matching documents. Returns an Array.
158- * @param callback Function to call. It will be called with three arguments: the document, a 0-based index, and <em>cursor</em> itself.
159- * @param thisArg An object which will be the value of `this` inside `callback`.
160- */
161- mapAsync < M > (
162- callback : ( doc : DBInterface , index : number , cursor : MongoCursor < DBInterface > ) => M ,
163- thisArg ?: any
164- ) : Promise < Array < M > >
165-
166- [ Symbol . iterator ] ( ) : Iterator < DBInterface , never , never >
167- [ Symbol . asyncIterator ] ( ) : AsyncIterator < DBInterface , never , never >
168-
169- /**
170- * Watch a query. Receive callbacks as the result set changes.
171- * @param callbacks Functions to call to deliver the result set as it changes
172- */
173- observe ( callbacks : ObserveCallbacks < DBInterface > ) : MongoLiveQueryHandle
174- /**
175- * Watch a query. Receive callbacks as the result set changes.
176- * @param callbacks Functions to call to deliver the result set as it changes
177- */
178- observeAsync ( callbacks : ObserveCallbacks < DBInterface > ) : Promise < MongoLiveQueryHandle >
179- /**
180- * Watch a query. Receive callbacks as the result set changes. Only the differences between the old and new documents are passed to the callbacks.
181- * @param callbacks Functions to call to deliver the result set as it changes
182- */
183- observeChanges ( callbacks : ObserveChangesCallbacks < DBInterface > ) : MongoLiveQueryHandle
184- /**
185- * Watch a query. Receive callbacks as the result set changes. Only the differences between the old and new documents are passed to the callbacks.
186- * @param callbacks Functions to call to deliver the result set as it changes
187- * @param options { nonMutatingCallbacks: boolean }
188- */
189- observeChangesAsync (
190- callbacks : ObserveChangesCallbacks < DBInterface > ,
191- options ?: { nonMutatingCallbacks ?: boolean | undefined }
192- ) : Promise < MongoLiveQueryHandle >
193- }
194-
19527export interface FindOneOptions < TRawDoc > {
19628 /** Sort order (default: natural order) */
19729 sort ?: SortSpecifier < TRawDoc >
0 commit comments