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
package/esm/fetcher.js CHANGED
@@ -6,13 +6,9 @@ import _createClass from "@babel/runtime/helpers/createClass";
6
6
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
7
7
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
8
  import _regeneratorRuntime from "@babel/runtime/regenerator";
9
-
10
9
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
11
-
12
10
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
-
14
11
  /* global $SolidTestEnvironment */
15
-
16
12
  /**
17
13
  *
18
14
  * Project: rdflib.js
@@ -62,8 +58,9 @@ var Parsable = {
62
58
  'application/xhtml+xml': true,
63
59
  'text/html': true,
64
60
  'application/ld+json': true
65
- }; // This is a minimal set to allow the use of damaged servers if necessary
61
+ };
66
62
 
63
+ // This is a minimal set to allow the use of damaged servers if necessary
67
64
  var CONTENT_TYPE_BY_EXT = {
68
65
  'rdf': RDFXMLContentType,
69
66
  'owl': RDFXMLContentType,
@@ -73,12 +70,13 @@ var CONTENT_TYPE_BY_EXT = {
73
70
  'acl': 'text/n3',
74
71
  'html': 'text/html',
75
72
  'xml': 'text/xml'
76
- }; // Convenience namespaces needed in this module.
73
+ };
74
+
75
+ // Convenience namespaces needed in this module.
77
76
  // These are deliberately not exported as the user application should
78
77
  // make its own list and not rely on the prefixes used here,
79
78
  // and not be tempted to add to them, and them clash with those of another
80
79
  // application.
81
-
82
80
  var getNS = function getNS(factory) {
83
81
  return {
84
82
  link: Namespace('http://www.w3.org/2007/ont/link#', factory),
@@ -91,69 +89,52 @@ var getNS = function getNS(factory) {
91
89
  ldp: Namespace('http://www.w3.org/ns/ldp#', factory)
92
90
  };
93
91
  };
94
-
95
92
  var ns = getNS();
93
+ var Handler = /*#__PURE__*/_createClass(
94
+ // TODO: Document, type
96
95
 
97
- var Handler = /*#__PURE__*/_createClass( // TODO: Document, type
98
96
  // TODO: Document, type
97
+
99
98
  function Handler(response, dom) {
100
99
  _classCallCheck(this, Handler);
101
-
102
100
  _defineProperty(this, "response", void 0);
103
-
104
101
  _defineProperty(this, "dom", void 0);
105
-
106
- this.response = response; // The type assertion operator here might need to be removed.
107
-
102
+ this.response = response;
103
+ // The type assertion operator here might need to be removed.
108
104
  this.dom = dom;
109
105
  });
110
-
111
106
  _defineProperty(Handler, "pattern", void 0);
112
-
113
107
  var RDFXMLHandler = /*#__PURE__*/function (_Handler) {
114
108
  _inherits(RDFXMLHandler, _Handler);
115
-
116
109
  var _super = _createSuper(RDFXMLHandler);
117
-
118
110
  function RDFXMLHandler() {
119
111
  _classCallCheck(this, RDFXMLHandler);
120
-
121
112
  return _super.apply(this, arguments);
122
113
  }
123
-
124
114
  _createClass(RDFXMLHandler, [{
125
115
  key: "parse",
126
- value: function parse(fetcher,
127
- /** An XML String */
128
- responseText,
129
- /** Requires .original */
116
+ value: function parse(fetcher, /** An XML String */
117
+ responseText, /** Requires .original */
130
118
  options) {
131
119
  var kb = fetcher.store;
132
-
133
120
  if (!this.dom) {
134
121
  this.dom = Util.parseXML(responseText);
135
122
  }
136
-
137
123
  var root = this.dom.documentElement;
138
-
139
124
  if (root.nodeName === 'parsererror') {
140
125
  // Mozilla only See issue/issue110
141
126
  // have to fail the request
142
127
  return fetcher.failFetch(options, 'Badly formed XML in ' + options.resource.value, 'parse_error');
143
128
  }
144
-
145
129
  var parser = new RDFParser(kb);
146
-
147
130
  try {
148
131
  parser.parse(this.dom, options.original.value, options.original);
149
132
  } catch (err) {
150
133
  return fetcher.failFetch(options, 'Syntax error parsing RDF/XML! ' + err, 'parse_error');
151
134
  }
152
-
153
135
  if (!options.noMeta) {
154
136
  kb.add(options.original, ns.rdf('type'), ns.link('RDFDocument'), fetcher.appNode);
155
137
  }
156
-
157
138
  return fetcher.doneFetch(options, this.response);
158
139
  }
159
140
  }], [{
@@ -169,76 +150,61 @@ var RDFXMLHandler = /*#__PURE__*/function (_Handler) {
169
150
  };
170
151
  }
171
152
  }]);
172
-
173
153
  return RDFXMLHandler;
174
154
  }(Handler);
175
-
176
155
  RDFXMLHandler.pattern = new RegExp('application/rdf\\+xml');
177
-
178
156
  var XHTMLHandler = /*#__PURE__*/function (_Handler2) {
179
157
  _inherits(XHTMLHandler, _Handler2);
180
-
181
158
  var _super2 = _createSuper(XHTMLHandler);
182
-
183
159
  function XHTMLHandler() {
184
160
  _classCallCheck(this, XHTMLHandler);
185
-
186
161
  return _super2.apply(this, arguments);
187
162
  }
188
-
189
163
  _createClass(XHTMLHandler, [{
190
164
  key: "parse",
191
165
  value: function parse(fetcher, responseText, options) {
192
166
  var relation, reverse;
193
-
194
167
  if (!this.dom) {
195
168
  this.dom = Util.parseXML(responseText);
196
169
  }
170
+ var kb = fetcher.store;
197
171
 
198
- var kb = fetcher.store; // dc:title
199
-
172
+ // dc:title
200
173
  var title = this.dom.getElementsByTagName('title');
201
-
202
174
  if (title.length > 0) {
203
- kb.add(options.resource, ns.dc('title'), kb.rdfFactory.literal(title[0].textContent), options.resource); // log.info("Inferring title of " + xhr.resource)
204
- } // link rel
205
-
175
+ kb.add(options.resource, ns.dc('title'), kb.rdfFactory.literal(title[0].textContent), options.resource);
176
+ // log.info("Inferring title of " + xhr.resource)
177
+ }
206
178
 
179
+ // link rel
207
180
  var links = this.dom.getElementsByTagName('link');
208
-
209
181
  for (var x = links.length - 1; x >= 0; x--) {
210
182
  // @@ rev
211
183
  relation = links[x].getAttribute('rel');
212
184
  reverse = false;
213
-
214
185
  if (!relation) {
215
186
  relation = links[x].getAttribute('rev');
216
187
  reverse = true;
217
188
  }
218
-
219
189
  if (relation) {
220
190
  fetcher.linkData(options.original, relation, links[x].getAttribute('href'), options.resource, reverse);
221
191
  }
222
- } // Data Islands
223
-
192
+ }
224
193
 
194
+ // Data Islands
225
195
  var scripts = this.dom.getElementsByTagName('script');
226
-
227
196
  for (var i = 0; i < scripts.length; i++) {
228
197
  var contentType = scripts[i].getAttribute('type');
229
-
230
198
  if (Parsable[contentType]) {
231
199
  // @ts-ignore incompatibility between Store.add and Formula.add
232
- rdfParse(scripts[i].textContent, kb, options.original.value, contentType); // @ts-ignore incompatibility between Store.add and Formula.add
233
-
200
+ rdfParse(scripts[i].textContent, kb, options.original.value, contentType);
201
+ // @ts-ignore incompatibility between Store.add and Formula.add
234
202
  rdfParse(scripts[i].textContent, kb, options.original.value, contentType);
235
203
  }
236
204
  }
237
-
238
205
  if (!options.noMeta) {
239
206
  kb.add(options.resource, ns.rdf('type'), ns.link('WebPage'), fetcher.appNode);
240
207
  }
241
-
242
208
  if (!options.noRDFa && parseRDFaDOM) {
243
209
  // enable by default
244
210
  try {
@@ -249,7 +215,6 @@ var XHTMLHandler = /*#__PURE__*/function (_Handler2) {
249
215
  return fetcher.failFetch(options, msg, 'parse_error');
250
216
  }
251
217
  }
252
-
253
218
  return fetcher.doneFetch(options, this.response);
254
219
  }
255
220
  }], [{
@@ -263,48 +228,42 @@ var XHTMLHandler = /*#__PURE__*/function (_Handler2) {
263
228
  fetcher.mediatypes[XHTMLContentType] = {};
264
229
  }
265
230
  }]);
266
-
267
231
  return XHTMLHandler;
268
232
  }(Handler);
269
-
270
233
  XHTMLHandler.pattern = new RegExp('application/xhtml');
271
-
272
234
  var XMLHandler = /*#__PURE__*/function (_Handler3) {
273
235
  _inherits(XMLHandler, _Handler3);
274
-
275
236
  var _super3 = _createSuper(XMLHandler);
276
-
277
237
  function XMLHandler() {
278
238
  _classCallCheck(this, XMLHandler);
279
-
280
239
  return _super3.apply(this, arguments);
281
240
  }
282
-
283
241
  _createClass(XMLHandler, [{
284
242
  key: "parse",
285
243
  value: function parse(fetcher, responseText, options) {
286
- var dom = Util.parseXML(responseText); // XML Semantics defined by root element namespace
287
- // figure out the root element
244
+ var dom = Util.parseXML(responseText);
288
245
 
246
+ // XML Semantics defined by root element namespace
247
+ // figure out the root element
289
248
  for (var c = 0; c < dom.childNodes.length; c++) {
290
- var node = dom.childNodes[c]; // is this node an element?
291
-
249
+ var node = dom.childNodes[c];
250
+ // is this node an element?
292
251
  if (XMLHandler.isElement(node)) {
293
252
  // We've found the first element, it's the root
294
- var _ns = node.namespaceURI; // Is it RDF/XML?
253
+ var _ns = node.namespaceURI;
295
254
 
255
+ // Is it RDF/XML?
296
256
  if (_ns && _ns === _ns['rdf']) {
297
257
  fetcher.addStatus(options.req, 'Has XML root element in the RDF namespace, so assume RDF/XML.');
298
258
  var rdfHandler = new RDFXMLHandler(this.response, dom);
299
259
  return rdfHandler.parse(fetcher, responseText, options);
300
260
  }
301
-
302
261
  break;
303
262
  }
304
- } // Or it could be XHTML?
305
- // Maybe it has an XHTML DOCTYPE?
306
-
263
+ }
307
264
 
265
+ // Or it could be XHTML?
266
+ // Maybe it has an XHTML DOCTYPE?
308
267
  if (dom.doctype) {
309
268
  // log.info("We found a DOCTYPE in " + xhr.resource)
310
269
  if (dom.doctype.name === 'html' && dom.doctype.publicId.match(/^-\/\/W3C\/\/DTD XHTML/) && dom.doctype.systemId.match(/http:\/\/www.w3.org\/TR\/xhtml/)) {
@@ -312,28 +271,24 @@ var XMLHandler = /*#__PURE__*/function (_Handler3) {
312
271
  var xhtmlHandler = new XHTMLHandler(this.response, dom);
313
272
  return xhtmlHandler.parse(fetcher, responseText, options);
314
273
  }
315
- } // Or what about an XHTML namespace?
316
-
274
+ }
317
275
 
276
+ // Or what about an XHTML namespace?
318
277
  var html = dom.getElementsByTagName('html')[0];
319
-
320
278
  if (html) {
321
279
  var xmlns = html.getAttribute('xmlns');
322
-
323
280
  if (xmlns && xmlns.match(/^http:\/\/www.w3.org\/1999\/xhtml/)) {
324
281
  fetcher.addStatus(options.req, 'Has a default namespace for ' + 'XHTML. Switching to XHTMLHandler.\n');
325
-
326
282
  var _xhtmlHandler = new XHTMLHandler(this.response, dom);
327
-
328
283
  return _xhtmlHandler.parse(fetcher, responseText, options);
329
284
  }
330
- } // At this point we should check the namespace document (cache it!) and
285
+ }
286
+
287
+ // At this point we should check the namespace document (cache it!) and
331
288
  // look for a GRDDL transform
332
289
  // @@ Get namespace document <n>, parse it, look for <n> grddl:namespaceTransform ?y
333
290
  // Apply ?y to dom
334
291
  // We give up. What dialect is this?
335
-
336
-
337
292
  return fetcher.failFetch(options, 'Unsupported dialect of XML: not RDF or XHTML namespace, etc.\n' + responseText.slice(0, 80), 901);
338
293
  }
339
294
  }], [{
@@ -357,57 +312,46 @@ var XMLHandler = /*#__PURE__*/function (_Handler3) {
357
312
  return node.nodeType === Node.ELEMENT_NODE;
358
313
  }
359
314
  }]);
360
-
361
315
  return XMLHandler;
362
316
  }(Handler);
363
-
364
317
  XMLHandler.pattern = new RegExp('(text|application)/(.*)xml');
365
-
366
318
  var HTMLHandler = /*#__PURE__*/function (_Handler4) {
367
319
  _inherits(HTMLHandler, _Handler4);
368
-
369
320
  var _super4 = _createSuper(HTMLHandler);
370
-
371
321
  function HTMLHandler() {
372
322
  _classCallCheck(this, HTMLHandler);
373
-
374
323
  return _super4.apply(this, arguments);
375
324
  }
376
-
377
325
  _createClass(HTMLHandler, [{
378
326
  key: "parse",
379
327
  value: function parse(fetcher, responseText, options) {
380
- var kb = fetcher.store; // We only handle XHTML so we have to figure out if this is XML
381
- // log.info("Sniffing HTML " + xhr.resource + " for XHTML.")
328
+ var kb = fetcher.store;
382
329
 
330
+ // We only handle XHTML so we have to figure out if this is XML
331
+ // log.info("Sniffing HTML " + xhr.resource + " for XHTML.")
383
332
  if (isXML(responseText)) {
384
333
  fetcher.addStatus(options.req, "Has an XML declaration. We'll assume " + "it's XHTML as the content-type was text/html.\n");
385
334
  var xhtmlHandler = new XHTMLHandler(this.response);
386
335
  return xhtmlHandler.parse(fetcher, responseText, options);
387
- } // DOCTYPE html
388
-
336
+ }
389
337
 
338
+ // DOCTYPE html
390
339
  if (isXHTML(responseText)) {
391
340
  fetcher.addStatus(options.req, 'Has XHTML DOCTYPE. Switching to XHTMLHandler.\n');
392
-
393
341
  var _xhtmlHandler2 = new XHTMLHandler(this.response);
394
-
395
342
  return _xhtmlHandler2.parse(fetcher, responseText, options);
396
- } // xmlns
397
-
343
+ }
398
344
 
345
+ // xmlns
399
346
  if (isXMLNS(responseText)) {
400
347
  fetcher.addStatus(options.req, 'Has default namespace for XHTML, so switching to XHTMLHandler.\n');
401
-
402
348
  var _xhtmlHandler3 = new XHTMLHandler(this.response);
403
-
404
349
  return _xhtmlHandler3.parse(fetcher, responseText, options);
405
- } // dc:title
406
- // no need to escape '/' here
407
-
350
+ }
408
351
 
352
+ // dc:title
353
+ // no need to escape '/' here
409
354
  var titleMatch = new RegExp('<title>([\\s\\S]+?)</title>', 'im').exec(responseText);
410
-
411
355
  if (titleMatch) {
412
356
  kb.add(options.resource, ns.dc('title'), kb.rdfFactory.literal(titleMatch[1]), options.resource); // think about xml:lang later
413
357
  }
@@ -429,23 +373,16 @@ var HTMLHandler = /*#__PURE__*/function (_Handler4) {
429
373
  };
430
374
  }
431
375
  }]);
432
-
433
376
  return HTMLHandler;
434
377
  }(Handler);
435
-
436
378
  HTMLHandler.pattern = new RegExp('text/html');
437
-
438
379
  var JsonLdHandler = /*#__PURE__*/function (_Handler5) {
439
380
  _inherits(JsonLdHandler, _Handler5);
440
-
441
381
  var _super5 = _createSuper(JsonLdHandler);
442
-
443
382
  function JsonLdHandler() {
444
383
  _classCallCheck(this, JsonLdHandler);
445
-
446
384
  return _super5.apply(this, arguments);
447
385
  }
448
-
449
386
  _createClass(JsonLdHandler, [{
450
387
  key: "parse",
451
388
  value: function parse(fetcher, responseText, options, response) {
@@ -457,7 +394,6 @@ var JsonLdHandler = /*#__PURE__*/function (_Handler5) {
457
394
  });
458
395
  } catch (err) {
459
396
  var msg = 'Error trying to parse ' + options.resource + ' as JSON-LD:\n' + err; // not err.stack -- irrelevant
460
-
461
397
  resolve(fetcher.failFetch(options, msg, 'parse_error', response));
462
398
  }
463
399
  });
@@ -475,44 +411,36 @@ var JsonLdHandler = /*#__PURE__*/function (_Handler5) {
475
411
  };
476
412
  }
477
413
  }]);
478
-
479
414
  return JsonLdHandler;
480
415
  }(Handler);
481
-
482
416
  JsonLdHandler.pattern = /application\/ld\+json/;
483
-
484
417
  var TextHandler = /*#__PURE__*/function (_Handler6) {
485
418
  _inherits(TextHandler, _Handler6);
486
-
487
419
  var _super6 = _createSuper(TextHandler);
488
-
489
420
  function TextHandler() {
490
421
  _classCallCheck(this, TextHandler);
491
-
492
422
  return _super6.apply(this, arguments);
493
423
  }
494
-
495
424
  _createClass(TextHandler, [{
496
425
  key: "parse",
497
426
  value: function parse(fetcher, responseText, options) {
498
427
  // We only speak dialects of XML right now. Is this XML?
428
+
499
429
  // Look for an XML declaration
500
430
  if (isXML(responseText)) {
501
431
  fetcher.addStatus(options.req, 'Warning: ' + options.resource + " has an XML declaration. We'll assume " + "it's XML but its content-type wasn't XML.\n");
502
432
  var xmlHandler = new XMLHandler(this.response);
503
433
  return xmlHandler.parse(fetcher, responseText, options);
504
- } // Look for an XML declaration
505
-
434
+ }
506
435
 
436
+ // Look for an XML declaration
507
437
  if (responseText.slice(0, 500).match(/xmlns:/)) {
508
438
  fetcher.addStatus(options.req, "May have an XML namespace. We'll assume " + "it's XML but its content-type wasn't XML.\n");
509
-
510
439
  var _xmlHandler = new XMLHandler(this.response);
511
-
512
440
  return _xmlHandler.parse(fetcher, responseText, options);
513
- } // We give up finding semantics - this is not an error, just no data
514
-
441
+ }
515
442
 
443
+ // We give up finding semantics - this is not an error, just no data
516
444
  fetcher.addStatus(options.req, 'Plain text document, no known RDF semantics.');
517
445
  return fetcher.doneFetch(options, this.response);
518
446
  }
@@ -529,38 +457,29 @@ var TextHandler = /*#__PURE__*/function (_Handler6) {
529
457
  };
530
458
  }
531
459
  }]);
532
-
533
460
  return TextHandler;
534
461
  }(Handler);
535
-
536
462
  TextHandler.pattern = new RegExp('text/plain');
537
-
538
463
  var N3Handler = /*#__PURE__*/function (_Handler7) {
539
464
  _inherits(N3Handler, _Handler7);
540
-
541
465
  var _super7 = _createSuper(N3Handler);
542
-
543
466
  function N3Handler() {
544
467
  _classCallCheck(this, N3Handler);
545
-
546
468
  return _super7.apply(this, arguments);
547
469
  }
548
-
549
470
  _createClass(N3Handler, [{
550
471
  key: "parse",
551
472
  value: function parse(fetcher, responseText, options, response) {
552
473
  // Parse the text of this N3 file
553
474
  var kb = fetcher.store;
554
- var p = N3Parser(kb, kb, options.original.value, options.original.value, null, null, '', null); // p.loadBuf(xhr.responseText)
555
-
475
+ var p = N3Parser(kb, kb, options.original.value, options.original.value, null, null, '', null);
476
+ // p.loadBuf(xhr.responseText)
556
477
  try {
557
478
  p.loadBuf(responseText);
558
479
  } catch (err) {
559
480
  var msg = 'Error trying to parse ' + options.resource + ' as Notation3:\n' + err; // not err.stack -- irrelevant
560
-
561
481
  return fetcher.failFetch(options, msg, 'parse_error', response);
562
482
  }
563
-
564
483
  fetcher.addStatus(options.req, 'N3 parsed: ' + p.statementCount + ' triples in ' + p.lines + ' lines.');
565
484
  fetcher.store.add(options.original, ns.rdf('type'), ns.link('RDFDocument'), fetcher.appNode);
566
485
  return fetcher.doneFetch(options, this.response);
@@ -576,22 +495,18 @@ var N3Handler = /*#__PURE__*/function (_Handler7) {
576
495
  fetcher.mediatypes['text/n3'] = {
577
496
  'q': '1.0'
578
497
  }; // as per 2008 spec
579
-
580
498
  /*
581
499
  fetcher.mediatypes['application/x-turtle'] = {
582
500
  'q': 1.0
583
501
  } // pre 2008
584
502
  */
585
-
586
503
  fetcher.mediatypes['text/turtle'] = {
587
504
  'q': 1.0
588
505
  }; // post 2008
589
506
  }
590
507
  }]);
591
-
592
508
  return N3Handler;
593
509
  }(Handler);
594
-
595
510
  N3Handler.pattern = new RegExp('(application|text)/(x-)?(rdf\\+)?(n3|turtle)');
596
511
  var defaultHandlers = {
597
512
  RDFXMLHandler: RDFXMLHandler,
@@ -602,28 +517,22 @@ var defaultHandlers = {
602
517
  N3Handler: N3Handler,
603
518
  JsonLdHandler: JsonLdHandler
604
519
  };
605
-
606
520
  function isXHTML(responseText) {
607
521
  var docTypeStart = responseText.indexOf('<!DOCTYPE html');
608
522
  var docTypeEnd = responseText.indexOf('>');
609
-
610
523
  if (docTypeStart === -1 || docTypeEnd === -1 || docTypeStart > docTypeEnd) {
611
524
  return false;
612
525
  }
613
-
614
526
  return responseText.substr(docTypeStart, docTypeEnd - docTypeStart).indexOf('XHTML') !== -1;
615
527
  }
616
-
617
528
  function isXML(responseText) {
618
529
  var match = responseText.match(/\s*<\?xml\s+version\s*=[^<>]+\?>/);
619
530
  return !!match;
620
531
  }
621
-
622
532
  function isXMLNS(responseText) {
623
533
  var match = responseText.match(/[^(<html)]*<html\s+[^<]*xmlns=['"]http:\/\/www.w3.org\/1999\/xhtml["'][^<]*>/);
624
534
  return !!match;
625
535
  }
626
-
627
536
  /** Fetcher
628
537
  *
629
538
  * The Fetcher object is a helper object for a quadstore
@@ -656,59 +565,41 @@ var Fetcher = /*#__PURE__*/function () {
656
565
  /** fetchCallbacks[uri].push(callback) */
657
566
 
658
567
  /** Keep track of explicit 404s -> we can overwrite etc */
568
+
659
569
  // TODO: Document this
660
570
 
661
571
  /** Methods added by calling Util.callbackify in the constructor*/
572
+
662
573
  function Fetcher(store) {
663
574
  var _this = this;
664
-
665
575
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
666
-
667
576
  _classCallCheck(this, Fetcher);
668
-
669
577
  _defineProperty(this, "store", void 0);
670
-
671
578
  _defineProperty(this, "timeout", void 0);
672
-
673
579
  _defineProperty(this, "_fetch", void 0);
674
-
675
580
  _defineProperty(this, "mediatypes", void 0);
676
-
677
581
  _defineProperty(this, "appNode", void 0);
678
-
679
582
  _defineProperty(this, "requested", void 0);
680
-
681
583
  _defineProperty(this, "timeouts", void 0);
682
-
683
584
  _defineProperty(this, "redirectedTo", void 0);
684
-
685
585
  _defineProperty(this, "fetchQueue", void 0);
686
-
687
586
  _defineProperty(this, "fetchCallbacks", void 0);
688
-
689
587
  _defineProperty(this, "nonexistent", void 0);
690
-
691
588
  _defineProperty(this, "lookedUp", void 0);
692
-
693
589
  _defineProperty(this, "handlers", void 0);
694
-
695
590
  _defineProperty(this, "ns", void 0);
696
-
697
591
  _defineProperty(this, "fireCallbacks", void 0);
698
-
699
592
  this.store = store || new IndexedFormula();
700
593
  this.ns = getNS(this.store.rdfFactory);
701
- this.timeout = options.timeout || 30000; // solidFetcher is deprecated
594
+ this.timeout = options.timeout || 30000;
702
595
 
596
+ // solidFetcher is deprecated
703
597
  this._fetch = options.fetch || typeof global !== 'undefined' && (global.solidFetcher || global.solidFetch) || typeof window !== 'undefined' && (window.solidFetcher || window.solidFetch) || crossFetch;
704
-
705
598
  if (!this._fetch) {
706
599
  throw new Error('No _fetch function available for Fetcher');
707
600
  }
708
-
709
601
  this.appNode = this.store.rdfFactory.blankNode();
710
602
  this.store.fetcher = this; // Bi-linked
711
-
712
603
  this.requested = {};
713
604
  this.timeouts = {};
714
605
  this.redirectedTo = {};
@@ -724,17 +615,16 @@ var Fetcher = /*#__PURE__*/function () {
724
615
  '*/*': {
725
616
  'q': 0.1
726
617
  } // Must allow access to random content
618
+ };
727
619
 
728
- }; // Util.callbackify(this, ['request', 'recv', 'headers', 'load', 'fail',
620
+ // Util.callbackify(this, ['request', 'recv', 'headers', 'load', 'fail',
729
621
  // 'refresh', 'retract', 'done'])
730
622
  // In switching to fetch(), 'recv', 'headers' and 'load' do not make sense
731
-
732
623
  Util.callbackify(this, ['request', 'fail', 'refresh', 'retract', 'done']);
733
624
  Object.keys(options.handlers || defaultHandlers).map(function (key) {
734
625
  return _this.addHandler(defaultHandlers[key]);
735
626
  });
736
627
  }
737
-
738
628
  _createClass(Fetcher, [{
739
629
  key: "load",
740
630
  value:
@@ -785,16 +675,13 @@ var Fetcher = /*#__PURE__*/function () {
785
675
  */
786
676
  function load(uri) {
787
677
  var _this2 = this;
788
-
789
678
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
790
679
  options = Object.assign({}, options); // Take a copy as we add stuff to the options!!
791
-
792
680
  if (uri instanceof Array) {
793
681
  return Promise.all(uri.map(function (x) {
794
682
  return _this2.load(x, Object.assign({}, options));
795
683
  }));
796
684
  }
797
-
798
685
  var uriIn = uri;
799
686
  var docuri = termValue(uriIn);
800
687
  docuri = docuri.split('#')[0];
@@ -804,43 +691,65 @@ var Fetcher = /*#__PURE__*/function () {
804
691
  }
805
692
  }, {
806
693
  key: "pendingFetchPromise",
807
- value: function pendingFetchPromise(uri, originalUri, options) {
808
- var _this3 = this;
809
-
810
- var pendingPromise; // Check to see if some request is already dealing with this uri
811
-
812
- if (!options.force && this.fetchQueue[originalUri]) {
813
- pendingPromise = this.fetchQueue[originalUri];
814
- } else {
815
- pendingPromise = Promise.race([this.setRequestTimeout(uri, options), this.fetchUri(uri, options)]);
816
- this.fetchQueue[originalUri] = pendingPromise; // Clean up the queued promise after a time, if it's resolved
817
-
818
- this.cleanupFetchRequest(originalUri, undefined, this.timeout);
694
+ value: function () {
695
+ var _pendingFetchPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(uri, originalUri, options) {
696
+ var _this3 = this;
697
+ var pendingPromise;
698
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
699
+ while (1) switch (_context.prev = _context.next) {
700
+ case 0:
701
+ _context.t0 = !options.force;
702
+ if (!_context.t0) {
703
+ _context.next = 5;
704
+ break;
705
+ }
706
+ _context.next = 4;
707
+ return this.fetchQueue[originalUri];
708
+ case 4:
709
+ _context.t0 = _context.sent;
710
+ case 5:
711
+ if (!_context.t0) {
712
+ _context.next = 9;
713
+ break;
714
+ }
715
+ pendingPromise = this.fetchQueue[originalUri];
716
+ _context.next = 12;
717
+ break;
718
+ case 9:
719
+ pendingPromise = Promise.race([this.setRequestTimeout(uri, options), this.fetchUri(uri, options)]);
720
+ this.fetchQueue[originalUri] = pendingPromise;
721
+
722
+ // Clean up the queued promise after a time, if it's resolved
723
+ this.cleanupFetchRequest(originalUri, undefined, this.timeout);
724
+ case 12:
725
+ return _context.abrupt("return", pendingPromise.then(function (x) {
726
+ if (uri in _this3.timeouts) {
727
+ _this3.timeouts[uri].forEach(clearTimeout);
728
+ delete _this3.timeouts[uri];
729
+ }
730
+ return x;
731
+ }));
732
+ case 13:
733
+ case "end":
734
+ return _context.stop();
735
+ }
736
+ }, _callee, this);
737
+ }));
738
+ function pendingFetchPromise(_x, _x2, _x3) {
739
+ return _pendingFetchPromise.apply(this, arguments);
819
740
  }
820
-
821
- return pendingPromise.then(function (x) {
822
- if (uri in _this3.timeouts) {
823
- _this3.timeouts[uri].forEach(clearTimeout);
824
-
825
- delete _this3.timeouts[uri];
826
- }
827
-
828
- return x;
829
- });
830
- }
741
+ return pendingFetchPromise;
742
+ }()
831
743
  /**
832
744
  * @param _options - DEPRECATED
833
745
  */
834
-
835
746
  }, {
836
747
  key: "cleanupFetchRequest",
837
748
  value: function cleanupFetchRequest(originalUri, _options, timeout) {
838
749
  var _this4 = this;
839
-
840
750
  if (_options !== undefined) {
841
751
  console.warn("_options is deprecated");
842
752
  }
843
-
844
753
  this.timeouts[originalUri] = (this.timeouts[originalUri] || []).concat(setTimeout(function () {
845
754
  if (!_this4.isPending(originalUri)) {
846
755
  delete _this4.fetchQueue[originalUri];
@@ -852,43 +761,35 @@ var Fetcher = /*#__PURE__*/function () {
852
761
  value: function initFetchOptions(uri, options) {
853
762
  var kb = this.store;
854
763
  var isGet = !options.method || options.method.toUpperCase() === 'GET';
855
-
856
764
  if (!isGet) {
857
765
  options.force = true;
858
766
  }
859
-
860
767
  options.resource = kb.rdfFactory.namedNode(uri); // This might be proxified
861
-
862
768
  options.baseURI = options.baseURI || uri; // Preserve though proxying etc
863
-
864
769
  options.original = kb.rdfFactory.namedNode(options.baseURI);
865
770
  options.req = kb.bnode();
866
771
  options.headers = options.headers || new Headers();
867
-
868
772
  if (options.contentType) {
869
773
  // @ts-ignore
870
774
  options.headers['content-type'] = options.contentType;
871
775
  }
872
-
873
776
  if (options.force) {
874
777
  options.cache = 'no-cache';
875
778
  }
876
-
877
- var acceptString = this.acceptString(); // @ts-ignore
878
-
779
+ var acceptString = this.acceptString();
780
+ // @ts-ignore
879
781
  options.headers['accept'] = acceptString;
880
782
  var requestedURI = Fetcher.offlineOverride(uri);
881
783
  options.requestedURI = requestedURI;
882
784
  Fetcher.setCredentials(requestedURI, options);
883
785
  var actualProxyURI = Fetcher.proxyIfNecessary(requestedURI);
884
-
885
786
  if (requestedURI !== actualProxyURI) {
886
787
  options.proxyUsed = true;
887
788
  }
888
-
889
789
  options.actualProxyURI = actualProxyURI;
890
790
  return options;
891
791
  }
792
+
892
793
  /**
893
794
  * (The promise chain ends in either a `failFetch()` or a `doneFetch()`)
894
795
  *
@@ -897,38 +798,32 @@ var Fetcher = /*#__PURE__*/function () {
897
798
  *
898
799
  * @returns {Promise<Object>} fetch() result or an { error, status } object
899
800
  */
900
-
901
801
  }, {
902
802
  key: "fetchUri",
903
803
  value: function fetchUri(docuri, options) {
904
804
  var _this5 = this;
905
-
906
805
  if (!docuri) {
907
806
  return Promise.reject(new Error('Cannot fetch an empty uri'));
908
807
  }
909
-
910
808
  if (Fetcher.unsupportedProtocol(docuri)) {
911
809
  return this.failFetch(options, 'fetcher: Unsupported protocol', 'unsupported_protocol');
912
810
  }
913
-
914
811
  var state = this.getState(docuri);
915
-
916
812
  if (!options.force) {
917
813
  if (state === 'fetched') {
918
814
  // URI already fetched and added to store
919
- return Promise.resolve( // @ts-ignore This is not a valid response object
815
+ return Promise.resolve(
816
+ // @ts-ignore This is not a valid response object
920
817
  this.doneFetch(options, {
921
818
  status: 200,
922
819
  ok: true,
923
820
  statusText: 'Already loaded into quadstore.'
924
821
  }));
925
822
  }
926
-
927
823
  if (state === 'failed' && this.requested[docuri] === 404) {
928
824
  // Remember nonexistence
929
- var _message = 'Previously failed: ' + this.requested[docuri]; // @ts-ignore This is not a valid response object
930
-
931
-
825
+ var _message = 'Previously failed: ' + this.requested[docuri];
826
+ // @ts-ignore This is not a valid response object
932
827
  var dummyResponse = {
933
828
  url: docuri,
934
829
  // This does not comply to Fetch spec, it can be a string value in rdflib
@@ -949,17 +844,16 @@ var Fetcher = /*#__PURE__*/function () {
949
844
  // options.force == true
950
845
  delete this.nonexistent[docuri];
951
846
  }
952
-
953
847
  this.fireCallbacks('request', [docuri]);
954
848
  this.requested[docuri] = true; // mark this uri as 'requested'
955
849
 
956
850
  if (!options.noMeta) {
957
851
  this.saveRequestMetadata(docuri, options);
958
852
  }
853
+ var actualProxyURI = options.actualProxyURI;
959
854
 
960
- var actualProxyURI = options.actualProxyURI; // Map might get mistakenly added into headers
855
+ // Map might get mistakenly added into headers
961
856
  // error TS2339: Property 'map' does not exist on type 'Headers'.
962
-
963
857
  /* let map
964
858
  if (options.headers && map in options.headers) {
965
859
  delete options.headers.map
@@ -987,13 +881,14 @@ var Fetcher = /*#__PURE__*/function () {
987
881
  console.log('Fetcher: <' + actualProxyURI + '> Non-HTTP fetch exception: ' + error);
988
882
  return _this5.handleError(dummyResponse, docuri, options); // possible credentials retry
989
883
  // return this.failFetch(options, 'fetch failed: ' + error, 999, dummyResponse) // Fake status code: fetch exception
990
- // handleError expects a response so we fake some important bits.
991
884
 
885
+ // handleError expects a response so we fake some important bits.
992
886
  /*
993
887
  this.handleError(, docuri, options)
994
888
  */
995
889
  });
996
890
  }
891
+
997
892
  /**
998
893
  * Asks for a doc to be loaded if necessary then calls back
999
894
  *
@@ -1021,13 +916,11 @@ var Fetcher = /*#__PURE__*/function () {
1021
916
  * response The fetch Response object (was: XHR) if there was was one
1022
917
  * includes response.status as the HTTP status if any.
1023
918
  */
1024
-
1025
919
  }, {
1026
920
  key: "nowOrWhenFetched",
1027
921
  value: function nowOrWhenFetched(uriIn, p2, userCallback) {
1028
922
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1029
923
  var uri = termValue(uriIn);
1030
-
1031
924
  if (typeof p2 === 'function') {
1032
925
  // nowOrWhenFetched (uri, userCallback)
1033
926
  userCallback = p2;
@@ -1040,7 +933,6 @@ var Fetcher = /*#__PURE__*/function () {
1040
933
  // nowOrWhenFetched (uri, options, userCallback)
1041
934
  options = p2;
1042
935
  }
1043
-
1044
936
  this.load(uri, options).then(function (fetchResponse) {
1045
937
  if (userCallback) {
1046
938
  if (fetchResponse) {
@@ -1049,7 +941,6 @@ var Fetcher = /*#__PURE__*/function () {
1049
941
  } else {
1050
942
  // console.log('@@@ fetcher.js Should not take this path !!!!!!!!!!!!')
1051
943
  var oops = 'HTTP error: Status ' + fetchResponse.status + ' (' + fetchResponse.statusText + ')';
1052
-
1053
944
  if (fetchResponse.responseText) {
1054
945
  oops += ' ' + fetchResponse.responseText; // not in 404, dns error, nock failure
1055
946
  }
@@ -1067,36 +958,34 @@ var Fetcher = /*#__PURE__*/function () {
1067
958
  var message = err.message || err.statusText;
1068
959
  message = 'Failed to load <' + uri + '> ' + message;
1069
960
  console.log(message);
1070
-
1071
961
  if (err.response && err.response.status) {
1072
962
  message += ' status: ' + err.response.status;
1073
963
  }
1074
-
1075
964
  userCallback(false, message, err.response);
1076
965
  });
1077
966
  }
967
+
1078
968
  /**
1079
969
  * Records a status message (as a literal node) by appending it to the
1080
970
  * request's metadata status collection.
1081
971
  *
1082
972
  */
1083
-
1084
973
  }, {
1085
974
  key: "addStatus",
1086
975
  value: function addStatus(req, statusMessage) {
1087
976
  // <Debug about="parsePerformance">
1088
977
  var now = new Date();
1089
- statusMessage = '[' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() + '.' + now.getMilliseconds() + '] ' + statusMessage; // </Debug>
1090
-
978
+ statusMessage = '[' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() + '.' + now.getMilliseconds() + '] ' + statusMessage;
979
+ // </Debug>
1091
980
  var kb = this.store;
1092
981
  var statusNode = kb.the(req, this.ns.link('status'));
1093
-
1094
982
  if (isCollection(statusNode)) {
1095
983
  statusNode.append(kb.rdfFactory.literal(statusMessage));
1096
984
  } else {
1097
985
  log.warn('web.js: No list to add to: ' + statusNode + ',' + statusMessage);
1098
986
  }
1099
987
  }
988
+
1100
989
  /**
1101
990
  * Records errors in the system on failure:
1102
991
  *
@@ -1105,52 +994,48 @@ var Fetcher = /*#__PURE__*/function () {
1105
994
  * - Fires the 'fail' callback
1106
995
  * - Rejects with an error result object, which has a response object if any
1107
996
  */
1108
-
1109
997
  }, {
1110
998
  key: "failFetch",
1111
999
  value: function failFetch(options, errorMessage, statusCode, response) {
1112
1000
  this.addStatus(options.req, errorMessage);
1113
-
1114
1001
  if (!options.noMeta) {
1115
1002
  this.store.add(options.original, this.ns.link('error'), this.store.rdfFactory.literal(errorMessage));
1116
1003
  }
1117
-
1118
1004
  var meth = (options.method || 'GET').toUpperCase();
1119
1005
  var isGet = meth === 'GET' || meth === 'HEAD';
1120
-
1121
1006
  if (isGet) {
1122
1007
  // only cache the status code on GET or HEAD
1123
- if (!options.resource.equals(options.original)) {// console.log('@@ Recording failure ' + meth + ' original ' + options.original +option '( as ' + options.resource + ') : ' + statusCode)
1124
- } else {// console.log('@@ Recording ' + meth + ' failure for ' + options.original + ': ' + statusCode)
1008
+ if (!options.resource.equals(options.original)) {
1009
+ // console.log('@@ Recording failure ' + meth + ' original ' + options.original +option '( as ' + options.resource + ') : ' + statusCode)
1010
+ } else {
1011
+ // console.log('@@ Recording ' + meth + ' failure for ' + options.original + ': ' + statusCode)
1125
1012
  }
1126
-
1127
1013
  this.requested[Uri.docpart(options.original.value)] = statusCode;
1128
1014
  this.fireCallbacks('fail', [options.original.value, errorMessage]);
1129
1015
  }
1016
+ var err = new Error('Fetcher: ' + errorMessage);
1130
1017
 
1131
- var err = new Error('Fetcher: ' + errorMessage); // err.ok = false // Is taken as a response, will work too @@ phase out?
1132
-
1018
+ // err.ok = false // Is taken as a response, will work too @@ phase out?
1133
1019
  err.status = statusCode;
1134
1020
  err.statusText = errorMessage;
1135
1021
  err.response = response;
1136
1022
  return Promise.reject(err);
1137
- } // in the why part of the quad distinguish between HTML and HTTP header
1138
- // Reverse is set iif the link was rev= as opposed to rel=
1023
+ }
1139
1024
 
1025
+ // in the why part of the quad distinguish between HTML and HTTP header
1026
+ // Reverse is set iif the link was rev= as opposed to rel=
1140
1027
  }, {
1141
1028
  key: "linkData",
1142
1029
  value: function linkData(originalUri, rel, uri, why, reverse) {
1143
1030
  if (!uri) return;
1144
1031
  var kb = this.store;
1145
- var predicate; // See http://www.w3.org/TR/powder-dr/#httplink for describedby 2008-12-10
1146
-
1032
+ var predicate;
1033
+ // See http://www.w3.org/TR/powder-dr/#httplink for describedby 2008-12-10
1147
1034
  var obj = kb.rdfFactory.namedNode(Uri.join(uri, originalUri.value));
1148
-
1149
1035
  if (rel === 'alternate' || rel === 'seeAlso' || rel === 'meta' || rel === 'describedby') {
1150
1036
  if (obj.value === originalUri.value) {
1151
1037
  return;
1152
1038
  }
1153
-
1154
1039
  predicate = this.ns.rdfs('seeAlso');
1155
1040
  } else if (rel === 'type') {
1156
1041
  predicate = kb.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type');
@@ -1160,7 +1045,6 @@ var Fetcher = /*#__PURE__*/function () {
1160
1045
  // encode space in e.g. rel="shortcut icon"
1161
1046
  predicate = kb.rdfFactory.namedNode(Uri.join(encodeURIComponent(rel), 'http://www.iana.org/assignments/link-relations/'));
1162
1047
  }
1163
-
1164
1048
  if (reverse) {
1165
1049
  kb.add(obj, predicate, originalUri, why);
1166
1050
  } else {
@@ -1172,32 +1056,30 @@ var Fetcher = /*#__PURE__*/function () {
1172
1056
  value: function parseLinkHeader(linkHeader, originalUri, reqNode) {
1173
1057
  if (!linkHeader) {
1174
1058
  return;
1175
- } // const linkexp = /<[^>]*>\s*(\s*;\s*[^()<>@,;:"/[\]?={} \t]+=(([^()<>@,;:"/[]?={} \t]+)|("[^"]*")))*(,|$)/g
1059
+ }
1060
+
1061
+ // const linkexp = /<[^>]*>\s*(\s*;\s*[^()<>@,;:"/[\]?={} \t]+=(([^()<>@,;:"/[]?={} \t]+)|("[^"]*")))*(,|$)/g
1176
1062
  // const paramexp = /[^()<>@,;:"/[]?={} \t]+=(([^()<>@,;:"/[]?={} \t]+)|("[^"]*"))/g
1063
+
1177
1064
  // From https://www.dcode.fr/regular-expression-simplificator:
1178
1065
  // const linkexp = /<[^>]*>\s*(\s*;\s*[^()<>@,;:"/[\]?={} t]+=["]))*[,$]/g
1179
1066
  // const paramexp = /[^\\<>@,;:"\/\[\]?={} \t]+=["])/g
1180
1067
  // Original:
1181
-
1182
-
1183
1068
  var linkexp = /<[^>]*>\s*(\s*;\s*[^()<>@,;:"/[\]?={} \t]+=(([^\(\)<>@,;:"\/\[\]\?={} \t]+)|("[^"]*")))*(,|$)/g;
1184
1069
  var paramexp = /[^\(\)<>@,;:"\/\[\]\?={} \t]+=(([^\(\)<>@,;:"\/\[\]\?={} \t]+)|("[^"]*"))/g;
1185
1070
  var matches = linkHeader.match(linkexp);
1186
1071
  if (matches == null) return;
1187
-
1188
1072
  for (var i = 0; i < matches.length; i++) {
1189
1073
  var split = matches[i].split('>');
1190
1074
  var href = split[0].substring(1);
1191
1075
  var ps = split[1];
1192
1076
  var s = ps.match(paramexp);
1193
1077
  if (s == null) return;
1194
-
1195
1078
  for (var j = 0; j < s.length; j++) {
1196
1079
  var p = s[j];
1197
- var paramsplit = p.split('='); // var name = paramsplit[0]
1198
-
1080
+ var paramsplit = p.split('=');
1081
+ // var name = paramsplit[0]
1199
1082
  var rel = paramsplit[1].replace(/["']/g, ''); // '"
1200
-
1201
1083
  this.linkData(originalUri, rel, href, reqNode);
1202
1084
  }
1203
1085
  }
@@ -1212,12 +1094,12 @@ var Fetcher = /*#__PURE__*/function () {
1212
1094
 
1213
1095
  return response;
1214
1096
  }
1097
+
1215
1098
  /**
1216
1099
  * Note two nodes are now smushed
1217
1100
  * If only one was flagged as looked up, then the new node is looked up again,
1218
1101
  * which will make sure all the URIs are dereferenced
1219
1102
  */
1220
-
1221
1103
  }, {
1222
1104
  key: "nowKnownAs",
1223
1105
  value: function nowKnownAs(was, now) {
@@ -1232,21 +1114,18 @@ var Fetcher = /*#__PURE__*/function () {
1232
1114
  }
1233
1115
  }
1234
1116
  }
1117
+
1235
1118
  /**
1236
1119
  * Writes back to the web what we have in the store for this uri
1237
1120
  */
1238
-
1239
1121
  }, {
1240
1122
  key: "putBack",
1241
1123
  value: function putBack(uri) {
1242
1124
  var _this6 = this;
1243
-
1244
1125
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1245
1126
  var uriSting = termValue(uri);
1246
1127
  var doc = new RDFlibNamedNode(uriSting).doc(); // strip off #
1247
-
1248
1128
  options.contentType = options["content-type"] || options["Content-Type"] || options.contentType || TurtleContentType;
1249
-
1250
1129
  if (options.contentType === 'application/ld+json') {
1251
1130
  return new Promise(function (resolve, reject) {
1252
1131
  serialize(doc, _this6.store, doc.uri, options.contentType, function (err, jsonString) {
@@ -1255,7 +1134,6 @@ var Fetcher = /*#__PURE__*/function () {
1255
1134
  } else {
1256
1135
  // @ts-ignore
1257
1136
  options.data = jsonString;
1258
-
1259
1137
  _this6.webOperation('PUT', uri, options).then(function (res) {
1260
1138
  return resolve(res);
1261
1139
  }).catch(function (error) {
@@ -1265,7 +1143,6 @@ var Fetcher = /*#__PURE__*/function () {
1265
1143
  });
1266
1144
  });
1267
1145
  }
1268
-
1269
1146
  options.data = serialize(doc, this.store, doc.value, options.contentType);
1270
1147
  return this.webOperation('PUT', uriSting, options);
1271
1148
  }
@@ -1273,9 +1150,9 @@ var Fetcher = /*#__PURE__*/function () {
1273
1150
  key: "webCopy",
1274
1151
  value: function webCopy(here, there, contentType) {
1275
1152
  var _this7 = this;
1276
-
1277
1153
  return this.webOperation('GET', here).then(function (result) {
1278
- return _this7.webOperation('PUT', // change to binary from text
1154
+ return _this7.webOperation('PUT',
1155
+ // change to binary from text
1279
1156
  there, {
1280
1157
  data: result.responseText,
1281
1158
  contentType: contentType
@@ -1286,100 +1163,82 @@ var Fetcher = /*#__PURE__*/function () {
1286
1163
  key: "delete",
1287
1164
  value: function _delete(uri, options) {
1288
1165
  var _this8 = this;
1289
-
1290
1166
  return this.webOperation('DELETE', uri, options).then(function (response) {
1291
1167
  _this8.requested[uri] = 404;
1292
1168
  _this8.nonexistent[uri] = true;
1293
-
1294
1169
  _this8.unload(_this8.store.rdfFactory.namedNode(uri));
1295
-
1296
1170
  return response;
1297
1171
  });
1298
1172
  }
1173
+
1299
1174
  /** Create an empty resource if it really does not exist
1300
1175
  * Be absolutely sure something does not exist before creating a new empty file
1301
1176
  * as otherwise existing could be deleted.
1302
1177
  * @param doc - The resource
1303
1178
  */
1304
-
1305
1179
  }, {
1306
1180
  key: "createIfNotExists",
1307
1181
  value: function () {
1308
- var _createIfNotExists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(doc) {
1182
+ var _createIfNotExists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(doc) {
1309
1183
  var contentType,
1310
- data,
1311
- fetcher,
1312
- response,
1313
- _args = arguments;
1314
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1315
- while (1) {
1316
- switch (_context.prev = _context.next) {
1317
- case 0:
1318
- contentType = _args.length > 1 && _args[1] !== undefined ? _args[1] : TurtleContentType;
1319
- data = _args.length > 2 && _args[2] !== undefined ? _args[2] : '';
1320
- fetcher = this;
1321
- _context.prev = 3;
1322
- _context.next = 6;
1323
- return fetcher.load(doc);
1324
-
1325
- case 6:
1326
- response = _context.sent;
1327
- _context.next = 29;
1328
- break;
1329
-
1330
- case 9:
1331
- _context.prev = 9;
1332
- _context.t0 = _context["catch"](3);
1333
-
1334
- if (!(_context.t0.response.status === 404)) {
1335
- _context.next = 27;
1336
- break;
1337
- }
1338
-
1339
- console.log('createIfNotExists: doc does NOT exist, will create... ' + doc);
1340
- _context.prev = 13;
1341
- _context.next = 16;
1342
- return fetcher.webOperation('PUT', doc.value, {
1343
- data: data,
1344
- contentType: contentType
1345
- });
1346
-
1347
- case 16:
1348
- response = _context.sent;
1349
- _context.next = 23;
1184
+ data,
1185
+ fetcher,
1186
+ response,
1187
+ _args2 = arguments;
1188
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1189
+ while (1) switch (_context2.prev = _context2.next) {
1190
+ case 0:
1191
+ contentType = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : TurtleContentType;
1192
+ data = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : '';
1193
+ fetcher = this;
1194
+ _context2.prev = 3;
1195
+ _context2.next = 6;
1196
+ return fetcher.load(doc);
1197
+ case 6:
1198
+ response = _context2.sent;
1199
+ _context2.next = 29;
1200
+ break;
1201
+ case 9:
1202
+ _context2.prev = 9;
1203
+ _context2.t0 = _context2["catch"](3);
1204
+ if (!(_context2.t0.response.status === 404)) {
1205
+ _context2.next = 27;
1350
1206
  break;
1351
-
1352
- case 19:
1353
- _context.prev = 19;
1354
- _context.t1 = _context["catch"](13);
1355
- console.log('createIfNotExists doc FAILED: ' + doc + ': ' + _context.t1);
1356
- throw _context.t1;
1357
-
1358
- case 23:
1359
- delete fetcher.requested[doc.value]; // delete cached 404 error
1360
- // console.log('createIfNotExists doc created ok ' + doc)
1361
-
1362
- return _context.abrupt("return", response);
1363
-
1364
- case 27:
1365
- console.log('createIfNotExists doc load error NOT 404: ' + doc + ': ' + _context.t0);
1366
- throw _context.t0;
1367
-
1368
- case 29:
1369
- return _context.abrupt("return", response);
1370
-
1371
- case 30:
1372
- case "end":
1373
- return _context.stop();
1374
- }
1207
+ }
1208
+ console.log('createIfNotExists: doc does NOT exist, will create... ' + doc);
1209
+ _context2.prev = 13;
1210
+ _context2.next = 16;
1211
+ return fetcher.webOperation('PUT', doc.value, {
1212
+ data: data,
1213
+ contentType: contentType
1214
+ });
1215
+ case 16:
1216
+ response = _context2.sent;
1217
+ _context2.next = 23;
1218
+ break;
1219
+ case 19:
1220
+ _context2.prev = 19;
1221
+ _context2.t1 = _context2["catch"](13);
1222
+ console.log('createIfNotExists doc FAILED: ' + doc + ': ' + _context2.t1);
1223
+ throw _context2.t1;
1224
+ case 23:
1225
+ delete fetcher.requested[doc.value]; // delete cached 404 error
1226
+ // console.log('createIfNotExists doc created ok ' + doc)
1227
+ return _context2.abrupt("return", response);
1228
+ case 27:
1229
+ console.log('createIfNotExists doc load error NOT 404: ' + doc + ': ' + _context2.t0);
1230
+ throw _context2.t0;
1231
+ case 29:
1232
+ return _context2.abrupt("return", response);
1233
+ case 30:
1234
+ case "end":
1235
+ return _context2.stop();
1375
1236
  }
1376
- }, _callee, this, [[3, 9], [13, 19]]);
1237
+ }, _callee2, this, [[3, 9], [13, 19]]);
1377
1238
  }));
1378
-
1379
- function createIfNotExists(_x) {
1239
+ function createIfNotExists(_x4) {
1380
1240
  return _createIfNotExists.apply(this, arguments);
1381
1241
  }
1382
-
1383
1242
  return createIfNotExists;
1384
1243
  }()
1385
1244
  /**
@@ -1387,7 +1246,6 @@ var Fetcher = /*#__PURE__*/function () {
1387
1246
  * @param folderName - Optional folder name (slug)
1388
1247
  * @param data - Optional folder metadata
1389
1248
  */
1390
-
1391
1249
  }, {
1392
1250
  key: "createContainer",
1393
1251
  value: function createContainer(parentURI, folderName, data) {
@@ -1396,32 +1254,28 @@ var Fetcher = /*#__PURE__*/function () {
1396
1254
  'content-type': TurtleContentType,
1397
1255
  'link': this.ns.ldp('BasicContainer') + '; rel="type"'
1398
1256
  };
1399
-
1400
1257
  if (folderName) {
1401
1258
  headers['slug'] = folderName;
1402
- } // @ts-ignore These headers lack some of the required operators.
1403
-
1259
+ }
1404
1260
 
1261
+ // @ts-ignore These headers lack some of the required operators.
1405
1262
  var options = {
1406
1263
  headers: headers
1407
1264
  };
1408
-
1409
1265
  if (data) {
1410
1266
  options.body = data;
1411
1267
  }
1412
-
1413
1268
  return this.webOperation('POST', parentURI, options);
1414
1269
  }
1415
1270
  }, {
1416
1271
  key: "invalidateCache",
1417
1272
  value: function invalidateCache(iri) {
1418
1273
  var uri = termValue(iri);
1419
- var fetcher = this; // @ts-ignore
1420
-
1274
+ var fetcher = this;
1275
+ // @ts-ignore
1421
1276
  if (fetcher.fetchQueue && fetcher.fetchQueue[uri]) {
1422
1277
  console.log('Internal error - fetchQueue exists ' + uri);
1423
1278
  var promise = fetcher.fetchQueue[uri];
1424
-
1425
1279
  if (promise['PromiseStatus'] === 'resolved') {
1426
1280
  delete fetcher.fetchQueue[uri];
1427
1281
  } else {
@@ -1430,16 +1284,16 @@ var Fetcher = /*#__PURE__*/function () {
1430
1284
  console.log('*** Fetcher: pending fetchQueue deleted ' + uri);
1431
1285
  }
1432
1286
  }
1433
-
1434
1287
  if (fetcher.requested[uri] && fetcher.requested[uri] !== 'done' && fetcher.requested[uri] !== 'failed' && fetcher.requested[uri] !== 404) {
1435
1288
  var msg = "Rdflib: fetcher: Destructive operation on <".concat(fetcher.requested[uri], "> file being fetched! ") + uri;
1436
- console.error(msg); // alert(msg)
1289
+ console.error(msg);
1290
+ // alert(msg)
1437
1291
  } else {
1438
1292
  delete fetcher.requested[uri]; // invalidate read cache -- @@ messes up logic if request in progress ??
1439
-
1440
1293
  delete fetcher.nonexistent[uri];
1441
1294
  }
1442
1295
  }
1296
+
1443
1297
  /**
1444
1298
  * A generic web operation, at the fetch() level.
1445
1299
  * does not involve the quad store.
@@ -1447,7 +1301,6 @@ var Fetcher = /*#__PURE__*/function () {
1447
1301
  * Returns promise of Response
1448
1302
  * If data is returned, copies it to response.responseText before returning
1449
1303
  */
1450
-
1451
1304
  }, {
1452
1305
  key: "webOperation",
1453
1306
  value: function webOperation(method, uriIn) {
@@ -1457,16 +1310,13 @@ var Fetcher = /*#__PURE__*/function () {
1457
1310
  options.body = options.data || options.body;
1458
1311
  options.force = true;
1459
1312
  var fetcher = this;
1460
-
1461
1313
  if (options.body && !options.contentType) {
1462
1314
  throw new Error('Web operation sending data must have a defined contentType.');
1463
1315
  }
1464
-
1465
1316
  if (options.contentType) {
1466
1317
  options.headers = options.headers || {};
1467
1318
  options.headers['content-type'] = options.contentType;
1468
1319
  }
1469
-
1470
1320
  Fetcher.setCredentials(uri, options);
1471
1321
  return new Promise(function (resolve, reject) {
1472
1322
  fetcher._fetch(uri, options).then(function (response) {
@@ -1474,8 +1324,6 @@ var Fetcher = /*#__PURE__*/function () {
1474
1324
  if (method === 'PUT' || method === 'PATCH' || method === 'POST' || method === 'DELETE') {
1475
1325
  fetcher.invalidateCache(uri);
1476
1326
  } // response.body with Chrome can't be relied on
1477
-
1478
-
1479
1327
  if (response.text) {
1480
1328
  // Was: response.body https://github.com/linkeddata/rdflib.js/issues/506
1481
1329
  response.text().then(function (data) {
@@ -1500,6 +1348,7 @@ var Fetcher = /*#__PURE__*/function () {
1500
1348
  });
1501
1349
  });
1502
1350
  }
1351
+
1503
1352
  /**
1504
1353
  * Looks up something.
1505
1354
  * Looks up all the URIs a things has.
@@ -1509,26 +1358,25 @@ var Fetcher = /*#__PURE__*/function () {
1509
1358
  * @param rterm - the resource which referred to this
1510
1359
  * (for tracking bad links)
1511
1360
  */
1512
-
1513
1361
  }, {
1514
1362
  key: "lookUpThing",
1515
1363
  value: function lookUpThing(term, rterm) {
1516
1364
  var _this9 = this;
1517
-
1518
1365
  var uris = this.store.uris(term); // Get all URIs
1519
-
1520
1366
  uris = uris.map(function (u) {
1521
1367
  return Uri.docpart(u);
1522
1368
  }); // Drop hash fragments
1523
1369
 
1524
1370
  uris.forEach(function (u) {
1525
1371
  _this9.lookedUp[u] = true;
1526
- }); // @ts-ignore Recursive type
1372
+ });
1527
1373
 
1374
+ // @ts-ignore Recursive type
1528
1375
  return this.load(uris, {
1529
1376
  referringTerm: rterm
1530
1377
  });
1531
1378
  }
1379
+
1532
1380
  /**
1533
1381
  * Looks up response header.
1534
1382
  *
@@ -1537,36 +1385,28 @@ var Fetcher = /*#__PURE__*/function () {
1537
1385
  * or undefined if no response is available.
1538
1386
  * Looks for { [] link:requestedURI ?uri; link:response [ httph:header-name ?value ] }
1539
1387
  */
1540
-
1541
1388
  }, {
1542
1389
  key: "getHeader",
1543
1390
  value: function getHeader(doc, header) {
1544
1391
  var kb = this.store; // look for the URI (AS A STRING NOT A NODE) for a stored request
1545
-
1546
1392
  var docuri = doc.value;
1547
1393
  var requests = kb.each(undefined, this.ns.link('requestedURI'), kb.rdfFactory.literal(docuri));
1548
-
1549
1394
  for (var r = 0; r < requests.length; r++) {
1550
1395
  var request = requests[r];
1551
-
1552
1396
  if (request !== undefined) {
1553
1397
  var _response = kb.any(request, this.ns.link('response'));
1554
-
1555
1398
  if (_response !== undefined && kb.anyValue(_response, this.ns.http('status')) && kb.anyValue(_response, this.ns.http('status')).startsWith('2')) {
1556
1399
  // Only look at success returns - not 401 error messagess etc
1557
1400
  var results = kb.each(_response, this.ns.httph(header.toLowerCase()));
1558
-
1559
1401
  if (results.length) {
1560
1402
  return results.map(function (v) {
1561
1403
  return v.value;
1562
1404
  });
1563
1405
  }
1564
-
1565
1406
  return [];
1566
1407
  }
1567
1408
  }
1568
1409
  }
1569
-
1570
1410
  return undefined;
1571
1411
  }
1572
1412
  }, {
@@ -1576,20 +1416,17 @@ var Fetcher = /*#__PURE__*/function () {
1576
1416
  var kb = this.store;
1577
1417
  var rterm = options.referringTerm;
1578
1418
  this.addStatus(options.req, 'Accept: ' + options.headers['accept']);
1579
-
1580
1419
  if (isNamedNode(rterm)) {
1581
1420
  kb.add(kb.rdfFactory.namedNode(docuri), this.ns.link('requestedBy'), rterm, this.appNode);
1582
1421
  }
1583
-
1584
1422
  if (options.original && options.original.value !== docuri) {
1585
1423
  kb.add(req, this.ns.link('orginalURI'), kb.rdfFactory.literal(options.original.value), this.appNode);
1586
1424
  }
1587
-
1588
1425
  var now = new Date();
1589
1426
  var timeNow = '[' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() + '] ';
1590
- kb.add(req, this.ns.rdfs('label'), kb.rdfFactory.literal(timeNow + ' Request for ' + docuri), this.appNode); // We store the docuri as a string, not as a node,
1427
+ kb.add(req, this.ns.rdfs('label'), kb.rdfFactory.literal(timeNow + ' Request for ' + docuri), this.appNode);
1428
+ // We store the docuri as a string, not as a node,
1591
1429
  // see https://github.com/linkeddata/rdflib.js/pull/427#pullrequestreview-447910061
1592
-
1593
1430
  kb.add(req, this.ns.link('requestedURI'), kb.rdfFactory.literal(docuri), this.appNode);
1594
1431
  kb.add(req, this.ns.link('status'), kb.collection(), this.appNode);
1595
1432
  }
@@ -1597,16 +1434,15 @@ var Fetcher = /*#__PURE__*/function () {
1597
1434
  key: "saveResponseMetadata",
1598
1435
  value: function saveResponseMetadata(response, options) {
1599
1436
  var _this10 = this;
1600
-
1601
1437
  var kb = this.store;
1602
1438
  var responseNode = kb.bnode();
1603
1439
  kb.add(options.req, this.ns.link('response'), responseNode, responseNode);
1604
1440
  kb.add(responseNode, this.ns.http('status'), kb.rdfFactory.literal(response.status), responseNode);
1605
- kb.add(responseNode, this.ns.http('statusText'), kb.rdfFactory.literal(response.statusText), responseNode); // Save the response headers
1441
+ kb.add(responseNode, this.ns.http('statusText'), kb.rdfFactory.literal(response.statusText), responseNode);
1606
1442
 
1443
+ // Save the response headers
1607
1444
  response.headers.forEach(function (value, header) {
1608
1445
  kb.add(responseNode, _this10.ns.httph(header), _this10.store.rdfFactory.literal(value), responseNode);
1609
-
1610
1446
  if (header === 'content-type') {
1611
1447
  kb.add(options.resource, _this10.ns.rdf('type'), kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value), responseNode);
1612
1448
  }
@@ -1617,19 +1453,19 @@ var Fetcher = /*#__PURE__*/function () {
1617
1453
  key: "objectRefresh",
1618
1454
  value: function objectRefresh(term) {
1619
1455
  var uris = this.store.uris(term); // Get all URIs
1620
-
1621
1456
  if (typeof uris !== 'undefined') {
1622
1457
  for (var i = 0; i < uris.length; i++) {
1623
- this.refresh(this.store.rdfFactory.namedNode(Uri.docpart(uris[i]))); // what about rterm?
1458
+ this.refresh(this.store.rdfFactory.namedNode(Uri.docpart(uris[i])));
1459
+ // what about rterm?
1624
1460
  }
1625
1461
  }
1626
1462
  }
1463
+
1627
1464
  /* refresh Reload data from a given document
1628
1465
  **
1629
1466
  ** @param term - An RDF Named Node for the eodcument in question
1630
1467
  ** @param userCallback - A function userCallback(ok, message, response)
1631
1468
  */
1632
-
1633
1469
  }, {
1634
1470
  key: "refresh",
1635
1471
  value: function refresh(term, userCallback) {
@@ -1640,17 +1476,16 @@ var Fetcher = /*#__PURE__*/function () {
1640
1476
  clearPreviousData: true
1641
1477
  }, userCallback);
1642
1478
  }
1479
+
1643
1480
  /* refreshIfExpired Conditional refresh if Expired
1644
1481
  **
1645
1482
  ** @param term - An RDF Named Node for the eodcument in question
1646
1483
  ** @param userCallback - A function userCallback(ok, message, response)
1647
1484
  */
1648
-
1649
1485
  }, {
1650
1486
  key: "refreshIfExpired",
1651
1487
  value: function refreshIfExpired(term, userCallback) {
1652
1488
  var exp = this.getHeader(term, 'Expires');
1653
-
1654
1489
  if (!exp || new Date(exp[0]).getTime() <= new Date().getTime()) {
1655
1490
  this.refresh(term, userCallback);
1656
1491
  } else {
@@ -1662,11 +1497,9 @@ var Fetcher = /*#__PURE__*/function () {
1662
1497
  value: function retract(term) {
1663
1498
  // sources_retract
1664
1499
  this.store.removeMany(undefined, undefined, undefined, term);
1665
-
1666
1500
  if (term.value) {
1667
1501
  delete this.requested[Uri.docpart(term.value)];
1668
1502
  }
1669
-
1670
1503
  this.fireCallbacks('retract', arguments);
1671
1504
  }
1672
1505
  }, {
@@ -1713,20 +1546,19 @@ var Fetcher = /*#__PURE__*/function () {
1713
1546
  options.retriedWithNoCredentials = true; // protect against being called twice
1714
1547
 
1715
1548
  delete this.requested[docuri]; // forget the original request happened
1716
-
1717
- delete this.fetchQueue[docuri]; // Note: XHR property was withCredentials, but fetch property is just credentials
1718
-
1549
+ delete this.fetchQueue[docuri];
1550
+ // Note: XHR property was withCredentials, but fetch property is just credentials
1719
1551
  var newOptions = Object.assign({}, options, {
1720
1552
  credentials: 'omit'
1721
1553
  });
1722
1554
  this.addStatus(options.req, 'Abort: Will retry with credentials SUPPRESSED to see if that helps');
1723
1555
  return this.load(docuri, newOptions);
1724
1556
  }
1557
+
1725
1558
  /**
1726
1559
  * Tests whether a request is being made to a cross-site URI (for purposes
1727
1560
  * of retrying with a proxy)
1728
1561
  */
1729
-
1730
1562
  }, {
1731
1563
  key: "isCrossSite",
1732
1564
  value: function isCrossSite(uri) {
@@ -1734,16 +1566,15 @@ var Fetcher = /*#__PURE__*/function () {
1734
1566
  if (typeof document === 'undefined' || !document.location) {
1735
1567
  return false;
1736
1568
  }
1737
-
1738
1569
  var hostpart = Uri.hostpart;
1739
1570
  var here = '' + document.location;
1740
1571
  return (hostpart(here) && hostpart(uri) && hostpart(here)) !== hostpart(uri);
1741
1572
  }
1573
+
1742
1574
  /**
1743
1575
  * Called when there's a network error in fetch(), or a response
1744
1576
  * with status of 0.
1745
1577
  */
1746
-
1747
1578
  }, {
1748
1579
  key: "handleError",
1749
1580
  value: function handleError(response, docuri, options) {
@@ -1751,149 +1582,125 @@ var Fetcher = /*#__PURE__*/function () {
1751
1582
  // Make sure we haven't retried already
1752
1583
  if (options.credentials && options.credentials === 'include' && !options.retriedWithNoCredentials) {
1753
1584
  return this.retryNoCredentials(docuri, options);
1754
- } // Now attempt retry via proxy
1755
-
1585
+ }
1756
1586
 
1587
+ // Now attempt retry via proxy
1757
1588
  var proxyUri = Fetcher.crossSiteProxy(docuri);
1758
-
1759
1589
  if (proxyUri && !options.proxyUsed) {
1760
1590
  console.log('web: Direct failed so trying proxy ' + proxyUri);
1761
1591
  return this.redirectToProxy(proxyUri, options);
1762
1592
  }
1763
1593
  }
1764
-
1765
1594
  var message;
1766
-
1767
1595
  if (response instanceof Error) {
1768
1596
  message = 'Fetch error: ' + response.message;
1769
1597
  } else {
1770
1598
  message = response.statusText;
1771
-
1772
1599
  if (response.responseText) {
1773
1600
  message += " ".concat(response.responseText);
1774
1601
  }
1775
- } // This is either not a CORS error, or retries have been made
1776
-
1602
+ }
1777
1603
 
1604
+ // This is either not a CORS error, or retries have been made
1778
1605
  return this.failFetch(options, message, response.status || 998, response);
1779
- } // deduce some things from the HTTP transaction
1606
+ }
1780
1607
 
1608
+ // deduce some things from the HTTP transaction
1781
1609
  }, {
1782
1610
  key: "addType",
1783
1611
  value: function addType(rdfType, req, kb, locURI) {
1784
1612
  // add type to all redirected resources too
1785
1613
  var prev = req;
1786
-
1787
1614
  if (locURI) {
1788
1615
  var reqURI = kb.any(prev, this.ns.link('requestedURI'));
1789
-
1790
1616
  if (reqURI && reqURI.value !== locURI) {
1791
1617
  kb.add(kb.rdfFactory.namedNode(locURI), this.ns.rdf('type'), rdfType, this.appNode);
1792
1618
  }
1793
1619
  }
1794
-
1795
1620
  for (;;) {
1796
1621
  var doc = kb.any(prev, this.ns.link('requestedURI'));
1797
-
1798
1622
  if (doc && doc.value) {
1799
1623
  kb.add(kb.rdfFactory.namedNode(doc.value), this.ns.rdf('type'), rdfType, this.appNode);
1800
1624
  } // convert Literal
1801
-
1802
-
1803
1625
  prev = kb.any(undefined, kb.rdfFactory.namedNode('http://www.w3.org/2007/ont/link#redirectedRequest'), prev);
1804
-
1805
1626
  if (!prev) {
1806
1627
  break;
1807
1628
  }
1808
-
1809
1629
  var response = kb.any(prev, kb.rdfFactory.namedNode('http://www.w3.org/2007/ont/link#response'));
1810
-
1811
1630
  if (!response) {
1812
1631
  break;
1813
1632
  }
1814
-
1815
1633
  var redirection = kb.any(response, kb.rdfFactory.namedNode('http://www.w3.org/2007/ont/http#status'));
1816
-
1817
1634
  if (!redirection) {
1818
1635
  break;
1819
- } // @ts-ignore always true?
1820
-
1821
-
1636
+ }
1637
+ // @ts-ignore always true?
1822
1638
  if (redirection !== '301' && redirection !== '302') {
1823
1639
  break;
1824
1640
  }
1825
1641
  }
1826
1642
  }
1643
+
1827
1644
  /**
1828
1645
  * Handle fetch() response
1829
1646
  */
1830
-
1831
1647
  }, {
1832
1648
  key: "handleResponse",
1833
1649
  value: function handleResponse(response, docuri, options) {
1834
1650
  var _this11 = this;
1835
-
1836
1651
  var kb = this.store;
1837
1652
  var headers = response.headers;
1838
1653
  var reqNode = options.req;
1839
1654
  var responseNode = this.saveResponseMetadata(response, options);
1840
1655
  var contentType = this.normalizedContentType(options, headers) || '';
1841
- var contentLocation = headers.get('content-location'); // this.fireCallbacks('recv', xhr.args)
1656
+ var contentLocation = headers.get('content-location');
1657
+
1658
+ // this.fireCallbacks('recv', xhr.args)
1842
1659
  // this.fireCallbacks('headers', [{uri: docuri, headers: xhr.headers}])
1843
- // Check for masked errors (CORS, etc)
1844
1660
 
1661
+ // Check for masked errors (CORS, etc)
1845
1662
  if (response.status === 0) {
1846
1663
  console.log('Masked error - status 0 for ' + docuri);
1847
1664
  return this.handleError(response, docuri, options);
1848
1665
  }
1849
-
1850
1666
  if (response.status >= 400) {
1851
1667
  if (response.status === 404) {
1852
1668
  this.nonexistent[options.original.value] = true;
1853
1669
  this.nonexistent[docuri] = true;
1854
1670
  }
1855
-
1856
1671
  return this.saveErrorResponse(response, responseNode).then(function () {
1857
1672
  var errorMessage = options.resource + ' ' + response.statusText;
1858
1673
  return _this11.failFetch(options, errorMessage, response.status, response);
1859
1674
  });
1860
1675
  }
1861
-
1862
1676
  var diffLocation = null;
1863
1677
  var absContentLocation = null;
1864
-
1865
1678
  if (contentLocation) {
1866
1679
  absContentLocation = Uri.join(contentLocation, docuri);
1867
-
1868
1680
  if (absContentLocation !== docuri) {
1869
1681
  diffLocation = absContentLocation;
1870
1682
  }
1871
1683
  }
1872
-
1873
1684
  if (response.status === 200) {
1874
1685
  this.addType(this.ns.link('Document'), reqNode, kb, docuri);
1875
-
1876
1686
  if (diffLocation) {
1877
1687
  this.addType(this.ns.link('Document'), reqNode, kb, diffLocation);
1878
- } // Before we parse new data clear old but only on 200
1879
-
1688
+ }
1880
1689
 
1690
+ // Before we parse new data clear old but only on 200
1881
1691
  if (options.clearPreviousData) {
1882
1692
  kb.removeDocument(options.resource);
1883
1693
  }
1884
-
1885
1694
  var isImage = contentType.includes('image/') || contentType.includes('application/pdf');
1886
-
1887
1695
  if (contentType && isImage) {
1888
1696
  this.addType(kb.rdfFactory.namedNode('http://purl.org/dc/terms/Image'), reqNode, kb, docuri);
1889
-
1890
1697
  if (diffLocation) {
1891
1698
  this.addType(kb.rdfFactory.namedNode('http://purl.org/dc/terms/Image'), reqNode, kb, diffLocation);
1892
1699
  }
1893
1700
  }
1894
- } // If we have already got the thing at this location, abort
1895
-
1701
+ }
1896
1702
 
1703
+ // If we have already got the thing at this location, abort
1897
1704
  if (contentLocation) {
1898
1705
  if (!options.force && diffLocation && this.requested[absContentLocation] === 'done') {
1899
1706
  // we have already fetched this
@@ -1902,20 +1709,17 @@ var Fetcher = /*#__PURE__*/function () {
1902
1709
  // xhr.resource + " as " + absContentLocation + ". Aborting.")
1903
1710
  return this.doneFetch(options, response);
1904
1711
  }
1905
-
1906
1712
  this.requested[absContentLocation] = true;
1907
1713
  }
1908
-
1909
1714
  this.parseLinkHeader(headers.get('link'), options.original, reqNode);
1910
1715
  var handler = this.handlerForContentType(contentType, response);
1911
-
1912
1716
  if (!handler) {
1913
1717
  // Not a problem, we just don't extract data
1914
1718
  this.addStatus(reqNode, 'Fetch over. No data handled.');
1915
1719
  return this.doneFetch(options, response);
1916
1720
  }
1917
-
1918
- return response.text() // @ts-ignore Types seem right
1721
+ return response.text()
1722
+ // @ts-ignore Types seem right
1919
1723
  .then(function (responseText) {
1920
1724
  response.responseText = responseText;
1921
1725
  return handler.parse(_this11, responseText, options, response);
@@ -1925,7 +1729,6 @@ var Fetcher = /*#__PURE__*/function () {
1925
1729
  key: "saveErrorResponse",
1926
1730
  value: function saveErrorResponse(response, responseNode) {
1927
1731
  var _this12 = this;
1928
-
1929
1732
  var kb = this.store;
1930
1733
  return response.text().then(function (content) {
1931
1734
  if (content.length > 10) {
@@ -1939,11 +1742,11 @@ var Fetcher = /*#__PURE__*/function () {
1939
1742
  if (!contentType) {
1940
1743
  return null;
1941
1744
  }
1942
-
1943
1745
  var Handler = this.handlers.find(function (handler) {
1944
1746
  return contentType.match(handler.pattern);
1945
- }); // @ts-ignore in practice all Handlers have constructors.
1747
+ });
1946
1748
 
1749
+ // @ts-ignore in practice all Handlers have constructors.
1947
1750
  return Handler ? new Handler(response) : null;
1948
1751
  }
1949
1752
  }, {
@@ -1957,34 +1760,27 @@ var Fetcher = /*#__PURE__*/function () {
1957
1760
  if (options.forceContentType) {
1958
1761
  return options.forceContentType;
1959
1762
  }
1960
-
1961
1763
  var contentType = headers.get('content-type');
1962
-
1963
1764
  if (!contentType || contentType.includes('application/octet-stream')) {
1964
1765
  var guess = this.guessContentType(options.resource.value);
1965
-
1966
1766
  if (guess) {
1967
1767
  return guess;
1968
1768
  }
1969
1769
  }
1970
-
1971
1770
  var protocol = Uri.protocol(options.resource.value);
1972
-
1973
1771
  if (!contentType && ['file', 'chrome'].includes(protocol)) {
1974
1772
  return 'text/xml';
1975
1773
  }
1976
-
1977
1774
  return contentType;
1978
1775
  }
1776
+
1979
1777
  /**
1980
1778
  * Sends a new request to the specified uri. (Extracted from `onerrorFactory()`)
1981
1779
  */
1982
-
1983
1780
  }, {
1984
1781
  key: "redirectToProxy",
1985
1782
  value: function redirectToProxy(newURI, options) {
1986
1783
  var _this13 = this;
1987
-
1988
1784
  this.addStatus(options.req, 'BLOCKED -> Cross-site Proxy to <' + newURI + '>');
1989
1785
  options.proxyUsed = true;
1990
1786
  var kb = this.store;
@@ -2003,7 +1799,6 @@ var Fetcher = /*#__PURE__*/function () {
2003
1799
  if (!newOptions.noMeta) {
2004
1800
  kb.add(oldReq, _this13.ns.link('redirectedRequest'), newOptions.req, _this13.appNode);
2005
1801
  }
2006
-
2007
1802
  return response;
2008
1803
  });
2009
1804
  }
@@ -2011,7 +1806,6 @@ var Fetcher = /*#__PURE__*/function () {
2011
1806
  key: "setRequestTimeout",
2012
1807
  value: function setRequestTimeout(uri, options) {
2013
1808
  var _this14 = this;
2014
-
2015
1809
  return new Promise(function (resolve) {
2016
1810
  _this14.timeouts[uri] = (_this14.timeouts[uri] || []).concat(setTimeout(function () {
2017
1811
  if (_this14.isPending(uri) && !options.retriedWithNoCredentials && !options.proxyUsed) {
@@ -2033,24 +1827,20 @@ var Fetcher = /*#__PURE__*/function () {
2033
1827
  key: "acceptString",
2034
1828
  value: function acceptString() {
2035
1829
  var acceptstring = '';
2036
-
2037
1830
  for (var mediaType in this.mediatypes) {
2038
1831
  if (acceptstring !== '') {
2039
1832
  acceptstring += ', ';
2040
1833
  }
2041
-
2042
1834
  acceptstring += mediaType;
2043
-
2044
1835
  for (var property in this.mediatypes[mediaType]) {
2045
1836
  acceptstring += ';' + property + '=' + this.mediatypes[mediaType][property];
2046
1837
  }
2047
1838
  }
2048
-
2049
1839
  return acceptstring;
2050
- } // var updatesVia = new $rdf.UpdatesVia(this) // Subscribe to headers
1840
+ }
1841
+ // var updatesVia = new $rdf.UpdatesVia(this) // Subscribe to headers
2051
1842
  // @@@@@@@@ This is turned off because it causes a websocket to be set up for ANY fetch
2052
1843
  // whether we want to track it ot not. including ontologies loaed though the XSSproxy
2053
-
2054
1844
  }], [{
2055
1845
  key: "crossSiteProxy",
2056
1846
  value: function crossSiteProxy(uri) {
@@ -2070,90 +1860,81 @@ var Fetcher = /*#__PURE__*/function () {
2070
1860
  // Do not remove without checking with TimBL
2071
1861
  var requestedURI = uri;
2072
1862
  var UI;
2073
-
2074
1863
  if (typeof window !== 'undefined' && window.panes && (UI = window.panes.UI) && UI.preferences && UI.preferences.get('offlineModeUsingLocalhost')) {
2075
1864
  if (requestedURI.slice(0, 7) === 'http://' && requestedURI.slice(7, 17) !== 'localhost/') {
2076
1865
  requestedURI = 'http://localhost/' + requestedURI.slice(7);
2077
1866
  log.warn('Localhost kludge for offline use: actually getting <' + requestedURI + '>');
2078
- } else {// log.warn("Localhost kludge NOT USED <" + requestedURI + ">")
1867
+ } else {
1868
+ // log.warn("Localhost kludge NOT USED <" + requestedURI + ">")
2079
1869
  }
2080
- } else {// log.warn("Localhost kludge OFF offline use: actually getting <" +
1870
+ } else {
1871
+ // log.warn("Localhost kludge OFF offline use: actually getting <" +
2081
1872
  // requestedURI + ">")
2082
1873
  }
2083
-
2084
1874
  return requestedURI;
2085
1875
  }
2086
1876
  }, {
2087
1877
  key: "proxyIfNecessary",
2088
1878
  value: function proxyIfNecessary(uri) {
2089
1879
  var UI;
2090
-
2091
1880
  if (typeof window !== 'undefined' && window.panes && (UI = window.panes.UI) && UI.isExtension) {
2092
1881
  return uri;
2093
1882
  } // Extension does not need proxy
2094
1883
 
2095
-
2096
1884
  if (typeof $SolidTestEnvironment !== 'undefined' && $SolidTestEnvironment.localSiteMap) {
2097
1885
  // nested dictionaries of URI parts from origin down
2098
1886
  var hostpath = uri.split('/').slice(2); // the bit after the //
2099
1887
 
2100
1888
  var lookup = function lookup(parts, index) {
2101
1889
  var z = index[parts.shift()];
2102
-
2103
1890
  if (!z) {
2104
1891
  return null;
2105
1892
  }
2106
-
2107
1893
  if (typeof z === 'string') {
2108
1894
  return z + parts.join('/');
2109
1895
  }
2110
-
2111
1896
  if (!parts) {
2112
1897
  return null;
2113
1898
  }
2114
-
2115
1899
  return lookup(parts, z);
2116
1900
  };
2117
-
2118
1901
  var y = lookup(hostpath, $SolidTestEnvironment.localSiteMap);
2119
-
2120
1902
  if (y) {
2121
1903
  return y;
2122
1904
  }
2123
- } // browser does 2014 on as https browser script not trusted
1905
+ }
1906
+
1907
+ // browser does 2014 on as https browser script not trusted
2124
1908
  // If the web app origin is https: then the mixed content rules
2125
1909
  // prevent it loading insecure http: stuff so we need proxy.
2126
-
2127
-
2128
- if (Fetcher.crossSiteProxyTemplate && typeof document !== 'undefined' && document.location && ('' + document.location).slice(0, 6) === 'https:' && // origin is secure
1910
+ if (Fetcher.crossSiteProxyTemplate && typeof document !== 'undefined' && document.location && ('' + document.location).slice(0, 6) === 'https:' &&
1911
+ // origin is secure
2129
1912
  uri.slice(0, 5) === 'http:') {
2130
1913
  // requested data is not
2131
1914
  return Fetcher.crossSiteProxyTemplate.replace('{uri}', encodeURIComponent(uri));
2132
1915
  }
2133
-
2134
1916
  return uri;
2135
1917
  }
1918
+
2136
1919
  /**
2137
1920
  * Tests whether the uri's protocol is supported by the Fetcher.
2138
1921
  * @param uri
2139
1922
  */
2140
-
2141
1923
  }, {
2142
1924
  key: "unsupportedProtocol",
2143
1925
  value: function unsupportedProtocol(uri) {
2144
1926
  var pcol = Uri.protocol(uri);
2145
1927
  return pcol === 'tel' || pcol === 'mailto' || pcol === 'urn';
2146
1928
  }
1929
+
2147
1930
  /** Decide on credentials using old XXHR api or new fetch() one
2148
1931
  * @param requestedURI
2149
1932
  * @param options
2150
1933
  */
2151
-
2152
1934
  }, {
2153
1935
  key: "setCredentials",
2154
1936
  value: function setCredentials(requestedURI) {
2155
1937
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2156
-
2157
1938
  // 2014 CORS problem:
2158
1939
  // XMLHttpRequest cannot load http://www.w3.org/People/Berners-Lee/card.
2159
1940
  // A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin'
@@ -2171,16 +1952,11 @@ var Fetcher = /*#__PURE__*/function () {
2171
1952
  }
2172
1953
  }
2173
1954
  }]);
2174
-
2175
1955
  return Fetcher;
2176
1956
  }();
2177
-
2178
1957
  _defineProperty(Fetcher, "HANDLERS", void 0);
2179
-
2180
1958
  _defineProperty(Fetcher, "CONTENT_TYPE_BY_EXT", void 0);
2181
-
2182
1959
  _defineProperty(Fetcher, "crossSiteProxyTemplate", void 0);
2183
-
2184
1960
  export { Fetcher as default };
2185
1961
  Fetcher.HANDLERS = defaultHandlers;
2186
1962
  Fetcher.CONTENT_TYPE_BY_EXT = CONTENT_TYPE_BY_EXT;