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