liboxen 0.53.0

Oxen is a fast data version control system, built with machine learning training data in mind. Designed to handle terabytes of data with ease, using a workflow similar to git. Version both structured and unstructured data of any modality: text, images, video, audio, CSV, Parquet, JSONL, model checkpoints, and more. liboxen is the embeddable core library behind the oxen CLI and server, which power fine tuning and inference pipelines for multimodal LLMs, image models, and video models on Oxen.ai.
use crate::api;
use crate::core::db::merkle_node::MerkleNodeBackend;
use crate::storage::StorageKind;
use crate::view::RepositoryView;
use crate::view::repository::RepositoryCreationView;
use crate::{error::OxenError, model::Remote};
use http::Uri;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct RemoteRepository {
    pub namespace: String,
    pub name: String,
    pub remote: Remote,
    pub min_version: Option<String>,
    pub is_empty: bool,
    /// The server's version-store backend for this repo (local filesystem or S3).
    pub storage_kind: StorageKind,
    /// The repo's Merkle node backend (filesystem / lmdb). A clone adopts it for the local repo it
    /// creates. `None` from a server that predates the field.
    pub merkle_node_backend: Option<MerkleNodeBackend>,
}

impl RemoteRepository {
    pub fn from_view(repository: &RepositoryView, remote: &Remote) -> RemoteRepository {
        RemoteRepository {
            namespace: repository.namespace.clone(),
            name: repository.name.clone(),
            remote: remote.clone(),
            min_version: repository.min_version.clone(),
            is_empty: repository.is_empty,
            storage_kind: repository.storage_kind,
            merkle_node_backend: repository.merkle_node_backend,
        }
    }

    pub fn from_creation_view(
        repository: &RepositoryCreationView,
        remote: &Remote,
    ) -> RemoteRepository {
        RemoteRepository {
            namespace: repository.namespace.clone(),
            name: repository.name.clone(),
            remote: remote.clone(),
            min_version: repository.min_version.clone(),
            is_empty: true,
            storage_kind: repository.storage_kind,
            merkle_node_backend: repository.merkle_node_backend,
        }
    }

    /// User friendly url for the remote repository
    /// Ex) http://localhost:3000/namespace/name
    pub fn url(&self) -> &str {
        &self.remote.url
    }

    /// Host of the remote repository
    pub fn host(&self) -> String {
        // parse it from the url
        let uri = self.remote.url.parse::<Uri>().unwrap();
        uri.host().unwrap().to_string()
    }

    /// Scheme of the remote repository
    pub fn scheme(&self) -> String {
        // parse it from the url
        let uri = self.remote.url.parse::<Uri>().unwrap();
        uri.scheme().unwrap().to_string()
    }

    /// Underlying api url for the remote repository
    /// Ex) http://localhost:3000/api/repos/namespace/name
    pub fn api_url(&self) -> Result<String, OxenError> {
        api::endpoint::url_from_repo(self, "")
    }
}