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 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);
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 = [
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 importStream = utils.createArrayStream(importQuads);
const removeStream = utils.createArrayStream(removeQuads);
await utils.waitForEvent(store.import(importStream), 'end', true);
await utils.waitForEvent(store.remove(removeStream), 'end', true);
const matchedQuads = await utils.streamToArray(store.match());
should(matchedQuads).have.length(1);
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);
});
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')
)
];
it('Shoud return the correct number of entries', async function () {
const ctx = this;
const store = ctx.store;
const quads = [];
for (let i = 0; i < 20; i++) {
quads.push(dataFactory.quad(
dataFactory.namedNode('http://ex.com/s' + i),
dataFactory.namedNode('http://ex.com/p' + i),
dataFactory.namedNode('http://ex.com/o' + i),
dataFactory.namedNode('http://ex.com/g' + i)
));
}
await store.put(quads);
const query = 'SELECT * WHERE { GRAPH ?g { ?s ?p ?o } }';
const bindings = await utils.streamToArray(await ctx.store.sparql(query));
should(bindings).have.length(20);
});
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);
});
});
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);
});
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 = [
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 importStream = utils.createArrayStream(importQuads);
const removeStream = utils.createArrayStream(removeQuads);
await utils.waitForEvent(store.import(importStream), 'end', true);
await utils.waitForEvent(store.remove(removeStream), 'end', true);
const matchedQuads = await utils.streamToArray(store.match());
should(matchedQuads).have.length(1);
});
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'),
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);
});