@@ -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,13 @@ 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
28−import GHC.TypeLits
29−import Prelude as P
30−import Text.ParserCombinators.ReadP
31−import Web.HttpApiData
32−import Web.PathPieces (PathPiece(..))
33−
34−#ifdef USE_UUID
24+import Data.UUID (UUID)
25+import qualified Data.UUID as UUID
3526import qualified Data.UUID.V4 as UUID.V4
36−#endif
37−#ifdef BACKEND
38−import Data.OpenApi
39−import Test.QuickCheck
27+#ifndef ghcjs_HOST_OS
4028#ifdef USE_CASSAVA
4129import Data.Csv as Csv hiding(Name)
4230#endif
@@ -45,7 +33,12 @@ import Database.PostgreSQL.Simple.FromField as PG (FromField)
4533import Database.PostgreSQL.Simple.ToField as PG (ToField)
4634#endif
4735#endif
48−
36+import GHC.TypeLits
37+import Prelude as P
38+import Test.QuickCheck
39+import Text.ParserCombinators.ReadP
40+import Web.HttpApiData
41+import Web.PathPieces (PathPiece(..))
4942#ifdef USE_FLAT
5043import Flat as F
5144#endif
@@ -62,11 +55,8 @@ 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 )
7060
7161type role Id nominal
7262
@@ -76,11 +66,9 @@ mkId :: forall s. UUID -> Id s
7666mkId = coerce
7767{-# INLINE mkId #-}
7868
79−#ifdef USE_UUID
8069randomId :: forall s. IO (Id s)
8170randomId = coerce <$> UUID.V4.nextRandom
8271{-# INLINE randomId #-}
83−#endif
8472
8573instance KnownSymbol s => Show (Id s) where
8674 show (Id v) = "Id-" <> symbolVal (Proxy @s) <> "-" <> P.show v
@@ -104,14 +92,12 @@ instance Data.Store.Store (Id s) where
10492 size = Data.Store.ConstSize 16
10593#endif
10694
107−#ifdef BACKEND
10895instance Arbitrary (Id t) where
10996 arbitrary = fmap Id $ UUID.fromWords
11097 <$> arbitrary
11198 <*> arbitrary
11299 <*> arbitrary
113100 <*> arbitrary
114−#endif
115101
116102instance PathPiece (Id t) where
117103 fromPathPiece = coerce . UUID.fromText
@@ -166,11 +152,9 @@ newtype IntId t = IntId { unIntId :: Integer }
166152#ifdef USE_STORE
167153 , Data.Store.Store
168154#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 )
155+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
156+ , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece, Arbitrary
157+ , Num, Integral, Real, Enum )
174158
175159type role IntId nominal
176160
@@ -210,18 +194,16 @@ newtype Name t = Name { unName :: Text }
210194#ifdef USE_CASSAVA
211195 , Csv.ToField, Csv.FromField
212196#endif
213−#endif
214197#ifdef USE_FLAT
215198 , Flat
216199#endif
217200#ifdef USE_STORE
218201 , Data.Store.Store
219202#endif
220−#ifdef BACKEND
221− , ToSchema, ToParamSchema
222203#endif
223− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
224− , ToHttpApiData, PathPiece, IsString, Semigroup, Monoid )
204+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
205+ , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece
206+ , IsString, Semigroup, Monoid )
225207
226208type role Name nominal
227209
@@ -239,10 +221,8 @@ instance KnownSymbol s => Read (Name s) where
239221 _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
240222 mkName <$> readS_to_P reads
241223
242−#ifdef BACKEND
243224instance Arbitrary (Name s) where
244225 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
245−#endif
246226
247227-- | This is a more \"explicit\" 'coerce' specifically for 'Name'.
248228-- You are forced to explicitly specify the phantom types you are converting