@netwerk-digitaal-erfgoed/ld-workbench
Version:
LDWorkbench is a Linked Data Transformation tool designed to use only SPARQL as transformation language.
30 lines • 1.01 kB
JavaScript
import File from '../file.js';
import { PreviousStage } from '../stage.js';
import { isFilePathString } from './guards.js';
export default function getEndpoint(stage, type = 'iterator', index) {
const t = type;
const endpoint = t === 'generator'
? stage.configuration[t]?.[index]?.endpoint
: stage.configuration[t]?.endpoint;
if (isFilePathString(endpoint)) {
return new File(endpoint);
}
else if (endpoint !== undefined) {
try {
return new URL(endpoint);
}
catch (e) {
throw new Error(`"${endpoint}" is not a valid URL`);
}
}
else {
const stagesSoFar = Array.from(stage.pipeline.stages.keys());
if (stagesSoFar.length === 0) {
throw new Error(`no destination defined for the ${type} and no previous stage to use that result`);
}
else {
return new PreviousStage(stage, stagesSoFar.pop());
}
}
}
//# sourceMappingURL=getEndpoint.js.map