git.iko.soy/typeable/servant
on master help sign in
[servant-foreign] Normalise names of arg field accessors
commitbfe812f5d91f699d41bfdc5c66e3eb934db23971 authorSteve Purcell <steve@sanityinc.com> dateSun 13 Mar 2016, 17:02 (11 years ago) parente34003e
7 files changed+43−43
servant-foreign/src/Servant/Foreign.hs+5−5 servant-foreign/src/Servant/Foreign/Internal.hs+16−16 servant-js/src/Servant/JS/Angular.hs+4−4 servant-js/src/Servant/JS/Axios.hs+4−4 servant-js/src/Servant/JS/Internal.hs+6−6 servant-js/src/Servant/JS/JQuery.hs+4−4 servant-js/src/Servant/JS/Vanilla.hs+4−4
servant-foreign/src/Servant/Foreign.hs+5−5
@@ -15,9 +15,9 @@ module Servant.Foreign
1515 , FunctionName(..)
1616 , PathSegment(..)
1717 -- lenses
18− , aName
19− , aType
20− , aPath
18+ , argName
19+ , argType
20+ , argPath
2121 , reqUrl
2222 , reqMethod
2323 , reqHeaders
@@ -26,8 +26,8 @@ module Servant.Foreign
2626 , reqFuncName
2727 , path
2828 , queryStr
29− , argName
30− , argType
29+ , queryArgName
30+ , queryArgType
3131 , headerArg
3232 -- prisms
3333 , _PathSegment
servant-foreign/src/Servant/Foreign/Internal.hs+16−16
@@ -38,14 +38,14 @@ newtype PathSegment = PathSegment { unPathSegment :: Text }
3838makePrisms ''PathSegment
3939
4040data Arg = Arg
41− { _aName :: PathSegment
42− , _aType :: ForeignType }
41+ { _argName :: PathSegment
42+ , _argType :: ForeignType }
4343 deriving (Show, Eq)
4444
4545makeLenses ''Arg
4646
47−aPath :: Getter Arg Text
48−aPath = aName . _PathSegment
47+argPath :: Getter Arg Text
48+argPath = argName . _PathSegment
4949
5050data SegmentType
5151 = Static PathSegment
@@ -80,8 +80,8 @@ data ArgType
8080makePrisms ''ArgType
8181
8282data QueryArg = QueryArg
83− { _argName :: Arg
84− , _argType :: ArgType
83+ { _queryArgName :: Arg
84+ , _queryArgType :: ArgType
8585 } deriving (Eq, Show)
8686
8787makeLenses ''QueryArg
@@ -194,8 +194,8 @@ instance (KnownSymbol sym, HasForeignType lang ftype, HasForeign lang sublayout)
194194 str = pack . symbolVal $ (Proxy :: Proxy sym)
195195 ftype = typeFor lang (Proxy :: Proxy ftype)
196196 arg = Arg
197− { _aName = PathSegment str
198− , _aType = ftype }
197+ { _argName = PathSegment str
198+ , _argType = ftype }
199199
200200instance (Elem JSON list, HasForeignType lang a, ReflectMethod method)
201201 => HasForeign lang (Verb method status list a) where
@@ -219,8 +219,8 @@ instance (KnownSymbol sym, HasForeignType lang a, HasForeign lang sublayout)
219219 where
220220 hname = pack . symbolVal $ (Proxy :: Proxy sym)
221221 arg = Arg
222− { _aName = PathSegment hname
223− , _aType = typeFor lang (Proxy :: Proxy a) }
222+ { _argName = PathSegment hname
223+ , _argType = typeFor lang (Proxy :: Proxy a) }
224224 subP = Proxy :: Proxy sublayout
225225
226226instance (KnownSymbol sym, HasForeignType lang a, HasForeign lang sublayout)
@@ -233,8 +233,8 @@ instance (KnownSymbol sym, HasForeignType lang a, HasForeign lang sublayout)
233233 where
234234 str = pack . symbolVal $ (Proxy :: Proxy sym)
235235 arg = Arg
236− { _aName = PathSegment str
237− , _aType = typeFor lang (Proxy :: Proxy a) }
236+ { _argName = PathSegment str
237+ , _argType = typeFor lang (Proxy :: Proxy a) }
238238
239239instance
240240 (KnownSymbol sym, HasForeignType lang [a], HasForeign lang sublayout)
@@ -246,8 +246,8 @@ instance
246246 where
247247 str = pack . symbolVal $ (Proxy :: Proxy sym)
248248 arg = Arg
249− { _aName = PathSegment str
250− , _aType = typeFor lang (Proxy :: Proxy [a]) }
249+ { _argName = PathSegment str
250+ , _argType = typeFor lang (Proxy :: Proxy [a]) }
251251
252252instance
253253 (KnownSymbol sym, HasForeignType lang Bool, HasForeign lang sublayout)
@@ -260,8 +260,8 @@ instance
260260 where
261261 str = pack . symbolVal $ (Proxy :: Proxy sym)
262262 arg = Arg
263− { _aName = PathSegment str
264− , _aType = typeFor lang (Proxy :: Proxy Bool) }
263+ { _argName = PathSegment str
264+ , _argType = typeFor lang (Proxy :: Proxy Bool) }
265265
266266instance HasForeign lang Raw where
267267 type Foreign Raw = HTTP.Method -> Req
servant-js/src/Servant/JS/Angular.hs+4−4
@@ -76,11 +76,11 @@ generateAngularJSWith ngOptions opts req = "\n" <>
7676 where argsStr = T.intercalate ", " args
7777 args = http
7878 ++ captures
79− ++ map (view $ argName . aPath) queryparams
79+ ++ map (view $ queryArgName . argPath) queryparams
8080 ++ body
8181 ++ map ( toValidFunctionName
8282 . (<>) "header"
83− . view (headerArg . aPath)
83+ . view (headerArg . argPath)
8484 ) hs
8585
8686 -- If we want to generate Top Level Function, they must depend on
@@ -90,7 +90,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
9090 0 -> ["$http"]
9191 _ -> []
9292
93− captures = map (view aPath . captureArg)
93+ captures = map (view argPath . captureArg)
9494 . filter isCapture
9595 $ req ^. reqUrl . path
9696
@@ -116,7 +116,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
116116 where
117117 headersStr = T.intercalate ", " $ map headerStr hs
118118 headerStr header = "\"" <>
119− header ^. headerArg . aPath <>
119+ header ^. headerArg . argPath <>
120120 "\": " <> toJSHeader header
121121
122122 namespace =
servant-js/src/Servant/JS/Axios.hs+4−4
@@ -62,14 +62,14 @@ generateAxiosJSWith aopts opts req = "\n" <>
6262
6363 where argsStr = T.intercalate ", " args
6464 args = captures
65− ++ map (view $ argName . aPath) queryparams
65+ ++ map (view $ queryArgName . argPath) queryparams
6666 ++ body
6767 ++ map ( toValidFunctionName
6868 . (<>) "header"
69− . view (headerArg . aPath)
69+ . view (headerArg . argPath)
7070 ) hs
7171
72− captures = map (view aPath . captureArg)
72+ captures = map (view argPath . captureArg)
7373 . filter isCapture
7474 $ req ^. reqUrl.path
7575
@@ -110,7 +110,7 @@ generateAxiosJSWith aopts opts req = "\n" <>
110110 where
111111 headersStr = T.intercalate ", " $ map headerStr hs
112112 headerStr header = "\"" <>
113− header ^. headerArg . aPath <>
113+ header ^. headerArg . argPath <>
114114 "\": " <> toJSHeader header
115115
116116 namespace =
servant-js/src/Servant/JS/Internal.hs+6−6
@@ -141,7 +141,7 @@ toValidFunctionName t =
141141
142142toJSHeader :: HeaderArg -> Text
143143toJSHeader (HeaderArg n)
144− = toValidFunctionName ("header" <> n ^. aName . _PathSegment)
144+ = toValidFunctionName ("header" <> n ^. argName . _PathSegment)
145145toJSHeader (ReplaceHeaderArg n p)
146146 | pn `T.isPrefixOf` p = pv <> " + \"" <> rp <> "\""
147147 | pn `T.isSuffixOf` p = "\"" <> rp <> "\" + " <> pv
@@ -149,8 +149,8 @@ toJSHeader (ReplaceHeaderArg n p)
149149 <> "\""
150150 | otherwise = p
151151 where
152− pv = toValidFunctionName ("header" <> n ^. aName . _PathSegment)
153− pn = "{" <> n ^. aName . _PathSegment <> "}"
152+ pv = toValidFunctionName ("header" <> n ^. argName . _PathSegment)
153+ pn = "{" <> n ^. argName . _PathSegment <> "}"
154154 rp = T.replace pn "" p
155155
156156jsSegments :: [Segment] -> Text
@@ -165,7 +165,7 @@ segmentToStr (Segment st) notTheEnd =
165165segmentTypeToStr :: SegmentType -> Text
166166segmentTypeToStr (Static s) = s ^. _PathSegment
167167segmentTypeToStr (Cap s) =
168− "' + encodeURIComponent(" <> s ^. aName . _PathSegment <> ") + '"
168+ "' + encodeURIComponent(" <> s ^. argName . _PathSegment <> ") + '"
169169
170170jsGParams :: Text -> [QueryArg] -> Text
171171jsGParams _ [] = ""
@@ -177,7 +177,7 @@ jsParams = jsGParams "&"
177177
178178paramToStr :: QueryArg -> Bool -> Text
179179paramToStr qarg notTheEnd =
180− case qarg ^. argType of
180+ case qarg ^. queryArgType of
181181 Normal -> name
182182 <> "=' + encodeURIComponent("
183183 <> name
@@ -187,4 +187,4 @@ paramToStr qarg notTheEnd =
187187 <> "[]=' + encodeURIComponent("
188188 <> name
189189 <> if notTheEnd then ") + '" else ")"
190− where name = qarg ^. argName . aName . _PathSegment
190+ where name = qarg ^. queryArgName . argName . _PathSegment
servant-js/src/Servant/JS/JQuery.hs+4−4
@@ -43,15 +43,15 @@ generateJQueryJSWith opts req = "\n" <>
4343
4444 where argsStr = T.intercalate ", " args
4545 args = captures
46− ++ map (view $ argName . aPath) queryparams
46+ ++ map (view $ queryArgName . argPath) queryparams
4747 ++ body
4848 ++ map (toValidFunctionName
4949 . (<>) "header"
50− . view (headerArg . aPath)
50+ . view (headerArg . argPath)
5151 ) hs
5252 ++ [onSuccess, onError]
5353
54− captures = map (view aPath . captureArg)
54+ captures = map (view argPath . captureArg)
5555 . filter isCapture
5656 $ req ^. reqUrl.path
5757
@@ -80,7 +80,7 @@ generateJQueryJSWith opts req = "\n" <>
8080 where
8181 headersStr = T.intercalate ", " $ map headerStr hs
8282 headerStr header = "\"" <>
83− header ^. headerArg . aPath <>
83+ header ^. headerArg . argPath <>
8484 "\": " <> toJSHeader header
8585
8686 namespace = if (moduleName opts) == ""
servant-js/src/Servant/JS/Vanilla.hs+4−4
@@ -54,15 +54,15 @@ generateVanillaJSWith opts req = "\n" <>
5454
5555 where argsStr = T.intercalate ", " args
5656 args = captures
57− ++ map (view $ argName . aPath) queryparams
57+ ++ map (view $ queryArgName . argPath) queryparams
5858 ++ body
5959 ++ map ( toValidFunctionName
6060 . (<>) "header"
61− . view (headerArg . aPath)
61+ . view (headerArg . argPath)
6262 ) hs
6363 ++ [onSuccess, onError]
6464
65− captures = map (view aPath . captureArg)
65+ captures = map (view argPath . captureArg)
6666 . filter isCapture
6767 $ req ^. reqUrl.path
6868
@@ -91,7 +91,7 @@ generateVanillaJSWith opts req = "\n" <>
9191 where
9292 headersStr = T.intercalate "\n" $ map headerStr hs
9393 headerStr header = " xhr.setRequestHeader(\"" <>
94− header ^. headerArg . aPath <>
94+ header ^. headerArg . argPath <>
9595 "\", " <> toJSHeader header <> ");"
9696
9797 namespace = if moduleName opts == ""