-
Notifications
You must be signed in to change notification settings - Fork 25
Use stricter types for path creation #466
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
Conversation
@@ -13,6 +13,10 @@ | |||
- Adds `program.accountDID(username)` shorthand method to retrieve the root DID of a given account username. | |||
- Adds the file system data functions as shorthand methods. | |||
|
|||
#### Other | |||
|
|||
- Introduces stricter types for paths to restrict the paths you can use with various functions and also to guide you a bit more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put this here since it shouldn't be a breaking change.
Unless you've been using the file system incorrectly 🙈
(): DirectoryPath | ||
(path: DirectoryPath): DirectoryPath | ||
(path: FilePath): FilePath | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to remove this, leftovers from 0.34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woot! 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 🎉
I left a couple of comments around where the types might be too restrictive or not restrictive enough, and one naming thing.
Love how the LSP suggests "public" or "private". Nice added bonus. ❤️
get(path: DistinctivePath): Promise<PuttableUnixTree | File | null> | ||
mv(from: DistinctivePath, to: DistinctivePath): Promise<this> | ||
rm(path: DistinctivePath): Promise<this> | ||
exists(path: DistinctivePath<PartitionedNonEmpty<Partition>>): Promise<boolean> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the public
and private
partitions guaranteed to exist? Is there any time that a developer would need to check for them? If so, this type may prevent them from doing so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The partitions are guaranteed to exist yeah.
|
||
// Files | ||
write( | ||
path: DistinctivePath, | ||
path: DistinctivePath<PartitionedNonEmpty<Partition>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be restricted further to a FilePath
? Are there cases where it is possible to write to a directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't no. Since we've removed add
and only kept write
, we had to move the functionality from add
to write
. You can add symlinks to a directory with write
, so we'll need directory and file paths. Actually now that I think about this, this shouldn't be NonEmpty
, because you can add symlinks to just private/
Co-authored-by: Brian Ginsburg <7957636+bgins@users.noreply.github.com> Signed-off-by: Steven Vandevelde <icid.asset@gmail.com>
This restricts the paths that can be used with the file system POSIX interface. For example,
fs.write
now requires a file path that starts with"private"
or"public"
and must have at least one more path segment.The other neat thing about this is when you start writing the following in your editor with the Typescript LSP:
It'll suggest
"private"
or"public"
so people don't have to guess anymore what to type in there as the first item.Further notes
Branch
has been renamed toRootBranch
Partition
s which areRootBranch
es that can be used the POSIX file system interface.RootBranch
enum to provide string values, for the people that prefer to use a constant.Thoughts?
How to write these types by hand
Closes
Closes #457