Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sparqlalgebrajs

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sparqlalgebrajs - npm Package Compare versions

Comparing version 0.7.7 to 0.7.8

45

lib/Factory.d.ts

@@ -7,3 +7,3 @@ import * as A from './algebra';

constructor(dataFactory?: RDF.DataFactory);
createAlt(left: A.Operation, right: A.Operation): A.Alt;
createAlt(left: A.PropertyPathSymbol, right: A.PropertyPathSymbol): A.Alt;
createAsk(input: A.Operation): A.Ask;

@@ -20,3 +20,3 @@ createBoundAggregate(variable: RDF.Variable, aggregate: string, expression: A.Expression, distinct: boolean, separator?: string): A.BoundAggregate;

createGroup(input: A.Operation, variables: RDF.Variable[], aggregates: A.BoundAggregate[]): A.Group;
createInv(path: A.Operation): A.Inv;
createInv(path: A.PropertyPathSymbol): A.Inv;
createJoin(left: A.Operation, right: A.Operation): A.Join;

@@ -27,9 +27,9 @@ createLeftJoin(left: A.Operation, right: A.Operation, expression?: A.Expression): A.LeftJoin;

createNps(iris: RDF.NamedNode[]): A.Nps;
createOneOrMorePath(path: A.Operation): A.OneOrMorePath;
createOneOrMorePath(path: A.PropertyPathSymbol): A.OneOrMorePath;
createOrderBy(input: A.Operation, expressions: A.Expression[]): A.OrderBy;
createPath(subject: RDF.Term, predicate: A.Operation, object: RDF.Term, graph?: RDF.Term): A.Path;
createPath(subject: RDF.Term, predicate: A.PropertyPathSymbol, object: RDF.Term, graph?: RDF.Term): A.Path;
createPattern(subject: RDF.Term, predicate: RDF.Term, object: RDF.Term, graph?: RDF.Term): A.Pattern;
createProject(input: A.Operation, variables: RDF.Variable[]): A.Project;
createReduced(input: A.Operation): A.Reduced;
createSeq(left: A.Operation, right: A.Operation): A.Seq;
createSeq(left: A.PropertyPathSymbol, right: A.PropertyPathSymbol): A.Seq;
createService(input: A.Operation, name: RDF.Term, silent?: boolean): A.Service;

@@ -41,4 +41,4 @@ createSlice(input: A.Operation, start: number, length?: number): A.Slice;

}[]): A.Values;
createZeroOrMorePath(path: A.Operation): A.ZeroOrMorePath;
createZeroOrOnePath(path: A.Operation): A.ZeroOrOnePath;
createZeroOrMorePath(path: A.PropertyPathSymbol): A.ZeroOrMorePath;
createZeroOrOnePath(path: A.PropertyPathSymbol): A.ZeroOrOnePath;
createAggregateExpression(aggregator: string, expression: A.Expression, distinct: boolean, separator?: string): A.AggregateExpression;

@@ -50,2 +50,33 @@ createExistenceExpression(not: boolean, input: A.Operation): A.ExistenceExpression;

createTerm(str: string): RDF.Term;
/**
* Creates a deep copy of the given Operation.
* Creates shallow copies of the non-Operation values.
* A map of callback functions can be provided for individual Operation types
* to specifically modify the given objects before triggering recursion.
* The return value of those callbacks should indicate whether recursion should be applied to this returned object or not.
* @param {Operation} op - The Operation to recurse on.
* @param { [type: string]: (op: Operation) => RecurseResult } callbacks - A map of required callback Operations.
* @returns {Operation} - The copied result.
*/
mapOperation(op: A.Operation, callbacks: {
[type: string]: (op: A.Operation) => RecurseResult;
}): A.Operation;
/**
* Similar to the {@link mapOperation} function but specifically for expressions.
* Both functions call each other while copying.
* Should not be called directly since it does not execute the callbacks, these happen in {@link mapOperation}.
* @param {Expression} expr - The Operation to recurse on.
* @param { [type: string]: (op: Operation) => RecurseResult } callbacks - A map of required callback Operations.
* @returns {Operation} - The copied result.
*/
private mapExpression(expr, callbacks);
}
/**
* @interface RecurseResult
* @property {Operation} result - The resulting A.Operation.
* @property {boolean} recurse - Whether to continue with recursion.
*/
export interface RecurseResult {
result: A.Operation;
recurse: boolean;
}

@@ -5,2 +5,3 @@ "use strict";

const rdf_string_1 = require("rdf-string");
const algebra_1 = require("./algebra");
const defaultGraph = { termType: 'DefaultGraph', value: '' };

@@ -81,4 +82,152 @@ class Factory {

}
/**
* Creates a deep copy of the given Operation.
* Creates shallow copies of the non-Operation values.
* A map of callback functions can be provided for individual Operation types
* to specifically modify the given objects before triggering recursion.
* The return value of those callbacks should indicate whether recursion should be applied to this returned object or not.
* @param {Operation} op - The Operation to recurse on.
* @param { [type: string]: (op: Operation) => RecurseResult } callbacks - A map of required callback Operations.
* @returns {Operation} - The copied result.
*/
mapOperation(op, callbacks) {
let result = op;
let doRecursion = true;
if (callbacks[op.type])
({ result, recurse: doRecursion } = callbacks[op.type](op));
if (!doRecursion)
return result;
let mapOp = (op) => this.mapOperation(op, callbacks);
switch (result.type) {
case algebra_1.types.ALT:
const alt = result;
return this.createAlt(mapOp(alt.left), mapOp(alt.right));
case algebra_1.types.ASK:
const ask = result;
return this.createAsk(mapOp(ask.input));
case algebra_1.types.BGP:
const bgp = result;
return this.createBgp(bgp.patterns.map(mapOp));
case algebra_1.types.CONSTRUCT:
const construct = result;
return this.createConstruct(mapOp(construct.input), construct.template.map(mapOp));
case algebra_1.types.DESCRIBE:
const describe = result;
return this.createDescribe(mapOp(describe.input), describe.terms);
case algebra_1.types.DISTINCT:
const distinct = result;
return this.createDistinct(mapOp(distinct.input));
case algebra_1.types.EXPRESSION:
const expr = result;
return this.mapExpression(expr, callbacks);
case algebra_1.types.EXTEND:
const extend = result;
return this.createExtend(mapOp(extend.input), extend.variable, mapOp(extend.expression));
case algebra_1.types.FILTER:
const filter = result;
return this.createFilter(mapOp(filter.input), mapOp(filter.expression));
case algebra_1.types.FROM:
const from = result;
return this.createFrom(mapOp(from.input), [].concat(from.default), [].concat(from.named));
case algebra_1.types.GRAPH:
const graph = result;
return this.createGraph(mapOp(graph.input), graph.name);
case algebra_1.types.GROUP:
const group = result;
return this.createGroup(mapOp(group.input), [].concat(group.variables), group.aggregates.map(mapOp));
case algebra_1.types.INV:
const inv = result;
return this.createInv(mapOp(inv.path));
case algebra_1.types.JOIN:
const join = result;
return this.createJoin(mapOp(join.left), mapOp(join.right));
case algebra_1.types.LEFT_JOIN:
const leftJoin = result;
return this.createLeftJoin(mapOp(leftJoin.left), mapOp(leftJoin.right), leftJoin.expression ? mapOp(leftJoin.expression) : undefined);
case algebra_1.types.LINK:
const link = result;
return this.createLink(link.iri);
case algebra_1.types.MINUS:
const minus = result;
return this.createMinus(mapOp(minus.left), mapOp(minus.right));
case algebra_1.types.NPS:
const nps = result;
return this.createNps([].concat(nps.iris));
case algebra_1.types.ONE_OR_MORE_PATH:
const oom = result;
return this.createOneOrMorePath(mapOp(oom.path));
case algebra_1.types.ORDER_BY:
const order = result;
return this.createOrderBy(mapOp(order.input), order.expressions.map(mapOp));
case algebra_1.types.PATH:
const path = result;
return this.createPath(path.subject, mapOp(path.predicate), path.object, path.graph);
case algebra_1.types.PATTERN:
const pattern = result;
return this.createPattern(pattern.subject, pattern.predicate, pattern.object, pattern.graph);
case algebra_1.types.PROJECT:
const project = result;
return this.createProject(mapOp(project.input), [].concat(project.variables));
case algebra_1.types.REDUCED:
const reduced = result;
return this.createReduced(mapOp(reduced.input));
case algebra_1.types.SEQ:
const seq = result;
return this.createSeq(mapOp(seq.left), mapOp(seq.right));
case algebra_1.types.SERVICE:
const service = result;
return this.createService(mapOp(service.input), service.name, service.silent);
case algebra_1.types.SLICE:
const slice = result;
return this.createSlice(mapOp(slice.input), slice.start, slice.length);
case algebra_1.types.UNION:
const union = result;
return this.createUnion(mapOp(union.left), mapOp(union.right));
case algebra_1.types.VALUES:
const values = result;
return this.createValues([].concat(values.variables), values.bindings.map(b => Object.assign({}, b)));
case algebra_1.types.ZERO_OR_MORE_PATH:
const zom = result;
return this.createZeroOrMorePath(mapOp(zom.path));
case algebra_1.types.ZERO_OR_ONE_PATH:
const zoo = result;
return this.createZeroOrOnePath(mapOp(zoo.path));
default: throw new Error('Unknown Operation type ' + result.type);
}
}
/**
* Similar to the {@link mapOperation} function but specifically for expressions.
* Both functions call each other while copying.
* Should not be called directly since it does not execute the callbacks, these happen in {@link mapOperation}.
* @param {Expression} expr - The Operation to recurse on.
* @param { [type: string]: (op: Operation) => RecurseResult } callbacks - A map of required callback Operations.
* @returns {Operation} - The copied result.
*/
mapExpression(expr, callbacks) {
let recurse = (op) => this.mapOperation(op, callbacks);
switch (expr.expressionType) {
case algebra_1.expressionTypes.AGGREGATE:
if (expr.variable) {
const bound = expr;
return this.createBoundAggregate(bound.variable, bound.aggregator, recurse(bound.expression), bound.distinct, bound.separator);
}
const aggregate = expr;
return this.createAggregateExpression(aggregate.aggregator, recurse(aggregate.expression), aggregate.distinct, aggregate.separator);
case algebra_1.expressionTypes.EXISTENCE:
const exist = expr;
return this.createExistenceExpression(exist.not, recurse(exist.input));
case algebra_1.expressionTypes.NAMED:
const named = expr;
return this.createNamedExpression(named.name, named.args.map(recurse));
case algebra_1.expressionTypes.OPERATOR:
const op = expr;
return this.createOperatorExpression(op.operator, op.args.map(recurse));
case algebra_1.expressionTypes.TERM:
const term = expr;
return this.createTermExpression(term.term);
default: throw new Error('Unknown Expression type ' + expr.expressionType);
}
}
}
exports.default = Factory;
//# sourceMappingURL=Factory.js.map

12

package.json
{
"name": "sparqlalgebrajs",
"version": "0.7.7",
"version": "0.7.8",
"description": "Convert SPARQL to SPARL algebra",

@@ -20,15 +20,15 @@ "author": "Joachim Van Herwegen",

"devDependencies": {
"@types/chai": "^4.1.2",
"@types/chai": "^4.1.4",
"@types/lodash.isequal": "^4.5.2",
"@types/minimist": "^1.2.0",
"@types/mocha": "^2.2.48",
"@types/node": "^8.0.50",
"@types/node": "^8.10.20",
"@types/rdf-data-model": "^1.0.1",
"@types/rdf-js": "^1.0.1",
"chai": "^4.1.2",
"mocha": "^3.5.3",
"mocha": "^5.2.0",
"nyc": "^12.0.2",
"pre-commit": "^1.2.2",
"ts-node": "^6.1.2",
"typescript": "^2.5.3"
"ts-node": "^6.2.0",
"typescript": "^2.9.2"
},

@@ -35,0 +35,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc