diff --git a/bower.json b/bower.json index 26399f6..e81a754 100644 --- a/bower.json +++ b/bower.json @@ -20,18 +20,26 @@ "package.json" ], "dependencies": { - "purescript-datetime": "^3.0.0", - "purescript-foreign": "^4.0.0", - "purescript-node-buffer": "^3.0.0", - "purescript-node-path": "^2.0.0", - "purescript-unsafe-coerce": "^3.0.0", - "purescript-nullable": "^3.0.0", - "purescript-node-streams": "^3.0.0", - "purescript-exceptions": "^3.0.0", - "purescript-js-date": ">= 4.0.0 < 6.0.0", - "purescript-globals": "^3.0.0" + "purescript-datetime": "^4.0.0", + "purescript-effect": "^2.0.0", + "purescript-either": "^4.0.0", + "purescript-enums": "^4.0.0", + "purescript-exceptions": "^4.0.0", + "purescript-functions": "^4.0.0", + "purescript-globals": "^4.0.0", + "purescript-integers": "^4.0.0", + "purescript-js-date": "^6.0.0", + "purescript-maybe": "^4.0.0", + "purescript-node-buffer": "^5.0.0", + "purescript-node-path": "^3.0.0", + "purescript-node-streams": "^4.0.0", + "purescript-nullable": "^4.0.0", + "purescript-partial": "^2.0.0", + "purescript-prelude": "^4.0.0", + "purescript-strings": "^4.0.0", + "purescript-unsafe-coerce": "^4.0.0" }, "devDependencies": { - "purescript-console": "^3.0.0" + "purescript-console": "^4.1.0" } } diff --git a/package.json b/package.json index ae769e4..2e21753 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,9 @@ }, "devDependencies": { "jscs": "^3.0.7", - "jshint": "^2.9.4", - "pulp": "^11.0.0", - "purescript-psa": "^0.5.0", - "rimraf": "^2.6.1" + "jshint": "^2.9.5", + "pulp": "^12.2.0", + "purescript-psa": "^0.6.0", + "rimraf": "^2.6.2" } } diff --git a/src/Node/FS.purs b/src/Node/FS.purs index 844dfd9..22f1b26 100644 --- a/src/Node/FS.purs +++ b/src/Node/FS.purs @@ -1,6 +1,5 @@ module Node.FS - ( FS() - , FileDescriptor(..) + ( FileDescriptor(..) , FileFlags(..) , FileMode(..) , SymlinkType(..) @@ -13,10 +12,6 @@ module Node.FS ) where import Prelude -import Control.Monad.Eff (kind Effect) - --- | Effect type for file system usage. -foreign import data FS :: Effect foreign import data FileDescriptor :: Type diff --git a/src/Node/FS/Async.purs b/src/Node/FS/Async.purs index 9fe82ac..3ebc669 100644 --- a/src/Node/FS/Async.purs +++ b/src/Node/FS/Async.purs @@ -32,37 +32,35 @@ module Node.FS.Async ) where import Prelude -import Control.Monad.Eff (Eff, runPure) -import Control.Monad.Eff.Unsafe (unsafeCoerceEff) -import Control.Monad.Eff.Exception (Error) + import Data.DateTime (DateTime) -import Data.Time.Duration (Milliseconds(..)) import Data.DateTime.Instant (fromDateTime, unInstant) import Data.Either (Either(..)) -import Data.Function.Uncurried (Fn2, Fn6, Fn4, Fn3, - runFn2, runFn6, runFn4, runFn3) +import Data.Function.Uncurried (Fn2, Fn6, Fn4, Fn3, runFn2, runFn6, runFn4, runFn3) +import Data.Int (round) import Data.Maybe (Maybe(..)) import Data.Nullable (Nullable, toNullable) -import Node.Buffer (Buffer(), BUFFER(), size) -import Data.Int (round) +import Data.Time.Duration (Milliseconds(..)) +import Effect (Effect) +import Effect.Exception (Error) +import Effect.Unsafe (unsafePerformEffect) +import Node.Buffer (Buffer, size) import Node.Encoding (Encoding) -import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength, - BufferOffset, FileMode, FileFlags, SymlinkType, - fileFlagsToNode, symlinkTypeToNode) -import Node.FS.Stats (StatsObj, Stats(..)) -import Node.Path (FilePath()) +import Node.FS (FileDescriptor, ByteCount, FilePosition, BufferLength, BufferOffset, FileMode, FileFlags, SymlinkType, fileFlagsToNode, symlinkTypeToNode) +import Node.FS.Internal (mkEffect, unsafeRequireFS) import Node.FS.Perms (Perms, permsToString, all, mkPerms) -import Node.FS.Internal (mkEff, unsafeRequireFS) +import Node.FS.Stats (StatsObj, Stats(..)) +import Node.Path (FilePath) type JSCallback a = Fn2 (Nullable Error) a Unit foreign import handleCallbackImpl :: - forall eff a. Fn3 (Error -> Either Error a) - (a -> Either Error a) - (Callback eff a) - (JSCallback a) + forall a. Fn3 (Error -> Either Error a) + (a -> Either Error a) + (Callback a) + (JSCallback a) -handleCallback :: forall eff a. (Callback eff a) -> JSCallback a +handleCallback :: forall a. (Callback a) -> JSCallback a handleCallback cb = runFn3 handleCallbackImpl Left Right cb fs :: @@ -92,145 +90,145 @@ fs :: fs = unsafeRequireFS -- | Type synonym for callback functions. -type Callback eff a = Either Error a -> Eff (fs :: FS | eff) Unit +type Callback a = Either Error a -> Effect Unit -- | Renames a file. -rename :: forall eff. FilePath - -> FilePath - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit -rename oldFile newFile cb = mkEff $ \_ -> runFn3 +rename :: FilePath + -> FilePath + -> Callback Unit + -> Effect Unit +rename oldFile newFile cb = mkEffect $ \_ -> runFn3 fs.rename oldFile newFile (handleCallback cb) -- | Truncates a file to the specified length. -truncate :: forall eff. FilePath - -> Int - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +truncate :: FilePath + -> Int + -> Callback Unit + -> Effect Unit -truncate file len cb = mkEff $ \_ -> runFn3 +truncate file len cb = mkEffect $ \_ -> runFn3 fs.truncate file len (handleCallback cb) -- | Changes the ownership of a file. -chown :: forall eff. FilePath - -> Int - -> Int - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +chown :: FilePath + -> Int + -> Int + -> Callback Unit + -> Effect Unit -chown file uid gid cb = mkEff $ \_ -> runFn4 +chown file uid gid cb = mkEffect $ \_ -> runFn4 fs.chown file uid gid (handleCallback cb) -- | Changes the permissions of a file. -chmod :: forall eff. FilePath - -> Perms - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +chmod :: FilePath + -> Perms + -> Callback Unit + -> Effect Unit -chmod file perms cb = mkEff $ \_ -> runFn3 +chmod file perms cb = mkEffect $ \_ -> runFn3 fs.chmod file (permsToString perms) (handleCallback cb) -- | Gets file statistics. -stat :: forall eff. FilePath - -> Callback eff Stats - -> Eff (fs :: FS | eff) Unit +stat :: FilePath + -> Callback Stats + -> Effect Unit -stat file cb = mkEff $ \_ -> runFn2 +stat file cb = mkEffect $ \_ -> runFn2 fs.stat file (handleCallback $ cb <<< (<$>) Stats) -- | Creates a link to an existing file. -link :: forall eff. FilePath - -> FilePath - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +link :: FilePath + -> FilePath + -> Callback Unit + -> Effect Unit -link src dst cb = mkEff $ \_ -> runFn3 +link src dst cb = mkEffect $ \_ -> runFn3 fs.link src dst (handleCallback cb) -- | Creates a symlink. -symlink :: forall eff. FilePath - -> FilePath - -> SymlinkType - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +symlink :: FilePath + -> FilePath + -> SymlinkType + -> Callback Unit + -> Effect Unit -symlink src dest ty cb = mkEff $ \_ -> runFn4 +symlink src dest ty cb = mkEffect $ \_ -> runFn4 fs.symlink src dest (symlinkTypeToNode ty) (handleCallback cb) -- | Reads the value of a symlink. -readlink :: forall eff. FilePath - -> Callback eff FilePath - -> Eff (fs :: FS | eff) Unit +readlink :: FilePath + -> Callback FilePath + -> Effect Unit -readlink path cb = mkEff $ \_ -> runFn2 +readlink path cb = mkEffect $ \_ -> runFn2 fs.readlink path (handleCallback cb) -- | Find the canonicalized absolute location for a path. -realpath :: forall eff. FilePath - -> Callback eff FilePath - -> Eff (fs :: FS | eff) Unit +realpath :: FilePath + -> Callback FilePath + -> Effect Unit -realpath path cb = mkEff $ \_ -> runFn3 +realpath path cb = mkEffect $ \_ -> runFn3 fs.realpath path {} (handleCallback cb) -- | Find the canonicalized absolute location for a path using a cache object -- | for already resolved paths. -realpath' :: forall eff cache. FilePath - -> { | cache } - -> Callback eff FilePath - -> Eff (fs :: FS | eff) Unit +realpath' :: forall cache. FilePath + -> { | cache } + -> Callback FilePath + -> Effect Unit -realpath' path cache cb = mkEff $ \_ -> runFn3 +realpath' path cache cb = mkEffect $ \_ -> runFn3 fs.realpath path cache (handleCallback cb) -- | Deletes a file. -unlink :: forall eff. FilePath - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +unlink :: FilePath + -> Callback Unit + -> Effect Unit -unlink file cb = mkEff $ \_ -> runFn2 +unlink file cb = mkEffect $ \_ -> runFn2 fs.unlink file (handleCallback cb) -- | Deletes a directory. -rmdir :: forall eff. FilePath - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +rmdir :: FilePath + -> Callback Unit + -> Effect Unit -rmdir file cb = mkEff $ \_ -> runFn2 +rmdir file cb = mkEffect $ \_ -> runFn2 fs.rmdir file (handleCallback cb) -- | Makes a new directory. -mkdir :: forall eff. FilePath - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +mkdir :: FilePath + -> Callback Unit + -> Effect Unit mkdir = flip mkdir' $ mkPerms all all all -- | Makes a new directory with the specified permissions. -mkdir' :: forall eff. FilePath - -> Perms - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +mkdir' :: FilePath + -> Perms + -> Callback Unit + -> Effect Unit -mkdir' file perms cb = mkEff $ \_ -> runFn3 +mkdir' file perms cb = mkEffect $ \_ -> runFn3 fs.mkdir file (permsToString perms) (handleCallback cb) -- | Reads the contents of a directory. -readdir :: forall eff. FilePath - -> Callback eff (Array FilePath) - -> Eff (fs :: FS | eff) Unit +readdir :: FilePath + -> Callback (Array FilePath) + -> Effect Unit -readdir file cb = mkEff $ \_ -> runFn2 +readdir file cb = mkEffect $ \_ -> runFn2 fs.readdir file (handleCallback cb) -- | Sets the accessed and modified times for the specified file. -utimes :: forall eff. FilePath - -> DateTime - -> DateTime - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +utimes :: FilePath + -> DateTime + -> DateTime + -> Callback Unit + -> Effect Unit -utimes file atime mtime cb = mkEff $ \_ -> runFn4 +utimes file atime mtime cb = mkEffect $ \_ -> runFn4 fs.utimes file (fromDate atime) (fromDate mtime) @@ -241,127 +239,121 @@ utimes file atime mtime cb = mkEff $ \_ -> runFn4 toEpochMilliseconds = unInstant <<< fromDateTime -- | Reads the entire contents of a file returning the result as a raw buffer. -readFile :: forall eff. FilePath - -> Callback (buffer :: BUFFER | eff) Buffer - -> Eff (buffer :: BUFFER, fs :: FS | eff) Unit +readFile :: FilePath + -> Callback Buffer + -> Effect Unit -readFile file cb = mkEff $ \_ -> runFn3 +readFile file cb = mkEffect $ \_ -> runFn3 fs.readFile file {} (handleCallback cb) -- | Reads the entire contents of a text file with the specified encoding. -readTextFile :: forall eff. Encoding - -> FilePath - -> Callback eff String - -> Eff (fs :: FS | eff) Unit +readTextFile :: Encoding + -> FilePath + -> Callback String + -> Effect Unit -readTextFile encoding file cb = mkEff $ \_ -> runFn3 +readTextFile encoding file cb = mkEffect $ \_ -> runFn3 fs.readFile file { encoding: show encoding } (handleCallback cb) -- | Writes a buffer to a file. -writeFile :: forall eff. FilePath - -> Buffer - -> Callback (buffer :: BUFFER | eff) Unit - -> Eff (buffer :: BUFFER, fs :: FS | eff) Unit +writeFile :: FilePath + -> Buffer + -> Callback Unit + -> Effect Unit -writeFile file buff cb = mkEff $ \_ -> runFn4 +writeFile file buff cb = mkEffect $ \_ -> runFn4 fs.writeFile file buff {} (handleCallback cb) -- | Writes text to a file using the specified encoding. -writeTextFile :: forall eff. Encoding - -> FilePath - -> String - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +writeTextFile :: Encoding + -> FilePath + -> String + -> Callback Unit + -> Effect Unit -writeTextFile encoding file buff cb = mkEff $ \_ -> runFn4 +writeTextFile encoding file buff cb = mkEffect $ \_ -> runFn4 fs.writeFile file buff { encoding: show encoding } (handleCallback cb) -- | Appends the contents of a buffer to a file. -appendFile :: forall eff. FilePath - -> Buffer - -> Callback (buffer :: BUFFER | eff) Unit - -> Eff (buffer :: BUFFER, fs :: FS | eff) Unit +appendFile :: FilePath + -> Buffer + -> Callback Unit + -> Effect Unit -appendFile file buff cb = mkEff $ \_ -> runFn4 +appendFile file buff cb = mkEffect $ \_ -> runFn4 fs.appendFile file buff {} (handleCallback cb) -- | Appends text to a file using the specified encoding. -appendTextFile :: forall eff. Encoding - -> FilePath - -> String - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit +appendTextFile :: Encoding + -> FilePath + -> String + -> Callback Unit + -> Effect Unit -appendTextFile encoding file buff cb = mkEff $ \_ -> runFn4 +appendTextFile encoding file buff cb = mkEffect $ \_ -> runFn4 fs.appendFile file buff { encoding: show encoding } (handleCallback cb) -- | Check if the path exists. -exists :: forall eff. FilePath - -> (Boolean -> Eff (fs :: FS | eff) Unit) - -> Eff (fs :: FS | eff) Unit -exists file cb = mkEff $ \_ -> runFn2 - fs.exists file $ \b -> runPure (unsafeCoerceEff (cb b)) +exists :: FilePath + -> (Boolean -> Effect Unit) + -> Effect Unit +exists file cb = mkEffect $ \_ -> runFn2 + fs.exists file $ \b -> unsafePerformEffect (cb b) -- | Open a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback) -- | for details. -fdOpen :: forall eff. - FilePath +fdOpen :: FilePath -> FileFlags -> Maybe FileMode - -> Callback eff FileDescriptor - -> Eff (fs :: FS | eff) Unit -fdOpen file flags mode cb = mkEff $ \_ -> runFn4 fs.open file (fileFlagsToNode flags) (toNullable mode) (handleCallback cb) + -> Callback FileDescriptor + -> Effect Unit +fdOpen file flags mode cb = mkEffect $ \_ -> runFn4 fs.open file (fileFlagsToNode flags) (toNullable mode) (handleCallback cb) -- | Read from a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) -- | for details. -fdRead :: forall eff. - FileDescriptor +fdRead :: FileDescriptor -> Buffer -> BufferOffset -> BufferLength -> Maybe FilePosition - -> Callback (buffer :: BUFFER | eff) ByteCount - -> Eff (buffer :: BUFFER, fs :: FS | eff) Unit -fdRead fd buff off len pos cb = mkEff $ \_ -> runFn6 fs.read fd buff off len (toNullable pos) (handleCallback cb) + -> Callback ByteCount + -> Effect Unit +fdRead fd buff off len pos cb = mkEffect $ \_ -> runFn6 fs.read fd buff off len (toNullable pos) (handleCallback cb) -- | Convenience function to fill the whole buffer from the current -- | file position. -fdNext :: forall eff. - FileDescriptor +fdNext :: FileDescriptor -> Buffer - -> Callback (buffer :: BUFFER | eff) ByteCount - -> Eff (buffer :: BUFFER, fs :: FS | eff) Unit + -> Callback ByteCount + -> Effect Unit fdNext fd buff cb = do sz <- size buff fdRead fd buff 0 sz Nothing cb -- | Write to a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback) -- | for details. -fdWrite :: forall eff. - FileDescriptor +fdWrite :: FileDescriptor -> Buffer -> BufferOffset -> BufferLength -> Maybe FilePosition - -> Callback (buffer :: BUFFER | eff) ByteCount - -> Eff (buffer :: BUFFER, fs :: FS | eff) Unit -fdWrite fd buff off len pos cb = mkEff $ \_ -> runFn6 fs.write fd buff off len (toNullable pos) (handleCallback cb) + -> Callback ByteCount + -> Effect Unit +fdWrite fd buff off len pos cb = mkEffect $ \_ -> runFn6 fs.write fd buff off len (toNullable pos) (handleCallback cb) -- | Convenience function to append the whole buffer to the current -- | file position. -fdAppend :: forall eff. - FileDescriptor +fdAppend :: FileDescriptor -> Buffer - -> Callback (buffer :: BUFFER | eff) ByteCount - -> Eff (buffer :: BUFFER, fs :: FS | eff) Unit + -> Callback ByteCount + -> Effect Unit fdAppend fd buff cb = do sz <- size buff fdWrite fd buff 0 sz Nothing cb -- | Close a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_close_fd_callback) -- | for details. -fdClose :: forall eff. - FileDescriptor - -> Callback eff Unit - -> Eff (fs :: FS | eff) Unit -fdClose fd cb = mkEff $ \_ -> runFn2 fs.close fd (handleCallback cb) +fdClose :: FileDescriptor + -> Callback Unit + -> Effect Unit +fdClose fd cb = mkEffect $ \_ -> runFn2 fs.close fd (handleCallback cb) diff --git a/src/Node/FS/Internal.purs b/src/Node/FS/Internal.purs index 962c45b..4277aa8 100644 --- a/src/Node/FS/Internal.purs +++ b/src/Node/FS/Internal.purs @@ -2,10 +2,11 @@ module Node.FS.Internal where import Prelude -import Control.Monad.Eff (Eff) + +import Effect (Effect) import Unsafe.Coerce (unsafeCoerce) -mkEff :: forall e a. (Unit -> a) -> Eff e a -mkEff = unsafeCoerce +mkEffect :: forall a. (Unit -> a) -> Effect a +mkEffect = unsafeCoerce foreign import unsafeRequireFS :: forall props. { | props } diff --git a/src/Node/FS/Perms.purs b/src/Node/FS/Perms.purs index c0b67a3..12368b1 100644 --- a/src/Node/FS/Perms.purs +++ b/src/Node/FS/Perms.purs @@ -13,10 +13,12 @@ module Node.FS.Perms ) where import Prelude -import Data.Char (fromCharCode) + +import Data.Enum (toEnum) import Data.Int (fromNumber) import Data.Maybe (Maybe(..), isNothing, fromJust) -import Data.String (Pattern(Pattern), toCharArray, joinWith, drop, charAt, indexOf) +import Data.String (Pattern(Pattern), joinWith, drop, indexOf) +import Data.String.CodeUnits (charAt, toCharArray) import Global (readInt) import Partial.Unsafe (unsafePartial) @@ -119,7 +121,7 @@ instance showPerms :: Show Perms where permsFromString :: String -> Maybe Perms permsFromString = _perms <<< toCharArray <<< dropPrefix zeroChar where - zeroChar = fromCharCode 48 + zeroChar = unsafePartial $ fromJust $ toEnum 48 dropPrefix x xs | charAt 0 xs == Just x = drop 1 xs diff --git a/src/Node/FS/Stream.purs b/src/Node/FS/Stream.purs index 534c263..ebb653c 100644 --- a/src/Node/FS/Stream.purs +++ b/src/Node/FS/Stream.purs @@ -17,18 +17,18 @@ import Prelude import Data.Maybe (Maybe(..)) import Data.Function.Uncurried (Fn2, runFn2) import Data.Nullable (Nullable, toNullable) -import Control.Monad.Eff (Eff) +import Effect (Effect) import Node.Stream (Readable(), Writable()) import Node.Path (FilePath()) -import Node.FS (FS, FileDescriptor, FileFlags(..), fileFlagsToNode) +import Node.FS (FileDescriptor, FileFlags(..), fileFlagsToNode) import Node.FS.Perms (Perms()) import Node.FS.Perms as Perms -import Node.FS.Internal (mkEff, unsafeRequireFS) +import Node.FS.Internal (mkEffect, unsafeRequireFS) fs :: - { createReadStream :: forall eff opts. Fn2 (Nullable FilePath) { | opts } (Readable () (fs :: FS | eff)) - , createWriteStream :: forall eff opts. Fn2 (Nullable FilePath) { | opts } (Writable () (fs :: FS | eff)) + { createReadStream :: forall opts. Fn2 (Nullable FilePath) { | opts } (Readable ()) + , createWriteStream :: forall opts. Fn2 (Nullable FilePath) { | opts } (Writable ()) } fs = unsafeRequireFS @@ -45,16 +45,14 @@ nonnull = toNullable <<< Just -- | Create a Writable stream which writes data to the specified file, using -- | the default options. -createWriteStream :: forall eff. - FilePath - -> Eff (fs :: FS | eff) (Writable () (fs :: FS | eff)) +createWriteStream :: FilePath + -> Effect (Writable ()) createWriteStream = createWriteStreamWith defaultWriteStreamOptions -- | Create a Writable stream which writes data to the specified file -- | descriptor, using the default options. -fdCreateWriteStream :: forall eff. - FileDescriptor - -> Eff (fs :: FS | eff) (Writable () (fs :: FS | eff)) +fdCreateWriteStream :: FileDescriptor + -> Effect (Writable ()) fdCreateWriteStream = fdCreateWriteStreamWith defaultWriteStreamOptions type WriteStreamOptions = @@ -69,22 +67,20 @@ defaultWriteStreamOptions = } -- | Like `createWriteStream`, but allows you to pass options. -createWriteStreamWith :: forall eff. - WriteStreamOptions +createWriteStreamWith :: WriteStreamOptions -> FilePath - -> Eff (fs :: FS | eff) (Writable () (fs :: FS | eff)) -createWriteStreamWith opts file = mkEff $ \_ -> runFn2 + -> Effect (Writable ()) +createWriteStreamWith opts file = mkEffect $ \_ -> runFn2 fs.createWriteStream (nonnull file) { mode: Perms.permsToInt opts.perms , flags: fileFlagsToNode opts.flags } -- | Like `fdCreateWriteStream`, but allows you to pass options. -fdCreateWriteStreamWith :: forall eff. - WriteStreamOptions +fdCreateWriteStreamWith :: WriteStreamOptions -> FileDescriptor - -> Eff (fs :: FS | eff) (Writable () (fs :: FS | eff)) -fdCreateWriteStreamWith opts fd = mkEff $ \_ -> runFn2 + -> Effect (Writable ()) +fdCreateWriteStreamWith opts fd = mkEffect $ \_ -> runFn2 fs.createWriteStream null { fd , mode: Perms.permsToInt opts.perms @@ -93,16 +89,14 @@ fdCreateWriteStreamWith opts fd = mkEff $ \_ -> runFn2 -- | Create a Readable stream which reads data to the specified file, using -- | the default options. -createReadStream :: forall eff. - FilePath - -> Eff (fs :: FS | eff) (Readable () (fs :: FS | eff)) +createReadStream :: FilePath + -> Effect (Readable ()) createReadStream = createReadStreamWith defaultReadStreamOptions -- | Create a Readable stream which reads data to the specified file -- | descriptor, using the default options. -fdCreateReadStream :: forall eff. - FileDescriptor - -> Eff (fs :: FS | eff) (Readable () (fs :: FS | eff)) +fdCreateReadStream :: FileDescriptor + -> Effect (Readable ()) fdCreateReadStream = fdCreateReadStreamWith defaultReadStreamOptions type ReadStreamOptions = @@ -119,11 +113,10 @@ defaultReadStreamOptions = } -- | Create a Readable stream which reads data from the specified file. -createReadStreamWith :: forall eff. - ReadStreamOptions +createReadStreamWith :: ReadStreamOptions -> FilePath - -> Eff (fs :: FS | eff) (Readable () (fs :: FS | eff)) -createReadStreamWith opts file = mkEff $ \_ -> runFn2 + -> Effect (Readable ()) +createReadStreamWith opts file = mkEffect $ \_ -> runFn2 fs.createReadStream (nonnull file) { mode: Perms.permsToInt opts.perms , flags: fileFlagsToNode opts.flags @@ -131,11 +124,10 @@ createReadStreamWith opts file = mkEff $ \_ -> runFn2 } -- | Create a Readable stream which reads data from the specified file descriptor. -fdCreateReadStreamWith :: forall eff. - ReadStreamOptions +fdCreateReadStreamWith :: ReadStreamOptions -> FileDescriptor - -> Eff (fs :: FS | eff) (Readable () (fs :: FS | eff)) -fdCreateReadStreamWith opts fd = mkEff $ \_ -> runFn2 + -> Effect (Readable ()) +fdCreateReadStreamWith opts fd = mkEffect $ \_ -> runFn2 fs.createReadStream null { fd , mode: Perms.permsToInt opts.perms diff --git a/src/Node/FS/Sync.purs b/src/Node/FS/Sync.purs index 7759dcc..7e90288 100644 --- a/src/Node/FS/Sync.purs +++ b/src/Node/FS/Sync.purs @@ -32,8 +32,7 @@ module Node.FS.Sync ) where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Exception (EXCEPTION) +import Effect (Effect) import Data.DateTime (DateTime) import Data.Time.Duration (Milliseconds(..)) import Data.DateTime.Instant (fromDateTime, unInstant) @@ -42,16 +41,16 @@ import Data.Function.Uncurried (Fn1, Fn5, Fn3, Fn2, import Data.Nullable (Nullable(), toNullable) import Data.Int (round) import Data.Maybe (Maybe(..)) -import Node.Buffer (Buffer(), BUFFER(), size) +import Node.Buffer (Buffer(), size) import Node.Encoding (Encoding) -import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength, +import Node.FS (FileDescriptor, ByteCount, FilePosition, BufferLength, BufferOffset, FileMode, FileFlags, SymlinkType, fileFlagsToNode, symlinkTypeToNode) import Node.FS.Stats (StatsObj, Stats(..)) import Node.Path (FilePath()) import Node.FS.Perms (Perms, permsToString, all, mkPerms) -import Node.FS.Internal (mkEff, unsafeRequireFS) +import Node.FS.Internal (mkEffect, unsafeRequireFS) fs :: { renameSync :: Fn2 FilePath FilePath Unit @@ -81,127 +80,127 @@ fs :: fs = unsafeRequireFS -- | Renames a file. -rename :: forall eff. FilePath - -> FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +rename :: FilePath + -> FilePath + -> Effect Unit -rename oldFile newFile = mkEff $ \_ -> runFn2 +rename oldFile newFile = mkEffect $ \_ -> runFn2 fs.renameSync oldFile newFile -- | Truncates a file to the specified length. -truncate :: forall eff. FilePath - -> Int - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +truncate :: FilePath + -> Int + -> Effect Unit -truncate file len = mkEff $ \_ -> runFn2 +truncate file len = mkEffect $ \_ -> runFn2 fs.truncateSync file len -- | Changes the ownership of a file. -chown :: forall eff. FilePath - -> Int - -> Int - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +chown :: FilePath + -> Int + -> Int + -> Effect Unit -chown file uid gid = mkEff $ \_ -> runFn3 +chown file uid gid = mkEffect $ \_ -> runFn3 fs.chownSync file uid gid -- | Changes the permissions of a file. -chmod :: forall eff. FilePath - -> Perms - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +chmod :: FilePath + -> Perms + -> Effect Unit -chmod file perms = mkEff $ \_ -> runFn2 +chmod file perms = mkEffect $ \_ -> runFn2 fs.chmodSync file (permsToString perms) -- | Gets file statistics. -stat :: forall eff. FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Stats +stat :: FilePath + -> Effect Stats -stat file = map Stats $ mkEff $ \_ -> runFn1 +stat file = map Stats $ mkEffect $ \_ -> runFn1 fs.statSync file -- | Creates a link to an existing file. -link :: forall eff. FilePath - -> FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +link :: FilePath + -> FilePath + -> Effect Unit -link src dst = mkEff $ \_ -> runFn2 +link src dst = mkEffect $ \_ -> runFn2 fs.linkSync src dst -- | Creates a symlink. -symlink :: forall eff. FilePath - -> FilePath - -> SymlinkType - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +symlink :: FilePath + -> FilePath + -> SymlinkType + -> Effect Unit -symlink src dst ty = mkEff $ \_ -> runFn3 +symlink src dst ty = mkEffect $ \_ -> runFn3 fs.symlinkSync src dst (symlinkTypeToNode ty) -- | Reads the value of a symlink. -readlink :: forall eff. FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) FilePath +readlink :: FilePath + -> Effect FilePath -readlink path = mkEff $ \_ -> runFn1 +readlink path = mkEffect $ \_ -> runFn1 fs.readlinkSync path -- | Find the canonicalized absolute location for a path. -realpath :: forall eff. FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) FilePath +realpath :: FilePath + -> Effect FilePath -realpath path = mkEff $ \_ -> runFn2 +realpath path = mkEffect $ \_ -> runFn2 fs.realpathSync path {} -- | Find the canonicalized absolute location for a path using a cache object for -- | already resolved paths. -realpath' :: forall eff cache. FilePath +realpath' :: forall cache. FilePath -> { | cache } - -> Eff (fs :: FS, exception :: EXCEPTION | eff) FilePath + -> Effect FilePath -realpath' path cache = mkEff $ \_ -> runFn2 +realpath' path cache = mkEffect $ \_ -> runFn2 fs.realpathSync path cache -- | Deletes a file. -unlink :: forall eff. FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +unlink :: FilePath + -> Effect Unit -unlink file = mkEff $ \_ -> runFn1 +unlink file = mkEffect $ \_ -> runFn1 fs.unlinkSync file -- | Deletes a directory. -rmdir :: forall eff. FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +rmdir :: FilePath + -> Effect Unit -rmdir file = mkEff $ \_ -> runFn1 +rmdir file = mkEffect $ \_ -> runFn1 fs.rmdirSync file -- | Makes a new directory. -mkdir :: forall eff. FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +mkdir :: FilePath + -> Effect Unit mkdir = flip mkdir' $ mkPerms all all all -- | Makes a new directory with the specified permissions. -mkdir' :: forall eff. FilePath - -> Perms - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +mkdir' :: FilePath + -> Perms + -> Effect Unit -mkdir' file perms = mkEff $ \_ -> runFn2 +mkdir' file perms = mkEffect $ \_ -> runFn2 fs.mkdirSync file (permsToString perms) -- | Reads the contents of a directory. -readdir :: forall eff. FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) (Array FilePath) +readdir :: FilePath + -> Effect (Array FilePath) -readdir file = mkEff $ \_ -> runFn1 +readdir file = mkEffect $ \_ -> runFn1 fs.readdirSync file -- | Sets the accessed and modified times for the specified file. -utimes :: forall eff. FilePath - -> DateTime - -> DateTime - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +utimes :: FilePath + -> DateTime + -> DateTime + -> Effect Unit -utimes file atime mtime = mkEff $ \_ -> runFn3 +utimes file atime mtime = mkEffect $ \_ -> runFn3 fs.utimesSync file (fromDate atime) (fromDate mtime) @@ -211,123 +210,116 @@ utimes file atime mtime = mkEff $ \_ -> runFn3 toEpochMilliseconds = unInstant <<< fromDateTime -- | Reads the entire contents of a file returning the result as a raw buffer. -readFile :: forall eff. FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Buffer +readFile :: FilePath + -> Effect Buffer -readFile file = mkEff $ \_ -> runFn2 +readFile file = mkEffect $ \_ -> runFn2 fs.readFileSync file {} -- | Reads the entire contents of a text file with the specified encoding. -readTextFile :: forall eff. Encoding - -> FilePath - -> Eff (fs :: FS, exception :: EXCEPTION | eff) String +readTextFile :: Encoding + -> FilePath + -> Effect String -readTextFile encoding file = mkEff $ \_ -> runFn2 +readTextFile encoding file = mkEffect $ \_ -> runFn2 fs.readFileSync file { encoding: show encoding } -- | Writes a buffer to a file. -writeFile :: forall eff. FilePath - -> Buffer - -> Eff (buffer :: BUFFER, fs :: FS, exception :: EXCEPTION | eff) Unit +writeFile :: FilePath + -> Buffer + -> Effect Unit -writeFile file buff = mkEff $ \_ -> runFn3 +writeFile file buff = mkEffect $ \_ -> runFn3 fs.writeFileSync file buff {} -- | Writes text to a file using the specified encoding. -writeTextFile :: forall eff. Encoding - -> FilePath - -> String - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +writeTextFile :: Encoding + -> FilePath + -> String + -> Effect Unit -writeTextFile encoding file text = mkEff $ \_ -> runFn3 +writeTextFile encoding file text = mkEffect $ \_ -> runFn3 fs.writeFileSync file text { encoding: show encoding } -- | Appends the contents of a buffer to a file. -appendFile :: forall eff. FilePath - -> Buffer - -> Eff (buffer :: BUFFER, fs :: FS, exception :: EXCEPTION | eff) Unit +appendFile :: FilePath + -> Buffer + -> Effect Unit -appendFile file buff = mkEff $ \_ -> runFn3 +appendFile file buff = mkEffect $ \_ -> runFn3 fs.appendFileSync file buff {} -- | Appends text to a file using the specified encoding. -appendTextFile :: forall eff. Encoding - -> FilePath - -> String - -> Eff (fs :: FS, exception :: EXCEPTION | eff) Unit +appendTextFile :: Encoding + -> FilePath + -> String + -> Effect Unit -appendTextFile encoding file buff = mkEff $ \_ -> runFn3 +appendTextFile encoding file buff = mkEffect $ \_ -> runFn3 fs.appendFileSync file buff { encoding: show encoding } -- | Check if the path exists. -exists :: forall eff. FilePath - -> Eff (fs :: FS | eff) Boolean -exists file = mkEff $ \_ -> fs.existsSync file +exists :: FilePath + -> Effect Boolean +exists file = mkEffect $ \_ -> fs.existsSync file -- | Open a file synchronously. See the [Node documentation](http://nodejs.org/api/fs.html#fs_fs_opensync_path_flags_mode) -- | for details. -fdOpen :: forall eff. - FilePath +fdOpen :: FilePath -> FileFlags -> Maybe FileMode - -> Eff (exception :: EXCEPTION, fs :: FS | eff) FileDescriptor -fdOpen file flags mode = mkEff $ \_ -> + -> Effect FileDescriptor +fdOpen file flags mode = mkEffect $ \_ -> runFn3 fs.openSync file (fileFlagsToNode flags) (toNullable mode) -- | Read from a file synchronously. See the [Node documentation](http://nodejs.org/api/fs.html#fs_fs_readsync_fd_buffer_offset_length_position) -- | for details. -fdRead :: forall eff. - FileDescriptor +fdRead :: FileDescriptor -> Buffer -> BufferOffset -> BufferLength -> Maybe FilePosition - -> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount + -> Effect ByteCount fdRead fd buff off len pos = - mkEff $ \_ -> runFn5 fs.readSync fd buff off len (toNullable pos) + mkEffect $ \_ -> runFn5 fs.readSync fd buff off len (toNullable pos) -- | Convenience function to fill the whole buffer from the current -- | file position. -fdNext :: forall eff. - FileDescriptor +fdNext :: FileDescriptor -> Buffer - -> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount + -> Effect ByteCount fdNext fd buff = do sz <- size buff fdRead fd buff 0 sz Nothing -- | Write to a file synchronously. See the [Node documentation](http://nodejs.org/api/fs.html#fs_fs_writesync_fd_buffer_offset_length_position) -- | for details. -fdWrite :: forall eff. - FileDescriptor +fdWrite :: FileDescriptor -> Buffer -> BufferOffset -> BufferLength -> Maybe FilePosition - -> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount + -> Effect ByteCount fdWrite fd buff off len pos = - mkEff $ \_ -> runFn5 fs.writeSync fd buff off len (toNullable pos) + mkEffect $ \_ -> runFn5 fs.writeSync fd buff off len (toNullable pos) -- | Convenience function to append the whole buffer to the current -- | file position. -fdAppend :: forall eff. - FileDescriptor +fdAppend :: FileDescriptor -> Buffer - -> Eff (buffer :: BUFFER, exception :: EXCEPTION, fs :: FS | eff) ByteCount + -> Effect ByteCount fdAppend fd buff = do sz <- size buff fdWrite fd buff 0 sz Nothing -- | Flush a file synchronously. See the [Node documentation](http://nodejs.org/api/fs.html#fs_fs_fsyncsync_fd) -- | for details. -fdFlush :: forall eff. - FileDescriptor - -> Eff (exception :: EXCEPTION, fs :: FS | eff) Unit -fdFlush fd = mkEff $ \_ -> runFn1 fs.fsyncSync fd +fdFlush :: FileDescriptor + -> Effect Unit +fdFlush fd = mkEffect $ \_ -> runFn1 fs.fsyncSync fd -- | Close a file synchronously. See the [Node documentation](http://nodejs.org/api/fs.html#fs_fs_closesync_fd) -- | for details. -fdClose :: forall eff. - FileDescriptor - -> Eff (exception :: EXCEPTION, fs :: FS | eff) Unit -fdClose fd = mkEff $ \_ -> runFn1 fs.closeSync fd +fdClose :: FileDescriptor + -> Effect Unit +fdClose fd = mkEffect $ \_ -> runFn1 fs.closeSync fd diff --git a/test/Main.purs b/test/Main.purs index 8cee6a8..08e5062 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,17 +1,12 @@ module Test.Main where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE) -import Control.Monad.Eff.Exception (EXCEPTION) -import Node.FS (FS) -import Node.Buffer (BUFFER) +import Effect (Effect) import Test as Test import TestAsync as TestAsync import Test.Streams as Streams -main::forall e. Eff (fs :: FS , console :: CONSOLE , - exception :: EXCEPTION , buffer :: BUFFER | e) Unit +main :: Effect Unit main = do Test.main TestAsync.main diff --git a/test/Streams.purs b/test/Streams.purs index 377f068..8e75daf 100644 --- a/test/Streams.purs +++ b/test/Streams.purs @@ -1,18 +1,16 @@ module Test.Streams where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (log, CONSOLE) -import Control.Monad.Eff.Exception (EXCEPTION) +import Effect (Effect) +import Effect.Console (log) import Node.Encoding (Encoding(..)) import Node.Path as Path import Node.Stream as Stream -import Node.FS (FS) import Node.FS.Stream (createWriteStream, createReadStream) import Node.FS.Sync as Sync -main::forall e. Eff (fs::FS, console::CONSOLE, exception::EXCEPTION | e) Unit +main :: Effect Unit main = do let fp = Path.concat diff --git a/test/Test.purs b/test/Test.purs index 73e5b02..a1c60e4 100644 --- a/test/Test.purs +++ b/test/Test.purs @@ -3,17 +3,16 @@ module Test where import Prelude import Data.Maybe (Maybe(..)) import Data.Either (Either(..), either) -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Exception (EXCEPTION, Error, error, throwException, - catchException) -import Control.Monad.Eff.Console (CONSOLE, log) +import Effect (Effect) +import Effect.Exception (Error, error, throwException, catchException) +import Effect.Console (log) import Node.Encoding (Encoding(..)) import Node.Buffer as Buffer import Node.Path as Path import Unsafe.Coerce (unsafeCoerce) -import Node.FS (FS, FileFlags(..)) +import Node.FS (FileFlags(..)) import Node.FS.Stats (statusChangedTime, accessedTime, modifiedTime, isSymbolicLink, isSocket, isFIFO, isCharacterDevice, isBlockDevice, isDirectory, isFile) @@ -23,15 +22,14 @@ import Node.FS.Sync as S -- Cheat to allow `main` to type check. See also issue #5 in -- purescript-exceptions. catchException' :: - forall a eff. - (Error -> Eff (exception :: EXCEPTION | eff) a) - -> Eff (exception :: EXCEPTION | eff) a - -> Eff (exception :: EXCEPTION | eff) a + forall a. + (Error -> Effect a) + -> Effect a + -> Effect a catchException' = unsafeCoerce catchException -main::forall e. Eff (fs::FS, console::CONSOLE, exception::EXCEPTION, - buffer::Buffer.BUFFER | e) Unit +main :: Effect Unit main = do let fp = Path.concat diff --git a/test/TestAsync.purs b/test/TestAsync.purs index d0a541d..5bdbec9 100644 --- a/test/TestAsync.purs +++ b/test/TestAsync.purs @@ -3,17 +3,17 @@ module TestAsync where import Prelude (Unit, show, bind, discard, (<>), ($)) import Data.Either (Either(..)) import Data.Maybe (Maybe(..)) -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console(log,CONSOLE()) +import Effect (Effect) +import Effect.Console (log) -import Node.FS (FileFlags(..), FS) +import Node.FS (FileFlags(..)) import Node.FS.Async as A import Node.Path as FP import Node.Buffer as B -- exercise the file descriptor based async IO functions -main ::forall e. Eff (fs::FS, console::CONSOLE, buffer::B.BUFFER |e) Unit +main :: Effect Unit main = do let path1 = FP.concat( ["test", "TestAsync.purs"] ) path2 = FP.concat( ["test", "TestAsync.purs.partial"] )