#[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::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};
use crate::dev_sensorthings::datastream;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", rename = "dev.sensorthings.datastream", tag = "$type")]
pub struct Datastream<'a> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(borrow)]
pub observation_type: UriValue<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub observed_area: Option<Data<'a>>,
#[serde(borrow)]
pub observed_property: AtUri<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
pub result_scale_factor: Option<i64>,
#[serde(borrow)]
pub sensor: AtUri<'a>,
#[serde(borrow)]
pub thing: AtUri<'a>,
#[serde(borrow)]
pub unit_of_measurement: datastream::UnitOfMeasurement<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub vertical_datum: Option<CowStr<'a>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct DatastreamGetRecordOutput<'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: Datastream<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct UnitOfMeasurement<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub definition: Option<UriValue<'a>>,
#[serde(borrow)]
pub name: CowStr<'a>,
#[serde(borrow)]
pub symbol: CowStr<'a>,
}
impl<'a> Datastream<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, DatastreamRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DatastreamRecord;
impl XrpcResp for DatastreamRecord {
const NSID: &'static str = "dev.sensorthings.datastream";
const ENCODING: &'static str = "application/json";
type Output<'de> = DatastreamGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<DatastreamGetRecordOutput<'_>> for Datastream<'_> {
fn from(output: DatastreamGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Datastream<'_> {
const NSID: &'static str = "dev.sensorthings.datastream";
type Record = DatastreamRecord;
}
impl Collection for DatastreamRecord {
const NSID: &'static str = "dev.sensorthings.datastream";
type Record = DatastreamRecord;
}
impl<'a> LexiconSchema for Datastream<'a> {
fn nsid() -> &'static str {
"dev.sensorthings.datastream"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_dev_sensorthings_datastream()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2048usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 2048usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 256usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 256usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.vertical_datum {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 256usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("vertical_datum"),
max: 256usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for UnitOfMeasurement<'a> {
fn nsid() -> &'static str {
"dev.sensorthings.datastream"
}
fn def_name() -> &'static str {
"unitOfMeasurement"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_dev_sensorthings_datastream()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.name;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 128usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 128usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.symbol;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 32usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("symbol"),
max: 32usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod datastream_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 ObservedProperty;
type Thing;
type UnitOfMeasurement;
type Name;
type Sensor;
type ObservationType;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type ObservedProperty = Unset;
type Thing = Unset;
type UnitOfMeasurement = Unset;
type Name = Unset;
type Sensor = Unset;
type ObservationType = Unset;
type CreatedAt = Unset;
}
pub struct SetObservedProperty<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetObservedProperty<S> {}
impl<S: State> State for SetObservedProperty<S> {
type ObservedProperty = Set<members::observed_property>;
type Thing = S::Thing;
type UnitOfMeasurement = S::UnitOfMeasurement;
type Name = S::Name;
type Sensor = S::Sensor;
type ObservationType = S::ObservationType;
type CreatedAt = S::CreatedAt;
}
pub struct SetThing<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetThing<S> {}
impl<S: State> State for SetThing<S> {
type ObservedProperty = S::ObservedProperty;
type Thing = Set<members::thing>;
type UnitOfMeasurement = S::UnitOfMeasurement;
type Name = S::Name;
type Sensor = S::Sensor;
type ObservationType = S::ObservationType;
type CreatedAt = S::CreatedAt;
}
pub struct SetUnitOfMeasurement<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUnitOfMeasurement<S> {}
impl<S: State> State for SetUnitOfMeasurement<S> {
type ObservedProperty = S::ObservedProperty;
type Thing = S::Thing;
type UnitOfMeasurement = Set<members::unit_of_measurement>;
type Name = S::Name;
type Sensor = S::Sensor;
type ObservationType = S::ObservationType;
type CreatedAt = S::CreatedAt;
}
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 ObservedProperty = S::ObservedProperty;
type Thing = S::Thing;
type UnitOfMeasurement = S::UnitOfMeasurement;
type Name = Set<members::name>;
type Sensor = S::Sensor;
type ObservationType = S::ObservationType;
type CreatedAt = S::CreatedAt;
}
pub struct SetSensor<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSensor<S> {}
impl<S: State> State for SetSensor<S> {
type ObservedProperty = S::ObservedProperty;
type Thing = S::Thing;
type UnitOfMeasurement = S::UnitOfMeasurement;
type Name = S::Name;
type Sensor = Set<members::sensor>;
type ObservationType = S::ObservationType;
type CreatedAt = S::CreatedAt;
}
pub struct SetObservationType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetObservationType<S> {}
impl<S: State> State for SetObservationType<S> {
type ObservedProperty = S::ObservedProperty;
type Thing = S::Thing;
type UnitOfMeasurement = S::UnitOfMeasurement;
type Name = S::Name;
type Sensor = S::Sensor;
type ObservationType = Set<members::observation_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 ObservedProperty = S::ObservedProperty;
type Thing = S::Thing;
type UnitOfMeasurement = S::UnitOfMeasurement;
type Name = S::Name;
type Sensor = S::Sensor;
type ObservationType = S::ObservationType;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct observed_property(());
pub struct thing(());
pub struct unit_of_measurement(());
pub struct name(());
pub struct sensor(());
pub struct observation_type(());
pub struct created_at(());
}
}
pub struct DatastreamBuilder<'a, S: datastream_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<UriValue<'a>>,
Option<Data<'a>>,
Option<AtUri<'a>>,
Option<i64>,
Option<AtUri<'a>>,
Option<AtUri<'a>>,
Option<datastream::UnitOfMeasurement<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Datastream<'a> {
pub fn new() -> DatastreamBuilder<'a, datastream_state::Empty> {
DatastreamBuilder::new()
}
}
impl<'a> DatastreamBuilder<'a, datastream_state::Empty> {
pub fn new() -> Self {
DatastreamBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> DatastreamBuilder<'a, S>
where
S: datastream_state::State,
S::CreatedAt: datastream_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> DatastreamBuilder<'a, datastream_state::SetCreatedAt<S>> {
self._fields.0 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: datastream_state::State> DatastreamBuilder<'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> DatastreamBuilder<'a, S>
where
S: datastream_state::State,
S::Name: datastream_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<CowStr<'a>>,
) -> DatastreamBuilder<'a, datastream_state::SetName<S>> {
self._fields.2 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> DatastreamBuilder<'a, S>
where
S: datastream_state::State,
S::ObservationType: datastream_state::IsUnset,
{
pub fn observation_type(
mut self,
value: impl Into<UriValue<'a>>,
) -> DatastreamBuilder<'a, datastream_state::SetObservationType<S>> {
self._fields.3 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: datastream_state::State> DatastreamBuilder<'a, S> {
pub fn observed_area(mut self, value: impl Into<Option<Data<'a>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_observed_area(mut self, value: Option<Data<'a>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S> DatastreamBuilder<'a, S>
where
S: datastream_state::State,
S::ObservedProperty: datastream_state::IsUnset,
{
pub fn observed_property(
mut self,
value: impl Into<AtUri<'a>>,
) -> DatastreamBuilder<'a, datastream_state::SetObservedProperty<S>> {
self._fields.5 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: datastream_state::State> DatastreamBuilder<'a, S> {
pub fn result_scale_factor(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_result_scale_factor(mut self, value: Option<i64>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S> DatastreamBuilder<'a, S>
where
S: datastream_state::State,
S::Sensor: datastream_state::IsUnset,
{
pub fn sensor(
mut self,
value: impl Into<AtUri<'a>>,
) -> DatastreamBuilder<'a, datastream_state::SetSensor<S>> {
self._fields.7 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> DatastreamBuilder<'a, S>
where
S: datastream_state::State,
S::Thing: datastream_state::IsUnset,
{
pub fn thing(
mut self,
value: impl Into<AtUri<'a>>,
) -> DatastreamBuilder<'a, datastream_state::SetThing<S>> {
self._fields.8 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> DatastreamBuilder<'a, S>
where
S: datastream_state::State,
S::UnitOfMeasurement: datastream_state::IsUnset,
{
pub fn unit_of_measurement(
mut self,
value: impl Into<datastream::UnitOfMeasurement<'a>>,
) -> DatastreamBuilder<'a, datastream_state::SetUnitOfMeasurement<S>> {
self._fields.9 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: datastream_state::State> DatastreamBuilder<'a, S> {
pub fn vertical_datum(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_vertical_datum(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.10 = value;
self
}
}
impl<'a, S> DatastreamBuilder<'a, S>
where
S: datastream_state::State,
S::ObservedProperty: datastream_state::IsSet,
S::Thing: datastream_state::IsSet,
S::UnitOfMeasurement: datastream_state::IsSet,
S::Name: datastream_state::IsSet,
S::Sensor: datastream_state::IsSet,
S::ObservationType: datastream_state::IsSet,
S::CreatedAt: datastream_state::IsSet,
{
pub fn build(self) -> Datastream<'a> {
Datastream {
created_at: self._fields.0.unwrap(),
description: self._fields.1,
name: self._fields.2.unwrap(),
observation_type: self._fields.3.unwrap(),
observed_area: self._fields.4,
observed_property: self._fields.5.unwrap(),
result_scale_factor: self._fields.6,
sensor: self._fields.7.unwrap(),
thing: self._fields.8.unwrap(),
unit_of_measurement: self._fields.9.unwrap(),
vertical_datum: self._fields.10,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
) -> Datastream<'a> {
Datastream {
created_at: self._fields.0.unwrap(),
description: self._fields.1,
name: self._fields.2.unwrap(),
observation_type: self._fields.3.unwrap(),
observed_area: self._fields.4,
observed_property: self._fields.5.unwrap(),
result_scale_factor: self._fields.6,
sensor: self._fields.7.unwrap(),
thing: self._fields.8.unwrap(),
unit_of_measurement: self._fields.9.unwrap(),
vertical_datum: self._fields.10,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_dev_sensorthings_datastream() -> 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("dev.sensorthings.datastream"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Groups Observations of one ObservedProperty by one Sensor on one Thing. Carries all context needed to interpret observation results.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("name"), SmolStr::new_static("thing"),
SmolStr::new_static("sensor"),
SmolStr::new_static("observedProperty"),
SmolStr::new_static("unitOfMeasurement"),
SmolStr::new_static("observationType"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
max_length: Some(2048usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
max_length: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("observationType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"O&M observation type URI, e.g. http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("observedArea"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"dev.sensorthings.thing#geoPoint",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("observedProperty"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT-URI of the dev.sensorthings.observedProperty record",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("resultScaleFactor"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sensor"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT-URI of the dev.sensorthings.sensor record",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("thing"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT-URI of the dev.sensorthings.thing record",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("unitOfMeasurement"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#unitOfMeasurement"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("verticalDatum"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Vertical datum reference for water level or elevation measurements. Either a URI (e.g. http://www.opengis.net/def/crs/EPSG/0/5731 for Malin Head) or a human-readable identifier (e.g. 'Chart Datum', 'local-gauge-zero'). Absent for non-vertical measurements.",
),
),
max_length: Some(256usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("unitOfMeasurement"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("UCUM-compatible unit description."),
),
required: Some(
vec![SmolStr::new_static("name"), SmolStr::new_static("symbol")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("definition"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"URI from QUDT, UCUM, or similar unit ontology",
),
),
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
max_length: Some(128usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("symbol"),
LexObjectProperty::String(LexString {
max_length: Some(32usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}