rdflib 2.2.37 → 2.3.0-08f819ce
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 +1 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/fetcher.js +17 -26
- package/esm/jsonldparser.js +8 -9
- package/esm/n3parser.js +45 -9
- package/esm/parse.js +5 -2
- package/esm/serializer.js +1 -0
- package/esm/store.js +14 -8
- package/lib/fetcher.js +18 -28
- package/lib/formula.d.ts +1 -0
- package/lib/index.js +1 -2
- package/lib/jsonldparser.d.ts +1 -1
- package/lib/jsonldparser.js +9 -11
- package/lib/literal.d.ts +1 -1
- package/lib/n3parser.js +46 -11
- package/lib/node-internal.d.ts +1 -1
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +6 -4
- package/lib/rdfaparser.js +1 -2
- package/lib/rdfxmlparser.js +1 -2
- package/lib/serializer.js +2 -2
- package/lib/statement.js +1 -2
- package/lib/store.d.ts +4 -1
- package/lib/store.js +14 -8
- package/lib/tf-types.d.ts +1 -1
- package/lib/update-manager.js +1 -2
- package/lib/utils-js.js +1 -2
- package/lib/variable.js +1 -2
- package/package.json +2 -2
- package/src/fetcher.ts +26 -34
- package/src/formula.ts +1 -0
- package/src/jsonldparser.js +12 -17
- package/src/literal.ts +1 -1
- package/src/n3parser.js +46 -17
- package/src/node-internal.ts +1 -1
- package/src/parse.ts +7 -2
- package/src/serializer.js +1 -1
- package/src/store.ts +15 -8
- package/src/tf-types.ts +1 -1
package/lib/rdfxmlparser.js
CHANGED
|
@@ -7,8 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var uriUtil = _interopRequireWildcard(require("./uri"));
|
|
10
|
-
function
|
|
11
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
11
|
/**
|
|
13
12
|
* RDF/XML PARSER
|
|
14
13
|
*
|
package/lib/serializer.js
CHANGED
|
@@ -15,8 +15,7 @@ var _canonicalDataFactory = _interopRequireDefault(require("./factories/canonica
|
|
|
15
15
|
var _xsd = require("./xsd");
|
|
16
16
|
var _solidNamespace = _interopRequireDefault(require("solid-namespace"));
|
|
17
17
|
var ttl2jsonld = _interopRequireWildcard(require("@frogcat/ttl2jsonld"));
|
|
18
|
-
function
|
|
19
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
20
19
|
/* Serialization of RDF Graphs
|
|
21
20
|
**
|
|
22
21
|
** Tim Berners-Lee 2006
|
|
@@ -32,6 +31,7 @@ function createSerializer(store) {
|
|
|
32
31
|
class Serializer {
|
|
33
32
|
constructor(store) {
|
|
34
33
|
(0, _defineProperty2.default)(this, "_notQNameChars", '\t\r\n !"#$%&\'()*.,+/;<=>?@[\\]^`{|}~');
|
|
34
|
+
// issue#228
|
|
35
35
|
(0, _defineProperty2.default)(this, "_notNameChars", this._notQNameChars + ':');
|
|
36
36
|
// stringToN3: String escaping for N3
|
|
37
37
|
(0, _defineProperty2.default)(this, "validPrefix", new RegExp(/^[a-zA-Z][a-zA-Z0-9]*$/));
|
package/lib/statement.js
CHANGED
|
@@ -9,8 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _nodeInternal = _interopRequireDefault(require("./node-internal"));
|
|
10
10
|
var _types = require("./types");
|
|
11
11
|
var _defaultGraph = _interopRequireWildcard(require("./default-graph"));
|
|
12
|
-
function
|
|
13
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
13
|
const defaultGraph = new _defaultGraph.default();
|
|
15
14
|
|
|
16
15
|
/** A Statement represents an RDF Triple or Quad. */
|
package/lib/store.d.ts
CHANGED
|
@@ -61,7 +61,9 @@ export default class IndexedFormula extends Formula {
|
|
|
61
61
|
/** Function to remove quads from the store arrays with */
|
|
62
62
|
private rdfArrayRemove;
|
|
63
63
|
/** Callbacks which are triggered after a statement has been added to the store */
|
|
64
|
-
private dataCallbacks
|
|
64
|
+
private dataCallbacks;
|
|
65
|
+
/** Callbacks which are triggered after a statement has been removed from the store */
|
|
66
|
+
private dataRemovalCallbacks;
|
|
65
67
|
/**
|
|
66
68
|
* Creates a new formula
|
|
67
69
|
* @param features - What sort of automatic processing to do? Array of string
|
|
@@ -86,6 +88,7 @@ export default class IndexedFormula extends Formula {
|
|
|
86
88
|
* @param cb
|
|
87
89
|
*/
|
|
88
90
|
addDataCallback(cb: (q: Quad) => void): void;
|
|
91
|
+
addDataRemovalCallback(cb: (q: Quad) => void): void;
|
|
89
92
|
/**
|
|
90
93
|
* Apply a set of statements to be deleted and to be inserted
|
|
91
94
|
*
|
package/lib/store.js
CHANGED
|
@@ -137,7 +137,9 @@ class IndexedFormula extends _formula.default {
|
|
|
137
137
|
/** Function to remove quads from the store arrays with */
|
|
138
138
|
(0, _defineProperty2.default)(this, "rdfArrayRemove", void 0);
|
|
139
139
|
/** Callbacks which are triggered after a statement has been added to the store */
|
|
140
|
-
(0, _defineProperty2.default)(this, "dataCallbacks",
|
|
140
|
+
(0, _defineProperty2.default)(this, "dataCallbacks", []);
|
|
141
|
+
/** Callbacks which are triggered after a statement has been removed from the store */
|
|
142
|
+
(0, _defineProperty2.default)(this, "dataRemovalCallbacks", []);
|
|
141
143
|
this.propertyActions = {};
|
|
142
144
|
this.classActions = {};
|
|
143
145
|
this.redirections = [];
|
|
@@ -159,6 +161,9 @@ class IndexedFormula extends _formula.default {
|
|
|
159
161
|
if (opts.dataCallback) {
|
|
160
162
|
this.dataCallbacks = [opts.dataCallback];
|
|
161
163
|
}
|
|
164
|
+
if (opts.dataRemovalCallback) {
|
|
165
|
+
this.dataRemovalCallbacks = [opts.dataRemovalCallback];
|
|
166
|
+
}
|
|
162
167
|
this.initPropertyActions(this.features);
|
|
163
168
|
}
|
|
164
169
|
|
|
@@ -187,11 +192,11 @@ class IndexedFormula extends _formula.default {
|
|
|
187
192
|
* @param cb
|
|
188
193
|
*/
|
|
189
194
|
addDataCallback(cb) {
|
|
190
|
-
if (!this.dataCallbacks) {
|
|
191
|
-
this.dataCallbacks = [];
|
|
192
|
-
}
|
|
193
195
|
this.dataCallbacks.push(cb);
|
|
194
196
|
}
|
|
197
|
+
addDataRemovalCallback(cb) {
|
|
198
|
+
this.dataRemovalCallbacks.push(cb);
|
|
199
|
+
}
|
|
195
200
|
|
|
196
201
|
/**
|
|
197
202
|
* Apply a set of statements to be deleted and to be inserted
|
|
@@ -405,10 +410,8 @@ class IndexedFormula extends _formula.default {
|
|
|
405
410
|
|
|
406
411
|
// log.debug("ADDING {"+subj+" "+pred+" "+objNode+"} "+why)
|
|
407
412
|
this.statements.push(st);
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
callback(st);
|
|
411
|
-
}
|
|
413
|
+
for (const callback of this.dataCallbacks) {
|
|
414
|
+
callback(st);
|
|
412
415
|
}
|
|
413
416
|
return st;
|
|
414
417
|
}
|
|
@@ -858,6 +861,9 @@ class IndexedFormula extends _formula.default {
|
|
|
858
861
|
}
|
|
859
862
|
}
|
|
860
863
|
this.rdfArrayRemove(this.statements, st);
|
|
864
|
+
for (const callback of this.dataRemovalCallbacks) {
|
|
865
|
+
callback(st);
|
|
866
|
+
}
|
|
861
867
|
return this;
|
|
862
868
|
}
|
|
863
869
|
|
package/lib/tf-types.d.ts
CHANGED
package/lib/update-manager.js
CHANGED
|
@@ -14,8 +14,7 @@ var _serializer = _interopRequireDefault(require("./serializer"));
|
|
|
14
14
|
var _terms = require("./utils/terms");
|
|
15
15
|
var Util = _interopRequireWildcard(require("./utils-js"));
|
|
16
16
|
var _termValue = require("./utils/termValue");
|
|
17
|
-
function
|
|
18
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
19
18
|
/* @file Update Manager Class
|
|
20
19
|
**
|
|
21
20
|
** 2007-07-15 original SPARQL Update module by Joe Presbrey <presbrey@mit.edu>
|
package/lib/utils-js.js
CHANGED
|
@@ -32,8 +32,7 @@ exports.uri = _uri;
|
|
|
32
32
|
var _log = _interopRequireDefault(require("./log"));
|
|
33
33
|
var _namedNode = _interopRequireDefault(require("./named-node"));
|
|
34
34
|
var _xmldom = require("@xmldom/xmldom");
|
|
35
|
-
function
|
|
36
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
35
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
37
36
|
/**
|
|
38
37
|
* Utility functions for $rdf
|
|
39
38
|
* @module util
|
package/lib/variable.js
CHANGED
|
@@ -10,8 +10,7 @@ var _classOrder = _interopRequireDefault(require("./class-order"));
|
|
|
10
10
|
var _nodeInternal = _interopRequireDefault(require("./node-internal"));
|
|
11
11
|
var _types = require("./types");
|
|
12
12
|
var Uri = _interopRequireWildcard(require("./uri"));
|
|
13
|
-
function
|
|
14
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
14
|
/**
|
|
16
15
|
* Variables are placeholders used in patterns to be matched.
|
|
17
16
|
* In cwm they are symbols which are the formula's list of quantified variables.
|
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.
|
|
4
|
+
"version": "2.3.0-08f819ce",
|
|
5
5
|
"private": false,
|
|
6
6
|
"browserslist": [
|
|
7
7
|
"> 0.5%"
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@babel/runtime": "^7.26.9",
|
|
48
48
|
"@frogcat/ttl2jsonld": "^0.0.10",
|
|
49
|
+
"@rdfjs/types": "^2.0.1",
|
|
49
50
|
"@xmldom/xmldom": "^0.8.10",
|
|
50
51
|
"cross-fetch": "^3.2.0",
|
|
51
52
|
"jsonld": "^8.3.3",
|
|
@@ -77,7 +78,6 @@
|
|
|
77
78
|
"nock": "^13.5.6",
|
|
78
79
|
"node-fetch": "^3.3.2",
|
|
79
80
|
"node-polyfill-webpack-plugin": "^2.0.1",
|
|
80
|
-
"rdf-js": "^4.0.2",
|
|
81
81
|
"sinon": "^15.2.0",
|
|
82
82
|
"sinon-chai": "^3.7.0",
|
|
83
83
|
"source-map-loader": "^4.0.2",
|
package/src/fetcher.ts
CHANGED
|
@@ -262,7 +262,9 @@ class XHTMLHandler extends Handler {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
static register (fetcher: Fetcher) {
|
|
265
|
-
fetcher.mediatypes[XHTMLContentType] = {
|
|
265
|
+
fetcher.mediatypes[XHTMLContentType] = {
|
|
266
|
+
'q': 0.8
|
|
267
|
+
}
|
|
266
268
|
}
|
|
267
269
|
|
|
268
270
|
parse (
|
|
@@ -429,7 +431,7 @@ class HTMLHandler extends Handler {
|
|
|
429
431
|
|
|
430
432
|
static register (fetcher: Fetcher) {
|
|
431
433
|
fetcher.mediatypes['text/html'] = {
|
|
432
|
-
'q': 0.
|
|
434
|
+
'q': 0.8
|
|
433
435
|
}
|
|
434
436
|
}
|
|
435
437
|
|
|
@@ -496,31 +498,30 @@ class JsonLdHandler extends Handler {
|
|
|
496
498
|
'q': 0.9
|
|
497
499
|
}
|
|
498
500
|
}
|
|
499
|
-
parse
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
501
|
+
async parse(
|
|
502
|
+
fetcher: Fetcher,
|
|
503
|
+
responseText: string,
|
|
504
|
+
options: {
|
|
505
|
+
req: Quad_Subject
|
|
506
|
+
original: Quad_Subject
|
|
507
|
+
resource: Quad_Subject
|
|
508
|
+
} & Options,
|
|
509
|
+
response: ExtendedResponse
|
|
508
510
|
): Promise<ExtendedResponse | FetchError> {
|
|
509
511
|
const kb = fetcher.store
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
const msg = 'Error trying to parse ' + options.resource +
|
|
512
|
+
try {
|
|
513
|
+
await jsonldParser(responseText, kb, options.original.value)
|
|
514
|
+
fetcher.store.add(options.original, ns.rdf('type'), ns.link('RDFDocument'), fetcher.appNode)
|
|
515
|
+
return fetcher.doneFetch(options, response)
|
|
516
|
+
} catch (err) {
|
|
517
|
+
const msg = 'Error trying to parse ' + options.resource +
|
|
517
518
|
' as JSON-LD:\n' + err // not err.stack -- irrelevant
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
})
|
|
519
|
+
return fetcher.failFetch(options, msg, 'parse_error', response)
|
|
520
|
+
}
|
|
521
521
|
}
|
|
522
522
|
}
|
|
523
|
-
|
|
523
|
+
|
|
524
|
+
JsonLdHandler.pattern = /application\/(ld\+json|activity\+json)/
|
|
524
525
|
|
|
525
526
|
class TextHandler extends Handler {
|
|
526
527
|
static toString () {
|
|
@@ -577,17 +578,8 @@ class N3Handler extends Handler {
|
|
|
577
578
|
}
|
|
578
579
|
|
|
579
580
|
static register (fetcher: Fetcher) {
|
|
580
|
-
fetcher.mediatypes['text/n3'] = {
|
|
581
|
-
|
|
582
|
-
} // as per 2008 spec
|
|
583
|
-
/*
|
|
584
|
-
fetcher.mediatypes['application/x-turtle'] = {
|
|
585
|
-
'q': 1.0
|
|
586
|
-
} // pre 2008
|
|
587
|
-
*/
|
|
588
|
-
fetcher.mediatypes['text/turtle'] = {
|
|
589
|
-
'q': 1.0
|
|
590
|
-
} // post 2008
|
|
581
|
+
fetcher.mediatypes['text/n3'] = {}
|
|
582
|
+
fetcher.mediatypes['text/turtle'] = {}
|
|
591
583
|
}
|
|
592
584
|
|
|
593
585
|
parse (
|
|
@@ -1057,7 +1049,7 @@ export default class Fetcher implements CallbackifyInterface {
|
|
|
1057
1049
|
options.baseURI = options.baseURI || uri // Preserve though proxying etc
|
|
1058
1050
|
options.original = kb.rdfFactory.namedNode(options.baseURI)
|
|
1059
1051
|
options.req = kb.bnode()
|
|
1060
|
-
options.headers = options.headers ||
|
|
1052
|
+
options.headers = options.headers || {}
|
|
1061
1053
|
|
|
1062
1054
|
if (options.contentType) {
|
|
1063
1055
|
// @ts-ignore
|
package/src/formula.ts
CHANGED
package/src/jsonldparser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {arrayToStatements} from './utils'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Parses json-ld formatted JS objects to a rdf Term.
|
|
@@ -6,7 +6,7 @@ import { arrayToStatements } from './utils'
|
|
|
6
6
|
* @param obj - The json-ld object to process.
|
|
7
7
|
* @return {Literal|NamedNode|BlankNode|Collection}
|
|
8
8
|
*/
|
|
9
|
-
export function jsonldObjectToTerm
|
|
9
|
+
export function jsonldObjectToTerm(kb, obj) {
|
|
10
10
|
if (typeof obj === 'string') {
|
|
11
11
|
return kb.rdfFactory.literal(obj)
|
|
12
12
|
}
|
|
@@ -41,7 +41,7 @@ export function jsonldObjectToTerm (kb, obj) {
|
|
|
41
41
|
/**
|
|
42
42
|
* Adds the statements in a json-ld list object to {kb}.
|
|
43
43
|
*/
|
|
44
|
-
function listToStatements
|
|
44
|
+
function listToStatements(kb, obj) {
|
|
45
45
|
const listId = obj['@id'] ? nodeType(kb, obj) : kb.rdfFactory.blankNode()
|
|
46
46
|
|
|
47
47
|
const items = obj['@list'].map((listItem => jsonldObjectToTerm(kb, listItem)))
|
|
@@ -51,7 +51,7 @@ function listToStatements (kb, obj) {
|
|
|
51
51
|
return listId
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function listToCollection
|
|
54
|
+
function listToCollection(kb, obj) {
|
|
55
55
|
if (!Array.isArray(obj)) {
|
|
56
56
|
throw new TypeError("Object must be an array")
|
|
57
57
|
}
|
|
@@ -63,24 +63,19 @@ function listToCollection (kb, obj) {
|
|
|
63
63
|
*
|
|
64
64
|
* Ensure that {kb.rdfFactory} is a DataFactory.
|
|
65
65
|
*/
|
|
66
|
-
export default function jsonldParser
|
|
66
|
+
export default async function jsonldParser(str, kb, base) {
|
|
67
67
|
const baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType')
|
|
68
68
|
? base.value
|
|
69
69
|
: base
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return kb
|
|
78
|
-
}, kb))
|
|
79
|
-
.then(callback)
|
|
80
|
-
.catch(callback)
|
|
71
|
+
const jsonld = await import('jsonld')
|
|
72
|
+
// ⚠ Unit tests also work without accessing `jsonld.default` explicitly, but real browser usage will fail with
|
|
73
|
+
// just calling `jsonld.flatten`, so please do not remove `default`
|
|
74
|
+
const flattened = await jsonld.default.flatten(JSON.parse(str), null, {base: baseString})
|
|
75
|
+
return flattened.reduce((store, flatResource) => processResource(store, base, flatResource), kb)
|
|
81
76
|
}
|
|
82
77
|
|
|
83
|
-
function nodeType
|
|
78
|
+
function nodeType(kb, obj) {
|
|
84
79
|
if (obj['@id'].startsWith('_:')) {
|
|
85
80
|
// This object is a Blank Node. Pass the id without the `_:` prefix
|
|
86
81
|
return kb.rdfFactory.blankNode(obj['@id'].substring(2));
|
|
@@ -106,7 +101,7 @@ function processResource(kb, base, flatResource) {
|
|
|
106
101
|
const nestedFlatResources = flatResource[property]
|
|
107
102
|
|
|
108
103
|
// recursively process all flat resources in the array, but with the graphId as base.
|
|
109
|
-
for (let i = 0; i < nestedFlatResources.length; i++
|
|
104
|
+
for (let i = 0; i < nestedFlatResources.length; i++) {
|
|
110
105
|
kb = processResource(kb, graphId, nestedFlatResources[i])
|
|
111
106
|
}
|
|
112
107
|
}
|
package/src/literal.ts
CHANGED
|
@@ -61,7 +61,7 @@ export default class Literal extends Node implements TFLiteral {
|
|
|
61
61
|
* Gets whether two literals are the same
|
|
62
62
|
* @param other The other statement
|
|
63
63
|
*/
|
|
64
|
-
equals (other: Term): boolean {
|
|
64
|
+
equals (other: Term | null | undefined): boolean {
|
|
65
65
|
if (!other) {
|
|
66
66
|
return false
|
|
67
67
|
}
|
package/src/n3parser.js
CHANGED
|
@@ -212,10 +212,20 @@ var signed_integer = new RegExp("^[-+]?[0-9]+", 'g');
|
|
|
212
212
|
var number_syntax = new RegExp("^([-+]?[0-9]+)(\\.[0-9]+)?([eE][-+]?[0-9]+)?", 'g');
|
|
213
213
|
var datetime_syntax = new RegExp('^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9](T[0-9][0-9]:[0-9][0-9](:[0-9][0-9](\\.[0-9]*)?)?)?Z?');
|
|
214
214
|
|
|
215
|
+
// Reused in tight loops to detect whitespace or comment after a dot
|
|
216
|
+
var wsOrHash = new RegExp("[\\s#]");
|
|
217
|
+
|
|
215
218
|
var digitstring = new RegExp("^[0-9]+", 'g');
|
|
216
219
|
var interesting = new RegExp("[\\\\\\r\\n\\\"]", 'g');
|
|
217
220
|
var langcode = new RegExp("^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*", 'g');
|
|
218
221
|
|
|
222
|
+
// Returns true when a dot at position i should terminate a name,
|
|
223
|
+
// i.e., when the next character is whitespace, a comment start, or EOF
|
|
224
|
+
function dotTerminatesName(str, i) {
|
|
225
|
+
var next = str.charAt(i + 1);
|
|
226
|
+
return next === '' || wsOrHash.test(next);
|
|
227
|
+
}
|
|
228
|
+
|
|
219
229
|
function createSinkParser(store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why) {
|
|
220
230
|
return new SinkParser(store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why);
|
|
221
231
|
}
|
|
@@ -554,7 +564,7 @@ export class SinkParser {
|
|
|
554
564
|
<- prop -<
|
|
555
565
|
_operator_*/
|
|
556
566
|
|
|
557
|
-
|
|
567
|
+
var j = this.skipSpace(str, i);
|
|
558
568
|
if ((j < 0)) {
|
|
559
569
|
return j;
|
|
560
570
|
}
|
|
@@ -703,22 +713,17 @@ export class SinkParser {
|
|
|
703
713
|
if ((j >= 0)) {
|
|
704
714
|
var subj = objs[0];
|
|
705
715
|
if ((pyjslib_len(objs) > 1)) {
|
|
706
|
-
|
|
707
716
|
var __obj = new pyjslib_Iterator(objs);
|
|
708
717
|
try {
|
|
709
718
|
while (true) {
|
|
710
719
|
var obj = __obj.next();
|
|
711
|
-
|
|
712
|
-
|
|
713
720
|
this.makeStatement(new pyjslib_Tuple([this._context, this._store.sym(DAML_sameAs_URI), subj, obj]));
|
|
714
|
-
|
|
715
721
|
}
|
|
716
722
|
} catch (e) {
|
|
717
723
|
if (e != StopIteration) {
|
|
718
724
|
throw e;
|
|
719
725
|
}
|
|
720
726
|
}
|
|
721
|
-
|
|
722
727
|
}
|
|
723
728
|
var j = this.skipSpace(str, j);
|
|
724
729
|
if ((j < 0)) {
|
|
@@ -743,6 +748,16 @@ export class SinkParser {
|
|
|
743
748
|
if ((j < 0)) {
|
|
744
749
|
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF when ']' expected after [ <propertyList>");
|
|
745
750
|
}
|
|
751
|
+
if ((str.slice( j, ( j + 1 ) ) == ".")) {
|
|
752
|
+
// If a dot is found after a blank node, treat it as a statement terminator.
|
|
753
|
+
// Do NOT consume the '.' here: statement terminators are handled centrally by
|
|
754
|
+
// checkDot() (called by directiveOrStatement after statement()). Consuming the dot
|
|
755
|
+
// locally would bypass that unified logic and could cause inconsistencies.
|
|
756
|
+
// We do consume ']' below because it is a structural closer of the blank node,
|
|
757
|
+
// not a statement terminator.
|
|
758
|
+
res.push(subj);
|
|
759
|
+
return j; // leave '.' for checkDot()
|
|
760
|
+
}
|
|
746
761
|
if ((str.slice( j, ( j + 1 ) ) != "]")) {
|
|
747
762
|
throw BadSyntax(this._thisDoc, this.lines, str, j, "']' expected");
|
|
748
763
|
}
|
|
@@ -1208,7 +1223,17 @@ export class SinkParser {
|
|
|
1208
1223
|
return -1;
|
|
1209
1224
|
}
|
|
1210
1225
|
var i = j;
|
|
1211
|
-
while ((i < pyjslib_len(str))
|
|
1226
|
+
while ((i < pyjslib_len(str))) {
|
|
1227
|
+
var c = str.charAt(i);
|
|
1228
|
+
if (c === '.') {
|
|
1229
|
+
if (dotTerminatesName(str, i)) {
|
|
1230
|
+
break; // treat as statement terminator, not part of name
|
|
1231
|
+
}
|
|
1232
|
+
// else: accept '.' as part of name
|
|
1233
|
+
} else if (_notNameChars.indexOf(c) >= 0) {
|
|
1234
|
+
// Other invalid characters terminate the name
|
|
1235
|
+
break;
|
|
1236
|
+
}
|
|
1212
1237
|
var i = ( i + 1 ) ;
|
|
1213
1238
|
}
|
|
1214
1239
|
res.push(str.slice( j, i));
|
|
@@ -1235,13 +1260,15 @@ export class SinkParser {
|
|
|
1235
1260
|
var i = ( i + 1 ) ;
|
|
1236
1261
|
while ((i < pyjslib_len(str))) {
|
|
1237
1262
|
var c = str.charAt(i);
|
|
1238
|
-
if (
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
else {
|
|
1263
|
+
if (c === '.') {
|
|
1264
|
+
if (dotTerminatesName(str, i)) {
|
|
1265
|
+
break; // dot ends the name here
|
|
1266
|
+
}
|
|
1267
|
+
} else if (_notNameChars.indexOf(c) >= 0) {
|
|
1243
1268
|
break;
|
|
1244
1269
|
}
|
|
1270
|
+
var ln = ( ln + c ) ;
|
|
1271
|
+
var i = ( i + 1 ) ;
|
|
1245
1272
|
}
|
|
1246
1273
|
}
|
|
1247
1274
|
else {
|
|
@@ -1253,13 +1280,15 @@ export class SinkParser {
|
|
|
1253
1280
|
var ln = "";
|
|
1254
1281
|
while ((i < pyjslib_len(str))) {
|
|
1255
1282
|
var c = str.charAt(i);
|
|
1256
|
-
if (
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
else {
|
|
1283
|
+
if (c === '.') {
|
|
1284
|
+
if (dotTerminatesName(str, i)) {
|
|
1285
|
+
break; // dot ends the name here
|
|
1286
|
+
}
|
|
1287
|
+
} else if (_notNameChars.indexOf(c) >= 0) {
|
|
1261
1288
|
break;
|
|
1262
1289
|
}
|
|
1290
|
+
var ln = ( ln + c ) ;
|
|
1291
|
+
var i = ( i + 1 ) ;
|
|
1263
1292
|
}
|
|
1264
1293
|
res.push(new pyjslib_Tuple([pfx, ln]));
|
|
1265
1294
|
return i;
|
package/src/node-internal.ts
CHANGED
package/src/parse.ts
CHANGED
|
@@ -17,7 +17,7 @@ type CallbackFunc = (error: any, kb: Formula | null) => void
|
|
|
17
17
|
* Parse a string and put the result into the graph kb.
|
|
18
18
|
* Normal method is sync.
|
|
19
19
|
* Unfortunately jsdonld is currently written to need to be called async.
|
|
20
|
-
*
|
|
20
|
+
* If you are parsing JSON-LD and want to know when and whether it succeeded, you need to use the callback param.
|
|
21
21
|
* @param str - The input string to parse
|
|
22
22
|
* @param kb - The store to use
|
|
23
23
|
* @param base - The base URI to use
|
|
@@ -52,7 +52,12 @@ export default function parse (
|
|
|
52
52
|
sparqlUpdateParser(str, kb, base)
|
|
53
53
|
executeCallback()
|
|
54
54
|
} else if (contentType === JSONLDContentType) {
|
|
55
|
-
|
|
55
|
+
// since we do not await the promise here, rejections will not be covered by the surrounding try catch
|
|
56
|
+
// we do not use await, because parse() should stay sync
|
|
57
|
+
// so, to not lose the async error, we need to catch the rejection and call the error callback here too
|
|
58
|
+
jsonldParser(str, kb, base)
|
|
59
|
+
.then(executeCallback)
|
|
60
|
+
.catch(executeErrorCallback)
|
|
56
61
|
} else if (contentType === NQuadsContentType ||
|
|
57
62
|
contentType === NQuadsAltContentType) {
|
|
58
63
|
var n3Parser = new N3jsParser({ factory: DataFactory })
|
package/src/serializer.js
CHANGED
|
@@ -251,7 +251,7 @@ export class Serializer {
|
|
|
251
251
|
return this.statementsToN3(f.statements)
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
_notQNameChars = '\t\r\n !"#$%&\'()*.,+/;<=>?@[\\]^`{|}~'
|
|
254
|
+
_notQNameChars = '\t\r\n !"#$%&\'()*.,+/;<=>?@[\\]^`{|}~' // issue#228
|
|
255
255
|
_notNameChars =
|
|
256
256
|
(this._notQNameChars + ':')
|
|
257
257
|
|
package/src/store.ts
CHANGED
|
@@ -168,7 +168,9 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
168
168
|
/** Function to remove quads from the store arrays with */
|
|
169
169
|
private rdfArrayRemove: (arr: Quad[], q: Quad) => void
|
|
170
170
|
/** Callbacks which are triggered after a statement has been added to the store */
|
|
171
|
-
private dataCallbacks
|
|
171
|
+
private dataCallbacks: Array<(q: Quad) => void> = []
|
|
172
|
+
/** Callbacks which are triggered after a statement has been removed from the store */
|
|
173
|
+
private dataRemovalCallbacks: Array<(q: Quad) => void> = []
|
|
172
174
|
|
|
173
175
|
/**
|
|
174
176
|
* Creates a new formula
|
|
@@ -208,6 +210,9 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
208
210
|
if (opts.dataCallback) {
|
|
209
211
|
this.dataCallbacks = [opts.dataCallback]
|
|
210
212
|
}
|
|
213
|
+
if (opts.dataRemovalCallback) {
|
|
214
|
+
this.dataRemovalCallbacks = [opts.dataRemovalCallback]
|
|
215
|
+
}
|
|
211
216
|
|
|
212
217
|
this.initPropertyActions(this.features)
|
|
213
218
|
}
|
|
@@ -237,12 +242,13 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
237
242
|
* @param cb
|
|
238
243
|
*/
|
|
239
244
|
addDataCallback(cb: (q: Quad) => void): void {
|
|
240
|
-
if (!this.dataCallbacks) {
|
|
241
|
-
this.dataCallbacks = []
|
|
242
|
-
}
|
|
243
245
|
this.dataCallbacks.push(cb)
|
|
244
246
|
}
|
|
245
247
|
|
|
248
|
+
addDataRemovalCallback(cb: (q: Quad) => void): void {
|
|
249
|
+
this.dataRemovalCallbacks.push(cb)
|
|
250
|
+
}
|
|
251
|
+
|
|
246
252
|
/**
|
|
247
253
|
* Apply a set of statements to be deleted and to be inserted
|
|
248
254
|
*
|
|
@@ -486,10 +492,8 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
486
492
|
// log.debug("ADDING {"+subj+" "+pred+" "+objNode+"} "+why)
|
|
487
493
|
this.statements.push(st)
|
|
488
494
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
callback(st)
|
|
492
|
-
}
|
|
495
|
+
for (const callback of this.dataCallbacks) {
|
|
496
|
+
callback(st)
|
|
493
497
|
}
|
|
494
498
|
|
|
495
499
|
return st
|
|
@@ -987,6 +991,9 @@ export default class IndexedFormula extends Formula { // IN future - allow pass
|
|
|
987
991
|
}
|
|
988
992
|
}
|
|
989
993
|
this.rdfArrayRemove(this.statements, st)
|
|
994
|
+
for (const callback of this.dataRemovalCallbacks) {
|
|
995
|
+
callback(st)
|
|
996
|
+
}
|
|
990
997
|
return this
|
|
991
998
|
}
|
|
992
999
|
|