Skip to content

Purescript 0.9.1 update #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
"package.json"
],
"dependencies": {
"purescript-datetime": "^0.9.0",
"purescript-foreign": "^0.7.0",
"purescript-node-buffer": "^0.2.0",
"purescript-node-path": "^0.4.0",
"purescript-unsafe-coerce": "^0.1.0",
"purescript-nullable": "~0.2.1",
"purescript-node-streams": "~0.4.0",
"purescript-exceptions": "~0.3.3"
"purescript-datetime": "^1.0.0",
"purescript-foreign": "^1.0.0",
"purescript-node-buffer": "^1.0.0",
"purescript-node-path": "^1.0.0",
"purescript-unsafe-coerce": "^1.0.0",
"purescript-nullable": "^1.0.0",
"purescript-node-streams": "^1.0.0",
"purescript-exceptions": "^1.0.0",
"purescript-js-date": "^1.0.0",
"purescript-globals": "^1.0.0"
},
"devDependencies": {
"purescript-console": "~0.1.1"
"purescript-console": "^1.0.0"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"devDependencies": {
"pulp": "^8.1.0",
"pulp": "^9.0.1",
"bower": "^1.7.7"
},
"scripts": {
Expand Down
35 changes: 20 additions & 15 deletions src/Node/FS/Async.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,27 @@ module Node.FS.Async
) where

import Prelude
import Control.Monad.Eff
import Control.Monad.Eff (Eff, runPure)
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff)
import Control.Monad.Eff.Exception
import Data.Date
import Data.Time
import Data.Either
import Data.Function
import Data.Maybe
import Data.Nullable
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.Maybe (Maybe(..))
import Data.Nullable (Nullable, toNullable)
import Node.Buffer (Buffer(), BUFFER(), size)
import Data.Int (round)
import Node.Encoding
import Node.FS
import Node.FS.Stats
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.Perms
import Node.FS.Internal
import Node.FS.Perms (Perms, permsToString, all, mkPerms)
import Node.FS.Internal (mkEff, unsafeRequireFS)

type JSCallback a = Fn2 (Nullable Error) a Unit

Expand Down Expand Up @@ -221,8 +225,8 @@ readdir file cb = mkEff $ \_ -> runFn2

-- | Sets the accessed and modified times for the specified file.
utimes :: forall eff. FilePath
-> Date
-> Date
-> DateTime
-> DateTime
-> Callback eff Unit
-> Eff (fs :: FS | eff) Unit

Expand All @@ -234,6 +238,7 @@ utimes file atime mtime cb = mkEff $ \_ -> runFn4
where
fromDate date = ms (toEpochMilliseconds date) / 1000
ms (Milliseconds n) = round n
toEpochMilliseconds = unInstant <<< fromDateTime

-- | Reads the entire contents of a file returning the result as a raw buffer.
readFile :: forall eff. FilePath
Expand Down
4 changes: 2 additions & 2 deletions src/Node/FS/Internal.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
module Node.FS.Internal where

import Prelude
import Control.Monad.Eff
import Unsafe.Coerce
import Control.Monad.Eff (Eff)
import Unsafe.Coerce (unsafeCoerce)

mkEff :: forall e a. (Unit -> a) -> Eff e a
mkEff = unsafeCoerce
Expand Down
32 changes: 16 additions & 16 deletions src/Node/FS/Perms.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ module Node.FS.Perms

import Prelude
import Global (readInt)
import Data.Maybe (Maybe(..), isNothing)
import Data.Maybe.Unsafe (fromJust)
import Data.Maybe (Maybe(..), isNothing, fromJust)
import Data.Char (fromCharCode)
import Data.String (toCharArray, joinWith, drop, charAt, indexOf)
import Data.Int (fromNumber)
import Partial.Unsafe (unsafePartial)

-- | A `Perm` value specifies what is allowed to be done with a particular
-- | file by a particular class of user &mdash; that is, whether it is
Expand All @@ -37,17 +37,17 @@ import Data.Int (fromNumber)
newtype Perm = Perm { r :: Boolean, w :: Boolean, x :: Boolean }

instance eqPerm :: Eq Perm where
eq (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
eq (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
r1 == r2 && w1 == w2 && x1 == x2

instance ordPerm :: Ord Perm where
compare (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
compare (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
compare [r1, w1, x1] [r2, w2, x2]

instance showPerm :: Show Perm where
show p | p == none = "none"
show p | p == all = "all"
show (Perm { r = r, w = w, x = x }) =
show (Perm { r: r, w: w, x: x }) =
joinWith " + " ps
where
ps =
Expand All @@ -56,10 +56,10 @@ instance showPerm :: Show Perm where
(if x then ["execute"] else [])

instance semiringPerm :: Semiring Perm where
add (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
add (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
Perm { r: r0 || r1, w: w0 || w1, x: x0 || x1 }
zero = Perm { r: false, w: false, x: false }
mul (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
mul (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
Perm { r: r0 && r1, w: w0 && w1, x: x0 && x1 }
one = Perm { r: true, w: true, x: true }

Expand Down Expand Up @@ -97,15 +97,15 @@ all = one
newtype Perms = Perms { u :: Perm, g :: Perm, o :: Perm }

instance eqPerms :: Eq Perms where
eq (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
eq (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
u1 == u2 && g1 == g2 && o1 == o2

instance ordPerms :: Ord Perms where
compare (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
compare (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
compare [u1, g1, o1] [u2, g2, o2]

instance showPerms :: Show Perms where
show (Perms { u = u, g = g, o = o }) =
show (Perms { u: u, g: g, o: o }) =
"mkPerms " <> joinWith " " (f <$> [u, g, o])
where
f perm = let str = show perm
Expand Down Expand Up @@ -154,7 +154,7 @@ mkPerms u g o = Perms { u: u, g: g, o: o }
-- | * `permToInt w == 2`
-- | * `permToInt (r + w) == 6`
permToInt :: Perm -> Int
permToInt (Perm { r = r, w = w, x = x }) =
permToInt (Perm { r: r, w: w, x: x }) =
(if r then 4 else 0)
+ (if w then 2 else 0)
+ (if x then 1 else 0)
Expand All @@ -167,12 +167,12 @@ permToString = show <<< permToInt
-- | accepted by `chmod`. For example:
-- | `permsToString (mkPerms (read + write) read read) == "0644"`
permsToString :: Perms -> String
permsToString (Perms { u = u, g = g, o = o }) =
permsToString (Perms { u: u, g: g, o: o }) =
"0"
++ permToString u
++ permToString g
++ permToString o
<> permToString u
<> permToString g
<> permToString o

-- | Convert a `Perms` value to an `Int`, via `permsToString`.
permsToInt :: Perms -> Int
permsToInt = fromJust <<< fromNumber <<< readInt 8 <<< permsToString
permsToInt = unsafePartial $ fromJust <<< fromNumber <<< readInt 8 <<< permsToString
22 changes: 12 additions & 10 deletions src/Node/FS/Stats.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ module Node.FS.Stats
) where

import Prelude
import Data.Date
import Data.Function
import Data.Maybe.Unsafe (fromJust)
import Data.DateTime (DateTime)
import Data.Function.Uncurried (Fn2, Fn0, runFn2)
import Data.JSDate (JSDate, toDateTime)
import Data.Maybe (fromJust)
import Partial.Unsafe (unsafePartial)

type StatsObj =
{ dev :: Number
Expand Down Expand Up @@ -44,7 +46,7 @@ data Stats = Stats StatsObj
foreign import showStatsObj :: StatsObj -> String

instance showStats :: Show Stats where
show (Stats o) = "Stats " ++ showStatsObj o
show (Stats o) = "Stats " <> showStatsObj o

foreign import statsMethod :: Fn2 String StatsObj Boolean

Expand All @@ -69,11 +71,11 @@ isSocket (Stats s) = runFn2 statsMethod "isSocket" s
isSymbolicLink :: Stats -> Boolean
isSymbolicLink (Stats s) = runFn2 statsMethod "isSymbolicLink" s

accessedTime :: Stats -> Date
accessedTime (Stats s) = fromJust (fromJSDate s.atime)
accessedTime :: Stats -> DateTime
accessedTime (Stats s) = unsafePartial $ fromJust (toDateTime s.atime)

modifiedTime :: Stats -> Date
modifiedTime (Stats s) = fromJust (fromJSDate s.mtime)
modifiedTime :: Stats -> DateTime
modifiedTime (Stats s) = unsafePartial $ fromJust (toDateTime s.mtime)

statusChangedTime :: Stats -> Date
statusChangedTime (Stats s) = fromJust (fromJSDate s.ctime)
statusChangedTime :: Stats -> DateTime
statusChangedTime (Stats s) = unsafePartial $ fromJust (toDateTime s.ctime)
10 changes: 5 additions & 5 deletions src/Node/FS/Stream.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ module Node.FS.Stream

import Prelude
import Data.Maybe (Maybe(..))
import Data.Function
import Data.Nullable
import Control.Monad.Eff
import Data.Function.Uncurried (Fn2, runFn2)
import Data.Nullable (Nullable, toNullable)
import Control.Monad.Eff (Eff)
import Node.Stream (Readable(), Writable())
import Node.Path (FilePath())

import Node.FS
import Node.FS (FS, FileDescriptor, FileFlags(..), fileFlagsToNode)
import Node.FS.Perms (Perms())
import Node.FS.Perms as Perms
import Node.FS.Internal
import Node.FS.Internal (mkEff, unsafeRequireFS)

fs ::
{ createReadStream :: forall eff opts. Fn2 (Nullable FilePath) { | opts } (Readable () (fs :: FS | eff))
Expand Down
29 changes: 17 additions & 12 deletions src/Node/FS/Sync.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,26 @@ module Node.FS.Sync
) where

import Prelude
import Control.Monad.Eff
import Control.Monad.Eff.Exception
import Data.Date
import Data.Time
import Data.Function
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Exception (EXCEPTION)
import Data.DateTime (DateTime)
import Data.Time.Duration (Milliseconds(..))
import Data.DateTime.Instant (fromDateTime, unInstant)
import Data.Function.Uncurried (Fn1, Fn5, Fn3, Fn2,
runFn1, runFn5, runFn3, runFn2)
import Data.Nullable (Nullable(), toNullable)
import Data.Int (round)
import Data.Maybe (Maybe(..))
import Node.Buffer (Buffer(), BUFFER(), size)
import Node.Encoding
import Node.Encoding (Encoding)

import Node.FS
import Node.FS.Stats
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.Perms
import Node.FS.Internal
import Node.FS.Perms (Perms, permsToString, all, mkPerms)
import Node.FS.Internal (mkEff, unsafeRequireFS)

fs ::
{ renameSync :: Fn2 FilePath FilePath Unit
Expand Down Expand Up @@ -193,8 +197,8 @@ readdir file = mkEff $ \_ -> runFn1

-- | Sets the accessed and modified times for the specified file.
utimes :: forall eff. FilePath
-> Date
-> Date
-> DateTime
-> DateTime
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit

utimes file atime mtime = mkEff $ \_ -> runFn3
Expand All @@ -204,6 +208,7 @@ utimes file atime mtime = mkEff $ \_ -> runFn3
where
fromDate date = ms (toEpochMilliseconds date) / 1000
ms (Milliseconds n) = round n
toEpochMilliseconds = unInstant <<< fromDateTime

-- | Reads the entire contents of a file returning the result as a raw buffer.
readFile :: forall eff. FilePath
Expand Down
11 changes: 9 additions & 2 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
module Test.Main where

import Prelude
import qualified Test as Test
import qualified TestAsync as TestAsync
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 Test as Test
import TestAsync as TestAsync
import Test.Streams as Streams

main::forall e. Eff (fs :: FS , console :: CONSOLE ,
err :: EXCEPTION , buffer :: BUFFER | e) Unit
main = do
Test.main
TestAsync.main
Expand Down
20 changes: 7 additions & 13 deletions test/Streams.purs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
module Test.Streams where

import Prelude
import Data.Maybe
import Data.Either
import Control.Apply ((*>))
import Control.Bind ((=<<))
import Control.Monad.Eff
import Control.Monad.Eff.Exception
import Control.Monad.Eff.Console (log)
import Node.Encoding
import Node.Buffer as Buffer
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (log, CONSOLE)
import Control.Monad.Eff.Exception (EXCEPTION)
import Node.Encoding (Encoding(..))
import Node.Path as Path
import Node.Stream as Stream
import Unsafe.Coerce

import Node.FS
import Node.FS.Stats
import Node.FS.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, err::EXCEPTION | e) Unit
main = do
let fp = Path.concat

Expand Down
Loading