85 Commits

Author SHA1 Message Date
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
74f349c180
fix(napi): reuse issue on AbortSignal (#2646)
- Close https://github.com/napi-rs/napi-rs/issues/2141
2025-05-18 15:57:10 +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
ff2c64b35d
chore: clippy fix (#2545) 2025-04-04 13:52:49 +08:00
LongYinan
5554c663ac
chore(cli): update deps (#2542) 2025-04-01 23:49:56 +08:00
Cong-Cong Pan
cc9989f4ac
fix(napi): js callback in threadsafefunction should not be Send (#2510) 2025-03-16 21:56:29 +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
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
24e6bd38f3
chore: remove ts-node in examples/napi test (#2425) 2025-01-12 19:22:37 +08:00
LongYinan
05572bf1d4
feat(napi): allow create ReadableStream from polyfill (#2424) 2025-01-12 15:32:12 +08:00
LongYinan
73d5c1d803
fix(napi): add back Buffer/TypedArray custom gc on wasi (#2421) 2025-01-12 11:45:50 +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
richerfu
5f7415c1fe
fix(napi): Function call with empty tuple should generate empty arguments (#2407)
Co-authored-by: LongYinan <lynweklm@gmail.com>
2025-01-02 17:10:53 +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
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
renovate[bot]
77fe9757fc
chore(deps): lock file maintenance (#2380)
* chore(deps): lock file maintenance

* Fix typecheck

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: LongYinan <lynweklm@gmail.com>
2024-12-03 15:28:37 +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
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
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
LongYinan
52c424a956
fix(napi): needless cast to CString before call napi_create_string_utf8 (#2321) 2024-10-21 12:48:43 +08:00
LongYinan
161758393f
fix(napi): TypedArray is not ArrayBuffer in Deno (#2314) 2024-10-17 16:36:21 +08:00
Richer
383b5d023c
fix(napi): before using from_raw_parts should check if data is null (#2311) 2024-10-15 16:47:34 +08:00
Richer
16fc9cbe31
feat(napi): support arraybuffer for de (#2296)
* feat(napi): support arraybuffer for de

* use BufferSlice

* clippy fix

---------

Co-authored-by: LongYinan <lynweklm@gmail.com>
2024-10-14 00:24:45 +08:00
LongYinan
af68b685f5
chore: set DISABLE_V8_COMPILE_CACHE in docker test (#2307) 2024-10-14 00:14:09 +08:00
LongYinan
afd081d003
feat(napi,napi-derive): allow lifetime in Class (#2298) 2024-10-10 05:59:14 +02:00
LongYinan
f704b4ac0f
feat(napi-derive): add async_runtime attribute (#2270) 2024-09-23 16:21:13 +08:00
LongYinan
0698bb1d80
feat(napi-derive): allow napi fn with lifetime (#2266) 2024-09-21 12:26:41 +08:00
LongYinan
521ef58f59
refactor(napi): allow create BufferSlice from external data (#2263)
- also refactor the enum codegen, now we will not emit #[derive(Copy,
  Clone)] for the original enums.
- also refacotr the fn codegen, now #[napi] fn can accept env: &Env as
  argument, this is useful when the return type contains lifetime
2024-09-19 22:22:33 +08:00
Igor Matuszewski
cc21452f65
fix(napi): nullptr handling in TypedArrays (#2258)
* fix: Safely return empty slices if TypedArray buffer is null ptr

* fix: Only dispose of TypedArray if the data is not a nullptr

* test: Add a regression test for typed array null ptr deref
2024-09-19 13:38:19 +08:00
Richer
5934ecd2a9
feat(napi): mark JsArraybufferValue's value pub (#2226) 2024-08-23 22:25:52 +08:00
CPunisher
249c27e06d
fix(napi-derive): tuple object and enum (#2227)
* Fix tuple struct

* Add testcase
2024-08-23 14:10:39 +08:00
CPunisher
c459f0acf6
feat: support structured enum with discriminated unions (#2222)
* Structured enum

* Type indent

* Add test example

* Remove trailing commas

* discriminant

* discriminant conflict

* more test

* typo
2024-08-22 14:59:50 +08:00
LongYinan
3f6822d9cd
test: skip unstable test in WASI env (#2196) 2024-07-24 12:09:08 +08:00
LongYinan
727f5a831a
test: skip memory exhausting test in wasi env (#2185) 2024-07-13 02:34:04 +08:00
LongYinan
3a511bacee
fix(napi): Promise callbacks should require static lifetime (#2172) 2024-07-07 20:42:17 +08:00
LongYinan
bc9e931a4e
feat(napi): provide PromiseRaw for non-await scenario (#2168) 2024-07-06 19:09:16 +08:00