All files / services/validation/presets index.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 2/2
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                      21x                 21x                   9x               22x 44x      
import { Store } from '@faubulous/mentor-rdf';
import basicOntologyShapes from '@src/ontologies/shapes/ontology-1.0.0.ttl';
import basicTaxonomyShapes from '@src/ontologies/shapes/taxonomy-1.0.0.ttl';
import { PresetGraph } from '@src/services/core/preset-graph';
import { ONTOLOGY_SHAPES_URI, TAXONOMY_SHAPES_URI } from '../preset-definitions';
 
/**
 * The bundled Turtle source of each preset shape graph, keyed by preset id. Used
 * both to seed the in-memory store ({@link loadPresetShapeGraphs}) and to write
 * a frozen copy into the workspace when a preset is instantiated.
 */
const PRESET_SHAPE_SOURCES: Record<string, string> = {
	'ontology': basicOntologyShapes,
	'taxonomy': basicTaxonomyShapes,
};
 
/**
 * The bundled preset shape graphs. Inference is skipped: the graphs are only ever
 * read as shape datasets.
 */
export const PRESET_SHAPE_GRAPHS: PresetGraph[] = [
	{ path: 'shapes/ontology-1.0.0.ttl', graphIri: ONTOLOGY_SHAPES_URI, source: basicOntologyShapes, executeInference: false },
	{ path: 'shapes/taxonomy-1.0.0.ttl', graphIri: TAXONOMY_SHAPES_URI, source: basicTaxonomyShapes, executeInference: false },
];
 
/**
 * Returns the bundled Turtle source for a preset shape graph, or `undefined` when
 * the preset id is unknown.
 */
export function getPresetShapeSource(presetId: string): string | undefined {
	return PRESET_SHAPE_SOURCES[presetId];
}
 
/**
 * Loads the bundled SHACL shape graphs referenced by the built-in validation
 * presets into the store.
 */
export function loadPresetShapeGraphs(store: Store): void {
	for (const graph of PRESET_SHAPE_GRAPHS) {
		store.loadTurtle(graph.source, graph.graphIri, graph.executeInference);
	}
}