mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-01-09 17:29:10 +00:00
feat: add meta in index file to preserve future compat
This commit is contained in:
parent
f009c957ca
commit
4f75af88b7
7 changed files with 42 additions and 20 deletions
|
@ -71,7 +71,7 @@ pub async fn get_package_version(
|
|||
|
||||
let (scope, name_part) = name.as_str();
|
||||
|
||||
let entries: IndexFile = {
|
||||
let file: IndexFile = {
|
||||
let source = app_state.source.lock().await;
|
||||
let repo = gix::open(source.path(&app_state.project))?;
|
||||
let tree = root_tree(&repo)?;
|
||||
|
@ -84,14 +84,15 @@ pub async fn get_package_version(
|
|||
|
||||
let Some((v_id, entry, targets)) = ({
|
||||
let version = match version {
|
||||
VersionRequest::Latest => match entries.keys().map(|k| k.version()).max() {
|
||||
VersionRequest::Latest => match file.entries.keys().map(|k| k.version()).max() {
|
||||
Some(latest) => latest.clone(),
|
||||
None => return Ok(HttpResponse::NotFound().finish()),
|
||||
},
|
||||
VersionRequest::Specific(version) => version,
|
||||
};
|
||||
|
||||
let versions = entries
|
||||
let versions = file
|
||||
.entries
|
||||
.iter()
|
||||
.filter(|(v_id, _)| *v_id.version() == version);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ pub async fn get_package_versions(
|
|||
|
||||
let (scope, name_part) = name.as_str();
|
||||
|
||||
let versions: IndexFile = {
|
||||
let file: IndexFile = {
|
||||
let source = app_state.source.lock().await;
|
||||
let repo = gix::open(source.path(&app_state.project))?;
|
||||
let tree = root_tree(&repo)?;
|
||||
|
@ -32,7 +32,7 @@ pub async fn get_package_versions(
|
|||
|
||||
let mut responses = BTreeMap::new();
|
||||
|
||||
for (v_id, entry) in versions {
|
||||
for (v_id, entry) in file.entries {
|
||||
let info = responses
|
||||
.entry(v_id.version().clone())
|
||||
.or_insert_with(|| PackageResponse {
|
||||
|
|
|
@ -371,7 +371,7 @@ pub async fn publish_package(
|
|||
}
|
||||
};
|
||||
|
||||
let mut entries: IndexFile =
|
||||
let mut file: IndexFile =
|
||||
toml::de::from_str(&read_file(&gix_tree, [scope, name])?.unwrap_or_default())?;
|
||||
|
||||
let new_entry = IndexFileEntry {
|
||||
|
@ -386,11 +386,12 @@ pub async fn publish_package(
|
|||
dependencies,
|
||||
};
|
||||
|
||||
let this_version = entries
|
||||
let this_version = file
|
||||
.entries
|
||||
.keys()
|
||||
.find(|v_id| *v_id.version() == manifest.version);
|
||||
if let Some(this_version) = this_version {
|
||||
let other_entry = entries.get(this_version).unwrap();
|
||||
let other_entry = file.entries.get(this_version).unwrap();
|
||||
|
||||
// description cannot be different - which one to render in the "Recently published" list?
|
||||
// the others cannot be different because what to return from the versions endpoint?
|
||||
|
@ -406,7 +407,8 @@ pub async fn publish_package(
|
|||
}
|
||||
}
|
||||
|
||||
if entries
|
||||
if file
|
||||
.entries
|
||||
.insert(
|
||||
VersionId::new(manifest.version.clone(), manifest.target.kind()),
|
||||
new_entry.clone(),
|
||||
|
@ -422,7 +424,7 @@ pub async fn publish_package(
|
|||
let reference = repo.find_reference(&refspec)?;
|
||||
|
||||
{
|
||||
let index_content = toml::to_string(&entries)?;
|
||||
let index_content = toml::to_string(&file)?;
|
||||
let mut blob_writer = repo.blob_writer(None)?;
|
||||
blob_writer.write_all(index_content.as_bytes())?;
|
||||
oids.push((name, blob_writer.commit()?));
|
||||
|
|
|
@ -68,10 +68,11 @@ pub async fn search_packages(
|
|||
.unwrap();
|
||||
let (scope, name) = id.as_str();
|
||||
|
||||
let versions: IndexFile =
|
||||
let file: IndexFile =
|
||||
toml::de::from_str(&read_file(&tree, [scope, name]).unwrap().unwrap()).unwrap();
|
||||
|
||||
let (latest_version, entry) = versions
|
||||
let (latest_version, entry) = file
|
||||
.entries
|
||||
.iter()
|
||||
.max_by_key(|(v_id, _)| v_id.version())
|
||||
.unwrap();
|
||||
|
@ -79,17 +80,19 @@ pub async fn search_packages(
|
|||
PackageResponse {
|
||||
name: id.to_string(),
|
||||
version: latest_version.version().to_string(),
|
||||
targets: versions
|
||||
targets: file
|
||||
.entries
|
||||
.iter()
|
||||
.filter(|(v_id, _)| v_id.version() == latest_version.version())
|
||||
.map(|(_, entry)| (&entry.target).into())
|
||||
.collect(),
|
||||
description: entry.description.clone().unwrap_or_default(),
|
||||
published_at: versions
|
||||
published_at: file
|
||||
.entries
|
||||
.values()
|
||||
.max_by_key(|entry| entry.published_at)
|
||||
.unwrap()
|
||||
.published_at,
|
||||
.map(|entry| entry.published_at)
|
||||
.max()
|
||||
.unwrap(),
|
||||
license: entry.license.clone().unwrap_or_default(),
|
||||
authors: entry.authors.clone(),
|
||||
repository: entry.repository.clone().map(|url| url.to_string()),
|
||||
|
|
|
@ -104,7 +104,7 @@ pub async fn make_search(
|
|||
pin!(stream);
|
||||
|
||||
while let Some((pkg_name, mut file)) = stream.next().await {
|
||||
let Some((_, latest_entry)) = file.pop_last() else {
|
||||
let Some((_, latest_entry)) = file.entries.pop_last() else {
|
||||
tracing::error!("no versions found for {pkg_name}");
|
||||
continue;
|
||||
};
|
||||
|
|
|
@ -128,7 +128,7 @@ impl PackageSource for PesdePackageSource {
|
|||
}
|
||||
};
|
||||
|
||||
let entries: IndexFile = toml::from_str(&string)
|
||||
let IndexFile { entries, .. } = toml::from_str(&string)
|
||||
.map_err(|e| Self::ResolveError::Parse(specifier.name.to_string(), e))?;
|
||||
|
||||
tracing::debug!("{} has {} possible entries", specifier.name, entries.len());
|
||||
|
@ -432,8 +432,20 @@ pub struct IndexFileEntry {
|
|||
pub dependencies: BTreeMap<String, (DependencySpecifiers, DependencyType)>,
|
||||
}
|
||||
|
||||
/// The package metadata in the index file
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
||||
pub struct IndexMetadata {}
|
||||
|
||||
/// The index file for a package
|
||||
pub type IndexFile = BTreeMap<VersionId, IndexFileEntry>;
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
pub struct IndexFile {
|
||||
/// Any package-wide metadata
|
||||
#[serde(default, skip_serializing_if = "crate::util::is_default")]
|
||||
pub meta: IndexMetadata,
|
||||
/// The entries in the index file
|
||||
#[serde(flatten)]
|
||||
pub entries: BTreeMap<VersionId, IndexFileEntry>,
|
||||
}
|
||||
|
||||
/// Errors that can occur when interacting with the pesde package source
|
||||
pub mod errors {
|
||||
|
|
|
@ -83,3 +83,7 @@ pub fn deserialize_git_like_url<'de, D: Deserializer<'de>>(
|
|||
pub fn hash<S: AsRef<[u8]>>(struc: S) -> String {
|
||||
format!("{:x}", Sha256::digest(struc.as_ref()))
|
||||
}
|
||||
|
||||
pub fn is_default<T: Default + Eq>(t: &T) -> bool {
|
||||
t == &T::default()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue