Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.

Commit 3867dc7

Browse files
feat: extraction graph update
Signed-off-by: Adithya Krishna <[email protected]>
1 parent 7688bde commit 3867dc7

File tree

1 file changed

+12
-38
lines changed

1 file changed

+12
-38
lines changed

src/ExtractionGraph.ts

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,26 @@ import { IExtractionPolicy } from "./types";
22
import yaml from "yaml";
33

44
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+
) {}
2611

2712
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);
3615
}
3716

3817
static fromYaml(spec: string): ExtractionGraph {
39-
const json = yaml.parse(spec);
40-
return ExtractionGraph.fromDict(json);
18+
return ExtractionGraph.fromDict(yaml.parse(spec));
4119
}
4220

4321
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+
);
5125
}
5226
}
5327

0 commit comments

Comments
 (0)