Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodejs bindings #353

Closed
thekingofcity opened this issue Mar 4, 2022 · 4 comments
Closed

Nodejs bindings #353

thekingofcity opened this issue Mar 4, 2022 · 4 comments

Comments

@thekingofcity
Copy link
Collaborator

Problem description
According to the Supported APIs, Nodejs will be supported. But it is missing right now.

Problem location
./nodejs/

Suggestions for an improvement

@thekingofcity
Copy link
Collaborator Author

thekingofcity commented Mar 4, 2022

I want to contribute to the Nodejs bindings of the Pravega client.

Changes will be split into several PRs:

@thekingofcity
Copy link
Collaborator Author

The binding uses neon-bindings instead of wasm-bindgen.

The reason is that the latter targets pure rust logic w/o touching sys and net. It can do everything pure js scripts can do. But for sys and net, they are not allowed in the browser. Touching the system files requires a proxy using the File System Access API and making a TCP connection is somewhat impossible in the browser. Workarounds will be a WebSocket proxy at the Pravega server-side to translate WebSocket to TCP.

This is what I get when I tried the wasm-bindgen:

$ wasm-pack build --target nodejs
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /home/thekingofcity/pravega-client-rust/pravegactl/Cargo.toml
workspace: /home/thekingofcity/pravega-client-rust/Cargo.toml
   Compiling socket2 v0.4.4
   Compiling slab v0.4.5
   Compiling futures-io v0.3.21
   Compiling regex-syntax v0.6.25
   Compiling fnv v1.0.7
   Compiling cfg-if v0.1.10
   Compiling base64 v0.13.0
   Compiling percent-encoding v2.1.0
error[E0583]: file not found for module `sys`
   --> /home/thekingofcity/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/lib.rs:124:1
    |
124 | mod sys;
    | ^^^^^^^^
    |
    = help: to create the module `sys`, create file "/home/thekingofcity/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/sys.rs" or "/home/thekingofcity/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/sys/mod.rs"

error: Socket2 doesn't support the compile target
   --> /home/thekingofcity/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/lib.rs:127:1
    |
127 | compile_error!("Socket2 doesn't support the compile target");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0432]: unresolved imports `crate::sys::sa_family_t`, `crate::sys::sockaddr`, `crate::sys::sockaddr_in`, `crate::sys::sockaddr_in6`, `crate::sys::sockaddr_storage`, `crate::sys::socklen_t`, `crate::sys::AF_INET`, `crate::sys::AF_INET6`
 --> /home/thekingofcity/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.4/src/sockaddr.rs:6:5
  |
6 |     sa_family_t, sockaddr, sockaddr_in, sockaddr_in6, sockaddr_storage, socklen_t, AF_INET,
  |     ^^^^^^^^^^^  ^^^^^^^^  ^^^^^^^^^^^  ^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^  ^^^^^^^^^  ^^^^^^^ no `AF_INET` in `sys`
  |     |            |         |            |             |                 |
  |     |            |         |            |             |                 no `socklen_t` in `sys`
  |     |            |         |            |             no `sockaddr_storage` in `sys`
  |     |            |         |            no `sockaddr_in6` in `sys`
  |     |            |         no `sockaddr_in` in `sys`
  |     |            no `sockaddr` in `sys`
  |     no `sa_family_t` in `sys`
7 |     AF_INET6,
  |     ^^^^^^^^ no `AF_INET6` in `sys`

Similar error and discussion could be found at WebAssembly with Rust problem compiling wasm.

@thekingofcity
Copy link
Collaborator Author

thekingofcity commented Mar 7, 2022

Although the neon has an example of how to construct a class in JS, this passage suggests a way of doing so without prototypes or classes.

JavaScript Pop Quiz 6: Which Do Experienced JavaScript Developers Prefer—Prototypes or Classes?
You guessed it, that’s another trick question—experienced JavaScript developers tend to avoid both when they can.
...

I update the code in 678caf3 to be composition and the code should look modern now. ✨

@thekingofcity
Copy link
Collaborator Author

thekingofcity commented Dec 24, 2022

Every feature mentioned in this issue is implemented in the related issues. The first stage of Nodejs binding should be complete.

Say Hi to @pravega/pravega and its documentation. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant