#[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};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::dev_sensorthings::datastream;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "dev.sensorthings.datastream",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Datastream<S: BosStr = DefaultStr> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
pub name: S,
pub observation_type: UriValue<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub observed_area: Option<Data<S>>,
pub observed_property: AtUri<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub result_scale_factor: Option<i64>,
pub sensor: AtUri<S>,
pub thing: AtUri<S>,
pub unit_of_measurement: datastream::UnitOfMeasurement<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub vertical_datum: Option<S>,
#[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 DatastreamGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Datastream<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct UnitOfMeasurement<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub definition: Option<UriValue<S>>,
pub name: S,
pub symbol: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Datastream<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, DatastreamRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[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<S: BosStr> = DatastreamGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<DatastreamGetRecordOutput<S>> for Datastream<S> {
fn from(output: DatastreamGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Datastream<S> {
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<S: BosStr> LexiconSchema for Datastream<S> {
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<S: BosStr> LexiconSchema for UnitOfMeasurement<S> {
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::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type UnitOfMeasurement;
type ObservedProperty;
type Name;
type ObservationType;
type CreatedAt;
type Thing;
type Sensor;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type UnitOfMeasurement = Unset;
type ObservedProperty = Unset;
type Name = Unset;
type ObservationType = Unset;
type CreatedAt = Unset;
type Thing = Unset;
type Sensor = Unset;
}
pub struct SetUnitOfMeasurement<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetUnitOfMeasurement<St> {}
impl<St: State> State for SetUnitOfMeasurement<St> {
type UnitOfMeasurement = Set<members::unit_of_measurement>;
type ObservedProperty = St::ObservedProperty;
type Name = St::Name;
type ObservationType = St::ObservationType;
type CreatedAt = St::CreatedAt;
type Thing = St::Thing;
type Sensor = St::Sensor;
}
pub struct SetObservedProperty<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetObservedProperty<St> {}
impl<St: State> State for SetObservedProperty<St> {
type UnitOfMeasurement = St::UnitOfMeasurement;
type ObservedProperty = Set<members::observed_property>;
type Name = St::Name;
type ObservationType = St::ObservationType;
type CreatedAt = St::CreatedAt;
type Thing = St::Thing;
type Sensor = St::Sensor;
}
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 UnitOfMeasurement = St::UnitOfMeasurement;
type ObservedProperty = St::ObservedProperty;
type Name = Set<members::name>;
type ObservationType = St::ObservationType;
type CreatedAt = St::CreatedAt;
type Thing = St::Thing;
type Sensor = St::Sensor;
}
pub struct SetObservationType<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetObservationType<St> {}
impl<St: State> State for SetObservationType<St> {
type UnitOfMeasurement = St::UnitOfMeasurement;
type ObservedProperty = St::ObservedProperty;
type Name = St::Name;
type ObservationType = Set<members::observation_type>;
type CreatedAt = St::CreatedAt;
type Thing = St::Thing;
type Sensor = St::Sensor;
}
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 UnitOfMeasurement = St::UnitOfMeasurement;
type ObservedProperty = St::ObservedProperty;
type Name = St::Name;
type ObservationType = St::ObservationType;
type CreatedAt = Set<members::created_at>;
type Thing = St::Thing;
type Sensor = St::Sensor;
}
pub struct SetThing<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetThing<St> {}
impl<St: State> State for SetThing<St> {
type UnitOfMeasurement = St::UnitOfMeasurement;
type ObservedProperty = St::ObservedProperty;
type Name = St::Name;
type ObservationType = St::ObservationType;
type CreatedAt = St::CreatedAt;
type Thing = Set<members::thing>;
type Sensor = St::Sensor;
}
pub struct SetSensor<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSensor<St> {}
impl<St: State> State for SetSensor<St> {
type UnitOfMeasurement = St::UnitOfMeasurement;
type ObservedProperty = St::ObservedProperty;
type Name = St::Name;
type ObservationType = St::ObservationType;
type CreatedAt = St::CreatedAt;
type Thing = St::Thing;
type Sensor = Set<members::sensor>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct unit_of_measurement(());
pub struct observed_property(());
pub struct name(());
pub struct observation_type(());
pub struct created_at(());
pub struct thing(());
pub struct sensor(());
}
}
pub struct DatastreamBuilder<S: BosStr, St: datastream_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<S>,
Option<S>,
Option<UriValue<S>>,
Option<Data<S>>,
Option<AtUri<S>>,
Option<i64>,
Option<AtUri<S>>,
Option<AtUri<S>>,
Option<datastream::UnitOfMeasurement<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Datastream<S> {
pub fn new() -> DatastreamBuilder<S, datastream_state::Empty> {
DatastreamBuilder::new()
}
}
impl<S: BosStr> DatastreamBuilder<S, datastream_state::Empty> {
pub fn new() -> Self {
DatastreamBuilder {
_state: PhantomData,
_fields: (
None, None, None, None, None, None, None, None, None, None, None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DatastreamBuilder<S, St>
where
St: datastream_state::State,
St::CreatedAt: datastream_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> DatastreamBuilder<S, datastream_state::SetCreatedAt<St>> {
self._fields.0 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: datastream_state::State> DatastreamBuilder<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> DatastreamBuilder<S, St>
where
St: datastream_state::State,
St::Name: datastream_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<S>,
) -> DatastreamBuilder<S, datastream_state::SetName<St>> {
self._fields.2 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DatastreamBuilder<S, St>
where
St: datastream_state::State,
St::ObservationType: datastream_state::IsUnset,
{
pub fn observation_type(
mut self,
value: impl Into<UriValue<S>>,
) -> DatastreamBuilder<S, datastream_state::SetObservationType<St>> {
self._fields.3 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: datastream_state::State> DatastreamBuilder<S, St> {
pub fn observed_area(mut self, value: impl Into<Option<Data<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_observed_area(mut self, value: Option<Data<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> DatastreamBuilder<S, St>
where
St: datastream_state::State,
St::ObservedProperty: datastream_state::IsUnset,
{
pub fn observed_property(
mut self,
value: impl Into<AtUri<S>>,
) -> DatastreamBuilder<S, datastream_state::SetObservedProperty<St>> {
self._fields.5 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: datastream_state::State> DatastreamBuilder<S, St> {
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<S: BosStr, St> DatastreamBuilder<S, St>
where
St: datastream_state::State,
St::Sensor: datastream_state::IsUnset,
{
pub fn sensor(
mut self,
value: impl Into<AtUri<S>>,
) -> DatastreamBuilder<S, datastream_state::SetSensor<St>> {
self._fields.7 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DatastreamBuilder<S, St>
where
St: datastream_state::State,
St::Thing: datastream_state::IsUnset,
{
pub fn thing(
mut self,
value: impl Into<AtUri<S>>,
) -> DatastreamBuilder<S, datastream_state::SetThing<St>> {
self._fields.8 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> DatastreamBuilder<S, St>
where
St: datastream_state::State,
St::UnitOfMeasurement: datastream_state::IsUnset,
{
pub fn unit_of_measurement(
mut self,
value: impl Into<datastream::UnitOfMeasurement<S>>,
) -> DatastreamBuilder<S, datastream_state::SetUnitOfMeasurement<St>> {
self._fields.9 = Option::Some(value.into());
DatastreamBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: datastream_state::State> DatastreamBuilder<S, St> {
pub fn vertical_datum(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_vertical_datum(mut self, value: Option<S>) -> Self {
self._fields.10 = value;
self
}
}
impl<S: BosStr, St> DatastreamBuilder<S, St>
where
St: datastream_state::State,
St::UnitOfMeasurement: datastream_state::IsSet,
St::ObservedProperty: datastream_state::IsSet,
St::Name: datastream_state::IsSet,
St::ObservationType: datastream_state::IsSet,
St::CreatedAt: datastream_state::IsSet,
St::Thing: datastream_state::IsSet,
St::Sensor: datastream_state::IsSet,
{
pub fn build(self) -> Datastream<S> {
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<SmolStr, Data<S>>) -> Datastream<S> {
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> {
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("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()
}
}