Skip to main content

mars_schema/resolve/
lock.rs

1use serde::{Deserialize, Serialize};
2
3use crate::claude::manifest::PluginSource;
4use crate::inspect::PluginHint;
5use crate::names::SourceSubpath;
6
7/// One `[dependencies.<name>]` row of `mars.lock`: where a dependency came from and the commit it
8/// was resolved to. The serialized form is the lock file's, so a field is added only with a
9/// default and never reordered.
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
11pub struct LockedDependency {
12    #[serde(default, skip_serializing_if = "Option::is_none")]
13    pub url: Option<String>,
14    #[serde(default, skip_serializing_if = "Option::is_none")]
15    pub path: Option<String>,
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    pub subpath: Option<SourceSubpath>,
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub version: Option<String>,
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    pub commit: Option<String>,
22    /// The marketplace plugin installed from this source. `url`, `version` and `commit` above
23    /// are then the marketplace's own.
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub plugin: Option<String>,
26    /// Where `plugin`'s files came from.
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub content: Option<LockedContent>,
29}
30
31/// The tree a marketplace plugin was read from. A plugin in the marketplace's own repository
32/// repeats the marketplace's `url` and `commit` with its path as `subpath`; with a marketplace
33/// at a local path, a local plugin has only its `subpath`.
34#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
35pub struct LockedContent {
36    #[serde(default, skip_serializing_if = "Option::is_none")]
37    pub url: Option<String>,
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    pub subpath: Option<SourceSubpath>,
40    #[serde(default, skip_serializing_if = "Option::is_none")]
41    pub commit: Option<String>,
42}
43
44/// A marketplace plugin as acquired: kept with the rooted package so that preparing it again
45/// (a restart pass) reads it through the same marketplace entry, never a fresh fetch.
46#[derive(Debug, Clone)]
47pub struct PluginRoot {
48    pub hint: PluginHint,
49    pub content: LockedContent,
50    /// The dependency named this plugin; otherwise its marketplace lists only this one.
51    pub named: bool,
52}
53
54impl PluginRoot {
55    pub fn name(&self) -> &str {
56        &self.hint.entry.name
57    }
58
59    /// The plugin the lock records: only one the dependency named, so a lock written for a
60    /// dependency that never named one (v0.19.0's) still describes it.
61    pub fn locked_name(&self) -> Option<&str> {
62        self.named.then(|| self.name())
63    }
64
65    /// Where the plugin's files came from, when the lock must say: for a plugin the dependency
66    /// named, or one in another repository, which a later sync fetches again by this record. An
67    /// only plugin in the marketplace's own tree is the marketplace's commit and needs none.
68    pub fn locked_content(&self) -> Option<&LockedContent> {
69        (self.named || matches!(self.hint.entry.source, PluginSource::Remote { .. }))
70            .then_some(&self.content)
71    }
72}