pub mod comment;
pub mod status;
#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{Did, AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::sh_tangled::repo::pull;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "sh.tangled.repo.pull",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Pull<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub body: Option<S>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub mentions: Option<Vec<Did<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub patch: Option<S>,
pub patch_blob: BlobRef<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub references: Option<Vec<AtUri<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub source: Option<pull::Source<S>>,
pub target: pull::Target<S>,
pub title: 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")]
pub struct PullGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Pull<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Source<S: BosStr = DefaultStr> {
pub branch: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub repo: Option<AtUri<S>>,
pub sha: 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 Target<S: BosStr = DefaultStr> {
pub branch: S,
pub repo: AtUri<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Pull<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, PullRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PullRecord;
impl XrpcResp for PullRecord {
const NSID: &'static str = "sh.tangled.repo.pull";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = PullGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<PullGetRecordOutput<S>> for Pull<S> {
fn from(output: PullGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Pull<S> {
const NSID: &'static str = "sh.tangled.repo.pull";
type Record = PullRecord;
}
impl Collection for PullRecord {
const NSID: &'static str = "sh.tangled.repo.pull";
type Record = PullRecord;
}
impl<S: BosStr> LexiconSchema for Pull<S> {
fn nsid() -> &'static str {
"sh.tangled.repo.pull"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_repo_pull()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.patch_blob;
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["text/x-patch"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("patch_blob"),
accepted: vec!["text/x-patch".to_string()],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for Source<S> {
fn nsid() -> &'static str {
"sh.tangled.repo.pull"
}
fn def_name() -> &'static str {
"source"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_repo_pull()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.sha;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 40usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("sha"),
max: 40usize,
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(())
}
}
impl<S: BosStr> LexiconSchema for Target<S> {
fn nsid() -> &'static str {
"sh.tangled.repo.pull"
}
fn def_name() -> &'static str {
"target"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_tangled_repo_pull()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod pull_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Title;
type Target;
type PatchBlob;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type Target = Unset;
type PatchBlob = Unset;
type CreatedAt = Unset;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type Title = Set<members::title>;
type Target = St::Target;
type PatchBlob = St::PatchBlob;
type CreatedAt = St::CreatedAt;
}
pub struct SetTarget<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTarget<St> {}
impl<St: State> State for SetTarget<St> {
type Title = St::Title;
type Target = Set<members::target>;
type PatchBlob = St::PatchBlob;
type CreatedAt = St::CreatedAt;
}
pub struct SetPatchBlob<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPatchBlob<St> {}
impl<St: State> State for SetPatchBlob<St> {
type Title = St::Title;
type Target = St::Target;
type PatchBlob = Set<members::patch_blob>;
type CreatedAt = St::CreatedAt;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type Title = St::Title;
type Target = St::Target;
type PatchBlob = St::PatchBlob;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct target(());
pub struct patch_blob(());
pub struct created_at(());
}
}
pub struct PullBuilder<S: BosStr, St: pull_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Datetime>,
Option<Vec<Did<S>>>,
Option<S>,
Option<BlobRef<S>>,
Option<Vec<AtUri<S>>>,
Option<pull::Source<S>>,
Option<pull::Target<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Pull<S> {
pub fn new() -> PullBuilder<S, pull_state::Empty> {
PullBuilder::new()
}
}
impl<S: BosStr> PullBuilder<S, pull_state::Empty> {
pub fn new() -> Self {
PullBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: pull_state::State> PullBuilder<S, St> {
pub fn body(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_body(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> PullBuilder<S, St>
where
St: pull_state::State,
St::CreatedAt: pull_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> PullBuilder<S, pull_state::SetCreatedAt<St>> {
self._fields.1 = Option::Some(value.into());
PullBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: pull_state::State> PullBuilder<S, St> {
pub fn mentions(mut self, value: impl Into<Option<Vec<Did<S>>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_mentions(mut self, value: Option<Vec<Did<S>>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: pull_state::State> PullBuilder<S, St> {
pub fn patch(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_patch(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> PullBuilder<S, St>
where
St: pull_state::State,
St::PatchBlob: pull_state::IsUnset,
{
pub fn patch_blob(
mut self,
value: impl Into<BlobRef<S>>,
) -> PullBuilder<S, pull_state::SetPatchBlob<St>> {
self._fields.4 = Option::Some(value.into());
PullBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: pull_state::State> PullBuilder<S, St> {
pub fn references(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_references(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: pull_state::State> PullBuilder<S, St> {
pub fn source(mut self, value: impl Into<Option<pull::Source<S>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_source(mut self, value: Option<pull::Source<S>>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> PullBuilder<S, St>
where
St: pull_state::State,
St::Target: pull_state::IsUnset,
{
pub fn target(
mut self,
value: impl Into<pull::Target<S>>,
) -> PullBuilder<S, pull_state::SetTarget<St>> {
self._fields.7 = Option::Some(value.into());
PullBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PullBuilder<S, St>
where
St: pull_state::State,
St::Title: pull_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> PullBuilder<S, pull_state::SetTitle<St>> {
self._fields.8 = Option::Some(value.into());
PullBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PullBuilder<S, St>
where
St: pull_state::State,
St::Title: pull_state::IsSet,
St::Target: pull_state::IsSet,
St::PatchBlob: pull_state::IsSet,
St::CreatedAt: pull_state::IsSet,
{
pub fn build(self) -> Pull<S> {
Pull {
body: self._fields.0,
created_at: self._fields.1.unwrap(),
mentions: self._fields.2,
patch: self._fields.3,
patch_blob: self._fields.4.unwrap(),
references: self._fields.5,
source: self._fields.6,
target: self._fields.7.unwrap(),
title: self._fields.8.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Pull<S> {
Pull {
body: self._fields.0,
created_at: self._fields.1.unwrap(),
mentions: self._fields.2,
patch: self._fields.3,
patch_blob: self._fields.4.unwrap(),
references: self._fields.5,
source: self._fields.6,
target: self._fields.7.unwrap(),
title: self._fields.8.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_sh_tangled_repo_pull() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("sh.tangled.repo.pull"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("target"), SmolStr::new_static("title"),
SmolStr::new_static("patchBlob"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("body"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("mentions"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::Did),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("patch"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("(deprecated) use patchBlob instead"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("patchBlob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("references"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("source"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#source"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("target"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#target"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("source"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("branch"), SmolStr::new_static("sha")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("branch"),
LexObjectProperty::String(LexString { ..Default::default() }),
);
map.insert(
SmolStr::new_static("repo"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sha"),
LexObjectProperty::String(LexString {
min_length: Some(40usize),
max_length: Some(40usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("target"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("repo"), SmolStr::new_static("branch")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("branch"),
LexObjectProperty::String(LexString { ..Default::default() }),
);
map.insert(
SmolStr::new_static("repo"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod target_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Branch;
type Repo;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Branch = Unset;
type Repo = Unset;
}
pub struct SetBranch<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetBranch<St> {}
impl<St: State> State for SetBranch<St> {
type Branch = Set<members::branch>;
type Repo = St::Repo;
}
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 Branch = St::Branch;
type Repo = Set<members::repo>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct branch(());
pub struct repo(());
}
}
pub struct TargetBuilder<S: BosStr, St: target_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<AtUri<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Target<S> {
pub fn new() -> TargetBuilder<S, target_state::Empty> {
TargetBuilder::new()
}
}
impl<S: BosStr> TargetBuilder<S, target_state::Empty> {
pub fn new() -> Self {
TargetBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> TargetBuilder<S, St>
where
St: target_state::State,
St::Branch: target_state::IsUnset,
{
pub fn branch(
mut self,
value: impl Into<S>,
) -> TargetBuilder<S, target_state::SetBranch<St>> {
self._fields.0 = Option::Some(value.into());
TargetBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> TargetBuilder<S, St>
where
St: target_state::State,
St::Repo: target_state::IsUnset,
{
pub fn repo(
mut self,
value: impl Into<AtUri<S>>,
) -> TargetBuilder<S, target_state::SetRepo<St>> {
self._fields.1 = Option::Some(value.into());
TargetBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> TargetBuilder<S, St>
where
St: target_state::State,
St::Branch: target_state::IsSet,
St::Repo: target_state::IsSet,
{
pub fn build(self) -> Target<S> {
Target {
branch: self._fields.0.unwrap(),
repo: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Target<S> {
Target {
branch: self._fields.0.unwrap(),
repo: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}