use crate::api::Result; use theseus::prelude::*; macro_rules! impl_cache_methods { ($(($variant:ident, $type:ty)),*) => { $( paste::paste! { #[tauri::command] pub async fn [](id: &str, cache_behaviour: Option) -> Result> { Ok(theseus::cache::[](id, cache_behaviour).await?) } #[tauri::command] pub async fn []( ids: Vec, cache_behaviour: Option, ) -> Result> { let ids = ids.iter().map(|x| &**x).collect::>(); let entries = theseus::cache::[](&*ids, cache_behaviour).await?; Ok(entries) } } )* } } impl_cache_methods!( (Project, Project), (Version, Version), (User, User), (Team, Vec), (Organization, Organization), (SearchResults, SearchResults) ); pub fn init() -> tauri::plugin::TauriPlugin { tauri::plugin::Builder::new("cache") .invoke_handler(tauri::generate_handler![ get_project, get_project_many, get_version, get_version_many, get_user, get_user_many, get_team, get_team_many, get_organization, get_organization_many, get_search_results, get_search_results_many, purge_cache_types, ]) .build() } #[tauri::command] pub async fn purge_cache_types(cache_types: Vec) -> Result<()> { Ok(theseus::cache::purge_cache_types(&cache_types).await?) }