rdf-store-inmemory
Advanced tools
Comparing version 0.1.2 to 0.3.0-rc1
126
index.js
@@ -1,80 +0,84 @@ | ||
'use strict'; | ||
var util = require('util') | ||
var AbstractStore = require('rdf-store-abstract') | ||
function InMemoryStore (rdf) { | ||
var graphs = {}; | ||
function iriToKey (iri) { | ||
// default graph | ||
if (iri === true) { | ||
return iri | ||
} | ||
this.graph = function (iri, callback) { | ||
var graph = null; | ||
// all graphs | ||
if (!iri) { | ||
return null | ||
} | ||
if (iri === undefined) { | ||
graph = rdf.createGraph(); | ||
return iri.toString() | ||
} | ||
this.forEach(function (toAdd) { | ||
graph.addAll(toAdd); | ||
}); | ||
} else if (iri in graphs) { | ||
graph = graphs[iri]; | ||
} | ||
function InMemoryStore (options) { | ||
options = options || {} | ||
callback(graph); | ||
}; | ||
this.rdf = options.rdf || require('rdf-ext') | ||
this.graphs = {} | ||
this.match = function (iri, subject, predicate, object, callback, limit) { | ||
this.graph(iri, function (graph) { | ||
if (!graph) { | ||
callback(null); | ||
} else { | ||
callback(graph.match(subject, predicate, object, limit)); | ||
} | ||
}); | ||
}; | ||
AbstractStore.call(this) | ||
} | ||
this.add = function (iri, graph, callback) { | ||
graphs[iri] = rdf.createGraph(); | ||
graphs[iri].addAll(graph); | ||
util.inherits(InMemoryStore, AbstractStore) | ||
callback(graph); | ||
}; | ||
InMemoryStore.prototype.add = function (iri, graph, callback) { | ||
var self = this | ||
this.merge = function (iri, graph, callback) { | ||
if (iri in graphs) { | ||
graphs[iri].addAll(graph); | ||
} else { | ||
graphs[iri] = graph; | ||
} | ||
iri = iriToKey(iri) | ||
callback = callback || function () {} | ||
callback(graph); | ||
}; | ||
return new Promise(function (resolve) { | ||
self.graphs[iri] = self.rdf.createGraph() | ||
self.graphs[iri].addAll(graph) | ||
this.remove = function (iri, graph, callback) { | ||
if (iri in graphs) { | ||
graphs[iri] = rdf.Graph.difference(graphs[iri], graph); | ||
} | ||
callback(null, graph) | ||
resolve(graph) | ||
}) | ||
} | ||
callback(true); | ||
}; | ||
InMemoryStore.prototype.delete = function (iri, callback) { | ||
var self = this | ||
this.removeMatches = function (iri, subject, predicate, object, callback) { | ||
if (iri in graphs) { | ||
graphs[iri].removeMatches(subject, predicate, object); | ||
iri = iriToKey(iri) | ||
callback = callback || function () {} | ||
return new Promise(function (resolve) { | ||
if (iri in self.graphs) { | ||
delete self.graphs[iri] | ||
} | ||
callback(true); | ||
}; | ||
callback() | ||
resolve() | ||
}) | ||
} | ||
this.delete = function (iri, callback) { | ||
if (iri in graphs) { | ||
delete graphs[iri]; | ||
InMemoryStore.prototype.graph = function (iri, callback) { | ||
var self = this | ||
iri = iriToKey(iri) | ||
callback = callback || function () {} | ||
return new Promise(function (resolve) { | ||
var graph = null | ||
if (iri) { | ||
graph = self.graphs[iri] | ||
} else { | ||
graph = self.rdf.createGraph() | ||
Object.keys(self.graphs).forEach(function (iri) { | ||
graph.addAll(self.graphs[iri]) | ||
}) | ||
} | ||
callback(true); | ||
}; | ||
callback(null, graph) | ||
resolve(graph) | ||
}) | ||
} | ||
this.forEach = function (callback) { | ||
Object.keys(graphs).forEach(function (iri) { | ||
callback(graphs[iri], iri); | ||
}); | ||
}; | ||
}; | ||
module.exports = InMemoryStore; | ||
module.exports = InMemoryStore |
{ | ||
"name": "rdf-store-inmemory", | ||
"version": "0.1.2", | ||
"version": "0.3.0-rc1", | ||
"description": "In Memory RDF Store that follows the RDF Interface specification", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"lint": "standard", | ||
"test": "node_modules/.bin/mocha" | ||
}, | ||
@@ -24,3 +25,10 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/rdf-ext/rdf-store-inmemory" | ||
"homepage": "https://github.com/rdf-ext/rdf-store-inmemory", | ||
"dependencies": { | ||
"rdf-ext": "^0.3.0-rc1", | ||
"rdf-store-abstract": "^0.3.0-rc1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.3.3" | ||
} | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
8974
5
218
0
1
2
1
2
+ Addedrdf-ext@^0.3.0-rc1
+ Addedes6-promise@3.3.1(transitive)
+ Addedrdf-ext@0.3.0(transitive)
+ Addedrdf-graph-abstract@0.3.0(transitive)
+ Addedrdf-graph-array@0.3.0(transitive)
+ Addedrdf-normalize@0.3.0(transitive)
+ Addedrdf-store-abstract@0.3.0(transitive)
+ Addedrdf-store-inmemory@0.3.0(transitive)