pub mod comment;
pub mod status;
#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::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;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Pull<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub body: Option<CowStr<'a>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub mentions: Option<Vec<Did<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub patch: Option<CowStr<'a>>,
#[serde(borrow)]
pub patch_blob: BlobRef<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub references: Option<Vec<AtUri<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub source: Option<pull::Source<'a>>,
#[serde(borrow)]
pub target: pull::Target<'a>,
#[serde(borrow)]
pub title: CowStr<'a>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PullGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: Pull<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Source<'a> {
#[serde(borrow)]
pub branch: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub repo: Option<AtUri<'a>>,
#[serde(borrow)]
pub sha: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Target<'a> {
#[serde(borrow)]
pub branch: CowStr<'a>,
#[serde(borrow)]
pub repo: AtUri<'a>,
}
impl<'a> Pull<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, PullRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[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<'de> = PullGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<PullGetRecordOutput<'_>> for Pull<'_> {
fn from(output: PullGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Pull<'_> {
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<'a> LexiconSchema for Pull<'a> {
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<'a> LexiconSchema for Source<'a> {
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<'a> LexiconSchema for Target<'a> {
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 PatchBlob;
type Target;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Title = Unset;
type PatchBlob = Unset;
type Target = Unset;
type CreatedAt = Unset;
}
pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTitle<S> {}
impl<S: State> State for SetTitle<S> {
type Title = Set<members::title>;
type PatchBlob = S::PatchBlob;
type Target = S::Target;
type CreatedAt = S::CreatedAt;
}
pub struct SetPatchBlob<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPatchBlob<S> {}
impl<S: State> State for SetPatchBlob<S> {
type Title = S::Title;
type PatchBlob = Set<members::patch_blob>;
type Target = S::Target;
type CreatedAt = S::CreatedAt;
}
pub struct SetTarget<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTarget<S> {}
impl<S: State> State for SetTarget<S> {
type Title = S::Title;
type PatchBlob = S::PatchBlob;
type Target = Set<members::target>;
type CreatedAt = S::CreatedAt;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type Title = S::Title;
type PatchBlob = S::PatchBlob;
type Target = S::Target;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct title(());
pub struct patch_blob(());
pub struct target(());
pub struct created_at(());
}
}
pub struct PullBuilder<'a, S: pull_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<Datetime>,
Option<Vec<Did<'a>>>,
Option<CowStr<'a>>,
Option<BlobRef<'a>>,
Option<Vec<AtUri<'a>>>,
Option<pull::Source<'a>>,
Option<pull::Target<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Pull<'a> {
pub fn new() -> PullBuilder<'a, pull_state::Empty> {
PullBuilder::new()
}
}
impl<'a> PullBuilder<'a, pull_state::Empty> {
pub fn new() -> Self {
PullBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: pull_state::State> PullBuilder<'a, S> {
pub fn body(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_body(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> PullBuilder<'a, S>
where
S: pull_state::State,
S::CreatedAt: pull_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> PullBuilder<'a, pull_state::SetCreatedAt<S>> {
self._fields.1 = Option::Some(value.into());
PullBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: pull_state::State> PullBuilder<'a, S> {
pub fn mentions(mut self, value: impl Into<Option<Vec<Did<'a>>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_mentions(mut self, value: Option<Vec<Did<'a>>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: pull_state::State> PullBuilder<'a, S> {
pub fn patch(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_patch(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> PullBuilder<'a, S>
where
S: pull_state::State,
S::PatchBlob: pull_state::IsUnset,
{
pub fn patch_blob(
mut self,
value: impl Into<BlobRef<'a>>,
) -> PullBuilder<'a, pull_state::SetPatchBlob<S>> {
self._fields.4 = Option::Some(value.into());
PullBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: pull_state::State> PullBuilder<'a, S> {
pub fn references(mut self, value: impl Into<Option<Vec<AtUri<'a>>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_references(mut self, value: Option<Vec<AtUri<'a>>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: pull_state::State> PullBuilder<'a, S> {
pub fn source(mut self, value: impl Into<Option<pull::Source<'a>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_source(mut self, value: Option<pull::Source<'a>>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S> PullBuilder<'a, S>
where
S: pull_state::State,
S::Target: pull_state::IsUnset,
{
pub fn target(
mut self,
value: impl Into<pull::Target<'a>>,
) -> PullBuilder<'a, pull_state::SetTarget<S>> {
self._fields.7 = Option::Some(value.into());
PullBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> PullBuilder<'a, S>
where
S: pull_state::State,
S::Title: pull_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<CowStr<'a>>,
) -> PullBuilder<'a, pull_state::SetTitle<S>> {
self._fields.8 = Option::Some(value.into());
PullBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> PullBuilder<'a, S>
where
S: pull_state::State,
S::Title: pull_state::IsSet,
S::PatchBlob: pull_state::IsSet,
S::Target: pull_state::IsSet,
S::CreatedAt: pull_state::IsSet,
{
pub fn build(self) -> Pull<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Pull<'a> {
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 Repo;
type Branch;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Repo = Unset;
type Branch = Unset;
}
pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRepo<S> {}
impl<S: State> State for SetRepo<S> {
type Repo = Set<members::repo>;
type Branch = S::Branch;
}
pub struct SetBranch<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetBranch<S> {}
impl<S: State> State for SetBranch<S> {
type Repo = S::Repo;
type Branch = Set<members::branch>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct repo(());
pub struct branch(());
}
}
pub struct TargetBuilder<'a, S: target_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<CowStr<'a>>, Option<AtUri<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Target<'a> {
pub fn new() -> TargetBuilder<'a, target_state::Empty> {
TargetBuilder::new()
}
}
impl<'a> TargetBuilder<'a, target_state::Empty> {
pub fn new() -> Self {
TargetBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> TargetBuilder<'a, S>
where
S: target_state::State,
S::Branch: target_state::IsUnset,
{
pub fn branch(
mut self,
value: impl Into<CowStr<'a>>,
) -> TargetBuilder<'a, target_state::SetBranch<S>> {
self._fields.0 = Option::Some(value.into());
TargetBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> TargetBuilder<'a, S>
where
S: target_state::State,
S::Repo: target_state::IsUnset,
{
pub fn repo(
mut self,
value: impl Into<AtUri<'a>>,
) -> TargetBuilder<'a, target_state::SetRepo<S>> {
self._fields.1 = Option::Some(value.into());
TargetBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> TargetBuilder<'a, S>
where
S: target_state::State,
S::Repo: target_state::IsSet,
S::Branch: target_state::IsSet,
{
pub fn build(self) -> Target<'a> {
Target {
branch: self._fields.0.unwrap(),
repo: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Target<'a> {
Target {
branch: self._fields.0.unwrap(),
repo: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}