fix: fuck u lol

This commit is contained in:
orion 2023-11-18 17:59:17 -06:00
parent 3f51f47d0c
commit 121cdb4ba2
Signed by: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 18 additions and 46 deletions

View File

@ -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

View File

@ -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