use super::output_request::*;
use super::processor::*;
use crate::non::NONGetObjectOutputResponse;
use cyfs_base::*;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct DecRootInfo {
pub root: ObjectId,
pub revision: u64,
pub dec_root: ObjectId,
}
#[derive(Clone)]
pub struct GlobalStateStub {
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
processor: GlobalStateOutputProcessorRef,
}
pub struct CreateObjectMapOption {
owner: Option<ObjectId>,
dec_id: Option<ObjectId>,
}
impl CreateObjectMapOption {
pub fn new(owner: Option<ObjectId>, dec_id: Option<ObjectId>) -> Self {
Self { owner, dec_id }
}
pub fn new_with_owner(owner: ObjectId) -> Self {
Self {
owner: Some(owner),
dec_id: None,
}
}
pub fn new_with_dec(dec_id: ObjectId) -> Self {
Self {
owner: None,
dec_id: Some(dec_id),
}
}
pub fn new_with_none() -> Self {
Self {
owner: None,
dec_id: None,
}
}
pub fn fill_request(&self, req: &mut OpEnvCreateNewOutputRequest) {
req.owner = self.owner.as_ref().map(|id| ObjectMapField::from(id));
req.dec = self.dec_id.as_ref().map(|id| ObjectMapField::from(id));
}
}
impl GlobalStateStub {
pub fn new(
processor: GlobalStateOutputProcessorRef,
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
) -> Self {
Self {
processor,
target,
target_dec_id,
}
}
pub async fn get_current_root(&self) -> BuckyResult<(ObjectId, u64)> {
let mut req = RootStateGetCurrentRootOutputRequest::new_global();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_current_root(req).await?;
Ok((resp.root, resp.revision))
}
pub async fn get_dec_root(&self) -> BuckyResult<DecRootInfo> {
let mut req = RootStateGetCurrentRootOutputRequest::new_dec();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_current_root(req).await?;
let info = DecRootInfo {
root: resp.root,
revision: resp.revision,
dec_root: resp.dec_root.unwrap(),
};
Ok(info)
}
pub async fn create_path_op_env(&self) -> BuckyResult<PathOpEnvStub> {
self.create_path_op_env_with_access(None).await
}
pub async fn create_path_op_env_with_access(
&self,
access: Option<RootStateOpEnvAccess>,
) -> BuckyResult<PathOpEnvStub> {
let mut req = RootStateCreateOpEnvOutputRequest::new(ObjectMapOpEnvType::Path);
req.access = access;
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.create_op_env(req).await?;
let op_env = PathOpEnvStub::new(resp, self.target.clone(), self.target_dec_id.clone());
Ok(op_env)
}
pub async fn create_single_op_env(&self) -> BuckyResult<SingleOpEnvStub> {
self.create_single_op_env_with_access(None).await
}
pub async fn create_single_op_env_with_access(
&self,
access: Option<RootStateOpEnvAccess>,
) -> BuckyResult<SingleOpEnvStub> {
let mut req = RootStateCreateOpEnvOutputRequest::new(ObjectMapOpEnvType::Single);
req.access = access;
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.create_op_env(req).await?;
let op_env = SingleOpEnvStub::new(resp, self.target.clone(), self.target_dec_id.clone());
Ok(op_env)
}
pub async fn create_isolate_path_op_env(&self) -> BuckyResult<IsolatePathOpEnvStub> {
self.create_isolate_path_op_env_with_access(None).await
}
pub async fn create_isolate_path_op_env_with_access(
&self,
access: Option<RootStateOpEnvAccess>,
) -> BuckyResult<IsolatePathOpEnvStub> {
let mut req = RootStateCreateOpEnvOutputRequest::new(ObjectMapOpEnvType::IsolatePath);
req.access = access;
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.create_op_env(req).await?;
let op_env =
IsolatePathOpEnvStub::new(resp, self.target.clone(), self.target_dec_id.clone());
Ok(op_env)
}
}
#[derive(Clone)]
pub struct SingleOpEnvStub {
processor: OpEnvOutputProcessorRef,
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
}
impl SingleOpEnvStub {
pub(crate) fn new(
processor: OpEnvOutputProcessorRef,
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
) -> Self {
Self {
processor,
target,
target_dec_id,
}
}
pub async fn create_new(&self, content_type: ObjectMapSimpleContentType) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new(content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.create_new(req).await
}
pub async fn create_new_with_option(
&self,
content_type: ObjectMapSimpleContentType,
options: &CreateObjectMapOption,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new(content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
options.fill_request(&mut req);
self.processor.create_new(req).await
}
pub async fn load(&self, target: ObjectId) -> BuckyResult<()> {
let mut req = OpEnvLoadOutputRequest::new(target);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.load(req).await
}
pub async fn load_with_inner_path(
&self,
target: ObjectId,
inner_path: impl Into<String>,
) -> BuckyResult<()> {
let mut req = OpEnvLoadOutputRequest::new_with_inner_path(target, inner_path);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.load(req).await
}
pub async fn load_by_path(&self, path: impl Into<String>) -> BuckyResult<()> {
let mut req = OpEnvLoadByPathOutputRequest::new(path.into());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.load_by_path(req).await
}
pub async fn get_current_root(&self) -> BuckyResult<ObjectId> {
let mut req = OpEnvGetCurrentRootOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_current_root(req).await?;
Ok(resp.dec_root)
}
pub async fn get_by_key(&self, key: impl Into<String>) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvGetByKeyOutputRequest::new_key(key);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_by_key(req).await?;
Ok(resp.value)
}
pub async fn insert_with_key(
&self,
key: impl Into<String>,
value: &ObjectId,
) -> BuckyResult<()> {
let mut req = OpEnvInsertWithKeyOutputRequest::new_key_value(key, value.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.insert_with_key(req).await?;
Ok(())
}
pub async fn set_with_key(
&self,
key: impl Into<String>,
value: &ObjectId,
prev_value: Option<ObjectId>,
auto_insert: bool,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvSetWithKeyOutputRequest::new_key_value(
key,
value.to_owned(),
prev_value,
auto_insert,
);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.set_with_key(req).await?;
Ok(resp.prev_value)
}
pub async fn remove_with_key(
&self,
key: impl Into<String>,
prev_value: Option<ObjectId>,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvRemoveWithKeyOutputRequest::new_key(key, prev_value);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.remove_with_key(req).await?;
Ok(resp.value)
}
pub async fn contains(&self, object_id: &ObjectId) -> BuckyResult<bool> {
let mut req = OpEnvContainsOutputRequest::new(object_id.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.contains(req).await?;
Ok(resp.result)
}
pub async fn insert(&self, object_id: &ObjectId) -> BuckyResult<bool> {
let mut req = OpEnvInsertOutputRequest::new(object_id.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.insert(req).await?;
Ok(resp.result)
}
pub async fn remove(&self, object_id: &ObjectId) -> BuckyResult<bool> {
let mut req = OpEnvRemoveOutputRequest::new(object_id.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.remove(req).await?;
Ok(resp.result)
}
pub async fn update(&self) -> BuckyResult<ObjectId> {
let mut req = OpEnvCommitOutputRequest::new_update();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.commit(req).await?;
Ok(resp.dec_root)
}
pub async fn commit(self) -> BuckyResult<ObjectId> {
let mut req = OpEnvCommitOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.commit(req).await?;
Ok(resp.dec_root)
}
pub async fn abort(self) -> BuckyResult<()> {
let mut req = OpEnvAbortOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.abort(req).await?;
Ok(())
}
pub async fn next(&self, step: u32) -> BuckyResult<Vec<ObjectMapContentItem>> {
let mut req = OpEnvNextOutputRequest::new(step);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.next(req).await?;
Ok(resp.list)
}
pub async fn reset(&self) -> BuckyResult<()> {
let mut req = OpEnvResetOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.reset(req).await
}
pub async fn list(&self) -> BuckyResult<Vec<ObjectMapContentItem>> {
let mut req = OpEnvListOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.list(req).await?;
Ok(resp.list)
}
pub async fn metadata(&self) -> BuckyResult<ObjectMapMetaData> {
let mut req = OpEnvMetadataOutputRequest::new(None);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.metadata(req).await?;
let metadata = ObjectMapMetaData {
content_mode: resp.content_mode,
content_type: resp.content_type,
count: resp.count,
size: resp.size,
depth: resp.depth,
};
Ok(metadata)
}
}
#[derive(Clone)]
pub struct PathOpEnvStub {
processor: OpEnvOutputProcessorRef,
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
}
impl PathOpEnvStub {
pub fn new(
processor: OpEnvOutputProcessorRef,
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
) -> Self {
Self {
processor,
target,
target_dec_id,
}
}
pub async fn get_current_root(&self) -> BuckyResult<DecRootInfo> {
let mut req = OpEnvGetCurrentRootOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_current_root(req).await?;
let info = DecRootInfo {
root: resp.root,
revision: resp.revision,
dec_root: resp.dec_root,
};
Ok(info)
}
pub async fn lock(&self, path_list: Vec<String>, duration_in_millsecs: u64) -> BuckyResult<()> {
let mut req = OpEnvLockOutputRequest::new(path_list, duration_in_millsecs);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.lock(req).await
}
pub async fn try_lock(
&self,
path_list: Vec<String>,
duration_in_millsecs: u64,
) -> BuckyResult<()> {
let mut req = OpEnvLockOutputRequest::new_try(path_list, duration_in_millsecs);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.lock(req).await
}
pub async fn get_by_key(
&self,
path: impl Into<String>,
key: impl Into<String>,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvGetByKeyOutputRequest::new_path_and_key(path, key);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_by_key(req).await?;
Ok(resp.value)
}
pub async fn create_new(
&self,
path: impl Into<String>,
key: impl Into<String>,
content_type: ObjectMapSimpleContentType,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new_with_path_and_key(path, key, content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.create_new(req).await?;
Ok(())
}
pub async fn create_new_with_option(
&self,
path: impl Into<String>,
key: impl Into<String>,
content_type: ObjectMapSimpleContentType,
options: &CreateObjectMapOption,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new_with_path_and_key(path, key, content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
options.fill_request(&mut req);
self.processor.create_new(req).await?;
Ok(())
}
pub async fn insert_with_key(
&self,
path: impl Into<String>,
key: impl Into<String>,
value: &ObjectId,
) -> BuckyResult<()> {
let mut req =
OpEnvInsertWithKeyOutputRequest::new_path_and_key_value(path, key, value.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.insert_with_key(req).await?;
Ok(())
}
pub async fn set_with_key(
&self,
path: impl Into<String>,
key: impl Into<String>,
value: &ObjectId,
prev_value: Option<ObjectId>,
auto_insert: bool,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvSetWithKeyOutputRequest::new_path_and_key_value(
path,
key,
value.to_owned(),
prev_value,
auto_insert,
);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.set_with_key(req).await?;
Ok(resp.prev_value)
}
pub async fn remove_with_key(
&self,
path: impl Into<String>,
key: impl Into<String>,
prev_value: Option<ObjectId>,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvRemoveWithKeyOutputRequest::new_path_and_key(path, key, prev_value);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.remove_with_key(req).await?;
Ok(resp.value)
}
pub async fn get_by_path(&self, full_path: impl Into<String>) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvGetByKeyOutputRequest::new_full_path(full_path);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_by_key(req).await?;
Ok(resp.value)
}
pub async fn create_new_with_path(
&self,
full_path: impl Into<String>,
content_type: ObjectMapSimpleContentType,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new_with_full_path(full_path, content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.create_new(req).await?;
Ok(())
}
pub async fn create_new_with_path_and_option(
&self,
full_path: impl Into<String>,
content_type: ObjectMapSimpleContentType,
options: &CreateObjectMapOption,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new_with_full_path(full_path, content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
options.fill_request(&mut req);
self.processor.create_new(req).await?;
Ok(())
}
pub async fn insert_with_path(
&self,
full_path: impl Into<String>,
value: &ObjectId,
) -> BuckyResult<()> {
let mut req =
OpEnvInsertWithKeyOutputRequest::new_full_path_and_value(full_path, value.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.insert_with_key(req).await?;
Ok(())
}
pub async fn set_with_path(
&self,
full_path: impl Into<String>,
value: &ObjectId,
prev_value: Option<ObjectId>,
auto_insert: bool,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvSetWithKeyOutputRequest::new_full_path_and_value(
full_path,
value.to_owned(),
prev_value,
auto_insert,
);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.set_with_key(req).await?;
Ok(resp.prev_value)
}
pub async fn remove_with_path(
&self,
full_path: impl Into<String>,
prev_value: Option<ObjectId>,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvRemoveWithKeyOutputRequest::new_full_path(full_path, prev_value);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.remove_with_key(req).await?;
Ok(resp.value)
}
pub async fn contains(
&self,
path: impl Into<String>,
object_id: &ObjectId,
) -> BuckyResult<bool> {
let mut req = OpEnvContainsOutputRequest::new_path(path, object_id.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.contains(req).await?;
Ok(resp.result)
}
pub async fn insert(&self, path: impl Into<String>, object_id: &ObjectId) -> BuckyResult<bool> {
let mut req = OpEnvInsertOutputRequest::new_path(path, object_id.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.insert(req).await?;
Ok(resp.result)
}
pub async fn remove(&self, path: impl Into<String>, object_id: &ObjectId) -> BuckyResult<bool> {
let mut req = OpEnvRemoveOutputRequest::new_path(path, object_id.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.remove(req).await?;
Ok(resp.result)
}
pub async fn update(&self) -> BuckyResult<DecRootInfo> {
let mut req = OpEnvCommitOutputRequest::new_update();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.commit(req).await?;
let info = DecRootInfo {
root: resp.root,
revision: resp.revision,
dec_root: resp.dec_root,
};
Ok(info)
}
pub async fn commit(self) -> BuckyResult<DecRootInfo> {
let mut req = OpEnvCommitOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.commit(req).await?;
let info = DecRootInfo {
root: resp.root,
revision: resp.revision,
dec_root: resp.dec_root,
};
Ok(info)
}
pub async fn abort(self) -> BuckyResult<()> {
let mut req = OpEnvAbortOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.abort(req).await?;
Ok(())
}
pub async fn list(&self, path: impl Into<String>) -> BuckyResult<Vec<ObjectMapContentItem>> {
let mut req = OpEnvListOutputRequest::new_path(path);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.list(req).await?;
Ok(resp.list)
}
pub async fn metadata(&self, path: impl Into<String>) -> BuckyResult<ObjectMapMetaData> {
let mut req = OpEnvMetadataOutputRequest::new(Some(path.into()));
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.metadata(req).await?;
let metadata = ObjectMapMetaData {
content_mode: resp.content_mode,
content_type: resp.content_type,
count: resp.count,
size: resp.size,
depth: resp.depth,
};
Ok(metadata)
}
}
#[derive(Clone)]
pub struct IsolatePathOpEnvStub {
processor: OpEnvOutputProcessorRef,
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
}
impl IsolatePathOpEnvStub {
pub(crate) fn new(
processor: OpEnvOutputProcessorRef,
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
) -> Self {
Self {
processor,
target,
target_dec_id,
}
}
pub async fn create_new(&self, content_type: ObjectMapSimpleContentType) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new(content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.create_new(req).await
}
pub async fn create_new_with_option(
&self,
content_type: ObjectMapSimpleContentType,
options: &CreateObjectMapOption,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new(content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
options.fill_request(&mut req);
self.processor.create_new(req).await
}
pub async fn load(&self, target: ObjectId) -> BuckyResult<()> {
let mut req = OpEnvLoadOutputRequest::new(target);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.load(req).await
}
pub async fn load_with_inner_path(
&self,
target: ObjectId,
inner_path: impl Into<String>,
) -> BuckyResult<()> {
let mut req = OpEnvLoadOutputRequest::new_with_inner_path(target, inner_path);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.load(req).await
}
pub async fn load_by_path(&self, path: impl Into<String>) -> BuckyResult<()> {
let mut req = OpEnvLoadByPathOutputRequest::new(path.into());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.load_by_path(req).await
}
pub async fn get_current_root(&self) -> BuckyResult<DecRootInfo> {
let mut req = OpEnvGetCurrentRootOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_current_root(req).await?;
let info = DecRootInfo {
root: resp.root,
revision: resp.revision,
dec_root: resp.dec_root,
};
Ok(info)
}
pub async fn get_by_key(
&self,
path: impl Into<String>,
key: impl Into<String>,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvGetByKeyOutputRequest::new_path_and_key(path, key);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_by_key(req).await?;
Ok(resp.value)
}
pub async fn create_new_with_key(
&self,
path: impl Into<String>,
key: impl Into<String>,
content_type: ObjectMapSimpleContentType,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new_with_path_and_key(path, key, content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.create_new(req).await?;
Ok(())
}
pub async fn create_new_with_key_and_option(
&self,
path: impl Into<String>,
key: impl Into<String>,
content_type: ObjectMapSimpleContentType,
options: &CreateObjectMapOption,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new_with_path_and_key(path, key, content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
options.fill_request(&mut req);
self.processor.create_new(req).await?;
Ok(())
}
pub async fn insert_with_key(
&self,
path: impl Into<String>,
key: impl Into<String>,
value: &ObjectId,
) -> BuckyResult<()> {
let mut req =
OpEnvInsertWithKeyOutputRequest::new_path_and_key_value(path, key, value.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.insert_with_key(req).await?;
Ok(())
}
pub async fn set_with_key(
&self,
path: impl Into<String>,
key: impl Into<String>,
value: &ObjectId,
prev_value: Option<ObjectId>,
auto_insert: bool,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvSetWithKeyOutputRequest::new_path_and_key_value(
path,
key,
value.to_owned(),
prev_value,
auto_insert,
);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.set_with_key(req).await?;
Ok(resp.prev_value)
}
pub async fn remove_with_key(
&self,
path: impl Into<String>,
key: impl Into<String>,
prev_value: Option<ObjectId>,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvRemoveWithKeyOutputRequest::new_path_and_key(path, key, prev_value);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.remove_with_key(req).await?;
Ok(resp.value)
}
pub async fn get_by_path(&self, full_path: impl Into<String>) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvGetByKeyOutputRequest::new_full_path(full_path);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_by_key(req).await?;
Ok(resp.value)
}
pub async fn create_new_with_path(
&self,
full_path: impl Into<String>,
content_type: ObjectMapSimpleContentType,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new_with_full_path(full_path, content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.create_new(req).await?;
Ok(())
}
pub async fn create_new_with_path_and_option(
&self,
full_path: impl Into<String>,
content_type: ObjectMapSimpleContentType,
options: &CreateObjectMapOption,
) -> BuckyResult<()> {
let mut req = OpEnvCreateNewOutputRequest::new_with_full_path(full_path, content_type);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
options.fill_request(&mut req);
self.processor.create_new(req).await?;
Ok(())
}
pub async fn insert_with_path(
&self,
full_path: impl Into<String>,
value: &ObjectId,
) -> BuckyResult<()> {
let mut req =
OpEnvInsertWithKeyOutputRequest::new_full_path_and_value(full_path, value.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.insert_with_key(req).await?;
Ok(())
}
pub async fn set_with_path(
&self,
full_path: impl Into<String>,
value: &ObjectId,
prev_value: Option<ObjectId>,
auto_insert: bool,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvSetWithKeyOutputRequest::new_full_path_and_value(
full_path,
value.to_owned(),
prev_value,
auto_insert,
);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.set_with_key(req).await?;
Ok(resp.prev_value)
}
pub async fn remove_with_path(
&self,
full_path: impl Into<String>,
prev_value: Option<ObjectId>,
) -> BuckyResult<Option<ObjectId>> {
let mut req = OpEnvRemoveWithKeyOutputRequest::new_full_path(full_path, prev_value);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.remove_with_key(req).await?;
Ok(resp.value)
}
pub async fn contains(
&self,
path: impl Into<String>,
object_id: &ObjectId,
) -> BuckyResult<bool> {
let mut req = OpEnvContainsOutputRequest::new_path(path, object_id.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.contains(req).await?;
Ok(resp.result)
}
pub async fn insert(&self, path: impl Into<String>, object_id: &ObjectId) -> BuckyResult<bool> {
let mut req = OpEnvInsertOutputRequest::new_path(path, object_id.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.insert(req).await?;
Ok(resp.result)
}
pub async fn remove(&self, path: impl Into<String>, object_id: &ObjectId) -> BuckyResult<bool> {
let mut req = OpEnvRemoveOutputRequest::new_path(path, object_id.to_owned());
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.remove(req).await?;
Ok(resp.result)
}
pub async fn update(&self) -> BuckyResult<DecRootInfo> {
let mut req = OpEnvCommitOutputRequest::new_update();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.commit(req).await?;
let info = DecRootInfo {
root: resp.root,
revision: resp.revision,
dec_root: resp.dec_root,
};
Ok(info)
}
pub async fn commit(self) -> BuckyResult<DecRootInfo> {
let mut req = OpEnvCommitOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.commit(req).await?;
let info = DecRootInfo {
root: resp.root,
revision: resp.revision,
dec_root: resp.dec_root,
};
Ok(info)
}
pub async fn abort(self) -> BuckyResult<()> {
let mut req = OpEnvAbortOutputRequest::new();
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
self.processor.abort(req).await?;
Ok(())
}
pub async fn list(&self, path: impl Into<String>) -> BuckyResult<Vec<ObjectMapContentItem>> {
let mut req = OpEnvListOutputRequest::new_path(path);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.list(req).await?;
Ok(resp.list)
}
pub async fn metadata(&self, path: impl Into<String>) -> BuckyResult<ObjectMapMetaData> {
let mut req = OpEnvMetadataOutputRequest::new(Some(path.into()));
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.metadata(req).await?;
let metadata = ObjectMapMetaData {
content_mode: resp.content_mode,
content_type: resp.content_type,
count: resp.count,
size: resp.size,
depth: resp.depth,
};
Ok(metadata)
}
}
#[derive(Clone)]
pub struct GlobalStateAccessorStub {
processor: GlobalStateAccessorOutputProcessorRef,
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
}
impl GlobalStateAccessorStub {
pub(crate) fn new(
processor: GlobalStateAccessorOutputProcessorRef,
target: Option<ObjectId>,
target_dec_id: Option<ObjectId>,
) -> Self {
Self {
processor,
target,
target_dec_id,
}
}
pub async fn get_object_by_path(
&self,
path: impl Into<String>,
) -> BuckyResult<NONGetObjectOutputResponse> {
let mut req = RootStateAccessorGetObjectByPathOutputRequest::new(path);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.get_object_by_path(req).await?;
Ok(resp.object)
}
pub async fn list(&self, path: impl Into<String>) -> BuckyResult<Vec<ObjectMapContentItem>> {
let mut req = RootStateAccessorListOutputRequest::new(path);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.list(req).await?;
Ok(resp.list)
}
pub async fn list_by_page(
&self,
path: impl Into<String>,
page_index: u32,
page_size: u32,
) -> BuckyResult<Vec<ObjectMapContentItem>> {
let mut req =
RootStateAccessorListOutputRequest::new_with_page(path, page_index, page_size);
req.common.target = self.target.clone();
req.common.target_dec_id = self.target_dec_id.clone();
let resp = self.processor.list(req).await?;
Ok(resp.list)
}
}