feat: Response.clone

This commit is contained in:
orion 2023-11-28 11:59:01 -06:00
parent 00ec9cf08c
commit d74d343165
Signed by: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 8 additions and 0 deletions

View File

@ -1,5 +1,8 @@
/// <reference lib="dom" />
/** @type {(_: Response) => () => Response} */
export const cloneImpl = rep => () => rep.clone()
/** @type {(_: Response) => () => Promise<unknown>} */
export const jsonImpl = rep => () => rep.json()

View File

@ -1,5 +1,6 @@
module HTTP.Response
( Response(..)
, clone
, json
, text
, blob
@ -36,6 +37,7 @@ import Web.File.Blob (Blob)
foreign import data Response :: Type
foreign import cloneImpl :: Response -> Effect Response
foreign import statusImpl :: Response -> Effect Int
foreign import statusTextImpl :: Response -> Effect String
foreign import headersImpl :: Response -> Effect (Object String)
@ -54,6 +56,9 @@ guardStatusOk rep = do
else
pure unit
clone :: forall m. MonadEffect m => Response -> m Response
clone = liftEffect <<< cloneImpl
json :: forall m @a. MonadAff m => ReadForeign a => Response -> m a
json = liftAff <<< flip bind (liftEither <<< lmap (error <<< show) <<< runExcept <<< readImpl) <<< Promise.toAffE <<< jsonImpl