Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should import a single quad correctly', async function () {
const store = this.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')
)
];
const source = utils.createArrayStream(quads);
await utils.waitForEvent(store.import(source), 'end', true);
const matchedQuads = await utils.streamToArray(store.match());
should(matchedQuads).have.length(1);
});
it('should import multiple quads correctly', async function () {
const store = this.store;
const quads = [
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p0'),
factory.literal('o0', 'en-gb'),
factory.namedNode('http://ex.com/g0')
),
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')
),
factory.quad(
factory.namedNode('http://ex.com/s2'),
factory.namedNode('http://ex.com/p2'),
factory.literal('o2', 'en-gb'),
factory.namedNode('http://ex.com/g3')
)
];
const source = utils.createArrayStream(quads);
await utils.waitForEvent(store.import(source), 'end', true);
const matchedQuads = await utils.streamToArray(store.match());
should(matchedQuads).have.length(3);
});
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p0'),
dataFactory.literal('1', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p1'),
dataFactory.literal('3', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p2'),
dataFactory.literal('5', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
)
];
await store.put(quads);
const query = 'SELECT * WHERE { GRAPH ?g { ?s ?p ?o. FILTER (?o >= 4) } }';
const bindings = await utils.streamToArray(await store.sparql(query));
should(bindings).have.length(2);
});
it('Should filter quads correctly by comparing integers', async function () {
const XSD = 'http://www.w3.org/2001/XMLSchema#';
const store = this.store;
const quads = [
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p3'),
dataFactory.literal('8', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p0'),
dataFactory.literal('1', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p1'),
dataFactory.literal('3', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p0'),
factory.literal('o0', 'en-gb'),
factory.namedNode('http://ex.com/g0')
),
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p1'),
factory.literal('o1', 'en-gb'),
factory.namedNode('http://ex.com/g1')
),
factory.quad(
factory.namedNode('http://ex.com/s2'),
factory.namedNode('http://ex.com/p1'),
factory.literal('o2', 'en-gb'),
factory.namedNode('http://ex.com/g1')
)
];
await store.put(quads);
await store.del({ subject: factory.namedNode('http://ex.com/s0') });
const foundQuads = await store.get({});
should(foundQuads).have.length(1);
});
});
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p3'),
dataFactory.literal('8', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p0'),
dataFactory.literal('1', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p1'),
dataFactory.literal('3', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p2'),
dataFactory.literal('5', `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
)
];
await store.put(quads);
const query = 'SELECT * WHERE { GRAPH ?g { ?s ?p ?o. FILTER (?o >= 4) } }';
const bindings = await utils.streamToArray(await store.sparql(query));
should(bindings).have.length(2);
});
it('Should delete matching quads correctly (callback).', async function () {
const store = this.store;
const quads = [
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p0'),
factory.literal('o0', 'en-gb'),
factory.namedNode('http://ex.com/g0')
),
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p1'),
factory.literal('o1', 'en-gb'),
factory.namedNode('http://ex.com/g1')
),
factory.quad(
factory.namedNode('http://ex.com/s2'),
factory.namedNode('http://ex.com/p1'),
factory.literal('o2', 'en-gb'),
factory.namedNode('http://ex.com/g1')
)
];
await store.put(quads);
it('Should filter quads correctly by comparing timestamps as integers', async function () {
const XSD = 'http://www.w3.org/2001/XMLSchema#';
const store = this.store;
const quads = [
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p2'),
dataFactory.literal(new Date('2017-01-02T00:00:00Z').valueOf(), `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p3'),
dataFactory.literal(new Date('2017-01-01T00:00:00Z').valueOf(), `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p0'),
dataFactory.literal(new Date('2017-01-01T12:00:00Z').valueOf(), `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
),
dataFactory.quad(
dataFactory.namedNode('http://ex.com/s0'),
dataFactory.namedNode('http://ex.com/p1'),
dataFactory.literal(new Date('2017-01-01T16:00:00Z').valueOf(), `${XSD}integer`),
dataFactory.namedNode('http://ex.com/g0')
)
];
await store.put(quads);
it('should remove matching quads correctly', async function () {
const store = this.store;
const importQuads = [
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p0'),
factory.literal('o0', 'en-gb'),
factory.namedNode('http://ex.com/g0')
),
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')
),
factory.quad(
factory.namedNode('http://ex.com/s2'),
factory.namedNode('http://ex.com/p2'),
factory.literal('o2', 'en-gb'),
factory.namedNode('http://ex.com/g1')
)
];
const importStream = utils.createArrayStream(importQuads);
await utils.waitForEvent(store.import(importStream), 'end', true);
await utils.waitForEvent(store.removeMatches(null, null, null, factory.namedNode('http://ex.com/g1')), 'end', true);
const matchedQuads = await utils.streamToArray(store.match());
should(matchedQuads).have.length(1);
});
});
it('should remove streamed quads correctly', async function () {
const store = this.store;
const importQuads = [
factory.quad(
factory.namedNode('http://ex.com/s0'),
factory.namedNode('http://ex.com/p0'),
factory.literal('o0', 'en-gb'),
factory.namedNode('http://ex.com/g0')
),
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')
),
factory.quad(
factory.namedNode('http://ex.com/s2'),
factory.namedNode('http://ex.com/p2'),
factory.literal('o2', 'en-gb'),
factory.namedNode('http://ex.com/g3')
)
];
const removeQuads = [