Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
request.onload = function () {
// Convert the response into an iterator
var response = AsyncIterator.single(request.responseText || '');
response.statusCode = request.status;
// Parse the response headers
var resHeaders = response.headers = {},
rawHeaders = request.getAllResponseHeaders() || '',
headerMatcher = /^([^:\n\r]+):[ \t]*([^\r\n]*)$/mg, match;
while (match = headerMatcher.exec(rawHeaders))
resHeaders[match[1].toLowerCase()] = match[2];
// Emit the response
requestProxy.emit('response', response);
// If the resource was time-negotiated, store its queryless URI
// to enable the PERFORMANCE HACK explained above
if (reqHeaders['accept-datetime'] && resHeaders['memento-datetime']) {
var resource = removeQuery(resHeaders['content-location'] || settings.url);
_transform (bindings, done) {
let exists = false
// build an iterator to evaluate the EXISTS clause using the set of bindings
// using a LIMIT 1, to minimize the evaluation cost
const iterator = this._builder._buildWhere(single(bindings), this._groups, this._options).take(1)
iterator.on('error', err => this.emit('error', err))
iterator.on('end', () => {
if (exists && (!this._notexists)) {
// EXISTS case
this._push(bindings)
} else if ((!exists) && this._notexists) {
// NOT EXISTS case
this._push(bindings)
}
done()
})
iterator.on('data', () => {
exists = true
})
}
}
_buildQueryPlan (query, options = {}, source = null) {
if (_.isNull(source)) {
// build pipeline starting iterator
source = single({})
}
options.prefixes = query.prefixes
// rewrite a DESCRIBE query into a CONSTRUCT query
if (query.queryType === 'DESCRIBE') {
const template = []
const where = [{
type: 'bgp',
triples: []
}]
query.variables.forEach(v => {
const triple = rdf.triple(v, `?pred__describe__${v}`, `?obj__describe__${v}`)
template.push(triple)
where[0].triples.push(triple)
})
const construct = {
if (_.isNull(this._serviceExecutor)) {
throw new Error('A PlanBuilder cannot evaluate a SERVICE clause without a ServiceExecutor')
}
// delegate SERVICE evaluation to an executor
return this._serviceExecutor.buildIterator(source, group, childOptions)
case 'group':
return this._buildWhere(source, group.patterns, childOptions)
case 'optional':
// childOptions = _.assign({ optional: true }, options)
return new OptionalOperator(source, group.patterns, this, options)
case 'union':
return new UnionOperator(...group.patterns.map(patternToken => {
return this._buildGroup(source.clone(), patternToken, childOptions)
}))
case 'minus':
const rightSource = this._buildWhere(single({}), group.patterns, options)
return new MinusOperator(source, rightSource, options)
case 'filter':
// FILTERs (NOT) EXISTS are handled using dedicated operators
switch (group.expression.operator) {
case 'exists':
return new ExistsOperator(source, group.expression.args, this, false, options)
case 'notexists':
return new ExistsOperator(source, group.expression.args, this, true, options)
default:
return new FilterOperator(source, group.expression, childOptions)
}
case 'bind':
return new BindOperator(source, group.variable, group.expression, childOptions)
default:
throw new Error(`Unsupported SPARQL group pattern found in query: ${group.type}`)
}
function createPipeline(triplePattern) {
// Create the iterator for the triple pattern
var startIterator = AsyncIterator.single(bindings),
pipeline = new TriplePatternIterator(startIterator, triplePattern, options);
// If the chosen subpattern has more triples, create a ReorderingGraphPatternIterator for it
if (subPattern && subPattern.length !== 0)
pipeline = new ReorderingGraphPatternIterator(pipeline, subPattern, options);
// Create ReorderingGraphPatternIterators for all interconnected subpatterns
while (subPattern = subPatterns.pop())
pipeline = new ReorderingGraphPatternIterator(pipeline, subPattern, options);
return pipeline;
}
};
// Create an iterator that projects the bindings according to the query type
if (query.base != null) {
options.base = query.base
}
// Handles FROM clauses
if (query.from) {
options._from = query.from
}
// Handles WHERE clause
let graphIterator
if (query.patterns != null || (query.where != null && query.where.length > 0)) {
graphIterator = this._buildWhere(source, query.patterns || query.where, options)
} else {
graphIterator = single({})
}
// Parse query variable to separate projection & aggregate variables
if ('variables' in query) {
const [projection, aggregates] = _.partition(query.variables, v => _.isString(v))
// add aggregates variables to projection variables
query.variables = projection.concat(aggregates.map(agg => agg.variable))
query.aggregates = aggregates
}
// Handles Aggregates
graphIterator = this._aggExecutor.buildIterator(graphIterator, query, options)
// Handles transformers
if ('aggregates' in query) {
graphIterator = query.aggregates.reduce((iter, agg) => {
})).then(results => {
results.sort(sortPatterns)
iter.source = results.reduce((iter, v) => {
return new IndexJoinOperator(iter, v.triple, this, options)
}, single({}))
})
return iter