fix(node): wrap native rest static via Proxy instead of mutating it#535
Closed
DorianZheng wants to merge 1 commit into
Closed
fix(node): wrap native rest static via Proxy instead of mutating it#535DorianZheng wants to merge 1 commit into
DorianZheng wants to merge 1 commit into
Conversation
napi-rs registers class statics as non-writable AND non-configurable. `lib/index.ts` reassigned `JsBoxlite.rest` to adapt the native positional `rest(url, credential?, prefix?)` to the public `BoxliteRestOptions` bag, which threw `TypeError: Cannot assign to read only property 'rest'` at module import — breaking every consumer of the SDK (3 integration suites failed on import). A Proxy over the native class is also rejected: a `get` trap may not substitute a non-configurable, non-writable own data property. So the Proxy target is a fresh function that owns no such property; `rest` resolves to the bag adapter while construction and every other static forward to the native class untouched. Adds rest-binding.integration.test.ts covering import + bag adaptation.
5 tasks
Member
Author
DorianZheng
added a commit
that referenced
this pull request
May 16, 2026
Consolidates the Node REST-binding fix into one PR (supersedes #535). - Native `rest` now takes a `#[napi] JsBoxliteRestOptions` class with a `From<&JsBoxliteRestOptions> for BoxliteRestOptions` conversion (the napi twin of the Python SDK's `impl From`); the positional→bag adaptation lives in Rust, not a JS Proxy. - `lib/index.ts` exposes the bag-taking `rest` via a plain ES subclass; the Proxy/static-mutation workaround is deleted. Public TypeScript API is byte-identical (`lib/options.ts` stays pure-TS). - Fixes the original import-time `TypeError: Cannot assign to read only property 'rest'` regression (broke 3 integration suites on main). Verified: Node test matrix, Rust clippy (3 platforms), rustfmt, full local make test:integration:node (46 passed), napi-subclass construct + static inheritance covered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sdks/node/lib/index.tsadapted the native positionalrest(url, credential?, prefix?)to the publicBoxliteRestOptionsbag by reassigning thereststatic on the native napi-rs class. napi-rs registers class statics as non-writable and non-configurable, so the assignment threwTypeError: Cannot assign to read only property 'rest'at module import — breaking every consumer of../lib/index.js. Three integration suites (credential,images,snapshot-clone-export) failed on import;mainwas red on Node integration.gettrap may not substitute a non-configurable, non-writable own data property. The fix proxies a fresh function that owns no such property —restresolves to the bag adapter, while construction (new) and every other static forward to the native class untouched.tests/rest-binding.integration.test.ts(reproducer: import + bag adaptation).Regression introduced by #532 (bearer auth). Surfaced while bumping SDK patch versions, whose pre-push
make testruns the Node integration suite.Test plan
TypeErroratlib/index.ts:60), passes aftercredential,images,snapshot-clone-exportmake test:integration:node: 9 passed / 1 skipped, 44 tests, exit 0npm run build(tsc) clean; unit project 69/69make testgreen on push