on master help sign in
[servant-foreign] Normalise names of arg field accessors
bfe812fSteve Purcell
servant-foreign/src/Servant/Foreign.hs+5−5
@@ -15,9 +15,9 @@ module Servant.Foreign
15 , FunctionName(..)
15 , FunctionName(..)
16 , PathSegment(..)
16 , PathSegment(..)
17 -- lenses
17 -- lenses
18− , aName
18+ , argName
19− , aType
19+ , argType
20− , aPath
20+ , argPath
21 , reqUrl
21 , reqUrl
22 , reqMethod
22 , reqMethod
23 , reqHeaders
23 , reqHeaders
@@ -26,8 +26,8 @@ module Servant.Foreign
26 , reqFuncName
26 , reqFuncName
27 , path
27 , path
28 , queryStr
28 , queryStr
29− , argName
29+ , queryArgName
30− , argType
30+ , queryArgType
31 , headerArg
31 , headerArg
32 -- prisms
32 -- prisms
33 , _PathSegment
33 , _PathSegment
servant-foreign/src/Servant/Foreign/Internal.hs+16−16
@@ -38,14 +38,14 @@ newtype PathSegment = PathSegment { unPathSegment :: Text }
38makePrisms ''PathSegment
38makePrisms ''PathSegment
39
39
40data Arg = Arg
40data Arg = Arg
41− { _aName :: PathSegment
41+ { _argName :: PathSegment
42− , _aType :: ForeignType }
42+ , _argType :: ForeignType }
43 deriving (Show, Eq)
43 deriving (Show, Eq)
44
44
45makeLenses ''Arg
45makeLenses ''Arg
46
46
47−aPath :: Getter Arg Text
47+argPath :: Getter Arg Text
48−aPath = aName . _PathSegment
48+argPath = argName . _PathSegment
49
49
50data SegmentType
50data SegmentType
51 = Static PathSegment
51 = Static PathSegment
@@ -80,8 +80,8 @@ data ArgType
80makePrisms ''ArgType
80makePrisms ''ArgType
81
81
82data QueryArg = QueryArg
82data QueryArg = QueryArg
83− { _argName :: Arg
83+ { _queryArgName :: Arg
84− , _argType :: ArgType
84+ , _queryArgType :: ArgType
85 } deriving (Eq, Show)
85 } deriving (Eq, Show)
86
86
87makeLenses ''QueryArg
87makeLenses ''QueryArg
@@ -194,8 +194,8 @@ instance (KnownSymbol sym, HasForeignType lang ftype, HasForeign lang sublayout)
194 str = pack . symbolVal $ (Proxy :: Proxy sym)
194 str = pack . symbolVal $ (Proxy :: Proxy sym)
195 ftype = typeFor lang (Proxy :: Proxy ftype)
195 ftype = typeFor lang (Proxy :: Proxy ftype)
196 arg = Arg
196 arg = Arg
197− { _aName = PathSegment str
197+ { _argName = PathSegment str
198− , _aType = ftype }
198+ , _argType = ftype }
199
199
200instance (Elem JSON list, HasForeignType lang a, ReflectMethod method)
200instance (Elem JSON list, HasForeignType lang a, ReflectMethod method)
201 => HasForeign lang (Verb method status list a) where
201 => HasForeign lang (Verb method status list a) where
@@ -219,8 +219,8 @@ instance (KnownSymbol sym, HasForeignType lang a, HasForeign lang sublayout)
219 where
219 where
220 hname = pack . symbolVal $ (Proxy :: Proxy sym)
220 hname = pack . symbolVal $ (Proxy :: Proxy sym)
221 arg = Arg
221 arg = Arg
222− { _aName = PathSegment hname
222+ { _argName = PathSegment hname
223− , _aType = typeFor lang (Proxy :: Proxy a) }
223+ , _argType = typeFor lang (Proxy :: Proxy a) }
224 subP = Proxy :: Proxy sublayout
224 subP = Proxy :: Proxy sublayout
225
225
226instance (KnownSymbol sym, HasForeignType lang a, HasForeign lang sublayout)
226instance (KnownSymbol sym, HasForeignType lang a, HasForeign lang sublayout)
@@ -233,8 +233,8 @@ instance (KnownSymbol sym, HasForeignType lang a, HasForeign lang sublayout)
233 where
233 where
234 str = pack . symbolVal $ (Proxy :: Proxy sym)
234 str = pack . symbolVal $ (Proxy :: Proxy sym)
235 arg = Arg
235 arg = Arg
236− { _aName = PathSegment str
236+ { _argName = PathSegment str
237− , _aType = typeFor lang (Proxy :: Proxy a) }
237+ , _argType = typeFor lang (Proxy :: Proxy a) }
238
238
239instance
239instance
240 (KnownSymbol sym, HasForeignType lang [a], HasForeign lang sublayout)
240 (KnownSymbol sym, HasForeignType lang [a], HasForeign lang sublayout)
@@ -246,8 +246,8 @@ instance
246 where
246 where
247 str = pack . symbolVal $ (Proxy :: Proxy sym)
247 str = pack . symbolVal $ (Proxy :: Proxy sym)
248 arg = Arg
248 arg = Arg
249− { _aName = PathSegment str
249+ { _argName = PathSegment str
250− , _aType = typeFor lang (Proxy :: Proxy [a]) }
250+ , _argType = typeFor lang (Proxy :: Proxy [a]) }
251
251
252instance
252instance
253 (KnownSymbol sym, HasForeignType lang Bool, HasForeign lang sublayout)
253 (KnownSymbol sym, HasForeignType lang Bool, HasForeign lang sublayout)
@@ -260,8 +260,8 @@ instance
260 where
260 where
261 str = pack . symbolVal $ (Proxy :: Proxy sym)
261 str = pack . symbolVal $ (Proxy :: Proxy sym)
262 arg = Arg
262 arg = Arg
263− { _aName = PathSegment str
263+ { _argName = PathSegment str
264− , _aType = typeFor lang (Proxy :: Proxy Bool) }
264+ , _argType = typeFor lang (Proxy :: Proxy Bool) }
265
265
266instance HasForeign lang Raw where
266instance HasForeign lang Raw where
267 type Foreign Raw = HTTP.Method -> Req
267 type Foreign Raw = HTTP.Method -> Req
servant-js/src/Servant/JS/Angular.hs+4−4
@@ -76,11 +76,11 @@ generateAngularJSWith ngOptions opts req = "\n" <>
76 where argsStr = T.intercalate ", " args
76 where argsStr = T.intercalate ", " args
77 args = http
77 args = http
78 ++ captures
78 ++ captures
79− ++ map (view $ argName . aPath) queryparams
79+ ++ map (view $ queryArgName . argPath) queryparams
80 ++ body
80 ++ body
81 ++ map ( toValidFunctionName
81 ++ map ( toValidFunctionName
82 . (<>) "header"
82 . (<>) "header"
83− . view (headerArg . aPath)
83+ . view (headerArg . argPath)
84 ) hs
84 ) hs
85
85
86 -- If we want to generate Top Level Function, they must depend on
86 -- If we want to generate Top Level Function, they must depend on
@@ -90,7 +90,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
90 0 -> ["$http"]
90 0 -> ["$http"]
91 _ -> []
91 _ -> []
92
92
93− captures = map (view aPath . captureArg)
93+ captures = map (view argPath . captureArg)
94 . filter isCapture
94 . filter isCapture
95 $ req ^. reqUrl . path
95 $ req ^. reqUrl . path
96
96
@@ -116,7 +116,7 @@ generateAngularJSWith ngOptions opts req = "\n" <>
116 where
116 where
117 headersStr = T.intercalate ", " $ map headerStr hs
117 headersStr = T.intercalate ", " $ map headerStr hs
118 headerStr header = "\"" <>
118 headerStr header = "\"" <>
119− header ^. headerArg . aPath <>
119+ header ^. headerArg . argPath <>
120 "\": " <> toJSHeader header
120 "\": " <> toJSHeader header
121
121
122 namespace =
122 namespace =
servant-js/src/Servant/JS/Axios.hs+4−4
@@ -62,14 +62,14 @@ generateAxiosJSWith aopts opts req = "\n" <>
62
62
63 where argsStr = T.intercalate ", " args
63 where argsStr = T.intercalate ", " args
64 args = captures
64 args = captures
65− ++ map (view $ argName . aPath) queryparams
65+ ++ map (view $ queryArgName . argPath) queryparams
66 ++ body
66 ++ body
67 ++ map ( toValidFunctionName
67 ++ map ( toValidFunctionName
68 . (<>) "header"
68 . (<>) "header"
69− . view (headerArg . aPath)
69+ . view (headerArg . argPath)
70 ) hs
70 ) hs
71
71
72− captures = map (view aPath . captureArg)
72+ captures = map (view argPath . captureArg)
73 . filter isCapture
73 . filter isCapture
74 $ req ^. reqUrl.path
74 $ req ^. reqUrl.path
75
75
@@ -110,7 +110,7 @@ generateAxiosJSWith aopts opts req = "\n" <>
110 where
110 where
111 headersStr = T.intercalate ", " $ map headerStr hs
111 headersStr = T.intercalate ", " $ map headerStr hs
112 headerStr header = "\"" <>
112 headerStr header = "\"" <>
113− header ^. headerArg . aPath <>
113+ header ^. headerArg . argPath <>
114 "\": " <> toJSHeader header
114 "\": " <> toJSHeader header
115
115
116 namespace =
116 namespace =
servant-js/src/Servant/JS/Internal.hs+6−6
@@ -141,7 +141,7 @@ toValidFunctionName t =
141
141
142toJSHeader :: HeaderArg -> Text
142toJSHeader :: HeaderArg -> Text
143toJSHeader (HeaderArg n)
143toJSHeader (HeaderArg n)
144− = toValidFunctionName ("header" <> n ^. aName . _PathSegment)
144+ = toValidFunctionName ("header" <> n ^. argName . _PathSegment)
145toJSHeader (ReplaceHeaderArg n p)
145toJSHeader (ReplaceHeaderArg n p)
146 | pn `T.isPrefixOf` p = pv <> " + \"" <> rp <> "\""
146 | pn `T.isPrefixOf` p = pv <> " + \"" <> rp <> "\""
147 | pn `T.isSuffixOf` p = "\"" <> rp <> "\" + " <> pv
147 | pn `T.isSuffixOf` p = "\"" <> rp <> "\" + " <> pv
@@ -149,8 +149,8 @@ toJSHeader (ReplaceHeaderArg n p)
149 <> "\""
149 <> "\""
150 | otherwise = p
150 | otherwise = p
151 where
151 where
152− pv = toValidFunctionName ("header" <> n ^. aName . _PathSegment)
152+ pv = toValidFunctionName ("header" <> n ^. argName . _PathSegment)
153− pn = "{" <> n ^. aName . _PathSegment <> "}"
153+ pn = "{" <> n ^. argName . _PathSegment <> "}"
154 rp = T.replace pn "" p
154 rp = T.replace pn "" p
155
155
156jsSegments :: [Segment] -> Text
156jsSegments :: [Segment] -> Text
@@ -165,7 +165,7 @@ segmentToStr (Segment st) notTheEnd =
165segmentTypeToStr :: SegmentType -> Text
165segmentTypeToStr :: SegmentType -> Text
166segmentTypeToStr (Static s) = s ^. _PathSegment
166segmentTypeToStr (Static s) = s ^. _PathSegment
167segmentTypeToStr (Cap s) =
167segmentTypeToStr (Cap s) =
168− "' + encodeURIComponent(" <> s ^. aName . _PathSegment <> ") + '"
168+ "' + encodeURIComponent(" <> s ^. argName . _PathSegment <> ") + '"
169
169
170jsGParams :: Text -> [QueryArg] -> Text
170jsGParams :: Text -> [QueryArg] -> Text
171jsGParams _ [] = ""
171jsGParams _ [] = ""
@@ -177,7 +177,7 @@ jsParams = jsGParams "&"
177
177
178paramToStr :: QueryArg -> Bool -> Text
178paramToStr :: QueryArg -> Bool -> Text
179paramToStr qarg notTheEnd =
179paramToStr qarg notTheEnd =
180− case qarg ^. argType of
180+ case qarg ^. queryArgType of
181 Normal -> name
181 Normal -> name
182 <> "=' + encodeURIComponent("
182 <> "=' + encodeURIComponent("
183 <> name
183 <> name
@@ -187,4 +187,4 @@ paramToStr qarg notTheEnd =
187 <> "[]=' + encodeURIComponent("
187 <> "[]=' + encodeURIComponent("
188 <> name
188 <> name
189 <> if notTheEnd then ") + '" else ")"
189 <> 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" <>
43
43
44 where argsStr = T.intercalate ", " args
44 where argsStr = T.intercalate ", " args
45 args = captures
45 args = captures
46− ++ map (view $ argName . aPath) queryparams
46+ ++ map (view $ queryArgName . argPath) queryparams
47 ++ body
47 ++ body
48 ++ map (toValidFunctionName
48 ++ map (toValidFunctionName
49 . (<>) "header"
49 . (<>) "header"
50− . view (headerArg . aPath)
50+ . view (headerArg . argPath)
51 ) hs
51 ) hs
52 ++ [onSuccess, onError]
52 ++ [onSuccess, onError]
53
53
54− captures = map (view aPath . captureArg)
54+ captures = map (view argPath . captureArg)
55 . filter isCapture
55 . filter isCapture
56 $ req ^. reqUrl.path
56 $ req ^. reqUrl.path
57
57
@@ -80,7 +80,7 @@ generateJQueryJSWith opts req = "\n" <>
80 where
80 where
81 headersStr = T.intercalate ", " $ map headerStr hs
81 headersStr = T.intercalate ", " $ map headerStr hs
82 headerStr header = "\"" <>
82 headerStr header = "\"" <>
83− header ^. headerArg . aPath <>
83+ header ^. headerArg . argPath <>
84 "\": " <> toJSHeader header
84 "\": " <> toJSHeader header
85
85
86 namespace = if (moduleName opts) == ""
86 namespace = if (moduleName opts) == ""
servant-js/src/Servant/JS/Vanilla.hs+4−4
@@ -54,15 +54,15 @@ generateVanillaJSWith opts req = "\n" <>
54
54
55 where argsStr = T.intercalate ", " args
55 where argsStr = T.intercalate ", " args
56 args = captures
56 args = captures
57− ++ map (view $ argName . aPath) queryparams
57+ ++ map (view $ queryArgName . argPath) queryparams
58 ++ body
58 ++ body
59 ++ map ( toValidFunctionName
59 ++ map ( toValidFunctionName
60 . (<>) "header"
60 . (<>) "header"
61− . view (headerArg . aPath)
61+ . view (headerArg . argPath)
62 ) hs
62 ) hs
63 ++ [onSuccess, onError]
63 ++ [onSuccess, onError]
64
64
65− captures = map (view aPath . captureArg)
65+ captures = map (view argPath . captureArg)
66 . filter isCapture
66 . filter isCapture
67 $ req ^. reqUrl.path
67 $ req ^. reqUrl.path
68
68
@@ -91,7 +91,7 @@ generateVanillaJSWith opts req = "\n" <>
91 where
91 where
92 headersStr = T.intercalate "\n" $ map headerStr hs
92 headersStr = T.intercalate "\n" $ map headerStr hs
93 headerStr header = " xhr.setRequestHeader(\"" <>
93 headerStr header = " xhr.setRequestHeader(\"" <>
94− header ^. headerArg . aPath <>
94+ header ^. headerArg . argPath <>
95 "\", " <> toJSHeader header <> ");"
95 "\", " <> toJSHeader header <> ");"
96
96
97 namespace = if moduleName opts == ""
97 namespace = if moduleName opts == ""