@rdfjs/serializer-jsonld-ext
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
0
84
11768
224
+ Added@digitalbazaar/http-client@1.2.0(transitive)
+ Addedabort-controller@3.0.0(transitive)
+ Addeddata-uri-to-buffer@3.0.1(transitive)
+ Addedesm@3.2.25(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedfetch-blob@2.1.2(transitive)
+ Addedjsonld@5.2.0(transitive)
+ Addedky@0.25.1(transitive)
+ Addedky-universal@0.8.2(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addednode-fetch@3.0.0-beta.9(transitive)
+ Addedrdf-canonize@3.4.0(transitive)
+ Addedsetimmediate@1.0.5(transitive)
+ Addedyallist@4.0.0(transitive)
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsonld@1.8.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removednode-forge@0.10.0(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrdf-canonize@1.2.0(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsemver@5.7.26.3.1(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
- Removedxmldom@0.1.19(transitive)
Updated@rdfjs/sink@^1.0.3
Updatedjsonld@^5.2.0
Updatedreadable-stream@^3.6.0