From 2973bba942c2fcf743d5ca45d554e8cbede46a2e Mon Sep 17 00:00:00 2001 From: Alex Snezhko Date: Sat, 2 Mar 2024 22:58:49 +0000 Subject: [PATCH] Address review feedback --- .../stdlib/{sys.fs.test.gr => fs.test.gr} | 2 +- stdlib/{sys => }/fs.gr | 22 ++++++++++++++---- stdlib/{sys => }/fs.md | 23 +++++++++++++++++++ stdlib/path.gr | 2 +- 4 files changed, 43 insertions(+), 6 deletions(-) rename compiler/test/stdlib/{sys.fs.test.gr => fs.test.gr} (99%) rename stdlib/{sys => }/fs.gr (98%) rename stdlib/{sys => }/fs.md (95%) diff --git a/compiler/test/stdlib/sys.fs.test.gr b/compiler/test/stdlib/fs.test.gr similarity index 99% rename from compiler/test/stdlib/sys.fs.test.gr rename to compiler/test/stdlib/fs.test.gr index 455a7dd78..d7ff3e956 100644 --- a/compiler/test/stdlib/sys.fs.test.gr +++ b/compiler/test/stdlib/fs.test.gr @@ -1,6 +1,6 @@ module FsTest -from "sys/fs" include Fs +from "fs" include Fs from "path" include Path from "bytes" include Bytes from "result" include Result diff --git a/stdlib/sys/fs.gr b/stdlib/fs.gr similarity index 98% rename from stdlib/sys/fs.gr rename to stdlib/fs.gr index 44617f4cf..35a22a1f1 100644 --- a/stdlib/sys/fs.gr +++ b/stdlib/fs.gr @@ -1,13 +1,20 @@ +/** + * High-level file system interactions. Utilizes WASI Preview 1 for underlying API + * + * @example from "fs" include Fs + * + * @since v0.6.0 + */ module Fs -from "sys/file" include File -from "bytes" include Bytes from "array" include Array +from "bytes" include Bytes +from "int64" include Int64 from "option" include Option -from "result" include Result from "path" include Path -from "int64" include Int64 +from "result" include Result from "string" include String +from "sys/file" include File from "runtime/wasi" include Wasi from "runtime/unsafe/wasmi32" include WasmI32 from "runtime/dataStructures" include DataStructures @@ -194,12 +201,19 @@ provide enum FileType { */ provide record Stats { fileType: FileType, + /** File size in bytes */ size: Number, + /** Last accessed timestamp in nanoseconds */ accessedTimestamp: Number, + /** Last modified timestamp in nanoseconds */ modifiedTimestamp: Number, + /** Last file status change timestamp in nanoseconds */ changedTimestamp: Number, } +/** + * Represents information about an item in a directory + */ provide record DirectoryEntry { name: String, fileType: FileType, diff --git a/stdlib/sys/fs.md b/stdlib/fs.md similarity index 95% rename from stdlib/sys/fs.md rename to stdlib/fs.md index 0d5c3859c..9fd2d5951 100644 --- a/stdlib/sys/fs.md +++ b/stdlib/fs.md @@ -2,6 +2,17 @@ title: Fs --- +High-level file system interactions. Utilizes WASI Preview 1 for underlying API + +
+Added in next +No other changes yet. +
+ +```grain +from "fs" include Fs +``` + ## Types Type declarations included in the Fs module. @@ -129,6 +140,16 @@ record Stats { Represents metadata about a file. +Fields: + +|name|type|description| +|----|----|-----------| +|`fileType`|`FileType`|| +|`size`|`Number`|File size in bytes| +|`accessedTimestamp`|`Number`|Last accessed timestamp in nanoseconds| +|`modifiedTimestamp`|`Number`|Last modified timestamp in nanoseconds| +|`changedTimestamp`|`Number`|Last file status change timestamp in nanoseconds| + ### Fs.**DirectoryEntry** ```grain @@ -138,6 +159,8 @@ record DirectoryEntry { } ``` +Represents information about an item in a directory + ### Fs.**RemoveMode** ```grain diff --git a/stdlib/path.gr b/stdlib/path.gr index e106f5d4b..fa9e506c0 100644 --- a/stdlib/path.gr +++ b/stdlib/path.gr @@ -571,7 +571,7 @@ provide let relativeTo = (source, dest) => { let pathInfo2 = pathInfo(dest) let (base2, _, _) = pathInfo2 match ((base1, base2)) { - (Abs(_), Rel(_)) | (Rel(_), Abs(_)) => Err(Incompatible(DifferentBases)), + (Abs(_), Rel(_)) | (Abs(_), Rel(_)) => Err(Incompatible(DifferentBases)), _ => Result.map(toPath, relativeToHelper(pathInfo1, pathInfo2)), } }