Skip to content

Commit

Permalink
feat: add N3StoreFactory (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr authored Jul 29, 2024
1 parent 83c9b64 commit 29a449b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/N3StoreFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import N3Store from './N3Store';

export default class N3DatasetCoreFactory {
dataset(quads) {
return new N3Store(quads);
}
}
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Lexer from './N3Lexer';
import Parser from './N3Parser';
import Writer from './N3Writer';
import Store, { N3EntityIndex as EntityIndex } from './N3Store';
import StoreFactory from './N3StoreFactory';
import StreamParser from './N3StreamParser';
import StreamWriter from './N3StreamWriter';
import * as Util from './N3Util';
Expand All @@ -28,6 +29,7 @@ export {
Parser,
Writer,
Store,
StoreFactory,
EntityIndex,
StreamParser,
StreamWriter,
Expand All @@ -54,6 +56,8 @@ export default {
Parser,
Writer,
Store,
StoreFactory,
EntityIndex,
StreamParser,
StreamWriter,
Util,
Expand Down
25 changes: 25 additions & 0 deletions test/N3StoreFactory-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import N3Store from '../src/N3Store';
import N3DatasetCoreFactory from '../src/N3StoreFactory';
import DF from '../src/N3DataFactory';

const { quad, namedNode } = DF;

describe('N3DatasetCoreFactory', () => {
let factory;

beforeEach(() => {
factory = new N3DatasetCoreFactory();
});

it('should create a new dataset with given quads', () => {
const quads = [
quad(namedNode('http://example.org/subject1'), namedNode('http://example.org/predicate1'), namedNode('http://example.org/object1')),
quad(namedNode('http://example.org/subject2'), namedNode('http://example.org/predicate2'), namedNode('http://example.org/object2')),
];

const dataset = factory.dataset(quads);

expect(dataset).toBeInstanceOf(N3Store);
expect([...dataset.match(namedNode('http://example.org/subject1'))]).toEqual([quads[0]]);
});
});

0 comments on commit 29a449b

Please sign in to comment.