Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
updates for aff-4.0 and use purescript-records
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Oct 8, 2017
1 parent 23d24a6 commit 92a520a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 68 deletions.
7 changes: 4 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
"url": "git://github.com/paf31/purescript-quickserve.git"
},
"dependencies": {
"purescript-aff": "^3.1.0",
"purescript-aff": "^4.0.0",
"purescript-node-http": "^4.0.0",
"purescript-foreign-generic": "^4.1.0",
"purescript-typelevel-prelude": "^2.3.0"
"purescript-foreign-generic": "^5.0.0",
"purescript-typelevel-prelude": "^2.4.0",
"purescript-record": "^0.2.3"
}
}
2 changes: 1 addition & 1 deletion generated-docs/QuickServe.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Newtype Capture _

``` purescript
class ServableList eff (l :: RowList) (r :: # Type) | l -> r where
serveListWith :: LProxy l -> { | r } -> Request -> Response -> List String -> Maybe (Eff (http :: HTTP | eff) Unit)
serveListWith :: RLProxy l -> { | r } -> Request -> Response -> List String -> Maybe (Eff (http :: HTTP | eff) Unit)
```

##### Instances
Expand Down
26 changes: 0 additions & 26 deletions generated-docs/QuickServe/Internal.md

This file was deleted.

14 changes: 7 additions & 7 deletions src/QuickServe.purs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Control.Monad.Eff.Ref.Unsafe (unsafeRunRef)
import Control.Monad.Eff.Unsafe (unsafeCoerceEff)
import Control.Monad.Except (runExcept)
import Data.Bifunctor (bimap)
import Data.Either (Either(..))
import Data.Either (Either(..), either)
import Data.Foreign (renderForeignError)
import Data.Foreign.Class (class Decode, class Encode)
import Data.Foreign.Generic (decodeJSON, encodeJSON)
Expand All @@ -42,15 +42,15 @@ import Data.Maybe (Maybe(Nothing, Just), maybe)
import Data.Monoid (mempty)
import Data.Newtype (class Newtype, unwrap, wrap)
import Data.Nullable (toMaybe)
import Data.Record (get)
import Data.String (split)
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
import Node.Encoding (Encoding(..))
import Node.HTTP (HTTP, ListenOptions, Request, Response, createServer, listen, requestAsStream, requestMethod, requestURL, responseAsStream, setHeader, setStatusCode, setStatusMessage)
import Node.Stream (end, onDataString, onEnd, onError, writeString)
import Node.URL (parse)
import QuickServe.Internal (LProxy(..), get, rowToList)
import Type.Proxy (Proxy(..))
import Type.Row (class RowToList, Cons, Nil, kind RowList)
import Type.Row (class RowToList, Cons, Nil, RLProxy(..), kind RowList)
import Unsafe.Coerce (unsafeCoerce)

-- | A type class for types of values which define
Expand Down Expand Up @@ -179,7 +179,7 @@ instance servableMethod
let actual = requestMethod req
expected = reflectSymbol (SProxy :: SProxy method)
if actual == expected
then void $ runAff handleError handleResponse (unwrap respond)
then void $ runAff (either handleError handleResponse) (unwrap respond)
else sendError res 405 "Method not allowed" ("Expected " <> expected)
serveWith _ _ _ _ = Nothing

Expand Down Expand Up @@ -265,11 +265,11 @@ badRoute :: forall eff. Response -> Eff (http :: HTTP | eff) Unit
badRoute res = sendError res 400 "Bad Request" "No such route"

instance servableRecord :: (RowToList r l, ServableList eff l r) => Servable eff (Record r) where
serveWith r = serveListWith (rowToList r) r
serveWith r = serveListWith (RLProxy :: RLProxy l) r

class ServableList eff (l :: RowList) (r :: # Type) | l -> r where
serveListWith
:: LProxy l
:: RLProxy l
-> Record r
-> Request
-> Response
Expand All @@ -285,4 +285,4 @@ instance servableListCons
serveListWith _ rec req res (actual : xs)
| actual == reflectSymbol (SProxy :: SProxy route)
= serveWith (get (SProxy :: SProxy route) rec :: s) req res xs
serveListWith _ rec req res xs = serveListWith (LProxy :: LProxy l) (unsafeCoerce rec) req res xs
serveListWith _ rec req res xs = serveListWith (RLProxy :: RLProxy l) (unsafeCoerce rec) req res xs
31 changes: 0 additions & 31 deletions src/QuickServe/Internal.purs

This file was deleted.

0 comments on commit 92a520a

Please sign in to comment.