78 Commits

Author SHA1 Message Date
LongYinan
18816c710c
refactor!(napi): move JsObjectValue into bindgen_runtime (#2649) 2025-05-18 22:29:45 +08:00
LongYinan
9de545e7a2
refactor!(napi): add lifetime to Object (#2619) 2025-05-11 19:51:29 +08:00
LongYinan
65fe29c854
refactor!(napi): add lifetime to JsString (#2614) 2025-05-08 13:20:09 +08:00
LongYinan
813c51e16a
refactor!(napi): move depracated types behind compat-mode feature flag (#2612) 2025-05-07 22:34:26 +08:00
LongYinan
23e9de2caa
refactor!(napi): add lifetime to Unkonwn (#2611)
Remove JsUnknown
2025-05-07 22:32:24 +08:00
LongYinan
a456fcdbc7
refactor!(napi): add lifetime for JsNumber (#2609) 2025-05-07 20:11:33 +08:00
LongYinan
95832ff168
refactor!(napi): introduce JsValue and JsObjectValue trait (#2606)
Add lifetime for JsGlobal JsTimeout and JSON
2025-05-06 23:45:37 +08:00
LongYinan
ebcf0ea88e
fix(napi-derive): make_ref with Vec<&S> cases (#2589)
- Close https://github.com/napi-rs/napi-rs/issues/2571
2025-05-02 23:13:46 +08:00
renovate[bot]
06215529d8
chore(deps): update dependency sinon to v20 (#2526)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-03-26 21:32:30 +08:00
LongYinan
c62acd2bfe
chore: upgrade npm dependencies (#2516) 2025-03-16 22:29:04 +08:00
LongYinan
d96bd288de
fix!(napi): upgrade to ctor 0.3.6 (#2472) 2025-02-20 12:22:29 +08:00
LongYinan
0ce8fab19c
chore(napi): merge thread cleanup (#2469) 2025-02-16 16:55:16 +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
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
Stanisław Czech
272334c69f
fix(napi): update logic for handling signed integers (#2356)
* Fix from functions for BigInt

Allow proper parsing of negative integers in those functions.

Fixes the pannic when calling:
BigInt::from(i128::MIN);

* Fix get_i128 and get_i64 for BigInt

Update the getter logic to take sign into account.

for get_i128 and get_u128 make lossless value consistent with the documentation
(documentation described different behavior then the code logic)

* Extend tests for BigInt types

Add more test cases for negative i64 and i128 to test the created changes

* Simplify the to napiValue logic for 128 bit types

Update the logic to handle negative values properly

Refactor to_napi_value and create_bigint_from_*128 to use the same logic
instead of copping mostly the same code 4 times

* Fix specification for deserialize object test

For unknown reason the binary specification was holding different value than spec file
2024-11-18 23:12:11 +08:00
Richer
48b3b238de
feat(napi): allow us to create nest function from closure (#2360) 2024-11-18 21:28:47 +08:00
LongYinan
79cbb9170e
fix!(sys): Node-API accpet NAPI_AUTO_LENGTH parameter type should be isize rather than usize (#2331) 2024-10-28 23:45:32 +08:00
LongYinan
72afae3736
refactor!(napi): Ref::unref accept &mut self instead of self (#2308) 2024-10-14 11:14:25 +08:00
LongYinan
4496ffd220
chore: refresh npm dependencies (#2303) 2024-10-13 23:50:57 +08:00
LongYinan
afd081d003
feat(napi,napi-derive): allow lifetime in Class (#2298) 2024-10-10 05:59:14 +02:00
LongYinan
724673225a
refactor!(napi): remove clone fn on ThreadsafeFunction (#2291) 2024-10-07 19:23:11 +02:00
LongYinan
a4a8d31a42
chore(napi): remove once_cell (#2271) 2024-09-23 16:57:14 +08:00
Richer
fec8ff4704
chore(example): use BufferSlice to replace JsBuffer (#2269)
* chore(example): use BufferSlice to replace JsBuffer

* chore: use BufferSlice to replace env method
2024-09-22 22:53:15 +08:00
renovate[bot]
382ed9442c
chore(deps): update dependency sinon to v19 (#2251) 2024-09-14 09:57:39 +08:00
LongYinan
bf8f568788
refactor!(napi): Ref should not hold the value ptr (#2243)
It's unsafe
2024-09-12 23:25:09 +08:00
LongYinan
bc9e931a4e
feat(napi): provide PromiseRaw for non-await scenario (#2168) 2024-07-06 19:09:16 +08:00
LongYinan
ea623903d8
chore: clippy fix (#2144) 2024-06-18 13:20:43 +08:00
Ranger
19e3488efc
fix(napi): JsString should respect \0 character to align with String (#2138)
* fix(napi): JsString should respect \0 character to align with String

* chore(test): update snapshot
2024-06-12 15:20:27 +08:00
Ranger
80d9d87ef9
chore(example): remove JsFunction from example (#2123)
* chore(example): remove jsfunction

* feat(napi): implement ToNapiValue for Ref as required by TSFN

* fix(test): tsfn test build failed

* chore: lint code

* fix(test): fix tsfn unit test
2024-05-26 21:07:01 +08:00
Ranger
a3b01870a3
feat(napi): support External for compact mode and add JsExternal as deprecated (#2125) 2024-05-26 14:43:33 +08:00
magic-akari
734d74bd02
fix(typegen): add missing declare keyword (#2117) 2024-05-19 16:53:23 +08:00
renovate[bot]
04da0d9fd1
chore(deps): update dependency sinon to v18 (#2112)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-16 14:27:55 +08:00
LongYinan
4572ede9f5
refactor(napi): split T and CallJsBackArgs generic type (#2091) 2024-05-06 18:25:40 +08:00
LongYinan
f2e5094345
feat(napi-sys): support load Node-API symbols dynamically (#2014) 2024-03-27 14:35:16 +08:00
LongYinan
0550c56fcf
fix(napi): External should impl FromNapiRef rather than FromNapiValue (#2013)
- Close https://github.com/napi-rs/napi-rs/issues/1994
2024-03-25 15:11:11 +08:00
LongYinan
4719caa643
feat(napi): support Return generic of ThreadsafeFunction (#1997)
* feat(napi): support to use tuple with either (#1993)

`Either` uses `ValidateNapiValue` + `TypeName` to validate and report error on value not being matched. So there's no way to remove these super traits from it. So I implemented these types to `Tuple` types.

* feat(napi): support `Return` generic of ThreadsafeFunction

* depracate JsFunction

* CalleeHandled tsfn should handle Result in callback

* Pass env to call_with_return_value callback

* Fix compile

* clippy fix

* Fix electron test

* Function args

---------

Co-authored-by: Hana <andywangsy@gmail.com>
2024-03-20 21:37:08 +08:00
LongYinan
0007e3aaf6
chore: upgrade all dependencies (#1933) 2024-02-01 12:14:56 +08:00
Janrupf
ac3626a023
fix(napi): Fix buffer corruption and soundness issues (#1923)
* fix(napi): Fix buffer corruption and soundness issues

* test: fix tests to conform to buffer API
2024-01-29 18:32:28 +08:00
liuyi
e32c105a26
fix(napi-derive): upgrade syn (#1849) 2023-12-13 12:40:01 +08:00
LongYinan
db89395966
chore: upgrade all npm dependencies (#1843) 2023-12-06 19:41:21 +08:00
LongYinan
7a3cd77bc8
ci: add YARN_IGNORE_NODE on macOS arm64 build 2023-11-02 20:32:36 +08:00
Tom Sherman
3418fd3e8f
feat(napi,sys): implement Symbol.for (#1721)
Co-authored-by: LongYinan <lynweklm@gmail.com>
2023-09-13 15:45:14 -07:00
LongYinan
05b4be4d80
style: clippy fix (#1711) 2023-08-30 16:41:13 +08:00
LongYinan
6d62b3f714
chore: upgrade dependencies (#1657) 2023-07-17 14:56:02 +08:00
LongYinan
1d78f6c294
chore: upgrade npm dependencies (#1557) 2023-04-11 10:47:52 +08:00
forehal
a781a4f27e feat(cli): brand new cli tool with both cli and programmatical usage (#1492)
BREAKING CHANGE: requires node >= 16 and some cli options have been renamed
2023-04-06 11:04:53 +08:00
Victor Teo
aee742f185
feat(napi): property getter and setter with closure (#1526)
* getter with closure with segment fault

* fix getter closure pointer

* add setter

* Cleanup API

* Add test for `create_function_from_closure`

* Fix compile error

* Fix flaky test title

---------

Co-authored-by: LongYinan <lynweklm@gmail.com>
2023-03-21 11:22:07 +08:00
LongYinan
e9de5681be
fix(napi): also apply electron external data fallback to lowlevel APIs (#1458)
* fix(napi): also apply electron external data fallback to lowlevel APIs

* chore: allow uninlined_format_args in tests
2023-01-28 21:31:57 +08:00
LongYinan
62b16d6a89
chore: upgrade npm dependencies (#1443) 2023-01-19 00:32:52 +08:00