87 Commits

Author SHA1 Message Date
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
LongYinan
52c424a956
fix(napi): needless cast to CString before call napi_create_string_utf8 (#2321) 2024-10-21 12:48:43 +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
d84fc42832
fix(napi-derive): string enum validate logic (#2213) 2024-08-10 21:27:17 +08:00
LongYinan
282ce1c00a
fix(napi): allow ThreadsafeFunction in Either (#2204) 2024-08-03 13:22:09 +08:00
LongYinan
13c18388f5
fix(cli): worker files format (#2186) 2024-07-14 22:23:34 +08:00
LongYinan
731dced1bb
fix(cli): update wasi js binding files on any builds (#2179) 2024-07-09 14:01:23 +08:00
LongYinan
d7a5a7e9a1
test(napi): spwan thread in thread (#2139) 2024-06-24 16:09:07 +08:00
Niklas Mischkulnig
f3d665d5b1
fix(napi): panic when deserializing empty buffer with Rust 1.78 (#2094)
* 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>
2024-05-07 17:57:15 +08:00
LongYinan
46cbcf3ff1
feat(cli): allow sync fs operation between workers/mainThread (#2064)
* feat(cli): allow sync fs operation between workers/mainThread

* allow sync fs operation between workers/mainThread (#2065)

* Fix

* Update fixture

* flaky test

* Fix cross compile target

* Update zig

* macos-cross test was filtered

---------

Co-authored-by: Toyo Li <lifenglin314@outlook.com>
2024-04-23 12:14:06 +08:00
LongYinan
12aec3c135
fix(cli): pass fs to browser worker binding (#2062) 2024-04-22 14:44:37 +08:00
LongYinan
4ccbb61179
feat(cli): improve the browser binding (#2056) 2024-04-19 16:12:30 +08:00
LongYinan
8f5d7e5274
fix(napi): handle panic in async block (#2050)
- Close https://github.com/napi-rs/napi-rs/issues/2047
2024-04-17 23:34:47 +08:00
LongYinan
cc937e1dba
feat(cli): allow control the wasm Memory options via napi config (#2038) 2024-04-15 23:19:02 +08:00
LongYinan
4c7d06fc72
feat(cli): support wasm32-wasipxx targets (#2030)
* chore(examples): update wasi binding template

* wasm32-wasip1
2024-04-10 09:08:57 +08:00
Caleb Everett
95dd6ef485
refactor(cli): refactor js-binding to support easier bundling. (#1957)
* 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>
2024-02-26 15:46:07 +08:00