From a96a53a12933f72d7de2cf07068f70e145aab8a3 Mon Sep 17 00:00:00 2001 From: justinwoo Date: Wed, 9 May 2018 00:09:14 +0300 Subject: [PATCH 1/4] updates for 0.12 --- bower.json | 16 ++-- example/Gzip.purs | 5 +- src/Node/Stream.purs | 207 +++++++++++++++++++++---------------------- test/Main.purs | 8 +- 4 files changed, 115 insertions(+), 121 deletions(-) diff --git a/bower.json b/bower.json index a3a68f6..9b43456 100644 --- a/bower.json +++ b/bower.json @@ -12,15 +12,15 @@ "url": "git://github.com/purescript-node/purescript-node-streams.git" }, "devDependencies": { - "purescript-console": "^3.0.0", - "purescript-assert": "^3.0.0", - "purescript-partial": "^1.2.0" + "purescript-console": "#compiler/0.12", + "purescript-assert": "#compiler/0.12", + "purescript-partial": "#compiler/0.12" }, "dependencies": { - "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" + "purescript-effect": "#compiler/0.12", + "purescript-node-buffer": "justinwoo/purescript-node-buffer#compiler/0.12", + "purescript-prelude": "#compiler/0.12", + "purescript-either": "#compiler/0.12", + "purescript-exceptions": "#compiler/0.12" } } diff --git a/example/Gzip.purs b/example/Gzip.purs index edd8784..fbbc14e 100644 --- a/example/Gzip.purs +++ b/example/Gzip.purs @@ -4,10 +4,9 @@ import Prelude import Node.Stream -import Control.Monad.Eff -import Control.Monad.Eff.Console +import Effect +import Effect.Console -foreign import data GZIP :: Effect foreign import gzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff)) foreign import stdin :: forall eff. Readable () (console :: CONSOLE | eff) diff --git a/src/Node/Stream.purs b/src/Node/Stream.purs index 6c92fd8..2483a3b 100644 --- a/src/Node/Stream.purs +++ b/src/Node/Stream.purs @@ -36,9 +36,8 @@ module Node.Stream import Prelude -import Control.Monad.Eff (Eff, kind Effect) -import Control.Monad.Eff.Exception (throw, EXCEPTION(), Error()) -import Control.Monad.Eff.Unsafe (unsafeCoerceEff) +import Effect (Effect) +import Effect.Exception (throw, Error()) import Data.Either (Either(..)) import Data.Maybe (Maybe(..), fromMaybe) import Node.Buffer (Buffer()) @@ -51,7 +50,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 :: # Type -> # Effect -> Type +foreign import data Stream :: # Type -> Type -- | A phantom type associated with _readable streams_. data Read @@ -84,10 +83,10 @@ readChunk = readChunkImpl Left Right -- | Listen for `data` events, returning data in a Buffer. Note that this will fail -- | if `setEncoding` has been called on the stream. onData - :: forall w eff - . Readable w (exception :: EXCEPTION | eff) - -> (Buffer -> Eff (exception :: EXCEPTION | eff) Unit) - -> Eff (exception :: EXCEPTION | eff) Unit + :: forall w + . Readable w + -> (Buffer -> Effect Unit) + -> Effect Unit onData r cb = onDataEither r (cb <=< fromEither) where @@ -99,10 +98,10 @@ onData r cb = pure buf read - :: forall w eff - . Readable w (exception :: EXCEPTION | eff) + :: forall w + . Readable w -> Maybe Int - -> Eff (exception :: EXCEPTION | eff) (Maybe Buffer) + -> Effect (Maybe Buffer) read r size = do v <- readEither r size case v of @@ -111,67 +110,67 @@ read r size = do Just (Right b) -> pure (Just b) readString - :: forall w eff - . Readable w (exception :: EXCEPTION | eff) + :: forall w + . Readable w -> Maybe Int -> Encoding - -> Eff (exception :: EXCEPTION | eff) (Maybe String) + -> Effect (Maybe String) readString r size enc = do v <- readEither r size case v of Nothing -> pure Nothing Just (Left _) -> throw "Stream encoding should not be set" - Just (Right buf) -> Just <$> (unsafeCoerceEff $ Buffer.toString enc buf) + Just (Right buf) -> Just <$> Buffer.toString enc buf readEither - :: forall w eff - . Readable w eff + :: forall w + . Readable w -> Maybe Int - -> Eff eff (Maybe (Either String Buffer)) + -> Effect (Maybe (Either String Buffer)) readEither r size = readImpl readChunk Nothing Just r (fromMaybe undefined size) foreign import readImpl - :: forall r eff + :: forall r . (Chunk -> Either String Buffer) -> (forall a. Maybe a) -> (forall a. a -> Maybe a) - -> Readable r eff + -> Readable r -> Int - -> Eff eff (Maybe (Either String Buffer)) + -> Effect (Maybe (Either String Buffer)) -- | Listen for `data` events, returning data in a String, which will be -- | decoded using the given encoding. Note that this will fail if `setEncoding` -- | has been called on the stream. onDataString - :: forall w eff - . Readable w (exception :: EXCEPTION | eff) + :: forall w + . Readable w -> Encoding - -> (String -> Eff (exception :: EXCEPTION | eff) Unit) - -> Eff (exception :: EXCEPTION | eff) Unit -onDataString r enc cb = onData r (cb <=< unsafeCoerceEff <<< Buffer.toString enc) + -> (String -> Effect Unit) + -> Effect Unit +onDataString r enc cb = onData r (cb <=< Buffer.toString enc) -- | Listen for `data` events, returning data in an `Either String Buffer`. This -- | function is provided for the (hopefully rare) case that `setEncoding` has -- | been called on the stream. onDataEither - :: forall r eff - . Readable r (exception :: EXCEPTION | eff) - -> (Either String Buffer -> Eff (exception :: EXCEPTION | eff) Unit) - -> Eff (exception :: EXCEPTION | eff) Unit + :: forall r + . Readable r + -> (Either String Buffer -> Effect Unit) + -> Effect Unit onDataEither r cb = onDataEitherImpl readChunk r cb foreign import onDataEitherImpl - :: forall r eff + :: forall r . (Chunk -> Either String Buffer) - -> Readable r eff - -> (Either String Buffer -> Eff eff Unit) - -> Eff eff Unit + -> Readable r + -> (Either String Buffer -> Effect Unit) + -> Effect Unit foreign import setEncodingImpl - :: forall w eff - . Readable w eff + :: forall w + . Readable w -> String - -> Eff eff Unit + -> Effect Unit -- | Set the encoding used to read chunks as strings from the stream. This -- | function may be useful when you are passing a readable stream to some other @@ -180,113 +179,113 @@ foreign import setEncodingImpl -- | Where possible, you should try to use `onDataString` instead of this -- | function. setEncoding - :: forall w eff - . Readable w eff + :: forall w + . Readable w -> Encoding - -> Eff eff Unit + -> Effect Unit setEncoding r enc = setEncodingImpl r (show enc) -- | Listen for `readable` events. foreign import onReadable - :: forall w eff - . Readable w eff - -> Eff eff Unit - -> Eff eff Unit + :: forall w + . Readable w + -> Effect Unit + -> Effect Unit -- | Listen for `end` events. foreign import onEnd - :: forall w eff - . Readable w eff - -> Eff eff Unit - -> Eff eff Unit + :: forall w + . Readable w + -> Effect Unit + -> Effect Unit -- | Listen for `finish` events. foreign import onFinish - :: forall w eff - . Writable w eff - -> Eff eff Unit - -> Eff eff Unit + :: forall w + . Writable w + -> Effect Unit + -> Effect Unit -- | Listen for `close` events. foreign import onClose - :: forall w eff - . Stream w eff - -> Eff eff Unit - -> Eff eff Unit + :: forall w + . Stream w + -> Effect Unit + -> Effect Unit -- | Listen for `error` events. foreign import onError - :: forall w eff - . Stream w eff - -> (Error -> Eff eff Unit) - -> Eff eff Unit + :: forall w + . Stream w + -> (Error -> Effect Unit) + -> Effect Unit -- | Resume reading from the stream. -foreign import resume :: forall w eff. Readable w eff -> Eff eff Unit +foreign import resume :: forall w. Readable w -> Effect Unit -- | Pause reading from the stream. -foreign import pause :: forall w eff. Readable w eff -> Eff eff Unit +foreign import pause :: forall w. Readable w -> Effect Unit -- | Check whether or not a stream is paused for reading. -foreign import isPaused :: forall w eff. Readable w eff -> Eff eff Boolean +foreign import isPaused :: forall w. Readable w -> Effect Boolean -- | Read chunks from a readable stream and write them to a writable stream. foreign import pipe - :: forall r w eff - . Readable w eff - -> Writable r eff - -> Eff eff (Writable r eff) + :: forall r w + . Readable w + -> Writable r + -> Effect (Writable r) -- | Detach a Writable stream previously attached using `pipe`. foreign import unpipe - :: forall r w eff - . Readable w eff - -> Writable r eff - -> Eff eff Unit + :: forall r w + . Readable w + -> Writable r + -> Effect Unit -- | Detach all Writable streams previously attached using `pipe`. foreign import unpipeAll - :: forall w eff - . Readable w eff - -> Eff eff Unit + :: forall w + . Readable w + -> Effect Unit -- | Write a Buffer to a writable stream. foreign import write - :: forall r eff - . Writable r eff + :: forall r + . Writable r -> Buffer - -> Eff eff Unit - -> Eff eff Boolean + -> Effect Unit + -> Effect Boolean foreign import writeStringImpl - :: forall r eff - . Writable r eff + :: forall r + . Writable r -> String -> String - -> Eff eff Unit - -> Eff eff Boolean + -> Effect Unit + -> Effect Boolean -- | Write a string in the specified encoding to a writable stream. writeString - :: forall r eff - . Writable r eff + :: forall r + . Writable r -> Encoding -> String - -> Eff eff Unit - -> Eff eff Boolean + -> Effect Unit + -> Effect Boolean writeString w enc = writeStringImpl w (show enc) -- | Force buffering of writes. -foreign import cork :: forall r eff. Writable r eff -> Eff eff Unit +foreign import cork :: forall r. Writable r -> Effect Unit -- | Flush buffered data. -foreign import uncork :: forall r eff. Writable r eff -> Eff eff Unit +foreign import uncork :: forall r. Writable r -> Effect Unit foreign import setDefaultEncodingImpl - :: forall r eff - . Writable r eff + :: forall r + . Writable r -> String - -> Eff eff Unit + -> Effect Unit -- | Set the default encoding used to write strings to the stream. This function -- | is useful when you are passing a writable stream to some other JavaScript @@ -294,32 +293,32 @@ foreign import setDefaultEncodingImpl -- | effect on the behaviour of the `writeString` function (because that -- | function ensures that the encoding is always supplied explicitly). setDefaultEncoding - :: forall r eff - . Writable r eff + :: forall r + . Writable r -> Encoding - -> Eff eff Unit + -> Effect Unit setDefaultEncoding r enc = setDefaultEncodingImpl r (show enc) -- | End writing data to the stream. foreign import end - :: forall r eff - . Writable r eff - -> Eff eff Unit - -> Eff eff Unit + :: forall r + . Writable r + -> Effect Unit + -> Effect Unit -- | Destroy the stream. It will release any internal resources. -- -- Added in node 8.0. foreign import destroy - :: forall r eff - . Stream r eff - -> Eff eff Unit + :: forall r + . Stream r + -> Effect Unit -- | Destroy the stream and emit 'error'. -- -- Added in node 8.0. foreign import destroyWithError - :: forall r eff - . Stream r eff + :: forall r + . Stream r -> Error - -> Eff eff Unit + -> Effect Unit diff --git a/test/Main.purs b/test/Main.purs index dcb9f1d..2a3a6c5 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,9 +1,8 @@ module Test.Main where import Prelude -import Control.Monad.Eff (Eff, kind Effect) -import Control.Monad.Eff.Console (CONSOLE, log) -import Control.Monad.Eff.Exception (EXCEPTION) +import Effect (Effect) +import Effect.Console (log) import Node.Encoding (Encoding(..)) import Node.Stream (Duplex, Readable, Writable, onDataString, end, writeString, pipe, onDataEither, onData, setEncoding, setDefaultEncoding, read, onReadable, readString) import Test.Assert (ASSERT, assert, assert') @@ -16,7 +15,6 @@ assertEqual :: forall e a. Show a => Eq a => a -> a -> Eff (assert :: ASSERT | e assertEqual x y = assert' (show x <> " did not equal " <> show y) (x == y) -foreign import data STREAM_BUFFER :: Effect foreign import writableStreamBuffer :: forall eff. Eff (sb :: STREAM_BUFFER | eff) (Writable () (sb :: STREAM_BUFFER | eff)) @@ -166,12 +164,10 @@ testPipe = do onDataString sOut UTF8 \str -> do assertEqual str testString -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 :: 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)) From b369b8183752f8a51ad197755c90ad7d1985a094 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 14 May 2018 11:20:43 +0200 Subject: [PATCH 2/4] Update tests for 0.12 --- test/Main.purs | 69 ++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 50 deletions(-) diff --git a/test/Main.purs b/test/Main.purs index 2a3a6c5..75d219e 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,42 +1,34 @@ module Test.Main where import Prelude + +import Data.Either (Either(..)) +import Data.Maybe (Maybe(..), fromJust, isNothing, isJust) import Effect (Effect) import Effect.Console (log) +import Node.Buffer as Buffer import Node.Encoding (Encoding(..)) import Node.Stream (Duplex, Readable, Writable, onDataString, end, writeString, pipe, onDataEither, onData, setEncoding, setDefaultEncoding, read, onReadable, readString) -import Test.Assert (ASSERT, assert, assert') -import Node.Buffer as Buffer -import Data.Either (Either(..)) -import Data.Maybe (Maybe(..), fromJust, isNothing, isJust) import Partial.Unsafe (unsafePartial) +import Test.Assert (assert, assert') -assertEqual :: forall e a. Show a => Eq a => a -> a -> Eff (assert :: ASSERT | e) Unit +assertEqual :: forall a. Show a => Eq a => a -> a -> Effect Unit assertEqual x y = assert' (show x <> " did not equal " <> show y) (x == y) -foreign import writableStreamBuffer :: forall eff. Eff (sb :: STREAM_BUFFER | eff) (Writable () (sb :: STREAM_BUFFER | eff)) +foreign import writableStreamBuffer :: Effect (Writable ()) -foreign import getContentsAsString :: forall r eff. Writable r (sb :: STREAM_BUFFER | eff) -> Eff (sb :: STREAM_BUFFER | eff) String +foreign import getContentsAsString :: forall r. Writable r -> Effect String -foreign import readableStreamBuffer :: forall eff. Eff (sb :: STREAM_BUFFER | eff) (Readable () (sb :: STREAM_BUFFER | eff)) +foreign import readableStreamBuffer :: Effect (Readable ()) -foreign import putImpl :: forall r eff. String -> String -> Readable r (sb :: STREAM_BUFFER | eff) -> Eff (sb :: STREAM_BUFFER | eff) Unit +foreign import putImpl :: forall r. String -> String -> Readable r -> Effect Unit -put :: forall r eff. String -> Encoding -> Readable r (sb :: STREAM_BUFFER | eff) -> Eff (sb :: STREAM_BUFFER | eff) Unit +put :: forall r. String -> Encoding -> Readable r -> Effect Unit put str enc = putImpl str (show enc) -main - :: forall eff - . Eff ( console :: CONSOLE - , sb :: STREAM_BUFFER - , assert :: ASSERT - , exception :: EXCEPTION - , buffer :: Buffer.BUFFER - , stream :: PASS_THROUGH - , gzip :: GZIP - | eff ) Boolean +main :: Effect Boolean main = do log "setDefaultEncoding should not affect writing" _ <- testSetDefaultEncoding @@ -53,13 +45,7 @@ main = do testString :: String testString = "üöß💡" -testReads - :: forall eff - . Eff ( stream :: PASS_THROUGH - , exception :: EXCEPTION - , buffer :: Buffer.BUFFER - , assert :: ASSERT - | eff ) Boolean +testReads :: Effect Boolean testReads = do _ <- testReadString testReadBuf @@ -94,11 +80,7 @@ testReads = do writeString sIn UTF8 testString do pure unit -testSetDefaultEncoding - :: forall eff - . Eff ( sb :: STREAM_BUFFER - , assert :: ASSERT - | eff ) Boolean +testSetDefaultEncoding :: Effect Boolean testSetDefaultEncoding = do w1 <- writableStreamBuffer _ <- check w1 @@ -113,13 +95,7 @@ testSetDefaultEncoding = do c <- getContentsAsString w assertEqual testString c -testSetEncoding - :: forall eff - . Eff ( sb :: STREAM_BUFFER - , exception :: EXCEPTION - , buffer :: Buffer.BUFFER - , assert :: ASSERT - | eff ) Unit +testSetEncoding :: Effect Unit testSetEncoding = do check UTF8 check UTF16LE @@ -138,14 +114,7 @@ testSetEncoding = do _ <- assertEqual <$> Buffer.toString enc buf <*> pure testString assertEqual str testString -testPipe - :: forall eff - . Eff ( stream :: PASS_THROUGH - , gzip :: GZIP - , exception :: EXCEPTION - , assert :: ASSERT - , console :: CONSOLE - | eff ) Boolean +testPipe :: Effect Boolean testPipe = do sIn <- passThrough sOut <- passThrough @@ -165,9 +134,9 @@ testPipe = do assertEqual str testString -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 createGzip :: Effect Duplex +foreign import createGunzip :: Effect Duplex -- | 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)) +foreign import passThrough :: Effect Duplex From 6d19b1bec7affc8014e2b1397b2c801983129421 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 14 May 2018 12:27:11 +0200 Subject: [PATCH 3/4] update bower.json, update example --- bower.json | 2 +- example/Gzip.purs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bower.json b/bower.json index 9b43456..f18832c 100644 --- a/bower.json +++ b/bower.json @@ -18,7 +18,7 @@ }, "dependencies": { "purescript-effect": "#compiler/0.12", - "purescript-node-buffer": "justinwoo/purescript-node-buffer#compiler/0.12", + "purescript-node-buffer": "#compiler/0.12", "purescript-prelude": "#compiler/0.12", "purescript-either": "#compiler/0.12", "purescript-exceptions": "#compiler/0.12" diff --git a/example/Gzip.purs b/example/Gzip.purs index fbbc14e..e4e52f6 100644 --- a/example/Gzip.purs +++ b/example/Gzip.purs @@ -2,16 +2,15 @@ module Gzip where import Prelude -import Node.Stream +import Effect (Effect) +import Node.Stream (Duplex, Readable, Writable, pipe) -import Effect -import Effect.Console +foreign import gzip :: Effect Duplex +foreign import stdin :: Readable () +foreign import stdout :: Writable () -foreign import gzip :: forall eff. Eff (gzip :: GZIP | eff) (Duplex (gzip :: GZIP | eff)) -foreign import stdin :: forall eff. Readable () (console :: CONSOLE | eff) -foreign import stdout :: forall eff. Writable () (console :: CONSOLE | eff) - +main :: Effect (Writable ()) main = do z <- gzip _ <- stdin `pipe` z From 7de2d2e6e639bb9b8c930a1a876810f112991ae9 Mon Sep 17 00:00:00 2001 From: justinwoo Date: Sun, 27 May 2018 03:12:36 +0300 Subject: [PATCH 4/4] update packages --- bower.json | 16 ++++++++-------- package.json | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bower.json b/bower.json index f18832c..b6ffa51 100644 --- a/bower.json +++ b/bower.json @@ -12,15 +12,15 @@ "url": "git://github.com/purescript-node/purescript-node-streams.git" }, "devDependencies": { - "purescript-console": "#compiler/0.12", - "purescript-assert": "#compiler/0.12", - "purescript-partial": "#compiler/0.12" + "purescript-console": "^4.1.0", + "purescript-assert": "^4.0.0", + "purescript-partial": "^2.0.0" }, "dependencies": { - "purescript-effect": "#compiler/0.12", - "purescript-node-buffer": "#compiler/0.12", - "purescript-prelude": "#compiler/0.12", - "purescript-either": "#compiler/0.12", - "purescript-exceptions": "#compiler/0.12" + "purescript-effect": "^2.0.0", + "purescript-node-buffer": "^5.0.0", + "purescript-prelude": "^4.0.0", + "purescript-either": "^4.0.0", + "purescript-exceptions": "^4.0.0" } } diff --git a/package.json b/package.json index d6f87cb..9d9e694 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,10 @@ }, "devDependencies": { "jscs": "^3.0.7", - "jshint": "^2.9.4", - "pulp": "^11.0.0", - "purescript-psa": "^0.5.0", - "rimraf": "^2.6.1", - "stream-buffers": "^3.0.1" + "jshint": "^2.9.5", + "pulp": "^12.2.0", + "purescript-psa": "^0.6.0", + "rimraf": "^2.6.2", + "stream-buffers": "^3.0.2" } }