@@ -13,7 +13,6 @@ module Yoga.Fetch.Om
13 , module Yoga.HTTP.API.Route
13 , module Yoga.HTTP.API.Route
14 , module Yoga.HTTP.API.Path
14 , module Yoga.HTTP.API.Path
15 , plainText
15 , plainText
17 , module Yoga.Fetch.Om.StreamDecode
16 , module Yoga.Fetch.Om.StreamDecode
18 , module Yoga.Fetch.Om.Simple
17 , module Yoga.Fetch.Om.Simple
@@ -35,7 +34,7 @@ import Yoga.Fetch.Om.BuildUrl (class BuildUrl, buildUrl)
35import 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_)
36import Yoga.Fetch.Om.StreamDecode (class StreamDecode, decodeStream)
35import Yoga.Fetch.Om.StreamDecode (class StreamDecode, decodeStream)
37import Yoga.Fetch.Om.ClientFunction (class BuildClientFn, class CheckBodyIsUnit, buildClientFn)
36import Yoga.Fetch.Om.ClientFunction (class BuildClientFn, class CheckBodyIsUnit, buildClientFn)
38−import Yoga.Fetch.Om.QueryDefaults (class BuildQueryFromPartial, buildQueryFromPartial)
37+import Yoga.Fetch.Om.ReadOptional (class ReadPartialQuery, readPartialQuery)
39import Yoga.Fetch.Om.ExtractParams (class ExtractRequestBody, class ExtractBodyEncoding, class ExtractRequestHeaders)
38import Yoga.Fetch.Om.ExtractParams (class ExtractRequestBody, class ExtractBodyEncoding, class ExtractRequestHeaders)
40import Yoga.Fetch.Om.MakeRequest (class MakeRequest, class BodyEncoding, makeRequest, encodingContentType, encodeBody)
39import Yoga.Fetch.Om.MakeRequest (class MakeRequest, class BodyEncoding, makeRequest, encodingContentType, encodeBody)
41import Yoga.Fetch.Om.ParseResponse (class ParseResponse, parseResponse)
40import Yoga.Fetch.Om.ParseResponse (class ParseResponse, parseResponse)
@@ -74,11 +73,11 @@ else instance
74 rest = toHeaders (Proxy :: Proxy tail) (unsafeCoerce headers :: Record tailRow)
73 rest = toHeaders (Proxy :: Proxy tail) (unsafeCoerce headers :: Record tailRow)
76class DeriveClientFn
75class DeriveClientFn
77− :: forall k1. Type -> k1 -> Type -> Row Type -> Row Type -> Row Type -> Row Type -> Type -> Type -> Constraint
76+ :: forall k1. Type -> k1 -> Type -> Row Type -> Row Type -> Row Type -> Row Type -> Row Type -> Type -> Type -> Constraint
79− DeriveClientFn method segments request response ctx extraErr routeErrors result fn
78+ DeriveClientFn method segments request response ctx extraErr given routeErrors result fn
80 | method segments request response -> routeErrors result
79 | method segments request response -> routeErrors result
81− , method segments request response ctx extraErr -> fn where
80+ , method segments request response ctx extraErr given -> fn where
82 deriveClientFn :: String -> Proxy (Route method segments request response) -> fn
81 deriveClientFn :: String -> Proxy (Route method segments request response) -> fn
@@ -98,18 +97,23 @@ instance
98 , Row.Union pathParams queryParams pathQuery
97 , Row.Union pathParams queryParams pathQuery
99 , Row.Nub pathQuery pathQuery
98 , Row.Nub pathQuery pathQuery
100 , RowToList pathQuery pathQueryRL
99 , RowToList pathQuery pathQueryRL
100+ , RowToList queryParams queryParamsRL
101+ , ReadPartialQuery queryParamsRL queryParams
101 , RowToList headers headersRL
102 , RowToList headers headersRL
102 , ToHeaders headersRL headers
103 , ToHeaders headersRL headers
103 , CheckBodyIsUnit body bodyFlag
104 , CheckBodyIsUnit body bodyFlag
104 , Row.Union routeErrors extraErr errRow
105 , Row.Union routeErrors extraErr errRow
105− , BuildClientFn pathQueryRL headersRL bodyFlag body pathQuery headers { | ctx } errRow result fn
106+ , BuildClientFn pathQueryRL headersRL bodyFlag body pathQuery headers given { | ctx } errRow result fn
107− DeriveClientFn method segments request response ctx extraErr routeErrors result fn where
108+ DeriveClientFn method segments request response ctx extraErr given routeErrors result fn where
108 deriveClientFn baseUrl _ =
109 deriveClientFn baseUrl _ =
109− buildClientFn (Proxy :: _ pathQueryRL) (Proxy :: _ headersRL) (Proxy :: _ bodyFlag) impl
110+ buildClientFn (Proxy :: _ pathQueryRL) (Proxy :: _ headersRL) (Proxy :: _ bodyFlag) convert impl
112+ convert :: Record given -> Record pathQuery
113+ convert = unsafeCoerce
111 impl :: Record pathQuery -> Record headers -> body -> Om { | ctx } errRow result
114 impl :: Record pathQuery -> Record headers -> body -> Om { | ctx } errRow result
112 impl pathQueryRec headersRec bodyVal = widenOm do
115 impl pathQueryRec headersRec bodyVal = widenOm do
116+ let queryParamsRec = readPartialQuery @queryParamsRL pathQueryRec
113 let url = buildUrl baseUrl (Proxy :: _ segments) pathParamsRec queryParamsRec
117 let url = buildUrl baseUrl (Proxy :: _ segments) pathParamsRec queryParamsRec
114 let hdrs = toHeaders (Proxy :: _ headersRL) headersRec
118 let hdrs = toHeaders (Proxy :: _ headersRL) headersRec
115 let ct = encodingContentType (Proxy :: _ encoding)
119 let ct = encodingContentType (Proxy :: _ encoding)
@@ -118,7 +122,6 @@ instance
118 variantOrValue (Proxy :: _ successRL) variant # pure
122 variantOrValue (Proxy :: _ successRL) variant # pure
120 pathParamsRec = unsafeCoerce pathQueryRec :: Record pathParams
124 pathParamsRec = unsafeCoerce pathQueryRec :: Record pathParams
121− queryParamsRec = unsafeCoerce pathQueryRec :: Record queryParams
122 widenOm :: Om (Record ()) routeErrors ~> Om { | ctx } errRow
125 widenOm :: Om (Record ()) routeErrors ~> Om { | ctx } errRow
123 widenOm = unsafeCoerce
126 widenOm = unsafeCoerce
@@ -146,15 +149,6 @@ deriveClient baseUrl = deriveClientImpl @ctx @extraErr baseUrl (Proxy :: _ { | r
146plainText :: PlainText -> String
149plainText :: PlainText -> String
147plainText = unsafeCoerce
150plainText = unsafeCoerce
149−-- | Convert a partial record to a full query params record.
150−-- | Provided fields get `Just`, missing fields get `Nothing`.
153−-- | api.listUsers $ opt { limit: 10 }
154−-- | -- instead of: api.listUsers { limit: Just 10, offset: Nothing }
156−opt :: forall @queryParams provided. BuildQueryFromPartial queryParams provided => Record provided -> Record queryParams
157−opt = buildQueryFromPartial
160 ( RowToList routesRow rl
154 ( RowToList routesRow rl
@@ -172,7 +166,7 @@ instance DeriveClientRL ctx extraErr RL.Nil acc acc where
174 ( IsSymbol label
168 ( IsSymbol label
175− , DeriveClientFn method segments request response ctx extraErr routeErrors result fn
169+ , DeriveClientFn method segments request response ctx extraErr given routeErrors result fn
176 , DeriveClientRL ctx extraErr tail acc1 acc2
170 , DeriveClientRL ctx extraErr tail acc1 acc2
177 , Row.Cons label fn acc2 out
171 , Row.Cons label fn acc2 out
178 , Row.Lacks label acc2
172 , Row.Lacks label acc2
@@ -181,5 +175,5 @@ instance
181 DeriveClientRL ctx extraErr (RL.Cons label (Route method segments request response) tail) acc1 out where
175 DeriveClientRL ctx extraErr (RL.Cons label (Route method segments request response) tail) acc1 out where
182 deriveClientRL baseUrl _ acc = Record.insert (Proxy :: _ label) clientFn rest
176 deriveClientRL baseUrl _ acc = Record.insert (Proxy :: _ label) clientFn rest
184− clientFn = deriveClientFn @_ @_ @_ @_ @ctx @extraErr baseUrl (Proxy :: _ (Route method segments request response))
178+ clientFn = deriveClientFn @_ @_ @_ @_ @ctx @extraErr @given baseUrl (Proxy :: _ (Route method segments request response))
185 rest = deriveClientRL @ctx @extraErr baseUrl (Proxy :: _ tail) acc
179 rest = deriveClientRL @ctx @extraErr baseUrl (Proxy :: _ tail) acc