#[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::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;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::org_hypercerts::SmallBlob;
use crate::org_hypercerts::Uri;
use crate::app_certified::location;
#[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<S: BosStr = DefaultStr> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
pub location: LocationLocation<S>,
pub location_type: LocationLocationType<S>,
pub lp_version: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
pub srs: UriValue<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum LocationLocation<S: BosStr = DefaultStr> {
#[serde(rename = "org.hypercerts.defs#uri")]
Uri(Box<Uri<S>>),
#[serde(rename = "org.hypercerts.defs#smallBlob")]
SmallBlob(Box<SmallBlob<S>>),
#[serde(rename = "app.certified.location#string")]
String(Box<location::LocationString<S>>),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum LocationLocationType<S: BosStr = DefaultStr> {
CoordinateDecimal,
GeojsonPoint,
Geojson,
H3,
Geohash,
Wkt,
Address,
ScaledCoordinates,
Other(S),
}
impl<S: BosStr> LocationLocationType<S> {
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(),
}
}
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<S: BosStr> core::fmt::Display for LocationLocationType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for LocationLocationType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for LocationLocationType<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for LocationLocationType<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for LocationLocationType<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for LocationLocationType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = LocationLocationType<S::Output>;
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())
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LocationGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Location<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LocationString<S: BosStr = DefaultStr> {
pub string: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Location<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, LocationRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[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<S: BosStr> = LocationGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<LocationGetRecordOutput<S>> for Location<S> {
fn from(output: LocationGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Location<S> {
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<S: BosStr> LexiconSchema for Location<S> {
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 <str>::len(value.as_ref()) > 2000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 2000usize,
actual: <str>::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 <str>::len(value.as_ref()) > 20usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("location_type"),
max: 20usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.lp_version;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("lp_version"),
max: 10usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 1000usize,
actual: <str>::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 <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("srs"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for LocationString<S> {
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 <str>::len(value.as_ref()) > 10000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("string"),
max: 10000usize,
actual: <str>::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(())
}
}
pub mod location_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 Srs;
type LocationType;
type CreatedAt;
type LpVersion;
type Location;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Srs = Unset;
type LocationType = Unset;
type CreatedAt = Unset;
type LpVersion = Unset;
type Location = Unset;
}
pub struct SetSrs<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSrs<St> {}
impl<St: State> State for SetSrs<St> {
type Srs = Set<members::srs>;
type LocationType = St::LocationType;
type CreatedAt = St::CreatedAt;
type LpVersion = St::LpVersion;
type Location = St::Location;
}
pub struct SetLocationType<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLocationType<St> {}
impl<St: State> State for SetLocationType<St> {
type Srs = St::Srs;
type LocationType = Set<members::location_type>;
type CreatedAt = St::CreatedAt;
type LpVersion = St::LpVersion;
type Location = St::Location;
}
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 Srs = St::Srs;
type LocationType = St::LocationType;
type CreatedAt = Set<members::created_at>;
type LpVersion = St::LpVersion;
type Location = St::Location;
}
pub struct SetLpVersion<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLpVersion<St> {}
impl<St: State> State for SetLpVersion<St> {
type Srs = St::Srs;
type LocationType = St::LocationType;
type CreatedAt = St::CreatedAt;
type LpVersion = Set<members::lp_version>;
type Location = St::Location;
}
pub struct SetLocation<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLocation<St> {}
impl<St: State> State for SetLocation<St> {
type Srs = St::Srs;
type LocationType = St::LocationType;
type CreatedAt = St::CreatedAt;
type LpVersion = St::LpVersion;
type Location = Set<members::location>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct srs(());
pub struct location_type(());
pub struct created_at(());
pub struct lp_version(());
pub struct location(());
}
}
pub struct LocationBuilder<S: BosStr, St: location_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<S>,
Option<LocationLocation<S>>,
Option<LocationLocationType<S>>,
Option<S>,
Option<S>,
Option<UriValue<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Location<S> {
pub fn new() -> LocationBuilder<S, location_state::Empty> {
LocationBuilder::new()
}
}
impl<S: BosStr> LocationBuilder<S, location_state::Empty> {
pub fn new() -> Self {
LocationBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LocationBuilder<S, St>
where
St: location_state::State,
St::CreatedAt: location_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> LocationBuilder<S, location_state::SetCreatedAt<St>> {
self._fields.0 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: location_state::State> LocationBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> LocationBuilder<S, St>
where
St: location_state::State,
St::Location: location_state::IsUnset,
{
pub fn location(
mut self,
value: impl Into<LocationLocation<S>>,
) -> LocationBuilder<S, location_state::SetLocation<St>> {
self._fields.2 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LocationBuilder<S, St>
where
St: location_state::State,
St::LocationType: location_state::IsUnset,
{
pub fn location_type(
mut self,
value: impl Into<LocationLocationType<S>>,
) -> LocationBuilder<S, location_state::SetLocationType<St>> {
self._fields.3 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LocationBuilder<S, St>
where
St: location_state::State,
St::LpVersion: location_state::IsUnset,
{
pub fn lp_version(
mut self,
value: impl Into<S>,
) -> LocationBuilder<S, location_state::SetLpVersion<St>> {
self._fields.4 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: location_state::State> LocationBuilder<S, St> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St> LocationBuilder<S, St>
where
St: location_state::State,
St::Srs: location_state::IsUnset,
{
pub fn srs(
mut self,
value: impl Into<UriValue<S>>,
) -> LocationBuilder<S, location_state::SetSrs<St>> {
self._fields.6 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LocationBuilder<S, St>
where
St: location_state::State,
St::Srs: location_state::IsSet,
St::LocationType: location_state::IsSet,
St::CreatedAt: location_state::IsSet,
St::LpVersion: location_state::IsSet,
St::Location: location_state::IsSet,
{
pub fn build(self) -> Location<S> {
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(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Location<S> {
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> {
#[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("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()
}
}