// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: app.certified.location // // This file was automatically generated from Lexicon schemas. // Any manual changes will be overwritten on the next regeneration. #[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::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, open_union}; use jacquard_lexicon::lexicon::LexiconDoc; use jacquard_lexicon::schema::LexiconSchema; use crate::app_certified::location; use crate::org_hypercerts::SmallBlob; use crate::org_hypercerts::Uri; #[allow(unused_imports)] use jacquard_lexicon::validation::{ConstraintError, ValidationPath}; use serde::{Deserialize, Serialize}; /// A location reference #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde( rename_all = "camelCase", rename = "app.certified.location", tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr") )] pub struct Location { /// Client-declared timestamp when this record was originally created pub created_at: Datetime, /// Additional context about this location, such as its significance to the work or specific boundaries #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, /// The location of where the work was performed as a URI, blob, or inline string. pub location: LocationLocation, /// An identifier for the format of the location data (e.g., coordinate-decimal, geojson-point). See the Location Protocol spec for the full registry: https://spec.decentralizedgeo.org/specification/location-types/#location-type-registry pub location_type: LocationLocationType, /// The version of the Location Protocol pub lp_version: S, /// Human-readable name for this location (e.g. 'Golden Gate Park', 'San Francisco Bay Area') #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, /// The Spatial Reference System URI (e.g., http://www.opengis.net/def/crs/OGC/1.3/CRS84) that defines the coordinate system. pub srs: UriValue, #[serde( flatten, default, deserialize_with = "deserialize_location_extra_data", skip_serializing_if = "Option::is_none" )] pub extra_data: Option>>, } #[open_union] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))] pub enum LocationLocation { #[serde(rename = "org.hypercerts.defs#uri")] Uri(Box>), #[serde(rename = "org.hypercerts.defs#smallBlob")] SmallBlob(Box>), #[serde(rename = "app.certified.location#string")] String(Box>), } /// An identifier for the format of the location data (e.g., coordinate-decimal, geojson-point). See the Location Protocol spec for the full registry: https://spec.decentralizedgeo.org/specification/location-types/#location-type-registry #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum LocationLocationType { CoordinateDecimal, GeojsonPoint, Geojson, H3, Geohash, Wkt, Address, ScaledCoordinates, Other(S), } impl LocationLocationType { pub fn as_str(&self) -> &str { match self { Self::CoordinateDecimal => "coordinate-decimal", Self::GeojsonPoint => "geojson-point", Self::Geojson => "geojson", Self::H3 => "h3", Self::Geohash => "geohash", Self::Wkt => "wkt", Self::Address => "address", Self::ScaledCoordinates => "scaledCoordinates", Self::Other(s) => s.as_ref(), } } /// Construct from a string-like value, matching known values. pub fn from_value(s: S) -> Self { match s.as_ref() { "coordinate-decimal" => Self::CoordinateDecimal, "geojson-point" => Self::GeojsonPoint, "geojson" => Self::Geojson, "h3" => Self::H3, "geohash" => Self::Geohash, "wkt" => Self::Wkt, "address" => Self::Address, "scaledCoordinates" => Self::ScaledCoordinates, _ => Self::Other(s), } } } impl core::fmt::Display for LocationLocationType { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{}", self.as_str()) } } impl AsRef for LocationLocationType { fn as_ref(&self) -> &str { self.as_str() } } impl Serialize for LocationLocationType { fn serialize(&self, serializer: Ser) -> Result where Ser: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for LocationLocationType { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { let s = S::deserialize(deserializer)?; Ok(Self::from_value(s)) } } impl Default for LocationLocationType { fn default() -> Self { Self::Other(Default::default()) } } impl jacquard_common::IntoStatic for LocationLocationType where S: BosStr + jacquard_common::IntoStatic, S::Output: BosStr, { type Output = LocationLocationType; fn into_static(self) -> Self::Output { match self { LocationLocationType::CoordinateDecimal => LocationLocationType::CoordinateDecimal, LocationLocationType::GeojsonPoint => LocationLocationType::GeojsonPoint, LocationLocationType::Geojson => LocationLocationType::Geojson, LocationLocationType::H3 => LocationLocationType::H3, LocationLocationType::Geohash => LocationLocationType::Geohash, LocationLocationType::Wkt => LocationLocationType::Wkt, LocationLocationType::Address => LocationLocationType::Address, LocationLocationType::ScaledCoordinates => LocationLocationType::ScaledCoordinates, LocationLocationType::Other(v) => LocationLocationType::Other(v.into_static()), } } } /// Typed wrapper for GetRecord response with this collection's record type. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct LocationGetRecordOutput { #[serde(skip_serializing_if = "Option::is_none")] pub cid: Option>, pub uri: AtUri, pub value: Location, } /// A location represented as a string, e.g. coordinates or a small GeoJSON string. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)] #[serde( rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr") )] pub struct LocationString { /// The location string value pub string: S, #[serde( flatten, default, deserialize_with = "deserialize_location_string_extra_data", skip_serializing_if = "Option::is_none" )] pub extra_data: Option>>, } impl Location { pub fn uri(uri: S) -> Result, UriError> { RecordUri::try_from_uri(AtUri::new(uri)?) } } /// Marker type for deserializing records from this collection. #[derive(Debug, Serialize, Deserialize)] pub struct LocationRecord; impl XrpcResp for LocationRecord { const NSID: &'static str = "app.certified.location"; const ENCODING: &'static str = "application/json"; type Output = LocationGetRecordOutput; type Err = RecordError; } impl From> for Location { fn from(output: LocationGetRecordOutput) -> Self { output.value } } impl Collection for Location { const NSID: &'static str = "app.certified.location"; type Record = LocationRecord; } impl Collection for LocationRecord { const NSID: &'static str = "app.certified.location"; type Record = LocationRecord; } impl LexiconSchema for Location { fn nsid() -> &'static str { "app.certified.location" } fn def_name() -> &'static str { "main" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_app_certified_location() } fn validate(&self) -> Result<(), ConstraintError> { if let Some(ref value) = self.description { #[allow(unused_comparisons)] if ::len(value.as_ref()) > 2000usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("description"), max: 2000usize, actual: ::len(value.as_ref()), }); } } if let Some(ref value) = self.description { { let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count(); if count > 500usize { return Err(ConstraintError::MaxGraphemes { path: ValidationPath::from_field("description"), max: 500usize, actual: count, }); } } } { let value = &self.location_type; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 20usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("location_type"), max: 20usize, actual: ::len(value.as_ref()), }); } } { let value = &self.lp_version; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 10usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("lp_version"), max: 10usize, actual: ::len(value.as_ref()), }); } } if let Some(ref value) = self.name { #[allow(unused_comparisons)] if ::len(value.as_ref()) > 1000usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("name"), max: 1000usize, actual: ::len(value.as_ref()), }); } } if let Some(ref value) = self.name { { let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count(); if count > 100usize { return Err(ConstraintError::MaxGraphemes { path: ValidationPath::from_field("name"), max: 100usize, actual: count, }); } } } { let value = &self.srs; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 100usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("srs"), max: 100usize, actual: ::len(value.as_ref()), }); } } Ok(()) } } impl LexiconSchema for LocationString { fn nsid() -> &'static str { "app.certified.location" } fn def_name() -> &'static str { "string" } fn lexicon_doc() -> LexiconDoc<'static> { lexicon_doc_app_certified_location() } fn validate(&self) -> Result<(), ConstraintError> { { let value = &self.string; #[allow(unused_comparisons)] if ::len(value.as_ref()) > 10000usize { return Err(ConstraintError::MaxLength { path: ValidationPath::from_field("string"), max: 10000usize, actual: ::len(value.as_ref()), }); } } { let value = &self.string; { let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count(); if count > 1000usize { return Err(ConstraintError::MaxGraphemes { path: ValidationPath::from_field("string"), max: 1000usize, actual: count, }); } } } Ok(()) } } fn deserialize_location_extra_data<'de, S, D>( deserializer: D, ) -> Result>>, D::Error> where S: BosStr + serde::Deserialize<'de>, D: serde::Deserializer<'de>, { let mut data = >> as serde::Deserialize<'de>>::deserialize(deserializer)?; if let Some(extra_data) = &mut data { extra_data.remove("$type"); if extra_data.is_empty() { data = None; } } Ok(data) } pub mod location_state { pub use crate::builder_types::{IsSet, IsUnset, Set, Unset}; #[allow(unused)] use ::core::marker::PhantomData; mod sealed { pub trait Sealed {} } /// State trait tracking which required fields have been set pub trait State: sealed::Sealed { type CreatedAt; type Location; type LocationType; type LpVersion; type Srs; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type CreatedAt = Unset; type Location = Unset; type LocationType = Unset; type LpVersion = Unset; type Srs = Unset; } ///State transition - sets the `created_at` field to Set pub struct SetCreatedAt(PhantomData St>); impl sealed::Sealed for SetCreatedAt {} impl State for SetCreatedAt { type CreatedAt = Set; type Location = St::Location; type LocationType = St::LocationType; type LpVersion = St::LpVersion; type Srs = St::Srs; } ///State transition - sets the `location` field to Set pub struct SetLocation(PhantomData St>); impl sealed::Sealed for SetLocation {} impl State for SetLocation { type CreatedAt = St::CreatedAt; type Location = Set; type LocationType = St::LocationType; type LpVersion = St::LpVersion; type Srs = St::Srs; } ///State transition - sets the `location_type` field to Set pub struct SetLocationType(PhantomData St>); impl sealed::Sealed for SetLocationType {} impl State for SetLocationType { type CreatedAt = St::CreatedAt; type Location = St::Location; type LocationType = Set; type LpVersion = St::LpVersion; type Srs = St::Srs; } ///State transition - sets the `lp_version` field to Set pub struct SetLpVersion(PhantomData St>); impl sealed::Sealed for SetLpVersion {} impl State for SetLpVersion { type CreatedAt = St::CreatedAt; type Location = St::Location; type LocationType = St::LocationType; type LpVersion = Set; type Srs = St::Srs; } ///State transition - sets the `srs` field to Set pub struct SetSrs(PhantomData St>); impl sealed::Sealed for SetSrs {} impl State for SetSrs { type CreatedAt = St::CreatedAt; type Location = St::Location; type LocationType = St::LocationType; type LpVersion = St::LpVersion; type Srs = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `created_at` field pub struct created_at(()); ///Marker type for the `location` field pub struct location(()); ///Marker type for the `location_type` field pub struct location_type(()); ///Marker type for the `lp_version` field pub struct lp_version(()); ///Marker type for the `srs` field pub struct srs(()); } } /// Builder for constructing an instance of this type. pub struct LocationBuilder { _state: PhantomData St>, _fields: ( Option, Option, Option>, Option>, Option, Option, Option>, ), _type: PhantomData S>, } impl Location { /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed pub fn new() -> LocationBuilder { LocationBuilder::new() } } impl Location { /// Create a new builder for this type pub fn builder() -> LocationBuilder { LocationBuilder::builder() } } impl LocationBuilder { /// Create a new builder with all fields unset, using the default string type, if needed pub fn new() -> Self { LocationBuilder { _state: PhantomData, _fields: (None, None, None, None, None, None, None), _type: PhantomData, } } } impl LocationBuilder { /// Create a new builder with all fields unset pub fn builder() -> Self { LocationBuilder { _state: PhantomData, _fields: (None, None, None, None, None, None, None), _type: PhantomData, } } } impl LocationBuilder where St: location_state::State, St::CreatedAt: location_state::IsUnset, { /// Set the `createdAt` field (required) pub fn created_at( mut self, value: impl Into, ) -> LocationBuilder, S> { self._fields.0 = Option::Some(value.into()); LocationBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl LocationBuilder { /// Set the `description` field (optional) pub fn description(mut self, value: impl Into>) -> Self { self._fields.1 = value.into(); self } /// Set the `description` field to an Option value (optional) pub fn maybe_description(mut self, value: Option) -> Self { self._fields.1 = value; self } } impl LocationBuilder where St: location_state::State, St::Location: location_state::IsUnset, { /// Set the `location` field (required) pub fn location( mut self, value: impl Into>, ) -> LocationBuilder, S> { self._fields.2 = Option::Some(value.into()); LocationBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl LocationBuilder where St: location_state::State, St::LocationType: location_state::IsUnset, { /// Set the `locationType` field (required) pub fn location_type( mut self, value: impl Into>, ) -> LocationBuilder, S> { self._fields.3 = Option::Some(value.into()); LocationBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl LocationBuilder where St: location_state::State, St::LpVersion: location_state::IsUnset, { /// Set the `lpVersion` field (required) pub fn lp_version( mut self, value: impl Into, ) -> LocationBuilder, S> { self._fields.4 = Option::Some(value.into()); LocationBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl LocationBuilder { /// Set the `name` field (optional) pub fn name(mut self, value: impl Into>) -> Self { self._fields.5 = value.into(); self } /// Set the `name` field to an Option value (optional) pub fn maybe_name(mut self, value: Option) -> Self { self._fields.5 = value; self } } impl LocationBuilder where St: location_state::State, St::Srs: location_state::IsUnset, { /// Set the `srs` field (required) pub fn srs( mut self, value: impl Into>, ) -> LocationBuilder, S> { self._fields.6 = Option::Some(value.into()); LocationBuilder { _state: PhantomData, _fields: self._fields, _type: PhantomData, } } } impl LocationBuilder where St: location_state::State, St::CreatedAt: location_state::IsSet, St::Location: location_state::IsSet, St::LocationType: location_state::IsSet, St::LpVersion: location_state::IsSet, St::Srs: location_state::IsSet, { /// Build the final struct. pub fn build(self) -> Location { Location { created_at: self._fields.0.unwrap(), description: self._fields.1, location: self._fields.2.unwrap(), location_type: self._fields.3.unwrap(), lp_version: self._fields.4.unwrap(), name: self._fields.5, srs: self._fields.6.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data. pub fn build_with_data(self, extra_data: BTreeMap>) -> Location { Location { created_at: self._fields.0.unwrap(), description: self._fields.1, location: self._fields.2.unwrap(), location_type: self._fields.3.unwrap(), lp_version: self._fields.4.unwrap(), name: self._fields.5, srs: self._fields.6.unwrap(), extra_data: Some(extra_data), } } } fn lexicon_doc_app_certified_location() -> 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("app.certified.location"), defs: { let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("main"), LexUserType::Record(LexRecord { description: Some(CowStr::new_static("A location reference")), key: Some(CowStr::new_static("tid")), record: LexRecordRecord::Object(LexObject { required: Some( vec![ SmolStr::new_static("lpVersion"), SmolStr::new_static("srs"), SmolStr::new_static("locationType"), SmolStr::new_static("location"), SmolStr::new_static("createdAt") ], ), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("createdAt"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "Client-declared timestamp when this record was originally created", ), ), format: Some(LexStringFormat::Datetime), ..Default::default() }), ); map.insert( SmolStr::new_static("description"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "Additional context about this location, such as its significance to the work or specific boundaries", ), ), max_length: Some(2000usize), max_graphemes: Some(500usize), ..Default::default() }), ); map.insert( SmolStr::new_static("location"), LexObjectProperty::Union(LexRefUnion { description: Some( CowStr::new_static( "The location of where the work was performed as a URI, blob, or inline string.", ), ), refs: vec![ CowStr::new_static("org.hypercerts.defs#uri"), CowStr::new_static("org.hypercerts.defs#smallBlob"), CowStr::new_static("#string") ], ..Default::default() }), ); map.insert( SmolStr::new_static("locationType"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "An identifier for the format of the location data (e.g., coordinate-decimal, geojson-point). See the Location Protocol spec for the full registry: https://spec.decentralizedgeo.org/specification/location-types/#location-type-registry", ), ), max_length: Some(20usize), ..Default::default() }), ); map.insert( SmolStr::new_static("lpVersion"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static("The version of the Location Protocol"), ), max_length: Some(10usize), ..Default::default() }), ); map.insert( SmolStr::new_static("name"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "Human-readable name for this location (e.g. 'Golden Gate Park', 'San Francisco Bay Area')", ), ), max_length: Some(1000usize), max_graphemes: Some(100usize), ..Default::default() }), ); map.insert( SmolStr::new_static("srs"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static( "The Spatial Reference System URI (e.g., http://www.opengis.net/def/crs/OGC/1.3/CRS84) that defines the coordinate system.", ), ), format: Some(LexStringFormat::Uri), max_length: Some(100usize), ..Default::default() }), ); map }, ..Default::default() }), ..Default::default() }), ); map.insert( SmolStr::new_static("string"), LexUserType::Object(LexObject { description: Some( CowStr::new_static( "A location represented as a string, e.g. coordinates or a small GeoJSON string.", ), ), required: Some(vec![SmolStr::new_static("string")]), properties: { #[allow(unused_mut)] let mut map = BTreeMap::new(); map.insert( SmolStr::new_static("string"), LexObjectProperty::String(LexString { description: Some( CowStr::new_static("The location string value"), ), max_length: Some(10000usize), max_graphemes: Some(1000usize), ..Default::default() }), ); map }, ..Default::default() }), ); map }, ..Default::default() } } fn deserialize_location_string_extra_data<'de, S, D>( deserializer: D, ) -> Result>>, D::Error> where S: BosStr + serde::Deserialize<'de>, D: serde::Deserializer<'de>, { let data = >> as serde::Deserialize<'de>>::deserialize(deserializer)?; Ok(data.filter(|extra_data| !extra_data.is_empty())) }