rdflib 2.2.22 → 2.2.23-6384f9a2

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