mdvault_core/scripting/
vault_context.rs1use std::path::PathBuf;
7use std::sync::Arc;
8
9use crate::captures::CaptureRepository;
10use crate::config::types::ResolvedConfig;
11use crate::index::IndexDb;
12use crate::macros::MacroRepository;
13use crate::templates::repository::TemplateRepository;
14use crate::types::TypeRegistry;
15
16use super::selector::SelectorCallback;
17
18#[derive(Clone, Debug)]
23pub struct CurrentNote {
24 pub path: String,
26 pub note_type: String,
28 pub title: Option<String>,
30 pub frontmatter: Option<serde_yaml::Value>,
32 pub content: String,
34}
35
36#[derive(Clone)]
41pub struct VaultContext {
42 pub config: Arc<ResolvedConfig>,
44 pub template_repo: Arc<TemplateRepository>,
46 pub capture_repo: Arc<CaptureRepository>,
48 pub macro_repo: Arc<MacroRepository>,
50 pub type_registry: Arc<TypeRegistry>,
52 pub index_db: Option<Arc<IndexDb>>,
54 pub current_note: Option<CurrentNote>,
56 pub vault_root: PathBuf,
58 pub selector_callback: Option<SelectorCallback>,
60}
61
62impl VaultContext {
63 pub fn new(
65 config: ResolvedConfig,
66 template_repo: TemplateRepository,
67 capture_repo: CaptureRepository,
68 macro_repo: MacroRepository,
69 type_registry: TypeRegistry,
70 ) -> Self {
71 let vault_root = config.vault_root.clone();
72 Self {
73 config: Arc::new(config),
74 template_repo: Arc::new(template_repo),
75 capture_repo: Arc::new(capture_repo),
76 macro_repo: Arc::new(macro_repo),
77 type_registry: Arc::new(type_registry),
78 index_db: None,
79 current_note: None,
80 vault_root,
81 selector_callback: None,
82 }
83 }
84
85 pub fn from_arcs(
87 config: Arc<ResolvedConfig>,
88 template_repo: Arc<TemplateRepository>,
89 capture_repo: Arc<CaptureRepository>,
90 macro_repo: Arc<MacroRepository>,
91 type_registry: Arc<TypeRegistry>,
92 ) -> Self {
93 let vault_root = config.vault_root.clone();
94 Self {
95 config,
96 template_repo,
97 capture_repo,
98 macro_repo,
99 type_registry,
100 index_db: None,
101 current_note: None,
102 vault_root,
103 selector_callback: None,
104 }
105 }
106
107 pub fn with_index(mut self, index_db: Arc<IndexDb>) -> Self {
109 self.index_db = Some(index_db);
110 self
111 }
112
113 pub fn with_current_note(mut self, note: CurrentNote) -> Self {
115 self.current_note = Some(note);
116 self
117 }
118
119 pub fn with_selector(mut self, callback: SelectorCallback) -> Self {
124 self.selector_callback = Some(callback);
125 self
126 }
127}