Skip to content

Use opaque types for Scala 3 #592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13972,10 +13972,10 @@ IDBCursor[JC] def primaryKey: IDBKey
IDBCursor[JC] def source: S
IDBCursor[JC] def update(value: IDBValue): IDBRequest[S, IDBKey]
IDBCursorDirection[JT]
IDBCursorDirection[SO] def next: IDBCursorDirection
IDBCursorDirection[SO] def nextunique: IDBCursorDirection
IDBCursorDirection[SO] def prev: IDBCursorDirection
IDBCursorDirection[SO] def prevunique: IDBCursorDirection
IDBCursorDirection[SO] val next: IDBCursorDirection
IDBCursorDirection[SO] val nextunique: IDBCursorDirection
IDBCursorDirection[SO] val prev: IDBCursorDirection
IDBCursorDirection[SO] val prevunique: IDBCursorDirection
IDBCursorReadOnly[JC] def advance(count: Double): Unit
IDBCursorReadOnly[JC] def continue(key: IDBKey?): Unit
IDBCursorReadOnly[JC] def direction: IDBCursorDirection
Expand Down Expand Up @@ -14120,13 +14120,13 @@ 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
IDBTransactionDurability[SO] val default: IDBTransactionDurability
IDBTransactionDurability[SO] val relaxed: IDBTransactionDurability
IDBTransactionDurability[SO] val strict: IDBTransactionDurability
IDBTransactionMode[JT]
IDBTransactionMode[SO] def readonly: IDBTransactionMode
IDBTransactionMode[SO] def readwrite: IDBTransactionMode
IDBTransactionMode[SO] def versionchange: IDBTransactionMode
IDBTransactionMode[SO] val readonly: IDBTransactionMode
IDBTransactionMode[SO] val readwrite: IDBTransactionMode
IDBTransactionMode[SO] val versionchange: IDBTransactionMode
IDBTransactionOptions[JT] val durability: js.UndefOr[IDBTransactionDurability]
IDBVersionChangeEvent[JC] def bubbles: Boolean
IDBVersionChangeEvent[JC] def cancelBubble: Boolean
Expand Down
20 changes: 10 additions & 10 deletions api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13972,10 +13972,10 @@ IDBCursor[JC] def primaryKey: IDBKey
IDBCursor[JC] def source: S
IDBCursor[JC] def update(value: IDBValue): IDBRequest[S, IDBKey]
IDBCursorDirection[JT]
IDBCursorDirection[SO] def next: IDBCursorDirection
IDBCursorDirection[SO] def nextunique: IDBCursorDirection
IDBCursorDirection[SO] def prev: IDBCursorDirection
IDBCursorDirection[SO] def prevunique: IDBCursorDirection
IDBCursorDirection[SO] val next: IDBCursorDirection
IDBCursorDirection[SO] val nextunique: IDBCursorDirection
IDBCursorDirection[SO] val prev: IDBCursorDirection
IDBCursorDirection[SO] val prevunique: IDBCursorDirection
IDBCursorReadOnly[JC] def advance(count: Double): Unit
IDBCursorReadOnly[JC] def continue(key: IDBKey?): Unit
IDBCursorReadOnly[JC] def direction: IDBCursorDirection
Expand Down Expand Up @@ -14120,13 +14120,13 @@ 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
IDBTransactionDurability[SO] val default: IDBTransactionDurability
IDBTransactionDurability[SO] val relaxed: IDBTransactionDurability
IDBTransactionDurability[SO] val strict: IDBTransactionDurability
IDBTransactionMode[JT]
IDBTransactionMode[SO] def readonly: IDBTransactionMode
IDBTransactionMode[SO] def readwrite: IDBTransactionMode
IDBTransactionMode[SO] def versionchange: IDBTransactionMode
IDBTransactionMode[SO] val readonly: IDBTransactionMode
IDBTransactionMode[SO] val readwrite: IDBTransactionMode
IDBTransactionMode[SO] val versionchange: IDBTransactionMode
IDBTransactionOptions[JT] val durability: js.UndefOr[IDBTransactionDurability]
IDBVersionChangeEvent[JC] def bubbles: Boolean
IDBVersionChangeEvent[JC] def cancelBubble: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ 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).
*/
@inline def prev: IDBCursorDirection = "prev".asInstanceOf[IDBCursorDirection]
val 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.
*/
@inline def prevunique: IDBCursorDirection = "prevunique".asInstanceOf[IDBCursorDirection]
val 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).
*/
@inline def next: IDBCursorDirection = "next".asInstanceOf[IDBCursorDirection]
val 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.
*/
@inline def nextunique: IDBCursorDirection = "nextunique".asInstanceOf[IDBCursorDirection]
val nextunique: IDBCursorDirection = "nextunique".asInstanceOf[IDBCursorDirection]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.scalajs.js
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]
val default: IDBTransactionDurability = "default".asInstanceOf[IDBTransactionDurability]
val strict: IDBTransactionDurability = "strict".asInstanceOf[IDBTransactionDurability]
val relaxed: IDBTransactionDurability = "relaxed".asInstanceOf[IDBTransactionDurability]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ sealed trait IDBTransactionMode extends js.Any
object IDBTransactionMode {

/** Allows data to be read but not changed. It is the default transaction mode. */
@inline def readonly: 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.
*/
@inline def versionchange: IDBTransactionMode = "versionchange".asInstanceOf[IDBTransactionMode]
val versionchange: IDBTransactionMode = "versionchange".asInstanceOf[IDBTransactionMode]

/** Allows reading and writing of data in existing data stores to be changed. */
@inline def readwrite: IDBTransactionMode = "readwrite".asInstanceOf[IDBTransactionMode]
val readwrite: IDBTransactionMode = "readwrite".asInstanceOf[IDBTransactionMode]
}
15 changes: 15 additions & 0 deletions src/main/scala-3/org/scalajs/dom/ClientType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.scalajs.dom

import scala.scalajs.js

opaque type ClientType = String

object ClientType {
val window: ClientType = "window"

val worker: ClientType = "worker"

val sharedworker: ClientType = "sharedworker"

val all: ClientType = "all"
}
23 changes: 23 additions & 0 deletions src/main/scala-3/org/scalajs/dom/FrameType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.scalajs.dom

import scala.scalajs.js

opaque type FrameType = String

/** part of ServiceWorker
* [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#client-frametype ¶4.2.2 frameType]] of
* serviceWorker spec
*/
object FrameType {

/** The window client's global object's browsing context is an auxiliary browsing context. */
val auxiliary: FrameType = "auxiliary"

/** The window client's global object's browsing context is a top-level browsing context. */
val `top-level`: FrameType = "top-level"

/** The window client's global object's browsing context is a nested browsing context. */
val nested: FrameType = "nested"

val none: FrameType = "none"
}
34 changes: 34 additions & 0 deletions src/main/scala-3/org/scalajs/dom/IDBCursorDirection.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
* http://creativecommons.org/licenses/by-sa/2.5/
*
* Everything else is under the MIT License http://opensource.org/licenses/MIT
*/
package org.scalajs.dom

import scala.scalajs.js

opaque type IDBCursorDirection = js.Any

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"

/** 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 prevunique: IDBCursorDirection = "prevunique"

/** 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"

/** 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 nextunique: IDBCursorDirection = "nextunique"
}
17 changes: 17 additions & 0 deletions src/main/scala-3/org/scalajs/dom/IDBTransactionDurability.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
* http://creativecommons.org/licenses/by-sa/2.5/
*
* Everything else is under the MIT License http://opensource.org/licenses/MIT
*/
package org.scalajs.dom

import scala.scalajs.js

opaque type IDBTransactionDurability = String

object IDBTransactionDurability {
val default: IDBTransactionDurability = "default"
val strict: IDBTransactionDurability = "strict"
val relaxed: IDBTransactionDurability = "relaxed"
}
29 changes: 29 additions & 0 deletions src/main/scala-3/org/scalajs/dom/IDBTransactionMode.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
* http://creativecommons.org/licenses/by-sa/2.5/
*
* Everything else is under the MIT License http://opensource.org/licenses/MIT
*/
package org.scalajs.dom

import scala.scalajs.js

/** IndexedDB transaction mode Provides constants for IDB Transaction modes These constants have been removed from
* browser support and replaced by String values
*/
opaque type IDBTransactionMode = String

object IDBTransactionMode {

/** Allows data to be read but not changed. It is the default transaction mode. */
val readonly: IDBTransactionMode = "readonly"

/** 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"

/** Allows reading and writing of data in existing data stores to be changed. */
val readwrite: IDBTransactionMode = "readwrite"
}
21 changes: 21 additions & 0 deletions src/main/scala-3/org/scalajs/dom/KeyFormat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.scalajs.dom

import scala.scalajs.js

/** see [[http://www.w3.org/TR/WebCryptoAPI/#dfn-KeyFormat ¶14.2 Data Types]] in W3C spec */
opaque type KeyFormat = String

object KeyFormat {

/** An unformatted sequence of bytes. Intended for secret keys. */
val raw: KeyFormat = "raw"

/** The DER encoding of the PrivateKeyInfo structure from RFC 5208. */
val pkcs8: KeyFormat = "pkcs8"

/** The DER encoding of the SubjectPublicKeyInfo structure from RFC 5280. */
val spki: KeyFormat = "spki"

/** The key is a JsonWebKey dictionary encoded as a JavaScript object */
val jwk: KeyFormat = "jwk"
}
12 changes: 12 additions & 0 deletions src/main/scala-3/org/scalajs/dom/KeyType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.scalajs.dom

import scala.scalajs.js

/** see [[http://www.w3.org/TR/WebCryptoAPI/#cryptokey-interface ¶13 CryptoKey interface]] in W3C doc */
opaque type KeyType = String

object KeyType {
val public: KeyType = "public"
val `private`: KeyType = "private"
val secret: KeyType = "secret"
}
17 changes: 17 additions & 0 deletions src/main/scala-3/org/scalajs/dom/KeyUsage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.scalajs.dom

import scala.scalajs.js

/** See [[http://www.w3.org/TR/WebCryptoAPI/#cryptokey-interface ¶ 13. CryptoKey Interface]] of w3c spec */
opaque type KeyUsage = String

object KeyUsage {
val encrypt: KeyUsage = "encrypt"
val decrypt: KeyUsage = "decrypt"
val sign: KeyUsage = "sign"
val verify: KeyUsage = "verify"
val deriveKey: KeyUsage = "deriveKey"
val deriveBits: KeyUsage = "deriveBits"
val wrapKey: KeyUsage = "wrapKey"
val unwrapKey: KeyUsage = "unwrapKey"
}
15 changes: 15 additions & 0 deletions src/main/scala-3/org/scalajs/dom/MIMEType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.scalajs.dom

import scala.scalajs.js

opaque type MIMEType = String

object MIMEType {
val `text/html`: MIMEType = "text/html"
val `text/xml`: MIMEType = "text/xml"
val `application/xml`: MIMEType = "application/xml"

val `application/xhtml+xml`: MIMEType =
"application/xhtml+xml"
val `image/svg+xml`: MIMEType = "image/svg+xml"
}
19 changes: 19 additions & 0 deletions src/main/scala-3/org/scalajs/dom/MediaDeviceKind.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** https://www.w3.org/TR/2016/CR-mediacapture-streams-20160519/ */
package org.scalajs.dom

import scala.scalajs.js

/** see [[https://www.w3.org/TR/2016/CR-mediacapture-streams-20160519/#idl-def-MediaDeviceKind]] in W3C spec */
opaque type MediaDeviceKind = String

object MediaDeviceKind {

/** Represents an audio input device; for example a microphone. */
val audioinput: MediaDeviceKind = "audioinput"

/** Represents an audio output device; for example a pair of headphones. */
val audiooutput: MediaDeviceKind = "audiooutput"

/** Represents a video input device; for example a webcam. */
val videoinput: MediaDeviceKind = "videoinput"
}
23 changes: 23 additions & 0 deletions src/main/scala-3/org/scalajs/dom/MediaStreamTrackState.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/** https://www.w3.org/TR/2016/CR-mediacapture-streams-20160519/ */
package org.scalajs.dom

import scala.scalajs.js

/** see [[https://www.w3.org/TR/2013/WD-mediacapture-streams-20130903/#widl-MediaStream-onended]] in W3C spec */
opaque type MediaStreamTrackState = String

object MediaStreamTrackState {

/** The track is active (the track's underlying media source is making a best-effort attempt to provide data in real
* time). The output of a track in the live state can be switched on and off with the enabled attribute.
*/
val live: MediaStreamTrackState = "live"

/** The track has ended (the track's underlying media source is no longer providing data, and will never provide more
* data for this track). Once a track enters this state, it never exits it.
*
* For example, a video track in a MediaStream ends if the user unplugs the USB web camera that acts as the track's
* media source.
*/
val ended: MediaStreamTrackState = "ended"
}
15 changes: 15 additions & 0 deletions src/main/scala-3/org/scalajs/dom/PermissionName.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.scalajs.dom

import scala.scalajs.js

opaque type PermissionName = String

object PermissionName {
val geolocation: PermissionName = "geolocation"
val midi: PermissionName = "midi"
val notifications: PermissionName = "notifications"
val push: PermissionName = "push"

val `persistent-storage`: PermissionName =
"persistent-storage"
}
11 changes: 11 additions & 0 deletions src/main/scala-3/org/scalajs/dom/PermissionState.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.scalajs.dom

import scala.scalajs.js

opaque type PermissionState = String

object PermissionState {
val granted: PermissionState = "granted"
val denied: PermissionState = "denied"
val prompt: PermissionState = "prompt"
}
Loading