#[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::cid::CidLink;
use jacquard_common::types::string::{Did, Tid, Datetime};
use jacquard_common::types::value::Data;
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::zone_stratos::sync::subscribe_records;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Commit<'a> {
#[serde(borrow)]
pub did: Did<'a>,
#[serde(borrow)]
pub ops: Vec<subscribe_records::RecordOp<'a>>,
pub rev: Tid,
pub seq: i64,
pub time: Datetime,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Info<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub message: Option<CowStr<'a>>,
#[serde(borrow)]
pub name: InfoName<'a>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum InfoName<'a> {
OutdatedCursor,
Other(CowStr<'a>),
}
impl<'a> InfoName<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::OutdatedCursor => "OutdatedCursor",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for InfoName<'a> {
fn from(s: &'a str) -> Self {
match s {
"OutdatedCursor" => Self::OutdatedCursor,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for InfoName<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"OutdatedCursor" => Self::OutdatedCursor,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for InfoName<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for InfoName<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for InfoName<'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 InfoName<'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 InfoName<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for InfoName<'_> {
type Output = InfoName<'static>;
fn into_static(self) -> Self::Output {
match self {
InfoName::OutdatedCursor => InfoName::OutdatedCursor,
InfoName::Other(v) => InfoName::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SubscribeRecords<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<i64>,
#[serde(borrow)]
pub did: Did<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub domain: Option<CowStr<'a>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum SubscribeRecordsMessage<'a> {
#[serde(rename = "#commit")]
Commit(Box<subscribe_records::Commit<'a>>),
#[serde(rename = "#info")]
Info(Box<subscribe_records::Info<'a>>),
}
impl<'a> SubscribeRecordsMessage<'a> {
pub fn decode_framed<'de: 'a>(
bytes: &'de [u8],
) -> Result<SubscribeRecordsMessage<'a>, jacquard_common::error::DecodeError> {
let (header, body) = jacquard_common::xrpc::subscription::parse_event_header(
bytes,
)?;
match header.t.as_str() {
"#commit" => {
let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
body,
)?;
Ok(Self::Commit(Box::new(variant)))
}
"#info" => {
let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
body,
)?;
Ok(Self::Info(Box::new(variant)))
}
unknown => {
Err(
jacquard_common::error::DecodeError::UnknownEventType(unknown.into()),
)
}
}
}
}
#[open_union]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Eq,
thiserror::Error,
miette::Diagnostic,
IntoStatic
)]
#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum SubscribeRecordsError<'a> {
#[serde(rename = "FutureCursor")]
FutureCursor(Option<CowStr<'a>>),
#[serde(rename = "AuthRequired")]
AuthRequired(Option<CowStr<'a>>),
}
impl core::fmt::Display for SubscribeRecordsError<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::FutureCursor(msg) => {
write!(f, "FutureCursor")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::AuthRequired(msg) => {
write!(f, "AuthRequired")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
}
}
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct RecordOp<'a> {
#[serde(borrow)]
pub action: RecordOpAction<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<CidLink<'a>>,
#[serde(borrow)]
pub path: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub record: Option<Data<'a>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RecordOpAction<'a> {
Create,
Update,
Delete,
Other(CowStr<'a>),
}
impl<'a> RecordOpAction<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Create => "create",
Self::Update => "update",
Self::Delete => "delete",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for RecordOpAction<'a> {
fn from(s: &'a str) -> Self {
match s {
"create" => Self::Create,
"update" => Self::Update,
"delete" => Self::Delete,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> From<String> for RecordOpAction<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"create" => Self::Create,
"update" => Self::Update,
"delete" => Self::Delete,
_ => Self::Other(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for RecordOpAction<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for RecordOpAction<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for RecordOpAction<'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 RecordOpAction<'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 RecordOpAction<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for RecordOpAction<'_> {
type Output = RecordOpAction<'static>;
fn into_static(self) -> Self::Output {
match self {
RecordOpAction::Create => RecordOpAction::Create,
RecordOpAction::Update => RecordOpAction::Update,
RecordOpAction::Delete => RecordOpAction::Delete,
RecordOpAction::Other(v) => RecordOpAction::Other(v.into_static()),
}
}
}
impl<'a> LexiconSchema for Commit<'a> {
fn nsid() -> &'static str {
"zone.stratos.sync.subscribeRecords"
}
fn def_name() -> &'static str {
"commit"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_zone_stratos_sync_subscribeRecords()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<'a> LexiconSchema for Info<'a> {
fn nsid() -> &'static str {
"zone.stratos.sync.subscribeRecords"
}
fn def_name() -> &'static str {
"info"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_zone_stratos_sync_subscribeRecords()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.message {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1024usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("message"),
max: 1024usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
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()),
});
}
}
Ok(())
}
}
pub struct SubscribeRecordsStream;
impl jacquard_common::xrpc::SubscriptionResp for SubscribeRecordsStream {
const NSID: &'static str = "zone.stratos.sync.subscribeRecords";
const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::Json;
type Message<'de> = SubscribeRecordsMessage<'de>;
type Error<'de> = SubscribeRecordsError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcSubscription for SubscribeRecords<'a> {
const NSID: &'static str = "zone.stratos.sync.subscribeRecords";
const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::Json;
type Stream = SubscribeRecordsStream;
}
pub struct SubscribeRecordsEndpoint;
impl jacquard_common::xrpc::SubscriptionEndpoint for SubscribeRecordsEndpoint {
const PATH: &'static str = "/xrpc/zone.stratos.sync.subscribeRecords";
const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::Json;
type Params<'de> = SubscribeRecords<'de>;
type Stream = SubscribeRecordsStream;
}
impl<'a> LexiconSchema for RecordOp<'a> {
fn nsid() -> &'static str {
"zone.stratos.sync.subscribeRecords"
}
fn def_name() -> &'static str {
"recordOp"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_zone_stratos_sync_subscribeRecords()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.action;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 32usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("action"),
max: 32usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.path;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("path"),
max: 512usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod commit_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 Ops;
type Time;
type Rev;
type Did;
type Seq;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Ops = Unset;
type Time = Unset;
type Rev = Unset;
type Did = Unset;
type Seq = Unset;
}
pub struct SetOps<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetOps<S> {}
impl<S: State> State for SetOps<S> {
type Ops = Set<members::ops>;
type Time = S::Time;
type Rev = S::Rev;
type Did = S::Did;
type Seq = S::Seq;
}
pub struct SetTime<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTime<S> {}
impl<S: State> State for SetTime<S> {
type Ops = S::Ops;
type Time = Set<members::time>;
type Rev = S::Rev;
type Did = S::Did;
type Seq = S::Seq;
}
pub struct SetRev<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRev<S> {}
impl<S: State> State for SetRev<S> {
type Ops = S::Ops;
type Time = S::Time;
type Rev = Set<members::rev>;
type Did = S::Did;
type Seq = S::Seq;
}
pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetDid<S> {}
impl<S: State> State for SetDid<S> {
type Ops = S::Ops;
type Time = S::Time;
type Rev = S::Rev;
type Did = Set<members::did>;
type Seq = S::Seq;
}
pub struct SetSeq<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSeq<S> {}
impl<S: State> State for SetSeq<S> {
type Ops = S::Ops;
type Time = S::Time;
type Rev = S::Rev;
type Did = S::Did;
type Seq = Set<members::seq>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct ops(());
pub struct time(());
pub struct rev(());
pub struct did(());
pub struct seq(());
}
}
pub struct CommitBuilder<'a, S: commit_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Did<'a>>,
Option<Vec<subscribe_records::RecordOp<'a>>>,
Option<Tid>,
Option<i64>,
Option<Datetime>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Commit<'a> {
pub fn new() -> CommitBuilder<'a, commit_state::Empty> {
CommitBuilder::new()
}
}
impl<'a> CommitBuilder<'a, commit_state::Empty> {
pub fn new() -> Self {
CommitBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> CommitBuilder<'a, S>
where
S: commit_state::State,
S::Did: commit_state::IsUnset,
{
pub fn did(
mut self,
value: impl Into<Did<'a>>,
) -> CommitBuilder<'a, commit_state::SetDid<S>> {
self._fields.0 = Option::Some(value.into());
CommitBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> CommitBuilder<'a, S>
where
S: commit_state::State,
S::Ops: commit_state::IsUnset,
{
pub fn ops(
mut self,
value: impl Into<Vec<subscribe_records::RecordOp<'a>>>,
) -> CommitBuilder<'a, commit_state::SetOps<S>> {
self._fields.1 = Option::Some(value.into());
CommitBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> CommitBuilder<'a, S>
where
S: commit_state::State,
S::Rev: commit_state::IsUnset,
{
pub fn rev(
mut self,
value: impl Into<Tid>,
) -> CommitBuilder<'a, commit_state::SetRev<S>> {
self._fields.2 = Option::Some(value.into());
CommitBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> CommitBuilder<'a, S>
where
S: commit_state::State,
S::Seq: commit_state::IsUnset,
{
pub fn seq(
mut self,
value: impl Into<i64>,
) -> CommitBuilder<'a, commit_state::SetSeq<S>> {
self._fields.3 = Option::Some(value.into());
CommitBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> CommitBuilder<'a, S>
where
S: commit_state::State,
S::Time: commit_state::IsUnset,
{
pub fn time(
mut self,
value: impl Into<Datetime>,
) -> CommitBuilder<'a, commit_state::SetTime<S>> {
self._fields.4 = Option::Some(value.into());
CommitBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> CommitBuilder<'a, S>
where
S: commit_state::State,
S::Ops: commit_state::IsSet,
S::Time: commit_state::IsSet,
S::Rev: commit_state::IsSet,
S::Did: commit_state::IsSet,
S::Seq: commit_state::IsSet,
{
pub fn build(self) -> Commit<'a> {
Commit {
did: self._fields.0.unwrap(),
ops: self._fields.1.unwrap(),
rev: self._fields.2.unwrap(),
seq: self._fields.3.unwrap(),
time: self._fields.4.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
) -> Commit<'a> {
Commit {
did: self._fields.0.unwrap(),
ops: self._fields.1.unwrap(),
rev: self._fields.2.unwrap(),
seq: self._fields.3.unwrap(),
time: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_zone_stratos_sync_subscribeRecords() -> 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("zone.stratos.sync.subscribeRecords"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("commit"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"A commit event containing record operations.",
),
),
required: Some(
vec![
SmolStr::new_static("seq"), SmolStr::new_static("did"),
SmolStr::new_static("time"), SmolStr::new_static("rev"),
SmolStr::new_static("ops")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("did"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The DID of the account."),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("ops"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"List of record operations in this commit.",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#recordOp"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rev"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("The repo revision.")),
format: Some(LexStringFormat::Tid),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("seq"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("time"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp of when the event was sequenced.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("info"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"An informational message about the subscription state.",
),
),
required: Some(vec![SmolStr::new_static("name")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("message"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Additional details about the info message.",
),
),
max_length: Some(1024usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The type of info message."),
),
max_length: Some(128usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::XrpcSubscription(LexXrpcSubscription {
parameters: Some(
LexXrpcSubscriptionParameter::Params(LexXrpcParameters {
required: Some(vec![SmolStr::new_static("did")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("cursor"),
LexXrpcParametersProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("did"),
LexXrpcParametersProperty::String(LexString {
description: Some(
CowStr::new_static(
"The DID of the account to subscribe to.",
),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("domain"),
LexXrpcParametersProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optional domain filter. Only events for records with this domain in their boundary will be emitted.",
),
),
max_length: Some(253usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("recordOp"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("A single record operation within a commit."),
),
required: Some(
vec![SmolStr::new_static("action"), SmolStr::new_static("path")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("action"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The type of operation."),
),
max_length: Some(32usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("cid"),
LexObjectProperty::CidLink(LexCidLink {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("path"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The record path (collection/rkey)."),
),
max_length: Some(512usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("record"),
LexObjectProperty::Unknown(LexUnknown {
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod subscribe_records_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 Did;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Did = Unset;
}
pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetDid<S> {}
impl<S: State> State for SetDid<S> {
type Did = Set<members::did>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct did(());
}
}
pub struct SubscribeRecordsBuilder<'a, S: subscribe_records_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<i64>, Option<Did<'a>>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> SubscribeRecords<'a> {
pub fn new() -> SubscribeRecordsBuilder<'a, subscribe_records_state::Empty> {
SubscribeRecordsBuilder::new()
}
}
impl<'a> SubscribeRecordsBuilder<'a, subscribe_records_state::Empty> {
pub fn new() -> Self {
SubscribeRecordsBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: subscribe_records_state::State> SubscribeRecordsBuilder<'a, S> {
pub fn cursor(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_cursor(mut self, value: Option<i64>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> SubscribeRecordsBuilder<'a, S>
where
S: subscribe_records_state::State,
S::Did: subscribe_records_state::IsUnset,
{
pub fn did(
mut self,
value: impl Into<Did<'a>>,
) -> SubscribeRecordsBuilder<'a, subscribe_records_state::SetDid<S>> {
self._fields.1 = Option::Some(value.into());
SubscribeRecordsBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: subscribe_records_state::State> SubscribeRecordsBuilder<'a, S> {
pub fn domain(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_domain(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> SubscribeRecordsBuilder<'a, S>
where
S: subscribe_records_state::State,
S::Did: subscribe_records_state::IsSet,
{
pub fn build(self) -> SubscribeRecords<'a> {
SubscribeRecords {
cursor: self._fields.0,
did: self._fields.1.unwrap(),
domain: self._fields.2,
}
}
}