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    Flathub,
28    Nix,
29    Npm,
30    Pacman,
31    Scoop,
32    #[serde(other)]
33    Unknown(String),
34}
35
36#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
37#[serde(rename_all = "camelCase")]
38pub enum OS {
39    Macos,
40    Linux,
41    Windows,
42}
43
44#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
45#[serde(rename_all = "camelCase")]
46pub enum Arch {
47    X64,
48    Aarch64,
49}
50
51#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
52#[serde(rename_all = "camelCase")]
53pub enum Distro {
54    None,
55    ArchLinux,
56    Ubuntu,
57}
58
59#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
60#[serde(rename_all = "camelCase")]
61pub struct Platform {
62    pub os: OS,
63    pub arch: Arch,
64    pub distro: Option<Distro>,
65}
66
67impl Default for Platform {
68    fn default() -> Self {
69        Platform {
70            os: OS::Linux,
71            arch: Arch::X64,
72            distro: None,
73        }
74    }
75}
76
77impl std::fmt::Display for Platform {
78    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79        match &self.distro {
80            Some(distro) => {
81                write!(f, "{:?} {:?} ({:?})", self.os, self.arch, distro)
82            }
83            None => {
84                write!(f, "{:?} {:?}", self.os, self.arch)
85            }
86        }
87    }
88}
89
90/// Package-specific configuration data
91#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
92pub struct PackageData {
93    pub name: Option<String>,
94    pub before: Option<String>,
95    pub after: Option<String>,
96    pub pre: Option<String>,
97    pub post: Option<String>,
98}
99
100impl PackageData {
101    pub fn new(name: &str) -> Self {
102        PackageData {
103            name: Some(name.to_string()),
104            before: None,
105            after: None,
106            pre: None,
107            post: None,
108        }
109    }
110}
111
112/// Map of package names to their source configurations
113pub type PackageDataList = HashMap<String, HashMap<KnownSources, Option<PackageData>>>;