@@ -4,12 +4,9 @@
44{-# OPTIONS_GHC -Wno-orphans #-}
55
66module Data.Id
7− ( Id, mkId, unId, unsafeIdTagConvert, coerceId, _Id, nilId
7+ ( Id, mkId, unId, randomId, unsafeIdTagConvert, coerceId, _Id, nilId
88 , IntId, mkIntId, unIntId, unsafeIntIdTagConvert, coerceIntId, _IntId
99 , Name, mkName, unName, unsafeNameTagConvert, coerceName, _Name
10−#ifdef USE_UUID
11− , randomId
12−#endif
1310 )
1411 where
1512
@@ -21,22 +18,19 @@ import Data.Binary (Binary)
2118import Data.Coerce (coerce)
2219import Data.Data
2320import Data.Hashable (Hashable)
21+import Data.OpenApi
2422import Data.String
2523import Data.Text as T
26−import Data.UUID.Types (UUID)
27−import qualified Data.UUID.Types as UUID
24+import Data.UUID (UUID)
25+import qualified Data.UUID as UUID
26+import qualified Data.UUID.V4 as UUID.V4
2827import GHC.TypeLits
2928import Prelude as P
29+import Test.QuickCheck
3030import Text.ParserCombinators.ReadP
3131import Web.HttpApiData
3232import Web.PathPieces (PathPiece(..))
3333
34−#ifdef USE_UUID
35−import qualified Data.UUID.V4 as UUID.V4
36−#endif
37−#ifdef BACKEND
38−import Data.OpenApi
39−import Test.QuickCheck
4034#ifdef USE_CASSAVA
4135import Data.Csv as Csv hiding(Name)
4236#endif
@@ -44,7 +38,6 @@ import Data.Csv as Csv hiding(Name)
4438import Database.PostgreSQL.Simple.FromField as PG (FromField)
4539import Database.PostgreSQL.Simple.ToField as PG (ToField)
4640#endif
47−#endif
4841
4942#ifdef USE_FLAT
5043import Flat as F
@@ -62,11 +55,9 @@ newtype Id t = Id { unId :: UUID }
6255 , PG.ToField, PG.FromField
6356#endif
6457#endif
65− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
66−#ifdef BACKEND
67− , ToSchema, ToParamSchema
68−#endif
69− , FromHttpApiData, ToHttpApiData )
58+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
59+ , ToParamSchema, FromHttpApiData, ToHttpApiData
60+ )
7061
7162type role Id nominal
7263
@@ -76,11 +67,9 @@ mkId :: forall s. UUID -> Id s
7667mkId = coerce
7768{-# INLINE mkId #-}
7869
79−#ifdef USE_UUID
8070randomId :: forall s. IO (Id s)
8171randomId = coerce <$> UUID.V4.nextRandom
8272{-# INLINE randomId #-}
83−#endif
8473
8574instance KnownSymbol s => Show (Id s) where
8675 show (Id v) = "Id-" <> symbolVal (Proxy @s) <> "-" <> P.show v
@@ -104,14 +93,12 @@ instance Data.Store.Store (Id s) where
10493 size = Data.Store.ConstSize 16
10594#endif
10695
107−#ifdef BACKEND
10896instance Arbitrary (Id t) where
10997 arbitrary = fmap Id $ UUID.fromWords
11098 <$> arbitrary
11199 <*> arbitrary
112100 <*> arbitrary
113101 <*> arbitrary
114−#endif
115102
116103instance PathPiece (Id t) where
117104 fromPathPiece = coerce . UUID.fromText
@@ -166,11 +153,10 @@ newtype IntId t = IntId { unIntId :: Integer }
166153#ifdef USE_STORE
167154 , Data.Store.Store
168155#endif
169−#ifdef BACKEND
170− , ToSchema, ToParamSchema, Arbitrary
171−#endif
172− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
173− , ToHttpApiData, PathPiece, Num, Integral, Real, Enum )
156+ , ToSchema, ToParamSchema, Arbitrary, FromJSON, ToJSON, NFData, Hashable
157+ , FromJSONKey, ToJSONKey, FromHttpApiData, ToHttpApiData, PathPiece, Num
158+ , Integral, Real, Enum
159+ )
174160
175161type role IntId nominal
176162
@@ -217,11 +203,10 @@ newtype Name t = Name { unName :: Text }
217203#ifdef USE_STORE
218204 , Data.Store.Store
219205#endif
220−#ifdef BACKEND
221− , ToSchema, ToParamSchema
222−#endif
223− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
224− , ToHttpApiData, PathPiece, IsString, Semigroup, Monoid )
206+ , ToSchema, ToParamSchema, FromJSON, ToJSON, NFData, Hashable, FromJSONKey
207+ , ToJSONKey, FromHttpApiData, ToHttpApiData, PathPiece, IsString, Semigroup
208+ , Monoid
209+ )
225210
226211type role Name nominal
227212
@@ -239,10 +224,8 @@ instance KnownSymbol s => Read (Name s) where
239224 _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
240225 mkName <$> readS_to_P reads
241226
242−#ifdef BACKEND
243227instance Arbitrary (Name s) where
244228 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
245−#endif
246229
247230-- | This is a more \"explicit\" 'coerce' specifically for 'Name'.
248231-- You are forced to explicitly specify the phantom types you are converting