1
1
import { Constructable } from '../../app.type.js' ;
2
- import { App } from '../../models/app/app.model.js' ;
3
- import { DiffMetadata } from '../diff/diff-metadata.js' ;
4
2
import { AHook } from './hook.abstract.js' ;
5
3
6
- export type PreCommitCallback = ( modelTransaction : DiffMetadata [ ] [ ] ) => Promise < void > ;
7
- type PreCommitMethodSignature = ( app : App , modelTransaction : DiffMetadata [ ] [ ] ) => Promise < void > ;
4
+ export type PreCommitCallback = ( ...args : any [ ] ) => Promise < void > ;
8
5
9
6
export class PreCommitHandleHook extends AHook {
10
7
private static readonly callbacks : PreCommitCallback [ ] = [ ] ;
@@ -17,18 +14,18 @@ export class PreCommitHandleHook extends AHook {
17
14
static override registrar (
18
15
constructor : Constructable < unknown > ,
19
16
propertyKey : string ,
20
- descriptor : TypedPropertyDescriptor < PreCommitMethodSignature > ,
17
+ descriptor : PropertyDescriptor ,
21
18
) : void {
22
19
const originalMethod = descriptor . value ;
23
20
const self = this ; // eslint-disable-line @typescript-eslint/no-this-alias
24
21
25
22
// `self` here references PreCommitHandleHook, vs `this` references the original method.
26
- descriptor . value = async function ( ...args : [ app : App , modelTransaction : DiffMetadata [ ] [ ] ] ) : Promise < void > {
23
+ descriptor . value = async function ( ...args : any [ ] ) : Promise < any > {
27
24
for ( const callback of self . callbacks ) {
28
- await callback ( args [ 1 ] ) ;
25
+ await callback . apply ( this , args ) ;
29
26
}
30
27
31
- await originalMethod ! . apply ( this , args ) ;
28
+ return await originalMethod ! . apply ( this , args ) ;
32
29
} ;
33
30
}
34
31
}
0 commit comments