use crate::effect::{
BatchDeleteSpec, BatchUpdateSpec, GetSpec, GuardedBumpSpec, MonotonicUpsertSpec, Row, ScanSpec,
ScopedGetSpec, ScopedGuardedBumpSpec, ScopedMaxSpec, ScopedScanSpec, StorageOp, UpsertSpec,
};
use crate::error::PortError;
use crate::platform::{MaybeSend, MaybeSync};
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
pub trait Storage: MaybeSend + MaybeSync + 'static {
async fn batch_upsert(&self, spec: UpsertSpec) -> Result<(), PortError>;
async fn batch_update(&self, spec: BatchUpdateSpec) -> Result<(), PortError>;
async fn monotonic_upsert(&self, spec: MonotonicUpsertSpec) -> Result<(), PortError>;
async fn guarded_bump(&self, spec: GuardedBumpSpec) -> Result<(), PortError>;
async fn scoped_guarded_bump(&self, _spec: ScopedGuardedBumpSpec) -> Result<(), PortError> {
Err(PortError::Storage(
"scoped guarded bump is not implemented by this driver".to_string(),
))
}
async fn get(&self, spec: GetSpec) -> Result<Option<Row>, PortError>;
async fn scoped_get(&self, _spec: ScopedGetSpec) -> Result<Option<Row>, PortError> {
Err(PortError::Storage(
"scoped get is not implemented by this driver".to_string(),
))
}
async fn scoped_max(&self, _spec: ScopedMaxSpec) -> Result<Option<Row>, PortError> {
Err(PortError::Storage(
"scoped max is not implemented by this driver".to_string(),
))
}
async fn scoped_scan(&self, _spec: ScopedScanSpec) -> Result<Vec<Row>, PortError> {
Err(PortError::Storage(
"scoped scan is not implemented by this driver".to_string(),
))
}
async fn scan(&self, spec: ScanSpec) -> Result<Vec<Row>, PortError>;
async fn batch_delete(&self, spec: BatchDeleteSpec) -> Result<(), PortError>;
async fn atomic_write(&self, _ops: Vec<StorageOp>) -> Result<(), PortError> {
Err(PortError::Storage(
"atomic storage write is not implemented by this driver".to_string(),
))
}
}