mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(native): opt out napi-derive noop feature (#12686)
It would cause the napi-derive not work as expect in workspace level <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved internal handling and type definitions for document parsing, resulting in clearer and more maintainable data structures. - **Chores** - Introduced a new feature flag for mobile native builds, enabling conditional compilation for enhanced flexibility across Android and iOS. - Updated build scripts to support the new feature flag for both Android and iOS platforms. - Updated iOS app dependencies to newer versions, including Apollo iOS, ChidoriMenu, and swift-collections, and removed SQLite.swift. - **Tests** - Enhanced Rust linting and testing workflows to run selectively across workspace packages with the new feature flag enabled. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
12
packages/backend/native/index.d.ts
vendored
12
packages/backend/native/index.d.ts
vendored
@@ -8,6 +8,11 @@ export const AFFINE_PRO_LICENSE_AES_KEY: string | undefined | null
|
||||
|
||||
export const AFFINE_PRO_PUBLIC_KEY: string | undefined | null
|
||||
|
||||
export interface Chunk {
|
||||
index: number
|
||||
content: string
|
||||
}
|
||||
|
||||
export declare function fromModelName(modelName: string): Tokenizer | null
|
||||
|
||||
export declare function getMime(input: Uint8Array): string
|
||||
@@ -22,6 +27,11 @@ export declare function mergeUpdatesInApplyWay(updates: Array<Buffer>): Buffer
|
||||
|
||||
export declare function mintChallengeResponse(resource: string, bits?: number | undefined | null): Promise<string>
|
||||
|
||||
export declare function parseDoc(filePath: string, doc: Buffer): Promise<{ name: string, chunks: Array<{index: number, content: string}> }>
|
||||
export interface ParsedDoc {
|
||||
name: string
|
||||
chunks: Array<Chunk>
|
||||
}
|
||||
|
||||
export declare function parseDoc(filePath: string, doc: Buffer): Promise<ParsedDoc>
|
||||
|
||||
export declare function verifyChallengeResponse(response: string, bits: number, resource: string): Promise<boolean>
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
use affine_common::doc_loader::Doc;
|
||||
use napi::{
|
||||
anyhow::anyhow,
|
||||
bindgen_prelude::{Array, AsyncTask, Buffer, Object},
|
||||
bindgen_prelude::{AsyncTask, Buffer},
|
||||
Env, Result, Task,
|
||||
};
|
||||
|
||||
#[napi(object)]
|
||||
pub struct Chunk {
|
||||
pub index: i64,
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
#[napi(object)]
|
||||
pub struct ParsedDoc {
|
||||
pub name: String,
|
||||
pub chunks: Vec<Chunk>,
|
||||
}
|
||||
|
||||
pub struct Document {
|
||||
inner: Doc,
|
||||
}
|
||||
@@ -14,21 +26,20 @@ impl Document {
|
||||
self.inner.name.clone()
|
||||
}
|
||||
|
||||
fn chunks(&self, env: &Env) -> Result<Array> {
|
||||
let vec = self
|
||||
fn chunks(&self) -> Vec<Chunk> {
|
||||
self
|
||||
.inner
|
||||
.chunks
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, chunk)| {
|
||||
let content = crate::utils::clean_content(&chunk.content);
|
||||
let mut obj = Object::new(env)?;
|
||||
obj.set("index", i as i64)?;
|
||||
obj.set("content", content)?;
|
||||
Ok(obj)
|
||||
Chunk {
|
||||
index: i as i64,
|
||||
content,
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<Object>>>()?;
|
||||
Array::from_vec(env, vec)
|
||||
.collect::<Vec<Chunk>>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,24 +51,22 @@ pub struct AsyncParseDocResponse {
|
||||
#[napi]
|
||||
impl Task for AsyncParseDocResponse {
|
||||
type Output = Document;
|
||||
type JsValue = Object<'static>;
|
||||
type JsValue = ParsedDoc;
|
||||
|
||||
fn compute(&mut self) -> Result<Self::Output> {
|
||||
let doc = Doc::new(&self.file_path, &self.doc).map_err(|e| anyhow!(e))?;
|
||||
Ok(Document { inner: doc })
|
||||
}
|
||||
|
||||
fn resolve(&mut self, env: Env, doc: Document) -> Result<Self::JsValue> {
|
||||
let mut obj = Object::new(&env)?;
|
||||
obj.set("name", doc.name())?;
|
||||
obj.set("chunks", doc.chunks(&env)?)?;
|
||||
Ok(obj)
|
||||
fn resolve(&mut self, _: Env, doc: Document) -> Result<Self::JsValue> {
|
||||
Ok(ParsedDoc {
|
||||
name: doc.name(),
|
||||
chunks: doc.chunks(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[napi(
|
||||
ts_return_type = "Promise<{ name: string, chunks: Array<{index: number, content: string}> }>"
|
||||
)]
|
||||
#[napi]
|
||||
pub fn parse_doc(file_path: String, doc: Buffer) -> AsyncTask<AsyncParseDocResponse> {
|
||||
AsyncTask::new(AsyncParseDocResponse {
|
||||
file_path,
|
||||
|
||||
Reference in New Issue
Block a user