Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function sparqlUpdate (filename, targetURI, text, callback) {
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)
debug('PATCH -- parsing patch ...')
var patchObject
try {
// Must parse relative to document's base address but patch doc should get diff URI
patchObject = $rdf.sparqlUpdateParser(text, patchKB, patchURI)
} catch (e) {
return callback(error(400, 'Patch format syntax error:\n' + e + '\n'))
}
debug('PATCH -- reading target file ...')
waterfall([
(cb) => {
fs.stat(filename, (err) => {
if (!err) return cb()
fs.writeFile(filename, '', (err) => {
if (err) {
return cb(error(err, 'Error creating the patch target'))
}
cb()
})
return new Promise((resolve, reject) => {
const baseURI = patchURI.replace(/#.*/, '')
try {
resolve($rdf.sparqlUpdateParser(patchText, patchKB, baseURI))
} catch (err) {
reject(error(400, 'Patch format syntax error:\n' + err + '\n'))
}
})
}
async function parsePatchDocument (targetURI, patchURI, patchText) {
const baseURI = patchURI.replace(/#.*/, '')
try {
return $rdf.sparqlUpdateParser(patchText, $rdf.graph(), baseURI)
} catch (err) {
throw error(400, `Patch document syntax error: ${err}`)
}
}