on a468684 help sign in
id.cabal+25−4
since splitsnapshots
unifiedsplit
@@ -5,16 +5,20 @@ version: 0.2.0.0
5license-file: LICENSE
5license-file: LICENSE
6
6
7Flag cassava
7Flag cassava
8− Description: Enable Postgresql support
8+ Description: Enable Cassava support
9 Default: True
9 Default: True
10 Manual: False
10 Manual: False
11
11
12−
13Flag postgres
12Flag postgres
14 Description: Enable Postgresql support
13 Description: Enable Postgresql support
15 Default: True
14 Default: True
16 Manual: False
15 Manual: False
17
16
17+Flag rel8
18+ Description: Enable Rel8 support
19+ Default: False
20+ Manual: False
21+
18Flag flat
22Flag flat
19 Description: Enable Flat serialization support
23 Description: Enable Flat serialization support
20 Default: True
24 Default: True
@@ -25,6 +29,16 @@ Flag store
25 Default: False
29 Default: False
26 Manual: False
30 Manual: False
27
31
32+Flag openapi
33+ Description: Enable OpenAPI instances
34+ Default: True
35+ Manual: False
36+
37+Flag lens
38+ Description: Generate lenses
39+ Default: True
40+ Manual: False
41+
28library
42library
29 exposed-modules:
43 exposed-modules:
30 Data.Id
44 Data.Id
@@ -37,8 +51,6 @@ library
37 deepseq,
51 deepseq,
38 hashable,
52 hashable,
39 http-api-data,
53 http-api-data,
40− lens,
41− openapi3,
42 path-pieces,
54 path-pieces,
43 text,
55 text,
44 QuickCheck,
56 QuickCheck,
@@ -47,6 +59,9 @@ library
47 build-depends:
59 build-depends:
48 postgresql-simple
60 postgresql-simple
49 cpp-options: -DUSE_POSTGRES
61 cpp-options: -DUSE_POSTGRES
62+ if flag(rel8) && !impl(ghcjs)
63+ build-depends: rel8
64+ cpp-options: -DUSE_REL8
50 if flag(cassava) && !impl(ghcjs)
65 if flag(cassava) && !impl(ghcjs)
51 build-depends:
66 build-depends:
52 cassava
67 cassava
@@ -59,6 +74,12 @@ library
59 build-depends:
74 build-depends:
60 store,
75 store,
61 cpp-options: -DUSE_STORE
76 cpp-options: -DUSE_STORE
77+ if flag(lens)
78+ build-depends: lens
79+ cpp-options: -DUSE_LENS
80+ if flag(openapi)
81+ build-depends: openapi3
82+ cpp-options: -DUSE_OPENAPI
62
83
63 hs-source-dirs:
84 hs-source-dirs:
64 src
85 src
src/Data/Id.hs+46−17
@@ -4,21 +4,29 @@
4{-# OPTIONS_GHC -Wno-orphans #-}
4{-# OPTIONS_GHC -Wno-orphans #-}
5
5
6module Data.Id
6module Data.Id
7− ( Id, mkId, unId, randomId, unsafeIdTagConvert, coerceId, _Id, nilId
7+ ( Id, mkId, unId, randomId, unsafeIdTagConvert, coerceId, nilId
8− , IntId, mkIntId, unIntId, unsafeIntIdTagConvert, coerceIntId, _IntId
8+ , IntId, mkIntId, unIntId, unsafeIntIdTagConvert, coerceIntId
9− , Name, mkName, unName, unsafeNameTagConvert, coerceName, _Name
9+ , Name, mkName, unName, unsafeNameTagConvert, coerceName
10+#ifdef USE_LENS
11+ , _Id, _IntId, _Name
12+#endif
10 )
13 )
11 where
14 where
12
15
13import Control.DeepSeq (NFData)
16import Control.DeepSeq (NFData)
17+#ifdef USE_LENS
14import Control.Lens
18import Control.Lens
19+#endif
15import Control.Monad
20import Control.Monad
16import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
21import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
17import Data.Binary (Binary)
22import Data.Binary (Binary)
18import Data.Coerce (coerce)
23import Data.Coerce (coerce)
19import Data.Data
24import Data.Data
20import Data.Hashable (Hashable)
25import Data.Hashable (Hashable)
26+import Data.Int (Int64)
27+#ifdef USE_OPENAPI
21import Data.OpenApi
28import Data.OpenApi
29+#endif
22import Data.String
30import Data.String
23import Data.Text as T
31import Data.Text as T
24import Data.UUID (UUID)
32import Data.UUID (UUID)
@@ -44,6 +52,9 @@ import Flat as F
44#ifdef USE_STORE
52#ifdef USE_STORE
45import qualified Data.Store
53import qualified Data.Store
46#endif
54#endif
55+#ifdef USE_REL8
56+import Rel8 (DBType(..))
57+#endif
47
58
48newtype Id t = Id { unId :: UUID }
59newtype Id t = Id { unId :: UUID }
49 deriving stock Data
60 deriving stock Data
@@ -53,14 +64,18 @@ newtype Id t = Id { unId :: UUID }
53#ifdef USE_POSTGRES
64#ifdef USE_POSTGRES
54 , PG.ToField, PG.FromField
65 , PG.ToField, PG.FromField
55#endif
66#endif
67+#ifdef USE_REL8
68+ , DBType
69+#endif
70+#endif
71+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
72+#ifdef USE_OPENAPI
73+ , ToSchema, ToParamSchema
56#endif
74#endif
57− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
58− , ToParamSchema, FromHttpApiData, ToHttpApiData )
75+ , FromHttpApiData, ToHttpApiData )
59
76
60type role Id nominal
77type role Id nominal
61
78
62−makePrisms ''Id
63−
64mkId :: forall s. UUID -> Id s
79mkId :: forall s. UUID -> Id s
65mkId = coerce
80mkId = coerce
66{-# INLINE mkId #-}
81{-# INLINE mkId #-}
@@ -133,7 +148,7 @@ type family Ambiguous (a :: k) :: j where
133 Ambiguous x = x
148 Ambiguous x = x
134
149
135----------------- IntId
150----------------- IntId
136−newtype IntId t = IntId { unIntId :: Integer }
151+newtype IntId t = IntId { unIntId :: Int64 }
137 deriving stock Data
152 deriving stock Data
138 deriving newtype
153 deriving newtype
139 ( Eq, Ord, Binary
154 ( Eq, Ord, Binary
@@ -150,17 +165,21 @@ newtype IntId t = IntId { unIntId :: Integer }
150#ifdef USE_STORE
165#ifdef USE_STORE
151 , Data.Store.Store
166 , Data.Store.Store
152#endif
167#endif
168+#ifdef USE_REL8
169+ , DBType
170+#endif
153#endif
171#endif
154− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
172+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
173+#ifdef USE_OPENAPI
174+ , ToSchema, ToParamSchema
175+#endif
155− , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece, Arbitrary
176+ , FromHttpApiData, ToHttpApiData, PathPiece, Arbitrary
156 , Num, Integral, Real, Enum )
177 , Num, Integral, Real, Enum )
157
178
158type role IntId nominal
179type role IntId nominal
159
180
160−makePrisms ''IntId
161−
162mkIntId :: forall s. Integer -> IntId s
181mkIntId :: forall s. Integer -> IntId s
163−mkIntId = coerce
182+mkIntId = fromInteger
164{-# INLINE mkIntId #-}
183{-# INLINE mkIntId #-}
165
184
166instance KnownSymbol s => Show (IntId s) where
185instance KnownSymbol s => Show (IntId s) where
@@ -199,15 +218,19 @@ newtype Name t = Name { unName :: Text }
199#ifdef USE_STORE
218#ifdef USE_STORE
200 , Data.Store.Store
219 , Data.Store.Store
201#endif
220#endif
221+#ifdef USE_REL8
222+ , DBType
223+#endif
224+#endif
225+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
226+#ifdef USE_OPENAPI
227+ , ToSchema, ToParamSchema
202#endif
228#endif
203− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, ToSchema
204− , ToParamSchema, FromHttpApiData, ToHttpApiData, PathPiece
229+ , FromHttpApiData, ToHttpApiData, PathPiece
205 , IsString, Semigroup, Monoid )
230 , IsString, Semigroup, Monoid )
206
231
207type role Name nominal
232type role Name nominal
208
233
209−makePrisms ''Name
210−
211mkName :: forall s. Text -> Name s
234mkName :: forall s. Text -> Name s
212mkName = coerce
235mkName = coerce
213{-# INLINE mkName #-}
236{-# INLINE mkName #-}
@@ -232,3 +255,9 @@ coerceName = coerce
232{-# INLINE coerceName #-}
255{-# INLINE coerceName #-}
233unsafeNameTagConvert = coerce
256unsafeNameTagConvert = coerce
234{-# INLINE unsafeNameTagConvert #-}
257{-# INLINE unsafeNameTagConvert #-}
258+
259+#ifdef USE_LENS
260+makePrisms ''Id
261+makePrisms ''IntId
262+makePrisms ''Name
263+#endif
stack.yaml+13−1
@@ -1,4 +1,16 @@
1−resolver: lts-18.18
1+resolver: lts-19.31
2
2
3packages:
3packages:
4- .
4- .
5+
6+nix:
7+ packages: [ postgresql ]
8+
9+flags:
10+ id:
11+ rel8: false
12+ openapi: false
13+ lens: false
14+ cassava: false
15+ flat: false
16+ store: false