#[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::git::list_refs;
#[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 ListRefs<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>,
pub repo: Did<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ListRefsOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub default_branch: Option<list_refs::DefaultBranch<S>>,
pub refs: Vec<list_refs::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, thiserror::Error, miette::Diagnostic,
)]
#[serde(tag = "error", content = "message")]
pub enum ListRefsError {
#[serde(rename = "RepoNotFound")]
RepoNotFound(Option<SmolStr>),
#[serde(rename = "InvalidRequest")]
InvalidRequest(Option<SmolStr>),
#[serde(untagged)]
Other {
error: SmolStr,
message: Option<SmolStr>,
},
}
impl core::fmt::Display for ListRefsError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::RepoNotFound(msg) => {
write!(f, "RepoNotFound")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
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, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Ref<S: BosStr = DefaultStr> {
pub r#ref: S,
pub sha: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> LexiconSchema for DefaultBranch<S> {
fn nsid() -> &'static str {
"sh.tangled.git.listRefs"
}
fn def_name() -> &'static str {
"defaultBranch"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_git_listRefs()
}
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 ListRefsResponse;
impl jacquard_common::xrpc::XrpcResp for ListRefsResponse {
const NSID: &'static str = "sh.tangled.git.listRefs";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ListRefsOutput<S>;
type Err = ListRefsError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ListRefs<S> {
const NSID: &'static str = "sh.tangled.git.listRefs";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
type Response = ListRefsResponse;
}
pub struct ListRefsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListRefsRequest {
const PATH: &'static str = "/xrpc/sh.tangled.git.listRefs";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
type Request<S: BosStr> = ListRefs<S>;
type Response = ListRefsResponse;
}
impl<S: BosStr> LexiconSchema for Ref<S> {
fn nsid() -> &'static str {
"sh.tangled.git.listRefs"
}
fn def_name() -> &'static str {
"ref"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_git_listRefs()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
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,
});
}
}
}
{
let value = &self.sha;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 128usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("sha"),
max: 128usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.sha;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) < 40usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("sha"),
min: 40usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
fn lexicon_doc_sh_tangled_git_listRefs() -> 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.git.listRefs"),
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 that HEAD points at, 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 {
required: Some(vec![SmolStr::new_static("repo")]),
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("repo"),
LexXrpcParametersProperty::String(LexString {
description: Some(CowStr::new_static(
"DID of the git repo as minted by the knot",
)),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map
},
..Default::default()
})),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("ref"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("ref"), SmolStr::new_static("sha")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("ref"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Full ref name, eg. refs/heads/main or refs/tags/v1.0",
),
),
max_length: Some(2560usize),
max_graphemes: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sha"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Object SHA the ref points at. Width depends on the repo's git object-format.",
),
),
min_length: Some(40usize),
max_length: Some(128usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
fn _default_limit() -> Option<i64> {
Some(100i64)
}
pub mod list_refs_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;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Repo = 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>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct repo(());
}
}
pub struct ListRefsBuilder<St: list_refs_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<i64>, Option<Did<S>>),
_type: PhantomData<fn() -> S>,
}
impl ListRefs<DefaultStr> {
pub fn new() -> ListRefsBuilder<list_refs_state::Empty, DefaultStr> {
ListRefsBuilder::new()
}
}
impl<S: BosStr> ListRefs<S> {
pub fn builder() -> ListRefsBuilder<list_refs_state::Empty, S> {
ListRefsBuilder::builder()
}
}
impl ListRefsBuilder<list_refs_state::Empty, DefaultStr> {
pub fn new() -> Self {
ListRefsBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> ListRefsBuilder<list_refs_state::Empty, S> {
pub fn builder() -> Self {
ListRefsBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<St: list_refs_state::State, S: BosStr> ListRefsBuilder<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_refs_state::State, S: BosStr> ListRefsBuilder<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, S: BosStr> ListRefsBuilder<St, S>
where
St: list_refs_state::State,
St::Repo: list_refs_state::IsUnset,
{
pub fn repo(
mut self,
value: impl Into<Did<S>>,
) -> ListRefsBuilder<list_refs_state::SetRepo<St>, S> {
self._fields.2 = Option::Some(value.into());
ListRefsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ListRefsBuilder<St, S>
where
St: list_refs_state::State,
St::Repo: list_refs_state::IsSet,
{
pub fn build(self) -> ListRefs<S> {
ListRefs {
cursor: self._fields.0,
limit: self._fields.1,
repo: self._fields.2.unwrap(),
}
}
}