Skip to content

Commit

Permalink
client: Make more types public
Browse files Browse the repository at this point in the history
  • Loading branch information
lann committed Jun 23, 2024
1 parent 34bd6ba commit 1e1139e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 58 deletions.
19 changes: 5 additions & 14 deletions crates/wasm-pkg-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
//! ```

mod loader;
mod local;
pub mod local;
pub mod oci;
mod release;
pub mod warg;

use std::collections::HashMap;
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -168,12 +168,3 @@ impl Client {
Ok(self.sources.get_mut(&registry).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,
}
34 changes: 1 addition & 33 deletions crates/wasm-pkg-client/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::cmp::Ordering;

use async_trait::async_trait;
use bytes::Bytes;
use futures_util::{stream::BoxStream, StreamExt};
Expand All @@ -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<Ordering> {
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 {
Expand Down
20 changes: 13 additions & 7 deletions crates/wasm-pkg-client/src/local.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Local filesystem-based package backend.
//!
//! Each package release is a file: `<root>/<namespace>/<name>/<version>.wasm`

use std::path::PathBuf;

use anyhow::anyhow;
Expand All @@ -6,22 +10,24 @@ 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)]
pub struct LocalConfig {
pub root: PathBuf,
}

/// A simple local filesystem-based backend.
///
/// Each package release is a file: `<root>/<namespace>/<name>/<version>.wasm`
pub struct LocalBackend {
pub(crate) struct LocalBackend {
root: PathBuf,
}

Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-pkg-client/src/oci/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
42 changes: 42 additions & 0 deletions crates/wasm-pkg-client/src/release.rs
Original file line number Diff line number Diff line change
@@ -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<Ordering> {
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)
}
}
4 changes: 2 additions & 2 deletions crates/wasm-pkg-client/src/warg/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit 1e1139e

Please sign in to comment.