Debian Codegraph @

test/N3Store-test.js

raw
1 import {
2 Store,
3 NamedNode,
4 Literal,
5 DefaultGraph,
6 Quad,
7 termFromId, termToId,
8 } from '../src/';
9 import namespaces from '../src/IRIs';
10 import chai, { expect } from 'chai';
11 import { Readable } from 'readable-stream';
12 import arrayifyStream from 'arrayify-stream';
13
14 const should = chai.should();
15
16 describe('Store', () => {
17 describe('The Store export', () => {
18 it('should be a function', () => {
19 Store.should.be.a('function');
20 });
21
22 it('should be an Store constructor', () => {
23 new Store().should.be.an.instanceof(Store);
24 });
25 });
26
27 describe('An empty Store', () => {
28 const store = new Store({});
29
30 it('should have size 0', () => {
31 expect(store.size).to.eql(0);
32 });
33
34 it('should be empty', () => {
35 store.getQuads().should.be.empty;
36 });
37
38 describe('when importing a stream of 2 quads', () => {
39 before(done => {
40 const stream = new ArrayReader([
41 new Quad(new NamedNode('s1'), new NamedNode('p2'), new NamedNode('o2')),
42 new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')),
43 ]);
44 const events = store.import(stream);
45 events.on('end', done);
46 });
47
48 it('should have size 2', () => { store.size.should.eql(2); });
49 });
50
51 describe('when removing a stream of 2 quads', () => {
52 before(done => {
53 const stream = new ArrayReader([
54 new Quad(new NamedNode('s1'), new NamedNode('p2'), new NamedNode('o2')),
55 new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')),
56 ]);
57 const events = store.remove(stream);
58 events.on('end', done);
59 });
60
61 it('should have size 0', () => { store.size.should.eql(0); });
62 });
63
64 describe('when importing a stream of 2 nested quads', () => {
65 before(done => {
66 const stream = new ArrayReader([
67 new Quad(new Quad(new NamedNode('s1'), new NamedNode('p2'), new NamedNode('o2')), new NamedNode('p2'), new NamedNode('o2')),
68 new Quad(new NamedNode('s1'), new NamedNode('p1'), new Quad(new NamedNode('s1'), new NamedNode('p2'), new NamedNode('o2'))),
69 ]);
70 const events = store.import(stream);
71 events.on('end', done);
72 });
73
74 it('should have size 2', () => { store.size.should.eql(2); });
75 });
76
77 describe('when removing a stream of 2 nested quads', () => {
78 before(done => {
79 const stream = new ArrayReader([
80 new Quad(new Quad(new NamedNode('s1'), new NamedNode('p2'), new NamedNode('o2')), new NamedNode('p2'), new NamedNode('o2')),
81 new Quad(new NamedNode('s1'), new NamedNode('p1'), new Quad(new NamedNode('s1'), new NamedNode('p2'), new NamedNode('o2'))),
82 ]);
83 const events = store.remove(stream);
84 events.on('end', done);
85 });
86
87 it('should have size 0', () => { store.size.should.eql(0); });
88 });
89
90 describe('every', () => {
91 describe('with no parameters and a callback always returning true', () => {
92 it('should return false', () => {
93 store.every(alwaysTrue, null, null, null, null).should.be.false;
94 });
95 });
96 describe('with no parameters and a callback always returning false', () => {
97 it('should return false', () => {
98 store.every(alwaysFalse, null, null, null, null).should.be.false;
99 });
100 });
101 });
102
103 describe('some', () => {
104 describe('with no parameters and a callback always returning true', () => {
105 it('should return false', () => {
106 store.some(alwaysTrue, null, null, null, null).should.be.false;
107 });
108 });
109 describe('with no parameters and a callback always returning false', () => {
110 it('should return false', () => {
111 store.some(alwaysFalse, null, null, null, null).should.be.false;
112 });
113 });
114 });
115
116 it('should still have size 0 (instead of null) after adding and removing a triple', () => {
117 expect(store.size).to.eql(0);
118 store.addQuad(new NamedNode('a'), new NamedNode('b'), new NamedNode('c')).should.be.true;
119 store.removeQuad(new NamedNode('a'), new NamedNode('b'), new NamedNode('c')).should.be.true;
120 expect(store.size).to.eql(0);
121 });
122
123 it('should be able to generate unnamed blank nodes', () => {
124 store.createBlankNode().value.should.eql('b0');
125 store.createBlankNode().value.should.eql('b1');
126
127 store.addQuad('_:b0', '_:b1', '_:b2').should.be.true;
128 store.createBlankNode().value.should.eql('b3');
129 store.removeQuads(store.getQuads());
130 });
131
132 it('should be able to generate named blank nodes', () => {
133 store.createBlankNode('blank').value.should.eql('blank');
134 store.createBlankNode('blank').value.should.eql('blank1');
135 store.createBlankNode('blank').value.should.eql('blank2');
136 });
137
138 it('should be able to store triples with generated blank nodes', () => {
139 store.addQuad(store.createBlankNode('x'), new NamedNode('b'), new NamedNode('c')).should.be.true;
140 shouldIncludeAll(store.getQuads(null, new NamedNode('b')), ['_:x', 'b', 'c'])();
141 store.removeQuads(store.getQuads());
142 });
143 });
144
145 describe('A Store with initialized with 5 elements', () => {
146 const store = new Store([
147 new Quad(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')), new NamedNode('p1'), new NamedNode('o1')),
148 new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')),
149 new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o2')),
150 new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o3')),
151 new Quad(new NamedNode('s2'), new NamedNode('p2'), new NamedNode('o2'), new NamedNode('g1')),
152 ]);
153
154 it('should have size 5', () => {
155 store.size.should.eql(5);
156 });
157
158 describe('adding a triple that already exists', () => {
159 it('should return false', () => {
160 store.addQuad('s1', 'p1', 'o1').should.be.false;
161 });
162
163 it('should not increase the size', () => {
164 store.size.should.eql(5);
165 });
166
167 it('should return false', () => {
168 store.addQuad(new Quad('s1', 'p1', 'o1'), 'p1', 'o1').should.be.false;
169 });
170
171 it('should not increase the size', () => {
172 store.size.should.eql(5);
173 });
174 });
175
176 describe('adding a triple that did not exist yet', () => {
177 it('should return true', () => {
178 store.has(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o4'))).should.be.false;
179 store.has(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o4')).should.be.false;
180 store.has(null, null, new NamedNode('o4')).should.be.false;
181
182 store.addQuad('s1', 'p1', 'o4').should.be.true;
183
184 store.has(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o4'))).should.be.true;
185 store.has(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o4')).should.be.true;
186 store.has(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o4'), new DefaultGraph()).should.be.true;
187 store.has(null, null, new NamedNode('o4')).should.be.true;
188 });
189
190 it('should increase the size', () => {
191 store.size.should.eql(6);
192 });
193
194 it('should return true', () => {
195 store.addQuad(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')), 'p1', 'o4').should.be.true;
196 });
197
198 it('should increase the size', () => {
199 store.size.should.eql(7);
200 });
201
202 it('should return self', () => {
203 should.equal(store.add(new Quad(new NamedNode('s2'), new NamedNode('p2'), new NamedNode('o2'))), store);
204 });
205
206 it('should increase the size', () => {
207 store.size.should.eql(8);
208 });
209 });
210
211 describe('removing an existing triple', () => {
212 it('should return true', () => {
213 store.removeQuad('s1', 'p1', 'o4').should.be.true;
214 });
215
216 it('should decrease the size', () => {
217 store.size.should.eql(7);
218 });
219
220 it('should return true', () => {
221 store.removeQuad(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')), 'p1', 'o4').should.be.true;
222 });
223
224 it('should decrease the size', () => {
225 store.size.should.eql(6);
226 });
227
228 it('should return self', () => {
229 should.equal(store.delete(new Quad(new NamedNode('s2'), new NamedNode('p2'), new NamedNode('o2'))), store);
230 });
231
232 it('should increase the size', () => {
233 store.size.should.eql(5);
234 });
235 });
236
237 describe('removing a non-existing triple', () => {
238 it('should return false', () => {
239 store.removeQuad('s1', 'p1', 'o5').should.be.false;
240 });
241
242 it('should not decrease the size', () => {
243 store.size.should.eql(5);
244 });
245
246 it('should return false', () => {
247 store.removeQuad(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o4')), 'p1', 'o1').should.be.false;
248 });
249
250 it('should not decrease the size', () => {
251 store.size.should.eql(5);
252 });
253 });
254
255 describe('removing matching quads', () => {
256 it('should return the removed quads',
257 forResultStream(shouldIncludeAll, () => { return store.removeMatches('s1', 'p1'); },
258 ['s1', 'p1', 'o1'],
259 ['s1', 'p1', 'o2'],
260 ['s1', 'p1', 'o3']));
261
262 it('should decrease the size', () => {
263 store.size.should.eql(2);
264 });
265 });
266
267 describe('removing a graph', () => {
268 it('should return the removed quads',
269 forResultStream(shouldIncludeAll, () => { return store.deleteGraph('g1'); },
270 ['s2', 'p2', 'o2', 'g1']));
271
272 it('should decrease the size', () => {
273 store.size.should.eql(1);
274 });
275 });
276 });
277
278 describe('removing matching quads for RDF*', () => {
279 let store;
280 beforeEach(() => {
281 store = new Store([
282 new Quad(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')), new NamedNode('p2'), new NamedNode('o1')),
283 new Quad(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')), new NamedNode('p1'), new NamedNode('o1')),
284 new Quad(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')), new NamedNode('p2'), new NamedNode('o2')),
285 new Quad(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')), new NamedNode('p1'), new NamedNode('o2')),
286 new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o2')),
287 ]);
288 });
289
290 it('should return the removed quads',
291 forResultStream(shouldIncludeAll, () => { return store.removeMatches(null, 'p2', 'o2'); },
292 [termToId(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1'))), 'p2', 'o2']));
293
294 it('should decrease the size', () => {
295 store.size.should.eql(5);
296 });
297
298 it('should match RDF* and normal quads at the same time', done => {
299 const stream = store.removeMatches(null, 'p1', 'o2');
300 stream.on('end', () => {
301 store.size.should.eql(3);
302 done();
303 });
304 });
305
306 it('should allow matching using a quad', done => {
307 const stream = store.removeMatches(termToId(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1'))));
308 stream.on('end', () => {
309 store.size.should.eql(1);
310 done();
311 });
312 });
313 });
314
315 describe('A Store with 7 elements', () => {
316 const store = new Store();
317 store.addQuad('s1', 'p1', 'o1').should.be.true;
318 store.addQuad({ subject: 's1', predicate: 'p1', object: 'o2' }).should.be.true;
319 store.addQuads([
320 { subject: 's1', predicate: 'p2', object: 'o2' },
321 { subject: 's2', predicate: 'p1', object: 'o1' },
322 ]);
323 store.addQuad('s1', 'p1', 'o1', 'c4').should.be.true;
324 store.addQuad(new Quad('s2', 'p2', 'o2'), 'p1', 'o3');
325 should.equal(store.add(new Quad('s2', 'p2', 'o2')), store);
326
327 it('should have size 7', () => {
328 store.size.should.eql(7);
329 });
330
331 describe('when searched without parameters', () => {
332 it('should return all items',
333 shouldIncludeAll(store.getQuads(),
334 ['s1', 'p1', 'o1'],
335 ['s1', 'p1', 'o2'],
336 ['s1', 'p2', 'o2'],
337 ['s2', 'p1', 'o1'],
338 ['s1', 'p1', 'o1', 'c4'],
339 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3'],
340 ['s2', 'p2', 'o2']));
341 });
342
343 describe('when searched with an existing subject parameter', () => {
344 it('should return all items with this subject in all graphs',
345 shouldIncludeAll(store.getQuads(new NamedNode('s1'), null, null),
346 ['s1', 'p1', 'o1'],
347 ['s1', 'p1', 'o2'],
348 ['s1', 'p2', 'o2'],
349 ['s1', 'p1', 'o1', 'c4']));
350 });
351
352 describe('when searched with a non-existing subject parameter', () => {
353 itShouldBeEmpty(store.getQuads(new NamedNode('s3'), null, null));
354 });
355
356 describe('when searched with a non-existing subject parameter that exists elsewhere', () => {
357 itShouldBeEmpty(store.getQuads(new NamedNode('p1'), null, null));
358 });
359
360 describe('when searched with an existing predicate parameter', () => {
361 it('should return all items with this predicate in all graphs',
362 shouldIncludeAll(store.getQuads(null, new NamedNode('p1'), null),
363 ['s1', 'p1', 'o1'],
364 ['s1', 'p1', 'o2'],
365 ['s2', 'p1', 'o1'],
366 ['s1', 'p1', 'o1', 'c4'],
367 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3']));
368 });
369
370 describe('when searched with a non-existing predicate parameter', () => {
371 itShouldBeEmpty(store.getQuads(null, new NamedNode('p3'), null));
372 });
373
374 describe('when searched with an existing object parameter', () => {
375 it('should return all items with this object in all graphs',
376 shouldIncludeAll(store.getQuads(null, null, new NamedNode('o1')),
377 ['s1', 'p1', 'o1'],
378 ['s2', 'p1', 'o1'],
379 ['s1', 'p1', 'o1', 'c4']));
380 });
381
382 describe('when searched with a non-existing object parameter', () => {
383 itShouldBeEmpty(store.getQuads(null, null, new NamedNode('o4')));
384 });
385
386 describe('when searched with existing subject and predicate parameters', () => {
387 it('should return all items with this subject and predicate in all graphs',
388 shouldIncludeAll(store.getQuads(new NamedNode('s1'), new NamedNode('p1'), null),
389 ['s1', 'p1', 'o1'],
390 ['s1', 'p1', 'o2'],
391 ['s1', 'p1', 'o1', 'c4']));
392 });
393
394 describe('when searched with non-existing subject and predicate parameters', () => {
395 itShouldBeEmpty(store.getQuads(new NamedNode('s2'), new NamedNode('p3'), null));
396 });
397
398 describe('when searched with existing subject and object parameters', () => {
399 it('should return all items with this subject and object in all graphs',
400 shouldIncludeAll(store.getQuads(new NamedNode('s1'), null, new NamedNode('o1')),
401 ['s1', 'p1', 'o1'],
402 ['s1', 'p1', 'o1', 'c4']));
403 });
404
405 describe('when searched with non-existing subject and object parameters', () => {
406 itShouldBeEmpty(store.getQuads(new NamedNode('s2'), null, new NamedNode('o3')));
407 });
408
409 describe('when searched with existing predicate and object parameters', () => {
410 it('should return all items with this predicate and object in all graphs',
411 shouldIncludeAll(store.getQuads(null, new NamedNode('p1'), new NamedNode('o1')),
412 ['s1', 'p1', 'o1'],
413 ['s2', 'p1', 'o1'],
414 ['s1', 'p1', 'o1', 'c4']));
415 });
416
417 describe('when searched with non-existing predicate and object parameters in the default graph', () => {
418 itShouldBeEmpty(store.getQuads(null, new NamedNode('p2'), new NamedNode('o3'), new DefaultGraph()));
419 });
420
421 describe('when searched with existing subject, predicate, and object parameters', () => {
422 it('should return all items with this subject, predicate, and object in all graphs',
423 shouldIncludeAll(store.getQuads(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')),
424 ['s1', 'p1', 'o1'],
425 ['s1', 'p1', 'o1', 'c4']));
426 });
427
428 describe('when searched with a non-existing triple', () => {
429 itShouldBeEmpty(store.getQuads(new NamedNode('s2'), new NamedNode('p2'), new NamedNode('o1')));
430 });
431
432 describe('when searched with the default graph parameter', () => {
433 it('should return all items in the default graph',
434 shouldIncludeAll(store.getQuads(null, null, null, new DefaultGraph()),
435 ['s1', 'p1', 'o1'],
436 ['s1', 'p1', 'o2'],
437 ['s1', 'p2', 'o2'],
438 ['s2', 'p1', 'o1'],
439 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3'],
440 ['s2', 'p2', 'o2']));
441 });
442
443 describe('when searched with an existing named graph parameter', () => {
444 it('should return all items in that graph',
445 shouldIncludeAll(store.getQuads(null, null, null, new NamedNode('c4')),
446 ['s1', 'p1', 'o1', 'c4']));
447 });
448
449 describe('when searched with a non-existing named graph parameter', () => {
450 itShouldBeEmpty(store.getQuads(null, null, null, new NamedNode('c5')));
451 });
452
453 describe('match', () => {
454 describe('without parameters', () => {
455 it('should return an object implementing the DatasetCore interface', () => {
456 const dataset = store.match();
457
458 dataset.add.should.be.a('function');
459 dataset.delete.should.be.a('function');
460 dataset.has.should.be.a('function');
461 dataset.match.should.be.a('function');
462 dataset[Symbol.iterator].should.be.a('function');
463 });
464
465 it('should return an object implementing the Readable stream interface', () => {
466 const stream = store.match();
467
468 stream.addListener.should.be.a('function');
469 stream.emit.should.be.a('function');
470 should.equal(stream.propertyIsEnumerable('destroyed'), false);
471 stream.destroyed.should.equal(false);
472 stream.destroy.should.be.a('function');
473 stream.eventNames.should.be.a('function');
474 stream.getMaxListeners.should.be.a('function');
475 stream.listenerCount.should.be.a('function');
476 stream.listeners.should.be.a('function');
477 stream.isPaused.should.be.a('function');
478 should.equal(stream.isPaused(), false);
479 stream.off.should.be.a('function');
480 stream.on.should.be.a('function');
481 stream.once.should.be.a('function');
482 stream.pause.should.be.a('function');
483 stream.pipe.should.be.a('function');
484 stream.prependListener.should.be.a('function');
485 stream.prependOnceListener.should.be.a('function');
486 stream.rawListeners.should.be.a('function');
487 stream.read.should.be.a('function');
488 stream.readable.should.equal(true);
489 should.equal(stream.propertyIsEnumerable('readableBuffer'), false);
490 should.exist(stream.readableBuffer);
491 // Readable from 'readable-stream' does not implement the `readableEncoding` property.
492 // stream.readableEncoding.should.equal(???);
493 // Readable from 'readable-stream' does not implement the `readableEnded` property.
494 // stream.readableEnded.should.equal(false);
495 should.equal(stream.propertyIsEnumerable('readableFlowing'), false);
496 should.equal(stream.readableFlowing, null);
497 should.equal(stream.propertyIsEnumerable('readableHighWaterMark'), false);
498 stream.readableHighWaterMark.should.equal(16);
499 should.equal(stream.propertyIsEnumerable('readableLength'), false);
500 stream.readableLength.should.equal(0);
501 // Readable from 'readable-stream' does not implement the `readableObjectMode` property.
502 // stream.readableObjectMode.should.equal(true);
503 stream.removeAllListeners.should.be.a('function');
504 stream.removeListener.should.be.a('function');
505 stream.resume.should.be.a('function');
506 stream.setEncoding.should.be.a('function');
507 stream.setMaxListeners.should.be.a('function');
508 stream.unpipe.should.be.a('function');
509 stream.unshift.should.be.a('function');
510 stream.wrap.should.be.a('function');
511 stream[Symbol.asyncIterator].should.be.a('function');
512 });
513
514 it('should return all items',
515 forResultStream(shouldIncludeAll, store.match(),
516 ['s1', 'p1', 'o1'],
517 ['s1', 'p1', 'o2'],
518 ['s1', 'p2', 'o2'],
519 ['s2', 'p1', 'o1'],
520 ['s1', 'p1', 'o1', 'c4'],
521 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3'],
522 ['s2', 'p2', 'o2']));
523 });
524
525 describe('with an existing subject parameter', () => {
526 it('should return all items with this subject in all graphs',
527 forResultStream(shouldIncludeAll, store.match(new NamedNode('s1'), null, null),
528 ['s1', 'p1', 'o1'],
529 ['s1', 'p1', 'o2'],
530 ['s1', 'p2', 'o2'],
531 ['s1', 'p1', 'o1', 'c4']));
532
533 it('should return an object implementing the DatasetCore interface', () => {
534 const subject = new NamedNode('s1');
535 const dataset = store.match(subject, null, null);
536
537 let count = 0;
538 for (const quad of dataset) {
539 count += 1;
540 should.equal(quad.subject.equals(subject), true);
541 }
542
543 should.equal(count, 4);
544 should.equal(dataset.size, count);
545
546 should.equal(dataset.has(new Quad('s2', 'p1', 'o1')), false);
547 dataset.add(new Quad('s2', 'p1', 'o1'));
548
549 count = 0;
550 // eslint-disable-next-line no-unused-vars
551 for (const _quad of dataset) {
552 count += 1;
553 }
554 should.equal(count, 5);
555
556 should.equal(dataset.has(new Quad('s2', 'p1', 'o1')), true);
557
558 const nextDataset = dataset.match(new NamedNode('s2'));
559 nextDataset.add(new Quad('s2', 'p2', 'o2'));
560
561 count = 0;
562 // eslint-disable-next-line no-unused-vars
563 for (const _quad of nextDataset) {
564 count += 1;
565 }
566 should.equal(count, 2);
567
568 should.equal(nextDataset.has(new Quad('s2', 'p1', 'o1')), true);
569 should.equal(nextDataset.has(new Quad('s2', 'p2', 'o2')), true);
570
571 nextDataset.delete(new Quad('s2', 'p1', 'o1'));
572 nextDataset.delete(new Quad('s2', 'p2', 'o2'));
573 should.equal(nextDataset.has(new Quad('s2', 'p1', 'o1')), false);
574 should.equal(nextDataset.has(new Quad('s2', 'p2', 'o2')), false);
575 });
576 });
577
578 describe('with non-existing predicate and object parameters in the default graph', () => {
579 forResultStream(itShouldBeEmpty, store.match(null, new NamedNode('p2'), new NamedNode('o3'), new DefaultGraph()));
580 });
581 });
582
583 describe('getSubjects', () => {
584 describe('with existing predicate, object and graph parameters', () => {
585 it('should return all subjects with this predicate, object and graph', () => {
586 store.getSubjects(new NamedNode('p1'), new NamedNode('o1'), new NamedNode('c4')).should.have.deep.members([new NamedNode('s1')]);
587 });
588 });
589
590 describe('with existing predicate and object parameters', () => {
591 it('should return all subjects with this predicate and object', () => {
592 store.getSubjects(new NamedNode('p2'), new NamedNode('o2'), null).should.have.deep.members([new NamedNode('s1'), new NamedNode('s2')]);
593 });
594 });
595
596 describe('with existing predicate and graph parameters', () => {
597 it('should return all subjects with this predicate and graph', () => {
598 store.getSubjects(new NamedNode('p1'), null, new DefaultGraph()).should.have.deep.members([new NamedNode('s1'), new NamedNode('s2'), new Quad(new NamedNode('s2'), new NamedNode('p2'), new NamedNode('o2'))]);
599 });
600 });
601
602 describe('with existing object and graph parameters', () => {
603 it('should return all subjects with this object and graph', () => {
604 store.getSubjects(null, new NamedNode('o1'), new DefaultGraph()).should.have.deep.members([new NamedNode('s1'), new NamedNode('s2')]);
605 });
606 });
607
608 describe('with an existing predicate parameter', () => {
609 it('should return all subjects with this predicate', () => {
610 store.getSubjects(new NamedNode('p1'), null, null).should.have.deep.members([new NamedNode('s1'), new NamedNode('s2'), new Quad(new NamedNode('s2'), new NamedNode('p2'), new NamedNode('o2'))]);
611 });
612 });
613
614 describe('with an existing object parameter', () => {
615 it('should return all subjects with this object', () => {
616 store.getSubjects(null, new NamedNode('o1'), null).should.have.deep.members([new NamedNode('s1'), new NamedNode('s2')]);
617 });
618 });
619
620 describe('with an existing graph parameter', () => {
621 it('should return all subjects in the graph', () => {
622 store.getSubjects(null, null, new NamedNode('c4')).should.have.deep.members([new NamedNode('s1')]);
623 });
624 });
625
626 describe('with no parameters', () => {
627 it('should return all subjects', () => {
628 store.getSubjects(null, null, null).should.have.deep.members([new NamedNode('s1'), new NamedNode('s2'), new Quad(new NamedNode('s2'), new NamedNode('p2'), new NamedNode('o2'))]);
629 });
630 });
631 });
632
633 describe('getPredicates', () => {
634 describe('with existing subject, object and graph parameters', () => {
635 it('should return all predicates with this subject, object and graph', () => {
636 store.getPredicates(new NamedNode('s1'), new NamedNode('o1'), new NamedNode('c4')).should.have.deep.members([new NamedNode('p1')]);
637 });
638 });
639
640 describe('with existing subject and object parameters', () => {
641 it('should return all predicates with this subject and object', () => {
642 store.getPredicates(new NamedNode('s1'), new NamedNode('o2'), null).should.have.deep.members([new NamedNode('p1'), new NamedNode('p2')]);
643 });
644 });
645
646 describe('with existing subject and graph parameters', () => {
647 it('should return all predicates with this subject and graph', () => {
648 store.getPredicates(new NamedNode('s1'), null, new DefaultGraph()).should.have.deep.members([new NamedNode('p1'), new NamedNode('p2')]);
649 });
650 });
651
652 describe('with existing object and graph parameters', () => {
653 it('should return all predicates with this object and graph', () => {
654 store.getPredicates(null, new NamedNode('o1'), new DefaultGraph()).should.have.deep.members([new NamedNode('p1')]);
655 });
656 });
657
658 describe('with an existing subject parameter', () => {
659 it('should return all predicates with this subject', () => {
660 store.getPredicates(new NamedNode('s2'), null, null).should.have.deep.members([new NamedNode('p1'), new NamedNode('p2')]);
661 });
662 });
663
664 describe('with an existing object parameter', () => {
665 it('should return all predicates with this object', () => {
666 store.getPredicates(null, new NamedNode('o1'), null).should.have.deep.members([new NamedNode('p1')]);
667 });
668 });
669
670 describe('with an existing graph parameter', () => {
671 it('should return all predicates in the graph', () => {
672 store.getPredicates(null, null, new NamedNode('c4')).should.have.deep.members([new NamedNode('p1')]);
673 });
674 });
675
676 describe('with no parameters', () => {
677 it('should return all predicates', () => {
678 store.getPredicates(null, null, null).should.have.deep.members([new NamedNode('p1'), new NamedNode('p2')]);
679 });
680 });
681 });
682
683 describe('getObjects', () => {
684 describe('with existing subject, predicate and graph parameters', () => {
685 it('should return all objects with this subject, predicate and graph', () => {
686 store.getObjects(new NamedNode('s1'), new NamedNode('p1'), new DefaultGraph()).should.have.deep.members([new NamedNode('o1'), new NamedNode('o2')]);
687 });
688 });
689
690 describe('with existing subject and predicate parameters', () => {
691 it('should return all objects with this subject and predicate', () => {
692 store.getObjects(new NamedNode('s1'), new NamedNode('p1'), null).should.have.deep.members([new NamedNode('o1'), new NamedNode('o2')]);
693 });
694 });
695
696 describe('with existing subject and graph parameters', () => {
697 it('should return all objects with this subject and graph', () => {
698 store.getObjects(new NamedNode('s1'), null, new DefaultGraph()).should.have.deep.members([new NamedNode('o1'), new NamedNode('o2')]);
699 });
700 });
701
702 describe('with existing predicate and graph parameters', () => {
703 it('should return all objects with this predicate and graph', () => {
704 store.getObjects(null, new NamedNode('p1'), new DefaultGraph()).should.have.deep.members([new NamedNode('o1'), new NamedNode('o2'), new NamedNode('o3')]);
705 });
706 });
707
708 describe('with an existing subject parameter', () => {
709 it('should return all objects with this subject', () => {
710 store.getObjects(new NamedNode('s1'), null, null).should.have.deep.members([new NamedNode('o1'), new NamedNode('o2')]);
711 });
712 });
713
714 describe('with an existing predicate parameter', () => {
715 it('should return all objects with this predicate', () => {
716 store.getObjects(null, new NamedNode('p1'), null).should.have.deep.members([new NamedNode('o1'), new NamedNode('o2'), new NamedNode('o3')]);
717 });
718 });
719
720 describe('with an existing graph parameter', () => {
721 it('should return all objects in the graph', () => {
722 store.getObjects(null, null, new NamedNode('c4')).should.have.deep.members([new NamedNode('o1')]);
723 });
724 });
725
726 describe('with no parameters', () => {
727 it('should return all objects', () => {
728 store.getObjects(null, null, null).should.have.deep.members([new NamedNode('o1'), new NamedNode('o2'), new NamedNode('o3')]);
729 });
730 });
731 });
732
733 describe('getGraphs', () => {
734 describe('with existing subject, predicate and object parameters', () => {
735 it('should return all graphs with this subject, predicate and object', () => {
736 store.getGraphs(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')).should.have.deep.members([new NamedNode('c4'), new DefaultGraph()]);
737 });
738 });
739
740 describe('with existing subject and predicate parameters', () => {
741 it('should return all graphs with this subject and predicate', () => {
742 store.getGraphs(new NamedNode('s1'), new NamedNode('p1'), null).should.have.deep.members([new NamedNode('c4'), new DefaultGraph()]);
743 });
744 });
745
746 describe('with existing subject and object parameters', () => {
747 it('should return all graphs with this subject and object', () => {
748 store.getGraphs(new NamedNode('s1'), null, new NamedNode('o2')).should.have.deep.members([new DefaultGraph()]);
749 });
750 });
751
752 describe('with existing predicate and object parameters', () => {
753 it('should return all graphs with this predicate and object', () => {
754 store.getGraphs(null, new NamedNode('p1'), new NamedNode('o1')).should.have.deep.members([new DefaultGraph(), new NamedNode('c4')]);
755 });
756 });
757
758 describe('with an existing subject parameter', () => {
759 it('should return all graphs with this subject', () => {
760 store.getGraphs(new NamedNode('s1'), null, null).should.have.deep.members([new NamedNode('c4'), new DefaultGraph()]);
761 });
762 });
763
764 describe('with an existing predicate parameter', () => {
765 it('should return all graphs with this predicate', () => {
766 store.getGraphs(null, new NamedNode('p1'), null).should.have.deep.members([new NamedNode('c4'), new DefaultGraph()]);
767 });
768 });
769
770 describe('with an existing object parameter', () => {
771 it('should return all graphs with this object', () => {
772 store.getGraphs(null, null, new NamedNode('o2')).should.have.deep.members([new DefaultGraph()]);
773 });
774 });
775
776 describe('with no parameters', () => {
777 it('should return all graphs', () => {
778 store.getGraphs(null, null, null).should.have.deep.members([new NamedNode('c4'), new DefaultGraph()]);
779 });
780 });
781 });
782
783 describe('forEach', () => {
784 describe('with existing subject, predicate, object and graph parameters', () => {
785 it('should have iterated all items with this subject, predicate, object and graph',
786 shouldIncludeAll(collect(store, 'forEach', 's1', 'p1', 'o2', ''),
787 ['s1', 'p1', 'o2', '']));
788 });
789
790 describe('with existing subject, predicate and object parameters', () => {
791 it('should have iterated all items with this subject, predicate and object',
792 shouldIncludeAll(collect(store, 'forEach', 's1', 'p2', 'o2', null),
793 ['s1', 'p2', 'o2', '']));
794 });
795
796 describe('with existing subject, predicate and graph parameters', () => {
797 it('should have iterated all items with this subject, predicate and graph',
798 shouldIncludeAll(collect(store, 'forEach', 's1', 'p1', null, ''),
799 ['s1', 'p1', 'o1', ''],
800 ['s1', 'p1', 'o2', '']));
801 });
802
803 describe('with existing subject, object and graph parameters', () => {
804 it('should have iterated all items with this subject, object and graph',
805 shouldIncludeAll(collect(store, 'forEach', 's1', null, 'o2', ''),
806 ['s1', 'p1', 'o2', ''],
807 ['s1', 'p2', 'o2', '']));
808 });
809
810 describe('with existing predicate, object and graph parameters', () => {
811 it('should have iterated all items with this predicate, object and graph',
812 shouldIncludeAll(collect(store, 'forEach', null, 'p1', 'o1', ''),
813 ['s1', 'p1', 'o1', ''],
814 ['s2', 'p1', 'o1', '']));
815 });
816
817 describe('with existing subject and predicate parameters', () => {
818 it('should iterate all items with this subject and predicate',
819 shouldIncludeAll(collect(store, 'forEach', 's1', 'p1', null, null),
820 ['s1', 'p1', 'o1', ''],
821 ['s1', 'p1', 'o2', ''],
822 ['s1', 'p1', 'o1', 'c4']));
823 });
824
825 describe('with existing subject and object parameters', () => {
826 it('should iterate all items with this subject and predicate',
827 shouldIncludeAll(collect(store, 'forEach', 's1', null, 'o2', null),
828 ['s1', 'p1', 'o2', ''],
829 ['s1', 'p2', 'o2', '']));
830 });
831
832 describe('with existing subject and graph parameters', () => {
833 it('should iterate all items with this subject and graph',
834 shouldIncludeAll(collect(store, 'forEach', 's1', null, null, 'c4'),
835 ['s1', 'p1', 'o1', 'c4']));
836 });
837
838 describe('with existing predicate and object parameters', () => {
839 it('should iterate all items with this predicate and object',
840 shouldIncludeAll(collect(store, 'forEach', null, 'p1', 'o1', null),
841 ['s1', 'p1', 'o1', ''],
842 ['s2', 'p1', 'o1', ''],
843 ['s1', 'p1', 'o1', 'c4']));
844 });
845
846 describe('with existing predicate and graph parameters', () => {
847 it('should iterate all items with this predicate and graph',
848 shouldIncludeAll(collect(store, 'forEach', null, 'p1', null, ''),
849 ['s1', 'p1', 'o1', ''],
850 ['s1', 'p1', 'o2', ''],
851 ['s2', 'p1', 'o1', ''],
852 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3', '']));
853 });
854
855 describe('with existing object and graph parameters', () => {
856 it('should iterate all items with this object and graph',
857 shouldIncludeAll(collect(store, 'forEach', null, null, 'o1', ''),
858 ['s1', 'p1', 'o1', ''],
859 ['s2', 'p1', 'o1', '']));
860 });
861
862 describe('with an existing subject parameter', () => {
863 it('should iterate all items with this subject',
864 shouldIncludeAll(collect(store, 'forEach', 's2', null, null, null),
865 ['s2', 'p1', 'o1', ''],
866 ['s2', 'p2', 'o2', '']));
867 });
868
869 describe('with an existing predicate parameter', () => {
870 it('should iterate all items with this predicate',
871 shouldIncludeAll(collect(store, 'forEach', null, 'p1', null, null),
872 ['s1', 'p1', 'o1', ''],
873 ['s1', 'p1', 'o2', ''],
874 ['s2', 'p1', 'o1', ''],
875 ['s1', 'p1', 'o1', 'c4'],
876 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3', '']));
877 });
878
879 describe('with an existing object parameter', () => {
880 it('should iterate all items with this object',
881 shouldIncludeAll(collect(store, 'forEach', null, null, 'o1', null),
882 ['s1', 'p1', 'o1', ''],
883 ['s2', 'p1', 'o1', ''],
884 ['s1', 'p1', 'o1', 'c4']));
885 });
886
887 describe('with an existing graph parameter', () => {
888 it('should iterate all items with this graph',
889 shouldIncludeAll(collect(store, 'forEach', null, null, null, ''),
890 ['s1', 'p1', 'o1'],
891 ['s1', 'p1', 'o2'],
892 ['s1', 'p2', 'o2'],
893 ['s2', 'p1', 'o1'],
894 ['s2', 'p2', 'o2'],
895 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3', '']));
896 });
897
898 describe('with no parameters', () => {
899 it('should iterate all items',
900 shouldIncludeAll(collect(store, 'forEach', null, null, null, null),
901 ['s1', 'p1', 'o1'],
902 ['s1', 'p1', 'o2'],
903 ['s1', 'p2', 'o2'],
904 ['s2', 'p1', 'o1'],
905 ['s2', 'p2', 'o2'],
906 ['s1', 'p1', 'o1', 'c4'],
907 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3', '']));
908 });
909 });
910
911 describe('forSubjects', () => {
912 describe('with existing predicate, object and graph parameters', () => {
913 it('should iterate all subjects with this predicate, object and graph', () => {
914 collect(store, 'forSubjects', 'p1', 'o1', '').should.have.deep.members([new NamedNode('s1'), new NamedNode('s2')]);
915 });
916 });
917 describe('with a non-existing predicate', () => {
918 it('should be empty', () => {
919 collect(store, 'forSubjects', 'p3', null, null).should.be.empty;
920 });
921 });
922 describe('with a non-existing object', () => {
923 it('should be empty', () => {
924 collect(store, 'forSubjects', null, 'o4', null).should.be.empty;
925 });
926 });
927 describe('with a non-existing graph', () => {
928 it('should be empty', () => {
929 collect(store, 'forSubjects', null, null, 'g2').should.be.empty;
930 });
931 });
932 });
933
934 describe('forPredicates', () => {
935 describe('with existing subject, object and graph parameters', () => {
936 it('should iterate all predicates with this subject, object and graph', () => {
937 collect(store, 'forPredicates', 's1', 'o2', '').should.have.deep.members([new NamedNode('p1'), new NamedNode('p2')]);
938 });
939 });
940 describe('with a non-existing subject', () => {
941 it('should be empty', () => {
942 collect(store, 'forPredicates', 's3', null, null).should.be.empty;
943 });
944 });
945 describe('with a non-existing object', () => {
946 it('should be empty', () => {
947 collect(store, 'forPredicates', null, 'o4', null).should.be.empty;
948 });
949 });
950 describe('with a non-existing graph', () => {
951 it('should be empty', () => {
952 collect(store, 'forPredicates', null, null, 'g2').should.be.empty;
953 });
954 });
955 });
956
957 describe('forObjects', () => {
958 describe('with existing subject, predicate and graph parameters', () => {
959 it('should iterate all objects with this subject, predicate and graph', () => {
960 collect(store, 'forObjects', 's1', 'p1', '').should.have.deep.members([new NamedNode('o1'), new NamedNode('o2')]);
961 });
962 });
963 describe('with a non-existing subject', () => {
964 it('should be empty', () => {
965 collect(store, 'forObjects', 's3', null, null).should.be.empty;
966 });
967 });
968 describe('with a non-existing predicate', () => {
969 it('should be empty', () => {
970 collect(store, 'forObjects', null, 'p3', null).should.be.empty;
971 });
972 });
973 describe('with a non-existing graph', () => {
974 it('should be empty', () => {
975 collect(store, 'forObjects', null, null, 'g2').should.be.empty;
976 });
977 });
978 });
979
980 describe('forGraphs', () => {
981 describe('with existing subject, predicate and object parameters', () => {
982 it('should iterate all graphs with this subject, predicate and object', () => {
983 collect(store, 'forGraphs', 's1', 'p1', 'o1').should.have.deep.members([new DefaultGraph(), new NamedNode('c4')]);
984 });
985 });
986 describe('with a non-existing subject', () => {
987 it('should be empty', () => {
988 collect(store, 'forObjects', 's3', null, null).should.be.empty;
989 });
990 });
991 describe('with a non-existing predicate', () => {
992 it('should be empty', () => {
993 collect(store, 'forObjects', null, 'p3', null).should.be.empty;
994 });
995 });
996 describe('with a non-existing graph', () => {
997 it('should be empty', () => {
998 collect(store, 'forPredicates', null, null, 'g2').should.be.empty;
999 });
1000 });
1001 });
1002
1003 describe('every', () => {
1004 let count = 3;
1005 function thirdTimeFalse() { return count-- === 0; }
1006
1007 describe('with no parameters and a callback always returning true', () => {
1008 it('should return true', () => {
1009 store.every(alwaysTrue, null, null, null, null).should.be.true;
1010 });
1011 });
1012 describe('with no parameters and a callback always returning false', () => {
1013 it('should return false', () => {
1014 store.every(alwaysFalse, null, null, null, null).should.be.false;
1015 });
1016 });
1017 describe('with no parameters and a callback that returns false after 3 calls', () => {
1018 it('should return false', () => {
1019 store.every(thirdTimeFalse, null, null, null, null).should.be.false;
1020 });
1021 });
1022 });
1023
1024 describe('some', () => {
1025 let count = 3;
1026 function thirdTimeFalse() { return count-- !== 0; }
1027
1028 describe('with no parameters and a callback always returning true', () => {
1029 it('should return true', () => {
1030 store.some(alwaysTrue, null, null, null, null).should.be.true;
1031 });
1032 });
1033 describe('with no parameters and a callback always returning false', () => {
1034 it('should return false', () => {
1035 store.some(alwaysFalse, null, null, null, null).should.be.false;
1036 });
1037 });
1038 describe('with no parameters and a callback that returns true after 3 calls', () => {
1039 it('should return false', () => {
1040 store.some(thirdTimeFalse, null, null, null, null).should.be.true;
1041 });
1042 });
1043 describe('with a non-existing subject', () => {
1044 it('should return true', () => {
1045 store.some(null, new NamedNode('s3'), null, null, null).should.be.false;
1046 });
1047 });
1048 describe('with a non-existing predicate', () => {
1049 it('should return false', () => {
1050 store.some(null, null, new NamedNode('p3'), null, null).should.be.false;
1051 });
1052 });
1053 describe('with a non-existing object', () => {
1054 it('should return false', () => {
1055 store.some(null, null, null, new NamedNode('o4'), null).should.be.false;
1056 });
1057 });
1058 describe('with a non-existing graph', () => {
1059 it('should return false', () => {
1060 store.some(null, null, null, null, new NamedNode('g2')).should.be.false;
1061 });
1062 });
1063 });
1064
1065 describe('when destructured', () => {
1066 it('should destructure all quads',
1067 shouldIncludeAll(
1068 () => {
1069 const [a, b, c, d, e, f, g] = store;
1070 return [a, b, c, d, e, f, g];
1071 },
1072 ['s1', 'p1', 'o1'],
1073 ['s1', 'p1', 'o2'],
1074 ['s1', 'p2', 'o2'],
1075 ['s2', 'p1', 'o1'],
1076 ['s2', 'p2', 'o2'],
1077 ['s1', 'p1', 'o1', 'c4'],
1078 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3']));
1079 });
1080
1081 describe('when iterated with for...of', () => {
1082 it('should iterate over all quads', () => {
1083 let count = 0;
1084 // eslint-disable-next-line no-unused-vars
1085 for (const quad of store) {
1086 count += 1;
1087 }
1088 should.equal(count, 7);
1089 });
1090 });
1091
1092 describe('when spread', () => {
1093 it('should spread all quads',
1094 shouldIncludeAll(
1095 [...store],
1096 ['s1', 'p1', 'o1'],
1097 ['s1', 'p1', 'o2'],
1098 ['s1', 'p2', 'o2'],
1099 ['s2', 'p1', 'o1'],
1100 ['s1', 'p1', 'o1', 'c4'],
1101 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3'],
1102 ['s2', 'p2', 'o2']));
1103 });
1104
1105 describe('when yield starred', () => {
1106 it('should yield all quads',
1107 shouldIncludeAll(
1108 () => {
1109 function* yieldAll() {
1110 yield* store;
1111 }
1112 return Array.from(yieldAll());
1113 },
1114 ['s1', 'p1', 'o1'],
1115 ['s1', 'p1', 'o2'],
1116 ['s1', 'p2', 'o2'],
1117 ['s2', 'p1', 'o1'],
1118 ['s2', 'p2', 'o2'],
1119 ['s1', 'p1', 'o1', 'c4'],
1120 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3']));
1121 });
1122
1123 describe('when counted without parameters', () => {
1124 it('should count all items in all graphs', () => {
1125 store.countQuads().should.equal(7);
1126 });
1127 });
1128
1129 describe('when counted with an existing subject parameter', () => {
1130 it('should count all items with this subject in all graphs', () => {
1131 store.countQuads(new NamedNode('s1'), null, null).should.equal(4);
1132 });
1133 });
1134
1135 describe('when counted with a non-existing subject parameter', () => {
1136 it('should be empty', () => {
1137 store.countQuads(new NamedNode('s3'), null, null).should.equal(0);
1138 });
1139 });
1140
1141 describe('when counted with a non-existing subject parameter that exists elsewhere', () => {
1142 it('should be empty', () => {
1143 store.countQuads(new NamedNode('p1'), null, null).should.equal(0);
1144 });
1145 });
1146
1147 describe('when counted with an existing predicate parameter', () => {
1148 it('should count all items with this predicate in all graphs', () => {
1149 store.countQuads(null, new NamedNode('p1'), null).should.equal(5);
1150 });
1151 });
1152
1153 describe('when counted with a non-existing predicate parameter', () => {
1154 it('should be empty', () => {
1155 store.countQuads(null, new NamedNode('p3'), null).should.equal(0);
1156 });
1157 });
1158
1159 describe('when counted with an existing object parameter', () => {
1160 it('should count all items with this object in all graphs', () => {
1161 store.countQuads(null, null, 'o1').should.equal(3);
1162 });
1163 });
1164
1165 describe('when counted with a non-existing object parameter', () => {
1166 it('should be empty', () => {
1167 store.countQuads(null, null, 'o4').should.equal(0);
1168 });
1169 });
1170
1171 describe('when counted with existing subject and predicate parameters', () => {
1172 it('should count all items with this subject and predicate in all graphs', () => {
1173 store.countQuads('s1', 'p1', null).should.equal(3);
1174 });
1175 });
1176
1177 describe('when counted with non-existing subject and predicate parameters', () => {
1178 it('should be empty', () => {
1179 store.countQuads('s2', 'p3', null).should.equal(0);
1180 });
1181 });
1182
1183 describe('when counted with existing subject and object parameters', () => {
1184 it('should count all items with this subject and object in all graphs', () => {
1185 store.countQuads('s1', null, 'o1').should.equal(2);
1186 });
1187 });
1188
1189 describe('when counted with non-existing subject and object parameters', () => {
1190 it('should be empty', () => {
1191 store.countQuads('s2', null, 'o3').should.equal(0);
1192 });
1193 });
1194
1195 describe('when counted with existing predicate and object parameters', () => {
1196 it('should count all items with this predicate and object in all graphs', () => {
1197 store.countQuads(null, 'p1', 'o1').should.equal(3);
1198 });
1199 });
1200
1201 describe('when counted with non-existing predicate and object parameters', () => {
1202 it('should be empty', () => {
1203 store.countQuads(null, 'p2', 'o3').should.equal(0);
1204 });
1205 });
1206
1207 describe('when counted with existing subject, predicate, and object parameters', () => {
1208 it('should count all items with this subject, predicate, and object in all graphs', () => {
1209 store.countQuads('s1', 'p1', 'o1').should.equal(2);
1210 });
1211 });
1212
1213 describe('when counted with a non-existing triple', () => {
1214 it('should be empty', () => {
1215 store.countQuads('s2', 'p2', 'o1').should.equal(0);
1216 });
1217 });
1218
1219 describe('when counted with the default graph parameter', () => {
1220 it('should count all items in the default graph', () => {
1221 store.countQuads(null, null, null, new DefaultGraph()).should.equal(6);
1222 });
1223 });
1224
1225 describe('when counted with an existing named graph parameter', () => {
1226 it('should count all items in that graph', () => {
1227 store.countQuads(null, null, null, 'c4').should.equal(1);
1228 });
1229 });
1230
1231 describe('when counted with a non-existing named graph parameter', () => {
1232 it('should be empty', () => {
1233 store.countQuads(null, null, null, 'c5').should.equal(0);
1234 });
1235 });
1236
1237 describe('when trying to remove a triple with a non-existing subject', () => {
1238 before(() => { store.removeQuad(new NamedNode('s0'), new NamedNode('p1'), new NamedNode('o1')).should.be.false; });
1239 it('should still have size 7', () => { store.size.should.eql(7); });
1240 });
1241
1242 describe('when trying to remove a triple with a non-existing predicate', () => {
1243 before(() => { store.removeQuad(new NamedNode('s1'), new NamedNode('p0'), new NamedNode('o1')).should.be.false; });
1244 it('should still have size 7', () => { store.size.should.eql(7); });
1245 });
1246
1247 describe('when trying to remove a triple with a non-existing object', () => {
1248 before(() => { store.removeQuad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o0')).should.be.false; });
1249 it('should still have size 7', () => { store.size.should.eql(7); });
1250 });
1251
1252 describe('when trying to remove a triple for which no subjects exist', () => {
1253 before(() => { store.removeQuad(new NamedNode('o1'), new NamedNode('p1'), new NamedNode('o1')).should.be.false; });
1254 it('should still have size 7', () => { store.size.should.eql(7); });
1255 });
1256
1257 describe('when trying to remove a triple for which no predicates exist', () => {
1258 before(() => { store.removeQuad(new NamedNode('s1'), new NamedNode('s1'), new NamedNode('o1')).should.be.false; });
1259 it('should still have size 7', () => { store.size.should.eql(7); });
1260 });
1261
1262 describe('when trying to remove a triple for which no objects exist', () => {
1263 before(() => { store.removeQuad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('s1')).should.be.false; });
1264 it('should still have size 7', () => { store.size.should.eql(7); });
1265 });
1266
1267 describe('when trying to remove a triple that does not exist', () => {
1268 before(() => { store.removeQuad(new NamedNode('s1'), new NamedNode('p2'), new NamedNode('o1')).should.be.false; });
1269 it('should still have size 7', () => { store.size.should.eql(7); });
1270 });
1271
1272 describe('when trying to remove an incomplete triple', () => {
1273 before(() => { store.removeQuad(new NamedNode('s1'), null, null).should.be.false; });
1274 it('should still have size 7', () => { store.size.should.eql(7); });
1275 });
1276
1277 describe('when trying to remove a triple with a non-existing graph', () => {
1278 before(() => { store.removeQuad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1'), new NamedNode('c0')).should.be.false; });
1279 it('should still have size 7', () => { store.size.should.eql(7); });
1280 });
1281
1282 describe('when removing an existing triple', () => {
1283 before(() => { store.removeQuad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')).should.be.true; });
1284
1285 it('should have size 6', () => { store.size.should.eql(6); });
1286
1287 it('should not contain that triple anymore',
1288 shouldIncludeAll(() => { return store.getQuads(); },
1289 ['s1', 'p1', 'o2'],
1290 ['s1', 'p2', 'o2'],
1291 ['s2', 'p1', 'o1'],
1292 ['s2', 'p2', 'o2'],
1293 ['s1', 'p1', 'o1', 'c4'],
1294 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3', '']));
1295 });
1296
1297 describe('when removing an existing triple from a named graph', () => {
1298 before(() => { store.removeQuad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1'), new NamedNode('c4')).should.be.true; });
1299
1300 it('should have size 5', () => { store.size.should.eql(5); });
1301
1302 itShouldBeEmpty(() => { return store.getQuads(null, null, null, 'c4'); });
1303 });
1304
1305 describe('when removing multiple triples', () => {
1306 before(() => {
1307 store.removeQuads([
1308 new Quad(new NamedNode('s1'), new NamedNode('p2'), new NamedNode('o2')),
1309 new Quad(new NamedNode('s2'), new NamedNode('p1'), new NamedNode('o1')),
1310 ]);
1311 });
1312
1313 it('should have size 3', () => { store.size.should.eql(3); });
1314
1315 it('should not contain those triples anymore',
1316 shouldIncludeAll(() => { return store.getQuads(); },
1317 ['s1', 'p1', 'o2'],
1318 ['s2', 'p2', 'o2'],
1319 [termToId(new Quad('s2', 'p2', 'o2')), 'p1', 'o3', '']));
1320 });
1321
1322 describe('when adding and removing a triple', () => {
1323 before(() => {
1324 store.addQuad(new NamedNode('a'), new NamedNode('b'), new NamedNode('c')).should.be.true;
1325 store.removeQuad(new NamedNode('a'), new NamedNode('b'), new NamedNode('c')).should.be.true;
1326 });
1327
1328 it('should have an unchanged size', () => { store.size.should.eql(3); });
1329 });
1330 });
1331
1332 describe('A Store containing a blank node', () => {
1333 const store = new Store();
1334 const b1 = store.createBlankNode();
1335 store.addQuad(new NamedNode('s1'), new NamedNode('p1'), b1).should.be.true;
1336
1337 describe('when searched with more than one variable', () => {
1338 it('should return a triple with the blank node as an object',
1339 shouldIncludeAll(store.getQuads(),
1340 ['s1', 'p1', `_:${b1.value}`]));
1341 });
1342
1343 describe('when searched with one variable', () => {
1344 it('should return a triple with the blank node as an object',
1345 shouldIncludeAll(store.getQuads('s1', 'p1'),
1346 ['s1', 'p1', `_:${b1.value}`]));
1347 });
1348 });
1349
1350 describe('A Store with a custom DataFactory', () => {
1351 const factory = {};
1352 let store;
1353 before(() => {
1354 factory.quad = function (s, p, o, g) { return { s: s, p: p, o: o, g: g }; };
1355 ['namedNode', 'blankNode', 'literal', 'variable', 'defaultGraph'].forEach(f => {
1356 factory[f] = function (n) { return n ? `${f[0]}-${n}` : f; };
1357 });
1358
1359 store = new Store({ factory: factory });
1360 store.addQuad('s1', 'p1', 'o1').should.be.true;
1361 store.addQuad({ subject: 's1', predicate: 'p1', object: 'o2' }).should.be.true;
1362 store.addQuads([
1363 { subject: 's1', predicate: 'p2', object: 'o2' },
1364 { subject: 's2', predicate: 'p1', object: 'o1' },
1365 ]);
1366 store.addQuad('s1', 'p1', 'o1', 'c4').should.be.true;
1367 });
1368
1369 it('should use the factory when returning quads', () => {
1370 store.getQuads().should.deep.equal([
1371 { s: 'n-s1', p: 'n-p1', o: 'n-o1', g: 'defaultGraph' },
1372 { s: 'n-s1', p: 'n-p1', o: 'n-o2', g: 'defaultGraph' },
1373 { s: 'n-s1', p: 'n-p2', o: 'n-o2', g: 'defaultGraph' },
1374 { s: 'n-s2', p: 'n-p1', o: 'n-o1', g: 'defaultGraph' },
1375 { s: 'n-s1', p: 'n-p1', o: 'n-o1', g: 'n-c4' },
1376 ]);
1377 });
1378 });
1379
1380 describe('A Store', () => {
1381 const store = new Store();
1382
1383 it('should implement the DatasetCore interface', () => {
1384 store.add.should.be.a('function');
1385 store.delete.should.be.a('function');
1386 store.has.should.be.a('function');
1387 store.match.should.be.a('function');
1388 store[Symbol.iterator].should.be.a('function');
1389 });
1390
1391 // Test inspired by http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/.
1392 // The value `__proto__` is not supported however – fixing it introduces too much overhead.
1393 it('should be able to contain entities with JavaScript object property names', () => {
1394 store.addQuad('toString', 'valueOf', 'toLocaleString', 'hasOwnProperty').should.be.true;
1395 shouldIncludeAll(store.getQuads(null, null, null, 'hasOwnProperty'),
1396 ['toString', 'valueOf', 'toLocaleString', 'hasOwnProperty'])();
1397 });
1398
1399 it('should be able to contain entities named "null"', () => {
1400 store.addQuad('null', 'null', 'null', 'null').should.be.true;
1401 shouldIncludeAll(store.getQuads(null, null, null, 'null'), ['null', 'null', 'null', 'null'])();
1402 });
1403 });
1404
1405 describe('A Store containing a well-formed rdf:Collection as subject', () => {
1406 const store = new Store();
1407 const listElements = addList(store, new NamedNode('element1'), new Literal('"element2"'));
1408 store.addQuad(listElements[0], new NamedNode('p1'), new NamedNode('o1')).should.be.true;
1409 const listItemsJSON = {
1410 b0: [
1411 { termType: 'NamedNode', value: 'element1' },
1412 { termType: 'Literal', value: 'element2',
1413 language: '', datatype: { termType: 'NamedNode', value: namespaces.xsd.string } },
1414 ],
1415 };
1416
1417 describe('extractLists without remove', () => {
1418 const lists = store.extractLists();
1419 it('should not delete triples',
1420 shouldIncludeAll(store.getQuads(),
1421 [`_:${listElements[0].value}`, 'p1', 'o1'],
1422 [`_:${listElements[0].value}`, namespaces.rdf.first, 'element1'],
1423 [`_:${listElements[0].value}`, namespaces.rdf.rest, `_:${listElements[1].value}`],
1424 [`_:${listElements[1].value}`, namespaces.rdf.first, '"element2"'],
1425 [`_:${listElements[1].value}`, namespaces.rdf.rest, namespaces.rdf.nil]
1426 ));
1427 it('should generate a list of Collections', () => {
1428 expect(listsToJSON(lists)).to.deep.equal(listItemsJSON);
1429 });
1430 });
1431
1432 describe('extractLists with remove', () => {
1433 const lists = store.extractLists({ remove: true });
1434 it('should remove the first/rest triples and return the list members',
1435 shouldIncludeAll(store.getQuads(),
1436 [`_:${listElements[0].value}`, 'p1', 'o1']));
1437 it('should generate a list of Collections', () => {
1438 expect(listsToJSON(lists)).to.deep.equal(listItemsJSON);
1439 });
1440 });
1441 });
1442
1443 describe('A Store containing a well-formed rdf:Collection as object', () => {
1444 const store = new Store();
1445 const listElements = addList(store, new NamedNode('element1'), new Literal('"element2"'));
1446 store.addQuad(new NamedNode('s1'), new NamedNode('p1'), listElements[0]).should.be.true;
1447 const listItemsJSON = {
1448 b0: [
1449 { termType: 'NamedNode', value: 'element1' },
1450 { termType: 'Literal', value: 'element2',
1451 language: '', datatype: { termType: 'NamedNode', value: namespaces.xsd.string } },
1452 ],
1453 };
1454
1455 describe('extractLists without remove', () => {
1456 const lists = store.extractLists();
1457 it('should not delete triples',
1458 shouldIncludeAll(store.getQuads(),
1459 ['s1', 'p1', `_:${listElements[0].value}`],
1460 [`_:${listElements[0].value}`, namespaces.rdf.first, 'element1'],
1461 [`_:${listElements[0].value}`, namespaces.rdf.rest, `_:${listElements[1].value}`],
1462 [`_:${listElements[1].value}`, namespaces.rdf.first, '"element2"'],
1463 [`_:${listElements[1].value}`, namespaces.rdf.rest, namespaces.rdf.nil]
1464 ));
1465 it('should generate a list of Collections', () => {
1466 expect(listsToJSON(lists)).to.deep.equal(listItemsJSON);
1467 });
1468 });
1469
1470 describe('extractLists with remove', () => {
1471 const lists = store.extractLists({ remove: true });
1472 it('should remove the first/rest triples and return the list members',
1473 shouldIncludeAll(store.getQuads(),
1474 ['s1', 'p1', `_:${listElements[0].value}`]));
1475 it('should generate a list of Collections', () => {
1476 expect(listsToJSON(lists)).to.deep.equal(listItemsJSON);
1477 });
1478 });
1479 });
1480
1481 describe('A Store containing a well-formed rdf:Collection that is not attached', () => {
1482 const store = new Store();
1483 const listElements = addList(store, new NamedNode('element1'), new Literal('"element2"'));
1484 store.addQuad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1'));
1485
1486 describe('extractLists without remove', () => {
1487 const lists = store.extractLists();
1488 it('should not delete triples',
1489 shouldIncludeAll(store.getQuads(),
1490 ['s1', 'p1', 'o1'],
1491 [`_:${listElements[0].value}`, namespaces.rdf.first, 'element1'],
1492 [`_:${listElements[0].value}`, namespaces.rdf.rest, `_:${listElements[1].value}`],
1493 [`_:${listElements[1].value}`, namespaces.rdf.first, '"element2"'],
1494 [`_:${listElements[1].value}`, namespaces.rdf.rest, namespaces.rdf.nil]
1495 ));
1496 it('should generate a list of Collections', () => {
1497 expect(listsToJSON(lists)).to.deep.equal({});
1498 });
1499 });
1500
1501 describe('extractLists with remove', () => {
1502 const lists = store.extractLists({ remove: true });
1503 it('should remove the first/rest triples and return the list members',
1504 shouldIncludeAll(store.getQuads(),
1505 ['s1', 'p1', 'o1']));
1506 it('should generate a list of Collections', () => {
1507 expect(listsToJSON(lists)).to.deep.equal({});
1508 });
1509 });
1510 });
1511
1512 describe('A Store containing a rdf:Collection without first', () => {
1513 const store = new Store();
1514 store.addQuad(store.createBlankNode(), new NamedNode(namespaces.rdf.rest), namespaces.rdf.nil).should.be.true;
1515
1516 it('extractLists throws an error', () => {
1517 expect(() => store.extractLists()).throws('b0 has no list head');
1518 });
1519 });
1520
1521 describe('A Store containing an rdf:Collection with multiple rdf:first arcs on head', () => {
1522 const store = new Store();
1523 const listElements = addList(store, store.createBlankNode(), store.createBlankNode());
1524 store.addQuad(listElements[0], new NamedNode(namespaces.rdf.first), store.createBlankNode()).should.be.true;
1525
1526 it('extractLists throws an error', () => {
1527 expect(() => store.extractLists()).throws('b2 has multiple rdf:first arcs');
1528 });
1529 });
1530
1531 describe('A Store containing an rdf:Collection with multiple rdf:first arcs on tail', () => {
1532 const store = new Store();
1533 const listElements = addList(store, store.createBlankNode(), store.createBlankNode());
1534 store.addQuad(listElements[1], new NamedNode(namespaces.rdf.first), store.createBlankNode()).should.be.true;
1535
1536 it('extractLists throws an error', () => {
1537 expect(() => store.extractLists()).throws('b3 has multiple rdf:first arcs');
1538 });
1539 });
1540
1541 describe('A Store containing an rdf:Collection with multiple rdf:rest arcs on head', () => {
1542 const store = new Store();
1543 const listElements = addList(store, store.createBlankNode(), store.createBlankNode());
1544 store.addQuad(listElements[0], new NamedNode(namespaces.rdf.rest), store.createBlankNode()).should.be.true;
1545
1546 it('extractLists throws an error', () => {
1547 expect(() => store.extractLists()).throws('b2 has multiple rdf:rest arcs');
1548 });
1549 });
1550
1551 describe('A Store containing an rdf:Collection with multiple rdf:rest arcs on tail', () => {
1552 const store = new Store();
1553 const listElements = addList(store, store.createBlankNode(), store.createBlankNode());
1554 store.addQuad(listElements[1], new NamedNode(namespaces.rdf.rest), store.createBlankNode()).should.be.true;
1555
1556 it('extractLists throws an error', () => {
1557 expect(() => store.extractLists()).throws('b3 has multiple rdf:rest arcs');
1558 });
1559 });
1560
1561 describe('A Store containing an rdf:Collection with non-list arcs out', () => {
1562 const store = new Store();
1563 const listElements = addList(store, store.createBlankNode(), store.createBlankNode(), store.createBlankNode());
1564 store.addQuad(listElements[1], new NamedNode('http://a.example/foo'), store.createBlankNode()).should.be.true;
1565
1566 it('extractLists throws an error', () => {
1567 expect(() => store.extractLists()).throws('b4 can\'t be subject and object');
1568 });
1569 });
1570
1571 describe('A Store containing an rdf:Collection with multiple incoming rdf:rest arcs', () => {
1572 const store = new Store();
1573 const listElements = addList(store, store.createBlankNode(), store.createBlankNode(), store.createBlankNode());
1574 store.addQuad(store.createBlankNode(), new NamedNode(namespaces.rdf.rest), listElements[1]).should.be.true;
1575
1576 it('extractLists throws an error', () => {
1577 expect(() => store.extractLists()).throws('b4 has incoming rdf:rest arcs');
1578 });
1579 });
1580
1581 describe('A Store containing an rdf:Collection with co-references out of head', () => {
1582 const store = new Store();
1583 const listElements = addList(store, store.createBlankNode(), store.createBlankNode(), store.createBlankNode());
1584 store.addQuad(listElements[0], new NamedNode('p1'), new NamedNode('o1')).should.be.true;
1585 store.addQuad(listElements[0], new NamedNode('p1'), new NamedNode('o2')).should.be.true;
1586
1587 it('extractLists throws an error', () => {
1588 expect(() => store.extractLists()).throws('b3 has non-list arcs out');
1589 });
1590 });
1591
1592 describe('A Store containing an rdf:Collection with co-references into head', () => {
1593 const store = new Store();
1594 const listElements = addList(store, store.createBlankNode(), store.createBlankNode(), store.createBlankNode());
1595 store.addQuad(new NamedNode('s1'), new NamedNode('p1'), listElements[0]).should.be.true;
1596 store.addQuad(new NamedNode('s2'), new NamedNode(namespaces.rdf.rest), listElements[0]).should.be.true;
1597 store.addQuad(new NamedNode('s2'), new NamedNode('p1'), listElements[0]).should.be.true;
1598
1599 it('extractLists throws an error', () => {
1600 expect(() => store.extractLists()).throws('b3 can\'t have coreferences');
1601 });
1602 });
1603
1604 describe('A Store containing an rdf:Collection spread across graphs', () => {
1605 const member0 = new NamedNode('element1');
1606 const member1 = new Literal('"element2"');
1607 const store = new Store();
1608 const listElements = [
1609 store.createBlankNode(),
1610 store.createBlankNode(),
1611 ];
1612 store.addQuad(listElements[0], new NamedNode(namespaces.rdf.first), member0).should.be.true;
1613 store.addQuad(listElements[0], new NamedNode(namespaces.rdf.rest), listElements[1], new NamedNode('g1')).should.be.true;
1614 store.addQuad(listElements[1], new NamedNode(namespaces.rdf.first), member1).should.be.true;
1615 store.addQuad(listElements[1], new NamedNode(namespaces.rdf.rest), new NamedNode(namespaces.rdf.nil)).should.be.true;
1616 store.addQuad(new NamedNode('s1'), new NamedNode('p1'), listElements[0]).should.be.true;
1617
1618 describe('extractLists without ignoreErrors', () => {
1619 it('extractLists throws an error', () => {
1620 expect(() => store.extractLists()).throws('b0 not confined to single graph');
1621 });
1622 });
1623
1624 describe('extractLists with ignoreErrors', () => {
1625 const lists = store.extractLists({ ignoreErrors: true });
1626 it('should not delete triples',
1627 shouldIncludeAll(store.getQuads(),
1628 ['s1', 'p1', `_:${listElements[0].value}`],
1629 [`_:${listElements[0].value}`, namespaces.rdf.first, 'element1'],
1630 [`_:${listElements[0].value}`, namespaces.rdf.rest, `_:${listElements[1].value}`, 'g1'],
1631 [`_:${listElements[1].value}`, namespaces.rdf.first, '"element2"'],
1632 [`_:${listElements[1].value}`, namespaces.rdf.rest, namespaces.rdf.nil]
1633 ));
1634 it('should generate an empty list of Collections', () => {
1635 expect(listsToJSON(lists)).to.deep.equal({});
1636 });
1637 });
1638 });
1639
1640 describe('handles concurrent read/write', () => {
1641 let store;
1642 beforeEach(() => {
1643 store = new Store([
1644 new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')),
1645 new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o3')),
1646 ]);
1647 });
1648
1649 it('should include added elements in match if iteration has not yet started', () => {
1650 const m = store.match(null, null, null, null);
1651 store.add(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o2')));
1652 [...m].should.have.length(3);
1653 [...store.match(null, null, null, null)].should.have.length(3);
1654 });
1655
1656 it('should still include results of original match after iterating while adding new data', () => {
1657 const m = store.match(null, null, null, null)[Symbol.iterator]();
1658 m.next().value.should.deep.equal(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')));
1659 store.add(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o0')));
1660 store.add(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o2')));
1661 store.add(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o4')));
1662 m.next().value.should.deep.equal(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o3')));
1663 m.next().done.should.be.true;
1664 [...store.match(null, null, null, null)].should.have.length(5);
1665 });
1666 });
1667 });
1668
1669 function alwaysTrue() { return true; }
1670 function alwaysFalse() { return false; }
1671
1672 function collect(store, method, arg1, arg2, arg3, arg4) {
1673 const results = [];
1674 store[method](r => results.push(r),
1675 arg1 && termFromId(arg1),
1676 arg2 && termFromId(arg2),
1677 arg3 && termFromId(arg3),
1678 arg4 && termFromId(arg4)
1679 );
1680 return results;
1681 }
1682
1683 function itShouldBeEmpty(result) {
1684 it('should be empty', () => {
1685 if (typeof result === 'function') result = result();
1686 result.should.be.empty;
1687 });
1688 }
1689
1690 function shouldIncludeAll(result) {
1691 const items = Array.prototype.slice.call(arguments, 1).map(arg => {
1692 return new Quad(termFromId(arg[0]), termFromId(arg[1]), termFromId(arg[2]), termFromId(arg[3] || ''));
1693 });
1694 return function () {
1695 if (typeof result === 'function') result = result();
1696 result = result.map(r => { return r.toJSON(); });
1697 result.should.have.length(items.length);
1698 for (let i = 0; i < items.length; i++)
1699 result.should.include.something.that.deep.equals(items[i].toJSON());
1700 };
1701 }
1702
1703 function forResultStream(testFunction, result) {
1704 const items = Array.prototype.slice.call(arguments, 2);
1705 return function (done) {
1706 if (typeof result === 'function') result = result();
1707 arrayifyStream(result)
1708 .then(array => {
1709 items.unshift(array);
1710 testFunction.apply({}, items)();
1711 })
1712 .then(done, done);
1713 };
1714 }
1715
1716 function ArrayReader(items) {
1717 const reader = new Readable({ objectMode: true });
1718 reader._read = function () { this.push(items.shift() || null); };
1719 return reader;
1720 }
1721
1722 function addList(store, ...items) {
1723 if (!items.length)
1724 return new NamedNode(namespaces.rdf.nil);
1725
1726 const listElements = [store.createBlankNode()];
1727 items.forEach((item, i) => {
1728 store.addQuad(listElements[i], new NamedNode(namespaces.rdf.first), item);
1729 if (i === items.length - 1)
1730 store.addQuad(listElements[i], new NamedNode(namespaces.rdf.rest), new NamedNode(namespaces.rdf.nil));
1731 else {
1732 listElements.push(store.createBlankNode());
1733 store.addQuad(listElements[i], new NamedNode(namespaces.rdf.rest), listElements[i + 1]);
1734 }
1735 });
1736 return listElements;
1737 }
1738
1739 function listsToJSON(lists) {
1740 for (const list in lists)
1741 lists[list] = lists[list].map(i => i.toJSON());
1742 return lists;
1743 }