Made a specific id for names.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2026-02-27 08:36:22 -05:00
parent 97f9d24330
commit 473b478877
9 changed files with 196 additions and 89 deletions

View File

@@ -5,9 +5,9 @@ use crate::{
definition::{DocDef, DocFuncType},
field::Field,
},
message::wrapper::Message,
message::{wrapper::Message, MessageAction},
mtterror::{ErrorID, MTTError},
name::NameType,
name::{NameID, NameType},
queue::{
data_director::{Include, Path, RegMsg, Register, RouteID},
router::Queue,
@@ -171,11 +171,11 @@ impl Index {
}
struct Indexes {
data: HashMap<Uuid, Index>,
data: HashMap<NameID, Index>,
}
impl Indexes {
fn new(settings: &HashMap<Uuid, IndexType>) -> Self {
fn new(settings: &HashMap<NameID, IndexType>) -> Self {
let mut output = HashMap::new();
for (key, value) in settings.iter() {
output.insert(key.clone(), value.create_index());
@@ -183,15 +183,20 @@ impl Indexes {
Self { data: output }
}
fn index_ids(&self) -> HashSet<&Uuid> {
self.data.keys().collect::<HashSet<&Uuid>>()
fn index_ids(&self) -> HashSet<&NameID> {
self.data.keys().collect::<HashSet<&NameID>>()
}
fn pull(&self, field_id: &Uuid, calc: &Calculation) -> Result<HashSet<Oid>, MTTError> {
fn pull(&self, field_id: &NameID, calc: &Calculation) -> Result<HashSet<Oid>, MTTError> {
self.data.get(field_id).unwrap().pull(calc)
}
fn add_to_index(&mut self, field_name: &Uuid, field: Field, oid: Oid) -> Result<(), MTTError> {
fn add_to_index(
&mut self,
field_name: &NameID,
field: Field,
oid: Oid,
) -> Result<(), MTTError> {
let index = match self.data.get_mut(field_name) {
Some(data) => data,
None => return Ok(()),
@@ -199,7 +204,7 @@ impl Indexes {
index.add(field, oid)
}
fn validate(&self, field_name: &Uuid, value: &Field) -> Result<(), MTTError> {
fn validate(&self, field_name: &NameID, value: &Field) -> Result<(), MTTError> {
match self.data.get(field_name) {
Some(index) => match index.validate(value) {
Ok(_) => {}
@@ -210,7 +215,7 @@ impl Indexes {
Ok(())
}
fn iter_mut(&mut self) -> impl Iterator<Item = (&Uuid, &mut Index)> {
fn iter_mut(&mut self) -> impl Iterator<Item = (&NameID, &mut Index)> {
self.data.iter_mut()
}
}
@@ -361,7 +366,7 @@ struct DocumentFile {
docdef: DocDef,
docs: InternalRecords,
indexes: Indexes,
name_id: Uuid,
name_id: NameID,
queue: Queue,
routes: HashMap<RouteID, DocFuncType>,
rx: Receiver<Message>,
@@ -373,7 +378,7 @@ impl DocumentFile {
rx: Receiver<Message>,
docdef: DocDef,
routes: HashMap<RouteID, DocFuncType>,
name_id: Uuid,
name_id: NameID,
) -> Self {
let indexes = Indexes::new(docdef.get_indexes());
Self {
@@ -472,11 +477,12 @@ impl DocumentFile {
where
NT: Into<NameType>,
{
let field_id = match self.docdef.get_field_id(field_name) {
let id_holder = field_name.into();
let field_id = match self.docdef.get_field_id(id_holder.clone()) {
Ok(data) => data,
Err(err) => return Err(err),
};
let output = match self.docdef.validate(field_id.clone(), value) {
let output = match self.docdef.validate(id_holder.clone(), value) {
Ok(data) => data,
Err(err) => return Err(err),
};
@@ -493,10 +499,17 @@ impl DocumentFile {
_ => return,
};
let mut holder = InternalRecord::new();
let mut field_ids = self.docdef.get_field_ids();
println!("{:?}", field_ids);
for (name_id, value) in addition.iter() {}
for (name_id, value) in addition.iter() {
let field_id = match self.docdef.get_field_id(name_id) {
Ok(id) => id,
Err(err) => {
Err(mut err) => {
err.add_parent(ErrorID::Field(name_id.clone()));
err.add_parent(ErrorID::Document(msg.doc_name().clone()));
let reply = msg.response(err);
self.queue.send(reply);
return;
@@ -504,14 +517,16 @@ impl DocumentFile {
};
holder.insert(field_id.clone(), value.get(&Field::None));
}
for field_id in self.docdef.field_ids().iter() {
for field_id in self.docdef.get_field_ids().iter() {
let value = match holder.get(field_id) {
Some(data) => data,
None => &Field::None,
};
let corrected = match self.validate(field_id, value) {
Ok(data) => data,
Err(err) => {
Err(mut err) => {
err.add_parent(ErrorID::Field(field_id.clone().into()));
err.add_parent(ErrorID::Document(msg.doc_name().clone()));
let reply = msg.response(err);
self.queue.send(reply);
return;
@@ -570,8 +585,8 @@ impl DocumentFile {
fn run_query(&self, query: &Query) -> Result<InternalRecords, MTTError> {
let indexed_ids = self.indexes.index_ids();
let mut indexed: HashMap<Uuid, Calculation> = HashMap::new();
let mut unindexed: HashMap<Uuid, Calculation> = HashMap::new();
let mut indexed: HashMap<NameID, Calculation> = HashMap::new();
let mut unindexed: HashMap<NameID, Calculation> = HashMap::new();
for (field, data) in query.iter() {
let id = match self.docdef.get_field_id(field) {
Ok(fid) => fid,
@@ -647,7 +662,7 @@ impl DocumentFile {
update: &Update,
msg: &Message,
) -> Result<Records, MTTError> {
let mut changes: HashMap<Uuid, &CalcValue> = HashMap::new();
let mut changes: HashMap<NameID, &CalcValue> = HashMap::new();
for (key, value) in update.get_values().iter() {
let field_id = match self.docdef.get_field_id(key) {
Ok(data) => data,
@@ -1125,7 +1140,6 @@ mod document_files {
}
assert!(entries.is_empty(), "did not use {:?}", entries);
}
*/
#[test]
fn errors_on_wrong_field_name() {
@@ -1145,8 +1159,10 @@ mod document_files {
_ => unreachable!("got {:?}: should have been an error", result.get_action()),
}
}
*/
#[test]
#[ignore = "move to lib"]
fn errors_on_wrong_field_type() {
let mut test_doc = TestDocument::new([FieldType::Uuid].to_vec());
test_doc.start(standard_paths());
@@ -1769,6 +1785,7 @@ mod document_files {
}
#[test]
#[ignore = "move to lib"]
fn update_errors_on_bad_field_type() {
let mut doc = TestDocument::new([FieldType::Uuid, FieldType::StaticString].to_vec());
doc.start(standard_paths());