Skip to main content

vantage_vista/forward/
blanket.rs

1//! Every `ForwardShell + Clone` is a [`TableShell`]: each method calls the
2//! wrapper's `ForwardShell` version, whether overridden or forwarded.
3
4use async_trait::async_trait;
5use ciborium::Value as CborValue;
6use indexmap::IndexMap;
7use vantage_core::Result;
8use vantage_types::Record;
9
10use super::ForwardShell;
11use crate::{
12    Condition, NativeCondition, Page, Preview, SortDirection, TableShell, Vista, VistaCapabilities,
13    VistaChangeStream, VistaMetadata,
14};
15
16type Rec = Record<CborValue>;
17
18#[async_trait]
19impl<T: ForwardShell + Clone> TableShell for T {
20    fn metadata(&self) -> &VistaMetadata {
21        ForwardShell::metadata(self)
22    }
23    fn capabilities(&self) -> &VistaCapabilities {
24        ForwardShell::capabilities(self)
25    }
26    fn driver_name(&self) -> &'static str {
27        ForwardShell::driver_name(self)
28    }
29    fn preview(&self) -> Preview {
30        ForwardShell::preview(self)
31    }
32    #[cfg(feature = "rhai")]
33    fn register_rhai_extensions(&self, engine: &mut vantage_rhai::rhai::Engine) {
34        ForwardShell::register_rhai_extensions(self, engine)
35    }
36
37    async fn list(&self) -> Result<IndexMap<String, Rec>> {
38        ForwardShell::list(self).await
39    }
40    async fn get(&self, id: &str) -> Result<Option<Rec>> {
41        ForwardShell::get(self, id).await
42    }
43    async fn count(&self) -> Result<i64> {
44        ForwardShell::count(self).await
45    }
46    async fn fetch_window(&self, offset: usize, limit: usize) -> Result<Page> {
47        ForwardShell::fetch_window(self, offset, limit).await
48    }
49    async fn fetch_cursor(
50        &self,
51        token: Option<CborValue>,
52        limit: usize,
53    ) -> Result<(Page, Option<CborValue>)> {
54        ForwardShell::fetch_cursor(self, token, limit).await
55    }
56    async fn watch(&self) -> Result<VistaChangeStream> {
57        ForwardShell::watch(self).await
58    }
59
60    fn add_condition(&mut self, condition: &Condition) -> Result<()> {
61        ForwardShell::add_condition(self, condition)
62    }
63    fn add_native_condition(&mut self, condition: NativeCondition) -> Result<()> {
64        ForwardShell::add_native_condition(self, condition)
65    }
66    fn set_search(&mut self, text: Option<&str>) -> Result<()> {
67        ForwardShell::set_search(self, text)
68    }
69    fn set_order(&mut self, order: Option<(&str, SortDirection)>) -> Result<()> {
70        ForwardShell::set_order(self, order)
71    }
72
73    async fn insert(&self, id: Option<&str>, record: &Rec) -> Result<(String, Rec)> {
74        ForwardShell::insert(self, id, record).await
75    }
76    async fn replace(&self, id: &str, record: &Rec) -> Result<Rec> {
77        ForwardShell::replace(self, id, record).await
78    }
79    async fn upsert(&self, id: &str, record: &Rec) -> Result<Rec> {
80        ForwardShell::upsert(self, id, record).await
81    }
82    async fn patch(&self, id: &str, partial: &Rec) -> Result<Rec> {
83        ForwardShell::patch(self, id, partial).await
84    }
85    async fn delete(&self, id: &str) -> Result<()> {
86        ForwardShell::delete(self, id).await
87    }
88    async fn delete_all(&self) -> Result<()> {
89        ForwardShell::delete_all(self).await
90    }
91    async fn import(&self, rows: &IndexMap<String, Rec>) -> Result<usize> {
92        ForwardShell::import(self, rows).await
93    }
94
95    fn get_ref(&self, relation: &str, row: Option<&Rec>) -> Result<Vista> {
96        ForwardShell::get_ref(self, relation, row)
97    }
98}