Moved addition into action.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s

This commit is contained in:
Jeff Baskin 2026-02-09 23:32:14 -05:00
parent aae2548da3
commit 9dbaaceb80
8 changed files with 107 additions and 103 deletions

View File

@ -1,4 +1,5 @@
mod action_type;
mod addition;
mod calculation;
mod message;
mod query;
@ -10,6 +11,7 @@ pub use crate::document::{
field::{Field, FieldType},
};
pub use action_type::Action;
pub use addition::Addition;
pub use calculation::{CalcValue, Calculation, Operand};
pub use message::MsgAction;
pub use query::Query;

94
src/action/addition.rs Normal file
View File

@ -0,0 +1,94 @@
use super::{CalcValue, Field, RequestData};
use crate::name::NameType;
use uuid::Uuid;
#[derive(Clone, Debug)]
pub struct Addition {
data: RequestData,
}
impl Addition {
pub fn new() -> Self {
Self {
data: RequestData::new(),
}
}
#[allow(dead_code)]
pub fn add_field<NT, CV>(&mut self, name: NT, field: CV)
where
CV: Into<CalcValue>,
NT: Into<NameType>,
{
self.data.add_field(name, field);
}
pub fn iter(&self) -> impl Iterator<Item = (&NameType, &CalcValue)> {
self.data.iter()
}
}
#[cfg(test)]
mod additions {
use super::*;
use crate::name::Name;
#[test]
fn can_add_static_string() {
let mut add = Addition::new();
let name = Name::english(Uuid::new_v4().to_string().as_str());
let ntype: NameType = name.clone().into();
let data = Uuid::new_v4().to_string();
add.add_field(name.clone(), data.clone());
assert_eq!(add.iter().count(), 1);
for (field_name, value) in add.iter() {
assert_eq!(field_name, &ntype);
match value {
CalcValue::Value(result) => match result {
Field::StaticString(output) => assert_eq!(output, &data),
_ => unreachable!("got {:?}, should have been a string", result),
},
_ => unreachable!("got {:?}: should have received value", value),
}
}
}
#[test]
fn can_add_uuid() {
let mut add = Addition::new();
let name = Name::english(Uuid::new_v4().to_string().as_str());
let ntype: NameType = name.clone().into();
let data = Uuid::new_v4();
add.add_field(name.clone(), data.clone());
assert_eq!(add.iter().count(), 1);
for (field_name, value) in add.iter() {
assert_eq!(field_name, &ntype);
match value {
CalcValue::Value(result) => match result {
Field::Uuid(output) => assert_eq!(output, &data),
_ => unreachable!("got {:?}, should have been a string", result),
},
_ => unreachable!("got {:?}: should have received value", value),
}
}
}
/*
#[test]
fn can_get_document() {
let mut add = Addition::new();
let name = Name::english(Uuid::new_v4().to_string().as_str());
let data = Uuid::new_v4();
add.add_field(name.clone(), data.clone());
let doc = add.get_document();
let output = doc.get_field(&name);
match output {
CalcValue::Value(holder) => match holder {
Field::Uuid(result) => assert_eq!(result, &data),
_ => unreachable!("should have received uuid"),
},
_ => unreachable!("got {:?}: should have received value", output),
}
}
*/
}

View File

@ -1,6 +1,6 @@
use super::{DocDef, Query, UserAction};
use super::{Addition, DocDef, Query, UserAction};
use crate::{
message::wrapper::{Addition, Delete, Records, Reply, Update},
message::wrapper::{Delete, Records, Reply, Update},
mtterror::MTTError,
name::NameType,
queue::data_director::Register,
@ -27,6 +27,7 @@ pub enum MsgAction {
impl MsgAction {
fn doc_name(&self) -> NameType {
match self {
Self::Addition(data) => NameType::None,
Self::Query(data) => data.doc_name(),
_ => NameType::None,
}

View File

@ -10,7 +10,7 @@ pub struct RequestData {
}
impl RequestData {
fn new() -> Self {
pub fn new() -> Self {
Self {
data: HashMap::new(),
}

View File

@ -811,9 +811,9 @@ impl DocumentFile {
mod document_files {
use super::*;
use crate::{
action::Operand,
action::{Addition, Operand},
document::field::FieldType,
message::wrapper::{Addition, Delete},
message::wrapper::Delete,
name::{Name, Names},
support_tests::TIMEOUT,
};

View File

@ -85,13 +85,13 @@ impl Session {
mod sessions {
use super::*;
use crate::{
action::{MsgAction, Query},
action::{Addition, MsgAction, Query},
document::{
clock::{clock_test_support::gen_clock_message, Clock},
create::CreateDoc,
field::Field,
},
message::wrapper::{Addition, Records},
message::wrapper::Records,
mtterror::MTTError,
name::{Name, NameType, Names},
queue::data_director::{Include, Path, RegMsg, Register},

View File

@ -6,10 +6,11 @@ mod name;
mod queue;
use action::{
Action, CalcValue, Calculation, DocDef, Field, FieldType, MsgAction, Operand, Query, UserAction,
Action, Addition, CalcValue, Calculation, DocDef, Field, FieldType, MsgAction, Operand, Query,
UserAction,
};
use document::{clock::Clock, create::CreateDoc, session::Session};
use message::wrapper::{Addition, Message};
use message::wrapper::Message;
use queue::{
data_director::{Include, Path, RegMsg, Register},
router::Queue,

View File

@ -237,100 +237,6 @@ mod messages {
}
}
#[derive(Clone, Debug)]
pub struct Addition {
data: Document,
}
impl Addition {
pub fn new() -> Self {
Self {
data: Document::new(),
}
}
#[allow(dead_code)]
pub fn add_field<NT, CV>(&mut self, name: NT, field: CV)
where
CV: Into<CalcValue>,
NT: Into<NameType>,
{
self.data.add_field(name, field);
}
#[allow(dead_code)]
fn get_field<NT>(&self, name: NT) -> &CalcValue
where
NT: Into<NameType>,
{
self.data.get_field(name)
}
#[allow(dead_code)]
fn get_document(&self) -> Document {
self.data.clone()
}
pub fn iter(&self) -> impl Iterator<Item = (&NameType, &CalcValue)> {
self.data.iter()
}
}
#[cfg(test)]
mod additions {
use super::*;
use crate::name::Name;
#[test]
fn can_add_static_string() {
let mut add = Addition::new();
let name = Name::english(Uuid::new_v4().to_string().as_str());
let data = Uuid::new_v4().to_string();
add.add_field(name.clone(), data.clone());
let result = add.get_field(&name);
match result {
CalcValue::Value(result) => match result {
Field::StaticString(output) => assert_eq!(output, &data),
_ => unreachable!("got {:?}, should have been a string", result),
},
_ => unreachable!("got {:?}: should have received value", result),
}
}
#[test]
fn can_add_uuid() {
let mut add = Addition::new();
let name = Name::english(Uuid::new_v4().to_string().as_str());
let data = Uuid::new_v4();
add.add_field(name.clone(), data.clone());
let output = add.get_field(&name);
match output {
CalcValue::Value(result) => match result {
Field::Uuid(result) => assert_eq!(result, &data),
_ => unreachable!("got {:?}: should have received uuid", result),
},
_ => unreachable!("got {:?}: should have received value", output),
}
}
#[test]
fn can_get_document() {
let mut add = Addition::new();
let name = Name::english(Uuid::new_v4().to_string().as_str());
let data = Uuid::new_v4();
add.add_field(name.clone(), data.clone());
let doc = add.get_document();
let output = doc.get_field(&name);
match output {
CalcValue::Value(holder) => match holder {
Field::Uuid(result) => assert_eq!(result, &data),
_ => unreachable!("should have received uuid"),
},
_ => unreachable!("got {:?}: should have received value", output),
}
}
}
#[allow(dead_code)]
#[derive(Clone, Debug)]
pub struct Operation {