package_parser/types.rs
1use std::collections::HashSet;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Deserialize, Serialize)]
5pub struct DependentPackage {
6 /// Dependent package URL
7 /// A compact purl package URL. Typically when there is an
8 /// unresolved requirement, there is no version.
9 /// If the dependency is resolved, the version should be added to the purl
10 pub purl: String,
11
12 /// dependent package version requirement
13 /// A string defining version(s)requirements. Package-type specific.
14 pub requirement: String,
15
16 /// dependency scope
17 /// The scope of this dependency, such as runtime, install, etc.
18 /// This is package-type specific and is the original scope string.
19 #[serde(default)]
20 pub scope: String,
21
22 /// is runtime flag
23 /// True if this dependency is a runtime dependency.
24 pub is_runtime: bool,
25
26 /// is optional flag
27 /// True if this dependency is an optional dependency'
28 pub is_optional: bool,
29
30 /// is resolved flag
31 /// True if this dependency version requirement has
32 /// been resolved and this dependency url points to an
33 /// exact version.
34 pub is_resolved: bool,
35
36 /// is reachable flag
37 #[serde(default)]
38 pub reachable: Reachability,
39
40 /// The relation of this dependency to the top package.
41 #[serde(default)]
42 pub relation: HashSet<Relation>,
43
44 /// parents, in purl format
45 #[serde(default)]
46 pub parents: HashSet<String>,
47}
48
49impl Default for DependentPackage {
50 fn default() -> Self {
51 Self {
52 purl: String::new(),
53 requirement: String::new(),
54 scope: String::new(),
55 is_runtime: true,
56 is_optional: false,
57 is_resolved: false,
58 reachable: Default::default(),
59 relation: HashSet::new(),
60 parents: HashSet::new(),
61 }
62 }
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize)]
66#[serde(rename_all = "lowercase")]
67pub enum Relation {
68 /// This is a direct dependency of the package
69 Direct,
70 /// This is a transitive dependency of the package
71 Indirect,
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize, Default)]
75#[serde(rename_all = "lowercase")]
76pub enum Reachability {
77 Yes,
78 #[default]
79 Possible,
80 No,
81}
82
83
84#[derive(Debug, Clone, Deserialize, Serialize)]
85pub struct Maintainer {
86 pub name: Option<String>,
87 pub email: Option<String>,
88}
89
90/// A party is a person, project or organization related to a package.
91#[derive(Debug, Clone, Default, Deserialize, Serialize)]
92pub struct Party {
93 /// the type of this party: One of:
94 /// person, project, organization
95 #[serde(rename = "type")]
96 pub typ: String,
97
98 /// A role for this party. Something such as author,
99 /// maintainer, contributor, owner, packager, distributor,
100 /// vendor, developer, owner, etc.
101 pub role: String,
102
103 /// The name of this party.
104 pub name: String,
105
106 /// The email address of this party.
107 pub email: String,
108
109 /// The url of this party.
110 pub url: String,
111}
112
113/// A package object as represented by either data from one of its different types of
114/// package manifests or that of a package instance created from one or more of these
115/// package manifests, and files for that package.
116#[derive(Debug, Clone, Default, Deserialize, Serialize)]
117pub struct Package {
118 /// Optional namespace for this package.
119 pub namespace: String,
120
121 /// The name of this package.
122 pub name: String,
123
124 /// Optional version of this package.
125 pub version: String,
126
127 /// Primary programming language
128 pub primary_language: String,
129
130 /// The license expression for this package typically derived
131 /// from its declared license or from some other type-specific
132 /// routine or convention.
133 pub license_expression: String,
134
135 /// The declared license mention, tag or text as found in a
136 /// package manifest. This can be a string, a list or dict of
137 /// strings possibly nested, as found originally in the manifest.
138 pub declared_license: String,
139
140 /// A list of DependentPackage for this package.
141 pub dependencies: Vec<DependentPackage>,
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize)]
145#[serde(rename_all = "camelCase")]
146pub struct LockMavenParam {
147 pub group_id: String,
148 pub artifact_id: String,
149 pub version: String,
150 #[serde(skip_serializing_if = "Option::is_none")]
151 pub scope: Option<String>,
152 #[serde(default)]
153 pub is_optional: bool,
154}
155
156
157#[derive(Debug, Clone, Deserialize, Serialize)]
158pub struct SupportedType {
159 /// Name of the file type, for logging purposes
160 pub name: String,
161 /// Glob patterns for file names
162 pub filenames: Vec<String>,
163 /// Regular expression patterns to match against the output of `file` command
164 pub patterns: Vec<String>,
165}
166