refactor: add upm application facade and module api
This commit is contained in:
parent
005d6ebfdb
commit
e2a01d3095
36 changed files with 1058 additions and 607 deletions
3
crates/upm-module-api/src/domain/mod.rs
Normal file
3
crates/upm-module-api/src/domain/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod search;
|
||||
pub mod source;
|
||||
pub mod update;
|
||||
68
crates/upm-module-api/src/domain/search.rs
Normal file
68
crates/upm-module-api/src/domain/search.rs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
pub const DEFAULT_REMOTE_LIMIT: usize = 10;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum SearchInstallStatus {
|
||||
Available,
|
||||
Installed {
|
||||
installed_version: Option<String>,
|
||||
},
|
||||
UpdateAvailable {
|
||||
installed_version: Option<String>,
|
||||
latest_version: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct SearchQuery {
|
||||
pub text: String,
|
||||
pub remote_limit: usize,
|
||||
}
|
||||
|
||||
impl SearchQuery {
|
||||
pub fn new(text: &str) -> Self {
|
||||
Self {
|
||||
text: text.to_owned(),
|
||||
remote_limit: DEFAULT_REMOTE_LIMIT,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_remote_limit(text: &str, remote_limit: usize) -> Self {
|
||||
Self {
|
||||
text: text.to_owned(),
|
||||
remote_limit,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct SearchResult {
|
||||
pub provider_id: String,
|
||||
pub display_name: String,
|
||||
pub description: Option<String>,
|
||||
pub source_locator: String,
|
||||
pub install_query: String,
|
||||
pub canonical_locator: String,
|
||||
pub version: Option<String>,
|
||||
pub install_status: SearchInstallStatus,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct InstalledSearchMatch {
|
||||
pub stable_id: String,
|
||||
pub display_name: String,
|
||||
pub installed_version: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct SearchWarning {
|
||||
pub provider_id: Option<String>,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct SearchResults {
|
||||
pub query_text: String,
|
||||
pub remote_hits: Vec<SearchResult>,
|
||||
pub installed_matches: Vec<InstalledSearchMatch>,
|
||||
pub warnings: Vec<SearchWarning>,
|
||||
}
|
||||
117
crates/upm-module-api/src/domain/source.rs
Normal file
117
crates/upm-module-api/src/domain/source.rs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub enum SourceKind {
|
||||
GitHub,
|
||||
GitLab,
|
||||
AppImageHub,
|
||||
SourceForge,
|
||||
DirectUrl,
|
||||
File,
|
||||
}
|
||||
|
||||
impl SourceKind {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::GitHub => "github",
|
||||
Self::GitLab => "gitlab",
|
||||
Self::AppImageHub => "appimagehub",
|
||||
Self::SourceForge => "sourceforge",
|
||||
Self::DirectUrl => "direct-url",
|
||||
Self::File => "file",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub enum SourceInputKind {
|
||||
RepoShorthand,
|
||||
GitHubRepositoryUrl,
|
||||
GitHubReleaseUrl,
|
||||
GitHubReleaseAssetUrl,
|
||||
GitLabUrl,
|
||||
AppImageHubUrl,
|
||||
AppImageHubShorthand,
|
||||
SourceForgeUrl,
|
||||
DirectUrl,
|
||||
File,
|
||||
}
|
||||
|
||||
impl SourceInputKind {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::RepoShorthand => "repo-shorthand",
|
||||
Self::GitHubRepositoryUrl => "github-repository-url",
|
||||
Self::GitHubReleaseUrl => "github-release-url",
|
||||
Self::GitHubReleaseAssetUrl => "github-release-asset-url",
|
||||
Self::GitLabUrl => "gitlab-url",
|
||||
Self::AppImageHubUrl => "appimagehub-url",
|
||||
Self::AppImageHubShorthand => "appimagehub-shorthand",
|
||||
Self::SourceForgeUrl => "sourceforge-url",
|
||||
Self::DirectUrl => "direct-url",
|
||||
Self::File => "file",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub enum NormalizedSourceKind {
|
||||
GitHubRepository,
|
||||
GitHubRelease,
|
||||
GitHubReleaseAsset,
|
||||
GitLab,
|
||||
GitLabCandidate,
|
||||
AppImageHub,
|
||||
SourceForge,
|
||||
SourceForgeCandidate,
|
||||
DirectUrl,
|
||||
File,
|
||||
}
|
||||
|
||||
impl NormalizedSourceKind {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::GitHubRepository => "github-repository",
|
||||
Self::GitHubRelease => "github-release",
|
||||
Self::GitHubReleaseAsset => "github-release-asset",
|
||||
Self::GitLab => "gitlab",
|
||||
Self::GitLabCandidate => "gitlab-candidate",
|
||||
Self::AppImageHub => "appimagehub",
|
||||
Self::SourceForge => "sourceforge",
|
||||
Self::SourceForgeCandidate => "sourceforge-candidate",
|
||||
Self::DirectUrl => "direct-url",
|
||||
Self::File => "file",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub struct SourceRef {
|
||||
pub kind: SourceKind,
|
||||
pub locator: String,
|
||||
#[serde(default = "default_source_input_kind")]
|
||||
pub input_kind: SourceInputKind,
|
||||
#[serde(default = "default_normalized_source_kind")]
|
||||
pub normalized_kind: NormalizedSourceKind,
|
||||
#[serde(default)]
|
||||
pub canonical_locator: Option<String>,
|
||||
#[serde(default)]
|
||||
pub requested_tag: Option<String>,
|
||||
#[serde(default)]
|
||||
pub requested_asset_name: Option<String>,
|
||||
#[serde(default)]
|
||||
pub tracks_latest: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub struct ResolvedRelease {
|
||||
pub version: String,
|
||||
#[serde(default)]
|
||||
pub prerelease: bool,
|
||||
}
|
||||
|
||||
const fn default_source_input_kind() -> SourceInputKind {
|
||||
SourceInputKind::DirectUrl
|
||||
}
|
||||
|
||||
const fn default_normalized_source_kind() -> NormalizedSourceKind {
|
||||
NormalizedSourceKind::DirectUrl
|
||||
}
|
||||
42
crates/upm-module-api/src/domain/update.rs
Normal file
42
crates/upm-module-api/src/domain/update.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub enum UpdateChannelKind {
|
||||
GitHubReleases,
|
||||
ElectronBuilder,
|
||||
Zsync,
|
||||
DirectAsset,
|
||||
}
|
||||
|
||||
impl UpdateChannelKind {
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::GitHubReleases => "github-releases",
|
||||
Self::ElectronBuilder => "electron-builder",
|
||||
Self::Zsync => "zsync",
|
||||
Self::DirectAsset => "direct-asset-lineage",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub struct ChannelPreference {
|
||||
pub kind: UpdateChannelKind,
|
||||
pub locator: String,
|
||||
pub reason: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
pub struct UpdateStrategy {
|
||||
pub preferred: ChannelPreference,
|
||||
#[serde(default)]
|
||||
pub alternates: Vec<ChannelPreference>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct ArtifactCandidate {
|
||||
pub url: String,
|
||||
pub version: String,
|
||||
pub arch: Option<String>,
|
||||
pub trusted_checksum: Option<String>,
|
||||
pub weak_checksum_md5: Option<String>,
|
||||
pub selection_reason: String,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue