#[derive(Debug, thiserror::Error)]
pub enum OutboxError {
#[error("db: {0}")]
Db(#[from] sqlx::Error),
#[error("invalid schema identifier: {0:?}")]
InvalidSchema(String),
#[error("publish failed: {0}")]
Publish(String),
#[error("publish exhausted: {0}")]
Exhausted(String),
}
pub type Result<T> = std::result::Result<T, OutboxError>;
pub(crate) fn validate_schema(schema: &str) -> Result<()> {
let ok = !schema.is_empty()
&& schema.len() <= 63
&& schema.bytes().next().map(|b| b == b'_' || b.is_ascii_lowercase()).unwrap_or(false)
&& schema.bytes().all(|b| b == b'_' || b.is_ascii_lowercase() || b.is_ascii_digit());
if ok {
Ok(())
} else {
Err(OutboxError::InvalidSchema(schema.to_string()))
}
}