fix: export request methods

This commit is contained in:
orion 2023-10-06 13:53:44 -05:00
parent 9d0470ceb1
commit 37ac23c57a
Signed by: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 18 additions and 18 deletions

View File

@ -2,71 +2,63 @@ import { HTTPResponse } from 'puppeteer'
import { HTTPRequest } from 'puppeteer'
/**
* `foreign import _abort :: String -> Request -> Promise Unit`
* @type {(_0: import("puppeteer").ErrorCode) => (_1: HTTPRequest) => () => Promise<void>}
*/
export const _abort = e => r => () => r.abort(e)
/**
* `foreign import _continue :: Foreign -> Request -> Promise Unit`
* @type {(_0: import("puppeteer").ContinueRequestOverrides) => (_1: HTTPRequest) => () => Promise<void>}
*/
export const _continue = o => r => () => r.continue(o)
/**
* `foreign import _respond :: RespondToRequest -> Request -> Promise Unit`
* @type {(_0: import("puppeteer").ResponseForRequest) => (_1: HTTPRequest) => () => Promise<void>}
*/
export const _respond = rep => req => () => req.respond(rep)
/**
* `foreign import _failure :: Request -> Effect (Nullable {errorText :: String})`
* @type {(_1: HTTPRequest) => () => {errorText: string} | null}
*/
export const _failure = r => () => r.failure()
/**
* `foreign import headers :: Request -> Effect (Map String String)`
* @type {(_1: HTTPRequest) => () => Map<string, string>}
* @type {(_1: HTTPRequest) => () => Array<{k: string, v: string}>}
*/
export const headers = r => () =>
Object.entries(r.headers()).reduce((map, [k, v]) => {
map.set(k, v)
return map
}, new Map())
export const headers = r => () => {
/** @type {Array<{k: string, v: string}>} */
const init = []
return Object.entries(r.headers()).reduce(
(map, [k, v]) => [...map, { k, v }],
init,
)
}
/**
* `foreign import _isNavigation :: Request -> Effect Boolean`
* @type {(_1: HTTPRequest) => () => boolean}
*/
export const isNavigation = r => () => r.isNavigationRequest()
/**
* `foreign import _method :: Request -> Effect String`
* @type {(_1: HTTPRequest) => () => string}
*/
export const method = r => () => r.method()
/**
* `foreign import _postData :: Request -> Effect Foreign`
* @type {(_1: HTTPRequest) => () => string | undefined}
*/
export const _postData = r => () => r.postData()
/**
* `foreign import _resourceType :: Request -> Effect String`
* @type {(_1: HTTPRequest) => () => string}
*/
export const resourceType = r => () => r.resourceType()
/**
* `foreign import _url :: Request -> Effect String`
* @type {(_1: HTTPRequest) => () => string}
*/
export const url = r => () => r.url()
/**
* `foreign import _response :: Request -> Effect (Nullable Response)`
* @type {(_1: HTTPRequest) => () => HTTPResponse | null}
*/
export const _response = r => () => r.response()

View File

@ -9,6 +9,11 @@ module Puppeteer.HTTP.Request
, failure
, postData
, response
, headers
, isNavigation
, method
, resourceType
, url
) where
import Prelude
@ -67,7 +72,6 @@ prepareContinueRequestOverrides { headers: headers', method: method', postData:
, url: FFI.maybeToUndefined url'
}
foreign import headers :: Request -> Effect (Map String String)
foreign import isNavigation :: Request -> Effect Boolean
foreign import method :: Request -> Effect String
foreign import resourceType :: Request -> Effect String
@ -77,10 +81,14 @@ foreign import _abort :: String -> Request -> Promise Unit
foreign import _continue :: Foreign -> Request -> Promise Unit
foreign import _respond :: Foreign -> Request -> Promise Unit
foreign import _headers :: Request -> Effect (Array {k :: String, v :: String})
foreign import _failure :: Request -> Effect (Nullable { errorText :: String })
foreign import _postData :: Request -> Effect Foreign
foreign import _response :: Request -> Effect (Nullable Response)
headers :: Request -> Effect (Map String String)
headers = map FFI.makeMap <<< _headers
abort :: Context InterceptRequestsHint -> ErrorCode -> Request -> Aff Unit
abort _ e = Promise.toAff <<< _abort (errorCodeString e)