From 1a6fc9cb64b137ac611eb56ee6eefaab22bd0c94 Mon Sep 17 00:00:00 2001 From: David Barri Date: Mon, 6 Sep 2021 16:16:18 +1000 Subject: [PATCH 1/8] Improve precision of IDB API and add tests --- api-reports/2_12.txt | 122 ++++++++----- api-reports/2_13.txt | 122 ++++++++----- src/main/scala/org/scalajs/dom/IDBTypes.scala | 170 +++++++++++++----- src/main/scala/org/scalajs/dom/idb.scala | 10 +- src/main/scala/org/scalajs/dom/raw.scala | 4 +- .../dom/tests/shared/AsyncTesting.scala | 7 + .../scalajs/dom/tests/shared/IdbTest.scala | 82 +++++++++ .../dom/tests/shared/SharedTests.scala | 24 +-- .../scalajs/dom/tests/webworker/Server.scala | 9 +- .../dom/tests/webworker/WebWorkerTests.scala | 20 ++- 10 files changed, 414 insertions(+), 156 deletions(-) create mode 100644 tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 4120f3b14..cd81b0a10 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -13530,32 +13530,43 @@ HttpMethod[SO] val PATCH: HttpMethod HttpMethod[SO] val POST: HttpMethod HttpMethod[SO] val PUT: HttpMethod HttpMethod[SO] val QUERY: HttpMethod +IDBCreateIndexOptions[JT] val locale: js.UndefOr[String] +IDBCreateIndexOptions[JT] val multiEntry: js.UndefOr[Boolean] +IDBCreateIndexOptions[JT] val unique: js.UndefOr[Boolean] +IDBCreateObjectStoreOptions[JT] val autoIncrement: js.UndefOr[Boolean] +IDBCreateObjectStoreOptions[JT] val keyPath: Any IDBCursor[JC] def advance(count: Int): Unit -IDBCursor[JC] def continue(key: js.Any?): Unit -IDBCursor[JC] def delete(): IDBRequest +IDBCursor[JC] def continue(key: Any?): Unit +IDBCursor[JC] def delete(): IDBRequest[Unit] IDBCursor[JC] def direction: IDBCursorDirection -IDBCursor[JC] def key: js.Any +IDBCursor[JC] def key: Any IDBCursor[JC] def primaryKey: js.Any IDBCursor[JC] def source: js.Any -IDBCursor[JC] def update(value: js.Any): IDBRequest +IDBCursor[JC] def update(value: js.Any): IDBRequest[Any] IDBCursorDirection[JT] IDBCursorDirection[SO] val NEXT: IDBCursorDirection IDBCursorDirection[SO] val NEXT_UNIQUE: IDBCursorDirection IDBCursorDirection[SO] val PREV: IDBCursorDirection IDBCursorDirection[SO] val PREV_UNIQUE: IDBCursorDirection +IDBCursorReadOnly[JC] def advance(count: Int): Unit +IDBCursorReadOnly[JC] def continue(key: Any?): Unit +IDBCursorReadOnly[JC] def direction: IDBCursorDirection +IDBCursorReadOnly[JC] def key: Any +IDBCursorReadOnly[JC] def primaryKey: js.Any +IDBCursorReadOnly[JC] def source: js.Any IDBCursorWithValue[JC] def advance(count: Int): Unit -IDBCursorWithValue[JC] def continue(key: js.Any?): Unit -IDBCursorWithValue[JC] def delete(): IDBRequest +IDBCursorWithValue[JC] def continue(key: Any?): Unit +IDBCursorWithValue[JC] def delete(): IDBRequest[Unit] IDBCursorWithValue[JC] def direction: IDBCursorDirection -IDBCursorWithValue[JC] def key: js.Any +IDBCursorWithValue[JC] def key: Any IDBCursorWithValue[JC] def primaryKey: js.Any IDBCursorWithValue[JC] def source: js.Any -IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest +IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest[Any] IDBCursorWithValue[JC] def value: js.Any IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBDatabase[JC] def close(): Unit -IDBDatabase[JC] def createObjectStore(name: String, optionalParameters: js.Any?): IDBObjectStore +IDBDatabase[JC] def createObjectStore(name: String, optionalParameters: js.UndefOr[IDBCreateObjectStoreOptions]?): IDBObjectStore IDBDatabase[JC] def deleteObjectStore(name: String): Unit IDBDatabase[JC] def dispatchEvent(evt: Event): Boolean IDBDatabase[JC] def name: String @@ -13567,20 +13578,42 @@ IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBDatabase[JC] def transaction(storeNames: js.Any, mode: IDBTransactionMode?): IDBTransaction IDBDatabase[JC] def version: Int +IDBDatabaseInfo[JT] val name: String +IDBDatabaseInfo[JT] val version: Int IDBEnvironment[JT] def indexedDB: IDBFactory (@deprecated in 1.2.0) +IDBEvent[JC] def bubbles: Boolean +IDBEvent[JC] def cancelBubble: Boolean +IDBEvent[JC] def cancelable: Boolean +IDBEvent[JC] def currentTarget: EventTarget +IDBEvent[JC] def defaultPrevented: Boolean +IDBEvent[JC] def eventPhase: Int +IDBEvent[JC] def isTrusted: Boolean +IDBEvent[JC] def preventDefault(): Unit +IDBEvent[JC] def stopImmediatePropagation(): Unit +IDBEvent[JC] def stopPropagation(): Unit +IDBEvent[JC] def target: EventTarget +IDBEvent[JC] override def target: IDBEventTarget[A] +IDBEvent[JC] def timeStamp: Double +IDBEvent[JC] def `type`: String +IDBEventTarget[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit +IDBEventTarget[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +IDBEventTarget[JC] def dispatchEvent(evt: Event): Boolean +IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit +IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +IDBEventTarget[JC] def result: A IDBFactory[JC] def cmp(first: js.Any, second: js.Any): Int -IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest -IDBFactory[JC] def open(name: String): IDBOpenDBRequest -IDBFactory[JC] def open(name: String, version: Int): IDBOpenDBRequest -IDBIndex[JC] def count(): IDBRequest -IDBIndex[JC] def count(key: js.Any): IDBRequest -IDBIndex[JC] def get(key: js.Any): IDBRequest -IDBIndex[JC] def getKey(key: js.Any): IDBRequest +IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] +IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] +IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] +IDBIndex[JC] def count(): IDBRequest[Double] +IDBIndex[JC] def count(key: Any): IDBRequest[Double] +IDBIndex[JC] def get(key: Any): IDBRequest[js.Any] +IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[js.Any]] IDBIndex[JC] def keyPath: String IDBIndex[JC] def name: String IDBIndex[JC] def objectStore: IDBObjectStore -IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest -IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest +IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursor] +IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursorReadOnly] IDBIndex[JC] def unique: Boolean IDBKeyRange[JC] def lower: js.Any IDBKeyRange[JC] def lowerOpen: Boolean @@ -13590,23 +13623,23 @@ IDBKeyRange[JO] def bound(lower: js.Any, upper: js.Any, lowerOpen: Boolean?, upp IDBKeyRange[JO] def lowerBound(bound: js.Any, open: Boolean?): IDBKeyRange IDBKeyRange[JO] def only(value: js.Any): IDBKeyRange IDBKeyRange[JO] def upperBound(bound: js.Any, open: Boolean?): IDBKeyRange -IDBObjectStore[JC] def add(value: js.Any, key: js.Any?): IDBRequest -IDBObjectStore[JC] def clear(): IDBRequest -IDBObjectStore[JC] def count(key: js.Any?): IDBRequest -IDBObjectStore[JC] def createIndex(name: String, keyPath: String, optionalParameters: js.Any?): IDBIndex -IDBObjectStore[JC] def delete(key: js.Any): IDBRequest +IDBObjectStore[JC] def add(value: js.Any, key: Any?): IDBRequest[Any] +IDBObjectStore[JC] def clear(): IDBRequest[Unit] +IDBObjectStore[JC] def count(key: Any?): IDBRequest[Double] +IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex +IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit -IDBObjectStore[JC] def get(key: js.Any): IDBRequest -IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | js.Any]?, count: js.UndefOr[Int]?): IDBRequest -IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | js.Any]?, count: js.UndefOr[Int]?): IDBRequest -IDBObjectStore[JC] def getKey(key: js.Any): IDBRequest +IDBObjectStore[JC] def get(key: Any): IDBRequest[js.Any] +IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[js.Any]] +IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] +IDBObjectStore[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] IDBObjectStore[JC] def index(name: String): IDBIndex IDBObjectStore[JC] def indexNames: DOMStringList IDBObjectStore[JC] def keyPath: String IDBObjectStore[JC] def name: String -IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | js.Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest -IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | js.Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest -IDBObjectStore[JC] def put(value: js.Any, key: js.Any?): IDBRequest +IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursor] +IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursorReadOnly] +IDBObjectStore[JC] def put(value: js.Any, key: Any?): IDBRequest[Any] IDBObjectStore[JC] def transaction: IDBTransaction IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13614,12 +13647,12 @@ IDBOpenDBRequest[JC] def dispatchEvent(evt: Event): Boolean IDBOpenDBRequest[JC] def error: DOMException IDBOpenDBRequest[JC] var onblocked: js.Function1[IDBVersionChangeEvent, _] IDBOpenDBRequest[JC] var onerror: js.Function1[Event, _] -IDBOpenDBRequest[JC] var onsuccess: js.Function1[Event, _] +IDBOpenDBRequest[JC] var onsuccess: js.Function1[IDBEvent[A], _] IDBOpenDBRequest[JC] var onupgradeneeded: js.Function1[IDBVersionChangeEvent, _] IDBOpenDBRequest[JC] def readyState: String IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit -IDBOpenDBRequest[JC] def result: js.Any +IDBOpenDBRequest[JC] def result: A IDBOpenDBRequest[JC] def source: js.Any IDBOpenDBRequest[JC] def transaction: IDBTransaction IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit @@ -13627,11 +13660,11 @@ IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Fun IDBRequest[JC] def dispatchEvent(evt: Event): Boolean IDBRequest[JC] def error: DOMException IDBRequest[JC] var onerror: js.Function1[Event, _] -IDBRequest[JC] var onsuccess: js.Function1[Event, _] +IDBRequest[JC] var onsuccess: js.Function1[IDBEvent[A], _] IDBRequest[JC] def readyState: String IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit -IDBRequest[JC] def result: js.Any +IDBRequest[JC] def result: A IDBRequest[JC] def source: js.Any IDBRequest[JC] def transaction: IDBTransaction IDBTransaction[JC] def abort(): Unit @@ -13648,9 +13681,9 @@ IDBTransaction[JC] var onerror: js.Function1[Event, _] IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBTransactionMode[JT] -IDBTransactionMode[SO] val READ_ONLY: IDBTransactionMode -IDBTransactionMode[SO] val READ_WRITE: IDBTransactionMode -IDBTransactionMode[SO] val VERSION_CHANGE: IDBTransactionMode +IDBTransactionMode[SO] val readonly: IDBTransactionMode +IDBTransactionMode[SO] val readwrite: IDBTransactionMode +IDBTransactionMode[SO] val versionchange: IDBTransactionMode IDBVersionChangeEvent[JC] def bubbles: Boolean IDBVersionChangeEvent[JC] def cancelBubble: Boolean IDBVersionChangeEvent[JC] def cancelable: Boolean @@ -13664,6 +13697,7 @@ IDBVersionChangeEvent[JC] def preventDefault(): Unit IDBVersionChangeEvent[JC] def stopImmediatePropagation(): Unit IDBVersionChangeEvent[JC] def stopPropagation(): Unit IDBVersionChangeEvent[JC] def target: EventTarget +IDBVersionChangeEvent[JC] override def target: IDBEventTarget[A] IDBVersionChangeEvent[JC] def timeStamp: Double IDBVersionChangeEvent[JC] def `type`: String IDBVersionChangeEventInit[JT] var bubbles: js.UndefOr[Boolean] @@ -25561,16 +25595,22 @@ html[SO] type UList = HTMLUListElement html[SO] type Unknown = HTMLUnknownElement html[SO] type Video = HTMLVideoElement html[SO] def Media = HTMLMediaElement +idb[SO] type CreateIndexOptions = IDBCreateIndexOptions +idb[SO] type CreateObjectStoreOptions = IDBCreateObjectStoreOptions idb[SO] type Cursor = IDBCursor +idb[SO] type CursorReadOnly = IDBCursorReadOnly idb[SO] type CursorWithValue = IDBCursorWithValue idb[SO] type Database = IDBDatabase +idb[SO] type DatabaseInfo = IDBDatabaseInfo idb[SO] type Environment = IDBEnvironment (@deprecated in 1.2.0) +idb[SO] type EventTarget[+A] = IDBEventTarget[A] +idb[SO] type Event[+A] = IDBEvent[A] idb[SO] type Factory = IDBFactory idb[SO] type Index = IDBIndex idb[SO] type KeyRange = IDBKeyRange idb[SO] type ObjectStore = IDBObjectStore -idb[SO] type OpenDBRequest = IDBOpenDBRequest -idb[SO] type Request = IDBRequest +idb[SO] type OpenDBRequest[A] = IDBOpenDBRequest[A] +idb[SO] type Request[A] = IDBRequest[A] idb[SO] type Transaction = IDBTransaction idb[SO] type VersionChangeEvent = IDBVersionChangeEvent idb[SO] def CursorDirection = IDBCursorDirection @@ -25744,8 +25784,8 @@ raw[SO] type IDBFactory = dom.IDBFactory (@deprecated in 2.0.0) raw[SO] type IDBIndex = dom.IDBIndex (@deprecated in 2.0.0) raw[SO] type IDBKeyRange = dom.IDBKeyRange (@deprecated in 2.0.0) raw[SO] type IDBObjectStore = dom.IDBObjectStore (@deprecated in 2.0.0) -raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest (@deprecated in 2.0.0) -raw[SO] type IDBRequest = dom.IDBRequest (@deprecated in 2.0.0) +raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest[js.Any] (@deprecated in 2.0.0) +raw[SO] type IDBRequest = dom.IDBRequest[js.Any] (@deprecated in 2.0.0) raw[SO] type IDBTransaction = dom.IDBTransaction (@deprecated in 2.0.0) raw[SO] type IDBVersionChangeEvent = dom.IDBVersionChangeEvent (@deprecated in 2.0.0) raw[SO] type ImageBitmap = dom.ImageBitmap (@deprecated in 2.0.0) diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 4120f3b14..cd81b0a10 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -13530,32 +13530,43 @@ HttpMethod[SO] val PATCH: HttpMethod HttpMethod[SO] val POST: HttpMethod HttpMethod[SO] val PUT: HttpMethod HttpMethod[SO] val QUERY: HttpMethod +IDBCreateIndexOptions[JT] val locale: js.UndefOr[String] +IDBCreateIndexOptions[JT] val multiEntry: js.UndefOr[Boolean] +IDBCreateIndexOptions[JT] val unique: js.UndefOr[Boolean] +IDBCreateObjectStoreOptions[JT] val autoIncrement: js.UndefOr[Boolean] +IDBCreateObjectStoreOptions[JT] val keyPath: Any IDBCursor[JC] def advance(count: Int): Unit -IDBCursor[JC] def continue(key: js.Any?): Unit -IDBCursor[JC] def delete(): IDBRequest +IDBCursor[JC] def continue(key: Any?): Unit +IDBCursor[JC] def delete(): IDBRequest[Unit] IDBCursor[JC] def direction: IDBCursorDirection -IDBCursor[JC] def key: js.Any +IDBCursor[JC] def key: Any IDBCursor[JC] def primaryKey: js.Any IDBCursor[JC] def source: js.Any -IDBCursor[JC] def update(value: js.Any): IDBRequest +IDBCursor[JC] def update(value: js.Any): IDBRequest[Any] IDBCursorDirection[JT] IDBCursorDirection[SO] val NEXT: IDBCursorDirection IDBCursorDirection[SO] val NEXT_UNIQUE: IDBCursorDirection IDBCursorDirection[SO] val PREV: IDBCursorDirection IDBCursorDirection[SO] val PREV_UNIQUE: IDBCursorDirection +IDBCursorReadOnly[JC] def advance(count: Int): Unit +IDBCursorReadOnly[JC] def continue(key: Any?): Unit +IDBCursorReadOnly[JC] def direction: IDBCursorDirection +IDBCursorReadOnly[JC] def key: Any +IDBCursorReadOnly[JC] def primaryKey: js.Any +IDBCursorReadOnly[JC] def source: js.Any IDBCursorWithValue[JC] def advance(count: Int): Unit -IDBCursorWithValue[JC] def continue(key: js.Any?): Unit -IDBCursorWithValue[JC] def delete(): IDBRequest +IDBCursorWithValue[JC] def continue(key: Any?): Unit +IDBCursorWithValue[JC] def delete(): IDBRequest[Unit] IDBCursorWithValue[JC] def direction: IDBCursorDirection -IDBCursorWithValue[JC] def key: js.Any +IDBCursorWithValue[JC] def key: Any IDBCursorWithValue[JC] def primaryKey: js.Any IDBCursorWithValue[JC] def source: js.Any -IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest +IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest[Any] IDBCursorWithValue[JC] def value: js.Any IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBDatabase[JC] def close(): Unit -IDBDatabase[JC] def createObjectStore(name: String, optionalParameters: js.Any?): IDBObjectStore +IDBDatabase[JC] def createObjectStore(name: String, optionalParameters: js.UndefOr[IDBCreateObjectStoreOptions]?): IDBObjectStore IDBDatabase[JC] def deleteObjectStore(name: String): Unit IDBDatabase[JC] def dispatchEvent(evt: Event): Boolean IDBDatabase[JC] def name: String @@ -13567,20 +13578,42 @@ IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBDatabase[JC] def transaction(storeNames: js.Any, mode: IDBTransactionMode?): IDBTransaction IDBDatabase[JC] def version: Int +IDBDatabaseInfo[JT] val name: String +IDBDatabaseInfo[JT] val version: Int IDBEnvironment[JT] def indexedDB: IDBFactory (@deprecated in 1.2.0) +IDBEvent[JC] def bubbles: Boolean +IDBEvent[JC] def cancelBubble: Boolean +IDBEvent[JC] def cancelable: Boolean +IDBEvent[JC] def currentTarget: EventTarget +IDBEvent[JC] def defaultPrevented: Boolean +IDBEvent[JC] def eventPhase: Int +IDBEvent[JC] def isTrusted: Boolean +IDBEvent[JC] def preventDefault(): Unit +IDBEvent[JC] def stopImmediatePropagation(): Unit +IDBEvent[JC] def stopPropagation(): Unit +IDBEvent[JC] def target: EventTarget +IDBEvent[JC] override def target: IDBEventTarget[A] +IDBEvent[JC] def timeStamp: Double +IDBEvent[JC] def `type`: String +IDBEventTarget[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit +IDBEventTarget[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +IDBEventTarget[JC] def dispatchEvent(evt: Event): Boolean +IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit +IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +IDBEventTarget[JC] def result: A IDBFactory[JC] def cmp(first: js.Any, second: js.Any): Int -IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest -IDBFactory[JC] def open(name: String): IDBOpenDBRequest -IDBFactory[JC] def open(name: String, version: Int): IDBOpenDBRequest -IDBIndex[JC] def count(): IDBRequest -IDBIndex[JC] def count(key: js.Any): IDBRequest -IDBIndex[JC] def get(key: js.Any): IDBRequest -IDBIndex[JC] def getKey(key: js.Any): IDBRequest +IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] +IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] +IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] +IDBIndex[JC] def count(): IDBRequest[Double] +IDBIndex[JC] def count(key: Any): IDBRequest[Double] +IDBIndex[JC] def get(key: Any): IDBRequest[js.Any] +IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[js.Any]] IDBIndex[JC] def keyPath: String IDBIndex[JC] def name: String IDBIndex[JC] def objectStore: IDBObjectStore -IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest -IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest +IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursor] +IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursorReadOnly] IDBIndex[JC] def unique: Boolean IDBKeyRange[JC] def lower: js.Any IDBKeyRange[JC] def lowerOpen: Boolean @@ -13590,23 +13623,23 @@ IDBKeyRange[JO] def bound(lower: js.Any, upper: js.Any, lowerOpen: Boolean?, upp IDBKeyRange[JO] def lowerBound(bound: js.Any, open: Boolean?): IDBKeyRange IDBKeyRange[JO] def only(value: js.Any): IDBKeyRange IDBKeyRange[JO] def upperBound(bound: js.Any, open: Boolean?): IDBKeyRange -IDBObjectStore[JC] def add(value: js.Any, key: js.Any?): IDBRequest -IDBObjectStore[JC] def clear(): IDBRequest -IDBObjectStore[JC] def count(key: js.Any?): IDBRequest -IDBObjectStore[JC] def createIndex(name: String, keyPath: String, optionalParameters: js.Any?): IDBIndex -IDBObjectStore[JC] def delete(key: js.Any): IDBRequest +IDBObjectStore[JC] def add(value: js.Any, key: Any?): IDBRequest[Any] +IDBObjectStore[JC] def clear(): IDBRequest[Unit] +IDBObjectStore[JC] def count(key: Any?): IDBRequest[Double] +IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex +IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit -IDBObjectStore[JC] def get(key: js.Any): IDBRequest -IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | js.Any]?, count: js.UndefOr[Int]?): IDBRequest -IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | js.Any]?, count: js.UndefOr[Int]?): IDBRequest -IDBObjectStore[JC] def getKey(key: js.Any): IDBRequest +IDBObjectStore[JC] def get(key: Any): IDBRequest[js.Any] +IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[js.Any]] +IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] +IDBObjectStore[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] IDBObjectStore[JC] def index(name: String): IDBIndex IDBObjectStore[JC] def indexNames: DOMStringList IDBObjectStore[JC] def keyPath: String IDBObjectStore[JC] def name: String -IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | js.Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest -IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | js.Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest -IDBObjectStore[JC] def put(value: js.Any, key: js.Any?): IDBRequest +IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursor] +IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursorReadOnly] +IDBObjectStore[JC] def put(value: js.Any, key: Any?): IDBRequest[Any] IDBObjectStore[JC] def transaction: IDBTransaction IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13614,12 +13647,12 @@ IDBOpenDBRequest[JC] def dispatchEvent(evt: Event): Boolean IDBOpenDBRequest[JC] def error: DOMException IDBOpenDBRequest[JC] var onblocked: js.Function1[IDBVersionChangeEvent, _] IDBOpenDBRequest[JC] var onerror: js.Function1[Event, _] -IDBOpenDBRequest[JC] var onsuccess: js.Function1[Event, _] +IDBOpenDBRequest[JC] var onsuccess: js.Function1[IDBEvent[A], _] IDBOpenDBRequest[JC] var onupgradeneeded: js.Function1[IDBVersionChangeEvent, _] IDBOpenDBRequest[JC] def readyState: String IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit -IDBOpenDBRequest[JC] def result: js.Any +IDBOpenDBRequest[JC] def result: A IDBOpenDBRequest[JC] def source: js.Any IDBOpenDBRequest[JC] def transaction: IDBTransaction IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit @@ -13627,11 +13660,11 @@ IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Fun IDBRequest[JC] def dispatchEvent(evt: Event): Boolean IDBRequest[JC] def error: DOMException IDBRequest[JC] var onerror: js.Function1[Event, _] -IDBRequest[JC] var onsuccess: js.Function1[Event, _] +IDBRequest[JC] var onsuccess: js.Function1[IDBEvent[A], _] IDBRequest[JC] def readyState: String IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit -IDBRequest[JC] def result: js.Any +IDBRequest[JC] def result: A IDBRequest[JC] def source: js.Any IDBRequest[JC] def transaction: IDBTransaction IDBTransaction[JC] def abort(): Unit @@ -13648,9 +13681,9 @@ IDBTransaction[JC] var onerror: js.Function1[Event, _] IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBTransactionMode[JT] -IDBTransactionMode[SO] val READ_ONLY: IDBTransactionMode -IDBTransactionMode[SO] val READ_WRITE: IDBTransactionMode -IDBTransactionMode[SO] val VERSION_CHANGE: IDBTransactionMode +IDBTransactionMode[SO] val readonly: IDBTransactionMode +IDBTransactionMode[SO] val readwrite: IDBTransactionMode +IDBTransactionMode[SO] val versionchange: IDBTransactionMode IDBVersionChangeEvent[JC] def bubbles: Boolean IDBVersionChangeEvent[JC] def cancelBubble: Boolean IDBVersionChangeEvent[JC] def cancelable: Boolean @@ -13664,6 +13697,7 @@ IDBVersionChangeEvent[JC] def preventDefault(): Unit IDBVersionChangeEvent[JC] def stopImmediatePropagation(): Unit IDBVersionChangeEvent[JC] def stopPropagation(): Unit IDBVersionChangeEvent[JC] def target: EventTarget +IDBVersionChangeEvent[JC] override def target: IDBEventTarget[A] IDBVersionChangeEvent[JC] def timeStamp: Double IDBVersionChangeEvent[JC] def `type`: String IDBVersionChangeEventInit[JT] var bubbles: js.UndefOr[Boolean] @@ -25561,16 +25595,22 @@ html[SO] type UList = HTMLUListElement html[SO] type Unknown = HTMLUnknownElement html[SO] type Video = HTMLVideoElement html[SO] def Media = HTMLMediaElement +idb[SO] type CreateIndexOptions = IDBCreateIndexOptions +idb[SO] type CreateObjectStoreOptions = IDBCreateObjectStoreOptions idb[SO] type Cursor = IDBCursor +idb[SO] type CursorReadOnly = IDBCursorReadOnly idb[SO] type CursorWithValue = IDBCursorWithValue idb[SO] type Database = IDBDatabase +idb[SO] type DatabaseInfo = IDBDatabaseInfo idb[SO] type Environment = IDBEnvironment (@deprecated in 1.2.0) +idb[SO] type EventTarget[+A] = IDBEventTarget[A] +idb[SO] type Event[+A] = IDBEvent[A] idb[SO] type Factory = IDBFactory idb[SO] type Index = IDBIndex idb[SO] type KeyRange = IDBKeyRange idb[SO] type ObjectStore = IDBObjectStore -idb[SO] type OpenDBRequest = IDBOpenDBRequest -idb[SO] type Request = IDBRequest +idb[SO] type OpenDBRequest[A] = IDBOpenDBRequest[A] +idb[SO] type Request[A] = IDBRequest[A] idb[SO] type Transaction = IDBTransaction idb[SO] type VersionChangeEvent = IDBVersionChangeEvent idb[SO] def CursorDirection = IDBCursorDirection @@ -25744,8 +25784,8 @@ raw[SO] type IDBFactory = dom.IDBFactory (@deprecated in 2.0.0) raw[SO] type IDBIndex = dom.IDBIndex (@deprecated in 2.0.0) raw[SO] type IDBKeyRange = dom.IDBKeyRange (@deprecated in 2.0.0) raw[SO] type IDBObjectStore = dom.IDBObjectStore (@deprecated in 2.0.0) -raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest (@deprecated in 2.0.0) -raw[SO] type IDBRequest = dom.IDBRequest (@deprecated in 2.0.0) +raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest[js.Any] (@deprecated in 2.0.0) +raw[SO] type IDBRequest = dom.IDBRequest[js.Any] (@deprecated in 2.0.0) raw[SO] type IDBTransaction = dom.IDBTransaction (@deprecated in 2.0.0) raw[SO] type IDBVersionChangeEvent = dom.IDBVersionChangeEvent (@deprecated in 2.0.0) raw[SO] type ImageBitmap = dom.ImageBitmap (@deprecated in 2.0.0) diff --git a/src/main/scala/org/scalajs/dom/IDBTypes.scala b/src/main/scala/org/scalajs/dom/IDBTypes.scala index 40c8a5b58..bff8891b8 100644 --- a/src/main/scala/org/scalajs/dom/IDBTypes.scala +++ b/src/main/scala/org/scalajs/dom/IDBTypes.scala @@ -10,6 +10,18 @@ import scala.scalajs.js import scala.scalajs.js.annotation._ import scala.scalajs.js.| +@js.native +@JSGlobal("Event") +class IDBEvent[+A](typeArg: String, init: js.UndefOr[EventInit] = js.undefined) extends Event(typeArg, init) { + override def target: IDBEventTarget[A] = js.native +} + +@js.native +@JSGlobal("EventTarget") +class IDBEventTarget[+A] extends EventTarget { + def result: A = js.native +} + /** IndexedDB transaction mode Provides constants for IDB Transaction modes These constants have been removed from * browser support and replaced by String values */ @@ -19,16 +31,16 @@ sealed trait IDBTransactionMode extends js.Any object IDBTransactionMode { /** Allows data to be read but not changed. It is the default transaction mode. */ - val READ_ONLY: IDBTransactionMode = "readonly".asInstanceOf[IDBTransactionMode] + val readonly: IDBTransactionMode = "readonly".asInstanceOf[IDBTransactionMode] /** Allows any operation to be performed, including ones that delete and create object stores and indexes. This mode * is for updating the version number of transactions that were started using the setVersion() method of IDBDatabase * objects. Transactions of this mode cannot run concurrently with other transactions. */ - val VERSION_CHANGE: IDBTransactionMode = "versionchange".asInstanceOf[IDBTransactionMode] + val versionchange: IDBTransactionMode = "versionchange".asInstanceOf[IDBTransactionMode] /** Allows reading and writing of data in existing data stores to be changed. */ - val READ_WRITE: IDBTransactionMode = "readwrite".asInstanceOf[IDBTransactionMode] + val readwrite: IDBTransactionMode = "readwrite".asInstanceOf[IDBTransactionMode] } @@ -52,36 +64,51 @@ class IDBObjectStore extends js.Object { */ def keyPath: String = js.native - def count(key: js.Any = js.native): IDBRequest = js.native + def count(key: Any = js.native): IDBRequest[Double] = js.native /** To determine if the add operation has completed successfully, listen for the transaction’s complete event in * addition to the IDBObjectStore.add request’s success event, because the transaction may still fail after the * success event fires. In other words, the success event is only triggered when the transaction has been * successfully queued. + * + * @return + * [[IDBRequest]] with the key as the `target` value */ - def add(value: js.Any, key: js.Any = js.native): IDBRequest = js.native + def add(value: js.Any, key: Any = js.native): IDBRequest[Any] = js.native /** Clearing an object store consists of removing all records from the object store and removing all records in * indexes that reference the object store. */ - def clear(): IDBRequest = js.native + def clear(): IDBRequest[Unit] = js.native /** Note that this method must be called only from a VersionChange transaction mode callback. */ - def createIndex(name: String, keyPath: String, optionalParameters: js.Any = js.native): IDBIndex = js.native + def createIndex(name: String, keyPath: Any, + optionalParameters: IDBCreateIndexOptions = js.native): IDBIndex = js.native /** If the record is successfully stored, then a success event is fired on the returned request object with the result * set to the key for the stored record, and the transaction set to the transaction in which this object store is * opened. + * + * @return + * [[IDBRequest]] with the key as the `target` value */ - def put(value: js.Any, key: js.Any = js.native): IDBRequest = js.native + def put(value: js.Any, key: Any = js.native): IDBRequest[Any] = js.native - /** The method sets the position of the cursor to the appropriate record, based on the specified direction. */ - def openCursor(range: js.UndefOr[IDBKeyRange | js.Any] = js.native, - direction: js.UndefOr[IDBCursorDirection] = js.native): IDBRequest = js.native + /** The method sets the position of the cursor to the appropriate record, based on the specified direction. + * + * @return + * [[IDBRequest]] with the `target` value being a new cursor or `null`. + */ + def openCursor(range: js.UndefOr[IDBKeyRange | Any] = js.native, + direction: js.UndefOr[IDBCursorDirection] = js.native): IDBRequest[IDBCursor] = js.native - /** The method sets the position of the cursor to the appropriate key, based on the specified direction. */ - def openKeyCursor(range: js.UndefOr[IDBKeyRange | js.Any] = js.native, - direction: js.UndefOr[IDBCursorDirection] = js.native): IDBRequest = js.native + /** The method sets the position of the cursor to the appropriate key, based on the specified direction. + * + * @return + * [[IDBRequest]] with the `target` value being a new cursor or `null`. + */ + def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any] = js.native, + direction: js.UndefOr[IDBCursorDirection] = js.native): IDBRequest[IDBCursorReadOnly] = js.native /** Note that this method must be called only from a VersionChange transaction mode callback. Note that this method * synchronously modifies the IDBObjectStore.indexNames property. @@ -94,27 +121,27 @@ class IDBObjectStore extends js.Object { /** If a value is successfully found, then a structured clone of it is created and set as the result of the request * object. */ - def get(key: js.Any): IDBRequest = js.native + def get(key: Any): IDBRequest[js.Any] = js.native /** If a value is successfully found, then a structured clone of it is created and set as the result of the request * object. */ - def getAll(query: js.UndefOr[IDBKeyRange | js.Any] = js.native, - count: js.UndefOr[Int] = js.native): IDBRequest = js.native + def getAll(query: js.UndefOr[IDBKeyRange | Any] = js.native, + count: js.UndefOr[Int] = js.native): IDBRequest[js.Array[js.Any]] = js.native /** If a value is successfully found, then a structured clone of it is created and set as the result of the request * object. */ - def getAllKeys(query: js.UndefOr[IDBKeyRange | js.Any] = js.native, - count: js.UndefOr[Int] = js.native): IDBRequest = js.native + def getAllKeys(query: js.UndefOr[IDBKeyRange | Any] = js.native, + count: js.UndefOr[Int] = js.native): IDBRequest[js.Array[Any]] = js.native /** If a value is successfully found, then a structured clone of it is created and set as the result of the request * object. */ - def getKey(key: js.Any): IDBRequest = js.native + def getKey(key: Any): IDBRequest[js.UndefOr[Any]] = js.native /** returns an IDBRequest object, and, in a separate thread, deletes the current object store. */ - def delete(key: js.Any): IDBRequest = js.native + def delete(key: Any): IDBRequest[Unit] = js.native } trait IDBVersionChangeEventInit extends EventInit { @@ -127,7 +154,8 @@ trait IDBVersionChangeEventInit extends EventInit { */ @js.native @JSGlobal -class IDBVersionChangeEvent(typeArg: String, init: js.UndefOr[IDBVersionChangeEventInit]) extends Event(typeArg, init) { +class IDBVersionChangeEvent(typeArg: String, init: js.UndefOr[IDBVersionChangeEventInit]) + extends IDBEvent[IDBDatabase](typeArg, init) { /** Returns the new version of the database. * @@ -168,30 +196,39 @@ class IDBIndex extends js.Object { /** The name of the object store referenced by this index. */ def objectStore: IDBObjectStore = js.native - def count(key: js.Any): IDBRequest = js.native + def count(key: Any): IDBRequest[Double] = js.native /** If you want to see how many records are between keys 1000 and 2000 in an object store, you can write the * following: */ - def count(): IDBRequest = js.native + def count(): IDBRequest[Double] = js.native + + /** Returns an IDBRequest object, and, in a separate thread, finds either the value in the referenced object store + * that corresponds to the given key or the first corresponding value, if key is a key range. + */ + def get(key: Any): IDBRequest[js.Any] = js.native /** Returns an IDBRequest object, and, in a separate thread, finds either the given key or the primary key, if key is * a key range. */ - def getKey(key: js.Any): IDBRequest = js.native + def getKey(key: Any): IDBRequest[js.UndefOr[js.Any]] = js.native - /** Returns an IDBRequest object, and, in a separate thread, creates a cursor over the specified key range, as - * arranged by this index. + /** The method sets the position of the cursor to the appropriate record, based on the specified direction. + * + * @return + * [[IDBRequest]] with the `target` value being a new cursor or `null`. */ - def openKeyCursor(range: IDBKeyRange = js.native, direction: IDBCursorDirection = js.native): IDBRequest = js.native + def openCursor(range: IDBKeyRange = js.native, + direction: IDBCursorDirection = js.native): IDBRequest[IDBCursor] = js.native - /** Returns an IDBRequest object, and, in a separate thread, finds either the value in the referenced object store - * that corresponds to the given key or the first corresponding value, if key is a key range. + /** Returns an IDBRequest object, and, in a separate thread, creates a cursor over the specified key range, as + * arranged by this index. + * + * @return + * [[IDBRequest]] with the `target` value being a new cursor or `null`. */ - def get(key: js.Any): IDBRequest = js.native - - /** The method sets the position of the cursor to the appropriate record, based on the specified direction. */ - def openCursor(range: IDBKeyRange = js.native, direction: IDBCursorDirection = js.native): IDBRequest = js.native + def openKeyCursor(range: IDBKeyRange = js.native, + direction: IDBCursorDirection = js.native): IDBRequest[IDBCursorReadOnly] = js.native } /** The IDBCursor interface of the IndexedDB API represents a cursor for traversing or iterating over multiple records @@ -203,7 +240,7 @@ class IDBIndex extends js.Object { */ @js.native @JSGlobal -class IDBCursor extends js.Object { +class IDBCursorReadOnly extends js.Object { /** On getting, this object returns the IDBObjectStore or IDBIndex that the cursor is iterating. This function never * returns null or throws an exception, even if the cursor is currently being iterated, has iterated past its end, or @@ -219,7 +256,7 @@ class IDBCursor extends js.Object { /** Returns the key for the record at the cursor's position. If the cursor is outside its range, this is set to * undefined. The cursor's key can be any data type. */ - def key: js.Any = js.native + def key: Any = js.native /** Returns the cursor's current effective key. If the cursor is currently being iterated or has iterated outside its * range, this is set to undefined. The cursor's primary key can be any data type. @@ -237,17 +274,29 @@ class IDBCursor extends js.Object { * * W3C */ - def continue(key: js.Any = js.native): Unit = js.native + def continue(key: Any = js.native): Unit = js.native +} + +/** The IDBCursor interface of the IndexedDB API represents a cursor for traversing or iterating over multiple records + * in a database. + * + * The cursor has a source that indicates which index or object store it is iterating. It has a position within the + * range, and moves in a direction that is increasing or decreasing in the order of record keys. The cursor enables an + * application to asynchronously process all the records in the cursor's range. + */ +@js.native +@JSGlobal +class IDBCursor extends IDBCursorReadOnly { /** Returns an IDBRequest object, and, in a separate thread, deletes the record at the cursor's position, without * changing the cursor's position. */ - def delete(): IDBRequest = js.native + def delete(): IDBRequest[Unit] = js.native /** Returns an IDBRequest object, and, in a separate thread, updates the value at the current position of the cursor * in the object store. */ - def update(value: js.Any): IDBRequest = js.native + def update(value: js.Any): IDBRequest[Any] = js.native } @js.native @@ -413,7 +462,8 @@ class IDBDatabase extends EventTarget { * important optional properties. You can use the property to uniquely identify individual objects in the store. As * the property is an identifier, it should be unique to every object, and every object should have that property. */ - def createObjectStore(name: String, optionalParameters: js.Any = js.native): IDBObjectStore = js.native + def createObjectStore(name: String, + optionalParameters: js.UndefOr[IDBCreateObjectStoreOptions] = js.native): IDBObjectStore = js.native /** The connection is not actually closed until all transactions created using this connection are complete. No new * transactions can be created for this connection once this method is called. Methods that create transactions throw @@ -438,7 +488,7 @@ class IDBDatabase extends EventTarget { */ @js.native @JSGlobal -class IDBOpenDBRequest extends IDBRequest { +class IDBOpenDBRequest[A] extends IDBRequest[A] { /** The event handler for the upgradeneeded event, fired when a database of a bigger version number than the existing * stored database is loaded. @@ -462,20 +512,29 @@ class IDBOpenDBRequest extends IDBRequest { @js.native @JSGlobal class IDBFactory extends js.Object { - def open(name: String, version: Int): IDBOpenDBRequest = js.native /** The open() method of the IDBFactory interface requests opening a connection to a database. see * [[https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory/open IDBFactory.open() on MDN]] * * w3c spec [[http://www.w3.org/TR/IndexedDB/#requests ¶3.2.3 Opening a database]] */ - def open(name: String): IDBOpenDBRequest = js.native + def open(name: String, version: Int = js.native): IDBOpenDBRequest[IDBDatabase] = js.native /** A method that compares two keys and returns a result indicating which one is greater in value. */ def cmp(first: js.Any, second: js.Any): Int = js.native + /** Returns a promise which resolves to a list of objects giving a snapshot of the names and versions of databases + * within the origin. + * + * This API is intended for web applications to introspect the use of databases, for example to clean up from earlier + * versions of a site’s code. Note that the result is a snapshot; there are no guarantees about the sequencing of the + * collection of the data or the delivery of the response with respect to requests to create, upgrade, or delete + * databases by this context or others. + */ + def databases(): js.Promise[js.Array[IDBDatabaseInfo]] = js.native + /** The deletion operation (performed in a different thread) consists of the following steps: */ - def deleteDatabase(name: String): IDBOpenDBRequest = js.native + def deleteDatabase(name: String): IDBOpenDBRequest[Unit] = js.native } /** The IDBRequest interface of the IndexedDB API provides access to results of asynchronous requests to databases and @@ -488,7 +547,7 @@ class IDBFactory extends js.Object { */ @js.native @JSGlobal -class IDBRequest extends EventTarget { +class IDBRequest[A] extends EventTarget { /** The source of the request, such as an Index or a ObjectStore. If no source exists (such as when calling * IDBFactory.open), it returns null. @@ -496,7 +555,7 @@ class IDBRequest extends EventTarget { def source: js.Any = js.native /** The event handler for the success event. */ - var onsuccess: js.Function1[Event, _] = js.native + var onsuccess: js.Function1[IDBEvent[A], _] = js.native /** Returns a DOMException in the event of an unsuccessful request, indicating what went wrong. */ def error: DOMException = js.native @@ -517,7 +576,24 @@ class IDBRequest extends EventTarget { /** Returns the result of the request. If the the request failed and the result is not available, * the InvalidStateError exception is thrown. */ - def result: js.Any = js.native + def result: A = js.native +} + +@js.native +trait IDBDatabaseInfo extends js.Object { + val name: String = js.native + val version: Int = js.native +} + +trait IDBCreateObjectStoreOptions extends js.Object { + val keyPath: Any = js.undefined + val autoIncrement: js.UndefOr[Boolean] = js.undefined +} + +trait IDBCreateIndexOptions extends js.Object { + val unique: js.UndefOr[Boolean] = js.undefined + val multiEntry: js.UndefOr[Boolean] = js.undefined + val locale: js.UndefOr[String] = js.undefined } /** The IDBEvironment interface of the IndexedDB API provides asynchronous access to a client-side database. It is diff --git a/src/main/scala/org/scalajs/dom/idb.scala b/src/main/scala/org/scalajs/dom/idb.scala index d613ca717..bc7b9916b 100644 --- a/src/main/scala/org/scalajs/dom/idb.scala +++ b/src/main/scala/org/scalajs/dom/idb.scala @@ -2,17 +2,23 @@ package org.scalajs.dom /** Short aliases of all the dom.IDBThing classes */ object idb { + type CreateIndexOptions = IDBCreateIndexOptions + type CreateObjectStoreOptions = IDBCreateObjectStoreOptions type Cursor = IDBCursor @inline def CursorDirection = IDBCursorDirection + type CursorReadOnly = IDBCursorReadOnly type CursorWithValue = IDBCursorWithValue type Database = IDBDatabase + type DatabaseInfo = IDBDatabaseInfo + type Event[+A] = IDBEvent[A] + type EventTarget[+A] = IDBEventTarget[A] type Factory = IDBFactory type Index = IDBIndex type KeyRange = IDBKeyRange @inline def KeyRange = IDBKeyRange type ObjectStore = IDBObjectStore - type OpenDBRequest = IDBOpenDBRequest - type Request = IDBRequest + type OpenDBRequest[A] = IDBOpenDBRequest[A] + type Request[A] = IDBRequest[A] type Transaction = IDBTransaction @inline def TransactionMode = IDBTransactionMode type VersionChangeEvent = IDBVersionChangeEvent diff --git a/src/main/scala/org/scalajs/dom/raw.scala b/src/main/scala/org/scalajs/dom/raw.scala index 5b76cfd29..eca06ce62 100644 --- a/src/main/scala/org/scalajs/dom/raw.scala +++ b/src/main/scala/org/scalajs/dom/raw.scala @@ -506,10 +506,10 @@ object raw { type IDBObjectStore = dom.IDBObjectStore @deprecated("use dom.IDBOpenDBRequest instead", "2.0.0") - type IDBOpenDBRequest = dom.IDBOpenDBRequest + type IDBOpenDBRequest = dom.IDBOpenDBRequest[js.Any] @deprecated("use dom.IDBRequest instead", "2.0.0") - type IDBRequest = dom.IDBRequest + type IDBRequest = dom.IDBRequest[js.Any] @deprecated("use dom.IDBTransaction instead", "2.0.0") type IDBTransaction = dom.IDBTransaction diff --git a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala index 2a1646097..7d723804d 100644 --- a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala +++ b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala @@ -3,6 +3,7 @@ package org.scalajs.dom.tests.shared import org.junit.Assert import scala.concurrent._ import scala.util._ +import scala.scalajs.js import scala.scalajs.js.timers._ object AsyncTesting { @@ -12,6 +13,12 @@ object AsyncTesting { implicit def global: ExecutionContext = ExecutionContext.global + def asyncPass: AsyncResult = + Future.successful(Success(())) + + def asyncWhenDefined[A](o: js.UndefOr[A])(f: A => AsyncResult): AsyncResult = + o.fold(asyncPass)(f) + def async(run: => Future[Any]): AsyncResult = { val p = Promise[Try[Unit]]() val timeout = setTimeout(1200) { diff --git a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala new file mode 100644 index 000000000..d79cc8b13 --- /dev/null +++ b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala @@ -0,0 +1,82 @@ +package org.scalajs.dom.tests.shared + +import java.util.UUID +import org.junit.Assert._ +import org.scalajs.dom._ +import org.scalajs.dom.tests.shared.AsyncTesting._ +import scala.concurrent._ +import scala.scalajs.js +import scala.util.Try + +/** Scala.js version of https://gist.github.com/JamesMessinger/a0d6389a5d0e3a24814b */ +object IdbTest { + + def apply(idb: js.UndefOr[IDBFactory]): AsyncResult = + asyncWhenDefined(idb)(apply(_)) + + def apply(idb: IDBFactory): AsyncResult = async { + open(idb).flatMap(use) + } + + private def open(idb: IDBFactory): Future[IDBDatabase] = { + val p = Promise[IDBDatabase]() + val r = idb.open(UUID.randomUUID().toString) + + r.onerror = (e: Event) => fail(p, "idb.open failed: " + r.error) + + r.onupgradeneeded = (e: IDBEvent[IDBDatabase]) => { + val db = e.target.result + val opts = new IDBCreateObjectStoreOptions { override val keyPath = "id" } + val store = db.createObjectStore("MyObjectStore", opts) + store.createIndex("NameIndex", js.Array("name.last", "name.first")) + } + + r.onsuccess = (e: IDBEvent[IDBDatabase]) => { + assertSame(r.result, e.target.result) + p.success(r.result) + } + + p.future + } + + private def fail(p: Promise[_], why: Any): Unit = + p.failure(new RuntimeException("" + why)) + + private def use(db: IDBDatabase): Future[Unit] = { + import js.Dynamic.{literal => obj} + + val tx = db.transaction("MyObjectStore", IDBTransactionMode.readwrite) + val store = tx.objectStore("MyObjectStore") + val index = store.index("NameIndex") + + // Add some data + store.put(obj(id = 12345, name = obj(first = "John", last = "Doe"), age = 42)) + store.put(obj(id = 67890, name = obj(first = "Bob", last = "Smith"), age = 35)) + + // Query the data + val getJohn = store.get(12345) + val getBob = index.get(js.Array("Smith", "Bob")) + + // Close the db when the transaction is done + tx.oncomplete = (e: Event) => { + db.close() + } + + def getFirstName(r: IDBRequest[js.Any]): Future[String] = { + val p = Promise[String]() + r.onerror = (e: Event) => fail(p, e) + r.onsuccess = (e: IDBEvent[js.Any]) => { + p.complete(Try(e.target.result.asInstanceOf[js.Dynamic].name.first.asInstanceOf[String])) + } + p.future + } + + for { + john <- getFirstName(getJohn) + bob <- getFirstName(getBob) + } yield { + assertEquals("John", john) + assertEquals("Bob", bob) + } + } +} diff --git a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/SharedTests.scala b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/SharedTests.scala index 15c84e377..456b34102 100644 --- a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/SharedTests.scala +++ b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/SharedTests.scala @@ -1,10 +1,12 @@ package org.scalajs.dom.tests.shared -import java.util.UUID +import org.scalajs.dom.tests.shared.AsyncTesting._ import org.junit.Test trait SharedTests { - import SharedTests._ + + // =================================================================================================================== + // Tests WITHOUT org.scalajs.dom._ in scope // This tests that ops are always implicitly available, no imports required @Test final def NodeListOpsTest(): Unit = @@ -18,7 +20,8 @@ trait SharedTests { .map(_.classList.mkString) } - // Don't move up + // =================================================================================================================== + // Tests WITH org.scalajs.dom._ in scope import org.scalajs.dom._ // https://github.com/scala-js/scala-js-dom/issues/411 - console doesn't work in web workers @@ -30,17 +33,6 @@ trait SharedTests { val _ = crypto.HashAlgorithm } - @Test final def WindowIdbTest(): Unit = - window.indexedDB.foreach(testIdb) - -} - -object SharedTests { - import org.scalajs.dom._ - - def testIdb(idb: IDBFactory): Unit = { - val open = idb.open(UUID.randomUUID().toString()) - open.onerror = (e: Event) => sys.error("idb open failed: " + e) - // TODO: Test properly in a different PR - } + @Test final def WindowIdbTest(): AsyncResult = + IdbTest(window.indexedDB) } diff --git a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Server.scala b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Server.scala index d017c7bf3..f3bad138e 100644 --- a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Server.scala +++ b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Server.scala @@ -1,6 +1,7 @@ package org.scalajs.dom.tests.webworker import org.scalajs.dom._ +import scala.concurrent.ExecutionContext.Implicits.global object Server extends ServerResponses { import Protocol._ @@ -13,9 +14,11 @@ object Server extends ServerResponses { val id = msgIn._1 val cmdId = msgIn._2 val cmd = WebWorkerCmd.byId(cmdId) - val output = respond(cmd) - val msgOut = Message(id, output) - ww.postMessage(msgOut) + respond(cmd).onComplete { t => + val output = t.getOrElse(t.failed.get.toString) + val msgOut = Message(id, output) + ww.postMessage(msgOut) + } } ww.postMessage(Message(ServerStarted, "")) diff --git a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/WebWorkerTests.scala b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/WebWorkerTests.scala index 340519cdc..02aa7a1c8 100644 --- a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/WebWorkerTests.scala +++ b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/WebWorkerTests.scala @@ -1,5 +1,7 @@ package org.scalajs.dom.tests.webworker +import scala.language.implicitConversions +import scala.concurrent.Future import org.junit.Assert._ import org.junit.Test import org.scalajs.dom.tests.shared.AsyncTesting._ @@ -46,10 +48,21 @@ trait WebWorkerTests { // ===================================================================================================================== trait ServerResponses { import org.scalajs.dom._ - import org.scalajs.dom.tests.shared.SharedTests._ + import org.scalajs.dom.tests.shared._ import org.scalajs.dom.DedicatedWorkerGlobalScope.self - final val respond: WebWorkerCmd => String = { + private implicit def autoLift(s: => String): Future[String] = + Future(s) + + private implicit class AsyncOps(r: AsyncResult) { + def andReturn(s: String): Future[String] = + r.map { t => + t.get + s + } + } + + final val respond: WebWorkerCmd => Future[String] = { case SayHello => "hello" @@ -60,7 +73,6 @@ trait ServerResponses { case TestIdb => assertTrue(self.indexedDB.isDefined) - testIdb(self.indexedDB.get) - "ok" + IdbTest(self.indexedDB.get).andReturn("ok") } } From e0d2f58dcf1346517e98cc9f2068f9849d2fbb42 Mon Sep 17 00:00:00 2001 From: David Barri Date: Thu, 9 Sep 2021 09:02:46 +1000 Subject: [PATCH 2/8] Replace use of `js.Any` in the IDB API with `Any` --- api-reports/2_12.txt | 50 +++++++++---------- api-reports/2_13.txt | 50 +++++++++---------- src/main/scala/org/scalajs/dom/IDBTypes.scala | 38 +++++++------- .../scalajs/dom/tests/shared/IdbTest.scala | 4 +- 4 files changed, 71 insertions(+), 71 deletions(-) diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index cd81b0a10..a3864262b 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -13540,9 +13540,9 @@ IDBCursor[JC] def continue(key: Any?): Unit IDBCursor[JC] def delete(): IDBRequest[Unit] IDBCursor[JC] def direction: IDBCursorDirection IDBCursor[JC] def key: Any -IDBCursor[JC] def primaryKey: js.Any -IDBCursor[JC] def source: js.Any -IDBCursor[JC] def update(value: js.Any): IDBRequest[Any] +IDBCursor[JC] def primaryKey: Any +IDBCursor[JC] def source: Any +IDBCursor[JC] def update(value: Any): IDBRequest[Any] IDBCursorDirection[JT] IDBCursorDirection[SO] val NEXT: IDBCursorDirection IDBCursorDirection[SO] val NEXT_UNIQUE: IDBCursorDirection @@ -13552,17 +13552,17 @@ IDBCursorReadOnly[JC] def advance(count: Int): Unit IDBCursorReadOnly[JC] def continue(key: Any?): Unit IDBCursorReadOnly[JC] def direction: IDBCursorDirection IDBCursorReadOnly[JC] def key: Any -IDBCursorReadOnly[JC] def primaryKey: js.Any -IDBCursorReadOnly[JC] def source: js.Any +IDBCursorReadOnly[JC] def primaryKey: Any +IDBCursorReadOnly[JC] def source: Any IDBCursorWithValue[JC] def advance(count: Int): Unit IDBCursorWithValue[JC] def continue(key: Any?): Unit IDBCursorWithValue[JC] def delete(): IDBRequest[Unit] IDBCursorWithValue[JC] def direction: IDBCursorDirection IDBCursorWithValue[JC] def key: Any -IDBCursorWithValue[JC] def primaryKey: js.Any -IDBCursorWithValue[JC] def source: js.Any -IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest[Any] -IDBCursorWithValue[JC] def value: js.Any +IDBCursorWithValue[JC] def primaryKey: Any +IDBCursorWithValue[JC] def source: Any +IDBCursorWithValue[JC] def update(value: Any): IDBRequest[Any] +IDBCursorWithValue[JC] def value: Any IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBDatabase[JC] def close(): Unit @@ -13576,7 +13576,7 @@ IDBDatabase[JC] var onerror: js.Function1[Event, _] IDBDatabase[JC] var onversionchange: js.Function1[IDBVersionChangeEvent, _] IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit -IDBDatabase[JC] def transaction(storeNames: js.Any, mode: IDBTransactionMode?): IDBTransaction +IDBDatabase[JC] def transaction(storeNames: Any, mode: IDBTransactionMode?): IDBTransaction IDBDatabase[JC] def version: Int IDBDatabaseInfo[JT] val name: String IDBDatabaseInfo[JT] val version: Int @@ -13601,36 +13601,36 @@ IDBEventTarget[JC] def dispatchEvent(evt: Event): Boolean IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBEventTarget[JC] def result: A -IDBFactory[JC] def cmp(first: js.Any, second: js.Any): Int +IDBFactory[JC] def cmp(first: Any, second: Any): Int IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] IDBIndex[JC] def count(): IDBRequest[Double] IDBIndex[JC] def count(key: Any): IDBRequest[Double] -IDBIndex[JC] def get(key: Any): IDBRequest[js.Any] -IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[js.Any]] +IDBIndex[JC] def get(key: Any): IDBRequest[Any] +IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] IDBIndex[JC] def keyPath: String IDBIndex[JC] def name: String IDBIndex[JC] def objectStore: IDBObjectStore IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursor] IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursorReadOnly] IDBIndex[JC] def unique: Boolean -IDBKeyRange[JC] def lower: js.Any +IDBKeyRange[JC] def lower: Any IDBKeyRange[JC] def lowerOpen: Boolean -IDBKeyRange[JC] def upper: js.Any +IDBKeyRange[JC] def upper: Any IDBKeyRange[JC] def upperOpen: Boolean -IDBKeyRange[JO] def bound(lower: js.Any, upper: js.Any, lowerOpen: Boolean?, upperOpen: Boolean?): IDBKeyRange -IDBKeyRange[JO] def lowerBound(bound: js.Any, open: Boolean?): IDBKeyRange -IDBKeyRange[JO] def only(value: js.Any): IDBKeyRange -IDBKeyRange[JO] def upperBound(bound: js.Any, open: Boolean?): IDBKeyRange -IDBObjectStore[JC] def add(value: js.Any, key: Any?): IDBRequest[Any] +IDBKeyRange[JO] def bound(lower: Any, upper: Any, lowerOpen: Boolean?, upperOpen: Boolean?): IDBKeyRange +IDBKeyRange[JO] def lowerBound(bound: Any, open: Boolean?): IDBKeyRange +IDBKeyRange[JO] def only(value: Any): IDBKeyRange +IDBKeyRange[JO] def upperBound(bound: Any, open: Boolean?): IDBKeyRange +IDBObjectStore[JC] def add(value: Any, key: Any?): IDBRequest[Any] IDBObjectStore[JC] def clear(): IDBRequest[Unit] IDBObjectStore[JC] def count(key: Any?): IDBRequest[Double] IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit -IDBObjectStore[JC] def get(key: Any): IDBRequest[js.Any] -IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[js.Any]] +IDBObjectStore[JC] def get(key: Any): IDBRequest[Any] +IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] IDBObjectStore[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] IDBObjectStore[JC] def index(name: String): IDBIndex @@ -13639,7 +13639,7 @@ IDBObjectStore[JC] def keyPath: String IDBObjectStore[JC] def name: String IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursor] IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursorReadOnly] -IDBObjectStore[JC] def put(value: js.Any, key: Any?): IDBRequest[Any] +IDBObjectStore[JC] def put(value: Any, key: Any?): IDBRequest[Any] IDBObjectStore[JC] def transaction: IDBTransaction IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13653,7 +13653,7 @@ IDBOpenDBRequest[JC] def readyState: String IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBOpenDBRequest[JC] def result: A -IDBOpenDBRequest[JC] def source: js.Any +IDBOpenDBRequest[JC] def source: Any IDBOpenDBRequest[JC] def transaction: IDBTransaction IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13665,7 +13665,7 @@ IDBRequest[JC] def readyState: String IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBRequest[JC] def result: A -IDBRequest[JC] def source: js.Any +IDBRequest[JC] def source: Any IDBRequest[JC] def transaction: IDBTransaction IDBTransaction[JC] def abort(): Unit IDBTransaction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index cd81b0a10..a3864262b 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -13540,9 +13540,9 @@ IDBCursor[JC] def continue(key: Any?): Unit IDBCursor[JC] def delete(): IDBRequest[Unit] IDBCursor[JC] def direction: IDBCursorDirection IDBCursor[JC] def key: Any -IDBCursor[JC] def primaryKey: js.Any -IDBCursor[JC] def source: js.Any -IDBCursor[JC] def update(value: js.Any): IDBRequest[Any] +IDBCursor[JC] def primaryKey: Any +IDBCursor[JC] def source: Any +IDBCursor[JC] def update(value: Any): IDBRequest[Any] IDBCursorDirection[JT] IDBCursorDirection[SO] val NEXT: IDBCursorDirection IDBCursorDirection[SO] val NEXT_UNIQUE: IDBCursorDirection @@ -13552,17 +13552,17 @@ IDBCursorReadOnly[JC] def advance(count: Int): Unit IDBCursorReadOnly[JC] def continue(key: Any?): Unit IDBCursorReadOnly[JC] def direction: IDBCursorDirection IDBCursorReadOnly[JC] def key: Any -IDBCursorReadOnly[JC] def primaryKey: js.Any -IDBCursorReadOnly[JC] def source: js.Any +IDBCursorReadOnly[JC] def primaryKey: Any +IDBCursorReadOnly[JC] def source: Any IDBCursorWithValue[JC] def advance(count: Int): Unit IDBCursorWithValue[JC] def continue(key: Any?): Unit IDBCursorWithValue[JC] def delete(): IDBRequest[Unit] IDBCursorWithValue[JC] def direction: IDBCursorDirection IDBCursorWithValue[JC] def key: Any -IDBCursorWithValue[JC] def primaryKey: js.Any -IDBCursorWithValue[JC] def source: js.Any -IDBCursorWithValue[JC] def update(value: js.Any): IDBRequest[Any] -IDBCursorWithValue[JC] def value: js.Any +IDBCursorWithValue[JC] def primaryKey: Any +IDBCursorWithValue[JC] def source: Any +IDBCursorWithValue[JC] def update(value: Any): IDBRequest[Any] +IDBCursorWithValue[JC] def value: Any IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBDatabase[JC] def close(): Unit @@ -13576,7 +13576,7 @@ IDBDatabase[JC] var onerror: js.Function1[Event, _] IDBDatabase[JC] var onversionchange: js.Function1[IDBVersionChangeEvent, _] IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit -IDBDatabase[JC] def transaction(storeNames: js.Any, mode: IDBTransactionMode?): IDBTransaction +IDBDatabase[JC] def transaction(storeNames: Any, mode: IDBTransactionMode?): IDBTransaction IDBDatabase[JC] def version: Int IDBDatabaseInfo[JT] val name: String IDBDatabaseInfo[JT] val version: Int @@ -13601,36 +13601,36 @@ IDBEventTarget[JC] def dispatchEvent(evt: Event): Boolean IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBEventTarget[JC] def result: A -IDBFactory[JC] def cmp(first: js.Any, second: js.Any): Int +IDBFactory[JC] def cmp(first: Any, second: Any): Int IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] IDBIndex[JC] def count(): IDBRequest[Double] IDBIndex[JC] def count(key: Any): IDBRequest[Double] -IDBIndex[JC] def get(key: Any): IDBRequest[js.Any] -IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[js.Any]] +IDBIndex[JC] def get(key: Any): IDBRequest[Any] +IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] IDBIndex[JC] def keyPath: String IDBIndex[JC] def name: String IDBIndex[JC] def objectStore: IDBObjectStore IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursor] IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursorReadOnly] IDBIndex[JC] def unique: Boolean -IDBKeyRange[JC] def lower: js.Any +IDBKeyRange[JC] def lower: Any IDBKeyRange[JC] def lowerOpen: Boolean -IDBKeyRange[JC] def upper: js.Any +IDBKeyRange[JC] def upper: Any IDBKeyRange[JC] def upperOpen: Boolean -IDBKeyRange[JO] def bound(lower: js.Any, upper: js.Any, lowerOpen: Boolean?, upperOpen: Boolean?): IDBKeyRange -IDBKeyRange[JO] def lowerBound(bound: js.Any, open: Boolean?): IDBKeyRange -IDBKeyRange[JO] def only(value: js.Any): IDBKeyRange -IDBKeyRange[JO] def upperBound(bound: js.Any, open: Boolean?): IDBKeyRange -IDBObjectStore[JC] def add(value: js.Any, key: Any?): IDBRequest[Any] +IDBKeyRange[JO] def bound(lower: Any, upper: Any, lowerOpen: Boolean?, upperOpen: Boolean?): IDBKeyRange +IDBKeyRange[JO] def lowerBound(bound: Any, open: Boolean?): IDBKeyRange +IDBKeyRange[JO] def only(value: Any): IDBKeyRange +IDBKeyRange[JO] def upperBound(bound: Any, open: Boolean?): IDBKeyRange +IDBObjectStore[JC] def add(value: Any, key: Any?): IDBRequest[Any] IDBObjectStore[JC] def clear(): IDBRequest[Unit] IDBObjectStore[JC] def count(key: Any?): IDBRequest[Double] IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit -IDBObjectStore[JC] def get(key: Any): IDBRequest[js.Any] -IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[js.Any]] +IDBObjectStore[JC] def get(key: Any): IDBRequest[Any] +IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] IDBObjectStore[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] IDBObjectStore[JC] def index(name: String): IDBIndex @@ -13639,7 +13639,7 @@ IDBObjectStore[JC] def keyPath: String IDBObjectStore[JC] def name: String IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursor] IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursorReadOnly] -IDBObjectStore[JC] def put(value: js.Any, key: Any?): IDBRequest[Any] +IDBObjectStore[JC] def put(value: Any, key: Any?): IDBRequest[Any] IDBObjectStore[JC] def transaction: IDBTransaction IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13653,7 +13653,7 @@ IDBOpenDBRequest[JC] def readyState: String IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBOpenDBRequest[JC] def result: A -IDBOpenDBRequest[JC] def source: js.Any +IDBOpenDBRequest[JC] def source: Any IDBOpenDBRequest[JC] def transaction: IDBTransaction IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13665,7 +13665,7 @@ IDBRequest[JC] def readyState: String IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBRequest[JC] def result: A -IDBRequest[JC] def source: js.Any +IDBRequest[JC] def source: Any IDBRequest[JC] def transaction: IDBTransaction IDBTransaction[JC] def abort(): Unit IDBTransaction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit diff --git a/src/main/scala/org/scalajs/dom/IDBTypes.scala b/src/main/scala/org/scalajs/dom/IDBTypes.scala index bff8891b8..59c62cf7d 100644 --- a/src/main/scala/org/scalajs/dom/IDBTypes.scala +++ b/src/main/scala/org/scalajs/dom/IDBTypes.scala @@ -74,7 +74,7 @@ class IDBObjectStore extends js.Object { * @return * [[IDBRequest]] with the key as the `target` value */ - def add(value: js.Any, key: Any = js.native): IDBRequest[Any] = js.native + def add(value: Any, key: Any = js.native): IDBRequest[Any] = js.native /** Clearing an object store consists of removing all records from the object store and removing all records in * indexes that reference the object store. @@ -92,7 +92,7 @@ class IDBObjectStore extends js.Object { * @return * [[IDBRequest]] with the key as the `target` value */ - def put(value: js.Any, key: Any = js.native): IDBRequest[Any] = js.native + def put(value: Any, key: Any = js.native): IDBRequest[Any] = js.native /** The method sets the position of the cursor to the appropriate record, based on the specified direction. * @@ -121,13 +121,13 @@ class IDBObjectStore extends js.Object { /** If a value is successfully found, then a structured clone of it is created and set as the result of the request * object. */ - def get(key: Any): IDBRequest[js.Any] = js.native + def get(key: Any): IDBRequest[Any] = js.native /** If a value is successfully found, then a structured clone of it is created and set as the result of the request * object. */ def getAll(query: js.UndefOr[IDBKeyRange | Any] = js.native, - count: js.UndefOr[Int] = js.native): IDBRequest[js.Array[js.Any]] = js.native + count: js.UndefOr[Int] = js.native): IDBRequest[js.Array[Any]] = js.native /** If a value is successfully found, then a structured clone of it is created and set as the result of the request * object. @@ -206,12 +206,12 @@ class IDBIndex extends js.Object { /** Returns an IDBRequest object, and, in a separate thread, finds either the value in the referenced object store * that corresponds to the given key or the first corresponding value, if key is a key range. */ - def get(key: Any): IDBRequest[js.Any] = js.native + def get(key: Any): IDBRequest[Any] = js.native /** Returns an IDBRequest object, and, in a separate thread, finds either the given key or the primary key, if key is * a key range. */ - def getKey(key: Any): IDBRequest[js.UndefOr[js.Any]] = js.native + def getKey(key: Any): IDBRequest[js.UndefOr[Any]] = js.native /** The method sets the position of the cursor to the appropriate record, based on the specified direction. * @@ -246,7 +246,7 @@ class IDBCursorReadOnly extends js.Object { * returns null or throws an exception, even if the cursor is currently being iterated, has iterated past its end, or * its transaction is not active. */ - def source: js.Any = js.native + def source: Any = js.native /** Is a DOMString that, on getting, returns the direction of traversal of the cursor. See Constants for possible * values. @@ -261,7 +261,7 @@ class IDBCursorReadOnly extends js.Object { /** Returns the cursor's current effective key. If the cursor is currently being iterated or has iterated outside its * range, this is set to undefined. The cursor's primary key can be any data type. */ - def primaryKey: js.Any = js.native + def primaryKey: Any = js.native /** This method may raise a DOMException of one of the following types: */ def advance(count: Int): Unit = js.native @@ -296,7 +296,7 @@ class IDBCursor extends IDBCursorReadOnly { /** Returns an IDBRequest object, and, in a separate thread, updates the value at the current position of the cursor * in the object store. */ - def update(value: js.Any): IDBRequest[Any] = js.native + def update(value: Any): IDBRequest[Any] = js.native } @js.native @@ -329,7 +329,7 @@ object IDBCursorDirection { @js.native @JSGlobal class IDBCursorWithValue extends IDBCursor { - def value: js.Any = js.native + def value: Any = js.native } /** The IDBKeyRange interface of the IndexedDB API represents a continuous interval over some data type that is used for @@ -346,13 +346,13 @@ class IDBCursorWithValue extends IDBCursor { class IDBKeyRange extends js.Object { /** The upper bound of the key range (can be any type.) */ - def upper: js.Any = js.native + def upper: Any = js.native /** Returns false if the upper-bound value is included in the key range. */ def upperOpen: Boolean = js.native /** The lower bound of the key range (can be any type.) */ - def lower: js.Any = js.native + def lower: Any = js.native /** Returns false if the lower-bound value is included in the key range. */ def lowerOpen: Boolean = js.native @@ -365,17 +365,17 @@ object IDBKeyRange extends js.Object { /** The bounds can be open (that is, the bounds exclude the endpoint values) or closed (that is, the bounds include * the endpoint values). By default, the bounds are closed. */ - def bound(lower: js.Any, upper: js.Any, lowerOpen: Boolean = js.native, + def bound(lower: Any, upper: Any, lowerOpen: Boolean = js.native, upperOpen: Boolean = js.native): IDBKeyRange = js.native /** This method may raise a DOMException of the following types: */ - def only(value: js.Any): IDBKeyRange = js.native + def only(value: Any): IDBKeyRange = js.native /** By default, it includes the lower endpoint value and is closed. */ - def lowerBound(bound: js.Any, open: Boolean = js.native): IDBKeyRange = js.native + def lowerBound(bound: Any, open: Boolean = js.native): IDBKeyRange = js.native /** By default, it includes the upper endpoint value and is closed. */ - def upperBound(bound: js.Any, open: Boolean = js.native): IDBKeyRange = js.native + def upperBound(bound: Any, open: Boolean = js.native): IDBKeyRange = js.native } /** The IDBTransaction interface of the IndexedDB API provides a static, asynchronous transaction on a database using @@ -474,7 +474,7 @@ class IDBDatabase extends EventTarget { /** Immediately returns a transaction object (IDBTransaction) containing the IDBTransaction.objectStore method, which * you can use to access your object store. Runs in a separate thread. */ - def transaction(storeNames: js.Any, mode: IDBTransactionMode = js.native): IDBTransaction = js.native + def transaction(storeNames: Any, mode: IDBTransactionMode = js.native): IDBTransaction = js.native /** As with createObjectStore, this method can be called only within a versionchange transaction. So for WebKit * browsers you must call the IDBVersionChangeRequest.setVersion method first before you can remove any object store @@ -521,7 +521,7 @@ class IDBFactory extends js.Object { def open(name: String, version: Int = js.native): IDBOpenDBRequest[IDBDatabase] = js.native /** A method that compares two keys and returns a result indicating which one is greater in value. */ - def cmp(first: js.Any, second: js.Any): Int = js.native + def cmp(first: Any, second: Any): Int = js.native /** Returns a promise which resolves to a list of objects giving a snapshot of the names and versions of databases * within the origin. @@ -552,7 +552,7 @@ class IDBRequest[A] extends EventTarget { /** The source of the request, such as an Index or a ObjectStore. If no source exists (such as when calling * IDBFactory.open), it returns null. */ - def source: js.Any = js.native + def source: Any = js.native /** The event handler for the success event. */ var onsuccess: js.Function1[IDBEvent[A], _] = js.native diff --git a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala index d79cc8b13..d89da8781 100644 --- a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala +++ b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala @@ -62,10 +62,10 @@ object IdbTest { db.close() } - def getFirstName(r: IDBRequest[js.Any]): Future[String] = { + def getFirstName(r: IDBRequest[Any]): Future[String] = { val p = Promise[String]() r.onerror = (e: Event) => fail(p, e) - r.onsuccess = (e: IDBEvent[js.Any]) => { + r.onsuccess = (e: IDBEvent[Any]) => { p.complete(Try(e.target.result.asInstanceOf[js.Dynamic].name.first.asInstanceOf[String])) } p.future From a731b3699096e9cc36e4bad515ab49bba6039043 Mon Sep 17 00:00:00 2001 From: David Barri Date: Thu, 9 Sep 2021 09:08:48 +1000 Subject: [PATCH 3/8] IDB counts should be Ints, not Doubles. Acording to https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/getAll#parameters the max count is 2^32 --- api-reports/2_12.txt | 6 +++--- api-reports/2_13.txt | 6 +++--- src/main/scala/org/scalajs/dom/IDBTypes.scala | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index a3864262b..dbebc0a93 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -13605,8 +13605,8 @@ IDBFactory[JC] def cmp(first: Any, second: Any): Int IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] -IDBIndex[JC] def count(): IDBRequest[Double] -IDBIndex[JC] def count(key: Any): IDBRequest[Double] +IDBIndex[JC] def count(): IDBRequest[Int] +IDBIndex[JC] def count(key: Any): IDBRequest[Int] IDBIndex[JC] def get(key: Any): IDBRequest[Any] IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] IDBIndex[JC] def keyPath: String @@ -13625,7 +13625,7 @@ IDBKeyRange[JO] def only(value: Any): IDBKeyRange IDBKeyRange[JO] def upperBound(bound: Any, open: Boolean?): IDBKeyRange IDBObjectStore[JC] def add(value: Any, key: Any?): IDBRequest[Any] IDBObjectStore[JC] def clear(): IDBRequest[Unit] -IDBObjectStore[JC] def count(key: Any?): IDBRequest[Double] +IDBObjectStore[JC] def count(key: Any?): IDBRequest[Int] IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index a3864262b..dbebc0a93 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -13605,8 +13605,8 @@ IDBFactory[JC] def cmp(first: Any, second: Any): Int IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] -IDBIndex[JC] def count(): IDBRequest[Double] -IDBIndex[JC] def count(key: Any): IDBRequest[Double] +IDBIndex[JC] def count(): IDBRequest[Int] +IDBIndex[JC] def count(key: Any): IDBRequest[Int] IDBIndex[JC] def get(key: Any): IDBRequest[Any] IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] IDBIndex[JC] def keyPath: String @@ -13625,7 +13625,7 @@ IDBKeyRange[JO] def only(value: Any): IDBKeyRange IDBKeyRange[JO] def upperBound(bound: Any, open: Boolean?): IDBKeyRange IDBObjectStore[JC] def add(value: Any, key: Any?): IDBRequest[Any] IDBObjectStore[JC] def clear(): IDBRequest[Unit] -IDBObjectStore[JC] def count(key: Any?): IDBRequest[Double] +IDBObjectStore[JC] def count(key: Any?): IDBRequest[Int] IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit diff --git a/src/main/scala/org/scalajs/dom/IDBTypes.scala b/src/main/scala/org/scalajs/dom/IDBTypes.scala index 59c62cf7d..6713e1a34 100644 --- a/src/main/scala/org/scalajs/dom/IDBTypes.scala +++ b/src/main/scala/org/scalajs/dom/IDBTypes.scala @@ -64,7 +64,7 @@ class IDBObjectStore extends js.Object { */ def keyPath: String = js.native - def count(key: Any = js.native): IDBRequest[Double] = js.native + def count(key: Any = js.native): IDBRequest[Int] = js.native /** To determine if the add operation has completed successfully, listen for the transaction’s complete event in * addition to the IDBObjectStore.add request’s success event, because the transaction may still fail after the @@ -196,12 +196,12 @@ class IDBIndex extends js.Object { /** The name of the object store referenced by this index. */ def objectStore: IDBObjectStore = js.native - def count(key: Any): IDBRequest[Double] = js.native + def count(key: Any): IDBRequest[Int] = js.native /** If you want to see how many records are between keys 1000 and 2000 in an object store, you can write the * following: */ - def count(): IDBRequest[Double] = js.native + def count(): IDBRequest[Int] = js.native /** Returns an IDBRequest object, and, in a separate thread, finds either the value in the referenced object store * that corresponds to the given key or the first corresponding value, if key is a key range. From 7a8708edb42b3cbfd77b58f8c6befa2ac2b3b61b Mon Sep 17 00:00:00 2001 From: David Barri Date: Thu, 9 Sep 2021 09:57:15 +1000 Subject: [PATCH 4/8] More improvement * Stop using js.Any in IDB * Replace all uses of Any with something more specific * Improve type safety of various methods * Add missing API * Add more ScalaDoc * Change constants to match the JS names --- api-reports/2_12.txt | 144 +++++---- api-reports/2_13.txt | 144 +++++---- src/main/scala/org/scalajs/dom/IDBTypes.scala | 290 ++++++++++-------- src/main/scala/org/scalajs/dom/idb.scala | 17 +- src/main/scala/org/scalajs/dom/package.scala | 12 + src/main/scala/org/scalajs/dom/raw.scala | 7 +- .../scalajs/dom/tests/shared/IdbTest.scala | 4 +- 7 files changed, 361 insertions(+), 257 deletions(-) diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index dbebc0a93..9c02f1a08 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -13534,35 +13534,35 @@ IDBCreateIndexOptions[JT] val locale: js.UndefOr[String] IDBCreateIndexOptions[JT] val multiEntry: js.UndefOr[Boolean] IDBCreateIndexOptions[JT] val unique: js.UndefOr[Boolean] IDBCreateObjectStoreOptions[JT] val autoIncrement: js.UndefOr[Boolean] -IDBCreateObjectStoreOptions[JT] val keyPath: Any +IDBCreateObjectStoreOptions[JT] val keyPath: IDBKeyPath IDBCursor[JC] def advance(count: Int): Unit -IDBCursor[JC] def continue(key: Any?): Unit -IDBCursor[JC] def delete(): IDBRequest[Unit] +IDBCursor[JC] def continue(key: IDBKey?): Unit +IDBCursor[JC] def delete(): IDBRequest[S, Unit] IDBCursor[JC] def direction: IDBCursorDirection -IDBCursor[JC] def key: Any -IDBCursor[JC] def primaryKey: Any -IDBCursor[JC] def source: Any -IDBCursor[JC] def update(value: Any): IDBRequest[Any] +IDBCursor[JC] def key: IDBKey +IDBCursor[JC] def primaryKey: IDBKey +IDBCursor[JC] def source: S +IDBCursor[JC] def update(value: IDBValue): IDBRequest[S, IDBKey] IDBCursorDirection[JT] -IDBCursorDirection[SO] val NEXT: IDBCursorDirection -IDBCursorDirection[SO] val NEXT_UNIQUE: IDBCursorDirection -IDBCursorDirection[SO] val PREV: IDBCursorDirection -IDBCursorDirection[SO] val PREV_UNIQUE: IDBCursorDirection +IDBCursorDirection[SO] def next: IDBCursorDirection +IDBCursorDirection[SO] def nextunique: IDBCursorDirection +IDBCursorDirection[SO] def prev: IDBCursorDirection +IDBCursorDirection[SO] def prevunique: IDBCursorDirection IDBCursorReadOnly[JC] def advance(count: Int): Unit -IDBCursorReadOnly[JC] def continue(key: Any?): Unit +IDBCursorReadOnly[JC] def continue(key: IDBKey?): Unit IDBCursorReadOnly[JC] def direction: IDBCursorDirection -IDBCursorReadOnly[JC] def key: Any -IDBCursorReadOnly[JC] def primaryKey: Any -IDBCursorReadOnly[JC] def source: Any +IDBCursorReadOnly[JC] def key: IDBKey +IDBCursorReadOnly[JC] def primaryKey: IDBKey +IDBCursorReadOnly[JC] def source: S IDBCursorWithValue[JC] def advance(count: Int): Unit -IDBCursorWithValue[JC] def continue(key: Any?): Unit -IDBCursorWithValue[JC] def delete(): IDBRequest[Unit] +IDBCursorWithValue[JC] def continue(key: IDBKey?): Unit +IDBCursorWithValue[JC] def delete(): IDBRequest[S, Unit] IDBCursorWithValue[JC] def direction: IDBCursorDirection -IDBCursorWithValue[JC] def key: Any -IDBCursorWithValue[JC] def primaryKey: Any -IDBCursorWithValue[JC] def source: Any -IDBCursorWithValue[JC] def update(value: Any): IDBRequest[Any] -IDBCursorWithValue[JC] def value: Any +IDBCursorWithValue[JC] def key: IDBKey +IDBCursorWithValue[JC] def primaryKey: IDBKey +IDBCursorWithValue[JC] def source: S +IDBCursorWithValue[JC] def update(value: IDBValue): IDBRequest[S, IDBKey] +IDBCursorWithValue[JC] def value: IDBValue IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBDatabase[JC] def close(): Unit @@ -13576,7 +13576,7 @@ IDBDatabase[JC] var onerror: js.Function1[Event, _] IDBDatabase[JC] var onversionchange: js.Function1[IDBVersionChangeEvent, _] IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit -IDBDatabase[JC] def transaction(storeNames: Any, mode: IDBTransactionMode?): IDBTransaction +IDBDatabase[JC] def transaction(storeNames: String | js.Array[String], mode: js.UndefOr[IDBTransactionMode]?, options: js.UndefOr[IDBTransactionOptions]?): IDBTransaction IDBDatabase[JC] def version: Int IDBDatabaseInfo[JT] val name: String IDBDatabaseInfo[JT] val version: Int @@ -13601,45 +13601,47 @@ IDBEventTarget[JC] def dispatchEvent(evt: Event): Boolean IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBEventTarget[JC] def result: A -IDBFactory[JC] def cmp(first: Any, second: Any): Int +IDBFactory[JC] def cmp(first: IDBValue, second: IDBValue): Int IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] -IDBIndex[JC] def count(): IDBRequest[Int] -IDBIndex[JC] def count(key: Any): IDBRequest[Int] -IDBIndex[JC] def get(key: Any): IDBRequest[Any] -IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] -IDBIndex[JC] def keyPath: String +IDBIndex[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBIndex[JC] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] +IDBIndex[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] +IDBIndex[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBIndex[JC] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] +IDBIndex[JC] def keyPath: IDBKeyPath +IDBIndex[JC] val multiEntry: Boolean IDBIndex[JC] def name: String IDBIndex[JC] def objectStore: IDBObjectStore -IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursor] -IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursorReadOnly] +IDBIndex[JC] def openCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursor[S]] +IDBIndex[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursorReadOnly[S]] IDBIndex[JC] def unique: Boolean -IDBKeyRange[JC] def lower: Any +IDBKeyRange[JC] def lower: IDBKey IDBKeyRange[JC] def lowerOpen: Boolean -IDBKeyRange[JC] def upper: Any +IDBKeyRange[JC] def upper: IDBKey IDBKeyRange[JC] def upperOpen: Boolean -IDBKeyRange[JO] def bound(lower: Any, upper: Any, lowerOpen: Boolean?, upperOpen: Boolean?): IDBKeyRange -IDBKeyRange[JO] def lowerBound(bound: Any, open: Boolean?): IDBKeyRange -IDBKeyRange[JO] def only(value: Any): IDBKeyRange -IDBKeyRange[JO] def upperBound(bound: Any, open: Boolean?): IDBKeyRange -IDBObjectStore[JC] def add(value: Any, key: Any?): IDBRequest[Any] -IDBObjectStore[JC] def clear(): IDBRequest[Unit] -IDBObjectStore[JC] def count(key: Any?): IDBRequest[Int] -IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex -IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit] +IDBKeyRange[JO] def bound(lower: IDBKey, upper: IDBKey, lowerOpen: Boolean?, upperOpen: Boolean?): IDBKeyRange +IDBKeyRange[JO] def lowerBound(bound: IDBKey, open: Boolean?): IDBKeyRange +IDBKeyRange[JO] def only(value: IDBValue): IDBKeyRange +IDBKeyRange[JO] def upperBound(bound: IDBKey, open: Boolean?): IDBKeyRange +IDBObjectStore[JC] def add(value: IDBValue, key: IDBKey?): IDBRequest[IDBObjectStore, IDBKey] +IDBObjectStore[JC] def clear(): IDBRequest[IDBObjectStore, Unit] +IDBObjectStore[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBObjectStore[JC] def createIndex(name: String, keyPath: IDBKeyPath, optionalParameters: IDBCreateIndexOptions?): IDBIndex +IDBObjectStore[JC] def delete(key: IDBKey | IDBKeyRange): IDBRequest[IDBObjectStore, Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit -IDBObjectStore[JC] def get(key: Any): IDBRequest[Any] -IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] -IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] -IDBObjectStore[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] +IDBObjectStore[JC] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] +IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] +IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBObjectStore[JC] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] IDBObjectStore[JC] def index(name: String): IDBIndex IDBObjectStore[JC] def indexNames: DOMStringList -IDBObjectStore[JC] def keyPath: String +IDBObjectStore[JC] def keyPath: IDBKeyPath IDBObjectStore[JC] def name: String -IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursor] -IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursorReadOnly] -IDBObjectStore[JC] def put(value: Any, key: Any?): IDBRequest[Any] +IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursor[S]] +IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursorReadOnly[S]] +IDBObjectStore[JC] def put(value: IDBValue, key: IDBKey?): IDBRequest[IDBObjectStore, IDBKey] IDBObjectStore[JC] def transaction: IDBTransaction IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13653,7 +13655,7 @@ IDBOpenDBRequest[JC] def readyState: String IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBOpenDBRequest[JC] def result: A -IDBOpenDBRequest[JC] def source: Any +IDBOpenDBRequest[JC] def source: S IDBOpenDBRequest[JC] def transaction: IDBTransaction IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13665,8 +13667,17 @@ IDBRequest[JC] def readyState: String IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBRequest[JC] def result: A -IDBRequest[JC] def source: Any +IDBRequest[JC] def source: S IDBRequest[JC] def transaction: IDBTransaction +IDBStoreLike[JT] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBStoreLike[JT] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] +IDBStoreLike[JT] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] +IDBStoreLike[JT] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBStoreLike[JT] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] +IDBStoreLike[JT] def keyPath: IDBKeyPath +IDBStoreLike[JT] def name: String +IDBStoreLike[JT] def openCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursor[S]] +IDBStoreLike[JT] def openKeyCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursorReadOnly[S]] IDBTransaction[JC] def abort(): Unit IDBTransaction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBTransaction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13680,10 +13691,15 @@ IDBTransaction[JC] var oncomplete: js.Function1[Event, _] IDBTransaction[JC] var onerror: js.Function1[Event, _] IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +IDBTransactionDurability[JT] +IDBTransactionDurability[SO] def default: IDBTransactionDurability +IDBTransactionDurability[SO] def relaxed: IDBTransactionDurability +IDBTransactionDurability[SO] def strict: IDBTransactionDurability IDBTransactionMode[JT] -IDBTransactionMode[SO] val readonly: IDBTransactionMode -IDBTransactionMode[SO] val readwrite: IDBTransactionMode -IDBTransactionMode[SO] val versionchange: IDBTransactionMode +IDBTransactionMode[SO] def readonly: IDBTransactionMode +IDBTransactionMode[SO] def readwrite: IDBTransactionMode +IDBTransactionMode[SO] def versionchange: IDBTransactionMode +IDBTransactionOptions[JT] val durability: js.UndefOr[IDBTransactionDurability] IDBVersionChangeEvent[JC] def bubbles: Boolean IDBVersionChangeEvent[JC] def cancelBubble: Boolean IDBVersionChangeEvent[JC] def cancelable: Boolean @@ -25597,9 +25613,9 @@ html[SO] type Video = HTMLVideoElement html[SO] def Media = HTMLMediaElement idb[SO] type CreateIndexOptions = IDBCreateIndexOptions idb[SO] type CreateObjectStoreOptions = IDBCreateObjectStoreOptions -idb[SO] type Cursor = IDBCursor -idb[SO] type CursorReadOnly = IDBCursorReadOnly +idb[SO] type CursorReadOnly[+Source] = IDBCursorReadOnly[Source] idb[SO] type CursorWithValue = IDBCursorWithValue +idb[SO] type Cursor[+Source] = IDBCursor[Source] idb[SO] type Database = IDBDatabase idb[SO] type DatabaseInfo = IDBDatabaseInfo idb[SO] type Environment = IDBEnvironment (@deprecated in 1.2.0) @@ -25607,11 +25623,14 @@ idb[SO] type EventTarget[+A] = IDBEventTarget[A] idb[SO] type Event[+A] = IDBEvent[A] idb[SO] type Factory = IDBFactory idb[SO] type Index = IDBIndex +idb[SO] type Key = IDBKey +idb[SO] type KeyPath = IDBKeyPath idb[SO] type KeyRange = IDBKeyRange idb[SO] type ObjectStore = IDBObjectStore idb[SO] type OpenDBRequest[A] = IDBOpenDBRequest[A] -idb[SO] type Request[A] = IDBRequest[A] +idb[SO] type Request[+Source, A] = IDBRequest[Source, A] idb[SO] type Transaction = IDBTransaction +idb[SO] type Value = IDBValue idb[SO] type VersionChangeEvent = IDBVersionChangeEvent idb[SO] def CursorDirection = IDBCursorDirection idb[SO] def KeyRange = IDBKeyRange @@ -25622,6 +25641,9 @@ package[SO] type ByteString = String package[SO] type ClientRect = DOMRect (@deprecated in 2.0.0) package[SO] type ClientRectList = DOMRectList (@deprecated in 2.0.0) package[SO] type HeadersInit = Headers | Sequence[Sequence[ByteString]] | OpenEndedDictionary[ByteString] +package[SO] type IDBKey = Any +package[SO] type IDBKeyPath = Any +package[SO] type IDBValue = Any package[SO] type NodeListOf[+T <: Node] = NodeList[T] (@deprecated in 2.0.0) package[SO] type OpenEndedDictionary[T] = js.Dictionary[T] package[SO] type RequestInfo = String | Request @@ -25776,7 +25798,7 @@ raw[SO] type HTMLUnknownElement = dom.HTMLUnknownElement (@deprecated in 2.0.0) raw[SO] type HTMLVideoElement = dom.HTMLVideoElement (@deprecated in 2.0.0) raw[SO] type HashChangeEvent = dom.HashChangeEvent (@deprecated in 2.0.0) raw[SO] type History = dom.History (@deprecated in 2.0.0) -raw[SO] type IDBCursor = dom.IDBCursor (@deprecated in 2.0.0) +raw[SO] type IDBCursor = dom.IDBCursor[IDBObjectStore | IDBIndex] (@deprecated in 2.0.0) raw[SO] type IDBCursorWithValue = dom.IDBCursorWithValue (@deprecated in 2.0.0) raw[SO] type IDBDatabase = dom.IDBDatabase (@deprecated in 2.0.0) raw[SO] type IDBEnvironment = dom.IDBEnvironment (@deprecated in 2.0.0) @@ -25784,8 +25806,8 @@ raw[SO] type IDBFactory = dom.IDBFactory (@deprecated in 2.0.0) raw[SO] type IDBIndex = dom.IDBIndex (@deprecated in 2.0.0) raw[SO] type IDBKeyRange = dom.IDBKeyRange (@deprecated in 2.0.0) raw[SO] type IDBObjectStore = dom.IDBObjectStore (@deprecated in 2.0.0) -raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest[js.Any] (@deprecated in 2.0.0) -raw[SO] type IDBRequest = dom.IDBRequest[js.Any] (@deprecated in 2.0.0) +raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest[Any] (@deprecated in 2.0.0) +raw[SO] type IDBRequest = dom.IDBRequest[Any, Any] (@deprecated in 2.0.0) raw[SO] type IDBTransaction = dom.IDBTransaction (@deprecated in 2.0.0) raw[SO] type IDBVersionChangeEvent = dom.IDBVersionChangeEvent (@deprecated in 2.0.0) raw[SO] type ImageBitmap = dom.ImageBitmap (@deprecated in 2.0.0) diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index dbebc0a93..9c02f1a08 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -13534,35 +13534,35 @@ IDBCreateIndexOptions[JT] val locale: js.UndefOr[String] IDBCreateIndexOptions[JT] val multiEntry: js.UndefOr[Boolean] IDBCreateIndexOptions[JT] val unique: js.UndefOr[Boolean] IDBCreateObjectStoreOptions[JT] val autoIncrement: js.UndefOr[Boolean] -IDBCreateObjectStoreOptions[JT] val keyPath: Any +IDBCreateObjectStoreOptions[JT] val keyPath: IDBKeyPath IDBCursor[JC] def advance(count: Int): Unit -IDBCursor[JC] def continue(key: Any?): Unit -IDBCursor[JC] def delete(): IDBRequest[Unit] +IDBCursor[JC] def continue(key: IDBKey?): Unit +IDBCursor[JC] def delete(): IDBRequest[S, Unit] IDBCursor[JC] def direction: IDBCursorDirection -IDBCursor[JC] def key: Any -IDBCursor[JC] def primaryKey: Any -IDBCursor[JC] def source: Any -IDBCursor[JC] def update(value: Any): IDBRequest[Any] +IDBCursor[JC] def key: IDBKey +IDBCursor[JC] def primaryKey: IDBKey +IDBCursor[JC] def source: S +IDBCursor[JC] def update(value: IDBValue): IDBRequest[S, IDBKey] IDBCursorDirection[JT] -IDBCursorDirection[SO] val NEXT: IDBCursorDirection -IDBCursorDirection[SO] val NEXT_UNIQUE: IDBCursorDirection -IDBCursorDirection[SO] val PREV: IDBCursorDirection -IDBCursorDirection[SO] val PREV_UNIQUE: IDBCursorDirection +IDBCursorDirection[SO] def next: IDBCursorDirection +IDBCursorDirection[SO] def nextunique: IDBCursorDirection +IDBCursorDirection[SO] def prev: IDBCursorDirection +IDBCursorDirection[SO] def prevunique: IDBCursorDirection IDBCursorReadOnly[JC] def advance(count: Int): Unit -IDBCursorReadOnly[JC] def continue(key: Any?): Unit +IDBCursorReadOnly[JC] def continue(key: IDBKey?): Unit IDBCursorReadOnly[JC] def direction: IDBCursorDirection -IDBCursorReadOnly[JC] def key: Any -IDBCursorReadOnly[JC] def primaryKey: Any -IDBCursorReadOnly[JC] def source: Any +IDBCursorReadOnly[JC] def key: IDBKey +IDBCursorReadOnly[JC] def primaryKey: IDBKey +IDBCursorReadOnly[JC] def source: S IDBCursorWithValue[JC] def advance(count: Int): Unit -IDBCursorWithValue[JC] def continue(key: Any?): Unit -IDBCursorWithValue[JC] def delete(): IDBRequest[Unit] +IDBCursorWithValue[JC] def continue(key: IDBKey?): Unit +IDBCursorWithValue[JC] def delete(): IDBRequest[S, Unit] IDBCursorWithValue[JC] def direction: IDBCursorDirection -IDBCursorWithValue[JC] def key: Any -IDBCursorWithValue[JC] def primaryKey: Any -IDBCursorWithValue[JC] def source: Any -IDBCursorWithValue[JC] def update(value: Any): IDBRequest[Any] -IDBCursorWithValue[JC] def value: Any +IDBCursorWithValue[JC] def key: IDBKey +IDBCursorWithValue[JC] def primaryKey: IDBKey +IDBCursorWithValue[JC] def source: S +IDBCursorWithValue[JC] def update(value: IDBValue): IDBRequest[S, IDBKey] +IDBCursorWithValue[JC] def value: IDBValue IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBDatabase[JC] def close(): Unit @@ -13576,7 +13576,7 @@ IDBDatabase[JC] var onerror: js.Function1[Event, _] IDBDatabase[JC] var onversionchange: js.Function1[IDBVersionChangeEvent, _] IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBDatabase[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit -IDBDatabase[JC] def transaction(storeNames: Any, mode: IDBTransactionMode?): IDBTransaction +IDBDatabase[JC] def transaction(storeNames: String | js.Array[String], mode: js.UndefOr[IDBTransactionMode]?, options: js.UndefOr[IDBTransactionOptions]?): IDBTransaction IDBDatabase[JC] def version: Int IDBDatabaseInfo[JT] val name: String IDBDatabaseInfo[JT] val version: Int @@ -13601,45 +13601,47 @@ IDBEventTarget[JC] def dispatchEvent(evt: Event): Boolean IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBEventTarget[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBEventTarget[JC] def result: A -IDBFactory[JC] def cmp(first: Any, second: Any): Int +IDBFactory[JC] def cmp(first: IDBValue, second: IDBValue): Int IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] -IDBIndex[JC] def count(): IDBRequest[Int] -IDBIndex[JC] def count(key: Any): IDBRequest[Int] -IDBIndex[JC] def get(key: Any): IDBRequest[Any] -IDBIndex[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] -IDBIndex[JC] def keyPath: String +IDBIndex[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBIndex[JC] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] +IDBIndex[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] +IDBIndex[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBIndex[JC] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] +IDBIndex[JC] def keyPath: IDBKeyPath +IDBIndex[JC] val multiEntry: Boolean IDBIndex[JC] def name: String IDBIndex[JC] def objectStore: IDBObjectStore -IDBIndex[JC] def openCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursor] -IDBIndex[JC] def openKeyCursor(range: IDBKeyRange?, direction: IDBCursorDirection?): IDBRequest[IDBCursorReadOnly] +IDBIndex[JC] def openCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursor[S]] +IDBIndex[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursorReadOnly[S]] IDBIndex[JC] def unique: Boolean -IDBKeyRange[JC] def lower: Any +IDBKeyRange[JC] def lower: IDBKey IDBKeyRange[JC] def lowerOpen: Boolean -IDBKeyRange[JC] def upper: Any +IDBKeyRange[JC] def upper: IDBKey IDBKeyRange[JC] def upperOpen: Boolean -IDBKeyRange[JO] def bound(lower: Any, upper: Any, lowerOpen: Boolean?, upperOpen: Boolean?): IDBKeyRange -IDBKeyRange[JO] def lowerBound(bound: Any, open: Boolean?): IDBKeyRange -IDBKeyRange[JO] def only(value: Any): IDBKeyRange -IDBKeyRange[JO] def upperBound(bound: Any, open: Boolean?): IDBKeyRange -IDBObjectStore[JC] def add(value: Any, key: Any?): IDBRequest[Any] -IDBObjectStore[JC] def clear(): IDBRequest[Unit] -IDBObjectStore[JC] def count(key: Any?): IDBRequest[Int] -IDBObjectStore[JC] def createIndex(name: String, keyPath: Any, optionalParameters: IDBCreateIndexOptions?): IDBIndex -IDBObjectStore[JC] def delete(key: Any): IDBRequest[Unit] +IDBKeyRange[JO] def bound(lower: IDBKey, upper: IDBKey, lowerOpen: Boolean?, upperOpen: Boolean?): IDBKeyRange +IDBKeyRange[JO] def lowerBound(bound: IDBKey, open: Boolean?): IDBKeyRange +IDBKeyRange[JO] def only(value: IDBValue): IDBKeyRange +IDBKeyRange[JO] def upperBound(bound: IDBKey, open: Boolean?): IDBKeyRange +IDBObjectStore[JC] def add(value: IDBValue, key: IDBKey?): IDBRequest[IDBObjectStore, IDBKey] +IDBObjectStore[JC] def clear(): IDBRequest[IDBObjectStore, Unit] +IDBObjectStore[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBObjectStore[JC] def createIndex(name: String, keyPath: IDBKeyPath, optionalParameters: IDBCreateIndexOptions?): IDBIndex +IDBObjectStore[JC] def delete(key: IDBKey | IDBKeyRange): IDBRequest[IDBObjectStore, Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit -IDBObjectStore[JC] def get(key: Any): IDBRequest[Any] -IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] -IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | Any]?, count: js.UndefOr[Int]?): IDBRequest[js.Array[Any]] -IDBObjectStore[JC] def getKey(key: Any): IDBRequest[js.UndefOr[Any]] +IDBObjectStore[JC] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] +IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] +IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBObjectStore[JC] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] IDBObjectStore[JC] def index(name: String): IDBIndex IDBObjectStore[JC] def indexNames: DOMStringList -IDBObjectStore[JC] def keyPath: String +IDBObjectStore[JC] def keyPath: IDBKeyPath IDBObjectStore[JC] def name: String -IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursor] -IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[IDBCursorReadOnly] -IDBObjectStore[JC] def put(value: Any, key: Any?): IDBRequest[Any] +IDBObjectStore[JC] def openCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursor[S]] +IDBObjectStore[JC] def openKeyCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursorReadOnly[S]] +IDBObjectStore[JC] def put(value: IDBValue, key: IDBKey?): IDBRequest[IDBObjectStore, IDBKey] IDBObjectStore[JC] def transaction: IDBTransaction IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13653,7 +13655,7 @@ IDBOpenDBRequest[JC] def readyState: String IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBOpenDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBOpenDBRequest[JC] def result: A -IDBOpenDBRequest[JC] def source: Any +IDBOpenDBRequest[JC] def source: S IDBOpenDBRequest[JC] def transaction: IDBTransaction IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13665,8 +13667,17 @@ IDBRequest[JC] def readyState: String IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit IDBRequest[JC] def result: A -IDBRequest[JC] def source: Any +IDBRequest[JC] def source: S IDBRequest[JC] def transaction: IDBTransaction +IDBStoreLike[JT] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBStoreLike[JT] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] +IDBStoreLike[JT] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] +IDBStoreLike[JT] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBStoreLike[JT] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] +IDBStoreLike[JT] def keyPath: IDBKeyPath +IDBStoreLike[JT] def name: String +IDBStoreLike[JT] def openCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursor[S]] +IDBStoreLike[JT] def openKeyCursor(range: js.UndefOr[IDBKeyRange | IDBKey]?, direction: js.UndefOr[IDBCursorDirection]?): IDBRequest[S, IDBCursorReadOnly[S]] IDBTransaction[JC] def abort(): Unit IDBTransaction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBTransaction[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit @@ -13680,10 +13691,15 @@ IDBTransaction[JC] var oncomplete: js.Function1[Event, _] IDBTransaction[JC] var onerror: js.Function1[Event, _] IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit IDBTransaction[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +IDBTransactionDurability[JT] +IDBTransactionDurability[SO] def default: IDBTransactionDurability +IDBTransactionDurability[SO] def relaxed: IDBTransactionDurability +IDBTransactionDurability[SO] def strict: IDBTransactionDurability IDBTransactionMode[JT] -IDBTransactionMode[SO] val readonly: IDBTransactionMode -IDBTransactionMode[SO] val readwrite: IDBTransactionMode -IDBTransactionMode[SO] val versionchange: IDBTransactionMode +IDBTransactionMode[SO] def readonly: IDBTransactionMode +IDBTransactionMode[SO] def readwrite: IDBTransactionMode +IDBTransactionMode[SO] def versionchange: IDBTransactionMode +IDBTransactionOptions[JT] val durability: js.UndefOr[IDBTransactionDurability] IDBVersionChangeEvent[JC] def bubbles: Boolean IDBVersionChangeEvent[JC] def cancelBubble: Boolean IDBVersionChangeEvent[JC] def cancelable: Boolean @@ -25597,9 +25613,9 @@ html[SO] type Video = HTMLVideoElement html[SO] def Media = HTMLMediaElement idb[SO] type CreateIndexOptions = IDBCreateIndexOptions idb[SO] type CreateObjectStoreOptions = IDBCreateObjectStoreOptions -idb[SO] type Cursor = IDBCursor -idb[SO] type CursorReadOnly = IDBCursorReadOnly +idb[SO] type CursorReadOnly[+Source] = IDBCursorReadOnly[Source] idb[SO] type CursorWithValue = IDBCursorWithValue +idb[SO] type Cursor[+Source] = IDBCursor[Source] idb[SO] type Database = IDBDatabase idb[SO] type DatabaseInfo = IDBDatabaseInfo idb[SO] type Environment = IDBEnvironment (@deprecated in 1.2.0) @@ -25607,11 +25623,14 @@ idb[SO] type EventTarget[+A] = IDBEventTarget[A] idb[SO] type Event[+A] = IDBEvent[A] idb[SO] type Factory = IDBFactory idb[SO] type Index = IDBIndex +idb[SO] type Key = IDBKey +idb[SO] type KeyPath = IDBKeyPath idb[SO] type KeyRange = IDBKeyRange idb[SO] type ObjectStore = IDBObjectStore idb[SO] type OpenDBRequest[A] = IDBOpenDBRequest[A] -idb[SO] type Request[A] = IDBRequest[A] +idb[SO] type Request[+Source, A] = IDBRequest[Source, A] idb[SO] type Transaction = IDBTransaction +idb[SO] type Value = IDBValue idb[SO] type VersionChangeEvent = IDBVersionChangeEvent idb[SO] def CursorDirection = IDBCursorDirection idb[SO] def KeyRange = IDBKeyRange @@ -25622,6 +25641,9 @@ package[SO] type ByteString = String package[SO] type ClientRect = DOMRect (@deprecated in 2.0.0) package[SO] type ClientRectList = DOMRectList (@deprecated in 2.0.0) package[SO] type HeadersInit = Headers | Sequence[Sequence[ByteString]] | OpenEndedDictionary[ByteString] +package[SO] type IDBKey = Any +package[SO] type IDBKeyPath = Any +package[SO] type IDBValue = Any package[SO] type NodeListOf[+T <: Node] = NodeList[T] (@deprecated in 2.0.0) package[SO] type OpenEndedDictionary[T] = js.Dictionary[T] package[SO] type RequestInfo = String | Request @@ -25776,7 +25798,7 @@ raw[SO] type HTMLUnknownElement = dom.HTMLUnknownElement (@deprecated in 2.0.0) raw[SO] type HTMLVideoElement = dom.HTMLVideoElement (@deprecated in 2.0.0) raw[SO] type HashChangeEvent = dom.HashChangeEvent (@deprecated in 2.0.0) raw[SO] type History = dom.History (@deprecated in 2.0.0) -raw[SO] type IDBCursor = dom.IDBCursor (@deprecated in 2.0.0) +raw[SO] type IDBCursor = dom.IDBCursor[IDBObjectStore | IDBIndex] (@deprecated in 2.0.0) raw[SO] type IDBCursorWithValue = dom.IDBCursorWithValue (@deprecated in 2.0.0) raw[SO] type IDBDatabase = dom.IDBDatabase (@deprecated in 2.0.0) raw[SO] type IDBEnvironment = dom.IDBEnvironment (@deprecated in 2.0.0) @@ -25784,8 +25806,8 @@ raw[SO] type IDBFactory = dom.IDBFactory (@deprecated in 2.0.0) raw[SO] type IDBIndex = dom.IDBIndex (@deprecated in 2.0.0) raw[SO] type IDBKeyRange = dom.IDBKeyRange (@deprecated in 2.0.0) raw[SO] type IDBObjectStore = dom.IDBObjectStore (@deprecated in 2.0.0) -raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest[js.Any] (@deprecated in 2.0.0) -raw[SO] type IDBRequest = dom.IDBRequest[js.Any] (@deprecated in 2.0.0) +raw[SO] type IDBOpenDBRequest = dom.IDBOpenDBRequest[Any] (@deprecated in 2.0.0) +raw[SO] type IDBRequest = dom.IDBRequest[Any, Any] (@deprecated in 2.0.0) raw[SO] type IDBTransaction = dom.IDBTransaction (@deprecated in 2.0.0) raw[SO] type IDBVersionChangeEvent = dom.IDBVersionChangeEvent (@deprecated in 2.0.0) raw[SO] type ImageBitmap = dom.ImageBitmap (@deprecated in 2.0.0) diff --git a/src/main/scala/org/scalajs/dom/IDBTypes.scala b/src/main/scala/org/scalajs/dom/IDBTypes.scala index 6713e1a34..a496b5b37 100644 --- a/src/main/scala/org/scalajs/dom/IDBTypes.scala +++ b/src/main/scala/org/scalajs/dom/IDBTypes.scala @@ -10,6 +10,7 @@ import scala.scalajs.js import scala.scalajs.js.annotation._ import scala.scalajs.js.| +/** @tparam A Type of `.target.result` */ @js.native @JSGlobal("Event") class IDBEvent[+A](typeArg: String, init: js.UndefOr[EventInit] = js.undefined) extends Event(typeArg, init) { @@ -31,40 +32,118 @@ sealed trait IDBTransactionMode extends js.Any object IDBTransactionMode { /** Allows data to be read but not changed. It is the default transaction mode. */ - val readonly: IDBTransactionMode = "readonly".asInstanceOf[IDBTransactionMode] + @inline def readonly: IDBTransactionMode = "readonly".asInstanceOf[IDBTransactionMode] /** Allows any operation to be performed, including ones that delete and create object stores and indexes. This mode * is for updating the version number of transactions that were started using the setVersion() method of IDBDatabase * objects. Transactions of this mode cannot run concurrently with other transactions. */ - val versionchange: IDBTransactionMode = "versionchange".asInstanceOf[IDBTransactionMode] + @inline def versionchange: IDBTransactionMode = "versionchange".asInstanceOf[IDBTransactionMode] /** Allows reading and writing of data in existing data stores to be changed. */ - val readwrite: IDBTransactionMode = "readwrite".asInstanceOf[IDBTransactionMode] + @inline def readwrite: IDBTransactionMode = "readwrite".asInstanceOf[IDBTransactionMode] +} + +@js.native +sealed trait IDBTransactionDurability extends js.Any +object IDBTransactionDurability { + @inline def default: IDBTransactionDurability = "default".asInstanceOf[IDBTransactionDurability] + @inline def strict: IDBTransactionDurability = "strict".asInstanceOf[IDBTransactionDurability] + @inline def relaxed: IDBTransactionDurability = "relaxed".asInstanceOf[IDBTransactionDurability] } -/** The IDBObjectStore interface of the IndexedDB API represents an object store in a database. Records within an object - * store are sorted according to their keys. This sorting enables fast insertion, look-up, and ordered retrieval. +/** Common members shared between [[IDBObjectStore]] and [[IDBIndex]]. + * + * @tparam S + * The type of `.source` */ @js.native -@JSGlobal -class IDBObjectStore extends js.Object { +trait IDBStoreLike[S] extends js.Object { - /** A list of the names of indexes on objects in this object store. */ - def indexNames: DOMStringList = js.native + def count(query: IDBKey | IDBKeyRange = js.native): IDBRequest[S, Int] = js.native - def name: String = js.native + /** Returns an [[IDBRequest]] object, and, in a separate thread, returns the object store selected by the specified + * key. This is for retrieving specific records from an object store. + * + * Note: This method produces the same result for: a) a record that doesn't exist in the database and b) a record + * that has an undefined value. To tell these situations apart, call the [[openCursor()]] method with the same key. + * That method provides a cursor if the record exists, and no cursor if it does not. + */ + def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] = js.native - /** The name of the transaction to which this object store belongs. */ - def transaction: IDBTransaction = js.native + /** Returns an [[IDBRequest]] object containing all objects in the object store matching the specified parameter or + * all objects in the store if no parameters are given. + * + * If a value is successfully found, then a structured clone of it is created and set as the result of the request + * object. + * + * This method produces the same result for: + * + * - a record that doesn't exist in the database + * - a record that has an undefined value + * + * To tell these situations apart, you either call + * + * - the [[openCursor()]] method with the same key. That method provides a cursor if the record exists, and no + * cursor if it does not. + * - the [[count()]] method with the same key, which will return 1 if the row exists and 0 if it doesn't. + */ + def getAll(query: js.UndefOr[IDBKeyRange | IDBKey] = js.native, + count: js.UndefOr[Int] = js.native): IDBRequest[S, js.Array[IDBValue]] = js.native + + /** Returns an [[IDBRequest]] object retrieves record keys for all objects in the object store matching the specified + * parameter or all objects in the store if no parameters are given. + * + * If a value is successfully found, then a structured clone of it is created and set as the result of the request + * object. + * + * This method produces the same result for: + * + * - a record that doesn't exist in the database + * - a record that has an undefined value + * + * To tell these situations apart, you need to call the [[openCursor()]] method with the same key. That method + * provides a cursor if the record exists, and no cursor if it does not. + */ + def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey] = js.native, + count: js.UndefOr[Int] = js.native): IDBRequest[S, js.Array[IDBKey]] = js.native + + /** Returns an [[IDBRequest]] object, and, in a separate thread, returns the key selected by the specified query. This + * is for retrieving specific records from an object store. + */ + def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] = js.native /** The key path of this object store. If this attribute is null, the application must provide a key for each * modification operation. */ - def keyPath: String = js.native + def keyPath: IDBKeyPath = js.native + + def name: String = js.native + + /** The method sets the position of the cursor to the appropriate record, based on the specified direction. + * + * @return + * [[IDBRequest]] with the `target` value being a new cursor or `null`. + */ + def openCursor(range: js.UndefOr[IDBKeyRange | IDBKey] = js.native, + direction: js.UndefOr[IDBCursorDirection] = js.native): IDBRequest[S, IDBCursor[S]] = js.native + + /** The method sets the position of the cursor to the appropriate key, based on the specified direction. + * + * @return + * [[IDBRequest]] with the `target` value being a new cursor or `null`. + */ + def openKeyCursor(range: js.UndefOr[IDBKeyRange | IDBKey] = js.native, + direction: js.UndefOr[IDBCursorDirection] = js.native): IDBRequest[S, IDBCursorReadOnly[S]] = js.native +} - def count(key: Any = js.native): IDBRequest[Int] = js.native +/** The IDBObjectStore interface of the IndexedDB API represents an object store in a database. Records within an object + * store are sorted according to their keys. This sorting enables fast insertion, look-up, and ordered retrieval. + */ +@js.native +@JSGlobal +class IDBObjectStore extends IDBStoreLike[IDBObjectStore] { /** To determine if the add operation has completed successfully, listen for the transaction’s complete event in * addition to the IDBObjectStore.add request’s success event, because the transaction may still fail after the @@ -74,41 +153,26 @@ class IDBObjectStore extends js.Object { * @return * [[IDBRequest]] with the key as the `target` value */ - def add(value: Any, key: Any = js.native): IDBRequest[Any] = js.native + def add(value: IDBValue, key: IDBKey = js.native): IDBRequest[IDBObjectStore, IDBKey] = js.native /** Clearing an object store consists of removing all records from the object store and removing all records in * indexes that reference the object store. */ - def clear(): IDBRequest[Unit] = js.native + def clear(): IDBRequest[IDBObjectStore, Unit] = js.native /** Note that this method must be called only from a VersionChange transaction mode callback. */ - def createIndex(name: String, keyPath: Any, + def createIndex(name: String, keyPath: IDBKeyPath, optionalParameters: IDBCreateIndexOptions = js.native): IDBIndex = js.native - /** If the record is successfully stored, then a success event is fired on the returned request object with the result - * set to the key for the stored record, and the transaction set to the transaction in which this object store is - * opened. - * - * @return - * [[IDBRequest]] with the key as the `target` value - */ - def put(value: Any, key: Any = js.native): IDBRequest[Any] = js.native - - /** The method sets the position of the cursor to the appropriate record, based on the specified direction. + /** Returns an [[IDBRequest]] object, and, in a separate thread, deletes the specified record or records. * - * @return - * [[IDBRequest]] with the `target` value being a new cursor or `null`. - */ - def openCursor(range: js.UndefOr[IDBKeyRange | Any] = js.native, - direction: js.UndefOr[IDBCursorDirection] = js.native): IDBRequest[IDBCursor] = js.native - - /** The method sets the position of the cursor to the appropriate key, based on the specified direction. + * Either a key or an [[IDBKeyRange]] can be passed, allowing one or multiple records to be deleted from a store. To + * delete all records in a store, use [[clear()]]. * - * @return - * [[IDBRequest]] with the `target` value being a new cursor or `null`. + * Bear in mind that if you are using an [[IDBCursor]], you can use the [[IDBCursor.delete()]] method to more + * efficiently delete the current record — without having to explicitly look up the record's key. */ - def openKeyCursor(range: js.UndefOr[IDBKeyRange | Any] = js.native, - direction: js.UndefOr[IDBCursorDirection] = js.native): IDBRequest[IDBCursorReadOnly] = js.native + def delete(key: IDBKey | IDBKeyRange): IDBRequest[IDBObjectStore, Unit] = js.native /** Note that this method must be called only from a VersionChange transaction mode callback. Note that this method * synchronously modifies the IDBObjectStore.indexNames property. @@ -118,30 +182,20 @@ class IDBObjectStore extends js.Object { /** This method may raise a DOMException of one of the following types: */ def index(name: String): IDBIndex = js.native - /** If a value is successfully found, then a structured clone of it is created and set as the result of the request - * object. - */ - def get(key: Any): IDBRequest[Any] = js.native - - /** If a value is successfully found, then a structured clone of it is created and set as the result of the request - * object. - */ - def getAll(query: js.UndefOr[IDBKeyRange | Any] = js.native, - count: js.UndefOr[Int] = js.native): IDBRequest[js.Array[Any]] = js.native - - /** If a value is successfully found, then a structured clone of it is created and set as the result of the request - * object. - */ - def getAllKeys(query: js.UndefOr[IDBKeyRange | Any] = js.native, - count: js.UndefOr[Int] = js.native): IDBRequest[js.Array[Any]] = js.native + /** A list of the names of indexes on objects in this object store. */ + def indexNames: DOMStringList = js.native - /** If a value is successfully found, then a structured clone of it is created and set as the result of the request - * object. + /** If the record is successfully stored, then a success event is fired on the returned request object with the result + * set to the key for the stored record, and the transaction set to the transaction in which this object store is + * opened. + * + * @return + * [[IDBRequest]] with the key as the `target` value */ - def getKey(key: Any): IDBRequest[js.UndefOr[Any]] = js.native + def put(value: IDBValue, key: IDBKey = js.native): IDBRequest[IDBObjectStore, IDBKey] = js.native - /** returns an IDBRequest object, and, in a separate thread, deletes the current object store. */ - def delete(key: Any): IDBRequest[Unit] = js.native + /** The name of the transaction to which this object store belongs. */ + def transaction: IDBTransaction = js.native } trait IDBVersionChangeEventInit extends EventInit { @@ -183,52 +237,21 @@ class IDBVersionChangeEvent(typeArg: String, init: js.UndefOr[IDBVersionChangeEv */ @js.native @JSGlobal -class IDBIndex extends js.Object { - - /** If true, this index does not allow duplicate values for a key. */ - def unique: Boolean = js.native - - def name: String = js.native - - /** The key path of this index. If null, this index is not auto-populated. */ - def keyPath: String = js.native +class IDBIndex extends IDBStoreLike[IDBIndex] { /** The name of the object store referenced by this index. */ def objectStore: IDBObjectStore = js.native - def count(key: Any): IDBRequest[Int] = js.native - - /** If you want to see how many records are between keys 1000 and 2000 in an object store, you can write the - * following: - */ - def count(): IDBRequest[Int] = js.native - - /** Returns an IDBRequest object, and, in a separate thread, finds either the value in the referenced object store - * that corresponds to the given key or the first corresponding value, if key is a key range. - */ - def get(key: Any): IDBRequest[Any] = js.native - - /** Returns an IDBRequest object, and, in a separate thread, finds either the given key or the primary key, if key is - * a key range. - */ - def getKey(key: Any): IDBRequest[js.UndefOr[Any]] = js.native - - /** The method sets the position of the cursor to the appropriate record, based on the specified direction. + /** Returns a boolean value that affects how the index behaves when the result of evaluating the index's key path + * yields an array. * - * @return - * [[IDBRequest]] with the `target` value being a new cursor or `null`. + * This is decided when the index is created, using the `IDBObjectStore.createIndex` method. This method takes an + * optional options parameter whose `multiEntry` property is set to `true`/`false`. */ - def openCursor(range: IDBKeyRange = js.native, - direction: IDBCursorDirection = js.native): IDBRequest[IDBCursor] = js.native + val multiEntry: Boolean = js.native - /** Returns an IDBRequest object, and, in a separate thread, creates a cursor over the specified key range, as - * arranged by this index. - * - * @return - * [[IDBRequest]] with the `target` value being a new cursor or `null`. - */ - def openKeyCursor(range: IDBKeyRange = js.native, - direction: IDBCursorDirection = js.native): IDBRequest[IDBCursorReadOnly] = js.native + /** If true, this index does not allow duplicate values for a key. */ + def unique: Boolean = js.native } /** The IDBCursor interface of the IndexedDB API represents a cursor for traversing or iterating over multiple records @@ -240,13 +263,13 @@ class IDBIndex extends js.Object { */ @js.native @JSGlobal -class IDBCursorReadOnly extends js.Object { +class IDBCursorReadOnly[+S] extends js.Object { /** On getting, this object returns the IDBObjectStore or IDBIndex that the cursor is iterating. This function never * returns null or throws an exception, even if the cursor is currently being iterated, has iterated past its end, or * its transaction is not active. */ - def source: Any = js.native + def source: S = js.native /** Is a DOMString that, on getting, returns the direction of traversal of the cursor. See Constants for possible * values. @@ -256,12 +279,12 @@ class IDBCursorReadOnly extends js.Object { /** Returns the key for the record at the cursor's position. If the cursor is outside its range, this is set to * undefined. The cursor's key can be any data type. */ - def key: Any = js.native + def key: IDBKey = js.native /** Returns the cursor's current effective key. If the cursor is currently being iterated or has iterated outside its * range, this is set to undefined. The cursor's primary key can be any data type. */ - def primaryKey: Any = js.native + def primaryKey: IDBKey = js.native /** This method may raise a DOMException of one of the following types: */ def advance(count: Int): Unit = js.native @@ -274,7 +297,7 @@ class IDBCursorReadOnly extends js.Object { * * W3C */ - def continue(key: Any = js.native): Unit = js.native + def continue(key: IDBKey = js.native): Unit = js.native } /** The IDBCursor interface of the IndexedDB API represents a cursor for traversing or iterating over multiple records @@ -286,17 +309,17 @@ class IDBCursorReadOnly extends js.Object { */ @js.native @JSGlobal -class IDBCursor extends IDBCursorReadOnly { +class IDBCursor[+S] extends IDBCursorReadOnly[S] { /** Returns an IDBRequest object, and, in a separate thread, deletes the record at the cursor's position, without * changing the cursor's position. */ - def delete(): IDBRequest[Unit] = js.native + def delete(): IDBRequest[S, Unit] = js.native /** Returns an IDBRequest object, and, in a separate thread, updates the value at the current position of the cursor * in the object store. */ - def update(value: Any): IDBRequest[Any] = js.native + def update(value: IDBValue): IDBRequest[S, IDBKey] = js.native } @js.native @@ -307,29 +330,29 @@ object IDBCursorDirection { /** The cursor shows all records, including duplicates. It starts at the upper bound of the key range and moves * downwards (monotonically decreasing in the order of keys). */ - val PREV: IDBCursorDirection = "prev".asInstanceOf[IDBCursorDirection] + @inline def prev: IDBCursorDirection = "prev".asInstanceOf[IDBCursorDirection] /** The cursor shows all records, excluding duplicates. If multiple records exist with the same key, only the first * one iterated is retrieved. It starts at the upper bound of the key range and moves downwards. */ - val PREV_UNIQUE: IDBCursorDirection = "prevunique".asInstanceOf[IDBCursorDirection] + @inline def prevunique: IDBCursorDirection = "prevunique".asInstanceOf[IDBCursorDirection] /** The cursor shows all records, including duplicates. It starts at the lower bound of the key range and moves * upwards (monotonically increasing in the order of keys). */ - val NEXT: IDBCursorDirection = "next".asInstanceOf[IDBCursorDirection] + @inline def next: IDBCursorDirection = "next".asInstanceOf[IDBCursorDirection] /** The cursor shows all records, excluding duplicates. If multiple records exist with the same key, only the first * one iterated is retrieved. It starts at the lower bound of the key range and moves upwards. */ - val NEXT_UNIQUE: IDBCursorDirection = "nextunique".asInstanceOf[IDBCursorDirection] + @inline def nextunique: IDBCursorDirection = "nextunique".asInstanceOf[IDBCursorDirection] } /** Same as IDBCursor with the value property. */ @js.native @JSGlobal class IDBCursorWithValue extends IDBCursor { - def value: Any = js.native + def value: IDBValue = js.native } /** The IDBKeyRange interface of the IndexedDB API represents a continuous interval over some data type that is used for @@ -346,13 +369,13 @@ class IDBCursorWithValue extends IDBCursor { class IDBKeyRange extends js.Object { /** The upper bound of the key range (can be any type.) */ - def upper: Any = js.native + def upper: IDBKey = js.native /** Returns false if the upper-bound value is included in the key range. */ def upperOpen: Boolean = js.native /** The lower bound of the key range (can be any type.) */ - def lower: Any = js.native + def lower: IDBKey = js.native /** Returns false if the lower-bound value is included in the key range. */ def lowerOpen: Boolean = js.native @@ -365,17 +388,17 @@ object IDBKeyRange extends js.Object { /** The bounds can be open (that is, the bounds exclude the endpoint values) or closed (that is, the bounds include * the endpoint values). By default, the bounds are closed. */ - def bound(lower: Any, upper: Any, lowerOpen: Boolean = js.native, + def bound(lower: IDBKey, upper: IDBKey, lowerOpen: Boolean = js.native, upperOpen: Boolean = js.native): IDBKeyRange = js.native /** This method may raise a DOMException of the following types: */ - def only(value: Any): IDBKeyRange = js.native + def only(value: IDBValue): IDBKeyRange = js.native /** By default, it includes the lower endpoint value and is closed. */ - def lowerBound(bound: Any, open: Boolean = js.native): IDBKeyRange = js.native + def lowerBound(bound: IDBKey, open: Boolean = js.native): IDBKeyRange = js.native /** By default, it includes the upper endpoint value and is closed. */ - def upperBound(bound: Any, open: Boolean = js.native): IDBKeyRange = js.native + def upperBound(bound: IDBKey, open: Boolean = js.native): IDBKeyRange = js.native } /** The IDBTransaction interface of the IndexedDB API provides a static, asynchronous transaction on a database using @@ -474,7 +497,8 @@ class IDBDatabase extends EventTarget { /** Immediately returns a transaction object (IDBTransaction) containing the IDBTransaction.objectStore method, which * you can use to access your object store. Runs in a separate thread. */ - def transaction(storeNames: Any, mode: IDBTransactionMode = js.native): IDBTransaction = js.native + def transaction(storeNames: String | js.Array[String], mode: js.UndefOr[IDBTransactionMode] = js.native, + options: js.UndefOr[IDBTransactionOptions] = js.native): IDBTransaction = js.native /** As with createObjectStore, this method can be called only within a versionchange transaction. So for WebKit * browsers you must call the IDBVersionChangeRequest.setVersion method first before you can remove any object store @@ -485,10 +509,13 @@ class IDBDatabase extends EventTarget { /** The IDBOpenDBRequest interface of the IndexedDB API provides access to results of requests to open databases using * specific event handler attributes. + * + * @tparam A + * Type of `.target.result` on events */ @js.native @JSGlobal -class IDBOpenDBRequest[A] extends IDBRequest[A] { +class IDBOpenDBRequest[A] extends IDBRequest[Null, A] { /** The event handler for the upgradeneeded event, fired when a database of a bigger version number than the existing * stored database is loaded. @@ -520,8 +547,16 @@ class IDBFactory extends js.Object { */ def open(name: String, version: Int = js.native): IDBOpenDBRequest[IDBDatabase] = js.native - /** A method that compares two keys and returns a result indicating which one is greater in value. */ - def cmp(first: Any, second: Any): Int = js.native + /** Compares two values as keys to determine equality and ordering for IndexedDB operations, such as storing and + * iterating. + * + * @return + * One of the following: + * - `-1` means 1st key is less than the 2nd key + * - `0` means 1st key is equal to the 2nd key + * - `1` means 1st key is greater than the 2nd key + */ + def cmp(first: IDBValue, second: IDBValue): Int = js.native /** Returns a promise which resolves to a list of objects giving a snapshot of the names and versions of databases * within the origin. @@ -544,15 +579,18 @@ class IDBFactory extends js.Object { * The request object does not initially contain any information about the result of the operation, but once * information becomes available, an event is fired on the request, and the information becomes available through the * properties of the IDBRequest instance. + * + * @tparam A + * Type of `.target.result` on events */ @js.native @JSGlobal -class IDBRequest[A] extends EventTarget { +class IDBRequest[+S, A] extends EventTarget { /** The source of the request, such as an Index or a ObjectStore. If no source exists (such as when calling * IDBFactory.open), it returns null. */ - def source: Any = js.native + def source: S = js.native /** The event handler for the success event. */ var onsuccess: js.Function1[IDBEvent[A], _] = js.native @@ -586,7 +624,7 @@ trait IDBDatabaseInfo extends js.Object { } trait IDBCreateObjectStoreOptions extends js.Object { - val keyPath: Any = js.undefined + val keyPath: IDBKeyPath = js.undefined val autoIncrement: js.UndefOr[Boolean] = js.undefined } @@ -596,6 +634,10 @@ trait IDBCreateIndexOptions extends js.Object { val locale: js.UndefOr[String] = js.undefined } +trait IDBTransactionOptions extends js.Object { + val durability: js.UndefOr[IDBTransactionDurability] = js.undefined +} + /** The IDBEvironment interface of the IndexedDB API provides asynchronous access to a client-side database. It is * implemented by window and Worker objects. */ diff --git a/src/main/scala/org/scalajs/dom/idb.scala b/src/main/scala/org/scalajs/dom/idb.scala index bc7b9916b..edd779ac7 100644 --- a/src/main/scala/org/scalajs/dom/idb.scala +++ b/src/main/scala/org/scalajs/dom/idb.scala @@ -2,11 +2,11 @@ package org.scalajs.dom /** Short aliases of all the dom.IDBThing classes */ object idb { + type CreateIndexOptions = IDBCreateIndexOptions type CreateObjectStoreOptions = IDBCreateObjectStoreOptions - type Cursor = IDBCursor - @inline def CursorDirection = IDBCursorDirection - type CursorReadOnly = IDBCursorReadOnly + type Cursor[+Source] = IDBCursor[Source] + type CursorReadOnly[+Source] = IDBCursorReadOnly[Source] type CursorWithValue = IDBCursorWithValue type Database = IDBDatabase type DatabaseInfo = IDBDatabaseInfo @@ -14,15 +14,20 @@ object idb { type EventTarget[+A] = IDBEventTarget[A] type Factory = IDBFactory type Index = IDBIndex + type Key = IDBKey + type KeyPath = IDBKeyPath type KeyRange = IDBKeyRange - @inline def KeyRange = IDBKeyRange type ObjectStore = IDBObjectStore type OpenDBRequest[A] = IDBOpenDBRequest[A] - type Request[A] = IDBRequest[A] + type Request[+Source, A] = IDBRequest[Source, A] type Transaction = IDBTransaction - @inline def TransactionMode = IDBTransactionMode + type Value = IDBValue type VersionChangeEvent = IDBVersionChangeEvent + @inline def CursorDirection = IDBCursorDirection + @inline def KeyRange = IDBKeyRange + @inline def TransactionMode = IDBTransactionMode + @deprecated( "Removed. This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible. See https://developer.mozilla.org/en-US/docs/Web/API/IDBEnvironment", "1.2.0") diff --git a/src/main/scala/org/scalajs/dom/package.scala b/src/main/scala/org/scalajs/dom/package.scala index d6603ba70..e432e4d1f 100644 --- a/src/main/scala/org/scalajs/dom/package.scala +++ b/src/main/scala/org/scalajs/dom/package.scala @@ -71,4 +71,16 @@ package object dom { @deprecated("use NodeList[T] instead", "2.0.0") type NodeListOf[+T <: Node] = NodeList[T] + + type IDBKey = Any + + /** A valid key path can include one of the following: an empty string, a JavaScript identifier, or multiple + * JavaScript identifiers separated by periods or an array containing any of those. It cannot include spaces. + * + * @see + * https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Basic_Terminology#key_path + */ + type IDBKeyPath = Any + + type IDBValue = Any } diff --git a/src/main/scala/org/scalajs/dom/raw.scala b/src/main/scala/org/scalajs/dom/raw.scala index eca06ce62..a8b65b186 100644 --- a/src/main/scala/org/scalajs/dom/raw.scala +++ b/src/main/scala/org/scalajs/dom/raw.scala @@ -9,6 +9,7 @@ package org.scalajs.dom import org.scalajs.dom import scala.scalajs.js import scala.scalajs.js.annotation._ +import scala.scalajs.js.| @deprecated("All the members of raw.* have been moved to dom.*", "2.0.0") object raw { @@ -479,7 +480,7 @@ object raw { type HTMLVideoElement = dom.HTMLVideoElement @deprecated("use dom.IDBCursor instead", "2.0.0") - type IDBCursor = dom.IDBCursor + type IDBCursor = dom.IDBCursor[IDBObjectStore | IDBIndex] @deprecated("use dom.IDBCursorWithValue instead", "2.0.0") type IDBCursorWithValue = dom.IDBCursorWithValue @@ -506,10 +507,10 @@ object raw { type IDBObjectStore = dom.IDBObjectStore @deprecated("use dom.IDBOpenDBRequest instead", "2.0.0") - type IDBOpenDBRequest = dom.IDBOpenDBRequest[js.Any] + type IDBOpenDBRequest = dom.IDBOpenDBRequest[Any] @deprecated("use dom.IDBRequest instead", "2.0.0") - type IDBRequest = dom.IDBRequest[js.Any] + type IDBRequest = dom.IDBRequest[Any, Any] @deprecated("use dom.IDBTransaction instead", "2.0.0") type IDBTransaction = dom.IDBTransaction diff --git a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala index d89da8781..c3952e4f3 100644 --- a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala +++ b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala @@ -62,10 +62,10 @@ object IdbTest { db.close() } - def getFirstName(r: IDBRequest[Any]): Future[String] = { + def getFirstName(r: IDBRequest[_, IDBValue]): Future[String] = { val p = Promise[String]() r.onerror = (e: Event) => fail(p, e) - r.onsuccess = (e: IDBEvent[Any]) => { + r.onsuccess = (e: IDBEvent[IDBValue]) => { p.complete(Try(e.target.result.asInstanceOf[js.Dynamic].name.first.asInstanceOf[String])) } p.future From af0c635c60f25e81708de0aec20d2ed3c6a9a35f Mon Sep 17 00:00:00 2001 From: David Barri Date: Thu, 9 Sep 2021 10:02:26 +1000 Subject: [PATCH 5/8] Clarify type parameter meanings in type aliases --- api-reports/2_12.txt | 8 ++++---- api-reports/2_13.txt | 8 ++++---- src/main/scala/org/scalajs/dom/idb.scala | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 9c02f1a08..54f942ac4 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -25619,16 +25619,16 @@ idb[SO] type Cursor[+Source] = IDBCursor[Source] idb[SO] type Database = IDBDatabase idb[SO] type DatabaseInfo = IDBDatabaseInfo idb[SO] type Environment = IDBEnvironment (@deprecated in 1.2.0) -idb[SO] type EventTarget[+A] = IDBEventTarget[A] -idb[SO] type Event[+A] = IDBEvent[A] +idb[SO] type EventTarget[+Result] = IDBEventTarget[Result] +idb[SO] type Event[+TargetResult] = IDBEvent[TargetResult] idb[SO] type Factory = IDBFactory idb[SO] type Index = IDBIndex idb[SO] type Key = IDBKey idb[SO] type KeyPath = IDBKeyPath idb[SO] type KeyRange = IDBKeyRange idb[SO] type ObjectStore = IDBObjectStore -idb[SO] type OpenDBRequest[A] = IDBOpenDBRequest[A] -idb[SO] type Request[+Source, A] = IDBRequest[Source, A] +idb[SO] type OpenDBRequest[TargetResult] = IDBOpenDBRequest[TargetResult] +idb[SO] type Request[+Source, TargetResult] = IDBRequest[Source, TargetResult] idb[SO] type Transaction = IDBTransaction idb[SO] type Value = IDBValue idb[SO] type VersionChangeEvent = IDBVersionChangeEvent diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 9c02f1a08..54f942ac4 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -25619,16 +25619,16 @@ idb[SO] type Cursor[+Source] = IDBCursor[Source] idb[SO] type Database = IDBDatabase idb[SO] type DatabaseInfo = IDBDatabaseInfo idb[SO] type Environment = IDBEnvironment (@deprecated in 1.2.0) -idb[SO] type EventTarget[+A] = IDBEventTarget[A] -idb[SO] type Event[+A] = IDBEvent[A] +idb[SO] type EventTarget[+Result] = IDBEventTarget[Result] +idb[SO] type Event[+TargetResult] = IDBEvent[TargetResult] idb[SO] type Factory = IDBFactory idb[SO] type Index = IDBIndex idb[SO] type Key = IDBKey idb[SO] type KeyPath = IDBKeyPath idb[SO] type KeyRange = IDBKeyRange idb[SO] type ObjectStore = IDBObjectStore -idb[SO] type OpenDBRequest[A] = IDBOpenDBRequest[A] -idb[SO] type Request[+Source, A] = IDBRequest[Source, A] +idb[SO] type OpenDBRequest[TargetResult] = IDBOpenDBRequest[TargetResult] +idb[SO] type Request[+Source, TargetResult] = IDBRequest[Source, TargetResult] idb[SO] type Transaction = IDBTransaction idb[SO] type Value = IDBValue idb[SO] type VersionChangeEvent = IDBVersionChangeEvent diff --git a/src/main/scala/org/scalajs/dom/idb.scala b/src/main/scala/org/scalajs/dom/idb.scala index edd779ac7..7cb7a65c3 100644 --- a/src/main/scala/org/scalajs/dom/idb.scala +++ b/src/main/scala/org/scalajs/dom/idb.scala @@ -10,16 +10,16 @@ object idb { type CursorWithValue = IDBCursorWithValue type Database = IDBDatabase type DatabaseInfo = IDBDatabaseInfo - type Event[+A] = IDBEvent[A] - type EventTarget[+A] = IDBEventTarget[A] + type Event[+TargetResult] = IDBEvent[TargetResult] + type EventTarget[+Result] = IDBEventTarget[Result] type Factory = IDBFactory type Index = IDBIndex type Key = IDBKey type KeyPath = IDBKeyPath type KeyRange = IDBKeyRange type ObjectStore = IDBObjectStore - type OpenDBRequest[A] = IDBOpenDBRequest[A] - type Request[+Source, A] = IDBRequest[Source, A] + type OpenDBRequest[TargetResult] = IDBOpenDBRequest[TargetResult] + type Request[+Source, TargetResult] = IDBRequest[Source, TargetResult] type Transaction = IDBTransaction type Value = IDBValue type VersionChangeEvent = IDBVersionChangeEvent From d3dbba7c8244629ae076d544fac2396f0d3bbd5b Mon Sep 17 00:00:00 2001 From: David Barri Date: Thu, 9 Sep 2021 10:06:37 +1000 Subject: [PATCH 6/8] Fix ScalaDoc --- src/main/scala/org/scalajs/dom/IDBTypes.scala | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/scala/org/scalajs/dom/IDBTypes.scala b/src/main/scala/org/scalajs/dom/IDBTypes.scala index a496b5b37..d70314af5 100644 --- a/src/main/scala/org/scalajs/dom/IDBTypes.scala +++ b/src/main/scala/org/scalajs/dom/IDBTypes.scala @@ -67,7 +67,7 @@ trait IDBStoreLike[S] extends js.Object { * key. This is for retrieving specific records from an object store. * * Note: This method produces the same result for: a) a record that doesn't exist in the database and b) a record - * that has an undefined value. To tell these situations apart, call the [[openCursor()]] method with the same key. + * that has an undefined value. To tell these situations apart, call the [[openCursor]] method with the same key. * That method provides a cursor if the record exists, and no cursor if it does not. */ def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] = js.native @@ -85,9 +85,9 @@ trait IDBStoreLike[S] extends js.Object { * * To tell these situations apart, you either call * - * - the [[openCursor()]] method with the same key. That method provides a cursor if the record exists, and no - * cursor if it does not. - * - the [[count()]] method with the same key, which will return 1 if the row exists and 0 if it doesn't. + * - the [[openCursor]] method with the same key. That method provides a cursor if the record exists, and no cursor + * if it does not. + * - the [[count]] method with the same key, which will return 1 if the row exists and 0 if it doesn't. */ def getAll(query: js.UndefOr[IDBKeyRange | IDBKey] = js.native, count: js.UndefOr[Int] = js.native): IDBRequest[S, js.Array[IDBValue]] = js.native @@ -103,8 +103,8 @@ trait IDBStoreLike[S] extends js.Object { * - a record that doesn't exist in the database * - a record that has an undefined value * - * To tell these situations apart, you need to call the [[openCursor()]] method with the same key. That method - * provides a cursor if the record exists, and no cursor if it does not. + * To tell these situations apart, you need to call the [[openCursor]] method with the same key. That method provides + * a cursor if the record exists, and no cursor if it does not. */ def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey] = js.native, count: js.UndefOr[Int] = js.native): IDBRequest[S, js.Array[IDBKey]] = js.native @@ -167,9 +167,9 @@ class IDBObjectStore extends IDBStoreLike[IDBObjectStore] { /** Returns an [[IDBRequest]] object, and, in a separate thread, deletes the specified record or records. * * Either a key or an [[IDBKeyRange]] can be passed, allowing one or multiple records to be deleted from a store. To - * delete all records in a store, use [[clear()]]. + * delete all records in a store, use [[clear]]. * - * Bear in mind that if you are using an [[IDBCursor]], you can use the [[IDBCursor.delete()]] method to more + * Bear in mind that if you are using an [[IDBCursor]], you can use the [[IDBCursor.delete]] method to more * efficiently delete the current record — without having to explicitly look up the record's key. */ def delete(key: IDBKey | IDBKeyRange): IDBRequest[IDBObjectStore, Unit] = js.native From 25e77831ad2f0d2fbf06d7dd421053a093579edd Mon Sep 17 00:00:00 2001 From: David Barri Date: Thu, 9 Sep 2021 10:16:43 +1000 Subject: [PATCH 7/8] Bugfix, thanks CI --- api-reports/2_12.txt | 4 ++-- api-reports/2_13.txt | 4 ++-- src/main/scala/org/scalajs/dom/IDBTypes.scala | 14 ++++++++++++-- src/main/scala/org/scalajs/dom/idb.scala | 2 +- src/main/scala/org/scalajs/dom/raw.scala | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 54f942ac4..50d733e54 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -25614,7 +25614,7 @@ html[SO] def Media = HTMLMediaElement idb[SO] type CreateIndexOptions = IDBCreateIndexOptions idb[SO] type CreateObjectStoreOptions = IDBCreateObjectStoreOptions idb[SO] type CursorReadOnly[+Source] = IDBCursorReadOnly[Source] -idb[SO] type CursorWithValue = IDBCursorWithValue +idb[SO] type CursorWithValue[+Source] = IDBCursorWithValue[Source] idb[SO] type Cursor[+Source] = IDBCursor[Source] idb[SO] type Database = IDBDatabase idb[SO] type DatabaseInfo = IDBDatabaseInfo @@ -25799,7 +25799,7 @@ raw[SO] type HTMLVideoElement = dom.HTMLVideoElement (@deprecated in 2.0.0) raw[SO] type HashChangeEvent = dom.HashChangeEvent (@deprecated in 2.0.0) raw[SO] type History = dom.History (@deprecated in 2.0.0) raw[SO] type IDBCursor = dom.IDBCursor[IDBObjectStore | IDBIndex] (@deprecated in 2.0.0) -raw[SO] type IDBCursorWithValue = dom.IDBCursorWithValue (@deprecated in 2.0.0) +raw[SO] type IDBCursorWithValue = dom.IDBCursorWithValue[Any] (@deprecated in 2.0.0) raw[SO] type IDBDatabase = dom.IDBDatabase (@deprecated in 2.0.0) raw[SO] type IDBEnvironment = dom.IDBEnvironment (@deprecated in 2.0.0) raw[SO] type IDBFactory = dom.IDBFactory (@deprecated in 2.0.0) diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 54f942ac4..50d733e54 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -25614,7 +25614,7 @@ html[SO] def Media = HTMLMediaElement idb[SO] type CreateIndexOptions = IDBCreateIndexOptions idb[SO] type CreateObjectStoreOptions = IDBCreateObjectStoreOptions idb[SO] type CursorReadOnly[+Source] = IDBCursorReadOnly[Source] -idb[SO] type CursorWithValue = IDBCursorWithValue +idb[SO] type CursorWithValue[+Source] = IDBCursorWithValue[Source] idb[SO] type Cursor[+Source] = IDBCursor[Source] idb[SO] type Database = IDBDatabase idb[SO] type DatabaseInfo = IDBDatabaseInfo @@ -25799,7 +25799,7 @@ raw[SO] type HTMLVideoElement = dom.HTMLVideoElement (@deprecated in 2.0.0) raw[SO] type HashChangeEvent = dom.HashChangeEvent (@deprecated in 2.0.0) raw[SO] type History = dom.History (@deprecated in 2.0.0) raw[SO] type IDBCursor = dom.IDBCursor[IDBObjectStore | IDBIndex] (@deprecated in 2.0.0) -raw[SO] type IDBCursorWithValue = dom.IDBCursorWithValue (@deprecated in 2.0.0) +raw[SO] type IDBCursorWithValue = dom.IDBCursorWithValue[Any] (@deprecated in 2.0.0) raw[SO] type IDBDatabase = dom.IDBDatabase (@deprecated in 2.0.0) raw[SO] type IDBEnvironment = dom.IDBEnvironment (@deprecated in 2.0.0) raw[SO] type IDBFactory = dom.IDBFactory (@deprecated in 2.0.0) diff --git a/src/main/scala/org/scalajs/dom/IDBTypes.scala b/src/main/scala/org/scalajs/dom/IDBTypes.scala index d70314af5..76dc7c240 100644 --- a/src/main/scala/org/scalajs/dom/IDBTypes.scala +++ b/src/main/scala/org/scalajs/dom/IDBTypes.scala @@ -260,6 +260,9 @@ class IDBIndex extends IDBStoreLike[IDBIndex] { * The cursor has a source that indicates which index or object store it is iterating. It has a position within the * range, and moves in a direction that is increasing or decreasing in the order of record keys. The cursor enables an * application to asynchronously process all the records in the cursor's range. + * + * @tparam S + * The type of `.source` */ @js.native @JSGlobal @@ -306,6 +309,9 @@ class IDBCursorReadOnly[+S] extends js.Object { * The cursor has a source that indicates which index or object store it is iterating. It has a position within the * range, and moves in a direction that is increasing or decreasing in the order of record keys. The cursor enables an * application to asynchronously process all the records in the cursor's range. + * + * @tparam S + * The type of `.source` */ @js.native @JSGlobal @@ -348,10 +354,14 @@ object IDBCursorDirection { @inline def nextunique: IDBCursorDirection = "nextunique".asInstanceOf[IDBCursorDirection] } -/** Same as IDBCursor with the value property. */ +/** Same as [[IDBCursor]] with the `value` property. + * + * @tparam S + * The type of `.source` + */ @js.native @JSGlobal -class IDBCursorWithValue extends IDBCursor { +class IDBCursorWithValue[+S] extends IDBCursor[S] { def value: IDBValue = js.native } diff --git a/src/main/scala/org/scalajs/dom/idb.scala b/src/main/scala/org/scalajs/dom/idb.scala index 7cb7a65c3..12ed55a2f 100644 --- a/src/main/scala/org/scalajs/dom/idb.scala +++ b/src/main/scala/org/scalajs/dom/idb.scala @@ -7,7 +7,7 @@ object idb { type CreateObjectStoreOptions = IDBCreateObjectStoreOptions type Cursor[+Source] = IDBCursor[Source] type CursorReadOnly[+Source] = IDBCursorReadOnly[Source] - type CursorWithValue = IDBCursorWithValue + type CursorWithValue[+Source] = IDBCursorWithValue[Source] type Database = IDBDatabase type DatabaseInfo = IDBDatabaseInfo type Event[+TargetResult] = IDBEvent[TargetResult] diff --git a/src/main/scala/org/scalajs/dom/raw.scala b/src/main/scala/org/scalajs/dom/raw.scala index a8b65b186..8adcc480e 100644 --- a/src/main/scala/org/scalajs/dom/raw.scala +++ b/src/main/scala/org/scalajs/dom/raw.scala @@ -483,7 +483,7 @@ object raw { type IDBCursor = dom.IDBCursor[IDBObjectStore | IDBIndex] @deprecated("use dom.IDBCursorWithValue instead", "2.0.0") - type IDBCursorWithValue = dom.IDBCursorWithValue + type IDBCursorWithValue = dom.IDBCursorWithValue[Any] @deprecated("use dom.IDBDatabase instead", "2.0.0") type IDBDatabase = dom.IDBDatabase From fec80ff6789b7e2ade50783196487750505cd625 Mon Sep 17 00:00:00 2001 From: David Barri Date: Thu, 9 Sep 2021 10:29:54 +1000 Subject: [PATCH 8/8] Whoops, counts should be Doubles cos 2^32 is 2^64 signed --- api-reports/2_12.txt | 24 +++++++++---------- api-reports/2_13.txt | 24 +++++++++---------- src/main/scala/org/scalajs/dom/IDBTypes.scala | 8 +++---- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 50d733e54..d61d01552 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -13535,7 +13535,7 @@ IDBCreateIndexOptions[JT] val multiEntry: js.UndefOr[Boolean] IDBCreateIndexOptions[JT] val unique: js.UndefOr[Boolean] IDBCreateObjectStoreOptions[JT] val autoIncrement: js.UndefOr[Boolean] IDBCreateObjectStoreOptions[JT] val keyPath: IDBKeyPath -IDBCursor[JC] def advance(count: Int): Unit +IDBCursor[JC] def advance(count: Double): Unit IDBCursor[JC] def continue(key: IDBKey?): Unit IDBCursor[JC] def delete(): IDBRequest[S, Unit] IDBCursor[JC] def direction: IDBCursorDirection @@ -13548,13 +13548,13 @@ IDBCursorDirection[SO] def next: IDBCursorDirection IDBCursorDirection[SO] def nextunique: IDBCursorDirection IDBCursorDirection[SO] def prev: IDBCursorDirection IDBCursorDirection[SO] def prevunique: IDBCursorDirection -IDBCursorReadOnly[JC] def advance(count: Int): Unit +IDBCursorReadOnly[JC] def advance(count: Double): Unit IDBCursorReadOnly[JC] def continue(key: IDBKey?): Unit IDBCursorReadOnly[JC] def direction: IDBCursorDirection IDBCursorReadOnly[JC] def key: IDBKey IDBCursorReadOnly[JC] def primaryKey: IDBKey IDBCursorReadOnly[JC] def source: S -IDBCursorWithValue[JC] def advance(count: Int): Unit +IDBCursorWithValue[JC] def advance(count: Double): Unit IDBCursorWithValue[JC] def continue(key: IDBKey?): Unit IDBCursorWithValue[JC] def delete(): IDBRequest[S, Unit] IDBCursorWithValue[JC] def direction: IDBCursorDirection @@ -13605,10 +13605,10 @@ IDBFactory[JC] def cmp(first: IDBValue, second: IDBValue): Int IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] -IDBIndex[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBIndex[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Double] IDBIndex[JC] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] -IDBIndex[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] -IDBIndex[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBIndex[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBValue]] +IDBIndex[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBKey]] IDBIndex[JC] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] IDBIndex[JC] def keyPath: IDBKeyPath IDBIndex[JC] val multiEntry: Boolean @@ -13627,13 +13627,13 @@ IDBKeyRange[JO] def only(value: IDBValue): IDBKeyRange IDBKeyRange[JO] def upperBound(bound: IDBKey, open: Boolean?): IDBKeyRange IDBObjectStore[JC] def add(value: IDBValue, key: IDBKey?): IDBRequest[IDBObjectStore, IDBKey] IDBObjectStore[JC] def clear(): IDBRequest[IDBObjectStore, Unit] -IDBObjectStore[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBObjectStore[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Double] IDBObjectStore[JC] def createIndex(name: String, keyPath: IDBKeyPath, optionalParameters: IDBCreateIndexOptions?): IDBIndex IDBObjectStore[JC] def delete(key: IDBKey | IDBKeyRange): IDBRequest[IDBObjectStore, Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit IDBObjectStore[JC] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] -IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] -IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBValue]] +IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBKey]] IDBObjectStore[JC] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] IDBObjectStore[JC] def index(name: String): IDBIndex IDBObjectStore[JC] def indexNames: DOMStringList @@ -13669,10 +13669,10 @@ IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js. IDBRequest[JC] def result: A IDBRequest[JC] def source: S IDBRequest[JC] def transaction: IDBTransaction -IDBStoreLike[JT] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBStoreLike[JT] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Double] IDBStoreLike[JT] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] -IDBStoreLike[JT] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] -IDBStoreLike[JT] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBStoreLike[JT] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBValue]] +IDBStoreLike[JT] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBKey]] IDBStoreLike[JT] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] IDBStoreLike[JT] def keyPath: IDBKeyPath IDBStoreLike[JT] def name: String diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 50d733e54..d61d01552 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -13535,7 +13535,7 @@ IDBCreateIndexOptions[JT] val multiEntry: js.UndefOr[Boolean] IDBCreateIndexOptions[JT] val unique: js.UndefOr[Boolean] IDBCreateObjectStoreOptions[JT] val autoIncrement: js.UndefOr[Boolean] IDBCreateObjectStoreOptions[JT] val keyPath: IDBKeyPath -IDBCursor[JC] def advance(count: Int): Unit +IDBCursor[JC] def advance(count: Double): Unit IDBCursor[JC] def continue(key: IDBKey?): Unit IDBCursor[JC] def delete(): IDBRequest[S, Unit] IDBCursor[JC] def direction: IDBCursorDirection @@ -13548,13 +13548,13 @@ IDBCursorDirection[SO] def next: IDBCursorDirection IDBCursorDirection[SO] def nextunique: IDBCursorDirection IDBCursorDirection[SO] def prev: IDBCursorDirection IDBCursorDirection[SO] def prevunique: IDBCursorDirection -IDBCursorReadOnly[JC] def advance(count: Int): Unit +IDBCursorReadOnly[JC] def advance(count: Double): Unit IDBCursorReadOnly[JC] def continue(key: IDBKey?): Unit IDBCursorReadOnly[JC] def direction: IDBCursorDirection IDBCursorReadOnly[JC] def key: IDBKey IDBCursorReadOnly[JC] def primaryKey: IDBKey IDBCursorReadOnly[JC] def source: S -IDBCursorWithValue[JC] def advance(count: Int): Unit +IDBCursorWithValue[JC] def advance(count: Double): Unit IDBCursorWithValue[JC] def continue(key: IDBKey?): Unit IDBCursorWithValue[JC] def delete(): IDBRequest[S, Unit] IDBCursorWithValue[JC] def direction: IDBCursorDirection @@ -13605,10 +13605,10 @@ IDBFactory[JC] def cmp(first: IDBValue, second: IDBValue): Int IDBFactory[JC] def databases(): js.Promise[js.Array[IDBDatabaseInfo]] IDBFactory[JC] def deleteDatabase(name: String): IDBOpenDBRequest[Unit] IDBFactory[JC] def open(name: String, version: Int?): IDBOpenDBRequest[IDBDatabase] -IDBIndex[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBIndex[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Double] IDBIndex[JC] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] -IDBIndex[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] -IDBIndex[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBIndex[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBValue]] +IDBIndex[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBKey]] IDBIndex[JC] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] IDBIndex[JC] def keyPath: IDBKeyPath IDBIndex[JC] val multiEntry: Boolean @@ -13627,13 +13627,13 @@ IDBKeyRange[JO] def only(value: IDBValue): IDBKeyRange IDBKeyRange[JO] def upperBound(bound: IDBKey, open: Boolean?): IDBKeyRange IDBObjectStore[JC] def add(value: IDBValue, key: IDBKey?): IDBRequest[IDBObjectStore, IDBKey] IDBObjectStore[JC] def clear(): IDBRequest[IDBObjectStore, Unit] -IDBObjectStore[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBObjectStore[JC] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Double] IDBObjectStore[JC] def createIndex(name: String, keyPath: IDBKeyPath, optionalParameters: IDBCreateIndexOptions?): IDBIndex IDBObjectStore[JC] def delete(key: IDBKey | IDBKeyRange): IDBRequest[IDBObjectStore, Unit] IDBObjectStore[JC] def deleteIndex(indexName: String): Unit IDBObjectStore[JC] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] -IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] -IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBObjectStore[JC] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBValue]] +IDBObjectStore[JC] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBKey]] IDBObjectStore[JC] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] IDBObjectStore[JC] def index(name: String): IDBIndex IDBObjectStore[JC] def indexNames: DOMStringList @@ -13669,10 +13669,10 @@ IDBRequest[JC] def removeEventListener[T <: Event](`type`: String, listener: js. IDBRequest[JC] def result: A IDBRequest[JC] def source: S IDBRequest[JC] def transaction: IDBTransaction -IDBStoreLike[JT] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Int] +IDBStoreLike[JT] def count(query: IDBKey | IDBKeyRange?): IDBRequest[S, Double] IDBStoreLike[JT] def get(key: IDBKey | IDBKeyRange): IDBRequest[S, IDBValue] -IDBStoreLike[JT] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBValue]] -IDBStoreLike[JT] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Int]?): IDBRequest[S, js.Array[IDBKey]] +IDBStoreLike[JT] def getAll(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBValue]] +IDBStoreLike[JT] def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey]?, count: js.UndefOr[Double]?): IDBRequest[S, js.Array[IDBKey]] IDBStoreLike[JT] def getKey(key: IDBKey): IDBRequest[S, js.UndefOr[IDBKey]] IDBStoreLike[JT] def keyPath: IDBKeyPath IDBStoreLike[JT] def name: String diff --git a/src/main/scala/org/scalajs/dom/IDBTypes.scala b/src/main/scala/org/scalajs/dom/IDBTypes.scala index 76dc7c240..2a196e41e 100644 --- a/src/main/scala/org/scalajs/dom/IDBTypes.scala +++ b/src/main/scala/org/scalajs/dom/IDBTypes.scala @@ -61,7 +61,7 @@ object IDBTransactionDurability { @js.native trait IDBStoreLike[S] extends js.Object { - def count(query: IDBKey | IDBKeyRange = js.native): IDBRequest[S, Int] = js.native + def count(query: IDBKey | IDBKeyRange = js.native): IDBRequest[S, Double] = js.native /** Returns an [[IDBRequest]] object, and, in a separate thread, returns the object store selected by the specified * key. This is for retrieving specific records from an object store. @@ -90,7 +90,7 @@ trait IDBStoreLike[S] extends js.Object { * - the [[count]] method with the same key, which will return 1 if the row exists and 0 if it doesn't. */ def getAll(query: js.UndefOr[IDBKeyRange | IDBKey] = js.native, - count: js.UndefOr[Int] = js.native): IDBRequest[S, js.Array[IDBValue]] = js.native + count: js.UndefOr[Double] = js.native): IDBRequest[S, js.Array[IDBValue]] = js.native /** Returns an [[IDBRequest]] object retrieves record keys for all objects in the object store matching the specified * parameter or all objects in the store if no parameters are given. @@ -107,7 +107,7 @@ trait IDBStoreLike[S] extends js.Object { * a cursor if the record exists, and no cursor if it does not. */ def getAllKeys(query: js.UndefOr[IDBKeyRange | IDBKey] = js.native, - count: js.UndefOr[Int] = js.native): IDBRequest[S, js.Array[IDBKey]] = js.native + count: js.UndefOr[Double] = js.native): IDBRequest[S, js.Array[IDBKey]] = js.native /** Returns an [[IDBRequest]] object, and, in a separate thread, returns the key selected by the specified query. This * is for retrieving specific records from an object store. @@ -290,7 +290,7 @@ class IDBCursorReadOnly[+S] extends js.Object { def primaryKey: IDBKey = js.native /** This method may raise a DOMException of one of the following types: */ - def advance(count: Int): Unit = js.native + def advance(count: Double): Unit = js.native /** Sets cursor to key if specified, otherwise advances cursor by one. *