@@ -19,7 +19,8 @@ module Yoga.Fetch.Om
20import Prelude
20import Prelude
22−import Data.Symbol (class IsSymbol)
22+import Data.Symbol (class IsSymbol, reflectSymbol)
23+import Data.Tuple.Nested ((/\))
23import Data.Variant (Variant)
24import Data.Variant (Variant)
24import Prim.Row as Row
25import Prim.Row as Row
25import Prim.RowList (class RowToList, RowList)
26import Prim.RowList (class RowToList, RowList)
@@ -29,7 +30,6 @@ import Type.Proxy (Proxy(..))
29import Unsafe.Coerce (unsafeCoerce)
30import Unsafe.Coerce (unsafeCoerce)
30import JS.Fetch.Headers (Headers)
31import JS.Fetch.Headers (Headers)
31import JS.Fetch.Headers as Headers
32import JS.Fetch.Headers as Headers
32−import Type.Row.Homogeneous (class Homogeneous)
33import Yoga.Fetch.Om.BuildUrl (class BuildUrl, buildUrl)
33import Yoga.Fetch.Om.BuildUrl (class BuildUrl, buildUrl)
34import Yoga.Fetch.Om.Simple (class DecodeResponse, decodeResponse, FetchError, FetchResponse, get, getWithHeaders, delete, deleteWithHeaders, delete_, post, postWithHeaders, post_, put, putWithHeaders, put_, patch, patchWithHeaders, patch_)
34import Yoga.Fetch.Om.Simple (class DecodeResponse, decodeResponse, FetchError, FetchResponse, get, getWithHeaders, delete, deleteWithHeaders, delete_, post, postWithHeaders, post_, put, putWithHeaders, put_, patch, patchWithHeaders, patch_)
35import Yoga.Fetch.Om.StreamDecode (class StreamDecode, decodeStream)
35import Yoga.Fetch.Om.StreamDecode (class StreamDecode, decodeStream)
@@ -40,7 +40,7 @@ import Yoga.Fetch.Om.ParseResponse (class ParseResponse, parseResponse)
40import Yoga.Fetch.Om.SplitResponses (class SplitResponses)
40import Yoga.Fetch.Om.SplitResponses (class SplitResponses)
41import Yoga.Fetch.Om.Variant (class VariantOrValue, variantOrValue)
41import Yoga.Fetch.Om.Variant (class VariantOrValue, variantOrValue)
42import Yoga.HTTP.API.Path (Path, Root, Lit, Capture, PathCons, Param, QueryParams, Required, type (/), type (:), type (:?), class PathPattern)
42import Yoga.HTTP.API.Path (Path, Root, Lit, Capture, PathCons, Param, QueryParams, Required, type (/), type (:), type (:?), class PathPattern)
43−import Yoga.HTTP.API.Route (Route(..), GET, POST, PUT, DELETE, PATCH, Response(..), JSON, FormData, PlainText, Streaming, NoBody)
43+import Yoga.HTTP.API.Route (Route(..), GET, POST, PUT, DELETE, PATCH, Response(..), JSON, FormData, PlainText, Streaming, NoBody, class HeaderValue, printHeader)
44import Yoga.HTTP.API.Route.Handler (class SegmentPathParams, class SegmentQueryParams)
44import Yoga.HTTP.API.Route.Handler (class SegmentPathParams, class SegmentQueryParams)
45import Yoga.Om (class ToOm, Om, toOm)
45import Yoga.Om (class ToOm, Om, toOm)
@@ -57,8 +57,19 @@ class ToHeaders headersRL headers where
57instance ToHeaders RL.Nil headers where
57instance ToHeaders RL.Nil headers where
58 toHeaders _ _ = Headers.empty
58 toHeaders _ _ = Headers.empty
63+ , Row.Cons name ty tailRow headers
64+ , Row.Lacks name tailRow
65+ , ToHeaders tail tailRow
60−else instance Homogeneous headers String => ToHeaders headersRL headers where
67+ ToHeaders (RL.Cons name ty tail) headers where
61− toHeaders _ = Headers.fromRecord
68+ toHeaders _ headers = Headers.fromFoldable ([ headerName /\ headerValue ] <> Headers.toArray rest)
70+ headerName = reflectSymbol (Proxy :: Proxy name)
71+ headerValue = printHeader (Record.get (Proxy :: Proxy name) headers)
72+ rest = toHeaders (Proxy :: Proxy tail) (unsafeCoerce headers :: Record tailRow)
63class DeriveClientFn :: forall k1. Type -> k1 -> Type -> Row Type -> Row Type -> Row Type -> Type -> Type -> Constraint
74class DeriveClientFn :: forall k1. Type -> k1 -> Type -> Row Type -> Row Type -> Row Type -> Type -> Type -> Constraint
@@ -114,23 +125,20 @@ class DeriveClient routesRow clientsRow | routesRow -> clientsRow where
114-- | type UserAPI = { getUser :: Route ... }
125-- | type UserAPI = { getUser :: Route ... }
115-- | api = client @UserAPI "https://api.example.com"
126-- | api = client @UserAPI "https://api.example.com"
117−client :: forall @routes routesRow clientsRow polyClientsRow. RecordRow routes routesRow => DeriveClient routesRow clientsRow => String -> Record polyClientsRow
128+client :: forall @routes routesRow clientsRow. RecordRow routes routesRow => DeriveClient routesRow clientsRow => String -> Record clientsRow
118−client baseUrl = polymorphic (deriveClientImpl baseUrl (Proxy :: _ { | routesRow }) :: Record clientsRow)
129+client baseUrl = deriveClientImpl baseUrl (Proxy :: _ { | routesRow })
120-- | Deprecated: Use `client` with VTA instead
131-- | Deprecated: Use `client` with VTA instead
122-- | ```purescript
133-- | ```purescript
123-- | api = deriveClient @UserAPI "https://api.example.com"
134-- | api = deriveClient @UserAPI "https://api.example.com"
125−deriveClient :: forall @routesRow clientsRow polyClientsRow. DeriveClient routesRow clientsRow => String -> Record polyClientsRow
136+deriveClient :: forall @routesRow clientsRow. DeriveClient routesRow clientsRow => String -> Record clientsRow
126−deriveClient baseUrl = polymorphic (deriveClientImpl baseUrl (Proxy :: _ { | routesRow }) :: Record clientsRow)
137+deriveClient baseUrl = deriveClientImpl baseUrl (Proxy :: _ { | routesRow })
128plainText :: PlainText -> String
139plainText :: PlainText -> String
129plainText = unsafeCoerce
140plainText = unsafeCoerce
131−polymorphic :: forall a b. a -> b
132−polymorphic = unsafeCoerce
135 ( RowToList routesRow rl
143 ( RowToList routesRow rl
136 , DeriveClientRL rl () clientsRow
144 , DeriveClientRL rl () clientsRow