wdl_modules/resolver/types.rs
1//! Value types returned by the [`Resolver`](super::Resolver) trait.
2
3use std::collections::BTreeMap;
4use std::path::PathBuf;
5
6use semver::Version;
7
8use crate::dependency::DependencyName;
9use crate::hash::ContentHash;
10use crate::lockfile::ResolvedSource;
11use crate::signing::SignerIdentity;
12use crate::signing::VerifyingKey;
13
14/// A symbolic import resolved to a concrete file on disk.
15#[derive(Clone, Debug, PartialEq, Eq)]
16pub struct MaterializedFile {
17 /// Absolute path to the resolved file.
18 pub path: PathBuf,
19 /// Absolute path to the root directory of the module that owns the file.
20 pub module_root: PathBuf,
21 /// The source the file's owning module came from.
22 pub source: ResolvedSource,
23 /// The parsed manifest of the dependency that owns this file.
24 pub manifest: std::sync::Arc<crate::Manifest>,
25}
26
27impl MaterializedFile {
28 /// Builds the [`Module`](crate::module::Module) that owns this file.
29 ///
30 /// The owning module is a child of `consumer` reached through `dep_name`,
31 /// so its transitive imports resolve their own relative paths and
32 /// lockfile entries correctly. Callers consume this instead of
33 /// assembling a module from the file's manifest and root themselves.
34 pub fn child_module(
35 &self,
36 consumer: &crate::module::Module,
37 dep_name: DependencyName,
38 ) -> crate::module::Module {
39 consumer.child(dep_name, self.manifest.clone(), self.module_root.clone())
40 }
41}
42
43/// A fully resolved dependency tree, suitable for `module-lock.json`
44/// generation.
45#[derive(Clone, Debug, Default, PartialEq, Eq)]
46pub struct ResolvedTree {
47 /// The top-level resolved dependencies, keyed by consumer-chosen
48 /// dependency name.
49 pub dependencies: BTreeMap<DependencyName, ResolvedDependency>,
50}
51
52/// One resolved dependency in a [`ResolvedTree`].
53#[derive(Clone, Debug, PartialEq, Eq)]
54pub struct ResolvedDependency {
55 /// The resolved source.
56 pub source: ResolvedSource,
57 /// The resolved module version, when selected from a version tag.
58 pub version: Option<Version>,
59 /// The module's content hash. `None` for local path sources, which
60 /// carry no checksum and are read as-is.
61 pub checksum: Option<ContentHash>,
62 /// The signer's public key, if the module was signed. `None` for
63 /// local path sources, which are not subject to signature verification.
64 pub signer: Option<VerifyingKey>,
65 /// Optional signer identity metadata captured from `module.sig`.
66 pub signer_identity: Option<SignerIdentity>,
67 /// The module's transitive resolved dependencies.
68 pub dependencies: BTreeMap<DependencyName, ResolvedDependency>,
69}
70
71/// One resolved module inside a [`ResolvedDependency`].
72///
73/// This type is produced during resolution before being folded into
74/// [`ResolvedDependency`].
75#[derive(Clone, Debug, PartialEq, Eq)]
76pub struct ResolvedModule {
77 /// The resolved module version, when selected from a version tag.
78 pub version: Option<Version>,
79 /// The module's content hash. `None` for local path sources, which
80 /// carry no checksum and are read as-is.
81 pub checksum: Option<ContentHash>,
82 /// The signer's public key, if the module was signed. `None` for
83 /// local path sources, which are not subject to signature verification.
84 pub signer: Option<VerifyingKey>,
85 /// Optional signer identity metadata captured from `module.sig`.
86 pub signer_identity: Option<SignerIdentity>,
87 /// The module's transitive resolved dependencies.
88 pub dependencies: BTreeMap<DependencyName, ResolvedDependency>,
89}