From 121cdb4ba2e9c2ffdf17c0e9f2cd545501ea47ed Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Sat, 18 Nov 2023 17:59:17 -0600 Subject: [PATCH] fix: fuck u lol --- src/Data.Tuple.Containing.purs | 5 ++- src/HTTP/Request.purs | 59 +++++++++------------------------- 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/src/Data.Tuple.Containing.purs b/src/Data.Tuple.Containing.purs index 06688b2..cc25493 100644 --- a/src/Data.Tuple.Containing.purs +++ b/src/Data.Tuple.Containing.purs @@ -8,7 +8,7 @@ import Data.Tuple.Nested (type (/\), (/\)) -- | given a tuple of any size with at least 1 value -- | of type `a`, `extract` the first occurence of `a` -- | from the tuple -class TupleContaining @a tup where +class TupleContaining a tup where extract :: tup -> a instance TupleContaining a a where @@ -17,10 +17,9 @@ else instance TupleContaining a (a /\ b) where extract = fst else instance TupleContaining b (a /\ b) where extract = snd -else instance TupleContaining b (a /\ b /\ c) where +else instance TupleContaining b (a /\ b /\ rest) where extract (_ /\ b /\ _) = b else instance TupleContaining c (a /\ b /\ c /\ Unit) where extract (_ /\ _ /\ c /\ _) = c else instance TupleContaining a tail => TupleContaining a (Tuple head tail) where extract (_ /\ tail) = extract tail - diff --git a/src/HTTP/Request.purs b/src/HTTP/Request.purs index c75c6d0..2236544 100644 --- a/src/HTTP/Request.purs +++ b/src/HTTP/Request.purs @@ -25,6 +25,7 @@ import Data.Map as Map import Data.Maybe (Maybe(..)) import Data.Newtype (unwrap) import Data.Tuple.Containing (class TupleContaining, extract) +import Data.Tuple.Nested (type (/\), (/\)) import Effect (Effect) import Effect.Aff.Class (class MonadAff, liftAff) import Effect.Class (class MonadEffect, liftEffect) @@ -34,10 +35,10 @@ import HTTP.Header (ContentType(..), Headers(..)) import HTTP.Header as Header import HTTP.MIME (MIME) import HTTP.MIME as MIME -import Node.URL (URL) import Node.Buffer (Buffer) import Node.Buffer as Buffer import Node.Encoding (Encoding(..)) +import Node.URL (URL) import Simple.JSON (class WriteForeign, writeJSON) import Unsafe.Coerce (unsafeCoerce) import Web.File.Blob (Blob) @@ -108,13 +109,7 @@ class Request a where requestBody :: forall m. MonadAff m => a -> m (Maybe RawRequestBody) requestHeaders :: forall m. MonadAff m => a -> m (Map String String) -instance - ( TupleContaining Body a - , TupleContaining URL a - , TupleContaining Method a - , TupleContaining (Effect Headers) a - ) => - Request a where +instance Request (Method /\ URL /\ Body /\ Effect Headers) where requestUrl = pure <<< extract requestMethod = pure <<< extract requestBody = map Just <<< bodyToRaw <<< extract @@ -122,13 +117,8 @@ instance (Headers hs) <- liftEffect $ extract req (Headers bodyHs) <- bodyHeaders $ extract req pure $ Map.union hs bodyHs -else instance - ( TupleContaining Body a - , TupleContaining URL a - , TupleContaining Method a - , TupleContaining Headers a - ) => - Request a where + +instance Request (Method /\ URL /\ Body /\ Headers) where requestUrl = pure <<< extract requestMethod = pure <<< extract requestBody = map Just <<< bodyToRaw <<< extract @@ -136,50 +126,33 @@ else instance let (Headers hs) = extract req (Headers bodyHs) <- bodyHeaders $ extract req pure $ Map.union hs bodyHs -else instance - ( TupleContaining Body a - , TupleContaining URL a - , TupleContaining Method a - ) => - Request a where + +instance Request (Method /\ URL /\ Body) where requestUrl = pure <<< extract requestMethod = pure <<< extract requestBody = map Just <<< bodyToRaw <<< extract requestHeaders _ = pure Map.empty -else instance - ( TupleContaining Headers a - , TupleContaining URL a - , TupleContaining Method a - ) => - Request a where + +instance Request (Method /\ URL /\ Headers) where requestUrl = pure <<< extract requestMethod = pure <<< extract requestBody _ = Just <$> bodyToRaw BodyEmpty requestHeaders = (\(Headers h) -> pure h) <<< extract -else instance - ( TupleContaining (Effect Headers) a - , TupleContaining URL a - , TupleContaining Method a - ) => - Request a where + +instance Request (Method /\ URL /\ Effect Headers) where requestUrl = pure <<< extract requestMethod = pure <<< extract requestBody _ = Just <$> bodyToRaw BodyEmpty requestHeaders = liftEffect <<< map (\(Headers h) -> h) <<< extract @(Effect Headers) -else instance - ( TupleContaining URL a - , TupleContaining Method a - ) => - Request a where + +instance Request (Method /\ URL) where requestUrl = pure <<< extract requestMethod = pure <<< extract requestBody _ = Just <$> bodyToRaw BodyEmpty requestHeaders _ = pure Map.empty -else instance - ( TupleContaining URL a - ) => - Request a where - requestUrl = pure <<< extract + +instance Request URL where + requestUrl = pure requestMethod _ = pure GET requestBody _ = Just <$> bodyToRaw BodyEmpty requestHeaders _ = pure Map.empty