-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUUIDHelpers.hs
More file actions
38 lines (28 loc) · 1.1 KB
/
UUIDHelpers.hs
File metadata and controls
38 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-# LANGUAGE OverloadedStrings #-}
module UUIDHelpers (
UUID,
module UUIDHelpers
) where
import Control.Arrow (left)
import Control.Monad.Fail (MonadFail)
import Data.Time.Clock (UTCTime)
--import Data.Time.Format.ISO8601 (iso8601Show)
import Data.UUID (fromASCIIBytes, fromText, toASCIIBytes, toText, UUID)
import Data.UUID.V4 (nextRandom)
import Data.UUID.V5 (generateNamed)
import Web.Scotty (Parsable(parseParam))
import qualified UnambiguiousStrings as US
instance Parsable UUID where
--parseParam :: US.LText -> Either US.LText UUID
parseParam = (maybe (Left "Unable to parse UUID") Right) . fromText . US.toStrictText
randomUUID :: IO UUID
randomUUID = nextRandom
--childUUIDFromTime :: UUID -> UTCTime -> UUID -- This does not guarentee good resolution or abscence of collisions.
--childFromTime parent time =
-- generateNamed parent $ US.unpackSBytes $ US.strictEncode $ US.packSText $ iso8601Show time
asPassword :: UUID -> US.SBytes
asPassword = toASCIIBytes
toSText :: UUID -> US.SText
toSText = toText
fromSText :: US.SText -> Maybe UUID
fromSText = fromText