chitralverma opened a new pull request, #9381:
URL: https://github.com/apache/opendal/pull/9381
# Which issue does this PR close?
Part of #9322 (tracker: #9320).
# Rationale for this change
#9333, #9348, #9363, and #9375 generate the Node.js `ListOptions`,
`StatOptions`, `DeleteOptions`, and `ReadOptions` from core. This PR generates
the existing `ReaderOptions` the same way, so its napi object, JSDoc, and
conversion to core come from the core `ReaderOptions`. `WriteOptions` stays
hand-written for a later PR.
# What changes are included in this PR?
- `dev/src/generate/nodejs.rs` gets a `ReaderOptions` table with the nine
members in `main`'s order. `prefetch` needs one new form, `Js::U32OrZero`: a
core `usize` as a `number` read as `u32`, where an omitted value is `0`, as
`unwrap_or_default() as usize` did on `main`. The other members reuse the
`ReadOptions` forms. Generation still fails when core changes the kind of an
exposed field. The generated files for the other four structs are
byte-identical to `main`.
- The table keeps the `gap` doc from #9338 ("Readers returned by `reader()`
and `readerSync()` read sequentially, so `gap` has no effect."). Its Node.js
wording describes `reader()` and `readerSync()`. They read the whole file, take
no suffix range or `content_length_hint`, and stat the file before they return
when `chunk` is positive. A rewrite may span core's line breaks. Each rewrite
must match, so generation fails when core rewords that text.
- `bindings/nodejs/src/options.rs` drops the hand-written struct and
conversion. `ReaderOptions` keeps its nine members with the same names, types,
and optionality. The conversion matches `main`:
- `chunk` and `prefetch` are read as `u32`, and an omitted `prefetch` is
`0`.
- `gap` ignores its sign and the bits above 64.
- `concurrent` is checked by `parse_count` (`0..=4294967295`), and an
omitted value is `0`.
- Invalid values fail in the same order: `ifModifiedSince`,
`ifUnmodifiedSince`, then `concurrent`.
- Core's `if_version_match`, `if_version_not_match`,
`content_length_hint`, and `checksum` stay unexposed and get their defaults, as
`content_length_hint: None` and `..Default::default()` did before.
- Core `ReaderOptions` doc corrections, each checked on a build of this
branch (details below):
- Struct: "A missing file fails with `NotFound` no matter which conditions
are set" now carries the qualification #9375 gave `ReadOptions`: "Once the
option and capability checks pass, a read that reaches storage fails with
`NotFound` for a missing file". "Depending on the service, a conditional error
may surface when creating the reader or while reading from it" now reads
"Creating the reader checks the options and capabilities without accessing
storage, so a missing file or a failed condition surfaces when reading from
it." `Service::read` is synchronous, so creating a reader sends no request on
any service.
- `concurrent`: the wording #9375 merged for `ReadOptions`. OpenDAL reads
concurrently only together with `chunk`.
- `chunk`: "OpenDAL will use services' preferred chunk size by default"
now reads "By default, OpenDAL reads each range with a single request instead
of in chunks." A new paragraph follows `ReadOptions::chunk`: a positive `chunk`
with an open-ended or suffix range first stats the file, and that stat needs
the stat capability of the version and each condition. It differs from
`ReadOptions` in two places. An earlier read from the reader that observed the
length skips the stat. An empty suffix range still stats, while `read_with`
returns it without a request.
- A second commit corrects the `chunk` and `concurrent` docs of the
`read_with` and `reader_with` builders (`FutureRead` and `FutureReader`), as
#9375's description said this PR would. They read "OpenDAL by default to write
file without concurrent" and "OpenDAL will use services' preferred chunk size
by default". They now use the wording above and point to `ReadOptions::chunk`
and `ReaderOptions::chunk`, and the `concurrent` examples set `chunk`. The
`ReadOptions` text in `options.rs` is unchanged.
- Running every `ci_odev.yml` generator changes, outside Node.js, only the
Java `ReaderOptions.chunk` Javadoc. It gains `@see
Capability#statWithIfModifiedSince`, which the Java generator takes from the
capability that core's `chunk` doc names, as #9375 did for `ReadOptions`.
- Tests:
- `tests/reader-options-surface.test.mjs` freezes the nine members and the
`reader` and `readerSync` signatures with literals copied from `generated.d.ts`
on `main`; the member set must match exactly. On `memory`, each member must
return the whole file through both methods, or fail with `Unsupported` naming
the core option when `memory` lacks the capability. It also checks zero and
positive `chunk`, `concurrent`, and `prefetch`. It checks that `chunk` reaches
core: on `memory`, only a positive `chunk` fails `reader()` for a missing path
with `NotFound` at `stat`. It also checks the lossy `gap` and the order of
conversion errors.
- Generator tests cover `ReaderOptions` in each per-struct test:
- A new core field stays unexposed.
- A missing field or a kind change fails.
- The nine napi fields, in order, and the four unexposed defaults are
pinned.
- The conversion and its order are checked.
- Each member's full doc paragraphs and the struct doc are compared
against text computed from core with Node.js names and the Node.js wording.
- A new test pins the Node.js wording, and a rewrite that no longer
matches core fails generation.
Verification:
- Doc claims were checked on `memory`, `fs`, and versioned Silo S3 (the CI
fixture), with a logging proxy showing each request. The Rust claims were
checked with `reader_options`, `reader_with`, and `read_with`; the Node.js
claims with `reader()` and `readerSync()`, reading to the end.
- Creating a reader sends no request. Without `chunk`, `reader('missing')`
succeeds, and the first read fails with `NotFound`. A condition the service
lacks (`ifMatch` on `memory` and `fs`) fails creation with `Unsupported`. On
Silo, a failing `ifMatch`, `ifModifiedSince`, or `ifUnmodifiedSince` fails the
first read with `ConditionNotMatch`, and an unknown version with `NotFound`. In
Rust, `reader_with` and `into_futures_async_read(..)` behave the same.
- Without `chunk`, or with `chunk: 0`, Silo gets one `GET`, also with
`concurrent: 3` or `prefetch: 2`. With `chunk: 4`, it gets a `HEAD` and four
ranged `GET`s, issued out of order with `concurrent: 3`. The `read_with` and
`reader_with` builders send the same requests for `concurrent(3)`, `chunk(0)`,
and `chunk(4).concurrent(8)`.
- The `chunk` stat:
- In Rust, `Reader::read` with `chunk(2)` and `if_modified_since` fails
with `Unsupported` at `stat` on `fs`, which has `readWithIfModifiedSince` but
not `statWithIfModifiedSince`. It fails for `..`, `suffix(3)`, and `suffix(0)`,
and succeeds for `0..4` or with `content_length_hint(16)`.
- On Silo, a second `read(..)` after `read(0..4)` sends no `HEAD`. On
`fs`, which reports no length on reads, it still stats.
- With `chunk(4)`, a reader's `suffix(0)` of a missing path fails with
`NotFound` at `stat` after a `HEAD`. `read_with(...).range(suffix(0)).chunk(4)`
returns an empty buffer without a request.
- In Node.js, `reader()` and `readerSync()` with a positive `chunk` send
the `HEAD` before they return. With `{ chunk: 2, ifModifiedSince }`, they fail
with `Unsupported` at `stat` on `fs`. On Silo, a future `ifModifiedSince` or a
failing `ifMatch` fails them with `ConditionNotMatch` at `stat`, and a missing
path with `NotFound` at `stat`.
- With comments removed, `generated.d.ts` is byte-identical to `main`. Only
the `ReaderOptions` JSDoc differs; with the interface and its JSDoc removed,
the files are identical. `generated.js`, `index.*`, `lib.rs`, and
`src/options/{list,stat,delete,read}.rs` are unchanged.
- Each new test fails under a mutation:
- Surface test (rebuilt binding): dropping `ifMatch`, making `gap` a
`number`, raising the `concurrent` minimum to 1, dropping the `chunk`
conversion, checking `gap`, converting `concurrent` before the timestamps,
renaming the `readerSync` options parameter, or making `reader()` fail.
- Generator tests: making `prefetch` a `U32`, defaulting it to `1`,
exposing `checksum`, moving `prefetch` after `gap`, dropping the `gap` doc or
`ifMatch`, making `gap` a `number`, removing the kind check, rendering
`prefetch` as defaulting to `1`, and keeping core's Rust text in, or dropping
the `chunk` sentence from, each Node.js rewrite.
- With core `prefetch` changed to `Option<usize>`, `concurrent` to
`Option<usize>`, or `prefetch` removed, `generate -l nodejs` exits with an
error. It also exits with an error when core rewords text that a rewrite
matches. With `src/options/` moved aside, generation recreates identical files.
- Old-consumer probes:
- A script of 1712 `reader` and `readerSync` calls on `memory` and `fs`,
each reading the reader to its end, produces identical output against builds of
`main` and this branch. It covers:
- each member with 12 to 15 values (`undefined`, `null`, wrong types,
negative, too large, and others);
- keys `main` never declared (`limit`, `offset`, `size`, `checksum`,
`contentLengthHint`, snake_case names, and others);
- a `chunk`/`concurrent`/`prefetch` grid, `chunk` with each condition,
and combinations of invalid values;
- each case for a file and for a missing path.
Dropping `ifMatch` changes 131 output lines, and dropping the `chunk`
conversion changes 182.
- A TypeScript file that implements and fully populates `main`'s
`ReaderOptions`, pins its exact key set and member types, and calls both
methods compiles against both builds under `strict` and
`exactOptionalPropertyTypes`. It fails when a member is removed, added,
retyped, or made required.
- The core doctests of `options.rs` and `operator_futures.rs` pass, and
`cargo doc -p opendal-core --all-features` builds with `-D warnings`.
- The behavior suite passes on `memory`, `fs`, and versioned Silo S3 (with
the CI fixture's capability overrides), with per-test outcomes identical to
`main`.
- The Node.js CI job's steps and the `ci_odev.yml` generator check pass in
an Ubuntu 24.04 container with Node.js 20.
# Are there any user-facing changes?
The `ReaderOptions` JSDoc now follows core. The core `ReaderOptions` rustdoc
and the `read_with` and `reader_with` builder docs get the corrections above,
and the Java `ReaderOptions.chunk` Javadoc gains a `@see`. Node.js members,
types, optionality, the `reader` and `readerSync` signatures, and the
conversion to core are unchanged.
# Breaking changes
None
# AI Usage Statement
- **Harness:** Claude Code via T3 Code | **Model:** Claude Opus 5.5 |
**Effort:** xhigh | **Role:** Implemented the generator table, tests, and core
doc corrections. Ran the doc-claim checks on `memory`, `fs`, and Silo S3, plus
the surface diff, mutation checks, old-consumer probes, and the local and Linux
CI steps. Drafted this description. The author reviews every change and claim.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]