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