diff --git a/id.cabal b/id.cabal index 4b3d82b..5cdf16a 100644 --- a/id.cabal +++ b/id.cabal @@ -33,17 +33,12 @@ library , hashable , http-api-data , lens + , openapi3 , path-pieces + , QuickCheck , text , uuid >=1.3.9 - if !(impl(ghcjs) || arch(javascript)) - build-depends: - , openapi3 - , QuickCheck - - cpp-options: -DBACKEND - if (flag(postgres) && !(impl(ghcjs) || arch(javascript))) build-depends: postgresql-simple cpp-options: -DUSE_POSTGRES diff --git a/src/Data/Id.hs b/src/Data/Id.hs index e62cf5e..a1f6945 100644 --- a/src/Data/Id.hs +++ b/src/Data/Id.hs @@ -18,6 +18,7 @@ import Data.Binary (Binary) import Data.Coerce (coerce) import Data.Data import Data.Hashable (Hashable) +import Data.OpenApi import Data.String import Data.Text as T import Data.UUID (UUID) @@ -25,13 +26,11 @@ import qualified Data.UUID as UUID import qualified Data.UUID.V4 as UUID.V4 import GHC.TypeLits import Prelude as P +import Test.QuickCheck import Text.ParserCombinators.ReadP import Web.HttpApiData import Web.PathPieces (PathPiece(..)) -#ifdef BACKEND -import Data.OpenApi -import Test.QuickCheck #ifdef USE_CASSAVA import Data.Csv as Csv hiding(Name) #endif @@ -39,7 +38,6 @@ import Data.Csv as Csv hiding(Name) import Database.PostgreSQL.Simple.FromField as PG (FromField) import Database.PostgreSQL.Simple.ToField as PG (ToField) #endif -#endif #ifdef USE_FLAT import Flat as F @@ -57,11 +55,9 @@ newtype Id t = Id { unId :: UUID } , PG.ToField, PG.FromField #endif #endif - , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey -#ifdef BACKEND - , ToSchema, ToParamSchema -#endif - , FromHttpApiData, ToHttpApiData ) + , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema + , ToParamSchema, FromHttpApiData, ToHttpApiData + ) type role Id nominal @@ -97,14 +93,12 @@ instance Data.Store.Store (Id s) where size = Data.Store.ConstSize 16 #endif -#ifdef BACKEND instance Arbitrary (Id t) where arbitrary = fmap Id $ UUID.fromWords <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary -#endif instance PathPiece (Id t) where fromPathPiece = coerce . UUID.fromText @@ -159,11 +153,10 @@ newtype IntId t = IntId { unIntId :: Integer } #ifdef USE_STORE , Data.Store.Store #endif -#ifdef BACKEND - , ToSchema, ToParamSchema, Arbitrary -#endif - , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData - , ToHttpApiData, PathPiece, Num, Integral, Real, Enum ) + , ToSchema, ToParamSchema, Arbitrary, FromJSON, ToJSON, NFData, Hashable + , FromJSONKey, ToJSONKey, FromHttpApiData, ToHttpApiData, PathPiece, Num + , Integral, Real, Enum + ) type role IntId nominal @@ -210,11 +203,10 @@ newtype Name t = Name { unName :: Text } #ifdef USE_STORE , Data.Store.Store #endif -#ifdef BACKEND - , ToSchema, ToParamSchema -#endif - , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData - , ToHttpApiData, PathPiece, IsString, Semigroup, Monoid ) + , ToSchema, ToParamSchema, FromJSON, ToJSON, NFData, Hashable, FromJSONKey + , ToJSONKey, FromHttpApiData, ToHttpApiData, PathPiece, IsString, Semigroup + , Monoid + ) type role Name nominal @@ -232,10 +224,8 @@ instance KnownSymbol s => Read (Name s) where _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-") mkName <$> readS_to_P reads -#ifdef BACKEND instance Arbitrary (Name s) where arbitrary = coerce . T.pack . getPrintableString <$> arbitrary -#endif -- | This is a more \"explicit\" 'coerce' specifically for 'Name'. -- You are forced to explicitly specify the phantom types you are converting