on dea6728 help sign in
id.cabal+2−7
since splitsnapshots
unifiedsplit
@@ -33,17 +33,12 @@ library
33 , hashable
33 , hashable
34 , http-api-data
34 , http-api-data
35 , lens
35 , lens
36+ , openapi3
36 , path-pieces
37 , path-pieces
38+ , QuickCheck
37 , text
39 , text
38 , uuid >=1.3.9
40 , uuid >=1.3.9
39
41
40− if !(impl(ghcjs) || arch(javascript))
41− build-depends:
42− , openapi3
43− , QuickCheck
44−
45− cpp-options: -DBACKEND
46−
47 if (flag(postgres) && !(impl(ghcjs) || arch(javascript)))
42 if (flag(postgres) && !(impl(ghcjs) || arch(javascript)))
48 build-depends: postgresql-simple
43 build-depends: postgresql-simple
49 cpp-options: -DUSE_POSTGRES
44 cpp-options: -DUSE_POSTGRES
src/Data/Id.hs+13−23
@@ -18,6 +18,7 @@ import Data.Binary (Binary)
18import Data.Coerce (coerce)
18import Data.Coerce (coerce)
19import Data.Data
19import Data.Data
20import Data.Hashable (Hashable)
20import Data.Hashable (Hashable)
21+import Data.OpenApi
21import Data.String
22import Data.String
22import Data.Text as T
23import Data.Text as T
23import Data.UUID (UUID)
24import Data.UUID (UUID)
@@ -25,13 +26,11 @@ import qualified Data.UUID as UUID
25import qualified Data.UUID.V4 as UUID.V4
26import qualified Data.UUID.V4 as UUID.V4
26import GHC.TypeLits
27import GHC.TypeLits
27import Prelude as P
28import Prelude as P
29+import Test.QuickCheck
28import Text.ParserCombinators.ReadP
30import Text.ParserCombinators.ReadP
29import Web.HttpApiData
31import Web.HttpApiData
30import Web.PathPieces (PathPiece(..))
32import Web.PathPieces (PathPiece(..))
31
33
32−#ifdef BACKEND
33−import Data.OpenApi
34−import Test.QuickCheck
35#ifdef USE_CASSAVA
34#ifdef USE_CASSAVA
36import Data.Csv as Csv hiding(Name)
35import Data.Csv as Csv hiding(Name)
37#endif
36#endif
@@ -39,7 +38,6 @@ import Data.Csv as Csv hiding(Name)
39import Database.PostgreSQL.Simple.FromField as PG (FromField)
38import Database.PostgreSQL.Simple.FromField as PG (FromField)
40import Database.PostgreSQL.Simple.ToField as PG (ToField)
39import Database.PostgreSQL.Simple.ToField as PG (ToField)
41#endif
40#endif
42−#endif
43
41
44#ifdef USE_FLAT
42#ifdef USE_FLAT
45import Flat as F
43import Flat as F
@@ -57,11 +55,9 @@ newtype Id t = Id { unId :: UUID }
57 , PG.ToField, PG.FromField
55 , PG.ToField, PG.FromField
58#endif
56#endif
59#endif
57#endif
60− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
58+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
61−#ifdef BACKEND
62− , ToSchema, ToParamSchema
63−#endif
64− , FromHttpApiData, ToHttpApiData )
59+ , ToParamSchema, FromHttpApiData, ToHttpApiData
60+ )
65
61
66type role Id nominal
62type role Id nominal
67
63
@@ -97,14 +93,12 @@ instance Data.Store.Store (Id s) where
97 size = Data.Store.ConstSize 16
93 size = Data.Store.ConstSize 16
98#endif
94#endif
99
95
100−#ifdef BACKEND
101instance Arbitrary (Id t) where
96instance Arbitrary (Id t) where
102 arbitrary = fmap Id $ UUID.fromWords
97 arbitrary = fmap Id $ UUID.fromWords
103 <$> arbitrary
98 <$> arbitrary
104 <*> arbitrary
99 <*> arbitrary
105 <*> arbitrary
100 <*> arbitrary
106 <*> arbitrary
101 <*> arbitrary
107−#endif
108
102
109instance PathPiece (Id t) where
103instance PathPiece (Id t) where
110 fromPathPiece = coerce . UUID.fromText
104 fromPathPiece = coerce . UUID.fromText
@@ -159,11 +153,10 @@ newtype IntId t = IntId { unIntId :: Integer }
159#ifdef USE_STORE
153#ifdef USE_STORE
160 , Data.Store.Store
154 , Data.Store.Store
161#endif
155#endif
162−#ifdef BACKEND
163− , ToSchema, ToParamSchema, Arbitrary
156+ , ToSchema, ToParamSchema, Arbitrary, FromJSON, ToJSON, NFData, Hashable
164−#endif
165− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
157+ , FromJSONKey, ToJSONKey, FromHttpApiData, ToHttpApiData, PathPiece, Num
166− , ToHttpApiData, PathPiece, Num, Integral, Real, Enum )
158+ , Integral, Real, Enum
159+ )
167
160
168type role IntId nominal
161type role IntId nominal
169
162
@@ -210,11 +203,10 @@ newtype Name t = Name { unName :: Text }
210#ifdef USE_STORE
203#ifdef USE_STORE
211 , Data.Store.Store
204 , Data.Store.Store
212#endif
205#endif
213−#ifdef BACKEND
214− , ToSchema, ToParamSchema
215−#endif
216− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
206+ , ToSchema, ToParamSchema, FromJSON, ToJSON, NFData, Hashable, FromJSONKey
217− , ToHttpApiData, PathPiece, IsString, Semigroup, Monoid )
207+ , ToJSONKey, FromHttpApiData, ToHttpApiData, PathPiece, IsString, Semigroup
208+ , Monoid
209+ )
218
210
219type role Name nominal
211type role Name nominal
220
212
@@ -232,10 +224,8 @@ instance KnownSymbol s => Read (Name s) where
232 _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
224 _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
233 mkName <$> readS_to_P reads
225 mkName <$> readS_to_P reads
234
226
235−#ifdef BACKEND
236instance Arbitrary (Name s) where
227instance Arbitrary (Name s) where
237 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
228 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
238−#endif
239
229
240-- | This is a more \"explicit\" 'coerce' specifically for 'Name'.
230-- | This is a more \"explicit\" 'coerce' specifically for 'Name'.
241-- 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