diff --git a/src/js/node/Fs.hx b/src/js/node/Fs.hx index 0fcab4a8..3dd9b839 100644 --- a/src/js/node/Fs.hx +++ b/src/js/node/Fs.hx @@ -491,6 +491,39 @@ typedef FsRmdirOptions = { @:optional var retryDelay:Int; } +typedef FsRmOptions = { + /** + When `true`, exceptions will be ignored if `path` does not exist. + **/ + @:optional + var force:Bool; + + /** + If an `EBUSY`, `EMFILE`, `ENFILE`, `ENOTEMPTY`, or + `EPERM` error is encountered, Node.js will retry the operation with a linear + backoff wait of `retryDelay` ms longer on each try. This option represents the + number of retries. This option is ignored if the `recursive` option is not + `true`. + **/ + @:optional + var maxRetries:Float; + + /** + If `true`, perform a recursive directory removal. In + recursive mode, errors are not reported if `path` does not exist, and + operations are retried on failure. + **/ + @:optional + var recursive:Bool; + + /** + The amount of time in milliseconds to wait between retries. + This option is ignored if the `recursive` option is not `true`. + **/ + @:optional + var retryDelay:Float; +}; + /** File I/O is provided by simple wrappers around standard POSIX functions. All the methods have asynchronous and synchronous forms. diff --git a/src/js/node/fs/Promises.hx b/src/js/node/fs/Promises.hx new file mode 100644 index 00000000..3dbf5af9 --- /dev/null +++ b/src/js/node/fs/Promises.hx @@ -0,0 +1,267 @@ +package js.node.fs; + +import haxe.DynamicAccess; +import js.node.Fs.FsConstants; +import js.node.Fs.FsMode; +import js.node.Fs.FsOpenFlag; +import js.node.Fs.FsPath; +import js.node.Fs.FsRmOptions; +import js.node.Fs.FsRmdirOptions; +import js.node.Fs.SymlinkType; +#if haxe4 +import js.lib.Promise; +#else +import js.Promise; +#end + +@:jsRequire("fs", "promises") +extern class Promises { + /** + Asynchronously tests a user's permissions for the file specified by path. + **/ + static function access(path:FsPath, ?mode:FsConstants):Promise; + + /** + Asynchronously copies `src` to `dest`. By default, `dest` is overwritten if it already exists. + Node.js makes no guarantees about the atomicity of the copy operation. + If an error occurs after the destination file has been opened for writing, Node.js will attempt + to remove the destination. + **/ + static function copyFile(src:FsPath, dest:FsPath, ?flags:FsConstants):Promise; + + /** + * REVIEW i let those with FileHandle i have not think for it + Asynchronous open(2) - open and possibly create a file. + **/ + /* + static function open(path:FsPath, flags:FsOpenFlag, ?mode:FsMode):Promise; + */ + /** + * REVIEW + Asynchronously reads data from the file referenced by the supplied `FileHandle`. + **/ + /* + static function read(handle:node.fs.promises.FileHandle, buffer:TBuffer, ?offset:Float, ?length:Float, ?position:Float):Promise<{ + var bytesRead:Float; + var buffer:TBuffer; + }>; + */ + /** + * REVIEW + Asynchronously writes `buffer` to the file referenced by the supplied `FileHandle`. + It is unsafe to call `fsPromises.write()` multiple times on the same file without waiting for the `Promise` + to be resolved (or rejected). For this scenario, `fs.createWriteStream` is strongly recommended. + + Asynchronously writes `string` to the file referenced by the supplied `FileHandle`. + It is unsafe to call `fsPromises.write()` multiple times on the same file without waiting for the `Promise` + to be resolved (or rejected). For this scenario, `fs.createWriteStream` is strongly recommended. + **/ + /* + @:overload(function(handle:node.fs.promises.FileHandle, string:String, ?position:Float, ?encoding:global.BufferEncoding):Promise<{ + var bytesWritten:Float; + var buffer:String; + }> {}) + static function write(handle:node.fs.promises.FileHandle, buffer:TBuffer, ?offset:Float, ?length:Float, ?position:Float):Promise<{ + var bytesWritten:Float; + var buffer:TBuffer; + }>; + */ + /** + Asynchronous rename(2) - Change the name or location of a file or directory. + **/ + static function rename(oldPath:FsPath, newPath:FsPath):Promise; + + /** + Asynchronous truncate(2) - Truncate a file to a specified length. + **/ + static function truncate(path:FsPath, ?len:Int):Promise; + + /** + * REVIEW i let those with FileHandle i have not think for it + Asynchronous ftruncate(2) - Truncate a file to a specified length. + **/ + /* + static function ftruncate(handle:node.fs.promises.FileHandle, ?len:Float):Promise; + */ + /** + Asynchronous rmdir(2) - delete a directory. + **/ + static function rmdir(path:FsPath, ?options:FsRmdirOptions):Promise; + + /** + REVIEW should add in non promise fs class too ( rm was added in v14 https://nodejs.org/api/fs.html#fs_fs_rm_path_options_callback) + added FsRmOptions in Fs class + Asynchronously removes files and directories (modeled on the standard POSIX `rm` utility). + **/ + static function rm(path:FsPath, ?options:FsRmOptions):Promise; + + /** + * REVIEW i let those with FileHandle i have not think for it + Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device. + **/ + /* + static function fdatasync(handle:node.fs.promises.FileHandle):Promise; + */ + /** + * REVIEW i let those with FileHandle i have not think for it + Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device. + **/ + /* + static function fsync(handle:node.fs.promises.FileHandle):Promise; + */ + /** + REVIEW change depend of pull request #175 + Asynchronous mkdir(2) - create a directory. + **/ + /* + @:overload(function(path:FsPath, ?options:ts.AnyOf3):Promise {}) + @:overload(function(path:FsPath, ?options:ts.AnyOf3):Promise> {}) + static function mkdir(path:FsPath, options:Dynamic):Promise; + */ + /** + Asynchronous readdir(3) - read a directory. + **/ + static function readdir(path:FsPath, ?options:DynamicAccess):Promise>; + + /** + Asynchronous readlink(2) - read value of a symbolic link. + **/ + static function readlink(path:FsPath, ?options:DynamicAccess):Promise; + + /** + Asynchronous symlink(2) - Create a new symbolic link to an existing file. + **/ + static function symlink(target:FsPath, path:FsPath, ?type:SymlinkType):Promise; + + /** + * REVIEW i let those with FileHandle i have not think for it + Asynchronous fstat(2) - Get file status. + **/ + /* + static function fstat(handle:node.fs.promises.FileHandle):Promise; + */ + /** + Asynchronous lstat(2) - Get file status. Does not dereference symbolic links. + **/ + static function lstat(path:FsPath):Promise; + + /** + Asynchronous stat(2) - Get file status. + **/ + static function stat(path:FsPath):Promise; + + /** + Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file. + **/ + static function link(existingPath:FsPath, newPath:FsPath):Promise; + + /** + Asynchronous unlink(2) - delete a name and possibly the file it refers to. + **/ + static function unlink(path:FsPath):Promise; + + /** + * REVIEW i let those with FileHandle i have not think for it + Asynchronous fchmod(2) - Change permissions of a file. + **/ + /* + static function fchmod(handle:node.fs.promises.FileHandle, mode:FsMode):Promise; + */ + /** + Asynchronous chmod(2) - Change permissions of a file. + **/ + static function chmod(path:FsPath, mode:FsMode):Promise; + + /** + Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links. + **/ + static function lchmod(path:FsPath, mode:FsMode):Promise; + + /** + Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links. + **/ + static function lchown(path:FsPath, uid:Float, gid:Float):Promise; + + /** + Changes the access and modification times of a file in the same way as `fsPromises.utimes()`, + with the difference that if the path refers to a symbolic link, then the link is not + dereferenced: instead, the timestamps of the symbolic link itself are changed. + **/ + static function lutimes(path:FsPath, atime:Date, mtime:Date):Promise; + + /** + * REVIEW i let those with FileHandle i have not think for it + Asynchronous fchown(2) - Change ownership of a file. + **/ + /* + static function fchown(handle:node.fs.promises.FileHandle, uid:Float, gid:Float):Promise; + */ + /** + Asynchronous chown(2) - Change ownership of a file. + **/ + static function chown(path:FsPath, uid:Float, gid:Float):Promise; + + /** + Asynchronously change file timestamps of the file referenced by the supplied path. + **/ + static function utimes(path:FsPath, atime:Date, mtime:Date):Promise; + + /** + * REVIEW i let those with FileHandle i have not think for it + Asynchronously change file timestamps of the file referenced by the supplied `FileHandle`. + **/ + /* + static function futimes(handle:node.fs.promises.FileHandle, atime:Date, mtime:Date):Promise; + */ + /** + Asynchronous realpath - return the canonicalized absolute pathname. + **/ + static function realpath(path:FsPath, ?option:DynamicAccess):Promise; + + /** + Asynchronously creates a unique temporary directory. + Generates six random characters to be appended behind a required `prefix` to create a unique temporary directory. + **/ + static function mkdtemp(prefix:String, ?option:DynamicAccess):Promise; + + /** + Asynchronously writes data to a file, replacing the file if it already exists. + It is unsafe to call `fsPromises.writeFile()` multiple times on the same file without waiting for the `Promise` to be resolved (or rejected). + **/ + /* + static function writeFile(path:ts.AnyOf4, data:ts.AnyOf2, + ?options:ts.AnyOf2; + }>):Promise; + */ + /** + Asynchronously append data to a file, creating the file if it does not exist. + **/ + /* + static function appendFile(path:ts.AnyOf4, data:ts.AnyOf2, + ?options:ts.AnyOf2; + }>):Promise; + */ + /** + Asynchronously reads the entire contents of a file. + + Asynchronously reads the entire contents of a file. + + Asynchronously reads the entire contents of a file. + **/ + /* + @:overload(function(path:ts.AnyOf4, + options:ts.AnyOf2;}>):Promise {}) + @:overload(function(path:ts.AnyOf4, + ?options:ts.AnyOf2;}>):Promise> {}) + static function readFile(path:ts.AnyOf4, + ?options:{@:optional var encoding:Any; @:optional var flag:ts.AnyOf2;}):Promise; + */ + /* + REVIEW this method is missing we should consider adding it + static function opendir(path:String, ?options:OpenDirOptions):Promise; + */ +}