Skip to main content

runmat_package/source/project_resolver/
model.rs

1use crate::{
2    DependencyGroup, FrozenProject, GitAcquisitionPlan, GitSourceId, HostCapability, LockSelection,
3    PackageLock, PathLockDecision, RegistryAcquisitionPlan, RegistryCandidatePlan,
4    RegistryCandidateRecord, RegistrySourceId, ServerProjectAcquisitionPlan, ServerProjectSourceId,
5    SourceAcquisitionIntent, SourceAcquisitionPolicy,
6};
7use std::collections::BTreeSet;
8use std::future::Future;
9use std::path::PathBuf;
10use std::pin::Pin;
11
12#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
13#[serde(deny_unknown_fields)]
14pub struct GitPackageMount {
15    pub source: GitSourceId,
16    pub root: PathBuf,
17}
18
19pub trait PackageSourceProvider {
20    fn acquire_git<'a>(
21        &'a self,
22        plan: &'a GitAcquisitionPlan,
23    ) -> Pin<Box<dyn Future<Output = Result<GitPackageMount, String>> + 'a>>;
24
25    fn acquire_server_project<'a>(
26        &'a self,
27        _plan: &'a ServerProjectAcquisitionPlan,
28    ) -> Pin<Box<dyn Future<Output = Result<ServerProjectPackageMount, String>> + 'a>> {
29        Box::pin(async { Err("Server project snapshot acquisition is not configured".to_string()) })
30    }
31
32    fn acquire_registry<'a>(
33        &'a self,
34        _plan: &'a RegistryAcquisitionPlan,
35    ) -> Pin<Box<dyn Future<Output = Result<RegistryPackageMount, String>> + 'a>> {
36        Box::pin(async { Err("registry package acquisition is not configured".to_string()) })
37    }
38
39    fn registry_candidates<'a>(
40        &'a self,
41        _plan: &'a RegistryCandidatePlan,
42    ) -> Pin<Box<dyn Future<Output = Result<Vec<RegistryCandidateRecord>, String>> + 'a>> {
43        Box::pin(async { Err("registry candidate acquisition is not configured".to_string()) })
44    }
45}
46
47pub use PackageSourceProvider as GitPackageProvider;
48
49#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
50#[serde(deny_unknown_fields)]
51pub struct ServerProjectPackageMount {
52    pub source: ServerProjectSourceId,
53    pub root: PathBuf,
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
57#[serde(deny_unknown_fields)]
58pub struct RegistryPackageMount {
59    pub source: RegistrySourceId,
60    pub root: PathBuf,
61    pub metadata: Option<crate::RegistryReleaseMetadata>,
62}
63
64#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
65#[serde(deny_unknown_fields)]
66pub struct ProjectResolveOptions {
67    pub target: String,
68    pub default_server_origin: String,
69    pub default_registry_index: String,
70    pub groups: BTreeSet<DependencyGroup>,
71    pub root_features: BTreeSet<String>,
72    pub host_capabilities: BTreeSet<HostCapability>,
73    pub source_intent: SourceAcquisitionIntent,
74    pub source_policy: SourceAcquisitionPolicy,
75}
76
77impl ProjectResolveOptions {
78    pub fn lock_selection(&self) -> LockSelection {
79        LockSelection {
80            target: self.target.clone(),
81            groups: self.groups.clone(),
82            root_features: self.root_features.clone(),
83            host_capabilities: self.host_capabilities.clone(),
84        }
85    }
86}
87
88#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
89#[serde(deny_unknown_fields)]
90pub struct ResolvedProject {
91    pub frozen: FrozenProject,
92    pub lock: PackageLock,
93    pub lock_decision: PathLockDecision,
94    pub acquired_git_sources: Vec<GitSourceId>,
95    pub acquired_server_sources: Vec<ServerProjectSourceId>,
96    pub acquired_registry_sources: Vec<RegistrySourceId>,
97    pub source_inventories: Vec<crate::SourceInventory>,
98}