Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rdfjs/parser-jsonld

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rdfjs/parser-jsonld - npm Package Compare versions

Comparing version 1.3.1 to 2.0.0

6

index.js

@@ -1,3 +0,3 @@

const Sink = require('@rdfjs/sink')
const ParserStream = require('./lib/ParserStream')
import Sink from '@rdfjs/sink'
import ParserStream from './lib/ParserStream.js'

@@ -10,2 +10,2 @@ class Parser extends Sink {

module.exports = Parser
export default Parser

@@ -1,4 +0,5 @@

const rdf = require('@rdfjs/data-model')
const { JsonLdParser } = require('jsonld-streaming-parser')
const { Transform } = require('readable-stream')
import rdf from '@rdfjs/data-model'
import toReadable from 'duplex-to/readable.js'
import { JsonLdParser } from 'jsonld-streaming-parser'
import { Transform } from 'readable-stream'

@@ -72,6 +73,6 @@ const relativeIriProtocol = 'null:'

return transform
return toReadable(transform)
}
}
module.exports = ParserStream
export default ParserStream
{
"name": "@rdfjs/parser-jsonld",
"version": "1.3.1",
"version": "2.0.0",
"description": "JSON-LD parser that implements the RDFJS Sink interface using jsonld.js",
"type": "module",
"main": "index.js",
"scripts": {
"coverage": "codecov",
"test": "stricter-standard && c8 --reporter=lcov --reporter=text mocha"

@@ -27,13 +27,16 @@ },

"dependencies": {
"@rdfjs/data-model": "^1.3.4",
"@rdfjs/sink": "^1.0.3",
"jsonld-streaming-parser": "^2.4.3",
"readable-stream": "^3.6.0"
"@rdfjs/data-model": "^2.0.1",
"@rdfjs/sink": "^2.0.0",
"duplex-to": "^2.0.0",
"jsonld-streaming-parser": "^3.0.0",
"readable-stream": "^4.2.0"
},
"devDependencies": {
"c8": "^7.11.0",
"codecov": "^3.8.3",
"mocha": "^9.1.3",
"assert": "^2.0.0",
"c8": "^7.12.0",
"is-stream": "^3.0.0",
"mocha": "^10.0.0",
"stream-chunks": "^1.0.0",
"stricter-standard": "^0.2.0"
}
}

@@ -36,4 +36,4 @@ # @rdfjs/parser-jsonld

```javascript
const ParserJsonld = require('@rdfjs/parser-jsonld')
const Readable = require('stream').Readable
import ParserJsonld from '@rdfjs/parser-jsonld'
import { Readable } from 'stream'

@@ -40,0 +40,0 @@ const parserJsonld = new ParserJsonld()

@@ -1,8 +0,8 @@

const { rejects, strictEqual } = require('assert')
const sinkTest = require('@rdfjs/sink/test')
const { describe, it } = require('mocha')
const { Readable } = require('readable-stream')
const JSONLDParser = require('..')
const toReadable = require('./support/toReadable')
const waitFor = require('./support/waitFor')
import { rejects, strictEqual } from 'assert'
import sinkTest from '@rdfjs/sink/test/index.js'
import { isReadableStream, isWritableStream } from 'is-stream'
import { describe, it } from 'mocha'
import { Readable } from 'readable-stream'
import chunks from 'stream-chunks/chunks.js'
import JSONLDParser from '../index.js'

@@ -12,18 +12,23 @@ describe('@rdfjs/parser-jsond', () => {

it('should return a readable stream', async () => {
const parser = new JSONLDParser()
const stream = parser.import(Readable.from('{}'))
strictEqual(isReadableStream(stream), true)
strictEqual(isWritableStream(stream), false)
await chunks(stream)
})
it('should support Named Node subjects', async () => {
const example = {
const example = JSON.stringify({
'@id': 'http://example.org/subject',
'http://example.org/predicate': 'object'
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -35,17 +40,12 @@ strictEqual(output[0].subject.termType, 'NamedNode')

it('should support empty Named Node subjects', async () => {
const example = {
const example = JSON.stringify({
'@id': '',
'http://example.org/predicate': 'object'
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -61,17 +61,12 @@ strictEqual(output[0].subject.termType, 'NamedNode')

it('should support relative Named Node subjects', async () => {
const example = {
const example = JSON.stringify({
'@id': 'relative',
'http://example.org/predicate': 'object'
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -83,16 +78,11 @@ strictEqual(output[0].subject.termType, 'NamedNode')

it('should support Blank Node subjects', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate': 'object'
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -103,16 +93,11 @@ strictEqual(output[0].subject.termType, 'BlankNode')

it('should parse the predicate', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate': 'object'
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -124,18 +109,13 @@ strictEqual(output[0].predicate.termType, 'NamedNode')

it('should parse a Named Node object', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate': {
'@id': 'http://example.org/object'
}
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -147,16 +127,11 @@ strictEqual(output[0].object.termType, 'NamedNode')

it('should parse a Blank Node object', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate': {}
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -168,17 +143,12 @@ strictEqual(output[0].object.termType, 'BlankNode')

it('should keep Blank Node object mapping', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate1': { '@id': '_:b0' },
'http://example.org/predicate2': { '@id': '_:b0' }
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 2)

@@ -189,18 +159,13 @@ strictEqual(output[0].object.equals(output[1].object), true)

it('should parse a Literal object', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate': {
'@value': 'object'
}
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -214,3 +179,3 @@ strictEqual(output[0].object.termType, 'Literal')

it('should parse the language of a Literal object', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate': {

@@ -220,14 +185,9 @@ '@value': 'object',

}
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -241,3 +201,3 @@ strictEqual(output[0].object.termType, 'Literal')

it('should parse the datatype of a Literal object', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate': {

@@ -247,14 +207,9 @@ '@value': 'object',

}
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -268,3 +223,3 @@ strictEqual(output[0].object.termType, 'Literal')

it('should parse the datatype of a Literal object into a full featured Literal', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate': {

@@ -274,14 +229,9 @@ '@value': 'object',

}
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -292,16 +242,11 @@ strictEqual(typeof output[0].object.datatype.equals, 'function')

it('should use the default graph if none was given', async () => {
const example = {
const example = JSON.stringify({
'http://example.org/predicate': 'object'
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -312,3 +257,3 @@ strictEqual(output[0].graph.termType, 'DefaultGraph')

it('should parse graph', async () => {
const example = {
const example = JSON.stringify({
'@id': 'http://example.org/graph',

@@ -318,14 +263,9 @@ '@graph': {

}
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -337,17 +277,12 @@ strictEqual(output[0].graph.termType, 'NamedNode')

it('should use baseIRI option', async () => {
const example = {
const example = JSON.stringify({
'@id': 'subject',
'http://example.org/predicate': 'object'
}
})
const parser = new JSONLDParser({ baseIRI: 'http://example.org/' })
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -359,6 +294,6 @@ strictEqual(output[0].subject.termType, 'NamedNode')

it('should use context option', async () => {
const example = {
const example = JSON.stringify({
'@id': 'subject',
predicate: 'object'
}
})

@@ -373,11 +308,6 @@ const context = {

})
const stream = parser.import(toReadable(example))
const output = []
const stream = parser.import(Readable.from(example))
stream.on('data', triple => {
output.push(triple)
})
const output = await chunks(stream)
await waitFor(stream)
strictEqual(output.length, 1)

@@ -399,3 +329,3 @@ strictEqual(output[0].subject.termType, 'NamedNode')

await rejects(waitFor(stream, true))
await rejects(chunks(stream, true))
})

@@ -405,20 +335,20 @@

const parser = new JSONLDParser()
const stream = parser.import(toReadable('{'))
const stream = parser.import(Readable.from('{'))
await rejects(waitFor(stream, true))
await rejects(chunks(stream, true))
})
it('should throw an error if JSON-LD is invalid', async () => {
const example = {
const example = JSON.stringify({
'@context': 'object'
}
})
const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const stream = parser.import(Readable.from(example))
await rejects(waitFor(stream, true))
await rejects(chunks(stream, true))
})
it('should emit a prefix event for each context entry', async () => {
const example = {
const example = JSON.stringify({
'@context': {

@@ -428,3 +358,3 @@ ex1: 'http://example.org/1',

}
}
})

@@ -434,3 +364,3 @@ const prefixes = {}

const parser = new JSONLDParser()
const stream = parser.import(toReadable(example))
const stream = parser.import(Readable.from(example))

@@ -441,3 +371,3 @@ stream.on('prefix', (prefix, namespace) => {

await waitFor(stream, true)
await chunks(stream, true)

@@ -444,0 +374,0 @@ strictEqual(prefixes.ex1.value, 'http://example.org/1')

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc