on a468684 help sign in
cabal.projectdeleted−11
since splitsnapshots
unifiedsplit
@@ -1,11 +0,0 @@
1−packages:
2− .
3−
4−-- To compile with js-backend use this:
5−source-repository-package
6− type: git
7− location: https://github.com/typeable/uuid.git
8− tag: 49f50ae517de0e4d5dfbf783edc61e71cfd54d6b
9− subdir:
10− uuid
11− uuid-types
id.cabal+74−61
@@ -1,77 +1,90 @@
1−cabal-version: 2.4
1+cabal-version: 2.4
2−name: id
3−version: 0.2.0.0
4−license-file: LICENSE
5
2
6−flag cassava
3+name: id
7− description: Enable Postgresql support
4+version: 0.2.0.0
8− default: True
5+license-file: LICENSE
9− manual: False
10
6
11−flag postgres
7+Flag cassava
12− description: Enable Postgresql support
8+ Description: Enable Cassava support
13− default: True
9+ Default: True
14− manual: False
10+ Manual: False
15
11
16−flag flat
12+Flag postgres
17− description: Enable Flat serialization support
13+ Description: Enable Postgresql support
18− default: True
14+ Default: True
19− manual: False
15+ Manual: False
20
16
21−flag store
17+Flag rel8
22− description: Enable Data.Store serialization support
18+ Description: Enable Rel8 support
23− default: False
19+ Default: False
24− manual: False
20+ Manual: False
25
21
26−flag uuid-impl
22+Flag flat
27− description: Include some functions with extra dependencies.
23+ Description: Enable Flat serialization support
28− Disable to reduce dependencies.
24+ Default: True
29− default: True
25+ Manual: False
26+
27+Flag store
28+ Description: Enable Data.Store serialization support
29+ Default: False
30+ Manual: False
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
30− manual: False
40+ Manual: False
31
41
32library
42library
33− exposed-modules: Data.Id
43+ exposed-modules:
44+ Data.Id
45+ -- other-modules:
46+ -- other-extensions:
34 build-depends:
47 build-depends:
35− , aeson >=1.0
48+ aeson,
36− , base >=4.12 && <5
49+ base >=4.12 && <5,
37− , binary
50+ binary,
38− , deepseq
51+ deepseq,
39− , hashable
52+ hashable,
40− , http-api-data
53+ http-api-data,
41− , lens
42− , path-pieces
54+ path-pieces,
43− , text
55+ text,
56+ QuickCheck,
44− , uuid-types
57+ uuid,
45− if flag(uuid-impl)
58+ if flag(postgres) && !impl(ghcjs)
46 build-depends:
59 build-depends:
47− , uuid >=1.3.9
60+ postgresql-simple
48− cpp-options: -DUSE_UUID
61+ cpp-options: -DUSE_POSTGRES
49−
50− if !(impl(ghcjs) || arch(javascript) || arch(wasm32))
62+ if flag(rel8) && !impl(ghcjs)
63+ build-depends: rel8
64+ cpp-options: -DUSE_REL8
65+ if flag(cassava) && !impl(ghcjs)
51 build-depends:
66 build-depends:
52− , openapi3
67+ cassava
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
68+ cpp-options: -DUSE_CASSAVA
64−
65 if flag(flat)
69 if flag(flat)
66− build-depends: flat >=0.4
70+ build-depends:
71+ flat,
67− cpp-options: -DUSE_FLAT
72+ cpp-options: -DUSE_FLAT
68−
69 if flag(store)
73 if flag(store)
70− build-depends: store
74+ build-depends:
75+ store,
71− 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
72
83
73− hs-source-dirs: src
84+ hs-source-dirs:
85+ src
74− default-language: Haskell2010
86+ default-language:
87+ Haskell2010
75 default-extensions:
88 default-extensions:
76 AllowAmbiguousTypes
89 AllowAmbiguousTypes
77 DeriveGeneric
90 DeriveGeneric
src/Data/Id.hs+54−46
@@ -4,39 +4,35 @@
4{-# OPTIONS_GHC -Wno-orphans #-}
4{-# OPTIONS_GHC -Wno-orphans #-}
5
5
6module Data.Id
6module Data.Id
7− ( Id, mkId, unId, 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_UUID
10+#ifdef USE_LENS
11− , randomId
11+ , _Id, _IntId, _Name
12#endif
12#endif
13 )
13 )
14 where
14 where
15
15
16import Control.DeepSeq (NFData)
16import Control.DeepSeq (NFData)
17+#ifdef USE_LENS
17import Control.Lens
18import Control.Lens
19+#endif
18import Control.Monad
20import Control.Monad
19import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
21import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey)
20import Data.Binary (Binary)
22import Data.Binary (Binary)
21import Data.Coerce (coerce)
23import Data.Coerce (coerce)
22import Data.Data
24import Data.Data
23import Data.Hashable (Hashable)
25import Data.Hashable (Hashable)
26+import Data.Int (Int64)
27+#ifdef USE_OPENAPI
28+import Data.OpenApi
29+#endif
24import Data.String
30import Data.String
25import Data.Text as T
31import Data.Text as T
26−import Data.UUID.Types (UUID)
32+import Data.UUID (UUID)
27−import qualified Data.UUID.Types as UUID
33+import qualified Data.UUID 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
35import qualified Data.UUID.V4 as UUID.V4
34import qualified Data.UUID.V4 as UUID.V4
36−#endif
35+#ifndef ghcjs_HOST_OS
37−#ifdef BACKEND
38−import Data.OpenApi
39−import Test.QuickCheck
40#ifdef USE_CASSAVA
36#ifdef USE_CASSAVA
41import Data.Csv as Csv hiding(Name)
37import Data.Csv as Csv hiding(Name)
42#endif
38#endif
@@ -45,13 +41,20 @@ import Database.PostgreSQL.Simple.FromField as PG (FromField)
45import Database.PostgreSQL.Simple.ToField as PG (ToField)
41import Database.PostgreSQL.Simple.ToField as PG (ToField)
46#endif
42#endif
47#endif
43#endif
48−
44+import GHC.TypeLits
45+import Test.QuickCheck
46+import Text.ParserCombinators.ReadP
47+import Web.HttpApiData
48+import Web.PathPieces (PathPiece(..))
49#ifdef USE_FLAT
49#ifdef USE_FLAT
50import Flat as F
50import Flat as F
51#endif
51#endif
52#ifdef USE_STORE
52#ifdef USE_STORE
53import qualified Data.Store
53import qualified Data.Store
54#endif
54#endif
55+#ifdef USE_REL8
56+import Rel8 (DBType(..))
57+#endif
55
58
56newtype Id t = Id { unId :: UUID }
59newtype Id t = Id { unId :: UUID }
57 deriving stock Data
60 deriving stock Data
@@ -61,29 +64,28 @@ newtype Id t = Id { unId :: UUID }
61#ifdef USE_POSTGRES
64#ifdef USE_POSTGRES
62 , PG.ToField, PG.FromField
65 , PG.ToField, PG.FromField
63#endif
66#endif
67+#ifdef USE_REL8
68+ , DBType
69+#endif
64#endif
70#endif
65 , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
71 , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
66−#ifdef BACKEND
72+#ifdef USE_OPENAPI
67 , ToSchema, ToParamSchema
73 , ToSchema, ToParamSchema
68#endif
74#endif
69 , FromHttpApiData, ToHttpApiData )
75 , FromHttpApiData, ToHttpApiData )
70
76
71type role Id nominal
77type role Id nominal
72
78
73−makePrisms ''Id
74−
75mkId :: forall s. UUID -> Id s
79mkId :: forall s. UUID -> Id s
76mkId = coerce
80mkId = coerce
77{-# INLINE mkId #-}
81{-# INLINE mkId #-}
78
82
79−#ifdef USE_UUID
80randomId :: forall s. IO (Id s)
83randomId :: forall s. IO (Id s)
81randomId = coerce <$> UUID.V4.nextRandom
84randomId = coerce <$> UUID.V4.nextRandom
82{-# INLINE randomId #-}
85{-# INLINE randomId #-}
83−#endif
84
86
85instance KnownSymbol s => Show (Id s) where
87instance KnownSymbol s => Show (Id s) where
86− show (Id v) = "Id-" <> symbolVal (Proxy @s) <> "-" <> P.show v
88+ show (Id v) = "Id-" <> symbolVal (Proxy @s) <> "-" <> show v
87
89
88instance KnownSymbol s => Read (Id s) where
90instance KnownSymbol s => Read (Id s) where
89 readsPrec _ = readP_to_S $ do
91 readsPrec _ = readP_to_S $ do
@@ -104,14 +106,12 @@ instance Data.Store.Store (Id s) where
104 size = Data.Store.ConstSize 16
106 size = Data.Store.ConstSize 16
105#endif
107#endif
106
108
107−#ifdef BACKEND
108instance Arbitrary (Id t) where
109instance Arbitrary (Id t) where
109 arbitrary = fmap Id $ UUID.fromWords
110 arbitrary = fmap Id $ UUID.fromWords
110 <$> arbitrary
111 <$> arbitrary
111 <*> arbitrary
112 <*> arbitrary
112 <*> arbitrary
113 <*> arbitrary
113 <*> arbitrary
114 <*> arbitrary
114−#endif
115
115
116instance PathPiece (Id t) where
116instance PathPiece (Id t) where
117 fromPathPiece = coerce . UUID.fromText
117 fromPathPiece = coerce . UUID.fromText
@@ -148,7 +148,7 @@ type family Ambiguous (a :: k) :: j where
148 Ambiguous x = x
148 Ambiguous x = x
149
149
150----------------- IntId
150----------------- IntId
151−newtype IntId t = IntId { unIntId :: Integer }
151+newtype IntId t = IntId { unIntId :: Int64 }
152 deriving stock Data
152 deriving stock Data
153 deriving newtype
153 deriving newtype
154 ( Eq, Ord, Binary
154 ( Eq, Ord, Binary
@@ -159,29 +159,31 @@ newtype IntId t = IntId { unIntId :: Integer }
159#ifdef USE_CASSAVA
159#ifdef USE_CASSAVA
160 , Csv.ToField, Csv.FromField
160 , Csv.ToField, Csv.FromField
161#endif
161#endif
162−#endif
163#ifdef USE_FLAT
162#ifdef USE_FLAT
164 , Flat
163 , Flat
165#endif
164#endif
166#ifdef USE_STORE
165#ifdef USE_STORE
167 , Data.Store.Store
166 , Data.Store.Store
168#endif
167#endif
169−#ifdef BACKEND
168+#ifdef USE_REL8
170− , ToSchema, ToParamSchema, Arbitrary
169+ , DBType
171#endif
170#endif
171+#endif
172− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
172+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
173+#ifdef USE_OPENAPI
174+ , ToSchema, ToParamSchema
175+#endif
176+ , FromHttpApiData, ToHttpApiData, PathPiece, Arbitrary
173− , ToHttpApiData, PathPiece, Num, Integral, Real, Enum )
177+ , Num, Integral, Real, Enum )
174
178
175type role IntId nominal
179type role IntId nominal
176
180
177−makePrisms ''IntId
178−
179mkIntId :: forall s. Integer -> IntId s
181mkIntId :: forall s. Integer -> IntId s
180−mkIntId = coerce
182+mkIntId = fromInteger
181{-# INLINE mkIntId #-}
183{-# INLINE mkIntId #-}
182
184
183instance KnownSymbol s => Show (IntId s) where
185instance KnownSymbol s => Show (IntId s) where
184− show (IntId v) = "IntId-" <> symbolVal (Proxy @s) <> "-" <> P.show v
186+ show (IntId v) = "IntId-" <> symbolVal (Proxy @s) <> "-" <> show v
185
187
186instance KnownSymbol s => Read (IntId s) where
188instance KnownSymbol s => Read (IntId s) where
187 readsPrec _ = readP_to_S $ do
189 readsPrec _ = readP_to_S $ do
@@ -210,39 +212,39 @@ newtype Name t = Name { unName :: Text }
210#ifdef USE_CASSAVA
212#ifdef USE_CASSAVA
211 , Csv.ToField, Csv.FromField
213 , Csv.ToField, Csv.FromField
212#endif
214#endif
213−#endif
214#ifdef USE_FLAT
215#ifdef USE_FLAT
215 , Flat
216 , Flat
216#endif
217#endif
217#ifdef USE_STORE
218#ifdef USE_STORE
218 , Data.Store.Store
219 , Data.Store.Store
219#endif
220#endif
220−#ifdef BACKEND
221+#ifdef USE_REL8
222+ , DBType
223+#endif
224+#endif
225+ , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey
226+#ifdef USE_OPENAPI
221 , ToSchema, ToParamSchema
227 , ToSchema, ToParamSchema
222#endif
228#endif
223− , FromJSON, ToJSON, NFData, Hashable, FromJSONKey, ToJSONKey, FromHttpApiData
229+ , FromHttpApiData, ToHttpApiData, PathPiece
224− , ToHttpApiData, PathPiece, IsString, Semigroup, Monoid )
230+ , IsString, Semigroup, Monoid )
225
231
226type role Name nominal
232type role Name nominal
227
233
228−makePrisms ''Name
229−
230mkName :: forall s. Text -> Name s
234mkName :: forall s. Text -> Name s
231mkName = coerce
235mkName = coerce
232{-# INLINE mkName #-}
236{-# INLINE mkName #-}
233
237
234instance KnownSymbol s => Show (Name s) where
238instance KnownSymbol s => Show (Name s) where
235− show (Name v) = "Name-" <> symbolVal (Proxy @s) <> "-" <> P.show v
239+ show (Name v) = "Name-" <> symbolVal (Proxy @s) <> "-" <> show v
236
240
237instance KnownSymbol s => Read (Name s) where
241instance KnownSymbol s => Read (Name s) where
238 readsPrec _ = readP_to_S $ do
242 readsPrec _ = readP_to_S $ do
239 _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
243 _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
240 mkName <$> readS_to_P reads
244 mkName <$> readS_to_P reads
241
245
242−#ifdef BACKEND
243instance Arbitrary (Name s) where
246instance Arbitrary (Name s) where
244 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
247 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
245−#endif
246
248
247-- | This is a more \"explicit\" 'coerce' specifically for 'Name'.
249-- | This is a more \"explicit\" 'coerce' specifically for 'Name'.
248-- You are forced to explicitly specify the phantom types you are converting
250-- You are forced to explicitly specify the phantom types you are converting
@@ -253,3 +255,9 @@ coerceName = coerce
253{-# INLINE coerceName #-}
255{-# INLINE coerceName #-}
254unsafeNameTagConvert = coerce
256unsafeNameTagConvert = coerce
255{-# 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