diff --git a/crates/wasm-pkg-client/src/lib.rs b/crates/wasm-pkg-client/src/lib.rs index 98093b3..bc09505 100644 --- a/crates/wasm-pkg-client/src/lib.rs +++ b/crates/wasm-pkg-client/src/lib.rs @@ -27,8 +27,9 @@ //! ``` mod loader; -mod local; +pub mod local; pub mod oci; +mod release; pub mod warg; use std::collections::HashMap; @@ -39,10 +40,7 @@ use futures_util::stream::BoxStream; use wasm_pkg_common::metadata::RegistryMetadata; -use crate::{ - loader::PackageLoader, loader::VersionInfo, local::LocalBackend, oci::OciBackend, - warg::WargBackend, -}; +use crate::{loader::PackageLoader, local::LocalBackend, oci::OciBackend, warg::WargBackend}; pub use wasm_pkg_common::{ config::Config, @@ -52,6 +50,8 @@ pub use wasm_pkg_common::{ Error, }; +pub use release::{Release, VersionInfo}; + /// A read-only registry client. pub struct Client { config: Config, @@ -168,12 +168,3 @@ impl Client { Ok(self.sources.get_mut(®istry).unwrap().as_mut()) } } - -/// Package release details. -/// -/// Returned by [`Client::get_release`] and passed to [`Client::stream_content`]. -#[derive(Clone, Debug)] -pub struct Release { - pub version: Version, - pub content_digest: ContentDigest, -} diff --git a/crates/wasm-pkg-client/src/loader.rs b/crates/wasm-pkg-client/src/loader.rs index e73cb0e..4887028 100644 --- a/crates/wasm-pkg-client/src/loader.rs +++ b/crates/wasm-pkg-client/src/loader.rs @@ -1,5 +1,3 @@ -use std::cmp::Ordering; - use async_trait::async_trait; use bytes::Bytes; use futures_util::{stream::BoxStream, StreamExt}; @@ -8,37 +6,7 @@ use wasm_pkg_common::{ Error, }; -use crate::Release; - -#[derive(Clone, Debug, Eq)] -pub struct VersionInfo { - pub version: Version, - pub yanked: bool, -} - -impl Ord for VersionInfo { - fn cmp(&self, other: &Self) -> Ordering { - self.version.cmp(&other.version) - } -} - -impl PartialOrd for VersionInfo { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.version.cmp(&other.version)) - } -} - -impl PartialEq for VersionInfo { - fn eq(&self, other: &Self) -> bool { - self.version == other.version - } -} - -impl std::fmt::Display for VersionInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{version}", version = self.version) - } -} +use crate::release::{Release, VersionInfo}; #[async_trait] pub trait PackageLoader: Send { diff --git a/crates/wasm-pkg-client/src/local.rs b/crates/wasm-pkg-client/src/local.rs index 645e691..85723f1 100644 --- a/crates/wasm-pkg-client/src/local.rs +++ b/crates/wasm-pkg-client/src/local.rs @@ -1,3 +1,7 @@ +//! Local filesystem-based package backend. +//! +//! Each package release is a file: `///.wasm` + use std::path::PathBuf; use anyhow::anyhow; @@ -6,11 +10,16 @@ use bytes::Bytes; use futures_util::{stream::BoxStream, StreamExt, TryStreamExt}; use serde::Deserialize; use tokio_util::io::ReaderStream; -use wasm_pkg_common::{config::RegistryConfig, package::Version}; +use wasm_pkg_common::{ + config::RegistryConfig, + digest::ContentDigest, + package::{PackageRef, Version}, + Error, +}; use crate::{ - loader::{PackageLoader, VersionInfo}, - ContentDigest, Error, PackageRef, Release, + loader::PackageLoader, + release::{Release, VersionInfo}, }; #[derive(Clone, Debug, Deserialize)] @@ -18,10 +27,7 @@ pub struct LocalConfig { pub root: PathBuf, } -/// A simple local filesystem-based backend. -/// -/// Each package release is a file: `///.wasm` -pub struct LocalBackend { +pub(crate) struct LocalBackend { root: PathBuf, } diff --git a/crates/wasm-pkg-client/src/oci/loader.rs b/crates/wasm-pkg-client/src/oci/loader.rs index 15e5e44..b232516 100644 --- a/crates/wasm-pkg-client/src/oci/loader.rs +++ b/crates/wasm-pkg-client/src/oci/loader.rs @@ -6,8 +6,8 @@ use warg_protocol::Version; use wasm_pkg_common::{package::PackageRef, Error}; use crate::{ - loader::{PackageLoader, VersionInfo}, - Release, + loader::PackageLoader, + release::{Release, VersionInfo}, }; use super::{oci_registry_error, OciBackend}; diff --git a/crates/wasm-pkg-client/src/release.rs b/crates/wasm-pkg-client/src/release.rs new file mode 100644 index 0000000..82d7eba --- /dev/null +++ b/crates/wasm-pkg-client/src/release.rs @@ -0,0 +1,42 @@ +use std::cmp::Ordering; + +use wasm_pkg_common::{digest::ContentDigest, package::Version}; + +/// Package release details. +/// +/// Returned by [`Client::get_release`] and passed to [`Client::stream_content`]. +#[derive(Clone, Debug)] +pub struct Release { + pub version: Version, + pub content_digest: ContentDigest, +} + +#[derive(Clone, Debug, Eq)] +pub struct VersionInfo { + pub version: Version, + pub yanked: bool, +} + +impl Ord for VersionInfo { + fn cmp(&self, other: &Self) -> Ordering { + self.version.cmp(&other.version) + } +} + +impl PartialOrd for VersionInfo { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.version.cmp(&other.version)) + } +} + +impl PartialEq for VersionInfo { + fn eq(&self, other: &Self) -> bool { + self.version == other.version + } +} + +impl std::fmt::Display for VersionInfo { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{version}", version = self.version) + } +} diff --git a/crates/wasm-pkg-client/src/warg/loader.rs b/crates/wasm-pkg-client/src/warg/loader.rs index 8a5b119..b210b9e 100644 --- a/crates/wasm-pkg-client/src/warg/loader.rs +++ b/crates/wasm-pkg-client/src/warg/loader.rs @@ -8,8 +8,8 @@ use wasm_pkg_common::{ }; use crate::{ - loader::{PackageLoader, VersionInfo}, - Release, + loader::PackageLoader, + release::{Release, VersionInfo}, }; use super::{package_ref_to_name, warg_registry_error, WargBackend};