omry_service/
service.rs

1//! [`tarpc`] service definition for Omry.
2use omry_archiving::{Record, RecordMeta, RecordParams};
3use omry_common::RecordId;
4use omry_search::SearchResponse;
5use serde::{Deserialize, Serialize};
6use std::sync::Arc;
7
8use crate::search_wrappers::SearchParametersWrapper;
9
10/// Status returned by the service.
11#[allow(missing_docs)]
12#[derive(Debug, Serialize, Deserialize)]
13pub enum ResponseStatus {
14    Ok,
15    Error,
16}
17
18/// flora RPC service error.
19pub type FloraError = String;
20
21/// Result alias for fallible operations with flora RPC service.
22pub type OmryResult<T> = Result<T, FloraError>;
23
24/// Type alias for a collection of record IDs.
25pub type RecordIds = Vec<RecordId>;
26
27/// Expected message on successful ping.
28pub const PONG: &str = "pong 🌱";
29
30/// Semantic version of the Omry service.
31pub const VERSION: &str = env!("CARGO_PKG_VERSION");
32
33/// Omry service RPCs.
34#[allow(missing_docs)]
35#[tarpc::service]
36pub trait FloraService {
37    /// Pings the server. Can be used to check the server is alive.
38    ///
39    /// A server is expected to respond with [`PONG`].
40    async fn ping() -> String;
41
42    /// Adds a record to flora.
43    async fn add_record(record_params: RecordParams) -> OmryResult<RecordId>;
44
45    /// Adds multiple records to flora.
46    async fn add_many_records(records: Vec<RecordParams>) -> OmryResult<RecordIds>;
47
48    /// Returns the count of records in the database.
49    async fn count() -> OmryResult<i64>;
50
51    /// Gets records matching the given IDs.
52    async fn get_records(record_ids: RecordIds) -> OmryResult<Arc<Vec<Record>>>;
53
54    /// Gets all records in the Omry database.
55    async fn get_all_records() -> OmryResult<Arc<Vec<Record>>>;
56
57    /// Gets the metadata (all fields except `document`)
58    /// for all records in the Omry database.
59    async fn get_all_records_meta() -> OmryResult<Vec<RecordMeta>>;
60
61    /// Deletes record with the given ID.
62    async fn delete_record(record_id: RecordId) -> OmryResult<usize>;
63
64    /// Searches Omry's Typesense instance.
65    async fn search(search_params: SearchParametersWrapper) -> OmryResult<SearchResponse>;
66
67    /// Returns the version of the Omry service.
68    async fn version() -> OmryResult<String>;
69}