This repository has been archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change blanknodes to namednodes (#181)
* Change blanknodes to namednodes * refactor namedNode calls * Create article with blankNode before namedNode is assigned * Remove console.log
- Loading branch information
1 parent
7d7fad7
commit 4560b10
Showing
8 changed files
with
45 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
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'; | ||
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<void> { | ||
async set(id: NamedNode, article: DatasetCore): Promise<void> { | ||
if (article.match(id, rdf.type, schema.Article).size === 0) { | ||
throw new NotAnArticle([...article.match(id, rdf.type)].map((quad: Quad): QuadObject => quad.object)); | ||
} | ||
|
||
this.articles[id.value] = [id, article]; | ||
} | ||
|
||
async get(id: BlankNode): Promise<DatasetCore> { | ||
async get(id: NamedNode): Promise<DatasetCore> { | ||
if (!(id.value in this.articles)) { | ||
throw new ArticleNotFound(id); | ||
} | ||
|
||
return this.articles[id.value][1]; | ||
} | ||
|
||
async remove(id: BlankNode): Promise<void> { | ||
async remove(id: NamedNode): Promise<void> { | ||
delete this.articles[id.value]; | ||
} | ||
|
||
async contains(id: BlankNode): Promise<boolean> { | ||
async contains(id: NamedNode): Promise<boolean> { | ||
return id.value in this.articles; | ||
} | ||
|
||
async count(): Promise<number> { | ||
return Object.values(this.articles).length; | ||
} | ||
|
||
async* [Symbol.asyncIterator](): AsyncIterator<[BlankNode, DatasetCore]> { | ||
async* [Symbol.asyncIterator](): AsyncIterator<[NamedNode, DatasetCore]> { | ||
yield* Object.values(this.articles); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4560b10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remember to change the commit description? The GitHub default isn’t very useful.
4560b10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 should conform to conventional commits
4560b10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and remove the PR id
4560b10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and summarize rather than listing lots of intermediate commits
4560b10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hadn't spotted the message wasn't changed either. 😰
4560b10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like https://github.com/zeke/semantic-pull-requests (idea more than this implementation) could be useful in the future.