diff --git a/src/adaptors/in-memory-articles.ts b/src/adaptors/in-memory-articles.ts index 2c860097..140384f7 100644 --- a/src/adaptors/in-memory-articles.ts +++ b/src/adaptors/in-memory-articles.ts @@ -1,5 +1,5 @@ import { - BlankNode, DatasetCore, Quad, Quad_Object as QuadObject, + DatasetCore, NamedNode, Quad, Quad_Object as QuadObject, } from 'rdf-js'; import Articles from '../articles'; import ArticleNotFound from '../errors/article-not-found'; @@ -7,9 +7,9 @@ import NotAnArticle from '../errors/not-an-article'; import { rdf, schema } from '../namespaces'; export default class InMemoryArticles implements Articles { - private articles: { [id: string]: [BlankNode, DatasetCore] } = {}; + private articles: { [id: string]: [NamedNode, DatasetCore] } = {}; - async set(id: BlankNode, article: DatasetCore): Promise { + async set(id: NamedNode, article: DatasetCore): Promise { if (article.match(id, rdf.type, schema.Article).size === 0) { throw new NotAnArticle([...article.match(id, rdf.type)].map((quad: Quad): QuadObject => quad.object)); } @@ -17,7 +17,7 @@ export default class InMemoryArticles implements Articles { this.articles[id.value] = [id, article]; } - async get(id: BlankNode): Promise { + async get(id: NamedNode): Promise { if (!(id.value in this.articles)) { throw new ArticleNotFound(id); } @@ -25,11 +25,11 @@ export default class InMemoryArticles implements Articles { return this.articles[id.value][1]; } - async remove(id: BlankNode): Promise { + async remove(id: NamedNode): Promise { delete this.articles[id.value]; } - async contains(id: BlankNode): Promise { + async contains(id: NamedNode): Promise { return id.value in this.articles; } @@ -37,7 +37,7 @@ export default class InMemoryArticles implements Articles { return Object.values(this.articles).length; } - async* [Symbol.asyncIterator](): AsyncIterator<[BlankNode, DatasetCore]> { + async* [Symbol.asyncIterator](): AsyncIterator<[NamedNode, DatasetCore]> { yield* Object.values(this.articles); } } diff --git a/src/articles.ts b/src/articles.ts index 3da38f93..4fd1e1e2 100644 --- a/src/articles.ts +++ b/src/articles.ts @@ -1,13 +1,13 @@ -import { BlankNode, DatasetCore } from 'rdf-js'; +import { DatasetCore, NamedNode } from 'rdf-js'; -interface Articles extends AsyncIterable<[BlankNode, DatasetCore]> { - set(id: BlankNode, article: DatasetCore): Promise; +interface Articles extends AsyncIterable<[NamedNode, DatasetCore]> { + set(id: NamedNode, article: DatasetCore): Promise; - get(id: BlankNode): Promise; + get(id: NamedNode): Promise; - remove(id: BlankNode): Promise; + remove(id: NamedNode): Promise; - contains(id: BlankNode): Promise; + contains(id: NamedNode): Promise; count(): Promise; } diff --git a/src/errors/article-not-found.ts b/src/errors/article-not-found.ts index 41771d40..ed39861b 100644 --- a/src/errors/article-not-found.ts +++ b/src/errors/article-not-found.ts @@ -1,10 +1,10 @@ -import { BlankNode } from 'rdf-js'; +import { NamedNode } from 'rdf-js'; import { termToString } from 'rdf-string'; export default class ArticleNotFound extends Error { - readonly id: BlankNode; + readonly id: NamedNode; - constructor(id: BlankNode) { + constructor(id: NamedNode) { super(`Article ${termToString(id)} could not be found`); this.id = id; diff --git a/src/routes/add-article.ts b/src/routes/add-article.ts index 24b3672c..26908683 100644 --- a/src/routes/add-article.ts +++ b/src/routes/add-article.ts @@ -12,7 +12,7 @@ import Routes from './index'; export default (): AppMiddleware => ( async ({ - articles, dataFactory: { blankNode, quad }, request, response, router, + articles, dataFactory: { namedNode, quad }, request, response, router, }: AppContext, next: Next): Promise => { const id = clownface({ dataset: request.dataset }).has(rdf.type, schema.Article).term; @@ -28,7 +28,7 @@ export default (): AppMiddleware => ( throw new createHttpError.BadRequest(`Article must have at least one ${termToString(schema('name'))}`); } - const newId = blankNode(uniqueString()); + const newId = namedNode(uniqueString()); [...request.dataset].forEach((originalQuad: Quad): void => { let newQuad: Quad; diff --git a/src/routes/article-list.ts b/src/routes/article-list.ts index e2f156e9..9290d17a 100644 --- a/src/routes/article-list.ts +++ b/src/routes/article-list.ts @@ -3,7 +3,7 @@ import { constants } from 'http2'; import all from 'it-all'; import { Next } from 'koa'; import { addAll } from 'rdf-dataset-ext'; -import { BlankNode, DatasetCore } from 'rdf-js'; +import { DatasetCore, NamedNode } from 'rdf-js'; import { toRdf } from 'rdf-literal'; import url from 'url'; import { AppContext, AppMiddleware } from '../app'; @@ -21,7 +21,7 @@ export default (): AppMiddleware => ( const listPromise = all(articles) .then((list): void => { - list.forEach(([id, article]: [BlankNode, DatasetCore]): void => { + list.forEach(([id, article]: [NamedNode, DatasetCore]): void => { graph.addOut(hydra.member, id); addAll(graph.dataset, article); }); diff --git a/test/adaptors/in-memory-articles.test.ts b/test/adaptors/in-memory-articles.test.ts index 9894e402..7272cb22 100644 --- a/test/adaptors/in-memory-articles.test.ts +++ b/test/adaptors/in-memory-articles.test.ts @@ -1,7 +1,7 @@ -import { blankNode, literal, quad } from '@rdfjs/data-model'; +import { literal, namedNode, quad } from '@rdfjs/data-model'; import all from 'it-all'; import 'jest-rdf'; -import { BlankNode, DatasetCore } from 'rdf-js'; +import { DatasetCore, NamedNode } from 'rdf-js'; import InMemoryArticles from '../../src/adaptors/in-memory-articles'; import ArticleNotFound from '../../src/errors/article-not-found'; import NotAnArticle from '../../src/errors/not-an-article'; @@ -11,7 +11,7 @@ import createArticle from '../create-article'; describe('in-memory articles', (): void => { it('can add an article', async (): Promise => { const articles = new InMemoryArticles(); - const id = blankNode(); + const id = namedNode('one'); expect(await articles.contains(id)).toBe(false); @@ -22,7 +22,7 @@ describe('in-memory articles', (): void => { it('can add an article with multiple types', async (): Promise => { const articles = new InMemoryArticles(); - const id = blankNode(); + const id = namedNode('one'); const article = createArticle({ id, types: [schema.Article, schema.NewsArticle] }); await articles.set(id, article); @@ -32,7 +32,7 @@ describe('in-memory articles', (): void => { it('can update an article', async (): Promise => { const articles = new InMemoryArticles(); - const id = blankNode(); + const id = namedNode('one'); await articles.set(id, createArticle({ id, name: literal('Original') })); await articles.set(id, createArticle({ id, name: literal('Updated') })); @@ -42,7 +42,7 @@ describe('in-memory articles', (): void => { it('throws an error if it is not an article', async (): Promise => { const articles = new InMemoryArticles(); - const id = blankNode(); + const id = namedNode('one'); const article = createArticle({ id, types: [schema.NewsArticle] }); await expect(articles.set(id, article)).rejects.toThrow(new NotAnArticle([schema.NewsArticle])); @@ -50,7 +50,7 @@ describe('in-memory articles', (): void => { it('throws an error if it has no type', async (): Promise => { const articles = new InMemoryArticles(); - const id = blankNode(); + const id = namedNode('one'); const article = createArticle({ id, types: [] }); await expect(articles.set(id, article)).rejects.toThrow(new NotAnArticle()); @@ -58,7 +58,7 @@ describe('in-memory articles', (): void => { it('can retrieve an article', async (): Promise => { const articles = new InMemoryArticles(); - const id = blankNode(); + const id = namedNode('one'); const article = createArticle({ id }); await articles.set(id, article); @@ -68,7 +68,7 @@ describe('in-memory articles', (): void => { it('throws an error if the article is not found', async (): Promise => { const articles = new InMemoryArticles(); - const id = blankNode(); + const id = namedNode('one'); await expect(articles.get(id)).rejects.toBeInstanceOf(ArticleNotFound); await expect(articles.get(id)).rejects.toHaveProperty('id', id); @@ -76,7 +76,7 @@ describe('in-memory articles', (): void => { it('can remove an article', async (): Promise => { const articles = new InMemoryArticles(); - const id = blankNode(); + const id = namedNode('one'); await articles.set(id, createArticle({ id })); await articles.remove(id); @@ -86,7 +86,7 @@ describe('in-memory articles', (): void => { it('does nothing when trying to remove an article that is not there', async (): Promise => { const articles = new InMemoryArticles(); - const id = blankNode(); + const id = namedNode('one'); await expect(articles.remove(id)).resolves.not.toThrow(); }); @@ -96,8 +96,8 @@ describe('in-memory articles', (): void => { expect(await articles.count()).toBe(0); - const id1 = blankNode(); - const id2 = blankNode(); + const id1 = namedNode('one'); + const id2 = namedNode('two'); await articles.set(id1, createArticle({ id: id1 })); await articles.set(id2, createArticle({ id: id2 })); @@ -109,15 +109,15 @@ describe('in-memory articles', (): void => { it('can iterate through the articles', async (): Promise => { const articles = new InMemoryArticles(); - const id1 = blankNode(); - const id2 = blankNode(); - const id3 = blankNode(); + const id1 = namedNode('one'); + const id2 = namedNode('two'); + const id3 = namedNode('three'); await articles.set(id1, createArticle({ id: id1 })); await articles.set(id3, createArticle({ id: id3 })); await articles.set(id2, createArticle({ id: id2 })); - const ids = (await all(articles)).map((parts: [BlankNode, DatasetCore]): BlankNode => parts[0]); + const ids = (await all(articles)).map((parts: [NamedNode, DatasetCore]): NamedNode => parts[0]); expect(ids).toStrictEqual([id1, id3, id2]); }); diff --git a/test/errors/article-not-found.test.ts b/test/errors/article-not-found.test.ts index 16db7c35..1c27e36f 100644 --- a/test/errors/article-not-found.test.ts +++ b/test/errors/article-not-found.test.ts @@ -1,21 +1,21 @@ -import { blankNode } from '@rdfjs/data-model'; +import { namedNode } from '@rdfjs/data-model'; import ArticleNotFound from '../../src/errors/article-not-found'; describe('article not found error', (): void => { it('should be an error', async (): Promise => { - const error = new ArticleNotFound(blankNode()); + const error = new ArticleNotFound(namedNode('one')); expect(error).toBeInstanceOf(Error); }); it('should have a message', async (): Promise => { - const error = new ArticleNotFound(blankNode('12345')); + const error = new ArticleNotFound(namedNode('12345')); - expect(error.message).toBe('Article _:12345 could not be found'); + expect(error.message).toBe('Article 12345 could not be found'); }); it('should have an ID', async (): Promise => { - const id = blankNode(); + const id = namedNode('one'); const error = new ArticleNotFound(id); expect(error.id).toBe(id); diff --git a/test/routes/article-list.test.ts b/test/routes/article-list.test.ts index 3fc249e8..41e7d9e4 100644 --- a/test/routes/article-list.test.ts +++ b/test/routes/article-list.test.ts @@ -1,4 +1,4 @@ -import { blankNode, namedNode, quad } from '@rdfjs/data-model'; +import { namedNode, quad } from '@rdfjs/data-model'; import { Response } from 'koa'; import { toRdf } from 'rdf-literal'; import InMemoryArticles from '../../src/adaptors/in-memory-articles'; @@ -35,8 +35,8 @@ describe('article list', (): void => { it('should return articles in the list', async (): Promise => { const articles = new InMemoryArticles(); - const id1 = blankNode(); - const id2 = blankNode(); + const id1 = namedNode('one'); + const id2 = namedNode('two'); await articles.set(id1, createArticle({ id: id1 })); await articles.set(id2, createArticle({ id: id2 }));