Skip to content

Commit d19f188

Browse files
committed
Move all the fetch-related APIs to dom.*.
1 parent b257d5e commit d19f188

File tree

9 files changed

+243
-97
lines changed

9 files changed

+243
-97
lines changed

src/main/scala/org/scalajs/dom/experimental/AbortController.scala renamed to src/main/scala/org/scalajs/dom/AbortController.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
package org.scalajs.dom.experimental
2-
3-
import org.scalajs.dom.EventTarget
1+
package org.scalajs.dom
42

53
import scala.scalajs.js
64
import scala.scalajs.js.annotation.JSGlobal

src/main/scala/org/scalajs/dom/experimental/Fetch.scala renamed to src/main/scala/org/scalajs/dom/Fetch.scala

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
package org.scalajs.dom.experimental
2-
3-
import org.scalajs.dom.{Blob, FormData}
1+
package org.scalajs.dom
42

53
import scala.scalajs.js
64
import scala.scalajs.js.annotation._
@@ -183,17 +181,6 @@ trait ResponseInit extends js.Object {
183181
var headers: HeadersInit
184182
}
185183

186-
object ResponseInit {
187-
def apply(_status: Int = 200, _statusText: ByteString = "OK",
188-
_headers: HeadersInit = js.Dictionary[String]()): ResponseInit = {
189-
new ResponseInit {
190-
var status = _status
191-
var statusText = _statusText
192-
var headers = _headers
193-
}
194-
}
195-
}
196-
197184
/**
198185
* See [[https://fetch.spec.whatwg.org/#body body interface]] in whatwg Fetch spec.
199186
*

src/main/scala/org/scalajs/dom/experimental/Stream.scala renamed to src/main/scala/org/scalajs/dom/Stream.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.scalajs.dom.experimental
1+
package org.scalajs.dom
22

33
import scala.scalajs.js
44
import scala.scalajs.js.annotation._

src/main/scala/org/scalajs/dom/experimental/URL.scala renamed to src/main/scala/org/scalajs/dom/URL.scala

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
1-
package org.scalajs.dom.experimental
1+
package org.scalajs.dom
22

33
import scala.scalajs.js
44
import scala.scalajs.js.annotation._
55

6+
/**
7+
* The URL object provides static methods used for creating object URLs.
8+
*
9+
* MDN
10+
*/
11+
@js.native
12+
@JSGlobal
13+
object URL extends js.Object {
14+
15+
/**
16+
* The URL.revokeObjectURL() static method releases an existing object URL which
17+
* was previously created by calling window.URL.createObjectURL().  Call this
18+
* method when you've finished using a object URL, in order to let the browser know it
19+
* doesn't need to keep the reference to the file any longer.
20+
*
21+
* MDN
22+
*/
23+
def revokeObjectURL(url: String): Unit = js.native
24+
25+
/**
26+
* The URL.createObjectURL() static method creates a DOMString containing an URL
27+
* representing the object given in parameter. The URL lifetime is tied to the
28+
* document in the window on which it was created. The new object URL represents the
29+
* specified File object or Blob object.
30+
*
31+
* MDN
32+
*/
33+
def createObjectURL(blob: Blob): String = js.native
34+
}
35+
636
/**
737
* The URL() constructor returns a newly created URL object representing the URL
838
* defined by the parameters.

src/main/scala/org/scalajs/dom/experimental/beacon/package.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.scalajs.dom.experimental
22

3+
import org.scalajs.dom
34
import org.scalajs.dom.{Navigator, WorkerNavigator}
45

56
import scala.scalajs.js
@@ -41,7 +42,7 @@ package object beacon {
4142
* @param data The data parameter is the ArrayBufferView, Blob, DOMString,
4243
* or FormData data that is to be transmitted.
4344
*/
44-
def sendBeacon(url: String, data: BodyInit = null): Boolean = js.native
45+
def sendBeacon(url: String, data: dom.BodyInit = null): Boolean = js.native
4546
}
4647

4748
@js.native
@@ -58,6 +59,6 @@ package object beacon {
5859
* @param data The data parameter is the ArrayBufferView, Blob, DOMString,
5960
* or FormData data that is to be transmitted.
6061
*/
61-
def sendBeacon(url: String, data: BodyInit = null): Boolean = js.native
62+
def sendBeacon(url: String, data: dom.BodyInit = null): Boolean = js.native
6263
}
6364
}
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,139 @@
11
package org.scalajs.dom
22

33
import scala.scalajs.js
4+
import scala.scalajs.js.annotation._
45
import scala.scalajs.js.|
56

67
import org.scalajs.dom
78

89
package object experimental {
910

10-
/**
11-
* defined at [[https://fetch.spec.whatwg.org/#request-class ¶6.3 Request class]]
12-
* of whatwg Fetch spec
13-
*/
14-
type RequestInfo = String | Request
15-
16-
/**
17-
* defined at [[https://fetch.spec.whatwg.org/#headersinit ¶6.1 Header Class]]
18-
* in whatwg Fetch spec
19-
* todo: it should be OpenEndedDictionary[ByteString]
20-
*/
21-
type HeadersInit =
22-
Headers | Sequence[Sequence[ByteString]] | OpenEndedDictionary[ByteString]
23-
24-
/**
25-
* This type should capture strings consisting only of ASCII chars
26-
* todo: is there a way to capture this type?
27-
*/
28-
type ByteString = String
29-
30-
/**
31-
* defined at [[https://fetch.spec.whatwg.org/#body-mixin ¶6.2 Body mixin]]
32-
* in whatwg Fetch spec
33-
*/
34-
type BodyInit =
35-
Blob | BufferSource | FormData | String //todo: add URLSearchParams
36-
37-
/**
38-
* WebIDL sequence<T> is js.Array[T] | JSIterable[T]. However @mseddon knows
39-
* at least Blink's IDL compiler treats these as simply js.Array[T] for now.
40-
* We keep this type as a reminder to check in more detail
41-
*/
42-
type Sequence[T] = js.Array[T]
43-
44-
/**
45-
* see [[https://fetch.spec.whatwg.org/#headers-class ¶6.1 Headers class]] in
46-
* whatwg Fetch spec.
47-
* also see: [[https://github.com/whatwg/fetch/issues/164 issue 164]] in Fetch
48-
* API git repo, as this is not clearly defined
49-
*/
50-
type OpenEndedDictionary[T] = js.Dictionary[T]
11+
// old package.scala
12+
13+
@deprecated("use dom.RequestInfo instead", "2.0.0")
14+
type RequestInfo = dom.RequestInfo
15+
16+
@deprecated("use dom.HeadersInit instead", "2.0.0")
17+
type HeadersInit = dom.HeadersInit
18+
19+
@deprecated("use dom.ByteString instead", "2.0.0")
20+
type ByteString = dom.ByteString
21+
22+
@deprecated("use dom.BodyInit instead", "2.0.0")
23+
type BodyInit = dom.BodyInit
24+
25+
@deprecated("use dom.Sequence instead", "2.0.0")
26+
type Sequence[T] = dom.Sequence[T]
27+
28+
@deprecated("use dom.OpenEndedDictionary instead", "2.0.0")
29+
type OpenEndedDictionary[T] = dom.OpenEndedDictionary[T]
30+
31+
// old AbortController.scala
32+
33+
@deprecated("use dom.AbortController instead", "2.0.0")
34+
type AbortController = dom.AbortController
35+
36+
@deprecated("use dom.AbortSignal instead", "2.0.0")
37+
type AbortSignal = dom.AbortSignal
38+
39+
// old Fetch.scala
40+
41+
@deprecated("use dom.fetch instead", "2.0.0")
42+
object Fetch {
43+
@js.native
44+
@JSGlobal("fetch")
45+
def fetch(info: RequestInfo,
46+
init: RequestInit = null): js.Promise[Response] = js.native
47+
}
48+
49+
@deprecated("use dom.Request instead", "2.0.0")
50+
type Request = dom.Request
51+
52+
@deprecated("use dom.RequestInit instead", "2.0.0")
53+
type RequestInit = dom.RequestInit
54+
55+
@deprecated("use dom.Response instead", "2.0.0")
56+
type Response = dom.Response
57+
58+
@deprecated("use dom.Response instead", "2.0.0")
59+
lazy val Response: dom.Response.type = dom.Response
60+
61+
@deprecated("use dom.ResponseInit instead", "2.0.0")
62+
type ResponseInit = dom.ResponseInit
63+
64+
@deprecated("use new dom.ResponseInit { ... } instead", "2.0.0")
65+
object ResponseInit {
66+
def apply(_status: Int = 200, _statusText: ByteString = "OK",
67+
_headers: HeadersInit = js.Dictionary[String]()): ResponseInit = {
68+
new ResponseInit {
69+
var status = _status
70+
var statusText = _statusText
71+
var headers = _headers
72+
}
73+
}
74+
}
75+
76+
@deprecated("use dom.Body instead", "2.0.0")
77+
type Body = dom.Body
78+
79+
@deprecated("use dom.Headers instead", "2.0.0")
80+
type Headers = dom.Headers
81+
82+
@deprecated("use dom.ReferrerPolicy instead", "2.0.0")
83+
type ReferrerPolicy = dom.ReferrerPolicy
84+
85+
@deprecated("use dom.ReferrerPolicy instead", "2.0.0")
86+
lazy val ReferrerPolicy: dom.ReferrerPolicy.type = dom.ReferrerPolicy
87+
88+
@deprecated("use dom.HttpMethod instead", "2.0.0")
89+
type HttpMethod = dom.HttpMethod
90+
91+
@deprecated("use dom.HttpMethod instead", "2.0.0")
92+
lazy val HttpMethod: dom.HttpMethod.type = dom.HttpMethod
93+
94+
@deprecated("use dom.RequestType instead", "2.0.0")
95+
type RequestType = dom.RequestType
96+
97+
@deprecated("use dom.RequestType instead", "2.0.0")
98+
lazy val RequestType: dom.RequestType.type = dom.RequestType
99+
100+
@deprecated("use dom.RequestDestination instead", "2.0.0")
101+
type RequestDestination = dom.RequestDestination
102+
103+
@deprecated("use dom.RequestDestination instead", "2.0.0")
104+
lazy val RequestDestination: dom.RequestDestination.type =
105+
dom.RequestDestination
106+
107+
@deprecated("use dom.RequestMode instead", "2.0.0")
108+
type RequestMode = dom.RequestMode
109+
110+
@deprecated("use dom.RequestMode instead", "2.0.0")
111+
lazy val RequestMode: dom.RequestMode.type = dom.RequestMode
112+
113+
@deprecated("use dom.RequestCredentials instead", "2.0.0")
114+
type RequestCredentials = dom.RequestCredentials
115+
116+
@deprecated("use dom.RequestCredentials instead", "2.0.0")
117+
lazy val RequestCredentials: dom.RequestCredentials.type =
118+
dom.RequestCredentials
119+
120+
@deprecated("use dom.RequestCache instead", "2.0.0")
121+
type RequestCache = dom.RequestCache
122+
123+
@deprecated("use dom.RequestCache instead", "2.0.0")
124+
lazy val RequestCache: dom.RequestCache.type = dom.RequestCache
125+
126+
@deprecated("use dom.RequestRedirect instead", "2.0.0")
127+
type RequestRedirect = dom.RequestRedirect
128+
129+
@deprecated("use dom.RequestRedirect instead", "2.0.0")
130+
lazy val RequestRedirect: dom.RequestRedirect.type = dom.RequestRedirect
131+
132+
@deprecated("use dom.ResponseType instead", "2.0.0")
133+
type ResponseType = dom.ResponseType
134+
135+
@deprecated("use dom.ResponseType instead", "2.0.0")
136+
lazy val ResponseType: dom.ResponseType.type = dom.ResponseType
51137

52138
// old Notification.scala
53139

@@ -59,4 +145,35 @@ package object experimental {
59145

60146
@deprecated("use dom.NotificationOptions instead", "2.0.0")
61147
type NotificationOptions = dom.NotificationOptions
148+
149+
// old Stream.scala
150+
151+
@deprecated("use dom.WriteableState instead", "2.0.0")
152+
type WriteableState = dom.WriteableState
153+
154+
@deprecated("use dom.WriteableState instead", "2.0.0")
155+
lazy val WriteableState: dom.WriteableState.type = dom.WriteableState
156+
157+
@deprecated("use dom.WriteableStream instead", "2.0.0")
158+
type WriteableStream[-T] = dom.WriteableStream[T]
159+
160+
@deprecated("use dom.ReadableStream instead", "2.0.0")
161+
type ReadableStream[+T] = dom.ReadableStream[T]
162+
163+
@deprecated("use dom.ReadableStreamReader instead", "2.0.0")
164+
type ReadableStreamReader[+T] = dom.ReadableStreamReader[T]
165+
166+
@deprecated("use dom.ReadableStreamController instead", "2.0.0")
167+
type ReadableStreamController[-T] = dom.ReadableStreamController[T]
168+
169+
@deprecated("use dom.Chunk instead", "2.0.0")
170+
type Chunk[+T] = dom.Chunk[T]
171+
172+
// old URL.scala
173+
174+
@deprecated("use dom.URL instead", "2.0.0")
175+
type URL = dom.URL
176+
177+
@deprecated("use dom.URLSearchParams instead", "2.0.0")
178+
type URLSearchParams = dom.URLSearchParams
62179
}

src/main/scala/org/scalajs/dom/experimental/serviceworkers/ServiceWorkers.scala

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import scala.scalajs.js
44
import scala.scalajs.js.annotation._
55
import scala.scalajs.js.|
66

7-
import org.scalajs.dom.{
8-
ErrorEvent, Event, EventInit, EventTarget, MessageEvent, MessagePort,
9-
Notification, NotificationOptions, WorkerGlobalScope
10-
}
11-
import org.scalajs.dom.experimental.{Request, RequestInfo, Response, Sequence}
7+
import org.scalajs.dom._
128
import org.scalajs.dom.webgl.RenderingContext
139

1410
@js.native

src/main/scala/org/scalajs/dom/lib.scala

-30
Original file line numberDiff line numberDiff line change
@@ -7280,36 +7280,6 @@ abstract class File extends Blob {
72807280
def name: String = js.native
72817281
}
72827282

7283-
/**
7284-
* The URL object provides static methods used for creating object URLs.
7285-
*
7286-
* MDN
7287-
*/
7288-
@js.native
7289-
@JSGlobal
7290-
object URL extends js.Object {
7291-
7292-
/**
7293-
* The URL.revokeObjectURL() static method releases an existing object URL which
7294-
* was previously created by calling window.URL.createObjectURL().  Call this
7295-
* method when you've finished using a object URL, in order to let the browser know it
7296-
* doesn't need to keep the reference to the file any longer.
7297-
*
7298-
* MDN
7299-
*/
7300-
def revokeObjectURL(url: String): Unit = js.native
7301-
7302-
/**
7303-
* The URL.createObjectURL() static method creates a DOMString containing an URL
7304-
* representing the object given in parameter. The URL lifetime is tied to the
7305-
* document in the window on which it was created. The new object URL represents the
7306-
* specified File object or Blob object.
7307-
*
7308-
* MDN
7309-
*/
7310-
def createObjectURL(blob: Blob): String = js.native
7311-
}
7312-
73137283
/**
73147284
* XMLHttpRequestEventTarget is the interface that describes the event handlers
73157285
* you can implement in an object that will handle events for an XMLHttpRequest.

0 commit comments

Comments
 (0)