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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
//! ref: composer/src/Composer/Repository/RepositoryInterface.php
use crate::package::BasePackageHandle;
use crate::package::PackageInterfaceHandle;
use crate::repository::AdvisoryProviderInterface;
use indexmap::IndexMap;
use shirabe_semver::constraint::AnyConstraint;
pub enum FindPackageConstraint {
String(String),
Constraint(AnyConstraint),
}
impl Clone for FindPackageConstraint {
fn clone(&self) -> Self {
match self {
Self::String(s) => Self::String(s.clone()),
Self::Constraint(c) => Self::Constraint(c.clone()),
}
}
}
#[derive(Debug)]
pub struct LoadPackagesResult {
pub names_found: Vec<String>,
pub packages: IndexMap<String, BasePackageHandle>,
}
#[derive(Debug, Clone)]
pub enum AbandonedInfo {
Replacement(String),
Abandoned,
}
#[derive(Debug, Clone)]
pub struct SearchResult {
pub name: String,
pub description: Option<String>,
pub abandoned: Option<AbandonedInfo>,
pub url: Option<String>,
}
#[derive(Debug, Clone)]
pub struct ProviderInfo {
pub name: String,
pub description: Option<String>,
pub r#type: String,
}
pub const SEARCH_FULLTEXT: i64 = 0;
pub const SEARCH_NAME: i64 = 1;
pub const SEARCH_VENDOR: i64 = 2;
pub trait RepositoryInterface: std::fmt::Debug {
fn count(&self) -> anyhow::Result<usize>;
fn has_package(&self, package: PackageInterfaceHandle) -> bool;
fn find_package(
&mut self,
name: &str,
constraint: FindPackageConstraint,
) -> anyhow::Result<Option<BasePackageHandle>>;
fn find_packages(
&mut self,
name: &str,
constraint: Option<FindPackageConstraint>,
) -> anyhow::Result<Vec<BasePackageHandle>>;
fn get_packages(&mut self) -> anyhow::Result<Vec<BasePackageHandle>>;
fn load_packages(
&mut self,
package_name_map: IndexMap<String, Option<AnyConstraint>>,
acceptable_stabilities: IndexMap<String, i64>,
stability_flags: IndexMap<String, i64>,
already_loaded: IndexMap<String, IndexMap<String, PackageInterfaceHandle>>,
) -> anyhow::Result<LoadPackagesResult>;
fn search(
&mut self,
query: String,
mode: i64,
r#type: Option<String>,
) -> anyhow::Result<Vec<SearchResult>>;
fn get_providers(
&mut self,
package_name: String,
) -> anyhow::Result<IndexMap<String, ProviderInfo>>;
fn get_repo_name(&self) -> String;
fn as_advisory_provider(&self) -> Option<&dyn AdvisoryProviderInterface> {
None
}
fn as_advisory_provider_mut(&mut self) -> Option<&mut dyn AdvisoryProviderInterface> {
None
}
fn as_installed_repository_interface(
&self,
) -> Option<&dyn crate::repository::InstalledRepositoryInterface> {
None
}
fn as_installed_repository_interface_mut(
&mut self,
) -> Option<&mut dyn crate::repository::InstalledRepositoryInterface> {
None
}
fn as_writable_repository_interface_mut(
&mut self,
) -> Option<&mut dyn crate::repository::WritableRepositoryInterface> {
None
}
fn as_any(&self) -> &dyn std::any::Any;
/// Injects this repository's own weak handle so that `add_package` can wire package ->
/// repository back-references (PHP `setRepository($this)`). Called once when the repository is
/// wrapped in a [`RepositoryInterfaceHandle`](crate::repository::RepositoryInterfaceHandle).
/// Wrapper repositories forward the same weak (the outermost handle) to their inner
/// `ArrayRepository`.
fn set_self_handle(&self, weak: crate::repository::RepositoryInterfaceWeakHandle) {
let _ = weak;
}
}
|