rdflib 2.2.17 → 2.2.18-ce0e0a33
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 +2 -61
- package/dist/rdflib.min.js.LICENSE.txt +68 -0
- 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 +10 -2
- package/esm/jsonldparser.js +33 -17
- package/esm/query.js +3 -2
- package/esm/rdfxmlparser.js +1 -1
- package/esm/serialize.js +12 -3
- package/esm/serializer.js +54 -3
- 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 +4 -6
- package/lib/formula.d.ts +2 -1
- package/lib/formula.js +5 -30
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -2
- package/lib/jsonldparser.d.ts +1 -1
- package/lib/jsonldparser.js +32 -17
- package/lib/query.js +4 -3
- package/lib/rdfxmlparser.d.ts +2 -2
- package/lib/rdfxmlparser.js +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 +54 -3
- package/lib/store.d.ts +1 -0
- package/lib/store.js +25 -0
- package/package.json +39 -39
- package/src/formula.ts +5 -27
- package/src/index.ts +6 -0
- package/src/jsonldparser.js +38 -17
- package/src/rdfxmlparser.js +1 -1
- package/src/serialize.ts +19 -5
- package/src/serializer.js +49 -3
- package/src/store.ts +23 -0
package/lib/jsonldparser.js
CHANGED
|
@@ -86,29 +86,44 @@ function jsonldParser(str, kb, base, callback) {
|
|
|
86
86
|
base: baseString
|
|
87
87
|
}).then(function (flattened) {
|
|
88
88
|
return flattened.reduce(function (store, flatResource) {
|
|
89
|
-
|
|
89
|
+
kb = processResource(kb, base, flatResource);
|
|
90
|
+
return kb;
|
|
91
|
+
}, kb);
|
|
92
|
+
}).then(callback).catch(callback);
|
|
93
|
+
}
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
function processResource(kb, base, flatResource) {
|
|
96
|
+
var id = flatResource['@id'] ? kb.rdfFactory.namedNode(flatResource['@id']) : kb.rdfFactory.blankNode();
|
|
93
97
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
98
|
+
for (var _i = 0, _Object$keys = Object.keys(flatResource); _i < _Object$keys.length; _i++) {
|
|
99
|
+
var property = _Object$keys[_i];
|
|
97
100
|
|
|
98
|
-
|
|
101
|
+
if (property === '@id') {
|
|
102
|
+
continue;
|
|
103
|
+
} else if (property == '@graph') {
|
|
104
|
+
// the JSON-LD flattened structure may contain nested graphs
|
|
105
|
+
// the id value for this object is the new base (named graph id) for all nested flat resources
|
|
106
|
+
var graphId = id; // this is an array of resources
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
} else {
|
|
105
|
-
kb.addStatement(createStatement(kb, id, property, value, base));
|
|
106
|
-
}
|
|
108
|
+
var nestedFlatResources = flatResource[property]; // recursively process all flat resources in the array, but with the graphId as base.
|
|
109
|
+
|
|
110
|
+
for (var i = 0; i < nestedFlatResources.length; i++) {
|
|
111
|
+
kb = processResource(kb, graphId, nestedFlatResources[i]);
|
|
107
112
|
}
|
|
113
|
+
}
|
|
108
114
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
var value = flatResource[property];
|
|
116
|
+
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
for (var _i2 = 0; _i2 < value.length; _i2++) {
|
|
119
|
+
kb.addStatement(createStatement(kb, id, property, value[_i2], base));
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
kb.addStatement(createStatement(kb, id, property, value, base));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return kb;
|
|
112
127
|
}
|
|
113
128
|
/**
|
|
114
129
|
* Create statement quad depending on @type being a type node
|
package/lib/query.js
CHANGED
|
@@ -8,6 +8,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.Query = void 0;
|
|
9
9
|
exports.indexedFormulaQuery = indexedFormulaQuery;
|
|
10
10
|
|
|
11
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
+
|
|
11
13
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
14
|
|
|
13
15
|
var _store = _interopRequireDefault(require("./store"));
|
|
@@ -41,7 +43,7 @@ var _uri = require("./uri");
|
|
|
41
43
|
/**
|
|
42
44
|
* Query class, for tracking queries the user has in the UI.
|
|
43
45
|
*/
|
|
44
|
-
var Query = function Query(name, id) {
|
|
46
|
+
var Query = /*#__PURE__*/(0, _createClass2.default)(function Query(name, id) {
|
|
45
47
|
(0, _classCallCheck2.default)(this, Query);
|
|
46
48
|
this.pat = new _store.default(); // The pattern to search for
|
|
47
49
|
|
|
@@ -50,7 +52,7 @@ var Query = function Query(name, id) {
|
|
|
50
52
|
|
|
51
53
|
this.name = name;
|
|
52
54
|
this.id = id;
|
|
53
|
-
};
|
|
55
|
+
});
|
|
54
56
|
/**
|
|
55
57
|
* This function will match a pattern to the current Store
|
|
56
58
|
*
|
|
@@ -67,7 +69,6 @@ var Query = function Query(name, id) {
|
|
|
67
69
|
* @param onDone - callback when query finished
|
|
68
70
|
*/
|
|
69
71
|
|
|
70
|
-
|
|
71
72
|
exports.Query = Query;
|
|
72
73
|
|
|
73
74
|
function indexedFormulaQuery(myQuery, callback, fetcher, onDone) {
|
package/lib/rdfxmlparser.d.ts
CHANGED
|
@@ -40,11 +40,11 @@ export default class RDFParser {
|
|
|
40
40
|
getAttributeNodeNS(node: any, uri: any, name: any): any;
|
|
41
41
|
/**
|
|
42
42
|
* Build our initial scope frame and parse the DOM into triples
|
|
43
|
-
* @param {
|
|
43
|
+
* @param {HTMLDocument} document The DOM to parse
|
|
44
44
|
* @param {String} base The base URL to use
|
|
45
45
|
* @param {Object} why The context to which this resource belongs
|
|
46
46
|
*/
|
|
47
|
-
parse(document:
|
|
47
|
+
parse(document: HTMLDocument, base: string, why: any): boolean;
|
|
48
48
|
base: string | undefined;
|
|
49
49
|
parseDOM(frame: any): void;
|
|
50
50
|
/**
|
package/lib/rdfxmlparser.js
CHANGED
|
@@ -269,7 +269,7 @@ var RDFParser = /*#__PURE__*/function () {
|
|
|
269
269
|
}
|
|
270
270
|
/**
|
|
271
271
|
* Build our initial scope frame and parse the DOM into triples
|
|
272
|
-
* @param {
|
|
272
|
+
* @param {HTMLDocument} document The DOM to parse
|
|
273
273
|
* @param {String} base The base URL to use
|
|
274
274
|
* @param {Object} why The context to which this resource belongs
|
|
275
275
|
*/
|
package/lib/serialize.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import Formula from './formula';
|
|
2
2
|
import { ContentType } from './types';
|
|
3
|
-
import IndexedFormula from './store';
|
|
4
3
|
import { BlankNode, NamedNode } from './tf-types';
|
|
5
4
|
/**
|
|
6
5
|
* Serialize to the appropriate format
|
|
7
6
|
*/
|
|
8
7
|
export default function serialize(
|
|
9
8
|
/** The graph or nodes that should be serialized */
|
|
10
|
-
target: Formula | NamedNode | BlankNode,
|
|
9
|
+
target: Formula | NamedNode | BlankNode | null,
|
|
11
10
|
/** The store */
|
|
12
|
-
kb
|
|
11
|
+
kb: Formula, base?: unknown,
|
|
13
12
|
/**
|
|
14
13
|
* The mime type.
|
|
15
14
|
* Defaults to Turtle.
|
|
@@ -19,5 +18,9 @@ contentType?: string | ContentType, callback?: (err: Error | undefined | null, r
|
|
|
19
18
|
* A string of letters, each of which set an options
|
|
20
19
|
* e.g. `deinprstux`
|
|
21
20
|
*/
|
|
22
|
-
flags
|
|
21
|
+
flags?: string;
|
|
22
|
+
/**
|
|
23
|
+
* A set of [prefix, uri] pairs that define namespace prefixes
|
|
24
|
+
*/
|
|
25
|
+
namespaces?: Record<string, string>;
|
|
23
26
|
}): string | undefined;
|
package/lib/serialize.js
CHANGED
|
@@ -32,7 +32,7 @@ kb, base,
|
|
|
32
32
|
* Defaults to Turtle.
|
|
33
33
|
*/
|
|
34
34
|
contentType, callback, options) {
|
|
35
|
-
base = base || target.value;
|
|
35
|
+
base = base || (target === null || target === void 0 ? void 0 : target.value);
|
|
36
36
|
var opts = options || {};
|
|
37
37
|
contentType = contentType || _types.TurtleContentType; // text/n3 if complex?
|
|
38
38
|
|
|
@@ -42,8 +42,17 @@ contentType, callback, options) {
|
|
|
42
42
|
var sz = (0, _serializer.default)(kb);
|
|
43
43
|
if (opts.flags) sz.setFlags(opts.flags);
|
|
44
44
|
var newSts = kb.statementsMatching(undefined, undefined, undefined, target);
|
|
45
|
-
var n3String;
|
|
46
|
-
|
|
45
|
+
var n3String; // If an IndexedFormula, use the namespaces from the given graph as suggestions
|
|
46
|
+
|
|
47
|
+
if ('namespaces' in kb) {
|
|
48
|
+
sz.suggestNamespaces(kb.namespaces);
|
|
49
|
+
} // use the provided options.namespaces are mandatory prefixes
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if (opts.namespaces) {
|
|
53
|
+
sz.setNamespaces(opts.namespaces);
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
sz.setBase(base);
|
|
48
57
|
|
|
49
58
|
switch (contentType) {
|
package/lib/serializer.d.ts
CHANGED
|
@@ -25,6 +25,19 @@ export class Serializer {
|
|
|
25
25
|
setFlags(flags: any): Serializer;
|
|
26
26
|
toStr(x: any): any;
|
|
27
27
|
fromStr(s: any): any;
|
|
28
|
+
/**
|
|
29
|
+
* Defines a set of [prefix, namespace] pairs to be uised by this Serializer instance.
|
|
30
|
+
* Overrides previous prefixes if any
|
|
31
|
+
* @param namespaces
|
|
32
|
+
* @return {Serializer}
|
|
33
|
+
*/
|
|
34
|
+
setNamespaces(namespaces: any): Serializer;
|
|
35
|
+
/**
|
|
36
|
+
* Defines a namespace prefix, overriding any existing prefix for that URI
|
|
37
|
+
* @param prefix
|
|
38
|
+
* @param uri
|
|
39
|
+
*/
|
|
40
|
+
setPrefix(prefix: any, uri: any): void;
|
|
28
41
|
suggestPrefix(prefix: any, uri: any): void;
|
|
29
42
|
suggestNamespaces(namespaces: any): Serializer;
|
|
30
43
|
checkIntegrity(): void;
|
package/lib/serializer.js
CHANGED
|
@@ -122,6 +122,50 @@ var Serializer = /*#__PURE__*/function () {
|
|
|
122
122
|
|
|
123
123
|
return this.store.fromNT(s);
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Defines a set of [prefix, namespace] pairs to be uised by this Serializer instance.
|
|
127
|
+
* Overrides previous prefixes if any
|
|
128
|
+
* @param namespaces
|
|
129
|
+
* @return {Serializer}
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
}, {
|
|
133
|
+
key: "setNamespaces",
|
|
134
|
+
value: function setNamespaces(namespaces) {
|
|
135
|
+
for (var px in namespaces) {
|
|
136
|
+
this.setPrefix(px, namespaces[px]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Defines a namespace prefix, overriding any existing prefix for that URI
|
|
143
|
+
* @param prefix
|
|
144
|
+
* @param uri
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
}, {
|
|
148
|
+
key: "setPrefix",
|
|
149
|
+
value: function setPrefix(prefix, uri) {
|
|
150
|
+
if (prefix.slice(0, 7) === 'default') return; // Try to weed these out
|
|
151
|
+
|
|
152
|
+
if (prefix.slice(0, 2) === 'ns') return; // From others inferior algos
|
|
153
|
+
|
|
154
|
+
if (!prefix || !uri) return; // empty strings not suitable
|
|
155
|
+
// remove any existing prefix targeting this uri
|
|
156
|
+
// for (let existingPrefix in this.namespaces) {
|
|
157
|
+
// if (this.namespaces[existingPrefix] == uri)
|
|
158
|
+
// delete this.namespaces[existingPrefix];
|
|
159
|
+
// }
|
|
160
|
+
// remove any existing mapping for this prefix
|
|
161
|
+
|
|
162
|
+
for (var existingNs in this.prefixes) {
|
|
163
|
+
if (this.prefixes[existingNs] == prefix) delete this.prefixes[existingNs];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
this.prefixes[uri] = prefix;
|
|
167
|
+
this.namespaces[prefix] = uri;
|
|
168
|
+
}
|
|
125
169
|
/* Accumulate Namespaces
|
|
126
170
|
**
|
|
127
171
|
** These are only hints. If two overlap, only one gets used
|
|
@@ -405,13 +449,13 @@ var Serializer = /*#__PURE__*/function () {
|
|
|
405
449
|
|
|
406
450
|
for (var i = 0; i < tree.length; i++) {
|
|
407
451
|
var branch = tree[i];
|
|
408
|
-
var s2 = typeof branch === 'string' ? branch : treeToLine(branch); // Note the space before the dot in case statement ends 123. which is in fact allowed but be conservative.
|
|
452
|
+
var s2 = typeof branch === 'string' ? branch : treeToLine(branch); // Note the space before the dot in case statement ends with 123 or colon. which is in fact allowed but be conservative.
|
|
409
453
|
|
|
410
454
|
if (i !== 0) {
|
|
411
455
|
var ch = str.slice(-1) || ' ';
|
|
412
456
|
|
|
413
457
|
if (s2 === ',' || s2 === ';') {// no gap
|
|
414
|
-
} else if (s2 === '.' && !'0123456789
|
|
458
|
+
} else if (s2 === '.' && !'0123456789.:'.includes(ch)) {// no gap except after number and colon
|
|
415
459
|
// no gap
|
|
416
460
|
} else {
|
|
417
461
|
str += ' '; // separate from previous token
|
|
@@ -454,7 +498,14 @@ var Serializer = /*#__PURE__*/function () {
|
|
|
454
498
|
if (typeof branch === 'string') {
|
|
455
499
|
if (branch.length === 1 && str.slice(-1) === '\n') {
|
|
456
500
|
if (',.;'.indexOf(branch) >= 0) {
|
|
457
|
-
str = str.slice(0, -1)
|
|
501
|
+
str = str.slice(0, -1); // be conservative and ensure a whitespace between some chars and a final dot, as in treeToLine above
|
|
502
|
+
|
|
503
|
+
if (branch == '.' && '0123456789.:'.includes(str.charAt(str.length - 1))) {
|
|
504
|
+
str += ' ';
|
|
505
|
+
lastLength += 1;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
str += branch + '\n'; // slip punct'n on end
|
|
458
509
|
|
|
459
510
|
lastLength += 1;
|
|
460
511
|
continue;
|
package/lib/store.d.ts
CHANGED
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); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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,11 +1,11 @@
|
|
|
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.
|
|
5
|
-
"engines": {
|
|
6
|
-
"node": ">=6.0"
|
|
7
|
-
},
|
|
4
|
+
"version": "2.2.18-ce0e0a33",
|
|
8
5
|
"private": false,
|
|
6
|
+
"browserslist": [
|
|
7
|
+
"> 0.5%"
|
|
8
|
+
],
|
|
9
9
|
"author": {
|
|
10
10
|
"name": "Tim BL",
|
|
11
11
|
"email": "timbl@w3.org"
|
|
@@ -44,49 +44,49 @@
|
|
|
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.
|
|
48
|
-
"@xmldom/xmldom": "^0.8.
|
|
49
|
-
"async": "^3.2.
|
|
50
|
-
"cross-fetch": "^3.1.
|
|
47
|
+
"@babel/runtime": "^7.17.8",
|
|
48
|
+
"@xmldom/xmldom": "^0.8.1",
|
|
49
|
+
"async": "^3.2.3",
|
|
50
|
+
"cross-fetch": "^3.1.5",
|
|
51
51
|
"jsonld": "^5.2.0",
|
|
52
|
-
"n3": "^1.
|
|
52
|
+
"n3": "^1.15.0",
|
|
53
53
|
"solid-namespace": "^0.5.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@babel/cli": "^7.
|
|
57
|
-
"@babel/core": "^7.
|
|
58
|
-
"@babel/plugin-proposal-class-properties": "^7.16.
|
|
59
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
60
|
-
"@babel/preset-env": "^7.16.
|
|
61
|
-
"@babel/preset-typescript": "^7.16.
|
|
62
|
-
"@babel/register": "^7.
|
|
63
|
-
"@types/chai": "^4.
|
|
56
|
+
"@babel/cli": "^7.17.6",
|
|
57
|
+
"@babel/core": "^7.17.8",
|
|
58
|
+
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
59
|
+
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
60
|
+
"@babel/preset-env": "^7.16.11",
|
|
61
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
62
|
+
"@babel/register": "^7.17.7",
|
|
63
|
+
"@types/chai": "^4.3.0",
|
|
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.
|
|
68
|
-
"@types/rdf-js": "^4.0.
|
|
69
|
-
"@types/sinon-chai": "^3.2.
|
|
70
|
-
"babel-loader": "^8.2.
|
|
71
|
-
"chai": "^4.3.
|
|
67
|
+
"@types/mocha": "^9.1.0",
|
|
68
|
+
"@types/rdf-js": "^4.0.2",
|
|
69
|
+
"@types/sinon-chai": "^3.2.8",
|
|
70
|
+
"babel-loader": "^8.2.4",
|
|
71
|
+
"chai": "^4.3.6",
|
|
72
72
|
"diff": "^5.0.0",
|
|
73
73
|
"dirty-chai": "^2.0.1",
|
|
74
74
|
"eslint": "^7.32.0",
|
|
75
|
-
"fs-grep": "
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"node-
|
|
80
|
-
"
|
|
75
|
+
"fs-grep": "0.0.5",
|
|
76
|
+
"locate-path": "^7.1.0",
|
|
77
|
+
"mocha": "^9.2.2",
|
|
78
|
+
"nock": "^13.2.4",
|
|
79
|
+
"node-fetch": "^2.6.7",
|
|
80
|
+
"node-polyfill-webpack-plugin": "^1.1.4",
|
|
81
81
|
"sinon": "^12.0.1",
|
|
82
82
|
"sinon-chai": "^3.7.0",
|
|
83
|
-
"source-map-loader": "^
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"webpack
|
|
88
|
-
"webpack-
|
|
89
|
-
"
|
|
83
|
+
"source-map-loader": "^3.0.1",
|
|
84
|
+
"ts-node": "^10.7.0",
|
|
85
|
+
"typedoc": "^0.22.13",
|
|
86
|
+
"typescript": "^4.6.2",
|
|
87
|
+
"webpack": "^5.70.0",
|
|
88
|
+
"webpack-cli": "^4.9.2",
|
|
89
|
+
"webpack-dev-server": "^4.7.4"
|
|
90
90
|
},
|
|
91
91
|
"scripts": {
|
|
92
92
|
"build": "babel src --extensions \".ts,.js\" -d lib",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"doc": "typedoc --out ./doc ./src/index.ts --excludePrivate --excludeInternal --tsconfig ./tsconfig.json",
|
|
97
97
|
"ignore:prepublishOnly": "npm ci && npm run build && npm run build:types && npm run build:browser && npm run build:esm",
|
|
98
98
|
"postversion": "git push --follow-tags",
|
|
99
|
-
"start": "webpack
|
|
99
|
+
"start": "webpack serve --port 4800",
|
|
100
100
|
"test": "npm run test:unit && npm run test:serialize && npm run test:types",
|
|
101
101
|
"test:clean": "rimraf tests/serialize/,*",
|
|
102
102
|
"test:serialize": "npm run build && npm run test:serialize:all && npm run test:clean",
|
|
@@ -117,9 +117,9 @@
|
|
|
117
117
|
"test:serialize:14": "cd ./tests/serialize && node ./data.js -in=t14.html -format=text/turtle -out=,t14.ttl && node diff ,t14.ttl t14-ref.ttl",
|
|
118
118
|
"test:serialize:15": "cd ./tests/serialize && node ./data.js -in=t15.html -format=text/turtle -out=,t15.ttl && node diff ,t15.ttl t15-ref.ttl",
|
|
119
119
|
"test:types": "tsc --noEmit --target es2019 --moduleResolution node tests/types/*.ts",
|
|
120
|
-
"test:unit": "mocha --growl --require
|
|
121
|
-
"test:unit:egp": "mocha --require ./tests/babel-register.js tests/unit/fetcher-egp-test.js",
|
|
122
|
-
"test:unit:dev": "mocha --watch --growl --require ./tests/babel-register.js tests/unit/**-test.js",
|
|
120
|
+
"test:unit": "mocha --growl --loader=ts-node/esm --require ./tests/babel-register.js tests/unit/**-test.*",
|
|
121
|
+
"test:unit:egp": "mocha --loader=ts-node/esm --require ./tests/babel-register.js tests/unit/fetcher-egp-test.js",
|
|
122
|
+
"test:unit:dev": "mocha --watch --growl --loader=ts-node/esm --require ./tests/babel-register.js tests/unit/**-test.js",
|
|
123
123
|
"watch": "babel src --extensions \".ts,.js\" --env-name esm -d esm --watch & babel src --extensions \".ts,.js\" -d lib --watch"
|
|
124
124
|
},
|
|
125
125
|
"files": [
|
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/index.ts
CHANGED
|
@@ -120,6 +120,9 @@ export {
|
|
|
120
120
|
export { termValue } from './utils/termValue'
|
|
121
121
|
|
|
122
122
|
export class ConnectedStore extends Store {
|
|
123
|
+
|
|
124
|
+
fetcher: Fetcher;
|
|
125
|
+
|
|
123
126
|
constructor (features) {
|
|
124
127
|
super(features)
|
|
125
128
|
this.fetcher = new Fetcher(this, {})
|
|
@@ -127,6 +130,9 @@ export class ConnectedStore extends Store {
|
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
export class LiveStore extends ConnectedStore {
|
|
133
|
+
|
|
134
|
+
updater: UpdateManager;
|
|
135
|
+
|
|
130
136
|
constructor (features) {
|
|
131
137
|
super(features)
|
|
132
138
|
this.updater = new UpdateManager(this)
|
package/src/jsonldparser.js
CHANGED
|
@@ -73,23 +73,8 @@ export default function jsonldParser (str, kb, base, callback) {
|
|
|
73
73
|
return jsonld
|
|
74
74
|
.flatten(JSON.parse(str), null, { base: baseString })
|
|
75
75
|
.then((flattened) => flattened.reduce((store, flatResource) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
: kb.rdfFactory.blankNode()
|
|
79
|
-
|
|
80
|
-
for (const property of Object.keys(flatResource)) {
|
|
81
|
-
if (property === '@id') {
|
|
82
|
-
continue
|
|
83
|
-
}
|
|
84
|
-
const value = flatResource[property]
|
|
85
|
-
if (Array.isArray(value)) {
|
|
86
|
-
for (let i = 0; i < value.length; i++) {
|
|
87
|
-
kb.addStatement(createStatement(kb, id, property, value[i], base))
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
kb.addStatement(createStatement(kb, id, property, value, base))
|
|
91
|
-
}
|
|
92
|
-
}
|
|
76
|
+
|
|
77
|
+
kb = processResource(kb, base, flatResource)
|
|
93
78
|
|
|
94
79
|
return kb
|
|
95
80
|
}, kb))
|
|
@@ -97,6 +82,41 @@ export default function jsonldParser (str, kb, base, callback) {
|
|
|
97
82
|
.catch(callback)
|
|
98
83
|
}
|
|
99
84
|
|
|
85
|
+
|
|
86
|
+
function processResource(kb, base, flatResource) {
|
|
87
|
+
const id = flatResource['@id']
|
|
88
|
+
? kb.rdfFactory.namedNode(flatResource['@id'])
|
|
89
|
+
: kb.rdfFactory.blankNode()
|
|
90
|
+
|
|
91
|
+
for (const property of Object.keys(flatResource)) {
|
|
92
|
+
if (property === '@id') {
|
|
93
|
+
continue
|
|
94
|
+
} else if (property == '@graph') {
|
|
95
|
+
// the JSON-LD flattened structure may contain nested graphs
|
|
96
|
+
// the id value for this object is the new base (named graph id) for all nested flat resources
|
|
97
|
+
const graphId = id
|
|
98
|
+
// this is an array of resources
|
|
99
|
+
const nestedFlatResources = flatResource[property]
|
|
100
|
+
|
|
101
|
+
// recursively process all flat resources in the array, but with the graphId as base.
|
|
102
|
+
for (let i = 0; i < nestedFlatResources.length; i++ ) {
|
|
103
|
+
kb = processResource(kb, graphId, nestedFlatResources[i])
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const value = flatResource[property]
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
for (let i = 0; i < value.length; i++) {
|
|
110
|
+
kb.addStatement(createStatement(kb, id, property, value[i], base))
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
kb.addStatement(createStatement(kb, id, property, value, base))
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return kb
|
|
118
|
+
}
|
|
119
|
+
|
|
100
120
|
/**
|
|
101
121
|
* Create statement quad depending on @type being a type node
|
|
102
122
|
* @param kb
|
|
@@ -107,6 +127,7 @@ export default function jsonldParser (str, kb, base, callback) {
|
|
|
107
127
|
*/
|
|
108
128
|
function createStatement(kb, id, property, value, base) {
|
|
109
129
|
let predicate, object
|
|
130
|
+
|
|
110
131
|
if (property === "@type") {
|
|
111
132
|
predicate = kb.rdfFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
|
|
112
133
|
object = kb.rdfFactory.namedNode(value)
|
package/src/rdfxmlparser.js
CHANGED
|
@@ -198,7 +198,7 @@ export default class RDFParser {
|
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
200
|
* Build our initial scope frame and parse the DOM into triples
|
|
201
|
-
* @param {
|
|
201
|
+
* @param {HTMLDocument} document The DOM to parse
|
|
202
202
|
* @param {String} base The base URL to use
|
|
203
203
|
* @param {Object} why The context to which this resource belongs
|
|
204
204
|
*/
|