selene-core 0.9.0-alpha.2

selene-core is the backend for Selene, a local-first music player
Documentation
// use lunar_lib::database::{Db, Entry, TransactionError};
// use serde::{Deserialize, Serialize};

// use crate::{
//     database::Library,
//     library::{
//         collectable::Collectable,
//         collection::rules::{AlbumRule, RuleGroup, TrackRule},
//         image_art::ImageArt,
//     },
// };

// mod frontend_impls;
// pub mod trait_impls;

// #[cfg(feature = "stable-abi")]
// mod sdk_impls;

// pub mod rules;

// #[derive(Debug, thiserror::Error)]
// pub enum CollectionCreationError {
//     #[error("Collection name resolved to an empty string")]
//     EmptyName,

//     #[error("Collection name resolved to a reserved collection name")]
//     ReservedName(String),
// }

// #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
// pub enum CollectionItems {
//     Static { collectables: Vec<Collectable> },
//     Dynamic { rules: Vec<DynamicCollectionRules> },
// }

// impl CollectionItems {
//     pub fn resolve(self, db: &Db<Library>) -> Result<Vec<Collectable>, TransactionError> {
//         match self {
//             CollectionItems::Static { collectables } => Ok(collectables),
//             CollectionItems::Dynamic { rules } => Ok(resolve_rules(&rules, db)?),
//         }
//     }
// }

// #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
// pub enum DynamicCollectionRules {
//     Track(RuleGroup<TrackRule>),
//     Album(RuleGroup<AlbumRule>),
// }

// #[derive(Debug, Clone, Serialize, Deserialize)]
// pub struct Collection {
//     pub name: String,
//     pub cover_art: Option<ImageArt>,

//     pub items: CollectionItems,
//     read_only: bool,
// }

// impl Collection {
//     /// Creates a new static collection with the input name
//     ///
//     /// # Errors
//     ///
//     /// This function will return `None` if the input name is empty or is trimmed to an empty string
//     fn new_static(name: impl AsRef<str>) -> Result<Self, CollectionCreationError> {
//         let name = name.as_ref().trim();
//         if name.is_empty() {
//             return Err(CollectionCreationError::EmptyName);
//         }

//         Ok(Self {
//             name: name.to_owned(),
//             cover_art: None,
//             items: CollectionItems::Static {
//                 collectables: Vec::new(),
//             },
//             read_only: false,
//         })
//     }
// }

// pub fn resolve_rules(
//     rules: &[DynamicCollectionRules],
//     db: &Db<Library>,
// ) -> Result<Vec<Collectable>, TransactionError> {
//     let tracks = Entry::db_get_all(db)?;
//     let albums = Entry::db_get_all(db)?;

//     let mut collectables = Vec::new();

//     for group in rules {
//         match group {
//             DynamicCollectionRules::Track(rule_group) => {
//                 let tracks = rule_group.filter(&tracks);
//                 collectables.extend(tracks.map(|t| Collectable::Track(t.id())));
//             }
//             DynamicCollectionRules::Album(rule_group) => {
//                 let albums = rule_group.filter(&albums);
//                 collectables.extend(albums.map(|t| Collectable::Album(t.id())));
//             }
//         }
//     }

//     Ok(collectables)
// }