1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::index::request::PublishDependency;
use crate::index::response::CrateVersion;
#[cfg(any(feature = "client", feature = "server"))]
use serde::{Deserialize, Serialize};

pub mod request;

pub mod response;

#[derive(Debug, Default, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(
    any(feature = "server", feature = "client"),
    derive(Serialize, Deserialize),
    serde(rename_all = "lowercase")
)]
#[cfg_attr(
    feature = "postgres",
    derive(postgres_types::ToSql, postgres_types::FromSql),
    postgres(name = "dependency_kind")
)]
pub enum DependencyKind {
    #[cfg_attr(feature = "postgres", postgres(name = "normal"))]
    #[default]
    Normal,
    #[cfg_attr(feature = "postgres", postgres(name = "dev"))]
    Dev,
    #[cfg_attr(feature = "postgres", postgres(name = "build"))]
    Build,
}

impl From<response::CrateVersion> for request::Publish {
    fn from(value: CrateVersion) -> Self {
        Self {
            name: value.name,
            vers: value.vers,
            deps: value
                .deps
                .into_iter()
                .map(|x| PublishDependency {
                    name: x.name,
                    version_req: x.req,
                    features: x.features,
                    optional: x.optional,
                    default_features: x.default_features,
                    target: x.target,
                    kind: x.kind,
                    registry: x.registry,
                    explicit_name_in_toml: x.package,
                })
                .collect(),
            features: value.features,
            /// Note: We do not carry over authors since its not in index
            authors: Vec::new(),
            description: None,
            documentation: None,
            homepage: None,
            readme: None,
            readme_file: None,
            keywords: vec![],
            categories: vec![],
            license: None,
            license_file: None,
            repository: None,
            badges: None,
            links: None,
        }
    }
}