Skip to content

Commit a6cd5ae

Browse files
committed
Purescript 0.9.1 update
1 parent 375c76e commit a6cd5ae

File tree

12 files changed

+170
-144
lines changed

12 files changed

+170
-144
lines changed

bower.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
"package.json"
1616
],
1717
"dependencies": {
18-
"purescript-datetime": "^0.9.0",
19-
"purescript-foreign": "^0.7.0",
20-
"purescript-node-buffer": "^0.2.0",
21-
"purescript-node-path": "^0.4.0",
22-
"purescript-unsafe-coerce": "^0.1.0",
23-
"purescript-nullable": "~0.2.1",
24-
"purescript-node-streams": "~0.4.0",
25-
"purescript-exceptions": "~0.3.3"
18+
"purescript-datetime": "^1.0.0",
19+
"purescript-foreign": "^1.0.0",
20+
"purescript-node-buffer": "^1.0.0",
21+
"purescript-node-path": "^1.0.0",
22+
"purescript-unsafe-coerce": "^1.0.0",
23+
"purescript-nullable": "~1.0.0",
24+
"purescript-node-streams": "~1.0.0",
25+
"purescript-exceptions": "~1.0.0",
26+
"purescript-js-date": "^1.0.0",
27+
"purescript-globals": "^1.0.0"
2628
},
2729
"devDependencies": {
28-
"purescript-console": "~0.1.1"
30+
"purescript-console": "~1.0.0"
2931
},
3032
"repository": {
3133
"type": "git",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"devDependencies": {
4-
"pulp": "^8.1.0",
4+
"pulp": "^9.0.1",
55
"bower": "^1.7.7"
66
},
77
"scripts": {

src/Node/FS/Async.purs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,28 @@ module Node.FS.Async
3131
, fdClose
3232
) where
3333

34-
import Prelude
35-
import Control.Monad.Eff
34+
import Prelude (Unit, bind, show, flip, ($), (<<<), (/), (<$>))
35+
import Control.Monad.Eff (Eff, runPure)
3636
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff)
37-
import Control.Monad.Eff.Exception
38-
import Data.Date
39-
import Data.Time
40-
import Data.Either
41-
import Data.Function
42-
import Data.Maybe
43-
import Data.Nullable
37+
import Control.Monad.Eff.Exception (Error)
38+
import Data.DateTime (DateTime)
39+
import Data.Time.Duration (Milliseconds(..))
40+
import Data.DateTime.Instant (fromDateTime, unInstant)
41+
import Data.Either (Either(..))
42+
import Data.Function.Uncurried (Fn2, Fn6, Fn4, Fn3,
43+
runFn2, runFn6, runFn4, runFn3)
44+
import Data.Maybe (Maybe(..))
45+
import Data.Nullable (Nullable, toNullable)
4446
import Node.Buffer (Buffer(), BUFFER(), size)
4547
import Data.Int (round)
46-
import Node.Encoding
47-
import Node.FS
48-
import Node.FS.Stats
48+
import Node.Encoding (Encoding)
49+
import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength,
50+
BufferOffset, FileMode, FileFlags, SymlinkType,
51+
fileFlagsToNode, symlinkTypeToNode)
52+
import Node.FS.Stats (StatsObj, Stats(..))
4953
import Node.Path (FilePath())
50-
import Node.FS.Perms
51-
import Node.FS.Internal
54+
import Node.FS.Perms (Perms, permsToString, all, mkPerms)
55+
import Node.FS.Internal (mkEff, unsafeRequireFS)
5256

5357
type JSCallback a = Fn2 (Nullable Error) a Unit
5458

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

222226
-- | Sets the accessed and modified times for the specified file.
223227
utimes :: forall eff. FilePath
224-
-> Date
225-
-> Date
228+
-> DateTime
229+
-> DateTime
226230
-> Callback eff Unit
227231
-> Eff (fs :: FS | eff) Unit
228232

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

238243
-- | Reads the entire contents of a file returning the result as a raw buffer.
239244
readFile :: forall eff. FilePath

src/Node/FS/Internal.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
module Node.FS.Internal where
33

4-
import Prelude
5-
import Control.Monad.Eff
6-
import Unsafe.Coerce
4+
import Prelude (Unit)
5+
import Control.Monad.Eff (Eff)
6+
import Unsafe.Coerce (unsafeCoerce)
77

88
mkEff :: forall e a. (Unit -> a) -> Eff e a
99
mkEff = unsafeCoerce

src/Node/FS/Perms.purs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ module Node.FS.Perms
1212
, permsToInt
1313
) where
1414

15-
import Prelude
15+
import Prelude (class Show, class Ord, class Eq, class Semiring,
16+
show, otherwise, compare, one, zero,
17+
(<<<), ($), (<>), (+), (<*>), (<$>), (==), (&&), (||))
1618
import Global (readInt)
17-
import Data.Maybe (Maybe(..), isNothing)
18-
import Data.Maybe.Unsafe (fromJust)
19+
import Data.Maybe (Maybe(..), isNothing, fromJust)
1920
import Data.Char (fromCharCode)
2021
import Data.String (toCharArray, joinWith, drop, charAt, indexOf)
2122
import Data.Int (fromNumber)
23+
import Partial.Unsafe (unsafePartial)
2224

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

3941
instance eqPerm :: Eq Perm where
40-
eq (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
42+
eq (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
4143
r1 == r2 && w1 == w2 && x1 == x2
4244

4345
instance ordPerm :: Ord Perm where
44-
compare (Perm { r = r1, w = w1, x = x1 }) (Perm { r = r2, w = w2, x = x2 }) =
46+
compare (Perm { r: r1, w: w1, x: x1 }) (Perm { r: r2, w: w2, x: x2 }) =
4547
compare [r1, w1, x1] [r2, w2, x2]
4648

4749
instance showPerm :: Show Perm where
4850
show p | p == none = "none"
4951
show p | p == all = "all"
50-
show (Perm { r = r, w = w, x = x }) =
52+
show (Perm { r: r, w: w, x: x }) =
5153
joinWith " + " ps
5254
where
5355
ps =
@@ -56,10 +58,10 @@ instance showPerm :: Show Perm where
5658
(if x then ["execute"] else [])
5759

5860
instance semiringPerm :: Semiring Perm where
59-
add (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
61+
add (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
6062
Perm { r: r0 || r1, w: w0 || w1, x: x0 || x1 }
6163
zero = Perm { r: false, w: false, x: false }
62-
mul (Perm { r = r0, w = w0, x = x0 }) (Perm { r = r1, w = w1, x = x1 }) =
64+
mul (Perm { r: r0, w: w0, x: x0 }) (Perm { r: r1, w: w1, x: x1 }) =
6365
Perm { r: r0 && r1, w: w0 && w1, x: x0 && x1 }
6466
one = Perm { r: true, w: true, x: true }
6567

@@ -97,15 +99,15 @@ all = one
9799
newtype Perms = Perms { u :: Perm, g :: Perm, o :: Perm }
98100

99101
instance eqPerms :: Eq Perms where
100-
eq (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
102+
eq (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
101103
u1 == u2 && g1 == g2 && o1 == o2
102104

103105
instance ordPerms :: Ord Perms where
104-
compare (Perms { u = u1, g = g1, o = o1 }) (Perms { u = u2, g = g2, o = o2 }) =
106+
compare (Perms { u: u1, g: g1, o: o1 }) (Perms { u: u2, g: g2, o: o2 }) =
105107
compare [u1, g1, o1] [u2, g2, o2]
106108

107109
instance showPerms :: Show Perms where
108-
show (Perms { u = u, g = g, o = o }) =
110+
show (Perms { u: u, g: g, o: o }) =
109111
"mkPerms " <> joinWith " " (f <$> [u, g, o])
110112
where
111113
f perm = let str = show perm
@@ -154,7 +156,7 @@ mkPerms u g o = Perms { u: u, g: g, o: o }
154156
-- | * `permToInt w == 2`
155157
-- | * `permToInt (r + w) == 6`
156158
permToInt :: Perm -> Int
157-
permToInt (Perm { r = r, w = w, x = x }) =
159+
permToInt (Perm { r: r, w: w, x: x }) =
158160
(if r then 4 else 0)
159161
+ (if w then 2 else 0)
160162
+ (if x then 1 else 0)
@@ -167,12 +169,12 @@ permToString = show <<< permToInt
167169
-- | accepted by `chmod`. For example:
168170
-- | `permsToString (mkPerms (read + write) read read) == "0644"`
169171
permsToString :: Perms -> String
170-
permsToString (Perms { u = u, g = g, o = o }) =
172+
permsToString (Perms { u: u, g: g, o: o }) =
171173
"0"
172-
++ permToString u
173-
++ permToString g
174-
++ permToString o
174+
<> permToString u
175+
<> permToString g
176+
<> permToString o
175177

176178
-- | Convert a `Perms` value to an `Int`, via `permsToString`.
177179
permsToInt :: Perms -> Int
178-
permsToInt = fromJust <<< fromNumber <<< readInt 8 <<< permsToString
180+
permsToInt = unsafePartial $ fromJust <<< fromNumber <<< readInt 8 <<< permsToString

src/Node/FS/Stats.purs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ module Node.FS.Stats
1313
, statusChangedTime
1414
) where
1515

16-
import Prelude
17-
import Data.Date
18-
import Data.Function
19-
import Data.Maybe.Unsafe (fromJust)
16+
import Prelude (class Show, ($), (<>))
17+
import Data.DateTime (DateTime)
18+
import Data.Function.Uncurried (Fn2, Fn0, runFn2)
19+
import Data.JSDate (JSDate, toDateTime)
20+
import Data.Maybe (fromJust)
21+
import Partial.Unsafe (unsafePartial)
2022

2123
type StatsObj =
2224
{ dev :: Number
@@ -44,7 +46,7 @@ data Stats = Stats StatsObj
4446
foreign import showStatsObj :: StatsObj -> String
4547

4648
instance showStats :: Show Stats where
47-
show (Stats o) = "Stats " ++ showStatsObj o
49+
show (Stats o) = "Stats " <> showStatsObj o
4850

4951
foreign import statsMethod :: Fn2 String StatsObj Boolean
5052

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

72-
accessedTime :: Stats -> Date
73-
accessedTime (Stats s) = fromJust (fromJSDate s.atime)
74+
accessedTime :: Stats -> DateTime
75+
accessedTime (Stats s) = unsafePartial $ fromJust (toDateTime s.atime)
7476

75-
modifiedTime :: Stats -> Date
76-
modifiedTime (Stats s) = fromJust (fromJSDate s.mtime)
77+
modifiedTime :: Stats -> DateTime
78+
modifiedTime (Stats s) = unsafePartial $ fromJust (toDateTime s.mtime)
7779

78-
statusChangedTime :: Stats -> Date
79-
statusChangedTime (Stats s) = fromJust (fromJSDate s.ctime)
80+
statusChangedTime :: Stats -> DateTime
81+
statusChangedTime (Stats s) = unsafePartial $ fromJust (toDateTime s.ctime)

src/Node/FS/Stream.purs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ module Node.FS.Stream
1313
, fdCreateReadStreamWith
1414
) where
1515

16-
import Prelude
16+
import Prelude (($), (<<<), (+))
1717
import Data.Maybe (Maybe(..))
18-
import Data.Function
19-
import Data.Nullable
20-
import Control.Monad.Eff
18+
import Data.Function.Uncurried (Fn2, runFn2)
19+
import Data.Nullable (Nullable, toNullable)
20+
import Control.Monad.Eff (Eff)
2121
import Node.Stream (Readable(), Writable())
2222
import Node.Path (FilePath())
2323

24-
import Node.FS
24+
import Node.FS (FS, FileDescriptor, FileFlags(..), fileFlagsToNode)
2525
import Node.FS.Perms (Perms())
2626
import Node.FS.Perms as Perms
27-
import Node.FS.Internal
27+
import Node.FS.Internal (mkEff, unsafeRequireFS)
2828

2929
fs ::
3030
{ createReadStream :: forall eff opts. Fn2 (Nullable FilePath) { | opts } (Readable () (fs :: FS | eff))

src/Node/FS/Sync.purs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,27 @@ module Node.FS.Sync
3131
, fdClose
3232
) where
3333

34-
import Prelude
35-
import Control.Monad.Eff
36-
import Control.Monad.Eff.Exception
37-
import Data.Date
38-
import Data.Time
39-
import Data.Function
34+
import Prelude (Unit, bind, show, flip, map, ($), (<<<), (/))
35+
import Control.Monad.Eff (Eff)
36+
import Control.Monad.Eff.Exception (EXCEPTION)
37+
import Data.DateTime (DateTime)
38+
import Data.Time.Duration (Milliseconds(..))
39+
import Data.DateTime.Instant (fromDateTime, unInstant)
40+
import Data.Function.Uncurried (Fn1, Fn5, Fn3, Fn2,
41+
runFn1, runFn5, runFn3, runFn2)
4042
import Data.Nullable (Nullable(), toNullable)
4143
import Data.Int (round)
4244
import Data.Maybe (Maybe(..))
4345
import Node.Buffer (Buffer(), BUFFER(), size)
44-
import Node.Encoding
46+
import Node.Encoding (Encoding)
4547

46-
import Node.FS
47-
import Node.FS.Stats
48+
import Node.FS (FS, FileDescriptor, ByteCount, FilePosition, BufferLength,
49+
BufferOffset, FileMode, FileFlags, SymlinkType,
50+
fileFlagsToNode, symlinkTypeToNode)
51+
import Node.FS.Stats (StatsObj, Stats(..))
4852
import Node.Path (FilePath())
49-
import Node.FS.Perms
50-
import Node.FS.Internal
53+
import Node.FS.Perms (Perms, permsToString, all, mkPerms)
54+
import Node.FS.Internal (mkEff, unsafeRequireFS)
5155

5256
fs ::
5357
{ renameSync :: Fn2 FilePath FilePath Unit
@@ -193,8 +197,8 @@ readdir file = mkEff $ \_ -> runFn1
193197

194198
-- | Sets the accessed and modified times for the specified file.
195199
utimes :: forall eff. FilePath
196-
-> Date
197-
-> Date
200+
-> DateTime
201+
-> DateTime
198202
-> Eff (fs :: FS, err :: EXCEPTION | eff) Unit
199203

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

208213
-- | Reads the entire contents of a file returning the result as a raw buffer.
209214
readFile :: forall eff. FilePath

test/Main.purs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
module Test.Main where
22

33
import Prelude
4-
import qualified Test as Test
5-
import qualified TestAsync as TestAsync
4+
import Control.Monad.Eff (Eff)
5+
import Control.Monad.Eff.Console (CONSOLE)
6+
import Control.Monad.Eff.Exception (EXCEPTION)
7+
import Node.FS (FS)
8+
import Node.Buffer (BUFFER)
9+
import Test as Test
10+
import TestAsync as TestAsync
611
import Test.Streams as Streams
712

13+
main::forall e. Eff (fs :: FS , console :: CONSOLE ,
14+
err :: EXCEPTION , buffer :: BUFFER | e) Unit
815
main = do
916
Test.main
1017
TestAsync.main

test/Streams.purs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
module Test.Streams where
22

3-
import Prelude
4-
import Data.Maybe
5-
import Data.Either
3+
import Prelude (Unit, bind, (==))
64
import Control.Apply ((*>))
75
import Control.Bind ((=<<))
8-
import Control.Monad.Eff
9-
import Control.Monad.Eff.Exception
10-
import Control.Monad.Eff.Console (log)
11-
import Node.Encoding
12-
import Node.Buffer as Buffer
6+
import Control.Monad.Eff (Eff)
7+
import Control.Monad.Eff.Console (log, CONSOLE)
8+
import Control.Monad.Eff.Exception (EXCEPTION)
9+
import Node.Encoding (Encoding(..))
1310
import Node.Path as Path
1411
import Node.Stream as Stream
15-
import Unsafe.Coerce
1612

1713
import Node.FS
18-
import Node.FS.Stats
19-
import Node.FS.Stream
14+
import Node.FS.Stream (createWriteStream, createReadStream)
2015
import Node.FS.Sync as Sync
2116

17+
main::forall e. Eff (fs::FS, console::CONSOLE, err::EXCEPTION | e) Unit
2218
main = do
2319
let fp = Path.concat
2420

0 commit comments

Comments
 (0)