@@ -27,8 +27,12 @@ newtype FunctionName = FunctionName { unFunctionName :: [Text] }
28makePrisms ''FunctionName
28makePrisms ''FunctionName
30−newtype ForeignType = ForeignType { unForeignType :: Text }
30+newtype ForeignType f = ForeignType { unForeignType :: f }
31− deriving (Show, Eq, IsString, Monoid)
31+
32+deriving instance Show f => Show (ForeignType f)
33+deriving instance Eq f => Eq (ForeignType f)
34+deriving instance IsString f => IsString (ForeignType f)
35+deriving instance Monoid f => Monoid (ForeignType f)
33makePrisms ''ForeignType
37makePrisms ''ForeignType
@@ -37,39 +41,45 @@ newtype PathSegment = PathSegment { unPathSegment :: Text }
38makePrisms ''PathSegment
42makePrisms ''PathSegment
40−data Arg = Arg
44+data Arg f = Arg
41 { _argName :: PathSegment
45 { _argName :: PathSegment
42− , _argType :: ForeignType }
46+ , _argType :: ForeignType f }
43− deriving (Show, Eq)
48+deriving instance Eq f => Eq (Arg f)
49+deriving instance Show f => Show (Arg f)
45makeLenses ''Arg
51makeLenses ''Arg
47−argPath :: Getter Arg Text
53+argPath :: Getter (Arg f) Text
48argPath = argName . _PathSegment
54argPath = argName . _PathSegment
50−data SegmentType
56+data SegmentType f
51 = Static PathSegment
57 = Static PathSegment
52 -- ^ a static path segment. like "/foo"
58 -- ^ a static path segment. like "/foo"
53− | Cap Arg
59+ | Cap (Arg f)
54 -- ^ a capture. like "/:userid"
60 -- ^ a capture. like "/:userid"
55− deriving (Show, Eq)
61+
62+deriving instance Eq f => Eq (SegmentType f)
63+deriving instance Show f => Show (SegmentType f)
57makePrisms ''SegmentType
65makePrisms ''SegmentType
59−newtype Segment = Segment { unSegment :: SegmentType }
67+newtype Segment f = Segment { unSegment :: SegmentType f }
60− deriving (Eq, Show)
69+deriving instance Eq f => Eq (Segment f)
70+deriving instance Show f => Show (Segment f)
62makePrisms ''Segment
72makePrisms ''Segment
64−isCapture :: Segment -> Bool
74+isCapture :: Segment f -> Bool
65isCapture (Segment (Cap _)) = True
75isCapture (Segment (Cap _)) = True
66isCapture _ = False
76isCapture _ = False
68−captureArg :: Segment -> Arg
78+captureArg :: Segment f -> Arg f
69captureArg (Segment (Cap s)) = s
79captureArg (Segment (Cap s)) = s
70captureArg _ = error "captureArg called on non capture"
80captureArg _ = error "captureArg called on non capture"
72−type Path = [Segment]
82+type Path f = [Segment f]
74data ArgType
84data ArgType
@@ -79,46 +89,58 @@ data ArgType
80makePrisms ''ArgType
90makePrisms ''ArgType
82−data QueryArg = QueryArg
92+data QueryArg f = QueryArg
83− { _queryArgName :: Arg
93+ { _queryArgName :: Arg f
84 , _queryArgType :: ArgType
94 , _queryArgType :: ArgType
97+deriving instance Eq f => Eq (QueryArg f)
85− } deriving (Eq, Show)
98+deriving instance Show f => Show (QueryArg f)
87makeLenses ''QueryArg
100makeLenses ''QueryArg
89−data HeaderArg = HeaderArg
102+data HeaderArg f = HeaderArg
90− { _headerArg :: Arg }
103+ { _headerArg :: Arg f }
91 | ReplaceHeaderArg
104 | ReplaceHeaderArg
92− { _headerArg :: Arg
105+ { _headerArg :: Arg f
93 , _headerPattern :: Text
106 , _headerPattern :: Text
109+deriving instance Eq f => Eq (HeaderArg f)
94− } deriving (Eq, Show)
110+deriving instance Show f => Show (HeaderArg f)
96makeLenses ''HeaderArg
112makeLenses ''HeaderArg
98makePrisms ''HeaderArg
114makePrisms ''HeaderArg
100−data Url = Url
116+data Url f = Url
101− { _path :: Path
117+ { _path :: Path f
102− , _queryStr :: [QueryArg]
118+ , _queryStr :: [QueryArg f]
103− } deriving (Eq, Show)
119+ }
121+deriving instance Eq f => Eq (Url f)
122+deriving instance Show f => Show (Url f)
105−defUrl :: Url
124+defUrl :: Url f
106defUrl = Url [] []
125defUrl = Url [] []
108makeLenses ''Url
127makeLenses ''Url
110−data Req = Req
129+data Req f = Req
111− { _reqUrl :: Url
130+ { _reqUrl :: Url f
112 , _reqMethod :: HTTP.Method
131 , _reqMethod :: HTTP.Method
113− , _reqHeaders :: [HeaderArg]
132+ , _reqHeaders :: [HeaderArg f]
114− , _reqBody :: Maybe ForeignType
133+ , _reqBody :: Maybe (ForeignType f)
115− , _reqReturnType :: ForeignType
134+ , _reqReturnType :: ForeignType f
116 , _reqFuncName :: FunctionName
135 , _reqFuncName :: FunctionName
138+deriving instance Eq f => Eq (Req f)
117− } deriving (Eq, Show)
139+deriving instance Show f => Show (Req f)
119makeLenses ''Req
141makeLenses ''Req
121−defReq :: Req
143+defReq :: Req Text
122defReq = Req defUrl "GET" [] Nothing (ForeignType "") (FunctionName [])
144defReq = Req defUrl "GET" [] Nothing (ForeignType "") (FunctionName [])
124-- | To be used exclusively as a "negative" return type/constraint
146-- | To be used exclusively as a "negative" return type/constraint
@@ -161,7 +183,7 @@ type family Elem (a :: *) (ls::[*]) :: Constraint where
163class HasForeignType lang a where
185class HasForeignType lang a where
164− typeFor :: Proxy lang -> Proxy a -> ForeignType
186+ typeFor :: Proxy lang -> Proxy a -> ForeignType Text
166data NoTypes
188data NoTypes
@@ -172,7 +194,7 @@ type HasNoForeignType = HasForeignType NoTypes
173class HasForeign lang (layout :: *) where
195class HasForeign lang (layout :: *) where
174 type Foreign layout :: *
196 type Foreign layout :: *
175− foreignFor :: Proxy lang -> Proxy layout -> Req -> Foreign layout
197+ foreignFor :: Proxy lang -> Proxy layout -> Req Text -> Foreign layout
177instance (HasForeign lang a, HasForeign lang b)
199instance (HasForeign lang a, HasForeign lang b)
178 => HasForeign lang (a :<|> b) where
200 => HasForeign lang (a :<|> b) where
@@ -199,7 +221,7 @@ instance (KnownSymbol sym, HasForeignType lang ftype, HasForeign lang sublayout)
200instance (Elem JSON list, HasForeignType lang a, ReflectMethod method)
222instance (Elem JSON list, HasForeignType lang a, ReflectMethod method)
201 => HasForeign lang (Verb method status list a) where
223 => HasForeign lang (Verb method status list a) where
202− type Foreign (Verb method status list a) = Req
224+ type Foreign (Verb method status list a) = Req Text
204 foreignFor lang Proxy req =
226 foreignFor lang Proxy req =
205 req & reqFuncName . _FunctionName %~ (methodLC :)
227 req & reqFuncName . _FunctionName %~ (methodLC :)
@@ -264,7 +286,7 @@ instance
264 , _argType = typeFor lang (Proxy :: Proxy Bool) }
286 , _argType = typeFor lang (Proxy :: Proxy Bool) }
266instance HasForeign lang Raw where
288instance HasForeign lang Raw where
267− type Foreign Raw = HTTP.Method -> Req
289+ type Foreign Raw = HTTP.Method -> Req Text
269 foreignFor _ Proxy req method =
291 foreignFor _ Proxy req method =
270 req & reqFuncName . _FunctionName %~ ((toLower $ decodeUtf8 method) :)
292 req & reqFuncName . _FunctionName %~ ((toLower $ decodeUtf8 method) :)
@@ -329,9 +351,9 @@ instance HasForeign lang sublayout
329-- the data needed to generate a function for each endpoint
351-- the data needed to generate a function for each endpoint
330-- and hands it all back in a list.
352-- and hands it all back in a list.
331class GenerateList reqs where
353class GenerateList reqs where
332− generateList :: reqs -> [Req]
354+ generateList :: reqs -> [Req Text]
334−instance GenerateList Req where
356+instance GenerateList (Req Text) where
335 generateList r = [r]
357 generateList r = [r]
337instance (GenerateList start, GenerateList rest)
359instance (GenerateList start, GenerateList rest)
@@ -344,5 +366,5 @@ listFromAPI
344 :: (HasForeign lang api, GenerateList (Foreign api))
366 :: (HasForeign lang api, GenerateList (Foreign api))
345 => Proxy lang
367 => Proxy lang
346 -> Proxy api
368 -> Proxy api
347− -> [Req]
369+ -> [Req Text]
348listFromAPI lang p = generateList (foreignFor lang p defReq)
370listFromAPI lang p = generateList (foreignFor lang p defReq)