Skip to content

Commit 69e69a0

Browse files
committed
mongodb fixes and enhancements
1 parent 59ab96e commit 69e69a0

File tree

2 files changed

+24
-60
lines changed

2 files changed

+24
-60
lines changed

node_libs/mongodb/src/main/scala/org/scalajs/nodejs/mongodb/Cursor.scala

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package org.scalajs.nodejs.mongodb
22

3-
import org.scalajs.nodejs.mongodb.Cursor.CursorFlag
43
import org.scalajs.nodejs
4+
import org.scalajs.nodejs.mongodb.Cursor.CursorFlag
55

66
import scala.scalajs.js
7+
import scala.scalajs.js.|
78

89
/**
910
* Cursor
@@ -27,13 +28,6 @@ trait Cursor extends nodejs.stream.Readable {
2728
*/
2829
def addQueryModifier(name: String, value: js.Any): this.type = js.native
2930

30-
/**
31-
* Sets the batch size parameter of this cursor to the given value.
32-
* @param batchSize the new batch size.
33-
* @example batchSize(batchSize[, callback])
34-
*/
35-
def batchSize(batchSize: Int): this.type = js.native
36-
3731
/**
3832
* Sets the batch size parameter of this cursor to the given value.
3933
* @param batchSize the new batch size.
@@ -43,7 +37,7 @@ trait Cursor extends nodejs.stream.Readable {
4337
* execution.
4438
* @example batchSize(batchSize[, callback])
4539
*/
46-
def batchSize(batchSize: Int, callback: js.Function): this.type = js.native
40+
def batchSize(batchSize: Int, callback: js.Function = js.native): this.type = js.native
4741

4842
/**
4943
* Clone the cursor
@@ -110,26 +104,14 @@ trait Cursor extends nodejs.stream.Readable {
110104
* Set the cursor hint
111105
* @param hint If specified, then the query system will only consider plans using the hinted index.
112106
*/
113-
def hint(hint: String): this.type = js.native
114-
115-
/**
116-
* Set the cursor hint
117-
*/
118-
def hint(): this.type = js.native
107+
def hint(hint: String = js.native): this.type = js.native
119108

120109
/**
121110
* Check if the cursor is closed or open.
122111
* @return the state of the cursor.
123112
*/
124113
def isClosed(): Boolean = js.native
125114

126-
/**
127-
* Sets the limit parameter of this cursor to the given value.
128-
* @param limit the new limit.
129-
* @example limit(limit[, callback])
130-
*/
131-
def limit(limit: Int): this.type = js.native
132-
133115
/**
134116
* Sets the limit parameter of this cursor to the given value.
135117
* @param limit the new limit.
@@ -138,7 +120,7 @@ trait Cursor extends nodejs.stream.Readable {
138120
* closed while the second parameter will contain a reference to this object upon successful execution.
139121
* @example limit(limit[, callback])
140122
*/
141-
def limit(limit: Int, callback: js.Function): this.type = js.native
123+
def limit(limit: Int, callback: js.Function = js.native): this.type = js.native
142124

143125
/**
144126
* Map all documents using the provided function
@@ -176,15 +158,7 @@ trait Cursor extends nodejs.stream.Readable {
176158
* successful execution.
177159
* @example maxTimeMS(maxTimeMS[, callback])
178160
*/
179-
def maxTimeMS(maxTimeMS: Int, callback: js.Function): this.type = js.native
180-
181-
/**
182-
* Specifies a time limit for a query operation. After the specified time is exceeded, the operation will be
183-
* aborted and an error will be returned to the client. If maxTimeMS is null, no limit is applied.
184-
* @param maxTimeMS the maxTimeMS for the query.
185-
* @example maxTimeMS(maxTimeMS[, callback])
186-
*/
187-
def maxTimeMS(maxTimeMS: Int): this.type = js.native
161+
def maxTimeMS(maxTimeMS: Int, callback: js.Function = js.native): this.type = js.native
188162

189163
/**
190164
* Set the cursor min
@@ -241,14 +215,6 @@ trait Cursor extends nodejs.stream.Readable {
241215
*/
242216
def rewind(): this.type = js.native
243217

244-
/**
245-
* Sets the read preference for the cursor
246-
* @param pref read preference for the cursor, one of [[ServerClass.READ_PRIMARY Server.READ_PRIMARY]],
247-
* [[ServerClass.READ_SECONDARY Server.READ_SECONDARY]], [[ServerClass.READ_SECONDARY Server.READ_SECONDARY_ONLY]]
248-
* @example setReadPreference(pref[, callback])
249-
*/
250-
def setReadPreference(pref: String): this.type = js.native
251-
252218
/**
253219
* Sets the read preference for the cursor
254220
* @param pref read preference for the cursor, one of [[ServerClass.READ_PRIMARY Server.READ_PRIMARY]],
@@ -259,7 +225,7 @@ trait Cursor extends nodejs.stream.Readable {
259225
* successful execution.
260226
* @example setReadPreference(pref[, callback])
261227
*/
262-
def setReadPreference(pref: String, callback: js.Function): this.type = js.native
228+
def setReadPreference(pref: String, callback: js.Function = js.native): this.type = js.native
263229

264230
/**
265231
* Set the cursor showRecordId
@@ -276,14 +242,7 @@ trait Cursor extends nodejs.stream.Readable {
276242
* while the second parameter will contain a reference to this object upon successful execution.
277243
* @example skip(skip[, callback])
278244
*/
279-
def skip(skip: Int, callback: js.Function): this.type = js.native
280-
281-
/**
282-
* Sets the skip parameter of this cursor to the given value.
283-
* @param skip the new skip value.
284-
* @example skip(skip[, callback])
285-
*/
286-
def skip(skip: Int): this.type = js.native
245+
def skip(skip: Int, callback: js.Function = js.native): this.type = js.native
287246

288247
/**
289248
* Sets the sort parameter of this cursor to the given value.
@@ -298,30 +257,25 @@ trait Cursor extends nodejs.stream.Readable {
298257
* to this object upon successful execution.
299258
* @example sort(keyOrList, direction, callback)
300259
*/
301-
def sort(keyOrList: js.Array[js.Any], direction: Int, callback: js.Function): this.type = js.native
260+
def sort(keyOrList: js.Any, direction: Int | String, callback: js.Function): this.type = js.native
302261

303262
/**
304263
* Sets the sort parameter of this cursor to the given value.
305264
* @param keyOrList this can be a string or an array. If passed as a string, the string will be the field to sort.
306265
* If passed an array, each element will represent a field to be sorted and should be an array that
307266
* contains the format [string, direction].
308-
* @param direction this determines how the results are sorted. "asc", "ascending" or 1 for
309-
* ascending order while "desc", "desceding or -1 for descending order.
310-
* <b>Note</b> that the strings are case insensitive.
311267
* @param callback this will be called after executing this method. The first parameter will contain an error
312268
* object when the cursor is already closed while the second parameter will contain a reference
313269
* to this object upon successful execution.
314-
* @example sort(keyOrList, direction, callback)
270+
* @example sort(keyOrList, callback)
315271
*/
316-
def sort(keyOrList: js.Array[js.Any], direction: String, callback: js.Function): this.type = js.native
272+
def sort(keyOrList: js.Any, callback: js.Function = js.native): this.type = js.native
317273

318274
/**
319-
* Sets the sort parameter of this cursor to the given value.
320-
* @param keyOrList this can be a string or an array. If passed as a string, the string will be the field to sort.
321-
* @example sort(keyOrList, direction, callback)
275+
* TODO document me
276+
* @param enable
277+
* @return
322278
*/
323-
def sort(keyOrList: js.Array[js.Any]): this.type = js.native
324-
325279
def snapshot(enable: Boolean): this.type = js.native
326280

327281
/**

node_libs/mongodb/src/main/scala/org/scalajs/nodejs/mongodb/package.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@ package object mongodb {
314314

315315
}
316316

317+
/**
318+
* Mongo Projection Enrichment
319+
* @param fields the given array of fields
320+
*/
321+
implicit class ProjectionEnrichment(val fields: js.Array[String]) extends AnyVal {
322+
323+
def toProjection = js.Dictionary(fields.map(_ -> 1): _*)
324+
325+
}
326+
317327
/**
318328
* Text Search Options
319329

0 commit comments

Comments
 (0)