chitralverma opened a new pull request, #9348:
URL: https://github.com/apache/opendal/pull/9348
# Which issue does this PR close?
Part of #9322 (tracker: #9320).
# Rationale for this change
#9333 started generating the Node.js operation options from core with
`ListOptions`. This PR generates the existing `StatOptions` the same way, so
its napi object, JSDoc, and conversion to core come from the core
`StatOptions`. The other Node.js option structs stay hand-written for later PRs.
# What changes are included in this PR?
- `dev/src/generate/nodejs.rs` now renders each generated options struct
from one table entry: the core struct name, its module under `src/options/`,
and the core fields that JS exposes with the core kind that each JS type was
chosen for. `ListOptions` moves into this table unchanged, and `StatOptions` is
added. `list_options_rs.j2` becomes `options_rs.j2`, which renders both.
- `StatOptions` exposes the same eight members as before, with the same
names, types, and order. `version`, `ifMatch`, `ifNoneMatch`, and the three
`override*` members pass their strings through. `ifModifiedSince` and
`ifUnmodifiedSince` stay strings parsed by `parse_timestamp`. An invalid value
still fails with `ifModifiedSince must be an ISO 8601 timestamp, …`, and
`ifModifiedSince` is still reported first when both values are invalid. Core's
`if_version_match`, `if_version_not_match`, and `checksum` stay unexposed, and
the conversion sets them to their defaults, as `..Default::default()` did
before.
- The conversion is a `TryFrom` when an exposed field can fail to convert (a
timestamp), and a `From` otherwise. As for `ListOptions`, it names every core
field, so a new core field fails to compile in the binding until `generate -l
nodejs` runs again.
- The `StatOptions` JSDoc now comes from the core doc comments, in full,
with the rules #9333 introduced: rustdoc links become code spans, and
capability references use their JS names, such as `Capability.statWithIfMatch`.
In addition:
- The reference-style link `[conditional operation
specification][crate::docs::specs::conditional_operations]` keeps only its
text, as the .NET generator does.
- The two timestamp members get a JS note after the core text. It says to
pass an ISO 8601 string, such as `2024-01-01T00:00:00Z` or the result of
`Date.prototype.toISOString()`, and that a string that does not parse fails the
operation. This replaces the MDN link in the old hand-written JSDoc.
- `ErrorKind` references stay as written (`crate::ErrorKind::NotFound`),
as in the `ListOptions` JSDoc on `main`. Node.js reports error kinds only in
the `Error` message, so there is no JS name to translate them to. #9334 tracks
translating names across bindings.
- `bindings/nodejs/src/options.rs` replaces the hand-written `StatOptions`
with the generated `src/options/stat.rs` and re-exports it, so `lib.rs` is
unchanged. The napi struct now also derives `Default`, which is Rust-only and
not visible in JS.
- Tests:
- `tests/stat-options-surface.test.mjs` freezes the eight `StatOptions`
members and the `stat` and `statSync` signatures, using literals copied from
`generated.d.ts` on `main`. The member set must match exactly. For each member,
both stat methods are called on `memory` with a value of the member's type. The
three `override*` members must succeed. Each other member must fail with
`Unsupported` naming its core option (for example `if_match`), because `memory`
lacks that capability. So dropping or misrouting `version` or a condition
member fails the test.
- Generator tests check that a new core field leaves both napi structs
unchanged and gets its default. They also check that generation fails when an
exposed field is missing or changes its core kind (`if_modified_since` to
`Option<String>`, `version` to a timestamp), and that `StatOptions` keeps its
eight napi fields. They pin the conversion of every member: six pass their
string through, and only the two timestamps get the parse and the note. They
also check that the JSDoc uses JS capability names and has no rustdoc link
syntax left. CI regenerates `stat.rs` and fails on a diff, so these checks
cover the committed conversion.
- Unlike `ListOptions`, the stat conversion has no Rust unit test in
`options.rs`. It returns `napi::Result`, and a test that unwraps or drops a
`napi::Error` pulls in napi runtime symbols that a Linux test binary cannot
link.
Verification:
- `generated.d.ts` differs from `main` only in the `StatOptions` JSDoc. With
comments removed, it is byte-identical to `main`. `generated.js`, `index.*`,
`lib.rs`, and `src/options/list.rs` are unchanged.
- napi-rs escapes `*/` in doc text as `*\/`, and quotes and backslashes
reach `generated.d.ts` unchanged (checked with a scratch doc line).
- Each new test fails under a mutation:
- Surface test: dropping `ifMatch` from the conversion, swapping `version`
and `ifNoneMatch`, failing the conversion when `overrideContentType` is set,
making `version` required, making the `stat` options parameter required, or
adding `checksum?: boolean`.
- Generator tests: skipping the kind check, dropping the timestamp note,
keeping reference links, translating `ListOptions` field names in every struct,
turning off the capability rewrite, always emitting `From`, exposing
`checksum`, calling another parse function, or filtering the `override*`
strings.
- With core `if_modified_since` changed to `Option<String>`, or `if_match`
removed, `generate -l nodejs` exits with an error. Adding a field to core
`StatOptions` only adds `fake_option: Default::default()` to `stat.rs`.
- Old-consumer probes:
- A script of 344 `stat` and `statSync` calls produces identical output
against builds of `main` and this branch. It covers each member with 18 values
(`null`, wrong types, valid and invalid timestamps, and others), keys `main`
never declared (`ifVersionMatch`, `checksum`, snake_case names), and missing
files. With the conversion mutated, 68 lines differ.
- A TypeScript file that implements and fully populates the `main`
`StatOptions` compiles against both under `strict` and
`exactOptionalPropertyTypes`, and fails when a member is removed.
- The behavior suite passes on `memory` and `fs`. On versioned Silo S3, all
12 stat option tests run and pass, and per-test outcomes match `main` (125
passed, 6 skipped).
# Are there any user-facing changes?
The `StatOptions` JSDoc text now follows core, plus the JS timestamp note.
Its members, types, optionality, the `stat` and `statSync` 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, template, and tests;
ran 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]