0 | module TyTTP.Adapter.Node.URI
 1 |
 2 | import Control.Monad.Maybe
 3 | import Node.JS.Std.URI
 4 | import TyTTP
 5 |
 6 | export
 7 | decodeUri : Alternative m
 8 |   => (
 9 |     Context me String v h1 s h2 a b
10 |     -> m $ Context me' String v' h1' s' h2' a' b'
11 |   )
12 |   -> Context me String v h1 s h2 a b
13 |   -> m $ Context me' String v' h1' s' h2' a' b'
14 | decodeUri handler ctx = case Std.URI.decodeURI ctx.request.url of
15 |   Right str => handler $ { request.url := str } ctx
16 |   Left _ => empty
17 |
18 | export
19 | decodeUri' : Monad m
20 |   => (
21 |     Context me String v h1 s h2 a b
22 |     -> m $ Context me' String v' h1' s' h2' a' b'
23 |   )
24 |   -> (
25 |     Context me String v h1 s h2 a b
26 |     -> MaybeT m $ Context me' String v' h1' s' h2' a' b'
27 |   )
28 |   -> Context me String v h1 s h2 a b
29 |   -> m $ Context me' String v' h1' s' h2' a' b'
30 | decodeUri' defHandler handler ctx = do
31 |   Just result <- runMaybeT $ decodeUri handler ctx
32 |     | Nothing => defHandler ctx
33 |   pure result
34 |