diff options
Diffstat (limited to 'lib/api-config')
| -rw-r--r-- | lib/api-config/Cargo.toml | 26 | ||||
| -rw-r--r-- | lib/api-config/src/error.rs | 13 | ||||
| -rw-r--r-- | lib/api-config/src/lib.rs | 3 | ||||
| -rw-r--r-- | lib/api-config/src/schema/create.rs | 15 | ||||
| -rw-r--r-- | lib/api-config/src/schema/mod.rs | 33 |
5 files changed, 90 insertions, 0 deletions
diff --git a/lib/api-config/Cargo.toml b/lib/api-config/Cargo.toml new file mode 100644 index 0000000..ec31262 --- /dev/null +++ b/lib/api-config/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "api-config" +version = "0.1.0" +edition = "2024" +license.workspace = true +readme.workspace = true +documentation.workspace = true +homepage.workspace = true +publish.workspace = true + +[dependencies] +serde.workspace = true +serde_json.workspace = true +thiserror.workspace = true +time = { workspace = true, features = ["serde"] } +tracing.workspace = true +utoipa = { workspace = true, optional = true } +warden-core.workspace = true + +[features] +default = [] +utoipa = ["dep:utoipa", "utoipa/time"] + +[dependencies.sqlx] +workspace = true +features = ["json", "runtime-tokio-rustls", "time"] diff --git a/lib/api-config/src/error.rs b/lib/api-config/src/error.rs new file mode 100644 index 0000000..6f7b099 --- /dev/null +++ b/lib/api-config/src/error.rs @@ -0,0 +1,13 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum ConfigurationError { + #[error("data store disconnected")] + Disconnect(#[from] sqlx::Error), + #[error("the data for key `{0}` is not available")] + Redaction(String), + #[error("invalid header (expected {expected:?}, found {found:?})")] + InvalidHeader { expected: String, found: String }, + #[error("unknown data store error")] + Unknown, +} diff --git a/lib/api-config/src/lib.rs b/lib/api-config/src/lib.rs new file mode 100644 index 0000000..84366c1 --- /dev/null +++ b/lib/api-config/src/lib.rs @@ -0,0 +1,3 @@ +mod error; +pub mod schema; +pub use error::ConfigurationError; diff --git a/lib/api-config/src/schema/create.rs b/lib/api-config/src/schema/create.rs new file mode 100644 index 0000000..5c91f64 --- /dev/null +++ b/lib/api-config/src/schema/create.rs @@ -0,0 +1,15 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] +/// Transaction to monitor +pub struct CreateSchema { + #[serde(rename = "type")] + /// Transaction schema type + pub kind: String, + /// The schema's version + pub version: String, + /// Transaction data + #[serde(rename = "json_schema")] + pub schema: serde_json::Value, +} diff --git a/lib/api-config/src/schema/mod.rs b/lib/api-config/src/schema/mod.rs new file mode 100644 index 0000000..654e6ad --- /dev/null +++ b/lib/api-config/src/schema/mod.rs @@ -0,0 +1,33 @@ +pub mod create; + +use serde::{Deserialize, Serialize}; +use time::OffsetDateTime; + +use crate::ConfigurationError; + +/// Transaction to monitor +#[derive(Deserialize, Serialize)] +#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] +pub struct TransactionSchema { + #[serde(rename = "type")] + /// Transaction schema type + pub kind: String, + /// The schema's version + pub version: String, + /// JSON schema for transcation + #[serde(rename = "json_schema")] + pub schema: serde_json::Value, + #[serde(with = "time::serde::rfc3339")] + pub created_at: OffsetDateTime, + #[serde(with = "time::serde::rfc3339")] + pub updated_at: OffsetDateTime, +} + +pub trait SchemaDriver { + fn create( + &self, + name: impl AsRef<str>, + version: impl AsRef<str>, + schema: serde_json::Value, + ) -> impl std::future::Future<Output = Result<TransactionSchema, ConfigurationError>> + Send + Sync; +} |
