#[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::{AtUri, Cid, Datetime, UriValue};
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};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "garden.goals.goal",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Goal<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub accent_color: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub categories: Option<Vec<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completed_accent_color: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completed_piece: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completed_piece_blob: Option<BlobRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub completed_piece_url: Option<UriValue<S>>,
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
pub goal_id: S,
pub name: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub piece: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub piece_blob: Option<BlobRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub piece_url: Option<UriValue<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub target_count: Option<i64>,
pub year: i64,
#[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 GoalGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Goal<S>,
}
impl<S: BosStr> Goal<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, GoalRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[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<S: BosStr> = GoalGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<GoalGetRecordOutput<S>> for Goal<S> {
fn from(output: GoalGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Goal<S> {
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<S: BosStr> LexiconSchema for Goal<S> {
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 Name;
type Year;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type GoalId = Unset;
type Name = Unset;
type Year = Unset;
type CreatedAt = Unset;
}
pub struct SetGoalId<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetGoalId<St> {}
impl<St: State> State for SetGoalId<St> {
type GoalId = Set<members::goal_id>;
type Name = St::Name;
type Year = St::Year;
type CreatedAt = St::CreatedAt;
}
pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetName<St> {}
impl<St: State> State for SetName<St> {
type GoalId = St::GoalId;
type Name = Set<members::name>;
type Year = St::Year;
type CreatedAt = St::CreatedAt;
}
pub struct SetYear<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetYear<St> {}
impl<St: State> State for SetYear<St> {
type GoalId = St::GoalId;
type Name = St::Name;
type Year = Set<members::year>;
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 GoalId = St::GoalId;
type Name = St::Name;
type Year = St::Year;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct goal_id(());
pub struct name(());
pub struct year(());
pub struct created_at(());
}
}
pub struct GoalBuilder<S: BosStr, St: goal_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Vec<S>>,
Option<S>,
Option<S>,
Option<BlobRef<S>>,
Option<UriValue<S>>,
Option<Datetime>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<BlobRef<S>>,
Option<UriValue<S>>,
Option<i64>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Goal<S> {
pub fn new() -> GoalBuilder<S, goal_state::Empty> {
GoalBuilder::new()
}
}
impl<S: BosStr> GoalBuilder<S, 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,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn accent_color(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_accent_color(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn categories(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_categories(mut self, value: Option<Vec<S>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn completed_accent_color(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_completed_accent_color(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn completed_piece(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_completed_piece(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn completed_piece_blob(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_completed_piece_blob(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn completed_piece_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_completed_piece_url(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St> GoalBuilder<S, St>
where
St: goal_state::State,
St::CreatedAt: goal_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> GoalBuilder<S, goal_state::SetCreatedAt<St>> {
self._fields.6 = Option::Some(value.into());
GoalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St> GoalBuilder<S, St>
where
St: goal_state::State,
St::GoalId: goal_state::IsUnset,
{
pub fn goal_id(
mut self,
value: impl Into<S>,
) -> GoalBuilder<S, goal_state::SetGoalId<St>> {
self._fields.8 = Option::Some(value.into());
GoalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GoalBuilder<S, St>
where
St: goal_state::State,
St::Name: goal_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<S>,
) -> GoalBuilder<S, goal_state::SetName<St>> {
self._fields.9 = Option::Some(value.into());
GoalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn piece(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_piece(mut self, value: Option<S>) -> Self {
self._fields.10 = value;
self
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn piece_blob(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_piece_blob(mut self, value: Option<BlobRef<S>>) -> Self {
self._fields.11 = value;
self
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
pub fn piece_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.12 = value.into();
self
}
pub fn maybe_piece_url(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.12 = value;
self
}
}
impl<S: BosStr, St: goal_state::State> GoalBuilder<S, St> {
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<S: BosStr, St> GoalBuilder<S, St>
where
St: goal_state::State,
St::Year: goal_state::IsUnset,
{
pub fn year(
mut self,
value: impl Into<i64>,
) -> GoalBuilder<S, goal_state::SetYear<St>> {
self._fields.14 = Option::Some(value.into());
GoalBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GoalBuilder<S, St>
where
St: goal_state::State,
St::GoalId: goal_state::IsSet,
St::Name: goal_state::IsSet,
St::Year: goal_state::IsSet,
St::CreatedAt: goal_state::IsSet,
{
pub fn build(self) -> Goal<S> {
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<SmolStr, Data<S>>) -> Goal<S> {
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()
}
}