git.iko.soy/typeable/random-token
on master help sign in
reduce js dependencies
commit7cdd6d77f230ceffc7a6a385fbc7667b3a38672f authorodr <dima.typeable.io> dateSun 12 Jan 2025, 11:40 (2 years ago) parent8a0e575
2 files changed+9−5
random-token.cabal+3−2 src/Random/Token.hs+6−3
random-token.cabal+3−2
@@ -17,12 +17,13 @@ library
1717 , aeson
1818 , base64-bytestring
1919 , bytestring
20− , cryptonite
2120 , deepseq
2221 , http-api-data
2322 , text
2423 if !(impl(ghcjs) || arch(javascript))
25− build-depends: postgresql-simple
24+ build-depends: cryptonite
25+ , postgresql-simple
26+ ,
2627 default-language: Haskell2010
2728 default-extensions: CPP
2829 , ConstraintKinds
src/Random/Token.hs+6−3
@@ -5,9 +5,11 @@ module Random.Token
55 , tokenToText
66 , asciiToToken
77 , textToToken
8− , generateToken
98 , unsafeCoerceToken
109 , tokenWithContents
10+#ifndef ghcjs_HOST_OS
11+ , generateToken
12+#endif
1113 ) where
1214
1315import Control.DeepSeq
@@ -22,9 +24,9 @@ import Data.Typeable
2224import Test.QuickCheck.Arbitrary
2325import Web.HttpApiData
2426
25−import Crypto.Random as R
2627
2728#ifndef ghcjs_HOST_OS
29+import Crypto.Random as R
2830import Database.PostgreSQL.Simple.FromField
2931import Database.PostgreSQL.Simple.ToField
3032#endif
@@ -54,11 +56,12 @@ instance forall a. (Typeable (Token a), Typeable a) => FromField (Token a) where
5456
5557instance ToField (Token a) where
5658 toField = toField . tokenToText
57−#endif
5859
5960generateToken :: (MonadRandom m) => m (Token a)
6061generateToken = Token <$> R.getRandomBytes 16
6162
63+#endif
64+
6265instance FromHttpApiData (Token a) where
6366 parseQueryParam = first T.pack . textToToken
6467