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 serde::{Deserialize, Serialize};
use std::path::PathBuf;
use utoipa::ToSchema;

use super::{Branch, Commit, Workspace, workspace::WorkspaceView};

/// In-process model. Not part of any API wire shape — `ParsedResourceView` is what
/// crosses the wire, and `From<ParsedResource> for ParsedResourceView` converts at the
/// response-construction boundary.
#[derive(Default, Debug, Clone)]
pub struct ParsedResource {
    pub commit: Option<Commit>,
    pub branch: Option<Branch>,
    pub workspace: Option<Workspace>,
    pub path: PathBuf,
    pub version: PathBuf,
    pub resource: PathBuf,
}

impl std::fmt::Display for ParsedResource {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}/{}",
            self.version.to_string_lossy(),
            self.path.to_string_lossy()
        )
    }
}

/// External (view) model that is returned to the client with fewer fields.
#[derive(Default, Deserialize, Serialize, Debug, Clone, ToSchema)]
pub struct ParsedResourceView {
    pub workspace: Option<WorkspaceView>,
    pub commit: Option<Commit>,
    pub branch: Option<Branch>,
    #[schema(value_type = String)]
    pub path: PathBuf,
    #[schema(value_type = String)]
    pub version: PathBuf,
    #[schema(value_type = String)]
    pub resource: PathBuf,
}

/// Conversion from the internal `ParsedResource` to the external `ParsedResourceView`.
impl From<ParsedResource> for ParsedResourceView {
    fn from(pr: ParsedResource) -> Self {
        Self {
            workspace: pr.workspace.map(WorkspaceView::from),
            commit: pr.commit,
            branch: pr.branch,
            path: pr.path,
            version: pr.version,
            resource: pr.resource,
        }
    }
}