-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#831 Error when generating types from non ontology
- Loading branch information
Showing
4 changed files
with
49 additions
and
8 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
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,29 @@ | ||
import { core } from '@tomic/lib'; | ||
import { store } from './store.js'; | ||
import chalk from 'chalk'; | ||
|
||
export const validateOntologies = async ( | ||
ontologies: string[], | ||
): Promise<[valid: boolean, report: string]> => { | ||
let isValid = true; | ||
let report = ''; | ||
|
||
for (const subject of ontologies) { | ||
try { | ||
const resource = await store.getResourceAsync(subject); | ||
|
||
if (!resource.hasClasses(core.classes.ontology)) { | ||
isValid = false; | ||
const isA = await store.getResourceAsync(resource.getClasses()[0]); | ||
report += `Expected ${chalk.cyan( | ||
resource.title, | ||
)} to have class Ontology but found ${chalk.cyan(isA.title)}\n`; | ||
} | ||
} catch (e) { | ||
isValid = false; | ||
report += `Could not fetch ontology at ${subject}\n`; | ||
} | ||
} | ||
|
||
return [isValid, report]; | ||
}; |