rdflib 2.2.35 → 2.2.36

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