From 09f8ccc9e55ea538fd57ffdca6e35aed81769809 Mon Sep 17 00:00:00 2001 From: Brendan Hay Date: Sat, 11 Feb 2017 10:35:53 +0100 Subject: [PATCH 1/4] Pinning haskell-src-exts to pre location annotation changes --- gen/gogol-gen.cabal | 4 ++-- gen/stack.yaml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gen/gogol-gen.cabal b/gen/gogol-gen.cabal index 8c9a100e23..1aef0ae5b1 100644 --- a/gen/gogol-gen.cabal +++ b/gen/gogol-gen.cabal @@ -55,8 +55,8 @@ executable gogol-gen , errors >= 2.1.2 , formatting , hashable - , haskell-src-exts >= 1.17.1 - , hindent + , haskell-src-exts == 1.17.1 + , hindent < 5 , lens , mtl , optparse-applicative diff --git a/gen/stack.yaml b/gen/stack.yaml index 9acd7b3edd..7bb134502c 100644 --- a/gen/stack.yaml +++ b/gen/stack.yaml @@ -5,6 +5,8 @@ flags: {} extra-deps: - text-regex-replace-0.1.1.1 + - haskell-src-exts-1.17.1 + - hindent-4.6.4 packages: - '.' From 97611433ae1ea3158b48a970547f3100aa651cc2 Mon Sep 17 00:00:00 2001 From: Brendan Hay Date: Sat, 11 Feb 2017 10:37:45 +0100 Subject: [PATCH 2/4] Updating to latest version of aeson --- gen/gogol-gen.cabal | 3 +-- gen/src/Gen/Orphans.hs | 34 ---------------------------------- gen/src/Gen/Types/Id.hs | 13 ++++--------- gen/src/Main.hs | 1 + 4 files changed, 6 insertions(+), 45 deletions(-) delete mode 100644 gen/src/Gen/Orphans.hs diff --git a/gen/gogol-gen.cabal b/gen/gogol-gen.cabal index 1aef0ae5b1..67dc4c5029 100644 --- a/gen/gogol-gen.cabal +++ b/gen/gogol-gen.cabal @@ -28,7 +28,6 @@ executable gogol-gen , Gen.Formatting , Gen.IO , Gen.JSON - , Gen.Orphans , Gen.Syntax , Gen.TH , Gen.Text @@ -44,7 +43,7 @@ executable gogol-gen ghc-options: -Wall -threaded build-depends: - aeson + aeson >= 1 , attoparsec , base >= 4.8 , bifunctors diff --git a/gen/src/Gen/Orphans.hs b/gen/src/Gen/Orphans.hs deleted file mode 100644 index 5394150563..0000000000 --- a/gen/src/Gen/Orphans.hs +++ /dev/null @@ -1,34 +0,0 @@ -{-# LANGUAGE FlexibleInstances #-} - -{-# OPTIONS_GHC -fno-warn-orphans #-} - --- Module : Gen.Orphans --- Copyright : (c) 2015-2016 Brendan Hay --- License : Mozilla Public License, v. 2.0. --- Maintainer : Brendan Hay --- Stability : provisional --- Portability : non-portable (GHC extensions) - -module Gen.Orphans where - -import Data.Aeson -import Data.Bifunctor -import Data.Hashable -import qualified Data.HashMap.Strict as Map -import Data.String -import qualified Data.Text as Text -import Language.Haskell.Exts.Build -import Language.Haskell.Exts.Pretty -import Language.Haskell.Exts.Syntax - -instance Hashable Name - -instance IsString Name where fromString = name -instance IsString QName where fromString = UnQual . name -instance IsString QOp where fromString = op . sym - -instance ToJSON a => ToJSON (Map.HashMap Name a) where - toJSON = toJSON - . Map.fromList - . map (first (Text.pack . prettyPrint)) - . Map.toList diff --git a/gen/src/Gen/Types/Id.hs b/gen/src/Gen/Types/Id.hs index 7539123f99..8a89f6bd09 100644 --- a/gen/src/Gen/Types/Id.hs +++ b/gen/src/Gen/Types/Id.hs @@ -58,12 +58,10 @@ import Control.Applicative import Control.Monad import Data.Aeson hiding (Bool, String) import qualified Data.Attoparsec.Text as A -import Data.Bifunctor (first) import qualified Data.CaseInsensitive as CI import Data.Foldable (foldl') import Data.Function (on) import Data.Hashable -import qualified Data.HashMap.Strict as Map import Data.List (intersperse) import Data.List (elemIndex, nub, sortOn) import Data.Semigroup hiding (Sum) @@ -75,7 +73,6 @@ import Data.Text.Manipulate import Formatting import Gen.Orphans () import Gen.Text -import Gen.Types.Map import GHC.Generics (Generic) import Language.Haskell.Exts.Build import Language.Haskell.Exts.Syntax (Exp, Name (..)) @@ -167,9 +164,8 @@ instance FromJSON Global where instance ToJSON Global where toJSON = toJSON . global -instance FromJSON v => FromJSON (Map Global v) where - parseJSON = fmap (Map.fromList . map (first mkGlobal) . Map.toList) - . parseJSON +instance FromJSONKey Global +instance ToJSONKey Global gid :: Format a (Global -> a) gid = later (Build.fromText . global) @@ -177,9 +173,8 @@ gid = later (Build.fromText . global) newtype Local = Local { local :: Text } deriving (Eq, Ord, Show, Generic, Hashable, FromJSON, ToJSON, IsString) -instance FromJSON v => FromJSON (Map Local v) where - parseJSON = fmap (Map.fromList . map (first Local) . Map.toList) - . parseJSON +instance FromJSONKey Local +instance ToJSONKey Local lid :: Format a (Local -> a) lid = later (Build.fromText . local) diff --git a/gen/src/Main.hs b/gen/src/Main.hs index 04ef3de731..0c623cb417 100644 --- a/gen/src/Main.hs +++ b/gen/src/Main.hs @@ -18,6 +18,7 @@ import Control.Error import Control.Lens hiding ((<.>)) import Control.Monad.State import Data.List (nub, sort) +import Data.Monoid ((<>)) import Data.String import qualified Data.Text as Text import qualified Filesystem as FS From 3f8bd78b0f6253ace56b00e93b2c17cf1c361ab8 Mon Sep 17 00:00:00 2001 From: Brendan Hay Date: Sat, 11 Feb 2017 11:03:46 +0100 Subject: [PATCH 3/4] Miscellaneous tweaks due to updating aeson and other dependencies --- gen/.ghci | 3 +++ gen/gogol-gen.cabal | 1 + gen/src/Gen/Orphans.hs | 23 +++++++++++++++++++++++ gen/src/Gen/Types/Data.hs | 1 - gen/src/Gen/Types/Id.hs | 23 +++++++++++++++-------- gen/src/Gen/Types/Schema.hs | 1 - gen/src/Main.hs | 2 +- 7 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 gen/.ghci create mode 100644 gen/src/Gen/Orphans.hs diff --git a/gen/.ghci b/gen/.ghci new file mode 100644 index 0000000000..99efa9c5eb --- /dev/null +++ b/gen/.ghci @@ -0,0 +1,3 @@ +:set -XOverloadedStrings + +:set prompt "> " diff --git a/gen/gogol-gen.cabal b/gen/gogol-gen.cabal index 67dc4c5029..47d045d2fa 100644 --- a/gen/gogol-gen.cabal +++ b/gen/gogol-gen.cabal @@ -28,6 +28,7 @@ executable gogol-gen , Gen.Formatting , Gen.IO , Gen.JSON + , Gen.Orphans , Gen.Syntax , Gen.TH , Gen.Text diff --git a/gen/src/Gen/Orphans.hs b/gen/src/Gen/Orphans.hs new file mode 100644 index 0000000000..bb6ee3d98c --- /dev/null +++ b/gen/src/Gen/Orphans.hs @@ -0,0 +1,23 @@ +{-# LANGUAGE FlexibleInstances #-} + +{-# OPTIONS_GHC -fno-warn-orphans #-} + +-- Module : Gen.Orphans +-- Copyright : (c) 2015-2016 Brendan Hay +-- License : Mozilla Public License, v. 2.0. +-- Maintainer : Brendan Hay +-- Stability : provisional +-- Portability : non-portable (GHC extensions) + +module Gen.Orphans where + +import Data.Hashable +import Data.String +import Language.Haskell.Exts.Build +import Language.Haskell.Exts.Syntax + +instance Hashable Name + +instance IsString Name where fromString = name +instance IsString QName where fromString = UnQual . name +instance IsString QOp where fromString = op . sym diff --git a/gen/src/Gen/Types/Data.hs b/gen/src/Gen/Types/Data.hs index 36d0c4fbe7..e5f99c5634 100644 --- a/gen/src/Gen/Types/Data.hs +++ b/gen/src/Gen/Types/Data.hs @@ -31,7 +31,6 @@ import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Lazy as LText import Data.Text.Manipulate -import Gen.Orphans () import Gen.Types.Help import Gen.Types.Id import Gen.Types.NS diff --git a/gen/src/Gen/Types/Id.hs b/gen/src/Gen/Types/Id.hs index 8a89f6bd09..7f2b651d7d 100644 --- a/gen/src/Gen/Types/Id.hs +++ b/gen/src/Gen/Types/Id.hs @@ -71,7 +71,6 @@ import qualified Data.Text as Text import qualified Data.Text.Lazy.Builder as Build import Data.Text.Manipulate import Formatting -import Gen.Orphans () import Gen.Text import GHC.Generics (Generic) import Language.Haskell.Exts.Build @@ -161,20 +160,28 @@ instance IsString Global where instance FromJSON Global where parseJSON = withText "global" (pure . mkGlobal) +instance FromJSONKey Global where + fromJSONKey = FromJSONKeyText mkGlobal + instance ToJSON Global where toJSON = toJSON . global -instance FromJSONKey Global -instance ToJSONKey Global - gid :: Format a (Global -> a) gid = later (Build.fromText . global) newtype Local = Local { local :: Text } - deriving (Eq, Ord, Show, Generic, Hashable, FromJSON, ToJSON, IsString) - -instance FromJSONKey Local -instance ToJSONKey Local + deriving + ( Eq + , Ord + , Show + , Generic + , Hashable + , FromJSON + , ToJSON + , FromJSONKey + , ToJSONKey + , IsString + ) lid :: Format a (Local -> a) lid = later (Build.fromText . local) diff --git a/gen/src/Gen/Types/Schema.hs b/gen/src/Gen/Types/Schema.hs index f6b9b848d9..70836776b5 100644 --- a/gen/src/Gen/Types/Schema.hs +++ b/gen/src/Gen/Types/Schema.hs @@ -38,7 +38,6 @@ import Data.Semigroup ((<>)) import Data.Text (Text) import qualified Data.Text as Text import Data.Text.Manipulate -import Gen.Orphans () import Gen.Text import Gen.TH import Gen.Types.Help diff --git a/gen/src/Main.hs b/gen/src/Main.hs index 0c623cb417..17535ba6a0 100644 --- a/gen/src/Main.hs +++ b/gen/src/Main.hs @@ -153,7 +153,7 @@ main = do let anx = _optAnnexes fromText modelName <.> "json" p <- isFile anx if not p - then say ("Skipping '" % stext % "' due to mimsing annex configuration.") + then say ("Skipping '" % stext % "' due to missing annex configuration.") modelName else do s <- sequence From 30a60507511eba4e86ff0e8d250bc1eef9cea12a Mon Sep 17 00:00:00 2001 From: Brendan Hay Date: Sat, 11 Feb 2017 11:14:14 +0100 Subject: [PATCH 4/4] Removing not-so-'smart' de/serialisation of base64 bytes streams --- core/gogol-core.cabal | 3 +- core/src/Network/Google/Data/Base64.hs | 53 -------------------------- core/src/Network/Google/Data/Bytes.hs | 49 ++++++++++++++++++++++++ core/src/Network/Google/Prelude.hs | 2 +- gen/src/Gen/Syntax.hs | 4 +- 5 files changed, 53 insertions(+), 58 deletions(-) delete mode 100644 core/src/Network/Google/Data/Base64.hs create mode 100644 core/src/Network/Google/Data/Bytes.hs diff --git a/core/gogol-core.cabal b/core/gogol-core.cabal index 3db5f4c688..356135340b 100644 --- a/core/gogol-core.cabal +++ b/core/gogol-core.cabal @@ -36,7 +36,7 @@ library ghc-options: -Wall exposed-modules: - Network.Google.Data.Base64 + Network.Google.Data.Bytes , Network.Google.Data.JSON , Network.Google.Data.Numeric , Network.Google.Data.Time @@ -59,7 +59,6 @@ library , http-media >= 0.6 , http-types >= 0.8.6 , lens >= 4.4 - , memory >= 0.8 , resourcet >= 1.1 , scientific >= 0.3 , servant >= 0.4.4 diff --git a/core/src/Network/Google/Data/Base64.hs b/core/src/Network/Google/Data/Base64.hs deleted file mode 100644 index f5187e06ce..0000000000 --- a/core/src/Network/Google/Data/Base64.hs +++ /dev/null @@ -1,53 +0,0 @@ -{-# LANGUAGE DeriveDataTypeable #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} - --- | --- Module : Network.Google.Data.Base64 --- Copyright : (c) 2013-2016 Brendan Hay --- License : Mozilla Public License, v. 2.0. --- Maintainer : Brendan Hay --- Stability : provisional --- Portability : non-portable (GHC extensions) --- -module Network.Google.Data.Base64 - ( Base64 (..) - , _Base64 - ) where - -import Control.Lens (Iso', iso) -import Data.Aeson (FromJSON (..), ToJSON (..)) -import qualified Data.ByteArray.Encoding as BA -import Data.ByteString (ByteString) -import qualified Data.ByteString.Char8 as BS8 -import Data.Data (Data, Typeable) -import Data.Hashable -import qualified Data.Text.Encoding as Text -import GHC.Generics (Generic) -import Network.Google.Data.JSON (parseJSONText, toJSONText) -import Web.HttpApiData (FromHttpApiData (..), - ToHttpApiData (..)) - --- | Base64 encoded binary data. --- --- Encoding\/decoding is automatically deferred to serialisation and deserialisation --- respectively. -newtype Base64 = Base64 { unBase64 :: ByteString } - deriving (Eq, Read, Ord, Data, Typeable, Generic) - -instance Hashable Base64 - -_Base64 :: Iso' Base64 ByteString -_Base64 = iso unBase64 Base64 - -instance ToHttpApiData Base64 where - toQueryParam = Text.decodeUtf8 . toHeader - toHeader = BA.convertToBase BA.Base64 . unBase64 - -instance FromHttpApiData Base64 where - parseQueryParam = parseHeader . Text.encodeUtf8 - parseHeader = either fail (pure . Base64) . BA.convertFromBase BA.Base64 - -instance Show Base64 where show = show . BS8.unpack . unBase64 -instance FromJSON Base64 where parseJSON = parseJSONText "Base64" -instance ToJSON Base64 where toJSON = toJSONText diff --git a/core/src/Network/Google/Data/Bytes.hs b/core/src/Network/Google/Data/Bytes.hs new file mode 100644 index 0000000000..595515d388 --- /dev/null +++ b/core/src/Network/Google/Data/Bytes.hs @@ -0,0 +1,49 @@ +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} + +-- | +-- Module : Network.Google.Data.Bytes +-- Copyright : (c) 2013-2016 Brendan Hay +-- License : Mozilla Public License, v. 2.0. +-- Maintainer : Brendan Hay +-- Stability : provisional +-- Portability : non-portable (GHC extensions) +-- +module Network.Google.Data.Bytes + ( Bytes (..) + , _Bytes + ) where + +import Control.Lens (Iso', iso) +import Data.Aeson (FromJSON (..), ToJSON (..)) +import Data.ByteString (ByteString) +import Data.Data (Data, Typeable) +import Data.Hashable +import qualified Data.Text.Encoding as Text +import GHC.Generics (Generic) +import Network.Google.Data.JSON (parseJSONText, toJSONText) +import Web.HttpApiData (FromHttpApiData (..), + ToHttpApiData (..)) +-- | Binary data. +-- +-- This data is passed to/from the serialisation routines as-is, and any +-- particular encoding or decoding (say, base64) is left up to the caller. +newtype Bytes = Bytes { unBytes :: ByteString } + deriving (Eq, Show, Read, Ord, Data, Typeable, Generic) + +instance Hashable Bytes + +_Bytes :: Iso' Bytes ByteString +_Bytes = iso unBytes Bytes + +instance ToHttpApiData Bytes where + toQueryParam = Text.decodeUtf8 . unBytes + toHeader = unBytes + +instance FromHttpApiData Bytes where + parseQueryParam = pure . Bytes . Text.encodeUtf8 + parseHeader = pure . Bytes + +instance FromJSON Bytes where parseJSON = parseJSONText "Bytes" +instance ToJSON Bytes where toJSON = toJSONText diff --git a/core/src/Network/Google/Prelude.hs b/core/src/Network/Google/Prelude.hs index 78a9db30b1..3c4c4e0023 100644 --- a/core/src/Network/Google/Prelude.hs +++ b/core/src/Network/Google/Prelude.hs @@ -31,7 +31,7 @@ import Servant.API as Export hiding (Headers, getResponse) import Servant.Utils.Links as Export hiding (Link) import Web.HttpApiData as Export (FromHttpApiData (..), ToHttpApiData (..)) -import Network.Google.Data.Base64 as Export +import Network.Google.Data.Bytes as Export import Network.Google.Data.JSON as Export import Network.Google.Data.Numeric as Export import Network.Google.Data.Time as Export diff --git a/gen/src/Gen/Syntax.hs b/gen/src/Gen/Syntax.hs index 902965683e..a1a0bbc981 100644 --- a/gen/src/Gen/Syntax.hs +++ b/gen/src/Gen/Syntax.hs @@ -588,7 +588,7 @@ internalLit = \case Nat -> TyApp (TyCon "Textual") (TyCon "Nat") Float -> TyApp (TyCon "Textual") (TyCon "Double") Double -> TyApp (TyCon "Textual") (TyCon "Double") - Byte -> TyCon "Base64" + Byte -> TyCon "Bytes" UInt32 -> TyApp (TyCon "Textual") (TyCon "Word32") UInt64 -> TyApp (TyCon "Textual") (TyCon "Word64") Int32 -> TyApp (TyCon "Textual") (TyCon "Int32") @@ -622,7 +622,7 @@ iso = \case TLit Duration -> Just (var "_Duration") TLit Float -> Just (var "_Coerce") TLit Double -> Just (var "_Coerce") - TLit Byte -> Just (var "_Base64") + TLit Byte -> Just (var "_Bytes") TLit UInt32 -> Just (var "_Coerce") TLit UInt64 -> Just (var "_Coerce") TLit Int32 -> Just (var "_Coerce")