@@ -4,12 +4,9 @@
4{-# OPTIONS_GHC -Wno-orphans #-}
4{-# OPTIONS_GHC -Wno-orphans #-}
6module Data.Id
6module Data.Id
7− ( Id, mkId, unId, unsafeIdTagConvert, coerceId, _Id, nilId
7+ ( Id, mkId, unId, randomId, unsafeIdTagConvert, coerceId, _Id, nilId
8 , IntId, mkIntId, unIntId, unsafeIntIdTagConvert, coerceIntId, _IntId
8 , IntId, mkIntId, unIntId, unsafeIntIdTagConvert, coerceIntId, _IntId
9 , Name, mkName, unName, unsafeNameTagConvert, coerceName, _Name
9 , Name, mkName, unName, unsafeNameTagConvert, coerceName, _Name
@@ -21,22 +18,19 @@ import Data.Binary (Binary)
21import Data.Coerce (coerce)
18import Data.Coerce (coerce)
22import Data.Data
19import Data.Data
23import Data.Hashable (Hashable)
20import Data.Hashable (Hashable)
24import Data.String
22import Data.String
25import Data.Text as T
23import Data.Text as T
26−import Data.UUID.Types (UUID)
24+import Data.UUID (UUID)
27−import qualified Data.UUID.Types as UUID
25+import qualified Data.UUID as UUID
26+import qualified Data.UUID.V4 as UUID.V4
28import GHC.TypeLits
27import GHC.TypeLits
29import Prelude as P
28import Prelude as P
29+import Test.QuickCheck
30import Text.ParserCombinators.ReadP
30import Text.ParserCombinators.ReadP
31import Web.HttpApiData
31import Web.HttpApiData
32import Web.PathPieces (PathPiece(..))
32import Web.PathPieces (PathPiece(..))
35−import qualified Data.UUID.V4 as UUID.V4
39−import Test.QuickCheck
40#ifdef USE_CASSAVA
34#ifdef USE_CASSAVA
41import Data.Csv as Csv hiding(Name)
35import Data.Csv as Csv hiding(Name)
@@ -44,7 +38,6 @@ import Data.Csv as Csv hiding(Name)
44import Database.PostgreSQL.Simple.FromField as PG (FromField)
38import Database.PostgreSQL.Simple.FromField as PG (FromField)
45import Database.PostgreSQL.Simple.ToField as PG (ToField)
39import Database.PostgreSQL.Simple.ToField as PG (ToField)
49#ifdef USE_FLAT
42#ifdef USE_FLAT
50import Flat as F
43import Flat as F
@@ -62,11 +55,9 @@ newtype Id t = Id { unId :: UUID }
62 , PG.ToField, PG.FromField
55 , PG.ToField, PG.FromField
65− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
58+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
67− , ToSchema, ToParamSchema
69− , FromHttpApiData, ToHttpApiData )
59+ , ToParamSchema, FromHttpApiData, ToHttpApiData
71type role Id nominal
62type role Id nominal
@@ -76,11 +67,9 @@ mkId :: forall s. UUID -> Id s
76mkId = coerce
67mkId = coerce
77{-# INLINE mkId #-}
68{-# INLINE mkId #-}
80randomId :: forall s. IO (Id s)
70randomId :: forall s. IO (Id s)
81randomId = coerce <$> UUID.V4.nextRandom
71randomId = coerce <$> UUID.V4.nextRandom
82{-# INLINE randomId #-}
72{-# INLINE randomId #-}
85instance KnownSymbol s => Show (Id s) where
74instance KnownSymbol s => Show (Id s) where
86 show (Id v) = "Id-" <> symbolVal (Proxy @s) <> "-" <> P.show v
75 show (Id v) = "Id-" <> symbolVal (Proxy @s) <> "-" <> P.show v
@@ -104,14 +93,12 @@ instance Data.Store.Store (Id s) where
104 size = Data.Store.ConstSize 16
93 size = Data.Store.ConstSize 16
108instance Arbitrary (Id t) where
96instance Arbitrary (Id t) where
109 arbitrary = fmap Id $ UUID.fromWords
97 arbitrary = fmap Id $ UUID.fromWords
110 <$> arbitrary
98 <$> arbitrary
111 <*> arbitrary
99 <*> arbitrary
112 <*> arbitrary
100 <*> arbitrary
113 <*> arbitrary
101 <*> arbitrary
116instance PathPiece (Id t) where
103instance PathPiece (Id t) where
117 fromPathPiece = coerce . UUID.fromText
104 fromPathPiece = coerce . UUID.fromText
@@ -166,11 +153,10 @@ newtype IntId t = IntId { unIntId :: Integer }
166#ifdef USE_STORE
153#ifdef USE_STORE
167 , Data.Store.Store
154 , Data.Store.Store
170− , ToSchema, ToParamSchema, Arbitrary
156+ , ToSchema, ToParamSchema, Arbitrary, FromJSON, ToJSON, NFData, Hashable
172− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
157+ , FromJSONKey, ToJSONKey, FromHttpApiData, ToHttpApiData, PathPiece, Num
173− , ToHttpApiData, PathPiece, Num, Integral, Real, Enum )
158+ , Integral, Real, Enum
175type role IntId nominal
161type role IntId nominal
@@ -217,11 +203,10 @@ newtype Name t = Name { unName :: Text }
217#ifdef USE_STORE
203#ifdef USE_STORE
218 , Data.Store.Store
204 , Data.Store.Store
221− , ToSchema, ToParamSchema
223− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
206+ , ToSchema, ToParamSchema, FromJSON, ToJSON, NFData, Hashable, FromJSONKey
224− , ToHttpApiData, PathPiece, IsString, Semigroup, Monoid )
207+ , ToJSONKey, FromHttpApiData, ToHttpApiData, PathPiece, IsString, Semigroup
226type role Name nominal
211type role Name nominal
@@ -239,10 +224,8 @@ instance KnownSymbol s => Read (Name s) where
239 _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
224 _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
240 mkName <$> readS_to_P reads
225 mkName <$> readS_to_P reads
243instance Arbitrary (Name s) where
227instance Arbitrary (Name s) where
244 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
228 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
247-- | This is a more \"explicit\" 'coerce' specifically for 'Name'.
230-- | This is a more \"explicit\" 'coerce' specifically for 'Name'.
248-- You are forced to explicitly specify the phantom types you are converting
231-- You are forced to explicitly specify the phantom types you are converting