@@ -11,8 +11,8 @@ pub enum StateMachineError {
1111 MemoryNotFound ( MemoryId ) ,
1212 #[ error( "Invalid state: {0}" ) ]
1313 InvalidState ( String ) ,
14- #[ error( "Cross-namespace edge is not allowed: from={from:?} ({from_ns }) to={to:?} ({to_ns })" ) ]
15- CrossNamespaceEdge { from : MemoryId , from_ns : String , to : MemoryId , to_ns : String } ,
14+ #[ error( "Cross-collection edge is not allowed: from={from:?} ({from_col }) to={to:?} ({to_col })" ) ]
15+ CrossCollectionEdge { from : MemoryId , from_col : String , to : MemoryId , to_col : String } ,
1616}
1717
1818pub type Result < T > = std:: result:: Result < T , StateMachineError > ;
@@ -44,7 +44,7 @@ impl StateMachine {
4444 pub fn apply_command ( & mut self , cmd : Command ) -> Result < ( ) > {
4545 match cmd {
4646 Command :: InsertMemory ( entry) => self . insert_memory ( entry) ,
47- Command :: DeleteMemory ( id) => self . delete_memory ( id) ,
47+ Command :: Delete ( id) => self . delete ( id) ,
4848 Command :: AddEdge { from, to, relation } => self . add_edge ( from, to, relation) ,
4949 Command :: RemoveEdge { from, to } => self . remove_edge ( from, to) ,
5050 }
@@ -83,7 +83,7 @@ impl StateMachine {
8383 }
8484
8585 /// Delete a memory entry and its edges
86- pub fn delete_memory ( & mut self , id : MemoryId ) -> Result < ( ) > {
86+ pub fn delete ( & mut self , id : MemoryId ) -> Result < ( ) > {
8787 if !self . memories . contains_key ( & id) {
8888 return Err ( StateMachineError :: MemoryNotFound ( id) ) ;
8989 }
@@ -109,12 +109,12 @@ impl StateMachine {
109109 let from_entry = self . memories . get ( & from) . ok_or ( StateMachineError :: MemoryNotFound ( from) ) ?;
110110 let to_entry = self . memories . get ( & to) . ok_or ( StateMachineError :: MemoryNotFound ( to) ) ?;
111111
112- if from_entry. namespace != to_entry. namespace {
113- return Err ( StateMachineError :: CrossNamespaceEdge {
112+ if from_entry. collection != to_entry. collection {
113+ return Err ( StateMachineError :: CrossCollectionEdge {
114114 from,
115- from_ns : from_entry. namespace . clone ( ) ,
115+ from_col : from_entry. collection . clone ( ) ,
116116 to,
117- to_ns : to_entry. namespace . clone ( ) ,
117+ to_col : to_entry. collection . clone ( ) ,
118118 } ) ;
119119 }
120120
@@ -129,10 +129,10 @@ impl StateMachine {
129129 Ok ( ( ) )
130130 }
131131
132- pub fn namespace_of ( & self , id : MemoryId ) -> Result < & str > {
132+ pub fn collection_of ( & self , id : MemoryId ) -> Result < & str > {
133133 self . memories
134134 . get ( & id)
135- . map ( |e| e. namespace . as_str ( ) )
135+ . map ( |e| e. collection . as_str ( ) )
136136 . ok_or ( StateMachineError :: MemoryNotFound ( id) )
137137 }
138138
@@ -149,10 +149,10 @@ impl StateMachine {
149149 self . memories . get ( & id) . ok_or ( StateMachineError :: MemoryNotFound ( id) )
150150 }
151151
152- /// Get all memories in a namespace
153- pub fn get_memories_in_namespace ( & self , namespace : & str ) -> Vec < & MemoryEntry > {
152+ /// Get all memories in a collection
153+ pub fn get_memories_in_collection ( & self , collection : & str ) -> Vec < & MemoryEntry > {
154154 let mut entries: Vec < _ > =
155- self . memories . values ( ) . filter ( |e| e. namespace == namespace ) . collect ( ) ;
155+ self . memories . values ( ) . filter ( |e| e. collection == collection ) . collect ( ) ;
156156 entries. sort_by_key ( |e| e. id ) ;
157157 entries
158158 }
@@ -210,10 +210,10 @@ impl Default for StateMachine {
210210mod tests {
211211 use super :: * ;
212212
213- fn create_test_entry ( id : u64 , namespace : & str , timestamp : u64 ) -> MemoryEntry {
213+ fn create_test_entry ( id : u64 , collection : & str , timestamp : u64 ) -> MemoryEntry {
214214 MemoryEntry :: new (
215215 MemoryId ( id) ,
216- namespace . to_string ( ) ,
216+ collection . to_string ( ) ,
217217 format ! ( "content_{}" , id) . into_bytes ( ) ,
218218 timestamp,
219219 )
@@ -238,13 +238,13 @@ mod tests {
238238 }
239239
240240 #[ test]
241- fn test_delete_memory ( ) {
241+ fn test_delete ( ) {
242242 let mut sm = StateMachine :: new ( ) ;
243243 let entry = create_test_entry ( 1 , "default" , 1000 ) ;
244244 sm. insert_memory ( entry) . unwrap ( ) ;
245245 assert_eq ! ( sm. len( ) , 1 ) ;
246246
247- sm. delete_memory ( MemoryId ( 1 ) ) . unwrap ( ) ;
247+ sm. delete ( MemoryId ( 1 ) ) . unwrap ( ) ;
248248 assert_eq ! ( sm. len( ) , 0 ) ;
249249 assert ! ( sm. get_memory( MemoryId ( 1 ) ) . is_err( ) ) ;
250250 }
@@ -309,13 +309,13 @@ mod tests {
309309 }
310310
311311 #[ test]
312- fn test_namespace_filtering ( ) {
312+ fn test_collection_filtering ( ) {
313313 let mut sm = StateMachine :: new ( ) ;
314314 sm. insert_memory ( create_test_entry ( 1 , "ns1" , 1000 ) ) . unwrap ( ) ;
315315 sm. insert_memory ( create_test_entry ( 2 , "ns2" , 1000 ) ) . unwrap ( ) ;
316316 sm. insert_memory ( create_test_entry ( 3 , "ns1" , 1000 ) ) . unwrap ( ) ;
317317
318- let ns1_entries = sm. get_memories_in_namespace ( "ns1" ) ;
318+ let ns1_entries = sm. get_memories_in_collection ( "ns1" ) ;
319319 assert_eq ! ( ns1_entries. len( ) , 2 ) ;
320320 assert_eq ! ( ns1_entries[ 0 ] . id, MemoryId ( 1 ) ) ;
321321 assert_eq ! ( ns1_entries[ 1 ] . id, MemoryId ( 3 ) ) ;
@@ -365,20 +365,20 @@ mod tests {
365365 sm. add_edge ( MemoryId ( 1 ) , MemoryId ( 2 ) , "refers" . to_string ( ) ) . unwrap ( ) ;
366366
367367 // Delete memory 2
368- sm. delete_memory ( MemoryId ( 2 ) ) . unwrap ( ) ;
368+ sm. delete ( MemoryId ( 2 ) ) . unwrap ( ) ;
369369
370370 // Edge should be cleaned up
371371 let neighbors = sm. get_neighbors ( MemoryId ( 1 ) ) . unwrap ( ) ;
372372 assert ! ( neighbors. is_empty( ) ) ;
373373 }
374374
375375 #[ test]
376- fn test_cross_namespace_edge_rejected ( ) {
376+ fn test_cross_collection_edge_rejected ( ) {
377377 let mut sm = StateMachine :: new ( ) ;
378378 sm. insert_memory ( create_test_entry ( 1 , "ns1" , 1000 ) ) . unwrap ( ) ;
379379 sm. insert_memory ( create_test_entry ( 2 , "ns2" , 1000 ) ) . unwrap ( ) ;
380380
381381 let result = sm. add_edge ( MemoryId ( 1 ) , MemoryId ( 2 ) , "bad" . to_string ( ) ) ;
382- assert ! ( matches!( result, Err ( StateMachineError :: CrossNamespaceEdge { .. } ) ) ) ;
382+ assert ! ( matches!( result, Err ( StateMachineError :: CrossCollectionEdge { .. } ) ) ) ;
383383 }
384384}
0 commit comments