diff --git a/bower.json b/bower.json index 627ce08..a3a68f6 100644 --- a/bower.json +++ b/bower.json @@ -12,15 +12,15 @@ "url": "git://github.com/purescript-node/purescript-node-streams.git" }, "devDependencies": { - "purescript-console": "^2.0.0", - "purescript-assert": "^2.0.0", - "purescript-partial": "^1.1.2" + "purescript-console": "^3.0.0", + "purescript-assert": "^3.0.0", + "purescript-partial": "^1.2.0" }, "dependencies": { - "purescript-eff": "^2.0.0", - "purescript-node-buffer": "^2.0.0", - "purescript-prelude": "^2.1.0", - "purescript-either": "^2.0.0", - "purescript-exceptions": "^2.0.0" + "purescript-eff": "^3.0.0", + "purescript-node-buffer": "^3.0.0", + "purescript-prelude": "^3.0.0", + "purescript-either": "^3.0.0", + "purescript-exceptions": "^3.0.0" } } diff --git a/package.json b/package.json index 6f75a70..d6f87cb 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,15 @@ "private": true, "scripts": { "clean": "rimraf output && rimraf .pulp-cache", - "build": "jshint src && jscs src && pulp build --censor-lib --strict", + "build": "jshint src && jscs src && pulp build -- --censor-lib --strict", "test": "pulp test" }, "devDependencies": { "jscs": "^3.0.7", - "jshint": "^2.9.3", - "pulp": "^9.0.1", - "purescript-psa": "^0.3.9", - "rimraf": "^2.5.4", + "jshint": "^2.9.4", + "pulp": "^11.0.0", + "purescript-psa": "^0.5.0", + "rimraf": "^2.6.1", "stream-buffers": "^3.0.1" } } diff --git a/src/Node/Stream.purs b/src/Node/Stream.purs index 9981085..37a9779 100644 --- a/src/Node/Stream.purs +++ b/src/Node/Stream.purs @@ -32,7 +32,7 @@ module Node.Stream import Prelude -import Control.Monad.Eff (Eff) +import Control.Monad.Eff (Eff, kind Effect) import Control.Monad.Eff.Exception (throw, EXCEPTION(), Error()) import Control.Monad.Eff.Unsafe (unsafeCoerceEff) import Data.Either (Either(..)) @@ -47,7 +47,7 @@ import Node.Encoding (Encoding) -- | -- | - Whether reading and/or writing from/to the stream are allowed. -- | - Effects associated with reading/writing from/to this stream. -foreign import data Stream :: # * -> # ! -> * +foreign import data Stream :: # Type -> # Effect -> Type -- | A phantom type associated with _readable streams_. data Read @@ -66,7 +66,7 @@ type Duplex = Stream (read :: Read, write :: Write) foreign import undefined :: forall a. a -foreign import data Chunk :: * +foreign import data Chunk :: Type foreign import readChunkImpl :: (forall l r. l -> Either l r) @@ -81,9 +81,9 @@ readChunk = readChunkImpl Left Right -- | if `setEncoding` has been called on the stream. onData :: forall w eff - . Readable w (err :: EXCEPTION | eff) - -> (Buffer -> Eff (err :: EXCEPTION | eff) Unit) - -> Eff (err :: EXCEPTION | eff) Unit + . Readable w (exception :: EXCEPTION | eff) + -> (Buffer -> Eff (exception :: EXCEPTION | eff) Unit) + -> Eff (exception :: EXCEPTION | eff) Unit onData r cb = onDataEither r (cb <=< fromEither) where @@ -96,9 +96,9 @@ onData r cb = read :: forall w eff - . Readable w (err :: EXCEPTION | eff) + . Readable w (exception :: EXCEPTION | eff) -> Maybe Int - -> Eff (err :: EXCEPTION | eff) (Maybe Buffer) + -> Eff (exception :: EXCEPTION | eff) (Maybe Buffer) read r size = do v <- readEither r size case v of @@ -108,10 +108,10 @@ read r size = do readString :: forall w eff - . Readable w (err :: EXCEPTION | eff) + . Readable w (exception :: EXCEPTION | eff) -> Maybe Int -> Encoding - -> Eff (err :: EXCEPTION | eff) (Maybe String) + -> Eff (exception :: EXCEPTION | eff) (Maybe String) readString r size enc = do v <- readEither r size case v of @@ -140,10 +140,10 @@ foreign import readImpl -- | has been called on the stream. onDataString :: forall w eff - . Readable w (err :: EXCEPTION | eff) + . Readable w (exception :: EXCEPTION | eff) -> Encoding - -> (String -> Eff (err :: EXCEPTION | eff) Unit) - -> Eff (err :: EXCEPTION | eff) Unit + -> (String -> Eff (exception :: EXCEPTION | eff) Unit) + -> Eff (exception :: EXCEPTION | eff) Unit onDataString r enc cb = onData r (cb <=< unsafeCoerceEff <<< Buffer.toString enc) -- | Listen for `data` events, returning data in an `Either String Buffer`. This @@ -151,9 +151,9 @@ onDataString r enc cb = onData r (cb <=< unsafeCoerceEff <<< Buffer.toString enc -- | been called on the stream. onDataEither :: forall r eff - . Readable r (err :: EXCEPTION | eff) - -> (Either String Buffer -> Eff (err :: EXCEPTION | eff) Unit) - -> Eff (err :: EXCEPTION | eff) Unit + . Readable r (exception :: EXCEPTION | eff) + -> (Either String Buffer -> Eff (exception :: EXCEPTION | eff) Unit) + -> Eff (exception :: EXCEPTION | eff) Unit onDataEither r cb = onDataEitherImpl readChunk r cb foreign import onDataEitherImpl diff --git a/test/Main.purs b/test/Main.purs index 7050a34..dcb9f1d 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,7 +1,7 @@ module Test.Main where import Prelude -import Control.Monad.Eff (Eff) +import Control.Monad.Eff (Eff, kind Effect) import Control.Monad.Eff.Console (CONSOLE, log) import Control.Monad.Eff.Exception (EXCEPTION) import Node.Encoding (Encoding(..)) @@ -12,11 +12,11 @@ import Data.Either (Either(..)) import Data.Maybe (Maybe(..), fromJust, isNothing, isJust) import Partial.Unsafe (unsafePartial) -assertEqual :: forall e a. (Show a, Eq a) => a -> a -> Eff (assert :: ASSERT | e) Unit +assertEqual :: forall e a. Show a => Eq a => a -> a -> Eff (assert :: ASSERT | e) Unit assertEqual x y = assert' (show x <> " did not equal " <> show y) (x == y) -foreign import data STREAM_BUFFER :: ! +foreign import data STREAM_BUFFER :: Effect foreign import writableStreamBuffer :: forall eff. Eff (sb :: STREAM_BUFFER | eff) (Writable () (sb :: STREAM_BUFFER | eff)) @@ -34,20 +34,20 @@ main . Eff ( console :: CONSOLE , sb :: STREAM_BUFFER , assert :: ASSERT - , err :: EXCEPTION + , exception :: EXCEPTION , buffer :: Buffer.BUFFER , stream :: PASS_THROUGH , gzip :: GZIP | eff ) Boolean main = do log "setDefaultEncoding should not affect writing" - testSetDefaultEncoding + _ <- testSetDefaultEncoding log "setEncoding should not affect reading" testSetEncoding log "test pipe" - testPipe + _ <- testPipe log "test manual reads" testReads @@ -58,12 +58,12 @@ testString = "üöß💡" testReads :: forall eff . Eff ( stream :: PASS_THROUGH - , err :: EXCEPTION + , exception :: EXCEPTION , buffer :: Buffer.BUFFER , assert :: ASSERT | eff ) Boolean testReads = do - testReadString + _ <- testReadString testReadBuf where @@ -89,7 +89,7 @@ testReads = do onReadable sIn do buf <- read sIn Nothing assert (isJust buf) - assertEqual <$> (Buffer.toString UTF8 (unsafePartial (fromJust buf))) + _ <- assertEqual <$> (Buffer.toString UTF8 (unsafePartial (fromJust buf))) <*> pure testString pure unit @@ -103,7 +103,7 @@ testSetDefaultEncoding | eff ) Boolean testSetDefaultEncoding = do w1 <- writableStreamBuffer - check w1 + _ <- check w1 w2 <- writableStreamBuffer setDefaultEncoding w2 UCS2 @@ -118,7 +118,7 @@ testSetDefaultEncoding = do testSetEncoding :: forall eff . Eff ( sb :: STREAM_BUFFER - , err :: EXCEPTION + , exception :: EXCEPTION , buffer :: Buffer.BUFFER , assert :: ASSERT | eff ) Unit @@ -137,14 +137,14 @@ testSetEncoding = do onData r1 \buf -> unsafePartial do onDataEither r2 \(Left str) -> do - assertEqual <$> Buffer.toString enc buf <*> pure testString + _ <- assertEqual <$> Buffer.toString enc buf <*> pure testString assertEqual str testString testPipe :: forall eff . Eff ( stream :: PASS_THROUGH , gzip :: GZIP - , err :: EXCEPTION + , exception :: EXCEPTION , assert :: ASSERT , console :: CONSOLE | eff ) Boolean @@ -155,23 +155,23 @@ testPipe = do unzip <- createGunzip log "pipe 1" - sIn `pipe` zip + _ <- sIn `pipe` zip log "pipe 2" - zip `pipe` unzip + _ <- zip `pipe` unzip log "pipe 3" - unzip `pipe` sOut + _ <- unzip `pipe` sOut writeString sIn UTF8 testString do end sIn do onDataString sOut UTF8 \str -> do assertEqual str testString -foreign import data GZIP :: ! +foreign import data GZIP :: Effect foreign import createGzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff)) foreign import createGunzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff)) -foreign import data PASS_THROUGH :: ! +foreign import data PASS_THROUGH :: Effect -- | Create a PassThrough stream, which simply writes its input to its output. foreign import passThrough :: forall eff. Eff (stream :: PASS_THROUGH | eff) (Duplex (stream :: PASS_THROUGH | eff))