rdflib 2.2.21 → 2.2.22-0de51c50
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.LICENSE.txt +13 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +3 -27
- package/esm/collection.js +7 -29
- package/esm/default-graph.js +1 -15
- package/esm/empty.js +0 -13
- package/esm/factories/canonical-data-factory.js +5 -40
- package/esm/factories/extended-term-factory.js +0 -11
- package/esm/factories/factory-types.js +2 -1
- package/esm/factories/rdflib-data-factory.js +0 -8
- package/esm/fetcher.js +257 -481
- package/esm/formula.js +43 -142
- package/esm/index.js +19 -36
- package/esm/jsonldparser.js +20 -29
- package/esm/jsonparser.js +0 -7
- package/esm/lists.js +18 -33
- package/esm/literal.js +10 -42
- package/esm/n3parser.js +38 -351
- package/esm/named-node.js +8 -27
- package/esm/namespace.js +0 -1
- package/esm/node-internal.js +11 -24
- package/esm/node.js +1 -6
- package/esm/parse.js +10 -17
- package/esm/patch-parser.js +9 -29
- package/esm/query-to-sparql.js +0 -18
- package/esm/query.js +50 -133
- package/esm/rdfaparser.js +72 -210
- package/esm/rdfxmlparser.js +31 -128
- package/esm/serialize.js +8 -33
- package/esm/serializer.js +122 -286
- package/esm/sparql-to-query.js +44 -134
- package/esm/statement.js +8 -19
- package/esm/store.js +109 -280
- package/esm/types.js +3 -2
- package/esm/update-manager.js +110 -246
- package/esm/updates-via.js +0 -27
- package/esm/uri.js +6 -50
- package/esm/utils/default-graph-uri.js +1 -0
- package/esm/utils/termValue.js +0 -1
- package/esm/utils/terms.js +15 -16
- package/esm/utils-js.js +16 -57
- package/esm/utils.js +4 -15
- package/esm/variable.js +0 -20
- package/lib/blank-node.js +3 -28
- package/lib/class-order.js +0 -1
- package/lib/collection.js +7 -34
- package/lib/default-graph.js +0 -20
- package/lib/empty.js +0 -18
- package/lib/factories/canonical-data-factory.js +4 -51
- package/lib/factories/extended-term-factory.js +0 -18
- package/lib/factories/factory-types.d.ts +6 -6
- package/lib/factories/factory-types.js +0 -3
- package/lib/factories/rdflib-data-factory.js +0 -12
- package/lib/fetcher.d.ts +6 -6
- package/lib/fetcher.js +258 -470
- package/lib/formula.d.ts +1 -1
- package/lib/formula.js +43 -151
- package/lib/index.d.ts +1 -2
- package/lib/index.js +14 -82
- package/lib/jsonldparser.js +19 -33
- package/lib/jsonparser.js +0 -9
- package/lib/lists.js +14 -39
- package/lib/literal.js +10 -49
- package/lib/log.d.ts +0 -6
- package/lib/log.js +0 -1
- package/lib/n3parser.d.ts +1 -0
- package/lib/n3parser.js +39 -359
- package/lib/named-node.js +7 -35
- package/lib/namespace.js +0 -3
- package/lib/node-internal.js +11 -21
- package/lib/node.js +1 -11
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +8 -27
- package/lib/patch-parser.js +10 -33
- package/lib/query-to-sparql.js +0 -23
- package/lib/query.js +46 -152
- package/lib/rdfaparser.js +72 -220
- package/lib/rdfxmlparser.js +31 -132
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +8 -43
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +121 -297
- package/lib/sparql-to-query.js +42 -167
- package/lib/statement.js +8 -24
- package/lib/store.d.ts +2 -2
- package/lib/store.js +102 -282
- package/lib/tf-types.d.ts +4 -4
- package/lib/types.d.ts +8 -8
- package/lib/types.js +3 -3
- package/lib/update-manager.d.ts +2 -2
- package/lib/update-manager.js +110 -254
- package/lib/updates-via.js +0 -30
- package/lib/uri.js +5 -58
- package/lib/utils/default-graph-uri.js +1 -3
- package/lib/utils/termValue.js +0 -2
- package/lib/utils/terms.js +15 -34
- package/lib/utils-js.js +16 -80
- package/lib/utils.js +4 -21
- package/lib/variable.js +0 -25
- package/lib/xsd-internal.js +0 -3
- package/lib/xsd.js +0 -4
- package/package.json +40 -39
- package/src/fetcher.ts +2 -2
- package/src/index.ts +0 -2
- package/src/jsonldparser.js +13 -4
- package/src/n3parser.js +12 -4
- package/src/serialize.ts +4 -11
- package/src/serializer.js +24 -0
- package/src/update-manager.ts +18 -7
- package/changes.txt +0 -59
- package/esm/convert.js +0 -61
- package/lib/convert.d.ts +0 -2
- package/lib/convert.js +0 -77
- package/src/convert.js +0 -70
package/lib/update-manager.js
CHANGED
|
@@ -1,48 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.default = void 0;
|
|
11
|
-
|
|
12
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
-
|
|
14
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
|
-
|
|
20
13
|
var _store = _interopRequireDefault(require("./store"));
|
|
21
|
-
|
|
22
14
|
var _uri = require("./uri");
|
|
23
|
-
|
|
24
15
|
var _fetcher = _interopRequireDefault(require("./fetcher"));
|
|
25
|
-
|
|
26
16
|
var _namespace = _interopRequireDefault(require("./namespace"));
|
|
27
|
-
|
|
28
17
|
var _serializer = _interopRequireDefault(require("./serializer"));
|
|
29
|
-
|
|
30
18
|
var _terms = require("./utils/terms");
|
|
31
|
-
|
|
32
19
|
var Util = _interopRequireWildcard(require("./utils-js"));
|
|
33
|
-
|
|
34
20
|
var _termValue = require("./utils/termValue");
|
|
35
|
-
|
|
36
21
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
37
|
-
|
|
38
22
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
39
|
-
|
|
40
23
|
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; } } }; }
|
|
41
|
-
|
|
42
24
|
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); }
|
|
43
|
-
|
|
44
|
-
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; }
|
|
45
|
-
|
|
25
|
+
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; }
|
|
46
26
|
/**
|
|
47
27
|
* The UpdateManager is a helper object for a store.
|
|
48
28
|
* Just as a Fetcher provides the store with the ability to read and write,
|
|
@@ -65,15 +45,12 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
65
45
|
(0, _defineProperty2.default)(this, "patchControl", void 0);
|
|
66
46
|
(0, _defineProperty2.default)(this, "ns", void 0);
|
|
67
47
|
store = store || new _store.default();
|
|
68
|
-
|
|
69
48
|
if (store.updater) {
|
|
70
49
|
throw new Error("You can't have two UpdateManagers for the same store");
|
|
71
50
|
}
|
|
72
|
-
|
|
73
51
|
if (!store.fetcher) {
|
|
74
52
|
store.fetcher = new _fetcher.default(store);
|
|
75
53
|
}
|
|
76
|
-
|
|
77
54
|
this.store = store;
|
|
78
55
|
store.updater = this;
|
|
79
56
|
this.ifps = {};
|
|
@@ -89,14 +66,12 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
89
66
|
this.ns.owl = (0, _namespace.default)('http://www.w3.org/2002/07/owl#');
|
|
90
67
|
this.patchControl = [];
|
|
91
68
|
}
|
|
92
|
-
|
|
93
69
|
(0, _createClass2.default)(UpdateManager, [{
|
|
94
70
|
key: "patchControlFor",
|
|
95
71
|
value: function patchControlFor(doc) {
|
|
96
72
|
if (!this.patchControl[doc.value]) {
|
|
97
73
|
this.patchControl[doc.value] = [];
|
|
98
74
|
}
|
|
99
|
-
|
|
100
75
|
return this.patchControl[doc.value];
|
|
101
76
|
}
|
|
102
77
|
}, {
|
|
@@ -104,6 +79,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
104
79
|
value: function isHttpUri(uri) {
|
|
105
80
|
return uri.slice(0, 4) === 'http';
|
|
106
81
|
}
|
|
82
|
+
|
|
107
83
|
/**
|
|
108
84
|
* Tests whether a file is editable.
|
|
109
85
|
* If the file has a specific annotation that it is machine written,
|
|
@@ -115,7 +91,6 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
115
91
|
* @returns The method string SPARQL or DAV or
|
|
116
92
|
* LOCALFILE or false if known, undefined if not known.
|
|
117
93
|
*/
|
|
118
|
-
|
|
119
94
|
}, {
|
|
120
95
|
key: "editable",
|
|
121
96
|
value: function editable(uri, kb) {
|
|
@@ -126,39 +101,30 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
126
101
|
if (!kb) {
|
|
127
102
|
kb = this.store;
|
|
128
103
|
}
|
|
129
|
-
|
|
130
104
|
uri = (0, _termValue.termValue)(uri);
|
|
131
|
-
|
|
132
105
|
if (!this.isHttpUri(uri)) {
|
|
133
106
|
if (kb.holds(this.store.rdfFactory.namedNode(uri), this.store.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), this.store.rdfFactory.namedNode('http://www.w3.org/2007/ont/link#MachineEditableDocument'))) {
|
|
134
107
|
return 'LOCALFILE';
|
|
135
108
|
}
|
|
136
109
|
}
|
|
137
|
-
|
|
138
110
|
var request;
|
|
139
|
-
var definitive = false;
|
|
140
|
-
|
|
111
|
+
var definitive = false;
|
|
112
|
+
// @ts-ignore passes a string to kb.each, which expects a term. Should this work?
|
|
141
113
|
var requests = kb.each(undefined, this.ns.link('requestedURI'), (0, _uri.docpart)(uri));
|
|
142
114
|
var method;
|
|
143
|
-
|
|
144
115
|
for (var r = 0; r < requests.length; r++) {
|
|
145
116
|
request = requests[r];
|
|
146
|
-
|
|
147
117
|
if (request !== undefined) {
|
|
148
118
|
var response = kb.any(request, this.ns.link('response'));
|
|
149
|
-
|
|
150
119
|
if (request !== undefined) {
|
|
151
120
|
var wacAllow = kb.anyValue(response, this.ns.httph('wac-allow'));
|
|
152
|
-
|
|
153
121
|
if (wacAllow) {
|
|
154
122
|
var _iterator = _createForOfIteratorHelper(wacAllow.split(',')),
|
|
155
|
-
|
|
156
|
-
|
|
123
|
+
_step;
|
|
157
124
|
try {
|
|
158
125
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
159
126
|
var bit = _step.value;
|
|
160
127
|
var lr = bit.split('=');
|
|
161
|
-
|
|
162
128
|
if (lr[0].includes('user') && !lr[1].includes('write') && !lr[1].includes('append')) {
|
|
163
129
|
// console.log(' editable? excluded by WAC-Allow: ', wacAllow)
|
|
164
130
|
return false;
|
|
@@ -170,9 +136,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
170
136
|
_iterator.f();
|
|
171
137
|
}
|
|
172
138
|
}
|
|
173
|
-
|
|
174
139
|
var acceptPatch = kb.each(response, this.ns.httph('accept-patch'));
|
|
175
|
-
|
|
176
140
|
if (acceptPatch.length) {
|
|
177
141
|
for (var i = 0; i < acceptPatch.length; i++) {
|
|
178
142
|
method = acceptPatch[i].value.trim();
|
|
@@ -180,50 +144,44 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
180
144
|
if (method.indexOf('application/sparql-update-single-match') >= 0) return 'SPARQL';
|
|
181
145
|
}
|
|
182
146
|
}
|
|
183
|
-
|
|
184
147
|
var authorVia = kb.each(response, this.ns.httph('ms-author-via'));
|
|
185
|
-
|
|
186
148
|
if (authorVia.length) {
|
|
187
149
|
for (var _i = 0; _i < authorVia.length; _i++) {
|
|
188
150
|
method = authorVia[_i].value.trim();
|
|
189
|
-
|
|
190
151
|
if (method.indexOf('SPARQL') >= 0) {
|
|
191
152
|
return 'SPARQL';
|
|
192
153
|
}
|
|
193
|
-
|
|
194
154
|
if (method.indexOf('DAV') >= 0) {
|
|
195
155
|
return 'DAV';
|
|
196
156
|
}
|
|
197
157
|
}
|
|
198
158
|
}
|
|
199
|
-
|
|
200
159
|
if (!this.isHttpUri(uri)) {
|
|
201
160
|
if (!wacAllow) return false;else return 'LOCALFILE';
|
|
202
161
|
}
|
|
203
|
-
|
|
204
162
|
var status = kb.each(response, this.ns.http('status'));
|
|
205
|
-
|
|
206
163
|
if (status.length) {
|
|
207
164
|
for (var _i2 = 0; _i2 < status.length; _i2++) {
|
|
208
165
|
// @ts-ignore since statuses should be TFTerms, this should always be false
|
|
209
166
|
if (status[_i2] === 200 || status[_i2] === 404) {
|
|
210
|
-
definitive = true;
|
|
167
|
+
definitive = true;
|
|
168
|
+
// return false // A definitive answer
|
|
211
169
|
}
|
|
212
170
|
}
|
|
213
171
|
}
|
|
214
|
-
} else {
|
|
172
|
+
} else {
|
|
173
|
+
// console.log('UpdateManager.editable: No response for ' + uri + '\n')
|
|
215
174
|
}
|
|
216
175
|
}
|
|
217
176
|
}
|
|
218
|
-
|
|
219
|
-
|
|
177
|
+
if (requests.length === 0) {
|
|
178
|
+
// console.log('UpdateManager.editable: No request for ' + uri + '\n')
|
|
220
179
|
} else {
|
|
221
180
|
if (definitive) {
|
|
222
181
|
return false; // We have got a request and it did NOT say editable => not editable
|
|
223
182
|
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
183
|
+
}
|
|
184
|
+
// console.log('UpdateManager.editable: inconclusive for ' + uri + '\n')
|
|
227
185
|
return undefined; // We don't know (yet) as we haven't had a response (yet)
|
|
228
186
|
}
|
|
229
187
|
}, {
|
|
@@ -241,11 +199,11 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
241
199
|
value: function nTriples(stmt) {
|
|
242
200
|
return "".concat(stmt.subject.toNT(), " ").concat(stmt.predicate.toNT(), " ").concat(stmt.object.toNT(), " .");
|
|
243
201
|
}
|
|
202
|
+
|
|
244
203
|
/**
|
|
245
204
|
* Returns a list of all bnodes occurring in a statement
|
|
246
205
|
* @private
|
|
247
206
|
*/
|
|
248
|
-
|
|
249
207
|
}, {
|
|
250
208
|
key: "statementBnodes",
|
|
251
209
|
value: function statementBnodes(st) {
|
|
@@ -253,59 +211,51 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
253
211
|
return (0, _terms.isBlankNode)(x);
|
|
254
212
|
});
|
|
255
213
|
}
|
|
214
|
+
|
|
256
215
|
/**
|
|
257
216
|
* Returns a list of all bnodes occurring in a list of statements
|
|
258
217
|
* @private
|
|
259
218
|
*/
|
|
260
|
-
|
|
261
219
|
}, {
|
|
262
220
|
key: "statementArrayBnodes",
|
|
263
221
|
value: function statementArrayBnodes(sts) {
|
|
264
222
|
var bnodes = [];
|
|
265
|
-
|
|
266
223
|
for (var i = 0; i < sts.length; i++) {
|
|
267
224
|
bnodes = bnodes.concat(this.statementBnodes(sts[i]));
|
|
268
225
|
}
|
|
269
|
-
|
|
270
226
|
bnodes.sort(); // in place sort - result may have duplicates
|
|
271
|
-
|
|
272
227
|
var bnodes2 = [];
|
|
273
|
-
|
|
274
228
|
for (var j = 0; j < bnodes.length; j++) {
|
|
275
229
|
if (j === 0 || !bnodes[j].equals(bnodes[j - 1])) {
|
|
276
230
|
bnodes2.push(bnodes[j]);
|
|
277
231
|
}
|
|
278
232
|
}
|
|
279
|
-
|
|
280
233
|
return bnodes2;
|
|
281
234
|
}
|
|
235
|
+
|
|
282
236
|
/**
|
|
283
237
|
* Makes a cached list of [Inverse-]Functional properties
|
|
284
238
|
* @private
|
|
285
239
|
*/
|
|
286
|
-
|
|
287
240
|
}, {
|
|
288
241
|
key: "cacheIfps",
|
|
289
242
|
value: function cacheIfps() {
|
|
290
243
|
this.ifps = {};
|
|
291
244
|
var a = this.store.each(undefined, this.ns.rdf('type'), this.ns.owl('InverseFunctionalProperty'));
|
|
292
|
-
|
|
293
245
|
for (var i = 0; i < a.length; i++) {
|
|
294
246
|
this.ifps[a[i].value] = true;
|
|
295
247
|
}
|
|
296
|
-
|
|
297
248
|
this.fps = {};
|
|
298
249
|
a = this.store.each(undefined, this.ns.rdf('type'), this.ns.owl('FunctionalProperty'));
|
|
299
|
-
|
|
300
250
|
for (var _i3 = 0; _i3 < a.length; _i3++) {
|
|
301
251
|
this.fps[a[_i3].value] = true;
|
|
302
252
|
}
|
|
303
253
|
}
|
|
254
|
+
|
|
304
255
|
/**
|
|
305
256
|
* Returns a context to bind a given node, up to a given depth
|
|
306
257
|
* @private
|
|
307
258
|
*/
|
|
308
|
-
|
|
309
259
|
}, {
|
|
310
260
|
key: "bnodeContext2",
|
|
311
261
|
value: function bnodeContext2(x, source, depth) {
|
|
@@ -313,56 +263,45 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
313
263
|
// Depth > 1 if try further indirection.
|
|
314
264
|
// Return array of statements (possibly empty), or null if failure
|
|
315
265
|
var sts = this.store.statementsMatching(undefined, undefined, x, source); // incoming links
|
|
316
|
-
|
|
317
266
|
var y;
|
|
318
267
|
var res;
|
|
319
|
-
|
|
320
268
|
for (var i = 0; i < sts.length; i++) {
|
|
321
269
|
if (this.fps[sts[i].predicate.value]) {
|
|
322
270
|
y = sts[i].subject;
|
|
323
|
-
|
|
324
271
|
if (!y.isBlank) {
|
|
325
272
|
return [sts[i]];
|
|
326
273
|
}
|
|
327
|
-
|
|
328
274
|
if (depth) {
|
|
329
275
|
res = this.bnodeContext2(y, source, depth - 1);
|
|
330
|
-
|
|
331
276
|
if (res) {
|
|
332
277
|
return res.concat([sts[i]]);
|
|
333
278
|
}
|
|
334
279
|
}
|
|
335
280
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
281
|
+
}
|
|
282
|
+
// outgoing links
|
|
339
283
|
sts = this.store.statementsMatching(x, undefined, undefined, source);
|
|
340
|
-
|
|
341
284
|
for (var _i4 = 0; _i4 < sts.length; _i4++) {
|
|
342
285
|
if (this.ifps[sts[_i4].predicate.value]) {
|
|
343
286
|
y = sts[_i4].object;
|
|
344
|
-
|
|
345
287
|
if (!y.isBlank) {
|
|
346
288
|
return [sts[_i4]];
|
|
347
289
|
}
|
|
348
|
-
|
|
349
290
|
if (depth) {
|
|
350
291
|
res = this.bnodeContext2(y, source, depth - 1);
|
|
351
|
-
|
|
352
292
|
if (res) {
|
|
353
293
|
return res.concat([sts[_i4]]);
|
|
354
294
|
}
|
|
355
295
|
}
|
|
356
296
|
}
|
|
357
297
|
}
|
|
358
|
-
|
|
359
298
|
return null; // Failure
|
|
360
299
|
}
|
|
300
|
+
|
|
361
301
|
/**
|
|
362
302
|
* Returns the smallest context to bind a given single bnode
|
|
363
303
|
* @private
|
|
364
304
|
*/
|
|
365
|
-
|
|
366
305
|
}, {
|
|
367
306
|
key: "bnodeContext1",
|
|
368
307
|
value: function bnodeContext1(x, source) {
|
|
@@ -372,34 +311,32 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
372
311
|
// Try simple first
|
|
373
312
|
var con = this.bnodeContext2(x, source, depth);
|
|
374
313
|
if (con !== null) return con;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
314
|
+
}
|
|
315
|
+
// If we can't guarantee unique with logic just send all info about node
|
|
378
316
|
return this.store.connectedStatements(x, source); // was:
|
|
379
317
|
// throw new Error('Unable to uniquely identify bnode: ' + x.toNT())
|
|
380
318
|
}
|
|
319
|
+
|
|
381
320
|
/**
|
|
382
321
|
* @private
|
|
383
322
|
*/
|
|
384
|
-
|
|
385
323
|
}, {
|
|
386
324
|
key: "mentioned",
|
|
387
325
|
value: function mentioned(x) {
|
|
388
|
-
return this.store.statementsMatching(x, null, null, null).length !== 0 ||
|
|
326
|
+
return this.store.statementsMatching(x, null, null, null).length !== 0 ||
|
|
327
|
+
// Don't pin fresh bnodes
|
|
389
328
|
this.store.statementsMatching(null, x).length !== 0 || this.store.statementsMatching(null, null, x).length !== 0;
|
|
390
329
|
}
|
|
330
|
+
|
|
391
331
|
/**
|
|
392
332
|
* @private
|
|
393
333
|
*/
|
|
394
|
-
|
|
395
334
|
}, {
|
|
396
335
|
key: "bnodeContext",
|
|
397
336
|
value: function bnodeContext(bnodes, doc) {
|
|
398
337
|
var context = [];
|
|
399
|
-
|
|
400
338
|
if (bnodes.length) {
|
|
401
339
|
this.cacheIfps();
|
|
402
|
-
|
|
403
340
|
for (var i = 0; i < bnodes.length; i++) {
|
|
404
341
|
// Does this occur in old graph?
|
|
405
342
|
var bnode = bnodes[i];
|
|
@@ -407,24 +344,23 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
407
344
|
context = context.concat(this.bnodeContext1(bnode, doc));
|
|
408
345
|
}
|
|
409
346
|
}
|
|
410
|
-
|
|
411
347
|
return context;
|
|
412
348
|
}
|
|
349
|
+
|
|
413
350
|
/**
|
|
414
351
|
* Returns the best context for a single statement
|
|
415
352
|
* @private
|
|
416
353
|
*/
|
|
417
|
-
|
|
418
354
|
}, {
|
|
419
355
|
key: "statementContext",
|
|
420
356
|
value: function statementContext(st) {
|
|
421
357
|
var bnodes = this.statementBnodes(st);
|
|
422
358
|
return this.bnodeContext(bnodes, st.graph);
|
|
423
359
|
}
|
|
360
|
+
|
|
424
361
|
/**
|
|
425
362
|
* @private
|
|
426
363
|
*/
|
|
427
|
-
|
|
428
364
|
}, {
|
|
429
365
|
key: "contextWhere",
|
|
430
366
|
value: function contextWhere(context) {
|
|
@@ -433,21 +369,20 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
433
369
|
return updater.anonymizeNT(x);
|
|
434
370
|
}).join('\n') + ' }\n';
|
|
435
371
|
}
|
|
372
|
+
|
|
436
373
|
/**
|
|
437
374
|
* @private
|
|
438
375
|
*/
|
|
439
|
-
|
|
440
376
|
}, {
|
|
441
377
|
key: "fire",
|
|
442
378
|
value: function fire(uri, query, callbackFunction) {
|
|
443
379
|
var _this = this;
|
|
444
|
-
|
|
445
380
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
446
381
|
return Promise.resolve().then(function () {
|
|
447
382
|
if (!uri) {
|
|
448
383
|
throw new Error('No URI given for remote editing operation: ' + query);
|
|
449
|
-
}
|
|
450
|
-
|
|
384
|
+
}
|
|
385
|
+
// console.log('UpdateManager: sending update to <' + uri + '>')
|
|
451
386
|
|
|
452
387
|
options.noMeta = true;
|
|
453
388
|
options.contentType = 'application/sparql-update';
|
|
@@ -455,18 +390,20 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
455
390
|
return _this.store.fetcher.webOperation('PATCH', uri, options);
|
|
456
391
|
}).then(function (response) {
|
|
457
392
|
if (!response.ok) {
|
|
458
|
-
var _message = 'UpdateManager: update failed for <' + uri + '> status=' + response.status + ', ' + response.statusText + '\n for query: ' + query;
|
|
459
|
-
|
|
460
|
-
|
|
393
|
+
var _message = 'UpdateManager: update failed for <' + uri + '> status=' + response.status + ', ' + response.statusText + '\n for query: ' + query;
|
|
394
|
+
// console.log(message)
|
|
461
395
|
throw new Error(_message);
|
|
462
|
-
}
|
|
396
|
+
}
|
|
463
397
|
|
|
398
|
+
// console.log('UpdateManager: update Ok for <' + uri + '>')
|
|
464
399
|
|
|
465
400
|
callbackFunction(uri, response.ok, response.responseText, response);
|
|
466
401
|
}).catch(function (err) {
|
|
467
402
|
callbackFunction(uri, false, err.message, err);
|
|
468
403
|
});
|
|
469
|
-
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// ARE THESE THEE FUNCTIONS USED? DEPROCATE?
|
|
470
407
|
|
|
471
408
|
/** return a statemnet updating function
|
|
472
409
|
*
|
|
@@ -474,14 +411,12 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
474
411
|
* It returns an object which includes
|
|
475
412
|
* function which can be used to change the object of the statement.
|
|
476
413
|
*/
|
|
477
|
-
|
|
478
414
|
}, {
|
|
479
415
|
key: "update_statement",
|
|
480
416
|
value: function update_statement(statement) {
|
|
481
417
|
if (statement && !statement.graph) {
|
|
482
418
|
return;
|
|
483
419
|
}
|
|
484
|
-
|
|
485
420
|
var updater = this;
|
|
486
421
|
var context = this.statementContext(statement);
|
|
487
422
|
return {
|
|
@@ -491,9 +426,12 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
491
426
|
set_object: function set_object(obj, callbackFunction) {
|
|
492
427
|
var query = this.where;
|
|
493
428
|
query += 'DELETE DATA { ' + this.statementNT + ' } ;\n';
|
|
494
|
-
query += 'INSERT DATA { ' +
|
|
495
|
-
this
|
|
496
|
-
this.anonymize(this.statement[
|
|
429
|
+
query += 'INSERT DATA { ' +
|
|
430
|
+
// @ts-ignore `this` might refer to the wrong scope. Does this work?
|
|
431
|
+
this.anonymize(this.statement[0]) + ' ' +
|
|
432
|
+
// @ts-ignore
|
|
433
|
+
this.anonymize(this.statement[1]) + ' ' +
|
|
434
|
+
// @ts-ignore
|
|
497
435
|
this.anonymize(obj) + ' ' + ' . }\n';
|
|
498
436
|
updater.fire(this.statement[3].value, query, callbackFunction);
|
|
499
437
|
}
|
|
@@ -504,19 +442,13 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
504
442
|
value: function insert_statement(st, callbackFunction) {
|
|
505
443
|
var st0 = st instanceof Array ? st[0] : st;
|
|
506
444
|
var query = this.contextWhere(this.statementContext(st0));
|
|
507
|
-
|
|
508
445
|
if (st instanceof Array) {
|
|
509
446
|
var stText = '';
|
|
510
|
-
|
|
511
|
-
for (var i = 0; i < st.length; i++) {
|
|
512
|
-
stText += st[i] + '\n';
|
|
513
|
-
}
|
|
514
|
-
|
|
447
|
+
for (var i = 0; i < st.length; i++) stText += st[i] + '\n';
|
|
515
448
|
query += 'INSERT DATA { ' + stText + ' }\n';
|
|
516
449
|
} else {
|
|
517
450
|
query += 'INSERT DATA { ' + this.anonymize(st.subject) + ' ' + this.anonymize(st.predicate) + ' ' + this.anonymize(st.object) + ' ' + ' . }\n';
|
|
518
451
|
}
|
|
519
|
-
|
|
520
452
|
this.fire(st0.graph.value, query, callbackFunction);
|
|
521
453
|
}
|
|
522
454
|
}, {
|
|
@@ -524,21 +456,17 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
524
456
|
value: function delete_statement(st, callbackFunction) {
|
|
525
457
|
var st0 = st instanceof Array ? st[0] : st;
|
|
526
458
|
var query = this.contextWhere(this.statementContext(st0));
|
|
527
|
-
|
|
528
459
|
if (st instanceof Array) {
|
|
529
460
|
var stText = '';
|
|
530
|
-
|
|
531
|
-
for (var i = 0; i < st.length; i++) {
|
|
532
|
-
stText += st[i] + '\n';
|
|
533
|
-
}
|
|
534
|
-
|
|
461
|
+
for (var i = 0; i < st.length; i++) stText += st[i] + '\n';
|
|
535
462
|
query += 'DELETE DATA { ' + stText + ' }\n';
|
|
536
463
|
} else {
|
|
537
464
|
query += 'DELETE DATA { ' + this.anonymize(st.subject) + ' ' + this.anonymize(st.predicate) + ' ' + this.anonymize(st.object) + ' ' + ' . }\n';
|
|
538
465
|
}
|
|
539
|
-
|
|
540
466
|
this.fire(st0.graph.value, query, callbackFunction);
|
|
541
|
-
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/// //////////////////////
|
|
542
470
|
|
|
543
471
|
/**
|
|
544
472
|
* Requests a now or future action to refresh changes coming downstream
|
|
@@ -549,12 +477,10 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
549
477
|
* @param doc
|
|
550
478
|
* @param action
|
|
551
479
|
*/
|
|
552
|
-
|
|
553
480
|
}, {
|
|
554
481
|
key: "requestDownstreamAction",
|
|
555
482
|
value: function requestDownstreamAction(doc, action) {
|
|
556
483
|
var control = this.patchControlFor(doc);
|
|
557
|
-
|
|
558
484
|
if (!control.pendingUpstream) {
|
|
559
485
|
action(doc);
|
|
560
486
|
} else {
|
|
@@ -568,11 +494,11 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
568
494
|
}
|
|
569
495
|
}
|
|
570
496
|
}
|
|
497
|
+
|
|
571
498
|
/**
|
|
572
499
|
* We want to start counting websocket notifications
|
|
573
500
|
* to distinguish the ones from others from our own.
|
|
574
501
|
*/
|
|
575
|
-
|
|
576
502
|
}, {
|
|
577
503
|
key: "clearUpstreamCount",
|
|
578
504
|
value: function clearUpstreamCount(doc) {
|
|
@@ -590,13 +516,10 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
590
516
|
key: "addDownstreamChangeListener",
|
|
591
517
|
value: function addDownstreamChangeListener(doc, listener) {
|
|
592
518
|
var _this2 = this;
|
|
593
|
-
|
|
594
519
|
var control = this.patchControlFor(doc);
|
|
595
|
-
|
|
596
520
|
if (!control.downstreamChangeListeners) {
|
|
597
521
|
control.downstreamChangeListeners = [];
|
|
598
522
|
}
|
|
599
|
-
|
|
600
523
|
control.downstreamChangeListeners.push(listener);
|
|
601
524
|
this.setRefreshHandler(doc, function (doc) {
|
|
602
525
|
_this2.reloadAndSync(doc);
|
|
@@ -607,7 +530,6 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
607
530
|
value: function reloadAndSync(doc) {
|
|
608
531
|
var control = this.patchControlFor(doc);
|
|
609
532
|
var updater = this;
|
|
610
|
-
|
|
611
533
|
if (control.reloading) {
|
|
612
534
|
// console.log(' Already reloading - note this load may be out of date')
|
|
613
535
|
control.outOfDate = true;
|
|
@@ -616,7 +538,6 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
616
538
|
|
|
617
539
|
control.reloading = true;
|
|
618
540
|
var retryTimeout = 1000; // ms
|
|
619
|
-
|
|
620
541
|
var tryReload = function tryReload() {
|
|
621
542
|
// console.log('try reload - timeout = ' + retryTimeout)
|
|
622
543
|
updater.reload(updater.store, doc, function (ok, message, response) {
|
|
@@ -627,9 +548,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
627
548
|
control.downstreamChangeListeners[i]();
|
|
628
549
|
}
|
|
629
550
|
}
|
|
630
|
-
|
|
631
551
|
control.reloading = false;
|
|
632
|
-
|
|
633
552
|
if (control.outOfDate) {
|
|
634
553
|
// console.log(' Extra reload because of extra update.')
|
|
635
554
|
control.outOfDate = false;
|
|
@@ -637,22 +556,22 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
637
556
|
}
|
|
638
557
|
} else {
|
|
639
558
|
control.reloading = false;
|
|
640
|
-
|
|
641
559
|
if (response.status === 0) {
|
|
642
560
|
// console.log('Network error refreshing the data. Retrying in ' +
|
|
643
561
|
// retryTimeout / 1000)
|
|
644
562
|
control.reloading = true;
|
|
645
563
|
retryTimeout = retryTimeout * 2;
|
|
646
564
|
setTimeout(tryReload, retryTimeout);
|
|
647
|
-
} else {
|
|
565
|
+
} else {
|
|
566
|
+
// console.log('Error ' + (response as Response).status + 'refreshing the data:' +
|
|
648
567
|
// message + '. Stopped' + doc)
|
|
649
568
|
}
|
|
650
569
|
}
|
|
651
570
|
});
|
|
652
571
|
};
|
|
653
|
-
|
|
654
572
|
tryReload();
|
|
655
573
|
}
|
|
574
|
+
|
|
656
575
|
/**
|
|
657
576
|
* Sets up websocket to listen on
|
|
658
577
|
*
|
|
@@ -670,32 +589,27 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
670
589
|
*
|
|
671
590
|
* @returns {boolean}
|
|
672
591
|
*/
|
|
673
|
-
|
|
674
592
|
}, {
|
|
675
593
|
key: "setRefreshHandler",
|
|
676
594
|
value: function setRefreshHandler(doc, handler) {
|
|
677
595
|
var wssURI = this.getUpdatesVia(doc); // relative
|
|
678
596
|
// var kb = this.store
|
|
679
|
-
|
|
680
597
|
var theHandler = handler;
|
|
681
598
|
var self = this;
|
|
682
599
|
var updater = this;
|
|
683
600
|
var retryTimeout = 1500; // *2 will be 3 Seconds, 6, 12, etc
|
|
684
|
-
|
|
685
601
|
var retries = 0;
|
|
686
|
-
|
|
687
602
|
if (!wssURI) {
|
|
688
603
|
// console.log('Server does not support live updates through Updates-Via :-(')
|
|
689
604
|
return false;
|
|
690
605
|
}
|
|
691
|
-
|
|
692
606
|
wssURI = (0, _uri.join)(wssURI, doc.value);
|
|
693
|
-
var validWssURI = wssURI.replace(/^http:/, 'ws:').replace(/^https:/, 'wss:');
|
|
607
|
+
var validWssURI = wssURI.replace(/^http:/, 'ws:').replace(/^https:/, 'wss:');
|
|
608
|
+
// console.log('Web socket URI ' + wssURI)
|
|
694
609
|
|
|
695
610
|
var openWebsocket = function openWebsocket() {
|
|
696
611
|
// From https://github.com/solid/solid-spec#live-updates
|
|
697
612
|
var socket;
|
|
698
|
-
|
|
699
613
|
if (typeof WebSocket !== 'undefined') {
|
|
700
614
|
socket = new WebSocket(validWssURI);
|
|
701
615
|
} else if (typeof window !== 'undefined' && window.WebSocket) {
|
|
@@ -704,24 +618,22 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
704
618
|
// console.log('Live update disabled, as WebSocket not supported by platform :-(')
|
|
705
619
|
return;
|
|
706
620
|
}
|
|
707
|
-
|
|
708
621
|
socket.onopen = function () {
|
|
709
622
|
// console.log(' websocket open')
|
|
710
623
|
retryTimeout = 1500; // reset timeout to fast on success
|
|
711
|
-
|
|
712
624
|
this.send('sub ' + doc.value);
|
|
713
|
-
|
|
714
625
|
if (retries) {
|
|
715
626
|
// console.log('Web socket has been down, better check for any news.')
|
|
716
627
|
updater.requestDownstreamAction(doc, theHandler);
|
|
717
628
|
}
|
|
718
629
|
};
|
|
719
|
-
|
|
720
630
|
var control = self.patchControlFor(doc);
|
|
721
631
|
control.upstreamCount = 0;
|
|
632
|
+
socket.onerror = function onerror(err) {
|
|
633
|
+
// console.log('Error on Websocket:', err)
|
|
634
|
+
};
|
|
722
635
|
|
|
723
|
-
|
|
724
|
-
}; // https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
|
|
636
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
|
|
725
637
|
//
|
|
726
638
|
// 1000 CLOSE_NORMAL Normal closure; the connection successfully completed whatever purpose for which it was created.
|
|
727
639
|
// 1001 CLOSE_GOING_AWAY The endpoint is going away, either
|
|
@@ -734,42 +646,36 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
734
646
|
// 1006 CLOSE_ABNORMAL Reserved. Used to indicate that a connection was closed abnormally (
|
|
735
647
|
//
|
|
736
648
|
//
|
|
737
|
-
|
|
738
|
-
|
|
739
649
|
socket.onclose = function (event) {
|
|
740
650
|
// console.log('*** Websocket closed with code ' + event.code +
|
|
741
651
|
// ", reason '" + event.reason + "' clean = " + event.wasClean)
|
|
742
652
|
retryTimeout *= 2;
|
|
743
|
-
retries += 1;
|
|
744
|
-
|
|
653
|
+
retries += 1;
|
|
654
|
+
// console.log('Retrying in ' + retryTimeout + 'ms') // (ask user?)
|
|
745
655
|
setTimeout(function () {
|
|
746
656
|
// console.log('Trying websocket again')
|
|
747
657
|
openWebsocket();
|
|
748
658
|
}, retryTimeout);
|
|
749
659
|
};
|
|
750
|
-
|
|
751
660
|
socket.onmessage = function (msg) {
|
|
752
661
|
if (msg.data && msg.data.slice(0, 3) === 'pub') {
|
|
753
662
|
if ('upstreamCount' in control) {
|
|
754
663
|
control.upstreamCount -= 1;
|
|
755
|
-
|
|
756
664
|
if (control.upstreamCount >= 0) {
|
|
757
665
|
// console.log('just an echo: ' + control.upstreamCount)
|
|
758
666
|
return; // Just an echo
|
|
759
667
|
}
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
|
|
668
|
+
}
|
|
669
|
+
// console.log('Assume a real downstream change: ' + control.upstreamCount + ' -> 0')
|
|
763
670
|
control.upstreamCount = 0;
|
|
764
671
|
self.requestDownstreamAction(doc, theHandler);
|
|
765
672
|
}
|
|
766
673
|
};
|
|
767
674
|
}; // openWebsocket
|
|
768
|
-
|
|
769
|
-
|
|
770
675
|
openWebsocket();
|
|
771
676
|
return true;
|
|
772
677
|
}
|
|
678
|
+
|
|
773
679
|
/**
|
|
774
680
|
* This high-level function updates the local store iff the web is changed successfully.
|
|
775
681
|
* Deletions, insertions may be undefined or single statements or lists or formulae (may contain bnodes which can be indirectly identified by a where clause).
|
|
@@ -779,7 +685,6 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
779
685
|
* @param insertions - Statement or statements to be inserted.
|
|
780
686
|
* @returns a promise
|
|
781
687
|
*/
|
|
782
|
-
|
|
783
688
|
}, {
|
|
784
689
|
key: "updateMany",
|
|
785
690
|
value: function updateMany(deletions) {
|
|
@@ -801,12 +706,12 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
801
706
|
return st.why.equals(doc);
|
|
802
707
|
}));
|
|
803
708
|
});
|
|
804
|
-
|
|
805
|
-
|
|
709
|
+
if (updates.length > 1) {
|
|
710
|
+
// console.log(`@@ updateMany to ${updates.length}: ${uniqueDocs}`)
|
|
806
711
|
}
|
|
807
|
-
|
|
808
712
|
return Promise.all(updates);
|
|
809
713
|
}
|
|
714
|
+
|
|
810
715
|
/**
|
|
811
716
|
* This high-level function updates the local store iff the web is changed successfully.
|
|
812
717
|
* Deletions, insertions may be undefined or single statements or lists or formulae (may contain bnodes which can be indirectly identified by a where clause).
|
|
@@ -817,14 +722,11 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
817
722
|
* OR returns a promise
|
|
818
723
|
* @param options - Options for the fetch call
|
|
819
724
|
*/
|
|
820
|
-
|
|
821
725
|
}, {
|
|
822
726
|
key: "update",
|
|
823
727
|
value: function update(deletions, insertions, callback, secondTry) {
|
|
824
728
|
var _this3 = this;
|
|
825
|
-
|
|
826
729
|
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
827
|
-
|
|
828
730
|
if (!callback) {
|
|
829
731
|
var thisUpdater = this;
|
|
830
732
|
return new Promise(function (resolve, reject) {
|
|
@@ -839,33 +741,31 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
839
741
|
}); // promise
|
|
840
742
|
} // if
|
|
841
743
|
|
|
842
|
-
|
|
843
744
|
try {
|
|
844
745
|
var kb = this.store;
|
|
845
746
|
var ds = !deletions ? [] : (0, _terms.isStore)(deletions) ? deletions.statements : deletions instanceof Array ? deletions : [deletions];
|
|
846
747
|
var is = !insertions ? [] : (0, _terms.isStore)(insertions) ? insertions.statements : insertions instanceof Array ? insertions : [insertions];
|
|
847
|
-
|
|
848
748
|
if (!(ds instanceof Array)) {
|
|
849
749
|
throw new Error('Type Error ' + (0, _typeof2.default)(ds) + ': ' + ds);
|
|
850
750
|
}
|
|
851
|
-
|
|
852
751
|
if (!(is instanceof Array)) {
|
|
853
752
|
throw new Error('Type Error ' + (0, _typeof2.default)(is) + ': ' + is);
|
|
854
753
|
}
|
|
855
|
-
|
|
856
754
|
if (ds.length === 0 && is.length === 0) {
|
|
857
755
|
return callback(null, true); // success -- nothing needed to be done.
|
|
858
756
|
}
|
|
859
757
|
|
|
860
758
|
var doc = ds.length ? ds[0].graph : is[0].graph;
|
|
861
|
-
|
|
862
759
|
if (!doc) {
|
|
863
|
-
var _message2 = 'Error patching: statement does not specify which document to patch:' + ds[0] + ', ' + is[0];
|
|
864
|
-
|
|
865
|
-
|
|
760
|
+
var _message2 = 'Error patching: statement does not specify which document to patch:' + ds[0] + ', ' + is[0];
|
|
761
|
+
// console.log(message)
|
|
866
762
|
throw new Error(_message2);
|
|
867
763
|
}
|
|
868
|
-
|
|
764
|
+
if (doc.termType !== 'NamedNode') {
|
|
765
|
+
var _message3 = 'Error patching: document not a NamedNode:' + ds[0] + ', ' + is[0];
|
|
766
|
+
// console.log(message)
|
|
767
|
+
throw new Error(_message3);
|
|
768
|
+
}
|
|
869
769
|
var control = this.patchControlFor(doc);
|
|
870
770
|
var startTime = Date.now();
|
|
871
771
|
var props = ['subject', 'predicate', 'object', 'why'];
|
|
@@ -879,7 +779,6 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
879
779
|
if (!doc.equals(st.graph)) {
|
|
880
780
|
throw new Error('update: destination ' + doc + ' inconsistent with delete quad ' + st.graph);
|
|
881
781
|
}
|
|
882
|
-
|
|
883
782
|
props.map(function (prop) {
|
|
884
783
|
if (typeof st[prop] === 'undefined') {
|
|
885
784
|
throw new Error('update: undefined ' + prop + ' of statement.');
|
|
@@ -888,18 +787,15 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
888
787
|
});
|
|
889
788
|
});
|
|
890
789
|
var protocol = this.editable(doc.value, kb);
|
|
891
|
-
|
|
892
790
|
if (protocol === false) {
|
|
893
791
|
throw new Error('Update: Can\'t make changes in uneditable ' + doc);
|
|
894
792
|
}
|
|
895
|
-
|
|
896
793
|
if (protocol === undefined) {
|
|
897
794
|
// Not enough metadata
|
|
898
795
|
if (secondTry) {
|
|
899
796
|
throw new Error('Update: Loaded ' + doc + "but stil can't figure out what editing protcol it supports.");
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
|
|
797
|
+
}
|
|
798
|
+
// console.log(`Update: have not loaded ${doc} before: loading now...`);
|
|
903
799
|
this.store.fetcher.load(doc).then(function (response) {
|
|
904
800
|
_this3.update(deletions, insertions, callback, true, options);
|
|
905
801
|
}, function (err) {
|
|
@@ -913,62 +809,50 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
913
809
|
return;
|
|
914
810
|
} else if (protocol.indexOf('SPARQL') >= 0) {
|
|
915
811
|
var bnodes = [];
|
|
812
|
+
// change ReadOnly type to Mutable type
|
|
813
|
+
|
|
916
814
|
if (ds.length) bnodes = this.statementArrayBnodes(ds);
|
|
917
815
|
if (is.length) bnodes = bnodes.concat(this.statementArrayBnodes(is));
|
|
918
816
|
var context = this.bnodeContext(bnodes, doc);
|
|
919
817
|
var whereClause = this.contextWhere(context);
|
|
920
818
|
var query = '';
|
|
921
|
-
|
|
922
819
|
if (whereClause.length) {
|
|
923
820
|
// Is there a WHERE clause?
|
|
924
821
|
if (ds.length) {
|
|
925
822
|
query += 'DELETE { ';
|
|
926
|
-
|
|
927
823
|
for (var i = 0; i < ds.length; i++) {
|
|
928
824
|
query += this.anonymizeNT(ds[i]) + '\n';
|
|
929
825
|
}
|
|
930
|
-
|
|
931
826
|
query += ' }\n';
|
|
932
827
|
}
|
|
933
|
-
|
|
934
828
|
if (is.length) {
|
|
935
829
|
query += 'INSERT { ';
|
|
936
|
-
|
|
937
830
|
for (var _i5 = 0; _i5 < is.length; _i5++) {
|
|
938
831
|
query += this.anonymizeNT(is[_i5]) + '\n';
|
|
939
832
|
}
|
|
940
|
-
|
|
941
833
|
query += ' }\n';
|
|
942
834
|
}
|
|
943
|
-
|
|
944
835
|
query += whereClause;
|
|
945
836
|
} else {
|
|
946
837
|
// no where clause
|
|
947
838
|
if (ds.length) {
|
|
948
839
|
query += 'DELETE DATA { ';
|
|
949
|
-
|
|
950
840
|
for (var _i6 = 0; _i6 < ds.length; _i6++) {
|
|
951
841
|
query += this.anonymizeNT(ds[_i6]) + '\n';
|
|
952
842
|
}
|
|
953
|
-
|
|
954
843
|
query += ' } \n';
|
|
955
844
|
}
|
|
956
|
-
|
|
957
845
|
if (is.length) {
|
|
958
846
|
if (ds.length) query += ' ; ';
|
|
959
847
|
query += 'INSERT DATA { ';
|
|
960
|
-
|
|
961
848
|
for (var _i7 = 0; _i7 < is.length; _i7++) {
|
|
962
849
|
query += this.nTriples(is[_i7]) + '\n';
|
|
963
850
|
}
|
|
964
|
-
|
|
965
851
|
query += ' }\n';
|
|
966
852
|
}
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
|
|
853
|
+
}
|
|
854
|
+
// Track pending upstream patches until they have finished their callbackFunction
|
|
970
855
|
control.pendingUpstream = control.pendingUpstream ? control.pendingUpstream + 1 : 1;
|
|
971
|
-
|
|
972
856
|
if ('upstreamCount' in control) {
|
|
973
857
|
control.upstreamCount += 1; // count changes we originated ourselves
|
|
974
858
|
// console.log('upstream count up to : ' + control.upstreamCount)
|
|
@@ -980,7 +864,6 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
980
864
|
(success ? 'success ' : 'FAILURE ') + (response as Response).status +
|
|
981
865
|
' elapsed ' + (response as any).elapsedTimeMs + 'ms')
|
|
982
866
|
*/
|
|
983
|
-
|
|
984
867
|
if (success) {
|
|
985
868
|
try {
|
|
986
869
|
kb.remove(ds);
|
|
@@ -988,20 +871,17 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
988
871
|
success = false;
|
|
989
872
|
body = 'Remote Ok BUT error deleting ' + ds.length + ' from store!!! ' + e;
|
|
990
873
|
} // Add in any case -- help recover from weirdness??
|
|
991
|
-
|
|
992
|
-
|
|
993
874
|
for (var _i8 = 0; _i8 < is.length; _i8++) {
|
|
994
875
|
kb.add(is[_i8].subject, is[_i8].predicate, is[_i8].object, doc);
|
|
995
876
|
}
|
|
996
877
|
}
|
|
997
|
-
|
|
998
878
|
callback(uri, success, body, response);
|
|
999
|
-
control.pendingUpstream -= 1;
|
|
1000
|
-
|
|
879
|
+
control.pendingUpstream -= 1;
|
|
880
|
+
// When upstream patches have been sent, reload state if downstream waiting
|
|
1001
881
|
if (control.pendingUpstream === 0 && control.downstreamAction) {
|
|
1002
882
|
var downstreamAction = control.downstreamAction;
|
|
1003
|
-
delete control.downstreamAction;
|
|
1004
|
-
|
|
883
|
+
delete control.downstreamAction;
|
|
884
|
+
// console.log('delayed downstream action:')
|
|
1005
885
|
downstreamAction(doc);
|
|
1006
886
|
}
|
|
1007
887
|
}, options);
|
|
@@ -1012,7 +892,8 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1012
892
|
try {
|
|
1013
893
|
this.updateLocalFile(doc, ds, is, callback, options);
|
|
1014
894
|
} catch (e) {
|
|
1015
|
-
callback(doc.value, false, 'Exception trying to write back file <' + doc.value + '>\n'
|
|
895
|
+
callback(doc.value, false, 'Exception trying to write back file <' + doc.value + '>\n'
|
|
896
|
+
// + tabulator.Util.stackString(e))
|
|
1016
897
|
);
|
|
1017
898
|
}
|
|
1018
899
|
} else {
|
|
@@ -1027,42 +908,35 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1027
908
|
key: "updateDav",
|
|
1028
909
|
value: function updateDav(doc, ds, is, callbackFunction) {
|
|
1029
910
|
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1030
|
-
var kb = this.store;
|
|
1031
|
-
|
|
911
|
+
var kb = this.store;
|
|
912
|
+
// The code below is derived from Kenny's UpdateCenter.js
|
|
1032
913
|
var request = kb.any(doc, this.ns.link('request'));
|
|
1033
|
-
|
|
1034
914
|
if (!request) {
|
|
1035
915
|
throw new Error('No record of our HTTP GET request for document: ' + doc);
|
|
1036
916
|
} // should not happen
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
917
|
var response = kb.any(request, this.ns.link('response'));
|
|
1040
|
-
|
|
1041
918
|
if (!response) {
|
|
1042
919
|
return null; // throw "No record HTTP GET response for document: "+doc
|
|
1043
920
|
}
|
|
1044
921
|
|
|
1045
|
-
var contentType = kb.the(response, this.ns.httph('content-type')).value;
|
|
922
|
+
var contentType = kb.the(response, this.ns.httph('content-type')).value;
|
|
1046
923
|
|
|
924
|
+
// prepare contents of revised document
|
|
1047
925
|
var newSts = kb.statementsMatching(undefined, undefined, undefined, doc).slice(); // copy!
|
|
1048
|
-
|
|
1049
926
|
for (var i = 0; i < ds.length; i++) {
|
|
1050
927
|
Util.RDFArrayRemove(newSts, ds[i]);
|
|
1051
928
|
}
|
|
1052
|
-
|
|
1053
929
|
for (var _i9 = 0; _i9 < is.length; _i9++) {
|
|
1054
930
|
newSts.push(is[_i9]);
|
|
1055
931
|
}
|
|
932
|
+
var documentString = this.serialize(doc.value, newSts, contentType);
|
|
1056
933
|
|
|
1057
|
-
|
|
1058
|
-
|
|
934
|
+
// Write the new version back
|
|
1059
935
|
var candidateTarget = kb.the(response, this.ns.httph('content-location'));
|
|
1060
936
|
var targetURI;
|
|
1061
|
-
|
|
1062
937
|
if (candidateTarget) {
|
|
1063
938
|
targetURI = (0, _uri.join)(candidateTarget.value, targetURI);
|
|
1064
939
|
}
|
|
1065
|
-
|
|
1066
940
|
options.contentType = contentType;
|
|
1067
941
|
options.noMeta = true;
|
|
1068
942
|
options.body = documentString;
|
|
@@ -1070,20 +944,18 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1070
944
|
if (!response.ok) {
|
|
1071
945
|
throw new Error(response.error);
|
|
1072
946
|
}
|
|
1073
|
-
|
|
1074
947
|
for (var _i10 = 0; _i10 < ds.length; _i10++) {
|
|
1075
948
|
kb.remove(ds[_i10]);
|
|
1076
949
|
}
|
|
1077
|
-
|
|
1078
950
|
for (var _i11 = 0; _i11 < is.length; _i11++) {
|
|
1079
951
|
kb.add(is[_i11].subject, is[_i11].predicate, is[_i11].object, doc);
|
|
1080
952
|
}
|
|
1081
|
-
|
|
1082
953
|
callbackFunction(doc.value, response.ok, response.responseText, response);
|
|
1083
954
|
}).catch(function (err) {
|
|
1084
955
|
callbackFunction(doc.value, false, err.message, err);
|
|
1085
956
|
});
|
|
1086
957
|
}
|
|
958
|
+
|
|
1087
959
|
/**
|
|
1088
960
|
* Likely deprecated, since this lib no longer deals with browser extension
|
|
1089
961
|
*
|
|
@@ -1093,105 +965,89 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1093
965
|
* @param callbackFunction
|
|
1094
966
|
* @param options
|
|
1095
967
|
*/
|
|
1096
|
-
|
|
1097
968
|
}, {
|
|
1098
969
|
key: "updateLocalFile",
|
|
1099
970
|
value: function updateLocalFile(doc, ds, is, callbackFunction) {
|
|
1100
971
|
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1101
|
-
var kb = this.store;
|
|
1102
|
-
//
|
|
972
|
+
var kb = this.store;
|
|
973
|
+
// console.log('Writing back to local file\n')
|
|
1103
974
|
|
|
975
|
+
// prepare contents of revised document
|
|
1104
976
|
var newSts = kb.statementsMatching(undefined, undefined, undefined, doc).slice(); // copy!
|
|
1105
977
|
|
|
1106
978
|
for (var i = 0; i < ds.length; i++) {
|
|
1107
979
|
Util.RDFArrayRemove(newSts, ds[i]);
|
|
1108
980
|
}
|
|
1109
|
-
|
|
1110
981
|
for (var _i12 = 0; _i12 < is.length; _i12++) {
|
|
1111
982
|
newSts.push(is[_i12]);
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
|
|
983
|
+
}
|
|
984
|
+
// serialize to the appropriate format
|
|
1115
985
|
var dot = doc.value.lastIndexOf('.');
|
|
1116
|
-
|
|
1117
986
|
if (dot < 1) {
|
|
1118
987
|
throw new Error('Rewriting file: No filename extension: ' + doc.value);
|
|
1119
988
|
}
|
|
1120
|
-
|
|
1121
989
|
var ext = doc.value.slice(dot + 1);
|
|
1122
990
|
var contentType = _fetcher.default.CONTENT_TYPE_BY_EXT[ext];
|
|
1123
|
-
|
|
1124
991
|
if (!contentType) {
|
|
1125
992
|
throw new Error('File extension .' + ext + ' not supported for data write');
|
|
1126
993
|
}
|
|
1127
|
-
|
|
1128
994
|
options.body = this.serialize(doc.value, newSts, contentType);
|
|
1129
995
|
options.contentType = contentType;
|
|
1130
996
|
kb.fetcher.webOperation('PUT', doc.value, options).then(function (response) {
|
|
1131
997
|
if (!response.ok) return callbackFunction(doc.value, false, response.error);
|
|
1132
|
-
|
|
1133
998
|
for (var _i13 = 0; _i13 < ds.length; _i13++) {
|
|
1134
999
|
kb.remove(ds[_i13]);
|
|
1135
1000
|
}
|
|
1136
|
-
|
|
1137
1001
|
for (var _i14 = 0; _i14 < is.length; _i14++) {
|
|
1138
1002
|
kb.add(is[_i14].subject, is[_i14].predicate, is[_i14].object, doc);
|
|
1139
1003
|
}
|
|
1140
|
-
|
|
1141
1004
|
callbackFunction(doc.value, true, ''); // success!
|
|
1142
1005
|
});
|
|
1143
1006
|
}
|
|
1007
|
+
|
|
1144
1008
|
/**
|
|
1145
1009
|
* @throws {Error} On unsupported content type
|
|
1146
1010
|
*
|
|
1147
1011
|
* @returns {string}
|
|
1148
1012
|
*/
|
|
1149
|
-
|
|
1150
1013
|
}, {
|
|
1151
1014
|
key: "serialize",
|
|
1152
1015
|
value: function serialize(uri, data, contentType) {
|
|
1153
1016
|
var kb = this.store;
|
|
1154
1017
|
var documentString;
|
|
1155
|
-
|
|
1156
1018
|
if (typeof data === 'string') {
|
|
1157
1019
|
return data;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1020
|
+
}
|
|
1160
1021
|
|
|
1022
|
+
// serialize to the appropriate format
|
|
1161
1023
|
var sz = (0, _serializer.default)(kb);
|
|
1162
1024
|
sz.suggestNamespaces(kb.namespaces);
|
|
1163
1025
|
sz.setBase(uri);
|
|
1164
|
-
|
|
1165
1026
|
switch (contentType) {
|
|
1166
1027
|
case 'text/xml':
|
|
1167
1028
|
case 'application/rdf+xml':
|
|
1168
1029
|
documentString = sz.statementsToXML(data);
|
|
1169
1030
|
break;
|
|
1170
|
-
|
|
1171
1031
|
case 'text/n3':
|
|
1172
1032
|
case 'text/turtle':
|
|
1173
1033
|
case 'application/x-turtle': // Legacy
|
|
1174
|
-
|
|
1175
1034
|
case 'application/n3':
|
|
1176
1035
|
// Legacy
|
|
1177
1036
|
documentString = sz.statementsToN3(data);
|
|
1178
1037
|
break;
|
|
1179
|
-
|
|
1180
1038
|
default:
|
|
1181
1039
|
throw new Error('Content-type ' + contentType + ' not supported for data serialization');
|
|
1182
1040
|
}
|
|
1183
|
-
|
|
1184
1041
|
return documentString;
|
|
1185
1042
|
}
|
|
1043
|
+
|
|
1186
1044
|
/**
|
|
1187
1045
|
* This is suitable for an initial creation of a document.
|
|
1188
1046
|
*/
|
|
1189
|
-
|
|
1190
1047
|
}, {
|
|
1191
1048
|
key: "put",
|
|
1192
1049
|
value: function put(doc, data, contentType, callback) {
|
|
1193
1050
|
var _this4 = this;
|
|
1194
|
-
|
|
1195
1051
|
var kb = this.store;
|
|
1196
1052
|
var documentString;
|
|
1197
1053
|
return Promise.resolve().then(function () {
|
|
@@ -1204,7 +1060,6 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1204
1060
|
if (!response.ok) {
|
|
1205
1061
|
return callback(doc.value, response.ok, response.error, response);
|
|
1206
1062
|
}
|
|
1207
|
-
|
|
1208
1063
|
delete kb.fetcher.nonexistent[doc.value];
|
|
1209
1064
|
delete kb.fetcher.requested[doc.value]; // @@ could this mess with the requested state machine? if a fetch is in progress
|
|
1210
1065
|
|
|
@@ -1213,12 +1068,12 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1213
1068
|
kb.addStatement(st);
|
|
1214
1069
|
});
|
|
1215
1070
|
}
|
|
1216
|
-
|
|
1217
1071
|
callback(doc.value, response.ok, '', response);
|
|
1218
1072
|
}).catch(function (err) {
|
|
1219
1073
|
callback(doc.value, false, err.message);
|
|
1220
1074
|
});
|
|
1221
1075
|
}
|
|
1076
|
+
|
|
1222
1077
|
/**
|
|
1223
1078
|
* Reloads a document.
|
|
1224
1079
|
*
|
|
@@ -1231,12 +1086,11 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1231
1086
|
* @param doc {RDFlibNamedNode}
|
|
1232
1087
|
* @param callbackFunction
|
|
1233
1088
|
*/
|
|
1234
|
-
|
|
1235
1089
|
}, {
|
|
1236
1090
|
key: "reload",
|
|
1237
1091
|
value: function reload(kb, doc, callbackFunction) {
|
|
1238
|
-
var startTime = Date.now();
|
|
1239
|
-
|
|
1092
|
+
var startTime = Date.now();
|
|
1093
|
+
// force sets no-cache and
|
|
1240
1094
|
var options = {
|
|
1241
1095
|
force: true,
|
|
1242
1096
|
noMeta: true,
|
|
@@ -1245,7 +1099,8 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1245
1099
|
kb.fetcher.nowOrWhenFetched(doc.value, options, function (ok, body, response) {
|
|
1246
1100
|
if (!ok) {
|
|
1247
1101
|
// console.log(' ERROR reloading data: ' + body)
|
|
1248
|
-
callbackFunction(false, 'Error reloading data: ' + body, response);
|
|
1102
|
+
callbackFunction(false, 'Error reloading data: ' + body, response);
|
|
1103
|
+
//@ts-ignore Where does onErrorWasCalled come from?
|
|
1249
1104
|
} else if (response.onErrorWasCalled || response.status !== 200) {
|
|
1250
1105
|
// console.log(' Non-HTTP error reloading data! onErrorWasCalled=' +
|
|
1251
1106
|
//@ts-ignore Where does onErrorWasCalled come from?
|
|
@@ -1256,7 +1111,9 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1256
1111
|
if (!doc.reloadTimeTotal) doc.reloadTimeTotal = 0;
|
|
1257
1112
|
if (!doc.reloadTimeCount) doc.reloadTimeCount = 0;
|
|
1258
1113
|
doc.reloadTimeTotal += elapsedTimeMs;
|
|
1259
|
-
doc.reloadTimeCount += 1;
|
|
1114
|
+
doc.reloadTimeCount += 1;
|
|
1115
|
+
|
|
1116
|
+
// console.log(' Fetch took ' + elapsedTimeMs + 'ms, av. of ' +
|
|
1260
1117
|
// doc.reloadTimeCount + ' = ' +
|
|
1261
1118
|
// (doc.reloadTimeTotal / doc.reloadTimeCount) + 'ms.')
|
|
1262
1119
|
|
|
@@ -1267,5 +1124,4 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
1267
1124
|
}]);
|
|
1268
1125
|
return UpdateManager;
|
|
1269
1126
|
}();
|
|
1270
|
-
|
|
1271
1127
|
exports.default = UpdateManager;
|