Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions id.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 13 additions & 23 deletions src/Data/Id.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,26 @@ 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)
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
#ifdef USE_POSTGRES
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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down