@@ -32,9 +32,69 @@ export interface DatabaseConfiguration {
32
32
}
33
33
}
34
34
35
+ export interface ForestRequest extends Request {
36
+ user : User ,
37
+ }
38
+
39
+ // Base attributes for actions requests (content of request.data.body.attributes)
40
+ interface ActionRequestAttributes {
41
+ collection_name : string ,
42
+ ids : string [ ] ,
43
+ parent_collection_name : string ,
44
+ parent_collection_id : string ,
45
+ parent_association_name : string ,
46
+ all_records : boolean ,
47
+ all_records_subset_query : Query ,
48
+ all_records_ids_excluded : string [ ] ,
49
+ smart_action_id : string ,
50
+ }
51
+
52
+ // Base body from requests for action routes / hooks
53
+ interface ActionRequestBody {
54
+ data : {
55
+ attributes : ActionRequestAttributes ,
56
+ type : 'action-requests' ,
57
+ } ,
58
+ }
59
+
60
+ // Base body from requests for classic smart action routes
61
+ interface SmartActionRequestBody {
62
+ data : {
63
+ attributes : ActionRequestAttributes & { values : Record < string , any > } ,
64
+ type : 'custom-action-requests' ,
65
+ } ,
66
+ }
67
+
68
+ // Base body from requests for smart action hooks
69
+ interface SmartActionHookRequestBody {
70
+ data : {
71
+ attributes : ActionRequestAttributes & {
72
+ fields : SmartActionChangeHookField [ ] ,
73
+ changedField : string ,
74
+ } ,
75
+ type : 'custom-action-hook-requests' ,
76
+ } ,
77
+ }
78
+
79
+ // Concrete smart action request for classic smart action routes
80
+ export interface SmartActionRequest extends ForestRequest {
81
+ body : SmartActionRequestBody ,
82
+ }
83
+
84
+ // Request passed to smart action load hooks
85
+ export interface SmartActionLoadHookRequest extends ForestRequest {
86
+ body : ActionRequestBody ,
87
+ }
88
+
89
+ // Request passed to smart action change hooks
90
+ export interface SmartActionChangeHookRequest extends ForestRequest {
91
+ body : SmartActionHookRequestBody ,
92
+ }
93
+
35
94
// Everything related to Forest Authentication
36
95
37
96
export function ensureAuthenticated ( request : Request , response : Response , next : NextFunction ) : void ;
97
+
38
98
export interface User {
39
99
renderingId : number ;
40
100
}
@@ -63,7 +123,7 @@ export class RecordGetter<T> extends AbstractRecordTool<T> {
63
123
64
124
export class RecordsGetter < T > extends AbstractRecordTool < T > {
65
125
getAll ( query : Query ) : Promise < ( T & Document ) [ ] > ;
66
- getIdsFromRequest ( request : Request ) : Promise < string [ ] > ;
126
+ getIdsFromRequest ( request : SmartActionRequest | SmartActionLoadHookRequest | SmartActionChangeHookRequest ) : Promise < string [ ] > ;
67
127
}
68
128
69
129
export class RecordsCounter < M extends Model < any > > extends AbstractRecordTool < M > {
@@ -222,16 +282,16 @@ export interface SmartActionLoadHookField extends SmartActionHookField {
222
282
position : number ,
223
283
}
224
284
225
- export interface SmartActionLoadHook < T = any > {
226
- ( context : { fields : SmartActionLoadHookField [ ] , record : T & Document } ) : SmartActionLoadHookField [ ]
285
+ export interface SmartActionLoadHook {
286
+ ( context : { fields : SmartActionLoadHookField [ ] , request : SmartActionLoadHookRequest } ) : SmartActionLoadHookField [ ]
227
287
}
228
288
229
289
export interface SmartActionChangeHookField extends SmartActionHookField {
230
290
previousValue : any ,
231
291
}
232
292
233
- export interface SmartActionChangeHook < T = any > {
234
- ( context : { fields : SmartActionChangeHookField [ ] , record : T , changedField : SmartActionChangeHookField } ) : SmartActionChangeHookField [ ]
293
+ export interface SmartActionChangeHook {
294
+ ( context : { fields : SmartActionChangeHookField [ ] , changedField : SmartActionChangeHookField , request : SmartActionChangeHookRequest } ) : SmartActionChangeHookField [ ]
235
295
}
236
296
237
297
export interface SmartActionHooks {
0 commit comments