From eb9833a9dd6b045547fe22736ac45be16f695320 Mon Sep 17 00:00:00 2001 From: bergi Date: Sat, 18 Nov 2023 22:33:35 +0100 Subject: [PATCH] feat!: renamed package, added pretty-print serializers --- .github/workflows/test.yaml | 4 +- Factory.js | 13 ++++ LICENSE.md | 21 ++++++ README.md | 38 +++++++++-- index.js | 46 +++++++------ lib/CustomJsonLdSerializer.js | 9 --- lib/CustomRdfXmlParser.js | 9 --- lib/Formats.js | 27 ++++++++ lib/JsonLdSerializer.js | 9 +++ lib/PrettyJsonLdSerializer.js | 14 ++++ lib/RdfXmlParser.js | 9 +++ package.json | 25 ++++--- pretty.js | 17 +++++ test/Factory.test.js | 45 +++++++++++++ test/Formats.test.js | 122 ++++++++++++++++++++++++++++++++++ test/pretty.test.js | 39 +++++++++++ test/support/testMediaType.js | 16 +++++ test/test.js | 67 +++++-------------- 18 files changed, 424 insertions(+), 106 deletions(-) create mode 100644 Factory.js create mode 100644 LICENSE.md delete mode 100644 lib/CustomJsonLdSerializer.js delete mode 100644 lib/CustomRdfXmlParser.js create mode 100644 lib/Formats.js create mode 100644 lib/JsonLdSerializer.js create mode 100644 lib/PrettyJsonLdSerializer.js create mode 100644 lib/RdfXmlParser.js create mode 100644 pretty.js create mode 100644 test/Factory.test.js create mode 100644 test/Formats.test.js create mode 100644 test/pretty.test.js create mode 100644 test/support/testMediaType.js diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c165e0a..4550867 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -8,9 +8,9 @@ jobs: strategy: matrix: node: - - '14' - - '16' - '18' + - '20' + - '21' steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/Factory.js b/Factory.js new file mode 100644 index 0000000..d537891 --- /dev/null +++ b/Factory.js @@ -0,0 +1,13 @@ +import Formats from './lib/Formats.js' + +class Factory { + init () { + this.formats = new Formats({ factory: this }) + } + + clone (original) { + this.formats.import(original.formats) + } +} + +export default Factory diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..91f9805 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Thomas Bergwinkl + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 55af9c9..dce3a24 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -# @rdfjs/formats-common -[![build status](https://img.shields.io/github/workflow/status/rdfjs-base/formats-common/Test)](https://github.com/rdfjs-base/formats-common/actions/workflows/test.yaml) -[![npm version](https://img.shields.io/npm/v/@rdfjs/formats-common.svg)](https://www.npmjs.com/package/@rdfjs/formats-common) +# @rdfjs/formats + +[![build status](https://img.shields.io/github/actions/workflow/status/rdfjs-base/formats/test.yaml?branch=master)](https://github.com/rdfjs-base/formats/actions/workflows/test.yaml) +[![npm version](https://img.shields.io/npm/v/@rdfjs/formats.svg)](https://www.npmjs.com/package/@rdfjs/formats) This module bundles parsers and serializers for the most common RDF formats. Instances of [SinkMap](https://github.com/rdfjs-base/sink-map) are used to handle different media types. @@ -8,12 +9,39 @@ Instances of [SinkMap](https://github.com/rdfjs-base/sink-map) are used to handl ## Usage The formats object has a `parsers` and `serializers` property. -Each of it is an instance of `SinkMap` with the most common RDF media types as key. +Each is an instance of `SinkMap` with the most common RDF media types as key. +The formats object is exported as default and can be imported like this: + +```javascript +import formats from '@rdfjs/formats' +``` + +### Pretty-Print Serializers + +The default bundle of serializers is optimized for streaming. +The pretty-print formats bundle can be used if a more human-readable output is required. +It can be imported like this: + +### Factory + +A factory that takes care of parsers and serializers. +An additional `.formats` object will be attached to the environment. +That object is compatible with the data structure of [@rdfjs/formats-common](https://github.com/rdfjs-base/formats-common). +The `.formats` object has an additional `.import()` function to import other format bundles. +The following code shows how to import the [@rdfjs/formats-common](https://github.com/rdfjs-base/formats-common) bundle: + + +```javascript +import formats from '@rdfjs/formats/pretty.js' +``` ## Example +The following example uses the parser for the media type `text/turtle` to parse the given string. +The quads emitted by the `data` event are written to the console: + ```javascript -import formats from '@rdfjs/formats-common' +import formats from '@rdfjs/formats' import { Readable } from 'readable-stream' const input = Readable.from([` diff --git a/index.js b/index.js index 379c1b9..22ff31d 100644 --- a/index.js +++ b/index.js @@ -1,38 +1,42 @@ import JsonLdParser from '@rdfjs/parser-jsonld' import N3Parser from '@rdfjs/parser-n3' import NTriplesSerializer from '@rdfjs/serializer-ntriples' +import TurtleSerializer from '@rdfjs/serializer-turtle' import SinkMap from '@rdfjs/sink-map' -import JsonLdSerializer from './lib/CustomJsonLdSerializer.js' -import RdfXmlParser from './lib/CustomRdfXmlParser.js' +import JsonLdSerializer from './lib/JsonLdSerializer.js' +import PrettyJsonLdSerializer from './lib/PrettyJsonLdSerializer.js' +import RdfXmlParser from './lib/RdfXmlParser.js' -const parsers = new SinkMap() -const serializers = new SinkMap() +const parsers = new SinkMap([ + ['application/ld+json', new JsonLdParser()], + ['application/trig', new N3Parser()], + ['application/n-quads', new N3Parser()], + ['application/n-triples', new N3Parser()], + ['text/n3', new N3Parser()], + ['text/turtle', new N3Parser()], + ['application/rdf+xml', new RdfXmlParser()] +]) + +const serializers = new SinkMap([ + ['application/ld+json', new JsonLdSerializer()], + ['application/n-quads', new NTriplesSerializer()], + ['application/n-triples', new NTriplesSerializer()], + ['text/n3', new NTriplesSerializer()], + ['text/turtle', new NTriplesSerializer()] +]) const formats = { parsers, serializers } -formats.parsers.set('application/ld+json', new JsonLdParser()) -formats.parsers.set('application/trig', new N3Parser()) -formats.parsers.set('application/n-quads', new N3Parser()) -formats.parsers.set('application/n-triples', new N3Parser()) -formats.parsers.set('text/n3', new N3Parser()) -formats.parsers.set('text/turtle', new N3Parser()) -formats.parsers.set('application/rdf+xml', new RdfXmlParser()) - -formats.serializers.set('application/ld+json', new JsonLdSerializer()) -formats.serializers.set('application/n-quads', new NTriplesSerializer()) -formats.serializers.set('application/n-triples', new NTriplesSerializer()) -formats.serializers.set('text/n3', new NTriplesSerializer()) -formats.serializers.set('text/turtle', new NTriplesSerializer()) - -export { parsers, serializers } -export default formats export { + formats as default, JsonLdParser, JsonLdSerializer, N3Parser, NTriplesSerializer, - RdfXmlParser + PrettyJsonLdSerializer, + RdfXmlParser, + TurtleSerializer } diff --git a/lib/CustomJsonLdSerializer.js b/lib/CustomJsonLdSerializer.js deleted file mode 100644 index 4965eaf..0000000 --- a/lib/CustomJsonLdSerializer.js +++ /dev/null @@ -1,9 +0,0 @@ -import JsonLdSerializer from '@rdfjs/serializer-jsonld' - -class CustomJsonLdSerializer extends JsonLdSerializer { - constructor ({ ...args } = {}) { - super({ encoding: 'string', ...args }) - } -} - -export default CustomJsonLdSerializer diff --git a/lib/CustomRdfXmlParser.js b/lib/CustomRdfXmlParser.js deleted file mode 100644 index 57718be..0000000 --- a/lib/CustomRdfXmlParser.js +++ /dev/null @@ -1,9 +0,0 @@ -import { RdfXmlParser } from 'rdfxml-streaming-parser' - -class CustomRdfXmlParser extends RdfXmlParser { - constructor ({ factory, ...args } = {}) { - super({ ...args, dataFactory: factory }) - } -} - -export default CustomRdfXmlParser diff --git a/lib/Formats.js b/lib/Formats.js new file mode 100644 index 0000000..ff7b25c --- /dev/null +++ b/lib/Formats.js @@ -0,0 +1,27 @@ +import SinkMap from '@rdfjs/sink-map' + +class Formats { + constructor ({ factory }) { + this.factory = factory + this.parsers = new SinkMap() + this.serializers = new SinkMap() + } + + import (other) { + if (other.parsers) { + for (const [mediaType, parser] of other.parsers) { + this.parsers.set(mediaType, new parser.constructor({ factory: this.factory })) + } + } + + if (other.serializers) { + for (const [mediaType, serializer] of other.serializers) { + this.serializers.set(mediaType, new serializer.constructor({ factory: this.factory })) + } + } + + return this + } +} + +export default Formats diff --git a/lib/JsonLdSerializer.js b/lib/JsonLdSerializer.js new file mode 100644 index 0000000..ebf9114 --- /dev/null +++ b/lib/JsonLdSerializer.js @@ -0,0 +1,9 @@ +import JsonLdSerializerBase from '@rdfjs/serializer-jsonld' + +class JsonLdSerializer extends JsonLdSerializerBase { + constructor ({ ...args } = {}) { + super({ ...args, encoding: 'string' }) + } +} + +export default JsonLdSerializer diff --git a/lib/PrettyJsonLdSerializer.js b/lib/PrettyJsonLdSerializer.js new file mode 100644 index 0000000..f98d550 --- /dev/null +++ b/lib/PrettyJsonLdSerializer.js @@ -0,0 +1,14 @@ +import JsonLdSerializer from '@rdfjs/serializer-jsonld-ext' + +class PrettyJsonLdSerializer extends JsonLdSerializer { + constructor ({ ...args } = {}) { + super({ + ...args, + compact: true, + encoding: 'string', + prettyPrint: true + }) + } +} + +export default PrettyJsonLdSerializer diff --git a/lib/RdfXmlParser.js b/lib/RdfXmlParser.js new file mode 100644 index 0000000..41e2886 --- /dev/null +++ b/lib/RdfXmlParser.js @@ -0,0 +1,9 @@ +import { RdfXmlParser as RdfXmlParserBase } from 'rdfxml-streaming-parser' + +class RdfXmlParser extends RdfXmlParserBase { + constructor ({ factory, ...args } = {}) { + super({ ...args, dataFactory: factory }) + } +} + +export default RdfXmlParser diff --git a/package.json b/package.json index 97cdece..bd1d322 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "@rdfjs/formats-common", + "name": "@rdfjs/formats", "version": "3.1.0", - "description": "Parsers and serializers for common RDF formats", + "description": "Bundle of RDF/JS parsers and serializers", "type": "module", "main": "index.js", "scripts": { @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/rdfjs-base/formats-common.git" + "url": "https://github.com/rdfjs-base/formats.git" }, "keywords": [ "rdf", @@ -21,20 +21,23 @@ "author": "Thomas Bergwinkl (https://www.bergnet.org/people/bergi/card#me)", "license": "MIT", "bugs": { - "url": "https://github.com/rdfjs-base/formats-common/issues" + "url": "https://github.com/rdfjs-base/formats/issues" }, - "homepage": "https://github.com/rdfjs-base/formats-common", + "homepage": "https://github.com/rdfjs-base/formats", "dependencies": { - "@rdfjs/parser-jsonld": "^2.0.0", - "@rdfjs/parser-n3": "^2.0.0", + "@rdfjs/parser-jsonld": "^2.1.0", + "@rdfjs/parser-n3": "^2.0.1", "@rdfjs/serializer-jsonld": "^2.0.0", + "@rdfjs/serializer-jsonld-ext": "^4.0.0", "@rdfjs/serializer-ntriples": "^2.0.0", + "@rdfjs/serializer-turtle": "^1.1.1", "@rdfjs/sink-map": "^2.0.0", - "rdfxml-streaming-parser": "^2.2.0" + "rdfxml-streaming-parser": "^2.3.0" }, "devDependencies": { - "c8": "^7.12.0", - "mocha": "^10.0.0", - "stricter-standard": "^0.2.0" + "@rdfjs/environment": "^1.0.0", + "c8": "^8.0.1", + "mocha": "^10.2.0", + "stricter-standard": "^0.3.0" } } diff --git a/pretty.js b/pretty.js new file mode 100644 index 0000000..10c2333 --- /dev/null +++ b/pretty.js @@ -0,0 +1,17 @@ +import SinkMap from '@rdfjs/sink-map' +import defaultFormats, { PrettyJsonLdSerializer, TurtleSerializer } from './index.js' + +const parsers = new SinkMap(defaultFormats.parsers) + +const serializers = new SinkMap(defaultFormats.serializers) + +serializers.set('application/ld+json', new PrettyJsonLdSerializer()) +serializers.set('text/n3', new TurtleSerializer()) +serializers.set('text/turtle', new TurtleSerializer()) + +const formats = { + parsers, + serializers +} + +export default formats diff --git a/test/Factory.test.js b/test/Factory.test.js new file mode 100644 index 0000000..f6d824c --- /dev/null +++ b/test/Factory.test.js @@ -0,0 +1,45 @@ +import { notStrictEqual, strictEqual } from 'assert' +import Environment from '@rdfjs/environment' +import { describe, it } from 'mocha' +import Factory from '../Factory.js' +import Formats from '../lib/Formats.js' + +describe('Factory', () => { + it('should be a constructor', () => { + strictEqual(typeof Factory, 'function') + }) + + it('should attach a Formats instance to .formats', () => { + const env = new Environment([Factory]) + + strictEqual(env.formats instanceof Formats, true) + }) + + it('should assign itself as factory to the formats instance', () => { + const env = new Environment([Factory]) + + strictEqual(env.formats.factory, env) + }) + + describe('.clone', () => { + it('should import the parsers and serializers from the original environment', () => { + class Parser {} + class Serializer {} + const original = { + parsers: new Map([['a', new Parser()]]), + serializers: new Map([['a', new Serializer()]]) + } + const env = new Environment([Factory]) + env.formats.import(original) + + const clone = env.clone() + + strictEqual(clone.formats.parsers.size, 1) + strictEqual(clone.formats.parsers.get('a') instanceof Parser, true) + notStrictEqual(clone.formats.parsers.get('a'), env.formats.parsers.get('a')) + strictEqual(clone.formats.serializers.size, 1) + strictEqual(clone.formats.serializers.get('a') instanceof Serializer, true) + notStrictEqual(clone.formats.serializers.get('a'), env.formats.serializers.get('a')) + }) + }) +}) diff --git a/test/Formats.test.js b/test/Formats.test.js new file mode 100644 index 0000000..74beb5f --- /dev/null +++ b/test/Formats.test.js @@ -0,0 +1,122 @@ +import { notStrictEqual, strictEqual } from 'assert' +import SinkMap from '@rdfjs/sink-map' +import { describe, it } from 'mocha' +import Formats from '../lib/Formats.js' + +describe('Formats', () => { + it('should be a constructor', () => { + strictEqual(typeof Formats, 'function') + }) + + it('should assign the given factory', () => { + const factory = {} + + const formats = new Formats({ factory }) + + strictEqual(formats.factory, factory) + }) + + it('should assign an empty SinkMap to .parsers', () => { + const formats = new Formats({ factory: {} }) + + strictEqual(formats.parsers instanceof SinkMap, true) + strictEqual(formats.parsers.size, 0) + }) + + it('should assign an empty SinkMap to .serializers', () => { + const formats = new Formats({ factory: {} }) + + strictEqual(formats.serializers instanceof SinkMap, true) + strictEqual(formats.serializers.size, 0) + }) + + describe('.import', () => { + it('should be a method', () => { + const formats = new Formats({ factory: {} }) + + strictEqual(typeof formats.import, 'function') + }) + + it('should import new instances of the parsers given in formats', () => { + class ParserA {} + class ParserB {} + const original = { + parsers: new Map([ + ['a', new ParserA()], + ['b', new ParserB()] + ]) + } + const formats = new Formats({ factory: {} }) + + formats.import(original) + + strictEqual(formats.parsers.size, 2) + strictEqual(formats.parsers.get('a') instanceof ParserA, true) + notStrictEqual(formats.parsers.get('a'), original.parsers.get('a')) + strictEqual(formats.parsers.get('b') instanceof ParserB, true) + notStrictEqual(formats.parsers.get('b'), original.parsers.get('b')) + }) + + it('should return the formats object', () => { + const formats = new Formats({ factory: {} }) + + const result = formats.import(new Map()) + + strictEqual(result, formats) + }) + + it('should forward the factory to the constructor of the new parser instance', () => { + class Parser { + constructor ({ factory }) { + this.factory = factory + } + } + const factory = {} + const original = { + parsers: new Map([['a', new Parser({ factory: {} })]]) + } + const formats = new Formats({ factory }) + + formats.import(original) + + strictEqual(formats.parsers.get('a').factory, factory) + }) + + it('should import new instances of the serializers given in formats', () => { + class SerializerA {} + class SerializerB {} + const original = { + serializers: new Map([ + ['a', new SerializerA()], + ['b', new SerializerB()] + ]) + } + const formats = new Formats({ factory: {} }) + + formats.import(original) + + strictEqual(formats.serializers.size, 2) + strictEqual(formats.serializers.get('a') instanceof SerializerA, true) + notStrictEqual(formats.serializers.get('a'), original.serializers.get('a')) + strictEqual(formats.serializers.get('b') instanceof SerializerB, true) + notStrictEqual(formats.serializers.get('b'), original.serializers.get('b')) + }) + + it('should forward the factory to the constructor of the new serializer instance', () => { + class Serializer { + constructor ({ factory }) { + this.factory = factory + } + } + const factory = {} + const original = { + serializers: new Map([['a', new Serializer({ factory: {} })]]) + } + const formats = new Formats({ factory }) + + formats.import(original) + + strictEqual(formats.serializers.get('a').factory, factory) + }) + }) +}) diff --git a/test/pretty.test.js b/test/pretty.test.js new file mode 100644 index 0000000..fa9fdf1 --- /dev/null +++ b/test/pretty.test.js @@ -0,0 +1,39 @@ +import { strictEqual } from 'assert' +import JsonLdParser from '@rdfjs/parser-jsonld' +import N3Parser from '@rdfjs/parser-n3' +import NTriplesSerializer from '@rdfjs/serializer-ntriples' +import TurtleSerializer from '@rdfjs/serializer-turtle' +import SinkMap from '@rdfjs/sink-map' +import { describe, it } from 'mocha' +import PrettyJsonLdSerializer from '../lib/PrettyJsonLdSerializer.js' +import RdfXmlParser from '../lib/RdfXmlParser.js' +import formats from '../pretty.js' +import testMediaType from './support/testMediaType.js' + +describe('pretty', () => { + describe('parsers', () => { + it('should be a SinkMap', () => { + strictEqual(formats.parsers instanceof SinkMap, true) + }) + + testMediaType(formats.parsers, 'application/ld+json', '@rdfjs/parser-jsonld', JsonLdParser) + testMediaType(formats.parsers, 'application/trig', '@rdfjs/parser-n3', N3Parser) + testMediaType(formats.parsers, 'application/n-quads', '@rdfjs/parser-n3', N3Parser) + testMediaType(formats.parsers, 'application/n-triples', '@rdfjs/parser-n3', N3Parser) + testMediaType(formats.parsers, 'text/n3', '@rdfjs/parser-n3', N3Parser) + testMediaType(formats.parsers, 'text/turtle', '@rdfjs/parser-n3', N3Parser) + testMediaType(formats.parsers, 'application/rdf+xml', 'rdfxml-streaming-parser', RdfXmlParser) + }) + + describe('serializers', () => { + it('should be a SinkMap', () => { + strictEqual(formats.serializers instanceof SinkMap, true) + }) + + testMediaType(formats.serializers, 'application/ld+json', '@rdfjs/serializer-jsonld', PrettyJsonLdSerializer) + testMediaType(formats.serializers, 'application/n-quads', '@rdfjs/serializer-ntriples', NTriplesSerializer) + testMediaType(formats.serializers, 'application/n-triples', '@rdfjs/serializer-ntriples', NTriplesSerializer) + testMediaType(formats.serializers, 'text/n3', '@rdfjs/serializer-ntriples', TurtleSerializer) + testMediaType(formats.serializers, 'text/turtle', '@rdfjs/serializer-ntriples', TurtleSerializer) + }) +}) diff --git a/test/support/testMediaType.js b/test/support/testMediaType.js new file mode 100644 index 0000000..9c65700 --- /dev/null +++ b/test/support/testMediaType.js @@ -0,0 +1,16 @@ +import { strictEqual } from 'assert' +import { describe, it } from 'mocha' + +function testMediaType (map, mediaType, name, implementation) { + describe(mediaType, () => { + it('should be supported', () => { + strictEqual(map.has(mediaType), true) + }) + + it(`should use ${name}`, () => { + strictEqual(map.get(mediaType) instanceof implementation, true) + }) + }) +} + +export default testMediaType diff --git a/test/test.js b/test/test.js index c3365f1..10c8f60 100644 --- a/test/test.js +++ b/test/test.js @@ -2,37 +2,18 @@ import { strictEqual } from 'assert' import JsonLdParser from '@rdfjs/parser-jsonld' import N3Parser from '@rdfjs/parser-n3' import NTriplesSerializer from '@rdfjs/serializer-ntriples' +import TurtleSerializer from '@rdfjs/serializer-turtle' import SinkMap from '@rdfjs/sink-map' import { describe, it } from 'mocha' import formats from '../index.js' import * as all from '../index.js' -import JsonLdSerializer from '../lib/CustomJsonLdSerializer.js' -import RdfXmlParser from '../lib/CustomRdfXmlParser.js' +import JsonLdSerializer from '../lib/JsonLdSerializer.js' +import PrettyJsonLdSerializer from '../lib/PrettyJsonLdSerializer.js' +import RdfXmlParser from '../lib/RdfXmlParser.js' +import testMediaType from './support/testMediaType.js' -function testMediaType (map, mediaType, name, implementation) { - describe(mediaType, () => { - it('should be supported', () => { - strictEqual(map.has(mediaType), true) - }) - - it(`should use ${name}`, () => { - strictEqual(map.get(mediaType) instanceof implementation, true) - }) - }) -} - -describe('@rdfjs/formats-common', () => { +describe('@rdfjs/formats', () => { describe('exports', () => { - it('should export all parsers as SinkMap', () => { - strictEqual(all.parsers instanceof SinkMap, true) - strictEqual(all.parsers.size, 7) - }) - - it('should export all serializers as SinkMap', () => { - strictEqual(all.serializers instanceof SinkMap, true) - strictEqual(all.serializers.size, 5) - }) - it('should export the JsonLdParser', () => { strictEqual(all.JsonLdParser, JsonLdParser) }) @@ -49,20 +30,22 @@ describe('@rdfjs/formats-common', () => { strictEqual(all.NTriplesSerializer, NTriplesSerializer) }) + it('should export the PrettyJsonLdSerializer', () => { + strictEqual(all.PrettyJsonLdSerializer, PrettyJsonLdSerializer) + }) + it('should export the RdfXmlParser', () => { strictEqual(all.RdfXmlParser, RdfXmlParser) }) - }) - describe('parsers', () => { - it('should implement the Map interface', () => { - strictEqual(typeof formats.parsers.get, 'function') - strictEqual(typeof formats.parsers.has, 'function') - strictEqual(typeof formats.parsers.set, 'function') + it('should export the TurtleSerializer', () => { + strictEqual(all.TurtleSerializer, TurtleSerializer) }) + }) - it('should implement .import', () => { - strictEqual(typeof formats.parsers.import, 'function') + describe('parsers', () => { + it('should be a SinkMap', () => { + strictEqual(formats.parsers instanceof SinkMap, true) }) testMediaType(formats.parsers, 'application/ld+json', '@rdfjs/parser-jsonld', JsonLdParser) @@ -75,22 +58,8 @@ describe('@rdfjs/formats-common', () => { }) describe('serializers', () => { - it('should contain serializers all defined media types', () => { - strictEqual(formats.serializers.has('application/ld+json'), true) - strictEqual(formats.serializers.has('application/n-quads'), true) - strictEqual(formats.serializers.has('application/n-triples'), true) - strictEqual(formats.serializers.has('text/n3'), true) - strictEqual(formats.serializers.has('text/turtle'), true) - }) - - it('should implement the Map interface', () => { - strictEqual(typeof formats.serializers.get, 'function') - strictEqual(typeof formats.serializers.has, 'function') - strictEqual(typeof formats.serializers.set, 'function') - }) - - it('should implement .import', () => { - strictEqual(typeof formats.serializers.import, 'function') + it('should be a SinkMap', () => { + strictEqual(formats.serializers instanceof SinkMap, true) }) testMediaType(formats.serializers, 'application/ld+json', '@rdfjs/serializer-jsonld', JsonLdSerializer)