Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit e3bd38d

Browse files
committed
Pin all exported functions' types
1 parent 45b6f51 commit e3bd38d

File tree

2 files changed

+185
-26
lines changed

2 files changed

+185
-26
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dependencies": {
2222
"purescript-aff": "~0.10.1",
2323
"purescript-node-fs": "~0.6.0",
24-
"purescript-either": "~0.1.8"
24+
"purescript-either": "~0.1.8",
25+
"purescript-node-path": "~0.3.0"
2526
}
2627
}

src/Node/FS/Aff.purs

Lines changed: 183 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ module Node.FS.Aff
2424
, exists
2525
) where
2626

27-
import Control.Monad.Eff (Eff(..))
27+
import Node.Path (FilePath())
28+
import Node.FS.Perms (Perms())
29+
import Node.FS.Stats (Stats())
30+
import Data.Date (Date())
31+
import Control.Monad.Eff (Eff())
2832
import Data.Either (either)
29-
import Control.Monad.Aff (Aff(..), makeAff)
33+
import Control.Monad.Aff (Aff(), makeAff)
34+
import Node.Buffer (Buffer())
35+
import Node.Encoding (Encoding())
3036
import qualified Node.FS as F
3137
import qualified Node.FS.Async as A
3238

@@ -39,35 +45,187 @@ toAff1 f a = toAff (f a)
3945
toAff2 f a b = toAff (f a b)
4046
toAff3 f a b c = toAff (f a b c)
4147

42-
rename = toAff2 A.rename
43-
truncate = toAff2 A.truncate
44-
chown = toAff3 A.chown
45-
chmod = toAff2 A.chmod
46-
stat = toAff1 A.stat
47-
link = toAff2 A.link
48-
symlink = toAff3 A.symlink
49-
readlink = toAff1 A.readlink
50-
realpath = toAff1 A.realpath
51-
realpath' = toAff2 A.realpath'
52-
unlink = toAff1 A.unlink
53-
rmdir = toAff1 A.rmdir
54-
mkdir = toAff1 A.mkdir
55-
mkdir' = toAff2 A.mkdir'
56-
readdir = toAff1 A.readdir
57-
utimes = toAff3 A.utimes
58-
readFile = toAff1 A.readFile
59-
readTextFile = toAff2 A.readTextFile
60-
writeFile = toAff2 A.writeFile
61-
writeTextFile = toAff3 A.writeTextFile
62-
appendFile = toAff2 A.appendFile
48+
-- |
49+
-- Renames a file.
50+
--
51+
rename :: forall eff. FilePath
52+
-> FilePath
53+
-> Aff (fs :: F.FS | eff) Unit
54+
rename = toAff2 A.rename
55+
56+
-- |
57+
-- Truncates a file to the specified length.
58+
--
59+
truncate :: forall eff. FilePath
60+
-> Number
61+
-> Aff (fs :: F.FS | eff) Unit
62+
truncate = toAff2 A.truncate
63+
64+
-- |
65+
-- Changes the ownership of a file.
66+
--
67+
chown :: forall eff. FilePath
68+
-> Number
69+
-> Number
70+
-> Aff (fs :: F.FS | eff) Unit
71+
chown = toAff3 A.chown
72+
73+
-- |
74+
-- Changes the permissions of a file.
75+
--
76+
chmod :: forall eff. FilePath
77+
-> Perms
78+
-> Aff (fs :: F.FS | eff) Unit
79+
chmod = toAff2 A.chmod
80+
81+
-- |
82+
-- Gets file statistics.
83+
--
84+
stat :: forall eff. FilePath
85+
-> Aff (fs :: F.FS | eff) Stats
86+
stat = toAff1 A.stat
87+
88+
-- |
89+
-- Creates a link to an existing file.
90+
--
91+
link :: forall eff. FilePath
92+
-> FilePath
93+
-> Aff (fs :: F.FS | eff) Unit
94+
link = toAff2 A.link
95+
96+
-- |
97+
-- Creates a symlink.
98+
--
99+
symlink :: forall eff. FilePath
100+
-> FilePath
101+
-> F.SymlinkType
102+
-> Aff (fs :: F.FS | eff) Unit
103+
symlink = toAff3 A.symlink
104+
105+
-- |
106+
-- Reads the value of a symlink.
107+
--
108+
readlink :: forall eff. FilePath
109+
-> Aff (fs :: F.FS | eff) FilePath
110+
readlink = toAff1 A.readlink
111+
112+
-- |
113+
-- Find the canonicalized absolute location for a path.
114+
--
115+
realpath :: forall eff. FilePath
116+
-> Aff (fs :: F.FS | eff) FilePath
117+
realpath = toAff1 A.realpath
118+
119+
-- |
120+
-- Find the canonicalized absolute location for a path using a cache object for
121+
-- already resolved paths.
122+
--
123+
realpath' :: forall eff cache. FilePath
124+
-> { | cache }
125+
-> Aff (fs :: F.FS | eff) FilePath
126+
realpath' = toAff2 A.realpath'
127+
128+
-- |
129+
-- Deletes a file.
130+
--
131+
unlink :: forall eff. FilePath
132+
-> Aff (fs :: F.FS | eff) Unit
133+
unlink = toAff1 A.unlink
134+
135+
-- |
136+
-- Deletes a directory.
137+
--
138+
rmdir :: forall eff. FilePath
139+
-> Aff (fs :: F.FS | eff) Unit
140+
rmdir = toAff1 A.rmdir
141+
142+
-- |
143+
-- Makes a new directory.
144+
--
145+
mkdir :: forall eff. FilePath
146+
-> Aff (fs :: F.FS | eff) Unit
147+
mkdir = toAff1 A.mkdir
148+
149+
-- |
150+
-- Makes a new directory with the specified permissions.
151+
--
152+
mkdir' :: forall eff. FilePath
153+
-> Perms
154+
-> Aff (fs :: F.FS | eff) Unit
155+
mkdir' = toAff2 A.mkdir'
156+
157+
-- |
158+
-- Reads the contents of a directory.
159+
--
160+
readdir :: forall eff. FilePath
161+
-> Aff (fs :: F.FS | eff) [FilePath]
162+
readdir = toAff1 A.readdir
163+
164+
--|
165+
-- Sets the accessed and modified times for the specified file.
166+
--
167+
utimes :: forall eff. FilePath
168+
-> Date
169+
-> Date
170+
-> Aff (fs :: F.FS | eff) Unit
171+
utimes = toAff3 A.utimes
172+
173+
-- |
174+
-- Reads the entire contents of a file returning the result as a raw buffer.
175+
--
176+
readFile :: forall eff. FilePath
177+
-> Aff (fs :: F.FS | eff) Buffer
178+
readFile = toAff1 A.readFile
179+
180+
-- |
181+
-- Reads the entire contents of a text file with the specified encoding.
182+
--
183+
readTextFile :: forall eff. Encoding
184+
-> FilePath
185+
-> Aff (fs :: F.FS | eff) String
186+
readTextFile = toAff2 A.readTextFile
187+
188+
-- |
189+
-- Writes a buffer to a file.
190+
--
191+
writeFile :: forall eff. FilePath
192+
-> Buffer
193+
-> Aff (fs :: F.FS | eff) Unit
194+
writeFile = toAff2 A.writeFile
195+
196+
-- |
197+
-- Writes text to a file using the specified encoding.
198+
--
199+
writeTextFile :: forall eff. Encoding
200+
-> FilePath
201+
-> String
202+
-> Aff (fs :: F.FS | eff) Unit
203+
writeTextFile = toAff3 A.writeTextFile
204+
205+
-- |
206+
-- Appends the contents of a buffer to a file.
207+
--
208+
appendFile :: forall eff. FilePath
209+
-> Buffer
210+
-> Aff (fs :: F.FS | eff) Unit
211+
appendFile = toAff2 A.appendFile
212+
213+
-- |
214+
-- Appends text to a file using the specified encoding.
215+
--
216+
appendTextFile :: forall eff. Encoding
217+
-> FilePath
218+
-> String
219+
-> Aff (fs :: F.FS | eff) Unit
63220
appendTextFile = toAff3 A.appendTextFile
64221

65222
-- |
66223
-- Patch `Node.FS.Async.exists`
67224
--
68225
import Data.Function
69226
foreign import fs "var fs = require('fs');" ::
70-
{ exists :: forall a. Fn2 String (Boolean -> a) Unit }
227+
{ exists :: forall a. Fn2 FilePath (Boolean -> a) Unit }
71228

72-
exists :: forall e. String -> Aff (fs :: F.FS | e) Boolean
229+
exists :: forall eff. String
230+
-> Aff (fs :: F.FS | eff) Boolean
73231
exists file = makeAff \_ a -> pure $ runFn2 fs.exists file a

0 commit comments

Comments
 (0)