2
2
//
3
3
// SPDX-License-Identifier: MIT
4
4
5
- import { SerializedValidationLayout } from 'server-response-types' ;
5
+ import { SerializedJobValidationLayout , SerializedTaskValidationLayout } from 'server-response-types' ;
6
6
import PluginRegistry from './plugins' ;
7
7
8
- export default class ValidationLayout {
9
- #honeypotFrames: number [ ] ;
10
- #honeypotRealFrames: number [ ] ;
8
+ export class JobValidationLayout {
9
+ #honeypotCount: JobValidationLayout [ 'honeypotCount' ] ;
10
+ #honeypotFrames: JobValidationLayout [ 'honeypotFrames' ] ;
11
+ #honeypotRealFrames: JobValidationLayout [ 'honeypotRealFrames' ] ;
11
12
12
- public constructor ( data : Required < SerializedValidationLayout > ) {
13
- this . #honeypotFrames = [ ...data . honeypot_frames ] ;
14
- this . #honeypotRealFrames = [ ...data . honeypot_real_frames ] ;
13
+ public constructor ( data : SerializedJobValidationLayout ) {
14
+ this . #honeypotCount = data . honeypot_count ?? 0 ;
15
+ this . #honeypotFrames = [ ...( data . honeypot_frames ?? [ ] ) ] ;
16
+ this . #honeypotRealFrames = [ ...( data . honeypot_real_frames ?? [ ] ) ] ;
15
17
}
16
18
17
- public get honeypotFrames ( ) {
19
+ public get honeypotCount ( ) : number {
20
+ return this . #honeypotCount;
21
+ }
22
+
23
+ public get honeypotFrames ( ) : number [ ] {
18
24
return [ ...this . #honeypotFrames] ;
19
25
}
20
26
21
- public get honeypotRealFrames ( ) {
27
+ public get honeypotRealFrames ( ) : number [ ] {
22
28
return [ ...this . #honeypotRealFrames] ;
23
29
}
24
30
25
31
async getRealFrame ( frame : number ) : Promise < number | null > {
26
- const result = await PluginRegistry . apiWrapper . call ( this , ValidationLayout . prototype . getRealFrame , frame ) ;
32
+ const result = await PluginRegistry . apiWrapper . call ( this , JobValidationLayout . prototype . getRealFrame , frame ) ;
27
33
return result ;
28
34
}
29
35
}
30
36
31
- Object . defineProperties ( ValidationLayout . prototype . getRealFrame , {
37
+ Object . defineProperties ( JobValidationLayout . prototype . getRealFrame , {
32
38
implementation : {
33
39
writable : false ,
34
40
enumerable : false ,
35
- value : function implementation ( this : ValidationLayout , frame : number ) : number | null {
41
+ value : function implementation ( this : JobValidationLayout , frame : number ) : number | null {
36
42
const index = this . honeypotFrames . indexOf ( frame ) ;
37
43
if ( index !== - 1 ) {
38
44
return this . honeypotRealFrames [ index ] ;
@@ -42,3 +48,28 @@ Object.defineProperties(ValidationLayout.prototype.getRealFrame, {
42
48
} ,
43
49
} ,
44
50
} ) ;
51
+
52
+ export class TaskValidationLayout extends JobValidationLayout {
53
+ #mode: TaskValidationLayout [ 'mode' ] ;
54
+ #validationFrames: TaskValidationLayout [ 'validationFrames' ] ;
55
+ #disabledFrames: TaskValidationLayout [ 'disabledFrames' ] ;
56
+
57
+ public constructor ( data : SerializedTaskValidationLayout ) {
58
+ super ( data ) ;
59
+ this . #mode = data . mode ;
60
+ this . #validationFrames = [ ...( data . validation_frames ?? [ ] ) ] ;
61
+ this . #disabledFrames = [ ...( data . disabled_frames ?? [ ] ) ] ;
62
+ }
63
+
64
+ public get mode ( ) : NonNullable < SerializedTaskValidationLayout [ 'mode' ] > {
65
+ return this . #mode;
66
+ }
67
+
68
+ public get validationFrames ( ) : number [ ] {
69
+ return [ ...this . #validationFrames] ;
70
+ }
71
+
72
+ public get disabledFrames ( ) : number [ ] {
73
+ return [ ...this . #disabledFrames] ;
74
+ }
75
+ }
0 commit comments