rdflib 2.2.16 → 2.2.17-31798263
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rdflib.min.js +5 -5
- package/dist/rdflib.min.js.map +1 -1
- package/esm/factories/extended-term-factory.js +2 -2
- package/esm/factories/rdflib-data-factory.js +2 -2
- package/esm/fetcher.js +3 -3
- package/esm/formula.js +5 -30
- package/esm/index.js +2 -3
- package/esm/query.js +2 -3
- package/esm/serialize.js +12 -3
- package/esm/serializer.js +44 -0
- package/esm/store.js +24 -0
- package/lib/factories/extended-term-factory.js +2 -2
- package/lib/factories/rdflib-data-factory.js +2 -2
- package/lib/fetcher.js +6 -4
- package/lib/formula.d.ts +2 -1
- package/lib/formula.js +5 -30
- package/lib/index.js +2 -4
- package/lib/jsonldparser.d.ts +1 -1
- package/lib/query.js +3 -4
- package/lib/rdfxmlparser.d.ts +1 -1
- package/lib/serialize.d.ts +7 -4
- package/lib/serialize.js +12 -3
- package/lib/serializer.d.ts +13 -0
- package/lib/serializer.js +44 -0
- package/lib/store.d.ts +1 -0
- package/lib/store.js +25 -0
- package/package.json +23 -23
- package/src/formula.ts +5 -27
- package/src/serialize.ts +19 -5
- package/src/serializer.js +40 -0
- package/src/store.ts +23 -0
package/lib/store.js
CHANGED
|
@@ -51,12 +51,18 @@ var _namedNode = _interopRequireDefault(require("./named-node"));
|
|
|
51
51
|
|
|
52
52
|
var _index = require("./index");
|
|
53
53
|
|
|
54
|
+
var _serialize2 = _interopRequireDefault(require("./serialize"));
|
|
55
|
+
|
|
54
56
|
var _blankNode = _interopRequireDefault(require("./blank-node"));
|
|
55
57
|
|
|
56
58
|
var _defaultGraph = _interopRequireDefault(require("./default-graph"));
|
|
57
59
|
|
|
58
60
|
var _literal = _interopRequireDefault(require("./literal"));
|
|
59
61
|
|
|
62
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
63
|
+
|
|
64
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
65
|
+
|
|
60
66
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
61
67
|
|
|
62
68
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -1159,6 +1165,11 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
|
|
|
1159
1165
|
|
|
1160
1166
|
if (prefix.slice(0, 2) === 'ns' || prefix.slice(0, 7) === 'default') {
|
|
1161
1167
|
return;
|
|
1168
|
+
} // remove any prefix that currently targets nsuri
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
for (var existingPrefix in this.namespaces) {
|
|
1172
|
+
if (this.namespaces[existingPrefix] == nsuri) delete this.namespaces[existingPrefix];
|
|
1162
1173
|
}
|
|
1163
1174
|
|
|
1164
1175
|
this.namespaces[prefix] = nsuri;
|
|
@@ -1291,6 +1302,20 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
|
|
|
1291
1302
|
|
|
1292
1303
|
return res;
|
|
1293
1304
|
}
|
|
1305
|
+
}, {
|
|
1306
|
+
key: "serialize",
|
|
1307
|
+
value: function serialize(base, contentType, provenance, options) {
|
|
1308
|
+
var _options;
|
|
1309
|
+
|
|
1310
|
+
// override Formula.serialize to force the serializer namespace prefixes
|
|
1311
|
+
// to those of this IndexedFormula
|
|
1312
|
+
// if namespaces are explicitly passed in options, let them override the existing namespaces in this formula
|
|
1313
|
+
var namespaces = (_options = options) !== null && _options !== void 0 && _options.namespaces ? _objectSpread(_objectSpread({}, this.namespaces), options.namespaces) : _objectSpread({}, this.namespaces);
|
|
1314
|
+
options = _objectSpread(_objectSpread({}, options || {}), {}, {
|
|
1315
|
+
namespaces: namespaces
|
|
1316
|
+
});
|
|
1317
|
+
return (0, _serialize2.default)(provenance, this, base, contentType, undefined, options);
|
|
1318
|
+
}
|
|
1294
1319
|
}], [{
|
|
1295
1320
|
key: "defaultGraphURI",
|
|
1296
1321
|
get: function get() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rdflib",
|
|
3
3
|
"description": "an RDF library for node.js. Suitable for client and server side.",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.17-31798263",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=6.0"
|
|
7
7
|
},
|
|
@@ -44,48 +44,48 @@
|
|
|
44
44
|
"homepage": "http://github.com/linkeddata/rdflib.js",
|
|
45
45
|
"bugs": "http://github.com/linkeddata/rdflib.js/issues",
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@babel/runtime": "^7.16.
|
|
47
|
+
"@babel/runtime": "^7.16.0",
|
|
48
48
|
"@xmldom/xmldom": "^0.8.0",
|
|
49
|
-
"async": "^3.2.
|
|
50
|
-
"cross-fetch": "^3.1.
|
|
49
|
+
"async": "^3.2.2",
|
|
50
|
+
"cross-fetch": "^3.1.4",
|
|
51
51
|
"jsonld": "^5.2.0",
|
|
52
|
-
"n3": "^1.
|
|
52
|
+
"n3": "^1.12.2",
|
|
53
53
|
"solid-namespace": "^0.5.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@babel/cli": "^7.16.
|
|
57
|
-
"@babel/core": "^7.16.
|
|
58
|
-
"@babel/plugin-proposal-class-properties": "^7.16.
|
|
59
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
60
|
-
"@babel/preset-env": "^7.16.
|
|
61
|
-
"@babel/preset-typescript": "^7.16.
|
|
62
|
-
"@babel/register": "^7.16.
|
|
63
|
-
"@types/chai": "^4.
|
|
56
|
+
"@babel/cli": "^7.16.0",
|
|
57
|
+
"@babel/core": "^7.16.0",
|
|
58
|
+
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
59
|
+
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
60
|
+
"@babel/preset-env": "^7.16.0",
|
|
61
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
62
|
+
"@babel/register": "^7.16.0",
|
|
63
|
+
"@types/chai": "^4.2.22",
|
|
64
64
|
"@types/dirty-chai": "^2.0.2",
|
|
65
65
|
"@types/express": "^4.17.13",
|
|
66
66
|
"@types/jsonld": "^1.5.6",
|
|
67
|
-
"@types/mocha": "^9.
|
|
67
|
+
"@types/mocha": "^9.0.0",
|
|
68
68
|
"@types/rdf-js": "^4.0.1",
|
|
69
|
-
"@types/sinon-chai": "^3.2.
|
|
69
|
+
"@types/sinon-chai": "^3.2.5",
|
|
70
70
|
"babel-loader": "^8.2.3",
|
|
71
|
-
"chai": "^4.3.
|
|
71
|
+
"chai": "^4.3.4",
|
|
72
72
|
"diff": "^5.0.0",
|
|
73
73
|
"dirty-chai": "^2.0.1",
|
|
74
74
|
"eslint": "^7.32.0",
|
|
75
75
|
"fs-grep": "^0.0.5",
|
|
76
|
-
"mocha": "^9.
|
|
77
|
-
"nock": "^13.
|
|
78
|
-
"node-fetch": "^2.6.
|
|
76
|
+
"mocha": "^9.1.3",
|
|
77
|
+
"nock": "^13.1.4",
|
|
78
|
+
"node-fetch": "^2.6.6",
|
|
79
79
|
"node-mkdirp": "0.0.1",
|
|
80
80
|
"rimraf": "^3.0.2",
|
|
81
81
|
"sinon": "^12.0.1",
|
|
82
82
|
"sinon-chai": "^3.7.0",
|
|
83
83
|
"source-map-loader": "^1.1.3",
|
|
84
|
-
"typedoc": "^0.22.
|
|
85
|
-
"typescript": "^4.
|
|
84
|
+
"typedoc": "^0.22.10",
|
|
85
|
+
"typescript": "^4.4.4",
|
|
86
86
|
"webpack": "^4.46.0",
|
|
87
|
-
"webpack-cli": "^4.9.
|
|
88
|
-
"webpack-dev-server": "^4.
|
|
87
|
+
"webpack-cli": "^4.9.1",
|
|
88
|
+
"webpack-dev-server": "^4.4.0",
|
|
89
89
|
"wrapper-webpack-plugin": "^2.1.0"
|
|
90
90
|
},
|
|
91
91
|
"scripts": {
|
package/src/formula.ts
CHANGED
|
@@ -5,7 +5,7 @@ import log from './log'
|
|
|
5
5
|
import RDFlibNamedNode from './named-node'
|
|
6
6
|
import Namespace from './namespace'
|
|
7
7
|
import Node from './node-internal'
|
|
8
|
-
import
|
|
8
|
+
import serialize from './serialize'
|
|
9
9
|
import Statement from './statement'
|
|
10
10
|
import {
|
|
11
11
|
Bindings,
|
|
@@ -721,33 +721,11 @@ export default class Formula extends Node {
|
|
|
721
721
|
* @param base - The base string
|
|
722
722
|
* @param contentType - The content type of the syntax to use
|
|
723
723
|
* @param provenance - The provenance URI
|
|
724
|
+
* @param options - options to pass to the serializer, as defined in serialize method
|
|
724
725
|
*/
|
|
725
|
-
serialize (base, contentType, provenance) {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
let sz
|
|
729
|
-
sz = Serializer(this)
|
|
730
|
-
sz.suggestNamespaces(this.ns)
|
|
731
|
-
sz.setBase(base)
|
|
732
|
-
if (provenance) {
|
|
733
|
-
sts = this.statementsMatching(void 0, void 0, void 0, provenance)
|
|
734
|
-
} else {
|
|
735
|
-
sts = this.statements
|
|
736
|
-
}
|
|
737
|
-
switch (
|
|
738
|
-
contentType != null ? contentType : 'text/n3') {
|
|
739
|
-
case 'application/rdf+xml':
|
|
740
|
-
documentString = sz.statementsToXML(sts)
|
|
741
|
-
break
|
|
742
|
-
case 'text/n3':
|
|
743
|
-
case 'text/turtle':
|
|
744
|
-
documentString = sz.statementsToN3(sts)
|
|
745
|
-
break
|
|
746
|
-
default:
|
|
747
|
-
throw new Error('serialize: Content-type ' + contentType +
|
|
748
|
-
' not supported.')
|
|
749
|
-
}
|
|
750
|
-
return documentString
|
|
726
|
+
serialize (base, contentType, provenance, options?) {
|
|
727
|
+
// delegate the graph serialization to the implementation in ./serialize
|
|
728
|
+
return serialize(provenance, this, base, contentType, undefined, options);
|
|
751
729
|
}
|
|
752
730
|
|
|
753
731
|
/**
|
package/src/serialize.ts
CHANGED
|
@@ -21,9 +21,9 @@ import { BlankNode, NamedNode } from './tf-types'
|
|
|
21
21
|
*/
|
|
22
22
|
export default function serialize (
|
|
23
23
|
/** The graph or nodes that should be serialized */
|
|
24
|
-
target: Formula | NamedNode | BlankNode,
|
|
24
|
+
target: Formula | NamedNode | BlankNode | null,
|
|
25
25
|
/** The store */
|
|
26
|
-
kb
|
|
26
|
+
kb: Formula,
|
|
27
27
|
base?: unknown,
|
|
28
28
|
/**
|
|
29
29
|
* The mime type.
|
|
@@ -36,10 +36,14 @@ export default function serialize (
|
|
|
36
36
|
* A string of letters, each of which set an options
|
|
37
37
|
* e.g. `deinprstux`
|
|
38
38
|
*/
|
|
39
|
-
flags
|
|
39
|
+
flags?: string,
|
|
40
|
+
/**
|
|
41
|
+
* A set of [prefix, uri] pairs that define namespace prefixes
|
|
42
|
+
*/
|
|
43
|
+
namespaces?: Record<string, string>
|
|
40
44
|
}
|
|
41
45
|
): string | undefined {
|
|
42
|
-
base = base || target
|
|
46
|
+
base = base || target?.value
|
|
43
47
|
const opts = options || {}
|
|
44
48
|
contentType = contentType || TurtleContentType // text/n3 if complex?
|
|
45
49
|
var documentString: string | undefined = undefined
|
|
@@ -48,7 +52,17 @@ export default function serialize (
|
|
|
48
52
|
if ((opts as any).flags) sz.setFlags((opts as any).flags)
|
|
49
53
|
var newSts = kb!.statementsMatching(undefined, undefined, undefined, target as NamedNode)
|
|
50
54
|
var n3String: string
|
|
51
|
-
|
|
55
|
+
|
|
56
|
+
// If an IndexedFormula, use the namespaces from the given graph as suggestions
|
|
57
|
+
if ('namespaces' in kb) {
|
|
58
|
+
sz.suggestNamespaces( (kb as IndexedFormula).namespaces);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// use the provided options.namespaces are mandatory prefixes
|
|
62
|
+
if (opts.namespaces) {
|
|
63
|
+
sz.setNamespaces( opts.namespaces);
|
|
64
|
+
}
|
|
65
|
+
|
|
52
66
|
sz.setBase(base)
|
|
53
67
|
switch (contentType) {
|
|
54
68
|
case RDFXMLContentType:
|
package/src/serializer.js
CHANGED
|
@@ -73,6 +73,46 @@ export class Serializer {
|
|
|
73
73
|
return this.store.fromNT(s)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Defines a set of [prefix, namespace] pairs to be uised by this Serializer instance.
|
|
78
|
+
* Overrides previous prefixes if any
|
|
79
|
+
* @param namespaces
|
|
80
|
+
* @return {Serializer}
|
|
81
|
+
*/
|
|
82
|
+
setNamespaces(namespaces) {
|
|
83
|
+
for (var px in namespaces) {
|
|
84
|
+
this.setPrefix(px, namespaces[px])
|
|
85
|
+
}
|
|
86
|
+
return this
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Defines a namespace prefix, overriding any existing prefix for that URI
|
|
91
|
+
* @param prefix
|
|
92
|
+
* @param uri
|
|
93
|
+
*/
|
|
94
|
+
setPrefix(prefix, uri) {
|
|
95
|
+
if (prefix.slice(0, 7) === 'default') return // Try to weed these out
|
|
96
|
+
if (prefix.slice(0, 2) === 'ns') return // From others inferior algos
|
|
97
|
+
if (!prefix || !uri) return // empty strings not suitable
|
|
98
|
+
|
|
99
|
+
// remove any existing prefix targeting this uri
|
|
100
|
+
// for (let existingPrefix in this.namespaces) {
|
|
101
|
+
// if (this.namespaces[existingPrefix] == uri)
|
|
102
|
+
// delete this.namespaces[existingPrefix];
|
|
103
|
+
// }
|
|
104
|
+
|
|
105
|
+
// remove any existing mapping for this prefix
|
|
106
|
+
for (let existingNs in this.prefixes) {
|
|
107
|
+
if (this.prefixes[existingNs] == prefix)
|
|
108
|
+
delete this.prefixes[existingNs];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.prefixes[uri] = prefix
|
|
112
|
+
this.namespaces[prefix] = uri
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
76
116
|
/* Accumulate Namespaces
|
|
77
117
|
**
|
|
78
118
|
** These are only hints. If two overlap, only one gets used
|
package/src/store.ts
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
Term,
|
|
53
53
|
} from './tf-types'
|
|
54
54
|
import { namedNode } from './index'
|
|
55
|
+
import serialize from "./serialize";
|
|
55
56
|
import BlankNode from './blank-node'
|
|
56
57
|
import DefaultGraph from './default-graph'
|
|
57
58
|
import Empty from './empty'
|
|
@@ -1046,6 +1047,13 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
1046
1047
|
if (prefix.slice(0, 2) === 'ns' || prefix.slice(0, 7) === 'default') {
|
|
1047
1048
|
return
|
|
1048
1049
|
}
|
|
1050
|
+
|
|
1051
|
+
// remove any prefix that currently targets nsuri
|
|
1052
|
+
for (let existingPrefix in this.namespaces) {
|
|
1053
|
+
if (this.namespaces[existingPrefix] == nsuri)
|
|
1054
|
+
delete this.namespaces[existingPrefix];
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1049
1057
|
this.namespaces[prefix] = nsuri
|
|
1050
1058
|
}
|
|
1051
1059
|
|
|
@@ -1154,5 +1162,20 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
1154
1162
|
}
|
|
1155
1163
|
return res
|
|
1156
1164
|
}
|
|
1165
|
+
|
|
1166
|
+
serialize (base, contentType, provenance, options?) {
|
|
1167
|
+
|
|
1168
|
+
// override Formula.serialize to force the serializer namespace prefixes
|
|
1169
|
+
// to those of this IndexedFormula
|
|
1170
|
+
|
|
1171
|
+
// if namespaces are explicitly passed in options, let them override the existing namespaces in this formula
|
|
1172
|
+
const namespaces = options?.namespaces ? {...this.namespaces, ...options.namespaces} : {...this.namespaces};
|
|
1173
|
+
|
|
1174
|
+
options = {
|
|
1175
|
+
...(options || {}),
|
|
1176
|
+
namespaces
|
|
1177
|
+
}
|
|
1178
|
+
return serialize(provenance, this, base, contentType, undefined, options);
|
|
1179
|
+
}
|
|
1157
1180
|
}
|
|
1158
1181
|
IndexedFormula.handleRDFType = handleRDFType
|