UNPKG

@netwerk-digitaal-erfgoed/ld-workbench

Version:

LDWorkbench is a Linked Data Transformation tool designed to use only SPARQL as transformation language.

40 lines 1.49 kB
import parseYamlFile from './parseYamlFile.js'; import validate from './validate.js'; import path from 'node:path'; import { dirname } from 'path'; /** * This is a wrapper for the YAML Parser and Schema Validator * to provide a 1 step loader. */ export default function loadConfiguration(filePath) { const configuration = parseYamlFile(filePath); const errors = validate(configuration); if (errors !== null) { throw new Error(`The YAML file \`${filePath}\` is not a valid LD Workbench configuration file.`); } return mapObject(configuration, inlineQueryFromFile(configuration.baseDir ?? dirname(filePath))); } const mapObject = (obj, replacer) => { return Object.fromEntries(Object.entries(obj).map(([key, value]) => { if (typeof value === 'string' && value.startsWith('file://')) { return [key, replacer(value)]; } else if (Array.isArray(value)) { return [key, value.map(v => mapObject(v, replacer))]; } else if (typeof value === 'object') { return [key, mapObject(value, replacer)]; } else { return [key, value]; } })); }; const inlineQueryFromFile = (directory) => (prefixedFilePath) => { const filePath = prefixedFilePath.replace('file://', ''); if (path.isAbsolute(filePath)) { return prefixedFilePath; } return `file://${path.resolve(directory, filePath)}`; }; //# sourceMappingURL=loadConfiguration.js.map