1#![cfg_attr(docsrs, feature(doc_cfg))]
16
17pub mod authorization;
18mod error;
19pub mod event;
20mod grants;
21pub mod hd_key;
22pub mod interfaces;
23mod utils;
24
25#[cfg(feature = "client")]
26pub mod client;
27
28cfg_if::cfg_if! {
29 if #[cfg(feature = "server")] {
30 pub mod endpoint;
31 mod handlers;
32 pub mod provider;
33 mod schema;
34 pub mod store;
35 mod tasks;
36
37 pub use http::StatusCode;
39
40 pub use crate::endpoint::Message;
41 pub use crate::provider::Provider;
42 pub use crate::utils::cid;
43 }
44}
45
46use ::serde::{Deserialize, Serialize};
48pub use credibil_infosec::{Receiver, Signer};
49use derive_more::Display;
50
51pub use crate::error::Error;
52
53pub type Result<T, E = Error> = std::result::Result<T, E>;
55
56pub trait BlockStore: Send + Sync {
59 fn put(
61 &self, owner: &str, partition: &str, cid: &str, data: &[u8],
62 ) -> impl Future<Output = anyhow::Result<()>> + Send;
63
64 fn get(
67 &self, owner: &str, partition: &str, cid: &str,
68 ) -> impl Future<Output = anyhow::Result<Option<Vec<u8>>>> + Send;
69
70 fn delete(
72 &self, owner: &str, partition: &str, cid: &str,
73 ) -> impl Future<Output = anyhow::Result<()>> + Send;
74
75 fn purge(
77 &self, owner: &str, partition: &str,
78 ) -> impl Future<Output = anyhow::Result<()>> + Send;
79}
80
81#[derive(Clone, Debug, Default, Display, Deserialize, Serialize, PartialEq, Eq)]
83pub enum Interface {
84 #[default]
86 Records,
87
88 Protocols,
90
91 Messages,
93}
94
95#[derive(Clone, Debug, Default, Display, Deserialize, Serialize, PartialEq, Eq)]
97pub enum Method {
98 #[default]
100 Read,
101 Write,
103 Query,
105 Configure,
107 Subscribe,
109 Delete,
111}
112
113#[derive(Clone, Debug, Default, Deserialize, Serialize)]
115pub enum Protocol {
116 #[default]
118 Http,
119}
120
121#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
124#[serde(untagged)]
125pub enum OneOrMany<T> {
126 One(T),
128 Many(Vec<T>),
130}
131
132impl<T: Default> Default for OneOrMany<T> {
133 fn default() -> Self {
134 Self::One(T::default())
135 }
136}
137
138impl<T: Clone> OneOrMany<T> {
139 pub fn to_vec(&self) -> Vec<T> {
141 match self {
142 Self::One(value) => vec![value.clone()],
143 Self::Many(values) => values.clone(),
144 }
145 }
146}
147
148impl<T> From<T> for OneOrMany<T> {
149 fn from(value: T) -> Self {
150 Self::One(value)
151 }
152}
153
154impl<T> From<Vec<T>> for OneOrMany<T> {
155 fn from(value: Vec<T>) -> Self {
156 Self::Many(value)
157 }
158}
159
160mod serde {
162 use chrono::SecondsFormat::Micros;
163 use chrono::{DateTime, Utc};
164 use serde::Serializer;
165
166 pub fn rfc3339_micros<S>(date: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
168 where
169 S: Serializer,
170 {
171 let s = date.to_rfc3339_opts(Micros, true);
172 serializer.serialize_str(&s)
173 }
174
175 #[allow(clippy::ref_option)]
177 pub fn rfc3339_micros_opt<S>(
178 date: &Option<DateTime<Utc>>, serializer: S,
179 ) -> Result<S::Ok, S::Error>
180 where
181 S: Serializer,
182 {
183 let Some(date) = date else {
184 return serializer.serialize_none();
185 };
186 rfc3339_micros(date, serializer)
187 }
188}