This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 04e632bc4d feat(bindings/nodejs): expose ListOptions glob from core 
(#9414)
04e632bc4d is described below

commit 04e632bc4d80cff1793221f524769557f64e8dfe
Author: Chitral Verma <[email protected]>
AuthorDate: Mon Nov 30 09:06:57 2026 +0530

    feat(bindings/nodejs): expose ListOptions glob from core (#9414)
    
    * feat(bindings/nodejs): expose ListOptions glob from core
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    * docs(bindings/nodejs): describe prefix paths in the list method docs
    
    Signed-off-by: Chitral Verma <[email protected]>
    
    ---------
    
    Signed-off-by: Chitral Verma <[email protected]>
---
 bindings/nodejs/generated.d.ts                     | 36 +++++++++++--
 bindings/nodejs/src/lib.rs                         | 12 +++--
 bindings/nodejs/src/options/list.rs                | 25 ++++++++-
 .../nodejs/tests/list-options-surface.test.mjs     | 10 ++--
 .../nodejs/tests/suites/asyncListOptions.suite.mjs | 15 ++++++
 .../nodejs/tests/suites/syncListOptions.suite.mjs  | 15 ++++++
 dev/src/generate/nodejs.rs                         | 61 ++++++++++++++--------
 7 files changed, 139 insertions(+), 35 deletions(-)

diff --git a/bindings/nodejs/generated.d.ts b/bindings/nodejs/generated.d.ts
index 6bc9c2489d..f04eba6e67 100644
--- a/bindings/nodejs/generated.d.ts
+++ b/bindings/nodejs/generated.d.ts
@@ -784,7 +784,8 @@ export declare class Operator {
    *
    * This function will return an array of entries.
    *
-   * An error will be returned if given path doesn't end with `/`.
+   * A `path` without a trailing `/` is a prefix: the result holds the entries
+   * whose paths start with it, such as `data/sub/cat.txt` for `data/sub/c`.
    *
    * ### Example
    *
@@ -818,7 +819,8 @@ export declare class Operator {
    *
    * This function will return an array of entries.
    *
-   * An error will be returned if given path doesn't end with `/`.
+   * A `path` without a trailing `/` is a prefix: the result holds the entries
+   * whose paths start with it, such as `data/sub/cat.txt` for `data/sub/c`.
    *
    * ### Example
    *
@@ -854,7 +856,8 @@ export declare class Operator {
    * This function returns a Lister that can be used to iterate over entries
    * in a streaming manner, which is more memory-efficient for large 
directories.
    *
-   * An error will be returned if given path doesn't end with `/`.
+   * A `path` without a trailing `/` is a prefix: the result holds the entries
+   * whose paths start with it, such as `data/sub/cat.txt` for `data/sub/c`.
    *
    * ### Example
    *
@@ -885,7 +888,8 @@ export declare class Operator {
    * This function returns a BlockingLister that can be used to iterate over 
entries
    * in a streaming manner, which is more memory-efficient for large 
directories.
    *
-   * An error will be returned if given path doesn't end with `/`.
+   * A `path` without a trailing `/` is a prefix: the result holds the entries
+   * whose paths start with it, such as `data/sub/cat.txt` for `data/sub/c`.
    *
    * ### Example
    *
@@ -1312,6 +1316,30 @@ export interface ListOptions {
    * Requires `Capability.listWithDeleted`.
    */
   deleted?: boolean
+  /**
+   * Filter entries with a case-sensitive Unix shell style glob pattern.
+   *
+   * The pattern is relative to the listed directory, or to the parent
+   * directory when the list path is a prefix without a trailing slash.
+   * Entries must also satisfy the list prefix. The pattern determines which
+   * depths can match, independently of `recursive`.
+   *
+   * - `*` matches zero or more characters within one path component.
+   * - `?` matches one Unicode scalar value within one path component.
+   * - `**` matches zero or more path components and must occupy a whole 
component.
+   * - `{a,b}` matches either alternative within a component.
+   * - `[ab]`, `[a-z]`, and `[!a-z]` match character sets, ranges, and negated 
sets.
+   * - A backslash escapes the next character within a component.
+   * - A trailing slash restricts matches to directories.
+   *
+   * Requires `Capability.listWithGlob`. Services with native glob
+   * support handle patterns directly; otherwise OpenDAL evaluates
+   * patterns client-side. Combining a multi-directory pattern with
+   * `startAfter`, `versions`, or `deleted` during client-side simulation
+   * also requires `Capability.listWithRecursive`.
+   * Empty or malformed patterns fail with an error whose message includes 
`ConfigInvalid`.
+   */
+  glob?: string
 }
 
 /** PresignedRequest is a presigned request return by `presign`. */
diff --git a/bindings/nodejs/src/lib.rs b/bindings/nodejs/src/lib.rs
index 22fe52ad7a..ef66d25c49 100644
--- a/bindings/nodejs/src/lib.rs
+++ b/bindings/nodejs/src/lib.rs
@@ -655,7 +655,8 @@ impl Operator {
     ///
     /// This function will return an array of entries.
     ///
-    /// An error will be returned if given path doesn't end with `/`.
+    /// A `path` without a trailing `/` is a prefix: the result holds the 
entries
+    /// whose paths start with it, such as `data/sub/cat.txt` for `data/sub/c`.
     ///
     /// ### Example
     ///
@@ -706,7 +707,8 @@ impl Operator {
     ///
     /// This function will return an array of entries.
     ///
-    /// An error will be returned if given path doesn't end with `/`.
+    /// A `path` without a trailing `/` is a prefix: the result holds the 
entries
+    /// whose paths start with it, such as `data/sub/cat.txt` for `data/sub/c`.
     ///
     /// ### Example
     ///
@@ -754,7 +756,8 @@ impl Operator {
     /// This function returns a Lister that can be used to iterate over entries
     /// in a streaming manner, which is more memory-efficient for large 
directories.
     ///
-    /// An error will be returned if given path doesn't end with `/`.
+    /// A `path` without a trailing `/` is a prefix: the result holds the 
entries
+    /// whose paths start with it, such as `data/sub/cat.txt` for `data/sub/c`.
     ///
     /// ### Example
     ///
@@ -804,7 +807,8 @@ impl Operator {
     /// This function returns a BlockingLister that can be used to iterate 
over entries
     /// in a streaming manner, which is more memory-efficient for large 
directories.
     ///
-    /// An error will be returned if given path doesn't end with `/`.
+    /// A `path` without a trailing `/` is a prefix: the result holds the 
entries
+    /// whose paths start with it, such as `data/sub/cat.txt` for `data/sub/c`.
     ///
     /// ### Example
     ///
diff --git a/bindings/nodejs/src/options/list.rs 
b/bindings/nodejs/src/options/list.rs
index 927b2cea79..cc8362fb6a 100644
--- a/bindings/nodejs/src/options/list.rs
+++ b/bindings/nodejs/src/options/list.rs
@@ -52,6 +52,29 @@ pub struct ListOptions {
     ///
     /// Requires `Capability.listWithDeleted`.
     pub deleted: Option<bool>,
+
+    /// Filter entries with a case-sensitive Unix shell style glob pattern.
+    ///
+    /// The pattern is relative to the listed directory, or to the parent
+    /// directory when the list path is a prefix without a trailing slash.
+    /// Entries must also satisfy the list prefix. The pattern determines which
+    /// depths can match, independently of `recursive`.
+    ///
+    /// - `*` matches zero or more characters within one path component.
+    /// - `?` matches one Unicode scalar value within one path component.
+    /// - `**` matches zero or more path components and must occupy a whole 
component.
+    /// - `{a,b}` matches either alternative within a component.
+    /// - `[ab]`, `[a-z]`, and `[!a-z]` match character sets, ranges, and 
negated sets.
+    /// - A backslash escapes the next character within a component.
+    /// - A trailing slash restricts matches to directories.
+    ///
+    /// Requires `Capability.listWithGlob`. Services with native glob
+    /// support handle patterns directly; otherwise OpenDAL evaluates
+    /// patterns client-side. Combining a multi-directory pattern with
+    /// `startAfter`, `versions`, or `deleted` during client-side simulation
+    /// also requires `Capability.listWithRecursive`.
+    /// Empty or malformed patterns fail with an error whose message includes 
`ConfigInvalid`.
+    pub glob: Option<String>,
 }
 
 impl From<ListOptions> for opendal::options::ListOptions {
@@ -62,7 +85,7 @@ impl From<ListOptions> for opendal::options::ListOptions {
             recursive: value.recursive.unwrap_or_default(),
             versions: value.versions.unwrap_or_default(),
             deleted: value.deleted.unwrap_or_default(),
-            glob: Default::default(),
+            glob: value.glob,
         }
     }
 }
diff --git a/bindings/nodejs/tests/list-options-surface.test.mjs 
b/bindings/nodejs/tests/list-options-surface.test.mjs
index 1aaa1681ec..27df18add6 100644
--- a/bindings/nodejs/tests/list-options-surface.test.mjs
+++ b/bindings/nodejs/tests/list-options-surface.test.mjs
@@ -24,17 +24,17 @@ import { assert, describe, test } from 'vitest'
 
 import { Operator } from '../index.mjs'
 
-// `ListOptions` and the list methods as `generated.d.ts` declared them before
-// `ListOptions` was generated from core. Callers pass these options as object
-// literals or implement the interface structurally, so each member must stay
-// with its type and stay optional, and a new member must be added here on
-// purpose.
+// `ListOptions` and the list methods as `generated.d.ts` declares them.
+// Callers pass these options as object literals or implement the interface
+// structurally, so each member must stay with its type and stay optional, and
+// a new member must be added here on purpose.
 const FROZEN_MEMBERS = [
   'limit?: number',
   'startAfter?: string',
   'recursive?: boolean',
   'versions?: boolean',
   'deleted?: boolean',
+  'glob?: string',
 ]
 
 const FROZEN_SIGNATURES = [
diff --git a/bindings/nodejs/tests/suites/asyncListOptions.suite.mjs 
b/bindings/nodejs/tests/suites/asyncListOptions.suite.mjs
index dfae63300a..043dd5b4f4 100644
--- a/bindings/nodejs/tests/suites/asyncListOptions.suite.mjs
+++ b/bindings/nodejs/tests/suites/asyncListOptions.suite.mjs
@@ -99,6 +99,21 @@ export function run(op, scheme) {
         await op.removeAll(dirname)
       })
 
+      test.runIf(capability.listWithGlob)('list with glob', async () => {
+        const dirname = `random_dir_${randomUUID()}/`
+        await op.createDir(dirname)
+
+        const given = ['a.txt', 'b.log', 'sub/c.txt']
+        for (const entry of given) {
+          await op.write(path.join(dirname, entry), 'content')
+        }
+
+        const lists = await op.list(dirname, { glob: '*.txt' })
+        expect(lists.map((item) => item.path())).toEqual([path.join(dirname, 
'a.txt')])
+
+        await op.removeAll(dirname)
+      })
+
       test.runIf(capability.listWithVersions)('list with versions', async () 
=> {
         const dirname = `random_dir_${randomUUID()}/`
 
diff --git a/bindings/nodejs/tests/suites/syncListOptions.suite.mjs 
b/bindings/nodejs/tests/suites/syncListOptions.suite.mjs
index 189a4c7bd2..eaff5f55d0 100644
--- a/bindings/nodejs/tests/suites/syncListOptions.suite.mjs
+++ b/bindings/nodejs/tests/suites/syncListOptions.suite.mjs
@@ -99,6 +99,21 @@ export function run(op, scheme) {
         op.removeAllSync(dirname)
       })
 
+      test.runIf(capability.listWithGlob)('list with glob', () => {
+        const dirname = `random_dir_${randomUUID()}/`
+        op.createDirSync(dirname)
+
+        const given = ['a.txt', 'b.log', 'sub/c.txt']
+        for (const entry of given) {
+          op.writeSync(path.join(dirname, entry), 'content')
+        }
+
+        const lists = op.listSync(dirname, { glob: '*.txt' })
+        expect(lists.map((item) => item.path())).toEqual([path.join(dirname, 
'a.txt')])
+
+        op.removeAllSync(dirname)
+      })
+
       test.runIf(capability.listWithVersions)('list with versions', () => {
         const dirname = `random_dir_${randomUUID()}/`
 
diff --git a/dev/src/generate/nodejs.rs b/dev/src/generate/nodejs.rs
index 84a947e9d5..17ace3090c 100644
--- a/dev/src/generate/nodejs.rs
+++ b/dev/src/generate/nodejs.rs
@@ -251,10 +251,19 @@ const LIST_OPTIONS: JsOptions = JsOptions {
         ("recursive", Js::Bool),
         ("versions", Js::Bool),
         ("deleted", Js::Bool),
+        ("glob", Js::String),
     ],
     renamed: &[],
     docs: &[],
-    rewrites: &[],
+    // The Node.js binding enables core's default `auto-simulate` feature.
+    rewrites: &[(
+        concat!(
+            "otherwise `crate::layers::SimulateLayer`\n",
+            "(installed automatically by the default `auto-simulate` feature) 
evaluates\n",
+            "patterns client-side.",
+        ),
+        "otherwise OpenDAL evaluates\npatterns client-side.",
+    )],
 };
 
 const STAT_OPTIONS: JsOptions = JsOptions {
@@ -788,7 +797,7 @@ fn js_doc(lines: &[String], options: &JsOptions, 
capabilities: &[CapabilityField
         }
     }
 
-    for kind in ["NotFound", "ConditionNotMatch", "Conflict"] {
+    for kind in ["NotFound", "ConditionNotMatch", "Conflict", "ConfigInvalid"] 
{
         let reference = format!("`crate::ErrorKind::{kind}`");
         let error = format!("an error whose message includes `{kind}`");
         doc = doc
@@ -840,9 +849,9 @@ fn render_crate_reference_links(line: &str) -> String {
 /// or `None` to keep the code span as written.
 ///
 /// napi-rs exposes snake_case Rust names in lower camel case, so an exposed
-/// field of these options like `start_after` or `ListOptions::start_after`
-/// reads `startAfter`, a renamed one like the read `override_content_type`
-/// reads `contentType`, and a core capability like
+/// field of these options like `start_after`, `ListOptions::start_after`, or
+/// `Self::start_after` reads `startAfter`, a renamed one like the read
+/// `override_content_type` reads `contentType`, and a core capability like
 /// `Capability::list_with_start_after` reads `Capability.listWithStartAfter`,
 /// the getter on the JS `Capability` that `op.capability()` returns. A core
 /// `range` has no single JS name, so it stays as written.
@@ -854,6 +863,7 @@ fn js_code_span(
     let field = code
         .strip_prefix(options.name)
         .and_then(|field| field.strip_prefix("::"))
+        .or_else(|| code.strip_prefix("Self::"))
         .unwrap_or(code);
     if let Some(&(name, ..)) = options
         .fields
@@ -1859,7 +1869,7 @@ mod tests {
         assert_eq!(
             js_doc(&lines, &LIST_OPTIONS, &core_capabilities()),
             [
-                "Rely on `crate::layers::SimulateLayer` and 
`Self::recursive`.",
+                "Rely on `crate::layers::SimulateLayer` and `recursive`.",
                 "A [plain](https://opendal.apache.org) link and `code` stay.",
                 "Read the [operation 
contract](https://opendal.apache.org/docs/specifications/conditional-operations/).",
                 "and `Capability.listWithLimit`; [a][b] stays.",
@@ -1873,7 +1883,7 @@ mod tests {
             "- Pagination: `limit`, `start_after`.",
             "Requires 
[`Capability::list_with_limit`](crate::Capability::list_with_limit).",
             "Requires [`crate::Capability::list_with_versions`] and 
`Capability::list_with_deleted`.",
-            "Unknown `Capability::no_such_flag`, `start_after_key`, `glob`, 
and prose start_after stay.",
+            "Unknown `Capability::no_such_flag`, `start_after_key`, 
`Self::pattern`, and prose start_after stay.",
         ]
         .map(String::from);
         assert_eq!(
@@ -1882,7 +1892,7 @@ mod tests {
                 "- Pagination: `limit`, `startAfter`.",
                 "Requires `Capability.listWithLimit`.",
                 "Requires `Capability.listWithVersions` and 
`Capability.listWithDeleted`.",
-                "Unknown `Capability::no_such_flag`, `start_after_key`, 
`glob`, and prose start_after stay.",
+                "Unknown `Capability::no_such_flag`, `start_after_key`, 
`Self::pattern`, and prose start_after stay.",
             ]
         );
 
@@ -1963,6 +1973,7 @@ mod tests {
             "A missing file returns [`crate::ErrorKind::NotFound`]. A failed 
condition returns",
             "[`crate::ErrorKind::ConditionNotMatch`]. Some calls also return 
`Unsupported`.",
             "A service conflict surfaces as [`crate::ErrorKind::Conflict`].",
+            "A bad pattern returns [`crate::ErrorKind::ConfigInvalid`].",
             "An unrelated `crate::ErrorKind::PermissionDenied` stays.",
         ]
         .map(String::from);
@@ -1975,6 +1986,7 @@ mod tests {
                     "A missing file produces an error whose message includes 
`NotFound`. A failed condition produces",
                     "an error whose message includes `ConditionNotMatch`. Some 
calls also return `Unsupported`.",
                     "A service conflict surfaces as an error whose message 
includes `Conflict`.",
+                    "A bad pattern produces an error whose message includes 
`ConfigInvalid`.",
                     "An unrelated `crate::ErrorKind::PermissionDenied` stays.",
                 ],
                 "{}",
@@ -2231,7 +2243,7 @@ mod tests {
             .replace_all(&text, |c: &regex::Captures| {
                 format!("`Capability.{}`", camel(&c[1]))
             });
-        let text = Regex::new(&format!(r"`(?:{struct_name}::)?(\w+)`"))
+        let text = Regex::new(&format!(r"`(?:{struct_name}::|Self::)?(\w+)`"))
             .unwrap()
             .replace_all(&text, |c: &regex::Captures| {
                 match names.iter().find(|(core, _)| *core == &c[1]) {
@@ -2239,18 +2251,20 @@ mod tests {
                     None => c[0].to_string(),
                 }
             });
-        let text =
-            
Regex::new(r"returns(\s+)`crate::ErrorKind::(NotFound|ConditionNotMatch|Conflict)`")
-                .unwrap()
-                .replace_all(&text, "produces${1}`crate::ErrorKind::$2`");
-        let text =
-            
Regex::new(r"`crate::ErrorKind::(Unsupported|NotFound|ConditionNotMatch|Conflict)`")
-                .unwrap()
-                .replace_all(&text, "an error whose message includes `$1`")
-                .replace(
-                    "`Some(0)` has the same behavior as `None`",
-                    "`0` has the same behavior as omitting it",
-                );
+        let text = Regex::new(
+            
r"returns(\s+)`crate::ErrorKind::(NotFound|ConditionNotMatch|Conflict|ConfigInvalid)`",
+        )
+        .unwrap()
+        .replace_all(&text, "produces${1}`crate::ErrorKind::$2`");
+        let text = Regex::new(
+            
r"`crate::ErrorKind::(Unsupported|NotFound|ConditionNotMatch|Conflict|ConfigInvalid)`",
+        )
+        .unwrap()
+        .replace_all(&text, "an error whose message includes `$1`")
+        .replace(
+            "`Some(0)` has the same behavior as `None`",
+            "`0` has the same behavior as omitting it",
+        );
         paragraphs(text.lines())
             .into_iter()
             .filter(|paragraph| 
!paragraph.contains("core/core/src/docs/performance"))
@@ -2261,6 +2275,11 @@ mod tests {
     /// not hold for the JS methods of `options`.
     fn node_wording(options: &str, paragraphs: Vec<String>) -> Vec<String> {
         let wording: &[(&str, &str)] = match options {
+            "ListOptions" => &[(
+                "otherwise `crate::layers::SimulateLayer` (installed 
automatically by the default \
+                 `auto-simulate` feature) evaluates patterns client-side.",
+                "otherwise OpenDAL evaluates patterns client-side.",
+            )],
             "ReadOptions" => &[
                 (
                     "A read with a zero limit or an empty range validates",

Reply via email to