rdflib 2.2.35-82f693dc → 2.2.35-b81eb5d5

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