@rescript/webapi 0.1.0-experimental-469231f → 0.1.0-experimental-3c28b39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rescript/webapi",
3
- "version": "0.1.0-experimental-469231f",
3
+ "version": "0.1.0-experimental-3c28b39",
4
4
  "description": "Experimental successor to [rescript-webapi](https://github.com/TheSpyder/rescript-webapi)",
5
5
  "homepage": "https://rescript-lang.github.io/experimental-rescript-webapi/",
6
6
  "bugs": "https://github.com/rescript-lang/experimental-rescript-webapi/issues",
@@ -31,13 +31,7 @@ external delete: (formData, string) => unit = "delete"
31
31
  [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData/get)
32
32
  */
33
33
  @send
34
- external get: (formData, string) => null<string> = "get"
35
-
36
- /**
37
- [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData/get)
38
- */
39
- @send
40
- external getFile: (formData, string) => null<file> = "get"
34
+ external get: (formData, string) => null<formDataEntryValue> = "get"
41
35
 
42
36
  /**
43
37
  [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData/getAll)
@@ -51,6 +45,12 @@ external getAll: (formData, string) => array<formDataEntryValue> = "getAll"
51
45
  @send
52
46
  external has: (formData, string) => bool = "has"
53
47
 
48
+ /**
49
+ [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData/entries)
50
+ */
51
+ @send
52
+ external entries: formData => Iterator.t<(string, formDataEntryValue)> = "entries"
53
+
54
54
  /**
55
55
  [Read more on MDN](https://developer.mozilla.org/docs/Web/API/FormData/keys)
56
56
  */
@@ -0,0 +1,22 @@
1
+ open Prelude
2
+ open FetchAPI
3
+ open FileAPI
4
+
5
+ external fromString: string => formDataEntryValue = "%identity"
6
+ external fromFile: file => formDataEntryValue = "%identity"
7
+
8
+ /**
9
+ Represents a decoded version of the abstract `formDataEntryValue` type.
10
+ A FormData entry value is either a string or a File.
11
+ */
12
+ type decoded =
13
+ | String(string)
14
+ | File(file)
15
+
16
+ let decode = (t: formDataEntryValue): decoded => {
17
+ if File.isInstanceOf(t) {
18
+ File(unsafeConversation(t))
19
+ } else {
20
+ String(unsafeConversation(t))
21
+ }
22
+ }
package/src/FetchAPI.res CHANGED
@@ -218,7 +218,8 @@ type formData = {}
218
218
 
219
219
  type requestInfo = any
220
220
 
221
- type formDataEntryValue = any
221
+ @editor.completeFrom(FormDataEntryValue)
222
+ type formDataEntryValue
222
223
 
223
224
  type requestInit = {
224
225
  /**
@@ -11,3 +11,5 @@ external make: (
11
11
  ~fileName: string,
12
12
  ~options: filePropertyBag=?,
13
13
  ) => file = "File"
14
+
15
+ let isInstanceOf = (_: 't): bool => %raw(`param instanceof File`)