chitralverma opened a new issue, #9322:
URL: https://github.com/apache/opendal/issues/9322

   
   *Drafted with AI assistance (Claude Code, Claude Opus 5.5, effort xhigh); 
the author is accountable for it.*
   
   ### Feature Description
   
   Generate the Node.js binding's operation options from core, then expose the 
options Node.js lacks, including options for `copy` and `rename`. Part of #9320.
   
   Abbreviations: VM/VNM = `if_version_match`/`if_version_not_match`, INC = 
`if_not_changed`. Links point at `4ae8e61222`.
   
   ### Problem and Solution
   
   **Current code**
   
   - 
[`bindings/nodejs/src/options.rs`](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/bindings/nodejs/src/options.rs)
 defines `#[napi(object)]` `StatOptions` (L66), `ReadOptions` (L149), 
`ReaderOptions` (L312), `ListOptions` (L435), `WriteOptions` (L498), and 
`DeleteOptions` (L603) by hand. Their conversions to core are at L120, L272, 
L400, L483, L574, and L615.
   - napi-rs writes the TypeScript interfaces into `generated.d.ts`. Node CI 
runs `pnpm build` and then `git diff --exit-code` 
([ci_bindings_nodejs.yml#L111](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/.github/workflows/ci_bindings_nodejs.yml#L111)).
   - `copy` and `rename` 
([lib.rs#L433-L480](https://github.com/apache/opendal/blob/4ae8e61222e6d282b2a1ec99db4e87dccacf5919/bindings/nodejs/src/lib.rs#L433-L480))
 and `presign*` (L794–L866) take no options.
   - `dev/src/generate/nodejs.rs` generates only `Capability` and `Metadata`.
   
   **Missing options**
   
   - read: VM, VNM, `limit`, `content_length_hint`, suffix ranges 
(`offset`/`size` only select forward ranges), and `checksum`
   - reader: VM, VNM, `content_length_hint`, and `checksum`
   - stat: VM, VNM, and `checksum`
   - write: `content_language`, `expires`, VM, VNM, INC, and `checksum`
   - list: `glob`
   - delete: `if_none_match`, VM, VNM, and INC
   - copy and rename: no options at all
   - compose, restore, deleter: no API
   
   **Step 1: generate the existing options with no API change**
   
   - Add a table in `dev/src/generate/nodejs.rs` that maps each core field to 
the existing JS name, napi type, and conversion. The generator renders the 
structs and conversions, and napi-rs keeps `generated.d.ts` in step.
   - Also generate `ComposeOptions`, `ComposeSourceOptions`, `RestoreOptions`, 
and `DeleterOptions`. `CopyOptions` and `RenameOptions` are in the same 
position in Node.js (no method takes them), so generate them here too. napi-rs 
emits these as new exported interfaces, which is additive.
   
   Behavior that step 1 must preserve:
   
   - JS types per field. `concurrent` is a `number` checked by `parse_count`. 
Read and reader `chunk` is a `number` (`u32`), but write `chunk` is a `bigint`. 
`gap`, `offset`, and `size` are `bigint`. List `limit` and reader `prefetch` 
are `number` (`u32`). Timestamps are strings parsed by `parse_timestamp` (L55).
   - Names: read uses `contentType`, `cacheControl`, and `contentDisposition`, 
while stat uses `overrideContentType`, `overrideCacheControl`, and 
`overrideContentDisposition`.
   - Conversion behavior: `gap` and write `chunk` use `get_u64().1` (L295, 
L421, L586), which ignores the sign and lossless flags, while `offset` and 
`size` go through `bigint_to_u64` (L31), which rejects such values. Keep this 
in step 1; tightening it is a separate, declared behavior change.
   - Every member stays optional, because TypeScript callers may implement 
these interfaces structurally.
   
   Add a frozen-surface test whose expectations are literals copied from 
`main`: each interface's member names and TS types from `generated.d.ts`. Prove 
it with a mutation. JSDoc text may change to core's docs; types must not.
   
   **Step 2: expose the missing options**
   
   - Add the missing fields as optional members. Give `copy` and `rename` (sync 
and async) an optional trailing `options` argument.
   - Read `limit`: document the `ConfigInvalid` conflicts with a positive 
`chunk` and with `concurrent` greater than one. `ReaderOptions` has no `limit`, 
and presign takes no options today.
   - Suffix ranges: agree on a field, because `offset`/`size` cannot express 
one.
   - INC: decide how options accept a `Metadata`, which is a class instance 
today. Core lowers it to a version or a non-weak ETag.
   - `expires`: agree on the JS type and unit.
   - Compose, restore, and deleter: add the methods and wire the step-1 types.
   - Blocked by #9319: write-side VM, VNM, and INC, plus compose 
`if_version_match` and `if_not_changed`. Copy conditions are not blocked: GCS 
does not advertise `copy_with_if_not_exists`, so the copy request builder never 
receives the combination that #9319 covers. The `checksum` fields follow #9316.
   
   ### Additional Context
   
   Step 1 is not a release-impacting change. Step 2 is additive for JS callers. 
In TypeScript, the new optional members and the new optional parameter are 
source-compatible.
   
   ### Are you willing to contribute to the development of this feature?
   
   - [x] Yes, I am willing to contribute to the development of this feature.
   


-- 
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