feat(native): upgrade NAPI-RS to 3.0.0 beta (#12652)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
	- Added a default export for the native binding in the frontend native module, allowing easier imports.

- **Refactor**
	- Streamlined and updated Rust-to-JavaScript type conversions and lifetime handling for improved safety and consistency.
	- Improved object and array construction in Rust modules for more idiomatic usage.
	- Simplified boolean and null value handling in JavaScript interop layers.

- **Chores**
	- Upgraded several dependencies and development tools to newer versions across backend, frontend, and common packages.
	- Updated build scripts for the frontend native package to simplify commands.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Brooooooklyn
2025-05-29 16:09:31 +00:00
parent 2a7f0162cf
commit e1ce42a6fc
12 changed files with 320 additions and 409 deletions
+6 -6
View File
@@ -1,5 +1,5 @@
use napi::{
bindgen_prelude::{Array as JsArray, Env, Unknown},
bindgen_prelude::{Array as JsArray, Env, JsObjectValue, JsValue, Null, ToNapiValue, Unknown},
ValueType,
};
use y_octo::{Any, Array, Value};
@@ -34,18 +34,18 @@ impl YArray {
}
#[napi(ts_generic_types = "T = unknown", ts_return_type = "T")]
pub fn get(&self, env: Env, index: i64) -> Result<MixedYType> {
pub fn get<'a>(&'a self, env: &'a Env, index: i64) -> Result<MixedYType<'a>> {
if let Some(value) = self.array.get(index as u64) {
match value {
Value::Any(any) => get_js_unknown_from_any(env, any).map(MixedYType::D),
Value::Array(array) => Ok(MixedYType::A(YArray::inner_new(array))),
Value::Map(map) => Ok(MixedYType::B(YMap::inner_new(map))),
Value::Text(text) => Ok(MixedYType::C(YText::inner_new(text))),
_ => env.get_null().map(|v| v.into_unknown()).map(MixedYType::D),
_ => Null.into_unknown(env).map(MixedYType::D),
}
.map_err(anyhow::Error::from)
} else {
Ok(MixedYType::D(env.get_null()?.into_unknown()))
Ok(MixedYType::D(Null.into_unknown(env)?))
}
}
@@ -73,7 +73,7 @@ impl YArray {
.array
.insert(index as u64, Any::Null)
.map_err(anyhow::Error::from),
ValueType::Boolean => match unknown.coerce_to_bool().and_then(|v| v.get_value()) {
ValueType::Boolean => match unsafe { unknown.cast::<bool>() } {
Ok(boolean) => self
.array
.insert(index as u64, boolean)
@@ -140,7 +140,7 @@ impl YArray {
}
#[napi]
pub fn to_json(&self, env: Env) -> Result<JsArray> {
pub fn to_json<'env>(&'env self, env: &'env Env) -> Result<JsArray<'env>> {
let mut js_array = env.create_array(0)?;
for value in self.array.iter() {
js_array.insert(get_js_unknown_from_value(env, value)?)?;