rdflib 2.2.21 → 2.2.22-0de51c50

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