Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (id, env) => {
try {
env = options(env)
} catch (e) {
return Promise.reject(e)
}
const queries = sparqlQueries(id, env)
const simplify = wdk.simplifySparqlResults
return Promise.all(queries.map(
sparql => executeQuery(sparql, env).then(simplify).then(
results => results.map(row => {
['item', 'class'].forEach(field => {
if (typeof row[field] === 'string') {
row[field] = { value: row[field] }
}
})
return row
})
)
)).catch(e => {
throw new Error('SPARQL request failed')
})
.then(results => {
var executeQuery = function(sparql) {
var options = {
uri: env.endpoint,
qs: {
format: 'json',
query: sparql
}
}
if (env.post) options.method = 'POST'
if (env.user || env.password) {
options.auth = {}
if (env.user) options.auth.user = env.user
if (env.password) options.auth.password = env.password
}
return request(options).then(wdk.simplifySparqlResults)
};