Comparing version 0.3.0 to 1.0.0
@@ -1,67 +0,37 @@ | ||
function Parsers (parsers) { | ||
var self = this | ||
class Parsers { | ||
constructor (parsers) { | ||
if (parsers) { | ||
Object.keys(parsers).forEach((mediaType) => { | ||
this[mediaType] = parsers[mediaType] | ||
}) | ||
} | ||
} | ||
if (parsers) { | ||
Object.keys(parsers).forEach(function (mediaType) { | ||
self[mediaType] = parsers[mediaType] | ||
}) | ||
find (mediaType) { | ||
if (!(mediaType in this)) { | ||
return null | ||
} | ||
return this[mediaType] | ||
} | ||
} | ||
Parsers.prototype.list = function () { | ||
var propertyBlackList = ['list', 'findParsers', 'parse', 'process', 'stream'] | ||
list () { | ||
let propertyBlackList = ['find', 'list', 'read'] | ||
return Object.keys(this) | ||
.filter(function (property) { | ||
return Object.keys(this).filter((property) => { | ||
return propertyBlackList.indexOf(property) === -1 | ||
}) | ||
} | ||
Parsers.prototype.findParsers = function (mediaType) { | ||
if (!(mediaType in this)) { | ||
return null | ||
} | ||
var parsers = this[mediaType] | ||
import (mediaType, input, options) { | ||
let parser = this.find(mediaType) | ||
if (!Array.isArray(parsers)) { | ||
parsers = [parsers] | ||
} | ||
if (!parser) { | ||
return null | ||
} | ||
return parsers | ||
} | ||
Parsers.prototype.parse = function (mediaType, data, callback, base, filter, graph) { | ||
var parsers = this.findParsers(mediaType) | ||
if (!parsers) { | ||
return Promise.reject('no parser for mime type: ' + mediaType + ' found') | ||
return parser.import(input, options) | ||
} | ||
// TODO: try other parsers on error | ||
return parsers.shift().parse(data, callback, base, filter, graph) | ||
} | ||
Parsers.prototype.process = function (mediaType, data, callback, base, filter, done) { | ||
var parsers = this.findParsers(mediaType) | ||
if (!parsers) { | ||
return Promise.reject('no parser for mime type: ' + mediaType + ' found') | ||
} | ||
// TODO: try other parsers on error | ||
return parsers.shift().process(data, callback, base, filter, done) | ||
} | ||
Parsers.prototype.stream = function (mediaType, inputStream, base, filter) { | ||
var parsers = this.findParsers(mediaType) | ||
if (!parsers) { | ||
return null | ||
} | ||
// TODO: try other parsers on error | ||
return parsers.shift().stream(inputStream, base, filter) | ||
} | ||
module.exports = Parsers |
@@ -1,48 +0,37 @@ | ||
function Serializers (serializers) { | ||
var self = this | ||
if (serializers) { | ||
Object.keys(serializers).forEach(function (mediaType) { | ||
self[mediaType] = serializers[mediaType] | ||
}) | ||
class Serializers { | ||
constructor (serializers) { | ||
if (serializers) { | ||
Object.keys(serializers).forEach((mediaType) => { | ||
this[mediaType] = serializers[mediaType] | ||
}) | ||
} | ||
} | ||
} | ||
Serializers.prototype.list = function () { | ||
var propertyBlackList = ['list', 'findSerializer', 'serialize', 'stream'] | ||
find (mediaType) { | ||
if (!(mediaType in this)) { | ||
return null | ||
} | ||
return Object.keys(this) | ||
.filter(function (property) { | ||
return propertyBlackList.indexOf(property) === -1 | ||
}) | ||
} | ||
Serializers.prototype.findSerializer = function (mediaType) { | ||
if (!(mediaType in this)) { | ||
return null | ||
return this[mediaType] | ||
} | ||
return this[mediaType] | ||
} | ||
import (mediaType, input, options) { | ||
let serializer = this.find(mediaType) | ||
Serializers.prototype.serialize = function (mediaType, graph, callback) { | ||
var serializer = this.findSerializer(mediaType) | ||
if (!serializer) { | ||
return null | ||
} | ||
if (!serializer) { | ||
return Promise.reject('no serializer for mime type: ' + mediaType + ' found') | ||
return serializer.import(input, options) | ||
} | ||
return serializer.serialize(graph, callback) | ||
} | ||
list () { | ||
let propertyBlackList = ['find', 'import', 'list'] | ||
Serializers.prototype.stream = function (mediaType, inputStream, base, filter) { | ||
var serializer = this.findSerializer(mediaType) | ||
if (!serializer) { | ||
return null | ||
return Object.keys(this).filter((property) => { | ||
return propertyBlackList.indexOf(property) === -1 | ||
}) | ||
} | ||
return serializer.stream(inputStream, base, filter) | ||
} | ||
module.exports = Serializers |
{ | ||
"name": "rdf-ext", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"description": "Extended Linked Data module", | ||
"main": "rdf-ext.js", | ||
"scripts": { | ||
"lint": "standard", | ||
"test": "node_modules/.bin/mocha" | ||
"test": "standard && mocha" | ||
}, | ||
@@ -16,4 +15,4 @@ "repository": { | ||
"rdf", | ||
"rdf-ext", | ||
"rdf-interfaces" | ||
"rdfjs", | ||
"rdf-ext" | ||
], | ||
@@ -27,12 +26,10 @@ "author": "Thomas Bergwinkl <bergi@axolotlfarm.org> (https://www.bergnet.org/people/bergi/card#me)", | ||
"dependencies": { | ||
"es6-promise": "^3.0.2", | ||
"rdf-graph-array": "^0.3.0", | ||
"rdf-store-inmemory": "^0.3.0" | ||
"rdf-data-model": "^1.0.0", | ||
"rdf-dataset-simple": "^1.0.0", | ||
"rdf-normalize": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.3.3", | ||
"nock": "^2.17.0", | ||
"rdf-test-data": "^0.3.0" | ||
}, | ||
"readmeFilename": "README.md" | ||
"mocha": "^3.2.0", | ||
"standard": "^9.0.1" | ||
} | ||
} |
# RDF Interfaces Extension | ||
**Attention: a lot of work has gone through rdf-ext 0.3.0 and it doesn't match this documentation. Right now you can have a look at the tests and at the different packages under the [rdf-ext](https://github.com/rdf-ext) organization. Documentation will be updated soon** | ||
[![Build Status](https://travis-ci.org/rdf-ext/rdf-ext.svg?branch=master)](https://travis-ci.org/rdf-ext/rdf-ext) | ||
[![npm version](https://badge.fury.io/js/rdf-ext.svg)](https://badge.fury.io/js/rdf-ext) | ||
[![Build Status](https://travis-ci.org/rdf-ext/rdf-ext.svg?branch=master)](https://travis-ci.org/zazukoians/rdf-ext) | ||
[![NPM Version](https://img.shields.io/npm/v/rdf-ext.svg?style=flat)](https://npm.im/rdf-ext) | ||
RDF-Ext provides a JavaScript library for working with RDF & Linked Data. | ||
This module contains the core classes to handle RDF Model data. | ||
Additional modules may be required to handle data in different formats (Turtle, JSON-LD, RDF/XML) or stores (LDP, SPARQL). | ||
Additional modules may be required to handle data in different formats (Turtle, JSON-LD) or stores (Web, SPARQL). | ||
The [module section](#modules) lists the most common modules. | ||
## Usage | ||
In general, consult the [API documentation](https://github.com/rdf-ext/rdf-ext-spec/blob/gh-pages/API.md) for details about how to interact with the library. | ||
In general, consult the [RDFJS specification](https://github.com/rdfjs/representation-task-force/) for details about how to interact with the library. | ||
### Node | ||
### node.js | ||
RDF-Ext is available on `npm`, to install it run: | ||
@@ -28,23 +23,19 @@ | ||
var rdf = require('rdf-ext'); | ||
const rdf = require('rdf-ext') | ||
### Browser | ||
Just import the RDF-Ext distribution: | ||
The preferred way to use RDF-Ext in the browser is using [browserify](http://browserify.org/). | ||
<script src="/js/rdf-ext.js"></script> | ||
#### Distribution | ||
You can download a prebuilt or custom distribution from the [RDF-Ext distribution builder site](http://rdf-ext.bergnet.org/). | ||
The [RDF-Ext distribution builder](https://github.com/rdf-ext/rdf-ext-dist-builder) also offers a command line interface to build custom distributions. | ||
It's also possible to use a prebuilt or custom distribution using the [RDF-Ext distribution builder](https://github.com/rdf-ext/rdf-ext-dist-builder). | ||
This can be also done using the [RDF-Ext distribution builder site](http://rdf-ext.bergnet.org/). | ||
Than just import the RDF-Ext distribution: | ||
#### Browserify | ||
<script src="/js/rdf-ext.js"></script> | ||
Everything is attached to the global variable `rdf`. | ||
If you build your application with Browserify, RDF-Ext can be bundled flawless. | ||
## Support | ||
@@ -56,44 +47,32 @@ | ||
## Modules | ||
There are many modules for parsing, serializing, stores for persistence and simplified data handling. | ||
In general all modules are available at [npm](https://www.npmjs.com) and you can use the Github repository name to install them. | ||
### Parsers | ||
* [Abstract](https://github.com/rdf-ext/rdf-parser-abstract) - Can be used to implement own parsers | ||
* [DOM](https://github.com/rdf-ext/rdf-parser-dom) - Can be used to implement parsers for XML or HTML formats | ||
* [JSON-LD](https://github.com/rdf-ext/rdf-parser-jsonld) - Uses the reference implementation to supports all document forms | ||
* [Microdata](https://github.com/rdf-ext/rdf-parser-microdata) - Fork of the [Green Turtle](https://github.com/alexmilowski/green-turtle) parser | ||
* [RDF/XML](https://github.com/rdf-ext/rdf-parser-rdfxml) - Fork of the [rdflib.js](https://github.com/linkeddata/rdflib.js/) RDF/XML parser | ||
* [Turtle & N-Triples](https://github.com/rdf-ext/rdf-parser-n3) - Uses [N3.js](https://github.com/RubenVerborgh/N3.js) for parsing | ||
Also see [rdf-formats-common](https://github.com/rdf-ext/rdf-formats-common) if you want to get support for the most common formats. | ||
### Serializers | ||
* [Abstract](https:https://github.com/rdf-ext/rdf-ext-spec/blob/gh-pages/API.md//github.com/rdf-ext/rdf-serializer-abstract) - Can be used to implement own serializers | ||
* [JSON-LD](https://github.com/rdf-ext/rdf-serializer-jsonld) - Outputs JSON-LD in flat document form | ||
* [N-Triples](https://github.com/rdf-ext/rdf-serializer-ntriples) - Uses the `.toNT()` method to serialize N-Triples | ||
* [Turtle](https://github.com/rdf-ext/rdf-serializer-ntriples) - Uses [N3.js](https://github.com/RubenVerborgh/N3.js) for serializing | ||
* [SPARQL Update](https://github.com/rdf-ext/rdf-serializer-sparql-update) - Generates `INSERT DATA` SPARQL updates | ||
* or [JSON-LD](https://github.com/rdf-ext/rdf-serializer-jsonld-ext) - Outputs JSON-LD with prefix support and more document forms | ||
* [N-Triples](https://github.com/rdf-ext/rdf-serializer-ntriples) - Outputs N-Triples | ||
Also see [rdf-formats-common](https://github.com/rdf-ext/rdf-formats-common) if you want to get support for the most common formats. | ||
### Stores | ||
- [Abstract](http://github.com/rdf-ext/rdf-store-abstract) - Abstract implementation, can be used to build your own store | ||
- [ACL wrapper](http://github.com/nicola/rdf-store-acl) - Add ACL support to your RDF store | ||
- [File system](http://github.com/rdf-ext/rdf-store-fs) - Using the file system | ||
- [In Memory](http://github.com/rdf-ext/rdf-store-inmemory) - Store loaded in memomory | ||
- [LDP](http://github.com/rdf-ext/rdf-store-ldp) - Query an external Linked Data Platform via RESTful HTTP requests | ||
- [Local/Remote](http://github.com/nicola/rdf-store-server) - Uses a local store or a remote store depending on the IRI | ||
- [Multistore](http://github.com/nicola/rdf-store-multi) - Use multiple store depending on the IRI | ||
- [Single graph (memory)](http://github.com/rdf-ext/rdf-store-singlegraph) - Store has only a single graph | ||
- [Dataset](http://github.com/rdf-ext/rdf-store-dataset) - Wrapper around a in memory Dataset | ||
- [SPARQL](http://github.com/rdf-ext/rdf-store-sparql) - Uses the Graph Store HTTP Protocol interface | ||
- [Web](http://github.com/rdf-ext/rdf-store-web) - Query an external Linked Data via RESTful HTTP requests | ||
### Others | ||
- [Clownface](https://github.com/rdf-ext/clownface) - Simple but powerful graph traversing library | ||
- [Common Formats](https://github.com/rdf-ext/rdf-formats-common) - Loads parsers and serializers for the most common formats | ||
- [SimpleRDF](https://github.com/nicola/simplerdf/) - Simple but powerful graph to object mapping | ||
- [RDF body parser](https://github.com/rdf-ext/rdf-body-parser) - Node body parsing middleware, parses incoming RDF data and sends RDF data |
/* global describe, it */ | ||
var assert = require('assert') | ||
var rdf = require('../rdf-ext') | ||
module.exports = function () { | ||
describe('parsers', function () { | ||
it('should implement all required functions', function () { | ||
assert.equal(typeof rdf.Parsers.prototype.list, 'function') | ||
assert.equal(typeof rdf.Parsers.prototype.findParsers, 'function') | ||
assert.equal(typeof rdf.Parsers.prototype.parse, 'function') | ||
assert.equal(typeof rdf.Parsers.prototype.process, 'function') | ||
assert.equal(typeof rdf.Parsers.prototype.stream, 'function') | ||
const assert = require('assert') | ||
const EventEmitter = require('events').EventEmitter | ||
const Parsers = require('..').Parsers | ||
describe('parsers', () => { | ||
it('should implement all required functions', function () { | ||
assert.equal(typeof Parsers.prototype.find, 'function') | ||
assert.equal(typeof Parsers.prototype.list, 'function') | ||
assert.equal(typeof Parsers.prototype.import, 'function') | ||
}) | ||
describe('.find', () => { | ||
it('should return null if no parser was found', function () { | ||
let parsers = new Parsers() | ||
assert.equal(parsers.find('image/jpeg'), null) | ||
}) | ||
it('.list should return an array', function () { | ||
var mediaTypes = rdf.parsers.list() | ||
it('should return the parser class for the given media type', function () { | ||
let jsonld = {} | ||
let turtle = {} | ||
assert(Array.isArray(mediaTypes)) | ||
let parsers = new Parsers({ | ||
'application/ld+json': jsonld, | ||
'text/turtle': turtle | ||
}) | ||
assert.equal(parsers.find('text/turtle'), turtle) | ||
}) | ||
}) | ||
it('.findParsers should return null if no parser was found', function () { | ||
assert.equal(rdf.parsers.findParsers('image/jpeg'), null) | ||
describe('.list', () => { | ||
it('should return an array', function () { | ||
let parsers = new Parsers() | ||
let mediaTypes = parsers.list() | ||
assert(Array.isArray(mediaTypes)) | ||
}) | ||
it('.parse should throw an error if no parser was found', function (done) { | ||
rdf.parsers.parse('image/jpeg', '').then(function () { | ||
done('no error thrown') | ||
}).catch(function () { | ||
done() | ||
it('should return all media types', function () { | ||
let parsers = new Parsers({ | ||
'application/ld+json': {}, | ||
'text/turtle': {} | ||
}) | ||
assert.deepEqual(parsers.list(), ['application/ld+json', 'text/turtle']) | ||
}) | ||
}) | ||
it('.process should throw an error if no parser was found', function (done) { | ||
rdf.parsers.process('image/jpeg', '', function () { | ||
}).then(function () { | ||
done('no error thrown') | ||
}).catch(function () { | ||
done() | ||
}) | ||
describe('.import', () => { | ||
it('should return null if no parser was found', function () { | ||
let parsers = new Parsers() | ||
assert.equal(parsers.import('image/jpeg', ''), null) | ||
}) | ||
it('.stream should return null if no parser was found', function () { | ||
assert.equal(rdf.parsers.stream('image/jpeg', ''), null) | ||
it('should call read on the parser class for the given media type', function () { | ||
let touched = false | ||
let jsonld = {} | ||
let turtle = new EventEmitter() | ||
turtle.import = () => { | ||
touched = true | ||
} | ||
let parsers = new Parsers({ | ||
'application/ld+json': jsonld, | ||
'text/turtle': turtle | ||
}) | ||
parsers.import('text/turtle') | ||
let result = new Promise((resolve) => { | ||
turtle.on('end', () => { | ||
assert(touched) | ||
resolve() | ||
}) | ||
}) | ||
turtle.emit('end') | ||
return result | ||
}) | ||
}) | ||
} | ||
}) |
/* global describe, it */ | ||
var assert = require('assert') | ||
var rdf = require('../rdf-ext') | ||
module.exports = function () { | ||
describe('serializers', function () { | ||
it('should implement all required functions', function () { | ||
assert.equal(typeof rdf.Serializers.prototype.list, 'function') | ||
assert.equal(typeof rdf.Serializers.prototype.findSerializer, 'function') | ||
assert.equal(typeof rdf.Serializers.prototype.serialize, 'function') | ||
assert.equal(typeof rdf.Serializers.prototype.stream, 'function') | ||
const assert = require('assert') | ||
const EventEmitter = require('events').EventEmitter | ||
const Serializers = require('..').Serializers | ||
describe('serializers', () => { | ||
it('should implement all required functions', function () { | ||
assert.equal(typeof Serializers.prototype.find, 'function') | ||
assert.equal(typeof Serializers.prototype.list, 'function') | ||
assert.equal(typeof Serializers.prototype.import, 'function') | ||
}) | ||
describe('.find', () => { | ||
it('should return null if no serializer was found', function () { | ||
let serializers = new Serializers() | ||
assert.equal(serializers.find('image/jpeg'), null) | ||
}) | ||
it('.list should return an array', function () { | ||
var mediaTypes = rdf.serializers.list() | ||
it('should return the serializer class for the given media type', function () { | ||
let jsonld = {} | ||
let turtle = {} | ||
assert(Array.isArray(mediaTypes)) | ||
let serializer = new Serializers({ | ||
'application/ld+json': jsonld, | ||
'text/turtle': turtle | ||
}) | ||
assert.equal(serializer.find('text/turtle'), turtle) | ||
}) | ||
}) | ||
it('.findSerializer should return null if no serializer was found', function () { | ||
assert.equal(rdf.serializers.findSerializer('image/jpeg'), null) | ||
describe('.list', () => { | ||
it('should return an array', function () { | ||
let serializers = new Serializers() | ||
let mediaTypes = serializers.list() | ||
assert(Array.isArray(mediaTypes)) | ||
}) | ||
it('.serialize should throw an error if no serializer was found', function (done) { | ||
rdf.serializers.serialize('image/jpeg', {}).then(function () { | ||
done('no error throw') | ||
}).catch(function () { | ||
done() | ||
it('should return all media types', function () { | ||
let serializers = new Serializers({ | ||
'application/ld+json': {}, | ||
'text/turtle': {} | ||
}) | ||
assert.deepEqual(serializers.list(), ['application/ld+json', 'text/turtle']) | ||
}) | ||
}) | ||
it('.stream should return null if no serializer was found', function () { | ||
assert.equal(rdf.serializers.stream('image/jpeg'), null) | ||
describe('.import', () => { | ||
it('should return null if no serializer was found', function () { | ||
let serializers = new Serializers() | ||
assert.equal(serializers.import('image/jpeg', ''), null) | ||
}) | ||
it('should call read on the serializer class for the given media type', function () { | ||
let touched = false | ||
let jsonld = {} | ||
let turtle = new EventEmitter() | ||
turtle.import = () => { | ||
touched = true | ||
} | ||
let serializers = new Serializers({ | ||
'application/ld+json': jsonld, | ||
'text/turtle': turtle | ||
}) | ||
serializers.import('text/turtle') | ||
let result = new Promise((resolve) => { | ||
turtle.on('end', () => { | ||
assert(touched) | ||
resolve() | ||
}) | ||
}) | ||
turtle.emit('end') | ||
return result | ||
}) | ||
}) | ||
} | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2
23
0
0
1
38048
893
77
+ Addedrdf-data-model@^1.0.0
+ Addedrdf-dataset-simple@^1.0.0
+ Addedrdf-normalize@^1.0.0
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedrdf-data-model@1.0.0(transitive)
+ Addedrdf-dataset-simple@1.0.0(transitive)
+ Addedrdf-normalize@1.0.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedes6-promise@^3.0.2
- Removedrdf-graph-array@^0.3.0
- Removedrdf-store-inmemory@^0.3.0
- Removedes6-promise@3.3.1(transitive)
- Removedrdf-graph-abstract@0.3.0(transitive)
- Removedrdf-graph-array@0.3.0(transitive)
- Removedrdf-normalize@0.3.0(transitive)
- Removedrdf-store-abstract@0.3.0(transitive)
- Removedrdf-store-inmemory@0.3.0(transitive)