#[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::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, 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;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", rename = "app.certified.location", tag = "$type")]
pub struct Location<'a> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(borrow)]
pub location: LocationLocation<'a>,
#[serde(borrow)]
pub location_type: LocationLocationType<'a>,
#[serde(borrow)]
pub lp_version: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub name: Option<CowStr<'a>>,
#[serde(borrow)]
pub srs: UriValue<'a>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
pub enum LocationLocation<'a> {
#[serde(rename = "org.hypercerts.defs#uri")]
Uri(Box<Uri<'a>>),
#[serde(rename = "org.hypercerts.defs#smallBlob")]
SmallBlob(Box<SmallBlob<'a>>),
#[serde(rename = "app.certified.location#string")]
String(Box<location::LocationString<'a>>),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum LocationLocationType<'a> {
CoordinateDecimal,
GeojsonPoint,
Geojson,
H3,
Geohash,
Wkt,
Address,
ScaledCoordinates,
Other(CowStr<'a>),
}
impl<'a> LocationLocationType<'a> {
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(),
}
}
}
impl<'a> From<&'a str> for LocationLocationType<'a> {
fn from(s: &'a str) -> Self {
match s {
"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(CowStr::from(s)),
}
}
}
impl<'a> From<String> for LocationLocationType<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"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(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for LocationLocationType<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for LocationLocationType<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for LocationLocationType<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for LocationLocationType<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for LocationLocationType<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for LocationLocationType<'_> {
type Output = LocationLocationType<'static>;
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<'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: Location<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct LocationString<'a> {
#[serde(borrow)]
pub string: CowStr<'a>,
}
impl<'a> Location<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, LocationRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[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<'de> = LocationGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<LocationGetRecordOutput<'_>> for Location<'_> {
fn from(output: LocationGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
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<'a> LexiconSchema for Location<'a> {
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<'a> LexiconSchema for LocationString<'a> {
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 LpVersion;
type Location;
type Srs;
type LocationType;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type LpVersion = Unset;
type Location = Unset;
type Srs = Unset;
type LocationType = Unset;
type CreatedAt = Unset;
}
pub struct SetLpVersion<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLpVersion<S> {}
impl<S: State> State for SetLpVersion<S> {
type LpVersion = Set<members::lp_version>;
type Location = S::Location;
type Srs = S::Srs;
type LocationType = S::LocationType;
type CreatedAt = S::CreatedAt;
}
pub struct SetLocation<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLocation<S> {}
impl<S: State> State for SetLocation<S> {
type LpVersion = S::LpVersion;
type Location = Set<members::location>;
type Srs = S::Srs;
type LocationType = S::LocationType;
type CreatedAt = S::CreatedAt;
}
pub struct SetSrs<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSrs<S> {}
impl<S: State> State for SetSrs<S> {
type LpVersion = S::LpVersion;
type Location = S::Location;
type Srs = Set<members::srs>;
type LocationType = S::LocationType;
type CreatedAt = S::CreatedAt;
}
pub struct SetLocationType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLocationType<S> {}
impl<S: State> State for SetLocationType<S> {
type LpVersion = S::LpVersion;
type Location = S::Location;
type Srs = S::Srs;
type LocationType = Set<members::location_type>;
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 LpVersion = S::LpVersion;
type Location = S::Location;
type Srs = S::Srs;
type LocationType = S::LocationType;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct lp_version(());
pub struct location(());
pub struct srs(());
pub struct location_type(());
pub struct created_at(());
}
}
pub struct LocationBuilder<'a, S: location_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<CowStr<'a>>,
Option<LocationLocation<'a>>,
Option<LocationLocationType<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<UriValue<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Location<'a> {
pub fn new() -> LocationBuilder<'a, location_state::Empty> {
LocationBuilder::new()
}
}
impl<'a> LocationBuilder<'a, location_state::Empty> {
pub fn new() -> Self {
LocationBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> LocationBuilder<'a, S>
where
S: location_state::State,
S::CreatedAt: location_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> LocationBuilder<'a, location_state::SetCreatedAt<S>> {
self._fields.0 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: location_state::State> LocationBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> LocationBuilder<'a, S>
where
S: location_state::State,
S::Location: location_state::IsUnset,
{
pub fn location(
mut self,
value: impl Into<LocationLocation<'a>>,
) -> LocationBuilder<'a, location_state::SetLocation<S>> {
self._fields.2 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> LocationBuilder<'a, S>
where
S: location_state::State,
S::LocationType: location_state::IsUnset,
{
pub fn location_type(
mut self,
value: impl Into<LocationLocationType<'a>>,
) -> LocationBuilder<'a, location_state::SetLocationType<S>> {
self._fields.3 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> LocationBuilder<'a, S>
where
S: location_state::State,
S::LpVersion: location_state::IsUnset,
{
pub fn lp_version(
mut self,
value: impl Into<CowStr<'a>>,
) -> LocationBuilder<'a, location_state::SetLpVersion<S>> {
self._fields.4 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: location_state::State> LocationBuilder<'a, S> {
pub fn name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S> LocationBuilder<'a, S>
where
S: location_state::State,
S::Srs: location_state::IsUnset,
{
pub fn srs(
mut self,
value: impl Into<UriValue<'a>>,
) -> LocationBuilder<'a, location_state::SetSrs<S>> {
self._fields.6 = Option::Some(value.into());
LocationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> LocationBuilder<'a, S>
where
S: location_state::State,
S::LpVersion: location_state::IsSet,
S::Location: location_state::IsSet,
S::Srs: location_state::IsSet,
S::LocationType: location_state::IsSet,
S::CreatedAt: location_state::IsSet,
{
pub fn build(self) -> Location<'a> {
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<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Location<'a> {
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()
}
}