diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fc17c3..d967bf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove unnecessary mutex in Wally package download by @daimond113 - Lazily format error messages by @daimond113 +## [0.5.3] - 2024-12-30 +### Added +- Add meta field in index files to preserve compatibility with potential future changes by @daimond113 + +### Changed +- Remove verbosity from release mode logging by @daimond113 + ## [0.5.2] - 2024-12-19 ### Fixed - Change dependency types for removed peer dependencies by @daimond113 @@ -117,6 +124,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Asyncify dependency linking by @daimond113 - Use `exec` in Unix bin linking to reduce the number of processes by @daimond113 +[0.5.3]: https://github.com/daimond113/pesde/compare/v0.5.2%2Bregistry.0.1.1..v0.5.3%2Bregistry.0.1.2 [0.5.2]: https://github.com/daimond113/pesde/compare/v0.5.1%2Bregistry.0.1.0..v0.5.2%2Bregistry.0.1.1 [0.5.1]: https://github.com/daimond113/pesde/compare/v0.5.0%2Bregistry.0.1.0..v0.5.1%2Bregistry.0.1.0 [0.5.0]: https://github.com/daimond113/pesde/compare/v0.4.7..v0.5.0%2Bregistry.0.1.0 diff --git a/Cargo.lock b/Cargo.lock index 5d69f6a..bc0f443 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3655,7 +3655,7 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pesde" -version = "0.5.2" +version = "0.5.3" dependencies = [ "anyhow", "async-compression", @@ -3698,7 +3698,7 @@ dependencies = [ [[package]] name = "pesde-registry" -version = "0.1.1" +version = "0.1.2" dependencies = [ "actix-cors", "actix-governor", diff --git a/Cargo.toml b/Cargo.toml index 02cef76..39e5a55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pesde" -version = "0.5.2" +version = "0.5.3" edition = "2021" license = "MIT" authors = ["daimond113 "] diff --git a/registry/CHANGELOG.md b/registry/CHANGELOG.md index 14dd6ed..1649c01 100644 --- a/registry/CHANGELOG.md +++ b/registry/CHANGELOG.md @@ -5,8 +5,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.2] +### Changed +- Update to pesde lib API changes by @daimond113 + +## [0.1.1] - 2024-12-19 +### Changed +- Switch to traccing for logging by @daimond113 + ## [0.1.0] - 2024-12-14 ### Added - Rewrite registry for pesde v0.5.0 by @daimond113 -[0.1.0]: https://github.com/daimond113/pesde/compare/v0.4.7..v0.5.0 +[0.1.2]: https://github.com/daimond113/pesde/compare/v0.5.2%2Bregistry.0.1.1..v0.5.3%2Bregistry.0.1.2 +[0.1.1]: https://github.com/daimond113/pesde/compare/v0.5.1%2Bregistry.0.1.0..v0.5.2%2Bregistry.0.1.1 +[0.1.0]: https://github.com/daimond113/pesde/compare/v0.4.7..v0.5.0%2Bregistry.0.1.0 diff --git a/registry/Cargo.toml b/registry/Cargo.toml index ea41efa..60c8c2d 100644 --- a/registry/Cargo.toml +++ b/registry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pesde-registry" -version = "0.1.1" +version = "0.1.2" edition = "2021" repository = "https://github.com/pesde-pkg/index" publish = false diff --git a/registry/src/endpoints/package_version.rs b/registry/src/endpoints/package_version.rs index 825ac12..7c27f53 100644 --- a/registry/src/endpoints/package_version.rs +++ b/registry/src/endpoints/package_version.rs @@ -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); diff --git a/registry/src/endpoints/package_versions.rs b/registry/src/endpoints/package_versions.rs index 4226807..93c8311 100644 --- a/registry/src/endpoints/package_versions.rs +++ b/registry/src/endpoints/package_versions.rs @@ -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 { diff --git a/registry/src/endpoints/publish_version.rs b/registry/src/endpoints/publish_version.rs index 1f846e7..9377938 100644 --- a/registry/src/endpoints/publish_version.rs +++ b/registry/src/endpoints/publish_version.rs @@ -377,7 +377,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 { @@ -392,11 +392,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? @@ -412,7 +413,8 @@ pub async fn publish_package( } } - if entries + if file + .entries .insert( VersionId::new(manifest.version.clone(), manifest.target.kind()), new_entry.clone(), @@ -428,7 +430,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()?)); diff --git a/registry/src/endpoints/search.rs b/registry/src/endpoints/search.rs index cb59eeb..0047a9d 100644 --- a/registry/src/endpoints/search.rs +++ b/registry/src/endpoints/search.rs @@ -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()), diff --git a/registry/src/search.rs b/registry/src/search.rs index bfcbba3..abb2419 100644 --- a/registry/src/search.rs +++ b/registry/src/search.rs @@ -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; }; diff --git a/src/source/pesde/mod.rs b/src/source/pesde/mod.rs index 703cbb4..ce73bbb 100644 --- a/src/source/pesde/mod.rs +++ b/src/source/pesde/mod.rs @@ -134,7 +134,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()); @@ -462,8 +462,20 @@ pub struct IndexFileEntry { pub dependencies: BTreeMap, } +/// 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; +#[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, +} /// Errors that can occur when interacting with the pesde package source pub mod errors { diff --git a/src/util.rs b/src/util.rs index 3baca73..cb942d9 100644 --- a/src/util.rs +++ b/src/util.rs @@ -83,3 +83,7 @@ pub fn deserialize_git_like_url<'de, D: Deserializer<'de>>( pub fn hash>(struc: S) -> String { format!("{:x}", Sha256::digest(struc.as_ref())) } + +pub fn is_default(t: &T) -> bool { + t == &T::default() +}