chitralverma opened a new pull request, #9383:
URL: https://github.com/apache/opendal/pull/9383

   # Which issue does this PR close?
   
   Part of #9322 (tracker: #9320).
   
   # Rationale for this change
   
   #9333, #9348, #9363, #9375, and #9381 generate the Node.js `ListOptions`, 
`StatOptions`, `DeleteOptions`, `ReadOptions`, and `ReaderOptions` from core. 
This PR generates the existing `WriteOptions` the same way, so its napi object, 
JSDoc, and conversion to core come from the core `WriteOptions`. It is the last 
hand-written Node.js options struct.
   
   # What changes are included in this PR?
   
   - `dev/src/generate/nodejs.rs` gets a `WriteOptions` table with the 11 
members in `main`'s order. `userMetadata` needs one new form, `Js::StringMap`: 
a core `Option<HashMap<String, String>>` as a `Record<string, string>`. The 
other members reuse the existing forms. Generation still fails when core 
changes the kind of an exposed field.
   - The table adds Node.js wording for core text that does not hold for the JS 
methods. Generation fails when core rewords the text a rewrite matches.
     - The struct doc says that `writer()` and `writerSync()` do not access 
storage, so a false condition surfaces from the returned writer's `write()` or 
`close()`.
     - `userMetadata` says that a later `stat()` or `statSync()` returns the 
metadata. Node.js readers return no metadata.
     - `concurrent` says that `write()` and `writeSync()` without `chunk` pass 
their content to the service as one write, so `concurrent` has no effect on 
them.
     - `chunk` is a `bigint`, so "`0` has the same behavior as omitting it" 
reads `0n`.
   - Code spans that name a field of the struct being rendered with its struct 
name now use the JS name. Core's `[`WriteOptions::if_not_exists`]` reads 
`ifNotExists`. `Self::x`, fields of other structs, and unknown names stay as 
written. No other generated docs change.
   - `dev/src/generate/core_options.rs` keeps the indentation of nested list 
items, so the JSDoc keeps core's nested lists, such as the items under "When 
chunk size is set:". Other lines, including list continuation lines, are still 
trimmed. Only core `WriteOptions` has nested lists, and every `ci_odev.yml` 
generator produces the same output for every other struct and binding.
   - `bindings/nodejs/src/options.rs` drops the hand-written struct and 
conversion. `WriteOptions` keeps its 11 members with the same names, types, and 
optionality. The conversion matches `main`:
     - Strings and `userMetadata` pass through, and an omitted `append` or 
`ifNotExists` is `false`.
     - `chunk` ignores its sign and the bits above 64 (`get_u64().1`).
     - `concurrent` is checked by `parse_count` (`0..=4294967295`), and an 
omitted value is `0`. It is the only conversion that can fail.
     - Core's `content_language`, `expires`, `if_version_match`, 
`if_version_not_match`, and `if_not_changed` stay unexposed and get their 
defaults. `checksum` follows #9316 and stays behind `..Default::default()`, as 
on `main`.
   - Core `WriteOptions` doc corrections, each checked on a build of this 
branch (details below):
     - Struct: "Depending on the service, the error may surface when the write 
starts, while writing, or when closing the writer" now reads "Creating a writer 
does not access storage, so depending on the service, the error surfaces while 
writing or when closing the writer." This matches the `ReaderOptions` wording 
from #9381.
     - `user_metadata`: "Keys are case-insensitive in most services" now reads 
"Some services, such as `s3`, return keys in lowercase".
     - `concurrent`: a new paragraph says that "A write of a single buffer 
without `chunk` reaches the service as one write, so `concurrent` has no effect 
on it."
     - `chunk`:
       - "By default, OpenDAL sets optimal chunk size based on service 
capabilities" now says how the default behaves. OpenDAL buffers data until it 
reaches the service's `write_multi_min_size` and then writes everything 
buffered at once. A service without that minimum receives each write as it 
arrives.
       - "Some services require minimum chunk sizes (e.g. S3's EntityTooSmall 
error)" now says that OpenDAL raises a chunk size below `write_multi_min_size` 
to that minimum and lowers one above `write_multi_max_size` to that maximum.
   - Running every `ci_odev.yml` generator changes nothing outside Node.js. 
Java and .NET render only the summary and capability links of these members, 
which are unchanged.
   - Tests:
     - `tests/write-options-surface.test.mjs` freezes the 11 members and the 
`write`, `writeSync`, `writer`, and `writerSync` signatures with literals 
copied from `generated.d.ts` on `main`; the member set must match exactly. On 
`memory`, each member must store the content through all four methods, or fail 
with `Unsupported` naming the core option when `memory` lacks the capability. 
It also checks:
       - that the metadata options reach core under their own names, read back 
through `stat()` and `statSync()`;
       - that `ifNotExists` keeps an existing file, and that the lossy `chunk` 
and zero values are accepted;
       - that an invalid `concurrent` is rejected;
       - that `writer()` and `writerSync()` reject an unsupported condition, 
and that a false condition fails the returned writer's `close()` on `memory`.
     - Generator tests cover `WriteOptions` in each per-struct test:
       - A new core field stays unexposed.
       - A missing field or a kind change fails.
       - The 11 napi fields, in order, and the unexposed defaults are pinned.
       - The conversion is 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.
       - New tests pin the Node.js wording and the nested lists.
       - A rewrite that no longer matches core fails generation.
     - A `core_options` test pins which lines keep their indentation.
   
   Verification:
   
   - Doc claims were checked with the Node.js build on `memory`, `fs`, Silo S3 
(the CI fixture), and azblob on Azurite 3.38.0 (the CI fixture), through a 
logging proxy that showed each request. A Rust probe covered the cases Node.js 
cannot set up.
     - Conditions:
       - An unadvertised condition or `append` fails `write()` and 
`writeSync()`, and fails `writer()` and `writerSync()` themselves, with 
`Unsupported` naming the core option. Examples: `ifMatch` and `ifNoneMatch` on 
`memory` and `fs`, `ifNoneMatch` on Silo (with the hint `use if_not_exists 
instead` for `"*"`), and `append` on `memory`.
       - A false condition never fails `writer()` or `writerSync()`. On `fs`, 
`ifNotExists` on an existing file fails the writer's first `write()`, or 
`close()` for an empty writer. On `memory`, Silo, and Azurite, it fails 
`close()`. The file keeps its old content in every case.
       - On Silo, `ifMatch` with the current ETag succeeds. A different ETag 
fails with `ConditionNotMatch` (412), and so does a missing file (404 
`NoSuchKey`, mapped by the S3 writer). `ifNotExists` sends `If-None-Match: *`. 
A single `PutObject` carries the condition. With `chunk: 5 MiB` and 11 MiB of 
data, `CompleteMultipartUpload` carries it, a failed condition returns 412 
there, and the old file remains.
       - On Azurite, `ifNoneMatch` with the file's ETag fails with 
`ConditionNotMatch`. A different ETag or a missing file lets the write succeed. 
`ifMatch` on a missing file fails with `ConditionNotMatch`.
     - Metadata:
       - On Silo, `contentType`, `cacheControl`, `contentDisposition`, 
`contentEncoding`, and `userMetadata` become `PutObject` headers, or 
`CreateMultipartUpload` headers with `chunk`. `stat()` returns them, with 
`userMetadata` keys in lowercase (`MixedCase` reads `mixedcase`). `memory` and 
`fs` keep the key case.
       - `fs` ignores the four header options. In Rust, `dashmap`, which lacks 
`write_with_user_metadata`, ignores `user_metadata`.
       - In Rust, `Reader::metadata()` on Silo returns the user metadata after 
a read, so core keeps "This metadata can be retrieved later when reading the 
object."
     - `chunk` on Silo (5 MiB minimum part size):
       - Without `chunk`, or with `chunk: 0n`, a writer given three 3 MiB 
writes uploads parts of 6 and 3 MiB, and a 12 MiB `write()` sends one 
`PutObject`.
       - `chunk: 4n` uploads 5 MiB parts, so S3's `EntityTooSmall` does not 
occur.
       - `chunk: 6 MiB` uploads exact 6 MiB parts and a smaller last part, also 
from writes of 1, 1, and 5 MiB.
       - In Rust, `chunk(10 MiB)` with `write_multi_max_size` overridden to 6 
MiB uploads 6 MiB parts. With `write_multi_min_size` overridden to 0, each 3 
MiB write becomes its own part, and Silo rejects the upload with 
`EntityTooSmall`.
     - `concurrent` on Silo, behind a proxy that delays each response by 300 ms:
       - A 20 MiB `write()` with `chunk: 5 MiB` takes 1986 ms with `concurrent: 
1` and 2031 ms with `concurrent: 0`, uploading parts one after another. With 
`concurrent: 4` it takes 1253 ms, and the four `UploadPart` requests overlap.
       - Without `chunk`, `write()` with `concurrent: 4` sends one 20 MiB 
`PutObject`. Rust `write_with(..).concurrent(4)` does the same.
       - A writer with `concurrent: 4` and four 5 MiB writes returns from the 
third and fourth `write()` in under 5 ms, while the parts upload. `close()` 
waits for them and completes the upload.
       - `memory` and `fs` accept `concurrent` and `chunk`.
   - With comments removed, `generated.d.ts` is byte-identical to `main`. With 
the `WriteOptions` interface and its JSDoc removed, it is identical including 
comments. `generated.js`, `index.*`, `lib.rs`, and 
`src/options/{list,stat,delete,read,reader}.rs` are unchanged.
   - Each new test fails under a mutation:
     - Surface test (rebuilt binding): dropping `ifMatch`, making `chunk` a 
`number`, swapping the `contentType` and `cacheControl` conversions, dropping 
the `ifNotExists`, `append`, or `userMetadata` conversion, raising the 
`concurrent` minimum to 1, checking `chunk` with `bigint_to_u64`, or renaming 
the `writerSync` options parameter.
     - Generator tests: making `chunk` a `number`, dropping `ifMatch`, exposing 
`content_language`, moving `concurrent` first, making `userMetadata` a string, 
reading `concurrent` as `u32`, removing the kind check, giving `Js::StringMap` 
another kind or Rust type, dropping or rewording any of the four Node.js 
rewrites, ignoring the struct name in code spans, flattening nested lists, 
keeping every line's indentation, or changing the lossy conversion.
     - With core `chunk` changed to `Option<u64>`, `concurrent` to 
`Option<usize>`, `user_metadata` or `if_not_exists` to `Option<String>`, or 
`if_match` 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 3504 `write`, `writeSync`, `writer`, and `writerSync` calls 
on `memory` and `fs` produces identical output against builds of `main` and 
this branch. It reads back each file's content and `stat()` metadata, and 
covers:
       - each member with 15 to 22 values (`undefined`, `null`, wrong types, 
negative, too large, and others);
       - keys `main` never declared (`contentLanguage`, `expires`, 
`ifVersionMatch`, `ifNotChanged`, `checksum`, snake_case names, and others);
       - combinations of conditions and of invalid values;
       - each case for a missing and an existing file.
   
       Dropping the `ifMatch` conversion changes 96 output lines, and dropping 
the `userMetadata` conversion changes 80.
     - A TypeScript file that implements and fully populates `main`'s 
`WriteOptions`, pins its exact key set and member types, and calls all four 
methods compiles against both builds under `strict` and 
`exactOptionalPropertyTypes`. It fails when a member is removed, added, 
retyped, or made required.
     - The doc-claim scripts produce the same results against both builds on 
all four services, and send the same requests to Silo.
   - `cargo doc -p opendal-core --all-features` builds with `-D warnings`.
   - The Node.js vitest suite passes on `memory`, `fs`, and 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.
   
   Not changed here:
   
   - The Rust `Operator::writer_with` docs still say that `s3` may return 
`EntityTooSmall` for undersized chunks and that OpenDAL determines optimal 
chunk sizes. The `FutureWrite` and `FutureWriter` builders point to 
`WriteOptions`.
   
   # Are there any user-facing changes?
   
   The `WriteOptions` JSDoc now follows core. The core `WriteOptions` rustdoc 
gets the corrections above. Node.js members, types, optionality, the four write 
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, parser change, 
tests, and core doc corrections. Ran the doc-claim checks on `memory`, `fs`, 
Silo S3, and Azurite, 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]

Reply via email to