From ff3b9fbaf400c344cae67ef9bdc9ba7d5f27b976 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sun, 29 Mar 2026 16:36:13 +0200 Subject: refactor: move state to core --- lib/api-config/src/error.rs | 13 +++++++++++++ lib/api-config/src/lib.rs | 3 +++ lib/api-config/src/schema/create.rs | 15 +++++++++++++++ lib/api-config/src/schema/mod.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 lib/api-config/src/error.rs create mode 100644 lib/api-config/src/lib.rs create mode 100644 lib/api-config/src/schema/create.rs create mode 100644 lib/api-config/src/schema/mod.rs (limited to 'lib/api-config/src') 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, + version: impl AsRef, + schema: serde_json::Value, + ) -> impl std::future::Future> + Send + Sync; +} -- cgit v1.2.3