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];
});
}
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]);
});
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]);
});
async* createResults(activity, document) {
const id = namedNode(new URL(`#${uuid()}`, document).href);
const published = literal(new Date().toISOString(), `${xsd}dateTime`);
activity = { id, published, ...activity };
const insert = replaceVariables(activityTemplate, activity);
yield { id, insert };
}
resolve(property) {
return this._createSubjectPath(namedNode(property));
}
public static patternToCountQuery(pattern: RDF.Quad): string {
return toSparql(ActorRdfResolveQuadPatternSparqlJson.FACTORY.createProject(
ActorRdfResolveQuadPatternSparqlJson.FACTORY.createExtend(
ActorRdfResolveQuadPatternSparqlJson.FACTORY.createGroup(
ActorRdfResolveQuadPatternSparqlJson.patternToBgp(pattern),
[],
[ActorRdfResolveQuadPatternSparqlJson.FACTORY.createBoundAggregate(
variable('var0'),
'count',
ActorRdfResolveQuadPatternSparqlJson.FACTORY.createTermExpression(namedNode('*')),
false,
)],
),
variable('count'),
ActorRdfResolveQuadPatternSparqlJson.FACTORY.createTermExpression(variable('var0')),
),
[ variable('count') ],
));
}