rdflib 2.2.19 → 2.2.20-506bc192
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/README.md +1 -1
- package/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/collection.js +2 -0
- package/esm/fetcher.js +2 -2
- package/esm/lists.js +168 -0
- package/esm/serializer.js +6 -3
- package/esm/statement.js +7 -0
- package/esm/store.js +6 -4
- package/esm/update-manager.js +35 -28
- package/esm/utils/terms.js +12 -1
- package/lib/collection.js +2 -0
- package/lib/fetcher.d.ts +3 -3
- package/lib/fetcher.js +2 -2
- package/lib/lists.d.ts +13 -0
- package/lib/lists.js +170 -0
- package/lib/serializer.d.ts +1 -1
- package/lib/serializer.js +6 -3
- package/lib/statement.js +7 -0
- package/lib/store.js +3 -3
- package/lib/update-manager.d.ts +9 -6
- package/lib/update-manager.js +33 -25
- 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/fetcher.ts +3 -3
- package/src/lists.ts +121 -0
- package/src/serializer.js +6 -4
- package/src/statement.ts +7 -0
- package/src/store.ts +7 -7
- package/src/update-manager.ts +37 -43
- 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/fetcher.js
CHANGED
|
@@ -1441,8 +1441,8 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
1441
1441
|
}
|
|
1442
1442
|
}
|
|
1443
1443
|
/**
|
|
1444
|
-
* A generic web
|
|
1445
|
-
* does not
|
|
1444
|
+
* A generic web operation, at the fetch() level.
|
|
1445
|
+
* does not involve the quad store.
|
|
1446
1446
|
*
|
|
1447
1447
|
* Returns promise of Response
|
|
1448
1448
|
* If data is returned, copies it to response.responseText before returning
|
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/serializer.js
CHANGED
|
@@ -60,7 +60,7 @@ export var Serializer = /*#__PURE__*/function () {
|
|
|
60
60
|
this.prefixchars = 'abcdefghijklmnopqustuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
61
61
|
this.incoming = null; // Array not calculated yet
|
|
62
62
|
|
|
63
|
-
this.formulas = []; //
|
|
63
|
+
this.formulas = []; // remembering original formulae from hashes
|
|
64
64
|
|
|
65
65
|
this.store = store;
|
|
66
66
|
this.rdfFactory = store.rdfFactory || CanonicalDataFactory;
|
|
@@ -102,7 +102,7 @@ export var Serializer = /*#__PURE__*/function () {
|
|
|
102
102
|
return this.store.fromNT(s);
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
|
-
* Defines a set of [prefix, namespace] pairs to be
|
|
105
|
+
* Defines a set of [prefix, namespace] pairs to be used by this Serializer instance.
|
|
106
106
|
* Overrides previous prefixes if any
|
|
107
107
|
* @param namespaces
|
|
108
108
|
* @return {Serializer}
|
|
@@ -665,7 +665,7 @@ export var Serializer = /*#__PURE__*/function () {
|
|
|
665
665
|
return val;
|
|
666
666
|
|
|
667
667
|
case 'http://www.w3.org/2001/XMLSchema#decimal':
|
|
668
|
-
// In
|
|
668
|
+
// In Turtle, must have dot
|
|
669
669
|
if (val.indexOf('.') < 0) val += '.0';
|
|
670
670
|
return val;
|
|
671
671
|
|
|
@@ -696,6 +696,9 @@ export var Serializer = /*#__PURE__*/function () {
|
|
|
696
696
|
case 'NamedNode':
|
|
697
697
|
return this.symbolToN3(expr);
|
|
698
698
|
|
|
699
|
+
case 'DefaultGraph':
|
|
700
|
+
return '';
|
|
701
|
+
|
|
699
702
|
default:
|
|
700
703
|
throw new Error('Internal: atomicTermToN3 cannot handle ' + expr + ' of termType: ' + expr.termType);
|
|
701
704
|
}
|
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
|
@@ -16,12 +16,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
16
16
|
** 2010-12-07 TimBL addred local file write code
|
|
17
17
|
*/
|
|
18
18
|
import IndexedFormula from './store';
|
|
19
|
-
import { docpart } from './uri';
|
|
19
|
+
import { docpart, join as uriJoin } from './uri';
|
|
20
20
|
import Fetcher from './fetcher';
|
|
21
21
|
import Namespace from './namespace';
|
|
22
22
|
import Serializer from './serializer';
|
|
23
|
-
import {
|
|
24
|
-
import { isStore, isBlankNode } from './utils/terms';
|
|
23
|
+
import { isBlankNode, isStore } from './utils/terms';
|
|
25
24
|
import * as Util from './utils-js';
|
|
26
25
|
import { termValue } from './utils/termValue';
|
|
27
26
|
|
|
@@ -224,6 +223,11 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
224
223
|
value: function anonymizeNT(stmt) {
|
|
225
224
|
return this.anonymize(stmt.subject) + ' ' + this.anonymize(stmt.predicate) + ' ' + this.anonymize(stmt.object) + ' .';
|
|
226
225
|
}
|
|
226
|
+
}, {
|
|
227
|
+
key: "nTriples",
|
|
228
|
+
value: function nTriples(stmt) {
|
|
229
|
+
return "".concat(stmt.subject.toNT(), " ").concat(stmt.predicate.toNT(), " ").concat(stmt.object.toNT(), " .");
|
|
230
|
+
}
|
|
227
231
|
/**
|
|
228
232
|
* Returns a list of all bnodes occurring in a statement
|
|
229
233
|
* @private
|
|
@@ -425,17 +429,16 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
425
429
|
value: function fire(uri, query, callbackFunction) {
|
|
426
430
|
var _this = this;
|
|
427
431
|
|
|
432
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
428
433
|
return Promise.resolve().then(function () {
|
|
429
434
|
if (!uri) {
|
|
430
435
|
throw new Error('No URI given for remote editing operation: ' + query);
|
|
431
436
|
} // console.log('UpdateManager: sending update to <' + uri + '>')
|
|
432
437
|
|
|
433
438
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
body: query
|
|
438
|
-
};
|
|
439
|
+
options.noMeta = true;
|
|
440
|
+
options.contentType = 'application/sparql-update';
|
|
441
|
+
options.body = query;
|
|
439
442
|
return _this.store.fetcher.webOperation('PATCH', uri, options);
|
|
440
443
|
}).then(function (response) {
|
|
441
444
|
if (!response.ok) {
|
|
@@ -786,8 +789,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
786
789
|
}));
|
|
787
790
|
});
|
|
788
791
|
|
|
789
|
-
if (updates.length > 1) {
|
|
790
|
-
console.log("@@ updateMany to ".concat(updates.length, ": ").concat(uniqueDocs));
|
|
792
|
+
if (updates.length > 1) {// console.log(`@@ updateMany to ${updates.length}: ${uniqueDocs}`)
|
|
791
793
|
}
|
|
792
794
|
|
|
793
795
|
return Promise.all(updates);
|
|
@@ -800,6 +802,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
800
802
|
* @param insertions - Statement or statements to be inserted.
|
|
801
803
|
* @param callback - called as callbackFunction(uri, success, errorbody)
|
|
802
804
|
* OR returns a promise
|
|
805
|
+
* @param options - Options for the fetch call
|
|
803
806
|
*/
|
|
804
807
|
|
|
805
808
|
}, {
|
|
@@ -807,6 +810,8 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
807
810
|
value: function update(deletions, insertions, callback, secondTry) {
|
|
808
811
|
var _this3 = this;
|
|
809
812
|
|
|
813
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
814
|
+
|
|
810
815
|
if (!callback) {
|
|
811
816
|
var thisUpdater = this;
|
|
812
817
|
return new Promise(function (resolve, reject) {
|
|
@@ -817,7 +822,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
817
822
|
} else {
|
|
818
823
|
resolve();
|
|
819
824
|
}
|
|
820
|
-
}); // callbackFunction
|
|
825
|
+
}, secondTry, options); // callbackFunction
|
|
821
826
|
}); // promise
|
|
822
827
|
} // if
|
|
823
828
|
|
|
@@ -883,11 +888,11 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
883
888
|
|
|
884
889
|
|
|
885
890
|
this.store.fetcher.load(doc).then(function (response) {
|
|
886
|
-
_this3.update(deletions, insertions, callback, true);
|
|
891
|
+
_this3.update(deletions, insertions, callback, true, options);
|
|
887
892
|
}, function (err) {
|
|
888
893
|
if (err.response.status === 404) {
|
|
889
894
|
// nonexistent files are fine
|
|
890
|
-
_this3.update(deletions, insertions, callback, true);
|
|
895
|
+
_this3.update(deletions, insertions, callback, true, options);
|
|
891
896
|
} else {
|
|
892
897
|
throw new Error("Update: Can't get updatability status ".concat(doc, " before patching: ").concat(err));
|
|
893
898
|
}
|
|
@@ -941,7 +946,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
941
946
|
query += 'INSERT DATA { ';
|
|
942
947
|
|
|
943
948
|
for (var _i7 = 0; _i7 < is.length; _i7++) {
|
|
944
|
-
query += this.
|
|
949
|
+
query += this.nTriples(is[_i7]) + '\n';
|
|
945
950
|
}
|
|
946
951
|
|
|
947
952
|
query += ' }\n';
|
|
@@ -958,7 +963,10 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
958
963
|
|
|
959
964
|
this.fire(doc.value, query, function (uri, success, body, response) {
|
|
960
965
|
response.elapsedTimeMs = Date.now() - startTime;
|
|
961
|
-
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
|
+
*/
|
|
962
970
|
|
|
963
971
|
if (success) {
|
|
964
972
|
try {
|
|
@@ -983,13 +991,13 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
983
991
|
|
|
984
992
|
downstreamAction(doc);
|
|
985
993
|
}
|
|
986
|
-
});
|
|
994
|
+
}, options);
|
|
987
995
|
} else if (protocol.indexOf('DAV') >= 0) {
|
|
988
|
-
this.updateDav(doc, ds, is, callback);
|
|
996
|
+
this.updateDav(doc, ds, is, callback, options);
|
|
989
997
|
} else {
|
|
990
998
|
if (protocol.indexOf('LOCALFILE') >= 0) {
|
|
991
999
|
try {
|
|
992
|
-
this.updateLocalFile(doc, ds, is, callback);
|
|
1000
|
+
this.updateLocalFile(doc, ds, is, callback, options);
|
|
993
1001
|
} catch (e) {
|
|
994
1002
|
callback(doc.value, false, 'Exception trying to write back file <' + doc.value + '>\n' // + tabulator.Util.stackString(e))
|
|
995
1003
|
);
|
|
@@ -1005,6 +1013,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1005
1013
|
}, {
|
|
1006
1014
|
key: "updateDav",
|
|
1007
1015
|
value: function updateDav(doc, ds, is, callbackFunction) {
|
|
1016
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1008
1017
|
var kb = this.store; // The code below is derived from Kenny's UpdateCenter.js
|
|
1009
1018
|
|
|
1010
1019
|
var request = kb.any(doc, this.ns.link('request'));
|
|
@@ -1041,11 +1050,9 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1041
1050
|
targetURI = uriJoin(candidateTarget.value, targetURI);
|
|
1042
1051
|
}
|
|
1043
1052
|
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
body: documentString
|
|
1048
|
-
};
|
|
1053
|
+
options.contentType = contentType;
|
|
1054
|
+
options.noMeta = true;
|
|
1055
|
+
options.body = documentString;
|
|
1049
1056
|
return kb.fetcher.webOperation('PUT', targetURI, options).then(function (response) {
|
|
1050
1057
|
if (!response.ok) {
|
|
1051
1058
|
throw new Error(response.error);
|
|
@@ -1071,11 +1078,13 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1071
1078
|
* @param ds
|
|
1072
1079
|
* @param is
|
|
1073
1080
|
* @param callbackFunction
|
|
1081
|
+
* @param options
|
|
1074
1082
|
*/
|
|
1075
1083
|
|
|
1076
1084
|
}, {
|
|
1077
1085
|
key: "updateLocalFile",
|
|
1078
1086
|
value: function updateLocalFile(doc, ds, is, callbackFunction) {
|
|
1087
|
+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1079
1088
|
var kb = this.store; // console.log('Writing back to local file\n')
|
|
1080
1089
|
// prepare contents of revised document
|
|
1081
1090
|
|
|
@@ -1103,11 +1112,9 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1103
1112
|
throw new Error('File extension .' + ext + ' not supported for data write');
|
|
1104
1113
|
}
|
|
1105
1114
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
contentType: contentType
|
|
1110
|
-
}).then(function (response) {
|
|
1115
|
+
options.body = this.serialize(doc.value, newSts, contentType);
|
|
1116
|
+
options.contentType = contentType;
|
|
1117
|
+
kb.fetcher.webOperation('PUT', doc.value, options).then(function (response) {
|
|
1111
1118
|
if (!response.ok) return callbackFunction(doc.value, false, response.error);
|
|
1112
1119
|
|
|
1113
1120
|
for (var _i13 = 0; _i13 < ds.length; _i13++) {
|
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/fetcher.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ declare global {
|
|
|
56
56
|
declare type UserCallback = (ok: boolean, message: string, response?: any) => void;
|
|
57
57
|
declare type HTTPMethods = 'GET' | 'PUT' | 'POST' | 'PATCH' | 'HEAD' | 'DELETE' | 'CONNECT' | 'TRACE' | 'OPTIONS';
|
|
58
58
|
/** All valid inputs for initFetchOptions */
|
|
59
|
-
declare type Options = Partial<AutoInitOptions>;
|
|
59
|
+
export declare type Options = Partial<AutoInitOptions>;
|
|
60
60
|
/** Initiated by initFetchOptions, which runs on load */
|
|
61
61
|
export interface AutoInitOptions extends RequestInit {
|
|
62
62
|
/** The used Fetch function */
|
|
@@ -370,8 +370,8 @@ export default class Fetcher implements CallbackifyInterface {
|
|
|
370
370
|
createContainer(parentURI: string, folderName: string, data: string): Promise<Response>;
|
|
371
371
|
invalidateCache(iri: string | NamedNode): void;
|
|
372
372
|
/**
|
|
373
|
-
* A generic web
|
|
374
|
-
* does not
|
|
373
|
+
* A generic web operation, at the fetch() level.
|
|
374
|
+
* does not involve the quad store.
|
|
375
375
|
*
|
|
376
376
|
* Returns promise of Response
|
|
377
377
|
* If data is returned, copies it to response.responseText before returning
|
package/lib/fetcher.js
CHANGED
|
@@ -1415,8 +1415,8 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
}
|
|
1417
1417
|
/**
|
|
1418
|
-
* A generic web
|
|
1419
|
-
* does not
|
|
1418
|
+
* A generic web operation, at the fetch() level.
|
|
1419
|
+
* does not involve the quad store.
|
|
1420
1420
|
*
|
|
1421
1421
|
* Returns promise of Response
|
|
1422
1422
|
* If data is returned, copies it to response.responseText before returning
|
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;
|