9
9
*/
10
10
package org .scalajs .dom
11
11
12
+ import scala .annotation .nowarn
13
+ import scala .language .implicitConversions
12
14
import scala .scalajs .js
13
15
import scala .scalajs .js .annotation ._
16
+ import scala .scalajs .js .typedarray ._
14
17
import scala .scalajs .js .|
15
18
19
+ /** number, date, string, binary, or array.
20
+ *
21
+ * Array objects, where every item is defined, is itself a valid key, and does not directly or indirectly contain itself. This includes empty arrays. Arrays can contain other arrays.
22
+ *
23
+ * https://w3c.github.io/IndexedDB/#key
24
+ * https://github.com/web-platform-tests/wpt/blob/master/IndexedDB/idb-binary-key-roundtrip.htm
25
+ */
26
+ @ js.native
27
+ sealed trait IDBKey extends js.Any
28
+
29
+ @ nowarn(" cat=unused" )
30
+ object IDBKey {
31
+
32
+ type Flat = Double | js.Date | String | ArrayBuffer | ArrayBufferView | BigInt64Array | BigUint64Array | DataView | Float32Array | Float64Array | Int16Array | Int32Array | Int8Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray
33
+
34
+ sealed trait IsKey [- A ]
35
+ object IsKey {
36
+ @ inline implicit def flat [A ](implicit e : | .Evidence [A , Flat ]): IsKey [A ] = null
37
+ @ inline implicit def array [A ](implicit e : IsKey [A ]): IsKey [js.Array [A ]] = null
38
+ @ inline implicit def coproduct [A , B ](implicit a : IsKey [A ], b : IsKey [B ]): IsKey [A | B ] = null
39
+ }
40
+
41
+ @ inline implicit def from [A : IsKey ](a : A ): IDBKey =
42
+ a.asInstanceOf [IDBKey ]
43
+
44
+ @ inline implicit def undef [A : IsKey ](a : A ): js.UndefOr [IDBKey ] =
45
+ a.asInstanceOf [js.UndefOr [IDBKey ]]
46
+
47
+ @ inline implicit def undefOrLeft [A : IsKey , B ](a : A ): js.UndefOr [IDBKey | B ] =
48
+ a.asInstanceOf [js.UndefOr [IDBKey | B ]]
49
+ }
50
+
16
51
/**
17
52
* IndexedDB transaction mode
18
53
* Provides constants for IDB Transaction modes
@@ -85,7 +120,7 @@ class IDBObjectStore extends js.Object {
85
120
*/
86
121
def keyPath : String = js.native
87
122
88
- def count (key : js. Any = js.native): IDBRequest = js.native
123
+ def count (key : IDBKey = js.native): IDBRequest = js.native
89
124
90
125
/**
91
126
* To determine if the add operation has completed successfully, listen for the
@@ -96,7 +131,7 @@ class IDBObjectStore extends js.Object {
96
131
*
97
132
* MDN
98
133
*/
99
- def add (value : js.Any , key : js. Any = js.native): IDBRequest = js.native
134
+ def add (value : js.Any , key : IDBKey = js.native): IDBRequest = js.native
100
135
101
136
/**
102
137
* Clearing an object store consists of removing all records from the object store and
@@ -122,15 +157,15 @@ class IDBObjectStore extends js.Object {
122
157
*
123
158
* MDN
124
159
*/
125
- def put (value : js.Any , key : js. Any = js.native): IDBRequest = js.native
160
+ def put (value : js.Any , key : IDBKey = js.native): IDBRequest = js.native
126
161
127
162
/**
128
163
* The method sets the position of the cursor to the appropriate record,
129
164
* based on the specified direction.
130
165
*
131
166
* MDN
132
167
*/
133
- def openCursor (range : js.UndefOr [IDBKeyRange | js. Any ] = js.undefined,
168
+ def openCursor (range : js.UndefOr [IDBKey | IDBKeyRange ] = js.undefined,
134
169
direction : js.UndefOr [
135
170
IDBCursorDirection ] = js.undefined): IDBRequest = js.native
136
171
@@ -140,7 +175,7 @@ class IDBObjectStore extends js.Object {
140
175
*
141
176
* MDN
142
177
*/
143
- def openKeyCursor (range : js.UndefOr [IDBKeyRange | js. Any ] = js.undefined,
178
+ def openKeyCursor (range : js.UndefOr [IDBKey | IDBKeyRange ] = js.undefined,
144
179
direction : js.UndefOr [
145
180
IDBCursorDirection ] = js.undefined): IDBRequest = js.native
146
181
@@ -166,15 +201,15 @@ class IDBObjectStore extends js.Object {
166
201
*
167
202
* MDN
168
203
*/
169
- def get (key : js. Any ): IDBRequest = js.native
204
+ def get (key : IDBKey ): IDBRequest = js.native
170
205
171
206
/**
172
207
* If a value is successfully found, then a structured clone of it is created and set as
173
208
* the result of the request object.
174
209
*
175
210
* MDN
176
211
*/
177
- def getAll (query : js.UndefOr [IDBKeyRange | js. Any ] = js.undefined,
212
+ def getAll (query : js.UndefOr [IDBKey | IDBKeyRange ] = js.undefined,
178
213
count : js.UndefOr [Int ] = js.undefined): IDBRequest = js.native
179
214
180
215
/**
@@ -183,7 +218,7 @@ class IDBObjectStore extends js.Object {
183
218
*
184
219
* MDN
185
220
*/
186
- def getAllKeys (query : js.UndefOr [IDBKeyRange | js. Any ] = js.undefined,
221
+ def getAllKeys (query : js.UndefOr [IDBKey | IDBKeyRange ] = js.undefined,
187
222
count : js.UndefOr [Int ] = js.undefined): IDBRequest = js.native
188
223
189
224
/**
@@ -192,15 +227,15 @@ class IDBObjectStore extends js.Object {
192
227
*
193
228
* MDN
194
229
*/
195
- def getKey (key : js. Any ): IDBRequest = js.native
230
+ def getKey (key : IDBKey ): IDBRequest = js.native
196
231
197
232
/**
198
233
* returns an IDBRequest object, and, in a separate thread, deletes the current
199
234
* object store.
200
235
*
201
236
* MDN
202
237
*/
203
- def delete (key : js. Any ): IDBRequest = js.native
238
+ def delete (key : IDBKey ): IDBRequest = js.native
204
239
}
205
240
206
241
trait IDBVersionChangeEventInit extends EventInit {
@@ -286,7 +321,7 @@ class IDBIndex extends js.Object {
286
321
*/
287
322
def objectStore : IDBObjectStore = js.native
288
323
289
- def count (key : js. Any ): IDBRequest = js.native
324
+ def count (key : IDBKey ): IDBRequest = js.native
290
325
291
326
/**
292
327
* If you want to see how many records are between keys 1000 and 2000 in an object store,
@@ -302,7 +337,7 @@ class IDBIndex extends js.Object {
302
337
*
303
338
* MDN
304
339
*/
305
- def getKey (key : js. Any ): IDBRequest = js.native
340
+ def getKey (key : IDBKey ): IDBRequest = js.native
306
341
307
342
/**
308
343
* Returns an IDBRequest object, and, in a separate thread, creates a cursor over the
@@ -320,7 +355,7 @@ class IDBIndex extends js.Object {
320
355
*
321
356
* MDN
322
357
*/
323
- def get (key : js. Any ): IDBRequest = js.native
358
+ def get (key : IDBKey ): IDBRequest = js.native
324
359
325
360
/**
326
361
* The method sets the position of the cursor to the appropriate record, based on the
@@ -371,7 +406,7 @@ class IDBCursor extends js.Object {
371
406
*
372
407
* MDN
373
408
*/
374
- def key : js. Any = js.native
409
+ def key : IDBKey = js.native
375
410
376
411
/**
377
412
* Returns the cursor's current effective key. If the cursor is currently being
@@ -397,7 +432,7 @@ class IDBCursor extends js.Object {
397
432
*
398
433
* W3C
399
434
*/
400
- def continue (key : js. Any = ??? ): Unit = js.native
435
+ def continue (key : IDBKey = ??? ): Unit = js.native
401
436
402
437
/**
403
438
* Returns an IDBRequest object, and, in a separate thread, deletes the record at the
0 commit comments