Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
user = await root.user;
}
catch (error) {
if (self.requireUser)
throw error;
return;
}
// Determine the storage location
const storage = await root.user.pim$storage;
const document = new URL(self.activitiesPath, storage || user).href;
// Obtain results for every activity on the path
const results = [];
const actor = namedNode(user);
type = namedNode(type);
for await (const object of path) {
if (object.termType === 'NamedNode') {
const activity = { actor, type, object };
for await (const result of self.createResults(activity, document, queryEngine))
results.push(result);
}
}
// Process all results and return paths starting from the returned terms
for (const term of await self.processResults(results, document, queryEngine))
yield root[term.value];
});
}
public static mapTerm(term: any): RDF.Term {
switch (term.termType) {
case 'NamedNode':
return namedNode(term.value);
case 'BlankNode':
return blankNode(term.value.substr(2)); // Remove the '_:' prefix.
case 'Literal':
return literal(term.value, term.language || term.datatype);
/*case 'Variable':
return variable(term.value);*/ // Variables can not occur in JSON-LD bodies
case 'DefaultGraph':
return defaultGraph();
}
}
if (blankMap[name]) {
name = blankMap[name];
} else {
if (variableNames.indexOf(name) >= 0) {
// increase index added to name until we find one that is available (2 loops at most)
let idx = 0;
while (variableNames.indexOf(name + idx) >= 0) {
++idx;
}
name = name + idx;
}
blankMap[term.value] = name;
variableNames.push(name);
}
changed = true;
return variable(name);
} else {
return term;
}
});
public static mapTerm(term: any): RDF.Term {
switch (term.termType) {
case 'NamedNode':
return namedNode(term.value);
case 'BlankNode':
return blankNode(term.value.substr(2)); // Remove the '_:' prefix.
case 'Literal':
return literal(term.value, term.language || term.datatype);
/*case 'Variable':
return variable(term.value);*/ // Variables can not occur in JSON-LD bodies
case 'DefaultGraph':
return defaultGraph();
}
}
public static mapTerm(term: any): RDF.Term {
switch (term.termType) {
case 'NamedNode':
return namedNode(term.value);
case 'BlankNode':
return blankNode(term.value.substr(2)); // Remove the '_:' prefix.
case 'Literal':
return literal(term.value, term.language || term.datatype);
/*case 'Variable':
return variable(term.value);*/ // Variables can not occur in JSON-LD bodies
case 'DefaultGraph':
return defaultGraph();
}
}
factory.quad(
factory.namedNode('http://ex.com/s'),
factory.namedNode('http://ex.com/p'),
factory.literal('o', 'en-gb'),
factory.namedNode('http://ex.com/g')
),
factory.quad(
factory.namedNode('http://ex.com/s'),
factory.namedNode('http://ex.com/p2'),
factory.literal('o', 'en-gb'),
factory.namedNode('http://ex.com/g')
)
];
const source = utils.createArrayStream(quads);
await utils.waitForEvent(store.import(source), 'end', true);
const predicate = factory.namedNode('http://ex.com/p2');
const matchedQuads = await utils.streamToArray(rs.match(null, predicate));
stripTermSerializedValue(matchedQuads);
should(matchedQuads).have.length(1);
should(matchedQuads[0]).deepEqual(quads[1]);
});
it('should match quads by the default graph (implicit)', async function () {
const store = this.store;
const rs = store;
const quads = [
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p0'),
factory.literal('o0', 'en-gb')
),
factory.quad(
factory.namedNode('http://ex.com/s1'),
factory.namedNode('http://ex.com/p1'),
factory.literal('o1', 'en-gb'),
factory.namedNode('http://ex.com/g1')
)
];
const source = utils.createArrayStream(quads);
await utils.waitForEvent(store.import(source), 'end', true);
const readStream = rs.match(null, null, null, factory.defaultGraph());
const matchedQuads = await utils.streamToArray(readStream);
stripTermSerializedValue(matchedQuads);
should(matchedQuads).have.length(1);
should(matchedQuads[0].graph).deepEqual(quads[0].graph);
});
factory.quad(
factory.namedNode('http://ex.com/s'),
factory.namedNode('http://ex.com/p'),
factory.literal('o', 'en-gb'),
factory.namedNode('http://ex.com/g')
),
factory.quad(
factory.namedNode('http://ex.com/s2'),
factory.namedNode('http://ex.com/p'),
factory.literal('o', 'en-gb'),
factory.namedNode('http://ex.com/g')
)
];
const source = utils.createArrayStream(quads);
await utils.waitForEvent(store.import(source), 'end', true);
const subject = factory.namedNode('http://ex.com/s2');
const matchedQuads = await utils.streamToArray(rs.match(subject));
stripTermSerializedValue(matchedQuads);
should(matchedQuads).have.length(1);
should(matchedQuads[0]).deepEqual(quads[1]);
});
it('should match quads by predicate', async function () {
const store = this.store;
const rs = store;
const quads = [
factory.quad(
factory.namedNode('http://ex.com/s'),
factory.namedNode('http://ex.com/p'),
factory.literal('o', 'en-gb'),
factory.namedNode('http://ex.com/g')
),
factory.quad(
factory.namedNode('http://ex.com/s'),
factory.namedNode('http://ex.com/p2'),
factory.literal('o', 'en-gb'),
factory.namedNode('http://ex.com/g')
)
];
const source = utils.createArrayStream(quads);
await utils.waitForEvent(store.import(source), 'end', true);
const predicate = factory.namedNode('http://ex.com/p2');
const matchedQuads = await utils.streamToArray(rs.match(null, predicate));
stripTermSerializedValue(matchedQuads);
should(matchedQuads).have.length(1);
should(matchedQuads[0]).deepEqual(quads[1]);
});
it('should match quads by subject', async function () {
const store = this.store;
const rs = store;
const quads = [
factory.quad(
factory.namedNode('http://ex.com/s'),
factory.namedNode('http://ex.com/p'),
factory.literal('o', 'en-gb'),
factory.namedNode('http://ex.com/g')
),
factory.quad(
factory.namedNode('http://ex.com/s2'),
factory.namedNode('http://ex.com/p'),
factory.literal('o', 'en-gb'),
factory.namedNode('http://ex.com/g')
)
];
const source = utils.createArrayStream(quads);
await utils.waitForEvent(store.import(source), 'end', true);
const subject = factory.namedNode('http://ex.com/s2');
const matchedQuads = await utils.streamToArray(rs.match(subject));
stripTermSerializedValue(matchedQuads);
should(matchedQuads).have.length(1);
should(matchedQuads[0]).deepEqual(quads[1]);
});