use super::OfflineSyncError;
pub const MAX_OFFLINE_RECORDS: usize = 50_000;
pub const MAX_OFFLINE_PENDING_MUTATIONS: usize = 2_000;
pub const MAX_OFFLINE_CONFLICTS: usize = 2_000;
pub const MAX_OFFLINE_PAYLOAD_BYTES: usize = 512 * 1024;
pub const MAX_OFFLINE_SNAPSHOT_BYTES: usize = 32 * 1024 * 1024;
pub const MAX_OFFLINE_PUSH_BATCH: usize = 100;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct OfflineSyncPolicy {
max_records: usize,
max_pending_mutations: usize,
max_conflicts: usize,
max_payload_bytes: usize,
max_snapshot_bytes: usize,
max_push_batch: usize,
}
impl OfflineSyncPolicy {
pub const fn new(
max_records: usize,
max_pending_mutations: usize,
max_conflicts: usize,
max_payload_bytes: usize,
max_snapshot_bytes: usize,
max_push_batch: usize,
) -> Result<Self, OfflineSyncError> {
if max_records == 0
|| max_records > MAX_OFFLINE_RECORDS
|| max_pending_mutations == 0
|| max_pending_mutations > MAX_OFFLINE_PENDING_MUTATIONS
|| max_conflicts == 0
|| max_conflicts > MAX_OFFLINE_CONFLICTS
|| max_payload_bytes == 0
|| max_payload_bytes > MAX_OFFLINE_PAYLOAD_BYTES
|| max_snapshot_bytes == 0
|| max_snapshot_bytes > MAX_OFFLINE_SNAPSHOT_BYTES
|| max_push_batch == 0
|| max_push_batch > MAX_OFFLINE_PUSH_BATCH
{
return Err(OfflineSyncError::InvalidPolicy);
}
Ok(Self {
max_records,
max_pending_mutations,
max_conflicts,
max_payload_bytes,
max_snapshot_bytes,
max_push_batch,
})
}
pub const fn max_records(self) -> usize {
self.max_records
}
pub const fn max_pending_mutations(self) -> usize {
self.max_pending_mutations
}
pub const fn max_conflicts(self) -> usize {
self.max_conflicts
}
pub const fn max_payload_bytes(self) -> usize {
self.max_payload_bytes
}
pub const fn max_snapshot_bytes(self) -> usize {
self.max_snapshot_bytes
}
pub const fn max_push_batch(self) -> usize {
self.max_push_batch
}
}
impl Default for OfflineSyncPolicy {
fn default() -> Self {
Self {
max_records: 10_000,
max_pending_mutations: 500,
max_conflicts: 500,
max_payload_bytes: 128 * 1024,
max_snapshot_bytes: 8 * 1024 * 1024,
max_push_batch: 50,
}
}
}