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

@rdfjs/serializer-jsonld-ext

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rdfjs/serializer-jsonld-ext - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

.github/workflows/ci.yaml

2

index.js

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

const Sink = require('@rdfjs/sink')
const SerializerStream = require('./lib/SerializerStream')
const Sink = require('@rdfjs/sink')

@@ -4,0 +4,0 @@ class Serializer extends Sink {

@@ -12,3 +12,2 @@ const jsonld = require('jsonld')

skipContext,
skipGraphProperty,
encoding = 'object'

@@ -26,3 +25,2 @@ } = {}) {

this.skipContext = skipContext
this.skipGraphProperty = skipGraphProperty
this.encoding = encoding

@@ -69,14 +67,2 @@

if (this.skipGraphProperty) {
if (data['@graph'] && data['@graph'].length === 1) {
const entry = data['@graph'][0]
Object.keys(entry).forEach((key) => {
data[key] = entry[key]
})
delete data['@graph']
}
}
if (this.encoding === 'string') {

@@ -83,0 +69,0 @@ return JSON.stringify(data)

{
"name": "@rdfjs/serializer-jsonld-ext",
"version": "2.0.0",
"version": "3.0.0",
"description": "JSON-LD serializer that implements the RDFJS Sink Interfaces and supports different output styles",
"main": "index.js",
"scripts": {
"test": "standard && mocha"
"test": "stricter-standard && mocha"
},

@@ -26,16 +26,13 @@ "repository": {

"dependencies": {
"@rdfjs/sink": "^1.0.2",
"@rdfjs/sink": "^1.0.3",
"concat-stream": "^2.0.0",
"jsonld": "^1.6.2",
"readable-stream": "^3.4.0"
"jsonld": "^5.2.0",
"readable-stream": "^3.6.0"
},
"devDependencies": {
"@rdfjs/data-model": "^1.1.1",
"@rdfjs/namespace": "^1.0.0",
"mocha": "^6.1.4",
"standard": "^12.0.1"
},
"engines": {
"node": ">=6"
"@rdfjs/data-model": "^1.3.4",
"@rdfjs/namespace": "^1.1.0",
"mocha": "^9.1.3",
"stricter-standard": "^0.2.0"
}
}

@@ -27,4 +27,2 @@ # @rdfjs/serializer-jsonld-ext

Useful for HTTP server when the media type `application/json` is used and a context is provided as header link.
- `skipGraphProperty`: Tries to get rid of the intermediate `@graph` property.
If `@graph` contains more than one element, this option will be ignored as it would cause data loss.
- `encoding`: Defines the encoding of the output.

@@ -77,2 +75,11 @@ Supported encodings are `string` and `object`.

})
// output:
// {
// '@context': { '@vocab': 'http://schema.org/', ex: 'http://example.org/' },
// '@id': 'ex:sheldon-cooper',
// familyName: 'Cooper',
// givenName: 'Sheldon',
// knows: { '@id': 'ex:amy-farrah-fowler' }
// }
```

@@ -7,3 +7,3 @@ const Readable = require('readable-stream')

read: () => {
quads.forEach((quad) => {
quads.forEach(quad => {
readable.push(quad)

@@ -10,0 +10,0 @@ })

@@ -1,10 +0,9 @@

/* global describe, it */
const assert = require('assert')
const rdf = require('@rdfjs/data-model')
const namespace = require('@rdfjs/namespace')
const quadsToReadable = require('./support/quadsToReadable')
const rdf = require('@rdfjs/data-model')
const sinkTest = require('@rdfjs/sink/test')
const { describe, it } = require('mocha')
const JsonldSerializer = require('..')
const streamConcat = require('../lib/streamConcat')
const JsonldSerializer = require('..')
const quadsToReadable = require('./support/quadsToReadable')

@@ -76,40 +75,2 @@ const ns = {

},
'@graph': [{
'@type': 'Thing',
property0: {
'@type': 'OtherThing',
property1: 'value1'
}
}]
}
const input = quadsToReadable(quads)
const serializer = new JsonldSerializer({ frame: true, context })
const stream = serializer.import(input)
const result = (await streamConcat(stream))[0]
assert.deepStrictEqual(result, jsonld)
})
it('should skip @graph property if skipGraphProperty is true and array.length == 1', async () => {
const root = rdf.blankNode()
const property = rdf.blankNode()
const quads = [
rdf.quad(root, ns.rdf.type, ns.ex.Thing),
rdf.quad(root, ns.ex.property0, property),
rdf.quad(property, ns.rdf.type, ns.ex.OtherThing),
rdf.quad(property, ns.ex.property1, rdf.literal('value1'))
]
const context = {
'@context': {
'@vocab': 'http://example.org/'
},
'@type': 'Thing'
}
const jsonld = {
'@context': {
'@vocab': 'http://example.org/'
},
'@type': 'Thing',

@@ -123,3 +84,3 @@ property0: {

const input = quadsToReadable(quads)
const serializer = new JsonldSerializer({ frame: true, context, skipGraphProperty: true })
const serializer = new JsonldSerializer({ frame: true, context })
const stream = serializer.import(input)

@@ -131,39 +92,2 @@ const result = (await streamConcat(stream))[0]

it('should not skip @graph property if skipGraphProperty is true and array.length != 1', async () => {
const subject0 = rdf.blankNode()
const subject1 = rdf.blankNode()
const quads = [
rdf.quad(subject0, ns.rdf.type, ns.ex.Thing),
rdf.quad(subject0, ns.ex.property0, rdf.literal('value0')),
rdf.quad(subject1, ns.rdf.type, ns.ex.OtherThing),
rdf.quad(subject1, ns.ex.property1, rdf.literal('value1'))
]
const context = {
'@context': {
'@vocab': 'http://example.org/'
}
}
const jsonld = {
'@context': {
'@vocab': 'http://example.org/'
},
'@graph': [{
'@type': 'Thing',
'property0': 'value0'
}, {
'@type': 'OtherThing',
'property1': 'value1'
}]
}
const input = quadsToReadable(quads)
const serializer = new JsonldSerializer({ context, frame: true, skipGraphProperty: true })
const stream = serializer.import(input)
const result = (await streamConcat(stream))[0]
assert.deepStrictEqual(result, jsonld)
})
it('should remove @context if skipContext is true', async () => {

@@ -184,6 +108,4 @@ const subject = rdf.blankNode()

const jsonld = {
'@graph': [{
'@type': 'Thing',
'property0': 'value0'
}]
'@type': 'Thing',
property0: 'value0'
}

@@ -190,0 +112,0 @@

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