@@ -13,7 +13,6 @@ module Yoga.Fetch.Om
1313 , module Yoga.HTTP.API.Route
1414 , module Yoga.HTTP.API.Path
1515 , plainText
16− , opt
1716 , module Yoga.Fetch.Om.StreamDecode
1817 , module Yoga.Fetch.Om.Simple
1918 ) where
@@ -35,7 +34,7 @@ import Yoga.Fetch.Om.BuildUrl (class BuildUrl, buildUrl)
3534import Yoga.Fetch.Om.Simple (class DecodeResponse, decodeResponse, FetchError, FetchResponse, get, getWithHeaders, delete, deleteWithHeaders, delete_, post, postWithHeaders, post_, put, putWithHeaders, put_, patch, patchWithHeaders, patch_)
3635import Yoga.Fetch.Om.StreamDecode (class StreamDecode, decodeStream)
3736import 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)
3938import Yoga.Fetch.Om.ExtractParams (class ExtractRequestBody, class ExtractBodyEncoding, class ExtractRequestHeaders)
4039import Yoga.Fetch.Om.MakeRequest (class MakeRequest, class BodyEncoding, makeRequest, encodingContentType, encodeBody)
4140import Yoga.Fetch.Om.ParseResponse (class ParseResponse, parseResponse)
@@ -74,11 +73,11 @@ else instance
7473 rest = toHeaders (Proxy :: Proxy tail) (unsafeCoerce headers :: Record tailRow)
7574
7675class 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
7877class
79− DeriveClientFn method segments request response ctx extraErr routeErrors result fn
78+ DeriveClientFn method segments request response ctx extraErr given routeErrors result fn
8079 | 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
8281 deriveClientFn :: String -> Proxy (Route method segments request response) -> fn
8382
8483instance
@@ -98,18 +97,23 @@ instance
9897 , Row.Union pathParams queryParams pathQuery
9998 , Row.Nub pathQuery pathQuery
10099 , RowToList pathQuery pathQueryRL
100+ , RowToList queryParams queryParamsRL
101+ , ReadPartialQuery queryParamsRL queryParams
101102 , RowToList headers headersRL
102103 , ToHeaders headersRL headers
103104 , CheckBodyIsUnit body bodyFlag
104105 , 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
106107 ) =>
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
108109 deriveClientFn baseUrl _ =
109− buildClientFn (Proxy :: _ pathQueryRL) (Proxy :: _ headersRL) (Proxy :: _ bodyFlag) impl
110+ buildClientFn (Proxy :: _ pathQueryRL) (Proxy :: _ headersRL) (Proxy :: _ bodyFlag) convert impl
110111 where
112+ convert :: Record given -> Record pathQuery
113+ convert = unsafeCoerce
111114 impl :: Record pathQuery -> Record headers -> body -> Om { | ctx } errRow result
112115 impl pathQueryRec headersRec bodyVal = widenOm do
116+ let queryParamsRec = readPartialQuery @queryParamsRL pathQueryRec
113117 let url = buildUrl baseUrl (Proxy :: _ segments) pathParamsRec queryParamsRec
114118 let hdrs = toHeaders (Proxy :: _ headersRL) headersRec
115119 let ct = encodingContentType (Proxy :: _ encoding)
@@ -118,7 +122,6 @@ instance
118122 variantOrValue (Proxy :: _ successRL) variant # pure
119123 where
120124 pathParamsRec = unsafeCoerce pathQueryRec :: Record pathParams
121− queryParamsRec = unsafeCoerce pathQueryRec :: Record queryParams
122125 widenOm :: Om (Record ()) routeErrors ~> Om { | ctx } errRow
123126 widenOm = unsafeCoerce
124127
@@ -146,15 +149,6 @@ deriveClient baseUrl = deriveClientImpl @ctx @extraErr baseUrl (Proxy :: _ { | r
146149plainText :: PlainText -> String
147150plainText = unsafeCoerce
148151
149−-- | Convert a partial record to a full query params record.
150−-- | Provided fields get `Just`, missing fields get `Nothing`.
151−-- |
152−-- | ```purescript
153−-- | api.listUsers $ opt { limit: 10 }
154−-- | -- instead of: api.listUsers { limit: Just 10, offset: Nothing }
155−-- | ```
156−opt :: forall @queryParams provided. BuildQueryFromPartial queryParams provided => Record provided -> Record queryParams
157−opt = buildQueryFromPartial
158152
159153instance
160154 ( RowToList routesRow rl
@@ -172,7 +166,7 @@ instance DeriveClientRL ctx extraErr RL.Nil acc acc where
172166
173167instance
174168 ( 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
176170 , DeriveClientRL ctx extraErr tail acc1 acc2
177171 , Row.Cons label fn acc2 out
178172 , Row.Lacks label acc2
@@ -181,5 +175,5 @@ instance
181175 DeriveClientRL ctx extraErr (RL.Cons label (Route method segments request response) tail) acc1 out where
182176 deriveClientRL baseUrl _ acc = Record.insert (Proxy :: _ label) clientFn rest
183177 where
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))
185179 rest = deriveClientRL @ctx @extraErr baseUrl (Proxy :: _ tail) acc