177 lines
4.7 KiB
Rust
177 lines
4.7 KiB
Rust
use crank_core::{
|
|
AuthProfile, DescriptorId, ExportMode, Operation, OperationId, OperationStatus, Protocol,
|
|
SampleId,
|
|
};
|
|
use crank_mapping::MappingSet;
|
|
use crank_schema::Schema;
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::Value;
|
|
|
|
macro_rules! define_registry_id {
|
|
($name:ident) => {
|
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
|
pub struct $name(String);
|
|
|
|
impl $name {
|
|
pub fn new(value: impl Into<String>) -> Self {
|
|
Self(value.into())
|
|
}
|
|
|
|
pub fn as_str(&self) -> &str {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl From<String> for $name {
|
|
fn from(value: String) -> Self {
|
|
Self(value)
|
|
}
|
|
}
|
|
|
|
impl From<&str> for $name {
|
|
fn from(value: &str) -> Self {
|
|
Self(value.to_owned())
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
define_registry_id!(YamlImportJobId);
|
|
|
|
pub type RegistryOperation = Operation<Schema, MappingSet>;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct OperationSummary {
|
|
pub id: OperationId,
|
|
pub name: String,
|
|
pub display_name: String,
|
|
pub protocol: Protocol,
|
|
pub status: OperationStatus,
|
|
pub current_draft_version: u32,
|
|
pub latest_published_version: Option<u32>,
|
|
pub created_at: String,
|
|
pub updated_at: String,
|
|
pub published_at: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct OperationVersionRecord {
|
|
pub operation_id: OperationId,
|
|
pub version: u32,
|
|
pub status: OperationStatus,
|
|
pub change_note: Option<String>,
|
|
pub created_at: String,
|
|
pub created_by: Option<String>,
|
|
pub snapshot: RegistryOperation,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum SampleKind {
|
|
InputJson,
|
|
OutputJson,
|
|
YamlImportSource,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct OperationSampleMetadata {
|
|
pub id: SampleId,
|
|
pub operation_id: OperationId,
|
|
pub version: u32,
|
|
pub sample_kind: SampleKind,
|
|
pub storage_ref: String,
|
|
pub content_type: String,
|
|
pub file_name: Option<String>,
|
|
pub created_at: String,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum DescriptorKind {
|
|
ProtoUpload,
|
|
DescriptorSet,
|
|
ReflectionSnapshot,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct DescriptorMetadata {
|
|
pub id: DescriptorId,
|
|
pub operation_id: Option<OperationId>,
|
|
pub version: Option<u32>,
|
|
pub descriptor_kind: DescriptorKind,
|
|
pub storage_ref: String,
|
|
pub source_name: Option<String>,
|
|
pub package_index: Option<Value>,
|
|
pub created_at: String,
|
|
}
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum YamlImportJobStatus {
|
|
Pending,
|
|
Completed,
|
|
Failed,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct YamlImportJob {
|
|
pub id: YamlImportJobId,
|
|
pub source_sample_id: Option<SampleId>,
|
|
pub status: YamlImportJobStatus,
|
|
pub format_version: String,
|
|
pub mode: ExportMode,
|
|
pub result_operation_id: Option<OperationId>,
|
|
pub result_version: Option<u32>,
|
|
pub error_text: Option<String>,
|
|
pub created_at: String,
|
|
pub finished_at: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct YamlImportJobCompletion {
|
|
pub status: YamlImportJobStatus,
|
|
pub result_operation_id: Option<OperationId>,
|
|
pub result_version: Option<u32>,
|
|
pub error_text: Option<String>,
|
|
pub finished_at: String,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct CreateVersionRequest<'a> {
|
|
pub snapshot: &'a RegistryOperation,
|
|
pub change_note: Option<&'a str>,
|
|
pub created_by: Option<&'a str>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct PublishRequest<'a> {
|
|
pub operation_id: &'a OperationId,
|
|
pub version: u32,
|
|
pub published_at: &'a str,
|
|
pub published_by: Option<&'a str>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct CreateYamlImportJobRequest<'a> {
|
|
pub id: &'a YamlImportJobId,
|
|
pub source_sample_id: Option<&'a SampleId>,
|
|
pub format_version: &'a str,
|
|
pub mode: ExportMode,
|
|
pub created_at: &'a str,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct SaveAuthProfileRequest<'a> {
|
|
pub profile: &'a AuthProfile,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct SaveSampleMetadataRequest<'a> {
|
|
pub sample: &'a OperationSampleMetadata,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub struct SaveDescriptorMetadataRequest<'a> {
|
|
pub descriptor: &'a DescriptorMetadata,
|
|
}
|