1use surrealdb_types::SurrealValue;
5
6#[derive(Clone, Debug, SurrealValue)]
7#[surreal(crate = "surrealdb_types")]
8#[surreal(default)]
9pub struct Config {
10 pub database_definition: bool,
16 pub users: bool,
17 pub accesses: bool,
18 pub params: bool,
19 pub functions: bool,
20 pub analyzers: bool,
21 pub apis: bool,
22 pub buckets: bool,
23 pub modules: bool,
24 pub configs: bool,
25 pub tables: TableConfig,
26 pub versions: bool,
27 pub records: bool,
28 pub sequences: bool,
29}
30
31impl Default for Config {
32 fn default() -> Config {
33 Config {
34 database_definition: true,
35 users: true,
36 accesses: true,
37 params: true,
38 functions: true,
39 analyzers: true,
40 apis: true,
41 buckets: true,
42 modules: true,
43 configs: true,
44 tables: TableConfig::default(),
45 versions: false,
46 records: true,
47 sequences: true,
48 }
49 }
50}
51
52#[derive(Clone, Debug, SurrealValue)]
55#[surreal(crate = "surrealdb_types")]
56pub struct ExcludedTables {
57 pub exclude: Vec<String>,
58}
59
60#[derive(Clone, Debug, Default, SurrealValue)]
61#[surreal(crate = "surrealdb_types")]
62#[surreal(untagged)]
63pub enum TableConfig {
64 #[default]
65 #[surreal(value = true)]
66 All,
67 #[surreal(value = false)]
68 None,
69 Some(Vec<String>),
70 Exclude(ExcludedTables),
71}
72
73impl From<bool> for TableConfig {
78 fn from(value: bool) -> Self {
79 match value {
80 true => TableConfig::All,
81 false => TableConfig::None,
82 }
83 }
84}
85
86impl From<Vec<String>> for TableConfig {
87 fn from(value: Vec<String>) -> Self {
88 TableConfig::Some(value)
89 }
90}
91
92impl From<Vec<&str>> for TableConfig {
93 fn from(value: Vec<&str>) -> Self {
94 TableConfig::Some(value.into_iter().map(ToOwned::to_owned).collect())
95 }
96}
97
98impl TableConfig {
99 pub fn is_any(&self) -> bool {
101 matches!(self, Self::All | Self::Some(_) | Self::Exclude(_))
102 }
103
104 pub fn includes(&self, table: &str) -> bool {
106 match self {
107 Self::All => true,
108 Self::None => false,
109 Self::Some(v) => v.iter().any(|v| v.eq(table)),
110 Self::Exclude(v) => !v.exclude.iter().any(|v| v.eq(table)),
111 }
112 }
113
114 pub fn names(&self) -> Option<&[String]> {
116 match self {
117 Self::Some(v) => Some(v.as_slice()),
118 Self::Exclude(v) => Some(v.exclude.as_slice()),
119 _ => None,
120 }
121 }
122}