aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository/repository_interface.rs
blob: 2a9c8f5ec944652cd232b66b961c0db6ae983d65 (plain)
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
//! ref: composer/src/Composer/Repository/RepositoryInterface.php

use crate::package::base_package::BasePackage;
use crate::package::package_interface::PackageInterface;
use crate::repository::advisory_provider_interface::AdvisoryProviderInterface;
use indexmap::IndexMap;
use shirabe_php_shim::Countable;
use shirabe_semver::constraint::constraint_interface::ConstraintInterface;

pub enum FindPackageConstraint {
    String(String),
    Constraint(Box<dyn ConstraintInterface>),
}

pub struct LoadPackagesResult {
    pub names_found: Vec<String>,
    pub packages: Vec<Box<dyn BasePackage>>,
}

pub enum AbandonedInfo {
    Replacement(String),
    Abandoned,
}

pub struct SearchResult {
    pub name: String,
    pub description: Option<String>,
    pub abandoned: Option<AbandonedInfo>,
    pub url: Option<String>,
}

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: Countable + std::fmt::Debug {
    fn has_package(&self, package: &dyn PackageInterface) -> bool;

    fn find_package(
        &self,
        name: String,
        constraint: FindPackageConstraint,
    ) -> Option<Box<dyn BasePackage>>;

    fn find_packages(
        &self,
        name: String,
        constraint: Option<FindPackageConstraint>,
    ) -> Vec<Box<dyn BasePackage>>;

    fn get_packages(&self) -> Vec<Box<dyn BasePackage>>;

    fn load_packages(
        &self,
        package_name_map: IndexMap<String, Option<Box<dyn ConstraintInterface>>>,
        acceptable_stabilities: IndexMap<String, i64>,
        stability_flags: IndexMap<String, i64>,
        already_loaded: IndexMap<String, IndexMap<String, Box<dyn PackageInterface>>>,
    ) -> LoadPackagesResult;

    fn search(&self, query: String, mode: i64, r#type: Option<String>) -> Vec<SearchResult>;

    fn get_providers(&self, package_name: String) -> IndexMap<String, ProviderInfo>;

    fn get_repo_name(&self) -> String;

    fn as_advisory_provider(&self) -> Option<&dyn AdvisoryProviderInterface> {
        None
    }

    fn as_any(&self) -> &dyn std::any::Any;

    fn clone_box(&self) -> Box<dyn RepositoryInterface> {
        todo!()
    }
}