use anyhow::Result;
#[derive(Debug, Clone, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct VersionError(String);
impl VersionError {
pub fn from_missing_version() -> Self {
Self("Missing version number".to_string())
}
pub fn from_parse_error(raw_version_number: &str) -> Self {
Self(format!("Version parse error: {}", raw_version_number))
}
pub fn message(&self) -> String {
self.0.clone()
}
}
pub type VersionParseResult = std::result::Result<String, VersionError>;
#[derive(Clone, Debug, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Dependency {
pub name: String,
pub version: VersionParseResult,
}
#[derive(Clone, Debug, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct DependenciesSpec {
pub path: std::path::PathBuf,
pub registry_host_name: String,
pub dependencies: Vec<Dependency>,
}
#[derive(Debug, Clone, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct RegistryPackageMetadata {
pub registry_host_name: String,
pub human_url: String,
pub artifact_url: String,
pub is_primary: bool,
pub package_version: String,
}
pub trait FromLib: Extension + Send + Sync {
fn new() -> Self
where
Self: Sized;
}
pub trait FromProcess: Extension + Send + Sync {
fn from_process(
process_path: &std::path::PathBuf,
extension_config_path: &std::path::PathBuf,
) -> Result<Self>
where
Self: Sized;
}
pub trait Extension: Send + Sync {
fn name(&self) -> String;
fn registries(&self) -> Vec<String>;
fn identify_local_dependencies(
&self,
working_directory: &std::path::PathBuf,
) -> Result<Vec<DependenciesSpec>>;
fn registries_package_metadata(
&self,
package_name: &str,
package_version: &Option<&str>,
) -> Result<Vec<RegistryPackageMetadata>>;
}