Fix dependencies with dependencies
Cargo for whatever reason uses a separate struct for uploading than downloading,
with the only difference being `version_req` -> `req`.
Diff
chartered-types/src/cargo.rs | 14 ++++++--------
chartered-frontend/src/pages/crate/CrateView.tsx | 6 +++---
chartered-web/src/endpoints/cargo_api/publish.rs | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 73 insertions(+), 13 deletions(-)
@@ -40,13 +40,15 @@
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct CrateDependency<'a> {
pub name: Cow<'a, str>,
pub version_req: Cow<'a, str>,
pub req: Cow<'a, str>,
pub features: Vec<Cow<'a, str>>,
pub optional: bool,
pub default_features: bool,
pub target: Option<Cow<'a, str>>,
pub kind: Cow<'a, str>,
pub kind: Cow<'a, str>,
#[serde(skip_serializing_if = "Option::is_none")]
pub registry: Option<Cow<'a, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub package: Option<Cow<'a, str>>,
}
@@ -54,12 +56,8 @@
pub fn into_owned(self) -> CrateDependency<'static> {
CrateDependency {
name: Cow::Owned(self.name.into_owned()),
version_req: Cow::Owned(self.version_req.into_owned()),
features: self
.features
.into_iter()
.map(|v| Cow::Owned(v.into_owned()))
.collect(),
req: Cow::Owned(self.req.into_owned()),
features: self.features.into_iter().map(|v| Cow::Owned(v.into_owned())).collect(),
optional: self.optional,
default_features: self.default_features,
target: self.target.map(|v| Cow::Owned(v.into_owned())),
@@ -63,7 +63,7 @@
export interface CrateInfoVersionDependency {
name: string;
version_req: string;
req: string;
registry?: string;
}
@@ -236,7 +236,7 @@
)}
{crateVersion.deps.map((dep) => (
<Dependency
key={`${dep.name}-${dep.version_req}`}
key={`${dep.name}-${dep.req}`}
organisation={organisation}
dep={dep}
/>
@@ -292,7 +292,7 @@
return (
<li className="list-group-item">
{link} = "<strong>{dep.version_req}</strong>"
{link} = "<strong>{dep.req}</strong>"
</li>
);
}
@@ -1,7 +1,8 @@
use axum::extract;
use bytes::Bytes;
use chartered_db::{crates::Crate, users::User, ConnectionPool};
use chartered_fs::FileSystem;
use chartered_types::cargo::{CrateFeatures, CrateVersion, CrateDependency};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::{borrow::Cow, convert::TryInto, sync::Arc};
@@ -84,7 +85,7 @@
file_ref,
hex::encode(Sha256::digest(crate_bytes)),
metadata_bytes.len().try_into().unwrap(),
metadata.inner.into_owned(),
metadata.inner.into(),
metadata.meta,
)
.await?;
@@ -125,5 +126,66 @@
#[serde(flatten)]
meta: chartered_types::cargo::CrateVersionMetadata,
#[serde(flatten)]
inner: chartered_types::cargo::CrateVersion<'a>,
inner: MetadataCrateVersion<'a>,
}
#[derive(Deserialize, Debug)]
pub struct MetadataCrateVersion<'a> {
#[serde(borrow)]
pub name: Cow<'a, str>,
#[serde(borrow)]
pub vers: Cow<'a, str>,
pub deps: Vec<MetadataCrateDependency<'a>>,
pub features: CrateFeatures,
#[serde(borrow)]
pub links: Option<Cow<'a, str>>,
}
impl From<MetadataCrateVersion<'_>> for CrateVersion<'static> {
fn from(us: MetadataCrateVersion<'_>) -> Self {
Self {
name: Cow::Owned(us.name.into_owned()),
vers: Cow::Owned(us.vers.into_owned()),
deps: us.deps.into_iter().map(CrateDependency::from).collect(),
features: us.features,
links: us.links.map(|v| Cow::Owned(v.into_owned())),
}
}
}
#[derive(Deserialize, Debug)]
pub struct MetadataCrateDependency<'a> {
pub name: Cow<'a, str>,
pub version_req: Cow<'a, str>,
pub features: Vec<Cow<'a, str>>,
pub optional: bool,
pub default_features: bool,
pub target: Option<Cow<'a, str>>,
pub kind: Cow<'a, str>,
pub registry: Option<Cow<'a, str>>,
pub explicit_name_in_toml: Option<Cow<'a, str>>,
}
impl From<MetadataCrateDependency<'_>> for CrateDependency<'static> {
fn from(us: MetadataCrateDependency<'_>) -> CrateDependency<'static> {
let (name, package) = if let Some(explicit_name_in_toml) = us.explicit_name_in_toml {
(explicit_name_in_toml.into_owned(), Some(us.name.into_owned()))
} else {
(us.name.into_owned(), None)
};
Self {
name: Cow::Owned(name),
req: Cow::Owned(us.version_req.into_owned()),
features: us.features.into_iter().map(|v| Cow::Owned(v.into_owned())).collect(),
optional: us.optional,
default_features: us.default_features,
target: us.target.map(|v| Cow::Owned(v.into_owned())),
kind: Cow::Owned(us.kind.into_owned()),
registry: us.registry.map(|v| Cow::Owned(v.into_owned())),
package: package.map(Cow::Owned),
}
}
}