diff --git a/package.json b/package.json index 534e7a7..bbbd3ee 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "scripts": { "test": "node tests/index.js", "build": "rewatch", - "format": "rescript format -all && prettier --write ./docs ./tests/index.js ./package.json", + "format": "rescript format -all && prettier --write ./tests/index.js ./package.json", "docs": "astro dev", "build:docs": "astro build" }, diff --git a/src/DOMAPI/Window.js b/src/DOMAPI/Window.js index dbf8d92..977be07 100644 --- a/src/DOMAPI/Window.js +++ b/src/DOMAPI/Window.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as EventTarget$WebAPI from "../EventAPI/EventTarget.js"; +import * as EventTarget$WebApi from "../EventAPI/EventTarget.js"; -EventTarget$WebAPI.Impl({}); +EventTarget$WebApi.Impl({}); /* Not a pure module */ diff --git a/src/FetchAPI.res b/src/FetchAPI.res index a3dca9b..0148de7 100644 --- a/src/FetchAPI.res +++ b/src/FetchAPI.res @@ -218,7 +218,9 @@ type urlSearchParams = { size: int, } -type headersInit = any +type headersInit + +type bodyInit type requestInfo = any @@ -236,7 +238,7 @@ type requestInit = { /** A BodyInit object or null to set request's body. */ - mutable body?: Null.t, + mutable body?: bodyInit, /** A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer. */ diff --git a/src/FetchAPI/BodyInit.js b/src/FetchAPI/BodyInit.js new file mode 100644 index 0000000..d856702 --- /dev/null +++ b/src/FetchAPI/BodyInit.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/src/FetchAPI/BodyInit.res b/src/FetchAPI/BodyInit.res new file mode 100644 index 0000000..71e9a72 --- /dev/null +++ b/src/FetchAPI/BodyInit.res @@ -0,0 +1,47 @@ +open FileAPI +open FetchAPI + +/** +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) + */ +external fromString: string => bodyInit = "%identity" + +/** +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) + */ +external fromArrayBuffer: ArrayBuffer.t => bodyInit = "%identity" + +/** +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) + */ +external fromTypedArray: TypedArray.t<'t> => bodyInit = "%identity" + +/** +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) + */ +external fromDataView: DataView.t => bodyInit = "%identity" + +/** +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) + */ +external fromBlob: blob => bodyInit = "%identity" + +/** +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) + */ +external fromFile: file => bodyInit = "%identity" + +/** +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) + */ +external fromURLSearchParams: urlSearchParams => bodyInit = "%identity" + +/** +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) + */ +external fromFormData: formData => bodyInit = "%identity" + +/** +[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) + */ +external fromReadableStream: readableStream<'t> => bodyInit = "%identity" diff --git a/src/FetchAPI/HeadersInit.js b/src/FetchAPI/HeadersInit.js new file mode 100644 index 0000000..d856702 --- /dev/null +++ b/src/FetchAPI/HeadersInit.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/src/FetchAPI/HeadersInit.res b/src/FetchAPI/HeadersInit.res new file mode 100644 index 0000000..2ca2f21 --- /dev/null +++ b/src/FetchAPI/HeadersInit.res @@ -0,0 +1,11 @@ +open FetchAPI + +/** + [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_headers) + */ +external fromDict: dict => headersInit = "%identity" + +/** + [Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_headers) + */ +external fromHeaders: headers => headersInit = "%identity" diff --git a/src/Prelude.res b/src/Prelude.res index 18579a0..fbc617f 100644 --- a/src/Prelude.res +++ b/src/Prelude.res @@ -5,8 +5,6 @@ external unsafeConversation: 'tinput => 'toutput = "%identity" type bufferSource = any -type bodyInit = any - type sharedArrayBuffer = any type float64Array = any diff --git a/tests/Global__test.js b/tests/Global__test.js index 9a955dc..42ad0d6 100644 --- a/tests/Global__test.js +++ b/tests/Global__test.js @@ -3,7 +3,16 @@ let response = await fetch("https://rescript-lang.org/"); +let response2 = await fetch("https://rescript-lang.org/", { + headers: { + "Content-Type": "application/json", + Authorization: "Bearer token" + }, + body: "secret=foo&response=bar" +}); + export { response, + response2, } /* response Not a pure module */ diff --git a/tests/Global__test.res b/tests/Global__test.res index ff4525e..01c2551 100644 --- a/tests/Global__test.res +++ b/tests/Global__test.res @@ -1,3 +1,16 @@ open WebAPI.Global let response = await fetch("https://rescript-lang.org/") + +let response2 = await fetch( + "https://rescript-lang.org/", + ~init={ + headers: HeadersInit.fromDict( + dict{ + "Content-Type": "application/json", + "Authorization": "Bearer token", + }, + ), + body: BodyInit.fromString(`secret=foo&response=bar`), + }, +)