MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / process_event

Function process_event

nodedb/src/control/event_trigger.rs:59–116  ·  view source on GitHub ↗

Process a single change event against all matching EventDefinitions.

(shared: &SharedState, event: &ChangeEvent)

Source from the content-addressed store, hash-verified

57
58/// Process a single change event against all matching EventDefinitions.
59async fn process_event(shared: &SharedState, event: &ChangeEvent) {
60 let catalog = match shared.credentials.catalog() {
61 Some(c) => c,
62 None => return,
63 };
64
65 let coll = match catalog.get_collection(
66 DatabaseId::DEFAULT,
67 event.tenant_id.as_u64(),
68 &event.collection,
69 ) {
70 Ok(Some(c)) => c,
71 _ => return,
72 };
73
74 if coll.event_defs.is_empty() {
75 return;
76 }
77
78 let op_str = event.operation.as_str();
79
80 for event_def in &coll.event_defs {
81 let when_upper = event_def.when_condition.to_uppercase();
82 let matches = match when_upper.as_str() {
83 "INSERT" => event.operation == ChangeOperation::Insert,
84 "UPDATE" => event.operation == ChangeOperation::Update,
85 "DELETE" => event.operation == ChangeOperation::Delete,
86 "ANY" | "*" | "TRUE" => true,
87 compound => compound.contains(op_str),
88 };
89
90 if !matches {
91 continue;
92 }
93
94 debug!(
95 event = event_def.name,
96 collection = event.collection,
97 document_id = event.document_id,
98 operation = op_str,
99 action = event_def.then_action,
100 "event trigger fired"
101 );
102
103 // Execute the THEN action as SQL.
104 execute_then_action(shared, event, &event_def.then_action, &event_def.name).await;
105
106 shared.audit_record(
107 crate::control::security::audit::AuditEvent::AdminAction,
108 Some(event.tenant_id),
109 "event_trigger",
110 &format!(
111 "event '{}' on '{}': doc={}, op={}, action={}",
112 event_def.name, event.collection, event.document_id, op_str, event_def.then_action
113 ),
114 );
115 }
116}

Callers

nothing calls this directly

Calls 8

execute_then_actionFunction · 0.85
audit_recordMethod · 0.80
catalogMethod · 0.45
get_collectionMethod · 0.45
as_u64Method · 0.45
is_emptyMethod · 0.45
as_strMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected