Skip to content

Commit

Permalink
No warrnings
Browse files Browse the repository at this point in the history
  • Loading branch information
robashton committed Jul 6, 2019
1 parent caa9dd5 commit f5f8dd4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/Stetson.Rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ Create an rest response for return from a rest callback
yeeha :: forall state. RestHandler state -> StetsonHandler state
```

Finish defining this rest handler, yeehaaw
Finish defining this rest handler_, yeehaaw


10 changes: 5 additions & 5 deletions src/Stetson.purs
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,21 @@ middlewares mws config =

-- | Start the listener with the specified name
startClear :: String -> StetsonConfig -> Effect Unit
startClear name config@{ bindAddress, bindPort, streamHandlers, middlewares } = do
startClear name config@{ bindAddress, bindPort, streamHandlers: streamHandlers_, middlewares: middlewares_ } = do
let paths = createRoute <$> reverse config.routes
dispatch = Routes.compile $ singleton $ Routes.anyHost paths
transOpts = Ip bindAddress : Port bindPort : nil
protoOpts = protocolOpts $
Env (env (Dispatch dispatch : nil)) : nil
<> List.fromFoldable (StreamHandlers <$> streamHandlers)
<> List.fromFoldable (Middlewares <$> middlewares)
<> List.fromFoldable (StreamHandlers <$> streamHandlers_)
<> List.fromFoldable (Middlewares <$> middlewares_)
_ <- Cowboy.startClear (atom name) transOpts protoOpts
pure unit


createRoute :: ConfiguredRoute -> Path
createRoute (Stetson { route, moduleName, args }) =
Routes.path route moduleName (Routes.InitialState $ unsafeToForeign args)
createRoute (Stetson { route: route_, moduleName, args }) =
Routes.path route_ moduleName (Routes.InitialState $ unsafeToForeign args)

createRoute (Cowboy path) = path

Expand Down
24 changes: 12 additions & 12 deletions src/Stetson/Rest.purs
Original file line number Diff line number Diff line change
Expand Up @@ -48,47 +48,47 @@ handler init = {

-- | Add an allowedMethods callback to the provided RestHandler
allowedMethods :: forall state. (Req -> state -> Effect (RestResult (List HttpMethod) state)) -> RestHandler state -> RestHandler state
allowedMethods fn handler = (handler { allowedMethods = Just fn })
allowedMethods fn handler_ = (handler_ { allowedMethods = Just fn })

-- | Add a resourceExists callback to the provided RestHandler
resourceExists :: forall state. (Req -> state -> Effect (RestResult Boolean state)) -> RestHandler state -> RestHandler state
resourceExists fn handler = (handler { resourceExists = Just fn })
resourceExists fn handler_ = (handler_ { resourceExists = Just fn })

-- | Add an isAuthorized callback to the provided RestHandler
isAuthorized :: forall state. (Req -> state -> Effect (RestResult Authorized state)) -> RestHandler state -> RestHandler state
isAuthorized fn handler = (handler { isAuthorized = Just fn })
isAuthorized fn handler_ = (handler_ { isAuthorized = Just fn })

-- | Add a contentTypesAccepted callback to the provided RestHandler
contentTypesAccepted :: forall state. (Req -> state -> Effect (RestResult (List (Tuple2 String (AcceptHandler state))) state)) -> RestHandler state -> RestHandler state
contentTypesAccepted fn handler = (handler { contentTypesAccepted = Just fn })
contentTypesAccepted fn handler_ = (handler_ { contentTypesAccepted = Just fn })

-- | Add a contentTypesProvided callback to the provided RestHandler
contentTypesProvided :: forall state. (Req -> state -> Effect (RestResult (List (Tuple2 String (ProvideHandler state))) state)) -> RestHandler state -> RestHandler state
contentTypesProvided fn handler = (handler { contentTypesProvided = Just fn })
contentTypesProvided fn handler_ = (handler_ { contentTypesProvided = Just fn })

-- | Add a deleteResource callback to the provided RestHandler
deleteResource :: forall state. (Req -> state -> Effect (RestResult Boolean state)) -> RestHandler state -> RestHandler state
deleteResource fn handler = (handler { deleteResource = Just fn })
deleteResource fn handler_ = (handler_ { deleteResource = Just fn })

-- | Add a movedTemporarily callback to the provided RestHandler
movedTemporarily :: forall state. (Req -> state -> Effect (RestResult MovedResult state)) -> RestHandler state -> RestHandler state
movedTemporarily fn handler = (handler { movedTemporarily = Just fn })
movedTemporarily fn handler_ = (handler_ { movedTemporarily = Just fn })

-- | Add a movedPermanently callback to the provided RestHandler
movedPermanently :: forall state. (Req -> state -> Effect (RestResult MovedResult state)) -> RestHandler state -> RestHandler state
movedPermanently fn handler = (handler { movedPermanently = Just fn })
movedPermanently fn handler_ = (handler_ { movedPermanently = Just fn })

-- | Add a serviceAvailable callback to the provided RestHandler
serviceAvailable :: forall state. (Req -> state -> Effect (RestResult Boolean state)) -> RestHandler state -> RestHandler state
serviceAvailable fn handler = (handler { serviceAvailable = Just fn })
serviceAvailable fn handler_ = (handler_ { serviceAvailable = Just fn })

-- | Add a previouslyExisted callback to the provided RestHandler
previouslyExisted :: forall state. (Req -> state -> Effect (RestResult Boolean state)) -> RestHandler state -> RestHandler state
previouslyExisted fn handler = (handler { previouslyExisted = Just fn })
previouslyExisted fn handler_ = (handler_ { previouslyExisted = Just fn })

-- | Add a forbidden callback to the provided RestHandler
forbidden :: forall state. (Req -> state -> Effect (RestResult Boolean state)) -> RestHandler state -> RestHandler state
forbidden fn handler = (handler { forbidden = Just fn })
forbidden fn handler_ = (handler_ { forbidden = Just fn })

-- | Create an init response for return from an InitHandler
initResult :: forall state. Req -> state -> Effect (InitResult state)
Expand All @@ -98,6 +98,6 @@ initResult rq st = pure $ InitOk rq st
result :: forall reply state. reply -> Req -> state -> Effect (RestResult reply state)
result re rq st = pure $ RestOk re rq st

-- | Finish defining this rest handler, yeehaaw
-- | Finish defining this rest handler_, yeehaaw
yeeha :: forall state. RestHandler state -> StetsonHandler state
yeeha = Rest
27 changes: 27 additions & 0 deletions src/Stetson/RestHandler.purs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ restResult outerState (Just result) = do
-- The function is entirely ignored and is therefore treated as optional
restResult outerState Nothing = noCall

noCall :: forall t3 t4. Applicative t3 => t3 t4
noCall = pure $ unsafeCoerce (atom "no_call")

accept :: forall state. Int -> EffectFn2 Req (State state) (Cowboy.RestResult Boolean (State state))
Expand All @@ -122,19 +123,45 @@ provide i = mkEffectFn2 \req state@{ provideHandlers } ->
call (provideHandlers !! i) req state


accept_0 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult Boolean (State state))
accept_0 = accept 0

accept_1 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult Boolean (State state))
accept_1 = accept 1

accept_2 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult Boolean (State state))
accept_2 = accept 2

accept_3 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult Boolean (State state))
accept_3 = accept 3

accept_4 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult Boolean (State state))
accept_4 = accept 4

accept_5 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult Boolean (State state))
accept_5 = accept 5

accept_6 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult Boolean (State state))
accept_6 = accept 6

provide_0 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult String (State state))
provide_0 = provide 0

provide_1 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult String (State state))
provide_1 = provide 1

provide_2 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult String (State state))
provide_2 = provide 2

provide_3 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult String (State state))
provide_3 = provide 3

provide_4 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult String (State state))
provide_4 = provide 4

provide_5 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult String (State state))
provide_5 = provide 5

provide_6 :: forall state. EffectFn2 Req (State state) (Cowboy.RestResult String (State state))
provide_6 = provide 6

0 comments on commit f5f8dd4

Please sign in to comment.