Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function sparql (filename, targetURI, text, callback) {
debug('PATCH -- parsing query ...')
var patchURI = targetURI // @@@ beware the triples from the patch ending up in the same place
var patchKB = $rdf.graph()
var targetKB = $rdf.graph()
var targetContentType = mime.lookup(filename)
var query = $rdf.SPARQLToQuery(text, false, patchKB, patchURI) // last param not used ATM
fs.readFile(filename, {encoding: 'utf8'}, function (err, dataIn) {
if (err) {
return callback(error(404, 'Patch: Original file read error:' + err))
}
debug('PATCH -- File read OK ' + dataIn.length)
debug('PATCH -- parsing target file ...')
try {
$rdf.parse(dataIn, targetKB, targetURI, targetContentType)
} catch (e) {
debug('Patch: Target ' + targetContentType + ' file syntax error:' + e)
return callback(error(500, 'Patch: Target ' + targetContentType + ' file syntax error:' + e))
}
debug('PATCH -- Target parsed OK ')
function patch (filename, targetURI, text, callback) {
debug('PATCH -- parsing query ...')
var patchURI = targetURI // @@@ beware the triples from the patch ending up in the same place
var patchKB = $rdf.graph()
var targetKB = $rdf.graph()
var targetContentType = mime.lookup(filename) || DEFAULT_CONTENT_TYPE
var query = $rdf.SPARQLToQuery(text, false, patchKB, patchURI) // last param not used ATM
fs.readFile(filename, {encoding: 'utf8'}, function (err, dataIn) {
if (err) {
return callback(error(404, 'Patch: Original file read error:' + err))
}
debug('PATCH -- File read OK ' + dataIn.length)
debug('PATCH -- parsing target file ...')
try {
$rdf.parse(dataIn, targetKB, targetURI, targetContentType)
} catch (e) {
debug('Patch: Target ' + targetContentType + ' file syntax error:' + e)
return callback(error(500, 'Patch: Target ' + targetContentType + ' file syntax error:' + e))
}
debug('PATCH -- Target parsed OK ')
return new Promise((resolve, reject) => {
const query = $rdf.SPARQLToQuery(sparql, false, store)
store.query(query, resolve, null, () => reject(new Error('No results.')))
})
}
return new Promise((resolve, reject)=>{
try {
let query = $rdf.SPARQLToQuery(fiddle.query,false,fiddle.store)
resolve(query)
}
catch(err) { reject(err) }
})
}