@@ -27,6 +27,22 @@ pub enum PreDispatchResult {
2727 } ,
2828}
2929
30+ /// Parameters shared by [`fire_pre_dispatch_triggers`] and [`fire_post_dispatch_triggers`].
31+ pub struct DispatchTriggerParams < ' a > {
32+ /// Shared server state (trigger registry, block cache).
33+ pub state : & ' a SharedState ,
34+ /// Caller identity (used unless a trigger is SECURITY DEFINER).
35+ pub identity : & ' a AuthenticatedIdentity ,
36+ /// Tenant scope for trigger lookup and execution.
37+ pub tenant_id : TenantId ,
38+ /// The DML write being dispatched.
39+ pub info : & ' a DmlWriteInfo ,
40+ /// The row's prior state, for UPDATE/DELETE (`None` for INSERT).
41+ pub old_row : & ' a Option < HashMap < String , nodedb_types:: Value > > ,
42+ /// Current cascade depth, for infinite-loop protection.
43+ pub cascade_depth : u32 ,
44+ }
45+
3046/// Fire BEFORE + INSTEAD OF triggers for a point write.
3147///
3248/// Returns `PreDispatchResult::Proceed` if the caller should dispatch normally.
@@ -37,15 +53,18 @@ pub enum PreDispatchResult {
3753///
3854/// On BEFORE trigger error (RAISE EXCEPTION), the error propagates and
3955/// the caller should abort the write.
40- #[ allow( clippy:: too_many_arguments) ]
4156pub async fn fire_pre_dispatch_triggers (
42- state : & SharedState ,
43- identity : & AuthenticatedIdentity ,
44- tenant_id : TenantId ,
45- info : & DmlWriteInfo ,
46- old_row : & Option < HashMap < String , nodedb_types:: Value > > ,
47- cascade_depth : u32 ,
57+ params : DispatchTriggerParams < ' _ > ,
4858) -> crate :: Result < PreDispatchResult > {
59+ let DispatchTriggerParams {
60+ state,
61+ identity,
62+ tenant_id,
63+ info,
64+ old_row,
65+ cascade_depth,
66+ } = params;
67+
4968 // Check INSTEAD OF first — if it handles the write, skip everything else.
5069 match info. event {
5170 DmlEvent :: Insert => {
@@ -70,13 +89,15 @@ pub async fn fire_pre_dispatch_triggers(
7089 let old_fields = old_row. as_ref ( ) . unwrap_or ( & empty) ;
7190 let new_fields = info. new_fields . as_ref ( ) . unwrap_or ( & empty) ;
7291 match super :: fire_instead:: fire_instead_of_update (
73- state,
74- identity,
75- tenant_id,
76- & info. collection ,
77- old_fields,
78- new_fields,
79- cascade_depth,
92+ super :: fire_instead:: InsteadOfUpdateParams {
93+ state,
94+ identity,
95+ tenant_id,
96+ collection : & info. collection ,
97+ old_fields,
98+ new_fields,
99+ cascade_depth,
100+ } ,
80101 )
81102 . await ?
82103 {
@@ -168,15 +189,16 @@ pub async fn fire_pre_dispatch_triggers(
168189///
169190/// Called after the Data Plane has committed the write. Only fires triggers
170191/// with `execution_mode = Sync`. ASYNC triggers are handled by the Event Plane.
171- #[ allow( clippy:: too_many_arguments) ]
172- pub async fn fire_post_dispatch_triggers (
173- state : & SharedState ,
174- identity : & AuthenticatedIdentity ,
175- tenant_id : TenantId ,
176- info : & DmlWriteInfo ,
177- old_row : & Option < HashMap < String , nodedb_types:: Value > > ,
178- cascade_depth : u32 ,
179- ) -> crate :: Result < ( ) > {
192+ pub async fn fire_post_dispatch_triggers ( params : DispatchTriggerParams < ' _ > ) -> crate :: Result < ( ) > {
193+ let DispatchTriggerParams {
194+ state,
195+ identity,
196+ tenant_id,
197+ info,
198+ old_row,
199+ cascade_depth,
200+ } = params;
201+
180202 let empty = HashMap :: new ( ) ;
181203
182204 // Fire SYNC AFTER ROW triggers.
@@ -198,16 +220,16 @@ pub async fn fire_post_dispatch_triggers(
198220 DmlEvent :: Update => {
199221 let old_fields = old_row. as_ref ( ) . unwrap_or ( & empty) ;
200222 let new_fields = info. new_fields . as_ref ( ) . unwrap_or ( & empty) ;
201- fire_after:: fire_after_update (
223+ fire_after:: fire_after_update ( fire_after :: FireAfterUpdateParams {
202224 state,
203225 identity,
204226 tenant_id,
205- & info. collection ,
227+ collection : & info. collection ,
206228 old_fields,
207229 new_fields,
208230 cascade_depth,
209- Some ( TriggerExecutionMode :: Sync ) ,
210- )
231+ mode_filter : Some ( TriggerExecutionMode :: Sync ) ,
232+ } )
211233 . await ?;
212234 }
213235 DmlEvent :: Delete => {
0 commit comments