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
Change blanknodes to namednodes #181
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The documentation says this should be an IRI, but we have good reasons to use host-free values.