rdflib 2.2.30 → 2.2.31-546de2c9
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/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/fetcher.js +10 -6
- package/esm/update-manager.js +112 -15
- package/lib/fetcher.d.ts +1 -1
- package/lib/fetcher.js +10 -6
- package/lib/update-manager.d.ts +20 -1
- package/lib/update-manager.js +112 -15
- package/package.json +2 -2
- package/src/fetcher.ts +9 -8
- package/src/update-manager.ts +61 -7
- package/dist/670.rdflib.min.js +0 -1
- package/dist/730.rdflib.min.js +0 -3
- package/dist/730.rdflib.min.js.LICENSE.txt +0 -58
- package/dist/730.rdflib.min.js.map +0 -1
- package/esm/convert.js +0 -60
- package/lib/convert.d.ts +0 -2
- package/lib/convert.js +0 -71
package/esm/fetcher.js
CHANGED
|
@@ -598,7 +598,9 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
598
598
|
if (!this._fetch) {
|
|
599
599
|
throw new Error('No _fetch function available for Fetcher');
|
|
600
600
|
}
|
|
601
|
-
|
|
601
|
+
// This is the name of the graph we store all the HTTP metadata in
|
|
602
|
+
this.appNode = this.store.sym('chrome://TheCurrentSession');
|
|
603
|
+
// this.appNode = this.store.rdfFactory.blankNode() // Needs to have a URI in tests
|
|
602
604
|
this.store.fetcher = this; // Bi-linked
|
|
603
605
|
this.requested = {};
|
|
604
606
|
this.timeouts = {};
|
|
@@ -1430,17 +1432,19 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
1430
1432
|
var _this10 = this;
|
|
1431
1433
|
var kb = this.store;
|
|
1432
1434
|
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),
|
|
1435
|
+
kb.add(options.req, this.ns.link('response'), responseNode, this.appNode);
|
|
1436
|
+
kb.add(responseNode, this.ns.http('status'), kb.rdfFactory.literal(response.status), this.appNode);
|
|
1437
|
+
kb.add(responseNode, this.ns.http('statusText'), kb.rdfFactory.literal(response.statusText), this.appNode);
|
|
1436
1438
|
|
|
1437
1439
|
// Save the response headers
|
|
1438
1440
|
response.headers.forEach(function (value, header) {
|
|
1439
|
-
kb.add(responseNode, _this10.ns.httph(header), _this10.store.rdfFactory.literal(value),
|
|
1441
|
+
kb.add(responseNode, _this10.ns.httph(header), _this10.store.rdfFactory.literal(value), _this10.appNode);
|
|
1440
1442
|
if (header === 'content-type') {
|
|
1441
|
-
kb.add(options.resource, _this10.ns.rdf('type'), kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value), responseNode
|
|
1443
|
+
kb.add(options.resource, _this10.ns.rdf('type'), kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value), _this10.appNode // responseNode
|
|
1444
|
+
);
|
|
1442
1445
|
}
|
|
1443
1446
|
});
|
|
1447
|
+
|
|
1444
1448
|
return responseNode;
|
|
1445
1449
|
}
|
|
1446
1450
|
}, {
|
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
|
@@ -581,7 +581,9 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
581
581
|
if (!this._fetch) {
|
|
582
582
|
throw new Error('No _fetch function available for Fetcher');
|
|
583
583
|
}
|
|
584
|
-
|
|
584
|
+
// This is the name of the graph we store all the HTTP metadata in
|
|
585
|
+
this.appNode = this.store.sym('chrome://TheCurrentSession');
|
|
586
|
+
// this.appNode = this.store.rdfFactory.blankNode() // Needs to have a URI in tests
|
|
585
587
|
this.store.fetcher = this; // Bi-linked
|
|
586
588
|
this.requested = {};
|
|
587
589
|
this.timeouts = {};
|
|
@@ -1413,17 +1415,19 @@ var Fetcher = /*#__PURE__*/function () {
|
|
|
1413
1415
|
var _this10 = this;
|
|
1414
1416
|
var kb = this.store;
|
|
1415
1417
|
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),
|
|
1418
|
+
kb.add(options.req, this.ns.link('response'), responseNode, this.appNode);
|
|
1419
|
+
kb.add(responseNode, this.ns.http('status'), kb.rdfFactory.literal(response.status), this.appNode);
|
|
1420
|
+
kb.add(responseNode, this.ns.http('statusText'), kb.rdfFactory.literal(response.statusText), this.appNode);
|
|
1419
1421
|
|
|
1420
1422
|
// Save the response headers
|
|
1421
1423
|
response.headers.forEach(function (value, header) {
|
|
1422
|
-
kb.add(responseNode, _this10.ns.httph(header), _this10.store.rdfFactory.literal(value),
|
|
1424
|
+
kb.add(responseNode, _this10.ns.httph(header), _this10.store.rdfFactory.literal(value), _this10.appNode);
|
|
1423
1425
|
if (header === 'content-type') {
|
|
1424
|
-
kb.add(options.resource, _this10.ns.rdf('type'), kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value), responseNode
|
|
1426
|
+
kb.add(options.resource, _this10.ns.rdf('type'), kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value), _this10.appNode // responseNode
|
|
1427
|
+
);
|
|
1425
1428
|
}
|
|
1426
1429
|
});
|
|
1430
|
+
|
|
1427
1431
|
return responseNode;
|
|
1428
1432
|
}
|
|
1429
1433
|
}, {
|
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.
|
package/lib/update-manager.js
CHANGED
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
10
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
12
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
13
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -80,13 +82,100 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
80
82
|
return uri.slice(0, 4) === 'http';
|
|
81
83
|
}
|
|
82
84
|
|
|
85
|
+
/** Remove from the store HTTP authorization metadata
|
|
86
|
+
* The editble function below relies on copies we have in the store
|
|
87
|
+
* of the results of previous HTTP transactions. Howver, when
|
|
88
|
+
* the user logs in, then that data misrepresents what would happen
|
|
89
|
+
* if the user tried again.
|
|
90
|
+
*/
|
|
91
|
+
}, {
|
|
92
|
+
key: "flagAuthorizationMetadata",
|
|
93
|
+
value: function flagAuthorizationMetadata(kb) {
|
|
94
|
+
var _kb$fetcher;
|
|
95
|
+
if (!kb) {
|
|
96
|
+
kb = this.store;
|
|
97
|
+
}
|
|
98
|
+
var meta = (_kb$fetcher = kb.fetcher) === null || _kb$fetcher === void 0 ? void 0 : _kb$fetcher.appNode;
|
|
99
|
+
var requests = kb.statementsMatching(undefined, this.ns.link('requestedURI'), undefined, meta).map(function (st) {
|
|
100
|
+
return st.subject;
|
|
101
|
+
});
|
|
102
|
+
var _iterator = _createForOfIteratorHelper(requests),
|
|
103
|
+
_step;
|
|
104
|
+
try {
|
|
105
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
106
|
+
var request = _step.value;
|
|
107
|
+
var _response = kb.any(request, this.ns.link('response'), null, meta);
|
|
108
|
+
if (_response !== undefined) {
|
|
109
|
+
// ts
|
|
110
|
+
kb.add(_response, this.ns.link('outOfDate'), true, meta); // @@ Boolean is fine - fix types
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {
|
|
114
|
+
_iterator.e(err);
|
|
115
|
+
} finally {
|
|
116
|
+
_iterator.f();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
83
120
|
/**
|
|
84
121
|
* Tests whether a file is editable.
|
|
85
122
|
* If the file has a specific annotation that it is machine written,
|
|
86
123
|
* for safety, it is editable (this doesn't actually check for write access)
|
|
87
124
|
* If the file has wac-allow and accept patch headers, those are respected.
|
|
88
125
|
* and local write access is determined by those headers.
|
|
89
|
-
* This version only looks at past HTTP requests,
|
|
126
|
+
* This async version not only looks at past HTTP requests, it also makes new ones if necessary.
|
|
127
|
+
*
|
|
128
|
+
* @returns The method string SPARQL or DAV or
|
|
129
|
+
* LOCALFILE or false if known, undefined if not known.
|
|
130
|
+
*/
|
|
131
|
+
}, {
|
|
132
|
+
key: "checkEditable",
|
|
133
|
+
value: function () {
|
|
134
|
+
var _checkEditable = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(uri, kb) {
|
|
135
|
+
var _kb$fetcher2;
|
|
136
|
+
var initial, final;
|
|
137
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
138
|
+
while (1) switch (_context.prev = _context.next) {
|
|
139
|
+
case 0:
|
|
140
|
+
if (uri) {
|
|
141
|
+
_context.next = 2;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
return _context.abrupt("return", false);
|
|
145
|
+
case 2:
|
|
146
|
+
if (!kb) {
|
|
147
|
+
kb = this.store;
|
|
148
|
+
}
|
|
149
|
+
initial = this.editable(uri, kb);
|
|
150
|
+
if (!(initial !== undefined)) {
|
|
151
|
+
_context.next = 6;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
return _context.abrupt("return", initial);
|
|
155
|
+
case 6:
|
|
156
|
+
_context.next = 8;
|
|
157
|
+
return (_kb$fetcher2 = kb.fetcher) === null || _kb$fetcher2 === void 0 ? void 0 : _kb$fetcher2.load(uri);
|
|
158
|
+
case 8:
|
|
159
|
+
final = this.editable(uri, kb); // console.log(`Loaded ${uri} just to check editable, result: ${final}.`)
|
|
160
|
+
return _context.abrupt("return", final);
|
|
161
|
+
case 10:
|
|
162
|
+
case "end":
|
|
163
|
+
return _context.stop();
|
|
164
|
+
}
|
|
165
|
+
}, _callee, this);
|
|
166
|
+
}));
|
|
167
|
+
function checkEditable(_x, _x2) {
|
|
168
|
+
return _checkEditable.apply(this, arguments);
|
|
169
|
+
}
|
|
170
|
+
return checkEditable;
|
|
171
|
+
}()
|
|
172
|
+
/**
|
|
173
|
+
* Tests whether a file is editable.
|
|
174
|
+
* If the file has a specific annotation that it is machine written,
|
|
175
|
+
* for safety, it is editable (this doesn't actually check for write access)
|
|
176
|
+
* If the file has wac-allow and accept patch headers, those are respected.
|
|
177
|
+
* and local write access is determined by those headers.
|
|
178
|
+
* This synchronous version only looks at past HTTP requests, does not make new ones.
|
|
90
179
|
*
|
|
91
180
|
* @returns The method string SPARQL or DAV or
|
|
92
181
|
* LOCALFILE or false if known, undefined if not known.
|
|
@@ -94,6 +183,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
94
183
|
}, {
|
|
95
184
|
key: "editable",
|
|
96
185
|
value: function editable(uri, kb) {
|
|
186
|
+
var _kb$fetcher3;
|
|
97
187
|
if (!uri) {
|
|
98
188
|
return false; // Eg subject is bnode, no known doc to write to
|
|
99
189
|
}
|
|
@@ -103,27 +193,34 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
103
193
|
}
|
|
104
194
|
uri = (0, _termValue.termValue)(uri);
|
|
105
195
|
if (!this.isHttpUri(uri)) {
|
|
106
|
-
if (kb.holds(
|
|
196
|
+
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'))) {
|
|
107
197
|
return 'LOCALFILE';
|
|
108
198
|
}
|
|
109
199
|
}
|
|
110
200
|
var request;
|
|
111
201
|
var definitive = false;
|
|
202
|
+
var meta = (_kb$fetcher3 = kb.fetcher) === null || _kb$fetcher3 === void 0 ? void 0 : _kb$fetcher3.appNode;
|
|
203
|
+
// const kb = s
|
|
204
|
+
|
|
112
205
|
// @ts-ignore passes a string to kb.each, which expects a term. Should this work?
|
|
113
|
-
var requests = kb.each(undefined, this.ns.link('requestedURI'), (0, _uri.docpart)(uri));
|
|
206
|
+
var requests = kb.each(undefined, this.ns.link('requestedURI'), (0, _uri.docpart)(uri), meta);
|
|
114
207
|
var method;
|
|
115
208
|
for (var r = 0; r < requests.length; r++) {
|
|
116
209
|
request = requests[r];
|
|
117
210
|
if (request !== undefined) {
|
|
118
|
-
var
|
|
119
|
-
if (
|
|
120
|
-
|
|
211
|
+
var _response2 = kb.any(request, this.ns.link('response'), null, meta);
|
|
212
|
+
if (_response2 !== undefined) {
|
|
213
|
+
// ts
|
|
214
|
+
|
|
215
|
+
var outOfDate = kb.anyJS(_response2, this.ns.link('outOfDate'), null, meta);
|
|
216
|
+
if (outOfDate) continue;
|
|
217
|
+
var wacAllow = kb.anyValue(_response2, this.ns.httph('wac-allow'));
|
|
121
218
|
if (wacAllow) {
|
|
122
|
-
var
|
|
123
|
-
|
|
219
|
+
var _iterator2 = _createForOfIteratorHelper(wacAllow.split(',')),
|
|
220
|
+
_step2;
|
|
124
221
|
try {
|
|
125
|
-
for (
|
|
126
|
-
var bit =
|
|
222
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
223
|
+
var bit = _step2.value;
|
|
127
224
|
var lr = bit.split('=');
|
|
128
225
|
if (lr[0].includes('user') && !lr[1].includes('write') && !lr[1].includes('append')) {
|
|
129
226
|
// console.log(' editable? excluded by WAC-Allow: ', wacAllow)
|
|
@@ -131,12 +228,12 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
131
228
|
}
|
|
132
229
|
}
|
|
133
230
|
} catch (err) {
|
|
134
|
-
|
|
231
|
+
_iterator2.e(err);
|
|
135
232
|
} finally {
|
|
136
|
-
|
|
233
|
+
_iterator2.f();
|
|
137
234
|
}
|
|
138
235
|
}
|
|
139
|
-
var acceptPatch = kb.each(
|
|
236
|
+
var acceptPatch = kb.each(_response2, this.ns.httph('accept-patch'));
|
|
140
237
|
if (acceptPatch.length) {
|
|
141
238
|
for (var i = 0; i < acceptPatch.length; i++) {
|
|
142
239
|
method = acceptPatch[i].value.trim();
|
|
@@ -144,7 +241,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
144
241
|
if (method.indexOf('application/sparql-update-single-match') >= 0) return 'SPARQL';
|
|
145
242
|
}
|
|
146
243
|
}
|
|
147
|
-
var authorVia = kb.each(
|
|
244
|
+
var authorVia = kb.each(_response2, this.ns.httph('ms-author-via'));
|
|
148
245
|
if (authorVia.length) {
|
|
149
246
|
for (var _i = 0; _i < authorVia.length; _i++) {
|
|
150
247
|
method = authorVia[_i].value.trim();
|
|
@@ -159,7 +256,7 @@ var UpdateManager = /*#__PURE__*/function () {
|
|
|
159
256
|
if (!this.isHttpUri(uri)) {
|
|
160
257
|
if (!wacAllow) return false;else return 'LOCALFILE';
|
|
161
258
|
}
|
|
162
|
-
var status = kb.each(
|
|
259
|
+
var status = kb.each(_response2, this.ns.http('status'));
|
|
163
260
|
if (status.length) {
|
|
164
261
|
for (var _i2 = 0; _i2 < status.length; _i2++) {
|
|
165
262
|
// @ts-ignore since statuses should be TFTerms, this should always be false
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rdflib",
|
|
3
3
|
"description": "an RDF library for node.js. Suitable for client and server side.",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.31-546de2c9",
|
|
5
5
|
"private": false,
|
|
6
6
|
"browserslist": [
|
|
7
7
|
"> 0.5%"
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"build:types": "tsc --emitDeclarationOnly -d --moduleResolution node --declarationDir lib",
|
|
95
95
|
"build:all": "npm run build && npm run build:types && npm run build:browser && npm run build:esm",
|
|
96
96
|
"doc": "typedoc --out ./doc ./src/index.ts --excludePrivate --excludeInternal --tsconfig ./tsconfig.json",
|
|
97
|
-
"prepublishOnly": "npm ci && npm run build:all && npm run doc && npm run test",
|
|
97
|
+
"ignore:prepublishOnly": "npm ci && npm run build:all && npm run doc && npm run test",
|
|
98
98
|
"postversion": "git push --follow-tags",
|
|
99
99
|
"start": "webpack serve --port 4800",
|
|
100
100
|
"test": "npm run test:unit && npm run test:serialize && npm run test:types",
|
package/src/fetcher.ts
CHANGED
|
@@ -721,7 +721,7 @@ export default class Fetcher implements CallbackifyInterface {
|
|
|
721
721
|
_fetch: Fetch
|
|
722
722
|
mediatypes: MediatypesMap
|
|
723
723
|
/** Denoting this session */
|
|
724
|
-
appNode:
|
|
724
|
+
appNode: NamedNode
|
|
725
725
|
/**
|
|
726
726
|
* this.requested[uri] states:
|
|
727
727
|
* undefined no record of web access or records reset
|
|
@@ -771,8 +771,9 @@ export default class Fetcher implements CallbackifyInterface {
|
|
|
771
771
|
if (!this._fetch) {
|
|
772
772
|
throw new Error('No _fetch function available for Fetcher')
|
|
773
773
|
}
|
|
774
|
-
|
|
775
|
-
this.appNode = this.store.
|
|
774
|
+
// This is the name of the graph we store all the HTTP metadata in
|
|
775
|
+
this.appNode = this.store.sym('chrome://TheCurrentSession')
|
|
776
|
+
// this.appNode = this.store.rdfFactory.blankNode() // Needs to have a URI in tests
|
|
776
777
|
this.store.fetcher = this // Bi-linked
|
|
777
778
|
this.requested = {}
|
|
778
779
|
this.timeouts = {}
|
|
@@ -1725,22 +1726,22 @@ export default class Fetcher implements CallbackifyInterface {
|
|
|
1725
1726
|
|
|
1726
1727
|
let responseNode = kb.bnode()
|
|
1727
1728
|
|
|
1728
|
-
kb.add(options.req, this.ns.link('response'), responseNode,
|
|
1729
|
+
kb.add(options.req, this.ns.link('response'), responseNode, this.appNode)
|
|
1729
1730
|
kb.add(responseNode, this.ns.http('status'),
|
|
1730
|
-
kb.rdfFactory.literal(response.status as any),
|
|
1731
|
+
kb.rdfFactory.literal(response.status as any), this.appNode)
|
|
1731
1732
|
kb.add(responseNode, this.ns.http('statusText'),
|
|
1732
|
-
kb.rdfFactory.literal(response.statusText),
|
|
1733
|
+
kb.rdfFactory.literal(response.statusText), this.appNode)
|
|
1733
1734
|
|
|
1734
1735
|
// Save the response headers
|
|
1735
1736
|
response.headers.forEach((value, header) => {
|
|
1736
|
-
kb.add(responseNode, this.ns.httph(header), this.store.rdfFactory.literal(value),
|
|
1737
|
+
kb.add(responseNode, this.ns.httph(header), this.store.rdfFactory.literal(value), this.appNode)
|
|
1737
1738
|
|
|
1738
1739
|
if (header === 'content-type') {
|
|
1739
1740
|
kb.add(
|
|
1740
1741
|
options.resource,
|
|
1741
1742
|
this.ns.rdf('type'),
|
|
1742
1743
|
kb.rdfFactory.namedNode(Util.mediaTypeClass(value).value),
|
|
1743
|
-
responseNode
|
|
1744
|
+
this.appNode // responseNode
|
|
1744
1745
|
)
|
|
1745
1746
|
}
|
|
1746
1747
|
})
|