#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::Did;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::sh_tangled::sync::list_repos;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct DefaultBranch<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub head: Option<S>,
pub r#ref: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ListRepos<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<S>,
#[serde(default = "_default_limit")]
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(default = "_default_order")]
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ListReposOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<S>,
pub repos: Vec<list_repos::Repo<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(
Serialize, Deserialize, Debug, Clone, PartialEq, Eq, thiserror::Error, miette::Diagnostic,
)]
#[serde(tag = "error", content = "message")]
pub enum ListReposError {
#[serde(rename = "InvalidRequest")]
InvalidRequest(Option<SmolStr>),
#[serde(untagged)]
Other {
error: SmolStr,
message: Option<SmolStr>,
},
}
impl core::fmt::Display for ListReposError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidRequest(msg) => {
write!(f, "InvalidRequest")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Other { error, message } => {
write!(f, "{}", error)?;
if let Some(msg) = message {
write!(f, ": {}", msg)?;
}
Ok(())
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Repo<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub default_branch: Option<list_repos::DefaultBranch<S>>,
pub repo: Did<S>,
pub status: RepoStatus<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RepoStatus<S: BosStr = DefaultStr> {
Active,
Archived,
Disabled,
Other(S),
}
impl<S: BosStr> RepoStatus<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Active => "active",
Self::Archived => "archived",
Self::Disabled => "disabled",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"active" => Self::Active,
"archived" => Self::Archived,
"disabled" => Self::Disabled,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for RepoStatus<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for RepoStatus<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for RepoStatus<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for RepoStatus<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for RepoStatus<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for RepoStatus<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = RepoStatus<S::Output>;
fn into_static(self) -> Self::Output {
match self {
RepoStatus::Active => RepoStatus::Active,
RepoStatus::Archived => RepoStatus::Archived,
RepoStatus::Disabled => RepoStatus::Disabled,
RepoStatus::Other(v) => RepoStatus::Other(v.into_static()),
}
}
}
impl<S: BosStr> LexiconSchema for DefaultBranch<S> {
fn nsid() -> &'static str {
"sh.tangled.sync.listRepos"
}
fn def_name() -> &'static str {
"defaultBranch"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_sync_listRepos()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.head {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 128usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("head"),
max: 128usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.head {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 40usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("head"),
min: 40usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.r#ref;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2560usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("ref"),
max: 2560usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.r#ref;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 256usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("ref"),
max: 256usize,
actual: count,
});
}
}
}
Ok(())
}
}
pub struct ListReposResponse;
impl jacquard_common::xrpc::XrpcResp for ListReposResponse {
const NSID: &'static str = "sh.tangled.sync.listRepos";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ListReposOutput<S>;
type Err = ListReposError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ListRepos<S> {
const NSID: &'static str = "sh.tangled.sync.listRepos";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
type Response = ListReposResponse;
}
pub struct ListReposRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListReposRequest {
const PATH: &'static str = "/xrpc/sh.tangled.sync.listRepos";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
type Request<S: BosStr> = ListRepos<S>;
type Response = ListReposResponse;
}
impl<S: BosStr> LexiconSchema for Repo<S> {
fn nsid() -> &'static str {
"sh.tangled.sync.listRepos"
}
fn def_name() -> &'static str {
"repo"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_sync_listRepos()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
fn lexicon_doc_sh_tangled_sync_listRepos() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("sh.tangled.sync.listRepos"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("defaultBranch"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("ref")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("head"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Commit SHA at the tip of the default branch, for reconciling against a last-known state. Width depends on the repo's git object-format.",
),
),
min_length: Some(40usize),
max_length: Some(128usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("ref"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Default branch ref name, eg. refs/heads/main.",
),
),
max_length: Some(2560usize),
max_graphemes: Some(256usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::XrpcQuery(LexXrpcQuery {
parameters: Some(LexXrpcQueryParameter::Params(LexXrpcParameters {
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("cursor"),
LexXrpcParametersProperty::String(LexString {
description: Some(CowStr::new_static("Pagination cursor")),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("limit"),
LexXrpcParametersProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("order"),
LexXrpcParametersProperty::String(LexString {
description: Some(CowStr::new_static(
"Sort direction over the service's repo listing order.",
)),
..Default::default()
}),
);
map
},
..Default::default()
})),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("repo"),
LexUserType::Object(LexObject {
required: Some(vec![
SmolStr::new_static("repo"),
SmolStr::new_static("status"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("defaultBranch"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#defaultBranch"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("repo"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"DID of the git repo as minted by the knot",
)),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("status"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Serving status of the repo according to the knot.",
)),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
fn _default_limit() -> Option<i64> {
Some(50i64)
}
fn _default_order<S: jacquard_common::FromStaticStr>() -> Option<S> {
Some(S::from_static("desc"))
}
pub mod list_repos_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {}
#[allow(non_camel_case_types)]
pub mod members {}
}
pub struct ListReposBuilder<St: list_repos_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<i64>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl ListRepos<DefaultStr> {
pub fn new() -> ListReposBuilder<list_repos_state::Empty, DefaultStr> {
ListReposBuilder::new()
}
}
impl<S: BosStr> ListRepos<S> {
pub fn builder() -> ListReposBuilder<list_repos_state::Empty, S> {
ListReposBuilder::builder()
}
}
impl ListReposBuilder<list_repos_state::Empty, DefaultStr> {
pub fn new() -> Self {
ListReposBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> ListReposBuilder<list_repos_state::Empty, S> {
pub fn builder() -> Self {
ListReposBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<St: list_repos_state::State, S: BosStr> ListReposBuilder<St, S> {
pub fn cursor(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_cursor(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<St: list_repos_state::State, S: BosStr> ListReposBuilder<St, S> {
pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_limit(mut self, value: Option<i64>) -> Self {
self._fields.1 = value;
self
}
}
impl<St: list_repos_state::State, S: BosStr> ListReposBuilder<St, S> {
pub fn order(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_order(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<St, S: BosStr> ListReposBuilder<St, S>
where
St: list_repos_state::State,
{
pub fn build(self) -> ListRepos<S> {
ListRepos {
cursor: self._fields.0,
limit: self._fields.1,
order: self._fields.2,
}
}
}
pub mod repo_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Repo;
type Status;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Repo = Unset;
type Status = Unset;
}
pub struct SetRepo<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetRepo<St> {}
impl<St: State> State for SetRepo<St> {
type Repo = Set<members::repo>;
type Status = St::Status;
}
pub struct SetStatus<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetStatus<St> {}
impl<St: State> State for SetStatus<St> {
type Repo = St::Repo;
type Status = Set<members::status>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct repo(());
pub struct status(());
}
}
pub struct RepoBuilder<St: repo_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<list_repos::DefaultBranch<S>>,
Option<Did<S>>,
Option<RepoStatus<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl Repo<DefaultStr> {
pub fn new() -> RepoBuilder<repo_state::Empty, DefaultStr> {
RepoBuilder::new()
}
}
impl<S: BosStr> Repo<S> {
pub fn builder() -> RepoBuilder<repo_state::Empty, S> {
RepoBuilder::builder()
}
}
impl RepoBuilder<repo_state::Empty, DefaultStr> {
pub fn new() -> Self {
RepoBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> RepoBuilder<repo_state::Empty, S> {
pub fn builder() -> Self {
RepoBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<St: repo_state::State, S: BosStr> RepoBuilder<St, S> {
pub fn default_branch(
mut self,
value: impl Into<Option<list_repos::DefaultBranch<S>>>,
) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_default_branch(mut self, value: Option<list_repos::DefaultBranch<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<St, S: BosStr> RepoBuilder<St, S>
where
St: repo_state::State,
St::Repo: repo_state::IsUnset,
{
pub fn repo(mut self, value: impl Into<Did<S>>) -> RepoBuilder<repo_state::SetRepo<St>, S> {
self._fields.1 = Option::Some(value.into());
RepoBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> RepoBuilder<St, S>
where
St: repo_state::State,
St::Status: repo_state::IsUnset,
{
pub fn status(
mut self,
value: impl Into<RepoStatus<S>>,
) -> RepoBuilder<repo_state::SetStatus<St>, S> {
self._fields.2 = Option::Some(value.into());
RepoBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> RepoBuilder<St, S>
where
St: repo_state::State,
St::Repo: repo_state::IsSet,
St::Status: repo_state::IsSet,
{
pub fn build(self) -> Repo<S> {
Repo {
default_branch: self._fields.0,
repo: self._fields.1.unwrap(),
status: self._fields.2.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Repo<S> {
Repo {
default_branch: self._fields.0,
repo: self._fields.1.unwrap(),
status: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}