@@ -2,52 +2,26 @@ import { IExtractionPolicy } from "./types";
2
2
import yaml from "yaml" ;
3
3
4
4
class ExtractionGraph {
5
- id ?: string ;
6
- name : string ;
7
- namespace ?: string ;
8
- extraction_policies : IExtractionPolicy [ ] ;
9
-
10
- constructor ( {
11
- id,
12
- name,
13
- namespace,
14
- extraction_policies,
15
- } : {
16
- id ?: string ;
17
- name : string ;
18
- namespace ?: string ;
19
- extraction_policies : IExtractionPolicy [ ] ;
20
- } ) {
21
- this . id = id ;
22
- this . name = name ;
23
- this . namespace = namespace ;
24
- this . extraction_policies = extraction_policies ;
25
- }
5
+ constructor (
6
+ public readonly name : string ,
7
+ public readonly extraction_policies : IExtractionPolicy [ ] ,
8
+ public readonly id ?: string ,
9
+ public readonly namespace ?: string
10
+ ) { }
26
11
27
12
static fromDict ( json : Record < string , any > ) : ExtractionGraph {
28
- if ( "namespace" in json ) {
29
- delete json [ "namespace" ] ;
30
- }
31
- return new ExtractionGraph ( {
32
- id : json . id ,
33
- name : json . name ,
34
- extraction_policies : json . extraction_policies ,
35
- } ) ;
13
+ const { id, name, extraction_policies, ...rest } = json ;
14
+ return new ExtractionGraph ( name , extraction_policies , id ) ;
36
15
}
37
16
38
17
static fromYaml ( spec : string ) : ExtractionGraph {
39
- const json = yaml . parse ( spec ) ;
40
- return ExtractionGraph . fromDict ( json ) ;
18
+ return ExtractionGraph . fromDict ( yaml . parse ( spec ) ) ;
41
19
}
42
20
43
21
toDict ( ) : Record < string , any > {
44
- const filteredDict : Record < string , any > = { } ;
45
- for ( const key in this ) {
46
- if ( this [ key ] !== null && this [ key ] !== undefined ) {
47
- filteredDict [ key ] = this [ key ] ;
48
- }
49
- }
50
- return filteredDict ;
22
+ return Object . fromEntries (
23
+ Object . entries ( this ) . filter ( ( [ _ , value ] ) => value != null )
24
+ ) ;
51
25
}
52
26
}
53
27
0 commit comments