72 Commits

Author SHA1 Message Date
LongYinan
10416f1b43
fix(napi): relax the lifetime restriction in PromiseRaw callbacks (#2819) 2025-07-31 09:51:10 +08:00
bde407ddab
fix(napi-derive): generate types for threadsafe_function with WEAK=true correctly (#2813) 2025-07-30 00:24:15 +08:00
LongYinan
bb9883ab09
fix(napi-derive): lifetime codegen issue (#2794) 2025-07-22 17:54:18 +08:00
LongYinan
1ca2bad43f
feat(napi): provide ScopedTask to resolve JsValue with lifetime (#2786) 2025-07-21 13:55:44 +08:00
LongYinan
c067e0d7bb
chore(cli): skip Buffer import if fs is enable (#2779) 2025-07-17 14:10:48 +08:00
LongYinan
485befffcb
chore(example): add define_class example (#2765) 2025-07-06 21:43:35 -07:00
LongYinan
0119f09237
feat(napi): support untyped TypedArray slice (#2762) 2025-07-03 16:50:35 +08:00
Brooooooklyn
2fed7f85e0
fix(napi): spawn_future_with_callback lifetime (#2760) 2025-07-03 07:09:22 +00:00
LongYinan
5add173ca2
feat(napi): support c string for object apis (#2759) 2025-07-03 14:08:05 +08:00
LongYinan
7e34e30b66
feat!(napi): create function from #[napi] fn (#2757) 2025-07-02 16:54:31 +08:00
LongYinan
99f4c089d4
feat(napi): add napi_ref impl for Object Symbol and External (#2754) 2025-07-01 00:45:32 -07:00
LongYinan
092f887f39
fix(napi-derive): generate object key types properly (#2752) 2025-06-30 17:10:17 +08:00
LongYinan
2273031264
test(napi): add fixture for #2746 (#2747) 2025-06-25 22:35:25 +08:00
LongYinan
3e2fe8a2a3
fix(napi): create external TypedArray in Electron env (#2740) 2025-06-24 22:48:00 +08:00
LongYinan
3dce1533fd
test(napi): add fixture for re-export complex class (#2733) 2025-06-24 16:31:26 +08:00
Kevin Deng
e7af6608fc
fix(cli): wasm url in binding files (#2710) 2025-06-11 12:03:32 -07:00
LongYinan
54935e34fa
fix(napi-derive): panic while creating type definition when Rust comment contains escape syntax (#2701) 2025-06-08 18:25:09 +08:00
LongYinan
814bc79412
fix(napi-derive): using js_name generating wrong type defs (#2700)
This commit introduces two main changes:

1.  Refactors the variable names used during the creation of
    `NapiStruct` in `crates/macro/src/parser/mod.rs`. The goal is to
    make the source of `NapiStruct.name` (the Rust identifier) and
    `NapiStruct.js_name` (the JavaScript name, potentially from a
    `#[napi(js_name = "...")]` attribute) more explicit. This change
    is primarily for code readability and maintainability. The core
    logic remains the same.

2.  Adds a new test case to `examples/napi` to specifically verify
    the behavior of `#[napi(js_name = "...")]` on structs. This
    includes:
    - A new Rust struct `OriginalRustNameForJsNamedStruct` in
      `examples/napi/src/class.rs` decorated with
      `#[napi(js_name = "MyJsNamedClass")]`.
    - Corresponding tests in `examples/napi/__tests__/values.spec.ts`
      that check for correct class instantiation, method calls, and
      type alias generation (`OriginalRustNameForJsNamedStruct` as an
      alias for `MyJsNamedClass`).

Note: I encountered some issues running the full build and tests for the example due to pre-commit hooks in the testing environment that I couldn't bypass. However, I believe the changes are correct based on static analysis and focused checks.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2025-06-08 17:14:57 +08:00
Hana
0a90c8a8f2
feat(napi): support build_threadsafe_function variant with error status (#2694) 2025-06-05 21:35:18 +08:00
LongYinan
d5a16483c5
fix(napi-derive): Either<f64, u32> should generate number ts type (#2683) 2025-06-02 23:53:14 +08:00
Hana
f4731bb566
feat!(napi): support custom tsfn result error code (#2672) 2025-06-02 22:47:50 +08:00
LongYinan
f8fab45de7
feat(napi): serialize BigInt to serde::Value (#2659) 2025-05-24 23:18:40 +08:00
LongYinan
3c5f22001b
fix(napi): wrong error status in ThreadsafeFunction callback (#2656) 2025-05-22 17:24:46 +08:00
LongYinan
7182db3a81
feat(napi): EscapableHandleScope API (#2652) 2025-05-19 19:52:21 +08:00
LongYinan
92b094e487
feat(napi): new handle scope API (#2650) 2025-05-18 23:16:40 +08:00
LongYinan
ce990542b9
fix(napi): module_exports binding (#2632) 2025-05-13 19:54:25 +08:00
LongYinan
7a972425b8
fix(napi): nested Either and Promise validate logic (#2625)
- Close https://github.com/napi-rs/napi-rs/issues/2578
2025-05-12 00:33:14 +08:00
LongYinan
bcf5e14aa8
feat(napi): add from_napi_value for Ref<T: FromNapiValue> (#2603) 2025-05-05 23:38:46 +08:00
LongYinan
674d7c7b56
refactor!(napi): add lifetime to Array (#2599) 2025-05-05 14:16:53 +08:00
Cong-Cong Pan
0ce726d9c7
feat(napi): serde value ref to napi_value (#2550)
* perf: convert serde value ref to napi_value

* chore: add test case

* fix: snapshot
2025-04-10 16:17:59 +08:00
LongYinan
1fe6ad0430
feat(napi): tokio multi-thread mode on wasi (#2501)
* feat(napi): tokio multi-thread mode on wasi

* tokio_unstable flag

* snapshot

* ensure runtime

* oncelock combine lazylock

* noop feature
2025-03-13 23:53:19 +08:00
LongYinan
68bf0c7561
chore(example): add extends JavaScript Error (#2497) 2025-03-05 11:28:26 +08:00
LongYinan
ee75b119cd
refactor!(napi): link crt1-reactor.o as poor man's wasi-exec-model=reactor (#2480) 2025-02-25 21:45:38 +08:00
lghuahua
8ea8e9ebfc
feat(napi-derive): impl #[napi(array)] (#2459) 2025-02-11 13:35:27 +08:00
LongYinan
ea05ad3845
fix(napi-derive): hide the lifetime recursively in codegen (#2426) 2025-01-12 22:36:14 +08:00
LongYinan
05572bf1d4
feat(napi): allow create ReadableStream from polyfill (#2424) 2025-01-12 15:32:12 +08:00
LongYinan
98cb7671d3
feat(napi): impl ReadableStream and AsyncGenerator (#2418)
* feat(napi): impl ReadableStream and AsyncGenerator

* clippy fix

* Into<Vec<u8>> trait

* Skip node18 stream test due to Node.js bug

* Cleanup

* Also skip wasi test

* Merge test

* Skip wasi

* Useless expect-error
2025-01-03 17:09:42 +08:00
lghuahua
31cd07c8c2
feat(napi-derive): support type on #[napi] (#2416)
Co-authored-by: LongYinan <lynweklm@gmail.com>
2025-01-02 17:15:07 +08:00
Stanisław Czech
b4b74d6f1f
refactor!(napi): arguments tuple behavior (#2401)
* Implement FromNapiValue trait as macro

Code behavior should remain the same, with much less copy-pasting of the same code.
Additionally, this commit adds a unit tests for test for FromNapiValue
for tuple trait which appears to be currently missing.

* Simplify macro arr_get

Rewrite the macro to reduce the size of expanded code of the macro
(from 4088 to 2429 lines). Although this is a minor change,
this may help reduce the size of compiled library.

* Refactor typegen Type::Path

Removes the need for keeping mutable variable, as its only assigned once.

* [API BREAKING] Update api for calling functions.

This commit introduces new type FnArgs,
that is created with the goal of distinguishing between
calling JS function from rust with tuple as argument
and calling with multiple arguments.

Currently there is no possibility to add ToNapiValue value,
as tuple is used to call callback functions with more than one
argument from rust.

With this change, callbacks with multiple arguments,
should be called, with converting tuple of argument
into FnArgs struct, either by calling into() on such
tuple, or by creating FnArgs struct directly.

* Add support for FnArgs when generating TS types

Updated the macro for generating typescript types,
to correctly handle FnArgs struct. This is now treated
as passthrough type and generates the output from the
type inside of FnArgs struct.

* Implement ToNapiValue trait for tuple

With the changes to callback calling API, it's now possible
to safely add this change. This change allows to pass tuple
from rust code to JS to match the existing FromNapiValue trait
currently existing in the library.
2025-01-02 16:58:58 +08:00
LongYinan
8fffa49282
fix(napi): resuse threads worker on Node.js (#2399) 2024-12-18 23:48:30 +08:00
underfin
533635619e
fix(napi): delete error reference with raw Error (#2388)
* fix: delete error reference at drop

* fix: ci

* fix: ci

* fix: ci

* fix: ci

* fix: avoid using drop
2024-12-09 19:17:16 +08:00
Hiroshi Ogawa
61543c0f45
fix(napi): handle nul byte in object key (#2385)
* fix: fix to_napi_value

* test: add test

* fix: fix from_napi_value

* fix: fix object.get/set

* test: test plain object

* test: snapshot
2024-12-03 14:17:18 +08:00
翠 / green
6a4ce688c4
fix(napi-derive): generate correct types for HashMap with RandomState argument (#2384)
* fix(napi-derive): generate correct types for HashMap with RandomState argument

* chore: update snapshot
2024-12-02 22:37:00 +08:00
翠 / green
521aefe420
feat(napi-derive): implement #[napi(transparent)] (#2376) 2024-11-30 10:28:40 +08:00
frankwang
8b474f929d
feat(napi-derive): allow ts_type in napi fn attrs (#2362)
* feat: allow ts_type in fn attrs

* chore: add override fn type example
2024-11-22 15:44:16 +08:00
Richer
c1b07a82c1
fix(backend): fix type when function as object field (#2359) 2024-11-18 14:39:49 +08:00
LongYinan
49ed2ddf71
fix(napi-derive): object lifetime compile issue (#2351) 2024-11-11 20:19:41 +08:00
LongYinan
f705454029
feat(napi): introduce AsyncBlock to let user dispose resources after future done (#2338) 2024-10-31 09:24:30 +08:00
LongYinan
c91456d84a
feat(napi): support return *const c_char to JavaScript directly (#2332) 2024-10-28 23:48:33 +08:00
LongYinan
f707f36c5a
feat(napi): implmenet Set (#2330) 2024-10-26 20:11:58 +08:00