rdflib 2.2.30 → 2.2.31-10c4e145
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.
- package/dist/730.rdflib.min.js +1 -1
- package/dist/730.rdflib.min.js.map +1 -1
- package/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.LICENSE.txt +0 -59
- package/dist/rdflib.min.js.map +1 -1
- package/esm/fetcher.js +41 -9
- package/esm/jsonldparser.js +4 -3
- package/esm/store.js +21 -1
- package/esm/update-manager.js +112 -15
- package/lib/fetcher.d.ts +1 -1
- package/lib/fetcher.js +41 -9
- package/lib/jsonldparser.js +9 -3
- package/lib/store.d.ts +1 -1
- package/lib/store.js +21 -1
- package/lib/update-manager.d.ts +20 -1
- package/lib/update-manager.js +112 -15
- package/package.json +3 -3
- package/src/fetcher.ts +22 -8
- package/src/jsonldparser.js +2 -4
- package/src/store.ts +18 -1
- package/src/update-manager.ts +61 -7
- package/esm/convert.js +0 -60
- package/lib/convert.d.ts +0 -2
- package/lib/convert.js +0 -71
package/esm/fetcher.js
CHANGED
|
@@ -6,6 +6,9 @@ import _createClass from "@babel/runtime/helpers/createClass";
|
|
|
6
6
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
7
7
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
8
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
9
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
10
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
12
|
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
13
|
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; } }
|
|
11
14
|
/* global $SolidTestEnvironment */
|
|
@@ -598,7 +601,9 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
598
601
|
if (!this._fetch) {
|
|
599
602
|
throw new Error('No _fetch function available for Fetcher');
|
|
600
603
|
}
|
|
601
|
-
|
|
604
|
+
// This is the name of the graph we store all the HTTP metadata in
|
|
605
|
+
this.appNode = this.store.sym('chrome://TheCurrentSession');
|
|
606
|
+
// this.appNode = this.store.rdfFactory.blankNode() // Needs to have a URI in tests
|
|
602
607
|
this.store.fetcher = this; // Bi-linked
|
|
603
608
|
this.requested = {};
|
|
604
609
|
this.timeouts = {};
|
|
@@ -686,6 +691,31 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
686
691
|
var docuri = termValue(uriIn);
|
|
687
692
|
docuri = docuri.split('#')[0];
|
|
688
693
|
options = this.initFetchOptions(docuri, options);
|
|
694
|
+
// if metadata flaged clear cache and removeDocument
|
|
695
|
+
var meta = this.appNode;
|
|
696
|
+
var kb = this.store;
|
|
697
|
+
var requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), kb.sym(docuri), meta).map(function (st) {
|
|
698
|
+
return st.subject;
|
|
699
|
+
});
|
|
700
|
+
var _iterator = _createForOfIteratorHelper(requests),
|
|
701
|
+
_step;
|
|
702
|
+
try {
|
|
703
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
704
|
+
var request = _step.value;
|
|
705
|
+
var _response = kb.any(request, this.ns.link('response'), null, meta);
|
|
706
|
+
if (_response !== undefined) {
|
|
707
|
+
// ts
|
|
708
|
+
var quad = kb.statementsMatching(_response, this.ns.link('outOfDate'), true, meta);
|
|
709
|
+
kb.remove(quad);
|
|
710
|
+
options.force = true;
|
|
711
|
+
options.clearPreviousData = true;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
} catch (err) {
|
|
715
|
+
_iterator.e(err);
|
|
716
|
+
} finally {
|
|
717
|
+
_iterator.f();
|
|
718
|
+
}
|
|
689
719
|
var initialisedOptions = this.initFetchOptions(docuri, options);
|
|
690
720
|
return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions);
|
|
691
721
|
}
|
|
@@ -1388,10 +1418,10 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
1388
1418
|
for (var r = 0; r < requests.length; r++) {
|
|
1389
1419
|
var request = requests[r];
|
|
1390
1420
|
if (request !== undefined) {
|
|
1391
|
-
var
|
|
1392
|
-
if (
|
|
1421
|
+
var _response2 = kb.any(request, this.ns.link('response'));
|
|
1422
|
+
if (_response2 !== undefined && kb.anyValue(_response2, this.ns.http('status')) && kb.anyValue(_response2, this.ns.http('status')).startsWith('2')) {
|
|
1393
1423
|
// Only look at success returns - not 401 error messagess etc
|
|
1394
|
-
var results = kb.each(
|
|
1424
|
+
var results = kb.each(_response2, this.ns.httph(header.toLowerCase()));
|
|
1395
1425
|
if (results.length) {
|
|
1396
1426
|
return results.map(function (v) {
|
|
1397
1427
|
return v.value;
|
|
@@ -1430,17 +1460,19 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
1430
1460
|
var _this10 = this;
|
|
1431
1461
|
var kb = this.store;
|
|
1432
1462
|
var responseNode = kb.bnode();
|
|
1433
|
-
kb.add(options.req, this.ns.link('response'), responseNode,
|
|
1434
|
-
kb.add(responseNode, this.ns.http('status'), kb.rdfFactory.literal(response.status),
|
|
1435
|
-
kb.add(responseNode, this.ns.http('statusText'), kb.rdfFactory.literal(response.statusText),
|
|
1463
|
+
kb.add(options.req, this.ns.link('response'), responseNode, this.appNode);
|
|
1464
|
+
kb.add(responseNode, this.ns.http('status'), kb.rdfFactory.literal(response.status), this.appNode);
|
|
1465
|
+
kb.add(responseNode, this.ns.http('statusText'), kb.rdfFactory.literal(response.statusText), this.appNode);
|
|
1436
1466
|
|
|
1437
1467
|
// Save the response headers
|
|
1438
1468
|
response.headers.forEach(function (value, header) {
|
|
1439
|
-
kb.add(responseNode, _this10.ns.httph(header), _this10.store.rdfFactory.literal(value),
|
|
1469
|
+
kb.add(responseNode, _this10.ns.httph(header), _this10.store.rdfFactory.literal(value), _this10.appNode);
|
|
1440
1470
|
if (header === 'content-type') {
|
|
1441
|
-
kb.add(options.resource, _this10.ns.rdf('type'), kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value), responseNode
|
|
1471
|
+
kb.add(options.resource, _this10.ns.rdf('type'), kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value), _this10.appNode // responseNode
|
|
1472
|
+
);
|
|
1442
1473
|
}
|
|
1443
1474
|
});
|
|
1475
|
+
|
|
1444
1476
|
return responseNode;
|
|
1445
1477
|
}
|
|
1446
1478
|
}, {
|
package/esm/jsonldparser.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import jsonld from 'jsonld';
|
|
2
1
|
import { arrayToStatements } from './utils';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -60,8 +59,10 @@ function listToCollection(kb, obj) {
|
|
|
60
59
|
*/
|
|
61
60
|
export default function jsonldParser(str, kb, base, callback) {
|
|
62
61
|
var baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base;
|
|
63
|
-
return jsonld.
|
|
64
|
-
|
|
62
|
+
return import('jsonld').then(function (jsonld) {
|
|
63
|
+
return jsonld.flatten(JSON.parse(str), null, {
|
|
64
|
+
base: baseString
|
|
65
|
+
});
|
|
65
66
|
}).then(function (flattened) {
|
|
66
67
|
return flattened.reduce(function (store, flatResource) {
|
|
67
68
|
kb = processResource(kb, base, flatResource);
|
package/esm/store.js
CHANGED
|
@@ -838,12 +838,32 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
|
|
|
838
838
|
}
|
|
839
839
|
|
|
840
840
|
/**
|
|
841
|
-
* Removes all statements in a doc
|
|
841
|
+
* Removes all statements in a doc, along with the related metadata including request/response
|
|
842
842
|
* @param doc - The document / graph
|
|
843
843
|
*/
|
|
844
844
|
}, {
|
|
845
845
|
key: "removeDocument",
|
|
846
846
|
value: function removeDocument(doc) {
|
|
847
|
+
var meta = this.sym('chrome://TheCurrentSession'); // or this.rdfFactory.namedNode('chrome://TheCurrentSession')
|
|
848
|
+
var linkNamespaceURI = 'http://www.w3.org/2007/ont/link#'; // alain
|
|
849
|
+
// remove request/response and metadata
|
|
850
|
+
var requests = this.statementsMatching(undefined, this.sym("".concat(linkNamespaceURI, "requestedURI")), this.rdfFactory.literal(doc.value), meta).map(function (st) {
|
|
851
|
+
return st.subject;
|
|
852
|
+
});
|
|
853
|
+
for (var r = 0; r < requests.length; r++) {
|
|
854
|
+
var request = requests[r];
|
|
855
|
+
if (request !== undefined) {
|
|
856
|
+
this.removeMatches(request, null, null, meta);
|
|
857
|
+
var response = this.any(request, this.sym("".concat(linkNamespaceURI, "response")), null, meta);
|
|
858
|
+
if (response !== undefined) {
|
|
859
|
+
// ts
|
|
860
|
+
this.removeMatches(response, null, null, meta);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
this.removeMatches(this.sym(doc.value), null, null, meta); // content-type
|
|
865
|
+
|
|
866
|
+
// remove document
|
|
847
867
|
var sts = this.statementsMatching(undefined, undefined, undefined, doc).slice(); // Take a copy as this is the actual index
|
|
848
868
|
for (var i = 0; i < sts.length; i++) {
|
|
849
869
|
this.removeStatement(sts[i]);
|
package/esm/update-manager.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
3
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
4
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
5
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
7
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
8
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
9
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
@@ -76,13 +78,100 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
76
78
|
return uri.slice(0, 4) === 'http';
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
/** Remove from the store HTTP authorization metadata
|
|
82
|
+
* The editble function below relies on copies we have in the store
|
|
83
|
+
* of the results of previous HTTP transactions. Howver, when
|
|
84
|
+
* the user logs in, then that data misrepresents what would happen
|
|
85
|
+
* if the user tried again.
|
|
86
|
+
*/
|
|
87
|
+
}, {
|
|
88
|
+
key: "flagAuthorizationMetadata",
|
|
89
|
+
value: function flagAuthorizationMetadata(kb) {
|
|
90
|
+
var _kb$fetcher;
|
|
91
|
+
if (!kb) {
|
|
92
|
+
kb = this.store;
|
|
93
|
+
}
|
|
94
|
+
var meta = (_kb$fetcher = kb.fetcher) === null || _kb$fetcher === void 0 ? void 0 : _kb$fetcher.appNode;
|
|
95
|
+
var requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), undefined, meta).map(function (st) {
|
|
96
|
+
return st.subject;
|
|
97
|
+
});
|
|
98
|
+
var _iterator = _createForOfIteratorHelper(requests),
|
|
99
|
+
_step;
|
|
100
|
+
try {
|
|
101
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
102
|
+
var request = _step.value;
|
|
103
|
+
var _response = kb.any(request, this.ns.link('response'), null, meta);
|
|
104
|
+
if (_response !== undefined) {
|
|
105
|
+
// ts
|
|
106
|
+
kb.add(_response, this.ns.link('outOfDate'), true, meta); // @@ Boolean is fine - fix types
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch (err) {
|
|
110
|
+
_iterator.e(err);
|
|
111
|
+
} finally {
|
|
112
|
+
_iterator.f();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
79
116
|
/**
|
|
80
117
|
* Tests whether a file is editable.
|
|
81
118
|
* If the file has a specific annotation that it is machine written,
|
|
82
119
|
* for safety, it is editable (this doesn't actually check for write access)
|
|
83
120
|
* If the file has wac-allow and accept patch headers, those are respected.
|
|
84
121
|
* and local write access is determined by those headers.
|
|
85
|
-
* This version only looks at past HTTP requests,
|
|
122
|
+
* This async version not only looks at past HTTP requests, it also makes new ones if necessary.
|
|
123
|
+
*
|
|
124
|
+
* @returns The method string SPARQL or DAV or
|
|
125
|
+
* LOCALFILE or false if known, undefined if not known.
|
|
126
|
+
*/
|
|
127
|
+
}, {
|
|
128
|
+
key: "checkEditable",
|
|
129
|
+
value: function () {
|
|
130
|
+
var _checkEditable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(uri, kb) {
|
|
131
|
+
var _kb$fetcher2;
|
|
132
|
+
var initial, final;
|
|
133
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
134
|
+
while (1) switch (_context.prev = _context.next) {
|
|
135
|
+
case 0:
|
|
136
|
+
if (uri) {
|
|
137
|
+
_context.next = 2;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
return _context.abrupt("return", false);
|
|
141
|
+
case 2:
|
|
142
|
+
if (!kb) {
|
|
143
|
+
kb = this.store;
|
|
144
|
+
}
|
|
145
|
+
initial = this.editable(uri, kb);
|
|
146
|
+
if (!(initial !== undefined)) {
|
|
147
|
+
_context.next = 6;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
return _context.abrupt("return", initial);
|
|
151
|
+
case 6:
|
|
152
|
+
_context.next = 8;
|
|
153
|
+
return (_kb$fetcher2 = kb.fetcher) === null || _kb$fetcher2 === void 0 ? void 0 : _kb$fetcher2.load(uri);
|
|
154
|
+
case 8:
|
|
155
|
+
final = this.editable(uri, kb); // console.log(`Loaded ${uri} just to check editable, result: ${final}.`)
|
|
156
|
+
return _context.abrupt("return", final);
|
|
157
|
+
case 10:
|
|
158
|
+
case "end":
|
|
159
|
+
return _context.stop();
|
|
160
|
+
}
|
|
161
|
+
}, _callee, this);
|
|
162
|
+
}));
|
|
163
|
+
function checkEditable(_x, _x2) {
|
|
164
|
+
return _checkEditable.apply(this, arguments);
|
|
165
|
+
}
|
|
166
|
+
return checkEditable;
|
|
167
|
+
}()
|
|
168
|
+
/**
|
|
169
|
+
* Tests whether a file is editable.
|
|
170
|
+
* If the file has a specific annotation that it is machine written,
|
|
171
|
+
* for safety, it is editable (this doesn't actually check for write access)
|
|
172
|
+
* If the file has wac-allow and accept patch headers, those are respected.
|
|
173
|
+
* and local write access is determined by those headers.
|
|
174
|
+
* This synchronous version only looks at past HTTP requests, does not make new ones.
|
|
86
175
|
*
|
|
87
176
|
* @returns The method string SPARQL or DAV or
|
|
88
177
|
* LOCALFILE or false if known, undefined if not known.
|
|
@@ -90,6 +179,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
90
179
|
}, {
|
|
91
180
|
key: "editable",
|
|
92
181
|
value: function editable(uri, kb) {
|
|
182
|
+
var _kb$fetcher3;
|
|
93
183
|
if (!uri) {
|
|
94
184
|
return false; // Eg subject is bnode, no known doc to write to
|
|
95
185
|
}
|
|
@@ -99,27 +189,34 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
99
189
|
}
|
|
100
190
|
uri = termValue(uri);
|
|
101
191
|
if (!this.isHttpUri(uri)) {
|
|
102
|
-
if (kb.holds(
|
|
192
|
+
if (kb.holds(kb.rdfFactory.namedNode(uri), kb.rdfFactory.namedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), kb.rdfFactory.namedNode('http://www.w3.org/2007/ont/link#MachineEditableDocument'))) {
|
|
103
193
|
return 'LOCALFILE';
|
|
104
194
|
}
|
|
105
195
|
}
|
|
106
196
|
var request;
|
|
107
197
|
var definitive = false;
|
|
198
|
+
var meta = (_kb$fetcher3 = kb.fetcher) === null || _kb$fetcher3 === void 0 ? void 0 : _kb$fetcher3.appNode;
|
|
199
|
+
// const kb = s
|
|
200
|
+
|
|
108
201
|
// @ts-ignore passes a string to kb.each, which expects a term. Should this work?
|
|
109
|
-
var requests = kb.each(undefined, this.ns.link('requestedURI'), docpart(uri));
|
|
202
|
+
var requests = kb.each(undefined, this.ns.link('requestedURI'), docpart(uri), meta);
|
|
110
203
|
var method;
|
|
111
204
|
for (var r = 0; r < requests.length; r++) {
|
|
112
205
|
request = requests[r];
|
|
113
206
|
if (request !== undefined) {
|
|
114
|
-
var
|
|
115
|
-
if (
|
|
116
|
-
|
|
207
|
+
var _response2 = kb.any(request, this.ns.link('response'), null, meta);
|
|
208
|
+
if (_response2 !== undefined) {
|
|
209
|
+
// ts
|
|
210
|
+
|
|
211
|
+
var outOfDate = kb.anyJS(_response2, this.ns.link('outOfDate'), null, meta);
|
|
212
|
+
if (outOfDate) continue;
|
|
213
|
+
var wacAllow = kb.anyValue(_response2, this.ns.httph('wac-allow'));
|
|
117
214
|
if (wacAllow) {
|
|
118
|
-
var
|
|
119
|
-
|
|
215
|
+
var _iterator2 = _createForOfIteratorHelper(wacAllow.split(',')),
|
|
216
|
+
_step2;
|
|
120
217
|
try {
|
|
121
|
-
for (
|
|
122
|
-
var bit =
|
|
218
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
219
|
+
var bit = _step2.value;
|
|
123
220
|
var lr = bit.split('=');
|
|
124
221
|
if (lr[0].includes('user') && !lr[1].includes('write') && !lr[1].includes('append')) {
|
|
125
222
|
// console.log(' editable? excluded by WAC-Allow: ', wacAllow)
|
|
@@ -127,12 +224,12 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
127
224
|
}
|
|
128
225
|
}
|
|
129
226
|
} catch (err) {
|
|
130
|
-
|
|
227
|
+
_iterator2.e(err);
|
|
131
228
|
} finally {
|
|
132
|
-
|
|
229
|
+
_iterator2.f();
|
|
133
230
|
}
|
|
134
231
|
}
|
|
135
|
-
var acceptPatch = kb.each(
|
|
232
|
+
var acceptPatch = kb.each(_response2, this.ns.httph('accept-patch'));
|
|
136
233
|
if (acceptPatch.length) {
|
|
137
234
|
for (var i = 0; i < acceptPatch.length; i++) {
|
|
138
235
|
method = acceptPatch[i].value.trim();
|
|
@@ -140,7 +237,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
140
237
|
if (method.indexOf('application/sparql-update-single-match') >= 0) return 'SPARQL';
|
|
141
238
|
}
|
|
142
239
|
}
|
|
143
|
-
var authorVia = kb.each(
|
|
240
|
+
var authorVia = kb.each(_response2, this.ns.httph('ms-author-via'));
|
|
144
241
|
if (authorVia.length) {
|
|
145
242
|
for (var _i = 0; _i < authorVia.length; _i++) {
|
|
146
243
|
method = authorVia[_i].value.trim();
|
|
@@ -155,7 +252,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
155
252
|
if (!this.isHttpUri(uri)) {
|
|
156
253
|
if (!wacAllow) return false;else return 'LOCALFILE';
|
|
157
254
|
}
|
|
158
|
-
var status = kb.each(
|
|
255
|
+
var status = kb.each(_response2, this.ns.http('status'));
|
|
159
256
|
if (status.length) {
|
|
160
257
|
for (var _i2 = 0; _i2 < status.length; _i2++) {
|
|
161
258
|
// @ts-ignore since statuses should be TFTerms, this should always be false
|
package/lib/fetcher.d.ts
CHANGED
|
@@ -181,7 +181,7 @@ export default class Fetcher implements CallbackifyInterface {
|
|
|
181
181
|
_fetch: Fetch;
|
|
182
182
|
mediatypes: MediatypesMap;
|
|
183
183
|
/** Denoting this session */
|
|
184
|
-
appNode:
|
|
184
|
+
appNode: NamedNode;
|
|
185
185
|
/**
|
|
186
186
|
* this.requested[uri] states:
|
|
187
187
|
* undefined no record of web access or records reset
|
package/lib/fetcher.js
CHANGED
|
@@ -32,6 +32,9 @@ var _termValue = require("./utils/termValue");
|
|
|
32
32
|
var _jsonldparser = _interopRequireDefault(require("./jsonldparser"));
|
|
33
33
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
34
34
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
36
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
37
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
35
38
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
36
39
|
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; } }
|
|
37
40
|
var Parsable = {
|
|
@@ -581,7 +584,9 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
581
584
|
if (!this._fetch) {
|
|
582
585
|
throw new Error('No _fetch function available for Fetcher');
|
|
583
586
|
}
|
|
584
|
-
|
|
587
|
+
// This is the name of the graph we store all the HTTP metadata in
|
|
588
|
+
this.appNode = this.store.sym('chrome://TheCurrentSession');
|
|
589
|
+
// this.appNode = this.store.rdfFactory.blankNode() // Needs to have a URI in tests
|
|
585
590
|
this.store.fetcher = this; // Bi-linked
|
|
586
591
|
this.requested = {};
|
|
587
592
|
this.timeouts = {};
|
|
@@ -669,6 +674,31 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
669
674
|
var docuri = (0, _termValue.termValue)(uriIn);
|
|
670
675
|
docuri = docuri.split('#')[0];
|
|
671
676
|
options = this.initFetchOptions(docuri, options);
|
|
677
|
+
// if metadata flaged clear cache and removeDocument
|
|
678
|
+
var meta = this.appNode;
|
|
679
|
+
var kb = this.store;
|
|
680
|
+
var requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), kb.sym(docuri), meta).map(function (st) {
|
|
681
|
+
return st.subject;
|
|
682
|
+
});
|
|
683
|
+
var _iterator = _createForOfIteratorHelper(requests),
|
|
684
|
+
_step;
|
|
685
|
+
try {
|
|
686
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
687
|
+
var request = _step.value;
|
|
688
|
+
var _response = kb.any(request, this.ns.link('response'), null, meta);
|
|
689
|
+
if (_response !== undefined) {
|
|
690
|
+
// ts
|
|
691
|
+
var quad = kb.statementsMatching(_response, this.ns.link('outOfDate'), true, meta);
|
|
692
|
+
kb.remove(quad);
|
|
693
|
+
options.force = true;
|
|
694
|
+
options.clearPreviousData = true;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
} catch (err) {
|
|
698
|
+
_iterator.e(err);
|
|
699
|
+
} finally {
|
|
700
|
+
_iterator.f();
|
|
701
|
+
}
|
|
672
702
|
var initialisedOptions = this.initFetchOptions(docuri, options);
|
|
673
703
|
return this.pendingFetchPromise(docuri, initialisedOptions.baseURI, initialisedOptions);
|
|
674
704
|
}
|
|
@@ -1371,10 +1401,10 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
1371
1401
|
for (var r = 0; r < requests.length; r++) {
|
|
1372
1402
|
var request = requests[r];
|
|
1373
1403
|
if (request !== undefined) {
|
|
1374
|
-
var
|
|
1375
|
-
if (
|
|
1404
|
+
var _response2 = kb.any(request, this.ns.link('response'));
|
|
1405
|
+
if (_response2 !== undefined && kb.anyValue(_response2, this.ns.http('status')) && kb.anyValue(_response2, this.ns.http('status')).startsWith('2')) {
|
|
1376
1406
|
// Only look at success returns - not 401 error messagess etc
|
|
1377
|
-
var results = kb.each(
|
|
1407
|
+
var results = kb.each(_response2, this.ns.httph(header.toLowerCase()));
|
|
1378
1408
|
if (results.length) {
|
|
1379
1409
|
return results.map(function (v) {
|
|
1380
1410
|
return v.value;
|
|
@@ -1413,17 +1443,19 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
1413
1443
|
var _this10 = this;
|
|
1414
1444
|
var kb = this.store;
|
|
1415
1445
|
var responseNode = kb.bnode();
|
|
1416
|
-
kb.add(options.req, this.ns.link('response'), responseNode,
|
|
1417
|
-
kb.add(responseNode, this.ns.http('status'), kb.rdfFactory.literal(response.status),
|
|
1418
|
-
kb.add(responseNode, this.ns.http('statusText'), kb.rdfFactory.literal(response.statusText),
|
|
1446
|
+
kb.add(options.req, this.ns.link('response'), responseNode, this.appNode);
|
|
1447
|
+
kb.add(responseNode, this.ns.http('status'), kb.rdfFactory.literal(response.status), this.appNode);
|
|
1448
|
+
kb.add(responseNode, this.ns.http('statusText'), kb.rdfFactory.literal(response.statusText), this.appNode);
|
|
1419
1449
|
|
|
1420
1450
|
// Save the response headers
|
|
1421
1451
|
response.headers.forEach(function (value, header) {
|
|
1422
|
-
kb.add(responseNode, _this10.ns.httph(header), _this10.store.rdfFactory.literal(value),
|
|
1452
|
+
kb.add(responseNode, _this10.ns.httph(header), _this10.store.rdfFactory.literal(value), _this10.appNode);
|
|
1423
1453
|
if (header === 'content-type') {
|
|
1424
|
-
kb.add(options.resource, _this10.ns.rdf('type'), kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value), responseNode
|
|
1454
|
+
kb.add(options.resource, _this10.ns.rdf('type'), kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value), _this10.appNode // responseNode
|
|
1455
|
+
);
|
|
1425
1456
|
}
|
|
1426
1457
|
});
|
|
1458
|
+
|
|
1427
1459
|
return responseNode;
|
|
1428
1460
|
}
|
|
1429
1461
|
}, {
|
package/lib/jsonldparser.js
CHANGED
|
@@ -6,8 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = jsonldParser;
|
|
8
8
|
exports.jsonldObjectToTerm = jsonldObjectToTerm;
|
|
9
|
-
var
|
|
9
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
10
|
var _utils = require("./utils");
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || (0, _typeof2.default)(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
13
|
/**
|
|
12
14
|
* Parses json-ld formatted JS objects to a rdf Term.
|
|
13
15
|
* @param kb - The DataFactory to use.
|
|
@@ -67,8 +69,12 @@ function listToCollection(kb, obj) {
|
|
|
67
69
|
*/
|
|
68
70
|
function jsonldParser(str, kb, base, callback) {
|
|
69
71
|
var baseString = base && Object.prototype.hasOwnProperty.call(base, 'termType') ? base.value : base;
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
+
return Promise.resolve().then(function () {
|
|
73
|
+
return _interopRequireWildcard(require('jsonld'));
|
|
74
|
+
}).then(function (jsonld) {
|
|
75
|
+
return jsonld.flatten(JSON.parse(str), null, {
|
|
76
|
+
base: baseString
|
|
77
|
+
});
|
|
72
78
|
}).then(function (flattened) {
|
|
73
79
|
return flattened.reduce(function (store, flatResource) {
|
|
74
80
|
kb = processResource(kb, base, flatResource);
|
package/lib/store.d.ts
CHANGED
|
@@ -233,7 +233,7 @@ export default class IndexedFormula extends Formula {
|
|
|
233
233
|
*/
|
|
234
234
|
remove(st: Quad | Quad[]): IndexedFormula;
|
|
235
235
|
/**
|
|
236
|
-
* Removes all statements in a doc
|
|
236
|
+
* Removes all statements in a doc, along with the related metadata including request/response
|
|
237
237
|
* @param doc - The document / graph
|
|
238
238
|
*/
|
|
239
239
|
removeDocument(doc: Quad_Graph): IndexedFormula;
|
package/lib/store.js
CHANGED
|
@@ -827,12 +827,32 @@ var IndexedFormula = /*#__PURE__*/function (_Formula) {
|
|
|
827
827
|
}
|
|
828
828
|
|
|
829
829
|
/**
|
|
830
|
-
* Removes all statements in a doc
|
|
830
|
+
* Removes all statements in a doc, along with the related metadata including request/response
|
|
831
831
|
* @param doc - The document / graph
|
|
832
832
|
*/
|
|
833
833
|
}, {
|
|
834
834
|
key: "removeDocument",
|
|
835
835
|
value: function removeDocument(doc) {
|
|
836
|
+
var meta = this.sym('chrome://TheCurrentSession'); // or this.rdfFactory.namedNode('chrome://TheCurrentSession')
|
|
837
|
+
var linkNamespaceURI = 'http://www.w3.org/2007/ont/link#'; // alain
|
|
838
|
+
// remove request/response and metadata
|
|
839
|
+
var requests = this.statementsMatching(undefined, this.sym("".concat(linkNamespaceURI, "requestedURI")), this.rdfFactory.literal(doc.value), meta).map(function (st) {
|
|
840
|
+
return st.subject;
|
|
841
|
+
});
|
|
842
|
+
for (var r = 0; r < requests.length; r++) {
|
|
843
|
+
var request = requests[r];
|
|
844
|
+
if (request !== undefined) {
|
|
845
|
+
this.removeMatches(request, null, null, meta);
|
|
846
|
+
var response = this.any(request, this.sym("".concat(linkNamespaceURI, "response")), null, meta);
|
|
847
|
+
if (response !== undefined) {
|
|
848
|
+
// ts
|
|
849
|
+
this.removeMatches(response, null, null, meta);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
this.removeMatches(this.sym(doc.value), null, null, meta); // content-type
|
|
854
|
+
|
|
855
|
+
// remove document
|
|
836
856
|
var sts = this.statementsMatching(undefined, undefined, undefined, doc).slice(); // Take a copy as this is the actual index
|
|
837
857
|
for (var i = 0; i < sts.length; i++) {
|
|
838
858
|
this.removeStatement(sts[i]);
|
package/lib/update-manager.d.ts
CHANGED
|
@@ -27,13 +27,32 @@ export default class UpdateManager {
|
|
|
27
27
|
constructor(store?: IndexedFormula);
|
|
28
28
|
patchControlFor(doc: NamedNode): any;
|
|
29
29
|
isHttpUri(uri: string): boolean;
|
|
30
|
+
/** Remove from the store HTTP authorization metadata
|
|
31
|
+
* The editble function below relies on copies we have in the store
|
|
32
|
+
* of the results of previous HTTP transactions. Howver, when
|
|
33
|
+
* the user logs in, then that data misrepresents what would happen
|
|
34
|
+
* if the user tried again.
|
|
35
|
+
*/
|
|
36
|
+
flagAuthorizationMetadata(kb?: IndexedFormula): void;
|
|
37
|
+
/**
|
|
38
|
+
* Tests whether a file is editable.
|
|
39
|
+
* If the file has a specific annotation that it is machine written,
|
|
40
|
+
* for safety, it is editable (this doesn't actually check for write access)
|
|
41
|
+
* If the file has wac-allow and accept patch headers, those are respected.
|
|
42
|
+
* and local write access is determined by those headers.
|
|
43
|
+
* This async version not only looks at past HTTP requests, it also makes new ones if necessary.
|
|
44
|
+
*
|
|
45
|
+
* @returns The method string SPARQL or DAV or
|
|
46
|
+
* LOCALFILE or false if known, undefined if not known.
|
|
47
|
+
*/
|
|
48
|
+
checkEditable(uri: string | NamedNode, kb?: IndexedFormula): Promise<string | boolean | undefined>;
|
|
30
49
|
/**
|
|
31
50
|
* Tests whether a file is editable.
|
|
32
51
|
* If the file has a specific annotation that it is machine written,
|
|
33
52
|
* for safety, it is editable (this doesn't actually check for write access)
|
|
34
53
|
* If the file has wac-allow and accept patch headers, those are respected.
|
|
35
54
|
* and local write access is determined by those headers.
|
|
36
|
-
* This version only looks at past HTTP requests, does not make new ones.
|
|
55
|
+
* This synchronous version only looks at past HTTP requests, does not make new ones.
|
|
37
56
|
*
|
|
38
57
|
* @returns The method string SPARQL or DAV or
|
|
39
58
|
* LOCALFILE or false if known, undefined if not known.
|