Skip to content

Commit bf47657

Browse files
committed
Use opaque types for Scala 3
1 parent 59b5c0e commit bf47657

File tree

70 files changed

+723
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+723
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type ClientType = String
6+
7+
object ClientType {
8+
val window: ClientType = "window"
9+
10+
val worker: ClientType = "worker"
11+
12+
val sharedworker: ClientType = "sharedworker"
13+
14+
val all: ClientType = "all"
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type FrameType = String
6+
7+
/** part of ServiceWorker
8+
* [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#client-frametype ¶4.2.2 frameType]] of
9+
* serviceWorker spec
10+
*/
11+
object FrameType {
12+
13+
/** The window client's global object's browsing context is an auxiliary browsing context. */
14+
val auxiliary: FrameType = "auxiliary"
15+
16+
/** The window client's global object's browsing context is a top-level browsing context. */
17+
val `top-level` = "top-level"
18+
19+
/** The window client's global object's browsing context is a nested browsing context. */
20+
val nested: FrameType = "nested"
21+
22+
val none: FrameType = "none"
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
11+
opaque type IDBCursorDirection = js.Any
12+
13+
object IDBCursorDirection {
14+
15+
/** The cursor shows all records, including duplicates. It starts at the upper bound of the key range and moves
16+
* downwards (monotonically decreasing in the order of keys).
17+
*/
18+
@inline def prev: IDBCursorDirection = "prev"
19+
20+
/** The cursor shows all records, excluding duplicates. If multiple records exist with the same key, only the first
21+
* one iterated is retrieved. It starts at the upper bound of the key range and moves downwards.
22+
*/
23+
@inline def prevunique: IDBCursorDirection = "prevunique"
24+
25+
/** The cursor shows all records, including duplicates. It starts at the lower bound of the key range and moves
26+
* upwards (monotonically increasing in the order of keys).
27+
*/
28+
@inline def next: IDBCursorDirection = "next"
29+
30+
/** The cursor shows all records, excluding duplicates. If multiple records exist with the same key, only the first
31+
* one iterated is retrieved. It starts at the lower bound of the key range and moves upwards.
32+
*/
33+
@inline def nextunique: IDBCursorDirection = "nextunique"
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
11+
opaque type IDBTransactionDurability = String
12+
13+
object IDBTransactionDurability {
14+
@inline def default: IDBTransactionDurability = "default"
15+
@inline def strict: IDBTransactionDurability = "strict"
16+
@inline def relaxed: IDBTransactionDurability = "relaxed"
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
11+
/** IndexedDB transaction mode Provides constants for IDB Transaction modes These constants have been removed from
12+
* browser support and replaced by String values
13+
*/
14+
opaque type IDBTransactionMode = String
15+
16+
object IDBTransactionMode {
17+
18+
/** Allows data to be read but not changed. It is the default transaction mode. */
19+
@inline def readonly: IDBTransactionMode = "readonly"
20+
21+
/** Allows any operation to be performed, including ones that delete and create object stores and indexes. This mode
22+
* is for updating the version number of transactions that were started using the setVersion() method of IDBDatabase
23+
* objects. Transactions of this mode cannot run concurrently with other transactions.
24+
*/
25+
@inline def versionchange: IDBTransactionMode = "versionchange"
26+
27+
/** Allows reading and writing of data in existing data stores to be changed. */
28+
@inline def readwrite: IDBTransactionMode = "readwrite"
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** see [[http://www.w3.org/TR/WebCryptoAPI/#dfn-KeyFormat ¶14.2 Data Types]] in W3C spec */
6+
opaque type KeyFormat = String
7+
8+
object KeyFormat {
9+
10+
/** An unformatted sequence of bytes. Intended for secret keys. */
11+
val raw: KeyFormat = "raw"
12+
13+
/** The DER encoding of the PrivateKeyInfo structure from RFC 5208. */
14+
val pkcs8: KeyFormat = "pkcs8"
15+
16+
/** The DER encoding of the SubjectPublicKeyInfo structure from RFC 5280. */
17+
val spki: KeyFormat = "spki"
18+
19+
/** The key is a JsonWebKey dictionary encoded as a JavaScript object */
20+
val jwk: KeyFormat = "jwk"
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** see [[http://www.w3.org/TR/WebCryptoAPI/#cryptokey-interface ¶13 CryptoKey interface]] in W3C doc */
6+
opaque type KeyType = String
7+
8+
object KeyType {
9+
val public: KeyType = "public"
10+
val `private`: KeyType = "private"
11+
val secret: KeyType = "secret"
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** See [[http://www.w3.org/TR/WebCryptoAPI/#cryptokey-interface ¶ 13. CryptoKey Interface]] of w3c spec */
6+
opaque type KeyUsage = String
7+
8+
object KeyUsage {
9+
val encrypt: KeyUsage = "encrypt"
10+
val decrypt: KeyUsage = "decrypt"
11+
val sign: KeyUsage = "sign"
12+
val verify: KeyUsage = "verify"
13+
val deriveKey: KeyUsage = "deriveKey"
14+
val deriveBits: KeyUsage = "deriveBits"
15+
val wrapKey: KeyUsage = "wrapKey"
16+
val unwrapKey: KeyUsage = "unwrapKey"
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type MIMEType = String
6+
7+
object MIMEType {
8+
val `text/html` = "text/html"
9+
val `text/xml` = "text/xml"
10+
val `application/xml` = "application/xml"
11+
12+
val `application/xhtml+xml` =
13+
"application/xhtml+xml"
14+
val `image/svg+xml` = "image/svg+xml"
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** https://www.w3.org/TR/2016/CR-mediacapture-streams-20160519/ */
2+
package org.scalajs.dom
3+
4+
import scala.scalajs.js
5+
6+
/** see [[https://www.w3.org/TR/2016/CR-mediacapture-streams-20160519/#idl-def-MediaDeviceKind]] in W3C spec */
7+
opaque type MediaDeviceKind = String
8+
9+
object MediaDeviceKind {
10+
11+
/** Represents an audio input device; for example a microphone. */
12+
val audioinput: MediaDeviceKind = "audioinput"
13+
14+
/** Represents an audio output device; for example a pair of headphones. */
15+
val audiooutput: MediaDeviceKind = "audiooutput"
16+
17+
/** Represents a video input device; for example a webcam. */
18+
val videoinput: MediaDeviceKind = "videoinput"
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/** https://www.w3.org/TR/2016/CR-mediacapture-streams-20160519/ */
2+
package org.scalajs.dom
3+
4+
import scala.scalajs.js
5+
6+
/** see [[https://www.w3.org/TR/2013/WD-mediacapture-streams-20130903/#widl-MediaStream-onended]] in W3C spec */
7+
opaque type MediaStreamTrackState = String
8+
9+
object MediaStreamTrackState {
10+
11+
/** The track is active (the track's underlying media source is making a best-effort attempt to provide data in real
12+
* time). The output of a track in the live state can be switched on and off with the enabled attribute.
13+
*/
14+
val live: MediaStreamTrackState = "live"
15+
16+
/** The track has ended (the track's underlying media source is no longer providing data, and will never provide more
17+
* data for this track). Once a track enters this state, it never exits it.
18+
*
19+
* For example, a video track in a MediaStream ends if the user unplugs the USB web camera that acts as the track's
20+
* media source.
21+
*/
22+
val ended: MediaStreamTrackState = "ended"
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type PermissionName = String
6+
7+
object PermissionName {
8+
val geolocation: PermissionName = "geolocation"
9+
val midi: PermissionName = "midi"
10+
val notifications: PermissionName = "notifications"
11+
val push: PermissionName = "push"
12+
13+
val `persistent-storage` =
14+
"persistent-storage"
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
opaque type PermissionState = String
6+
7+
object PermissionState {
8+
val granted: PermissionState = "granted"
9+
val denied: PermissionState = "denied"
10+
val prompt: PermissionState = "prompt"
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** This represents a JavaScript enumeration representing the various keys you an request from a [[PushSubscription]] as
6+
* described here: [[http://www.w3.org/TR/push-api/#idl-def-PushEncryptionKeyName]]
7+
*/
8+
opaque type PushEncryptionKeyName = String
9+
10+
/** Static definitions for [[PushEncryptionKeyName]] */
11+
object PushEncryptionKeyName {
12+
13+
/** used to retrieve the P-256 ECDH Diffie-Hellman public key described here:
14+
* [[https://tools.ietf.org/html/draft-ietf-webpush-encryption-01]]
15+
*/
16+
val p256dh: PushEncryptionKeyName = "p256dh"
17+
18+
/** used to retrieve the authentication secret described here:
19+
* [[https://tools.ietf.org/html/draft-ietf-webpush-encryption-01]]
20+
*/
21+
val auth: PushEncryptionKeyName = "auth"
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
5+
/** This represents a JavaScript enumeration describing the state of permissions for pushing described here:
6+
* [[http://www.w3.org/TR/push-api/#idl-def-PushPermissionState]]
7+
*/
8+
opaque type PushPermissionState = String
9+
10+
/** Static definitions for [[PushPermissionState]] */
11+
object PushPermissionState {
12+
13+
/** The webapp has permission to use the Push API. */
14+
val granted: PushPermissionState = "granted"
15+
16+
/** The webapp has been denied permission to use the Push API. */
17+
val denied: PushPermissionState = "denied"
18+
19+
/** The webapp needs to ask for permission in order to use the Push API. */
20+
val prompt: PushPermissionState = "prompt"
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/** http://www.w3.org/TR/2015/WD-webrtc-20150210/ */
2+
package org.scalajs.dom
3+
4+
import scala.scalajs.js
5+
6+
/** see [[https://www.w3.org/TR/2015/WD-webrtc-20150210/#idl-def-RTCBundlePolicy]] in W3C spec */
7+
opaque type RTCBundlePolicy = String
8+
9+
object RTCBundlePolicy {
10+
11+
/** Gather ICE candidates for each media type in use (audio, video, and data). If the remote endpoint is not
12+
* BUNDLE-aware, negotiate only one audio and video track on separate transports.
13+
*/
14+
val balanced: RTCBundlePolicy = "balanced"
15+
16+
/** Gather ICE candidates for each track. If the remote endpoint is not BUNDLE-aware, negotiate all media tracks on
17+
* separate transports.
18+
*/
19+
val `max-compat` = "max-compat"
20+
21+
/** Gather ICE candidates for only one track. If the remote endpoint is not BUNDLE-aware, negotiate only one media
22+
* track.
23+
*/
24+
val `max-bundle` = "max-bundle"
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/** http://www.w3.org/TR/2015/WD-webrtc-20150210/ */
2+
package org.scalajs.dom
3+
4+
import scala.scalajs.js
5+
6+
/** see [[https://www.w3.org/TR/2015/WD-webrtc-20150210/#idl-def-RTCDataChannelState]] in W3C spec */
7+
opaque type RTCDataChannelState = String
8+
9+
object RTCDataChannelState {
10+
11+
/** The user agent is attempting to establish the underlying data transport. This is the initial state of a
12+
* RTCDataChannel object created with createDataChannel().
13+
*/
14+
val connecting: RTCDataChannelState = "connecting"
15+
16+
/** The underlying data transport is established and communication is possible. This is the initial state of a
17+
* RTCDataChannel object dispatched as a part of a RTCDataChannelEvent.
18+
*/
19+
val open: RTCDataChannelState = "open"
20+
21+
/** The procedure to close down the underlying data transport has started. */
22+
val closing: RTCDataChannelState = "closing"
23+
24+
/** The underlying data transport has been closed or could not be established. */
25+
val closed: RTCDataChannelState = "closed"
26+
}

0 commit comments

Comments
 (0)