surrealdb-server 3.3.1

A scalable, distributed, collaborative, document-graph database, for the realtime web
use std::net::SocketAddr;
use std::path::PathBuf;

use anyhow::Result;
use surrealdb_core::CommunityComposer;
use surrealdb_core::options::EngineOptions;

use crate::ntw::client_ip::ClientIp;

/// Trait for validating configuration before system initialization.
///
/// This trait is part of the composer pattern and allows composers to perform
/// validation checks on the configuration before the datastore and network
/// components are initialized. Implementations can verify that the configuration
/// is valid for the specific backend and features being used.
#[async_trait::async_trait]
pub trait ConfigCheck: Send + Sync + 'static {
	/// Validates the provided configuration.
	///
	/// # Parameters
	/// - `cfg`: The configuration to validate
	///
	/// # Returns
	/// - `Ok(())` if the configuration is valid
	/// - `Err` if the configuration is invalid or incompatible
	async fn check_config(&mut self, _cfg: &Config) -> Result<()>;
}

#[async_trait::async_trait]
impl ConfigCheck for CommunityComposer {
	async fn check_config(&mut self, _cfg: &Config) -> Result<()> {
		Ok(())
	}
}

#[derive(Clone, Debug)]
pub struct Config {
	pub bind: SocketAddr,
	pub postgres_bind: Option<SocketAddr>,
	pub path: String,
	pub client_ip: ClientIp,
	pub user: Option<String>,
	pub pass: Option<String>,
	pub crt: Option<PathBuf>,
	pub key: Option<PathBuf>,
	pub engine: EngineOptions,
	pub no_identification_headers: bool,
	pub allow_origin: Vec<String>,
	/// When set, client-attached HTTP RPC sessions are persisted in the
	/// datastore and expire after this idle TTL. `None` disables persistence.
	pub durable_session_ttl: Option<std::time::Duration>,
}