rdflib 2.2.20 → 2.2.21-3a98cfb3
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/collection.js +2 -0
- package/esm/lists.js +168 -0
- package/esm/statement.js +7 -0
- package/esm/store.js +6 -4
- package/esm/update-manager.js +5 -3
- package/esm/utils/terms.js +12 -1
- package/lib/collection.js +2 -0
- package/lib/lists.d.ts +13 -0
- package/lib/lists.js +170 -0
- package/lib/statement.js +7 -0
- package/lib/store.js +3 -3
- package/lib/update-manager.js +5 -3
- package/lib/utils/terms.d.ts +6 -1
- package/lib/utils/terms.js +16 -1
- package/package.json +1 -2
- package/src/collection.ts +2 -0
- package/src/lists.ts +121 -0
- package/src/statement.ts +7 -0
- package/src/store.ts +7 -7
- package/src/update-manager.ts +3 -2
- package/src/utils/terms.ts +23 -1
package/esm/collection.js
CHANGED
|
@@ -161,6 +161,8 @@ var Collection = /*#__PURE__*/function (_Node) {
|
|
|
161
161
|
}], [{
|
|
162
162
|
key: "toNT",
|
|
163
163
|
value: function toNT(collection) {
|
|
164
|
+
// return '(' + collection.elements.map(x => x.toNT()).join(' ') + ')'
|
|
165
|
+
// As lists are not in NT and toNT() must be a reversible function, we kludge it for a list
|
|
164
166
|
return RdflibBlankNode.NTAnonymousNodePrefix + collection.id;
|
|
165
167
|
}
|
|
166
168
|
}]);
|
package/esm/lists.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
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; } } }; }
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
|
|
5
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
6
|
+
|
|
7
|
+
/* Lists form conversion
|
|
8
|
+
*/
|
|
9
|
+
// import DataFactory from './factories/extended-term-factory'
|
|
10
|
+
// import jsonldParser from './jsonldparser'
|
|
11
|
+
// @ts-ignore is this injected?
|
|
12
|
+
// @@ Goal: remove this dependency
|
|
13
|
+
// import N3Parser from './n3parser'
|
|
14
|
+
// import { parseRDFaDOM } from './rdfaparser'
|
|
15
|
+
// import RDFParser from './rdfxmlparser'
|
|
16
|
+
// import sparqlUpdateParser from './patch-parser'
|
|
17
|
+
// import * as Util from './utils-js'
|
|
18
|
+
// import BlankNode from './blank-node'
|
|
19
|
+
// import NamedNode from './named-node'
|
|
20
|
+
import Collection from './collection';
|
|
21
|
+
import Statement from './statement'; // import Formula from './formula'
|
|
22
|
+
|
|
23
|
+
import Namespace from './namespace';
|
|
24
|
+
var RDF = Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
|
|
25
|
+
/* Replace a given node with another node throughout a given document
|
|
26
|
+
*
|
|
27
|
+
* we do the predicate as well for complenesss though we don't expect Collections to use it
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export function substituteInDoc(store, x, y, doc) {
|
|
31
|
+
// console.log(`substituteInDoc put ${x} for ${y} in ${doc}}`)
|
|
32
|
+
var _iterator = _createForOfIteratorHelper(store.statementsMatching(y, null, null, doc)),
|
|
33
|
+
_step;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
37
|
+
var quad = _step.value;
|
|
38
|
+
var newStatement = new Statement(x, quad.predicate, quad.object, doc);
|
|
39
|
+
store.remove(quad);
|
|
40
|
+
store.add(newStatement);
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
_iterator.e(err);
|
|
44
|
+
} finally {
|
|
45
|
+
_iterator.f();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var _iterator2 = _createForOfIteratorHelper(store.statementsMatching(null, y, null, doc)),
|
|
49
|
+
_step2;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
53
|
+
var _quad = _step2.value;
|
|
54
|
+
store.remove(_quad); // console.log(` substituteInDoc predicate ${x} in ${quad}}`)
|
|
55
|
+
|
|
56
|
+
store.add(new Statement(_quad.subject, x, _quad.object, doc));
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
_iterator2.e(err);
|
|
60
|
+
} finally {
|
|
61
|
+
_iterator2.f();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var _iterator3 = _createForOfIteratorHelper(store.statementsMatching(null, null, y, doc)),
|
|
65
|
+
_step3;
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
69
|
+
var _quad2 = _step3.value;
|
|
70
|
+
store.remove(_quad2);
|
|
71
|
+
store.add(new Statement(_quad2.subject, _quad2.predicate, x, doc));
|
|
72
|
+
}
|
|
73
|
+
} catch (err) {
|
|
74
|
+
_iterator3.e(err);
|
|
75
|
+
} finally {
|
|
76
|
+
_iterator3.f();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/* Change all lone rdf:nil nodes into empty Collections
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
export function substituteNillsInDoc(store, doc) {
|
|
83
|
+
var x = RDF('nil');
|
|
84
|
+
|
|
85
|
+
var _iterator4 = _createForOfIteratorHelper(store.statementsMatching(x, null, null, doc)),
|
|
86
|
+
_step4;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
90
|
+
var quad = _step4.value;
|
|
91
|
+
store.remove(quad);
|
|
92
|
+
var y = new Collection();
|
|
93
|
+
store.add(new Statement(y, quad.predicate, quad.object, doc));
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
_iterator4.e(err);
|
|
97
|
+
} finally {
|
|
98
|
+
_iterator4.f();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var _iterator5 = _createForOfIteratorHelper(store.statementsMatching(null, null, x, doc)),
|
|
102
|
+
_step5;
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
106
|
+
var _quad3 = _step5.value;
|
|
107
|
+
|
|
108
|
+
if (!_quad3.predicate.sameTerm(RDF('rest'))) {
|
|
109
|
+
// If not a tail
|
|
110
|
+
store.remove(_quad3);
|
|
111
|
+
|
|
112
|
+
var _y = new Collection();
|
|
113
|
+
|
|
114
|
+
store.add(new Statement(_quad3.subject, _quad3.predicate, _y, doc));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch (err) {
|
|
118
|
+
_iterator5.e(err);
|
|
119
|
+
} finally {
|
|
120
|
+
_iterator5.f();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Convert lists reified as rdf:first, rest
|
|
125
|
+
* Normal method is sync.
|
|
126
|
+
* Unfortunately jsdonld is currently written to need to be called async.
|
|
127
|
+
* Hence the mess below with executeCallback.
|
|
128
|
+
* @param store - The quadstore
|
|
129
|
+
* @param doc - The document in which the conversion is done
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
export function convertFirstRestNil(store, doc // Do whole store?
|
|
133
|
+
) {
|
|
134
|
+
function preceding(ele, listSoFar, trash) {
|
|
135
|
+
var rests = store.statementsMatching(ele, RDF('rest'), null, doc);
|
|
136
|
+
if (rests.length !== 1) throw new Error("Bad list structure: no rest at ".concat(ele));
|
|
137
|
+
var firsts = store.statementsMatching(ele, RDF('first'), null, doc);
|
|
138
|
+
if (firsts.length !== 1) throw new Error("Bad list structure: rest but ".concat(firsts.length, " firsts at ").concat(ele));
|
|
139
|
+
var value = firsts[0].object;
|
|
140
|
+
var total = [value].concat(listSoFar); // console.log(' List now is: ', total)
|
|
141
|
+
|
|
142
|
+
var totalTrash = trash.concat(rests).concat(firsts);
|
|
143
|
+
var pres = store.statementsMatching(null, RDF('rest'), ele, doc);
|
|
144
|
+
|
|
145
|
+
if (pres.length === 0) {
|
|
146
|
+
// Head of the list
|
|
147
|
+
var newList = new Collection(total);
|
|
148
|
+
store.remove(totalTrash); // Replace old list with new list:
|
|
149
|
+
|
|
150
|
+
substituteInDoc(store, newList, ele, doc);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (pres.length !== 1) throw new Error("Bad list structure: ".concat(pres.length, " pres at ").concat(ele));
|
|
155
|
+
var pre = pres[0].subject;
|
|
156
|
+
if (pre.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(pre, " type: ").concat(pre.termType, " "));
|
|
157
|
+
preceding(pre, total, totalTrash);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
substituteNillsInDoc(store, doc); // lone ones only
|
|
162
|
+
|
|
163
|
+
var tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
|
|
164
|
+
tails.forEach(function (tail) {
|
|
165
|
+
if (tail.subject.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(tail.subject, " type: ").concat(tail.subject.termType, " "));
|
|
166
|
+
preceding(tail.subject, [], []);
|
|
167
|
+
});
|
|
168
|
+
}
|
package/esm/statement.js
CHANGED
|
@@ -118,6 +118,13 @@ var Statement = /*#__PURE__*/function () {
|
|
|
118
118
|
}, {
|
|
119
119
|
key: "toString",
|
|
120
120
|
value: function toString() {
|
|
121
|
+
/*
|
|
122
|
+
return [
|
|
123
|
+
this.subject.toString(),
|
|
124
|
+
this.predicate.toString(),
|
|
125
|
+
this.object.toString(),
|
|
126
|
+
].join(' ') + ' .'
|
|
127
|
+
*/
|
|
121
128
|
return this.toNT();
|
|
122
129
|
}
|
|
123
130
|
}]);
|
package/esm/store.js
CHANGED
|
@@ -43,7 +43,9 @@ import { defaultGraphURI } from './factories/canonical-data-factory';
|
|
|
43
43
|
import Formula from './formula';
|
|
44
44
|
import { ArrayIndexOf } from './utils';
|
|
45
45
|
import { RDFArrayRemove } from './utils-js';
|
|
46
|
-
import { isRDFlibObject, isStore, isGraph, isPredicate,
|
|
46
|
+
import { isRDFlibSubject, isRDFlibPredicate, isRDFlibObject, isStore, isGraph, // isPredicate,
|
|
47
|
+
isQuad // isSubject
|
|
48
|
+
} from './utils/terms';
|
|
47
49
|
import Node from './node';
|
|
48
50
|
import Variable from './variable';
|
|
49
51
|
import { Query, indexedFormulaQuery } from './query';
|
|
@@ -449,11 +451,11 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
|
|
|
449
451
|
var objNode = Node.fromValue(obj);
|
|
450
452
|
why = Node.fromValue(why);
|
|
451
453
|
|
|
452
|
-
if (!
|
|
454
|
+
if (!isRDFlibSubject(subj)) {
|
|
453
455
|
throw new Error('Subject is not a subject type');
|
|
454
456
|
}
|
|
455
457
|
|
|
456
|
-
if (!
|
|
458
|
+
if (!isRDFlibPredicate(pred)) {
|
|
457
459
|
throw new Error("Predicate ".concat(pred, " is not a predicate type"));
|
|
458
460
|
}
|
|
459
461
|
|
|
@@ -1010,7 +1012,7 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
|
|
|
1010
1012
|
}, {
|
|
1011
1013
|
key: "removeMatches",
|
|
1012
1014
|
value: function removeMatches(subject, predicate, object, graph) {
|
|
1013
|
-
this.
|
|
1015
|
+
this.removeMany(subject, predicate, object, graph);
|
|
1014
1016
|
return this;
|
|
1015
1017
|
}
|
|
1016
1018
|
/**
|
package/esm/update-manager.js
CHANGED
|
@@ -789,8 +789,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
789
789
|
}));
|
|
790
790
|
});
|
|
791
791
|
|
|
792
|
-
if (updates.length > 1) {
|
|
793
|
-
console.log("@@ updateMany to ".concat(updates.length, ": ").concat(uniqueDocs));
|
|
792
|
+
if (updates.length > 1) {// console.log(`@@ updateMany to ${updates.length}: ${uniqueDocs}`)
|
|
794
793
|
}
|
|
795
794
|
|
|
796
795
|
return Promise.all(updates);
|
|
@@ -964,7 +963,10 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
964
963
|
|
|
965
964
|
this.fire(doc.value, query, function (uri, success, body, response) {
|
|
966
965
|
response.elapsedTimeMs = Date.now() - startTime;
|
|
967
|
-
console.log(' UpdateManager: Return ' +
|
|
966
|
+
/* console.log(' UpdateManager: Return ' +
|
|
967
|
+
(success ? 'success ' : 'FAILURE ') + (response as Response).status +
|
|
968
|
+
' elapsed ' + (response as any).elapsedTimeMs + 'ms')
|
|
969
|
+
*/
|
|
968
970
|
|
|
969
971
|
if (success) {
|
|
970
972
|
try {
|
package/esm/utils/terms.js
CHANGED
|
@@ -15,11 +15,22 @@ export function isStore(obj) {
|
|
|
15
15
|
export function isCollection(obj) {
|
|
16
16
|
return isTerm(obj) && obj.termType === CollectionTermType;
|
|
17
17
|
}
|
|
18
|
-
/** TypeGuard for valid RDFlib Object types, also allows Collections */
|
|
18
|
+
/** TypeGuard for valid RDFlib Object types, also allows Collections, Graphs */
|
|
19
19
|
|
|
20
20
|
export function isRDFlibObject(obj) {
|
|
21
21
|
return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (obj.termType === NamedNodeTermType || obj.termType === VariableTermType || obj.termType === BlankNodeTermType || obj.termType === CollectionTermType || obj.termType === LiteralTermType || obj.termType === GraphTermType);
|
|
22
22
|
}
|
|
23
|
+
/** TypeGuard for valid RDFlib Subject types, same as Object as RDFLib symmetrical.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export function isRDFlibSubject(obj) {
|
|
27
|
+
return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (obj.termType === NamedNodeTermType || obj.termType === VariableTermType || obj.termType === BlankNodeTermType || obj.termType === CollectionTermType || obj.termType === LiteralTermType || obj.termType === GraphTermType);
|
|
28
|
+
}
|
|
29
|
+
/** TypeGuard for valid RDF/JS spec Predicate types */
|
|
30
|
+
|
|
31
|
+
export function isRDFlibPredicate(obj) {
|
|
32
|
+
return isTerm(obj) && (obj.termType === NamedNodeTermType || obj.termType === BlankNodeTermType || obj.termType === VariableTermType);
|
|
33
|
+
}
|
|
23
34
|
/** TypeGuard for RDFLib Variables */
|
|
24
35
|
|
|
25
36
|
export function isVariable(obj) {
|
package/lib/collection.js
CHANGED
|
@@ -176,6 +176,8 @@ var Collection = /*#__PURE__*/function (_Node) {
|
|
|
176
176
|
}], [{
|
|
177
177
|
key: "toNT",
|
|
178
178
|
value: function toNT(collection) {
|
|
179
|
+
// return '(' + collection.elements.map(x => x.toNT()).join(' ') + ')'
|
|
180
|
+
// As lists are not in NT and toNT() must be a reversible function, we kludge it for a list
|
|
179
181
|
return _blankNode.default.NTAnonymousNodePrefix + collection.id;
|
|
180
182
|
}
|
|
181
183
|
}]);
|
package/lib/lists.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Store from './store';
|
|
2
|
+
import { NamedNode, Term } from './tf-types';
|
|
3
|
+
export declare function substituteInDoc(store: Store, x: Term, y: Term, doc?: NamedNode): void;
|
|
4
|
+
export declare function substituteNillsInDoc(store: Store, doc?: NamedNode): void;
|
|
5
|
+
/**
|
|
6
|
+
* Convert lists reified as rdf:first, rest
|
|
7
|
+
* Normal method is sync.
|
|
8
|
+
* Unfortunately jsdonld is currently written to need to be called async.
|
|
9
|
+
* Hence the mess below with executeCallback.
|
|
10
|
+
* @param store - The quadstore
|
|
11
|
+
* @param doc - The document in which the conversion is done
|
|
12
|
+
*/
|
|
13
|
+
export declare function convertFirstRestNil(store: Store, doc: NamedNode | undefined): void;
|
package/lib/lists.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.convertFirstRestNil = convertFirstRestNil;
|
|
9
|
+
exports.substituteInDoc = substituteInDoc;
|
|
10
|
+
exports.substituteNillsInDoc = substituteNillsInDoc;
|
|
11
|
+
|
|
12
|
+
var _collection = _interopRequireDefault(require("./collection"));
|
|
13
|
+
|
|
14
|
+
var _statement = _interopRequireDefault(require("./statement"));
|
|
15
|
+
|
|
16
|
+
var _namespace = _interopRequireDefault(require("./namespace"));
|
|
17
|
+
|
|
18
|
+
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; } } }; }
|
|
19
|
+
|
|
20
|
+
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); }
|
|
21
|
+
|
|
22
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
23
|
+
|
|
24
|
+
var RDF = (0, _namespace.default)('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
|
|
25
|
+
/* Replace a given node with another node throughout a given document
|
|
26
|
+
*
|
|
27
|
+
* we do the predicate as well for complenesss though we don't expect Collections to use it
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
function substituteInDoc(store, x, y, doc) {
|
|
31
|
+
// console.log(`substituteInDoc put ${x} for ${y} in ${doc}}`)
|
|
32
|
+
var _iterator = _createForOfIteratorHelper(store.statementsMatching(y, null, null, doc)),
|
|
33
|
+
_step;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
37
|
+
var quad = _step.value;
|
|
38
|
+
var newStatement = new _statement.default(x, quad.predicate, quad.object, doc);
|
|
39
|
+
store.remove(quad);
|
|
40
|
+
store.add(newStatement);
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
_iterator.e(err);
|
|
44
|
+
} finally {
|
|
45
|
+
_iterator.f();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var _iterator2 = _createForOfIteratorHelper(store.statementsMatching(null, y, null, doc)),
|
|
49
|
+
_step2;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
53
|
+
var _quad = _step2.value;
|
|
54
|
+
store.remove(_quad); // console.log(` substituteInDoc predicate ${x} in ${quad}}`)
|
|
55
|
+
|
|
56
|
+
store.add(new _statement.default(_quad.subject, x, _quad.object, doc));
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
_iterator2.e(err);
|
|
60
|
+
} finally {
|
|
61
|
+
_iterator2.f();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var _iterator3 = _createForOfIteratorHelper(store.statementsMatching(null, null, y, doc)),
|
|
65
|
+
_step3;
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
69
|
+
var _quad2 = _step3.value;
|
|
70
|
+
store.remove(_quad2);
|
|
71
|
+
store.add(new _statement.default(_quad2.subject, _quad2.predicate, x, doc));
|
|
72
|
+
}
|
|
73
|
+
} catch (err) {
|
|
74
|
+
_iterator3.e(err);
|
|
75
|
+
} finally {
|
|
76
|
+
_iterator3.f();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/* Change all lone rdf:nil nodes into empty Collections
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
function substituteNillsInDoc(store, doc) {
|
|
84
|
+
var x = RDF('nil');
|
|
85
|
+
|
|
86
|
+
var _iterator4 = _createForOfIteratorHelper(store.statementsMatching(x, null, null, doc)),
|
|
87
|
+
_step4;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
91
|
+
var quad = _step4.value;
|
|
92
|
+
store.remove(quad);
|
|
93
|
+
var y = new _collection.default();
|
|
94
|
+
store.add(new _statement.default(y, quad.predicate, quad.object, doc));
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
_iterator4.e(err);
|
|
98
|
+
} finally {
|
|
99
|
+
_iterator4.f();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var _iterator5 = _createForOfIteratorHelper(store.statementsMatching(null, null, x, doc)),
|
|
103
|
+
_step5;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
107
|
+
var _quad3 = _step5.value;
|
|
108
|
+
|
|
109
|
+
if (!_quad3.predicate.sameTerm(RDF('rest'))) {
|
|
110
|
+
// If not a tail
|
|
111
|
+
store.remove(_quad3);
|
|
112
|
+
|
|
113
|
+
var _y = new _collection.default();
|
|
114
|
+
|
|
115
|
+
store.add(new _statement.default(_quad3.subject, _quad3.predicate, _y, doc));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} catch (err) {
|
|
119
|
+
_iterator5.e(err);
|
|
120
|
+
} finally {
|
|
121
|
+
_iterator5.f();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Convert lists reified as rdf:first, rest
|
|
126
|
+
* Normal method is sync.
|
|
127
|
+
* Unfortunately jsdonld is currently written to need to be called async.
|
|
128
|
+
* Hence the mess below with executeCallback.
|
|
129
|
+
* @param store - The quadstore
|
|
130
|
+
* @param doc - The document in which the conversion is done
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
function convertFirstRestNil(store, doc // Do whole store?
|
|
135
|
+
) {
|
|
136
|
+
function preceding(ele, listSoFar, trash) {
|
|
137
|
+
var rests = store.statementsMatching(ele, RDF('rest'), null, doc);
|
|
138
|
+
if (rests.length !== 1) throw new Error("Bad list structure: no rest at ".concat(ele));
|
|
139
|
+
var firsts = store.statementsMatching(ele, RDF('first'), null, doc);
|
|
140
|
+
if (firsts.length !== 1) throw new Error("Bad list structure: rest but ".concat(firsts.length, " firsts at ").concat(ele));
|
|
141
|
+
var value = firsts[0].object;
|
|
142
|
+
var total = [value].concat(listSoFar); // console.log(' List now is: ', total)
|
|
143
|
+
|
|
144
|
+
var totalTrash = trash.concat(rests).concat(firsts);
|
|
145
|
+
var pres = store.statementsMatching(null, RDF('rest'), ele, doc);
|
|
146
|
+
|
|
147
|
+
if (pres.length === 0) {
|
|
148
|
+
// Head of the list
|
|
149
|
+
var newList = new _collection.default(total);
|
|
150
|
+
store.remove(totalTrash); // Replace old list with new list:
|
|
151
|
+
|
|
152
|
+
substituteInDoc(store, newList, ele, doc);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (pres.length !== 1) throw new Error("Bad list structure: ".concat(pres.length, " pres at ").concat(ele));
|
|
157
|
+
var pre = pres[0].subject;
|
|
158
|
+
if (pre.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(pre, " type: ").concat(pre.termType, " "));
|
|
159
|
+
preceding(pre, total, totalTrash);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
substituteNillsInDoc(store, doc); // lone ones only
|
|
164
|
+
|
|
165
|
+
var tails = store.statementsMatching(null, RDF('rest'), RDF('nil'), doc);
|
|
166
|
+
tails.forEach(function (tail) {
|
|
167
|
+
if (tail.subject.termType !== 'BlankNode') throw new Error("Bad list element node ".concat(tail.subject, " type: ").concat(tail.subject.termType, " "));
|
|
168
|
+
preceding(tail.subject, [], []);
|
|
169
|
+
});
|
|
170
|
+
}
|
package/lib/statement.js
CHANGED
|
@@ -134,6 +134,13 @@ var Statement = /*#__PURE__*/function () {
|
|
|
134
134
|
}, {
|
|
135
135
|
key: "toString",
|
|
136
136
|
value: function toString() {
|
|
137
|
+
/*
|
|
138
|
+
return [
|
|
139
|
+
this.subject.toString(),
|
|
140
|
+
this.predicate.toString(),
|
|
141
|
+
this.object.toString(),
|
|
142
|
+
].join(' ') + ' .'
|
|
143
|
+
*/
|
|
137
144
|
return this.toNT();
|
|
138
145
|
}
|
|
139
146
|
}]);
|
package/lib/store.js
CHANGED
|
@@ -450,11 +450,11 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
|
|
|
450
450
|
|
|
451
451
|
why = _node.default.fromValue(why);
|
|
452
452
|
|
|
453
|
-
if (!(0, _terms.
|
|
453
|
+
if (!(0, _terms.isRDFlibSubject)(subj)) {
|
|
454
454
|
throw new Error('Subject is not a subject type');
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
-
if (!(0, _terms.
|
|
457
|
+
if (!(0, _terms.isRDFlibPredicate)(pred)) {
|
|
458
458
|
throw new Error("Predicate ".concat(pred, " is not a predicate type"));
|
|
459
459
|
}
|
|
460
460
|
|
|
@@ -1012,7 +1012,7 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
|
|
|
1012
1012
|
}, {
|
|
1013
1013
|
key: "removeMatches",
|
|
1014
1014
|
value: function removeMatches(subject, predicate, object, graph) {
|
|
1015
|
-
this.
|
|
1015
|
+
this.removeMany(subject, predicate, object, graph);
|
|
1016
1016
|
return this;
|
|
1017
1017
|
}
|
|
1018
1018
|
/**
|
package/lib/update-manager.js
CHANGED
|
@@ -802,8 +802,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
802
802
|
}));
|
|
803
803
|
});
|
|
804
804
|
|
|
805
|
-
if (updates.length > 1) {
|
|
806
|
-
console.log("@@ updateMany to ".concat(updates.length, ": ").concat(uniqueDocs));
|
|
805
|
+
if (updates.length > 1) {// console.log(`@@ updateMany to ${updates.length}: ${uniqueDocs}`)
|
|
807
806
|
}
|
|
808
807
|
|
|
809
808
|
return Promise.all(updates);
|
|
@@ -977,7 +976,10 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
977
976
|
|
|
978
977
|
this.fire(doc.value, query, function (uri, success, body, response) {
|
|
979
978
|
response.elapsedTimeMs = Date.now() - startTime;
|
|
980
|
-
console.log(' UpdateManager: Return ' +
|
|
979
|
+
/* console.log(' UpdateManager: Return ' +
|
|
980
|
+
(success ? 'success ' : 'FAILURE ') + (response as Response).status +
|
|
981
|
+
' elapsed ' + (response as any).elapsedTimeMs + 'ms')
|
|
982
|
+
*/
|
|
981
983
|
|
|
982
984
|
if (success) {
|
|
983
985
|
try {
|
package/lib/utils/terms.d.ts
CHANGED
|
@@ -9,8 +9,13 @@ export declare function isStatement(obj: any): obj is Statement;
|
|
|
9
9
|
export declare function isStore(obj: any): obj is IndexedFormula;
|
|
10
10
|
/** TypeGuard for RDFLib Collections */
|
|
11
11
|
export declare function isCollection(obj: any): obj is Collection<any>;
|
|
12
|
-
/** TypeGuard for valid RDFlib Object types, also allows Collections */
|
|
12
|
+
/** TypeGuard for valid RDFlib Object types, also allows Collections, Graphs */
|
|
13
13
|
export declare function isRDFlibObject(obj: any): obj is ObjectType;
|
|
14
|
+
/** TypeGuard for valid RDFlib Subject types, same as Object as RDFLib symmetrical.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isRDFlibSubject(obj: any): obj is ObjectType;
|
|
17
|
+
/** TypeGuard for valid RDF/JS spec Predicate types */
|
|
18
|
+
export declare function isRDFlibPredicate(obj: any): obj is Quad_Predicate;
|
|
14
19
|
/** TypeGuard for RDFLib Variables */
|
|
15
20
|
export declare function isVariable(obj: any): obj is Variable;
|
|
16
21
|
/** TypeGuard for RDF/JS spec Terms */
|
package/lib/utils/terms.js
CHANGED
|
@@ -14,6 +14,8 @@ exports.isPredicate = isPredicate;
|
|
|
14
14
|
exports.isQuad = isQuad;
|
|
15
15
|
exports.isRDFObject = isRDFObject;
|
|
16
16
|
exports.isRDFlibObject = isRDFlibObject;
|
|
17
|
+
exports.isRDFlibPredicate = isRDFlibPredicate;
|
|
18
|
+
exports.isRDFlibSubject = isRDFlibSubject;
|
|
17
19
|
exports.isStatement = isStatement;
|
|
18
20
|
exports.isStore = isStore;
|
|
19
21
|
exports.isSubject = isSubject;
|
|
@@ -40,12 +42,25 @@ function isStore(obj) {
|
|
|
40
42
|
function isCollection(obj) {
|
|
41
43
|
return isTerm(obj) && obj.termType === _types.CollectionTermType;
|
|
42
44
|
}
|
|
43
|
-
/** TypeGuard for valid RDFlib Object types, also allows Collections */
|
|
45
|
+
/** TypeGuard for valid RDFlib Object types, also allows Collections, Graphs */
|
|
44
46
|
|
|
45
47
|
|
|
46
48
|
function isRDFlibObject(obj) {
|
|
47
49
|
return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.VariableTermType || obj.termType === _types.BlankNodeTermType || obj.termType === _types.CollectionTermType || obj.termType === _types.LiteralTermType || obj.termType === _types.GraphTermType);
|
|
48
50
|
}
|
|
51
|
+
/** TypeGuard for valid RDFlib Subject types, same as Object as RDFLib symmetrical.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
function isRDFlibSubject(obj) {
|
|
56
|
+
return obj && Object.prototype.hasOwnProperty.call(obj, 'termType') && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.VariableTermType || obj.termType === _types.BlankNodeTermType || obj.termType === _types.CollectionTermType || obj.termType === _types.LiteralTermType || obj.termType === _types.GraphTermType);
|
|
57
|
+
}
|
|
58
|
+
/** TypeGuard for valid RDF/JS spec Predicate types */
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
function isRDFlibPredicate(obj) {
|
|
62
|
+
return isTerm(obj) && (obj.termType === _types.NamedNodeTermType || obj.termType === _types.BlankNodeTermType || obj.termType === _types.VariableTermType);
|
|
63
|
+
}
|
|
49
64
|
/** TypeGuard for RDFLib Variables */
|
|
50
65
|
|
|
51
66
|
|
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.21-3a98cfb3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"browserslist": [
|
|
7
7
|
"> 0.5%"
|
|
@@ -64,7 +64,6 @@
|
|
|
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.1.0",
|
|
68
67
|
"@types/rdf-js": "^4.0.2",
|
|
69
68
|
"@types/sinon-chai": "^3.2.8",
|
|
70
69
|
"babel-loader": "^8.2.4",
|
package/src/collection.ts
CHANGED
|
@@ -112,6 +112,8 @@ export default class Collection<
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
static toNT (collection) {
|
|
115
|
+
// return '(' + collection.elements.map(x => x.toNT()).join(' ') + ')'
|
|
116
|
+
// As lists are not in NT and toNT() must be a reversible function, we kludge it for a list
|
|
115
117
|
return RdflibBlankNode.NTAnonymousNodePrefix + collection.id
|
|
116
118
|
}
|
|
117
119
|
|