santa_data/
models.rs

1// Core data models for Santa Package Manager
2
3use derive_more::{Display, From, Into};
4use serde::{Deserialize, Serialize};
5use serde_enum_str::{Deserialize_enum_str, Serialize_enum_str};
6use std::collections::HashMap;
7
8/// Strong type for package names to prevent mixing up with other strings
9#[derive(Debug, Clone, PartialEq, Eq, Hash, Display, From, Into, Serialize, Deserialize)]
10pub struct PackageName(pub String);
11
12/// Strong type for source names to prevent mixing up with other strings
13#[derive(Debug, Clone, PartialEq, Eq, Hash, Display, From, Into, Serialize, Deserialize)]
14pub struct SourceName(pub String);
15
16/// Strong type for command names to prevent command/package name confusion
17#[derive(Debug, Clone, PartialEq, Eq, Hash, Display, From, Into, Serialize, Deserialize)]
18pub struct CommandName(pub String);
19
20#[derive(Serialize_enum_str, Deserialize_enum_str, Debug, Clone, Eq, PartialEq, Hash)]
21#[serde(rename_all = "camelCase")]
22pub enum KnownSources {
23    Apt,
24    Aur,
25    Brew,
26    Cargo,
27    Pacman,
28    Scoop,
29    Nix,
30    #[serde(other)]
31    Unknown(String),
32}
33
34#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
35#[serde(rename_all = "camelCase")]
36pub enum OS {
37    Macos,
38    Linux,
39    Windows,
40}
41
42#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
43#[serde(rename_all = "camelCase")]
44pub enum Arch {
45    X64,
46    Aarch64,
47}
48
49#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
50#[serde(rename_all = "camelCase")]
51pub enum Distro {
52    None,
53    ArchLinux,
54    Ubuntu,
55}
56
57#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
58#[serde(rename_all = "camelCase")]
59pub struct Platform {
60    pub os: OS,
61    pub arch: Arch,
62    pub distro: Option<Distro>,
63}
64
65impl Default for Platform {
66    fn default() -> Self {
67        Platform {
68            os: OS::Linux,
69            arch: Arch::X64,
70            distro: None,
71        }
72    }
73}
74
75impl std::fmt::Display for Platform {
76    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77        match &self.distro {
78            Some(distro) => {
79                write!(f, "{:?} {:?} ({:?})", self.os, self.arch, distro)
80            }
81            None => {
82                write!(f, "{:?} {:?}", self.os, self.arch)
83            }
84        }
85    }
86}
87
88/// Package-specific configuration data
89#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
90pub struct PackageData {
91    pub name: Option<String>,
92    pub before: Option<String>,
93    pub after: Option<String>,
94    pub pre: Option<String>,
95    pub post: Option<String>,
96}
97
98impl PackageData {
99    pub fn new(name: &str) -> Self {
100        PackageData {
101            name: Some(name.to_string()),
102            before: None,
103            after: None,
104            pre: None,
105            post: None,
106        }
107    }
108}
109
110/// Map of package names to their source configurations
111pub type PackageDataList = HashMap<String, HashMap<KnownSources, Option<PackageData>>>;