Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/frilvault-cli/src/command/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use frilvault_core::{AddNoteRequest, FrilVault, LineAnchor, NoteAnchor, SymbolAn
use crate::cli::add::{AddCommand, SymbolKindArg};

pub fn execute(command: AddCommand) -> Result<()> {
let workspace = FrilVault::open(std::env::current_dir()?)?;
let mut service = FrilVault::create_note_service(&workspace)?;
let vault = FrilVault::open(std::env::current_dir()?)?;
let mut service = vault.notes()?;

let anchor = create_anchor(&command)?;

Expand Down
4 changes: 2 additions & 2 deletions apps/frilvault-cli/src/command/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use uuid::Uuid;
use crate::cli::delete::DeleteCommand;

pub fn execute(command: DeleteCommand) -> Result<()> {
let workspace = FrilVault::open(std::env::current_dir()?)?;
let mut service = FrilVault::create_note_service(&workspace)?;
let vault = FrilVault::open(std::env::current_dir()?)?;
let mut service = vault.notes()?;

service.delete_note(&command.file, Uuid::parse_str(&command.id)?)?;

Expand Down
4 changes: 2 additions & 2 deletions apps/frilvault-cli/src/command/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anyhow::Result;
use frilvault_core::FrilVault;

pub fn execute() -> Result<()> {
let workspace = FrilVault::open(std::env::current_dir()?)?;
let mut service = FrilVault::create_workspace_service(&workspace)?;
let vault = FrilVault::open(std::env::current_dir()?)?;
let mut service = vault.workspace()?;

let health = service.health_check()?;

Expand Down
4 changes: 2 additions & 2 deletions apps/frilvault-cli/src/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
};

pub fn execute(command: ListCommand) -> Result<()> {
let workspace = FrilVault::open(std::env::current_dir()?)?;
let mut service = FrilVault::create_note_service(&workspace)?;
let vault = FrilVault::open(std::env::current_dir()?)?;
let mut service = vault.notes()?;

let notes = service.list_notes(&command.file)?;

Expand Down
4 changes: 2 additions & 2 deletions apps/frilvault-cli/src/command/repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use frilvault_core::FrilVault;
use crate::cli::repair::RepairCommand;

pub fn execute(command: RepairCommand) -> Result<()> {
let workspace = FrilVault::open(std::env::current_dir()?)?;
let mut service = FrilVault::create_workspace_service(&workspace)?;
let vault = FrilVault::open(std::env::current_dir()?)?;
let mut service = vault.workspace()?;

if command.apply {
let repaired = service.apply_repairs()?;
Expand Down
4 changes: 2 additions & 2 deletions apps/frilvault-cli/src/command/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
};

pub fn execute(command: SearchCommand) -> Result<()> {
let workspace = FrilVault::open(std::env::current_dir()?)?;
let mut service = FrilVault::create_note_service(&workspace)?;
let vault = FrilVault::open(std::env::current_dir()?)?;
let mut service = vault.notes()?;

let results = match (command.keyword.as_deref(), command.file.as_deref()) {
(Some(keyword), Some(file)) => service
Expand Down
4 changes: 2 additions & 2 deletions apps/frilvault-cli/src/command/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anyhow::Result;
use frilvault_core::FrilVault;

pub fn execute() -> Result<()> {
let workspace = FrilVault::open(std::env::current_dir()?)?;
let mut service = FrilVault::create_workspace_service(&workspace)?;
let vault = FrilVault::open(std::env::current_dir()?)?;
let mut service = vault.workspace()?;

let stats = service.stats()?;

Expand Down
4 changes: 2 additions & 2 deletions apps/frilvault-cli/src/command/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use uuid::Uuid;
use crate::cli::update::UpdateCommand;

pub fn execute(command: UpdateCommand) -> Result<()> {
let workspace = FrilVault::open(std::env::current_dir()?)?;
let mut service = FrilVault::create_note_service(&workspace)?;
let vault = FrilVault::open(std::env::current_dir()?)?;
let mut service = vault.notes()?;

service.update_note(
&command.file,
Expand Down
26 changes: 11 additions & 15 deletions crates/frilvault-core/src/app/frilvault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl FrilVault {
})
}

pub fn create_note_service(&self) -> FrilVaultResult<NoteService> {
fn build_context(&self) -> FrilVaultResult<(VaultContext, WorkspaceIndexRepository)> {
let resolver = PathResolver::new(&self.workspace_root);

let workspace_repository = WorkspaceRepository::new(resolver.clone());
Expand All @@ -29,23 +29,19 @@ impl FrilVault {
index_repository.create_if_missing()?;

let note_repository = YamlNoteRepository::new(resolver.clone());
let vault_context = VaultContext::new(note_repository, index_repository);

Ok(NoteService::new(vault_context))
}

pub fn create_workspace_service(&self) -> FrilVaultResult<WorkspaceService> {
let resolver = PathResolver::new(&self.workspace_root);

let workspace_repository = WorkspaceRepository::new(resolver.clone());
workspace_repository.create_if_missing()?;
let vault_context = VaultContext::new(note_repository, index_repository.clone());

let index_repository = WorkspaceIndexRepository::new(resolver.clone());
index_repository.create_if_missing()?;
Ok((vault_context, index_repository))
}

let note_repository = YamlNoteRepository::new(resolver);
let vault_context = VaultContext::new(note_repository, index_repository.clone());
pub fn notes(&self) -> FrilVaultResult<NoteService> {
let (context, _) = self.build_context()?;
Ok(NoteService::new(context))
}

Ok(WorkspaceService::new(vault_context, index_repository))
pub fn workspace(&self) -> FrilVaultResult<WorkspaceService> {
let (context, index_repository) = self.build_context()?;
Ok(WorkspaceService::new(context, index_repository))
}
}
2 changes: 2 additions & 0 deletions crates/frilvault-core/src/error/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ pub enum FrilVaultError {
#[error("invalid note file path")]
InvalidNoteFilePath,
}

pub type FrilVaultResult<T> = Result<T, FrilVaultError>;
2 changes: 1 addition & 1 deletion crates/frilvault-core/src/error/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod errors;

pub use errors::FrilVaultError;
pub use errors::*;
19 changes: 7 additions & 12 deletions crates/frilvault-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
pub mod app;
pub mod error;
pub mod note;

mod app;
mod constants;
mod error;
mod note;
mod parser;
mod runtime;
mod storage;
mod workspace;

pub use app::*;
pub use error::*;
pub use note::*;
pub use parser::*;
pub use runtime::*;
pub use storage::*;
pub use workspace::*;
pub use app::FrilVault;

pub type FrilVaultResult<T> = Result<T, FrilVaultError>;
pub use error::{FrilVaultError, FrilVaultResult};
pub use note::{AddNoteRequest, LineAnchor, Note, NoteAnchor, NoteView, SymbolAnchor, SymbolKind};
pub use workspace::{RepairSuggestion, WorkspaceHealth, WorkspaceStats};

#[cfg(test)]
mod tests;
4 changes: 2 additions & 2 deletions crates/frilvault-core/src/note/dto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod add_note_request;
pub mod note_view;
mod add_note_request;
mod note_view;

pub use add_note_request::*;
pub use note_view::*;
2 changes: 1 addition & 1 deletion crates/frilvault-core/src/note/entity/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::{add_note_request::AddNoteRequest, note::NoteAnchor};
use crate::{AddNoteRequest, note::NoteAnchor};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Note {
Expand Down
2 changes: 0 additions & 2 deletions crates/frilvault-core/src/note/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod dto;
mod entity;
mod note_repository;
mod note_service;

pub use dto::*;
pub use entity::*;
pub use note_repository::*;
pub use note_service::*;
13 changes: 0 additions & 13 deletions crates/frilvault-core/src/note/note_repository.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/frilvault-core/src/note/note_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use chrono::Utc;
use uuid::Uuid;

use crate::{
FrilVaultError, FrilVaultResult, NoteAnchor, VaultContext, add_note_request::AddNoteRequest,
note::Note, note_view::NoteView,
AddNoteRequest, FrilVaultError, FrilVaultResult, NoteAnchor, NoteView, note::Note,
runtime::VaultContext,
};

/// Application service responsible for note operations.
Expand Down
4 changes: 2 additions & 2 deletions crates/frilvault-core/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod note_parser;
mod yaml_parser;

pub use note_parser::NoteParser;
pub use yaml_parser::YamlParser;
pub use note_parser::*;
pub use yaml_parser::*;
2 changes: 0 additions & 2 deletions crates/frilvault-core/src/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod cache_stats;
mod note_cache;
mod vault_context;

pub use cache_stats::*;
pub use note_cache::*;
pub use vault_context::*;
2 changes: 1 addition & 1 deletion crates/frilvault-core/src/runtime/note_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};

use crate::NoteFile;
use crate::note::NoteFile;

#[derive(Debug, Default, Clone)]
pub struct NoteCache {
Expand Down
7 changes: 5 additions & 2 deletions crates/frilvault-core/src/runtime/vault_context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::path::{Path, PathBuf};

use crate::{
FrilVaultResult, NoteCache, NoteFile, NoteFileRecord, WorkspaceIndex, WorkspaceIndexRepository,
YamlNoteRepository,
FrilVaultResult,
note::NoteFile,
runtime::NoteCache,
storage::{NoteFileRecord, YamlNoteRepository},
workspace::{WorkspaceIndex, WorkspaceIndexRepository},
};

/// Runtime container for FrilVault.
Expand Down
28 changes: 6 additions & 22 deletions crates/frilvault-core/src/storage/yaml_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
//! Notes are persisted as YAML files
//! inside the `.vault/notes` directory.

use crate::note::{Note, NoteFile};
use crate::parser::{NoteParser, YamlParser};
use crate::workspace::PathResolver;
use crate::{FrilVaultResult, NoteFileRecord, NoteRepository};
use std::fs;
use std::path::{Path, PathBuf};

use crate::note::NoteFile;
use crate::parser::{NoteParser, YamlParser};
use crate::storage::NoteFileRecord;
use crate::workspace::PathResolver;
use crate::{FrilVaultResult, Note};

#[derive(Debug, Clone)]
pub struct YamlNoteRepository {
path_resolver: PathResolver,
Expand Down Expand Up @@ -128,21 +130,3 @@ impl YamlNoteRepository {
self.path_resolver.resolve_note_path(source_file)
}
}

impl NoteRepository for YamlNoteRepository {
fn append_note(&self, source_file: &Path, note: &Note) -> FrilVaultResult<()> {
YamlNoteRepository::append_note(self, source_file, note)
}

fn load_by_source_file(&self, source_file: &Path) -> FrilVaultResult<NoteFile> {
YamlNoteRepository::load_by_source_file(self, source_file)
}

fn replace_notes(&self, source_file: &Path, notes: Vec<Note>) -> FrilVaultResult<()> {
YamlNoteRepository::replace_notes(self, source_file, notes)
}

fn list_all_note_files(&self) -> FrilVaultResult<Vec<NoteFileRecord>> {
YamlNoteRepository::list_all_note_files(self)
}
}
29 changes: 9 additions & 20 deletions crates/frilvault-core/src/tests/frilvault_app_test.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use std::fs;

use super::helper::create_test_workspace;
use crate::{AddNoteRequest, FrilVault, LineAnchor, NoteAnchor};

#[test]
fn frilvault_open_creates_note_service() {
let workspace_root =
std::env::temp_dir().join(format!("frilvault-test-{}", uuid::Uuid::new_v4()));

fs::create_dir_all(&workspace_root).unwrap();
let workspace = create_test_workspace();
let workspace_root = workspace.root();
let vault = FrilVault::open(workspace_root).unwrap();

let vault = FrilVault::open(&workspace_root).unwrap();

let mut notes = vault.create_note_service().unwrap();
let mut notes = vault.notes().unwrap();

notes
.add_note(AddNoteRequest {
Expand All @@ -25,24 +21,17 @@ fn frilvault_open_creates_note_service() {

assert_eq!(result.len(), 1);
assert_eq!(result[0].note.content, "facade note");

fs::remove_dir_all(workspace_root).unwrap();
}

#[test]
fn frilvault_open_creates_workspace_service() {
let workspace_root =
std::env::temp_dir().join(format!("frilvault-test-{}", uuid::Uuid::new_v4()));
let workspace = create_test_workspace();
let workspace_root = workspace.root();
let vault = FrilVault::open(workspace_root).unwrap();

fs::create_dir_all(&workspace_root).unwrap();

let vault = FrilVault::open(&workspace_root).unwrap();

let mut workspace = vault.create_workspace_service().unwrap();
let mut workspace = vault.workspace().unwrap();

let stats = workspace.stats().unwrap();

assert_eq!(stats.file_count, 0);

fs::remove_dir_all(workspace_root).unwrap();
}
Loading