Skip to content

Commit 31714b8

Browse files
ddvlanckrubensworks
authored andcommitted
Update jsonld to 1.0.2
This contains fixes for the following open non-RDFJS-compliance issues in jsonld: * digitalbazaar/jsonld.js#243 * digitalbazaar/jsonld.js#244
1 parent 10cad3b commit 31714b8

File tree

3 files changed

+2168
-28
lines changed

3 files changed

+2168
-28
lines changed

lib/ParserStream.js

+21-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const concat = require('concat-stream')
22
const jsonld = require('jsonld')
3-
const rdf = require('rdf-data-model')
43
const Readable = require('readable-stream')
4+
const rdf = require('@rdfjs/data-model')
5+
const RdfTerms = require('rdf-terms')
56

67
class ParserStream extends Readable {
78
constructor (input, options) {
@@ -38,20 +39,21 @@ class ParserStream extends Readable {
3839
})
3940
}
4041

41-
term (options) {
42-
if (options.type === 'IRI') {
43-
return this.factory.namedNode(options.value)
42+
/**
43+
* Function rewrite with term.termType.
44+
* This is done to fix issue #243, see https://github.com/digitalbazaar/jsonld.js/issues/243 .
45+
* **/
46+
term (term) {
47+
switch (term.termType) {
48+
case 'NamedNode':
49+
return this.factory.namedNode(term.value)
50+
case 'BlankNode':
51+
return this.factory.blankNode(term.value.substr(2)) // Remove the '_:' prefix. see https://github.com/digitalbazaar/jsonld.js/issues/244
52+
case 'Literal':
53+
return this.factory.literal(term.value, term.language || term.datatype)
54+
case 'DefaultGraph':
55+
return this.factory.defaultGraph()
4456
}
45-
46-
if (options.type === 'blank node') {
47-
if (!(options.value in this.blankNodes)) {
48-
this.blankNodes[options.value] = this.factory.blankNode()
49-
}
50-
51-
return this.blankNodes[options.value]
52-
}
53-
54-
return this.factory.literal(options.value, options.language || options.datatype)
5557
}
5658

5759
parse (data) {
@@ -72,17 +74,11 @@ class ParserStream extends Readable {
7274

7375
return jsonld.promises().toRDF(json, toRdfOptions)
7476
}).then((rawGraph) => {
75-
Object.keys(rawGraph).forEach((graphIri) => {
76-
const graph = graphIri !== '@default' ? this.factory.namedNode(graphIri) : null
77-
78-
rawGraph[graphIri].forEach((triple) => {
79-
this.push(this.factory.quad(
80-
this.term(triple.subject),
81-
this.term(triple.predicate),
82-
this.term(triple.object),
83-
graph))
84-
})
85-
})
77+
for (let index in rawGraph) {
78+
this.push(RdfTerms.mapTerms(rawGraph[index], (value) => this.term(value), this.factory))
79+
}
80+
}).catch((error) => {
81+
this.emit('error', error)
8682
})
8783
}
8884

0 commit comments

Comments
 (0)