* 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.
- 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
* 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
* Add test for #2083
* Add test for serde_byte with empty buffer
* Fix using serde_bytes with empty buffers
* skip wasi test
* fix test
* clippy fix
* avoid ub
* use safer impl
---------
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
Co-authored-by: LongYinan <lynweklm@gmail.com>
* Refactor js-binding to support bundling single-package artifacts
The existsSync check breaks the bundlers I've tested (esbuild, webpack,
ncc), so you cannot bundle napi-rs packages that have all binarys in a
single package.
I've tested this change with both single package and multi package
libraries.
* Update snapshots
* Update CI
* Fix electron test
---------
Co-authored-by: Caleb ツ Everett <calebev@amazon.com>
Co-authored-by: LongYinan <lynweklm@gmail.com>