Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/route/src/Obelisk/Route.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ module Obelisk.Route
, fieldMapEncoder
, pathFieldEncoder
, jsonEncoder
, utf8Encoder
) where

import Prelude hiding ((.), id)
Expand Down Expand Up @@ -1274,6 +1275,14 @@ jsonEncoder = unsafeEncoder $ do
Right x -> return x
}

utf8Encoder :: (Applicative check, MonadError Text parse) => Encoder check parse Text BS.ByteString
utf8Encoder = unsafeMkEncoder $ EncoderImpl
{ _encoderImpl_encode = T.encodeUtf8
, _encoderImpl_decode = \bs -> case T.decodeUtf8' bs of
Left err -> throwError $ "utf8Encoder: " <> tshow err
Right x -> pure x
}

-- Useful for app server integration.
-- p must not start with slashes
byteStringsToPageName :: BS.ByteString -> BS.ByteString -> PageName
Expand Down
1 change: 1 addition & 0 deletions lib/route/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ atomicEncoders = let t n e = (n, Ex e) in
[ t "addPathSegmentEncoder" addPathSegmentEncoder
, t "fieldMapEncoder" $ fieldMapEncoder @_ @_ @XY
, t "jsonEncoder" $ jsonEncoder @_ @_ @Input
, t "utf8Encoder" utf8Encoder
, t "maybeToEitherEncoder" $ maybeToEitherEncoder @_ @_ @Input
, t "pathComponentEncoder" fragmentEncoder
, t "pathSegmentsTextEncoder" pathSegmentsTextEncoder
Expand Down
Loading