-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* extraction graph from yaml * version bump
- Loading branch information
1 parent
0b9f008
commit fedd5ca
Showing
6 changed files
with
129 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { IExtractionPolicy } from "./types"; | ||
import yaml from "yaml"; | ||
|
||
class ExtractionGraph { | ||
id?: string; | ||
name: string; | ||
namespace?: string; | ||
extraction_policies: IExtractionPolicy[]; | ||
|
||
constructor({ | ||
id, | ||
name, | ||
namespace, | ||
extraction_policies, | ||
}: { | ||
id?: string; | ||
name: string; | ||
namespace?: string; | ||
extraction_policies: IExtractionPolicy[]; | ||
}) { | ||
this.id = id; | ||
this.name = name; | ||
this.namespace = namespace; | ||
this.extraction_policies = extraction_policies; | ||
} | ||
|
||
static fromDict(json: Record<string, any>): ExtractionGraph { | ||
if ("namespace" in json) { | ||
delete json["namespace"]; | ||
} | ||
return new ExtractionGraph({ | ||
id: json.id, | ||
name: json.name, | ||
extraction_policies: json.extraction_policies, | ||
}); | ||
} | ||
|
||
static fromYaml(spec: string): ExtractionGraph { | ||
const json = yaml.parse(spec); | ||
return ExtractionGraph.fromDict(json); | ||
} | ||
|
||
toDict(): Record<string, any> { | ||
const filteredDict: Record<string, any> = {}; | ||
for (const key in this) { | ||
if (this[key] !== null && this[key] !== undefined) { | ||
filteredDict[key] = this[key]; | ||
} | ||
} | ||
return filteredDict; | ||
} | ||
} | ||
|
||
export default ExtractionGraph; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters