on master help sign in
2 files changed+100−72
since splitsnapshots
unifiedsplit
id.cabal+61−53 src/Data/Id.hs+39−19
id.cabal+61−53
@@ -1,69 +1,77 @@
1−cabal-version: 2.4
1+cabal-version: 2.4
2+name: id
3+version: 0.2.0.0
4+license-file: LICENSE
25
3−name: id
4−version: 0.2.0.0
5−license-file: LICENSE
6+flag cassava
7+ description: Enable Postgresql support
8+ default: True
9+ manual: False
610
7−Flag cassava
8− Description: Enable Postgresql support
9− Default: True
10− Manual: False
11+flag postgres
12+ description: Enable Postgresql support
13+ default: True
14+ manual: False
1115
16+flag flat
17+ description: Enable Flat serialization support
18+ default: True
19+ manual: False
1220
13−Flag postgres
14− Description: Enable Postgresql support
15− Default: True
16− Manual: False
21+flag store
22+ description: Enable Data.Store serialization support
23+ default: False
24+ manual: False
1725
18−Flag flat
19− Description: Enable Flat serialization support
20− Default: True
21− Manual: False
22−
23−Flag store
24− Description: Enable Data.Store serialization support
25− Default: False
26− Manual: False
26+flag uuid-impl
27+ description: Include some functions with extra dependencies.
28+ Disable to reduce dependencies.
29+ default: True
30+ manual: False
2731
2832library
29− exposed-modules:
30− Data.Id
31− -- other-modules:
32− -- other-extensions:
33+ exposed-modules: Data.Id
3334 build-depends:
34− aeson,
35− base >=4.12 && <5,
36− binary,
37− deepseq,
38− hashable,
39− http-api-data,
40− lens,
41− openapi3,
42− path-pieces,
43− text,
44− QuickCheck,
45− uuid,
46− if flag(postgres) && !(impl(ghcjs) || arch(javascript))
35+ , aeson >=1.0
36+ , base >=4.12 && <5
37+ , binary
38+ , deepseq
39+ , hashable
40+ , http-api-data
41+ , lens
42+ , path-pieces
43+ , text
44+ , uuid-types
45+ if flag(uuid-impl)
4746 build-depends:
48− postgresql-simple
49− cpp-options: -DUSE_POSTGRES
50− if flag(cassava) && !(impl(ghcjs) || arch(javascript))
47+ , uuid >=1.3.9
48+ cpp-options: -DUSE_UUID
49+
50+ if !(impl(ghcjs) || arch(javascript) || arch(wasm32))
5151 build-depends:
52− cassava
53− cpp-options: -DUSE_CASSAVA
52+ , openapi3
53+ , QuickCheck
54+
55+ cpp-options: -DBACKEND
56+
57+ if (flag(postgres) && !(impl(ghcjs) || arch(javascript) || arch(wasm32)))
58+ build-depends: postgresql-simple
59+ cpp-options: -DUSE_POSTGRES
60+
61+ if (flag(cassava) && !(impl(ghcjs) || arch(javascript) || arch(wasm32)))
62+ build-depends: cassava
63+ cpp-options: -DUSE_CASSAVA
64+
5465 if flag(flat)
55− build-depends:
56− flat,
57− cpp-options: -DUSE_FLAT
66+ build-depends: flat >=0.4
67+ cpp-options: -DUSE_FLAT
68+
5869 if flag(store)
59− build-depends:
60− store,
61− cpp-options: -DUSE_STORE
70+ build-depends: store
71+ cpp-options: -DUSE_STORE
6272
63− hs-source-dirs:
64− src
65− default-language:
66− Haskell2010
73+ hs-source-dirs: src
74+ default-language: Haskell2010
6775 default-extensions:
6876 AllowAmbiguousTypes
6977 DeriveGeneric
src/Data/Id.hs+39−19
@@ -4,9 +4,12 @@
44{-# OPTIONS_GHC -Wno-orphans #-}
55
66module Data.Id
7− ( Id, mkId, unId, randomId, unsafeIdTagConvert, coerceId, _Id, nilId
7+ ( Id, mkId, unId, 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
1013 )
1114 where
1215
@@ -18,13 +21,22 @@ import Data.Binary (Binary)
1821import Data.Coerce (coerce)
1922import Data.Data
2023import Data.Hashable (Hashable)
21−import Data.OpenApi
2224import Data.String
2325import Data.Text as T
24−import Data.UUID (UUID)
25−import qualified Data.UUID as UUID
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
2635import qualified Data.UUID.V4 as UUID.V4
27−#ifndef ghcjs_HOST_OS
36+#endif
37+#ifdef BACKEND
38+import Data.OpenApi
39+import Test.QuickCheck
2840#ifdef USE_CASSAVA
2941import Data.Csv as Csv hiding(Name)
3042#endif
@@ -33,12 +45,7 @@ import Database.PostgreSQL.Simple.FromField as PG (FromField)
3345import Database.PostgreSQL.Simple.ToField as PG (ToField)
3446#endif
3547#endif
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(..))
48+
4249#ifdef USE_FLAT
4350import Flat as F
4451#endif
@@ -55,8 +62,11 @@ newtype Id t = Id { unId :: UUID }
5562 , PG.ToField, PG.FromField
5663#endif
5764#endif
58− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
59− , ToParamSchema, FromHttpApiData, ToHttpApiData )
65+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
66+#ifdef BACKEND
67+ , ToSchema, ToParamSchema
68+#endif
69+ , FromHttpApiData, ToHttpApiData )
6070
6171type role Id nominal
6272
@@ -66,9 +76,11 @@ mkId :: forall s. UUID -> Id s
6676mkId = coerce
6777{-# INLINE mkId #-}
6878
79+#ifdef USE_UUID
6980randomId :: forall s. IO (Id s)
7081randomId = coerce <$> UUID.V4.nextRandom
7182{-# INLINE randomId #-}
83+#endif
7284
7385instance KnownSymbol s => Show (Id s) where
7486 show (Id v) = "Id-" <> symbolVal (Proxy @s) <> "-" <> P.show v
@@ -92,12 +104,14 @@ instance Data.Store.Store (Id s) where
92104 size = Data.Store.ConstSize 16
93105#endif
94106
107+#ifdef BACKEND
95108instance Arbitrary (Id t) where
96109 arbitrary = fmap Id $ UUID.fromWords
97110 <$> arbitrary
98111 <*> arbitrary
99112 <*> arbitrary
100113 <*> arbitrary
114+#endif
101115
102116instance PathPiece (Id t) where
103117 fromPathPiece = coerce . UUID.fromText
@@ -145,16 +159,18 @@ newtype IntId t = IntId { unIntId :: Integer }
145159#ifdef USE_CASSAVA
146160 , Csv.ToField, Csv.FromField
147161#endif
162+#endif
148163#ifdef USE_FLAT
149164 , Flat
150165#endif
151166#ifdef USE_STORE
152167 , Data.Store.Store
153168#endif
169+#ifdef BACKEND
170+ , ToSchema, ToParamSchema, Arbitrary
154171#endif
155− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
156− , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece, Arbitrary
157− , Num, Integral, Real, Enum )
172+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
173+ , ToHttpApiData, PathPiece, Num, Integral, Real, Enum )
158174
159175type role IntId nominal
160176
@@ -194,16 +210,18 @@ newtype Name t = Name { unName :: Text }
194210#ifdef USE_CASSAVA
195211 , Csv.ToField, Csv.FromField
196212#endif
213+#endif
197214#ifdef USE_FLAT
198215 , Flat
199216#endif
200217#ifdef USE_STORE
201218 , Data.Store.Store
202219#endif
220+#ifdef BACKEND
221+ , ToSchema, ToParamSchema
203222#endif
204− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
205− , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece
206− , IsString, Semigroup, Monoid )
223+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
224+ , ToHttpApiData, PathPiece, IsString, Semigroup, Monoid )
207225
208226type role Name nominal
209227
@@ -221,8 +239,10 @@ instance KnownSymbol s => Read (Name s) where
221239 _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
222240 mkName <$> readS_to_P reads
223241
242+#ifdef BACKEND
224243instance Arbitrary (Name s) where
225244 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
245+#endif
226246
227247-- | This is a more \"explicit\" 'coerce' specifically for 'Name'.
228248-- You are forced to explicitly specify the phantom types you are converting