on develop help sign in
Renamed conflicting names for data types & hid some conflicting imports from Prelude

I also hid the `Bytes` from the Prelude of Sum packages because of a similar conflict

commitdde08939524d98661e10b39623cb0f73f54c0724 authorKoray Al <koray.al@soostone.com.tr> dateThu 10 Jan 2019, 12:31 (8 years ago) parent5b76e74
10 files changed+119−114
core/src/Network/Google/Data/Time.hs+13−13 core/src/Network/Google/Prelude.hs+3−3 core/src/Network/Google/Types.hs+23−25 gen/src/Gen/Syntax.hs+55−58 gen/src/Gen/Types.hs+12−2 gen/src/Gen/Types/Schema.hs+4−4 gogol/src/Network/Google/Auth.hs+5−5 gogol/src/Network/Google/Internal/Auth.hs+2−2 gogol/src/Network/Google/Internal/HTTP.hs+1−1 gogol/src/Network/Google/Internal/Logger.hs+1−1
core/src/Network/Google/Data/Time.hs+13−13
@@ -14,13 +14,13 @@
1414module Network.Google.Data.Time
1515 ( Time'
1616 , Date'
17− , DateTime'
18− , Duration
17+ , DateTime' (..)
18+ , GDuration
1919
2020 , _Time
2121 , _Date
2222 , _DateTime
23− , _Duration
23+ , _GDuration
2424 ) where
2525
2626import Data.Monoid ((<>))
@@ -79,26 +79,26 @@ _DateTime = iso unDateTime DateTime'
7979-- | A duration in seconds with up to nine fractional digits, terminated by 's'.
8080--
8181-- /Example/: @"3.5s"@.
82−newtype Duration = Duration { unDuration :: Scientific }
82+newtype GDuration = GDuration { unGDuration :: Scientific }
8383 deriving (Eq, Ord, Show, Read, Generic, Data, Typeable)
8484
85−_Duration :: Iso' Duration Scientific
86−_Duration = iso unDuration Duration
85+_GDuration :: Iso' GDuration Scientific
86+_GDuration = iso unGDuration GDuration
8787
88−instance ToHttpApiData Duration where
88+instance ToHttpApiData GDuration where
8989 toQueryParam =
9090 LText.toStrict
9191 . (\seconds -> Build.toLazyText seconds <> "s")
9292 . Sci.formatScientificBuilder Sci.Fixed (Just 9)
93− . unDuration
93+ . unGDuration
9494
95−instance FromHttpApiData Duration where
96− parseQueryParam = second Duration . parseText durationParser
95+instance FromHttpApiData GDuration where
96+ parseQueryParam = second GDuration . parseText durationParser
9797
9898instance ToJSON Time' where toJSON = String . toQueryParam
9999instance ToJSON Date' where toJSON = String . toQueryParam
100100instance ToJSON DateTime' where toJSON = toJSON . unDateTime
101−instance ToJSON Duration where toJSON = String . toQueryParam
101+instance ToJSON GDuration where toJSON = String . toQueryParam
102102
103103instance FromJSON Time' where
104104 parseJSON = fmap Time' . withText "time" (run timeParser)
@@ -109,8 +109,8 @@ instance FromJSON Date' where
109109instance FromJSON DateTime' where
110110 parseJSON = fmap DateTime' . parseJSON
111111
112−instance FromJSON Duration where
113− parseJSON = fmap Duration . withText "duration" (run durationParser)
112+instance FromJSON GDuration where
113+ parseJSON = fmap GDuration . withText "duration" (run durationParser)
114114
115115parseText :: Parser a -> Text -> Either Text a
116116parseText p = first Text.pack . parseOnly p
core/src/Network/Google/Prelude.hs+3−3
@@ -26,9 +26,9 @@ import Data.Word as Export (Word32, Word64, Word8)
2626import GHC.Generics as Export (Generic)
2727import Network.HTTP.Client as Export (RequestBody)
2828import Numeric.Natural as Export (Natural)
29−import Prelude as Export hiding (product)
30−import Servant.API as Export hiding (Headers, Link, getResponse, Stream)
31−import Servant.Utils.Links as Export hiding (Link)
29+import Prelude as Export hiding (product, span, any, Word)
30+import Servant.API as Export hiding (Headers, Link, getResponse, Stream, ResponseHeader, Header, header)
31+import Servant.Links as Export hiding (Link)
3232import Web.HttpApiData as Export (FromHttpApiData (..), ToHttpApiData (..))
3333
3434import Network.Google.Data.Bytes as Export
core/src/Network/Google/Types.hs+23−25
@@ -24,7 +24,6 @@
2424--
2525module Network.Google.Types where
2626
27−import Control.Applicative
2827import Control.Exception.Lens (exception)
2928import Control.Lens
3029import Control.Monad.Catch
@@ -37,7 +36,6 @@ import Data.Conduit
3736import Data.Data
3837import Data.DList (DList)
3938import Data.Foldable (foldMap, foldl')
40−import Data.Semigroup
4139import Data.String
4240import Data.Text (Text)
4341import Data.Text.Lazy.Builder (Builder)
@@ -149,7 +147,7 @@ newtype ServiceId = ServiceId Text
149147 )
150148
151149-- | An opaque client secret.
152−newtype Secret = Secret Text
150+newtype GSecret = GSecret Text
153151 deriving
154152 ( Eq
155153 , Ord
@@ -163,7 +161,7 @@ newtype Secret = Secret Text
163161 , ToJSON
164162 )
165163
166−instance Show Secret where
164+instance Show GSecret where
167165 show = const "*****"
168166
169167newtype MediaDownload a = MediaDownload a
@@ -340,7 +338,7 @@ setBody :: Request -> [Body] -> Request
340338setBody rq bs = rq { _rqBody = bs }
341339
342340-- | A materialised 'http-client' request and associated response parser.
343−data Client a = Client
341+data GClient a = GClient
344342 { _cliAccept :: !(Maybe MediaType)
345343 , _cliMethod :: !Method
346344 , _cliCheck :: !(Status -> Bool)
@@ -349,7 +347,7 @@ data Client a = Client
349347 , _cliResponse :: !(Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
350348 }
351349
352−clientService :: Lens' (Client a) ServiceConfig
350+clientService :: Lens' (GClient a) ServiceConfig
353351clientService = lens _cliService (\s a -> s { _cliService = a })
354352
355353mime :: FromStream c a
@@ -358,24 +356,24 @@ mime :: FromStream c a
358356 -> [Int]
359357 -> Request
360358 -> ServiceConfig
361− -> Client a
362−mime p = client (fromStream p) (Just (contentType p))
359+ -> GClient a
360+mime p = gClient (fromStream p) (Just (contentType p))
363361
364362discard :: Method
365363 -> [Int]
366364 -> Request
367365 -> ServiceConfig
368− -> Client ()
369−discard = client (\b -> runConduit (b .| Conduit.sinkNull) >> pure (Right ())) Nothing
366+ -> GClient ()
367+discard = gClient (\b -> runConduit (b .| Conduit.sinkNull) >> pure (Right ())) Nothing
370368
371−client :: (Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
369+gClient :: (Stream -> ResourceT IO (Either (String, LBS.ByteString) a))
372370 -> Maybe MediaType
373371 -> Method
374372 -> [Int]
375373 -> Request
376374 -> ServiceConfig
377− -> Client a
378−client f cs m statuses rq s = Client
375+ -> GClient a
376+gClient f cs m statuses rq s = GClient
379377 { _cliAccept = cs
380378 , _cliMethod = m
381379 , _cliCheck = \status -> fromEnum status `elem` statuses
@@ -421,7 +419,7 @@ class GoogleRequest a where
421419 type Rs a :: *
422420 type Scopes a :: [Symbol]
423421
424− requestClient :: a -> Client (Rs a)
422+ requestClient :: a -> GClient (Rs a)
425423
426424class GoogleClient fn where
427425 type Fn fn :: *
@@ -549,61 +547,61 @@ instance ( ToBody c a
549547
550548instance {-# OVERLAPPABLE #-}
551549 FromStream c a => GoogleClient (Get (c ': cs) a) where
552− type Fn (Get (c ': cs) a) = ServiceConfig -> Client a
550+ type Fn (Get (c ': cs) a) = ServiceConfig -> GClient a
553551
554552 buildClient Proxy = mime (Proxy :: Proxy c) methodGet [200, 203]
555553
556554instance {-# OVERLAPPING #-}
557555 GoogleClient (Get (c ': cs) ()) where
558− type Fn (Get (c ': cs) ()) = ServiceConfig -> Client ()
556+ type Fn (Get (c ': cs) ()) = ServiceConfig -> GClient ()
559557
560558 buildClient Proxy = discard methodGet [204]
561559
562560instance {-# OVERLAPPABLE #-}
563561 (FromStream c a, cs' ~ (c ': cs)) => GoogleClient (Post cs' a) where
564− type Fn (Post cs' a) = ServiceConfig -> Client a
562+ type Fn (Post cs' a) = ServiceConfig -> GClient a
565563
566564 buildClient Proxy = mime (Proxy :: Proxy c) methodPost [200, 201]
567565
568566instance {-# OVERLAPPING #-}
569567 GoogleClient (Post cs ()) where
570− type Fn (Post cs ()) = ServiceConfig -> Client ()
568+ type Fn (Post cs ()) = ServiceConfig -> GClient ()
571569
572570 buildClient Proxy = discard methodPost [204]
573571
574572instance {-# OVERLAPPABLE #-}
575573 FromStream c a => GoogleClient (Put (c ': cs) a) where
576− type Fn (Put (c ': cs) a) = ServiceConfig -> Client a
574+ type Fn (Put (c ': cs) a) = ServiceConfig -> GClient a
577575
578576 buildClient Proxy = mime (Proxy :: Proxy c) methodPut [200, 201]
579577
580578instance {-# OVERLAPPING #-}
581579 GoogleClient (Put (c ': cs) ()) where
582− type Fn (Put (c ': cs) ()) = ServiceConfig -> Client ()
580+ type Fn (Put (c ': cs) ()) = ServiceConfig -> GClient ()
583581
584582 buildClient Proxy = discard methodPut [204]
585583
586584instance {-# OVERLAPPABLE #-}
587585 FromStream c a => GoogleClient (Patch (c ': cs) a) where
588− type Fn (Patch (c ': cs) a) = ServiceConfig -> Client a
586+ type Fn (Patch (c ': cs) a) = ServiceConfig -> GClient a
589587
590588 buildClient Proxy = mime (Proxy :: Proxy c) methodPatch [200, 201]
591589
592590instance {-# OVERLAPPING #-}
593591 GoogleClient (Patch (c ': cs) ()) where
594− type Fn (Patch (c ': cs) ()) = ServiceConfig -> Client ()
592+ type Fn (Patch (c ': cs) ()) = ServiceConfig -> GClient ()
595593
596594 buildClient Proxy = discard methodPatch [204]
597595
598596instance {-# OVERLAPPABLE #-}
599597 FromStream c a => GoogleClient (Delete (c ': cs) a) where
600− type Fn (Delete (c ': cs) a) = ServiceConfig -> Client a
598+ type Fn (Delete (c ': cs) a) = ServiceConfig -> GClient a
601599
602600 buildClient Proxy = mime (Proxy :: Proxy c) methodDelete [200, 202]
603601
604602instance {-# OVERLAPPING #-}
605603 GoogleClient (Delete (c ': cs) ()) where
606− type Fn (Delete (c ': cs) ()) = ServiceConfig -> Client ()
604+ type Fn (Delete (c ': cs) ()) = ServiceConfig -> GClient ()
607605
608606 buildClient Proxy = discard methodDelete [204]
609607
@@ -644,7 +642,7 @@ seconds (Seconds n)
644642microseconds :: Seconds -> Int
645643microseconds = (1000000 *) . seconds
646644
647−newtype FieldMask = FieldMask Text
645+newtype GFieldMask = GFieldMask Text
648646 deriving
649647 ( Eq
650648 , Ord
gen/src/Gen/Syntax.hs+55−58
@@ -12,8 +12,7 @@
1212
1313module Gen.Syntax where
1414
15−import Control.Lens hiding (iso, mapping, op, pre,
16− strict)
15+import Control.Lens hiding (iso, mapping, op, pre, strict)
1716import Data.Either
1817import Data.Foldable (foldl', foldr')
1918import qualified Data.HashMap.Strict as Map
@@ -25,9 +24,7 @@ import qualified Data.Text as Text
2524import Data.Text.Manipulate
2625import Gen.Text
2726import Gen.Types
28−import Language.Haskell.Exts.Build (app, appFun, infixApp, lamE,
29− listE, name, noBinds, paren,
30− patBind, pvar, sfun, strE, sym,
27+import Language.Haskell.Exts.Build (app, appFun, infixApp, lamE, listE, name, noBinds, paren, patBind, pvar, sfun, strE, sym,
3128 var)
3229import Language.Haskell.Exts.SrcLoc
3330import Language.Haskell.Exts.Syntax hiding (Alt, Int, Lit)
@@ -558,47 +555,47 @@ internalType = \case
558555
559556externalLit :: Lit -> Type
560557externalLit = \case
561− Text -> TyCon "Text"
562− Bool -> TyCon "Bool"
563− Time -> TyCon "TimeOfDay"
564− Date -> TyCon "Day"
565− DateTime -> TyCon "UTCTime"
566− Nat -> TyCon "Natural"
567− Float -> TyCon "Double"
568− Double -> TyCon "Double"
569− Byte -> TyCon "ByteString"
570− UInt32 -> TyCon "Word32"
571− UInt64 -> TyCon "Word64"
572− Int32 -> TyCon "Int32"
573− Int64 -> TyCon "Int64"
574− Alt t -> TyCon (unqual (Text.unpack t))
575− RqBody -> TyCon "RequestBody"
576− RsBody -> TyCon "Stream"
577− JSONValue -> TyCon "JSONValue"
578− FieldMask -> TyCon "FieldMask"
579− Duration -> TyCon "Scientific"
558+ Text -> TyCon "Text"
559+ Bool -> TyCon "Bool"
560+ Time -> TyCon "TimeOfDay"
561+ Date -> TyCon "Day"
562+ DateTime -> TyCon "UTCTime"
563+ Nat -> TyCon "Natural"
564+ Float -> TyCon "Double"
565+ Double -> TyCon "Double"
566+ Byte -> TyCon "ByteString"
567+ UInt32 -> TyCon "Word32"
568+ UInt64 -> TyCon "Word64"
569+ Int32 -> TyCon "Int32"
570+ Int64 -> TyCon "Int64"
571+ Alt t -> TyCon (unqual (Text.unpack t))
572+ RqBody -> TyCon "RequestBody"
573+ RsBody -> TyCon "Stream"
574+ JSONValue -> TyCon "JSONValue"
575+ GFieldMask -> TyCon "GFieldMask"
576+ GDuration -> TyCon "Scientific"
580577
581578internalLit :: Lit -> Type
582579internalLit = \case
583− Text -> TyCon "Text"
584− Bool -> TyCon "Bool"
585− Time -> TyCon "Time'"
586− Date -> TyCon "Date'"
587− DateTime -> TyCon "DateTime'"
588− Nat -> TyApp (TyCon "Textual") (TyCon "Nat")
589− Float -> TyApp (TyCon "Textual") (TyCon "Double")
590− Double -> TyApp (TyCon "Textual") (TyCon "Double")
591− Byte -> TyCon "Bytes"
592− UInt32 -> TyApp (TyCon "Textual") (TyCon "Word32")
593− UInt64 -> TyApp (TyCon "Textual") (TyCon "Word64")
594− Int32 -> TyApp (TyCon "Textual") (TyCon "Int32")
595− Int64 -> TyApp (TyCon "Textual") (TyCon "Int64")
596− Alt t -> TyCon (unqual (Text.unpack t))
597− RqBody -> TyCon "RequestBody"
598− RsBody -> TyCon "Stream"
599− JSONValue -> TyCon "JSONValue"
600− FieldMask -> TyCon "FieldMask"
601− Duration -> TyCon "Duration"
580+ Text -> TyCon "Text"
581+ Bool -> TyCon "Bool"
582+ Time -> TyCon "Time'"
583+ Date -> TyCon "Date'"
584+ DateTime -> TyCon "DateTime'"
585+ Nat -> TyApp (TyCon "Textual") (TyCon "Nat")
586+ Float -> TyApp (TyCon "Textual") (TyCon "Double")
587+ Double -> TyApp (TyCon "Textual") (TyCon "Double")
588+ Byte -> TyCon "Bytes"
589+ UInt32 -> TyApp (TyCon "Textual") (TyCon "Word32")
590+ UInt64 -> TyApp (TyCon "Textual") (TyCon "Word64")
591+ Int32 -> TyApp (TyCon "Textual") (TyCon "Int32")
592+ Int64 -> TyApp (TyCon "Textual") (TyCon "Int64")
593+ Alt t -> TyCon (unqual (Text.unpack t))
594+ RqBody -> TyCon "RequestBody"
595+ RsBody -> TyCon "Stream"
596+ JSONValue -> TyCon "JSONValue"
597+ GFieldMask -> TyCon "GFieldMask"
598+ GDuration -> TyCon "GDuration"
602599
603600mapping :: TType -> Exp -> Exp
604601mapping t e = infixE e "." (go t)
@@ -613,21 +610,21 @@ mapping t e = infixE e "." (go t)
613610
614611iso :: TType -> Maybe Exp
615612iso = \case
616− TList {} -> Just (var "_Coerce")
617− TMap {} -> Just (var "_Coerce")
618− TLit Nat -> Just (var "_Coerce")
619− TLit Time -> Just (var "_Time")
620− TLit Date -> Just (var "_Date")
621− TLit DateTime -> Just (var "_DateTime")
622− TLit Duration -> Just (var "_Duration")
623− TLit Float -> Just (var "_Coerce")
624− TLit Double -> Just (var "_Coerce")
625− TLit Byte -> Just (var "_Bytes")
626− TLit UInt32 -> Just (var "_Coerce")
627− TLit UInt64 -> Just (var "_Coerce")
628− TLit Int32 -> Just (var "_Coerce")
629− TLit Int64 -> Just (var "_Coerce")
630− _ -> Nothing
613+ TList {} -> Just (var "_Coerce")
614+ TMap {} -> Just (var "_Coerce")
615+ TLit Nat -> Just (var "_Coerce")
616+ TLit Time -> Just (var "_Time")
617+ TLit Date -> Just (var "_Date")
618+ TLit DateTime -> Just (var "_DateTime")
619+ TLit GDuration -> Just (var "_GDuration")
620+ TLit Float -> Just (var "_Coerce")
621+ TLit Double -> Just (var "_Coerce")
622+ TLit Byte -> Just (var "_Bytes")
623+ TLit UInt32 -> Just (var "_Coerce")
624+ TLit UInt64 -> Just (var "_Coerce")
625+ TLit Int32 -> Just (var "_Coerce")
626+ TLit Int64 -> Just (var "_Coerce")
627+ _ -> Nothing
631628
632629require :: TType -> TType
633630require (TMaybe t) = t
gen/src/Gen/Types.hs+12−2
@@ -126,7 +126,13 @@ parseVersion x = first (mappend (Text.unpack x) . mappend " -> ") $
126126 <*> (alpha <|> beta <|> sandbox <|> pure Nothing)
127127
128128 preface = A.takeWhile (/= '_') *> void (A.char '_') <|> pure ()
129− number = A.takeWhile (/= 'v') *> A.char 'v' *> A.double
129+
130+ protoVersionParser = do
131+ n <- A.many1 A.digit
132+ _ <- A.char 'p'
133+ p <- A.many1 A.digit
134+ return (read (n ++ "." ++ p) :: Double)
135+ number = A.takeWhile (/= 'v') *> A.char 'v' *> (protoVersionParser <|> A.double)
130136
131137 alpha = A.string "alpha"
132138 *> (Alpha <$> optional A.decimal <*> optional A.letter)
@@ -189,7 +195,7 @@ serviceImports s = Imports
189195 { tocImports = [preludeNS]
190196 , typeImports = sort [preludeNS, prodNS s, sumNS s]
191197 , prodImports = sort [preludeNS, sumNS s]
192− , sumImports = [preludeNS]
198+ , sumImports = [preludeSumNS]
193199 , actionImports = sort [preludeNS, typesNS s]
194200 }
195201
@@ -202,6 +208,10 @@ sumNS = (<> "Sum") . typesNS
202208preludeNS :: NS
203209preludeNS = "Network.Google.Prelude"
204210
211+-- | hide some conflicting (unneeded) data types from Sum modules
212+preludeSumNS :: NS
213+preludeSumNS = "Network.Google.Prelude hiding (Bytes)"
214+
205215resourceNS, methodNS :: NS
206216resourceNS = "Network.Google.Resource"
207217methodNS = "Network.Google.Method"
gen/src/Gen/Types/Schema.hs+4−4
@@ -197,8 +197,8 @@ data Lit
197197 | Time
198198 | Date
199199 | DateTime
200− | FieldMask
201− | Duration
200+ | GFieldMask
201+ | GDuration
202202
203203 -- Core types.
204204 | RqBody
@@ -228,8 +228,8 @@ instance FromJSON Lit where
228228 "date-time" -> pure DateTime
229229
230230 "google-datetime" -> pure DateTime
231− "google-fieldmask" -> pure FieldMask
232− "google-duration" -> pure Duration
231+ "google-fieldmask" -> pure GFieldMask
232+ "google-duration" -> pure GDuration
233233
234234 _ -> fail $
235235 "Unable to parse Literal from: " ++ Text.unpack t
gogol/src/Network/Google/Auth.hs+5−5
@@ -63,7 +63,7 @@ module Network.Google.Auth
6363 -- * Re-exported Types
6464 , AccessToken (..)
6565 , RefreshToken (..)
66− , Secret (..)
66+ , GSecret (..)
6767 , ServiceId (..)
6868 , ClientId (..)
6969
@@ -166,10 +166,10 @@ exchange :: forall m s. (MonadIO m, MonadCatch m, AllowScopes s)
166166exchange c l = fmap (Auth c) . action l
167167 where
168168 action = case c of
169− FromMetadata s -> metadataToken s
170− FromAccount a -> serviceAccountToken a (Proxy :: Proxy s)
171− FromClient x n -> exchangeCode x n
172− FromUser u -> authorizedUserToken u Nothing
169+ FromMetadata s -> metadataToken s
170+ FromAccount a -> serviceAccountToken a (Proxy :: Proxy s)
171+ FromClient x n -> exchangeCode x n
172+ FromUser u -> authorizedUserToken u Nothing
173173
174174-- | Refresh an existing 'OAuthToken'.
175175refresh :: forall m s. (MonadIO m, MonadCatch m, AllowScopes s)
gogol/src/Network/Google/Internal/Auth.hs+2−2
@@ -128,7 +128,7 @@ The secret and refresh token are used to obtain a valid 'OAuthToken' from
128128data AuthorizedUser = AuthorizedUser
129129 { _userId :: !ClientId
130130 , _userRefresh :: !RefreshToken
131− , _userSecret :: !Secret
131+ , _userSecret :: !GSecret
132132 } deriving (Eq, Show)
133133
134134instance ToJSON AuthorizedUser where
@@ -147,7 +147,7 @@ instance FromJSON AuthorizedUser where
147147-- | A client identifier and accompanying secret used to obtain/refresh a token.
148148data OAuthClient = OAuthClient
149149 { _clientId :: !ClientId
150− , _clientSecret :: !Secret
150+ , _clientSecret :: !GSecret
151151 } deriving (Eq, Show)
152152
153153{-| An OAuth bearer type token of the following form:
gogol/src/Network/Google/Internal/HTTP.hs+1−1
@@ -57,7 +57,7 @@ perform Env{..} x = catches go handlers
5757 where
5858 Request {..} = _cliRequest
5959 ServiceConfig {..} = _cliService
60− Client {..} = requestClient x
60+ GClient {..} = requestClient x
6161 & clientService %~ appEndo (getDual _envOverride)
6262
6363 go = liftResourceT $ do
gogol/src/Network/Google/Internal/Logger.hs+1−1
@@ -47,7 +47,7 @@ import qualified Data.Text.Encoding as Text
4747import qualified Data.Text.Lazy as LText
4848import qualified Data.Text.Lazy.Encoding as LText
4949import Data.Word (Word16)
50−import Network.Google.Prelude hiding (Header, Request)
50+import Network.Google.Prelude hiding (Request)
5151import Network.HTTP.Conduit
5252import Network.HTTP.Types
5353import Numeric (showFFloat)