From d74d3431652e8be77f3116d1226e4eb350b3376a Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Tue, 28 Nov 2023 11:59:01 -0600 Subject: [PATCH] feat: Response.clone --- src/HTTP/Response.js | 3 +++ src/HTTP/Response.purs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/HTTP/Response.js b/src/HTTP/Response.js index 54cf4ee..2077eb2 100644 --- a/src/HTTP/Response.js +++ b/src/HTTP/Response.js @@ -1,5 +1,8 @@ /// +/** @type {(_: Response) => () => Response} */ +export const cloneImpl = rep => () => rep.clone() + /** @type {(_: Response) => () => Promise} */ export const jsonImpl = rep => () => rep.json() diff --git a/src/HTTP/Response.purs b/src/HTTP/Response.purs index 9ce0964..92f1d6a 100644 --- a/src/HTTP/Response.purs +++ b/src/HTTP/Response.purs @@ -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