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