feat(manifest): add id and capabilities fields to notebook manifest

This commit is contained in:
Matthieu Bessat 2025-02-21 10:56:37 +01:00
parent e5004fbf32
commit 00862f3aca
4 changed files with 34 additions and 29 deletions

View file

@ -11,12 +11,17 @@ use crate::{fs_notebook::NotebookContext, pdel_parser::{preprocess::Expansion, P
use super::{graph::BackLinksIndex, ids::Id, labels::LabelEntryIndex}; use super::{graph::BackLinksIndex, ids::Id, labels::LabelEntryIndex};
/// A user-config for the Notebook /// A user-config for the Notebook
/// Result of the deserialization of a Notebook manifest.json file /// Result of the deserialization of a notebook.yaml file
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
#[fully_pub] #[fully_pub]
struct Manifest { struct NotebookManifest {
/// Notebook unique identifier (can be a UUID)
id: String,
/// Name or title of the notebook
name: String, name: String,
description: String description: String,
/// List of enabled modules scopes
capabilities: Vec<String>
} }
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@ -142,7 +147,7 @@ struct Notebook {
files: Vec<SourceFile>, files: Vec<SourceFile>,
entries: Vec<EntryContainer>, entries: Vec<EntryContainer>,
// TODO: add a labels index // TODO: add a labels index
manifest: Manifest, manifest: NotebookManifest,
labels_index: LabelEntryIndex, labels_index: LabelEntryIndex,
backlinks: BackLinksIndex backlinks: BackLinksIndex
} }

View file

@ -4,7 +4,7 @@ use git2::{Repository, Signature};
use pathdiff::diff_paths; use pathdiff::diff_paths;
use thiserror::Error; use thiserror::Error;
use crate::{database::models::Manifest, indexer::{index_and_save, IndexingErr}}; use crate::{database::models::NotebookManifest, indexer::{index_and_save, IndexingErr}};
use super::NotebookContext; use super::NotebookContext;
@ -22,7 +22,7 @@ pub enum InitErr {
fn init_fs(desired_notebook: &NotebookContext) -> Result<(), io::Error> { fn init_fs(desired_notebook: &NotebookContext) -> Result<(), io::Error> {
std::fs::create_dir(desired_notebook.sources_path())?; std::fs::create_dir(desired_notebook.sources_path())?;
std::fs::create_dir(desired_notebook.internals_path())?; std::fs::create_dir(desired_notebook.internals_path())?;
let manifest = Manifest::empty(); let manifest = NotebookManifest::empty();
std::fs::write( std::fs::write(
desired_notebook.manifest_path(), desired_notebook.manifest_path(),
serde_yaml::to_string(&manifest).expect("Encode empty manifest.") serde_yaml::to_string(&manifest).expect("Encode empty manifest.")

View file

@ -2,7 +2,8 @@ use std::path::Path;
use std::io; use std::io;
use std::fs; use std::fs;
use fully_pub::fully_pub; use fully_pub::fully_pub;
use crate::database::models::Manifest; use uuid::Uuid;
use crate::database::models::NotebookManifest;
#[fully_pub] #[fully_pub]
#[derive(Debug)] #[derive(Debug)]
@ -16,31 +17,35 @@ enum ScanManifestErr {
InvalidScheme InvalidScheme
} }
impl Manifest { impl NotebookManifest {
/// Scan a fanifest file /// Scan a fanifest file
pub fn from_path(manifest_path: &Path) -> Result<Manifest, ScanManifestErr> { pub fn from_path(manifest_path: &Path) -> Result<Self, ScanManifestErr> {
if !manifest_path.exists() { return Err(ScanManifestErr::FileNotFound); } if !manifest_path.exists() { return Err(ScanManifestErr::FileNotFound); }
let manifest_content = fs::read_to_string(manifest_path) let manifest_content = fs::read_to_string(manifest_path)
.map_err(ScanManifestErr::CannotReadFile)?; .map_err(ScanManifestErr::CannotReadFile)?;
let data: Manifest = serde_yaml::from_str(&manifest_content) let data: Self = serde_yaml::from_str(&manifest_content)
.map_err(ScanManifestErr::ParseError)?; .map_err(ScanManifestErr::ParseError)?;
Ok(data) Ok(data)
} }
pub fn example() -> Manifest { pub fn example() -> Self {
Manifest { Self {
name: "Example Notebook".to_string(), id: "example".into(),
description: "Notebook description".to_string(), name: "Example Notebook".into(),
description: "Notebook description".into(),
capabilities: vec!["calendar".into()]
} }
} }
pub fn empty() -> Manifest { pub fn empty() -> NotebookManifest {
Manifest { Self {
name: "My super cool Notebook".to_string(), id: Uuid::new_v4().into(),
description: "This is a notebook description, feel free to change this.".to_string(), name: "My super cool Notebook".into(),
description: "This is a notebook description, feel free to change this.".into(),
capabilities: vec![]
} }
} }
} }

View file

@ -1,7 +1,7 @@
use crate::database::ids::Id; use crate::database::ids::Id;
use crate::database::labels::LabelEntryIndex; use crate::database::labels::LabelEntryIndex;
use crate::database::graph::BackLinksIndex; use crate::database::graph::BackLinksIndex;
use crate::database::models::{Entry, EntryContainer, Manifest, Notebook, SourceFile}; use crate::database::models::{Entry, EntryContainer, NotebookManifest, Notebook, SourceFile};
use crate::database::parse_extractor::{flatten_embedded_entries, ExtractErr}; use crate::database::parse_extractor::{flatten_embedded_entries, ExtractErr};
use crate::database::save::{save_db, SaveErr}; use crate::database::save::{save_db, SaveErr};
use crate::pdel_parser::preprocess::{apply_expansions, preprocess_code, AdaptableRange, Expansion}; use crate::pdel_parser::preprocess::{apply_expansions, preprocess_code, AdaptableRange, Expansion};
@ -253,15 +253,10 @@ fn add_id_on_entry_code(expansions: &[Expansion], inp_file_code: &String, pout:
fn index_notebook(context: &NotebookContext) -> Result<Notebook, IndexingErr> fn index_notebook(context: &NotebookContext) -> Result<Notebook, IndexingErr>
{ {
// scan manifest file to get the name, description and others setting of the notebook // scan manifest file to get the name, description and others setting of the notebook
let manifest = Manifest::from_path(&context.manifest_path()) let manifest = NotebookManifest::from_path(&context.manifest_path())
.map_err(IndexingErr::ManifestErr)?; .map_err(IndexingErr::ManifestErr)?;
let index_res = match index_dir(&context.sources_path(), &context.sources_path()) { let index_res = index_dir(&context.sources_path(), &context.sources_path())?;
Ok(res) => res,
Err(err) => {
return Err(err)
}
};
Notebook::build( Notebook::build(
manifest, manifest,
@ -330,7 +325,7 @@ fn watch<P: AsRef<Path>>(path: P) -> notify::Result<()> {
impl Notebook { impl Notebook {
/// build a notebook from components /// build a notebook from components
pub fn build( pub fn build(
manifest: Manifest, manifest: NotebookManifest,
files: Vec<SourceFile>, files: Vec<SourceFile>,
entries_containers: Vec<EntryContainer> entries_containers: Vec<EntryContainer>
) -> Result<Notebook, IndexingErr> { ) -> Result<Notebook, IndexingErr> {
@ -370,11 +365,11 @@ impl Notebook {
/// build virtual notebook from one single markdown string /// build virtual notebook from one single markdown string
/// for now does not support macros /// for now does not support macros
pub fn build_virtual( pub fn build_virtual(
manifest: Manifest, manifest: NotebookManifest,
markdown_code: &str markdown_code: &str
)-> Result<Notebook, IndexingErr> { )-> Result<Notebook, IndexingErr> {
let markdown_val = parse_markdown(markdown_code, 0).map_err( let markdown_val = parse_markdown(markdown_code, 0).map_err(
|_e| IndexingErr::ParseErr |e| IndexingErr::ParseErr(e)
)?; )?;
let sf = SourceFile { let sf = SourceFile {
id: Uuid::new_v4(), id: Uuid::new_v4(),