Skip to content

Commit b825520

Browse files
committed
feat(node): support for fs.opendir[Sync]
feat(node): implement `fs.Dir` feat(node): implement `fs.Dirent` feat(node): implement `fs.opendir` feat(node): implement `fs.opendirSync` feat(node): implement `fs/promises.opendir` test(node): tests for `fs.opendir` and friends test(node): test for `fs/promises.opendir` chore: update `graalvm` api pins Signed-off-by: Sam Gammon <sam@elide.dev>
1 parent 20351b4 commit b825520

File tree

12 files changed

+1195
-15
lines changed

12 files changed

+1195
-15
lines changed

packages/graalvm/api/graalvm.api

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3842,6 +3842,14 @@ public abstract interface class elide/runtime/intrinsics/js/node/WritableFilesys
38423842
public abstract fun mkdirSync (Lorg/graalvm/polyglot/Value;)Ljava/lang/String;
38433843
public abstract fun mkdirSync (Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)Ljava/lang/String;
38443844
public static synthetic fun mkdirSync$default (Lelide/runtime/intrinsics/js/node/WritableFilesystemAPI;Lelide/runtime/intrinsics/js/node/path/Path;Lelide/runtime/intrinsics/js/node/fs/MkdirOptions;ILjava/lang/Object;)Ljava/lang/String;
3845+
public abstract fun opendir (Lelide/runtime/intrinsics/js/node/path/Path;Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;Lkotlin/jvm/functions/Function2;)V
3846+
public abstract fun opendir (Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)V
3847+
public static synthetic fun opendir$default (Lelide/runtime/intrinsics/js/node/WritableFilesystemAPI;Lelide/runtime/intrinsics/js/node/path/Path;Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
3848+
public static synthetic fun opendir$default (Lelide/runtime/intrinsics/js/node/WritableFilesystemAPI;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;ILjava/lang/Object;)V
3849+
public abstract fun opendirSync (Lelide/runtime/intrinsics/js/node/path/Path;Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;)Lelide/runtime/node/fs/Directory;
3850+
public abstract fun opendirSync (Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)Lelide/runtime/node/fs/Directory;
3851+
public static synthetic fun opendirSync$default (Lelide/runtime/intrinsics/js/node/WritableFilesystemAPI;Lelide/runtime/intrinsics/js/node/path/Path;Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;ILjava/lang/Object;)Lelide/runtime/node/fs/Directory;
3852+
public static synthetic fun opendirSync$default (Lelide/runtime/intrinsics/js/node/WritableFilesystemAPI;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;ILjava/lang/Object;)Lelide/runtime/node/fs/Directory;
38453853
public abstract fun writeFile (Lelide/runtime/intrinsics/js/node/path/Path;Ljava/lang/String;Lelide/runtime/intrinsics/js/node/fs/WriteFileOptions;Lkotlin/jvm/functions/Function1;)V
38463854
public abstract fun writeFile (Lelide/runtime/intrinsics/js/node/path/Path;[BLelide/runtime/intrinsics/js/node/fs/WriteFileOptions;Lkotlin/jvm/functions/Function1;)V
38473855
public abstract fun writeFile (Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)V
@@ -3865,6 +3873,10 @@ public abstract interface class elide/runtime/intrinsics/js/node/WritableFilesys
38653873
public abstract fun mkdir (Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/JsPromise;
38663874
public abstract fun mkdir (Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/JsPromise;
38673875
public static synthetic fun mkdir$default (Lelide/runtime/intrinsics/js/node/WritableFilesystemPromiseAPI;Lelide/runtime/intrinsics/js/node/path/Path;Lelide/runtime/intrinsics/js/node/fs/MkdirOptions;ILjava/lang/Object;)Lelide/runtime/intrinsics/js/JsPromise;
3876+
public abstract fun opendir (Lelide/runtime/intrinsics/js/node/path/Path;Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;)Lelide/runtime/intrinsics/js/JsPromise;
3877+
public abstract fun opendir (Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/JsPromise;
3878+
public static synthetic fun opendir$default (Lelide/runtime/intrinsics/js/node/WritableFilesystemPromiseAPI;Lelide/runtime/intrinsics/js/node/path/Path;Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;ILjava/lang/Object;)Lelide/runtime/intrinsics/js/JsPromise;
3879+
public static synthetic fun opendir$default (Lelide/runtime/intrinsics/js/node/WritableFilesystemPromiseAPI;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;ILjava/lang/Object;)Lelide/runtime/intrinsics/js/JsPromise;
38683880
public abstract fun writeFile (Lelide/runtime/intrinsics/js/node/path/Path;Ljava/lang/Object;Lelide/runtime/intrinsics/js/node/fs/WriteFileOptions;)Lelide/runtime/intrinsics/js/JsPromise;
38693881
public abstract fun writeFile (Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/JsPromise;
38703882
public abstract fun writeFile (Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/JsPromise;
@@ -4597,10 +4609,25 @@ public final class elide/runtime/intrinsics/js/node/events/RemoveEventListenerOp
45974609
public final fun getDEFAULTS ()Lelide/runtime/intrinsics/js/node/events/RemoveEventListenerOptions;
45984610
}
45994611

4600-
public abstract interface class elide/runtime/intrinsics/js/node/fs/Dir {
4612+
public abstract interface class elide/runtime/intrinsics/js/node/fs/Dir : elide/runtime/interop/ReadOnlyProxyObject, java/lang/AutoCloseable, org/graalvm/polyglot/proxy/ProxyIterable {
4613+
public abstract fun close (Lkotlin/jvm/functions/Function0;)V
4614+
public abstract fun close (Lorg/graalvm/polyglot/Value;)V
4615+
public abstract fun closeSync ()V
4616+
public abstract fun getPath ()Ljava/lang/String;
4617+
public abstract fun read (Lorg/graalvm/polyglot/Value;)V
4618+
public abstract fun readSync ()Lelide/runtime/intrinsics/js/node/fs/Dirent;
46014619
}
46024620

4603-
public abstract interface class elide/runtime/intrinsics/js/node/fs/Dirent {
4621+
public abstract interface class elide/runtime/intrinsics/js/node/fs/Dirent : elide/runtime/interop/ReadOnlyProxyObject {
4622+
public abstract fun getName ()Ljava/lang/String;
4623+
public abstract fun getParentPath ()Ljava/lang/String;
4624+
public abstract fun isBlockDevice ()Z
4625+
public abstract fun isCharacterDevice ()Z
4626+
public abstract fun isDirectory ()Z
4627+
public abstract fun isFIFO ()Z
4628+
public abstract fun isFile ()Z
4629+
public abstract fun isSocket ()Z
4630+
public abstract fun isSymbolicLink ()Z
46044631
}
46054632

46064633
public abstract interface class elide/runtime/intrinsics/js/node/fs/FSWatcher {
@@ -4631,6 +4658,30 @@ public final class elide/runtime/intrinsics/js/node/fs/MkdirOptions$Companion {
46314658
public final fun getDEFAULTS ()Lelide/runtime/intrinsics/js/node/fs/MkdirOptions;
46324659
}
46334660

4661+
public final class elide/runtime/intrinsics/js/node/fs/OpenDirOptions {
4662+
public static final field Companion Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions$Companion;
4663+
public fun <init> ()V
4664+
public fun <init> (Ljava/lang/Object;Ljava/lang/Integer;Z)V
4665+
public synthetic fun <init> (Ljava/lang/Object;Ljava/lang/Integer;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
4666+
public final fun component1 ()Ljava/lang/Object;
4667+
public final fun component2 ()Ljava/lang/Integer;
4668+
public final fun component3 ()Z
4669+
public final fun copy (Ljava/lang/Object;Ljava/lang/Integer;Z)Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;
4670+
public static synthetic fun copy$default (Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;Ljava/lang/Object;Ljava/lang/Integer;ZILjava/lang/Object;)Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;
4671+
public fun equals (Ljava/lang/Object;)Z
4672+
public static final fun from (Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;
4673+
public final fun getBufferSize ()Ljava/lang/Integer;
4674+
public final fun getEncoding ()Ljava/lang/Object;
4675+
public final fun getRecursive ()Z
4676+
public fun hashCode ()I
4677+
public fun toString ()Ljava/lang/String;
4678+
}
4679+
4680+
public final class elide/runtime/intrinsics/js/node/fs/OpenDirOptions$Companion {
4681+
public final fun from (Lorg/graalvm/polyglot/Value;)Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;
4682+
public final fun getDEFAULTS ()Lelide/runtime/intrinsics/js/node/fs/OpenDirOptions;
4683+
}
4684+
46344685
public final class elide/runtime/intrinsics/js/node/fs/ReadFileOptions {
46354686
public static final field Companion Lelide/runtime/intrinsics/js/node/fs/ReadFileOptions$Companion;
46364687
public fun <init> ()V
@@ -8162,6 +8213,81 @@ public synthetic class elide/runtime/node/fs/$VfsInitializerListener$Definition
81628213
public fun load ()Lio/micronaut/inject/BeanDefinition;
81638214
}
81648215

8216+
public final class elide/runtime/node/fs/Directory : elide/runtime/intrinsics/js/node/fs/Dir {
8217+
public static final field Factory Lelide/runtime/node/fs/Directory$Factory;
8218+
public synthetic fun <init> (Ljava/io/File;Ljava/lang/String;Ljava/nio/file/DirectoryStream;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
8219+
public fun close ()V
8220+
public fun close (Lkotlin/jvm/functions/Function0;)V
8221+
public fun close (Lorg/graalvm/polyglot/Value;)V
8222+
public fun closeSync ()V
8223+
public synthetic fun getIterator ()Ljava/lang/Object;
8224+
public fun getIterator ()Lorg/graalvm/polyglot/proxy/ProxyIterator;
8225+
public fun getMember (Ljava/lang/String;)Ljava/lang/Object;
8226+
public synthetic fun getMemberKeys ()Ljava/lang/Object;
8227+
public fun getMemberKeys ()[Ljava/lang/String;
8228+
public fun getPath ()Ljava/lang/String;
8229+
public static final fun of (Ljava/io/File;Ljava/nio/file/Path;)Lelide/runtime/node/fs/Directory;
8230+
public fun read (Lorg/graalvm/polyglot/Value;)V
8231+
public fun readSync ()Lelide/runtime/intrinsics/js/node/fs/Dirent;
8232+
public static final fun wrap (Ljava/io/File;Ljava/nio/file/DirectoryStream;)Lelide/runtime/node/fs/Directory;
8233+
}
8234+
8235+
public final class elide/runtime/node/fs/Directory$Factory : org/graalvm/polyglot/proxy/ProxyInstantiable {
8236+
public fun newInstance ([Lorg/graalvm/polyglot/Value;)Ljava/lang/Object;
8237+
public final fun of (Ljava/io/File;Ljava/nio/file/Path;)Lelide/runtime/node/fs/Directory;
8238+
public final fun wrap (Ljava/io/File;Ljava/nio/file/DirectoryStream;)Lelide/runtime/node/fs/Directory;
8239+
}
8240+
8241+
public abstract interface class elide/runtime/node/fs/DirectoryEntry : elide/runtime/intrinsics/js/node/fs/Dirent {
8242+
public static final field Factory Lelide/runtime/node/fs/DirectoryEntry$Factory;
8243+
public static fun forFile (Ljava/io/File;)Lelide/runtime/node/fs/DirectoryEntry$FileEntry;
8244+
public static fun forPath (Ljava/nio/file/Path;)Lelide/runtime/node/fs/DirectoryEntry$PathEntry;
8245+
public fun getMember (Ljava/lang/String;)Ljava/lang/Object;
8246+
public synthetic fun getMemberKeys ()Ljava/lang/Object;
8247+
public fun getMemberKeys ()[Ljava/lang/String;
8248+
}
8249+
8250+
public final class elide/runtime/node/fs/DirectoryEntry$Factory : org/graalvm/polyglot/proxy/ProxyInstantiable {
8251+
public final fun forFile (Ljava/io/File;)Lelide/runtime/node/fs/DirectoryEntry$FileEntry;
8252+
public final fun forPath (Ljava/nio/file/Path;)Lelide/runtime/node/fs/DirectoryEntry$PathEntry;
8253+
public fun newInstance ([Lorg/graalvm/polyglot/Value;)Ljava/lang/Object;
8254+
}
8255+
8256+
public final class elide/runtime/node/fs/DirectoryEntry$FileEntry : elide/runtime/node/fs/DirectoryEntry {
8257+
public synthetic fun <init> (Ljava/io/File;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
8258+
public final fun getFile ()Ljava/io/File;
8259+
public fun getName ()Ljava/lang/String;
8260+
public fun getParentPath ()Ljava/lang/String;
8261+
public fun isBlockDevice ()Z
8262+
public fun isCharacterDevice ()Z
8263+
public fun isDirectory ()Z
8264+
public fun isFIFO ()Z
8265+
public fun isFile ()Z
8266+
public fun isSocket ()Z
8267+
public fun isSymbolicLink ()Z
8268+
public static final fun of (Ljava/io/File;)Lelide/runtime/node/fs/DirectoryEntry$FileEntry;
8269+
}
8270+
8271+
public final class elide/runtime/node/fs/DirectoryEntry$PathEntry : elide/runtime/node/fs/DirectoryEntry {
8272+
public synthetic fun <init> (Ljava/nio/file/Path;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
8273+
public fun getName ()Ljava/lang/String;
8274+
public fun getParentPath ()Ljava/lang/String;
8275+
public final fun getPath ()Ljava/nio/file/Path;
8276+
public fun isBlockDevice ()Z
8277+
public fun isCharacterDevice ()Z
8278+
public fun isDirectory ()Z
8279+
public fun isFIFO ()Z
8280+
public fun isFile ()Z
8281+
public fun isSocket ()Z
8282+
public fun isSymbolicLink ()Z
8283+
public static final fun of (Ljava/nio/file/Path;)Lelide/runtime/node/fs/DirectoryEntry$PathEntry;
8284+
}
8285+
8286+
public final class elide/runtime/node/fs/DirectoryEntryKt {
8287+
public static final fun asDirectoryEntry (Ljava/io/File;)Lelide/runtime/node/fs/DirectoryEntry$FileEntry;
8288+
public static final fun asDirectoryEntry (Ljava/nio/file/Path;)Lelide/runtime/node/fs/DirectoryEntry$PathEntry;
8289+
}
8290+
81658291
public final class elide/runtime/node/fs/VfsInitializerListener : elide/runtime/plugins/vfs/VfsListener, java/util/function/Supplier {
81668292
public fun <init> ()V
81678293
public fun get ()Lelide/runtime/vfs/GuestVFS;

packages/graalvm/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ graalvmNative {
423423
classpath(tasks.compileJava, tasks.compileKotlin, configurations.nativeImageClasspath)
424424

425425
buildArgs(sharedLibArgs.plus(listOf(
426-
// "-H:LayerUse=${baseLayer.get().asFile.absolutePath}",
427426
"-H:LayerCreate=${layerOut.get().asFile.name}"
428427
)))
429428
}
@@ -432,6 +431,7 @@ graalvmNative {
432431
fallback = false
433432
sharedLibrary = false
434433
quickBuild = true
434+
jvmArgs("-Dpolyglot.engine.WarnInterpreterOnly=false")
435435
buildArgs(sharedLibArgs.plus(testLibArgs).plus(listOf(
436436
"--features=org.graalvm.junit.platform.JUnitPlatformFeature",
437437
)))

packages/graalvm/src/main/kotlin/elide/runtime/intrinsics/js/node/FilesystemAPI.kt

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Elide Technologies, Inc.
2+
* Copyright (c) 2024-2025 Elide Technologies, Inc.
33
*
44
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
55
* with the License. You may obtain a copy of the License at
@@ -17,6 +17,7 @@ import java.nio.file.AccessMode
1717
import elide.annotations.API
1818
import elide.runtime.intrinsics.js.node.fs.*
1919
import elide.runtime.intrinsics.js.node.path.Path
20+
import elide.runtime.node.fs.Directory
2021
import elide.vm.annotations.Polyglot
2122

2223
/**
@@ -512,6 +513,80 @@ import elide.vm.annotations.Polyglot
512513
* @param dest The destination path to copy to.
513514
*/
514515
@Polyglot public fun copyFileSync(src: Value, dest: Value)
516+
517+
/**
518+
* ## Method: `fs.opendir`
519+
*
520+
* Asynchronously open a directory at the provided [path], employing the provided [options]; a `Dir` instance is
521+
* passed to the provided [callback] for directory operations.
522+
*
523+
* From the Node.js docs:
524+
* "Asynchronously open a directory. See the POSIX `opendir(3)` documentation for more details. Creates an `fs.Dir`,
525+
* which contains all further functions for reading from and cleaning up the directory. The `encoding` option sets the
526+
* encoding for the path while opening the directory and subsequent read operations."
527+
*
528+
* This method variant is meant for implementation and host-side dispatch.
529+
*
530+
* @param path Path to the directory to open.
531+
* @param options Options to apply to the operation.
532+
* @param callback Callback function to invoke with the directory iterator.
533+
*/
534+
@Polyglot public fun opendir(path: Path, options: OpenDirOptions = OpenDirOptions.DEFAULTS, callback: OpenDirCallback)
535+
536+
/**
537+
* ## Method: `fs.opendir`
538+
*
539+
* Asynchronously open a directory at the provided [path], employing the provided [options]; a `Dir` instance is
540+
* passed to the provided [callback] for directory operations.
541+
*
542+
* From the Node.js docs:
543+
* "Asynchronously open a directory. See the POSIX `opendir(3)` documentation for more details. Creates an `fs.Dir`,
544+
* which contains all further functions for reading from and cleaning up the directory. The `encoding` option sets the
545+
* encoding for the path while opening the directory and subsequent read operations."
546+
*
547+
* This method variant is meant for guest-side dispatch.
548+
*
549+
* @param path Path to the directory to open.
550+
* @param options Options to apply to the operation.
551+
* @param callback Callback function to invoke with the directory iterator.
552+
*/
553+
@Polyglot public fun opendir(path: Value, options: Value? = null, callback: Value)
554+
555+
/**
556+
* ## Method: `fs.opendirSync`
557+
*
558+
* Synchronously open a directory at the provided [path], employing the provided [options].
559+
*
560+
* From the Node.js docs:
561+
* "Synchronously open a directory. See `opendir(3)`. Creates an `fs.Dir`, which contains all further functions for
562+
* reading from and cleaning up the directory. The encoding option sets the encoding for the path while opening the
563+
* directory and subsequent read operations."
564+
*
565+
* This method variant is meant for implementation and host-side dispatch.
566+
*
567+
* @param path Path to the directory to open.
568+
* @param options Options to apply to the operation.
569+
* @return [Directory] handle instance.
570+
*/
571+
@Polyglot public fun opendirSync(path: Path, options: OpenDirOptions = OpenDirOptions.DEFAULTS): Directory
572+
573+
/**
574+
* ## Method: `fs.opendirSync`
575+
*
576+
* Synchronously open a directory at the provided [path], employing the provided [options], if any.
577+
*
578+
* From the Node.js docs:
579+
* "Synchronously open a directory. See `opendir(3)`. Creates an `fs.Dir`, which contains all further functions for
580+
* reading from and cleaning up the directory. The encoding option sets the encoding for the path while opening the
581+
* directory and subsequent read operations."
582+
*
583+
* This method variant is meant for guest-side dispatch.
584+
*
585+
* @param path Path to the directory to open.
586+
* @param options Options to apply to the operation.
587+
* @return [Directory] handle instance.
588+
*/
589+
@Polyglot public fun opendirSync(path: Value, options: Value? = null): Directory
515590
}
516591

517592
/**

packages/graalvm/src/main/kotlin/elide/runtime/intrinsics/js/node/FilesystemPromiseAPI.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Elide Technologies, Inc.
2+
* Copyright (c) 2024-2025 Elide Technologies, Inc.
33
*
44
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
55
* with the License. You may obtain a copy of the License at
@@ -341,6 +341,28 @@ import elide.vm.annotations.Polyglot
341341
* @return Upon success, fulfills with `undefined`; otherwise, rejects with an error.
342342
*/
343343
@Polyglot public fun copyFile(src: Value, dest: Value, mode: Int): JsPromise<Value>
344+
345+
/**
346+
* ## Method: `fs.opendir`
347+
*
348+
* Asynchronously opens a directory for the streaming of entries.
349+
*
350+
* @param path Path to the directory to stream entries for.
351+
* @param options Options to apply to the operation.
352+
* @return Upon success, fulfills with an instance of [Dir]; otherwise, errors.
353+
*/
354+
public fun opendir(path: Path, options: OpenDirOptions? = null): JsPromise<Dir>
355+
356+
/**
357+
* ## Method: `fs.opendir`
358+
*
359+
* Asynchronously opens a directory for the streaming of entries.
360+
*
361+
* @param path Path to the directory to stream entries for.
362+
* @param options Options to apply to the operation.
363+
* @return Upon success, fulfills with an instance of [Dir]; otherwise, errors.
364+
*/
365+
@Polyglot public fun opendir(path: Value, options: Value? = null): JsPromise<Dir>
344366
}
345367

346368
/**

packages/graalvm/src/main/kotlin/elide/runtime/intrinsics/js/node/fs/Dir.kt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Elide Technologies, Inc.
2+
* Copyright (c) 2024-2025 Elide Technologies, Inc.
33
*
44
* Licensed under the MIT license (the "License"); you may not use this file except in compliance
55
* with the License. You may obtain a copy of the License at
@@ -12,10 +12,47 @@
1212
*/
1313
package elide.runtime.intrinsics.js.node.fs
1414

15+
import org.graalvm.polyglot.Value
16+
import org.graalvm.polyglot.proxy.ProxyIterable
1517
import elide.annotations.API
18+
import elide.runtime.interop.ReadOnlyProxyObject
19+
import elide.vm.annotations.Polyglot
1620

1721
/**
18-
*
22+
* ## Node Filesystem: Directory
1923
*/
20-
@API public interface Dir {
24+
@API public interface Dir : AutoCloseable, ProxyIterable, ReadOnlyProxyObject {
25+
/**
26+
* Public access to the original path used to create this instance.
27+
*/
28+
@get:Polyglot public val path: String
29+
30+
/**
31+
* Close the underlying resource for this directory instance, and then invoke the provided [callback].
32+
*
33+
* @param callback Callback to invoke after closing
34+
*/
35+
@Polyglot public fun close(callback: Value)
36+
37+
/**
38+
* Close the underlying resource for this directory instance, and then invoke the provided [callback].
39+
*
40+
* @param callback Callback to invoke after closing
41+
*/
42+
public fun close(callback: () -> Unit)
43+
44+
/**
45+
* Synchronously close underlying file resources.
46+
*/
47+
@Polyglot public fun closeSync()
48+
49+
/**
50+
* Asynchronously read the next directory entry via `readdir(3)` as an instance of [Dirent].
51+
*/
52+
@Polyglot public fun read(callback: Value)
53+
54+
/**
55+
* Synchronously read the next directory entry as an instance of [Dirent].
56+
*/
57+
@Polyglot public fun readSync(): Dirent?
2158
}

0 commit comments

Comments
 (0)