#[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::{AtUri, Cid, Datetime, UriValue};
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};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", rename = "garden.goals.goal", tag = "$type")]
pub struct Goal<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub accent_color: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub categories: Option<Vec<CowStr<'a>>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub completed_accent_color: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub completed_piece: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub completed_piece_blob: Option<BlobRef<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub completed_piece_url: Option<UriValue<'a>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(borrow)]
pub goal_id: CowStr<'a>,
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub piece: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub piece_blob: Option<BlobRef<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub piece_url: Option<UriValue<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub target_count: Option<i64>,
pub year: i64,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GoalGetRecordOutput<'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: Goal<'a>,
}
impl<'a> Goal<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, GoalRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GoalRecord;
impl XrpcResp for GoalRecord {
const NSID: &'static str = "garden.goals.goal";
const ENCODING: &'static str = "application/json";
type Output<'de> = GoalGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<GoalGetRecordOutput<'_>> for Goal<'_> {
fn from(output: GoalGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Goal<'_> {
const NSID: &'static str = "garden.goals.goal";
type Record = GoalRecord;
}
impl Collection for GoalRecord {
const NSID: &'static str = "garden.goals.goal";
type Record = GoalRecord;
}
impl<'a> LexiconSchema for Goal<'a> {
fn nsid() -> &'static str {
"garden.goals.goal"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_garden_goals_goal()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.accent_color {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("accent_color"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.completed_accent_color {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("completed_accent_color"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.completed_piece {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("completed_piece"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.completed_piece_blob {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("completed_piece_blob"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.completed_piece_blob {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/*"];
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("completed_piece_blob"),
accepted: vec!["image/*".to_string()],
actual: mime.to_string(),
});
}
}
}
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 500usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.goal_id;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("goal_id"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.piece {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("piece"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.piece_blob {
{
let size = value.blob().size;
if size > 1000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("piece_blob"),
max: 1000000usize,
actual: size,
});
}
}
}
if let Some(ref value) = self.piece_blob {
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/*"];
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("piece_blob"),
accepted: vec!["image/*".to_string()],
actual: mime.to_string(),
});
}
}
}
if let Some(ref value) = self.target_count {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("target_count"),
min: 1i64,
actual: *value,
});
}
}
{
let value = &self.year;
if *value < 1970i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("year"),
min: 1970i64,
actual: *value,
});
}
}
Ok(())
}
}
pub mod goal_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 GoalId;
type CreatedAt;
type Name;
type Year;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type GoalId = Unset;
type CreatedAt = Unset;
type Name = Unset;
type Year = Unset;
}
pub struct SetGoalId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetGoalId<S> {}
impl<S: State> State for SetGoalId<S> {
type GoalId = Set<members::goal_id>;
type CreatedAt = S::CreatedAt;
type Name = S::Name;
type Year = S::Year;
}
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 GoalId = S::GoalId;
type CreatedAt = Set<members::created_at>;
type Name = S::Name;
type Year = S::Year;
}
pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetName<S> {}
impl<S: State> State for SetName<S> {
type GoalId = S::GoalId;
type CreatedAt = S::CreatedAt;
type Name = Set<members::name>;
type Year = S::Year;
}
pub struct SetYear<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetYear<S> {}
impl<S: State> State for SetYear<S> {
type GoalId = S::GoalId;
type CreatedAt = S::CreatedAt;
type Name = S::Name;
type Year = Set<members::year>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct goal_id(());
pub struct created_at(());
pub struct name(());
pub struct year(());
}
}
pub struct GoalBuilder<'a, S: goal_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<Vec<CowStr<'a>>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<BlobRef<'a>>,
Option<UriValue<'a>>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<BlobRef<'a>>,
Option<UriValue<'a>>,
Option<i64>,
Option<i64>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Goal<'a> {
pub fn new() -> GoalBuilder<'a, goal_state::Empty> {
GoalBuilder::new()
}
}
impl<'a> GoalBuilder<'a, goal_state::Empty> {
pub fn new() -> Self {
GoalBuilder {
_state: PhantomData,
_fields: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_lifetime: PhantomData,
}
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn accent_color(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_accent_color(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn categories(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_categories(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn completed_accent_color(
mut self,
value: impl Into<Option<CowStr<'a>>>,
) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_completed_accent_color(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn completed_piece(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_completed_piece(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn completed_piece_blob(
mut self,
value: impl Into<Option<BlobRef<'a>>>,
) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_completed_piece_blob(mut self, value: Option<BlobRef<'a>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn completed_piece_url(
mut self,
value: impl Into<Option<UriValue<'a>>>,
) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_completed_piece_url(mut self, value: Option<UriValue<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::CreatedAt: goal_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> GoalBuilder<'a, goal_state::SetCreatedAt<S>> {
self._fields.6 = Option::Some(value.into());
GoalBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.7 = value;
self
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::GoalId: goal_state::IsUnset,
{
pub fn goal_id(
mut self,
value: impl Into<CowStr<'a>>,
) -> GoalBuilder<'a, goal_state::SetGoalId<S>> {
self._fields.8 = Option::Some(value.into());
GoalBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::Name: goal_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<CowStr<'a>>,
) -> GoalBuilder<'a, goal_state::SetName<S>> {
self._fields.9 = Option::Some(value.into());
GoalBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn piece(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_piece(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.10 = value;
self
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn piece_blob(mut self, value: impl Into<Option<BlobRef<'a>>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_piece_blob(mut self, value: Option<BlobRef<'a>>) -> Self {
self._fields.11 = value;
self
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn piece_url(mut self, value: impl Into<Option<UriValue<'a>>>) -> Self {
self._fields.12 = value.into();
self
}
pub fn maybe_piece_url(mut self, value: Option<UriValue<'a>>) -> Self {
self._fields.12 = value;
self
}
}
impl<'a, S: goal_state::State> GoalBuilder<'a, S> {
pub fn target_count(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.13 = value.into();
self
}
pub fn maybe_target_count(mut self, value: Option<i64>) -> Self {
self._fields.13 = value;
self
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::Year: goal_state::IsUnset,
{
pub fn year(
mut self,
value: impl Into<i64>,
) -> GoalBuilder<'a, goal_state::SetYear<S>> {
self._fields.14 = Option::Some(value.into());
GoalBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> GoalBuilder<'a, S>
where
S: goal_state::State,
S::GoalId: goal_state::IsSet,
S::CreatedAt: goal_state::IsSet,
S::Name: goal_state::IsSet,
S::Year: goal_state::IsSet,
{
pub fn build(self) -> Goal<'a> {
Goal {
accent_color: self._fields.0,
categories: self._fields.1,
completed_accent_color: self._fields.2,
completed_piece: self._fields.3,
completed_piece_blob: self._fields.4,
completed_piece_url: self._fields.5,
created_at: self._fields.6.unwrap(),
description: self._fields.7,
goal_id: self._fields.8.unwrap(),
name: self._fields.9.unwrap(),
piece: self._fields.10,
piece_blob: self._fields.11,
piece_url: self._fields.12,
target_count: self._fields.13,
year: self._fields.14.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>,
>,
) -> Goal<'a> {
Goal {
accent_color: self._fields.0,
categories: self._fields.1,
completed_accent_color: self._fields.2,
completed_piece: self._fields.3,
completed_piece_blob: self._fields.4,
completed_piece_url: self._fields.5,
created_at: self._fields.6.unwrap(),
description: self._fields.7,
goal_id: self._fields.8.unwrap(),
name: self._fields.9.unwrap(),
piece: self._fields.10,
piece_blob: self._fields.11,
piece_url: self._fields.12,
target_count: self._fields.13,
year: self._fields.14.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_garden_goals_goal() -> 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("garden.goals.goal"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A goal to track daily completions for a year.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("goalId"), SmolStr::new_static("name"),
SmolStr::new_static("year"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("accentColor"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Preset name or hex color for incomplete state",
),
),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("categories"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Array of category UUIDs this goal belongs to",
),
),
items: LexArrayItem::String(LexString {
max_length: Some(64usize),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("completedAccentColor"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Preset name or hex color for complete state",
),
),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("completedPiece"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Shape name or emoji for complete state"),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("completedPieceBlob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("completedPieceUrl"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Favicon URL for complete state"),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Timestamp when the goal was created"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Optional description of the goal"),
),
max_length: Some(500usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("goalId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Unique identifier for the goal (UUID)"),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Display name of the goal"),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("piece"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Shape name or emoji for incomplete state",
),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("pieceBlob"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("pieceUrl"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Favicon URL for incomplete state"),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("targetCount"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("year"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1970i64),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}