Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { getCurrentResource } from 'platform/api/navigation';
import { ConfigHolder } from 'platform/api/services/config-holder';
import { isQuery, isTerm, isIri } from './TypeGuards';
// by default we initialized parser without prefixes so we don't need
// to initialize it explicitly in all tests, but the expectation is that
// in production run init is called on the system startup
let Parser: SparqlJs.SparqlParser = new SparqlJs.Parser();
export let RegisteredPrefixes: { [key: string]: string } = {};
export function init(registeredPrefixes: { [key: string]: string }) {
RegisteredPrefixes = registeredPrefixes;
Parser = new SparqlJs.Parser(registeredPrefixes);
}
const Generator = new SparqlJs.Generator();
export type RDFResultFormat = 'application/ld+json'
| 'application/n-quads'
| 'application/n-triples'
| 'application/rdf+json'
| 'application/rdf+xml'
| 'application/trig'
| 'application/trix'
| 'application/x-binary-rdf'
| 'application/x-trig'
| 'application/x-turtle'
| 'application/xml'
| 'text/n3'
| 'text/nquads'
| 'text/plain'
| 'text/rdf+n3'
function post (req, res) {
req.setTimeout(0) // no timeout
var graphUri = req.body.graph
const parser = new SparqlParser()
const generator = new SparqlGenerator()
var query
try {
query = parser.parse(req.body.query)
} catch (e) {
form(req, res, {
query: req.body.query,
graph: req.body.graph,
errors: [
e.stack
]
})
}
const queryString = generator.stringify(query)
function post (req, res) {
req.setTimeout(0) // no timeout
var graphUri
if (req.body.graph === 'user') {
graphUri = req.user.graphUri
} else {
graphUri = null
}
const parser = new SparqlParser()
const generator = new SparqlGenerator()
var query
try {
query = parser.parse(req.body.query)
} catch (e) {
form(req, res, {
query: req.body.query,
graph: req.body.graph,
errors: [
e.stack
]
})
return
}
import RemoteSparqlService from '../remote-sparql-service'
import {getPrefixesFromQuery} from '../query'
import _ from 'lodash'
import {Parser, Generator} from 'sparqljs'
const parser = new Parser()
const generator = new Generator()
const sparqlService = new RemoteSparqlService()
export default {
state: {
'query': '',
'isLoading': false,
outstandingQuery: undefined // Used to store query for aborting
},
getters: {
query: state => {
return state.query
},
isLoading: state => {
return state.isLoading
}
},
async function _req(backend, parsedQuery, accept, timeout, limit, chunkLimit, chunkOffset, data) {
parsedQuery.limit = chunkLimit;
parsedQuery.offset = chunkOffset;
const generator = SparqlGenerator();
const query = generator.stringify(parsedQuery);
const options = {
uri: backend,
form: {query},
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': accept,
},
json: true,
timeout
};
console.log("REQ limit=" + limit + ", chunkLimit=" + chunkLimit + ", chunkOffset=" + chunkOffset);
const {r, promise} = post(options);
let queryString = undefined;
if (useCase && useCase.generateQuery) {
const queryMask = {
type: "query",
queryType: "SELECT",
variables: ["?result", "?score"],
};
let useCaseQuery = {
...useCase.generateQuery(args, "?result"),
...queryMask,
};
if (useCaseQuery) {
const sparqlGenerator = new Generator();
queryString = useCaseQuery && sparqlGenerator.stringify(useCaseQuery);
}
}
const seeksContentNode = seeksContentUri
? buildSeeksContentNode(seeksContentUri, args.seeks)
: {};
const doNotMatchAfterFnOrLit = useCase && useCase.doNotMatchAfter;
const doNotMatchAfter = is("Function", doNotMatchAfterFnOrLit)
? doNotMatchAfterFnOrLit(
args,
{
"@graph": [seeksContentNode],
},
useCase && useCase.timeToLiveMillisDefault
function query (req, res, rawQuery, graphUri) {
graphUri = graphUri || null
const parser = new SparqlParser()
const generator = new SparqlGenerator()
var query
var queryString
if (rawQuery) {
try {
query = parser.parse(rawQuery)
} catch (e) {
res.status(500).send(e.stack)
return
}
queryString = generator.stringify(query)
try {
checkQuery(query, req.user)