2024-06-12 16:32:28 +08:00
|
|
|
pub use client_api::entity::ai_dto::{TranslateItem, TranslateRowResponse};
|
2024-08-18 05:16:42 +02:00
|
|
|
use collab::entity::EncodedCollab;
|
2023-10-10 19:05:55 +08:00
|
|
|
use collab_entity::CollabType;
|
2024-07-22 09:43:48 +02:00
|
|
|
use flowy_error::FlowyError;
|
2024-08-01 23:13:35 +08:00
|
|
|
use lib_infra::async_trait::async_trait;
|
2024-03-23 09:18:47 +08:00
|
|
|
use std::collections::HashMap;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
2024-08-18 05:16:42 +02:00
|
|
|
pub type EncodeCollabByOid = HashMap<String, EncodedCollab>;
|
2024-05-05 22:04:34 +08:00
|
|
|
pub type SummaryRowContent = HashMap<String, String>;
|
2024-06-12 16:32:28 +08:00
|
|
|
pub type TranslateRowContent = Vec<TranslateItem>;
|
2024-08-01 23:13:35 +08:00
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
pub trait DatabaseAIService: Send + Sync {
|
|
|
|
async fn summary_database_row(
|
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_object_id: &str,
|
|
|
|
_summary_row: SummaryRowContent,
|
|
|
|
) -> Result<String, FlowyError> {
|
|
|
|
Ok("".to_string())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn translate_database_row(
|
|
|
|
&self,
|
|
|
|
_workspace_id: &str,
|
|
|
|
_translate_row: TranslateRowContent,
|
|
|
|
_language: &str,
|
|
|
|
) -> Result<TranslateRowResponse, FlowyError> {
|
|
|
|
Ok(TranslateRowResponse::default())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-29 09:46:24 +08:00
|
|
|
/// A trait for database cloud service.
|
|
|
|
/// Each kind of server should implement this trait. Check out the [AppFlowyServerProvider] of
|
|
|
|
/// [flowy-server] crate for more information.
|
2024-03-30 16:28:24 +08:00
|
|
|
///
|
|
|
|
/// returns the doc state of the object with the given object_id.
|
|
|
|
/// None if the object is not found.
|
2024-08-01 23:13:35 +08:00
|
|
|
///
|
|
|
|
#[async_trait]
|
2023-07-29 09:46:24 +08:00
|
|
|
pub trait DatabaseCloudService: Send + Sync {
|
2024-08-18 05:16:42 +02:00
|
|
|
async fn get_database_encode_collab(
|
2023-07-29 09:46:24 +08:00
|
|
|
&self,
|
|
|
|
object_id: &str,
|
2023-10-02 17:22:22 +08:00
|
|
|
collab_type: CollabType,
|
2023-10-23 11:43:31 +08:00
|
|
|
workspace_id: &str,
|
2024-10-26 11:20:16 +08:00
|
|
|
) -> Result<Option<EncodedCollab>, FlowyError>;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
2024-09-15 00:02:17 +08:00
|
|
|
async fn create_database_encode_collab(
|
|
|
|
&self,
|
|
|
|
object_id: &str,
|
|
|
|
collab_type: CollabType,
|
|
|
|
workspace_id: &str,
|
|
|
|
encoded_collab: EncodedCollab,
|
2024-10-26 11:20:16 +08:00
|
|
|
) -> Result<(), FlowyError>;
|
2024-09-15 00:02:17 +08:00
|
|
|
|
2024-08-18 05:16:42 +02:00
|
|
|
async fn batch_get_database_encode_collab(
|
2023-07-29 09:46:24 +08:00
|
|
|
&self,
|
|
|
|
object_ids: Vec<String>,
|
|
|
|
object_ty: CollabType,
|
2023-10-23 11:43:31 +08:00
|
|
|
workspace_id: &str,
|
2024-10-26 11:20:16 +08:00
|
|
|
) -> Result<EncodeCollabByOid, FlowyError>;
|
2023-07-29 09:46:24 +08:00
|
|
|
|
2024-08-18 05:16:42 +02:00
|
|
|
async fn get_database_collab_object_snapshots(
|
2023-07-29 09:46:24 +08:00
|
|
|
&self,
|
|
|
|
object_id: &str,
|
2023-08-17 23:46:39 +08:00
|
|
|
limit: usize,
|
2024-10-26 11:20:16 +08:00
|
|
|
) -> Result<Vec<DatabaseSnapshot>, FlowyError>;
|
2023-07-29 09:46:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DatabaseSnapshot {
|
|
|
|
pub snapshot_id: i64,
|
|
|
|
pub database_id: String,
|
|
|
|
pub data: Vec<u8>,
|
|
|
|
pub created_at: i64,
|
|
|
|
}
|