Xuanwo opened a new pull request, #8970:
URL: https://github.com/apache/opendal/pull/8970
# Which issue does this PR close?
# Rationale for this change
Four correctness and test-coverage issues exist in `bindings/nodejs`:
1. **CommonJS exports and `layers` namespace mismatch**: `index.cjs` only
exported `Operator` and a partial `layers` object (`RetryLayer`,
`ConcurrentLimitLayer`), leaving every other runtime export declared in
`index.d.ts` (`TimeoutLayer`, `LoggingLayer`, `ThrottleLayer`,
`CapabilityOverrideLayer`, `EntryMode`, `Entry`, `Metadata`, `Capability`,
`Reader`, `BlockingReader`, `Writer`, `BlockingWriter`, `Lister`,
`BlockingLister`, `Layer`) `undefined` for CommonJS consumers. `index.mjs` also
omitted `TimeoutLayer`, `LoggingLayer`, and `ThrottleLayer` from `layers`.
2. **`BlockingReadStream` error and cleanup semantics**:
`BlockingReadStream._read` called `this.emit('error', e)` instead of
`this.destroy(e)` and lacked `_destroy`, so errored blocking read streams
stayed undestroyed (`destroyed === false`), never emitted `'close'`, could
re-enter `_read` on subsequent reads, and retained the native `BlockingReader`
until GC.
3. **`WriteStream` / `BlockingWriteStream` encoding corruption and
cleanup**: Both writable stream wrappers ignored the `encoding` argument in
`_write(chunk, encoding, callback)`, so string writes under `{ decodeStrings:
false }` with non-UTF-8 encodings (such as `'hex'`, `'base64'`, `'utf16le'`, or
`'latin1'`) were passed to Rust as UTF-8 strings and silently corrupted.
Neither wrapper implemented `_destroy` to release the native writer when
destroyed.
4. **Permanently skipped sync test suite**: `tests/suites/sync.suite.mjs`
gated `describe('sync tests', ...)` on `op.capability().blocking`, which no
longer exists on `Capability` (`undefined`), skipping all sync tests in CI. Its
`blocking reader/writer stream pipeline` test also attached a `'finish'`
listener without awaiting completion.
# What changes are included in this PR?
- **`bindings/nodejs/index.cjs` & `bindings/nodejs/index.mjs`**:
- Export all runtime symbols from `./generated.js` in `index.cjs` (with
explicit `module.exports.<Name>` assignments so Node's static CJS lexer also
exposes every named export to ESM importers without mutating `generated.js`),
and expose all 6 layer classes (`CapabilityOverrideLayer`,
`ConcurrentLimitLayer`, `LoggingLayer`, `RetryLayer`, `ThrottleLayer`,
`TimeoutLayer`) in `layers` in both `index.cjs` and `index.mjs`.
- Update `BlockingReadStream._read` to guard against destroyed streams,
call `this.destroy(error)` on error, and implement `_destroy(error, callback)`
to release `this.reader` (aligned with `ReadStream`).
- Convert non-UTF-8 string chunks via `Buffer.from(chunk, encoding)` in
`WriteStream._write` and `BlockingWriteStream._write`, and implement
`_destroy(error, callback)` on both to release `this.writer`.
- **`bindings/nodejs/tests/suites/sync.suite.mjs`,
`bindings/nodejs/tests/suites/async.suite.mjs`, &
`bindings/nodejs/tests/entrypoint.test.mjs`**:
- Remove the stale `op.capability().blocking` guard from `sync.suite.mjs`,
await `pipeline(rs, ws)` and `finished(ws)` in `blocking reader/writer stream
pipeline`, and compare `contentLength` against `BigInt(buf.length)`.
- Add regression tests covering ESM/CJS export and `layers` parity against
`generated.d.ts`, isolated CJS stream behavior, `BlockingReadStream` error
destruction and non-re-entry, and `WriteStream`/`BlockingWriteStream` string
encoding (`decodeStrings: false`) and `.destroy()` cleanup.
# Are there any user-facing changes?
- CommonJS consumers (`require('opendal')`) can now import all runtime
classes and enums declared in `index.d.ts`, and both ESM and CommonJS `layers`
namespaces include all 6 layer classes.
- `BlockingReadStream` now properly destroys itself and emits `'close'` on
read errors, and `WriteStream` / `BlockingWriteStream` honor string `encoding`
under `{ decodeStrings: false }` and release native writers on destroy.
# Breaking changes
# AI Usage Statement
- Harness: pi
- Model: Gemini 4 Neon
- Effort: high
- Role: Independently verified all four findings against `main`, implemented
the fixes in `bindings/nodejs/index.cjs`, `bindings/nodejs/index.mjs`, and the
Vitest suites, and validated formatting, typechecking, clippy, Cargo tests, and
memory/fs behavior tests locally.
--
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]