Moved MsgAction into action module.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
This commit is contained in:
parent
ca68759c79
commit
3d19493763
@ -1,21 +1,8 @@
|
|||||||
|
mod message;
|
||||||
mod query;
|
mod query;
|
||||||
|
mod user;
|
||||||
|
|
||||||
pub use crate::document::{definition::DocDef, field::FieldType};
|
pub use crate::document::{definition::DocDef, field::FieldType};
|
||||||
|
pub use message::MsgAction;
|
||||||
pub use query::Query;
|
pub use query::Query;
|
||||||
|
pub use user::UserAction;
|
||||||
pub enum UserAction {
|
|
||||||
CreateDocument(DocDef),
|
|
||||||
Query(Query),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<DocDef> for UserAction {
|
|
||||||
fn from(value: DocDef) -> Self {
|
|
||||||
Self::CreateDocument(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Query> for UserAction {
|
|
||||||
fn from(value: Query) -> Self {
|
|
||||||
Self::Query(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
148
src/action/message.rs
Normal file
148
src/action/message.rs
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
use super::{DocDef, Query, UserAction};
|
||||||
|
use crate::{
|
||||||
|
message::wrapper::{Addition, Delete, Records, Reply, Update},
|
||||||
|
mtterror::MTTError,
|
||||||
|
queue::data_director::Register,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum MsgAction {
|
||||||
|
Addition(Addition),
|
||||||
|
Create(DocDef),
|
||||||
|
Error(MTTError),
|
||||||
|
OnAddition(Records),
|
||||||
|
OnDelete(Records),
|
||||||
|
OnQuery(Records),
|
||||||
|
OnUpdate(Records),
|
||||||
|
Query(Query),
|
||||||
|
Records(Records),
|
||||||
|
Register(Register),
|
||||||
|
Reply(Reply),
|
||||||
|
Show,
|
||||||
|
Delete(Delete),
|
||||||
|
Update(Update),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Addition> for MsgAction {
|
||||||
|
fn from(value: Addition) -> Self {
|
||||||
|
MsgAction::Addition(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Delete> for MsgAction {
|
||||||
|
fn from(value: Delete) -> Self {
|
||||||
|
MsgAction::Delete(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<DocDef> for MsgAction {
|
||||||
|
fn from(value: DocDef) -> Self {
|
||||||
|
MsgAction::Create(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MTTError> for MsgAction {
|
||||||
|
fn from(value: MTTError) -> Self {
|
||||||
|
MsgAction::Error(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Query> for MsgAction {
|
||||||
|
fn from(value: Query) -> Self {
|
||||||
|
MsgAction::Query(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Records> for MsgAction {
|
||||||
|
fn from(value: Records) -> Self {
|
||||||
|
MsgAction::Records(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Register> for MsgAction {
|
||||||
|
fn from(value: Register) -> Self {
|
||||||
|
MsgAction::Register(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Reply> for MsgAction {
|
||||||
|
fn from(value: Reply) -> Self {
|
||||||
|
MsgAction::Reply(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Update> for MsgAction {
|
||||||
|
fn from(value: Update) -> Self {
|
||||||
|
MsgAction::Update(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<UserAction> for MsgAction {
|
||||||
|
fn from(value: UserAction) -> Self {
|
||||||
|
match value {
|
||||||
|
UserAction::CreateDocument(data) => Self::Create(data),
|
||||||
|
UserAction::Query(data) => Self::Query(data),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod msgactions {
|
||||||
|
use super::*;
|
||||||
|
use crate::name::Name;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn turn_document_definition_into_action() {
|
||||||
|
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||||
|
let value = DocDef::new(name.clone());
|
||||||
|
let result: MsgAction = value.into();
|
||||||
|
match result {
|
||||||
|
MsgAction::Create(def) => assert_eq!(def.get_document_names(), &[name].to_vec()),
|
||||||
|
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn turn_error_into_action() {
|
||||||
|
let data = "data".to_string();
|
||||||
|
let value = MTTError::DocumentAlreadyExists(data.clone());
|
||||||
|
let result: MsgAction = value.into();
|
||||||
|
match result {
|
||||||
|
MsgAction::Error(result) => match result {
|
||||||
|
MTTError::DocumentAlreadyExists(output) => assert_eq!(output, data),
|
||||||
|
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||||
|
},
|
||||||
|
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||||
|
}
|
||||||
|
let value = MTTError::DocumentNotFound(data.clone());
|
||||||
|
let result: MsgAction = value.into();
|
||||||
|
match result {
|
||||||
|
MsgAction::Error(result) => match result {
|
||||||
|
MTTError::DocumentNotFound(output) => assert_eq!(output, data),
|
||||||
|
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||||
|
},
|
||||||
|
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn turn_query_into_action() {
|
||||||
|
let value = Query::new();
|
||||||
|
let result: MsgAction = value.into();
|
||||||
|
match result {
|
||||||
|
MsgAction::Query(_) => {}
|
||||||
|
_ => unreachable!("Got {:?}: dhould have been query", result),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn turn_reply_into_action() {
|
||||||
|
let value = Reply::new();
|
||||||
|
let result: MsgAction = value.into();
|
||||||
|
match result {
|
||||||
|
MsgAction::Reply(_) => {}
|
||||||
|
_ => unreachable!("Got {:?}: dhould have been reply", result),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/action/user.rs
Normal file
19
src/action/user.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
use super::Query;
|
||||||
|
use crate::document::{definition::DocDef, field::FieldType};
|
||||||
|
|
||||||
|
pub enum UserAction {
|
||||||
|
CreateDocument(DocDef),
|
||||||
|
Query(Query),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<DocDef> for UserAction {
|
||||||
|
fn from(value: DocDef) -> Self {
|
||||||
|
Self::CreateDocument(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Query> for UserAction {
|
||||||
|
fn from(value: Query) -> Self {
|
||||||
|
Self::Query(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
action::MsgAction,
|
||||||
message::{
|
message::{
|
||||||
action::{Action, MsgAction},
|
action::Action,
|
||||||
wrapper::{Message, Records},
|
wrapper::{Message, Records},
|
||||||
},
|
},
|
||||||
name::{Name, NameType, Names},
|
name::{Name, NameType, Names},
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
action::Query,
|
action::{MsgAction, Query},
|
||||||
document::{
|
document::{
|
||||||
definition::{DocDef, DocFuncType},
|
definition::{DocDef, DocFuncType},
|
||||||
field::Field,
|
field::Field,
|
||||||
},
|
},
|
||||||
message::{
|
message::{
|
||||||
action::{Action, MsgAction},
|
action::Action,
|
||||||
wrapper::{
|
wrapper::{
|
||||||
CalcValue, Calculation, InternalRecord, InternalRecords, Message, Oid, Records, Reply,
|
CalcValue, Calculation, InternalRecord, InternalRecords, Message, Oid, Records, Reply,
|
||||||
Update,
|
Update,
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
|
action::MsgAction,
|
||||||
document::{
|
document::{
|
||||||
create::IndexType,
|
create::IndexType,
|
||||||
field::{Field, FieldType},
|
field::{Field, FieldType},
|
||||||
},
|
},
|
||||||
message::{
|
message::{action::Action, wrapper::CalcValue},
|
||||||
action::{Action, MsgAction},
|
|
||||||
wrapper::CalcValue,
|
|
||||||
},
|
|
||||||
mtterror::MTTError,
|
mtterror::MTTError,
|
||||||
name::{Name, NameType, Names},
|
name::{Name, NameType, Names},
|
||||||
queue::data_director::{Include, Path},
|
queue::data_director::{Include, Path},
|
||||||
|
|||||||
@ -89,16 +89,13 @@ impl Session {
|
|||||||
mod sessions {
|
mod sessions {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
action::Query,
|
action::{MsgAction, Query},
|
||||||
document::{
|
document::{
|
||||||
clock::{clock_test_support::gen_clock_message, Clock},
|
clock::{clock_test_support::gen_clock_message, Clock},
|
||||||
create::CreateDoc,
|
create::CreateDoc,
|
||||||
field::Field,
|
field::Field,
|
||||||
},
|
},
|
||||||
message::{
|
message::wrapper::{Addition, Records},
|
||||||
action::MsgAction,
|
|
||||||
wrapper::{Addition, Records},
|
|
||||||
},
|
|
||||||
mtterror::MTTError,
|
mtterror::MTTError,
|
||||||
name::{Name, NameType, Names},
|
name::{Name, NameType, Names},
|
||||||
queue::data_director::{Include, Path, RegMsg, Register},
|
queue::data_director::{Include, Path, RegMsg, Register},
|
||||||
|
|||||||
@ -5,7 +5,7 @@ mod mtterror;
|
|||||||
mod name;
|
mod name;
|
||||||
mod queue;
|
mod queue;
|
||||||
|
|
||||||
use action::{DocDef, Query, UserAction};
|
use action::{DocDef, MsgAction, Query, UserAction};
|
||||||
use document::{
|
use document::{
|
||||||
clock::Clock,
|
clock::Clock,
|
||||||
create::CreateDoc,
|
create::CreateDoc,
|
||||||
@ -13,7 +13,7 @@ use document::{
|
|||||||
session::Session,
|
session::Session,
|
||||||
};
|
};
|
||||||
use message::{
|
use message::{
|
||||||
action::{Action, MsgAction},
|
action::Action,
|
||||||
wrapper::{Addition, CalcValue, Calculation, Message, Operand},
|
wrapper::{Addition, CalcValue, Calculation, Message, Operand},
|
||||||
};
|
};
|
||||||
pub use mtterror::MTTError;
|
pub use mtterror::MTTError;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
action::Query,
|
action::{MsgAction, Query},
|
||||||
document::definition::DocDef,
|
document::definition::DocDef,
|
||||||
message::wrapper::{Addition, Delete, Records, Reply, Update},
|
message::wrapper::{Addition, Delete, Records, Reply, Update},
|
||||||
mtterror::MTTError,
|
mtterror::MTTError,
|
||||||
@ -52,145 +52,3 @@ impl From<&MsgAction> for Action {
|
|||||||
Self::from(action)
|
Self::from(action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub enum MsgAction {
|
|
||||||
Addition(Addition),
|
|
||||||
Create(DocDef),
|
|
||||||
Error(MTTError),
|
|
||||||
OnAddition(Records),
|
|
||||||
OnDelete(Records),
|
|
||||||
OnQuery(Records),
|
|
||||||
OnUpdate(Records),
|
|
||||||
Query(Query),
|
|
||||||
Records(Records),
|
|
||||||
Register(Register),
|
|
||||||
Reply(Reply),
|
|
||||||
Show,
|
|
||||||
Delete(Delete),
|
|
||||||
Update(Update),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Addition> for MsgAction {
|
|
||||||
fn from(value: Addition) -> Self {
|
|
||||||
MsgAction::Addition(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Delete> for MsgAction {
|
|
||||||
fn from(value: Delete) -> Self {
|
|
||||||
MsgAction::Delete(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<DocDef> for MsgAction {
|
|
||||||
fn from(value: DocDef) -> Self {
|
|
||||||
MsgAction::Create(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<MTTError> for MsgAction {
|
|
||||||
fn from(value: MTTError) -> Self {
|
|
||||||
MsgAction::Error(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Query> for MsgAction {
|
|
||||||
fn from(value: Query) -> Self {
|
|
||||||
MsgAction::Query(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Records> for MsgAction {
|
|
||||||
fn from(value: Records) -> Self {
|
|
||||||
MsgAction::Records(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Register> for MsgAction {
|
|
||||||
fn from(value: Register) -> Self {
|
|
||||||
MsgAction::Register(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Reply> for MsgAction {
|
|
||||||
fn from(value: Reply) -> Self {
|
|
||||||
MsgAction::Reply(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Update> for MsgAction {
|
|
||||||
fn from(value: Update) -> Self {
|
|
||||||
MsgAction::Update(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<UserAction> for MsgAction {
|
|
||||||
fn from(value: UserAction) -> Self {
|
|
||||||
match value {
|
|
||||||
UserAction::CreateDocument(data) => Self::Create(data),
|
|
||||||
UserAction::Query(data) => Self::Query(data),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod msgactions {
|
|
||||||
use super::*;
|
|
||||||
use crate::name::Name;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn turn_document_definition_into_action() {
|
|
||||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
|
||||||
let value = DocDef::new(name.clone());
|
|
||||||
let result: MsgAction = value.into();
|
|
||||||
match result {
|
|
||||||
MsgAction::Create(def) => assert_eq!(def.get_document_names(), &[name].to_vec()),
|
|
||||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn turn_error_into_action() {
|
|
||||||
let data = "data".to_string();
|
|
||||||
let value = MTTError::DocumentAlreadyExists(data.clone());
|
|
||||||
let result: MsgAction = value.into();
|
|
||||||
match result {
|
|
||||||
MsgAction::Error(result) => match result {
|
|
||||||
MTTError::DocumentAlreadyExists(output) => assert_eq!(output, data),
|
|
||||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
|
||||||
},
|
|
||||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
|
||||||
}
|
|
||||||
let value = MTTError::DocumentNotFound(data.clone());
|
|
||||||
let result: MsgAction = value.into();
|
|
||||||
match result {
|
|
||||||
MsgAction::Error(result) => match result {
|
|
||||||
MTTError::DocumentNotFound(output) => assert_eq!(output, data),
|
|
||||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
|
||||||
},
|
|
||||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn turn_query_into_action() {
|
|
||||||
let value = Query::new();
|
|
||||||
let result: MsgAction = value.into();
|
|
||||||
match result {
|
|
||||||
MsgAction::Query(_) => {}
|
|
||||||
_ => unreachable!("Got {:?}: dhould have been query", result),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn turn_reply_into_action() {
|
|
||||||
let value = Reply::new();
|
|
||||||
let result: MsgAction = value.into();
|
|
||||||
match result {
|
|
||||||
MsgAction::Reply(_) => {}
|
|
||||||
_ => unreachable!("Got {:?}: dhould have been reply", result),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
action::Query,
|
action::{MsgAction, Query},
|
||||||
document::field::{Field, FieldType},
|
document::field::{Field, FieldType},
|
||||||
message::action::MsgAction,
|
|
||||||
mtterror::MTTError,
|
mtterror::MTTError,
|
||||||
name::{NameType, Names},
|
name::{NameType, Names},
|
||||||
queue::data_director::{Include, Path, Route},
|
queue::data_director::{Include, Path, Route},
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
message::{
|
action::MsgAction,
|
||||||
action::{Action, MsgAction},
|
message::{action::Action, wrapper::Message},
|
||||||
wrapper::Message,
|
|
||||||
},
|
|
||||||
mtterror::MTTError,
|
mtterror::MTTError,
|
||||||
name::{Name, NameType, Names},
|
name::{Name, NameType, Names},
|
||||||
queue::router::Queue,
|
queue::router::Queue,
|
||||||
@ -123,7 +121,7 @@ impl Path {
|
|||||||
mod paths {
|
mod paths {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
message::{action::MsgAction, wrapper::Records},
|
message::wrapper::Records,
|
||||||
name::{Name, Names},
|
name::{Name, Names},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -96,7 +96,11 @@ impl Queue {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod routers {
|
mod routers {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{action::Query, message::action::MsgAction, name::Name, support_tests::TIMEOUT};
|
use crate::{
|
||||||
|
action::{MsgAction, Query},
|
||||||
|
name::Name,
|
||||||
|
support_tests::TIMEOUT,
|
||||||
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
sync::mpsc::{Receiver, RecvTimeoutError},
|
sync::mpsc::{Receiver, RecvTimeoutError},
|
||||||
@ -238,7 +242,7 @@ mod routers {
|
|||||||
mod queues {
|
mod queues {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
message::action::MsgAction,
|
action::MsgAction,
|
||||||
mtterror::MTTError,
|
mtterror::MTTError,
|
||||||
name::Name,
|
name::Name,
|
||||||
queue::data_director::{Include, Path},
|
queue::data_director::{Include, Path},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user