use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::{NodeKind, Revision, VirtualPath};
pub const DEFAULT_PAGE_LIMIT: u32 = 100;
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ByteRange {
pub start: u64,
pub end: u64,
}
impl ByteRange {
pub const fn new(start: u64, end: u64) -> Self {
Self { start, end }
}
pub const fn len(self) -> u64 {
self.end.saturating_sub(self.start)
}
pub const fn is_empty(self) -> bool {
self.start >= self.end
}
}
#[non_exhaustive]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct PageRequest {
pub cursor: Option<String>,
pub limit: u32,
}
impl PageRequest {
#[must_use]
pub fn cursor(mut self, cursor: Option<String>) -> Self {
self.cursor = cursor;
self
}
#[must_use]
pub const fn limit(mut self, limit: u32) -> Self {
self.limit = limit;
self
}
}
impl Default for PageRequest {
fn default() -> Self {
Self {
cursor: None,
limit: DEFAULT_PAGE_LIMIT,
}
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct StatOptions {
pub follow_symlinks: bool,
}
impl StatOptions {
#[must_use]
pub const fn follow_symlinks(mut self, follow_symlinks: bool) -> Self {
self.follow_symlinks = follow_symlinks;
self
}
}
impl Default for StatOptions {
fn default() -> Self {
Self {
follow_symlinks: true,
}
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct TreeOptions {
pub max_depth: Option<u32>,
pub follow_symlinks: bool,
}
impl TreeOptions {
#[must_use]
pub const fn max_depth(mut self, max_depth: Option<u32>) -> Self {
self.max_depth = max_depth;
self
}
#[must_use]
pub const fn follow_symlinks(mut self, follow_symlinks: bool) -> Self {
self.follow_symlinks = follow_symlinks;
self
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct CreateOptions {
pub parents: bool,
pub exist_ok: bool,
pub expected_revision: Option<Revision>,
}
impl CreateOptions {
#[must_use]
pub const fn parents(mut self, parents: bool) -> Self {
self.parents = parents;
self
}
#[must_use]
pub const fn exist_ok(mut self, exist_ok: bool) -> Self {
self.exist_ok = exist_ok;
self
}
#[must_use]
pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
self.expected_revision = expected_revision;
self
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ReadOptions {
pub range: Option<ByteRange>,
pub follow_symlinks: bool,
}
impl ReadOptions {
#[must_use]
pub const fn range(mut self, range: Option<ByteRange>) -> Self {
self.range = range;
self
}
#[must_use]
pub const fn follow_symlinks(mut self, follow_symlinks: bool) -> Self {
self.follow_symlinks = follow_symlinks;
self
}
}
impl Default for ReadOptions {
fn default() -> Self {
Self {
range: None,
follow_symlinks: true,
}
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct WriteOptions {
pub create: bool,
pub expected_revision: Option<Revision>,
}
impl WriteOptions {
#[must_use]
pub const fn create(mut self, create: bool) -> Self {
self.create = create;
self
}
#[must_use]
pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
self.expected_revision = expected_revision;
self
}
pub const fn replace() -> Self {
Self {
create: false,
expected_revision: None,
}
}
}
impl Default for WriteOptions {
fn default() -> Self {
Self {
create: true,
expected_revision: None,
}
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct MutationOptions {
pub expected_revision: Option<Revision>,
}
impl MutationOptions {
#[must_use]
pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
self.expected_revision = expected_revision;
self
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct TouchOptions {
pub create: bool,
pub expected_revision: Option<Revision>,
}
impl TouchOptions {
#[must_use]
pub const fn create(mut self, create: bool) -> Self {
self.create = create;
self
}
#[must_use]
pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
self.expected_revision = expected_revision;
self
}
}
impl Default for TouchOptions {
fn default() -> Self {
Self {
create: true,
expected_revision: None,
}
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct CopyOptions {
pub recursive: bool,
pub overwrite: bool,
pub expected_revision: Option<Revision>,
}
impl CopyOptions {
#[must_use]
pub const fn recursive(mut self, recursive: bool) -> Self {
self.recursive = recursive;
self
}
#[must_use]
pub const fn overwrite(mut self, overwrite: bool) -> Self {
self.overwrite = overwrite;
self
}
#[must_use]
pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
self.expected_revision = expected_revision;
self
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct MoveOptions {
pub overwrite: bool,
pub expected_revision: Option<Revision>,
}
impl MoveOptions {
#[must_use]
pub const fn overwrite(mut self, overwrite: bool) -> Self {
self.overwrite = overwrite;
self
}
#[must_use]
pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
self.expected_revision = expected_revision;
self
}
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct RemoveOptions {
pub recursive: bool,
pub expected_revision: Option<Revision>,
}
impl RemoveOptions {
#[must_use]
pub const fn recursive(mut self, recursive: bool) -> Self {
self.recursive = recursive;
self
}
#[must_use]
pub const fn expected_revision(mut self, expected_revision: Option<Revision>) -> Self {
self.expected_revision = expected_revision;
self
}
}
#[non_exhaustive]
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct FindQuery {
pub root: VirtualPath,
pub name_contains: Option<String>,
pub kind: Option<NodeKind>,
pub min_logical_size: Option<u64>,
pub max_logical_size: Option<u64>,
pub modified_after_ms: Option<i64>,
pub modified_before_ms: Option<i64>,
pub attributes: BTreeMap<String, Value>,
}
impl FindQuery {
#[must_use]
pub fn root(mut self, root: VirtualPath) -> Self {
self.root = root;
self
}
#[must_use]
pub fn name_contains(mut self, name_contains: Option<String>) -> Self {
self.name_contains = name_contains;
self
}
#[must_use]
pub const fn kind(mut self, kind: Option<NodeKind>) -> Self {
self.kind = kind;
self
}
#[must_use]
pub const fn min_logical_size(mut self, min_logical_size: Option<u64>) -> Self {
self.min_logical_size = min_logical_size;
self
}
#[must_use]
pub const fn max_logical_size(mut self, max_logical_size: Option<u64>) -> Self {
self.max_logical_size = max_logical_size;
self
}
#[must_use]
pub const fn modified_after_ms(mut self, modified_after_ms: Option<i64>) -> Self {
self.modified_after_ms = modified_after_ms;
self
}
#[must_use]
pub const fn modified_before_ms(mut self, modified_before_ms: Option<i64>) -> Self {
self.modified_before_ms = modified_before_ms;
self
}
#[must_use]
pub fn attributes(mut self, attributes: BTreeMap<String, Value>) -> Self {
self.attributes = attributes;
self
}
}
impl Default for FindQuery {
fn default() -> Self {
Self {
root: VirtualPath::root(),
name_contains: None,
kind: None,
min_logical_size: None,
max_logical_size: None,
modified_after_ms: None,
modified_before_ms: None,
attributes: BTreeMap::new(),
}
}
}
#[non_exhaustive]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ContentQuery {
pub root: VirtualPath,
pub needle: Vec<u8>,
}
impl ContentQuery {
#[must_use]
pub fn root(mut self, root: VirtualPath) -> Self {
self.root = root;
self
}
#[must_use]
pub fn needle(mut self, needle: Vec<u8>) -> Self {
self.needle = needle;
self
}
}
impl Default for ContentQuery {
fn default() -> Self {
Self {
root: VirtualPath::root(),
needle: Vec::new(),
}
}
}