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 -- | given a tuple of any size with at least 1 value
-- | of type `a`, `extract` the first occurence of `a` -- | of type `a`, `extract` the first occurence of `a`
-- | from the tuple -- | from the tuple
class TupleContaining @a tup where class TupleContaining a tup where
extract :: tup -> a extract :: tup -> a
instance TupleContaining a a where instance TupleContaining a a where
@ -17,10 +17,9 @@ else instance TupleContaining a (a /\ b) where
extract = fst extract = fst
else instance TupleContaining b (a /\ b) where else instance TupleContaining b (a /\ b) where
extract = snd extract = snd
else instance TupleContaining b (a /\ b /\ c) where else instance TupleContaining b (a /\ b /\ rest) where
extract (_ /\ b /\ _) = b extract (_ /\ b /\ _) = b
else instance TupleContaining c (a /\ b /\ c /\ Unit) where else instance TupleContaining c (a /\ b /\ c /\ Unit) where
extract (_ /\ _ /\ c /\ _) = c extract (_ /\ _ /\ c /\ _) = c
else instance TupleContaining a tail => TupleContaining a (Tuple head tail) where else instance TupleContaining a tail => TupleContaining a (Tuple head tail) where
extract (_ /\ tail) = extract tail extract (_ /\ tail) = extract tail

View File

@ -25,6 +25,7 @@ import Data.Map as Map
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap) import Data.Newtype (unwrap)
import Data.Tuple.Containing (class TupleContaining, extract) import Data.Tuple.Containing (class TupleContaining, extract)
import Data.Tuple.Nested (type (/\), (/\))
import Effect (Effect) import Effect (Effect)
import Effect.Aff.Class (class MonadAff, liftAff) import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (class MonadEffect, liftEffect) import Effect.Class (class MonadEffect, liftEffect)
@ -34,10 +35,10 @@ import HTTP.Header (ContentType(..), Headers(..))
import HTTP.Header as Header import HTTP.Header as Header
import HTTP.MIME (MIME) import HTTP.MIME (MIME)
import HTTP.MIME as MIME import HTTP.MIME as MIME
import Node.URL (URL)
import Node.Buffer (Buffer) import Node.Buffer (Buffer)
import Node.Buffer as Buffer import Node.Buffer as Buffer
import Node.Encoding (Encoding(..)) import Node.Encoding (Encoding(..))
import Node.URL (URL)
import Simple.JSON (class WriteForeign, writeJSON) import Simple.JSON (class WriteForeign, writeJSON)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Web.File.Blob (Blob) import Web.File.Blob (Blob)
@ -108,13 +109,7 @@ class Request a where
requestBody :: forall m. MonadAff m => a -> m (Maybe RawRequestBody) requestBody :: forall m. MonadAff m => a -> m (Maybe RawRequestBody)
requestHeaders :: forall m. MonadAff m => a -> m (Map String String) requestHeaders :: forall m. MonadAff m => a -> m (Map String String)
instance instance Request (Method /\ URL /\ Body /\ Effect Headers) where
( TupleContaining Body a
, TupleContaining URL a
, TupleContaining Method a
, TupleContaining (Effect Headers) a
) =>
Request a where
requestUrl = pure <<< extract requestUrl = pure <<< extract
requestMethod = pure <<< extract requestMethod = pure <<< extract
requestBody = map Just <<< bodyToRaw <<< extract requestBody = map Just <<< bodyToRaw <<< extract
@ -122,13 +117,8 @@ instance
(Headers hs) <- liftEffect $ extract req (Headers hs) <- liftEffect $ extract req
(Headers bodyHs) <- bodyHeaders $ extract req (Headers bodyHs) <- bodyHeaders $ extract req
pure $ Map.union hs bodyHs pure $ Map.union hs bodyHs
else instance
( TupleContaining Body a instance Request (Method /\ URL /\ Body /\ Headers) where
, TupleContaining URL a
, TupleContaining Method a
, TupleContaining Headers a
) =>
Request a where
requestUrl = pure <<< extract requestUrl = pure <<< extract
requestMethod = pure <<< extract requestMethod = pure <<< extract
requestBody = map Just <<< bodyToRaw <<< extract requestBody = map Just <<< bodyToRaw <<< extract
@ -136,50 +126,33 @@ else instance
let (Headers hs) = extract req let (Headers hs) = extract req
(Headers bodyHs) <- bodyHeaders $ extract req (Headers bodyHs) <- bodyHeaders $ extract req
pure $ Map.union hs bodyHs pure $ Map.union hs bodyHs
else instance
( TupleContaining Body a instance Request (Method /\ URL /\ Body) where
, TupleContaining URL a
, TupleContaining Method a
) =>
Request a where
requestUrl = pure <<< extract requestUrl = pure <<< extract
requestMethod = pure <<< extract requestMethod = pure <<< extract
requestBody = map Just <<< bodyToRaw <<< extract requestBody = map Just <<< bodyToRaw <<< extract
requestHeaders _ = pure Map.empty requestHeaders _ = pure Map.empty
else instance
( TupleContaining Headers a instance Request (Method /\ URL /\ Headers) where
, TupleContaining URL a
, TupleContaining Method a
) =>
Request a where
requestUrl = pure <<< extract requestUrl = pure <<< extract
requestMethod = pure <<< extract requestMethod = pure <<< extract
requestBody _ = Just <$> bodyToRaw BodyEmpty requestBody _ = Just <$> bodyToRaw BodyEmpty
requestHeaders = (\(Headers h) -> pure h) <<< extract requestHeaders = (\(Headers h) -> pure h) <<< extract
else instance
( TupleContaining (Effect Headers) a instance Request (Method /\ URL /\ Effect Headers) where
, TupleContaining URL a
, TupleContaining Method a
) =>
Request a where
requestUrl = pure <<< extract requestUrl = pure <<< extract
requestMethod = pure <<< extract requestMethod = pure <<< extract
requestBody _ = Just <$> bodyToRaw BodyEmpty requestBody _ = Just <$> bodyToRaw BodyEmpty
requestHeaders = liftEffect <<< map (\(Headers h) -> h) <<< extract @(Effect Headers) requestHeaders = liftEffect <<< map (\(Headers h) -> h) <<< extract @(Effect Headers)
else instance
( TupleContaining URL a instance Request (Method /\ URL) where
, TupleContaining Method a
) =>
Request a where
requestUrl = pure <<< extract requestUrl = pure <<< extract
requestMethod = pure <<< extract requestMethod = pure <<< extract
requestBody _ = Just <$> bodyToRaw BodyEmpty requestBody _ = Just <$> bodyToRaw BodyEmpty
requestHeaders _ = pure Map.empty requestHeaders _ = pure Map.empty
else instance
( TupleContaining URL a instance Request URL where
) => requestUrl = pure
Request a where
requestUrl = pure <<< extract
requestMethod _ = pure GET requestMethod _ = pure GET
requestBody _ = Just <$> bodyToRaw BodyEmpty requestBody _ = Just <$> bodyToRaw BodyEmpty
requestHeaders _ = pure Map.empty requestHeaders _ = pure Map.empty