mod.rs 1014 B

1234567891011121314151617181920212223242526272829303132
  1. mod middleware;
  2. mod server_api;
  3. mod server_api_mock;
  4. pub use server_api::*;
  5. // TODO: ignore mock files in production
  6. use crate::{
  7. entities::doc::{CreateDocParams, Doc, QueryDocParams, UpdateDocParams},
  8. errors::DocError,
  9. };
  10. use flowy_infra::future::ResultFuture;
  11. pub use server_api_mock::*;
  12. use std::sync::Arc;
  13. pub(crate) type Server = Arc<dyn DocumentServerAPI + Send + Sync>;
  14. pub trait DocumentServerAPI {
  15. fn create_doc(&self, token: &str, params: CreateDocParams) -> ResultFuture<Doc, DocError>;
  16. fn read_doc(&self, token: &str, params: QueryDocParams) -> ResultFuture<Option<Doc>, DocError>;
  17. fn update_doc(&self, token: &str, params: UpdateDocParams) -> ResultFuture<(), DocError>;
  18. fn delete_doc(&self, token: &str, params: QueryDocParams) -> ResultFuture<(), DocError>;
  19. }
  20. pub(crate) fn construct_doc_server() -> Arc<dyn DocumentServerAPI + Send + Sync> {
  21. if cfg!(feature = "http_server") {
  22. Arc::new(DocServer {})
  23. } else {
  24. Arc::new(DocServerMock {})
  25. }
  26. }