chitralverma opened a new pull request, #9375:
URL: https://github.com/apache/opendal/pull/9375
# Which issue does this PR close?
Part of #9322 (tracker: #9320).
# Rationale for this change
#9333, #9348, and #9363 generate the Node.js `ListOptions`, `StatOptions`,
and `DeleteOptions` from core. This PR generates the existing `ReadOptions` the
same way, so its napi object, JSDoc, and conversion to core come from the core
`ReadOptions`. `ReaderOptions` and `WriteOptions` stay hand-written for later
PRs.
# What changes are included in this PR?
- `dev/src/generate/nodejs.rs`: each row of the options table now names the
field's JS form, and each form carries exactly one core kind (`Js::kind`), so
generation still fails when core changes the kind of an exposed field. The
`ListOptions`, `StatOptions`, and `DeleteOptions` rows only change notation;
their generated files are byte-identical to `main`. `ReadOptions` needs three
forms that the earlier structs did not:
- `concurrent` is a `number` checked by `parse_count` (`0..=4294967295`),
and an omitted value is `0`.
- `gap` is a `bigint` read with `BigInt::get_u64().1`, which ignores the
sign and the bits above 64, as on `main`.
- core `range` becomes the `offset` and `size` `bigint`s, which
`bigint_to_u64` checks. `bytes_range` in `src/options.rs` replaces
`ReadOptions::make_range` with the same checks in the same order.
- The table can also rename a field and replace a doc that does not hold for
JS. `ReadOptions` keeps its names `contentType`, `cacheControl`, and
`contentDisposition` for core `override_*`, and keeps the `gap` doc from #9338
("Each call to `read()` or `readSync()` reads a single byte range, so `gap` has
no effect."). Core's `range` doc describes Rust range syntax, so `offset` and
`size` get JS docs. `options_rs.j2` is unchanged.
- `ReadOptions` keeps its 13 members, with the same names, types, and
optionality. The conversion matches `main`: `chunk` is read as `u32`, an
omitted `concurrent` is `0`, and invalid values fail in the same order
(`offset`, `size`, `ifModifiedSince`, `ifUnmodifiedSince`, `concurrent`).
Core's `limit`, `if_version_match`, `if_version_not_match`,
`content_length_hint`, and `checksum` stay unexposed and get their defaults, as
`..Default::default()` and `content_length_hint: None` did before.
- Generated docs, for every options struct: `js_doc` drops the paragraph
that links the performance guide, because that guide covers the Rust API only,
and reads "`Some(0)` has the same behavior as `None`" as "`0` has the same
behavior as omitting it". Only `ReadOptions` renders such text today.
- Core `ReadOptions` doc corrections, each checked on a release build of
this branch (details below):
- Struct: "A missing file fails the read with `NotFound` no matter which
conditions are set" now starts "With valid, supported options, ...", as #9348
did for `StatOptions`.
- `chunk`: "OpenDAL will use services' preferred chunk size by default"
now reads "By default, OpenDAL reads the range with a single request instead of
in chunks."
- `concurrent`: it takes effect only with `chunk`, and the doc now says so.
- `override_*`: "only meaningful when used along with presign" now reads
"Request a `content-type` response header override from services that support
it, including for presigned read requests", as #9348 did for `StatOptions`.
- Running every `ci_odev.yml` generator changes, outside Node.js, only the
three `override_*` comments in the Java and .NET `ReadOptions`. The Java
Javadoc contract test pinned the old sentence and now expects the new one.
- Tests:
- `tests/read-options-surface.test.mjs` freezes the 13 members and the
`read` and `readSync` signatures with literals copied from `generated.d.ts` on
`main`; the member set must match exactly. On `memory`, each member must
succeed with the expected bytes, or fail with `Unsupported` naming the core
option when `memory` lacks the capability. It also checks `offset` with `size`,
zero `chunk` and `concurrent`, the lossy `gap`, an empty range on a missing
path, and the order of conversion errors.
- Generator tests cover `ReadOptions` too: a new core field stays
unexposed, a missing field or a kind change fails, the 13 napi fields and the
five unexposed defaults are pinned, and the conversion and its order are
checked. A new test compares every member's full doc paragraphs, and each
struct doc, for all four structs against text computed from core's doc comments
with Node.js names, plus literals for the JS-only docs.
Verification:
- Doc claims, on `memory`, `fs`, and versioned Silo S3 (the CI fixture),
through a logging proxy that showed each request:
- A missing file: `NotFound` without options; `Unsupported` with an option
the service lacks (for example `ifMatch` on `memory` and `fs`); `NotFound` with
supported conditions (`ifModifiedSince` on `fs`; all four on Silo).
- `size: 0n` on a missing file returns an empty buffer on all three, also
with `ifMatch` on Silo, without a request; with `ifMatch` on `memory`, it fails
with `Unsupported`.
- On Silo, a matching or failing `ifMatch`, `ifNoneMatch`,
`ifModifiedSince`, and `ifUnmodifiedSince` returns the data or
`ConditionNotMatch`. `version` reads that version; a well-formed unknown
version returns `NotFound`.
- Without `chunk`, or with `chunk: 0`, Silo gets one `GET`, also with
`concurrent: 3`. With `chunk: 4` it gets a `HEAD` and three ranged `GET`s,
issued out of order with `concurrent: 3`.
- A plain `read` with the three overrides sends `GET
/test/f?response-content-disposition=attachment&response-content-type=text/x-probe&response-cache-control=no-store`.
- An `offset` at or past the end returns an empty buffer on `memory` and
`fs` and `RangeNotSatisfied` on Silo. A `size` past the end fails on all three.
- `generated.d.ts` differs from `main` only in the `ReadOptions` JSDoc; with
comments removed, it is byte-identical. `generated.js`, `index.*`, `lib.rs`,
and `src/options/{list,stat,delete}.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, checking `size` before
`offset`, or ignoring `offset`.
- Generator tests: documenting `recursive` as defaulting to `true`,
keeping the performance guide paragraph, dropping the `Some(0)` rewrite, the
`gap` doc, the renames, or the kind check, changing the `offset` doc, exposing
`checksum`, making `gap` a `number`, raising the `concurrent` minimum, moving
`range` first, using core names for renamed fields, rewriting `Unsupported`
only for `ListOptions`, or changing the `gap` conversion.
- With core `chunk` changed to `Option<u64>`, `concurrent` to
`Option<usize>`, or `range` removed, `generate -l nodejs` exits with an error.
Adding a field to core `ReadOptions` only adds `fake_option:
Default::default()` to `read.rs`. With `src/options/` moved aside, generation
recreates identical files.
- Old-consumer probes:
- A script of 2328 `read` and `readSync` calls on `memory` and `fs`
produces identical output against builds of `main` and this branch. It covers
each member with 14 or 15 values (`undefined`, `null`, wrong types, negative,
too large, and others), keys `main` never declared (`limit`, `range`,
`checksum`, `overrideContentType`, snake_case names, and others),
`offset`/`size` and `chunk`/`concurrent` grids, and combinations of invalid
values, for a file and a missing path. Ignoring `offset` in the conversion
changes 220 output lines, and dropping `ifMatch` changes 110.
- A TypeScript file that implements and fully populates `main`'s
`ReadOptions`, pins its exact key set and member types, and calls both methods
compiles against both under `strict` and `exactOptionalPropertyTypes`. It fails
when a member is removed, added, retyped, or made required.
- 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 also pass
in an Ubuntu 24.04 container with Node.js 20.
# Are there any user-facing changes?
The `ReadOptions` JSDoc now follows core, and the core `ReadOptions` rustdoc
gets the corrections above; the Java and .NET `ReadOptions` override comments
follow it. Node.js members, types, optionality, the `read` and `readSync`
signatures, and the conversion to core are unchanged.
Not changed here:
- The struct doc mentions "a zero limit"; Node.js does not expose `limit`
yet (#9322, step 2).
- "Including for presigned read requests" matches the `StatOptions` docs;
Node.js `presignRead` takes no options yet.
- Core `ReaderOptions` repeats the `NotFound`, `chunk`, and `concurrent`
sentences; its generation PR will check and correct them.
# Breaking changes
None
# AI Usage Statement
- **Harness:** Claude Code via T3 Code | **Model:** Claude Opus 5.5 |
**Effort:** xhigh | **Role:** Implemented the generator forms, 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]