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